quake2ts 0.0.45 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/viewer/dist/browser/index.global.js +1 -1
- package/apps/viewer/dist/browser/index.global.js.map +1 -1
- package/apps/viewer/dist/cjs/index.cjs.map +1 -1
- package/apps/viewer/dist/esm/index.js.map +1 -1
- package/apps/viewer/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/browser/index.global.js +69 -10
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +781 -5
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +763 -5
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/index.d.ts +2 -0
- package/packages/engine/dist/types/index.d.ts.map +1 -1
- package/packages/engine/dist/types/render/md3Pipeline.d.ts +79 -0
- package/packages/engine/dist/types/render/md3Pipeline.d.ts.map +1 -0
- package/packages/engine/dist/types/render/particleSystem.d.ts +105 -0
- package/packages/engine/dist/types/render/particleSystem.d.ts.map +1 -0
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +65 -0
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +61 -0
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/index.d.ts +1 -0
- package/packages/shared/dist/types/index.d.ts.map +1 -1
- package/packages/shared/dist/types/math/mat4.d.ts +7 -0
- package/packages/shared/dist/types/math/mat4.d.ts.map +1 -0
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Quake2Engine=(()=>{var Ca=Object.create;var wn=Object.defineProperty;var Ea=Object.getOwnPropertyDescriptor;var Ta=Object.getOwnPropertyNames;var za=Object.getPrototypeOf,Pa=Object.prototype.hasOwnProperty;var Fa=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ia=(t,e)=>{for(var r in e)wn(t,r,{get:e[r],enumerable:!0})},ji=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ta(e))!Pa.call(t,o)&&o!==r&&wn(t,o,{get:()=>e[o],enumerable:!(n=Ea(e,o))||n.enumerable});return t};var ka=(t,e,r)=>(r=t!=null?Ca(za(t)):{},ji(e||!t||!t.__esModule?wn(r,"default",{value:t,enumerable:!0}):r,t)),Ra=t=>ji(wn({},"__esModule",{value:!0}),t);var Cs=Fa((wu,Ls)=>{"use strict";Ls.exports=Worker});var dl={};Ia(dl,{ATTN_IDLE:()=>oa,ATTN_LOOP_NONE:()=>ra,ATTN_NONE:()=>So,ATTN_NORM:()=>na,ATTN_STATIC:()=>ia,AssetDependencyError:()=>kt,AssetDependencyTracker:()=>gn,AssetManager:()=>xo,AudioApi:()=>Po,AudioContextController:()=>_o,AudioRegistry:()=>cr,AudioRegistryError:()=>pn,AudioSystem:()=>To,BSP_SURFACE_FRAGMENT_SOURCE:()=>Fi,BSP_SURFACE_VERTEX_SOURCE:()=>Pi,BSP_VERTEX_LAYOUT:()=>Ei,BspSurfacePipeline:()=>ko,ConfigStringRegistry:()=>Bt,Cvar:()=>xr,CvarRegistry:()=>Pn,EngineHost:()=>Ot,EngineRuntime:()=>gr,FixedTimestepLoop:()=>gt,Framebuffer:()=>Fo,IndexBuffer:()=>yt,LruCache:()=>Qe,MAX_SOUND_CHANNELS:()=>wi,MD2_FRAGMENT_SHADER:()=>Oi,MD2_VERTEX_SHADER:()=>Ni,Md2Loader:()=>Ut,Md2MeshBuffers:()=>Ho,Md2ParseError:()=>K,Md2Pipeline:()=>Do,Md3Loader:()=>Gt,Md3ParseError:()=>pe,MusicSystem:()=>zo,PakArchive:()=>Vt,PakIndexStore:()=>go,PakIngestionError:()=>Je,PakParseError:()=>fe,PakValidationError:()=>xt,PakValidator:()=>In,RERELEASE_KNOWN_PAKS:()=>Qo,SKYBOX_FRAGMENT_SHADER:()=>Hi,SKYBOX_VERTEX_SHADER:()=>Ri,SOUND_FULLVOLUME:()=>lr,SOUND_LOOP_ATTENUATE:()=>sa,ShaderProgram:()=>Me,SkyboxPipeline:()=>Ro,SoundChannel:()=>bo,SoundPrecache:()=>Mo,SoundRegistry:()=>wo,Texture2D:()=>ur,TextureCache:()=>Wt,TextureCubeMap:()=>dr,VertexArray:()=>Re,VertexBuffer:()=>Le,VirtualFileSystem:()=>Fn,advanceAnimation:()=>bs,applySurfaceState:()=>xa,attenuationToDistanceMultiplier:()=>Rt,boxIntersectsFrustum:()=>bn,buildBspGeometry:()=>da,buildMd2Geometry:()=>Bi,buildMd2VertexData:()=>Vi,calculateMaxAudibleDistance:()=>vo,calculatePakChecksum:()=>ds,computeFrameBlend:()=>Ss,computeSkyScroll:()=>va,createAnimationState:()=>vs,createAudioGraph:()=>Ao,createEngine:()=>ul,createEngineRuntime:()=>ls,createInitialChannels:()=>Lo,createProgramFromSources:()=>ua,createWebGLContext:()=>ca,decodeOgg:()=>yo,deriveSurfaceRenderState:()=>ki,extractFrustumPlanes:()=>ma,filesToPakSources:()=>Zo,findLeafForPoint:()=>zi,gatherVisibleFaces:()=>ya,groupMd2Animations:()=>gs,ingestPakFiles:()=>ms,ingestPaks:()=>kn,interpolateVec3:()=>_s,parseMd2:()=>ei,parseMd3:()=>ti,parsePcx:()=>As,parseWal:()=>Hn,parseWalTexture:()=>Ms,parseWav:()=>Nn,pcxToRgba:()=>Dn,pickChannel:()=>Co,preparePcxTexture:()=>ws,removeViewTranslation:()=>Sa,resolveLightStyles:()=>Ii,spatializeOrigin:()=>Eo,walToRgba:()=>ri,wireDropTarget:()=>fs,wireFileInput:()=>ps});var Ha=()=>typeof performance<"u"?performance.now():Date.now(),Da=t=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,25)},gt=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,o=r.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:o,maxDeltaMs:r.maxDeltaMs??n*o,startTimeMs:r.startTimeMs,now:r.now??Ha,schedule:r.schedule??Da}}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 o=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&o<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:r}),this.accumulatorMs-=this.options.fixedDeltaMs,o+=1;let i=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:i,nowMs:r,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var Ot=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.renderClient=e=>{this.client&&this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame})};let o=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??o,this.loop=new gt({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 Ji={x:0,y:0,z:0};var yl=Math.PI/180;function Qi(t,e){return{x:t.x-e.x,y:t.y-e.y,z:t.z-e.z}}function Na(t,e){return{x:t.x*e,y:t.y*e,z:t.z*e}}function Uo(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}function Oa(t){return Uo(t,t)}function Go(t){return Math.sqrt(Oa(t))}function Zi(t){let e=Go(t);return e===0?t:Na(t,1/e)}var gl=Math.PI/180,xl=180/Math.PI;var Ce=1,je=2;var Wo=8,Xo=16,Ba=32;var Va=16384;var Mn=65536,es=1<<17,Ua=1<<18,Ga=1<<19,Wa=1<<20,Xa=1<<21,Ka=1<<22,qa=1<<23,bl=1<<24,Ln=1<<25,$a=1<<26,Sl=1<<27,vl=1<<28,_l=1<<29,Cn=1<<30,Al=1<<31;var yr=0;var ts=4,rs=8,ns=16,os=32,is=64;var wl=1<<25,Ml=1<<28,Ll=1<<29,Cl=1<<30,El=1<<31;var Tl=Ce|je,zl=Ce|Mn|je|Ln|Cn,Pl=Ce|Mn|je,Fl=Ce|es|je|Ln|Cn,Il=Ba|Wo|Xo,kl=Ce|Xo|Wo,Ya=Ce|Ln|Cn|je|$a,Rl=Ua|Ga|Wa|Xa|Ka|qa,Hl=Ce|Wo|Xo|Ln|Cn,Dl=Ce|Mn|je,Nl=Ce|je,Ol=Ce|Mn|je|es,Bl=Ya|Va;var Vl=Number.MAX_SAFE_INTEGER-1;var En=(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))(En||{});var Tn=256;var Ko=256,qo=8192,zn=2048,$o=512,Yo=256,jo=Tn*2,Jo=256,Vo=32,hr=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+qo]="Sounds",t[t.Images=t.Sounds+zn]="Images",t[t.Lights=t.Images+$o]="Lights",t[t.ShadowLights=t.Lights+Ko]="ShadowLights",t[t.Items=t.ShadowLights+Jo]="Items",t[t.PlayerSkins=t.Items+Yo]="PlayerSkins",t[t.General=t.PlayerSkins+Tn]="General",t[t.WheelWeapons=t.General+jo]="WheelWeapons",t[t.WheelAmmo=t.WheelWeapons+Vo]="WheelAmmo",t[t.WheelPowerups=t.WheelAmmo+Vo]="WheelPowerups",t[t.CdLoopCount=t.WheelPowerups+Vo]="CdLoopCount",t[t.GameStyle=t.CdLoopCount+1]="GameStyle",t[t.MaxConfigStrings=t.GameStyle+1]="MaxConfigStrings",t))(k||{}),ss=k.MaxConfigStrings;function as(t){return t>=5&&t<59?hr*(59-t):t>=k.General&&t<k.WheelWeapons?hr*(k.MaxConfigStrings-t):hr}function ja(t){if(t<0||t>=k.MaxConfigStrings)throw new RangeError(`Configstring index ${t} is out of range (0-${k.MaxConfigStrings-1})`)}function cs(t,e){let r=as(t);if(e.length>r)throw new RangeError(`Configstring ${t} exceeds maximum length (${e.length} > ${r}); limit is ${hr} chars per slot`)}var Bt=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 ja(e),cs(e,r),this.values.set(e,r),e}get(e){return this.values.get(e)}getAll(){let e=new Array(ss).fill("");for(let[r,n]of this.values.entries())e[r]=n;return e}modelIndex(e){return this.register(e,k.Models,qo,"modelCursor")}soundIndex(e){return this.register(e,k.Sounds,zn,"soundCursor")}findSoundIndex(e){for(let r=k.Sounds;r<k.Sounds+zn;r+=1)if(this.values.get(r)===e)return r}imageIndex(e){return this.register(e,k.Images,$o,"imageCursor")}lightIndex(e){return this.register(e,k.Lights,Ko,"lightCursor")}shadowLightIndex(e){return this.register(e,k.ShadowLights,Jo,"shadowLightCursor")}itemIndex(e){return this.register(e,k.Items,Yo,"itemCursor")}playerSkinIndex(e){return this.register(e,k.PlayerSkins,Tn,"playerSkinCursor")}generalIndex(e){return this.register(e,k.General,jo,"generalCursor")}register(e,r,n,o){for(let a=r;a<r+n;a+=1)if(this.values.get(a)===e)return a;let i=this[o],s=r+n;if(i>=s)throw new RangeError(`Out of configstring slots for range starting at ${r}`);return cs(i,e),this.values.set(i,e),this[o]=i+1,i}};var gr=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 ls(t,e,r,n){return new gr(t,new Ot(e,r,n))}var xr=class{constructor({name:e,defaultValue:r,description:n,flags:o=En.None,onChange:i}){this.modifiedCount=0;this.name=e,this.defaultValue=r,this.description=n,this.flags=o,this._value=r,this.onChange=i}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&En.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)}},Pn=class{constructor(){this.cvars=new Map}register(e){let r=this.cvars.get(e.name);if(r)return r;let n=new xr(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 Ja="PACK";function Qa(t,e,r){let n=[];for(let o=0;o<r;o+=1){let i=t.getUint8(e+o);if(i===0)break;n.push(i)}return String.fromCharCode(...n)}function U(t){return t.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Za(){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 ec=Za();function us(t){let e=4294967295;for(let r=0;r<t.length;r+=1){let n=t[r];e=ec[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var fe=class extends Error{},Vt=class t{constructor(e,r,n,o){this.name=e;this.buffer=r;this.entries=new Map(n.map(i=>[i.name,i])),this.checksum=o,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 o=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(o!==Ja)throw new fe(`Invalid PAK header magic: ${o}`);let i=n.getInt32(4,!0),s=n.getInt32(8,!0);if(i<12)throw new fe(`Invalid directory offset: ${i}`);if(s<=0||s%64!==0)throw new fe(`Invalid directory length: ${s}`);if(i+s>r.byteLength)throw new fe("Directory exceeds buffer length");let c=s/64,l=[],u=new Map;for(let d=0;d<c;d+=1){let f=i+d*64,p=Qa(n,f,56),y=U(p),h=n.getInt32(f+56,!0),g=n.getInt32(f+60,!0);if(h<0||g<0||h+g>r.byteLength)throw new fe(`Invalid entry bounds for ${p||"<unnamed>"} (offset=${h}, length=${g})`);if(!y)throw new fe(`Entry ${d} has an empty name`);let b={name:y,offset:h,length:g};u.set(y,b)}return l.push(...u.values()),new t(e,r,l,us(new Uint8Array(r)))}getEntry(e){return this.entries.get(U(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 ds(t){return us(new Uint8Array(t))}var Fn=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=U(r.name);this.files.set(n,{archive:e,entry:r})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(U(e))}stat(e){let r=this.files.get(U(e));if(r)return{path:r.entry.name,size:r.entry.length,sourcePak:r.archive.name}}async readFile(e){let r=this.files.get(U(e));if(!r)throw new Error(`File not found in VFS: ${e}`);return r.archive.readFile(e)}list(e=""){let r=U(e).replace(/\/+$|^\//g,""),n=[],o=new Set,i=r?`${r}/`:"";for(let s of this.files.values()){if(r&&!s.entry.name.startsWith(i))continue;let a=r?s.entry.name.slice(i.length):s.entry.name,c=a.indexOf("/");c===-1?n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}):o.add(a.slice(0,c))}return n.sort((s,a)=>s.path.localeCompare(a.path)),{files:n,directories:[...o].sort()}}findByExtension(e){let r=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let o of this.files.values())o.entry.name.toLowerCase().endsWith(r)&&n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name});return n.sort((o,i)=>o.path.localeCompare(i.path))}};var Qo=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"}]),xt=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"}},In=class{constructor(e=Qo){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")),o=e.checksum,i="size"in e?e.size:void 0,s=this.known.get(n);return s?s.checksum!==o?{name:n,checksum:o,expectedChecksum:s.checksum,status:"mismatch",size:i,description:s.description}:{name:n,checksum:o,expectedChecksum:s.checksum,status:"valid",size:i,description:s.description}:{name:n,checksum:o,status:"unknown",size:i}}assertValid(e,r){let n=this.validateArchive(e,r);if(n.status==="mismatch")throw new xt(n);return n}normalizePakName(e){let r=U(e),n=r.split("/"),o=n.pop()??r,i=n.pop();return i?`${o}@${i}`:o}};var Je=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 tc(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 o=new FileReader;o.onerror=()=>n(o.error??new Error("Unknown FileReader error")),o.onprogress=i=>{e?.({file:"blob",loadedBytes:i.loaded,totalBytes:i.total||t.size,state:"reading"})},o.onload=()=>{let i=o.result;i instanceof ArrayBuffer?r(i):n(new Error("Unexpected FileReader result"))},o.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=[],o=0;for(;;){let{done:a,value:c}=await r.read();if(a)break;if(!c)continue;let l=c;n.push(l),o+=l.byteLength,e?.({file:"blob",loadedBytes:o,totalBytes:t.size,state:"reading"})}let i=new Uint8Array(o),s=0;for(let a of n)i.set(a,s),s+=a.byteLength;return i.buffer}throw new Je("blob",new Error("Unsupported Blob type"))}async function rc(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 tc(t.data,o=>e?.({...o,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 kn(t,e,r){let n=typeof r=="function"?{onProgress:r}:r??{},o=n.persistIndexes??!!n.pakIndexStore,i=n.enforceValidation??!!n.validator,s=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let u=await rc(l,n.onProgress),d=Vt.fromArrayBuffer(l.name,u),f=n.validator?.validateArchive(d);if(f){n.onValidationResult?.(f);let p=f.status==="mismatch",y=f.status==="unknown";if(p&&i||y&&!s){let h=new xt(f);if(n.onError?.(l.name,h),a)throw new Je(l.name,h);c.push({archive:d,mounted:!1,validation:f});continue}}if(t.mountPak(d),o&&n.pakIndexStore)try{await n.pakIndexStore.persist(d)}catch(p){if(n.onError?.(l.name,p),a)throw new Je(l.name,p)}n.onProgress?.({file:l.name,loadedBytes:u.byteLength,totalBytes:u.byteLength,state:"parsed"}),c.push({archive:d,mounted:!0,validation:f})}catch(u){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,u),a)throw new Je(l.name,u)}return c}var Qe=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 nc(t){return Array.isArray(t)?t:Array.from(t)}function Zo(t){return nc(t).map(e=>({name:e.name,data:e}))}async function ms(t,e,r){let n=Zo(e);return kn(t,n,r??{})}function fs(t,e){let r=o=>{o.preventDefault(),o.dataTransfer?.dropEffect&&(o.dataTransfer.dropEffect="copy")},n=o=>{o.preventDefault();let i=o.dataTransfer?.files;i&&i.length>0&&e(Array.from(i))};return t.addEventListener("dragover",r),t.addEventListener("drop",n),()=>{t.removeEventListener("dragover",r),t.removeEventListener("drop",n)}}function ps(t,e){let r=n=>{let o=n.target;!o||!o.files||o.files.length===0||(e(o.files),o.value="")};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}var oc=844121161,ic=8,hs=68,sc=[{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}],K=class extends Error{},Ut=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 ys(t,e,r){let n=[];for(let o=0;o<r;o+=1){let i=t.getUint8(e+o);if(i===0)break;n.push(i)}return String.fromCharCode(...n)}function br(t,e,r,n){if(r!==0&&(e<hs||e+r>t.byteLength))throw new K(`${n} section is out of bounds`)}function ac(t){if(t.byteLength<hs)throw new K("MD2 buffer too small to contain header");let e=new DataView(t),r=e.getInt32(0,!0),n=e.getInt32(4,!0);if(r!==oc)throw new K(`Invalid MD2 ident: ${r}`);if(n!==ic)throw new K(`Unsupported MD2 version: ${n}`);let o={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)},i=40+o.numVertices*4;if(o.frameSize!==i)throw new K(`Unexpected frame size ${o.frameSize}, expected ${i}`);if(o.offsetEnd>t.byteLength)throw new K("MD2 offset_end exceeds buffer length");return o}function cc(t,e){let r=e.numSkins*64;br(t,e.offsetSkins,r,"skins");let n=new DataView(t,e.offsetSkins,r),o=[];for(let i=0;i<e.numSkins;i+=1)o.push({name:ys(n,i*64,64)});return o}function lc(t,e){let r=e.numTexCoords*4;br(t,e.offsetTexCoords,r,"texcoords");let n=new DataView(t,e.offsetTexCoords,r),o=[];for(let i=0;i<e.numTexCoords;i+=1){let s=i*4;o.push({s:n.getInt16(s,!0),t:n.getInt16(s+2,!0)})}return o}function uc(t,e){let r=e.numTriangles*12;br(t,e.offsetTriangles,r,"triangles");let n=new DataView(t,e.offsetTriangles,r),o=[];for(let i=0;i<e.numTriangles;i+=1){let s=i*12,a=[n.getUint16(s,!0),n.getUint16(s+2,!0),n.getUint16(s+4,!0)],c=[n.getUint16(s+6,!0),n.getUint16(s+8,!0),n.getUint16(s+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new K("Triangle references out of range vertex or texcoord");o.push({vertexIndices:a,texCoordIndices:c})}return o}function dc(t,e){let r=e.numFrames*e.frameSize;br(t,e.offsetFrames,r,"frames");let n=[];for(let o=0;o<e.numFrames;o+=1){let i=e.offsetFrames+o*e.frameSize,s=new DataView(t,i,e.frameSize),a={x:s.getFloat32(0,!0),y:s.getFloat32(4,!0),z:s.getFloat32(8,!0)},c={x:s.getFloat32(12,!0),y:s.getFloat32(16,!0),z:s.getFloat32(20,!0)},l=ys(s,24,16),u=[];for(let d=0;d<e.numVertices;d+=1){let f=40+d*4,p={x:s.getUint8(f)*a.x+c.x,y:s.getUint8(f+1)*a.y+c.y,z:s.getUint8(f+2)*a.z+c.z},y=s.getUint8(f+3),h=sc[y];if(!h)throw new K(`Invalid normal index ${y} in frame ${l}`);u.push({position:p,normalIndex:y,normal:h})}n.push({name:l,vertices:u})}return n}function mc(t,e){let r=e.numGlCommands*4;if(br(t,e.offsetGlCommands,r,"gl commands"),r===0)return[];let n=new DataView(t,e.offsetGlCommands,r),o=[],i=0;for(;;){if(i+4>r)throw new K("GL command list ended unexpectedly");let s=n.getInt32(i,!0);if(i+=4,s===0)break;let a=Math.abs(s),c=[],l=a*12;if(i+l>r)throw new K("GL command vertex block exceeds buffer");for(let u=0;u<a;u+=1){let d=n.getFloat32(i,!0),f=n.getFloat32(i+4,!0),p=n.getInt32(i+8,!0);if(i+=12,p<0||p>=e.numVertices)throw new K("GL command references invalid vertex index");c.push({s:d,t:f,vertexIndex:p})}o.push({mode:s>0?"strip":"fan",vertices:c})}if(i!==r)throw new K("GL command list did not consume expected data");return o}function ei(t){let e=ac(t),r=cc(t,e),n=lc(t,e),o=uc(t,e),i=dc(t,e),s=mc(t,e);return{header:e,skins:r,texCoords:n,triangles:o,frames:i,glCommands:s}}function gs(t){let e=[],r=0;for(;r<t.length;){let n=t[r].name,o=n.replace(/\d+$/,"")||n,i=r;for(;i+1<t.length&&(t[i+1].name.replace(/\d+$/,"")||t[i+1].name)===o;)i+=1;e.push({name:o,firstFrame:r,lastFrame:i}),r=i+1}return e}var xs=860898377,fc=15,pe=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Sr(t,e,r){let n=new Uint8Array(t.buffer,t.byteOffset+e,r);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function pc(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 Rn(t,e,r,n){if(e<0||e+r>n)throw new pe(`${t} exceeds buffer bounds`)}function hc(t){let e=t.getInt32(0,!0);if(e!==xs)throw new pe(`Invalid MD3 ident: ${e}`);let r=t.getInt32(4,!0);if(r!==fc)throw new pe(`Unsupported MD3 version: ${r}`);let n=Sr(t,8,64),o=t.getInt32(72,!0),i=t.getInt32(76,!0),s=t.getInt32(80,!0),a=t.getInt32(84,!0),c=t.getInt32(88,!0),l=t.getInt32(92,!0),u=t.getInt32(96,!0),d=t.getInt32(100,!0),f=t.getInt32(104,!0);if(i<=0||a<0||s<0)throw new pe("Invalid MD3 counts");return{ident:e,version:r,name:n,flags:o,numFrames:i,numTags:s,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:u,ofsSurfaces:d,ofsEnd:f}}function yc(t,e){let r=[];Rn("Frames",e.ofsFrames,e.numFrames*56,t.byteLength);for(let o=0;o<e.numFrames;o+=1){let i=e.ofsFrames+o*56;r.push({minBounds:{x:t.getFloat32(i,!0),y:t.getFloat32(i+4,!0),z:t.getFloat32(i+8,!0)},maxBounds:{x:t.getFloat32(i+12,!0),y:t.getFloat32(i+16,!0),z:t.getFloat32(i+20,!0)},localOrigin:{x:t.getFloat32(i+24,!0),y:t.getFloat32(i+28,!0),z:t.getFloat32(i+32,!0)},radius:t.getFloat32(i+36,!0),name:Sr(t,i+40,16)})}return r}function gc(t,e){let r=[],o=e.numFrames*e.numTags*112;Rn("Tags",e.ofsTags,o,t.byteLength);for(let i=0;i<e.numFrames;i+=1){let s=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(i*e.numTags+a)*112,l=c+64,u=l+12;s.push({name:Sr(t,c,64),origin:{x:t.getFloat32(l,!0),y:t.getFloat32(l+4,!0),z:t.getFloat32(l+8,!0)},axis:[{x:t.getFloat32(u,!0),y:t.getFloat32(u+4,!0),z:t.getFloat32(u+8,!0)},{x:t.getFloat32(u+12,!0),y:t.getFloat32(u+16,!0),z:t.getFloat32(u+20,!0)},{x:t.getFloat32(u+24,!0),y:t.getFloat32(u+28,!0),z:t.getFloat32(u+32,!0)}]})}r.push(s)}return r}function xc(t,e){let r=t.getInt32(e,!0);if(r!==xs)throw new pe(`Invalid surface ident at ${e}: ${r}`);let n=Sr(t,e+4,64),o=t.getInt32(e+68,!0),i=t.getInt32(e+72,!0),s=t.getInt32(e+76,!0),a=t.getInt32(e+80,!0),c=t.getInt32(e+84,!0),l=t.getInt32(e+88,!0),u=t.getInt32(e+92,!0),d=t.getInt32(e+96,!0),f=t.getInt32(e+100,!0),p=t.getInt32(e+104,!0);if(i<=0||a<=0||c<=0)throw new pe(`Invalid surface counts for ${n}`);let y=p;Rn(`Surface ${n}`,e,y,t.byteLength);let h=[],g=e+l;for(let X=0;X<c;X+=1){let oe=g+X*12;h.push({indices:[t.getInt32(oe,!0),t.getInt32(oe+4,!0),t.getInt32(oe+8,!0)]})}let b=[],T=e+u;for(let X=0;X<s;X+=1){let oe=T+X*68;b.push({name:Sr(t,oe,64),shaderIndex:t.getInt32(oe+64,!0)})}let P=[],ne=e+d;for(let X=0;X<a;X+=1){let oe=ne+X*8;P.push({s:t.getFloat32(oe,!0),t:t.getFloat32(oe+4,!0)})}let Y=[],Ht=e+f;for(let X=0;X<i;X+=1){let oe=[];for(let fr=0;fr<a;fr+=1){let Dt=Ht+(X*a+fr)*8,No=t.getInt16(Dt,!0)/64,Oo=t.getInt16(Dt+2,!0)/64,Bo=t.getInt16(Dt+4,!0)/64,Sn=t.getUint16(Dt+6,!0);oe.push({position:{x:No,y:Oo,z:Bo},latLng:Sn,normal:pc(Sn)})}Y.push(oe)}return{surface:{name:n,flags:o,numFrames:i,shaders:b,triangles:h,texCoords:P,vertices:Y},nextOffset:e+p}}function ti(t){if(t.byteLength<108)throw new pe("MD3 buffer too small for header");let e=new DataView(t),r=hc(e);Rn("MD3 end",r.ofsEnd,0,t.byteLength);let n=yc(e,r),o=gc(e,r),i=[],s=r.ofsSurfaces;for(let a=0;a<r.numSurfaces;a+=1){let{surface:c,nextOffset:l}=xc(e,s);i.push(c),s=l}if(s!==r.ofsEnd)throw new pe("Surface parsing did not reach ofsEnd");return{header:r,frames:n,tags:o,surfaces:i}}var Gt=class{constructor(e){this.vfs=e}async load(e){let r=await this.vfs.readFile(e);return ti(r.slice().buffer)}};function bs(t,e){let r=(t.sequence.end-t.sequence.start+1)/t.sequence.fps,n=t.sequence.loop!==!1,o=t.time+e;return n?o=(o%r+r)%r:o>r&&(o=r),{...t,time:Math.max(0,Math.min(o,r))}}function Ss(t){let e=t.sequence.end-t.sequence.start+1,r=1/t.sequence.fps,n=t.sequence.loop!==!1,o=t.time/r;if(!n&&o>=e)return{frame:t.sequence.end,nextFrame:t.sequence.end,lerp:0};let i=n?o%e:Math.min(o,e-1),s=Math.floor(i),a=t.sequence.start+s,c=s+1>=e?n?t.sequence.start:t.sequence.end:a+1,l=!n&&s>=e-1?0:i-s;return{frame:a,nextFrame:c,lerp:l}}function vs(t){return{sequence:t,time:0}}function _s(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 vr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function Hn(t){if(t.byteLength<100)throw new vr("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(),o=e.getInt32(32,!0),i=e.getInt32(36,!0),s=[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),u=e.getInt32(92,!0),d=e.getInt32(96,!0);if(o<=0||i<=0)throw new vr("Invalid WAL dimensions");let f=[],p=o,y=i;for(let h=0;h<s.length;h+=1){let g=s[h],b=Math.max(1,p*y|0);if(g<=0||g+b>t.byteLength)throw new vr(`Invalid WAL mip offset for level ${h}`);let T=new Uint8Array(t,g,b);f.push({level:h,width:p,height:y,data:T}),p=Math.max(1,p>>1),y=Math.max(1,y>>1)}return{name:n,width:o,height:i,mipmaps:f,animName:c,flags:l,contents:u,value:d}}var bt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function As(t){if(t.byteLength<128)throw new bt("PCX buffer too small for header");let e=new DataView(t),r=e.getUint8(0),n=e.getUint8(2),o=e.getUint8(3),i=e.getUint16(4,!0),s=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(r!==10||n!==1)throw new bt("Unsupported PCX encoding");if(o!==8)throw new bt("Only 8bpp PCX files are supported");let l=a-i+1,u=c-s+1,d=e.getUint16(66,!0),f=t.byteLength-769;if(f<128||new DataView(t,f,1).getUint8(0)!==12)throw new bt("Missing PCX palette");let p=new Uint8Array(t,f+1,768),y=new Uint8Array(t,128,f-128),h=new Uint8Array(l*u),g=0,b=0;for(let T=0;T<u;T+=1){let P=0;for(;P<d&&g<y.length;){let ne=1,Y=y[g++];if((Y&192)===192){if(ne=Y&63,g>=y.length)throw new bt("Unexpected end of PCX RLE data");Y=y[g++]}for(let Ht=0;Ht<ne&&P<d;Ht+=1)P<l&&(h[b++]=Y),P+=1}}return{width:l,height:u,bitsPerPixel:o,pixels:h,palette:p}}function Dn(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],o=n*3,i=r*4;e[i]=t.palette[o],e[i+1]=t.palette[o+1],e[i+2]=t.palette[o+2],e[i+3]=n===255?0:255}return e}var Wt=class{constructor(e={}){this.cache=new Qe(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 ri(t,e){let r=[];for(let n of t.mipmaps){let o=new Uint8Array(n.width*n.height*4);for(let i=0;i<n.data.length;i+=1){let s=n.data[i],a=s*3,c=i*4;o[c]=e[a],o[c+1]=e[a+1],o[c+2]=e[a+2],o[c+3]=s===255?0:255}r.push({level:n.level,width:n.width,height:n.height,rgba:o})}return{width:t.width,height:t.height,levels:r,source:"wal"}}function ws(t){let e=Dn(t),r={level:0,width:t.width,height:t.height,rgba:e};return{width:t.width,height:t.height,levels:[r],source:"pcx"}}function Ms(t,e){return ri(Hn(t),e)}var St=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function ni(t,e,r){return new TextDecoder("ascii").decode(new Uint8Array(t.buffer,t.byteOffset+e,r))}function Nn(t){if(t.byteLength<44)throw new St("WAV buffer too small");let e=new DataView(t);if(ni(e,0,4)!=="RIFF"||ni(e,8,4)!=="WAVE")throw new St("Invalid WAV header");let r=12,n=-1,o=-1,i=0,s=0;for(;r+8<=t.byteLength;){let y=ni(e,r,4),h=e.getUint32(r+4,!0),g=r+8;y==="fmt "?(n=g,i=h):y==="data"&&(o=g,s=h),r=g+h}if(n===-1||o===-1)throw new St("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),u=e.getUint16(n+14,!0);if(a!==1)throw new St("Only PCM WAV is supported");let d=u/8,f=s/(d*c),p=new Float32Array(f*c);for(let y=0;y<f;y+=1)for(let h=0;h<c;h+=1){let g=y*c+h,b=o+g*d,T=0;if(u===8)T=e.getUint8(b),p[g]=(T-128)/128;else if(u===16)T=e.getInt16(b,!0),p[g]=T/32768;else if(u===24){let P=e.getUint8(b),ne=e.getUint8(b+1),Y=e.getInt8(b+2);T=P|ne<<8|Y<<16,p[g]=T/8388608}else throw new St(`Unsupported bitsPerSample: ${u}`)}return{sampleRate:l,channels:c,bitsPerSample:u,samples:p}}var bc=(t,e=4294967295,r=79764919)=>{let n=new Int32Array(256),o,i,s,a=e;for(o=0;o<256;o++){for(s=o<<24,i=8;i>0;--i)s=2147483648&s?s<<1^r:s<<1;n[o]=s}for(o=0;o<t.length;o++)a=a<<8^n[255&(a>>24^t[o])];return a};var oi=(t,e=bc)=>{let r=g=>new Uint8Array(g.length/2).map(((b,T)=>parseInt(g.substring(2*T,2*(T+1)),16))),n=g=>r(g)[0],o=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach(((g,b)=>o.set(g,b)));let i=new Uint8Array(t.length),s,a,c,l=!1,u=0,d=42,f=t.length>13&&t.substring(0,9)==="dynEncode",p=0;f&&(p=11,a=n(t.substring(9,p)),a<=1&&(p+=2,d=n(t.substring(11,p))),a===1&&(p+=8,c=(g=>new DataView(r(g).buffer).getInt32(0,!0))(t.substring(13,p))));let y=256-d;for(let g=p;g<t.length;g++)if(s=t.charCodeAt(g),s!==61||l){if(s===92&&g<t.length-5&&f){let b=t.charCodeAt(g+1);b!==117&&b!==85||(s=parseInt(t.substring(g+2,g+6),16),g+=5)}if(s>255){let b=o.get(s);b&&(s=b+127)}l&&(l=!1,s-=64),i[u++]=s<d&&s>0?s+y:s-d}else l=!0;let h=i.subarray(0,u);if(f&&a===1){let g=e(h);if(g!==c){let b="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",b+`
|
|
1
|
+
"use strict";var Quake2Engine=(()=>{var $a=Object.create;var Fn=Object.defineProperty;var Ja=Object.getOwnPropertyDescriptor;var Qa=Object.getOwnPropertyNames;var Za=Object.getPrototypeOf,ec=Object.prototype.hasOwnProperty;var tc=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),rc=(r,e)=>{for(var t in e)Fn(r,t,{get:e[t],enumerable:!0})},ds=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Qa(e))!ec.call(r,o)&&o!==t&&Fn(r,o,{get:()=>e[o],enumerable:!(n=Ja(e,o))||n.enumerable});return r};var nc=(r,e,t)=>(t=r!=null?$a(Za(r)):{},ds(e||!r||!r.__esModule?Fn(t,"default",{value:r,enumerable:!0}):t,r)),oc=r=>ds(Fn({},"__esModule",{value:!0}),r);var Gs=tc((Zu,Us)=>{"use strict";Us.exports=Worker});var Nl={};rc(Nl,{ATTN_IDLE:()=>va,ATTN_LOOP_NONE:()=>xa,ATTN_NONE:()=>Co,ATTN_NORM:()=>ba,ATTN_STATIC:()=>Sa,AssetDependencyError:()=>Nt,AssetDependencyTracker:()=>An,AssetManager:()=>wo,AudioApi:()=>Oo,AudioContextController:()=>To,AudioRegistry:()=>fr,AudioRegistryError:()=>vn,AudioSystem:()=>Do,BSP_SURFACE_FRAGMENT_SOURCE:()=>Ni,BSP_SURFACE_VERTEX_SOURCE:()=>Bi,BSP_VERTEX_LAYOUT:()=>Di,BspSurfacePipeline:()=>Vo,ConfigStringRegistry:()=>Xt,Cvar:()=>Mr,CvarRegistry:()=>On,EngineHost:()=>Wt,EngineRuntime:()=>Ar,FixedTimestepLoop:()=>At,Framebuffer:()=>Bo,IndexBuffer:()=>we,LruCache:()=>it,MAX_SOUND_CHANNELS:()=>Pi,MD2_FRAGMENT_SHADER:()=>Ki,MD2_VERTEX_SHADER:()=>qi,MD3_FRAGMENT_SHADER:()=>es,MD3_VERTEX_SHADER:()=>Zi,Md2Loader:()=>Kt,Md2MeshBuffers:()=>Go,Md2ParseError:()=>j,Md2Pipeline:()=>Wo,Md3Loader:()=>Yt,Md3ModelMesh:()=>Xo,Md3ParseError:()=>xe,Md3Pipeline:()=>qo,Md3SurfaceMesh:()=>Cn,MusicSystem:()=>Ho,PARTICLE_FRAGMENT_SHADER:()=>rs,PARTICLE_VERTEX_SHADER:()=>ts,PakArchive:()=>qt,PakIndexStore:()=>Mo,PakIngestionError:()=>ot,PakParseError:()=>ge,PakValidationError:()=>Mt,PakValidator:()=>Nn,ParticleRenderer:()=>Yo,ParticleSystem:()=>Ko,RERELEASE_KNOWN_PAKS:()=>si,SKYBOX_FRAGMENT_SHADER:()=>Wi,SKYBOX_VERTEX_SHADER:()=>Gi,SOUND_FULLVOLUME:()=>pr,SOUND_LOOP_ATTENUATE:()=>_a,ShaderProgram:()=>ie,SkyboxPipeline:()=>Uo,SoundChannel:()=>Lo,SoundPrecache:()=>Po,SoundRegistry:()=>Fo,Texture2D:()=>hr,TextureCache:()=>jt,TextureCubeMap:()=>yr,VertexArray:()=>le,VertexBuffer:()=>se,VirtualFileSystem:()=>Bn,advanceAnimation:()=>ks,applySurfaceState:()=>Ra,attenuationToDistanceMultiplier:()=>Vt,boxIntersectsFrustum:()=>wn,buildBspGeometry:()=>Ca,buildMd2Geometry:()=>Yi,buildMd2VertexData:()=>ji,buildMd3SurfaceGeometry:()=>Ji,buildMd3VertexData:()=>Qi,calculateMaxAudibleDistance:()=>Eo,calculatePakChecksum:()=>Cs,computeFrameBlend:()=>Ds,computeSkyScroll:()=>Ha,createAnimationState:()=>Hs,createAudioGraph:()=>zo,createEngine:()=>Bl,createEngineRuntime:()=>ws,createInitialChannels:()=>Io,createProgramFromSources:()=>La,createWebGLContext:()=>Ma,decodeOgg:()=>Ao,deriveSurfaceRenderState:()=>Ui,extractFrustumPlanes:()=>Ea,filesToPakSources:()=>ai,findLeafForPoint:()=>Oi,gatherVisibleFaces:()=>Pa,groupMd2Animations:()=>Is,ingestPakFiles:()=>Es,ingestPaks:()=>Vn,interpolateMd3Tag:()=>Ba,interpolateVec3:()=>Os,parseMd2:()=>ci,parseMd3:()=>li,parsePcx:()=>Bs,parseWal:()=>Gn,parseWalTexture:()=>Vs,parseWav:()=>Xn,pcxToRgba:()=>Wn,pickChannel:()=>Ro,preparePcxTexture:()=>Ns,removeViewTranslation:()=>Da,resolveLightStyles:()=>Vi,spatializeOrigin:()=>ko,spawnBlood:()=>Ua,spawnBulletImpact:()=>Na,spawnExplosion:()=>Va,spawnMuzzleFlash:()=>Wa,spawnTeleportFlash:()=>Ga,spawnTrail:()=>Xa,walToRgba:()=>ui,wireDropTarget:()=>Ts,wireFileInput:()=>zs});var ic=()=>typeof performance<"u"?performance.now():Date.now(),sc=r=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>r()):setTimeout(r,25)},At=class{constructor(e,t={}){this.callbacks=e;this.accumulatorMs=0;this.frame=0;this.running=!1;this.tick=()=>{if(!this.running)return;let e=this.options.now(),t=this.lastTimeMs===void 0?0:e-this.lastTimeMs;this.lastTimeMs=e,this.advance(t,e),this.running&&this.options.schedule(this.tick)};let n=t.fixedDeltaMs??25,o=t.maxSubSteps??5;this.options={fixedDeltaMs:n,maxSubSteps:o,maxDeltaMs:t.maxDeltaMs??n*o,startTimeMs:t.startTimeMs,now:t.now??ic,schedule:t.schedule??sc}}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 t=(this.lastTimeMs??0)+e;this.lastTimeMs=t,this.advance(e,t)}isRunning(){return this.running}get frameNumber(){return this.frame}advance(e,t){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 o=0;for(;this.accumulatorMs>=this.options.fixedDeltaMs&&o<this.options.maxSubSteps;)this.frame+=1,this.callbacks.simulate({frame:this.frame,deltaMs:this.options.fixedDeltaMs,nowMs:t}),this.accumulatorMs-=this.options.fixedDeltaMs,o+=1;let i=this.options.fixedDeltaMs===0?0:this.accumulatorMs/this.options.fixedDeltaMs;this.callbacks.render?.({alpha:i,nowMs:t,accumulatorMs:this.accumulatorMs,frame:this.frame})}};var Wt=class{constructor(e,t,n={}){this.game=e;this.client=t;this.started=!1;this.stepSimulation=e=>{this.previousFrame=this.latestFrame,this.latestFrame=this.game.frame(e)};this.renderClient=e=>{this.client&&this.client.render({...e,previous:this.previousFrame,latest:this.latestFrame})};let o=n.loop?.now?.()??Date.now();this.startTimeMs=n.startTimeMs??n.loop?.startTimeMs??o,this.loop=new At({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 ms={x:0,y:0,z:0};var Xl=Math.PI/180;function fs(r,e){return{x:r.x-e.x,y:r.y-e.y,z:r.z-e.z}}function ac(r,e){return{x:r.x*e,y:r.y*e,z:r.z*e}}function $o(r,e){return r.x*e.x+r.y*e.y+r.z*e.z}function cc(r){return $o(r,r)}function Jo(r){return Math.sqrt(cc(r))}function Ee(r){let e=Jo(r);return e===0?r:ac(r,1/e)}var ql=Math.PI/180,Kl=180/Math.PI;function lc(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function ps(r,e){let t=e.x,n=e.y,o=e.z;return{x:r[0]*t+r[4]*n+r[8]*o+r[12],y:r[1]*t+r[5]*n+r[9]*o+r[13],z:r[2]*t+r[6]*n+r[10]*o+r[14]}}function hs(r,e){let t=lc();return t[0]=e[0].x,t[1]=e[0].y,t[2]=e[0].z,t[4]=e[1].x,t[5]=e[1].y,t[6]=e[1].z,t[8]=e[2].x,t[9]=e[2].y,t[10]=e[2].z,t[12]=r.x,t[13]=r.y,t[14]=r.z,t}var Re=1,nt=2;var Qo=8,Zo=16,uc=32;var dc=16384;var Pn=65536,ys=1<<17,mc=1<<18,fc=1<<19,pc=1<<20,hc=1<<21,yc=1<<22,gc=1<<23,Yl=1<<24,In=1<<25,xc=1<<26,jl=1<<27,$l=1<<28,Jl=1<<29,Rn=1<<30,Ql=1<<31;var _r=0;var gs=4,xs=8,bs=16,vs=32,Ss=64;var Zl=1<<25,eu=1<<28,tu=1<<29,ru=1<<30,nu=1<<31;var ou=Re|nt,iu=Re|Pn|nt|In|Rn,su=Re|Pn|nt,au=Re|ys|nt|In|Rn,cu=uc|Qo|Zo,lu=Re|Zo|Qo,bc=Re|In|Rn|nt|xc,uu=mc|fc|pc|hc|yc|gc,du=Re|Qo|Zo|In|Rn,mu=Re|Pn|nt,fu=Re|nt,pu=Re|Pn|nt|ys,hu=bc|dc;var yu=Number.MAX_SAFE_INTEGER-1;var kn=(r=>(r[r.None=0]="None",r[r.Archive=1]="Archive",r[r.UserInfo=2]="UserInfo",r[r.ServerInfo=4]="ServerInfo",r[r.Latch=8]="Latch",r[r.Cheat=16]="Cheat",r))(kn||{});var Dn=256;var ei=256,ti=8192,Hn=2048,ri=512,ni=256,oi=Dn*2,ii=256,jo=32,Sr=96;var R=(r=>(r[r.Name=0]="Name",r[r.CdTrack=1]="CdTrack",r[r.Sky=2]="Sky",r[r.SkyAxis=3]="SkyAxis",r[r.SkyRotate=4]="SkyRotate",r[r.StatusBar=5]="StatusBar",r[r.AirAccel=59]="AirAccel",r[r.MaxClients=60]="MaxClients",r[r.MapChecksum=61]="MapChecksum",r[r.Models=62]="Models",r[r.Sounds=62+ti]="Sounds",r[r.Images=r.Sounds+Hn]="Images",r[r.Lights=r.Images+ri]="Lights",r[r.ShadowLights=r.Lights+ei]="ShadowLights",r[r.Items=r.ShadowLights+ii]="Items",r[r.PlayerSkins=r.Items+ni]="PlayerSkins",r[r.General=r.PlayerSkins+Dn]="General",r[r.WheelWeapons=r.General+oi]="WheelWeapons",r[r.WheelAmmo=r.WheelWeapons+jo]="WheelAmmo",r[r.WheelPowerups=r.WheelAmmo+jo]="WheelPowerups",r[r.CdLoopCount=r.WheelPowerups+jo]="CdLoopCount",r[r.GameStyle=r.CdLoopCount+1]="GameStyle",r[r.MaxConfigStrings=r.GameStyle+1]="MaxConfigStrings",r))(R||{}),_s=R.MaxConfigStrings;function As(r){return r>=5&&r<59?Sr*(59-r):r>=R.General&&r<R.WheelWeapons?Sr*(R.MaxConfigStrings-r):Sr}function vc(r){if(r<0||r>=R.MaxConfigStrings)throw new RangeError(`Configstring index ${r} is out of range (0-${R.MaxConfigStrings-1})`)}function Ms(r,e){let t=As(r);if(e.length>t)throw new RangeError(`Configstring ${r} exceeds maximum length (${e.length} > ${t}); limit is ${Sr} chars per slot`)}var Xt=class{constructor(){this.values=new Map;this.modelCursor=R.Models;this.soundCursor=R.Sounds;this.imageCursor=R.Images;this.lightCursor=R.Lights;this.shadowLightCursor=R.ShadowLights;this.itemCursor=R.Items;this.playerSkinCursor=R.PlayerSkins;this.generalCursor=R.General}set(e,t){return vc(e),Ms(e,t),this.values.set(e,t),e}get(e){return this.values.get(e)}getAll(){let e=new Array(_s).fill("");for(let[t,n]of this.values.entries())e[t]=n;return e}modelIndex(e){return this.register(e,R.Models,ti,"modelCursor")}soundIndex(e){return this.register(e,R.Sounds,Hn,"soundCursor")}findSoundIndex(e){for(let t=R.Sounds;t<R.Sounds+Hn;t+=1)if(this.values.get(t)===e)return t}imageIndex(e){return this.register(e,R.Images,ri,"imageCursor")}lightIndex(e){return this.register(e,R.Lights,ei,"lightCursor")}shadowLightIndex(e){return this.register(e,R.ShadowLights,ii,"shadowLightCursor")}itemIndex(e){return this.register(e,R.Items,ni,"itemCursor")}playerSkinIndex(e){return this.register(e,R.PlayerSkins,Dn,"playerSkinCursor")}generalIndex(e){return this.register(e,R.General,oi,"generalCursor")}register(e,t,n,o){for(let a=t;a<t+n;a+=1)if(this.values.get(a)===e)return a;let i=this[o],s=t+n;if(i>=s)throw new RangeError(`Out of configstring slots for range starting at ${t}`);return Ms(i,e),this.values.set(i,e),this[o]=i+1,i}};var Ar=class{constructor(e,t){this.engine=e;this.host=t;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 ws(r,e,t,n){return new Ar(r,new Wt(e,t,n))}var Mr=class{constructor({name:e,defaultValue:t,description:n,flags:o=kn.None,onChange:i}){this.modifiedCount=0;this.name=e,this.defaultValue=t,this.description=n,this.flags=o,this._value=t,this.onChange=i}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&kn.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 t=this._value;this._value=e,this.modifiedCount+=1,this.onChange?.(this,t)}},On=class{constructor(){this.cvars=new Map}register(e){let t=this.cvars.get(e.name);if(t)return t;let n=new Mr(e);return this.cvars.set(e.name,n),n}get(e){return this.cvars.get(e)}setValue(e,t){let n=this.get(e);if(!n)throw new Error(`Unknown cvar: ${e}`);return n.set(t),n}resetAll(){for(let e of this.cvars.values())e.reset()}applyLatched(){let e=!1;for(let t of this.cvars.values())e=t.applyLatched()||e;return e}list(){return[...this.cvars.values()].sort((e,t)=>e.name.localeCompare(t.name))}};var Sc="PACK";function _c(r,e,t){let n=[];for(let o=0;o<t;o+=1){let i=r.getUint8(e+o);if(i===0)break;n.push(i)}return String.fromCharCode(...n)}function W(r){return r.replace(/\\/g,"/").replace(/^\/+/,"").toLowerCase()}function Ac(){let r=new Uint32Array(256);for(let e=0;e<256;e+=1){let t=e;for(let n=0;n<8;n+=1)t=(t&1)!==0?3988292384^t>>>1:t>>>1;r[e]=t>>>0}return r}var Mc=Ac();function Ls(r){let e=4294967295;for(let t=0;t<r.length;t+=1){let n=r[t];e=Mc[(e^n)&255]^e>>>8}return(e^4294967295)>>>0}var ge=class extends Error{},qt=class r{constructor(e,t,n,o){this.name=e;this.buffer=t;this.entries=new Map(n.map(i=>[i.name,i])),this.checksum=o,this.size=t.byteLength}static fromArrayBuffer(e,t){let n=new DataView(t);if(t.byteLength<12)throw new ge("PAK buffer too small to contain header");let o=String.fromCharCode(n.getUint8(0),n.getUint8(1),n.getUint8(2),n.getUint8(3));if(o!==Sc)throw new ge(`Invalid PAK header magic: ${o}`);let i=n.getInt32(4,!0),s=n.getInt32(8,!0);if(i<12)throw new ge(`Invalid directory offset: ${i}`);if(s<=0||s%64!==0)throw new ge(`Invalid directory length: ${s}`);if(i+s>t.byteLength)throw new ge("Directory exceeds buffer length");let c=s/64,l=[],u=new Map;for(let d=0;d<c;d+=1){let m=i+d*64,p=_c(n,m,56),h=W(p),y=n.getInt32(m+56,!0),g=n.getInt32(m+60,!0);if(y<0||g<0||y+g>t.byteLength)throw new ge(`Invalid entry bounds for ${p||"<unnamed>"} (offset=${y}, length=${g})`);if(!h)throw new ge(`Entry ${d} has an empty name`);let b={name:h,offset:y,length:g};u.set(h,b)}return l.push(...u.values()),new r(e,t,l,Ls(new Uint8Array(t)))}getEntry(e){return this.entries.get(W(e))}listEntries(){return Array.from(this.entries.values())}readFile(e){let t=this.getEntry(e);if(!t)throw new ge(`File not found in PAK: ${e}`);return new Uint8Array(this.buffer,t.offset,t.length)}validate(){return{checksum:this.checksum,entries:this.listEntries()}}};function Cs(r){return Ls(new Uint8Array(r))}var Bn=class{constructor(e=[]){this.mounts=[];this.files=new Map;e.forEach(t=>this.mountPak(t))}mountPak(e){this.mounts.push(e);for(let t of e.listEntries()){let n=W(t.name);this.files.set(n,{archive:e,entry:t})}}get mountedPaks(){return[...this.mounts]}hasFile(e){return this.files.has(W(e))}stat(e){let t=this.files.get(W(e));if(t)return{path:t.entry.name,size:t.entry.length,sourcePak:t.archive.name}}async readFile(e){let t=this.files.get(W(e));if(!t)throw new Error(`File not found in VFS: ${e}`);return t.archive.readFile(e)}list(e=""){let t=W(e).replace(/\/+$|^\//g,""),n=[],o=new Set,i=t?`${t}/`:"";for(let s of this.files.values()){if(t&&!s.entry.name.startsWith(i))continue;let a=t?s.entry.name.slice(i.length):s.entry.name,c=a.indexOf("/");c===-1?n.push({path:s.entry.name,size:s.entry.length,sourcePak:s.archive.name}):o.add(a.slice(0,c))}return n.sort((s,a)=>s.path.localeCompare(a.path)),{files:n,directories:[...o].sort()}}findByExtension(e){let t=e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`,n=[];for(let o of this.files.values())o.entry.name.toLowerCase().endsWith(t)&&n.push({path:o.entry.name,size:o.entry.length,sourcePak:o.archive.name});return n.sort((o,i)=>o.path.localeCompare(i.path))}};var si=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"}]),Mt=class extends Error{constructor(t){super(t.status==="unknown"?`Unknown PAK not allowed: ${t.name}`:`PAK checksum mismatch for ${t.name}`);this.result=t;this.name="PakValidationError"}},Nn=class{constructor(e=si){this.known=new Map;e.forEach(t=>this.known.set(this.normalizePakName(t.name),t))}validateArchive(e,t){let n=this.normalizePakName(t??("name"in e?e.name:"unknown")),o=e.checksum,i="size"in e?e.size:void 0,s=this.known.get(n);return s?s.checksum!==o?{name:n,checksum:o,expectedChecksum:s.checksum,status:"mismatch",size:i,description:s.description}:{name:n,checksum:o,expectedChecksum:s.checksum,status:"valid",size:i,description:s.description}:{name:n,checksum:o,status:"unknown",size:i}}assertValid(e,t){let n=this.validateArchive(e,t);if(n.status==="mismatch")throw new Mt(n);return n}normalizePakName(e){let t=W(e),n=t.split("/"),o=n.pop()??t,i=n.pop();return i?`${o}@${i}`:o}};var ot=class extends Error{constructor(t,n){super(`Failed to ingest PAK: ${t}`);this.file=t;this.name="PakIngestionError",n instanceof Error&&n.stack&&(this.stack=n.stack),this.cause=n}};async function wc(r,e){if(typeof r.arrayBuffer=="function"){let t=await r.arrayBuffer();return e?.({file:"blob",loadedBytes:t.byteLength,totalBytes:t.byteLength,state:"reading"}),t}if(typeof FileReader<"u")return new Promise((t,n)=>{let o=new FileReader;o.onerror=()=>n(o.error??new Error("Unknown FileReader error")),o.onprogress=i=>{e?.({file:"blob",loadedBytes:i.loaded,totalBytes:i.total||r.size,state:"reading"})},o.onload=()=>{let i=o.result;i instanceof ArrayBuffer?t(i):n(new Error("Unexpected FileReader result"))},o.readAsArrayBuffer(r)});if(typeof Response<"u"){let t=await new Response(r).arrayBuffer();return e?.({file:"blob",loadedBytes:t.byteLength,totalBytes:t.byteLength,state:"reading"}),t}if(typeof r.stream=="function"){let t=r.stream().getReader(),n=[],o=0;for(;;){let{done:a,value:c}=await t.read();if(a)break;if(!c)continue;let l=c;n.push(l),o+=l.byteLength,e?.({file:"blob",loadedBytes:o,totalBytes:r.size,state:"reading"})}let i=new Uint8Array(o),s=0;for(let a of n)i.set(a,s),s+=a.byteLength;return i.buffer}throw new ot("blob",new Error("Unsupported Blob type"))}async function Lc(r,e){if(r.data instanceof ArrayBuffer)return e?.({file:r.name,loadedBytes:r.data.byteLength,totalBytes:r.data.byteLength,state:"reading"}),r.data;if(r.data instanceof Blob){let n=r.data.size;return wc(r.data,o=>e?.({...o,file:r.name,totalBytes:n}))}let t=r.data.buffer.slice(r.data.byteOffset,r.data.byteOffset+r.data.byteLength);return e?.({file:r.name,loadedBytes:t.byteLength,totalBytes:t.byteLength,state:"reading"}),t}async function Vn(r,e,t){let n=typeof t=="function"?{onProgress:t}:t??{},o=n.persistIndexes??!!n.pakIndexStore,i=n.enforceValidation??!!n.validator,s=n.allowUnknownPaks??!0,a=n.stopOnError??!1,c=[];for(let l of e)try{let u=await Lc(l,n.onProgress),d=qt.fromArrayBuffer(l.name,u),m=n.validator?.validateArchive(d);if(m){n.onValidationResult?.(m);let p=m.status==="mismatch",h=m.status==="unknown";if(p&&i||h&&!s){let y=new Mt(m);if(n.onError?.(l.name,y),a)throw new ot(l.name,y);c.push({archive:d,mounted:!1,validation:m});continue}}if(r.mountPak(d),o&&n.pakIndexStore)try{await n.pakIndexStore.persist(d)}catch(p){if(n.onError?.(l.name,p),a)throw new ot(l.name,p)}n.onProgress?.({file:l.name,loadedBytes:u.byteLength,totalBytes:u.byteLength,state:"parsed"}),c.push({archive:d,mounted:!0,validation:m})}catch(u){if(n.onProgress?.({file:l.name,loadedBytes:0,totalBytes:0,state:"error"}),n.onError?.(l.name,u),a)throw new ot(l.name,u)}return c}var it=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 t=this.map.get(e);if(t!==void 0)return this.map.delete(e),this.map.set(e,t),t}set(e,t){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,t),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,t])=>({key:e,value:t}))}};function Cc(r){return Array.isArray(r)?r:Array.from(r)}function ai(r){return Cc(r).map(e=>({name:e.name,data:e}))}async function Es(r,e,t){let n=ai(e);return Vn(r,n,t??{})}function Ts(r,e){let t=o=>{o.preventDefault(),o.dataTransfer?.dropEffect&&(o.dataTransfer.dropEffect="copy")},n=o=>{o.preventDefault();let i=o.dataTransfer?.files;i&&i.length>0&&e(Array.from(i))};return r.addEventListener("dragover",t),r.addEventListener("drop",n),()=>{r.removeEventListener("dragover",t),r.removeEventListener("drop",n)}}function zs(r,e){let t=n=>{let o=n.target;!o||!o.files||o.files.length===0||(e(o.files),o.value="")};return r.addEventListener("change",t),()=>r.removeEventListener("change",t)}var Ec=844121161,Tc=8,Fs=68,zc=[{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}],j=class extends Error{},Kt=class{constructor(e){this.vfs=e}async load(e){let t=await this.vfs.readFile(e),n=new Uint8Array(t.byteLength);return n.set(t),ci(n.buffer)}};function Ps(r,e,t){let n=[];for(let o=0;o<t;o+=1){let i=r.getUint8(e+o);if(i===0)break;n.push(i)}return String.fromCharCode(...n)}function wr(r,e,t,n){if(t!==0&&(e<Fs||e+t>r.byteLength))throw new j(`${n} section is out of bounds`)}function Fc(r){if(r.byteLength<Fs)throw new j("MD2 buffer too small to contain header");let e=new DataView(r),t=e.getInt32(0,!0),n=e.getInt32(4,!0);if(t!==Ec)throw new j(`Invalid MD2 ident: ${t}`);if(n!==Tc)throw new j(`Unsupported MD2 version: ${n}`);let o={ident:t,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)},i=40+o.numVertices*4;if(o.frameSize!==i)throw new j(`Unexpected frame size ${o.frameSize}, expected ${i}`);if(o.offsetEnd>r.byteLength)throw new j("MD2 offset_end exceeds buffer length");return o}function Pc(r,e){let t=e.numSkins*64;wr(r,e.offsetSkins,t,"skins");let n=new DataView(r,e.offsetSkins,t),o=[];for(let i=0;i<e.numSkins;i+=1)o.push({name:Ps(n,i*64,64)});return o}function Ic(r,e){let t=e.numTexCoords*4;wr(r,e.offsetTexCoords,t,"texcoords");let n=new DataView(r,e.offsetTexCoords,t),o=[];for(let i=0;i<e.numTexCoords;i+=1){let s=i*4;o.push({s:n.getInt16(s,!0),t:n.getInt16(s+2,!0)})}return o}function Rc(r,e){let t=e.numTriangles*12;wr(r,e.offsetTriangles,t,"triangles");let n=new DataView(r,e.offsetTriangles,t),o=[];for(let i=0;i<e.numTriangles;i+=1){let s=i*12,a=[n.getUint16(s,!0),n.getUint16(s+2,!0),n.getUint16(s+4,!0)],c=[n.getUint16(s+6,!0),n.getUint16(s+8,!0),n.getUint16(s+10,!0)];if(a.some(l=>l>=e.numVertices)||c.some(l=>l>=e.numTexCoords))throw new j("Triangle references out of range vertex or texcoord");o.push({vertexIndices:a,texCoordIndices:c})}return o}function kc(r,e){let t=e.numFrames*e.frameSize;wr(r,e.offsetFrames,t,"frames");let n=[];for(let o=0;o<e.numFrames;o+=1){let i=e.offsetFrames+o*e.frameSize,s=new DataView(r,i,e.frameSize),a={x:s.getFloat32(0,!0),y:s.getFloat32(4,!0),z:s.getFloat32(8,!0)},c={x:s.getFloat32(12,!0),y:s.getFloat32(16,!0),z:s.getFloat32(20,!0)},l=Ps(s,24,16),u=[];for(let d=0;d<e.numVertices;d+=1){let m=40+d*4,p={x:s.getUint8(m)*a.x+c.x,y:s.getUint8(m+1)*a.y+c.y,z:s.getUint8(m+2)*a.z+c.z},h=s.getUint8(m+3),y=zc[h];if(!y)throw new j(`Invalid normal index ${h} in frame ${l}`);u.push({position:p,normalIndex:h,normal:y})}n.push({name:l,vertices:u})}return n}function Dc(r,e){let t=e.numGlCommands*4;if(wr(r,e.offsetGlCommands,t,"gl commands"),t===0)return[];let n=new DataView(r,e.offsetGlCommands,t),o=[],i=0;for(;;){if(i+4>t)throw new j("GL command list ended unexpectedly");let s=n.getInt32(i,!0);if(i+=4,s===0)break;let a=Math.abs(s),c=[],l=a*12;if(i+l>t)throw new j("GL command vertex block exceeds buffer");for(let u=0;u<a;u+=1){let d=n.getFloat32(i,!0),m=n.getFloat32(i+4,!0),p=n.getInt32(i+8,!0);if(i+=12,p<0||p>=e.numVertices)throw new j("GL command references invalid vertex index");c.push({s:d,t:m,vertexIndex:p})}o.push({mode:s>0?"strip":"fan",vertices:c})}if(i!==t)throw new j("GL command list did not consume expected data");return o}function ci(r){let e=Fc(r),t=Pc(r,e),n=Ic(r,e),o=Rc(r,e),i=kc(r,e),s=Dc(r,e);return{header:e,skins:t,texCoords:n,triangles:o,frames:i,glCommands:s}}function Is(r){let e=[],t=0;for(;t<r.length;){let n=r[t].name,o=n.replace(/\d+$/,"")||n,i=t;for(;i+1<r.length&&(r[i+1].name.replace(/\d+$/,"")||r[i+1].name)===o;)i+=1;e.push({name:o,firstFrame:t,lastFrame:i}),t=i+1}return e}var Rs=860898377,Hc=15,xe=class extends Error{constructor(e){super(e),this.name="Md3ParseError"}};function Lr(r,e,t){let n=new Uint8Array(r.buffer,r.byteOffset+e,t);return new TextDecoder("utf-8").decode(n).replace(/\0.*$/,"").trim()}function Oc(r){let e=(r>>8&255)*(2*Math.PI/255),t=(r&255)*(2*Math.PI/255),n=Math.sin(t);return{x:Math.cos(e)*n,y:Math.sin(e)*n,z:Math.cos(t)}}function Un(r,e,t,n){if(e<0||e+t>n)throw new xe(`${r} exceeds buffer bounds`)}function Bc(r){let e=r.getInt32(0,!0);if(e!==Rs)throw new xe(`Invalid MD3 ident: ${e}`);let t=r.getInt32(4,!0);if(t!==Hc)throw new xe(`Unsupported MD3 version: ${t}`);let n=Lr(r,8,64),o=r.getInt32(72,!0),i=r.getInt32(76,!0),s=r.getInt32(80,!0),a=r.getInt32(84,!0),c=r.getInt32(88,!0),l=r.getInt32(92,!0),u=r.getInt32(96,!0),d=r.getInt32(100,!0),m=r.getInt32(104,!0);if(i<=0||a<0||s<0)throw new xe("Invalid MD3 counts");return{ident:e,version:t,name:n,flags:o,numFrames:i,numTags:s,numSurfaces:a,numSkins:c,ofsFrames:l,ofsTags:u,ofsSurfaces:d,ofsEnd:m}}function Nc(r,e){let t=[];Un("Frames",e.ofsFrames,e.numFrames*56,r.byteLength);for(let o=0;o<e.numFrames;o+=1){let i=e.ofsFrames+o*56;t.push({minBounds:{x:r.getFloat32(i,!0),y:r.getFloat32(i+4,!0),z:r.getFloat32(i+8,!0)},maxBounds:{x:r.getFloat32(i+12,!0),y:r.getFloat32(i+16,!0),z:r.getFloat32(i+20,!0)},localOrigin:{x:r.getFloat32(i+24,!0),y:r.getFloat32(i+28,!0),z:r.getFloat32(i+32,!0)},radius:r.getFloat32(i+36,!0),name:Lr(r,i+40,16)})}return t}function Vc(r,e){let t=[],o=e.numFrames*e.numTags*112;Un("Tags",e.ofsTags,o,r.byteLength);for(let i=0;i<e.numFrames;i+=1){let s=[];for(let a=0;a<e.numTags;a+=1){let c=e.ofsTags+(i*e.numTags+a)*112,l=c+64,u=l+12;s.push({name:Lr(r,c,64),origin:{x:r.getFloat32(l,!0),y:r.getFloat32(l+4,!0),z:r.getFloat32(l+8,!0)},axis:[{x:r.getFloat32(u,!0),y:r.getFloat32(u+4,!0),z:r.getFloat32(u+8,!0)},{x:r.getFloat32(u+12,!0),y:r.getFloat32(u+16,!0),z:r.getFloat32(u+20,!0)},{x:r.getFloat32(u+24,!0),y:r.getFloat32(u+28,!0),z:r.getFloat32(u+32,!0)}]})}t.push(s)}return t}function Uc(r,e){let t=r.getInt32(e,!0);if(t!==Rs)throw new xe(`Invalid surface ident at ${e}: ${t}`);let n=Lr(r,e+4,64),o=r.getInt32(e+68,!0),i=r.getInt32(e+72,!0),s=r.getInt32(e+76,!0),a=r.getInt32(e+80,!0),c=r.getInt32(e+84,!0),l=r.getInt32(e+88,!0),u=r.getInt32(e+92,!0),d=r.getInt32(e+96,!0),m=r.getInt32(e+100,!0),p=r.getInt32(e+104,!0);if(i<=0||a<=0||c<=0)throw new xe(`Invalid surface counts for ${n}`);let h=p;Un(`Surface ${n}`,e,h,r.byteLength);let y=[],g=e+l;for(let B=0;B<c;B+=1){let K=g+B*12;y.push({indices:[r.getInt32(K,!0),r.getInt32(K+4,!0),r.getInt32(K+8,!0)]})}let b=[],C=e+u;for(let B=0;B<s;B+=1){let K=C+B*68;b.push({name:Lr(r,K,64),shaderIndex:r.getInt32(K+64,!0)})}let L=[],q=e+d;for(let B=0;B<a;B+=1){let K=q+B*8;L.push({s:r.getFloat32(K,!0),t:r.getFloat32(K+4,!0)})}let G=[],Le=e+m;for(let B=0;B<i;B+=1){let K=[];for(let Ie=0;Ie<a;Ie+=1){let Ce=Le+(B*a+Ie)*8,et=r.getInt16(Ce,!0)/64,br=r.getInt16(Ce+2,!0)/64,Ut=r.getInt16(Ce+4,!0)/64,tt=r.getUint16(Ce+6,!0);K.push({position:{x:et,y:br,z:Ut},latLng:tt,normal:Oc(tt)})}G.push(K)}return{surface:{name:n,flags:o,numFrames:i,shaders:b,triangles:y,texCoords:L,vertices:G},nextOffset:e+p}}function li(r){if(r.byteLength<108)throw new xe("MD3 buffer too small for header");let e=new DataView(r),t=Bc(e);Un("MD3 end",t.ofsEnd,0,r.byteLength);let n=Nc(e,t),o=Vc(e,t),i=[],s=t.ofsSurfaces;for(let a=0;a<t.numSurfaces;a+=1){let{surface:c,nextOffset:l}=Uc(e,s);i.push(c),s=l}if(s!==t.ofsEnd)throw new xe("Surface parsing did not reach ofsEnd");return{header:t,frames:n,tags:o,surfaces:i}}var Yt=class{constructor(e){this.vfs=e}async load(e){let t=await this.vfs.readFile(e);return li(t.slice().buffer)}};function ks(r,e){let t=(r.sequence.end-r.sequence.start+1)/r.sequence.fps,n=r.sequence.loop!==!1,o=r.time+e;return n?o=(o%t+t)%t:o>t&&(o=t),{...r,time:Math.max(0,Math.min(o,t))}}function Ds(r){let e=r.sequence.end-r.sequence.start+1,t=1/r.sequence.fps,n=r.sequence.loop!==!1,o=r.time/t;if(!n&&o>=e)return{frame:r.sequence.end,nextFrame:r.sequence.end,lerp:0};let i=n?o%e:Math.min(o,e-1),s=Math.floor(i),a=r.sequence.start+s,c=s+1>=e?n?r.sequence.start:r.sequence.end:a+1,l=!n&&s>=e-1?0:i-s;return{frame:a,nextFrame:c,lerp:l}}function Hs(r){return{sequence:r,time:0}}function Os(r,e,t){return{x:r.x+(e.x-r.x)*t,y:r.y+(e.y-r.y)*t,z:r.z+(e.z-r.z)*t}}var Cr=class extends Error{constructor(e){super(e),this.name="WalParseError"}};function Gn(r){if(r.byteLength<100)throw new Cr("WAL buffer too small");let e=new DataView(r),t=new Uint8Array(r,0,32),n=new TextDecoder("utf-8").decode(t).replace(/\0.*$/,"").trim(),o=e.getInt32(32,!0),i=e.getInt32(36,!0),s=[e.getInt32(40,!0),e.getInt32(44,!0),e.getInt32(48,!0),e.getInt32(52,!0)],a=new Uint8Array(r,56,32),c=new TextDecoder("utf-8").decode(a).replace(/\0.*$/,"").trim(),l=e.getInt32(88,!0),u=e.getInt32(92,!0),d=e.getInt32(96,!0);if(o<=0||i<=0)throw new Cr("Invalid WAL dimensions");let m=[],p=o,h=i;for(let y=0;y<s.length;y+=1){let g=s[y],b=Math.max(1,p*h|0);if(g<=0||g+b>r.byteLength)throw new Cr(`Invalid WAL mip offset for level ${y}`);let C=new Uint8Array(r,g,b);m.push({level:y,width:p,height:h,data:C}),p=Math.max(1,p>>1),h=Math.max(1,h>>1)}return{name:n,width:o,height:i,mipmaps:m,animName:c,flags:l,contents:u,value:d}}var wt=class extends Error{constructor(e){super(e),this.name="PcxParseError"}};function Bs(r){if(r.byteLength<128)throw new wt("PCX buffer too small for header");let e=new DataView(r),t=e.getUint8(0),n=e.getUint8(2),o=e.getUint8(3),i=e.getUint16(4,!0),s=e.getUint16(6,!0),a=e.getUint16(8,!0),c=e.getUint16(10,!0);if(t!==10||n!==1)throw new wt("Unsupported PCX encoding");if(o!==8)throw new wt("Only 8bpp PCX files are supported");let l=a-i+1,u=c-s+1,d=e.getUint16(66,!0),m=r.byteLength-769;if(m<128||new DataView(r,m,1).getUint8(0)!==12)throw new wt("Missing PCX palette");let p=new Uint8Array(r,m+1,768),h=new Uint8Array(r,128,m-128),y=new Uint8Array(l*u),g=0,b=0;for(let C=0;C<u;C+=1){let L=0;for(;L<d&&g<h.length;){let q=1,G=h[g++];if((G&192)===192){if(q=G&63,g>=h.length)throw new wt("Unexpected end of PCX RLE data");G=h[g++]}for(let Le=0;Le<q&&L<d;Le+=1)L<l&&(y[b++]=G),L+=1}}return{width:l,height:u,bitsPerPixel:o,pixels:y,palette:p}}function Wn(r){let e=new Uint8Array(r.width*r.height*4);for(let t=0;t<r.pixels.length;t+=1){let n=r.pixels[t],o=n*3,i=t*4;e[i]=r.palette[o],e[i+1]=r.palette[o+1],e[i+2]=r.palette[o+2],e[i+3]=n===255?0:255}return e}var jt=class{constructor(e={}){this.cache=new it(e.capacity??128)}get size(){return this.cache.size}get(e){return this.cache.get(e.toLowerCase())}set(e,t){this.cache.set(e.toLowerCase(),t)}clear(){this.cache.clear()}};function ui(r,e){let t=[];for(let n of r.mipmaps){let o=new Uint8Array(n.width*n.height*4);for(let i=0;i<n.data.length;i+=1){let s=n.data[i],a=s*3,c=i*4;o[c]=e[a],o[c+1]=e[a+1],o[c+2]=e[a+2],o[c+3]=s===255?0:255}t.push({level:n.level,width:n.width,height:n.height,rgba:o})}return{width:r.width,height:r.height,levels:t,source:"wal"}}function Ns(r){let e=Wn(r),t={level:0,width:r.width,height:r.height,rgba:e};return{width:r.width,height:r.height,levels:[t],source:"pcx"}}function Vs(r,e){return ui(Gn(r),e)}var Lt=class extends Error{constructor(e){super(e),this.name="WavParseError"}};function di(r,e,t){return new TextDecoder("ascii").decode(new Uint8Array(r.buffer,r.byteOffset+e,t))}function Xn(r){if(r.byteLength<44)throw new Lt("WAV buffer too small");let e=new DataView(r);if(di(e,0,4)!=="RIFF"||di(e,8,4)!=="WAVE")throw new Lt("Invalid WAV header");let t=12,n=-1,o=-1,i=0,s=0;for(;t+8<=r.byteLength;){let h=di(e,t,4),y=e.getUint32(t+4,!0),g=t+8;h==="fmt "?(n=g,i=y):h==="data"&&(o=g,s=y),t=g+y}if(n===-1||o===-1)throw new Lt("Missing fmt or data chunk");let a=e.getUint16(n,!0),c=e.getUint16(n+2,!0),l=e.getUint32(n+4,!0),u=e.getUint16(n+14,!0);if(a!==1)throw new Lt("Only PCM WAV is supported");let d=u/8,m=s/(d*c),p=new Float32Array(m*c);for(let h=0;h<m;h+=1)for(let y=0;y<c;y+=1){let g=h*c+y,b=o+g*d,C=0;if(u===8)C=e.getUint8(b),p[g]=(C-128)/128;else if(u===16)C=e.getInt16(b,!0),p[g]=C/32768;else if(u===24){let L=e.getUint8(b),q=e.getUint8(b+1),G=e.getInt8(b+2);C=L|q<<8|G<<16,p[g]=C/8388608}else throw new Lt(`Unsupported bitsPerSample: ${u}`)}return{sampleRate:l,channels:c,bitsPerSample:u,samples:p}}var Gc=(r,e=4294967295,t=79764919)=>{let n=new Int32Array(256),o,i,s,a=e;for(o=0;o<256;o++){for(s=o<<24,i=8;i>0;--i)s=2147483648&s?s<<1^t:s<<1;n[o]=s}for(o=0;o<r.length;o++)a=a<<8^n[255&(a>>24^r[o])];return a};var mi=(r,e=Gc)=>{let t=g=>new Uint8Array(g.length/2).map(((b,C)=>parseInt(g.substring(2*C,2*(C+1)),16))),n=g=>t(g)[0],o=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach(((g,b)=>o.set(g,b)));let i=new Uint8Array(r.length),s,a,c,l=!1,u=0,d=42,m=r.length>13&&r.substring(0,9)==="dynEncode",p=0;m&&(p=11,a=n(r.substring(9,p)),a<=1&&(p+=2,d=n(r.substring(11,p))),a===1&&(p+=8,c=(g=>new DataView(t(g).buffer).getInt32(0,!0))(r.substring(13,p))));let h=256-d;for(let g=p;g<r.length;g++)if(s=r.charCodeAt(g),s!==61||l){if(s===92&&g<r.length-5&&m){let b=r.charCodeAt(g+1);b!==117&&b!==85||(s=parseInt(r.substring(g+2,g+6),16),g+=5)}if(s>255){let b=o.get(s);b&&(s=b+127)}l&&(l=!1,s-=64),i[u++]=s<d&&s>0?s+h:s-d}else l=!0;let y=i.subarray(0,u);if(m&&a===1){let g=e(y);if(g!==c){let b="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",b+`
|
|
2
2
|
`,"Expected: "+c+"; Got: "+g+`
|
|
3
|
-
`,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(b)}}return h};function D(){let t=Uint8Array,e=Float32Array;D.modules||Object.defineProperties(D,{modules:{value:new WeakMap},setModule:{value(r,n){D.modules.set(r,Promise.resolve(n))}},getModule:{value(r,n){let o=D.modules.get(r);return o||(n?o=WebAssembly.compile(oi(n)):(n=r.wasm,o=D.inflateDynEncodeString(n).then(i=>WebAssembly.compile(i))),D.modules.set(r,o)),o}},concatFloat32:{value(r,n){let o=new e(n),i=0,s=0;for(;i<r.length;)o.set(r[i],s),s+=r[i++].length;return o}},getDecodedAudio:{value:(r,n,o,i,s)=>({errors:r,channelData:n,samplesDecoded:o,sampleRate:i,bitDepth:s})},getDecodedAudioMultiChannel:{value(r,n,o,i,s,a){let c=[],l,u;for(l=0;l<o;l++){let d=[];for(u=0;u<n.length;)d.push(n[u++][l]||[]);c.push(D.concatFloat32(d,i))}return D.getDecodedAudio(r,c,i,s,a)}},inflateDynEncodeString:{value(r){return r=oi(r),new Promise(n=>{let o=String.raw`dynEncode012804c7886d()((()>+*§§)§,§§§§)§+§§§)§+.-()(*)-+)(.7*§)i¸¸,3§(i¸¸,3/G+.¡*(,(,3+)2å:-),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)^*<H,H(P*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)J.H.W)(i)c)(H,i)I,H-i*I-4)33i(I.*hH(V)(H+n5(H(i*I-i(I,i)I.+hH,i*J+iHn,hi(I-i*I,+hH,H/H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)J(H(V)(J(i)c)(H)H(i)H,c)(3H*i*I*H,i)I,4(3(-H(H,W)(H-I-H,i*I,4)3(3(3H,H-I1H+I,H.i)H1V)(J.i(v5(33H.-H(H,i(c)(H,i*I,4)333)-§i*I*+§H*iHn,hi73H,H(i)8(H+J+H)P*(H*V)(J-r,§H)P*,H.i)H+H,i)V)(-H*i*I*H+i)I+H-H.I.H,H-i)I,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7H,c)(i)H+i´8W)(H,I,H+i*I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,H-b((3H(P*0i)I.4)3H-i¨*n5*H-iÅ*s,hi73H-i)J+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)J+i¸7V)(H(H+iø7V)(8(J/H(P*0J+s,hi73H+H,H.J,I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+H.H+H/U((b((H(H(P*0i)J+^*0H,i)I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)c)(H,i*I,H+i)I+4)33i)I-3H-3!2)0§K(i2J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,J(H,P*8J/s50H,H.i+J0^*<i¦I*H.H,P*4J1J.U(*H.U((J2i')o5/H.U()I.H,H(^*<H0H1U((H.i0J.i§i0i')o5/H/H.H2J*H(J.q50H,P*0J/H*I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0H(H1U((b((H/i)I/H(i)I(H*i)I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-H(i0c)(H(i*I(4)33iè1i1H,i-iÈ*8)Bi(I(+hH(ido,hH,i-H(i-c)(H(i*I(4)33iÈ6iè6H,i-iF8)BiØ1i)b((41-H,i-H(i/c)(H(i*I(4)3(3(-H,i-H(i1c)(H(i*I(4)3(3(-H,i-H(i0c)(H(i*I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)^*TH,H,iø-^*PH,H,iX^*LH,H,i(^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iEr5)H(i©*I1H-i)I0i(i;H.i,J(i(H(i(rCJ(J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-H-V)(i)H,i+8(c)(H/i)I/H-i*I-H*i)I*4)-H(i)i¨1I/+hH(H*o,hH,i-H/V)(i)i(c)(H/i*I/H(i)I(4)33i¤I*H,iø-H,i¸)H,i-i;8)5+H0H1I2i(I-+hH-H2p,hH,H,iP8*J*i(p5-H*i7u,hH,i-H-i)H*c)(H-i)I-4*3i(I/i+I.i+I(*h*h*hH*i86*(*)3H-m,hi£I*403H-i)H,W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.J(H-J.p,hi¢I*4.3H,i-H-i)I*+hH(,hH*H/c)(H*i*I*H(i)I(4)-H.I-4+3(3(33H,W)1m,hiI*4,3H,iø-H,i¸)H,i-H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-o5,3H,i(H,iXH,i-H1i)H08)J(,hi I*H(i(p5,H0H,V)H,V)o5,3H,H,iPH,iH8+I*4+3(3(3H,i$6i¬78+I*3H*H3m5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(((«(Ë(ë((*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7*S7US0U `;D.getModule(D,o).then(i=>WebAssembly.instantiate(i,{})).then(({exports:i})=>{let s=new Map(Object.entries(i)),a=s.get("puff"),c=s.get("memory").buffer,l=new t(c),u=new DataView(c),d=s.get("__heap_base"),f=r.length,p=d;d+=4,u.setInt32(p,f,!0);let y=d;d+=f,l.set(r,y);let h=d;d+=4,u.setInt32(h,l.byteLength-d,!0),a(d,h,y,p),n(l.slice(d,d+u.getInt32(h,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(r,n,o)=>{let i=[],s=0;for(;s<n;)i.push(r.slice(s*o,s++*o+o));return i},this.allocateTypedArray=(r,n,o=!0)=>{let i=this._wasm.malloc(n.BYTES_PER_ELEMENT*r);return o&&this._pointers.add(i),{ptr:i,len:r,buf:new n(this._wasm.HEAP,i,r)}},this.free=()=>{this._pointers.forEach(r=>{this._wasm.free(r)}),this._pointers.clear()},this.codeToString=r=>{let n=[],o=new Uint8Array(this._wasm.HEAP);for(let i=o[r];i!==0;i=o[++r])n.push(i);return String.fromCharCode.apply(null,n)},this.addError=(r,n,o,i,s,a)=>{r.push({message:n,frameLength:o,frameNumber:i,inputBytes:s,outputSamples:a})},this.instantiate=(r,n)=>(n&&D.setModule(r,n),this._wasm=new r(D).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Es=ka(Cs(),1);var Sc=()=>globalThis.Worker||Es.default,Xt=class extends Sc(){constructor(e,r,n,o){D.modules||new D;let i=D.modules.get(n);if(!i){let s="text/javascript",a,c=`'use strict';(${((l,u,d)=>{let f,p,y=new Promise(h=>{p=h});self.onmessage=({data:{id:h,command:g,data:b}})=>{let T=y,P={id:h},ne;g==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:u},EmscriptenWASM:{value:d},module:{value:b.module},isWebWorker:{value:!0}}),f=new l(b.options),p()):g==="free"?f.free():g==="ready"?T=T.then(()=>f.ready):g==="reset"?T=T.then(()=>f.reset()):(Object.assign(P,f[g](Array.isArray(b)?b.map(Y=>new Uint8Array(Y)):new Uint8Array(b))),ne=P.channelData?P.channelData.map(Y=>Y.buffer):[]),T.then(()=>self.postMessage(P,ne))}}).toString()})(${n}, ${D}, ${o})`;try{a=typeof process.versions.node<"u"}catch{}i=a?`data:${s};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:s})),D.modules.set(n,i)}super(i,{name:r}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:s})=>{let{id:a,...c}=s;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new o(D).getModule().then(s=>{this.postToDecoder("init",{module:s,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 On=(t,e)=>{Object.defineProperty(t,"name",{value:e})};var N=Symbol,Ts=", ",_=(()=>{let t="front",e="side",r="rear",n="left",o="center",i="right";return["",t+" ",e+" ",r+" "].map(s=>[[n,i],[n,i,o],[n,o,i],[o,n,i],[o]].flatMap(a=>a.map(c=>s+c).join(Ts)))})(),Ee="LFE",Ze="monophonic (mono)",et="stereo",_r="surround",O=(t,...e)=>`${[Ze,et,`linear ${_r}`,"quadraphonic",`5.0 ${_r}`,`5.1 ${_r}`,`6.1 ${_r}`,`7.1 ${_r}`][t-1]} (${e.join(Ts)})`,Ar=[Ze,O(2,_[0][0]),O(3,_[0][2]),O(4,_[1][0],_[3][0]),O(5,_[1][2],_[3][0]),O(6,_[1][2],_[3][0],Ee),O(7,_[1][2],_[2][0],_[3][4],Ee),O(8,_[1][2],_[2][0],_[3][0],Ee)],zs=192e3,Ps=176400,Bn=96e3,Vn=88200,Fs=64e3,tt=48e3,Kt=44100,qt=32e3,$t=24e3,Yt=22050,jt=16e3,Un=12e3,Gn=11025,Jt=8e3,Is=7350,ve="absoluteGranulePosition",M="bandwidth",j="bitDepth",J="bitrate",wr=J+"Maximum",Mr=J+"Minimum",Lr=J+"Nominal",Te="buffer",Cr=Te+"Fullness",H="codec",Q=H+"Frames",Er="coupledStreamCount",Qt="crc",Tr=Qt+"16",zr=Qt+"32",R="data",v="description",ze="duration",Zt="emphasis",Pr="hasOpusPadding",ae="header",rt="isContinuedPacket",Fr="isCopyrighted",nt="isFirstPage",Ir="isHome",ce="isLastPage",De="isOriginal",Ne="isPrivate",kr="isVbr",ie="layer",m="length",w="mode",Oe=w+"Extension",Wn="mpeg",Be=Wn+"Version",Rr="numberAACFrames",Hr="outputGain",vt="preSkip",Dr="profile",Xn=N(),Ve="protection",ii="rawData",he="segments",L="subarray",ot="version",_t="vorbis",Nr=_t+"Comments",er=_t+"Setup",Kn="block",Or=Kn+"ingStrategy",qn=N(),Ue=Kn+"Size",it=Kn+"size0",st=Kn+"size1",Br=N(),$n="channel",Ge=$n+"MappingFamily",Vr=$n+"MappingTable",Z=$n+"Mode",Ur=N(),S=$n+"s",ks="copyright",Gr=ks+"Id",Wr=ks+"IdStart",We="frame",Xe=We+"Count",se=We+"Length",Yn="Number",Ke=We+Yn,Pe=We+"Padding",A=We+"Size",Rs="Rate",Xr="inputSample"+Rs,si="page",At=si+"Checksum",tr=N(),at=si+"SegmentTable",G=si+"Sequence"+Yn,ai="sample",Kr=ai+Yn,C=ai+Rs,Fe=N(),E=ai+"s",jn="stream",qr=jn+"Count",$r=jn+"Info",Ie=jn+"Serial"+Yn,ci=jn+"StructureVersion",li="total",wt=li+"BytesOut",Mt=li+"Duration",Lt=li+"Samples",z=N(),ye=N(),Yr=N(),ct=N(),_e=N(),Jn=N(),ui=N(),lt=N(),F=N(),ge=N(),xe=N(),ke=N(),ut=N(),Qn=N(),Ae=N(),we=N(),be=N(),Zn=N(),ee=Uint8Array,dt=DataView,I="reserved",te="bad",rr="free",jr="none",eo="16bit CRC";var di=(t,e,r)=>{for(let n=0;n<t[m];n++){let o=e(n);for(let i=8;i>0;i--)o=r(o);t[n]=o}return t},_c=di(new ee(256),t=>t,t=>t&128?7^t<<1:t<<1),B=[di(new Uint16Array(256),t=>t<<8,t=>t<<1^(t&32768?32773:0))],V=[di(new Uint32Array(256),t=>t,t=>t>>>1^(t&1)*3988292384)];for(let t=0;t<15;t++){B.push(new Uint16Array(256)),V.push(new Uint32Array(256));for(let e=0;e<=255;e++)B[t+1][e]=B[0][B[t][e]>>>8]^B[t][e]<<8,V[t+1][e]=V[t][e]>>>8^V[0][V[t][e]&255]}var Ds=t=>{let e=0,r=t[m];for(let n=0;n!==r;n++)e=_c[e^t[n]];return e},Ns=t=>{let e=t[m],r=e-16,n=0,o=0;for(;o<=r;)n^=t[o++]<<8|t[o++],n=B[15][n>>8]^B[14][n&255]^B[13][t[o++]]^B[12][t[o++]]^B[11][t[o++]]^B[10][t[o++]]^B[9][t[o++]]^B[8][t[o++]]^B[7][t[o++]]^B[6][t[o++]]^B[5][t[o++]]^B[4][t[o++]]^B[3][t[o++]]^B[2][t[o++]]^B[1][t[o++]]^B[0][t[o++]];for(;o!==e;)n=(n&255)<<8^B[0][n>>8^t[o++]];return n},Os=t=>{let e=t[m],r=e-16,n=0,o=0;for(;o<=r;)n=V[15][(t[o++]^n)&255]^V[14][(t[o++]^n>>>8)&255]^V[13][(t[o++]^n>>>16)&255]^V[12][t[o++]^n>>>24]^V[11][t[o++]]^V[10][t[o++]]^V[9][t[o++]]^V[8][t[o++]]^V[7][t[o++]]^V[6][t[o++]]^V[5][t[o++]]^V[4][t[o++]]^V[3][t[o++]]^V[2][t[o++]]^V[1][t[o++]]^V[0][t[o++]];for(;o!==e;)n=V[0][(n^t[o++])&255]^n>>>8;return n^-1},Qr=(...t)=>{let e=new ee(t.reduce((r,n)=>r+n[m],0));return t.reduce((r,n)=>(e.set(n,r),r+n[m]),0),e},le=t=>String.fromCharCode(...t),Hs=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Jr=t=>Hs[t&15]<<4|Hs[t>>4],to=class{constructor(e){this._data=e,this._pos=e[m]*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,(Jr(this._data[r-1])<<8)+Jr(this._data[r])>>7-n&255}},Bs=(t,e)=>{try{return t.getBigInt64(e,!0)}catch{let r=t.getUint8(e+7)&128?-1:1,n=t.getUint32(e,!0),o=t.getUint32(e+4,!0);return r===-1&&(n=~n+1,o=~o+1),o>1048575&&console.warn("This platform does not support BigInt"),r*(n+o*2**32)}};var Zr=class{constructor(e,r){this._onCodecHeader=e,this._onCodecUpdate=r,this[Ae]()}[we](){this._isEnabled=!0}[Ae](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[Qn](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}}[F](e){let r=this._headerCache.get(e);return r&&this._updateCurrentHeader(e),r}[ge](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 W=new WeakMap,q=new WeakMap;var re=class{constructor(e,r){this._codecParser=e,this._headerCache=r}*[ui](){let e;do{if(e=yield*this.Frame[xe](this._codecParser,this._headerCache,0),e)return e;this._codecParser[ye](1)}while(!0)}*[lt](e){let r=yield*this[ui](),n=q.get(r)[m];if(e||this._codecParser._flushing||(yield*this.Header[F](this._codecParser,this._headerCache,n)))return this._headerCache[we](),this._codecParser[ye](n),this._codecParser[ct](r),r;this._codecParser[_e](`Missing ${We} at ${n} bytes from current position.`,`Dropping current ${We} and trying again.`),this._headerCache[Ae](),this._codecParser[ye](1)}};var Ct=class{constructor(e,r){q.set(this,{[ae]:e}),this[R]=r}};var ue=class extends Ct{static*[xe](e,r,n,o,i){let s=yield*e[F](n,o,i);if(s){let a=W.get(s)[se],c=W.get(s)[E],l=(yield*n[z](a,i))[L](0,a);return new r(s,l,c)}else return null}constructor(e,r,n){super(e,r),this[ae]=e,this[E]=n,this[ze]=n/e[C]*1e3,this[Ke]=null,this[wt]=null,this[Lt]=null,this[Mt]=null,q.get(this)[m]=r[m]}};var mi="unsynchronizationFlag",fi="extendedHeaderFlag",pi="experimentalFlag",hi="footerPresent",en=class t{static*getID3v2Header(e,r,n){let i={},s=yield*e[z](3,n);if(s[0]!==73||s[1]!==68||s[2]!==51||(s=yield*e[z](10,n),i[ot]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(i[mi]=!!(s[5]&128),i[fi]=!!(s[5]&64),i[pi]=!!(s[5]&32),i[hi]=!!(s[5]&16),s[6]&128||s[7]&128||s[8]&128||s[9]&128))return null;let a=s[6]<<21|s[7]<<14|s[8]<<7|s[9];return i[m]=10+a,new t(i)}constructor(e){this[ot]=e[ot],this[mi]=e[mi],this[fi]=e[fi],this[pi]=e[pi],this[hi]=e[hi],this[m]=e[m]}};var de=class{constructor(e){W.set(this,e),this[j]=e[j],this[J]=null,this[S]=e[S],this[Z]=e[Z],this[C]=e[C]}};var Xs={0:[rr,rr,rr,rr,rr],16:[32,32,32,32,8],240:[te,te,te,te,te]},ro=(t,e,r)=>8*((t+r)%e+e)*(1<<(t+r)/e)-8*e*(e/8|0);for(let t=2;t<15;t++)Xs[t<<4]=[t*32,ro(t,4,0),ro(t,4,-1),ro(t,8,4),ro(t,8,0)];var Ac=0,wc=1,Mc=2,Lc=3,Vs=4,no="bands ",oo=" to 31",Us={0:no+4+oo,16:no+8+oo,32:no+12+oo,48:no+16+oo},Et="bitrateIndex",tn="v2",lo="v1",io="Intensity stereo ",so=", MS stereo ",ao="on",co="off",Cc={0:io+co+so+co,16:io+ao+so+co,32:io+co+so+ao,48:io+ao+so+ao},yi={0:{[v]:I},2:{[v]:"Layer III",[Pe]:1,[Oe]:Cc,[lo]:{[Et]:Mc,[E]:1152},[tn]:{[Et]:Vs,[E]:576}},4:{[v]:"Layer II",[Pe]:1,[Oe]:Us,[E]:1152,[lo]:{[Et]:wc},[tn]:{[Et]:Vs}},6:{[v]:"Layer I",[Pe]:4,[Oe]:Us,[E]:384,[lo]:{[Et]:Ac},[tn]:{[Et]:Lc}}},gi="MPEG Version ",Gs="ISO/IEC ",Ec={0:{[v]:`${gi}2.5 (later extension of MPEG 2)`,[ie]:tn,[C]:{0:Gn,4:Un,8:Jt,12:I}},8:{[v]:I},16:{[v]:`${gi}2 (${Gs}13818-3)`,[ie]:tn,[C]:{0:Yt,4:$t,8:jt,12:I}},24:{[v]:`${gi}1 (${Gs}11172-3)`,[ie]:lo,[C]:{0:Kt,4:tt,8:qt,12:I}},length:m},Tc={0:eo,1:jr},zc={0:jr,1:"50/15 ms",2:I,3:"CCIT J.17"},Ws={0:{[S]:2,[v]:et},64:{[S]:2,[v]:"joint "+et},128:{[S]:2,[v]:"dual channel"},192:{[S]:1,[v]:Ze}},Tt=class t extends de{static*[F](e,r,n){let o={},i=yield*en.getID3v2Header(e,r,n);i&&(yield*e[z](i[m],n),e[ye](i[m]));let s=yield*e[z](4,n),a=le(s[L](0,4)),c=r[F](a);if(c)return new t(c);if(s[0]!==255||s[1]<224)return null;let l=Ec[s[1]&24];if(l[v]===I)return null;let u=s[1]&6;if(yi[u][v]===I)return null;let d={...yi[u],...yi[u][l[ie]]};if(o[Be]=l[v],o[ie]=d[v],o[E]=d[E],o[Ve]=Tc[s[1]&1],o[m]=4,o[J]=Xs[s[2]&240][d[Et]],o[J]===te||(o[C]=l[C][s[2]&12],o[C]===I)||(o[Pe]=s[2]&2&&d[Pe],o[Ne]=!!(s[2]&1),o[se]=Math.floor(125*o[J]*o[E]/o[C]+o[Pe]),!o[se]))return null;let f=s[3]&192;if(o[Z]=Ws[f][v],o[S]=Ws[f][S],o[Oe]=d[Oe][s[3]&48],o[Fr]=!!(s[3]&8),o[De]=!!(s[3]&4),o[Zt]=zc[s[3]&3],o[Zt]===I)return null;o[j]=16;{let{length:p,frameLength:y,samples:h,...g}=o;r[ge](a,o,g)}return new t(o)}constructor(e){super(e),this[J]=e[J],this[Zt]=e[Zt],this[Pe]=e[Pe],this[Fr]=e[Fr],this[De]=e[De],this[Ne]=e[Ne],this[ie]=e[ie],this[Oe]=e[Oe],this[Be]=e[Be],this[Ve]=e[Ve]}};var rn=class t extends ue{static*[xe](e,r,n){return yield*super[xe](Tt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var nn=class extends re{constructor(e,r,n){super(e,r),this.Frame=rn,this.Header=Tt,n(this[H])}get[H](){return Wn}*[ke](){return yield*this[lt]()}};var Pc={0:"MPEG-4",8:"MPEG-2"},Fc={0:"valid",2:te,4:te,6:te},Ic={0:eo,1:jr},kc={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},Rc={0:Bn,4:Vn,8:Fs,12:tt,16:Kt,20:qt,24:$t,28:Yt,32:jt,36:Un,40:Gn,44:Jt,48:Is,52:I,56:I,60:"frequency is written explicitly"},Ks={0:{[S]:0,[v]:"Defined in AOT Specific Config"},64:{[S]:1,[v]:Ze},128:{[S]:2,[v]:O(2,_[0][0])},192:{[S]:3,[v]:O(3,_[1][3])},256:{[S]:4,[v]:O(4,_[1][3],_[3][4])},320:{[S]:5,[v]:O(5,_[1][3],_[3][0])},384:{[S]:6,[v]:O(6,_[1][3],_[3][0],Ee)},448:{[S]:8,[v]:O(8,_[1][3],_[2][0],_[3][0],Ee)}},zt=class t extends de{static*[F](e,r,n){let o={},i=yield*e[z](7,n),s=le([i[0],i[1],i[2],i[3]&252|i[6]&3]),a=r[F](s);if(a)Object.assign(o,a);else{if(i[0]!==255||i[1]<240||(o[Be]=Pc[i[1]&8],o[ie]=Fc[i[1]&6],o[ie]===te))return null;let l=i[1]&1;o[Ve]=Ic[l],o[m]=l?7:9,o[Xn]=i[2]&192,o[Fe]=i[2]&60;let u=i[2]&2;if(o[Dr]=kc[o[Xn]],o[C]=Rc[o[Fe]],o[C]===I)return null;o[Ne]=!!u,o[Ur]=(i[2]<<8|i[3])&448,o[Z]=Ks[o[Ur]][v],o[S]=Ks[o[Ur]][S],o[De]=!!(i[3]&32),o[Ir]=!!(i[3]&8),o[Gr]=!!(i[3]&8),o[Wr]=!!(i[3]&4),o[j]=16,o[E]=1024,o[Rr]=i[6]&3;{let{length:d,channelModeBits:f,profileBits:p,sampleRateBits:y,frameLength:h,samples:g,numberAACFrames:b,...T}=o;r[ge](s,o,T)}}if(o[se]=(i[3]<<11|i[4]<<3|i[5]>>5)&8191,!o[se])return null;let c=(i[5]<<6|i[6]>>2)&2047;return o[Cr]=c===2047?"VBR":c,new t(o)}constructor(e){super(e),this[Gr]=e[Gr],this[Wr]=e[Wr],this[Cr]=e[Cr],this[Ir]=e[Ir],this[De]=e[De],this[Ne]=e[Ne],this[ie]=e[ie],this[m]=e[m],this[Be]=e[Be],this[Rr]=e[Rr],this[Dr]=e[Dr],this[Ve]=e[Ve]}get audioSpecificConfig(){let e=W.get(this),r=e[Xn]+64<<5|e[Fe]<<5|e[Ur]>>3,n=new ee(2);return new dt(n[Te]).setUint16(0,r,!1),n}};var on=class t extends ue{static*[xe](e,r,n){return yield*super[xe](zt,t,e,r,n)}constructor(e,r,n){super(e,r,n)}};var sn=class extends re{constructor(e,r,n){super(e,r),this.Frame=on,this.Header=zt,n(this[H])}get[H](){return"aac"}*[ke](){return yield*this[lt]()}};var mt=class t extends ue{static _getFrameFooterCrc16(e){return(e[e[m]-2]<<8)+e[e[m]-1]}static[Zn](e){let r=t._getFrameFooterCrc16(e),n=Ns(e[L](0,-2));return r===n}constructor(e,r,n){r[$r]=n,r[Tr]=t._getFrameFooterCrc16(e),super(r,e,W.get(r)[E])}};var qs="get from STREAMINFO metadata block",Hc={0:"Fixed",1:"Variable"},$s={0:I,16:192};for(let t=2;t<16;t++)$s[t<<4]=t<6?576*2**(t-2):2**t;var Dc={0:qs,1:Vn,2:Ps,3:zs,4:Jt,5:jt,6:Yt,7:$t,8:qt,9:Kt,10:tt,11:Bn,15:te},Nc={0:{[S]:1,[v]:Ze},16:{[S]:2,[v]:O(2,_[0][0])},32:{[S]:3,[v]:O(3,_[0][1])},48:{[S]:4,[v]:O(4,_[1][0],_[3][0])},64:{[S]:5,[v]:O(5,_[1][1],_[3][0])},80:{[S]:6,[v]:O(6,_[1][1],Ee,_[3][0])},96:{[S]:7,[v]:O(7,_[1][1],Ee,_[3][4],_[2][0])},112:{[S]:8,[v]:O(8,_[1][1],Ee,_[3][0],_[2][0])},128:{[S]:2,[v]:`${et} (left, diff)`},144:{[S]:2,[v]:`${et} (diff, right)`},160:{[S]:2,[v]:`${et} (avg, diff)`},176:I,192:I,208:I,224:I,240:I},Oc={0:qs,2:8,4:12,6:I,8:16,10:20,12:24,14:I},ft=class t extends de{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let r=1;for(let s=64;s&e[0];s>>=1)r++;let n=r-1,o=0,i=0;for(;n>0;i+=6,n--){if((e[n]&192)!==128)return null;o|=(e[n]&63)<<i}return o|=(e[n]&127>>r)<<i,{value:o,length:r}}static[be](e,r){let n={[z]:function*(){return e}};return t[F](n,r,0).next().value}static*[F](e,r,n){let o=yield*e[z](6,n);if(o[0]!==255||!(o[1]===248||o[1]===249))return null;let i={},s=le(o[L](0,4)),a=r[F](s);if(a)Object.assign(i,a);else{if(i[qn]=o[1]&1,i[Or]=Hc[i[qn]],i[Br]=o[2]&240,i[Fe]=o[2]&15,i[Ue]=$s[i[Br]],i[Ue]===I||(i[C]=Dc[i[Fe]],i[C]===te)||o[3]&1)return null;let l=Nc[o[3]&240];if(l===I||(i[S]=l[S],i[Z]=l[v],i[j]=Oc[o[3]&14],i[j]===I))return null}i[m]=5,o=yield*e[z](i[m]+8,n);let c=t._decodeUTF8Int(o[L](4));if(!c||(i[qn]?i[Kr]=c.value:i[Ke]=c.value,i[m]+=c[m],i[Br]===96?(o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[Ue]=o[i[m]-1]+1,i[m]+=1):i[Br]===112&&(o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[Ue]=(o[i[m]-1]<<8)+o[i[m]]+1,i[m]+=2),i[E]=i[Ue],i[Fe]===12?(o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[C]=o[i[m]-1]*1e3,i[m]+=1):i[Fe]===13?(o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[C]=(o[i[m]-1]<<8)+o[i[m]],i[m]+=2):i[Fe]===14&&(o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[C]=((o[i[m]-1]<<8)+o[i[m]])*10,i[m]+=2),o[m]<i[m]&&(o=yield*e[z](i[m],n)),i[Qt]=o[i[m]-1],i[Qt]!==Ds(o[L](0,i[m]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:u,sampleNumber:d,samples:f,sampleRateBits:p,blockSizeBits:y,crc:h,length:g,...b}=i;r[ge](s,i,b)}return new t(i)}constructor(e){super(e),this[Tr]=null,this[Or]=e[Or],this[Ue]=e[Ue],this[Ke]=e[Ke],this[Kr]=e[Kr],this[$r]=null}};var Bc=2,Vc=512*1024,Pt=class extends re{constructor(e,r,n){super(e,r),this.Frame=mt,this.Header=ft,n(this[H])}get[H](){return"flac"}*_getNextFrameSyncOffset(e){let r=yield*this._codecParser[z](2,0),n=r[m]-2;for(;e<n;){if(r[e]===255){let i=r[e+1];if(i===248||i===249)break;i!==255&&e++}e++}return e}*[ke](){do{let e=yield*ft[F](this._codecParser,this._headerCache,0);if(e){let r=W.get(e)[m]+Bc;for(;r<=Vc;){if(this._codecParser._flushing||(yield*ft[F](this._codecParser,this._headerCache,r))){let n=yield*this._codecParser[z](r);if(this._codecParser._flushing||(n=n[L](0,r)),mt[Zn](n)){let o=new mt(n,e);return this._headerCache[we](),this._codecParser[ye](r),this._codecParser[ct](o),o}}r=yield*this._getNextFrameSyncOffset(r+1)}this._codecParser[_e](`Unable to sync FLAC frame after searching ${r} bytes.`),this._codecParser[ye](r)}else this._codecParser[ye](yield*this._getNextFrameSyncOffset(1))}while(!0)}[ut](e){return e[G]===0?(this._headerCache[we](),this._streamInfo=e[R][L](13)):e[G]===1||(e[Q]=q.get(e)[he].map(r=>{let n=ft[be](r,this._headerCache);if(n)return new mt(r,n,this._streamInfo);this._codecParser[_e]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(r=>!!r)),e}};var Ft=class t{static*[F](e,r,n){let o={},i=yield*e[z](28,n);if(i[0]!==79||i[1]!==103||i[2]!==103||i[3]!==83||(o[ci]=i[4],i[5]&248))return null;o[ce]=!!(i[5]&4),o[nt]=!!(i[5]&2),o[rt]=!!(i[5]&1);let a=new dt(ee.from(i[L](0,28))[Te]);o[ve]=Bs(a,6),o[Ie]=a.getInt32(14,!0),o[G]=a.getInt32(18,!0),o[At]=a.getInt32(22,!0);let c=i[26];o[m]=c+27,i=yield*e[z](o[m],n),o[se]=0,o[at]=[],o[tr]=ee.from(i[L](27,o[m]));for(let l=0,u=0;l<c;l++){let d=o[tr][l];o[se]+=d,u+=d,(d!==255||l===c-1)&&(o[at].push(u),u=0)}return new t(o)}constructor(e){W.set(this,e),this[ve]=e[ve],this[rt]=e[rt],this[nt]=e[nt],this[ce]=e[ce],this[at]=e[at],this[G]=e[G],this[At]=e[At],this[Ie]=e[Ie]}};var an=class t extends Ct{static*[xe](e,r,n){let o=yield*Ft[F](e,r,n);if(o){let i=W.get(o)[se],s=W.get(o)[m],a=s+i,c=(yield*e[z](a,0))[L](0,a),l=c[L](s,a);return new t(o,l,c)}else return null}constructor(e,r,n){super(e,r),q.get(this)[m]=n[m],this[Q]=[],this[ii]=n,this[ve]=e[ve],this[zr]=e[At],this[ze]=0,this[rt]=e[rt],this[nt]=e[nt],this[ce]=e[ce],this[G]=e[G],this[E]=0,this[Ie]=e[Ie]}};var nr=class extends ue{constructor(e,r,n){super(r,e,n)}};var Ys={0:Ar.slice(0,2),1:Ar},Se="SILK-only",$="CELT-only",uo="Hybrid",pt="narrowband",mo="medium-band",ht="wideband",or="super-wideband",ir="fullband",Uc={0:{[w]:Se,[M]:pt,[A]:10},8:{[w]:Se,[M]:pt,[A]:20},16:{[w]:Se,[M]:pt,[A]:40},24:{[w]:Se,[M]:pt,[A]:60},32:{[w]:Se,[M]:mo,[A]:10},40:{[w]:Se,[M]:mo,[A]:20},48:{[w]:Se,[M]:mo,[A]:40},56:{[w]:Se,[M]:mo,[A]:60},64:{[w]:Se,[M]:ht,[A]:10},72:{[w]:Se,[M]:ht,[A]:20},80:{[w]:Se,[M]:ht,[A]:40},88:{[w]:Se,[M]:ht,[A]:60},96:{[w]:uo,[M]:or,[A]:10},104:{[w]:uo,[M]:or,[A]:20},112:{[w]:uo,[M]:ir,[A]:10},120:{[w]:uo,[M]:ir,[A]:20},128:{[w]:$,[M]:pt,[A]:2.5},136:{[w]:$,[M]:pt,[A]:5},144:{[w]:$,[M]:pt,[A]:10},152:{[w]:$,[M]:pt,[A]:20},160:{[w]:$,[M]:ht,[A]:2.5},168:{[w]:$,[M]:ht,[A]:5},176:{[w]:$,[M]:ht,[A]:10},184:{[w]:$,[M]:ht,[A]:20},192:{[w]:$,[M]:or,[A]:2.5},200:{[w]:$,[M]:or,[A]:5},208:{[w]:$,[M]:or,[A]:10},216:{[w]:$,[M]:or,[A]:20},224:{[w]:$,[M]:ir,[A]:2.5},232:{[w]:$,[M]:ir,[A]:5},240:{[w]:$,[M]:ir,[A]:10},248:{[w]:$,[M]:ir,[A]:20}},sr=class t extends de{static[be](e,r,n){let o={};if(o[S]=e[9],o[Ge]=e[18],o[m]=o[Ge]!==0?21+o[S]:19,e[m]<o[m])throw new Error("Out of data while inside an Ogg Page");let i=r[0]&3,s=i===3?2:1,a=le(e[L](0,o[m]))+le(r[L](0,s)),c=n[F](a);if(c)return new t(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;o[R]=ee.from(e[L](0,o[m]));let l=new dt(o[R][Te]);if(o[j]=16,o[vt]=l.getUint16(10,!0),o[Xr]=l.getUint32(12,!0),o[C]=tt,o[Hr]=l.getInt16(16,!0),o[Ge]in Ys&&(o[Z]=Ys[o[Ge]][o[S]-1],!o[Z]))return null;o[Ge]!==0&&(o[qr]=e[19],o[Er]=e[20],o[Vr]=[...e[L](21,o[S]+21)]);let u=Uc[248&r[0]];switch(o[w]=u[w],o[M]=u[M],o[A]=u[A],i){case 0:o[Xe]=1;break;case 1:case 2:o[Xe]=2;break;case 3:o[kr]=!!(128&r[1]),o[Pr]=!!(64&r[1]),o[Xe]=63&r[1];break;default:return null}{let{length:d,data:f,channelMappingFamily:p,...y}=o;n[ge](a,o,y)}return new t(o)}constructor(e){super(e),this[R]=e[R],this[M]=e[M],this[Ge]=e[Ge],this[Vr]=e[Vr],this[Er]=e[Er],this[Xe]=e[Xe],this[A]=e[A],this[Pr]=e[Pr],this[Xr]=e[Xr],this[kr]=e[kr],this[w]=e[w],this[Hr]=e[Hr],this[vt]=e[vt],this[qr]=e[qr]}};var cn=class extends re{constructor(e,r,n){super(e,r),this.Frame=nr,this.Header=sr,n(this[H]),this._identificationHeader=null,this._preSkipRemaining=null}get[H](){return"opus"}[ut](e){return e[G]===0?(this._headerCache[we](),this._identificationHeader=e[R]):e[G]===1||(e[Q]=q.get(e)[he].map(r=>{let n=sr[be](this._identificationHeader,r,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[vt]);let o=n[A]*n[Xe]/1e3*n[C];return this._preSkipRemaining>0&&(this._preSkipRemaining-=o,o=this._preSkipRemaining<0?-this._preSkipRemaining:0),new nr(r,n,o)}this._codecParser[Jn]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var ar=class extends ue{constructor(e,r,n){super(r,e,n)}};var xi={};for(let t=0;t<8;t++)xi[t+6]=2**(6+t);var ln=class t extends de{static[be](e,r,n,o){if(e[m]<30)throw new Error("Out of data while inside an Ogg Page");let i=le(e[L](0,30)),s=r[F](i);if(s)return new t(s);let a={[m]:30};if(i.substr(0,7)!=="vorbis")return null;a[R]=ee.from(e[L](0,30));let c=new dt(a[R][Te]);if(a[ot]=c.getUint32(7,!0),a[ot]!==0||(a[S]=e[11],a[Z]=Ar[a[S]-1]||"application defined",a[C]=c.getUint32(12,!0),a[wr]=c.getInt32(16,!0),a[Lr]=c.getInt32(20,!0),a[Mr]=c.getInt32(24,!0),a[st]=xi[(e[28]&240)>>4],a[it]=xi[e[28]&15],a[it]>a[st])||e[29]!==1)return null;a[j]=32,a[er]=o,a[Nr]=n;{let{length:l,data:u,version:d,vorbisSetup:f,vorbisComments:p,...y}=a;r[ge](i,a,y)}return new t(a)}constructor(e){super(e),this[wr]=e[wr],this[Mr]=e[Mr],this[Lr]=e[Lr],this[it]=e[it],this[st]=e[st],this[R]=e[R],this[Nr]=e[Nr],this[er]=e[er]}};var un=class extends re{constructor(e,r,n){super(e,r),this.Frame=ar,n(this[H]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[H](){return _t}[ut](e){e[Q]=[];for(let r of q.get(e)[he])if(r[0]===1)this._headerCache[we](),this._identificationHeader=e[R],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=ln[be](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[Q].push(new ar(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 o=this._mode.blockFlags[e[0]>>1&this._mode.mask]?r[st]:r[it],i=this._prevBlockSize===null?0:(this._prevBlockSize+o)/4;return this._prevBlockSize=o,i}_parseSetupHeader(e){let r=new to(e),n={count:0,blockFlags:[]};for(;(r.read(1)&1)!==1;);let o;for(;n.count<64&&r.position>0;){Jr(r.read(8));let i=0;for(;r.read(8)===0&&i++<3;);if(i===4)o=r.read(7),n.blockFlags.unshift(o&1),r.position+=6,n.count++;else{((Jr(o)&126)>>1)+1!==n.count&&this._codecParser[_e]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var bi=class{constructor(e,r,n){this._codecParser=e,this._headerCache=r,this._onCodec=n,this._continuedPacket=new ee,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[H](){return this._codec||""}_updateCodec(e,r){this._codec!==e&&(this._headerCache[Ae](),this._parser=new r(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let r=le(e[L](0,8));switch(r){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",cn),!0;case(/^\x7fFLAC/.test(r)&&r):return this._updateCodec("flac",Pt),!0;case(/^\x01vorbis/.test(r)&&r):return this._updateCodec(_t,un),!0;default:return!1}}_checkPageSequenceNumber(e){e[G]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[G]>1&&this._codecParser[_e]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[G]}`),this._pageSequenceNumber=e[G]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[G],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let r=q.get(e),n=W.get(r[ae]),o=0;if(r[he]=n[at].map(i=>e[R][L](o,o+=i)),this._continuedPacket[m]&&(r[he][0]=Qr(this._continuedPacket,r[he][0]),this._continuedPacket=new ee),n[tr][n[tr][m]-1]===255&&(this._continuedPacket=Qr(this._continuedPacket,r[he].pop())),this._previousAbsoluteGranulePosition!==null&&(e[E]=Number(e[ve]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[ve],this._isSupported){let i=this._parser[ut](e);return this._codecParser[ct](i),i}else return e}},dn=class extends re{constructor(e,r,n){super(e,r),this._onCodec=n,this.Frame=an,this.Header=Ft,this._streams=new Map,this._currentSerialNumber=null}get[H](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[ke](){let e=yield*this[lt](!0);this._currentSerialNumber=e[Ie];let r=this._streams.get(this._currentSerialNumber);return r||(r=new bi(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,r)),e[ce]&&this._streams.delete(this._currentSerialNumber),r._parsePage(e)}};var Si=()=>{},mn=class{constructor(e,{onCodec:r,onCodecHeader:n,onCodecUpdate:o,enableLogging:i=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=r||Si,this._onCodecHeader=n||Si,this._onCodecUpdate=o,this._enableLogging=i,this._crc32=s?Os:Si,this[Ae]()}get[H](){return this._parser?this._parser[H]:""}[Ae](){this._headerCache=new Zr(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[Ae]()}*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 sn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new nn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new Pt(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new dn(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[ke]();e&&(yield e)}}*[z](e=0,r=0){let n;for(;this._rawData[m]<=e+r;){if(n=yield,this._flushing)return this._rawData[L](r);n&&(this._totalBytesIn+=n[m],this._rawData=Qr(this._rawData,n))}return this._rawData[L](r)}[ye](e){this._currentReadPosition+=e,this._rawData=this._rawData[L](e)}[Yr](e){this._sampleRate=e[ae][C],e[ae][J]=e[ze]>0?Math.round(e[R][m]/e[ze])*8:0,e[Ke]=this._frameNumber++,e[wt]=this._totalBytesOut,e[Lt]=this._totalSamples,e[Mt]=this._totalSamples/this._sampleRate*1e3,e[zr]=this._crc32(e[R]),this._headerCache[Qn](e[ae][J],e[Mt]),this._totalBytesOut+=e[R][m],this._totalSamples+=e[E]}[ct](e){if(e[Q]){if(e[ce]){let r=e[E];e[Q].forEach(n=>{let o=n[E];r<o&&(n[E]=r>0?r:0,n[ze]=n[E]/n[ae][C]*1e3),r-=o,this[Yr](n)})}else e[E]=0,e[Q].forEach(r=>{e[E]+=r[E],this[Yr](r)});e[ze]=e[E]/this._sampleRate*1e3||0,e[Lt]=this._totalSamples,e[Mt]=this._totalSamples/this._sampleRate*1e3||0,e[wt]=this._totalBytesOut}else this[Yr](e)}_log(e,r){if(this._enableLogging){let n=[`${H}: ${this[H]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${wt}: ${this._totalBytesOut}`],o=Math.max(...n.map(i=>i[m]));r.push(`--stats--${"-".repeat(o-9)}`,...n,"-".repeat(o)),e("codec-parser",r.reduce((i,s)=>i+`
|
|
4
|
-
`+s,""))}}[
|
|
3
|
+
`,"Visit https://github.com/eshaz/simple-yenc for more information"),Error(b)}}return y};function H(){let r=Uint8Array,e=Float32Array;H.modules||Object.defineProperties(H,{modules:{value:new WeakMap},setModule:{value(t,n){H.modules.set(t,Promise.resolve(n))}},getModule:{value(t,n){let o=H.modules.get(t);return o||(n?o=WebAssembly.compile(mi(n)):(n=t.wasm,o=H.inflateDynEncodeString(n).then(i=>WebAssembly.compile(i))),H.modules.set(t,o)),o}},concatFloat32:{value(t,n){let o=new e(n),i=0,s=0;for(;i<t.length;)o.set(t[i],s),s+=t[i++].length;return o}},getDecodedAudio:{value:(t,n,o,i,s)=>({errors:t,channelData:n,samplesDecoded:o,sampleRate:i,bitDepth:s})},getDecodedAudioMultiChannel:{value(t,n,o,i,s,a){let c=[],l,u;for(l=0;l<o;l++){let d=[];for(u=0;u<n.length;)d.push(n[u++][l]||[]);c.push(H.concatFloat32(d,i))}return H.getDecodedAudio(t,c,i,s,a)}},inflateDynEncodeString:{value(t){return t=mi(t),new Promise(n=>{let o=String.raw`dynEncode012804c7886d()((()>+*§§)§,§§§§)§+§§§)§+.-()(*)-+)(.7*§)i¸¸,3§(i¸¸,3/G+.¡*(,(,3+)2å:-),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)^*<H,H(P*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)J.H.W)(i)c)(H,i)I,H-i*I-4)33i(I.*hH(V)(H+n5(H(i*I-i(I,i)I.+hH,i*J+iHn,hi(I-i*I,+hH,H/H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)J(H(V)(J(i)c)(H)H(i)H,c)(3H*i*I*H,i)I,4(3(-H(H,W)(H-I-H,i*I,4)3(3(3H,H-I1H+I,H.i)H1V)(J.i(v5(33H.-H(H,i(c)(H,i*I,4)333)-§i*I*+§H*iHn,hi73H,H(i)8(H+J+H)P*(H*V)(J-r,§H)P*,H.i)H+H,i)V)(-H*i*I*H+i)I+H-H.I.H,H-i)I,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7H,c)(i)H+i´8W)(H,I,H+i*I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,H-b((3H(P*0i)I.4)3H-i¨*n5*H-iÅ*s,hi73H-i)J+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)J+i¸7V)(H(H+iø7V)(8(J/H(P*0J+s,hi73H+H,H.J,I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+H.H+H/U((b((H(H(P*0i)J+^*0H,i)I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)c)(H,i*I,H+i)I+4)33i)I-3H-3!2)0§K(i2J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,J(H,P*8J/s50H,H.i+J0^*<i¦I*H.H,P*4J1J.U(*H.U((J2i')o5/H.U()I.H,H(^*<H0H1U((H.i0J.i§i0i')o5/H/H.H2J*H(J.q50H,P*0J/H*I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0H(H1U((b((H/i)I/H(i)I(H*i)I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-H(i0c)(H(i*I(4)33iè1i1H,i-iÈ*8)Bi(I(+hH(ido,hH,i-H(i-c)(H(i*I(4)33iÈ6iè6H,i-iF8)BiØ1i)b((41-H,i-H(i/c)(H(i*I(4)3(3(-H,i-H(i1c)(H(i*I(4)3(3(-H,i-H(i0c)(H(i*I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)^*TH,H,iø-^*PH,H,iX^*LH,H,i(^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iEr5)H(i©*I1H-i)I0i(i;H.i,J(i(H(i(rCJ(J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-H-V)(i)H,i+8(c)(H/i)I/H-i*I-H*i)I*4)-H(i)i¨1I/+hH(H*o,hH,i-H/V)(i)i(c)(H/i*I/H(i)I(4)33i¤I*H,iø-H,i¸)H,i-i;8)5+H0H1I2i(I-+hH-H2p,hH,H,iP8*J*i(p5-H*i7u,hH,i-H-i)H*c)(H-i)I-4*3i(I/i+I.i+I(*h*h*hH*i86*(*)3H-m,hi£I*403H-i)H,W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.J(H-J.p,hi¢I*4.3H,i-H-i)I*+hH(,hH*H/c)(H*i*I*H(i)I(4)-H.I-4+3(3(33H,W)1m,hiI*4,3H,iø-H,i¸)H,i-H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-o5,3H,i(H,iXH,i-H1i)H08)J(,hi I*H(i(p5,H0H,V)H,V)o5,3H,H,iPH,iH8+I*4+3(3(3H,i$6i¬78+I*3H*H3m5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(((«(Ë(ë((*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7*S7US0U `;H.getModule(H,o).then(i=>WebAssembly.instantiate(i,{})).then(({exports:i})=>{let s=new Map(Object.entries(i)),a=s.get("puff"),c=s.get("memory").buffer,l=new r(c),u=new DataView(c),d=s.get("__heap_base"),m=t.length,p=d;d+=4,u.setInt32(p,m,!0);let h=d;d+=m,l.set(t,h);let y=d;d+=4,u.setInt32(y,l.byteLength-d,!0),a(d,y,h,p),n(l.slice(d,d+u.getInt32(y,!0)))})})}}}),Object.defineProperty(this,"wasm",{enumerable:!0,get:()=>this._wasm}),this.getOutputChannels=(t,n,o)=>{let i=[],s=0;for(;s<n;)i.push(t.slice(s*o,s++*o+o));return i},this.allocateTypedArray=(t,n,o=!0)=>{let i=this._wasm.malloc(n.BYTES_PER_ELEMENT*t);return o&&this._pointers.add(i),{ptr:i,len:t,buf:new n(this._wasm.HEAP,i,t)}},this.free=()=>{this._pointers.forEach(t=>{this._wasm.free(t)}),this._pointers.clear()},this.codeToString=t=>{let n=[],o=new Uint8Array(this._wasm.HEAP);for(let i=o[t];i!==0;i=o[++t])n.push(i);return String.fromCharCode.apply(null,n)},this.addError=(t,n,o,i,s,a)=>{t.push({message:n,frameLength:o,frameNumber:i,inputBytes:s,outputSamples:a})},this.instantiate=(t,n)=>(n&&H.setModule(t,n),this._wasm=new t(H).instantiate(),this._pointers=new Set,this._wasm.ready.then(()=>this))}var Ws=nc(Gs(),1);var Wc=()=>globalThis.Worker||Ws.default,$t=class extends Wc(){constructor(e,t,n,o){H.modules||new H;let i=H.modules.get(n);if(!i){let s="text/javascript",a,c=`'use strict';(${((l,u,d)=>{let m,p,h=new Promise(y=>{p=y});self.onmessage=({data:{id:y,command:g,data:b}})=>{let C=h,L={id:y},q;g==="init"?(Object.defineProperties(l,{WASMAudioDecoderCommon:{value:u},EmscriptenWASM:{value:d},module:{value:b.module},isWebWorker:{value:!0}}),m=new l(b.options),p()):g==="free"?m.free():g==="ready"?C=C.then(()=>m.ready):g==="reset"?C=C.then(()=>m.reset()):(Object.assign(L,m[g](Array.isArray(b)?b.map(G=>new Uint8Array(G)):new Uint8Array(b))),q=L.channelData?L.channelData.map(G=>G.buffer):[]),C.then(()=>self.postMessage(L,q))}}).toString()})(${n}, ${H}, ${o})`;try{a=typeof process.versions.node<"u"}catch{}i=a?`data:${s};base64,${Buffer.from(c).toString("base64")}`:URL.createObjectURL(new Blob([c],{type:s})),H.modules.set(n,i)}super(i,{name:t}),this._id=Number.MIN_SAFE_INTEGER,this._enqueuedOperations=new Map,this.onmessage=({data:s})=>{let{id:a,...c}=s;this._enqueuedOperations.get(a)(c),this._enqueuedOperations.delete(a)},new o(H).getModule().then(s=>{this.postToDecoder("init",{module:s,options:e})})}async postToDecoder(e,t){return new Promise(n=>{this.postMessage({command:e,id:this._id,data:t}),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 qn=(r,e)=>{Object.defineProperty(r,"name",{value:e})};var O=Symbol,Xs=", ",_=(()=>{let r="front",e="side",t="rear",n="left",o="center",i="right";return["",r+" ",e+" ",t+" "].map(s=>[[n,i],[n,i,o],[n,o,i],[o,n,i],[o]].flatMap(a=>a.map(c=>s+c).join(Xs)))})(),ke="LFE",st="monophonic (mono)",at="stereo",Er="surround",N=(r,...e)=>`${[st,at,`linear ${Er}`,"quadraphonic",`5.0 ${Er}`,`5.1 ${Er}`,`6.1 ${Er}`,`7.1 ${Er}`][r-1]} (${e.join(Xs)})`,Tr=[st,N(2,_[0][0]),N(3,_[0][2]),N(4,_[1][0],_[3][0]),N(5,_[1][2],_[3][0]),N(6,_[1][2],_[3][0],ke),N(7,_[1][2],_[2][0],_[3][4],ke),N(8,_[1][2],_[2][0],_[3][0],ke)],qs=192e3,Ks=176400,Kn=96e3,Yn=88200,Ys=64e3,ct=48e3,Jt=44100,Qt=32e3,Zt=24e3,er=22050,tr=16e3,jn=12e3,$n=11025,rr=8e3,js=7350,Te="absoluteGranulePosition",w="bandwidth",Q="bitDepth",Z="bitrate",zr=Z+"Maximum",Fr=Z+"Minimum",Pr=Z+"Nominal",De="buffer",Ir=De+"Fullness",D="codec",ee=D+"Frames",Rr="coupledStreamCount",nr="crc",kr=nr+"16",Dr=nr+"32",k="data",S="description",He="duration",or="emphasis",Hr="hasOpusPadding",ue="header",lt="isContinuedPacket",Or="isCopyrighted",ut="isFirstPage",Br="isHome",de="isLastPage",Ue="isOriginal",Ge="isPrivate",Nr="isVbr",ae="layer",f="length",M="mode",We=M+"Extension",Jn="mpeg",Xe=Jn+"Version",Vr="numberAACFrames",Ur="outputGain",Ct="preSkip",Gr="profile",Qn=O(),qe="protection",fi="rawData",be="segments",E="subarray",dt="version",Et="vorbis",Wr=Et+"Comments",ir=Et+"Setup",Zn="block",Xr=Zn+"ingStrategy",eo=O(),Ke=Zn+"Size",mt=Zn+"size0",ft=Zn+"size1",qr=O(),to="channel",Ye=to+"MappingFamily",Kr=to+"MappingTable",te=to+"Mode",Yr=O(),v=to+"s",$s="copyright",jr=$s+"Id",$r=$s+"IdStart",je="frame",$e=je+"Count",ce=je+"Length",ro="Number",Je=je+ro,Oe=je+"Padding",A=je+"Size",Js="Rate",Jr="inputSample"+Js,pi="page",Tt=pi+"Checksum",sr=O(),pt=pi+"SegmentTable",X=pi+"Sequence"+ro,hi="sample",Qr=hi+ro,T=hi+Js,Be=O(),z=hi+"s",no="stream",Zr=no+"Count",en=no+"Info",Ne=no+"Serial"+ro,yi=no+"StructureVersion",gi="total",zt=gi+"BytesOut",Ft=gi+"Duration",Pt=gi+"Samples",F=O(),ve=O(),tn=O(),ht=O(),ze=O(),oo=O(),xi=O(),yt=O(),P=O(),Se=O(),_e=O(),Ve=O(),gt=O(),io=O(),Fe=O(),Pe=O(),Ae=O(),so=O(),re=Uint8Array,xt=DataView,I="reserved",ne="bad",ar="free",rn="none",ao="16bit CRC";var bi=(r,e,t)=>{for(let n=0;n<r[f];n++){let o=e(n);for(let i=8;i>0;i--)o=t(o);r[n]=o}return r},qc=bi(new re(256),r=>r,r=>r&128?7^r<<1:r<<1),V=[bi(new Uint16Array(256),r=>r<<8,r=>r<<1^(r&32768?32773:0))],U=[bi(new Uint32Array(256),r=>r,r=>r>>>1^(r&1)*3988292384)];for(let r=0;r<15;r++){V.push(new Uint16Array(256)),U.push(new Uint32Array(256));for(let e=0;e<=255;e++)V[r+1][e]=V[0][V[r][e]>>>8]^V[r][e]<<8,U[r+1][e]=U[r][e]>>>8^U[0][U[r][e]&255]}var Zs=r=>{let e=0,t=r[f];for(let n=0;n!==t;n++)e=qc[e^r[n]];return e},ea=r=>{let e=r[f],t=e-16,n=0,o=0;for(;o<=t;)n^=r[o++]<<8|r[o++],n=V[15][n>>8]^V[14][n&255]^V[13][r[o++]]^V[12][r[o++]]^V[11][r[o++]]^V[10][r[o++]]^V[9][r[o++]]^V[8][r[o++]]^V[7][r[o++]]^V[6][r[o++]]^V[5][r[o++]]^V[4][r[o++]]^V[3][r[o++]]^V[2][r[o++]]^V[1][r[o++]]^V[0][r[o++]];for(;o!==e;)n=(n&255)<<8^V[0][n>>8^r[o++]];return n},ta=r=>{let e=r[f],t=e-16,n=0,o=0;for(;o<=t;)n=U[15][(r[o++]^n)&255]^U[14][(r[o++]^n>>>8)&255]^U[13][(r[o++]^n>>>16)&255]^U[12][r[o++]^n>>>24]^U[11][r[o++]]^U[10][r[o++]]^U[9][r[o++]]^U[8][r[o++]]^U[7][r[o++]]^U[6][r[o++]]^U[5][r[o++]]^U[4][r[o++]]^U[3][r[o++]]^U[2][r[o++]]^U[1][r[o++]]^U[0][r[o++]];for(;o!==e;)n=U[0][(n^r[o++])&255]^n>>>8;return n^-1},on=(...r)=>{let e=new re(r.reduce((t,n)=>t+n[f],0));return r.reduce((t,n)=>(e.set(n,t),t+n[f]),0),e},me=r=>String.fromCharCode(...r),Qs=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],nn=r=>Qs[r&15]<<4|Qs[r>>4],co=class{constructor(e){this._data=e,this._pos=e[f]*8}set position(e){this._pos=e}get position(){return this._pos}read(e){let t=Math.floor(this._pos/8),n=this._pos%8;return this._pos-=e,(nn(this._data[t-1])<<8)+nn(this._data[t])>>7-n&255}},ra=(r,e)=>{try{return r.getBigInt64(e,!0)}catch{let t=r.getUint8(e+7)&128?-1:1,n=r.getUint32(e,!0),o=r.getUint32(e+4,!0);return t===-1&&(n=~n+1,o=~o+1),o>1048575&&console.warn("This platform does not support BigInt"),t*(n+o*2**32)}};var sn=class{constructor(e,t){this._onCodecHeader=e,this._onCodecUpdate=t,this[Fe]()}[Pe](){this._isEnabled=!0}[Fe](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[io](e,t){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},t),this._codecShouldUpdate=!1}}[P](e){let t=this._headerCache.get(e);return t&&this._updateCurrentHeader(e),t}[Se](e,t,n){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...t}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,t),this._codecUpdateData.set(t,n))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}};var Y=new WeakMap,$=new WeakMap;var oe=class{constructor(e,t){this._codecParser=e,this._headerCache=t}*[xi](){let e;do{if(e=yield*this.Frame[_e](this._codecParser,this._headerCache,0),e)return e;this._codecParser[ve](1)}while(!0)}*[yt](e){let t=yield*this[xi](),n=$.get(t)[f];if(e||this._codecParser._flushing||(yield*this.Header[P](this._codecParser,this._headerCache,n)))return this._headerCache[Pe](),this._codecParser[ve](n),this._codecParser[ht](t),t;this._codecParser[ze](`Missing ${je} at ${n} bytes from current position.`,`Dropping current ${je} and trying again.`),this._headerCache[Fe](),this._codecParser[ve](1)}};var It=class{constructor(e,t){$.set(this,{[ue]:e}),this[k]=t}};var fe=class extends It{static*[_e](e,t,n,o,i){let s=yield*e[P](n,o,i);if(s){let a=Y.get(s)[ce],c=Y.get(s)[z],l=(yield*n[F](a,i))[E](0,a);return new t(s,l,c)}else return null}constructor(e,t,n){super(e,t),this[ue]=e,this[z]=n,this[He]=n/e[T]*1e3,this[Je]=null,this[zt]=null,this[Pt]=null,this[Ft]=null,$.get(this)[f]=t[f]}};var vi="unsynchronizationFlag",Si="extendedHeaderFlag",_i="experimentalFlag",Ai="footerPresent",an=class r{static*getID3v2Header(e,t,n){let i={},s=yield*e[F](3,n);if(s[0]!==73||s[1]!==68||s[2]!==51||(s=yield*e[F](10,n),i[dt]=`id3v2.${s[3]}.${s[4]}`,s[5]&15)||(i[vi]=!!(s[5]&128),i[Si]=!!(s[5]&64),i[_i]=!!(s[5]&32),i[Ai]=!!(s[5]&16),s[6]&128||s[7]&128||s[8]&128||s[9]&128))return null;let a=s[6]<<21|s[7]<<14|s[8]<<7|s[9];return i[f]=10+a,new r(i)}constructor(e){this[dt]=e[dt],this[vi]=e[vi],this[Si]=e[Si],this[_i]=e[_i],this[Ai]=e[Ai],this[f]=e[f]}};var pe=class{constructor(e){Y.set(this,e),this[Q]=e[Q],this[Z]=null,this[v]=e[v],this[te]=e[te],this[T]=e[T]}};var aa={0:[ar,ar,ar,ar,ar],16:[32,32,32,32,8],240:[ne,ne,ne,ne,ne]},lo=(r,e,t)=>8*((r+t)%e+e)*(1<<(r+t)/e)-8*e*(e/8|0);for(let r=2;r<15;r++)aa[r<<4]=[r*32,lo(r,4,0),lo(r,4,-1),lo(r,8,4),lo(r,8,0)];var Kc=0,Yc=1,jc=2,$c=3,na=4,uo="bands ",mo=" to 31",oa={0:uo+4+mo,16:uo+8+mo,32:uo+12+mo,48:uo+16+mo},Rt="bitrateIndex",cn="v2",go="v1",fo="Intensity stereo ",po=", MS stereo ",ho="on",yo="off",Jc={0:fo+yo+po+yo,16:fo+ho+po+yo,32:fo+yo+po+ho,48:fo+ho+po+ho},Mi={0:{[S]:I},2:{[S]:"Layer III",[Oe]:1,[We]:Jc,[go]:{[Rt]:jc,[z]:1152},[cn]:{[Rt]:na,[z]:576}},4:{[S]:"Layer II",[Oe]:1,[We]:oa,[z]:1152,[go]:{[Rt]:Yc},[cn]:{[Rt]:na}},6:{[S]:"Layer I",[Oe]:4,[We]:oa,[z]:384,[go]:{[Rt]:Kc},[cn]:{[Rt]:$c}}},wi="MPEG Version ",ia="ISO/IEC ",Qc={0:{[S]:`${wi}2.5 (later extension of MPEG 2)`,[ae]:cn,[T]:{0:$n,4:jn,8:rr,12:I}},8:{[S]:I},16:{[S]:`${wi}2 (${ia}13818-3)`,[ae]:cn,[T]:{0:er,4:Zt,8:tr,12:I}},24:{[S]:`${wi}1 (${ia}11172-3)`,[ae]:go,[T]:{0:Jt,4:ct,8:Qt,12:I}},length:f},Zc={0:ao,1:rn},el={0:rn,1:"50/15 ms",2:I,3:"CCIT J.17"},sa={0:{[v]:2,[S]:at},64:{[v]:2,[S]:"joint "+at},128:{[v]:2,[S]:"dual channel"},192:{[v]:1,[S]:st}},kt=class r extends pe{static*[P](e,t,n){let o={},i=yield*an.getID3v2Header(e,t,n);i&&(yield*e[F](i[f],n),e[ve](i[f]));let s=yield*e[F](4,n),a=me(s[E](0,4)),c=t[P](a);if(c)return new r(c);if(s[0]!==255||s[1]<224)return null;let l=Qc[s[1]&24];if(l[S]===I)return null;let u=s[1]&6;if(Mi[u][S]===I)return null;let d={...Mi[u],...Mi[u][l[ae]]};if(o[Xe]=l[S],o[ae]=d[S],o[z]=d[z],o[qe]=Zc[s[1]&1],o[f]=4,o[Z]=aa[s[2]&240][d[Rt]],o[Z]===ne||(o[T]=l[T][s[2]&12],o[T]===I)||(o[Oe]=s[2]&2&&d[Oe],o[Ge]=!!(s[2]&1),o[ce]=Math.floor(125*o[Z]*o[z]/o[T]+o[Oe]),!o[ce]))return null;let m=s[3]&192;if(o[te]=sa[m][S],o[v]=sa[m][v],o[We]=d[We][s[3]&48],o[Or]=!!(s[3]&8),o[Ue]=!!(s[3]&4),o[or]=el[s[3]&3],o[or]===I)return null;o[Q]=16;{let{length:p,frameLength:h,samples:y,...g}=o;t[Se](a,o,g)}return new r(o)}constructor(e){super(e),this[Z]=e[Z],this[or]=e[or],this[Oe]=e[Oe],this[Or]=e[Or],this[Ue]=e[Ue],this[Ge]=e[Ge],this[ae]=e[ae],this[We]=e[We],this[Xe]=e[Xe],this[qe]=e[qe]}};var ln=class r extends fe{static*[_e](e,t,n){return yield*super[_e](kt,r,e,t,n)}constructor(e,t,n){super(e,t,n)}};var un=class extends oe{constructor(e,t,n){super(e,t),this.Frame=ln,this.Header=kt,n(this[D])}get[D](){return Jn}*[Ve](){return yield*this[yt]()}};var tl={0:"MPEG-4",8:"MPEG-2"},rl={0:"valid",2:ne,4:ne,6:ne},nl={0:ao,1:rn},ol={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},il={0:Kn,4:Yn,8:Ys,12:ct,16:Jt,20:Qt,24:Zt,28:er,32:tr,36:jn,40:$n,44:rr,48:js,52:I,56:I,60:"frequency is written explicitly"},ca={0:{[v]:0,[S]:"Defined in AOT Specific Config"},64:{[v]:1,[S]:st},128:{[v]:2,[S]:N(2,_[0][0])},192:{[v]:3,[S]:N(3,_[1][3])},256:{[v]:4,[S]:N(4,_[1][3],_[3][4])},320:{[v]:5,[S]:N(5,_[1][3],_[3][0])},384:{[v]:6,[S]:N(6,_[1][3],_[3][0],ke)},448:{[v]:8,[S]:N(8,_[1][3],_[2][0],_[3][0],ke)}},Dt=class r extends pe{static*[P](e,t,n){let o={},i=yield*e[F](7,n),s=me([i[0],i[1],i[2],i[3]&252|i[6]&3]),a=t[P](s);if(a)Object.assign(o,a);else{if(i[0]!==255||i[1]<240||(o[Xe]=tl[i[1]&8],o[ae]=rl[i[1]&6],o[ae]===ne))return null;let l=i[1]&1;o[qe]=nl[l],o[f]=l?7:9,o[Qn]=i[2]&192,o[Be]=i[2]&60;let u=i[2]&2;if(o[Gr]=ol[o[Qn]],o[T]=il[o[Be]],o[T]===I)return null;o[Ge]=!!u,o[Yr]=(i[2]<<8|i[3])&448,o[te]=ca[o[Yr]][S],o[v]=ca[o[Yr]][v],o[Ue]=!!(i[3]&32),o[Br]=!!(i[3]&8),o[jr]=!!(i[3]&8),o[$r]=!!(i[3]&4),o[Q]=16,o[z]=1024,o[Vr]=i[6]&3;{let{length:d,channelModeBits:m,profileBits:p,sampleRateBits:h,frameLength:y,samples:g,numberAACFrames:b,...C}=o;t[Se](s,o,C)}}if(o[ce]=(i[3]<<11|i[4]<<3|i[5]>>5)&8191,!o[ce])return null;let c=(i[5]<<6|i[6]>>2)&2047;return o[Ir]=c===2047?"VBR":c,new r(o)}constructor(e){super(e),this[jr]=e[jr],this[$r]=e[$r],this[Ir]=e[Ir],this[Br]=e[Br],this[Ue]=e[Ue],this[Ge]=e[Ge],this[ae]=e[ae],this[f]=e[f],this[Xe]=e[Xe],this[Vr]=e[Vr],this[Gr]=e[Gr],this[qe]=e[qe]}get audioSpecificConfig(){let e=Y.get(this),t=e[Qn]+64<<5|e[Be]<<5|e[Yr]>>3,n=new re(2);return new xt(n[De]).setUint16(0,t,!1),n}};var dn=class r extends fe{static*[_e](e,t,n){return yield*super[_e](Dt,r,e,t,n)}constructor(e,t,n){super(e,t,n)}};var mn=class extends oe{constructor(e,t,n){super(e,t),this.Frame=dn,this.Header=Dt,n(this[D])}get[D](){return"aac"}*[Ve](){return yield*this[yt]()}};var bt=class r extends fe{static _getFrameFooterCrc16(e){return(e[e[f]-2]<<8)+e[e[f]-1]}static[so](e){let t=r._getFrameFooterCrc16(e),n=ea(e[E](0,-2));return t===n}constructor(e,t,n){t[en]=n,t[kr]=r._getFrameFooterCrc16(e),super(t,e,Y.get(t)[z])}};var la="get from STREAMINFO metadata block",sl={0:"Fixed",1:"Variable"},ua={0:I,16:192};for(let r=2;r<16;r++)ua[r<<4]=r<6?576*2**(r-2):2**r;var al={0:la,1:Yn,2:Ks,3:qs,4:rr,5:tr,6:er,7:Zt,8:Qt,9:Jt,10:ct,11:Kn,15:ne},cl={0:{[v]:1,[S]:st},16:{[v]:2,[S]:N(2,_[0][0])},32:{[v]:3,[S]:N(3,_[0][1])},48:{[v]:4,[S]:N(4,_[1][0],_[3][0])},64:{[v]:5,[S]:N(5,_[1][1],_[3][0])},80:{[v]:6,[S]:N(6,_[1][1],ke,_[3][0])},96:{[v]:7,[S]:N(7,_[1][1],ke,_[3][4],_[2][0])},112:{[v]:8,[S]:N(8,_[1][1],ke,_[3][0],_[2][0])},128:{[v]:2,[S]:`${at} (left, diff)`},144:{[v]:2,[S]:`${at} (diff, right)`},160:{[v]:2,[S]:`${at} (avg, diff)`},176:I,192:I,208:I,224:I,240:I},ll={0:la,2:8,4:12,6:I,8:16,10:20,12:24,14:I},vt=class r extends pe{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let t=1;for(let s=64;s&e[0];s>>=1)t++;let n=t-1,o=0,i=0;for(;n>0;i+=6,n--){if((e[n]&192)!==128)return null;o|=(e[n]&63)<<i}return o|=(e[n]&127>>t)<<i,{value:o,length:t}}static[Ae](e,t){let n={[F]:function*(){return e}};return r[P](n,t,0).next().value}static*[P](e,t,n){let o=yield*e[F](6,n);if(o[0]!==255||!(o[1]===248||o[1]===249))return null;let i={},s=me(o[E](0,4)),a=t[P](s);if(a)Object.assign(i,a);else{if(i[eo]=o[1]&1,i[Xr]=sl[i[eo]],i[qr]=o[2]&240,i[Be]=o[2]&15,i[Ke]=ua[i[qr]],i[Ke]===I||(i[T]=al[i[Be]],i[T]===ne)||o[3]&1)return null;let l=cl[o[3]&240];if(l===I||(i[v]=l[v],i[te]=l[S],i[Q]=ll[o[3]&14],i[Q]===I))return null}i[f]=5,o=yield*e[F](i[f]+8,n);let c=r._decodeUTF8Int(o[E](4));if(!c||(i[eo]?i[Qr]=c.value:i[Je]=c.value,i[f]+=c[f],i[qr]===96?(o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[Ke]=o[i[f]-1]+1,i[f]+=1):i[qr]===112&&(o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[Ke]=(o[i[f]-1]<<8)+o[i[f]]+1,i[f]+=2),i[z]=i[Ke],i[Be]===12?(o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[T]=o[i[f]-1]*1e3,i[f]+=1):i[Be]===13?(o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[T]=(o[i[f]-1]<<8)+o[i[f]],i[f]+=2):i[Be]===14&&(o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[T]=((o[i[f]-1]<<8)+o[i[f]])*10,i[f]+=2),o[f]<i[f]&&(o=yield*e[F](i[f],n)),i[nr]=o[i[f]-1],i[nr]!==Zs(o[E](0,i[f]-1))))return null;if(!a){let{blockingStrategyBits:l,frameNumber:u,sampleNumber:d,samples:m,sampleRateBits:p,blockSizeBits:h,crc:y,length:g,...b}=i;t[Se](s,i,b)}return new r(i)}constructor(e){super(e),this[kr]=null,this[Xr]=e[Xr],this[Ke]=e[Ke],this[Je]=e[Je],this[Qr]=e[Qr],this[en]=null}};var ul=2,dl=512*1024,Ht=class extends oe{constructor(e,t,n){super(e,t),this.Frame=bt,this.Header=vt,n(this[D])}get[D](){return"flac"}*_getNextFrameSyncOffset(e){let t=yield*this._codecParser[F](2,0),n=t[f]-2;for(;e<n;){if(t[e]===255){let i=t[e+1];if(i===248||i===249)break;i!==255&&e++}e++}return e}*[Ve](){do{let e=yield*vt[P](this._codecParser,this._headerCache,0);if(e){let t=Y.get(e)[f]+ul;for(;t<=dl;){if(this._codecParser._flushing||(yield*vt[P](this._codecParser,this._headerCache,t))){let n=yield*this._codecParser[F](t);if(this._codecParser._flushing||(n=n[E](0,t)),bt[so](n)){let o=new bt(n,e);return this._headerCache[Pe](),this._codecParser[ve](t),this._codecParser[ht](o),o}}t=yield*this._getNextFrameSyncOffset(t+1)}this._codecParser[ze](`Unable to sync FLAC frame after searching ${t} bytes.`),this._codecParser[ve](t)}else this._codecParser[ve](yield*this._getNextFrameSyncOffset(1))}while(!0)}[gt](e){return e[X]===0?(this._headerCache[Pe](),this._streamInfo=e[k][E](13)):e[X]===1||(e[ee]=$.get(e)[be].map(t=>{let n=vt[Ae](t,this._headerCache);if(n)return new bt(t,n,this._streamInfo);this._codecParser[ze]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")}).filter(t=>!!t)),e}};var Ot=class r{static*[P](e,t,n){let o={},i=yield*e[F](28,n);if(i[0]!==79||i[1]!==103||i[2]!==103||i[3]!==83||(o[yi]=i[4],i[5]&248))return null;o[de]=!!(i[5]&4),o[ut]=!!(i[5]&2),o[lt]=!!(i[5]&1);let a=new xt(re.from(i[E](0,28))[De]);o[Te]=ra(a,6),o[Ne]=a.getInt32(14,!0),o[X]=a.getInt32(18,!0),o[Tt]=a.getInt32(22,!0);let c=i[26];o[f]=c+27,i=yield*e[F](o[f],n),o[ce]=0,o[pt]=[],o[sr]=re.from(i[E](27,o[f]));for(let l=0,u=0;l<c;l++){let d=o[sr][l];o[ce]+=d,u+=d,(d!==255||l===c-1)&&(o[pt].push(u),u=0)}return new r(o)}constructor(e){Y.set(this,e),this[Te]=e[Te],this[lt]=e[lt],this[ut]=e[ut],this[de]=e[de],this[pt]=e[pt],this[X]=e[X],this[Tt]=e[Tt],this[Ne]=e[Ne]}};var fn=class r extends It{static*[_e](e,t,n){let o=yield*Ot[P](e,t,n);if(o){let i=Y.get(o)[ce],s=Y.get(o)[f],a=s+i,c=(yield*e[F](a,0))[E](0,a),l=c[E](s,a);return new r(o,l,c)}else return null}constructor(e,t,n){super(e,t),$.get(this)[f]=n[f],this[ee]=[],this[fi]=n,this[Te]=e[Te],this[Dr]=e[Tt],this[He]=0,this[lt]=e[lt],this[ut]=e[ut],this[de]=e[de],this[X]=e[X],this[z]=0,this[Ne]=e[Ne]}};var cr=class extends fe{constructor(e,t,n){super(t,e,n)}};var da={0:Tr.slice(0,2),1:Tr},Me="SILK-only",J="CELT-only",xo="Hybrid",St="narrowband",bo="medium-band",_t="wideband",lr="super-wideband",ur="fullband",ml={0:{[M]:Me,[w]:St,[A]:10},8:{[M]:Me,[w]:St,[A]:20},16:{[M]:Me,[w]:St,[A]:40},24:{[M]:Me,[w]:St,[A]:60},32:{[M]:Me,[w]:bo,[A]:10},40:{[M]:Me,[w]:bo,[A]:20},48:{[M]:Me,[w]:bo,[A]:40},56:{[M]:Me,[w]:bo,[A]:60},64:{[M]:Me,[w]:_t,[A]:10},72:{[M]:Me,[w]:_t,[A]:20},80:{[M]:Me,[w]:_t,[A]:40},88:{[M]:Me,[w]:_t,[A]:60},96:{[M]:xo,[w]:lr,[A]:10},104:{[M]:xo,[w]:lr,[A]:20},112:{[M]:xo,[w]:ur,[A]:10},120:{[M]:xo,[w]:ur,[A]:20},128:{[M]:J,[w]:St,[A]:2.5},136:{[M]:J,[w]:St,[A]:5},144:{[M]:J,[w]:St,[A]:10},152:{[M]:J,[w]:St,[A]:20},160:{[M]:J,[w]:_t,[A]:2.5},168:{[M]:J,[w]:_t,[A]:5},176:{[M]:J,[w]:_t,[A]:10},184:{[M]:J,[w]:_t,[A]:20},192:{[M]:J,[w]:lr,[A]:2.5},200:{[M]:J,[w]:lr,[A]:5},208:{[M]:J,[w]:lr,[A]:10},216:{[M]:J,[w]:lr,[A]:20},224:{[M]:J,[w]:ur,[A]:2.5},232:{[M]:J,[w]:ur,[A]:5},240:{[M]:J,[w]:ur,[A]:10},248:{[M]:J,[w]:ur,[A]:20}},dr=class r extends pe{static[Ae](e,t,n){let o={};if(o[v]=e[9],o[Ye]=e[18],o[f]=o[Ye]!==0?21+o[v]:19,e[f]<o[f])throw new Error("Out of data while inside an Ogg Page");let i=t[0]&3,s=i===3?2:1,a=me(e[E](0,o[f]))+me(t[E](0,s)),c=n[P](a);if(c)return new r(c);if(a.substr(0,8)!=="OpusHead"||e[8]!==1)return null;o[k]=re.from(e[E](0,o[f]));let l=new xt(o[k][De]);if(o[Q]=16,o[Ct]=l.getUint16(10,!0),o[Jr]=l.getUint32(12,!0),o[T]=ct,o[Ur]=l.getInt16(16,!0),o[Ye]in da&&(o[te]=da[o[Ye]][o[v]-1],!o[te]))return null;o[Ye]!==0&&(o[Zr]=e[19],o[Rr]=e[20],o[Kr]=[...e[E](21,o[v]+21)]);let u=ml[248&t[0]];switch(o[M]=u[M],o[w]=u[w],o[A]=u[A],i){case 0:o[$e]=1;break;case 1:case 2:o[$e]=2;break;case 3:o[Nr]=!!(128&t[1]),o[Hr]=!!(64&t[1]),o[$e]=63&t[1];break;default:return null}{let{length:d,data:m,channelMappingFamily:p,...h}=o;n[Se](a,o,h)}return new r(o)}constructor(e){super(e),this[k]=e[k],this[w]=e[w],this[Ye]=e[Ye],this[Kr]=e[Kr],this[Rr]=e[Rr],this[$e]=e[$e],this[A]=e[A],this[Hr]=e[Hr],this[Jr]=e[Jr],this[Nr]=e[Nr],this[M]=e[M],this[Ur]=e[Ur],this[Ct]=e[Ct],this[Zr]=e[Zr]}};var pn=class extends oe{constructor(e,t,n){super(e,t),this.Frame=cr,this.Header=dr,n(this[D]),this._identificationHeader=null,this._preSkipRemaining=null}get[D](){return"opus"}[gt](e){return e[X]===0?(this._headerCache[Pe](),this._identificationHeader=e[k]):e[X]===1||(e[ee]=$.get(e)[be].map(t=>{let n=dr[Ae](this._identificationHeader,t,this._headerCache);if(n){this._preSkipRemaining===null&&(this._preSkipRemaining=n[Ct]);let o=n[A]*n[$e]/1e3*n[T];return this._preSkipRemaining>0&&(this._preSkipRemaining-=o,o=this._preSkipRemaining<0?-this._preSkipRemaining:0),new cr(t,n,o)}this._codecParser[oo]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")})),e}};var mr=class extends fe{constructor(e,t,n){super(t,e,n)}};var Li={};for(let r=0;r<8;r++)Li[r+6]=2**(6+r);var hn=class r extends pe{static[Ae](e,t,n,o){if(e[f]<30)throw new Error("Out of data while inside an Ogg Page");let i=me(e[E](0,30)),s=t[P](i);if(s)return new r(s);let a={[f]:30};if(i.substr(0,7)!=="vorbis")return null;a[k]=re.from(e[E](0,30));let c=new xt(a[k][De]);if(a[dt]=c.getUint32(7,!0),a[dt]!==0||(a[v]=e[11],a[te]=Tr[a[v]-1]||"application defined",a[T]=c.getUint32(12,!0),a[zr]=c.getInt32(16,!0),a[Pr]=c.getInt32(20,!0),a[Fr]=c.getInt32(24,!0),a[ft]=Li[(e[28]&240)>>4],a[mt]=Li[e[28]&15],a[mt]>a[ft])||e[29]!==1)return null;a[Q]=32,a[ir]=o,a[Wr]=n;{let{length:l,data:u,version:d,vorbisSetup:m,vorbisComments:p,...h}=a;t[Se](i,a,h)}return new r(a)}constructor(e){super(e),this[zr]=e[zr],this[Fr]=e[Fr],this[Pr]=e[Pr],this[mt]=e[mt],this[ft]=e[ft],this[k]=e[k],this[Wr]=e[Wr],this[ir]=e[ir]}};var yn=class extends oe{constructor(e,t,n){super(e,t),this.Frame=mr,n(this[D]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[D](){return Et}[gt](e){e[ee]=[];for(let t of $.get(e)[be])if(t[0]===1)this._headerCache[Pe](),this._identificationHeader=e[k],this._setupComplete=!1;else if(t[0]===3)this._vorbisComments=t;else if(t[0]===5)this._vorbisSetup=t,this._mode=this._parseSetupHeader(t),this._setupComplete=!0;else if(this._setupComplete){let n=hn[Ae](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);n?e[ee].push(new mr(t,n,this._getSamples(t,n))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return e}_getSamples(e,t){let o=this._mode.blockFlags[e[0]>>1&this._mode.mask]?t[ft]:t[mt],i=this._prevBlockSize===null?0:(this._prevBlockSize+o)/4;return this._prevBlockSize=o,i}_parseSetupHeader(e){let t=new co(e),n={count:0,blockFlags:[]};for(;(t.read(1)&1)!==1;);let o;for(;n.count<64&&t.position>0;){nn(t.read(8));let i=0;for(;t.read(8)===0&&i++<3;);if(i===4)o=t.read(7),n.blockFlags.unshift(o&1),t.position+=6,n.count++;else{((nn(o)&126)>>1)+1!==n.count&&this._codecParser[ze]("vorbis derived mode count did not match actual mode count");break}}return n.mask=(1<<Math.log2(n.count))-1,n}};var Ci=class{constructor(e,t,n){this._codecParser=e,this._headerCache=t,this._onCodec=n,this._continuedPacket=new re,this._codec=null,this._isSupported=null,this._previousAbsoluteGranulePosition=null}get[D](){return this._codec||""}_updateCodec(e,t){this._codec!==e&&(this._headerCache[Fe](),this._parser=new t(this._codecParser,this._headerCache,this._onCodec),this._codec=e)}_checkCodecSupport({data:e}){let t=me(e[E](0,8));switch(t){case"fishead\0":return!1;case"OpusHead":return this._updateCodec("opus",pn),!0;case(/^\x7fFLAC/.test(t)&&t):return this._updateCodec("flac",Ht),!0;case(/^\x01vorbis/.test(t)&&t):return this._updateCodec(Et,yn),!0;default:return!1}}_checkPageSequenceNumber(e){e[X]!==this._pageSequenceNumber+1&&this._pageSequenceNumber>1&&e[X]>1&&this._codecParser[ze]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[X]}`),this._pageSequenceNumber=e[X]}_parsePage(e){this._isSupported===null&&(this._pageSequenceNumber=e[X],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);let t=$.get(e),n=Y.get(t[ue]),o=0;if(t[be]=n[pt].map(i=>e[k][E](o,o+=i)),this._continuedPacket[f]&&(t[be][0]=on(this._continuedPacket,t[be][0]),this._continuedPacket=new re),n[sr][n[sr][f]-1]===255&&(this._continuedPacket=on(this._continuedPacket,t[be].pop())),this._previousAbsoluteGranulePosition!==null&&(e[z]=Number(e[Te]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[Te],this._isSupported){let i=this._parser[gt](e);return this._codecParser[ht](i),i}else return e}},gn=class extends oe{constructor(e,t,n){super(e,t),this._onCodec=n,this.Frame=fn,this.Header=Ot,this._streams=new Map,this._currentSerialNumber=null}get[D](){let e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[Ve](){let e=yield*this[yt](!0);this._currentSerialNumber=e[Ne];let t=this._streams.get(this._currentSerialNumber);return t||(t=new Ci(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,t)),e[de]&&this._streams.delete(this._currentSerialNumber),t._parsePage(e)}};var Ei=()=>{},xn=class{constructor(e,{onCodec:t,onCodecHeader:n,onCodecUpdate:o,enableLogging:i=!1,enableFrameCRC32:s=!0}={}){this._inputMimeType=e,this._onCodec=t||Ei,this._onCodecHeader=n||Ei,this._onCodecUpdate=o,this._enableLogging=i,this._crc32=s?ta:Ei,this[Fe]()}get[D](){return this._parser?this._parser[D]:""}[Fe](){this._headerCache=new sn(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[Fe]()}*parseChunk(e){for(let t=this._generator.next(e);t.value;t=this._generator.next())yield t.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new mn(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new un(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new Ht(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/ogg/))this._parser=new gn(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[Ve]();e&&(yield e)}}*[F](e=0,t=0){let n;for(;this._rawData[f]<=e+t;){if(n=yield,this._flushing)return this._rawData[E](t);n&&(this._totalBytesIn+=n[f],this._rawData=on(this._rawData,n))}return this._rawData[E](t)}[ve](e){this._currentReadPosition+=e,this._rawData=this._rawData[E](e)}[tn](e){this._sampleRate=e[ue][T],e[ue][Z]=e[He]>0?Math.round(e[k][f]/e[He])*8:0,e[Je]=this._frameNumber++,e[zt]=this._totalBytesOut,e[Pt]=this._totalSamples,e[Ft]=this._totalSamples/this._sampleRate*1e3,e[Dr]=this._crc32(e[k]),this._headerCache[io](e[ue][Z],e[Ft]),this._totalBytesOut+=e[k][f],this._totalSamples+=e[z]}[ht](e){if(e[ee]){if(e[de]){let t=e[z];e[ee].forEach(n=>{let o=n[z];t<o&&(n[z]=t>0?t:0,n[He]=n[z]/n[ue][T]*1e3),t-=o,this[tn](n)})}else e[z]=0,e[ee].forEach(t=>{e[z]+=t[z],this[tn](t)});e[He]=e[z]/this._sampleRate*1e3||0,e[Pt]=this._totalSamples,e[Ft]=this._totalSamples/this._sampleRate*1e3||0,e[zt]=this._totalBytesOut}else this[tn](e)}_log(e,t){if(this._enableLogging){let n=[`${D}: ${this[D]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${zt}: ${this._totalBytesOut}`],o=Math.max(...n.map(i=>i[f]));t.push(`--stats--${"-".repeat(o-9)}`,...n,"-".repeat(o)),e("codec-parser",t.reduce((i,s)=>i+`
|
|
4
|
+
`+s,""))}}[ze](...e){this._log(console.warn,e)}[oo](...e){this._log(console.error,e)}};var ma=xn;var vo=ee;var So=k;var fa=ue;var pa=de;var ha=ir;var ya=Pt;function Qe(r){var e=e;function t(){}e={};function n(x){throw x}var o,i,s,a,c,l,u,d,m,p,h;function y(){var x=h.buffer;o=new Int8Array(x),i=new Int16Array(x),a=new Uint8Array(x),c=new Uint16Array(x),s=new Int32Array(x),l=new Uint32Array(x),u=new Float32Array(x),d=new Float64Array(x),m=new BigInt64Array(x),p=new BigUint64Array(x)}for(var g=x=>{for(var ye,vr,Gt=0,En=0,Tn=x.length,zn=new Uint8Array((Tn*3>>2)-(x[Tn-2]=="=")-(x[Tn-1]=="="));Gt<Tn;Gt+=4,En+=3)ye=he[x.charCodeAt(Gt+1)],vr=he[x.charCodeAt(Gt+2)],zn[En]=he[x.charCodeAt(Gt)]<<2|ye>>4,zn[En+1]=ye<<4|vr>>2,zn[En+2]=vr<<6|he[x.charCodeAt(Gt+3)];return zn},b=()=>n(""),C=()=>{},L={},q=x=>x(),G=()=>performance.now(),Le=(x,ye)=>{if(L[x]&&(clearTimeout(L[x].id),delete L[x]),!ye)return 0;var vr=setTimeout(()=>{delete L[x],q(()=>us(x,G()))},ye);return L[x]={id:vr,timeout_ms:ye},0},B=Math.atan,K=Math.cos,Ie=Math.exp,Ce=Math.log,et=Math.pow,br=Math.sin,Ut=x=>{var ye=a.length;return x>>>=0,!1},tt=x=>{throw`exit(${x})`},he=new Uint8Array(123),rt=25;rt>=0;--rt)he[48+rt]=52+rt,he[65+rt]=rt,he[97+rt]=26+rt;he[43]=62,he[47]=63;var qa={e:b,d:C,f:Le,b:B,a:K,i:Ie,h:Ce,g:et,c:br,k:Ut,j:tt};function Ka(x){ns=x.n,os=x.o,is=x.p,ss=x.q,as=x.r,cs=x.s,ls=x.t,us=x.v}var ns,os,is,ss,as,cs,ls,us;function Ya(x){x.m()}Qe.wasm||Object.defineProperty(Qe,"wasm",{get:()=>String.raw`dynEncode012091253f87dì%nä= 4&¿nÝØäÂLÚªã9ÚØ[äº\ ¼¡³R=}L]Èÿ2 ÿù¶J1jj¡é,zäV|i¸Qk¹=
|
|
5
5
|
¨¨%ýv²±»oúâLa:ê±ÊäÌÓ.÷Øý×>àW>z¯°8¯ñ\Ñós9\§ôÊ@Ü (tÃø4° ¢7fqÓg²Jè6x[zç®&4=} p.(°tÍÞã¾>÷CõË"*k?¿~7~H2ÛÜâ.ÏQä;6{ÜãFÑá'DD¤±°HQ>MínÎÏÎöʵÑÓ
ÞÌP¼P¨Þ*X²E=M¦qíxMñ=MÌë4/<gNO/¢ ¢>a~Ï®ììììì0ìa笡çëOÓÇM Q9tùµyuéµµÞÏ/±Óõò}E{òÓJ¹Û|·ôfÒ c¬Wêaûÿlʽp¹|)ÖEL¦ }ypÕSϹI]¢ºãæ°ÿo¶7ÛRq¾ÔÅEߨ]æËwÚ{óçVwó1¾EØpàe"Æùû¡Áª Ààð´LõÎxEÓ¢N¦
9ëùi& Ò§Ø!ÇFçS=MbäO?߷縪7ùa}5ðûÕtsUþ£KïgN¾)ø§\V0uSIö:ÌU4ж¯´Õn9ÔèE£ZƼ{hµmÙ¾6ÆÑ+xñ´«þ¸=Mߤ·å®«ïÆGFÝì|H?äE"þ!9«Æïpæ'][¯ù·£W÷O§&#ax$qf=}ø ô bÏ×W÷LôoÝWQÕÓ)u÷½èV|¥Gà¨Ö¸@ê|ÇK5ò A·Â9CS2¸¼¿,äÝÑÝy!ÑR%ÆÝÎ0Âv§ qTcó±hØÉã=}Z=}Ælüën¯ð(-°ÜwVÏï.th¥íS~SÏ»ZZÔZ
|
|
6
6
|
3BÌÛ¬<éæO)ÎyÚ¯O*®uìÛ$öI¥Ý9ôø³\¤ò³Ù¹ÇP¸J×y@ÔyOÇmô½ü¾|S?2àú¤F?½ûoo3ô;<àáûÜ8ì²7ïë¨RäY¹|ÓºÌF,Ð-¸*\P!FJÒ8= o6HwLrúº¶ÐÛ\Ù¬o¢9IqÝ.ôf¶ÎÈ{Ī×N|Mfs
¤ÉÝàâ§*+ã§ô¯î¬7ç×§ä)!Z¨É,Äp~ý·wsSGóäsE\ýïé§Ö:Ò'Cç(_X$\¦½eÒ8$XF|eíÙÓ¡¤Û<ØÞÛ¸9¿ðÃÎ#b~× 4éîÿÏq
|
|
7
7
|
ód|0wU&®è·vh6¨{ÚçÚ18Ó(ÓY\0¦= çèíß)Ø=}[xü-v?N(Kkg0}âÚ´ð¬ÕQNÍ¢usѳ=}. ëg
û= ÍMBp'²¨ x4è@9t§eݵ¾âð½ z?Z¹FH'̯¿<K,üµ<{ ¶JãývåàÆeù0Ð"F¥ÃÒÞþÔÉvCzl}ðN£ Í^P%²¸FX»WÎêô¶
äÉJ^g×SÃã.Ät*'ªG«ÒB<ÜÓ
¿ºp\àuV¯£ÅݽáÞ ùß=}ÎÚ^ÿí>¥!¨ â=M·?*/¤"å)â·ÿîÿî*(%*2[½"üríÔ4l½»a}¯CwpCÓèìGc-ã6®=M32k?Êg
!So-x>³G+ã@ò, ÁïáåN0þÙè.~È÷¡vTr¶Ã[üB±º»ávëw¹{pܺû"Aæ±9Æ^¹³òïRIAy5GÂwÉf4@Tù|qý7ðªwBL|Ôqv!ª°|]KiÐJVQ5¸åõ§å"H¼0e¬<óBîÚSÏUìHPÙA+çÉ'seÌNf°@ÈM,ð½egÖ¬x©û½2~«Ò1;Ö«
¯°4&90èE»Ó׺çʧJ<Æ¿&~Nu¼ãÙµ¢.UÇä(qQô^ö·%!É
|
|
@@ -138,7 +138,7 @@ KÙ:KµºKí{K]ûK£[KÚKóKÓ½R׿ÿ'P^j9TîçmóþL¿_o©×hÙtÙ
|
|
|
138
138
|
Ái;ªäÀ%n= =M+W= ÓÖc[aS
|
|
139
139
|
FÁð]NôÝ'= qr(¶ù¤nü«òÿ¿d&ÿÈõT4Þ=}z|ö ¿OW×SMtdH.ÏãRX&§o3ØÜXÍ^ÊMí£W´iâ]NüOå£S£Å·ç÷ݧ½GÑUy¹¦ß§/6P0(Cúýb"þ¥°VÙÄá£ÓÙ@¾YýòD{òÃv?EP©=MBé\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±ÏÁÕ¯¦ðvZmT}3xËz×cºrÑM=Mc-É©Ô7½wæc§Î»cû¾yfÙWòÆÝÔc¥³ôØf«Äñ·9ø%g:y^+{U]¤þ
[&fÓÏYë«Gªõ¹¦Öðþ¬moÛø?/ÛS.[S9ÛùC
/û2²Y£ÎÑ%/sy¢×ÌùJW6Oí\g0^JùêßÏ0í[Ü'ÏÔ>À-¿[ÔW?Y]±ØÙÃî<~ÎëR~Ìf¾Z/×¼_á¾Þê+îoÐñ{Þ\e3K%©¹§íB¹§(c=}ËÈ·SzÔnf§èx}o\9öf|%Ýå¥~©IÇüñY8}Ffú@Rú1éþ3÷ËótQøvû|³Îaá,Óé>BG6Òê}ÃJ|¶=}°öf6õk¶ÌºHgNjÒ{æ¾M;9·é§WèO±Ä3ÒËÒyt ;ù´à©a|Ó^!ÝøûÂÄ
|
|
140
140
|
(VV¸ÇÙcÏ>yoçzÃvòG{3Þ£½c×ôíÅé;°OÛGØ<wÜW> rU]q{û'ùÝír{*øï?t-ígùWÿ
&§]m}×ût¥Ë~ß&>&Õv!b#ÅÌq¢µ|jÍüùÉ^Æ&ôþ~sIµ"]d)uâ´ºvk Å\<Íÿöê½Â
|
|
141
|
-
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var La={a:Aa};this.setModule=x=>{t.setModule(qe,x)},this.getModule=()=>t.getModule(qe),this.instantiate=()=>(this.getModule().then(x=>WebAssembly.instantiate(x,La)).then(x=>{let me=x.exports;wa(me),y=me.l,h(),Ma(me),r()}),this.ready=new Promise(x=>{r=x}).then(()=>{this.HEAP=y.buffer,this.malloc=Gi,this.free=$i,this.create_decoder=Ui,this.send_setup=Wi,this.init_dsp=Xi,this.decode_packets=Ki,this.destroy_decoder=qi}),this)}function It(){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 o=0;o<t.length;o++){let i=t[o];this._input.buf.set(i),this._inputLen.buf[0]=i.length,this._common.wasm.decode_packets(this._decoder);let s=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 u=new Float32Array(s);s&&u.set(new Float32Array(this._common.wasm.HEAP,c[l],s)),a.push(u)}e.push(a),r+=s,this._frameNumber++,this._inputBytes+=i.length,this._outputSamples+=s;for(let l=0;l<this._errorsLength.buf;l+=2){let u=this._common.codeToString(this._errors.buf[l]),d=this._common.codeToString(this._errors.buf[l+1]);n.push({message:u+" vorbis_synthesis"+d,frameLength:i.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=It.isWebWorker,this._WASMAudioDecoderCommon=It.WASMAudioDecoderCommon||D,this._EmscriptenWASM=It.EmscriptenWASM||qe,this._module=It.module,this._inputSize=128*1024,this._ready=this._init(),this}var ho=Symbol(),$e=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new D,this._init(),this._ready=this[ho](It)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new js("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[ho](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 i=0;i<e.length;i++){let s=e[i];if(this._vorbisSetupInProgress&&(s[po][0]===1&&this._decoder.sendSetupHeader(s[po]),s[fo].length)){let a=s[fo][0][Js];this._decoder.sendSetupHeader(a[Zs]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...s[fo].map(a=>a[po]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let o=e[e.length-1];if(o&&o[Qs]){let i=this._totalSamplesDecoded-o[ea];if(i>0){for(let s=0;s<n.channelData.length;s++)n.channelData[s]=n.channelData[s].subarray(0,n.samplesDecoded-i);n.samplesDecoded-=i,this._totalSamplesDecoded-=i}}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 vi=class extends Xt{constructor(e){super(e,"ogg-vorbis-decoder",It,qe)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},fn=class extends $e{constructor(){super(),this._ready=super[ho](vi)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};On($e,"OggVorbisDecoder");On(fn,"OggVorbisDecoderWebWorker");var _i=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function yo(t,e=new $e){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new _i(n.map(o=>o.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var pn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},cr=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new Qe(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 i=(await this.vfs.readFile(e)).slice().buffer,s=await this.decodeByExtension(e,i);return this.cache.set(r,s),this.refCounts.set(r,1),s}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 o=Nn(r),i=o.channels,s=Array.from({length:i},()=>new Float32Array(o.samples.length/i));for(let a=0;a<o.samples.length;a+=1)s[a%i][Math.floor(a/i)]=o.samples[a];return{sampleRate:o.sampleRate,channels:i,bitDepth:o.bitsPerSample,channelData:s}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return yo(r);throw new pn(`Unsupported audio format: ${e}`)}};var Gc="quake2ts-pak-indexes",Wc="pak-indexes";function ta(){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 hn(t,e){let r=ta();return r?new Promise((n,o)=>{let i=r.open(t,1);i.onupgradeneeded=()=>{let{result:s}=i;s.objectStoreNames.contains(e)||s.createObjectStore(e,{keyPath:"key"})},i.onerror=()=>o(i.error??new Error("Unknown IndexedDB error")),i.onsuccess=()=>n(i.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function yn(t,e,r,n){return new Promise((o,i)=>{let a=t.transaction(e,r).objectStore(e),c=n(a);c.onsuccess=()=>o(c.result),c.onerror=()=>i(c.error??new Error("IndexedDB transaction error"))})}function Ai(t,e){return`${U(t)}:${e.toString(16)}`}function Xc(t){return t.map(e=>({...e}))}var go=class{constructor(e=Gc,r=Wc){this.dbName=e;this.storeName=r}get isSupported(){return!!ta()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ai(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:Xc(r.entries)},o=await hn(this.dbName,this.storeName);return await yn(o,this.storeName,"readwrite",i=>i.put(n)),o.close(),n}async find(e,r){if(!this.isSupported)return;let n=await hn(this.dbName,this.storeName),o=r!==void 0?Ai(e,r):void 0,i=await yn(n,this.storeName,"readonly",s=>o?s.get(o):s.getAll());if(n.close(),!!i){if(Array.isArray(i)){let s=U(e),a=i.filter(c=>U(c.name)===s);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return i}}async remove(e,r){if(!this.isSupported)return!1;let n=await hn(this.dbName,this.storeName),o=r!==void 0?Ai(e,r):void 0,i=await yn(n,this.storeName,"readwrite",s=>{if(o)return s.delete(o);let a=`${U(e)}:`;return s.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof i=="number"?i>0:!0}async clear(){if(!this.isSupported)return;let e=await hn(this.dbName,this.storeName);await yn(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await hn(this.dbName,this.storeName),r=await yn(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,o)=>o.persistedAt-n.persistedAt)}};var kt=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},gn=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(o=>n.dependencies.add(o)),this.nodes.set(e,n),r.forEach(o=>{this.nodes.has(o)||this.nodes.set(o,{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 kt(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 o of r.dependencies)this.nodes.get(o)?.loaded||n.push(o);return n}},xo=class{constructor(e,r={}){this.vfs=e;this.textures=new Wt({capacity:r.textureCacheCapacity??128}),this.audio=new cr(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new gn,this.md2=new Ut(e),this.md3=new Gt(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),o=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,o);let i=this.dependencyTracker.missingDependencies(n);if(i.length>0)throw new kt(i,`Asset ${n} is missing dependencies: ${i.join(", ")}`);let s=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),s}async loadMd3Model(e,r=[]){let n=this.makeKey("model",e),o=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,o);let i=this.dependencyTracker.missingDependencies(n);if(i.length>0)throw new kt(i,`Asset ${n} is missing dependencies: ${i.join(", ")}`);let s=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),s}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset()}makeKey(e,r){return`${e}:${U(r)}`}};var wi=32,bo=(d=>(d[d.Auto=0]="Auto",d[d.Weapon=1]="Weapon",d[d.Voice=2]="Voice",d[d.Item=3]="Item",d[d.Body=4]="Body",d[d.Aux=5]="Aux",d[d.Footstep=6]="Footstep",d[d.Aux3=7]="Aux3",d[d.NoPhsAdd=8]="NoPhsAdd",d[d.Reliable=16]="Reliable",d[d.ForcePos=32]="ForcePos",d))(bo||{}),ra=-1,So=0,na=1,oa=2,ia=3,lr=80,sa=.003;function Rt(t){return t===3?t*.001:t*5e-4}function vo(t){let e=Rt(t);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var _o=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 Ao(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),o=e.createBiquadFilter?.();return o?(o.type="lowpass",o.frequency.value=2e4,o.Q.value=.707,r.connect(o),o.connect(n)):r.connect(n),n.connect(e.destination),{context:e,master:r,compressor:n,filter:o}}var wo=class{constructor(e=new Bt){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 Mo=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(i=>this.normalize(i)))],n={loaded:[],skipped:[],missing:[],errors:{}},o=this.contextController.getContext();for(let i of r)try{let s=this.registry.find(i);if(s!==void 0&&this.registry.has(s)){n.skipped.push(i);continue}if(!this.vfs.stat(i)){n.missing.push(i);continue}let l=(await this.vfs.readFile(i)).slice().buffer,u=await this.decodeAudio(o,l);this.registry.register(i,u),n.loaded.push(i)}catch(s){let a=s instanceof Error?s:new Error(String(s));n.errors[i]=a}return n}normalize(e){let r=U(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:U(`${this.soundRoot}${r}`)}};var Kc=7,xn=t=>t&Kc;function Lo(t){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function Co(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let o=xn(r),i=-1,s=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let c=t[a],l=xn(c.entchannel);if(o!==0&&c.entnum===e&&l===o){i=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let u=c.endTimeMs-n.nowMs;(i===-1||u<s)&&(s=u,i=a)}return i===-1?void 0:i}function Eo(t,e,r,n,o){if(o)return{left:r,right:r,distanceComponent:0};let i=Qi(t,e.origin),s=Go(i),a=Zi(i),c=s-80;c<0&&(c=0),c*=Rt(n);let l=Uo(e.right,a),u=e.mono??!1,d=u||n===0?1:.5*(1+l),f=u||n===0?1:.5*(1-l),p=Math.max(0,Math.floor(r*(1-c)*d));return{left:Math.max(0,Math.floor(r*(1-c)*f)),right:p,distanceComponent:c}}var To=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=Lo(e.playerEntity),this.listener=e.listener??{origin:Ji,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=Ao(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,o=n.currentTime*1e3,i=Co(this.channels,e.entity,e.channel,{nowMs:o,playerEntity:this.playerEntity});if(i===void 0)return;let s=this.activeSources.get(i);s&&(s.source.onended=null,s.source.stop(),this.activeSources.delete(i));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),u=this.createPanner(n,e.attenuation),d=this.resolveOcclusion?.(this.listener,c,e.attenuation),f=aa(d?.gainScale??1),p=this.resolveOcclusion?this.createOcclusionFilter(n,d?.lowpassHz??2e4):void 0;this.applyOriginToPanner(u,c);let y=e.entity===this.playerEntity,h=Eo(c,this.listener,e.volume,e.attenuation,y),b=(e.volume===0?0:Math.max(h.left,h.right)/Math.max(1,e.volume))*(e.volume/255)*this.masterVolume*this.sfxVolume;l.gain.value=b*f;let T=n.currentTime+(e.timeOffsetMs??0)/1e3,P=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+T*1e3;a.connect(u),p?(u.connect(p),p.connect(l)):u.connect(l),l.connect(this.graph.master),a.start(T),a.onended=()=>{this.channels[i].active=!1,this.activeSources.delete(i)};let ne={channelIndex:i,entnum:e.entity,entchannel:xn(e.channel),endTimeMs:P,source:a,panner:u,gain:l,baseGain:b,origin:c,attenuation:e.attenuation,occlusion:p?{scale:f,lowpassHz:d?.lowpassHz,filter:p}:d?{scale:f,lowpassHz:d.lowpassHz}:void 0};return this.channels[i]={entnum:e.entity,entchannel:xn(e.channel),endTimeMs:P,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(i,ne),ne}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 o=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,o)}}positionedSound(e,r,n,o){return this.play({entity:0,channel:0,soundIndex:r,volume:n,attenuation:o,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=Rt(r);return e.refDistance=80,e.maxDistance=vo(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=Mi(r,10,2e4),n}applyOcclusion(e,r){let n=aa(r?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let o=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Mi(o,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Mi=(t,e,r)=>Math.min(r,Math.max(e,t)),aa=t=>Mi(t,0,1);var zo=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 o=await this.resolveSource(e),i=this.createElement();i.src=o,i.loop=r,i.volume=this.volume,i.currentTime=0,i.load(),await i.play(),this.element=i,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 Po=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,o,i,s){this.system.play({entity:e,channel:r,soundIndex:n,volume:o,attenuation:i,timeOffsetMs:s})}positioned_sound(e,r,n,o){this.system.positionedSound(e,r,n,o)}loop_sound(e,r,n,o,i){this.system.play({entity:e,channel:r,soundIndex:n,volume:o,attenuation:i,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 qc(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 $c(t,e,r,n){for(let o of e){let i=t.getExtension(o);if(!i)throw new Error(`Missing required WebGL extension: ${o}`);n.set(o,i)}for(let o of r){let i=t.getExtension(o);i&&n.set(o,i)}}function ca(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:o=[]}=e,i=t.getContext("webgl2",r??{antialias:!0});if(!i)throw new Error("WebGL2 not supported or failed to initialize");qc(i);let s=new Map;$c(i,n,o,s);let a=!1,c=new Set,l=new Set,u=f=>{a=!0,f.preventDefault();for(let p of c)p()},d=()=>{a=!1;for(let f of l)f()};return t.addEventListener("webglcontextlost",u),t.addEventListener("webglcontextrestored",d),{gl:i,extensions:s,isLost:()=>a,onLost(f){return c.add(f),()=>c.delete(f)},onRestored(f){return l.add(f),()=>l.delete(f)},dispose(){t.removeEventListener("webglcontextlost",u),t.removeEventListener("webglcontextrestored",d),c.clear(),l.clear(),s.clear()}}}function la(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 i=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(i)}return n}function Yc(t,e,r,n){let o=t.createProgram();if(!o)throw new Error("Failed to allocate shader program");if(t.attachShader(o,e),t.attachShader(o,r),n)for(let[s,a]of Object.entries(n))t.bindAttribLocation(o,a,s);if(t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS)){let s=t.getProgramInfoLog(o)??"Unknown shader link failure";throw t.deleteProgram(o),new Error(s)}return o}var Me=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 o=la(e,e.VERTEX_SHADER,r.vertex),i=la(e,e.FRAGMENT_SHADER,r.fragment);try{let s=Yc(e,o,i,n);return new t(e,s)}finally{e.deleteShader(o),e.deleteShader(i)}}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 ua(t,e,r){return Me.create(t,e,r)}var Le=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let o=e.createBuffer();if(!o)throw new Error("Failed to allocate buffer");this.buffer=o,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)}},yt=class extends Le{constructor(e,r=e.STATIC_DRAW){super(e,r,e.ELEMENT_ARRAY_BUFFER)}},Re=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)}},ur=class{constructor(e,r=e.TEXTURE_2D){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)}uploadImage(e,r,n,o,i,s,a,c){this.bind(),this.gl.texImage2D(this.target,e,r,n,o,i,s,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},dr=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,o,i,s,a,c,l){this.bind(),this.gl.texImage2D(e,r,n,o,i,s,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},Fo=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 Ci=4,Li=7*Ci,Ei=[{index:0,size:3,type:5126,stride:Li,offset:0},{index:1,size:2,type:5126,stride:Li,offset:3*Ci},{index:2,size:2,type:5126,stride:Li,offset:5*Ci}];function jc(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function Jc(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 Qc(t,e,r){let n=Jc(r),o=t.width*4,i=e.x+t.padding,s=e.y+t.padding,a=0;for(let c=0;c<r.height;c++){let l=(s+c)*o+i*4;for(let u=0;u<r.width;u++){let d=l+u*4;t.data[d]=r.samples[a],t.data[d+1]=r.samples[a+1],t.data[d+2]=r.samples[a+2],t.data[d+3]=n===4?r.samples[a+3]:255,a+=n}}}function Zc(t,e,r){let n=e.width+r.lightmapPadding*2,o=e.height+r.lightmapPadding*2;if(n>r.atlasSize||o>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+o>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,o),{placement:c,atlas:a}}let i=jc(r.atlasSize,r.lightmapPadding);t.push(i);let s={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return i.cursorX=n+r.lightmapPadding,i.rowHeight=o,{placement:s,atlas:i}}function Io(t){return t instanceof Float32Array?t:new Float32Array(t)}function el(t,e){if(!t){let n=new Uint16Array(e);for(let o=0;o<e;o++)n[o]=o;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function tl(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 rl(t,e){let r=Io(t.vertices),n=Io(t.textureCoords),o=e?tl(Io(t.lightmapCoords??t.textureCoords),e):Io(t.lightmapCoords??new Float32Array(n.length)),i=r.length/3;if(n.length/2!==i)throw new Error("Texture coordinates count mismatch");if(o.length/2!==i)throw new Error("Lightmap coordinates count mismatch");let s=new Float32Array(i*7);for(let a=0;a<i;a++){let c=a*3,l=a*2,u=a*7;s[u]=r[c],s[u+1]=r[c+1],s[u+2]=r[c+2],s[u+3]=n[l],s[u+4]=n[l+1],s[u+5]=o[l],s[u+6]=o[l+1]}return s}function da(t,e,r={}){let n={atlasSize:r.atlasSize??1024,lightmapPadding:r.lightmapPadding??1},o=[],i=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:u,atlas:d}=Zc(o,c.lightmap,n);Qc(d,u,c.lightmap),i.set(l,{atlasIndex:u.atlasIndex,offset:[(u.x+n.lightmapPadding)/n.atlasSize,(u.y+n.lightmapPadding)/n.atlasSize],scale:[u.width/n.atlasSize,u.height/n.atlasSize]})});let s=o.map(c=>{let l=new ur(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 u=i.get(l),d=rl(c,u),f=el(c.indices,d.length/7),p=new Le(t,t.STATIC_DRAW,t.ARRAY_BUFFER);p.upload(d);let y=new yt(t,t.STATIC_DRAW);y.upload(f);let h=new Re(t);return h.configureAttributes(Ei,p),{vao:h,vertexBuffer:p,indexBuffer:y,indexCount:f.length,texture:c.texture,surfaceFlags:c.surfaceFlags??yr,lightmap:u,vertexData:d,indexData:f}}),lightmaps:s}}function mr(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 o=1/n;return{normal:{x:e.x*o,y:e.y*o,z:e.z*o},distance:r*o}}function ma(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],o=t[12],i=t[1],s=t[5],a=t[9],c=t[13],l=t[2],u=t[6],d=t[10],f=t[14],p=t[3],y=t[7],h=t[11],g=t[15];return[mr({normal:{x:p+e,y:y+r,z:h+n},distance:g+o}),mr({normal:{x:p-e,y:y-r,z:h-n},distance:g-o}),mr({normal:{x:p+i,y:y+s,z:h+a},distance:g+c}),mr({normal:{x:p-i,y:y-s,z:h-a},distance:g-c}),mr({normal:{x:p+l,y:y+u,z:h+d},distance:g+f}),mr({normal:{x:p-l,y:y-u,z:h-d},distance:g-f})]}function nl(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function bn(t,e,r){for(let n of r){let o=n.normal.x>=0?e.x:t.x,i=n.normal.y>=0?e.y:t.y,s=n.normal.z>=0?e.z:t.z;if(nl(n,{x:o,y:i,z:s})<0)return!1}return!0}function fa(t){return t<0}function pa(t){return-t-1}function ha(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function ol(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),o=t.clusters[e].pvs,i=Math.floor(r/8),s=1<<r%8;return i<0||i>=n?!1:(o[i]&s)!==0}function il(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 bn(r,n,e)}function zi(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],o=t.planes[n.planeIndex],s=ha(o,e)>=0?0:1,a=n.children[s];if(fa(a))return pa(a);r=a}return-1}function sl(t,e){let r=t.leafs[e],n=[];for(let o=0;o<r.numLeafFaces;o+=1)n.push(t.leafLists.leafFaces[e][o]);return n}function Ti(t,e,r,n,o,i,s){if(fa(e)){let f=pa(e),p=t.leafs[f];if(!ol(t.visibility,o,p.cluster)||!il(p,n))return;let y={x:(p.mins[0]+p.maxs[0])*.5,y:(p.mins[1]+p.maxs[1])*.5,z:(p.mins[2]+p.maxs[2])*.5},h=y.x-r.x,g=y.y-r.y,b=y.z-r.z,T=-(h*h+g*g+b*b);for(let P of sl(t,f))s.has(P)||(s.add(P),i.push({faceIndex:P,leafIndex:f,sortKey:T}));return}let a=t.nodes[e],c=t.planes[a.planeIndex],l=ha(c,r),u=l>=0?a.children[0]:a.children[1],d=l>=0?a.children[1]:a.children[0];bn({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)&&(Ti(t,u,r,n,o,i,s),Ti(t,d,r,n,o,i,s))}function ya(t,e,r){let n=zi(t,e),o=n>=0?t.leafs[n].cluster:-1,i=[];return Ti(t,0,e,r,o,i,new Set),i}var Pi=`#version 300 es
|
|
141
|
+
ïBçϧmÙIólÜoëVb¦¯éWÇû3`});var ja={a:qa};this.setModule=x=>{r.setModule(Qe,x)},this.getModule=()=>r.getModule(Qe),this.instantiate=()=>(this.getModule().then(x=>WebAssembly.instantiate(x,ja)).then(x=>{let ye=x.exports;Ka(ye),h=ye.l,y(),Ya(ye),t()}),this.ready=new Promise(x=>{t=x}).then(()=>{this.HEAP=h.buffer,this.malloc=os,this.free=ls,this.create_decoder=ns,this.send_setup=is,this.init_dsp=ss,this.decode_packets=as,this.destroy_decoder=cs}),this)}function Bt(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(r=>{this._common=r,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=r=>{this._input.buf.set(r),this._inputLen.buf[0]=r.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=r=>{let e=[],t=0,n=[];for(let o=0;o<r.length;o++){let i=r[o];this._input.buf.set(i),this._inputLen.buf[0]=i.length,this._common.wasm.decode_packets(this._decoder);let s=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 u=new Float32Array(s);s&&u.set(new Float32Array(this._common.wasm.HEAP,c[l],s)),a.push(u)}e.push(a),t+=s,this._frameNumber++,this._inputBytes+=i.length,this._outputSamples+=s;for(let l=0;l<this._errorsLength.buf;l+=2){let u=this._common.codeToString(this._errors.buf[l]),d=this._common.codeToString(this._errors.buf[l+1]);n.push({message:u+" vorbis_synthesis"+d,frameLength:i.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],t,this._sampleRate.buf[0],16)},this._isWebWorker=Bt.isWebWorker,this._WASMAudioDecoderCommon=Bt.WASMAudioDecoderCommon||H,this._EmscriptenWASM=Bt.EmscriptenWASM||Qe,this._module=Bt.module,this._inputSize=128*1024,this._ready=this._init(),this}var _o=Symbol(),Ze=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new H,this._init(),this._ready=this[_o](Bt)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new ma("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[_o](e){if(this._decoder){let t=this._decoder;await t.ready.then(()=>t.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 t=[];for(let i=0;i<e.length;i++){let s=e[i];if(this._vorbisSetupInProgress&&(s[So][0]===1&&this._decoder.sendSetupHeader(s[So]),s[vo].length)){let a=s[vo][0][fa];this._decoder.sendSetupHeader(a[ha]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}t.push(...s[vo].map(a=>a[So]))}let n=await this._decoder.decodePackets(t);this._totalSamplesDecoded+=n.samplesDecoded;let o=e[e.length-1];if(o&&o[pa]){let i=this._totalSamplesDecoded-o[ya];if(i>0){for(let s=0;s<n.channelData.length;s++)n.channelData[s]=n.channelData[s].subarray(0,n.samplesDecoded-i);n.samplesDecoded-=i,this._totalSamplesDecoded-=i}}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 t=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),t}};var Ti=class extends $t{constructor(e){super(e,"ogg-vorbis-decoder",Bt,Qe)}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 Ze{constructor(){super(),this._ready=super[_o](Ti)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};qn(Ze,"OggVorbisDecoder");qn(bn,"OggVorbisDecoderWebWorker");var zi=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function Ao(r,e=new Ze){await e.ready;let t=await e.decode(new Uint8Array(r)),n=t.errors;if(n&&n.length>0)throw new zi(n.map(o=>o.message).join("; "));return{sampleRate:t.sampleRate,channels:t.channelData.length,bitDepth:t.bitDepth,channelData:t.channelData}}var vn=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},fr=class{constructor(e,t={}){this.vfs=e;this.refCounts=new Map;this.cache=new it(t.cacheSize??64)}get size(){return this.cache.size}async load(e){let t=e.toLowerCase(),n=this.cache.get(t);if(n)return this.refCounts.set(t,(this.refCounts.get(t)??0)+1),n;let i=(await this.vfs.readFile(e)).slice().buffer,s=await this.decodeByExtension(e,i);return this.cache.set(t,s),this.refCounts.set(t,1),s}release(e){let t=e.toLowerCase(),n=this.refCounts.get(t)??0;n<=1?(this.cache.delete(t),this.refCounts.delete(t)):this.refCounts.set(t,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,t){let n=e.toLowerCase();if(n.endsWith(".wav")){let o=Xn(t),i=o.channels,s=Array.from({length:i},()=>new Float32Array(o.samples.length/i));for(let a=0;a<o.samples.length;a+=1)s[a%i][Math.floor(a/i)]=o.samples[a];return{sampleRate:o.sampleRate,channels:i,bitDepth:o.bitsPerSample,channelData:s}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return Ao(t);throw new vn(`Unsupported audio format: ${e}`)}};var fl="quake2ts-pak-indexes",pl="pak-indexes";function ga(){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 Sn(r,e){let t=ga();return t?new Promise((n,o)=>{let i=t.open(r,1);i.onupgradeneeded=()=>{let{result:s}=i;s.objectStoreNames.contains(e)||s.createObjectStore(e,{keyPath:"key"})},i.onerror=()=>o(i.error??new Error("Unknown IndexedDB error")),i.onsuccess=()=>n(i.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function _n(r,e,t,n){return new Promise((o,i)=>{let a=r.transaction(e,t).objectStore(e),c=n(a);c.onsuccess=()=>o(c.result),c.onerror=()=>i(c.error??new Error("IndexedDB transaction error"))})}function Fi(r,e){return`${W(r)}:${e.toString(16)}`}function hl(r){return r.map(e=>({...e}))}var Mo=class{constructor(e=fl,t=pl){this.dbName=e;this.storeName=t}get isSupported(){return!!ga()}async persist(e){if(!this.isSupported)return;let t=e.validate(),n={...t,key:Fi(e.name,t.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:hl(t.entries)},o=await Sn(this.dbName,this.storeName);return await _n(o,this.storeName,"readwrite",i=>i.put(n)),o.close(),n}async find(e,t){if(!this.isSupported)return;let n=await Sn(this.dbName,this.storeName),o=t!==void 0?Fi(e,t):void 0,i=await _n(n,this.storeName,"readonly",s=>o?s.get(o):s.getAll());if(n.close(),!!i){if(Array.isArray(i)){let s=W(e),a=i.filter(c=>W(c.name)===s);return a.length===0?void 0:a.sort((c,l)=>l.persistedAt-c.persistedAt)[0]}return i}}async remove(e,t){if(!this.isSupported)return!1;let n=await Sn(this.dbName,this.storeName),o=t!==void 0?Fi(e,t):void 0,i=await _n(n,this.storeName,"readwrite",s=>{if(o)return s.delete(o);let a=`${W(e)}:`;return s.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof i=="number"?i>0:!0}async clear(){if(!this.isSupported)return;let e=await Sn(this.dbName,this.storeName);await _n(e,this.storeName,"readwrite",t=>t.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await Sn(this.dbName,this.storeName),t=await _n(e,this.storeName,"readonly",n=>n.getAll());return e.close(),t.sort((n,o)=>o.persistedAt-n.persistedAt)}};var Nt=class extends Error{constructor(t,n){super(n??`Missing dependencies: ${t.join(", ")}`);this.missing=t;this.name="AssetDependencyError"}},An=class{constructor(){this.nodes=new Map}register(e,t=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};t.forEach(o=>n.dependencies.add(o)),this.nodes.set(e,n),t.forEach(o=>{this.nodes.has(o)||this.nodes.set(o,{dependencies:new Set,loaded:!1})})}markLoaded(e){let t=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,t);if(n.length>0)throw new Nt(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);t.loaded=!0,this.nodes.set(e,t)}markUnloaded(e){let t=this.nodes.get(e);t&&(t.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let t=this.nodes.get(e);return t?this.getMissingDependencies(e,t):[]}reset(){this.nodes.clear()}getMissingDependencies(e,t){let n=[];for(let o of t.dependencies)this.nodes.get(o)?.loaded||n.push(o);return n}},wo=class{constructor(e,t={}){this.vfs=e;this.textures=new jt({capacity:t.textureCacheCapacity??128}),this.audio=new fr(e,{cacheSize:t.audioCacheSize??64}),this.dependencyTracker=t.dependencyTracker??new An,this.md2=new Kt(e),this.md3=new Yt(e)}isAssetLoaded(e,t){return this.dependencyTracker.isLoaded(this.makeKey(e,t))}registerTexture(e,t){this.textures.set(e,t);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadSound(e){let t=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),t}async loadMd2Model(e,t=[]){let n=this.makeKey("model",e),o=t.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,o);let i=this.dependencyTracker.missingDependencies(n);if(i.length>0)throw new Nt(i,`Asset ${n} is missing dependencies: ${i.join(", ")}`);let s=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),s}async loadMd3Model(e,t=[]){let n=this.makeKey("model",e),o=t.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,o);let i=this.dependencyTracker.missingDependencies(n);if(i.length>0)throw new Nt(i,`Asset ${n} is missing dependencies: ${i.join(", ")}`);let s=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),s}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset()}makeKey(e,t){return`${e}:${W(t)}`}};var Pi=32,Lo=(d=>(d[d.Auto=0]="Auto",d[d.Weapon=1]="Weapon",d[d.Voice=2]="Voice",d[d.Item=3]="Item",d[d.Body=4]="Body",d[d.Aux=5]="Aux",d[d.Footstep=6]="Footstep",d[d.Aux3=7]="Aux3",d[d.NoPhsAdd=8]="NoPhsAdd",d[d.Reliable=16]="Reliable",d[d.ForcePos=32]="ForcePos",d))(Lo||{}),xa=-1,Co=0,ba=1,va=2,Sa=3,pr=80,_a=.003;function Vt(r){return r===3?r*.001:r*5e-4}function Eo(r){let e=Vt(r);return e<=0?Number.POSITIVE_INFINITY:80+1/e}var To=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 zo(r){let e=r.getContext(),t=e.createGain();t.gain.value=1;let n=e.createDynamicsCompressor(),o=e.createBiquadFilter?.();return o?(o.type="lowpass",o.frequency.value=2e4,o.Q.value=.707,t.connect(o),o.connect(n)):t.connect(n),n.connect(e.destination),{context:e,master:t,compressor:n,filter:o}}var Fo=class{constructor(e=new Xt){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,t){let n=this.registerName(e);return this.buffers.set(n,t),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}};var Po=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((t,n)=>{if(!t.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return t.decodeAudioData(n)})}async precache(e){let t=[...new Set(e.map(i=>this.normalize(i)))],n={loaded:[],skipped:[],missing:[],errors:{}},o=this.contextController.getContext();for(let i of t)try{let s=this.registry.find(i);if(s!==void 0&&this.registry.has(s)){n.skipped.push(i);continue}if(!this.vfs.stat(i)){n.missing.push(i);continue}let l=(await this.vfs.readFile(i)).slice().buffer,u=await this.decodeAudio(o,l);this.registry.register(i,u),n.loaded.push(i)}catch(s){let a=s instanceof Error?s:new Error(String(s));n.errors[i]=a}return n}normalize(e){let t=W(e.replace(/^\//,""));return t.startsWith(this.soundRoot)?t:W(`${this.soundRoot}${t}`)}};var yl=7,Mn=r=>r&yl;function Io(r){return Array.from({length:32},()=>({entnum:0,entchannel:0,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===r}))}function Ro(r,e,t,n){if(t<0)throw new Error("pickChannel: entchannel must be non-negative");let o=Mn(t),i=-1,s=Number.POSITIVE_INFINITY;for(let a=0;a<r.length;a+=1){let c=r[a],l=Mn(c.entchannel);if(o!==0&&c.entnum===e&&l===o){i=a;break}if(c.active&&c.entnum===n.playerEntity&&e!==n.playerEntity)continue;let u=c.endTimeMs-n.nowMs;(i===-1||u<s)&&(s=u,i=a)}return i===-1?void 0:i}function ko(r,e,t,n,o){if(o)return{left:t,right:t,distanceComponent:0};let i=fs(r,e.origin),s=Jo(i),a=Ee(i),c=s-80;c<0&&(c=0),c*=Vt(n);let l=$o(e.right,a),u=e.mono??!1,d=u||n===0?1:.5*(1+l),m=u||n===0?1:.5*(1-l),p=Math.max(0,Math.floor(t*(1-c)*d));return{left:Math.max(0,Math.floor(t*(1-c)*m)),right:p,distanceComponent:c}}var Do=class{constructor(e){this.activeSources=new Map;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=Io(e.playerEntity),this.listener=e.listener??{origin:ms,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=zo(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 t=this.registry.get(e.soundIndex);if(!t)return;let n=this.graph.context,o=n.currentTime*1e3,i=Ro(this.channels,e.entity,e.channel,{nowMs:o,playerEntity:this.playerEntity});if(i===void 0)return;let s=this.activeSources.get(i);s&&(s.source.onended=null,s.source.stop(),this.activeSources.delete(i));let a=n.createBufferSource();a.buffer=t,a.loop=e.looping??!1;let c=e.origin??this.listener.origin,l=n.createGain(),u=this.createPanner(n,e.attenuation),d=this.resolveOcclusion?.(this.listener,c,e.attenuation),m=Aa(d?.gainScale??1),p=this.resolveOcclusion?this.createOcclusionFilter(n,d?.lowpassHz??2e4):void 0;this.applyOriginToPanner(u,c);let h=e.entity===this.playerEntity,y=ko(c,this.listener,e.volume,e.attenuation,h),b=(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=b*m;let C=n.currentTime+(e.timeOffsetMs??0)/1e3,L=(e.looping?Number.POSITIVE_INFINITY:t.duration*1e3)+C*1e3;a.connect(u),p?(u.connect(p),p.connect(l)):u.connect(l),l.connect(this.graph.master),a.start(C),a.onended=()=>{this.channels[i].active=!1,this.activeSources.delete(i)};let q={channelIndex:i,entnum:e.entity,entchannel:Mn(e.channel),endTimeMs:L,source:a,panner:u,gain:l,baseGain:b,origin:c,attenuation:e.attenuation,occlusion:p?{scale:m,lowpassHz:d?.lowpassHz,filter:p}:d?{scale:m,lowpassHz:d.lowpassHz}:void 0};return this.channels[i]={entnum:e.entity,entchannel:Mn(e.channel),endTimeMs:L,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(i,q),q}stop(e){let t=this.activeSources.get(e);t&&(t.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[t,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[t].active=!1,this.activeSources.delete(t))}updateEntityPosition(e,t){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,t),n.origin=t,this.resolveOcclusion)){let o=this.resolveOcclusion(this.listener,t,n.attenuation);this.applyOcclusion(n,o)}}positionedSound(e,t,n,o){return this.play({entity:0,channel:0,soundIndex:t,volume:n,attenuation:o,origin:e})}ambientSound(e,t,n){return this.play({entity:0,channel:0,soundIndex:t,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,t=400){let n=this.graph.filter;n&&(n.type="lowpass",n.Q.value=.707,n.frequency.value=e?t:2e4)}createPanner(e,t){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,t)}configurePanner(e,t){let n=Vt(t);return e.refDistance=80,e.maxDistance=Eo(t),e.rolloffFactor=n,e.distanceModel=t===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,t){e.positionX.value=t.x,e.positionY.value=t.y,e.positionZ.value=t.z}createOcclusionFilter(e,t){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Ii(t,10,2e4),n}applyOcclusion(e,t){let n=Aa(t?.gainScale??1);if(e.gain.gain.value=e.baseGain*n,e.occlusion?.filter){let o=t?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Ii(o,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=t?.lowpassHz):t&&(e.occlusion={scale:n,lowpassHz:t.lowpassHz})}},Ii=(r,e,t)=>Math.min(t,Math.max(e,r)),Aa=r=>Ii(r,0,1);var Ho=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async t=>t),this.volume=e.volume??1}async play(e,{loop:t=!0,restart:n=!1}={}){if(this.track===e&&this.element){this.element.loop=t,this.element.volume=this.volume,n&&(this.element.currentTime=0),(this.element.paused||n)&&await this.element.play();return}let o=await this.resolveSource(e),i=this.createElement();i.src=o,i.loop=t,i.volume=this.volume,i.currentTime=0,i.load(),await i.play(),this.element=i,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),t=!!this.element?.paused;return{track:this.track,paused:t,playing:e,volume:this.volume}}};var Oo=class{constructor(e){this.registry=e.registry,this.system=e.system,this.music=e.music}soundindex(e){return this.registry.registerName(e)}sound(e,t,n,o,i,s){this.system.play({entity:e,channel:t,soundIndex:n,volume:o,attenuation:i,timeOffsetMs:s})}positioned_sound(e,t,n,o){this.system.positionedSound(e,t,n,o)}loop_sound(e,t,n,o,i){this.system.play({entity:e,channel:t,soundIndex:n,volume:o,attenuation:i,looping:!0})}stop_entity_sounds(e){this.system.stopEntitySounds(e)}set_listener(e){this.system.setListener(e)}play_music(e,t=!0){return this.music?this.music.play(e,{loop:t}):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,t,n){this.system.ambientSound(e,t,n)}play_channel(e){this.system.play({...e})}};function gl(r){r.enable(r.DEPTH_TEST),r.depthFunc(r.LEQUAL),r.enable(r.CULL_FACE),r.cullFace(r.BACK),r.enable(r.BLEND),r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)}function xl(r,e,t,n){for(let o of e){let i=r.getExtension(o);if(!i)throw new Error(`Missing required WebGL extension: ${o}`);n.set(o,i)}for(let o of t){let i=r.getExtension(o);i&&n.set(o,i)}}function Ma(r,e={}){let{contextAttributes:t,requiredExtensions:n=[],optionalExtensions:o=[]}=e,i=r.getContext("webgl2",t??{antialias:!0});if(!i)throw new Error("WebGL2 not supported or failed to initialize");gl(i);let s=new Map;xl(i,n,o,s);let a=!1,c=new Set,l=new Set,u=m=>{a=!0,m.preventDefault();for(let p of c)p()},d=()=>{a=!1;for(let m of l)m()};return r.addEventListener("webglcontextlost",u),r.addEventListener("webglcontextrestored",d),{gl:i,extensions:s,isLost:()=>a,onLost(m){return c.add(m),()=>c.delete(m)},onRestored(m){return l.add(m),()=>l.delete(m)},dispose(){r.removeEventListener("webglcontextlost",u),r.removeEventListener("webglcontextrestored",d),c.clear(),l.clear(),s.clear()}}}function wa(r,e,t){let n=r.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(r.shaderSource(n,t),r.compileShader(n),!r.getShaderParameter(n,r.COMPILE_STATUS)){let i=r.getShaderInfoLog(n)??"Unknown shader compile failure";throw r.deleteShader(n),new Error(i)}return n}function bl(r,e,t,n){let o=r.createProgram();if(!o)throw new Error("Failed to allocate shader program");if(r.attachShader(o,e),r.attachShader(o,t),n)for(let[s,a]of Object.entries(n))r.bindAttribLocation(o,a,s);if(r.linkProgram(o),!r.getProgramParameter(o,r.LINK_STATUS)){let s=r.getProgramInfoLog(o)??"Unknown shader link failure";throw r.deleteProgram(o),new Error(s)}return o}var ie=class r{constructor(e,t){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=t}static create(e,t,n){let o=wa(e,e.VERTEX_SHADER,t.vertex),i=wa(e,e.FRAGMENT_SHADER,t.fragment);try{let s=bl(e,o,i,n);return new r(e,s)}finally{e.deleteShader(o),e.deleteShader(i)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let t=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,t)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let t=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,t)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function La(r,e,t){return ie.create(r,e,t)}var se=class{constructor(e,t=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let o=e.createBuffer();if(!o)throw new Error("Failed to allocate buffer");this.buffer=o,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,t)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,t=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,t)}update(e,t=0){this.bind(),this.gl.bufferSubData(this.target,t,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},we=class extends se{constructor(e,t=e.STATIC_DRAW){super(e,t,e.ELEMENT_ARRAY_BUFFER)}},le=class{constructor(e){this.gl=e;let t=e.createVertexArray();if(!t)throw new Error("Failed to allocate vertex array object");this.vao=t}bind(){this.gl.bindVertexArray(this.vao)}configureAttributes(e,t){this.bind(),t&&t.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)}},hr=class{constructor(e,t=e.TEXTURE_2D){this.gl=e,this.target=t;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)}uploadImage(e,t,n,o,i,s,a,c){this.bind(),this.gl.texImage2D(this.target,e,t,n,o,i,s,a,c)}dispose(){this.gl.deleteTexture(this.texture)}},yr=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let t=e.createTexture();if(!t)throw new Error("Failed to allocate cubemap texture");this.texture=t}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,t,n,o,i,s,a,c,l){this.bind(),this.gl.texImage2D(e,t,n,o,i,s,a,c,l)}dispose(){this.gl.deleteTexture(this.texture)}},Bo=class{constructor(e){this.gl=e;let t=e.createFramebuffer();if(!t)throw new Error("Failed to allocate framebuffer");this.framebuffer=t}bind(e=this.gl.FRAMEBUFFER){this.gl.bindFramebuffer(e,this.framebuffer)}attachTexture2D(e,t,n=0){this.bind(),this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,e,t.target,t.texture,n)}dispose(){this.gl.deleteFramebuffer(this.framebuffer)}};var ki=4,Ri=7*ki,Di=[{index:0,size:3,type:5126,stride:Ri,offset:0},{index:1,size:2,type:5126,stride:Ri,offset:3*ki},{index:2,size:2,type:5126,stride:Ri,offset:5*ki}];function vl(r,e){return{width:r,height:r,padding:e,data:new Uint8Array(r*r*4),cursorX:0,cursorY:0,rowHeight:0}}function Sl(r){let e=r.width*r.height;if(e===0)throw new Error("Invalid lightmap with zero area");let t=r.samples.byteLength/e;if(!Number.isInteger(t)||t<3||t>4)throw new Error("Unsupported lightmap channel count");return t}function _l(r,e,t){let n=Sl(t),o=r.width*4,i=e.x+r.padding,s=e.y+r.padding,a=0;for(let c=0;c<t.height;c++){let l=(s+c)*o+i*4;for(let u=0;u<t.width;u++){let d=l+u*4;r.data[d]=t.samples[a],r.data[d+1]=t.samples[a+1],r.data[d+2]=t.samples[a+2],r.data[d+3]=n===4?t.samples[a+3]:255,a+=n}}}function Al(r,e,t){let n=e.width+t.lightmapPadding*2,o=e.height+t.lightmapPadding*2;if(n>t.atlasSize||o>t.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of r){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+t.lightmapPadding,a.rowHeight=0),a.cursorY+o>a.height)continue;let c={atlasIndex:r.indexOf(a),x:a.cursorX,y:a.cursorY,width:e.width,height:e.height};return a.cursorX+=n+t.lightmapPadding,a.rowHeight=Math.max(a.rowHeight,o),{placement:c,atlas:a}}let i=vl(t.atlasSize,t.lightmapPadding);r.push(i);let s={atlasIndex:r.length-1,x:0,y:0,width:e.width,height:e.height};return i.cursorX=n+t.lightmapPadding,i.rowHeight=o,{placement:s,atlas:i}}function No(r){return r instanceof Float32Array?r:new Float32Array(r)}function Ml(r,e){if(!r){let n=new Uint16Array(e);for(let o=0;o<e;o++)n[o]=o;return n}return r instanceof Uint16Array?r:new Uint16Array(r)}function wl(r,e){let t=new Float32Array(r.length);for(let n=0;n<r.length;n+=2)t[n]=e.offset[0]+r[n]*e.scale[0],t[n+1]=e.offset[1]+r[n+1]*e.scale[1];return t}function Ll(r,e){let t=No(r.vertices),n=No(r.textureCoords),o=e?wl(No(r.lightmapCoords??r.textureCoords),e):No(r.lightmapCoords??new Float32Array(n.length)),i=t.length/3;if(n.length/2!==i)throw new Error("Texture coordinates count mismatch");if(o.length/2!==i)throw new Error("Lightmap coordinates count mismatch");let s=new Float32Array(i*7);for(let a=0;a<i;a++){let c=a*3,l=a*2,u=a*7;s[u]=t[c],s[u+1]=t[c+1],s[u+2]=t[c+2],s[u+3]=n[l],s[u+4]=n[l+1],s[u+5]=o[l],s[u+6]=o[l+1]}return s}function Ca(r,e,t={}){let n={atlasSize:t.atlasSize??1024,lightmapPadding:t.lightmapPadding??1},o=[],i=new Map;e.forEach((c,l)=>{if(!c.lightmap)return;let{placement:u,atlas:d}=Al(o,c.lightmap,n);_l(d,u,c.lightmap),i.set(l,{atlasIndex:u.atlasIndex,offset:[(u.x+n.lightmapPadding)/n.atlasSize,(u.y+n.lightmapPadding)/n.atlasSize],scale:[u.width/n.atlasSize,u.height/n.atlasSize]})});let s=o.map(c=>{let l=new hr(r);return l.setParameters({wrapS:r.CLAMP_TO_EDGE,wrapT:r.CLAMP_TO_EDGE,minFilter:r.LINEAR,magFilter:r.LINEAR}),l.uploadImage(0,r.RGBA,c.width,c.height,0,r.RGBA,r.UNSIGNED_BYTE,c.data),{texture:l,width:c.width,height:c.height,pixels:c.data}});return{surfaces:e.map((c,l)=>{let u=i.get(l),d=Ll(c,u),m=Ml(c.indices,d.length/7),p=new se(r,r.STATIC_DRAW,r.ARRAY_BUFFER);p.upload(d);let h=new we(r,r.STATIC_DRAW);h.upload(m);let y=new le(r);return y.configureAttributes(Di,p),{vao:y,vertexBuffer:p,indexBuffer:h,indexCount:m.length,texture:c.texture,surfaceFlags:c.surfaceFlags??_r,lightmap:u,vertexData:d,indexData:m}}),lightmaps:s}}function gr(r){let{normal:e,distance:t}=r,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return r;let o=1/n;return{normal:{x:e.x*o,y:e.y*o,z:e.z*o},distance:t*o}}function Ea(r){if(r.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=r[0],t=r[4],n=r[8],o=r[12],i=r[1],s=r[5],a=r[9],c=r[13],l=r[2],u=r[6],d=r[10],m=r[14],p=r[3],h=r[7],y=r[11],g=r[15];return[gr({normal:{x:p+e,y:h+t,z:y+n},distance:g+o}),gr({normal:{x:p-e,y:h-t,z:y-n},distance:g-o}),gr({normal:{x:p+i,y:h+s,z:y+a},distance:g+c}),gr({normal:{x:p-i,y:h-s,z:y-a},distance:g-c}),gr({normal:{x:p+l,y:h+u,z:y+d},distance:g+m}),gr({normal:{x:p-l,y:h-u,z:y-d},distance:g-m})]}function Cl(r,e){return r.normal.x*e.x+r.normal.y*e.y+r.normal.z*e.z+r.distance}function wn(r,e,t){for(let n of t){let o=n.normal.x>=0?e.x:r.x,i=n.normal.y>=0?e.y:r.y,s=n.normal.z>=0?e.z:r.z;if(Cl(n,{x:o,y:i,z:s})<0)return!1}return!0}function Ta(r){return r<0}function za(r){return-r-1}function Fa(r,e){return r.normal[0]*e.x+r.normal[1]*e.y+r.normal[2]*e.z-r.dist}function El(r,e,t){if(!r||e<0||t<0)return!0;let n=Math.ceil(r.numClusters/8),o=r.clusters[e].pvs,i=Math.floor(t/8),s=1<<t%8;return i<0||i>=n?!1:(o[i]&s)!==0}function Tl(r,e){let t={x:r.mins[0],y:r.mins[1],z:r.mins[2]},n={x:r.maxs[0],y:r.maxs[1],z:r.maxs[2]};return wn(t,n,e)}function Oi(r,e){let t=0;for(;t>=0;){let n=r.nodes[t],o=r.planes[n.planeIndex],s=Fa(o,e)>=0?0:1,a=n.children[s];if(Ta(a))return za(a);t=a}return-1}function zl(r,e){let t=r.leafs[e],n=[];for(let o=0;o<t.numLeafFaces;o+=1)n.push(r.leafLists.leafFaces[e][o]);return n}function Hi(r,e,t,n,o,i,s){if(Ta(e)){let m=za(e),p=r.leafs[m];if(!El(r.visibility,o,p.cluster)||!Tl(p,n))return;let h={x:(p.mins[0]+p.maxs[0])*.5,y:(p.mins[1]+p.maxs[1])*.5,z:(p.mins[2]+p.maxs[2])*.5},y=h.x-t.x,g=h.y-t.y,b=h.z-t.z,C=-(y*y+g*g+b*b);for(let L of zl(r,m))s.has(L)||(s.add(L),i.push({faceIndex:L,leafIndex:m,sortKey:C}));return}let a=r.nodes[e],c=r.planes[a.planeIndex],l=Fa(c,t),u=l>=0?a.children[0]:a.children[1],d=l>=0?a.children[1]:a.children[0];wn({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)&&(Hi(r,u,t,n,o,i,s),Hi(r,d,t,n,o,i,s))}function Pa(r,e,t){let n=Oi(r,e),o=n>=0?r.leafs[n].cluster:-1,i=[];return Hi(r,0,e,t,o,i,new Set),i}var Bi=`#version 300 es
|
|
142
142
|
precision highp float;
|
|
143
143
|
|
|
144
144
|
layout(location = 0) in vec3 a_position;
|
|
@@ -160,7 +160,7 @@ void main() {
|
|
|
160
160
|
v_texCoord = applyScroll(a_texCoord, u_texScroll);
|
|
161
161
|
v_lightmapCoord = applyScroll(a_lightmapCoord, u_lightmapScroll);
|
|
162
162
|
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
163
|
-
}`,
|
|
163
|
+
}`,Ni=`#version 300 es
|
|
164
164
|
precision highp float;
|
|
165
165
|
|
|
166
166
|
in vec2 v_texCoord;
|
|
@@ -197,7 +197,7 @@ void main() {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
o_color = vec4(base.rgb, base.a * u_alpha);
|
|
200
|
-
}`,
|
|
200
|
+
}`,Ia=[0,255,255,255];function Vi(r=Ia,e=[]){let t=new Float32Array(4);for(let n=0;n<4;n+=1){let o=r[n]??255;if(o===255){t[n]=0;continue}let i=e[o];t[n]=i!==void 0?i:1}return t}function Fl(r){return[-(r*.25%1),0]}function Ui(r=_r,e=0){let t=(r&Ss)!==0,n=(r&xs)!==0,o=(r&gs)!==0,i=(r&bs)!==0,s=(r&vs)!==0,a=i?.33:s?.66:1,c=i||s,l=!c&&!o,u=t?Fl(e):[0,0];return{alpha:a,blend:c,depthWrite:l,warp:n,flowOffset:u,sky:o}}var Vo=class{constructor(e){this.gl=e,this.program=ie.create(e,{vertex:Bi,fragment:Ni},{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:t,styleIndices:n=Ia,styleValues:o=[],diffuseSampler:i=0,lightmapSampler:s=1,surfaceFlags:a=_r,timeSeconds:c=0}=e,l=Ui(a,c),u=Vi(n,o);return this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,t),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,u),this.gl.uniform1f(this.uniformAlpha,l.alpha),this.gl.uniform1i(this.uniformApplyLightmap,l.sky?0:1),this.gl.uniform1i(this.uniformWarp,l.warp?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,i),this.gl.uniform1i(this.uniformLightmap,s),l}dispose(){this.program.dispose()}};function Ra(r,e){r.depthMask(e.depthWrite),e.blend?(r.enable(r.BLEND),r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA)):r.disable(r.BLEND)}var ka=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]),Gi=`#version 300 es
|
|
201
201
|
precision highp float;
|
|
202
202
|
|
|
203
203
|
layout(location = 0) in vec3 a_position;
|
|
@@ -212,7 +212,7 @@ void main() {
|
|
|
212
212
|
dir.xy += u_scroll;
|
|
213
213
|
v_direction = dir;
|
|
214
214
|
gl_Position = u_viewProjectionNoTranslation * vec4(a_position, 1.0);
|
|
215
|
-
}`,
|
|
215
|
+
}`,Wi=`#version 300 es
|
|
216
216
|
precision highp float;
|
|
217
217
|
|
|
218
218
|
in vec3 v_direction;
|
|
@@ -222,7 +222,7 @@ out vec4 o_color;
|
|
|
222
222
|
|
|
223
223
|
void main() {
|
|
224
224
|
o_color = texture(u_skybox, v_direction);
|
|
225
|
-
}`,
|
|
225
|
+
}`,Uo=class{constructor(e){this.gl=e,this.program=ie.create(e,{vertex:Gi,fragment:Wi},{a_position:0}),this.vao=new le(e),this.vbo=new se(e,e.STATIC_DRAW),this.vbo.upload(ka,e.STATIC_DRAW);let t=[{index:0,size:3,type:e.FLOAT,stride:12,offset:0}];this.vao.configureAttributes(t,this.vbo),this.uniformViewProj=this.program.getUniformLocation("u_viewProjectionNoTranslation"),this.uniformScroll=this.program.getUniformLocation("u_scroll"),this.uniformSampler=this.program.getUniformLocation("u_skybox"),this.cubemap=new yr(e),this.cubemap.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE})}bind(e){let{viewProjection:t,scroll:n,textureUnit:o=0}=e;this.program.use(),this.gl.depthMask(!1),this.gl.uniformMatrix4fv(this.uniformViewProj,!1,t),this.gl.uniform2f(this.uniformScroll,n[0],n[1]),this.gl.uniform1i(this.uniformSampler,o),this.cubemap.bind(o),this.vao.bind()}draw(){this.gl.drawArrays(this.gl.TRIANGLES,0,ka.length/3)}dispose(){this.vbo.dispose(),this.vao.dispose(),this.cubemap.dispose(),this.program.dispose()}};function Da(r){let e=r.slice();return e[12]=0,e[13]=0,e[14]=0,e}function Ha(r,e=[.01,.02]){let[t,n]=e;return[t*r,n*r]}var qi=`#version 300 es
|
|
226
226
|
precision highp float;
|
|
227
227
|
|
|
228
228
|
layout(location = 0) in vec3 a_position;
|
|
@@ -240,7 +240,7 @@ void main() {
|
|
|
240
240
|
v_light = max(dot(normal, normalize(u_lightDir)), 0.0);
|
|
241
241
|
v_texCoord = a_texCoord;
|
|
242
242
|
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
243
|
-
}`,
|
|
243
|
+
}`,Ki=`#version 300 es
|
|
244
244
|
precision highp float;
|
|
245
245
|
|
|
246
246
|
in vec2 v_texCoord;
|
|
@@ -254,5 +254,64 @@ out vec4 o_color;
|
|
|
254
254
|
void main() {
|
|
255
255
|
vec4 albedo = texture(u_diffuseMap, v_texCoord) * u_tint;
|
|
256
256
|
o_color = vec4(albedo.rgb * v_light, albedo.a);
|
|
257
|
-
}`;function
|
|
257
|
+
}`;function Pl(r){let e=r.x*r.x+r.y*r.y+r.z*r.z;if(e<=0)return{x:0,y:0,z:1};let t=1/Math.sqrt(e);return{x:r.x*t,y:r.y*t,z:r.z*t}}function Xi(r,e,t){return r+(e-r)*t}function Oa(r,e,t){return{x:Xi(r.x,e.x,t),y:Xi(r.y,e.y,t),z:Xi(r.z,e.z,t)}}function Il(r,e,t){return[r/t.skinWidth,1-e/t.skinHeight]}function Yi(r){if(r.glCommands.length===0){let n=[],o=[];return r.triangles.forEach(i=>{let s=n.length;for(let a=0;a<3;a+=1){let c=i.vertexIndices[a],l=i.texCoordIndices[a],u=r.texCoords[l];n.push({vertexIndex:c,texCoord:Il(u.s,u.t,r.header)})}o.push(s,s+1,s+2)}),{vertices:n,indices:new Uint16Array(o)}}let e=[],t=[];for(let n of r.glCommands){let o=e.length;if(e.push(...n.vertices.map(i=>({vertexIndex:i.vertexIndex,texCoord:[i.s,1-i.t]}))),n.mode==="strip")for(let i=0;i<n.vertices.length-2;i+=1){let s=i%2===0,a=o+i+(s?0:1),c=o+i+(s?1:0),l=o+i+2;t.push(a,c,l)}else for(let i=1;i<n.vertices.length-1;i+=1)t.push(o,o+i,o+i+1)}return{vertices:e,indices:new Uint16Array(t)}}function ji(r,e,t){let{currentFrame:n,nextFrame:o,lerp:i}=t,s=r.frames[n],a=r.frames[o];if(!s||!a)throw new Error("Requested MD2 frames are out of range");let c=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,u)=>{let d=s.vertices[l.vertexIndex],m=a.vertices[l.vertexIndex];if(!d||!m)throw new Error("MD2 vertex index out of range for frame");let p=Oa(d.position,m.position,i),h=Pl(Oa(d.normal,m.normal,i)),y=u*8;c[y]=p.x,c[y+1]=p.y,c[y+2]=p.z,c[y+3]=h.x,c[y+4]=h.y,c[y+5]=h.z,c[y+6]=l.texCoord[0],c[y+7]=l.texCoord[1]}),c}var Go=class{constructor(e,t,n){this.gl=e,this.geometry=Yi(t),this.vertexBuffer=new se(e,e.STATIC_DRAW),this.indexBuffer=new we(e,e.STATIC_DRAW),this.vertexArray=new le(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(t,n)}update(e,t){let n=ji(e,this.geometry,t);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()}},Wo=class{constructor(e){this.gl=e,this.program=ie.create(e,{vertex:qi,fragment:Ki},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap")}bind(e){let{modelViewProjection:t,lightDirection:n=[0,0,1],tint:o=[1,1,1,1],diffuseSampler:i=0}=e,s=new Float32Array(n),a=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,t),this.gl.uniform3fv(this.uniformLightDir,s),this.gl.uniform4fv(this.uniformTint,a),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 Rl=[.2,.2,.2],kl={x:0,y:0,z:1},Dl=[.8,.8,.8];function $i(r,e,t){return r+(e-r)*t}function xr(r,e,t){return{x:$i(r.x,e.x,t),y:$i(r.y,e.y,t),z:$i(r.z,e.z,t)}}function Ln(r){return r<0?0:r>1?1:r}function Ji(r){let e=[],t=[];for(let n of r.triangles){let o=e.length,[i,s,a]=n.indices,c=r.texCoords[i],l=r.texCoords[s],u=r.texCoords[a];if(!c||!l||!u)throw new Error(`Missing texCoord for triangle in surface ${r.name}`);e.push({vertexIndex:i,texCoord:[c.s,1-c.t]},{vertexIndex:s,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[u.s,1-u.t]}),t.push(o,o+1,o+2)}return{vertices:e,indices:new Uint16Array(t)}}function Hl(r,e,t){let n=t?.ambient??Rl,o=t?.directional??{direction:kl,color:Dl},i=Ee(r),s=Ee(o.direction),a=Ln(i.x*s.x+i.y*s.y+i.z*s.z),c=n[0]+o.color[0]*a,l=n[1]+o.color[1]*a,u=n[2]+o.color[2]*a;if(t?.dynamicLights){let d=t.modelMatrix?ps(t.modelMatrix,e):e;for(let m of t.dynamicLights){let p=d.x-m.origin.x,h=d.y-m.origin.y,y=d.z-m.origin.z,g=p*p+h*h+y*y,b=m.radius*m.radius;if(g<b&&b>0){let C=1-Math.sqrt(g)/m.radius,L=Ln(C*a);c+=m.color[0]*L,l+=m.color[1]*L,u+=m.color[2]*L}}}return[Ln(c),Ln(l),Ln(u)]}function Qi(r,e,t,n){let o=r.vertices[t.currentFrame],i=r.vertices[t.nextFrame];if(!o||!i)throw new Error("Requested MD3 frames are out of range");let s=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,c)=>{let l=o[a.vertexIndex],u=i[a.vertexIndex];if(!l||!u)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let d=xr(l.position,u.position,t.lerp),m=Ee(xr(l.normal,u.normal,t.lerp)),p=Hl(m,d,n),h=c*12;s[h]=d.x,s[h+1]=d.y,s[h+2]=d.z,s[h+3]=m.x,s[h+4]=m.y,s[h+5]=m.z,s[h+6]=a.texCoord[0],s[h+7]=a.texCoord[1],s[h+8]=p[0],s[h+9]=p[1],s[h+10]=p[2],s[h+11]=1}),s}function Ba(r,e,t){let n=r.tags[0];if(!n)return null;let o=n.findIndex(y=>y.name===t);if(o===-1)return null;let i=r.tags[e.currentFrame]?.[o],s=r.tags[e.nextFrame]?.[o];if(!i||!s)throw new Error(`Tag ${t} is missing for one of the interpolated frames`);let a=xr(i.origin,s.origin,e.lerp),c=Ee(xr(i.axis[0],s.axis[0],e.lerp)),l=Ee(xr(i.axis[1],s.axis[1],e.lerp)),u=Ee(xr(i.axis[2],s.axis[2],e.lerp)),d=c,m=Ee({x:l.x-d.x*(d.x*l.x+d.y*l.y+d.z*l.z),y:l.y-d.y*(d.x*l.x+d.y*l.y+d.z*l.z),z:l.z-d.z*(d.x*l.x+d.y*l.y+d.z*l.z)}),p=Ee({x:d.y*m.z-d.z*m.y,y:d.z*m.x-d.x*m.z,z:d.x*m.y-d.y*m.x}),h=[d,m,p];return{origin:a,axis:h,matrix:hs(a,h)}}var Zi=`#version 300 es
|
|
258
|
+
precision highp float;
|
|
259
|
+
|
|
260
|
+
layout(location = 0) in vec3 a_position;
|
|
261
|
+
layout(location = 1) in vec3 a_normal;
|
|
262
|
+
layout(location = 2) in vec2 a_texCoord;
|
|
263
|
+
layout(location = 3) in vec4 a_color;
|
|
264
|
+
|
|
265
|
+
uniform mat4 u_modelViewProjection;
|
|
266
|
+
|
|
267
|
+
out vec2 v_texCoord;
|
|
268
|
+
out vec4 v_color;
|
|
269
|
+
|
|
270
|
+
void main() {
|
|
271
|
+
v_texCoord = a_texCoord;
|
|
272
|
+
v_color = a_color;
|
|
273
|
+
gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
|
|
274
|
+
}`,es=`#version 300 es
|
|
275
|
+
precision highp float;
|
|
276
|
+
|
|
277
|
+
in vec2 v_texCoord;
|
|
278
|
+
in vec4 v_color;
|
|
279
|
+
|
|
280
|
+
uniform sampler2D u_diffuseMap;
|
|
281
|
+
uniform vec4 u_tint;
|
|
282
|
+
|
|
283
|
+
out vec4 o_color;
|
|
284
|
+
|
|
285
|
+
void main() {
|
|
286
|
+
vec4 albedo = texture(u_diffuseMap, v_texCoord) * u_tint;
|
|
287
|
+
o_color = vec4(albedo.rgb * v_color.rgb, albedo.a * v_color.a);
|
|
288
|
+
}`,Cn=class{constructor(e,t,n,o){this.gl=e,this.geometry=Ji(t),this.vertexBuffer=new se(e,e.STATIC_DRAW),this.indexBuffer=new we(e,e.STATIC_DRAW),this.vertexArray=new le(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(t,n,o)}update(e,t,n){let o=Qi(e,this.geometry,t,n);this.vertexBuffer.upload(o,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,t,n,o){this.surfaces=new Map;this.gl=e,this.model=t,this.blend=n,this.lighting=o,t.surfaces.forEach(i=>{this.surfaces.set(i.name,new Cn(e,i,n,o))})}update(e,t){this.blend=e,this.lighting=t??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()}},qo=class{constructor(e){this.gl=e,this.program=ie.create(e,{vertex:Zi,fragment:es},{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,t=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(t)),this.gl.uniform1i(this.uniformDiffuse,n)}drawSurface(e,t){let n=t?.diffuseSampler??0,o=t?.tint??[1,1,1,1];this.gl.uniform4fv(this.uniformTint,new Float32Array(o)),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 Ol=[1,1,1,1],Ko=class{constructor(e,t=Math.random){this.maxParticles=e,this.random=t,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 t=this.findFreeSlot();if(t===-1)return null;let n=e.color??Ol,o=e.velocity??{x:0,y:0,z:0};return this.alive[t]=1,this.positionX[t]=e.position.x,this.positionY[t]=e.position.y,this.positionZ[t]=e.position.z,this.velocityX[t]=o.x,this.velocityY[t]=o.y,this.velocityZ[t]=o.z,this.colorR[t]=n[0],this.colorG[t]=n[1],this.colorB[t]=n[2],this.colorA[t]=n[3],this.size[t]=e.size??2.5,this.lifetime[t]=e.lifetime,this.remaining[t]=e.lifetime,this.gravity[t]=e.gravity??800,this.damping[t]=e.damping??0,this.bounce[t]=e.bounce??.25,this.fade[t]=e.fade?1:0,this.blendMode[t]=e.blendMode==="additive"?1:0,t}update(e,t={}){let n=t.floorZ??-1/0;for(let o=0;o<this.maxParticles;o+=1){if(!this.alive[o])continue;if(this.remaining[o]-=e,this.remaining[o]<=0){this.alive[o]=0;continue}let i=Math.max(0,1-this.damping[o]*e);this.velocityX[o]*=i,this.velocityY[o]*=i,this.velocityZ[o]=this.velocityZ[o]*i-this.gravity[o]*e,this.positionX[o]+=this.velocityX[o]*e,this.positionY[o]+=this.velocityY[o]*e,this.positionZ[o]+=this.velocityZ[o]*e,this.positionZ[o]<n&&(this.positionZ[o]=n,this.velocityZ[o]=-this.velocityZ[o]*this.bounce[o],this.velocityX[o]*=.7,this.velocityY[o]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let t=0;t<this.maxParticles;t+=1)this.alive[t]&&(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,t){let n=[],o=[],i=[],s=a=>{let c=o.length,l=0;for(let u=0;u<this.maxParticles;u+=1){if(!this.alive[u]||(a==="additive"?1:0)!==this.blendMode[u])continue;l+=1;let d=n.length/9,m=this.size[u]*.5,p=this.fade[u]?Math.max(this.remaining[u]/this.lifetime[u],0):1,h=this.blendMode[u]===1?1.2:1,y=this.colorR[u]*h,g=this.colorG[u]*h,b=this.colorB[u]*h,C=this.colorA[u]*p,L=this.positionX[u],q=this.positionY[u],G=this.positionZ[u],Le=e.x*m,B=e.y*m,K=e.z*m,Ie=t.x*m,Ce=t.y*m,et=t.z*m,br=[{x:L-Le-Ie,y:q-B-Ce,z:G-K-et},{x:L+Le-Ie,y:q+B-Ce,z:G+K-et},{x:L-Le+Ie,y:q-B+Ce,z:G-K+et},{x:L+Le+Ie,y:q+B+Ce,z:G+K+et}],Ut=[[0,1],[1,1],[0,0],[1,0]];br.forEach((tt,he)=>{n.push(tt.x,tt.y,tt.z,Ut[he]?.[0]??0,Ut[he]?.[1]??0,y,g,b,C)}),o.push(d,d+1,d+2,d+2,d+1,d+3)}l>0&&i.push({blendMode:a,start:c,count:o.length-c})};return s("alpha"),s("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(o),batches:i}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},ts=`#version 300 es
|
|
289
|
+
precision highp float;
|
|
290
|
+
|
|
291
|
+
layout(location = 0) in vec3 a_position;
|
|
292
|
+
layout(location = 1) in vec2 a_uv;
|
|
293
|
+
layout(location = 2) in vec4 a_color;
|
|
294
|
+
|
|
295
|
+
uniform mat4 u_viewProjection;
|
|
296
|
+
|
|
297
|
+
out vec2 v_uv;
|
|
298
|
+
out vec4 v_color;
|
|
299
|
+
|
|
300
|
+
void main() {
|
|
301
|
+
v_uv = a_uv;
|
|
302
|
+
v_color = a_color;
|
|
303
|
+
gl_Position = u_viewProjection * vec4(a_position, 1.0);
|
|
304
|
+
}`,rs=`#version 300 es
|
|
305
|
+
precision highp float;
|
|
306
|
+
|
|
307
|
+
in vec2 v_uv;
|
|
308
|
+
in vec4 v_color;
|
|
309
|
+
|
|
310
|
+
out vec4 o_color;
|
|
311
|
+
|
|
312
|
+
void main() {
|
|
313
|
+
float dist = distance(v_uv, vec2(0.5));
|
|
314
|
+
float alpha = v_color.a * (1.0 - smoothstep(0.35, 0.5, dist));
|
|
315
|
+
o_color = vec4(v_color.rgb, alpha);
|
|
316
|
+
}`,Yo=class{constructor(e,t){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=t,this.program=ie.create(e,{vertex:ts,fragment:rs}),this.vertexBuffer=new se(e,e.DYNAMIC_DRAW),this.indexBuffer=new we(e,e.DYNAMIC_DRAW),this.vertexArray=new le(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 t=this.system.buildMesh(e.viewRight,e.viewUp);if(t.indices.length===0)return;let n=t.vertices;t.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=t.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let o=t.indices;t.indices.byteLength>this.indexCapacity?(this.indexCapacity=t.indices.byteLength,this.indexBuffer.upload(o,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(o),this.gl.depthMask(!1),this.program.use();let i=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(i,!1,e.viewProjection),this.vertexArray.bind();for(let s of t.batches)s.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,s.count,this.gl.UNSIGNED_SHORT,s.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function Na(r){let{system:e,origin:t,normal:n={x:0,y:0,z:1}}=r;for(let o=0;o<12;o+=1){let i=200+e.random()*180,s=e.random()*.35;e.spawn({position:t,velocity:{x:n.x*i+(e.random()-.5)*80,y:n.y*i+(e.random()-.5)*80,z:Math.max(n.z*i,120)+s*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 o=0;o<8;o+=1)e.spawn({position:t,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 Va(r){let{system:e,origin:t}=r;for(let n=0;n<40;n+=1){let o=e.random()*Math.PI*2,i=Math.acos(2*e.random()-1),s=220+e.random()*260,a={x:Math.sin(i)*Math.cos(o),y:Math.sin(i)*Math.sin(o),z:Math.cos(i)};e.spawn({position:t,velocity:{x:a.x*s,y:a.y*s,z:a.z*s},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:t,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 Ua(r){let{system:e,origin:t,direction:n={x:0,y:0,z:1}}=r;for(let o=0;o<24;o+=1){let i=120+e.random()*180;e.spawn({position:t,velocity:{x:n.x*i+(e.random()-.5)*70,y:n.y*i+(e.random()-.5)*70,z:n.z*i+e.random()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function Ga(r){let{system:e,origin:t}=r;for(let n=0;n<30;n+=1){let o=e.random()*Math.PI*2,i=8+e.random()*8;e.spawn({position:t,velocity:{x:Math.cos(o)*i,y:Math.sin(o)*i,z:100+e.random()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function Wa(r){let{system:e,origin:t,direction:n={x:1,y:0,z:0}}=r;for(let o=0;o<10;o+=1){let i=350+e.random()*100;e.spawn({position:t,velocity:{x:n.x*i+(e.random()-.5)*30,y:n.y*i+(e.random()-.5)*30,z:n.z*i+(e.random()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function Xa(r){let{system:e,origin:t,direction:n={x:0,y:0,z:0}}=r;for(let o=0;o<6;o+=1)e.spawn({position:{x:t.x+n.x*o*2,y:t.y+n.y*o*2,z:t.z+n.z*o*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})}function Bl(r){return{init(){r.trace({x:0,y:0,z:0},{x:0,y:0,z:0})},shutdown(){},createMainLoop(e,t){return new At(e,t)}}}return oc(Nl);})();
|
|
258
317
|
//# sourceMappingURL=index.global.js.map
|