@quake2ts/engine 0.0.875 → 0.0.877
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/dist/browser/index.global.js +20 -20
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.cjs +16 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +16 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/render/bsp/geometry.d.ts +10 -0
- package/dist/types/render/bsp/geometry.d.ts.map +1 -1
- package/dist/types/render/bsp/surface.d.ts.map +1 -1
- package/dist/types/render/bsp.d.ts +10 -0
- package/dist/types/render/bsp.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Quake2Engine=(()=>{var fg=Object.create;var ro=Object.defineProperty;var hg=Object.getOwnPropertyDescriptor;var mg=Object.getOwnPropertyNames;var pg=Object.getPrototypeOf,gg=Object.prototype.hasOwnProperty;var yg=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var bg=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ni=(t,e)=>{for(var r in e)ro(t,r,{get:e[r],enumerable:!0})},Zf=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mg(e))!gg.call(t,i)&&i!==r&&ro(t,i,{get:()=>e[i],enumerable:!(n=hg(e,i))||n.enumerable});return t};var xg=(t,e,r)=>(r=t!=null?fg(pg(t)):{},Zf(e||!t||!t.__esModule?ro(r,"default",{value:t,enumerable:!0}):r,t)),vg=t=>Zf(ro({},"__esModule",{value:!0}),t);var h=(t,e,r)=>yg(t,typeof e!="symbol"?e+"":e,r);var kh=bg((WA,Dh)=>{"use strict";Dh.exports=Worker});var B2={};Ni(B2,{ATTN_IDLE:()=>Pu,ATTN_LOOP_NONE:()=>Tu,ATTN_NONE:()=>lo,ATTN_NORM:()=>Lu,ATTN_STATIC:()=>Ru,AssetDependencyError:()=>Ei,AssetDependencyTracker:()=>ds,AssetManager:()=>jl,AssetPreviewGenerator:()=>nu,AudioApi:()=>Ki,AudioContextController:()=>Ql,AudioOcclusion:()=>hs,AudioRegistry:()=>ba,AudioRegistryError:()=>ls,AudioSystem:()=>ac,BSP_SURFACE_FRAGMENT_SOURCE:()=>vd,BSP_SURFACE_VERTEX_SOURCE:()=>xd,BSP_VERTEX_LAYOUT:()=>hd,BspLoader:()=>Zi,BspLump:()=>Uu,BspParseError:()=>fe,BspSurfacePipeline:()=>Sa,Camera:()=>bc,ClientConnection:()=>cu,Command:()=>no,CommandRegistry:()=>Gi,ConfigStringRegistry:()=>Yi,ConnectionState:()=>Gf,CoordinateSystem:()=>ef,Cvar:()=>co,CvarRegistry:()=>Xi,DemoAnalyzer:()=>qa,DemoCameraMode:()=>Uf,DemoClipper:()=>ru,DemoEventType:()=>kf,DemoPlaybackController:()=>Hs,DemoReader:()=>wr,DemoRecorder:()=>Ws,DemoValidator:()=>tu,DynamicLightManager:()=>uc,EngineHost:()=>$i,EngineRuntime:()=>uo,FileType:()=>zf,FixedTimestepLoop:()=>ii,Framebuffer:()=>Ti,IndexBuffer:()=>ut,LoggingRenderer:()=>lu,LruCache:()=>Ln,MAX_SOUND_CHANNELS:()=>so,MD2_FRAGMENT_SHADER:()=>Td,MD2_VERTEX_SHADER:()=>Ed,MD3_FRAGMENT_SHADER:()=>Yd,MD3_VERTEX_SHADER:()=>Kd,MapAnalyzer:()=>iu,Md2Loader:()=>ji,Md2MeshBuffers:()=>Aa,Md2ParseError:()=>st,Md2Pipeline:()=>Ea,Md3Loader:()=>Qi,Md3ModelMesh:()=>Ra,Md3ParseError:()=>rr,Md3Pipeline:()=>Ca,Md3SurfaceMesh:()=>xs,MessageWriter:()=>eu,MusicSystem:()=>oc,NetworkMessageParser:()=>_t,NullRenderer:()=>au,PARTICLE_FRAGMENT_SHADER:()=>Zd,PARTICLE_VERTEX_SHADER:()=>qd,PROTOCOL_VERSION_RERELEASE:()=>Yr,PakArchive:()=>qi,PakIndexStore:()=>Zl,PakIngestionError:()=>Tn,PakParseError:()=>Ne,PakValidationError:()=>ui,PakValidator:()=>ul,PakWriter:()=>sl,ParticleRenderer:()=>Fa,ParticleSystem:()=>Ba,PlaybackState:()=>Jc,RERELEASE_KNOWN_PAKS:()=>Du,ResourceLoadTracker:()=>ll,ResourceType:()=>Iu,SKYBOX_FRAGMENT_SHADER:()=>Md,SKYBOX_VERTEX_SHADER:()=>wd,SOUND_FULLVOLUME:()=>Hi,SOUND_LOOP_ATTENUATE:()=>Cu,ShaderProgram:()=>he,SkyboxPipeline:()=>wa,SoundChannel:()=>Ir,SoundPrecache:()=>tc,SoundRegistry:()=>ec,SpriteLoader:()=>Ji,SpriteParseError:()=>Pn,SpriteRenderer:()=>Ia,StreamingPakArchive:()=>ol,Texture2D:()=>dt,TextureCache:()=>ea,TextureCubeMap:()=>xa,TgaParseError:()=>jr,U_ALPHA:()=>Lr,U_ANGLE1:()=>Ct,U_ANGLE2:()=>Et,U_ANGLE3:()=>Tt,U_EFFECTS16:()=>et,U_EFFECTS8:()=>je,U_EVENT:()=>Pt,U_FRAME16:()=>Ft,U_FRAME8:()=>Lt,U_INSTANCE_BITS:()=>Br,U_LOOP_ATTENUATION_HIGH:()=>wn,U_LOOP_VOLUME:()=>Fr,U_MODEL:()=>Bt,U_MODEL2:()=>It,U_MODEL3:()=>Dt,U_MODEL4:()=>kt,U_OLDORIGIN:()=>br,U_OLD_FRAME_HIGH:()=>An,U_ORIGIN1:()=>Mt,U_ORIGIN2:()=>At,U_ORIGIN3:()=>Rt,U_OWNER_HIGH:()=>Mn,U_REMOVE:()=>ao,U_RENDERFX16:()=>Je,U_RENDERFX8:()=>Ze,U_SCALE:()=>Cr,U_SKIN16:()=>tt,U_SKIN8:()=>Qe,U_SOLID:()=>zt,U_SOUND:()=>Ut,VertexArray:()=>Fe,VertexBuffer:()=>Be,VirtualFileSystem:()=>cl,advanceAnimation:()=>Rh,applyEntityDelta:()=>q0,applySurfaceState:()=>ms,attenuationToDistanceMultiplier:()=>Wi,boxIntersectsFrustum:()=>Li,buildBspGeometry:()=>cc,buildMd2Geometry:()=>Ld,buildMd2VertexData:()=>Pd,buildMd3SurfaceGeometry:()=>Xd,buildMd3VertexData:()=>$d,calculateMaxAudibleDistance:()=>ci,calculatePakChecksum:()=>mh,captureRenderTarget:()=>ng,computeFrameBlend:()=>Ch,computeSkyScroll:()=>Ri,createAnimationState:()=>Bh,createAudioGraph:()=>Jl,createBspSurfaces:()=>lc,createEmptyEntityState:()=>Kr,createEmptyProtocolPlayerState:()=>Mr,createEngine:()=>C2,createEngineRuntime:()=>dh,createFaceLightmap:()=>fl,createHeadlessRenderTarget:()=>rg,createInitialChannels:()=>rc,createOcclusionResolver:()=>fm,createProgramFromSources:()=>pm,createRenderer:()=>gp,createWebGLContext:()=>hm,createWebGPUContext:()=>Tc,createWebGPURenderer:()=>Ep,decodeOgg:()=>ql,deriveSurfaceRenderState:()=>Sd,detectFileType:()=>Of,extractFrustumPlanes:()=>cr,filesToPakSources:()=>ku,findLeafForPoint:()=>Pi,gatherVisibleFaces:()=>dn,groupMd2Animations:()=>Eh,ingestPakFiles:()=>bh,ingestPaks:()=>dl,interpolateMd3Tag:()=>Jm,interpolateVec3:()=>Fh,isBinaryFile:()=>j0,isTextFile:()=>Nf,parseBsp:()=>fo,parseEntLump:()=>J0,parseMd2:()=>zu,parseMd3:()=>Ou,parsePcx:()=>go,parseSprite:()=>Nu,parseTga:()=>Gu,parseWal:()=>ml,parseWalTexture:()=>yl,parseWav:()=>bl,pcxToRgba:()=>pl,pickChannel:()=>nc,preparePcxTexture:()=>gl,queryCapabilities:()=>yp,removeViewTranslation:()=>Ma,resolveLightStyles:()=>_d,serializeEntLump:()=>eg,spawnBfgExplosion:()=>dp,spawnBlasterImpact:()=>up,spawnBlood:()=>rp,spawnBulletImpact:()=>ep,spawnExplosion:()=>tp,spawnMuzzleFlash:()=>ip,spawnRailTrail:()=>lp,spawnSparks:()=>cp,spawnSplash:()=>op,spawnSteam:()=>sp,spawnTeleportFlash:()=>np,spawnTrail:()=>ap,validateEntity:()=>tg,walToRgba:()=>Vu,wireDropTarget:()=>xh,wireFileInput:()=>vh});var _g=()=>typeof performance<"u"?performance.now():Date.now(),Sg=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},ii=class{constructor(e,r={}){this.callbacks=e;h(this,"options");h(this,"accumulatorMs",0);h(this,"frame",0);h(this,"lastTimeMs");h(this,"running",!1);h(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??_g,schedule:r.schedule??Sg}}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 a=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:a,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var no=class{constructor(e,r,n){h(this,"name");h(this,"description");h(this,"callback");this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},Gi=class{constructor(){h(this,"commands",new Map);h(this,"history",[]);h(this,"historyLimit",64);h(this,"autocompleteProviders",[]);h(this,"onConsoleOutput")}register(e,r,n){let i=new no(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],a=n.slice(1),o=this.get(i);return o?(o.execute(a),!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 a of i)a.startsWith(e)&&r.add(a)}return Array.from(r).sort()}tokenize(e){let r=[],n="",i=!1;for(let a=0;a<e.length;a++){let o=e[a];o==='"'?i=!i:o===" "&&!i?n.length>0&&(r.push(n),n=""):n+=o}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var jf=Object.defineProperty,wg=(t,e,r)=>e in t?jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Mg=(t,e)=>{for(var r in e)jf(t,r,{get:e[r],enumerable:!0})},te=(t,e,r)=>wg(t,typeof e!="symbol"?e+"":e,r),Qf={x:0,y:0,z:0};var X2=Math.PI/180;function Jf(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function Ag(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function Eg(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function Tg(t){return Eg(t,t)}function gu(t){return Math.sqrt(Tg(t))}function qr(t){let e=gu(t);return e===0?t:Ag(t,1/e)}var Lg=Math.PI/180,Pg=180/Math.PI,Ee=Lg,yu=Pg;var yr=[[-.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]];var Ar=624,Rg=397,Cg=2567483615,Bg=2147483648,Fg=2147483647,mu=4294967296,Ig=class{constructor(t=5489){te(this,"state",new Uint32Array(Ar)),te(this,"index",Ar),this.seed(t)}seed(t){this.state[0]=t>>>0;for(let e=1;e<Ar;e++){let r=this.state[e-1]^this.state[e-1]>>>30,n=Math.imul(r>>>0,1812433253)+e;this.state[e]=n>>>0}this.index=Ar}nextUint32(){this.index>=Ar&&this.twist();let t=this.state[this.index++];return t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}twist(){for(let t=0;t<Ar;t++){let e=this.state[t]&Bg|this.state[(t+1)%Ar]&Fg,r=this.state[(t+Rg)%Ar]^e>>>1;(e&1)!==0&&(r^=Cg),this.state[t]=r>>>0}this.index=0}getState(){return{index:this.index,state:Array.from(this.state)}}setState(t){if(t.state.length!==Ar)throw new Error(`Expected ${Ar} MT state values, received ${t.state.length}`);this.index=t.index,this.state=Uint32Array.from(t.state,e=>e>>>0)}},eh=class{constructor(t={}){te(this,"mt"),this.mt=new Ig(t.seed)}seed(t){this.mt.seed(t)}frandom(){return this.mt.nextUint32()/mu}frandomRange(t,e){return t+(e-t)*this.frandom()}frandomMax(t){return this.frandomRange(0,t)}crandom(){return this.frandomRange(-1,1)}crandomOpen(){let t=Number.EPSILON;return this.frandomRange(-1+t,1)}irandomUint32(){return this.mt.nextUint32()}irandomRange(t,e){if(e-t<=1)return t;let r=e-t,n=mu-mu%r,i;do i=this.mt.nextUint32();while(i>=n);return t+i%r}irandom(t){return t<=0?0:this.irandomRange(0,t)}randomTimeRange(t,e){return e<=t?t:this.irandomRange(t,e)}randomTime(t){return this.irandom(t)}randomIndex(t){return this.irandom(t.length)}getState(){return{mt:this.mt.getState()}}setState(t){this.mt.setState(t.mt)}};function Dg(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function bu(t,e){let r=new Float32Array(16);for(let n=0;n<4;n+=1)for(let i=0;i<4;i+=1)r[i*4+n]=t[0+n]*e[i*4+0]+t[4+n]*e[i*4+1]+t[8+n]*e[i*4+2]+t[12+n]*e[i*4+3];return r}function th(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 rh(t,e){let r=Dg();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 Er=1,bn=2;var xu=8,vu=16,kg=32;var Ug=16384;var Js=65536,nh=1<<17,zg=1<<18,Og=1<<19,Ng=1<<20,Gg=1<<21,Vg=1<<22,Hg=1<<23,$2=1<<24,el=1<<25,Wg=1<<26,K2=1<<27,Y2=1<<28,q2=1<<29,tl=1<<30,Z2=1<<31;var xn=0;var vn=4,Zr=8,_n=16,Sn=32,rl=64;var j2=1<<25,Q2=1<<28,J2=1<<29,eM=1<<30,tM=1<<31;var rM=Er|bn,nM=Er|Js|bn|el|tl,iM=Er|Js|bn,aM=Er|nh|bn|el|tl,oM=kg|xu|vu,sM=Er|vu|xu,Xg=Er|el|tl|bn|Wg,lM=zg|Og|Ng|Gg|Vg|Hg,cM=Er|xu|vu|el|tl,uM=Er|Js|bn,dM=Er|bn,fM=Er|Js|bn|nh,hM=Xg|Ug;var mM=Number.MAX_SAFE_INTEGER-1;var nl=(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))(nl||{});var il=256;var _u=256,Su=8192,al=2048,wu=512,Mu=256,Au=il*2,Eu=256,pu=32,io=96;var ne=(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+Su]="Sounds",t[t.Images=t.Sounds+al]="Images",t[t.Lights=t.Images+wu]="Lights",t[t.ShadowLights=t.Lights+_u]="ShadowLights",t[t.Items=t.ShadowLights+Eu]="Items",t[t.Players=t.Items+Mu]="Players",t[t.PlayerSkins=t.Players]="PlayerSkins",t[t.General=t.Players+il]="General",t[t.WheelWeapons=t.General+Au]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+pu]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+pu]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+pu]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(ne||{}),ih=ne.MaxConfigStrings;function ah(t){return t>=5&&t<59?io*(59-t):t>=ne.General&&t<ne.WheelWeapons?io*(ne.MaxConfigStrings-t):io}var pM=ne.Sounds,gM=ne.Images,yM=ne.Lights,bM=ne.Items,xM=ne.Players,vM=ne.General,$g={};Mg($g,{addReplayFrame:()=>Zg,createReplaySession:()=>qg,deserializeReplay:()=>Yg,serializeReplay:()=>Kg});function Kg(t){return JSON.stringify(t,null,2)}function Yg(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 qg(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function Zg(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var C=(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))(C||{}),oi=(t=>(t[t.bad=0]="bad",t[t.nop=1]="nop",t[t.move=2]="move",t[t.userinfo=3]="userinfo",t[t.stringcmd=4]="stringcmd",t))(oi||{}),O=(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))(O||{});var oh=64;var jg=12,Qg=9,_M=Math.ceil(jg*Qg/16),Jg=23,ey=2,SM=Math.ceil(Jg*ey/16);function sh(t,e){t.writeByte(e.msec),t.writeByte(e.buttons),t.writeAngle16(e.angles.x),t.writeAngle16(e.angles.y),t.writeAngle16(e.angles.z),t.writeShort(e.forwardmove),t.writeShort(e.sidemove),t.writeShort(e.upmove),t.writeByte(e.impulse),t.writeByte(0)}var ty=[0,145,227,114,7,150,228,117,14,159,237,124,9,152,234,123,28,141,255,110,27,138,248,105,18,131,241,96,21,132,246,103,56,169,219,74,63,174,220,77,54,167,213,68,49,160,210,67,36,181,199,86,35,178,192,81,42,187,201,88,45,188,206,95,112,225,147,2,119,230,148,5,126,239,157,12,121,232,154,11,108,253,143,30,107,250,136,25,98,243,129,16,101,244,134,23,72,217,171,58,79,222,172,61,70,215,165,52,65,208,162,51,84,197,183,38,83,194,176,33,90,203,185,40,93,204,190,47,224,113,3,146,231,118,4,149,238,127,13,156,233,120,10,155,252,109,31,142,251,106,24,137,242,99,17,128,245,100,22,135,216,73,59,170,223,78,60,173,214,71,53,164,209,64,50,163,196,85,39,182,195,82,32,177,202,91,41,184,205,92,46,191,144,1,115,226,151,6,116,229,158,15,125,236,153,8,122,235,140,29,111,254,139,26,104,249,130,19,97,240,133,20,102,247,168,57,75,218,175,62,76,221,166,55,69,212,161,48,66,211,180,37,86,199,179,34,80,193,186,43,89,200,189,44,94,207];function lh(t){let e=0;for(let r=0;r<t.length;r++)e=ty[(e^t[r])&255];return e}var Mt=1,At=2,Et=4,Tt=8,Lt=16,Pt=32,ao=64,Tr=128,si=256,Rt=512,Ct=1024,Bt=2048,Ze=4096,Lr=8192,je=16384,Pr=32768,Qe=65536,Ft=1<<17,Je=1<<18,et=1<<19,It=1<<20,Dt=1<<21,kt=1<<22,Rr=1<<23,br=1<<24,tt=1<<25,Ut=1<<26,zt=1<<27,Cr=1<<28,Br=1<<29,Fr=1<<30,Vi=-2147483648,wn=1,Mn=2,An=4;var En=class{constructor(t){te(this,"view"),te(this,"offset"),te(this,"length"),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=yr[e];t.x=r[0],t.y=r[1],t.z=r[2]}},li=class{constructor(t=1400){te(this,"buffer"),te(this,"view"),te(this,"offset"),te(this,"fixed"),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<yr.length;n++){let i=yr[n],a=t.x*i[0]+t.y*i[1]+t.z*i[2];a>e&&(e=a,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}},oo=class{constructor(t=1024){te(this,"buffer"),te(this,"view"),te(this,"offset"),this.buffer=new Uint8Array(t),this.view=new DataView(this.buffer.buffer),this.offset=0}ensureCapacity(t){if(this.offset+t>this.buffer.length){let e=Math.max(this.buffer.length*2,this.offset+t),r=new Uint8Array(e);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer)}}getData(){return this.buffer.slice(0,this.offset)}writeByte(t){this.ensureCapacity(1),this.view.setUint8(this.offset,t),this.offset+=1}writeChar(t){this.ensureCapacity(1),this.view.setInt8(this.offset,t),this.offset+=1}writeShort(t){this.ensureCapacity(2),this.view.setInt16(this.offset,t,!0),this.offset+=2}writeUShort(t){this.ensureCapacity(2),this.view.setUint16(this.offset,t,!0),this.offset+=2}writeLong(t){this.ensureCapacity(4),this.view.setInt32(this.offset,t,!0),this.offset+=4}writeFloat(t){this.ensureCapacity(4),this.view.setFloat32(this.offset,t,!0),this.offset+=4}writeString(t){let e=t.length+1;this.ensureCapacity(e);for(let r=0;r<t.length;r++)this.view.setUint8(this.offset+r,t.charCodeAt(r));this.view.setUint8(this.offset+t.length,0),this.offset+=e}writeData(t){this.ensureCapacity(t.length),this.buffer.set(t,this.offset),this.offset+=t.length}writeCoord(t){this.writeShort(Math.round(t*8))}writeAngle(t){this.writeByte(Math.round(t*256/360)&255)}writeAngle16(t){this.writeShort(Math.round(t*65536/360))}writeDir(t,e,r){let n=0,i=-999999,a=Math.sqrt(t*t+e*e+r*r);if(a>0){t/=a,e/=a,r/=a;for(let o=0;o<162;o++){let s=t*yr[o][0]+e*yr[o][1]+r*yr[o][2];s>i&&(i=s,n=o)}}this.writeByte(n)}},ai=class ot{constructor(){te(this,"qport",0),te(this,"incomingSequence",0),te(this,"outgoingSequence",0),te(this,"incomingAcknowledged",0),te(this,"incomingReliableAcknowledged",!1),te(this,"incomingReliableSequence",0),te(this,"outgoingReliableSequence",0),te(this,"reliableMessage"),te(this,"reliableLength",0),te(this,"fragmentSendOffset",0),te(this,"fragmentBuffer",null),te(this,"fragmentLength",0),te(this,"fragmentReceived",0),te(this,"lastReceived",0),te(this,"lastSent",0),te(this,"remoteAddress",null),this.reliableMessage=new li(ot.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>ot.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>ot.FRAGMENT_SIZE&&(r=ot.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let a=ot.PACKET_HEADER,o=r>0?2+(n?8:0):0,s=e?e.length:0;a+o+r+s>ot.MAX_MSGLEN&&(s=ot.MAX_MSGLEN-a-o-r,s<0&&(s=0));let c=new ArrayBuffer(a+o+r+s),l=new DataView(c),u=new Uint8Array(c),d=this.outgoingSequence;r>0&&(d|=2147483648,(this.outgoingReliableSequence&1)!==0&&(d|=1073741824)),l.setUint32(0,d,!0);let f=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(f|=2147483648),l.setUint32(4,f,!0),l.setUint16(8,this.qport,!0);let m=a;if(r>0){let p=r;n&&(p|=32768),l.setUint16(m,p,!0),m+=2,n&&(l.setUint32(m,i,!0),m+=4,l.setUint32(m,this.reliableLength,!0),m+=4);let g=this.reliableMessage.getBuffer().subarray(i,i+r);u.set(g,m),m+=r}if(e&&s>0){let p=e.slice(0,s);u.set(p,m)}return u}process(e){if(e.length<4)return null;this.lastReceived=Date.now();let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(0,!0);if(n===4294967295)return e.subarray(4);if(e.length<ot.PACKET_HEADER)return null;let i=r.getUint32(4,!0),a=r.getUint16(8,!0);if(this.qport!==a)return null;let o=n&1073741823;if((o-this.incomingSequence|0)<=0)return null;this.incomingSequence=o;let s=i&2147483647,c=(i&2147483648)!==0;if(s>this.incomingAcknowledged&&(this.incomingAcknowledged=s),this.reliableLength>0){let p=c?1:0,y=this.outgoingReliableSequence&1;p!==y&&(this.reliableLength=0,this.reliableMessage.reset(),this.outgoingReliableSequence^=1,this.fragmentSendOffset=0)}let l=(n&2147483648)!==0,u=(n&1073741824)!==0?1:0,d=ot.PACKET_HEADER,f=null;if(l){if(d+2>e.byteLength)return null;let p=r.getUint16(d,!0);d+=2;let y=(p&32768)!==0;p&=32767;let g=this.incomingReliableSequence&1;if(u===g)if(y){if(d+8>e.byteLength)return null;let b=r.getUint32(d,!0);d+=4;let _=r.getUint32(d,!0);if(d+=4,_>ot.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${ot.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),d+p>e.byteLength)return null;let x=e.subarray(d,d+p);b===this.fragmentReceived&&b+p<=_&&(this.fragmentBuffer.set(x,b),this.fragmentReceived+=p,this.fragmentReceived>=_&&(f=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,d+p>e.byteLength)return null;f=e.slice(d,d+p)}d+=p}let m=e.slice(d);if(f&&f.length>0){let p=f.length+m.length,y=new Uint8Array(p);return y.set(f,0),y.set(m,f.length),y}return m||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(e){if(this.reliableLength+1>ot.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(e),this.reliableLength++}writeReliableShort(e){if(this.reliableLength+2>ot.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(e),this.reliableLength+=2}writeReliableLong(e){if(this.reliableLength+4>ot.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>ot.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}};te(ai,"MAX_MSGLEN",1400);te(ai,"FRAGMENT_SIZE",1024);te(ai,"PACKET_HEADER",10);te(ai,"HEADER_OVERHEAD",ai.PACKET_HEADER+2);te(ai,"MAX_RELIABLE_BUFFER",262144);var ch=ai;var uh=(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))(uh||{}),wM=Object.keys(uh).length/2;var so=32,Ir=(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))(Ir||{}),Tu=-1,lo=0,Lu=1,Pu=2,Ru=3,Hi=80,Cu=.003;function Wi(t){return t*.001}function ci(t){let e=Wi(t);return e<=0?Number.POSITIVE_INFINITY:Hi+1/e}var co=class{constructor({name:e,defaultValue:r,description:n,flags:i=nl.None,onChange:a}){h(this,"name");h(this,"defaultValue");h(this,"description");h(this,"flags");h(this,"_value");h(this,"latched");h(this,"onChange");h(this,"modifiedCount",0);this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=a}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&nl.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)}},Xi=class{constructor(){h(this,"cvars",new Map);h(this,"onCvarChange")}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=e.onChange,i=(o,s)=>{n?.(o,s),this.onCvarChange?.(o.name,o.string)},a=new co({...e,onChange:i});return this.cvars.set(e.name,a),a}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 $i=class{constructor(e,r,n={}){this.game=e;this.client=r;h(this,"loop");h(this,"startTimeMs");h(this,"previousFrame");h(this,"latestFrame");h(this,"started",!1);h(this,"paused_",!1);h(this,"latestCommand");h(this,"commands",new Gi);h(this,"cvars",new Xi);h(this,"stepSimulation",e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)});h(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 ii({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs}),this.commands.registerAutocompleteProvider(()=>this.cvars.list().map(a=>a.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 Ki=class{constructor(e){h(this,"registry");h(this,"system");h(this,"music");h(this,"client");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,a,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:a,timeOffsetMs:o}),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,a){let o=this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:a,looping:!0});return this.triggerSubtitle(n),o}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 uo=class{constructor(e,r){this.engine=e;this.host=r;h(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 dh(t,e,r,n,i){let a=new Ki({...n,client:r}),o=new $i(e,r,i);return{runtime:new uo(t,o),audio:a}}function ry(t){if(t<0||t>=ne.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${ne.MaxConfigStrings-1})`)}function fh(t,e){let r=ah(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${io} chars per slot`)}var Yi=class{constructor(){h(this,"values",new Map);h(this,"modelCursor",ne.Models);h(this,"soundCursor",ne.Sounds);h(this,"imageCursor",ne.Images);h(this,"lightCursor",ne.Lights);h(this,"shadowLightCursor",ne.ShadowLights);h(this,"itemCursor",ne.Items);h(this,"playerSkinCursor",ne.PlayerSkins);h(this,"generalCursor",ne.General)}set(e,r){return ry(e),fh(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(ih).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,ne.Models,Su,"modelCursor")}soundIndex(e){return this.register(e,ne.Sounds,al,"soundCursor")}findSoundIndex(e){for(let r=ne.Sounds;r<ne.Sounds+al;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,ne.Images,wu,"imageCursor")}lightIndex(e){return this.register(e,ne.Lights,_u,"lightCursor")}shadowLightIndex(e){return this.register(e,ne.ShadowLights,Eu,"shadowLightCursor")}itemIndex(e){return this.register(e,ne.Items,Mu,"itemCursor")}playerSkinIndex(e){return this.register(e,ne.PlayerSkins,il,"playerSkinCursor")}generalIndex(e){return this.register(e,ne.General,Au,"generalCursor")}register(e,r,n,i){for(let s=r;s<r+n;s+=1)if(this.values.get(s)===e)return s;let a=this[i],o=r+n;if(a>=o)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return fh(a,e),this.values.set(a,e),this[i]=a+1,a}};var ny="PACK";function iy(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function Le(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function ay(){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 oy=ay();function hh(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=oy[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Ne=class extends Error{},qi=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;h(this,"entries");h(this,"checksum");h(this,"size");this.entries=new Map(n.map(a=>[a.name,a])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Ne("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!==ny)throw new Ne(`Invalid PAK header magic: ${i}`);let a=n.getInt32(4,!0),o=n.getInt32(8,!0);if(a<12)throw new Ne(`Invalid directory offset: ${a}`);if(o<0||o%64!==0)throw new Ne(`Invalid directory length: ${o}`);if(a+o>r.byteLength)throw new Ne("Directory exceeds buffer length");let c=o/64,l=[],u=new Map;for(let d=0;d<c;d+=1){let f=a+d*64,m=iy(n,f,56),p=Le(m),y=n.getInt32(f+56,!0),g=n.getInt32(f+60,!0);if(y<0||g<0||y+g>r.byteLength)throw new Ne(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${g})`);if(!p)throw new Ne(`Entry ${d} has an empty name`);let b={name:p,offset:y,length:g};u.set(p,b)}return l.push(...u.values()),new t(e,r,l,hh(new Uint8Array(r)))}getEntry(e){return this.entries.get(Le(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 Ne(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function mh(t){return hh(new Uint8Array(t))}var sy="PACK",ph=12,Bu=64;function gh(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}var ol=class{constructor(e){this.source=e;h(this,"entries",null)}async readDirectory(){if(this.entries)return Array.from(this.entries.values());let e=await this.readChunk(0,ph),r=new DataView(e),n=String.fromCharCode(r.getUint8(0),r.getUint8(1),r.getUint8(2),r.getUint8(3));if(n!==sy)throw new Ne(`Invalid PAK header magic: ${n}`);let i=r.getInt32(4,!0),a=r.getInt32(8,!0);if(i<ph)throw new Ne(`Invalid directory offset: ${i}`);if(a<0||a%Bu!==0)throw new Ne(`Invalid directory length: ${a}`);let o=await this.readChunk(i,a),s=new DataView(o),c=a/Bu,l=new Map;for(let u=0;u<c;u++){let d=u*Bu,f=this.readCString(s,d,56),m=gh(f),p=s.getInt32(d+56,!0),y=s.getInt32(d+60,!0);p<0||y<0||p+y>this.source.size,m&&l.set(m,{name:m,offset:p,length:y})}return this.entries=l,Array.from(l.values())}async readFile(e){let r=await this.getEntry(e);if(!r)throw new Ne(`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 Ne(`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(gh(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 a=0;a<n;a+=1){let o=e.getUint8(r+a);if(o===0)break;i.push(o)}return String.fromCharCode(...i)}};var Fu=12,yh=64,sl=class t{constructor(){h(this,"entries",new Map)}addFile(e,r){let n=Le(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(Le(e))}build(){let e=0;for(let f of this.entries.values())e+=f.byteLength;let r=this.entries.size*yh,n=Fu+e+r,i=new Uint8Array(n),a=new DataView(i.buffer);a.setUint8(0,80),a.setUint8(1,65),a.setUint8(2,67),a.setUint8(3,75);let o=Fu+e;a.setInt32(4,o,!0),a.setInt32(8,r,!0);let s=Fu,c=new Map,l=Array.from(this.entries.keys()).sort();for(let f of l){let m=this.entries.get(f);c.set(f,s),i.set(m,s),s+=m.byteLength}let u=o,d=new TextEncoder;for(let f of l){let m=this.entries.get(f),p=d.encode(f);if(p.length>56)throw new Error(`Path too long after encoding: ${f}`);for(let y=0;y<56;y++)y<p.length?a.setUint8(u+y,p[y]):a.setUint8(u+y,0);a.setInt32(u+56,c.get(f),!0),a.setInt32(u+60,m.byteLength,!0),u+=yh}return i}static buildFromEntries(e){let r=new t;for(let[n,i]of e)r.addFile(n,i);return r.build()}};var Iu=(o=>(o.Texture="texture",o.Sound="sound",o.Model="model",o.Map="map",o.Sprite="sprite",o.ConfigString="configString",o))(Iu||{}),ll=class{constructor(){h(this,"tracking",!1);h(this,"entries",[]);h(this,"currentFrame",0);h(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 cl=class{constructor(e=[]){h(this,"mounts",[]);h(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,a)=>a.priority-i.priority);for(let i of e.listEntries()){let a=Le(i.name),o={archive:e,entry:i,priority:r};this.files.has(a)||this.files.set(a,[]);let s=this.files.get(a),c=s.findIndex(l=>l.archive===e);c!==-1&&s.splice(c,1),s.unshift(o),s.sort((l,u)=>u.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(Le(e))}getSource(e){let r=this.files.get(Le(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,a=i.readFile(e),o=0,s=a.length;return new ReadableStream({pull(c){if(o>=s){c.close();return}let l=Math.min(o+r,s),u=a.slice(o,l);o=l,c.enqueue(u)}})}async readTextFile(e){let r=await this.readFile(e);return new TextDecoder("utf-8").decode(r)}list(e=""){let r=Le(e).replace(/\/+$|^\//g,""),n=[],i=new Set,a=r?`${r}/`:"";for(let[o,s]of this.files){let c=s[0];if(r&&!c.entry.name.startsWith(a))continue;let l=r?c.entry.name.slice(a.length):c.entry.name,u=l.indexOf("/");u===-1?n.push({path:c.entry.name,size:c.entry.length,sourcePak:c.archive.name}):i.add(l.slice(0,u))}return n.sort((o,s)=>o.path.localeCompare(s.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,a]of this.files){let o=a[0];o.entry.name.toLowerCase().endsWith(r)&&n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name})}return n.sort((i,a)=>i.path.localeCompare(a.path))}listByExtension(e){let r=new Set(e.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let[i,a]of this.files){let o=a[0],s=o.entry.name.toLowerCase();for(let c of r)if(s.endsWith(c)){n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name});break}}return n.sort((i,a)=>i.path.localeCompare(a.path))}searchFiles(e){let r=[];for(let[n,i]of this.files){let a=i[0];e.test(a.entry.name)&&r.push({path:a.entry.name,size:a.entry.length,sourcePak:a.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 a=i[0];return{path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name}}).sort((i,a)=>i.path.localeCompare(a.path));for(let i of n){let a=i.path.split("/"),o=a.pop(),s="",c=e;for(let l of a){let u=s;s=s?`${s}/${l}`:l;let d=r.get(s);d||(d={name:l,path:s,files:[],directories:[]},c.directories.push(d),r.set(s,d)),c=d}c.files.push(i)}return e}};var Du=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"}]),ui=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"}},ul=class{constructor(e=Du){h(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,a="size"in e?e.size:void 0,o=this.known.get(n);return o?o.checksum!==i?{name:n,checksum:i,expectedChecksum:o.checksum,status:"mismatch",size:a,description:o.description}:{name:n,checksum:i,expectedChecksum:o.checksum,status:"valid",size:a,description:o.description}:{name:n,checksum:i,status:"unknown",size:a}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new ui(n);return n}normalizePakName(e){let r=Le(e),n=r.split("/"),i=n.pop()??r,a=n.pop();return a?`${i}@${a}`:i}};var Tn=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 ly(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=a=>{e?.({file:"blob",loadedBytes:a.loaded,totalBytes:a.total||t.size,state:"reading"})},i.onload=()=>{let a=i.result;a instanceof ArrayBuffer?r(a):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:s,value:c}=await r.read();if(s)break;if(!c)continue;let l=c;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let a=new Uint8Array(i),o=0;for(let s of n)a.set(s,o),o+=s.byteLength;return a.buffer}throw new Tn("blob",new Error("Unsupported Blob type"))}async function cy(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 ly(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 dl(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,a=n.enforceValidation??!!n.validator,o=n.allowUnknownPaks??!0,s=n.stopOnError??!1,c=[];for(let l of e)try{let u=await cy(l,n.onProgress),d=qi.fromArrayBuffer(l.name,u),f=n.validator?.validateArchive(d);if(f){n.onValidationResult?.(f);let m=f.status==="mismatch",p=f.status==="unknown";if(m&&a||p&&!o){let y=new ui(f);if(n.onError?.(l.name,y),s)throw new Tn(l.name,y);c.push({archive:d,mounted:!1,validation:f});continue}}if(t.mountPak(d),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(d)}catch(m){if(n.onError?.(l.name,m),s)throw new Tn(l.name,m)}n.onProgress?.({file:l.name,loadedBytes:u.byteLength,totalBytes:u.byteLength,state:"parsed"}),c.push({archive:d,mounted:!0,validation:f})}catch(u){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,u),s)throw new Tn(l.name,u)}return c}var Ln=class{constructor(e,r=1/0,n=()=>0){this._capacity=e;this._maxMemory=r;this.sizeCalculator=n;h(this,"map",new Map);h(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}get capacity(){return this._capacity}set capacity(e){if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero");this._capacity=e,this.evict()}get maxMemory(){return this._maxMemory}set maxMemory(e){this._maxMemory=e,this.evict()}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 uy(t){return Array.isArray(t)?t:Array.from(t)}function ku(t){return uy(t).map(e=>({name:e.name,data:e}))}async function bh(t,e,r){let n=ku(e);return dl(t,n,r??{})}function xh(t,e){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let a=i.dataTransfer?.files;a&&a.length>0&&e(Array.from(a))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function vh(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 dy="IBSP",fy=38,Sh=19,hy=8+Sh*8,Uu=(x=>(x[x.Entities=0]="Entities",x[x.Planes=1]="Planes",x[x.Vertices=2]="Vertices",x[x.Visibility=3]="Visibility",x[x.Nodes=4]="Nodes",x[x.TexInfo=5]="TexInfo",x[x.Faces=6]="Faces",x[x.Lighting=7]="Lighting",x[x.Leafs=8]="Leafs",x[x.LeafFaces=9]="LeafFaces",x[x.LeafBrushes=10]="LeafBrushes",x[x.Edges=11]="Edges",x[x.SurfEdges=12]="SurfEdges",x[x.Models=13]="Models",x[x.Brushes=14]="Brushes",x[x.BrushSides=15]="BrushSides",x[x.Pop=16]="Pop",x[x.Areas=17]="Areas",x[x.AreaPortals=18]="AreaPortals",x))(Uu||{}),fe=class extends Error{},Zi=class{constructor(e,r={}){this.vfs=e;this.options=r}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);if(n.set(new Uint8Array(r)),this.options.useWorker&&typeof Worker<"u")try{let i=await this.parseInWorker(n.buffer);return wh(i)}catch(i){console.warn("BSP worker parsing failed, falling back to main thread",i)}return fo(n.buffer)}parseInWorker(e){return new Promise((r,n)=>{if(!this.options.workerPath){n(new Error("No worker path provided"));return}let i=new Worker(this.options.workerPath,{type:"module"});i.onmessage=a=>{let{type:o,data:s,message:c}=a.data;o==="success"?(r(this.rehydrateData(s)),i.terminate()):(n(new Error(c)),i.terminate())},i.onerror=a=>{n(a),i.terminate()},i.postMessage(e,[e])})}rehydrateData(e){if(e.entities&&!e.entities.getUniqueClassnames){let r=e.entities;r.getUniqueClassnames=function(){let n=new Set;for(let i of this.entities)i.classname&&n.add(i.classname);return Array.from(n).sort()}}return e}};function fo(t){let e=my(t);return wh(e)}function wh(t){return{...t,pickEntity(e){let r=null,n=1/0;for(let i of t.entities.entities){let a=i.properties.model;if(!a||!a.startsWith("*"))continue;let o=parseInt(a.substring(1),10);if(isNaN(o)||o<0||o>=t.models.length)continue;let s=t.models[o],c=py(e.origin,e.direction,s.mins,s.maxs);c!==null&&c<n&&(n=c,r={entity:i,model:s,distance:c})}return r},findLeaf(e){let n=t.models[0].headNode;for(;n>=0;){let i=t.nodes[n],a=t.planes[i.planeIndex];a.normal[0]*e[0]+a.normal[1]*e[1]+a.normal[2]*e[2]-a.dist>=0?n=i.children[0]:n=i.children[1]}return t.leafs[-(n+1)]},calculatePVS(e){let r=this.findLeaf(e);if(!(r.cluster===-1||!t.visibility)&&!(r.cluster<0||r.cluster>=t.visibility.clusters.length))return t.visibility.clusters[r.cluster].pvs}}}function my(t){if(t.byteLength<hy)throw new fe("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!==dy)throw new fe(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==fy)throw new fe(`Unsupported BSP version ${n}`);let i=new Map;for(let T=0;T<Sh;T+=1){let L=e.getInt32(8+T*8,!0),A=e.getInt32(12+T*8,!0);if(L<0||A<0||L+A>t.byteLength)throw new fe(`Invalid lump bounds for index ${T}`);i.set(T,{offset:L,length:A})}let a={version:n,lumps:i},o=gy(t,i.get(0)),s=by(t,i.get(1)),c=xy(t,i.get(2)),l=vy(t,i.get(4)),u=_y(t,i.get(5)),d=Sy(t,i.get(6)),f=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=Iy(d,i.get(7)),p=wy(t,i.get(8)),y=My(t,i.get(11)),g=Ay(t,i.get(12)),b=Ey(t,i.get(13)),_=Ty(t,i.get(14)),x=Ly(t,i.get(15)),v=By(t,i.get(9),i.get(10),p),S=Fy(t,i.get(3)),M=Py(t,i.get(17)),w=Ry(t,i.get(18));return{header:a,entities:o,planes:s,vertices:c,nodes:l,texInfo:u,faces:d,lightMaps:f,lightMapInfo:m,leafs:p,leafLists:v,edges:y,surfEdges:g,models:b,brushes:_,brushSides:x,visibility:S,areas:M,areaPortals:w}}function py(t,e,r,n){let i=0,a=1/0;for(let o=0;o<3;o++)if(Math.abs(e[o])<1e-8){if(t[o]<r[o]||t[o]>n[o])return null}else{let s=1/e[o],c=(r[o]-t[o])*s,l=(n[o]-t[o])*s;if(c>l){let u=c;c=l,l=u}if(i=Math.max(i,c),a=Math.min(a,l),i>a)return null}return i}function gy(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=yy(r),i=n.find(a=>a.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let a=new Set;for(let o of n)o.classname&&a.add(o.classname);return Array.from(a).sort()}}}function yy(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],a={},o=/"([^\"]*)"\s+"([^\"]*)"/g,s;for(;(s=o.exec(i))!==null;)a[s[1]]=s[2];e.push({classname:a.classname,properties:a})}return e}function by(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new fe("Plane lump has invalid length");let i=[];for(let a=0;a<n;a+=1){let o=[r.getFloat32(a*20,!0),r.getFloat32(a*20+4,!0),r.getFloat32(a*20+8,!0)],s=r.getFloat32(a*20+12,!0),c=r.getInt32(a*20+16,!0);i.push({normal:o,dist:s,type:c})}return i}function xy(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new fe("Vertex lump has invalid length");let i=[];for(let a=0;a<n;a+=1)i.push([r.getFloat32(a*12,!0),r.getFloat32(a*12+4,!0),r.getFloat32(a*12+8,!0)]);return i}function vy(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new fe("Node lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=[r.getInt32(s+4,!0),r.getInt32(s+8,!0)],u=[r.getInt16(s+12,!0),r.getInt16(s+14,!0),r.getInt16(s+16,!0)],d=[r.getInt16(s+18,!0),r.getInt16(s+20,!0),r.getInt16(s+22,!0)],f=r.getUint16(s+24,!0),m=r.getUint16(s+26,!0);a.push({planeIndex:c,children:l,mins:u,maxs:d,firstFace:f,numFaces:m})}return a}function _y(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new fe("TexInfo lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=[r.getFloat32(s,!0),r.getFloat32(s+4,!0),r.getFloat32(s+8,!0)],l=r.getFloat32(s+12,!0),u=[r.getFloat32(s+16,!0),r.getFloat32(s+20,!0),r.getFloat32(s+24,!0)],d=r.getFloat32(s+28,!0),f=r.getInt32(s+32,!0),m=r.getInt32(s+36,!0),p=new Uint8Array(t,e.offset+s+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),g=r.getInt32(s+72,!0);a.push({s:c,sOffset:l,t:u,tOffset:d,flags:f,value:m,texture:y,nextTexInfo:g})}return a}function Sy(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new fe("Face lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getUint16(s,!0),l=r.getInt16(s+2,!0),u=r.getInt32(s+4,!0),d=r.getInt16(s+8,!0),f=r.getInt16(s+10,!0),m=[r.getUint8(s+12),r.getUint8(s+13),r.getUint8(s+14),r.getUint8(s+15)],p=r.getInt32(s+16,!0);a.push({planeIndex:c,side:l,firstEdge:u,numEdges:d,texInfo:f,styles:m,lightOffset:p})}return a}function wy(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new fe("Leaf lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt16(s+4,!0),u=r.getInt16(s+6,!0),d=[r.getInt16(s+8,!0),r.getInt16(s+10,!0),r.getInt16(s+12,!0)],f=[r.getInt16(s+14,!0),r.getInt16(s+16,!0),r.getInt16(s+18,!0)],m=r.getUint16(s+20,!0),p=r.getUint16(s+22,!0),y=r.getUint16(s+24,!0),g=r.getUint16(s+26,!0);a.push({contents:c,cluster:l,area:u,mins:d,maxs:f,firstLeafFace:m,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:g})}return a}function My(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new fe("Edge lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({vertices:[r.getUint16(s,!0),r.getUint16(s+2,!0)]})}return a}function Ay(t,e){let r=e.length/4;if(r%1!==0)throw new fe("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let a=0;a<r;a+=1)i[a]=n.getInt32(a*4,!0);return i}function Ey(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new fe("Model lump has invalid length");let i=e.length/n,a=[];for(let o=0;o<i;o+=1){let s=o*n,c=[r.getFloat32(s,!0),r.getFloat32(s+4,!0),r.getFloat32(s+8,!0)],l=[r.getFloat32(s+12,!0),r.getFloat32(s+16,!0),r.getFloat32(s+20,!0)],u=[r.getFloat32(s+24,!0),r.getFloat32(s+28,!0),r.getFloat32(s+32,!0)],d=r.getInt32(s+36,!0),f=r.getInt32(s+40,!0),m=r.getInt32(s+44,!0);a.push({mins:c,maxs:l,origin:u,headNode:d,firstFace:f,numFaces:m})}return a}function Ty(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new fe("Brush lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({firstSide:r.getInt32(s,!0),numSides:r.getInt32(s+4,!0),contents:r.getInt32(s+8,!0)})}return a}function Ly(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new fe("Brush side lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({planeIndex:r.getUint16(s,!0),texInfo:r.getInt16(s+2,!0)})}return a}function Py(t,e){let r=new DataView(t,e.offset,e.length),n=8,i=e.length/n;if(i%1!==0)throw new fe("Area lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt32(s+4,!0);a.push({numAreaPortals:c,firstAreaPortal:l})}return a}function Ry(t,e){return Cy(t,e)}function Cy(t,e){let r=new DataView(t,e.offset,e.length),n=8,i=e.length/n;if(i%1!==0)throw new fe("AreaPortal lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt32(s+4,!0);a.push({portalNumber:c,otherArea:l})}return a}function By(t,e,r,n){let i=[],a=[],o=e.length/2,s=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let u of n){if(u.firstLeafFace+u.numLeafFaces>o)throw new fe("Leaf faces reference data past lump bounds");if(u.firstLeafBrush+u.numLeafBrushes>s)throw new fe("Leaf brushes reference data past lump bounds");let d=[];for(let m=0;m<u.numLeafFaces;m+=1)d.push(c.getUint16((u.firstLeafFace+m)*2,!0));let f=[];for(let m=0;m<u.numLeafBrushes;m+=1)f.push(l.getUint16((u.firstLeafBrush+m)*2,!0));i.push(d),a.push(f)}return{leafFaces:i,leafBrushes:a}}function Fy(t,e){if(e.length===0)return;if(e.length<4)throw new fe("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 fe("Visibility lump truncated");let a=4,o=[];for(let s=0;s<n;s+=1){let c=r.getInt32(a,!0),l=r.getInt32(a+4,!0);a+=8;let u=e.offset+c,d=e.offset+l,f=e.offset+e.length;if(c<0||l<0||u>=f||d>=f)throw new fe("Visibility offsets out of range");o.push({pvs:_h(t,u,n,e),phs:_h(t,d,n,e)})}return{numClusters:n,clusters:o}}function _h(t,e,r,n){let i=Math.ceil(r/8),a=new Uint8Array(i),o=new Uint8Array(t),s=e,c=0,l=n.offset+n.length;for(;c<i;){if(s>=l)throw new fe("Visibility data truncated");let u=o[s++];if(u!==0){a[c++]=u;continue}if(s>=l)throw new fe("Visibility run exceeds lump bounds");let d=o[s++];for(let f=0;f<d&&c<i;f+=1)a[c++]=0}return a}function Iy(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function fl(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 Dy=844121161,ky=8,Mh=68,st=class extends Error{},ji=class{constructor(e){this.vfs=e;h(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=zu(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Ah(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function ho(t,e,r,n){if(r!==0&&(e<Mh||e+r>t.byteLength))throw new st(`${n} section is out of bounds`)}function Uy(t){if(t.byteLength<Mh)throw new st("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==Dy)throw new st(`Invalid MD2 ident: ${r}`);if(n!==ky)throw new st(`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},a=40+i.numVertices*4;if(i.frameSize!==a)throw new st(`Unexpected frame size ${i.frameSize}, expected ${a}`);if(i.offsetEnd>t.byteLength)throw new st("MD2 offset_end exceeds buffer length");return i}function zy(t,e){let r=e.numSkins*64;ho(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let a=0;a<e.numSkins;a+=1)i.push({name:Ah(n,a*64,64)});return i}function Oy(t,e){let r=e.numTexCoords*4;ho(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let a=0;a<e.numTexCoords;a+=1){let o=a*4;i.push({s:n.getInt16(o,!0),t:n.getInt16(o+2,!0)})}return i}function Ny(t,e){let r=e.numTriangles*12;ho(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let a=0;a<e.numTriangles;a+=1){let o=a*12,s=[n.getUint16(o,!0),n.getUint16(o+2,!0),n.getUint16(o+4,!0)],c=[n.getUint16(o+6,!0),n.getUint16(o+8,!0),n.getUint16(o+10,!0)];if(s.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new st("Triangle references out of range vertex or texcoord");i.push({vertexIndices:s,texCoordIndices:c})}return i}function Gy(t,e){let r=e.numFrames*e.frameSize;ho(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let a=e.offsetFrames+i*e.frameSize,o=new DataView(t,a,e.frameSize),s={x:o.getFloat32(0,!0),y:o.getFloat32(4,!0),z:o.getFloat32(8,!0)},c={x:o.getFloat32(12,!0),y:o.getFloat32(16,!0),z:o.getFloat32(20,!0)},l=Ah(o,24,16),u=[],d=1/0,f=1/0,m=1/0,p=-1/0,y=-1/0,g=-1/0;for(let b=0;b<e.numVertices;b+=1){let _=40+b*4,x=o.getUint8(_)*s.x+c.x,v=o.getUint8(_+1)*s.y+c.y,S=o.getUint8(_+2)*s.z+c.z;x<d&&(d=x),v<f&&(f=v),S<m&&(m=S),x>p&&(p=x),v>y&&(y=v),S>g&&(g=S);let M={x,y:v,z:S},w=o.getUint8(_+3),T=yr[w];if(!T)throw new st(`Invalid normal index ${w} in frame ${l}`);let L={x:T[0],y:T[1],z:T[2]};u.push({position:M,normalIndex:w,normal:L})}n.push({name:l,vertices:u,minBounds:{x:d,y:f,z:m},maxBounds:{x:p,y,z:g}})}return n}function Vy(t,e){let r=e.numGlCommands*4;if(ho(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],a=0;for(;;){if(a+4>r)throw new st("GL command list ended unexpectedly");let o=n.getInt32(a,!0);if(a+=4,o===0)break;let s=Math.abs(o),c=[],l=s*12;if(a+l>r)throw new st("GL command vertex block exceeds buffer");for(let u=0;u<s;u+=1){let d=n.getFloat32(a,!0),f=n.getFloat32(a+4,!0),m=n.getInt32(a+8,!0);if(a+=12,m<0||m>=e.numVertices)throw new st("GL command references invalid vertex index");c.push({s:d,t:f,vertexIndex:m})}i.push({mode:o>0?"strip":"fan",vertices:c})}if(a!==r)throw new st("GL command list did not consume expected data");return i}function zu(t){let e=Uy(t),r=zy(t,e),n=Oy(t,e),i=Ny(t,e),a=Gy(t,e),o=Vy(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:a,glCommands:o}}function Eh(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,a=r;for(;a+1<t.length&&(t[a+1].name.replace(/\d+$/,"")||t[a+1].name)===i;)a+=1;e.push({name:i,firstFrame:r,lastFrame:a}),r=a+1}return e}var Th=860898377,Hy=15,rr=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function mo(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function Wy(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 hl(t,e,r,n){if(e<0||e+r>n)throw new rr(`${t} exceeds buffer bounds`)}function Xy(t){let e=t.getInt32(0,!0);if(e!==Th)throw new rr(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==Hy)throw new rr(`Unsupported MD3 version: ${r}`);let n=mo(t,8,64),i=t.getInt32(72,!0),a=t.getInt32(76,!0),o=t.getInt32(80,!0),s=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),u=t.getInt32(96,!0),d=t.getInt32(100,!0),f=t.getInt32(104,!0);if(a<=0||s<0||o<0)throw new rr("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:a,numTags:o,numSurfaces:s,numSkins:c,ofsFrames:l,ofsTags:u,ofsSurfaces:d,ofsEnd:f,magic:e}}function $y(t,e){let r=[];hl("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let a=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(a,!0),y:t.getFloat32(a+4,!0),z:t.getFloat32(a+8,!0)},maxBounds:{x:t.getFloat32(a+12,!0),y:t.getFloat32(a+16,!0),z:t.getFloat32(a+20,!0)},localOrigin:{x:t.getFloat32(a+24,!0),y:t.getFloat32(a+28,!0),z:t.getFloat32(a+32,!0)},radius:t.getFloat32(a+36,!0),name:mo(t,a+40,16)})}return r}function Ky(t,e){let r=[],i=e.numFrames*e.numTags*112;hl("Tags",e.ofsTags,i,t.byteLength);for(let a=0;a<e.numFrames;a+=1){let o=[];for(let s=0;s<e.numTags;s+=1){let c=e.ofsTags+(a*e.numTags+s)*112,l=c+64,u=l+12;o.push({name:mo(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(u,!0),y:t.getFloat32(u+4,!0),z:t.getFloat32(u+8,!0)},{x:t.getFloat32(u+12,!0),y:t.getFloat32(u+16,!0),z:t.getFloat32(u+20,!0)},{x:t.getFloat32(u+24,!0),y:t.getFloat32(u+28,!0),z:t.getFloat32(u+32,!0)}]})}r.push(o)}return r}function Yy(t,e){let r=t.getInt32(e,!0);if(r!==Th)throw new rr(`Invalid surface ident at ${e}: ${r}`);let n=mo(t,e+4,64),i=t.getInt32(e+68,!0),a=t.getInt32(e+72,!0),o=t.getInt32(e+76,!0),s=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),u=t.getInt32(e+92,!0),d=t.getInt32(e+96,!0),f=t.getInt32(e+100,!0),m=t.getInt32(e+104,!0);if(a<=0||s<=0||c<=0)throw new rr(`Invalid surface counts for ${n}`);let p=m;hl(`Surface ${n}`,e,p,t.byteLength);let y=[],g=e+l;for(let w=0;w<c;w+=1){let T=g+w*12;y.push({indices:[t.getInt32(T,!0),t.getInt32(T+4,!0),t.getInt32(T+8,!0)]})}let b=[],_=e+u;for(let w=0;w<o;w+=1){let T=_+w*68;b.push({name:mo(t,T,64),shaderIndex:t.getInt32(T+64,!0)})}let x=[],v=e+d;for(let w=0;w<s;w+=1){let T=v+w*8;x.push({s:t.getFloat32(T,!0),t:t.getFloat32(T+4,!0)})}let S=[],M=e+f;for(let w=0;w<a;w+=1){let T=[];for(let L=0;L<s;L+=1){let A=M+(w*s+L)*8,R=t.getInt16(A,!0)/64,D=t.getInt16(A+2,!0)/64,k=t.getInt16(A+4,!0)/64,F=t.getUint16(A+6,!0);T.push({position:{x:R,y:D,z:k},latLng:F,normal:Wy(F)})}S.push(T)}return{surface:{name:n,flags:i,numFrames:a,shaders:b,triangles:y,texCoords:x,vertices:S},nextOffset:e+m}}function Ou(t){if(t.byteLength<108)throw new rr("MD3 buffer too small for header");let e=new DataView(t),r=Xy(e);hl("MD3 end",r.ofsEnd,0,t.byteLength);let n=$y(e,r),i=Ky(e,r),a=[],o=r.ofsSurfaces;for(let s=0;s<r.numSurfaces;s+=1){let{surface:c,nextOffset:l}=Yy(e,o);a.push(c),o=l}if(o!==r.ofsEnd)throw new rr("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:a}}var Qi=class{constructor(e){this.vfs=e;h(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=Ou(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var qy=844317769,Zy=2,Lh=64,Ph=12,Pn=class extends Error{};function jy(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function Nu(t){if(t.byteLength<Ph)throw new Pn("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!==qy)throw new Pn(`Invalid Sprite ident: ${r}`);if(n!==Zy)throw new Pn(`Unsupported Sprite version: ${n}`);let a=[],o=16+Lh,s=Ph;for(let c=0;c<i;c+=1){if(s+o>t.byteLength)throw new Pn("Sprite frame data exceeds buffer length");let l=e.getInt32(s,!0),u=e.getInt32(s+4,!0),d=e.getInt32(s+8,!0),f=e.getInt32(s+12,!0),m=jy(e,s+16,Lh);a.push({width:l,height:u,originX:d,originY:f,name:m}),s+=o}return{ident:r,version:n,numFrames:i,frames:a}}var Ji=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),Nu(n.buffer)}};function Rh(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 Ch(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 a=n?i%e:Math.min(i,e-1),o=Math.floor(a),s=t.sequence.start+o,c=o+1>=e?n?t.sequence.start:t.sequence.end:s+1,l=!n&&o>=e-1?0:a-o;return{frame0:s,frame1:c,lerp:l}}function Bh(t){return{sequence:t,time:0}}function Fh(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 po=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function ml(t){if(t.byteLength<100)throw new po("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),a=e.getInt32(36,!0),o=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],s=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(s).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),u=e.getInt32(92,!0),d=e.getInt32(96,!0);if(i<=0||a<=0)throw new po("Invalid WAL dimensions");let f=[],m=i,p=a;for(let y=0;y<o.length;y+=1){let g=o[y],b=Math.max(1,m*p|0);if(g<=0||g+b>t.byteLength)throw new po(`Invalid WAL mip offset for level ${y}`);let _=new Uint8Array(t,g,b);f.push({level:y,width:m,height:p,data:_}),m=Math.max(1,m>>1),p=Math.max(1,p>>1)}return{name:n,width:i,height:a,mipmaps:f,animName:c,flags:l,contents:u,value:d}}var di=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function go(t){if(t.byteLength<128)throw new di("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),a=e.getUint16(4,!0),o=e.getUint16(6,!0),s=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new di("Unsupported PCX encoding");if(i!==8)throw new di("Only 8bpp PCX files are supported");let l=s-a+1,u=c-o+1,d=e.getUint16(66,!0),f=t.byteLength-769;if(f<128||new DataView(t,f,1).getUint8(0)!==12)throw new di("Missing PCX palette");let m=new Uint8Array(t,f+1,768),p=new Uint8Array(t,128,f-128),y=new Uint8Array(l*u),g=0,b=0;for(let _=0;_<u;_+=1){let x=0;for(;x<d&&g<p.length;){let v=1,S=p[g++];if((S&192)===192){if(v=S&63,g>=p.length)throw new di("Unexpected end of PCX RLE data");S=p[g++]}for(let M=0;M<v&&x<d;M+=1)x<l&&(y[b++]=S),x+=1}}return{width:l,height:u,bitsPerPixel:i,pixels:y,palette:m}}function pl(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,a=r*4;e[a]=t.palette[i],e[a+1]=t.palette[i+1],e[a+2]=t.palette[i+2],e[a+3]=n===255?0:255}return e}var jr=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function Gu(t){let e=new DataView(t);if(t.byteLength<18)throw new jr("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),a=e.getUint16(12,!0),o=e.getUint16(14,!0),s=e.getUint8(16),c=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new jr(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(s!==24&&s!==32&&s!==8)throw new jr(`Unsupported pixel depth: ${s} (only 8, 24, 32 bpp supported)`);let l=i>=9,u=i===3||i===11,d=s/8,f=18+r;if(n===1){let x=e.getUint16(5,!0),v=e.getUint8(7);f+=x*(v/8)}let m=a*o,p=new Uint8Array(m*4),y=(c&32)!==0,g=0,b=new Uint8Array(t),_=x=>{if(u){let v=b[f++];p[x]=v,p[x+1]=v,p[x+2]=v,p[x+3]=255}else{let v=b[f++],S=b[f++],M=b[f++],w=s===32?b[f++]:255;p[x]=M,p[x+1]=S,p[x+2]=v,p[x+3]=w}};if(l){let x=0;for(;x<m;){if(f>=t.byteLength)throw new jr("Unexpected end of TGA RLE data");let v=b[f++],S=(v&127)+1,M=(v&128)!==0;if(x+S>m)throw new jr("TGA RLE packet exceeds image bounds");if(M){let w=u?b[f]:b[f+2],T=u?b[f]:b[f+1],L=b[f],A=u?255:s===32?b[f+3]:255;f+=d;for(let R=0;R<S;R++){let D=(x+R)*4;p[D]=w,p[D+1]=T,p[D+2]=L,p[D+3]=A}}else for(let w=0;w<S;w++)_((x+w)*4);x+=S}}else for(let x=0;x<m;x++){if(f>=t.byteLength)throw new jr("Unexpected end of TGA data");_(x*4)}if(!y){let x=a*4,v=new Uint8Array(x);for(let S=0;S<o/2;S++){let M=S*x,w=(o-1-S)*x;v.set(p.subarray(M,M+x)),p.set(p.subarray(w,w+x),M),p.set(v,w)}}return{width:a,height:o,bitsPerPixel:32,pixels:p}}function Qy(t){let e=0;for(let r of t.levels)e+=r.rgba.byteLength;return e}var ea=class{constructor(e={}){h(this,"cache");this.cache=new Ln(e.capacity??128,e.maxMemory??256*1024*1024,Qy)}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()}get capacity(){return this.cache.capacity}set capacity(e){this.cache.capacity=e}get maxMemory(){return this.cache.maxMemory}set maxMemory(e){this.cache.maxMemory=e}};function Vu(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let a=0;a<n.data.length;a+=1){let o=n.data[a],s=o*3,c=a*4;i[c]=e[s],i[c+1]=e[s+1],i[c+2]=e[s+2],i[c+3]=o===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 gl(t){let e=pl(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Ih(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 yl(t,e){return Vu(ml(t),e)}var fi=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function Hu(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function bl(t){if(t.byteLength<44)throw new fi("WAV buffer too small");let e=new DataView(t);if(Hu(e,0,4)!=="RIFF"||Hu(e,8,4)!=="WAVE")throw new fi("Invalid WAV header");let r=12,n=-1,i=-1,a=0,o=0;for(;r+8<=t.byteLength;){let p=Hu(e,r,4),y=e.getUint32(r+4,!0),g=r+8;p==="fmt "?(n=g,a=y):p==="data"&&(i=g,o=y),r=g+y}if(n===-1||i===-1)throw new fi("Missing fmt or data chunk");let s=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),u=e.getUint16(n+14,!0);if(s!==1)throw new fi("Only PCM WAV is supported");let d=u/8,f=o/(d*c),m=new Float32Array(f*c);for(let p=0;p<f;p+=1)for(let y=0;y<c;y+=1){let g=p*c+y,b=i+g*d,_=0;if(u===8)_=e.getUint8(b),m[g]=(_-128)/128;else if(u===16)_=e.getInt16(b,!0),m[g]=_/32768;else if(u===24){let x=e.getUint8(b),v=e.getUint8(b+1),S=e.getInt8(b+2);_=x|v<<8|S<<16,m[g]=_/8388608}else throw new fi(`Unsupported bitsPerSample: ${u}`)}return{sampleRate:l,channels:c,bitsPerSample:u,samples:m}}var Jy=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,a,o,s=e;for(i=0;i<256;i++){for(o=i<<24,a=8;a>0;--a)o=2147483648&o?o<<1^r:o<<1;n[i]=o}for(i=0;i<t.length;i++)s=s<<8^n[255&(s>>24^t[i])];return s};var Wu=(t,e=Jy)=>{let r=g=>new Uint8Array(g.length/2).map(((b,_)=>parseInt(g.substring(2*_,2*(_+1)),16))),n=g=>r(g)[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(((g,b)=>i.set(g,b)));let a=new Uint8Array(t.length),o,s,c,l=!1,u=0,d=42,f=t.length>13&&t.substring(0,9)==="dynEncode",m=0;f&&(m=11,s=n(t.substring(9,m)),s<=1&&(m+=2,d=n(t.substring(11,m))),s===1&&(m+=8,c=(g=>new DataView(r(g).buffer).getInt32(0,!0))(t.substring(13,m))));let p=256-d;for(let g=m;g<t.length;g++)if(o=t.charCodeAt(g),o!==61||l){if(o===92&&g<t.length-5&&f){let b=t.charCodeAt(g+1);b!==117&&b!==85||(o=parseInt(t.substring(g+2,g+6),16),g+=5)}if(o>255){let b=i.get(o);b&&(o=b+127)}l&&(l=!1,o-=64),a[u++]=o<d&&o>0?o+p:o-d}else l=!0;let y=a.subarray(0,u);if(f&&s===1){let g=e(y);if(g!==c){let b="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",b+`
|
|
1
|
+
"use strict";var Quake2Engine=(()=>{var fg=Object.create;var ro=Object.defineProperty;var hg=Object.getOwnPropertyDescriptor;var mg=Object.getOwnPropertyNames;var pg=Object.getPrototypeOf,gg=Object.prototype.hasOwnProperty;var yg=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var bg=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ni=(t,e)=>{for(var r in e)ro(t,r,{get:e[r],enumerable:!0})},Zf=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mg(e))!gg.call(t,i)&&i!==r&&ro(t,i,{get:()=>e[i],enumerable:!(n=hg(e,i))||n.enumerable});return t};var xg=(t,e,r)=>(r=t!=null?fg(pg(t)):{},Zf(e||!t||!t.__esModule?ro(r,"default",{value:t,enumerable:!0}):r,t)),vg=t=>Zf(ro({},"__esModule",{value:!0}),t);var f=(t,e,r)=>yg(t,typeof e!="symbol"?e+"":e,r);var kh=bg((WA,Dh)=>{"use strict";Dh.exports=Worker});var B2={};Ni(B2,{ATTN_IDLE:()=>Pu,ATTN_LOOP_NONE:()=>Tu,ATTN_NONE:()=>lo,ATTN_NORM:()=>Lu,ATTN_STATIC:()=>Ru,AssetDependencyError:()=>Ei,AssetDependencyTracker:()=>ds,AssetManager:()=>jl,AssetPreviewGenerator:()=>nu,AudioApi:()=>Ki,AudioContextController:()=>Ql,AudioOcclusion:()=>hs,AudioRegistry:()=>ba,AudioRegistryError:()=>ls,AudioSystem:()=>ac,BSP_SURFACE_FRAGMENT_SOURCE:()=>vd,BSP_SURFACE_VERTEX_SOURCE:()=>xd,BSP_VERTEX_LAYOUT:()=>hd,BspLoader:()=>Zi,BspLump:()=>Uu,BspParseError:()=>fe,BspSurfacePipeline:()=>Sa,Camera:()=>bc,ClientConnection:()=>cu,Command:()=>no,CommandRegistry:()=>Gi,ConfigStringRegistry:()=>Yi,ConnectionState:()=>Gf,CoordinateSystem:()=>ef,Cvar:()=>co,CvarRegistry:()=>Xi,DemoAnalyzer:()=>qa,DemoCameraMode:()=>Uf,DemoClipper:()=>ru,DemoEventType:()=>kf,DemoPlaybackController:()=>Hs,DemoReader:()=>wr,DemoRecorder:()=>Ws,DemoValidator:()=>tu,DynamicLightManager:()=>uc,EngineHost:()=>$i,EngineRuntime:()=>uo,FileType:()=>zf,FixedTimestepLoop:()=>ii,Framebuffer:()=>Ti,IndexBuffer:()=>ut,LoggingRenderer:()=>lu,LruCache:()=>Ln,MAX_SOUND_CHANNELS:()=>so,MD2_FRAGMENT_SHADER:()=>Td,MD2_VERTEX_SHADER:()=>Ed,MD3_FRAGMENT_SHADER:()=>Yd,MD3_VERTEX_SHADER:()=>Kd,MapAnalyzer:()=>iu,Md2Loader:()=>ji,Md2MeshBuffers:()=>Aa,Md2ParseError:()=>st,Md2Pipeline:()=>Ea,Md3Loader:()=>Qi,Md3ModelMesh:()=>Ra,Md3ParseError:()=>rr,Md3Pipeline:()=>Ca,Md3SurfaceMesh:()=>xs,MessageWriter:()=>eu,MusicSystem:()=>oc,NetworkMessageParser:()=>_t,NullRenderer:()=>au,PARTICLE_FRAGMENT_SHADER:()=>Zd,PARTICLE_VERTEX_SHADER:()=>qd,PROTOCOL_VERSION_RERELEASE:()=>Yr,PakArchive:()=>qi,PakIndexStore:()=>Zl,PakIngestionError:()=>Tn,PakParseError:()=>Ne,PakValidationError:()=>ui,PakValidator:()=>ul,PakWriter:()=>sl,ParticleRenderer:()=>Fa,ParticleSystem:()=>Ba,PlaybackState:()=>Jc,RERELEASE_KNOWN_PAKS:()=>Du,ResourceLoadTracker:()=>ll,ResourceType:()=>Iu,SKYBOX_FRAGMENT_SHADER:()=>Md,SKYBOX_VERTEX_SHADER:()=>wd,SOUND_FULLVOLUME:()=>Hi,SOUND_LOOP_ATTENUATE:()=>Cu,ShaderProgram:()=>he,SkyboxPipeline:()=>wa,SoundChannel:()=>Ir,SoundPrecache:()=>tc,SoundRegistry:()=>ec,SpriteLoader:()=>Ji,SpriteParseError:()=>Pn,SpriteRenderer:()=>Ia,StreamingPakArchive:()=>ol,Texture2D:()=>dt,TextureCache:()=>ea,TextureCubeMap:()=>xa,TgaParseError:()=>jr,U_ALPHA:()=>Lr,U_ANGLE1:()=>Ct,U_ANGLE2:()=>Et,U_ANGLE3:()=>Tt,U_EFFECTS16:()=>et,U_EFFECTS8:()=>je,U_EVENT:()=>Pt,U_FRAME16:()=>Ft,U_FRAME8:()=>Lt,U_INSTANCE_BITS:()=>Br,U_LOOP_ATTENUATION_HIGH:()=>wn,U_LOOP_VOLUME:()=>Fr,U_MODEL:()=>Bt,U_MODEL2:()=>It,U_MODEL3:()=>Dt,U_MODEL4:()=>kt,U_OLDORIGIN:()=>br,U_OLD_FRAME_HIGH:()=>An,U_ORIGIN1:()=>Mt,U_ORIGIN2:()=>At,U_ORIGIN3:()=>Rt,U_OWNER_HIGH:()=>Mn,U_REMOVE:()=>ao,U_RENDERFX16:()=>Je,U_RENDERFX8:()=>Ze,U_SCALE:()=>Cr,U_SKIN16:()=>tt,U_SKIN8:()=>Qe,U_SOLID:()=>zt,U_SOUND:()=>Ut,VertexArray:()=>Fe,VertexBuffer:()=>Be,VirtualFileSystem:()=>cl,advanceAnimation:()=>Rh,applyEntityDelta:()=>q0,applySurfaceState:()=>ms,attenuationToDistanceMultiplier:()=>Wi,boxIntersectsFrustum:()=>Li,buildBspGeometry:()=>cc,buildMd2Geometry:()=>Ld,buildMd2VertexData:()=>Pd,buildMd3SurfaceGeometry:()=>Xd,buildMd3VertexData:()=>$d,calculateMaxAudibleDistance:()=>ci,calculatePakChecksum:()=>mh,captureRenderTarget:()=>ng,computeFrameBlend:()=>Ch,computeSkyScroll:()=>Ri,createAnimationState:()=>Bh,createAudioGraph:()=>Jl,createBspSurfaces:()=>lc,createEmptyEntityState:()=>Kr,createEmptyProtocolPlayerState:()=>Mr,createEngine:()=>C2,createEngineRuntime:()=>dh,createFaceLightmap:()=>fl,createHeadlessRenderTarget:()=>rg,createInitialChannels:()=>rc,createOcclusionResolver:()=>fm,createProgramFromSources:()=>pm,createRenderer:()=>gp,createWebGLContext:()=>hm,createWebGPUContext:()=>Tc,createWebGPURenderer:()=>Ep,decodeOgg:()=>ql,deriveSurfaceRenderState:()=>Sd,detectFileType:()=>Of,extractFrustumPlanes:()=>cr,filesToPakSources:()=>ku,findLeafForPoint:()=>Pi,gatherVisibleFaces:()=>dn,groupMd2Animations:()=>Eh,ingestPakFiles:()=>bh,ingestPaks:()=>dl,interpolateMd3Tag:()=>Jm,interpolateVec3:()=>Fh,isBinaryFile:()=>j0,isTextFile:()=>Nf,parseBsp:()=>fo,parseEntLump:()=>J0,parseMd2:()=>zu,parseMd3:()=>Ou,parsePcx:()=>go,parseSprite:()=>Nu,parseTga:()=>Gu,parseWal:()=>ml,parseWalTexture:()=>yl,parseWav:()=>bl,pcxToRgba:()=>pl,pickChannel:()=>nc,preparePcxTexture:()=>gl,queryCapabilities:()=>yp,removeViewTranslation:()=>Ma,resolveLightStyles:()=>_d,serializeEntLump:()=>eg,spawnBfgExplosion:()=>dp,spawnBlasterImpact:()=>up,spawnBlood:()=>rp,spawnBulletImpact:()=>ep,spawnExplosion:()=>tp,spawnMuzzleFlash:()=>ip,spawnRailTrail:()=>lp,spawnSparks:()=>cp,spawnSplash:()=>op,spawnSteam:()=>sp,spawnTeleportFlash:()=>np,spawnTrail:()=>ap,validateEntity:()=>tg,walToRgba:()=>Vu,wireDropTarget:()=>xh,wireFileInput:()=>vh});var _g=()=>typeof performance<"u"?performance.now():Date.now(),Sg=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},ii=class{constructor(e,r={}){this.callbacks=e;f(this,"options");f(this,"accumulatorMs",0);f(this,"frame",0);f(this,"lastTimeMs");f(this,"running",!1);f(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??_g,schedule:r.schedule??Sg}}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 a=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:a,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var no=class{constructor(e,r,n){f(this,"name");f(this,"description");f(this,"callback");this.name=e,this.callback=r,this.description=n}execute(e){this.callback(e)}},Gi=class{constructor(){f(this,"commands",new Map);f(this,"history",[]);f(this,"historyLimit",64);f(this,"autocompleteProviders",[]);f(this,"onConsoleOutput")}register(e,r,n){let i=new no(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],a=n.slice(1),o=this.get(i);return o?(o.execute(a),!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 a of i)a.startsWith(e)&&r.add(a)}return Array.from(r).sort()}tokenize(e){let r=[],n="",i=!1;for(let a=0;a<e.length;a++){let o=e[a];o==='"'?i=!i:o===" "&&!i?n.length>0&&(r.push(n),n=""):n+=o}return n.length>0&&r.push(n),r}list(){return[...this.commands.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var jf=Object.defineProperty,wg=(t,e,r)=>e in t?jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Mg=(t,e)=>{for(var r in e)jf(t,r,{get:e[r],enumerable:!0})},te=(t,e,r)=>wg(t,typeof e!="symbol"?e+"":e,r),Qf={x:0,y:0,z:0};var X2=Math.PI/180;function Jf(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function Ag(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function Eg(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function Tg(t){return Eg(t,t)}function gu(t){return Math.sqrt(Tg(t))}function qr(t){let e=gu(t);return e===0?t:Ag(t,1/e)}var Lg=Math.PI/180,Pg=180/Math.PI,Ee=Lg,yu=Pg;var yr=[[-.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]];var Ar=624,Rg=397,Cg=2567483615,Bg=2147483648,Fg=2147483647,mu=4294967296,Ig=class{constructor(t=5489){te(this,"state",new Uint32Array(Ar)),te(this,"index",Ar),this.seed(t)}seed(t){this.state[0]=t>>>0;for(let e=1;e<Ar;e++){let r=this.state[e-1]^this.state[e-1]>>>30,n=Math.imul(r>>>0,1812433253)+e;this.state[e]=n>>>0}this.index=Ar}nextUint32(){this.index>=Ar&&this.twist();let t=this.state[this.index++];return t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}twist(){for(let t=0;t<Ar;t++){let e=this.state[t]&Bg|this.state[(t+1)%Ar]&Fg,r=this.state[(t+Rg)%Ar]^e>>>1;(e&1)!==0&&(r^=Cg),this.state[t]=r>>>0}this.index=0}getState(){return{index:this.index,state:Array.from(this.state)}}setState(t){if(t.state.length!==Ar)throw new Error(`Expected ${Ar} MT state values, received ${t.state.length}`);this.index=t.index,this.state=Uint32Array.from(t.state,e=>e>>>0)}},eh=class{constructor(t={}){te(this,"mt"),this.mt=new Ig(t.seed)}seed(t){this.mt.seed(t)}frandom(){return this.mt.nextUint32()/mu}frandomRange(t,e){return t+(e-t)*this.frandom()}frandomMax(t){return this.frandomRange(0,t)}crandom(){return this.frandomRange(-1,1)}crandomOpen(){let t=Number.EPSILON;return this.frandomRange(-1+t,1)}irandomUint32(){return this.mt.nextUint32()}irandomRange(t,e){if(e-t<=1)return t;let r=e-t,n=mu-mu%r,i;do i=this.mt.nextUint32();while(i>=n);return t+i%r}irandom(t){return t<=0?0:this.irandomRange(0,t)}randomTimeRange(t,e){return e<=t?t:this.irandomRange(t,e)}randomTime(t){return this.irandom(t)}randomIndex(t){return this.irandom(t.length)}getState(){return{mt:this.mt.getState()}}setState(t){this.mt.setState(t.mt)}};function Dg(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function bu(t,e){let r=new Float32Array(16);for(let n=0;n<4;n+=1)for(let i=0;i<4;i+=1)r[i*4+n]=t[0+n]*e[i*4+0]+t[4+n]*e[i*4+1]+t[8+n]*e[i*4+2]+t[12+n]*e[i*4+3];return r}function th(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 rh(t,e){let r=Dg();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 Er=1,bn=2;var xu=8,vu=16,kg=32;var Ug=16384;var Js=65536,nh=1<<17,zg=1<<18,Og=1<<19,Ng=1<<20,Gg=1<<21,Vg=1<<22,Hg=1<<23,$2=1<<24,el=1<<25,Wg=1<<26,K2=1<<27,Y2=1<<28,q2=1<<29,tl=1<<30,Z2=1<<31;var xn=0;var vn=4,Zr=8,_n=16,Sn=32,rl=64;var j2=1<<25,Q2=1<<28,J2=1<<29,eM=1<<30,tM=1<<31;var rM=Er|bn,nM=Er|Js|bn|el|tl,iM=Er|Js|bn,aM=Er|nh|bn|el|tl,oM=kg|xu|vu,sM=Er|vu|xu,Xg=Er|el|tl|bn|Wg,lM=zg|Og|Ng|Gg|Vg|Hg,cM=Er|xu|vu|el|tl,uM=Er|Js|bn,dM=Er|bn,fM=Er|Js|bn|nh,hM=Xg|Ug;var mM=Number.MAX_SAFE_INTEGER-1;var nl=(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))(nl||{});var il=256;var _u=256,Su=8192,al=2048,wu=512,Mu=256,Au=il*2,Eu=256,pu=32,io=96;var ne=(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+Su]="Sounds",t[t.Images=t.Sounds+al]="Images",t[t.Lights=t.Images+wu]="Lights",t[t.ShadowLights=t.Lights+_u]="ShadowLights",t[t.Items=t.ShadowLights+Eu]="Items",t[t.Players=t.Items+Mu]="Players",t[t.PlayerSkins=t.Players]="PlayerSkins",t[t.General=t.Players+il]="General",t[t.WheelWeapons=t.General+Au]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+pu]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+pu]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+pu]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(ne||{}),ih=ne.MaxConfigStrings;function ah(t){return t>=5&&t<59?io*(59-t):t>=ne.General&&t<ne.WheelWeapons?io*(ne.MaxConfigStrings-t):io}var pM=ne.Sounds,gM=ne.Images,yM=ne.Lights,bM=ne.Items,xM=ne.Players,vM=ne.General,$g={};Mg($g,{addReplayFrame:()=>Zg,createReplaySession:()=>qg,deserializeReplay:()=>Yg,serializeReplay:()=>Kg});function Kg(t){return JSON.stringify(t,null,2)}function Yg(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 qg(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function Zg(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var C=(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))(C||{}),oi=(t=>(t[t.bad=0]="bad",t[t.nop=1]="nop",t[t.move=2]="move",t[t.userinfo=3]="userinfo",t[t.stringcmd=4]="stringcmd",t))(oi||{}),O=(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))(O||{});var oh=64;var jg=12,Qg=9,_M=Math.ceil(jg*Qg/16),Jg=23,ey=2,SM=Math.ceil(Jg*ey/16);function sh(t,e){t.writeByte(e.msec),t.writeByte(e.buttons),t.writeAngle16(e.angles.x),t.writeAngle16(e.angles.y),t.writeAngle16(e.angles.z),t.writeShort(e.forwardmove),t.writeShort(e.sidemove),t.writeShort(e.upmove),t.writeByte(e.impulse),t.writeByte(0)}var ty=[0,145,227,114,7,150,228,117,14,159,237,124,9,152,234,123,28,141,255,110,27,138,248,105,18,131,241,96,21,132,246,103,56,169,219,74,63,174,220,77,54,167,213,68,49,160,210,67,36,181,199,86,35,178,192,81,42,187,201,88,45,188,206,95,112,225,147,2,119,230,148,5,126,239,157,12,121,232,154,11,108,253,143,30,107,250,136,25,98,243,129,16,101,244,134,23,72,217,171,58,79,222,172,61,70,215,165,52,65,208,162,51,84,197,183,38,83,194,176,33,90,203,185,40,93,204,190,47,224,113,3,146,231,118,4,149,238,127,13,156,233,120,10,155,252,109,31,142,251,106,24,137,242,99,17,128,245,100,22,135,216,73,59,170,223,78,60,173,214,71,53,164,209,64,50,163,196,85,39,182,195,82,32,177,202,91,41,184,205,92,46,191,144,1,115,226,151,6,116,229,158,15,125,236,153,8,122,235,140,29,111,254,139,26,104,249,130,19,97,240,133,20,102,247,168,57,75,218,175,62,76,221,166,55,69,212,161,48,66,211,180,37,86,199,179,34,80,193,186,43,89,200,189,44,94,207];function lh(t){let e=0;for(let r=0;r<t.length;r++)e=ty[(e^t[r])&255];return e}var Mt=1,At=2,Et=4,Tt=8,Lt=16,Pt=32,ao=64,Tr=128,si=256,Rt=512,Ct=1024,Bt=2048,Ze=4096,Lr=8192,je=16384,Pr=32768,Qe=65536,Ft=1<<17,Je=1<<18,et=1<<19,It=1<<20,Dt=1<<21,kt=1<<22,Rr=1<<23,br=1<<24,tt=1<<25,Ut=1<<26,zt=1<<27,Cr=1<<28,Br=1<<29,Fr=1<<30,Vi=-2147483648,wn=1,Mn=2,An=4;var En=class{constructor(t){te(this,"view"),te(this,"offset"),te(this,"length"),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=yr[e];t.x=r[0],t.y=r[1],t.z=r[2]}},li=class{constructor(t=1400){te(this,"buffer"),te(this,"view"),te(this,"offset"),te(this,"fixed"),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<yr.length;n++){let i=yr[n],a=t.x*i[0]+t.y*i[1]+t.z*i[2];a>e&&(e=a,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}},oo=class{constructor(t=1024){te(this,"buffer"),te(this,"view"),te(this,"offset"),this.buffer=new Uint8Array(t),this.view=new DataView(this.buffer.buffer),this.offset=0}ensureCapacity(t){if(this.offset+t>this.buffer.length){let e=Math.max(this.buffer.length*2,this.offset+t),r=new Uint8Array(e);r.set(this.buffer),this.buffer=r,this.view=new DataView(this.buffer.buffer)}}getData(){return this.buffer.slice(0,this.offset)}writeByte(t){this.ensureCapacity(1),this.view.setUint8(this.offset,t),this.offset+=1}writeChar(t){this.ensureCapacity(1),this.view.setInt8(this.offset,t),this.offset+=1}writeShort(t){this.ensureCapacity(2),this.view.setInt16(this.offset,t,!0),this.offset+=2}writeUShort(t){this.ensureCapacity(2),this.view.setUint16(this.offset,t,!0),this.offset+=2}writeLong(t){this.ensureCapacity(4),this.view.setInt32(this.offset,t,!0),this.offset+=4}writeFloat(t){this.ensureCapacity(4),this.view.setFloat32(this.offset,t,!0),this.offset+=4}writeString(t){let e=t.length+1;this.ensureCapacity(e);for(let r=0;r<t.length;r++)this.view.setUint8(this.offset+r,t.charCodeAt(r));this.view.setUint8(this.offset+t.length,0),this.offset+=e}writeData(t){this.ensureCapacity(t.length),this.buffer.set(t,this.offset),this.offset+=t.length}writeCoord(t){this.writeShort(Math.round(t*8))}writeAngle(t){this.writeByte(Math.round(t*256/360)&255)}writeAngle16(t){this.writeShort(Math.round(t*65536/360))}writeDir(t,e,r){let n=0,i=-999999,a=Math.sqrt(t*t+e*e+r*r);if(a>0){t/=a,e/=a,r/=a;for(let o=0;o<162;o++){let s=t*yr[o][0]+e*yr[o][1]+r*yr[o][2];s>i&&(i=s,n=o)}}this.writeByte(n)}},ai=class ot{constructor(){te(this,"qport",0),te(this,"incomingSequence",0),te(this,"outgoingSequence",0),te(this,"incomingAcknowledged",0),te(this,"incomingReliableAcknowledged",!1),te(this,"incomingReliableSequence",0),te(this,"outgoingReliableSequence",0),te(this,"reliableMessage"),te(this,"reliableLength",0),te(this,"fragmentSendOffset",0),te(this,"fragmentBuffer",null),te(this,"fragmentLength",0),te(this,"fragmentReceived",0),te(this,"lastReceived",0),te(this,"lastSent",0),te(this,"remoteAddress",null),this.reliableMessage=new li(ot.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>ot.FRAGMENT_SIZE?(n=!0,this.fragmentSendOffset>=this.reliableLength&&(this.fragmentSendOffset=0),r=this.reliableLength-this.fragmentSendOffset,r>ot.FRAGMENT_SIZE&&(r=ot.FRAGMENT_SIZE),i=this.fragmentSendOffset,this.fragmentSendOffset+=r):r=this.reliableLength);let a=ot.PACKET_HEADER,o=r>0?2+(n?8:0):0,s=e?e.length:0;a+o+r+s>ot.MAX_MSGLEN&&(s=ot.MAX_MSGLEN-a-o-r,s<0&&(s=0));let c=new ArrayBuffer(a+o+r+s),l=new DataView(c),u=new Uint8Array(c),d=this.outgoingSequence;r>0&&(d|=2147483648,(this.outgoingReliableSequence&1)!==0&&(d|=1073741824)),l.setUint32(0,d,!0);let h=this.incomingSequence;(this.incomingReliableSequence&1)!==0&&(h|=2147483648),l.setUint32(4,h,!0),l.setUint16(8,this.qport,!0);let m=a;if(r>0){let p=r;n&&(p|=32768),l.setUint16(m,p,!0),m+=2,n&&(l.setUint32(m,i,!0),m+=4,l.setUint32(m,this.reliableLength,!0),m+=4);let g=this.reliableMessage.getBuffer().subarray(i,i+r);u.set(g,m),m+=r}if(e&&s>0){let p=e.slice(0,s);u.set(p,m)}return u}process(e){if(e.length<4)return null;this.lastReceived=Date.now();let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(0,!0);if(n===4294967295)return e.subarray(4);if(e.length<ot.PACKET_HEADER)return null;let i=r.getUint32(4,!0),a=r.getUint16(8,!0);if(this.qport!==a)return null;let o=n&1073741823;if((o-this.incomingSequence|0)<=0)return null;this.incomingSequence=o;let s=i&2147483647,c=(i&2147483648)!==0;if(s>this.incomingAcknowledged&&(this.incomingAcknowledged=s),this.reliableLength>0){let p=c?1:0,y=this.outgoingReliableSequence&1;p!==y&&(this.reliableLength=0,this.reliableMessage.reset(),this.outgoingReliableSequence^=1,this.fragmentSendOffset=0)}let l=(n&2147483648)!==0,u=(n&1073741824)!==0?1:0,d=ot.PACKET_HEADER,h=null;if(l){if(d+2>e.byteLength)return null;let p=r.getUint16(d,!0);d+=2;let y=(p&32768)!==0;p&=32767;let g=this.incomingReliableSequence&1;if(u===g)if(y){if(d+8>e.byteLength)return null;let b=r.getUint32(d,!0);d+=4;let _=r.getUint32(d,!0);if(d+=4,_>ot.MAX_RELIABLE_BUFFER)return console.warn(`NetChan: received invalid fragment total ${_} > ${ot.MAX_RELIABLE_BUFFER}`),null;if((!this.fragmentBuffer||this.fragmentBuffer.length!==_)&&(this.fragmentBuffer=new Uint8Array(_),this.fragmentLength=_,this.fragmentReceived=0),d+p>e.byteLength)return null;let x=e.subarray(d,d+p);b===this.fragmentReceived&&b+p<=_&&(this.fragmentBuffer.set(x,b),this.fragmentReceived+=p,this.fragmentReceived>=_&&(h=this.fragmentBuffer,this.incomingReliableSequence++,this.fragmentBuffer=null,this.fragmentLength=0,this.fragmentReceived=0))}else{if(this.incomingReliableSequence++,d+p>e.byteLength)return null;h=e.slice(d,d+p)}d+=p}let m=e.slice(d);if(h&&h.length>0){let p=h.length+m.length,y=new Uint8Array(p);return y.set(h,0),y.set(m,h.length),y}return m||new Uint8Array(0)}canSendReliable(){return this.reliableLength===0}writeReliableByte(e){if(this.reliableLength+1>ot.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeByte(e),this.reliableLength++}writeReliableShort(e){if(this.reliableLength+2>ot.MAX_RELIABLE_BUFFER)throw new Error("NetChan reliable buffer overflow");this.reliableMessage.writeShort(e),this.reliableLength+=2}writeReliableLong(e){if(this.reliableLength+4>ot.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>ot.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}};te(ai,"MAX_MSGLEN",1400);te(ai,"FRAGMENT_SIZE",1024);te(ai,"PACKET_HEADER",10);te(ai,"HEADER_OVERHEAD",ai.PACKET_HEADER+2);te(ai,"MAX_RELIABLE_BUFFER",262144);var ch=ai;var uh=(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))(uh||{}),wM=Object.keys(uh).length/2;var so=32,Ir=(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))(Ir||{}),Tu=-1,lo=0,Lu=1,Pu=2,Ru=3,Hi=80,Cu=.003;function Wi(t){return t*.001}function ci(t){let e=Wi(t);return e<=0?Number.POSITIVE_INFINITY:Hi+1/e}var co=class{constructor({name:e,defaultValue:r,description:n,flags:i=nl.None,onChange:a}){f(this,"name");f(this,"defaultValue");f(this,"description");f(this,"flags");f(this,"_value");f(this,"latched");f(this,"onChange");f(this,"modifiedCount",0);this.name=e,this.defaultValue=r,this.description=n,this.flags=i,this._value=r,this.onChange=a}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&nl.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)}},Xi=class{constructor(){f(this,"cvars",new Map);f(this,"onCvarChange")}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=e.onChange,i=(o,s)=>{n?.(o,s),this.onCvarChange?.(o.name,o.string)},a=new co({...e,onChange:i});return this.cvars.set(e.name,a),a}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 $i=class{constructor(e,r,n={}){this.game=e;this.client=r;f(this,"loop");f(this,"startTimeMs");f(this,"previousFrame");f(this,"latestFrame");f(this,"started",!1);f(this,"paused_",!1);f(this,"latestCommand");f(this,"commands",new Gi);f(this,"cvars",new Xi);f(this,"stepSimulation",e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)});f(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 ii({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs}),this.commands.registerAutocompleteProvider(()=>this.cvars.list().map(a=>a.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 Ki=class{constructor(e){f(this,"registry");f(this,"system");f(this,"music");f(this,"client");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,a,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:a,timeOffsetMs:o}),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,a){let o=this.system.play({entity:e,channel:r,soundIndex:n,volume:i,attenuation:a,looping:!0});return this.triggerSubtitle(n),o}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 uo=class{constructor(e,r){this.engine=e;this.host=r;f(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 dh(t,e,r,n,i){let a=new Ki({...n,client:r}),o=new $i(e,r,i);return{runtime:new uo(t,o),audio:a}}function ry(t){if(t<0||t>=ne.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${ne.MaxConfigStrings-1})`)}function fh(t,e){let r=ah(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${io} chars per slot`)}var Yi=class{constructor(){f(this,"values",new Map);f(this,"modelCursor",ne.Models);f(this,"soundCursor",ne.Sounds);f(this,"imageCursor",ne.Images);f(this,"lightCursor",ne.Lights);f(this,"shadowLightCursor",ne.ShadowLights);f(this,"itemCursor",ne.Items);f(this,"playerSkinCursor",ne.PlayerSkins);f(this,"generalCursor",ne.General)}set(e,r){return ry(e),fh(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(ih).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,ne.Models,Su,"modelCursor")}soundIndex(e){return this.register(e,ne.Sounds,al,"soundCursor")}findSoundIndex(e){for(let r=ne.Sounds;r<ne.Sounds+al;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,ne.Images,wu,"imageCursor")}lightIndex(e){return this.register(e,ne.Lights,_u,"lightCursor")}shadowLightIndex(e){return this.register(e,ne.ShadowLights,Eu,"shadowLightCursor")}itemIndex(e){return this.register(e,ne.Items,Mu,"itemCursor")}playerSkinIndex(e){return this.register(e,ne.PlayerSkins,il,"playerSkinCursor")}generalIndex(e){return this.register(e,ne.General,Au,"generalCursor")}register(e,r,n,i){for(let s=r;s<r+n;s+=1)if(this.values.get(s)===e)return s;let a=this[i],o=r+n;if(a>=o)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return fh(a,e),this.values.set(a,e),this[i]=a+1,a}};var ny="PACK";function iy(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function Le(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function ay(){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 oy=ay();function hh(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=oy[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Ne=class extends Error{},qi=class t{constructor(e,r,n,i){this.name=e;this.buffer=r;f(this,"entries");f(this,"checksum");f(this,"size");this.entries=new Map(n.map(a=>[a.name,a])),this.checksum=i,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Ne("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!==ny)throw new Ne(`Invalid PAK header magic: ${i}`);let a=n.getInt32(4,!0),o=n.getInt32(8,!0);if(a<12)throw new Ne(`Invalid directory offset: ${a}`);if(o<0||o%64!==0)throw new Ne(`Invalid directory length: ${o}`);if(a+o>r.byteLength)throw new Ne("Directory exceeds buffer length");let c=o/64,l=[],u=new Map;for(let d=0;d<c;d+=1){let h=a+d*64,m=iy(n,h,56),p=Le(m),y=n.getInt32(h+56,!0),g=n.getInt32(h+60,!0);if(y<0||g<0||y+g>r.byteLength)throw new Ne(`Invalid entry bounds for ${m||"<unnamed>"} (offset=${y}, length=${g})`);if(!p)throw new Ne(`Entry ${d} has an empty name`);let b={name:p,offset:y,length:g};u.set(p,b)}return l.push(...u.values()),new t(e,r,l,hh(new Uint8Array(r)))}getEntry(e){return this.entries.get(Le(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 Ne(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function mh(t){return hh(new Uint8Array(t))}var sy="PACK",ph=12,Bu=64;function gh(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}var ol=class{constructor(e){this.source=e;f(this,"entries",null)}async readDirectory(){if(this.entries)return Array.from(this.entries.values());let e=await this.readChunk(0,ph),r=new DataView(e),n=String.fromCharCode(r.getUint8(0),r.getUint8(1),r.getUint8(2),r.getUint8(3));if(n!==sy)throw new Ne(`Invalid PAK header magic: ${n}`);let i=r.getInt32(4,!0),a=r.getInt32(8,!0);if(i<ph)throw new Ne(`Invalid directory offset: ${i}`);if(a<0||a%Bu!==0)throw new Ne(`Invalid directory length: ${a}`);let o=await this.readChunk(i,a),s=new DataView(o),c=a/Bu,l=new Map;for(let u=0;u<c;u++){let d=u*Bu,h=this.readCString(s,d,56),m=gh(h),p=s.getInt32(d+56,!0),y=s.getInt32(d+60,!0);p<0||y<0||p+y>this.source.size,m&&l.set(m,{name:m,offset:p,length:y})}return this.entries=l,Array.from(l.values())}async readFile(e){let r=await this.getEntry(e);if(!r)throw new Ne(`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 Ne(`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(gh(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 a=0;a<n;a+=1){let o=e.getUint8(r+a);if(o===0)break;i.push(o)}return String.fromCharCode(...i)}};var Fu=12,yh=64,sl=class t{constructor(){f(this,"entries",new Map)}addFile(e,r){let n=Le(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(Le(e))}build(){let e=0;for(let h of this.entries.values())e+=h.byteLength;let r=this.entries.size*yh,n=Fu+e+r,i=new Uint8Array(n),a=new DataView(i.buffer);a.setUint8(0,80),a.setUint8(1,65),a.setUint8(2,67),a.setUint8(3,75);let o=Fu+e;a.setInt32(4,o,!0),a.setInt32(8,r,!0);let s=Fu,c=new Map,l=Array.from(this.entries.keys()).sort();for(let h of l){let m=this.entries.get(h);c.set(h,s),i.set(m,s),s+=m.byteLength}let u=o,d=new TextEncoder;for(let h of l){let m=this.entries.get(h),p=d.encode(h);if(p.length>56)throw new Error(`Path too long after encoding: ${h}`);for(let y=0;y<56;y++)y<p.length?a.setUint8(u+y,p[y]):a.setUint8(u+y,0);a.setInt32(u+56,c.get(h),!0),a.setInt32(u+60,m.byteLength,!0),u+=yh}return i}static buildFromEntries(e){let r=new t;for(let[n,i]of e)r.addFile(n,i);return r.build()}};var Iu=(o=>(o.Texture="texture",o.Sound="sound",o.Model="model",o.Map="map",o.Sprite="sprite",o.ConfigString="configString",o))(Iu||{}),ll=class{constructor(){f(this,"tracking",!1);f(this,"entries",[]);f(this,"currentFrame",0);f(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 cl=class{constructor(e=[]){f(this,"mounts",[]);f(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,a)=>a.priority-i.priority);for(let i of e.listEntries()){let a=Le(i.name),o={archive:e,entry:i,priority:r};this.files.has(a)||this.files.set(a,[]);let s=this.files.get(a),c=s.findIndex(l=>l.archive===e);c!==-1&&s.splice(c,1),s.unshift(o),s.sort((l,u)=>u.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(Le(e))}getSource(e){let r=this.files.get(Le(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,a=i.readFile(e),o=0,s=a.length;return new ReadableStream({pull(c){if(o>=s){c.close();return}let l=Math.min(o+r,s),u=a.slice(o,l);o=l,c.enqueue(u)}})}async readTextFile(e){let r=await this.readFile(e);return new TextDecoder("utf-8").decode(r)}list(e=""){let r=Le(e).replace(/\/+$|^\//g,""),n=[],i=new Set,a=r?`${r}/`:"";for(let[o,s]of this.files){let c=s[0];if(r&&!c.entry.name.startsWith(a))continue;let l=r?c.entry.name.slice(a.length):c.entry.name,u=l.indexOf("/");u===-1?n.push({path:c.entry.name,size:c.entry.length,sourcePak:c.archive.name}):i.add(l.slice(0,u))}return n.sort((o,s)=>o.path.localeCompare(s.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,a]of this.files){let o=a[0];o.entry.name.toLowerCase().endsWith(r)&&n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name})}return n.sort((i,a)=>i.path.localeCompare(a.path))}listByExtension(e){let r=new Set(e.map(i=>i.startsWith(".")?i.toLowerCase():`.${i.toLowerCase()}`)),n=[];for(let[i,a]of this.files){let o=a[0],s=o.entry.name.toLowerCase();for(let c of r)if(s.endsWith(c)){n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name});break}}return n.sort((i,a)=>i.path.localeCompare(a.path))}searchFiles(e){let r=[];for(let[n,i]of this.files){let a=i[0];e.test(a.entry.name)&&r.push({path:a.entry.name,size:a.entry.length,sourcePak:a.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 a=i[0];return{path:a.entry.name,size:a.entry.length,sourcePak:a.archive.name}}).sort((i,a)=>i.path.localeCompare(a.path));for(let i of n){let a=i.path.split("/"),o=a.pop(),s="",c=e;for(let l of a){let u=s;s=s?`${s}/${l}`:l;let d=r.get(s);d||(d={name:l,path:s,files:[],directories:[]},c.directories.push(d),r.set(s,d)),c=d}c.files.push(i)}return e}};var Du=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"}]),ui=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"}},ul=class{constructor(e=Du){f(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,a="size"in e?e.size:void 0,o=this.known.get(n);return o?o.checksum!==i?{name:n,checksum:i,expectedChecksum:o.checksum,status:"mismatch",size:a,description:o.description}:{name:n,checksum:i,expectedChecksum:o.checksum,status:"valid",size:a,description:o.description}:{name:n,checksum:i,status:"unknown",size:a}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new ui(n);return n}normalizePakName(e){let r=Le(e),n=r.split("/"),i=n.pop()??r,a=n.pop();return a?`${i}@${a}`:i}};var Tn=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 ly(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=a=>{e?.({file:"blob",loadedBytes:a.loaded,totalBytes:a.total||t.size,state:"reading"})},i.onload=()=>{let a=i.result;a instanceof ArrayBuffer?r(a):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:s,value:c}=await r.read();if(s)break;if(!c)continue;let l=c;n.push(l),i+=l.byteLength,e?.({file:"blob",loadedBytes:i,totalBytes:t.size,state:"reading"})}let a=new Uint8Array(i),o=0;for(let s of n)a.set(s,o),o+=s.byteLength;return a.buffer}throw new Tn("blob",new Error("Unsupported Blob type"))}async function cy(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 ly(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 dl(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},i=n.persistIndexes??!!n.pakIndexStore,a=n.enforceValidation??!!n.validator,o=n.allowUnknownPaks??!0,s=n.stopOnError??!1,c=[];for(let l of e)try{let u=await cy(l,n.onProgress),d=qi.fromArrayBuffer(l.name,u),h=n.validator?.validateArchive(d);if(h){n.onValidationResult?.(h);let m=h.status==="mismatch",p=h.status==="unknown";if(m&&a||p&&!o){let y=new ui(h);if(n.onError?.(l.name,y),s)throw new Tn(l.name,y);c.push({archive:d,mounted:!1,validation:h});continue}}if(t.mountPak(d),i&&n.pakIndexStore)try{await n.pakIndexStore.persist(d)}catch(m){if(n.onError?.(l.name,m),s)throw new Tn(l.name,m)}n.onProgress?.({file:l.name,loadedBytes:u.byteLength,totalBytes:u.byteLength,state:"parsed"}),c.push({archive:d,mounted:!0,validation:h})}catch(u){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,u),s)throw new Tn(l.name,u)}return c}var Ln=class{constructor(e,r=1/0,n=()=>0){this._capacity=e;this._maxMemory=r;this.sizeCalculator=n;f(this,"map",new Map);f(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}get capacity(){return this._capacity}set capacity(e){if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero");this._capacity=e,this.evict()}get maxMemory(){return this._maxMemory}set maxMemory(e){this._maxMemory=e,this.evict()}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 uy(t){return Array.isArray(t)?t:Array.from(t)}function ku(t){return uy(t).map(e=>({name:e.name,data:e}))}async function bh(t,e,r){let n=ku(e);return dl(t,n,r??{})}function xh(t,e){let r=i=>{i.preventDefault(),i.dataTransfer?.dropEffect&&(i.dataTransfer.dropEffect="copy")},n=i=>{i.preventDefault();let a=i.dataTransfer?.files;a&&a.length>0&&e(Array.from(a))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function vh(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 dy="IBSP",fy=38,Sh=19,hy=8+Sh*8,Uu=(x=>(x[x.Entities=0]="Entities",x[x.Planes=1]="Planes",x[x.Vertices=2]="Vertices",x[x.Visibility=3]="Visibility",x[x.Nodes=4]="Nodes",x[x.TexInfo=5]="TexInfo",x[x.Faces=6]="Faces",x[x.Lighting=7]="Lighting",x[x.Leafs=8]="Leafs",x[x.LeafFaces=9]="LeafFaces",x[x.LeafBrushes=10]="LeafBrushes",x[x.Edges=11]="Edges",x[x.SurfEdges=12]="SurfEdges",x[x.Models=13]="Models",x[x.Brushes=14]="Brushes",x[x.BrushSides=15]="BrushSides",x[x.Pop=16]="Pop",x[x.Areas=17]="Areas",x[x.AreaPortals=18]="AreaPortals",x))(Uu||{}),fe=class extends Error{},Zi=class{constructor(e,r={}){this.vfs=e;this.options=r}async load(e){let r=await this.vfs.readFile(e),n=new Uint8Array(r.byteLength);if(n.set(new Uint8Array(r)),this.options.useWorker&&typeof Worker<"u")try{let i=await this.parseInWorker(n.buffer);return wh(i)}catch(i){console.warn("BSP worker parsing failed, falling back to main thread",i)}return fo(n.buffer)}parseInWorker(e){return new Promise((r,n)=>{if(!this.options.workerPath){n(new Error("No worker path provided"));return}let i=new Worker(this.options.workerPath,{type:"module"});i.onmessage=a=>{let{type:o,data:s,message:c}=a.data;o==="success"?(r(this.rehydrateData(s)),i.terminate()):(n(new Error(c)),i.terminate())},i.onerror=a=>{n(a),i.terminate()},i.postMessage(e,[e])})}rehydrateData(e){if(e.entities&&!e.entities.getUniqueClassnames){let r=e.entities;r.getUniqueClassnames=function(){let n=new Set;for(let i of this.entities)i.classname&&n.add(i.classname);return Array.from(n).sort()}}return e}};function fo(t){let e=my(t);return wh(e)}function wh(t){return{...t,pickEntity(e){let r=null,n=1/0;for(let i of t.entities.entities){let a=i.properties.model;if(!a||!a.startsWith("*"))continue;let o=parseInt(a.substring(1),10);if(isNaN(o)||o<0||o>=t.models.length)continue;let s=t.models[o],c=py(e.origin,e.direction,s.mins,s.maxs);c!==null&&c<n&&(n=c,r={entity:i,model:s,distance:c})}return r},findLeaf(e){let n=t.models[0].headNode;for(;n>=0;){let i=t.nodes[n],a=t.planes[i.planeIndex];a.normal[0]*e[0]+a.normal[1]*e[1]+a.normal[2]*e[2]-a.dist>=0?n=i.children[0]:n=i.children[1]}return t.leafs[-(n+1)]},calculatePVS(e){let r=this.findLeaf(e);if(!(r.cluster===-1||!t.visibility)&&!(r.cluster<0||r.cluster>=t.visibility.clusters.length))return t.visibility.clusters[r.cluster].pvs}}}function my(t){if(t.byteLength<hy)throw new fe("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!==dy)throw new fe(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==fy)throw new fe(`Unsupported BSP version ${n}`);let i=new Map;for(let E=0;E<Sh;E+=1){let L=e.getInt32(8+E*8,!0),A=e.getInt32(12+E*8,!0);if(L<0||A<0||L+A>t.byteLength)throw new fe(`Invalid lump bounds for index ${E}`);i.set(E,{offset:L,length:A})}let a={version:n,lumps:i},o=gy(t,i.get(0)),s=by(t,i.get(1)),c=xy(t,i.get(2)),l=vy(t,i.get(4)),u=_y(t,i.get(5)),d=Sy(t,i.get(6)),h=new Uint8Array(t,i.get(7).offset,i.get(7).length),m=Iy(d,i.get(7)),p=wy(t,i.get(8)),y=My(t,i.get(11)),g=Ay(t,i.get(12)),b=Ey(t,i.get(13)),_=Ty(t,i.get(14)),x=Ly(t,i.get(15)),v=By(t,i.get(9),i.get(10),p),w=Fy(t,i.get(3)),M=Py(t,i.get(17)),S=Ry(t,i.get(18));return{header:a,entities:o,planes:s,vertices:c,nodes:l,texInfo:u,faces:d,lightMaps:h,lightMapInfo:m,leafs:p,leafLists:v,edges:y,surfEdges:g,models:b,brushes:_,brushSides:x,visibility:w,areas:M,areaPortals:S}}function py(t,e,r,n){let i=0,a=1/0;for(let o=0;o<3;o++)if(Math.abs(e[o])<1e-8){if(t[o]<r[o]||t[o]>n[o])return null}else{let s=1/e[o],c=(r[o]-t[o])*s,l=(n[o]-t[o])*s;if(c>l){let u=c;c=l,l=u}if(i=Math.max(i,c),a=Math.min(a,l),i>a)return null}return i}function gy(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=yy(r),i=n.find(a=>a.classname==="worldspawn");return{raw:r,entities:n,worldspawn:i,getUniqueClassnames(){let a=new Set;for(let o of n)o.classname&&a.add(o.classname);return Array.from(a).sort()}}}function yy(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let i=n[1],a={},o=/"([^\"]*)"\s+"([^\"]*)"/g,s;for(;(s=o.exec(i))!==null;)a[s[1]]=s[2];e.push({classname:a.classname,properties:a})}return e}function by(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new fe("Plane lump has invalid length");let i=[];for(let a=0;a<n;a+=1){let o=[r.getFloat32(a*20,!0),r.getFloat32(a*20+4,!0),r.getFloat32(a*20+8,!0)],s=r.getFloat32(a*20+12,!0),c=r.getInt32(a*20+16,!0);i.push({normal:o,dist:s,type:c})}return i}function xy(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new fe("Vertex lump has invalid length");let i=[];for(let a=0;a<n;a+=1)i.push([r.getFloat32(a*12,!0),r.getFloat32(a*12+4,!0),r.getFloat32(a*12+8,!0)]);return i}function vy(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new fe("Node lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=[r.getInt32(s+4,!0),r.getInt32(s+8,!0)],u=[r.getInt16(s+12,!0),r.getInt16(s+14,!0),r.getInt16(s+16,!0)],d=[r.getInt16(s+18,!0),r.getInt16(s+20,!0),r.getInt16(s+22,!0)],h=r.getUint16(s+24,!0),m=r.getUint16(s+26,!0);a.push({planeIndex:c,children:l,mins:u,maxs:d,firstFace:h,numFaces:m})}return a}function _y(t,e){let r=new DataView(t,e.offset,e.length),n=76,i=e.length/n;if(i%1!==0)throw new fe("TexInfo lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=[r.getFloat32(s,!0),r.getFloat32(s+4,!0),r.getFloat32(s+8,!0)],l=r.getFloat32(s+12,!0),u=[r.getFloat32(s+16,!0),r.getFloat32(s+20,!0),r.getFloat32(s+24,!0)],d=r.getFloat32(s+28,!0),h=r.getInt32(s+32,!0),m=r.getInt32(s+36,!0),p=new Uint8Array(t,e.offset+s+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),g=r.getInt32(s+72,!0);a.push({s:c,sOffset:l,t:u,tOffset:d,flags:h,value:m,texture:y,nextTexInfo:g})}return a}function Sy(t,e){let r=new DataView(t,e.offset,e.length),n=20,i=e.length/n;if(i%1!==0)throw new fe("Face lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getUint16(s,!0),l=r.getInt16(s+2,!0),u=r.getInt32(s+4,!0),d=r.getInt16(s+8,!0),h=r.getInt16(s+10,!0),m=[r.getUint8(s+12),r.getUint8(s+13),r.getUint8(s+14),r.getUint8(s+15)],p=r.getInt32(s+16,!0);a.push({planeIndex:c,side:l,firstEdge:u,numEdges:d,texInfo:h,styles:m,lightOffset:p})}return a}function wy(t,e){let r=new DataView(t,e.offset,e.length),n=28,i=e.length/n;if(i%1!==0)throw new fe("Leaf lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt16(s+4,!0),u=r.getInt16(s+6,!0),d=[r.getInt16(s+8,!0),r.getInt16(s+10,!0),r.getInt16(s+12,!0)],h=[r.getInt16(s+14,!0),r.getInt16(s+16,!0),r.getInt16(s+18,!0)],m=r.getUint16(s+20,!0),p=r.getUint16(s+22,!0),y=r.getUint16(s+24,!0),g=r.getUint16(s+26,!0);a.push({contents:c,cluster:l,area:u,mins:d,maxs:h,firstLeafFace:m,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:g})}return a}function My(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new fe("Edge lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({vertices:[r.getUint16(s,!0),r.getUint16(s+2,!0)]})}return a}function Ay(t,e){let r=e.length/4;if(r%1!==0)throw new fe("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),i=new Int32Array(r);for(let a=0;a<r;a+=1)i[a]=n.getInt32(a*4,!0);return i}function Ey(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new fe("Model lump has invalid length");let i=e.length/n,a=[];for(let o=0;o<i;o+=1){let s=o*n,c=[r.getFloat32(s,!0),r.getFloat32(s+4,!0),r.getFloat32(s+8,!0)],l=[r.getFloat32(s+12,!0),r.getFloat32(s+16,!0),r.getFloat32(s+20,!0)],u=[r.getFloat32(s+24,!0),r.getFloat32(s+28,!0),r.getFloat32(s+32,!0)],d=r.getInt32(s+36,!0),h=r.getInt32(s+40,!0),m=r.getInt32(s+44,!0);a.push({mins:c,maxs:l,origin:u,headNode:d,firstFace:h,numFaces:m})}return a}function Ty(t,e){let r=new DataView(t,e.offset,e.length),n=12,i=e.length/n;if(i%1!==0)throw new fe("Brush lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({firstSide:r.getInt32(s,!0),numSides:r.getInt32(s+4,!0),contents:r.getInt32(s+8,!0)})}return a}function Ly(t,e){let r=new DataView(t,e.offset,e.length),n=4,i=e.length/n;if(i%1!==0)throw new fe("Brush side lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n;a.push({planeIndex:r.getUint16(s,!0),texInfo:r.getInt16(s+2,!0)})}return a}function Py(t,e){let r=new DataView(t,e.offset,e.length),n=8,i=e.length/n;if(i%1!==0)throw new fe("Area lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt32(s+4,!0);a.push({numAreaPortals:c,firstAreaPortal:l})}return a}function Ry(t,e){return Cy(t,e)}function Cy(t,e){let r=new DataView(t,e.offset,e.length),n=8,i=e.length/n;if(i%1!==0)throw new fe("AreaPortal lump has invalid length");let a=[];for(let o=0;o<i;o+=1){let s=o*n,c=r.getInt32(s,!0),l=r.getInt32(s+4,!0);a.push({portalNumber:c,otherArea:l})}return a}function By(t,e,r,n){let i=[],a=[],o=e.length/2,s=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let u of n){if(u.firstLeafFace+u.numLeafFaces>o)throw new fe("Leaf faces reference data past lump bounds");if(u.firstLeafBrush+u.numLeafBrushes>s)throw new fe("Leaf brushes reference data past lump bounds");let d=[];for(let m=0;m<u.numLeafFaces;m+=1)d.push(c.getUint16((u.firstLeafFace+m)*2,!0));let h=[];for(let m=0;m<u.numLeafBrushes;m+=1)h.push(l.getUint16((u.firstLeafBrush+m)*2,!0));i.push(d),a.push(h)}return{leafFaces:i,leafBrushes:a}}function Fy(t,e){if(e.length===0)return;if(e.length<4)throw new fe("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 fe("Visibility lump truncated");let a=4,o=[];for(let s=0;s<n;s+=1){let c=r.getInt32(a,!0),l=r.getInt32(a+4,!0);a+=8;let u=e.offset+c,d=e.offset+l,h=e.offset+e.length;if(c<0||l<0||u>=h||d>=h)throw new fe("Visibility offsets out of range");o.push({pvs:_h(t,u,n,e),phs:_h(t,d,n,e)})}return{numClusters:n,clusters:o}}function _h(t,e,r,n){let i=Math.ceil(r/8),a=new Uint8Array(i),o=new Uint8Array(t),s=e,c=0,l=n.offset+n.length;for(;c<i;){if(s>=l)throw new fe("Visibility data truncated");let u=o[s++];if(u!==0){a[c++]=u;continue}if(s>=l)throw new fe("Visibility run exceeds lump bounds");let d=o[s++];for(let h=0;h<d&&c<i;h+=1)a[c++]=0}return a}function Iy(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function fl(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 Dy=844121161,ky=8,Mh=68,st=class extends Error{},ji=class{constructor(e){this.vfs=e;f(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=zu(n.buffer);return this.cache.set(e,i),i}get(e){return this.cache.get(e)}};function Ah(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function ho(t,e,r,n){if(r!==0&&(e<Mh||e+r>t.byteLength))throw new st(`${n} section is out of bounds`)}function Uy(t){if(t.byteLength<Mh)throw new st("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==Dy)throw new st(`Invalid MD2 ident: ${r}`);if(n!==ky)throw new st(`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},a=40+i.numVertices*4;if(i.frameSize!==a)throw new st(`Unexpected frame size ${i.frameSize}, expected ${a}`);if(i.offsetEnd>t.byteLength)throw new st("MD2 offset_end exceeds buffer length");return i}function zy(t,e){let r=e.numSkins*64;ho(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),i=[];for(let a=0;a<e.numSkins;a+=1)i.push({name:Ah(n,a*64,64)});return i}function Oy(t,e){let r=e.numTexCoords*4;ho(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),i=[];for(let a=0;a<e.numTexCoords;a+=1){let o=a*4;i.push({s:n.getInt16(o,!0),t:n.getInt16(o+2,!0)})}return i}function Ny(t,e){let r=e.numTriangles*12;ho(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),i=[];for(let a=0;a<e.numTriangles;a+=1){let o=a*12,s=[n.getUint16(o,!0),n.getUint16(o+2,!0),n.getUint16(o+4,!0)],c=[n.getUint16(o+6,!0),n.getUint16(o+8,!0),n.getUint16(o+10,!0)];if(s.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new st("Triangle references out of range vertex or texcoord");i.push({vertexIndices:s,texCoordIndices:c})}return i}function Gy(t,e){let r=e.numFrames*e.frameSize;ho(t,e.offsetFrames,r,"frames");let n=[];for(let i=0;i<e.numFrames;i+=1){let a=e.offsetFrames+i*e.frameSize,o=new DataView(t,a,e.frameSize),s={x:o.getFloat32(0,!0),y:o.getFloat32(4,!0),z:o.getFloat32(8,!0)},c={x:o.getFloat32(12,!0),y:o.getFloat32(16,!0),z:o.getFloat32(20,!0)},l=Ah(o,24,16),u=[],d=1/0,h=1/0,m=1/0,p=-1/0,y=-1/0,g=-1/0;for(let b=0;b<e.numVertices;b+=1){let _=40+b*4,x=o.getUint8(_)*s.x+c.x,v=o.getUint8(_+1)*s.y+c.y,w=o.getUint8(_+2)*s.z+c.z;x<d&&(d=x),v<h&&(h=v),w<m&&(m=w),x>p&&(p=x),v>y&&(y=v),w>g&&(g=w);let M={x,y:v,z:w},S=o.getUint8(_+3),E=yr[S];if(!E)throw new st(`Invalid normal index ${S} in frame ${l}`);let L={x:E[0],y:E[1],z:E[2]};u.push({position:M,normalIndex:S,normal:L})}n.push({name:l,vertices:u,minBounds:{x:d,y:h,z:m},maxBounds:{x:p,y,z:g}})}return n}function Vy(t,e){let r=e.numGlCommands*4;if(ho(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),i=[],a=0;for(;;){if(a+4>r)throw new st("GL command list ended unexpectedly");let o=n.getInt32(a,!0);if(a+=4,o===0)break;let s=Math.abs(o),c=[],l=s*12;if(a+l>r)throw new st("GL command vertex block exceeds buffer");for(let u=0;u<s;u+=1){let d=n.getFloat32(a,!0),h=n.getFloat32(a+4,!0),m=n.getInt32(a+8,!0);if(a+=12,m<0||m>=e.numVertices)throw new st("GL command references invalid vertex index");c.push({s:d,t:h,vertexIndex:m})}i.push({mode:o>0?"strip":"fan",vertices:c})}if(a!==r)throw new st("GL command list did not consume expected data");return i}function zu(t){let e=Uy(t),r=zy(t,e),n=Oy(t,e),i=Ny(t,e),a=Gy(t,e),o=Vy(t,e);return{header:e,skins:r,texCoords:n,triangles:i,frames:a,glCommands:o}}function Eh(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,i=n.replace(/\d+$/,"")||n,a=r;for(;a+1<t.length&&(t[a+1].name.replace(/\d+$/,"")||t[a+1].name)===i;)a+=1;e.push({name:i,firstFrame:r,lastFrame:a}),r=a+1}return e}var Th=860898377,Hy=15,rr=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function mo(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function Wy(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 hl(t,e,r,n){if(e<0||e+r>n)throw new rr(`${t} exceeds buffer bounds`)}function Xy(t){let e=t.getInt32(0,!0);if(e!==Th)throw new rr(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==Hy)throw new rr(`Unsupported MD3 version: ${r}`);let n=mo(t,8,64),i=t.getInt32(72,!0),a=t.getInt32(76,!0),o=t.getInt32(80,!0),s=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),u=t.getInt32(96,!0),d=t.getInt32(100,!0),h=t.getInt32(104,!0);if(a<=0||s<0||o<0)throw new rr("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:i,numFrames:a,numTags:o,numSurfaces:s,numSkins:c,ofsFrames:l,ofsTags:u,ofsSurfaces:d,ofsEnd:h,magic:e}}function $y(t,e){let r=[];hl("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let a=e.ofsFrames+i*56;r.push({minBounds:{x:t.getFloat32(a,!0),y:t.getFloat32(a+4,!0),z:t.getFloat32(a+8,!0)},maxBounds:{x:t.getFloat32(a+12,!0),y:t.getFloat32(a+16,!0),z:t.getFloat32(a+20,!0)},localOrigin:{x:t.getFloat32(a+24,!0),y:t.getFloat32(a+28,!0),z:t.getFloat32(a+32,!0)},radius:t.getFloat32(a+36,!0),name:mo(t,a+40,16)})}return r}function Ky(t,e){let r=[],i=e.numFrames*e.numTags*112;hl("Tags",e.ofsTags,i,t.byteLength);for(let a=0;a<e.numFrames;a+=1){let o=[];for(let s=0;s<e.numTags;s+=1){let c=e.ofsTags+(a*e.numTags+s)*112,l=c+64,u=l+12;o.push({name:mo(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(u,!0),y:t.getFloat32(u+4,!0),z:t.getFloat32(u+8,!0)},{x:t.getFloat32(u+12,!0),y:t.getFloat32(u+16,!0),z:t.getFloat32(u+20,!0)},{x:t.getFloat32(u+24,!0),y:t.getFloat32(u+28,!0),z:t.getFloat32(u+32,!0)}]})}r.push(o)}return r}function Yy(t,e){let r=t.getInt32(e,!0);if(r!==Th)throw new rr(`Invalid surface ident at ${e}: ${r}`);let n=mo(t,e+4,64),i=t.getInt32(e+68,!0),a=t.getInt32(e+72,!0),o=t.getInt32(e+76,!0),s=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),u=t.getInt32(e+92,!0),d=t.getInt32(e+96,!0),h=t.getInt32(e+100,!0),m=t.getInt32(e+104,!0);if(a<=0||s<=0||c<=0)throw new rr(`Invalid surface counts for ${n}`);let p=m;hl(`Surface ${n}`,e,p,t.byteLength);let y=[],g=e+l;for(let S=0;S<c;S+=1){let E=g+S*12;y.push({indices:[t.getInt32(E,!0),t.getInt32(E+4,!0),t.getInt32(E+8,!0)]})}let b=[],_=e+u;for(let S=0;S<o;S+=1){let E=_+S*68;b.push({name:mo(t,E,64),shaderIndex:t.getInt32(E+64,!0)})}let x=[],v=e+d;for(let S=0;S<s;S+=1){let E=v+S*8;x.push({s:t.getFloat32(E,!0),t:t.getFloat32(E+4,!0)})}let w=[],M=e+h;for(let S=0;S<a;S+=1){let E=[];for(let L=0;L<s;L+=1){let A=M+(S*s+L)*8,R=t.getInt16(A,!0)/64,D=t.getInt16(A+2,!0)/64,k=t.getInt16(A+4,!0)/64,F=t.getUint16(A+6,!0);E.push({position:{x:R,y:D,z:k},latLng:F,normal:Wy(F)})}w.push(E)}return{surface:{name:n,flags:i,numFrames:a,shaders:b,triangles:y,texCoords:x,vertices:w},nextOffset:e+m}}function Ou(t){if(t.byteLength<108)throw new rr("MD3 buffer too small for header");let e=new DataView(t),r=Xy(e);hl("MD3 end",r.ofsEnd,0,t.byteLength);let n=$y(e,r),i=Ky(e,r),a=[],o=r.ofsSurfaces;for(let s=0;s<r.numSurfaces;s+=1){let{surface:c,nextOffset:l}=Yy(e,o);a.push(c),o=l}if(o!==r.ofsEnd)throw new rr("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:i,surfaces:a}}var Qi=class{constructor(e){this.vfs=e;f(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=Ou(r.slice().buffer);return this.cache.set(e,n),n}get(e){return this.cache.get(e)}};var qy=844317769,Zy=2,Lh=64,Ph=12,Pn=class extends Error{};function jy(t,e,r){let n=[];for(let i=0;i<r;i+=1){let a=t.getUint8(e+i);if(a===0)break;n.push(a)}return String.fromCharCode(...n)}function Nu(t){if(t.byteLength<Ph)throw new Pn("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!==qy)throw new Pn(`Invalid Sprite ident: ${r}`);if(n!==Zy)throw new Pn(`Unsupported Sprite version: ${n}`);let a=[],o=16+Lh,s=Ph;for(let c=0;c<i;c+=1){if(s+o>t.byteLength)throw new Pn("Sprite frame data exceeds buffer length");let l=e.getInt32(s,!0),u=e.getInt32(s+4,!0),d=e.getInt32(s+8,!0),h=e.getInt32(s+12,!0),m=jy(e,s+16,Lh);a.push({width:l,height:u,originX:d,originY:h,name:m}),s+=o}return{ident:r,version:n,numFrames:i,frames:a}}var Ji=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),Nu(n.buffer)}};function Rh(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 Ch(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 a=n?i%e:Math.min(i,e-1),o=Math.floor(a),s=t.sequence.start+o,c=o+1>=e?n?t.sequence.start:t.sequence.end:s+1,l=!n&&o>=e-1?0:a-o;return{frame0:s,frame1:c,lerp:l}}function Bh(t){return{sequence:t,time:0}}function Fh(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 po=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function ml(t){if(t.byteLength<100)throw new po("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),a=e.getInt32(36,!0),o=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],s=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(s).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),u=e.getInt32(92,!0),d=e.getInt32(96,!0);if(i<=0||a<=0)throw new po("Invalid WAL dimensions");let h=[],m=i,p=a;for(let y=0;y<o.length;y+=1){let g=o[y],b=Math.max(1,m*p|0);if(g<=0||g+b>t.byteLength)throw new po(`Invalid WAL mip offset for level ${y}`);let _=new Uint8Array(t,g,b);h.push({level:y,width:m,height:p,data:_}),m=Math.max(1,m>>1),p=Math.max(1,p>>1)}return{name:n,width:i,height:a,mipmaps:h,animName:c,flags:l,contents:u,value:d}}var di=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function go(t){if(t.byteLength<128)throw new di("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),i=e.getUint8(3),a=e.getUint16(4,!0),o=e.getUint16(6,!0),s=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new di("Unsupported PCX encoding");if(i!==8)throw new di("Only 8bpp PCX files are supported");let l=s-a+1,u=c-o+1,d=e.getUint16(66,!0),h=t.byteLength-769;if(h<128||new DataView(t,h,1).getUint8(0)!==12)throw new di("Missing PCX palette");let m=new Uint8Array(t,h+1,768),p=new Uint8Array(t,128,h-128),y=new Uint8Array(l*u),g=0,b=0;for(let _=0;_<u;_+=1){let x=0;for(;x<d&&g<p.length;){let v=1,w=p[g++];if((w&192)===192){if(v=w&63,g>=p.length)throw new di("Unexpected end of PCX RLE data");w=p[g++]}for(let M=0;M<v&&x<d;M+=1)x<l&&(y[b++]=w),x+=1}}return{width:l,height:u,bitsPerPixel:i,pixels:y,palette:m}}function pl(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,a=r*4;e[a]=t.palette[i],e[a+1]=t.palette[i+1],e[a+2]=t.palette[i+2],e[a+3]=n===255?0:255}return e}var jr=class extends Error{constructor(e){super(e),this.name="TgaParseError"}};function Gu(t){let e=new DataView(t);if(t.byteLength<18)throw new jr("Buffer too small for TGA header");let r=e.getUint8(0),n=e.getUint8(1),i=e.getUint8(2),a=e.getUint16(12,!0),o=e.getUint16(14,!0),s=e.getUint8(16),c=e.getUint8(17);if(i!==2&&i!==10&&i!==3&&i!==11)throw new jr(`Unsupported TGA image type: ${i} (only RGB/Grayscale supported)`);if(s!==24&&s!==32&&s!==8)throw new jr(`Unsupported pixel depth: ${s} (only 8, 24, 32 bpp supported)`);let l=i>=9,u=i===3||i===11,d=s/8,h=18+r;if(n===1){let x=e.getUint16(5,!0),v=e.getUint8(7);h+=x*(v/8)}let m=a*o,p=new Uint8Array(m*4),y=(c&32)!==0,g=0,b=new Uint8Array(t),_=x=>{if(u){let v=b[h++];p[x]=v,p[x+1]=v,p[x+2]=v,p[x+3]=255}else{let v=b[h++],w=b[h++],M=b[h++],S=s===32?b[h++]:255;p[x]=M,p[x+1]=w,p[x+2]=v,p[x+3]=S}};if(l){let x=0;for(;x<m;){if(h>=t.byteLength)throw new jr("Unexpected end of TGA RLE data");let v=b[h++],w=(v&127)+1,M=(v&128)!==0;if(x+w>m)throw new jr("TGA RLE packet exceeds image bounds");if(M){let S=u?b[h]:b[h+2],E=u?b[h]:b[h+1],L=b[h],A=u?255:s===32?b[h+3]:255;h+=d;for(let R=0;R<w;R++){let D=(x+R)*4;p[D]=S,p[D+1]=E,p[D+2]=L,p[D+3]=A}}else for(let S=0;S<w;S++)_((x+S)*4);x+=w}}else for(let x=0;x<m;x++){if(h>=t.byteLength)throw new jr("Unexpected end of TGA data");_(x*4)}if(!y){let x=a*4,v=new Uint8Array(x);for(let w=0;w<o/2;w++){let M=w*x,S=(o-1-w)*x;v.set(p.subarray(M,M+x)),p.set(p.subarray(S,S+x),M),p.set(v,S)}}return{width:a,height:o,bitsPerPixel:32,pixels:p}}function Qy(t){let e=0;for(let r of t.levels)e+=r.rgba.byteLength;return e}var ea=class{constructor(e={}){f(this,"cache");this.cache=new Ln(e.capacity??128,e.maxMemory??256*1024*1024,Qy)}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()}get capacity(){return this.cache.capacity}set capacity(e){this.cache.capacity=e}get maxMemory(){return this.cache.maxMemory}set maxMemory(e){this.cache.maxMemory=e}};function Vu(t,e){let r=[];for(let n of t.mipmaps){let i=new Uint8Array(n.width*n.height*4);for(let a=0;a<n.data.length;a+=1){let o=n.data[a],s=o*3,c=a*4;i[c]=e[s],i[c+1]=e[s+1],i[c+2]=e[s+2],i[c+3]=o===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 gl(t){let e=pl(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Ih(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 yl(t,e){return Vu(ml(t),e)}var fi=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function Hu(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function bl(t){if(t.byteLength<44)throw new fi("WAV buffer too small");let e=new DataView(t);if(Hu(e,0,4)!=="RIFF"||Hu(e,8,4)!=="WAVE")throw new fi("Invalid WAV header");let r=12,n=-1,i=-1,a=0,o=0;for(;r+8<=t.byteLength;){let p=Hu(e,r,4),y=e.getUint32(r+4,!0),g=r+8;p==="fmt "?(n=g,a=y):p==="data"&&(i=g,o=y),r=g+y}if(n===-1||i===-1)throw new fi("Missing fmt or data chunk");let s=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),u=e.getUint16(n+14,!0);if(s!==1)throw new fi("Only PCM WAV is supported");let d=u/8,h=o/(d*c),m=new Float32Array(h*c);for(let p=0;p<h;p+=1)for(let y=0;y<c;y+=1){let g=p*c+y,b=i+g*d,_=0;if(u===8)_=e.getUint8(b),m[g]=(_-128)/128;else if(u===16)_=e.getInt16(b,!0),m[g]=_/32768;else if(u===24){let x=e.getUint8(b),v=e.getUint8(b+1),w=e.getInt8(b+2);_=x|v<<8|w<<16,m[g]=_/8388608}else throw new fi(`Unsupported bitsPerSample: ${u}`)}return{sampleRate:l,channels:c,bitsPerSample:u,samples:m}}var Jy=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),i,a,o,s=e;for(i=0;i<256;i++){for(o=i<<24,a=8;a>0;--a)o=2147483648&o?o<<1^r:o<<1;n[i]=o}for(i=0;i<t.length;i++)s=s<<8^n[255&(s>>24^t[i])];return s};var Wu=(t,e=Jy)=>{let r=g=>new Uint8Array(g.length/2).map(((b,_)=>parseInt(g.substring(2*_,2*(_+1)),16))),n=g=>r(g)[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(((g,b)=>i.set(g,b)));let a=new Uint8Array(t.length),o,s,c,l=!1,u=0,d=42,h=t.length>13&&t.substring(0,9)==="dynEncode",m=0;h&&(m=11,s=n(t.substring(9,m)),s<=1&&(m+=2,d=n(t.substring(11,m))),s===1&&(m+=8,c=(g=>new DataView(r(g).buffer).getInt32(0,!0))(t.substring(13,m))));let p=256-d;for(let g=m;g<t.length;g++)if(o=t.charCodeAt(g),o!==61||l){if(o===92&&g<t.length-5&&h){let b=t.charCodeAt(g+1);b!==117&&b!==85||(o=parseInt(t.substring(g+2,g+6),16),g+=5)}if(o>255){let b=i.get(o);b&&(o=b+127)}l&&(l=!1,o-=64),a[u++]=o<d&&o>0?o+p:o-d}else l=!0;let y=a.subarray(0,u);if(h&&s===1){let g=e(y);if(g!==c){let b="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",b+`
|
|
2
2
|
`,"Expected: "+c+"; Got: "+g+`
|
|
3
|
-
`,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(b)}}return y};function Se(){let t=Uint8Array,e=Float32Array;Se.modules||Object.defineProperties(Se,{modules:{value:new WeakMap},setModule:{value(r,n){Se.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=Se.modules.get(r);return i||(n?i=WebAssembly.compile(Wu(n)):(n=r.wasm,i=Se.inflateDynEncodeString(n).then(a=>WebAssembly.compile(a))),Se.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new e(n),a=0,o=0;for(;a<r.length;)i.set(r[a],o),o+=r[a++].length;return i}},getDecodedAudio:{value:(r,n,i,a,o)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:a,bitDepth:o})},getDecodedAudioMultiChannel:{value(r,n,i,a,o,s){let c=[],l,u;for(l=0;l<i;l++){let d=[];for(u=0;u<n.length;)d.push(n[u++][l]||[]);c.push(Se.concatFloat32(d,a))}return Se.getDecodedAudio(r,c,a,o,s)}},inflateDynEncodeString:{value(r){return r=Wu(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 `;Se.getModule(Se,i).then(a=>WebAssembly.instantiate(a,{})).then(({exports:a})=>{let o=new Map(Object.entries(a)),s=o.get("puff"),c=o.get("memory").buffer,l=new t(c),u=new DataView(c),d=o.get("__heap_base"),f=r.length,m=d;d+=4,u.setInt32(m,f,!0);let p=d;d+=f,l.set(r,p);let y=d;d+=4,u.setInt32(y,l.byteLength-d,!0),s(d,y,p,m),n(l.slice(d,d+u.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let a=[],o=0;for(;o<n;)a.push(r.slice(o*i,o++*i+i));return a},this.allocateTypedArray=(r,n,i=!0)=>{let a=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return i&&this._pointers.add(a),{ptr:a,len:r,buf:new n(this._wasm.HEAP,a,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 a=i[r];a!==0;a=i[++r])n.push(a);return String.fromCharCode.apply(null,n)},this.addError=(r,n,i,a,o,s)=>{r.push({message:n,frameLength:i,frameNumber:a,inputBytes:o,outputSamples:s})},this.instantiate=(r,n)=>(n&&Se.setModule(r,n),this._wasm=new r(Se).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Uh=xg(kh(),1);var e1=()=>globalThis.Worker||Uh.default,ta=class extends e1(){constructor(e,r,n,i){Se.modules||new Se;let a=Se.modules.get(n);if(!a){let o="text/javascript",s,c=`'use strict';(${((l,u,d)=>{let f,m,p=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:g,data:b}})=>{let _=p,x={id:y},v;g==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:u},EmscriptenWASM:{value:d},module:{value:b.module},isWebWorker:{value:!0}}),f=new l(b.options),m()):g==="free"?f.free():g==="ready"?_=_.then(()=>f.ready):g==="reset"?_=_.then(()=>f.reset()):(Object.assign(x,f[g](Array.isArray(b)?b.map(S=>new Uint8Array(S)):new Uint8Array(b))),v=x.channelData?x.channelData.map(S=>S.buffer):[]),_.then(()=>self.postMessage(x,v))}}).toString()})(${n}, ${Se}, ${i})`;try{s=typeof process.versions.node<"u"}catch{}a=s?`data:${o};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:o})),Se.modules.set(n,a)}super(a,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:o})=>{let{id:s,...c}=o;this._enqueuedOperations.get(s)(c),this._enqueuedOperations.delete(s)},new i(Se).getModule().then(o=>{this.postToDecoder("init",{module:o,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 xl=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var we=Symbol,zh=", ",X=(()=>{let t="front",e="side",r="rear",n="left",i="center",a="right";return["",t+" ",e+" ",r+" "].map(o=>[[n,a],[n,a,i],[n,i,a],[i,n,a],[i]].flatMap(s=>s.map(c=>o+c).join(zh)))})(),Dr="LFE",Rn="monophonic (mono)",Cn="stereo",yo="surround",Pe=(t,...e)=>`${[Rn,Cn,`linear ${yo}`,"quadraphonic",`5.0 ${yo}`,`5.1 ${yo}`,`6.1 ${yo}`,`7.1 ${yo}`][t-1]} (${e.join(zh)})`,bo=[Rn,Pe(2,X[0][0]),Pe(3,X[0][2]),Pe(4,X[1][0],X[3][0]),Pe(5,X[1][2],X[3][0]),Pe(6,X[1][2],X[3][0],Dr),Pe(7,X[1][2],X[2][0],X[3][4],Dr),Pe(8,X[1][2],X[2][0],X[3][0],Dr)],Oh=192e3,Nh=176400,vl=96e3,_l=88200,Gh=64e3,Bn=48e3,ra=44100,na=32e3,ia=24e3,aa=22050,oa=16e3,Sl=12e3,wl=11025,sa=8e3,Vh=7350,xr="absoluteGranulePosition",q="bandwidth",ht="bitDepth",mt="bitrate",xo=mt+"Maximum",vo=mt+"Minimum",_o=mt+"Nominal",kr="buffer",So=kr+"Fullness",be="codec",pt=be+"Frames",wo="coupledStreamCount",la="crc",Mo=la+"16",Ao=la+"32",ye="data",W="description",Ur="duration",ca="emphasis",Eo="hasOpusPadding",Wt="header",Fn="isContinuedPacket",To="isCopyrighted",In="isFirstPage",Lo="isHome",Xt="isLastPage",Qr="isOriginal",Jr="isPrivate",Po="isVbr",Ot="layer",B="length",Y="mode",en=Y+"Extension",Ml="mpeg",tn=Ml+"Version",Ro="numberAACFrames",Co="outputGain",hi="preSkip",Bo="profile",Al=we(),rn="protection",Xu="rawData",nr="segments",Q="subarray",Dn="version",mi="vorbis",Fo=mi+"Comments",ua=mi+"Setup",El="block",Io=El+"ingStrategy",Tl=we(),nn=El+"Size",kn=El+"size0",Un=El+"size1",Do=we(),Ll="channel",an=Ll+"MappingFamily",ko=Ll+"MappingTable",gt=Ll+"Mode",Uo=we(),H=Ll+"s",Hh="copyright",zo=Hh+"Id",Oo=Hh+"IdStart",on="frame",sn=on+"Count",Nt=on+"Length",Pl="Number",ln=on+Pl,zr=on+"Padding",$=on+"Size",Wh="Rate",No="inputSample"+Wh,$u="page",pi=$u+"Checksum",da=we(),zn=$u+"SegmentTable",ke=$u+"Sequence"+Pl,Ku="sample",Go=Ku+Pl,ie=Ku+Wh,Or=we(),ae=Ku+"s",Rl="stream",Vo=Rl+"Count",Ho=Rl+"Info",Nr=Rl+"Serial"+Pl,Yu=Rl+"StructureVersion",qu="total",gi=qu+"BytesOut",yi=qu+"Duration",bi=qu+"Samples",ce=we(),ir=we(),Wo=we(),On=we(),vr=we(),Cl=we(),Zu=we(),Nn=we(),pe=we(),ar=we(),or=we(),Gr=we(),Gn=we(),Bl=we(),_r=we(),Sr=we(),sr=we(),Fl=we(),yt=Uint8Array,Vn=DataView,ge="reserved",bt="bad",fa="free",Xo="none",Il="16bit CRC";var ju=(t,e,r)=>{for(let n=0;n<t[B];n++){let i=e(n);for(let a=8;a>0;a--)i=r(i);t[n]=i}return t},r1=ju(new yt(256),t=>t,t=>t&128?7^t<<1:t<<1),Re=[ju(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],Ce=[ju(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){Re.push(new Uint16Array(256)),Ce.push(new Uint32Array(256));for(let e=0;e<=255;e++)Re[t+1][e]=Re[0][Re[t][e]>>>8]^Re[t][e]<<8,Ce[t+1][e]=Ce[t][e]>>>8^Ce[0][Ce[t][e]&255]}var $h=t=>{let e=0,r=t[B];for(let n=0;n!==r;n++)e=r1[e^t[n]];return e},Kh=t=>{let e=t[B],r=e-16,n=0,i=0;for(;i<=r;)n^=t[i++]<<8|t[i++],n=Re[15][n>>8]^Re[14][n&255]^Re[13][t[i++]]^Re[12][t[i++]]^Re[11][t[i++]]^Re[10][t[i++]]^Re[9][t[i++]]^Re[8][t[i++]]^Re[7][t[i++]]^Re[6][t[i++]]^Re[5][t[i++]]^Re[4][t[i++]]^Re[3][t[i++]]^Re[2][t[i++]]^Re[1][t[i++]]^Re[0][t[i++]];for(;i!==e;)n=(n&255)<<8^Re[0][n>>8^t[i++]];return n},Yh=t=>{let e=t[B],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},Ko=(...t)=>{let e=new yt(t.reduce((r,n)=>r+n[B],0));return t.reduce((r,n)=>(e.set(n,r),r+n[B]),0),e},$t=t=>String.fromCharCode(...t),Xh=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],$o=t=>Xh[t&15]<<4|Xh[t>>4],Dl=class{constructor(e){this._data=e,this._pos=e[B]*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,($o(this._data[r-1])<<8)+$o(this._data[r])>>7-n&255}},qh=(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 Yo=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[_r]()}[Sr](){this._isEnabled=!0}[_r](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[Bl](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}}[pe](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[ar](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 Ge=new WeakMap,lt=new WeakMap;var xt=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[Zu](){let e;do{if(e=yield*this.Frame[or](this._codecParser,this._headerCache,0),e)return e;this._codecParser[ir](1)}while(!0)}*[Nn](e){let r=yield*this[Zu](),n=lt.get(r)[B];if(e||this._codecParser._flushing||(yield*this.Header[pe](this._codecParser,this._headerCache,n)))return this._headerCache[Sr](),this._codecParser[ir](n),this._codecParser[On](r),r;this._codecParser[vr](`Missing ${on} at ${n} bytes from current position.`,`Dropping current ${on} and trying again.`),this._headerCache[_r](),this._codecParser[ir](1)}};var xi=class{constructor(e,r){lt.set(this,{[Wt]:e}),this[ye]=r}};var Kt=class extends xi{static*[or](e,r,n,i,a){let o=yield*e[pe](n,i,a);if(o){let s=Ge.get(o)[Nt],c=Ge.get(o)[ae],l=(yield*n[ce](s,a))[Q](0,s);return new r(o,l,c)}else return null}constructor(e,r,n){super(e,r),this[Wt]=e,this[ae]=n,this[Ur]=n/e[ie]*1e3,this[ln]=null,this[gi]=null,this[bi]=null,this[yi]=null,lt.get(this)[B]=r[B]}};var Qu="unsynchronizationFlag",Ju="extendedHeaderFlag",ed="experimentalFlag",td="footerPresent",qo=class t{static*getID3v2Header(e,r,n){let a={},o=yield*e[ce](3,n);if(o[0]!==73||o[1]!==68||o[2]!==51||(o=yield*e[ce](10,n),a[Dn]=`id3v2.${o[3]}.${o[4]}`,o[5]&15)||(a[Qu]=!!(o[5]&128),a[Ju]=!!(o[5]&64),a[ed]=!!(o[5]&32),a[td]=!!(o[5]&16),o[6]&128||o[7]&128||o[8]&128||o[9]&128))return null;let s=o[6]<<21|o[7]<<14|o[8]<<7|o[9];return a[B]=10+s,new t(a)}constructor(e){this[Dn]=e[Dn],this[Qu]=e[Qu],this[Ju]=e[Ju],this[ed]=e[ed],this[td]=e[td],this[B]=e[B]}};var Yt=class{constructor(e){Ge.set(this,e),this[ht]=e[ht],this[mt]=null,this[H]=e[H],this[gt]=e[gt],this[ie]=e[ie]}};var em={0:[fa,fa,fa,fa,fa],16:[32,32,32,32,8],240:[bt,bt,bt,bt,bt]},kl=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)em[t<<4]=[t*32,kl(t,4,0),kl(t,4,-1),kl(t,8,4),kl(t,8,0)];var n1=0,i1=1,a1=2,o1=3,Zh=4,Ul="bands ",zl=" to 31",jh={0:Ul+4+zl,16:Ul+8+zl,32:Ul+12+zl,48:Ul+16+zl},vi="bitrateIndex",Zo="v2",Hl="v1",Ol="Intensity stereo ",Nl=", MS stereo ",Gl="on",Vl="off",s1={0:Ol+Vl+Nl+Vl,16:Ol+Gl+Nl+Vl,32:Ol+Vl+Nl+Gl,48:Ol+Gl+Nl+Gl},rd={0:{[W]:ge},2:{[W]:"Layer III",[zr]:1,[en]:s1,[Hl]:{[vi]:a1,[ae]:1152},[Zo]:{[vi]:Zh,[ae]:576}},4:{[W]:"Layer II",[zr]:1,[en]:jh,[ae]:1152,[Hl]:{[vi]:i1},[Zo]:{[vi]:Zh}},6:{[W]:"Layer I",[zr]:4,[en]:jh,[ae]:384,[Hl]:{[vi]:n1},[Zo]:{[vi]:o1}}},nd="MPEG Version ",Qh="ISO/IEC ",l1={0:{[W]:`${nd}2.5 (later extension of MPEG 2)`,[Ot]:Zo,[ie]:{0:wl,4:Sl,8:sa,12:ge}},8:{[W]:ge},16:{[W]:`${nd}2 (${Qh}13818-3)`,[Ot]:Zo,[ie]:{0:aa,4:ia,8:oa,12:ge}},24:{[W]:`${nd}1 (${Qh}11172-3)`,[Ot]:Hl,[ie]:{0:ra,4:Bn,8:na,12:ge}},length:B},c1={0:Il,1:Xo},u1={0:Xo,1:"50/15 ms",2:ge,3:"CCIT J.17"},Jh={0:{[H]:2,[W]:Cn},64:{[H]:2,[W]:"joint "+Cn},128:{[H]:2,[W]:"dual channel"},192:{[H]:1,[W]:Rn}},_i=class t extends Yt{static*[pe](e,r,n){let i={},a=yield*qo.getID3v2Header(e,r,n);a&&(yield*e[ce](a[B],n),e[ir](a[B]));let o=yield*e[ce](4,n),s=$t(o[Q](0,4)),c=r[pe](s);if(c)return new t(c);if(o[0]!==255||o[1]<224)return null;let l=l1[o[1]&24];if(l[W]===ge)return null;let u=o[1]&6;if(rd[u][W]===ge)return null;let d={...rd[u],...rd[u][l[Ot]]};if(i[tn]=l[W],i[Ot]=d[W],i[ae]=d[ae],i[rn]=c1[o[1]&1],i[B]=4,i[mt]=em[o[2]&240][d[vi]],i[mt]===bt||(i[ie]=l[ie][o[2]&12],i[ie]===ge)||(i[zr]=o[2]&2&&d[zr],i[Jr]=!!(o[2]&1),i[Nt]=Math.floor(125*i[mt]*i[ae]/i[ie]+i[zr]),!i[Nt]))return null;let f=o[3]&192;if(i[gt]=Jh[f][W],i[H]=Jh[f][H],i[en]=d[en][o[3]&48],i[To]=!!(o[3]&8),i[Qr]=!!(o[3]&4),i[ca]=u1[o[3]&3],i[ca]===ge)return null;i[ht]=16;{let{length:m,frameLength:p,samples:y,...g}=i;r[ar](s,i,g)}return new t(i)}constructor(e){super(e),this[mt]=e[mt],this[ca]=e[ca],this[zr]=e[zr],this[To]=e[To],this[Qr]=e[Qr],this[Jr]=e[Jr],this[Ot]=e[Ot],this[en]=e[en],this[tn]=e[tn],this[rn]=e[rn]}};var jo=class t extends Kt{static*[or](e,r,n){return yield*super[or](_i,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Qo=class extends xt{constructor(e,r,n){super(e,r),this.Frame=jo,this.Header=_i,n(this[be])}get[be](){return Ml}*[Gr](){return yield*this[Nn]()}};var d1={0:"MPEG-4",8:"MPEG-2"},f1={0:"valid",2:bt,4:bt,6:bt},h1={0:Il,1:Xo},m1={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},p1={0:vl,4:_l,8:Gh,12:Bn,16:ra,20:na,24:ia,28:aa,32:oa,36:Sl,40:wl,44:sa,48:Vh,52:ge,56:ge,60:"frequency is written explicitly"},tm={0:{[H]:0,[W]:"Defined in AOT Specific Config"},64:{[H]:1,[W]:Rn},128:{[H]:2,[W]:Pe(2,X[0][0])},192:{[H]:3,[W]:Pe(3,X[1][3])},256:{[H]:4,[W]:Pe(4,X[1][3],X[3][4])},320:{[H]:5,[W]:Pe(5,X[1][3],X[3][0])},384:{[H]:6,[W]:Pe(6,X[1][3],X[3][0],Dr)},448:{[H]:8,[W]:Pe(8,X[1][3],X[2][0],X[3][0],Dr)}},Si=class t extends Yt{static*[pe](e,r,n){let i={},a=yield*e[ce](7,n),o=$t([a[0],a[1],a[2],a[3]&252|a[6]&3]),s=r[pe](o);if(s)Object.assign(i,s);else{if(a[0]!==255||a[1]<240||(i[tn]=d1[a[1]&8],i[Ot]=f1[a[1]&6],i[Ot]===bt))return null;let l=a[1]&1;i[rn]=h1[l],i[B]=l?7:9,i[Al]=a[2]&192,i[Or]=a[2]&60;let u=a[2]&2;if(i[Bo]=m1[i[Al]],i[ie]=p1[i[Or]],i[ie]===ge)return null;i[Jr]=!!u,i[Uo]=(a[2]<<8|a[3])&448,i[gt]=tm[i[Uo]][W],i[H]=tm[i[Uo]][H],i[Qr]=!!(a[3]&32),i[Lo]=!!(a[3]&8),i[zo]=!!(a[3]&8),i[Oo]=!!(a[3]&4),i[ht]=16,i[ae]=1024,i[Ro]=a[6]&3;{let{length:d,channelModeBits:f,profileBits:m,sampleRateBits:p,frameLength:y,samples:g,numberAACFrames:b,..._}=i;r[ar](o,i,_)}}if(i[Nt]=(a[3]<<11|a[4]<<3|a[5]>>5)&8191,!i[Nt])return null;let c=(a[5]<<6|a[6]>>2)&2047;return i[So]=c===2047?"VBR":c,new t(i)}constructor(e){super(e),this[zo]=e[zo],this[Oo]=e[Oo],this[So]=e[So],this[Lo]=e[Lo],this[Qr]=e[Qr],this[Jr]=e[Jr],this[Ot]=e[Ot],this[B]=e[B],this[tn]=e[tn],this[Ro]=e[Ro],this[Bo]=e[Bo],this[rn]=e[rn]}get audioSpecificConfig(){let e=Ge.get(this),r=e[Al]+64<<5|e[Or]<<5|e[Uo]>>3,n=new yt(2);return new Vn(n[kr]).setUint16(0,r,!1),n}};var Jo=class t extends Kt{static*[or](e,r,n){return yield*super[or](Si,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var es=class extends xt{constructor(e,r,n){super(e,r),this.Frame=Jo,this.Header=Si,n(this[be])}get[be](){return"aac"}*[Gr](){return yield*this[Nn]()}};var Hn=class t extends Kt{static _getFrameFooterCrc16(e){return(e[e[B]-2]<<8)+e[e[B]-1]}static[Fl](e){let r=t._getFrameFooterCrc16(e),n=Kh(e[Q](0,-2));return r===n}constructor(e,r,n){r[Ho]=n,r[Mo]=t._getFrameFooterCrc16(e),super(r,e,Ge.get(r)[ae])}};var rm="get from STREAMINFO metadata block",g1={0:"Fixed",1:"Variable"},nm={0:ge,16:192};for(let t=2;t<16;t++)nm[t<<4]=t<6?576*2**(t-2):2**t;var y1={0:rm,1:_l,2:Nh,3:Oh,4:sa,5:oa,6:aa,7:ia,8:na,9:ra,10:Bn,11:vl,15:bt},b1={0:{[H]:1,[W]:Rn},16:{[H]:2,[W]:Pe(2,X[0][0])},32:{[H]:3,[W]:Pe(3,X[0][1])},48:{[H]:4,[W]:Pe(4,X[1][0],X[3][0])},64:{[H]:5,[W]:Pe(5,X[1][1],X[3][0])},80:{[H]:6,[W]:Pe(6,X[1][1],Dr,X[3][0])},96:{[H]:7,[W]:Pe(7,X[1][1],Dr,X[3][4],X[2][0])},112:{[H]:8,[W]:Pe(8,X[1][1],Dr,X[3][0],X[2][0])},128:{[H]:2,[W]:`${Cn} (left, diff)`},144:{[H]:2,[W]:`${Cn} (diff, right)`},160:{[H]:2,[W]:`${Cn} (avg, diff)`},176:ge,192:ge,208:ge,224:ge,240:ge},x1={0:rm,2:8,4:12,6:ge,8:16,10:20,12:24,14:ge},Wn=class t extends Yt{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let o=64;o&e[0];o>>=1)r++;let n=r-1,i=0,a=0;for(;n>0;a+=6,n--){if((e[n]&192)!==128)return null;i|=(e[n]&63)<<a}return i|=(e[n]&127>>r)<<a,{value:i,length:r}}static[sr](e,r){let n={[ce]:function*(){return e}};return t[pe](n,r,0).next().value}static*[pe](e,r,n){let i=yield*e[ce](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let a={},o=$t(i[Q](0,4)),s=r[pe](o);if(s)Object.assign(a,s);else{if(a[Tl]=i[1]&1,a[Io]=g1[a[Tl]],a[Do]=i[2]&240,a[Or]=i[2]&15,a[nn]=nm[a[Do]],a[nn]===ge||(a[ie]=y1[a[Or]],a[ie]===bt)||i[3]&1)return null;let l=b1[i[3]&240];if(l===ge||(a[H]=l[H],a[gt]=l[W],a[ht]=x1[i[3]&14],a[ht]===ge))return null}a[B]=5,i=yield*e[ce](a[B]+8,n);let c=t._decodeUTF8Int(i[Q](4));if(!c||(a[Tl]?a[Go]=c.value:a[ln]=c.value,a[B]+=c[B],a[Do]===96?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[nn]=i[a[B]-1]+1,a[B]+=1):a[Do]===112&&(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[nn]=(i[a[B]-1]<<8)+i[a[B]]+1,a[B]+=2),a[ae]=a[nn],a[Or]===12?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=i[a[B]-1]*1e3,a[B]+=1):a[Or]===13?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=(i[a[B]-1]<<8)+i[a[B]],a[B]+=2):a[Or]===14&&(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=((i[a[B]-1]<<8)+i[a[B]])*10,a[B]+=2),i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[la]=i[a[B]-1],a[la]!==$h(i[Q](0,a[B]-1))))return null;if(!s){let{blockingStrategyBits:l,frameNumber:u,sampleNumber:d,samples:f,sampleRateBits:m,blockSizeBits:p,crc:y,length:g,...b}=a;r[ar](o,a,b)}return new t(a)}constructor(e){super(e),this[Mo]=null,this[Io]=e[Io],this[nn]=e[nn],this[ln]=e[ln],this[Go]=e[Go],this[Ho]=null}};var v1=2,_1=512*1024,wi=class extends xt{constructor(e,r,n){super(e,r),this.Frame=Hn,this.Header=Wn,n(this[be])}get[be](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[ce](2,0),n=r[B]-2;for(;e<n;){if(r[e]===255){let a=r[e+1];if(a===248||a===249)break;a!==255&&e++}e++}return e}*[Gr](){do{let e=yield*Wn[pe](this._codecParser,this._headerCache,0);if(e){let r=Ge.get(e)[B]+v1;for(;r<=_1;){if(this._codecParser._flushing||(yield*Wn[pe](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[ce](r);if(this._codecParser._flushing||(n=n[Q](0,r)),Hn[Fl](n)){let i=new Hn(n,e);return this._headerCache[Sr](),this._codecParser[ir](r),this._codecParser[On](i),i}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[vr](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[ir](r)}else this._codecParser[ir](yield*this._getNextFrameSyncOffset(1))}while(!0)}[Gn](e){return e[ke]===0?(this._headerCache[Sr](),this._streamInfo=e[ye][Q](13)):e[ke]===1||(e[pt]=lt.get(e)[nr].map(r=>{let n=Wn[sr](r,this._headerCache);if(n)return new Hn(r,n,this._streamInfo);this._codecParser[vr]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var Mi=class t{static*[pe](e,r,n){let i={},a=yield*e[ce](28,n);if(a[0]!==79||a[1]!==103||a[2]!==103||a[3]!==83||(i[Yu]=a[4],a[5]&248))return null;i[Xt]=!!(a[5]&4),i[In]=!!(a[5]&2),i[Fn]=!!(a[5]&1);let s=new Vn(yt.from(a[Q](0,28))[kr]);i[xr]=qh(s,6),i[Nr]=s.getInt32(14,!0),i[ke]=s.getInt32(18,!0),i[pi]=s.getInt32(22,!0);let c=a[26];i[B]=c+27,a=yield*e[ce](i[B],n),i[Nt]=0,i[zn]=[],i[da]=yt.from(a[Q](27,i[B]));for(let l=0,u=0;l<c;l++){let d=i[da][l];i[Nt]+=d,u+=d,(d!==255||l===c-1)&&(i[zn].push(u),u=0)}return new t(i)}constructor(e){Ge.set(this,e),this[xr]=e[xr],this[Fn]=e[Fn],this[In]=e[In],this[Xt]=e[Xt],this[zn]=e[zn],this[ke]=e[ke],this[pi]=e[pi],this[Nr]=e[Nr]}};var ts=class t extends xi{static*[or](e,r,n){let i=yield*Mi[pe](e,r,n);if(i){let a=Ge.get(i)[Nt],o=Ge.get(i)[B],s=o+a,c=(yield*e[ce](s,0))[Q](0,s),l=c[Q](o,s);return new t(i,l,c)}else return null}constructor(e,r,n){super(e,r),lt.get(this)[B]=n[B],this[pt]=[],this[Xu]=n,this[xr]=e[xr],this[Ao]=e[pi],this[Ur]=0,this[Fn]=e[Fn],this[In]=e[In],this[Xt]=e[Xt],this[ke]=e[ke],this[ae]=0,this[Nr]=e[Nr]}};var ha=class extends Kt{constructor(e,r,n){super(r,e,n)}};var im={0:bo.slice(0,2),1:bo},lr="SILK-only",ct="CELT-only",Wl="Hybrid",Xn="narrowband",Xl="medium-band",$n="wideband",ma="super-wideband",pa="fullband",S1={0:{[Y]:lr,[q]:Xn,[$]:10},8:{[Y]:lr,[q]:Xn,[$]:20},16:{[Y]:lr,[q]:Xn,[$]:40},24:{[Y]:lr,[q]:Xn,[$]:60},32:{[Y]:lr,[q]:Xl,[$]:10},40:{[Y]:lr,[q]:Xl,[$]:20},48:{[Y]:lr,[q]:Xl,[$]:40},56:{[Y]:lr,[q]:Xl,[$]:60},64:{[Y]:lr,[q]:$n,[$]:10},72:{[Y]:lr,[q]:$n,[$]:20},80:{[Y]:lr,[q]:$n,[$]:40},88:{[Y]:lr,[q]:$n,[$]:60},96:{[Y]:Wl,[q]:ma,[$]:10},104:{[Y]:Wl,[q]:ma,[$]:20},112:{[Y]:Wl,[q]:pa,[$]:10},120:{[Y]:Wl,[q]:pa,[$]:20},128:{[Y]:ct,[q]:Xn,[$]:2.5},136:{[Y]:ct,[q]:Xn,[$]:5},144:{[Y]:ct,[q]:Xn,[$]:10},152:{[Y]:ct,[q]:Xn,[$]:20},160:{[Y]:ct,[q]:$n,[$]:2.5},168:{[Y]:ct,[q]:$n,[$]:5},176:{[Y]:ct,[q]:$n,[$]:10},184:{[Y]:ct,[q]:$n,[$]:20},192:{[Y]:ct,[q]:ma,[$]:2.5},200:{[Y]:ct,[q]:ma,[$]:5},208:{[Y]:ct,[q]:ma,[$]:10},216:{[Y]:ct,[q]:ma,[$]:20},224:{[Y]:ct,[q]:pa,[$]:2.5},232:{[Y]:ct,[q]:pa,[$]:5},240:{[Y]:ct,[q]:pa,[$]:10},248:{[Y]:ct,[q]:pa,[$]:20}},ga=class t extends Yt{static[sr](e,r,n){let i={};if(i[H]=e[9],i[an]=e[18],i[B]=i[an]!==0?21+i[H]:19,e[B]<i[B])throw new Error("Out of data while inside an Ogg Page");let a=r[0]&3,o=a===3?2:1,s=$t(e[Q](0,i[B]))+$t(r[Q](0,o)),c=n[pe](s);if(c)return new t(c);if(s.substr(0,8)!=="OpusHead"||e[8]!==1)return null;i[ye]=yt.from(e[Q](0,i[B]));let l=new Vn(i[ye][kr]);if(i[ht]=16,i[hi]=l.getUint16(10,!0),i[No]=l.getUint32(12,!0),i[ie]=Bn,i[Co]=l.getInt16(16,!0),i[an]in im&&(i[gt]=im[i[an]][i[H]-1],!i[gt]))return null;i[an]!==0&&(i[Vo]=e[19],i[wo]=e[20],i[ko]=[...e[Q](21,i[H]+21)]);let u=S1[248&r[0]];switch(i[Y]=u[Y],i[q]=u[q],i[$]=u[$],a){case 0:i[sn]=1;break;case 1:case 2:i[sn]=2;break;case 3:i[Po]=!!(128&r[1]),i[Eo]=!!(64&r[1]),i[sn]=63&r[1];break;default:return null}{let{length:d,data:f,channelMappingFamily:m,...p}=i;n[ar](s,i,p)}return new t(i)}constructor(e){super(e),this[ye]=e[ye],this[q]=e[q],this[an]=e[an],this[ko]=e[ko],this[wo]=e[wo],this[sn]=e[sn],this[$]=e[$],this[Eo]=e[Eo],this[No]=e[No],this[Po]=e[Po],this[Y]=e[Y],this[Co]=e[Co],this[hi]=e[hi],this[Vo]=e[Vo]}};var rs=class extends xt{constructor(e,r,n){super(e,r),this.Frame=ha,this.Header=ga,n(this[be]),this._identificationHeader=null,this._preSkipRemaining=null}get[be](){return"opus"}[Gn](e){return e[ke]===0?(this._headerCache[Sr](),this._identificationHeader=e[ye]):e[ke]===1||(e[pt]=lt.get(e)[nr].map(r=>{let n=ga[sr](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[hi]);let i=n[$]*n[sn]/1e3*n[ie];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new ha(r,n,i)}this._codecParser[Cl]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var ya=class extends Kt{constructor(e,r,n){super(r,e,n)}};var id={};for(let t=0;t<8;t++)id[t+6]=2**(6+t);var ns=class t extends Yt{static[sr](e,r,n,i){if(e[B]<30)throw new Error("Out of data while inside an Ogg Page");let a=$t(e[Q](0,30)),o=r[pe](a);if(o)return new t(o);let s={[B]:30};if(a.substr(0,7)!=="vorbis")return null;s[ye]=yt.from(e[Q](0,30));let c=new Vn(s[ye][kr]);if(s[Dn]=c.getUint32(7,!0),s[Dn]!==0||(s[H]=e[11],s[gt]=bo[s[H]-1]||"application defined",s[ie]=c.getUint32(12,!0),s[xo]=c.getInt32(16,!0),s[_o]=c.getInt32(20,!0),s[vo]=c.getInt32(24,!0),s[Un]=id[(e[28]&240)>>4],s[kn]=id[e[28]&15],s[kn]>s[Un])||e[29]!==1)return null;s[ht]=32,s[ua]=i,s[Fo]=n;{let{length:l,data:u,version:d,vorbisSetup:f,vorbisComments:m,...p}=s;r[ar](a,s,p)}return new t(s)}constructor(e){super(e),this[xo]=e[xo],this[vo]=e[vo],this[_o]=e[_o],this[kn]=e[kn],this[Un]=e[Un],this[ye]=e[ye],this[Fo]=e[Fo],this[ua]=e[ua]}};var is=class extends xt{constructor(e,r,n){super(e,r),this.Frame=ya,n(this[be]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[be](){return mi}[Gn](e){e[pt]=[];for(let r of lt.get(e)[nr])if(r[0]===1)this._headerCache[Sr](),this._identificationHeader=e[ye],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=ns[sr](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[pt].push(new ya(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[Un]:r[kn],a=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,a}_parseSetupHeader(e){let r=new Dl(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){$o(r.read(8));let a=0;for(;r.read(8)===0&&a++<3;);if(a===4)i=r.read(7),n.blockFlags.unshift(i&1),r.position+=6,n.count++;else{(($o(i)&126)>>1)+1!==n.count&&this._codecParser[vr]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var ad=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new yt,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[be](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[_r](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=$t(e[Q](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",rs),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",wi),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(mi,is),!0;default:return!1}}_checkPageSequenceNumber(e){e[ke]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[ke]>1&&this._codecParser[vr]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[ke]}`),this._pageSequenceNumber=e[ke]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[ke],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=lt.get(e),n=Ge.get(r[Wt]),i=0;if(r[nr]=n[zn].map(a=>e[ye][Q](i,i+=a)),this._continuedPacket[B]&&(r[nr][0]=Ko(this._continuedPacket,r[nr][0]),this._continuedPacket=new yt),n[da][n[da][B]-1]===255&&(this._continuedPacket=Ko(this._continuedPacket,r[nr].pop())),this._previousAbsoluteGranulePosition!==null&&(e[ae]=Number(e[xr]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[xr],this._isSupported){let a=this._parser[Gn](e);return this._codecParser[On](a),a}else return e}},as=class extends xt{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=ts,this.Header=Mi,this._streams=new Map,this._currentSerialNumber=null}get[be](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Gr](){let e=yield*this[Nn](!0);this._currentSerialNumber=e[Nr];let r=this._streams.get(this._currentSerialNumber);return r||(r=new ad(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Xt]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var od=()=>{},os=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:a=!1,enableFrameCRC32:o=!0}={}){this._inputMimeType=e,this._onCodec=r||od,this._onCodecHeader=n||od,this._onCodecUpdate=i,this._enableLogging=a,this._crc32=o?Yh:od,this[_r]()}get[be](){return this._parser?this._parser[be]:""}[_r](){this._headerCache=new Yo(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[_r]()}*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 es(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Qo(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new wi(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new as(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[Gr]();e&&(yield e)}}*[ce](e=0,r=0){let n;for(;this._rawData[B]<=e+r;){if(n=yield,this._flushing)return this._rawData[Q](r);n&&(this._totalBytesIn+=n[B],this._rawData=Ko(this._rawData,n))}return this._rawData[Q](r)}[ir](e){this._currentReadPosition+=e,this._rawData=this._rawData[Q](e)}[Wo](e){this._sampleRate=e[Wt][ie],e[Wt][mt]=e[Ur]>0?Math.round(e[ye][B]/e[Ur])*8:0,e[ln]=this._frameNumber++,e[gi]=this._totalBytesOut,e[bi]=this._totalSamples,e[yi]=this._totalSamples/this._sampleRate*1e3,e[Ao]=this._crc32(e[ye]),this._headerCache[Bl](e[Wt][mt],e[yi]),this._totalBytesOut+=e[ye][B],this._totalSamples+=e[ae]}[On](e){if(e[pt]){if(e[Xt]){let r=e[ae];e[pt].forEach(n=>{let i=n[ae];r<i&&(n[ae]=r>0?r:0,n[Ur]=n[ae]/n[Wt][ie]*1e3),r-=i,this[Wo](n)})}else e[ae]=0,e[pt].forEach(r=>{e[ae]+=r[ae],this[Wo](r)});e[Ur]=e[ae]/this._sampleRate*1e3||0,e[bi]=this._totalSamples,e[yi]=this._totalSamples/this._sampleRate*1e3||0,e[gi]=this._totalBytesOut}else this[Wo](e)}_log(e,r){if(this._enableLogging){let n=[`${be}: ${this[be]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${gi}: ${this._totalBytesOut}`],i=Math.max(...n.map(a=>a[B]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((a,o)=>a+`
|
|
4
|
-
`+o,""))}}[vr](...e){this._log(console.warn,e)}[Cl](...e){this._log(console.error,e)}};var am=os;var $l=pt;var Kl=ye;var om=Wt;var sm=Xt;var lm=ua;var cm=bi;function cn(t){var e=e;function r(){}e={};function n(z){throw z}var i,a,o,s,c,l,u,d,
|
|
3
|
+
`,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(b)}}return y};function Se(){let t=Uint8Array,e=Float32Array;Se.modules||Object.defineProperties(Se,{modules:{value:new WeakMap},setModule:{value(r,n){Se.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let i=Se.modules.get(r);return i||(n?i=WebAssembly.compile(Wu(n)):(n=r.wasm,i=Se.inflateDynEncodeString(n).then(a=>WebAssembly.compile(a))),Se.modules.set(r,i)),i}},concatFloat32:{value(r,n){let i=new e(n),a=0,o=0;for(;a<r.length;)i.set(r[a],o),o+=r[a++].length;return i}},getDecodedAudio:{value:(r,n,i,a,o)=>({errors:r,channelData:n,samplesDecoded:i,sampleRate:a,bitDepth:o})},getDecodedAudioMultiChannel:{value(r,n,i,a,o,s){let c=[],l,u;for(l=0;l<i;l++){let d=[];for(u=0;u<n.length;)d.push(n[u++][l]||[]);c.push(Se.concatFloat32(d,a))}return Se.getDecodedAudio(r,c,a,o,s)}},inflateDynEncodeString:{value(r){return r=Wu(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 `;Se.getModule(Se,i).then(a=>WebAssembly.instantiate(a,{})).then(({exports:a})=>{let o=new Map(Object.entries(a)),s=o.get("puff"),c=o.get("memory").buffer,l=new t(c),u=new DataView(c),d=o.get("__heap_base"),h=r.length,m=d;d+=4,u.setInt32(m,h,!0);let p=d;d+=h,l.set(r,p);let y=d;d+=4,u.setInt32(y,l.byteLength-d,!0),s(d,y,p,m),n(l.slice(d,d+u.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,i)=>{let a=[],o=0;for(;o<n;)a.push(r.slice(o*i,o++*i+i));return a},this.allocateTypedArray=(r,n,i=!0)=>{let a=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return i&&this._pointers.add(a),{ptr:a,len:r,buf:new n(this._wasm.HEAP,a,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 a=i[r];a!==0;a=i[++r])n.push(a);return String.fromCharCode.apply(null,n)},this.addError=(r,n,i,a,o,s)=>{r.push({message:n,frameLength:i,frameNumber:a,inputBytes:o,outputSamples:s})},this.instantiate=(r,n)=>(n&&Se.setModule(r,n),this._wasm=new r(Se).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Uh=xg(kh(),1);var e1=()=>globalThis.Worker||Uh.default,ta=class extends e1(){constructor(e,r,n,i){Se.modules||new Se;let a=Se.modules.get(n);if(!a){let o="text/javascript",s,c=`'use strict';(${((l,u,d)=>{let h,m,p=new Promise(y=>{m=y});self.onmessage=({data:{id:y,command:g,data:b}})=>{let _=p,x={id:y},v;g==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:u},EmscriptenWASM:{value:d},module:{value:b.module},isWebWorker:{value:!0}}),h=new l(b.options),m()):g==="free"?h.free():g==="ready"?_=_.then(()=>h.ready):g==="reset"?_=_.then(()=>h.reset()):(Object.assign(x,h[g](Array.isArray(b)?b.map(w=>new Uint8Array(w)):new Uint8Array(b))),v=x.channelData?x.channelData.map(w=>w.buffer):[]),_.then(()=>self.postMessage(x,v))}}).toString()})(${n}, ${Se}, ${i})`;try{s=typeof process.versions.node<"u"}catch{}a=s?`data:${o};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:o})),Se.modules.set(n,a)}super(a,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:o})=>{let{id:s,...c}=o;this._enqueuedOperations.get(s)(c),this._enqueuedOperations.delete(s)},new i(Se).getModule().then(o=>{this.postToDecoder("init",{module:o,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 xl=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var we=Symbol,zh=", ",X=(()=>{let t="front",e="side",r="rear",n="left",i="center",a="right";return["",t+" ",e+" ",r+" "].map(o=>[[n,a],[n,a,i],[n,i,a],[i,n,a],[i]].flatMap(s=>s.map(c=>o+c).join(zh)))})(),Dr="LFE",Rn="monophonic (mono)",Cn="stereo",yo="surround",Pe=(t,...e)=>`${[Rn,Cn,`linear ${yo}`,"quadraphonic",`5.0 ${yo}`,`5.1 ${yo}`,`6.1 ${yo}`,`7.1 ${yo}`][t-1]} (${e.join(zh)})`,bo=[Rn,Pe(2,X[0][0]),Pe(3,X[0][2]),Pe(4,X[1][0],X[3][0]),Pe(5,X[1][2],X[3][0]),Pe(6,X[1][2],X[3][0],Dr),Pe(7,X[1][2],X[2][0],X[3][4],Dr),Pe(8,X[1][2],X[2][0],X[3][0],Dr)],Oh=192e3,Nh=176400,vl=96e3,_l=88200,Gh=64e3,Bn=48e3,ra=44100,na=32e3,ia=24e3,aa=22050,oa=16e3,Sl=12e3,wl=11025,sa=8e3,Vh=7350,xr="absoluteGranulePosition",q="bandwidth",ht="bitDepth",mt="bitrate",xo=mt+"Maximum",vo=mt+"Minimum",_o=mt+"Nominal",kr="buffer",So=kr+"Fullness",be="codec",pt=be+"Frames",wo="coupledStreamCount",la="crc",Mo=la+"16",Ao=la+"32",ye="data",W="description",Ur="duration",ca="emphasis",Eo="hasOpusPadding",Wt="header",Fn="isContinuedPacket",To="isCopyrighted",In="isFirstPage",Lo="isHome",Xt="isLastPage",Qr="isOriginal",Jr="isPrivate",Po="isVbr",Ot="layer",B="length",Y="mode",en=Y+"Extension",Ml="mpeg",tn=Ml+"Version",Ro="numberAACFrames",Co="outputGain",hi="preSkip",Bo="profile",Al=we(),rn="protection",Xu="rawData",nr="segments",Q="subarray",Dn="version",mi="vorbis",Fo=mi+"Comments",ua=mi+"Setup",El="block",Io=El+"ingStrategy",Tl=we(),nn=El+"Size",kn=El+"size0",Un=El+"size1",Do=we(),Ll="channel",an=Ll+"MappingFamily",ko=Ll+"MappingTable",gt=Ll+"Mode",Uo=we(),H=Ll+"s",Hh="copyright",zo=Hh+"Id",Oo=Hh+"IdStart",on="frame",sn=on+"Count",Nt=on+"Length",Pl="Number",ln=on+Pl,zr=on+"Padding",$=on+"Size",Wh="Rate",No="inputSample"+Wh,$u="page",pi=$u+"Checksum",da=we(),zn=$u+"SegmentTable",ke=$u+"Sequence"+Pl,Ku="sample",Go=Ku+Pl,ie=Ku+Wh,Or=we(),ae=Ku+"s",Rl="stream",Vo=Rl+"Count",Ho=Rl+"Info",Nr=Rl+"Serial"+Pl,Yu=Rl+"StructureVersion",qu="total",gi=qu+"BytesOut",yi=qu+"Duration",bi=qu+"Samples",ce=we(),ir=we(),Wo=we(),On=we(),vr=we(),Cl=we(),Zu=we(),Nn=we(),pe=we(),ar=we(),or=we(),Gr=we(),Gn=we(),Bl=we(),_r=we(),Sr=we(),sr=we(),Fl=we(),yt=Uint8Array,Vn=DataView,ge="reserved",bt="bad",fa="free",Xo="none",Il="16bit CRC";var ju=(t,e,r)=>{for(let n=0;n<t[B];n++){let i=e(n);for(let a=8;a>0;a--)i=r(i);t[n]=i}return t},r1=ju(new yt(256),t=>t,t=>t&128?7^t<<1:t<<1),Re=[ju(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],Ce=[ju(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){Re.push(new Uint16Array(256)),Ce.push(new Uint32Array(256));for(let e=0;e<=255;e++)Re[t+1][e]=Re[0][Re[t][e]>>>8]^Re[t][e]<<8,Ce[t+1][e]=Ce[t][e]>>>8^Ce[0][Ce[t][e]&255]}var $h=t=>{let e=0,r=t[B];for(let n=0;n!==r;n++)e=r1[e^t[n]];return e},Kh=t=>{let e=t[B],r=e-16,n=0,i=0;for(;i<=r;)n^=t[i++]<<8|t[i++],n=Re[15][n>>8]^Re[14][n&255]^Re[13][t[i++]]^Re[12][t[i++]]^Re[11][t[i++]]^Re[10][t[i++]]^Re[9][t[i++]]^Re[8][t[i++]]^Re[7][t[i++]]^Re[6][t[i++]]^Re[5][t[i++]]^Re[4][t[i++]]^Re[3][t[i++]]^Re[2][t[i++]]^Re[1][t[i++]]^Re[0][t[i++]];for(;i!==e;)n=(n&255)<<8^Re[0][n>>8^t[i++]];return n},Yh=t=>{let e=t[B],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},Ko=(...t)=>{let e=new yt(t.reduce((r,n)=>r+n[B],0));return t.reduce((r,n)=>(e.set(n,r),r+n[B]),0),e},$t=t=>String.fromCharCode(...t),Xh=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],$o=t=>Xh[t&15]<<4|Xh[t>>4],Dl=class{constructor(e){this._data=e,this._pos=e[B]*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,($o(this._data[r-1])<<8)+$o(this._data[r])>>7-n&255}},qh=(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 Yo=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[_r]()}[Sr](){this._isEnabled=!0}[_r](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[Bl](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}}[pe](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[ar](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 Ge=new WeakMap,lt=new WeakMap;var xt=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[Zu](){let e;do{if(e=yield*this.Frame[or](this._codecParser,this._headerCache,0),e)return e;this._codecParser[ir](1)}while(!0)}*[Nn](e){let r=yield*this[Zu](),n=lt.get(r)[B];if(e||this._codecParser._flushing||(yield*this.Header[pe](this._codecParser,this._headerCache,n)))return this._headerCache[Sr](),this._codecParser[ir](n),this._codecParser[On](r),r;this._codecParser[vr](`Missing ${on} at ${n} bytes from current position.`,`Dropping current ${on} and trying again.`),this._headerCache[_r](),this._codecParser[ir](1)}};var xi=class{constructor(e,r){lt.set(this,{[Wt]:e}),this[ye]=r}};var Kt=class extends xi{static*[or](e,r,n,i,a){let o=yield*e[pe](n,i,a);if(o){let s=Ge.get(o)[Nt],c=Ge.get(o)[ae],l=(yield*n[ce](s,a))[Q](0,s);return new r(o,l,c)}else return null}constructor(e,r,n){super(e,r),this[Wt]=e,this[ae]=n,this[Ur]=n/e[ie]*1e3,this[ln]=null,this[gi]=null,this[bi]=null,this[yi]=null,lt.get(this)[B]=r[B]}};var Qu="unsynchronizationFlag",Ju="extendedHeaderFlag",ed="experimentalFlag",td="footerPresent",qo=class t{static*getID3v2Header(e,r,n){let a={},o=yield*e[ce](3,n);if(o[0]!==73||o[1]!==68||o[2]!==51||(o=yield*e[ce](10,n),a[Dn]=`id3v2.${o[3]}.${o[4]}`,o[5]&15)||(a[Qu]=!!(o[5]&128),a[Ju]=!!(o[5]&64),a[ed]=!!(o[5]&32),a[td]=!!(o[5]&16),o[6]&128||o[7]&128||o[8]&128||o[9]&128))return null;let s=o[6]<<21|o[7]<<14|o[8]<<7|o[9];return a[B]=10+s,new t(a)}constructor(e){this[Dn]=e[Dn],this[Qu]=e[Qu],this[Ju]=e[Ju],this[ed]=e[ed],this[td]=e[td],this[B]=e[B]}};var Yt=class{constructor(e){Ge.set(this,e),this[ht]=e[ht],this[mt]=null,this[H]=e[H],this[gt]=e[gt],this[ie]=e[ie]}};var em={0:[fa,fa,fa,fa,fa],16:[32,32,32,32,8],240:[bt,bt,bt,bt,bt]},kl=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)em[t<<4]=[t*32,kl(t,4,0),kl(t,4,-1),kl(t,8,4),kl(t,8,0)];var n1=0,i1=1,a1=2,o1=3,Zh=4,Ul="bands ",zl=" to 31",jh={0:Ul+4+zl,16:Ul+8+zl,32:Ul+12+zl,48:Ul+16+zl},vi="bitrateIndex",Zo="v2",Hl="v1",Ol="Intensity stereo ",Nl=", MS stereo ",Gl="on",Vl="off",s1={0:Ol+Vl+Nl+Vl,16:Ol+Gl+Nl+Vl,32:Ol+Vl+Nl+Gl,48:Ol+Gl+Nl+Gl},rd={0:{[W]:ge},2:{[W]:"Layer III",[zr]:1,[en]:s1,[Hl]:{[vi]:a1,[ae]:1152},[Zo]:{[vi]:Zh,[ae]:576}},4:{[W]:"Layer II",[zr]:1,[en]:jh,[ae]:1152,[Hl]:{[vi]:i1},[Zo]:{[vi]:Zh}},6:{[W]:"Layer I",[zr]:4,[en]:jh,[ae]:384,[Hl]:{[vi]:n1},[Zo]:{[vi]:o1}}},nd="MPEG Version ",Qh="ISO/IEC ",l1={0:{[W]:`${nd}2.5 (later extension of MPEG 2)`,[Ot]:Zo,[ie]:{0:wl,4:Sl,8:sa,12:ge}},8:{[W]:ge},16:{[W]:`${nd}2 (${Qh}13818-3)`,[Ot]:Zo,[ie]:{0:aa,4:ia,8:oa,12:ge}},24:{[W]:`${nd}1 (${Qh}11172-3)`,[Ot]:Hl,[ie]:{0:ra,4:Bn,8:na,12:ge}},length:B},c1={0:Il,1:Xo},u1={0:Xo,1:"50/15 ms",2:ge,3:"CCIT J.17"},Jh={0:{[H]:2,[W]:Cn},64:{[H]:2,[W]:"joint "+Cn},128:{[H]:2,[W]:"dual channel"},192:{[H]:1,[W]:Rn}},_i=class t extends Yt{static*[pe](e,r,n){let i={},a=yield*qo.getID3v2Header(e,r,n);a&&(yield*e[ce](a[B],n),e[ir](a[B]));let o=yield*e[ce](4,n),s=$t(o[Q](0,4)),c=r[pe](s);if(c)return new t(c);if(o[0]!==255||o[1]<224)return null;let l=l1[o[1]&24];if(l[W]===ge)return null;let u=o[1]&6;if(rd[u][W]===ge)return null;let d={...rd[u],...rd[u][l[Ot]]};if(i[tn]=l[W],i[Ot]=d[W],i[ae]=d[ae],i[rn]=c1[o[1]&1],i[B]=4,i[mt]=em[o[2]&240][d[vi]],i[mt]===bt||(i[ie]=l[ie][o[2]&12],i[ie]===ge)||(i[zr]=o[2]&2&&d[zr],i[Jr]=!!(o[2]&1),i[Nt]=Math.floor(125*i[mt]*i[ae]/i[ie]+i[zr]),!i[Nt]))return null;let h=o[3]&192;if(i[gt]=Jh[h][W],i[H]=Jh[h][H],i[en]=d[en][o[3]&48],i[To]=!!(o[3]&8),i[Qr]=!!(o[3]&4),i[ca]=u1[o[3]&3],i[ca]===ge)return null;i[ht]=16;{let{length:m,frameLength:p,samples:y,...g}=i;r[ar](s,i,g)}return new t(i)}constructor(e){super(e),this[mt]=e[mt],this[ca]=e[ca],this[zr]=e[zr],this[To]=e[To],this[Qr]=e[Qr],this[Jr]=e[Jr],this[Ot]=e[Ot],this[en]=e[en],this[tn]=e[tn],this[rn]=e[rn]}};var jo=class t extends Kt{static*[or](e,r,n){return yield*super[or](_i,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Qo=class extends xt{constructor(e,r,n){super(e,r),this.Frame=jo,this.Header=_i,n(this[be])}get[be](){return Ml}*[Gr](){return yield*this[Nn]()}};var d1={0:"MPEG-4",8:"MPEG-2"},f1={0:"valid",2:bt,4:bt,6:bt},h1={0:Il,1:Xo},m1={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},p1={0:vl,4:_l,8:Gh,12:Bn,16:ra,20:na,24:ia,28:aa,32:oa,36:Sl,40:wl,44:sa,48:Vh,52:ge,56:ge,60:"frequency is written explicitly"},tm={0:{[H]:0,[W]:"Defined in AOT Specific Config"},64:{[H]:1,[W]:Rn},128:{[H]:2,[W]:Pe(2,X[0][0])},192:{[H]:3,[W]:Pe(3,X[1][3])},256:{[H]:4,[W]:Pe(4,X[1][3],X[3][4])},320:{[H]:5,[W]:Pe(5,X[1][3],X[3][0])},384:{[H]:6,[W]:Pe(6,X[1][3],X[3][0],Dr)},448:{[H]:8,[W]:Pe(8,X[1][3],X[2][0],X[3][0],Dr)}},Si=class t extends Yt{static*[pe](e,r,n){let i={},a=yield*e[ce](7,n),o=$t([a[0],a[1],a[2],a[3]&252|a[6]&3]),s=r[pe](o);if(s)Object.assign(i,s);else{if(a[0]!==255||a[1]<240||(i[tn]=d1[a[1]&8],i[Ot]=f1[a[1]&6],i[Ot]===bt))return null;let l=a[1]&1;i[rn]=h1[l],i[B]=l?7:9,i[Al]=a[2]&192,i[Or]=a[2]&60;let u=a[2]&2;if(i[Bo]=m1[i[Al]],i[ie]=p1[i[Or]],i[ie]===ge)return null;i[Jr]=!!u,i[Uo]=(a[2]<<8|a[3])&448,i[gt]=tm[i[Uo]][W],i[H]=tm[i[Uo]][H],i[Qr]=!!(a[3]&32),i[Lo]=!!(a[3]&8),i[zo]=!!(a[3]&8),i[Oo]=!!(a[3]&4),i[ht]=16,i[ae]=1024,i[Ro]=a[6]&3;{let{length:d,channelModeBits:h,profileBits:m,sampleRateBits:p,frameLength:y,samples:g,numberAACFrames:b,..._}=i;r[ar](o,i,_)}}if(i[Nt]=(a[3]<<11|a[4]<<3|a[5]>>5)&8191,!i[Nt])return null;let c=(a[5]<<6|a[6]>>2)&2047;return i[So]=c===2047?"VBR":c,new t(i)}constructor(e){super(e),this[zo]=e[zo],this[Oo]=e[Oo],this[So]=e[So],this[Lo]=e[Lo],this[Qr]=e[Qr],this[Jr]=e[Jr],this[Ot]=e[Ot],this[B]=e[B],this[tn]=e[tn],this[Ro]=e[Ro],this[Bo]=e[Bo],this[rn]=e[rn]}get audioSpecificConfig(){let e=Ge.get(this),r=e[Al]+64<<5|e[Or]<<5|e[Uo]>>3,n=new yt(2);return new Vn(n[kr]).setUint16(0,r,!1),n}};var Jo=class t extends Kt{static*[or](e,r,n){return yield*super[or](Si,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var es=class extends xt{constructor(e,r,n){super(e,r),this.Frame=Jo,this.Header=Si,n(this[be])}get[be](){return"aac"}*[Gr](){return yield*this[Nn]()}};var Hn=class t extends Kt{static _getFrameFooterCrc16(e){return(e[e[B]-2]<<8)+e[e[B]-1]}static[Fl](e){let r=t._getFrameFooterCrc16(e),n=Kh(e[Q](0,-2));return r===n}constructor(e,r,n){r[Ho]=n,r[Mo]=t._getFrameFooterCrc16(e),super(r,e,Ge.get(r)[ae])}};var rm="get from STREAMINFO metadata block",g1={0:"Fixed",1:"Variable"},nm={0:ge,16:192};for(let t=2;t<16;t++)nm[t<<4]=t<6?576*2**(t-2):2**t;var y1={0:rm,1:_l,2:Nh,3:Oh,4:sa,5:oa,6:aa,7:ia,8:na,9:ra,10:Bn,11:vl,15:bt},b1={0:{[H]:1,[W]:Rn},16:{[H]:2,[W]:Pe(2,X[0][0])},32:{[H]:3,[W]:Pe(3,X[0][1])},48:{[H]:4,[W]:Pe(4,X[1][0],X[3][0])},64:{[H]:5,[W]:Pe(5,X[1][1],X[3][0])},80:{[H]:6,[W]:Pe(6,X[1][1],Dr,X[3][0])},96:{[H]:7,[W]:Pe(7,X[1][1],Dr,X[3][4],X[2][0])},112:{[H]:8,[W]:Pe(8,X[1][1],Dr,X[3][0],X[2][0])},128:{[H]:2,[W]:`${Cn} (left, diff)`},144:{[H]:2,[W]:`${Cn} (diff, right)`},160:{[H]:2,[W]:`${Cn} (avg, diff)`},176:ge,192:ge,208:ge,224:ge,240:ge},x1={0:rm,2:8,4:12,6:ge,8:16,10:20,12:24,14:ge},Wn=class t extends Yt{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let o=64;o&e[0];o>>=1)r++;let n=r-1,i=0,a=0;for(;n>0;a+=6,n--){if((e[n]&192)!==128)return null;i|=(e[n]&63)<<a}return i|=(e[n]&127>>r)<<a,{value:i,length:r}}static[sr](e,r){let n={[ce]:function*(){return e}};return t[pe](n,r,0).next().value}static*[pe](e,r,n){let i=yield*e[ce](6,n);if(i[0]!==255||!(i[1]===248||i[1]===249))return null;let a={},o=$t(i[Q](0,4)),s=r[pe](o);if(s)Object.assign(a,s);else{if(a[Tl]=i[1]&1,a[Io]=g1[a[Tl]],a[Do]=i[2]&240,a[Or]=i[2]&15,a[nn]=nm[a[Do]],a[nn]===ge||(a[ie]=y1[a[Or]],a[ie]===bt)||i[3]&1)return null;let l=b1[i[3]&240];if(l===ge||(a[H]=l[H],a[gt]=l[W],a[ht]=x1[i[3]&14],a[ht]===ge))return null}a[B]=5,i=yield*e[ce](a[B]+8,n);let c=t._decodeUTF8Int(i[Q](4));if(!c||(a[Tl]?a[Go]=c.value:a[ln]=c.value,a[B]+=c[B],a[Do]===96?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[nn]=i[a[B]-1]+1,a[B]+=1):a[Do]===112&&(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[nn]=(i[a[B]-1]<<8)+i[a[B]]+1,a[B]+=2),a[ae]=a[nn],a[Or]===12?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=i[a[B]-1]*1e3,a[B]+=1):a[Or]===13?(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=(i[a[B]-1]<<8)+i[a[B]],a[B]+=2):a[Or]===14&&(i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[ie]=((i[a[B]-1]<<8)+i[a[B]])*10,a[B]+=2),i[B]<a[B]&&(i=yield*e[ce](a[B],n)),a[la]=i[a[B]-1],a[la]!==$h(i[Q](0,a[B]-1))))return null;if(!s){let{blockingStrategyBits:l,frameNumber:u,sampleNumber:d,samples:h,sampleRateBits:m,blockSizeBits:p,crc:y,length:g,...b}=a;r[ar](o,a,b)}return new t(a)}constructor(e){super(e),this[Mo]=null,this[Io]=e[Io],this[nn]=e[nn],this[ln]=e[ln],this[Go]=e[Go],this[Ho]=null}};var v1=2,_1=512*1024,wi=class extends xt{constructor(e,r,n){super(e,r),this.Frame=Hn,this.Header=Wn,n(this[be])}get[be](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[ce](2,0),n=r[B]-2;for(;e<n;){if(r[e]===255){let a=r[e+1];if(a===248||a===249)break;a!==255&&e++}e++}return e}*[Gr](){do{let e=yield*Wn[pe](this._codecParser,this._headerCache,0);if(e){let r=Ge.get(e)[B]+v1;for(;r<=_1;){if(this._codecParser._flushing||(yield*Wn[pe](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[ce](r);if(this._codecParser._flushing||(n=n[Q](0,r)),Hn[Fl](n)){let i=new Hn(n,e);return this._headerCache[Sr](),this._codecParser[ir](r),this._codecParser[On](i),i}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[vr](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[ir](r)}else this._codecParser[ir](yield*this._getNextFrameSyncOffset(1))}while(!0)}[Gn](e){return e[ke]===0?(this._headerCache[Sr](),this._streamInfo=e[ye][Q](13)):e[ke]===1||(e[pt]=lt.get(e)[nr].map(r=>{let n=Wn[sr](r,this._headerCache);if(n)return new Hn(r,n,this._streamInfo);this._codecParser[vr]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var Mi=class t{static*[pe](e,r,n){let i={},a=yield*e[ce](28,n);if(a[0]!==79||a[1]!==103||a[2]!==103||a[3]!==83||(i[Yu]=a[4],a[5]&248))return null;i[Xt]=!!(a[5]&4),i[In]=!!(a[5]&2),i[Fn]=!!(a[5]&1);let s=new Vn(yt.from(a[Q](0,28))[kr]);i[xr]=qh(s,6),i[Nr]=s.getInt32(14,!0),i[ke]=s.getInt32(18,!0),i[pi]=s.getInt32(22,!0);let c=a[26];i[B]=c+27,a=yield*e[ce](i[B],n),i[Nt]=0,i[zn]=[],i[da]=yt.from(a[Q](27,i[B]));for(let l=0,u=0;l<c;l++){let d=i[da][l];i[Nt]+=d,u+=d,(d!==255||l===c-1)&&(i[zn].push(u),u=0)}return new t(i)}constructor(e){Ge.set(this,e),this[xr]=e[xr],this[Fn]=e[Fn],this[In]=e[In],this[Xt]=e[Xt],this[zn]=e[zn],this[ke]=e[ke],this[pi]=e[pi],this[Nr]=e[Nr]}};var ts=class t extends xi{static*[or](e,r,n){let i=yield*Mi[pe](e,r,n);if(i){let a=Ge.get(i)[Nt],o=Ge.get(i)[B],s=o+a,c=(yield*e[ce](s,0))[Q](0,s),l=c[Q](o,s);return new t(i,l,c)}else return null}constructor(e,r,n){super(e,r),lt.get(this)[B]=n[B],this[pt]=[],this[Xu]=n,this[xr]=e[xr],this[Ao]=e[pi],this[Ur]=0,this[Fn]=e[Fn],this[In]=e[In],this[Xt]=e[Xt],this[ke]=e[ke],this[ae]=0,this[Nr]=e[Nr]}};var ha=class extends Kt{constructor(e,r,n){super(r,e,n)}};var im={0:bo.slice(0,2),1:bo},lr="SILK-only",ct="CELT-only",Wl="Hybrid",Xn="narrowband",Xl="medium-band",$n="wideband",ma="super-wideband",pa="fullband",S1={0:{[Y]:lr,[q]:Xn,[$]:10},8:{[Y]:lr,[q]:Xn,[$]:20},16:{[Y]:lr,[q]:Xn,[$]:40},24:{[Y]:lr,[q]:Xn,[$]:60},32:{[Y]:lr,[q]:Xl,[$]:10},40:{[Y]:lr,[q]:Xl,[$]:20},48:{[Y]:lr,[q]:Xl,[$]:40},56:{[Y]:lr,[q]:Xl,[$]:60},64:{[Y]:lr,[q]:$n,[$]:10},72:{[Y]:lr,[q]:$n,[$]:20},80:{[Y]:lr,[q]:$n,[$]:40},88:{[Y]:lr,[q]:$n,[$]:60},96:{[Y]:Wl,[q]:ma,[$]:10},104:{[Y]:Wl,[q]:ma,[$]:20},112:{[Y]:Wl,[q]:pa,[$]:10},120:{[Y]:Wl,[q]:pa,[$]:20},128:{[Y]:ct,[q]:Xn,[$]:2.5},136:{[Y]:ct,[q]:Xn,[$]:5},144:{[Y]:ct,[q]:Xn,[$]:10},152:{[Y]:ct,[q]:Xn,[$]:20},160:{[Y]:ct,[q]:$n,[$]:2.5},168:{[Y]:ct,[q]:$n,[$]:5},176:{[Y]:ct,[q]:$n,[$]:10},184:{[Y]:ct,[q]:$n,[$]:20},192:{[Y]:ct,[q]:ma,[$]:2.5},200:{[Y]:ct,[q]:ma,[$]:5},208:{[Y]:ct,[q]:ma,[$]:10},216:{[Y]:ct,[q]:ma,[$]:20},224:{[Y]:ct,[q]:pa,[$]:2.5},232:{[Y]:ct,[q]:pa,[$]:5},240:{[Y]:ct,[q]:pa,[$]:10},248:{[Y]:ct,[q]:pa,[$]:20}},ga=class t extends Yt{static[sr](e,r,n){let i={};if(i[H]=e[9],i[an]=e[18],i[B]=i[an]!==0?21+i[H]:19,e[B]<i[B])throw new Error("Out of data while inside an Ogg Page");let a=r[0]&3,o=a===3?2:1,s=$t(e[Q](0,i[B]))+$t(r[Q](0,o)),c=n[pe](s);if(c)return new t(c);if(s.substr(0,8)!=="OpusHead"||e[8]!==1)return null;i[ye]=yt.from(e[Q](0,i[B]));let l=new Vn(i[ye][kr]);if(i[ht]=16,i[hi]=l.getUint16(10,!0),i[No]=l.getUint32(12,!0),i[ie]=Bn,i[Co]=l.getInt16(16,!0),i[an]in im&&(i[gt]=im[i[an]][i[H]-1],!i[gt]))return null;i[an]!==0&&(i[Vo]=e[19],i[wo]=e[20],i[ko]=[...e[Q](21,i[H]+21)]);let u=S1[248&r[0]];switch(i[Y]=u[Y],i[q]=u[q],i[$]=u[$],a){case 0:i[sn]=1;break;case 1:case 2:i[sn]=2;break;case 3:i[Po]=!!(128&r[1]),i[Eo]=!!(64&r[1]),i[sn]=63&r[1];break;default:return null}{let{length:d,data:h,channelMappingFamily:m,...p}=i;n[ar](s,i,p)}return new t(i)}constructor(e){super(e),this[ye]=e[ye],this[q]=e[q],this[an]=e[an],this[ko]=e[ko],this[wo]=e[wo],this[sn]=e[sn],this[$]=e[$],this[Eo]=e[Eo],this[No]=e[No],this[Po]=e[Po],this[Y]=e[Y],this[Co]=e[Co],this[hi]=e[hi],this[Vo]=e[Vo]}};var rs=class extends xt{constructor(e,r,n){super(e,r),this.Frame=ha,this.Header=ga,n(this[be]),this._identificationHeader=null,this._preSkipRemaining=null}get[be](){return"opus"}[Gn](e){return e[ke]===0?(this._headerCache[Sr](),this._identificationHeader=e[ye]):e[ke]===1||(e[pt]=lt.get(e)[nr].map(r=>{let n=ga[sr](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[hi]);let i=n[$]*n[sn]/1e3*n[ie];return this._preSkipRemaining>0&&(this._preSkipRemaining-=i,i=this._preSkipRemaining<0?-this._preSkipRemaining:0),new ha(r,n,i)}this._codecParser[Cl]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var ya=class extends Kt{constructor(e,r,n){super(r,e,n)}};var id={};for(let t=0;t<8;t++)id[t+6]=2**(6+t);var ns=class t extends Yt{static[sr](e,r,n,i){if(e[B]<30)throw new Error("Out of data while inside an Ogg Page");let a=$t(e[Q](0,30)),o=r[pe](a);if(o)return new t(o);let s={[B]:30};if(a.substr(0,7)!=="vorbis")return null;s[ye]=yt.from(e[Q](0,30));let c=new Vn(s[ye][kr]);if(s[Dn]=c.getUint32(7,!0),s[Dn]!==0||(s[H]=e[11],s[gt]=bo[s[H]-1]||"application defined",s[ie]=c.getUint32(12,!0),s[xo]=c.getInt32(16,!0),s[_o]=c.getInt32(20,!0),s[vo]=c.getInt32(24,!0),s[Un]=id[(e[28]&240)>>4],s[kn]=id[e[28]&15],s[kn]>s[Un])||e[29]!==1)return null;s[ht]=32,s[ua]=i,s[Fo]=n;{let{length:l,data:u,version:d,vorbisSetup:h,vorbisComments:m,...p}=s;r[ar](a,s,p)}return new t(s)}constructor(e){super(e),this[xo]=e[xo],this[vo]=e[vo],this[_o]=e[_o],this[kn]=e[kn],this[Un]=e[Un],this[ye]=e[ye],this[Fo]=e[Fo],this[ua]=e[ua]}};var is=class extends xt{constructor(e,r,n){super(e,r),this.Frame=ya,n(this[be]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[be](){return mi}[Gn](e){e[pt]=[];for(let r of lt.get(e)[nr])if(r[0]===1)this._headerCache[Sr](),this._identificationHeader=e[ye],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=ns[sr](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[pt].push(new ya(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[Un]:r[kn],a=this._prevBlockSize===null?0:(this._prevBlockSize+i)/4;return this._prevBlockSize=i,a}_parseSetupHeader(e){let r=new Dl(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let i;for(;n.count<64&&r.position>0;){$o(r.read(8));let a=0;for(;r.read(8)===0&&a++<3;);if(a===4)i=r.read(7),n.blockFlags.unshift(i&1),r.position+=6,n.count++;else{(($o(i)&126)>>1)+1!==n.count&&this._codecParser[vr]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var ad=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new yt,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[be](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[_r](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=$t(e[Q](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",rs),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",wi),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(mi,is),!0;default:return!1}}_checkPageSequenceNumber(e){e[ke]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[ke]>1&&this._codecParser[vr]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[ke]}`),this._pageSequenceNumber=e[ke]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[ke],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=lt.get(e),n=Ge.get(r[Wt]),i=0;if(r[nr]=n[zn].map(a=>e[ye][Q](i,i+=a)),this._continuedPacket[B]&&(r[nr][0]=Ko(this._continuedPacket,r[nr][0]),this._continuedPacket=new yt),n[da][n[da][B]-1]===255&&(this._continuedPacket=Ko(this._continuedPacket,r[nr].pop())),this._previousAbsoluteGranulePosition!==null&&(e[ae]=Number(e[xr]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[xr],this._isSupported){let a=this._parser[Gn](e);return this._codecParser[On](a),a}else return e}},as=class extends xt{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=ts,this.Header=Mi,this._streams=new Map,this._currentSerialNumber=null}get[be](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Gr](){let e=yield*this[Nn](!0);this._currentSerialNumber=e[Nr];let r=this._streams.get(this._currentSerialNumber);return r||(r=new ad(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Xt]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var od=()=>{},os=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:i,enableLogging:a=!1,enableFrameCRC32:o=!0}={}){this._inputMimeType=e,this._onCodec=r||od,this._onCodecHeader=n||od,this._onCodecUpdate=i,this._enableLogging=a,this._crc32=o?Yh:od,this[_r]()}get[be](){return this._parser?this._parser[be]:""}[_r](){this._headerCache=new Yo(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[_r]()}*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 es(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Qo(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new wi(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new as(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[Gr]();e&&(yield e)}}*[ce](e=0,r=0){let n;for(;this._rawData[B]<=e+r;){if(n=yield,this._flushing)return this._rawData[Q](r);n&&(this._totalBytesIn+=n[B],this._rawData=Ko(this._rawData,n))}return this._rawData[Q](r)}[ir](e){this._currentReadPosition+=e,this._rawData=this._rawData[Q](e)}[Wo](e){this._sampleRate=e[Wt][ie],e[Wt][mt]=e[Ur]>0?Math.round(e[ye][B]/e[Ur])*8:0,e[ln]=this._frameNumber++,e[gi]=this._totalBytesOut,e[bi]=this._totalSamples,e[yi]=this._totalSamples/this._sampleRate*1e3,e[Ao]=this._crc32(e[ye]),this._headerCache[Bl](e[Wt][mt],e[yi]),this._totalBytesOut+=e[ye][B],this._totalSamples+=e[ae]}[On](e){if(e[pt]){if(e[Xt]){let r=e[ae];e[pt].forEach(n=>{let i=n[ae];r<i&&(n[ae]=r>0?r:0,n[Ur]=n[ae]/n[Wt][ie]*1e3),r-=i,this[Wo](n)})}else e[ae]=0,e[pt].forEach(r=>{e[ae]+=r[ae],this[Wo](r)});e[Ur]=e[ae]/this._sampleRate*1e3||0,e[bi]=this._totalSamples,e[yi]=this._totalSamples/this._sampleRate*1e3||0,e[gi]=this._totalBytesOut}else this[Wo](e)}_log(e,r){if(this._enableLogging){let n=[`${be}: ${this[be]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${gi}: ${this._totalBytesOut}`],i=Math.max(...n.map(a=>a[B]));r.push(`--stats--${"-".repeat(i-9)}`,...n,"-".repeat(i)),e("codec-parser",r.reduce((a,o)=>a+`
|
|
4
|
+
`+o,""))}}[vr](...e){this._log(console.warn,e)}[Cl](...e){this._log(console.error,e)}};var am=os;var $l=pt;var Kl=ye;var om=Wt;var sm=Xt;var lm=ua;var cm=bi;function cn(t){var e=e;function r(){}e={};function n(z){throw z}var i,a,o,s,c,l,u,d,h,m,p;function y(){var z=p.buffer;i=new Int8Array(z),a=new Int16Array(z),s=new Uint8Array(z),c=new Uint16Array(z),o=new Int32Array(z),l=new Uint32Array(z),u=new Float32Array(z),d=new Float64Array(z),h=new BigInt64Array(z),m=new BigUint64Array(z)}for(var g=z=>{for(var de,ze,Ue=0,pr=0,Qt=z.length,gn=new Uint8Array((Qt*3>>2)-(z[Qt-2]=="=")-(z[Qt-1]=="="));Ue<Qt;Ue+=4,pr+=3)de=U[z.charCodeAt(Ue+1)],ze=U[z.charCodeAt(Ue+2)],gn[pr]=U[z.charCodeAt(Ue)]<<2|de>>4,gn[pr+1]=de<<4|ze>>2,gn[pr+2]=ze<<6|U[z.charCodeAt(Ue+3)];return gn},b=()=>n(""),_=()=>{},x={},v=z=>z(),w=()=>performance.now(),M=(z,de)=>{if(x[z]&&(clearTimeout(x[z].id),delete x[z]),!de)return 0;var ze=setTimeout(()=>{delete x[z],v(()=>mr(z,w()))},de);return x[z]={id:ze,timeout_ms:de},0},S=Math.atan,E=Math.cos,L=Math.exp,A=Math.log,R=Math.pow,D=Math.sin,k=z=>{var de=s.length;return z>>>=0,!1},F=z=>{throw`exit(${z})`},U=new Uint8Array(123),ee=25;ee>=0;--ee)U[48+ee]=52+ee,U[65+ee]=ee,U[97+ee]=26+ee;U[43]=62,U[47]=63;var He={e:b,d:_,f:M,b:S,a:E,i:L,h:A,g:R,c:D,k,j:F};function We(z){Ae=z.n,j=z.o,ue=z.p,ve=z.q,Ie=z.r,nt=z.s,jt=z.t,mr=z.v}var Ae,j,ue,ve,Ie,nt,jt,mr;function ft(z){z.m()}cn.wasm||Object.defineProperty(cn,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØäÂLÚªã9ÚØ[äº\ ¼¡³R=}L]Èÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹=
|
|
5
5
|
¨¨%ýv²±»oúâLa:ê±ÊäÌÓ.÷Øý×>àW>z¯°8¯ñ\Ñós9\§ôÊ@Ü (tÃø4° ¢7fqÓg²Jè6x[zç®&4=} p.(°tÍÞã¾>÷CõË"*k?¿~7~H2ÛÜâ.ÏQä;6{ÜãFÑá'DD¤±°HQ>MínÎÏÎöʵÑÓ
ÞÌP¼P¨Þ*X²E=M¦qíxMñ=MÌë4/<gNO/¢ ¢>a~Ï®ììììì0ìa笡çëOÓÇM Q9tùµyuéµµÞÏ/±Óõò}E{òÓJ¹Û|·ôfÒ c¬Wêaûÿlʽp¹|)ÖEL¦ }ypÕSϹI]¢ºãæ°ÿo¶7ÛRq¾ÔÅEߨ]æËwÚ{óçVwó1¾EØpàe"Æùû¡Áª Ààð´LõÎxEÓ¢N¦
9ëùi& Ò§Ø!ÇFçS=MbäO?߷縪7ùa}5ðûÕtsUþ£KïgN¾)ø§\V0uSIö:ÌU4ж¯´Õn9ÔèE£ZƼ{hµmÙ¾6ÆÑ+xñ´«þ¸=Mߤ·å®«ïÆGFÝì|H?äE"þ!9«Æïpæ'][¯ù·£W÷O§&#ax$qf=}ø ô bÏ×W÷LôoÝWQÕÓ)u÷½èV|¥Gà¨Ö¸@ê|ÇK5ò A·Â9CS2¸¼¿,äÝÑÝy!ÑR%ÆÝÎ0Âv§ qTcó±hØÉã=}Z=}Ælüën¯ð(-°ÜwVÏï.th¥íS~SÏ»ZZÔZ
|
|
6
6
|
3BÌÛ¬<éæO)ÎyÚ¯O*®uìÛ$öI¥Ý9ôø³\¤ò³Ù¹ÇP¸J×y@ÔyOÇmô½ü¾|S?2àú¤F?½ûoo3ô;<àáûÜ8ì²7ïë¨RäY¹|ÓºÌF,Ð-¸*\P!FJÒ8= o6HwLrúº¶ÐÛ\Ù¬o¢9IqÝ.ôf¶ÎÈ{Ī×N|Mfs
¤ÉÝàâ§*+ã§ô¯î¬7ç×§ä)!Z¨É,Äp~ý·wsSGóäsE\ýïé§Ö:Ò'Cç(_X$\¦½eÒ8$XF|eíÙÓ¡¤Û<ØÞÛ¸9¿ðÃÎ#b~× 4éîÿÏq
|
|
7
7
|
ód|0wU&®è·vh6¨{ÚçÚ18Ó(ÓY\0¦= çèíß)Ø=}[xü-v?N(Kkg0}âÚ´ð¬ÕQNÍ¢usѳ=}. ëg
û= ÍMBp'²¨ x4è@9t§eݵ¾âð½ z?Z¹FH'̯¿<K,üµ<{ ¶JãývåàÆeù0Ð"F¥ÃÒÞþÔÉvCzl}ðN£ Í^P%²¸FX»WÎêô¶
äÉJ^g×SÃã.Ät*'ªG«ÒB<ÜÓ
¿ºp\àuV¯£ÅݽáÞ ùß=}ÎÚ^ÿí>¥!¨ â=M·?*/¤"å)â·ÿîÿî*(%*2[½"üríÔ4l½»a}¯CwpCÓèìGc-ã6®=M32k?Êg
!So-x>³G+ã@ò, ÁïáåN0þÙè.~È÷¡vTr¶Ã[üB±º»ávëw¹{pܺû"Aæ±9Æ^¹³òïRIAy5GÂwÉf4@Tù|qý7ðªwBL|Ôqv!ª°|]KiÐJVQ5¸åõ§å"H¼0e¬<óBîÚSÏUìHPÙA+çÉ'seÌNf°@ÈM,ð½egÖ¬x©û½2~«Ò1;Ö«
¯°4&90èE»Ó׺çʧJ<Æ¿&~Nu¼ãÙµ¢.UÇä(qQô^ö·%!É
|
|
@@ -138,7 +138,7 @@ KÙ:KµºKí{K]ûK£[KÚKóKÓ½R׿ÿ'P^j9TîçmóþL¿_o©×hÙtÙ
|
|
|
138
138
|
Ái;ªäÀ%n= =M+W= ÓÖc[aS
|
|
139
139
|
FÁð]NôÝ'= qr(¶ù¤nü«òÿ¿d&ÿÈõT4Þ=}z|ö ¿OW×SMtdH.ÏãRX&§o3ØÜXÍ^ÊMí£W´iâ]NüOå£S£Å·ç÷ݧ½GÑUy¹¦ß§/6P0(Cúýb"þ¥°VÙÄá£ÓÙ@¾YýòD{òÃv?EP©=MBé\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±ÏÁÕ¯¦ðvZmT}3xËz×cºrÑM=Mc-É©Ô7½wæc§Î»cû¾yfÙWòÆÝÔc¥³ôØf«Äñ·9ø%g:y^+{U]¤þ
[&fÓÏYë«Gªõ¹¦Öðþ¬moÛø?/ÛS.[S9ÛùC
/û2²Y£ÎÑ%/sy¢×ÌùJW6Oí\g0^JùêßÏ0í[Ü'ÏÔ>À-¿[ÔW?Y]±ØÙÃî<~ÎëR~Ìf¾Z/×¼_á¾Þê+îoÐñ{Þ\e3K%©¹§íB¹§(c=}ËÈ·SzÔnf§èx}o\9öf|%Ýå¥~©IÇüñY8}Ffú@Rú1éþ3÷ËótQøvû|³Îaá,Óé>BG6Òê}ÃJ|¶=}°öf6õk¶ÌºHgNjÒ{æ¾M;9·é§WèO±Ä3ÒËÒyt ;ù´à©a|Ó^!ÝøûÂÄ
|
|
140
140
|
(VV¸ÇÙcÏ>yoçzÃvòG{3Þ£½c×ôíÅé;°OÛGØ<wÜW> rU]q{û'ùÝír{*øï?t-ígùWÿ
&§]m}×ût¥Ë~ß&>&Õv!b#ÅÌq¢µ|jÍüùÉ^Æ&ôþ~sIµ"]d)uâ´ºvk Å\<Íÿöê½Â
|
|
141
|
-
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var Xe={a:He};this.setModule=z=>{t.setModule(cn,z)},this.getModule=()=>t.getModule(cn),this.instantiate=()=>(this.getModule().then(z=>WebAssembly.instantiate(z,Xe)).then(z=>{let de=z.exports;We(de),p=de.l,y(),ft(de),r()}),this.ready=new Promise(z=>{r=z}).then(()=>{this.HEAP=p.buffer,this.malloc=j,this.free=jt,this.create_decoder=Ae,this.send_setup=ue,this.init_dsp=ve,this.decode_packets=Ie,this.destroy_decoder=nt}),this)}function Ai(){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 a=t[i];this._input.buf.set(a),this._inputLen.buf[0]=a.length,this._common.wasm.decode_packets(this._decoder);let o=this._samplesDecoded.buf[0],s=[],c=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let u=new Float32Array(o);o&&u.set(new Float32Array(this._common.wasm.HEAP,c[l],o)),s.push(u)}e.push(s),r+=o,this._frameNumber++,this._inputBytes+=a.length,this._outputSamples+=o;for(let l=0;l<this._errorsLength.buf;l+=2){let u=this._common.codeToString(this._errors.buf[l]),d=this._common.codeToString(this._errors.buf[l+1]);n.push({message:u+" vorbis_synthesis"+d,frameLength:a.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=Ai.isWebWorker,this._WASMAudioDecoderCommon=Ai.WASMAudioDecoderCommon||Se,this._EmscriptenWASM=Ai.EmscriptenWASM||cn,this._module=Ai.module,this._inputSize=128*1024,this._ready=this._init(),this}var Yl=Symbol(),un=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Se,this._init(),this._ready=this[Yl](Ai)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new am("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[Yl](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 a=0;a<e.length;a++){let o=e[a];if(this._vorbisSetupInProgress&&(o[Kl][0]===1&&this._decoder.sendSetupHeader(o[Kl]),o[$l].length)){let s=o[$l][0][om];this._decoder.sendSetupHeader(s[lm]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...o[$l].map(s=>s[Kl]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[sm]){let a=this._totalSamplesDecoded-i[cm];if(a>0){for(let o=0;o<n.channelData.length;o++)n.channelData[o]=n.channelData[o].subarray(0,n.samplesDecoded-a);n.samplesDecoded-=a,this._totalSamplesDecoded-=a}}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 sd=class extends ta{constructor(e){super(e,"ogg-vorbis-decoder",Ai,cn)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},ss=class extends un{constructor(){super(),this._ready=super[Yl](sd)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};xl(un,"OggVorbisDecoder");xl(ss,"OggVorbisDecoderWebWorker");var ld=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ql(t,e=new un){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new ld(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var ls=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},ba=class{constructor(e,r={}){this.vfs=e;h(this,"cache");h(this,"refCounts",new Map);h(this,"worker");h(this,"nextRequestId",0);this.cache=new Ln(r.cacheSize??64),r.workerPath&&(this.worker=new Worker(r.workerPath,{type:"module"}))}get size(){return this.cache.size}get capacity(){return this.cache.capacity}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 a=(await this.vfs.readFile(e)).slice().buffer,o=await this.decodeByExtension(e,a);return this.cache.set(r,o),this.refCounts.set(r,1),o}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()}set capacity(e){this.cache.capacity=e}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){if(this.worker)return this.decodeWavInWorker(r);let i=bl(r),a=i.channels,o=Array.from({length:a},()=>new Float32Array(i.samples.length/a));for(let s=0;s<i.samples.length;s+=1)o[s%a][Math.floor(s/a)]=i.samples[s];return{sampleRate:i.sampleRate,channels:a,bitDepth:i.bitsPerSample,channelData:o}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ql(r);throw new ls(`Unsupported audio format: ${e}`)}decodeWavInWorker(e){return new Promise((r,n)=>{if(!this.worker){n(new Error("Worker not initialized"));return}let i=this.nextRequestId++,a=o=>{if(o.data.id===i)if(this.worker.removeEventListener("message",a),o.data.type==="success"){let s=o.data.data,c=s.channels,l=Array.from({length:c},()=>new Float32Array(s.samples.length/c));for(let u=0;u<s.samples.length;u+=1)l[u%c][Math.floor(u/c)]=s.samples[u];r({sampleRate:s.sampleRate,channels:c,bitDepth:s.bitsPerSample,channelData:l})}else n(new Error(o.data.message))};this.worker.addEventListener("message",a),this.worker.postMessage({id:i,buffer:e,type:"wav"},[e])})}};var w1="quake2ts-pak-indexes",M1="pak-indexes";function um(){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 cs(t,e){let r=um();return r?new Promise((n,i)=>{let a=r.open(t,1);a.onupgradeneeded=()=>{let{result:o}=a;o.objectStoreNames.contains(e)||o.createObjectStore(e,{keyPath:"key"})},a.onerror=()=>i(a.error??new Error("Unknown IndexedDB error")),a.onsuccess=()=>n(a.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function us(t,e,r,n){return new Promise((i,a)=>{let s=t.transaction(e,r).objectStore(e),c=n(s);c.onsuccess=()=>i(c.result),c.onerror=()=>a(c.error??new Error("IndexedDB transaction error"))})}function cd(t,e){return`${Le(t)}:${e.toString(16)}`}function A1(t){return t.map(e=>({...e}))}var Zl=class{constructor(e=w1,r=M1){this.dbName=e;this.storeName=r}get isSupported(){return!!um()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:cd(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:A1(r.entries)},i=await cs(this.dbName,this.storeName);return await us(i,this.storeName,"readwrite",a=>a.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await cs(this.dbName,this.storeName),i=r!==void 0?cd(e,r):void 0,a=await us(n,this.storeName,"readonly",o=>i?o.get(i):o.getAll());if(n.close(),!!a){if(Array.isArray(a)){let o=Le(e),s=a.filter(c=>Le(c.name)===o);return s.length===0?void 0:s.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return a}}async remove(e,r){if(!this.isSupported)return!1;let n=await cs(this.dbName,this.storeName),i=r!==void 0?cd(e,r):void 0,a=await us(n,this.storeName,"readwrite",o=>{if(i)return o.delete(i);let s=`${Le(e)}:`;return o.delete(IDBKeyRange.bound(s,`${s}\uFFFF`,!1,!0))});return n.close(),typeof a=="number"?a>0:!0}async clear(){if(!this.isSupported)return;let e=await cs(this.dbName,this.storeName);await us(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await cs(this.dbName,this.storeName),r=await us(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var Ei=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},ds=class{constructor(){h(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 Ei(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}},jl=class{constructor(e,r={}){this.vfs=e;h(this,"textures");h(this,"audio");h(this,"dependencyTracker");h(this,"resourceTracker");h(this,"md2");h(this,"md3");h(this,"sprite");h(this,"bsp");h(this,"palette");h(this,"maps",new Map);h(this,"loadQueue",[]);h(this,"activeLoads",0);h(this,"maxConcurrentLoads");this.textures=new ea({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new ba(e,{cacheSize:r.audioCacheSize??64,workerPath:r.audioWorkerPath}),this.dependencyTracker=r.dependencyTracker??new ds,this.resourceTracker=r.resourceTracker,this.md2=new ji(e),this.md3=new Qi(e),this.sprite=new Ji(e),this.bsp=new Zi(e,{useWorker:!!r.bspWorkerPath,workerPath:r.bspWorkerPath}),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=go(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 o=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,o?.size,o?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),a;if(i==="wal")a=yl(n,this.palette);else if(i==="pcx")a=gl(go(n));else if(i==="tga")a=Ih(Gu(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,a),a}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 s=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,s?.size,s?.sourcePak)}let n=this.makeKey("model",e),i=r.map(s=>this.makeKey("texture",s));this.dependencyTracker.register(n,i);let a=this.dependencyTracker.missingDependencies(n);if(a.length>0)throw new Ei(a,`Asset ${n} is missing dependencies: ${a.join(", ")}`);let o=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),o}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 s=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,s?.size,s?.sourcePak)}let n=this.makeKey("model",e),i=r.map(s=>this.makeKey("texture",s));this.dependencyTracker.register(n,i);let a=this.dependencyTracker.missingDependencies(n);if(a.length>0)throw new Ei(a,`Asset ${n} is missing dependencies: ${a.join(", ")}`);let o=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),o}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:this.audio.size,heapTotal:e,heapUsed:r}}enforceMemoryBudget(e){e.textureMemoryLimit!==void 0&&(this.textures.maxMemory=e.textureMemoryLimit),e.textureCacheCapacity!==void 0&&(this.textures.capacity=e.textureCacheCapacity),e.audioCacheSize!==void 0&&(this.audio.capacity=e.audioCacheSize)}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,a)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:a}),this.loadQueue.sort((o,s)=>s.priority-o.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}:${Le(r)}`}};var Ql=class{constructor(e){this.factory=e;h(this,"context")}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 Jl(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),a;if(e.createConvolver&&e.createGain){let o=e.createConvolver(),s=e.createGain(),c=e.createGain();s.connect(o),o.connect(c),a={convolver:o,input:s,output:c}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),a&&a.output.connect(i)):(r.connect(n),a&&a.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:a}}var ec=class{constructor(e=new Yi){this.configStrings=e;h(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 tc=class{constructor(e){h(this,"vfs");h(this,"registry");h(this,"contextController");h(this,"decodeAudio");h(this,"soundRoot");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(a=>this.normalize(a)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let a of r)try{let o=this.registry.find(a);if(o!==void 0&&this.registry.has(o)){n.skipped.push(a);continue}if(!this.vfs.stat(a)){n.missing.push(a);continue}let l=(await this.vfs.readFile(a)).slice().buffer,u=await this.decodeAudio(i,l);this.registry.register(a,u),n.loaded.push(a)}catch(o){let s=o instanceof Error?o:new Error(String(o));n.errors[a]=s}return n}normalize(e){let r=Le(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:Le(`${this.soundRoot}${r}`)}};var E1=7,fs=t=>t&E1;function rc(t){return Array.from({length:so},()=>({entnum:0,entchannel:Ir.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function nc(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=fs(r),a=-1,o=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s+=1){let c=t[s],l=fs(c.entchannel);if(i!==Ir.Auto&&c.entnum===e&&l===i){a=s;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let u=c.endTimeMs-n.nowMs;(a===-1||u<o)&&(o=u,a=s)}return a===-1?void 0:a}var ic=class{constructor(e){h(this,"activePreset",null);h(this,"node");h(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 ac=class{constructor(e){h(this,"channels");h(this,"registry");h(this,"contextController");h(this,"graph");h(this,"playerEntity");h(this,"activeSources",new Map);h(this,"resolveOcclusion");h(this,"listener");h(this,"sfxVolume");h(this,"masterVolume");h(this,"playbackRate",1);h(this,"reverb");this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=rc(e.playerEntity),this.listener=e.listener??{origin:Qf,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=Jl(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new ic(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,a=nc(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(a===void 0)return;let o=this.activeSources.get(a);o&&(o.source.onended=null,o.source.stop(),this.activeSources.delete(a));let s=n.createBufferSource();s.buffer=r,s.loop=e.looping??!1,s.playbackRate&&(s.playbackRate.value=this.playbackRate);let c=e.origin??this.listener.origin,l=n.createGain(),u=this.createPanner(n,e.attenuation),d=this.resolveOcclusion?.(this.listener,c,e.attenuation),f=dm(d?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,d?.lowpassHz??2e4):void 0;this.applyOriginToPanner(u,c);let y=e.volume/255*this.sfxVolume,g=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=y*f*g;let b=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+b*1e3;s.connect(u);let x=u;m?(u.connect(m),m.connect(l),x=l):(u.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),s.start(b),s.onended=()=>{this.channels[a].active=!1,this.activeSources.delete(a)};let v={channelIndex:a,entnum:e.entity,entchannel:fs(e.channel),endTimeMs:_,source:s,panner:u,gain:l,baseGain:y,origin:c,attenuation:e.attenuation,occlusion:m?{scale:f,lowpassHz:d?.lowpassHz,filter:m}:d?{scale:f,lowpassHz:d.lowpassHz}:void 0};return this.channels[a]={entnum:e.entity,entchannel:fs(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(a,v),v}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:Ir.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:Ir.Auto,soundIndex:r,volume:n,attenuation:lo,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=Wi(r);return e.refDistance=Hi,e.maxDistance=ci(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=ud(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=dm(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 a=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=ud(a,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},ud=(t,e,r)=>Math.min(r,Math.max(e,t)),dm=t=>ud(t,0,1);var hs=class{constructor(e){this.trace=e;h(this,"resolve",(e,r,n)=>{let i=gu(Jf(r,e.origin)),a=ci(n),c=2e4*(1-Math.min(i,a)/Math.max(1,a)*.9),l=this.trace(e.origin,r,void 0,void 0),u=1,d=2e4;l.fraction<1&&(u=.3,d=400);let f=Math.min(c,d);if(u<1||f<2e4)return{gainScale:u,lowpassHz:f}})}};function fm(t){return new hs(t).resolve}var oc=class{constructor(e){h(this,"createElement");h(this,"resolveSource");h(this,"crossfadeDuration");h(this,"currentElement");h(this,"fadingElement");h(this,"track");h(this,"volume");h(this,"fadeInterval");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 a=this.createElement();a.src=i,a.loop=r,a.volume=0,a.currentTime=0,a.load();try{await a.play()}catch(o){console.warn(`MusicSystem: Failed to play ${e}`,o),this.fadingElement}this.currentElement=a,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,a=this.fadingElement?this.fadingElement.volume:0,o=()=>{let s=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(s=!0)),this.fadingElement&&(a=Math.max(0,a-n),this.fadingElement.volume=a,a>0?s=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),s||this.cancelFade()};o(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(o,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function T1(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 L1(t,e,r,n){for(let i of e){let a=t.getExtension(i);if(!a)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,a)}for(let i of r){let a=t.getExtension(i);a&&n.set(i,a)}}function hm(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,a=t.getContext("webgl2",r??{antialias:!0});if(!a)throw new Error("WebGL2 not supported or failed to initialize");T1(a);let o=new Map;L1(a,n,i,o);let s=!1,c=new Set,l=new Set,u=f=>{s=!0,f.preventDefault();for(let m of c)m()},d=()=>{s=!1;for(let f of l)f()};return t.addEventListener("webglcontextlost",u),t.addEventListener("webglcontextrestored",d),{gl:a,extensions:o,isLost:()=>s,onLost(f){return c.add(f),()=>c.delete(f)},onRestored(f){return l.add(f),()=>l.delete(f)},dispose(){t.removeEventListener("webglcontextlost",u),t.removeEventListener("webglcontextrestored",d),c.clear(),l.clear(),o.clear()}}}function mm(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r.trim()),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let a=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(a)}return n}function P1(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[o,s]of Object.entries(n))t.bindAttribLocation(i,s,o);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let o=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(o)}return i}var he=class t{constructor(e,r,n){h(this,"gl");h(this,"program");h(this,"uniformLocations",new Map);h(this,"attributeLocations",new Map);h(this,"sourceSize");this.gl=e,this.program=r,this.sourceSize=n}static create(e,r,n){let i=mm(e,e.VERTEX_SHADER,r.vertex),a=mm(e,e.FRAGMENT_SHADER,r.fragment);try{let o=P1(e,i,a,n),s=r.vertex.length+r.fragment.length;return new t(e,o,s)}finally{e.deleteShader(i),e.deleteShader(a)}}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 pm(t,e,r){return he.create(t,e,r)}var Be=class{constructor(e,r=e.STATIC_DRAW,n){h(this,"gl");h(this,"buffer");h(this,"target");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)}},ut=class extends Be{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},Fe=class{constructor(e){h(this,"gl");h(this,"vao");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)}},dt=class{constructor(e,r=e.TEXTURE_2D){h(this,"gl");h(this,"texture");h(this,"target");h(this,"width",0);h(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,a,o,s,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,a,o,s,c)}dispose(){this.gl.deleteTexture(this.texture)}},xa=class{constructor(e){h(this,"gl");h(this,"texture");h(this,"target");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,a,o,s,c,l){this.bind(),this.gl.texImage2D(e,r,n,i,a,o,s,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},Ti=class{constructor(e){h(this,"gl");h(this,"framebuffer");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 fd=4,dd=7*fd,hd=[{index:0,size:3,type:5126,stride:dd,offset:0},{index:1,size:2,type:5126,stride:dd,offset:3*fd},{index:2,size:2,type:5126,stride:dd,offset:5*fd}];function R1(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function C1(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 B1(t,e,r){let n=C1(r),i=t.width*4,a=e.x+t.padding,o=e.y+t.padding,s=0;for(let c=0;c<r.height;c++){let l=(o+c)*i+a*4;for(let u=0;u<r.width;u++){let d=l+u*4;t.data[d]=r.samples[s],t.data[d+1]=r.samples[s+1],t.data[d+2]=r.samples[s+2],t.data[d+3]=n===4?r.samples[s+3]:255,s+=n}}}function F1(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 s of t){if(s.cursorX+n>s.width&&(s.cursorX=0,s.cursorY+=s.rowHeight+r.lightmapPadding,s.rowHeight=0),s.cursorY+i>s.height)continue;let c={atlasIndex:t.indexOf(s),x:s.cursorX,y:s.cursorY,width:e.width,height:e.height};return s.cursorX+=n+r.lightmapPadding,s.rowHeight=Math.max(s.rowHeight,i),{placement:c,atlas:s}}let a=R1(r.atlasSize,r.lightmapPadding);t.push(a);let o={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return a.cursorX=n+r.lightmapPadding,a.rowHeight=i,{placement:o,atlas:a}}function sc(t){return t instanceof Float32Array?t:new Float32Array(t)}function I1(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 D1(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 k1(t,e){let r=sc(t.vertices),n=sc(t.textureCoords),i=e?D1(sc(t.lightmapCoords??t.textureCoords),e):sc(t.lightmapCoords??new Float32Array(n.length)),a=r.length/3;if(n.length/2!==a)throw new Error("Texture coordinates count mismatch");if(i.length/2!==a)throw new Error("Lightmap coordinates count mismatch");let o=new Float32Array(a*7);for(let s=0;s<a;s++){let c=s*3,l=s*2,u=s*7;o[u]=r[c],o[u+1]=r[c+1],o[u+2]=r[c+2],o[u+3]=n[l],o[u+4]=n[l+1],o[u+5]=i[l],o[u+6]=i[l+1]}return o}function lc(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],a=[],o=[],s=[];for(let f=0;f<n.numEdges;f++){let m=t.surfEdges[n.firstEdge+f],p=t.edges[Math.abs(m)],y=m>=0?p.vertices[0]:p.vertices[1],g=t.vertices[y];a.push(g[0],g[1],g[2]);let b=g[0]*i.s[0]+g[1]*i.s[1]+g[2]*i.s[2]+i.sOffset,_=g[0]*i.t[0]+g[1]*i.t[1]+g[2]*i.t[2]+i.tOffset;o.push(b,_),s.push(b,_)}let c=[],l=a.length/3;for(let f=1;f<l-1;f++)c.push(0,f,f+1);let u,d=t.lightMapInfo[r];if(d){let f=1/0,m=-1/0,p=1/0,y=-1/0;for(let S=0;S<o.length;S+=2){let M=o[S],w=o[S+1];M<f&&(f=M),M>m&&(m=M),w<p&&(p=w),w>y&&(y=w)}let g=Math.floor(f/16),b=Math.floor(p/16),_=Math.ceil(m/16)-g+1,x=Math.ceil(y/16)-b+1,v=fl(n,t.lightMaps,d);if(v&&v.length===_*x*3){u={width:_,height:x,samples:v};for(let S=0;S<s.length;S+=2)s[S]=o[S]/16-g+.5,s[S+1]=o[S+1]/16-b+.5}}e.push({vertices:new Float32Array(a),textureCoords:new Float32Array(o),lightmapCoords:new Float32Array(s),indices:new Uint16Array(c),texture:i.texture,surfaceFlags:i.flags,lightmap:u,faceIndex:r})}return e}function cc(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let u=new Set;for(let d of r.entities.entities)if(d.classname&&n.hiddenClassnames.has(d.classname)){let f=d.properties.model;if(f&&f.startsWith("*")){let m=parseInt(f.substring(1),10);if(!isNaN(m)&&m>=0&&m<r.models.length){let p=r.models[m];for(let y=0;y<p.numFaces;y++)u.add(p.firstFace+y)}}}u.size>0&&(i=e.filter(d=>!u.has(d.faceIndex)))}let a={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},o=[],s=new Map;i.forEach((u,d)=>{if(!u.lightmap)return;let{placement:f,atlas:m}=F1(o,u.lightmap,a);B1(m,f,u.lightmap),s.set(d,{atlasIndex:f.atlasIndex,offset:[(f.x+a.lightmapPadding)/a.atlasSize,(f.y+a.lightmapPadding)/a.atlasSize],scale:[f.width/a.atlasSize,f.height/a.atlasSize]})});let c=o.map(u=>{let d=new dt(t);return d.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),d.uploadImage(0,t.RGBA,u.width,u.height,0,t.RGBA,t.UNSIGNED_BYTE,u.data),{texture:d,width:u.width,height:u.height,pixels:u.data}});return{surfaces:i.map((u,d)=>{let f=s.get(d),m=k1(u,f),p=I1(u.indices,m.length/7),y=new Be(t,t.STATIC_DRAW,t.ARRAY_BUFFER);y.upload(m);let g=new ut(t,t.STATIC_DRAW);g.upload(p);let b=new Fe(t);return b.configureAttributes(hd,y),{vao:b,vertexBuffer:y,indexBuffer:g,indexCount:p.length,vertexCount:m.length/7,texture:u.texture,surfaceFlags:u.surfaceFlags??xn,lightmap:f,vertexData:m,indexData:p}}),lightmaps:c}}function va(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 cr(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],a=t[1],o=t[5],s=t[9],c=t[13],l=t[2],u=t[6],d=t[10],f=t[14],m=t[3],p=t[7],y=t[11],g=t[15];return[va({normal:{x:m+e,y:p+r,z:y+n},distance:g+i}),va({normal:{x:m-e,y:p-r,z:y-n},distance:g-i}),va({normal:{x:m+a,y:p+o,z:y+s},distance:g+c}),va({normal:{x:m-a,y:p-o,z:y-s},distance:g-c}),va({normal:{x:m+l,y:p+u,z:y+d},distance:g+f}),va({normal:{x:m-l,y:p-u,z:y-d},distance:g-f})]}function U1(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Li(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,a=n.normal.y>=0?e.y:t.y,o=n.normal.z>=0?e.z:t.z;if(U1(n,{x:i,y:a,z:o})<0)return!1}return!0}function gm(t,e,r){let n=(t.x+e.x)*.5,i=(t.y+e.y)*.5,a=(t.z+e.z)*.5,o=(e.x-t.x)*.5,s=(e.y-t.y)*.5,c=(e.z-t.z)*.5,l=r,u=l[0]*n+l[4]*i+l[8]*a+l[12],d=l[1]*n+l[5]*i+l[9]*a+l[13],f=l[2]*n+l[6]*i+l[10]*a+l[14],m=Math.abs(l[0])*o+Math.abs(l[4])*s+Math.abs(l[8])*c,p=Math.abs(l[1])*o+Math.abs(l[5])*s+Math.abs(l[9])*c,y=Math.abs(l[2])*o+Math.abs(l[6])*s+Math.abs(l[10])*c;return{mins:{x:u-m,y:d-p,z:f-y},maxs:{x:u+m,y:d+p,z:f+y}}}function md(t){return t<0}function pd(t){return-t-1}function ym(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function yd(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,a=Math.floor(r/8),o=1<<r%8;return a<0||a>=n?!1:(i[a]&o)!==0}function z1(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 Li(r,n,e)}function Pi(t,e){if(t.models.length===0)return-1;let r=t.models[0].headNode;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],o=ym(i,e)>=0?0:1,s=n.children[o];if(md(s))return pd(s);r=s}return md(r)?pd(r):-1}function O1(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 gd(t,e,r,n,i,a,o,s){if(md(e)){let m=pd(e),p=t.leafs[m];if(s&&p.area>=0&&!s.has(p.area)||!yd(t.visibility,i,p.cluster)||!z1(p,n))return;let y={x:(p.mins[0]+p.maxs[0])*.5,y:(p.mins[1]+p.maxs[1])*.5,z:(p.mins[2]+p.maxs[2])*.5},g=y.x-r.x,b=y.y-r.y,_=y.z-r.z,x=-(g*g+b*b+_*_);for(let v of O1(t,m))o.has(v)||(o.add(v),a.push({faceIndex:v,leafIndex:m,sortKey:x}));return}let c=t.nodes[e],l=t.planes[c.planeIndex],u=ym(l,r),d=u>=0?c.children[0]:c.children[1],f=u>=0?c.children[1]:c.children[0];Li({x:c.mins[0],y:c.mins[1],z:c.mins[2]},{x:c.maxs[0],y:c.maxs[1],z:c.maxs[2]},n)&&(gd(t,d,r,n,i,a,o,s),gd(t,f,r,n,i,a,o,s))}function bd(t,e,r){let n=new Set;if(e<0||e>=t.areas.length)return n;let i=[e];for(n.add(e);i.length>0;){let a=i.pop(),o=t.areas[a];for(let s=0;s<o.numAreaPortals;s++){let c=o.firstAreaPortal+s,l=t.areaPortals[c],u=l.otherArea;(l.portalNumber<=0||r[l.portalNumber])&&!n.has(u)&&(n.add(u),i.push(u))}}return n}function dn(t,e,r,n){let i=Pi(t,e),a=i>=0?t.leafs[i]:null,o=a?a.cluster:-1,s=a?a.area:-1,c=null;n&&s>=0&&t.areas&&t.areas.length>0&&(c=bd(t,s,n));let l=[],u=new Set;if(t.models.length>0){let d=t.models[0].headNode;gd(t,d,e,r,o,l,u,c)}return l}var Vr=32,uc=class{constructor(){h(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 _a(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],a=t[r+2];e.push(n,i,i,a,a,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var xd=`#version 300 es
|
|
141
|
+
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var Xe={a:He};this.setModule=z=>{t.setModule(cn,z)},this.getModule=()=>t.getModule(cn),this.instantiate=()=>(this.getModule().then(z=>WebAssembly.instantiate(z,Xe)).then(z=>{let de=z.exports;We(de),p=de.l,y(),ft(de),r()}),this.ready=new Promise(z=>{r=z}).then(()=>{this.HEAP=p.buffer,this.malloc=j,this.free=jt,this.create_decoder=Ae,this.send_setup=ue,this.init_dsp=ve,this.decode_packets=Ie,this.destroy_decoder=nt}),this)}function Ai(){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 a=t[i];this._input.buf.set(a),this._inputLen.buf[0]=a.length,this._common.wasm.decode_packets(this._decoder);let o=this._samplesDecoded.buf[0],s=[],c=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let u=new Float32Array(o);o&&u.set(new Float32Array(this._common.wasm.HEAP,c[l],o)),s.push(u)}e.push(s),r+=o,this._frameNumber++,this._inputBytes+=a.length,this._outputSamples+=o;for(let l=0;l<this._errorsLength.buf;l+=2){let u=this._common.codeToString(this._errors.buf[l]),d=this._common.codeToString(this._errors.buf[l+1]);n.push({message:u+" vorbis_synthesis"+d,frameLength:a.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=Ai.isWebWorker,this._WASMAudioDecoderCommon=Ai.WASMAudioDecoderCommon||Se,this._EmscriptenWASM=Ai.EmscriptenWASM||cn,this._module=Ai.module,this._inputSize=128*1024,this._ready=this._init(),this}var Yl=Symbol(),un=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Se,this._init(),this._ready=this[Yl](Ai)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new am("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[Yl](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 a=0;a<e.length;a++){let o=e[a];if(this._vorbisSetupInProgress&&(o[Kl][0]===1&&this._decoder.sendSetupHeader(o[Kl]),o[$l].length)){let s=o[$l][0][om];this._decoder.sendSetupHeader(s[lm]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...o[$l].map(s=>s[Kl]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[sm]){let a=this._totalSamplesDecoded-i[cm];if(a>0){for(let o=0;o<n.channelData.length;o++)n.channelData[o]=n.channelData[o].subarray(0,n.samplesDecoded-a);n.samplesDecoded-=a,this._totalSamplesDecoded-=a}}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 sd=class extends ta{constructor(e){super(e,"ogg-vorbis-decoder",Ai,cn)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},ss=class extends un{constructor(){super(),this._ready=super[Yl](sd)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};xl(un,"OggVorbisDecoder");xl(ss,"OggVorbisDecoderWebWorker");var ld=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function ql(t,e=new un){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new ld(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var ls=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},ba=class{constructor(e,r={}){this.vfs=e;f(this,"cache");f(this,"refCounts",new Map);f(this,"worker");f(this,"nextRequestId",0);this.cache=new Ln(r.cacheSize??64),r.workerPath&&(this.worker=new Worker(r.workerPath,{type:"module"}))}get size(){return this.cache.size}get capacity(){return this.cache.capacity}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 a=(await this.vfs.readFile(e)).slice().buffer,o=await this.decodeByExtension(e,a);return this.cache.set(r,o),this.refCounts.set(r,1),o}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()}set capacity(e){this.cache.capacity=e}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){if(this.worker)return this.decodeWavInWorker(r);let i=bl(r),a=i.channels,o=Array.from({length:a},()=>new Float32Array(i.samples.length/a));for(let s=0;s<i.samples.length;s+=1)o[s%a][Math.floor(s/a)]=i.samples[s];return{sampleRate:i.sampleRate,channels:a,bitDepth:i.bitsPerSample,channelData:o}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return ql(r);throw new ls(`Unsupported audio format: ${e}`)}decodeWavInWorker(e){return new Promise((r,n)=>{if(!this.worker){n(new Error("Worker not initialized"));return}let i=this.nextRequestId++,a=o=>{if(o.data.id===i)if(this.worker.removeEventListener("message",a),o.data.type==="success"){let s=o.data.data,c=s.channels,l=Array.from({length:c},()=>new Float32Array(s.samples.length/c));for(let u=0;u<s.samples.length;u+=1)l[u%c][Math.floor(u/c)]=s.samples[u];r({sampleRate:s.sampleRate,channels:c,bitDepth:s.bitsPerSample,channelData:l})}else n(new Error(o.data.message))};this.worker.addEventListener("message",a),this.worker.postMessage({id:i,buffer:e,type:"wav"},[e])})}};var w1="quake2ts-pak-indexes",M1="pak-indexes";function um(){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 cs(t,e){let r=um();return r?new Promise((n,i)=>{let a=r.open(t,1);a.onupgradeneeded=()=>{let{result:o}=a;o.objectStoreNames.contains(e)||o.createObjectStore(e,{keyPath:"key"})},a.onerror=()=>i(a.error??new Error("Unknown IndexedDB error")),a.onsuccess=()=>n(a.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function us(t,e,r,n){return new Promise((i,a)=>{let s=t.transaction(e,r).objectStore(e),c=n(s);c.onsuccess=()=>i(c.result),c.onerror=()=>a(c.error??new Error("IndexedDB transaction error"))})}function cd(t,e){return`${Le(t)}:${e.toString(16)}`}function A1(t){return t.map(e=>({...e}))}var Zl=class{constructor(e=w1,r=M1){this.dbName=e;this.storeName=r}get isSupported(){return!!um()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:cd(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:A1(r.entries)},i=await cs(this.dbName,this.storeName);return await us(i,this.storeName,"readwrite",a=>a.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await cs(this.dbName,this.storeName),i=r!==void 0?cd(e,r):void 0,a=await us(n,this.storeName,"readonly",o=>i?o.get(i):o.getAll());if(n.close(),!!a){if(Array.isArray(a)){let o=Le(e),s=a.filter(c=>Le(c.name)===o);return s.length===0?void 0:s.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return a}}async remove(e,r){if(!this.isSupported)return!1;let n=await cs(this.dbName,this.storeName),i=r!==void 0?cd(e,r):void 0,a=await us(n,this.storeName,"readwrite",o=>{if(i)return o.delete(i);let s=`${Le(e)}:`;return o.delete(IDBKeyRange.bound(s,`${s}\uFFFF`,!1,!0))});return n.close(),typeof a=="number"?a>0:!0}async clear(){if(!this.isSupported)return;let e=await cs(this.dbName,this.storeName);await us(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await cs(this.dbName,this.storeName),r=await us(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var Ei=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},ds=class{constructor(){f(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 Ei(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}},jl=class{constructor(e,r={}){this.vfs=e;f(this,"textures");f(this,"audio");f(this,"dependencyTracker");f(this,"resourceTracker");f(this,"md2");f(this,"md3");f(this,"sprite");f(this,"bsp");f(this,"palette");f(this,"maps",new Map);f(this,"loadQueue",[]);f(this,"activeLoads",0);f(this,"maxConcurrentLoads");this.textures=new ea({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new ba(e,{cacheSize:r.audioCacheSize??64,workerPath:r.audioWorkerPath}),this.dependencyTracker=r.dependencyTracker??new ds,this.resourceTracker=r.resourceTracker,this.md2=new ji(e),this.md3=new Qi(e),this.sprite=new Ji(e),this.bsp=new Zi(e,{useWorker:!!r.bspWorkerPath,workerPath:r.bspWorkerPath}),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=go(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 o=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,o?.size,o?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),a;if(i==="wal")a=yl(n,this.palette);else if(i==="pcx")a=gl(go(n));else if(i==="tga")a=Ih(Gu(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,a),a}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 s=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,s?.size,s?.sourcePak)}let n=this.makeKey("model",e),i=r.map(s=>this.makeKey("texture",s));this.dependencyTracker.register(n,i);let a=this.dependencyTracker.missingDependencies(n);if(a.length>0)throw new Ei(a,`Asset ${n} is missing dependencies: ${a.join(", ")}`);let o=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),o}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 s=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,s?.size,s?.sourcePak)}let n=this.makeKey("model",e),i=r.map(s=>this.makeKey("texture",s));this.dependencyTracker.register(n,i);let a=this.dependencyTracker.missingDependencies(n);if(a.length>0)throw new Ei(a,`Asset ${n} is missing dependencies: ${a.join(", ")}`);let o=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),o}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:this.audio.size,heapTotal:e,heapUsed:r}}enforceMemoryBudget(e){e.textureMemoryLimit!==void 0&&(this.textures.maxMemory=e.textureMemoryLimit),e.textureCacheCapacity!==void 0&&(this.textures.capacity=e.textureCacheCapacity),e.audioCacheSize!==void 0&&(this.audio.capacity=e.audioCacheSize)}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,a)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:a}),this.loadQueue.sort((o,s)=>s.priority-o.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}:${Le(r)}`}};var Ql=class{constructor(e){this.factory=e;f(this,"context")}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 Jl(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),a;if(e.createConvolver&&e.createGain){let o=e.createConvolver(),s=e.createGain(),c=e.createGain();s.connect(o),o.connect(c),a={convolver:o,input:s,output:c}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),a&&a.output.connect(i)):(r.connect(n),a&&a.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:a}}var ec=class{constructor(e=new Yi){this.configStrings=e;f(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 tc=class{constructor(e){f(this,"vfs");f(this,"registry");f(this,"contextController");f(this,"decodeAudio");f(this,"soundRoot");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(a=>this.normalize(a)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let a of r)try{let o=this.registry.find(a);if(o!==void 0&&this.registry.has(o)){n.skipped.push(a);continue}if(!this.vfs.stat(a)){n.missing.push(a);continue}let l=(await this.vfs.readFile(a)).slice().buffer,u=await this.decodeAudio(i,l);this.registry.register(a,u),n.loaded.push(a)}catch(o){let s=o instanceof Error?o:new Error(String(o));n.errors[a]=s}return n}normalize(e){let r=Le(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:Le(`${this.soundRoot}${r}`)}};var E1=7,fs=t=>t&E1;function rc(t){return Array.from({length:so},()=>({entnum:0,entchannel:Ir.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function nc(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=fs(r),a=-1,o=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s+=1){let c=t[s],l=fs(c.entchannel);if(i!==Ir.Auto&&c.entnum===e&&l===i){a=s;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let u=c.endTimeMs-n.nowMs;(a===-1||u<o)&&(o=u,a=s)}return a===-1?void 0:a}var ic=class{constructor(e){f(this,"activePreset",null);f(this,"node");f(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 ac=class{constructor(e){f(this,"channels");f(this,"registry");f(this,"contextController");f(this,"graph");f(this,"playerEntity");f(this,"activeSources",new Map);f(this,"resolveOcclusion");f(this,"listener");f(this,"sfxVolume");f(this,"masterVolume");f(this,"playbackRate",1);f(this,"reverb");this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=rc(e.playerEntity),this.listener=e.listener??{origin:Qf,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=Jl(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new ic(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,a=nc(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(a===void 0)return;let o=this.activeSources.get(a);o&&(o.source.onended=null,o.source.stop(),this.activeSources.delete(a));let s=n.createBufferSource();s.buffer=r,s.loop=e.looping??!1,s.playbackRate&&(s.playbackRate.value=this.playbackRate);let c=e.origin??this.listener.origin,l=n.createGain(),u=this.createPanner(n,e.attenuation),d=this.resolveOcclusion?.(this.listener,c,e.attenuation),h=dm(d?.gainScale??1),m=this.resolveOcclusion?this.createOcclusionFilter(n,d?.lowpassHz??2e4):void 0;this.applyOriginToPanner(u,c);let y=e.volume/255*this.sfxVolume,g=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=y*h*g;let b=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+b*1e3;s.connect(u);let x=u;m?(u.connect(m),m.connect(l),x=l):(u.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),s.start(b),s.onended=()=>{this.channels[a].active=!1,this.activeSources.delete(a)};let v={channelIndex:a,entnum:e.entity,entchannel:fs(e.channel),endTimeMs:_,source:s,panner:u,gain:l,baseGain:y,origin:c,attenuation:e.attenuation,occlusion:m?{scale:h,lowpassHz:d?.lowpassHz,filter:m}:d?{scale:h,lowpassHz:d.lowpassHz}:void 0};return this.channels[a]={entnum:e.entity,entchannel:fs(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(a,v),v}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:Ir.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:Ir.Auto,soundIndex:r,volume:n,attenuation:lo,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=Wi(r);return e.refDistance=Hi,e.maxDistance=ci(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=ud(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=dm(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 a=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=ud(a,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},ud=(t,e,r)=>Math.min(r,Math.max(e,t)),dm=t=>ud(t,0,1);var hs=class{constructor(e){this.trace=e;f(this,"resolve",(e,r,n)=>{let i=gu(Jf(r,e.origin)),a=ci(n),c=2e4*(1-Math.min(i,a)/Math.max(1,a)*.9),l=this.trace(e.origin,r,void 0,void 0),u=1,d=2e4;l.fraction<1&&(u=.3,d=400);let h=Math.min(c,d);if(u<1||h<2e4)return{gainScale:u,lowpassHz:h}})}};function fm(t){return new hs(t).resolve}var oc=class{constructor(e){f(this,"createElement");f(this,"resolveSource");f(this,"crossfadeDuration");f(this,"currentElement");f(this,"fadingElement");f(this,"track");f(this,"volume");f(this,"fadeInterval");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 a=this.createElement();a.src=i,a.loop=r,a.volume=0,a.currentTime=0,a.load();try{await a.play()}catch(o){console.warn(`MusicSystem: Failed to play ${e}`,o),this.fadingElement}this.currentElement=a,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,a=this.fadingElement?this.fadingElement.volume:0,o=()=>{let s=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(s=!0)),this.fadingElement&&(a=Math.max(0,a-n),this.fadingElement.volume=a,a>0?s=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),s||this.cancelFade()};o(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(o,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function T1(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 L1(t,e,r,n){for(let i of e){let a=t.getExtension(i);if(!a)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,a)}for(let i of r){let a=t.getExtension(i);a&&n.set(i,a)}}function hm(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,a=t.getContext("webgl2",r??{antialias:!0});if(!a)throw new Error("WebGL2 not supported or failed to initialize");T1(a);let o=new Map;L1(a,n,i,o);let s=!1,c=new Set,l=new Set,u=h=>{s=!0,h.preventDefault();for(let m of c)m()},d=()=>{s=!1;for(let h of l)h()};return t.addEventListener("webglcontextlost",u),t.addEventListener("webglcontextrestored",d),{gl:a,extensions:o,isLost:()=>s,onLost(h){return c.add(h),()=>c.delete(h)},onRestored(h){return l.add(h),()=>l.delete(h)},dispose(){t.removeEventListener("webglcontextlost",u),t.removeEventListener("webglcontextrestored",d),c.clear(),l.clear(),o.clear()}}}function mm(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r.trim()),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let a=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(a)}return n}function P1(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[o,s]of Object.entries(n))t.bindAttribLocation(i,s,o);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let o=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(o)}return i}var he=class t{constructor(e,r,n){f(this,"gl");f(this,"program");f(this,"uniformLocations",new Map);f(this,"attributeLocations",new Map);f(this,"sourceSize");this.gl=e,this.program=r,this.sourceSize=n}static create(e,r,n){let i=mm(e,e.VERTEX_SHADER,r.vertex),a=mm(e,e.FRAGMENT_SHADER,r.fragment);try{let o=P1(e,i,a,n),s=r.vertex.length+r.fragment.length;return new t(e,o,s)}finally{e.deleteShader(i),e.deleteShader(a)}}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 pm(t,e,r){return he.create(t,e,r)}var Be=class{constructor(e,r=e.STATIC_DRAW,n){f(this,"gl");f(this,"buffer");f(this,"target");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)}},ut=class extends Be{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},Fe=class{constructor(e){f(this,"gl");f(this,"vao");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)}},dt=class{constructor(e,r=e.TEXTURE_2D){f(this,"gl");f(this,"texture");f(this,"target");f(this,"width",0);f(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,a,o,s,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,a,o,s,c)}dispose(){this.gl.deleteTexture(this.texture)}},xa=class{constructor(e){f(this,"gl");f(this,"texture");f(this,"target");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,a,o,s,c,l){this.bind(),this.gl.texImage2D(e,r,n,i,a,o,s,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},Ti=class{constructor(e){f(this,"gl");f(this,"framebuffer");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 fd=4,dd=7*fd,hd=[{index:0,size:3,type:5126,stride:dd,offset:0},{index:1,size:2,type:5126,stride:dd,offset:3*fd},{index:2,size:2,type:5126,stride:dd,offset:5*fd}];function R1(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function C1(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 B1(t,e,r){let n=C1(r),i=t.width*4,a=e.x+t.padding,o=e.y+t.padding,s=0;for(let c=0;c<r.height;c++){let l=(o+c)*i+a*4;for(let u=0;u<r.width;u++){let d=l+u*4;t.data[d]=r.samples[s],t.data[d+1]=r.samples[s+1],t.data[d+2]=r.samples[s+2],t.data[d+3]=n===4?r.samples[s+3]:255,s+=n}}}function F1(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 s of t){if(s.cursorX+n>s.width&&(s.cursorX=0,s.cursorY+=s.rowHeight+r.lightmapPadding,s.rowHeight=0),s.cursorY+i>s.height)continue;let c={atlasIndex:t.indexOf(s),x:s.cursorX,y:s.cursorY,width:e.width,height:e.height};return s.cursorX+=n+r.lightmapPadding,s.rowHeight=Math.max(s.rowHeight,i),{placement:c,atlas:s}}let a=R1(r.atlasSize,r.lightmapPadding);t.push(a);let o={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return a.cursorX=n+r.lightmapPadding,a.rowHeight=i,{placement:o,atlas:a}}function sc(t){return t instanceof Float32Array?t:new Float32Array(t)}function I1(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 D1(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 k1(t,e){let r=sc(t.vertices),n=sc(t.textureCoords),i=e?D1(sc(t.lightmapCoords??t.textureCoords),e):sc(t.lightmapCoords??new Float32Array(n.length)),a=r.length/3;if(n.length/2!==a)throw new Error("Texture coordinates count mismatch");if(i.length/2!==a)throw new Error("Lightmap coordinates count mismatch");let o=new Float32Array(a*7);for(let s=0;s<a;s++){let c=s*3,l=s*2,u=s*7;o[u]=r[c],o[u+1]=r[c+1],o[u+2]=r[c+2],o[u+3]=n[l],o[u+4]=n[l+1],o[u+5]=i[l],o[u+6]=i[l+1]}return o}function lc(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],a=[],o=[],s=[];for(let p=0;p<n.numEdges;p++){let y=t.surfEdges[n.firstEdge+p],g=t.edges[Math.abs(y)],b=y>=0?g.vertices[0]:g.vertices[1],_=t.vertices[b];a.push(_[0],_[1],_[2]);let x=_[0]*i.s[0]+_[1]*i.s[1]+_[2]*i.s[2]+i.sOffset,v=_[0]*i.t[0]+_[1]*i.t[1]+_[2]*i.t[2]+i.tOffset;o.push(x,v),s.push(x,v)}let c=[],l=a.length/3;for(let p=1;p<l-1;p++)c.push(0,p,p+1);let u,d=t.lightMapInfo[r];if(d){let p=1/0,y=-1/0,g=1/0,b=-1/0;for(let S=0;S<o.length;S+=2){let E=o[S],L=o[S+1];E<p&&(p=E),E>y&&(y=E),L<g&&(g=L),L>b&&(b=L)}let _=Math.floor(p/16),x=Math.floor(g/16),v=Math.ceil(y/16)-_+1,w=Math.ceil(b/16)-x+1,M=fl(n,t.lightMaps,d);if(M&&M.length===v*w*3){u={width:v,height:w,samples:M};for(let S=0;S<s.length;S+=2)s[S]=o[S]/16-_+.5,s[S+1]=o[S+1]/16-x+.5}}let h={x:1/0,y:1/0,z:1/0},m={x:-1/0,y:-1/0,z:-1/0};for(let p=0;p<a.length;p+=3)a[p]<h.x&&(h.x=a[p]),a[p+1]<h.y&&(h.y=a[p+1]),a[p+2]<h.z&&(h.z=a[p+2]),a[p]>m.x&&(m.x=a[p]),a[p+1]>m.y&&(m.y=a[p+1]),a[p+2]>m.z&&(m.z=a[p+2]);e.push({vertices:new Float32Array(a),textureCoords:new Float32Array(o),lightmapCoords:new Float32Array(s),indices:new Uint16Array(c),texture:i.texture,surfaceFlags:i.flags,lightmap:u,faceIndex:r,mins:h,maxs:m})}return e}function cc(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let u=new Set;for(let d of r.entities.entities)if(d.classname&&n.hiddenClassnames.has(d.classname)){let h=d.properties.model;if(h&&h.startsWith("*")){let m=parseInt(h.substring(1),10);if(!isNaN(m)&&m>=0&&m<r.models.length){let p=r.models[m];for(let y=0;y<p.numFaces;y++)u.add(p.firstFace+y)}}}u.size>0&&(i=e.filter(d=>!u.has(d.faceIndex)))}let a={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},o=[],s=new Map;i.forEach((u,d)=>{if(!u.lightmap)return;let{placement:h,atlas:m}=F1(o,u.lightmap,a);B1(m,h,u.lightmap),s.set(d,{atlasIndex:h.atlasIndex,offset:[(h.x+a.lightmapPadding)/a.atlasSize,(h.y+a.lightmapPadding)/a.atlasSize],scale:[h.width/a.atlasSize,h.height/a.atlasSize]})});let c=o.map(u=>{let d=new dt(t);return d.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),d.uploadImage(0,t.RGBA,u.width,u.height,0,t.RGBA,t.UNSIGNED_BYTE,u.data),{texture:d,width:u.width,height:u.height,pixels:u.data}});return{surfaces:i.map((u,d)=>{let h=s.get(d),m=k1(u,h),p=I1(u.indices,m.length/7),y=new Be(t,t.STATIC_DRAW,t.ARRAY_BUFFER);y.upload(m);let g=new ut(t,t.STATIC_DRAW);g.upload(p);let b=new Fe(t);return b.configureAttributes(hd,y),{vao:b,vertexBuffer:y,indexBuffer:g,indexCount:p.length,vertexCount:m.length/7,texture:u.texture,surfaceFlags:u.surfaceFlags??xn,lightmap:h,vertexData:m,indexData:p,mins:u.mins,maxs:u.maxs}}),lightmaps:c}}function va(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 cr(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],a=t[1],o=t[5],s=t[9],c=t[13],l=t[2],u=t[6],d=t[10],h=t[14],m=t[3],p=t[7],y=t[11],g=t[15];return[va({normal:{x:m+e,y:p+r,z:y+n},distance:g+i}),va({normal:{x:m-e,y:p-r,z:y-n},distance:g-i}),va({normal:{x:m+a,y:p+o,z:y+s},distance:g+c}),va({normal:{x:m-a,y:p-o,z:y-s},distance:g-c}),va({normal:{x:m+l,y:p+u,z:y+d},distance:g+h}),va({normal:{x:m-l,y:p-u,z:y-d},distance:g-h})]}function U1(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Li(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,a=n.normal.y>=0?e.y:t.y,o=n.normal.z>=0?e.z:t.z;if(U1(n,{x:i,y:a,z:o})<0)return!1}return!0}function gm(t,e,r){let n=(t.x+e.x)*.5,i=(t.y+e.y)*.5,a=(t.z+e.z)*.5,o=(e.x-t.x)*.5,s=(e.y-t.y)*.5,c=(e.z-t.z)*.5,l=r,u=l[0]*n+l[4]*i+l[8]*a+l[12],d=l[1]*n+l[5]*i+l[9]*a+l[13],h=l[2]*n+l[6]*i+l[10]*a+l[14],m=Math.abs(l[0])*o+Math.abs(l[4])*s+Math.abs(l[8])*c,p=Math.abs(l[1])*o+Math.abs(l[5])*s+Math.abs(l[9])*c,y=Math.abs(l[2])*o+Math.abs(l[6])*s+Math.abs(l[10])*c;return{mins:{x:u-m,y:d-p,z:h-y},maxs:{x:u+m,y:d+p,z:h+y}}}function md(t){return t<0}function pd(t){return-t-1}function ym(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function yd(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,a=Math.floor(r/8),o=1<<r%8;return a<0||a>=n?!1:(i[a]&o)!==0}function z1(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 Li(r,n,e)}function Pi(t,e){if(t.models.length===0)return-1;let r=t.models[0].headNode;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],o=ym(i,e)>=0?0:1,s=n.children[o];if(md(s))return pd(s);r=s}return md(r)?pd(r):-1}function O1(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 gd(t,e,r,n,i,a,o,s){if(md(e)){let m=pd(e),p=t.leafs[m];if(s&&p.area>=0&&!s.has(p.area)||!yd(t.visibility,i,p.cluster)||!z1(p,n))return;let y={x:(p.mins[0]+p.maxs[0])*.5,y:(p.mins[1]+p.maxs[1])*.5,z:(p.mins[2]+p.maxs[2])*.5},g=y.x-r.x,b=y.y-r.y,_=y.z-r.z,x=-(g*g+b*b+_*_);for(let v of O1(t,m))o.has(v)||(o.add(v),a.push({faceIndex:v,leafIndex:m,sortKey:x}));return}let c=t.nodes[e],l=t.planes[c.planeIndex],u=ym(l,r),d=u>=0?c.children[0]:c.children[1],h=u>=0?c.children[1]:c.children[0];Li({x:c.mins[0],y:c.mins[1],z:c.mins[2]},{x:c.maxs[0],y:c.maxs[1],z:c.maxs[2]},n)&&(gd(t,d,r,n,i,a,o,s),gd(t,h,r,n,i,a,o,s))}function bd(t,e,r){let n=new Set;if(e<0||e>=t.areas.length)return n;let i=[e];for(n.add(e);i.length>0;){let a=i.pop(),o=t.areas[a];for(let s=0;s<o.numAreaPortals;s++){let c=o.firstAreaPortal+s,l=t.areaPortals[c],u=l.otherArea;(l.portalNumber<=0||r[l.portalNumber])&&!n.has(u)&&(n.add(u),i.push(u))}}return n}function dn(t,e,r,n){let i=Pi(t,e),a=i>=0?t.leafs[i]:null,o=a?a.cluster:-1,s=a?a.area:-1,c=null;n&&s>=0&&t.areas&&t.areas.length>0&&(c=bd(t,s,n));let l=[],u=new Set;if(t.models.length>0){let d=t.models[0].headNode;gd(t,d,e,r,o,l,u,c)}return l}var Vr=32,uc=class{constructor(){f(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 _a(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],a=t[r+2];e.push(n,i,i,a,a,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var xd=`#version 300 es
|
|
142
142
|
precision highp float;
|
|
143
143
|
|
|
144
144
|
layout(location = 0) in vec3 a_position;
|
|
@@ -339,7 +339,7 @@ void main() {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
o_color = finalColor;
|
|
342
|
-
}`,bm=[0,255,255,255],N1=[0,-1,-1,-1];function _d(t=bm,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let a=e[i];r[n]=a!==void 0?a:1}return r}function G1(t){return[-(t*.25%1),0]}function Sd(t=xn,e=0){let r=(t&rl)!==0,n=(t&Zr)!==0,i=(t&vn)!==0,a=(t&_n)!==0,o=(t&Sn)!==0,s=a?.33:o?.66:1,c=a||o||n,l=!c&&!i,u=r?G1(e):[0,0];return{alpha:s,blend:c,depthWrite:l,warp:n,flowOffset:u,sky:i}}var Sa=class{constructor(e){
|
|
342
|
+
}`,bm=[0,255,255,255],N1=[0,-1,-1,-1];function _d(t=bm,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let a=e[i];r[n]=a!==void 0?a:1}return r}function G1(t){return[-(t*.25%1),0]}function Sd(t=xn,e=0){let r=(t&rl)!==0,n=(t&Zr)!==0,i=(t&vn)!==0,a=(t&_n)!==0,o=(t&Sn)!==0,s=a?.33:o?.66:1,c=a||o||n,l=!c&&!i,u=r?G1(e):[0,0];return{alpha:s,blend:c,depthWrite:l,warp:n,flowOffset:u,sky:i}}var Sa=class{constructor(e){f(this,"gl");f(this,"program");f(this,"uniformMvp");f(this,"uniformTexScroll");f(this,"uniformLmScroll");f(this,"uniformLightStyles");f(this,"uniformStyleLayerMapping");f(this,"uniformAlpha");f(this,"uniformApplyLightmap");f(this,"uniformWarp");f(this,"uniformLightmapOnly");f(this,"uniformDiffuse");f(this,"uniformLightmap");f(this,"uniformRefraction");f(this,"uniformHasRefraction");f(this,"uniformTime");f(this,"uniformRenderMode");f(this,"uniformSolidColor");f(this,"uniformNumDlights");f(this,"uniformDlights",[]);f(this,"uniformBrightness");f(this,"uniformGamma");f(this,"uniformFullbright");f(this,"uniformAmbient");this.gl=e,this.program=he.create(e,{vertex:xd,fragment:vd},{a_position:0,a_texCoord:1,a_lightmapCoord:2,a_lightmapStep:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTexScroll=this.program.getUniformLocation("u_texScroll"),this.uniformLmScroll=this.program.getUniformLocation("u_lightmapScroll"),this.uniformLightStyles=this.program.getUniformLocation("u_lightStyleFactors"),this.uniformStyleLayerMapping=this.program.getUniformLocation("u_styleLayerMapping"),this.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformLightmapOnly=this.program.getUniformLocation("u_lightmapOnly"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformRefraction=this.program.getUniformLocation("u_refractionMap"),this.uniformHasRefraction=this.program.getUniformLocation("u_hasRefraction"),this.uniformTime=this.program.getUniformLocation("u_time"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Vr;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformAmbient=this.program.getUniformLocation("u_ambient")}get shaderSize(){return this.program.sourceSize}bind(e){let{modelViewProjection:r,styleIndices:n=bm,styleLayers:i=N1,styleValues:a=[],diffuseSampler:o=0,lightmapSampler:s,refractionSampler:c,surfaceFlags:l=xn,timeSeconds:u=0,texScroll:d,alpha:h,warp:m,dlights:p=[],renderMode:y,lightmapOnly:g,brightness:b=1,gamma:_=1,fullbright:x=!1,ambient:v=0}=e,w=Sd(l,u),M=_d(n,a),S=d?d[0]:w.flowOffset[0],E=d?d[1]:w.flowOffset[1],L=h!==void 0?h:w.alpha,A=m!==void 0?m:w.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,S,E),this.gl.uniform2f(this.uniformLmScroll,w.flowOffset[0],w.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,M),this.gl.uniform4fv(this.uniformStyleLayerMapping,i),this.gl.uniform1f(this.uniformAlpha,L);let R=!w.sky&&s!==void 0&&!A;this.gl.uniform1i(this.uniformApplyLightmap,R?1:0),this.gl.uniform1i(this.uniformWarp,A?1:0),this.gl.uniform1i(this.uniformLightmapOnly,g?1:0),this.gl.uniform1f(this.uniformTime,u),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,s??0),c!==void 0&&A?(this.gl.uniform1i(this.uniformRefraction,c),this.gl.uniform1i(this.uniformHasRefraction,1)):this.gl.uniform1i(this.uniformHasRefraction,0);let D=0,k=[1,1,1,1];y&&(y.mode==="solid"||y.mode==="wireframe"?D=1:y.mode==="solid-faceted"&&(D=2),y.color?k=[...y.color]:y.generateRandomColor&&(k=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,D),this.gl.uniform4f(this.uniformSolidColor,k[0],k[1],k[2],k[3]);let F=Math.min(p.length,Vr);this.gl.uniform1i(this.uniformNumDlights,F);for(let U=0;U<F;U++){let ee=p[U];this.gl.uniform3f(this.uniformDlights[U].pos,ee.origin.x,ee.origin.y,ee.origin.z),this.gl.uniform3f(this.uniformDlights[U].color,ee.color.x,ee.color.y,ee.color.z),this.gl.uniform1f(this.uniformDlights[U].intensity,ee.intensity)}return this.gl.uniform1f(this.uniformBrightness,b),this.gl.uniform1f(this.uniformGamma,_),this.gl.uniform1i(this.uniformFullbright,x?1:0),this.gl.uniform1f(this.uniformAmbient,v),w}draw(e,r){if(e.vao.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){let n=e;n.wireframeIndexBuffer=new ut(this.gl,this.gl.STATIC_DRAW);let i=_a(e.indexData);n.wireframeIndexBuffer.upload(i),n.wireframeIndexCount=i.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};function ms(t,e){t.depthMask(e.depthWrite),e.blend?(t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)):t.disable(t.BLEND)}var xm=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,-1,1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1]),wd=`#version 300 es
|
|
343
343
|
precision highp float;
|
|
344
344
|
|
|
345
345
|
layout(location = 0) in vec3 a_position;
|
|
@@ -382,7 +382,7 @@ out vec4 o_color;
|
|
|
382
382
|
|
|
383
383
|
void main() {
|
|
384
384
|
o_color = texture(u_skybox, v_direction);
|
|
385
|
-
}`,wa=class{constructor(e){
|
|
385
|
+
}`,wa=class{constructor(e){f(this,"gl");f(this,"program");f(this,"vao");f(this,"vbo");f(this,"cubemap");f(this,"uniformViewProj");f(this,"uniformScroll");f(this,"uniformSampler");this.gl=e,this.program=he.create(e,{vertex:wd,fragment:Md},{a_position:0}),this.vao=new Fe(e),this.vbo=new Be(e,e.STATIC_DRAW),this.vbo.upload(xm,e.STATIC_DRAW);let r=[{index:0,size:3,type:e.FLOAT,stride:12,offset:0}];this.vao.configureAttributes(r,this.vbo),this.uniformViewProj=this.program.getUniformLocation("u_viewProjectionNoTranslation"),this.uniformScroll=this.program.getUniformLocation("u_scroll"),this.uniformSampler=this.program.getUniformLocation("u_skybox"),this.cubemap=new xa(e),this.cubemap.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE})}get shaderSize(){return this.program.sourceSize}bind(e){let{viewProjection:r,scroll:n,textureUnit:i=0}=e;this.program.use(),this.gl.enable(this.gl.DEPTH_TEST),this.gl.depthFunc(this.gl.LEQUAL),this.gl.depthMask(!1),this.gl.disable(this.gl.CULL_FACE),this.gl.uniformMatrix4fv(this.uniformViewProj,!1,r),this.gl.uniform2f(this.uniformScroll,n[0],n[1]),this.gl.uniform1i(this.uniformSampler,i),this.cubemap.bind(i),this.vao.bind()}draw(){this.gl.drawArrays(this.gl.TRIANGLES,0,xm.length/3)}dispose(){this.vbo.dispose(),this.vao.dispose(),this.cubemap.dispose(),this.program.dispose()}};function Ma(t){let e=new Float32Array(t);return e[12]=0,e[13]=0,e[14]=0,e}function Ri(t,e=[.01,.02]){let[r,n]=e;return[r*t,n*t]}var Ed=`#version 300 es
|
|
386
386
|
precision highp float;
|
|
387
387
|
|
|
388
388
|
layout(location = 0) in vec3 a_position;
|
|
@@ -494,7 +494,7 @@ void main() {
|
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
o_color = finalColor;
|
|
497
|
-
}`;function V1(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function Ad(t,e,r){return t+(e-t)*r}function vm(t,e,r){return{x:Ad(t.x,e.x,r),y:Ad(t.y,e.y,r),z:Ad(t.z,e.z,r)}}function H1(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Ld(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(a=>{let o=n.length;for(let s=0;s<3;s+=1){let c=a.vertexIndices[s],l=a.texCoordIndices[s],u=t.texCoords[l];n.push({vertexIndex:c,texCoord:H1(u.s,u.t,t.header)})}i.push(o,o+1,o+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(a=>({vertexIndex:a.vertexIndex,texCoord:[a.s,1-a.t]}))),n.mode==="strip")for(let a=0;a<n.vertices.length-2;a+=1){let o=a%2===0,s=i+a+(o?0:1),c=i+a+(o?1:0),l=i+a+2;r.push(s,c,l)}else for(let a=1;a<n.vertices.length-1;a+=1)r.push(i,i+a,i+a+1)}return{vertices:e,indices:new Uint16Array(r)}}function Pd(t,e,r){let{frame0:n,frame1:i,lerp:a}=r,o=t.frames[n],s=t.frames[i];if(!o||!s)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,u)=>{let d=o.vertices[l.vertexIndex],f=s.vertices[l.vertexIndex];if(!d||!f)throw new Error("MD2 vertex index out of range for frame");let m=vm(d.position,f.position,a),p=V1(vm(d.normal,f.normal,a)),y=u*8;c[y]=m.x,c[y+1]=m.y,c[y+2]=m.z,c[y+3]=p.x,c[y+4]=p.y,c[y+5]=p.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var Aa=class{constructor(e,r,n){h(this,"gl");h(this,"geometry");h(this,"vertexBuffer");h(this,"indexBuffer");h(this,"vertexArray");h(this,"indexCount");h(this,"wireframeIndexBuffer");h(this,"wireframeIndexCount");this.gl=e,this.geometry=Ld(r),this.vertexBuffer=new Be(e,e.STATIC_DRAW),this.indexBuffer=new ut(e,e.STATIC_DRAW),this.vertexArray=new Fe(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=Pd(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Ea=class{constructor(e){h(this,"gl");h(this,"program");h(this,"uniformMvp");h(this,"uniformModelMatrix");h(this,"uniformLightDir");h(this,"uniformAmbient");h(this,"uniformTint");h(this,"uniformDiffuse");h(this,"uniformRenderMode");h(this,"uniformSolidColor");h(this,"uniformNumDlights");h(this,"uniformDlights",[]);h(this,"uniformBrightness");h(this,"uniformGamma");h(this,"uniformFullbright");h(this,"uniformGlobalAmbient");this.gl=e,this.program=he.create(e,{vertex:Ed,fragment:Td},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Vr;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:a=.2,tint:o=[1,1,1,1],diffuseSampler:s=0,dlights:c=[],renderMode:l,brightness:u=1,gamma:d=1,fullbright:f=!1,ambient:m=0}=e,p=new Float32Array(i),y=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,p),this.gl.uniform1f(this.uniformAmbient,a),this.gl.uniform4fv(this.uniformTint,y),this.gl.uniform1i(this.uniformDiffuse,s);let g=0,b=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?g=1:l.mode==="solid-faceted"&&(g=2),l.color?b=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,g),this.gl.uniform4f(this.uniformSolidColor,b[0],b[1],b[2],b[3]);let _=Math.min(c.length,Vr);this.gl.uniform1i(this.uniformNumDlights,_);for(let x=0;x<_;x++){let v=c[x];this.gl.uniform3f(this.uniformDlights[x].pos,v.origin.x,v.origin.y,v.origin.z),this.gl.uniform3f(this.uniformDlights[x].color,v.color.x,v.color.y,v.color.z),this.gl.uniform1f(this.uniformDlights[x].intensity,v.intensity)}this.gl.uniform1f(this.uniformBrightness,u),this.gl.uniform1f(this.uniformGamma,d),this.gl.uniform1i(this.uniformFullbright,f?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,m)}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new ut(this.gl,this.gl.STATIC_DRAW);let n=_a(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var V=1e-6,xe=typeof Float32Array<"u"?Float32Array:Array,ur=Math.random,_m="zyx";function fn(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var jL=Math.PI/180,QL=180/Math.PI;var gs={};Ni(gs,{add:()=>fb,adjoint:()=>Q1,clone:()=>X1,copy:()=>$1,create:()=>Rd,determinant:()=>J1,equals:()=>gb,exactEquals:()=>pb,frob:()=>db,fromMat2d:()=>ob,fromMat4:()=>W1,fromQuat:()=>sb,fromRotation:()=>ib,fromScaling:()=>ab,fromTranslation:()=>nb,fromValues:()=>K1,identity:()=>q1,invert:()=>j1,mul:()=>yb,multiply:()=>Sm,multiplyScalar:()=>hb,multiplyScalarAndAdd:()=>mb,normalFromMat4:()=>lb,projection:()=>cb,rotate:()=>tb,scale:()=>rb,set:()=>Y1,str:()=>ub,sub:()=>bb,subtract:()=>wm,translate:()=>eb,transpose:()=>Z1});function Rd(){var t=new xe(9);return xe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function W1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function X1(t){var e=new xe(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function $1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function K1(t,e,r,n,i,a,o,s,c){var l=new xe(9);return l[0]=t,l[1]=e,l[2]=r,l[3]=n,l[4]=i,l[5]=a,l[6]=o,l[7]=s,l[8]=c,l}function Y1(t,e,r,n,i,a,o,s,c,l){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t}function q1(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function Z1(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t}function j1(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=u*o-s*l,f=-u*a+s*c,m=l*a-o*c,p=r*d+n*f+i*m;return p?(p=1/p,t[0]=d*p,t[1]=(-u*n+i*l)*p,t[2]=(s*n-i*o)*p,t[3]=f*p,t[4]=(u*r-i*c)*p,t[5]=(-s*r+i*a)*p,t[6]=m*p,t[7]=(-l*r+n*c)*p,t[8]=(o*r-n*a)*p,t):null}function Q1(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8];return t[0]=o*u-s*l,t[1]=i*l-n*u,t[2]=n*s-i*o,t[3]=s*c-a*u,t[4]=r*u-i*c,t[5]=i*a-r*s,t[6]=a*l-o*c,t[7]=n*c-r*l,t[8]=r*o-n*a,t}function J1(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8];return e*(l*a-o*c)+r*(-l*i+o*s)+n*(c*i-a*s)}function Sm(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],f=r[0],m=r[1],p=r[2],y=r[3],g=r[4],b=r[5],_=r[6],x=r[7],v=r[8];return t[0]=f*n+m*o+p*l,t[1]=f*i+m*s+p*u,t[2]=f*a+m*c+p*d,t[3]=y*n+g*o+b*l,t[4]=y*i+g*s+b*u,t[5]=y*a+g*c+b*d,t[6]=_*n+x*o+v*l,t[7]=_*i+x*s+v*u,t[8]=_*a+x*c+v*d,t}function eb(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],f=r[0],m=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=c,t[6]=f*n+m*o+l,t[7]=f*i+m*s+u,t[8]=f*a+m*c+d,t}function tb(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],f=Math.sin(r),m=Math.cos(r);return t[0]=m*n+f*o,t[1]=m*i+f*s,t[2]=m*a+f*c,t[3]=m*o-f*n,t[4]=m*s-f*i,t[5]=m*c-f*a,t[6]=l,t[7]=u,t[8]=d,t}function rb(t,e,r){var n=r[0],i=r[1];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function nb(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=e[0],t[7]=e[1],t[8]=1,t}function ib(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function ab(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=e[1],t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function ob(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t}function sb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,c=i+i,l=r*o,u=n*o,d=n*s,f=i*o,m=i*s,p=i*c,y=a*o,g=a*s,b=a*c;return t[0]=1-d-p,t[3]=u-b,t[6]=f+g,t[1]=u+b,t[4]=1-l-p,t[7]=m-y,t[2]=f-g,t[5]=m+y,t[8]=1-l-d,t}function lb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],f=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,S=n*c-i*s,M=n*l-a*s,w=i*l-a*c,T=u*y-d*p,L=u*g-f*p,A=u*b-m*p,R=d*g-f*y,D=d*b-m*y,k=f*b-m*g,F=_*k-x*D+v*R+S*A-M*L+w*T;return F?(F=1/F,t[0]=(s*k-c*D+l*R)*F,t[1]=(c*A-o*k-l*L)*F,t[2]=(o*D-s*A+l*T)*F,t[3]=(i*D-n*k-a*R)*F,t[4]=(r*k-i*A+a*L)*F,t[5]=(n*A-r*D-a*T)*F,t[6]=(y*w-g*M+b*S)*F,t[7]=(g*v-p*w-b*x)*F,t[8]=(p*M-y*v+b*_)*F,t):null}function cb(t,e,r){return t[0]=2/e,t[1]=0,t[2]=0,t[3]=0,t[4]=-2/r,t[5]=0,t[6]=-1,t[7]=1,t[8]=1,t}function ub(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"}function db(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8])}function fb(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t}function wm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t}function hb(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t}function mb(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t}function pb(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]}function gb(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=e[0],f=e[1],m=e[2],p=e[3],y=e[4],g=e[5],b=e[6],_=e[7],x=e[8];return Math.abs(r-d)<=V*Math.max(1,Math.abs(r),Math.abs(d))&&Math.abs(n-f)<=V*Math.max(1,Math.abs(n),Math.abs(f))&&Math.abs(i-m)<=V*Math.max(1,Math.abs(i),Math.abs(m))&&Math.abs(a-p)<=V*Math.max(1,Math.abs(a),Math.abs(p))&&Math.abs(o-y)<=V*Math.max(1,Math.abs(o),Math.abs(y))&&Math.abs(s-g)<=V*Math.max(1,Math.abs(s),Math.abs(g))&&Math.abs(c-b)<=V*Math.max(1,Math.abs(c),Math.abs(b))&&Math.abs(l-_)<=V*Math.max(1,Math.abs(l),Math.abs(_))&&Math.abs(u-x)<=V*Math.max(1,Math.abs(u),Math.abs(x))}var yb=Sm,bb=wm;var I={};Ni(I,{add:()=>nx,adjoint:()=>Eb,clone:()=>vb,copy:()=>_b,create:()=>xb,decompose:()=>Hb,determinant:()=>Tb,equals:()=>sx,exactEquals:()=>ox,frob:()=>rx,fromQuat:()=>$b,fromQuat2:()=>Nb,fromRotation:()=>kb,fromRotationTranslation:()=>Em,fromRotationTranslationScale:()=>Wb,fromRotationTranslationScaleOrigin:()=>Xb,fromScaling:()=>Db,fromTranslation:()=>Ib,fromValues:()=>Sb,fromXRotation:()=>Ub,fromYRotation:()=>zb,fromZRotation:()=>Ob,frustum:()=>Kb,getRotation:()=>Vb,getScaling:()=>Tm,getTranslation:()=>Gb,identity:()=>Mm,invert:()=>Ab,lookAt:()=>Jb,mul:()=>lx,multiply:()=>Am,multiplyScalar:()=>ix,multiplyScalarAndAdd:()=>ax,ortho:()=>jb,orthoNO:()=>Pm,orthoZO:()=>Qb,perspective:()=>Yb,perspectiveFromFieldOfView:()=>Zb,perspectiveNO:()=>Lm,perspectiveZO:()=>qb,rotate:()=>Rb,rotateX:()=>Cb,rotateY:()=>Bb,rotateZ:()=>Fb,scale:()=>Pb,set:()=>wb,str:()=>tx,sub:()=>cx,subtract:()=>Rm,targetTo:()=>ex,translate:()=>Lb,transpose:()=>Mb});function xb(){var t=new xe(16);return xe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function vb(t){var e=new xe(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function _b(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Sb(t,e,r,n,i,a,o,s,c,l,u,d,f,m,p,y){var g=new xe(16);return g[0]=t,g[1]=e,g[2]=r,g[3]=n,g[4]=i,g[5]=a,g[6]=o,g[7]=s,g[8]=c,g[9]=l,g[10]=u,g[11]=d,g[12]=f,g[13]=m,g[14]=p,g[15]=y,g}function wb(t,e,r,n,i,a,o,s,c,l,u,d,f,m,p,y,g){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=m,t[13]=p,t[14]=y,t[15]=g,t}function Mm(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Mb(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Ab(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],f=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,S=n*c-i*s,M=n*l-a*s,w=i*l-a*c,T=u*y-d*p,L=u*g-f*p,A=u*b-m*p,R=d*g-f*y,D=d*b-m*y,k=f*b-m*g,F=_*k-x*D+v*R+S*A-M*L+w*T;return F?(F=1/F,t[0]=(s*k-c*D+l*R)*F,t[1]=(i*D-n*k-a*R)*F,t[2]=(y*w-g*M+b*S)*F,t[3]=(f*M-d*w-m*S)*F,t[4]=(c*A-o*k-l*L)*F,t[5]=(r*k-i*A+a*L)*F,t[6]=(g*v-p*w-b*x)*F,t[7]=(u*w-f*v+m*x)*F,t[8]=(o*D-s*A+l*T)*F,t[9]=(n*A-r*D-a*T)*F,t[10]=(p*M-y*v+b*_)*F,t[11]=(d*v-u*M-m*_)*F,t[12]=(s*L-o*R-c*T)*F,t[13]=(r*R-n*L+i*T)*F,t[14]=(y*x-p*S-g*_)*F,t[15]=(u*S-d*x+f*_)*F,t):null}function Eb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],f=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,S=n*c-i*s,M=n*l-a*s,w=i*l-a*c,T=u*y-d*p,L=u*g-f*p,A=u*b-m*p,R=d*g-f*y,D=d*b-m*y,k=f*b-m*g;return t[0]=s*k-c*D+l*R,t[1]=i*D-n*k-a*R,t[2]=y*w-g*M+b*S,t[3]=f*M-d*w-m*S,t[4]=c*A-o*k-l*L,t[5]=r*k-i*A+a*L,t[6]=g*v-p*w-b*x,t[7]=u*w-f*v+m*x,t[8]=o*D-s*A+l*T,t[9]=n*A-r*D-a*T,t[10]=p*M-y*v+b*_,t[11]=d*v-u*M-m*_,t[12]=s*L-o*R-c*T,t[13]=r*R-n*L+i*T,t[14]=y*x-p*S-g*_,t[15]=u*S-d*x+f*_,t}function Tb(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],m=t[12],p=t[13],y=t[14],g=t[15],b=e*o-r*a,_=e*s-n*a,x=r*s-n*o,v=l*p-u*m,S=l*y-d*m,M=u*y-d*p,w=e*M-r*S+n*v,T=a*M-o*S+s*v,L=l*x-u*_+d*b,A=m*x-p*_+y*b;return c*w-i*T+g*L-f*A}function Am(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],f=e[9],m=e[10],p=e[11],y=e[12],g=e[13],b=e[14],_=e[15],x=r[0],v=r[1],S=r[2],M=r[3];return t[0]=x*n+v*s+S*d+M*y,t[1]=x*i+v*c+S*f+M*g,t[2]=x*a+v*l+S*m+M*b,t[3]=x*o+v*u+S*p+M*_,x=r[4],v=r[5],S=r[6],M=r[7],t[4]=x*n+v*s+S*d+M*y,t[5]=x*i+v*c+S*f+M*g,t[6]=x*a+v*l+S*m+M*b,t[7]=x*o+v*u+S*p+M*_,x=r[8],v=r[9],S=r[10],M=r[11],t[8]=x*n+v*s+S*d+M*y,t[9]=x*i+v*c+S*f+M*g,t[10]=x*a+v*l+S*m+M*b,t[11]=x*o+v*u+S*p+M*_,x=r[12],v=r[13],S=r[14],M=r[15],t[12]=x*n+v*s+S*d+M*y,t[13]=x*i+v*c+S*f+M*g,t[14]=x*a+v*l+S*m+M*b,t[15]=x*o+v*u+S*p+M*_,t}function Lb(t,e,r){var n=r[0],i=r[1],a=r[2],o,s,c,l,u,d,f,m,p,y,g,b;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*a+e[12],t[13]=e[1]*n+e[5]*i+e[9]*a+e[13],t[14]=e[2]*n+e[6]*i+e[10]*a+e[14],t[15]=e[3]*n+e[7]*i+e[11]*a+e[15]):(o=e[0],s=e[1],c=e[2],l=e[3],u=e[4],d=e[5],f=e[6],m=e[7],p=e[8],y=e[9],g=e[10],b=e[11],t[0]=o,t[1]=s,t[2]=c,t[3]=l,t[4]=u,t[5]=d,t[6]=f,t[7]=m,t[8]=p,t[9]=y,t[10]=g,t[11]=b,t[12]=o*n+u*i+p*a+e[12],t[13]=s*n+d*i+y*a+e[13],t[14]=c*n+f*i+g*a+e[14],t[15]=l*n+m*i+b*a+e[15]),t}function Pb(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Rb(t,e,r,n){var i=n[0],a=n[1],o=n[2],s=Math.sqrt(i*i+a*a+o*o),c,l,u,d,f,m,p,y,g,b,_,x,v,S,M,w,T,L,A,R,D,k,F,U;return s<V?null:(s=1/s,i*=s,a*=s,o*=s,c=Math.sin(r),l=Math.cos(r),u=1-l,d=e[0],f=e[1],m=e[2],p=e[3],y=e[4],g=e[5],b=e[6],_=e[7],x=e[8],v=e[9],S=e[10],M=e[11],w=i*i*u+l,T=a*i*u+o*c,L=o*i*u-a*c,A=i*a*u-o*c,R=a*a*u+l,D=o*a*u+i*c,k=i*o*u+a*c,F=a*o*u-i*c,U=o*o*u+l,t[0]=d*w+y*T+x*L,t[1]=f*w+g*T+v*L,t[2]=m*w+b*T+S*L,t[3]=p*w+_*T+M*L,t[4]=d*A+y*R+x*D,t[5]=f*A+g*R+v*D,t[6]=m*A+b*R+S*D,t[7]=p*A+_*R+M*D,t[8]=d*k+y*F+x*U,t[9]=f*k+g*F+v*U,t[10]=m*k+b*F+S*U,t[11]=p*k+_*F+M*U,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Cb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=a*i+l*n,t[5]=o*i+u*n,t[6]=s*i+d*n,t[7]=c*i+f*n,t[8]=l*i-a*n,t[9]=u*i-o*n,t[10]=d*i-s*n,t[11]=f*i-c*n,t}function Bb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],c=e[3],l=e[8],u=e[9],d=e[10],f=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i-l*n,t[1]=o*i-u*n,t[2]=s*i-d*n,t[3]=c*i-f*n,t[8]=a*n+l*i,t[9]=o*n+u*i,t[10]=s*n+d*i,t[11]=c*n+f*i,t}function Fb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],c=e[3],l=e[4],u=e[5],d=e[6],f=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i+l*n,t[1]=o*i+u*n,t[2]=s*i+d*n,t[3]=c*i+f*n,t[4]=l*i-a*n,t[5]=u*i-o*n,t[6]=d*i-s*n,t[7]=f*i-c*n,t}function Ib(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function Db(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function kb(t,e,r){var n=r[0],i=r[1],a=r[2],o=Math.sqrt(n*n+i*i+a*a),s,c,l;return o<V?null:(o=1/o,n*=o,i*=o,a*=o,s=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=i*n*l+a*s,t[2]=a*n*l-i*s,t[3]=0,t[4]=n*i*l-a*s,t[5]=i*i*l+c,t[6]=a*i*l+n*s,t[7]=0,t[8]=n*a*l+i*s,t[9]=i*a*l-n*s,t[10]=a*a*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Ub(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function zb(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Ob(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Em(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=n+n,c=i+i,l=a+a,u=n*s,d=n*c,f=n*l,m=i*c,p=i*l,y=a*l,g=o*s,b=o*c,_=o*l;return t[0]=1-(m+y),t[1]=d+_,t[2]=f-b,t[3]=0,t[4]=d-_,t[5]=1-(u+y),t[6]=p+g,t[7]=0,t[8]=f+b,t[9]=p-g,t[10]=1-(u+m),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Nb(t,e){var r=new xe(3),n=-e[0],i=-e[1],a=-e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=n*n+i*i+a*a+o*o;return d>0?(r[0]=(s*o+u*n+c*a-l*i)*2/d,r[1]=(c*o+u*i+l*n-s*a)*2/d,r[2]=(l*o+u*a+s*i-c*n)*2/d):(r[0]=(s*o+u*n+c*a-l*i)*2,r[1]=(c*o+u*i+l*n-s*a)*2,r[2]=(l*o+u*a+s*i-c*n)*2),Em(t,e,r),t}function Gb(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Tm(t,e){var r=e[0],n=e[1],i=e[2],a=e[4],o=e[5],s=e[6],c=e[8],l=e[9],u=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(a*a+o*o+s*s),t[2]=Math.sqrt(c*c+l*l+u*u),t}function Vb(t,e){var r=new xe(3);Tm(r,e);var n=1/r[0],i=1/r[1],a=1/r[2],o=e[0]*n,s=e[1]*i,c=e[2]*a,l=e[4]*n,u=e[5]*i,d=e[6]*a,f=e[8]*n,m=e[9]*i,p=e[10]*a,y=o+u+p,g=0;return y>0?(g=Math.sqrt(y+1)*2,t[3]=.25*g,t[0]=(d-m)/g,t[1]=(f-c)/g,t[2]=(s-l)/g):o>u&&o>p?(g=Math.sqrt(1+o-u-p)*2,t[3]=(d-m)/g,t[0]=.25*g,t[1]=(s+l)/g,t[2]=(f+c)/g):u>p?(g=Math.sqrt(1+u-o-p)*2,t[3]=(f-c)/g,t[0]=(s+l)/g,t[1]=.25*g,t[2]=(d+m)/g):(g=Math.sqrt(1+p-o-u)*2,t[3]=(s-l)/g,t[0]=(f+c)/g,t[1]=(d+m)/g,t[2]=.25*g),t}function Hb(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],a=n[1],o=n[2],s=n[4],c=n[5],l=n[6],u=n[8],d=n[9],f=n[10];r[0]=Math.sqrt(i*i+a*a+o*o),r[1]=Math.sqrt(s*s+c*c+l*l),r[2]=Math.sqrt(u*u+d*d+f*f);var m=1/r[0],p=1/r[1],y=1/r[2],g=i*m,b=a*p,_=o*y,x=s*m,v=c*p,S=l*y,M=u*m,w=d*p,T=f*y,L=g+v+T,A=0;return L>0?(A=Math.sqrt(L+1)*2,t[3]=.25*A,t[0]=(S-w)/A,t[1]=(M-_)/A,t[2]=(b-x)/A):g>v&&g>T?(A=Math.sqrt(1+g-v-T)*2,t[3]=(S-w)/A,t[0]=.25*A,t[1]=(b+x)/A,t[2]=(M+_)/A):v>T?(A=Math.sqrt(1+v-g-T)*2,t[3]=(M-_)/A,t[0]=(b+x)/A,t[1]=.25*A,t[2]=(S+w)/A):(A=Math.sqrt(1+T-g-v)*2,t[3]=(b-x)/A,t[0]=(M+_)/A,t[1]=(S+w)/A,t[2]=.25*A),t}function Wb(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3],c=i+i,l=a+a,u=o+o,d=i*c,f=i*l,m=i*u,p=a*l,y=a*u,g=o*u,b=s*c,_=s*l,x=s*u,v=n[0],S=n[1],M=n[2];return t[0]=(1-(p+g))*v,t[1]=(f+x)*v,t[2]=(m-_)*v,t[3]=0,t[4]=(f-x)*S,t[5]=(1-(d+g))*S,t[6]=(y+b)*S,t[7]=0,t[8]=(m+_)*M,t[9]=(y-b)*M,t[10]=(1-(d+p))*M,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Xb(t,e,r,n,i){var a=e[0],o=e[1],s=e[2],c=e[3],l=a+a,u=o+o,d=s+s,f=a*l,m=a*u,p=a*d,y=o*u,g=o*d,b=s*d,_=c*l,x=c*u,v=c*d,S=n[0],M=n[1],w=n[2],T=i[0],L=i[1],A=i[2],R=(1-(y+b))*S,D=(m+v)*S,k=(p-x)*S,F=(m-v)*M,U=(1-(f+b))*M,ee=(g+_)*M,He=(p+x)*w,We=(g-_)*w,Ae=(1-(f+y))*w;return t[0]=R,t[1]=D,t[2]=k,t[3]=0,t[4]=F,t[5]=U,t[6]=ee,t[7]=0,t[8]=He,t[9]=We,t[10]=Ae,t[11]=0,t[12]=r[0]+T-(R*T+F*L+He*A),t[13]=r[1]+L-(D*T+U*L+We*A),t[14]=r[2]+A-(k*T+ee*L+Ae*A),t[15]=1,t}function $b(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,c=i+i,l=r*o,u=n*o,d=n*s,f=i*o,m=i*s,p=i*c,y=a*o,g=a*s,b=a*c;return t[0]=1-d-p,t[1]=u+b,t[2]=f-g,t[3]=0,t[4]=u-b,t[5]=1-l-p,t[6]=m+y,t[7]=0,t[8]=f+g,t[9]=m-y,t[10]=1-l-d,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Kb(t,e,r,n,i,a,o){var s=1/(r-e),c=1/(i-n),l=1/(a-o);return t[0]=a*2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*s,t[9]=(i+n)*c,t[10]=(o+a)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*a*2*l,t[15]=0,t}function Lm(t,e,r,n,i){var a=1/Math.tan(e/2);if(t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=(i+n)*o,t[14]=2*i*n*o}else t[10]=-1,t[14]=-2*n;return t}var Yb=Lm;function qb(t,e,r,n,i){var a=1/Math.tan(e/2);if(t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=i*o,t[14]=i*n*o}else t[10]=-1,t[14]=-n;return t}function Zb(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),a=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),s=Math.tan(e.rightDegrees*Math.PI/180),c=2/(o+s),l=2/(i+a);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((o-s)*c*.5),t[9]=(i-a)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Pm(t,e,r,n,i,a,o){var s=1/(e-r),c=1/(n-i),l=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*c,t[14]=(o+a)*l,t[15]=1,t}var jb=Pm;function Qb(t,e,r,n,i,a,o){var s=1/(e-r),c=1/(n-i),l=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*c,t[14]=a*l,t[15]=1,t}function Jb(t,e,r,n){var i,a,o,s,c,l,u,d,f,m,p=e[0],y=e[1],g=e[2],b=n[0],_=n[1],x=n[2],v=r[0],S=r[1],M=r[2];return Math.abs(p-v)<V&&Math.abs(y-S)<V&&Math.abs(g-M)<V?Mm(t):(u=p-v,d=y-S,f=g-M,m=1/Math.sqrt(u*u+d*d+f*f),u*=m,d*=m,f*=m,i=_*f-x*d,a=x*u-b*f,o=b*d-_*u,m=Math.sqrt(i*i+a*a+o*o),m?(m=1/m,i*=m,a*=m,o*=m):(i=0,a=0,o=0),s=d*o-f*a,c=f*i-u*o,l=u*a-d*i,m=Math.sqrt(s*s+c*c+l*l),m?(m=1/m,s*=m,c*=m,l*=m):(s=0,c=0,l=0),t[0]=i,t[1]=s,t[2]=u,t[3]=0,t[4]=a,t[5]=c,t[6]=d,t[7]=0,t[8]=o,t[9]=l,t[10]=f,t[11]=0,t[12]=-(i*p+a*y+o*g),t[13]=-(s*p+c*y+l*g),t[14]=-(u*p+d*y+f*g),t[15]=1,t)}function ex(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=n[0],c=n[1],l=n[2],u=i-r[0],d=a-r[1],f=o-r[2],m=u*u+d*d+f*f;m>0&&(m=1/Math.sqrt(m),u*=m,d*=m,f*=m);var p=c*f-l*d,y=l*u-s*f,g=s*d-c*u;return m=p*p+y*y+g*g,m>0&&(m=1/Math.sqrt(m),p*=m,y*=m,g*=m),t[0]=p,t[1]=y,t[2]=g,t[3]=0,t[4]=d*g-f*y,t[5]=f*p-u*g,t[6]=u*y-d*p,t[7]=0,t[8]=u,t[9]=d,t[10]=f,t[11]=0,t[12]=i,t[13]=a,t[14]=o,t[15]=1,t}function tx(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function rx(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function nx(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function Rm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function ix(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function ax(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function ox(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function sx(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],m=t[11],p=t[12],y=t[13],g=t[14],b=t[15],_=e[0],x=e[1],v=e[2],S=e[3],M=e[4],w=e[5],T=e[6],L=e[7],A=e[8],R=e[9],D=e[10],k=e[11],F=e[12],U=e[13],ee=e[14],He=e[15];return Math.abs(r-_)<=V*Math.max(1,Math.abs(r),Math.abs(_))&&Math.abs(n-x)<=V*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-v)<=V*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(a-S)<=V*Math.max(1,Math.abs(a),Math.abs(S))&&Math.abs(o-M)<=V*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(s-w)<=V*Math.max(1,Math.abs(s),Math.abs(w))&&Math.abs(c-T)<=V*Math.max(1,Math.abs(c),Math.abs(T))&&Math.abs(l-L)<=V*Math.max(1,Math.abs(l),Math.abs(L))&&Math.abs(u-A)<=V*Math.max(1,Math.abs(u),Math.abs(A))&&Math.abs(d-R)<=V*Math.max(1,Math.abs(d),Math.abs(R))&&Math.abs(f-D)<=V*Math.max(1,Math.abs(f),Math.abs(D))&&Math.abs(m-k)<=V*Math.max(1,Math.abs(m),Math.abs(k))&&Math.abs(p-F)<=V*Math.max(1,Math.abs(p),Math.abs(F))&&Math.abs(y-U)<=V*Math.max(1,Math.abs(y),Math.abs(U))&&Math.abs(g-ee)<=V*Math.max(1,Math.abs(g),Math.abs(ee))&&Math.abs(b-He)<=V*Math.max(1,Math.abs(b),Math.abs(He))}var lx=Am,cx=Rm;var yc={};Ni(yc,{add:()=>Bv,calculateW:()=>_v,clone:()=>Lv,conjugate:()=>Av,copy:()=>Rv,create:()=>Vd,dot:()=>Zm,equals:()=>zv,exactEquals:()=>Uv,exp:()=>$m,fromEuler:()=>Ev,fromMat3:()=>Ym,fromValues:()=>Pv,getAngle:()=>yv,getAxisAngle:()=>gv,identity:()=>pv,invert:()=>Mv,len:()=>Dv,length:()=>jm,lerp:()=>Iv,ln:()=>Km,mul:()=>Fv,multiply:()=>Xm,normalize:()=>Hd,pow:()=>Sv,random:()=>wv,rotateX:()=>bv,rotateY:()=>xv,rotateZ:()=>vv,rotationTo:()=>Ov,scale:()=>qm,set:()=>Cv,setAxes:()=>Gv,setAxisAngle:()=>Wm,slerp:()=>gc,sqlerp:()=>Nv,sqrLen:()=>kv,squaredLength:()=>Qm,str:()=>Tv});var P={};Ni(P,{add:()=>hx,angle:()=>Ix,bezier:()=>Ex,ceil:()=>mx,clone:()=>ux,copy:()=>dx,create:()=>dc,cross:()=>bs,dist:()=>Vx,distance:()=>Dm,div:()=>Gx,divide:()=>Im,dot:()=>ys,equals:()=>zx,exactEquals:()=>Ux,floor:()=>px,forEach:()=>Xx,fromValues:()=>fc,hermite:()=>Ax,inverse:()=>Sx,len:()=>Bd,length:()=>Cm,lerp:()=>wx,max:()=>yx,min:()=>gx,mul:()=>Nx,multiply:()=>Fm,negate:()=>_x,normalize:()=>Cd,random:()=>Tx,rotateX:()=>Cx,rotateY:()=>Bx,rotateZ:()=>Fx,round:()=>bx,scale:()=>xx,scaleAndAdd:()=>vx,set:()=>fx,slerp:()=>Mx,sqrDist:()=>Hx,sqrLen:()=>Wx,squaredDistance:()=>km,squaredLength:()=>Um,str:()=>kx,sub:()=>Ox,subtract:()=>Bm,transformMat3:()=>Px,transformMat4:()=>Lx,transformQuat:()=>Rx,zero:()=>Dx});function dc(){var t=new xe(3);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ux(t){var e=new xe(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Cm(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function fc(t,e,r){var n=new xe(3);return n[0]=t,n[1]=e,n[2]=r,n}function dx(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function fx(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function hx(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Bm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Fm(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Im(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function mx(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function px(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function gx(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function yx(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function bx(t,e){return t[0]=fn(e[0]),t[1]=fn(e[1]),t[2]=fn(e[2]),t}function xx(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function vx(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function Dm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function km(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function Um(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function _x(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Sx(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function Cd(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a)),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a,t}function ys(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function bs(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],c=r[2];return t[0]=i*c-a*s,t[1]=a*o-n*c,t[2]=n*s-i*o,t}function wx(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t}function Mx(t,e,r,n){var i=Math.acos(Math.min(Math.max(ys(e,r),-1),1)),a=Math.sin(i),o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a;return t[0]=o*e[0]+s*r[0],t[1]=o*e[1]+s*r[1],t[2]=o*e[2]+s*r[2],t}function Ax(t,e,r,n,i,a){var o=a*a,s=o*(2*a-3)+1,c=o*(a-2)+a,l=o*(a-1),u=o*(3-2*a);return t[0]=e[0]*s+r[0]*c+n[0]*l+i[0]*u,t[1]=e[1]*s+r[1]*c+n[1]*l+i[1]*u,t[2]=e[2]*s+r[2]*c+n[2]*l+i[2]*u,t}function Ex(t,e,r,n,i,a){var o=1-a,s=o*o,c=a*a,l=s*o,u=3*a*s,d=3*c*o,f=c*a;return t[0]=e[0]*l+r[0]*u+n[0]*d+i[0]*f,t[1]=e[1]*l+r[1]*u+n[1]*d+i[1]*f,t[2]=e[2]*l+r[2]*u+n[2]*d+i[2]*f,t}function Tx(t,e){e=e===void 0?1:e;var r=ur()*2*Math.PI,n=ur()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function Lx(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[3]*n+r[7]*i+r[11]*a+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/o,t}function Px(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t}function Rx(t,e,r){var n=r[0],i=r[1],a=r[2],o=r[3],s=e[0],c=e[1],l=e[2],u=i*l-a*c,d=a*s-n*l,f=n*c-i*s;return u=u+u,d=d+d,f=f+f,t[0]=s+o*u+i*f-a*d,t[1]=c+o*d+a*u-n*f,t[2]=l+o*f+n*d-i*u,t}function Cx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Bx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Fx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Ix(t,e){var r=t[0],n=t[1],i=t[2],a=e[0],o=e[1],s=e[2],c=Math.sqrt((r*r+n*n+i*i)*(a*a+o*o+s*s)),l=c&&ys(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function Dx(t){return t[0]=0,t[1]=0,t[2]=0,t}function kx(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Ux(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function zx(t,e){var r=t[0],n=t[1],i=t[2],a=e[0],o=e[1],s=e[2];return Math.abs(r-a)<=V*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(n-o)<=V*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-s)<=V*Math.max(1,Math.abs(i),Math.abs(s))}var Ox=Bm,Nx=Fm,Gx=Im,Vx=Dm,Hx=km,Bd=Cm,Wx=Um,Xx=(function(){var t=dc();return function(e,r,n,i,a,o){var s,c;for(r||(r=3),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,s=n;s<c;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}})();var Ta={};Ni(Ta,{add:()=>Ud,ceil:()=>$x,clone:()=>Fd,copy:()=>Dd,create:()=>zm,cross:()=>ev,dist:()=>uv,distance:()=>Vm,div:()=>cv,divide:()=>Gm,dot:()=>pc,equals:()=>ov,exactEquals:()=>Gd,floor:()=>Kx,forEach:()=>mv,fromValues:()=>Id,inverse:()=>Jx,len:()=>fv,length:()=>hc,lerp:()=>Nd,max:()=>qx,min:()=>Yx,mul:()=>lv,multiply:()=>Nm,negate:()=>Qx,normalize:()=>Od,random:()=>tv,round:()=>Zx,scale:()=>zd,scaleAndAdd:()=>jx,set:()=>kd,sqrDist:()=>dv,sqrLen:()=>hv,squaredDistance:()=>Hm,squaredLength:()=>mc,str:()=>av,sub:()=>sv,subtract:()=>Om,transformMat4:()=>rv,transformQuat:()=>nv,zero:()=>iv});function zm(){var t=new xe(4);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function Fd(t){var e=new xe(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function Id(t,e,r,n){var i=new xe(4);return i[0]=t,i[1]=e,i[2]=r,i[3]=n,i}function Dd(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function kd(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}function Ud(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t}function Om(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t}function Nm(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t}function Gm(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t}function $x(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t}function Kx(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t}function Yx(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t}function qx(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t}function Zx(t,e){return t[0]=fn(e[0]),t[1]=fn(e[1]),t[2]=fn(e[2]),t[3]=fn(e[3]),t}function zd(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t}function jx(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t}function Vm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)}function Hm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a}function hc(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)}function mc(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i}function Qx(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}function Jx(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}function Od(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),t[0]=r*o,t[1]=n*o,t[2]=i*o,t[3]=a*o,t}function pc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function ev(t,e,r,n){var i=r[0]*n[1]-r[1]*n[0],a=r[0]*n[2]-r[2]*n[0],o=r[0]*n[3]-r[3]*n[0],s=r[1]*n[2]-r[2]*n[1],c=r[1]*n[3]-r[3]*n[1],l=r[2]*n[3]-r[3]*n[2],u=e[0],d=e[1],f=e[2],m=e[3];return t[0]=d*l-f*c+m*s,t[1]=-(u*l)+f*o-m*a,t[2]=u*c-d*o+m*i,t[3]=-(u*s)+d*a-f*i,t}function Nd(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t}function tv(t,e){e=e===void 0?1:e;var r,n,i,a,o,s,c;c=ur(),r=c*2-1,n=(4*ur()-2)*Math.sqrt(c*-c+c),o=r*r+n*n,c=ur(),i=c*2-1,a=(4*ur()-2)*Math.sqrt(c*-c+c),s=i*i+a*a;var l=Math.sqrt((1-o)/s);return t[0]=e*r,t[1]=e*n,t[2]=e*i*l,t[3]=e*a*l,t}function rv(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t}function nv(t,e,r){var n=r[0],i=r[1],a=r[2],o=r[3],s=e[0],c=e[1],l=e[2],u=i*l-a*c,d=a*s-n*l,f=n*c-i*s;return u=u+u,d=d+d,f=f+f,t[0]=s+o*u+i*f-a*d,t[1]=c+o*d+a*u-n*f,t[2]=l+o*f+n*d-i*u,t[3]=e[3],t}function iv(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}function av(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}function Gd(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function ov(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=e[0],s=e[1],c=e[2],l=e[3];return Math.abs(r-o)<=V*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-s)<=V*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(i-c)<=V*Math.max(1,Math.abs(i),Math.abs(c))&&Math.abs(a-l)<=V*Math.max(1,Math.abs(a),Math.abs(l))}var sv=Om,lv=Nm,cv=Gm,uv=Vm,dv=Hm,fv=hc,hv=mc,mv=(function(){var t=zm();return function(e,r,n,i,a,o){var s,c;for(r||(r=4),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,s=n;s<c;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}})();function Vd(){var t=new xe(4);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function pv(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Wm(t,e,r){r=r*.5;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t}function gv(t,e){var r=Math.acos(e[3])*2,n=Math.sin(r/2);return n>V?(t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n):(t[0]=1,t[1]=0,t[2]=0),r}function yv(t,e){var r=Zm(t,e);return Math.acos(2*r*r-1)}function Xm(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],c=r[1],l=r[2],u=r[3];return t[0]=n*u+o*s+i*l-a*c,t[1]=i*u+o*c+a*s-n*l,t[2]=a*u+o*l+n*c-i*s,t[3]=o*u-n*s-i*c-a*l,t}function bv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c+o*s,t[1]=i*c+a*s,t[2]=a*c-i*s,t[3]=o*c-n*s,t}function xv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c-a*s,t[1]=i*c+o*s,t[2]=a*c+n*s,t[3]=o*c-i*s,t}function vv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c+i*s,t[1]=i*c-n*s,t[2]=a*c+o*s,t[3]=o*c-a*s,t}function _v(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t}function $m(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=Math.sqrt(r*r+n*n+i*i),s=Math.exp(a),c=o>0?s*Math.sin(o)/o:0;return t[0]=r*c,t[1]=n*c,t[2]=i*c,t[3]=s*Math.cos(o),t}function Km(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=Math.sqrt(r*r+n*n+i*i),s=o>0?Math.atan2(o,a)/o:0;return t[0]=r*s,t[1]=n*s,t[2]=i*s,t[3]=.5*Math.log(r*r+n*n+i*i+a*a),t}function Sv(t,e,r){return Km(t,e),qm(t,t,r),$m(t,t),t}function gc(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3],c=r[0],l=r[1],u=r[2],d=r[3],f,m,p,y,g;return m=i*c+a*l+o*u+s*d,m<0&&(m=-m,c=-c,l=-l,u=-u,d=-d),1-m>V?(f=Math.acos(m),p=Math.sin(f),y=Math.sin((1-n)*f)/p,g=Math.sin(n*f)/p):(y=1-n,g=n),t[0]=y*i+g*c,t[1]=y*a+g*l,t[2]=y*o+g*u,t[3]=y*s+g*d,t}function wv(t){var e=ur(),r=ur(),n=ur(),i=Math.sqrt(1-e),a=Math.sqrt(e);return t[0]=i*Math.sin(2*Math.PI*r),t[1]=i*Math.cos(2*Math.PI*r),t[2]=a*Math.sin(2*Math.PI*n),t[3]=a*Math.cos(2*Math.PI*n),t}function Mv(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t}function Av(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function Ym(t,e){var r=e[0]+e[4]+e[8],n;if(r>0)n=Math.sqrt(r+1),t[3]=.5*n,n=.5/n,t[0]=(e[5]-e[7])*n,t[1]=(e[6]-e[2])*n,t[2]=(e[1]-e[3])*n;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[i*3+i]&&(i=2);var a=(i+1)%3,o=(i+2)%3;n=Math.sqrt(e[i*3+i]-e[a*3+a]-e[o*3+o]+1),t[i]=.5*n,n=.5/n,t[3]=(e[a*3+o]-e[o*3+a])*n,t[a]=(e[a*3+i]+e[i*3+a])*n,t[o]=(e[o*3+i]+e[i*3+o])*n}return t}function Ev(t,e,r,n){var i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:_m,a=Math.PI/360;e*=a,n*=a,r*=a;var o=Math.sin(e),s=Math.cos(e),c=Math.sin(r),l=Math.cos(r),u=Math.sin(n),d=Math.cos(n);switch(i){case"xyz":t[0]=o*l*d+s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d-o*c*u;break;case"xzy":t[0]=o*l*d-s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d+o*c*u;break;case"yxz":t[0]=o*l*d+s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d+o*c*u;break;case"yzx":t[0]=o*l*d+s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d-o*c*u;break;case"zxy":t[0]=o*l*d-s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d-o*c*u;break;case"zyx":t[0]=o*l*d-s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d+o*c*u;break;default:throw new Error("Unknown angle order "+i)}return t}function Tv(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}var Lv=Fd,Pv=Id,Rv=Dd,Cv=kd,Bv=Ud,Fv=Xm,qm=zd,Zm=pc,Iv=Nd,jm=hc,Dv=jm,Qm=mc,kv=Qm,Hd=Od,Uv=Gd;function zv(t,e){return Math.abs(pc(t,e))>=1-V}var Ov=(function(){var t=dc(),e=fc(1,0,0),r=fc(0,1,0);return function(n,i,a){var o=ys(i,a);return o<-.999999?(bs(t,e,i),Bd(t)<1e-6&&bs(t,r,i),Cd(t,t),Wm(n,t,Math.PI),n):o>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(bs(t,i,a),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=1+o,Hd(n,n))}})(),Nv=(function(){var t=Vd(),e=Vd();return function(r,n,i,a,o,s){return gc(t,n,o,s),gc(e,i,a,s),gc(r,t,e,2*s*(1-s)),r}})(),Gv=(function(){var t=Rd();return function(e,r,n,i){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],Hd(e,Ym(e,t))}})();var bc=class{constructor(e,r){h(this,"_position",P.create());h(this,"_angles",P.create());h(this,"_bobAngles",P.create());h(this,"_bobOffset",P.create());h(this,"_kickAngles",P.create());h(this,"_rollAngle",0);h(this,"_fov",90);h(this,"_aspect",1);h(this,"_near",.1);h(this,"_far",1e3);h(this,"_viewMatrix",I.create());h(this,"_projectionMatrix",I.create());h(this,"_viewProjectionMatrix",I.create());h(this,"_dirty",!0);h(this,"onCameraMove");e!==void 0&&r!==void 0&&r>0&&(this._aspect=e/r)}get position(){return this._position}set position(e){P.equals(this._position,e)||(P.copy(this._position,e),this._dirty=!0,this.triggerMoveEvent())}get angles(){return this._angles}set angles(e){P.equals(this._angles,e)||(P.copy(this._angles,e),this._dirty=!0,this.triggerMoveEvent())}get bobAngles(){return this._bobAngles}set bobAngles(e){P.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){P.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){P.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}toState(){return{position:P.clone(this._position),angles:P.clone(this._angles),fov:this._fov,aspect:this._aspect,near:this._near,far:this._far}}setPosition(e,r,n){let i=P.fromValues(e,r,n);P.equals(this._position,i)||(P.copy(this._position,i),this._dirty=!0,this.triggerMoveEvent())}setRotation(e,r,n){let i=P.fromValues(e,r,n);P.equals(this._angles,i)||(P.copy(this._angles,i),this._dirty=!0,this.triggerMoveEvent())}setFov(e){this.fov=e}setAspectRatio(e){this.aspect=e}lookAt(e){let r=P.create();if(P.subtract(r,e,this._position),P.length(r)<.001)return;let i=Math.atan2(r[1],r[0])*yu,a=Math.hypot(r[0],r[1]),o=-Math.atan2(r[2],a)*yu;this.setRotation(o,i,0)}triggerMoveEvent(){this.onCameraMove&&this.onCameraMove({position:P.clone(this._position),angles:P.clone(this._angles)})}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=I.create();return I.perspective(r,e*Ee,this._aspect,this._near,this._far),r}screenToWorldRay(e,r){let n=e*2-1,i=1-r*2,a=P.fromValues(n,i,-1),o=P.fromValues(n,i,1),s=I.create();I.invert(s,this.viewProjectionMatrix);let c=P.create(),l=P.create();P.transformMat4(c,a,s),P.transformMat4(l,o,s);let u=P.create();return P.subtract(u,l,c),P.normalize(u,u),{origin:P.clone(this._position),direction:u}}updateMatrices(){if(!this._dirty)return;I.perspective(this._projectionMatrix,this._fov*Ee,this._aspect,this._near,this._far);let e=I.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,a=r*Ee,o=n*Ee,s=i*Ee,c=I.create();I.identity(c),I.rotateZ(c,c,-o),I.rotateY(c,c,-a),I.rotateX(c,c,-s);let l=I.create();I.multiply(l,e,c);let u=P.add(P.create(),this._position,this._bobOffset),d=P.negate(P.create(),u),f=P.create();P.transformMat4(f,d,c);let m=P.fromValues(f[1]?-f[1]:0,f[2]||0,f[0]?-f[0]:0);I.copy(this._viewMatrix,l),this._viewMatrix[12]=m[0],this._viewMatrix[13]=m[1],this._viewMatrix[14]=m[2],I.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Vv=[.2,.2,.2],Hv={x:0,y:0,z:1},Wv=[.8,.8,.8];function Wd(t,e,r){return t+(e-t)*r}function Pa(t,e,r){return{x:Wd(t.x,e.x,r),y:Wd(t.y,e.y,r),z:Wd(t.z,e.z,r)}}function La(t){return t<0?0:t>1?1:t}function Xd(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[a,o,s]=n.indices,c=t.texCoords[a],l=t.texCoords[o],u=t.texCoords[s];if(!c||!l||!u)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:a,texCoord:[c.s,1-c.t]},{vertexIndex:o,texCoord:[l.s,1-l.t]},{vertexIndex:s,texCoord:[u.s,1-u.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Xv(t,e,r){let n=r?.ambient??Vv,i=r?.directional??{direction:Hv,color:Wv},a=qr(t),o=qr(i.direction),s=La(a.x*o.x+a.y*o.y+a.z*o.z),c=n[0]+i.color[0]*s,l=n[1]+i.color[1]*s,u=n[2]+i.color[2]*s;if(r?.dynamicLights){let d=r.modelMatrix?th(r.modelMatrix,e):e;for(let f of r.dynamicLights){let m=d.x-f.origin.x,p=d.y-f.origin.y,y=d.z-f.origin.z,g=m*m+p*p+y*y,b=f.radius*f.radius;if(g<b&&b>0){let _=1-Math.sqrt(g)/f.radius,x=Math.sqrt(g),v=x>0?La(-(m*a.x+p*a.y+y*a.z)/x):0,S=La(_*v);c+=f.color[0]*S,l+=f.color[1]*S,u+=f.color[2]*S}}}return[La(c),La(l),La(u)]}function $d(t,e,r,n){let i=t.vertices[r.frame0],a=t.vertices[r.frame1];if(!i||!a)throw new Error("Requested MD3 frames are out of range");let o=new Float32Array(e.vertices.length*12);return e.vertices.forEach((s,c)=>{let l=i[s.vertexIndex],u=a[s.vertexIndex];if(!l||!u)throw new Error(`Vertex index ${s.vertexIndex} missing for frame`);let d=Pa(l.position,u.position,r.lerp),f=qr(Pa(l.normal,u.normal,r.lerp)),m=Xv(f,d,n),p=c*12;o[p]=d.x,o[p+1]=d.y,o[p+2]=d.z,o[p+3]=f.x,o[p+4]=f.y,o[p+5]=f.z,o[p+6]=s.texCoord[0],o[p+7]=s.texCoord[1],o[p+8]=m[0],o[p+9]=m[1],o[p+10]=m[2],o[p+11]=1}),o}function Jm(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(y=>y.name===r);if(i===-1)return null;let a=t.tags[e.frame0]?.[i],o=t.tags[e.frame1]?.[i];if(!a||!o)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let s=Pa(a.origin,o.origin,e.lerp),c=qr(Pa(a.axis[0],o.axis[0],e.lerp)),l=qr(Pa(a.axis[1],o.axis[1],e.lerp)),u=qr(Pa(a.axis[2],o.axis[2],e.lerp)),d=c,f=qr({x:l.x-d.x*(d.x*l.x+d.y*l.y+d.z*l.z),y:l.y-d.y*(d.x*l.x+d.y*l.y+d.z*l.z),z:l.z-d.z*(d.x*l.x+d.y*l.y+d.z*l.z)}),m=qr({x:d.y*f.z-d.z*f.y,y:d.z*f.x-d.x*f.z,z:d.x*f.y-d.y*f.x}),p=[d,f,m];return{origin:s,axis:p,matrix:rh(s,p)}}var Kd=`#version 300 es
|
|
497
|
+
}`;function V1(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function Ad(t,e,r){return t+(e-t)*r}function vm(t,e,r){return{x:Ad(t.x,e.x,r),y:Ad(t.y,e.y,r),z:Ad(t.z,e.z,r)}}function H1(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Ld(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(a=>{let o=n.length;for(let s=0;s<3;s+=1){let c=a.vertexIndices[s],l=a.texCoordIndices[s],u=t.texCoords[l];n.push({vertexIndex:c,texCoord:H1(u.s,u.t,t.header)})}i.push(o,o+1,o+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(a=>({vertexIndex:a.vertexIndex,texCoord:[a.s,1-a.t]}))),n.mode==="strip")for(let a=0;a<n.vertices.length-2;a+=1){let o=a%2===0,s=i+a+(o?0:1),c=i+a+(o?1:0),l=i+a+2;r.push(s,c,l)}else for(let a=1;a<n.vertices.length-1;a+=1)r.push(i,i+a,i+a+1)}return{vertices:e,indices:new Uint16Array(r)}}function Pd(t,e,r){let{frame0:n,frame1:i,lerp:a}=r,o=t.frames[n],s=t.frames[i];if(!o||!s)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,u)=>{let d=o.vertices[l.vertexIndex],h=s.vertices[l.vertexIndex];if(!d||!h)throw new Error("MD2 vertex index out of range for frame");let m=vm(d.position,h.position,a),p=V1(vm(d.normal,h.normal,a)),y=u*8;c[y]=m.x,c[y+1]=m.y,c[y+2]=m.z,c[y+3]=p.x,c[y+4]=p.y,c[y+5]=p.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var Aa=class{constructor(e,r,n){f(this,"gl");f(this,"geometry");f(this,"vertexBuffer");f(this,"indexBuffer");f(this,"vertexArray");f(this,"indexCount");f(this,"wireframeIndexBuffer");f(this,"wireframeIndexCount");this.gl=e,this.geometry=Ld(r),this.vertexBuffer=new Be(e,e.STATIC_DRAW),this.indexBuffer=new ut(e,e.STATIC_DRAW),this.vertexArray=new Fe(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=Pd(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Ea=class{constructor(e){f(this,"gl");f(this,"program");f(this,"uniformMvp");f(this,"uniformModelMatrix");f(this,"uniformLightDir");f(this,"uniformAmbient");f(this,"uniformTint");f(this,"uniformDiffuse");f(this,"uniformRenderMode");f(this,"uniformSolidColor");f(this,"uniformNumDlights");f(this,"uniformDlights",[]);f(this,"uniformBrightness");f(this,"uniformGamma");f(this,"uniformFullbright");f(this,"uniformGlobalAmbient");this.gl=e,this.program=he.create(e,{vertex:Ed,fragment:Td},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<Vr;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:a=.2,tint:o=[1,1,1,1],diffuseSampler:s=0,dlights:c=[],renderMode:l,brightness:u=1,gamma:d=1,fullbright:h=!1,ambient:m=0}=e,p=new Float32Array(i),y=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,p),this.gl.uniform1f(this.uniformAmbient,a),this.gl.uniform4fv(this.uniformTint,y),this.gl.uniform1i(this.uniformDiffuse,s);let g=0,b=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?g=1:l.mode==="solid-faceted"&&(g=2),l.color?b=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,g),this.gl.uniform4f(this.uniformSolidColor,b[0],b[1],b[2],b[3]);let _=Math.min(c.length,Vr);this.gl.uniform1i(this.uniformNumDlights,_);for(let x=0;x<_;x++){let v=c[x];this.gl.uniform3f(this.uniformDlights[x].pos,v.origin.x,v.origin.y,v.origin.z),this.gl.uniform3f(this.uniformDlights[x].color,v.color.x,v.color.y,v.color.z),this.gl.uniform1f(this.uniformDlights[x].intensity,v.intensity)}this.gl.uniform1f(this.uniformBrightness,u),this.gl.uniform1f(this.uniformGamma,d),this.gl.uniform1i(this.uniformFullbright,h?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,m)}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new ut(this.gl,this.gl.STATIC_DRAW);let n=_a(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var V=1e-6,xe=typeof Float32Array<"u"?Float32Array:Array,ur=Math.random,_m="zyx";function fn(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var jL=Math.PI/180,QL=180/Math.PI;var gs={};Ni(gs,{add:()=>fb,adjoint:()=>Q1,clone:()=>X1,copy:()=>$1,create:()=>Rd,determinant:()=>J1,equals:()=>gb,exactEquals:()=>pb,frob:()=>db,fromMat2d:()=>ob,fromMat4:()=>W1,fromQuat:()=>sb,fromRotation:()=>ib,fromScaling:()=>ab,fromTranslation:()=>nb,fromValues:()=>K1,identity:()=>q1,invert:()=>j1,mul:()=>yb,multiply:()=>Sm,multiplyScalar:()=>hb,multiplyScalarAndAdd:()=>mb,normalFromMat4:()=>lb,projection:()=>cb,rotate:()=>tb,scale:()=>rb,set:()=>Y1,str:()=>ub,sub:()=>bb,subtract:()=>wm,translate:()=>eb,transpose:()=>Z1});function Rd(){var t=new xe(9);return xe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function W1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function X1(t){var e=new xe(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function $1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function K1(t,e,r,n,i,a,o,s,c){var l=new xe(9);return l[0]=t,l[1]=e,l[2]=r,l[3]=n,l[4]=i,l[5]=a,l[6]=o,l[7]=s,l[8]=c,l}function Y1(t,e,r,n,i,a,o,s,c,l){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t}function q1(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function Z1(t,e){if(t===e){var r=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=r,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t}function j1(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=u*o-s*l,h=-u*a+s*c,m=l*a-o*c,p=r*d+n*h+i*m;return p?(p=1/p,t[0]=d*p,t[1]=(-u*n+i*l)*p,t[2]=(s*n-i*o)*p,t[3]=h*p,t[4]=(u*r-i*c)*p,t[5]=(-s*r+i*a)*p,t[6]=m*p,t[7]=(-l*r+n*c)*p,t[8]=(o*r-n*a)*p,t):null}function Q1(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8];return t[0]=o*u-s*l,t[1]=i*l-n*u,t[2]=n*s-i*o,t[3]=s*c-a*u,t[4]=r*u-i*c,t[5]=i*a-r*s,t[6]=a*l-o*c,t[7]=n*c-r*l,t[8]=r*o-n*a,t}function J1(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8];return e*(l*a-o*c)+r*(-l*i+o*s)+n*(c*i-a*s)}function Sm(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],h=r[0],m=r[1],p=r[2],y=r[3],g=r[4],b=r[5],_=r[6],x=r[7],v=r[8];return t[0]=h*n+m*o+p*l,t[1]=h*i+m*s+p*u,t[2]=h*a+m*c+p*d,t[3]=y*n+g*o+b*l,t[4]=y*i+g*s+b*u,t[5]=y*a+g*c+b*d,t[6]=_*n+x*o+v*l,t[7]=_*i+x*s+v*u,t[8]=_*a+x*c+v*d,t}function eb(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],h=r[0],m=r[1];return t[0]=n,t[1]=i,t[2]=a,t[3]=o,t[4]=s,t[5]=c,t[6]=h*n+m*o+l,t[7]=h*i+m*s+u,t[8]=h*a+m*c+d,t}function tb(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],h=Math.sin(r),m=Math.cos(r);return t[0]=m*n+h*o,t[1]=m*i+h*s,t[2]=m*a+h*c,t[3]=m*o-h*n,t[4]=m*s-h*i,t[5]=m*c-h*a,t[6]=l,t[7]=u,t[8]=d,t}function rb(t,e,r){var n=r[0],i=r[1];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function nb(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=e[0],t[7]=e[1],t[8]=1,t}function ib(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function ab(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=e[1],t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function ob(t,e){return t[0]=e[0],t[1]=e[1],t[2]=0,t[3]=e[2],t[4]=e[3],t[5]=0,t[6]=e[4],t[7]=e[5],t[8]=1,t}function sb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,c=i+i,l=r*o,u=n*o,d=n*s,h=i*o,m=i*s,p=i*c,y=a*o,g=a*s,b=a*c;return t[0]=1-d-p,t[3]=u-b,t[6]=h+g,t[1]=u+b,t[4]=1-l-p,t[7]=m-y,t[2]=h-g,t[5]=m+y,t[8]=1-l-d,t}function lb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],h=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,w=n*c-i*s,M=n*l-a*s,S=i*l-a*c,E=u*y-d*p,L=u*g-h*p,A=u*b-m*p,R=d*g-h*y,D=d*b-m*y,k=h*b-m*g,F=_*k-x*D+v*R+w*A-M*L+S*E;return F?(F=1/F,t[0]=(s*k-c*D+l*R)*F,t[1]=(c*A-o*k-l*L)*F,t[2]=(o*D-s*A+l*E)*F,t[3]=(i*D-n*k-a*R)*F,t[4]=(r*k-i*A+a*L)*F,t[5]=(n*A-r*D-a*E)*F,t[6]=(y*S-g*M+b*w)*F,t[7]=(g*v-p*S-b*x)*F,t[8]=(p*M-y*v+b*_)*F,t):null}function cb(t,e,r){return t[0]=2/e,t[1]=0,t[2]=0,t[3]=0,t[4]=-2/r,t[5]=0,t[6]=-1,t[7]=1,t[8]=1,t}function ub(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"}function db(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8])}function fb(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t}function wm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t}function hb(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t}function mb(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t}function pb(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]}function gb(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=e[0],h=e[1],m=e[2],p=e[3],y=e[4],g=e[5],b=e[6],_=e[7],x=e[8];return Math.abs(r-d)<=V*Math.max(1,Math.abs(r),Math.abs(d))&&Math.abs(n-h)<=V*Math.max(1,Math.abs(n),Math.abs(h))&&Math.abs(i-m)<=V*Math.max(1,Math.abs(i),Math.abs(m))&&Math.abs(a-p)<=V*Math.max(1,Math.abs(a),Math.abs(p))&&Math.abs(o-y)<=V*Math.max(1,Math.abs(o),Math.abs(y))&&Math.abs(s-g)<=V*Math.max(1,Math.abs(s),Math.abs(g))&&Math.abs(c-b)<=V*Math.max(1,Math.abs(c),Math.abs(b))&&Math.abs(l-_)<=V*Math.max(1,Math.abs(l),Math.abs(_))&&Math.abs(u-x)<=V*Math.max(1,Math.abs(u),Math.abs(x))}var yb=Sm,bb=wm;var I={};Ni(I,{add:()=>nx,adjoint:()=>Eb,clone:()=>vb,copy:()=>_b,create:()=>xb,decompose:()=>Hb,determinant:()=>Tb,equals:()=>sx,exactEquals:()=>ox,frob:()=>rx,fromQuat:()=>$b,fromQuat2:()=>Nb,fromRotation:()=>kb,fromRotationTranslation:()=>Em,fromRotationTranslationScale:()=>Wb,fromRotationTranslationScaleOrigin:()=>Xb,fromScaling:()=>Db,fromTranslation:()=>Ib,fromValues:()=>Sb,fromXRotation:()=>Ub,fromYRotation:()=>zb,fromZRotation:()=>Ob,frustum:()=>Kb,getRotation:()=>Vb,getScaling:()=>Tm,getTranslation:()=>Gb,identity:()=>Mm,invert:()=>Ab,lookAt:()=>Jb,mul:()=>lx,multiply:()=>Am,multiplyScalar:()=>ix,multiplyScalarAndAdd:()=>ax,ortho:()=>jb,orthoNO:()=>Pm,orthoZO:()=>Qb,perspective:()=>Yb,perspectiveFromFieldOfView:()=>Zb,perspectiveNO:()=>Lm,perspectiveZO:()=>qb,rotate:()=>Rb,rotateX:()=>Cb,rotateY:()=>Bb,rotateZ:()=>Fb,scale:()=>Pb,set:()=>wb,str:()=>tx,sub:()=>cx,subtract:()=>Rm,targetTo:()=>ex,translate:()=>Lb,transpose:()=>Mb});function xb(){var t=new xe(16);return xe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function vb(t){var e=new xe(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function _b(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Sb(t,e,r,n,i,a,o,s,c,l,u,d,h,m,p,y){var g=new xe(16);return g[0]=t,g[1]=e,g[2]=r,g[3]=n,g[4]=i,g[5]=a,g[6]=o,g[7]=s,g[8]=c,g[9]=l,g[10]=u,g[11]=d,g[12]=h,g[13]=m,g[14]=p,g[15]=y,g}function wb(t,e,r,n,i,a,o,s,c,l,u,d,h,m,p,y,g){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=h,t[12]=m,t[13]=p,t[14]=y,t[15]=g,t}function Mm(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Mb(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],a=e[6],o=e[7],s=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=a,t[11]=e[14],t[12]=i,t[13]=o,t[14]=s}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Ab(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],h=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,w=n*c-i*s,M=n*l-a*s,S=i*l-a*c,E=u*y-d*p,L=u*g-h*p,A=u*b-m*p,R=d*g-h*y,D=d*b-m*y,k=h*b-m*g,F=_*k-x*D+v*R+w*A-M*L+S*E;return F?(F=1/F,t[0]=(s*k-c*D+l*R)*F,t[1]=(i*D-n*k-a*R)*F,t[2]=(y*S-g*M+b*w)*F,t[3]=(h*M-d*S-m*w)*F,t[4]=(c*A-o*k-l*L)*F,t[5]=(r*k-i*A+a*L)*F,t[6]=(g*v-p*S-b*x)*F,t[7]=(u*S-h*v+m*x)*F,t[8]=(o*D-s*A+l*E)*F,t[9]=(n*A-r*D-a*E)*F,t[10]=(p*M-y*v+b*_)*F,t[11]=(d*v-u*M-m*_)*F,t[12]=(s*L-o*R-c*E)*F,t[13]=(r*R-n*L+i*E)*F,t[14]=(y*x-p*w-g*_)*F,t[15]=(u*w-d*x+h*_)*F,t):null}function Eb(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7],u=e[8],d=e[9],h=e[10],m=e[11],p=e[12],y=e[13],g=e[14],b=e[15],_=r*s-n*o,x=r*c-i*o,v=r*l-a*o,w=n*c-i*s,M=n*l-a*s,S=i*l-a*c,E=u*y-d*p,L=u*g-h*p,A=u*b-m*p,R=d*g-h*y,D=d*b-m*y,k=h*b-m*g;return t[0]=s*k-c*D+l*R,t[1]=i*D-n*k-a*R,t[2]=y*S-g*M+b*w,t[3]=h*M-d*S-m*w,t[4]=c*A-o*k-l*L,t[5]=r*k-i*A+a*L,t[6]=g*v-p*S-b*x,t[7]=u*S-h*v+m*x,t[8]=o*D-s*A+l*E,t[9]=n*A-r*D-a*E,t[10]=p*M-y*v+b*_,t[11]=d*v-u*M-m*_,t[12]=s*L-o*R-c*E,t[13]=r*R-n*L+i*E,t[14]=y*x-p*w-g*_,t[15]=u*w-d*x+h*_,t}function Tb(t){var e=t[0],r=t[1],n=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],h=t[11],m=t[12],p=t[13],y=t[14],g=t[15],b=e*o-r*a,_=e*s-n*a,x=r*s-n*o,v=l*p-u*m,w=l*y-d*m,M=u*y-d*p,S=e*M-r*w+n*v,E=a*M-o*w+s*v,L=l*x-u*_+d*b,A=m*x-p*_+y*b;return c*S-i*E+g*L-h*A}function Am(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=e[8],h=e[9],m=e[10],p=e[11],y=e[12],g=e[13],b=e[14],_=e[15],x=r[0],v=r[1],w=r[2],M=r[3];return t[0]=x*n+v*s+w*d+M*y,t[1]=x*i+v*c+w*h+M*g,t[2]=x*a+v*l+w*m+M*b,t[3]=x*o+v*u+w*p+M*_,x=r[4],v=r[5],w=r[6],M=r[7],t[4]=x*n+v*s+w*d+M*y,t[5]=x*i+v*c+w*h+M*g,t[6]=x*a+v*l+w*m+M*b,t[7]=x*o+v*u+w*p+M*_,x=r[8],v=r[9],w=r[10],M=r[11],t[8]=x*n+v*s+w*d+M*y,t[9]=x*i+v*c+w*h+M*g,t[10]=x*a+v*l+w*m+M*b,t[11]=x*o+v*u+w*p+M*_,x=r[12],v=r[13],w=r[14],M=r[15],t[12]=x*n+v*s+w*d+M*y,t[13]=x*i+v*c+w*h+M*g,t[14]=x*a+v*l+w*m+M*b,t[15]=x*o+v*u+w*p+M*_,t}function Lb(t,e,r){var n=r[0],i=r[1],a=r[2],o,s,c,l,u,d,h,m,p,y,g,b;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*a+e[12],t[13]=e[1]*n+e[5]*i+e[9]*a+e[13],t[14]=e[2]*n+e[6]*i+e[10]*a+e[14],t[15]=e[3]*n+e[7]*i+e[11]*a+e[15]):(o=e[0],s=e[1],c=e[2],l=e[3],u=e[4],d=e[5],h=e[6],m=e[7],p=e[8],y=e[9],g=e[10],b=e[11],t[0]=o,t[1]=s,t[2]=c,t[3]=l,t[4]=u,t[5]=d,t[6]=h,t[7]=m,t[8]=p,t[9]=y,t[10]=g,t[11]=b,t[12]=o*n+u*i+p*a+e[12],t[13]=s*n+d*i+y*a+e[13],t[14]=c*n+h*i+g*a+e[14],t[15]=l*n+m*i+b*a+e[15]),t}function Pb(t,e,r){var n=r[0],i=r[1],a=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*a,t[9]=e[9]*a,t[10]=e[10]*a,t[11]=e[11]*a,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Rb(t,e,r,n){var i=n[0],a=n[1],o=n[2],s=Math.sqrt(i*i+a*a+o*o),c,l,u,d,h,m,p,y,g,b,_,x,v,w,M,S,E,L,A,R,D,k,F,U;return s<V?null:(s=1/s,i*=s,a*=s,o*=s,c=Math.sin(r),l=Math.cos(r),u=1-l,d=e[0],h=e[1],m=e[2],p=e[3],y=e[4],g=e[5],b=e[6],_=e[7],x=e[8],v=e[9],w=e[10],M=e[11],S=i*i*u+l,E=a*i*u+o*c,L=o*i*u-a*c,A=i*a*u-o*c,R=a*a*u+l,D=o*a*u+i*c,k=i*o*u+a*c,F=a*o*u-i*c,U=o*o*u+l,t[0]=d*S+y*E+x*L,t[1]=h*S+g*E+v*L,t[2]=m*S+b*E+w*L,t[3]=p*S+_*E+M*L,t[4]=d*A+y*R+x*D,t[5]=h*A+g*R+v*D,t[6]=m*A+b*R+w*D,t[7]=p*A+_*R+M*D,t[8]=d*k+y*F+x*U,t[9]=h*k+g*F+v*U,t[10]=m*k+b*F+w*U,t[11]=p*k+_*F+M*U,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Cb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],h=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=a*i+l*n,t[5]=o*i+u*n,t[6]=s*i+d*n,t[7]=c*i+h*n,t[8]=l*i-a*n,t[9]=u*i-o*n,t[10]=d*i-s*n,t[11]=h*i-c*n,t}function Bb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],c=e[3],l=e[8],u=e[9],d=e[10],h=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i-l*n,t[1]=o*i-u*n,t[2]=s*i-d*n,t[3]=c*i-h*n,t[8]=a*n+l*i,t[9]=o*n+u*i,t[10]=s*n+d*i,t[11]=c*n+h*i,t}function Fb(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],o=e[1],s=e[2],c=e[3],l=e[4],u=e[5],d=e[6],h=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=a*i+l*n,t[1]=o*i+u*n,t[2]=s*i+d*n,t[3]=c*i+h*n,t[4]=l*i-a*n,t[5]=u*i-o*n,t[6]=d*i-s*n,t[7]=h*i-c*n,t}function Ib(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function Db(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function kb(t,e,r){var n=r[0],i=r[1],a=r[2],o=Math.sqrt(n*n+i*i+a*a),s,c,l;return o<V?null:(o=1/o,n*=o,i*=o,a*=o,s=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=i*n*l+a*s,t[2]=a*n*l-i*s,t[3]=0,t[4]=n*i*l-a*s,t[5]=i*i*l+c,t[6]=a*i*l+n*s,t[7]=0,t[8]=n*a*l+i*s,t[9]=i*a*l-n*s,t[10]=a*a*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Ub(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function zb(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Ob(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Em(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=n+n,c=i+i,l=a+a,u=n*s,d=n*c,h=n*l,m=i*c,p=i*l,y=a*l,g=o*s,b=o*c,_=o*l;return t[0]=1-(m+y),t[1]=d+_,t[2]=h-b,t[3]=0,t[4]=d-_,t[5]=1-(u+y),t[6]=p+g,t[7]=0,t[8]=h+b,t[9]=p-g,t[10]=1-(u+m),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Nb(t,e){var r=new xe(3),n=-e[0],i=-e[1],a=-e[2],o=e[3],s=e[4],c=e[5],l=e[6],u=e[7],d=n*n+i*i+a*a+o*o;return d>0?(r[0]=(s*o+u*n+c*a-l*i)*2/d,r[1]=(c*o+u*i+l*n-s*a)*2/d,r[2]=(l*o+u*a+s*i-c*n)*2/d):(r[0]=(s*o+u*n+c*a-l*i)*2,r[1]=(c*o+u*i+l*n-s*a)*2,r[2]=(l*o+u*a+s*i-c*n)*2),Em(t,e,r),t}function Gb(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Tm(t,e){var r=e[0],n=e[1],i=e[2],a=e[4],o=e[5],s=e[6],c=e[8],l=e[9],u=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(a*a+o*o+s*s),t[2]=Math.sqrt(c*c+l*l+u*u),t}function Vb(t,e){var r=new xe(3);Tm(r,e);var n=1/r[0],i=1/r[1],a=1/r[2],o=e[0]*n,s=e[1]*i,c=e[2]*a,l=e[4]*n,u=e[5]*i,d=e[6]*a,h=e[8]*n,m=e[9]*i,p=e[10]*a,y=o+u+p,g=0;return y>0?(g=Math.sqrt(y+1)*2,t[3]=.25*g,t[0]=(d-m)/g,t[1]=(h-c)/g,t[2]=(s-l)/g):o>u&&o>p?(g=Math.sqrt(1+o-u-p)*2,t[3]=(d-m)/g,t[0]=.25*g,t[1]=(s+l)/g,t[2]=(h+c)/g):u>p?(g=Math.sqrt(1+u-o-p)*2,t[3]=(h-c)/g,t[0]=(s+l)/g,t[1]=.25*g,t[2]=(d+m)/g):(g=Math.sqrt(1+p-o-u)*2,t[3]=(s-l)/g,t[0]=(h+c)/g,t[1]=(d+m)/g,t[2]=.25*g),t}function Hb(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],a=n[1],o=n[2],s=n[4],c=n[5],l=n[6],u=n[8],d=n[9],h=n[10];r[0]=Math.sqrt(i*i+a*a+o*o),r[1]=Math.sqrt(s*s+c*c+l*l),r[2]=Math.sqrt(u*u+d*d+h*h);var m=1/r[0],p=1/r[1],y=1/r[2],g=i*m,b=a*p,_=o*y,x=s*m,v=c*p,w=l*y,M=u*m,S=d*p,E=h*y,L=g+v+E,A=0;return L>0?(A=Math.sqrt(L+1)*2,t[3]=.25*A,t[0]=(w-S)/A,t[1]=(M-_)/A,t[2]=(b-x)/A):g>v&&g>E?(A=Math.sqrt(1+g-v-E)*2,t[3]=(w-S)/A,t[0]=.25*A,t[1]=(b+x)/A,t[2]=(M+_)/A):v>E?(A=Math.sqrt(1+v-g-E)*2,t[3]=(M-_)/A,t[0]=(b+x)/A,t[1]=.25*A,t[2]=(w+S)/A):(A=Math.sqrt(1+E-g-v)*2,t[3]=(b-x)/A,t[0]=(M+_)/A,t[1]=(w+S)/A,t[2]=.25*A),t}function Wb(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3],c=i+i,l=a+a,u=o+o,d=i*c,h=i*l,m=i*u,p=a*l,y=a*u,g=o*u,b=s*c,_=s*l,x=s*u,v=n[0],w=n[1],M=n[2];return t[0]=(1-(p+g))*v,t[1]=(h+x)*v,t[2]=(m-_)*v,t[3]=0,t[4]=(h-x)*w,t[5]=(1-(d+g))*w,t[6]=(y+b)*w,t[7]=0,t[8]=(m+_)*M,t[9]=(y-b)*M,t[10]=(1-(d+p))*M,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Xb(t,e,r,n,i){var a=e[0],o=e[1],s=e[2],c=e[3],l=a+a,u=o+o,d=s+s,h=a*l,m=a*u,p=a*d,y=o*u,g=o*d,b=s*d,_=c*l,x=c*u,v=c*d,w=n[0],M=n[1],S=n[2],E=i[0],L=i[1],A=i[2],R=(1-(y+b))*w,D=(m+v)*w,k=(p-x)*w,F=(m-v)*M,U=(1-(h+b))*M,ee=(g+_)*M,He=(p+x)*S,We=(g-_)*S,Ae=(1-(h+y))*S;return t[0]=R,t[1]=D,t[2]=k,t[3]=0,t[4]=F,t[5]=U,t[6]=ee,t[7]=0,t[8]=He,t[9]=We,t[10]=Ae,t[11]=0,t[12]=r[0]+E-(R*E+F*L+He*A),t[13]=r[1]+L-(D*E+U*L+We*A),t[14]=r[2]+A-(k*E+ee*L+Ae*A),t[15]=1,t}function $b(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r+r,s=n+n,c=i+i,l=r*o,u=n*o,d=n*s,h=i*o,m=i*s,p=i*c,y=a*o,g=a*s,b=a*c;return t[0]=1-d-p,t[1]=u+b,t[2]=h-g,t[3]=0,t[4]=u-b,t[5]=1-l-p,t[6]=m+y,t[7]=0,t[8]=h+g,t[9]=m-y,t[10]=1-l-d,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Kb(t,e,r,n,i,a,o){var s=1/(r-e),c=1/(i-n),l=1/(a-o);return t[0]=a*2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*s,t[9]=(i+n)*c,t[10]=(o+a)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*a*2*l,t[15]=0,t}function Lm(t,e,r,n,i){var a=1/Math.tan(e/2);if(t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=(i+n)*o,t[14]=2*i*n*o}else t[10]=-1,t[14]=-2*n;return t}var Yb=Lm;function qb(t,e,r,n,i){var a=1/Math.tan(e/2);if(t[0]=a/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=i*o,t[14]=i*n*o}else t[10]=-1,t[14]=-n;return t}function Zb(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),a=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),s=Math.tan(e.rightDegrees*Math.PI/180),c=2/(o+s),l=2/(i+a);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((o-s)*c*.5),t[9]=(i-a)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Pm(t,e,r,n,i,a,o){var s=1/(e-r),c=1/(n-i),l=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*c,t[14]=(o+a)*l,t[15]=1,t}var jb=Pm;function Qb(t,e,r,n,i,a,o){var s=1/(e-r),c=1/(n-i),l=1/(a-o);return t[0]=-2*s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*s,t[13]=(i+n)*c,t[14]=a*l,t[15]=1,t}function Jb(t,e,r,n){var i,a,o,s,c,l,u,d,h,m,p=e[0],y=e[1],g=e[2],b=n[0],_=n[1],x=n[2],v=r[0],w=r[1],M=r[2];return Math.abs(p-v)<V&&Math.abs(y-w)<V&&Math.abs(g-M)<V?Mm(t):(u=p-v,d=y-w,h=g-M,m=1/Math.sqrt(u*u+d*d+h*h),u*=m,d*=m,h*=m,i=_*h-x*d,a=x*u-b*h,o=b*d-_*u,m=Math.sqrt(i*i+a*a+o*o),m?(m=1/m,i*=m,a*=m,o*=m):(i=0,a=0,o=0),s=d*o-h*a,c=h*i-u*o,l=u*a-d*i,m=Math.sqrt(s*s+c*c+l*l),m?(m=1/m,s*=m,c*=m,l*=m):(s=0,c=0,l=0),t[0]=i,t[1]=s,t[2]=u,t[3]=0,t[4]=a,t[5]=c,t[6]=d,t[7]=0,t[8]=o,t[9]=l,t[10]=h,t[11]=0,t[12]=-(i*p+a*y+o*g),t[13]=-(s*p+c*y+l*g),t[14]=-(u*p+d*y+h*g),t[15]=1,t)}function ex(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=n[0],c=n[1],l=n[2],u=i-r[0],d=a-r[1],h=o-r[2],m=u*u+d*d+h*h;m>0&&(m=1/Math.sqrt(m),u*=m,d*=m,h*=m);var p=c*h-l*d,y=l*u-s*h,g=s*d-c*u;return m=p*p+y*y+g*g,m>0&&(m=1/Math.sqrt(m),p*=m,y*=m,g*=m),t[0]=p,t[1]=y,t[2]=g,t[3]=0,t[4]=d*g-h*y,t[5]=h*p-u*g,t[6]=u*y-d*p,t[7]=0,t[8]=u,t[9]=d,t[10]=h,t[11]=0,t[12]=i,t[13]=a,t[14]=o,t[15]=1,t}function tx(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function rx(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function nx(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function Rm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function ix(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function ax(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function ox(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function sx(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],h=t[10],m=t[11],p=t[12],y=t[13],g=t[14],b=t[15],_=e[0],x=e[1],v=e[2],w=e[3],M=e[4],S=e[5],E=e[6],L=e[7],A=e[8],R=e[9],D=e[10],k=e[11],F=e[12],U=e[13],ee=e[14],He=e[15];return Math.abs(r-_)<=V*Math.max(1,Math.abs(r),Math.abs(_))&&Math.abs(n-x)<=V*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-v)<=V*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(a-w)<=V*Math.max(1,Math.abs(a),Math.abs(w))&&Math.abs(o-M)<=V*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(s-S)<=V*Math.max(1,Math.abs(s),Math.abs(S))&&Math.abs(c-E)<=V*Math.max(1,Math.abs(c),Math.abs(E))&&Math.abs(l-L)<=V*Math.max(1,Math.abs(l),Math.abs(L))&&Math.abs(u-A)<=V*Math.max(1,Math.abs(u),Math.abs(A))&&Math.abs(d-R)<=V*Math.max(1,Math.abs(d),Math.abs(R))&&Math.abs(h-D)<=V*Math.max(1,Math.abs(h),Math.abs(D))&&Math.abs(m-k)<=V*Math.max(1,Math.abs(m),Math.abs(k))&&Math.abs(p-F)<=V*Math.max(1,Math.abs(p),Math.abs(F))&&Math.abs(y-U)<=V*Math.max(1,Math.abs(y),Math.abs(U))&&Math.abs(g-ee)<=V*Math.max(1,Math.abs(g),Math.abs(ee))&&Math.abs(b-He)<=V*Math.max(1,Math.abs(b),Math.abs(He))}var lx=Am,cx=Rm;var yc={};Ni(yc,{add:()=>Bv,calculateW:()=>_v,clone:()=>Lv,conjugate:()=>Av,copy:()=>Rv,create:()=>Vd,dot:()=>Zm,equals:()=>zv,exactEquals:()=>Uv,exp:()=>$m,fromEuler:()=>Ev,fromMat3:()=>Ym,fromValues:()=>Pv,getAngle:()=>yv,getAxisAngle:()=>gv,identity:()=>pv,invert:()=>Mv,len:()=>Dv,length:()=>jm,lerp:()=>Iv,ln:()=>Km,mul:()=>Fv,multiply:()=>Xm,normalize:()=>Hd,pow:()=>Sv,random:()=>wv,rotateX:()=>bv,rotateY:()=>xv,rotateZ:()=>vv,rotationTo:()=>Ov,scale:()=>qm,set:()=>Cv,setAxes:()=>Gv,setAxisAngle:()=>Wm,slerp:()=>gc,sqlerp:()=>Nv,sqrLen:()=>kv,squaredLength:()=>Qm,str:()=>Tv});var P={};Ni(P,{add:()=>hx,angle:()=>Ix,bezier:()=>Ex,ceil:()=>mx,clone:()=>ux,copy:()=>dx,create:()=>dc,cross:()=>bs,dist:()=>Vx,distance:()=>Dm,div:()=>Gx,divide:()=>Im,dot:()=>ys,equals:()=>zx,exactEquals:()=>Ux,floor:()=>px,forEach:()=>Xx,fromValues:()=>fc,hermite:()=>Ax,inverse:()=>Sx,len:()=>Bd,length:()=>Cm,lerp:()=>wx,max:()=>yx,min:()=>gx,mul:()=>Nx,multiply:()=>Fm,negate:()=>_x,normalize:()=>Cd,random:()=>Tx,rotateX:()=>Cx,rotateY:()=>Bx,rotateZ:()=>Fx,round:()=>bx,scale:()=>xx,scaleAndAdd:()=>vx,set:()=>fx,slerp:()=>Mx,sqrDist:()=>Hx,sqrLen:()=>Wx,squaredDistance:()=>km,squaredLength:()=>Um,str:()=>kx,sub:()=>Ox,subtract:()=>Bm,transformMat3:()=>Px,transformMat4:()=>Lx,transformQuat:()=>Rx,zero:()=>Dx});function dc(){var t=new xe(3);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ux(t){var e=new xe(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Cm(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function fc(t,e,r){var n=new xe(3);return n[0]=t,n[1]=e,n[2]=r,n}function dx(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function fx(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function hx(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Bm(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Fm(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Im(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function mx(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function px(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function gx(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function yx(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function bx(t,e){return t[0]=fn(e[0]),t[1]=fn(e[1]),t[2]=fn(e[2]),t}function xx(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function vx(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function Dm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function km(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function Um(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function _x(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Sx(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function Cd(t,e){var r=e[0],n=e[1],i=e[2],a=r*r+n*n+i*i;return a>0&&(a=1/Math.sqrt(a)),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a,t}function ys(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function bs(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[0],s=r[1],c=r[2];return t[0]=i*c-a*s,t[1]=a*o-n*c,t[2]=n*s-i*o,t}function wx(t,e,r,n){var i=e[0],a=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t}function Mx(t,e,r,n){var i=Math.acos(Math.min(Math.max(ys(e,r),-1),1)),a=Math.sin(i),o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a;return t[0]=o*e[0]+s*r[0],t[1]=o*e[1]+s*r[1],t[2]=o*e[2]+s*r[2],t}function Ax(t,e,r,n,i,a){var o=a*a,s=o*(2*a-3)+1,c=o*(a-2)+a,l=o*(a-1),u=o*(3-2*a);return t[0]=e[0]*s+r[0]*c+n[0]*l+i[0]*u,t[1]=e[1]*s+r[1]*c+n[1]*l+i[1]*u,t[2]=e[2]*s+r[2]*c+n[2]*l+i[2]*u,t}function Ex(t,e,r,n,i,a){var o=1-a,s=o*o,c=a*a,l=s*o,u=3*a*s,d=3*c*o,h=c*a;return t[0]=e[0]*l+r[0]*u+n[0]*d+i[0]*h,t[1]=e[1]*l+r[1]*u+n[1]*d+i[1]*h,t[2]=e[2]*l+r[2]*u+n[2]*d+i[2]*h,t}function Tx(t,e){e=e===void 0?1:e;var r=ur()*2*Math.PI,n=ur()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function Lx(t,e,r){var n=e[0],i=e[1],a=e[2],o=r[3]*n+r[7]*i+r[11]*a+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/o,t}function Px(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t}function Rx(t,e,r){var n=r[0],i=r[1],a=r[2],o=r[3],s=e[0],c=e[1],l=e[2],u=i*l-a*c,d=a*s-n*l,h=n*c-i*s;return u=u+u,d=d+d,h=h+h,t[0]=s+o*u+i*h-a*d,t[1]=c+o*d+a*u-n*h,t[2]=l+o*h+n*d-i*u,t}function Cx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Bx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Fx(t,e,r,n){var i=[],a=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t}function Ix(t,e){var r=t[0],n=t[1],i=t[2],a=e[0],o=e[1],s=e[2],c=Math.sqrt((r*r+n*n+i*i)*(a*a+o*o+s*s)),l=c&&ys(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function Dx(t){return t[0]=0,t[1]=0,t[2]=0,t}function kx(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Ux(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function zx(t,e){var r=t[0],n=t[1],i=t[2],a=e[0],o=e[1],s=e[2];return Math.abs(r-a)<=V*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(n-o)<=V*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-s)<=V*Math.max(1,Math.abs(i),Math.abs(s))}var Ox=Bm,Nx=Fm,Gx=Im,Vx=Dm,Hx=km,Bd=Cm,Wx=Um,Xx=(function(){var t=dc();return function(e,r,n,i,a,o){var s,c;for(r||(r=3),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,s=n;s<c;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2];return e}})();var Ta={};Ni(Ta,{add:()=>Ud,ceil:()=>$x,clone:()=>Fd,copy:()=>Dd,create:()=>zm,cross:()=>ev,dist:()=>uv,distance:()=>Vm,div:()=>cv,divide:()=>Gm,dot:()=>pc,equals:()=>ov,exactEquals:()=>Gd,floor:()=>Kx,forEach:()=>mv,fromValues:()=>Id,inverse:()=>Jx,len:()=>fv,length:()=>hc,lerp:()=>Nd,max:()=>qx,min:()=>Yx,mul:()=>lv,multiply:()=>Nm,negate:()=>Qx,normalize:()=>Od,random:()=>tv,round:()=>Zx,scale:()=>zd,scaleAndAdd:()=>jx,set:()=>kd,sqrDist:()=>dv,sqrLen:()=>hv,squaredDistance:()=>Hm,squaredLength:()=>mc,str:()=>av,sub:()=>sv,subtract:()=>Om,transformMat4:()=>rv,transformQuat:()=>nv,zero:()=>iv});function zm(){var t=new xe(4);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function Fd(t){var e=new xe(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function Id(t,e,r,n){var i=new xe(4);return i[0]=t,i[1]=e,i[2]=r,i[3]=n,i}function Dd(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function kd(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}function Ud(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t}function Om(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t}function Nm(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t}function Gm(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t}function $x(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t}function Kx(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t}function Yx(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t}function qx(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t}function Zx(t,e){return t[0]=fn(e[0]),t[1]=fn(e[1]),t[2]=fn(e[2]),t[3]=fn(e[3]),t}function zd(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t}function jx(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t}function Vm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(r*r+n*n+i*i+a*a)}function Hm(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return r*r+n*n+i*i+a*a}function hc(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.sqrt(e*e+r*r+n*n+i*i)}function mc(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i}function Qx(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}function Jx(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}function Od(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),t[0]=r*o,t[1]=n*o,t[2]=i*o,t[3]=a*o,t}function pc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function ev(t,e,r,n){var i=r[0]*n[1]-r[1]*n[0],a=r[0]*n[2]-r[2]*n[0],o=r[0]*n[3]-r[3]*n[0],s=r[1]*n[2]-r[2]*n[1],c=r[1]*n[3]-r[3]*n[1],l=r[2]*n[3]-r[3]*n[2],u=e[0],d=e[1],h=e[2],m=e[3];return t[0]=d*l-h*c+m*s,t[1]=-(u*l)+h*o-m*a,t[2]=u*c-d*o+m*i,t[3]=-(u*s)+d*a-h*i,t}function Nd(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=o+n*(r[2]-o),t[3]=s+n*(r[3]-s),t}function tv(t,e){e=e===void 0?1:e;var r,n,i,a,o,s,c;c=ur(),r=c*2-1,n=(4*ur()-2)*Math.sqrt(c*-c+c),o=r*r+n*n,c=ur(),i=c*2-1,a=(4*ur()-2)*Math.sqrt(c*-c+c),s=i*i+a*a;var l=Math.sqrt((1-o)/s);return t[0]=e*r,t[1]=e*n,t[2]=e*i*l,t[3]=e*a*l,t}function rv(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*o,t}function nv(t,e,r){var n=r[0],i=r[1],a=r[2],o=r[3],s=e[0],c=e[1],l=e[2],u=i*l-a*c,d=a*s-n*l,h=n*c-i*s;return u=u+u,d=d+d,h=h+h,t[0]=s+o*u+i*h-a*d,t[1]=c+o*d+a*u-n*h,t[2]=l+o*h+n*d-i*u,t[3]=e[3],t}function iv(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}function av(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}function Gd(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function ov(t,e){var r=t[0],n=t[1],i=t[2],a=t[3],o=e[0],s=e[1],c=e[2],l=e[3];return Math.abs(r-o)<=V*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-s)<=V*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(i-c)<=V*Math.max(1,Math.abs(i),Math.abs(c))&&Math.abs(a-l)<=V*Math.max(1,Math.abs(a),Math.abs(l))}var sv=Om,lv=Nm,cv=Gm,uv=Vm,dv=Hm,fv=hc,hv=mc,mv=(function(){var t=zm();return function(e,r,n,i,a,o){var s,c;for(r||(r=4),n||(n=0),i?c=Math.min(i*r+n,e.length):c=e.length,s=n;s<c;s+=r)t[0]=e[s],t[1]=e[s+1],t[2]=e[s+2],t[3]=e[s+3],a(t,t,o),e[s]=t[0],e[s+1]=t[1],e[s+2]=t[2],e[s+3]=t[3];return e}})();function Vd(){var t=new xe(4);return xe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function pv(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Wm(t,e,r){r=r*.5;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t}function gv(t,e){var r=Math.acos(e[3])*2,n=Math.sin(r/2);return n>V?(t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n):(t[0]=1,t[1]=0,t[2]=0),r}function yv(t,e){var r=Zm(t,e);return Math.acos(2*r*r-1)}function Xm(t,e,r){var n=e[0],i=e[1],a=e[2],o=e[3],s=r[0],c=r[1],l=r[2],u=r[3];return t[0]=n*u+o*s+i*l-a*c,t[1]=i*u+o*c+a*s-n*l,t[2]=a*u+o*l+n*c-i*s,t[3]=o*u-n*s-i*c-a*l,t}function bv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c+o*s,t[1]=i*c+a*s,t[2]=a*c-i*s,t[3]=o*c-n*s,t}function xv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c-a*s,t[1]=i*c+o*s,t[2]=a*c+n*s,t[3]=o*c-i*s,t}function vv(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(r),c=Math.cos(r);return t[0]=n*c+i*s,t[1]=i*c-n*s,t[2]=a*c+o*s,t[3]=o*c-a*s,t}function _v(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t}function $m(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=Math.sqrt(r*r+n*n+i*i),s=Math.exp(a),c=o>0?s*Math.sin(o)/o:0;return t[0]=r*c,t[1]=n*c,t[2]=i*c,t[3]=s*Math.cos(o),t}function Km(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=Math.sqrt(r*r+n*n+i*i),s=o>0?Math.atan2(o,a)/o:0;return t[0]=r*s,t[1]=n*s,t[2]=i*s,t[3]=.5*Math.log(r*r+n*n+i*i+a*a),t}function Sv(t,e,r){return Km(t,e),qm(t,t,r),$m(t,t),t}function gc(t,e,r,n){var i=e[0],a=e[1],o=e[2],s=e[3],c=r[0],l=r[1],u=r[2],d=r[3],h,m,p,y,g;return m=i*c+a*l+o*u+s*d,m<0&&(m=-m,c=-c,l=-l,u=-u,d=-d),1-m>V?(h=Math.acos(m),p=Math.sin(h),y=Math.sin((1-n)*h)/p,g=Math.sin(n*h)/p):(y=1-n,g=n),t[0]=y*i+g*c,t[1]=y*a+g*l,t[2]=y*o+g*u,t[3]=y*s+g*d,t}function wv(t){var e=ur(),r=ur(),n=ur(),i=Math.sqrt(1-e),a=Math.sqrt(e);return t[0]=i*Math.sin(2*Math.PI*r),t[1]=i*Math.cos(2*Math.PI*r),t[2]=a*Math.sin(2*Math.PI*n),t[3]=a*Math.cos(2*Math.PI*n),t}function Mv(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],o=r*r+n*n+i*i+a*a,s=o?1/o:0;return t[0]=-r*s,t[1]=-n*s,t[2]=-i*s,t[3]=a*s,t}function Av(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function Ym(t,e){var r=e[0]+e[4]+e[8],n;if(r>0)n=Math.sqrt(r+1),t[3]=.5*n,n=.5/n,t[0]=(e[5]-e[7])*n,t[1]=(e[6]-e[2])*n,t[2]=(e[1]-e[3])*n;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[i*3+i]&&(i=2);var a=(i+1)%3,o=(i+2)%3;n=Math.sqrt(e[i*3+i]-e[a*3+a]-e[o*3+o]+1),t[i]=.5*n,n=.5/n,t[3]=(e[a*3+o]-e[o*3+a])*n,t[a]=(e[a*3+i]+e[i*3+a])*n,t[o]=(e[o*3+i]+e[i*3+o])*n}return t}function Ev(t,e,r,n){var i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:_m,a=Math.PI/360;e*=a,n*=a,r*=a;var o=Math.sin(e),s=Math.cos(e),c=Math.sin(r),l=Math.cos(r),u=Math.sin(n),d=Math.cos(n);switch(i){case"xyz":t[0]=o*l*d+s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d-o*c*u;break;case"xzy":t[0]=o*l*d-s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d+o*c*u;break;case"yxz":t[0]=o*l*d+s*c*u,t[1]=s*c*d-o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d+o*c*u;break;case"yzx":t[0]=o*l*d+s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d-o*c*u;break;case"zxy":t[0]=o*l*d-s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u+o*c*d,t[3]=s*l*d-o*c*u;break;case"zyx":t[0]=o*l*d-s*c*u,t[1]=s*c*d+o*l*u,t[2]=s*l*u-o*c*d,t[3]=s*l*d+o*c*u;break;default:throw new Error("Unknown angle order "+i)}return t}function Tv(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}var Lv=Fd,Pv=Id,Rv=Dd,Cv=kd,Bv=Ud,Fv=Xm,qm=zd,Zm=pc,Iv=Nd,jm=hc,Dv=jm,Qm=mc,kv=Qm,Hd=Od,Uv=Gd;function zv(t,e){return Math.abs(pc(t,e))>=1-V}var Ov=(function(){var t=dc(),e=fc(1,0,0),r=fc(0,1,0);return function(n,i,a){var o=ys(i,a);return o<-.999999?(bs(t,e,i),Bd(t)<1e-6&&bs(t,r,i),Cd(t,t),Wm(n,t,Math.PI),n):o>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(bs(t,i,a),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=1+o,Hd(n,n))}})(),Nv=(function(){var t=Vd(),e=Vd();return function(r,n,i,a,o,s){return gc(t,n,o,s),gc(e,i,a,s),gc(r,t,e,2*s*(1-s)),r}})(),Gv=(function(){var t=Rd();return function(e,r,n,i){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],Hd(e,Ym(e,t))}})();var bc=class{constructor(e,r){f(this,"_position",P.create());f(this,"_angles",P.create());f(this,"_bobAngles",P.create());f(this,"_bobOffset",P.create());f(this,"_kickAngles",P.create());f(this,"_rollAngle",0);f(this,"_fov",90);f(this,"_aspect",1);f(this,"_near",.1);f(this,"_far",1e3);f(this,"_viewMatrix",I.create());f(this,"_projectionMatrix",I.create());f(this,"_viewProjectionMatrix",I.create());f(this,"_dirty",!0);f(this,"onCameraMove");e!==void 0&&r!==void 0&&r>0&&(this._aspect=e/r)}get position(){return this._position}set position(e){P.equals(this._position,e)||(P.copy(this._position,e),this._dirty=!0,this.triggerMoveEvent())}get angles(){return this._angles}set angles(e){P.equals(this._angles,e)||(P.copy(this._angles,e),this._dirty=!0,this.triggerMoveEvent())}get bobAngles(){return this._bobAngles}set bobAngles(e){P.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){P.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){P.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}toState(){return{position:P.clone(this._position),angles:P.clone(this._angles),fov:this._fov,aspect:this._aspect,near:this._near,far:this._far}}setPosition(e,r,n){let i=P.fromValues(e,r,n);P.equals(this._position,i)||(P.copy(this._position,i),this._dirty=!0,this.triggerMoveEvent())}setRotation(e,r,n){let i=P.fromValues(e,r,n);P.equals(this._angles,i)||(P.copy(this._angles,i),this._dirty=!0,this.triggerMoveEvent())}setFov(e){this.fov=e}setAspectRatio(e){this.aspect=e}lookAt(e){let r=P.create();if(P.subtract(r,e,this._position),P.length(r)<.001)return;let i=Math.atan2(r[1],r[0])*yu,a=Math.hypot(r[0],r[1]),o=-Math.atan2(r[2],a)*yu;this.setRotation(o,i,0)}triggerMoveEvent(){this.onCameraMove&&this.onCameraMove({position:P.clone(this._position),angles:P.clone(this._angles)})}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=I.create();return I.perspective(r,e*Ee,this._aspect,this._near,this._far),r}screenToWorldRay(e,r){let n=e*2-1,i=1-r*2,a=P.fromValues(n,i,-1),o=P.fromValues(n,i,1),s=I.create();I.invert(s,this.viewProjectionMatrix);let c=P.create(),l=P.create();P.transformMat4(c,a,s),P.transformMat4(l,o,s);let u=P.create();return P.subtract(u,l,c),P.normalize(u,u),{origin:P.clone(this._position),direction:u}}updateMatrices(){if(!this._dirty)return;I.perspective(this._projectionMatrix,this._fov*Ee,this._aspect,this._near,this._far);let e=I.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,a=r*Ee,o=n*Ee,s=i*Ee,c=I.create();I.identity(c),I.rotateZ(c,c,-o),I.rotateY(c,c,-a),I.rotateX(c,c,-s);let l=I.create();I.multiply(l,e,c);let u=P.add(P.create(),this._position,this._bobOffset),d=P.negate(P.create(),u),h=P.create();P.transformMat4(h,d,c);let m=P.fromValues(h[1]?-h[1]:0,h[2]||0,h[0]?-h[0]:0);I.copy(this._viewMatrix,l),this._viewMatrix[12]=m[0],this._viewMatrix[13]=m[1],this._viewMatrix[14]=m[2],I.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Vv=[.2,.2,.2],Hv={x:0,y:0,z:1},Wv=[.8,.8,.8];function Wd(t,e,r){return t+(e-t)*r}function Pa(t,e,r){return{x:Wd(t.x,e.x,r),y:Wd(t.y,e.y,r),z:Wd(t.z,e.z,r)}}function La(t){return t<0?0:t>1?1:t}function Xd(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[a,o,s]=n.indices,c=t.texCoords[a],l=t.texCoords[o],u=t.texCoords[s];if(!c||!l||!u)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:a,texCoord:[c.s,1-c.t]},{vertexIndex:o,texCoord:[l.s,1-l.t]},{vertexIndex:s,texCoord:[u.s,1-u.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Xv(t,e,r){let n=r?.ambient??Vv,i=r?.directional??{direction:Hv,color:Wv},a=qr(t),o=qr(i.direction),s=La(a.x*o.x+a.y*o.y+a.z*o.z),c=n[0]+i.color[0]*s,l=n[1]+i.color[1]*s,u=n[2]+i.color[2]*s;if(r?.dynamicLights){let d=r.modelMatrix?th(r.modelMatrix,e):e;for(let h of r.dynamicLights){let m=d.x-h.origin.x,p=d.y-h.origin.y,y=d.z-h.origin.z,g=m*m+p*p+y*y,b=h.radius*h.radius;if(g<b&&b>0){let _=1-Math.sqrt(g)/h.radius,x=Math.sqrt(g),v=x>0?La(-(m*a.x+p*a.y+y*a.z)/x):0,w=La(_*v);c+=h.color[0]*w,l+=h.color[1]*w,u+=h.color[2]*w}}}return[La(c),La(l),La(u)]}function $d(t,e,r,n){let i=t.vertices[r.frame0],a=t.vertices[r.frame1];if(!i||!a)throw new Error("Requested MD3 frames are out of range");let o=new Float32Array(e.vertices.length*12);return e.vertices.forEach((s,c)=>{let l=i[s.vertexIndex],u=a[s.vertexIndex];if(!l||!u)throw new Error(`Vertex index ${s.vertexIndex} missing for frame`);let d=Pa(l.position,u.position,r.lerp),h=qr(Pa(l.normal,u.normal,r.lerp)),m=Xv(h,d,n),p=c*12;o[p]=d.x,o[p+1]=d.y,o[p+2]=d.z,o[p+3]=h.x,o[p+4]=h.y,o[p+5]=h.z,o[p+6]=s.texCoord[0],o[p+7]=s.texCoord[1],o[p+8]=m[0],o[p+9]=m[1],o[p+10]=m[2],o[p+11]=1}),o}function Jm(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(y=>y.name===r);if(i===-1)return null;let a=t.tags[e.frame0]?.[i],o=t.tags[e.frame1]?.[i];if(!a||!o)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let s=Pa(a.origin,o.origin,e.lerp),c=qr(Pa(a.axis[0],o.axis[0],e.lerp)),l=qr(Pa(a.axis[1],o.axis[1],e.lerp)),u=qr(Pa(a.axis[2],o.axis[2],e.lerp)),d=c,h=qr({x:l.x-d.x*(d.x*l.x+d.y*l.y+d.z*l.z),y:l.y-d.y*(d.x*l.x+d.y*l.y+d.z*l.z),z:l.z-d.z*(d.x*l.x+d.y*l.y+d.z*l.z)}),m=qr({x:d.y*h.z-d.z*h.y,y:d.z*h.x-d.x*h.z,z:d.x*h.y-d.y*h.x}),p=[d,h,m];return{origin:s,axis:p,matrix:rh(s,p)}}var Kd=`#version 300 es
|
|
498
498
|
precision highp float;
|
|
499
499
|
|
|
500
500
|
layout(location = 0) in vec3 a_position;
|
|
@@ -569,7 +569,7 @@ void main() {
|
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
o_color = finalColor;
|
|
572
|
-
}`,xs=class{constructor(e,r,n,i){
|
|
572
|
+
}`,xs=class{constructor(e,r,n,i){f(this,"gl");f(this,"geometry");f(this,"vertexBuffer");f(this,"indexBuffer");f(this,"vertexArray");f(this,"indexCount");f(this,"wireframeIndexBuffer");f(this,"wireframeIndexCount");this.gl=e,this.geometry=Xd(r),this.vertexBuffer=new Be(e,e.STATIC_DRAW),this.indexBuffer=new ut(e,e.STATIC_DRAW),this.vertexArray=new Fe(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=$d(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Ra=class{constructor(e,r,n,i){f(this,"surfaces",new Map);f(this,"gl");f(this,"model");f(this,"blend");f(this,"lighting");this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(a=>{this.surfaces.set(a.name,new xs(e,a,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},Ca=class{constructor(e){f(this,"gl");f(this,"program");f(this,"uniformMvp");f(this,"uniformTint");f(this,"uniformDiffuse");f(this,"uniformRenderMode");f(this,"uniformSolidColor");f(this,"uniformBrightness");f(this,"uniformGamma");f(this,"uniformFullbright");f(this,"uniformGlobalAmbient");this.gl=e,this.program=he.create(e,{vertex:Kd,fragment:Yd},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],a=r?.renderMode,o=r?.brightness??1,s=r?.gamma??1,c=r?.fullbright??!1,l=r?.globalAmbient??0;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let u=0,d=[1,1,1,1];if(a&&(a.mode==="solid"||a.mode==="wireframe"?u=1:a.mode==="solid-faceted"&&(u=2),a.color&&(d=[...a.color])),this.gl.uniform1i(this.uniformRenderMode,u),this.gl.uniform4f(this.uniformSolidColor,d[0],d[1],d[2],d[3]),this.gl.uniform1f(this.uniformBrightness,o),this.gl.uniform1f(this.uniformGamma,s),this.gl.uniform1i(this.uniformFullbright,c?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,l),e.vertexArray.bind(),a&&a.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new ut(this.gl,this.gl.STATIC_DRAW);let h=_a(e.geometry.indices);e.wireframeIndexBuffer.upload(h),e.wireframeIndexCount=h.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var $v=[1,1,1,1],Ba=class{constructor(e,r){f(this,"maxParticles");f(this,"rng");f(this,"alive");f(this,"positionX");f(this,"positionY");f(this,"positionZ");f(this,"velocityX");f(this,"velocityY");f(this,"velocityZ");f(this,"colorR");f(this,"colorG");f(this,"colorB");f(this,"colorA");f(this,"size");f(this,"lifetime");f(this,"remaining");f(this,"gravity");f(this,"damping");f(this,"bounce");f(this,"fade");f(this,"blendMode");f(this,"textureIndex");this.maxParticles=e,this.rng=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e),this.textureIndex=new Int16Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??$v,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,this.textureIndex[r]=e.textureIndex??0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let a=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=a,this.velocityY[i]*=a,this.velocityZ[i]=this.velocityZ[i]*a-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha",textureIndex:this.textureIndex[e]}}buildMesh(e,r){let n=[],i=[],a=[],o=s=>{let c=i.length,l=0;for(let u=0;u<this.maxParticles;u+=1){if(!this.alive[u]||(s==="additive"?1:0)!==this.blendMode[u])continue;l+=1;let d=n.length/9,h=this.size[u]*.5,m=this.fade[u]?Math.max(this.remaining[u]/this.lifetime[u],0):1,p=this.blendMode[u]===1?1.2:1,y=this.colorR[u]*p,g=this.colorG[u]*p,b=this.colorB[u]*p,_=this.colorA[u]*m,x=this.positionX[u],v=this.positionY[u],w=this.positionZ[u],M=e.x*h,S=e.y*h,E=e.z*h,L=r.x*h,A=r.y*h,R=r.z*h,D=[{x:x-M-L,y:v-S-A,z:w-E-R},{x:x+M-L,y:v+S-A,z:w+E-R},{x:x-M+L,y:v-S+A,z:w-E+R},{x:x+M+L,y:v+S+A,z:w+E+R}],k=[[0,1],[1,1],[0,0],[1,0]];D.forEach((F,U)=>{n.push(F.x,F.y,F.z,k[U]?.[0]??0,k[U]?.[1]??0,y,g,b,_)}),i.push(d,d+1,d+2,d+2,d+1,d+3)}l>0&&a.push({blendMode:s,start:c,count:i.length-c})};return o("alpha"),o("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:a}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},qd=`#version 300 es
|
|
573
573
|
precision highp float;
|
|
574
574
|
|
|
575
575
|
layout(location = 0) in vec3 a_position;
|
|
@@ -597,7 +597,7 @@ void main() {
|
|
|
597
597
|
float dist = distance(v_uv, vec2(0.5));
|
|
598
598
|
float alpha = v_color.a * (1.0 - smoothstep(0.35, 0.5, dist));
|
|
599
599
|
o_color = vec4(v_color.rgb, alpha);
|
|
600
|
-
}`,Fa=class{constructor(e,r){
|
|
600
|
+
}`,Fa=class{constructor(e,r){f(this,"gl");f(this,"program");f(this,"system");f(this,"vertexBuffer");f(this,"indexBuffer");f(this,"vertexArray");f(this,"vertexCapacity",0);f(this,"indexCapacity",0);this.gl=e,this.system=r,this.program=he.create(e,{vertex:qd,fragment:Zd}),this.vertexBuffer=new Be(e,e.DYNAMIC_DRAW),this.indexBuffer=new ut(e,e.DYNAMIC_DRAW),this.vertexArray=new Fe(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}get shaderSize(){return this.program.sourceSize}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let i=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(i,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(i),this.gl.depthMask(!1),this.program.use();let a=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(a,!1,e.viewProjection),this.vertexArray.bind();for(let o of r.batches)o.blendMode==="additive"?this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.drawElements(this.gl.TRIANGLES,o.count,this.gl.UNSIGNED_SHORT,o.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function ep(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let a=200+e.rng.frandom()*180,o=e.rng.frandom()*.35;e.spawn({position:r,velocity:{x:n.x*a+(e.rng.frandom()-.5)*80,y:n.y*a+(e.rng.frandom()-.5)*80,z:Math.max(n.z*a,120)+o*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.rng.frandom()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*40,y:(e.rng.frandom()-.5)*40,z:80+e.rng.frandom()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function tp(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.rng.frandom()*Math.PI*2,a=Math.acos(2*e.rng.frandom()-1),o=220+e.rng.frandom()*260,s={x:Math.sin(a)*Math.cos(i),y:Math.sin(a)*Math.sin(i),z:Math.cos(a)};e.spawn({position:r,velocity:{x:s.x*o,y:s.y*o,z:s.z*o},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*30,y:(e.rng.frandom()-.5)*30,z:120+e.rng.frandom()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function rp(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let i=0;i<24;i+=1){let a=120+e.rng.frandom()*180;e.spawn({position:r,velocity:{x:n.x*a+(e.rng.frandom()-.5)*70,y:n.y*a+(e.rng.frandom()-.5)*70,z:n.z*a+e.rng.frandom()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function np(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let i=e.rng.frandom()*Math.PI*2,a=8+e.rng.frandom()*8;e.spawn({position:r,velocity:{x:Math.cos(i)*a,y:Math.sin(i)*a,z:100+e.rng.frandom()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function ip(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let i=0;i<10;i+=1){let a=350+e.rng.frandom()*100;e.spawn({position:r,velocity:{x:n.x*a+(e.rng.frandom()-.5)*30,y:n.y*a+(e.rng.frandom()-.5)*30,z:n.z*a+(e.rng.frandom()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function ap(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let i=0;i<6;i+=1)e.spawn({position:{x:r.x+n.x*i*2,y:r.y+n.y*i*2,z:r.z+n.z*i*2},velocity:{x:(e.rng.frandom()-.5)*15,y:(e.rng.frandom()-.5)*15,z:20+e.rng.frandom()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}function op(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<30;i+=1){let a=100+e.rng.frandom()*150;e.spawn({position:r,velocity:{x:n.x*a+(e.rng.frandom()-.5)*80,y:n.y*a+(e.rng.frandom()-.5)*80,z:100+e.rng.frandom()*120},color:[.5,.6,.8,.5],size:3,lifetime:.5+e.rng.frandom()*.3,gravity:800,damping:1.5,blendMode:"alpha",fade:!0})}}function sp(t){let{system:e,origin:r}=t;for(let n=0;n<8;n+=1)e.spawn({position:{x:r.x+(e.rng.frandom()-.5)*10,y:r.y+(e.rng.frandom()-.5)*10,z:r.z+(e.rng.frandom()-.5)*10},velocity:{x:(e.rng.frandom()-.5)*20,y:(e.rng.frandom()-.5)*20,z:40+e.rng.frandom()*20},color:[.8,.8,.8,.3],size:5+e.rng.frandom()*4,lifetime:1.5+e.rng.frandom()*.5,gravity:-50,damping:.5,blendMode:"alpha",fade:!0})}function lp(t){let{system:e,start:r,end:n}=t,i=n.x-r.x,a=n.y-r.y,o=n.z-r.z,s=Math.sqrt(i*i+a*a+o*o);if(s<1)return;let c={x:i/s,y:a/s,z:o/s},l=8;for(let u=0;u<s;u+=l){let d=r.x+c.x*u,h=r.y+c.y*u,m=r.z+c.z*u;e.spawn({position:{x:d,y:h,z:m},velocity:{x:0,y:0,z:0},color:[.4,.4,1,.8],size:2,lifetime:.6,blendMode:"additive",fade:!0});let p=3,y=u*.5;e.spawn({position:{x:d+(e.rng.frandom()-.5)*6,y:h+(e.rng.frandom()-.5)*6,z:m+(e.rng.frandom()-.5)*6},velocity:{x:(e.rng.frandom()-.5)*10,y:(e.rng.frandom()-.5)*10,z:(e.rng.frandom()-.5)*10},color:[.1,.1,.8,.6],size:3,lifetime:.8+e.rng.frandom()*.2,blendMode:"additive",fade:!0})}}function cp(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1},count:i=12,color:a=[1,.9,.2,1]}=t;for(let o=0;o<i;o++){let s=100+e.rng.frandom()*200,c=.5;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*100*c,y:n.y*s+(e.rng.frandom()-.5)*100*c,z:n.z*s+(e.rng.frandom()-.5)*100*c},color:a,size:1.5,lifetime:.3+e.rng.frandom()*.2,gravity:800,bounce:.5,damping:1,blendMode:"additive",fade:!0})}}function up(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1},color:i=[1,.8,0,1]}=t;e.spawn({position:r,velocity:{x:0,y:0,z:0},color:i,size:8,lifetime:.2,blendMode:"additive",fade:!0});for(let a=0;a<8;a++){let o=150+e.rng.frandom()*150;e.spawn({position:r,velocity:{x:n.x*o+(e.rng.frandom()-.5)*120,y:n.y*o+(e.rng.frandom()-.5)*120,z:n.z*o+(e.rng.frandom()-.5)*120},color:i,size:2,lifetime:.4+e.rng.frandom()*.2,gravity:400,blendMode:"additive",fade:!0})}}function dp(t){let{system:e,origin:r}=t;e.spawn({position:r,velocity:{x:0,y:0,z:0},color:[.2,1,.2,1],size:30,lifetime:.5,blendMode:"additive",fade:!0});for(let n=0;n<60;n++){let i=e.rng.frandom()*Math.PI*2,a=Math.acos(2*e.rng.frandom()-1),o=300+e.rng.frandom()*400,s={x:Math.sin(a)*Math.cos(i),y:Math.sin(a)*Math.sin(i),z:Math.cos(a)};e.spawn({position:r,velocity:{x:s.x*o,y:s.y*o,z:s.z*o},color:[.2,1,.2,.8],size:4,lifetime:1,gravity:100,damping:1,blendMode:"additive",fade:!0})}}var Kv=`#version 300 es
|
|
601
601
|
layout(location = 0) in vec2 a_position;
|
|
602
602
|
|
|
603
603
|
out vec2 v_texCoord;
|
|
@@ -632,7 +632,7 @@ void main() {
|
|
|
632
632
|
|
|
633
633
|
o_color = texture(u_texture, uv);
|
|
634
634
|
}
|
|
635
|
-
`,xc=class{constructor(e){
|
|
635
|
+
`,xc=class{constructor(e){f(this,"gl");f(this,"program");f(this,"vao");f(this,"uTime");f(this,"uStrength");f(this,"uTexture");this.gl=e,this.program=he.create(e,{vertex:Kv,fragment:Yv},{a_position:0}),this.uTime=this.program.getUniformLocation("u_time"),this.uStrength=this.program.getUniformLocation("u_strength"),this.uTexture=this.program.getUniformLocation("u_texture"),this.vao=e.createVertexArray(),e.bindVertexArray(this.vao);let r=new Float32Array([-1,-1,1,-1,-1,1,1,1]),n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null)}render(e,r,n=1){this.program.use(),this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.uniform1i(this.uTexture,0),this.gl.uniform1f(this.uTime,r),this.gl.uniform1f(this.uStrength,n),this.gl.bindVertexArray(this.vao),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),this.gl.bindVertexArray(null)}dispose(){this.program.dispose(),this.gl.deleteVertexArray(this.vao)}};var jd=`#version 300 es
|
|
636
636
|
layout(location = 0) in vec2 a_position;
|
|
637
637
|
|
|
638
638
|
out vec2 v_texCoord;
|
|
@@ -699,7 +699,7 @@ void main() {
|
|
|
699
699
|
vec4 color = texture(u_texture, v_texCoord);
|
|
700
700
|
o_color = vec4(color.rgb * u_intensity, 1.0);
|
|
701
701
|
}
|
|
702
|
-
`,vc=class{constructor(e){
|
|
702
|
+
`,vc=class{constructor(e){f(this,"gl");f(this,"extractProgram");f(this,"blurProgram");f(this,"compositeProgram");f(this,"vao");f(this,"framebuffer1");f(this,"framebuffer2");f(this,"texture1");f(this,"texture2");f(this,"width",0);f(this,"height",0);this.gl=e,this.extractProgram=he.create(e,{vertex:jd,fragment:qv},{a_position:0}),this.blurProgram=he.create(e,{vertex:jd,fragment:Zv},{a_position:0}),this.compositeProgram=he.create(e,{vertex:jd,fragment:jv},{a_position:0}),this.framebuffer1=new Ti(e),this.framebuffer2=new Ti(e),this.texture1=new dt(e),this.texture2=new dt(e),this.texture1.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE}),this.texture2.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE}),this.vao=e.createVertexArray(),e.bindVertexArray(this.vao);let r=new Float32Array([-1,-1,1,-1,-1,1,1,1]),n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindVertexArray(null)}resize(e,r){if(this.width!==e||this.height!==r){this.width=e,this.height=r;let n=Math.floor(e/2)||1,i=Math.floor(r/2)||1;this.texture1.upload(n,i,null),this.framebuffer1.attachTexture2D(this.gl.COLOR_ATTACHMENT0,this.texture1),this.texture2.upload(n,i,null),this.framebuffer2.attachTexture2D(this.gl.COLOR_ATTACHMENT0,this.texture2)}}render(e,r=.5){let n=this.gl,i=Math.floor(this.width/2)||1,a=Math.floor(this.height/2)||1;n.bindVertexArray(this.vao),this.framebuffer1.bind(),n.viewport(0,0,i,a),n.clear(n.COLOR_BUFFER_BIT),this.extractProgram.use(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,e.texture),n.uniform1i(this.extractProgram.getUniformLocation("u_texture"),0),n.uniform1f(this.extractProgram.getUniformLocation("u_threshold"),.7),n.drawArrays(n.TRIANGLE_STRIP,0,4),this.blurProgram.use(),n.uniform1fv(this.blurProgram.getUniformLocation("u_weight"),[.227027,.1945946,.1216216,.054054,.016216]);let o=this.blurProgram.getUniformLocation("u_horizontal"),s=this.blurProgram.getUniformLocation("u_texture"),c=4,l=!0,u=!0;for(let d=0;d<c;d++)this.framebuffer2.bind(),l?(this.framebuffer2.bind(),n.bindTexture(n.TEXTURE_2D,this.texture1.texture)):(this.framebuffer1.bind(),n.bindTexture(n.TEXTURE_2D,this.texture2.texture)),n.uniform1i(o,l?1:0),n.uniform1i(s,0),n.drawArrays(n.TRIANGLE_STRIP,0,4),l=!l;n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,this.width,this.height),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE),n.disable(n.DEPTH_TEST),this.compositeProgram.use(),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.texture1.texture),n.uniform1i(this.compositeProgram.getUniformLocation("u_texture"),0),n.uniform1f(this.compositeProgram.getUniformLocation("u_intensity"),r),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.enable(n.DEPTH_TEST),n.bindVertexArray(null)}dispose(){this.extractProgram.dispose(),this.blurProgram.dispose(),this.compositeProgram.dispose(),this.framebuffer1.dispose(),this.framebuffer2.dispose(),this.texture1.dispose(),this.texture2.dispose(),this.gl.deleteVertexArray(this.vao)}};var Qv={gatherVisibleFaces:dn,extractFrustumPlanes:cr,computeSkyScroll:Ri,removeViewTranslation:Ma};function Jv(t,e,r,n,i){if(!n)return;let a=i.removeViewTranslation(e.viewMatrix),o=I.create();I.multiply(o,e.projectionMatrix,a);let s=i.computeSkyScroll(r,n.scrollSpeeds??[.01,.02]);t.bind({viewProjection:o,scroll:s,textureUnit:n.textureUnit??0}),t.draw(),t.gl.depthMask(!0)}function e_(t){return[...t].sort((e,r)=>r.sortKey-e.sortKey)}function t_(t){return[...t].sort((e,r)=>e.sortKey-r.sortKey)}function r_(t,e,r){let n=e?.materials?.getMaterial(t.texture),i;if(n){let s=n.texture;s&&(i=s)}i||(i=e?.textures?.get(t.texture));let a=t.lightmap?.atlasIndex,o=a!==void 0?e?.lightmaps?.[a]?.texture:void 0;return{diffuse:i,lightmap:o,refraction:r}}function fp(t,e,r,n){let i=n.diffuse;i&&r.diffuse!==i&&(i.bind(0),r.diffuse=i);let a=n.lightmap;a&&r.lightmap!==a&&(a.bind(1),r.lightmap=a),a||(r.lightmap=void 0);let o=n.refraction,s;return o&&t.surfaceFlags&Zr?(r.refraction!==o&&(o.bind(2),r.refraction=o),s=2):r.refraction=void 0,{diffuse:0,lightmap:a?1:void 0,refraction:s}}function n_(t,e,r,n){if(!r)return!1;let i=r.fov?e.getViewmodelProjectionMatrix(r.fov):e.projectionMatrix,a=n(e.viewMatrix),o=I.create();return I.multiply(o,i,a),r.depthRange&&t.depthRange(r.depthRange[0],r.depthRange[1]),r.draw(new Float32Array(o)),r.depthRange&&t.depthRange(0,1),!0}function i_(t,e){if(!t)return 1;let r=Math.floor(e*10)%t.length;return(t.charCodeAt(r)-97)/12}var hp=(t,e,r,n=Qv)=>{let i=new xc(t),a=new vc(t),o=0,s,c=0,l=0,u=(h,m)=>((!s||c!==h||l!==m)&&(s=new dt(t),s.upload(h,m,null),s.setParameters({minFilter:t.LINEAR,magFilter:t.LINEAR,wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE}),c=h,l=m),s);return{renderFrame:h=>{let m=performance.now(),p=o>0?1e3/(m-o):0;o=m;let y={batches:0,facesDrawn:0,drawCalls:0,skyDrawn:!1,viewModelDrawn:!1,fps:Math.round(p),vertexCount:0},{camera:g,world:b,sky:_,clearColor:x=[0,0,0,1],timeSeconds:v=0,viewModel:w,dlights:M,renderMode:S,disableLightmaps:E,lightmapOnly:L,brightness:A,gamma:R,fullbright:D,ambient:k,lightStyleOverrides:F,waterTint:U,underwaterWarp:ee,bloom:He,bloomIntensity:We,portalState:Ae}=h,j=new Float32Array(g.viewProjectionMatrix);if(t.clearColor(x[0],x[1],x[2],x[3]),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),Jv(r,g,v,_,n),y.skyDrawn=!!_,b){b.materials?.update(v);let ue=n.extractFrustumPlanes(Array.from(j)),ve={x:g.position[0]??0,y:g.position[1]??0,z:g.position[2]??0},Ie=n.gatherVisibleFaces(b.map,ve,ue,Ae),nt=[],jt=[];for(let de of Ie){let ze=b.surfaces[de.faceIndex];if(!ze)continue;(ze.surfaceFlags&(_n|Sn|Zr))!==0?jt.push(de):nt.push(de)}let mr=e_(nt),ft=b.lightStyles||[];if(F&&F.size>0){let de=[...b.lightStyles||[]];for(let[ze,Ue]of F){for(;de.length<=ze;)de.push(1);de[ze]=i_(Ue,v)}ft=de}let Xe=(de,ze)=>{let Ue,pr,Qt={},gn=ze?s:void 0;for(let{faceIndex:$s}of de){let St=b.surfaces[$s];if(!St||(St.surfaceFlags&vn)!==0)continue;let Ks=b.map.faces[$s]?.styles,Za=b.materials?.getMaterial(St.texture),ti=r_(St,b,gn),ja=S;S&&!S.applyToAll&&ti.diffuse?ja=void 0:S&&!S.applyToAll&&!ti.diffuse&&(ja=S);let Qa=ti.lightmap;E&&(Qa=void 0);let Oi={diffuse:ti.diffuse,lightmap:Qa,surfaceFlags:St.surfaceFlags,styleKey:Ks?.join(",")??""};if(Ue&&Ue.diffuse===Oi.diffuse&&Ue.lightmap===Oi.lightmap&&Ue.surfaceFlags===Oi.surfaceFlags&&Ue.styleKey===Oi.styleKey){let Ys={...ti,lightmap:Qa};fp(St,b,Qt,Ys),pr&&ms(t,pr)}else{y.batches+=1,Qt.diffuse=void 0,Qt.lightmap=void 0,Qt.refraction=void 0;let Ys={...ti,lightmap:Qa},qs=fp(St,b,Qt,Ys),Vf=Za?Za.scrollOffset:void 0,Hf=Za?Za.warp:void 0;pr=e.bind({modelViewProjection:j,styleIndices:Ks,styleValues:ft,surfaceFlags:St.surfaceFlags,timeSeconds:v,diffuseSampler:qs.diffuse??0,lightmapSampler:qs.lightmap,refractionSampler:qs.refraction,texScroll:Vf,warp:Hf,dlights:M,renderMode:ja,lightmapOnly:L,brightness:A,gamma:R,fullbright:D,ambient:k}),ms(t,pr),Ue=Oi}e.draw(St,ja),y.facesDrawn+=1,y.drawCalls+=1,y.vertexCount+=St.vertexCount}};if(Xe(mr,!1),jt.length>0){let de=t.canvas.width,ze=t.canvas.height;u(de,ze).bind(2),t.copyTexImage2D(t.TEXTURE_2D,0,t.RGBA,0,0,de,ze,0)}let z=t_(jt);Xe(z,!0)}if(n_(t,g,w,n.removeViewTranslation)&&(y.viewModelDrawn=!0),ee){let ue=t.canvas.width,ve=t.canvas.height,Ie=u(ue,ve);Ie.bind(0),t.copyTexImage2D(t.TEXTURE_2D,0,t.RGBA,0,0,ue,ve,0),t.disable(t.DEPTH_TEST),t.depthMask(!1),i.render(Ie.texture,v),t.enable(t.DEPTH_TEST),t.depthMask(!0)}if(He){let ue=t.canvas.width,ve=t.canvas.height;a.resize(ue,ve);let Ie=u(ue,ve);Ie.bind(0),t.copyTexImage2D(t.TEXTURE_2D,0,t.RGBA,0,0,ue,ve,0),a.render(Ie,We??.5)}return y}}};var a_=`#version 300 es
|
|
703
703
|
precision highp float;
|
|
704
704
|
|
|
705
705
|
layout(location = 0) in vec2 a_position;
|
|
@@ -724,7 +724,7 @@ out vec4 o_color;
|
|
|
724
724
|
|
|
725
725
|
void main() {
|
|
726
726
|
o_color = texture(u_diffuseMap, v_texCoord) * u_tint;
|
|
727
|
-
}`,Ia=class{constructor(e){
|
|
727
|
+
}`,Ia=class{constructor(e){f(this,"gl");f(this,"program");f(this,"vao");f(this,"vbo");f(this,"whiteTexture");f(this,"uniformProjection");f(this,"uniformDiffuse");f(this,"uniformTint");this.gl=e,this.program=he.create(e,{vertex:a_,fragment:o_},{a_position:0,a_texCoord:1}),this.uniformProjection=this.program.getUniformLocation("u_projection"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.vao=new Fe(e),this.vbo=new Be(e,e.STREAM_DRAW),this.vao.configureAttributes([{index:0,size:2,type:e.FLOAT,stride:16,offset:0},{index:1,size:2,type:e.FLOAT,stride:16,offset:8}],this.vbo),this.whiteTexture=new dt(e),this.whiteTexture.upload(1,1,new Uint8Array([255,255,255,255]))}get shaderSize(){return this.program.sourceSize}begin(e){this.program.use(),this.gl.uniformMatrix4fv(this.uniformProjection,!1,e)}draw(e,r,n,i,a=0,o=0,s=1,c=1,l=[1,1,1,1]){let u=e,d=r,h=e+n,m=r+i,p=new Float32Array([u,d,a,o,h,d,s,o,u,m,a,c,h,m,s,c]);this.vbo.upload(p,this.gl.STREAM_DRAW),this.gl.uniform4fv(this.uniformTint,new Float32Array(l)),this.vao.bind(),this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4)}drawRect(e,r,n,i,a){this.whiteTexture.bind(0),this.draw(e,r,n,i,0,0,1,1,a)}};var s_=`#version 300 es
|
|
728
728
|
precision highp float;
|
|
729
729
|
|
|
730
730
|
layout(location = 0) in vec3 a_position;
|
|
@@ -745,7 +745,7 @@ out vec4 o_color;
|
|
|
745
745
|
|
|
746
746
|
void main() {
|
|
747
747
|
o_color = v_color;
|
|
748
|
-
}`,_c=class{constructor(e){
|
|
748
|
+
}`,_c=class{constructor(e){f(this,"gl");f(this,"program");f(this,"vao");f(this,"vbo");f(this,"vertices",[]);f(this,"uniformViewProjection");this.gl=e,this.program=he.create(e,{vertex:s_,fragment:l_},{a_position:0,a_color:1}),this.uniformViewProjection=this.program.getUniformLocation("u_viewProjection"),this.vao=new Fe(e),this.vbo=new Be(e,e.STREAM_DRAW),this.vao.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:28,offset:0},{index:1,size:4,type:e.FLOAT,stride:28,offset:12}],this.vbo)}get shaderSize(){return this.program.sourceSize}addLine(e,r,n={r:1,g:0,b:0,a:1}){this.vertices.push(e.x,e.y,e.z,n.r,n.g,n.b,n.a,r.x,r.y,r.z,n.r,n.g,n.b,n.a)}addBBox(e,r,n={r:0,g:1,b:0,a:1}){let i={x:e.x,y:e.y,z:e.z},a={x:r.x,y:e.y,z:e.z},o={x:r.x,y:r.y,z:e.z},s={x:e.x,y:r.y,z:e.z},c={x:e.x,y:e.y,z:r.z},l={x:r.x,y:e.y,z:r.z},u={x:r.x,y:r.y,z:r.z},d={x:e.x,y:r.y,z:r.z};this.addLine(i,a,n),this.addLine(a,o,n),this.addLine(o,s,n),this.addLine(s,i,n),this.addLine(c,l,n),this.addLine(l,u,n),this.addLine(u,d,n),this.addLine(d,c,n),this.addLine(i,c,n),this.addLine(a,l,n),this.addLine(o,u,n),this.addLine(s,d,n)}clear(){this.vertices=[]}render(e){this.vertices.length!==0&&(this.program.use(),this.gl.uniformMatrix4fv(this.uniformViewProjection,!1,e),this.vbo.upload(new Float32Array(this.vertices),this.gl.STREAM_DRAW),this.vao.bind(),this.gl.drawArrays(this.gl.LINES,0,this.vertices.length/7))}};function c_(t,e){let r=t.models[0].headNode;for(;r>=0;){let i=t.nodes[r],a=t.planes[i.planeIndex];a.normal[0]*e.x+a.normal[1]*e.y+a.normal[2]*e.z-a.dist>=0?r=i.children[0]:r=i.children[1]}let n=-(r+1);return{leaf:t.leafs[n],index:n}}function u_(t){if(t.entities.worldspawn?.properties.light){let e=parseInt(t.entities.worldspawn.properties.light,10);if(!isNaN(e))return e/255}if(t.entities.worldspawn?.properties._minlight){let e=parseInt(t.entities.worldspawn.properties._minlight,10);if(!isNaN(e))return e/255}return .2}function d_(t,e,r,n){let i=t.faces[e];if(!i||i.lightOffset<0||!t.lightMapInfo[e])return 0;let o=t.texInfo[i.texInfo],s=1/0,c=-1/0,l=1/0,u=-1/0,d=i.firstEdge;for(let E=0;E<i.numEdges;E++){let L=t.surfEdges[d+E],A=L>=0?t.edges[L].vertices[0]:t.edges[Math.abs(L)].vertices[1],R=t.vertices[A],D=R[0]*o.s[0]+R[1]*o.s[1]+R[2]*o.s[2]+o.sOffset,k=R[0]*o.t[0]+R[1]*o.t[1]+R[2]*o.t[2]+o.tOffset;D<s&&(s=D),D>c&&(c=D),k<l&&(l=k),k>u&&(u=k)}let h=Math.floor(s/16),m=Math.floor(l/16),p=Math.ceil(c/16)-h+1,y=Math.ceil(u/16)-m+1,g=r/16-h,b=n/16-m,_=Math.max(0,Math.min(p-1,Math.floor(g))),x=Math.max(0,Math.min(y-1,Math.floor(b))),v=i.lightOffset+(x*p+_)*3;if(v+2>=t.lightMaps.length)return 0;let w=t.lightMaps[v],M=t.lightMaps[v+1],S=t.lightMaps[v+2];return Math.max(w,M,S)/255}function mp(t,e){if(!t)return 1;let r=u_(t),n={x:e.x,y:e.y,z:e.z-8192},i=1,a=-1,o=0,s=0,{leaf:c,index:l}=c_(t,e);if(c.contents&1)return r;let u=t.leafLists.leafFaces[l];if(u)for(let d of u){let h=t.faces[d],m=t.planes[h.planeIndex],p=h.side,y=p?-m.normal[0]:m.normal[0],g=p?-m.normal[1]:m.normal[1],b=p?-m.normal[2]:m.normal[2],_=p?-m.dist:m.dist;if(b>.7){let x=y*e.x+g*e.y+b*e.z-_;if(x>=0&&x<64){let v=t.texInfo[h.texInfo],w=e.x*v.s[0]+e.y*v.s[1]+e.z*v.s[2]+v.sOffset,M=e.x*v.t[0]+e.y*v.t[1]+e.z*v.t[2]+v.tOffset,S=d_(t,d,w,M);if(S>r)return S}}}return Math.max(r,.2)}var Sc=class{constructor(e){f(this,"ext");f(this,"gl");f(this,"activeQueries",[]);f(this,"queryPool",[]);f(this,"currentQuery",null);f(this,"lastGpuTimeMs",0);f(this,"frameStartTime",0);f(this,"lastCpuFrameTimeMs",0);f(this,"textureMemoryBytes",0);f(this,"bufferMemoryBytes",0);f(this,"shaderMemoryBytes",0);this.gl=e,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")}get available(){return!!this.ext}getPerformanceReport(e){let r=this.textureMemoryBytes/1048576,n=this.bufferMemoryBytes/(1024*1024);return{frameTimeMs:this.lastCpuFrameTimeMs,gpuTimeMs:this.lastGpuTimeMs,cpuFrameTimeMs:this.lastCpuFrameTimeMs,drawCalls:e.drawCalls,triangles:Math.floor(e.vertexCount/3),vertices:e.vertexCount,textureBinds:e.batches,shaderSwitches:e.shaderSwitches,visibleSurfaces:e.visibleSurfaces,culledSurfaces:e.culledSurfaces,visibleEntities:e.visibleEntities,culledEntities:e.culledEntities,memoryUsageMB:{textures:r,geometry:n,total:r+n}}}startFrame(){if(this.frameStartTime=performance.now(),!this.ext||this.currentQuery)return;let e=this.getQuery();e&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,e),this.currentQuery=e)}endFrame(){this.lastCpuFrameTimeMs=performance.now()-this.frameStartTime,!(!this.ext||!this.currentQuery)&&(this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.activeQueries.push(this.currentQuery),this.currentQuery=null,this.pollQueries())}trackTextureMemory(e){this.textureMemoryBytes+=e}trackBufferMemory(e){this.bufferMemoryBytes+=e}trackShaderMemory(e){this.shaderMemoryBytes+=e}getMemoryUsage(){let e=this.textureMemoryBytes,r=this.bufferMemoryBytes,n=this.shaderMemoryBytes,i=this.bufferMemoryBytes,a=e+r+n;return{texturesBytes:e,geometryBytes:r,shadersBytes:n,buffersBytes:i,totalBytes:a}}getQuery(){return this.queryPool.length>0?this.queryPool.pop():this.gl.createQuery()}pollQueries(){if(this.activeQueries.length===0)return;let e=this.activeQueries[0],r=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE),n=this.gl.getParameter(this.ext.GPU_DISJOINT_EXT);if(r)if(n)this.activeQueries.forEach(i=>this.queryPool.push(i)),this.activeQueries.length=0;else{let i=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);this.lastGpuTimeMs=i/1e6,this.activeQueries.shift(),this.queryPool.push(e)}}dispose(){[...this.activeQueries,...this.queryPool].forEach(e=>this.gl.deleteQuery(e)),this.activeQueries.length=0,this.queryPool.length=0}};var pp={1:[1,0,0,1],2:[0,1,0,1],3:[1,1,0,1],4:[0,0,1,1],5:[0,1,1,1],6:[1,0,1,1],7:[1,1,1,1],0:[0,0,0,1]};function wc(t){let e=[],r="",n;for(let i=0;i<t.length;i++){if(t[i]==="^"&&i+1<t.length){let a=t[i+1];if(pp[a]){r.length>0&&(e.push({text:r,color:n}),r=""),n=pp[a],i++;continue}}r+=t[i]}return r.length>0&&e.push({text:r,color:n}),e}var f_=`
|
|
749
749
|
attribute vec3 a_position;
|
|
750
750
|
attribute vec3 a_color;
|
|
751
751
|
uniform mat4 u_viewProjection;
|
|
@@ -797,7 +797,7 @@ void main() {
|
|
|
797
797
|
|
|
798
798
|
gl_FragColor = vec4(color, 1.0);
|
|
799
799
|
}
|
|
800
|
-
`;function Mc(t){return P.fromValues(t.x,t.y,t.z)}function dr(t){return{x:t[0],y:t[1],z:t[2]}}var Ac=class{constructor(e){h(this,"gl");h(this,"shader");h(this,"vao");h(this,"vbo");h(this,"shaderSolid");h(this,"vaoSolid");h(this,"vboSolid");h(this,"vertices",[]);h(this,"solidVertices",[]);h(this,"labels",[]);this.gl=e,this.shader=he.create(e,{vertex:f_,fragment:h_}),this.vao=new Fe(e),this.vbo=new Be(e,e.DYNAMIC_DRAW),this.vao.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:24,offset:0},{index:1,size:3,type:e.FLOAT,stride:24,offset:12}],this.vbo),this.shaderSolid=he.create(e,{vertex:m_,fragment:p_}),this.vaoSolid=new Fe(e),this.vboSolid=new Be(e,e.DYNAMIC_DRAW),this.vaoSolid.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:3,type:e.FLOAT,stride:36,offset:12},{index:2,size:3,type:e.FLOAT,stride:36,offset:24}],this.vboSolid)}get shaderSize(){return this.shader.sourceSize+this.shaderSolid.sourceSize}drawLine(e,r,n){this.vertices.push(e.x,e.y,e.z,n.r,n.g,n.b,r.x,r.y,r.z,n.r,n.g,n.b)}drawBoundingBox(e,r,n){let{x:i,y:a,z:o}=e,{x:s,y:c,z:l}=r;this.drawLine({x:i,y:a,z:o},{x:s,y:a,z:o},n),this.drawLine({x:s,y:a,z:o},{x:s,y:c,z:o},n),this.drawLine({x:s,y:c,z:o},{x:i,y:c,z:o},n),this.drawLine({x:i,y:c,z:o},{x:i,y:a,z:o},n),this.drawLine({x:i,y:a,z:l},{x:s,y:a,z:l},n),this.drawLine({x:s,y:a,z:l},{x:s,y:c,z:l},n),this.drawLine({x:s,y:c,z:l},{x:i,y:c,z:l},n),this.drawLine({x:i,y:c,z:l},{x:i,y:a,z:l},n),this.drawLine({x:i,y:a,z:o},{x:i,y:a,z:l},n),this.drawLine({x:s,y:a,z:o},{x:s,y:a,z:l},n),this.drawLine({x:s,y:c,z:o},{x:s,y:c,z:l},n),this.drawLine({x:i,y:c,z:o},{x:i,y:c,z:l},n)}drawPoint(e,r,n){let i=r/2;this.drawBoundingBox({x:e.x-i,y:e.y-i,z:e.z-i},{x:e.x+i,y:e.y+i,z:e.z+i},n)}drawAxes(e,r){this.drawLine(e,{x:e.x+r,y:e.y,z:e.z},{r:1,g:0,b:0}),this.drawLine(e,{x:e.x,y:e.y+r,z:e.z},{r:0,g:1,b:0}),this.drawLine(e,{x:e.x,y:e.y,z:e.z+r},{r:0,g:0,b:1})}drawText3D(e,r){this.labels.push({text:e,position:r})}addTriangle(e,r,n,i,a){this.solidVertices.push(e.x,e.y,e.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z),this.solidVertices.push(r.x,r.y,r.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z),this.solidVertices.push(n.x,n.y,n.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z)}addCone(e,r,n,i){let o=Mc(e),s=Mc(r),c=P.create();P.subtract(c,o,s),P.normalize(c,c);let l=P.fromValues(0,0,1);Math.abs(P.dot(c,l))>.99&&(l=P.fromValues(0,1,0));let u=P.create();P.cross(u,l,c),P.normalize(u,u);let d=P.create();P.cross(d,c,u);let f=[];for(let g=0;g<16;g++){let b=g/16*Math.PI*2,_=Math.cos(b)*n,x=Math.sin(b)*n,v=P.clone(s);P.scaleAndAdd(v,v,u,_),P.scaleAndAdd(v,v,d,x),f.push(v)}let m=P.clone(c);P.scale(m,m,-1);let p=dr(m),y=r;for(let g=0;g<16;g++){let b=dr(f[g]),_=dr(f[(g+1)%16]);this.addTriangle(y,_,b,p,i)}for(let g=0;g<16;g++){let b=f[g],_=f[(g+1)%16],x=dr(b),v=dr(_),S=P.create();P.subtract(S,_,b);let M=P.create();P.subtract(M,o,b);let w=P.create();P.cross(w,S,M),P.normalize(w,w);let T=dr(w);this.addTriangle(x,v,e,T,i)}}addTorus(e,r,n,i,a={x:0,y:0,z:1}){let c=Mc(a);P.normalize(c,c);let l=Mc(e),u=P.fromValues(0,0,1),d=I.create();if(Math.abs(P.dot(c,u))>.999)c[2]<0&&I.rotateX(d,d,Math.PI);else{let p=P.create();P.cross(p,u,c),P.normalize(p,p);let y=Math.acos(P.dot(u,c));I.fromRotation(d,y,p)}let f=[],m=[];for(let p=0;p<=16;p++){let y=p/16*Math.PI*2,g=Math.cos(y),b=Math.sin(y),_=[],x=[];for(let v=0;v<=8;v++){let S=v/8*Math.PI*2,M=Math.cos(S),w=Math.sin(S),T=(r+n*M)*g,L=(r+n*M)*b,A=n*w,R=P.fromValues(T,L,A),D=M*g,k=M*b,F=w,U=P.fromValues(D,k,F);P.transformMat4(R,R,d),P.transformMat4(U,U,d),P.add(R,R,l),_.push(R),x.push(U)}f.push(_),m.push(x)}for(let p=0;p<16;p++)for(let y=0;y<8;y++){let g=f[p][y],b=f[p+1][y],_=f[p+1][y+1],x=f[p][y+1],v=dr(g),S=dr(b),M=dr(_),w=dr(x),T=P.create();P.subtract(T,b,g);let L=P.create();P.subtract(L,_,g);let A=P.create();P.cross(A,T,L),P.normalize(A,A),this.addTriangle(v,S,M,dr(A),i);let R=P.create();P.subtract(R,_,g);let D=P.create();P.subtract(D,x,g);let k=P.create();P.cross(k,R,D),P.normalize(k,k),this.addTriangle(v,M,w,dr(k),i)}}render(e,r=!1){if(r&&this.gl.disable(this.gl.DEPTH_TEST),this.vertices.length>0){this.shader.use();let n=this.shader.getUniformLocation("u_viewProjection");n&&this.gl.uniformMatrix4fv(n,!1,e),this.vbo.upload(new Float32Array(this.vertices)),this.vao.bind(),this.gl.drawArrays(this.gl.LINES,0,this.vertices.length/6)}if(this.solidVertices.length>0){this.shaderSolid.use();let n=this.shaderSolid.getUniformLocation("u_viewProjection");n&&this.gl.uniformMatrix4fv(n,!1,e);let i=this.shaderSolid.getUniformLocation("u_lightingEnabled");i&&this.gl.uniform1i(i,1),this.vboSolid.upload(new Float32Array(this.solidVertices)),this.vaoSolid.bind(),this.gl.drawArrays(this.gl.TRIANGLES,0,this.solidVertices.length/9)}r&&this.gl.enable(this.gl.DEPTH_TEST)}getLabels(e,r,n){let i=[];for(let a of this.labels){let o=Ta.fromValues(a.position.x,a.position.y,a.position.z,1),s=Ta.create(),l=e,u=o[0],d=o[1],f=o[2],m=o[3];if(s[0]=l[0]*u+l[4]*d+l[8]*f+l[12]*m,s[1]=l[1]*u+l[5]*d+l[9]*f+l[13]*m,s[2]=l[2]*u+l[6]*d+l[10]*f+l[14]*m,s[3]=l[3]*u+l[7]*d+l[11]*f+l[15]*m,s[3]>0){let p=s[0]/s[3],y=s[1]/s[3],g=(p+1)*.5*r,b=(1-y)*.5*n;g>=0&&g<=r&&b>=0&&b<=n&&i.push({text:a.text,x:g,y:b})}}return i}clear(){this.vertices=[],this.solidVertices=[],this.labels=[]}};function Ec(t,e,r,n=32){let i=[];for(let s of t){let c=!0;for(let l of e)if(l.normal.x*s.origin.x+l.normal.y*s.origin.y+l.normal.z*s.origin.z+l.distance<-s.intensity){c=!1;break}if(c){let l=0;if(r){let u=s.origin.x-r.x,d=s.origin.y-r.y,f=s.origin.z-r.z;l=u*u+d*d+f*f}i.push({light:s,distSq:l})}}r&&i.sort((s,c)=>s.distSq-c.distSq);let a=[],o=Math.min(i.length,n);for(let s=0;s<o;s++)a.push(i[s].light);return a}function Qd(t){let e=(t*1664525+1013904223>>>0)/4294967296,r=(t*25214903917+11>>>0)/4294967296,n=(t*69069+1>>>0)/4294967296;return[e,r,n,1]}var gp=t=>{let e=new Sa(t),r=new wa(t),n=new Ea(t),i=new Ca(t),a=new Ia(t),o=new _c(t),s=new Ac(t),c=new Sc(t),l=new eh({seed:Date.now()}),u=new Ba(4096,l),d=new Fa(t,u),f=e.shaderSize+r.shaderSize+n.shaderSize+i.shaderSize+a.shaderSize+o.shaderSize+s.shaderSize+d.shaderSize;c.trackShaderMemory(f);let m=new Map,p=new Map,y=new Map,g=new Map,b=0,_=600,x=300,v=null,S={drawCalls:0,vertexCount:0,batches:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0},M=new Map,w=new Map,T=0,L=1,A=1,R=!1,D=0,k=new Map,F=!1,U=!1,ee=.5,He=1,We=new Array(1024).fill(!0),Ae=hp(t,e,r),j=1e4,ue=[],ve=0,Ie=yc.create(),nt=P.create(),jt=P.create();for(let E=0;E<j;E++){let K={id:-1,model:void 0,transform:new Float32Array(16),type:"md3",blend:{frame0:0,frame1:0,lerp:0},tint:[1,1,1,1],lighting:{ambient:[.5,.5,.5],dynamicLights:[],modelMatrix:void 0}};K.lighting&&(K.lighting.modelMatrix=K.transform),ue.push(K)}let mr=[],ft,Xe,z,de=(E,K)=>{if(E.type==="md2"){let le=E.model;if(!le.lods||le.lods.length===0)return{model:E.model,type:E.type};let me=E.transform[12]-K.x,oe=E.transform[13]-K.y,_e=E.transform[14]-K.z,it=Math.sqrt(me*me+oe*oe+_e*_e),Vt=Math.floor(it*He/500);if(Vt<=0)return{model:E.model,type:E.type};let Oe=le.lods,Jt=Math.min(Vt-1,Oe.length-1);return{model:Oe[Jt],type:E.type}}return{model:E.model,type:E.type}},ze=(E,K,le)=>{c.startFrame(),b++;let me=mr.length>0?[...K,...mr]:K;mr.length=0,ve=0,E.deltaTime&&u.update(E.deltaTime),t.disable(t.BLEND),t.enable(t.DEPTH_TEST),t.depthMask(!0);let _e=E.renderMode,it=!1;le?.wireframe||T===6?_e={mode:"wireframe",applyToAll:!0,color:[1,1,1,1]}:T===5&&(it=!0);let Vt=E.sky;le?.showSkybox===!1&&(Vt=void 0);let Oe=new Float32Array(E.camera.viewProjectionMatrix),Jt=cr(Oe),Ht=E.dlights?Ec(E.dlights,Jt,{x:E.camera.position[0],y:E.camera.position[1],z:E.camera.position[2]},32):void 0,Ja={...E,sky:Vt,renderMode:_e,disableLightmaps:le?.showLightmaps===!1&&T!==5,dlights:Ht,lightmapOnly:it,brightness:L,gamma:A,fullbright:R,ambient:D,lightStyleOverrides:k,underwaterWarp:F,bloom:U,bloomIntensity:ee,portalState:We},Zs=Ae.renderFrame(Ja),Wf=Zs.facesDrawn||0,Xf=0;E.world&&E.world.map&&E.world.map.faces&&(Xf=E.world.map.faces.length);let lg=Xf-Wf,uu=-1,du=-1,fu=null;if(E.world&&le?.cullingEnabled!==!1){let N={x:E.camera.position[0],y:E.camera.position[1],z:E.camera.position[2]},$e=Pi(E.world.map,N);if($e>=0){let wt=E.world.map.leafs[$e];uu=wt.cluster,du=wt.area,du>=0&&E.world.map.areas.length>0&&(fu=bd(E.world.map,du,We))}}let js,eo=0,hu=0,$f=0,Qs=0,cg={x:E.camera.position[0],y:E.camera.position[1],z:E.camera.position[2]};if(b%_===0)for(let[N,$e]of g)b-$e.lastFrameSeen>x&&g.delete(N);for(let N of me){if(E.world&&uu>=0){let re={x:N.transform[12],y:N.transform[13],z:N.transform[14]},G=-1;if(N.id!==void 0){let Z=g.get(N.id);Z&&Z.position[12]===N.transform[12]&&Z.position[13]===N.transform[13]&&Z.position[14]===N.transform[14]?(G=Z.leafIndex,Z.lastFrameSeen=b):(G=Pi(E.world.map,re),G>=0&&g.set(N.id,{leafIndex:G,position:new Float32Array(N.transform),lastFrameSeen:b}))}else G=Pi(E.world.map,re);if(G>=0){let Z=E.world.map.leafs[G],er=Z.cluster,Ye=Z.area;if(fu&&Ye>=0&&!fu.has(Ye)){Qs++;continue}if(!yd(E.world.map.visibility,uu,er)){Qs++;continue}}}let{model:$e,type:wt}=de(N,cg),Ke,Te;if(wt==="md2"){let re=$e,G=re.frames[N.blend.frame0%re.frames.length],Z=re.frames[N.blend.frame1%re.frames.length];G&&Z&&(Ke={x:Math.min(G.minBounds.x,Z.minBounds.x),y:Math.min(G.minBounds.y,Z.minBounds.y),z:Math.min(G.minBounds.z,Z.minBounds.z)},Te={x:Math.max(G.maxBounds.x,Z.maxBounds.x),y:Math.max(G.maxBounds.y,Z.maxBounds.y),z:Math.max(G.maxBounds.z,Z.maxBounds.z)})}else if(wt==="md3"){let re=$e,G=re.frames[N.blend.frame0%re.frames.length],Z=re.frames[N.blend.frame1%re.frames.length];G&&Z?(Ke={x:Math.min(G.minBounds.x,Z.minBounds.x),y:Math.min(G.minBounds.y,Z.minBounds.y),z:Math.min(G.minBounds.z,Z.minBounds.z)},Te={x:Math.max(G.maxBounds.x,Z.maxBounds.x),y:Math.max(G.maxBounds.y,Z.maxBounds.y),z:Math.max(G.maxBounds.z,Z.maxBounds.z)}):(Ke={x:-32,y:-32,z:-32},Te={x:32,y:32,z:32})}if(Ke&&Te){let re=gm(Ke,Te,N.transform);if(!Li(re.mins,re.maxs,Jt)){Qs++;continue}}$f++;let gr={x:N.transform[12],y:N.transform[13],z:N.transform[14]},at=mp(E.world?.map,gr),De=N.id!==void 0?M.get(N.id):void 0;switch(wt){case"md2":{let re=$e,G=p.get(re);if(G)G.update(re,N.blend);else{G=new Aa(t,re,N.blend),p.set(re,G);let qe=G.geometry.vertices.length*8*4,yn=G.geometry.indices.length*2;c.trackBufferMemory(qe+yn)}let Z=bu(Oe,N.transform),er=N.skin,Ye=er?E.world?.textures?.get(er):void 0;Ye&&Ye!==js&&(Ye.bind(0),js=Ye);let tr=_e;if(tr&&!tr.applyToAll&&Ye&&(tr=void 0),tr?.generateRandomColor&&N.id!==void 0){let qe=Qd(N.id);tr={...tr,color:qe}}if(n.bind({modelViewProjection:Z,modelMatrix:N.transform,ambientLight:at,dlights:E.dlights,renderMode:tr,tint:N.tint,brightness:L,gamma:A,fullbright:R,ambient:D}),n.draw(G,tr),eo++,hu+=G.geometry.vertices.length,De){let qe={mode:"wireframe",applyToAll:!0,color:De};n.bind({modelViewProjection:Z,modelMatrix:N.transform,ambientLight:1,renderMode:qe,tint:[1,1,1,1],brightness:1,gamma:1,fullbright:!0,ambient:0}),n.draw(G,qe),eo++}}break;case"md3":{let re=$e,G=m.get(re),Z=N,er=E.dlights?E.dlights.map(qe=>({origin:qe.origin,color:[qe.color.x,qe.color.y,qe.color.z],radius:qe.intensity})):void 0,Ye={...Z.lighting,ambient:[at,at,at],dynamicLights:er,modelMatrix:N.transform};G?G.update(N.blend,Ye):(G=new Ra(t,re,N.blend,Ye),m.set(re,G));let tr=bu(Oe,N.transform);i.bind(tr);for(let qe of re.surfaces){let yn=G.surfaces.get(qe.name);if(yn){let Yf=Z.skins?.get(qe.name),to=Yf?E.world?.textures?.get(Yf):void 0;to&&to!==js&&(to.bind(0),js=to);let ni=_e;if(ni&&!ni.applyToAll&&to&&(ni=void 0),ni?.generateRandomColor&&N.id!==void 0){let qf=Qd(N.id);ni={...ni,color:qf}}let ug={renderMode:ni,brightness:L,gamma:A,fullbright:R,globalAmbient:D};if(i.drawSurface(yn,ug),eo++,hu+=yn.geometry.vertices.length,De){let dg={renderMode:{mode:"wireframe",applyToAll:!0,color:De},brightness:1,gamma:1,fullbright:!0,globalAmbient:0};i.drawSurface(yn,dg),eo++}}}}break}}let ri=E.camera.viewMatrix;if(ri){let N={x:ri[0],y:ri[4],z:ri[8]},$e={x:ri[1],y:ri[5],z:ri[9]};d.render({viewProjection:Oe,viewRight:N,viewUp:$e})}if(Ja.waterTint&&(ft(),z(0,0,t.canvas.width,t.canvas.height,Ja.waterTint),Xe()),o.render(Oe),o.clear(),E.world&&(w.size>0||T===3)){let N=new Map(w);if(T===3&&E.world){let $e=cr(Oe),wt={x:E.camera.position[0],y:E.camera.position[1],z:E.camera.position[2]},Ke=dn(E.world.map,wt,$e,We);for(let{faceIndex:Te,leafIndex:gr}of Ke){let at=E.world.map.leafs[gr];at&&!N.has(Te)&&N.set(Te,Qd(at.cluster))}}for(let[$e,wt]of N){let Ke=E.world.surfaces[$e];if(Ke&&Ke.vertexCount>0){let Te=[];for(let De=0;De<Ke.vertexCount;De++)Te.push({x:Ke.vertexData[De*7],y:Ke.vertexData[De*7+1],z:Ke.vertexData[De*7+2]});let at={r:wt[0],g:wt[1],b:wt[2]};for(let De=0;De<Te.length;De++){let re=Te[De],G=Te[(De+1)%Te.length];s.drawLine(re,G,at)}s.drawLine(Te[0],Te[Te.length/2|0],at)}}}if((le?.showNormals||T===2)&&E.world){let N=cr(Oe),$e={x:E.camera.position[0],y:E.camera.position[1],z:E.camera.position[2]},wt=dn(E.world.map,$e,N,We);for(let{faceIndex:Ke}of wt){let Te=E.world.map.faces[Ke],gr=E.world.map.planes[Te.planeIndex],at=E.world.surfaces[Ke];if(!at)continue;let De=0,re=0,G=0,Z=at.vertexCount;for(let er=0;er<Z;er++){let Ye=er*7;De+=at.vertexData[Ye],re+=at.vertexData[Ye+1],G+=at.vertexData[Ye+2]}if(Z>0){De/=Z,re/=Z,G/=Z;let er=Te.side===0?gr.normal[0]:-gr.normal[0],Ye=Te.side===0?gr.normal[1]:-gr.normal[1],tr=Te.side===0?gr.normal[2]:-gr.normal[2],qe={x:De,y:re,z:G},yn={x:De+er*8,y:re+Ye*8,z:G+tr*8};s.drawLine(qe,yn,{r:1,g:1,b:0})}}}s.render(Oe);let Kf=s.getLabels(Oe,t.canvas.width,t.canvas.height);if(Kf.length>0){ft();for(let N of Kf)St(N.x,N.y,N.text,[1,1,1,1]);Xe()}s.clear(),S={drawCalls:Zs.drawCalls+eo,vertexCount:Zs.vertexCount+hu,batches:Zs.batches,shaderSwitches:0,visibleSurfaces:Wf,culledSurfaces:lg,visibleEntities:$f,culledEntities:Qs},c.endFrame()},Ue=async(E,K)=>{if(y.has(E))return y.get(E);let le=new Blob([K]),me=await createImageBitmap(le),oe=new dt(t);return oe.upload(me.width,me.height,me),y.set(E,oe),c.trackTextureMemory(me.width*me.height*4),E.includes("conchars")&&(v=oe),oe},pr=(E,K)=>{if(y.has(E))return y.get(E);let le=new dt(t),me=K.levels[0];return le.upload(me.width,me.height,me.rgba),y.set(E,le),c.trackTextureMemory(me.width*me.height*4),E.includes("conchars")&&(v=le),le},Qt=E=>y.get(E);ft=()=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.depthMask(!1);let E=I.create();I.ortho(E,0,t.canvas.width,t.canvas.height,0,-1,1),a.begin(E)},Xe=()=>{t.disable(t.BLEND),t.enable(t.DEPTH_TEST),t.depthMask(!0)};let gn=(E,K,le,me)=>{le.bind(0),a.draw(E,K,le.width,le.height,0,0,1,1,me)},$s=(E,K,le,me)=>{if(!v)return;let oe=8,_e=8,it=v.width/oe,Vt=le&255,Oe=Vt%it*oe/v.width,Jt=Math.floor(Vt/it)*_e/v.height,Ht=Oe+oe/v.width,Ja=Jt+_e/v.height;v.bind(0),a.draw(E,K,oe,_e,Oe,Jt,Ht,Ja,me)},St=(E,K,le,me)=>{let oe=wc(le),_e=E,it=8;for(let Vt of oe){let Oe=Vt.color||me;for(let Jt=0;Jt<Vt.text.length;Jt++)$s(_e,K,Vt.text.charCodeAt(Jt),Oe),_e+=it}},Ks=(E,K)=>{let oe=K.replace(/\^[0-9]/g,"").length*8,_e=(t.canvas.width-oe)/2;St(_e,E,K)};return z=(E,K,le,me,oe)=>{a.drawRect(E,K,le,me,oe)},{get width(){return t.canvas.width},get height(){return t.canvas.height},get collisionVis(){return o},get debug(){return s},get particleSystem(){return u},getPerformanceReport:()=>c.getPerformanceReport(S),getMemoryUsage:()=>c.getMemoryUsage(),renderFrame:ze,registerPic:Ue,registerTexture:pr,getTexture:Qt,begin2D:ft,end2D:Xe,drawPic:gn,drawString:St,drawCenterString:Ks,drawfillRect:z,setEntityHighlight:(E,K)=>{M.set(E,K)},clearEntityHighlight:E=>{M.delete(E)},highlightSurface:(E,K)=>{w.set(E,K)},removeSurfaceHighlight:E=>{w.delete(E)},setDebugMode:E=>{T=E},setBrightness:E=>{L=Math.max(0,Math.min(2,E))},setGamma:E=>{A=Math.max(.5,Math.min(3,E))},setFullbright:E=>{R=E},setAmbient:E=>{D=Math.max(0,Math.min(1,E))},setLightStyle:(E,K)=>{K===null?k.delete(E):k.set(E,K)},setUnderwaterWarp:E=>{F=E},setBloom:E=>{U=E},setBloomIntensity:E=>{ee=E},setLodBias:E=>{He=Math.max(0,Math.min(2,E))},setAreaPortalState:(E,K)=>{E>=0&&E<We.length&&(We[E]=K)},renderInstanced:(E,K)=>{let le="glCommands"in E,me=le?"md2":"md3";for(let oe of K){if(ve>=j){console.warn("Max instances reached");break}let _e=ue[ve++];_e.model=E,_e.type=me;let it=_e.blend;oe.frame!==void 0?(it.frame0=oe.frame,it.frame1=oe.frame,it.lerp=0):(it.frame0=oe.frame0||0,it.frame1=oe.frame1||0,it.lerp=oe.lerp||0),le&&(_e.skin=oe.skin!==void 0?"skin"+oe.skin:void 0);let Vt=oe.rotation,Oe=oe.position,Jt=oe.scale||{x:1,y:1,z:1};I.fromRotationTranslationScale(_e.transform,Ie,nt,jt);let Ht=_e.lighting;Ht&&(Ht.dynamicLights?Ht.dynamicLights.length=0:Ht.dynamicLights=[],Ht.ambient?(Ht.ambient[0]=.5,Ht.ambient[1]=.5,Ht.ambient[2]=.5):Ht.ambient=[.5,.5,.5]),mr.push(_e)}},uploadBspGeometry:E=>{let K=lc(E);return cc(t,K,E)},dispose:()=>{c.dispose()}}};async function Tc(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 f of e.requiredFeatures)if(!r.features.has(f))throw new Error(`Required feature not available: ${f}`)}let n={requiredFeatures:e?.requiredFeatures,requiredLimits:e?.requiredLimits},i=await r.requestDevice(n),a,o="rgba8unorm",s="depth24plus",c=!0,l=e?.width||800,u=e?.height||600;if(t){if(a=t.getContext("webgpu"),!a)throw new Error("Failed to get WebGPU context from canvas");c=!1,o=navigator.gpu.getPreferredCanvasFormat(),l=t.width,u=t.height,a.configure({device:i,format:o,alphaMode:"opaque"})}let d=new Set;for(let f of r.features)d.add(f);return{adapter:r,device:i,context:a,format:o,depthFormat:s,features:d,limits:i.limits,isHeadless:c,width:l,height:u}}function yp(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}}var g_=!0;function y_(t,e){if(!t)return 1;let r=Math.floor(e*10)%t.length;return(t.charCodeAt(r)-97)/12}function b_(t){return[...t].sort((e,r)=>r.sortKey-e.sortKey)}function x_(t){return[...t].sort((e,r)=>e.sortKey-r.sortKey)}var Lc=class{constructor(e,r){this.context=e;this.pipelines=r;h(this,"depthTexture",null);h(this,"copyTexture",null);h(this,"headlessTarget",null);h(this,"lastWidth",0);h(this,"lastHeight",0);h(this,"lastFrameTime",0);h(this,"currentFrameContext",null)}ensureDepthTexture(e,r){return this.depthTexture&&this.lastWidth===e&&this.lastHeight===r?this.depthTexture.createView():(this.depthTexture&&this.depthTexture.destroy(),this.depthTexture=this.context.device.createTexture({size:[e,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT,label:"depth-buffer"}),this.copyTexture&&(this.copyTexture.destroy(),this.copyTexture=null),this.lastWidth=e,this.lastHeight=r,this.depthTexture.createView())}ensureCopyTexture(e,r){return this.copyTexture&&this.lastWidth===e&&this.lastHeight===r?this.copyTexture:(this.copyTexture&&this.copyTexture.destroy(),this.copyTexture=this.context.device.createTexture({size:[e,r],format:this.context.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,label:"frame-copy-texture"}),this.copyTexture)}ensureHeadlessTarget(e,r){return this.headlessTarget&&this.headlessTarget.width===e&&this.headlessTarget.height===r?this.headlessTarget.createView():(this.headlessTarget&&this.headlessTarget.destroy(),this.headlessTarget=this.context.device.createTexture({size:[e,r],format:this.context.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING,label:"headless-render-target"}),this.headlessTarget.createView())}beginFrame(){let{device:e,context:r,width:n,height:i}=this.context,a=e.createCommandEncoder({label:"frame-command-encoder"}),o;r?o=r.getCurrentTexture().createView():o=this.ensureHeadlessTarget(n,i);let s=this.ensureDepthTexture(n,i);return{device:e,commandEncoder:a,renderTarget:o,depthTexture:s,width:n,height:i}}begin2DPass(){if(!this.currentFrameContext)throw new Error("begin2DPass called outside of renderFrame");let{commandEncoder:e,renderTarget:r,width:n,height:i}=this.currentFrameContext;this.pipelines.sprite.setProjection(n,i),this.pipelines.sprite.begin(e,r)}end2DPass(){this.pipelines.sprite.end()}renderFrame(e){let r=performance.now(),n=this.lastFrameTime>0?1e3/(r-this.lastFrameTime):0;this.lastFrameTime=r;let i={batches:0,facesDrawn:0,drawCalls:0,skyDrawn:!1,viewModelDrawn:!1,fps:Math.round(n),vertexCount:0},a=this.beginFrame();this.currentFrameContext=a;let{commandEncoder:o,renderTarget:s,depthTexture:c}=a,{clearColor:l=[0,0,0,1],world:u,camera:d,timeSeconds:f=0,dlights:m,renderMode:p,disableLightmaps:y,lightmapOnly:g,brightness:b,gamma:_,fullbright:x,ambient:v,lightStyleOverrides:S,portalState:M}=e,w=new Float32Array(e.camera.viewProjectionMatrix),T={colorAttachments:[{view:s,clearValue:l,loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:c,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"},label:"opaque-render-pass"},L=o.beginRenderPass(T);if(e.sky&&e.sky.cubemap){if(g_){let D=e.cameraState??e.camera.toState(),k=Ri(e.timeSeconds??0,e.sky.scrollSpeeds??[.01,.02]);this.pipelines.skybox.draw(L,{cameraState:D,scroll:k,cubemap:e.sky.cubemap})}else{let D=Ma(e.camera.viewMatrix),k=I.create();I.multiply(k,e.camera.projectionMatrix,D);let F=Ri(e.timeSeconds??0,e.sky.scrollSpeeds??[.01,.02]);this.pipelines.skybox.draw(L,{viewProjection:k,scroll:F,cubemap:e.sky.cubemap})}i.skyDrawn=!0}let A=[],R=[];if(u){u.materials?.update(f);let D=cr(Array.from(w)),k={x:d.position[0]??0,y:d.position[1]??0,z:d.position[2]??0},F=dn(u.map,k,D,M);for(let j of F){let ue=u.surfaces[j.faceIndex];if(!ue)continue;(ue.surfaceFlags&(_n|Sn|Zr))!==0?R.push(j):A.push(j)}let U=b_(A),ee=u.lightStyles||[];if(S&&S.size>0){let j=[...u.lightStyles||[]];for(let[ue,ve]of S){for(;j.length<=ue;)j.push(1);j[ue]=y_(ve,f)}ee=j}let He=(j,ue,ve)=>{for(let{faceIndex:Ie}of j){let nt=u.surfaces[Ie];if(!nt||(nt.surfaceFlags&vn)!==0)continue;let jt=u.map.faces[Ie]?.styles;this.pipelines.bsp.bind(ue,{modelViewProjection:w,styleIndices:jt,styleValues:ve,surfaceFlags:nt.surfaceFlags,timeSeconds:f,dlights:m,renderMode:p,lightmapOnly:g,brightness:b,gamma:_,fullbright:x,ambient:v,cameraPosition:e.camera.position,surfaceMins:nt.mins}),this.pipelines.bsp.draw(ue,nt,p),i.facesDrawn++,i.drawCalls++,i.vertexCount+=nt.vertexCount}};He(U,L,ee),L.end();let We={colorAttachments:[{view:s,loadOp:"load",storeOp:"store"}],depthStencilAttachment:{view:c,depthLoadOp:"load",depthStoreOp:"store"},label:"transparent-render-pass"},Ae=o.beginRenderPass(We);if(R.length>0){let j=x_(R);He(j,Ae,ee)}Ae.end()}else L.end();return e.underwaterWarp||e.bloom,e.onDraw2D&&e.onDraw2D(),this.pipelines.sprite.isActive&&(console.warn("2D render pass was not properly closed - auto-closing to prevent resource leak"),this.end2DPass()),this.context.device.queue.submit([o.finish()]),this.currentFrameContext=null,i}};var bp=`
|
|
800
|
+
`;function Mc(t){return P.fromValues(t.x,t.y,t.z)}function dr(t){return{x:t[0],y:t[1],z:t[2]}}var Ac=class{constructor(e){f(this,"gl");f(this,"shader");f(this,"vao");f(this,"vbo");f(this,"shaderSolid");f(this,"vaoSolid");f(this,"vboSolid");f(this,"vertices",[]);f(this,"solidVertices",[]);f(this,"labels",[]);this.gl=e,this.shader=he.create(e,{vertex:f_,fragment:h_}),this.vao=new Fe(e),this.vbo=new Be(e,e.DYNAMIC_DRAW),this.vao.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:24,offset:0},{index:1,size:3,type:e.FLOAT,stride:24,offset:12}],this.vbo),this.shaderSolid=he.create(e,{vertex:m_,fragment:p_}),this.vaoSolid=new Fe(e),this.vboSolid=new Be(e,e.DYNAMIC_DRAW),this.vaoSolid.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:3,type:e.FLOAT,stride:36,offset:12},{index:2,size:3,type:e.FLOAT,stride:36,offset:24}],this.vboSolid)}get shaderSize(){return this.shader.sourceSize+this.shaderSolid.sourceSize}drawLine(e,r,n){this.vertices.push(e.x,e.y,e.z,n.r,n.g,n.b,r.x,r.y,r.z,n.r,n.g,n.b)}drawBoundingBox(e,r,n){let{x:i,y:a,z:o}=e,{x:s,y:c,z:l}=r;this.drawLine({x:i,y:a,z:o},{x:s,y:a,z:o},n),this.drawLine({x:s,y:a,z:o},{x:s,y:c,z:o},n),this.drawLine({x:s,y:c,z:o},{x:i,y:c,z:o},n),this.drawLine({x:i,y:c,z:o},{x:i,y:a,z:o},n),this.drawLine({x:i,y:a,z:l},{x:s,y:a,z:l},n),this.drawLine({x:s,y:a,z:l},{x:s,y:c,z:l},n),this.drawLine({x:s,y:c,z:l},{x:i,y:c,z:l},n),this.drawLine({x:i,y:c,z:l},{x:i,y:a,z:l},n),this.drawLine({x:i,y:a,z:o},{x:i,y:a,z:l},n),this.drawLine({x:s,y:a,z:o},{x:s,y:a,z:l},n),this.drawLine({x:s,y:c,z:o},{x:s,y:c,z:l},n),this.drawLine({x:i,y:c,z:o},{x:i,y:c,z:l},n)}drawPoint(e,r,n){let i=r/2;this.drawBoundingBox({x:e.x-i,y:e.y-i,z:e.z-i},{x:e.x+i,y:e.y+i,z:e.z+i},n)}drawAxes(e,r){this.drawLine(e,{x:e.x+r,y:e.y,z:e.z},{r:1,g:0,b:0}),this.drawLine(e,{x:e.x,y:e.y+r,z:e.z},{r:0,g:1,b:0}),this.drawLine(e,{x:e.x,y:e.y,z:e.z+r},{r:0,g:0,b:1})}drawText3D(e,r){this.labels.push({text:e,position:r})}addTriangle(e,r,n,i,a){this.solidVertices.push(e.x,e.y,e.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z),this.solidVertices.push(r.x,r.y,r.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z),this.solidVertices.push(n.x,n.y,n.z),this.solidVertices.push(a.r,a.g,a.b),this.solidVertices.push(i.x,i.y,i.z)}addCone(e,r,n,i){let o=Mc(e),s=Mc(r),c=P.create();P.subtract(c,o,s),P.normalize(c,c);let l=P.fromValues(0,0,1);Math.abs(P.dot(c,l))>.99&&(l=P.fromValues(0,1,0));let u=P.create();P.cross(u,l,c),P.normalize(u,u);let d=P.create();P.cross(d,c,u);let h=[];for(let g=0;g<16;g++){let b=g/16*Math.PI*2,_=Math.cos(b)*n,x=Math.sin(b)*n,v=P.clone(s);P.scaleAndAdd(v,v,u,_),P.scaleAndAdd(v,v,d,x),h.push(v)}let m=P.clone(c);P.scale(m,m,-1);let p=dr(m),y=r;for(let g=0;g<16;g++){let b=dr(h[g]),_=dr(h[(g+1)%16]);this.addTriangle(y,_,b,p,i)}for(let g=0;g<16;g++){let b=h[g],_=h[(g+1)%16],x=dr(b),v=dr(_),w=P.create();P.subtract(w,_,b);let M=P.create();P.subtract(M,o,b);let S=P.create();P.cross(S,w,M),P.normalize(S,S);let E=dr(S);this.addTriangle(x,v,e,E,i)}}addTorus(e,r,n,i,a={x:0,y:0,z:1}){let c=Mc(a);P.normalize(c,c);let l=Mc(e),u=P.fromValues(0,0,1),d=I.create();if(Math.abs(P.dot(c,u))>.999)c[2]<0&&I.rotateX(d,d,Math.PI);else{let p=P.create();P.cross(p,u,c),P.normalize(p,p);let y=Math.acos(P.dot(u,c));I.fromRotation(d,y,p)}let h=[],m=[];for(let p=0;p<=16;p++){let y=p/16*Math.PI*2,g=Math.cos(y),b=Math.sin(y),_=[],x=[];for(let v=0;v<=8;v++){let w=v/8*Math.PI*2,M=Math.cos(w),S=Math.sin(w),E=(r+n*M)*g,L=(r+n*M)*b,A=n*S,R=P.fromValues(E,L,A),D=M*g,k=M*b,F=S,U=P.fromValues(D,k,F);P.transformMat4(R,R,d),P.transformMat4(U,U,d),P.add(R,R,l),_.push(R),x.push(U)}h.push(_),m.push(x)}for(let p=0;p<16;p++)for(let y=0;y<8;y++){let g=h[p][y],b=h[p+1][y],_=h[p+1][y+1],x=h[p][y+1],v=dr(g),w=dr(b),M=dr(_),S=dr(x),E=P.create();P.subtract(E,b,g);let L=P.create();P.subtract(L,_,g);let A=P.create();P.cross(A,E,L),P.normalize(A,A),this.addTriangle(v,w,M,dr(A),i);let R=P.create();P.subtract(R,_,g);let D=P.create();P.subtract(D,x,g);let k=P.create();P.cross(k,R,D),P.normalize(k,k),this.addTriangle(v,M,S,dr(k),i)}}render(e,r=!1){if(r&&this.gl.disable(this.gl.DEPTH_TEST),this.vertices.length>0){this.shader.use();let n=this.shader.getUniformLocation("u_viewProjection");n&&this.gl.uniformMatrix4fv(n,!1,e),this.vbo.upload(new Float32Array(this.vertices)),this.vao.bind(),this.gl.drawArrays(this.gl.LINES,0,this.vertices.length/6)}if(this.solidVertices.length>0){this.shaderSolid.use();let n=this.shaderSolid.getUniformLocation("u_viewProjection");n&&this.gl.uniformMatrix4fv(n,!1,e);let i=this.shaderSolid.getUniformLocation("u_lightingEnabled");i&&this.gl.uniform1i(i,1),this.vboSolid.upload(new Float32Array(this.solidVertices)),this.vaoSolid.bind(),this.gl.drawArrays(this.gl.TRIANGLES,0,this.solidVertices.length/9)}r&&this.gl.enable(this.gl.DEPTH_TEST)}getLabels(e,r,n){let i=[];for(let a of this.labels){let o=Ta.fromValues(a.position.x,a.position.y,a.position.z,1),s=Ta.create(),l=e,u=o[0],d=o[1],h=o[2],m=o[3];if(s[0]=l[0]*u+l[4]*d+l[8]*h+l[12]*m,s[1]=l[1]*u+l[5]*d+l[9]*h+l[13]*m,s[2]=l[2]*u+l[6]*d+l[10]*h+l[14]*m,s[3]=l[3]*u+l[7]*d+l[11]*h+l[15]*m,s[3]>0){let p=s[0]/s[3],y=s[1]/s[3],g=(p+1)*.5*r,b=(1-y)*.5*n;g>=0&&g<=r&&b>=0&&b<=n&&i.push({text:a.text,x:g,y:b})}}return i}clear(){this.vertices=[],this.solidVertices=[],this.labels=[]}};function Ec(t,e,r,n=32){let i=[];for(let s of t){let c=!0;for(let l of e)if(l.normal.x*s.origin.x+l.normal.y*s.origin.y+l.normal.z*s.origin.z+l.distance<-s.intensity){c=!1;break}if(c){let l=0;if(r){let u=s.origin.x-r.x,d=s.origin.y-r.y,h=s.origin.z-r.z;l=u*u+d*d+h*h}i.push({light:s,distSq:l})}}r&&i.sort((s,c)=>s.distSq-c.distSq);let a=[],o=Math.min(i.length,n);for(let s=0;s<o;s++)a.push(i[s].light);return a}function Qd(t){let e=(t*1664525+1013904223>>>0)/4294967296,r=(t*25214903917+11>>>0)/4294967296,n=(t*69069+1>>>0)/4294967296;return[e,r,n,1]}var gp=t=>{let e=new Sa(t),r=new wa(t),n=new Ea(t),i=new Ca(t),a=new Ia(t),o=new _c(t),s=new Ac(t),c=new Sc(t),l=new eh({seed:Date.now()}),u=new Ba(4096,l),d=new Fa(t,u),h=e.shaderSize+r.shaderSize+n.shaderSize+i.shaderSize+a.shaderSize+o.shaderSize+s.shaderSize+d.shaderSize;c.trackShaderMemory(h);let m=new Map,p=new Map,y=new Map,g=new Map,b=0,_=600,x=300,v=null,w={drawCalls:0,vertexCount:0,batches:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0},M=new Map,S=new Map,E=0,L=1,A=1,R=!1,D=0,k=new Map,F=!1,U=!1,ee=.5,He=1,We=new Array(1024).fill(!0),Ae=hp(t,e,r),j=1e4,ue=[],ve=0,Ie=yc.create(),nt=P.create(),jt=P.create();for(let T=0;T<j;T++){let K={id:-1,model:void 0,transform:new Float32Array(16),type:"md3",blend:{frame0:0,frame1:0,lerp:0},tint:[1,1,1,1],lighting:{ambient:[.5,.5,.5],dynamicLights:[],modelMatrix:void 0}};K.lighting&&(K.lighting.modelMatrix=K.transform),ue.push(K)}let mr=[],ft,Xe,z,de=(T,K)=>{if(T.type==="md2"){let le=T.model;if(!le.lods||le.lods.length===0)return{model:T.model,type:T.type};let me=T.transform[12]-K.x,oe=T.transform[13]-K.y,_e=T.transform[14]-K.z,it=Math.sqrt(me*me+oe*oe+_e*_e),Vt=Math.floor(it*He/500);if(Vt<=0)return{model:T.model,type:T.type};let Oe=le.lods,Jt=Math.min(Vt-1,Oe.length-1);return{model:Oe[Jt],type:T.type}}return{model:T.model,type:T.type}},ze=(T,K,le)=>{c.startFrame(),b++;let me=mr.length>0?[...K,...mr]:K;mr.length=0,ve=0,T.deltaTime&&u.update(T.deltaTime),t.disable(t.BLEND),t.enable(t.DEPTH_TEST),t.depthMask(!0);let _e=T.renderMode,it=!1;le?.wireframe||E===6?_e={mode:"wireframe",applyToAll:!0,color:[1,1,1,1]}:E===5&&(it=!0);let Vt=T.sky;le?.showSkybox===!1&&(Vt=void 0);let Oe=new Float32Array(T.camera.viewProjectionMatrix),Jt=cr(Oe),Ht=T.dlights?Ec(T.dlights,Jt,{x:T.camera.position[0],y:T.camera.position[1],z:T.camera.position[2]},32):void 0,Ja={...T,sky:Vt,renderMode:_e,disableLightmaps:le?.showLightmaps===!1&&E!==5,dlights:Ht,lightmapOnly:it,brightness:L,gamma:A,fullbright:R,ambient:D,lightStyleOverrides:k,underwaterWarp:F,bloom:U,bloomIntensity:ee,portalState:We},Zs=Ae.renderFrame(Ja),Wf=Zs.facesDrawn||0,Xf=0;T.world&&T.world.map&&T.world.map.faces&&(Xf=T.world.map.faces.length);let lg=Xf-Wf,uu=-1,du=-1,fu=null;if(T.world&&le?.cullingEnabled!==!1){let N={x:T.camera.position[0],y:T.camera.position[1],z:T.camera.position[2]},$e=Pi(T.world.map,N);if($e>=0){let wt=T.world.map.leafs[$e];uu=wt.cluster,du=wt.area,du>=0&&T.world.map.areas.length>0&&(fu=bd(T.world.map,du,We))}}let js,eo=0,hu=0,$f=0,Qs=0,cg={x:T.camera.position[0],y:T.camera.position[1],z:T.camera.position[2]};if(b%_===0)for(let[N,$e]of g)b-$e.lastFrameSeen>x&&g.delete(N);for(let N of me){if(T.world&&uu>=0){let re={x:N.transform[12],y:N.transform[13],z:N.transform[14]},G=-1;if(N.id!==void 0){let Z=g.get(N.id);Z&&Z.position[12]===N.transform[12]&&Z.position[13]===N.transform[13]&&Z.position[14]===N.transform[14]?(G=Z.leafIndex,Z.lastFrameSeen=b):(G=Pi(T.world.map,re),G>=0&&g.set(N.id,{leafIndex:G,position:new Float32Array(N.transform),lastFrameSeen:b}))}else G=Pi(T.world.map,re);if(G>=0){let Z=T.world.map.leafs[G],er=Z.cluster,Ye=Z.area;if(fu&&Ye>=0&&!fu.has(Ye)){Qs++;continue}if(!yd(T.world.map.visibility,uu,er)){Qs++;continue}}}let{model:$e,type:wt}=de(N,cg),Ke,Te;if(wt==="md2"){let re=$e,G=re.frames[N.blend.frame0%re.frames.length],Z=re.frames[N.blend.frame1%re.frames.length];G&&Z&&(Ke={x:Math.min(G.minBounds.x,Z.minBounds.x),y:Math.min(G.minBounds.y,Z.minBounds.y),z:Math.min(G.minBounds.z,Z.minBounds.z)},Te={x:Math.max(G.maxBounds.x,Z.maxBounds.x),y:Math.max(G.maxBounds.y,Z.maxBounds.y),z:Math.max(G.maxBounds.z,Z.maxBounds.z)})}else if(wt==="md3"){let re=$e,G=re.frames[N.blend.frame0%re.frames.length],Z=re.frames[N.blend.frame1%re.frames.length];G&&Z?(Ke={x:Math.min(G.minBounds.x,Z.minBounds.x),y:Math.min(G.minBounds.y,Z.minBounds.y),z:Math.min(G.minBounds.z,Z.minBounds.z)},Te={x:Math.max(G.maxBounds.x,Z.maxBounds.x),y:Math.max(G.maxBounds.y,Z.maxBounds.y),z:Math.max(G.maxBounds.z,Z.maxBounds.z)}):(Ke={x:-32,y:-32,z:-32},Te={x:32,y:32,z:32})}if(Ke&&Te){let re=gm(Ke,Te,N.transform);if(!Li(re.mins,re.maxs,Jt)){Qs++;continue}}$f++;let gr={x:N.transform[12],y:N.transform[13],z:N.transform[14]},at=mp(T.world?.map,gr),De=N.id!==void 0?M.get(N.id):void 0;switch(wt){case"md2":{let re=$e,G=p.get(re);if(G)G.update(re,N.blend);else{G=new Aa(t,re,N.blend),p.set(re,G);let qe=G.geometry.vertices.length*8*4,yn=G.geometry.indices.length*2;c.trackBufferMemory(qe+yn)}let Z=bu(Oe,N.transform),er=N.skin,Ye=er?T.world?.textures?.get(er):void 0;Ye&&Ye!==js&&(Ye.bind(0),js=Ye);let tr=_e;if(tr&&!tr.applyToAll&&Ye&&(tr=void 0),tr?.generateRandomColor&&N.id!==void 0){let qe=Qd(N.id);tr={...tr,color:qe}}if(n.bind({modelViewProjection:Z,modelMatrix:N.transform,ambientLight:at,dlights:T.dlights,renderMode:tr,tint:N.tint,brightness:L,gamma:A,fullbright:R,ambient:D}),n.draw(G,tr),eo++,hu+=G.geometry.vertices.length,De){let qe={mode:"wireframe",applyToAll:!0,color:De};n.bind({modelViewProjection:Z,modelMatrix:N.transform,ambientLight:1,renderMode:qe,tint:[1,1,1,1],brightness:1,gamma:1,fullbright:!0,ambient:0}),n.draw(G,qe),eo++}}break;case"md3":{let re=$e,G=m.get(re),Z=N,er=T.dlights?T.dlights.map(qe=>({origin:qe.origin,color:[qe.color.x,qe.color.y,qe.color.z],radius:qe.intensity})):void 0,Ye={...Z.lighting,ambient:[at,at,at],dynamicLights:er,modelMatrix:N.transform};G?G.update(N.blend,Ye):(G=new Ra(t,re,N.blend,Ye),m.set(re,G));let tr=bu(Oe,N.transform);i.bind(tr);for(let qe of re.surfaces){let yn=G.surfaces.get(qe.name);if(yn){let Yf=Z.skins?.get(qe.name),to=Yf?T.world?.textures?.get(Yf):void 0;to&&to!==js&&(to.bind(0),js=to);let ni=_e;if(ni&&!ni.applyToAll&&to&&(ni=void 0),ni?.generateRandomColor&&N.id!==void 0){let qf=Qd(N.id);ni={...ni,color:qf}}let ug={renderMode:ni,brightness:L,gamma:A,fullbright:R,globalAmbient:D};if(i.drawSurface(yn,ug),eo++,hu+=yn.geometry.vertices.length,De){let dg={renderMode:{mode:"wireframe",applyToAll:!0,color:De},brightness:1,gamma:1,fullbright:!0,globalAmbient:0};i.drawSurface(yn,dg),eo++}}}}break}}let ri=T.camera.viewMatrix;if(ri){let N={x:ri[0],y:ri[4],z:ri[8]},$e={x:ri[1],y:ri[5],z:ri[9]};d.render({viewProjection:Oe,viewRight:N,viewUp:$e})}if(Ja.waterTint&&(ft(),z(0,0,t.canvas.width,t.canvas.height,Ja.waterTint),Xe()),o.render(Oe),o.clear(),T.world&&(S.size>0||E===3)){let N=new Map(S);if(E===3&&T.world){let $e=cr(Oe),wt={x:T.camera.position[0],y:T.camera.position[1],z:T.camera.position[2]},Ke=dn(T.world.map,wt,$e,We);for(let{faceIndex:Te,leafIndex:gr}of Ke){let at=T.world.map.leafs[gr];at&&!N.has(Te)&&N.set(Te,Qd(at.cluster))}}for(let[$e,wt]of N){let Ke=T.world.surfaces[$e];if(Ke&&Ke.vertexCount>0){let Te=[];for(let De=0;De<Ke.vertexCount;De++)Te.push({x:Ke.vertexData[De*7],y:Ke.vertexData[De*7+1],z:Ke.vertexData[De*7+2]});let at={r:wt[0],g:wt[1],b:wt[2]};for(let De=0;De<Te.length;De++){let re=Te[De],G=Te[(De+1)%Te.length];s.drawLine(re,G,at)}s.drawLine(Te[0],Te[Te.length/2|0],at)}}}if((le?.showNormals||E===2)&&T.world){let N=cr(Oe),$e={x:T.camera.position[0],y:T.camera.position[1],z:T.camera.position[2]},wt=dn(T.world.map,$e,N,We);for(let{faceIndex:Ke}of wt){let Te=T.world.map.faces[Ke],gr=T.world.map.planes[Te.planeIndex],at=T.world.surfaces[Ke];if(!at)continue;let De=0,re=0,G=0,Z=at.vertexCount;for(let er=0;er<Z;er++){let Ye=er*7;De+=at.vertexData[Ye],re+=at.vertexData[Ye+1],G+=at.vertexData[Ye+2]}if(Z>0){De/=Z,re/=Z,G/=Z;let er=Te.side===0?gr.normal[0]:-gr.normal[0],Ye=Te.side===0?gr.normal[1]:-gr.normal[1],tr=Te.side===0?gr.normal[2]:-gr.normal[2],qe={x:De,y:re,z:G},yn={x:De+er*8,y:re+Ye*8,z:G+tr*8};s.drawLine(qe,yn,{r:1,g:1,b:0})}}}s.render(Oe);let Kf=s.getLabels(Oe,t.canvas.width,t.canvas.height);if(Kf.length>0){ft();for(let N of Kf)St(N.x,N.y,N.text,[1,1,1,1]);Xe()}s.clear(),w={drawCalls:Zs.drawCalls+eo,vertexCount:Zs.vertexCount+hu,batches:Zs.batches,shaderSwitches:0,visibleSurfaces:Wf,culledSurfaces:lg,visibleEntities:$f,culledEntities:Qs},c.endFrame()},Ue=async(T,K)=>{if(y.has(T))return y.get(T);let le=new Blob([K]),me=await createImageBitmap(le),oe=new dt(t);return oe.upload(me.width,me.height,me),y.set(T,oe),c.trackTextureMemory(me.width*me.height*4),T.includes("conchars")&&(v=oe),oe},pr=(T,K)=>{if(y.has(T))return y.get(T);let le=new dt(t),me=K.levels[0];return le.upload(me.width,me.height,me.rgba),y.set(T,le),c.trackTextureMemory(me.width*me.height*4),T.includes("conchars")&&(v=le),le},Qt=T=>y.get(T);ft=()=>{t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.disable(t.DEPTH_TEST),t.depthMask(!1);let T=I.create();I.ortho(T,0,t.canvas.width,t.canvas.height,0,-1,1),a.begin(T)},Xe=()=>{t.disable(t.BLEND),t.enable(t.DEPTH_TEST),t.depthMask(!0)};let gn=(T,K,le,me)=>{le.bind(0),a.draw(T,K,le.width,le.height,0,0,1,1,me)},$s=(T,K,le,me)=>{if(!v)return;let oe=8,_e=8,it=v.width/oe,Vt=le&255,Oe=Vt%it*oe/v.width,Jt=Math.floor(Vt/it)*_e/v.height,Ht=Oe+oe/v.width,Ja=Jt+_e/v.height;v.bind(0),a.draw(T,K,oe,_e,Oe,Jt,Ht,Ja,me)},St=(T,K,le,me)=>{let oe=wc(le),_e=T,it=8;for(let Vt of oe){let Oe=Vt.color||me;for(let Jt=0;Jt<Vt.text.length;Jt++)$s(_e,K,Vt.text.charCodeAt(Jt),Oe),_e+=it}},Ks=(T,K)=>{let oe=K.replace(/\^[0-9]/g,"").length*8,_e=(t.canvas.width-oe)/2;St(_e,T,K)};return z=(T,K,le,me,oe)=>{a.drawRect(T,K,le,me,oe)},{get width(){return t.canvas.width},get height(){return t.canvas.height},get collisionVis(){return o},get debug(){return s},get particleSystem(){return u},getPerformanceReport:()=>c.getPerformanceReport(w),getMemoryUsage:()=>c.getMemoryUsage(),renderFrame:ze,registerPic:Ue,registerTexture:pr,getTexture:Qt,begin2D:ft,end2D:Xe,drawPic:gn,drawString:St,drawCenterString:Ks,drawfillRect:z,setEntityHighlight:(T,K)=>{M.set(T,K)},clearEntityHighlight:T=>{M.delete(T)},highlightSurface:(T,K)=>{S.set(T,K)},removeSurfaceHighlight:T=>{S.delete(T)},setDebugMode:T=>{E=T},setBrightness:T=>{L=Math.max(0,Math.min(2,T))},setGamma:T=>{A=Math.max(.5,Math.min(3,T))},setFullbright:T=>{R=T},setAmbient:T=>{D=Math.max(0,Math.min(1,T))},setLightStyle:(T,K)=>{K===null?k.delete(T):k.set(T,K)},setUnderwaterWarp:T=>{F=T},setBloom:T=>{U=T},setBloomIntensity:T=>{ee=T},setLodBias:T=>{He=Math.max(0,Math.min(2,T))},setAreaPortalState:(T,K)=>{T>=0&&T<We.length&&(We[T]=K)},renderInstanced:(T,K)=>{let le="glCommands"in T,me=le?"md2":"md3";for(let oe of K){if(ve>=j){console.warn("Max instances reached");break}let _e=ue[ve++];_e.model=T,_e.type=me;let it=_e.blend;oe.frame!==void 0?(it.frame0=oe.frame,it.frame1=oe.frame,it.lerp=0):(it.frame0=oe.frame0||0,it.frame1=oe.frame1||0,it.lerp=oe.lerp||0),le&&(_e.skin=oe.skin!==void 0?"skin"+oe.skin:void 0);let Vt=oe.rotation,Oe=oe.position,Jt=oe.scale||{x:1,y:1,z:1};I.fromRotationTranslationScale(_e.transform,Ie,nt,jt);let Ht=_e.lighting;Ht&&(Ht.dynamicLights?Ht.dynamicLights.length=0:Ht.dynamicLights=[],Ht.ambient?(Ht.ambient[0]=.5,Ht.ambient[1]=.5,Ht.ambient[2]=.5):Ht.ambient=[.5,.5,.5]),mr.push(_e)}},uploadBspGeometry:T=>{let K=lc(T);return cc(t,K,T)},dispose:()=>{c.dispose()}}};async function Tc(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 h of e.requiredFeatures)if(!r.features.has(h))throw new Error(`Required feature not available: ${h}`)}let n={requiredFeatures:e?.requiredFeatures,requiredLimits:e?.requiredLimits},i=await r.requestDevice(n),a,o="rgba8unorm",s="depth24plus",c=!0,l=e?.width||800,u=e?.height||600;if(t){if(a=t.getContext("webgpu"),!a)throw new Error("Failed to get WebGPU context from canvas");c=!1,o=navigator.gpu.getPreferredCanvasFormat(),l=t.width,u=t.height,a.configure({device:i,format:o,alphaMode:"opaque"})}let d=new Set;for(let h of r.features)d.add(h);return{adapter:r,device:i,context:a,format:o,depthFormat:s,features:d,limits:i.limits,isHeadless:c,width:l,height:u}}function yp(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}}var g_=!0;function y_(t,e){if(!t)return 1;let r=Math.floor(e*10)%t.length;return(t.charCodeAt(r)-97)/12}function b_(t){return[...t].sort((e,r)=>r.sortKey-e.sortKey)}function x_(t){return[...t].sort((e,r)=>e.sortKey-r.sortKey)}var Lc=class{constructor(e,r){this.context=e;this.pipelines=r;f(this,"depthTexture",null);f(this,"copyTexture",null);f(this,"headlessTarget",null);f(this,"lastWidth",0);f(this,"lastHeight",0);f(this,"lastFrameTime",0);f(this,"currentFrameContext",null)}ensureDepthTexture(e,r){return this.depthTexture&&this.lastWidth===e&&this.lastHeight===r?this.depthTexture.createView():(this.depthTexture&&this.depthTexture.destroy(),this.depthTexture=this.context.device.createTexture({size:[e,r],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT,label:"depth-buffer"}),this.copyTexture&&(this.copyTexture.destroy(),this.copyTexture=null),this.lastWidth=e,this.lastHeight=r,this.depthTexture.createView())}ensureCopyTexture(e,r){return this.copyTexture&&this.lastWidth===e&&this.lastHeight===r?this.copyTexture:(this.copyTexture&&this.copyTexture.destroy(),this.copyTexture=this.context.device.createTexture({size:[e,r],format:this.context.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,label:"frame-copy-texture"}),this.copyTexture)}ensureHeadlessTarget(e,r){return this.headlessTarget&&this.headlessTarget.width===e&&this.headlessTarget.height===r?this.headlessTarget.createView():(this.headlessTarget&&this.headlessTarget.destroy(),this.headlessTarget=this.context.device.createTexture({size:[e,r],format:this.context.format,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC|GPUTextureUsage.TEXTURE_BINDING,label:"headless-render-target"}),this.headlessTarget.createView())}beginFrame(){let{device:e,context:r,width:n,height:i}=this.context,a=e.createCommandEncoder({label:"frame-command-encoder"}),o;r?o=r.getCurrentTexture().createView():o=this.ensureHeadlessTarget(n,i);let s=this.ensureDepthTexture(n,i);return{device:e,commandEncoder:a,renderTarget:o,depthTexture:s,width:n,height:i}}begin2DPass(){if(!this.currentFrameContext)throw new Error("begin2DPass called outside of renderFrame");let{commandEncoder:e,renderTarget:r,width:n,height:i}=this.currentFrameContext;this.pipelines.sprite.setProjection(n,i),this.pipelines.sprite.begin(e,r)}end2DPass(){this.pipelines.sprite.end()}renderFrame(e){let r=performance.now(),n=this.lastFrameTime>0?1e3/(r-this.lastFrameTime):0;this.lastFrameTime=r;let i={batches:0,facesDrawn:0,drawCalls:0,skyDrawn:!1,viewModelDrawn:!1,fps:Math.round(n),vertexCount:0},a=this.beginFrame();this.currentFrameContext=a;let{commandEncoder:o,renderTarget:s,depthTexture:c}=a,{clearColor:l=[0,0,0,1],world:u,camera:d,timeSeconds:h=0,dlights:m,renderMode:p,disableLightmaps:y,lightmapOnly:g,brightness:b,gamma:_,fullbright:x,ambient:v,lightStyleOverrides:w,portalState:M}=e,S=new Float32Array(e.camera.viewProjectionMatrix),E={colorAttachments:[{view:s,clearValue:l,loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:c,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"},label:"opaque-render-pass"},L=o.beginRenderPass(E);if(e.sky&&e.sky.cubemap){if(g_){let D=e.cameraState??e.camera.toState(),k=Ri(e.timeSeconds??0,e.sky.scrollSpeeds??[.01,.02]);this.pipelines.skybox.draw(L,{cameraState:D,scroll:k,cubemap:e.sky.cubemap})}else{let D=Ma(e.camera.viewMatrix),k=I.create();I.multiply(k,e.camera.projectionMatrix,D);let F=Ri(e.timeSeconds??0,e.sky.scrollSpeeds??[.01,.02]);this.pipelines.skybox.draw(L,{viewProjection:k,scroll:F,cubemap:e.sky.cubemap})}i.skyDrawn=!0}let A=[],R=[];if(u){u.materials?.update(h);let D=cr(Array.from(S)),k={x:d.position[0]??0,y:d.position[1]??0,z:d.position[2]??0},F=dn(u.map,k,D,M);for(let j of F){let ue=u.surfaces[j.faceIndex];if(!ue)continue;(ue.surfaceFlags&(_n|Sn|Zr))!==0?R.push(j):A.push(j)}let U=b_(A),ee=u.lightStyles||[];if(w&&w.size>0){let j=[...u.lightStyles||[]];for(let[ue,ve]of w){for(;j.length<=ue;)j.push(1);j[ue]=y_(ve,h)}ee=j}let He=(j,ue,ve)=>{for(let{faceIndex:Ie}of j){let nt=u.surfaces[Ie];if(!nt||(nt.surfaceFlags&vn)!==0)continue;let jt=u.map.faces[Ie]?.styles;this.pipelines.bsp.bind(ue,{modelViewProjection:S,styleIndices:jt,styleValues:ve,surfaceFlags:nt.surfaceFlags,timeSeconds:h,dlights:m,renderMode:p,lightmapOnly:g,brightness:b,gamma:_,fullbright:x,ambient:v,cameraPosition:e.camera.position,surfaceMins:nt.mins}),this.pipelines.bsp.draw(ue,nt,p),i.facesDrawn++,i.drawCalls++,i.vertexCount+=nt.vertexCount}};He(U,L,ee),L.end();let We={colorAttachments:[{view:s,loadOp:"load",storeOp:"store"}],depthStencilAttachment:{view:c,depthLoadOp:"load",depthStoreOp:"store"},label:"transparent-render-pass"},Ae=o.beginRenderPass(We);if(R.length>0){let j=x_(R);He(j,Ae,ee)}Ae.end()}else L.end();return e.underwaterWarp||e.bloom,e.onDraw2D&&e.onDraw2D(),this.pipelines.sprite.isActive&&(console.warn("2D render pass was not properly closed - auto-closing to prevent resource leak"),this.end2DPass()),this.context.device.queue.submit([o.finish()]),this.currentFrameContext=null,i}};var bp=`
|
|
801
801
|
struct VSOutput {
|
|
802
802
|
@builtin(position) position: vec4f,
|
|
803
803
|
@location(0) texcoord: vec2f,
|
|
@@ -827,7 +827,7 @@ fn vs_main(@builtin(vertex_index) vertexIndex : u32) -> VSOutput {
|
|
|
827
827
|
fn fs_main(in: VSOutput) -> @location(0) vec4f {
|
|
828
828
|
return textureSample(img, imgSampler, in.texcoord);
|
|
829
829
|
}
|
|
830
|
-
`;var Pc;var Da=class{constructor(e,r){this.device=e;
|
|
830
|
+
`;var Pc;var Da=class{constructor(e,r){this.device=e;f(this,"buffer");f(this,"size");f(this,"usage");this.size=Math.ceil(r.size/4)*4,this.usage=r.usage,this.buffer=e.createBuffer({size:this.size,usage:this.usage,label:r.label,mappedAtCreation:r.mappedAtCreation}),Pc?.trackBuffer(this)}write(e,r=0){let n=e.byteLength;if(r+n>this.size)throw new Error(`Buffer write out of bounds: offset ${r} + data ${n} > buffer ${this.size}`);this.device.queue.writeBuffer(this.buffer,r,e,0)}async mapAsync(e,r=0,n){await this.buffer.mapAsync(e,r,n)}getMappedRange(e=0,r){return this.buffer.getMappedRange(e,r)}unmap(){this.buffer.unmap()}destroy(){Pc?.untrackBuffer(this),this.buffer.destroy()}},ka=class extends Da{constructor(e,r){super(e,{size:r.size,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|(r.usage||0),label:r.label})}},Ua=class extends Da{constructor(e,r){super(e,{size:r.size,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST|(r.usage||0),label:r.label})}},Rc=class extends Da{constructor(e,r){super(e,{size:r.size,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST|(r.usage||0),label:r.label})}};function xp(t){switch(t){case"rgba8unorm":case"rgba8unorm-srgb":case"bgra8unorm":case"bgra8unorm-srgb":case"rgba8sint":case"rgba8uint":return 4;case"rg8unorm":case"rg8sint":case"rg8uint":case"r16float":case"r16sint":case"r16uint":return 2;case"r8unorm":case"r8sint":case"r8uint":return 1;case"rgba16float":case"rgba16sint":case"rgba16uint":return 8;case"rgba32float":case"rgba32sint":case"rgba32uint":return 16;case"depth24plus":case"depth24plus-stencil8":case"depth32float":return 4;default:return 4}}var Kn=class Kn{constructor(e,r){this.device=e;f(this,"texture");f(this,"width");f(this,"height");f(this,"format");this.width=r.width,this.height=r.height,this.format=r.format;let n=r.usage??GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT;this.texture=e.createTexture({size:[this.width,this.height,1],format:this.format,usage:n,mipLevelCount:r.mipLevelCount??1,label:r.label}),Pc?.trackTexture(this)}upload(e,r={}){let n=r.width??this.width,i=r.height??this.height,a=r.depthOrArrayLayers??1,o=r.mipLevel??0,s=xp(this.format),c=r.bytesPerRow;c||(c=n*s),this.device.queue.writeTexture({texture:this.texture,mipLevel:o,origin:{x:0,y:0,z:0}},e,{offset:0,bytesPerRow:c,rowsPerImage:r.rowsPerImage??i},{width:n,height:i,depthOrArrayLayers:a})}getMipmapPipeline(e){let r=Kn.mipmapPipelines.get(this.device);r||(r=new Map,Kn.mipmapPipelines.set(this.device,r));let n=r.get(e);if(!n){let i=this.device.createShaderModule({code:bp,label:"mipmap-shader"});n=this.device.createRenderPipeline({layout:"auto",vertex:{module:i,entryPoint:"vs_main"},fragment:{module:i,entryPoint:"fs_main",targets:[{format:e}]},primitive:{topology:"triangle-list"},label:`mipmap-pipeline-${e}`}),r.set(e,n)}return n}getMipmapSampler(){let e=Kn.mipmapSamplers.get(this.device);return e||(e=this.device.createSampler({minFilter:"linear",magFilter:"linear",label:"mipmap-sampler"}),Kn.mipmapSamplers.set(this.device,e)),e}generateMipmaps(e){let r=this.texture.mipLevelCount;if(r<=1)return;let n=this.getMipmapPipeline(this.format),i=this.getMipmapSampler();for(let a=1;a<r;a++){let o=this.texture.createView({baseMipLevel:a-1,mipLevelCount:1,label:`mipmap-src-${a-1}`}),s=this.texture.createView({baseMipLevel:a,mipLevelCount:1,label:`mipmap-dst-${a}`}),c=e.beginRenderPass({colorAttachments:[{view:s,loadOp:"clear",storeOp:"store"}],label:`mipmap-pass-${a}`}),l=this.device.createBindGroup({layout:n.getBindGroupLayout(0),entries:[{binding:0,resource:i},{binding:1,resource:o}],label:`mipmap-bindgroup-${a}`});c.setPipeline(n),c.setBindGroup(0,l),c.draw(6),c.end()}}createView(e){return this.texture.createView(e)}destroy(){Pc?.untrackTexture(this),this.texture.destroy()}get memorySize(){let e=xp(this.format),r=0,n=this.width,i=this.height,a=this.texture.mipLevelCount;for(let o=0;o<a;o++)r+=n*i*e,n=Math.max(1,Math.floor(n/2)),i=Math.max(1,Math.floor(i/2));return r}};f(Kn,"mipmapPipelines",new WeakMap),f(Kn,"mipmapSamplers",new WeakMap);var Yn=Kn;var Cc=class{constructor(e,r){f(this,"sampler");this.sampler=e.createSampler({...r,label:r.label})}destroy(){}};function Fc(t){return new Cc(t,{minFilter:"linear",magFilter:"linear",mipmapFilter:"linear",label:"linear-sampler"})}var Bc=class{constructor(e,r){this.device=e;f(this,"module");this.module=e.createShaderModule({code:r.code,label:r.label})}get compilationInfo(){return this.module.getCompilationInfo()}},vs=class{constructor(e,r){this.device=e;f(this,"pipeline");let n=r.layout;this.pipeline=e.createRenderPipeline({layout:n,vertex:{module:r.vertex.module.module,entryPoint:r.vertex.entryPoint,buffers:r.vertex.buffers},fragment:r.fragment?{module:r.fragment.module.module,entryPoint:r.fragment.entryPoint,targets:r.fragment.targets}:void 0,primitive:r.primitive,depthStencil:r.depthStencil,multisample:r.multisample,label:r.label})}get layout(){throw new Error("Cannot retrieve layout from pipeline created with 'auto' layout")}destroy(){}};var Jd=class{constructor(e,r){this.device=e;f(this,"layout");this.layout=e.createBindGroupLayout({entries:r.entries,label:r.label})}},_s=class{constructor(e,r,n,i){this.device=e;f(this,"bindGroup");let a=n.map(o=>{let s;return o.resource instanceof Da?s={buffer:o.resource.buffer}:o.resource instanceof Cc?s=o.resource.sampler:s=o.resource,{binding:o.binding,resource:s}});this.bindGroup=e.createBindGroup({layout:r.layout,entries:a,label:i})}destroy(){}},Ss=class{constructor(e){this.label=e;f(this,"entries",[])}addUniformBuffer(e,r){return this.entries.push({binding:e,visibility:r,buffer:{type:"uniform"}}),this}addStorageBuffer(e,r,n="read-only-storage"){return this.entries.push({binding:e,visibility:r,buffer:{type:n}}),this}addTexture(e,r,n="float",i="2d"){return this.entries.push({binding:e,visibility:r,texture:{sampleType:n,viewDimension:i}}),this}addSampler(e,r,n="filtering"){return this.entries.push({binding:e,visibility:r,sampler:{type:n}}),this}build(e){return new Jd(e,{entries:this.entries,label:this.label})}};var vp=`
|
|
831
831
|
// Sprite Rendering Shader (WGSL)
|
|
832
832
|
|
|
833
833
|
struct VertexInput {
|
|
@@ -871,7 +871,7 @@ fn fs_main(input: VertexOutput) -> @location(0) vec4f {
|
|
|
871
871
|
fn fs_solid(input: VertexOutput) -> @location(0) vec4f {
|
|
872
872
|
return input.color;
|
|
873
873
|
}
|
|
874
|
-
`;var za=2048,Ic=4,_p=6,ws=8,Dc=class{constructor(e,r){this.device=e;this.format=r;
|
|
874
|
+
`;var za=2048,Ic=4,_p=6,ws=8,Dc=class{constructor(e,r){this.device=e;this.format=r;f(this,"pipelineTextured");f(this,"pipelineSolid");f(this,"vertexBuffer");f(this,"indexBuffer");f(this,"uniformBuffer");f(this,"uniformBindGroup");f(this,"textureBindGroupLayout");f(this,"defaultSampler");f(this,"projectionMatrix");f(this,"vertexData");f(this,"currentVertexCount",0);f(this,"currentIndexCount",0);f(this,"currentTexture",null);f(this,"drawCommands",[]);f(this,"textureBindGroups",new Map);f(this,"_activeEncoder",null);f(this,"_activeRenderTarget",null);let n=new Bc(e,{code:vp,label:"sprite-shader"}),i={arrayStride:ws*4,stepMode:"vertex",attributes:[{format:"float32x2",offset:0,shaderLocation:0},{format:"float32x2",offset:8,shaderLocation:1},{format:"float32x4",offset:16,shaderLocation:2}]},a=new Ss("sprite-uniform-layout");a.addUniformBuffer(0,GPUShaderStage.VERTEX);let o=a.build(e),s=new Ss("sprite-texture-layout");s.addSampler(0,GPUShaderStage.FRAGMENT),s.addTexture(1,GPUShaderStage.FRAGMENT),this.textureBindGroupLayout=s.build(e);let c=e.createPipelineLayout({bindGroupLayouts:[o.layout,this.textureBindGroupLayout.layout],label:"sprite-pipeline-layout"}),l=e.createPipelineLayout({bindGroupLayouts:[o.layout],label:"sprite-pipeline-solid-layout"}),u={color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}};this.pipelineTextured=new vs(e,{layout:c,vertex:{module:n,entryPoint:"vs_main",buffers:[i]},fragment:{module:n,entryPoint:"fs_main",targets:[{format:this.format,blend:u}]},primitive:{topology:"triangle-list",cullMode:"none"},label:"sprite-pipeline-textured"}),this.pipelineSolid=new vs(e,{layout:l,vertex:{module:n,entryPoint:"vs_main",buffers:[i]},fragment:{module:n,entryPoint:"fs_solid",targets:[{format:this.format,blend:u}]},primitive:{topology:"triangle-list",cullMode:"none"},label:"sprite-pipeline-solid"}),this.vertexBuffer=new ka(e,{size:za*Ic*ws*4,label:"sprite-vertex-buffer",usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),this.indexBuffer=new Ua(e,{size:za*_p*2,label:"sprite-index-buffer",usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST}),this.uniformBuffer=new Rc(e,{size:64,label:"sprite-uniform-buffer",usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.uniformBindGroup=new _s(e,o,[{binding:0,resource:this.uniformBuffer}],"sprite-uniform-bind-group"),this.vertexData=new Float32Array(za*Ic*ws);let d=new Uint16Array(za*_p);for(let h=0;h<za;h++){let m=h*4,p=h*6;d[p]=m,d[p+1]=m+1,d[p+2]=m+2,d[p+3]=m,d[p+4]=m+2,d[p+5]=m+3}this.indexBuffer.write(d),this.projectionMatrix=I.create(),this.defaultSampler=Fc(e)}setProjection(e,r){I.ortho(this.projectionMatrix,0,e,r,0,-1,1),this.uniformBuffer.write(this.projectionMatrix)}begin(e,r){this.currentVertexCount=0,this.currentIndexCount=0,this.drawCommands=[],this.currentTexture=null,this._activeEncoder=e,this._activeRenderTarget=r}drawTexturedQuad(e,r,n,i,a,o=0,s=0,c=1,l=1,u=[1,1,1,1]){this.currentVertexCount+Ic>za*Ic&&this.flush(),(this.drawCommands.length===0||this.currentTexture!==a)&&(this.drawCommands.push({texture:a,start:this.currentIndexCount,count:0}),this.currentTexture=a);let d=this.currentVertexCount*ws,[h,m,p,y]=u;this.vertexData[d]=e,this.vertexData[d+1]=r,this.vertexData[d+2]=o,this.vertexData[d+3]=s,this.vertexData[d+4]=h,this.vertexData[d+5]=m,this.vertexData[d+6]=p,this.vertexData[d+7]=y,this.vertexData[d+8]=e,this.vertexData[d+9]=r+i,this.vertexData[d+10]=o,this.vertexData[d+11]=l,this.vertexData[d+12]=h,this.vertexData[d+13]=m,this.vertexData[d+14]=p,this.vertexData[d+15]=y,this.vertexData[d+16]=e+n,this.vertexData[d+17]=r+i,this.vertexData[d+18]=c,this.vertexData[d+19]=l,this.vertexData[d+20]=h,this.vertexData[d+21]=m,this.vertexData[d+22]=p,this.vertexData[d+23]=y,this.vertexData[d+24]=e+n,this.vertexData[d+25]=r,this.vertexData[d+26]=c,this.vertexData[d+27]=s,this.vertexData[d+28]=h,this.vertexData[d+29]=m,this.vertexData[d+30]=p,this.vertexData[d+31]=y,this.currentVertexCount+=4,this.currentIndexCount+=6,this.drawCommands[this.drawCommands.length-1].count+=6}drawSolidRect(e,r,n,i,a){this.currentTexture!==null&&(this.drawCommands.push({texture:null,start:this.currentIndexCount,count:0}),this.currentTexture=null),this.drawTexturedQuad(e,r,n,i,null,0,0,0,0,a)}flush(){if(this.currentVertexCount===0||!this._activeEncoder||!this._activeRenderTarget)return;let e=this.currentVertexCount*ws;this.vertexBuffer.write(this.vertexData.subarray(0,e));let r=this._activeEncoder.beginRenderPass({colorAttachments:[{view:this._activeRenderTarget,loadOp:"load",storeOp:"store"}],label:"sprite-pass"});r.setBindGroup(0,this.uniformBindGroup.bindGroup),r.setVertexBuffer(0,this.vertexBuffer.buffer),r.setIndexBuffer(this.indexBuffer.buffer,"uint16");for(let n of this.drawCommands)if(n.count!==0){if(n.texture){r.setPipeline(this.pipelineTextured.pipeline);let i=this.textureBindGroups.get(n.texture);i||(i=new _s(this.device,this.textureBindGroupLayout,[{binding:0,resource:this.defaultSampler},{binding:1,resource:n.texture.createView()}],`sprite-texture-bind-group-${n.texture.texture.label}`),this.textureBindGroups.set(n.texture,i)),r.setBindGroup(1,i.bindGroup)}else r.setPipeline(this.pipelineSolid.pipeline);r.drawIndexed(n.count,1,n.start,0,0)}r.end(),this.currentVertexCount=0,this.currentIndexCount=0,this.drawCommands=[],this.currentTexture=null}end(){this.flush(),this._activeEncoder=null,this._activeRenderTarget=null}get isActive(){return this._activeEncoder!==null}destroy(){this.vertexBuffer.destroy(),this.indexBuffer.destroy(),this.uniformBuffer.destroy()}};var Sp=`// Skybox shader using full-screen triangle approach
|
|
875
875
|
// This avoids the w\u22480 issue with cube geometry at diagonal view angles
|
|
876
876
|
// by computing the world-space direction analytically per-pixel
|
|
877
877
|
|
|
@@ -961,7 +961,7 @@ fn fragmentMain(@builtin(position) fragCoord: vec4<f32>) -> @location(0) vec4<f3
|
|
|
961
961
|
|
|
962
962
|
return textureSample(t_skybox, s_skybox, cubemapDir);
|
|
963
963
|
}
|
|
964
|
-
`;var ef=(n=>(n.QUAKE="quake",n.OPENGL="opengl",n.WEBGPU="webgpu",n))(ef||{});var Oa=class{constructor(){
|
|
964
|
+
`;var ef=(n=>(n.QUAKE="quake",n.OPENGL="opengl",n.WEBGPU="webgpu",n))(ef||{});var Oa=class{constructor(){f(this,"coordinateSystem","webgpu")}buildProjectionMatrix(e){let r=I.create(),n=1/Math.tan(e.fov*Ee/2),i=1/(e.near-e.far);return r[0]=n/e.aspect,r[5]=n,r[10]=e.far*i,r[11]=-1,r[14]=e.near*e.far*i,r[15]=0,r}buildViewMatrix(e){let[r,n,i]=e.angles,a=r*Ee,o=n*Ee,s=i*Ee,c=I.create();I.identity(c),I.rotateZ(c,c,-o),I.rotateY(c,c,-a),I.rotateX(c,c,-s);let l=I.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),u=I.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),d=I.create();I.multiply(d,u,c);let h=P.fromValues(e.position[0],e.position[1],e.position[2]),m=P.transformMat4(P.create(),h,d);P.negate(m,m);let p=I.clone(d);return p[12]=m[0],p[13]=m[1],p[14]=m[2],p}};var wp=new Float32Array([-1,-1,1,-1,1,1,-1,-1,1,1,-1,1]),kc=class{constructor(e,r){this.device=e;this.format=r;f(this,"pipeline");f(this,"vertexBuffer");f(this,"bindGroupHelper");f(this,"uniformBuffer");f(this,"sampler");f(this,"matrixBuilder");this.matrixBuilder=new Oa;let n=e.createShaderModule({label:"skybox-shader",code:Sp});this.vertexBuffer=e.createBuffer({label:"skybox-vertex-buffer",size:wp.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:!0}),new Float32Array(this.vertexBuffer.getMappedRange()).set(wp),this.vertexBuffer.unmap(),this.uniformBuffer=e.createBuffer({label:"skybox-uniform-buffer",size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.sampler=e.createSampler({label:"skybox-sampler",minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge"});let i=e.createBindGroupLayout({label:"skybox-bind-group-layout",entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{viewDimension:"cube"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}}]});this.pipeline=e.createRenderPipeline({label:"skybox-pipeline",layout:e.createPipelineLayout({bindGroupLayouts:[i]}),vertex:{module:n,entryPoint:"vertexMain",buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]}]},fragment:{module:n,entryPoint:"fragmentMain",targets:[{format:this.format,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},depthStencil:{format:"depth24plus",depthWriteEnabled:!1,depthCompare:"always"},primitive:{topology:"triangle-list",cullMode:"none"}}),this.bindGroupHelper=new tf(e,i,this.uniformBuffer,this.sampler)}draw(e,r){if(!r.cameraState)throw new Error("SkyboxPipeline: cameraState is required for full-screen skybox rendering");let n=r.cameraState,i=this.matrixBuilder.buildViewMatrix(n),a=gs.fromValues(i[0],i[4],i[8],i[1],i[5],i[9],i[2],i[6],i[10]),o=Math.tan(n.fov*Ee/2),s=n.aspect,c=new Float32Array(16);c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=0,c[4]=a[3],c[5]=a[4],c[6]=a[5],c[7]=0,c[8]=a[6],c[9]=a[7],c[10]=a[8],c[11]=0,c[12]=o,c[13]=s,c[14]=r.scroll[0],c[15]=r.scroll[1],this.device.queue.writeBuffer(this.uniformBuffer,0,c);let l=this.bindGroupHelper.getBindGroup(r.cubemap);e.setPipeline(this.pipeline),e.setBindGroup(0,l),e.setVertexBuffer(0,this.vertexBuffer),e.draw(6)}destroy(){this.vertexBuffer.destroy(),this.uniformBuffer.destroy()}},tf=class{constructor(e,r,n,i){this.device=e;this.layout=r;this.uniformBuffer=n;this.sampler=i;f(this,"bindGroupCache",new Map)}getBindGroup(e){if(this.bindGroupCache.has(e))return this.bindGroupCache.get(e);let r=this.device.createBindGroup({layout:this.layout,entries:[{binding:0,resource:{buffer:this.uniformBuffer}},{binding:1,resource:e.createView()},{binding:2,resource:this.sampler}]});return this.bindGroupCache.set(e,r),r}};var Mp=`struct DLight {
|
|
965
965
|
position: vec3<f32>,
|
|
966
966
|
intensity: f32,
|
|
967
967
|
color: vec3<f32>,
|
|
@@ -1157,14 +1157,14 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4<f32> {
|
|
|
1157
1157
|
|
|
1158
1158
|
return finalColor;
|
|
1159
1159
|
}
|
|
1160
|
-
`;var Ap=[0,255,255,255],S_=[0,-1,-1,-1];function w_(t=Ap,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let a=e[i];r[n]=a!==void 0?a:1}return r}function M_(t){return[-(t*.25%1),0]}function A_(t=xn,e=0){let r=(t&rl)!==0,n=(t&Zr)!==0,i=(t&vn)!==0,a=(t&_n)!==0,o=(t&Sn)!==0,s=a?.33:o?.66:1,c=a||o||n,l=!c&&!i,u=r?M_(e):[0,0];return{alpha:s,blend:c,depthWrite:l,warp:n,flowOffset:u,sky:i}}var Uc=class{constructor(e,r,n){h(this,"device");h(this,"pipeline");h(this,"pipelineWireframe");h(this,"frameUniformBuffer");h(this,"surfaceUniformBuffer");h(this,"frameBindGroup");h(this,"frameBindGroupLayout");h(this,"surfaceBindGroupLayout");h(this,"textureBindGroupLayout");h(this,"defaultWhiteTexture");h(this,"defaultSampler");h(this,"defaultBindGroup");h(this,"textureBindGroupCache",new Map);this.device=e;let i=2048,a=256;this.frameUniformBuffer=e.createBuffer({size:i,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.surfaceUniformBuffer=e.createBuffer({size:a,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.frameBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),this.surfaceBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),this.textureBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),this.defaultSampler=Fc(e),this.defaultWhiteTexture=new Yn(e,{width:1,height:1,format:"rgba8unorm",label:"bsp-default-white"}),this.defaultWhiteTexture.upload(new Uint8Array([255,255,255,255])),this.defaultBindGroup=e.createBindGroup({layout:this.textureBindGroupLayout,entries:[{binding:0,resource:this.defaultWhiteTexture.createView()},{binding:1,resource:this.defaultSampler.sampler},{binding:2,resource:this.defaultWhiteTexture.createView()},{binding:3,resource:this.defaultSampler.sampler}]}),this.createPipelines(r,n),this.frameBindGroup=e.createBindGroup({layout:this.frameBindGroupLayout,entries:[{binding:0,resource:{buffer:this.frameUniformBuffer}}]})}createPipelines(e,r){let n=this.device.createShaderModule({code:Mp}),i=this.device.createPipelineLayout({bindGroupLayouts:[this.frameBindGroupLayout,this.surfaceBindGroupLayout,this.textureBindGroupLayout]}),a={module:n,entryPoint:"vertexMain",buffers:[{arrayStride:32,attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x2"},{shaderLocation:2,offset:20,format:"float32x2"},{shaderLocation:3,offset:28,format:"float32"}]}]};this.pipeline=this.device.createRenderPipeline({layout:i,vertex:a,fragment:{module:n,entryPoint:"fragmentMain",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{format:r,depthWriteEnabled:!0,depthCompare:"less"}}),this.pipelineWireframe=this.device.createRenderPipeline({layout:i,vertex:a,fragment:{module:n,entryPoint:"fragmentMain",targets:[{format:e,writeMask:GPUColorWrite.ALL}]},primitive:{topology:"line-list"},depthStencil:{format:r,depthWriteEnabled:!0,depthCompare:"less"}})}bind(e,r){let{modelViewProjection:n,styleIndices:i=Ap,styleLayers:a=S_,styleValues:o=[],diffuseTexture:s,diffuseSampler:c,lightmapTexture:l,lightmapSampler:u,surfaceFlags:d=xn,timeSeconds:f=0,texScroll:m,alpha:p,warp:y,dlights:g=[],renderMode:b,lightmapOnly:_,brightness:x=1,gamma:v=1,fullbright:S=!1,ambient:M=0,cameraPosition:w=[0,0,0],surfaceMins:T={x:0,y:0,z:0}}=r,L=A_(d,f),A=w_(i,o),R=m?m[0]:L.flowOffset[0],D=m?m[1]:L.flowOffset[1],k=p!==void 0?p:L.alpha,F=y!==void 0?y:L.warp,U=new Float32Array(512);U.set(n,0),U.set(w,16),U[19]=0,U[20]=f,U[21]=x,U[22]=v,U[23]=M;let ee=Math.min(g.length,Vr),He=new Uint32Array(U.buffer,96,1);He[0]=ee;let We=new Uint32Array(U.buffer,100,1);We[0]=S?1:0;let Ae=32;for(let ft=0;ft<ee;ft++){let Xe=g[ft];U[Ae+0]=Xe.origin.x,U[Ae+1]=Xe.origin.y,U[Ae+2]=Xe.origin.z,U[Ae+3]=Xe.intensity,U[Ae+4]=Xe.color.x,U[Ae+5]=Xe.color.y,U[Ae+6]=Xe.color.z,U[Ae+7]=0,Ae+=8}this.device.queue.writeBuffer(this.frameUniformBuffer,0,U,0,Ae);let j=new Float32Array(32);j[0]=R,j[1]=D,j[2]=L.flowOffset[0],j[3]=L.flowOffset[1],j.set(A,4),j.set(a,8);let ue=0,ve=[1,1,1,1];b&&(b.mode==="solid"||b.mode==="wireframe"?ue=1:b.mode==="solid-faceted"?ue=2:b.mode==="worldpos-debug"?ue=3:b.mode==="distance-debug"&&(ue=4),b.color?ve=[...b.color]:b.generateRandomColor&&(ve=[1,1,1,1])),j.set(ve,12),j[16]=k;let Ie=new Uint32Array(j.buffer),nt=!L.sky&&u!==void 0&&!F;Ie[17]=nt?1:0,Ie[18]=F?1:0,Ie[19]=_?1:0,Ie[20]=ue,j[28]=T.x,j[29]=T.y,j[30]=T.z,this.device.queue.writeBuffer(this.surfaceUniformBuffer,0,j);let jt=this.device.createBindGroup({layout:this.surfaceBindGroupLayout,entries:[{binding:0,resource:{buffer:this.surfaceUniformBuffer}}]});if(s&&c&&l&&u){let ft=this.device.createBindGroup({layout:this.textureBindGroupLayout,entries:[{binding:0,resource:s},{binding:1,resource:c},{binding:2,resource:l},{binding:3,resource:u}]});e.setBindGroup(2,ft)}else e.setBindGroup(2,this.defaultBindGroup);let mr=b&&b.mode==="wireframe"?this.pipelineWireframe:this.pipeline;return e.setPipeline(mr),e.setBindGroup(0,this.frameBindGroup),e.setBindGroup(1,jt),L}draw(e,r,n){r.gpuIndexBuffer&&(n&&n.mode==="wireframe"||(e.setVertexBuffer(0,r.gpuVertexBuffer),e.setIndexBuffer(r.gpuIndexBuffer,"uint16"),e.drawIndexed(r.indexCount)))}destroy(){this.frameUniformBuffer.destroy(),this.surfaceUniformBuffer.destroy(),this.defaultWhiteTexture.destroy()}};var rf=class{constructor(e,r,n){this.context=e;this.frameRenderer=r;this.pipelines=n;h(this,"type","webgpu");h(this,"picCache",new Map);h(this,"whiteTexture");h(this,"font",null);h(this,"is2DActive",!1);h(this,"collisionVis");h(this,"debug");h(this,"particleSystem");this.whiteTexture=new Yn(e.device,{width:1,height:1,format:e.format,label:"white-texture"}),this.whiteTexture.upload(new Uint8Array([255,255,255,255])),this.collisionVis=null,this.debug=null,this.particleSystem=null}get device(){return this.context.device}get width(){return this.context.width}get height(){return this.context.height}renderFrame(e,r=[],n){let i=e,a=i.dlights;if(i.dlights&&i.dlights.length>0){let s=new Float32Array(i.camera.viewProjectionMatrix),c=cr(s),l={x:i.camera.position[0],y:i.camera.position[1],z:i.camera.position[2]};a=Ec(i.dlights,c,l,32)}let o={...i,dlights:a};this.frameRenderer.renderFrame(o)}uploadBspGeometry(e){for(let r of e){if(r.gpuVertexBuffer&&r.gpuIndexBuffer)continue;let n=new ka(this.device,{size:r.vertexData.byteLength,label:`bsp-surface-vb-${r.texture}`});n.write(r.vertexData);let i=new Ua(this.device,{size:r.indexData.byteLength,label:`bsp-surface-ib-${r.texture}`});i.write(r.indexData);let a=r;a.gpuVertexBuffer=n.buffer,a.gpuIndexBuffer=i.buffer}}async registerPic(e,r){if(this.picCache.has(e))return this.picCache.get(e);let n=new Yn(this.device,{width:256,height:256,format:this.context.format,label:`pic-${e}`});return n.upload(r),this.picCache.set(e,n),n}registerTexture(e,r){if(this.picCache.has(e))return this.picCache.get(e);let n=new Yn(this.device,{width:r.width,height:r.height,format:this.context.format,mipLevelCount:r.levels.length,label:`texture-${e}`});for(let i of r.levels)n.upload(i.rgba,{width:i.width,height:i.height,mipLevel:i.level});return this.picCache.set(e,n),n}begin2D(){this.frameRenderer.begin2DPass(),this.is2DActive=!0}end2D(){this.frameRenderer.end2DPass(),this.is2DActive=!1}drawPic(e,r,n,i=[1,1,1,1]){if(!this.is2DActive)throw new Error("drawPic called outside begin2D/end2D");this.pipelines.sprite.drawTexturedQuad(e,r,n.width,n.height,n,0,0,1,1,i)}drawfillRect(e,r,n,i,a){if(!this.is2DActive)throw new Error("drawfillRect called outside begin2D/end2D");this.pipelines.sprite.drawSolidRect(e,r,n,i,a)}drawString(e,r,n,i=[1,1,1,1]){if(!this.is2DActive)throw new Error("drawString called outside begin2D/end2D");if(!this.font)return;let a=wc(n),o=e,s=8,c=8;for(let l of a){let u=l.color||i;for(let d of l.text){let f=d.charCodeAt(0),m=f%16,p=Math.floor(f/16),y=m/16,g=p/16,b=(m+1)/16,_=(p+1)/16;this.pipelines.sprite.drawTexturedQuad(o,r,s,c,this.font,y,g,b,_,u),o+=s}}}drawCenterString(e,r){if(!this.is2DActive)throw new Error("drawCenterString called outside begin2D/end2D");let a=r.replace(/\^[0-9]/g,"").length*8,o=(this.width-a)/2;this.drawString(o,e,r)}setEntityHighlight(e,r){}clearEntityHighlight(e){}highlightSurface(e,r){}removeSurfaceHighlight(e){}setDebugMode(e){}setBrightness(e){}setGamma(e){}setFullbright(e){}setAmbient(e){}setLightStyle(e,r){}setUnderwaterWarp(e){}setBloom(e){}setBloomIntensity(e){}setLodBias(e){}renderInstanced(e,r){}getPerformanceReport(){return{frameTimeMs:0,gpuTimeMs:0,cpuFrameTimeMs:0,drawCalls:0,triangles:0,vertices:0,textureBinds:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0,memoryUsageMB:{textures:0,geometry:0,total:0}}}getMemoryUsage(){return{texturesBytes:0,geometryBytes:0,shadersBytes:0,buffersBytes:0,totalBytes:0}}resize(e,r){this.context.context&&!this.context.isHeadless?(this.context.width=e,this.context.height=r):(this.context.width=e,this.context.height=r)}dispose(){this.pipelines.sprite.destroy(),this.pipelines.skybox.destroy(),this.pipelines.bsp.destroy();for(let e of this.picCache.values())e.destroy();this.picCache.clear(),this.whiteTexture.destroy(),this.context.device.destroy()}destroy(){this.dispose()}};async function Ep(t,e){let r=await Tc(t,e),n=new Dc(r.device,r.format),i=new kc(r.device,r.format),a=new Uc(r.device,r.format,r.depthFormat||"depth24plus"),o={sprite:n,skybox:i,bsp:a};t?(r.width=t.width,r.height=t.height):(r.width=800,r.height=600);let s=new Lc(r,o);return new rf(r,s,o)}var wr=class{constructor(e){h(this,"buffer");h(this,"view");h(this,"offset");h(this,"messageOffsets",[]);h(this,"currentBlock",null);this.buffer=e,this.view=new DataView(e),this.offset=0,this.scan()}scan(){let e=0;for(this.messageOffsets=[];e+4<=this.buffer.byteLength;){let r=this.view.getInt32(e,!0);if(r===-1)break;if(r<0||r>2097152){console.warn(`DemoReader: Invalid block length ${r} at offset ${e} during scan`);break}if(e+4+r>this.buffer.byteLength){console.warn(`DemoReader: Incomplete block at offset ${e} during scan`);break}this.messageOffsets.push(e),e+=4+r}}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(e===-1||e<0||this.offset+4+e>this.buffer.byteLength)return null;this.offset+=4;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new En(r)}}nextBlock(){let e=this.readNextBlock();return e?(this.currentBlock=e,!0):(this.currentBlock=null,!1)}getBlock(){if(!this.currentBlock)throw new Error("No current block. Call nextBlock() first.");return this.currentBlock}readAllBlocksToBuffer(){let e=0,r=this.offset,n=[],i=this.offset;for(;i+4<=this.buffer.byteLength;){let c=this.view.getInt32(i,!0);if(c===-1||c<0||i+4+c>this.buffer.byteLength)break;n.push({offset:i+4,length:c}),e+=c,i+=4+c}let a=new Uint8Array(e),o=0,s=new Uint8Array(this.buffer);for(let c of n)a.set(s.subarray(c.offset,c.offset+c.length),o),o+=c.length;return this.offset=i,a.buffer}reset(){this.offset=0,this.currentBlock=null}seekToMessage(e){return e<0||e>=this.messageOffsets.length?!1:(this.offset=this.messageOffsets[e],this.currentBlock=null,!0)}getMessageCount(){return this.messageOffsets.length}getOffset(){return this.offset}getProgress(){let e=this.offset,r=this.buffer.byteLength;return{current:e,total:r,percent:r>0?e/r*100:0}}};function Xa(t){let e=t.length;for(;--e>=0;)t[e]=0}var E_=0,d0=1,T_=2,L_=3,P_=258,Tf=29,zs=256,Rs=zs+1+Tf,Va=30,Lf=19,f0=2*Rs+1,Ci=15,nf=16,R_=7,Pf=256,h0=16,m0=17,p0=18,bf=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Hc=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),C_=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),g0=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),B_=512,mn=new Array((Rs+2)*2);Xa(mn);var Ts=new Array(Va*2);Xa(Ts);var Cs=new Array(B_);Xa(Cs);var Bs=new Array(P_-L_+1);Xa(Bs);var Rf=new Array(Tf);Xa(Rf);var Wc=new Array(Va);Xa(Wc);function af(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}var y0,b0,x0;function of(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}var v0=t=>t<256?Cs[t]:Cs[256+(t>>>7)],Fs=(t,e)=>{t.pending_buf[t.pending++]=e&255,t.pending_buf[t.pending++]=e>>>8&255},Gt=(t,e,r)=>{t.bi_valid>nf-r?(t.bi_buf|=e<<t.bi_valid&65535,Fs(t,t.bi_buf),t.bi_buf=e>>nf-t.bi_valid,t.bi_valid+=r-nf):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=r)},Wr=(t,e,r)=>{Gt(t,r[e*2],r[e*2+1])},_0=(t,e)=>{let r=0;do r|=t&1,t>>>=1,r<<=1;while(--e>0);return r>>>1},F_=t=>{t.bi_valid===16?(Fs(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=t.bi_buf&255,t.bi_buf>>=8,t.bi_valid-=8)},I_=(t,e)=>{let r=e.dyn_tree,n=e.max_code,i=e.stat_desc.static_tree,a=e.stat_desc.has_stree,o=e.stat_desc.extra_bits,s=e.stat_desc.extra_base,c=e.stat_desc.max_length,l,u,d,f,m,p,y=0;for(f=0;f<=Ci;f++)t.bl_count[f]=0;for(r[t.heap[t.heap_max]*2+1]=0,l=t.heap_max+1;l<f0;l++)u=t.heap[l],f=r[r[u*2+1]*2+1]+1,f>c&&(f=c,y++),r[u*2+1]=f,!(u>n)&&(t.bl_count[f]++,m=0,u>=s&&(m=o[u-s]),p=r[u*2],t.opt_len+=p*(f+m),a&&(t.static_len+=p*(i[u*2+1]+m)));if(y!==0){do{for(f=c-1;t.bl_count[f]===0;)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[c]--,y-=2}while(y>0);for(f=c;f!==0;f--)for(u=t.bl_count[f];u!==0;)d=t.heap[--l],!(d>n)&&(r[d*2+1]!==f&&(t.opt_len+=(f-r[d*2+1])*r[d*2],r[d*2+1]=f),u--)}},S0=(t,e,r)=>{let n=new Array(Ci+1),i=0,a,o;for(a=1;a<=Ci;a++)i=i+r[a-1]<<1,n[a]=i;for(o=0;o<=e;o++){let s=t[o*2+1];s!==0&&(t[o*2]=_0(n[s]++,s))}},D_=()=>{let t,e,r,n,i,a=new Array(Ci+1);for(r=0,n=0;n<Tf-1;n++)for(Rf[n]=r,t=0;t<1<<bf[n];t++)Bs[r++]=n;for(Bs[r-1]=n,i=0,n=0;n<16;n++)for(Wc[n]=i,t=0;t<1<<Hc[n];t++)Cs[i++]=n;for(i>>=7;n<Va;n++)for(Wc[n]=i<<7,t=0;t<1<<Hc[n]-7;t++)Cs[256+i++]=n;for(e=0;e<=Ci;e++)a[e]=0;for(t=0;t<=143;)mn[t*2+1]=8,t++,a[8]++;for(;t<=255;)mn[t*2+1]=9,t++,a[9]++;for(;t<=279;)mn[t*2+1]=7,t++,a[7]++;for(;t<=287;)mn[t*2+1]=8,t++,a[8]++;for(S0(mn,Rs+1,a),t=0;t<Va;t++)Ts[t*2+1]=5,Ts[t*2]=_0(t,5);y0=new af(mn,bf,zs+1,Rs,Ci),b0=new af(Ts,Hc,0,Va,Ci),x0=new af(new Array(0),C_,0,Lf,R_)},w0=t=>{let e;for(e=0;e<Rs;e++)t.dyn_ltree[e*2]=0;for(e=0;e<Va;e++)t.dyn_dtree[e*2]=0;for(e=0;e<Lf;e++)t.bl_tree[e*2]=0;t.dyn_ltree[Pf*2]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},M0=t=>{t.bi_valid>8?Fs(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},Tp=(t,e,r,n)=>{let i=e*2,a=r*2;return t[i]<t[a]||t[i]===t[a]&&n[e]<=n[r]},sf=(t,e,r)=>{let n=t.heap[r],i=r<<1;for(;i<=t.heap_len&&(i<t.heap_len&&Tp(e,t.heap[i+1],t.heap[i],t.depth)&&i++,!Tp(e,n,t.heap[i],t.depth));)t.heap[r]=t.heap[i],r=i,i<<=1;t.heap[r]=n},Lp=(t,e,r)=>{let n,i,a=0,o,s;if(t.sym_next!==0)do n=t.pending_buf[t.sym_buf+a++]&255,n+=(t.pending_buf[t.sym_buf+a++]&255)<<8,i=t.pending_buf[t.sym_buf+a++],n===0?Wr(t,i,e):(o=Bs[i],Wr(t,o+zs+1,e),s=bf[o],s!==0&&(i-=Rf[o],Gt(t,i,s)),n--,o=v0(n),Wr(t,o,r),s=Hc[o],s!==0&&(n-=Wc[o],Gt(t,n,s)));while(a<t.sym_next);Wr(t,Pf,e)},xf=(t,e)=>{let r=e.dyn_tree,n=e.stat_desc.static_tree,i=e.stat_desc.has_stree,a=e.stat_desc.elems,o,s,c=-1,l;for(t.heap_len=0,t.heap_max=f0,o=0;o<a;o++)r[o*2]!==0?(t.heap[++t.heap_len]=c=o,t.depth[o]=0):r[o*2+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=c<2?++c:0,r[l*2]=1,t.depth[l]=0,t.opt_len--,i&&(t.static_len-=n[l*2+1]);for(e.max_code=c,o=t.heap_len>>1;o>=1;o--)sf(t,r,o);l=a;do o=t.heap[1],t.heap[1]=t.heap[t.heap_len--],sf(t,r,1),s=t.heap[1],t.heap[--t.heap_max]=o,t.heap[--t.heap_max]=s,r[l*2]=r[o*2]+r[s*2],t.depth[l]=(t.depth[o]>=t.depth[s]?t.depth[o]:t.depth[s])+1,r[o*2+1]=r[s*2+1]=l,t.heap[1]=l++,sf(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],I_(t,e),S0(r,c,t.bl_count)},Pp=(t,e,r)=>{let n,i=-1,a,o=e[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),e[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=e[(n+1)*2+1],!(++s<c&&a===o)&&(s<l?t.bl_tree[a*2]+=s:a!==0?(a!==i&&t.bl_tree[a*2]++,t.bl_tree[h0*2]++):s<=10?t.bl_tree[m0*2]++:t.bl_tree[p0*2]++,s=0,i=a,o===0?(c=138,l=3):a===o?(c=6,l=3):(c=7,l=4))},Rp=(t,e,r)=>{let n,i=-1,a,o=e[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),n=0;n<=r;n++)if(a=o,o=e[(n+1)*2+1],!(++s<c&&a===o)){if(s<l)do Wr(t,a,t.bl_tree);while(--s!==0);else a!==0?(a!==i&&(Wr(t,a,t.bl_tree),s--),Wr(t,h0,t.bl_tree),Gt(t,s-3,2)):s<=10?(Wr(t,m0,t.bl_tree),Gt(t,s-3,3)):(Wr(t,p0,t.bl_tree),Gt(t,s-11,7));s=0,i=a,o===0?(c=138,l=3):a===o?(c=6,l=3):(c=7,l=4)}},k_=t=>{let e;for(Pp(t,t.dyn_ltree,t.l_desc.max_code),Pp(t,t.dyn_dtree,t.d_desc.max_code),xf(t,t.bl_desc),e=Lf-1;e>=3&&t.bl_tree[g0[e]*2+1]===0;e--);return t.opt_len+=3*(e+1)+5+5+4,e},U_=(t,e,r,n)=>{let i;for(Gt(t,e-257,5),Gt(t,r-1,5),Gt(t,n-4,4),i=0;i<n;i++)Gt(t,t.bl_tree[g0[i]*2+1],3);Rp(t,t.dyn_ltree,e-1),Rp(t,t.dyn_dtree,r-1)},z_=t=>{let e=4093624447,r;for(r=0;r<=31;r++,e>>>=1)if(e&1&&t.dyn_ltree[r*2]!==0)return 0;if(t.dyn_ltree[18]!==0||t.dyn_ltree[20]!==0||t.dyn_ltree[26]!==0)return 1;for(r=32;r<zs;r++)if(t.dyn_ltree[r*2]!==0)return 1;return 0},Cp=!1,O_=t=>{Cp||(D_(),Cp=!0),t.l_desc=new of(t.dyn_ltree,y0),t.d_desc=new of(t.dyn_dtree,b0),t.bl_desc=new of(t.bl_tree,x0),t.bi_buf=0,t.bi_valid=0,w0(t)},A0=(t,e,r,n)=>{Gt(t,(E_<<1)+(n?1:0),3),M0(t),Fs(t,r),Fs(t,~r),r&&t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r},N_=t=>{Gt(t,d0<<1,3),Wr(t,Pf,mn),F_(t)},G_=(t,e,r,n)=>{let i,a,o=0;t.level>0?(t.strm.data_type===2&&(t.strm.data_type=z_(t)),xf(t,t.l_desc),xf(t,t.d_desc),o=k_(t),i=t.opt_len+3+7>>>3,a=t.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&e!==-1?A0(t,e,r,n):t.strategy===4||a===i?(Gt(t,(d0<<1)+(n?1:0),3),Lp(t,mn,Ts)):(Gt(t,(T_<<1)+(n?1:0),3),U_(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),Lp(t,t.dyn_ltree,t.dyn_dtree)),w0(t),n&&M0(t)},V_=(t,e,r)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=r,e===0?t.dyn_ltree[r*2]++:(t.matches++,e--,t.dyn_ltree[(Bs[r]+zs+1)*2]++,t.dyn_dtree[v0(e)*2]++),t.sym_next===t.sym_end),H_=O_,W_=A0,X_=G_,$_=V_,K_=N_,Y_={_tr_init:H_,_tr_stored_block:W_,_tr_flush_block:X_,_tr_tally:$_,_tr_align:K_},q_=(t,e,r,n)=>{let i=t&65535|0,a=t>>>16&65535|0,o=0;for(;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+e[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0},Is=q_,Z_=()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;e[r]=t}return e},j_=new Uint32Array(Z_()),Q_=(t,e,r,n)=>{let i=j_,a=n+r;t^=-1;for(let o=n;o<a;o++)t=t>>>8^i[(t^e[o])&255];return t^-1},Ve=Q_,Ii={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Ui={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:J_,_tr_stored_block:vf,_tr_flush_block:eS,_tr_tally:jn,_tr_align:tS}=Y_,{Z_NO_FLUSH:Qn,Z_PARTIAL_FLUSH:rS,Z_FULL_FLUSH:nS,Z_FINISH:fr,Z_BLOCK:Bp,Z_OK:rt,Z_STREAM_END:Fp,Z_STREAM_ERROR:Xr,Z_DATA_ERROR:iS,Z_BUF_ERROR:lf,Z_DEFAULT_COMPRESSION:aS,Z_FILTERED:oS,Z_HUFFMAN_ONLY:zc,Z_RLE:sS,Z_FIXED:lS,Z_DEFAULT_STRATEGY:cS,Z_UNKNOWN:uS,Z_DEFLATED:Kc}=Ui,dS=9,fS=15,hS=8,mS=29,pS=256,_f=pS+1+mS,gS=30,yS=19,bS=2*_f+1,xS=15,J=3,Zn=258,$r=Zn+J+1,vS=32,Ha=42,Cf=57,Sf=69,wf=73,Mf=91,Af=103,Bi=113,As=666,vt=1,$a=2,Di=3,Ka=4,_S=3,Fi=(t,e)=>(t.msg=Ii[e],e),Ip=t=>t*2-(t>4?9:0),qn=t=>{let e=t.length;for(;--e>=0;)t[e]=0},SS=t=>{let e,r,n,i=t.w_size;e=t.hash_size,n=e;do r=t.head[--n],t.head[n]=r>=i?r-i:0;while(--e);e=i,n=e;do r=t.prev[--n],t.prev[n]=r>=i?r-i:0;while(--e)},wS=(t,e,r)=>(e<<t.hash_shift^r)&t.hash_mask,Jn=wS,qt=t=>{let e=t.state,r=e.pending;r>t.avail_out&&(r=t.avail_out),r!==0&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,e.pending===0&&(e.pending_out=0))},Zt=(t,e)=>{eS(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,qt(t.strm)},se=(t,e)=>{t.pending_buf[t.pending++]=e},Ms=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=e&255},Ef=(t,e,r,n)=>{let i=t.avail_in;return i>n&&(i=n),i===0?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),t.state.wrap===1?t.adler=Is(t.adler,e,i,r):t.state.wrap===2&&(t.adler=Ve(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},E0=(t,e)=>{let r=t.max_chain_length,n=t.strstart,i,a,o=t.prev_length,s=t.nice_match,c=t.strstart>t.w_size-$r?t.strstart-(t.w_size-$r):0,l=t.window,u=t.w_mask,d=t.prev,f=t.strstart+Zn,m=l[n+o-1],p=l[n+o];t.prev_length>=t.good_match&&(r>>=2),s>t.lookahead&&(s=t.lookahead);do if(i=e,!(l[i+o]!==p||l[i+o-1]!==m||l[i]!==l[n]||l[++i]!==l[n+1])){n+=2,i++;do;while(l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&n<f);if(a=Zn-(f-n),n=f-Zn,a>o){if(t.match_start=e,o=a,a>=s)break;m=l[n+o-1],p=l[n+o]}}while((e=d[e&u])>c&&--r!==0);return o<=t.lookahead?o:t.lookahead},Wa=t=>{let e=t.w_size,r,n,i;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-$r)&&(t.window.set(t.window.subarray(e,e+e-n),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),SS(t),n+=e),t.strm.avail_in===0)break;if(r=Ef(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=r,t.lookahead+t.insert>=J)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=Jn(t,t.ins_h,t.window[i+1]);t.insert&&(t.ins_h=Jn(t,t.ins_h,t.window[i+J-1]),t.prev[i&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=i,i++,t.insert--,!(t.lookahead+t.insert<J)););}while(t.lookahead<$r&&t.strm.avail_in!==0)},T0=(t,e)=>{let r=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,n,i,a,o=0,s=t.strm.avail_in;do{if(n=65535,a=t.bi_valid+42>>3,t.strm.avail_out<a||(a=t.strm.avail_out-a,i=t.strstart-t.block_start,n>i+t.strm.avail_in&&(n=i+t.strm.avail_in),n>a&&(n=a),n<r&&(n===0&&e!==fr||e===Qn||n!==i+t.strm.avail_in)))break;o=e===fr&&n===i+t.strm.avail_in?1:0,vf(t,0,0,o),t.pending_buf[t.pending-4]=n,t.pending_buf[t.pending-3]=n>>8,t.pending_buf[t.pending-2]=~n,t.pending_buf[t.pending-1]=~n>>8,qt(t.strm),i&&(i>n&&(i=n),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,n-=i),n&&(Ef(t.strm,t.strm.output,t.strm.next_out,n),t.strm.next_out+=n,t.strm.avail_out-=n,t.strm.total_out+=n)}while(o===0);return s-=t.strm.avail_in,s&&(s>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=s&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-s,t.strm.next_in),t.strstart),t.strstart+=s,t.insert+=s>t.w_size-t.insert?t.w_size-t.insert:s),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),o?Ka:e!==Qn&&e!==fr&&t.strm.avail_in===0&&t.strstart===t.block_start?$a:(a=t.window_size-t.strstart,t.strm.avail_in>a&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,a+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),a>t.strm.avail_in&&(a=t.strm.avail_in),a&&(Ef(t.strm,t.window,t.strstart,a),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.high_water<t.strstart&&(t.high_water=t.strstart),a=t.bi_valid+42>>3,a=t.pending_buf_size-a>65535?65535:t.pending_buf_size-a,r=a>t.w_size?t.w_size:a,i=t.strstart-t.block_start,(i>=r||(i||e===fr)&&e!==Qn&&t.strm.avail_in===0&&i<=a)&&(n=i>a?a:i,o=e===fr&&t.strm.avail_in===0&&n===i?1:0,vf(t,t.block_start,n,o),t.block_start+=n,qt(t.strm)),o?Di:vt)},cf=(t,e)=>{let r,n;for(;;){if(t.lookahead<$r){if(Wa(t),t.lookahead<$r&&e===Qn)return vt;if(t.lookahead===0)break}if(r=0,t.lookahead>=J&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),r!==0&&t.strstart-r<=t.w_size-$r&&(t.match_length=E0(t,r)),t.match_length>=J)if(n=jn(t,t.strstart-t.match_start,t.match_length-J),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=J){t.match_length--;do t.strstart++,t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart;while(--t.match_length!==0);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+1]);else n=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=t.strstart<J-1?t.strstart:J-1,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},Na=(t,e)=>{let r,n,i;for(;;){if(t.lookahead<$r){if(Wa(t),t.lookahead<$r&&e===Qn)return vt;if(t.lookahead===0)break}if(r=0,t.lookahead>=J&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=J-1,r!==0&&t.prev_length<t.max_lazy_match&&t.strstart-r<=t.w_size-$r&&(t.match_length=E0(t,r),t.match_length<=5&&(t.strategy===oS||t.match_length===J&&t.strstart-t.match_start>4096)&&(t.match_length=J-1)),t.prev_length>=J&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-J,n=jn(t,t.strstart-1-t.prev_match,t.prev_length-J),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=i&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart);while(--t.prev_length!==0);if(t.match_available=0,t.match_length=J-1,t.strstart++,n&&(Zt(t,!1),t.strm.avail_out===0))return vt}else if(t.match_available){if(n=jn(t,0,t.window[t.strstart-1]),n&&Zt(t,!1),t.strstart++,t.lookahead--,t.strm.avail_out===0)return vt}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=jn(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<J-1?t.strstart:J-1,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},MS=(t,e)=>{let r,n,i,a,o=t.window;for(;;){if(t.lookahead<=Zn){if(Wa(t),t.lookahead<=Zn&&e===Qn)return vt;if(t.lookahead===0)break}if(t.match_length=0,t.lookahead>=J&&t.strstart>0&&(i=t.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+Zn;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);t.match_length=Zn-(a-i),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=J?(r=jn(t,1,t.match_length-J),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=0,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},AS=(t,e)=>{let r;for(;;){if(t.lookahead===0&&(Wa(t),t.lookahead===0)){if(e===Qn)return vt;break}if(t.match_length=0,r=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=0,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a};function Hr(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Es=[new Hr(0,0,0,0,T0),new Hr(4,4,8,4,cf),new Hr(4,5,16,8,cf),new Hr(4,6,32,32,cf),new Hr(4,4,16,16,Na),new Hr(8,16,32,32,Na),new Hr(8,16,128,128,Na),new Hr(8,32,128,256,Na),new Hr(32,128,258,1024,Na),new Hr(32,258,258,4096,Na)],ES=t=>{t.window_size=2*t.w_size,qn(t.head),t.max_lazy_match=Es[t.level].max_lazy,t.good_match=Es[t.level].good_length,t.nice_match=Es[t.level].nice_length,t.max_chain_length=Es[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=J-1,t.match_available=0,t.ins_h=0};function TS(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Kc,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(bS*2),this.dyn_dtree=new Uint16Array((2*gS+1)*2),this.bl_tree=new Uint16Array((2*yS+1)*2),qn(this.dyn_ltree),qn(this.dyn_dtree),qn(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(xS+1),this.heap=new Uint16Array(2*_f+1),qn(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*_f+1),qn(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Os=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.status!==Ha&&e.status!==Cf&&e.status!==Sf&&e.status!==wf&&e.status!==Mf&&e.status!==Af&&e.status!==Bi&&e.status!==As?1:0},L0=t=>{if(Os(t))return Fi(t,Xr);t.total_in=t.total_out=0,t.data_type=uS;let e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap===2?Cf:e.wrap?Ha:Bi,t.adler=e.wrap===2?0:1,e.last_flush=-2,J_(e),rt},P0=t=>{let e=L0(t);return e===rt&&ES(t.state),e},LS=(t,e)=>Os(t)||t.state.wrap!==2?Xr:(t.state.gzhead=e,rt),R0=(t,e,r,n,i,a)=>{if(!t)return Xr;let o=1;if(e===aS&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>dS||r!==Kc||n<8||n>15||e<0||e>9||a<0||a>lS||n===8&&o!==1)return Fi(t,Xr);n===8&&(n=9);let s=new TS;return t.state=s,s.strm=t,s.status=Ha,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+J-1)/J),s.window=new Uint8Array(s.w_size*2),s.head=new Uint16Array(s.hash_size),s.prev=new Uint16Array(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new Uint8Array(s.pending_buf_size),s.sym_buf=s.lit_bufsize,s.sym_end=(s.lit_bufsize-1)*3,s.level=e,s.strategy=a,s.method=r,P0(t)},PS=(t,e)=>R0(t,e,Kc,fS,hS,cS),RS=(t,e)=>{if(Os(t)||e>Bp||e<0)return t?Fi(t,Xr):Xr;let r=t.state;if(!t.output||t.avail_in!==0&&!t.input||r.status===As&&e!==fr)return Fi(t,t.avail_out===0?lf:Xr);let n=r.last_flush;if(r.last_flush=e,r.pending!==0){if(qt(t),t.avail_out===0)return r.last_flush=-1,rt}else if(t.avail_in===0&&Ip(e)<=Ip(n)&&e!==fr)return Fi(t,lf);if(r.status===As&&t.avail_in!==0)return Fi(t,lf);if(r.status===Ha&&r.wrap===0&&(r.status=Bi),r.status===Ha){let i=Kc+(r.w_bits-8<<4)<<8,a=-1;if(r.strategy>=zc||r.level<2?a=0:r.level<6?a=1:r.level===6?a=2:a=3,i|=a<<6,r.strstart!==0&&(i|=vS),i+=31-i%31,Ms(r,i),r.strstart!==0&&(Ms(r,t.adler>>>16),Ms(r,t.adler&65535)),t.adler=1,r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(r.status===Cf){if(t.adler=0,se(r,31),se(r,139),se(r,8),r.gzhead)se(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),se(r,r.gzhead.time&255),se(r,r.gzhead.time>>8&255),se(r,r.gzhead.time>>16&255),se(r,r.gzhead.time>>24&255),se(r,r.level===9?2:r.strategy>=zc||r.level<2?4:0),se(r,r.gzhead.os&255),r.gzhead.extra&&r.gzhead.extra.length&&(se(r,r.gzhead.extra.length&255),se(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Ve(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=Sf;else if(se(r,0),se(r,0),se(r,0),se(r,0),se(r,0),se(r,r.level===9?2:r.strategy>=zc||r.level<2?4:0),se(r,_S),r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(r.status===Sf){if(r.gzhead.extra){let i=r.pending,a=(r.gzhead.extra.length&65535)-r.gzindex;for(;r.pending+a>r.pending_buf_size;){let s=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+s),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex+=s,qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0,a-=s}let o=new Uint8Array(r.gzhead.extra);r.pending_buf.set(o.subarray(r.gzindex,r.gzindex+a),r.pending),r.pending+=a,r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=wf}if(r.status===wf){if(r.gzhead.name){let i=r.pending,a;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0}r.gzindex<r.gzhead.name.length?a=r.gzhead.name.charCodeAt(r.gzindex++)&255:a=0,se(r,a)}while(a!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Mf}if(r.status===Mf){if(r.gzhead.comment){let i=r.pending,a;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0}r.gzindex<r.gzhead.comment.length?a=r.gzhead.comment.charCodeAt(r.gzindex++)&255:a=0,se(r,a)}while(a!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i))}r.status=Af}if(r.status===Af){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&(qt(t),r.pending!==0))return r.last_flush=-1,rt;se(r,t.adler&255),se(r,t.adler>>8&255),t.adler=0}if(r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(t.avail_in!==0||r.lookahead!==0||e!==Qn&&r.status!==As){let i=r.level===0?T0(r,e):r.strategy===zc?AS(r,e):r.strategy===sS?MS(r,e):Es[r.level].func(r,e);if((i===Di||i===Ka)&&(r.status=As),i===vt||i===Di)return t.avail_out===0&&(r.last_flush=-1),rt;if(i===$a&&(e===rS?tS(r):e!==Bp&&(vf(r,0,0,!1),e===nS&&(qn(r.head),r.lookahead===0&&(r.strstart=0,r.block_start=0,r.insert=0))),qt(t),t.avail_out===0))return r.last_flush=-1,rt}return e!==fr?rt:r.wrap<=0?Fp:(r.wrap===2?(se(r,t.adler&255),se(r,t.adler>>8&255),se(r,t.adler>>16&255),se(r,t.adler>>24&255),se(r,t.total_in&255),se(r,t.total_in>>8&255),se(r,t.total_in>>16&255),se(r,t.total_in>>24&255)):(Ms(r,t.adler>>>16),Ms(r,t.adler&65535)),qt(t),r.wrap>0&&(r.wrap=-r.wrap),r.pending!==0?rt:Fp)},CS=t=>{if(Os(t))return Xr;let e=t.state.status;return t.state=null,e===Bi?Fi(t,iS):rt},BS=(t,e)=>{let r=e.length;if(Os(t))return Xr;let n=t.state,i=n.wrap;if(i===2||i===1&&n.status!==Ha||n.lookahead)return Xr;if(i===1&&(t.adler=Is(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){i===0&&(qn(n.head),n.strstart=0,n.block_start=0,n.insert=0);let c=new Uint8Array(n.w_size);c.set(e.subarray(r-n.w_size,r),0),e=c,r=n.w_size}let a=t.avail_in,o=t.next_in,s=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Wa(n);n.lookahead>=J;){let c=n.strstart,l=n.lookahead-(J-1);do n.ins_h=Jn(n,n.ins_h,n.window[c+J-1]),n.prev[c&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=c,c++;while(--l);n.strstart=c,n.lookahead=J-1,Wa(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=J-1,n.match_available=0,t.next_in=o,t.input=s,t.avail_in=a,n.wrap=i,rt},FS=PS,IS=R0,DS=P0,kS=L0,US=LS,zS=RS,OS=CS,NS=BS,GS="pako deflate (from Nodeca project)",Ls={deflateInit:FS,deflateInit2:IS,deflateReset:DS,deflateResetKeep:kS,deflateSetHeader:US,deflate:zS,deflateEnd:OS,deflateSetDictionary:NS,deflateInfo:GS},VS=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),HS=function(t){let e=Array.prototype.slice.call(arguments,1);for(;e.length;){let r=e.shift();if(r){if(typeof r!="object")throw new TypeError(r+"must be non-object");for(let n in r)VS(r,n)&&(t[n]=r[n])}}return t},WS=t=>{let e=0;for(let n=0,i=t.length;n<i;n++)e+=t[n].length;let r=new Uint8Array(e);for(let n=0,i=0,a=t.length;n<a;n++){let o=t[n];r.set(o,i),i+=o.length}return r},Yc={assign:HS,flattenChunks:WS},C0=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{C0=!1}var Ds=new Uint8Array(256);for(let t=0;t<256;t++)Ds[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ds[254]=Ds[254]=1;var XS=t=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(t);let e,r,n,i,a,o=t.length,s=0;for(i=0;i<o;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),s+=r<128?1:r<2048?2:r<65536?3:4;for(e=new Uint8Array(s),a=0,i=0;a<s;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),r<128?e[a++]=r:r<2048?(e[a++]=192|r>>>6,e[a++]=128|r&63):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|r&63):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|r&63);return e},$S=(t,e)=>{if(e<65534&&t.subarray&&C0)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let n=0;n<e;n++)r+=String.fromCharCode(t[n]);return r},KS=(t,e)=>{let r=e||t.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(t.subarray(0,e));let n,i,a=new Array(r*2);for(i=0,n=0;n<r;){let o=t[n++];if(o<128){a[i++]=o;continue}let s=Ds[o];if(s>4){a[i++]=65533,n+=s-1;continue}for(o&=s===2?31:s===3?15:7;s>1&&n<r;)o=o<<6|t[n++]&63,s--;if(s>1){a[i++]=65533;continue}o<65536?a[i++]=o:(o-=65536,a[i++]=55296|o>>10&1023,a[i++]=56320|o&1023)}return $S(a,i)},YS=(t,e)=>{e=e||t.length,e>t.length&&(e=t.length);let r=e-1;for(;r>=0&&(t[r]&192)===128;)r--;return r<0||r===0?e:r+Ds[t[r]]>e?r:e},ks={string2buf:XS,buf2string:KS,utf8border:YS};function qS(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var B0=qS,F0=Object.prototype.toString,{Z_NO_FLUSH:ZS,Z_SYNC_FLUSH:jS,Z_FULL_FLUSH:QS,Z_FINISH:JS,Z_OK:Xc,Z_STREAM_END:ew,Z_DEFAULT_COMPRESSION:tw,Z_DEFAULT_STRATEGY:rw,Z_DEFLATED:nw}=Ui;function Ns(t){this.options=Yc.assign({level:tw,method:nw,chunkSize:16384,windowBits:15,memLevel:8,strategy:rw},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new B0,this.strm.avail_out=0;let r=Ls.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Xc)throw new Error(Ii[r]);if(e.header&&Ls.deflateSetHeader(this.strm,e.header),e.dictionary){let n;if(typeof e.dictionary=="string"?n=ks.string2buf(e.dictionary):F0.call(e.dictionary)==="[object ArrayBuffer]"?n=new Uint8Array(e.dictionary):n=e.dictionary,r=Ls.deflateSetDictionary(this.strm,n),r!==Xc)throw new Error(Ii[r]);this._dict_set=!0}}Ns.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i,a;if(this.ended)return!1;for(e===~~e?a=e:a=e===!0?JS:ZS,typeof t=="string"?r.input=ks.string2buf(t):F0.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){if(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(a===jS||a===QS)&&r.avail_out<=6){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(i=Ls.deflate(r,a),i===ew)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=Ls.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===Xc;if(r.avail_out===0){this.onData(r.output);continue}if(a>0&&r.next_out>0){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(r.avail_in===0)break}return!0};Ns.prototype.onData=function(t){this.chunks.push(t)};Ns.prototype.onEnd=function(t){t===Xc&&(this.result=Yc.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Bf(t,e){let r=new Ns(e);if(r.push(t,!0),r.err)throw r.msg||Ii[r.err];return r.result}function iw(t,e){return e=e||{},e.raw=!0,Bf(t,e)}function aw(t,e){return e=e||{},e.gzip=!0,Bf(t,e)}var ow=Ns,sw=Bf,lw=iw,cw=aw,uw=Ui,dw={Deflate:ow,deflate:sw,deflateRaw:lw,gzip:cw,constants:uw},Oc=16209,fw=16191,hw=function(e,r){let n,i,a,o,s,c,l,u,d,f,m,p,y,g,b,_,x,v,S,M,w,T,L,A,R=e.state;n=e.next_in,L=e.input,i=n+(e.avail_in-5),a=e.next_out,A=e.output,o=a-(r-e.avail_out),s=a+(e.avail_out-257),c=R.dmax,l=R.wsize,u=R.whave,d=R.wnext,f=R.window,m=R.hold,p=R.bits,y=R.lencode,g=R.distcode,b=(1<<R.lenbits)-1,_=(1<<R.distbits)-1;e:do{p<15&&(m+=L[n++]<<p,p+=8,m+=L[n++]<<p,p+=8),x=y[m&b];t:for(;;){if(v=x>>>24,m>>>=v,p-=v,v=x>>>16&255,v===0)A[a++]=x&65535;else if(v&16){S=x&65535,v&=15,v&&(p<v&&(m+=L[n++]<<p,p+=8),S+=m&(1<<v)-1,m>>>=v,p-=v),p<15&&(m+=L[n++]<<p,p+=8,m+=L[n++]<<p,p+=8),x=g[m&_];r:for(;;){if(v=x>>>24,m>>>=v,p-=v,v=x>>>16&255,v&16){if(M=x&65535,v&=15,p<v&&(m+=L[n++]<<p,p+=8,p<v&&(m+=L[n++]<<p,p+=8)),M+=m&(1<<v)-1,M>c){e.msg="invalid distance too far back",R.mode=Oc;break e}if(m>>>=v,p-=v,v=a-o,M>v){if(v=M-v,v>u&&R.sane){e.msg="invalid distance too far back",R.mode=Oc;break e}if(w=0,T=f,d===0){if(w+=l-v,v<S){S-=v;do A[a++]=f[w++];while(--v);w=a-M,T=A}}else if(d<v){if(w+=l+d-v,v-=d,v<S){S-=v;do A[a++]=f[w++];while(--v);if(w=0,d<S){v=d,S-=v;do A[a++]=f[w++];while(--v);w=a-M,T=A}}}else if(w+=d-v,v<S){S-=v;do A[a++]=f[w++];while(--v);w=a-M,T=A}for(;S>2;)A[a++]=T[w++],A[a++]=T[w++],A[a++]=T[w++],S-=3;S&&(A[a++]=T[w++],S>1&&(A[a++]=T[w++]))}else{w=a-M;do A[a++]=A[w++],A[a++]=A[w++],A[a++]=A[w++],S-=3;while(S>2);S&&(A[a++]=A[w++],S>1&&(A[a++]=A[w++]))}}else if((v&64)===0){x=g[(x&65535)+(m&(1<<v)-1)];continue r}else{e.msg="invalid distance code",R.mode=Oc;break e}break}}else if((v&64)===0){x=y[(x&65535)+(m&(1<<v)-1)];continue t}else if(v&32){R.mode=fw;break e}else{e.msg="invalid literal/length code",R.mode=Oc;break e}break}}while(n<i&&a<s);S=p>>3,n-=S,p-=S<<3,m&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),R.hold=m,R.bits=p},Ga=15,Dp=852,kp=592,Up=0,uf=1,zp=2,mw=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),pw=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),gw=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),yw=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),bw=(t,e,r,n,i,a,o,s)=>{let c=s.bits,l=0,u=0,d=0,f=0,m=0,p=0,y=0,g=0,b=0,_=0,x,v,S,M,w,T=null,L,A=new Uint16Array(Ga+1),R=new Uint16Array(Ga+1),D=null,k,F,U;for(l=0;l<=Ga;l++)A[l]=0;for(u=0;u<n;u++)A[e[r+u]]++;for(m=c,f=Ga;f>=1&&A[f]===0;f--);if(m>f&&(m=f),f===0)return i[a++]=1<<24|64<<16|0,i[a++]=1<<24|64<<16|0,s.bits=1,0;for(d=1;d<f&&A[d]===0;d++);for(m<d&&(m=d),g=1,l=1;l<=Ga;l++)if(g<<=1,g-=A[l],g<0)return-1;if(g>0&&(t===Up||f!==1))return-1;for(R[1]=0,l=1;l<Ga;l++)R[l+1]=R[l]+A[l];for(u=0;u<n;u++)e[r+u]!==0&&(o[R[e[r+u]]++]=u);if(t===Up?(T=D=o,L=20):t===uf?(T=mw,D=pw,L=257):(T=gw,D=yw,L=0),_=0,u=0,l=d,w=a,p=m,y=0,S=-1,b=1<<m,M=b-1,t===uf&&b>Dp||t===zp&&b>kp)return 1;for(;;){k=l-y,o[u]+1<L?(F=0,U=o[u]):o[u]>=L?(F=D[o[u]-L],U=T[o[u]-L]):(F=96,U=0),x=1<<l-y,v=1<<p,d=v;do v-=x,i[w+(_>>y)+v]=k<<24|F<<16|U|0;while(v!==0);for(x=1<<l-1;_&x;)x>>=1;if(x!==0?(_&=x-1,_+=x):_=0,u++,--A[l]===0){if(l===f)break;l=e[r+o[u]]}if(l>m&&(_&M)!==S){for(y===0&&(y=m),w+=d,p=l-y,g=1<<p;p+y<f&&(g-=A[p+y],!(g<=0));)p++,g<<=1;if(b+=1<<p,t===uf&&b>Dp||t===zp&&b>kp)return 1;S=_&M,i[S]=m<<24|p<<16|w-a|0}}return _!==0&&(i[w+_]=l-y<<24|64<<16|0),s.bits=m,0},Ps=bw,xw=0,I0=1,D0=2,{Z_FINISH:Op,Z_BLOCK:vw,Z_TREES:Nc,Z_OK:ki,Z_STREAM_END:_w,Z_NEED_DICT:Sw,Z_STREAM_ERROR:hr,Z_DATA_ERROR:k0,Z_MEM_ERROR:U0,Z_BUF_ERROR:ww,Z_DEFLATED:Np}=Ui,qc=16180,Gp=16181,Vp=16182,Hp=16183,Wp=16184,Xp=16185,$p=16186,Kp=16187,Yp=16188,qp=16189,$c=16190,hn=16191,df=16192,Zp=16193,ff=16194,jp=16195,Qp=16196,Jp=16197,e0=16198,Gc=16199,Vc=16200,t0=16201,r0=16202,n0=16203,i0=16204,a0=16205,hf=16206,o0=16207,s0=16208,Me=16209,z0=16210,O0=16211,Mw=852,Aw=592,Ew=15,Tw=Ew,l0=t=>(t>>>24&255)+(t>>>8&65280)+((t&65280)<<8)+((t&255)<<24);function Lw(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var zi=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.mode<qc||e.mode>O0?1:0},N0=t=>{if(zi(t))return hr;let e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=e.wrap&1),e.mode=qc,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Mw),e.distcode=e.distdyn=new Int32Array(Aw),e.sane=1,e.back=-1,ki},G0=t=>{if(zi(t))return hr;let e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,N0(t)},V0=(t,e)=>{let r;if(zi(t))return hr;let n=t.state;return e<0?(r=0,e=-e):(r=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?hr:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,G0(t))},H0=(t,e)=>{if(!t)return hr;let r=new Lw;t.state=r,r.strm=t,r.window=null,r.mode=qc;let n=V0(t,e);return n!==ki&&(t.state=null),n},Pw=t=>H0(t,Tw),c0=!0,mf,pf,Rw=t=>{if(c0){mf=new Int32Array(512),pf=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Ps(I0,t.lens,0,288,mf,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Ps(D0,t.lens,0,32,pf,0,t.work,{bits:5}),c0=!1}t.lencode=mf,t.lenbits=9,t.distcode=pf,t.distbits=5},W0=(t,e,r,n)=>{let i,a=t.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),n>=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),n-=i,n?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0},Cw=(t,e)=>{let r,n,i,a,o,s,c,l,u,d,f,m,p,y,g=0,b,_,x,v,S,M,w,T,L=new Uint8Array(4),A,R,D=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(zi(t)||!t.output||!t.input&&t.avail_in!==0)return hr;r=t.state,r.mode===hn&&(r.mode=df),o=t.next_out,i=t.output,c=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,l=r.hold,u=r.bits,d=s,f=c,T=ki;e:for(;;)switch(r.mode){case qc:if(r.wrap===0){r.mode=df;break}for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&2&&l===35615){r.wbits===0&&(r.wbits=15),r.check=0,L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0),l=0,u=0,r.mode=Gp;break}if(r.head&&(r.head.done=!1),!(r.wrap&1)||(((l&255)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=Me;break}if((l&15)!==Np){t.msg="unknown compression method",r.mode=Me;break}if(l>>>=4,u-=4,w=(l&15)+8,r.wbits===0&&(r.wbits=w),w>15||w>r.wbits){t.msg="invalid window size",r.mode=Me;break}r.dmax=1<<r.wbits,r.flags=0,t.adler=r.check=1,r.mode=l&512?qp:hn,l=0,u=0;break;case Gp:for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.flags=l,(r.flags&255)!==Np){t.msg="unknown compression method",r.mode=Me;break}if(r.flags&57344){t.msg="unknown header flags set",r.mode=Me;break}r.head&&(r.head.text=l>>8&1),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0,r.mode=Vp;case Vp:for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.time=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,L[2]=l>>>16&255,L[3]=l>>>24&255,r.check=Ve(r.check,L,4,0)),l=0,u=0,r.mode=Hp;case Hp:for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.xflags=l&255,r.head.os=l>>8),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0,r.mode=Wp;case Wp:if(r.flags&1024){for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.length=l,r.head&&(r.head.extra_len=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0}else r.head&&(r.head.extra=null);r.mode=Xp;case Xp:if(r.flags&1024&&(m=r.length,m>s&&(m=s),m&&(r.head&&(w=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+m),w)),r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,r.length-=m),r.length))break e;r.length=0,r.mode=$p;case $p:if(r.flags&2048){if(s===0)break e;m=0;do w=n[a+m++],r.head&&w&&r.length<65536&&(r.head.name+=String.fromCharCode(w));while(w&&m<s);if(r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,w)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Kp;case Kp:if(r.flags&4096){if(s===0)break e;m=0;do w=n[a+m++],r.head&&w&&r.length<65536&&(r.head.comment+=String.fromCharCode(w));while(w&&m<s);if(r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,w)break e}else r.head&&(r.head.comment=null);r.mode=Yp;case Yp:if(r.flags&512){for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&4&&l!==(r.check&65535)){t.msg="header crc mismatch",r.mode=Me;break}l=0,u=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=hn;break;case qp:for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}t.adler=r.check=l0(l),l=0,u=0,r.mode=$c;case $c:if(r.havedict===0)return t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,Sw;t.adler=r.check=1,r.mode=hn;case hn:if(e===vw||e===Nc)break e;case df:if(r.last){l>>>=u&7,u-=u&7,r.mode=hf;break}for(;u<3;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}switch(r.last=l&1,l>>>=1,u-=1,l&3){case 0:r.mode=Zp;break;case 1:if(Rw(r),r.mode=Gc,e===Nc){l>>>=2,u-=2;break e}break;case 2:r.mode=Qp;break;case 3:t.msg="invalid block type",r.mode=Me}l>>>=2,u-=2;break;case Zp:for(l>>>=u&7,u-=u&7;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if((l&65535)!==(l>>>16^65535)){t.msg="invalid stored block lengths",r.mode=Me;break}if(r.length=l&65535,l=0,u=0,r.mode=ff,e===Nc)break e;case ff:r.mode=jp;case jp:if(m=r.length,m){if(m>s&&(m=s),m>c&&(m=c),m===0)break e;i.set(n.subarray(a,a+m),o),s-=m,a+=m,c-=m,o+=m,r.length-=m;break}r.mode=hn;break;case Qp:for(;u<14;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.nlen=(l&31)+257,l>>>=5,u-=5,r.ndist=(l&31)+1,l>>>=5,u-=5,r.ncode=(l&15)+4,l>>>=4,u-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Me;break}r.have=0,r.mode=Jp;case Jp:for(;r.have<r.ncode;){for(;u<3;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.lens[D[r.have++]]=l&7,l>>>=3,u-=3}for(;r.have<19;)r.lens[D[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},T=Ps(xw,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,T){t.msg="invalid code lengths set",r.mode=Me;break}r.have=0,r.mode=e0;case e0:for(;r.have<r.nlen+r.ndist;){for(;g=r.lencode[l&(1<<r.lenbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(x<16)l>>>=b,u-=b,r.lens[r.have++]=x;else{if(x===16){for(R=b+2;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(l>>>=b,u-=b,r.have===0){t.msg="invalid bit length repeat",r.mode=Me;break}w=r.lens[r.have-1],m=3+(l&3),l>>>=2,u-=2}else if(x===17){for(R=b+3;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=b,u-=b,w=0,m=3+(l&7),l>>>=3,u-=3}else{for(R=b+7;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=b,u-=b,w=0,m=11+(l&127),l>>>=7,u-=7}if(r.have+m>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Me;break}for(;m--;)r.lens[r.have++]=w}}if(r.mode===Me)break;if(r.lens[256]===0){t.msg="invalid code -- missing end-of-block",r.mode=Me;break}if(r.lenbits=9,A={bits:r.lenbits},T=Ps(I0,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,T){t.msg="invalid literal/lengths set",r.mode=Me;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},T=Ps(D0,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,T){t.msg="invalid distances set",r.mode=Me;break}if(r.mode=Gc,e===Nc)break e;case Gc:r.mode=Vc;case Vc:if(s>=6&&c>=258){t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,hw(t,f),o=t.next_out,i=t.output,c=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,l=r.hold,u=r.bits,r.mode===hn&&(r.back=-1);break}for(r.back=0;g=r.lencode[l&(1<<r.lenbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(_&&(_&240)===0){for(v=b,S=_,M=x;g=r.lencode[M+((l&(1<<v+S)-1)>>v)],b=g>>>24,_=g>>>16&255,x=g&65535,!(v+b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=v,u-=v,r.back+=v}if(l>>>=b,u-=b,r.back+=b,r.length=x,_===0){r.mode=a0;break}if(_&32){r.back=-1,r.mode=hn;break}if(_&64){t.msg="invalid literal/length code",r.mode=Me;break}r.extra=_&15,r.mode=t0;case t0:if(r.extra){for(R=r.extra;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=r0;case r0:for(;g=r.distcode[l&(1<<r.distbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if((_&240)===0){for(v=b,S=_,M=x;g=r.distcode[M+((l&(1<<v+S)-1)>>v)],b=g>>>24,_=g>>>16&255,x=g&65535,!(v+b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=v,u-=v,r.back+=v}if(l>>>=b,u-=b,r.back+=b,_&64){t.msg="invalid distance code",r.mode=Me;break}r.offset=x,r.extra=_&15,r.mode=n0;case n0:if(r.extra){for(R=r.extra;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Me;break}r.mode=i0;case i0:if(c===0)break e;if(m=f-c,r.offset>m){if(m=r.offset-m,m>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Me;break}m>r.wnext?(m-=r.wnext,p=r.wsize-m):p=r.wnext-m,m>r.length&&(m=r.length),y=r.window}else y=i,p=o-r.offset,m=r.length;m>c&&(m=c),c-=m,r.length-=m;do i[o++]=y[p++];while(--m);r.length===0&&(r.mode=Vc);break;case a0:if(c===0)break e;i[o++]=r.length,c--,r.mode=Vc;break;case hf:if(r.wrap){for(;u<32;){if(s===0)break e;s--,l|=n[a++]<<u,u+=8}if(f-=c,t.total_out+=f,r.total+=f,r.wrap&4&&f&&(t.adler=r.check=r.flags?Ve(r.check,i,f,o-f):Is(r.check,i,f,o-f)),f=c,r.wrap&4&&(r.flags?l:l0(l))!==r.check){t.msg="incorrect data check",r.mode=Me;break}l=0,u=0}r.mode=o0;case o0:if(r.wrap&&r.flags){for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&4&&l!==(r.total&4294967295)){t.msg="incorrect length check",r.mode=Me;break}l=0,u=0}r.mode=s0;case s0:T=_w;break e;case Me:T=k0;break e;case z0:return U0;case O0:default:return hr}return t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,(r.wsize||f!==t.avail_out&&r.mode<Me&&(r.mode<hf||e!==Op))&&W0(t,t.output,t.next_out,f-t.avail_out),d-=t.avail_in,f-=t.avail_out,t.total_in+=d,t.total_out+=f,r.total+=f,r.wrap&4&&f&&(t.adler=r.check=r.flags?Ve(r.check,i,f,t.next_out-f):Is(r.check,i,f,t.next_out-f)),t.data_type=r.bits+(r.last?64:0)+(r.mode===hn?128:0)+(r.mode===Gc||r.mode===ff?256:0),(d===0&&f===0||e===Op)&&T===ki&&(T=ww),T},Bw=t=>{if(zi(t))return hr;let e=t.state;return e.window&&(e.window=null),t.state=null,ki},Fw=(t,e)=>{if(zi(t))return hr;let r=t.state;return(r.wrap&2)===0?hr:(r.head=e,e.done=!1,ki)},Iw=(t,e)=>{let r=e.length,n,i,a;return zi(t)||(n=t.state,n.wrap!==0&&n.mode!==$c)?hr:n.mode===$c&&(i=1,i=Is(i,e,r,0),i!==n.check)?k0:(a=W0(t,e,r,r),a?(n.mode=z0,U0):(n.havedict=1,ki))},Dw=G0,kw=V0,Uw=N0,zw=Pw,Ow=H0,Nw=Cw,Gw=Bw,Vw=Fw,Hw=Iw,Ww="pako inflate (from Nodeca project)",pn={inflateReset:Dw,inflateReset2:kw,inflateResetKeep:Uw,inflateInit:zw,inflateInit2:Ow,inflate:Nw,inflateEnd:Gw,inflateGetHeader:Vw,inflateSetDictionary:Hw,inflateInfo:Ww};function Xw(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var $w=Xw,X0=Object.prototype.toString,{Z_NO_FLUSH:Kw,Z_FINISH:Yw,Z_OK:Us,Z_STREAM_END:gf,Z_NEED_DICT:yf,Z_STREAM_ERROR:qw,Z_DATA_ERROR:u0,Z_MEM_ERROR:Zw}=Ui;function Gs(t){this.options=Yc.assign({chunkSize:1024*64,windowBits:15,to:""},t||{});let e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(t&&t.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new B0,this.strm.avail_out=0;let r=pn.inflateInit2(this.strm,e.windowBits);if(r!==Us)throw new Error(Ii[r]);if(this.header=new $w,pn.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=ks.string2buf(e.dictionary):X0.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=pn.inflateSetDictionary(this.strm,e.dictionary),r!==Us)))throw new Error(Ii[r])}Gs.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i=this.options.dictionary,a,o,s;if(this.ended)return!1;for(e===~~e?o=e:o=e===!0?Yw:Kw,X0.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),a=pn.inflate(r,o),a===yf&&i&&(a=pn.inflateSetDictionary(r,i),a===Us?a=pn.inflate(r,o):a===u0&&(a=yf));r.avail_in>0&&a===gf&&r.state.wrap>0&&t[r.next_in]!==0;)pn.inflateReset(r),a=pn.inflate(r,o);switch(a){case qw:case u0:case yf:case Zw:return this.onEnd(a),this.ended=!0,!1}if(s=r.avail_out,r.next_out&&(r.avail_out===0||a===gf))if(this.options.to==="string"){let c=ks.utf8border(r.output,r.next_out),l=r.next_out-c,u=ks.buf2string(r.output,c);r.next_out=l,r.avail_out=n-l,l&&r.output.set(r.output.subarray(c,c+l),0),this.onData(u)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(!(a===Us&&s===0)){if(a===gf)return a=pn.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,!0;if(r.avail_in===0)break}}return!0};Gs.prototype.onData=function(t){this.chunks.push(t)};Gs.prototype.onEnd=function(t){t===Us&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=Yc.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Ff(t,e){let r=new Gs(e);if(r.push(t),r.err)throw r.msg||Ii[r.err];return r.result}function jw(t,e){return e=e||{},e.raw=!0,Ff(t,e)}var Qw=Gs,Jw=Ff,e2=jw,t2=Ff,r2=Ui,n2={Inflate:Qw,inflate:Jw,inflateRaw:e2,ungzip:t2,constants:r2},{Deflate:i2,deflate:a2,deflateRaw:o2,gzip:s2}=dw,{Inflate:l2,inflate:c2,inflateRaw:u2,ungzip:d2}=n2,f2=i2,h2=a2,m2=o2,p2=s2,g2=l2,y2=c2,b2=u2,x2=d2,v2=Ui,If={Deflate:f2,deflate:h2,deflateRaw:m2,gzip:p2,Inflate:g2,inflate:y2,inflateRaw:b2,ungzip:x2,constants:v2};var Ya=class Ya{constructor(e=Ya.INITIAL_SIZE){h(this,"buffer");h(this,"readOffset");h(this,"writeOffset");this.buffer=new Uint8Array(e),this.readOffset=0,this.writeOffset=0}append(e){let r=e instanceof Uint8Array?e:new Uint8Array(e),n=this.writeOffset+r.length;n>this.buffer.length&&this.grow(n),this.buffer.set(r,this.writeOffset),this.writeOffset+=r.length}hasBytes(e){return this.writeOffset-this.readOffset>=e}available(){return this.writeOffset-this.readOffset}readByte(){if(!this.hasBytes(1))throw new Error("Buffer underflow");return this.buffer[this.readOffset++]}readShort(){if(!this.hasBytes(2))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8;return this.readOffset+=2,e>32767?e-65536:e}readLong(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8|this.buffer[this.readOffset+2]<<16|this.buffer[this.readOffset+3]<<24;return this.readOffset+=4,e}readFloat(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let r=new DataView(this.buffer.buffer,this.buffer.byteOffset+this.readOffset,4).getFloat32(0,!0);return this.readOffset+=4,r}readString(){let e=Math.min(Ya.MAX_STRING_LENGTH,this.writeOffset-this.readOffset),r=0;for(;r<e&&this.buffer[this.readOffset+r]!==0;)r++;if(r>=e)throw this.writeOffset-this.readOffset<=e?new Error("Buffer underflow"):new Error("String exceeds max length");let n=this.buffer.slice(this.readOffset,this.readOffset+r);return this.readOffset+=r+1,new TextDecoder("latin1").decode(n)}peekBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");return this.buffer.slice(this.readOffset,this.readOffset+e)}readBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");let r=this.buffer.slice(this.readOffset,this.readOffset+e);return this.readOffset+=e,r}readData(e){return this.readBytes(e)}getReadPosition(){return this.readOffset}getWritePosition(){return this.writeOffset}setReadPosition(e){if(e<0||e>this.writeOffset)throw new Error("Invalid read position");this.readOffset=e}grow(e){let r=e?Math.max(e,this.buffer.length*2):this.buffer.length*2,n=new Uint8Array(r);n.set(this.buffer),this.buffer=n}compact(){if(this.readOffset===0)return;let e=this.writeOffset-this.readOffset;if(e===0){this.readOffset=0,this.writeOffset=0;return}this.buffer.copyWithin(0,this.readOffset,this.writeOffset),this.readOffset=0,this.writeOffset=e}getCapacity(){return this.buffer.length}reset(){this.readOffset=0,this.writeOffset=0}};h(Ya,"INITIAL_SIZE",64*1024),h(Ya,"MAX_STRING_LENGTH",2048);var ei=Ya;var Kr=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0,bitsHigh:0,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame:0}),Mr=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0,watertype:0});var $0={0:C.bad,1:C.nop,2:C.disconnect,3:C.reconnect,4:C.download,5:C.frame,6:C.inventory,7:C.layout,8:C.muzzleflash,9:C.temp_entity,10:C.sound,11:C.print,12:C.stufftext,13:C.serverdata,14:C.configstring,15:C.spawnbaseline,16:C.centerprint,17:C.playerinfo,18:C.packetentities,19:C.deltapacketentities,20:C.muzzleflash2},Zc=class{constructor(){h(this,"protocolVersion",34)}translateCommand(e){return $0[e]!==void 0?$0[e]:C.bad}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n;return r&si?n=e.readShort():n=e.readByte(),{number:n,bits:r,bitsHigh:0}}parseDelta(e,r,n,i,a,o){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Yr=2023,jc=class{constructor(){h(this,"protocolVersion",Yr)}translateCommand(e){return e}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readByte(),o=e.readString(),s=e.readShort();if(s===-2){let l=e.readShort();for(let u=0;u<l;u++)e.readShort();s=0}else s===-1&&(s=-1);let c=e.readString();return{protocol:r,serverCount:n,spawnCount:n,attractLoop:0,gameDir:o,playerNum:s,levelName:c,tickRate:a,demoType:i}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n=0;r&Vi&&(n=e.readByte());let i;return r&si?i=e.readShort():i=e.readByte(),{number:i,bits:r,bitsHigh:n}}parseDelta(e,r,n,i,a,o){Object.assign(r,e),r.origin={...e.origin},r.old_origin={...e.old_origin},r.angles={...e.angles},r.number=n,r.bits=i,r.bitsHigh=a,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort()),i&Lr&&(r.alpha=o.readByte()/255),i&Cr&&(r.scale=o.readFloat()),i&Br&&(r.instanceBits=o.readLong()),i&Fr&&(r.loopVolume=o.readByte()/255),a&wn&&(r.loopAttenuation=o.readByte()/255),a&Mn&&(r.owner=o.readShort()),a&An&&(r.oldFrame=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Qc=class{constructor(e=0){h(this,"protocolVersion");this.protocolVersion=e}translateCommand(e){return e}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n;return r&si?n=e.readShort():n=e.readByte(),{number:n,bits:r,bitsHigh:0}}parseDelta(e,r,n,i,a,o){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Vs=class{constructor(){h(this,"protocolVersion",0)}translateCommand(e){return e===7?C.serverdata:e===12?C.serverdata:e===13?C.serverdata:e===C.stufftext?C.stufftext:C.bad}parseServerData(e){let r=e.readLong();if(r===Yr){let n=e.readLong(),i=e.readByte(),a=e.readByte(),o=e.readString(),s=e.readShort();if(s===-2){let l=e.readShort();for(let u=0;u<l;u++)e.readShort();s=0}else s===-1&&(s=-1);let c=e.readString();return{protocol:r,serverCount:n,spawnCount:n,attractLoop:0,gameDir:o,playerNum:s,levelName:c,tickRate:a,demoType:i}}else{let n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}}parseEntityBits(e){throw new Error("Bootstrap handler cannot parse entities")}parseDelta(e,r,n,i,a,o){throw new Error("Bootstrap handler cannot parse delta")}parsePlayerState(e){throw new Error("Bootstrap handler cannot parse player state")}};function K0(t){return t===0?new Vs:t===Yr?new jc:t===34?new Zc:new Qc(t)}var Y0=1,_2=2,S2=128,Df=class extends ei{constructor(r){super(0);this.stream=r}readByte(){return this.stream.readByte()}readShort(){return this.stream.readShort()}readLong(){return this.stream.readLong()}readFloat(){return this.stream.readFloat()}readString(){return this.stream.readString()}readData(r){return this.stream.readData(r)}hasBytes(r){return this.stream.hasMore()}available(){return this.stream.getRemaining()}getReadPosition(){return this.stream.getPosition()}peekBytes(r){throw new Error("peekBytes not implemented for BinaryStreamAdapter")}},_t=class t{constructor(e,r,n=!1){h(this,"stream");h(this,"handler");h(this,"strictMode",!1);h(this,"errorCount",0);h(this,"protocolHandler");h(this,"isDemo",Y0);e instanceof En?this.stream=new Df(e):this.stream=e,this.handler=r,this.strictMode=n,this.protocolHandler=new Vs}setProtocolVersion(e){this.protocolHandler.protocolVersion!==e&&(this.protocolHandler=K0(e))}getProtocolVersion(){return this.protocolHandler.protocolVersion}getErrorCount(){return this.errorCount}parseMessage(){for(;this.stream.hasBytes(1);){let e=this.stream.getReadPosition(),r=-1;try{if(r=this.stream.readByte(),r===-1)break;let n=r,i=this.protocolHandler.translateCommand(r);switch(i){case C.bad:if(n===0)return;let a=`Unknown server command: ${n} (translated: ${i}) at offset ${e} (Protocol: ${this.getProtocolVersion()})`;if(this.strictMode)throw new Error(a);console.warn(a),this.errorCount++;return;case C.nop:break;case C.disconnect:this.handler?.onDisconnect&&this.handler.onDisconnect();break;case C.reconnect:this.handler?.onReconnect&&this.handler.onReconnect();break;case C.print:this.parsePrint();break;case C.serverdata:this.parseServerData();break;case C.configstring:this.parseConfigString();break;case C.spawnbaseline:this.parseSpawnBaseline();break;case C.centerprint:this.parseCenterPrint();break;case C.download:this.parseDownload();break;case C.frame:this.parseFrame();break;case C.packetentities:this.parsePacketEntities(!1);break;case C.deltapacketentities:this.parsePacketEntities(!0);break;case C.playerinfo:this.parsePlayerState();break;case C.stufftext:this.parseStuffText();break;case C.layout:this.parseLayout();break;case C.inventory:this.parseInventory();break;case C.sound:this.parseSound();break;case C.muzzleflash:this.parseMuzzleFlash();break;case C.muzzleflash2:this.parseMuzzleFlash2();break;case C.temp_entity:this.parseTempEntity();break;case C.splitclient:this.parseSplitClient();break;case C.configblast:this.parseConfigBlast();break;case C.spawnbaselineblast:this.parseSpawnBaselineBlast();break;case C.level_restart:this.handler?.onLevelRestart&&this.handler.onLevelRestart();break;case C.damage:this.parseDamage();break;case C.locprint:this.parseLocPrint();break;case C.fog:this.parseFog();break;case C.waitingforplayers:this.parseWaitingForPlayers();break;case C.bot_chat:this.parseBotChat();break;case C.poi:this.parsePoi();break;case C.help_path:this.parseHelpPath();break;case C.muzzleflash3:this.parseMuzzleFlash3();break;case C.achievement:this.parseAchievement();break;default:let o=`Unknown server command: ${n} (translated: ${i}) at offset ${e}`;if(this.strictMode)throw new Error(o);console.warn(o),this.errorCount++;return}}catch(n){let i=n.message;if(i==="Buffer underflow"||i.includes("StreamingBuffer")){try{this.stream.setReadPosition(e)}catch(o){console.error("Failed to rollback stream position",o)}return}let a=`offset ${e}, cmd ${r}, protocol ${this.getProtocolVersion()}`;if(console.warn(`Error parsing command ${r} (${a}): ${i}`),this.errorCount++,this.strictMode)throw n;return}}}readAngle16(){return this.stream.readShort()*(360/65536)}readCoord(){return this.stream.readShort()*.125}readAngle(){return this.stream.readByte()*(360/256)}readPos(e){e.x=this.stream.readShort()*.125,e.y=this.stream.readShort()*.125,e.z=this.stream.readShort()*.125}readDir(e){let r=this.stream.readByte();if(r>=yr.length)e.x=0,e.y=0,e.z=0;else{let n=yr[r];e.x=n[0],e.y=n[1],e.z=n[2]}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}parseServerData(){let e=this.protocolHandler.parseServerData(this.stream);this.setProtocolVersion(e.protocol),this.handler&&this.handler.onServerData(e.protocol,e.serverCount,e.attractLoop,e.gameDir,e.playerNum,e.levelName,e.tickRate,e.demoType),e.protocol===Yr?this.isDemo=e.demoType??Y0:this.isDemo=e.attractLoop}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseSplitClient(){let e=this.stream.readByte();this.handler?.onSplitClient&&this.handler.onSplitClient(e)}parseConfigBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=If.inflate(n),a=new En(i.buffer);for(;a.hasMore();){let o=a.readUShort(),s=a.readString();this.handler&&this.handler.onConfigString(o,s)}}catch(i){console.error("svc_configblast error",i)}}parseSpawnBaselineBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=If.inflate(n),a=new En(i.buffer),o=new t(a,this.handler,this.strictMode);for(o.setProtocolVersion(this.getProtocolVersion());a.hasMore();)o.parseSpawnBaseline()}catch(i){console.error("svc_spawnbaselineblast error",i)}}parseLocPrint(){let e=this.stream.readByte(),r=this.stream.readString(),n=this.stream.readByte(),i=[];for(let a=0;a<n;a++)i.push(this.stream.readString());this.handler?.onLocPrint&&this.handler.onLocPrint(e,r,i)}parseWaitingForPlayers(){let e=this.stream.readByte();this.handler?.onWaitingForPlayers&&this.handler.onWaitingForPlayers(e)}parseBotChat(){let e=this.stream.readString(),r=this.stream.readShort(),n=this.stream.readString();this.handler?.onBotChat&&this.handler.onBotChat(n)}parsePoi(){let e=this.stream.readShort(),r=this.stream.readShort(),n={x:0,y:0,z:0};this.readPos(n);let i=this.stream.readShort(),a=this.stream.readByte(),o=this.stream.readByte();this.handler?.onPoi&&this.handler.onPoi(o,n)}parseHelpPath(){let e=this.stream.readByte(),r={x:0,y:0,z:0};this.readPos(r);let n={x:0,y:0,z:0};this.readDir(n),this.handler?.onHelpPath&&this.handler.onHelpPath(r)}parseAchievement(){let e=this.stream.readString();this.handler?.onAchievement&&this.handler.onAchievement(e)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,a,o,s;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(a=this.stream.readByte()),e&8&&(o=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.readPos(c),s=c}this.handler&&this.handler.onSound(e,r,n,i,a,o,s)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler?.onMuzzleFlash3&&this.handler.onMuzzleFlash3(e,r)}parseFog(){let e=this.stream.readByte();if(e&128){let n=this.stream.readByte();e|=n<<8}let r={};e&1&&(r.density=this.stream.readFloat(),r.skyfactor=this.stream.readByte()),e&2&&(r.red=this.stream.readByte()),e&4&&(r.green=this.stream.readByte()),e&8&&(r.blue=this.stream.readByte()),e&16&&(r.time=this.stream.readShort()),e&32&&(r.hf_falloff=this.stream.readFloat()),e&64&&(r.hf_density=this.stream.readFloat()),e&256&&(r.hf_start_r=this.stream.readByte()),e&512&&(r.hf_start_g=this.stream.readByte()),e&1024&&(r.hf_start_b=this.stream.readByte()),e&2048&&(r.hf_start_dist=this.stream.readLong()),e&4096&&(r.hf_end_r=this.stream.readByte()),e&8192&&(r.hf_end_g=this.stream.readByte()),e&16384&&(r.hf_end_b=this.stream.readByte()),e&32768&&(r.hf_end_dist=this.stream.readLong()),this.handler?.onFog&&this.handler.onFog(r)}parseDamage(){let e=this.stream.readByte(),r=[];for(let n=0;n<e;n++){let i=this.stream.readByte(),a={x:0,y:0,z:0};this.readDir(a);let o=i&31,s=(i&32)!==0,c=(i&64)!==0,l=(i&128)!==0;r.push({damage:o,health:s,armor:c,power:l,dir:a})}this.handler?.onDamage&&this.handler.onDamage(r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},a,o,s,c,l;switch(e){case O.EXPLOSION1:case O.EXPLOSION2:case O.ROCKET_EXPLOSION:case O.GRENADE_EXPLOSION:case O.ROCKET_EXPLOSION_WATER:case O.GRENADE_EXPLOSION_WATER:case O.BFG_EXPLOSION:case O.BFG_BIGEXPLOSION:case O.BOSSTPORT:case O.PLASMA_EXPLOSION:case O.PLAIN_EXPLOSION:case O.CHAINFIST_SMOKE:case O.TRACKER_EXPLOSION:case O.TELEPORT_EFFECT:case O.DBALL_GOAL:case O.NUKEBLAST:case O.WIDOWSPLASH:case O.EXPLOSION1_BIG:case O.EXPLOSION1_NP:this.readPos(r);break;case O.GUNSHOT:case O.BLOOD:case O.BLASTER:case O.SHOTGUN:case O.SPARKS:case O.BULLET_SPARKS:case O.SCREEN_SPARKS:case O.SHIELD_SPARKS:case O.BLASTER2:case O.FLECHETTE:case O.MOREBLOOD:case O.ELECTRIC_SPARKS:case O.HEATBEAM_SPARKS:case O.HEATBEAM_STEAM:this.readPos(r),this.readDir(i);break;case O.SPLASH:case O.LASER_SPARKS:case O.WELDING_SPARKS:case O.TUNNEL_SPARKS:a=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte();break;case O.BLUEHYPERBLASTER:this.getProtocolVersion()>=32?(this.readPos(r),this.readPos(n)):(this.readPos(r),this.readDir(i));break;case O.GREENBLOOD:this.getProtocolVersion()>=32?(this.readPos(r),this.readDir(i)):(this.readPos(r),this.readPos(n));break;case O.RAILTRAIL:case O.BUBBLETRAIL:case O.BFG_LASER:case O.DEBUGTRAIL:case O.BUBBLETRAIL2:this.readPos(r),this.readPos(n);break;case O.PARASITE_ATTACK:case O.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.readPos(r),this.readPos(n);break;case O.GRAPPLE_CABLE:s=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readPos(i);break;case O.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.readPos(r),this.readPos(n);break;case O.FLASHLIGHT:this.readPos(r),s=this.stream.readShort();break;case O.FORCEWALL:this.readPos(r),this.readPos(n),o=this.stream.readByte();break;case O.STEAM:let u=this.stream.readShort();a=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte(),this.stream.readShort(),u!==-1&&this.stream.readLong();break;case O.WIDOWBEAMOUT:this.stream.readShort();case O.HEATBEAM:case O.MONSTER_HEATBEAM:s=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readDir(i);break}this.handler&&this.handler.onTempEntity(e,r,n,i,a,o,s,c,l)}parseSpawnBaseline(){let e=this.protocolHandler.parseEntityBits(this.stream),r=Kr();this.protocolHandler.parseDelta(Kr(),r,e.number,e.bits,e.bitsHigh,this.stream),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=0;this.getProtocolVersion()!==26&&this.getProtocolVersion()!==25&&(n=this.stream.readByte());let i=this.stream.readByte(),a=this.stream.readData(i),o=this.stream.readByte();if(o=this.protocolHandler.translateCommand(o),o!==C.playerinfo){if(this.strictMode)throw new Error(`Expected svc_playerinfo after svc_frame, got ${o}`);return}let s=this.parsePlayerState(),c=this.stream.readByte();if(c=this.protocolHandler.translateCommand(c),c!==C.packetentities&&c!==C.deltapacketentities){if(this.strictMode)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${c}`);return}let l=this.collectPacketEntities();if(this.isDemo===S2){let u=this.stream.readByte();for(let d=0;d<u;d++)this.stream.readByte()}this.isDemo===_2&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:a,playerState:s,packetEntities:{delta:!0,entities:l}})}parsePlayerState(){return this.protocolHandler.parsePlayerState(this.stream)}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Mr(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.protocolHandler.parseEntityBits(this.stream);if(r.bits&ao){if(r.number===0)break;continue}let n=Kr();if(r.number===0)break;this.protocolHandler.parseDelta(Kr(),n,r.number,r.bits,r.bitsHigh,this.stream),e.push(n)}return e}};var kf=(u=>(u.WeaponFire="weapon_fire",u.DamageDealt="damage_dealt",u.DamageReceived="damage_received",u.Pickup="pickup",u.Death="death",u.Kill="kill",u.Spawn="spawn",u.PlayerInfo="player_info",u.Chat="chat",u.Objective="objective",u))(kf||{});var qa=class{constructor(e){h(this,"buffer");h(this,"events",[]);h(this,"summary",{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map});h(this,"header",null);h(this,"configStrings",new Map);h(this,"serverInfo",{});h(this,"statistics",null);h(this,"playerStats",new Map);h(this,"weaponStats",new Map);h(this,"activeEntities",new Set);this.buffer=e}analyze(){let e=new wr(this.buffer),r=-1,n=0,i=.1,a=0,o={onServerData:(s,c,l,u,d,f,m,p)=>{a=s,this.header={protocolVersion:s,gameDir:u,levelName:f,playerNum:d,serverCount:c,spawnCount:c,tickRate:m,demoType:p},m&&m>0&&(i=1/m)},onConfigString:(s,c)=>{this.configStrings.set(s,c),s===0&&this.parseServerInfo(c)},onSpawnBaseline:s=>{},onFrame:s=>{let c=new Set;if(s.packetEntities&&s.packetEntities.entities)for(let l of s.packetEntities.entities)c.add(l.number),this.activeEntities.has(l.number)||this.recordEvent({type:"spawn",frame:r,time:n,entityId:l.number,position:{x:l.origin.x,y:l.origin.y,z:l.origin.z},description:`Entity ${l.number} spawned`});this.activeEntities=c,s.playerState&&this.header},onPrint:(s,c)=>{let l=c.replace(/\n/g," ").trim();l.includes("died")||l.includes("killed")||l.includes("suicide")?(this.summary.totalDeaths++,this.recordEvent({type:"death",frame:r,time:n,description:l})):l.startsWith("You got the ")?this.recordEvent({type:"pickup",frame:r,time:n,description:l}):(s===3||s===2)&&this.recordEvent({type:"chat",frame:r,time:n,description:l,data:{level:s}})},onCenterPrint:s=>{this.recordEvent({type:"objective",frame:r,time:n,description:s.trim()})},onStuffText:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onMuzzleFlash2:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onMuzzleFlash3:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{},onDamage:s=>{for(let c of s)if(this.recordEvent({type:"damage_received",frame:r,time:n,value:c.damage,position:c.dir,description:`Took ${c.damage} damage`}),this.summary.damageReceived+=c.damage,this.header){let l=this.getOrCreatePlayerStats(this.header.playerNum);l.damageReceived+=c.damage}}};for(;e.hasMore();){let s=e.readNextBlock();if(!s)break;r++,n=r*i;let c=new _t(s.data,o);c.setProtocolVersion(a),c.parseMessage(),a=c.getProtocolVersion()}return this.statistics={duration:n,frameCount:r+1,averageFps:(r+1)/(n||1),mapName:this.header?.levelName||"unknown",playerCount:1},{events:this.events,summary:this.summary,header:this.header,configStrings:this.configStrings,serverInfo:this.serverInfo,statistics:this.statistics,playerStats:this.playerStats,weaponStats:this.weaponStats}}handleWeaponFire(e,r,n,i){this.recordEvent({type:"weapon_fire",frame:n,time:i,entityId:e,value:r,description:`Weapon ${r} fired by ${e}`});let a=this.summary.weaponUsage.get(r)||0;this.summary.weaponUsage.set(r,a+1);let o=this.getOrCreateWeaponStat(e,r);o.shotsFired++}recordEvent(e){this.events.push(e)}parseServerInfo(e){let r=e.split("\\");for(let n=1;n<r.length;n+=2)n+1<r.length&&(this.serverInfo[r[n]]=r[n+1])}getOrCreatePlayerStats(e){let r=this.playerStats.get(e);return r||(r={kills:0,deaths:0,damageDealt:0,damageReceived:0,suicides:0},this.playerStats.set(e,r)),r}getOrCreateWeaponStat(e,r){let n=this.weaponStats.get(e);n||(n=[],this.weaponStats.set(e,n));let i=n.find(a=>a.weaponId===r);return i||(i={weaponId:r,shotsFired:0,hits:0,kills:0},n.push(i)),i}};var Uf=(i=>(i[i.FirstPerson=0]="FirstPerson",i[i.ThirdPerson=1]="ThirdPerson",i[i.Free=2]="Free",i[i.Follow=3]="Follow",i))(Uf||{});var Jc=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Jc||{}),w2=()=>({onServerData:()=>{},onConfigString:()=>{},onSpawnBaseline:()=>{},onFrame:()=>{},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}}),Hs=class{constructor(){h(this,"reader",null);h(this,"buffer",null);h(this,"state",0);h(this,"playbackSpeed",1);h(this,"handler");h(this,"callbacks");h(this,"currentProtocolVersion",0);h(this,"currentFrameIndex",-1);h(this,"lastFrameData",null);h(this,"accumulatedTime",0);h(this,"frameDuration",100);h(this,"snapshotInterval",100);h(this,"snapshots",new Map);h(this,"cachedEvents",null);h(this,"cachedSummary",null);h(this,"cachedHeader",null);h(this,"cachedConfigStrings",null);h(this,"cachedServerInfo",null);h(this,"cachedStatistics",null);h(this,"cachedPlayerStats",null);h(this,"cachedWeaponStats",null);h(this,"tracker",null);h(this,"cameraMode",0);h(this,"thirdPersonDistance",80);h(this,"thirdPersonOffset",{x:0,y:0,z:0})}setHandler(e){this.handler=e}setCallbacks(e){this.callbacks=e}loadDemo(e){this.buffer=e,this.reader=new wr(e),this.transitionState(0),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.snapshots.clear(),this.lastFrameData=null,this.cachedEvents=null,this.cachedSummary=null,this.cachedHeader=null,this.cachedConfigStrings=null,this.cachedServerInfo=null,this.cachedStatistics=null,this.cachedPlayerStats=null,this.cachedWeaponStats=null}play(){this.reader&&this.state!==1&&this.transitionState(1)}pause(){this.state===1&&this.transitionState(2)}stop(){this.transitionState(0),this.reader&&this.reader.reset(),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.lastFrameData=null}transitionState(e){this.state!==e&&(this.state=e,this.callbacks?.onPlaybackStateChange&&this.callbacks.onPlaybackStateChange(e))}setFrameDuration(e){this.frameDuration=e}setSpeed(e){this.playbackSpeed=Math.max(.1,Math.min(e,16))}getSpeed(){return this.playbackSpeed}getPlaybackSpeed(){return this.playbackSpeed}getInterpolationFactor(){return this.frameDuration<=0?0:Math.max(0,Math.min(1,this.accumulatedTime/this.frameDuration))}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.processNextFrame())return;this.accumulatedTime-=this.frameDuration,this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}}stepForward(){this.reader&&(this.processNextFrame(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime()))}stepBackward(){this.reader&&this.currentFrameIndex>0&&this.seek(this.currentFrameIndex-1)}seekToTime(e){let r=this.timeToFrame(e);this.seek(r)}seekToFrame(e){this.seek(e)}frameToTime(e){return e*this.frameDuration/1e3}timeToFrame(e){return Math.floor(e*1e3/this.frameDuration)}playFrom(e){if(e.type==="frame")this.seek(e.frame);else if(e.type==="time")this.seekToTime(e.seconds);else throw new Error(`Invalid offset type: ${e.type}`);this.play()}playRange(e,r){let n=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),i=r.type==="frame"?r.frame:this.timeToFrame(r.seconds),a=this.getTotalFrames(),o=Math.max(0,a-1);if(n<0)throw new Error(`Invalid start offset: ${n}`);if(i<n)throw new Error(`End offset (${i}) cannot be before start offset (${n})`);this.playFrom(e);let s=this.callbacks?.onFrameUpdate,c={...this.callbacks,onFrameUpdate:l=>{if(s&&s(l),this.currentFrameIndex>=i){this.pause();let u=this.callbacks?.onPlaybackComplete;this.callbacks===c&&this.setCallbacks({...this.callbacks,onFrameUpdate:s}),u&&u()}}};this.setCallbacks(c)}seek(e){if(!this.reader)return;let r=this.getTotalFrames();if(r>0&&e>=r&&(e=r-1),e<0&&(e=0),e===this.currentFrameIndex+1){this.processNextFrame(),this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}if(e===this.currentFrameIndex){this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}let n=-1,i=null;if(e>this.currentFrameIndex&&this.currentFrameIndex!==-1&&(n=this.currentFrameIndex),this.callbacks?.onRestoreSnapshot)for(let[a,o]of this.snapshots)a<=e&&a>n&&(n=a,i=o);for(n===-1&&this.currentFrameIndex>e?(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0):n===-1&&(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0),i&&this.callbacks?.onRestoreSnapshot&&(this.callbacks.onRestoreSnapshot(i),this.reader.seekToMessage(n+1)?this.currentFrameIndex=n:(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0));this.currentFrameIndex<e&&(this.callbacks?.onCaptureSnapshot&&(this.currentFrameIndex+1)%this.snapshotInterval,!!this.processNextFrame()););this.accumulatedTime=0,this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}processNextFrame(){if(!this.reader||!this.reader.hasMore())return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;let e=this.reader.readNextBlock();if(!e)return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;this.currentFrameIndex++,this.tracker&&(this.tracker.setCurrentFrame(this.currentFrameIndex),this.tracker.setCurrentTime(this.getCurrentTime()));try{let r={...this.handler||w2(),onFrame:i=>{this.lastFrameData=i,this.handler?.onFrame&&this.handler.onFrame(i),this.callbacks?.onFrameUpdate&&this.callbacks.onFrameUpdate(i)}},n=new _t(e.data,r);if(n.setProtocolVersion(this.currentProtocolVersion),n.parseMessage(),this.currentProtocolVersion=n.getProtocolVersion(),this.callbacks?.onCaptureSnapshot&&this.currentFrameIndex%this.snapshotInterval===0&&this.currentFrameIndex>0){let i=this.callbacks.onCaptureSnapshot(this.currentFrameIndex);i&&this.snapshots.set(this.currentFrameIndex,i)}}catch(r){return console.error("Error processing demo frame",r),this.callbacks?.onPlaybackError&&this.callbacks.onPlaybackError(r instanceof Error?r:new Error(String(r))),!1}return!0}getState(){return this.state}getCurrentTime(){return this.currentFrameIndex<0?this.accumulatedTime/1e3:(this.currentFrameIndex*this.frameDuration+this.accumulatedTime)/1e3}getFrameCount(){return this.reader?this.reader.getMessageCount():0}getTotalFrames(){return this.getFrameCount()}getCurrentFrame(){return this.currentFrameIndex<0?0:this.currentFrameIndex}getDuration(){return this.getFrameCount()*this.frameDuration/1e3}getTotalBytes(){return this.reader?this.reader.getProgress().total:0}getProcessedBytes(){return this.reader?this.reader.getOffset():0}getFrameData(e){if(e===this.currentFrameIndex&&this.lastFrameData)return this.lastFrameData;let r=this.state;return this.pause(),this.seek(e),r===1&&this.play(),this.lastFrameData}getFramePlayerState(e){if(e===this.currentFrameIndex&&this.handler?.getPlayerState){let n=this.handler.getPlayerState();if(n)return n}let r=this.getFrameData(e);return r?r.playerState:null}getFrameEntities(e){if(e===this.currentFrameIndex&&this.handler?.getEntities){let r=this.handler.getEntities();if(r)return Array.from(r.values())}if(this.seek(e),this.handler?.getEntities){let r=this.handler.getEntities();return r?Array.from(r.values()):[]}return[]}compareFrames(e,r){let n=this.getFramePlayerState(e),i=this.getFrameEntities(e),a=new Map;i.forEach(u=>a.set(u.number,u));let o=this.getFramePlayerState(r),s=this.getFrameEntities(r),c=new Map;s.forEach(u=>c.set(u.number,u));let l={frameA:e,frameB:r,playerStateDiff:{origin:null,viewangles:null,health:null,ammo:null},entityDiffs:{added:[],removed:[],moved:[]}};n&&o&&((n.origin.x!==o.origin.x||n.origin.y!==o.origin.y||n.origin.z!==o.origin.z)&&(l.playerStateDiff.origin={x:o.origin.x-n.origin.x,y:o.origin.y-n.origin.y,z:o.origin.z-n.origin.z}),n.stats[1]!==o.stats[1]&&(l.playerStateDiff.health=o.stats[1]-n.stats[1]),n.stats[2]!==o.stats[2]&&(l.playerStateDiff.ammo=o.stats[2]-n.stats[2]));for(let[u,d]of c){let f=a.get(u);f?(f.origin.x!==d.origin.x||f.origin.y!==d.origin.y||f.origin.z!==d.origin.z)&&l.entityDiffs.moved.push({id:u,delta:{x:d.origin.x-f.origin.x,y:d.origin.y-f.origin.y,z:d.origin.z-f.origin.z}}):l.entityDiffs.added.push(u)}for(let[u,d]of a)c.has(u)||l.entityDiffs.removed.push(u);return l}getEntityTrajectory(e,r,n){let i=[],a=this.getCurrentFrame();for(this.seek(r);this.getCurrentFrame()<=n&&this.state!==3;){let o=null;if(e===-1){let s=this.getFramePlayerState(this.getCurrentFrame());s&&(o={...s.origin})}else if(this.handler?.getEntities){let s=this.handler.getEntities().get(e);s&&(o={...s.origin})}if(o&&i.push(o),this.getCurrentFrame()===n)break;this.stepForward()}return this.seek(a),i}getEvents(){return this.ensureAnalysis(),this.cachedEvents||[]}getDemoEvents(){return this.getEvents()}filterEvents(e,r){return this.getDemoEvents().filter(i=>!(i.type!==e||r!==void 0&&i.entityId!==r))}getEventSummary(){return this.ensureAnalysis(),this.cachedSummary||{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map}}getMetadata(){let e=this.getDemoHeader();if(!e)return null;let r=this.getDemoServerInfo(),n="Unknown";return this.cachedConfigStrings,{mapName:e.levelName,playerName:n,serverName:r.hostname,demoVersion:e.protocolVersion,tickRate:e.tickRate||10}}getDemoHeader(){return this.ensureAnalysis(),this.cachedHeader}getDemoConfigStrings(){return this.ensureAnalysis(),this.cachedConfigStrings||new Map}getDemoServerInfo(){return this.ensureAnalysis(),this.cachedServerInfo||{}}getDemoStatistics(){return this.ensureAnalysis(),this.cachedStatistics}getPlayerStatistics(e){return this.ensureAnalysis(),this.cachedPlayerStats?.get(e)||null}getWeaponStatistics(e){return this.ensureAnalysis(),this.cachedWeaponStats?.get(e)||null}ensureAnalysis(){if(!this.cachedEvents&&this.buffer){let r=new qa(this.buffer).analyze();this.cachedEvents=r.events,this.cachedSummary=r.summary,this.cachedHeader=r.header,this.cachedConfigStrings=r.configStrings,this.cachedServerInfo=r.serverInfo,this.cachedStatistics=r.statistics,this.cachedPlayerStats=r.playerStats,this.cachedWeaponStats=r.weaponStats}}setCameraMode(e){this.cameraMode=e}getCameraMode(){return this.cameraMode}setThirdPersonDistance(e){this.thirdPersonDistance=e}setThirdPersonOffset(e){this.thirdPersonOffset=e}async playWithTracking(e,r={}){if(this.tracker=e,e.startTracking(),r.fastForward)try{this.state===0&&this.reader,this.transitionState(1);let n=100,i=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let a=0;for(;a<n;){if(!this.processNextFrame()){this.transitionState(0);let o=e.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),o}a++}return await new Promise(o=>setTimeout(o,0)),i()};return await i()}catch(n){throw this.transitionState(0),e.stopTracking(),this.tracker=null,n}else return new Promise((n,i)=>{let a=this.callbacks?.onPlaybackComplete,o=this.callbacks?.onPlaybackError,s=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:a,onPlaybackError:o}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let c=e.stopTracking();a&&a(),s(),n(c)},onPlaybackError:c=>{e.stopTracking(),o&&o(c),s(),i(c)}}),this.play()})}async playRangeWithTracking(e,r,n,i={}){this.tracker=n,n.startTracking();let a=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),o=r.type==="frame"?r.frame:this.timeToFrame(r.seconds);if(i.fastForward)try{this.playFrom(e),this.transitionState(1);let s=100,c=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let l=0;for(;l<s;){if(this.currentFrameIndex>=o||!this.processNextFrame()){this.transitionState(0);let u=n.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),u}l++}return await new Promise(u=>setTimeout(u,0)),c()};return await c()}catch(s){throw this.transitionState(0),n.stopTracking(),this.tracker=null,s}else return new Promise((s,c)=>{let l=this.callbacks?.onPlaybackComplete,u=this.callbacks?.onPlaybackError,d=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:l,onPlaybackError:u}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let f=n.stopTracking();l&&l(),d(),s(f)},onPlaybackError:f=>{n.stopTracking(),u&&u(f),d(),c(f)}}),this.playRange(e,r)})}};var Ws=class{constructor(){h(this,"isRecording",!1);h(this,"messageBuffer");h(this,"startTime",0);h(this,"frameCount",0);h(this,"filename",null);h(this,"lastMessageSize",-1);this.messageBuffer=new li(1024*1024)}startRecording(e,r=0){this.isRecording||(this.isRecording=!0,this.filename=e,this.startTime=r,this.frameCount=0,this.messageBuffer.reset(),console.log(`DemoRecorder: Started recording to ${e}`))}recordMessage(e){if(this.isRecording){this.messageBuffer.writeLong(e.byteLength);for(let r=0;r<e.length;r++)this.messageBuffer.writeByte(e[r]);this.frameCount++}}stopRecording(){return this.isRecording?(this.isRecording=!1,this.messageBuffer.writeLong(-1),console.log(`DemoRecorder: Stopped recording. Frames: ${this.frameCount}, Size: ${this.messageBuffer.getOffset()} bytes`),this.messageBuffer.getData()):null}getIsRecording(){return this.isRecording}};var eu=class{constructor(e,r=34){h(this,"writer");h(this,"protocol");this.writer=e||new li(new Uint8Array(64*1024)),this.protocol=r}getData(){return this.writer.getData()}getOpcode(e){if(this.protocol===34)switch(e){case C.serverdata:return 13;case C.frame:return 5;case C.playerinfo:return 17;case C.packetentities:return 18;case C.deltapacketentities:return 19;case C.print:return 11;case C.centerprint:return 16;case C.stufftext:return 12;case C.sound:return 10;case C.temp_entity:return 9;case C.configstring:return 14;case C.spawnbaseline:return 15;case C.layout:return 7;case C.inventory:return 6;case C.muzzleflash:return 8;case C.muzzleflash2:return 20}return e}writeCommand(e,r){let n=r??this.protocol;n===34||n===0?this.writer.writeByte(this.getOpcode(e)):this.writer.writeByte(e)}writeServerData(e,r,n,i,a,o){this.writeCommand(C.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeString(i),this.writer.writeShort(a),this.writer.writeString(o)}writeConfigString(e,r){this.writeCommand(C.configstring),this.writer.writeShort(e),this.writer.writeString(r)}writeStuffText(e){this.writeCommand(C.stufftext),this.writer.writeString(e)}writeCenterPrint(e){this.writeCommand(C.centerprint),this.writer.writeString(e)}writePrint(e,r){this.writeCommand(C.print),this.writer.writeByte(e),this.writer.writeString(r)}writeLayout(e){this.writeCommand(C.layout),this.writer.writeString(e)}writeInventory(e){this.writeCommand(C.inventory);for(let r of e)this.writer.writeShort(r);for(let r=e.length;r<256;r++)this.writer.writeShort(0)}writeMuzzleFlash(e,r){this.writeCommand(C.muzzleflash),this.writer.writeShort(e),this.writer.writeByte(r)}writeMuzzleFlash2(e,r){this.writeCommand(C.muzzleflash2),this.writer.writeShort(e),this.writer.writeByte(r)}writeSound(e,r,n,i,a,o,s,c){this.writeCommand(C.sound),this.writer.writeByte(e),this.writer.writeByte(r),e&1&&this.writer.writeByte(n),e&2&&this.writer.writeByte(i),e&16&&this.writer.writeByte(a),e&8&&this.writer.writeShort(o),e&4&&(this.writer.writeCoord(s.x),this.writer.writeCoord(s.y),this.writer.writeCoord(s.z))}writeTempEntity(e,r,n,i,a,o,s,c,l){this.writeCommand(C.temp_entity),this.writer.writeByte(e),r&&this.writer.writePos(r)}writePlayerState(e){this.writeCommand(C.playerinfo);let r=0;e.pm_type!==0&&(r|=1),(e.origin.x!==0||e.origin.y!==0||e.origin.z!==0)&&(r|=2),(e.velocity.x!==0||e.velocity.y!==0||e.velocity.z!==0)&&(r|=4),e.pm_time!==0&&(r|=8),e.pm_flags!==0&&(r|=16),e.gravity!==0&&(r|=32),(e.delta_angles.x!==0||e.delta_angles.y!==0||e.delta_angles.z!==0)&&(r|=64),(e.viewoffset.x!==0||e.viewoffset.y!==0||e.viewoffset.z!==0)&&(r|=128),(e.viewangles.x!==0||e.viewangles.y!==0||e.viewangles.z!==0)&&(r|=256),(e.kick_angles.x!==0||e.kick_angles.y!==0||e.kick_angles.z!==0)&&(r|=512),e.gun_index!==0&&(r|=4096),(e.gun_frame!==0||e.gun_offset.x!==0||e.gun_offset.y!==0||e.gun_offset.z!==0||e.gun_angles.x!==0||e.gun_angles.y!==0||e.gun_angles.z!==0)&&(r|=8192),(e.blend[0]!==0||e.blend[1]!==0||e.blend[2]!==0||e.blend[3]!==0)&&(r|=1024),e.fov!==0&&(r|=2048),e.rdflags!==0&&(r|=16384),e.watertype!==0&&(r|=32768),this.writer.writeShort(r),r&1&&this.writer.writeByte(e.pm_type),r&2&&(this.writer.writeShort(e.origin.x/.125),this.writer.writeShort(e.origin.y/.125),this.writer.writeShort(e.origin.z/.125)),r&4&&(this.writer.writeShort(e.velocity.x/.125),this.writer.writeShort(e.velocity.y/.125),this.writer.writeShort(e.velocity.z/.125)),r&8&&this.writer.writeByte(e.pm_time),r&16&&this.writer.writeByte(e.pm_flags),r&32&&this.writer.writeShort(e.gravity),r&64&&(this.writer.writeShort(e.delta_angles.x/(180/32768)),this.writer.writeShort(e.delta_angles.y/(180/32768)),this.writer.writeShort(e.delta_angles.z/(180/32768))),r&128&&(this.writer.writeByte(e.viewoffset.x/.25),this.writer.writeByte(e.viewoffset.y/.25),this.writer.writeByte(e.viewoffset.z/.25)),r&256&&(this.writer.writeShort(e.viewangles.x/(360/65536)),this.writer.writeShort(e.viewangles.y/(360/65536)),this.writer.writeShort(e.viewangles.z/(360/65536))),r&512&&(this.writer.writeByte(e.kick_angles.x/.25),this.writer.writeByte(e.kick_angles.y/.25),this.writer.writeByte(e.kick_angles.z/.25)),r&4096&&this.writer.writeByte(e.gun_index),r&8192&&(this.writer.writeByte(e.gun_frame),this.writer.writeByte(e.gun_offset.x/.25),this.writer.writeByte(e.gun_offset.y/.25),this.writer.writeByte(e.gun_offset.z/.25),this.writer.writeByte(e.gun_angles.x/.25),this.writer.writeByte(e.gun_angles.y/.25),this.writer.writeByte(e.gun_angles.z/.25)),r&1024&&(this.writer.writeByte(e.blend[0]),this.writer.writeByte(e.blend[1]),this.writer.writeByte(e.blend[2]),this.writer.writeByte(e.blend[3])),r&2048&&this.writer.writeByte(e.fov),r&16384&&this.writer.writeByte(e.rdflags),r&32768&&this.writer.writeByte(e.watertype);let n=0;for(let i=0;i<32;i++)e.stats[i]!==0&&(n|=1<<i);this.writer.writeLong(n);for(let i=0;i<32;i++)n&1<<i&&this.writer.writeShort(e.stats[i])}writePacketEntities(e,r,n){this.writeCommand(r?C.deltapacketentities:C.packetentities);for(let i of e)this.writeDeltaEntity(Kr(),i,!0);this.writer.writeShort(0)}writeFrame(e,r){this.writeCommand(C.frame),this.writer.writeLong(e.serverFrame),this.writer.writeLong(e.deltaFrame),r!==26&&r!==25&&this.writer.writeByte(e.surpressCount),this.writer.writeByte(e.areaBytes),this.writer.writeBytes(e.areaBits),this.writePlayerState(e.playerState),this.writePacketEntities(e.packetEntities.entities,e.packetEntities.delta,r)}writeDeltaEntity(e,r,n){let i=0,a=0;(r.modelindex!==e.modelindex||n)&&(i|=Bt),(r.modelindex2!==e.modelindex2||n)&&(i|=It),(r.modelindex3!==e.modelindex3||n)&&(i|=Dt),(r.modelindex4!==e.modelindex4||n)&&(i|=kt),(r.frame!==e.frame||n)&&(r.frame>=256?i|=Ft:i|=Lt),(r.skinnum!==e.skinnum||n)&&(r.skinnum>=256?i|=tt:i|=Qe),(r.effects!==e.effects||n)&&(r.effects>=256?i|=et:i|=je),(r.renderfx!==e.renderfx||n)&&(r.renderfx>=256?i|=Je:i|=Ze),(r.origin.x!==e.origin.x||n)&&r.origin.x!==0&&(i|=Mt),(r.origin.y!==e.origin.y||n)&&r.origin.y!==0&&(i|=At),(r.origin.z!==e.origin.z||n)&&r.origin.z!==0&&(i|=Rt),(r.angles.x!==e.angles.x||n)&&r.angles.x!==0&&(i|=Ct),(r.angles.y!==e.angles.y||n)&&r.angles.y!==0&&(i|=Et),(r.angles.z!==e.angles.z||n)&&r.angles.z!==0&&(i|=Tt),(r.sound!==e.sound||n)&&(i|=Ut),(r.event!==e.event||n)&&(i|=Pt),(r.solid!==e.solid||n)&&(i|=zt),this.protocol!==34&&((r.alpha!==e.alpha||n)&&(i|=Lr),(r.scale!==e.scale||n)&&(i|=Cr),(r.instanceBits!==e.instanceBits||n)&&(i|=Br),(r.loopVolume!==e.loopVolume||n)&&(i|=Fr),(r.loopAttenuation!==e.loopAttenuation||n)&&(a|=wn),(r.owner!==e.owner||n)&&(a|=Mn),(r.oldFrame!==e.oldFrame||n)&&(a|=An)),a>0&&(i|=Vi),i&4278190080&&(i|=Rr),i&4294901760&&(i|=Pr),i&4294967040&&(i|=Tr),this.writer.writeByte(i&255),i&Tr&&this.writer.writeByte(i>>8&255),i&Pr&&this.writer.writeByte(i>>16&255),i&Rr&&this.writer.writeByte(i>>24&255),i&Vi&&this.writer.writeByte(a&255),r.number>=256?this.writer.writeShort(r.number):this.writer.writeByte(r.number),i&Bt&&this.writer.writeByte(r.modelindex),i&It&&this.writer.writeByte(r.modelindex2),i&Dt&&this.writer.writeByte(r.modelindex3),i&kt&&this.writer.writeByte(r.modelindex4),i&Lt&&this.writer.writeByte(r.frame),i&Ft&&this.writer.writeShort(r.frame),i&Qe&&this.writer.writeByte(r.skinnum),i&tt&&this.writer.writeShort(r.skinnum),i&je&&this.writer.writeByte(r.effects),i&et&&this.writer.writeShort(r.effects),i&Ze&&this.writer.writeByte(r.renderfx),i&Je&&this.writer.writeShort(r.renderfx),i&Mt&&this.writer.writeCoord(r.origin.x),i&At&&this.writer.writeCoord(r.origin.y),i&Rt&&this.writer.writeCoord(r.origin.z),i&Ct&&this.writer.writeAngle(r.angles.x),i&Et&&this.writer.writeAngle(r.angles.y),i&Tt&&this.writer.writeAngle(r.angles.z),i&Ut&&this.writer.writeByte(r.sound??0),i&Pt&&this.writer.writeByte(r.event??0),i&zt&&this.writer.writeShort(r.solid),this.protocol!==34&&(i&Lr&&this.writer.writeByte(r.alpha*255),i&Cr&&this.writer.writeFloat(r.scale),i&Br&&this.writer.writeLong(r.instanceBits),i&Fr&&this.writer.writeByte(r.loopVolume*255),a&wn&&this.writer.writeByte(r.loopAttenuation*255),a&Mn&&this.writer.writeShort(r.owner),a&An&&this.writer.writeShort(r.oldFrame))}};var tu=class{static validate(e,r){if(r&&!r.toLowerCase().endsWith(".dm2"))return{valid:!1,error:"Invalid file extension (expected .dm2)"};if(e.byteLength<5)return{valid:!1,error:"File too small to be a valid demo"};let n=new DataView(e),i=n.getInt32(0,!0);if(i<=0||i>e.byteLength-4)return{valid:!1,error:`Invalid first block length: ${i}`};let a=n.getUint8(4);if(a!==C.serverdata)return{valid:!1,error:`First command is not svc_serverdata (expected ${C.serverdata}, got ${a})`};let o=-1;return i>=5&&(o=n.getInt32(5,!0)),{valid:!0,version:o}}};var ru=class{constructor(e){h(this,"parser");h(this,"frames",[]);h(this,"serverData");h(this,"configStrings",new Map);h(this,"baselines",new Map);h(this,"currentEntities",new Map);if(e){let r=new ei(e.byteLength);r.append(new Uint8Array(e)),r.setReadPosition(0),this.parser=new _t(r,this)}else this.parser=new _t(new ei,this)}extractClip(e,r,n,i){let a=new wr(e.buffer),o=[],s=0,c=r.frame??-1,l=n.frame??Number.MAX_SAFE_INTEGER,u=0,d=0;for(;a.nextBlock();){let g=a.getBlock().data,b=!1,_=-1,x=!1,v={onServerData:w=>{u=w,b=!0,x=!0},onConfigString:()=>{b=!0,x=!0},onSpawnBaseline:()=>{b=!0,x=!0},onFrame:w=>{_=w.serverFrame,x=!0,_>=c&&_<=l&&(b=!0)},onCenterPrint:()=>{x=!0},onStuffText:()=>{x=!0},onPrint:()=>{x=!0},onSound:()=>{x=!0},onTempEntity:()=>{x=!0},onLayout:()=>{x=!0},onInventory:()=>{x=!0},onMuzzleFlash:()=>{x=!0},onMuzzleFlash2:()=>{x=!0},onDisconnect:()=>{x=!0},onReconnect:()=>{x=!0},onDownload:()=>{x=!0}},S=new ei(g.getLength());S.append(g.readData(g.getLength())),S.setReadPosition(0),g.seek(0);let M=new _t(S,v);u>0&&M.setProtocolVersion(u);try{M.parseMessage()}catch{}if(x||d>=c&&d<=l&&(b=!0),b){let w=new Uint8Array(4);new DataView(w.buffer).setUint32(0,g.getLength(),!0),o.push(w);let L=g.readData(g.getLength());o.push(L),s+=4+L.length}d++}let f=new Uint8Array(4);new DataView(f.buffer).setInt32(0,-1,!0),o.push(f),s+=4;let m=new Uint8Array(s),p=0;for(let y of o)m.set(y,p),p+=y.length;return m}extractDemoRange(e,r,n){return this.extractClip(e,{frame:r},{frame:n})}onServerData(e,r,n,i,a,o){this.serverData={protocol:e,serverCount:r,attractLoop:n,gameDir:i,playerNum:a,levelName:o}}onConfigString(e,r){this.configStrings.set(e,r)}onSpawnBaseline(e){this.baselines.set(e.number,e)}onFrame(e){this.frames.push(e)}onCenterPrint(e){}onStuffText(e){}onPrint(e,r){}onSound(e,r,n,i,a,o,s){}onTempEntity(e,r,n,i,a,o,s,c,l){}onLayout(e){}onInventory(e){}onMuzzleFlash(e,r){}onMuzzleFlash2(e,r){}onDisconnect(){}onReconnect(){}onDownload(e,r,n){}};function q0(t,e){let r=e.bits;t.bits=r,t.number=e.number,r&Bt&&(t.modelindex=e.modelindex),r&It&&(t.modelindex2=e.modelindex2),r&Dt&&(t.modelindex3=e.modelindex3),r&kt&&(t.modelindex4=e.modelindex4),r&Lt&&(t.frame=e.frame),r&Ft&&(t.frame=e.frame),r&Qe&&(t.skinnum=e.skinnum),r&tt&&(t.skinnum=e.skinnum),r&je&&(t.effects=e.effects),r&et&&(t.effects=e.effects),r&Ze&&(t.renderfx=e.renderfx),r&Je&&(t.renderfx=e.renderfx),r&Mt&&(t.origin.x=e.origin.x),r&At&&(t.origin.y=e.origin.y),r&Rt&&(t.origin.z=e.origin.z),r&Ct&&(t.angles.x=e.angles.x),r&Et&&(t.angles.y=e.angles.y),r&Tt&&(t.angles.z=e.angles.z),r&br&&(t.old_origin.x=e.old_origin.x,t.old_origin.y=e.old_origin.y,t.old_origin.z=e.old_origin.z),r&Ut&&(t.sound=e.sound),r&Pt&&(t.event=e.event),r&zt&&(t.solid=e.solid),r&Lr&&(t.alpha=e.alpha),r&Cr&&(t.scale=e.scale),r&Br&&(t.instanceBits=e.instanceBits),r&Fr&&(t.loopVolume=e.loopVolume)}var zf=(f=>(f.Unknown="unknown",f.BSP="bsp",f.MD2="md2",f.MD3="md3",f.WAL="wal",f.PCX="pcx",f.TGA="tga",f.WAV="wav",f.OGG="ogg",f.TXT="txt",f.CFG="cfg",f.DEM="dem",f))(zf||{}),Z0={".bsp":"bsp",".md2":"md2",".md3":"md3",".wal":"wal",".pcx":"pcx",".tga":"tga",".wav":"wav",".ogg":"ogg",".txt":"txt",".cfg":"cfg",".dm2":"dem"};function Xs(t,e){if(t.length<e.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r])return!1;return!0}var M2=[73,66,83,80],A2=[73,68,80,50],E2=[73,68,80,51];var T2=[82,73,70,70];var L2=[79,103,103,83];function Of(t,e){let r=t.slice(t.lastIndexOf(".")).toLowerCase();if(e){if(Xs(e,M2))return"bsp";if(Xs(e,A2))return"md2";if(Xs(e,E2))return"md3";if(Xs(e,L2))return"ogg";if(e.length>128&&e[0]===10&&e[1]<6)return"pcx";if(Xs(e,T2)&&e.length>=12&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69)return"wav"}return Z0[r]?Z0[r]:"unknown"}function Nf(t){let e=Of(t);return e==="txt"||e==="cfg"}function j0(t){return!Nf(t)}function P2(t,e,r,n,i){let a=new Uint8ClampedArray(n*i*4),o=e/n,s=r/i;for(let c=0;c<i;c++)for(let l=0;l<n;l++){let u=l*o,d=c*s,f=Math.floor(u),m=Math.floor(d),p=u-f,y=d-m,g=Math.min(f+1,e-1),b=Math.min(m+1,r-1),_=(m*e+f)*4,x=(m*e+g)*4,v=(b*e+f)*4,S=(b*e+g)*4,M=(c*n+l)*4;for(let w=0;w<4;w++){let T=t[_+w],L=t[x+w],A=t[v+w],R=t[S+w],D=T*(1-p)+L*p,k=A*(1-p)+R*p,F=D*(1-y)+k*y;a[M+w]=F}}return a}function R2(t,e,r,n,i,a,o,s,c,l,u){n=Math.floor(n),i=Math.floor(i),a=Math.floor(a),o=Math.floor(o);let d=Math.abs(a-n),f=Math.abs(o-i),m=n<a?1:-1,p=i<o?1:-1,y=d-f;for(;;){if(n>=0&&n<e&&i>=0&&i<r){let b=(i*e+n)*4,_=1-u/255;t[b]=s*(u/255)+t[b]*_,t[b+1]=c*(u/255)+t[b+1]*_,t[b+2]=l*(u/255)+t[b+2]*_,t[b+3]=255}if(n===a&&i===o)break;let g=2*y;g>-f&&(y-=f,n+=m),g<d&&(y+=d,i+=p)}}function Q0(t,e,r,n,i){let s=(t.x-n.x)*.707-(t.y-n.y)*.707,c=(t.x-n.x)*.707+(t.y-n.y)*.707,l=t.z-n.z,u=.866,d=.5,f=c*u-l*d,m=c*d+l*u,p=e/2+s*i,y=r/2-m*i;return{x:p,y}}var nu=class{constructor(e){this.assetManager=e}async generateTextureThumbnail(e,r){try{let n=await this.assetManager.loadTexture(e);if(!n||n.levels.length===0)return null;let i=n.levels[0],a=i.width/i.height,o=r,s=r;a>1?s=Math.floor(r/a):o=Math.floor(r*a),o=Math.max(1,o),s=Math.max(1,s);let c=P2(i.rgba,i.width,i.height,o,s);return new ImageData(c,o,s)}catch(n){return console.error(`Failed to generate thumbnail for ${e}`,n),null}}async generateModelThumbnail(e,r){try{let n=[],i=[],a=e.split(".").pop()?.toLowerCase();if(a==="md2"){let g=await this.assetManager.loadMd2Model(e);if(!g||g.frames.length===0)return null;n=g.frames[0].vertices.map(_=>_.position);for(let _ of g.triangles)i.push(_.vertexIndices[0],_.vertexIndices[1]),i.push(_.vertexIndices[1],_.vertexIndices[2]),i.push(_.vertexIndices[2],_.vertexIndices[0])}else if(a==="md3"){let g=await this.assetManager.loadMd3Model(e);if(!g||g.surfaces.length===0)return null;let b=0;for(let _ of g.surfaces){if(_.vertices.length===0)continue;let x=_.vertices[0];n.push(...x.map(v=>({x:v.position.x,y:v.position.y,z:v.position.z})));for(let v of _.triangles)i.push(b+v.indices[0],b+v.indices[1]),i.push(b+v.indices[1],b+v.indices[2]),i.push(b+v.indices[2],b+v.indices[0]);b+=x.length}}else return null;if(n.length===0)return null;let o={x:1/0,y:1/0,z:1/0},s={x:-1/0,y:-1/0,z:-1/0};for(let g of n)o.x=Math.min(o.x,g.x),o.y=Math.min(o.y,g.y),o.z=Math.min(o.z,g.z),s.x=Math.max(s.x,g.x),s.y=Math.max(s.y,g.y),s.z=Math.max(s.z,g.z);let c={x:(o.x+s.x)/2,y:(o.y+s.y)/2,z:(o.z+s.z)/2},l=s.x-o.x,u=s.y-o.y,d=s.z-o.z,f=Math.max(l,u,d),m=Math.max(f,.001),p=r*.8/m,y=new Uint8ClampedArray(r*r*4);for(let g=0;g<i.length;g+=2){let b=i[g],_=i[g+1],x=n[b],v=n[_],S=Q0(x,r,r,c,p),M=Q0(v,r,r,c,p);R2(y,r,r,S.x,S.y,M.x,M.y,0,255,0,255)}return new ImageData(y,r,r)}catch(n){return console.error(`Failed to generate model thumbnail for ${e}`,n),null}}async getMapBounds(e,r){try{let n=fo(r);if(n.models.length>0){let i=n.models[0];return{mins:{x:i.mins[0],y:i.mins[1],z:i.mins[2]},maxs:{x:i.maxs[0],y:i.maxs[1],z:i.maxs[2]}}}return null}catch(n){return console.error("Failed to get map bounds",n),null}}async extractMapScreenshot(e){return null}};var iu=class{constructor(e){this.loader=e}async getMapStatistics(e){let r=await this.loader.load(e),n=r.faces.filter(o=>o.lightOffset!==-1).length,i=r.models[0],a=i?{mins:i.mins,maxs:i.maxs}:{mins:[0,0,0],maxs:[0,0,0]};return{entityCount:r.entities.entities.length,surfaceCount:r.faces.length,lightmapCount:n,vertexCount:r.vertices.length,bounds:a}}async getUsedTextures(e){let r=await this.loader.load(e),n=new Set;for(let i of r.texInfo)i.texture&&n.add(i.texture);return Array.from(n).sort()}async getUsedModels(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities)i.properties.model&&!i.properties.model.startsWith("*")&&n.add(i.properties.model);return Array.from(n).sort()}async getUsedSounds(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities){i.properties.noise&&n.add(i.properties.noise);for(let[a,o]of Object.entries(i.properties))(a==="noise"||a.endsWith("_sound")||a==="sound")&&typeof o=="string"&&n.add(o)}return Array.from(n).sort()}};function J0(t){let e=[],r=0,n=t.length;function i(){for(;r<n&&/\s/.test(t[r]);)r++}function a(){if(i(),r>=n)return null;if(t[r]==='"'){r++;let o=r;for(;r<n&&t[r]!=='"';)t[r],r++;let s=t.substring(o,r);return r++,s}else{if(t[r]==="{"||t[r]==="}")return t[r++];{if(t.startsWith("//",r)){for(;r<n&&t[r]!==`
|
|
1160
|
+
`;var Ap=[0,255,255,255],S_=[0,-1,-1,-1];function w_(t=Ap,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let a=e[i];r[n]=a!==void 0?a:1}return r}function M_(t){return[-(t*.25%1),0]}function A_(t=xn,e=0){let r=(t&rl)!==0,n=(t&Zr)!==0,i=(t&vn)!==0,a=(t&_n)!==0,o=(t&Sn)!==0,s=a?.33:o?.66:1,c=a||o||n,l=!c&&!i,u=r?M_(e):[0,0];return{alpha:s,blend:c,depthWrite:l,warp:n,flowOffset:u,sky:i}}var Uc=class{constructor(e,r,n){f(this,"device");f(this,"pipeline");f(this,"pipelineWireframe");f(this,"frameUniformBuffer");f(this,"surfaceUniformBuffer");f(this,"frameBindGroup");f(this,"frameBindGroupLayout");f(this,"surfaceBindGroupLayout");f(this,"textureBindGroupLayout");f(this,"defaultWhiteTexture");f(this,"defaultSampler");f(this,"defaultBindGroup");f(this,"textureBindGroupCache",new Map);this.device=e;let i=2048,a=256;this.frameUniformBuffer=e.createBuffer({size:i,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.surfaceUniformBuffer=e.createBuffer({size:a,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.frameBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),this.surfaceBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),this.textureBindGroupLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),this.defaultSampler=Fc(e),this.defaultWhiteTexture=new Yn(e,{width:1,height:1,format:"rgba8unorm",label:"bsp-default-white"}),this.defaultWhiteTexture.upload(new Uint8Array([255,255,255,255])),this.defaultBindGroup=e.createBindGroup({layout:this.textureBindGroupLayout,entries:[{binding:0,resource:this.defaultWhiteTexture.createView()},{binding:1,resource:this.defaultSampler.sampler},{binding:2,resource:this.defaultWhiteTexture.createView()},{binding:3,resource:this.defaultSampler.sampler}]}),this.createPipelines(r,n),this.frameBindGroup=e.createBindGroup({layout:this.frameBindGroupLayout,entries:[{binding:0,resource:{buffer:this.frameUniformBuffer}}]})}createPipelines(e,r){let n=this.device.createShaderModule({code:Mp}),i=this.device.createPipelineLayout({bindGroupLayouts:[this.frameBindGroupLayout,this.surfaceBindGroupLayout,this.textureBindGroupLayout]}),a={module:n,entryPoint:"vertexMain",buffers:[{arrayStride:32,attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x2"},{shaderLocation:2,offset:20,format:"float32x2"},{shaderLocation:3,offset:28,format:"float32"}]}]};this.pipeline=this.device.createRenderPipeline({layout:i,vertex:a,fragment:{module:n,entryPoint:"fragmentMain",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{format:r,depthWriteEnabled:!0,depthCompare:"less"}}),this.pipelineWireframe=this.device.createRenderPipeline({layout:i,vertex:a,fragment:{module:n,entryPoint:"fragmentMain",targets:[{format:e,writeMask:GPUColorWrite.ALL}]},primitive:{topology:"line-list"},depthStencil:{format:r,depthWriteEnabled:!0,depthCompare:"less"}})}bind(e,r){let{modelViewProjection:n,styleIndices:i=Ap,styleLayers:a=S_,styleValues:o=[],diffuseTexture:s,diffuseSampler:c,lightmapTexture:l,lightmapSampler:u,surfaceFlags:d=xn,timeSeconds:h=0,texScroll:m,alpha:p,warp:y,dlights:g=[],renderMode:b,lightmapOnly:_,brightness:x=1,gamma:v=1,fullbright:w=!1,ambient:M=0,cameraPosition:S=[0,0,0],surfaceMins:E={x:0,y:0,z:0}}=r,L=A_(d,h),A=w_(i,o),R=m?m[0]:L.flowOffset[0],D=m?m[1]:L.flowOffset[1],k=p!==void 0?p:L.alpha,F=y!==void 0?y:L.warp,U=new Float32Array(512);U.set(n,0),U.set(S,16),U[19]=0,U[20]=h,U[21]=x,U[22]=v,U[23]=M;let ee=Math.min(g.length,Vr),He=new Uint32Array(U.buffer,96,1);He[0]=ee;let We=new Uint32Array(U.buffer,100,1);We[0]=w?1:0;let Ae=32;for(let ft=0;ft<ee;ft++){let Xe=g[ft];U[Ae+0]=Xe.origin.x,U[Ae+1]=Xe.origin.y,U[Ae+2]=Xe.origin.z,U[Ae+3]=Xe.intensity,U[Ae+4]=Xe.color.x,U[Ae+5]=Xe.color.y,U[Ae+6]=Xe.color.z,U[Ae+7]=0,Ae+=8}this.device.queue.writeBuffer(this.frameUniformBuffer,0,U,0,Ae);let j=new Float32Array(32);j[0]=R,j[1]=D,j[2]=L.flowOffset[0],j[3]=L.flowOffset[1],j.set(A,4),j.set(a,8);let ue=0,ve=[1,1,1,1];b&&(b.mode==="solid"||b.mode==="wireframe"?ue=1:b.mode==="solid-faceted"?ue=2:b.mode==="worldpos-debug"?ue=3:b.mode==="distance-debug"&&(ue=4),b.color?ve=[...b.color]:b.generateRandomColor&&(ve=[1,1,1,1])),j.set(ve,12),j[16]=k;let Ie=new Uint32Array(j.buffer),nt=!L.sky&&u!==void 0&&!F;Ie[17]=nt?1:0,Ie[18]=F?1:0,Ie[19]=_?1:0,Ie[20]=ue,j[28]=E.x,j[29]=E.y,j[30]=E.z,this.device.queue.writeBuffer(this.surfaceUniformBuffer,0,j);let jt=this.device.createBindGroup({layout:this.surfaceBindGroupLayout,entries:[{binding:0,resource:{buffer:this.surfaceUniformBuffer}}]});if(s&&c&&l&&u){let ft=this.device.createBindGroup({layout:this.textureBindGroupLayout,entries:[{binding:0,resource:s},{binding:1,resource:c},{binding:2,resource:l},{binding:3,resource:u}]});e.setBindGroup(2,ft)}else e.setBindGroup(2,this.defaultBindGroup);let mr=b&&b.mode==="wireframe"?this.pipelineWireframe:this.pipeline;return e.setPipeline(mr),e.setBindGroup(0,this.frameBindGroup),e.setBindGroup(1,jt),L}draw(e,r,n){r.gpuIndexBuffer&&(n&&n.mode==="wireframe"||(e.setVertexBuffer(0,r.gpuVertexBuffer),e.setIndexBuffer(r.gpuIndexBuffer,"uint16"),e.drawIndexed(r.indexCount)))}destroy(){this.frameUniformBuffer.destroy(),this.surfaceUniformBuffer.destroy(),this.defaultWhiteTexture.destroy()}};var rf=class{constructor(e,r,n){this.context=e;this.frameRenderer=r;this.pipelines=n;f(this,"type","webgpu");f(this,"picCache",new Map);f(this,"whiteTexture");f(this,"font",null);f(this,"is2DActive",!1);f(this,"collisionVis");f(this,"debug");f(this,"particleSystem");this.whiteTexture=new Yn(e.device,{width:1,height:1,format:e.format,label:"white-texture"}),this.whiteTexture.upload(new Uint8Array([255,255,255,255])),this.collisionVis=null,this.debug=null,this.particleSystem=null}get device(){return this.context.device}get width(){return this.context.width}get height(){return this.context.height}renderFrame(e,r=[],n){let i=e,a=i.dlights;if(i.dlights&&i.dlights.length>0){let s=new Float32Array(i.camera.viewProjectionMatrix),c=cr(s),l={x:i.camera.position[0],y:i.camera.position[1],z:i.camera.position[2]};a=Ec(i.dlights,c,l,32)}let o={...i,dlights:a};this.frameRenderer.renderFrame(o)}uploadBspGeometry(e){for(let r of e){if(r.gpuVertexBuffer&&r.gpuIndexBuffer)continue;let n=new ka(this.device,{size:r.vertexData.byteLength,label:`bsp-surface-vb-${r.texture}`});n.write(r.vertexData);let i=new Ua(this.device,{size:r.indexData.byteLength,label:`bsp-surface-ib-${r.texture}`});i.write(r.indexData);let a=r;a.gpuVertexBuffer=n.buffer,a.gpuIndexBuffer=i.buffer}}async registerPic(e,r){if(this.picCache.has(e))return this.picCache.get(e);let n=new Yn(this.device,{width:256,height:256,format:this.context.format,label:`pic-${e}`});return n.upload(r),this.picCache.set(e,n),n}registerTexture(e,r){if(this.picCache.has(e))return this.picCache.get(e);let n=new Yn(this.device,{width:r.width,height:r.height,format:this.context.format,mipLevelCount:r.levels.length,label:`texture-${e}`});for(let i of r.levels)n.upload(i.rgba,{width:i.width,height:i.height,mipLevel:i.level});return this.picCache.set(e,n),n}begin2D(){this.frameRenderer.begin2DPass(),this.is2DActive=!0}end2D(){this.frameRenderer.end2DPass(),this.is2DActive=!1}drawPic(e,r,n,i=[1,1,1,1]){if(!this.is2DActive)throw new Error("drawPic called outside begin2D/end2D");this.pipelines.sprite.drawTexturedQuad(e,r,n.width,n.height,n,0,0,1,1,i)}drawfillRect(e,r,n,i,a){if(!this.is2DActive)throw new Error("drawfillRect called outside begin2D/end2D");this.pipelines.sprite.drawSolidRect(e,r,n,i,a)}drawString(e,r,n,i=[1,1,1,1]){if(!this.is2DActive)throw new Error("drawString called outside begin2D/end2D");if(!this.font)return;let a=wc(n),o=e,s=8,c=8;for(let l of a){let u=l.color||i;for(let d of l.text){let h=d.charCodeAt(0),m=h%16,p=Math.floor(h/16),y=m/16,g=p/16,b=(m+1)/16,_=(p+1)/16;this.pipelines.sprite.drawTexturedQuad(o,r,s,c,this.font,y,g,b,_,u),o+=s}}}drawCenterString(e,r){if(!this.is2DActive)throw new Error("drawCenterString called outside begin2D/end2D");let a=r.replace(/\^[0-9]/g,"").length*8,o=(this.width-a)/2;this.drawString(o,e,r)}setEntityHighlight(e,r){}clearEntityHighlight(e){}highlightSurface(e,r){}removeSurfaceHighlight(e){}setDebugMode(e){}setBrightness(e){}setGamma(e){}setFullbright(e){}setAmbient(e){}setLightStyle(e,r){}setUnderwaterWarp(e){}setBloom(e){}setBloomIntensity(e){}setLodBias(e){}renderInstanced(e,r){}getPerformanceReport(){return{frameTimeMs:0,gpuTimeMs:0,cpuFrameTimeMs:0,drawCalls:0,triangles:0,vertices:0,textureBinds:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0,memoryUsageMB:{textures:0,geometry:0,total:0}}}getMemoryUsage(){return{texturesBytes:0,geometryBytes:0,shadersBytes:0,buffersBytes:0,totalBytes:0}}resize(e,r){this.context.context&&!this.context.isHeadless?(this.context.width=e,this.context.height=r):(this.context.width=e,this.context.height=r)}dispose(){this.pipelines.sprite.destroy(),this.pipelines.skybox.destroy(),this.pipelines.bsp.destroy();for(let e of this.picCache.values())e.destroy();this.picCache.clear(),this.whiteTexture.destroy(),this.context.device.destroy()}destroy(){this.dispose()}};async function Ep(t,e){let r=await Tc(t,e),n=new Dc(r.device,r.format),i=new kc(r.device,r.format),a=new Uc(r.device,r.format,r.depthFormat||"depth24plus"),o={sprite:n,skybox:i,bsp:a};t?(r.width=t.width,r.height=t.height):(r.width=800,r.height=600);let s=new Lc(r,o);return new rf(r,s,o)}var wr=class{constructor(e){f(this,"buffer");f(this,"view");f(this,"offset");f(this,"messageOffsets",[]);f(this,"currentBlock",null);this.buffer=e,this.view=new DataView(e),this.offset=0,this.scan()}scan(){let e=0;for(this.messageOffsets=[];e+4<=this.buffer.byteLength;){let r=this.view.getInt32(e,!0);if(r===-1)break;if(r<0||r>2097152){console.warn(`DemoReader: Invalid block length ${r} at offset ${e} during scan`);break}if(e+4+r>this.buffer.byteLength){console.warn(`DemoReader: Incomplete block at offset ${e} during scan`);break}this.messageOffsets.push(e),e+=4+r}}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(e===-1||e<0||this.offset+4+e>this.buffer.byteLength)return null;this.offset+=4;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new En(r)}}nextBlock(){let e=this.readNextBlock();return e?(this.currentBlock=e,!0):(this.currentBlock=null,!1)}getBlock(){if(!this.currentBlock)throw new Error("No current block. Call nextBlock() first.");return this.currentBlock}readAllBlocksToBuffer(){let e=0,r=this.offset,n=[],i=this.offset;for(;i+4<=this.buffer.byteLength;){let c=this.view.getInt32(i,!0);if(c===-1||c<0||i+4+c>this.buffer.byteLength)break;n.push({offset:i+4,length:c}),e+=c,i+=4+c}let a=new Uint8Array(e),o=0,s=new Uint8Array(this.buffer);for(let c of n)a.set(s.subarray(c.offset,c.offset+c.length),o),o+=c.length;return this.offset=i,a.buffer}reset(){this.offset=0,this.currentBlock=null}seekToMessage(e){return e<0||e>=this.messageOffsets.length?!1:(this.offset=this.messageOffsets[e],this.currentBlock=null,!0)}getMessageCount(){return this.messageOffsets.length}getOffset(){return this.offset}getProgress(){let e=this.offset,r=this.buffer.byteLength;return{current:e,total:r,percent:r>0?e/r*100:0}}};function Xa(t){let e=t.length;for(;--e>=0;)t[e]=0}var E_=0,d0=1,T_=2,L_=3,P_=258,Tf=29,zs=256,Rs=zs+1+Tf,Va=30,Lf=19,f0=2*Rs+1,Ci=15,nf=16,R_=7,Pf=256,h0=16,m0=17,p0=18,bf=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Hc=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),C_=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),g0=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),B_=512,mn=new Array((Rs+2)*2);Xa(mn);var Ts=new Array(Va*2);Xa(Ts);var Cs=new Array(B_);Xa(Cs);var Bs=new Array(P_-L_+1);Xa(Bs);var Rf=new Array(Tf);Xa(Rf);var Wc=new Array(Va);Xa(Wc);function af(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}var y0,b0,x0;function of(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}var v0=t=>t<256?Cs[t]:Cs[256+(t>>>7)],Fs=(t,e)=>{t.pending_buf[t.pending++]=e&255,t.pending_buf[t.pending++]=e>>>8&255},Gt=(t,e,r)=>{t.bi_valid>nf-r?(t.bi_buf|=e<<t.bi_valid&65535,Fs(t,t.bi_buf),t.bi_buf=e>>nf-t.bi_valid,t.bi_valid+=r-nf):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=r)},Wr=(t,e,r)=>{Gt(t,r[e*2],r[e*2+1])},_0=(t,e)=>{let r=0;do r|=t&1,t>>>=1,r<<=1;while(--e>0);return r>>>1},F_=t=>{t.bi_valid===16?(Fs(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=t.bi_buf&255,t.bi_buf>>=8,t.bi_valid-=8)},I_=(t,e)=>{let r=e.dyn_tree,n=e.max_code,i=e.stat_desc.static_tree,a=e.stat_desc.has_stree,o=e.stat_desc.extra_bits,s=e.stat_desc.extra_base,c=e.stat_desc.max_length,l,u,d,h,m,p,y=0;for(h=0;h<=Ci;h++)t.bl_count[h]=0;for(r[t.heap[t.heap_max]*2+1]=0,l=t.heap_max+1;l<f0;l++)u=t.heap[l],h=r[r[u*2+1]*2+1]+1,h>c&&(h=c,y++),r[u*2+1]=h,!(u>n)&&(t.bl_count[h]++,m=0,u>=s&&(m=o[u-s]),p=r[u*2],t.opt_len+=p*(h+m),a&&(t.static_len+=p*(i[u*2+1]+m)));if(y!==0){do{for(h=c-1;t.bl_count[h]===0;)h--;t.bl_count[h]--,t.bl_count[h+1]+=2,t.bl_count[c]--,y-=2}while(y>0);for(h=c;h!==0;h--)for(u=t.bl_count[h];u!==0;)d=t.heap[--l],!(d>n)&&(r[d*2+1]!==h&&(t.opt_len+=(h-r[d*2+1])*r[d*2],r[d*2+1]=h),u--)}},S0=(t,e,r)=>{let n=new Array(Ci+1),i=0,a,o;for(a=1;a<=Ci;a++)i=i+r[a-1]<<1,n[a]=i;for(o=0;o<=e;o++){let s=t[o*2+1];s!==0&&(t[o*2]=_0(n[s]++,s))}},D_=()=>{let t,e,r,n,i,a=new Array(Ci+1);for(r=0,n=0;n<Tf-1;n++)for(Rf[n]=r,t=0;t<1<<bf[n];t++)Bs[r++]=n;for(Bs[r-1]=n,i=0,n=0;n<16;n++)for(Wc[n]=i,t=0;t<1<<Hc[n];t++)Cs[i++]=n;for(i>>=7;n<Va;n++)for(Wc[n]=i<<7,t=0;t<1<<Hc[n]-7;t++)Cs[256+i++]=n;for(e=0;e<=Ci;e++)a[e]=0;for(t=0;t<=143;)mn[t*2+1]=8,t++,a[8]++;for(;t<=255;)mn[t*2+1]=9,t++,a[9]++;for(;t<=279;)mn[t*2+1]=7,t++,a[7]++;for(;t<=287;)mn[t*2+1]=8,t++,a[8]++;for(S0(mn,Rs+1,a),t=0;t<Va;t++)Ts[t*2+1]=5,Ts[t*2]=_0(t,5);y0=new af(mn,bf,zs+1,Rs,Ci),b0=new af(Ts,Hc,0,Va,Ci),x0=new af(new Array(0),C_,0,Lf,R_)},w0=t=>{let e;for(e=0;e<Rs;e++)t.dyn_ltree[e*2]=0;for(e=0;e<Va;e++)t.dyn_dtree[e*2]=0;for(e=0;e<Lf;e++)t.bl_tree[e*2]=0;t.dyn_ltree[Pf*2]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},M0=t=>{t.bi_valid>8?Fs(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},Tp=(t,e,r,n)=>{let i=e*2,a=r*2;return t[i]<t[a]||t[i]===t[a]&&n[e]<=n[r]},sf=(t,e,r)=>{let n=t.heap[r],i=r<<1;for(;i<=t.heap_len&&(i<t.heap_len&&Tp(e,t.heap[i+1],t.heap[i],t.depth)&&i++,!Tp(e,n,t.heap[i],t.depth));)t.heap[r]=t.heap[i],r=i,i<<=1;t.heap[r]=n},Lp=(t,e,r)=>{let n,i,a=0,o,s;if(t.sym_next!==0)do n=t.pending_buf[t.sym_buf+a++]&255,n+=(t.pending_buf[t.sym_buf+a++]&255)<<8,i=t.pending_buf[t.sym_buf+a++],n===0?Wr(t,i,e):(o=Bs[i],Wr(t,o+zs+1,e),s=bf[o],s!==0&&(i-=Rf[o],Gt(t,i,s)),n--,o=v0(n),Wr(t,o,r),s=Hc[o],s!==0&&(n-=Wc[o],Gt(t,n,s)));while(a<t.sym_next);Wr(t,Pf,e)},xf=(t,e)=>{let r=e.dyn_tree,n=e.stat_desc.static_tree,i=e.stat_desc.has_stree,a=e.stat_desc.elems,o,s,c=-1,l;for(t.heap_len=0,t.heap_max=f0,o=0;o<a;o++)r[o*2]!==0?(t.heap[++t.heap_len]=c=o,t.depth[o]=0):r[o*2+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=c<2?++c:0,r[l*2]=1,t.depth[l]=0,t.opt_len--,i&&(t.static_len-=n[l*2+1]);for(e.max_code=c,o=t.heap_len>>1;o>=1;o--)sf(t,r,o);l=a;do o=t.heap[1],t.heap[1]=t.heap[t.heap_len--],sf(t,r,1),s=t.heap[1],t.heap[--t.heap_max]=o,t.heap[--t.heap_max]=s,r[l*2]=r[o*2]+r[s*2],t.depth[l]=(t.depth[o]>=t.depth[s]?t.depth[o]:t.depth[s])+1,r[o*2+1]=r[s*2+1]=l,t.heap[1]=l++,sf(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],I_(t,e),S0(r,c,t.bl_count)},Pp=(t,e,r)=>{let n,i=-1,a,o=e[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),e[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=e[(n+1)*2+1],!(++s<c&&a===o)&&(s<l?t.bl_tree[a*2]+=s:a!==0?(a!==i&&t.bl_tree[a*2]++,t.bl_tree[h0*2]++):s<=10?t.bl_tree[m0*2]++:t.bl_tree[p0*2]++,s=0,i=a,o===0?(c=138,l=3):a===o?(c=6,l=3):(c=7,l=4))},Rp=(t,e,r)=>{let n,i=-1,a,o=e[1],s=0,c=7,l=4;for(o===0&&(c=138,l=3),n=0;n<=r;n++)if(a=o,o=e[(n+1)*2+1],!(++s<c&&a===o)){if(s<l)do Wr(t,a,t.bl_tree);while(--s!==0);else a!==0?(a!==i&&(Wr(t,a,t.bl_tree),s--),Wr(t,h0,t.bl_tree),Gt(t,s-3,2)):s<=10?(Wr(t,m0,t.bl_tree),Gt(t,s-3,3)):(Wr(t,p0,t.bl_tree),Gt(t,s-11,7));s=0,i=a,o===0?(c=138,l=3):a===o?(c=6,l=3):(c=7,l=4)}},k_=t=>{let e;for(Pp(t,t.dyn_ltree,t.l_desc.max_code),Pp(t,t.dyn_dtree,t.d_desc.max_code),xf(t,t.bl_desc),e=Lf-1;e>=3&&t.bl_tree[g0[e]*2+1]===0;e--);return t.opt_len+=3*(e+1)+5+5+4,e},U_=(t,e,r,n)=>{let i;for(Gt(t,e-257,5),Gt(t,r-1,5),Gt(t,n-4,4),i=0;i<n;i++)Gt(t,t.bl_tree[g0[i]*2+1],3);Rp(t,t.dyn_ltree,e-1),Rp(t,t.dyn_dtree,r-1)},z_=t=>{let e=4093624447,r;for(r=0;r<=31;r++,e>>>=1)if(e&1&&t.dyn_ltree[r*2]!==0)return 0;if(t.dyn_ltree[18]!==0||t.dyn_ltree[20]!==0||t.dyn_ltree[26]!==0)return 1;for(r=32;r<zs;r++)if(t.dyn_ltree[r*2]!==0)return 1;return 0},Cp=!1,O_=t=>{Cp||(D_(),Cp=!0),t.l_desc=new of(t.dyn_ltree,y0),t.d_desc=new of(t.dyn_dtree,b0),t.bl_desc=new of(t.bl_tree,x0),t.bi_buf=0,t.bi_valid=0,w0(t)},A0=(t,e,r,n)=>{Gt(t,(E_<<1)+(n?1:0),3),M0(t),Fs(t,r),Fs(t,~r),r&&t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r},N_=t=>{Gt(t,d0<<1,3),Wr(t,Pf,mn),F_(t)},G_=(t,e,r,n)=>{let i,a,o=0;t.level>0?(t.strm.data_type===2&&(t.strm.data_type=z_(t)),xf(t,t.l_desc),xf(t,t.d_desc),o=k_(t),i=t.opt_len+3+7>>>3,a=t.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&e!==-1?A0(t,e,r,n):t.strategy===4||a===i?(Gt(t,(d0<<1)+(n?1:0),3),Lp(t,mn,Ts)):(Gt(t,(T_<<1)+(n?1:0),3),U_(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),Lp(t,t.dyn_ltree,t.dyn_dtree)),w0(t),n&&M0(t)},V_=(t,e,r)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=r,e===0?t.dyn_ltree[r*2]++:(t.matches++,e--,t.dyn_ltree[(Bs[r]+zs+1)*2]++,t.dyn_dtree[v0(e)*2]++),t.sym_next===t.sym_end),H_=O_,W_=A0,X_=G_,$_=V_,K_=N_,Y_={_tr_init:H_,_tr_stored_block:W_,_tr_flush_block:X_,_tr_tally:$_,_tr_align:K_},q_=(t,e,r,n)=>{let i=t&65535|0,a=t>>>16&65535|0,o=0;for(;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+e[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0},Is=q_,Z_=()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;e[r]=t}return e},j_=new Uint32Array(Z_()),Q_=(t,e,r,n)=>{let i=j_,a=n+r;t^=-1;for(let o=n;o<a;o++)t=t>>>8^i[(t^e[o])&255];return t^-1},Ve=Q_,Ii={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Ui={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:J_,_tr_stored_block:vf,_tr_flush_block:eS,_tr_tally:jn,_tr_align:tS}=Y_,{Z_NO_FLUSH:Qn,Z_PARTIAL_FLUSH:rS,Z_FULL_FLUSH:nS,Z_FINISH:fr,Z_BLOCK:Bp,Z_OK:rt,Z_STREAM_END:Fp,Z_STREAM_ERROR:Xr,Z_DATA_ERROR:iS,Z_BUF_ERROR:lf,Z_DEFAULT_COMPRESSION:aS,Z_FILTERED:oS,Z_HUFFMAN_ONLY:zc,Z_RLE:sS,Z_FIXED:lS,Z_DEFAULT_STRATEGY:cS,Z_UNKNOWN:uS,Z_DEFLATED:Kc}=Ui,dS=9,fS=15,hS=8,mS=29,pS=256,_f=pS+1+mS,gS=30,yS=19,bS=2*_f+1,xS=15,J=3,Zn=258,$r=Zn+J+1,vS=32,Ha=42,Cf=57,Sf=69,wf=73,Mf=91,Af=103,Bi=113,As=666,vt=1,$a=2,Di=3,Ka=4,_S=3,Fi=(t,e)=>(t.msg=Ii[e],e),Ip=t=>t*2-(t>4?9:0),qn=t=>{let e=t.length;for(;--e>=0;)t[e]=0},SS=t=>{let e,r,n,i=t.w_size;e=t.hash_size,n=e;do r=t.head[--n],t.head[n]=r>=i?r-i:0;while(--e);e=i,n=e;do r=t.prev[--n],t.prev[n]=r>=i?r-i:0;while(--e)},wS=(t,e,r)=>(e<<t.hash_shift^r)&t.hash_mask,Jn=wS,qt=t=>{let e=t.state,r=e.pending;r>t.avail_out&&(r=t.avail_out),r!==0&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,e.pending===0&&(e.pending_out=0))},Zt=(t,e)=>{eS(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,qt(t.strm)},se=(t,e)=>{t.pending_buf[t.pending++]=e},Ms=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=e&255},Ef=(t,e,r,n)=>{let i=t.avail_in;return i>n&&(i=n),i===0?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),t.state.wrap===1?t.adler=Is(t.adler,e,i,r):t.state.wrap===2&&(t.adler=Ve(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},E0=(t,e)=>{let r=t.max_chain_length,n=t.strstart,i,a,o=t.prev_length,s=t.nice_match,c=t.strstart>t.w_size-$r?t.strstart-(t.w_size-$r):0,l=t.window,u=t.w_mask,d=t.prev,h=t.strstart+Zn,m=l[n+o-1],p=l[n+o];t.prev_length>=t.good_match&&(r>>=2),s>t.lookahead&&(s=t.lookahead);do if(i=e,!(l[i+o]!==p||l[i+o-1]!==m||l[i]!==l[n]||l[++i]!==l[n+1])){n+=2,i++;do;while(l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&n<h);if(a=Zn-(h-n),n=h-Zn,a>o){if(t.match_start=e,o=a,a>=s)break;m=l[n+o-1],p=l[n+o]}}while((e=d[e&u])>c&&--r!==0);return o<=t.lookahead?o:t.lookahead},Wa=t=>{let e=t.w_size,r,n,i;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-$r)&&(t.window.set(t.window.subarray(e,e+e-n),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),SS(t),n+=e),t.strm.avail_in===0)break;if(r=Ef(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=r,t.lookahead+t.insert>=J)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=Jn(t,t.ins_h,t.window[i+1]);t.insert&&(t.ins_h=Jn(t,t.ins_h,t.window[i+J-1]),t.prev[i&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=i,i++,t.insert--,!(t.lookahead+t.insert<J)););}while(t.lookahead<$r&&t.strm.avail_in!==0)},T0=(t,e)=>{let r=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,n,i,a,o=0,s=t.strm.avail_in;do{if(n=65535,a=t.bi_valid+42>>3,t.strm.avail_out<a||(a=t.strm.avail_out-a,i=t.strstart-t.block_start,n>i+t.strm.avail_in&&(n=i+t.strm.avail_in),n>a&&(n=a),n<r&&(n===0&&e!==fr||e===Qn||n!==i+t.strm.avail_in)))break;o=e===fr&&n===i+t.strm.avail_in?1:0,vf(t,0,0,o),t.pending_buf[t.pending-4]=n,t.pending_buf[t.pending-3]=n>>8,t.pending_buf[t.pending-2]=~n,t.pending_buf[t.pending-1]=~n>>8,qt(t.strm),i&&(i>n&&(i=n),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,n-=i),n&&(Ef(t.strm,t.strm.output,t.strm.next_out,n),t.strm.next_out+=n,t.strm.avail_out-=n,t.strm.total_out+=n)}while(o===0);return s-=t.strm.avail_in,s&&(s>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=s&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-s,t.strm.next_in),t.strstart),t.strstart+=s,t.insert+=s>t.w_size-t.insert?t.w_size-t.insert:s),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),o?Ka:e!==Qn&&e!==fr&&t.strm.avail_in===0&&t.strstart===t.block_start?$a:(a=t.window_size-t.strstart,t.strm.avail_in>a&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,a+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),a>t.strm.avail_in&&(a=t.strm.avail_in),a&&(Ef(t.strm,t.window,t.strstart,a),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.high_water<t.strstart&&(t.high_water=t.strstart),a=t.bi_valid+42>>3,a=t.pending_buf_size-a>65535?65535:t.pending_buf_size-a,r=a>t.w_size?t.w_size:a,i=t.strstart-t.block_start,(i>=r||(i||e===fr)&&e!==Qn&&t.strm.avail_in===0&&i<=a)&&(n=i>a?a:i,o=e===fr&&t.strm.avail_in===0&&n===i?1:0,vf(t,t.block_start,n,o),t.block_start+=n,qt(t.strm)),o?Di:vt)},cf=(t,e)=>{let r,n;for(;;){if(t.lookahead<$r){if(Wa(t),t.lookahead<$r&&e===Qn)return vt;if(t.lookahead===0)break}if(r=0,t.lookahead>=J&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),r!==0&&t.strstart-r<=t.w_size-$r&&(t.match_length=E0(t,r)),t.match_length>=J)if(n=jn(t,t.strstart-t.match_start,t.match_length-J),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=J){t.match_length--;do t.strstart++,t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart;while(--t.match_length!==0);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+1]);else n=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=t.strstart<J-1?t.strstart:J-1,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},Na=(t,e)=>{let r,n,i;for(;;){if(t.lookahead<$r){if(Wa(t),t.lookahead<$r&&e===Qn)return vt;if(t.lookahead===0)break}if(r=0,t.lookahead>=J&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=J-1,r!==0&&t.prev_length<t.max_lazy_match&&t.strstart-r<=t.w_size-$r&&(t.match_length=E0(t,r),t.match_length<=5&&(t.strategy===oS||t.match_length===J&&t.strstart-t.match_start>4096)&&(t.match_length=J-1)),t.prev_length>=J&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-J,n=jn(t,t.strstart-1-t.prev_match,t.prev_length-J),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=i&&(t.ins_h=Jn(t,t.ins_h,t.window[t.strstart+J-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart);while(--t.prev_length!==0);if(t.match_available=0,t.match_length=J-1,t.strstart++,n&&(Zt(t,!1),t.strm.avail_out===0))return vt}else if(t.match_available){if(n=jn(t,0,t.window[t.strstart-1]),n&&Zt(t,!1),t.strstart++,t.lookahead--,t.strm.avail_out===0)return vt}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=jn(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<J-1?t.strstart:J-1,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},MS=(t,e)=>{let r,n,i,a,o=t.window;for(;;){if(t.lookahead<=Zn){if(Wa(t),t.lookahead<=Zn&&e===Qn)return vt;if(t.lookahead===0)break}if(t.match_length=0,t.lookahead>=J&&t.strstart>0&&(i=t.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=t.strstart+Zn;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);t.match_length=Zn-(a-i),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=J?(r=jn(t,1,t.match_length-J),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=0,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a},AS=(t,e)=>{let r;for(;;){if(t.lookahead===0&&(Wa(t),t.lookahead===0)){if(e===Qn)return vt;break}if(t.match_length=0,r=jn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(Zt(t,!1),t.strm.avail_out===0))return vt}return t.insert=0,e===fr?(Zt(t,!0),t.strm.avail_out===0?Di:Ka):t.sym_next&&(Zt(t,!1),t.strm.avail_out===0)?vt:$a};function Hr(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Es=[new Hr(0,0,0,0,T0),new Hr(4,4,8,4,cf),new Hr(4,5,16,8,cf),new Hr(4,6,32,32,cf),new Hr(4,4,16,16,Na),new Hr(8,16,32,32,Na),new Hr(8,16,128,128,Na),new Hr(8,32,128,256,Na),new Hr(32,128,258,1024,Na),new Hr(32,258,258,4096,Na)],ES=t=>{t.window_size=2*t.w_size,qn(t.head),t.max_lazy_match=Es[t.level].max_lazy,t.good_match=Es[t.level].good_length,t.nice_match=Es[t.level].nice_length,t.max_chain_length=Es[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=J-1,t.match_available=0,t.ins_h=0};function TS(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Kc,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(bS*2),this.dyn_dtree=new Uint16Array((2*gS+1)*2),this.bl_tree=new Uint16Array((2*yS+1)*2),qn(this.dyn_ltree),qn(this.dyn_dtree),qn(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(xS+1),this.heap=new Uint16Array(2*_f+1),qn(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*_f+1),qn(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Os=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.status!==Ha&&e.status!==Cf&&e.status!==Sf&&e.status!==wf&&e.status!==Mf&&e.status!==Af&&e.status!==Bi&&e.status!==As?1:0},L0=t=>{if(Os(t))return Fi(t,Xr);t.total_in=t.total_out=0,t.data_type=uS;let e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap===2?Cf:e.wrap?Ha:Bi,t.adler=e.wrap===2?0:1,e.last_flush=-2,J_(e),rt},P0=t=>{let e=L0(t);return e===rt&&ES(t.state),e},LS=(t,e)=>Os(t)||t.state.wrap!==2?Xr:(t.state.gzhead=e,rt),R0=(t,e,r,n,i,a)=>{if(!t)return Xr;let o=1;if(e===aS&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>dS||r!==Kc||n<8||n>15||e<0||e>9||a<0||a>lS||n===8&&o!==1)return Fi(t,Xr);n===8&&(n=9);let s=new TS;return t.state=s,s.strm=t,s.status=Ha,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+J-1)/J),s.window=new Uint8Array(s.w_size*2),s.head=new Uint16Array(s.hash_size),s.prev=new Uint16Array(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new Uint8Array(s.pending_buf_size),s.sym_buf=s.lit_bufsize,s.sym_end=(s.lit_bufsize-1)*3,s.level=e,s.strategy=a,s.method=r,P0(t)},PS=(t,e)=>R0(t,e,Kc,fS,hS,cS),RS=(t,e)=>{if(Os(t)||e>Bp||e<0)return t?Fi(t,Xr):Xr;let r=t.state;if(!t.output||t.avail_in!==0&&!t.input||r.status===As&&e!==fr)return Fi(t,t.avail_out===0?lf:Xr);let n=r.last_flush;if(r.last_flush=e,r.pending!==0){if(qt(t),t.avail_out===0)return r.last_flush=-1,rt}else if(t.avail_in===0&&Ip(e)<=Ip(n)&&e!==fr)return Fi(t,lf);if(r.status===As&&t.avail_in!==0)return Fi(t,lf);if(r.status===Ha&&r.wrap===0&&(r.status=Bi),r.status===Ha){let i=Kc+(r.w_bits-8<<4)<<8,a=-1;if(r.strategy>=zc||r.level<2?a=0:r.level<6?a=1:r.level===6?a=2:a=3,i|=a<<6,r.strstart!==0&&(i|=vS),i+=31-i%31,Ms(r,i),r.strstart!==0&&(Ms(r,t.adler>>>16),Ms(r,t.adler&65535)),t.adler=1,r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(r.status===Cf){if(t.adler=0,se(r,31),se(r,139),se(r,8),r.gzhead)se(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),se(r,r.gzhead.time&255),se(r,r.gzhead.time>>8&255),se(r,r.gzhead.time>>16&255),se(r,r.gzhead.time>>24&255),se(r,r.level===9?2:r.strategy>=zc||r.level<2?4:0),se(r,r.gzhead.os&255),r.gzhead.extra&&r.gzhead.extra.length&&(se(r,r.gzhead.extra.length&255),se(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=Ve(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=Sf;else if(se(r,0),se(r,0),se(r,0),se(r,0),se(r,0),se(r,r.level===9?2:r.strategy>=zc||r.level<2?4:0),se(r,_S),r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(r.status===Sf){if(r.gzhead.extra){let i=r.pending,a=(r.gzhead.extra.length&65535)-r.gzindex;for(;r.pending+a>r.pending_buf_size;){let s=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+s),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex+=s,qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0,a-=s}let o=new Uint8Array(r.gzhead.extra);r.pending_buf.set(o.subarray(r.gzindex,r.gzindex+a),r.pending),r.pending+=a,r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=wf}if(r.status===wf){if(r.gzhead.name){let i=r.pending,a;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0}r.gzindex<r.gzhead.name.length?a=r.gzhead.name.charCodeAt(r.gzindex++)&255:a=0,se(r,a)}while(a!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Mf}if(r.status===Mf){if(r.gzhead.comment){let i=r.pending,a;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i)),qt(t),r.pending!==0)return r.last_flush=-1,rt;i=0}r.gzindex<r.gzhead.comment.length?a=r.gzhead.comment.charCodeAt(r.gzindex++)&255:a=0,se(r,a)}while(a!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=Ve(t.adler,r.pending_buf,r.pending-i,i))}r.status=Af}if(r.status===Af){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&(qt(t),r.pending!==0))return r.last_flush=-1,rt;se(r,t.adler&255),se(r,t.adler>>8&255),t.adler=0}if(r.status=Bi,qt(t),r.pending!==0)return r.last_flush=-1,rt}if(t.avail_in!==0||r.lookahead!==0||e!==Qn&&r.status!==As){let i=r.level===0?T0(r,e):r.strategy===zc?AS(r,e):r.strategy===sS?MS(r,e):Es[r.level].func(r,e);if((i===Di||i===Ka)&&(r.status=As),i===vt||i===Di)return t.avail_out===0&&(r.last_flush=-1),rt;if(i===$a&&(e===rS?tS(r):e!==Bp&&(vf(r,0,0,!1),e===nS&&(qn(r.head),r.lookahead===0&&(r.strstart=0,r.block_start=0,r.insert=0))),qt(t),t.avail_out===0))return r.last_flush=-1,rt}return e!==fr?rt:r.wrap<=0?Fp:(r.wrap===2?(se(r,t.adler&255),se(r,t.adler>>8&255),se(r,t.adler>>16&255),se(r,t.adler>>24&255),se(r,t.total_in&255),se(r,t.total_in>>8&255),se(r,t.total_in>>16&255),se(r,t.total_in>>24&255)):(Ms(r,t.adler>>>16),Ms(r,t.adler&65535)),qt(t),r.wrap>0&&(r.wrap=-r.wrap),r.pending!==0?rt:Fp)},CS=t=>{if(Os(t))return Xr;let e=t.state.status;return t.state=null,e===Bi?Fi(t,iS):rt},BS=(t,e)=>{let r=e.length;if(Os(t))return Xr;let n=t.state,i=n.wrap;if(i===2||i===1&&n.status!==Ha||n.lookahead)return Xr;if(i===1&&(t.adler=Is(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){i===0&&(qn(n.head),n.strstart=0,n.block_start=0,n.insert=0);let c=new Uint8Array(n.w_size);c.set(e.subarray(r-n.w_size,r),0),e=c,r=n.w_size}let a=t.avail_in,o=t.next_in,s=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,Wa(n);n.lookahead>=J;){let c=n.strstart,l=n.lookahead-(J-1);do n.ins_h=Jn(n,n.ins_h,n.window[c+J-1]),n.prev[c&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=c,c++;while(--l);n.strstart=c,n.lookahead=J-1,Wa(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=J-1,n.match_available=0,t.next_in=o,t.input=s,t.avail_in=a,n.wrap=i,rt},FS=PS,IS=R0,DS=P0,kS=L0,US=LS,zS=RS,OS=CS,NS=BS,GS="pako deflate (from Nodeca project)",Ls={deflateInit:FS,deflateInit2:IS,deflateReset:DS,deflateResetKeep:kS,deflateSetHeader:US,deflate:zS,deflateEnd:OS,deflateSetDictionary:NS,deflateInfo:GS},VS=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),HS=function(t){let e=Array.prototype.slice.call(arguments,1);for(;e.length;){let r=e.shift();if(r){if(typeof r!="object")throw new TypeError(r+"must be non-object");for(let n in r)VS(r,n)&&(t[n]=r[n])}}return t},WS=t=>{let e=0;for(let n=0,i=t.length;n<i;n++)e+=t[n].length;let r=new Uint8Array(e);for(let n=0,i=0,a=t.length;n<a;n++){let o=t[n];r.set(o,i),i+=o.length}return r},Yc={assign:HS,flattenChunks:WS},C0=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{C0=!1}var Ds=new Uint8Array(256);for(let t=0;t<256;t++)Ds[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ds[254]=Ds[254]=1;var XS=t=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(t);let e,r,n,i,a,o=t.length,s=0;for(i=0;i<o;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),s+=r<128?1:r<2048?2:r<65536?3:4;for(e=new Uint8Array(s),a=0,i=0;a<s;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),r<128?e[a++]=r:r<2048?(e[a++]=192|r>>>6,e[a++]=128|r&63):r<65536?(e[a++]=224|r>>>12,e[a++]=128|r>>>6&63,e[a++]=128|r&63):(e[a++]=240|r>>>18,e[a++]=128|r>>>12&63,e[a++]=128|r>>>6&63,e[a++]=128|r&63);return e},$S=(t,e)=>{if(e<65534&&t.subarray&&C0)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let n=0;n<e;n++)r+=String.fromCharCode(t[n]);return r},KS=(t,e)=>{let r=e||t.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(t.subarray(0,e));let n,i,a=new Array(r*2);for(i=0,n=0;n<r;){let o=t[n++];if(o<128){a[i++]=o;continue}let s=Ds[o];if(s>4){a[i++]=65533,n+=s-1;continue}for(o&=s===2?31:s===3?15:7;s>1&&n<r;)o=o<<6|t[n++]&63,s--;if(s>1){a[i++]=65533;continue}o<65536?a[i++]=o:(o-=65536,a[i++]=55296|o>>10&1023,a[i++]=56320|o&1023)}return $S(a,i)},YS=(t,e)=>{e=e||t.length,e>t.length&&(e=t.length);let r=e-1;for(;r>=0&&(t[r]&192)===128;)r--;return r<0||r===0?e:r+Ds[t[r]]>e?r:e},ks={string2buf:XS,buf2string:KS,utf8border:YS};function qS(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var B0=qS,F0=Object.prototype.toString,{Z_NO_FLUSH:ZS,Z_SYNC_FLUSH:jS,Z_FULL_FLUSH:QS,Z_FINISH:JS,Z_OK:Xc,Z_STREAM_END:ew,Z_DEFAULT_COMPRESSION:tw,Z_DEFAULT_STRATEGY:rw,Z_DEFLATED:nw}=Ui;function Ns(t){this.options=Yc.assign({level:tw,method:nw,chunkSize:16384,windowBits:15,memLevel:8,strategy:rw},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new B0,this.strm.avail_out=0;let r=Ls.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Xc)throw new Error(Ii[r]);if(e.header&&Ls.deflateSetHeader(this.strm,e.header),e.dictionary){let n;if(typeof e.dictionary=="string"?n=ks.string2buf(e.dictionary):F0.call(e.dictionary)==="[object ArrayBuffer]"?n=new Uint8Array(e.dictionary):n=e.dictionary,r=Ls.deflateSetDictionary(this.strm,n),r!==Xc)throw new Error(Ii[r]);this._dict_set=!0}}Ns.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i,a;if(this.ended)return!1;for(e===~~e?a=e:a=e===!0?JS:ZS,typeof t=="string"?r.input=ks.string2buf(t):F0.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){if(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(a===jS||a===QS)&&r.avail_out<=6){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(i=Ls.deflate(r,a),i===ew)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=Ls.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===Xc;if(r.avail_out===0){this.onData(r.output);continue}if(a>0&&r.next_out>0){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(r.avail_in===0)break}return!0};Ns.prototype.onData=function(t){this.chunks.push(t)};Ns.prototype.onEnd=function(t){t===Xc&&(this.result=Yc.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Bf(t,e){let r=new Ns(e);if(r.push(t,!0),r.err)throw r.msg||Ii[r.err];return r.result}function iw(t,e){return e=e||{},e.raw=!0,Bf(t,e)}function aw(t,e){return e=e||{},e.gzip=!0,Bf(t,e)}var ow=Ns,sw=Bf,lw=iw,cw=aw,uw=Ui,dw={Deflate:ow,deflate:sw,deflateRaw:lw,gzip:cw,constants:uw},Oc=16209,fw=16191,hw=function(e,r){let n,i,a,o,s,c,l,u,d,h,m,p,y,g,b,_,x,v,w,M,S,E,L,A,R=e.state;n=e.next_in,L=e.input,i=n+(e.avail_in-5),a=e.next_out,A=e.output,o=a-(r-e.avail_out),s=a+(e.avail_out-257),c=R.dmax,l=R.wsize,u=R.whave,d=R.wnext,h=R.window,m=R.hold,p=R.bits,y=R.lencode,g=R.distcode,b=(1<<R.lenbits)-1,_=(1<<R.distbits)-1;e:do{p<15&&(m+=L[n++]<<p,p+=8,m+=L[n++]<<p,p+=8),x=y[m&b];t:for(;;){if(v=x>>>24,m>>>=v,p-=v,v=x>>>16&255,v===0)A[a++]=x&65535;else if(v&16){w=x&65535,v&=15,v&&(p<v&&(m+=L[n++]<<p,p+=8),w+=m&(1<<v)-1,m>>>=v,p-=v),p<15&&(m+=L[n++]<<p,p+=8,m+=L[n++]<<p,p+=8),x=g[m&_];r:for(;;){if(v=x>>>24,m>>>=v,p-=v,v=x>>>16&255,v&16){if(M=x&65535,v&=15,p<v&&(m+=L[n++]<<p,p+=8,p<v&&(m+=L[n++]<<p,p+=8)),M+=m&(1<<v)-1,M>c){e.msg="invalid distance too far back",R.mode=Oc;break e}if(m>>>=v,p-=v,v=a-o,M>v){if(v=M-v,v>u&&R.sane){e.msg="invalid distance too far back",R.mode=Oc;break e}if(S=0,E=h,d===0){if(S+=l-v,v<w){w-=v;do A[a++]=h[S++];while(--v);S=a-M,E=A}}else if(d<v){if(S+=l+d-v,v-=d,v<w){w-=v;do A[a++]=h[S++];while(--v);if(S=0,d<w){v=d,w-=v;do A[a++]=h[S++];while(--v);S=a-M,E=A}}}else if(S+=d-v,v<w){w-=v;do A[a++]=h[S++];while(--v);S=a-M,E=A}for(;w>2;)A[a++]=E[S++],A[a++]=E[S++],A[a++]=E[S++],w-=3;w&&(A[a++]=E[S++],w>1&&(A[a++]=E[S++]))}else{S=a-M;do A[a++]=A[S++],A[a++]=A[S++],A[a++]=A[S++],w-=3;while(w>2);w&&(A[a++]=A[S++],w>1&&(A[a++]=A[S++]))}}else if((v&64)===0){x=g[(x&65535)+(m&(1<<v)-1)];continue r}else{e.msg="invalid distance code",R.mode=Oc;break e}break}}else if((v&64)===0){x=y[(x&65535)+(m&(1<<v)-1)];continue t}else if(v&32){R.mode=fw;break e}else{e.msg="invalid literal/length code",R.mode=Oc;break e}break}}while(n<i&&a<s);w=p>>3,n-=w,p-=w<<3,m&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),R.hold=m,R.bits=p},Ga=15,Dp=852,kp=592,Up=0,uf=1,zp=2,mw=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),pw=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),gw=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),yw=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),bw=(t,e,r,n,i,a,o,s)=>{let c=s.bits,l=0,u=0,d=0,h=0,m=0,p=0,y=0,g=0,b=0,_=0,x,v,w,M,S,E=null,L,A=new Uint16Array(Ga+1),R=new Uint16Array(Ga+1),D=null,k,F,U;for(l=0;l<=Ga;l++)A[l]=0;for(u=0;u<n;u++)A[e[r+u]]++;for(m=c,h=Ga;h>=1&&A[h]===0;h--);if(m>h&&(m=h),h===0)return i[a++]=1<<24|64<<16|0,i[a++]=1<<24|64<<16|0,s.bits=1,0;for(d=1;d<h&&A[d]===0;d++);for(m<d&&(m=d),g=1,l=1;l<=Ga;l++)if(g<<=1,g-=A[l],g<0)return-1;if(g>0&&(t===Up||h!==1))return-1;for(R[1]=0,l=1;l<Ga;l++)R[l+1]=R[l]+A[l];for(u=0;u<n;u++)e[r+u]!==0&&(o[R[e[r+u]]++]=u);if(t===Up?(E=D=o,L=20):t===uf?(E=mw,D=pw,L=257):(E=gw,D=yw,L=0),_=0,u=0,l=d,S=a,p=m,y=0,w=-1,b=1<<m,M=b-1,t===uf&&b>Dp||t===zp&&b>kp)return 1;for(;;){k=l-y,o[u]+1<L?(F=0,U=o[u]):o[u]>=L?(F=D[o[u]-L],U=E[o[u]-L]):(F=96,U=0),x=1<<l-y,v=1<<p,d=v;do v-=x,i[S+(_>>y)+v]=k<<24|F<<16|U|0;while(v!==0);for(x=1<<l-1;_&x;)x>>=1;if(x!==0?(_&=x-1,_+=x):_=0,u++,--A[l]===0){if(l===h)break;l=e[r+o[u]]}if(l>m&&(_&M)!==w){for(y===0&&(y=m),S+=d,p=l-y,g=1<<p;p+y<h&&(g-=A[p+y],!(g<=0));)p++,g<<=1;if(b+=1<<p,t===uf&&b>Dp||t===zp&&b>kp)return 1;w=_&M,i[w]=m<<24|p<<16|S-a|0}}return _!==0&&(i[S+_]=l-y<<24|64<<16|0),s.bits=m,0},Ps=bw,xw=0,I0=1,D0=2,{Z_FINISH:Op,Z_BLOCK:vw,Z_TREES:Nc,Z_OK:ki,Z_STREAM_END:_w,Z_NEED_DICT:Sw,Z_STREAM_ERROR:hr,Z_DATA_ERROR:k0,Z_MEM_ERROR:U0,Z_BUF_ERROR:ww,Z_DEFLATED:Np}=Ui,qc=16180,Gp=16181,Vp=16182,Hp=16183,Wp=16184,Xp=16185,$p=16186,Kp=16187,Yp=16188,qp=16189,$c=16190,hn=16191,df=16192,Zp=16193,ff=16194,jp=16195,Qp=16196,Jp=16197,e0=16198,Gc=16199,Vc=16200,t0=16201,r0=16202,n0=16203,i0=16204,a0=16205,hf=16206,o0=16207,s0=16208,Me=16209,z0=16210,O0=16211,Mw=852,Aw=592,Ew=15,Tw=Ew,l0=t=>(t>>>24&255)+(t>>>8&65280)+((t&65280)<<8)+((t&255)<<24);function Lw(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var zi=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.mode<qc||e.mode>O0?1:0},N0=t=>{if(zi(t))return hr;let e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=e.wrap&1),e.mode=qc,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Mw),e.distcode=e.distdyn=new Int32Array(Aw),e.sane=1,e.back=-1,ki},G0=t=>{if(zi(t))return hr;let e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,N0(t)},V0=(t,e)=>{let r;if(zi(t))return hr;let n=t.state;return e<0?(r=0,e=-e):(r=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?hr:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,G0(t))},H0=(t,e)=>{if(!t)return hr;let r=new Lw;t.state=r,r.strm=t,r.window=null,r.mode=qc;let n=V0(t,e);return n!==ki&&(t.state=null),n},Pw=t=>H0(t,Tw),c0=!0,mf,pf,Rw=t=>{if(c0){mf=new Int32Array(512),pf=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Ps(I0,t.lens,0,288,mf,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Ps(D0,t.lens,0,32,pf,0,t.work,{bits:5}),c0=!1}t.lencode=mf,t.lenbits=9,t.distcode=pf,t.distbits=5},W0=(t,e,r,n)=>{let i,a=t.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),n>=a.wsize?(a.window.set(e.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),a.window.set(e.subarray(r-n,r-n+i),a.wnext),n-=i,n?(a.window.set(e.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0},Cw=(t,e)=>{let r,n,i,a,o,s,c,l,u,d,h,m,p,y,g=0,b,_,x,v,w,M,S,E,L=new Uint8Array(4),A,R,D=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(zi(t)||!t.output||!t.input&&t.avail_in!==0)return hr;r=t.state,r.mode===hn&&(r.mode=df),o=t.next_out,i=t.output,c=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,l=r.hold,u=r.bits,d=s,h=c,E=ki;e:for(;;)switch(r.mode){case qc:if(r.wrap===0){r.mode=df;break}for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&2&&l===35615){r.wbits===0&&(r.wbits=15),r.check=0,L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0),l=0,u=0,r.mode=Gp;break}if(r.head&&(r.head.done=!1),!(r.wrap&1)||(((l&255)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=Me;break}if((l&15)!==Np){t.msg="unknown compression method",r.mode=Me;break}if(l>>>=4,u-=4,S=(l&15)+8,r.wbits===0&&(r.wbits=S),S>15||S>r.wbits){t.msg="invalid window size",r.mode=Me;break}r.dmax=1<<r.wbits,r.flags=0,t.adler=r.check=1,r.mode=l&512?qp:hn,l=0,u=0;break;case Gp:for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.flags=l,(r.flags&255)!==Np){t.msg="unknown compression method",r.mode=Me;break}if(r.flags&57344){t.msg="unknown header flags set",r.mode=Me;break}r.head&&(r.head.text=l>>8&1),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0,r.mode=Vp;case Vp:for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.time=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,L[2]=l>>>16&255,L[3]=l>>>24&255,r.check=Ve(r.check,L,4,0)),l=0,u=0,r.mode=Hp;case Hp:for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.xflags=l&255,r.head.os=l>>8),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0,r.mode=Wp;case Wp:if(r.flags&1024){for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.length=l,r.head&&(r.head.extra_len=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=Ve(r.check,L,2,0)),l=0,u=0}else r.head&&(r.head.extra=null);r.mode=Xp;case Xp:if(r.flags&1024&&(m=r.length,m>s&&(m=s),m&&(r.head&&(S=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+m),S)),r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,r.length-=m),r.length))break e;r.length=0,r.mode=$p;case $p:if(r.flags&2048){if(s===0)break e;m=0;do S=n[a+m++],r.head&&S&&r.length<65536&&(r.head.name+=String.fromCharCode(S));while(S&&m<s);if(r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,S)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Kp;case Kp:if(r.flags&4096){if(s===0)break e;m=0;do S=n[a+m++],r.head&&S&&r.length<65536&&(r.head.comment+=String.fromCharCode(S));while(S&&m<s);if(r.flags&512&&r.wrap&4&&(r.check=Ve(r.check,n,m,a)),s-=m,a+=m,S)break e}else r.head&&(r.head.comment=null);r.mode=Yp;case Yp:if(r.flags&512){for(;u<16;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&4&&l!==(r.check&65535)){t.msg="header crc mismatch",r.mode=Me;break}l=0,u=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=hn;break;case qp:for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}t.adler=r.check=l0(l),l=0,u=0,r.mode=$c;case $c:if(r.havedict===0)return t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,Sw;t.adler=r.check=1,r.mode=hn;case hn:if(e===vw||e===Nc)break e;case df:if(r.last){l>>>=u&7,u-=u&7,r.mode=hf;break}for(;u<3;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}switch(r.last=l&1,l>>>=1,u-=1,l&3){case 0:r.mode=Zp;break;case 1:if(Rw(r),r.mode=Gc,e===Nc){l>>>=2,u-=2;break e}break;case 2:r.mode=Qp;break;case 3:t.msg="invalid block type",r.mode=Me}l>>>=2,u-=2;break;case Zp:for(l>>>=u&7,u-=u&7;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if((l&65535)!==(l>>>16^65535)){t.msg="invalid stored block lengths",r.mode=Me;break}if(r.length=l&65535,l=0,u=0,r.mode=ff,e===Nc)break e;case ff:r.mode=jp;case jp:if(m=r.length,m){if(m>s&&(m=s),m>c&&(m=c),m===0)break e;i.set(n.subarray(a,a+m),o),s-=m,a+=m,c-=m,o+=m,r.length-=m;break}r.mode=hn;break;case Qp:for(;u<14;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.nlen=(l&31)+257,l>>>=5,u-=5,r.ndist=(l&31)+1,l>>>=5,u-=5,r.ncode=(l&15)+4,l>>>=4,u-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=Me;break}r.have=0,r.mode=Jp;case Jp:for(;r.have<r.ncode;){for(;u<3;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.lens[D[r.have++]]=l&7,l>>>=3,u-=3}for(;r.have<19;)r.lens[D[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},E=Ps(xw,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,E){t.msg="invalid code lengths set",r.mode=Me;break}r.have=0,r.mode=e0;case e0:for(;r.have<r.nlen+r.ndist;){for(;g=r.lencode[l&(1<<r.lenbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(x<16)l>>>=b,u-=b,r.lens[r.have++]=x;else{if(x===16){for(R=b+2;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(l>>>=b,u-=b,r.have===0){t.msg="invalid bit length repeat",r.mode=Me;break}S=r.lens[r.have-1],m=3+(l&3),l>>>=2,u-=2}else if(x===17){for(R=b+3;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=b,u-=b,S=0,m=3+(l&7),l>>>=3,u-=3}else{for(R=b+7;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=b,u-=b,S=0,m=11+(l&127),l>>>=7,u-=7}if(r.have+m>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=Me;break}for(;m--;)r.lens[r.have++]=S}}if(r.mode===Me)break;if(r.lens[256]===0){t.msg="invalid code -- missing end-of-block",r.mode=Me;break}if(r.lenbits=9,A={bits:r.lenbits},E=Ps(I0,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,E){t.msg="invalid literal/lengths set",r.mode=Me;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},E=Ps(D0,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,E){t.msg="invalid distances set",r.mode=Me;break}if(r.mode=Gc,e===Nc)break e;case Gc:r.mode=Vc;case Vc:if(s>=6&&c>=258){t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,hw(t,h),o=t.next_out,i=t.output,c=t.avail_out,a=t.next_in,n=t.input,s=t.avail_in,l=r.hold,u=r.bits,r.mode===hn&&(r.back=-1);break}for(r.back=0;g=r.lencode[l&(1<<r.lenbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(_&&(_&240)===0){for(v=b,w=_,M=x;g=r.lencode[M+((l&(1<<v+w)-1)>>v)],b=g>>>24,_=g>>>16&255,x=g&65535,!(v+b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=v,u-=v,r.back+=v}if(l>>>=b,u-=b,r.back+=b,r.length=x,_===0){r.mode=a0;break}if(_&32){r.back=-1,r.mode=hn;break}if(_&64){t.msg="invalid literal/length code",r.mode=Me;break}r.extra=_&15,r.mode=t0;case t0:if(r.extra){for(R=r.extra;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=r0;case r0:for(;g=r.distcode[l&(1<<r.distbits)-1],b=g>>>24,_=g>>>16&255,x=g&65535,!(b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if((_&240)===0){for(v=b,w=_,M=x;g=r.distcode[M+((l&(1<<v+w)-1)>>v)],b=g>>>24,_=g>>>16&255,x=g&65535,!(v+b<=u);){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}l>>>=v,u-=v,r.back+=v}if(l>>>=b,u-=b,r.back+=b,_&64){t.msg="invalid distance code",r.mode=Me;break}r.offset=x,r.extra=_&15,r.mode=n0;case n0:if(r.extra){for(R=r.extra;u<R;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=Me;break}r.mode=i0;case i0:if(c===0)break e;if(m=h-c,r.offset>m){if(m=r.offset-m,m>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=Me;break}m>r.wnext?(m-=r.wnext,p=r.wsize-m):p=r.wnext-m,m>r.length&&(m=r.length),y=r.window}else y=i,p=o-r.offset,m=r.length;m>c&&(m=c),c-=m,r.length-=m;do i[o++]=y[p++];while(--m);r.length===0&&(r.mode=Vc);break;case a0:if(c===0)break e;i[o++]=r.length,c--,r.mode=Vc;break;case hf:if(r.wrap){for(;u<32;){if(s===0)break e;s--,l|=n[a++]<<u,u+=8}if(h-=c,t.total_out+=h,r.total+=h,r.wrap&4&&h&&(t.adler=r.check=r.flags?Ve(r.check,i,h,o-h):Is(r.check,i,h,o-h)),h=c,r.wrap&4&&(r.flags?l:l0(l))!==r.check){t.msg="incorrect data check",r.mode=Me;break}l=0,u=0}r.mode=o0;case o0:if(r.wrap&&r.flags){for(;u<32;){if(s===0)break e;s--,l+=n[a++]<<u,u+=8}if(r.wrap&4&&l!==(r.total&4294967295)){t.msg="incorrect length check",r.mode=Me;break}l=0,u=0}r.mode=s0;case s0:E=_w;break e;case Me:E=k0;break e;case z0:return U0;case O0:default:return hr}return t.next_out=o,t.avail_out=c,t.next_in=a,t.avail_in=s,r.hold=l,r.bits=u,(r.wsize||h!==t.avail_out&&r.mode<Me&&(r.mode<hf||e!==Op))&&W0(t,t.output,t.next_out,h-t.avail_out),d-=t.avail_in,h-=t.avail_out,t.total_in+=d,t.total_out+=h,r.total+=h,r.wrap&4&&h&&(t.adler=r.check=r.flags?Ve(r.check,i,h,t.next_out-h):Is(r.check,i,h,t.next_out-h)),t.data_type=r.bits+(r.last?64:0)+(r.mode===hn?128:0)+(r.mode===Gc||r.mode===ff?256:0),(d===0&&h===0||e===Op)&&E===ki&&(E=ww),E},Bw=t=>{if(zi(t))return hr;let e=t.state;return e.window&&(e.window=null),t.state=null,ki},Fw=(t,e)=>{if(zi(t))return hr;let r=t.state;return(r.wrap&2)===0?hr:(r.head=e,e.done=!1,ki)},Iw=(t,e)=>{let r=e.length,n,i,a;return zi(t)||(n=t.state,n.wrap!==0&&n.mode!==$c)?hr:n.mode===$c&&(i=1,i=Is(i,e,r,0),i!==n.check)?k0:(a=W0(t,e,r,r),a?(n.mode=z0,U0):(n.havedict=1,ki))},Dw=G0,kw=V0,Uw=N0,zw=Pw,Ow=H0,Nw=Cw,Gw=Bw,Vw=Fw,Hw=Iw,Ww="pako inflate (from Nodeca project)",pn={inflateReset:Dw,inflateReset2:kw,inflateResetKeep:Uw,inflateInit:zw,inflateInit2:Ow,inflate:Nw,inflateEnd:Gw,inflateGetHeader:Vw,inflateSetDictionary:Hw,inflateInfo:Ww};function Xw(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var $w=Xw,X0=Object.prototype.toString,{Z_NO_FLUSH:Kw,Z_FINISH:Yw,Z_OK:Us,Z_STREAM_END:gf,Z_NEED_DICT:yf,Z_STREAM_ERROR:qw,Z_DATA_ERROR:u0,Z_MEM_ERROR:Zw}=Ui;function Gs(t){this.options=Yc.assign({chunkSize:1024*64,windowBits:15,to:""},t||{});let e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(t&&t.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new B0,this.strm.avail_out=0;let r=pn.inflateInit2(this.strm,e.windowBits);if(r!==Us)throw new Error(Ii[r]);if(this.header=new $w,pn.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=ks.string2buf(e.dictionary):X0.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=pn.inflateSetDictionary(this.strm,e.dictionary),r!==Us)))throw new Error(Ii[r])}Gs.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i=this.options.dictionary,a,o,s;if(this.ended)return!1;for(e===~~e?o=e:o=e===!0?Yw:Kw,X0.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),a=pn.inflate(r,o),a===yf&&i&&(a=pn.inflateSetDictionary(r,i),a===Us?a=pn.inflate(r,o):a===u0&&(a=yf));r.avail_in>0&&a===gf&&r.state.wrap>0&&t[r.next_in]!==0;)pn.inflateReset(r),a=pn.inflate(r,o);switch(a){case qw:case u0:case yf:case Zw:return this.onEnd(a),this.ended=!0,!1}if(s=r.avail_out,r.next_out&&(r.avail_out===0||a===gf))if(this.options.to==="string"){let c=ks.utf8border(r.output,r.next_out),l=r.next_out-c,u=ks.buf2string(r.output,c);r.next_out=l,r.avail_out=n-l,l&&r.output.set(r.output.subarray(c,c+l),0),this.onData(u)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(!(a===Us&&s===0)){if(a===gf)return a=pn.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,!0;if(r.avail_in===0)break}}return!0};Gs.prototype.onData=function(t){this.chunks.push(t)};Gs.prototype.onEnd=function(t){t===Us&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=Yc.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Ff(t,e){let r=new Gs(e);if(r.push(t),r.err)throw r.msg||Ii[r.err];return r.result}function jw(t,e){return e=e||{},e.raw=!0,Ff(t,e)}var Qw=Gs,Jw=Ff,e2=jw,t2=Ff,r2=Ui,n2={Inflate:Qw,inflate:Jw,inflateRaw:e2,ungzip:t2,constants:r2},{Deflate:i2,deflate:a2,deflateRaw:o2,gzip:s2}=dw,{Inflate:l2,inflate:c2,inflateRaw:u2,ungzip:d2}=n2,f2=i2,h2=a2,m2=o2,p2=s2,g2=l2,y2=c2,b2=u2,x2=d2,v2=Ui,If={Deflate:f2,deflate:h2,deflateRaw:m2,gzip:p2,Inflate:g2,inflate:y2,inflateRaw:b2,ungzip:x2,constants:v2};var Ya=class Ya{constructor(e=Ya.INITIAL_SIZE){f(this,"buffer");f(this,"readOffset");f(this,"writeOffset");this.buffer=new Uint8Array(e),this.readOffset=0,this.writeOffset=0}append(e){let r=e instanceof Uint8Array?e:new Uint8Array(e),n=this.writeOffset+r.length;n>this.buffer.length&&this.grow(n),this.buffer.set(r,this.writeOffset),this.writeOffset+=r.length}hasBytes(e){return this.writeOffset-this.readOffset>=e}available(){return this.writeOffset-this.readOffset}readByte(){if(!this.hasBytes(1))throw new Error("Buffer underflow");return this.buffer[this.readOffset++]}readShort(){if(!this.hasBytes(2))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8;return this.readOffset+=2,e>32767?e-65536:e}readLong(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8|this.buffer[this.readOffset+2]<<16|this.buffer[this.readOffset+3]<<24;return this.readOffset+=4,e}readFloat(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let r=new DataView(this.buffer.buffer,this.buffer.byteOffset+this.readOffset,4).getFloat32(0,!0);return this.readOffset+=4,r}readString(){let e=Math.min(Ya.MAX_STRING_LENGTH,this.writeOffset-this.readOffset),r=0;for(;r<e&&this.buffer[this.readOffset+r]!==0;)r++;if(r>=e)throw this.writeOffset-this.readOffset<=e?new Error("Buffer underflow"):new Error("String exceeds max length");let n=this.buffer.slice(this.readOffset,this.readOffset+r);return this.readOffset+=r+1,new TextDecoder("latin1").decode(n)}peekBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");return this.buffer.slice(this.readOffset,this.readOffset+e)}readBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");let r=this.buffer.slice(this.readOffset,this.readOffset+e);return this.readOffset+=e,r}readData(e){return this.readBytes(e)}getReadPosition(){return this.readOffset}getWritePosition(){return this.writeOffset}setReadPosition(e){if(e<0||e>this.writeOffset)throw new Error("Invalid read position");this.readOffset=e}grow(e){let r=e?Math.max(e,this.buffer.length*2):this.buffer.length*2,n=new Uint8Array(r);n.set(this.buffer),this.buffer=n}compact(){if(this.readOffset===0)return;let e=this.writeOffset-this.readOffset;if(e===0){this.readOffset=0,this.writeOffset=0;return}this.buffer.copyWithin(0,this.readOffset,this.writeOffset),this.readOffset=0,this.writeOffset=e}getCapacity(){return this.buffer.length}reset(){this.readOffset=0,this.writeOffset=0}};f(Ya,"INITIAL_SIZE",64*1024),f(Ya,"MAX_STRING_LENGTH",2048);var ei=Ya;var Kr=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0,bitsHigh:0,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame:0}),Mr=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0,watertype:0});var $0={0:C.bad,1:C.nop,2:C.disconnect,3:C.reconnect,4:C.download,5:C.frame,6:C.inventory,7:C.layout,8:C.muzzleflash,9:C.temp_entity,10:C.sound,11:C.print,12:C.stufftext,13:C.serverdata,14:C.configstring,15:C.spawnbaseline,16:C.centerprint,17:C.playerinfo,18:C.packetentities,19:C.deltapacketentities,20:C.muzzleflash2},Zc=class{constructor(){f(this,"protocolVersion",34)}translateCommand(e){return $0[e]!==void 0?$0[e]:C.bad}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n;return r&si?n=e.readShort():n=e.readByte(),{number:n,bits:r,bitsHigh:0}}parseDelta(e,r,n,i,a,o){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Yr=2023,jc=class{constructor(){f(this,"protocolVersion",Yr)}translateCommand(e){return e}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readByte(),o=e.readString(),s=e.readShort();if(s===-2){let l=e.readShort();for(let u=0;u<l;u++)e.readShort();s=0}else s===-1&&(s=-1);let c=e.readString();return{protocol:r,serverCount:n,spawnCount:n,attractLoop:0,gameDir:o,playerNum:s,levelName:c,tickRate:a,demoType:i}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n=0;r&Vi&&(n=e.readByte());let i;return r&si?i=e.readShort():i=e.readByte(),{number:i,bits:r,bitsHigh:n}}parseDelta(e,r,n,i,a,o){Object.assign(r,e),r.origin={...e.origin},r.old_origin={...e.old_origin},r.angles={...e.angles},r.number=n,r.bits=i,r.bitsHigh=a,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort()),i&Lr&&(r.alpha=o.readByte()/255),i&Cr&&(r.scale=o.readFloat()),i&Br&&(r.instanceBits=o.readLong()),i&Fr&&(r.loopVolume=o.readByte()/255),a&wn&&(r.loopAttenuation=o.readByte()/255),a&Mn&&(r.owner=o.readShort()),a&An&&(r.oldFrame=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Qc=class{constructor(e=0){f(this,"protocolVersion");this.protocolVersion=e}translateCommand(e){return e}parseServerData(e){let r=e.readLong(),n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}parseEntityBits(e){let r=e.readByte();r&Tr&&(r|=e.readByte()<<8),r&Pr&&(r|=e.readByte()<<16),r&Rr&&(r|=e.readByte()<<24);let n;return r&si?n=e.readShort():n=e.readByte(),{number:n,bits:r,bitsHigh:0}}parseDelta(e,r,n,i,a,o){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.number=n,r.bits=i,i&Bt&&(r.modelindex=o.readByte()),i&It&&(r.modelindex2=o.readByte()),i&Dt&&(r.modelindex3=o.readByte()),i&kt&&(r.modelindex4=o.readByte()),i&Lt&&(r.frame=o.readByte()),i&Ft&&(r.frame=o.readShort()),i&Qe&&i&tt?r.skinnum=o.readLong():i&Qe?r.skinnum=o.readByte():i&tt&&(r.skinnum=o.readShort()),i&je&&i&et?r.effects=o.readLong():i&je?r.effects=o.readByte():i&et&&(r.effects=o.readShort()),i&Ze&&i&Je?r.renderfx=o.readLong():i&Ze?r.renderfx=o.readByte():i&Je&&(r.renderfx=o.readShort()),i&Mt&&(r.origin.x=o.readShort()*.125),i&At&&(r.origin.y=o.readShort()*.125),i&Rt&&(r.origin.z=o.readShort()*.125),i&Ct&&(r.angles.x=o.readByte()*(360/256)),i&Et&&(r.angles.y=o.readByte()*(360/256)),i&Tt&&(r.angles.z=o.readByte()*(360/256)),i&br&&(r.old_origin.x=o.readShort()*.125,r.old_origin.y=o.readShort()*.125,r.old_origin.z=o.readShort()*.125),i&Ut&&(r.sound=o.readByte()),i&Pt?r.event=o.readByte():r.event=0,i&zt&&(r.solid=o.readShort())}parsePlayerState(e){let r=Mr(),n=e.readShort();n&1&&(r.pm_type=e.readByte()),n&2&&(r.origin.x=e.readShort()*.125,r.origin.y=e.readShort()*.125,r.origin.z=e.readShort()*.125),n&4&&(r.velocity.x=e.readShort()*.125,r.velocity.y=e.readShort()*.125,r.velocity.z=e.readShort()*.125),n&8&&(r.pm_time=e.readByte()),n&16&&(r.pm_flags=e.readByte()),n&32&&(r.gravity=e.readShort()),n&64&&(r.delta_angles.x=e.readShort()*(180/32768),r.delta_angles.y=e.readShort()*(180/32768),r.delta_angles.z=e.readShort()*(180/32768)),n&128&&(r.viewoffset.x=(e.readByte()<<24>>24)*.25,r.viewoffset.y=(e.readByte()<<24>>24)*.25,r.viewoffset.z=(e.readByte()<<24>>24)*.25),n&256&&(r.viewangles.x=e.readShort()*(360/65536),r.viewangles.y=e.readShort()*(360/65536),r.viewangles.z=e.readShort()*(360/65536)),n&512&&(r.kick_angles.x=(e.readByte()<<24>>24)*.25,r.kick_angles.y=(e.readByte()<<24>>24)*.25,r.kick_angles.z=(e.readByte()<<24>>24)*.25),n&4096&&(r.gun_index=e.readByte()),n&8192&&(r.gun_frame=e.readByte(),r.gun_offset.x=(e.readByte()<<24>>24)*.25,r.gun_offset.y=(e.readByte()<<24>>24)*.25,r.gun_offset.z=(e.readByte()<<24>>24)*.25,r.gun_angles.x=(e.readByte()<<24>>24)*.25,r.gun_angles.y=(e.readByte()<<24>>24)*.25,r.gun_angles.z=(e.readByte()<<24>>24)*.25),n&1024&&(r.blend[0]=e.readByte(),r.blend[1]=e.readByte(),r.blend[2]=e.readByte(),r.blend[3]=e.readByte()),n&2048&&(r.fov=e.readByte()),n&16384&&(r.rdflags=e.readByte()),n&32768&&(r.watertype=e.readByte());let i=e.readLong();for(let a=0;a<32;a++)i&1<<a&&(r.stats[a]=e.readShort());return r}};var Vs=class{constructor(){f(this,"protocolVersion",0)}translateCommand(e){return e===7?C.serverdata:e===12?C.serverdata:e===13?C.serverdata:e===C.stufftext?C.stufftext:C.bad}parseServerData(e){let r=e.readLong();if(r===Yr){let n=e.readLong(),i=e.readByte(),a=e.readByte(),o=e.readString(),s=e.readShort();if(s===-2){let l=e.readShort();for(let u=0;u<l;u++)e.readShort();s=0}else s===-1&&(s=-1);let c=e.readString();return{protocol:r,serverCount:n,spawnCount:n,attractLoop:0,gameDir:o,playerNum:s,levelName:c,tickRate:a,demoType:i}}else{let n=e.readLong(),i=e.readByte(),a=e.readString(),o=e.readShort(),s=e.readString();return{protocol:r,serverCount:n,attractLoop:i,gameDir:a,playerNum:o,levelName:s}}}parseEntityBits(e){throw new Error("Bootstrap handler cannot parse entities")}parseDelta(e,r,n,i,a,o){throw new Error("Bootstrap handler cannot parse delta")}parsePlayerState(e){throw new Error("Bootstrap handler cannot parse player state")}};function K0(t){return t===0?new Vs:t===Yr?new jc:t===34?new Zc:new Qc(t)}var Y0=1,_2=2,S2=128,Df=class extends ei{constructor(r){super(0);this.stream=r}readByte(){return this.stream.readByte()}readShort(){return this.stream.readShort()}readLong(){return this.stream.readLong()}readFloat(){return this.stream.readFloat()}readString(){return this.stream.readString()}readData(r){return this.stream.readData(r)}hasBytes(r){return this.stream.hasMore()}available(){return this.stream.getRemaining()}getReadPosition(){return this.stream.getPosition()}peekBytes(r){throw new Error("peekBytes not implemented for BinaryStreamAdapter")}},_t=class t{constructor(e,r,n=!1){f(this,"stream");f(this,"handler");f(this,"strictMode",!1);f(this,"errorCount",0);f(this,"protocolHandler");f(this,"isDemo",Y0);e instanceof En?this.stream=new Df(e):this.stream=e,this.handler=r,this.strictMode=n,this.protocolHandler=new Vs}setProtocolVersion(e){this.protocolHandler.protocolVersion!==e&&(this.protocolHandler=K0(e))}getProtocolVersion(){return this.protocolHandler.protocolVersion}getErrorCount(){return this.errorCount}parseMessage(){for(;this.stream.hasBytes(1);){let e=this.stream.getReadPosition(),r=-1;try{if(r=this.stream.readByte(),r===-1)break;let n=r,i=this.protocolHandler.translateCommand(r);switch(i){case C.bad:if(n===0)return;let a=`Unknown server command: ${n} (translated: ${i}) at offset ${e} (Protocol: ${this.getProtocolVersion()})`;if(this.strictMode)throw new Error(a);console.warn(a),this.errorCount++;return;case C.nop:break;case C.disconnect:this.handler?.onDisconnect&&this.handler.onDisconnect();break;case C.reconnect:this.handler?.onReconnect&&this.handler.onReconnect();break;case C.print:this.parsePrint();break;case C.serverdata:this.parseServerData();break;case C.configstring:this.parseConfigString();break;case C.spawnbaseline:this.parseSpawnBaseline();break;case C.centerprint:this.parseCenterPrint();break;case C.download:this.parseDownload();break;case C.frame:this.parseFrame();break;case C.packetentities:this.parsePacketEntities(!1);break;case C.deltapacketentities:this.parsePacketEntities(!0);break;case C.playerinfo:this.parsePlayerState();break;case C.stufftext:this.parseStuffText();break;case C.layout:this.parseLayout();break;case C.inventory:this.parseInventory();break;case C.sound:this.parseSound();break;case C.muzzleflash:this.parseMuzzleFlash();break;case C.muzzleflash2:this.parseMuzzleFlash2();break;case C.temp_entity:this.parseTempEntity();break;case C.splitclient:this.parseSplitClient();break;case C.configblast:this.parseConfigBlast();break;case C.spawnbaselineblast:this.parseSpawnBaselineBlast();break;case C.level_restart:this.handler?.onLevelRestart&&this.handler.onLevelRestart();break;case C.damage:this.parseDamage();break;case C.locprint:this.parseLocPrint();break;case C.fog:this.parseFog();break;case C.waitingforplayers:this.parseWaitingForPlayers();break;case C.bot_chat:this.parseBotChat();break;case C.poi:this.parsePoi();break;case C.help_path:this.parseHelpPath();break;case C.muzzleflash3:this.parseMuzzleFlash3();break;case C.achievement:this.parseAchievement();break;default:let o=`Unknown server command: ${n} (translated: ${i}) at offset ${e}`;if(this.strictMode)throw new Error(o);console.warn(o),this.errorCount++;return}}catch(n){let i=n.message;if(i==="Buffer underflow"||i.includes("StreamingBuffer")){try{this.stream.setReadPosition(e)}catch(o){console.error("Failed to rollback stream position",o)}return}let a=`offset ${e}, cmd ${r}, protocol ${this.getProtocolVersion()}`;if(console.warn(`Error parsing command ${r} (${a}): ${i}`),this.errorCount++,this.strictMode)throw n;return}}}readAngle16(){return this.stream.readShort()*(360/65536)}readCoord(){return this.stream.readShort()*.125}readAngle(){return this.stream.readByte()*(360/256)}readPos(e){e.x=this.stream.readShort()*.125,e.y=this.stream.readShort()*.125,e.z=this.stream.readShort()*.125}readDir(e){let r=this.stream.readByte();if(r>=yr.length)e.x=0,e.y=0,e.z=0;else{let n=yr[r];e.x=n[0],e.y=n[1],e.z=n[2]}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}parseServerData(){let e=this.protocolHandler.parseServerData(this.stream);this.setProtocolVersion(e.protocol),this.handler&&this.handler.onServerData(e.protocol,e.serverCount,e.attractLoop,e.gameDir,e.playerNum,e.levelName,e.tickRate,e.demoType),e.protocol===Yr?this.isDemo=e.demoType??Y0:this.isDemo=e.attractLoop}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseSplitClient(){let e=this.stream.readByte();this.handler?.onSplitClient&&this.handler.onSplitClient(e)}parseConfigBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=If.inflate(n),a=new En(i.buffer);for(;a.hasMore();){let o=a.readUShort(),s=a.readString();this.handler&&this.handler.onConfigString(o,s)}}catch(i){console.error("svc_configblast error",i)}}parseSpawnBaselineBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=If.inflate(n),a=new En(i.buffer),o=new t(a,this.handler,this.strictMode);for(o.setProtocolVersion(this.getProtocolVersion());a.hasMore();)o.parseSpawnBaseline()}catch(i){console.error("svc_spawnbaselineblast error",i)}}parseLocPrint(){let e=this.stream.readByte(),r=this.stream.readString(),n=this.stream.readByte(),i=[];for(let a=0;a<n;a++)i.push(this.stream.readString());this.handler?.onLocPrint&&this.handler.onLocPrint(e,r,i)}parseWaitingForPlayers(){let e=this.stream.readByte();this.handler?.onWaitingForPlayers&&this.handler.onWaitingForPlayers(e)}parseBotChat(){let e=this.stream.readString(),r=this.stream.readShort(),n=this.stream.readString();this.handler?.onBotChat&&this.handler.onBotChat(n)}parsePoi(){let e=this.stream.readShort(),r=this.stream.readShort(),n={x:0,y:0,z:0};this.readPos(n);let i=this.stream.readShort(),a=this.stream.readByte(),o=this.stream.readByte();this.handler?.onPoi&&this.handler.onPoi(o,n)}parseHelpPath(){let e=this.stream.readByte(),r={x:0,y:0,z:0};this.readPos(r);let n={x:0,y:0,z:0};this.readDir(n),this.handler?.onHelpPath&&this.handler.onHelpPath(r)}parseAchievement(){let e=this.stream.readString();this.handler?.onAchievement&&this.handler.onAchievement(e)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,a,o,s;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(a=this.stream.readByte()),e&8&&(o=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.readPos(c),s=c}this.handler&&this.handler.onSound(e,r,n,i,a,o,s)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler?.onMuzzleFlash3&&this.handler.onMuzzleFlash3(e,r)}parseFog(){let e=this.stream.readByte();if(e&128){let n=this.stream.readByte();e|=n<<8}let r={};e&1&&(r.density=this.stream.readFloat(),r.skyfactor=this.stream.readByte()),e&2&&(r.red=this.stream.readByte()),e&4&&(r.green=this.stream.readByte()),e&8&&(r.blue=this.stream.readByte()),e&16&&(r.time=this.stream.readShort()),e&32&&(r.hf_falloff=this.stream.readFloat()),e&64&&(r.hf_density=this.stream.readFloat()),e&256&&(r.hf_start_r=this.stream.readByte()),e&512&&(r.hf_start_g=this.stream.readByte()),e&1024&&(r.hf_start_b=this.stream.readByte()),e&2048&&(r.hf_start_dist=this.stream.readLong()),e&4096&&(r.hf_end_r=this.stream.readByte()),e&8192&&(r.hf_end_g=this.stream.readByte()),e&16384&&(r.hf_end_b=this.stream.readByte()),e&32768&&(r.hf_end_dist=this.stream.readLong()),this.handler?.onFog&&this.handler.onFog(r)}parseDamage(){let e=this.stream.readByte(),r=[];for(let n=0;n<e;n++){let i=this.stream.readByte(),a={x:0,y:0,z:0};this.readDir(a);let o=i&31,s=(i&32)!==0,c=(i&64)!==0,l=(i&128)!==0;r.push({damage:o,health:s,armor:c,power:l,dir:a})}this.handler?.onDamage&&this.handler.onDamage(r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},a,o,s,c,l;switch(e){case O.EXPLOSION1:case O.EXPLOSION2:case O.ROCKET_EXPLOSION:case O.GRENADE_EXPLOSION:case O.ROCKET_EXPLOSION_WATER:case O.GRENADE_EXPLOSION_WATER:case O.BFG_EXPLOSION:case O.BFG_BIGEXPLOSION:case O.BOSSTPORT:case O.PLASMA_EXPLOSION:case O.PLAIN_EXPLOSION:case O.CHAINFIST_SMOKE:case O.TRACKER_EXPLOSION:case O.TELEPORT_EFFECT:case O.DBALL_GOAL:case O.NUKEBLAST:case O.WIDOWSPLASH:case O.EXPLOSION1_BIG:case O.EXPLOSION1_NP:this.readPos(r);break;case O.GUNSHOT:case O.BLOOD:case O.BLASTER:case O.SHOTGUN:case O.SPARKS:case O.BULLET_SPARKS:case O.SCREEN_SPARKS:case O.SHIELD_SPARKS:case O.BLASTER2:case O.FLECHETTE:case O.MOREBLOOD:case O.ELECTRIC_SPARKS:case O.HEATBEAM_SPARKS:case O.HEATBEAM_STEAM:this.readPos(r),this.readDir(i);break;case O.SPLASH:case O.LASER_SPARKS:case O.WELDING_SPARKS:case O.TUNNEL_SPARKS:a=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte();break;case O.BLUEHYPERBLASTER:this.getProtocolVersion()>=32?(this.readPos(r),this.readPos(n)):(this.readPos(r),this.readDir(i));break;case O.GREENBLOOD:this.getProtocolVersion()>=32?(this.readPos(r),this.readDir(i)):(this.readPos(r),this.readPos(n));break;case O.RAILTRAIL:case O.BUBBLETRAIL:case O.BFG_LASER:case O.DEBUGTRAIL:case O.BUBBLETRAIL2:this.readPos(r),this.readPos(n);break;case O.PARASITE_ATTACK:case O.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.readPos(r),this.readPos(n);break;case O.GRAPPLE_CABLE:s=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readPos(i);break;case O.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.readPos(r),this.readPos(n);break;case O.FLASHLIGHT:this.readPos(r),s=this.stream.readShort();break;case O.FORCEWALL:this.readPos(r),this.readPos(n),o=this.stream.readByte();break;case O.STEAM:let u=this.stream.readShort();a=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte(),this.stream.readShort(),u!==-1&&this.stream.readLong();break;case O.WIDOWBEAMOUT:this.stream.readShort();case O.HEATBEAM:case O.MONSTER_HEATBEAM:s=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readDir(i);break}this.handler&&this.handler.onTempEntity(e,r,n,i,a,o,s,c,l)}parseSpawnBaseline(){let e=this.protocolHandler.parseEntityBits(this.stream),r=Kr();this.protocolHandler.parseDelta(Kr(),r,e.number,e.bits,e.bitsHigh,this.stream),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=0;this.getProtocolVersion()!==26&&this.getProtocolVersion()!==25&&(n=this.stream.readByte());let i=this.stream.readByte(),a=this.stream.readData(i),o=this.stream.readByte();if(o=this.protocolHandler.translateCommand(o),o!==C.playerinfo){if(this.strictMode)throw new Error(`Expected svc_playerinfo after svc_frame, got ${o}`);return}let s=this.parsePlayerState(),c=this.stream.readByte();if(c=this.protocolHandler.translateCommand(c),c!==C.packetentities&&c!==C.deltapacketentities){if(this.strictMode)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${c}`);return}let l=this.collectPacketEntities();if(this.isDemo===S2){let u=this.stream.readByte();for(let d=0;d<u;d++)this.stream.readByte()}this.isDemo===_2&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:a,playerState:s,packetEntities:{delta:!0,entities:l}})}parsePlayerState(){return this.protocolHandler.parsePlayerState(this.stream)}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Mr(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.protocolHandler.parseEntityBits(this.stream);if(r.bits&ao){if(r.number===0)break;continue}let n=Kr();if(r.number===0)break;this.protocolHandler.parseDelta(Kr(),n,r.number,r.bits,r.bitsHigh,this.stream),e.push(n)}return e}};var kf=(u=>(u.WeaponFire="weapon_fire",u.DamageDealt="damage_dealt",u.DamageReceived="damage_received",u.Pickup="pickup",u.Death="death",u.Kill="kill",u.Spawn="spawn",u.PlayerInfo="player_info",u.Chat="chat",u.Objective="objective",u))(kf||{});var qa=class{constructor(e){f(this,"buffer");f(this,"events",[]);f(this,"summary",{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map});f(this,"header",null);f(this,"configStrings",new Map);f(this,"serverInfo",{});f(this,"statistics",null);f(this,"playerStats",new Map);f(this,"weaponStats",new Map);f(this,"activeEntities",new Set);this.buffer=e}analyze(){let e=new wr(this.buffer),r=-1,n=0,i=.1,a=0,o={onServerData:(s,c,l,u,d,h,m,p)=>{a=s,this.header={protocolVersion:s,gameDir:u,levelName:h,playerNum:d,serverCount:c,spawnCount:c,tickRate:m,demoType:p},m&&m>0&&(i=1/m)},onConfigString:(s,c)=>{this.configStrings.set(s,c),s===0&&this.parseServerInfo(c)},onSpawnBaseline:s=>{},onFrame:s=>{let c=new Set;if(s.packetEntities&&s.packetEntities.entities)for(let l of s.packetEntities.entities)c.add(l.number),this.activeEntities.has(l.number)||this.recordEvent({type:"spawn",frame:r,time:n,entityId:l.number,position:{x:l.origin.x,y:l.origin.y,z:l.origin.z},description:`Entity ${l.number} spawned`});this.activeEntities=c,s.playerState&&this.header},onPrint:(s,c)=>{let l=c.replace(/\n/g," ").trim();l.includes("died")||l.includes("killed")||l.includes("suicide")?(this.summary.totalDeaths++,this.recordEvent({type:"death",frame:r,time:n,description:l})):l.startsWith("You got the ")?this.recordEvent({type:"pickup",frame:r,time:n,description:l}):(s===3||s===2)&&this.recordEvent({type:"chat",frame:r,time:n,description:l,data:{level:s}})},onCenterPrint:s=>{this.recordEvent({type:"objective",frame:r,time:n,description:s.trim()})},onStuffText:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onMuzzleFlash2:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onMuzzleFlash3:(s,c)=>{this.handleWeaponFire(s,c,r,n)},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{},onDamage:s=>{for(let c of s)if(this.recordEvent({type:"damage_received",frame:r,time:n,value:c.damage,position:c.dir,description:`Took ${c.damage} damage`}),this.summary.damageReceived+=c.damage,this.header){let l=this.getOrCreatePlayerStats(this.header.playerNum);l.damageReceived+=c.damage}}};for(;e.hasMore();){let s=e.readNextBlock();if(!s)break;r++,n=r*i;let c=new _t(s.data,o);c.setProtocolVersion(a),c.parseMessage(),a=c.getProtocolVersion()}return this.statistics={duration:n,frameCount:r+1,averageFps:(r+1)/(n||1),mapName:this.header?.levelName||"unknown",playerCount:1},{events:this.events,summary:this.summary,header:this.header,configStrings:this.configStrings,serverInfo:this.serverInfo,statistics:this.statistics,playerStats:this.playerStats,weaponStats:this.weaponStats}}handleWeaponFire(e,r,n,i){this.recordEvent({type:"weapon_fire",frame:n,time:i,entityId:e,value:r,description:`Weapon ${r} fired by ${e}`});let a=this.summary.weaponUsage.get(r)||0;this.summary.weaponUsage.set(r,a+1);let o=this.getOrCreateWeaponStat(e,r);o.shotsFired++}recordEvent(e){this.events.push(e)}parseServerInfo(e){let r=e.split("\\");for(let n=1;n<r.length;n+=2)n+1<r.length&&(this.serverInfo[r[n]]=r[n+1])}getOrCreatePlayerStats(e){let r=this.playerStats.get(e);return r||(r={kills:0,deaths:0,damageDealt:0,damageReceived:0,suicides:0},this.playerStats.set(e,r)),r}getOrCreateWeaponStat(e,r){let n=this.weaponStats.get(e);n||(n=[],this.weaponStats.set(e,n));let i=n.find(a=>a.weaponId===r);return i||(i={weaponId:r,shotsFired:0,hits:0,kills:0},n.push(i)),i}};var Uf=(i=>(i[i.FirstPerson=0]="FirstPerson",i[i.ThirdPerson=1]="ThirdPerson",i[i.Free=2]="Free",i[i.Follow=3]="Follow",i))(Uf||{});var Jc=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Jc||{}),w2=()=>({onServerData:()=>{},onConfigString:()=>{},onSpawnBaseline:()=>{},onFrame:()=>{},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}}),Hs=class{constructor(){f(this,"reader",null);f(this,"buffer",null);f(this,"state",0);f(this,"playbackSpeed",1);f(this,"handler");f(this,"callbacks");f(this,"currentProtocolVersion",0);f(this,"currentFrameIndex",-1);f(this,"lastFrameData",null);f(this,"accumulatedTime",0);f(this,"frameDuration",100);f(this,"snapshotInterval",100);f(this,"snapshots",new Map);f(this,"cachedEvents",null);f(this,"cachedSummary",null);f(this,"cachedHeader",null);f(this,"cachedConfigStrings",null);f(this,"cachedServerInfo",null);f(this,"cachedStatistics",null);f(this,"cachedPlayerStats",null);f(this,"cachedWeaponStats",null);f(this,"tracker",null);f(this,"cameraMode",0);f(this,"thirdPersonDistance",80);f(this,"thirdPersonOffset",{x:0,y:0,z:0})}setHandler(e){this.handler=e}setCallbacks(e){this.callbacks=e}loadDemo(e){this.buffer=e,this.reader=new wr(e),this.transitionState(0),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.snapshots.clear(),this.lastFrameData=null,this.cachedEvents=null,this.cachedSummary=null,this.cachedHeader=null,this.cachedConfigStrings=null,this.cachedServerInfo=null,this.cachedStatistics=null,this.cachedPlayerStats=null,this.cachedWeaponStats=null}play(){this.reader&&this.state!==1&&this.transitionState(1)}pause(){this.state===1&&this.transitionState(2)}stop(){this.transitionState(0),this.reader&&this.reader.reset(),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.lastFrameData=null}transitionState(e){this.state!==e&&(this.state=e,this.callbacks?.onPlaybackStateChange&&this.callbacks.onPlaybackStateChange(e))}setFrameDuration(e){this.frameDuration=e}setSpeed(e){this.playbackSpeed=Math.max(.1,Math.min(e,16))}getSpeed(){return this.playbackSpeed}getPlaybackSpeed(){return this.playbackSpeed}getInterpolationFactor(){return this.frameDuration<=0?0:Math.max(0,Math.min(1,this.accumulatedTime/this.frameDuration))}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.processNextFrame())return;this.accumulatedTime-=this.frameDuration,this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}}stepForward(){this.reader&&(this.processNextFrame(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime()))}stepBackward(){this.reader&&this.currentFrameIndex>0&&this.seek(this.currentFrameIndex-1)}seekToTime(e){let r=this.timeToFrame(e);this.seek(r)}seekToFrame(e){this.seek(e)}frameToTime(e){return e*this.frameDuration/1e3}timeToFrame(e){return Math.floor(e*1e3/this.frameDuration)}playFrom(e){if(e.type==="frame")this.seek(e.frame);else if(e.type==="time")this.seekToTime(e.seconds);else throw new Error(`Invalid offset type: ${e.type}`);this.play()}playRange(e,r){let n=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),i=r.type==="frame"?r.frame:this.timeToFrame(r.seconds),a=this.getTotalFrames(),o=Math.max(0,a-1);if(n<0)throw new Error(`Invalid start offset: ${n}`);if(i<n)throw new Error(`End offset (${i}) cannot be before start offset (${n})`);this.playFrom(e);let s=this.callbacks?.onFrameUpdate,c={...this.callbacks,onFrameUpdate:l=>{if(s&&s(l),this.currentFrameIndex>=i){this.pause();let u=this.callbacks?.onPlaybackComplete;this.callbacks===c&&this.setCallbacks({...this.callbacks,onFrameUpdate:s}),u&&u()}}};this.setCallbacks(c)}seek(e){if(!this.reader)return;let r=this.getTotalFrames();if(r>0&&e>=r&&(e=r-1),e<0&&(e=0),e===this.currentFrameIndex+1){this.processNextFrame(),this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}if(e===this.currentFrameIndex){this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}let n=-1,i=null;if(e>this.currentFrameIndex&&this.currentFrameIndex!==-1&&(n=this.currentFrameIndex),this.callbacks?.onRestoreSnapshot)for(let[a,o]of this.snapshots)a<=e&&a>n&&(n=a,i=o);for(n===-1&&this.currentFrameIndex>e?(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0):n===-1&&(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0),i&&this.callbacks?.onRestoreSnapshot&&(this.callbacks.onRestoreSnapshot(i),this.reader.seekToMessage(n+1)?this.currentFrameIndex=n:(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0));this.currentFrameIndex<e&&(this.callbacks?.onCaptureSnapshot&&(this.currentFrameIndex+1)%this.snapshotInterval,!!this.processNextFrame()););this.accumulatedTime=0,this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}processNextFrame(){if(!this.reader||!this.reader.hasMore())return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;let e=this.reader.readNextBlock();if(!e)return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;this.currentFrameIndex++,this.tracker&&(this.tracker.setCurrentFrame(this.currentFrameIndex),this.tracker.setCurrentTime(this.getCurrentTime()));try{let r={...this.handler||w2(),onFrame:i=>{this.lastFrameData=i,this.handler?.onFrame&&this.handler.onFrame(i),this.callbacks?.onFrameUpdate&&this.callbacks.onFrameUpdate(i)}},n=new _t(e.data,r);if(n.setProtocolVersion(this.currentProtocolVersion),n.parseMessage(),this.currentProtocolVersion=n.getProtocolVersion(),this.callbacks?.onCaptureSnapshot&&this.currentFrameIndex%this.snapshotInterval===0&&this.currentFrameIndex>0){let i=this.callbacks.onCaptureSnapshot(this.currentFrameIndex);i&&this.snapshots.set(this.currentFrameIndex,i)}}catch(r){return console.error("Error processing demo frame",r),this.callbacks?.onPlaybackError&&this.callbacks.onPlaybackError(r instanceof Error?r:new Error(String(r))),!1}return!0}getState(){return this.state}getCurrentTime(){return this.currentFrameIndex<0?this.accumulatedTime/1e3:(this.currentFrameIndex*this.frameDuration+this.accumulatedTime)/1e3}getFrameCount(){return this.reader?this.reader.getMessageCount():0}getTotalFrames(){return this.getFrameCount()}getCurrentFrame(){return this.currentFrameIndex<0?0:this.currentFrameIndex}getDuration(){return this.getFrameCount()*this.frameDuration/1e3}getTotalBytes(){return this.reader?this.reader.getProgress().total:0}getProcessedBytes(){return this.reader?this.reader.getOffset():0}getFrameData(e){if(e===this.currentFrameIndex&&this.lastFrameData)return this.lastFrameData;let r=this.state;return this.pause(),this.seek(e),r===1&&this.play(),this.lastFrameData}getFramePlayerState(e){if(e===this.currentFrameIndex&&this.handler?.getPlayerState){let n=this.handler.getPlayerState();if(n)return n}let r=this.getFrameData(e);return r?r.playerState:null}getFrameEntities(e){if(e===this.currentFrameIndex&&this.handler?.getEntities){let r=this.handler.getEntities();if(r)return Array.from(r.values())}if(this.seek(e),this.handler?.getEntities){let r=this.handler.getEntities();return r?Array.from(r.values()):[]}return[]}compareFrames(e,r){let n=this.getFramePlayerState(e),i=this.getFrameEntities(e),a=new Map;i.forEach(u=>a.set(u.number,u));let o=this.getFramePlayerState(r),s=this.getFrameEntities(r),c=new Map;s.forEach(u=>c.set(u.number,u));let l={frameA:e,frameB:r,playerStateDiff:{origin:null,viewangles:null,health:null,ammo:null},entityDiffs:{added:[],removed:[],moved:[]}};n&&o&&((n.origin.x!==o.origin.x||n.origin.y!==o.origin.y||n.origin.z!==o.origin.z)&&(l.playerStateDiff.origin={x:o.origin.x-n.origin.x,y:o.origin.y-n.origin.y,z:o.origin.z-n.origin.z}),n.stats[1]!==o.stats[1]&&(l.playerStateDiff.health=o.stats[1]-n.stats[1]),n.stats[2]!==o.stats[2]&&(l.playerStateDiff.ammo=o.stats[2]-n.stats[2]));for(let[u,d]of c){let h=a.get(u);h?(h.origin.x!==d.origin.x||h.origin.y!==d.origin.y||h.origin.z!==d.origin.z)&&l.entityDiffs.moved.push({id:u,delta:{x:d.origin.x-h.origin.x,y:d.origin.y-h.origin.y,z:d.origin.z-h.origin.z}}):l.entityDiffs.added.push(u)}for(let[u,d]of a)c.has(u)||l.entityDiffs.removed.push(u);return l}getEntityTrajectory(e,r,n){let i=[],a=this.getCurrentFrame();for(this.seek(r);this.getCurrentFrame()<=n&&this.state!==3;){let o=null;if(e===-1){let s=this.getFramePlayerState(this.getCurrentFrame());s&&(o={...s.origin})}else if(this.handler?.getEntities){let s=this.handler.getEntities().get(e);s&&(o={...s.origin})}if(o&&i.push(o),this.getCurrentFrame()===n)break;this.stepForward()}return this.seek(a),i}getEvents(){return this.ensureAnalysis(),this.cachedEvents||[]}getDemoEvents(){return this.getEvents()}filterEvents(e,r){return this.getDemoEvents().filter(i=>!(i.type!==e||r!==void 0&&i.entityId!==r))}getEventSummary(){return this.ensureAnalysis(),this.cachedSummary||{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map}}getMetadata(){let e=this.getDemoHeader();if(!e)return null;let r=this.getDemoServerInfo(),n="Unknown";return this.cachedConfigStrings,{mapName:e.levelName,playerName:n,serverName:r.hostname,demoVersion:e.protocolVersion,tickRate:e.tickRate||10}}getDemoHeader(){return this.ensureAnalysis(),this.cachedHeader}getDemoConfigStrings(){return this.ensureAnalysis(),this.cachedConfigStrings||new Map}getDemoServerInfo(){return this.ensureAnalysis(),this.cachedServerInfo||{}}getDemoStatistics(){return this.ensureAnalysis(),this.cachedStatistics}getPlayerStatistics(e){return this.ensureAnalysis(),this.cachedPlayerStats?.get(e)||null}getWeaponStatistics(e){return this.ensureAnalysis(),this.cachedWeaponStats?.get(e)||null}ensureAnalysis(){if(!this.cachedEvents&&this.buffer){let r=new qa(this.buffer).analyze();this.cachedEvents=r.events,this.cachedSummary=r.summary,this.cachedHeader=r.header,this.cachedConfigStrings=r.configStrings,this.cachedServerInfo=r.serverInfo,this.cachedStatistics=r.statistics,this.cachedPlayerStats=r.playerStats,this.cachedWeaponStats=r.weaponStats}}setCameraMode(e){this.cameraMode=e}getCameraMode(){return this.cameraMode}setThirdPersonDistance(e){this.thirdPersonDistance=e}setThirdPersonOffset(e){this.thirdPersonOffset=e}async playWithTracking(e,r={}){if(this.tracker=e,e.startTracking(),r.fastForward)try{this.state===0&&this.reader,this.transitionState(1);let n=100,i=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let a=0;for(;a<n;){if(!this.processNextFrame()){this.transitionState(0);let o=e.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),o}a++}return await new Promise(o=>setTimeout(o,0)),i()};return await i()}catch(n){throw this.transitionState(0),e.stopTracking(),this.tracker=null,n}else return new Promise((n,i)=>{let a=this.callbacks?.onPlaybackComplete,o=this.callbacks?.onPlaybackError,s=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:a,onPlaybackError:o}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let c=e.stopTracking();a&&a(),s(),n(c)},onPlaybackError:c=>{e.stopTracking(),o&&o(c),s(),i(c)}}),this.play()})}async playRangeWithTracking(e,r,n,i={}){this.tracker=n,n.startTracking();let a=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),o=r.type==="frame"?r.frame:this.timeToFrame(r.seconds);if(i.fastForward)try{this.playFrom(e),this.transitionState(1);let s=100,c=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let l=0;for(;l<s;){if(this.currentFrameIndex>=o||!this.processNextFrame()){this.transitionState(0);let u=n.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),u}l++}return await new Promise(u=>setTimeout(u,0)),c()};return await c()}catch(s){throw this.transitionState(0),n.stopTracking(),this.tracker=null,s}else return new Promise((s,c)=>{let l=this.callbacks?.onPlaybackComplete,u=this.callbacks?.onPlaybackError,d=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:l,onPlaybackError:u}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let h=n.stopTracking();l&&l(),d(),s(h)},onPlaybackError:h=>{n.stopTracking(),u&&u(h),d(),c(h)}}),this.playRange(e,r)})}};var Ws=class{constructor(){f(this,"isRecording",!1);f(this,"messageBuffer");f(this,"startTime",0);f(this,"frameCount",0);f(this,"filename",null);f(this,"lastMessageSize",-1);this.messageBuffer=new li(1024*1024)}startRecording(e,r=0){this.isRecording||(this.isRecording=!0,this.filename=e,this.startTime=r,this.frameCount=0,this.messageBuffer.reset(),console.log(`DemoRecorder: Started recording to ${e}`))}recordMessage(e){if(this.isRecording){this.messageBuffer.writeLong(e.byteLength);for(let r=0;r<e.length;r++)this.messageBuffer.writeByte(e[r]);this.frameCount++}}stopRecording(){return this.isRecording?(this.isRecording=!1,this.messageBuffer.writeLong(-1),console.log(`DemoRecorder: Stopped recording. Frames: ${this.frameCount}, Size: ${this.messageBuffer.getOffset()} bytes`),this.messageBuffer.getData()):null}getIsRecording(){return this.isRecording}};var eu=class{constructor(e,r=34){f(this,"writer");f(this,"protocol");this.writer=e||new li(new Uint8Array(64*1024)),this.protocol=r}getData(){return this.writer.getData()}getOpcode(e){if(this.protocol===34)switch(e){case C.serverdata:return 13;case C.frame:return 5;case C.playerinfo:return 17;case C.packetentities:return 18;case C.deltapacketentities:return 19;case C.print:return 11;case C.centerprint:return 16;case C.stufftext:return 12;case C.sound:return 10;case C.temp_entity:return 9;case C.configstring:return 14;case C.spawnbaseline:return 15;case C.layout:return 7;case C.inventory:return 6;case C.muzzleflash:return 8;case C.muzzleflash2:return 20}return e}writeCommand(e,r){let n=r??this.protocol;n===34||n===0?this.writer.writeByte(this.getOpcode(e)):this.writer.writeByte(e)}writeServerData(e,r,n,i,a,o){this.writeCommand(C.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeString(i),this.writer.writeShort(a),this.writer.writeString(o)}writeConfigString(e,r){this.writeCommand(C.configstring),this.writer.writeShort(e),this.writer.writeString(r)}writeStuffText(e){this.writeCommand(C.stufftext),this.writer.writeString(e)}writeCenterPrint(e){this.writeCommand(C.centerprint),this.writer.writeString(e)}writePrint(e,r){this.writeCommand(C.print),this.writer.writeByte(e),this.writer.writeString(r)}writeLayout(e){this.writeCommand(C.layout),this.writer.writeString(e)}writeInventory(e){this.writeCommand(C.inventory);for(let r of e)this.writer.writeShort(r);for(let r=e.length;r<256;r++)this.writer.writeShort(0)}writeMuzzleFlash(e,r){this.writeCommand(C.muzzleflash),this.writer.writeShort(e),this.writer.writeByte(r)}writeMuzzleFlash2(e,r){this.writeCommand(C.muzzleflash2),this.writer.writeShort(e),this.writer.writeByte(r)}writeSound(e,r,n,i,a,o,s,c){this.writeCommand(C.sound),this.writer.writeByte(e),this.writer.writeByte(r),e&1&&this.writer.writeByte(n),e&2&&this.writer.writeByte(i),e&16&&this.writer.writeByte(a),e&8&&this.writer.writeShort(o),e&4&&(this.writer.writeCoord(s.x),this.writer.writeCoord(s.y),this.writer.writeCoord(s.z))}writeTempEntity(e,r,n,i,a,o,s,c,l){this.writeCommand(C.temp_entity),this.writer.writeByte(e),r&&this.writer.writePos(r)}writePlayerState(e){this.writeCommand(C.playerinfo);let r=0;e.pm_type!==0&&(r|=1),(e.origin.x!==0||e.origin.y!==0||e.origin.z!==0)&&(r|=2),(e.velocity.x!==0||e.velocity.y!==0||e.velocity.z!==0)&&(r|=4),e.pm_time!==0&&(r|=8),e.pm_flags!==0&&(r|=16),e.gravity!==0&&(r|=32),(e.delta_angles.x!==0||e.delta_angles.y!==0||e.delta_angles.z!==0)&&(r|=64),(e.viewoffset.x!==0||e.viewoffset.y!==0||e.viewoffset.z!==0)&&(r|=128),(e.viewangles.x!==0||e.viewangles.y!==0||e.viewangles.z!==0)&&(r|=256),(e.kick_angles.x!==0||e.kick_angles.y!==0||e.kick_angles.z!==0)&&(r|=512),e.gun_index!==0&&(r|=4096),(e.gun_frame!==0||e.gun_offset.x!==0||e.gun_offset.y!==0||e.gun_offset.z!==0||e.gun_angles.x!==0||e.gun_angles.y!==0||e.gun_angles.z!==0)&&(r|=8192),(e.blend[0]!==0||e.blend[1]!==0||e.blend[2]!==0||e.blend[3]!==0)&&(r|=1024),e.fov!==0&&(r|=2048),e.rdflags!==0&&(r|=16384),e.watertype!==0&&(r|=32768),this.writer.writeShort(r),r&1&&this.writer.writeByte(e.pm_type),r&2&&(this.writer.writeShort(e.origin.x/.125),this.writer.writeShort(e.origin.y/.125),this.writer.writeShort(e.origin.z/.125)),r&4&&(this.writer.writeShort(e.velocity.x/.125),this.writer.writeShort(e.velocity.y/.125),this.writer.writeShort(e.velocity.z/.125)),r&8&&this.writer.writeByte(e.pm_time),r&16&&this.writer.writeByte(e.pm_flags),r&32&&this.writer.writeShort(e.gravity),r&64&&(this.writer.writeShort(e.delta_angles.x/(180/32768)),this.writer.writeShort(e.delta_angles.y/(180/32768)),this.writer.writeShort(e.delta_angles.z/(180/32768))),r&128&&(this.writer.writeByte(e.viewoffset.x/.25),this.writer.writeByte(e.viewoffset.y/.25),this.writer.writeByte(e.viewoffset.z/.25)),r&256&&(this.writer.writeShort(e.viewangles.x/(360/65536)),this.writer.writeShort(e.viewangles.y/(360/65536)),this.writer.writeShort(e.viewangles.z/(360/65536))),r&512&&(this.writer.writeByte(e.kick_angles.x/.25),this.writer.writeByte(e.kick_angles.y/.25),this.writer.writeByte(e.kick_angles.z/.25)),r&4096&&this.writer.writeByte(e.gun_index),r&8192&&(this.writer.writeByte(e.gun_frame),this.writer.writeByte(e.gun_offset.x/.25),this.writer.writeByte(e.gun_offset.y/.25),this.writer.writeByte(e.gun_offset.z/.25),this.writer.writeByte(e.gun_angles.x/.25),this.writer.writeByte(e.gun_angles.y/.25),this.writer.writeByte(e.gun_angles.z/.25)),r&1024&&(this.writer.writeByte(e.blend[0]),this.writer.writeByte(e.blend[1]),this.writer.writeByte(e.blend[2]),this.writer.writeByte(e.blend[3])),r&2048&&this.writer.writeByte(e.fov),r&16384&&this.writer.writeByte(e.rdflags),r&32768&&this.writer.writeByte(e.watertype);let n=0;for(let i=0;i<32;i++)e.stats[i]!==0&&(n|=1<<i);this.writer.writeLong(n);for(let i=0;i<32;i++)n&1<<i&&this.writer.writeShort(e.stats[i])}writePacketEntities(e,r,n){this.writeCommand(r?C.deltapacketentities:C.packetentities);for(let i of e)this.writeDeltaEntity(Kr(),i,!0);this.writer.writeShort(0)}writeFrame(e,r){this.writeCommand(C.frame),this.writer.writeLong(e.serverFrame),this.writer.writeLong(e.deltaFrame),r!==26&&r!==25&&this.writer.writeByte(e.surpressCount),this.writer.writeByte(e.areaBytes),this.writer.writeBytes(e.areaBits),this.writePlayerState(e.playerState),this.writePacketEntities(e.packetEntities.entities,e.packetEntities.delta,r)}writeDeltaEntity(e,r,n){let i=0,a=0;(r.modelindex!==e.modelindex||n)&&(i|=Bt),(r.modelindex2!==e.modelindex2||n)&&(i|=It),(r.modelindex3!==e.modelindex3||n)&&(i|=Dt),(r.modelindex4!==e.modelindex4||n)&&(i|=kt),(r.frame!==e.frame||n)&&(r.frame>=256?i|=Ft:i|=Lt),(r.skinnum!==e.skinnum||n)&&(r.skinnum>=256?i|=tt:i|=Qe),(r.effects!==e.effects||n)&&(r.effects>=256?i|=et:i|=je),(r.renderfx!==e.renderfx||n)&&(r.renderfx>=256?i|=Je:i|=Ze),(r.origin.x!==e.origin.x||n)&&r.origin.x!==0&&(i|=Mt),(r.origin.y!==e.origin.y||n)&&r.origin.y!==0&&(i|=At),(r.origin.z!==e.origin.z||n)&&r.origin.z!==0&&(i|=Rt),(r.angles.x!==e.angles.x||n)&&r.angles.x!==0&&(i|=Ct),(r.angles.y!==e.angles.y||n)&&r.angles.y!==0&&(i|=Et),(r.angles.z!==e.angles.z||n)&&r.angles.z!==0&&(i|=Tt),(r.sound!==e.sound||n)&&(i|=Ut),(r.event!==e.event||n)&&(i|=Pt),(r.solid!==e.solid||n)&&(i|=zt),this.protocol!==34&&((r.alpha!==e.alpha||n)&&(i|=Lr),(r.scale!==e.scale||n)&&(i|=Cr),(r.instanceBits!==e.instanceBits||n)&&(i|=Br),(r.loopVolume!==e.loopVolume||n)&&(i|=Fr),(r.loopAttenuation!==e.loopAttenuation||n)&&(a|=wn),(r.owner!==e.owner||n)&&(a|=Mn),(r.oldFrame!==e.oldFrame||n)&&(a|=An)),a>0&&(i|=Vi),i&4278190080&&(i|=Rr),i&4294901760&&(i|=Pr),i&4294967040&&(i|=Tr),this.writer.writeByte(i&255),i&Tr&&this.writer.writeByte(i>>8&255),i&Pr&&this.writer.writeByte(i>>16&255),i&Rr&&this.writer.writeByte(i>>24&255),i&Vi&&this.writer.writeByte(a&255),r.number>=256?this.writer.writeShort(r.number):this.writer.writeByte(r.number),i&Bt&&this.writer.writeByte(r.modelindex),i&It&&this.writer.writeByte(r.modelindex2),i&Dt&&this.writer.writeByte(r.modelindex3),i&kt&&this.writer.writeByte(r.modelindex4),i&Lt&&this.writer.writeByte(r.frame),i&Ft&&this.writer.writeShort(r.frame),i&Qe&&this.writer.writeByte(r.skinnum),i&tt&&this.writer.writeShort(r.skinnum),i&je&&this.writer.writeByte(r.effects),i&et&&this.writer.writeShort(r.effects),i&Ze&&this.writer.writeByte(r.renderfx),i&Je&&this.writer.writeShort(r.renderfx),i&Mt&&this.writer.writeCoord(r.origin.x),i&At&&this.writer.writeCoord(r.origin.y),i&Rt&&this.writer.writeCoord(r.origin.z),i&Ct&&this.writer.writeAngle(r.angles.x),i&Et&&this.writer.writeAngle(r.angles.y),i&Tt&&this.writer.writeAngle(r.angles.z),i&Ut&&this.writer.writeByte(r.sound??0),i&Pt&&this.writer.writeByte(r.event??0),i&zt&&this.writer.writeShort(r.solid),this.protocol!==34&&(i&Lr&&this.writer.writeByte(r.alpha*255),i&Cr&&this.writer.writeFloat(r.scale),i&Br&&this.writer.writeLong(r.instanceBits),i&Fr&&this.writer.writeByte(r.loopVolume*255),a&wn&&this.writer.writeByte(r.loopAttenuation*255),a&Mn&&this.writer.writeShort(r.owner),a&An&&this.writer.writeShort(r.oldFrame))}};var tu=class{static validate(e,r){if(r&&!r.toLowerCase().endsWith(".dm2"))return{valid:!1,error:"Invalid file extension (expected .dm2)"};if(e.byteLength<5)return{valid:!1,error:"File too small to be a valid demo"};let n=new DataView(e),i=n.getInt32(0,!0);if(i<=0||i>e.byteLength-4)return{valid:!1,error:`Invalid first block length: ${i}`};let a=n.getUint8(4);if(a!==C.serverdata)return{valid:!1,error:`First command is not svc_serverdata (expected ${C.serverdata}, got ${a})`};let o=-1;return i>=5&&(o=n.getInt32(5,!0)),{valid:!0,version:o}}};var ru=class{constructor(e){f(this,"parser");f(this,"frames",[]);f(this,"serverData");f(this,"configStrings",new Map);f(this,"baselines",new Map);f(this,"currentEntities",new Map);if(e){let r=new ei(e.byteLength);r.append(new Uint8Array(e)),r.setReadPosition(0),this.parser=new _t(r,this)}else this.parser=new _t(new ei,this)}extractClip(e,r,n,i){let a=new wr(e.buffer),o=[],s=0,c=r.frame??-1,l=n.frame??Number.MAX_SAFE_INTEGER,u=0,d=0;for(;a.nextBlock();){let g=a.getBlock().data,b=!1,_=-1,x=!1,v={onServerData:S=>{u=S,b=!0,x=!0},onConfigString:()=>{b=!0,x=!0},onSpawnBaseline:()=>{b=!0,x=!0},onFrame:S=>{_=S.serverFrame,x=!0,_>=c&&_<=l&&(b=!0)},onCenterPrint:()=>{x=!0},onStuffText:()=>{x=!0},onPrint:()=>{x=!0},onSound:()=>{x=!0},onTempEntity:()=>{x=!0},onLayout:()=>{x=!0},onInventory:()=>{x=!0},onMuzzleFlash:()=>{x=!0},onMuzzleFlash2:()=>{x=!0},onDisconnect:()=>{x=!0},onReconnect:()=>{x=!0},onDownload:()=>{x=!0}},w=new ei(g.getLength());w.append(g.readData(g.getLength())),w.setReadPosition(0),g.seek(0);let M=new _t(w,v);u>0&&M.setProtocolVersion(u);try{M.parseMessage()}catch{}if(x||d>=c&&d<=l&&(b=!0),b){let S=new Uint8Array(4);new DataView(S.buffer).setUint32(0,g.getLength(),!0),o.push(S);let L=g.readData(g.getLength());o.push(L),s+=4+L.length}d++}let h=new Uint8Array(4);new DataView(h.buffer).setInt32(0,-1,!0),o.push(h),s+=4;let m=new Uint8Array(s),p=0;for(let y of o)m.set(y,p),p+=y.length;return m}extractDemoRange(e,r,n){return this.extractClip(e,{frame:r},{frame:n})}onServerData(e,r,n,i,a,o){this.serverData={protocol:e,serverCount:r,attractLoop:n,gameDir:i,playerNum:a,levelName:o}}onConfigString(e,r){this.configStrings.set(e,r)}onSpawnBaseline(e){this.baselines.set(e.number,e)}onFrame(e){this.frames.push(e)}onCenterPrint(e){}onStuffText(e){}onPrint(e,r){}onSound(e,r,n,i,a,o,s){}onTempEntity(e,r,n,i,a,o,s,c,l){}onLayout(e){}onInventory(e){}onMuzzleFlash(e,r){}onMuzzleFlash2(e,r){}onDisconnect(){}onReconnect(){}onDownload(e,r,n){}};function q0(t,e){let r=e.bits;t.bits=r,t.number=e.number,r&Bt&&(t.modelindex=e.modelindex),r&It&&(t.modelindex2=e.modelindex2),r&Dt&&(t.modelindex3=e.modelindex3),r&kt&&(t.modelindex4=e.modelindex4),r&Lt&&(t.frame=e.frame),r&Ft&&(t.frame=e.frame),r&Qe&&(t.skinnum=e.skinnum),r&tt&&(t.skinnum=e.skinnum),r&je&&(t.effects=e.effects),r&et&&(t.effects=e.effects),r&Ze&&(t.renderfx=e.renderfx),r&Je&&(t.renderfx=e.renderfx),r&Mt&&(t.origin.x=e.origin.x),r&At&&(t.origin.y=e.origin.y),r&Rt&&(t.origin.z=e.origin.z),r&Ct&&(t.angles.x=e.angles.x),r&Et&&(t.angles.y=e.angles.y),r&Tt&&(t.angles.z=e.angles.z),r&br&&(t.old_origin.x=e.old_origin.x,t.old_origin.y=e.old_origin.y,t.old_origin.z=e.old_origin.z),r&Ut&&(t.sound=e.sound),r&Pt&&(t.event=e.event),r&zt&&(t.solid=e.solid),r&Lr&&(t.alpha=e.alpha),r&Cr&&(t.scale=e.scale),r&Br&&(t.instanceBits=e.instanceBits),r&Fr&&(t.loopVolume=e.loopVolume)}var zf=(h=>(h.Unknown="unknown",h.BSP="bsp",h.MD2="md2",h.MD3="md3",h.WAL="wal",h.PCX="pcx",h.TGA="tga",h.WAV="wav",h.OGG="ogg",h.TXT="txt",h.CFG="cfg",h.DEM="dem",h))(zf||{}),Z0={".bsp":"bsp",".md2":"md2",".md3":"md3",".wal":"wal",".pcx":"pcx",".tga":"tga",".wav":"wav",".ogg":"ogg",".txt":"txt",".cfg":"cfg",".dm2":"dem"};function Xs(t,e){if(t.length<e.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r])return!1;return!0}var M2=[73,66,83,80],A2=[73,68,80,50],E2=[73,68,80,51];var T2=[82,73,70,70];var L2=[79,103,103,83];function Of(t,e){let r=t.slice(t.lastIndexOf(".")).toLowerCase();if(e){if(Xs(e,M2))return"bsp";if(Xs(e,A2))return"md2";if(Xs(e,E2))return"md3";if(Xs(e,L2))return"ogg";if(e.length>128&&e[0]===10&&e[1]<6)return"pcx";if(Xs(e,T2)&&e.length>=12&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69)return"wav"}return Z0[r]?Z0[r]:"unknown"}function Nf(t){let e=Of(t);return e==="txt"||e==="cfg"}function j0(t){return!Nf(t)}function P2(t,e,r,n,i){let a=new Uint8ClampedArray(n*i*4),o=e/n,s=r/i;for(let c=0;c<i;c++)for(let l=0;l<n;l++){let u=l*o,d=c*s,h=Math.floor(u),m=Math.floor(d),p=u-h,y=d-m,g=Math.min(h+1,e-1),b=Math.min(m+1,r-1),_=(m*e+h)*4,x=(m*e+g)*4,v=(b*e+h)*4,w=(b*e+g)*4,M=(c*n+l)*4;for(let S=0;S<4;S++){let E=t[_+S],L=t[x+S],A=t[v+S],R=t[w+S],D=E*(1-p)+L*p,k=A*(1-p)+R*p,F=D*(1-y)+k*y;a[M+S]=F}}return a}function R2(t,e,r,n,i,a,o,s,c,l,u){n=Math.floor(n),i=Math.floor(i),a=Math.floor(a),o=Math.floor(o);let d=Math.abs(a-n),h=Math.abs(o-i),m=n<a?1:-1,p=i<o?1:-1,y=d-h;for(;;){if(n>=0&&n<e&&i>=0&&i<r){let b=(i*e+n)*4,_=1-u/255;t[b]=s*(u/255)+t[b]*_,t[b+1]=c*(u/255)+t[b+1]*_,t[b+2]=l*(u/255)+t[b+2]*_,t[b+3]=255}if(n===a&&i===o)break;let g=2*y;g>-h&&(y-=h,n+=m),g<d&&(y+=d,i+=p)}}function Q0(t,e,r,n,i){let s=(t.x-n.x)*.707-(t.y-n.y)*.707,c=(t.x-n.x)*.707+(t.y-n.y)*.707,l=t.z-n.z,u=.866,d=.5,h=c*u-l*d,m=c*d+l*u,p=e/2+s*i,y=r/2-m*i;return{x:p,y}}var nu=class{constructor(e){this.assetManager=e}async generateTextureThumbnail(e,r){try{let n=await this.assetManager.loadTexture(e);if(!n||n.levels.length===0)return null;let i=n.levels[0],a=i.width/i.height,o=r,s=r;a>1?s=Math.floor(r/a):o=Math.floor(r*a),o=Math.max(1,o),s=Math.max(1,s);let c=P2(i.rgba,i.width,i.height,o,s);return new ImageData(c,o,s)}catch(n){return console.error(`Failed to generate thumbnail for ${e}`,n),null}}async generateModelThumbnail(e,r){try{let n=[],i=[],a=e.split(".").pop()?.toLowerCase();if(a==="md2"){let g=await this.assetManager.loadMd2Model(e);if(!g||g.frames.length===0)return null;n=g.frames[0].vertices.map(_=>_.position);for(let _ of g.triangles)i.push(_.vertexIndices[0],_.vertexIndices[1]),i.push(_.vertexIndices[1],_.vertexIndices[2]),i.push(_.vertexIndices[2],_.vertexIndices[0])}else if(a==="md3"){let g=await this.assetManager.loadMd3Model(e);if(!g||g.surfaces.length===0)return null;let b=0;for(let _ of g.surfaces){if(_.vertices.length===0)continue;let x=_.vertices[0];n.push(...x.map(v=>({x:v.position.x,y:v.position.y,z:v.position.z})));for(let v of _.triangles)i.push(b+v.indices[0],b+v.indices[1]),i.push(b+v.indices[1],b+v.indices[2]),i.push(b+v.indices[2],b+v.indices[0]);b+=x.length}}else return null;if(n.length===0)return null;let o={x:1/0,y:1/0,z:1/0},s={x:-1/0,y:-1/0,z:-1/0};for(let g of n)o.x=Math.min(o.x,g.x),o.y=Math.min(o.y,g.y),o.z=Math.min(o.z,g.z),s.x=Math.max(s.x,g.x),s.y=Math.max(s.y,g.y),s.z=Math.max(s.z,g.z);let c={x:(o.x+s.x)/2,y:(o.y+s.y)/2,z:(o.z+s.z)/2},l=s.x-o.x,u=s.y-o.y,d=s.z-o.z,h=Math.max(l,u,d),m=Math.max(h,.001),p=r*.8/m,y=new Uint8ClampedArray(r*r*4);for(let g=0;g<i.length;g+=2){let b=i[g],_=i[g+1],x=n[b],v=n[_],w=Q0(x,r,r,c,p),M=Q0(v,r,r,c,p);R2(y,r,r,w.x,w.y,M.x,M.y,0,255,0,255)}return new ImageData(y,r,r)}catch(n){return console.error(`Failed to generate model thumbnail for ${e}`,n),null}}async getMapBounds(e,r){try{let n=fo(r);if(n.models.length>0){let i=n.models[0];return{mins:{x:i.mins[0],y:i.mins[1],z:i.mins[2]},maxs:{x:i.maxs[0],y:i.maxs[1],z:i.maxs[2]}}}return null}catch(n){return console.error("Failed to get map bounds",n),null}}async extractMapScreenshot(e){return null}};var iu=class{constructor(e){this.loader=e}async getMapStatistics(e){let r=await this.loader.load(e),n=r.faces.filter(o=>o.lightOffset!==-1).length,i=r.models[0],a=i?{mins:i.mins,maxs:i.maxs}:{mins:[0,0,0],maxs:[0,0,0]};return{entityCount:r.entities.entities.length,surfaceCount:r.faces.length,lightmapCount:n,vertexCount:r.vertices.length,bounds:a}}async getUsedTextures(e){let r=await this.loader.load(e),n=new Set;for(let i of r.texInfo)i.texture&&n.add(i.texture);return Array.from(n).sort()}async getUsedModels(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities)i.properties.model&&!i.properties.model.startsWith("*")&&n.add(i.properties.model);return Array.from(n).sort()}async getUsedSounds(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities){i.properties.noise&&n.add(i.properties.noise);for(let[a,o]of Object.entries(i.properties))(a==="noise"||a.endsWith("_sound")||a==="sound")&&typeof o=="string"&&n.add(o)}return Array.from(n).sort()}};function J0(t){let e=[],r=0,n=t.length;function i(){for(;r<n&&/\s/.test(t[r]);)r++}function a(){if(i(),r>=n)return null;if(t[r]==='"'){r++;let o=r;for(;r<n&&t[r]!=='"';)t[r],r++;let s=t.substring(o,r);return r++,s}else{if(t[r]==="{"||t[r]==="}")return t[r++];{if(t.startsWith("//",r)){for(;r<n&&t[r]!==`
|
|
1161
1161
|
`;)r++;return a()}let o=r;for(;r<n&&!/\s/.test(t[r])&&t[r]!=="}"&&t[r]!=="{";)r++;return t.substring(o,r)}}}for(;r<n;){let o=a();if(o===null)break;if(o==="{"){let s={};for(;;){let c=r,l=a();if(l==="}"||l===null)break;if(l==="{"){r=c;break}let u=a();if(u===null||u==="}"||u==="{"){u==="}"&&r--,u==="{"&&r--;break}s[l]=u}e.push({classname:s.classname,properties:s})}}return e}function eg(t){let e="";for(let r of t){e+=`{
|
|
1162
1162
|
`;let i=Object.keys(r.properties).sort((a,o)=>a==="classname"?-1:o==="classname"?1:a==="origin"?-1:o==="origin"?1:a.localeCompare(o));for(let a of i){let o=r.properties[a];e+=`"${a}" "${o}"
|
|
1163
1163
|
`}e+=`}
|
|
1164
|
-
`}return e}function tg(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}}function rg(t,e,r,n="rgba8unorm"){let i=typeof GPUTextureUsage<"u"?GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC:17,a=t.createTexture({size:{width:e,height:r,depthOrArrayLayers:1},format:n,usage:i}),o=a.createView();return{texture:a,view:o,width:e,height:r}}async function ng(t,e){let r=e.width,n=e.height,i=4,a=r*i,o=256,s=Math.max(i*r,Math.ceil(r*i/o)*o),c=s*n,l=typeof GPUBufferUsage<"u"?GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ:9,u=t.createBuffer({size:c,usage:l}),d=t.createCommandEncoder();d.copyTextureToBuffer({texture:e},{buffer:u,bytesPerRow:s},{width:r,height:n,depthOrArrayLayers:1}),t.queue.submit([d.finish()]);let
|
|
1164
|
+
`}return e}function tg(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}}function rg(t,e,r,n="rgba8unorm"){let i=typeof GPUTextureUsage<"u"?GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC:17,a=t.createTexture({size:{width:e,height:r,depthOrArrayLayers:1},format:n,usage:i}),o=a.createView();return{texture:a,view:o,width:e,height:r}}async function ng(t,e){let r=e.width,n=e.height,i=4,a=r*i,o=256,s=Math.max(i*r,Math.ceil(r*i/o)*o),c=s*n,l=typeof GPUBufferUsage<"u"?GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ:9,u=t.createBuffer({size:c,usage:l}),d=t.createCommandEncoder();d.copyTextureToBuffer({texture:e},{buffer:u,bytesPerRow:s},{width:r,height:n,depthOrArrayLayers:1}),t.queue.submit([d.finish()]);let h=typeof GPUMapMode<"u"?GPUMapMode.READ:1;await u.mapAsync(h);let m=u.getMappedRange(),p=new Uint8Array(m),y=new Uint8ClampedArray(r*n*4);if(s===a)y.set(p);else for(let g=0;g<n;g++){let b=g*s,_=g*a;y.set(p.subarray(b,b+a),_)}return u.unmap(),y}var au=class{constructor(e=800,r=600){f(this,"width",0);f(this,"height",0);f(this,"collisionVis",null);f(this,"debug",null);f(this,"particleSystem",null);f(this,"frameCount",0);f(this,"callLog",[]);this.width=e,this.height=r}renderFrame(e,r=[]){this.frameCount++,this.callLog.push(`renderFrame(frame=${this.frameCount}, entities=${r.length})`);let n=e.cameraState??e.camera.toState();this.callLog.push(` camera: pos=${n.position}, angles=${n.angles}`)}async registerPic(e,r){return this.callLog.push(`registerPic(${e})`),{width:256,height:256}}registerTexture(e,r){return this.callLog.push(`registerTexture(${e})`),{width:r.width,height:r.height}}begin2D(){this.callLog.push("begin2D()")}end2D(){this.callLog.push("end2D()")}drawPic(e,r,n,i){this.callLog.push(`drawPic(${e}, ${r})`)}drawString(e,r,n,i){this.callLog.push(`drawString(${e}, ${r}, "${n}")`)}drawCenterString(e,r){this.callLog.push(`drawCenterString(${e}, "${r}")`)}drawfillRect(e,r,n,i,a){this.callLog.push(`drawfillRect(${e}, ${r}, ${n}, ${i})`)}uploadBspGeometry(e){return this.callLog.push(`uploadBspGeometry(${e.faces.length})`),{surfaces:[],lightmaps:[]}}setEntityHighlight(e,r){}clearEntityHighlight(e){}highlightSurface(e,r){}removeSurfaceHighlight(e){}setDebugMode(e){}setBrightness(e){}setGamma(e){}setFullbright(e){}setAmbient(e){}setLightStyle(e,r){}setUnderwaterWarp(e){}setBloom(e){}setBloomIntensity(e){}setLodBias(e){}renderInstanced(e,r){}getPerformanceReport(){return{frameTimeMs:0,gpuTimeMs:0,cpuFrameTimeMs:0,drawCalls:0,triangles:0,vertices:0,textureBinds:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0,memoryUsageMB:{textures:0,geometry:0,total:0}}}getMemoryUsage(){return{texturesBytes:0,geometryBytes:0,shadersBytes:0,buffersBytes:0,totalBytes:0}}dispose(){this.callLog.push("dispose()")}getCallLog(){return this.callLog}resetCallLog(){this.callLog=[]}getFrameCount(){return this.frameCount}};var ou=class{constructor(){f(this,"coordinateSystem","opengl")}buildProjectionMatrix(e){let r=I.create();return I.perspective(r,e.fov*Ee,e.aspect,e.near,e.far),r}buildViewMatrix(e){let r=I.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),[n,i,a]=e.angles,o=n*Ee,s=i*Ee,c=a*Ee,l=I.create();I.identity(l),I.rotateZ(l,l,-s),I.rotateY(l,l,-o),I.rotateX(l,l,-c);let u=I.create();I.multiply(u,r,l);let d=P.negate(P.create(),e.position),h=P.create();P.transformMat4(h,d,l);let m=P.fromValues(h[1]?-h[1]:0,h[2]||0,h[0]?-h[0]:0),p=I.clone(u);return p[12]=m[0],p[13]=m[1],p[14]=m[2],p}};var su=class{constructor(){f(this,"coordinateSystem","quake")}buildProjectionMatrix(e){let r=I.create();return I.perspective(r,e.fov*Ee,e.aspect,e.near,e.far),r}buildViewMatrix(e){let[r,n,i]=e.angles,a=r*Ee,o=n*Ee,s=i*Ee,c=I.create();I.identity(c),I.rotateZ(c,c,o),I.rotateX(c,c,a),I.rotateY(c,c,s);let l=I.create();I.fromTranslation(l,[-e.position[0],-e.position[1],-e.position[2]]);let u=I.create();return I.multiply(u,c,l),u}};function ig(t,e){let r=t.buildViewMatrix(e),n=t.buildProjectionMatrix(e),i=I.create();return I.multiply(i,n,r),{view:r,projection:n,viewProjection:i}}function ag(t){return P.fromValues(-t[1],t[2],-t[0])}function og(t){return P.fromValues(-t[1],t[2],-t[0])}var lu=class{constructor(e={}){f(this,"width",0);f(this,"height",0);f(this,"collisionVis",null);f(this,"debug",null);f(this,"particleSystem",null);f(this,"logs",[]);f(this,"builder");f(this,"options");switch(this.options={targetSystem:e.targetSystem??"quake",verbose:e.verbose??!0,validateTransforms:e.validateTransforms??!0},this.options.targetSystem){case"opengl":this.builder=new ou;break;case"webgpu":this.builder=new Oa;break;default:this.builder=new su}this.log(`LoggingRenderer initialized (target=${this.options.targetSystem})`)}renderFrame(e,r=[]){this.log(`
|
|
1165
1165
|
=== FRAME START ===`);let n=e.cameraState??e.camera.toState();this.log("Camera State:"),this.log(` Position: ${this.formatVec3(n.position)} (Quake space)`),this.log(` Angles: ${this.formatVec3(n.angles)} (degrees)`),this.log(` FOV: ${n.fov}\xB0, Aspect: ${n.aspect.toFixed(2)}`);let i=ig(this.builder,n);this.log(`Matrices (${this.options.targetSystem}):`),this.options.verbose&&(this.log(" View Matrix:"),this.logMatrix(i.view),this.log(" Projection Matrix:"),this.logMatrix(i.projection)),this.options.validateTransforms&&this.validateCoordinateTransforms(n,i.view),this.log(`Entities: ${r.length}`),this.options.verbose&&r.length>0&&(r.slice(0,5).forEach((a,o)=>{this.log(` [${o}] type=${a.type}, model=${a.model??"none"}`)}),r.length>5&&this.log(` ... and ${r.length-5} more`)),this.log(`=== FRAME END ===
|
|
1166
1166
|
`)}validateCoordinateTransforms(e,r){let n=e.position,i=ag(n),a=og(n),o=[r[12],r[13],r[14]];switch(this.log("Transform Validation:"),this.log(` Quake position: ${this.formatVec3(n)}`),this.options.targetSystem){case"opengl":this.log(` Expected GL transform: ${this.formatVec3(i)}`);break;case"webgpu":this.log(` Expected WebGPU transform: ${this.formatVec3(a)}`);break}this.log(` Matrix translation: [${o.map(l=>l.toFixed(2)).join(", ")}]`);let s=Math.abs(n[0])+Math.abs(n[1])+Math.abs(n[2]),c=Math.abs(o[0])+Math.abs(o[1])+Math.abs(o[2]);s>0&&c/s>2&&this.log(" \u26A0\uFE0F WARNING: Matrix translation seems large relative to input - possible double-transform!")}formatVec3(e){return`[${e[0].toFixed(2)}, ${e[1].toFixed(2)}, ${e[2].toFixed(2)}]`}logMatrix(e){for(let r=0;r<4;r++){let n=[e[r],e[r+4],e[r+8],e[r+12]];this.log(` [${n.map(i=>i.toFixed(4).padStart(8)).join(" ")}]`)}}log(e){this.logs.push(e),this.options.verbose&&console.log(`[LogRenderer] ${e}`)}async registerPic(e,r){return this.log(`registerPic("${e}", ${r.byteLength} bytes)`),{width:256,height:256}}registerTexture(e,r){return this.log(`registerTexture("${e}", ${r.width}x${r.height})`),{width:r.width,height:r.height}}begin2D(){this.log("begin2D()")}end2D(){this.log("end2D()")}drawPic(e,r,n,i){this.log(`drawPic(${e}, ${r})`)}drawString(e,r,n,i){this.log(`drawString(${e}, ${r}, "${n}")`)}drawCenterString(e,r){this.log(`drawCenterString(${e}, "${r}")`)}drawfillRect(e,r,n,i,a){this.log(`drawfillRect(${e}, ${r}, ${n}x${i})`)}uploadBspGeometry(e){return this.log(`uploadBspGeometry(map with ${e.faces.length} faces)`),{surfaces:[],lightmaps:[]}}setEntityHighlight(e,r){}clearEntityHighlight(e){}highlightSurface(e,r){}removeSurfaceHighlight(e){}setDebugMode(e){}setBrightness(e){}setGamma(e){}setFullbright(e){}setAmbient(e){}setLightStyle(e,r){}setUnderwaterWarp(e){}setBloom(e){}setBloomIntensity(e){}setLodBias(e){}renderInstanced(e,r){}getPerformanceReport(){return{frameTimeMs:0,gpuTimeMs:0,cpuFrameTimeMs:0,drawCalls:0,triangles:0,vertices:0,textureBinds:0,shaderSwitches:0,visibleSurfaces:0,culledSurfaces:0,visibleEntities:0,culledEntities:0,memoryUsageMB:{textures:0,geometry:0,total:0}}}getMemoryUsage(){return{texturesBytes:0,geometryBytes:0,shadersBytes:0,buffersBytes:0,totalBytes:0}}dispose(){this.log("dispose()")}getLogs(){return this.logs}resetLogs(){this.logs=[]}printLogs(){console.log(this.logs.join(`
|
|
1167
|
-
`))}};var Gf=(o=>(o[o.Disconnected=0]="Disconnected",o[o.Connecting=1]="Connecting",o[o.Challenge=2]="Challenge",o[o.Connected=3]="Connected",o[o.Loading=4]="Loading",o[o.Active=5]="Active",o))(Gf||{}),cu=class{constructor(e){
|
|
1167
|
+
`))}};var Gf=(o=>(o[o.Disconnected=0]="Disconnected",o[o.Connecting=1]="Connecting",o[o.Challenge=2]="Challenge",o[o.Connected=3]="Connected",o[o.Loading=4]="Loading",o[o.Active=5]="Active",o))(Gf||{}),cu=class{constructor(e){f(this,"state",0);f(this,"netchan");f(this,"parser",null);f(this,"options");f(this,"listeners",{});f(this,"serverProtocol",0);f(this,"serverCount",0);f(this,"gameDir","");f(this,"playerNum",0);f(this,"levelName","");f(this,"configStrings",new Map);f(this,"baselines",new Map);f(this,"entities",new Map);f(this,"latestServerFrame",0);f(this,"frameCRCs",new Map);f(this,"currentPacketCRC",0);f(this,"commandHistory",[]);this.options=e,this.netchan=e.netchan??new ch}on(e,r){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(r)}off(e,r){this.listeners[e]&&(this.listeners[e]=this.listeners[e].filter(n=>n!==r))}emit(e,...r){this.listeners[e]&&this.listeners[e].forEach(n=>n(...r))}connect(){this.netchan.reset(),this.cleanup(),this.setState(1)}startProtocol(){this.state!==1&&this.connect(),this.setState(2),this.sendChallenge()}disconnect(){this.state!==0&&(this.setState(0),this.emit("disconnect"),this.cleanup())}cleanup(){this.configStrings.clear(),this.baselines.clear(),this.entities.clear(),this.commandHistory=[],this.latestServerFrame=0,this.parser=null,this.frameCRCs.clear()}getState(){return this.state}setState(e){this.state!==e&&(this.state=e,this.emit("state",e))}handleMessage(e){let r=this.netchan.process(new Uint8Array(e));if(!r||r.byteLength===0)return;this.currentPacketCRC=lh(r);let n=new En(r.buffer);this.parser=new _t(n,this),this.serverProtocol&&this.parser.setProtocolVersion(this.serverProtocol),this.parser.parseMessage()}sendUserCommand(e){if(this.state!==5)return;let r={...e,serverFrame:e.serverFrame??this.latestServerFrame};this.commandHistory.push(r),this.commandHistory.length>oh&&this.commandHistory.shift();let n=new li;n.writeByte(oi.move);let i=this.frameCRCs.get(this.latestServerFrame)||0;n.writeByte(i),n.writeLong(this.latestServerFrame),sh(n,r),this.transmit(n.getData())}transmit(e){let r=this.netchan.transmit(e);this.emit("send",r)}sendChallenge(){let e=new oo;e.writeByte(oi.stringcmd),e.writeString("getchallenge"),this.transmit(e.getData())}sendConnect(e){let r=new oo;r.writeByte(oi.stringcmd);let n=`\\name\\${this.options.username}\\model\\${this.options.model}\\skin\\${this.options.skin}\\hand\\${this.options.hand??0}\\fov\\${this.options.fov??90}`;r.writeString(`connect ${Yr} ${e} ${n}`),this.transmit(r.getData())}sendNew(){let e=new oo;e.writeByte(oi.stringcmd),e.writeString("new"),this.transmit(e.getData())}sendBegin(){let e=new oo;e.writeByte(oi.stringcmd),e.writeString("begin"),this.transmit(e.getData())}onServerData(e,r,n,i,a,o){this.serverProtocol=e,this.serverCount=r,this.gameDir=i,this.playerNum=a,this.levelName=o,this.setState(3),this.emit("serverdata",{protocol:e,serverCount:r,gameDir:i,levelName:o}),this.sendNew(),this.setState(4)}onConfigString(e,r){this.configStrings.set(e,r)}onSpawnBaseline(e){this.baselines.set(e.number,e)}onStuffText(e){if(this.emit("stufftext",e),e.startsWith("precache")&&(this.sendBegin(),this.setState(5)),e.startsWith("challenge ")){let r=e.split(" ");if(r.length>1){let n=parseInt(r[1],10);this.sendConnect(n)}}}onFrame(e){e.serverFrame>this.latestServerFrame&&(this.latestServerFrame=e.serverFrame),this.frameCRCs.set(e.serverFrame,this.currentPacketCRC);let r=e.packetEntities;r.delta||this.entities.clear();for(let n of r.entities)this.entities.set(n.number,n);this.emit("frame",e)}onDisconnect(){this.disconnect()}onPrint(e,r){this.emit("print",r,e)}onCenterPrint(e){this.emit("centerprint",e)}onSound(e,r,n,i,a,o,s){this.emit("sound",{flags:e,soundNum:r,volume:n,attenuation:i,offset:a,ent:o,pos:s})}onTempEntity(e,r,n,i,a,o,s,c,l){this.emit("temp_entity",{type:e,pos:r,pos2:n,dir:i,cnt:a,color:o,ent:s})}onInventory(e){this.emit("inventory",e)}onMuzzleFlash(e,r){this.emit("muzzleflash",e,r)}onMuzzleFlash2(e,r){}onMuzzleFlash3(e,r){this.emit("muzzleflash",e,r)}onDownload(e,r,n){this.emit("download",e,r,n)}onReconnect(){}onLayout(e){}onSplitClient(e){}onConfigBlast(e,r){}onSpawnBaselineBlast(e){}onLevelRestart(){}onDamage(e){}onLocPrint(e,r,n){}onFog(e){}onWaitingForPlayers(e){}onBotChat(e){}onPoi(e,r){}onHelpPath(e){}onAchievement(e){}};function C2(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new ii(e,r)},setAreaPortalState(e,r){t.renderer&&t.renderer.setAreaPortalState&&t.renderer.setAreaPortalState(e,r)}}}return vg(B2);})();
|
|
1168
1168
|
/*! Bundled license information:
|
|
1169
1169
|
|
|
1170
1170
|
pako/dist/pako.esm.mjs:
|