quake2ts 0.0.89 → 0.0.90

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.
Files changed (45) hide show
  1. package/package.json +1 -1
  2. package/packages/client/dist/browser/index.global.js +1 -1
  3. package/packages/client/dist/browser/index.global.js.map +1 -1
  4. package/packages/client/dist/cjs/index.cjs +121 -10
  5. package/packages/client/dist/cjs/index.cjs.map +1 -1
  6. package/packages/client/dist/esm/index.js +121 -10
  7. package/packages/client/dist/esm/index.js.map +1 -1
  8. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  9. package/packages/client/dist/types/hud/icons.d.ts +3 -2
  10. package/packages/client/dist/types/hud/icons.d.ts.map +1 -1
  11. package/packages/client/dist/types/hud/messages.d.ts +10 -0
  12. package/packages/client/dist/types/hud/messages.d.ts.map +1 -0
  13. package/packages/client/dist/types/hud/numbers.d.ts +1 -1
  14. package/packages/client/dist/types/hud/numbers.d.ts.map +1 -1
  15. package/packages/client/dist/types/hud.d.ts +2 -1
  16. package/packages/client/dist/types/hud.d.ts.map +1 -1
  17. package/packages/client/dist/types/index.d.ts +2 -0
  18. package/packages/client/dist/types/index.d.ts.map +1 -1
  19. package/packages/engine/dist/browser/index.global.js +8 -8
  20. package/packages/engine/dist/browser/index.global.js.map +1 -1
  21. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  22. package/packages/engine/dist/esm/index.js.map +1 -1
  23. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  24. package/packages/engine/dist/types/render/renderer.d.ts +1 -1
  25. package/packages/engine/dist/types/render/renderer.d.ts.map +1 -1
  26. package/packages/game/dist/browser/index.global.js +1 -1
  27. package/packages/game/dist/browser/index.global.js.map +1 -1
  28. package/packages/game/dist/cjs/index.cjs +2687 -2640
  29. package/packages/game/dist/cjs/index.cjs.map +1 -1
  30. package/packages/game/dist/esm/index.js +2687 -2640
  31. package/packages/game/dist/esm/index.js.map +1 -1
  32. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
  33. package/packages/game/dist/types/entities/system.d.ts.map +1 -1
  34. package/packages/game/dist/types/physics/movement.d.ts +1 -0
  35. package/packages/game/dist/types/physics/movement.d.ts.map +1 -1
  36. package/packages/shared/dist/browser/index.global.js +1 -1
  37. package/packages/shared/dist/browser/index.global.js.map +1 -1
  38. package/packages/shared/dist/cjs/index.cjs +22 -0
  39. package/packages/shared/dist/cjs/index.cjs.map +1 -1
  40. package/packages/shared/dist/esm/index.js +19 -0
  41. package/packages/shared/dist/esm/index.js.map +1 -1
  42. package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
  43. package/packages/shared/dist/types/bsp/collision.d.ts +8 -0
  44. package/packages/shared/dist/types/bsp/collision.d.ts.map +1 -1
  45. package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,7 @@
1
- "use strict";var Quake2Engine=(()=>{var ml=Object.create;var es=Object.defineProperty;var fl=Object.getOwnPropertyDescriptor;var hl=Object.getOwnPropertyNames;var pl=Object.getPrototypeOf,yl=Object.prototype.hasOwnProperty;var gl=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ho=(t,e)=>{for(var r in e)es(t,r,{get:e[r],enumerable:!0})},aa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of hl(e))!yl.call(t,s)&&s!==r&&es(t,s,{get:()=>e[s],enumerable:!(n=fl(e,s))||n.enumerable});return t};var xl=(t,e,r)=>(r=t!=null?ml(pl(t)):{},aa(e||!t||!t.__esModule?es(r,"default",{value:t,enumerable:!0}):r,t)),bl=t=>aa(es({},"__esModule",{value:!0}),t);var Wa=gl((Pf,Ga)=>{"use strict";Ga.exports=Worker});var mm={};Ho(mm,{ATTN_IDLE:()=>Sc,ATTN_LOOP_NONE:()=>bc,ATTN_NONE:()=>Qs,ATTN_NORM:()=>vc,ATTN_STATIC:()=>Mc,AssetDependencyError:()=>Qt,AssetDependencyTracker:()=>Nn,AssetManager:()=>$s,AudioApi:()=>co,AudioContextController:()=>Zs,AudioRegistry:()=>Pr,AudioRegistryError:()=>kn,AudioSystem:()=>io,BSP_SURFACE_FRAGMENT_SOURCE:()=>Ri,BSP_SURFACE_VERTEX_SOURCE:()=>Ti,BSP_VERTEX_LAYOUT:()=>zi,BspLoader:()=>us,BspParseError:()=>Y,BspSurfacePipeline:()=>mo,Camera:()=>go,ConfigStringRegistry:()=>or,Cvar:()=>Hr,CvarRegistry:()=>as,DemoPlaybackController:()=>$n,DemoReader:()=>Zt,EngineHost:()=>nr,EngineRuntime:()=>Nr,FixedTimestepLoop:()=>Rt,Framebuffer:()=>lo,IndexBuffer:()=>Ne,LruCache:()=>ht,MAX_SOUND_CHANNELS:()=>Li,MD2_FRAGMENT_SHADER:()=>Ui,MD2_VERTEX_SHADER:()=>Hi,MD3_FRAGMENT_SHADER:()=>ji,MD3_VERTEX_SHADER:()=>$i,Md2Loader:()=>ar,Md2MeshBuffers:()=>ho,Md2ParseError:()=>le,Md2Pipeline:()=>po,Md3Loader:()=>cr,Md3ModelMesh:()=>xo,Md3ParseError:()=>Ce,Md3Pipeline:()=>bo,Md3SurfaceMesh:()=>Vn,MusicSystem:()=>ao,NetworkMessageParser:()=>tr,PARTICLE_FRAGMENT_SHADER:()=>Ji,PARTICLE_VERTEX_SHADER:()=>Qi,PakArchive:()=>ir,PakIndexStore:()=>qs,PakIngestionError:()=>ft,PakParseError:()=>Fe,PakValidationError:()=>Bt,PakValidator:()=>ls,ParticleRenderer:()=>So,ParticleSystem:()=>vo,PlaybackState:()=>No,RERELEASE_KNOWN_PAKS:()=>Jo,SKYBOX_FRAGMENT_SHADER:()=>Di,SKYBOX_VERTEX_SHADER:()=>Oi,SOUND_FULLVOLUME:()=>Ir,SOUND_LOOP_ATTENUATE:()=>Ac,ShaderProgram:()=>be,SkyboxPipeline:()=>fo,SoundChannel:()=>js,SoundPrecache:()=>ro,SoundRegistry:()=>to,SpriteLoader:()=>lr,SpriteParseError:()=>pt,Texture2D:()=>zr,TextureCache:()=>dr,TextureCubeMap:()=>Fr,U_ANGLE1:()=>zo,U_ANGLE2:()=>wo,U_ANGLE3:()=>Lo,U_EFFECTS16:()=>Yn,U_EFFECTS8:()=>Wn,U_EVENT:()=>Po,U_FRAME16:()=>Co,U_FRAME8:()=>Eo,U_MODEL:()=>Fo,U_MODEL2:()=>To,U_MODEL3:()=>Ro,U_MODEL4:()=>Bo,U_OLDORIGIN:()=>ko,U_ORIGIN1:()=>Ao,U_ORIGIN2:()=>_o,U_ORIGIN3:()=>Io,U_REMOVE:()=>Zi,U_RENDERFX16:()=>Kn,U_RENDERFX8:()=>Gn,U_SKIN16:()=>qn,U_SKIN8:()=>Xn,U_SOLID:()=>Do,U_SOUND:()=>Oo,VertexArray:()=>_e,VertexBuffer:()=>ve,VirtualFileSystem:()=>cs,advanceAnimation:()=>ka,applySurfaceState:()=>kc,attenuationToDistanceMultiplier:()=>Jt,boxIntersectsFrustum:()=>Un,buildBspGeometry:()=>Ic,buildMd2Geometry:()=>Vi,buildMd2VertexData:()=>Gi,buildMd3SurfaceGeometry:()=>Yi,buildMd3VertexData:()=>qi,calculateMaxAudibleDistance:()=>Js,calculatePakChecksum:()=>_a,computeFrameBlend:()=>Oa,computeSkyScroll:()=>Nc,createAnimationState:()=>Da,createAudioGraph:()=>eo,createBspSurfaces:()=>Pc,createEmptyEntityState:()=>er,createEmptyProtocolPlayerState:()=>Mo,createEngine:()=>um,createEngineRuntime:()=>Ma,createFaceLightmap:()=>ms,createInitialChannels:()=>no,createProgramFromSources:()=>Ec,createWebGLContext:()=>wc,decodeOgg:()=>Ys,deriveSurfaceRenderState:()=>ki,extractFrustumPlanes:()=>zc,filesToPakSources:()=>Zo,findLeafForPoint:()=>Ci,gatherVisibleFaces:()=>Rc,groupMd2Animations:()=>Ca,ingestPakFiles:()=>wa,ingestPaks:()=>ds,interpolateMd3Tag:()=>nl,interpolateVec3:()=>Na,parseBsp:()=>ei,parseMd2:()=>ti,parseMd3:()=>ri,parsePcx:()=>Ha,parseSprite:()=>ni,parseWal:()=>hs,parseWalTexture:()=>Va,parseWav:()=>ys,pcxToRgba:()=>ps,pickChannel:()=>so,preparePcxTexture:()=>Ua,removeViewTranslation:()=>Dc,resolveLightStyles:()=>Bi,spatializeOrigin:()=>oo,spawnBlood:()=>il,spawnBulletImpact:()=>sl,spawnExplosion:()=>ol,spawnMuzzleFlash:()=>cl,spawnTeleportFlash:()=>al,spawnTrail:()=>ll,walToRgba:()=>si,wireDropTarget:()=>La,wireFileInput:()=>Ea});var vl=()=>typeof performance<"u"?performance.now():Date.now(),Sl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Rt=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,s=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:s,maxDeltaMs:r.maxDeltaMs??n*s,startTimeMs:r.startTimeMs,now:r.now??vl,schedule:r.schedule??Sl}}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 s=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&s<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,s+=1;let o=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:o,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var nr=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let s=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??s,this.loop=new Rt({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs})}start(){this.started||(this.latestFrame=this.game.init(this.startTimeMs)??this.latestFrame,this.client?.init(this.latestFrame),this.started=!0,this.loop.start())}stop(){this.started&&(this.loop.stop(),this.client?.shutdown(),this.game.shutdown(),this.previousFrame=void 0,this.latestFrame=void 0,this.started=!1)}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};var Ml=Object.defineProperty,Al=(t,e)=>{for(var r in e)Ml(t,r,{get:e[r],enumerable:!0})},ca={x:0,y:0,z:0};var gm=Math.PI/180;function la(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function _l(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function Vo(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function wl(t){return Vo(t,t)}function Go(t){return Math.sqrt(wl(t))}function Ue(t){let e=Go(t);return e===0?t:_l(t,1/e)}var Ll=Math.PI/180,xm=180/Math.PI,sr=Ll;function El(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function da(t,e){let r=e.x,n=e.y,s=e.z;return{x:t[0]*r+t[4]*n+t[8]*s+t[12],y:t[1]*r+t[5]*n+t[9]*s+t[13],z:t[2]*r+t[6]*n+t[10]*s+t[14]}}function ua(t,e){let r=El();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var Ke=1,mt=2;var Wo=8,Xo=16,Pl=32;var Il=16384;var ts=65536,ma=1<<17,zl=1<<18,Fl=1<<19,Cl=1<<20,Tl=1<<21,Rl=1<<22,Bl=1<<23,bm=1<<24,rs=1<<25,kl=1<<26,vm=1<<27,Sm=1<<28,Mm=1<<29,ns=1<<30,Am=1<<31;var Dr=0;var fa=4,ha=8,pa=16,ya=32,ga=64;var _m=1<<25,wm=1<<28,Lm=1<<29,Em=1<<30,Pm=1<<31;var Im=Ke|mt,zm=Ke|ts|mt|rs|ns,Fm=Ke|ts|mt,Cm=Ke|ma|mt|rs|ns,Tm=Pl|Wo|Xo,Rm=Ke|Xo|Wo,Ol=Ke|rs|ns|mt|kl,Bm=zl|Fl|Cl|Tl|Rl|Bl,km=Ke|Wo|Xo|rs|ns,Om=Ke|ts|mt,Dm=Ke|mt,Nm=Ke|ts|mt|ma,Hm=Ol|Il;var Um=Number.MAX_SAFE_INTEGER-1;var ss=(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))(ss||{});var os=256;var Ko=256,Yo=8192,is=2048,qo=512,$o=256,jo=os*2,Qo=256,Uo=32,Or=96;var K=(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.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+Yo]="Sounds",t[t.Images=t.Sounds+is]="Images",t[t.Lights=t.Images+qo]="Lights",t[t.ShadowLights=t.Lights+Ko]="ShadowLights",t[t.Items=t.ShadowLights+Qo]="Items",t[t.PlayerSkins=t.Items+$o]="PlayerSkins",t[t.General=t.PlayerSkins+os]="General",t[t.WheelWeapons=t.General+jo]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+Uo]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+Uo]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+Uo]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(K||{}),xa=K.MaxConfigStrings;function ba(t){return t>=5&&t<59?Or*(59-t):t>=K.General&&t<K.WheelWeapons?Or*(K.MaxConfigStrings-t):Or}var Dl={};Al(Dl,{addReplayFrame:()=>Vl,createReplaySession:()=>Ul,deserializeReplay:()=>Hl,serializeReplay:()=>Nl});function Nl(t){return JSON.stringify(t,null,2)}function Hl(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 Ul(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function Vl(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var j=(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))(j||{});var E=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t))(E||{});var va=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}hasMore(){return this.offset<this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){if(this.readByte()>=162){t.x=0,t.y=0,t.z=0;return}t.x=0,t.y=0,t.z=0}};function Gl(t){if(t<0||t>=K.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${K.MaxConfigStrings-1})`)}function Sa(t,e){let r=ba(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${Or} chars per slot`)}var or=class{constructor(){this.values=new Map;this.modelCursor=K.Models;this.soundCursor=K.Sounds;this.imageCursor=K.Images;this.lightCursor=K.Lights;this.shadowLightCursor=K.ShadowLights;this.itemCursor=K.Items;this.playerSkinCursor=K.PlayerSkins;this.generalCursor=K.General}set(e,r){return Gl(e),Sa(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getAll(){let e=new Array(xa).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,K.Models,Yo,"modelCursor")}soundIndex(e){return this.register(e,K.Sounds,is,"soundCursor")}findSoundIndex(e){for(let r=K.Sounds;r<K.Sounds+is;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,K.Images,qo,"imageCursor")}lightIndex(e){return this.register(e,K.Lights,Ko,"lightCursor")}shadowLightIndex(e){return this.register(e,K.ShadowLights,Qo,"shadowLightCursor")}itemIndex(e){return this.register(e,K.Items,$o,"itemCursor")}playerSkinIndex(e){return this.register(e,K.PlayerSkins,os,"playerSkinCursor")}generalIndex(e){return this.register(e,K.General,jo,"generalCursor")}register(e,r,n,s){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===e)return a;let o=this[s],i=r+n;if(o>=i)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return Sa(o,e),this.values.set(o,e),this[s]=o+1,o}};var Nr=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Ma(t,e,r,n){return new Nr(t,new nr(e,r,n))}var Hr=class{constructor({name:e,defaultValue:r,description:n,flags:s=ss.None,onChange:o}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=s,this._value=r,this.onChange=o}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(e){if(this.flags&ss.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)}},as=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=new Hr(e);return this.cvars.set(e.name,n),n}get(e){return this.cvars.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Wl="PACK";function Xl(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function se(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Kl(){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 Yl=Kl();function Aa(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Yl[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Fe=class extends Error{},ir=class t{constructor(e,r,n,s){this.name=e;this.buffer=r;this.entries=new Map(n.map(o=>[o.name,o])),this.checksum=s,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Fe("PAK buffer too small to contain header");let s=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(s!==Wl)throw new Fe(`Invalid PAK header magic: ${s}`);let o=n.getInt32(4,!0),i=n.getInt32(8,!0);if(o<12)throw new Fe(`Invalid directory offset: ${o}`);if(i<=0||i%64!==0)throw new Fe(`Invalid directory length: ${i}`);if(o+i>r.byteLength)throw new Fe("Directory exceeds buffer length");let c=i/64,l=[],d=new Map;for(let u=0;u<c;u+=1){let m=o+u*64,f=Xl(n,m,56),p=se(f),y=n.getInt32(m+56,!0),h=n.getInt32(m+60,!0);if(y<0||h<0||y+h>r.byteLength)throw new Fe(`Invalid entry bounds for ${f||"<unnamed>"} (offset=${y}, length=${h})`);if(!p)throw new Fe(`Entry ${u} has an empty name`);let g={name:p,offset:y,length:h};d.set(p,g)}return l.push(...d.values()),new t(e,r,l,Aa(new Uint8Array(r)))}getEntry(e){return this.entries.get(se(e))}listEntries(){return Array.from(this.entries.values())}readFile(e){let r=this.getEntry(e);if(!r)throw new Fe(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function _a(t){return Aa(new Uint8Array(t))}var cs=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e){this.mounts.push(e);for(let r of e.listEntries()){let n=se(r.name);this.files.set(n,{archive:e,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(se(e))}stat(e){let r=this.files.get(se(e));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}async readFile(e){let r=this.files.get(se(e));if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}list(e=""){let r=se(e).replace(/\/+$|^\//g,""),n=[],s=new Set,o=r?`${r}/`:"";for(let i of this.files.values()){if(r&&!i.entry.name.startsWith(o))continue;let a=r?i.entry.name.slice(o.length):i.entry.name,c=a.indexOf("/");c===-1?n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name}):s.add(a.slice(0,c))}return n.sort((i,a)=>i.path.localeCompare(a.path)),{files:n,directories:[...s].sort()}}findByExtension(e){let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let s of this.files.values())s.entry.name.toLowerCase().endsWith(r)&&n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name});return n.sort((s,o)=>s.path.localeCompare(o.path))}};var Jo=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"}]),Bt=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"}},ls=class{constructor(e=Jo){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")),s=e.checksum,o="size"in e?e.size:void 0,i=this.known.get(n);return i?i.checksum!==s?{name:n,checksum:s,expectedChecksum:i.checksum,status:"mismatch",size:o,description:i.description}:{name:n,checksum:s,expectedChecksum:i.checksum,status:"valid",size:o,description:i.description}:{name:n,checksum:s,status:"unknown",size:o}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Bt(n);return n}normalizePakName(e){let r=se(e),n=r.split("/"),s=n.pop()??r,o=n.pop();return o?`${s}@${o}`:s}};var ft=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 ql(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 s=new FileReader;s.onerror=()=>n(s.error??new Error("Unknown FileReader error")),s.onprogress=o=>{e?.({file:"blob",loadedBytes:o.loaded,totalBytes:o.total||t.size,state:"reading"})},s.onload=()=>{let o=s.result;o instanceof ArrayBuffer?r(o):n(new Error("Unexpected FileReader result"))},s.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=[],s=0;for(;;){let{done:a,value:c}=await r.read();if(a)break;if(!c)continue;let l=c;n.push(l),s+=l.byteLength,e?.({file:"blob",loadedBytes:s,totalBytes:t.size,state:"reading"})}let o=new Uint8Array(s),i=0;for(let a of n)o.set(a,i),i+=a.byteLength;return o.buffer}throw new ft("blob",new Error("Unsupported Blob type"))}async function $l(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 ql(t.data,s=>e?.({...s,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 ds(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},s=n.persistIndexes??!!n.pakIndexStore,o=n.enforceValidation??!!n.validator,i=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let d=await $l(l,n.onProgress),u=ir.fromArrayBuffer(l.name,d),m=n.validator?.validateArchive(u);if(m){n.onValidationResult?.(m);let f=m.status==="mismatch",p=m.status==="unknown";if(f&&o||p&&!i){let y=new Bt(m);if(n.onError?.(l.name,y),a)throw new ft(l.name,y);c.push({archive:u,mounted:!1,validation:m});continue}}if(t.mountPak(u),s&&n.pakIndexStore)try{await n.pakIndexStore.persist(u)}catch(f){if(n.onError?.(l.name,f),a)throw new ft(l.name,f)}n.onProgress?.({file:l.name,loadedBytes:d.byteLength,totalBytes:d.byteLength,state:"parsed"}),c.push({archive:u,mounted:!0,validation:m})}catch(d){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,d),a)throw new ft(l.name,d)}return c}var ht=class{constructor(e){this.capacity=e;this.map=new Map;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}};function jl(t){return Array.isArray(t)?t:Array.from(t)}function Zo(t){return jl(t).map(e=>({name:e.name,data:e}))}async function wa(t,e,r){let n=Zo(e);return ds(t,n,r??{})}function La(t,e){let r=s=>{s.preventDefault(),s.dataTransfer?.dropEffect&&(s.dataTransfer.dropEffect="copy")},n=s=>{s.preventDefault();let o=s.dataTransfer?.files;o&&o.length>0&&e(Array.from(o))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Ea(t,e){let r=n=>{let s=n.target;!s||!s.files||s.files.length===0||(e(s.files),s.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var Ql="IBSP",Jl=38,Ia=19,Zl=8+Ia*8;var Y=class extends Error{},us=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),ei(n.buffer)}};function ei(t){if(t.byteLength<Zl)throw new Y("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!==Ql)throw new Y(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Jl)throw new Y(`Unsupported BSP version ${n}`);let s=new Map;for(let A=0;A<Ia;A+=1){let _=e.getInt32(8+A*8,!0),L=e.getInt32(12+A*8,!0);if(_<0||L<0||_+L>t.byteLength)throw new Y(`Invalid lump bounds for index ${A}`);s.set(A,{offset:_,length:L})}let o={version:n,lumps:s},i=ed(t,s.get(0)),a=rd(t,s.get(1)),c=nd(t,s.get(2)),l=sd(t,s.get(4)),d=od(t,s.get(5)),u=id(t,s.get(6)),m=new Uint8Array(t,s.get(7).offset,s.get(7).length),f=pd(u,s.get(7)),p=ad(t,s.get(8)),y=cd(t,s.get(11)),h=ld(t,s.get(12)),g=dd(t,s.get(13)),S=ud(t,s.get(14)),b=md(t,s.get(15)),M=fd(t,s.get(9),s.get(10),p),v=hd(t,s.get(3));return{header:o,entities:i,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:m,lightMapInfo:f,leafs:p,leafLists:M,edges:y,surfEdges:h,models:g,brushes:S,brushSides:b,visibility:v}}function ed(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=td(r),s=n.find(o=>o.classname==="worldspawn");return{raw:r,entities:n,worldspawn:s}}function td(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let s=n[1],o={},i=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=i.exec(s))!==null;)o[a[1]]=a[2];e.push({classname:o.classname,properties:o})}return e}function rd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new Y("Plane lump has invalid length");let s=[];for(let o=0;o<n;o+=1){let i=[r.getFloat32(o*20,!0),r.getFloat32(o*20+4,!0),r.getFloat32(o*20+8,!0)],a=r.getFloat32(o*20+12,!0),c=r.getInt32(o*20+16,!0);s.push({normal:i,dist:a,type:c})}return s}function nd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new Y("Vertex lump has invalid length");let s=[];for(let o=0;o<n;o+=1)s.push([r.getFloat32(o*12,!0),r.getFloat32(o*12+4,!0),r.getFloat32(o*12+8,!0)]);return s}function sd(t,e){let r=new DataView(t,e.offset,e.length),n=36,s=e.length/n;if(s%1!==0)throw new Y("Node lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],d=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],u=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],m=r.getUint16(a+24,!0),f=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:m,numFaces:f})}return o}function od(t,e){let r=new DataView(t,e.offset,e.length),n=76,s=e.length/n;if(s%1!==0)throw new Y("TexInfo lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),d=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],u=r.getFloat32(a+28,!0),m=r.getInt32(a+32,!0),f=r.getInt32(a+36,!0),p=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),h=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:m,value:f,texture:y,nextTexInfo:h})}return o}function id(t,e){let r=new DataView(t,e.offset,e.length),n=20,s=e.length/n;if(s%1!==0)throw new Y("Face lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getUint16(a,!0),l=r.getInt16(a+2,!0),d=r.getInt32(a+4,!0),u=r.getInt16(a+8,!0),m=r.getInt16(a+10,!0),f=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],p=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:m,styles:f,lightOffset:p})}return o}function ad(t,e){let r=new DataView(t,e.offset,e.length),n=28,s=e.length/n;if(s%1!==0)throw new Y("Leaf lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getInt32(a,!0),l=r.getInt16(a+4,!0),d=r.getInt16(a+6,!0),u=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],m=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],f=r.getUint16(a+20,!0),p=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),h=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:m,firstLeafFace:f,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:h})}return o}function cd(t,e){let r=new DataView(t,e.offset,e.length),n=4,s=e.length/n;if(s%1!==0)throw new Y("Edge lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return o}function ld(t,e){let r=e.length/4;if(r%1!==0)throw new Y("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),s=new Int32Array(r);for(let o=0;o<r;o+=1)s[o]=n.getInt32(o*4,!0);return s}function dd(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new Y("Model lump has invalid length");let s=e.length/n,o=[];for(let i=0;i<s;i+=1){let a=i*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),m=r.getInt32(a+40,!0),f=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:m,numFaces:f})}return o}function ud(t,e){let r=new DataView(t,e.offset,e.length),n=12,s=e.length/n;if(s%1!==0)throw new Y("Brush lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return o}function md(t,e){let r=new DataView(t,e.offset,e.length),n=8,s=e.length/n;if(s%1!==0)throw new Y("Brush side lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return o}function fd(t,e,r,n){let s=[],o=[],i=e.length/2,a=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let d of n){if(d.firstLeafFace+d.numLeafFaces>i)throw new Y("Leaf faces reference data past lump bounds");if(d.firstLeafBrush+d.numLeafBrushes>a)throw new Y("Leaf brushes reference data past lump bounds");let u=[];for(let f=0;f<d.numLeafFaces;f+=1)u.push(c.getUint16((d.firstLeafFace+f)*2,!0));let m=[];for(let f=0;f<d.numLeafBrushes;f+=1)m.push(l.getUint16((d.firstLeafBrush+f)*2,!0));s.push(u),o.push(m)}return{leafFaces:s,leafBrushes:o}}function hd(t,e){if(e.length===0)return;if(e.length<4)throw new Y("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),s=4+n*8;if(n<0||s>e.length)throw new Y("Visibility lump truncated");let o=4,i=[];for(let a=0;a<n;a+=1){let c=r.getInt32(o,!0),l=r.getInt32(o+4,!0);o+=8;let d=e.offset+c,u=e.offset+l,m=e.offset+e.length;if(c<0||l<0||d>=m||u>=m)throw new Y("Visibility offsets out of range");i.push({pvs:Pa(t,d,n,e),phs:Pa(t,u,n,e)})}return{numClusters:n,clusters:i}}function Pa(t,e,r,n){let s=Math.ceil(r/8),o=new Uint8Array(s),i=new Uint8Array(t),a=e,c=0,l=n.offset+n.length;for(;c<s;){if(a>=l)throw new Y("Visibility data truncated");let d=i[a++];if(d!==0){o[c++]=d;continue}if(a>=l)throw new Y("Visibility run exceeds lump bounds");let u=i[a++];for(let m=0;m<u&&c<s;m+=1)o[c++]=0}return o}function pd(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function ms(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,s=Math.min(r?.length??n,n);if(!(s<=0))return e.subarray(t.lightOffset,t.lightOffset+s)}var yd=844121161,gd=8,za=68,xd=[{x:-.525731,y:0,z:.850651},{x:-.442863,y:.238856,z:.864188},{x:-.295242,y:0,z:.955423},{x:-.309017,y:.5,z:.809017},{x:-.16246,y:.262866,z:.951056},{x:0,y:0,z:1},{x:0,y:.850651,z:.525731},{x:-.147621,y:.716567,z:.681718},{x:.147621,y:.716567,z:.681718},{x:0,y:.525731,z:.850651},{x:.309017,y:.5,z:.809017},{x:.525731,y:0,z:.850651},{x:.295242,y:0,z:.955423},{x:.442863,y:.238856,z:.864188},{x:.16246,y:.262866,z:.951056},{x:-.681718,y:.147621,z:.716567},{x:-.809017,y:.309017,z:.5},{x:-.587785,y:.425325,z:.688191},{x:-.850651,y:.525731,z:0},{x:-.864188,y:.442863,z:.238856},{x:-.716567,y:.681718,z:.147621},{x:-.688191,y:.587785,z:.425325},{x:-.5,y:.809017,z:.309017},{x:-.238856,y:.864188,z:.442863},{x:-.425325,y:.688191,z:.587785},{x:-.716567,y:.681718,z:-.147621},{x:-.5,y:.809017,z:-.309017},{x:-.525731,y:.850651,z:0},{x:0,y:.850651,z:-.525731},{x:-.238856,y:.864188,z:-.442863},{x:0,y:.955423,z:-.295242},{x:-.262866,y:.951056,z:-.16246},{x:0,y:1,z:0},{x:0,y:.955423,z:.295242},{x:-.262866,y:.951056,z:.16246},{x:.238856,y:.864188,z:.442863},{x:.262866,y:.951056,z:.16246},{x:.5,y:.809017,z:.309017},{x:.238856,y:.864188,z:-.442863},{x:.262866,y:.951056,z:-.16246},{x:.5,y:.809017,z:-.309017},{x:.850651,y:.525731,z:0},{x:.716567,y:.681718,z:.147621},{x:.716567,y:.681718,z:-.147621},{x:.525731,y:.850651,z:0},{x:.425325,y:.688191,z:.587785},{x:.864188,y:.442863,z:.238856},{x:.688191,y:.587785,z:.425325},{x:.809017,y:.309017,z:.5},{x:.681718,y:.147621,z:.716567},{x:.587785,y:.425325,z:.688191},{x:.955423,y:.295242,z:0},{x:1,y:0,z:0},{x:.951056,y:.16246,z:.262866},{x:.850651,y:-.525731,z:0},{x:.955423,y:-.295242,z:0},{x:.864188,y:-.442863,z:.238856},{x:.951056,y:-.16246,z:.262866},{x:.809017,y:-.309017,z:.5},{x:.681718,y:-.147621,z:.716567},{x:.850651,y:0,z:.525731},{x:.864188,y:.442863,z:-.238856},{x:.809017,y:.309017,z:-.5},{x:.951056,y:.16246,z:-.262866},{x:.525731,y:0,z:-.850651},{x:.681718,y:.147621,z:-.716567},{x:.681718,y:-.147621,z:-.716567},{x:.850651,y:0,z:-.525731},{x:.809017,y:-.309017,z:-.5},{x:.864188,y:-.442863,z:-.238856},{x:.951056,y:-.16246,z:-.262866},{x:.147621,y:.716567,z:-.681718},{x:.309017,y:.5,z:-.809017},{x:.425325,y:.688191,z:-.587785},{x:.442863,y:.238856,z:-.864188},{x:.587785,y:.425325,z:-.688191},{x:.688191,y:.587785,z:-.425325},{x:-.147621,y:.716567,z:-.681718},{x:-.309017,y:.5,z:-.809017},{x:0,y:.525731,z:-.850651},{x:-.525731,y:0,z:-.850651},{x:-.442863,y:.238856,z:-.864188},{x:-.295242,y:0,z:-.955423},{x:-.16246,y:.262866,z:-.951056},{x:0,y:0,z:-1},{x:.295242,y:0,z:-.955423},{x:.16246,y:.262866,z:-.951056},{x:-.442863,y:-.238856,z:-.864188},{x:-.309017,y:-.5,z:-.809017},{x:-.16246,y:-.262866,z:-.951056},{x:0,y:-.850651,z:-.525731},{x:-.147621,y:-.716567,z:-.681718},{x:.147621,y:-.716567,z:-.681718},{x:0,y:-.525731,z:-.850651},{x:.309017,y:-.5,z:-.809017},{x:.442863,y:-.238856,z:-.864188},{x:.16246,y:-.262866,z:-.951056},{x:.238856,y:-.864188,z:-.442863},{x:.5,y:-.809017,z:-.309017},{x:.425325,y:-.688191,z:-.587785},{x:.716567,y:-.681718,z:-.147621},{x:.688191,y:-.587785,z:-.425325},{x:.587785,y:-.425325,z:-.688191},{x:0,y:-.955423,z:-.295242},{x:0,y:-1,z:0},{x:.262866,y:-.951056,z:-.16246},{x:0,y:-.850651,z:.525731},{x:0,y:-.955423,z:.295242},{x:.238856,y:-.864188,z:.442863},{x:.262866,y:-.951056,z:.16246},{x:.5,y:-.809017,z:.309017},{x:.716567,y:-.681718,z:.147621},{x:.525731,y:-.850651,z:0},{x:-.238856,y:-.864188,z:-.442863},{x:-.5,y:-.809017,z:-.309017},{x:-.262866,y:-.951056,z:-.16246},{x:-.850651,y:-.525731,z:0},{x:-.716567,y:-.681718,z:-.147621},{x:-.716567,y:-.681718,z:.147621},{x:-.525731,y:-.850651,z:0},{x:-.5,y:-.809017,z:.309017},{x:-.238856,y:-.864188,z:.442863},{x:-.262866,y:-.951056,z:.16246},{x:-.864188,y:-.442863,z:.238856},{x:-.809017,y:-.309017,z:.5},{x:-.688191,y:-.587785,z:.425325},{x:-.681718,y:-.147621,z:.716567},{x:-.442863,y:-.238856,z:.864188},{x:-.587785,y:-.425325,z:.688191},{x:-.309017,y:-.5,z:.809017},{x:-.147621,y:-.716567,z:.681718},{x:-.425325,y:-.688191,z:.587785},{x:-.16246,y:-.262866,z:.951056},{x:.442863,y:-.238856,z:.864188},{x:.16246,y:-.262866,z:.951056},{x:.309017,y:-.5,z:.809017},{x:.147621,y:-.716567,z:.681718},{x:0,y:-.525731,z:.850651},{x:.425325,y:-.688191,z:.587785},{x:.587785,y:-.425325,z:.688191},{x:.688191,y:-.587785,z:.425325},{x:-.955423,y:.295242,z:0},{x:-.951056,y:.16246,z:.262866},{x:-1,y:0,z:0},{x:-.850651,y:0,z:.525731},{x:-.955423,y:-.295242,z:0},{x:-.951056,y:-.16246,z:.262866},{x:-.864188,y:.442863,z:-.238856},{x:-.951056,y:.16246,z:-.262866},{x:-.809017,y:.309017,z:-.5},{x:-.864188,y:-.442863,z:-.238856},{x:-.951056,y:-.16246,z:-.262866},{x:-.809017,y:-.309017,z:-.5},{x:-.681718,y:.147621,z:-.716567},{x:-.681718,y:-.147621,z:-.716567},{x:-.850651,y:0,z:-.525731},{x:-.688191,y:.587785,z:-.425325},{x:-.587785,y:.425325,z:-.688191},{x:-.425325,y:.688191,z:-.587785},{x:-.425325,y:-.688191,z:-.587785},{x:-.587785,y:-.425325,z:-.688191},{x:-.688191,y:-.587785,z:-.425325}],le=class extends Error{},ar=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),ti(n.buffer)}};function Fa(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function Ur(t,e,r,n){if(r!==0&&(e<za||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function bd(t){if(t.byteLength<za)throw new le("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==yd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==gd)throw new le(`Unsupported MD2 version: ${n}`);let s={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)},o=40+s.numVertices*4;if(s.frameSize!==o)throw new le(`Unexpected frame size ${s.frameSize}, expected ${o}`);if(s.offsetEnd>t.byteLength)throw new le("MD2 offset_end exceeds buffer length");return s}function vd(t,e){let r=e.numSkins*64;Ur(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),s=[];for(let o=0;o<e.numSkins;o+=1)s.push({name:Fa(n,o*64,64)});return s}function Sd(t,e){let r=e.numTexCoords*4;Ur(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),s=[];for(let o=0;o<e.numTexCoords;o+=1){let i=o*4;s.push({s:n.getInt16(i,!0),t:n.getInt16(i+2,!0)})}return s}function Md(t,e){let r=e.numTriangles*12;Ur(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),s=[];for(let o=0;o<e.numTriangles;o+=1){let i=o*12,a=[n.getUint16(i,!0),n.getUint16(i+2,!0),n.getUint16(i+4,!0)],c=[n.getUint16(i+6,!0),n.getUint16(i+8,!0),n.getUint16(i+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new le("Triangle references out of range vertex or texcoord");s.push({vertexIndices:a,texCoordIndices:c})}return s}function Ad(t,e){let r=e.numFrames*e.frameSize;Ur(t,e.offsetFrames,r,"frames");let n=[];for(let s=0;s<e.numFrames;s+=1){let o=e.offsetFrames+s*e.frameSize,i=new DataView(t,o,e.frameSize),a={x:i.getFloat32(0,!0),y:i.getFloat32(4,!0),z:i.getFloat32(8,!0)},c={x:i.getFloat32(12,!0),y:i.getFloat32(16,!0),z:i.getFloat32(20,!0)},l=Fa(i,24,16),d=[];for(let u=0;u<e.numVertices;u+=1){let m=40+u*4,f={x:i.getUint8(m)*a.x+c.x,y:i.getUint8(m+1)*a.y+c.y,z:i.getUint8(m+2)*a.z+c.z},p=i.getUint8(m+3),y=xd[p];if(!y)throw new le(`Invalid normal index ${p} in frame ${l}`);d.push({position:f,normalIndex:p,normal:y})}n.push({name:l,vertices:d})}return n}function _d(t,e){let r=e.numGlCommands*4;if(Ur(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),s=[],o=0;for(;;){if(o+4>r)throw new le("GL command list ended unexpectedly");let i=n.getInt32(o,!0);if(o+=4,i===0)break;let a=Math.abs(i),c=[],l=a*12;if(o+l>r)throw new le("GL command vertex block exceeds buffer");for(let d=0;d<a;d+=1){let u=n.getFloat32(o,!0),m=n.getFloat32(o+4,!0),f=n.getInt32(o+8,!0);if(o+=12,f<0||f>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:m,vertexIndex:f})}s.push({mode:i>0?"strip":"fan",vertices:c})}if(o!==r)throw new le("GL command list did not consume expected data");return s}function ti(t){let e=bd(t),r=vd(t,e),n=Sd(t,e),s=Md(t,e),o=Ad(t,e),i=_d(t,e);return{header:e,skins:r,texCoords:n,triangles:s,frames:o,glCommands:i}}function Ca(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,s=n.replace(/\d+$/,"")||n,o=r;for(;o+1<t.length&&(t[o+1].name.replace(/\d+$/,"")||t[o+1].name)===s;)o+=1;e.push({name:s,firstFrame:r,lastFrame:o}),r=o+1}return e}var Ta=860898377,wd=15,Ce=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Vr(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function Ld(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 fs(t,e,r,n){if(e<0||e+r>n)throw new Ce(`${t} exceeds buffer bounds`)}function Ed(t){let e=t.getInt32(0,!0);if(e!==Ta)throw new Ce(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==wd)throw new Ce(`Unsupported MD3 version: ${r}`);let n=Vr(t,8,64),s=t.getInt32(72,!0),o=t.getInt32(76,!0),i=t.getInt32(80,!0),a=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),d=t.getInt32(96,!0),u=t.getInt32(100,!0),m=t.getInt32(104,!0);if(o<=0||a<0||i<0)throw new Ce("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:s,numFrames:o,numTags:i,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:d,ofsSurfaces:u,ofsEnd:m}}function Pd(t,e){let r=[];fs("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let s=0;s<e.numFrames;s+=1){let o=e.ofsFrames+s*56;r.push({minBounds:{x:t.getFloat32(o,!0),y:t.getFloat32(o+4,!0),z:t.getFloat32(o+8,!0)},maxBounds:{x:t.getFloat32(o+12,!0),y:t.getFloat32(o+16,!0),z:t.getFloat32(o+20,!0)},localOrigin:{x:t.getFloat32(o+24,!0),y:t.getFloat32(o+28,!0),z:t.getFloat32(o+32,!0)},radius:t.getFloat32(o+36,!0),name:Vr(t,o+40,16)})}return r}function Id(t,e){let r=[],s=e.numFrames*e.numTags*112;fs("Tags",e.ofsTags,s,t.byteLength);for(let o=0;o<e.numFrames;o+=1){let i=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(o*e.numTags+a)*112,l=c+64,d=l+12;i.push({name:Vr(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(d,!0),y:t.getFloat32(d+4,!0),z:t.getFloat32(d+8,!0)},{x:t.getFloat32(d+12,!0),y:t.getFloat32(d+16,!0),z:t.getFloat32(d+20,!0)},{x:t.getFloat32(d+24,!0),y:t.getFloat32(d+28,!0),z:t.getFloat32(d+32,!0)}]})}r.push(i)}return r}function zd(t,e){let r=t.getInt32(e,!0);if(r!==Ta)throw new Ce(`Invalid surface ident at ${e}: ${r}`);let n=Vr(t,e+4,64),s=t.getInt32(e+68,!0),o=t.getInt32(e+72,!0),i=t.getInt32(e+76,!0),a=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),d=t.getInt32(e+92,!0),u=t.getInt32(e+96,!0),m=t.getInt32(e+100,!0),f=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Ce(`Invalid surface counts for ${n}`);let p=f;fs(`Surface ${n}`,e,p,t.byteLength);let y=[],h=e+l;for(let _=0;_<c;_+=1){let L=h+_*12;y.push({indices:[t.getInt32(L,!0),t.getInt32(L+4,!0),t.getInt32(L+8,!0)]})}let g=[],S=e+d;for(let _=0;_<i;_+=1){let L=S+_*68;g.push({name:Vr(t,L,64),shaderIndex:t.getInt32(L+64,!0)})}let b=[],M=e+u;for(let _=0;_<a;_+=1){let L=M+_*8;b.push({s:t.getFloat32(L,!0),t:t.getFloat32(L+4,!0)})}let v=[],A=e+m;for(let _=0;_<o;_+=1){let L=[];for(let C=0;C<a;C+=1){let w=A+(_*a+C)*8,H=t.getInt16(w,!0)/64,G=t.getInt16(w+2,!0)/64,V=t.getInt16(w+4,!0)/64,T=t.getUint16(w+6,!0);L.push({position:{x:H,y:G,z:V},latLng:T,normal:Ld(T)})}v.push(L)}return{surface:{name:n,flags:s,numFrames:o,shaders:g,triangles:y,texCoords:b,vertices:v},nextOffset:e+f}}function ri(t){if(t.byteLength<108)throw new Ce("MD3 buffer too small for header");let e=new DataView(t),r=Ed(e);fs("MD3 end",r.ofsEnd,0,t.byteLength);let n=Pd(e,r),s=Id(e,r),o=[],i=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=zd(e,i);o.push(c),i=l}if(i!==r.ofsEnd)throw new Ce("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:s,surfaces:o}}var cr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e);return ri(r.slice().buffer)}};var Fd=1229214514,Cd=2,Ra=64,Ba=12,pt=class extends Error{};function Td(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function ni(t){if(t.byteLength<Ba)throw new pt("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),s=e.getInt32(8,!0);if(r!==Fd)throw new pt(`Invalid Sprite ident: ${r}`);if(n!==Cd)throw new pt(`Unsupported Sprite version: ${n}`);let o=[],i=16+Ra,a=Ba;for(let c=0;c<s;c+=1){if(a+i>t.byteLength)throw new pt("Sprite frame data exceeds buffer length");let l=e.getInt32(a,!0),d=e.getInt32(a+4,!0),u=e.getInt32(a+8,!0),m=e.getInt32(a+12,!0),f=Td(e,a+16,Ra);o.push({width:l,height:d,originX:u,originY:m,name:f}),a+=i}return{ident:r,version:n,numFrames:s,frames:o}}var lr=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),ni(n.buffer)}};function ka(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,s=t.time+e;return n?s=(s%r+r)%r:s>r&&(s=r),{...t,time:Math.max(0,Math.min(s,r))}}function Oa(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,s=t.time/r;if(!n&&s>=e)return{frame:t.sequence.end,nextFrame:t.sequence.end,lerp:0};let o=n?s%e:Math.min(s,e-1),i=Math.floor(o),a=t.sequence.start+i,c=i+1>=e?n?t.sequence.start:t.sequence.end:a+1,l=!n&&i>=e-1?0:o-i;return{frame:a,nextFrame:c,lerp:l}}function Da(t){return{sequence:t,time:0}}function Na(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 Gr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function hs(t){if(t.byteLength<100)throw new Gr("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(),s=e.getInt32(32,!0),o=e.getInt32(36,!0),i=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],a=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),d=e.getInt32(92,!0),u=e.getInt32(96,!0);if(s<=0||o<=0)throw new Gr("Invalid WAL dimensions");let m=[],f=s,p=o;for(let y=0;y<i.length;y+=1){let h=i[y],g=Math.max(1,f*p|0);if(h<=0||h+g>t.byteLength)throw new Gr(`Invalid WAL mip offset for level ${y}`);let S=new Uint8Array(t,h,g);m.push({level:y,width:f,height:p,data:S}),f=Math.max(1,f>>1),p=Math.max(1,p>>1)}return{name:n,width:s,height:o,mipmaps:m,animName:c,flags:l,contents:d,value:u}}var kt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Ha(t){if(t.byteLength<128)throw new kt("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),s=e.getUint8(3),o=e.getUint16(4,!0),i=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new kt("Unsupported PCX encoding");if(s!==8)throw new kt("Only 8bpp PCX files are supported");let l=a-o+1,d=c-i+1,u=e.getUint16(66,!0),m=t.byteLength-769;if(m<128||new DataView(t,m,1).getUint8(0)!==12)throw new kt("Missing PCX palette");let f=new Uint8Array(t,m+1,768),p=new Uint8Array(t,128,m-128),y=new Uint8Array(l*d),h=0,g=0;for(let S=0;S<d;S+=1){let b=0;for(;b<u&&h<p.length;){let M=1,v=p[h++];if((v&192)===192){if(M=v&63,h>=p.length)throw new kt("Unexpected end of PCX RLE data");v=p[h++]}for(let A=0;A<M&&b<u;A+=1)b<l&&(y[g++]=v),b+=1}}return{width:l,height:d,bitsPerPixel:s,pixels:y,palette:f}}function ps(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],s=n*3,o=r*4;e[o]=t.palette[s],e[o+1]=t.palette[s+1],e[o+2]=t.palette[s+2],e[o+3]=n===255?0:255}return e}var dr=class{constructor(e={}){this.cache=new ht(e.capacity??128)}get size(){return this.cache.size}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function si(t,e){let r=[];for(let n of t.mipmaps){let s=new Uint8Array(n.width*n.height*4);for(let o=0;o<n.data.length;o+=1){let i=n.data[o],a=i*3,c=o*4;s[c]=e[a],s[c+1]=e[a+1],s[c+2]=e[a+2],s[c+3]=i===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:s})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function Ua(t){let e=ps(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Va(t,e){return si(hs(t),e)}var Ot=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function oi(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function ys(t){if(t.byteLength<44)throw new Ot("WAV buffer too small");let e=new DataView(t);if(oi(e,0,4)!=="RIFF"||oi(e,8,4)!=="WAVE")throw new Ot("Invalid WAV header");let r=12,n=-1,s=-1,o=0,i=0;for(;r+8<=t.byteLength;){let p=oi(e,r,4),y=e.getUint32(r+4,!0),h=r+8;p==="fmt "?(n=h,o=y):p==="data"&&(s=h,i=y),r=h+y}if(n===-1||s===-1)throw new Ot("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),d=e.getUint16(n+14,!0);if(a!==1)throw new Ot("Only PCM WAV is supported");let u=d/8,m=i/(u*c),f=new Float32Array(m*c);for(let p=0;p<m;p+=1)for(let y=0;y<c;y+=1){let h=p*c+y,g=s+h*u,S=0;if(d===8)S=e.getUint8(g),f[h]=(S-128)/128;else if(d===16)S=e.getInt16(g,!0),f[h]=S/32768;else if(d===24){let b=e.getUint8(g),M=e.getUint8(g+1),v=e.getInt8(g+2);S=b|M<<8|v<<16,f[h]=S/8388608}else throw new Ot(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:f}}var Rd=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),s,o,i,a=e;for(s=0;s<256;s++){for(i=s<<24,o=8;o>0;--o)i=2147483648&i?i<<1^r:i<<1;n[s]=i}for(s=0;s<t.length;s++)a=a<<8^n[255&(a>>24^t[s])];return a};var ii=(t,e=Rd)=>{let r=h=>new Uint8Array(h.length/2).map(((g,S)=>parseInt(h.substring(2*S,2*(S+1)),16))),n=h=>r(h)[0],s=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(((h,g)=>s.set(h,g)));let o=new Uint8Array(t.length),i,a,c,l=!1,d=0,u=42,m=t.length>13&&t.substring(0,9)==="dynEncode",f=0;m&&(f=11,a=n(t.substring(9,f)),a<=1&&(f+=2,u=n(t.substring(11,f))),a===1&&(f+=8,c=(h=>new DataView(r(h).buffer).getInt32(0,!0))(t.substring(13,f))));let p=256-u;for(let h=f;h<t.length;h++)if(i=t.charCodeAt(h),i!==61||l){if(i===92&&h<t.length-5&&m){let g=t.charCodeAt(h+1);g!==117&&g!==85||(i=parseInt(t.substring(h+2,h+6),16),h+=5)}if(i>255){let g=s.get(i);g&&(i=g+127)}l&&(l=!1,i-=64),o[d++]=i<u&&i>0?i+p:i-u}else l=!0;let y=o.subarray(0,d);if(m&&a===1){let h=e(y);if(h!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
1
+ "use strict";var Quake2Engine=(()=>{var ml=Object.create;var es=Object.defineProperty;var fl=Object.getOwnPropertyDescriptor;var hl=Object.getOwnPropertyNames;var pl=Object.getPrototypeOf,yl=Object.prototype.hasOwnProperty;var gl=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ho=(t,e)=>{for(var r in e)es(t,r,{get:e[r],enumerable:!0})},aa=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of hl(e))!yl.call(t,s)&&s!==r&&es(t,s,{get:()=>e[s],enumerable:!(n=fl(e,s))||n.enumerable});return t};var xl=(t,e,r)=>(r=t!=null?ml(pl(t)):{},aa(e||!t||!t.__esModule?es(r,"default",{value:t,enumerable:!0}):r,t)),bl=t=>aa(es({},"__esModule",{value:!0}),t);var Wa=gl((Pf,Ga)=>{"use strict";Ga.exports=Worker});var mm={};Ho(mm,{ATTN_IDLE:()=>Sc,ATTN_LOOP_NONE:()=>bc,ATTN_NONE:()=>Qs,ATTN_NORM:()=>vc,ATTN_STATIC:()=>Mc,AssetDependencyError:()=>Qt,AssetDependencyTracker:()=>Nn,AssetManager:()=>$s,AudioApi:()=>co,AudioContextController:()=>Zs,AudioRegistry:()=>Pr,AudioRegistryError:()=>kn,AudioSystem:()=>io,BSP_SURFACE_FRAGMENT_SOURCE:()=>Ri,BSP_SURFACE_VERTEX_SOURCE:()=>Ci,BSP_VERTEX_LAYOUT:()=>zi,BspLoader:()=>us,BspParseError:()=>Y,BspSurfacePipeline:()=>mo,Camera:()=>go,ConfigStringRegistry:()=>or,Cvar:()=>Hr,CvarRegistry:()=>as,DemoPlaybackController:()=>$n,DemoReader:()=>Zt,EngineHost:()=>nr,EngineRuntime:()=>Nr,FixedTimestepLoop:()=>Rt,Framebuffer:()=>lo,IndexBuffer:()=>Ne,LruCache:()=>ht,MAX_SOUND_CHANNELS:()=>Li,MD2_FRAGMENT_SHADER:()=>Ui,MD2_VERTEX_SHADER:()=>Hi,MD3_FRAGMENT_SHADER:()=>ji,MD3_VERTEX_SHADER:()=>$i,Md2Loader:()=>ar,Md2MeshBuffers:()=>ho,Md2ParseError:()=>le,Md2Pipeline:()=>po,Md3Loader:()=>cr,Md3ModelMesh:()=>xo,Md3ParseError:()=>Te,Md3Pipeline:()=>bo,Md3SurfaceMesh:()=>Vn,MusicSystem:()=>ao,NetworkMessageParser:()=>tr,PARTICLE_FRAGMENT_SHADER:()=>Ji,PARTICLE_VERTEX_SHADER:()=>Qi,PakArchive:()=>ir,PakIndexStore:()=>qs,PakIngestionError:()=>ft,PakParseError:()=>Fe,PakValidationError:()=>Bt,PakValidator:()=>ls,ParticleRenderer:()=>So,ParticleSystem:()=>vo,PlaybackState:()=>No,RERELEASE_KNOWN_PAKS:()=>Jo,SKYBOX_FRAGMENT_SHADER:()=>Di,SKYBOX_VERTEX_SHADER:()=>Oi,SOUND_FULLVOLUME:()=>Ir,SOUND_LOOP_ATTENUATE:()=>Ac,ShaderProgram:()=>be,SkyboxPipeline:()=>fo,SoundChannel:()=>js,SoundPrecache:()=>ro,SoundRegistry:()=>to,SpriteLoader:()=>lr,SpriteParseError:()=>pt,Texture2D:()=>zr,TextureCache:()=>dr,TextureCubeMap:()=>Fr,U_ANGLE1:()=>zo,U_ANGLE2:()=>wo,U_ANGLE3:()=>Lo,U_EFFECTS16:()=>Yn,U_EFFECTS8:()=>Wn,U_EVENT:()=>Po,U_FRAME16:()=>To,U_FRAME8:()=>Eo,U_MODEL:()=>Fo,U_MODEL2:()=>Co,U_MODEL3:()=>Ro,U_MODEL4:()=>Bo,U_OLDORIGIN:()=>ko,U_ORIGIN1:()=>Ao,U_ORIGIN2:()=>_o,U_ORIGIN3:()=>Io,U_REMOVE:()=>Zi,U_RENDERFX16:()=>Kn,U_RENDERFX8:()=>Gn,U_SKIN16:()=>qn,U_SKIN8:()=>Xn,U_SOLID:()=>Do,U_SOUND:()=>Oo,VertexArray:()=>_e,VertexBuffer:()=>ve,VirtualFileSystem:()=>cs,advanceAnimation:()=>ka,applySurfaceState:()=>kc,attenuationToDistanceMultiplier:()=>Jt,boxIntersectsFrustum:()=>Un,buildBspGeometry:()=>Ic,buildMd2Geometry:()=>Vi,buildMd2VertexData:()=>Gi,buildMd3SurfaceGeometry:()=>Yi,buildMd3VertexData:()=>qi,calculateMaxAudibleDistance:()=>Js,calculatePakChecksum:()=>_a,computeFrameBlend:()=>Oa,computeSkyScroll:()=>Nc,createAnimationState:()=>Da,createAudioGraph:()=>eo,createBspSurfaces:()=>Pc,createEmptyEntityState:()=>er,createEmptyProtocolPlayerState:()=>Mo,createEngine:()=>um,createEngineRuntime:()=>Ma,createFaceLightmap:()=>ms,createInitialChannels:()=>no,createProgramFromSources:()=>Ec,createWebGLContext:()=>wc,decodeOgg:()=>Ys,deriveSurfaceRenderState:()=>ki,extractFrustumPlanes:()=>zc,filesToPakSources:()=>Zo,findLeafForPoint:()=>Ti,gatherVisibleFaces:()=>Rc,groupMd2Animations:()=>Ta,ingestPakFiles:()=>wa,ingestPaks:()=>ds,interpolateMd3Tag:()=>nl,interpolateVec3:()=>Na,parseBsp:()=>ei,parseMd2:()=>ti,parseMd3:()=>ri,parsePcx:()=>Ha,parseSprite:()=>ni,parseWal:()=>hs,parseWalTexture:()=>Va,parseWav:()=>ys,pcxToRgba:()=>ps,pickChannel:()=>so,preparePcxTexture:()=>Ua,removeViewTranslation:()=>Dc,resolveLightStyles:()=>Bi,spatializeOrigin:()=>oo,spawnBlood:()=>il,spawnBulletImpact:()=>sl,spawnExplosion:()=>ol,spawnMuzzleFlash:()=>cl,spawnTeleportFlash:()=>al,spawnTrail:()=>ll,walToRgba:()=>si,wireDropTarget:()=>La,wireFileInput:()=>Ea});var vl=()=>typeof performance<"u"?performance.now():Date.now(),Sl=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},Rt=class{constructor(e,r={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),r=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(r,e),this.running&&this.options.schedule(this.tick)};let n=r.fixedDeltaMs??25,s=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:s,maxDeltaMs:r.maxDeltaMs??n*s,startTimeMs:r.startTimeMs,now:r.now??vl,schedule:r.schedule??Sl}}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 s=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&s<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,s+=1;let o=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:o,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var nr=class{constructor(e,r,n={}){this.game=e;this.client=r;this.started=!1;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e,this.latestCommand)};this.renderClient=e=>{this.client&&(this.latestCommand=this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame}))};let s=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??s,this.loop=new Rt({simulate:this.stepSimulation,render:this.renderClient},{...n.loop,startTimeMs:this.startTimeMs})}start(){this.started||(this.latestFrame=this.game.init(this.startTimeMs)??this.latestFrame,this.client?.init(this.latestFrame),this.started=!0,this.loop.start())}stop(){this.started&&(this.loop.stop(),this.client?.shutdown(),this.game.shutdown(),this.previousFrame=void 0,this.latestFrame=void 0,this.started=!1)}pump(e){this.loop.pump(e)}getLatestFrame(){return this.latestFrame}isRunning(){return this.loop.isRunning()}};var Ml=Object.defineProperty,Al=(t,e)=>{for(var r in e)Ml(t,r,{get:e[r],enumerable:!0})},ca={x:0,y:0,z:0};var gm=Math.PI/180;function la(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function _l(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function Vo(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function wl(t){return Vo(t,t)}function Go(t){return Math.sqrt(wl(t))}function Ue(t){let e=Go(t);return e===0?t:_l(t,1/e)}var Ll=Math.PI/180,xm=180/Math.PI,sr=Ll;function El(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function da(t,e){let r=e.x,n=e.y,s=e.z;return{x:t[0]*r+t[4]*n+t[8]*s+t[12],y:t[1]*r+t[5]*n+t[9]*s+t[13],z:t[2]*r+t[6]*n+t[10]*s+t[14]}}function ua(t,e){let r=El();return r[0]=e[0].x,r[1]=e[0].y,r[2]=e[0].z,r[4]=e[1].x,r[5]=e[1].y,r[6]=e[1].z,r[8]=e[2].x,r[9]=e[2].y,r[10]=e[2].z,r[12]=t.x,r[13]=t.y,r[14]=t.z,r}var Ke=1,mt=2;var Wo=8,Xo=16,Pl=32;var Il=16384;var ts=65536,ma=1<<17,zl=1<<18,Fl=1<<19,Tl=1<<20,Cl=1<<21,Rl=1<<22,Bl=1<<23,bm=1<<24,rs=1<<25,kl=1<<26,vm=1<<27,Sm=1<<28,Mm=1<<29,ns=1<<30,Am=1<<31;var Dr=0;var fa=4,ha=8,pa=16,ya=32,ga=64;var _m=1<<25,wm=1<<28,Lm=1<<29,Em=1<<30,Pm=1<<31;var Im=Ke|mt,zm=Ke|ts|mt|rs|ns,Fm=Ke|ts|mt,Tm=Ke|ma|mt|rs|ns,Cm=Pl|Wo|Xo,Rm=Ke|Xo|Wo,Ol=Ke|rs|ns|mt|kl,Bm=zl|Fl|Tl|Cl|Rl|Bl,km=Ke|Wo|Xo|rs|ns,Om=Ke|ts|mt,Dm=Ke|mt,Nm=Ke|ts|mt|ma,Hm=Ol|Il;var Um=Number.MAX_SAFE_INTEGER-1;var ss=(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))(ss||{});var os=256;var Ko=256,Yo=8192,is=2048,qo=512,$o=256,jo=os*2,Qo=256,Uo=32,Or=96;var K=(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.AirAccel=59]="AirAccel",t[t.MaxClients=60]="MaxClients",t[t.MapChecksum=61]="MapChecksum",t[t.Models=62]="Models",t[t.Sounds=62+Yo]="Sounds",t[t.Images=t.Sounds+is]="Images",t[t.Lights=t.Images+qo]="Lights",t[t.ShadowLights=t.Lights+Ko]="ShadowLights",t[t.Items=t.ShadowLights+Qo]="Items",t[t.PlayerSkins=t.Items+$o]="PlayerSkins",t[t.General=t.PlayerSkins+os]="General",t[t.WheelWeapons=t.General+jo]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+Uo]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+Uo]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+Uo]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(K||{}),xa=K.MaxConfigStrings;function ba(t){return t>=5&&t<59?Or*(59-t):t>=K.General&&t<K.WheelWeapons?Or*(K.MaxConfigStrings-t):Or}var Dl={};Al(Dl,{addReplayFrame:()=>Vl,createReplaySession:()=>Ul,deserializeReplay:()=>Hl,serializeReplay:()=>Nl});function Nl(t){return JSON.stringify(t,null,2)}function Hl(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 Ul(t,e){return{metadata:{map:t,date:new Date().toISOString(),version:"1.0",seed:e},frames:[]}}function Vl(t,e,r,n){t.frames.push({serverFrame:r,cmd:e,timestamp:Date.now()-n})}var j=(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))(j||{});var E=(t=>(t[t.GUNSHOT=0]="GUNSHOT",t[t.BLOOD=1]="BLOOD",t[t.BLASTER=2]="BLASTER",t[t.RAILTRAIL=3]="RAILTRAIL",t[t.SHOTGUN=4]="SHOTGUN",t[t.EXPLOSION1=5]="EXPLOSION1",t[t.EXPLOSION2=6]="EXPLOSION2",t[t.ROCKET_EXPLOSION=7]="ROCKET_EXPLOSION",t[t.GRENADE_EXPLOSION=8]="GRENADE_EXPLOSION",t[t.SPARKS=9]="SPARKS",t[t.SPLASH=10]="SPLASH",t[t.BUBBLETRAIL=11]="BUBBLETRAIL",t[t.SCREEN_SPARKS=12]="SCREEN_SPARKS",t[t.SHIELD_SPARKS=13]="SHIELD_SPARKS",t[t.BULLET_SPARKS=14]="BULLET_SPARKS",t[t.LASER_SPARKS=15]="LASER_SPARKS",t[t.PARASITE_ATTACK=16]="PARASITE_ATTACK",t[t.ROCKET_EXPLOSION_WATER=17]="ROCKET_EXPLOSION_WATER",t[t.GRENADE_EXPLOSION_WATER=18]="GRENADE_EXPLOSION_WATER",t[t.MEDIC_CABLE_ATTACK=19]="MEDIC_CABLE_ATTACK",t[t.BFG_EXPLOSION=20]="BFG_EXPLOSION",t[t.BFG_BIGEXPLOSION=21]="BFG_BIGEXPLOSION",t[t.BOSSTPORT=22]="BOSSTPORT",t[t.BFG_LASER=23]="BFG_LASER",t[t.GRAPPLE_CABLE=24]="GRAPPLE_CABLE",t[t.WELDING_SPARKS=25]="WELDING_SPARKS",t[t.GREENBLOOD=26]="GREENBLOOD",t[t.BLUEHYPERBLASTER=27]="BLUEHYPERBLASTER",t[t.PLASMA_EXPLOSION=28]="PLASMA_EXPLOSION",t[t.TUNNEL_SPARKS=29]="TUNNEL_SPARKS",t[t.BLASTER2=30]="BLASTER2",t[t.RAILTRAIL2=31]="RAILTRAIL2",t[t.FLAME=32]="FLAME",t[t.LIGHTNING=33]="LIGHTNING",t[t.DEBUGTRAIL=34]="DEBUGTRAIL",t[t.PLAIN_EXPLOSION=35]="PLAIN_EXPLOSION",t[t.FLASHLIGHT=36]="FLASHLIGHT",t[t.FORCEWALL=37]="FORCEWALL",t[t.HEATBEAM=38]="HEATBEAM",t[t.MONSTER_HEATBEAM=39]="MONSTER_HEATBEAM",t[t.STEAM=40]="STEAM",t[t.BUBBLETRAIL2=41]="BUBBLETRAIL2",t[t.MOREBLOOD=42]="MOREBLOOD",t[t.HEATBEAM_SPARKS=43]="HEATBEAM_SPARKS",t[t.HEATBEAM_STEAM=44]="HEATBEAM_STEAM",t[t.CHAINFIST_SMOKE=45]="CHAINFIST_SMOKE",t[t.ELECTRIC_SPARKS=46]="ELECTRIC_SPARKS",t[t.TRACKER_EXPLOSION=47]="TRACKER_EXPLOSION",t[t.TELEPORT_EFFECT=48]="TELEPORT_EFFECT",t[t.DBALL_GOAL=49]="DBALL_GOAL",t[t.WIDOWBEAMOUT=50]="WIDOWBEAMOUT",t[t.NUKEBLAST=51]="NUKEBLAST",t[t.WIDOWSPLASH=52]="WIDOWSPLASH",t[t.EXPLOSION1_BIG=53]="EXPLOSION1_BIG",t[t.EXPLOSION1_NP=54]="EXPLOSION1_NP",t[t.FLECHETTE=55]="FLECHETTE",t))(E||{});var va=class{constructor(t){t instanceof Uint8Array?this.view=new DataView(t.buffer,t.byteOffset,t.byteLength):this.view=new DataView(t),this.offset=0,this.length=this.view.byteLength}getPosition(){return this.offset}seek(t){if(t<0||t>this.length)throw new Error(`Seek out of bounds: ${t} (length: ${this.length})`);this.offset=t}hasMore(){return this.offset<this.length}readChar(){let t=this.view.getInt8(this.offset);return this.offset+=1,t}readByte(){let t=this.view.getUint8(this.offset);return this.offset+=1,t}readShort(){let t=this.view.getInt16(this.offset,!0);return this.offset+=2,t}readLong(){let t=this.view.getInt32(this.offset,!0);return this.offset+=4,t}readFloat(){let t=this.view.getFloat32(this.offset,!0);return this.offset+=4,t}readString(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0)break;t+=String.fromCharCode(e)}return t}readStringLine(){let t="";for(;this.offset<this.length;){let e=this.readChar();if(e===-1||e===0||e===10)break;t+=String.fromCharCode(e)}return t}readCoord(){return this.readShort()*(1/8)}readAngle(){return this.readChar()*(360/256)}readAngle16(){return this.readShort()*360/65536}readData(t){if(this.offset+t>this.length)throw new Error(`Read out of bounds: ${this.offset+t} (length: ${this.length})`);let e=new Uint8Array(this.view.buffer,this.view.byteOffset+this.offset,t);return this.offset+=t,new Uint8Array(e)}readPos(t){t.x=this.readCoord(),t.y=this.readCoord(),t.z=this.readCoord()}readDir(t){if(this.readByte()>=162){t.x=0,t.y=0,t.z=0;return}t.x=0,t.y=0,t.z=0}};function Gl(t){if(t<0||t>=K.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${K.MaxConfigStrings-1})`)}function Sa(t,e){let r=ba(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${Or} chars per slot`)}var or=class{constructor(){this.values=new Map;this.modelCursor=K.Models;this.soundCursor=K.Sounds;this.imageCursor=K.Images;this.lightCursor=K.Lights;this.shadowLightCursor=K.ShadowLights;this.itemCursor=K.Items;this.playerSkinCursor=K.PlayerSkins;this.generalCursor=K.General}set(e,r){return Gl(e),Sa(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getAll(){let e=new Array(xa).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,K.Models,Yo,"modelCursor")}soundIndex(e){return this.register(e,K.Sounds,is,"soundCursor")}findSoundIndex(e){for(let r=K.Sounds;r<K.Sounds+is;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,K.Images,qo,"imageCursor")}lightIndex(e){return this.register(e,K.Lights,Ko,"lightCursor")}shadowLightIndex(e){return this.register(e,K.ShadowLights,Qo,"shadowLightCursor")}itemIndex(e){return this.register(e,K.Items,$o,"itemCursor")}playerSkinIndex(e){return this.register(e,K.PlayerSkins,os,"playerSkinCursor")}generalIndex(e){return this.register(e,K.General,jo,"generalCursor")}register(e,r,n,s){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===e)return a;let o=this[s],i=r+n;if(o>=i)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return Sa(o,e),this.values.set(o,e),this[s]=o+1,o}};var Nr=class{constructor(e,r){this.engine=e;this.host=r;this.started=!1}start(){this.started||(this.engine.init(),this.host.start(),this.started=!0)}stop(){this.started&&(this.host.stop(),this.engine.shutdown(),this.started=!1)}pump(e){this.host.pump(e)}getLatestFrame(){return this.host.getLatestFrame()}isRunning(){return this.started&&this.host.isRunning()}};function Ma(t,e,r,n){return new Nr(t,new nr(e,r,n))}var Hr=class{constructor({name:e,defaultValue:r,description:n,flags:s=ss.None,onChange:o}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=s,this._value=r,this.onChange=o}get string(){return this._value}get number(){return Number(this._value)}get integer(){return Math.trunc(this.number)}get boolean(){return!!this.integer}set(e){if(this.flags&ss.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)}},as=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=new Hr(e);return this.cvars.set(e.name,n),n}get(e){return this.cvars.get(e)}setValue(e,r){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(r),n}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let r of this.cvars.values())e=r.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,r)=>e.name.localeCompare(r.name))}};var Wl="PACK";function Xl(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function se(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Kl(){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 Yl=Kl();function Aa(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=Yl[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var Fe=class extends Error{},ir=class t{constructor(e,r,n,s){this.name=e;this.buffer=r;this.entries=new Map(n.map(o=>[o.name,o])),this.checksum=s,this.size=r.byteLength}static fromArrayBuffer(e,r){let n=new DataView(r);if(r.byteLength<12)throw new Fe("PAK buffer too small to contain header");let s=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(s!==Wl)throw new Fe(`Invalid PAK header magic: ${s}`);let o=n.getInt32(4,!0),i=n.getInt32(8,!0);if(o<12)throw new Fe(`Invalid directory offset: ${o}`);if(i<=0||i%64!==0)throw new Fe(`Invalid directory length: ${i}`);if(o+i>r.byteLength)throw new Fe("Directory exceeds buffer length");let c=i/64,l=[],d=new Map;for(let u=0;u<c;u+=1){let m=o+u*64,f=Xl(n,m,56),p=se(f),y=n.getInt32(m+56,!0),h=n.getInt32(m+60,!0);if(y<0||h<0||y+h>r.byteLength)throw new Fe(`Invalid entry bounds for ${f||"<unnamed>"} (offset=${y}, length=${h})`);if(!p)throw new Fe(`Entry ${u} has an empty name`);let g={name:p,offset:y,length:h};d.set(p,g)}return l.push(...d.values()),new t(e,r,l,Aa(new Uint8Array(r)))}getEntry(e){return this.entries.get(se(e))}listEntries(){return Array.from(this.entries.values())}readFile(e){let r=this.getEntry(e);if(!r)throw new Fe(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,r.offset,r.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function _a(t){return Aa(new Uint8Array(t))}var cs=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(r=>this.mountPak(r))}mountPak(e){this.mounts.push(e);for(let r of e.listEntries()){let n=se(r.name);this.files.set(n,{archive:e,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(se(e))}stat(e){let r=this.files.get(se(e));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}async readFile(e){let r=this.files.get(se(e));if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}list(e=""){let r=se(e).replace(/\/+$|^\//g,""),n=[],s=new Set,o=r?`${r}/`:"";for(let i of this.files.values()){if(r&&!i.entry.name.startsWith(o))continue;let a=r?i.entry.name.slice(o.length):i.entry.name,c=a.indexOf("/");c===-1?n.push({path:i.entry.name,size:i.entry.length,sourcePak:i.archive.name}):s.add(a.slice(0,c))}return n.sort((i,a)=>i.path.localeCompare(a.path)),{files:n,directories:[...s].sort()}}findByExtension(e){let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let s of this.files.values())s.entry.name.toLowerCase().endsWith(r)&&n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name});return n.sort((s,o)=>s.path.localeCompare(o.path))}};var Jo=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"}]),Bt=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"}},ls=class{constructor(e=Jo){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")),s=e.checksum,o="size"in e?e.size:void 0,i=this.known.get(n);return i?i.checksum!==s?{name:n,checksum:s,expectedChecksum:i.checksum,status:"mismatch",size:o,description:i.description}:{name:n,checksum:s,expectedChecksum:i.checksum,status:"valid",size:o,description:i.description}:{name:n,checksum:s,status:"unknown",size:o}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new Bt(n);return n}normalizePakName(e){let r=se(e),n=r.split("/"),s=n.pop()??r,o=n.pop();return o?`${s}@${o}`:s}};var ft=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 ql(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 s=new FileReader;s.onerror=()=>n(s.error??new Error("Unknown FileReader error")),s.onprogress=o=>{e?.({file:"blob",loadedBytes:o.loaded,totalBytes:o.total||t.size,state:"reading"})},s.onload=()=>{let o=s.result;o instanceof ArrayBuffer?r(o):n(new Error("Unexpected FileReader result"))},s.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=[],s=0;for(;;){let{done:a,value:c}=await r.read();if(a)break;if(!c)continue;let l=c;n.push(l),s+=l.byteLength,e?.({file:"blob",loadedBytes:s,totalBytes:t.size,state:"reading"})}let o=new Uint8Array(s),i=0;for(let a of n)o.set(a,i),i+=a.byteLength;return o.buffer}throw new ft("blob",new Error("Unsupported Blob type"))}async function $l(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 ql(t.data,s=>e?.({...s,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 ds(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},s=n.persistIndexes??!!n.pakIndexStore,o=n.enforceValidation??!!n.validator,i=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let d=await $l(l,n.onProgress),u=ir.fromArrayBuffer(l.name,d),m=n.validator?.validateArchive(u);if(m){n.onValidationResult?.(m);let f=m.status==="mismatch",p=m.status==="unknown";if(f&&o||p&&!i){let y=new Bt(m);if(n.onError?.(l.name,y),a)throw new ft(l.name,y);c.push({archive:u,mounted:!1,validation:m});continue}}if(t.mountPak(u),s&&n.pakIndexStore)try{await n.pakIndexStore.persist(u)}catch(f){if(n.onError?.(l.name,f),a)throw new ft(l.name,f)}n.onProgress?.({file:l.name,loadedBytes:d.byteLength,totalBytes:d.byteLength,state:"parsed"}),c.push({archive:u,mounted:!0,validation:m})}catch(d){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,d),a)throw new ft(l.name,d)}return c}var ht=class{constructor(e){this.capacity=e;this.map=new Map;if(e<=0)throw new RangeError("LRU cache capacity must be greater than zero")}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let r=this.map.get(e);if(r!==void 0)return this.map.delete(e),this.map.set(e,r),r}set(e,r){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,r),this.map.size>this.capacity){let n=this.map.keys().next();n.done||this.map.delete(n.value)}}delete(e){return this.map.delete(e)}clear(){this.map.clear()}entries(){return Array.from(this.map.entries()).reverse().map(([e,r])=>({key:e,value:r}))}};function jl(t){return Array.isArray(t)?t:Array.from(t)}function Zo(t){return jl(t).map(e=>({name:e.name,data:e}))}async function wa(t,e,r){let n=Zo(e);return ds(t,n,r??{})}function La(t,e){let r=s=>{s.preventDefault(),s.dataTransfer?.dropEffect&&(s.dataTransfer.dropEffect="copy")},n=s=>{s.preventDefault();let o=s.dataTransfer?.files;o&&o.length>0&&e(Array.from(o))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function Ea(t,e){let r=n=>{let s=n.target;!s||!s.files||s.files.length===0||(e(s.files),s.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var Ql="IBSP",Jl=38,Ia=19,Zl=8+Ia*8;var Y=class extends Error{},us=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),ei(n.buffer)}};function ei(t){if(t.byteLength<Zl)throw new Y("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!==Ql)throw new Y(`Invalid BSP magic ${r}`);let n=e.getInt32(4,!0);if(n!==Jl)throw new Y(`Unsupported BSP version ${n}`);let s=new Map;for(let A=0;A<Ia;A+=1){let _=e.getInt32(8+A*8,!0),L=e.getInt32(12+A*8,!0);if(_<0||L<0||_+L>t.byteLength)throw new Y(`Invalid lump bounds for index ${A}`);s.set(A,{offset:_,length:L})}let o={version:n,lumps:s},i=ed(t,s.get(0)),a=rd(t,s.get(1)),c=nd(t,s.get(2)),l=sd(t,s.get(4)),d=od(t,s.get(5)),u=id(t,s.get(6)),m=new Uint8Array(t,s.get(7).offset,s.get(7).length),f=pd(u,s.get(7)),p=ad(t,s.get(8)),y=cd(t,s.get(11)),h=ld(t,s.get(12)),g=dd(t,s.get(13)),S=ud(t,s.get(14)),b=md(t,s.get(15)),M=fd(t,s.get(9),s.get(10),p),v=hd(t,s.get(3));return{header:o,entities:i,planes:a,vertices:c,nodes:l,texInfo:d,faces:u,lightMaps:m,lightMapInfo:f,leafs:p,leafLists:M,edges:y,surfEdges:h,models:g,brushes:S,brushSides:b,visibility:v}}function ed(t,e){let r=new TextDecoder().decode(new Uint8Array(t,e.offset,e.length)),n=td(r),s=n.find(o=>o.classname==="worldspawn");return{raw:r,entities:n,worldspawn:s}}function td(t){let e=[],r=/\{([^}]*)\}/gms,n;for(;(n=r.exec(t))!==null;){let s=n[1],o={},i=/"([^\"]*)"\s+"([^\"]*)"/g,a;for(;(a=i.exec(s))!==null;)o[a[1]]=a[2];e.push({classname:o.classname,properties:o})}return e}function rd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/20;if(n%1!==0)throw new Y("Plane lump has invalid length");let s=[];for(let o=0;o<n;o+=1){let i=[r.getFloat32(o*20,!0),r.getFloat32(o*20+4,!0),r.getFloat32(o*20+8,!0)],a=r.getFloat32(o*20+12,!0),c=r.getInt32(o*20+16,!0);s.push({normal:i,dist:a,type:c})}return s}function nd(t,e){let r=new DataView(t,e.offset,e.length),n=e.length/12;if(n%1!==0)throw new Y("Vertex lump has invalid length");let s=[];for(let o=0;o<n;o+=1)s.push([r.getFloat32(o*12,!0),r.getFloat32(o*12+4,!0),r.getFloat32(o*12+8,!0)]);return s}function sd(t,e){let r=new DataView(t,e.offset,e.length),n=36,s=e.length/n;if(s%1!==0)throw new Y("Node lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getInt32(a,!0),l=[r.getInt32(a+4,!0),r.getInt32(a+8,!0)],d=[r.getInt16(a+12,!0),r.getInt16(a+14,!0),r.getInt16(a+16,!0)],u=[r.getInt16(a+18,!0),r.getInt16(a+20,!0),r.getInt16(a+22,!0)],m=r.getUint16(a+24,!0),f=r.getUint16(a+26,!0);o.push({planeIndex:c,children:l,mins:d,maxs:u,firstFace:m,numFaces:f})}return o}function od(t,e){let r=new DataView(t,e.offset,e.length),n=76,s=e.length/n;if(s%1!==0)throw new Y("TexInfo lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=r.getFloat32(a+12,!0),d=[r.getFloat32(a+16,!0),r.getFloat32(a+20,!0),r.getFloat32(a+24,!0)],u=r.getFloat32(a+28,!0),m=r.getInt32(a+32,!0),f=r.getInt32(a+36,!0),p=new Uint8Array(t,e.offset+a+40,32),y=new TextDecoder("utf-8").decode(p).replace(/\0.*$/,""),h=r.getInt32(a+72,!0);o.push({s:c,sOffset:l,t:d,tOffset:u,flags:m,value:f,texture:y,nextTexInfo:h})}return o}function id(t,e){let r=new DataView(t,e.offset,e.length),n=20,s=e.length/n;if(s%1!==0)throw new Y("Face lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getUint16(a,!0),l=r.getInt16(a+2,!0),d=r.getInt32(a+4,!0),u=r.getInt16(a+8,!0),m=r.getInt16(a+10,!0),f=[r.getUint8(a+12),r.getUint8(a+13),r.getUint8(a+14),r.getUint8(a+15)],p=r.getInt32(a+16,!0);o.push({planeIndex:c,side:l,firstEdge:d,numEdges:u,texInfo:m,styles:f,lightOffset:p})}return o}function ad(t,e){let r=new DataView(t,e.offset,e.length),n=28,s=e.length/n;if(s%1!==0)throw new Y("Leaf lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n,c=r.getInt32(a,!0),l=r.getInt16(a+4,!0),d=r.getInt16(a+6,!0),u=[r.getInt16(a+8,!0),r.getInt16(a+10,!0),r.getInt16(a+12,!0)],m=[r.getInt16(a+14,!0),r.getInt16(a+16,!0),r.getInt16(a+18,!0)],f=r.getUint16(a+20,!0),p=r.getUint16(a+22,!0),y=r.getUint16(a+24,!0),h=r.getUint16(a+26,!0);o.push({contents:c,cluster:l,area:d,mins:u,maxs:m,firstLeafFace:f,numLeafFaces:p,firstLeafBrush:y,numLeafBrushes:h})}return o}function cd(t,e){let r=new DataView(t,e.offset,e.length),n=4,s=e.length/n;if(s%1!==0)throw new Y("Edge lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({vertices:[r.getUint16(a,!0),r.getUint16(a+2,!0)]})}return o}function ld(t,e){let r=e.length/4;if(r%1!==0)throw new Y("SurfEdge lump has invalid length");let n=new DataView(t,e.offset,e.length),s=new Int32Array(r);for(let o=0;o<r;o+=1)s[o]=n.getInt32(o*4,!0);return s}function dd(t,e){let r=new DataView(t,e.offset,e.length),n=48;if(e.length%n!==0)throw new Y("Model lump has invalid length");let s=e.length/n,o=[];for(let i=0;i<s;i+=1){let a=i*n,c=[r.getFloat32(a,!0),r.getFloat32(a+4,!0),r.getFloat32(a+8,!0)],l=[r.getFloat32(a+12,!0),r.getFloat32(a+16,!0),r.getFloat32(a+20,!0)],d=[r.getFloat32(a+24,!0),r.getFloat32(a+28,!0),r.getFloat32(a+32,!0)],u=r.getInt32(a+36,!0),m=r.getInt32(a+40,!0),f=r.getInt32(a+44,!0);o.push({mins:c,maxs:l,origin:d,headNode:u,firstFace:m,numFaces:f})}return o}function ud(t,e){let r=new DataView(t,e.offset,e.length),n=12,s=e.length/n;if(s%1!==0)throw new Y("Brush lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({firstSide:r.getInt32(a,!0),numSides:r.getInt32(a+4,!0),contents:r.getInt32(a+8,!0)})}return o}function md(t,e){let r=new DataView(t,e.offset,e.length),n=8,s=e.length/n;if(s%1!==0)throw new Y("Brush side lump has invalid length");let o=[];for(let i=0;i<s;i+=1){let a=i*n;o.push({planeIndex:r.getUint16(a,!0),texInfo:r.getInt16(a+2,!0)})}return o}function fd(t,e,r,n){let s=[],o=[],i=e.length/2,a=r.length/2,c=new DataView(t,e.offset,e.length),l=new DataView(t,r.offset,r.length);for(let d of n){if(d.firstLeafFace+d.numLeafFaces>i)throw new Y("Leaf faces reference data past lump bounds");if(d.firstLeafBrush+d.numLeafBrushes>a)throw new Y("Leaf brushes reference data past lump bounds");let u=[];for(let f=0;f<d.numLeafFaces;f+=1)u.push(c.getUint16((d.firstLeafFace+f)*2,!0));let m=[];for(let f=0;f<d.numLeafBrushes;f+=1)m.push(l.getUint16((d.firstLeafBrush+f)*2,!0));s.push(u),o.push(m)}return{leafFaces:s,leafBrushes:o}}function hd(t,e){if(e.length===0)return;if(e.length<4)throw new Y("Visibility lump too small");let r=new DataView(t,e.offset,e.length),n=r.getInt32(0,!0),s=4+n*8;if(n<0||s>e.length)throw new Y("Visibility lump truncated");let o=4,i=[];for(let a=0;a<n;a+=1){let c=r.getInt32(o,!0),l=r.getInt32(o+4,!0);o+=8;let d=e.offset+c,u=e.offset+l,m=e.offset+e.length;if(c<0||l<0||d>=m||u>=m)throw new Y("Visibility offsets out of range");i.push({pvs:Pa(t,d,n,e),phs:Pa(t,u,n,e)})}return{numClusters:n,clusters:i}}function Pa(t,e,r,n){let s=Math.ceil(r/8),o=new Uint8Array(s),i=new Uint8Array(t),a=e,c=0,l=n.offset+n.length;for(;c<s;){if(a>=l)throw new Y("Visibility data truncated");let d=i[a++];if(d!==0){o[c++]=d;continue}if(a>=l)throw new Y("Visibility run exceeds lump bounds");let u=i[a++];for(let m=0;m<u&&c<s;m+=1)o[c++]=0}return o}function pd(t,e){return t.map(r=>{if(!(r.lightOffset<0))return{offset:r.lightOffset,length:Math.max(0,e.length-r.lightOffset)}})}function ms(t,e,r){if(t.lightOffset<0||t.lightOffset>=e.byteLength)return;let n=e.byteLength-t.lightOffset,s=Math.min(r?.length??n,n);if(!(s<=0))return e.subarray(t.lightOffset,t.lightOffset+s)}var yd=844121161,gd=8,za=68,xd=[{x:-.525731,y:0,z:.850651},{x:-.442863,y:.238856,z:.864188},{x:-.295242,y:0,z:.955423},{x:-.309017,y:.5,z:.809017},{x:-.16246,y:.262866,z:.951056},{x:0,y:0,z:1},{x:0,y:.850651,z:.525731},{x:-.147621,y:.716567,z:.681718},{x:.147621,y:.716567,z:.681718},{x:0,y:.525731,z:.850651},{x:.309017,y:.5,z:.809017},{x:.525731,y:0,z:.850651},{x:.295242,y:0,z:.955423},{x:.442863,y:.238856,z:.864188},{x:.16246,y:.262866,z:.951056},{x:-.681718,y:.147621,z:.716567},{x:-.809017,y:.309017,z:.5},{x:-.587785,y:.425325,z:.688191},{x:-.850651,y:.525731,z:0},{x:-.864188,y:.442863,z:.238856},{x:-.716567,y:.681718,z:.147621},{x:-.688191,y:.587785,z:.425325},{x:-.5,y:.809017,z:.309017},{x:-.238856,y:.864188,z:.442863},{x:-.425325,y:.688191,z:.587785},{x:-.716567,y:.681718,z:-.147621},{x:-.5,y:.809017,z:-.309017},{x:-.525731,y:.850651,z:0},{x:0,y:.850651,z:-.525731},{x:-.238856,y:.864188,z:-.442863},{x:0,y:.955423,z:-.295242},{x:-.262866,y:.951056,z:-.16246},{x:0,y:1,z:0},{x:0,y:.955423,z:.295242},{x:-.262866,y:.951056,z:.16246},{x:.238856,y:.864188,z:.442863},{x:.262866,y:.951056,z:.16246},{x:.5,y:.809017,z:.309017},{x:.238856,y:.864188,z:-.442863},{x:.262866,y:.951056,z:-.16246},{x:.5,y:.809017,z:-.309017},{x:.850651,y:.525731,z:0},{x:.716567,y:.681718,z:.147621},{x:.716567,y:.681718,z:-.147621},{x:.525731,y:.850651,z:0},{x:.425325,y:.688191,z:.587785},{x:.864188,y:.442863,z:.238856},{x:.688191,y:.587785,z:.425325},{x:.809017,y:.309017,z:.5},{x:.681718,y:.147621,z:.716567},{x:.587785,y:.425325,z:.688191},{x:.955423,y:.295242,z:0},{x:1,y:0,z:0},{x:.951056,y:.16246,z:.262866},{x:.850651,y:-.525731,z:0},{x:.955423,y:-.295242,z:0},{x:.864188,y:-.442863,z:.238856},{x:.951056,y:-.16246,z:.262866},{x:.809017,y:-.309017,z:.5},{x:.681718,y:-.147621,z:.716567},{x:.850651,y:0,z:.525731},{x:.864188,y:.442863,z:-.238856},{x:.809017,y:.309017,z:-.5},{x:.951056,y:.16246,z:-.262866},{x:.525731,y:0,z:-.850651},{x:.681718,y:.147621,z:-.716567},{x:.681718,y:-.147621,z:-.716567},{x:.850651,y:0,z:-.525731},{x:.809017,y:-.309017,z:-.5},{x:.864188,y:-.442863,z:-.238856},{x:.951056,y:-.16246,z:-.262866},{x:.147621,y:.716567,z:-.681718},{x:.309017,y:.5,z:-.809017},{x:.425325,y:.688191,z:-.587785},{x:.442863,y:.238856,z:-.864188},{x:.587785,y:.425325,z:-.688191},{x:.688191,y:.587785,z:-.425325},{x:-.147621,y:.716567,z:-.681718},{x:-.309017,y:.5,z:-.809017},{x:0,y:.525731,z:-.850651},{x:-.525731,y:0,z:-.850651},{x:-.442863,y:.238856,z:-.864188},{x:-.295242,y:0,z:-.955423},{x:-.16246,y:.262866,z:-.951056},{x:0,y:0,z:-1},{x:.295242,y:0,z:-.955423},{x:.16246,y:.262866,z:-.951056},{x:-.442863,y:-.238856,z:-.864188},{x:-.309017,y:-.5,z:-.809017},{x:-.16246,y:-.262866,z:-.951056},{x:0,y:-.850651,z:-.525731},{x:-.147621,y:-.716567,z:-.681718},{x:.147621,y:-.716567,z:-.681718},{x:0,y:-.525731,z:-.850651},{x:.309017,y:-.5,z:-.809017},{x:.442863,y:-.238856,z:-.864188},{x:.16246,y:-.262866,z:-.951056},{x:.238856,y:-.864188,z:-.442863},{x:.5,y:-.809017,z:-.309017},{x:.425325,y:-.688191,z:-.587785},{x:.716567,y:-.681718,z:-.147621},{x:.688191,y:-.587785,z:-.425325},{x:.587785,y:-.425325,z:-.688191},{x:0,y:-.955423,z:-.295242},{x:0,y:-1,z:0},{x:.262866,y:-.951056,z:-.16246},{x:0,y:-.850651,z:.525731},{x:0,y:-.955423,z:.295242},{x:.238856,y:-.864188,z:.442863},{x:.262866,y:-.951056,z:.16246},{x:.5,y:-.809017,z:.309017},{x:.716567,y:-.681718,z:.147621},{x:.525731,y:-.850651,z:0},{x:-.238856,y:-.864188,z:-.442863},{x:-.5,y:-.809017,z:-.309017},{x:-.262866,y:-.951056,z:-.16246},{x:-.850651,y:-.525731,z:0},{x:-.716567,y:-.681718,z:-.147621},{x:-.716567,y:-.681718,z:.147621},{x:-.525731,y:-.850651,z:0},{x:-.5,y:-.809017,z:.309017},{x:-.238856,y:-.864188,z:.442863},{x:-.262866,y:-.951056,z:.16246},{x:-.864188,y:-.442863,z:.238856},{x:-.809017,y:-.309017,z:.5},{x:-.688191,y:-.587785,z:.425325},{x:-.681718,y:-.147621,z:.716567},{x:-.442863,y:-.238856,z:.864188},{x:-.587785,y:-.425325,z:.688191},{x:-.309017,y:-.5,z:.809017},{x:-.147621,y:-.716567,z:.681718},{x:-.425325,y:-.688191,z:.587785},{x:-.16246,y:-.262866,z:.951056},{x:.442863,y:-.238856,z:.864188},{x:.16246,y:-.262866,z:.951056},{x:.309017,y:-.5,z:.809017},{x:.147621,y:-.716567,z:.681718},{x:0,y:-.525731,z:.850651},{x:.425325,y:-.688191,z:.587785},{x:.587785,y:-.425325,z:.688191},{x:.688191,y:-.587785,z:.425325},{x:-.955423,y:.295242,z:0},{x:-.951056,y:.16246,z:.262866},{x:-1,y:0,z:0},{x:-.850651,y:0,z:.525731},{x:-.955423,y:-.295242,z:0},{x:-.951056,y:-.16246,z:.262866},{x:-.864188,y:.442863,z:-.238856},{x:-.951056,y:.16246,z:-.262866},{x:-.809017,y:.309017,z:-.5},{x:-.864188,y:-.442863,z:-.238856},{x:-.951056,y:-.16246,z:-.262866},{x:-.809017,y:-.309017,z:-.5},{x:-.681718,y:.147621,z:-.716567},{x:-.681718,y:-.147621,z:-.716567},{x:-.850651,y:0,z:-.525731},{x:-.688191,y:.587785,z:-.425325},{x:-.587785,y:.425325,z:-.688191},{x:-.425325,y:.688191,z:-.587785},{x:-.425325,y:-.688191,z:-.587785},{x:-.587785,y:-.425325,z:-.688191},{x:-.688191,y:-.587785,z:-.425325}],le=class extends Error{},ar=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),ti(n.buffer)}};function Fa(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function Ur(t,e,r,n){if(r!==0&&(e<za||e+r>t.byteLength))throw new le(`${n} section is out of bounds`)}function bd(t){if(t.byteLength<za)throw new le("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==yd)throw new le(`Invalid MD2 ident: ${r}`);if(n!==gd)throw new le(`Unsupported MD2 version: ${n}`);let s={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)},o=40+s.numVertices*4;if(s.frameSize!==o)throw new le(`Unexpected frame size ${s.frameSize}, expected ${o}`);if(s.offsetEnd>t.byteLength)throw new le("MD2 offset_end exceeds buffer length");return s}function vd(t,e){let r=e.numSkins*64;Ur(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),s=[];for(let o=0;o<e.numSkins;o+=1)s.push({name:Fa(n,o*64,64)});return s}function Sd(t,e){let r=e.numTexCoords*4;Ur(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),s=[];for(let o=0;o<e.numTexCoords;o+=1){let i=o*4;s.push({s:n.getInt16(i,!0),t:n.getInt16(i+2,!0)})}return s}function Md(t,e){let r=e.numTriangles*12;Ur(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),s=[];for(let o=0;o<e.numTriangles;o+=1){let i=o*12,a=[n.getUint16(i,!0),n.getUint16(i+2,!0),n.getUint16(i+4,!0)],c=[n.getUint16(i+6,!0),n.getUint16(i+8,!0),n.getUint16(i+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new le("Triangle references out of range vertex or texcoord");s.push({vertexIndices:a,texCoordIndices:c})}return s}function Ad(t,e){let r=e.numFrames*e.frameSize;Ur(t,e.offsetFrames,r,"frames");let n=[];for(let s=0;s<e.numFrames;s+=1){let o=e.offsetFrames+s*e.frameSize,i=new DataView(t,o,e.frameSize),a={x:i.getFloat32(0,!0),y:i.getFloat32(4,!0),z:i.getFloat32(8,!0)},c={x:i.getFloat32(12,!0),y:i.getFloat32(16,!0),z:i.getFloat32(20,!0)},l=Fa(i,24,16),d=[];for(let u=0;u<e.numVertices;u+=1){let m=40+u*4,f={x:i.getUint8(m)*a.x+c.x,y:i.getUint8(m+1)*a.y+c.y,z:i.getUint8(m+2)*a.z+c.z},p=i.getUint8(m+3),y=xd[p];if(!y)throw new le(`Invalid normal index ${p} in frame ${l}`);d.push({position:f,normalIndex:p,normal:y})}n.push({name:l,vertices:d})}return n}function _d(t,e){let r=e.numGlCommands*4;if(Ur(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),s=[],o=0;for(;;){if(o+4>r)throw new le("GL command list ended unexpectedly");let i=n.getInt32(o,!0);if(o+=4,i===0)break;let a=Math.abs(i),c=[],l=a*12;if(o+l>r)throw new le("GL command vertex block exceeds buffer");for(let d=0;d<a;d+=1){let u=n.getFloat32(o,!0),m=n.getFloat32(o+4,!0),f=n.getInt32(o+8,!0);if(o+=12,f<0||f>=e.numVertices)throw new le("GL command references invalid vertex index");c.push({s:u,t:m,vertexIndex:f})}s.push({mode:i>0?"strip":"fan",vertices:c})}if(o!==r)throw new le("GL command list did not consume expected data");return s}function ti(t){let e=bd(t),r=vd(t,e),n=Sd(t,e),s=Md(t,e),o=Ad(t,e),i=_d(t,e);return{header:e,skins:r,texCoords:n,triangles:s,frames:o,glCommands:i}}function Ta(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,s=n.replace(/\d+$/,"")||n,o=r;for(;o+1<t.length&&(t[o+1].name.replace(/\d+$/,"")||t[o+1].name)===s;)o+=1;e.push({name:s,firstFrame:r,lastFrame:o}),r=o+1}return e}var Ca=860898377,wd=15,Te=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Vr(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function Ld(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 fs(t,e,r,n){if(e<0||e+r>n)throw new Te(`${t} exceeds buffer bounds`)}function Ed(t){let e=t.getInt32(0,!0);if(e!==Ca)throw new Te(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==wd)throw new Te(`Unsupported MD3 version: ${r}`);let n=Vr(t,8,64),s=t.getInt32(72,!0),o=t.getInt32(76,!0),i=t.getInt32(80,!0),a=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),d=t.getInt32(96,!0),u=t.getInt32(100,!0),m=t.getInt32(104,!0);if(o<=0||a<0||i<0)throw new Te("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:s,numFrames:o,numTags:i,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:d,ofsSurfaces:u,ofsEnd:m}}function Pd(t,e){let r=[];fs("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let s=0;s<e.numFrames;s+=1){let o=e.ofsFrames+s*56;r.push({minBounds:{x:t.getFloat32(o,!0),y:t.getFloat32(o+4,!0),z:t.getFloat32(o+8,!0)},maxBounds:{x:t.getFloat32(o+12,!0),y:t.getFloat32(o+16,!0),z:t.getFloat32(o+20,!0)},localOrigin:{x:t.getFloat32(o+24,!0),y:t.getFloat32(o+28,!0),z:t.getFloat32(o+32,!0)},radius:t.getFloat32(o+36,!0),name:Vr(t,o+40,16)})}return r}function Id(t,e){let r=[],s=e.numFrames*e.numTags*112;fs("Tags",e.ofsTags,s,t.byteLength);for(let o=0;o<e.numFrames;o+=1){let i=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(o*e.numTags+a)*112,l=c+64,d=l+12;i.push({name:Vr(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(d,!0),y:t.getFloat32(d+4,!0),z:t.getFloat32(d+8,!0)},{x:t.getFloat32(d+12,!0),y:t.getFloat32(d+16,!0),z:t.getFloat32(d+20,!0)},{x:t.getFloat32(d+24,!0),y:t.getFloat32(d+28,!0),z:t.getFloat32(d+32,!0)}]})}r.push(i)}return r}function zd(t,e){let r=t.getInt32(e,!0);if(r!==Ca)throw new Te(`Invalid surface ident at ${e}: ${r}`);let n=Vr(t,e+4,64),s=t.getInt32(e+68,!0),o=t.getInt32(e+72,!0),i=t.getInt32(e+76,!0),a=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),d=t.getInt32(e+92,!0),u=t.getInt32(e+96,!0),m=t.getInt32(e+100,!0),f=t.getInt32(e+104,!0);if(o<=0||a<=0||c<=0)throw new Te(`Invalid surface counts for ${n}`);let p=f;fs(`Surface ${n}`,e,p,t.byteLength);let y=[],h=e+l;for(let _=0;_<c;_+=1){let L=h+_*12;y.push({indices:[t.getInt32(L,!0),t.getInt32(L+4,!0),t.getInt32(L+8,!0)]})}let g=[],S=e+d;for(let _=0;_<i;_+=1){let L=S+_*68;g.push({name:Vr(t,L,64),shaderIndex:t.getInt32(L+64,!0)})}let b=[],M=e+u;for(let _=0;_<a;_+=1){let L=M+_*8;b.push({s:t.getFloat32(L,!0),t:t.getFloat32(L+4,!0)})}let v=[],A=e+m;for(let _=0;_<o;_+=1){let L=[];for(let T=0;T<a;T+=1){let w=A+(_*a+T)*8,H=t.getInt16(w,!0)/64,G=t.getInt16(w+2,!0)/64,V=t.getInt16(w+4,!0)/64,C=t.getUint16(w+6,!0);L.push({position:{x:H,y:G,z:V},latLng:C,normal:Ld(C)})}v.push(L)}return{surface:{name:n,flags:s,numFrames:o,shaders:g,triangles:y,texCoords:b,vertices:v},nextOffset:e+f}}function ri(t){if(t.byteLength<108)throw new Te("MD3 buffer too small for header");let e=new DataView(t),r=Ed(e);fs("MD3 end",r.ofsEnd,0,t.byteLength);let n=Pd(e,r),s=Id(e,r),o=[],i=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=zd(e,i);o.push(c),i=l}if(i!==r.ofsEnd)throw new Te("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:s,surfaces:o}}var cr=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e);return ri(r.slice().buffer)}};var Fd=1229214514,Td=2,Ra=64,Ba=12,pt=class extends Error{};function Cd(t,e,r){let n=[];for(let s=0;s<r;s+=1){let o=t.getUint8(e+s);if(o===0)break;n.push(o)}return String.fromCharCode(...n)}function ni(t){if(t.byteLength<Ba)throw new pt("Sprite buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0),s=e.getInt32(8,!0);if(r!==Fd)throw new pt(`Invalid Sprite ident: ${r}`);if(n!==Td)throw new pt(`Unsupported Sprite version: ${n}`);let o=[],i=16+Ra,a=Ba;for(let c=0;c<s;c+=1){if(a+i>t.byteLength)throw new pt("Sprite frame data exceeds buffer length");let l=e.getInt32(a,!0),d=e.getInt32(a+4,!0),u=e.getInt32(a+8,!0),m=e.getInt32(a+12,!0),f=Cd(e,a+16,Ra);o.push({width:l,height:d,originX:u,originY:m,name:f}),a+=i}return{ident:r,version:n,numFrames:s,frames:o}}var lr=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),ni(n.buffer)}};function ka(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,s=t.time+e;return n?s=(s%r+r)%r:s>r&&(s=r),{...t,time:Math.max(0,Math.min(s,r))}}function Oa(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,s=t.time/r;if(!n&&s>=e)return{frame:t.sequence.end,nextFrame:t.sequence.end,lerp:0};let o=n?s%e:Math.min(s,e-1),i=Math.floor(o),a=t.sequence.start+i,c=i+1>=e?n?t.sequence.start:t.sequence.end:a+1,l=!n&&i>=e-1?0:o-i;return{frame:a,nextFrame:c,lerp:l}}function Da(t){return{sequence:t,time:0}}function Na(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 Gr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function hs(t){if(t.byteLength<100)throw new Gr("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(),s=e.getInt32(32,!0),o=e.getInt32(36,!0),i=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],a=new Uint8Array(t,56,32),c=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),d=e.getInt32(92,!0),u=e.getInt32(96,!0);if(s<=0||o<=0)throw new Gr("Invalid WAL dimensions");let m=[],f=s,p=o;for(let y=0;y<i.length;y+=1){let h=i[y],g=Math.max(1,f*p|0);if(h<=0||h+g>t.byteLength)throw new Gr(`Invalid WAL mip offset for level ${y}`);let S=new Uint8Array(t,h,g);m.push({level:y,width:f,height:p,data:S}),f=Math.max(1,f>>1),p=Math.max(1,p>>1)}return{name:n,width:s,height:o,mipmaps:m,animName:c,flags:l,contents:d,value:u}}var kt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Ha(t){if(t.byteLength<128)throw new kt("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),s=e.getUint8(3),o=e.getUint16(4,!0),i=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new kt("Unsupported PCX encoding");if(s!==8)throw new kt("Only 8bpp PCX files are supported");let l=a-o+1,d=c-i+1,u=e.getUint16(66,!0),m=t.byteLength-769;if(m<128||new DataView(t,m,1).getUint8(0)!==12)throw new kt("Missing PCX palette");let f=new Uint8Array(t,m+1,768),p=new Uint8Array(t,128,m-128),y=new Uint8Array(l*d),h=0,g=0;for(let S=0;S<d;S+=1){let b=0;for(;b<u&&h<p.length;){let M=1,v=p[h++];if((v&192)===192){if(M=v&63,h>=p.length)throw new kt("Unexpected end of PCX RLE data");v=p[h++]}for(let A=0;A<M&&b<u;A+=1)b<l&&(y[g++]=v),b+=1}}return{width:l,height:d,bitsPerPixel:s,pixels:y,palette:f}}function ps(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],s=n*3,o=r*4;e[o]=t.palette[s],e[o+1]=t.palette[s+1],e[o+2]=t.palette[s+2],e[o+3]=n===255?0:255}return e}var dr=class{constructor(e={}){this.cache=new ht(e.capacity??128)}get size(){return this.cache.size}get(e){return this.cache.get(e.toLowerCase())}set(e,r){this.cache.set(e.toLowerCase(),r)}clear(){this.cache.clear()}};function si(t,e){let r=[];for(let n of t.mipmaps){let s=new Uint8Array(n.width*n.height*4);for(let o=0;o<n.data.length;o+=1){let i=n.data[o],a=i*3,c=o*4;s[c]=e[a],s[c+1]=e[a+1],s[c+2]=e[a+2],s[c+3]=i===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:s})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function Ua(t){let e=ps(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Va(t,e){return si(hs(t),e)}var Ot=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function oi(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function ys(t){if(t.byteLength<44)throw new Ot("WAV buffer too small");let e=new DataView(t);if(oi(e,0,4)!=="RIFF"||oi(e,8,4)!=="WAVE")throw new Ot("Invalid WAV header");let r=12,n=-1,s=-1,o=0,i=0;for(;r+8<=t.byteLength;){let p=oi(e,r,4),y=e.getUint32(r+4,!0),h=r+8;p==="fmt "?(n=h,o=y):p==="data"&&(s=h,i=y),r=h+y}if(n===-1||s===-1)throw new Ot("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),d=e.getUint16(n+14,!0);if(a!==1)throw new Ot("Only PCM WAV is supported");let u=d/8,m=i/(u*c),f=new Float32Array(m*c);for(let p=0;p<m;p+=1)for(let y=0;y<c;y+=1){let h=p*c+y,g=s+h*u,S=0;if(d===8)S=e.getUint8(g),f[h]=(S-128)/128;else if(d===16)S=e.getInt16(g,!0),f[h]=S/32768;else if(d===24){let b=e.getUint8(g),M=e.getUint8(g+1),v=e.getInt8(g+2);S=b|M<<8|v<<16,f[h]=S/8388608}else throw new Ot(`Unsupported bitsPerSample: ${d}`)}return{sampleRate:l,channels:c,bitsPerSample:d,samples:f}}var Rd=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),s,o,i,a=e;for(s=0;s<256;s++){for(i=s<<24,o=8;o>0;--o)i=2147483648&i?i<<1^r:i<<1;n[s]=i}for(s=0;s<t.length;s++)a=a<<8^n[255&(a>>24^t[s])];return a};var ii=(t,e=Rd)=>{let r=h=>new Uint8Array(h.length/2).map(((g,S)=>parseInt(h.substring(2*S,2*(S+1)),16))),n=h=>r(h)[0],s=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(((h,g)=>s.set(h,g)));let o=new Uint8Array(t.length),i,a,c,l=!1,d=0,u=42,m=t.length>13&&t.substring(0,9)==="dynEncode",f=0;m&&(f=11,a=n(t.substring(9,f)),a<=1&&(f+=2,u=n(t.substring(11,f))),a===1&&(f+=8,c=(h=>new DataView(r(h).buffer).getInt32(0,!0))(t.substring(13,f))));let p=256-u;for(let h=f;h<t.length;h++)if(i=t.charCodeAt(h),i!==61||l){if(i===92&&h<t.length-5&&m){let g=t.charCodeAt(h+1);g!==117&&g!==85||(i=parseInt(t.substring(h+2,h+6),16),h+=5)}if(i>255){let g=s.get(i);g&&(i=g+127)}l&&(l=!1,i-=64),o[d++]=i<u&&i>0?i+p:i-u}else l=!0;let y=o.subarray(0,d);if(m&&a===1){let h=e(y);if(h!==c){let g="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",g+`
2
2
  `,"Expected: "+c+"; Got: "+h+`
3
- `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(g)}}return y};function Z(){let t=Uint8Array,e=Float32Array;Z.modules||Object.defineProperties(Z,{modules:{value:new WeakMap},setModule:{value(r,n){Z.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let s=Z.modules.get(r);return s||(n?s=WebAssembly.compile(ii(n)):(n=r.wasm,s=Z.inflateDynEncodeString(n).then(o=>WebAssembly.compile(o))),Z.modules.set(r,s)),s}},concatFloat32:{value(r,n){let s=new e(n),o=0,i=0;for(;o<r.length;)s.set(r[o],i),i+=r[o++].length;return s}},getDecodedAudio:{value:(r,n,s,o,i)=>({errors:r,channelData:n,samplesDecoded:s,sampleRate:o,bitDepth:i})},getDecodedAudioMultiChannel:{value(r,n,s,o,i,a){let c=[],l,d;for(l=0;l<s;l++){let u=[];for(d=0;d<n.length;)u.push(n[d++][l]||[]);c.push(Z.concatFloat32(u,o))}return Z.getDecodedAudio(r,c,o,i,a)}},inflateDynEncodeString:{value(r){return r=ii(r),new Promise(n=>{let s=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;Z.getModule(Z,s).then(o=>WebAssembly.instantiate(o,{})).then(({exports:o})=>{let i=new Map(Object.entries(o)),a=i.get("puff"),c=i.get("memory").buffer,l=new t(c),d=new DataView(c),u=i.get("__heap_base"),m=r.length,f=u;u+=4,d.setInt32(f,m,!0);let p=u;u+=m,l.set(r,p);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,p,f),n(l.slice(u,u+d.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,s)=>{let o=[],i=0;for(;i<n;)o.push(r.slice(i*s,i++*s+s));return o},this.allocateTypedArray=(r,n,s=!0)=>{let o=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return s&&this._pointers.add(o),{ptr:o,len:r,buf:new n(this._wasm.HEAP,o,r)}},this.free=()=>{this._pointers.forEach(r=>{this._wasm.free(r)}),this._pointers.clear()},this.codeToString=r=>{let n=[],s=new Uint8Array(this._wasm.HEAP);for(let o=s[r];o!==0;o=s[++r])n.push(o);return String.fromCharCode.apply(null,n)},this.addError=(r,n,s,o,i,a)=>{r.push({message:n,frameLength:s,frameNumber:o,inputBytes:i,outputSamples:a})},this.instantiate=(r,n)=>(n&&Z.setModule(r,n),this._wasm=new r(Z).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Xa=xl(Wa(),1);var Bd=()=>globalThis.Worker||Xa.default,ur=class extends Bd(){constructor(e,r,n,s){Z.modules||new Z;let o=Z.modules.get(n);if(!o){let i="text/javascript",a,c=`'use strict';(${((l,d,u)=>{let m,f,p=new Promise(y=>{f=y});self.onmessage=({data:{id:y,command:h,data:g}})=>{let S=p,b={id:y},M;h==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),m=new l(g.options),f()):h==="free"?m.free():h==="ready"?S=S.then(()=>m.ready):h==="reset"?S=S.then(()=>m.reset()):(Object.assign(b,m[h](Array.isArray(g)?g.map(v=>new Uint8Array(v)):new Uint8Array(g))),M=b.channelData?b.channelData.map(v=>v.buffer):[]),S.then(()=>self.postMessage(b,M))}}).toString()})(${n}, ${Z}, ${s})`;try{a=typeof process.versions.node<"u"}catch{}o=a?`data:${i};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:i})),Z.modules.set(n,o)}super(o,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:i})=>{let{id:a,...c}=i;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new s(Z).getModule().then(i=>{this.postToDecoder("init",{module:i,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 gs=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var ee=Symbol,Ka=", ",F=(()=>{let t="front",e="side",r="rear",n="left",s="center",o="right";return["",t+" ",e+" ",r+" "].map(i=>[[n,o],[n,o,s],[n,s,o],[s,n,o],[s]].flatMap(a=>a.map(c=>i+c).join(Ka)))})(),Ye="LFE",yt="monophonic (mono)",gt="stereo",Wr="surround",te=(t,...e)=>`${[yt,gt,`linear ${Wr}`,"quadraphonic",`5.0 ${Wr}`,`5.1 ${Wr}`,`6.1 ${Wr}`,`7.1 ${Wr}`][t-1]} (${e.join(Ka)})`,Xr=[yt,te(2,F[0][0]),te(3,F[0][2]),te(4,F[1][0],F[3][0]),te(5,F[1][2],F[3][0]),te(6,F[1][2],F[3][0],Ye),te(7,F[1][2],F[2][0],F[3][4],Ye),te(8,F[1][2],F[2][0],F[3][0],Ye)],Ya=192e3,qa=176400,xs=96e3,bs=88200,$a=64e3,xt=48e3,mr=44100,fr=32e3,hr=24e3,pr=22050,yr=16e3,vs=12e3,Ss=11025,gr=8e3,ja=7350,Ve="absoluteGranulePosition",k="bandwidth",me="bitDepth",fe="bitrate",Kr=fe+"Maximum",Yr=fe+"Minimum",qr=fe+"Nominal",qe="buffer",$r=qe+"Fullness",Q="codec",he=Q+"Frames",jr="coupledStreamCount",xr="crc",Qr=xr+"16",Jr=xr+"32",q="data",z="description",$e="duration",br="emphasis",Zr="hasOpusPadding",we="header",bt="isContinuedPacket",en="isCopyrighted",vt="isFirstPage",tn="isHome",Le="isLastPage",et="isOriginal",tt="isPrivate",rn="isVbr",Me="layer",x="length",B="mode",rt=B+"Extension",Ms="mpeg",nt=Ms+"Version",nn="numberAACFrames",sn="outputGain",Dt="preSkip",on="profile",As=ee(),st="protection",ai="rawData",Te="segments",O="subarray",St="version",Nt="vorbis",an=Nt+"Comments",vr=Nt+"Setup",_s="block",cn=_s+"ingStrategy",ws=ee(),ot=_s+"Size",Mt=_s+"size0",At=_s+"size1",ln=ee(),Ls="channel",it=Ls+"MappingFamily",dn=Ls+"MappingTable",pe=Ls+"Mode",un=ee(),I=Ls+"s",Qa="copyright",mn=Qa+"Id",fn=Qa+"IdStart",at="frame",ct=at+"Count",Ae=at+"Length",Es="Number",lt=at+Es,je=at+"Padding",R=at+"Size",Ja="Rate",hn="inputSample"+Ja,ci="page",Ht=ci+"Checksum",Sr=ee(),_t=ci+"SegmentTable",oe=ci+"Sequence"+Es,li="sample",pn=li+Es,D=li+Ja,Qe=ee(),N=li+"s",Ps="stream",yn=Ps+"Count",gn=Ps+"Info",Je=Ps+"Serial"+Es,di=Ps+"StructureVersion",ui="total",Ut=ui+"BytesOut",Vt=ui+"Duration",Gt=ui+"Samples",U=ee(),Re=ee(),xn=ee(),wt=ee(),Ge=ee(),Is=ee(),mi=ee(),Lt=ee(),W=ee(),Be=ee(),ke=ee(),Ze=ee(),Et=ee(),zs=ee(),We=ee(),Xe=ee(),Oe=ee(),Fs=ee(),ye=Uint8Array,Pt=DataView,X="reserved",ge="bad",Mr="free",bn="none",Cs="16bit CRC";var fi=(t,e,r)=>{for(let n=0;n<t[x];n++){let s=e(n);for(let o=8;o>0;o--)s=r(s);t[n]=s}return t},Od=fi(new ye(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[fi(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[fi(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){re.push(new Uint16Array(256)),ne.push(new Uint32Array(256));for(let e=0;e<=255;e++)re[t+1][e]=re[0][re[t][e]>>>8]^re[t][e]<<8,ne[t+1][e]=ne[t][e]>>>8^ne[0][ne[t][e]&255]}var ec=t=>{let e=0,r=t[x];for(let n=0;n!==r;n++)e=Od[e^t[n]];return e},tc=t=>{let e=t[x],r=e-16,n=0,s=0;for(;s<=r;)n^=t[s++]<<8|t[s++],n=re[15][n>>8]^re[14][n&255]^re[13][t[s++]]^re[12][t[s++]]^re[11][t[s++]]^re[10][t[s++]]^re[9][t[s++]]^re[8][t[s++]]^re[7][t[s++]]^re[6][t[s++]]^re[5][t[s++]]^re[4][t[s++]]^re[3][t[s++]]^re[2][t[s++]]^re[1][t[s++]]^re[0][t[s++]];for(;s!==e;)n=(n&255)<<8^re[0][n>>8^t[s++]];return n},rc=t=>{let e=t[x],r=e-16,n=0,s=0;for(;s<=r;)n=ne[15][(t[s++]^n)&255]^ne[14][(t[s++]^n>>>8)&255]^ne[13][(t[s++]^n>>>16)&255]^ne[12][t[s++]^n>>>24]^ne[11][t[s++]]^ne[10][t[s++]]^ne[9][t[s++]]^ne[8][t[s++]]^ne[7][t[s++]]^ne[6][t[s++]]^ne[5][t[s++]]^ne[4][t[s++]]^ne[3][t[s++]]^ne[2][t[s++]]^ne[1][t[s++]]^ne[0][t[s++]];for(;s!==e;)n=ne[0][(n^t[s++])&255]^n>>>8;return n^-1},Sn=(...t)=>{let e=new ye(t.reduce((r,n)=>r+n[x],0));return t.reduce((r,n)=>(e.set(n,r),r+n[x]),0),e},Ee=t=>String.fromCharCode(...t),Za=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],vn=t=>Za[t&15]<<4|Za[t>>4],Ts=class{constructor(e){this._data=e,this._pos=e[x]*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,(vn(this._data[r-1])<<8)+vn(this._data[r])>>7-n&255}},nc=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),s=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,s=~s+1),s>1048575&&console.warn("This platform does not support BigInt"),r*(n+s*2**32)}};var Mn=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[We]()}[Xe](){this._isEnabled=!0}[We](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[zs](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}}[W](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[Be](e,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var ce=new WeakMap,de=new WeakMap;var xe=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[mi](){let e;do{if(e=yield*this.Frame[ke](this._codecParser,this._headerCache,0),e)return e;this._codecParser[Re](1)}while(!0)}*[Lt](e){let r=yield*this[mi](),n=de.get(r)[x];if(e||this._codecParser._flushing||(yield*this.Header[W](this._codecParser,this._headerCache,n)))return this._headerCache[Xe](),this._codecParser[Re](n),this._codecParser[wt](r),r;this._codecParser[Ge](`Missing ${at} at ${n} bytes from current position.`,`Dropping current ${at} and trying again.`),this._headerCache[We](),this._codecParser[Re](1)}};var Wt=class{constructor(e,r){de.set(this,{[we]:e}),this[q]=r}};var Pe=class extends Wt{static*[ke](e,r,n,s,o){let i=yield*e[W](n,s,o);if(i){let a=ce.get(i)[Ae],c=ce.get(i)[N],l=(yield*n[U](a,o))[O](0,a);return new r(i,l,c)}else return null}constructor(e,r,n){super(e,r),this[we]=e,this[N]=n,this[$e]=n/e[D]*1e3,this[lt]=null,this[Ut]=null,this[Gt]=null,this[Vt]=null,de.get(this)[x]=r[x]}};var hi="unsynchronizationFlag",pi="extendedHeaderFlag",yi="experimentalFlag",gi="footerPresent",An=class t{static*getID3v2Header(e,r,n){let o={},i=yield*e[U](3,n);if(i[0]!==73||i[1]!==68||i[2]!==51||(i=yield*e[U](10,n),o[St]=`id3v2.${i[3]}.${i[4]}`,i[5]&15)||(o[hi]=!!(i[5]&128),o[pi]=!!(i[5]&64),o[yi]=!!(i[5]&32),o[gi]=!!(i[5]&16),i[6]&128||i[7]&128||i[8]&128||i[9]&128))return null;let a=i[6]<<21|i[7]<<14|i[8]<<7|i[9];return o[x]=10+a,new t(o)}constructor(e){this[St]=e[St],this[hi]=e[hi],this[pi]=e[pi],this[yi]=e[yi],this[gi]=e[gi],this[x]=e[x]}};var Ie=class{constructor(e){ce.set(this,e),this[me]=e[me],this[fe]=null,this[I]=e[I],this[pe]=e[pe],this[D]=e[D]}};var cc={0:[Mr,Mr,Mr,Mr,Mr],16:[32,32,32,32,8],240:[ge,ge,ge,ge,ge]},Rs=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)cc[t<<4]=[t*32,Rs(t,4,0),Rs(t,4,-1),Rs(t,8,4),Rs(t,8,0)];var Dd=0,Nd=1,Hd=2,Ud=3,sc=4,Bs="bands ",ks=" to 31",oc={0:Bs+4+ks,16:Bs+8+ks,32:Bs+12+ks,48:Bs+16+ks},Xt="bitrateIndex",_n="v2",Us="v1",Os="Intensity stereo ",Ds=", MS stereo ",Ns="on",Hs="off",Vd={0:Os+Hs+Ds+Hs,16:Os+Ns+Ds+Hs,32:Os+Hs+Ds+Ns,48:Os+Ns+Ds+Ns},xi={0:{[z]:X},2:{[z]:"Layer III",[je]:1,[rt]:Vd,[Us]:{[Xt]:Hd,[N]:1152},[_n]:{[Xt]:sc,[N]:576}},4:{[z]:"Layer II",[je]:1,[rt]:oc,[N]:1152,[Us]:{[Xt]:Nd},[_n]:{[Xt]:sc}},6:{[z]:"Layer I",[je]:4,[rt]:oc,[N]:384,[Us]:{[Xt]:Dd},[_n]:{[Xt]:Ud}}},bi="MPEG Version ",ic="ISO/IEC ",Gd={0:{[z]:`${bi}2.5 (later extension of MPEG 2)`,[Me]:_n,[D]:{0:Ss,4:vs,8:gr,12:X}},8:{[z]:X},16:{[z]:`${bi}2 (${ic}13818-3)`,[Me]:_n,[D]:{0:pr,4:hr,8:yr,12:X}},24:{[z]:`${bi}1 (${ic}11172-3)`,[Me]:Us,[D]:{0:mr,4:xt,8:fr,12:X}},length:x},Wd={0:Cs,1:bn},Xd={0:bn,1:"50/15 ms",2:X,3:"CCIT J.17"},ac={0:{[I]:2,[z]:gt},64:{[I]:2,[z]:"joint "+gt},128:{[I]:2,[z]:"dual channel"},192:{[I]:1,[z]:yt}},Kt=class t extends Ie{static*[W](e,r,n){let s={},o=yield*An.getID3v2Header(e,r,n);o&&(yield*e[U](o[x],n),e[Re](o[x]));let i=yield*e[U](4,n),a=Ee(i[O](0,4)),c=r[W](a);if(c)return new t(c);if(i[0]!==255||i[1]<224)return null;let l=Gd[i[1]&24];if(l[z]===X)return null;let d=i[1]&6;if(xi[d][z]===X)return null;let u={...xi[d],...xi[d][l[Me]]};if(s[nt]=l[z],s[Me]=u[z],s[N]=u[N],s[st]=Wd[i[1]&1],s[x]=4,s[fe]=cc[i[2]&240][u[Xt]],s[fe]===ge||(s[D]=l[D][i[2]&12],s[D]===X)||(s[je]=i[2]&2&&u[je],s[tt]=!!(i[2]&1),s[Ae]=Math.floor(125*s[fe]*s[N]/s[D]+s[je]),!s[Ae]))return null;let m=i[3]&192;if(s[pe]=ac[m][z],s[I]=ac[m][I],s[rt]=u[rt][i[3]&48],s[en]=!!(i[3]&8),s[et]=!!(i[3]&4),s[br]=Xd[i[3]&3],s[br]===X)return null;s[me]=16;{let{length:f,frameLength:p,samples:y,...h}=s;r[Be](a,s,h)}return new t(s)}constructor(e){super(e),this[fe]=e[fe],this[br]=e[br],this[je]=e[je],this[en]=e[en],this[et]=e[et],this[tt]=e[tt],this[Me]=e[Me],this[rt]=e[rt],this[nt]=e[nt],this[st]=e[st]}};var wn=class t extends Pe{static*[ke](e,r,n){return yield*super[ke](Kt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Ln=class extends xe{constructor(e,r,n){super(e,r),this.Frame=wn,this.Header=Kt,n(this[Q])}get[Q](){return Ms}*[Ze](){return yield*this[Lt]()}};var Kd={0:"MPEG-4",8:"MPEG-2"},Yd={0:"valid",2:ge,4:ge,6:ge},qd={0:Cs,1:bn},$d={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},jd={0:xs,4:bs,8:$a,12:xt,16:mr,20:fr,24:hr,28:pr,32:yr,36:vs,40:Ss,44:gr,48:ja,52:X,56:X,60:"frequency is written explicitly"},lc={0:{[I]:0,[z]:"Defined in AOT Specific Config"},64:{[I]:1,[z]:yt},128:{[I]:2,[z]:te(2,F[0][0])},192:{[I]:3,[z]:te(3,F[1][3])},256:{[I]:4,[z]:te(4,F[1][3],F[3][4])},320:{[I]:5,[z]:te(5,F[1][3],F[3][0])},384:{[I]:6,[z]:te(6,F[1][3],F[3][0],Ye)},448:{[I]:8,[z]:te(8,F[1][3],F[2][0],F[3][0],Ye)}},Yt=class t extends Ie{static*[W](e,r,n){let s={},o=yield*e[U](7,n),i=Ee([o[0],o[1],o[2],o[3]&252|o[6]&3]),a=r[W](i);if(a)Object.assign(s,a);else{if(o[0]!==255||o[1]<240||(s[nt]=Kd[o[1]&8],s[Me]=Yd[o[1]&6],s[Me]===ge))return null;let l=o[1]&1;s[st]=qd[l],s[x]=l?7:9,s[As]=o[2]&192,s[Qe]=o[2]&60;let d=o[2]&2;if(s[on]=$d[s[As]],s[D]=jd[s[Qe]],s[D]===X)return null;s[tt]=!!d,s[un]=(o[2]<<8|o[3])&448,s[pe]=lc[s[un]][z],s[I]=lc[s[un]][I],s[et]=!!(o[3]&32),s[tn]=!!(o[3]&8),s[mn]=!!(o[3]&8),s[fn]=!!(o[3]&4),s[me]=16,s[N]=1024,s[nn]=o[6]&3;{let{length:u,channelModeBits:m,profileBits:f,sampleRateBits:p,frameLength:y,samples:h,numberAACFrames:g,...S}=s;r[Be](i,s,S)}}if(s[Ae]=(o[3]<<11|o[4]<<3|o[5]>>5)&8191,!s[Ae])return null;let c=(o[5]<<6|o[6]>>2)&2047;return s[$r]=c===2047?"VBR":c,new t(s)}constructor(e){super(e),this[mn]=e[mn],this[fn]=e[fn],this[$r]=e[$r],this[tn]=e[tn],this[et]=e[et],this[tt]=e[tt],this[Me]=e[Me],this[x]=e[x],this[nt]=e[nt],this[nn]=e[nn],this[on]=e[on],this[st]=e[st]}get audioSpecificConfig(){let e=ce.get(this),r=e[As]+64<<5|e[Qe]<<5|e[un]>>3,n=new ye(2);return new Pt(n[qe]).setUint16(0,r,!1),n}};var En=class t extends Pe{static*[ke](e,r,n){return yield*super[ke](Yt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Pn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=En,this.Header=Yt,n(this[Q])}get[Q](){return"aac"}*[Ze](){return yield*this[Lt]()}};var It=class t extends Pe{static _getFrameFooterCrc16(e){return(e[e[x]-2]<<8)+e[e[x]-1]}static[Fs](e){let r=t._getFrameFooterCrc16(e),n=tc(e[O](0,-2));return r===n}constructor(e,r,n){r[gn]=n,r[Qr]=t._getFrameFooterCrc16(e),super(r,e,ce.get(r)[N])}};var dc="get from STREAMINFO metadata block",Qd={0:"Fixed",1:"Variable"},uc={0:X,16:192};for(let t=2;t<16;t++)uc[t<<4]=t<6?576*2**(t-2):2**t;var Jd={0:dc,1:bs,2:qa,3:Ya,4:gr,5:yr,6:pr,7:hr,8:fr,9:mr,10:xt,11:xs,15:ge},Zd={0:{[I]:1,[z]:yt},16:{[I]:2,[z]:te(2,F[0][0])},32:{[I]:3,[z]:te(3,F[0][1])},48:{[I]:4,[z]:te(4,F[1][0],F[3][0])},64:{[I]:5,[z]:te(5,F[1][1],F[3][0])},80:{[I]:6,[z]:te(6,F[1][1],Ye,F[3][0])},96:{[I]:7,[z]:te(7,F[1][1],Ye,F[3][4],F[2][0])},112:{[I]:8,[z]:te(8,F[1][1],Ye,F[3][0],F[2][0])},128:{[I]:2,[z]:`${gt} (left, diff)`},144:{[I]:2,[z]:`${gt} (diff, right)`},160:{[I]:2,[z]:`${gt} (avg, diff)`},176:X,192:X,208:X,224:X,240:X},eu={0:dc,2:8,4:12,6:X,8:16,10:20,12:24,14:X},zt=class t extends Ie{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let i=64;i&e[0];i>>=1)r++;let n=r-1,s=0,o=0;for(;n>0;o+=6,n--){if((e[n]&192)!==128)return null;s|=(e[n]&63)<<o}return s|=(e[n]&127>>r)<<o,{value:s,length:r}}static[Oe](e,r){let n={[U]:function*(){return e}};return t[W](n,r,0).next().value}static*[W](e,r,n){let s=yield*e[U](6,n);if(s[0]!==255||!(s[1]===248||s[1]===249))return null;let o={},i=Ee(s[O](0,4)),a=r[W](i);if(a)Object.assign(o,a);else{if(o[ws]=s[1]&1,o[cn]=Qd[o[ws]],o[ln]=s[2]&240,o[Qe]=s[2]&15,o[ot]=uc[o[ln]],o[ot]===X||(o[D]=Jd[o[Qe]],o[D]===ge)||s[3]&1)return null;let l=Zd[s[3]&240];if(l===X||(o[I]=l[I],o[pe]=l[z],o[me]=eu[s[3]&14],o[me]===X))return null}o[x]=5,s=yield*e[U](o[x]+8,n);let c=t._decodeUTF8Int(s[O](4));if(!c||(o[ws]?o[pn]=c.value:o[lt]=c.value,o[x]+=c[x],o[ln]===96?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[ot]=s[o[x]-1]+1,o[x]+=1):o[ln]===112&&(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[ot]=(s[o[x]-1]<<8)+s[o[x]]+1,o[x]+=2),o[N]=o[ot],o[Qe]===12?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=s[o[x]-1]*1e3,o[x]+=1):o[Qe]===13?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=(s[o[x]-1]<<8)+s[o[x]],o[x]+=2):o[Qe]===14&&(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=((s[o[x]-1]<<8)+s[o[x]])*10,o[x]+=2),s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[xr]=s[o[x]-1],o[xr]!==ec(s[O](0,o[x]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:m,sampleRateBits:f,blockSizeBits:p,crc:y,length:h,...g}=o;r[Be](i,o,g)}return new t(o)}constructor(e){super(e),this[Qr]=null,this[cn]=e[cn],this[ot]=e[ot],this[lt]=e[lt],this[pn]=e[pn],this[gn]=null}};var tu=2,ru=512*1024,qt=class extends xe{constructor(e,r,n){super(e,r),this.Frame=It,this.Header=zt,n(this[Q])}get[Q](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[U](2,0),n=r[x]-2;for(;e<n;){if(r[e]===255){let o=r[e+1];if(o===248||o===249)break;o!==255&&e++}e++}return e}*[Ze](){do{let e=yield*zt[W](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[x]+tu;for(;r<=ru;){if(this._codecParser._flushing||(yield*zt[W](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[U](r);if(this._codecParser._flushing||(n=n[O](0,r)),It[Fs](n)){let s=new It(n,e);return this._headerCache[Xe](),this._codecParser[Re](r),this._codecParser[wt](s),s}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[Ge](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[Re](r)}else this._codecParser[Re](yield*this._getNextFrameSyncOffset(1))}while(!0)}[Et](e){return e[oe]===0?(this._headerCache[Xe](),this._streamInfo=e[q][O](13)):e[oe]===1||(e[he]=de.get(e)[Te].map(r=>{let n=zt[Oe](r,this._headerCache);if(n)return new It(r,n,this._streamInfo);this._codecParser[Ge]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var $t=class t{static*[W](e,r,n){let s={},o=yield*e[U](28,n);if(o[0]!==79||o[1]!==103||o[2]!==103||o[3]!==83||(s[di]=o[4],o[5]&248))return null;s[Le]=!!(o[5]&4),s[vt]=!!(o[5]&2),s[bt]=!!(o[5]&1);let a=new Pt(ye.from(o[O](0,28))[qe]);s[Ve]=nc(a,6),s[Je]=a.getInt32(14,!0),s[oe]=a.getInt32(18,!0),s[Ht]=a.getInt32(22,!0);let c=o[26];s[x]=c+27,o=yield*e[U](s[x],n),s[Ae]=0,s[_t]=[],s[Sr]=ye.from(o[O](27,s[x]));for(let l=0,d=0;l<c;l++){let u=s[Sr][l];s[Ae]+=u,d+=u,(u!==255||l===c-1)&&(s[_t].push(d),d=0)}return new t(s)}constructor(e){ce.set(this,e),this[Ve]=e[Ve],this[bt]=e[bt],this[vt]=e[vt],this[Le]=e[Le],this[_t]=e[_t],this[oe]=e[oe],this[Ht]=e[Ht],this[Je]=e[Je]}};var In=class t extends Wt{static*[ke](e,r,n){let s=yield*$t[W](e,r,n);if(s){let o=ce.get(s)[Ae],i=ce.get(s)[x],a=i+o,c=(yield*e[U](a,0))[O](0,a),l=c[O](i,a);return new t(s,l,c)}else return null}constructor(e,r,n){super(e,r),de.get(this)[x]=n[x],this[he]=[],this[ai]=n,this[Ve]=e[Ve],this[Jr]=e[Ht],this[$e]=0,this[bt]=e[bt],this[vt]=e[vt],this[Le]=e[Le],this[oe]=e[oe],this[N]=0,this[Je]=e[Je]}};var Ar=class extends Pe{constructor(e,r,n){super(r,e,n)}};var mc={0:Xr.slice(0,2),1:Xr},De="SILK-only",ue="CELT-only",Vs="Hybrid",Ft="narrowband",Gs="medium-band",Ct="wideband",_r="super-wideband",wr="fullband",nu={0:{[B]:De,[k]:Ft,[R]:10},8:{[B]:De,[k]:Ft,[R]:20},16:{[B]:De,[k]:Ft,[R]:40},24:{[B]:De,[k]:Ft,[R]:60},32:{[B]:De,[k]:Gs,[R]:10},40:{[B]:De,[k]:Gs,[R]:20},48:{[B]:De,[k]:Gs,[R]:40},56:{[B]:De,[k]:Gs,[R]:60},64:{[B]:De,[k]:Ct,[R]:10},72:{[B]:De,[k]:Ct,[R]:20},80:{[B]:De,[k]:Ct,[R]:40},88:{[B]:De,[k]:Ct,[R]:60},96:{[B]:Vs,[k]:_r,[R]:10},104:{[B]:Vs,[k]:_r,[R]:20},112:{[B]:Vs,[k]:wr,[R]:10},120:{[B]:Vs,[k]:wr,[R]:20},128:{[B]:ue,[k]:Ft,[R]:2.5},136:{[B]:ue,[k]:Ft,[R]:5},144:{[B]:ue,[k]:Ft,[R]:10},152:{[B]:ue,[k]:Ft,[R]:20},160:{[B]:ue,[k]:Ct,[R]:2.5},168:{[B]:ue,[k]:Ct,[R]:5},176:{[B]:ue,[k]:Ct,[R]:10},184:{[B]:ue,[k]:Ct,[R]:20},192:{[B]:ue,[k]:_r,[R]:2.5},200:{[B]:ue,[k]:_r,[R]:5},208:{[B]:ue,[k]:_r,[R]:10},216:{[B]:ue,[k]:_r,[R]:20},224:{[B]:ue,[k]:wr,[R]:2.5},232:{[B]:ue,[k]:wr,[R]:5},240:{[B]:ue,[k]:wr,[R]:10},248:{[B]:ue,[k]:wr,[R]:20}},Lr=class t extends Ie{static[Oe](e,r,n){let s={};if(s[I]=e[9],s[it]=e[18],s[x]=s[it]!==0?21+s[I]:19,e[x]<s[x])throw new Error("Out of data while inside an Ogg Page");let o=r[0]&3,i=o===3?2:1,a=Ee(e[O](0,s[x]))+Ee(r[O](0,i)),c=n[W](a);if(c)return new t(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;s[q]=ye.from(e[O](0,s[x]));let l=new Pt(s[q][qe]);if(s[me]=16,s[Dt]=l.getUint16(10,!0),s[hn]=l.getUint32(12,!0),s[D]=xt,s[sn]=l.getInt16(16,!0),s[it]in mc&&(s[pe]=mc[s[it]][s[I]-1],!s[pe]))return null;s[it]!==0&&(s[yn]=e[19],s[jr]=e[20],s[dn]=[...e[O](21,s[I]+21)]);let d=nu[248&r[0]];switch(s[B]=d[B],s[k]=d[k],s[R]=d[R],o){case 0:s[ct]=1;break;case 1:case 2:s[ct]=2;break;case 3:s[rn]=!!(128&r[1]),s[Zr]=!!(64&r[1]),s[ct]=63&r[1];break;default:return null}{let{length:u,data:m,channelMappingFamily:f,...p}=s;n[Be](a,s,p)}return new t(s)}constructor(e){super(e),this[q]=e[q],this[k]=e[k],this[it]=e[it],this[dn]=e[dn],this[jr]=e[jr],this[ct]=e[ct],this[R]=e[R],this[Zr]=e[Zr],this[hn]=e[hn],this[rn]=e[rn],this[B]=e[B],this[sn]=e[sn],this[Dt]=e[Dt],this[yn]=e[yn]}};var zn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=Ar,this.Header=Lr,n(this[Q]),this._identificationHeader=null,this._preSkipRemaining=null}get[Q](){return"opus"}[Et](e){return e[oe]===0?(this._headerCache[Xe](),this._identificationHeader=e[q]):e[oe]===1||(e[he]=de.get(e)[Te].map(r=>{let n=Lr[Oe](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Dt]);let s=n[R]*n[ct]/1e3*n[D];return this._preSkipRemaining>0&&(this._preSkipRemaining-=s,s=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Ar(r,n,s)}this._codecParser[Is]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Er=class extends Pe{constructor(e,r,n){super(r,e,n)}};var vi={};for(let t=0;t<8;t++)vi[t+6]=2**(6+t);var Fn=class t extends Ie{static[Oe](e,r,n,s){if(e[x]<30)throw new Error("Out of data while inside an Ogg Page");let o=Ee(e[O](0,30)),i=r[W](o);if(i)return new t(i);let a={[x]:30};if(o.substr(0,7)!=="vorbis")return null;a[q]=ye.from(e[O](0,30));let c=new Pt(a[q][qe]);if(a[St]=c.getUint32(7,!0),a[St]!==0||(a[I]=e[11],a[pe]=Xr[a[I]-1]||"application defined",a[D]=c.getUint32(12,!0),a[Kr]=c.getInt32(16,!0),a[qr]=c.getInt32(20,!0),a[Yr]=c.getInt32(24,!0),a[At]=vi[(e[28]&240)>>4],a[Mt]=vi[e[28]&15],a[Mt]>a[At])||e[29]!==1)return null;a[me]=32,a[vr]=s,a[an]=n;{let{length:l,data:d,version:u,vorbisSetup:m,vorbisComments:f,...p}=a;r[Be](o,a,p)}return new t(a)}constructor(e){super(e),this[Kr]=e[Kr],this[Yr]=e[Yr],this[qr]=e[qr],this[Mt]=e[Mt],this[At]=e[At],this[q]=e[q],this[an]=e[an],this[vr]=e[vr]}};var Cn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=Er,n(this[Q]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[Q](){return Nt}[Et](e){e[he]=[];for(let r of de.get(e)[Te])if(r[0]===1)this._headerCache[Xe](),this._identificationHeader=e[q],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=Fn[Oe](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[he].push(new Er(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 s=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[At]:r[Mt],o=this._prevBlockSize===null?0:(this._prevBlockSize+s)/4;return this._prevBlockSize=s,o}_parseSetupHeader(e){let r=new Ts(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let s;for(;n.count<64&&r.position>0;){vn(r.read(8));let o=0;for(;r.read(8)===0&&o++<3;);if(o===4)s=r.read(7),n.blockFlags.unshift(s&1),r.position+=6,n.count++;else{((vn(s)&126)>>1)+1!==n.count&&this._codecParser[Ge]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Si=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new ye,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[Q](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[We](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=Ee(e[O](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",zn),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",qt),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(Nt,Cn),!0;default:return!1}}_checkPageSequenceNumber(e){e[oe]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[oe]>1&&this._codecParser[Ge]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[oe]}`),this._pageSequenceNumber=e[oe]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[oe],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=de.get(e),n=ce.get(r[we]),s=0;if(r[Te]=n[_t].map(o=>e[q][O](s,s+=o)),this._continuedPacket[x]&&(r[Te][0]=Sn(this._continuedPacket,r[Te][0]),this._continuedPacket=new ye),n[Sr][n[Sr][x]-1]===255&&(this._continuedPacket=Sn(this._continuedPacket,r[Te].pop())),this._previousAbsoluteGranulePosition!==null&&(e[N]=Number(e[Ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Ve],this._isSupported){let o=this._parser[Et](e);return this._codecParser[wt](o),o}else return e}},Tn=class extends xe{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=In,this.Header=$t,this._streams=new Map,this._currentSerialNumber=null}get[Q](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ze](){let e=yield*this[Lt](!0);this._currentSerialNumber=e[Je];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Si(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Le]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var Mi=()=>{},Rn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:s,enableLogging:o=!1,enableFrameCRC32:i=!0}={}){this._inputMimeType=e,this._onCodec=r||Mi,this._onCodecHeader=n||Mi,this._onCodecUpdate=s,this._enableLogging=o,this._crc32=i?rc:Mi,this[We]()}get[Q](){return this._parser?this._parser[Q]:""}[We](){this._headerCache=new Mn(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[We]()}*parseChunk(e){for(let r=this._generator.next(e);r.value;r=this._generator.next())yield r.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new Pn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Ln(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new qt(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new Tn(this,this._headerCache,this._onCodec);else throw new Error(`Unsupported Codec ${mimeType}`);for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){let e=yield*this._parser[Ze]();e&&(yield e)}}*[U](e=0,r=0){let n;for(;this._rawData[x]<=e+r;){if(n=yield,this._flushing)return this._rawData[O](r);n&&(this._totalBytesIn+=n[x],this._rawData=Sn(this._rawData,n))}return this._rawData[O](r)}[Re](e){this._currentReadPosition+=e,this._rawData=this._rawData[O](e)}[xn](e){this._sampleRate=e[we][D],e[we][fe]=e[$e]>0?Math.round(e[q][x]/e[$e])*8:0,e[lt]=this._frameNumber++,e[Ut]=this._totalBytesOut,e[Gt]=this._totalSamples,e[Vt]=this._totalSamples/this._sampleRate*1e3,e[Jr]=this._crc32(e[q]),this._headerCache[zs](e[we][fe],e[Vt]),this._totalBytesOut+=e[q][x],this._totalSamples+=e[N]}[wt](e){if(e[he]){if(e[Le]){let r=e[N];e[he].forEach(n=>{let s=n[N];r<s&&(n[N]=r>0?r:0,n[$e]=n[N]/n[we][D]*1e3),r-=s,this[xn](n)})}else e[N]=0,e[he].forEach(r=>{e[N]+=r[N],this[xn](r)});e[$e]=e[N]/this._sampleRate*1e3||0,e[Gt]=this._totalSamples,e[Vt]=this._totalSamples/this._sampleRate*1e3||0,e[Ut]=this._totalBytesOut}else this[xn](e)}_log(e,r){if(this._enableLogging){let n=[`${Q}: ${this[Q]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${Ut}: ${this._totalBytesOut}`],s=Math.max(...n.map(o=>o[x]));r.push(`--stats--${"-".repeat(s-9)}`,...n,"-".repeat(s)),e("codec-parser",r.reduce((o,i)=>o+`
4
- `+i,""))}}[Ge](...e){this._log(console.warn,e)}[Is](...e){this._log(console.error,e)}};var fc=Rn;var Ws=he;var Xs=q;var hc=we;var pc=Le;var yc=vr;var gc=Gt;function dt(t){var e=e;function r(){}e={};function n(P){throw P}var s,o,i,a,c,l,d,u,m,f,p;function y(){var P=p.buffer;s=new Int8Array(P),o=new Int16Array(P),a=new Uint8Array(P),c=new Uint16Array(P),i=new Int32Array(P),l=new Uint32Array(P),d=new Float32Array(P),u=new Float64Array(P),m=new BigInt64Array(P),f=new BigUint64Array(P)}for(var h=P=>{for(var ze,kr,rr=0,Qn=0,Jn=P.length,Zn=new Uint8Array((Jn*3>>2)-(P[Jn-2]=="=")-(P[Jn-1]=="="));rr<Jn;rr+=4,Qn+=3)ze=J[P.charCodeAt(rr+1)],kr=J[P.charCodeAt(rr+2)],Zn[Qn]=J[P.charCodeAt(rr)]<<2|ze>>4,Zn[Qn+1]=ze<<4|kr>>2,Zn[Qn+2]=kr<<6|J[P.charCodeAt(rr+3)];return Zn},g=()=>n(""),S=()=>{},b={},M=P=>P(),v=()=>performance.now(),A=(P,ze)=>{if(b[P]&&(clearTimeout(b[P].id),delete b[P]),!ze)return 0;var kr=setTimeout(()=>{delete b[P],M(()=>ia(P,v()))},ze);return b[P]={id:kr,timeout_ms:ze},0},_=Math.atan,L=Math.cos,C=Math.exp,w=Math.log,H=Math.pow,G=Math.sin,V=P=>{var ze=a.length;return P>>>=0,!1},T=P=>{throw`exit(${P})`},J=new Uint8Array(123),Se=25;Se>=0;--Se)J[48+Se]=52+Se,J[65+Se]=Se,J[97+Se]=26+Se;J[43]=62,J[47]=63;var Tt={e:g,d:S,f:A,b:_,a:L,i:C,h:w,g:H,c:G,k:V,j:T};function jn(P){Br=P.n,ea=P.o,ta=P.p,ra=P.q,na=P.r,sa=P.s,oa=P.t,ia=P.v}var Br,ea,ta,ra,na,sa,oa,ia;function dl(P){P.m()}dt.wasm||Object.defineProperty(dt,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØä‘ÂLÚªã9ÚØ[äº\ ¼¡³R=}L]ŸÈÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹‡= 
3
+ `,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(g)}}return y};function Z(){let t=Uint8Array,e=Float32Array;Z.modules||Object.defineProperties(Z,{modules:{value:new WeakMap},setModule:{value(r,n){Z.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let s=Z.modules.get(r);return s||(n?s=WebAssembly.compile(ii(n)):(n=r.wasm,s=Z.inflateDynEncodeString(n).then(o=>WebAssembly.compile(o))),Z.modules.set(r,s)),s}},concatFloat32:{value(r,n){let s=new e(n),o=0,i=0;for(;o<r.length;)s.set(r[o],i),i+=r[o++].length;return s}},getDecodedAudio:{value:(r,n,s,o,i)=>({errors:r,channelData:n,samplesDecoded:s,sampleRate:o,bitDepth:i})},getDecodedAudioMultiChannel:{value(r,n,s,o,i,a){let c=[],l,d;for(l=0;l<s;l++){let u=[];for(d=0;d<n.length;)u.push(n[d++][l]||[]);c.push(Z.concatFloat32(u,o))}return Z.getDecodedAudio(r,c,o,i,a)}},inflateDynEncodeString:{value(r){return r=ii(r),new Promise(n=>{let s=String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;Z.getModule(Z,s).then(o=>WebAssembly.instantiate(o,{})).then(({exports:o})=>{let i=new Map(Object.entries(o)),a=i.get("puff"),c=i.get("memory").buffer,l=new t(c),d=new DataView(c),u=i.get("__heap_base"),m=r.length,f=u;u+=4,d.setInt32(f,m,!0);let p=u;u+=m,l.set(r,p);let y=u;u+=4,d.setInt32(y,l.byteLength-u,!0),a(u,y,p,f),n(l.slice(u,u+d.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,s)=>{let o=[],i=0;for(;i<n;)o.push(r.slice(i*s,i++*s+s));return o},this.allocateTypedArray=(r,n,s=!0)=>{let o=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return s&&this._pointers.add(o),{ptr:o,len:r,buf:new n(this._wasm.HEAP,o,r)}},this.free=()=>{this._pointers.forEach(r=>{this._wasm.free(r)}),this._pointers.clear()},this.codeToString=r=>{let n=[],s=new Uint8Array(this._wasm.HEAP);for(let o=s[r];o!==0;o=s[++r])n.push(o);return String.fromCharCode.apply(null,n)},this.addError=(r,n,s,o,i,a)=>{r.push({message:n,frameLength:s,frameNumber:o,inputBytes:i,outputSamples:a})},this.instantiate=(r,n)=>(n&&Z.setModule(r,n),this._wasm=new r(Z).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Xa=xl(Wa(),1);var Bd=()=>globalThis.Worker||Xa.default,ur=class extends Bd(){constructor(e,r,n,s){Z.modules||new Z;let o=Z.modules.get(n);if(!o){let i="text/javascript",a,c=`'use strict';(${((l,d,u)=>{let m,f,p=new Promise(y=>{f=y});self.onmessage=({data:{id:y,command:h,data:g}})=>{let S=p,b={id:y},M;h==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:d},EmscriptenWASM:{value:u},module:{value:g.module},isWebWorker:{value:!0}}),m=new l(g.options),f()):h==="free"?m.free():h==="ready"?S=S.then(()=>m.ready):h==="reset"?S=S.then(()=>m.reset()):(Object.assign(b,m[h](Array.isArray(g)?g.map(v=>new Uint8Array(v)):new Uint8Array(g))),M=b.channelData?b.channelData.map(v=>v.buffer):[]),S.then(()=>self.postMessage(b,M))}}).toString()})(${n}, ${Z}, ${s})`;try{a=typeof process.versions.node<"u"}catch{}o=a?`data:${i};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:i})),Z.modules.set(n,o)}super(o,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:i})=>{let{id:a,...c}=i;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new s(Z).getModule().then(i=>{this.postToDecoder("init",{module:i,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 gs=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var ee=Symbol,Ka=", ",F=(()=>{let t="front",e="side",r="rear",n="left",s="center",o="right";return["",t+" ",e+" ",r+" "].map(i=>[[n,o],[n,o,s],[n,s,o],[s,n,o],[s]].flatMap(a=>a.map(c=>i+c).join(Ka)))})(),Ye="LFE",yt="monophonic (mono)",gt="stereo",Wr="surround",te=(t,...e)=>`${[yt,gt,`linear ${Wr}`,"quadraphonic",`5.0 ${Wr}`,`5.1 ${Wr}`,`6.1 ${Wr}`,`7.1 ${Wr}`][t-1]} (${e.join(Ka)})`,Xr=[yt,te(2,F[0][0]),te(3,F[0][2]),te(4,F[1][0],F[3][0]),te(5,F[1][2],F[3][0]),te(6,F[1][2],F[3][0],Ye),te(7,F[1][2],F[2][0],F[3][4],Ye),te(8,F[1][2],F[2][0],F[3][0],Ye)],Ya=192e3,qa=176400,xs=96e3,bs=88200,$a=64e3,xt=48e3,mr=44100,fr=32e3,hr=24e3,pr=22050,yr=16e3,vs=12e3,Ss=11025,gr=8e3,ja=7350,Ve="absoluteGranulePosition",k="bandwidth",me="bitDepth",fe="bitrate",Kr=fe+"Maximum",Yr=fe+"Minimum",qr=fe+"Nominal",qe="buffer",$r=qe+"Fullness",Q="codec",he=Q+"Frames",jr="coupledStreamCount",xr="crc",Qr=xr+"16",Jr=xr+"32",q="data",z="description",$e="duration",br="emphasis",Zr="hasOpusPadding",we="header",bt="isContinuedPacket",en="isCopyrighted",vt="isFirstPage",tn="isHome",Le="isLastPage",et="isOriginal",tt="isPrivate",rn="isVbr",Me="layer",x="length",B="mode",rt=B+"Extension",Ms="mpeg",nt=Ms+"Version",nn="numberAACFrames",sn="outputGain",Dt="preSkip",on="profile",As=ee(),st="protection",ai="rawData",Ce="segments",O="subarray",St="version",Nt="vorbis",an=Nt+"Comments",vr=Nt+"Setup",_s="block",cn=_s+"ingStrategy",ws=ee(),ot=_s+"Size",Mt=_s+"size0",At=_s+"size1",ln=ee(),Ls="channel",it=Ls+"MappingFamily",dn=Ls+"MappingTable",pe=Ls+"Mode",un=ee(),I=Ls+"s",Qa="copyright",mn=Qa+"Id",fn=Qa+"IdStart",at="frame",ct=at+"Count",Ae=at+"Length",Es="Number",lt=at+Es,je=at+"Padding",R=at+"Size",Ja="Rate",hn="inputSample"+Ja,ci="page",Ht=ci+"Checksum",Sr=ee(),_t=ci+"SegmentTable",oe=ci+"Sequence"+Es,li="sample",pn=li+Es,D=li+Ja,Qe=ee(),N=li+"s",Ps="stream",yn=Ps+"Count",gn=Ps+"Info",Je=Ps+"Serial"+Es,di=Ps+"StructureVersion",ui="total",Ut=ui+"BytesOut",Vt=ui+"Duration",Gt=ui+"Samples",U=ee(),Re=ee(),xn=ee(),wt=ee(),Ge=ee(),Is=ee(),mi=ee(),Lt=ee(),W=ee(),Be=ee(),ke=ee(),Ze=ee(),Et=ee(),zs=ee(),We=ee(),Xe=ee(),Oe=ee(),Fs=ee(),ye=Uint8Array,Pt=DataView,X="reserved",ge="bad",Mr="free",bn="none",Ts="16bit CRC";var fi=(t,e,r)=>{for(let n=0;n<t[x];n++){let s=e(n);for(let o=8;o>0;o--)s=r(s);t[n]=s}return t},Od=fi(new ye(256),t=>t,t=>t&128?7^t<<1:t<<1),re=[fi(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],ne=[fi(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){re.push(new Uint16Array(256)),ne.push(new Uint32Array(256));for(let e=0;e<=255;e++)re[t+1][e]=re[0][re[t][e]>>>8]^re[t][e]<<8,ne[t+1][e]=ne[t][e]>>>8^ne[0][ne[t][e]&255]}var ec=t=>{let e=0,r=t[x];for(let n=0;n!==r;n++)e=Od[e^t[n]];return e},tc=t=>{let e=t[x],r=e-16,n=0,s=0;for(;s<=r;)n^=t[s++]<<8|t[s++],n=re[15][n>>8]^re[14][n&255]^re[13][t[s++]]^re[12][t[s++]]^re[11][t[s++]]^re[10][t[s++]]^re[9][t[s++]]^re[8][t[s++]]^re[7][t[s++]]^re[6][t[s++]]^re[5][t[s++]]^re[4][t[s++]]^re[3][t[s++]]^re[2][t[s++]]^re[1][t[s++]]^re[0][t[s++]];for(;s!==e;)n=(n&255)<<8^re[0][n>>8^t[s++]];return n},rc=t=>{let e=t[x],r=e-16,n=0,s=0;for(;s<=r;)n=ne[15][(t[s++]^n)&255]^ne[14][(t[s++]^n>>>8)&255]^ne[13][(t[s++]^n>>>16)&255]^ne[12][t[s++]^n>>>24]^ne[11][t[s++]]^ne[10][t[s++]]^ne[9][t[s++]]^ne[8][t[s++]]^ne[7][t[s++]]^ne[6][t[s++]]^ne[5][t[s++]]^ne[4][t[s++]]^ne[3][t[s++]]^ne[2][t[s++]]^ne[1][t[s++]]^ne[0][t[s++]];for(;s!==e;)n=ne[0][(n^t[s++])&255]^n>>>8;return n^-1},Sn=(...t)=>{let e=new ye(t.reduce((r,n)=>r+n[x],0));return t.reduce((r,n)=>(e.set(n,r),r+n[x]),0),e},Ee=t=>String.fromCharCode(...t),Za=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],vn=t=>Za[t&15]<<4|Za[t>>4],Cs=class{constructor(e){this._data=e,this._pos=e[x]*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,(vn(this._data[r-1])<<8)+vn(this._data[r])>>7-n&255}},nc=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),s=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,s=~s+1),s>1048575&&console.warn("This platform does not support BigInt"),r*(n+s*2**32)}};var Mn=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[We]()}[Xe](){this._isEnabled=!0}[We](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[zs](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}}[W](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[Be](e,r,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...r}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,r),this._codecUpdateData.set(r,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var ce=new WeakMap,de=new WeakMap;var xe=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[mi](){let e;do{if(e=yield*this.Frame[ke](this._codecParser,this._headerCache,0),e)return e;this._codecParser[Re](1)}while(!0)}*[Lt](e){let r=yield*this[mi](),n=de.get(r)[x];if(e||this._codecParser._flushing||(yield*this.Header[W](this._codecParser,this._headerCache,n)))return this._headerCache[Xe](),this._codecParser[Re](n),this._codecParser[wt](r),r;this._codecParser[Ge](`Missing ${at} at ${n} bytes from current position.`,`Dropping current ${at} and trying again.`),this._headerCache[We](),this._codecParser[Re](1)}};var Wt=class{constructor(e,r){de.set(this,{[we]:e}),this[q]=r}};var Pe=class extends Wt{static*[ke](e,r,n,s,o){let i=yield*e[W](n,s,o);if(i){let a=ce.get(i)[Ae],c=ce.get(i)[N],l=(yield*n[U](a,o))[O](0,a);return new r(i,l,c)}else return null}constructor(e,r,n){super(e,r),this[we]=e,this[N]=n,this[$e]=n/e[D]*1e3,this[lt]=null,this[Ut]=null,this[Gt]=null,this[Vt]=null,de.get(this)[x]=r[x]}};var hi="unsynchronizationFlag",pi="extendedHeaderFlag",yi="experimentalFlag",gi="footerPresent",An=class t{static*getID3v2Header(e,r,n){let o={},i=yield*e[U](3,n);if(i[0]!==73||i[1]!==68||i[2]!==51||(i=yield*e[U](10,n),o[St]=`id3v2.${i[3]}.${i[4]}`,i[5]&15)||(o[hi]=!!(i[5]&128),o[pi]=!!(i[5]&64),o[yi]=!!(i[5]&32),o[gi]=!!(i[5]&16),i[6]&128||i[7]&128||i[8]&128||i[9]&128))return null;let a=i[6]<<21|i[7]<<14|i[8]<<7|i[9];return o[x]=10+a,new t(o)}constructor(e){this[St]=e[St],this[hi]=e[hi],this[pi]=e[pi],this[yi]=e[yi],this[gi]=e[gi],this[x]=e[x]}};var Ie=class{constructor(e){ce.set(this,e),this[me]=e[me],this[fe]=null,this[I]=e[I],this[pe]=e[pe],this[D]=e[D]}};var cc={0:[Mr,Mr,Mr,Mr,Mr],16:[32,32,32,32,8],240:[ge,ge,ge,ge,ge]},Rs=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)cc[t<<4]=[t*32,Rs(t,4,0),Rs(t,4,-1),Rs(t,8,4),Rs(t,8,0)];var Dd=0,Nd=1,Hd=2,Ud=3,sc=4,Bs="bands ",ks=" to 31",oc={0:Bs+4+ks,16:Bs+8+ks,32:Bs+12+ks,48:Bs+16+ks},Xt="bitrateIndex",_n="v2",Us="v1",Os="Intensity stereo ",Ds=", MS stereo ",Ns="on",Hs="off",Vd={0:Os+Hs+Ds+Hs,16:Os+Ns+Ds+Hs,32:Os+Hs+Ds+Ns,48:Os+Ns+Ds+Ns},xi={0:{[z]:X},2:{[z]:"Layer III",[je]:1,[rt]:Vd,[Us]:{[Xt]:Hd,[N]:1152},[_n]:{[Xt]:sc,[N]:576}},4:{[z]:"Layer II",[je]:1,[rt]:oc,[N]:1152,[Us]:{[Xt]:Nd},[_n]:{[Xt]:sc}},6:{[z]:"Layer I",[je]:4,[rt]:oc,[N]:384,[Us]:{[Xt]:Dd},[_n]:{[Xt]:Ud}}},bi="MPEG Version ",ic="ISO/IEC ",Gd={0:{[z]:`${bi}2.5 (later extension of MPEG 2)`,[Me]:_n,[D]:{0:Ss,4:vs,8:gr,12:X}},8:{[z]:X},16:{[z]:`${bi}2 (${ic}13818-3)`,[Me]:_n,[D]:{0:pr,4:hr,8:yr,12:X}},24:{[z]:`${bi}1 (${ic}11172-3)`,[Me]:Us,[D]:{0:mr,4:xt,8:fr,12:X}},length:x},Wd={0:Ts,1:bn},Xd={0:bn,1:"50/15 ms",2:X,3:"CCIT J.17"},ac={0:{[I]:2,[z]:gt},64:{[I]:2,[z]:"joint "+gt},128:{[I]:2,[z]:"dual channel"},192:{[I]:1,[z]:yt}},Kt=class t extends Ie{static*[W](e,r,n){let s={},o=yield*An.getID3v2Header(e,r,n);o&&(yield*e[U](o[x],n),e[Re](o[x]));let i=yield*e[U](4,n),a=Ee(i[O](0,4)),c=r[W](a);if(c)return new t(c);if(i[0]!==255||i[1]<224)return null;let l=Gd[i[1]&24];if(l[z]===X)return null;let d=i[1]&6;if(xi[d][z]===X)return null;let u={...xi[d],...xi[d][l[Me]]};if(s[nt]=l[z],s[Me]=u[z],s[N]=u[N],s[st]=Wd[i[1]&1],s[x]=4,s[fe]=cc[i[2]&240][u[Xt]],s[fe]===ge||(s[D]=l[D][i[2]&12],s[D]===X)||(s[je]=i[2]&2&&u[je],s[tt]=!!(i[2]&1),s[Ae]=Math.floor(125*s[fe]*s[N]/s[D]+s[je]),!s[Ae]))return null;let m=i[3]&192;if(s[pe]=ac[m][z],s[I]=ac[m][I],s[rt]=u[rt][i[3]&48],s[en]=!!(i[3]&8),s[et]=!!(i[3]&4),s[br]=Xd[i[3]&3],s[br]===X)return null;s[me]=16;{let{length:f,frameLength:p,samples:y,...h}=s;r[Be](a,s,h)}return new t(s)}constructor(e){super(e),this[fe]=e[fe],this[br]=e[br],this[je]=e[je],this[en]=e[en],this[et]=e[et],this[tt]=e[tt],this[Me]=e[Me],this[rt]=e[rt],this[nt]=e[nt],this[st]=e[st]}};var wn=class t extends Pe{static*[ke](e,r,n){return yield*super[ke](Kt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Ln=class extends xe{constructor(e,r,n){super(e,r),this.Frame=wn,this.Header=Kt,n(this[Q])}get[Q](){return Ms}*[Ze](){return yield*this[Lt]()}};var Kd={0:"MPEG-4",8:"MPEG-2"},Yd={0:"valid",2:ge,4:ge,6:ge},qd={0:Ts,1:bn},$d={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},jd={0:xs,4:bs,8:$a,12:xt,16:mr,20:fr,24:hr,28:pr,32:yr,36:vs,40:Ss,44:gr,48:ja,52:X,56:X,60:"frequency is written explicitly"},lc={0:{[I]:0,[z]:"Defined in AOT Specific Config"},64:{[I]:1,[z]:yt},128:{[I]:2,[z]:te(2,F[0][0])},192:{[I]:3,[z]:te(3,F[1][3])},256:{[I]:4,[z]:te(4,F[1][3],F[3][4])},320:{[I]:5,[z]:te(5,F[1][3],F[3][0])},384:{[I]:6,[z]:te(6,F[1][3],F[3][0],Ye)},448:{[I]:8,[z]:te(8,F[1][3],F[2][0],F[3][0],Ye)}},Yt=class t extends Ie{static*[W](e,r,n){let s={},o=yield*e[U](7,n),i=Ee([o[0],o[1],o[2],o[3]&252|o[6]&3]),a=r[W](i);if(a)Object.assign(s,a);else{if(o[0]!==255||o[1]<240||(s[nt]=Kd[o[1]&8],s[Me]=Yd[o[1]&6],s[Me]===ge))return null;let l=o[1]&1;s[st]=qd[l],s[x]=l?7:9,s[As]=o[2]&192,s[Qe]=o[2]&60;let d=o[2]&2;if(s[on]=$d[s[As]],s[D]=jd[s[Qe]],s[D]===X)return null;s[tt]=!!d,s[un]=(o[2]<<8|o[3])&448,s[pe]=lc[s[un]][z],s[I]=lc[s[un]][I],s[et]=!!(o[3]&32),s[tn]=!!(o[3]&8),s[mn]=!!(o[3]&8),s[fn]=!!(o[3]&4),s[me]=16,s[N]=1024,s[nn]=o[6]&3;{let{length:u,channelModeBits:m,profileBits:f,sampleRateBits:p,frameLength:y,samples:h,numberAACFrames:g,...S}=s;r[Be](i,s,S)}}if(s[Ae]=(o[3]<<11|o[4]<<3|o[5]>>5)&8191,!s[Ae])return null;let c=(o[5]<<6|o[6]>>2)&2047;return s[$r]=c===2047?"VBR":c,new t(s)}constructor(e){super(e),this[mn]=e[mn],this[fn]=e[fn],this[$r]=e[$r],this[tn]=e[tn],this[et]=e[et],this[tt]=e[tt],this[Me]=e[Me],this[x]=e[x],this[nt]=e[nt],this[nn]=e[nn],this[on]=e[on],this[st]=e[st]}get audioSpecificConfig(){let e=ce.get(this),r=e[As]+64<<5|e[Qe]<<5|e[un]>>3,n=new ye(2);return new Pt(n[qe]).setUint16(0,r,!1),n}};var En=class t extends Pe{static*[ke](e,r,n){return yield*super[ke](Yt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var Pn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=En,this.Header=Yt,n(this[Q])}get[Q](){return"aac"}*[Ze](){return yield*this[Lt]()}};var It=class t extends Pe{static _getFrameFooterCrc16(e){return(e[e[x]-2]<<8)+e[e[x]-1]}static[Fs](e){let r=t._getFrameFooterCrc16(e),n=tc(e[O](0,-2));return r===n}constructor(e,r,n){r[gn]=n,r[Qr]=t._getFrameFooterCrc16(e),super(r,e,ce.get(r)[N])}};var dc="get from STREAMINFO metadata block",Qd={0:"Fixed",1:"Variable"},uc={0:X,16:192};for(let t=2;t<16;t++)uc[t<<4]=t<6?576*2**(t-2):2**t;var Jd={0:dc,1:bs,2:qa,3:Ya,4:gr,5:yr,6:pr,7:hr,8:fr,9:mr,10:xt,11:xs,15:ge},Zd={0:{[I]:1,[z]:yt},16:{[I]:2,[z]:te(2,F[0][0])},32:{[I]:3,[z]:te(3,F[0][1])},48:{[I]:4,[z]:te(4,F[1][0],F[3][0])},64:{[I]:5,[z]:te(5,F[1][1],F[3][0])},80:{[I]:6,[z]:te(6,F[1][1],Ye,F[3][0])},96:{[I]:7,[z]:te(7,F[1][1],Ye,F[3][4],F[2][0])},112:{[I]:8,[z]:te(8,F[1][1],Ye,F[3][0],F[2][0])},128:{[I]:2,[z]:`${gt} (left, diff)`},144:{[I]:2,[z]:`${gt} (diff, right)`},160:{[I]:2,[z]:`${gt} (avg, diff)`},176:X,192:X,208:X,224:X,240:X},eu={0:dc,2:8,4:12,6:X,8:16,10:20,12:24,14:X},zt=class t extends Ie{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let i=64;i&e[0];i>>=1)r++;let n=r-1,s=0,o=0;for(;n>0;o+=6,n--){if((e[n]&192)!==128)return null;s|=(e[n]&63)<<o}return s|=(e[n]&127>>r)<<o,{value:s,length:r}}static[Oe](e,r){let n={[U]:function*(){return e}};return t[W](n,r,0).next().value}static*[W](e,r,n){let s=yield*e[U](6,n);if(s[0]!==255||!(s[1]===248||s[1]===249))return null;let o={},i=Ee(s[O](0,4)),a=r[W](i);if(a)Object.assign(o,a);else{if(o[ws]=s[1]&1,o[cn]=Qd[o[ws]],o[ln]=s[2]&240,o[Qe]=s[2]&15,o[ot]=uc[o[ln]],o[ot]===X||(o[D]=Jd[o[Qe]],o[D]===ge)||s[3]&1)return null;let l=Zd[s[3]&240];if(l===X||(o[I]=l[I],o[pe]=l[z],o[me]=eu[s[3]&14],o[me]===X))return null}o[x]=5,s=yield*e[U](o[x]+8,n);let c=t._decodeUTF8Int(s[O](4));if(!c||(o[ws]?o[pn]=c.value:o[lt]=c.value,o[x]+=c[x],o[ln]===96?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[ot]=s[o[x]-1]+1,o[x]+=1):o[ln]===112&&(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[ot]=(s[o[x]-1]<<8)+s[o[x]]+1,o[x]+=2),o[N]=o[ot],o[Qe]===12?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=s[o[x]-1]*1e3,o[x]+=1):o[Qe]===13?(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=(s[o[x]-1]<<8)+s[o[x]],o[x]+=2):o[Qe]===14&&(s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[D]=((s[o[x]-1]<<8)+s[o[x]])*10,o[x]+=2),s[x]<o[x]&&(s=yield*e[U](o[x],n)),o[xr]=s[o[x]-1],o[xr]!==ec(s[O](0,o[x]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:d,sampleNumber:u,samples:m,sampleRateBits:f,blockSizeBits:p,crc:y,length:h,...g}=o;r[Be](i,o,g)}return new t(o)}constructor(e){super(e),this[Qr]=null,this[cn]=e[cn],this[ot]=e[ot],this[lt]=e[lt],this[pn]=e[pn],this[gn]=null}};var tu=2,ru=512*1024,qt=class extends xe{constructor(e,r,n){super(e,r),this.Frame=It,this.Header=zt,n(this[Q])}get[Q](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[U](2,0),n=r[x]-2;for(;e<n;){if(r[e]===255){let o=r[e+1];if(o===248||o===249)break;o!==255&&e++}e++}return e}*[Ze](){do{let e=yield*zt[W](this._codecParser,this._headerCache,0);if(e){let r=ce.get(e)[x]+tu;for(;r<=ru;){if(this._codecParser._flushing||(yield*zt[W](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[U](r);if(this._codecParser._flushing||(n=n[O](0,r)),It[Fs](n)){let s=new It(n,e);return this._headerCache[Xe](),this._codecParser[Re](r),this._codecParser[wt](s),s}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[Ge](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[Re](r)}else this._codecParser[Re](yield*this._getNextFrameSyncOffset(1))}while(!0)}[Et](e){return e[oe]===0?(this._headerCache[Xe](),this._streamInfo=e[q][O](13)):e[oe]===1||(e[he]=de.get(e)[Ce].map(r=>{let n=zt[Oe](r,this._headerCache);if(n)return new It(r,n,this._streamInfo);this._codecParser[Ge]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var $t=class t{static*[W](e,r,n){let s={},o=yield*e[U](28,n);if(o[0]!==79||o[1]!==103||o[2]!==103||o[3]!==83||(s[di]=o[4],o[5]&248))return null;s[Le]=!!(o[5]&4),s[vt]=!!(o[5]&2),s[bt]=!!(o[5]&1);let a=new Pt(ye.from(o[O](0,28))[qe]);s[Ve]=nc(a,6),s[Je]=a.getInt32(14,!0),s[oe]=a.getInt32(18,!0),s[Ht]=a.getInt32(22,!0);let c=o[26];s[x]=c+27,o=yield*e[U](s[x],n),s[Ae]=0,s[_t]=[],s[Sr]=ye.from(o[O](27,s[x]));for(let l=0,d=0;l<c;l++){let u=s[Sr][l];s[Ae]+=u,d+=u,(u!==255||l===c-1)&&(s[_t].push(d),d=0)}return new t(s)}constructor(e){ce.set(this,e),this[Ve]=e[Ve],this[bt]=e[bt],this[vt]=e[vt],this[Le]=e[Le],this[_t]=e[_t],this[oe]=e[oe],this[Ht]=e[Ht],this[Je]=e[Je]}};var In=class t extends Wt{static*[ke](e,r,n){let s=yield*$t[W](e,r,n);if(s){let o=ce.get(s)[Ae],i=ce.get(s)[x],a=i+o,c=(yield*e[U](a,0))[O](0,a),l=c[O](i,a);return new t(s,l,c)}else return null}constructor(e,r,n){super(e,r),de.get(this)[x]=n[x],this[he]=[],this[ai]=n,this[Ve]=e[Ve],this[Jr]=e[Ht],this[$e]=0,this[bt]=e[bt],this[vt]=e[vt],this[Le]=e[Le],this[oe]=e[oe],this[N]=0,this[Je]=e[Je]}};var Ar=class extends Pe{constructor(e,r,n){super(r,e,n)}};var mc={0:Xr.slice(0,2),1:Xr},De="SILK-only",ue="CELT-only",Vs="Hybrid",Ft="narrowband",Gs="medium-band",Tt="wideband",_r="super-wideband",wr="fullband",nu={0:{[B]:De,[k]:Ft,[R]:10},8:{[B]:De,[k]:Ft,[R]:20},16:{[B]:De,[k]:Ft,[R]:40},24:{[B]:De,[k]:Ft,[R]:60},32:{[B]:De,[k]:Gs,[R]:10},40:{[B]:De,[k]:Gs,[R]:20},48:{[B]:De,[k]:Gs,[R]:40},56:{[B]:De,[k]:Gs,[R]:60},64:{[B]:De,[k]:Tt,[R]:10},72:{[B]:De,[k]:Tt,[R]:20},80:{[B]:De,[k]:Tt,[R]:40},88:{[B]:De,[k]:Tt,[R]:60},96:{[B]:Vs,[k]:_r,[R]:10},104:{[B]:Vs,[k]:_r,[R]:20},112:{[B]:Vs,[k]:wr,[R]:10},120:{[B]:Vs,[k]:wr,[R]:20},128:{[B]:ue,[k]:Ft,[R]:2.5},136:{[B]:ue,[k]:Ft,[R]:5},144:{[B]:ue,[k]:Ft,[R]:10},152:{[B]:ue,[k]:Ft,[R]:20},160:{[B]:ue,[k]:Tt,[R]:2.5},168:{[B]:ue,[k]:Tt,[R]:5},176:{[B]:ue,[k]:Tt,[R]:10},184:{[B]:ue,[k]:Tt,[R]:20},192:{[B]:ue,[k]:_r,[R]:2.5},200:{[B]:ue,[k]:_r,[R]:5},208:{[B]:ue,[k]:_r,[R]:10},216:{[B]:ue,[k]:_r,[R]:20},224:{[B]:ue,[k]:wr,[R]:2.5},232:{[B]:ue,[k]:wr,[R]:5},240:{[B]:ue,[k]:wr,[R]:10},248:{[B]:ue,[k]:wr,[R]:20}},Lr=class t extends Ie{static[Oe](e,r,n){let s={};if(s[I]=e[9],s[it]=e[18],s[x]=s[it]!==0?21+s[I]:19,e[x]<s[x])throw new Error("Out of data while inside an Ogg Page");let o=r[0]&3,i=o===3?2:1,a=Ee(e[O](0,s[x]))+Ee(r[O](0,i)),c=n[W](a);if(c)return new t(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;s[q]=ye.from(e[O](0,s[x]));let l=new Pt(s[q][qe]);if(s[me]=16,s[Dt]=l.getUint16(10,!0),s[hn]=l.getUint32(12,!0),s[D]=xt,s[sn]=l.getInt16(16,!0),s[it]in mc&&(s[pe]=mc[s[it]][s[I]-1],!s[pe]))return null;s[it]!==0&&(s[yn]=e[19],s[jr]=e[20],s[dn]=[...e[O](21,s[I]+21)]);let d=nu[248&r[0]];switch(s[B]=d[B],s[k]=d[k],s[R]=d[R],o){case 0:s[ct]=1;break;case 1:case 2:s[ct]=2;break;case 3:s[rn]=!!(128&r[1]),s[Zr]=!!(64&r[1]),s[ct]=63&r[1];break;default:return null}{let{length:u,data:m,channelMappingFamily:f,...p}=s;n[Be](a,s,p)}return new t(s)}constructor(e){super(e),this[q]=e[q],this[k]=e[k],this[it]=e[it],this[dn]=e[dn],this[jr]=e[jr],this[ct]=e[ct],this[R]=e[R],this[Zr]=e[Zr],this[hn]=e[hn],this[rn]=e[rn],this[B]=e[B],this[sn]=e[sn],this[Dt]=e[Dt],this[yn]=e[yn]}};var zn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=Ar,this.Header=Lr,n(this[Q]),this._identificationHeader=null,this._preSkipRemaining=null}get[Q](){return"opus"}[Et](e){return e[oe]===0?(this._headerCache[Xe](),this._identificationHeader=e[q]):e[oe]===1||(e[he]=de.get(e)[Ce].map(r=>{let n=Lr[Oe](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Dt]);let s=n[R]*n[ct]/1e3*n[D];return this._preSkipRemaining>0&&(this._preSkipRemaining-=s,s=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Ar(r,n,s)}this._codecParser[Is]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var Er=class extends Pe{constructor(e,r,n){super(r,e,n)}};var vi={};for(let t=0;t<8;t++)vi[t+6]=2**(6+t);var Fn=class t extends Ie{static[Oe](e,r,n,s){if(e[x]<30)throw new Error("Out of data while inside an Ogg Page");let o=Ee(e[O](0,30)),i=r[W](o);if(i)return new t(i);let a={[x]:30};if(o.substr(0,7)!=="vorbis")return null;a[q]=ye.from(e[O](0,30));let c=new Pt(a[q][qe]);if(a[St]=c.getUint32(7,!0),a[St]!==0||(a[I]=e[11],a[pe]=Xr[a[I]-1]||"application defined",a[D]=c.getUint32(12,!0),a[Kr]=c.getInt32(16,!0),a[qr]=c.getInt32(20,!0),a[Yr]=c.getInt32(24,!0),a[At]=vi[(e[28]&240)>>4],a[Mt]=vi[e[28]&15],a[Mt]>a[At])||e[29]!==1)return null;a[me]=32,a[vr]=s,a[an]=n;{let{length:l,data:d,version:u,vorbisSetup:m,vorbisComments:f,...p}=a;r[Be](o,a,p)}return new t(a)}constructor(e){super(e),this[Kr]=e[Kr],this[Yr]=e[Yr],this[qr]=e[qr],this[Mt]=e[Mt],this[At]=e[At],this[q]=e[q],this[an]=e[an],this[vr]=e[vr]}};var Tn=class extends xe{constructor(e,r,n){super(e,r),this.Frame=Er,n(this[Q]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[Q](){return Nt}[Et](e){e[he]=[];for(let r of de.get(e)[Ce])if(r[0]===1)this._headerCache[Xe](),this._identificationHeader=e[q],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=Fn[Oe](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[he].push(new Er(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 s=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[At]:r[Mt],o=this._prevBlockSize===null?0:(this._prevBlockSize+s)/4;return this._prevBlockSize=s,o}_parseSetupHeader(e){let r=new Cs(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let s;for(;n.count<64&&r.position>0;){vn(r.read(8));let o=0;for(;r.read(8)===0&&o++<3;);if(o===4)s=r.read(7),n.blockFlags.unshift(s&1),r.position+=6,n.count++;else{((vn(s)&126)>>1)+1!==n.count&&this._codecParser[Ge]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Si=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new ye,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[Q](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[We](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=Ee(e[O](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",zn),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",qt),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(Nt,Tn),!0;default:return!1}}_checkPageSequenceNumber(e){e[oe]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[oe]>1&&this._codecParser[Ge]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[oe]}`),this._pageSequenceNumber=e[oe]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[oe],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=de.get(e),n=ce.get(r[we]),s=0;if(r[Ce]=n[_t].map(o=>e[q][O](s,s+=o)),this._continuedPacket[x]&&(r[Ce][0]=Sn(this._continuedPacket,r[Ce][0]),this._continuedPacket=new ye),n[Sr][n[Sr][x]-1]===255&&(this._continuedPacket=Sn(this._continuedPacket,r[Ce].pop())),this._previousAbsoluteGranulePosition!==null&&(e[N]=Number(e[Ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Ve],this._isSupported){let o=this._parser[Et](e);return this._codecParser[wt](o),o}else return e}},Cn=class extends xe{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=In,this.Header=$t,this._streams=new Map,this._currentSerialNumber=null}get[Q](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ze](){let e=yield*this[Lt](!0);this._currentSerialNumber=e[Je];let r=this._streams.get(this._currentSerialNumber);return r||(r=new Si(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[Le]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var Mi=()=>{},Rn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:s,enableLogging:o=!1,enableFrameCRC32:i=!0}={}){this._inputMimeType=e,this._onCodec=r||Mi,this._onCodecHeader=n||Mi,this._onCodecUpdate=s,this._enableLogging=o,this._crc32=i?rc:Mi,this[We]()}get[Q](){return this._parser?this._parser[Q]:""}[We](){this._headerCache=new Mn(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[We]()}*parseChunk(e){for(let r=this._generator.next(e);r.value;r=this._generator.next())yield r.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new Pn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new Ln(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new qt(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new Cn(this,this._headerCache,this._onCodec);else throw new Error(`Unsupported Codec ${mimeType}`);for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){let e=yield*this._parser[Ze]();e&&(yield e)}}*[U](e=0,r=0){let n;for(;this._rawData[x]<=e+r;){if(n=yield,this._flushing)return this._rawData[O](r);n&&(this._totalBytesIn+=n[x],this._rawData=Sn(this._rawData,n))}return this._rawData[O](r)}[Re](e){this._currentReadPosition+=e,this._rawData=this._rawData[O](e)}[xn](e){this._sampleRate=e[we][D],e[we][fe]=e[$e]>0?Math.round(e[q][x]/e[$e])*8:0,e[lt]=this._frameNumber++,e[Ut]=this._totalBytesOut,e[Gt]=this._totalSamples,e[Vt]=this._totalSamples/this._sampleRate*1e3,e[Jr]=this._crc32(e[q]),this._headerCache[zs](e[we][fe],e[Vt]),this._totalBytesOut+=e[q][x],this._totalSamples+=e[N]}[wt](e){if(e[he]){if(e[Le]){let r=e[N];e[he].forEach(n=>{let s=n[N];r<s&&(n[N]=r>0?r:0,n[$e]=n[N]/n[we][D]*1e3),r-=s,this[xn](n)})}else e[N]=0,e[he].forEach(r=>{e[N]+=r[N],this[xn](r)});e[$e]=e[N]/this._sampleRate*1e3||0,e[Gt]=this._totalSamples,e[Vt]=this._totalSamples/this._sampleRate*1e3||0,e[Ut]=this._totalBytesOut}else this[xn](e)}_log(e,r){if(this._enableLogging){let n=[`${Q}: ${this[Q]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${Ut}: ${this._totalBytesOut}`],s=Math.max(...n.map(o=>o[x]));r.push(`--stats--${"-".repeat(s-9)}`,...n,"-".repeat(s)),e("codec-parser",r.reduce((o,i)=>o+`
4
+ `+i,""))}}[Ge](...e){this._log(console.warn,e)}[Is](...e){this._log(console.error,e)}};var fc=Rn;var Ws=he;var Xs=q;var hc=we;var pc=Le;var yc=vr;var gc=Gt;function dt(t){var e=e;function r(){}e={};function n(P){throw P}var s,o,i,a,c,l,d,u,m,f,p;function y(){var P=p.buffer;s=new Int8Array(P),o=new Int16Array(P),a=new Uint8Array(P),c=new Uint16Array(P),i=new Int32Array(P),l=new Uint32Array(P),d=new Float32Array(P),u=new Float64Array(P),m=new BigInt64Array(P),f=new BigUint64Array(P)}for(var h=P=>{for(var ze,kr,rr=0,Qn=0,Jn=P.length,Zn=new Uint8Array((Jn*3>>2)-(P[Jn-2]=="=")-(P[Jn-1]=="="));rr<Jn;rr+=4,Qn+=3)ze=J[P.charCodeAt(rr+1)],kr=J[P.charCodeAt(rr+2)],Zn[Qn]=J[P.charCodeAt(rr)]<<2|ze>>4,Zn[Qn+1]=ze<<4|kr>>2,Zn[Qn+2]=kr<<6|J[P.charCodeAt(rr+3)];return Zn},g=()=>n(""),S=()=>{},b={},M=P=>P(),v=()=>performance.now(),A=(P,ze)=>{if(b[P]&&(clearTimeout(b[P].id),delete b[P]),!ze)return 0;var kr=setTimeout(()=>{delete b[P],M(()=>ia(P,v()))},ze);return b[P]={id:kr,timeout_ms:ze},0},_=Math.atan,L=Math.cos,T=Math.exp,w=Math.log,H=Math.pow,G=Math.sin,V=P=>{var ze=a.length;return P>>>=0,!1},C=P=>{throw`exit(${P})`},J=new Uint8Array(123),Se=25;Se>=0;--Se)J[48+Se]=52+Se,J[65+Se]=Se,J[97+Se]=26+Se;J[43]=62,J[47]=63;var Ct={e:g,d:S,f:A,b:_,a:L,i:T,h:w,g:H,c:G,k:V,j:C};function jn(P){Br=P.n,ea=P.o,ta=P.p,ra=P.q,na=P.r,sa=P.s,oa=P.t,ia=P.v}var Br,ea,ta,ra,na,sa,oa,ia;function dl(P){P.m()}dt.wasm||Object.defineProperty(dt,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØä‘ÂLÚªã9ÚØ[äº\ ¼¡³R=}L]ŸÈÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹‡= 
5
5
  ¨¨Ÿ%‰€ýv²†±»ŸoúâLa:ê±ÊäÌÓ.÷؇ý×>àW>z¯°8¯ñ€\Ñós 9ˆ\§ôÊ@Ü (tÂø4° ¢7fqÓg²Jè6x[zç®&4=} p.(°tÍޖ™ã¾>÷CõË"*k?¿~ 7‚~H2ÛÜâ.ÏQä;Œ6{ÜãFÑá'DœD¤±°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ïg‡ˆN™¾)ø§\V0uSIö:ÌU4ж¯´Õn9ÔƒèE£ZƼ{hµmى¾6ÆžÑ+xñ´«„þ¸=M‚ߤ·å®«ïÆGFÝì|H?äE"þ!9«Æïpæ'][¯ù·£W÷O§&#aŸ‡x$qf=}ø ô bϗŸ×W÷LôožÝWQÕӎ)u †÷½èV|¥Gà¨Ö¸˜@Œê| ÇK5ò €A·Â9’CS2š¸‹¼¿,ä›Ý ÑÝy™!ÑR„%ÆÝÎ0Âv§ qTcó±hØÉã‰=}Z=}Ælü­ën¯ð(-°ÜwVχï.th¥í­‡S~SÏ»Z”ZÔZ
6
6
  3–BÌÛ¬•<éæ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ó—äs„E€\ýï鞧Ö:Ò'“Cç(_X$\¦½eҒ8$’X˜F|e‚•œíٙә‚†¡¤Û<ØÞÛ¸9‰¿ðÃÎ#b~× ‚4éîÿÏq
7
7
  ˜ód‡|0•wU‰—&®è·vh6¨—{Ú珁Ú18ә(ÓY‚\ƒ0¦= çˆèíß)Ø=} ˜[xü-v˜?N(Kk‘gš0}âډ´ð“†¬”œÕQNÍ¢usѳ=}. ëg…û= Í M—Bp'²¨ œx’4è@9t“§eݵ¾âð½ z?†‹Z¹FH'‰Ì¯¿<ŒK,üµ<{˜ ¶JãývåàÆeù0Ð"F¥ÃÒÞŽþԛÉvC›zl}„ðN’£ Í^ƒP%²¸FX»WÎêô¶…ŠäÉJ^gƒ×SÃã.žÄt*'ªG‘«ÒB<ÜӅ¿ºp­\àuV¯£›Åݑ½á–Þ ùߞ=}ÎÚ^‹Ÿÿí>¥!¨ â=M·? */¤"å)â·ÿîÿî*(%*›2[½"üríÔ4š’l½»a}¯CwpCÓèìGc-ã6®=M32†k?Êg­…–!So-™x›>³G+ã@ò,™ Áïƒá„åN0þŠÙ‚è.~È÷¡vTr¶‰­‚Æ[üB±º»ávëw¹{pÜºû"Aæ’±9Æ^¹³òïRIAy5GÂwÉfœ4@Tù|qý7†ðªwBL|ÔqŽ‘v!ª°|]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ÑU y¹¦ß§/6P0(Cúýb"þ¥°VٌÄᣈ’ÓÙ@¾YýòDŽŒ{òÃv?’EP©”=MBé­\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±†Ï€ÁÕ¯¦ð‰vZ’mT}Œ3x˘z×cºrÑM=M„ c-ɩԈ™7½wæc§Î»cû¾yf‡ÙWòŒÆÝÔc¥³ôØfƒ«Äñ·9‰ø%­g:y”^+{U]¤þ‚…[&fӁÏY낫‡Gªõ‡¹¦ÖŒðþ¬m„oÛø‘?/ÛS’.[S›9ÛùœC›…/û2”²Y£ÎÑ%/sy¢×ÌùJ­W6Oí\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¶ÌºHgN’j‡Ò{柾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 ul={a:Tt};this.setModule=P=>{t.setModule(dt,P)},this.getModule=()=>t.getModule(dt),this.instantiate=()=>(this.getModule().then(P=>WebAssembly.instantiate(P,ul)).then(P=>{let ze=P.exports;jn(ze),p=ze.l,y(),dl(ze),r()}),this.ready=new Promise(P=>{r=P}).then(()=>{this.HEAP=p.buffer,this.malloc=ea,this.free=oa,this.create_decoder=Br,this.send_setup=ta,this.init_dsp=ra,this.decode_packets=na,this.destroy_decoder=sa}),this)}function jt(){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 s=0;s<t.length;s++){let o=t[s];this._input.buf.set(o),this._inputLen.buf[0]=o.length,this._common.wasm.decode_packets(this._decoder);let i=this._samplesDecoded.buf[0],a=[],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 d=new Float32Array(i);i&&d.set(new Float32Array(this._common.wasm.HEAP,c[l],i)),a.push(d)}e.push(a),r+=i,this._frameNumber++,this._inputBytes+=o.length,this._outputSamples+=i;for(let l=0;l<this._errorsLength.buf;l+=2){let d=this._common.codeToString(this._errors.buf[l]),u=this._common.codeToString(this._errors.buf[l+1]);n.push({message:d+" vorbis_synthesis"+u,frameLength:o.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=jt.isWebWorker,this._WASMAudioDecoderCommon=jt.WASMAudioDecoderCommon||Z,this._EmscriptenWASM=jt.EmscriptenWASM||dt,this._module=jt.module,this._inputSize=128*1024,this._ready=this._init(),this}var Ks=Symbol(),ut=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Z,this._init(),this._ready=this[Ks](jt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new fc("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[Ks](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 o=0;o<e.length;o++){let i=e[o];if(this._vorbisSetupInProgress&&(i[Xs][0]===1&&this._decoder.sendSetupHeader(i[Xs]),i[Ws].length)){let a=i[Ws][0][hc];this._decoder.sendSetupHeader(a[yc]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...i[Ws].map(a=>a[Xs]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let s=e[e.length-1];if(s&&s[pc]){let o=this._totalSamplesDecoded-s[gc];if(o>0){for(let i=0;i<n.channelData.length;i++)n.channelData[i]=n.channelData[i].subarray(0,n.samplesDecoded-o);n.samplesDecoded-=o,this._totalSamplesDecoded-=o}}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 Ai=class extends ur{constructor(e){super(e,"ogg-vorbis-decoder",jt,dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},Bn=class extends ut{constructor(){super(),this._ready=super[Ks](Ai)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};gs(ut,"OggVorbisDecoder");gs(Bn,"OggVorbisDecoderWebWorker");var _i=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function Ys(t,e=new ut){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new _i(n.map(s=>s.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var kn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Pr=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new ht(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let o=(await this.vfs.readFile(e)).slice().buffer,i=await this.decodeByExtension(e,o);return this.cache.set(r,i),this.refCounts.set(r,1),i}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let s=ys(r),o=s.channels,i=Array.from({length:o},()=>new Float32Array(s.samples.length/o));for(let a=0;a<s.samples.length;a+=1)i[a%o][Math.floor(a/o)]=s.samples[a];return{sampleRate:s.sampleRate,channels:o,bitDepth:s.bitsPerSample,channelData:i}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return Ys(r);throw new kn(`Unsupported audio format: ${e}`)}};var su="quake2ts-pak-indexes",ou="pak-indexes";function xc(){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 On(t,e){let r=xc();return r?new Promise((n,s)=>{let o=r.open(t,1);o.onupgradeneeded=()=>{let{result:i}=o;i.objectStoreNames.contains(e)||i.createObjectStore(e,{keyPath:"key"})},o.onerror=()=>s(o.error??new Error("Unknown IndexedDB error")),o.onsuccess=()=>n(o.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Dn(t,e,r,n){return new Promise((s,o)=>{let a=t.transaction(e,r).objectStore(e),c=n(a);c.onsuccess=()=>s(c.result),c.onerror=()=>o(c.error??new Error("IndexedDB transaction error"))})}function wi(t,e){return`${se(t)}:${e.toString(16)}`}function iu(t){return t.map(e=>({...e}))}var qs=class{constructor(e=su,r=ou){this.dbName=e;this.storeName=r}get isSupported(){return!!xc()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:wi(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:iu(r.entries)},s=await On(this.dbName,this.storeName);return await Dn(s,this.storeName,"readwrite",o=>o.put(n)),s.close(),n}async find(e,r){if(!this.isSupported)return;let n=await On(this.dbName,this.storeName),s=r!==void 0?wi(e,r):void 0,o=await Dn(n,this.storeName,"readonly",i=>s?i.get(s):i.getAll());if(n.close(),!!o){if(Array.isArray(o)){let i=se(e),a=o.filter(c=>se(c.name)===i);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return o}}async remove(e,r){if(!this.isSupported)return!1;let n=await On(this.dbName,this.storeName),s=r!==void 0?wi(e,r):void 0,o=await Dn(n,this.storeName,"readwrite",i=>{if(s)return i.delete(s);let a=`${se(e)}:`;return i.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof o=="number"?o>0:!0}async clear(){if(!this.isSupported)return;let e=await On(this.dbName,this.storeName);await Dn(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await On(this.dbName,this.storeName),r=await Dn(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,s)=>s.persistedAt-n.persistedAt)}};var Qt=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},Nn=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(s=>n.dependencies.add(s)),this.nodes.set(e,n),r.forEach(s=>{this.nodes.has(s)||this.nodes.set(s,{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 Qt(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 s of r.dependencies)this.nodes.get(s)?.loaded||n.push(s);return n}},$s=class{constructor(e,r={}){this.vfs=e;this.textures=new dr({capacity:r.textureCacheCapacity??128}),this.audio=new Pr(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new Nn,this.md2=new ar(e),this.md3=new cr(e),this.sprite=new lr(e)}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 loadSound(e){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=[]){let n=this.makeKey("model",e),s=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,s);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Qt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let i=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),i}async loadMd3Model(e,r=[]){let n=this.makeKey("model",e),s=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,s);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Qt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let i=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),i}async loadSprite(e){let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset()}makeKey(e,r){return`${e}:${se(r)}`}};var Li=32,js=(u=>(u[u.Auto=0]="Auto",u[u.Weapon=1]="Weapon",u[u.Voice=2]="Voice",u[u.Item=3]="Item",u[u.Body=4]="Body",u[u.Aux=5]="Aux",u[u.Footstep=6]="Footstep",u[u.Aux3=7]="Aux3",u[u.NoPhsAdd=8]="NoPhsAdd",u[u.Reliable=16]="Reliable",u[u.ForcePos=32]="ForcePos",u))(js||{}),bc=-1,Qs=0,vc=1,Sc=2,Mc=3,Ir=80,Ac=.003;function Jt(t){return t===3?t*.001:t*5e-4}function Js(t){let e=Jt(t);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var Zs=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function eo(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),s=e.createBiquadFilter?.();return s?(s.type="lowpass",s.frequency.value=2e4,s.Q.value=.707,r.connect(s),s.connect(n)):r.connect(n),n.connect(e.destination),{context:e,master:r,compressor:n,filter:s}}var to=class{constructor(e=new or){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}};var ro=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(o=>this.normalize(o)))],n={loaded:[],skipped:[],missing:[],errors:{}},s=this.contextController.getContext();for(let o of r)try{let i=this.registry.find(o);if(i!==void 0&&this.registry.has(i)){n.skipped.push(o);continue}if(!this.vfs.stat(o)){n.missing.push(o);continue}let l=(await this.vfs.readFile(o)).slice().buffer,d=await this.decodeAudio(s,l);this.registry.register(o,d),n.loaded.push(o)}catch(i){let a=i instanceof Error?i:new Error(String(i));n.errors[o]=a}return n}normalize(e){let r=se(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:se(`${this.soundRoot}${r}`)}};var au=7,Hn=t=>t&au;function no(t){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function so(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let s=Hn(r),o=-1,i=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let c=t[a],l=Hn(c.entchannel);if(s!==0&&c.entnum===e&&l===s){o=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let d=c.endTimeMs-n.nowMs;(o===-1||d<i)&&(i=d,o=a)}return o===-1?void 0:o}function oo(t,e,r,n,s){if(s)return{left:r,right:r,distanceComponent:0};let o=la(t,e.origin),i=Go(o),a=Ue(o),c=i-80;c<0&&(c=0),c*=Jt(n);let l=Vo(e.right,a),d=e.mono??!1,u=d||n===0?1:.5*(1+l),m=d||n===0?1:.5*(1-l),f=Math.max(0,Math.floor(r*(1-c)*u));return{left:Math.max(0,Math.floor(r*(1-c)*m)),right:f,distanceComponent:c}}var io=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=no(e.playerEntity),this.listener=e.listener??{origin:ca,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=eo(this.contextController),this.graph.master.gain.value=this.masterVolume}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}async ensureRunning(){await this.contextController.resume()}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,s=n.currentTime*1e3,o=so(this.channels,e.entity,e.channel,{nowMs:s,playerEntity:this.playerEntity});if(o===void 0)return;let i=this.activeSources.get(o);i&&(i.source.onended=null,i.source.stop(),this.activeSources.delete(o));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),d=this.createPanner(n,e.attenuation),u=this.resolveOcclusion?.(this.listener,c,e.attenuation),m=_c(u?.gainScale??1),f=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let p=e.entity===this.playerEntity,y=oo(c,this.listener,e.volume,e.attenuation,p),g=(e.volume===0?0:Math.max(y.left,y.right)/Math.max(1,e.volume))*(e.volume/255)*this.masterVolume*this.sfxVolume;l.gain.value=g*m;let S=n.currentTime+(e.timeOffsetMs??0)/1e3,b=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+S*1e3;a.connect(d),f?(d.connect(f),f.connect(l)):d.connect(l),l.connect(this.graph.master),a.start(S),a.onended=()=>{this.channels[o].active=!1,this.activeSources.delete(o)};let M={channelIndex:o,entnum:e.entity,entchannel:Hn(e.channel),endTimeMs:b,source:a,panner:d,gain:l,baseGain:g,origin:c,attenuation:e.attenuation,occlusion:f?{scale:m,lowpassHz:u?.lowpassHz,filter:f}:u?{scale:m,lowpassHz:u.lowpassHz}:void 0};return this.channels[o]={entnum:e.entity,entchannel:Hn(e.channel),endTimeMs:b,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(o,M),M}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 s=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,s)}}positionedSound(e,r,n,s){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:s,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:0,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=Jt(r);return e.refDistance=80,e.maxDistance=Js(r),e.rolloffFactor=n,e.distanceModel=r===0?"linear":"inverse",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=Ei(r,10,2e4),n}applyOcclusion(e,r){let n=_c(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Ei(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Ei=(t,e,r)=>Math.min(r,Math.max(e,t)),_c=t=>Ei(t,0,1);var ao=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.element){this.element.loop=r,this.element.volume=this.volume,n&&(this.element.currentTime=0),(this.element.paused||n)&&await this.element.play();return}let s=await this.resolveSource(e),o=this.createElement();o.src=s,o.loop=r,o.volume=this.volume,o.currentTime=0,o.load(),await o.play(),this.element=o,this.track=e}pause(){!this.element||this.element.paused||this.element.pause()}async resume(){!this.element||!this.element.paused||await this.element.play()}stop(){this.element&&(this.element.pause(),this.element.currentTime=0,this.element=void 0,this.track=void 0)}setVolume(e){this.volume=e,this.element&&(this.element.volume=e)}getState(){let e=!!(this.element&&!this.element.paused&&!this.element.ended),r=!!this.element?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}};var co=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,s,o,i){this.system.play({entity:e,channel:r,soundIndex:n,volume:s,attenuation:o,timeOffsetMs:i})}positioned_sound(e,r,n,s){this.system.positionedSound(e,r,n,s)}loop_sound(e,r,n,s,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:s,attenuation:o,looping:!0})}stop_entity_sounds(e){this.system.stopEntitySounds(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n)}play_channel(e){this.system.play({...e})}};function cu(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 lu(t,e,r,n){for(let s of e){let o=t.getExtension(s);if(!o)throw new Error(`Missing required WebGL extension: ${s}`);n.set(s,o)}for(let s of r){let o=t.getExtension(s);o&&n.set(s,o)}}function wc(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:s=[]}=e,o=t.getContext("webgl2",r??{antialias:!0});if(!o)throw new Error("WebGL2 not supported or failed to initialize");cu(o);let i=new Map;lu(o,n,s,i);let a=!1,c=new Set,l=new Set,d=m=>{a=!0,m.preventDefault();for(let f of c)f()},u=()=>{a=!1;for(let m of l)m()};return t.addEventListener("webglcontextlost",d),t.addEventListener("webglcontextrestored",u),{gl:o,extensions:i,isLost:()=>a,onLost(m){return c.add(m),()=>c.delete(m)},onRestored(m){return l.add(m),()=>l.delete(m)},dispose(){t.removeEventListener("webglcontextlost",d),t.removeEventListener("webglcontextrestored",u),c.clear(),l.clear(),i.clear()}}}function Lc(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(o)}return n}function du(t,e,r,n){let s=t.createProgram();if(!s)throw new Error("Failed to allocate shader program");if(t.attachShader(s,e),t.attachShader(s,r),n)for(let[i,a]of Object.entries(n))t.bindAttribLocation(s,a,i);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){let i=t.getProgramInfoLog(s)??"Unknown shader link failure";throw t.deleteProgram(s),new Error(i)}return s}var be=class t{constructor(e,r){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r}static create(e,r,n){let s=Lc(e,e.VERTEX_SHADER,r.vertex),o=Lc(e,e.FRAGMENT_SHADER,r.fragment);try{let i=du(e,s,o,n);return new t(e,i)}finally{e.deleteShader(s),e.deleteShader(o)}}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 Ec(t,e,r){return be.create(t,e,r)}var ve=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let s=e.createBuffer();if(!s)throw new Error("Failed to allocate buffer");this.buffer=s,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)}},Ne=class extends ve{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},_e=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},zr=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,s,o,i,a,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,s,o,i,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},Fr=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,s,o,i,a,c,l){this.bind(),this.gl.texImage2D(e,r,n,s,o,i,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},lo=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Ii=4,Pi=7*Ii,zi=[{index:0,size:3,type:5126,stride:Pi,offset:0},{index:1,size:2,type:5126,stride:Pi,offset:3*Ii},{index:2,size:2,type:5126,stride:Pi,offset:5*Ii}];function uu(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function mu(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 fu(t,e,r){let n=mu(r),s=t.width*4,o=e.x+t.padding,i=e.y+t.padding,a=0;for(let c=0;c<r.height;c++){let l=(i+c)*s+o*4;for(let d=0;d<r.width;d++){let u=l+d*4;t.data[u]=r.samples[a],t.data[u+1]=r.samples[a+1],t.data[u+2]=r.samples[a+2],t.data[u+3]=n===4?r.samples[a+3]:255,a+=n}}}function hu(t,e,r){let n=e.width+r.lightmapPadding*2,s=e.height+r.lightmapPadding*2;if(n>r.atlasSize||s>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+s>a.height)continue;let c={atlasIndex:t.indexOf(a),x:a.cursorX,y:a.cursorY,width:e.width,height:e.height};return a.cursorX+=n+r.lightmapPadding,a.rowHeight=Math.max(a.rowHeight,s),{placement:c,atlas:a}}let o=uu(r.atlasSize,r.lightmapPadding);t.push(o);let i={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return o.cursorX=n+r.lightmapPadding,o.rowHeight=s,{placement:i,atlas:o}}function uo(t){return t instanceof Float32Array?t:new Float32Array(t)}function pu(t,e){if(!t){let n=new Uint16Array(e);for(let s=0;s<e;s++)n[s]=s;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function yu(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 gu(t,e){let r=uo(t.vertices),n=uo(t.textureCoords),s=e?yu(uo(t.lightmapCoords??t.textureCoords),e):uo(t.lightmapCoords??new Float32Array(n.length)),o=r.length/3;if(n.length/2!==o)throw new Error("Texture coordinates count mismatch");if(s.length/2!==o)throw new Error("Lightmap coordinates count mismatch");let i=new Float32Array(o*7);for(let a=0;a<o;a++){let c=a*3,l=a*2,d=a*7;i[d]=r[c],i[d+1]=r[c+1],i[d+2]=r[c+2],i[d+3]=n[l],i[d+4]=n[l+1],i[d+5]=s[l],i[d+6]=s[l+1]}return i}function Pc(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let s=t.texInfo[n.texInfo],o=[],i=[],a=[];for(let m=0;m<n.numEdges;m++){let f=t.surfEdges[n.firstEdge+m],p=t.edges[Math.abs(f)],y=f>=0?p.vertices[0]:p.vertices[1],h=t.vertices[y];o.push(h[0],h[1],h[2]);let g=h[0]*s.s[0]+h[1]*s.s[1]+h[2]*s.s[2]+s.sOffset,S=h[0]*s.t[0]+h[1]*s.t[1]+h[2]*s.t[2]+s.tOffset;i.push(g,S),a.push(g,S)}let c=[],l=o.length/3;for(let m=1;m<l-1;m++)c.push(0,m,m+1);let d,u=t.lightMapInfo[r];if(u){let m=1/0,f=-1/0,p=1/0,y=-1/0;for(let v=0;v<i.length;v+=2){let A=i[v],_=i[v+1];A<m&&(m=A),A>f&&(f=A),_<p&&(p=_),_>y&&(y=_)}let h=Math.floor(m/16),g=Math.floor(p/16),S=Math.ceil(f/16)-h+1,b=Math.ceil(y/16)-g+1,M=ms(n,t.lightMaps,u);if(M&&M.length===S*b*3){d={width:S,height:b,samples:M};for(let v=0;v<a.length;v+=2)a[v]=i[v]/16-h+.5,a[v+1]=i[v+1]/16-g+.5}}e.push({vertices:new Float32Array(o),textureCoords:new Float32Array(i),lightmapCoords:new Float32Array(a),indices:new Uint16Array(c),texture:s.texture,surfaceFlags:s.flags,lightmap:d})}return e}function Ic(t,e,r={}){let n={atlasSize:r.atlasSize??1024,lightmapPadding:r.lightmapPadding??1},s=[],o=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:d,atlas:u}=hu(s,c.lightmap,n);fu(u,d,c.lightmap),o.set(l,{atlasIndex:d.atlasIndex,offset:[(d.x+n.lightmapPadding)/n.atlasSize,(d.y+n.lightmapPadding)/n.atlasSize],scale:[d.width/n.atlasSize,d.height/n.atlasSize]})});let i=s.map(c=>{let l=new zr(t);return l.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),l.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:l,width:c.width,height:c.height,pixels:c.data}});return{surfaces:e.map((c,l)=>{let d=o.get(l),u=gu(c,d),m=pu(c.indices,u.length/7),f=new ve(t,t.STATIC_DRAW,t.ARRAY_BUFFER);f.upload(u);let p=new Ne(t,t.STATIC_DRAW);p.upload(m);let y=new _e(t);return y.configureAttributes(zi,f),{vao:y,vertexBuffer:f,indexBuffer:p,indexCount:m.length,vertexCount:u.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??Dr,lightmap:d,vertexData:u,indexData:m}}),lightmaps:i}}function Cr(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 s=1/n;return{normal:{x:e.x*s,y:e.y*s,z:e.z*s},distance:r*s}}function zc(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],s=t[12],o=t[1],i=t[5],a=t[9],c=t[13],l=t[2],d=t[6],u=t[10],m=t[14],f=t[3],p=t[7],y=t[11],h=t[15];return[Cr({normal:{x:f+e,y:p+r,z:y+n},distance:h+s}),Cr({normal:{x:f-e,y:p-r,z:y-n},distance:h-s}),Cr({normal:{x:f+o,y:p+i,z:y+a},distance:h+c}),Cr({normal:{x:f-o,y:p-i,z:y-a},distance:h-c}),Cr({normal:{x:f+l,y:p+d,z:y+u},distance:h+m}),Cr({normal:{x:f-l,y:p-d,z:y-u},distance:h-m})]}function xu(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Un(t,e,r){for(let n of r){let s=n.normal.x>=0?e.x:t.x,o=n.normal.y>=0?e.y:t.y,i=n.normal.z>=0?e.z:t.z;if(xu(n,{x:s,y:o,z:i})<0)return!1}return!0}function Fc(t){return t<0}function Cc(t){return-t-1}function Tc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function bu(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),s=t.clusters[e].pvs,o=Math.floor(r/8),i=1<<r%8;return o<0||o>=n?!1:(s[o]&i)!==0}function vu(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 Un(r,n,e)}function Ci(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],s=t.planes[n.planeIndex],i=Tc(s,e)>=0?0:1,a=n.children[i];if(Fc(a))return Cc(a);r=a}return-1}function Su(t,e){let r=t.leafs[e],n=[];for(let s=0;s<r.numLeafFaces;s+=1)n.push(t.leafLists.leafFaces[e][s]);return n}function Fi(t,e,r,n,s,o,i){if(Fc(e)){let m=Cc(e),f=t.leafs[m];if(!bu(t.visibility,s,f.cluster)||!vu(f,n))return;let p={x:(f.mins[0]+f.maxs[0])*.5,y:(f.mins[1]+f.maxs[1])*.5,z:(f.mins[2]+f.maxs[2])*.5},y=p.x-r.x,h=p.y-r.y,g=p.z-r.z,S=-(y*y+h*h+g*g);for(let b of Su(t,m))i.has(b)||(i.add(b),o.push({faceIndex:b,leafIndex:m,sortKey:S}));return}let a=t.nodes[e],c=t.planes[a.planeIndex],l=Tc(c,r),d=l>=0?a.children[0]:a.children[1],u=l>=0?a.children[1]:a.children[0];Un({x:a.mins[0],y:a.mins[1],z:a.mins[2]},{x:a.maxs[0],y:a.maxs[1],z:a.maxs[2]},n)&&(Fi(t,d,r,n,s,o,i),Fi(t,u,r,n,s,o,i))}function Rc(t,e,r){let n=Ci(t,e),s=n>=0?t.leafs[n].cluster:-1,o=[];return Fi(t,0,e,r,s,o,new Set),o}var Ti=`#version 300 es
141
+ ïBçϧmÙIólÜoëVbƒ¦¯éWÇû3`});var ul={a:Ct};this.setModule=P=>{t.setModule(dt,P)},this.getModule=()=>t.getModule(dt),this.instantiate=()=>(this.getModule().then(P=>WebAssembly.instantiate(P,ul)).then(P=>{let ze=P.exports;jn(ze),p=ze.l,y(),dl(ze),r()}),this.ready=new Promise(P=>{r=P}).then(()=>{this.HEAP=p.buffer,this.malloc=ea,this.free=oa,this.create_decoder=Br,this.send_setup=ta,this.init_dsp=ra,this.decode_packets=na,this.destroy_decoder=sa}),this)}function jt(){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 s=0;s<t.length;s++){let o=t[s];this._input.buf.set(o),this._inputLen.buf[0]=o.length,this._common.wasm.decode_packets(this._decoder);let i=this._samplesDecoded.buf[0],a=[],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 d=new Float32Array(i);i&&d.set(new Float32Array(this._common.wasm.HEAP,c[l],i)),a.push(d)}e.push(a),r+=i,this._frameNumber++,this._inputBytes+=o.length,this._outputSamples+=i;for(let l=0;l<this._errorsLength.buf;l+=2){let d=this._common.codeToString(this._errors.buf[l]),u=this._common.codeToString(this._errors.buf[l+1]);n.push({message:d+" vorbis_synthesis"+u,frameLength:o.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=jt.isWebWorker,this._WASMAudioDecoderCommon=jt.WASMAudioDecoderCommon||Z,this._EmscriptenWASM=jt.EmscriptenWASM||dt,this._module=jt.module,this._inputSize=128*1024,this._ready=this._init(),this}var Ks=Symbol(),ut=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new Z,this._init(),this._ready=this[Ks](jt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new fc("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[Ks](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 o=0;o<e.length;o++){let i=e[o];if(this._vorbisSetupInProgress&&(i[Xs][0]===1&&this._decoder.sendSetupHeader(i[Xs]),i[Ws].length)){let a=i[Ws][0][hc];this._decoder.sendSetupHeader(a[yc]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...i[Ws].map(a=>a[Xs]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let s=e[e.length-1];if(s&&s[pc]){let o=this._totalSamplesDecoded-s[gc];if(o>0){for(let i=0;i<n.channelData.length;i++)n.channelData[i]=n.channelData[i].subarray(0,n.samplesDecoded-o);n.samplesDecoded-=o,this._totalSamplesDecoded-=o}}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 Ai=class extends ur{constructor(e){super(e,"ogg-vorbis-decoder",jt,dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},Bn=class extends ut{constructor(){super(),this._ready=super[Ks](Ai)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};gs(ut,"OggVorbisDecoder");gs(Bn,"OggVorbisDecoderWebWorker");var _i=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function Ys(t,e=new ut){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new _i(n.map(s=>s.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var kn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},Pr=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new ht(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let o=(await this.vfs.readFile(e)).slice().buffer,i=await this.decodeByExtension(e,o);return this.cache.set(r,i),this.refCounts.set(r,1),i}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let s=ys(r),o=s.channels,i=Array.from({length:o},()=>new Float32Array(s.samples.length/o));for(let a=0;a<s.samples.length;a+=1)i[a%o][Math.floor(a/o)]=s.samples[a];return{sampleRate:s.sampleRate,channels:o,bitDepth:s.bitsPerSample,channelData:i}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return Ys(r);throw new kn(`Unsupported audio format: ${e}`)}};var su="quake2ts-pak-indexes",ou="pak-indexes";function xc(){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 On(t,e){let r=xc();return r?new Promise((n,s)=>{let o=r.open(t,1);o.onupgradeneeded=()=>{let{result:i}=o;i.objectStoreNames.contains(e)||i.createObjectStore(e,{keyPath:"key"})},o.onerror=()=>s(o.error??new Error("Unknown IndexedDB error")),o.onsuccess=()=>n(o.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function Dn(t,e,r,n){return new Promise((s,o)=>{let a=t.transaction(e,r).objectStore(e),c=n(a);c.onsuccess=()=>s(c.result),c.onerror=()=>o(c.error??new Error("IndexedDB transaction error"))})}function wi(t,e){return`${se(t)}:${e.toString(16)}`}function iu(t){return t.map(e=>({...e}))}var qs=class{constructor(e=su,r=ou){this.dbName=e;this.storeName=r}get isSupported(){return!!xc()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:wi(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:iu(r.entries)},s=await On(this.dbName,this.storeName);return await Dn(s,this.storeName,"readwrite",o=>o.put(n)),s.close(),n}async find(e,r){if(!this.isSupported)return;let n=await On(this.dbName,this.storeName),s=r!==void 0?wi(e,r):void 0,o=await Dn(n,this.storeName,"readonly",i=>s?i.get(s):i.getAll());if(n.close(),!!o){if(Array.isArray(o)){let i=se(e),a=o.filter(c=>se(c.name)===i);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return o}}async remove(e,r){if(!this.isSupported)return!1;let n=await On(this.dbName,this.storeName),s=r!==void 0?wi(e,r):void 0,o=await Dn(n,this.storeName,"readwrite",i=>{if(s)return i.delete(s);let a=`${se(e)}:`;return i.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof o=="number"?o>0:!0}async clear(){if(!this.isSupported)return;let e=await On(this.dbName,this.storeName);await Dn(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await On(this.dbName,this.storeName),r=await Dn(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,s)=>s.persistedAt-n.persistedAt)}};var Qt=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},Nn=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(s=>n.dependencies.add(s)),this.nodes.set(e,n),r.forEach(s=>{this.nodes.has(s)||this.nodes.set(s,{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 Qt(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 s of r.dependencies)this.nodes.get(s)?.loaded||n.push(s);return n}},$s=class{constructor(e,r={}){this.vfs=e;this.textures=new dr({capacity:r.textureCacheCapacity??128}),this.audio=new Pr(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new Nn,this.md2=new ar(e),this.md3=new cr(e),this.sprite=new lr(e)}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 loadSound(e){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=[]){let n=this.makeKey("model",e),s=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,s);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Qt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let i=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),i}async loadMd3Model(e,r=[]){let n=this.makeKey("model",e),s=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,s);let o=this.dependencyTracker.missingDependencies(n);if(o.length>0)throw new Qt(o,`Asset ${n} is missing dependencies: ${o.join(", ")}`);let i=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),i}async loadSprite(e){let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset()}makeKey(e,r){return`${e}:${se(r)}`}};var Li=32,js=(u=>(u[u.Auto=0]="Auto",u[u.Weapon=1]="Weapon",u[u.Voice=2]="Voice",u[u.Item=3]="Item",u[u.Body=4]="Body",u[u.Aux=5]="Aux",u[u.Footstep=6]="Footstep",u[u.Aux3=7]="Aux3",u[u.NoPhsAdd=8]="NoPhsAdd",u[u.Reliable=16]="Reliable",u[u.ForcePos=32]="ForcePos",u))(js||{}),bc=-1,Qs=0,vc=1,Sc=2,Mc=3,Ir=80,Ac=.003;function Jt(t){return t===3?t*.001:t*5e-4}function Js(t){let e=Jt(t);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var Zs=class{constructor(e){this.factory=e}getContext(){return this.context||(this.context=this.factory()),this.context}async resume(){let e=this.getContext();e.state==="suspended"&&await e.resume()}getState(){return this.context?.state??"suspended"}};function eo(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),s=e.createBiquadFilter?.();return s?(s.type="lowpass",s.frequency.value=2e4,s.Q.value=.707,r.connect(s),s.connect(n)):r.connect(n),n.connect(e.destination),{context:e,master:r,compressor:n,filter:s}}var to=class{constructor(e=new or){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}};var ro=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(o=>this.normalize(o)))],n={loaded:[],skipped:[],missing:[],errors:{}},s=this.contextController.getContext();for(let o of r)try{let i=this.registry.find(o);if(i!==void 0&&this.registry.has(i)){n.skipped.push(o);continue}if(!this.vfs.stat(o)){n.missing.push(o);continue}let l=(await this.vfs.readFile(o)).slice().buffer,d=await this.decodeAudio(s,l);this.registry.register(o,d),n.loaded.push(o)}catch(i){let a=i instanceof Error?i:new Error(String(i));n.errors[o]=a}return n}normalize(e){let r=se(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:se(`${this.soundRoot}${r}`)}};var au=7,Hn=t=>t&au;function no(t){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function so(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let s=Hn(r),o=-1,i=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let c=t[a],l=Hn(c.entchannel);if(s!==0&&c.entnum===e&&l===s){o=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let d=c.endTimeMs-n.nowMs;(o===-1||d<i)&&(i=d,o=a)}return o===-1?void 0:o}function oo(t,e,r,n,s){if(s)return{left:r,right:r,distanceComponent:0};let o=la(t,e.origin),i=Go(o),a=Ue(o),c=i-80;c<0&&(c=0),c*=Jt(n);let l=Vo(e.right,a),d=e.mono??!1,u=d||n===0?1:.5*(1+l),m=d||n===0?1:.5*(1-l),f=Math.max(0,Math.floor(r*(1-c)*u));return{left:Math.max(0,Math.floor(r*(1-c)*m)),right:f,distanceComponent:c}}var io=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=no(e.playerEntity),this.listener=e.listener??{origin:ca,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=eo(this.contextController),this.graph.master.gain.value=this.masterVolume}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}async ensureRunning(){await this.contextController.resume()}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,s=n.currentTime*1e3,o=so(this.channels,e.entity,e.channel,{nowMs:s,playerEntity:this.playerEntity});if(o===void 0)return;let i=this.activeSources.get(o);i&&(i.source.onended=null,i.source.stop(),this.activeSources.delete(o));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),d=this.createPanner(n,e.attenuation),u=this.resolveOcclusion?.(this.listener,c,e.attenuation),m=_c(u?.gainScale??1),f=this.resolveOcclusion?this.createOcclusionFilter(n,u?.lowpassHz??2e4):void 0;this.applyOriginToPanner(d,c);let p=e.entity===this.playerEntity,y=oo(c,this.listener,e.volume,e.attenuation,p),g=(e.volume===0?0:Math.max(y.left,y.right)/Math.max(1,e.volume))*(e.volume/255)*this.masterVolume*this.sfxVolume;l.gain.value=g*m;let S=n.currentTime+(e.timeOffsetMs??0)/1e3,b=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+S*1e3;a.connect(d),f?(d.connect(f),f.connect(l)):d.connect(l),l.connect(this.graph.master),a.start(S),a.onended=()=>{this.channels[o].active=!1,this.activeSources.delete(o)};let M={channelIndex:o,entnum:e.entity,entchannel:Hn(e.channel),endTimeMs:b,source:a,panner:d,gain:l,baseGain:g,origin:c,attenuation:e.attenuation,occlusion:f?{scale:m,lowpassHz:u?.lowpassHz,filter:f}:u?{scale:m,lowpassHz:u.lowpassHz}:void 0};return this.channels[o]={entnum:e.entity,entchannel:Hn(e.channel),endTimeMs:b,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(o,M),M}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 s=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,s)}}positionedSound(e,r,n,s){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:s,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:0,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=Jt(r);return e.refDistance=80,e.maxDistance=Js(r),e.rolloffFactor=n,e.distanceModel=r===0?"linear":"inverse",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=Ei(r,10,2e4),n}applyOcclusion(e,r){let n=_c(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Ei(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Ei=(t,e,r)=>Math.min(r,Math.max(e,t)),_c=t=>Ei(t,0,1);var ao=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.element){this.element.loop=r,this.element.volume=this.volume,n&&(this.element.currentTime=0),(this.element.paused||n)&&await this.element.play();return}let s=await this.resolveSource(e),o=this.createElement();o.src=s,o.loop=r,o.volume=this.volume,o.currentTime=0,o.load(),await o.play(),this.element=o,this.track=e}pause(){!this.element||this.element.paused||this.element.pause()}async resume(){!this.element||!this.element.paused||await this.element.play()}stop(){this.element&&(this.element.pause(),this.element.currentTime=0,this.element=void 0,this.track=void 0)}setVolume(e){this.volume=e,this.element&&(this.element.volume=e)}getState(){let e=!!(this.element&&!this.element.paused&&!this.element.ended),r=!!this.element?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}};var co=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music}soundindex(e){return this.registry.registerName(e)}sound(e,r,n,s,o,i){this.system.play({entity:e,channel:r,soundIndex:n,volume:s,attenuation:o,timeOffsetMs:i})}positioned_sound(e,r,n,s){this.system.positionedSound(e,r,n,s)}loop_sound(e,r,n,s,o){this.system.play({entity:e,channel:r,soundIndex:n,volume:s,attenuation:o,looping:!0})}stop_entity_sounds(e){this.system.stopEntitySounds(e)}set_listener(e){this.system.setListener(e)}play_music(e,r=!0){return this.music?this.music.play(e,{loop:r}):Promise.resolve()}pause_music(){this.music?.pause()}resume_music(){return this.music?.resume()??Promise.resolve()}stop_music(){this.music?.stop()}set_music_volume(e){this.music?.setVolume(e)}play_ambient(e,r,n){this.system.ambientSound(e,r,n)}play_channel(e){this.system.play({...e})}};function cu(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 lu(t,e,r,n){for(let s of e){let o=t.getExtension(s);if(!o)throw new Error(`Missing required WebGL extension: ${s}`);n.set(s,o)}for(let s of r){let o=t.getExtension(s);o&&n.set(s,o)}}function wc(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:s=[]}=e,o=t.getContext("webgl2",r??{antialias:!0});if(!o)throw new Error("WebGL2 not supported or failed to initialize");cu(o);let i=new Map;lu(o,n,s,i);let a=!1,c=new Set,l=new Set,d=m=>{a=!0,m.preventDefault();for(let f of c)f()},u=()=>{a=!1;for(let m of l)m()};return t.addEventListener("webglcontextlost",d),t.addEventListener("webglcontextrestored",u),{gl:o,extensions:i,isLost:()=>a,onLost(m){return c.add(m),()=>c.delete(m)},onRestored(m){return l.add(m),()=>l.delete(m)},dispose(){t.removeEventListener("webglcontextlost",d),t.removeEventListener("webglcontextrestored",u),c.clear(),l.clear(),i.clear()}}}function Lc(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let o=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(o)}return n}function du(t,e,r,n){let s=t.createProgram();if(!s)throw new Error("Failed to allocate shader program");if(t.attachShader(s,e),t.attachShader(s,r),n)for(let[i,a]of Object.entries(n))t.bindAttribLocation(s,a,i);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){let i=t.getProgramInfoLog(s)??"Unknown shader link failure";throw t.deleteProgram(s),new Error(i)}return s}var be=class t{constructor(e,r){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r}static create(e,r,n){let s=Lc(e,e.VERTEX_SHADER,r.vertex),o=Lc(e,e.FRAGMENT_SHADER,r.fragment);try{let i=du(e,s,o,n);return new t(e,i)}finally{e.deleteShader(s),e.deleteShader(o)}}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 Ec(t,e,r){return be.create(t,e,r)}var ve=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let s=e.createBuffer();if(!s)throw new Error("Failed to allocate buffer");this.buffer=s,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)}},Ne=class extends ve{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},_e=class{constructor(e){this.gl=e;let r=e.createVertexArray();if(!r)throw new Error("Failed to allocate vertex array object");this.vao=r}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,r){this.bind(),r&&r.bind();for(let n of e)this.gl.enableVertexAttribArray(n.index),this.gl.vertexAttribPointer(n.index,n.size,n.type,n.normalized??!1,n.stride??0,n.offset??0),n.divisor!==void 0&&this.gl.vertexAttribDivisor(n.index,n.divisor)}dispose(){this.gl.deleteVertexArray(this.vao)}},zr=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,s,o,i,a,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,s,o,i,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},Fr=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,s,o,i,a,c,l){this.bind(),this.gl.texImage2D(e,r,n,s,o,i,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},lo=class{constructor(e){this.gl=e;let r=e.createFramebuffer();if(!r)throw new Error("Failed to allocate framebuffer");this.framebuffer=r}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,r,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,r.target,r.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var Ii=4,Pi=7*Ii,zi=[{index:0,size:3,type:5126,stride:Pi,offset:0},{index:1,size:2,type:5126,stride:Pi,offset:3*Ii},{index:2,size:2,type:5126,stride:Pi,offset:5*Ii}];function uu(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function mu(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 fu(t,e,r){let n=mu(r),s=t.width*4,o=e.x+t.padding,i=e.y+t.padding,a=0;for(let c=0;c<r.height;c++){let l=(i+c)*s+o*4;for(let d=0;d<r.width;d++){let u=l+d*4;t.data[u]=r.samples[a],t.data[u+1]=r.samples[a+1],t.data[u+2]=r.samples[a+2],t.data[u+3]=n===4?r.samples[a+3]:255,a+=n}}}function hu(t,e,r){let n=e.width+r.lightmapPadding*2,s=e.height+r.lightmapPadding*2;if(n>r.atlasSize||s>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+s>a.height)continue;let c={atlasIndex:t.indexOf(a),x:a.cursorX,y:a.cursorY,width:e.width,height:e.height};return a.cursorX+=n+r.lightmapPadding,a.rowHeight=Math.max(a.rowHeight,s),{placement:c,atlas:a}}let o=uu(r.atlasSize,r.lightmapPadding);t.push(o);let i={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return o.cursorX=n+r.lightmapPadding,o.rowHeight=s,{placement:i,atlas:o}}function uo(t){return t instanceof Float32Array?t:new Float32Array(t)}function pu(t,e){if(!t){let n=new Uint16Array(e);for(let s=0;s<e;s++)n[s]=s;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function yu(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 gu(t,e){let r=uo(t.vertices),n=uo(t.textureCoords),s=e?yu(uo(t.lightmapCoords??t.textureCoords),e):uo(t.lightmapCoords??new Float32Array(n.length)),o=r.length/3;if(n.length/2!==o)throw new Error("Texture coordinates count mismatch");if(s.length/2!==o)throw new Error("Lightmap coordinates count mismatch");let i=new Float32Array(o*7);for(let a=0;a<o;a++){let c=a*3,l=a*2,d=a*7;i[d]=r[c],i[d+1]=r[c+1],i[d+2]=r[c+2],i[d+3]=n[l],i[d+4]=n[l+1],i[d+5]=s[l],i[d+6]=s[l+1]}return i}function Pc(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let s=t.texInfo[n.texInfo],o=[],i=[],a=[];for(let m=0;m<n.numEdges;m++){let f=t.surfEdges[n.firstEdge+m],p=t.edges[Math.abs(f)],y=f>=0?p.vertices[0]:p.vertices[1],h=t.vertices[y];o.push(h[0],h[1],h[2]);let g=h[0]*s.s[0]+h[1]*s.s[1]+h[2]*s.s[2]+s.sOffset,S=h[0]*s.t[0]+h[1]*s.t[1]+h[2]*s.t[2]+s.tOffset;i.push(g,S),a.push(g,S)}let c=[],l=o.length/3;for(let m=1;m<l-1;m++)c.push(0,m,m+1);let d,u=t.lightMapInfo[r];if(u){let m=1/0,f=-1/0,p=1/0,y=-1/0;for(let v=0;v<i.length;v+=2){let A=i[v],_=i[v+1];A<m&&(m=A),A>f&&(f=A),_<p&&(p=_),_>y&&(y=_)}let h=Math.floor(m/16),g=Math.floor(p/16),S=Math.ceil(f/16)-h+1,b=Math.ceil(y/16)-g+1,M=ms(n,t.lightMaps,u);if(M&&M.length===S*b*3){d={width:S,height:b,samples:M};for(let v=0;v<a.length;v+=2)a[v]=i[v]/16-h+.5,a[v+1]=i[v+1]/16-g+.5}}e.push({vertices:new Float32Array(o),textureCoords:new Float32Array(i),lightmapCoords:new Float32Array(a),indices:new Uint16Array(c),texture:s.texture,surfaceFlags:s.flags,lightmap:d})}return e}function Ic(t,e,r={}){let n={atlasSize:r.atlasSize??1024,lightmapPadding:r.lightmapPadding??1},s=[],o=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:d,atlas:u}=hu(s,c.lightmap,n);fu(u,d,c.lightmap),o.set(l,{atlasIndex:d.atlasIndex,offset:[(d.x+n.lightmapPadding)/n.atlasSize,(d.y+n.lightmapPadding)/n.atlasSize],scale:[d.width/n.atlasSize,d.height/n.atlasSize]})});let i=s.map(c=>{let l=new zr(t);return l.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),l.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:l,width:c.width,height:c.height,pixels:c.data}});return{surfaces:e.map((c,l)=>{let d=o.get(l),u=gu(c,d),m=pu(c.indices,u.length/7),f=new ve(t,t.STATIC_DRAW,t.ARRAY_BUFFER);f.upload(u);let p=new Ne(t,t.STATIC_DRAW);p.upload(m);let y=new _e(t);return y.configureAttributes(zi,f),{vao:y,vertexBuffer:f,indexBuffer:p,indexCount:m.length,vertexCount:u.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??Dr,lightmap:d,vertexData:u,indexData:m}}),lightmaps:i}}function Tr(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 s=1/n;return{normal:{x:e.x*s,y:e.y*s,z:e.z*s},distance:r*s}}function zc(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],s=t[12],o=t[1],i=t[5],a=t[9],c=t[13],l=t[2],d=t[6],u=t[10],m=t[14],f=t[3],p=t[7],y=t[11],h=t[15];return[Tr({normal:{x:f+e,y:p+r,z:y+n},distance:h+s}),Tr({normal:{x:f-e,y:p-r,z:y-n},distance:h-s}),Tr({normal:{x:f+o,y:p+i,z:y+a},distance:h+c}),Tr({normal:{x:f-o,y:p-i,z:y-a},distance:h-c}),Tr({normal:{x:f+l,y:p+d,z:y+u},distance:h+m}),Tr({normal:{x:f-l,y:p-d,z:y-u},distance:h-m})]}function xu(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Un(t,e,r){for(let n of r){let s=n.normal.x>=0?e.x:t.x,o=n.normal.y>=0?e.y:t.y,i=n.normal.z>=0?e.z:t.z;if(xu(n,{x:s,y:o,z:i})<0)return!1}return!0}function Fc(t){return t<0}function Tc(t){return-t-1}function Cc(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function bu(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),s=t.clusters[e].pvs,o=Math.floor(r/8),i=1<<r%8;return o<0||o>=n?!1:(s[o]&i)!==0}function vu(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 Un(r,n,e)}function Ti(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],s=t.planes[n.planeIndex],i=Cc(s,e)>=0?0:1,a=n.children[i];if(Fc(a))return Tc(a);r=a}return-1}function Su(t,e){let r=t.leafs[e],n=[];for(let s=0;s<r.numLeafFaces;s+=1)n.push(t.leafLists.leafFaces[e][s]);return n}function Fi(t,e,r,n,s,o,i){if(Fc(e)){let m=Tc(e),f=t.leafs[m];if(!bu(t.visibility,s,f.cluster)||!vu(f,n))return;let p={x:(f.mins[0]+f.maxs[0])*.5,y:(f.mins[1]+f.maxs[1])*.5,z:(f.mins[2]+f.maxs[2])*.5},y=p.x-r.x,h=p.y-r.y,g=p.z-r.z,S=-(y*y+h*h+g*g);for(let b of Su(t,m))i.has(b)||(i.add(b),o.push({faceIndex:b,leafIndex:m,sortKey:S}));return}let a=t.nodes[e],c=t.planes[a.planeIndex],l=Cc(c,r),d=l>=0?a.children[0]:a.children[1],u=l>=0?a.children[1]:a.children[0];Un({x:a.mins[0],y:a.mins[1],z:a.mins[2]},{x:a.maxs[0],y:a.maxs[1],z:a.maxs[2]},n)&&(Fi(t,d,r,n,s,o,i),Fi(t,u,r,n,s,o,i))}function Rc(t,e,r){let n=Ti(t,e),s=n>=0?t.leafs[n].cluster:-1,o=[];return Fi(t,0,e,r,s,o,new Set),o}var Ci=`#version 300 es
142
142
  precision highp float;
143
143
 
144
144
  layout(location = 0) in vec3 a_position;
@@ -197,7 +197,7 @@ void main() {
197
197
  }
198
198
 
199
199
  o_color = vec4(base.rgb, base.a * u_alpha);
200
- }`,Bc=[0,255,255,255];function Bi(t=Bc,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let s=t[n]??255;if(s===255){r[n]=0;continue}let o=e[s];r[n]=o!==void 0?o:1}return r}function Mu(t){return[-(t*.25%1),0]}function ki(t=Dr,e=0){let r=(t&ga)!==0,n=(t&ha)!==0,s=(t&fa)!==0,o=(t&pa)!==0,i=(t&ya)!==0,a=o?.33:i?.66:1,c=o||i,l=!c&&!s,d=r?Mu(e):[0,0];return{alpha:a,blend:c,depthWrite:l,warp:n,flowOffset:d,sky:s}}var mo=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:Ti,fragment:Ri},{a_position:0,a_texCoord:1,a_lightmapCoord:2}),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.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformTime=this.program.getUniformLocation("u_time")}bind(e){let{modelViewProjection:r,styleIndices:n=Bc,styleValues:s=[],diffuseSampler:o=0,lightmapSampler:i,surfaceFlags:a=Dr,timeSeconds:c=0}=e,l=ki(a,c),d=Bi(n,s);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,l.flowOffset[0],l.flowOffset[1]),this.gl.uniform2f(this.uniformLmScroll,l.flowOffset[0],l.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,d),this.gl.uniform1f(this.uniformAlpha,l.alpha);let u=!l.sky&&i!==void 0;return this.gl.uniform1i(this.uniformApplyLightmap,u?1:0),this.gl.uniform1i(this.uniformWarp,l.warp?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,i??0),l}dispose(){this.program.dispose()}};function kc(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 Oc=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]),Oi=`#version 300 es
200
+ }`,Bc=[0,255,255,255];function Bi(t=Bc,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let s=t[n]??255;if(s===255){r[n]=0;continue}let o=e[s];r[n]=o!==void 0?o:1}return r}function Mu(t){return[-(t*.25%1),0]}function ki(t=Dr,e=0){let r=(t&ga)!==0,n=(t&ha)!==0,s=(t&fa)!==0,o=(t&pa)!==0,i=(t&ya)!==0,a=o?.33:i?.66:1,c=o||i,l=!c&&!s,d=r?Mu(e):[0,0];return{alpha:a,blend:c,depthWrite:l,warp:n,flowOffset:d,sky:s}}var mo=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:Ci,fragment:Ri},{a_position:0,a_texCoord:1,a_lightmapCoord:2}),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.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformTime=this.program.getUniformLocation("u_time")}bind(e){let{modelViewProjection:r,styleIndices:n=Bc,styleValues:s=[],diffuseSampler:o=0,lightmapSampler:i,surfaceFlags:a=Dr,timeSeconds:c=0}=e,l=ki(a,c),d=Bi(n,s);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,l.flowOffset[0],l.flowOffset[1]),this.gl.uniform2f(this.uniformLmScroll,l.flowOffset[0],l.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,d),this.gl.uniform1f(this.uniformAlpha,l.alpha);let u=!l.sky&&i!==void 0;return this.gl.uniform1i(this.uniformApplyLightmap,u?1:0),this.gl.uniform1i(this.uniformWarp,l.warp?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,i??0),l}dispose(){this.program.dispose()}};function kc(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 Oc=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]),Oi=`#version 300 es
201
201
  precision highp float;
202
202
 
203
203
  layout(location = 0) in vec3 a_position;
@@ -256,7 +256,7 @@ out vec4 o_color;
256
256
  void main() {
257
257
  vec4 albedo = texture(u_diffuseMap, v_texCoord) * u_tint;
258
258
  o_color = vec4(albedo.rgb * v_light, albedo.a);
259
- }`;function Au(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 Ni(t,e,r){return t+(e-t)*r}function Hc(t,e,r){return{x:Ni(t.x,e.x,r),y:Ni(t.y,e.y,r),z:Ni(t.z,e.z,r)}}function _u(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Vi(t){if(t.glCommands.length===0){let n=[],s=[];return t.triangles.forEach(o=>{let i=n.length;for(let a=0;a<3;a+=1){let c=o.vertexIndices[a],l=o.texCoordIndices[a],d=t.texCoords[l];n.push({vertexIndex:c,texCoord:_u(d.s,d.t,t.header)})}s.push(i,i+1,i+2)}),{vertices:n,indices:new Uint16Array(s)}}let e=[],r=[];for(let n of t.glCommands){let s=e.length;if(e.push(...n.vertices.map(o=>({vertexIndex:o.vertexIndex,texCoord:[o.s,1-o.t]}))),n.mode==="strip")for(let o=0;o<n.vertices.length-2;o+=1){let i=o%2===0,a=s+o+(i?0:1),c=s+o+(i?1:0),l=s+o+2;r.push(a,c,l)}else for(let o=1;o<n.vertices.length-1;o+=1)r.push(s,s+o,s+o+1)}return{vertices:e,indices:new Uint16Array(r)}}function Gi(t,e,r){let{currentFrame:n,nextFrame:s,lerp:o}=r,i=t.frames[n],a=t.frames[s];if(!i||!a)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,d)=>{let u=i.vertices[l.vertexIndex],m=a.vertices[l.vertexIndex];if(!u||!m)throw new Error("MD2 vertex index out of range for frame");let f=Hc(u.position,m.position,o),p=Au(Hc(u.normal,m.normal,o)),y=d*8;c[y]=f.x,c[y+1]=f.y,c[y+2]=f.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 ho=class{constructor(e,r,n){this.gl=e,this.geometry=Vi(r),this.vertexBuffer=new ve(e,e.STATIC_DRAW),this.indexBuffer=new Ne(e,e.STATIC_DRAW),this.vertexArray=new _e(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=Gi(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()}},po=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:Hi,fragment:Ui},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),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")}bind(e){let{modelViewProjection:r,lightDirection:n=[0,0,1],ambientLight:s=.2,tint:o=[1,1,1,1],diffuseSampler:i=0}=e,a=new Float32Array(n),c=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform3fv(this.uniformLightDir,a),this.gl.uniform1f(this.uniformAmbient,s),this.gl.uniform4fv(this.uniformTint,c),this.gl.uniform1i(this.uniformDiffuse,i)}draw(e){e.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var $=1e-6,He=typeof Float32Array<"u"?Float32Array:Array,Wi=Math.random;function yo(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var ay=Math.PI/180,cy=180/Math.PI;var ae={};Ho(ae,{add:()=>l0,adjoint:()=>Cu,clone:()=>Lu,copy:()=>Eu,create:()=>wu,decompose:()=>$u,determinant:()=>Tu,equals:()=>f0,exactEquals:()=>m0,frob:()=>c0,fromQuat:()=>Ju,fromQuat2:()=>Ku,fromRotation:()=>Vu,fromRotationTranslation:()=>Wc,fromRotationTranslationScale:()=>ju,fromRotationTranslationScaleOrigin:()=>Qu,fromScaling:()=>Uu,fromTranslation:()=>Hu,fromValues:()=>Pu,fromXRotation:()=>Gu,fromYRotation:()=>Wu,fromZRotation:()=>Xu,frustum:()=>Zu,getRotation:()=>qu,getScaling:()=>Xc,getTranslation:()=>Yu,identity:()=>Vc,invert:()=>Fu,lookAt:()=>o0,mul:()=>h0,multiply:()=>Gc,multiplyScalar:()=>d0,multiplyScalarAndAdd:()=>u0,ortho:()=>n0,orthoNO:()=>Yc,orthoZO:()=>s0,perspective:()=>e0,perspectiveFromFieldOfView:()=>r0,perspectiveNO:()=>Kc,perspectiveZO:()=>t0,rotate:()=>ku,rotateX:()=>Ou,rotateY:()=>Du,rotateZ:()=>Nu,scale:()=>Bu,set:()=>Iu,str:()=>a0,sub:()=>p0,subtract:()=>qc,targetTo:()=>i0,translate:()=>Ru,transpose:()=>zu});function wu(){var t=new He(16);return He!=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 Lu(t){var e=new He(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 Eu(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 Pu(t,e,r,n,s,o,i,a,c,l,d,u,m,f,p,y){var h=new He(16);return h[0]=t,h[1]=e,h[2]=r,h[3]=n,h[4]=s,h[5]=o,h[6]=i,h[7]=a,h[8]=c,h[9]=l,h[10]=d,h[11]=u,h[12]=m,h[13]=f,h[14]=p,h[15]=y,h}function Iu(t,e,r,n,s,o,i,a,c,l,d,u,m,f,p,y,h){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=o,t[5]=i,t[6]=a,t[7]=c,t[8]=l,t[9]=d,t[10]=u,t[11]=m,t[12]=f,t[13]=p,t[14]=y,t[15]=h,t}function Vc(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 zu(t,e){if(t===e){var r=e[1],n=e[2],s=e[3],o=e[6],i=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=o,t[11]=e[14],t[12]=s,t[13]=i,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Fu(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],m=e[10],f=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*i,b=r*c-s*i,M=r*l-o*i,v=n*c-s*a,A=n*l-o*a,_=s*l-o*c,L=d*y-u*p,C=d*h-m*p,w=d*g-f*p,H=u*h-m*y,G=u*g-f*y,V=m*g-f*h,T=S*V-b*G+M*H+v*w-A*C+_*L;return T?(T=1/T,t[0]=(a*V-c*G+l*H)*T,t[1]=(s*G-n*V-o*H)*T,t[2]=(y*_-h*A+g*v)*T,t[3]=(m*A-u*_-f*v)*T,t[4]=(c*w-i*V-l*C)*T,t[5]=(r*V-s*w+o*C)*T,t[6]=(h*M-p*_-g*b)*T,t[7]=(d*_-m*M+f*b)*T,t[8]=(i*G-a*w+l*L)*T,t[9]=(n*w-r*G-o*L)*T,t[10]=(p*A-y*M+g*S)*T,t[11]=(u*M-d*A-f*S)*T,t[12]=(a*C-i*H-c*L)*T,t[13]=(r*H-n*C+s*L)*T,t[14]=(y*b-p*v-h*S)*T,t[15]=(d*v-u*b+m*S)*T,t):null}function Cu(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],m=e[10],f=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*i,b=r*c-s*i,M=r*l-o*i,v=n*c-s*a,A=n*l-o*a,_=s*l-o*c,L=d*y-u*p,C=d*h-m*p,w=d*g-f*p,H=u*h-m*y,G=u*g-f*y,V=m*g-f*h;return t[0]=a*V-c*G+l*H,t[1]=s*G-n*V-o*H,t[2]=y*_-h*A+g*v,t[3]=m*A-u*_-f*v,t[4]=c*w-i*V-l*C,t[5]=r*V-s*w+o*C,t[6]=h*M-p*_-g*b,t[7]=d*_-m*M+f*b,t[8]=i*G-a*w+l*L,t[9]=n*w-r*G-o*L,t[10]=p*A-y*M+g*S,t[11]=u*M-d*A-f*S,t[12]=a*C-i*H-c*L,t[13]=r*H-n*C+s*L,t[14]=y*b-p*v-h*S,t[15]=d*v-u*b+m*S,t}function Tu(t){var e=t[0],r=t[1],n=t[2],s=t[3],o=t[4],i=t[5],a=t[6],c=t[7],l=t[8],d=t[9],u=t[10],m=t[11],f=t[12],p=t[13],y=t[14],h=t[15],g=e*i-r*o,S=e*a-n*o,b=r*a-n*i,M=l*p-d*f,v=l*y-u*f,A=d*y-u*p,_=e*A-r*v+n*M,L=o*A-i*v+a*M,C=l*b-d*S+u*g,w=f*b-p*S+y*g;return c*_-s*L+h*C-m*w}function Gc(t,e,r){var n=e[0],s=e[1],o=e[2],i=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=e[8],m=e[9],f=e[10],p=e[11],y=e[12],h=e[13],g=e[14],S=e[15],b=r[0],M=r[1],v=r[2],A=r[3];return t[0]=b*n+M*a+v*u+A*y,t[1]=b*s+M*c+v*m+A*h,t[2]=b*o+M*l+v*f+A*g,t[3]=b*i+M*d+v*p+A*S,b=r[4],M=r[5],v=r[6],A=r[7],t[4]=b*n+M*a+v*u+A*y,t[5]=b*s+M*c+v*m+A*h,t[6]=b*o+M*l+v*f+A*g,t[7]=b*i+M*d+v*p+A*S,b=r[8],M=r[9],v=r[10],A=r[11],t[8]=b*n+M*a+v*u+A*y,t[9]=b*s+M*c+v*m+A*h,t[10]=b*o+M*l+v*f+A*g,t[11]=b*i+M*d+v*p+A*S,b=r[12],M=r[13],v=r[14],A=r[15],t[12]=b*n+M*a+v*u+A*y,t[13]=b*s+M*c+v*m+A*h,t[14]=b*o+M*l+v*f+A*g,t[15]=b*i+M*d+v*p+A*S,t}function Ru(t,e,r){var n=r[0],s=r[1],o=r[2],i,a,c,l,d,u,m,f,p,y,h,g;return e===t?(t[12]=e[0]*n+e[4]*s+e[8]*o+e[12],t[13]=e[1]*n+e[5]*s+e[9]*o+e[13],t[14]=e[2]*n+e[6]*s+e[10]*o+e[14],t[15]=e[3]*n+e[7]*s+e[11]*o+e[15]):(i=e[0],a=e[1],c=e[2],l=e[3],d=e[4],u=e[5],m=e[6],f=e[7],p=e[8],y=e[9],h=e[10],g=e[11],t[0]=i,t[1]=a,t[2]=c,t[3]=l,t[4]=d,t[5]=u,t[6]=m,t[7]=f,t[8]=p,t[9]=y,t[10]=h,t[11]=g,t[12]=i*n+d*s+p*o+e[12],t[13]=a*n+u*s+y*o+e[13],t[14]=c*n+m*s+h*o+e[14],t[15]=l*n+f*s+g*o+e[15]),t}function Bu(t,e,r){var n=r[0],s=r[1],o=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ku(t,e,r,n){var s=n[0],o=n[1],i=n[2],a=Math.sqrt(s*s+o*o+i*i),c,l,d,u,m,f,p,y,h,g,S,b,M,v,A,_,L,C,w,H,G,V,T,J;return a<$?null:(a=1/a,s*=a,o*=a,i*=a,c=Math.sin(r),l=Math.cos(r),d=1-l,u=e[0],m=e[1],f=e[2],p=e[3],y=e[4],h=e[5],g=e[6],S=e[7],b=e[8],M=e[9],v=e[10],A=e[11],_=s*s*d+l,L=o*s*d+i*c,C=i*s*d-o*c,w=s*o*d-i*c,H=o*o*d+l,G=i*o*d+s*c,V=s*i*d+o*c,T=o*i*d-s*c,J=i*i*d+l,t[0]=u*_+y*L+b*C,t[1]=m*_+h*L+M*C,t[2]=f*_+g*L+v*C,t[3]=p*_+S*L+A*C,t[4]=u*w+y*H+b*G,t[5]=m*w+h*H+M*G,t[6]=f*w+g*H+v*G,t[7]=p*w+S*H+A*G,t[8]=u*V+y*T+b*J,t[9]=m*V+h*T+M*J,t[10]=f*V+g*T+v*J,t[11]=p*V+S*T+A*J,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Ou(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[4],i=e[5],a=e[6],c=e[7],l=e[8],d=e[9],u=e[10],m=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*s+l*n,t[5]=i*s+d*n,t[6]=a*s+u*n,t[7]=c*s+m*n,t[8]=l*s-o*n,t[9]=d*s-i*n,t[10]=u*s-a*n,t[11]=m*s-c*n,t}function Du(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[0],i=e[1],a=e[2],c=e[3],l=e[8],d=e[9],u=e[10],m=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*s-l*n,t[1]=i*s-d*n,t[2]=a*s-u*n,t[3]=c*s-m*n,t[8]=o*n+l*s,t[9]=i*n+d*s,t[10]=a*n+u*s,t[11]=c*n+m*s,t}function Nu(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[0],i=e[1],a=e[2],c=e[3],l=e[4],d=e[5],u=e[6],m=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*s+l*n,t[1]=i*s+d*n,t[2]=a*s+u*n,t[3]=c*s+m*n,t[4]=l*s-o*n,t[5]=d*s-i*n,t[6]=u*s-a*n,t[7]=m*s-c*n,t}function Hu(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 Uu(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 Vu(t,e,r){var n=r[0],s=r[1],o=r[2],i=Math.sqrt(n*n+s*s+o*o),a,c,l;return i<$?null:(i=1/i,n*=i,s*=i,o*=i,a=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=s*n*l+o*a,t[2]=o*n*l-s*a,t[3]=0,t[4]=n*s*l-o*a,t[5]=s*s*l+c,t[6]=o*s*l+n*a,t[7]=0,t[8]=n*o*l+s*a,t[9]=s*o*l-n*a,t[10]=o*o*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Gu(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 Wu(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 Xu(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 Wc(t,e,r){var n=e[0],s=e[1],o=e[2],i=e[3],a=n+n,c=s+s,l=o+o,d=n*a,u=n*c,m=n*l,f=s*c,p=s*l,y=o*l,h=i*a,g=i*c,S=i*l;return t[0]=1-(f+y),t[1]=u+S,t[2]=m-g,t[3]=0,t[4]=u-S,t[5]=1-(d+y),t[6]=p+h,t[7]=0,t[8]=m+g,t[9]=p-h,t[10]=1-(d+f),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Ku(t,e){var r=new He(3),n=-e[0],s=-e[1],o=-e[2],i=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=n*n+s*s+o*o+i*i;return u>0?(r[0]=(a*i+d*n+c*o-l*s)*2/u,r[1]=(c*i+d*s+l*n-a*o)*2/u,r[2]=(l*i+d*o+a*s-c*n)*2/u):(r[0]=(a*i+d*n+c*o-l*s)*2,r[1]=(c*i+d*s+l*n-a*o)*2,r[2]=(l*i+d*o+a*s-c*n)*2),Wc(t,e,r),t}function Yu(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Xc(t,e){var r=e[0],n=e[1],s=e[2],o=e[4],i=e[5],a=e[6],c=e[8],l=e[9],d=e[10];return t[0]=Math.sqrt(r*r+n*n+s*s),t[1]=Math.sqrt(o*o+i*i+a*a),t[2]=Math.sqrt(c*c+l*l+d*d),t}function qu(t,e){var r=new He(3);Xc(r,e);var n=1/r[0],s=1/r[1],o=1/r[2],i=e[0]*n,a=e[1]*s,c=e[2]*o,l=e[4]*n,d=e[5]*s,u=e[6]*o,m=e[8]*n,f=e[9]*s,p=e[10]*o,y=i+d+p,h=0;return y>0?(h=Math.sqrt(y+1)*2,t[3]=.25*h,t[0]=(u-f)/h,t[1]=(m-c)/h,t[2]=(a-l)/h):i>d&&i>p?(h=Math.sqrt(1+i-d-p)*2,t[3]=(u-f)/h,t[0]=.25*h,t[1]=(a+l)/h,t[2]=(m+c)/h):d>p?(h=Math.sqrt(1+d-i-p)*2,t[3]=(m-c)/h,t[0]=(a+l)/h,t[1]=.25*h,t[2]=(u+f)/h):(h=Math.sqrt(1+p-i-d)*2,t[3]=(a-l)/h,t[0]=(m+c)/h,t[1]=(u+f)/h,t[2]=.25*h),t}function $u(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var s=n[0],o=n[1],i=n[2],a=n[4],c=n[5],l=n[6],d=n[8],u=n[9],m=n[10];r[0]=Math.sqrt(s*s+o*o+i*i),r[1]=Math.sqrt(a*a+c*c+l*l),r[2]=Math.sqrt(d*d+u*u+m*m);var f=1/r[0],p=1/r[1],y=1/r[2],h=s*f,g=o*p,S=i*y,b=a*f,M=c*p,v=l*y,A=d*f,_=u*p,L=m*y,C=h+M+L,w=0;return C>0?(w=Math.sqrt(C+1)*2,t[3]=.25*w,t[0]=(v-_)/w,t[1]=(A-S)/w,t[2]=(g-b)/w):h>M&&h>L?(w=Math.sqrt(1+h-M-L)*2,t[3]=(v-_)/w,t[0]=.25*w,t[1]=(g+b)/w,t[2]=(A+S)/w):M>L?(w=Math.sqrt(1+M-h-L)*2,t[3]=(A-S)/w,t[0]=(g+b)/w,t[1]=.25*w,t[2]=(v+_)/w):(w=Math.sqrt(1+L-h-M)*2,t[3]=(g-b)/w,t[0]=(A+S)/w,t[1]=(v+_)/w,t[2]=.25*w),t}function ju(t,e,r,n){var s=e[0],o=e[1],i=e[2],a=e[3],c=s+s,l=o+o,d=i+i,u=s*c,m=s*l,f=s*d,p=o*l,y=o*d,h=i*d,g=a*c,S=a*l,b=a*d,M=n[0],v=n[1],A=n[2];return t[0]=(1-(p+h))*M,t[1]=(m+b)*M,t[2]=(f-S)*M,t[3]=0,t[4]=(m-b)*v,t[5]=(1-(u+h))*v,t[6]=(y+g)*v,t[7]=0,t[8]=(f+S)*A,t[9]=(y-g)*A,t[10]=(1-(u+p))*A,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Qu(t,e,r,n,s){var o=e[0],i=e[1],a=e[2],c=e[3],l=o+o,d=i+i,u=a+a,m=o*l,f=o*d,p=o*u,y=i*d,h=i*u,g=a*u,S=c*l,b=c*d,M=c*u,v=n[0],A=n[1],_=n[2],L=s[0],C=s[1],w=s[2],H=(1-(y+g))*v,G=(f+M)*v,V=(p-b)*v,T=(f-M)*A,J=(1-(m+g))*A,Se=(h+S)*A,Tt=(p+b)*_,jn=(h-S)*_,Br=(1-(m+y))*_;return t[0]=H,t[1]=G,t[2]=V,t[3]=0,t[4]=T,t[5]=J,t[6]=Se,t[7]=0,t[8]=Tt,t[9]=jn,t[10]=Br,t[11]=0,t[12]=r[0]+L-(H*L+T*C+Tt*w),t[13]=r[1]+C-(G*L+J*C+jn*w),t[14]=r[2]+w-(V*L+Se*C+Br*w),t[15]=1,t}function Ju(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=r+r,a=n+n,c=s+s,l=r*i,d=n*i,u=n*a,m=s*i,f=s*a,p=s*c,y=o*i,h=o*a,g=o*c;return t[0]=1-u-p,t[1]=d+g,t[2]=m-h,t[3]=0,t[4]=d-g,t[5]=1-l-p,t[6]=f+y,t[7]=0,t[8]=m+h,t[9]=f-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Zu(t,e,r,n,s,o,i){var a=1/(r-e),c=1/(s-n),l=1/(o-i);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(s+n)*c,t[10]=(i+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=i*o*2*l,t[15]=0,t}function Kc(t,e,r,n,s){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,s!=null&&s!==1/0){var i=1/(n-s);t[10]=(s+n)*i,t[14]=2*s*n*i}else t[10]=-1,t[14]=-2*n;return t}var e0=Kc;function t0(t,e,r,n,s){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,s!=null&&s!==1/0){var i=1/(n-s);t[10]=s*i,t[14]=s*n*i}else t[10]=-1,t[14]=-n;return t}function r0(t,e,r,n){var s=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),i=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(i+a),l=2/(s+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((i-a)*c*.5),t[9]=(s-o)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Yc(t,e,r,n,s,o,i){var a=1/(e-r),c=1/(n-s),l=1/(o-i);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(s+n)*c,t[14]=(i+o)*l,t[15]=1,t}var n0=Yc;function s0(t,e,r,n,s,o,i){var a=1/(e-r),c=1/(n-s),l=1/(o-i);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(s+n)*c,t[14]=o*l,t[15]=1,t}function o0(t,e,r,n){var s,o,i,a,c,l,d,u,m,f,p=e[0],y=e[1],h=e[2],g=n[0],S=n[1],b=n[2],M=r[0],v=r[1],A=r[2];return Math.abs(p-M)<$&&Math.abs(y-v)<$&&Math.abs(h-A)<$?Vc(t):(d=p-M,u=y-v,m=h-A,f=1/Math.sqrt(d*d+u*u+m*m),d*=f,u*=f,m*=f,s=S*m-b*u,o=b*d-g*m,i=g*u-S*d,f=Math.sqrt(s*s+o*o+i*i),f?(f=1/f,s*=f,o*=f,i*=f):(s=0,o=0,i=0),a=u*i-m*o,c=m*s-d*i,l=d*o-u*s,f=Math.sqrt(a*a+c*c+l*l),f?(f=1/f,a*=f,c*=f,l*=f):(a=0,c=0,l=0),t[0]=s,t[1]=a,t[2]=d,t[3]=0,t[4]=o,t[5]=c,t[6]=u,t[7]=0,t[8]=i,t[9]=l,t[10]=m,t[11]=0,t[12]=-(s*p+o*y+i*h),t[13]=-(a*p+c*y+l*h),t[14]=-(d*p+u*y+m*h),t[15]=1,t)}function i0(t,e,r,n){var s=e[0],o=e[1],i=e[2],a=n[0],c=n[1],l=n[2],d=s-r[0],u=o-r[1],m=i-r[2],f=d*d+u*u+m*m;f>0&&(f=1/Math.sqrt(f),d*=f,u*=f,m*=f);var p=c*m-l*u,y=l*d-a*m,h=a*u-c*d;return f=p*p+y*y+h*h,f>0&&(f=1/Math.sqrt(f),p*=f,y*=f,h*=f),t[0]=p,t[1]=y,t[2]=h,t[3]=0,t[4]=u*h-m*y,t[5]=m*p-d*h,t[6]=d*y-u*p,t[7]=0,t[8]=d,t[9]=u,t[10]=m,t[11]=0,t[12]=s,t[13]=o,t[14]=i,t[15]=1,t}function a0(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 c0(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 l0(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 qc(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 d0(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 u0(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 m0(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 f0(t,e){var r=t[0],n=t[1],s=t[2],o=t[3],i=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],m=t[10],f=t[11],p=t[12],y=t[13],h=t[14],g=t[15],S=e[0],b=e[1],M=e[2],v=e[3],A=e[4],_=e[5],L=e[6],C=e[7],w=e[8],H=e[9],G=e[10],V=e[11],T=e[12],J=e[13],Se=e[14],Tt=e[15];return Math.abs(r-S)<=$*Math.max(1,Math.abs(r),Math.abs(S))&&Math.abs(n-b)<=$*Math.max(1,Math.abs(n),Math.abs(b))&&Math.abs(s-M)<=$*Math.max(1,Math.abs(s),Math.abs(M))&&Math.abs(o-v)<=$*Math.max(1,Math.abs(o),Math.abs(v))&&Math.abs(i-A)<=$*Math.max(1,Math.abs(i),Math.abs(A))&&Math.abs(a-_)<=$*Math.max(1,Math.abs(a),Math.abs(_))&&Math.abs(c-L)<=$*Math.max(1,Math.abs(c),Math.abs(L))&&Math.abs(l-C)<=$*Math.max(1,Math.abs(l),Math.abs(C))&&Math.abs(d-w)<=$*Math.max(1,Math.abs(d),Math.abs(w))&&Math.abs(u-H)<=$*Math.max(1,Math.abs(u),Math.abs(H))&&Math.abs(m-G)<=$*Math.max(1,Math.abs(m),Math.abs(G))&&Math.abs(f-V)<=$*Math.max(1,Math.abs(f),Math.abs(V))&&Math.abs(p-T)<=$*Math.max(1,Math.abs(p),Math.abs(T))&&Math.abs(y-J)<=$*Math.max(1,Math.abs(y),Math.abs(J))&&Math.abs(h-Se)<=$*Math.max(1,Math.abs(h),Math.abs(Se))&&Math.abs(g-Tt)<=$*Math.max(1,Math.abs(g),Math.abs(Tt))}var h0=Gc,p0=qc;var ie={};Ho(ie,{add:()=>v0,angle:()=>G0,bezier:()=>B0,ceil:()=>S0,clone:()=>y0,copy:()=>x0,create:()=>$c,cross:()=>F0,dist:()=>Q0,distance:()=>el,div:()=>j0,divide:()=>Zc,dot:()=>Xi,equals:()=>Y0,exactEquals:()=>K0,floor:()=>M0,forEach:()=>tm,fromValues:()=>g0,hermite:()=>R0,inverse:()=>I0,len:()=>Z0,length:()=>jc,lerp:()=>C0,max:()=>_0,min:()=>A0,mul:()=>$0,multiply:()=>Jc,negate:()=>P0,normalize:()=>z0,random:()=>k0,rotateX:()=>H0,rotateY:()=>U0,rotateZ:()=>V0,round:()=>w0,scale:()=>L0,scaleAndAdd:()=>E0,set:()=>b0,slerp:()=>T0,sqrDist:()=>J0,sqrLen:()=>em,squaredDistance:()=>tl,squaredLength:()=>rl,str:()=>X0,sub:()=>q0,subtract:()=>Qc,transformMat3:()=>D0,transformMat4:()=>O0,transformQuat:()=>N0,zero:()=>W0});function $c(){var t=new He(3);return He!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function y0(t){var e=new He(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function jc(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function g0(t,e,r){var n=new He(3);return n[0]=t,n[1]=e,n[2]=r,n}function x0(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function b0(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function v0(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Qc(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Jc(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Zc(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function S0(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function M0(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function A0(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 _0(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 w0(t,e){return t[0]=yo(e[0]),t[1]=yo(e[1]),t[2]=yo(e[2]),t}function L0(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function E0(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 el(t,e){var r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return Math.sqrt(r*r+n*n+s*s)}function tl(t,e){var r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return r*r+n*n+s*s}function rl(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function P0(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function I0(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function z0(t,e){var r=e[0],n=e[1],s=e[2],o=r*r+n*n+s*s;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function Xi(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function F0(t,e,r){var n=e[0],s=e[1],o=e[2],i=r[0],a=r[1],c=r[2];return t[0]=s*c-o*a,t[1]=o*i-n*c,t[2]=n*a-s*i,t}function C0(t,e,r,n){var s=e[0],o=e[1],i=e[2];return t[0]=s+n*(r[0]-s),t[1]=o+n*(r[1]-o),t[2]=i+n*(r[2]-i),t}function T0(t,e,r,n){var s=Math.acos(Math.min(Math.max(Xi(e,r),-1),1)),o=Math.sin(s),i=Math.sin((1-n)*s)/o,a=Math.sin(n*s)/o;return t[0]=i*e[0]+a*r[0],t[1]=i*e[1]+a*r[1],t[2]=i*e[2]+a*r[2],t}function R0(t,e,r,n,s,o){var i=o*o,a=i*(2*o-3)+1,c=i*(o-2)+o,l=i*(o-1),d=i*(3-2*o);return t[0]=e[0]*a+r[0]*c+n[0]*l+s[0]*d,t[1]=e[1]*a+r[1]*c+n[1]*l+s[1]*d,t[2]=e[2]*a+r[2]*c+n[2]*l+s[2]*d,t}function B0(t,e,r,n,s,o){var i=1-o,a=i*i,c=o*o,l=a*i,d=3*o*a,u=3*c*i,m=c*o;return t[0]=e[0]*l+r[0]*d+n[0]*u+s[0]*m,t[1]=e[1]*l+r[1]*d+n[1]*u+s[1]*m,t[2]=e[2]*l+r[2]*d+n[2]*u+s[2]*m,t}function k0(t,e){e=e===void 0?1:e;var r=Wi()*2*Math.PI,n=Wi()*2-1,s=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*s,t[1]=Math.sin(r)*s,t[2]=n*e,t}function O0(t,e,r){var n=e[0],s=e[1],o=e[2],i=r[3]*n+r[7]*s+r[11]*o+r[15];return i=i||1,t[0]=(r[0]*n+r[4]*s+r[8]*o+r[12])/i,t[1]=(r[1]*n+r[5]*s+r[9]*o+r[13])/i,t[2]=(r[2]*n+r[6]*s+r[10]*o+r[14])/i,t}function D0(t,e,r){var n=e[0],s=e[1],o=e[2];return t[0]=n*r[0]+s*r[3]+o*r[6],t[1]=n*r[1]+s*r[4]+o*r[7],t[2]=n*r[2]+s*r[5]+o*r[8],t}function N0(t,e,r){var n=r[0],s=r[1],o=r[2],i=r[3],a=e[0],c=e[1],l=e[2],d=s*l-o*c,u=o*a-n*l,m=n*c-s*a;return d=d+d,u=u+u,m=m+m,t[0]=a+i*d+s*m-o*u,t[1]=c+i*u+o*d-n*m,t[2]=l+i*m+n*u-s*d,t}function H0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[0],o[1]=s[1]*Math.cos(n)-s[2]*Math.sin(n),o[2]=s[1]*Math.sin(n)+s[2]*Math.cos(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function U0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[2]*Math.sin(n)+s[0]*Math.cos(n),o[1]=s[1],o[2]=s[2]*Math.cos(n)-s[0]*Math.sin(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function V0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[0]*Math.cos(n)-s[1]*Math.sin(n),o[1]=s[0]*Math.sin(n)+s[1]*Math.cos(n),o[2]=s[2],t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function G0(t,e){var r=t[0],n=t[1],s=t[2],o=e[0],i=e[1],a=e[2],c=Math.sqrt((r*r+n*n+s*s)*(o*o+i*i+a*a)),l=c&&Xi(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function W0(t){return t[0]=0,t[1]=0,t[2]=0,t}function X0(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function K0(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Y0(t,e){var r=t[0],n=t[1],s=t[2],o=e[0],i=e[1],a=e[2];return Math.abs(r-o)<=$*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-i)<=$*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(s-a)<=$*Math.max(1,Math.abs(s),Math.abs(a))}var q0=Qc,$0=Jc,j0=Zc,Q0=el,J0=tl,Z0=jc,em=rl,tm=(function(){var t=$c();return function(e,r,n,s,o,i){var a,c;for(r||(r=3),n||(n=0),s?c=Math.min(s*r+n,e.length):c=e.length,a=n;a<c;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,i),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var go=class{constructor(){this._position=ie.create();this._angles=ie.create();this._bobAngles=ie.create();this._bobOffset=ie.create();this._kickAngles=ie.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ae.create();this._projectionMatrix=ae.create();this._viewProjectionMatrix=ae.create();this._dirty=!0}get position(){return this._position}set position(e){ie.copy(this._position,e),this._dirty=!0}get angles(){return this._angles}set angles(e){ie.copy(this._angles,e),this._dirty=!0}get bobAngles(){return this._bobAngles}set bobAngles(e){ie.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){ie.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){ie.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ae.create();return ae.perspective(r,e*sr,this._aspect,this._near,this._far),r}updateMatrices(){if(!this._dirty)return;ae.perspective(this._projectionMatrix,this._fov*sr,this._aspect,this._near,this._far);let e=ae.fromValues(0,-1,0,0,0,0,1,0,-1,0,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],s=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,o=r*sr,i=n*sr,a=s*sr,c=ae.create();ae.identity(c),ae.rotateZ(c,c,-i),ae.rotateY(c,c,-o),ae.rotateX(c,c,-a);let l=ae.create();ae.multiply(l,e,c);let d=ie.add(ie.create(),this._position,this._bobOffset),u=ie.negate(ie.create(),d),m=ie.create();ie.transformMat4(m,u,c);let f=ie.fromValues(m[1]||0,m[2]||0,m[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=f[0],this._viewMatrix[13]=f[1],this._viewMatrix[14]=f[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var rm=[.2,.2,.2],nm={x:0,y:0,z:1},sm=[.8,.8,.8];function Ki(t,e,r){return t+(e-t)*r}function Rr(t,e,r){return{x:Ki(t.x,e.x,r),y:Ki(t.y,e.y,r),z:Ki(t.z,e.z,r)}}function Tr(t){return t<0?0:t>1?1:t}function Yi(t){let e=[],r=[];for(let n of t.triangles){let s=e.length,[o,i,a]=n.indices,c=t.texCoords[o],l=t.texCoords[i],d=t.texCoords[a];if(!c||!l||!d)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:o,texCoord:[c.s,1-c.t]},{vertexIndex:i,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[d.s,1-d.t]}),r.push(s,s+1,s+2)}return{vertices:e,indices:new Uint16Array(r)}}function om(t,e,r){let n=r?.ambient??rm,s=r?.directional??{direction:nm,color:sm},o=Ue(t),i=Ue(s.direction),a=Tr(o.x*i.x+o.y*i.y+o.z*i.z),c=n[0]+s.color[0]*a,l=n[1]+s.color[1]*a,d=n[2]+s.color[2]*a;if(r?.dynamicLights){let u=r.modelMatrix?da(r.modelMatrix,e):e;for(let m of r.dynamicLights){let f=u.x-m.origin.x,p=u.y-m.origin.y,y=u.z-m.origin.z,h=f*f+p*p+y*y,g=m.radius*m.radius;if(h<g&&g>0){let S=1-Math.sqrt(h)/m.radius,b=Math.sqrt(h),M=b>0?Tr(-(f*o.x+p*o.y+y*o.z)/b):0,v=Tr(S*M);c+=m.color[0]*v,l+=m.color[1]*v,d+=m.color[2]*v}}}return[Tr(c),Tr(l),Tr(d)]}function qi(t,e,r,n){let s=t.vertices[r.currentFrame],o=t.vertices[r.nextFrame];if(!s||!o)throw new Error("Requested MD3 frames are out of range");let i=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,c)=>{let l=s[a.vertexIndex],d=o[a.vertexIndex];if(!l||!d)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let u=Rr(l.position,d.position,r.lerp),m=Ue(Rr(l.normal,d.normal,r.lerp)),f=om(m,u,n),p=c*12;i[p]=u.x,i[p+1]=u.y,i[p+2]=u.z,i[p+3]=m.x,i[p+4]=m.y,i[p+5]=m.z,i[p+6]=a.texCoord[0],i[p+7]=a.texCoord[1],i[p+8]=f[0],i[p+9]=f[1],i[p+10]=f[2],i[p+11]=1}),i}function nl(t,e,r){let n=t.tags[0];if(!n)return null;let s=n.findIndex(y=>y.name===r);if(s===-1)return null;let o=t.tags[e.currentFrame]?.[s],i=t.tags[e.nextFrame]?.[s];if(!o||!i)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=Rr(o.origin,i.origin,e.lerp),c=Ue(Rr(o.axis[0],i.axis[0],e.lerp)),l=Ue(Rr(o.axis[1],i.axis[1],e.lerp)),d=Ue(Rr(o.axis[2],i.axis[2],e.lerp)),u=c,m=Ue({x:l.x-u.x*(u.x*l.x+u.y*l.y+u.z*l.z),y:l.y-u.y*(u.x*l.x+u.y*l.y+u.z*l.z),z:l.z-u.z*(u.x*l.x+u.y*l.y+u.z*l.z)}),f=Ue({x:u.y*m.z-u.z*m.y,y:u.z*m.x-u.x*m.z,z:u.x*m.y-u.y*m.x}),p=[u,m,f];return{origin:a,axis:p,matrix:ua(a,p)}}var $i=`#version 300 es
259
+ }`;function Au(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 Ni(t,e,r){return t+(e-t)*r}function Hc(t,e,r){return{x:Ni(t.x,e.x,r),y:Ni(t.y,e.y,r),z:Ni(t.z,e.z,r)}}function _u(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function Vi(t){if(t.glCommands.length===0){let n=[],s=[];return t.triangles.forEach(o=>{let i=n.length;for(let a=0;a<3;a+=1){let c=o.vertexIndices[a],l=o.texCoordIndices[a],d=t.texCoords[l];n.push({vertexIndex:c,texCoord:_u(d.s,d.t,t.header)})}s.push(i,i+1,i+2)}),{vertices:n,indices:new Uint16Array(s)}}let e=[],r=[];for(let n of t.glCommands){let s=e.length;if(e.push(...n.vertices.map(o=>({vertexIndex:o.vertexIndex,texCoord:[o.s,1-o.t]}))),n.mode==="strip")for(let o=0;o<n.vertices.length-2;o+=1){let i=o%2===0,a=s+o+(i?0:1),c=s+o+(i?1:0),l=s+o+2;r.push(a,c,l)}else for(let o=1;o<n.vertices.length-1;o+=1)r.push(s,s+o,s+o+1)}return{vertices:e,indices:new Uint16Array(r)}}function Gi(t,e,r){let{currentFrame:n,nextFrame:s,lerp:o}=r,i=t.frames[n],a=t.frames[s];if(!i||!a)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,d)=>{let u=i.vertices[l.vertexIndex],m=a.vertices[l.vertexIndex];if(!u||!m)throw new Error("MD2 vertex index out of range for frame");let f=Hc(u.position,m.position,o),p=Au(Hc(u.normal,m.normal,o)),y=d*8;c[y]=f.x,c[y+1]=f.y,c[y+2]=f.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 ho=class{constructor(e,r,n){this.gl=e,this.geometry=Vi(r),this.vertexBuffer=new ve(e,e.STATIC_DRAW),this.indexBuffer=new Ne(e,e.STATIC_DRAW),this.vertexArray=new _e(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=Gi(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()}},po=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:Hi,fragment:Ui},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),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")}bind(e){let{modelViewProjection:r,lightDirection:n=[0,0,1],ambientLight:s=.2,tint:o=[1,1,1,1],diffuseSampler:i=0}=e,a=new Float32Array(n),c=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform3fv(this.uniformLightDir,a),this.gl.uniform1f(this.uniformAmbient,s),this.gl.uniform4fv(this.uniformTint,c),this.gl.uniform1i(this.uniformDiffuse,i)}draw(e){e.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var $=1e-6,He=typeof Float32Array<"u"?Float32Array:Array,Wi=Math.random;function yo(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var ay=Math.PI/180,cy=180/Math.PI;var ae={};Ho(ae,{add:()=>l0,adjoint:()=>Tu,clone:()=>Lu,copy:()=>Eu,create:()=>wu,decompose:()=>$u,determinant:()=>Cu,equals:()=>f0,exactEquals:()=>m0,frob:()=>c0,fromQuat:()=>Ju,fromQuat2:()=>Ku,fromRotation:()=>Vu,fromRotationTranslation:()=>Wc,fromRotationTranslationScale:()=>ju,fromRotationTranslationScaleOrigin:()=>Qu,fromScaling:()=>Uu,fromTranslation:()=>Hu,fromValues:()=>Pu,fromXRotation:()=>Gu,fromYRotation:()=>Wu,fromZRotation:()=>Xu,frustum:()=>Zu,getRotation:()=>qu,getScaling:()=>Xc,getTranslation:()=>Yu,identity:()=>Vc,invert:()=>Fu,lookAt:()=>o0,mul:()=>h0,multiply:()=>Gc,multiplyScalar:()=>d0,multiplyScalarAndAdd:()=>u0,ortho:()=>n0,orthoNO:()=>Yc,orthoZO:()=>s0,perspective:()=>e0,perspectiveFromFieldOfView:()=>r0,perspectiveNO:()=>Kc,perspectiveZO:()=>t0,rotate:()=>ku,rotateX:()=>Ou,rotateY:()=>Du,rotateZ:()=>Nu,scale:()=>Bu,set:()=>Iu,str:()=>a0,sub:()=>p0,subtract:()=>qc,targetTo:()=>i0,translate:()=>Ru,transpose:()=>zu});function wu(){var t=new He(16);return He!=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 Lu(t){var e=new He(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 Eu(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 Pu(t,e,r,n,s,o,i,a,c,l,d,u,m,f,p,y){var h=new He(16);return h[0]=t,h[1]=e,h[2]=r,h[3]=n,h[4]=s,h[5]=o,h[6]=i,h[7]=a,h[8]=c,h[9]=l,h[10]=d,h[11]=u,h[12]=m,h[13]=f,h[14]=p,h[15]=y,h}function Iu(t,e,r,n,s,o,i,a,c,l,d,u,m,f,p,y,h){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=o,t[5]=i,t[6]=a,t[7]=c,t[8]=l,t[9]=d,t[10]=u,t[11]=m,t[12]=f,t[13]=p,t[14]=y,t[15]=h,t}function Vc(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 zu(t,e){if(t===e){var r=e[1],n=e[2],s=e[3],o=e[6],i=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=o,t[11]=e[14],t[12]=s,t[13]=i,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Fu(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],m=e[10],f=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*i,b=r*c-s*i,M=r*l-o*i,v=n*c-s*a,A=n*l-o*a,_=s*l-o*c,L=d*y-u*p,T=d*h-m*p,w=d*g-f*p,H=u*h-m*y,G=u*g-f*y,V=m*g-f*h,C=S*V-b*G+M*H+v*w-A*T+_*L;return C?(C=1/C,t[0]=(a*V-c*G+l*H)*C,t[1]=(s*G-n*V-o*H)*C,t[2]=(y*_-h*A+g*v)*C,t[3]=(m*A-u*_-f*v)*C,t[4]=(c*w-i*V-l*T)*C,t[5]=(r*V-s*w+o*T)*C,t[6]=(h*M-p*_-g*b)*C,t[7]=(d*_-m*M+f*b)*C,t[8]=(i*G-a*w+l*L)*C,t[9]=(n*w-r*G-o*L)*C,t[10]=(p*A-y*M+g*S)*C,t[11]=(u*M-d*A-f*S)*C,t[12]=(a*T-i*H-c*L)*C,t[13]=(r*H-n*T+s*L)*C,t[14]=(y*b-p*v-h*S)*C,t[15]=(d*v-u*b+m*S)*C,t):null}function Tu(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],l=e[7],d=e[8],u=e[9],m=e[10],f=e[11],p=e[12],y=e[13],h=e[14],g=e[15],S=r*a-n*i,b=r*c-s*i,M=r*l-o*i,v=n*c-s*a,A=n*l-o*a,_=s*l-o*c,L=d*y-u*p,T=d*h-m*p,w=d*g-f*p,H=u*h-m*y,G=u*g-f*y,V=m*g-f*h;return t[0]=a*V-c*G+l*H,t[1]=s*G-n*V-o*H,t[2]=y*_-h*A+g*v,t[3]=m*A-u*_-f*v,t[4]=c*w-i*V-l*T,t[5]=r*V-s*w+o*T,t[6]=h*M-p*_-g*b,t[7]=d*_-m*M+f*b,t[8]=i*G-a*w+l*L,t[9]=n*w-r*G-o*L,t[10]=p*A-y*M+g*S,t[11]=u*M-d*A-f*S,t[12]=a*T-i*H-c*L,t[13]=r*H-n*T+s*L,t[14]=y*b-p*v-h*S,t[15]=d*v-u*b+m*S,t}function Cu(t){var e=t[0],r=t[1],n=t[2],s=t[3],o=t[4],i=t[5],a=t[6],c=t[7],l=t[8],d=t[9],u=t[10],m=t[11],f=t[12],p=t[13],y=t[14],h=t[15],g=e*i-r*o,S=e*a-n*o,b=r*a-n*i,M=l*p-d*f,v=l*y-u*f,A=d*y-u*p,_=e*A-r*v+n*M,L=o*A-i*v+a*M,T=l*b-d*S+u*g,w=f*b-p*S+y*g;return c*_-s*L+h*T-m*w}function Gc(t,e,r){var n=e[0],s=e[1],o=e[2],i=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=e[8],m=e[9],f=e[10],p=e[11],y=e[12],h=e[13],g=e[14],S=e[15],b=r[0],M=r[1],v=r[2],A=r[3];return t[0]=b*n+M*a+v*u+A*y,t[1]=b*s+M*c+v*m+A*h,t[2]=b*o+M*l+v*f+A*g,t[3]=b*i+M*d+v*p+A*S,b=r[4],M=r[5],v=r[6],A=r[7],t[4]=b*n+M*a+v*u+A*y,t[5]=b*s+M*c+v*m+A*h,t[6]=b*o+M*l+v*f+A*g,t[7]=b*i+M*d+v*p+A*S,b=r[8],M=r[9],v=r[10],A=r[11],t[8]=b*n+M*a+v*u+A*y,t[9]=b*s+M*c+v*m+A*h,t[10]=b*o+M*l+v*f+A*g,t[11]=b*i+M*d+v*p+A*S,b=r[12],M=r[13],v=r[14],A=r[15],t[12]=b*n+M*a+v*u+A*y,t[13]=b*s+M*c+v*m+A*h,t[14]=b*o+M*l+v*f+A*g,t[15]=b*i+M*d+v*p+A*S,t}function Ru(t,e,r){var n=r[0],s=r[1],o=r[2],i,a,c,l,d,u,m,f,p,y,h,g;return e===t?(t[12]=e[0]*n+e[4]*s+e[8]*o+e[12],t[13]=e[1]*n+e[5]*s+e[9]*o+e[13],t[14]=e[2]*n+e[6]*s+e[10]*o+e[14],t[15]=e[3]*n+e[7]*s+e[11]*o+e[15]):(i=e[0],a=e[1],c=e[2],l=e[3],d=e[4],u=e[5],m=e[6],f=e[7],p=e[8],y=e[9],h=e[10],g=e[11],t[0]=i,t[1]=a,t[2]=c,t[3]=l,t[4]=d,t[5]=u,t[6]=m,t[7]=f,t[8]=p,t[9]=y,t[10]=h,t[11]=g,t[12]=i*n+d*s+p*o+e[12],t[13]=a*n+u*s+y*o+e[13],t[14]=c*n+m*s+h*o+e[14],t[15]=l*n+f*s+g*o+e[15]),t}function Bu(t,e,r){var n=r[0],s=r[1],o=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function ku(t,e,r,n){var s=n[0],o=n[1],i=n[2],a=Math.sqrt(s*s+o*o+i*i),c,l,d,u,m,f,p,y,h,g,S,b,M,v,A,_,L,T,w,H,G,V,C,J;return a<$?null:(a=1/a,s*=a,o*=a,i*=a,c=Math.sin(r),l=Math.cos(r),d=1-l,u=e[0],m=e[1],f=e[2],p=e[3],y=e[4],h=e[5],g=e[6],S=e[7],b=e[8],M=e[9],v=e[10],A=e[11],_=s*s*d+l,L=o*s*d+i*c,T=i*s*d-o*c,w=s*o*d-i*c,H=o*o*d+l,G=i*o*d+s*c,V=s*i*d+o*c,C=o*i*d-s*c,J=i*i*d+l,t[0]=u*_+y*L+b*T,t[1]=m*_+h*L+M*T,t[2]=f*_+g*L+v*T,t[3]=p*_+S*L+A*T,t[4]=u*w+y*H+b*G,t[5]=m*w+h*H+M*G,t[6]=f*w+g*H+v*G,t[7]=p*w+S*H+A*G,t[8]=u*V+y*C+b*J,t[9]=m*V+h*C+M*J,t[10]=f*V+g*C+v*J,t[11]=p*V+S*C+A*J,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Ou(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[4],i=e[5],a=e[6],c=e[7],l=e[8],d=e[9],u=e[10],m=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*s+l*n,t[5]=i*s+d*n,t[6]=a*s+u*n,t[7]=c*s+m*n,t[8]=l*s-o*n,t[9]=d*s-i*n,t[10]=u*s-a*n,t[11]=m*s-c*n,t}function Du(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[0],i=e[1],a=e[2],c=e[3],l=e[8],d=e[9],u=e[10],m=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*s-l*n,t[1]=i*s-d*n,t[2]=a*s-u*n,t[3]=c*s-m*n,t[8]=o*n+l*s,t[9]=i*n+d*s,t[10]=a*n+u*s,t[11]=c*n+m*s,t}function Nu(t,e,r){var n=Math.sin(r),s=Math.cos(r),o=e[0],i=e[1],a=e[2],c=e[3],l=e[4],d=e[5],u=e[6],m=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*s+l*n,t[1]=i*s+d*n,t[2]=a*s+u*n,t[3]=c*s+m*n,t[4]=l*s-o*n,t[5]=d*s-i*n,t[6]=u*s-a*n,t[7]=m*s-c*n,t}function Hu(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 Uu(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 Vu(t,e,r){var n=r[0],s=r[1],o=r[2],i=Math.sqrt(n*n+s*s+o*o),a,c,l;return i<$?null:(i=1/i,n*=i,s*=i,o*=i,a=Math.sin(e),c=Math.cos(e),l=1-c,t[0]=n*n*l+c,t[1]=s*n*l+o*a,t[2]=o*n*l-s*a,t[3]=0,t[4]=n*s*l-o*a,t[5]=s*s*l+c,t[6]=o*s*l+n*a,t[7]=0,t[8]=n*o*l+s*a,t[9]=s*o*l-n*a,t[10]=o*o*l+c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Gu(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 Wu(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 Xu(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 Wc(t,e,r){var n=e[0],s=e[1],o=e[2],i=e[3],a=n+n,c=s+s,l=o+o,d=n*a,u=n*c,m=n*l,f=s*c,p=s*l,y=o*l,h=i*a,g=i*c,S=i*l;return t[0]=1-(f+y),t[1]=u+S,t[2]=m-g,t[3]=0,t[4]=u-S,t[5]=1-(d+y),t[6]=p+h,t[7]=0,t[8]=m+g,t[9]=p-h,t[10]=1-(d+f),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Ku(t,e){var r=new He(3),n=-e[0],s=-e[1],o=-e[2],i=e[3],a=e[4],c=e[5],l=e[6],d=e[7],u=n*n+s*s+o*o+i*i;return u>0?(r[0]=(a*i+d*n+c*o-l*s)*2/u,r[1]=(c*i+d*s+l*n-a*o)*2/u,r[2]=(l*i+d*o+a*s-c*n)*2/u):(r[0]=(a*i+d*n+c*o-l*s)*2,r[1]=(c*i+d*s+l*n-a*o)*2,r[2]=(l*i+d*o+a*s-c*n)*2),Wc(t,e,r),t}function Yu(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Xc(t,e){var r=e[0],n=e[1],s=e[2],o=e[4],i=e[5],a=e[6],c=e[8],l=e[9],d=e[10];return t[0]=Math.sqrt(r*r+n*n+s*s),t[1]=Math.sqrt(o*o+i*i+a*a),t[2]=Math.sqrt(c*c+l*l+d*d),t}function qu(t,e){var r=new He(3);Xc(r,e);var n=1/r[0],s=1/r[1],o=1/r[2],i=e[0]*n,a=e[1]*s,c=e[2]*o,l=e[4]*n,d=e[5]*s,u=e[6]*o,m=e[8]*n,f=e[9]*s,p=e[10]*o,y=i+d+p,h=0;return y>0?(h=Math.sqrt(y+1)*2,t[3]=.25*h,t[0]=(u-f)/h,t[1]=(m-c)/h,t[2]=(a-l)/h):i>d&&i>p?(h=Math.sqrt(1+i-d-p)*2,t[3]=(u-f)/h,t[0]=.25*h,t[1]=(a+l)/h,t[2]=(m+c)/h):d>p?(h=Math.sqrt(1+d-i-p)*2,t[3]=(m-c)/h,t[0]=(a+l)/h,t[1]=.25*h,t[2]=(u+f)/h):(h=Math.sqrt(1+p-i-d)*2,t[3]=(a-l)/h,t[0]=(m+c)/h,t[1]=(u+f)/h,t[2]=.25*h),t}function $u(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var s=n[0],o=n[1],i=n[2],a=n[4],c=n[5],l=n[6],d=n[8],u=n[9],m=n[10];r[0]=Math.sqrt(s*s+o*o+i*i),r[1]=Math.sqrt(a*a+c*c+l*l),r[2]=Math.sqrt(d*d+u*u+m*m);var f=1/r[0],p=1/r[1],y=1/r[2],h=s*f,g=o*p,S=i*y,b=a*f,M=c*p,v=l*y,A=d*f,_=u*p,L=m*y,T=h+M+L,w=0;return T>0?(w=Math.sqrt(T+1)*2,t[3]=.25*w,t[0]=(v-_)/w,t[1]=(A-S)/w,t[2]=(g-b)/w):h>M&&h>L?(w=Math.sqrt(1+h-M-L)*2,t[3]=(v-_)/w,t[0]=.25*w,t[1]=(g+b)/w,t[2]=(A+S)/w):M>L?(w=Math.sqrt(1+M-h-L)*2,t[3]=(A-S)/w,t[0]=(g+b)/w,t[1]=.25*w,t[2]=(v+_)/w):(w=Math.sqrt(1+L-h-M)*2,t[3]=(g-b)/w,t[0]=(A+S)/w,t[1]=(v+_)/w,t[2]=.25*w),t}function ju(t,e,r,n){var s=e[0],o=e[1],i=e[2],a=e[3],c=s+s,l=o+o,d=i+i,u=s*c,m=s*l,f=s*d,p=o*l,y=o*d,h=i*d,g=a*c,S=a*l,b=a*d,M=n[0],v=n[1],A=n[2];return t[0]=(1-(p+h))*M,t[1]=(m+b)*M,t[2]=(f-S)*M,t[3]=0,t[4]=(m-b)*v,t[5]=(1-(u+h))*v,t[6]=(y+g)*v,t[7]=0,t[8]=(f+S)*A,t[9]=(y-g)*A,t[10]=(1-(u+p))*A,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Qu(t,e,r,n,s){var o=e[0],i=e[1],a=e[2],c=e[3],l=o+o,d=i+i,u=a+a,m=o*l,f=o*d,p=o*u,y=i*d,h=i*u,g=a*u,S=c*l,b=c*d,M=c*u,v=n[0],A=n[1],_=n[2],L=s[0],T=s[1],w=s[2],H=(1-(y+g))*v,G=(f+M)*v,V=(p-b)*v,C=(f-M)*A,J=(1-(m+g))*A,Se=(h+S)*A,Ct=(p+b)*_,jn=(h-S)*_,Br=(1-(m+y))*_;return t[0]=H,t[1]=G,t[2]=V,t[3]=0,t[4]=C,t[5]=J,t[6]=Se,t[7]=0,t[8]=Ct,t[9]=jn,t[10]=Br,t[11]=0,t[12]=r[0]+L-(H*L+C*T+Ct*w),t[13]=r[1]+T-(G*L+J*T+jn*w),t[14]=r[2]+w-(V*L+Se*T+Br*w),t[15]=1,t}function Ju(t,e){var r=e[0],n=e[1],s=e[2],o=e[3],i=r+r,a=n+n,c=s+s,l=r*i,d=n*i,u=n*a,m=s*i,f=s*a,p=s*c,y=o*i,h=o*a,g=o*c;return t[0]=1-u-p,t[1]=d+g,t[2]=m-h,t[3]=0,t[4]=d-g,t[5]=1-l-p,t[6]=f+y,t[7]=0,t[8]=m+h,t[9]=f-y,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Zu(t,e,r,n,s,o,i){var a=1/(r-e),c=1/(s-n),l=1/(o-i);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(s+n)*c,t[10]=(i+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=i*o*2*l,t[15]=0,t}function Kc(t,e,r,n,s){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,s!=null&&s!==1/0){var i=1/(n-s);t[10]=(s+n)*i,t[14]=2*s*n*i}else t[10]=-1,t[14]=-2*n;return t}var e0=Kc;function t0(t,e,r,n,s){var o=1/Math.tan(e/2);if(t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,s!=null&&s!==1/0){var i=1/(n-s);t[10]=s*i,t[14]=s*n*i}else t[10]=-1,t[14]=-n;return t}function r0(t,e,r,n){var s=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),i=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(i+a),l=2/(s+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((i-a)*c*.5),t[9]=(s-o)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Yc(t,e,r,n,s,o,i){var a=1/(e-r),c=1/(n-s),l=1/(o-i);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(s+n)*c,t[14]=(i+o)*l,t[15]=1,t}var n0=Yc;function s0(t,e,r,n,s,o,i){var a=1/(e-r),c=1/(n-s),l=1/(o-i);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(s+n)*c,t[14]=o*l,t[15]=1,t}function o0(t,e,r,n){var s,o,i,a,c,l,d,u,m,f,p=e[0],y=e[1],h=e[2],g=n[0],S=n[1],b=n[2],M=r[0],v=r[1],A=r[2];return Math.abs(p-M)<$&&Math.abs(y-v)<$&&Math.abs(h-A)<$?Vc(t):(d=p-M,u=y-v,m=h-A,f=1/Math.sqrt(d*d+u*u+m*m),d*=f,u*=f,m*=f,s=S*m-b*u,o=b*d-g*m,i=g*u-S*d,f=Math.sqrt(s*s+o*o+i*i),f?(f=1/f,s*=f,o*=f,i*=f):(s=0,o=0,i=0),a=u*i-m*o,c=m*s-d*i,l=d*o-u*s,f=Math.sqrt(a*a+c*c+l*l),f?(f=1/f,a*=f,c*=f,l*=f):(a=0,c=0,l=0),t[0]=s,t[1]=a,t[2]=d,t[3]=0,t[4]=o,t[5]=c,t[6]=u,t[7]=0,t[8]=i,t[9]=l,t[10]=m,t[11]=0,t[12]=-(s*p+o*y+i*h),t[13]=-(a*p+c*y+l*h),t[14]=-(d*p+u*y+m*h),t[15]=1,t)}function i0(t,e,r,n){var s=e[0],o=e[1],i=e[2],a=n[0],c=n[1],l=n[2],d=s-r[0],u=o-r[1],m=i-r[2],f=d*d+u*u+m*m;f>0&&(f=1/Math.sqrt(f),d*=f,u*=f,m*=f);var p=c*m-l*u,y=l*d-a*m,h=a*u-c*d;return f=p*p+y*y+h*h,f>0&&(f=1/Math.sqrt(f),p*=f,y*=f,h*=f),t[0]=p,t[1]=y,t[2]=h,t[3]=0,t[4]=u*h-m*y,t[5]=m*p-d*h,t[6]=d*y-u*p,t[7]=0,t[8]=d,t[9]=u,t[10]=m,t[11]=0,t[12]=s,t[13]=o,t[14]=i,t[15]=1,t}function a0(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 c0(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 l0(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 qc(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 d0(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 u0(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 m0(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 f0(t,e){var r=t[0],n=t[1],s=t[2],o=t[3],i=t[4],a=t[5],c=t[6],l=t[7],d=t[8],u=t[9],m=t[10],f=t[11],p=t[12],y=t[13],h=t[14],g=t[15],S=e[0],b=e[1],M=e[2],v=e[3],A=e[4],_=e[5],L=e[6],T=e[7],w=e[8],H=e[9],G=e[10],V=e[11],C=e[12],J=e[13],Se=e[14],Ct=e[15];return Math.abs(r-S)<=$*Math.max(1,Math.abs(r),Math.abs(S))&&Math.abs(n-b)<=$*Math.max(1,Math.abs(n),Math.abs(b))&&Math.abs(s-M)<=$*Math.max(1,Math.abs(s),Math.abs(M))&&Math.abs(o-v)<=$*Math.max(1,Math.abs(o),Math.abs(v))&&Math.abs(i-A)<=$*Math.max(1,Math.abs(i),Math.abs(A))&&Math.abs(a-_)<=$*Math.max(1,Math.abs(a),Math.abs(_))&&Math.abs(c-L)<=$*Math.max(1,Math.abs(c),Math.abs(L))&&Math.abs(l-T)<=$*Math.max(1,Math.abs(l),Math.abs(T))&&Math.abs(d-w)<=$*Math.max(1,Math.abs(d),Math.abs(w))&&Math.abs(u-H)<=$*Math.max(1,Math.abs(u),Math.abs(H))&&Math.abs(m-G)<=$*Math.max(1,Math.abs(m),Math.abs(G))&&Math.abs(f-V)<=$*Math.max(1,Math.abs(f),Math.abs(V))&&Math.abs(p-C)<=$*Math.max(1,Math.abs(p),Math.abs(C))&&Math.abs(y-J)<=$*Math.max(1,Math.abs(y),Math.abs(J))&&Math.abs(h-Se)<=$*Math.max(1,Math.abs(h),Math.abs(Se))&&Math.abs(g-Ct)<=$*Math.max(1,Math.abs(g),Math.abs(Ct))}var h0=Gc,p0=qc;var ie={};Ho(ie,{add:()=>v0,angle:()=>G0,bezier:()=>B0,ceil:()=>S0,clone:()=>y0,copy:()=>x0,create:()=>$c,cross:()=>F0,dist:()=>Q0,distance:()=>el,div:()=>j0,divide:()=>Zc,dot:()=>Xi,equals:()=>Y0,exactEquals:()=>K0,floor:()=>M0,forEach:()=>tm,fromValues:()=>g0,hermite:()=>R0,inverse:()=>I0,len:()=>Z0,length:()=>jc,lerp:()=>T0,max:()=>_0,min:()=>A0,mul:()=>$0,multiply:()=>Jc,negate:()=>P0,normalize:()=>z0,random:()=>k0,rotateX:()=>H0,rotateY:()=>U0,rotateZ:()=>V0,round:()=>w0,scale:()=>L0,scaleAndAdd:()=>E0,set:()=>b0,slerp:()=>C0,sqrDist:()=>J0,sqrLen:()=>em,squaredDistance:()=>tl,squaredLength:()=>rl,str:()=>X0,sub:()=>q0,subtract:()=>Qc,transformMat3:()=>D0,transformMat4:()=>O0,transformQuat:()=>N0,zero:()=>W0});function $c(){var t=new He(3);return He!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function y0(t){var e=new He(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function jc(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function g0(t,e,r){var n=new He(3);return n[0]=t,n[1]=e,n[2]=r,n}function x0(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function b0(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function v0(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Qc(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Jc(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Zc(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function S0(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function M0(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function A0(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 _0(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 w0(t,e){return t[0]=yo(e[0]),t[1]=yo(e[1]),t[2]=yo(e[2]),t}function L0(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function E0(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 el(t,e){var r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return Math.sqrt(r*r+n*n+s*s)}function tl(t,e){var r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return r*r+n*n+s*s}function rl(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function P0(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function I0(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function z0(t,e){var r=e[0],n=e[1],s=e[2],o=r*r+n*n+s*s;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function Xi(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function F0(t,e,r){var n=e[0],s=e[1],o=e[2],i=r[0],a=r[1],c=r[2];return t[0]=s*c-o*a,t[1]=o*i-n*c,t[2]=n*a-s*i,t}function T0(t,e,r,n){var s=e[0],o=e[1],i=e[2];return t[0]=s+n*(r[0]-s),t[1]=o+n*(r[1]-o),t[2]=i+n*(r[2]-i),t}function C0(t,e,r,n){var s=Math.acos(Math.min(Math.max(Xi(e,r),-1),1)),o=Math.sin(s),i=Math.sin((1-n)*s)/o,a=Math.sin(n*s)/o;return t[0]=i*e[0]+a*r[0],t[1]=i*e[1]+a*r[1],t[2]=i*e[2]+a*r[2],t}function R0(t,e,r,n,s,o){var i=o*o,a=i*(2*o-3)+1,c=i*(o-2)+o,l=i*(o-1),d=i*(3-2*o);return t[0]=e[0]*a+r[0]*c+n[0]*l+s[0]*d,t[1]=e[1]*a+r[1]*c+n[1]*l+s[1]*d,t[2]=e[2]*a+r[2]*c+n[2]*l+s[2]*d,t}function B0(t,e,r,n,s,o){var i=1-o,a=i*i,c=o*o,l=a*i,d=3*o*a,u=3*c*i,m=c*o;return t[0]=e[0]*l+r[0]*d+n[0]*u+s[0]*m,t[1]=e[1]*l+r[1]*d+n[1]*u+s[1]*m,t[2]=e[2]*l+r[2]*d+n[2]*u+s[2]*m,t}function k0(t,e){e=e===void 0?1:e;var r=Wi()*2*Math.PI,n=Wi()*2-1,s=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*s,t[1]=Math.sin(r)*s,t[2]=n*e,t}function O0(t,e,r){var n=e[0],s=e[1],o=e[2],i=r[3]*n+r[7]*s+r[11]*o+r[15];return i=i||1,t[0]=(r[0]*n+r[4]*s+r[8]*o+r[12])/i,t[1]=(r[1]*n+r[5]*s+r[9]*o+r[13])/i,t[2]=(r[2]*n+r[6]*s+r[10]*o+r[14])/i,t}function D0(t,e,r){var n=e[0],s=e[1],o=e[2];return t[0]=n*r[0]+s*r[3]+o*r[6],t[1]=n*r[1]+s*r[4]+o*r[7],t[2]=n*r[2]+s*r[5]+o*r[8],t}function N0(t,e,r){var n=r[0],s=r[1],o=r[2],i=r[3],a=e[0],c=e[1],l=e[2],d=s*l-o*c,u=o*a-n*l,m=n*c-s*a;return d=d+d,u=u+u,m=m+m,t[0]=a+i*d+s*m-o*u,t[1]=c+i*u+o*d-n*m,t[2]=l+i*m+n*u-s*d,t}function H0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[0],o[1]=s[1]*Math.cos(n)-s[2]*Math.sin(n),o[2]=s[1]*Math.sin(n)+s[2]*Math.cos(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function U0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[2]*Math.sin(n)+s[0]*Math.cos(n),o[1]=s[1],o[2]=s[2]*Math.cos(n)-s[0]*Math.sin(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function V0(t,e,r,n){var s=[],o=[];return s[0]=e[0]-r[0],s[1]=e[1]-r[1],s[2]=e[2]-r[2],o[0]=s[0]*Math.cos(n)-s[1]*Math.sin(n),o[1]=s[0]*Math.sin(n)+s[1]*Math.cos(n),o[2]=s[2],t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t}function G0(t,e){var r=t[0],n=t[1],s=t[2],o=e[0],i=e[1],a=e[2],c=Math.sqrt((r*r+n*n+s*s)*(o*o+i*i+a*a)),l=c&&Xi(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function W0(t){return t[0]=0,t[1]=0,t[2]=0,t}function X0(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function K0(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Y0(t,e){var r=t[0],n=t[1],s=t[2],o=e[0],i=e[1],a=e[2];return Math.abs(r-o)<=$*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-i)<=$*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(s-a)<=$*Math.max(1,Math.abs(s),Math.abs(a))}var q0=Qc,$0=Jc,j0=Zc,Q0=el,J0=tl,Z0=jc,em=rl,tm=(function(){var t=$c();return function(e,r,n,s,o,i){var a,c;for(r||(r=3),n||(n=0),s?c=Math.min(s*r+n,e.length):c=e.length,a=n;a<c;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,i),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var go=class{constructor(){this._position=ie.create();this._angles=ie.create();this._bobAngles=ie.create();this._bobOffset=ie.create();this._kickAngles=ie.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ae.create();this._projectionMatrix=ae.create();this._viewProjectionMatrix=ae.create();this._dirty=!0}get position(){return this._position}set position(e){ie.copy(this._position,e),this._dirty=!0}get angles(){return this._angles}set angles(e){ie.copy(this._angles,e),this._dirty=!0}get bobAngles(){return this._bobAngles}set bobAngles(e){ie.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){ie.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){ie.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ae.create();return ae.perspective(r,e*sr,this._aspect,this._near,this._far),r}updateMatrices(){if(!this._dirty)return;ae.perspective(this._projectionMatrix,this._fov*sr,this._aspect,this._near,this._far);let e=ae.fromValues(0,-1,0,0,0,0,1,0,-1,0,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],s=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,o=r*sr,i=n*sr,a=s*sr,c=ae.create();ae.identity(c),ae.rotateZ(c,c,-i),ae.rotateY(c,c,-o),ae.rotateX(c,c,-a);let l=ae.create();ae.multiply(l,e,c);let d=ie.add(ie.create(),this._position,this._bobOffset),u=ie.negate(ie.create(),d),m=ie.create();ie.transformMat4(m,u,c);let f=ie.fromValues(m[1]||0,m[2]||0,m[0]||0);ae.copy(this._viewMatrix,l),this._viewMatrix[12]=f[0],this._viewMatrix[13]=f[1],this._viewMatrix[14]=f[2],ae.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var rm=[.2,.2,.2],nm={x:0,y:0,z:1},sm=[.8,.8,.8];function Ki(t,e,r){return t+(e-t)*r}function Rr(t,e,r){return{x:Ki(t.x,e.x,r),y:Ki(t.y,e.y,r),z:Ki(t.z,e.z,r)}}function Cr(t){return t<0?0:t>1?1:t}function Yi(t){let e=[],r=[];for(let n of t.triangles){let s=e.length,[o,i,a]=n.indices,c=t.texCoords[o],l=t.texCoords[i],d=t.texCoords[a];if(!c||!l||!d)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:o,texCoord:[c.s,1-c.t]},{vertexIndex:i,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[d.s,1-d.t]}),r.push(s,s+1,s+2)}return{vertices:e,indices:new Uint16Array(r)}}function om(t,e,r){let n=r?.ambient??rm,s=r?.directional??{direction:nm,color:sm},o=Ue(t),i=Ue(s.direction),a=Cr(o.x*i.x+o.y*i.y+o.z*i.z),c=n[0]+s.color[0]*a,l=n[1]+s.color[1]*a,d=n[2]+s.color[2]*a;if(r?.dynamicLights){let u=r.modelMatrix?da(r.modelMatrix,e):e;for(let m of r.dynamicLights){let f=u.x-m.origin.x,p=u.y-m.origin.y,y=u.z-m.origin.z,h=f*f+p*p+y*y,g=m.radius*m.radius;if(h<g&&g>0){let S=1-Math.sqrt(h)/m.radius,b=Math.sqrt(h),M=b>0?Cr(-(f*o.x+p*o.y+y*o.z)/b):0,v=Cr(S*M);c+=m.color[0]*v,l+=m.color[1]*v,d+=m.color[2]*v}}}return[Cr(c),Cr(l),Cr(d)]}function qi(t,e,r,n){let s=t.vertices[r.currentFrame],o=t.vertices[r.nextFrame];if(!s||!o)throw new Error("Requested MD3 frames are out of range");let i=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,c)=>{let l=s[a.vertexIndex],d=o[a.vertexIndex];if(!l||!d)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let u=Rr(l.position,d.position,r.lerp),m=Ue(Rr(l.normal,d.normal,r.lerp)),f=om(m,u,n),p=c*12;i[p]=u.x,i[p+1]=u.y,i[p+2]=u.z,i[p+3]=m.x,i[p+4]=m.y,i[p+5]=m.z,i[p+6]=a.texCoord[0],i[p+7]=a.texCoord[1],i[p+8]=f[0],i[p+9]=f[1],i[p+10]=f[2],i[p+11]=1}),i}function nl(t,e,r){let n=t.tags[0];if(!n)return null;let s=n.findIndex(y=>y.name===r);if(s===-1)return null;let o=t.tags[e.currentFrame]?.[s],i=t.tags[e.nextFrame]?.[s];if(!o||!i)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=Rr(o.origin,i.origin,e.lerp),c=Ue(Rr(o.axis[0],i.axis[0],e.lerp)),l=Ue(Rr(o.axis[1],i.axis[1],e.lerp)),d=Ue(Rr(o.axis[2],i.axis[2],e.lerp)),u=c,m=Ue({x:l.x-u.x*(u.x*l.x+u.y*l.y+u.z*l.z),y:l.y-u.y*(u.x*l.x+u.y*l.y+u.z*l.z),z:l.z-u.z*(u.x*l.x+u.y*l.y+u.z*l.z)}),f=Ue({x:u.y*m.z-u.z*m.y,y:u.z*m.x-u.x*m.z,z:u.x*m.y-u.y*m.x}),p=[u,m,f];return{origin:a,axis:p,matrix:ua(a,p)}}var $i=`#version 300 es
260
260
  precision highp float;
261
261
 
262
262
  layout(location = 0) in vec3 a_position;
@@ -287,7 +287,7 @@ out vec4 o_color;
287
287
  void main() {
288
288
  vec4 albedo = texture(u_diffuseMap, v_texCoord) * u_tint;
289
289
  o_color = vec4(albedo.rgb * v_color.rgb, albedo.a * v_color.a);
290
- }`,Vn=class{constructor(e,r,n,s){this.gl=e,this.geometry=Yi(r),this.vertexBuffer=new ve(e,e.STATIC_DRAW),this.indexBuffer=new Ne(e,e.STATIC_DRAW),this.vertexArray=new _e(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,s)}update(e,r,n){let s=qi(e,this.geometry,r,n);this.vertexBuffer.upload(s,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}},xo=class{constructor(e,r,n,s){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=s,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Vn(e,o,n,s))})}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()}},bo=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:$i,fragment:ji},{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")}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)}drawSurface(e,r){let n=r?.diffuseSampler??0,s=r?.tint??[1,1,1,1];this.gl.uniform4fv(this.uniformTint,new Float32Array(s)),this.gl.uniform1i(this.uniformDiffuse,n),e.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var im=[1,1,1,1],vo=class{constructor(e,r=Math.random){this.maxParticles=e,this.random=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)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??im,s=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]=s.x,this.velocityY[r]=s.y,this.velocityZ[r]=s.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,r}update(e,r={}){let n=r.floorZ??-1/0;for(let s=0;s<this.maxParticles;s+=1){if(!this.alive[s])continue;if(this.remaining[s]-=e,this.remaining[s]<=0){this.alive[s]=0;continue}let o=Math.max(0,1-this.damping[s]*e);this.velocityX[s]*=o,this.velocityY[s]*=o,this.velocityZ[s]=this.velocityZ[s]*o-this.gravity[s]*e,this.positionX[s]+=this.velocityX[s]*e,this.positionY[s]+=this.velocityY[s]*e,this.positionZ[s]+=this.velocityZ[s]*e,this.positionZ[s]<n&&(this.positionZ[s]=n,this.velocityZ[s]=-this.velocityZ[s]*this.bounce[s],this.velocityX[s]*=.7,this.velocityY[s]*=.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"}}buildMesh(e,r){let n=[],s=[],o=[],i=a=>{let c=s.length,l=0;for(let d=0;d<this.maxParticles;d+=1){if(!this.alive[d]||(a==="additive"?1:0)!==this.blendMode[d])continue;l+=1;let u=n.length/9,m=this.size[d]*.5,f=this.fade[d]?Math.max(this.remaining[d]/this.lifetime[d],0):1,p=this.blendMode[d]===1?1.2:1,y=this.colorR[d]*p,h=this.colorG[d]*p,g=this.colorB[d]*p,S=this.colorA[d]*f,b=this.positionX[d],M=this.positionY[d],v=this.positionZ[d],A=e.x*m,_=e.y*m,L=e.z*m,C=r.x*m,w=r.y*m,H=r.z*m,G=[{x:b-A-C,y:M-_-w,z:v-L-H},{x:b+A-C,y:M+_-w,z:v+L-H},{x:b-A+C,y:M-_+w,z:v-L+H},{x:b+A+C,y:M+_+w,z:v+L+H}],V=[[0,1],[1,1],[0,0],[1,0]];G.forEach((T,J)=>{n.push(T.x,T.y,T.z,V[J]?.[0]??0,V[J]?.[1]??0,y,h,g,S)}),s.push(u,u+1,u+2,u+2,u+1,u+3)}l>0&&o.push({blendMode:a,start:c,count:s.length-c})};return i("alpha"),i("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(s),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},Qi=`#version 300 es
290
+ }`,Vn=class{constructor(e,r,n,s){this.gl=e,this.geometry=Yi(r),this.vertexBuffer=new ve(e,e.STATIC_DRAW),this.indexBuffer=new Ne(e,e.STATIC_DRAW),this.vertexArray=new _e(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,s)}update(e,r,n){let s=qi(e,this.geometry,r,n);this.vertexBuffer.upload(s,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}},xo=class{constructor(e,r,n,s){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=s,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Vn(e,o,n,s))})}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()}},bo=class{constructor(e){this.gl=e,this.program=be.create(e,{vertex:$i,fragment:ji},{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")}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)}drawSurface(e,r){let n=r?.diffuseSampler??0,s=r?.tint??[1,1,1,1];this.gl.uniform4fv(this.uniformTint,new Float32Array(s)),this.gl.uniform1i(this.uniformDiffuse,n),e.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var im=[1,1,1,1],vo=class{constructor(e,r=Math.random){this.maxParticles=e,this.random=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)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??im,s=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]=s.x,this.velocityY[r]=s.y,this.velocityZ[r]=s.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,r}update(e,r={}){let n=r.floorZ??-1/0;for(let s=0;s<this.maxParticles;s+=1){if(!this.alive[s])continue;if(this.remaining[s]-=e,this.remaining[s]<=0){this.alive[s]=0;continue}let o=Math.max(0,1-this.damping[s]*e);this.velocityX[s]*=o,this.velocityY[s]*=o,this.velocityZ[s]=this.velocityZ[s]*o-this.gravity[s]*e,this.positionX[s]+=this.velocityX[s]*e,this.positionY[s]+=this.velocityY[s]*e,this.positionZ[s]+=this.velocityZ[s]*e,this.positionZ[s]<n&&(this.positionZ[s]=n,this.velocityZ[s]=-this.velocityZ[s]*this.bounce[s],this.velocityX[s]*=.7,this.velocityY[s]*=.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"}}buildMesh(e,r){let n=[],s=[],o=[],i=a=>{let c=s.length,l=0;for(let d=0;d<this.maxParticles;d+=1){if(!this.alive[d]||(a==="additive"?1:0)!==this.blendMode[d])continue;l+=1;let u=n.length/9,m=this.size[d]*.5,f=this.fade[d]?Math.max(this.remaining[d]/this.lifetime[d],0):1,p=this.blendMode[d]===1?1.2:1,y=this.colorR[d]*p,h=this.colorG[d]*p,g=this.colorB[d]*p,S=this.colorA[d]*f,b=this.positionX[d],M=this.positionY[d],v=this.positionZ[d],A=e.x*m,_=e.y*m,L=e.z*m,T=r.x*m,w=r.y*m,H=r.z*m,G=[{x:b-A-T,y:M-_-w,z:v-L-H},{x:b+A-T,y:M+_-w,z:v+L-H},{x:b-A+T,y:M-_+w,z:v-L+H},{x:b+A+T,y:M+_+w,z:v+L+H}],V=[[0,1],[1,1],[0,0],[1,0]];G.forEach((C,J)=>{n.push(C.x,C.y,C.z,V[J]?.[0]??0,V[J]?.[1]??0,y,h,g,S)}),s.push(u,u+1,u+2,u+2,u+1,u+3)}l>0&&o.push({blendMode:a,start:c,count:s.length-c})};return i("alpha"),i("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(s),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},Qi=`#version 300 es
291
291
  precision highp float;
292
292
 
293
293
  layout(location = 0) in vec3 a_position;
@@ -315,5 +315,5 @@ void main() {
315
315
  float dist = distance(v_uv, vec2(0.5));
316
316
  float alpha = v_color.a * (1.0 - smoothstep(0.35, 0.5, dist));
317
317
  o_color = vec4(v_color.rgb, alpha);
318
- }`,So=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=be.create(e,{vertex:Qi,fragment:Ji}),this.vertexBuffer=new ve(e,e.DYNAMIC_DRAW),this.indexBuffer=new Ne(e,e.DYNAMIC_DRAW),this.vertexArray=new _e(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let s=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(s,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(s),this.gl.depthMask(!1),this.program.use();let o=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(o,!1,e.viewProjection),this.vertexArray.bind();for(let i of r.batches)i.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,i.count,this.gl.UNSIGNED_SHORT,i.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function sl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let s=0;s<12;s+=1){let o=200+e.random()*180,i=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+i*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let s=0;s<8;s+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ol(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let s=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),i=220+e.random()*260,a={x:Math.sin(o)*Math.cos(s),y:Math.sin(o)*Math.sin(s),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*i,y:a.y*i,z:a.z*i},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function il(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let s=0;s<24;s+=1){let o=120+e.random()*180;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*70,y:n.y*o+(e.random()-.5)*70,z:n.z*o+e.random()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function al(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let s=e.random()*Math.PI*2,o=8+e.random()*8;e.spawn({position:r,velocity:{x:Math.cos(s)*o,y:Math.sin(s)*o,z:100+e.random()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function cl(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let s=0;s<10;s+=1){let o=350+e.random()*100;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*30,y:n.y*o+(e.random()-.5)*30,z:n.z*o+(e.random()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function ll(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let s=0;s<6;s+=1)e.spawn({position:{x:r.x+n.x*s*2,y:r.y+n.y*s*2,z:r.z+n.z*s*2},velocity:{x:(e.random()-.5)*15,y:(e.random()-.5)*15,z:20+e.random()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}var Zt=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.offset=0}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(this.offset+=4,e<0||e>262144)return console.warn(`DemoReader: Invalid block length ${e} at offset ${this.offset-4}`),null;if(this.offset+e>this.buffer.byteLength)return console.warn(`DemoReader: Incomplete block. Expected ${e} bytes, but only ${this.buffer.byteLength-this.offset} remain.`),null;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new va(r)}}reset(){this.offset=0}getOffset(){return this.offset}};var Ao=1,_o=2,wo=4,Lo=8,Eo=16,Po=32,Zi=64,am=128,cm=256,Io=512,zo=1024,Fo=2048,Gn=4096,Wn=16384,lm=32768,Xn=65536,Co=1<<17,Kn=1<<18,Yn=1<<19,To=1<<20,Ro=1<<21,Bo=1<<22,dm=1<<23,ko=1<<24,qn=1<<25,Oo=1<<26,Do=1<<27,er=()=>({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}),Mo=()=>({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)}),tr=class{constructor(e,r){this.stream=e,this.handler=r}parseMessage(){for(;this.stream.hasMore();){let e=this.stream.readByte();if(e===-1)break;switch(e){case j.nop:break;case j.disconnect:this.handler?this.handler.onDisconnect():console.log("Server disconnected");break;case j.reconnect:this.handler?this.handler.onReconnect():console.log("Server reconnect");break;case j.print:let r=this.stream.readByte(),n=this.stream.readString();this.handler?this.handler.onPrint(r,n):console.log(`[Server Print ${r}]: ${n}`);break;case j.serverdata:this.parseServerData();break;case j.configstring:this.parseConfigString();break;case j.spawnbaseline:this.parseSpawnBaseline();break;case j.centerprint:let s=this.stream.readString();this.handler?this.handler.onCenterPrint(s):console.log(`[Center Print]: ${s}`);break;case j.download:this.parseDownload();break;case j.frame:this.parseFrame();break;case j.packetentities:this.parsePacketEntities(!1);break;case j.deltapacketentities:this.parsePacketEntities(!0);break;case j.stufftext:let o=this.stream.readString();this.handler?this.handler.onStuffText(o):console.log(`[StuffText]: ${o}`);break;case j.layout:let i=this.stream.readString();this.handler&&this.handler.onLayout(i);break;case j.inventory:this.parseInventory();break;case j.sound:this.parseSound();break;case j.muzzleflash:this.parseMuzzleFlash();break;case j.muzzleflash2:this.parseMuzzleFlash2();break;case j.temp_entity:this.parseTempEntity();break;default:console.warn(`Unknown server command: ${e}`);return}}}parseServerData(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),s=this.stream.readString(),o=this.stream.readShort(),i=this.stream.readString();this.handler?this.handler.onServerData(e,r,n,s,o,i):console.log(`Server Data: Protocol ${e}, Level ${i}, GameDir ${s}`)}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,s,o,i,a;if(e&1&&(n=this.stream.readByte()),e&2&&(s=this.stream.readByte()),e&16&&(o=this.stream.readByte()),e&8&&(i=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.stream.readPos(c),a=c}this.handler&&this.handler.onSound(e,r,n,s,o,i,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},s={x:0,y:0,z:0},o,i,a,c,l;switch(e){case E.BLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.GUNSHOT:case E.SPARKS:case E.BULLET_SPARKS:case E.SCREEN_SPARKS:case E.SHIELD_SPARKS:case E.SHOTGUN:this.stream.readPos(r),this.stream.readDir(s);break;case E.SPLASH:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.LASER_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.BLUEHYPERBLASTER:this.stream.readPos(r),this.stream.readPos(s);break;case E.BLASTER:this.stream.readPos(r),this.stream.readDir(s);break;case E.RAILTRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.EXPLOSION2:case E.GRENADE_EXPLOSION:case E.GRENADE_EXPLOSION_WATER:case E.PLASMA_EXPLOSION:case E.EXPLOSION1:case E.EXPLOSION1_BIG:case E.ROCKET_EXPLOSION:case E.ROCKET_EXPLOSION_WATER:case E.EXPLOSION1_NP:case E.BFG_EXPLOSION:case E.BFG_BIGEXPLOSION:this.stream.readPos(r);break;case E.BFG_LASER:this.stream.readPos(r),this.stream.readPos(n);break;case E.BUBBLETRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.PARASITE_ATTACK:case E.MEDIC_CABLE_ATTACK:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.BOSSTPORT:this.stream.readPos(r);break;case E.GRAPPLE_CABLE:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.WELDING_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.GREENBLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.TUNNEL_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.BLASTER2:case E.FLECHETTE:this.stream.readPos(r),this.stream.readDir(s);break;case E.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.DEBUGTRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.PLAIN_EXPLOSION:this.stream.readPos(r);break;case E.FLASHLIGHT:this.stream.readPos(r),a=this.stream.readShort();break;case E.FORCEWALL:this.stream.readPos(r),this.stream.readPos(n),i=this.stream.readByte();break;case E.HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.MONSTER_HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.HEATBEAM_SPARKS:case E.HEATBEAM_STEAM:this.stream.readPos(r),this.stream.readDir(s);break;case E.STEAM:this.stream.readShort()!==-1?(o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte(),this.stream.readShort(),this.stream.readLong()):(o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte(),this.stream.readShort());break;case E.BUBBLETRAIL2:this.stream.readPos(r),this.stream.readPos(n);break;case E.MOREBLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.CHAINFIST_SMOKE:this.stream.readPos(r);break;case E.ELECTRIC_SPARKS:this.stream.readPos(r),this.stream.readDir(s);break;case E.TRACKER_EXPLOSION:this.stream.readPos(r);break;case E.TELEPORT_EFFECT:case E.DBALL_GOAL:this.stream.readPos(r);break;case E.WIDOWBEAMOUT:this.stream.readShort(),this.stream.readPos(r);break;case E.NUKEBLAST:this.stream.readPos(r);break;case E.WIDOWSPLASH:this.stream.readPos(r);break;default:console.warn(`CL_ParseTEnt: bad type ${e}`);break}this.handler&&this.handler.onTempEntity(e,r,n,s,o,i,a,c,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=er();this.parseDelta(er(),r,e.number,e.bits),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),s=this.stream.readByte(),o=this.stream.readData(s),i=this.stream.readByte();if(i!==j.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${i}`);let a=this.parsePlayerState(),c=this.stream.readByte();if(c!==j.packetentities&&c!==j.deltapacketentities)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${c}`);let l=c===j.deltapacketentities,d=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:s,areaBits:o,playerState:a,packetEntities:{delta:l,entities:d}})}parsePlayerState(){let e=Mo(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.stream.readShort()*.125,e.origin.y=this.stream.readShort()*.125,e.origin.z=this.stream.readShort()*.125),r&4&&(e.velocity.x=this.stream.readShort()*.125,e.velocity.y=this.stream.readShort()*.125,e.velocity.z=this.stream.readShort()*.125),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=this.stream.readChar()*.25,e.viewoffset.y=this.stream.readChar()*.25,e.viewoffset.z=this.stream.readChar()*.25),r&256&&(e.viewangles.x=this.stream.readAngle16(),e.viewangles.y=this.stream.readAngle16(),e.viewangles.z=this.stream.readAngle16()),r&512&&(e.kick_angles.x=this.stream.readChar()*.25,e.kick_angles.y=this.stream.readChar()*.25,e.kick_angles.z=this.stream.readChar()*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=this.stream.readChar()*.25,e.gun_offset.y=this.stream.readChar()*.25,e.gun_offset.z=this.stream.readChar()*.25,e.gun_angles.x=this.stream.readChar()*.25,e.gun_angles.y=this.stream.readChar()*.25,e.gun_angles.z=this.stream.readChar()*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let s=0;s<32;s++)n&1<<s&&(e.stats[s]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Mo(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.number===0)break;let n=er();this.parseDelta(er(),n,r.number,r.bits),e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&am&&(e|=this.stream.readByte()<<8),e&lm&&(e|=this.stream.readByte()<<16),e&dm&&(e|=this.stream.readByte()<<24);let r;return e&cm?r=this.stream.readShort():r=this.stream.readByte(),{number:r,bits:e}}parseDelta(e,r,n,s){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=s,s&Fo&&(r.modelindex=this.stream.readByte()),s&To&&(r.modelindex2=this.stream.readByte()),s&Ro&&(r.modelindex3=this.stream.readByte()),s&Bo&&(r.modelindex4=this.stream.readByte()),s&Eo&&(r.frame=this.stream.readByte()),s&Co&&(r.frame=this.stream.readShort()),s&Xn&&s&qn?r.skinnum=this.stream.readLong():s&Xn?r.skinnum=this.stream.readByte():s&qn&&(r.skinnum=this.stream.readShort()),s&Wn&&s&Yn?r.effects=this.stream.readLong():s&Wn?r.effects=this.stream.readByte():s&Yn&&(r.effects=this.stream.readShort()),s&Gn&&s&Kn?r.renderfx=this.stream.readLong():s&Gn?r.renderfx=this.stream.readByte():s&Kn&&(r.renderfx=this.stream.readShort()),s&Ao&&(r.origin.x=this.stream.readCoord()),s&_o&&(r.origin.y=this.stream.readCoord()),s&Io&&(r.origin.z=this.stream.readCoord()),s&zo&&(r.angles.x=this.stream.readAngle()),s&wo&&(r.angles.y=this.stream.readAngle()),s&Lo&&(r.angles.z=this.stream.readAngle()),s&ko&&this.stream.readPos(r.old_origin),s&Oo&&(r.sound=this.stream.readByte()),s&Po?r.event=this.stream.readByte():r.event=0,s&Do&&(r.solid=this.stream.readShort())}};var No=(s=>(s[s.Stopped=0]="Stopped",s[s.Playing=1]="Playing",s[s.Paused=2]="Paused",s[s.Finished=3]="Finished",s))(No||{}),$n=class{constructor(){this.reader=null;this.state=0;this.playbackSpeed=1;this.accumulatedTime=0;this.frameDuration=100}setHandler(e){this.handler=e}loadDemo(e){this.reader=new Zt(e),this.state=0,this.accumulatedTime=0}play(){this.reader&&(this.state=1)}pause(){this.state===1&&(this.state=2)}stop(){this.state=0,this.reader&&this.reader.reset(),this.accumulatedTime=0}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.reader.hasMore()){this.state=3;return}let r=this.reader.readNextBlock();if(!r){this.state=3;return}new tr(r.data,this.handler).parseMessage(),this.accumulatedTime-=this.frameDuration}}getState(){return this.state}};function um(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Rt(e,r)}}}return bl(mm);})();
318
+ }`,So=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=be.create(e,{vertex:Qi,fragment:Ji}),this.vertexBuffer=new ve(e,e.DYNAMIC_DRAW),this.indexBuffer=new Ne(e,e.DYNAMIC_DRAW),this.vertexArray=new _e(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let s=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(s,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(s),this.gl.depthMask(!1),this.program.use();let o=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(o,!1,e.viewProjection),this.vertexArray.bind();for(let i of r.batches)i.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,i.count,this.gl.UNSIGNED_SHORT,i.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function sl(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let s=0;s<12;s+=1){let o=200+e.random()*180,i=e.random()*.35;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*80,y:n.y*o+(e.random()-.5)*80,z:Math.max(n.z*o,120)+i*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.random()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let s=0;s<8;s+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*40,y:(e.random()-.5)*40,z:80+e.random()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function ol(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let s=e.random()*Math.PI*2,o=Math.acos(2*e.random()-1),i=220+e.random()*260,a={x:Math.sin(o)*Math.cos(s),y:Math.sin(o)*Math.sin(s),z:Math.cos(o)};e.spawn({position:r,velocity:{x:a.x*i,y:a.y*i,z:a.z*i},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.random()-.5)*30,y:(e.random()-.5)*30,z:120+e.random()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function il(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let s=0;s<24;s+=1){let o=120+e.random()*180;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*70,y:n.y*o+(e.random()-.5)*70,z:n.z*o+e.random()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function al(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let s=e.random()*Math.PI*2,o=8+e.random()*8;e.spawn({position:r,velocity:{x:Math.cos(s)*o,y:Math.sin(s)*o,z:100+e.random()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function cl(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let s=0;s<10;s+=1){let o=350+e.random()*100;e.spawn({position:r,velocity:{x:n.x*o+(e.random()-.5)*30,y:n.y*o+(e.random()-.5)*30,z:n.z*o+(e.random()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function ll(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let s=0;s<6;s+=1)e.spawn({position:{x:r.x+n.x*s*2,y:r.y+n.y*s*2,z:r.z+n.z*s*2},velocity:{x:(e.random()-.5)*15,y:(e.random()-.5)*15,z:20+e.random()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}var Zt=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.offset=0}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(this.offset+=4,e<0||e>262144)return console.warn(`DemoReader: Invalid block length ${e} at offset ${this.offset-4}`),null;if(this.offset+e>this.buffer.byteLength)return console.warn(`DemoReader: Incomplete block. Expected ${e} bytes, but only ${this.buffer.byteLength-this.offset} remain.`),null;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new va(r)}}reset(){this.offset=0}getOffset(){return this.offset}};var Ao=1,_o=2,wo=4,Lo=8,Eo=16,Po=32,Zi=64,am=128,cm=256,Io=512,zo=1024,Fo=2048,Gn=4096,Wn=16384,lm=32768,Xn=65536,To=1<<17,Kn=1<<18,Yn=1<<19,Co=1<<20,Ro=1<<21,Bo=1<<22,dm=1<<23,ko=1<<24,qn=1<<25,Oo=1<<26,Do=1<<27,er=()=>({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}),Mo=()=>({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)}),tr=class{constructor(e,r){this.stream=e,this.handler=r}parseMessage(){for(;this.stream.hasMore();){let e=this.stream.readByte();if(e===-1)break;switch(e){case j.nop:break;case j.disconnect:this.handler?this.handler.onDisconnect():console.log("Server disconnected");break;case j.reconnect:this.handler?this.handler.onReconnect():console.log("Server reconnect");break;case j.print:let r=this.stream.readByte(),n=this.stream.readString();this.handler?this.handler.onPrint(r,n):console.log(`[Server Print ${r}]: ${n}`);break;case j.serverdata:this.parseServerData();break;case j.configstring:this.parseConfigString();break;case j.spawnbaseline:this.parseSpawnBaseline();break;case j.centerprint:let s=this.stream.readString();this.handler?this.handler.onCenterPrint(s):console.log(`[Center Print]: ${s}`);break;case j.download:this.parseDownload();break;case j.frame:this.parseFrame();break;case j.packetentities:this.parsePacketEntities(!1);break;case j.deltapacketentities:this.parsePacketEntities(!0);break;case j.stufftext:let o=this.stream.readString();this.handler?this.handler.onStuffText(o):console.log(`[StuffText]: ${o}`);break;case j.layout:let i=this.stream.readString();this.handler&&this.handler.onLayout(i);break;case j.inventory:this.parseInventory();break;case j.sound:this.parseSound();break;case j.muzzleflash:this.parseMuzzleFlash();break;case j.muzzleflash2:this.parseMuzzleFlash2();break;case j.temp_entity:this.parseTempEntity();break;default:console.warn(`Unknown server command: ${e}`);return}}}parseServerData(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),s=this.stream.readString(),o=this.stream.readShort(),i=this.stream.readString();this.handler?this.handler.onServerData(e,r,n,s,o,i):console.log(`Server Data: Protocol ${e}, Level ${i}, GameDir ${s}`)}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,s,o,i,a;if(e&1&&(n=this.stream.readByte()),e&2&&(s=this.stream.readByte()),e&16&&(o=this.stream.readByte()),e&8&&(i=this.stream.readShort()),e&4){let c={x:0,y:0,z:0};this.stream.readPos(c),a=c}this.handler&&this.handler.onSound(e,r,n,s,o,i,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},s={x:0,y:0,z:0},o,i,a,c,l;switch(e){case E.BLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.GUNSHOT:case E.SPARKS:case E.BULLET_SPARKS:case E.SCREEN_SPARKS:case E.SHIELD_SPARKS:case E.SHOTGUN:this.stream.readPos(r),this.stream.readDir(s);break;case E.SPLASH:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.LASER_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.BLUEHYPERBLASTER:this.stream.readPos(r),this.stream.readPos(s);break;case E.BLASTER:this.stream.readPos(r),this.stream.readDir(s);break;case E.RAILTRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.EXPLOSION2:case E.GRENADE_EXPLOSION:case E.GRENADE_EXPLOSION_WATER:case E.PLASMA_EXPLOSION:case E.EXPLOSION1:case E.EXPLOSION1_BIG:case E.ROCKET_EXPLOSION:case E.ROCKET_EXPLOSION_WATER:case E.EXPLOSION1_NP:case E.BFG_EXPLOSION:case E.BFG_BIGEXPLOSION:this.stream.readPos(r);break;case E.BFG_LASER:this.stream.readPos(r),this.stream.readPos(n);break;case E.BUBBLETRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.PARASITE_ATTACK:case E.MEDIC_CABLE_ATTACK:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.BOSSTPORT:this.stream.readPos(r);break;case E.GRAPPLE_CABLE:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.WELDING_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.GREENBLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.TUNNEL_SPARKS:o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte();break;case E.BLASTER2:case E.FLECHETTE:this.stream.readPos(r),this.stream.readDir(s);break;case E.LIGHTNING:c=this.stream.readShort(),l=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n);break;case E.DEBUGTRAIL:this.stream.readPos(r),this.stream.readPos(n);break;case E.PLAIN_EXPLOSION:this.stream.readPos(r);break;case E.FLASHLIGHT:this.stream.readPos(r),a=this.stream.readShort();break;case E.FORCEWALL:this.stream.readPos(r),this.stream.readPos(n),i=this.stream.readByte();break;case E.HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.MONSTER_HEATBEAM:a=this.stream.readShort(),this.stream.readPos(r),this.stream.readPos(n),this.stream.readPos(s);break;case E.HEATBEAM_SPARKS:case E.HEATBEAM_STEAM:this.stream.readPos(r),this.stream.readDir(s);break;case E.STEAM:this.stream.readShort()!==-1?(o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte(),this.stream.readShort(),this.stream.readLong()):(o=this.stream.readByte(),this.stream.readPos(r),this.stream.readDir(s),i=this.stream.readByte(),this.stream.readShort());break;case E.BUBBLETRAIL2:this.stream.readPos(r),this.stream.readPos(n);break;case E.MOREBLOOD:this.stream.readPos(r),this.stream.readDir(s);break;case E.CHAINFIST_SMOKE:this.stream.readPos(r);break;case E.ELECTRIC_SPARKS:this.stream.readPos(r),this.stream.readDir(s);break;case E.TRACKER_EXPLOSION:this.stream.readPos(r);break;case E.TELEPORT_EFFECT:case E.DBALL_GOAL:this.stream.readPos(r);break;case E.WIDOWBEAMOUT:this.stream.readShort(),this.stream.readPos(r);break;case E.NUKEBLAST:this.stream.readPos(r);break;case E.WIDOWSPLASH:this.stream.readPos(r);break;default:console.warn(`CL_ParseTEnt: bad type ${e}`);break}this.handler&&this.handler.onTempEntity(e,r,n,s,o,i,a,c,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=er();this.parseDelta(er(),r,e.number,e.bits),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=this.stream.readByte(),s=this.stream.readByte(),o=this.stream.readData(s),i=this.stream.readByte();if(i!==j.playerinfo)throw new Error(`Expected svc_playerinfo after svc_frame, got ${i}`);let a=this.parsePlayerState(),c=this.stream.readByte();if(c!==j.packetentities&&c!==j.deltapacketentities)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${c}`);let l=c===j.deltapacketentities,d=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:s,areaBits:o,playerState:a,packetEntities:{delta:l,entities:d}})}parsePlayerState(){let e=Mo(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.stream.readShort()*.125,e.origin.y=this.stream.readShort()*.125,e.origin.z=this.stream.readShort()*.125),r&4&&(e.velocity.x=this.stream.readShort()*.125,e.velocity.y=this.stream.readShort()*.125,e.velocity.z=this.stream.readShort()*.125),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=this.stream.readChar()*.25,e.viewoffset.y=this.stream.readChar()*.25,e.viewoffset.z=this.stream.readChar()*.25),r&256&&(e.viewangles.x=this.stream.readAngle16(),e.viewangles.y=this.stream.readAngle16(),e.viewangles.z=this.stream.readAngle16()),r&512&&(e.kick_angles.x=this.stream.readChar()*.25,e.kick_angles.y=this.stream.readChar()*.25,e.kick_angles.z=this.stream.readChar()*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=this.stream.readChar()*.25,e.gun_offset.y=this.stream.readChar()*.25,e.gun_offset.z=this.stream.readChar()*.25,e.gun_angles.x=this.stream.readChar()*.25,e.gun_angles.y=this.stream.readChar()*.25,e.gun_angles.z=this.stream.readChar()*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let s=0;s<32;s++)n&1<<s&&(e.stats[s]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:Mo(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.number===0)break;let n=er();this.parseDelta(er(),n,r.number,r.bits),e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&am&&(e|=this.stream.readByte()<<8),e&lm&&(e|=this.stream.readByte()<<16),e&dm&&(e|=this.stream.readByte()<<24);let r;return e&cm?r=this.stream.readShort():r=this.stream.readByte(),{number:r,bits:e}}parseDelta(e,r,n,s){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=s,s&Fo&&(r.modelindex=this.stream.readByte()),s&Co&&(r.modelindex2=this.stream.readByte()),s&Ro&&(r.modelindex3=this.stream.readByte()),s&Bo&&(r.modelindex4=this.stream.readByte()),s&Eo&&(r.frame=this.stream.readByte()),s&To&&(r.frame=this.stream.readShort()),s&Xn&&s&qn?r.skinnum=this.stream.readLong():s&Xn?r.skinnum=this.stream.readByte():s&qn&&(r.skinnum=this.stream.readShort()),s&Wn&&s&Yn?r.effects=this.stream.readLong():s&Wn?r.effects=this.stream.readByte():s&Yn&&(r.effects=this.stream.readShort()),s&Gn&&s&Kn?r.renderfx=this.stream.readLong():s&Gn?r.renderfx=this.stream.readByte():s&Kn&&(r.renderfx=this.stream.readShort()),s&Ao&&(r.origin.x=this.stream.readCoord()),s&_o&&(r.origin.y=this.stream.readCoord()),s&Io&&(r.origin.z=this.stream.readCoord()),s&zo&&(r.angles.x=this.stream.readAngle()),s&wo&&(r.angles.y=this.stream.readAngle()),s&Lo&&(r.angles.z=this.stream.readAngle()),s&ko&&this.stream.readPos(r.old_origin),s&Oo&&(r.sound=this.stream.readByte()),s&Po?r.event=this.stream.readByte():r.event=0,s&Do&&(r.solid=this.stream.readShort())}};var No=(s=>(s[s.Stopped=0]="Stopped",s[s.Playing=1]="Playing",s[s.Paused=2]="Paused",s[s.Finished=3]="Finished",s))(No||{}),$n=class{constructor(){this.reader=null;this.state=0;this.playbackSpeed=1;this.accumulatedTime=0;this.frameDuration=100}setHandler(e){this.handler=e}loadDemo(e){this.reader=new Zt(e),this.state=0,this.accumulatedTime=0}play(){this.reader&&(this.state=1)}pause(){this.state===1&&(this.state=2)}stop(){this.state=0,this.reader&&this.reader.reset(),this.accumulatedTime=0}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.reader.hasMore()){this.state=3;return}let r=this.reader.readNextBlock();if(!r){this.state=3;return}new tr(r.data,this.handler).parseMessage(),this.accumulatedTime-=this.frameDuration}}getState(){return this.state}};function um(t){return{init(){t.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,r){return new Rt(e,r)}}}return bl(mm);})();
319
319
  //# sourceMappingURL=index.global.js.map