quake2ts 0.0.541 → 0.0.542

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/packages/client/dist/browser/index.global.js.map +1 -1
  3. package/packages/client/dist/cjs/index.cjs.map +1 -1
  4. package/packages/client/dist/esm/index.js.map +1 -1
  5. package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
  6. package/packages/engine/dist/browser/index.global.js +6 -6
  7. package/packages/engine/dist/browser/index.global.js.map +1 -1
  8. package/packages/engine/dist/cjs/index.cjs +19 -2
  9. package/packages/engine/dist/cjs/index.cjs.map +1 -1
  10. package/packages/engine/dist/esm/index.js +19 -2
  11. package/packages/engine/dist/esm/index.js.map +1 -1
  12. package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
  13. package/packages/engine/dist/types/render/bspPipeline.d.ts +1 -0
  14. package/packages/engine/dist/types/render/bspPipeline.d.ts.map +1 -1
  15. package/packages/engine/dist/types/render/collisionVis.d.ts +1 -0
  16. package/packages/engine/dist/types/render/collisionVis.d.ts.map +1 -1
  17. package/packages/engine/dist/types/render/debug.d.ts +1 -0
  18. package/packages/engine/dist/types/render/debug.d.ts.map +1 -1
  19. package/packages/engine/dist/types/render/gpuProfiler.d.ts +4 -0
  20. package/packages/engine/dist/types/render/gpuProfiler.d.ts.map +1 -1
  21. package/packages/engine/dist/types/render/md2Pipeline.d.ts +1 -0
  22. package/packages/engine/dist/types/render/md2Pipeline.d.ts.map +1 -1
  23. package/packages/engine/dist/types/render/md3Pipeline.d.ts +1 -0
  24. package/packages/engine/dist/types/render/md3Pipeline.d.ts.map +1 -1
  25. package/packages/engine/dist/types/render/particleSystem.d.ts +1 -0
  26. package/packages/engine/dist/types/render/particleSystem.d.ts.map +1 -1
  27. package/packages/engine/dist/types/render/renderer.d.ts +2 -0
  28. package/packages/engine/dist/types/render/renderer.d.ts.map +1 -1
  29. package/packages/engine/dist/types/render/shaderProgram.d.ts +1 -0
  30. package/packages/engine/dist/types/render/shaderProgram.d.ts.map +1 -1
  31. package/packages/engine/dist/types/render/skybox.d.ts +1 -0
  32. package/packages/engine/dist/types/render/skybox.d.ts.map +1 -1
  33. package/packages/engine/dist/types/render/sprite.d.ts +1 -0
  34. package/packages/engine/dist/types/render/sprite.d.ts.map +1 -1
  35. package/packages/engine/dist/types/render/types.d.ts +7 -0
  36. package/packages/engine/dist/types/render/types.d.ts.map +1 -1
  37. package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
@@ -138,7 +138,7 @@ KÙ:KµºKí{K]ûK£[KÚKóšKÓ½R׿ÿ'P^j9TîçmóœþL¿_o©×hÙtÙ
138
138
  ÁiŸ;ª•äÀž‡%Ёn= =M+W= ÓÖc[aS
139
139
  FÁð]Nô‡Ý'= “qr(¶ù¤nŒü«òÿ¿d&ÿ ÈõT4Þ=}z|ö ¿OW×SMtdH.τãRX&§o3ؘÜXÍ^œÊM–í£W´iâ]NüOå£S£Å·ƒç÷­˜Ý§½GÑU y¹¦ß§/6P0(Cúýb"þ¥°VٌÄᣈ’ÓÙ@¾YýòDŽŒ{òÃv?’EP©”=MBé­\ĽYäýRò øfâëEEf¼D+gC×úDZGÅÿ±Ç?TzÙ¡±†Ï€ÁÕ¯¦ð‰vZ’mT}Œ3x˘z×cºrÑM=M„ c-ɩԈ™7½wæc§Î»cû¾yf‡ÙWòŒÆÝÔc¥³ôØfƒ«Äñ·9‰ø%­g:y”^+{U]¤þ‚…[&fӁÏY낫‡Gªõ‡¹¦ÖŒðþ¬m„oÛø‘?/ÛS’.[S›9ÛùœC›…/û2”²Y£ÎÑ%/sy¢×ÌùJ­W6Oí\g0^JùêßÏ0í[Ü“'ÏÔ>žÀ-¿[ÔW?Y]±ž ØÙÃî<~ÎëR~Ìf¾Z—/×¼_á¾Þê+îoÐñ{Þ\e3K%©¹§íB¹§(c=}ËÈ·SzÔnf§èx}o\9öf|%Ýå¥~©‚Iǀ ü€ñY8}FfŸú@Rú1éþ3‚÷˂‹ótQøvœû|³Îaá,Óé>BG6Òê}—ÄJ|¶=}°Žˆöf6žõk¶ÌºHgN’j‡Ò{柾M;9·é—§WèO±›Ä3қËÒyt™ ;ù´ˆà©aš|—Ó^!ÝøûšÄ
140
140
  (VV¸ ÇÙcÏ>yoçz ÃvòG{3Þ£½šŠcמôŒ íŚé;°OÛ‰GØ<wÜW> rU]Žq­{û'ùÝír{*øï?t-ígùWÿ…&§] m}×ût¥‚Ë~ß&>&Õv!b#ÅÌ‚q¢µ|jŽÍüùÉ^Æ&™ôžþŸ~sIµ"“]d)uâ´‘ºvk Å\<͉ÿ­öꍽƒÂ
141
- ïBçϧmÙIólÜoëVbƒ¦¯éWÇû3`});var kh={a:Nr};this.setModule=F=>{t.setModule(Dt,F)},this.getModule=()=>t.getModule(Dt),this.instantiate=()=>(this.getModule().then(F=>WebAssembly.instantiate(F,kh)).then(F=>{let He=F.exports;js(He),m=He.l,g(),Th(He),r()}),this.ready=new Promise(F=>{r=F}).then(()=>{this.HEAP=m.buffer,this.malloc=Zc,this.free=Jc,this.create_decoder=pi,this.send_setup=Yc,this.init_dsp=qc,this.decode_packets=jc,this.destroy_decoder=Qc}),this)}function sn(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let s=t[i];this._input.buf.set(s),this._inputLen.buf[0]=s.length,this._common.wasm.decode_packets(this._decoder);let o=this._samplesDecoded.buf[0],a=[],u=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let c=new Float32Array(o);o&&c.set(new Float32Array(this._common.wasm.HEAP,u[l],o)),a.push(c)}e.push(a),r+=o,this._frameNumber++,this._inputBytes+=s.length,this._outputSamples+=o;for(let l=0;l<this._errorsLength.buf;l+=2){let c=this._common.codeToString(this._errors.buf[l]),f=this._common.codeToString(this._errors.buf[l+1]);n.push({message:c+" vorbis_synthesis"+f,frameLength:s.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=sn.isWebWorker,this._WASMAudioDecoderCommon=sn.WASMAudioDecoderCommon||re,this._EmscriptenWASM=sn.EmscriptenWASM||Dt,this._module=sn.module,this._inputSize=128*1024,this._ready=this._init(),this}var qo=Symbol(),Bt=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new re,this._init(),this._ready=this[qo](sn)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new ad("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[qo](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let s=0;s<e.length;s++){let o=e[s];if(this._vorbisSetupInProgress&&(o[Yo][0]===1&&this._decoder.sendSetupHeader(o[Yo]),o[Zo].length)){let a=o[Zo][0][ld];this._decoder.sendSetupHeader(a[ud]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...o[Zo].map(a=>a[Yo]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[cd]){let s=this._totalSamplesDecoded-i[dd];if(s>0){for(let o=0;o<n.channelData.length;o++)n.channelData[o]=n.channelData[o].subarray(0,n.samplesDecoded-s);n.samplesDecoded-=s,this._totalSamplesDecoded-=s}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var Dl=class extends zn{constructor(e){super(e,"ogg-vorbis-decoder",sn,Dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},xs=class extends Bt{constructor(){super(),this._ready=super[qo](Dl)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};vo(Bt,"OggVorbisDecoder");vo(xs,"OggVorbisDecoderWebWorker");var Bl=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function jo(t,e=new Bt){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Bl(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var _s=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},jn=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new Xt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let s=(await this.vfs.readFile(e)).slice().buffer,o=await this.decodeByExtension(e,s);return this.cache.set(r,o),this.refCounts.set(r,1),o}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=_o(r),s=i.channels,o=Array.from({length:s},()=>new Float32Array(i.samples.length/s));for(let a=0;a<i.samples.length;a+=1)o[a%s][Math.floor(a/s)]=i.samples[a];return{sampleRate:i.sampleRate,channels:s,bitDepth:i.bitsPerSample,channelData:o}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return jo(r);throw new _s(`Unsupported audio format: ${e}`)}};var qm="quake2ts-pak-indexes",jm="pak-indexes";function fd(){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 vs(t,e){let r=fd();return r?new Promise((n,i)=>{let s=r.open(t,1);s.onupgradeneeded=()=>{let{result:o}=s;o.objectStoreNames.contains(e)||o.createObjectStore(e,{keyPath:"key"})},s.onerror=()=>i(s.error??new Error("Unknown IndexedDB error")),s.onsuccess=()=>n(s.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function ws(t,e,r,n){return new Promise((i,s)=>{let a=t.transaction(e,r).objectStore(e),u=n(a);u.onsuccess=()=>i(u.result),u.onerror=()=>s(u.error??new Error("IndexedDB transaction error"))})}function Ol(t,e){return`${oe(t)}:${e.toString(16)}`}function Qm(t){return t.map(e=>({...e}))}var Qo=class{constructor(e=qm,r=jm){this.dbName=e;this.storeName=r}get isSupported(){return!!fd()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ol(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:Qm(r.entries)},i=await vs(this.dbName,this.storeName);return await ws(i,this.storeName,"readwrite",s=>s.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await vs(this.dbName,this.storeName),i=r!==void 0?Ol(e,r):void 0,s=await ws(n,this.storeName,"readonly",o=>i?o.get(i):o.getAll());if(n.close(),!!s){if(Array.isArray(s)){let o=oe(e),a=s.filter(u=>oe(u.name)===o);return a.length===0?void 0:a.sort((u,l)=>l.persistedAt-u.persistedAt)[0]}return s}}async remove(e,r){if(!this.isSupported)return!1;let n=await vs(this.dbName,this.storeName),i=r!==void 0?Ol(e,r):void 0,s=await ws(n,this.storeName,"readwrite",o=>{if(i)return o.delete(i);let a=`${oe(e)}:`;return o.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof s=="number"?s>0:!0}async clear(){if(!this.isSupported)return;let e=await vs(this.dbName,this.storeName);await ws(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await vs(this.dbName,this.storeName),r=await ws(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var on=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},Ss=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new on(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},Jo=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.loadQueue=[];this.activeLoads=0;this.textures=new Fn({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new jn(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new Ss,this.resourceTracker=r.resourceTracker,this.md2=new Cn(e),this.md3=new In(e),this.sprite=new Rn(e),this.bsp=new kn(e),this.maxConcurrentLoads=r.maxConcurrentLoads??4,this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Ti(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,o?.size,o?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),s;if(i==="wal")s=xo(n,this.palette);else if(i==="pcx")s=bo(Ti(n));else if(i==="tga")s=Du(gl(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,s),s}async loadSound(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sound",e,i?.size,i?.sourcePak)}let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,a?.size,a?.sourcePak)}let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let o=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),o}getMd2Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md2.get(e)}async loadMd3Model(e,r=[]){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,a?.size,a?.sourcePak)}let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let o=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),o}getMd3Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md3.get(e)}async loadSprite(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sprite",e,i?.size,i?.sourcePak)}let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("map",e,i?.size,i?.sourcePak)}let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear(),this.loadQueue.length=0}getMemoryUsage(){let e=0,r=0;if(typeof process<"u"&&process.memoryUsage){let n=process.memoryUsage();e=n.heapTotal,r=n.heapUsed}return{textures:this.textures.memoryUsage,audio:0,heapTotal:e,heapUsed:r}}clearCache(e){switch(e){case"texture":this.textures.clear();break;case"sound":this.audio.clearAll();break;case"map":this.maps.clear();break}}async preloadAssets(e){let r=e.map(n=>{let i=this.detectAssetType(n);return i?this.queueLoad(n,i,0):Promise.resolve()});await Promise.all(r)}queueLoad(e,r,n=1){return r==="texture"&&this.textures.get(e)?Promise.resolve(this.textures.get(e)):new Promise((i,s)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:s}),this.loadQueue.sort((o,a)=>a.priority-o.priority),this.processQueue()})}async processQueue(){if(this.activeLoads>=this.maxConcurrentLoads||this.loadQueue.length===0)return;let e=this.loadQueue.shift();this.activeLoads++;try{let r;switch(e.type){case"texture":r=await this.loadTexture(e.path);break;case"sound":r=await this.loadSound(e.path);break;case"model":e.path.endsWith(".md2")?r=await this.loadMd2Model(e.path):e.path.endsWith(".md3")&&(r=await this.loadMd3Model(e.path));break;case"sprite":r=await this.loadSprite(e.path);break;case"map":r=await this.loadMap(e.path);break;default:throw new Error(`Unknown asset type ${e.type}`)}e.resolve(r)}catch(r){e.reject(r)}finally{this.activeLoads--,this.processQueue()}}detectAssetType(e){let r=e.split(".").pop()?.toLowerCase();return r?["wal","pcx","tga","png","jpg"].includes(r)?"texture":["wav","ogg"].includes(r)?"sound":["md2","md3"].includes(r)?"model":["sp2"].includes(r)?"sprite":["bsp"].includes(r)?"map":null:null}makeKey(e,r){return`${e}:${oe(r)}`}};var ea=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 ta(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),s;if(e.createConvolver&&e.createGain){let o=e.createConvolver(),a=e.createGain(),u=e.createGain();a.connect(o),o.connect(u),s={convolver:o,input:a,output:u}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),s&&s.output.connect(i)):(r.connect(n),s&&s.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:s}}var ra=class{constructor(e=new En){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var na=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(s=>this.normalize(s)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let s of r)try{let o=this.registry.find(s);if(o!==void 0&&this.registry.has(o)){n.skipped.push(s);continue}if(!this.vfs.stat(s)){n.missing.push(s);continue}let l=(await this.vfs.readFile(s)).slice().buffer,c=await this.decodeAudio(i,l);this.registry.register(s,c),n.loaded.push(s)}catch(o){let a=o instanceof Error?o:new Error(String(o));n.errors[s]=a}return n}normalize(e){let r=oe(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:oe(`${this.soundRoot}${r}`)}};var Jm=7,As=t=>t&Jm;function ia(t){return Array.from({length:_i},()=>({entnum:0,entchannel:ot.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function sa(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=As(r),s=-1,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let u=t[a],l=As(u.entchannel);if(i!==ot.Auto&&u.entnum===e&&l===i){s=a;break}if(u.active&&u.entnum===n.playerEntity&&e!==n.playerEntity)continue;let c=u.endTimeMs-n.nowMs;(s===-1||c<o)&&(o=c,s=a)}return s===-1?void 0:s}var oa=class{constructor(e){this.activePreset=null;this.enabled=!0;this.node=e,this.node.input.gain.value=.5,this.node.output.gain.value=1}setPreset(e){this.activePreset=e,this.node.convolver.buffer!==(e?.buffer??null)&&(this.node.convolver.buffer=e?.buffer??null),e&&e.gain!==void 0?this.node.output.gain.value=e.gain:this.node.output.gain.value=1}setEnabled(e){this.enabled=e,e?this.node.input.gain.value=.5:this.node.input.gain.value=0}getOutputNode(){return this.node.output}getInputNode(){return this.node.input}};var aa=class{constructor(e){this.activeSources=new Map;this.playbackRate=1;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=ia(e.playerEntity),this.listener=e.listener??{origin:nu,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=ta(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new oa(this.graph.reverb))}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}setPlaybackRate(e){this.playbackRate=e;for(let r of this.activeSources.values())r.source.playbackRate&&(r.source.playbackRate.value=e),this.updateSourceGain(r)}async ensureRunning(){await this.contextController.resume()}setReverbPreset(e){this.reverb?.setPreset(e)}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,s=sa(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(s===void 0)return;let o=this.activeSources.get(s);o&&(o.source.onended=null,o.source.stop(),this.activeSources.delete(s));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1,a.playbackRate&&(a.playbackRate.value=this.playbackRate);let u=e.origin??this.listener.origin,l=n.createGain(),c=this.createPanner(n,e.attenuation),f=this.resolveOcclusion?.(this.listener,u,e.attenuation),d=hd(f?.gainScale??1),h=this.resolveOcclusion?this.createOcclusionFilter(n,f?.lowpassHz??2e4):void 0;this.applyOriginToPanner(c,u);let g=e.volume/255*this.sfxVolume,p=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=g*d*p;let y=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+y*1e3;a.connect(c);let x=c;h?(c.connect(h),h.connect(l),x=l):(c.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),a.start(y),a.onended=()=>{this.channels[s].active=!1,this.activeSources.delete(s)};let b={channelIndex:s,entnum:e.entity,entchannel:As(e.channel),endTimeMs:_,source:a,panner:c,gain:l,baseGain:g,origin:u,attenuation:e.attenuation,occlusion:h?{scale:d,lowpassHz:f?.lowpassHz,filter:h}:f?{scale:d,lowpassHz:f.lowpassHz}:void 0};return this.channels[s]={entnum:e.entity,entchannel:As(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(s,b),b}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:ot.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:ot.Auto,soundIndex:r,volume:n,attenuation:vi,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=Sn(r);return e.refDistance=wn,e.maxDistance=Vr(r),e.rolloffFactor=n,e.distanceModel="linear",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Nl(r,10,2e4),n}updateSourceGain(e){let r=e.occlusion?.scale??1,n=Math.abs(this.playbackRate-1)<.001?1:0;e.gain.gain.value=e.baseGain*r*n}applyOcclusion(e,r){let n=hd(r?.gainScale??1),i=Math.abs(this.playbackRate-1)<.001?1:0;if(e.gain.gain.value=e.baseGain*n*i,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Nl(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Nl=(t,e,r)=>Math.min(r,Math.max(e,t)),hd=t=>Nl(t,0,1);var Ms=class{constructor(e){this.trace=e;this.resolve=(e,r,n)=>{let i=Za(iu(r,e.origin)),s=Vr(n),u=2e4*(1-Math.min(i,s)/Math.max(1,s)*.9),l=this.trace(e.origin,r,void 0,void 0),c=1,f=2e4;l.fraction<1&&(c=.3,f=400);let d=Math.min(u,f);if(c<1||d<2e4)return{gainScale:c,lowpassHz:d}}}};function md(t){return new Ms(t).resolve}var la=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1,this.crossfadeDuration=e.crossfadeDuration??1}async playTrack(e){let r=`music/track${e.toString().padStart(2,"0")}.ogg`;return this.play(r)}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.currentElement){this.currentElement.loop=r,this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement.volume=this.volume,n&&(this.currentElement.currentTime=0),(this.currentElement.paused||n)&&await this.currentElement.play();return}let i=await this.resolveSource(e);this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement&&(this.fadingElement=this.currentElement,this.currentElement=void 0);let s=this.createElement();s.src=i,s.loop=r,s.volume=0,s.currentTime=0,s.load();try{await s.play()}catch(o){console.warn(`MusicSystem: Failed to play ${e}`,o),this.fadingElement}this.currentElement=s,this.track=e,this.startCrossfade()}pause(){this.cancelFade(),this.currentElement&&!this.currentElement.paused&&this.currentElement.pause(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0)}async resume(){!this.currentElement||!this.currentElement.paused||(await this.currentElement.play(),this.currentElement.volume=this.volume)}stop(){this.cancelFade(),this.currentElement&&(this.currentElement.pause(),this.currentElement.currentTime=0,this.currentElement=void 0),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.track=void 0}setVolume(e){this.volume=e,this.currentElement&&!this.fadeInterval&&(this.currentElement.volume=e)}getState(){let e=!!(this.currentElement&&!this.currentElement.paused&&!this.currentElement.ended),r=!!this.currentElement?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}startCrossfade(){let r=this.crossfadeDuration*1e3/50,n=this.volume/r,i=0,s=this.fadingElement?this.fadingElement.volume:0,o=()=>{let a=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(a=!0)),this.fadingElement&&(s=Math.max(0,s-n),this.fadingElement.volume=s,s>0?a=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),a||this.cancelFade()};o(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(o,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function ep(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 tp(t,e,r,n){for(let i of e){let s=t.getExtension(i);if(!s)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,s)}for(let i of r){let s=t.getExtension(i);s&&n.set(i,s)}}function pd(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,s=t.getContext("webgl2",r??{antialias:!0});if(!s)throw new Error("WebGL2 not supported or failed to initialize");ep(s);let o=new Map;tp(s,n,i,o);let a=!1,u=new Set,l=new Set,c=d=>{a=!0,d.preventDefault();for(let h of u)h()},f=()=>{a=!1;for(let d of l)d()};return t.addEventListener("webglcontextlost",c),t.addEventListener("webglcontextrestored",f),{gl:s,extensions:o,isLost:()=>a,onLost(d){return u.add(d),()=>u.delete(d)},onRestored(d){return l.add(d),()=>l.delete(d)},dispose(){t.removeEventListener("webglcontextlost",c),t.removeEventListener("webglcontextrestored",f),u.clear(),l.clear(),o.clear()}}}function gd(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let s=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(s)}return n}function rp(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[o,a]of Object.entries(n))t.bindAttribLocation(i,a,o);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let o=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(o)}return i}var Le=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 i=gd(e,e.VERTEX_SHADER,r.vertex),s=gd(e,e.FRAGMENT_SHADER,r.fragment);try{let o=rp(e,i,s,n);return new t(e,o)}finally{e.deleteShader(i),e.deleteShader(s)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function yd(t,e,r){return Le.create(t,e,r)}var Te=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},xe=class extends Te{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)}},Qn=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,s,o,a,u){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,s,o,a,u)}dispose(){this.gl.deleteTexture(this.texture)}},Jn=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,s,o,a,u,l){this.bind(),this.gl.texImage2D(e,r,n,i,s,o,a,u,l)}dispose(){this.gl.deleteTexture(this.texture)}},ca=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 Hl=4,Ul=7*Hl,Vl=[{index:0,size:3,type:5126,stride:Ul,offset:0},{index:1,size:2,type:5126,stride:Ul,offset:3*Hl},{index:2,size:2,type:5126,stride:Ul,offset:5*Hl}];function np(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function ip(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 sp(t,e,r){let n=ip(r),i=t.width*4,s=e.x+t.padding,o=e.y+t.padding,a=0;for(let u=0;u<r.height;u++){let l=(o+u)*i+s*4;for(let c=0;c<r.width;c++){let f=l+c*4;t.data[f]=r.samples[a],t.data[f+1]=r.samples[a+1],t.data[f+2]=r.samples[a+2],t.data[f+3]=n===4?r.samples[a+3]:255,a+=n}}}function op(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+i>a.height)continue;let u={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,i),{placement:u,atlas:a}}let s=np(r.atlasSize,r.lightmapPadding);t.push(s);let o={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return s.cursorX=n+r.lightmapPadding,s.rowHeight=i,{placement:o,atlas:s}}function ua(t){return t instanceof Float32Array?t:new Float32Array(t)}function ap(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function lp(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 cp(t,e){let r=ua(t.vertices),n=ua(t.textureCoords),i=e?lp(ua(t.lightmapCoords??t.textureCoords),e):ua(t.lightmapCoords??new Float32Array(n.length)),s=r.length/3;if(n.length/2!==s)throw new Error("Texture coordinates count mismatch");if(i.length/2!==s)throw new Error("Lightmap coordinates count mismatch");let o=new Float32Array(s*7);for(let a=0;a<s;a++){let u=a*3,l=a*2,c=a*7;o[c]=r[u],o[c+1]=r[u+1],o[c+2]=r[u+2],o[c+3]=n[l],o[c+4]=n[l+1],o[c+5]=i[l],o[c+6]=i[l+1]}return o}function bd(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],s=[],o=[],a=[];for(let d=0;d<n.numEdges;d++){let h=t.surfEdges[n.firstEdge+d],m=t.edges[Math.abs(h)],g=h>=0?m.vertices[0]:m.vertices[1],p=t.vertices[g];s.push(p[0],p[1],p[2]);let y=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,_=p[0]*i.t[0]+p[1]*i.t[1]+p[2]*i.t[2]+i.tOffset;o.push(y,_),a.push(y,_)}let u=[],l=s.length/3;for(let d=1;d<l-1;d++)u.push(0,d,d+1);let c,f=t.lightMapInfo[r];if(f){let d=1/0,h=-1/0,m=1/0,g=-1/0;for(let v=0;v<o.length;v+=2){let S=o[v],w=o[v+1];S<d&&(d=S),S>h&&(h=S),w<m&&(m=w),w>g&&(g=w)}let p=Math.floor(d/16),y=Math.floor(m/16),_=Math.ceil(h/16)-p+1,x=Math.ceil(g/16)-y+1,b=mo(n,t.lightMaps,f);if(b&&b.length===_*x*3){c={width:_,height:x,samples:b};for(let v=0;v<a.length;v+=2)a[v]=o[v]/16-p+.5,a[v+1]=o[v+1]/16-y+.5}}e.push({vertices:new Float32Array(s),textureCoords:new Float32Array(o),lightmapCoords:new Float32Array(a),indices:new Uint16Array(u),texture:i.texture,surfaceFlags:i.flags,lightmap:c,faceIndex:r})}return e}function xd(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let c=new Set;for(let f of r.entities.entities)if(f.classname&&n.hiddenClassnames.has(f.classname)){let d=f.properties.model;if(d&&d.startsWith("*")){let h=parseInt(d.substring(1),10);if(!isNaN(h)&&h>=0&&h<r.models.length){let m=r.models[h];for(let g=0;g<m.numFaces;g++)c.add(m.firstFace+g)}}}c.size>0&&(i=e.filter(f=>!c.has(f.faceIndex)))}let s={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},o=[],a=new Map;i.forEach((c,f)=>{if(!c.lightmap)return;let{placement:d,atlas:h}=op(o,c.lightmap,s);sp(h,d,c.lightmap),a.set(f,{atlasIndex:d.atlasIndex,offset:[(d.x+s.lightmapPadding)/s.atlasSize,(d.y+s.lightmapPadding)/s.atlasSize],scale:[d.width/s.atlasSize,d.height/s.atlasSize]})});let u=o.map(c=>{let f=new Qn(t);return f.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),f.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:f,width:c.width,height:c.height,pixels:c.data}});return{surfaces:i.map((c,f)=>{let d=a.get(f),h=cp(c,d),m=ap(c.indices,h.length/7),g=new Te(t,t.STATIC_DRAW,t.ARRAY_BUFFER);g.upload(h);let p=new xe(t,t.STATIC_DRAW);p.upload(m);let y=new Re(t);return y.configureAttributes(Vl,g),{vao:y,vertexBuffer:g,indexBuffer:p,indexCount:m.length,vertexCount:h.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??xi,lightmap:d,vertexData:h,indexData:m}}),lightmaps:u}}function ei(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function _d(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],s=t[1],o=t[5],a=t[9],u=t[13],l=t[2],c=t[6],f=t[10],d=t[14],h=t[3],m=t[7],g=t[11],p=t[15];return[ei({normal:{x:h+e,y:m+r,z:g+n},distance:p+i}),ei({normal:{x:h-e,y:m-r,z:g-n},distance:p-i}),ei({normal:{x:h+s,y:m+o,z:g+a},distance:p+u}),ei({normal:{x:h-s,y:m-o,z:g-a},distance:p-u}),ei({normal:{x:h+l,y:m+c,z:g+f},distance:p+d}),ei({normal:{x:h-l,y:m-c,z:g-f},distance:p-d})]}function up(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Es(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,s=n.normal.y>=0?e.y:t.y,o=n.normal.z>=0?e.z:t.z;if(up(n,{x:i,y:s,z:o})<0)return!1}return!0}function vd(t){return t<0}function wd(t){return-t-1}function Sd(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function dp(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,s=Math.floor(r/8),o=1<<r%8;return s<0||s>=n?!1:(i[s]&o)!==0}function fp(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 Es(r,n,e)}function Wl(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],o=Sd(i,e)>=0?0:1,a=n.children[o];if(vd(a))return wd(a);r=a}return-1}function hp(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Gl(t,e,r,n,i,s,o){if(vd(e)){let d=wd(e),h=t.leafs[d];if(!dp(t.visibility,i,h.cluster)||!fp(h,n))return;let m={x:(h.mins[0]+h.maxs[0])*.5,y:(h.mins[1]+h.maxs[1])*.5,z:(h.mins[2]+h.maxs[2])*.5},g=m.x-r.x,p=m.y-r.y,y=m.z-r.z,_=-(g*g+p*p+y*y);for(let x of hp(t,d))o.has(x)||(o.add(x),s.push({faceIndex:x,leafIndex:d,sortKey:_}));return}let a=t.nodes[e],u=t.planes[a.planeIndex],l=Sd(u,r),c=l>=0?a.children[0]:a.children[1],f=l>=0?a.children[1]:a.children[0];Es({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)&&(Gl(t,c,r,n,i,s,o),Gl(t,f,r,n,i,s,o))}function Ad(t,e,r){let n=Wl(t,e),i=n>=0?t.leafs[n].cluster:-1,s=[];return Gl(t,0,e,r,i,s,new Set),s}var ur=32,da=class{constructor(){this.lights=[]}addLight(e,r){if(e.key!==void 0){let n=this.lights.findIndex(i=>i.key===e.key);if(n!==-1){this.lights[n]=e;return}}this.lights.push(e)}clear(){this.lights=[]}update(e,r=0){if(this.lights=this.lights.filter(n=>n.die>e),r>0)for(let n of this.lights)n.radiusSpeed!==void 0&&n.radiusSpeed!==0&&(n.intensity+=n.radiusSpeed*r,n.intensity<0&&(n.intensity=0))}getActiveLights(){return this.lights}};function ti(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],s=t[r+2];e.push(n,i,i,s,s,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var Xl=`#version 300 es
141
+ ïBçϧmÙIólÜoëVbƒ¦¯éWÇû3`});var kh={a:Nr};this.setModule=F=>{t.setModule(Dt,F)},this.getModule=()=>t.getModule(Dt),this.instantiate=()=>(this.getModule().then(F=>WebAssembly.instantiate(F,kh)).then(F=>{let He=F.exports;js(He),m=He.l,g(),Th(He),r()}),this.ready=new Promise(F=>{r=F}).then(()=>{this.HEAP=m.buffer,this.malloc=Zc,this.free=Jc,this.create_decoder=pi,this.send_setup=Yc,this.init_dsp=qc,this.decode_packets=jc,this.destroy_decoder=Qc}),this)}function sn(){return this._init=()=>new this._WASMAudioDecoderCommon().instantiate(this._EmscriptenWASM,this._module).then(t=>{this._common=t,this._input=this._common.allocateTypedArray(this._inputSize,Uint8Array),this._firstPage=!0,this._inputLen=this._common.allocateTypedArray(1,Uint32Array),this._outputBufferPtr=this._common.allocateTypedArray(1,Uint32Array),this._channels=this._common.allocateTypedArray(1,Uint32Array),this._sampleRate=this._common.allocateTypedArray(1,Uint32Array),this._samplesDecoded=this._common.allocateTypedArray(1,Uint32Array);let e=256;this._errors=this._common.allocateTypedArray(e,Uint32Array),this._errorsLength=this._common.allocateTypedArray(1,Int32Array),this._frameNumber=0,this._inputBytes=0,this._outputSamples=0,this._decoder=this._common.wasm.create_decoder(this._input.ptr,this._inputLen.ptr,this._outputBufferPtr.ptr,this._channels.ptr,this._sampleRate.ptr,this._samplesDecoded.ptr,this._errors.ptr,this._errorsLength.ptr,e)}),Object.defineProperty(this,"ready",{enumerable:!0,get:()=>this._ready}),this.reset=()=>(this.free(),this._init()),this.free=()=>{this._common.wasm.destroy_decoder(this._decoder),this._common.free()},this.sendSetupHeader=t=>{this._input.buf.set(t),this._inputLen.buf[0]=t.length,this._common.wasm.send_setup(this._decoder,this._firstPage),this._firstPage=!1},this.initDsp=()=>{this._common.wasm.init_dsp(this._decoder)},this.decodePackets=t=>{let e=[],r=0,n=[];for(let i=0;i<t.length;i++){let s=t[i];this._input.buf.set(s),this._inputLen.buf[0]=s.length,this._common.wasm.decode_packets(this._decoder);let o=this._samplesDecoded.buf[0],a=[],u=new Uint32Array(this._common.wasm.HEAP,this._outputBufferPtr.buf[0],this._channels.buf[0]);for(let l=0;l<this._channels.buf[0];l++){let c=new Float32Array(o);o&&c.set(new Float32Array(this._common.wasm.HEAP,u[l],o)),a.push(c)}e.push(a),r+=o,this._frameNumber++,this._inputBytes+=s.length,this._outputSamples+=o;for(let l=0;l<this._errorsLength.buf;l+=2){let c=this._common.codeToString(this._errors.buf[l]),f=this._common.codeToString(this._errors.buf[l+1]);n.push({message:c+" vorbis_synthesis"+f,frameLength:s.length,frameNumber:this._frameNumber,inputBytes:this._inputBytes,outputSamples:this._outputSamples})}this._errorsLength.buf[0]=0}return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel(n,e,this._channels.buf[0],r,this._sampleRate.buf[0],16)},this._isWebWorker=sn.isWebWorker,this._WASMAudioDecoderCommon=sn.WASMAudioDecoderCommon||re,this._EmscriptenWASM=sn.EmscriptenWASM||Dt,this._module=sn.module,this._inputSize=128*1024,this._ready=this._init(),this}var qo=Symbol(),Bt=class{constructor(){this._onCodec=e=>{if(e!=="vorbis")throw new Error("@wasm-audio-decoders/ogg-vorbis does not support this codec "+e)},new re,this._init(),this._ready=this[qo](sn)}_init(){this._vorbisSetupInProgress=!0,this._totalSamplesDecoded=0,this._codecParser=new ad("audio/ogg",{onCodec:this._onCodec,enableFrameCRC32:!1})}async[qo](e){if(this._decoder){let r=this._decoder;await r.ready.then(()=>r.free())}return this._decoder=new e,this._decoder.ready}get ready(){return this._ready}async reset(){return this._init(),this._decoder.reset()}free(){this._decoder.free()}async decodeOggPages(e){let r=[];for(let s=0;s<e.length;s++){let o=e[s];if(this._vorbisSetupInProgress&&(o[Yo][0]===1&&this._decoder.sendSetupHeader(o[Yo]),o[Zo].length)){let a=o[Zo][0][ld];this._decoder.sendSetupHeader(a[ud]),this._decoder.initDsp(),this._vorbisSetupInProgress=!1}r.push(...o[Zo].map(a=>a[Yo]))}let n=await this._decoder.decodePackets(r);this._totalSamplesDecoded+=n.samplesDecoded;let i=e[e.length-1];if(i&&i[cd]){let s=this._totalSamplesDecoded-i[dd];if(s>0){for(let o=0;o<n.channelData.length;o++)n.channelData[o]=n.channelData[o].subarray(0,n.samplesDecoded-s);n.samplesDecoded-=s,this._totalSamplesDecoded-=s}}return n}async decode(e){return this.decodeOggPages([...this._codecParser.parseChunk(e)])}async flush(){let e=await this.decodeOggPages([...this._codecParser.flush()]);return await this.reset(),e}async decodeFile(e){let r=await this.decodeOggPages([...this._codecParser.parseAll(e)]);return await this.reset(),r}};var Dl=class extends zn{constructor(e){super(e,"ogg-vorbis-decoder",sn,Dt)}async sendSetupHeader(e){return this.postToDecoder("sendSetupHeader",e)}async initDsp(){return this.postToDecoder("initDsp")}async decodePackets(e){return this.postToDecoder("decodePackets",e)}},xs=class extends Bt{constructor(){super(),this._ready=super[qo](Dl)}async free(){await this._decoder.free()}terminate(){this._decoder.terminate()}};vo(Bt,"OggVorbisDecoder");vo(xs,"OggVorbisDecoderWebWorker");var Bl=class extends Error{constructor(e){super(e),this.name="OggDecodeError"}};async function jo(t,e=new Bt){await e.ready;let r=await e.decode(new Uint8Array(t)),n=r.errors;if(n&&n.length>0)throw new Bl(n.map(i=>i.message).join("; "));return{sampleRate:r.sampleRate,channels:r.channelData.length,bitDepth:r.bitDepth,channelData:r.channelData}}var _s=class extends Error{constructor(e){super(e),this.name="AudioRegistryError"}},jn=class{constructor(e,r={}){this.vfs=e;this.refCounts=new Map;this.cache=new Xt(r.cacheSize??64)}get size(){return this.cache.size}async load(e){let r=e.toLowerCase(),n=this.cache.get(r);if(n)return this.refCounts.set(r,(this.refCounts.get(r)??0)+1),n;let s=(await this.vfs.readFile(e)).slice().buffer,o=await this.decodeByExtension(e,s);return this.cache.set(r,o),this.refCounts.set(r,1),o}release(e){let r=e.toLowerCase(),n=this.refCounts.get(r)??0;n<=1?(this.cache.delete(r),this.refCounts.delete(r)):this.refCounts.set(r,n-1)}clearAll(){this.cache.clear(),this.refCounts.clear()}async decodeByExtension(e,r){let n=e.toLowerCase();if(n.endsWith(".wav")){let i=_o(r),s=i.channels,o=Array.from({length:s},()=>new Float32Array(i.samples.length/s));for(let a=0;a<i.samples.length;a+=1)o[a%s][Math.floor(a/s)]=i.samples[a];return{sampleRate:i.sampleRate,channels:s,bitDepth:i.bitsPerSample,channelData:o}}if(n.endsWith(".ogg")||n.endsWith(".oga"))return jo(r);throw new _s(`Unsupported audio format: ${e}`)}};var qm="quake2ts-pak-indexes",jm="pak-indexes";function fd(){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 vs(t,e){let r=fd();return r?new Promise((n,i)=>{let s=r.open(t,1);s.onupgradeneeded=()=>{let{result:o}=s;o.objectStoreNames.contains(e)||o.createObjectStore(e,{keyPath:"key"})},s.onerror=()=>i(s.error??new Error("Unknown IndexedDB error")),s.onsuccess=()=>n(s.result)}):Promise.reject(new Error("IndexedDB is not available in this environment"))}function ws(t,e,r,n){return new Promise((i,s)=>{let a=t.transaction(e,r).objectStore(e),u=n(a);u.onsuccess=()=>i(u.result),u.onerror=()=>s(u.error??new Error("IndexedDB transaction error"))})}function Ol(t,e){return`${oe(t)}:${e.toString(16)}`}function Qm(t){return t.map(e=>({...e}))}var Qo=class{constructor(e=qm,r=jm){this.dbName=e;this.storeName=r}get isSupported(){return!!fd()}async persist(e){if(!this.isSupported)return;let r=e.validate(),n={...r,key:Ol(e.name,r.checksum),name:e.name,size:e.size,persistedAt:Date.now(),entries:Qm(r.entries)},i=await vs(this.dbName,this.storeName);return await ws(i,this.storeName,"readwrite",s=>s.put(n)),i.close(),n}async find(e,r){if(!this.isSupported)return;let n=await vs(this.dbName,this.storeName),i=r!==void 0?Ol(e,r):void 0,s=await ws(n,this.storeName,"readonly",o=>i?o.get(i):o.getAll());if(n.close(),!!s){if(Array.isArray(s)){let o=oe(e),a=s.filter(u=>oe(u.name)===o);return a.length===0?void 0:a.sort((u,l)=>l.persistedAt-u.persistedAt)[0]}return s}}async remove(e,r){if(!this.isSupported)return!1;let n=await vs(this.dbName,this.storeName),i=r!==void 0?Ol(e,r):void 0,s=await ws(n,this.storeName,"readwrite",o=>{if(i)return o.delete(i);let a=`${oe(e)}:`;return o.delete(IDBKeyRange.bound(a,`${a}\uFFFF`,!1,!0))});return n.close(),typeof s=="number"?s>0:!0}async clear(){if(!this.isSupported)return;let e=await vs(this.dbName,this.storeName);await ws(e,this.storeName,"readwrite",r=>r.clear()),e.close()}async list(){if(!this.isSupported)return[];let e=await vs(this.dbName,this.storeName),r=await ws(e,this.storeName,"readonly",n=>n.getAll());return e.close(),r.sort((n,i)=>i.persistedAt-n.persistedAt)}};var on=class extends Error{constructor(r,n){super(n??`Missing dependencies: ${r.join(", ")}`);this.missing=r;this.name="AssetDependencyError"}},Ss=class{constructor(){this.nodes=new Map}register(e,r=[]){let n=this.nodes.get(e)??{dependencies:new Set,loaded:!1};r.forEach(i=>n.dependencies.add(i)),this.nodes.set(e,n),r.forEach(i=>{this.nodes.has(i)||this.nodes.set(i,{dependencies:new Set,loaded:!1})})}markLoaded(e){let r=this.nodes.get(e)??{dependencies:new Set,loaded:!1},n=this.getMissingDependencies(e,r);if(n.length>0)throw new on(n,`Asset ${e} is missing dependencies: ${n.join(", ")}`);r.loaded=!0,this.nodes.set(e,r)}markUnloaded(e){let r=this.nodes.get(e);r&&(r.loaded=!1)}isLoaded(e){return this.nodes.get(e)?.loaded??!1}missingDependencies(e){let r=this.nodes.get(e);return r?this.getMissingDependencies(e,r):[]}reset(){this.nodes.clear()}getMissingDependencies(e,r){let n=[];for(let i of r.dependencies)this.nodes.get(i)?.loaded||n.push(i);return n}},Jo=class{constructor(e,r={}){this.vfs=e;this.maps=new Map;this.loadQueue=[];this.activeLoads=0;this.textures=new Fn({capacity:r.textureCacheCapacity??128,maxMemory:r.textureMemoryLimit}),this.audio=new jn(e,{cacheSize:r.audioCacheSize??64}),this.dependencyTracker=r.dependencyTracker??new Ss,this.resourceTracker=r.resourceTracker,this.md2=new Cn(e),this.md3=new In(e),this.sprite=new Rn(e),this.bsp=new kn(e),this.maxConcurrentLoads=r.maxConcurrentLoads??4,this.palette=new Uint8Array(768);for(let n=0;n<256;n++)this.palette[n*3]=n,this.palette[n*3+1]=n,this.palette[n*3+2]=n}async loadPalette(e="pics/colormap.pcx"){try{let r=await this.vfs.readFile(e),n=Ti(r);n.palette&&(this.palette=n.palette)}catch(r){console.warn(`Failed to load palette from ${e}:`,r)}}isAssetLoaded(e,r){return this.dependencyTracker.isLoaded(this.makeKey(e,r))}registerTexture(e,r){this.textures.set(e,r);let n=this.makeKey("texture",e);this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n)}async loadTexture(e){if(this.resourceTracker){let o=this.vfs.stat(e);this.resourceTracker.recordLoad("texture",e,o?.size,o?.sourcePak)}let r=this.textures.get(e);if(r)return r;let n=await this.vfs.readFile(e),i=e.split(".").pop()?.toLowerCase(),s;if(i==="wal")s=xo(n,this.palette);else if(i==="pcx")s=bo(Ti(n));else if(i==="tga")s=Du(gl(n));else throw new Error(`Unsupported texture format for loadTexture: ${i}`);return this.registerTexture(e,s),s}async loadSound(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sound",e,i?.size,i?.sourcePak)}let r=await this.audio.load(e),n=this.makeKey("sound",e);return this.dependencyTracker.register(n),this.dependencyTracker.markLoaded(n),r}async loadMd2Model(e,r=[]){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,a?.size,a?.sourcePak)}let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let o=await this.md2.load(e);return this.dependencyTracker.markLoaded(n),o}getMd2Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md2.get(e)}async loadMd3Model(e,r=[]){if(this.resourceTracker){let a=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,a?.size,a?.sourcePak)}let n=this.makeKey("model",e),i=r.map(a=>this.makeKey("texture",a));this.dependencyTracker.register(n,i);let s=this.dependencyTracker.missingDependencies(n);if(s.length>0)throw new on(s,`Asset ${n} is missing dependencies: ${s.join(", ")}`);let o=await this.md3.load(e);return this.dependencyTracker.markLoaded(n),o}getMd3Model(e){if(this.resourceTracker){let r=this.vfs.stat(e);this.resourceTracker.recordLoad("model",e,r?.size,r?.sourcePak)}return this.md3.get(e)}async loadSprite(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("sprite",e,i?.size,i?.sourcePak)}let r=this.makeKey("sprite",e);this.dependencyTracker.register(r);let n=await this.sprite.load(e);return this.dependencyTracker.markLoaded(r),n}async loadMap(e){if(this.resourceTracker){let i=this.vfs.stat(e);this.resourceTracker.recordLoad("map",e,i?.size,i?.sourcePak)}let r=this.makeKey("map",e);if(this.maps.has(e))return this.maps.get(e);this.dependencyTracker.register(r);let n=await this.bsp.load(e);return this.maps.set(e,n),this.dependencyTracker.markLoaded(r),n}getMap(e){return this.maps.get(e)}listFiles(e){return this.vfs.findByExtension(e)}resetForLevelChange(){this.textures.clear(),this.audio.clearAll(),this.dependencyTracker.reset(),this.maps.clear(),this.loadQueue.length=0}getMemoryUsage(){let e=0,r=0;if(typeof process<"u"&&process.memoryUsage){let n=process.memoryUsage();e=n.heapTotal,r=n.heapUsed}return{textures:this.textures.memoryUsage,audio:0,heapTotal:e,heapUsed:r}}clearCache(e){switch(e){case"texture":this.textures.clear();break;case"sound":this.audio.clearAll();break;case"map":this.maps.clear();break}}async preloadAssets(e){let r=e.map(n=>{let i=this.detectAssetType(n);return i?this.queueLoad(n,i,0):Promise.resolve()});await Promise.all(r)}queueLoad(e,r,n=1){return r==="texture"&&this.textures.get(e)?Promise.resolve(this.textures.get(e)):new Promise((i,s)=>{this.loadQueue.push({path:e,type:r,priority:n,resolve:i,reject:s}),this.loadQueue.sort((o,a)=>a.priority-o.priority),this.processQueue()})}async processQueue(){if(this.activeLoads>=this.maxConcurrentLoads||this.loadQueue.length===0)return;let e=this.loadQueue.shift();this.activeLoads++;try{let r;switch(e.type){case"texture":r=await this.loadTexture(e.path);break;case"sound":r=await this.loadSound(e.path);break;case"model":e.path.endsWith(".md2")?r=await this.loadMd2Model(e.path):e.path.endsWith(".md3")&&(r=await this.loadMd3Model(e.path));break;case"sprite":r=await this.loadSprite(e.path);break;case"map":r=await this.loadMap(e.path);break;default:throw new Error(`Unknown asset type ${e.type}`)}e.resolve(r)}catch(r){e.reject(r)}finally{this.activeLoads--,this.processQueue()}}detectAssetType(e){let r=e.split(".").pop()?.toLowerCase();return r?["wal","pcx","tga","png","jpg"].includes(r)?"texture":["wav","ogg"].includes(r)?"sound":["md2","md3"].includes(r)?"model":["sp2"].includes(r)?"sprite":["bsp"].includes(r)?"map":null:null}makeKey(e,r){return`${e}:${oe(r)}`}};var ea=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 ta(t){let e=t.getContext(),r=e.createGain();r.gain.value=1;let n=e.createDynamicsCompressor(),i=e.createBiquadFilter?.(),s;if(e.createConvolver&&e.createGain){let o=e.createConvolver(),a=e.createGain(),u=e.createGain();a.connect(o),o.connect(u),s={convolver:o,input:a,output:u}}return i?(i.type="lowpass",i.frequency.value=2e4,i.Q.value=.707,r.connect(i),i.connect(n),s&&s.output.connect(i)):(r.connect(n),s&&s.output.connect(n)),n.connect(e.destination),{context:e,master:r,compressor:n,filter:i,reverb:s}}var ra=class{constructor(e=new En){this.configStrings=e;this.buffers=new Map}registerName(e){return this.configStrings.soundIndex(e)}register(e,r){let n=this.registerName(e);return this.buffers.set(n,r),n}find(e){return this.configStrings.findSoundIndex(e)}get(e){return this.buffers.get(e)}has(e){return this.buffers.has(e)}getName(e){return this.configStrings.getName(e)}};var na=class{constructor(e){this.vfs=e.vfs,this.registry=e.registry,this.contextController=e.context,this.soundRoot=e.soundRoot??"sound/",this.decodeAudio=e.decodeAudio??((r,n)=>{if(!r.decodeAudioData)throw new Error("decodeAudioData is not available on the provided audio context");return r.decodeAudioData(n)})}async precache(e){let r=[...new Set(e.map(s=>this.normalize(s)))],n={loaded:[],skipped:[],missing:[],errors:{}},i=this.contextController.getContext();for(let s of r)try{let o=this.registry.find(s);if(o!==void 0&&this.registry.has(o)){n.skipped.push(s);continue}if(!this.vfs.stat(s)){n.missing.push(s);continue}let l=(await this.vfs.readFile(s)).slice().buffer,c=await this.decodeAudio(i,l);this.registry.register(s,c),n.loaded.push(s)}catch(o){let a=o instanceof Error?o:new Error(String(o));n.errors[s]=a}return n}normalize(e){let r=oe(e.replace(/^\//,""));return r.startsWith(this.soundRoot)?r:oe(`${this.soundRoot}${r}`)}};var Jm=7,As=t=>t&Jm;function ia(t){return Array.from({length:_i},()=>({entnum:0,entchannel:ot.Auto,endTimeMs:0,isPlayer:!1,active:!1})).map(e=>({...e,isPlayer:e.entnum===t}))}function sa(t,e,r,n){if(r<0)throw new Error("pickChannel: entchannel must be non-negative");let i=As(r),s=-1,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a+=1){let u=t[a],l=As(u.entchannel);if(i!==ot.Auto&&u.entnum===e&&l===i){s=a;break}if(u.active&&u.entnum===n.playerEntity&&e!==n.playerEntity)continue;let c=u.endTimeMs-n.nowMs;(s===-1||c<o)&&(o=c,s=a)}return s===-1?void 0:s}var oa=class{constructor(e){this.activePreset=null;this.enabled=!0;this.node=e,this.node.input.gain.value=.5,this.node.output.gain.value=1}setPreset(e){this.activePreset=e,this.node.convolver.buffer!==(e?.buffer??null)&&(this.node.convolver.buffer=e?.buffer??null),e&&e.gain!==void 0?this.node.output.gain.value=e.gain:this.node.output.gain.value=1}setEnabled(e){this.enabled=e,e?this.node.input.gain.value=.5:this.node.input.gain.value=0}getOutputNode(){return this.node.output}getInputNode(){return this.node.input}};var aa=class{constructor(e){this.activeSources=new Map;this.playbackRate=1;this.contextController=e.context,this.registry=e.registry,this.playerEntity=e.playerEntity,this.channels=ia(e.playerEntity),this.listener=e.listener??{origin:nu,right:{x:1,y:0,z:0}},this.sfxVolume=e.sfxVolume??1,this.masterVolume=e.masterVolume??1,this.resolveOcclusion=e.resolveOcclusion,this.graph=ta(this.contextController),this.graph.master.gain.value=this.masterVolume,this.graph.reverb&&(this.reverb=new oa(this.graph.reverb))}setListener(e){this.listener=e}setMasterVolume(e){this.masterVolume=e,this.graph.master.gain.value=e}setSfxVolume(e){this.sfxVolume=e}setPlaybackRate(e){this.playbackRate=e;for(let r of this.activeSources.values())r.source.playbackRate&&(r.source.playbackRate.value=e),this.updateSourceGain(r)}async ensureRunning(){await this.contextController.resume()}setReverbPreset(e){this.reverb?.setPreset(e)}play(e){let r=this.registry.get(e.soundIndex);if(!r)return;let n=this.graph.context,i=n.currentTime*1e3,s=sa(this.channels,e.entity,e.channel,{nowMs:i,playerEntity:this.playerEntity});if(s===void 0)return;let o=this.activeSources.get(s);o&&(o.source.onended=null,o.source.stop(),this.activeSources.delete(s));let a=n.createBufferSource();a.buffer=r,a.loop=e.looping??!1,a.playbackRate&&(a.playbackRate.value=this.playbackRate);let u=e.origin??this.listener.origin,l=n.createGain(),c=this.createPanner(n,e.attenuation),f=this.resolveOcclusion?.(this.listener,u,e.attenuation),d=hd(f?.gainScale??1),h=this.resolveOcclusion?this.createOcclusionFilter(n,f?.lowpassHz??2e4):void 0;this.applyOriginToPanner(c,u);let g=e.volume/255*this.sfxVolume,p=Math.abs(this.playbackRate-1)<.001?1:0;l.gain.value=g*d*p;let y=n.currentTime+(e.timeOffsetMs??0)/1e3,_=(e.looping?Number.POSITIVE_INFINITY:r.duration*1e3)+y*1e3;a.connect(c);let x=c;h?(c.connect(h),h.connect(l),x=l):(c.connect(l),x=l),l.connect(this.graph.master),this.reverb&&l.connect(this.reverb.getInputNode()),a.start(y),a.onended=()=>{this.channels[s].active=!1,this.activeSources.delete(s)};let b={channelIndex:s,entnum:e.entity,entchannel:As(e.channel),endTimeMs:_,source:a,panner:c,gain:l,baseGain:g,origin:u,attenuation:e.attenuation,occlusion:h?{scale:d,lowpassHz:f?.lowpassHz,filter:h}:f?{scale:d,lowpassHz:f.lowpassHz}:void 0};return this.channels[s]={entnum:e.entity,entchannel:As(e.channel),endTimeMs:_,isPlayer:e.entity===this.playerEntity,active:!0},this.activeSources.set(s,b),b}stop(e){let r=this.activeSources.get(e);r&&(r.source.stop(),this.channels[e].active=!1,this.activeSources.delete(e))}stopEntitySounds(e){for(let[r,n]of[...this.activeSources.entries()])n.entnum===e&&(n.source.stop(),this.channels[r].active=!1,this.activeSources.delete(r))}updateEntityPosition(e,r){for(let n of this.activeSources.values())if(n.entnum===e&&(this.applyOriginToPanner(n.panner,r),n.origin=r,this.resolveOcclusion)){let i=this.resolveOcclusion(this.listener,r,n.attenuation);this.applyOcclusion(n,i)}}positionedSound(e,r,n,i){return this.play({entity:0,channel:ot.Auto,soundIndex:r,volume:n,attenuation:i,origin:e})}ambientSound(e,r,n){return this.play({entity:0,channel:ot.Auto,soundIndex:r,volume:n,attenuation:vi,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=Sn(r);return e.refDistance=wn,e.maxDistance=Vr(r),e.rolloffFactor=n,e.distanceModel="linear",e.positionX.value=this.listener.origin.x,e.positionY.value=this.listener.origin.y,e.positionZ.value=this.listener.origin.z,e}applyOriginToPanner(e,r){e.positionX.value=r.x,e.positionY.value=r.y,e.positionZ.value=r.z}createOcclusionFilter(e,r){if(!e.createBiquadFilter)return;let n=e.createBiquadFilter();return n.type="lowpass",n.Q.value=.707,n.frequency.value=Nl(r,10,2e4),n}updateSourceGain(e){let r=e.occlusion?.scale??1,n=Math.abs(this.playbackRate-1)<.001?1:0;e.gain.gain.value=e.baseGain*r*n}applyOcclusion(e,r){let n=hd(r?.gainScale??1),i=Math.abs(this.playbackRate-1)<.001?1:0;if(e.gain.gain.value=e.baseGain*n*i,e.occlusion?.filter){let s=r?.lowpassHz??2e4;e.occlusion.filter.frequency.value=Nl(s,10,2e4)}e.occlusion?(e.occlusion.scale=n,e.occlusion.lowpassHz=r?.lowpassHz):r&&(e.occlusion={scale:n,lowpassHz:r.lowpassHz})}},Nl=(t,e,r)=>Math.min(r,Math.max(e,t)),hd=t=>Nl(t,0,1);var Ms=class{constructor(e){this.trace=e;this.resolve=(e,r,n)=>{let i=Za(iu(r,e.origin)),s=Vr(n),u=2e4*(1-Math.min(i,s)/Math.max(1,s)*.9),l=this.trace(e.origin,r,void 0,void 0),c=1,f=2e4;l.fraction<1&&(c=.3,f=400);let d=Math.min(u,f);if(c<1||d<2e4)return{gainScale:c,lowpassHz:d}}}};function md(t){return new Ms(t).resolve}var la=class{constructor(e){this.createElement=e.createElement,this.resolveSource=e.resolveSource??(async r=>r),this.volume=e.volume??1,this.crossfadeDuration=e.crossfadeDuration??1}async playTrack(e){let r=`music/track${e.toString().padStart(2,"0")}.ogg`;return this.play(r)}async play(e,{loop:r=!0,restart:n=!1}={}){if(this.track===e&&this.currentElement){this.currentElement.loop=r,this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement.volume=this.volume,n&&(this.currentElement.currentTime=0),(this.currentElement.paused||n)&&await this.currentElement.play();return}let i=await this.resolveSource(e);this.cancelFade(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.currentElement&&(this.fadingElement=this.currentElement,this.currentElement=void 0);let s=this.createElement();s.src=i,s.loop=r,s.volume=0,s.currentTime=0,s.load();try{await s.play()}catch(o){console.warn(`MusicSystem: Failed to play ${e}`,o),this.fadingElement}this.currentElement=s,this.track=e,this.startCrossfade()}pause(){this.cancelFade(),this.currentElement&&!this.currentElement.paused&&this.currentElement.pause(),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0)}async resume(){!this.currentElement||!this.currentElement.paused||(await this.currentElement.play(),this.currentElement.volume=this.volume)}stop(){this.cancelFade(),this.currentElement&&(this.currentElement.pause(),this.currentElement.currentTime=0,this.currentElement=void 0),this.fadingElement&&(this.fadingElement.pause(),this.fadingElement=void 0),this.track=void 0}setVolume(e){this.volume=e,this.currentElement&&!this.fadeInterval&&(this.currentElement.volume=e)}getState(){let e=!!(this.currentElement&&!this.currentElement.paused&&!this.currentElement.ended),r=!!this.currentElement?.paused;return{track:this.track,paused:r,playing:e,volume:this.volume}}startCrossfade(){let r=this.crossfadeDuration*1e3/50,n=this.volume/r,i=0,s=this.fadingElement?this.fadingElement.volume:0,o=()=>{let a=!1;this.currentElement&&(i=Math.min(this.volume,i+n),this.currentElement.volume=i,i<this.volume&&(a=!0)),this.fadingElement&&(s=Math.max(0,s-n),this.fadingElement.volume=s,s>0?a=!0:(this.fadingElement.pause(),this.fadingElement=void 0)),a||this.cancelFade()};o(),(this.currentElement&&this.currentElement.volume<this.volume||this.fadingElement)&&(this.fadeInterval=setInterval(o,50))}cancelFade(){this.fadeInterval&&(clearInterval(this.fadeInterval),this.fadeInterval=void 0)}};function ep(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 tp(t,e,r,n){for(let i of e){let s=t.getExtension(i);if(!s)throw new Error(`Missing required WebGL extension: ${i}`);n.set(i,s)}for(let i of r){let s=t.getExtension(i);s&&n.set(i,s)}}function pd(t,e={}){let{contextAttributes:r,requiredExtensions:n=[],optionalExtensions:i=[]}=e,s=t.getContext("webgl2",r??{antialias:!0});if(!s)throw new Error("WebGL2 not supported or failed to initialize");ep(s);let o=new Map;tp(s,n,i,o);let a=!1,u=new Set,l=new Set,c=d=>{a=!0,d.preventDefault();for(let h of u)h()},f=()=>{a=!1;for(let d of l)d()};return t.addEventListener("webglcontextlost",c),t.addEventListener("webglcontextrestored",f),{gl:s,extensions:o,isLost:()=>a,onLost(d){return u.add(d),()=>u.delete(d)},onRestored(d){return l.add(d),()=>l.delete(d)},dispose(){t.removeEventListener("webglcontextlost",c),t.removeEventListener("webglcontextrestored",f),u.clear(),l.clear(),o.clear()}}}function gd(t,e,r){let n=t.createShader(e);if(!n)throw new Error("Failed to allocate shader");if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){let s=t.getShaderInfoLog(n)??"Unknown shader compile failure";throw t.deleteShader(n),new Error(s)}return n}function rp(t,e,r,n){let i=t.createProgram();if(!i)throw new Error("Failed to allocate shader program");if(t.attachShader(i,e),t.attachShader(i,r),n)for(let[o,a]of Object.entries(n))t.bindAttribLocation(i,a,o);if(t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){let o=t.getProgramInfoLog(i)??"Unknown shader link failure";throw t.deleteProgram(i),new Error(o)}return i}var Le=class t{constructor(e,r,n){this.uniformLocations=new Map;this.attributeLocations=new Map;this.gl=e,this.program=r,this.sourceSize=n}static create(e,r,n){let i=gd(e,e.VERTEX_SHADER,r.vertex),s=gd(e,e.FRAGMENT_SHADER,r.fragment);try{let o=rp(e,i,s,n),a=r.vertex.length+r.fragment.length;return new t(e,o,a)}finally{e.deleteShader(i),e.deleteShader(s)}}use(){this.gl.useProgram(this.program)}getUniformLocation(e){if(!this.uniformLocations.has(e)){let r=this.gl.getUniformLocation(this.program,e);this.uniformLocations.set(e,r)}return this.uniformLocations.get(e)??null}getAttributeLocation(e){if(!this.attributeLocations.has(e)){let r=this.gl.getAttribLocation(this.program,e);this.attributeLocations.set(e,r)}return this.attributeLocations.get(e)??-1}dispose(){this.gl.deleteProgram(this.program),this.uniformLocations.clear(),this.attributeLocations.clear()}};function yd(t,e,r){return Le.create(t,e,r)}var Te=class{constructor(e,r=e.STATIC_DRAW,n){this.gl=e,this.target=n??e.ARRAY_BUFFER;let i=e.createBuffer();if(!i)throw new Error("Failed to allocate buffer");this.buffer=i,e.bindBuffer(this.target,this.buffer),e.bufferData(this.target,0,r)}bind(){this.gl.bindBuffer(this.target,this.buffer)}upload(e,r=this.gl.STATIC_DRAW){this.bind(),this.gl.bufferData(this.target,e,r)}update(e,r=0){this.bind(),this.gl.bufferSubData(this.target,r,e)}dispose(){this.gl.deleteBuffer(this.buffer)}},xe=class extends Te{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)}},Qn=class{constructor(e,r=e.TEXTURE_2D){this.width=0;this.height=0;this.gl=e,this.target=r;let n=e.createTexture();if(!n)throw new Error("Failed to allocate texture");this.texture=n}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}upload(e,r,n){this.width=e,this.height=r,this.uploadImage(0,this.gl.RGBA,e,r,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,n)}uploadImage(e,r,n,i,s,o,a,u){this.bind(),this.gl.texImage2D(this.target,e,r,n,i,s,o,a,u)}dispose(){this.gl.deleteTexture(this.texture)}},Jn=class{constructor(e){this.gl=e,this.target=e.TEXTURE_CUBE_MAP;let r=e.createTexture();if(!r)throw new Error("Failed to allocate cubemap texture");this.texture=r}bind(e=0){this.gl.activeTexture(this.gl.TEXTURE0+e),this.gl.bindTexture(this.target,this.texture)}setParameters(e){this.bind(),e.wrapS!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,e.wrapS),e.wrapT!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,e.wrapT),e.minFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,e.minFilter),e.magFilter!==void 0&&this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,e.magFilter)}uploadFace(e,r,n,i,s,o,a,u,l){this.bind(),this.gl.texImage2D(e,r,n,i,s,o,a,u,l)}dispose(){this.gl.deleteTexture(this.texture)}},ca=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 Hl=4,Ul=7*Hl,Vl=[{index:0,size:3,type:5126,stride:Ul,offset:0},{index:1,size:2,type:5126,stride:Ul,offset:3*Hl},{index:2,size:2,type:5126,stride:Ul,offset:5*Hl}];function np(t,e){return{width:t,height:t,padding:e,data:new Uint8Array(t*t*4),cursorX:0,cursorY:0,rowHeight:0}}function ip(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 sp(t,e,r){let n=ip(r),i=t.width*4,s=e.x+t.padding,o=e.y+t.padding,a=0;for(let u=0;u<r.height;u++){let l=(o+u)*i+s*4;for(let c=0;c<r.width;c++){let f=l+c*4;t.data[f]=r.samples[a],t.data[f+1]=r.samples[a+1],t.data[f+2]=r.samples[a+2],t.data[f+3]=n===4?r.samples[a+3]:255,a+=n}}}function op(t,e,r){let n=e.width+r.lightmapPadding*2,i=e.height+r.lightmapPadding*2;if(n>r.atlasSize||i>r.atlasSize)throw new Error("Lightmap too large for atlas");for(let a of t){if(a.cursorX+n>a.width&&(a.cursorX=0,a.cursorY+=a.rowHeight+r.lightmapPadding,a.rowHeight=0),a.cursorY+i>a.height)continue;let u={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,i),{placement:u,atlas:a}}let s=np(r.atlasSize,r.lightmapPadding);t.push(s);let o={atlasIndex:t.length-1,x:0,y:0,width:e.width,height:e.height};return s.cursorX=n+r.lightmapPadding,s.rowHeight=i,{placement:o,atlas:s}}function ua(t){return t instanceof Float32Array?t:new Float32Array(t)}function ap(t,e){if(!t){let n=new Uint16Array(e);for(let i=0;i<e;i++)n[i]=i;return n}return t instanceof Uint16Array?t:new Uint16Array(t)}function lp(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 cp(t,e){let r=ua(t.vertices),n=ua(t.textureCoords),i=e?lp(ua(t.lightmapCoords??t.textureCoords),e):ua(t.lightmapCoords??new Float32Array(n.length)),s=r.length/3;if(n.length/2!==s)throw new Error("Texture coordinates count mismatch");if(i.length/2!==s)throw new Error("Lightmap coordinates count mismatch");let o=new Float32Array(s*7);for(let a=0;a<s;a++){let u=a*3,l=a*2,c=a*7;o[c]=r[u],o[c+1]=r[u+1],o[c+2]=r[u+2],o[c+3]=n[l],o[c+4]=n[l+1],o[c+5]=i[l],o[c+6]=i[l+1]}return o}function bd(t){let e=[];for(let r=0;r<t.faces.length;r++){let n=t.faces[r];if(n.texInfo<0)continue;let i=t.texInfo[n.texInfo],s=[],o=[],a=[];for(let d=0;d<n.numEdges;d++){let h=t.surfEdges[n.firstEdge+d],m=t.edges[Math.abs(h)],g=h>=0?m.vertices[0]:m.vertices[1],p=t.vertices[g];s.push(p[0],p[1],p[2]);let y=p[0]*i.s[0]+p[1]*i.s[1]+p[2]*i.s[2]+i.sOffset,_=p[0]*i.t[0]+p[1]*i.t[1]+p[2]*i.t[2]+i.tOffset;o.push(y,_),a.push(y,_)}let u=[],l=s.length/3;for(let d=1;d<l-1;d++)u.push(0,d,d+1);let c,f=t.lightMapInfo[r];if(f){let d=1/0,h=-1/0,m=1/0,g=-1/0;for(let v=0;v<o.length;v+=2){let S=o[v],w=o[v+1];S<d&&(d=S),S>h&&(h=S),w<m&&(m=w),w>g&&(g=w)}let p=Math.floor(d/16),y=Math.floor(m/16),_=Math.ceil(h/16)-p+1,x=Math.ceil(g/16)-y+1,b=mo(n,t.lightMaps,f);if(b&&b.length===_*x*3){c={width:_,height:x,samples:b};for(let v=0;v<a.length;v+=2)a[v]=o[v]/16-p+.5,a[v+1]=o[v+1]/16-y+.5}}e.push({vertices:new Float32Array(s),textureCoords:new Float32Array(o),lightmapCoords:new Float32Array(a),indices:new Uint16Array(u),texture:i.texture,surfaceFlags:i.flags,lightmap:c,faceIndex:r})}return e}function xd(t,e,r,n={}){let i=e;if(r&&n.hiddenClassnames&&n.hiddenClassnames.size>0){let c=new Set;for(let f of r.entities.entities)if(f.classname&&n.hiddenClassnames.has(f.classname)){let d=f.properties.model;if(d&&d.startsWith("*")){let h=parseInt(d.substring(1),10);if(!isNaN(h)&&h>=0&&h<r.models.length){let m=r.models[h];for(let g=0;g<m.numFaces;g++)c.add(m.firstFace+g)}}}c.size>0&&(i=e.filter(f=>!c.has(f.faceIndex)))}let s={atlasSize:n.atlasSize??1024,lightmapPadding:n.lightmapPadding??1,hiddenClassnames:n.hiddenClassnames??new Set},o=[],a=new Map;i.forEach((c,f)=>{if(!c.lightmap)return;let{placement:d,atlas:h}=op(o,c.lightmap,s);sp(h,d,c.lightmap),a.set(f,{atlasIndex:d.atlasIndex,offset:[(d.x+s.lightmapPadding)/s.atlasSize,(d.y+s.lightmapPadding)/s.atlasSize],scale:[d.width/s.atlasSize,d.height/s.atlasSize]})});let u=o.map(c=>{let f=new Qn(t);return f.setParameters({wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,minFilter:t.LINEAR,magFilter:t.LINEAR}),f.uploadImage(0,t.RGBA,c.width,c.height,0,t.RGBA,t.UNSIGNED_BYTE,c.data),{texture:f,width:c.width,height:c.height,pixels:c.data}});return{surfaces:i.map((c,f)=>{let d=a.get(f),h=cp(c,d),m=ap(c.indices,h.length/7),g=new Te(t,t.STATIC_DRAW,t.ARRAY_BUFFER);g.upload(h);let p=new xe(t,t.STATIC_DRAW);p.upload(m);let y=new Re(t);return y.configureAttributes(Vl,g),{vao:y,vertexBuffer:g,indexBuffer:p,indexCount:m.length,vertexCount:h.length/7,texture:c.texture,surfaceFlags:c.surfaceFlags??xi,lightmap:d,vertexData:h,indexData:m}}),lightmaps:u}}function ei(t){let{normal:e,distance:r}=t,n=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(n===0)return t;let i=1/n;return{normal:{x:e.x*i,y:e.y*i,z:e.z*i},distance:r*i}}function _d(t){if(t.length!==16)throw new Error("View-projection matrix must contain 16 elements");let e=t[0],r=t[4],n=t[8],i=t[12],s=t[1],o=t[5],a=t[9],u=t[13],l=t[2],c=t[6],f=t[10],d=t[14],h=t[3],m=t[7],g=t[11],p=t[15];return[ei({normal:{x:h+e,y:m+r,z:g+n},distance:p+i}),ei({normal:{x:h-e,y:m-r,z:g-n},distance:p-i}),ei({normal:{x:h+s,y:m+o,z:g+a},distance:p+u}),ei({normal:{x:h-s,y:m-o,z:g-a},distance:p-u}),ei({normal:{x:h+l,y:m+c,z:g+f},distance:p+d}),ei({normal:{x:h-l,y:m-c,z:g-f},distance:p-d})]}function up(t,e){return t.normal.x*e.x+t.normal.y*e.y+t.normal.z*e.z+t.distance}function Es(t,e,r){for(let n of r){let i=n.normal.x>=0?e.x:t.x,s=n.normal.y>=0?e.y:t.y,o=n.normal.z>=0?e.z:t.z;if(up(n,{x:i,y:s,z:o})<0)return!1}return!0}function vd(t){return t<0}function wd(t){return-t-1}function Sd(t,e){return t.normal[0]*e.x+t.normal[1]*e.y+t.normal[2]*e.z-t.dist}function dp(t,e,r){if(!t||e<0||r<0)return!0;let n=Math.ceil(t.numClusters/8),i=t.clusters[e].pvs,s=Math.floor(r/8),o=1<<r%8;return s<0||s>=n?!1:(i[s]&o)!==0}function fp(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 Es(r,n,e)}function Wl(t,e){let r=0;for(;r>=0;){let n=t.nodes[r],i=t.planes[n.planeIndex],o=Sd(i,e)>=0?0:1,a=n.children[o];if(vd(a))return wd(a);r=a}return-1}function hp(t,e){let r=t.leafs[e],n=[];for(let i=0;i<r.numLeafFaces;i+=1)n.push(t.leafLists.leafFaces[e][i]);return n}function Gl(t,e,r,n,i,s,o){if(vd(e)){let d=wd(e),h=t.leafs[d];if(!dp(t.visibility,i,h.cluster)||!fp(h,n))return;let m={x:(h.mins[0]+h.maxs[0])*.5,y:(h.mins[1]+h.maxs[1])*.5,z:(h.mins[2]+h.maxs[2])*.5},g=m.x-r.x,p=m.y-r.y,y=m.z-r.z,_=-(g*g+p*p+y*y);for(let x of hp(t,d))o.has(x)||(o.add(x),s.push({faceIndex:x,leafIndex:d,sortKey:_}));return}let a=t.nodes[e],u=t.planes[a.planeIndex],l=Sd(u,r),c=l>=0?a.children[0]:a.children[1],f=l>=0?a.children[1]:a.children[0];Es({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)&&(Gl(t,c,r,n,i,s,o),Gl(t,f,r,n,i,s,o))}function Ad(t,e,r){let n=Wl(t,e),i=n>=0?t.leafs[n].cluster:-1,s=[];return Gl(t,0,e,r,i,s,new Set),s}var ur=32,da=class{constructor(){this.lights=[]}addLight(e,r){if(e.key!==void 0){let n=this.lights.findIndex(i=>i.key===e.key);if(n!==-1){this.lights[n]=e;return}}this.lights.push(e)}clear(){this.lights=[]}update(e,r=0){if(this.lights=this.lights.filter(n=>n.die>e),r>0)for(let n of this.lights)n.radiusSpeed!==void 0&&n.radiusSpeed!==0&&(n.intensity+=n.radiusSpeed*r,n.intensity<0&&(n.intensity=0))}getActiveLights(){return this.lights}};function ti(t){let e=[];for(let r=0;r<t.length;r+=3){let n=t[r],i=t[r+1],s=t[r+2];e.push(n,i,i,s,s,n)}return t instanceof Uint32Array||Math.max(...e)>65535?new Uint32Array(e):new Uint16Array(e)}var Xl=`#version 300 es
142
142
  precision highp float;
143
143
 
144
144
  layout(location = 0) in vec3 a_position;
@@ -339,7 +339,7 @@ void main() {
339
339
  }
340
340
 
341
341
  o_color = finalColor;
342
- }`,Md=[0,255,255,255],mp=[0,-1,-1,-1];function $l(t=Md,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let s=e[i];r[n]=s!==void 0?s:1}return r}function pp(t){return[-(t*.25%1),0]}function Zl(t=xi,e=0){let r=(t&fu)!==0,n=(t&cu)!==0,i=(t&lu)!==0,s=(t&uu)!==0,o=(t&du)!==0,a=s?.33:o?.66:1,u=s||o||n,l=!u&&!i,c=r?pp(e):[0,0];return{alpha:a,blend:u,depthWrite:l,warp:n,flowOffset:c,sky:i}}var fa=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=Le.create(e,{vertex:Xl,fragment:Kl},{a_position:0,a_texCoord:1,a_lightmapCoord:2,a_lightmapStep:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTexScroll=this.program.getUniformLocation("u_texScroll"),this.uniformLmScroll=this.program.getUniformLocation("u_lightmapScroll"),this.uniformLightStyles=this.program.getUniformLocation("u_lightStyleFactors"),this.uniformStyleLayerMapping=this.program.getUniformLocation("u_styleLayerMapping"),this.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformLightmapOnly=this.program.getUniformLocation("u_lightmapOnly"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformRefraction=this.program.getUniformLocation("u_refractionMap"),this.uniformHasRefraction=this.program.getUniformLocation("u_hasRefraction"),this.uniformTime=this.program.getUniformLocation("u_time"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<ur;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformAmbient=this.program.getUniformLocation("u_ambient")}bind(e){let{modelViewProjection:r,styleIndices:n=Md,styleLayers:i=mp,styleValues:s=[],diffuseSampler:o=0,lightmapSampler:a,refractionSampler:u,surfaceFlags:l=xi,timeSeconds:c=0,texScroll:f,alpha:d,warp:h,dlights:m=[],renderMode:g,lightmapOnly:p,brightness:y=1,gamma:_=1,fullbright:x=!1,ambient:b=0}=e,v=Zl(l,c),S=$l(n,s),w=f?f[0]:v.flowOffset[0],M=f?f[1]:v.flowOffset[1],L=d!==void 0?d:v.alpha,A=h!==void 0?h:v.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,w,M),this.gl.uniform2f(this.uniformLmScroll,v.flowOffset[0],v.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,S),this.gl.uniform4fv(this.uniformStyleLayerMapping,i),this.gl.uniform1f(this.uniformAlpha,L);let T=!v.sky&&a!==void 0&&!A;this.gl.uniform1i(this.uniformApplyLightmap,T?1:0),this.gl.uniform1i(this.uniformWarp,A?1:0),this.gl.uniform1i(this.uniformLightmapOnly,p?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,a??0),u!==void 0&&A?(this.gl.uniform1i(this.uniformRefraction,u),this.gl.uniform1i(this.uniformHasRefraction,1)):this.gl.uniform1i(this.uniformHasRefraction,0);let I=0,z=[1,1,1,1];g&&(g.mode==="solid"||g.mode==="wireframe"?I=1:g.mode==="solid-faceted"&&(I=2),g.color?z=[...g.color]:g.generateRandomColor&&(z=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,I),this.gl.uniform4f(this.uniformSolidColor,z[0],z[1],z[2],z[3]);let C=Math.min(m.length,ur);this.gl.uniform1i(this.uniformNumDlights,C);for(let V=0;V<C;V++){let se=m[V];this.gl.uniform3f(this.uniformDlights[V].pos,se.origin.x,se.origin.y,se.origin.z),this.gl.uniform3f(this.uniformDlights[V].color,se.color.x,se.color.y,se.color.z),this.gl.uniform1f(this.uniformDlights[V].intensity,se.intensity)}return this.gl.uniform1f(this.uniformBrightness,y),this.gl.uniform1f(this.uniformGamma,_),this.gl.uniform1i(this.uniformFullbright,x?1:0),this.gl.uniform1f(this.uniformAmbient,b),v}draw(e,r){if(e.vao.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){let n=e;n.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let i=ti(e.indexData);n.wireframeIndexBuffer.upload(i),n.wireframeIndexCount=i.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};function Ed(t,e){t.depthMask(e.depthWrite),e.blend?(t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)):t.disable(t.BLEND)}var Ld=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]),Yl=`#version 300 es
342
+ }`,Md=[0,255,255,255],mp=[0,-1,-1,-1];function $l(t=Md,e=[]){let r=new Float32Array(4);for(let n=0;n<4;n+=1){let i=t[n]??255;if(i===255){r[n]=0;continue}let s=e[i];r[n]=s!==void 0?s:1}return r}function pp(t){return[-(t*.25%1),0]}function Zl(t=xi,e=0){let r=(t&fu)!==0,n=(t&cu)!==0,i=(t&lu)!==0,s=(t&uu)!==0,o=(t&du)!==0,a=s?.33:o?.66:1,u=s||o||n,l=!u&&!i,c=r?pp(e):[0,0];return{alpha:a,blend:u,depthWrite:l,warp:n,flowOffset:c,sky:i}}var fa=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=Le.create(e,{vertex:Xl,fragment:Kl},{a_position:0,a_texCoord:1,a_lightmapCoord:2,a_lightmapStep:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTexScroll=this.program.getUniformLocation("u_texScroll"),this.uniformLmScroll=this.program.getUniformLocation("u_lightmapScroll"),this.uniformLightStyles=this.program.getUniformLocation("u_lightStyleFactors"),this.uniformStyleLayerMapping=this.program.getUniformLocation("u_styleLayerMapping"),this.uniformAlpha=this.program.getUniformLocation("u_alpha"),this.uniformApplyLightmap=this.program.getUniformLocation("u_applyLightmap"),this.uniformWarp=this.program.getUniformLocation("u_warp"),this.uniformLightmapOnly=this.program.getUniformLocation("u_lightmapOnly"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformLightmap=this.program.getUniformLocation("u_lightmapAtlas"),this.uniformRefraction=this.program.getUniformLocation("u_refractionMap"),this.uniformHasRefraction=this.program.getUniformLocation("u_hasRefraction"),this.uniformTime=this.program.getUniformLocation("u_time"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<ur;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformAmbient=this.program.getUniformLocation("u_ambient")}get shaderSize(){return this.program.sourceSize}bind(e){let{modelViewProjection:r,styleIndices:n=Md,styleLayers:i=mp,styleValues:s=[],diffuseSampler:o=0,lightmapSampler:a,refractionSampler:u,surfaceFlags:l=xi,timeSeconds:c=0,texScroll:f,alpha:d,warp:h,dlights:m=[],renderMode:g,lightmapOnly:p,brightness:y=1,gamma:_=1,fullbright:x=!1,ambient:b=0}=e,v=Zl(l,c),S=$l(n,s),w=f?f[0]:v.flowOffset[0],M=f?f[1]:v.flowOffset[1],L=d!==void 0?d:v.alpha,A=h!==void 0?h:v.warp;this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),this.gl.uniform2f(this.uniformTexScroll,w,M),this.gl.uniform2f(this.uniformLmScroll,v.flowOffset[0],v.flowOffset[1]),this.gl.uniform4fv(this.uniformLightStyles,S),this.gl.uniform4fv(this.uniformStyleLayerMapping,i),this.gl.uniform1f(this.uniformAlpha,L);let T=!v.sky&&a!==void 0&&!A;this.gl.uniform1i(this.uniformApplyLightmap,T?1:0),this.gl.uniform1i(this.uniformWarp,A?1:0),this.gl.uniform1i(this.uniformLightmapOnly,p?1:0),this.gl.uniform1f(this.uniformTime,c),this.gl.uniform1i(this.uniformDiffuse,o),this.gl.uniform1i(this.uniformLightmap,a??0),u!==void 0&&A?(this.gl.uniform1i(this.uniformRefraction,u),this.gl.uniform1i(this.uniformHasRefraction,1)):this.gl.uniform1i(this.uniformHasRefraction,0);let I=0,z=[1,1,1,1];g&&(g.mode==="solid"||g.mode==="wireframe"?I=1:g.mode==="solid-faceted"&&(I=2),g.color?z=[...g.color]:g.generateRandomColor&&(z=[1,1,1,1])),this.gl.uniform1i(this.uniformRenderMode,I),this.gl.uniform4f(this.uniformSolidColor,z[0],z[1],z[2],z[3]);let C=Math.min(m.length,ur);this.gl.uniform1i(this.uniformNumDlights,C);for(let V=0;V<C;V++){let se=m[V];this.gl.uniform3f(this.uniformDlights[V].pos,se.origin.x,se.origin.y,se.origin.z),this.gl.uniform3f(this.uniformDlights[V].color,se.color.x,se.color.y,se.color.z),this.gl.uniform1f(this.uniformDlights[V].intensity,se.intensity)}return this.gl.uniform1f(this.uniformBrightness,y),this.gl.uniform1f(this.uniformGamma,_),this.gl.uniform1i(this.uniformFullbright,x?1:0),this.gl.uniform1f(this.uniformAmbient,b),v}draw(e,r){if(e.vao.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){let n=e;n.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let i=ti(e.indexData);n.wireframeIndexBuffer.upload(i),n.wireframeIndexCount=i.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};function Ed(t,e){t.depthMask(e.depthWrite),e.blend?(t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)):t.disable(t.BLEND)}var Ld=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]),Yl=`#version 300 es
343
343
  precision highp float;
344
344
 
345
345
  layout(location = 0) in vec3 a_position;
@@ -364,7 +364,7 @@ out vec4 o_color;
364
364
 
365
365
  void main() {
366
366
  o_color = texture(u_skybox, v_direction);
367
- }`,ha=class{constructor(e){this.gl=e,this.program=Le.create(e,{vertex:Yl,fragment:ql},{a_position:0}),this.vao=new Re(e),this.vbo=new Te(e,e.STATIC_DRAW),this.vbo.upload(Ld,e.STATIC_DRAW);let r=[{index:0,size:3,type:e.FLOAT,stride:12,offset:0}];this.vao.configureAttributes(r,this.vbo),this.uniformViewProj=this.program.getUniformLocation("u_viewProjectionNoTranslation"),this.uniformScroll=this.program.getUniformLocation("u_scroll"),this.uniformSampler=this.program.getUniformLocation("u_skybox"),this.cubemap=new Jn(e),this.cubemap.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE})}bind(e){let{viewProjection:r,scroll:n,textureUnit:i=0}=e;this.program.use(),this.gl.depthMask(!1),this.gl.uniformMatrix4fv(this.uniformViewProj,!1,r),this.gl.uniform2f(this.uniformScroll,n[0],n[1]),this.gl.uniform1i(this.uniformSampler,i),this.cubemap.bind(i),this.vao.bind()}draw(){this.gl.drawArrays(this.gl.TRIANGLES,0,Ld.length/3)}dispose(){this.vbo.dispose(),this.vao.dispose(),this.cubemap.dispose(),this.program.dispose()}};function Td(t){let e=new Float32Array(t);return e[12]=0,e[13]=0,e[14]=0,e}function kd(t,e=[.01,.02]){let[r,n]=e;return[r*t,n*t]}var Ql=`#version 300 es
367
+ }`,ha=class{constructor(e){this.gl=e,this.program=Le.create(e,{vertex:Yl,fragment:ql},{a_position:0}),this.vao=new Re(e),this.vbo=new Te(e,e.STATIC_DRAW),this.vbo.upload(Ld,e.STATIC_DRAW);let r=[{index:0,size:3,type:e.FLOAT,stride:12,offset:0}];this.vao.configureAttributes(r,this.vbo),this.uniformViewProj=this.program.getUniformLocation("u_viewProjectionNoTranslation"),this.uniformScroll=this.program.getUniformLocation("u_scroll"),this.uniformSampler=this.program.getUniformLocation("u_skybox"),this.cubemap=new Jn(e),this.cubemap.setParameters({minFilter:e.LINEAR,magFilter:e.LINEAR,wrapS:e.CLAMP_TO_EDGE,wrapT:e.CLAMP_TO_EDGE})}get shaderSize(){return this.program.sourceSize}bind(e){let{viewProjection:r,scroll:n,textureUnit:i=0}=e;this.program.use(),this.gl.depthMask(!1),this.gl.uniformMatrix4fv(this.uniformViewProj,!1,r),this.gl.uniform2f(this.uniformScroll,n[0],n[1]),this.gl.uniform1i(this.uniformSampler,i),this.cubemap.bind(i),this.vao.bind()}draw(){this.gl.drawArrays(this.gl.TRIANGLES,0,Ld.length/3)}dispose(){this.vbo.dispose(),this.vao.dispose(),this.cubemap.dispose(),this.program.dispose()}};function Td(t){let e=new Float32Array(t);return e[12]=0,e[13]=0,e[14]=0,e}function kd(t,e=[.01,.02]){let[r,n]=e;return[r*t,n*t]}var Ql=`#version 300 es
368
368
  precision highp float;
369
369
 
370
370
  layout(location = 0) in vec3 a_position;
@@ -476,7 +476,7 @@ void main() {
476
476
  }
477
477
 
478
478
  o_color = finalColor;
479
- }`;function gp(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function jl(t,e,r){return t+(e-t)*r}function Cd(t,e,r){return{x:jl(t.x,e.x,r),y:jl(t.y,e.y,r),z:jl(t.z,e.z,r)}}function yp(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function ec(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(s=>{let o=n.length;for(let a=0;a<3;a+=1){let u=s.vertexIndices[a],l=s.texCoordIndices[a],c=t.texCoords[l];n.push({vertexIndex:u,texCoord:yp(c.s,c.t,t.header)})}i.push(o,o+1,o+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(s=>({vertexIndex:s.vertexIndex,texCoord:[s.s,1-s.t]}))),n.mode==="strip")for(let s=0;s<n.vertices.length-2;s+=1){let o=s%2===0,a=i+s+(o?0:1),u=i+s+(o?1:0),l=i+s+2;r.push(a,u,l)}else for(let s=1;s<n.vertices.length-1;s+=1)r.push(i,i+s,i+s+1)}return{vertices:e,indices:new Uint16Array(r)}}function tc(t,e,r){let{frame0:n,frame1:i,lerp:s}=r,o=t.frames[n],a=t.frames[i];if(!o||!a)throw new Error("Requested MD2 frames are out of range");let u=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,c)=>{let f=o.vertices[l.vertexIndex],d=a.vertices[l.vertexIndex];if(!f||!d)throw new Error("MD2 vertex index out of range for frame");let h=Cd(f.position,d.position,s),m=gp(Cd(f.normal,d.normal,s)),g=c*8;u[g]=h.x,u[g+1]=h.y,u[g+2]=h.z,u[g+3]=m.x,u[g+4]=m.y,u[g+5]=m.z,u[g+6]=l.texCoord[0],u[g+7]=l.texCoord[1]}),u}var ma=class{constructor(e,r,n){this.gl=e,this.geometry=ec(r),this.vertexBuffer=new Te(e,e.STATIC_DRAW),this.indexBuffer=new xe(e,e.STATIC_DRAW),this.vertexArray=new Re(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=tc(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},pa=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=Le.create(e,{vertex:Ql,fragment:Jl},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<ur;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:s=.2,tint:o=[1,1,1,1],diffuseSampler:a=0,dlights:u=[],renderMode:l,brightness:c=1,gamma:f=1,fullbright:d=!1,ambient:h=0}=e,m=new Float32Array(i),g=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,m),this.gl.uniform1f(this.uniformAmbient,s),this.gl.uniform4fv(this.uniformTint,g),this.gl.uniform1i(this.uniformDiffuse,a);let p=0,y=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?p=1:l.mode==="solid-faceted"&&(p=2),l.color?y=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,p),this.gl.uniform4f(this.uniformSolidColor,y[0],y[1],y[2],y[3]);let _=Math.min(u.length,ur);this.gl.uniform1i(this.uniformNumDlights,_);for(let x=0;x<_;x++){let b=u[x];this.gl.uniform3f(this.uniformDlights[x].pos,b.origin.x,b.origin.y,b.origin.z),this.gl.uniform3f(this.uniformDlights[x].color,b.color.x,b.color.y,b.color.z),this.gl.uniform1f(this.uniformDlights[x].intensity,b.intensity)}this.gl.uniform1f(this.uniformBrightness,c),this.gl.uniform1f(this.uniformGamma,f),this.gl.uniform1i(this.uniformFullbright,d?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,h)}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let n=ti(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var ee=1e-6,qe=typeof Float32Array<"u"?Float32Array:Array,rc=Math.random;function ga(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var zS=Math.PI/180,PS=180/Math.PI;var ue={};Ka(ue,{add:()=>r1,adjoint:()=>Mp,clone:()=>xp,copy:()=>_p,create:()=>bp,decompose:()=>Vp,determinant:()=>Ep,equals:()=>o1,exactEquals:()=>s1,frob:()=>t1,fromQuat:()=>Xp,fromQuat2:()=>Np,fromRotation:()=>Pp,fromRotationTranslation:()=>zd,fromRotationTranslationScale:()=>Gp,fromRotationTranslationScaleOrigin:()=>Wp,fromScaling:()=>zp,fromTranslation:()=>Fp,fromValues:()=>vp,fromXRotation:()=>Dp,fromYRotation:()=>Bp,fromZRotation:()=>Op,frustum:()=>Kp,getRotation:()=>Hp,getScaling:()=>Pd,getTranslation:()=>Up,identity:()=>Rd,invert:()=>Ap,lookAt:()=>Qp,mul:()=>a1,multiply:()=>Fd,multiplyScalar:()=>n1,multiplyScalarAndAdd:()=>i1,ortho:()=>qp,orthoNO:()=>Bd,orthoZO:()=>jp,perspective:()=>$p,perspectiveFromFieldOfView:()=>Yp,perspectiveNO:()=>Dd,perspectiveZO:()=>Zp,rotate:()=>kp,rotateX:()=>Cp,rotateY:()=>Ip,rotateZ:()=>Rp,scale:()=>Tp,set:()=>wp,str:()=>e1,sub:()=>l1,subtract:()=>Od,targetTo:()=>Jp,translate:()=>Lp,transpose:()=>Sp});function bp(){var t=new qe(16);return qe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function xp(t){var e=new qe(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function _p(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function vp(t,e,r,n,i,s,o,a,u,l,c,f,d,h,m,g){var p=new qe(16);return p[0]=t,p[1]=e,p[2]=r,p[3]=n,p[4]=i,p[5]=s,p[6]=o,p[7]=a,p[8]=u,p[9]=l,p[10]=c,p[11]=f,p[12]=d,p[13]=h,p[14]=m,p[15]=g,p}function wp(t,e,r,n,i,s,o,a,u,l,c,f,d,h,m,g,p){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=s,t[5]=o,t[6]=a,t[7]=u,t[8]=l,t[9]=c,t[10]=f,t[11]=d,t[12]=h,t[13]=m,t[14]=g,t[15]=p,t}function Rd(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Sp(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],s=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=s,t[11]=e[14],t[12]=i,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Ap(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],l=e[7],c=e[8],f=e[9],d=e[10],h=e[11],m=e[12],g=e[13],p=e[14],y=e[15],_=r*a-n*o,x=r*u-i*o,b=r*l-s*o,v=n*u-i*a,S=n*l-s*a,w=i*l-s*u,M=c*g-f*m,L=c*p-d*m,A=c*y-h*m,T=f*p-d*g,I=f*y-h*g,z=d*y-h*p,C=_*z-x*I+b*T+v*A-S*L+w*M;return C?(C=1/C,t[0]=(a*z-u*I+l*T)*C,t[1]=(i*I-n*z-s*T)*C,t[2]=(g*w-p*S+y*v)*C,t[3]=(d*S-f*w-h*v)*C,t[4]=(u*A-o*z-l*L)*C,t[5]=(r*z-i*A+s*L)*C,t[6]=(p*b-m*w-y*x)*C,t[7]=(c*w-d*b+h*x)*C,t[8]=(o*I-a*A+l*M)*C,t[9]=(n*A-r*I-s*M)*C,t[10]=(m*S-g*b+y*_)*C,t[11]=(f*b-c*S-h*_)*C,t[12]=(a*L-o*T-u*M)*C,t[13]=(r*T-n*L+i*M)*C,t[14]=(g*x-m*v-p*_)*C,t[15]=(c*v-f*x+d*_)*C,t):null}function Mp(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],l=e[7],c=e[8],f=e[9],d=e[10],h=e[11],m=e[12],g=e[13],p=e[14],y=e[15],_=r*a-n*o,x=r*u-i*o,b=r*l-s*o,v=n*u-i*a,S=n*l-s*a,w=i*l-s*u,M=c*g-f*m,L=c*p-d*m,A=c*y-h*m,T=f*p-d*g,I=f*y-h*g,z=d*y-h*p;return t[0]=a*z-u*I+l*T,t[1]=i*I-n*z-s*T,t[2]=g*w-p*S+y*v,t[3]=d*S-f*w-h*v,t[4]=u*A-o*z-l*L,t[5]=r*z-i*A+s*L,t[6]=p*b-m*w-y*x,t[7]=c*w-d*b+h*x,t[8]=o*I-a*A+l*M,t[9]=n*A-r*I-s*M,t[10]=m*S-g*b+y*_,t[11]=f*b-c*S-h*_,t[12]=a*L-o*T-u*M,t[13]=r*T-n*L+i*M,t[14]=g*x-m*v-p*_,t[15]=c*v-f*x+d*_,t}function Ep(t){var e=t[0],r=t[1],n=t[2],i=t[3],s=t[4],o=t[5],a=t[6],u=t[7],l=t[8],c=t[9],f=t[10],d=t[11],h=t[12],m=t[13],g=t[14],p=t[15],y=e*o-r*s,_=e*a-n*s,x=r*a-n*o,b=l*m-c*h,v=l*g-f*h,S=c*g-f*m,w=e*S-r*v+n*b,M=s*S-o*v+a*b,L=l*x-c*_+f*y,A=h*x-m*_+g*y;return u*w-i*M+p*L-d*A}function Fd(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=e[4],u=e[5],l=e[6],c=e[7],f=e[8],d=e[9],h=e[10],m=e[11],g=e[12],p=e[13],y=e[14],_=e[15],x=r[0],b=r[1],v=r[2],S=r[3];return t[0]=x*n+b*a+v*f+S*g,t[1]=x*i+b*u+v*d+S*p,t[2]=x*s+b*l+v*h+S*y,t[3]=x*o+b*c+v*m+S*_,x=r[4],b=r[5],v=r[6],S=r[7],t[4]=x*n+b*a+v*f+S*g,t[5]=x*i+b*u+v*d+S*p,t[6]=x*s+b*l+v*h+S*y,t[7]=x*o+b*c+v*m+S*_,x=r[8],b=r[9],v=r[10],S=r[11],t[8]=x*n+b*a+v*f+S*g,t[9]=x*i+b*u+v*d+S*p,t[10]=x*s+b*l+v*h+S*y,t[11]=x*o+b*c+v*m+S*_,x=r[12],b=r[13],v=r[14],S=r[15],t[12]=x*n+b*a+v*f+S*g,t[13]=x*i+b*u+v*d+S*p,t[14]=x*s+b*l+v*h+S*y,t[15]=x*o+b*c+v*m+S*_,t}function Lp(t,e,r){var n=r[0],i=r[1],s=r[2],o,a,u,l,c,f,d,h,m,g,p,y;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*s+e[12],t[13]=e[1]*n+e[5]*i+e[9]*s+e[13],t[14]=e[2]*n+e[6]*i+e[10]*s+e[14],t[15]=e[3]*n+e[7]*i+e[11]*s+e[15]):(o=e[0],a=e[1],u=e[2],l=e[3],c=e[4],f=e[5],d=e[6],h=e[7],m=e[8],g=e[9],p=e[10],y=e[11],t[0]=o,t[1]=a,t[2]=u,t[3]=l,t[4]=c,t[5]=f,t[6]=d,t[7]=h,t[8]=m,t[9]=g,t[10]=p,t[11]=y,t[12]=o*n+c*i+m*s+e[12],t[13]=a*n+f*i+g*s+e[13],t[14]=u*n+d*i+p*s+e[14],t[15]=l*n+h*i+y*s+e[15]),t}function Tp(t,e,r){var n=r[0],i=r[1],s=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function kp(t,e,r,n){var i=n[0],s=n[1],o=n[2],a=Math.sqrt(i*i+s*s+o*o),u,l,c,f,d,h,m,g,p,y,_,x,b,v,S,w,M,L,A,T,I,z,C,V;return a<ee?null:(a=1/a,i*=a,s*=a,o*=a,u=Math.sin(r),l=Math.cos(r),c=1-l,f=e[0],d=e[1],h=e[2],m=e[3],g=e[4],p=e[5],y=e[6],_=e[7],x=e[8],b=e[9],v=e[10],S=e[11],w=i*i*c+l,M=s*i*c+o*u,L=o*i*c-s*u,A=i*s*c-o*u,T=s*s*c+l,I=o*s*c+i*u,z=i*o*c+s*u,C=s*o*c-i*u,V=o*o*c+l,t[0]=f*w+g*M+x*L,t[1]=d*w+p*M+b*L,t[2]=h*w+y*M+v*L,t[3]=m*w+_*M+S*L,t[4]=f*A+g*T+x*I,t[5]=d*A+p*T+b*I,t[6]=h*A+y*T+v*I,t[7]=m*A+_*T+S*I,t[8]=f*z+g*C+x*V,t[9]=d*z+p*C+b*V,t[10]=h*z+y*C+v*V,t[11]=m*z+_*C+S*V,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Cp(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[4],o=e[5],a=e[6],u=e[7],l=e[8],c=e[9],f=e[10],d=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=s*i+l*n,t[5]=o*i+c*n,t[6]=a*i+f*n,t[7]=u*i+d*n,t[8]=l*i-s*n,t[9]=c*i-o*n,t[10]=f*i-a*n,t[11]=d*i-u*n,t}function Ip(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],l=e[8],c=e[9],f=e[10],d=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i-l*n,t[1]=o*i-c*n,t[2]=a*i-f*n,t[3]=u*i-d*n,t[8]=s*n+l*i,t[9]=o*n+c*i,t[10]=a*n+f*i,t[11]=u*n+d*i,t}function Rp(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],l=e[4],c=e[5],f=e[6],d=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i+l*n,t[1]=o*i+c*n,t[2]=a*i+f*n,t[3]=u*i+d*n,t[4]=l*i-s*n,t[5]=c*i-o*n,t[6]=f*i-a*n,t[7]=d*i-u*n,t}function Fp(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function zp(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Pp(t,e,r){var n=r[0],i=r[1],s=r[2],o=Math.sqrt(n*n+i*i+s*s),a,u,l;return o<ee?null:(o=1/o,n*=o,i*=o,s*=o,a=Math.sin(e),u=Math.cos(e),l=1-u,t[0]=n*n*l+u,t[1]=i*n*l+s*a,t[2]=s*n*l-i*a,t[3]=0,t[4]=n*i*l-s*a,t[5]=i*i*l+u,t[6]=s*i*l+n*a,t[7]=0,t[8]=n*s*l+i*a,t[9]=i*s*l-n*a,t[10]=s*s*l+u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Dp(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Bp(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Op(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function zd(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=n+n,u=i+i,l=s+s,c=n*a,f=n*u,d=n*l,h=i*u,m=i*l,g=s*l,p=o*a,y=o*u,_=o*l;return t[0]=1-(h+g),t[1]=f+_,t[2]=d-y,t[3]=0,t[4]=f-_,t[5]=1-(c+g),t[6]=m+p,t[7]=0,t[8]=d+y,t[9]=m-p,t[10]=1-(c+h),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Np(t,e){var r=new qe(3),n=-e[0],i=-e[1],s=-e[2],o=e[3],a=e[4],u=e[5],l=e[6],c=e[7],f=n*n+i*i+s*s+o*o;return f>0?(r[0]=(a*o+c*n+u*s-l*i)*2/f,r[1]=(u*o+c*i+l*n-a*s)*2/f,r[2]=(l*o+c*s+a*i-u*n)*2/f):(r[0]=(a*o+c*n+u*s-l*i)*2,r[1]=(u*o+c*i+l*n-a*s)*2,r[2]=(l*o+c*s+a*i-u*n)*2),zd(t,e,r),t}function Up(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Pd(t,e){var r=e[0],n=e[1],i=e[2],s=e[4],o=e[5],a=e[6],u=e[8],l=e[9],c=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(s*s+o*o+a*a),t[2]=Math.sqrt(u*u+l*l+c*c),t}function Hp(t,e){var r=new qe(3);Pd(r,e);var n=1/r[0],i=1/r[1],s=1/r[2],o=e[0]*n,a=e[1]*i,u=e[2]*s,l=e[4]*n,c=e[5]*i,f=e[6]*s,d=e[8]*n,h=e[9]*i,m=e[10]*s,g=o+c+m,p=0;return g>0?(p=Math.sqrt(g+1)*2,t[3]=.25*p,t[0]=(f-h)/p,t[1]=(d-u)/p,t[2]=(a-l)/p):o>c&&o>m?(p=Math.sqrt(1+o-c-m)*2,t[3]=(f-h)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(d+u)/p):c>m?(p=Math.sqrt(1+c-o-m)*2,t[3]=(d-u)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(f+h)/p):(p=Math.sqrt(1+m-o-c)*2,t[3]=(a-l)/p,t[0]=(d+u)/p,t[1]=(f+h)/p,t[2]=.25*p),t}function Vp(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],s=n[1],o=n[2],a=n[4],u=n[5],l=n[6],c=n[8],f=n[9],d=n[10];r[0]=Math.sqrt(i*i+s*s+o*o),r[1]=Math.sqrt(a*a+u*u+l*l),r[2]=Math.sqrt(c*c+f*f+d*d);var h=1/r[0],m=1/r[1],g=1/r[2],p=i*h,y=s*m,_=o*g,x=a*h,b=u*m,v=l*g,S=c*h,w=f*m,M=d*g,L=p+b+M,A=0;return L>0?(A=Math.sqrt(L+1)*2,t[3]=.25*A,t[0]=(v-w)/A,t[1]=(S-_)/A,t[2]=(y-x)/A):p>b&&p>M?(A=Math.sqrt(1+p-b-M)*2,t[3]=(v-w)/A,t[0]=.25*A,t[1]=(y+x)/A,t[2]=(S+_)/A):b>M?(A=Math.sqrt(1+b-p-M)*2,t[3]=(S-_)/A,t[0]=(y+x)/A,t[1]=.25*A,t[2]=(v+w)/A):(A=Math.sqrt(1+M-p-b)*2,t[3]=(y-x)/A,t[0]=(S+_)/A,t[1]=(v+w)/A,t[2]=.25*A),t}function Gp(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=e[3],u=i+i,l=s+s,c=o+o,f=i*u,d=i*l,h=i*c,m=s*l,g=s*c,p=o*c,y=a*u,_=a*l,x=a*c,b=n[0],v=n[1],S=n[2];return t[0]=(1-(m+p))*b,t[1]=(d+x)*b,t[2]=(h-_)*b,t[3]=0,t[4]=(d-x)*v,t[5]=(1-(f+p))*v,t[6]=(g+y)*v,t[7]=0,t[8]=(h+_)*S,t[9]=(g-y)*S,t[10]=(1-(f+m))*S,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Wp(t,e,r,n,i){var s=e[0],o=e[1],a=e[2],u=e[3],l=s+s,c=o+o,f=a+a,d=s*l,h=s*c,m=s*f,g=o*c,p=o*f,y=a*f,_=u*l,x=u*c,b=u*f,v=n[0],S=n[1],w=n[2],M=i[0],L=i[1],A=i[2],T=(1-(g+y))*v,I=(h+b)*v,z=(m-x)*v,C=(h-b)*S,V=(1-(d+y))*S,se=(p+_)*S,Nr=(m+x)*w,js=(p-_)*w,pi=(1-(d+g))*w;return t[0]=T,t[1]=I,t[2]=z,t[3]=0,t[4]=C,t[5]=V,t[6]=se,t[7]=0,t[8]=Nr,t[9]=js,t[10]=pi,t[11]=0,t[12]=r[0]+M-(T*M+C*L+Nr*A),t[13]=r[1]+L-(I*M+V*L+js*A),t[14]=r[2]+A-(z*M+se*L+pi*A),t[15]=1,t}function Xp(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,u=i+i,l=r*o,c=n*o,f=n*a,d=i*o,h=i*a,m=i*u,g=s*o,p=s*a,y=s*u;return t[0]=1-f-m,t[1]=c+y,t[2]=d-p,t[3]=0,t[4]=c-y,t[5]=1-l-m,t[6]=h+g,t[7]=0,t[8]=d+p,t[9]=h-g,t[10]=1-l-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Kp(t,e,r,n,i,s,o){var a=1/(r-e),u=1/(i-n),l=1/(s-o);return t[0]=s*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s*2*u,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(i+n)*u,t[10]=(o+s)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*s*2*l,t[15]=0,t}function Dd(t,e,r,n,i){var s=1/Math.tan(e/2);if(t[0]=s/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=(i+n)*o,t[14]=2*i*n*o}else t[10]=-1,t[14]=-2*n;return t}var $p=Dd;function Zp(t,e,r,n,i){var s=1/Math.tan(e/2);if(t[0]=s/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=i*o,t[14]=i*n*o}else t[10]=-1,t[14]=-n;return t}function Yp(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),s=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),u=2/(o+a),l=2/(i+s);return t[0]=u,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((o-a)*u*.5),t[9]=(i-s)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Bd(t,e,r,n,i,s,o){var a=1/(e-r),u=1/(n-i),l=1/(s-o);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*u,t[14]=(o+s)*l,t[15]=1,t}var qp=Bd;function jp(t,e,r,n,i,s,o){var a=1/(e-r),u=1/(n-i),l=1/(s-o);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*u,t[14]=s*l,t[15]=1,t}function Qp(t,e,r,n){var i,s,o,a,u,l,c,f,d,h,m=e[0],g=e[1],p=e[2],y=n[0],_=n[1],x=n[2],b=r[0],v=r[1],S=r[2];return Math.abs(m-b)<ee&&Math.abs(g-v)<ee&&Math.abs(p-S)<ee?Rd(t):(c=m-b,f=g-v,d=p-S,h=1/Math.sqrt(c*c+f*f+d*d),c*=h,f*=h,d*=h,i=_*d-x*f,s=x*c-y*d,o=y*f-_*c,h=Math.sqrt(i*i+s*s+o*o),h?(h=1/h,i*=h,s*=h,o*=h):(i=0,s=0,o=0),a=f*o-d*s,u=d*i-c*o,l=c*s-f*i,h=Math.sqrt(a*a+u*u+l*l),h?(h=1/h,a*=h,u*=h,l*=h):(a=0,u=0,l=0),t[0]=i,t[1]=a,t[2]=c,t[3]=0,t[4]=s,t[5]=u,t[6]=f,t[7]=0,t[8]=o,t[9]=l,t[10]=d,t[11]=0,t[12]=-(i*m+s*g+o*p),t[13]=-(a*m+u*g+l*p),t[14]=-(c*m+f*g+d*p),t[15]=1,t)}function Jp(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=n[0],u=n[1],l=n[2],c=i-r[0],f=s-r[1],d=o-r[2],h=c*c+f*f+d*d;h>0&&(h=1/Math.sqrt(h),c*=h,f*=h,d*=h);var m=u*d-l*f,g=l*c-a*d,p=a*f-u*c;return h=m*m+g*g+p*p,h>0&&(h=1/Math.sqrt(h),m*=h,g*=h,p*=h),t[0]=m,t[1]=g,t[2]=p,t[3]=0,t[4]=f*p-d*g,t[5]=d*m-c*p,t[6]=c*g-f*m,t[7]=0,t[8]=c,t[9]=f,t[10]=d,t[11]=0,t[12]=i,t[13]=s,t[14]=o,t[15]=1,t}function e1(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function t1(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function r1(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function Od(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function n1(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function i1(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function s1(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function o1(t,e){var r=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],u=t[6],l=t[7],c=t[8],f=t[9],d=t[10],h=t[11],m=t[12],g=t[13],p=t[14],y=t[15],_=e[0],x=e[1],b=e[2],v=e[3],S=e[4],w=e[5],M=e[6],L=e[7],A=e[8],T=e[9],I=e[10],z=e[11],C=e[12],V=e[13],se=e[14],Nr=e[15];return Math.abs(r-_)<=ee*Math.max(1,Math.abs(r),Math.abs(_))&&Math.abs(n-x)<=ee*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-b)<=ee*Math.max(1,Math.abs(i),Math.abs(b))&&Math.abs(s-v)<=ee*Math.max(1,Math.abs(s),Math.abs(v))&&Math.abs(o-S)<=ee*Math.max(1,Math.abs(o),Math.abs(S))&&Math.abs(a-w)<=ee*Math.max(1,Math.abs(a),Math.abs(w))&&Math.abs(u-M)<=ee*Math.max(1,Math.abs(u),Math.abs(M))&&Math.abs(l-L)<=ee*Math.max(1,Math.abs(l),Math.abs(L))&&Math.abs(c-A)<=ee*Math.max(1,Math.abs(c),Math.abs(A))&&Math.abs(f-T)<=ee*Math.max(1,Math.abs(f),Math.abs(T))&&Math.abs(d-I)<=ee*Math.max(1,Math.abs(d),Math.abs(I))&&Math.abs(h-z)<=ee*Math.max(1,Math.abs(h),Math.abs(z))&&Math.abs(m-C)<=ee*Math.max(1,Math.abs(m),Math.abs(C))&&Math.abs(g-V)<=ee*Math.max(1,Math.abs(g),Math.abs(V))&&Math.abs(p-se)<=ee*Math.max(1,Math.abs(p),Math.abs(se))&&Math.abs(y-Nr)<=ee*Math.max(1,Math.abs(y),Math.abs(Nr))}var a1=Fd,l1=Od;var D={};Ka(D,{add:()=>h1,angle:()=>D1,bezier:()=>T1,ceil:()=>m1,clone:()=>c1,copy:()=>d1,create:()=>Nd,cross:()=>A1,dist:()=>W1,distance:()=>Wd,div:()=>G1,divide:()=>Gd,dot:()=>nc,equals:()=>U1,exactEquals:()=>N1,floor:()=>p1,forEach:()=>Z1,fromValues:()=>u1,hermite:()=>L1,inverse:()=>w1,len:()=>K1,length:()=>Ud,lerp:()=>M1,max:()=>y1,min:()=>g1,mul:()=>V1,multiply:()=>Vd,negate:()=>v1,normalize:()=>S1,random:()=>k1,rotateX:()=>F1,rotateY:()=>z1,rotateZ:()=>P1,round:()=>b1,scale:()=>x1,scaleAndAdd:()=>_1,set:()=>f1,slerp:()=>E1,sqrDist:()=>X1,sqrLen:()=>$1,squaredDistance:()=>Xd,squaredLength:()=>Kd,str:()=>O1,sub:()=>H1,subtract:()=>Hd,transformMat3:()=>I1,transformMat4:()=>C1,transformQuat:()=>R1,zero:()=>B1});function Nd(){var t=new qe(3);return qe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function c1(t){var e=new qe(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Ud(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function u1(t,e,r){var n=new qe(3);return n[0]=t,n[1]=e,n[2]=r,n}function d1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function f1(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function h1(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Hd(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Vd(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Gd(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function m1(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function p1(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function g1(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function y1(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function b1(t,e){return t[0]=ga(e[0]),t[1]=ga(e[1]),t[2]=ga(e[2]),t}function x1(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function _1(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function Wd(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function Xd(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function Kd(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function v1(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function w1(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function S1(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function nc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function A1(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[0],a=r[1],u=r[2];return t[0]=i*u-s*a,t[1]=s*o-n*u,t[2]=n*a-i*o,t}function M1(t,e,r,n){var i=e[0],s=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=s+n*(r[1]-s),t[2]=o+n*(r[2]-o),t}function E1(t,e,r,n){var i=Math.acos(Math.min(Math.max(nc(e,r),-1),1)),s=Math.sin(i),o=Math.sin((1-n)*i)/s,a=Math.sin(n*i)/s;return t[0]=o*e[0]+a*r[0],t[1]=o*e[1]+a*r[1],t[2]=o*e[2]+a*r[2],t}function L1(t,e,r,n,i,s){var o=s*s,a=o*(2*s-3)+1,u=o*(s-2)+s,l=o*(s-1),c=o*(3-2*s);return t[0]=e[0]*a+r[0]*u+n[0]*l+i[0]*c,t[1]=e[1]*a+r[1]*u+n[1]*l+i[1]*c,t[2]=e[2]*a+r[2]*u+n[2]*l+i[2]*c,t}function T1(t,e,r,n,i,s){var o=1-s,a=o*o,u=s*s,l=a*o,c=3*s*a,f=3*u*o,d=u*s;return t[0]=e[0]*l+r[0]*c+n[0]*f+i[0]*d,t[1]=e[1]*l+r[1]*c+n[1]*f+i[1]*d,t[2]=e[2]*l+r[2]*c+n[2]*f+i[2]*d,t}function k1(t,e){e=e===void 0?1:e;var r=rc()*2*Math.PI,n=rc()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function C1(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[3]*n+r[7]*i+r[11]*s+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*s+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*s+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*s+r[14])/o,t}function I1(t,e,r){var n=e[0],i=e[1],s=e[2];return t[0]=n*r[0]+i*r[3]+s*r[6],t[1]=n*r[1]+i*r[4]+s*r[7],t[2]=n*r[2]+i*r[5]+s*r[8],t}function R1(t,e,r){var n=r[0],i=r[1],s=r[2],o=r[3],a=e[0],u=e[1],l=e[2],c=i*l-s*u,f=s*a-n*l,d=n*u-i*a;return c=c+c,f=f+f,d=d+d,t[0]=a+o*c+i*d-s*f,t[1]=u+o*f+s*c-n*d,t[2]=l+o*d+n*f-i*c,t}function F1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0],s[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),s[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function z1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),s[1]=i[1],s[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function P1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),s[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),s[2]=i[2],t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function D1(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2],u=Math.sqrt((r*r+n*n+i*i)*(s*s+o*o+a*a)),l=u&&nc(t,e)/u;return Math.acos(Math.min(Math.max(l,-1),1))}function B1(t){return t[0]=0,t[1]=0,t[2]=0,t}function O1(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function N1(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function U1(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(r-s)<=ee*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=ee*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=ee*Math.max(1,Math.abs(i),Math.abs(a))}var H1=Hd,V1=Vd,G1=Gd,W1=Wd,X1=Xd,K1=Ud,$1=Kd,Z1=(function(){var t=Nd();return function(e,r,n,i,s,o){var a,u;for(r||(r=3),n||(n=0),i?u=Math.min(i*r+n,e.length):u=e.length,a=n;a<u;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],s(t,t,o),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var ya=class{constructor(){this._position=D.create();this._angles=D.create();this._bobAngles=D.create();this._bobOffset=D.create();this._kickAngles=D.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ue.create();this._projectionMatrix=ue.create();this._viewProjectionMatrix=ue.create();this._dirty=!0}get position(){return this._position}set position(e){D.equals(this._position,e)||(D.copy(this._position,e),this._dirty=!0,this.triggerMoveEvent())}get angles(){return this._angles}set angles(e){D.equals(this._angles,e)||(D.copy(this._angles,e),this._dirty=!0,this.triggerMoveEvent())}get bobAngles(){return this._bobAngles}set bobAngles(e){D.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){D.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){D.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}setPosition(e,r,n){let i=D.fromValues(e,r,n);D.equals(this._position,i)||(D.copy(this._position,i),this._dirty=!0,this.triggerMoveEvent())}setRotation(e,r,n){let i=D.fromValues(e,r,n);D.equals(this._angles,i)||(D.copy(this._angles,i),this._dirty=!0,this.triggerMoveEvent())}setFov(e){this.fov=e}setAspectRatio(e){this.aspect=e}lookAt(e){let r=D.create();if(D.subtract(r,e,this._position),D.length(r)<.001)return;let i=Math.atan2(r[1],r[0])*Ya,s=Math.hypot(r[0],r[1]),o=-Math.atan2(r[2],s)*Ya;this.setRotation(o,i,0)}triggerMoveEvent(){this.onCameraMove&&this.onCameraMove({position:D.clone(this._position),angles:D.clone(this._angles)})}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ue.create();return ue.perspective(r,e*_n,this._aspect,this._near,this._far),r}screenToWorldRay(e,r){let n=e*2-1,i=1-r*2,s=D.fromValues(n,i,-1),o=D.fromValues(n,i,1),a=ue.create();ue.invert(a,this.viewProjectionMatrix);let u=D.create(),l=D.create();D.transformMat4(u,s,a),D.transformMat4(l,o,a);let c=D.create();return D.subtract(c,l,u),D.normalize(c,c),{origin:D.clone(this._position),direction:c}}updateMatrices(){if(!this._dirty)return;ue.perspective(this._projectionMatrix,this._fov*_n,this._aspect,this._near,this._far);let e=ue.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,s=r*_n,o=n*_n,a=i*_n,u=ue.create();ue.identity(u),ue.rotateZ(u,u,-o),ue.rotateY(u,u,-s),ue.rotateX(u,u,-a);let l=ue.create();ue.multiply(l,e,u);let c=D.add(D.create(),this._position,this._bobOffset),f=D.negate(D.create(),c),d=D.create();D.transformMat4(d,f,u);let h=D.fromValues(d[1]?-d[1]:0,d[2]||0,d[0]?-d[0]:0);ue.copy(this._viewMatrix,l),this._viewMatrix[12]=h[0],this._viewMatrix[13]=h[1],this._viewMatrix[14]=h[2],ue.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Y1=[.2,.2,.2],q1={x:0,y:0,z:1},j1=[.8,.8,.8];function ic(t,e,r){return t+(e-t)*r}function ni(t,e,r){return{x:ic(t.x,e.x,r),y:ic(t.y,e.y,r),z:ic(t.z,e.z,r)}}function ri(t){return t<0?0:t>1?1:t}function sc(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[s,o,a]=n.indices,u=t.texCoords[s],l=t.texCoords[o],c=t.texCoords[a];if(!u||!l||!c)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:s,texCoord:[u.s,1-u.t]},{vertexIndex:o,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[c.s,1-c.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Q1(t,e,r){let n=r?.ambient??Y1,i=r?.directional??{direction:q1,color:j1},s=At(t),o=At(i.direction),a=ri(s.x*o.x+s.y*o.y+s.z*o.z),u=n[0]+i.color[0]*a,l=n[1]+i.color[1]*a,c=n[2]+i.color[2]*a;if(r?.dynamicLights){let f=r.modelMatrix?su(r.modelMatrix,e):e;for(let d of r.dynamicLights){let h=f.x-d.origin.x,m=f.y-d.origin.y,g=f.z-d.origin.z,p=h*h+m*m+g*g,y=d.radius*d.radius;if(p<y&&y>0){let _=1-Math.sqrt(p)/d.radius,x=Math.sqrt(p),b=x>0?ri(-(h*s.x+m*s.y+g*s.z)/x):0,v=ri(_*b);u+=d.color[0]*v,l+=d.color[1]*v,c+=d.color[2]*v}}}return[ri(u),ri(l),ri(c)]}function oc(t,e,r,n){let i=t.vertices[r.frame0],s=t.vertices[r.frame1];if(!i||!s)throw new Error("Requested MD3 frames are out of range");let o=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,u)=>{let l=i[a.vertexIndex],c=s[a.vertexIndex];if(!l||!c)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let f=ni(l.position,c.position,r.lerp),d=At(ni(l.normal,c.normal,r.lerp)),h=Q1(d,f,n),m=u*12;o[m]=f.x,o[m+1]=f.y,o[m+2]=f.z,o[m+3]=d.x,o[m+4]=d.y,o[m+5]=d.z,o[m+6]=a.texCoord[0],o[m+7]=a.texCoord[1],o[m+8]=h[0],o[m+9]=h[1],o[m+10]=h[2],o[m+11]=1}),o}function $d(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(g=>g.name===r);if(i===-1)return null;let s=t.tags[e.frame0]?.[i],o=t.tags[e.frame1]?.[i];if(!s||!o)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=ni(s.origin,o.origin,e.lerp),u=At(ni(s.axis[0],o.axis[0],e.lerp)),l=At(ni(s.axis[1],o.axis[1],e.lerp)),c=At(ni(s.axis[2],o.axis[2],e.lerp)),f=u,d=At({x:l.x-f.x*(f.x*l.x+f.y*l.y+f.z*l.z),y:l.y-f.y*(f.x*l.x+f.y*l.y+f.z*l.z),z:l.z-f.z*(f.x*l.x+f.y*l.y+f.z*l.z)}),h=At({x:f.y*d.z-f.z*d.y,y:f.z*d.x-f.x*d.z,z:f.x*d.y-f.y*d.x}),m=[f,d,h];return{origin:a,axis:m,matrix:ou(a,m)}}var ac=`#version 300 es
479
+ }`;function gp(t){let e=t.x*t.x+t.y*t.y+t.z*t.z;if(e<=0)return{x:0,y:0,z:1};let r=1/Math.sqrt(e);return{x:t.x*r,y:t.y*r,z:t.z*r}}function jl(t,e,r){return t+(e-t)*r}function Cd(t,e,r){return{x:jl(t.x,e.x,r),y:jl(t.y,e.y,r),z:jl(t.z,e.z,r)}}function yp(t,e,r){return[t/r.skinWidth,1-e/r.skinHeight]}function ec(t){if(t.glCommands.length===0){let n=[],i=[];return t.triangles.forEach(s=>{let o=n.length;for(let a=0;a<3;a+=1){let u=s.vertexIndices[a],l=s.texCoordIndices[a],c=t.texCoords[l];n.push({vertexIndex:u,texCoord:yp(c.s,c.t,t.header)})}i.push(o,o+1,o+2)}),{vertices:n,indices:new Uint16Array(i)}}let e=[],r=[];for(let n of t.glCommands){let i=e.length;if(e.push(...n.vertices.map(s=>({vertexIndex:s.vertexIndex,texCoord:[s.s,1-s.t]}))),n.mode==="strip")for(let s=0;s<n.vertices.length-2;s+=1){let o=s%2===0,a=i+s+(o?0:1),u=i+s+(o?1:0),l=i+s+2;r.push(a,u,l)}else for(let s=1;s<n.vertices.length-1;s+=1)r.push(i,i+s,i+s+1)}return{vertices:e,indices:new Uint16Array(r)}}function tc(t,e,r){let{frame0:n,frame1:i,lerp:s}=r,o=t.frames[n],a=t.frames[i];if(!o||!a)throw new Error("Requested MD2 frames are out of range");let u=new Float32Array(e.vertices.length*8);return e.vertices.forEach((l,c)=>{let f=o.vertices[l.vertexIndex],d=a.vertices[l.vertexIndex];if(!f||!d)throw new Error("MD2 vertex index out of range for frame");let h=Cd(f.position,d.position,s),m=gp(Cd(f.normal,d.normal,s)),g=c*8;u[g]=h.x,u[g+1]=h.y,u[g+2]=h.z,u[g+3]=m.x,u[g+4]=m.y,u[g+5]=m.z,u[g+6]=l.texCoord[0],u[g+7]=l.texCoord[1]}),u}var ma=class{constructor(e,r,n){this.gl=e,this.geometry=ec(r),this.vertexBuffer=new Te(e,e.STATIC_DRAW),this.indexBuffer=new xe(e,e.STATIC_DRAW),this.vertexArray=new Re(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:32,offset:0},{index:1,size:3,type:e.FLOAT,stride:32,offset:12},{index:2,size:2,type:e.FLOAT,stride:32,offset:24}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n)}update(e,r){let n=tc(e,this.geometry,r);this.vertexBuffer.upload(n,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},pa=class{constructor(e){this.uniformDlights=[];this.gl=e,this.program=Le.create(e,{vertex:Ql,fragment:Jl},{a_position:0,a_normal:1,a_texCoord:2}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformModelMatrix=this.program.getUniformLocation("u_modelMatrix"),this.uniformLightDir=this.program.getUniformLocation("u_lightDir"),this.uniformAmbient=this.program.getUniformLocation("u_ambient"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformNumDlights=this.program.getUniformLocation("u_numDlights");for(let r=0;r<ur;r++)this.uniformDlights.push({pos:this.program.getUniformLocation(`u_dlights[${r}].position`),color:this.program.getUniformLocation(`u_dlights[${r}].color`),intensity:this.program.getUniformLocation(`u_dlights[${r}].intensity`)});this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e){let{modelViewProjection:r,modelMatrix:n,lightDirection:i=[0,0,1],ambientLight:s=.2,tint:o=[1,1,1,1],diffuseSampler:a=0,dlights:u=[],renderMode:l,brightness:c=1,gamma:f=1,fullbright:d=!1,ambient:h=0}=e,m=new Float32Array(i),g=new Float32Array(o);this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,r),n?this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,n):this.gl.uniformMatrix4fv(this.uniformModelMatrix,!1,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),this.gl.uniform3fv(this.uniformLightDir,m),this.gl.uniform1f(this.uniformAmbient,s),this.gl.uniform4fv(this.uniformTint,g),this.gl.uniform1i(this.uniformDiffuse,a);let p=0,y=[1,1,1,1];l&&(l.mode==="solid"||l.mode==="wireframe"?p=1:l.mode==="solid-faceted"&&(p=2),l.color?y=[...l.color]:l.generateRandomColor),this.gl.uniform1i(this.uniformRenderMode,p),this.gl.uniform4f(this.uniformSolidColor,y[0],y[1],y[2],y[3]);let _=Math.min(u.length,ur);this.gl.uniform1i(this.uniformNumDlights,_);for(let x=0;x<_;x++){let b=u[x];this.gl.uniform3f(this.uniformDlights[x].pos,b.origin.x,b.origin.y,b.origin.z),this.gl.uniform3f(this.uniformDlights[x].color,b.color.x,b.color.y,b.color.z),this.gl.uniform1f(this.uniformDlights[x].intensity,b.intensity)}this.gl.uniform1f(this.uniformBrightness,c),this.gl.uniform1f(this.uniformGamma,f),this.gl.uniform1i(this.uniformFullbright,d?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,h)}draw(e,r){if(e.vertexArray.bind(),r&&r.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let n=ti(e.geometry.indices);e.wireframeIndexBuffer.upload(n),e.wireframeIndexCount=n.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var ee=1e-6,qe=typeof Float32Array<"u"?Float32Array:Array,rc=Math.random;function ga(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}var z2=Math.PI/180,P2=180/Math.PI;var ue={};Ka(ue,{add:()=>r1,adjoint:()=>Mp,clone:()=>xp,copy:()=>_p,create:()=>bp,decompose:()=>Vp,determinant:()=>Ep,equals:()=>o1,exactEquals:()=>s1,frob:()=>t1,fromQuat:()=>Xp,fromQuat2:()=>Np,fromRotation:()=>Pp,fromRotationTranslation:()=>zd,fromRotationTranslationScale:()=>Gp,fromRotationTranslationScaleOrigin:()=>Wp,fromScaling:()=>zp,fromTranslation:()=>Fp,fromValues:()=>vp,fromXRotation:()=>Dp,fromYRotation:()=>Bp,fromZRotation:()=>Op,frustum:()=>Kp,getRotation:()=>Hp,getScaling:()=>Pd,getTranslation:()=>Up,identity:()=>Rd,invert:()=>Ap,lookAt:()=>Qp,mul:()=>a1,multiply:()=>Fd,multiplyScalar:()=>n1,multiplyScalarAndAdd:()=>i1,ortho:()=>qp,orthoNO:()=>Bd,orthoZO:()=>jp,perspective:()=>$p,perspectiveFromFieldOfView:()=>Yp,perspectiveNO:()=>Dd,perspectiveZO:()=>Zp,rotate:()=>kp,rotateX:()=>Cp,rotateY:()=>Ip,rotateZ:()=>Rp,scale:()=>Tp,set:()=>wp,str:()=>e1,sub:()=>l1,subtract:()=>Od,targetTo:()=>Jp,translate:()=>Lp,transpose:()=>Sp});function bp(){var t=new qe(16);return qe!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function xp(t){var e=new qe(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function _p(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function vp(t,e,r,n,i,s,o,a,u,l,c,f,d,h,m,g){var p=new qe(16);return p[0]=t,p[1]=e,p[2]=r,p[3]=n,p[4]=i,p[5]=s,p[6]=o,p[7]=a,p[8]=u,p[9]=l,p[10]=c,p[11]=f,p[12]=d,p[13]=h,p[14]=m,p[15]=g,p}function wp(t,e,r,n,i,s,o,a,u,l,c,f,d,h,m,g,p){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=s,t[5]=o,t[6]=a,t[7]=u,t[8]=l,t[9]=c,t[10]=f,t[11]=d,t[12]=h,t[13]=m,t[14]=g,t[15]=p,t}function Rd(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Sp(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],s=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=s,t[11]=e[14],t[12]=i,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Ap(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],l=e[7],c=e[8],f=e[9],d=e[10],h=e[11],m=e[12],g=e[13],p=e[14],y=e[15],_=r*a-n*o,x=r*u-i*o,b=r*l-s*o,v=n*u-i*a,S=n*l-s*a,w=i*l-s*u,M=c*g-f*m,L=c*p-d*m,A=c*y-h*m,T=f*p-d*g,I=f*y-h*g,z=d*y-h*p,C=_*z-x*I+b*T+v*A-S*L+w*M;return C?(C=1/C,t[0]=(a*z-u*I+l*T)*C,t[1]=(i*I-n*z-s*T)*C,t[2]=(g*w-p*S+y*v)*C,t[3]=(d*S-f*w-h*v)*C,t[4]=(u*A-o*z-l*L)*C,t[5]=(r*z-i*A+s*L)*C,t[6]=(p*b-m*w-y*x)*C,t[7]=(c*w-d*b+h*x)*C,t[8]=(o*I-a*A+l*M)*C,t[9]=(n*A-r*I-s*M)*C,t[10]=(m*S-g*b+y*_)*C,t[11]=(f*b-c*S-h*_)*C,t[12]=(a*L-o*T-u*M)*C,t[13]=(r*T-n*L+i*M)*C,t[14]=(g*x-m*v-p*_)*C,t[15]=(c*v-f*x+d*_)*C,t):null}function Mp(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],l=e[7],c=e[8],f=e[9],d=e[10],h=e[11],m=e[12],g=e[13],p=e[14],y=e[15],_=r*a-n*o,x=r*u-i*o,b=r*l-s*o,v=n*u-i*a,S=n*l-s*a,w=i*l-s*u,M=c*g-f*m,L=c*p-d*m,A=c*y-h*m,T=f*p-d*g,I=f*y-h*g,z=d*y-h*p;return t[0]=a*z-u*I+l*T,t[1]=i*I-n*z-s*T,t[2]=g*w-p*S+y*v,t[3]=d*S-f*w-h*v,t[4]=u*A-o*z-l*L,t[5]=r*z-i*A+s*L,t[6]=p*b-m*w-y*x,t[7]=c*w-d*b+h*x,t[8]=o*I-a*A+l*M,t[9]=n*A-r*I-s*M,t[10]=m*S-g*b+y*_,t[11]=f*b-c*S-h*_,t[12]=a*L-o*T-u*M,t[13]=r*T-n*L+i*M,t[14]=g*x-m*v-p*_,t[15]=c*v-f*x+d*_,t}function Ep(t){var e=t[0],r=t[1],n=t[2],i=t[3],s=t[4],o=t[5],a=t[6],u=t[7],l=t[8],c=t[9],f=t[10],d=t[11],h=t[12],m=t[13],g=t[14],p=t[15],y=e*o-r*s,_=e*a-n*s,x=r*a-n*o,b=l*m-c*h,v=l*g-f*h,S=c*g-f*m,w=e*S-r*v+n*b,M=s*S-o*v+a*b,L=l*x-c*_+f*y,A=h*x-m*_+g*y;return u*w-i*M+p*L-d*A}function Fd(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=e[4],u=e[5],l=e[6],c=e[7],f=e[8],d=e[9],h=e[10],m=e[11],g=e[12],p=e[13],y=e[14],_=e[15],x=r[0],b=r[1],v=r[2],S=r[3];return t[0]=x*n+b*a+v*f+S*g,t[1]=x*i+b*u+v*d+S*p,t[2]=x*s+b*l+v*h+S*y,t[3]=x*o+b*c+v*m+S*_,x=r[4],b=r[5],v=r[6],S=r[7],t[4]=x*n+b*a+v*f+S*g,t[5]=x*i+b*u+v*d+S*p,t[6]=x*s+b*l+v*h+S*y,t[7]=x*o+b*c+v*m+S*_,x=r[8],b=r[9],v=r[10],S=r[11],t[8]=x*n+b*a+v*f+S*g,t[9]=x*i+b*u+v*d+S*p,t[10]=x*s+b*l+v*h+S*y,t[11]=x*o+b*c+v*m+S*_,x=r[12],b=r[13],v=r[14],S=r[15],t[12]=x*n+b*a+v*f+S*g,t[13]=x*i+b*u+v*d+S*p,t[14]=x*s+b*l+v*h+S*y,t[15]=x*o+b*c+v*m+S*_,t}function Lp(t,e,r){var n=r[0],i=r[1],s=r[2],o,a,u,l,c,f,d,h,m,g,p,y;return e===t?(t[12]=e[0]*n+e[4]*i+e[8]*s+e[12],t[13]=e[1]*n+e[5]*i+e[9]*s+e[13],t[14]=e[2]*n+e[6]*i+e[10]*s+e[14],t[15]=e[3]*n+e[7]*i+e[11]*s+e[15]):(o=e[0],a=e[1],u=e[2],l=e[3],c=e[4],f=e[5],d=e[6],h=e[7],m=e[8],g=e[9],p=e[10],y=e[11],t[0]=o,t[1]=a,t[2]=u,t[3]=l,t[4]=c,t[5]=f,t[6]=d,t[7]=h,t[8]=m,t[9]=g,t[10]=p,t[11]=y,t[12]=o*n+c*i+m*s+e[12],t[13]=a*n+f*i+g*s+e[13],t[14]=u*n+d*i+p*s+e[14],t[15]=l*n+h*i+y*s+e[15]),t}function Tp(t,e,r){var n=r[0],i=r[1],s=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function kp(t,e,r,n){var i=n[0],s=n[1],o=n[2],a=Math.sqrt(i*i+s*s+o*o),u,l,c,f,d,h,m,g,p,y,_,x,b,v,S,w,M,L,A,T,I,z,C,V;return a<ee?null:(a=1/a,i*=a,s*=a,o*=a,u=Math.sin(r),l=Math.cos(r),c=1-l,f=e[0],d=e[1],h=e[2],m=e[3],g=e[4],p=e[5],y=e[6],_=e[7],x=e[8],b=e[9],v=e[10],S=e[11],w=i*i*c+l,M=s*i*c+o*u,L=o*i*c-s*u,A=i*s*c-o*u,T=s*s*c+l,I=o*s*c+i*u,z=i*o*c+s*u,C=s*o*c-i*u,V=o*o*c+l,t[0]=f*w+g*M+x*L,t[1]=d*w+p*M+b*L,t[2]=h*w+y*M+v*L,t[3]=m*w+_*M+S*L,t[4]=f*A+g*T+x*I,t[5]=d*A+p*T+b*I,t[6]=h*A+y*T+v*I,t[7]=m*A+_*T+S*I,t[8]=f*z+g*C+x*V,t[9]=d*z+p*C+b*V,t[10]=h*z+y*C+v*V,t[11]=m*z+_*C+S*V,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Cp(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[4],o=e[5],a=e[6],u=e[7],l=e[8],c=e[9],f=e[10],d=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=s*i+l*n,t[5]=o*i+c*n,t[6]=a*i+f*n,t[7]=u*i+d*n,t[8]=l*i-s*n,t[9]=c*i-o*n,t[10]=f*i-a*n,t[11]=d*i-u*n,t}function Ip(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],l=e[8],c=e[9],f=e[10],d=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i-l*n,t[1]=o*i-c*n,t[2]=a*i-f*n,t[3]=u*i-d*n,t[8]=s*n+l*i,t[9]=o*n+c*i,t[10]=a*n+f*i,t[11]=u*n+d*i,t}function Rp(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],l=e[4],c=e[5],f=e[6],d=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i+l*n,t[1]=o*i+c*n,t[2]=a*i+f*n,t[3]=u*i+d*n,t[4]=l*i-s*n,t[5]=c*i-o*n,t[6]=f*i-a*n,t[7]=d*i-u*n,t}function Fp(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function zp(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Pp(t,e,r){var n=r[0],i=r[1],s=r[2],o=Math.sqrt(n*n+i*i+s*s),a,u,l;return o<ee?null:(o=1/o,n*=o,i*=o,s*=o,a=Math.sin(e),u=Math.cos(e),l=1-u,t[0]=n*n*l+u,t[1]=i*n*l+s*a,t[2]=s*n*l-i*a,t[3]=0,t[4]=n*i*l-s*a,t[5]=i*i*l+u,t[6]=s*i*l+n*a,t[7]=0,t[8]=n*s*l+i*a,t[9]=i*s*l-n*a,t[10]=s*s*l+u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function Dp(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Bp(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Op(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function zd(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=n+n,u=i+i,l=s+s,c=n*a,f=n*u,d=n*l,h=i*u,m=i*l,g=s*l,p=o*a,y=o*u,_=o*l;return t[0]=1-(h+g),t[1]=f+_,t[2]=d-y,t[3]=0,t[4]=f-_,t[5]=1-(c+g),t[6]=m+p,t[7]=0,t[8]=d+y,t[9]=m-p,t[10]=1-(c+h),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Np(t,e){var r=new qe(3),n=-e[0],i=-e[1],s=-e[2],o=e[3],a=e[4],u=e[5],l=e[6],c=e[7],f=n*n+i*i+s*s+o*o;return f>0?(r[0]=(a*o+c*n+u*s-l*i)*2/f,r[1]=(u*o+c*i+l*n-a*s)*2/f,r[2]=(l*o+c*s+a*i-u*n)*2/f):(r[0]=(a*o+c*n+u*s-l*i)*2,r[1]=(u*o+c*i+l*n-a*s)*2,r[2]=(l*o+c*s+a*i-u*n)*2),zd(t,e,r),t}function Up(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Pd(t,e){var r=e[0],n=e[1],i=e[2],s=e[4],o=e[5],a=e[6],u=e[8],l=e[9],c=e[10];return t[0]=Math.sqrt(r*r+n*n+i*i),t[1]=Math.sqrt(s*s+o*o+a*a),t[2]=Math.sqrt(u*u+l*l+c*c),t}function Hp(t,e){var r=new qe(3);Pd(r,e);var n=1/r[0],i=1/r[1],s=1/r[2],o=e[0]*n,a=e[1]*i,u=e[2]*s,l=e[4]*n,c=e[5]*i,f=e[6]*s,d=e[8]*n,h=e[9]*i,m=e[10]*s,g=o+c+m,p=0;return g>0?(p=Math.sqrt(g+1)*2,t[3]=.25*p,t[0]=(f-h)/p,t[1]=(d-u)/p,t[2]=(a-l)/p):o>c&&o>m?(p=Math.sqrt(1+o-c-m)*2,t[3]=(f-h)/p,t[0]=.25*p,t[1]=(a+l)/p,t[2]=(d+u)/p):c>m?(p=Math.sqrt(1+c-o-m)*2,t[3]=(d-u)/p,t[0]=(a+l)/p,t[1]=.25*p,t[2]=(f+h)/p):(p=Math.sqrt(1+m-o-c)*2,t[3]=(a-l)/p,t[0]=(d+u)/p,t[1]=(f+h)/p,t[2]=.25*p),t}function Vp(t,e,r,n){e[0]=n[12],e[1]=n[13],e[2]=n[14];var i=n[0],s=n[1],o=n[2],a=n[4],u=n[5],l=n[6],c=n[8],f=n[9],d=n[10];r[0]=Math.sqrt(i*i+s*s+o*o),r[1]=Math.sqrt(a*a+u*u+l*l),r[2]=Math.sqrt(c*c+f*f+d*d);var h=1/r[0],m=1/r[1],g=1/r[2],p=i*h,y=s*m,_=o*g,x=a*h,b=u*m,v=l*g,S=c*h,w=f*m,M=d*g,L=p+b+M,A=0;return L>0?(A=Math.sqrt(L+1)*2,t[3]=.25*A,t[0]=(v-w)/A,t[1]=(S-_)/A,t[2]=(y-x)/A):p>b&&p>M?(A=Math.sqrt(1+p-b-M)*2,t[3]=(v-w)/A,t[0]=.25*A,t[1]=(y+x)/A,t[2]=(S+_)/A):b>M?(A=Math.sqrt(1+b-p-M)*2,t[3]=(S-_)/A,t[0]=(y+x)/A,t[1]=.25*A,t[2]=(v+w)/A):(A=Math.sqrt(1+M-p-b)*2,t[3]=(y-x)/A,t[0]=(S+_)/A,t[1]=(v+w)/A,t[2]=.25*A),t}function Gp(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=e[3],u=i+i,l=s+s,c=o+o,f=i*u,d=i*l,h=i*c,m=s*l,g=s*c,p=o*c,y=a*u,_=a*l,x=a*c,b=n[0],v=n[1],S=n[2];return t[0]=(1-(m+p))*b,t[1]=(d+x)*b,t[2]=(h-_)*b,t[3]=0,t[4]=(d-x)*v,t[5]=(1-(f+p))*v,t[6]=(g+y)*v,t[7]=0,t[8]=(h+_)*S,t[9]=(g-y)*S,t[10]=(1-(f+m))*S,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function Wp(t,e,r,n,i){var s=e[0],o=e[1],a=e[2],u=e[3],l=s+s,c=o+o,f=a+a,d=s*l,h=s*c,m=s*f,g=o*c,p=o*f,y=a*f,_=u*l,x=u*c,b=u*f,v=n[0],S=n[1],w=n[2],M=i[0],L=i[1],A=i[2],T=(1-(g+y))*v,I=(h+b)*v,z=(m-x)*v,C=(h-b)*S,V=(1-(d+y))*S,se=(p+_)*S,Nr=(m+x)*w,js=(p-_)*w,pi=(1-(d+g))*w;return t[0]=T,t[1]=I,t[2]=z,t[3]=0,t[4]=C,t[5]=V,t[6]=se,t[7]=0,t[8]=Nr,t[9]=js,t[10]=pi,t[11]=0,t[12]=r[0]+M-(T*M+C*L+Nr*A),t[13]=r[1]+L-(I*M+V*L+js*A),t[14]=r[2]+A-(z*M+se*L+pi*A),t[15]=1,t}function Xp(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,u=i+i,l=r*o,c=n*o,f=n*a,d=i*o,h=i*a,m=i*u,g=s*o,p=s*a,y=s*u;return t[0]=1-f-m,t[1]=c+y,t[2]=d-p,t[3]=0,t[4]=c-y,t[5]=1-l-m,t[6]=h+g,t[7]=0,t[8]=d+p,t[9]=h-g,t[10]=1-l-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Kp(t,e,r,n,i,s,o){var a=1/(r-e),u=1/(i-n),l=1/(s-o);return t[0]=s*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s*2*u,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(i+n)*u,t[10]=(o+s)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*s*2*l,t[15]=0,t}function Dd(t,e,r,n,i){var s=1/Math.tan(e/2);if(t[0]=s/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=(i+n)*o,t[14]=2*i*n*o}else t[10]=-1,t[14]=-2*n;return t}var $p=Dd;function Zp(t,e,r,n,i){var s=1/Math.tan(e/2);if(t[0]=s/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){var o=1/(n-i);t[10]=i*o,t[14]=i*n*o}else t[10]=-1,t[14]=-n;return t}function Yp(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),s=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),u=2/(o+a),l=2/(i+s);return t[0]=u,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((o-a)*u*.5),t[9]=(i-s)*l*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Bd(t,e,r,n,i,s,o){var a=1/(e-r),u=1/(n-i),l=1/(s-o);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*u,t[14]=(o+s)*l,t[15]=1,t}var qp=Bd;function jp(t,e,r,n,i,s,o){var a=1/(e-r),u=1/(n-i),l=1/(s-o);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*u,t[14]=s*l,t[15]=1,t}function Qp(t,e,r,n){var i,s,o,a,u,l,c,f,d,h,m=e[0],g=e[1],p=e[2],y=n[0],_=n[1],x=n[2],b=r[0],v=r[1],S=r[2];return Math.abs(m-b)<ee&&Math.abs(g-v)<ee&&Math.abs(p-S)<ee?Rd(t):(c=m-b,f=g-v,d=p-S,h=1/Math.sqrt(c*c+f*f+d*d),c*=h,f*=h,d*=h,i=_*d-x*f,s=x*c-y*d,o=y*f-_*c,h=Math.sqrt(i*i+s*s+o*o),h?(h=1/h,i*=h,s*=h,o*=h):(i=0,s=0,o=0),a=f*o-d*s,u=d*i-c*o,l=c*s-f*i,h=Math.sqrt(a*a+u*u+l*l),h?(h=1/h,a*=h,u*=h,l*=h):(a=0,u=0,l=0),t[0]=i,t[1]=a,t[2]=c,t[3]=0,t[4]=s,t[5]=u,t[6]=f,t[7]=0,t[8]=o,t[9]=l,t[10]=d,t[11]=0,t[12]=-(i*m+s*g+o*p),t[13]=-(a*m+u*g+l*p),t[14]=-(c*m+f*g+d*p),t[15]=1,t)}function Jp(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=n[0],u=n[1],l=n[2],c=i-r[0],f=s-r[1],d=o-r[2],h=c*c+f*f+d*d;h>0&&(h=1/Math.sqrt(h),c*=h,f*=h,d*=h);var m=u*d-l*f,g=l*c-a*d,p=a*f-u*c;return h=m*m+g*g+p*p,h>0&&(h=1/Math.sqrt(h),m*=h,g*=h,p*=h),t[0]=m,t[1]=g,t[2]=p,t[3]=0,t[4]=f*p-d*g,t[5]=d*m-c*p,t[6]=c*g-f*m,t[7]=0,t[8]=c,t[9]=f,t[10]=d,t[11]=0,t[12]=i,t[13]=s,t[14]=o,t[15]=1,t}function e1(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function t1(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function r1(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function Od(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function n1(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function i1(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function s1(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function o1(t,e){var r=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],u=t[6],l=t[7],c=t[8],f=t[9],d=t[10],h=t[11],m=t[12],g=t[13],p=t[14],y=t[15],_=e[0],x=e[1],b=e[2],v=e[3],S=e[4],w=e[5],M=e[6],L=e[7],A=e[8],T=e[9],I=e[10],z=e[11],C=e[12],V=e[13],se=e[14],Nr=e[15];return Math.abs(r-_)<=ee*Math.max(1,Math.abs(r),Math.abs(_))&&Math.abs(n-x)<=ee*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-b)<=ee*Math.max(1,Math.abs(i),Math.abs(b))&&Math.abs(s-v)<=ee*Math.max(1,Math.abs(s),Math.abs(v))&&Math.abs(o-S)<=ee*Math.max(1,Math.abs(o),Math.abs(S))&&Math.abs(a-w)<=ee*Math.max(1,Math.abs(a),Math.abs(w))&&Math.abs(u-M)<=ee*Math.max(1,Math.abs(u),Math.abs(M))&&Math.abs(l-L)<=ee*Math.max(1,Math.abs(l),Math.abs(L))&&Math.abs(c-A)<=ee*Math.max(1,Math.abs(c),Math.abs(A))&&Math.abs(f-T)<=ee*Math.max(1,Math.abs(f),Math.abs(T))&&Math.abs(d-I)<=ee*Math.max(1,Math.abs(d),Math.abs(I))&&Math.abs(h-z)<=ee*Math.max(1,Math.abs(h),Math.abs(z))&&Math.abs(m-C)<=ee*Math.max(1,Math.abs(m),Math.abs(C))&&Math.abs(g-V)<=ee*Math.max(1,Math.abs(g),Math.abs(V))&&Math.abs(p-se)<=ee*Math.max(1,Math.abs(p),Math.abs(se))&&Math.abs(y-Nr)<=ee*Math.max(1,Math.abs(y),Math.abs(Nr))}var a1=Fd,l1=Od;var D={};Ka(D,{add:()=>h1,angle:()=>D1,bezier:()=>T1,ceil:()=>m1,clone:()=>c1,copy:()=>d1,create:()=>Nd,cross:()=>A1,dist:()=>W1,distance:()=>Wd,div:()=>G1,divide:()=>Gd,dot:()=>nc,equals:()=>U1,exactEquals:()=>N1,floor:()=>p1,forEach:()=>Z1,fromValues:()=>u1,hermite:()=>L1,inverse:()=>w1,len:()=>K1,length:()=>Ud,lerp:()=>M1,max:()=>y1,min:()=>g1,mul:()=>V1,multiply:()=>Vd,negate:()=>v1,normalize:()=>S1,random:()=>k1,rotateX:()=>F1,rotateY:()=>z1,rotateZ:()=>P1,round:()=>b1,scale:()=>x1,scaleAndAdd:()=>_1,set:()=>f1,slerp:()=>E1,sqrDist:()=>X1,sqrLen:()=>$1,squaredDistance:()=>Xd,squaredLength:()=>Kd,str:()=>O1,sub:()=>H1,subtract:()=>Hd,transformMat3:()=>I1,transformMat4:()=>C1,transformQuat:()=>R1,zero:()=>B1});function Nd(){var t=new qe(3);return qe!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function c1(t){var e=new qe(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Ud(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function u1(t,e,r){var n=new qe(3);return n[0]=t,n[1]=e,n[2]=r,n}function d1(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function f1(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function h1(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Hd(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Vd(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Gd(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function m1(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function p1(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function g1(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function y1(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function b1(t,e){return t[0]=ga(e[0]),t[1]=ga(e[1]),t[2]=ga(e[2]),t}function x1(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function _1(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function Wd(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(r*r+n*n+i*i)}function Xd(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function Kd(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function v1(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function w1(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function S1(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function nc(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function A1(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[0],a=r[1],u=r[2];return t[0]=i*u-s*a,t[1]=s*o-n*u,t[2]=n*a-i*o,t}function M1(t,e,r,n){var i=e[0],s=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=s+n*(r[1]-s),t[2]=o+n*(r[2]-o),t}function E1(t,e,r,n){var i=Math.acos(Math.min(Math.max(nc(e,r),-1),1)),s=Math.sin(i),o=Math.sin((1-n)*i)/s,a=Math.sin(n*i)/s;return t[0]=o*e[0]+a*r[0],t[1]=o*e[1]+a*r[1],t[2]=o*e[2]+a*r[2],t}function L1(t,e,r,n,i,s){var o=s*s,a=o*(2*s-3)+1,u=o*(s-2)+s,l=o*(s-1),c=o*(3-2*s);return t[0]=e[0]*a+r[0]*u+n[0]*l+i[0]*c,t[1]=e[1]*a+r[1]*u+n[1]*l+i[1]*c,t[2]=e[2]*a+r[2]*u+n[2]*l+i[2]*c,t}function T1(t,e,r,n,i,s){var o=1-s,a=o*o,u=s*s,l=a*o,c=3*s*a,f=3*u*o,d=u*s;return t[0]=e[0]*l+r[0]*c+n[0]*f+i[0]*d,t[1]=e[1]*l+r[1]*c+n[1]*f+i[1]*d,t[2]=e[2]*l+r[2]*c+n[2]*f+i[2]*d,t}function k1(t,e){e=e===void 0?1:e;var r=rc()*2*Math.PI,n=rc()*2-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function C1(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[3]*n+r[7]*i+r[11]*s+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*s+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*s+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*s+r[14])/o,t}function I1(t,e,r){var n=e[0],i=e[1],s=e[2];return t[0]=n*r[0]+i*r[3]+s*r[6],t[1]=n*r[1]+i*r[4]+s*r[7],t[2]=n*r[2]+i*r[5]+s*r[8],t}function R1(t,e,r){var n=r[0],i=r[1],s=r[2],o=r[3],a=e[0],u=e[1],l=e[2],c=i*l-s*u,f=s*a-n*l,d=n*u-i*a;return c=c+c,f=f+f,d=d+d,t[0]=a+o*c+i*d-s*f,t[1]=u+o*f+s*c-n*d,t[2]=l+o*d+n*f-i*c,t}function F1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0],s[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),s[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function z1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),s[1]=i[1],s[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function P1(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),s[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),s[2]=i[2],t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function D1(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2],u=Math.sqrt((r*r+n*n+i*i)*(s*s+o*o+a*a)),l=u&&nc(t,e)/u;return Math.acos(Math.min(Math.max(l,-1),1))}function B1(t){return t[0]=0,t[1]=0,t[2]=0,t}function O1(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function N1(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function U1(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(r-s)<=ee*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=ee*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=ee*Math.max(1,Math.abs(i),Math.abs(a))}var H1=Hd,V1=Vd,G1=Gd,W1=Wd,X1=Xd,K1=Ud,$1=Kd,Z1=(function(){var t=Nd();return function(e,r,n,i,s,o){var a,u;for(r||(r=3),n||(n=0),i?u=Math.min(i*r+n,e.length):u=e.length,a=n;a<u;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],s(t,t,o),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var ya=class{constructor(){this._position=D.create();this._angles=D.create();this._bobAngles=D.create();this._bobOffset=D.create();this._kickAngles=D.create();this._rollAngle=0;this._fov=90;this._aspect=1;this._near=.1;this._far=1e3;this._viewMatrix=ue.create();this._projectionMatrix=ue.create();this._viewProjectionMatrix=ue.create();this._dirty=!0}get position(){return this._position}set position(e){D.equals(this._position,e)||(D.copy(this._position,e),this._dirty=!0,this.triggerMoveEvent())}get angles(){return this._angles}set angles(e){D.equals(this._angles,e)||(D.copy(this._angles,e),this._dirty=!0,this.triggerMoveEvent())}get bobAngles(){return this._bobAngles}set bobAngles(e){D.copy(this._bobAngles,e),this._dirty=!0}get kickAngles(){return this._kickAngles}set kickAngles(e){D.copy(this._kickAngles,e),this._dirty=!0}get bobOffset(){return this._bobOffset}set bobOffset(e){D.copy(this._bobOffset,e),this._dirty=!0}get rollAngle(){return this._rollAngle}set rollAngle(e){this._rollAngle=e,this._dirty=!0}get fov(){return this._fov}set fov(e){this._fov=e,this._dirty=!0}get aspect(){return this._aspect}set aspect(e){this._aspect=e,this._dirty=!0}setPosition(e,r,n){let i=D.fromValues(e,r,n);D.equals(this._position,i)||(D.copy(this._position,i),this._dirty=!0,this.triggerMoveEvent())}setRotation(e,r,n){let i=D.fromValues(e,r,n);D.equals(this._angles,i)||(D.copy(this._angles,i),this._dirty=!0,this.triggerMoveEvent())}setFov(e){this.fov=e}setAspectRatio(e){this.aspect=e}lookAt(e){let r=D.create();if(D.subtract(r,e,this._position),D.length(r)<.001)return;let i=Math.atan2(r[1],r[0])*Ya,s=Math.hypot(r[0],r[1]),o=-Math.atan2(r[2],s)*Ya;this.setRotation(o,i,0)}triggerMoveEvent(){this.onCameraMove&&this.onCameraMove({position:D.clone(this._position),angles:D.clone(this._angles)})}get viewMatrix(){return this.updateMatrices(),this._viewMatrix}get projectionMatrix(){return this.updateMatrices(),this._projectionMatrix}get viewProjectionMatrix(){return this.updateMatrices(),this._viewProjectionMatrix}getViewmodelProjectionMatrix(e){let r=ue.create();return ue.perspective(r,e*_n,this._aspect,this._near,this._far),r}screenToWorldRay(e,r){let n=e*2-1,i=1-r*2,s=D.fromValues(n,i,-1),o=D.fromValues(n,i,1),a=ue.create();ue.invert(a,this.viewProjectionMatrix);let u=D.create(),l=D.create();D.transformMat4(u,s,a),D.transformMat4(l,o,a);let c=D.create();return D.subtract(c,l,u),D.normalize(c,c),{origin:D.clone(this._position),direction:c}}updateMatrices(){if(!this._dirty)return;ue.perspective(this._projectionMatrix,this._fov*_n,this._aspect,this._near,this._far);let e=ue.fromValues(0,0,-1,0,-1,0,0,0,0,1,0,0,0,0,0,1),r=this._angles[0]+this._bobAngles[0]+this._kickAngles[0],n=this._angles[1]+this._bobAngles[1]+this._kickAngles[1],i=this._angles[2]+this._bobAngles[2]+this._kickAngles[2]+this._rollAngle,s=r*_n,o=n*_n,a=i*_n,u=ue.create();ue.identity(u),ue.rotateZ(u,u,-o),ue.rotateY(u,u,-s),ue.rotateX(u,u,-a);let l=ue.create();ue.multiply(l,e,u);let c=D.add(D.create(),this._position,this._bobOffset),f=D.negate(D.create(),c),d=D.create();D.transformMat4(d,f,u);let h=D.fromValues(d[1]?-d[1]:0,d[2]||0,d[0]?-d[0]:0);ue.copy(this._viewMatrix,l),this._viewMatrix[12]=h[0],this._viewMatrix[13]=h[1],this._viewMatrix[14]=h[2],ue.multiply(this._viewProjectionMatrix,this._projectionMatrix,this._viewMatrix),this._dirty=!1}};var Y1=[.2,.2,.2],q1={x:0,y:0,z:1},j1=[.8,.8,.8];function ic(t,e,r){return t+(e-t)*r}function ni(t,e,r){return{x:ic(t.x,e.x,r),y:ic(t.y,e.y,r),z:ic(t.z,e.z,r)}}function ri(t){return t<0?0:t>1?1:t}function sc(t){let e=[],r=[];for(let n of t.triangles){let i=e.length,[s,o,a]=n.indices,u=t.texCoords[s],l=t.texCoords[o],c=t.texCoords[a];if(!u||!l||!c)throw new Error(`Missing texCoord for triangle in surface ${t.name}`);e.push({vertexIndex:s,texCoord:[u.s,1-u.t]},{vertexIndex:o,texCoord:[l.s,1-l.t]},{vertexIndex:a,texCoord:[c.s,1-c.t]}),r.push(i,i+1,i+2)}return{vertices:e,indices:new Uint16Array(r)}}function Q1(t,e,r){let n=r?.ambient??Y1,i=r?.directional??{direction:q1,color:j1},s=At(t),o=At(i.direction),a=ri(s.x*o.x+s.y*o.y+s.z*o.z),u=n[0]+i.color[0]*a,l=n[1]+i.color[1]*a,c=n[2]+i.color[2]*a;if(r?.dynamicLights){let f=r.modelMatrix?su(r.modelMatrix,e):e;for(let d of r.dynamicLights){let h=f.x-d.origin.x,m=f.y-d.origin.y,g=f.z-d.origin.z,p=h*h+m*m+g*g,y=d.radius*d.radius;if(p<y&&y>0){let _=1-Math.sqrt(p)/d.radius,x=Math.sqrt(p),b=x>0?ri(-(h*s.x+m*s.y+g*s.z)/x):0,v=ri(_*b);u+=d.color[0]*v,l+=d.color[1]*v,c+=d.color[2]*v}}}return[ri(u),ri(l),ri(c)]}function oc(t,e,r,n){let i=t.vertices[r.frame0],s=t.vertices[r.frame1];if(!i||!s)throw new Error("Requested MD3 frames are out of range");let o=new Float32Array(e.vertices.length*12);return e.vertices.forEach((a,u)=>{let l=i[a.vertexIndex],c=s[a.vertexIndex];if(!l||!c)throw new Error(`Vertex index ${a.vertexIndex} missing for frame`);let f=ni(l.position,c.position,r.lerp),d=At(ni(l.normal,c.normal,r.lerp)),h=Q1(d,f,n),m=u*12;o[m]=f.x,o[m+1]=f.y,o[m+2]=f.z,o[m+3]=d.x,o[m+4]=d.y,o[m+5]=d.z,o[m+6]=a.texCoord[0],o[m+7]=a.texCoord[1],o[m+8]=h[0],o[m+9]=h[1],o[m+10]=h[2],o[m+11]=1}),o}function $d(t,e,r){let n=t.tags[0];if(!n)return null;let i=n.findIndex(g=>g.name===r);if(i===-1)return null;let s=t.tags[e.frame0]?.[i],o=t.tags[e.frame1]?.[i];if(!s||!o)throw new Error(`Tag ${r} is missing for one of the interpolated frames`);let a=ni(s.origin,o.origin,e.lerp),u=At(ni(s.axis[0],o.axis[0],e.lerp)),l=At(ni(s.axis[1],o.axis[1],e.lerp)),c=At(ni(s.axis[2],o.axis[2],e.lerp)),f=u,d=At({x:l.x-f.x*(f.x*l.x+f.y*l.y+f.z*l.z),y:l.y-f.y*(f.x*l.x+f.y*l.y+f.z*l.z),z:l.z-f.z*(f.x*l.x+f.y*l.y+f.z*l.z)}),h=At({x:f.y*d.z-f.z*d.y,y:f.z*d.x-f.x*d.z,z:f.x*d.y-f.y*d.x}),m=[f,d,h];return{origin:a,axis:m,matrix:ou(a,m)}}var ac=`#version 300 es
480
480
  precision highp float;
481
481
 
482
482
  layout(location = 0) in vec3 a_position;
@@ -551,7 +551,7 @@ void main() {
551
551
  }
552
552
 
553
553
  o_color = finalColor;
554
- }`,Ls=class{constructor(e,r,n,i){this.gl=e,this.geometry=sc(r),this.vertexBuffer=new Te(e,e.STATIC_DRAW),this.indexBuffer=new xe(e,e.STATIC_DRAW),this.vertexArray=new Re(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=oc(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},ba=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(s=>{this.surfaces.set(s.name,new Ls(e,s,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},xa=class{constructor(e){this.gl=e,this.program=Le.create(e,{vertex:ac,fragment:lc},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],s=r?.renderMode,o=r?.brightness??1,a=r?.gamma??1,u=r?.fullbright??!1,l=r?.globalAmbient??0;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let c=0,f=[1,1,1,1];if(s&&(s.mode==="solid"||s.mode==="wireframe"?c=1:s.mode==="solid-faceted"&&(c=2),s.color&&(f=[...s.color])),this.gl.uniform1i(this.uniformRenderMode,c),this.gl.uniform4f(this.uniformSolidColor,f[0],f[1],f[2],f[3]),this.gl.uniform1f(this.uniformBrightness,o),this.gl.uniform1f(this.uniformGamma,a),this.gl.uniform1i(this.uniformFullbright,u?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,l),e.vertexArray.bind(),s&&s.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let d=ti(e.geometry.indices);e.wireframeIndexBuffer.upload(d),e.wireframeIndexCount=d.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var J1=[1,1,1,1],_a=class{constructor(e,r){this.maxParticles=e,this.rng=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??J1,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let s=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=s,this.velocityY[i]*=s,this.velocityZ[i]=this.velocityZ[i]*s-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha"}}buildMesh(e,r){let n=[],i=[],s=[],o=a=>{let u=i.length,l=0;for(let c=0;c<this.maxParticles;c+=1){if(!this.alive[c]||(a==="additive"?1:0)!==this.blendMode[c])continue;l+=1;let f=n.length/9,d=this.size[c]*.5,h=this.fade[c]?Math.max(this.remaining[c]/this.lifetime[c],0):1,m=this.blendMode[c]===1?1.2:1,g=this.colorR[c]*m,p=this.colorG[c]*m,y=this.colorB[c]*m,_=this.colorA[c]*h,x=this.positionX[c],b=this.positionY[c],v=this.positionZ[c],S=e.x*d,w=e.y*d,M=e.z*d,L=r.x*d,A=r.y*d,T=r.z*d,I=[{x:x-S-L,y:b-w-A,z:v-M-T},{x:x+S-L,y:b+w-A,z:v+M-T},{x:x-S+L,y:b-w+A,z:v-M+T},{x:x+S+L,y:b+w+A,z:v+M+T}],z=[[0,1],[1,1],[0,0],[1,0]];I.forEach((C,V)=>{n.push(C.x,C.y,C.z,z[V]?.[0]??0,z[V]?.[1]??0,g,p,y,_)}),i.push(f,f+1,f+2,f+2,f+1,f+3)}l>0&&s.push({blendMode:a,start:u,count:i.length-u})};return o("alpha"),o("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:s}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},cc=`#version 300 es
554
+ }`,Ls=class{constructor(e,r,n,i){this.gl=e,this.geometry=sc(r),this.vertexBuffer=new Te(e,e.STATIC_DRAW),this.indexBuffer=new xe(e,e.STATIC_DRAW),this.vertexArray=new Re(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=oc(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},ba=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(s=>{this.surfaces.set(s.name,new Ls(e,s,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},xa=class{constructor(e){this.gl=e,this.program=Le.create(e,{vertex:ac,fragment:lc},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],s=r?.renderMode,o=r?.brightness??1,a=r?.gamma??1,u=r?.fullbright??!1,l=r?.globalAmbient??0;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let c=0,f=[1,1,1,1];if(s&&(s.mode==="solid"||s.mode==="wireframe"?c=1:s.mode==="solid-faceted"&&(c=2),s.color&&(f=[...s.color])),this.gl.uniform1i(this.uniformRenderMode,c),this.gl.uniform4f(this.uniformSolidColor,f[0],f[1],f[2],f[3]),this.gl.uniform1f(this.uniformBrightness,o),this.gl.uniform1f(this.uniformGamma,a),this.gl.uniform1i(this.uniformFullbright,u?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,l),e.vertexArray.bind(),s&&s.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new xe(this.gl,this.gl.STATIC_DRAW);let d=ti(e.geometry.indices);e.wireframeIndexBuffer.upload(d),e.wireframeIndexCount=d.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var J1=[1,1,1,1],_a=class{constructor(e,r){this.maxParticles=e,this.rng=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??J1,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let s=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=s,this.velocityY[i]*=s,this.velocityZ[i]=this.velocityZ[i]*s-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha"}}buildMesh(e,r){let n=[],i=[],s=[],o=a=>{let u=i.length,l=0;for(let c=0;c<this.maxParticles;c+=1){if(!this.alive[c]||(a==="additive"?1:0)!==this.blendMode[c])continue;l+=1;let f=n.length/9,d=this.size[c]*.5,h=this.fade[c]?Math.max(this.remaining[c]/this.lifetime[c],0):1,m=this.blendMode[c]===1?1.2:1,g=this.colorR[c]*m,p=this.colorG[c]*m,y=this.colorB[c]*m,_=this.colorA[c]*h,x=this.positionX[c],b=this.positionY[c],v=this.positionZ[c],S=e.x*d,w=e.y*d,M=e.z*d,L=r.x*d,A=r.y*d,T=r.z*d,I=[{x:x-S-L,y:b-w-A,z:v-M-T},{x:x+S-L,y:b+w-A,z:v+M-T},{x:x-S+L,y:b-w+A,z:v-M+T},{x:x+S+L,y:b+w+A,z:v+M+T}],z=[[0,1],[1,1],[0,0],[1,0]];I.forEach((C,V)=>{n.push(C.x,C.y,C.z,z[V]?.[0]??0,z[V]?.[1]??0,g,p,y,_)}),i.push(f,f+1,f+2,f+2,f+1,f+3)}l>0&&s.push({blendMode:a,start:u,count:i.length-u})};return o("alpha"),o("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:s}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},cc=`#version 300 es
555
555
  precision highp float;
556
556
 
557
557
  layout(location = 0) in vec3 a_position;
@@ -579,7 +579,7 @@ void main() {
579
579
  float dist = distance(v_uv, vec2(0.5));
580
580
  float alpha = v_color.a * (1.0 - smoothstep(0.35, 0.5, dist));
581
581
  o_color = vec4(v_color.rgb, alpha);
582
- }`,va=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=Le.create(e,{vertex:cc,fragment:uc}),this.vertexBuffer=new Te(e,e.DYNAMIC_DRAW),this.indexBuffer=new xe(e,e.DYNAMIC_DRAW),this.vertexArray=new Re(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let i=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(i,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(i),this.gl.depthMask(!1),this.program.use();let s=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(s,!1,e.viewProjection),this.vertexArray.bind();for(let o of r.batches)o.blendMode==="additive"?this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.drawElements(this.gl.TRIANGLES,o.count,this.gl.UNSIGNED_SHORT,o.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function Zd(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let s=200+e.rng.frandom()*180,o=e.rng.frandom()*.35;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*80,y:n.y*s+(e.rng.frandom()-.5)*80,z:Math.max(n.z*s,120)+o*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.rng.frandom()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*40,y:(e.rng.frandom()-.5)*40,z:80+e.rng.frandom()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function Yd(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.rng.frandom()*Math.PI*2,s=Math.acos(2*e.rng.frandom()-1),o=220+e.rng.frandom()*260,a={x:Math.sin(s)*Math.cos(i),y:Math.sin(s)*Math.sin(i),z:Math.cos(s)};e.spawn({position:r,velocity:{x:a.x*o,y:a.y*o,z:a.z*o},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*30,y:(e.rng.frandom()-.5)*30,z:120+e.rng.frandom()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function qd(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let i=0;i<24;i+=1){let s=120+e.rng.frandom()*180;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*70,y:n.y*s+(e.rng.frandom()-.5)*70,z:n.z*s+e.rng.frandom()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function jd(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let i=e.rng.frandom()*Math.PI*2,s=8+e.rng.frandom()*8;e.spawn({position:r,velocity:{x:Math.cos(i)*s,y:Math.sin(i)*s,z:100+e.rng.frandom()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function Qd(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let i=0;i<10;i+=1){let s=350+e.rng.frandom()*100;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*30,y:n.y*s+(e.rng.frandom()-.5)*30,z:n.z*s+(e.rng.frandom()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function Jd(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let i=0;i<6;i+=1)e.spawn({position:{x:r.x+n.x*i*2,y:r.y+n.y*i*2,z:r.z+n.z*i*2},velocity:{x:(e.rng.frandom()-.5)*15,y:(e.rng.frandom()-.5)*15,z:20+e.rng.frandom()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}function ef(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<30;i+=1){let s=100+e.rng.frandom()*150;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*80,y:n.y*s+(e.rng.frandom()-.5)*80,z:100+e.rng.frandom()*120},color:[.5,.6,.8,.5],size:3,lifetime:.5+e.rng.frandom()*.3,gravity:800,damping:1.5,blendMode:"alpha",fade:!0})}}function tf(t){let{system:e,origin:r}=t;for(let n=0;n<8;n+=1)e.spawn({position:{x:r.x+(e.rng.frandom()-.5)*10,y:r.y+(e.rng.frandom()-.5)*10,z:r.z+(e.rng.frandom()-.5)*10},velocity:{x:(e.rng.frandom()-.5)*20,y:(e.rng.frandom()-.5)*20,z:40+e.rng.frandom()*20},color:[.8,.8,.8,.3],size:5+e.rng.frandom()*4,lifetime:1.5+e.rng.frandom()*.5,gravity:-50,damping:.5,blendMode:"alpha",fade:!0})}var je=class{constructor(e){this.messageOffsets=[];this.currentBlock=null;this.buffer=e,this.view=new DataView(e),this.offset=0,this.scan()}scan(){let e=0;for(this.messageOffsets=[];e+4<=this.buffer.byteLength;){let r=this.view.getInt32(e,!0);if(r===-1)break;if(r<0||r>2097152){console.warn(`DemoReader: Invalid block length ${r} at offset ${e} during scan`);break}if(e+4+r>this.buffer.byteLength){console.warn(`DemoReader: Incomplete block at offset ${e} during scan`);break}this.messageOffsets.push(e),e+=4+r}}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(e===-1||e<0||this.offset+4+e>this.buffer.byteLength)return null;this.offset+=4;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new vn(r)}}nextBlock(){let e=this.readNextBlock();return e?(this.currentBlock=e,!0):(this.currentBlock=null,!1)}getBlock(){if(!this.currentBlock)throw new Error("No current block. Call nextBlock() first.");return this.currentBlock}readAllBlocksToBuffer(){let e=0,r=this.offset,n=[],i=this.offset;for(;i+4<=this.buffer.byteLength;){let u=this.view.getInt32(i,!0);if(u===-1||u<0||i+4+u>this.buffer.byteLength)break;n.push({offset:i+4,length:u}),e+=u,i+=4+u}let s=new Uint8Array(e),o=0,a=new Uint8Array(this.buffer);for(let u of n)s.set(a.subarray(u.offset,u.offset+u.length),o),o+=u.length;return this.offset=i,s.buffer}reset(){this.offset=0,this.currentBlock=null}seekToMessage(e){return e<0||e>=this.messageOffsets.length?!1:(this.offset=this.messageOffsets[e],this.currentBlock=null,!0)}getMessageCount(){return this.messageOffsets.length}getOffset(){return this.offset}getProgress(){let e=this.offset,r=this.buffer.byteLength;return{current:e,total:r,percent:r>0?e/r*100:0}}};function ci(t){let e=t.length;for(;--e>=0;)t[e]=0}var eg=0,Hf=1,tg=2,rg=3,ng=258,zc=29,Vs=256,zs=Vs+1+zc,oi=30,Pc=19,Vf=2*zs+1,an=15,dc=16,ig=7,Dc=256,Gf=16,Wf=17,Xf=18,Mc=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),La=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),sg=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Kf=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),og=512,Nt=new Array((zs+2)*2);ci(Nt);var Is=new Array(oi*2);ci(Is);var Ps=new Array(og);ci(Ps);var Ds=new Array(ng-rg+1);ci(Ds);var Bc=new Array(zc);ci(Bc);var Ta=new Array(oi);ci(Ta);function fc(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}var $f,Zf,Yf;function hc(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}var qf=t=>t<256?Ps[t]:Ps[256+(t>>>7)],Bs=(t,e)=>{t.pending_buf[t.pending++]=e&255,t.pending_buf[t.pending++]=e>>>8&255},Fe=(t,e,r)=>{t.bi_valid>dc-r?(t.bi_buf|=e<<t.bi_valid&65535,Bs(t,t.bi_buf),t.bi_buf=e>>dc-t.bi_valid,t.bi_valid+=r-dc):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=r)},pt=(t,e,r)=>{Fe(t,r[e*2],r[e*2+1])},jf=(t,e)=>{let r=0;do r|=t&1,t>>>=1,r<<=1;while(--e>0);return r>>>1},ag=t=>{t.bi_valid===16?(Bs(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=t.bi_buf&255,t.bi_buf>>=8,t.bi_valid-=8)},lg=(t,e)=>{let r=e.dyn_tree,n=e.max_code,i=e.stat_desc.static_tree,s=e.stat_desc.has_stree,o=e.stat_desc.extra_bits,a=e.stat_desc.extra_base,u=e.stat_desc.max_length,l,c,f,d,h,m,g=0;for(d=0;d<=an;d++)t.bl_count[d]=0;for(r[t.heap[t.heap_max]*2+1]=0,l=t.heap_max+1;l<Vf;l++)c=t.heap[l],d=r[r[c*2+1]*2+1]+1,d>u&&(d=u,g++),r[c*2+1]=d,!(c>n)&&(t.bl_count[d]++,h=0,c>=a&&(h=o[c-a]),m=r[c*2],t.opt_len+=m*(d+h),s&&(t.static_len+=m*(i[c*2+1]+h)));if(g!==0){do{for(d=u-1;t.bl_count[d]===0;)d--;t.bl_count[d]--,t.bl_count[d+1]+=2,t.bl_count[u]--,g-=2}while(g>0);for(d=u;d!==0;d--)for(c=t.bl_count[d];c!==0;)f=t.heap[--l],!(f>n)&&(r[f*2+1]!==d&&(t.opt_len+=(d-r[f*2+1])*r[f*2],r[f*2+1]=d),c--)}},Qf=(t,e,r)=>{let n=new Array(an+1),i=0,s,o;for(s=1;s<=an;s++)i=i+r[s-1]<<1,n[s]=i;for(o=0;o<=e;o++){let a=t[o*2+1];a!==0&&(t[o*2]=jf(n[a]++,a))}},cg=()=>{let t,e,r,n,i,s=new Array(an+1);for(r=0,n=0;n<zc-1;n++)for(Bc[n]=r,t=0;t<1<<Mc[n];t++)Ds[r++]=n;for(Ds[r-1]=n,i=0,n=0;n<16;n++)for(Ta[n]=i,t=0;t<1<<La[n];t++)Ps[i++]=n;for(i>>=7;n<oi;n++)for(Ta[n]=i<<7,t=0;t<1<<La[n]-7;t++)Ps[256+i++]=n;for(e=0;e<=an;e++)s[e]=0;for(t=0;t<=143;)Nt[t*2+1]=8,t++,s[8]++;for(;t<=255;)Nt[t*2+1]=9,t++,s[9]++;for(;t<=279;)Nt[t*2+1]=7,t++,s[7]++;for(;t<=287;)Nt[t*2+1]=8,t++,s[8]++;for(Qf(Nt,zs+1,s),t=0;t<oi;t++)Is[t*2+1]=5,Is[t*2]=jf(t,5);$f=new fc(Nt,Mc,Vs+1,zs,an),Zf=new fc(Is,La,0,oi,an),Yf=new fc(new Array(0),sg,0,Pc,ig)},Jf=t=>{let e;for(e=0;e<zs;e++)t.dyn_ltree[e*2]=0;for(e=0;e<oi;e++)t.dyn_dtree[e*2]=0;for(e=0;e<Pc;e++)t.bl_tree[e*2]=0;t.dyn_ltree[Dc*2]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},eh=t=>{t.bi_valid>8?Bs(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},rf=(t,e,r,n)=>{let i=e*2,s=r*2;return t[i]<t[s]||t[i]===t[s]&&n[e]<=n[r]},mc=(t,e,r)=>{let n=t.heap[r],i=r<<1;for(;i<=t.heap_len&&(i<t.heap_len&&rf(e,t.heap[i+1],t.heap[i],t.depth)&&i++,!rf(e,n,t.heap[i],t.depth));)t.heap[r]=t.heap[i],r=i,i<<=1;t.heap[r]=n},nf=(t,e,r)=>{let n,i,s=0,o,a;if(t.sym_next!==0)do n=t.pending_buf[t.sym_buf+s++]&255,n+=(t.pending_buf[t.sym_buf+s++]&255)<<8,i=t.pending_buf[t.sym_buf+s++],n===0?pt(t,i,e):(o=Ds[i],pt(t,o+Vs+1,e),a=Mc[o],a!==0&&(i-=Bc[o],Fe(t,i,a)),n--,o=qf(n),pt(t,o,r),a=La[o],a!==0&&(n-=Ta[o],Fe(t,n,a)));while(s<t.sym_next);pt(t,Dc,e)},Ec=(t,e)=>{let r=e.dyn_tree,n=e.stat_desc.static_tree,i=e.stat_desc.has_stree,s=e.stat_desc.elems,o,a,u=-1,l;for(t.heap_len=0,t.heap_max=Vf,o=0;o<s;o++)r[o*2]!==0?(t.heap[++t.heap_len]=u=o,t.depth[o]=0):r[o*2+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=u<2?++u:0,r[l*2]=1,t.depth[l]=0,t.opt_len--,i&&(t.static_len-=n[l*2+1]);for(e.max_code=u,o=t.heap_len>>1;o>=1;o--)mc(t,r,o);l=s;do o=t.heap[1],t.heap[1]=t.heap[t.heap_len--],mc(t,r,1),a=t.heap[1],t.heap[--t.heap_max]=o,t.heap[--t.heap_max]=a,r[l*2]=r[o*2]+r[a*2],t.depth[l]=(t.depth[o]>=t.depth[a]?t.depth[o]:t.depth[a])+1,r[o*2+1]=r[a*2+1]=l,t.heap[1]=l++,mc(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],lg(t,e),Qf(r,u,t.bl_count)},sf=(t,e,r)=>{let n,i=-1,s,o=e[1],a=0,u=7,l=4;for(o===0&&(u=138,l=3),e[(r+1)*2+1]=65535,n=0;n<=r;n++)s=o,o=e[(n+1)*2+1],!(++a<u&&s===o)&&(a<l?t.bl_tree[s*2]+=a:s!==0?(s!==i&&t.bl_tree[s*2]++,t.bl_tree[Gf*2]++):a<=10?t.bl_tree[Wf*2]++:t.bl_tree[Xf*2]++,a=0,i=s,o===0?(u=138,l=3):s===o?(u=6,l=3):(u=7,l=4))},of=(t,e,r)=>{let n,i=-1,s,o=e[1],a=0,u=7,l=4;for(o===0&&(u=138,l=3),n=0;n<=r;n++)if(s=o,o=e[(n+1)*2+1],!(++a<u&&s===o)){if(a<l)do pt(t,s,t.bl_tree);while(--a!==0);else s!==0?(s!==i&&(pt(t,s,t.bl_tree),a--),pt(t,Gf,t.bl_tree),Fe(t,a-3,2)):a<=10?(pt(t,Wf,t.bl_tree),Fe(t,a-3,3)):(pt(t,Xf,t.bl_tree),Fe(t,a-11,7));a=0,i=s,o===0?(u=138,l=3):s===o?(u=6,l=3):(u=7,l=4)}},ug=t=>{let e;for(sf(t,t.dyn_ltree,t.l_desc.max_code),sf(t,t.dyn_dtree,t.d_desc.max_code),Ec(t,t.bl_desc),e=Pc-1;e>=3&&t.bl_tree[Kf[e]*2+1]===0;e--);return t.opt_len+=3*(e+1)+5+5+4,e},dg=(t,e,r,n)=>{let i;for(Fe(t,e-257,5),Fe(t,r-1,5),Fe(t,n-4,4),i=0;i<n;i++)Fe(t,t.bl_tree[Kf[i]*2+1],3);of(t,t.dyn_ltree,e-1),of(t,t.dyn_dtree,r-1)},fg=t=>{let e=4093624447,r;for(r=0;r<=31;r++,e>>>=1)if(e&1&&t.dyn_ltree[r*2]!==0)return 0;if(t.dyn_ltree[18]!==0||t.dyn_ltree[20]!==0||t.dyn_ltree[26]!==0)return 1;for(r=32;r<Vs;r++)if(t.dyn_ltree[r*2]!==0)return 1;return 0},af=!1,hg=t=>{af||(cg(),af=!0),t.l_desc=new hc(t.dyn_ltree,$f),t.d_desc=new hc(t.dyn_dtree,Zf),t.bl_desc=new hc(t.bl_tree,Yf),t.bi_buf=0,t.bi_valid=0,Jf(t)},th=(t,e,r,n)=>{Fe(t,(eg<<1)+(n?1:0),3),eh(t),Bs(t,r),Bs(t,~r),r&&t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r},mg=t=>{Fe(t,Hf<<1,3),pt(t,Dc,Nt),ag(t)},pg=(t,e,r,n)=>{let i,s,o=0;t.level>0?(t.strm.data_type===2&&(t.strm.data_type=fg(t)),Ec(t,t.l_desc),Ec(t,t.d_desc),o=ug(t),i=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=i&&(i=s)):i=s=r+5,r+4<=i&&e!==-1?th(t,e,r,n):t.strategy===4||s===i?(Fe(t,(Hf<<1)+(n?1:0),3),nf(t,Nt,Is)):(Fe(t,(tg<<1)+(n?1:0),3),dg(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),nf(t,t.dyn_ltree,t.dyn_dtree)),Jf(t),n&&eh(t)},gg=(t,e,r)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=r,e===0?t.dyn_ltree[r*2]++:(t.matches++,e--,t.dyn_ltree[(Ds[r]+Vs+1)*2]++,t.dyn_dtree[qf(e)*2]++),t.sym_next===t.sym_end),yg=hg,bg=th,xg=pg,_g=gg,vg=mg,wg={_tr_init:yg,_tr_stored_block:bg,_tr_flush_block:xg,_tr_tally:_g,_tr_align:vg},Sg=(t,e,r,n)=>{let i=t&65535|0,s=t>>>16&65535|0,o=0;for(;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+e[n++]|0,s=s+i|0;while(--o);i%=65521,s%=65521}return i|s<<16|0},Os=Sg,Ag=()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;e[r]=t}return e},Mg=new Uint32Array(Ag()),Eg=(t,e,r,n)=>{let i=Mg,s=n+r;t^=-1;for(let o=n;o<s;o++)t=t>>>8^i[(t^e[o])&255];return t^-1},he=Eg,un={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},hn={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:Lg,_tr_stored_block:Lc,_tr_flush_block:Tg,_tr_tally:hr,_tr_align:kg}=wg,{Z_NO_FLUSH:mr,Z_PARTIAL_FLUSH:Cg,Z_FULL_FLUSH:Ig,Z_FINISH:Qe,Z_BLOCK:lf,Z_OK:me,Z_STREAM_END:cf,Z_STREAM_ERROR:gt,Z_DATA_ERROR:Rg,Z_BUF_ERROR:pc,Z_DEFAULT_COMPRESSION:Fg,Z_FILTERED:zg,Z_HUFFMAN_ONLY:wa,Z_RLE:Pg,Z_FIXED:Dg,Z_DEFAULT_STRATEGY:Bg,Z_UNKNOWN:Og,Z_DEFLATED:Ia}=hn,Ng=9,Ug=15,Hg=8,Vg=29,Gg=256,Tc=Gg+1+Vg,Wg=30,Xg=19,Kg=2*Tc+1,$g=15,W=3,fr=258,yt=fr+W+1,Zg=32,ai=42,Oc=57,kc=69,Cc=73,Ic=91,Rc=103,ln=113,ks=666,ke=1,ui=2,dn=3,di=4,Yg=3,cn=(t,e)=>(t.msg=un[e],e),uf=t=>t*2-(t>4?9:0),dr=t=>{let e=t.length;for(;--e>=0;)t[e]=0},qg=t=>{let e,r,n,i=t.w_size;e=t.hash_size,n=e;do r=t.head[--n],t.head[n]=r>=i?r-i:0;while(--e);e=i,n=e;do r=t.prev[--n],t.prev[n]=r>=i?r-i:0;while(--e)},jg=(t,e,r)=>(e<<t.hash_shift^r)&t.hash_mask,pr=jg,Ne=t=>{let e=t.state,r=e.pending;r>t.avail_out&&(r=t.avail_out),r!==0&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,e.pending===0&&(e.pending_out=0))},Ue=(t,e)=>{Tg(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Ne(t.strm)},Z=(t,e)=>{t.pending_buf[t.pending++]=e},Ts=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=e&255},Fc=(t,e,r,n)=>{let i=t.avail_in;return i>n&&(i=n),i===0?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),t.state.wrap===1?t.adler=Os(t.adler,e,i,r):t.state.wrap===2&&(t.adler=he(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},rh=(t,e)=>{let r=t.max_chain_length,n=t.strstart,i,s,o=t.prev_length,a=t.nice_match,u=t.strstart>t.w_size-yt?t.strstart-(t.w_size-yt):0,l=t.window,c=t.w_mask,f=t.prev,d=t.strstart+fr,h=l[n+o-1],m=l[n+o];t.prev_length>=t.good_match&&(r>>=2),a>t.lookahead&&(a=t.lookahead);do if(i=e,!(l[i+o]!==m||l[i+o-1]!==h||l[i]!==l[n]||l[++i]!==l[n+1])){n+=2,i++;do;while(l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&n<d);if(s=fr-(d-n),n=d-fr,s>o){if(t.match_start=e,o=s,s>=a)break;h=l[n+o-1],m=l[n+o]}}while((e=f[e&c])>u&&--r!==0);return o<=t.lookahead?o:t.lookahead},li=t=>{let e=t.w_size,r,n,i;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-yt)&&(t.window.set(t.window.subarray(e,e+e-n),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),qg(t),n+=e),t.strm.avail_in===0)break;if(r=Fc(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=r,t.lookahead+t.insert>=W)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=pr(t,t.ins_h,t.window[i+1]);t.insert&&(t.ins_h=pr(t,t.ins_h,t.window[i+W-1]),t.prev[i&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=i,i++,t.insert--,!(t.lookahead+t.insert<W)););}while(t.lookahead<yt&&t.strm.avail_in!==0)},nh=(t,e)=>{let r=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,n,i,s,o=0,a=t.strm.avail_in;do{if(n=65535,s=t.bi_valid+42>>3,t.strm.avail_out<s||(s=t.strm.avail_out-s,i=t.strstart-t.block_start,n>i+t.strm.avail_in&&(n=i+t.strm.avail_in),n>s&&(n=s),n<r&&(n===0&&e!==Qe||e===mr||n!==i+t.strm.avail_in)))break;o=e===Qe&&n===i+t.strm.avail_in?1:0,Lc(t,0,0,o),t.pending_buf[t.pending-4]=n,t.pending_buf[t.pending-3]=n>>8,t.pending_buf[t.pending-2]=~n,t.pending_buf[t.pending-1]=~n>>8,Ne(t.strm),i&&(i>n&&(i=n),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,n-=i),n&&(Fc(t.strm,t.strm.output,t.strm.next_out,n),t.strm.next_out+=n,t.strm.avail_out-=n,t.strm.total_out+=n)}while(o===0);return a-=t.strm.avail_in,a&&(a>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=a&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-a,t.strm.next_in),t.strstart),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),o?di:e!==mr&&e!==Qe&&t.strm.avail_in===0&&t.strstart===t.block_start?ui:(s=t.window_size-t.strstart,t.strm.avail_in>s&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,s+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),s>t.strm.avail_in&&(s=t.strm.avail_in),s&&(Fc(t.strm,t.window,t.strstart,s),t.strstart+=s,t.insert+=s>t.w_size-t.insert?t.w_size-t.insert:s),t.high_water<t.strstart&&(t.high_water=t.strstart),s=t.bi_valid+42>>3,s=t.pending_buf_size-s>65535?65535:t.pending_buf_size-s,r=s>t.w_size?t.w_size:s,i=t.strstart-t.block_start,(i>=r||(i||e===Qe)&&e!==mr&&t.strm.avail_in===0&&i<=s)&&(n=i>s?s:i,o=e===Qe&&t.strm.avail_in===0&&n===i?1:0,Lc(t,t.block_start,n,o),t.block_start+=n,Ne(t.strm)),o?dn:ke)},gc=(t,e)=>{let r,n;for(;;){if(t.lookahead<yt){if(li(t),t.lookahead<yt&&e===mr)return ke;if(t.lookahead===0)break}if(r=0,t.lookahead>=W&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),r!==0&&t.strstart-r<=t.w_size-yt&&(t.match_length=rh(t,r)),t.match_length>=W)if(n=hr(t,t.strstart-t.match_start,t.match_length-W),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=W){t.match_length--;do t.strstart++,t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart;while(--t.match_length!==0);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=pr(t,t.ins_h,t.window[t.strstart+1]);else n=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=t.strstart<W-1?t.strstart:W-1,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},ii=(t,e)=>{let r,n,i;for(;;){if(t.lookahead<yt){if(li(t),t.lookahead<yt&&e===mr)return ke;if(t.lookahead===0)break}if(r=0,t.lookahead>=W&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=W-1,r!==0&&t.prev_length<t.max_lazy_match&&t.strstart-r<=t.w_size-yt&&(t.match_length=rh(t,r),t.match_length<=5&&(t.strategy===zg||t.match_length===W&&t.strstart-t.match_start>4096)&&(t.match_length=W-1)),t.prev_length>=W&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-W,n=hr(t,t.strstart-1-t.prev_match,t.prev_length-W),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=i&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart);while(--t.prev_length!==0);if(t.match_available=0,t.match_length=W-1,t.strstart++,n&&(Ue(t,!1),t.strm.avail_out===0))return ke}else if(t.match_available){if(n=hr(t,0,t.window[t.strstart-1]),n&&Ue(t,!1),t.strstart++,t.lookahead--,t.strm.avail_out===0)return ke}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=hr(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<W-1?t.strstart:W-1,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},Qg=(t,e)=>{let r,n,i,s,o=t.window;for(;;){if(t.lookahead<=fr){if(li(t),t.lookahead<=fr&&e===mr)return ke;if(t.lookahead===0)break}if(t.match_length=0,t.lookahead>=W&&t.strstart>0&&(i=t.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){s=t.strstart+fr;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<s);t.match_length=fr-(s-i),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=W?(r=hr(t,1,t.match_length-W),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=0,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},Jg=(t,e)=>{let r;for(;;){if(t.lookahead===0&&(li(t),t.lookahead===0)){if(e===mr)return ke;break}if(t.match_length=0,r=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=0,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui};function mt(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Cs=[new mt(0,0,0,0,nh),new mt(4,4,8,4,gc),new mt(4,5,16,8,gc),new mt(4,6,32,32,gc),new mt(4,4,16,16,ii),new mt(8,16,32,32,ii),new mt(8,16,128,128,ii),new mt(8,32,128,256,ii),new mt(32,128,258,1024,ii),new mt(32,258,258,4096,ii)],ey=t=>{t.window_size=2*t.w_size,dr(t.head),t.max_lazy_match=Cs[t.level].max_lazy,t.good_match=Cs[t.level].good_length,t.nice_match=Cs[t.level].nice_length,t.max_chain_length=Cs[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=W-1,t.match_available=0,t.ins_h=0};function ty(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ia,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(Kg*2),this.dyn_dtree=new Uint16Array((2*Wg+1)*2),this.bl_tree=new Uint16Array((2*Xg+1)*2),dr(this.dyn_ltree),dr(this.dyn_dtree),dr(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array($g+1),this.heap=new Uint16Array(2*Tc+1),dr(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*Tc+1),dr(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Gs=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.status!==ai&&e.status!==Oc&&e.status!==kc&&e.status!==Cc&&e.status!==Ic&&e.status!==Rc&&e.status!==ln&&e.status!==ks?1:0},ih=t=>{if(Gs(t))return cn(t,gt);t.total_in=t.total_out=0,t.data_type=Og;let e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap===2?Oc:e.wrap?ai:ln,t.adler=e.wrap===2?0:1,e.last_flush=-2,Lg(e),me},sh=t=>{let e=ih(t);return e===me&&ey(t.state),e},ry=(t,e)=>Gs(t)||t.state.wrap!==2?gt:(t.state.gzhead=e,me),oh=(t,e,r,n,i,s)=>{if(!t)return gt;let o=1;if(e===Fg&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>Ng||r!==Ia||n<8||n>15||e<0||e>9||s<0||s>Dg||n===8&&o!==1)return cn(t,gt);n===8&&(n=9);let a=new ty;return t.state=a,a.strm=t,a.status=ai,a.wrap=o,a.gzhead=null,a.w_bits=n,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=i+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+W-1)/W),a.window=new Uint8Array(a.w_size*2),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<i+6,a.pending_buf_size=a.lit_bufsize*4,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=(a.lit_bufsize-1)*3,a.level=e,a.strategy=s,a.method=r,sh(t)},ny=(t,e)=>oh(t,e,Ia,Ug,Hg,Bg),iy=(t,e)=>{if(Gs(t)||e>lf||e<0)return t?cn(t,gt):gt;let r=t.state;if(!t.output||t.avail_in!==0&&!t.input||r.status===ks&&e!==Qe)return cn(t,t.avail_out===0?pc:gt);let n=r.last_flush;if(r.last_flush=e,r.pending!==0){if(Ne(t),t.avail_out===0)return r.last_flush=-1,me}else if(t.avail_in===0&&uf(e)<=uf(n)&&e!==Qe)return cn(t,pc);if(r.status===ks&&t.avail_in!==0)return cn(t,pc);if(r.status===ai&&r.wrap===0&&(r.status=ln),r.status===ai){let i=Ia+(r.w_bits-8<<4)<<8,s=-1;if(r.strategy>=wa||r.level<2?s=0:r.level<6?s=1:r.level===6?s=2:s=3,i|=s<<6,r.strstart!==0&&(i|=Zg),i+=31-i%31,Ts(r,i),r.strstart!==0&&(Ts(r,t.adler>>>16),Ts(r,t.adler&65535)),t.adler=1,r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(r.status===Oc){if(t.adler=0,Z(r,31),Z(r,139),Z(r,8),r.gzhead)Z(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Z(r,r.gzhead.time&255),Z(r,r.gzhead.time>>8&255),Z(r,r.gzhead.time>>16&255),Z(r,r.gzhead.time>>24&255),Z(r,r.level===9?2:r.strategy>=wa||r.level<2?4:0),Z(r,r.gzhead.os&255),r.gzhead.extra&&r.gzhead.extra.length&&(Z(r,r.gzhead.extra.length&255),Z(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=he(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=kc;else if(Z(r,0),Z(r,0),Z(r,0),Z(r,0),Z(r,0),Z(r,r.level===9?2:r.strategy>=wa||r.level<2?4:0),Z(r,Yg),r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(r.status===kc){if(r.gzhead.extra){let i=r.pending,s=(r.gzhead.extra.length&65535)-r.gzindex;for(;r.pending+s>r.pending_buf_size;){let a=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+a),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex+=a,Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0,s-=a}let o=new Uint8Array(r.gzhead.extra);r.pending_buf.set(o.subarray(r.gzindex,r.gzindex+s),r.pending),r.pending+=s,r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Cc}if(r.status===Cc){if(r.gzhead.name){let i=r.pending,s;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0}r.gzindex<r.gzhead.name.length?s=r.gzhead.name.charCodeAt(r.gzindex++)&255:s=0,Z(r,s)}while(s!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Ic}if(r.status===Ic){if(r.gzhead.comment){let i=r.pending,s;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0}r.gzindex<r.gzhead.comment.length?s=r.gzhead.comment.charCodeAt(r.gzindex++)&255:s=0,Z(r,s)}while(s!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i))}r.status=Rc}if(r.status===Rc){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&(Ne(t),r.pending!==0))return r.last_flush=-1,me;Z(r,t.adler&255),Z(r,t.adler>>8&255),t.adler=0}if(r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(t.avail_in!==0||r.lookahead!==0||e!==mr&&r.status!==ks){let i=r.level===0?nh(r,e):r.strategy===wa?Jg(r,e):r.strategy===Pg?Qg(r,e):Cs[r.level].func(r,e);if((i===dn||i===di)&&(r.status=ks),i===ke||i===dn)return t.avail_out===0&&(r.last_flush=-1),me;if(i===ui&&(e===Cg?kg(r):e!==lf&&(Lc(r,0,0,!1),e===Ig&&(dr(r.head),r.lookahead===0&&(r.strstart=0,r.block_start=0,r.insert=0))),Ne(t),t.avail_out===0))return r.last_flush=-1,me}return e!==Qe?me:r.wrap<=0?cf:(r.wrap===2?(Z(r,t.adler&255),Z(r,t.adler>>8&255),Z(r,t.adler>>16&255),Z(r,t.adler>>24&255),Z(r,t.total_in&255),Z(r,t.total_in>>8&255),Z(r,t.total_in>>16&255),Z(r,t.total_in>>24&255)):(Ts(r,t.adler>>>16),Ts(r,t.adler&65535)),Ne(t),r.wrap>0&&(r.wrap=-r.wrap),r.pending!==0?me:cf)},sy=t=>{if(Gs(t))return gt;let e=t.state.status;return t.state=null,e===ln?cn(t,Rg):me},oy=(t,e)=>{let r=e.length;if(Gs(t))return gt;let n=t.state,i=n.wrap;if(i===2||i===1&&n.status!==ai||n.lookahead)return gt;if(i===1&&(t.adler=Os(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){i===0&&(dr(n.head),n.strstart=0,n.block_start=0,n.insert=0);let u=new Uint8Array(n.w_size);u.set(e.subarray(r-n.w_size,r),0),e=u,r=n.w_size}let s=t.avail_in,o=t.next_in,a=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,li(n);n.lookahead>=W;){let u=n.strstart,l=n.lookahead-(W-1);do n.ins_h=pr(n,n.ins_h,n.window[u+W-1]),n.prev[u&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=u,u++;while(--l);n.strstart=u,n.lookahead=W-1,li(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=W-1,n.match_available=0,t.next_in=o,t.input=a,t.avail_in=s,n.wrap=i,me},ay=ny,ly=oh,cy=sh,uy=ih,dy=ry,fy=iy,hy=sy,my=oy,py="pako deflate (from Nodeca project)",Rs={deflateInit:ay,deflateInit2:ly,deflateReset:cy,deflateResetKeep:uy,deflateSetHeader:dy,deflate:fy,deflateEnd:hy,deflateSetDictionary:my,deflateInfo:py},gy=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),yy=function(t){let e=Array.prototype.slice.call(arguments,1);for(;e.length;){let r=e.shift();if(r){if(typeof r!="object")throw new TypeError(r+"must be non-object");for(let n in r)gy(r,n)&&(t[n]=r[n])}}return t},by=t=>{let e=0;for(let n=0,i=t.length;n<i;n++)e+=t[n].length;let r=new Uint8Array(e);for(let n=0,i=0,s=t.length;n<s;n++){let o=t[n];r.set(o,i),i+=o.length}return r},Ra={assign:yy,flattenChunks:by},ah=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{ah=!1}var Ns=new Uint8Array(256);for(let t=0;t<256;t++)Ns[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ns[254]=Ns[254]=1;var xy=t=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(t);let e,r,n,i,s,o=t.length,a=0;for(i=0;i<o;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),a+=r<128?1:r<2048?2:r<65536?3:4;for(e=new Uint8Array(a),s=0,i=0;s<a;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),r<128?e[s++]=r:r<2048?(e[s++]=192|r>>>6,e[s++]=128|r&63):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|r&63):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|r&63);return e},_y=(t,e)=>{if(e<65534&&t.subarray&&ah)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let n=0;n<e;n++)r+=String.fromCharCode(t[n]);return r},vy=(t,e)=>{let r=e||t.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(t.subarray(0,e));let n,i,s=new Array(r*2);for(i=0,n=0;n<r;){let o=t[n++];if(o<128){s[i++]=o;continue}let a=Ns[o];if(a>4){s[i++]=65533,n+=a-1;continue}for(o&=a===2?31:a===3?15:7;a>1&&n<r;)o=o<<6|t[n++]&63,a--;if(a>1){s[i++]=65533;continue}o<65536?s[i++]=o:(o-=65536,s[i++]=55296|o>>10&1023,s[i++]=56320|o&1023)}return _y(s,i)},wy=(t,e)=>{e=e||t.length,e>t.length&&(e=t.length);let r=e-1;for(;r>=0&&(t[r]&192)===128;)r--;return r<0||r===0?e:r+Ns[t[r]]>e?r:e},Us={string2buf:xy,buf2string:vy,utf8border:wy};function Sy(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var lh=Sy,ch=Object.prototype.toString,{Z_NO_FLUSH:Ay,Z_SYNC_FLUSH:My,Z_FULL_FLUSH:Ey,Z_FINISH:Ly,Z_OK:ka,Z_STREAM_END:Ty,Z_DEFAULT_COMPRESSION:ky,Z_DEFAULT_STRATEGY:Cy,Z_DEFLATED:Iy}=hn;function Ws(t){this.options=Ra.assign({level:ky,method:Iy,chunkSize:16384,windowBits:15,memLevel:8,strategy:Cy},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new lh,this.strm.avail_out=0;let r=Rs.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==ka)throw new Error(un[r]);if(e.header&&Rs.deflateSetHeader(this.strm,e.header),e.dictionary){let n;if(typeof e.dictionary=="string"?n=Us.string2buf(e.dictionary):ch.call(e.dictionary)==="[object ArrayBuffer]"?n=new Uint8Array(e.dictionary):n=e.dictionary,r=Rs.deflateSetDictionary(this.strm,n),r!==ka)throw new Error(un[r]);this._dict_set=!0}}Ws.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i,s;if(this.ended)return!1;for(e===~~e?s=e:s=e===!0?Ly:Ay,typeof t=="string"?r.input=Us.string2buf(t):ch.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){if(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(s===My||s===Ey)&&r.avail_out<=6){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(i=Rs.deflate(r,s),i===Ty)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=Rs.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===ka;if(r.avail_out===0){this.onData(r.output);continue}if(s>0&&r.next_out>0){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(r.avail_in===0)break}return!0};Ws.prototype.onData=function(t){this.chunks.push(t)};Ws.prototype.onEnd=function(t){t===ka&&(this.result=Ra.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Nc(t,e){let r=new Ws(e);if(r.push(t,!0),r.err)throw r.msg||un[r.err];return r.result}function Ry(t,e){return e=e||{},e.raw=!0,Nc(t,e)}function Fy(t,e){return e=e||{},e.gzip=!0,Nc(t,e)}var zy=Ws,Py=Nc,Dy=Ry,By=Fy,Oy=hn,Ny={Deflate:zy,deflate:Py,deflateRaw:Dy,gzip:By,constants:Oy},Sa=16209,Uy=16191,Hy=function(e,r){let n,i,s,o,a,u,l,c,f,d,h,m,g,p,y,_,x,b,v,S,w,M,L,A,T=e.state;n=e.next_in,L=e.input,i=n+(e.avail_in-5),s=e.next_out,A=e.output,o=s-(r-e.avail_out),a=s+(e.avail_out-257),u=T.dmax,l=T.wsize,c=T.whave,f=T.wnext,d=T.window,h=T.hold,m=T.bits,g=T.lencode,p=T.distcode,y=(1<<T.lenbits)-1,_=(1<<T.distbits)-1;e:do{m<15&&(h+=L[n++]<<m,m+=8,h+=L[n++]<<m,m+=8),x=g[h&y];t:for(;;){if(b=x>>>24,h>>>=b,m-=b,b=x>>>16&255,b===0)A[s++]=x&65535;else if(b&16){v=x&65535,b&=15,b&&(m<b&&(h+=L[n++]<<m,m+=8),v+=h&(1<<b)-1,h>>>=b,m-=b),m<15&&(h+=L[n++]<<m,m+=8,h+=L[n++]<<m,m+=8),x=p[h&_];r:for(;;){if(b=x>>>24,h>>>=b,m-=b,b=x>>>16&255,b&16){if(S=x&65535,b&=15,m<b&&(h+=L[n++]<<m,m+=8,m<b&&(h+=L[n++]<<m,m+=8)),S+=h&(1<<b)-1,S>u){e.msg="invalid distance too far back",T.mode=Sa;break e}if(h>>>=b,m-=b,b=s-o,S>b){if(b=S-b,b>c&&T.sane){e.msg="invalid distance too far back",T.mode=Sa;break e}if(w=0,M=d,f===0){if(w+=l-b,b<v){v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}}else if(f<b){if(w+=l+f-b,b-=f,b<v){v-=b;do A[s++]=d[w++];while(--b);if(w=0,f<v){b=f,v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}}}else if(w+=f-b,b<v){v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}for(;v>2;)A[s++]=M[w++],A[s++]=M[w++],A[s++]=M[w++],v-=3;v&&(A[s++]=M[w++],v>1&&(A[s++]=M[w++]))}else{w=s-S;do A[s++]=A[w++],A[s++]=A[w++],A[s++]=A[w++],v-=3;while(v>2);v&&(A[s++]=A[w++],v>1&&(A[s++]=A[w++]))}}else if((b&64)===0){x=p[(x&65535)+(h&(1<<b)-1)];continue r}else{e.msg="invalid distance code",T.mode=Sa;break e}break}}else if((b&64)===0){x=g[(x&65535)+(h&(1<<b)-1)];continue t}else if(b&32){T.mode=Uy;break e}else{e.msg="invalid literal/length code",T.mode=Sa;break e}break}}while(n<i&&s<a);v=m>>3,n-=v,m-=v<<3,h&=(1<<m)-1,e.next_in=n,e.next_out=s,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=s<a?257+(a-s):257-(s-a),T.hold=h,T.bits=m},si=15,df=852,ff=592,hf=0,yc=1,mf=2,Vy=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Gy=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Wy=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),Xy=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),Ky=(t,e,r,n,i,s,o,a)=>{let u=a.bits,l=0,c=0,f=0,d=0,h=0,m=0,g=0,p=0,y=0,_=0,x,b,v,S,w,M=null,L,A=new Uint16Array(si+1),T=new Uint16Array(si+1),I=null,z,C,V;for(l=0;l<=si;l++)A[l]=0;for(c=0;c<n;c++)A[e[r+c]]++;for(h=u,d=si;d>=1&&A[d]===0;d--);if(h>d&&(h=d),d===0)return i[s++]=1<<24|64<<16|0,i[s++]=1<<24|64<<16|0,a.bits=1,0;for(f=1;f<d&&A[f]===0;f++);for(h<f&&(h=f),p=1,l=1;l<=si;l++)if(p<<=1,p-=A[l],p<0)return-1;if(p>0&&(t===hf||d!==1))return-1;for(T[1]=0,l=1;l<si;l++)T[l+1]=T[l]+A[l];for(c=0;c<n;c++)e[r+c]!==0&&(o[T[e[r+c]]++]=c);if(t===hf?(M=I=o,L=20):t===yc?(M=Vy,I=Gy,L=257):(M=Wy,I=Xy,L=0),_=0,c=0,l=f,w=s,m=h,g=0,v=-1,y=1<<h,S=y-1,t===yc&&y>df||t===mf&&y>ff)return 1;for(;;){z=l-g,o[c]+1<L?(C=0,V=o[c]):o[c]>=L?(C=I[o[c]-L],V=M[o[c]-L]):(C=96,V=0),x=1<<l-g,b=1<<m,f=b;do b-=x,i[w+(_>>g)+b]=z<<24|C<<16|V|0;while(b!==0);for(x=1<<l-1;_&x;)x>>=1;if(x!==0?(_&=x-1,_+=x):_=0,c++,--A[l]===0){if(l===d)break;l=e[r+o[c]]}if(l>h&&(_&S)!==v){for(g===0&&(g=h),w+=f,m=l-g,p=1<<m;m+g<d&&(p-=A[m+g],!(p<=0));)m++,p<<=1;if(y+=1<<m,t===yc&&y>df||t===mf&&y>ff)return 1;v=_&S,i[v]=h<<24|m<<16|w-s|0}}return _!==0&&(i[w+_]=l-g<<24|64<<16|0),a.bits=h,0},Fs=Ky,$y=0,uh=1,dh=2,{Z_FINISH:pf,Z_BLOCK:Zy,Z_TREES:Aa,Z_OK:fn,Z_STREAM_END:Yy,Z_NEED_DICT:qy,Z_STREAM_ERROR:Je,Z_DATA_ERROR:fh,Z_MEM_ERROR:hh,Z_BUF_ERROR:jy,Z_DEFLATED:gf}=hn,Fa=16180,yf=16181,bf=16182,xf=16183,_f=16184,vf=16185,wf=16186,Sf=16187,Af=16188,Mf=16189,Ca=16190,Ot=16191,bc=16192,Ef=16193,xc=16194,Lf=16195,Tf=16196,kf=16197,Cf=16198,Ma=16199,Ea=16200,If=16201,Rf=16202,Ff=16203,zf=16204,Pf=16205,_c=16206,Df=16207,Bf=16208,ie=16209,mh=16210,ph=16211,Qy=852,Jy=592,eb=15,tb=eb,Of=t=>(t>>>24&255)+(t>>>8&65280)+((t&65280)<<8)+((t&255)<<24);function rb(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var mn=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.mode<Fa||e.mode>ph?1:0},gh=t=>{if(mn(t))return Je;let e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=e.wrap&1),e.mode=Fa,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Qy),e.distcode=e.distdyn=new Int32Array(Jy),e.sane=1,e.back=-1,fn},yh=t=>{if(mn(t))return Je;let e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,gh(t)},bh=(t,e)=>{let r;if(mn(t))return Je;let n=t.state;return e<0?(r=0,e=-e):(r=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?Je:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,yh(t))},xh=(t,e)=>{if(!t)return Je;let r=new rb;t.state=r,r.strm=t,r.window=null,r.mode=Fa;let n=bh(t,e);return n!==fn&&(t.state=null),n},nb=t=>xh(t,tb),Nf=!0,vc,wc,ib=t=>{if(Nf){vc=new Int32Array(512),wc=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Fs(uh,t.lens,0,288,vc,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Fs(dh,t.lens,0,32,wc,0,t.work,{bits:5}),Nf=!1}t.lencode=vc,t.lenbits=9,t.distcode=wc,t.distbits=5},_h=(t,e,r,n)=>{let i,s=t.state;return s.window===null&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),n>=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(i=s.wsize-s.wnext,i>n&&(i=n),s.window.set(e.subarray(r-n,r-n+i),s.wnext),n-=i,n?(s.window.set(e.subarray(r-n,r),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=i))),0},sb=(t,e)=>{let r,n,i,s,o,a,u,l,c,f,d,h,m,g,p=0,y,_,x,b,v,S,w,M,L=new Uint8Array(4),A,T,I=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(mn(t)||!t.output||!t.input&&t.avail_in!==0)return Je;r=t.state,r.mode===Ot&&(r.mode=bc),o=t.next_out,i=t.output,u=t.avail_out,s=t.next_in,n=t.input,a=t.avail_in,l=r.hold,c=r.bits,f=a,d=u,M=fn;e:for(;;)switch(r.mode){case Fa:if(r.wrap===0){r.mode=bc;break}for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&2&&l===35615){r.wbits===0&&(r.wbits=15),r.check=0,L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0),l=0,c=0,r.mode=yf;break}if(r.head&&(r.head.done=!1),!(r.wrap&1)||(((l&255)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=ie;break}if((l&15)!==gf){t.msg="unknown compression method",r.mode=ie;break}if(l>>>=4,c-=4,w=(l&15)+8,r.wbits===0&&(r.wbits=w),w>15||w>r.wbits){t.msg="invalid window size",r.mode=ie;break}r.dmax=1<<r.wbits,r.flags=0,t.adler=r.check=1,r.mode=l&512?Mf:Ot,l=0,c=0;break;case yf:for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.flags=l,(r.flags&255)!==gf){t.msg="unknown compression method",r.mode=ie;break}if(r.flags&57344){t.msg="unknown header flags set",r.mode=ie;break}r.head&&(r.head.text=l>>8&1),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0,r.mode=bf;case bf:for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.head&&(r.head.time=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,L[2]=l>>>16&255,L[3]=l>>>24&255,r.check=he(r.check,L,4,0)),l=0,c=0,r.mode=xf;case xf:for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.head&&(r.head.xflags=l&255,r.head.os=l>>8),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0,r.mode=_f;case _f:if(r.flags&1024){for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.length=l,r.head&&(r.head.extra_len=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=vf;case vf:if(r.flags&1024&&(h=r.length,h>a&&(h=a),h&&(r.head&&(w=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(s,s+h),w)),r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,r.length-=h),r.length))break e;r.length=0,r.mode=wf;case wf:if(r.flags&2048){if(a===0)break e;h=0;do w=n[s+h++],r.head&&w&&r.length<65536&&(r.head.name+=String.fromCharCode(w));while(w&&h<a);if(r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,w)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Sf;case Sf:if(r.flags&4096){if(a===0)break e;h=0;do w=n[s+h++],r.head&&w&&r.length<65536&&(r.head.comment+=String.fromCharCode(w));while(w&&h<a);if(r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,w)break e}else r.head&&(r.head.comment=null);r.mode=Af;case Af:if(r.flags&512){for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&4&&l!==(r.check&65535)){t.msg="header crc mismatch",r.mode=ie;break}l=0,c=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ot;break;case Mf:for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}t.adler=r.check=Of(l),l=0,c=0,r.mode=Ca;case Ca:if(r.havedict===0)return t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,qy;t.adler=r.check=1,r.mode=Ot;case Ot:if(e===Zy||e===Aa)break e;case bc:if(r.last){l>>>=c&7,c-=c&7,r.mode=_c;break}for(;c<3;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}switch(r.last=l&1,l>>>=1,c-=1,l&3){case 0:r.mode=Ef;break;case 1:if(ib(r),r.mode=Ma,e===Aa){l>>>=2,c-=2;break e}break;case 2:r.mode=Tf;break;case 3:t.msg="invalid block type",r.mode=ie}l>>>=2,c-=2;break;case Ef:for(l>>>=c&7,c-=c&7;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if((l&65535)!==(l>>>16^65535)){t.msg="invalid stored block lengths",r.mode=ie;break}if(r.length=l&65535,l=0,c=0,r.mode=xc,e===Aa)break e;case xc:r.mode=Lf;case Lf:if(h=r.length,h){if(h>a&&(h=a),h>u&&(h=u),h===0)break e;i.set(n.subarray(s,s+h),o),a-=h,s+=h,u-=h,o+=h,r.length-=h;break}r.mode=Ot;break;case Tf:for(;c<14;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.nlen=(l&31)+257,l>>>=5,c-=5,r.ndist=(l&31)+1,l>>>=5,c-=5,r.ncode=(l&15)+4,l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=ie;break}r.have=0,r.mode=kf;case kf:for(;r.have<r.ncode;){for(;c<3;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.lens[I[r.have++]]=l&7,l>>>=3,c-=3}for(;r.have<19;)r.lens[I[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},M=Fs($y,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,M){t.msg="invalid code lengths set",r.mode=ie;break}r.have=0,r.mode=Cf;case Cf:for(;r.have<r.nlen+r.ndist;){for(;p=r.lencode[l&(1<<r.lenbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(x<16)l>>>=y,c-=y,r.lens[r.have++]=x;else{if(x===16){for(T=y+2;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(l>>>=y,c-=y,r.have===0){t.msg="invalid bit length repeat",r.mode=ie;break}w=r.lens[r.have-1],h=3+(l&3),l>>>=2,c-=2}else if(x===17){for(T=y+3;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=y,c-=y,w=0,h=3+(l&7),l>>>=3,c-=3}else{for(T=y+7;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=y,c-=y,w=0,h=11+(l&127),l>>>=7,c-=7}if(r.have+h>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=ie;break}for(;h--;)r.lens[r.have++]=w}}if(r.mode===ie)break;if(r.lens[256]===0){t.msg="invalid code -- missing end-of-block",r.mode=ie;break}if(r.lenbits=9,A={bits:r.lenbits},M=Fs(uh,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,M){t.msg="invalid literal/lengths set",r.mode=ie;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},M=Fs(dh,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,M){t.msg="invalid distances set",r.mode=ie;break}if(r.mode=Ma,e===Aa)break e;case Ma:r.mode=Ea;case Ea:if(a>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,Hy(t,d),o=t.next_out,i=t.output,u=t.avail_out,s=t.next_in,n=t.input,a=t.avail_in,l=r.hold,c=r.bits,r.mode===Ot&&(r.back=-1);break}for(r.back=0;p=r.lencode[l&(1<<r.lenbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(_&&(_&240)===0){for(b=y,v=_,S=x;p=r.lencode[S+((l&(1<<b+v)-1)>>b)],y=p>>>24,_=p>>>16&255,x=p&65535,!(b+y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=y,c-=y,r.back+=y,r.length=x,_===0){r.mode=Pf;break}if(_&32){r.back=-1,r.mode=Ot;break}if(_&64){t.msg="invalid literal/length code",r.mode=ie;break}r.extra=_&15,r.mode=If;case If:if(r.extra){for(T=r.extra;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=Rf;case Rf:for(;p=r.distcode[l&(1<<r.distbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if((_&240)===0){for(b=y,v=_,S=x;p=r.distcode[S+((l&(1<<b+v)-1)>>b)],y=p>>>24,_=p>>>16&255,x=p&65535,!(b+y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=y,c-=y,r.back+=y,_&64){t.msg="invalid distance code",r.mode=ie;break}r.offset=x,r.extra=_&15,r.mode=Ff;case Ff:if(r.extra){for(T=r.extra;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=ie;break}r.mode=zf;case zf:if(u===0)break e;if(h=d-u,r.offset>h){if(h=r.offset-h,h>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=ie;break}h>r.wnext?(h-=r.wnext,m=r.wsize-h):m=r.wnext-h,h>r.length&&(h=r.length),g=r.window}else g=i,m=o-r.offset,h=r.length;h>u&&(h=u),u-=h,r.length-=h;do i[o++]=g[m++];while(--h);r.length===0&&(r.mode=Ea);break;case Pf:if(u===0)break e;i[o++]=r.length,u--,r.mode=Ea;break;case _c:if(r.wrap){for(;c<32;){if(a===0)break e;a--,l|=n[s++]<<c,c+=8}if(d-=u,t.total_out+=d,r.total+=d,r.wrap&4&&d&&(t.adler=r.check=r.flags?he(r.check,i,d,o-d):Os(r.check,i,d,o-d)),d=u,r.wrap&4&&(r.flags?l:Of(l))!==r.check){t.msg="incorrect data check",r.mode=ie;break}l=0,c=0}r.mode=Df;case Df:if(r.wrap&&r.flags){for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&4&&l!==(r.total&4294967295)){t.msg="incorrect length check",r.mode=ie;break}l=0,c=0}r.mode=Bf;case Bf:M=Yy;break e;case ie:M=fh;break e;case mh:return hh;case ph:default:return Je}return t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,(r.wsize||d!==t.avail_out&&r.mode<ie&&(r.mode<_c||e!==pf))&&_h(t,t.output,t.next_out,d-t.avail_out),f-=t.avail_in,d-=t.avail_out,t.total_in+=f,t.total_out+=d,r.total+=d,r.wrap&4&&d&&(t.adler=r.check=r.flags?he(r.check,i,d,t.next_out-d):Os(r.check,i,d,t.next_out-d)),t.data_type=r.bits+(r.last?64:0)+(r.mode===Ot?128:0)+(r.mode===Ma||r.mode===xc?256:0),(f===0&&d===0||e===pf)&&M===fn&&(M=jy),M},ob=t=>{if(mn(t))return Je;let e=t.state;return e.window&&(e.window=null),t.state=null,fn},ab=(t,e)=>{if(mn(t))return Je;let r=t.state;return(r.wrap&2)===0?Je:(r.head=e,e.done=!1,fn)},lb=(t,e)=>{let r=e.length,n,i,s;return mn(t)||(n=t.state,n.wrap!==0&&n.mode!==Ca)?Je:n.mode===Ca&&(i=1,i=Os(i,e,r,0),i!==n.check)?fh:(s=_h(t,e,r,r),s?(n.mode=mh,hh):(n.havedict=1,fn))},cb=yh,ub=bh,db=gh,fb=nb,hb=xh,mb=sb,pb=ob,gb=ab,yb=lb,bb="pako inflate (from Nodeca project)",Ut={inflateReset:cb,inflateReset2:ub,inflateResetKeep:db,inflateInit:fb,inflateInit2:hb,inflate:mb,inflateEnd:pb,inflateGetHeader:gb,inflateSetDictionary:yb,inflateInfo:bb};function xb(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var _b=xb,vh=Object.prototype.toString,{Z_NO_FLUSH:vb,Z_FINISH:wb,Z_OK:Hs,Z_STREAM_END:Sc,Z_NEED_DICT:Ac,Z_STREAM_ERROR:Sb,Z_DATA_ERROR:Uf,Z_MEM_ERROR:Ab}=hn;function Xs(t){this.options=Ra.assign({chunkSize:1024*64,windowBits:15,to:""},t||{});let e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(t&&t.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new lh,this.strm.avail_out=0;let r=Ut.inflateInit2(this.strm,e.windowBits);if(r!==Hs)throw new Error(un[r]);if(this.header=new _b,Ut.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=Us.string2buf(e.dictionary):vh.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=Ut.inflateSetDictionary(this.strm,e.dictionary),r!==Hs)))throw new Error(un[r])}Xs.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i=this.options.dictionary,s,o,a;if(this.ended)return!1;for(e===~~e?o=e:o=e===!0?wb:vb,vh.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),s=Ut.inflate(r,o),s===Ac&&i&&(s=Ut.inflateSetDictionary(r,i),s===Hs?s=Ut.inflate(r,o):s===Uf&&(s=Ac));r.avail_in>0&&s===Sc&&r.state.wrap>0&&t[r.next_in]!==0;)Ut.inflateReset(r),s=Ut.inflate(r,o);switch(s){case Sb:case Uf:case Ac:case Ab:return this.onEnd(s),this.ended=!0,!1}if(a=r.avail_out,r.next_out&&(r.avail_out===0||s===Sc))if(this.options.to==="string"){let u=Us.utf8border(r.output,r.next_out),l=r.next_out-u,c=Us.buf2string(r.output,u);r.next_out=l,r.avail_out=n-l,l&&r.output.set(r.output.subarray(u,u+l),0),this.onData(c)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(!(s===Hs&&a===0)){if(s===Sc)return s=Ut.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(r.avail_in===0)break}}return!0};Xs.prototype.onData=function(t){this.chunks.push(t)};Xs.prototype.onEnd=function(t){t===Hs&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=Ra.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Uc(t,e){let r=new Xs(e);if(r.push(t),r.err)throw r.msg||un[r.err];return r.result}function Mb(t,e){return e=e||{},e.raw=!0,Uc(t,e)}var Eb=Xs,Lb=Uc,Tb=Mb,kb=Uc,Cb=hn,Ib={Inflate:Eb,inflate:Lb,inflateRaw:Tb,ungzip:kb,constants:Cb},{Deflate:Rb,deflate:Fb,deflateRaw:zb,gzip:Pb}=Ny,{Inflate:Db,inflate:Bb,inflateRaw:Ob,ungzip:Nb}=Ib,Ub=Rb,Hb=Fb,Vb=zb,Gb=Pb,Wb=Db,Xb=Bb,Kb=Ob,$b=Nb,Zb=hn,Hc={Deflate:Ub,deflate:Hb,deflateRaw:Vb,gzip:Gb,Inflate:Wb,inflate:Xb,inflateRaw:Kb,ungzip:$b,constants:Zb};var fi=class fi{constructor(e=fi.INITIAL_SIZE){this.buffer=new Uint8Array(e),this.readOffset=0,this.writeOffset=0}append(e){let r=e instanceof Uint8Array?e:new Uint8Array(e),n=this.writeOffset+r.length;n>this.buffer.length&&this.grow(n),this.buffer.set(r,this.writeOffset),this.writeOffset+=r.length}hasBytes(e){return this.writeOffset-this.readOffset>=e}available(){return this.writeOffset-this.readOffset}readByte(){if(!this.hasBytes(1))throw new Error("Buffer underflow");return this.buffer[this.readOffset++]}readShort(){if(!this.hasBytes(2))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8;return this.readOffset+=2,e>32767?e-65536:e}readLong(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8|this.buffer[this.readOffset+2]<<16|this.buffer[this.readOffset+3]<<24;return this.readOffset+=4,e}readFloat(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let r=new DataView(this.buffer.buffer,this.buffer.byteOffset+this.readOffset,4).getFloat32(0,!0);return this.readOffset+=4,r}readString(){let e=Math.min(fi.MAX_STRING_LENGTH,this.writeOffset-this.readOffset),r=0;for(;r<e&&this.buffer[this.readOffset+r]!==0;)r++;if(r>=e)throw this.writeOffset-this.readOffset<=e?new Error("Buffer underflow"):new Error("String exceeds max length");let n=this.buffer.slice(this.readOffset,this.readOffset+r);return this.readOffset+=r+1,new TextDecoder("latin1").decode(n)}peekBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");return this.buffer.slice(this.readOffset,this.readOffset+e)}readBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");let r=this.buffer.slice(this.readOffset,this.readOffset+e);return this.readOffset+=e,r}readData(e){return this.readBytes(e)}getReadPosition(){return this.readOffset}getWritePosition(){return this.writeOffset}setReadPosition(e){if(e<0||e>this.writeOffset)throw new Error("Invalid read position");this.readOffset=e}grow(e){let r=e?Math.max(e,this.buffer.length*2):this.buffer.length*2,n=new Uint8Array(r);n.set(this.buffer),this.buffer=n}compact(){if(this.readOffset===0)return;let e=this.writeOffset-this.readOffset;if(e===0){this.readOffset=0,this.writeOffset=0;return}this.buffer.copyWithin(0,this.readOffset,this.writeOffset),this.readOffset=0,this.writeOffset=e}getCapacity(){return this.buffer.length}reset(){this.readOffset=0,this.writeOffset=0}};fi.INITIAL_SIZE=64*1024,fi.MAX_STRING_LENGTH=2048;var za=fi;var hi=2023,gr=1,yr=2,br=4,xr=8,_r=16,vr=32,$s=64,Ks=128,Pa=256,wr=512,Sr=1024,Ar=2048,bt=4096,Mr=8192,xt=16384,Da=32768,_t=65536,Er=1<<17,vt=1<<18,wt=1<<19,Lr=1<<20,Tr=1<<21,kr=1<<22,Ba=1<<23,Cr=1<<24,St=1<<25,Ir=1<<26,Rr=1<<27,Fr=1<<28,zr=1<<29,Pr=1<<30,Oa=-2147483648,Dr=1,Br=2,Or=4;var Yb=1,qb=2,jb=128,Ht=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0,bitsHigh:0,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame:0}),pn=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0}),Vc=class extends za{constructor(r){super(0);this.stream=r}readByte(){return this.stream.readByte()}readShort(){return this.stream.readShort()}readLong(){return this.stream.readLong()}readFloat(){return this.stream.readFloat()}readString(){return this.stream.readString()}readData(r){return this.stream.readData(r)}hasBytes(r){return this.stream.hasMore()}available(){return this.stream.getRemaining()}getReadPosition(){return this.stream.getPosition()}peekBytes(r){throw new Error("peekBytes not implemented for BinaryStreamAdapter")}},it=class t{constructor(e,r,n=!1){this.protocolVersion=0;this.isDemo=Yb;this.strictMode=!1;this.errorCount=0;e instanceof vn?this.stream=new Vc(e):this.stream=e,this.handler=r,this.strictMode=n}setProtocolVersion(e){this.protocolVersion=e}getProtocolVersion(){return this.protocolVersion}getErrorCount(){return this.errorCount}translateCommand(e){if(this.protocolVersion===0)return e===7?k.serverdata:e===12?k.serverdata:e;if(this.protocolVersion===hi)return e;if(this.protocolVersion===25||this.protocolVersion===26){if(e===0)return k.bad;let r=e+5;return r>=k.nop&&r<=k.frame?r:k.bad}return this.protocolVersion===34?e<=k.frame?e:k.bad:e}parseMessage(){for(;this.stream.hasBytes(1);){let e=this.stream.getReadPosition(),r=-1;try{if(r=this.stream.readByte(),r===-1)break;let n=r;switch(r=this.translateCommand(r),r){case k.bad:return;case k.nop:break;case k.disconnect:this.handler?.onDisconnect&&this.handler.onDisconnect();break;case k.reconnect:this.handler?.onReconnect&&this.handler.onReconnect();break;case k.print:this.parsePrint();break;case k.serverdata:this.parseServerData();break;case k.configstring:this.parseConfigString();break;case k.spawnbaseline:this.parseSpawnBaseline();break;case k.centerprint:this.parseCenterPrint();break;case k.download:this.parseDownload();break;case k.frame:this.parseFrame();break;case k.packetentities:this.parsePacketEntities(!1);break;case k.deltapacketentities:this.parsePacketEntities(!0);break;case k.playerinfo:this.parsePlayerState();break;case k.stufftext:this.parseStuffText();break;case k.layout:this.parseLayout();break;case k.inventory:this.parseInventory();break;case k.sound:this.parseSound();break;case k.muzzleflash:this.parseMuzzleFlash();break;case k.muzzleflash2:this.parseMuzzleFlash2();break;case k.temp_entity:this.parseTempEntity();break;case k.splitclient:this.parseSplitClient();break;case k.configblast:this.parseConfigBlast();break;case k.spawnbaselineblast:this.parseSpawnBaselineBlast();break;case k.level_restart:this.handler?.onLevelRestart&&this.handler.onLevelRestart();break;case k.damage:this.parseDamage();break;case k.locprint:this.parseLocPrint();break;case k.fog:this.parseFog();break;case k.waitingforplayers:this.parseWaitingForPlayers();break;case k.bot_chat:this.parseBotChat();break;case k.poi:this.parsePoi();break;case k.help_path:this.parseHelpPath();break;case k.muzzleflash3:this.parseMuzzleFlash3();break;case k.achievement:this.parseAchievement();break;default:let i=`Unknown server command: ${n} (translated: ${r}) at offset ${e}`;if(this.strictMode)throw new Error(i);console.warn(i),this.errorCount++;return}}catch(n){let i=n.message;if(i==="Buffer underflow"||i.includes("StreamingBuffer")){try{this.stream.setReadPosition(e)}catch(o){console.error("Failed to rollback stream position",o)}return}let s=`offset ${e}, cmd ${r}, protocol ${this.protocolVersion}`;if(console.warn(`Error parsing command ${r} (${s}): ${i}`),this.errorCount++,this.strictMode)throw n;return}}}readAngle16(){return this.stream.readShort()*(360/65536)}readCoord(){return this.stream.readShort()*.125}readAngle(){return this.stream.readByte()*(360/256)}readPos(e){e.x=this.stream.readShort()*.125,e.y=this.stream.readShort()*.125,e.z=this.stream.readShort()*.125}readDir(e){let r=this.stream.readByte();if(r>=bn.length)e.x=0,e.y=0,e.z=0;else{let n=bn[r];e.x=n[0],e.y=n[1],e.z=n[2]}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}parseServerData(){if(this.protocolVersion=this.stream.readLong(),this.protocolVersion===hi){let e=this.stream.readLong(),r=this.stream.readByte();this.isDemo=r;let n=this.stream.readByte(),i=this.stream.readString(),s=this.stream.readShort();if(s===-2){let a=this.stream.readShort();for(let u=0;u<a;u++)this.stream.readShort();s=0}else s===-1&&(s=-1);let o=this.stream.readString();this.handler&&this.handler.onServerData(this.protocolVersion,e,0,i,s,o,n,r)}else{let e=this.stream.readLong(),r=this.stream.readByte();this.isDemo=r;let n=this.stream.readString(),i=this.stream.readShort(),s=this.stream.readString();this.handler&&this.handler.onServerData(this.protocolVersion,e,r,n,i,s)}}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseSplitClient(){let e=this.stream.readByte();this.handler?.onSplitClient&&this.handler.onSplitClient(e)}parseConfigBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=Hc.inflate(n),s=new vn(i.buffer);for(;s.hasMore();){let o=s.readUShort(),a=s.readString();this.handler&&this.handler.onConfigString(o,a)}}catch(i){console.error("svc_configblast error",i)}}parseSpawnBaselineBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=Hc.inflate(n),s=new vn(i.buffer),o=new t(s,this.handler,this.strictMode);for(o.setProtocolVersion(this.protocolVersion);s.hasMore();)o.parseSpawnBaseline()}catch(i){console.error("svc_spawnbaselineblast error",i)}}parseLocPrint(){let e=this.stream.readByte(),r=this.stream.readString(),n=this.stream.readByte(),i=[];for(let s=0;s<n;s++)i.push(this.stream.readString());this.handler?.onLocPrint&&this.handler.onLocPrint(e,r,i)}parseWaitingForPlayers(){let e=this.stream.readByte();this.handler?.onWaitingForPlayers&&this.handler.onWaitingForPlayers(e)}parseBotChat(){let e=this.stream.readString(),r=this.stream.readShort(),n=this.stream.readString();this.handler?.onBotChat&&this.handler.onBotChat(n)}parsePoi(){let e=this.stream.readShort(),r=this.stream.readShort(),n={x:0,y:0,z:0};this.readPos(n);let i=this.stream.readShort(),s=this.stream.readByte(),o=this.stream.readByte();this.handler?.onPoi&&this.handler.onPoi(o,n)}parseHelpPath(){let e=this.stream.readByte(),r={x:0,y:0,z:0};this.readPos(r);let n={x:0,y:0,z:0};this.readDir(n),this.handler?.onHelpPath&&this.handler.onHelpPath(r)}parseAchievement(){let e=this.stream.readString();this.handler?.onAchievement&&this.handler.onAchievement(e)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,s,o,a;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(s=this.stream.readByte()),e&8&&(o=this.stream.readShort()),e&4){let u={x:0,y:0,z:0};this.readPos(u),a=u}this.handler&&this.handler.onSound(e,r,n,i,s,o,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler?.onMuzzleFlash3&&this.handler.onMuzzleFlash3(e,r)}parseFog(){let e=this.stream.readByte();if(e&128){let n=this.stream.readByte();e|=n<<8}let r={};e&1&&(r.density=this.stream.readFloat(),r.skyfactor=this.stream.readByte()),e&2&&(r.red=this.stream.readByte()),e&4&&(r.green=this.stream.readByte()),e&8&&(r.blue=this.stream.readByte()),e&16&&(r.time=this.stream.readShort()),e&32&&(r.hf_falloff=this.stream.readFloat()),e&64&&(r.hf_density=this.stream.readFloat()),e&256&&(r.hf_start_r=this.stream.readByte()),e&512&&(r.hf_start_g=this.stream.readByte()),e&1024&&(r.hf_start_b=this.stream.readByte()),e&2048&&(r.hf_start_dist=this.stream.readLong()),e&4096&&(r.hf_end_r=this.stream.readByte()),e&8192&&(r.hf_end_g=this.stream.readByte()),e&16384&&(r.hf_end_b=this.stream.readByte()),e&32768&&(r.hf_end_dist=this.stream.readLong()),this.handler?.onFog&&this.handler.onFog(r)}parseDamage(){let e=this.stream.readByte(),r=[];for(let n=0;n<e;n++){let i=this.stream.readByte(),s={x:0,y:0,z:0};this.readDir(s);let o=i&31,a=(i&32)!==0,u=(i&64)!==0,l=(i&128)!==0;r.push({damage:o,health:a,armor:u,power:l,dir:s})}this.handler?.onDamage&&this.handler.onDamage(r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},s,o,a,u,l;switch(e){case R.EXPLOSION1:case R.EXPLOSION2:case R.ROCKET_EXPLOSION:case R.GRENADE_EXPLOSION:case R.ROCKET_EXPLOSION_WATER:case R.GRENADE_EXPLOSION_WATER:case R.BFG_EXPLOSION:case R.BFG_BIGEXPLOSION:case R.BOSSTPORT:case R.PLASMA_EXPLOSION:case R.PLAIN_EXPLOSION:case R.CHAINFIST_SMOKE:case R.TRACKER_EXPLOSION:case R.TELEPORT_EFFECT:case R.DBALL_GOAL:case R.NUKEBLAST:case R.WIDOWSPLASH:case R.EXPLOSION1_BIG:case R.EXPLOSION1_NP:this.readPos(r);break;case R.GUNSHOT:case R.BLOOD:case R.BLASTER:case R.SHOTGUN:case R.SPARKS:case R.BULLET_SPARKS:case R.SCREEN_SPARKS:case R.SHIELD_SPARKS:case R.BLASTER2:case R.FLECHETTE:case R.MOREBLOOD:case R.ELECTRIC_SPARKS:case R.HEATBEAM_SPARKS:case R.HEATBEAM_STEAM:this.readPos(r),this.readDir(i);break;case R.SPLASH:case R.LASER_SPARKS:case R.WELDING_SPARKS:case R.TUNNEL_SPARKS:s=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte();break;case R.BLUEHYPERBLASTER:this.protocolVersion>=32?(this.readPos(r),this.readPos(n)):(this.readPos(r),this.readDir(i));break;case R.GREENBLOOD:this.protocolVersion>=32?(this.readPos(r),this.readDir(i)):(this.readPos(r),this.readPos(n));break;case R.RAILTRAIL:case R.BUBBLETRAIL:case R.BFG_LASER:case R.DEBUGTRAIL:case R.BUBBLETRAIL2:this.readPos(r),this.readPos(n);break;case R.PARASITE_ATTACK:case R.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.readPos(r),this.readPos(n);break;case R.GRAPPLE_CABLE:a=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readPos(i);break;case R.LIGHTNING:u=this.stream.readShort(),l=this.stream.readShort(),this.readPos(r),this.readPos(n);break;case R.FLASHLIGHT:this.readPos(r),a=this.stream.readShort();break;case R.FORCEWALL:this.readPos(r),this.readPos(n),o=this.stream.readByte();break;case R.STEAM:let c=this.stream.readShort();s=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte(),this.stream.readShort(),c!==-1&&this.stream.readLong();break;case R.WIDOWBEAMOUT:this.stream.readShort();case R.HEATBEAM:case R.MONSTER_HEATBEAM:a=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readDir(i);break}this.handler&&this.handler.onTempEntity(e,r,n,i,s,o,a,u,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=Ht();this.parseDelta(Ht(),r,e.number,e.bits,e.bitsHigh),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=0;this.protocolVersion!==26&&this.protocolVersion!==25&&(n=this.stream.readByte());let i=this.stream.readByte(),s=this.stream.readData(i),o=this.stream.readByte();if(o=this.translateCommand(o),o!==k.playerinfo){if(this.strictMode)throw new Error(`Expected svc_playerinfo after svc_frame, got ${o}`);return}let a=this.parsePlayerState(),u=this.stream.readByte();if(u=this.translateCommand(u),u!==k.packetentities){if(this.strictMode)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${u}`);return}let l=this.collectPacketEntities();if(this.isDemo===jb){let c=this.stream.readByte();for(let f=0;f<c;f++)this.stream.readByte()}this.isDemo===qb&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:s,playerState:a,packetEntities:{delta:!0,entities:l}})}parsePlayerState(){let e=pn(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.readCoord(),e.origin.y=this.readCoord(),e.origin.z=this.readCoord()),r&4&&(e.velocity.x=this.readCoord(),e.velocity.y=this.readCoord(),e.velocity.z=this.readCoord()),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=(this.stream.readByte()<<24>>24)*.25,e.viewoffset.y=(this.stream.readByte()<<24>>24)*.25,e.viewoffset.z=(this.stream.readByte()<<24>>24)*.25),r&256&&(e.viewangles.x=this.readAngle16(),e.viewangles.y=this.readAngle16(),e.viewangles.z=this.readAngle16()),r&512&&(e.kick_angles.x=(this.stream.readByte()<<24>>24)*.25,e.kick_angles.y=(this.stream.readByte()<<24>>24)*.25,e.kick_angles.z=(this.stream.readByte()<<24>>24)*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=(this.stream.readByte()<<24>>24)*.25,e.gun_offset.y=(this.stream.readByte()<<24>>24)*.25,e.gun_offset.z=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.x=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.y=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.z=(this.stream.readByte()<<24>>24)*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let i=0;i<32;i++)n&1<<i&&(e.stats[i]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:pn(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.bits&$s){if(r.number===0)break;continue}let n=Ht(),i=r.number===0&&!(r.bits&Ks);if((r.number!==0||i)&&this.parseDelta(Ht(),n,r.number,r.bits,r.bitsHigh),r.number===0)break;e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&Ks&&(e|=this.stream.readByte()<<8),e&Da&&(e|=this.stream.readByte()<<16),e&Ba&&(e|=this.stream.readByte()<<24);let r=0;this.protocolVersion===hi&&e&Oa&&(r=this.stream.readByte());let n;return e&Pa?n=this.stream.readShort():n=this.stream.readByte(),{number:n,bits:e,bitsHigh:r}}parseDelta(e,r,n,i,s=0){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.alpha=e.alpha,r.scale=e.scale,r.instanceBits=e.instanceBits,r.loopVolume=e.loopVolume,r.loopAttenuation=e.loopAttenuation,r.owner=e.owner,r.oldFrame=e.oldFrame,r.number=n,r.bits=i,r.bitsHigh=s,i&Ar&&(r.modelindex=this.stream.readByte()),i&Lr&&(r.modelindex2=this.stream.readByte()),i&Tr&&(r.modelindex3=this.stream.readByte()),i&kr&&(r.modelindex4=this.stream.readByte()),i&_r&&(r.frame=this.stream.readByte()),i&Er&&(r.frame=this.stream.readShort()),i&_t&&i&St?r.skinnum=this.stream.readLong():i&_t?r.skinnum=this.stream.readByte():i&St&&(r.skinnum=this.stream.readShort()),i&xt&&i&wt?r.effects=this.stream.readLong():i&xt?r.effects=this.stream.readByte():i&wt&&(r.effects=this.stream.readShort()),i&bt&&i&vt?r.renderfx=this.stream.readLong():i&bt?r.renderfx=this.stream.readByte():i&vt&&(r.renderfx=this.stream.readShort()),i&gr&&(r.origin.x=this.readCoord()),i&yr&&(r.origin.y=this.readCoord()),i&wr&&(r.origin.z=this.readCoord()),i&Sr&&(r.angles.x=this.readAngle()),i&br&&(r.angles.y=this.readAngle()),i&xr&&(r.angles.z=this.readAngle()),i&Cr&&this.readPos(r.old_origin),i&Ir&&(r.sound=this.stream.readByte()),i&vr?r.event=this.stream.readByte():r.event=0,i&Rr&&(r.solid=this.stream.readShort()),this.protocolVersion===hi&&(i&Mr&&(r.alpha=this.stream.readByte()/255),i&Fr&&(r.scale=this.stream.readFloat()),i&zr&&(r.instanceBits=this.stream.readLong()),i&Pr&&(r.loopVolume=this.stream.readByte()/255),s&Dr&&(r.loopAttenuation=this.stream.readByte()/255),s&Br&&(r.owner=this.stream.readShort()),s&Or&&(r.oldFrame=this.stream.readShort()))}};var Gc=(c=>(c.WeaponFire="weapon_fire",c.DamageDealt="damage_dealt",c.DamageReceived="damage_received",c.Pickup="pickup",c.Death="death",c.Kill="kill",c.Spawn="spawn",c.PlayerInfo="player_info",c.Chat="chat",c.Objective="objective",c))(Gc||{});var mi=class{constructor(e){this.events=[];this.summary={totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map};this.header=null;this.configStrings=new Map;this.serverInfo={};this.statistics=null;this.playerStats=new Map;this.weaponStats=new Map;this.activeEntities=new Set;this.buffer=e}analyze(){let e=new je(this.buffer),r=-1,n=0,i=.1,s=0,o={onServerData:(a,u,l,c,f,d,h,m)=>{s=a,this.header={protocolVersion:a,gameDir:c,levelName:d,playerNum:f,serverCount:u,spawnCount:u,tickRate:h,demoType:m},h&&h>0&&(i=1/h)},onConfigString:(a,u)=>{this.configStrings.set(a,u),a===0&&this.parseServerInfo(u)},onSpawnBaseline:a=>{},onFrame:a=>{let u=new Set;if(a.packetEntities&&a.packetEntities.entities)for(let l of a.packetEntities.entities)u.add(l.number),this.activeEntities.has(l.number)||this.recordEvent({type:"spawn",frame:r,time:n,entityId:l.number,position:{x:l.origin.x,y:l.origin.y,z:l.origin.z},description:`Entity ${l.number} spawned`});this.activeEntities=u,a.playerState&&this.header},onPrint:(a,u)=>{let l=u.replace(/\n/g," ").trim();l.includes("died")||l.includes("killed")||l.includes("suicide")?(this.summary.totalDeaths++,this.recordEvent({type:"death",frame:r,time:n,description:l})):l.startsWith("You got the ")?this.recordEvent({type:"pickup",frame:r,time:n,description:l}):(a===3||a===2)&&this.recordEvent({type:"chat",frame:r,time:n,description:l,data:{level:a}})},onCenterPrint:a=>{this.recordEvent({type:"objective",frame:r,time:n,description:a.trim()})},onStuffText:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onMuzzleFlash2:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onMuzzleFlash3:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{},onDamage:a=>{for(let u of a)if(this.recordEvent({type:"damage_received",frame:r,time:n,value:u.damage,position:u.dir,description:`Took ${u.damage} damage`}),this.summary.damageReceived+=u.damage,this.header){let l=this.getOrCreatePlayerStats(this.header.playerNum);l.damageReceived+=u.damage}}};for(;e.hasMore();){let a=e.readNextBlock();if(!a)break;r++,n=r*i;let u=new it(a.data,o);u.setProtocolVersion(s),u.parseMessage(),s=u.getProtocolVersion()}return this.statistics={duration:n,frameCount:r+1,averageFps:(r+1)/(n||1),mapName:this.header?.levelName||"unknown",playerCount:1},{events:this.events,summary:this.summary,header:this.header,configStrings:this.configStrings,serverInfo:this.serverInfo,statistics:this.statistics,playerStats:this.playerStats,weaponStats:this.weaponStats}}handleWeaponFire(e,r,n,i){this.recordEvent({type:"weapon_fire",frame:n,time:i,entityId:e,value:r,description:`Weapon ${r} fired by ${e}`});let s=this.summary.weaponUsage.get(r)||0;this.summary.weaponUsage.set(r,s+1);let o=this.getOrCreateWeaponStat(e,r);o.shotsFired++}recordEvent(e){this.events.push(e)}parseServerInfo(e){let r=e.split("\\");for(let n=1;n<r.length;n+=2)n+1<r.length&&(this.serverInfo[r[n]]=r[n+1])}getOrCreatePlayerStats(e){let r=this.playerStats.get(e);return r||(r={kills:0,deaths:0,damageDealt:0,damageReceived:0,suicides:0},this.playerStats.set(e,r)),r}getOrCreateWeaponStat(e,r){let n=this.weaponStats.get(e);n||(n=[],this.weaponStats.set(e,n));let i=n.find(s=>s.weaponId===r);return i||(i={weaponId:r,shotsFired:0,hits:0,kills:0},n.push(i)),i}};var Wc=(i=>(i[i.FirstPerson=0]="FirstPerson",i[i.ThirdPerson=1]="ThirdPerson",i[i.Free=2]="Free",i[i.Follow=3]="Follow",i))(Wc||{});var Na=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Na||{}),Qb=()=>({onServerData:()=>{},onConfigString:()=>{},onSpawnBaseline:()=>{},onFrame:()=>{},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}}),Vt=class{constructor(){this.reader=null;this.buffer=null;this.state=0;this.playbackSpeed=1;this.currentProtocolVersion=0;this.currentFrameIndex=-1;this.lastFrameData=null;this.accumulatedTime=0;this.frameDuration=100;this.snapshotInterval=100;this.snapshots=new Map;this.cachedEvents=null;this.cachedSummary=null;this.cachedHeader=null;this.cachedConfigStrings=null;this.cachedServerInfo=null;this.cachedStatistics=null;this.cachedPlayerStats=null;this.cachedWeaponStats=null;this.tracker=null;this.cameraMode=0;this.thirdPersonDistance=80;this.thirdPersonOffset={x:0,y:0,z:0}}setHandler(e){this.handler=e}setCallbacks(e){this.callbacks=e}loadDemo(e){this.buffer=e,this.reader=new je(e),this.transitionState(0),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.snapshots.clear(),this.lastFrameData=null,this.cachedEvents=null,this.cachedSummary=null,this.cachedHeader=null,this.cachedConfigStrings=null,this.cachedServerInfo=null,this.cachedStatistics=null,this.cachedPlayerStats=null,this.cachedWeaponStats=null}play(){this.reader&&this.state!==1&&this.transitionState(1)}pause(){this.state===1&&this.transitionState(2)}stop(){this.transitionState(0),this.reader&&this.reader.reset(),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.lastFrameData=null}transitionState(e){this.state!==e&&(this.state=e,this.callbacks?.onPlaybackStateChange&&this.callbacks.onPlaybackStateChange(e))}setFrameDuration(e){this.frameDuration=e}setSpeed(e){this.playbackSpeed=Math.max(.1,Math.min(e,16))}getSpeed(){return this.playbackSpeed}getPlaybackSpeed(){return this.playbackSpeed}getInterpolationFactor(){return this.frameDuration<=0?0:Math.max(0,Math.min(1,this.accumulatedTime/this.frameDuration))}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.processNextFrame())return;this.accumulatedTime-=this.frameDuration,this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}}stepForward(){this.reader&&(this.processNextFrame(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime()))}stepBackward(){this.reader&&this.currentFrameIndex>0&&this.seek(this.currentFrameIndex-1)}seekToTime(e){let r=this.timeToFrame(e);this.seek(r)}seekToFrame(e){this.seek(e)}frameToTime(e){return e*this.frameDuration/1e3}timeToFrame(e){return Math.floor(e*1e3/this.frameDuration)}playFrom(e){if(e.type==="frame")this.seek(e.frame);else if(e.type==="time")this.seekToTime(e.seconds);else throw new Error(`Invalid offset type: ${e.type}`);this.play()}playRange(e,r){let n=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),i=r.type==="frame"?r.frame:this.timeToFrame(r.seconds),s=this.getTotalFrames(),o=Math.max(0,s-1);if(n<0)throw new Error(`Invalid start offset: ${n}`);if(i<n)throw new Error(`End offset (${i}) cannot be before start offset (${n})`);this.playFrom(e);let a=this.callbacks?.onFrameUpdate,u={...this.callbacks,onFrameUpdate:l=>{a&&a(l),this.currentFrameIndex>=i&&(this.pause(),this.callbacks===u&&this.setCallbacks({...this.callbacks,onFrameUpdate:a}),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete())}};this.setCallbacks(u)}seek(e){if(!this.reader)return;let r=this.getTotalFrames();if(r>0&&e>=r&&(e=r-1),e<0&&(e=0),e===this.currentFrameIndex+1){this.processNextFrame(),this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}if(e===this.currentFrameIndex){this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}let n=-1,i=null;if(e>this.currentFrameIndex&&this.currentFrameIndex!==-1&&(n=this.currentFrameIndex),this.callbacks?.onRestoreSnapshot)for(let[s,o]of this.snapshots)s<=e&&s>n&&(n=s,i=o);for(n===-1&&this.currentFrameIndex>e?(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0):n===-1&&(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0),i&&this.callbacks?.onRestoreSnapshot&&(this.callbacks.onRestoreSnapshot(i),this.reader.seekToMessage(n+1)?this.currentFrameIndex=n:(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0));this.currentFrameIndex<e&&(this.callbacks?.onCaptureSnapshot&&(this.currentFrameIndex+1)%this.snapshotInterval,!!this.processNextFrame()););this.accumulatedTime=0,this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}processNextFrame(){if(!this.reader||!this.reader.hasMore())return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;let e=this.reader.readNextBlock();if(!e)return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;this.currentFrameIndex++,this.tracker&&(this.tracker.setCurrentFrame(this.currentFrameIndex),this.tracker.setCurrentTime(this.getCurrentTime()));try{let r={...this.handler||Qb(),onFrame:i=>{this.lastFrameData=i,this.handler?.onFrame&&this.handler.onFrame(i),this.callbacks?.onFrameUpdate&&this.callbacks.onFrameUpdate(i)}},n=new it(e.data,r);if(n.setProtocolVersion(this.currentProtocolVersion),n.parseMessage(),this.currentProtocolVersion=n.getProtocolVersion(),this.callbacks?.onCaptureSnapshot&&this.currentFrameIndex%this.snapshotInterval===0&&this.currentFrameIndex>0){let i=this.callbacks.onCaptureSnapshot(this.currentFrameIndex);i&&this.snapshots.set(this.currentFrameIndex,i)}}catch(r){return console.error("Error processing demo frame",r),this.callbacks?.onPlaybackError&&this.callbacks.onPlaybackError(r instanceof Error?r:new Error(String(r))),!1}return!0}getState(){return this.state}getCurrentTime(){return this.currentFrameIndex<0?this.accumulatedTime:this.currentFrameIndex*this.frameDuration+this.accumulatedTime}getFrameCount(){return this.reader?this.reader.getMessageCount():0}getTotalFrames(){return this.getFrameCount()}getCurrentFrame(){return this.currentFrameIndex<0?0:this.currentFrameIndex}getDuration(){return this.getFrameCount()*this.frameDuration/1e3}getTotalBytes(){return this.reader?this.reader.getProgress().total:0}getProcessedBytes(){return this.reader?this.reader.getOffset():0}getFrameData(e){if(e===this.currentFrameIndex&&this.lastFrameData)return this.lastFrameData;let r=this.state;return this.pause(),this.seek(e),r===1&&this.play(),this.lastFrameData}getFramePlayerState(e){if(e===this.currentFrameIndex&&this.handler?.getPlayerState){let n=this.handler.getPlayerState();if(n)return n}let r=this.getFrameData(e);return r?r.playerState:null}getFrameEntities(e){if(e===this.currentFrameIndex&&this.handler?.getEntities){let r=this.handler.getEntities();if(r)return Array.from(r.values())}if(this.seek(e),this.handler?.getEntities){let r=this.handler.getEntities();return r?Array.from(r.values()):[]}return[]}compareFrames(e,r){let n=this.getFramePlayerState(e),i=this.getFrameEntities(e),s=new Map;i.forEach(c=>s.set(c.number,c));let o=this.getFramePlayerState(r),a=this.getFrameEntities(r),u=new Map;a.forEach(c=>u.set(c.number,c));let l={frameA:e,frameB:r,playerStateDiff:{origin:null,viewangles:null,health:null,ammo:null},entityDiffs:{added:[],removed:[],moved:[]}};n&&o&&((n.origin.x!==o.origin.x||n.origin.y!==o.origin.y||n.origin.z!==o.origin.z)&&(l.playerStateDiff.origin={x:o.origin.x-n.origin.x,y:o.origin.y-n.origin.y,z:o.origin.z-n.origin.z}),n.stats[1]!==o.stats[1]&&(l.playerStateDiff.health=o.stats[1]-n.stats[1]),n.stats[2]!==o.stats[2]&&(l.playerStateDiff.ammo=o.stats[2]-n.stats[2]));for(let[c,f]of u){let d=s.get(c);d?(d.origin.x!==f.origin.x||d.origin.y!==f.origin.y||d.origin.z!==f.origin.z)&&l.entityDiffs.moved.push({id:c,delta:{x:f.origin.x-d.origin.x,y:f.origin.y-d.origin.y,z:f.origin.z-d.origin.z}}):l.entityDiffs.added.push(c)}for(let[c,f]of s)u.has(c)||l.entityDiffs.removed.push(c);return l}getEntityTrajectory(e,r,n){let i=[],s=this.getCurrentFrame();for(this.seek(r);this.getCurrentFrame()<=n&&this.state!==3;){let o=null;if(e===-1){let a=this.getFramePlayerState(this.getCurrentFrame());a&&(o={...a.origin})}else if(this.handler?.getEntities){let a=this.handler.getEntities().get(e);a&&(o={...a.origin})}if(o&&i.push(o),this.getCurrentFrame()===n)break;this.stepForward()}return this.seek(s),i}getEvents(){return this.ensureAnalysis(),this.cachedEvents||[]}getDemoEvents(){return this.getEvents()}filterEvents(e,r){return this.getDemoEvents().filter(i=>!(i.type!==e||r!==void 0&&i.entityId!==r))}getEventSummary(){return this.ensureAnalysis(),this.cachedSummary||{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map}}getMetadata(){let e=this.getDemoHeader();if(!e)return null;let r=this.getDemoServerInfo(),n="Unknown";return this.cachedConfigStrings,{mapName:e.levelName,playerName:n,serverName:r.hostname,demoVersion:e.protocolVersion,tickRate:e.tickRate||10}}getDemoHeader(){return this.ensureAnalysis(),this.cachedHeader}getDemoConfigStrings(){return this.ensureAnalysis(),this.cachedConfigStrings||new Map}getDemoServerInfo(){return this.ensureAnalysis(),this.cachedServerInfo||{}}getDemoStatistics(){return this.ensureAnalysis(),this.cachedStatistics}getPlayerStatistics(e){return this.ensureAnalysis(),this.cachedPlayerStats?.get(e)||null}getWeaponStatistics(e){return this.ensureAnalysis(),this.cachedWeaponStats?.get(e)||null}ensureAnalysis(){if(!this.cachedEvents&&this.buffer){let r=new mi(this.buffer).analyze();this.cachedEvents=r.events,this.cachedSummary=r.summary,this.cachedHeader=r.header,this.cachedConfigStrings=r.configStrings,this.cachedServerInfo=r.serverInfo,this.cachedStatistics=r.statistics,this.cachedPlayerStats=r.playerStats,this.cachedWeaponStats=r.weaponStats}}setCameraMode(e){this.cameraMode=e}getCameraMode(){return this.cameraMode}setThirdPersonDistance(e){this.thirdPersonDistance=e}setThirdPersonOffset(e){this.thirdPersonOffset=e}async playWithTracking(e,r={}){if(this.tracker=e,e.startTracking(),r.fastForward)try{this.state===0&&this.reader,this.transitionState(1);let n=100,i=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let s=0;for(;s<n;){if(!this.processNextFrame()){let o=e.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),o}s++}return await new Promise(o=>setTimeout(o,0)),i()};return await i()}catch(n){throw e.stopTracking(),this.tracker=null,n}else return new Promise((n,i)=>{let s=this.callbacks?.onPlaybackComplete,o=this.callbacks?.onPlaybackError,a=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:s,onPlaybackError:o}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let u=e.stopTracking();s&&s(),a(),n(u)},onPlaybackError:u=>{e.stopTracking(),o&&o(u),a(),i(u)}}),this.play()})}async playRangeWithTracking(e,r,n,i={}){this.tracker=n,n.startTracking();let s=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),o=r.type==="frame"?r.frame:this.timeToFrame(r.seconds);if(i.fastForward)try{this.playFrom(e),this.transitionState(1);let a=100,u=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let l=0;for(;l<a;){if(this.currentFrameIndex>=o||!this.processNextFrame()){let c=n.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),c}l++}return await new Promise(c=>setTimeout(c,0)),u()};return await u()}catch(a){throw n.stopTracking(),this.tracker=null,a}else return new Promise((a,u)=>{let l=this.callbacks?.onPlaybackComplete,c=this.callbacks?.onPlaybackError,f=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:l,onPlaybackError:c}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let d=n.stopTracking();l&&l(),f(),a(d)},onPlaybackError:d=>{n.stopTracking(),c&&c(d),f(),u(d)}}),this.playRange(e,r)})}};var Zs=class{constructor(){this.isRecording=!1;this.startTime=0;this.frameCount=0;this.filename=null;this.lastMessageSize=-1;this.messageBuffer=new Hr(1024*1024)}startRecording(e,r=0){this.isRecording||(this.isRecording=!0,this.filename=e,this.startTime=r,this.frameCount=0,this.messageBuffer.reset(),console.log(`DemoRecorder: Started recording to ${e}`))}recordMessage(e){if(this.isRecording){this.messageBuffer.writeLong(e.byteLength);for(let r=0;r<e.length;r++)this.messageBuffer.writeByte(e[r]);this.frameCount++}}stopRecording(){return this.isRecording?(this.isRecording=!1,this.messageBuffer.writeLong(-1),console.log(`DemoRecorder: Stopped recording. Frames: ${this.frameCount}, Size: ${this.messageBuffer.getOffset()} bytes`),this.messageBuffer.getData()):null}getIsRecording(){return this.isRecording}};var Ua=class{static validate(e,r){if(r&&!r.toLowerCase().endsWith(".dm2"))return{valid:!1,error:"Invalid file extension (expected .dm2)"};if(e.byteLength<5)return{valid:!1,error:"File too small to be a valid demo"};let n=new DataView(e),i=n.getInt32(0,!0);if(i<=0||i>e.byteLength-4)return{valid:!1,error:`Invalid first block length: ${i}`};let s=n.getUint8(4);if(s!==k.serverdata)return{valid:!1,error:`First command is not svc_serverdata (expected ${k.serverdata}, got ${s})`};let o=-1;return i>=5&&(o=n.getInt32(5,!0)),{valid:!0,version:o}}};var Ys=class{constructor(){this.writer=new Hr}getData(){return this.writer.getData()}writeServerData(e,r,n,i,s,o){this.writer.writeByte(k.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeString(i),this.writer.writeShort(s),this.writer.writeString(o)}writeServerDataRerelease(e,r,n,i,s,o,a){this.writer.writeByte(k.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeByte(i),this.writer.writeString(s),this.writer.writeShort(o),this.writer.writeString(a)}writeConfigString(e,r){this.writer.writeByte(k.configstring),this.writer.writeShort(e),this.writer.writeString(r)}writeSpawnBaseline(e,r){this.writer.writeByte(k.spawnbaseline),this.writeEntityState(e,null,!0,r)}writeStuffText(e){this.writer.writeByte(k.stufftext),this.writer.writeString(e)}writeCenterPrint(e){this.writer.writeByte(k.centerprint),this.writer.writeString(e)}writePrint(e,r){this.writer.writeByte(k.print),this.writer.writeByte(e),this.writer.writeString(r)}writeLayout(e){this.writer.writeByte(k.layout),this.writer.writeString(e)}writeInventory(e){this.writer.writeByte(k.inventory);for(let r=0;r<256;r++)this.writer.writeShort(e[r]||0)}writeMuzzleFlash(e,r){this.writer.writeByte(k.muzzleflash),this.writer.writeShort(e),this.writer.writeByte(r)}writeMuzzleFlash2(e,r){this.writer.writeByte(k.muzzleflash2),this.writer.writeShort(e),this.writer.writeByte(r)}writeTempEntity(e,r,n,i,s,o,a,u,l){console.warn("writeTempEntity not implemented - skipping message")}writeSound(e,r,n,i,s,o,a){this.writer.writeByte(k.sound),this.writer.writeByte(e),this.writer.writeByte(r),e&1&&this.writer.writeByte(n||0),e&2&&this.writer.writeByte(i||0),e&16&&this.writer.writeByte(s||0),e&8&&this.writer.writeShort(o||0),e&4&&a&&(this.writer.writeCoord(a.x),this.writer.writeCoord(a.y),this.writer.writeCoord(a.z))}writeDisconnect(){this.writer.writeByte(k.disconnect)}writeReconnect(){this.writer.writeByte(k.reconnect)}writeFrame(e,r){this.writer.writeByte(k.frame),this.writer.writeLong(e.serverFrame),this.writer.writeLong(e.deltaFrame),r!==25&&r!==26&&this.writer.writeByte(e.surpressCount),this.writer.writeByte(e.areaBytes),e.areaBytes>0&&this.writer.writeBytes(e.areaBits),this.writer.writeByte(k.playerinfo),this.writePlayerState(e.playerState),this.writePacketEntities(e.packetEntities.entities,e.packetEntities.delta,r)}writePlayerState(e){let r=0;e.pm_type!==0&&(r|=1),(e.origin.x!==0||e.origin.y!==0||e.origin.z!==0)&&(r|=2),(e.velocity.x!==0||e.velocity.y!==0||e.velocity.z!==0)&&(r|=4),e.pm_time!==0&&(r|=8),e.pm_flags!==0&&(r|=16),e.gravity!==0&&(r|=32),(e.delta_angles.x!==0||e.delta_angles.y!==0||e.delta_angles.z!==0)&&(r|=64),(e.viewoffset.x!==0||e.viewoffset.y!==0||e.viewoffset.z!==0)&&(r|=128),(e.viewangles.x!==0||e.viewangles.y!==0||e.viewangles.z!==0)&&(r|=256),(e.kick_angles.x!==0||e.kick_angles.y!==0||e.kick_angles.z!==0)&&(r|=512),(e.blend[0]!==0||e.blend[1]!==0||e.blend[2]!==0||e.blend[3]!==0)&&(r|=1024),e.gun_index!==0&&(r|=4096),(e.gun_frame!==0||e.gun_offset.x!==0||e.gun_offset.y!==0||e.gun_offset.z!==0||e.gun_angles.x!==0||e.gun_angles.y!==0||e.gun_angles.z!==0)&&(r|=8192),e.fov!==0&&(r|=2048),e.rdflags!==0&&(r|=16384),this.writer.writeShort(r),r&1&&this.writer.writeByte(e.pm_type),r&2&&(this.writer.writeCoord(e.origin.x),this.writer.writeCoord(e.origin.y),this.writer.writeCoord(e.origin.z)),r&4&&(this.writer.writeCoord(e.velocity.x),this.writer.writeCoord(e.velocity.y),this.writer.writeCoord(e.velocity.z)),r&8&&this.writer.writeByte(e.pm_time),r&16&&this.writer.writeByte(e.pm_flags),r&32&&this.writer.writeShort(e.gravity),r&64&&(this.writer.writeShort(Math.round(e.delta_angles.x*(32768/180))),this.writer.writeShort(Math.round(e.delta_angles.y*(32768/180))),this.writer.writeShort(Math.round(e.delta_angles.z*(32768/180)))),r&128&&(this.writer.writeChar(Math.round(e.viewoffset.x*4)),this.writer.writeChar(Math.round(e.viewoffset.y*4)),this.writer.writeChar(Math.round(e.viewoffset.z*4))),r&256&&(this.writer.writeAngle16(e.viewangles.x),this.writer.writeAngle16(e.viewangles.y),this.writer.writeAngle16(e.viewangles.z)),r&512&&(this.writer.writeChar(Math.round(e.kick_angles.x*4)),this.writer.writeChar(Math.round(e.kick_angles.y*4)),this.writer.writeChar(Math.round(e.kick_angles.z*4))),r&4096&&this.writer.writeByte(e.gun_index),r&8192&&(this.writer.writeByte(e.gun_frame),this.writer.writeChar(Math.round(e.gun_offset.x*4)),this.writer.writeChar(Math.round(e.gun_offset.y*4)),this.writer.writeChar(Math.round(e.gun_offset.z*4)),this.writer.writeChar(Math.round(e.gun_angles.x*4)),this.writer.writeChar(Math.round(e.gun_angles.y*4)),this.writer.writeChar(Math.round(e.gun_angles.z*4))),r&1024&&(this.writer.writeByte(e.blend[0]),this.writer.writeByte(e.blend[1]),this.writer.writeByte(e.blend[2]),this.writer.writeByte(e.blend[3])),r&2048&&this.writer.writeByte(e.fov),r&16384&&this.writer.writeByte(e.rdflags);let n=0;for(let i=0;i<32;i++)e.stats[i]!==0&&(n|=1<<i);this.writer.writeLong(n);for(let i=0;i<32;i++)n&1<<i&&this.writer.writeShort(e.stats[i])}writePacketEntities(e,r,n){this.writer.writeByte(r?k.deltapacketentities:k.packetentities);for(let i of e){let s=!r;this.writeEntityState(i,null,s,n)}this.writer.writeShort(0)}writeEntityState(e,r,n,i){let s=0,o=0;e.bits!==0&&!n?(s=e.bits,o=e.bitsHigh):(e.modelindex!==0&&(s|=Ar),e.modelindex2!==0&&(s|=Lr),e.modelindex3!==0&&(s|=Tr),e.modelindex4!==0&&(s|=kr),e.frame!==0&&(e.frame>=256?s|=Er:s|=_r),e.skinnum!==0&&(e.skinnum>=256?s|=St:s|=_t),e.effects!==0&&(e.effects>=256?s|=wt:s|=xt),e.renderfx!==0&&(e.renderfx>=256?s|=vt:s|=bt),e.origin.x!==0&&(s|=gr),e.origin.y!==0&&(s|=yr),e.origin.z!==0&&(s|=wr),e.angles.x!==0&&(s|=Sr),e.angles.y!==0&&(s|=br),e.angles.z!==0&&(s|=xr),(e.old_origin.x!==0||e.old_origin.y!==0||e.old_origin.z!==0)&&(s|=Cr),e.sound!==0&&(s|=Ir),e.event!==0&&(s|=vr),e.solid!==0&&(s|=Rr),i>=2023&&(e.alpha!==0&&(s|=Mr),e.scale!==0&&(s|=Fr),e.instanceBits!==0&&(s|=zr),e.loopVolume!==0&&(s|=Pr),e.loopAttenuation!==0&&(o|=Dr),e.owner!==0&&(o|=Br),e.oldFrame!==0&&(o|=Or)),e.number>=256&&(s|=Pa)),o!==0&&(s|=Oa),(s&4278190080)!==0&&(s|=Ba),(s&16711680)!==0&&(s|=Da),(s&65280)!==0&&(s|=Ks),this.writer.writeByte(s&255),s&Ks&&this.writer.writeByte(s>>8&255),s&Da&&this.writer.writeByte(s>>16&255),s&Ba&&this.writer.writeByte(s>>24&255),i>=2023&&s&Oa&&this.writer.writeByte(o&255),s&Pa?this.writer.writeShort(e.number):this.writer.writeByte(e.number),s&Ar&&this.writer.writeByte(e.modelindex),s&Lr&&this.writer.writeByte(e.modelindex2),s&Tr&&this.writer.writeByte(e.modelindex3),s&kr&&this.writer.writeByte(e.modelindex4),s&_r&&this.writer.writeByte(e.frame),s&Er&&this.writer.writeShort(e.frame),s&_t&&s&St?this.writer.writeLong(e.skinnum):s&_t?this.writer.writeByte(e.skinnum):s&St&&this.writer.writeShort(e.skinnum),s&xt&&s&wt?this.writer.writeLong(e.effects):s&xt?this.writer.writeByte(e.effects):s&wt&&this.writer.writeShort(e.effects),s&bt&&s&vt?this.writer.writeLong(e.renderfx):s&bt?this.writer.writeByte(e.renderfx):s&vt&&this.writer.writeShort(e.renderfx),s&gr&&this.writer.writeCoord(e.origin.x),s&yr&&this.writer.writeCoord(e.origin.y),s&wr&&this.writer.writeCoord(e.origin.z),s&Sr&&this.writer.writeAngle(e.angles.x),s&br&&this.writer.writeAngle(e.angles.y),s&xr&&this.writer.writeAngle(e.angles.z),s&Cr&&(this.writer.writeCoord(e.old_origin.x),this.writer.writeCoord(e.old_origin.y),this.writer.writeCoord(e.old_origin.z)),s&Ir&&this.writer.writeByte(e.sound),s&vr&&this.writer.writeByte(e.event),s&Rr&&this.writer.writeShort(e.solid),i>=2023&&(s&Mr&&this.writer.writeByte(Math.round(e.alpha*255)),s&Fr&&this.writer.writeFloat(e.scale),s&zr&&this.writer.writeLong(e.instanceBits),s&Pr&&this.writer.writeByte(Math.round(e.loopVolume*255)),o&Dr&&this.writer.writeByte(Math.round(e.loopAttenuation*255)),o&Br&&this.writer.writeShort(e.owner),o&Or&&this.writer.writeShort(e.oldFrame))}};var Ha=class{constructor(){this.writer=new Hr}writeBlock(e){this.writer.writeLong(e.byteLength),this.writer.writeBytes(e)}writeEOF(){this.writer.writeLong(-1)}getData(){return this.writer.getData()}};function Va(t,e){let r=e.bits,n=e.bitsHigh;t.number=e.number,r&Ar&&(t.modelindex=e.modelindex),r&Lr&&(t.modelindex2=e.modelindex2),r&Tr&&(t.modelindex3=e.modelindex3),r&kr&&(t.modelindex4=e.modelindex4),r&_r&&(t.frame=e.frame),r&Er&&(t.frame=e.frame),(r&_t||r&St)&&(t.skinnum=e.skinnum),(r&xt||r&wt)&&(t.effects=e.effects),(r&bt||r&vt)&&(t.renderfx=e.renderfx),r&gr&&(t.origin.x=e.origin.x),r&yr&&(t.origin.y=e.origin.y),r&wr&&(t.origin.z=e.origin.z),r&Sr&&(t.angles.x=e.angles.x),r&br&&(t.angles.y=e.angles.y),r&xr&&(t.angles.z=e.angles.z),r&Cr&&(t.old_origin.x=e.old_origin.x,t.old_origin.y=e.old_origin.y,t.old_origin.z=e.old_origin.z),r&Ir&&(t.sound=e.sound),r&vr&&(t.event=e.event),r&Rr&&(t.solid=e.solid),r&Mr&&(t.alpha=e.alpha),r&Fr&&(t.scale=e.scale),r&zr&&(t.instanceBits=e.instanceBits),r&Pr&&(t.loopVolume=e.loopVolume),n&Dr&&(t.loopAttenuation=e.loopAttenuation),n&Br&&(t.owner=e.owner),n&Or&&(t.oldFrame=e.oldFrame)}var Ga=class{extractClip(e,r,n,i){let s=new je(e.buffer),o=r.type==="frame"?r.frame:i.timeToFrame(r.seconds),a=n.type==="frame"?n.frame:i.timeToFrame(n.seconds);if(!s.seekToMessage(o))throw new Error(`Start frame ${o} out of bounds`);let u=s.getOffset(),l=e.byteLength;s.seekToMessage(a+1)&&(l=s.getOffset());let c=e.slice(u,l),f=new Uint8Array(c.length+4);return f.set(c),new DataView(f.buffer).setInt32(c.length,-1,!0),f}extractDemoRange(e,r,n){let i=new Vt;return i.loadDemo(e.buffer),this.extractClip(e,{type:"frame",frame:r},{type:"frame",frame:n},i)}async captureWorldState(e,r){let n=new Vt;n.loadDemo(e.buffer);let i={serverData:{protocol:0,serverCount:0,attractLoop:0,gameDir:"",playerNum:0,levelName:""},configStrings:new Map,entityBaselines:new Map,playerState:pn(),currentEntities:new Map,currentFrameNumber:0},s={onServerData:(a,u,l,c,f,d,h,m)=>{i.serverData={protocol:a,serverCount:u,attractLoop:l,gameDir:c,playerNum:f,levelName:d,tickRate:h,demoType:m}},onConfigString:(a,u)=>{i.configStrings.set(a,u)},onSpawnBaseline:a=>{i.entityBaselines.set(a.number,{...a})},onFrame:a=>{i.playerState={...a.playerState},i.currentFrameNumber=a.serverFrame,a.packetEntities.delta||i.currentEntities.clear();let u=new Map;if(a.packetEntities.delta)for(let[l,c]of i.currentEntities)u.set(l,c);for(let l of a.packetEntities.entities){if(l.bits&$s){u.delete(l.number);continue}let c=u.get(l.number);if(c)c={...c};else{let f=i.entityBaselines.get(l.number);f?c={...f}:(c=Ht(),c.number=l.number)}Va(c,l),u.set(l.number,c)}i.currentEntities=u},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}};n.setHandler(s);let o=r.type==="frame"?r.frame:n.timeToFrame(r.seconds);return n.seek(o),i}extractStandaloneClip(e,r,n,i){let s=new Ha,o=new Ys,a=new Vt;a.loadDemo(e.buffer);let u=r.type==="frame"?r.frame:a.timeToFrame(r.seconds),l=n.type==="frame"?n.frame:a.timeToFrame(n.seconds),{serverData:c}=i;c.protocol>=2023?o.writeServerDataRerelease(c.protocol,c.serverCount,c.demoType||0,c.tickRate||10,c.gameDir,c.playerNum,c.levelName):o.writeServerData(c.protocol,c.serverCount,c.attractLoop,c.gameDir,c.playerNum,c.levelName);for(let[g,p]of i.configStrings)o.writeConfigString(g,p);for(let g of i.entityBaselines.values())o.writeSpawnBaseline(g,c.protocol);let f=Array.from(i.currentEntities.values()),d={serverFrame:0,deltaFrame:-1,surpressCount:0,areaBytes:0,areaBits:new Uint8Array(0),playerState:i.playerState,packetEntities:{delta:!1,entities:f}};o.writeFrame(d,c.protocol),s.writeBlock(o.getData());let h=new Map;h.set(u,0);let m=new je(e.buffer);if(m.seekToMessage(u+1)){let g=u+1;for(;g<=l&&m.nextBlock();){let y=m.getBlock().data,_=new Ys,x={onServerData:()=>{},onConfigString:(S,w)=>_.writeConfigString(S,w),onSpawnBaseline:S=>_.writeSpawnBaseline(S,c.protocol),onCenterPrint:S=>_.writeCenterPrint(S),onStuffText:S=>_.writeStuffText(S),onPrint:(S,w)=>_.writePrint(S,w),onSound:(S,w,M,L,A,T,I)=>_.writeSound(S,w,M,L,A,T,I),onLayout:S=>_.writeLayout(S),onInventory:S=>_.writeInventory(S),onMuzzleFlash:(S,w)=>_.writeMuzzleFlash(S,w),onMuzzleFlash2:(S,w)=>_.writeMuzzleFlash2(S,w),onTempEntity:(S,w,M,L,A,T,I,z,C)=>_.writeTempEntity(S,w,M,L,A,T,I,z,C),onDisconnect:()=>_.writeDisconnect(),onReconnect:()=>_.writeReconnect(),onDownload:()=>{},onFrame:S=>{let w=S.serverFrame,M=S.deltaFrame,L=g-u,A=-1;h.has(M)?A=h.get(M):S.packetEntities.delta=!1,h.set(w,L),S.serverFrame=L,S.deltaFrame=A,_.writeFrame(S,c.protocol)}},b=new it(y,x,!1);b.setProtocolVersion(c.protocol),b.parseMessage();let v=_.getData();v.byteLength>0&&s.writeBlock(v),g++}}return s.writeEOF(),s.getData()}};var Xc=(d=>(d.Unknown="unknown",d.BSP="bsp",d.MD2="md2",d.MD3="md3",d.WAL="wal",d.PCX="pcx",d.TGA="tga",d.WAV="wav",d.OGG="ogg",d.TXT="txt",d.CFG="cfg",d.DEM="dem",d))(Xc||{}),wh={".bsp":"bsp",".md2":"md2",".md3":"md3",".wal":"wal",".pcx":"pcx",".tga":"tga",".wav":"wav",".ogg":"ogg",".txt":"txt",".cfg":"cfg",".dm2":"dem"};function qs(t,e){if(t.length<e.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r])return!1;return!0}var Jb=[73,66,83,80],ex=[73,68,80,50],tx=[73,68,80,51];var rx=[82,73,70,70];var nx=[79,103,103,83];function Kc(t,e){let r=t.slice(t.lastIndexOf(".")).toLowerCase();if(e){if(qs(e,Jb))return"bsp";if(qs(e,ex))return"md2";if(qs(e,tx))return"md3";if(qs(e,nx))return"ogg";if(e.length>128&&e[0]===10&&e[1]<6)return"pcx";if(qs(e,rx)&&e.length>=12&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69)return"wav"}return wh[r]?wh[r]:"unknown"}function $c(t){let e=Kc(t);return e==="txt"||e==="cfg"}function Sh(t){return!$c(t)}function ix(t,e,r,n,i){let s=new Uint8ClampedArray(n*i*4),o=e/n,a=r/i;for(let u=0;u<i;u++)for(let l=0;l<n;l++){let c=l*o,f=u*a,d=Math.floor(c),h=Math.floor(f),m=c-d,g=f-h,p=Math.min(d+1,e-1),y=Math.min(h+1,r-1),_=(h*e+d)*4,x=(h*e+p)*4,b=(y*e+d)*4,v=(y*e+p)*4,S=(u*n+l)*4;for(let w=0;w<4;w++){let M=t[_+w],L=t[x+w],A=t[b+w],T=t[v+w],I=M*(1-m)+L*m,z=A*(1-m)+T*m,C=I*(1-g)+z*g;s[S+w]=C}}return s}function sx(t,e,r,n,i,s,o,a,u,l,c){n=Math.floor(n),i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);let f=Math.abs(s-n),d=Math.abs(o-i),h=n<s?1:-1,m=i<o?1:-1,g=f-d;for(;;){if(n>=0&&n<e&&i>=0&&i<r){let y=(i*e+n)*4,_=1-c/255;t[y]=a*(c/255)+t[y]*_,t[y+1]=u*(c/255)+t[y+1]*_,t[y+2]=l*(c/255)+t[y+2]*_,t[y+3]=255}if(n===s&&i===o)break;let p=2*g;p>-d&&(g-=d,n+=h),p<f&&(g+=f,i+=m)}}function Ah(t,e,r,n,i){let a=(t.x-n.x)*.707-(t.y-n.y)*.707,u=(t.x-n.x)*.707+(t.y-n.y)*.707,l=t.z-n.z,c=.866,f=.5,d=u*c-l*f,h=u*f+l*c,m=e/2+a*i,g=r/2-h*i;return{x:m,y:g}}var Wa=class{constructor(e){this.assetManager=e}async generateTextureThumbnail(e,r){try{let n=await this.assetManager.loadTexture(e);if(!n||n.levels.length===0)return null;let i=n.levels[0],s=i.width/i.height,o=r,a=r;s>1?a=Math.floor(r/s):o=Math.floor(r*s),o=Math.max(1,o),a=Math.max(1,a);let u=ix(i.rgba,i.width,i.height,o,a);return new ImageData(u,o,a)}catch(n){return console.error(`Failed to generate thumbnail for ${e}`,n),null}}async generateModelThumbnail(e,r){try{let n=[],i=[],s=e.split(".").pop()?.toLowerCase();if(s==="md2"){let p=await this.assetManager.loadMd2Model(e);if(!p||p.frames.length===0)return null;n=p.frames[0].vertices.map(_=>_.position);for(let _ of p.triangles)i.push(_.vertexIndices[0],_.vertexIndices[1]),i.push(_.vertexIndices[1],_.vertexIndices[2]),i.push(_.vertexIndices[2],_.vertexIndices[0])}else if(s==="md3"){let p=await this.assetManager.loadMd3Model(e);if(!p||p.surfaces.length===0)return null;let y=0;for(let _ of p.surfaces){if(_.vertices.length===0)continue;let x=_.vertices[0];n.push(...x.map(b=>({x:b.position.x,y:b.position.y,z:b.position.z})));for(let b of _.triangles)i.push(y+b.indices[0],y+b.indices[1]),i.push(y+b.indices[1],y+b.indices[2]),i.push(y+b.indices[2],y+b.indices[0]);y+=x.length}}else return null;if(n.length===0)return null;let o={x:1/0,y:1/0,z:1/0},a={x:-1/0,y:-1/0,z:-1/0};for(let p of n)o.x=Math.min(o.x,p.x),o.y=Math.min(o.y,p.y),o.z=Math.min(o.z,p.z),a.x=Math.max(a.x,p.x),a.y=Math.max(a.y,p.y),a.z=Math.max(a.z,p.z);let u={x:(o.x+a.x)/2,y:(o.y+a.y)/2,z:(o.z+a.z)/2},l=a.x-o.x,c=a.y-o.y,f=a.z-o.z,d=Math.max(l,c,f),h=Math.max(d,.001),m=r*.8/h,g=new Uint8ClampedArray(r*r*4);for(let p=0;p<i.length;p+=2){let y=i[p],_=i[p+1],x=n[y],b=n[_],v=Ah(x,r,r,u,m),S=Ah(b,r,r,u,m);sx(g,r,r,v.x,v.y,S.x,S.y,0,255,0,255)}return new ImageData(g,r,r)}catch(n){return console.error(`Failed to generate model thumbnail for ${e}`,n),null}}async getMapBounds(e,r){try{let n=Ai(r);if(n.models.length>0){let i=n.models[0];return{mins:{x:i.mins[0],y:i.mins[1],z:i.mins[2]},maxs:{x:i.maxs[0],y:i.maxs[1],z:i.maxs[2]}}}return null}catch(n){return console.error("Failed to get map bounds",n),null}}async extractMapScreenshot(e){return null}};var Xa=class{constructor(e){this.loader=e}async getMapStatistics(e){let r=await this.loader.load(e),n=r.faces.filter(o=>o.lightOffset!==-1).length,i=r.models[0],s=i?{mins:i.mins,maxs:i.maxs}:{mins:[0,0,0],maxs:[0,0,0]};return{entityCount:r.entities.entities.length,surfaceCount:r.faces.length,lightmapCount:n,vertexCount:r.vertices.length,bounds:s}}async getUsedTextures(e){let r=await this.loader.load(e),n=new Set;for(let i of r.texInfo)i.texture&&n.add(i.texture);return Array.from(n).sort()}async getUsedModels(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities)i.properties.model&&!i.properties.model.startsWith("*")&&n.add(i.properties.model);return Array.from(n).sort()}async getUsedSounds(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities){i.properties.noise&&n.add(i.properties.noise);for(let[s,o]of Object.entries(i.properties))(s==="noise"||s.endsWith("_sound")||s==="sound")&&typeof o=="string"&&n.add(o)}return Array.from(n).sort()}};function Mh(t){let e=[],r=0,n=t.length;function i(){for(;r<n&&/\s/.test(t[r]);)r++}function s(){if(i(),r>=n)return null;if(t[r]==='"'){r++;let o=r;for(;r<n&&t[r]!=='"';)t[r],r++;let a=t.substring(o,r);return r++,a}else{if(t[r]==="{"||t[r]==="}")return t[r++];{if(t.startsWith("//",r)){for(;r<n&&t[r]!==`
582
+ }`,va=class{constructor(e,r){this.vertexCapacity=0;this.indexCapacity=0;this.gl=e,this.system=r,this.program=Le.create(e,{vertex:cc,fragment:uc}),this.vertexBuffer=new Te(e,e.DYNAMIC_DRAW),this.indexBuffer=new xe(e,e.DYNAMIC_DRAW),this.vertexArray=new Re(e),this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:36,offset:0},{index:1,size:2,type:e.FLOAT,stride:36,offset:12},{index:2,size:4,type:e.FLOAT,stride:36,offset:20}],this.vertexBuffer)}get shaderSize(){return this.program.sourceSize}render(e){let r=this.system.buildMesh(e.viewRight,e.viewUp);if(r.indices.length===0)return;let n=r.vertices;r.vertices.byteLength>this.vertexCapacity?(this.vertexCapacity=r.vertices.byteLength,this.vertexBuffer.upload(n,this.gl.DYNAMIC_DRAW)):this.vertexBuffer.update(n);let i=r.indices;r.indices.byteLength>this.indexCapacity?(this.indexCapacity=r.indices.byteLength,this.indexBuffer.upload(i,this.gl.DYNAMIC_DRAW)):this.indexBuffer.update(i),this.gl.depthMask(!1),this.program.use();let s=this.program.getUniformLocation("u_viewProjection");this.gl.uniformMatrix4fv(s,!1,e.viewProjection),this.vertexArray.bind();for(let o of r.batches)o.blendMode==="additive"?this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.drawElements(this.gl.TRIANGLES,o.count,this.gl.UNSIGNED_SHORT,o.start*2);this.gl.depthMask(!0)}dispose(){this.program.dispose(),this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose()}};function Zd(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<12;i+=1){let s=200+e.rng.frandom()*180,o=e.rng.frandom()*.35;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*80,y:n.y*s+(e.rng.frandom()-.5)*80,z:Math.max(n.z*s,120)+o*80},color:[1,.8,.4,1],size:2.5,lifetime:.45+e.rng.frandom()*.1,gravity:600,damping:2,bounce:.45,blendMode:"additive",fade:!0})}for(let i=0;i<8;i+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*40,y:(e.rng.frandom()-.5)*40,z:80+e.rng.frandom()*40},color:[.45,.45,.45,.75],size:6,lifetime:.6,gravity:200,damping:4,bounce:.15,blendMode:"alpha",fade:!0})}function Yd(t){let{system:e,origin:r}=t;for(let n=0;n<40;n+=1){let i=e.rng.frandom()*Math.PI*2,s=Math.acos(2*e.rng.frandom()-1),o=220+e.rng.frandom()*260,a={x:Math.sin(s)*Math.cos(i),y:Math.sin(s)*Math.sin(i),z:Math.cos(s)};e.spawn({position:r,velocity:{x:a.x*o,y:a.y*o,z:a.z*o},color:[1,.6,.2,1],size:5,lifetime:.9,gravity:700,damping:1,bounce:.35,blendMode:"additive",fade:!0})}for(let n=0;n<16;n+=1)e.spawn({position:r,velocity:{x:(e.rng.frandom()-.5)*30,y:(e.rng.frandom()-.5)*30,z:120+e.rng.frandom()*120},color:[.25,.25,.25,.9],size:12,lifetime:1.2,gravity:300,damping:3,blendMode:"alpha",fade:!0})}function qd(t){let{system:e,origin:r,direction:n={x:0,y:0,z:1}}=t;for(let i=0;i<24;i+=1){let s=120+e.rng.frandom()*180;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*70,y:n.y*s+(e.rng.frandom()-.5)*70,z:n.z*s+e.rng.frandom()*80},color:[.6,0,0,.95],size:3,lifetime:.8,gravity:900,damping:1,bounce:.2,blendMode:"alpha",fade:!0})}}function jd(t){let{system:e,origin:r}=t;for(let n=0;n<30;n+=1){let i=e.rng.frandom()*Math.PI*2,s=8+e.rng.frandom()*8;e.spawn({position:r,velocity:{x:Math.cos(i)*s,y:Math.sin(i)*s,z:100+e.rng.frandom()*80},color:[.4,.6,1,.9],size:4,lifetime:.5,gravity:300,damping:2,blendMode:"additive",fade:!0})}}function Qd(t){let{system:e,origin:r,direction:n={x:1,y:0,z:0}}=t;for(let i=0;i<10;i+=1){let s=350+e.rng.frandom()*100;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*30,y:n.y*s+(e.rng.frandom()-.5)*30,z:n.z*s+(e.rng.frandom()-.5)*30},color:[1,.8,.3,1],size:3,lifetime:.25,gravity:200,damping:1,blendMode:"additive",fade:!0})}}function Jd(t){let{system:e,origin:r,direction:n={x:0,y:0,z:0}}=t;for(let i=0;i<6;i+=1)e.spawn({position:{x:r.x+n.x*i*2,y:r.y+n.y*i*2,z:r.z+n.z*i*2},velocity:{x:(e.rng.frandom()-.5)*15,y:(e.rng.frandom()-.5)*15,z:20+e.rng.frandom()*15},color:[.6,.6,.6,.8],size:2.2,lifetime:.6,gravity:200,damping:1.5,blendMode:"alpha",fade:!0})}function ef(t){let{system:e,origin:r,normal:n={x:0,y:0,z:1}}=t;for(let i=0;i<30;i+=1){let s=100+e.rng.frandom()*150;e.spawn({position:r,velocity:{x:n.x*s+(e.rng.frandom()-.5)*80,y:n.y*s+(e.rng.frandom()-.5)*80,z:100+e.rng.frandom()*120},color:[.5,.6,.8,.5],size:3,lifetime:.5+e.rng.frandom()*.3,gravity:800,damping:1.5,blendMode:"alpha",fade:!0})}}function tf(t){let{system:e,origin:r}=t;for(let n=0;n<8;n+=1)e.spawn({position:{x:r.x+(e.rng.frandom()-.5)*10,y:r.y+(e.rng.frandom()-.5)*10,z:r.z+(e.rng.frandom()-.5)*10},velocity:{x:(e.rng.frandom()-.5)*20,y:(e.rng.frandom()-.5)*20,z:40+e.rng.frandom()*20},color:[.8,.8,.8,.3],size:5+e.rng.frandom()*4,lifetime:1.5+e.rng.frandom()*.5,gravity:-50,damping:.5,blendMode:"alpha",fade:!0})}var je=class{constructor(e){this.messageOffsets=[];this.currentBlock=null;this.buffer=e,this.view=new DataView(e),this.offset=0,this.scan()}scan(){let e=0;for(this.messageOffsets=[];e+4<=this.buffer.byteLength;){let r=this.view.getInt32(e,!0);if(r===-1)break;if(r<0||r>2097152){console.warn(`DemoReader: Invalid block length ${r} at offset ${e} during scan`);break}if(e+4+r>this.buffer.byteLength){console.warn(`DemoReader: Incomplete block at offset ${e} during scan`);break}this.messageOffsets.push(e),e+=4+r}}hasMore(){return this.offset<this.buffer.byteLength}readNextBlock(){if(this.offset+4>this.buffer.byteLength)return null;let e=this.view.getInt32(this.offset,!0);if(e===-1||e<0||this.offset+4+e>this.buffer.byteLength)return null;this.offset+=4;let r=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,{length:e,data:new vn(r)}}nextBlock(){let e=this.readNextBlock();return e?(this.currentBlock=e,!0):(this.currentBlock=null,!1)}getBlock(){if(!this.currentBlock)throw new Error("No current block. Call nextBlock() first.");return this.currentBlock}readAllBlocksToBuffer(){let e=0,r=this.offset,n=[],i=this.offset;for(;i+4<=this.buffer.byteLength;){let u=this.view.getInt32(i,!0);if(u===-1||u<0||i+4+u>this.buffer.byteLength)break;n.push({offset:i+4,length:u}),e+=u,i+=4+u}let s=new Uint8Array(e),o=0,a=new Uint8Array(this.buffer);for(let u of n)s.set(a.subarray(u.offset,u.offset+u.length),o),o+=u.length;return this.offset=i,s.buffer}reset(){this.offset=0,this.currentBlock=null}seekToMessage(e){return e<0||e>=this.messageOffsets.length?!1:(this.offset=this.messageOffsets[e],this.currentBlock=null,!0)}getMessageCount(){return this.messageOffsets.length}getOffset(){return this.offset}getProgress(){let e=this.offset,r=this.buffer.byteLength;return{current:e,total:r,percent:r>0?e/r*100:0}}};function ci(t){let e=t.length;for(;--e>=0;)t[e]=0}var eg=0,Hf=1,tg=2,rg=3,ng=258,zc=29,Vs=256,zs=Vs+1+zc,oi=30,Pc=19,Vf=2*zs+1,an=15,dc=16,ig=7,Dc=256,Gf=16,Wf=17,Xf=18,Mc=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),La=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),sg=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Kf=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),og=512,Nt=new Array((zs+2)*2);ci(Nt);var Is=new Array(oi*2);ci(Is);var Ps=new Array(og);ci(Ps);var Ds=new Array(ng-rg+1);ci(Ds);var Bc=new Array(zc);ci(Bc);var Ta=new Array(oi);ci(Ta);function fc(t,e,r,n,i){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=t&&t.length}var $f,Zf,Yf;function hc(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}var qf=t=>t<256?Ps[t]:Ps[256+(t>>>7)],Bs=(t,e)=>{t.pending_buf[t.pending++]=e&255,t.pending_buf[t.pending++]=e>>>8&255},Fe=(t,e,r)=>{t.bi_valid>dc-r?(t.bi_buf|=e<<t.bi_valid&65535,Bs(t,t.bi_buf),t.bi_buf=e>>dc-t.bi_valid,t.bi_valid+=r-dc):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=r)},pt=(t,e,r)=>{Fe(t,r[e*2],r[e*2+1])},jf=(t,e)=>{let r=0;do r|=t&1,t>>>=1,r<<=1;while(--e>0);return r>>>1},ag=t=>{t.bi_valid===16?(Bs(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=t.bi_buf&255,t.bi_buf>>=8,t.bi_valid-=8)},lg=(t,e)=>{let r=e.dyn_tree,n=e.max_code,i=e.stat_desc.static_tree,s=e.stat_desc.has_stree,o=e.stat_desc.extra_bits,a=e.stat_desc.extra_base,u=e.stat_desc.max_length,l,c,f,d,h,m,g=0;for(d=0;d<=an;d++)t.bl_count[d]=0;for(r[t.heap[t.heap_max]*2+1]=0,l=t.heap_max+1;l<Vf;l++)c=t.heap[l],d=r[r[c*2+1]*2+1]+1,d>u&&(d=u,g++),r[c*2+1]=d,!(c>n)&&(t.bl_count[d]++,h=0,c>=a&&(h=o[c-a]),m=r[c*2],t.opt_len+=m*(d+h),s&&(t.static_len+=m*(i[c*2+1]+h)));if(g!==0){do{for(d=u-1;t.bl_count[d]===0;)d--;t.bl_count[d]--,t.bl_count[d+1]+=2,t.bl_count[u]--,g-=2}while(g>0);for(d=u;d!==0;d--)for(c=t.bl_count[d];c!==0;)f=t.heap[--l],!(f>n)&&(r[f*2+1]!==d&&(t.opt_len+=(d-r[f*2+1])*r[f*2],r[f*2+1]=d),c--)}},Qf=(t,e,r)=>{let n=new Array(an+1),i=0,s,o;for(s=1;s<=an;s++)i=i+r[s-1]<<1,n[s]=i;for(o=0;o<=e;o++){let a=t[o*2+1];a!==0&&(t[o*2]=jf(n[a]++,a))}},cg=()=>{let t,e,r,n,i,s=new Array(an+1);for(r=0,n=0;n<zc-1;n++)for(Bc[n]=r,t=0;t<1<<Mc[n];t++)Ds[r++]=n;for(Ds[r-1]=n,i=0,n=0;n<16;n++)for(Ta[n]=i,t=0;t<1<<La[n];t++)Ps[i++]=n;for(i>>=7;n<oi;n++)for(Ta[n]=i<<7,t=0;t<1<<La[n]-7;t++)Ps[256+i++]=n;for(e=0;e<=an;e++)s[e]=0;for(t=0;t<=143;)Nt[t*2+1]=8,t++,s[8]++;for(;t<=255;)Nt[t*2+1]=9,t++,s[9]++;for(;t<=279;)Nt[t*2+1]=7,t++,s[7]++;for(;t<=287;)Nt[t*2+1]=8,t++,s[8]++;for(Qf(Nt,zs+1,s),t=0;t<oi;t++)Is[t*2+1]=5,Is[t*2]=jf(t,5);$f=new fc(Nt,Mc,Vs+1,zs,an),Zf=new fc(Is,La,0,oi,an),Yf=new fc(new Array(0),sg,0,Pc,ig)},Jf=t=>{let e;for(e=0;e<zs;e++)t.dyn_ltree[e*2]=0;for(e=0;e<oi;e++)t.dyn_dtree[e*2]=0;for(e=0;e<Pc;e++)t.bl_tree[e*2]=0;t.dyn_ltree[Dc*2]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},eh=t=>{t.bi_valid>8?Bs(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},rf=(t,e,r,n)=>{let i=e*2,s=r*2;return t[i]<t[s]||t[i]===t[s]&&n[e]<=n[r]},mc=(t,e,r)=>{let n=t.heap[r],i=r<<1;for(;i<=t.heap_len&&(i<t.heap_len&&rf(e,t.heap[i+1],t.heap[i],t.depth)&&i++,!rf(e,n,t.heap[i],t.depth));)t.heap[r]=t.heap[i],r=i,i<<=1;t.heap[r]=n},nf=(t,e,r)=>{let n,i,s=0,o,a;if(t.sym_next!==0)do n=t.pending_buf[t.sym_buf+s++]&255,n+=(t.pending_buf[t.sym_buf+s++]&255)<<8,i=t.pending_buf[t.sym_buf+s++],n===0?pt(t,i,e):(o=Ds[i],pt(t,o+Vs+1,e),a=Mc[o],a!==0&&(i-=Bc[o],Fe(t,i,a)),n--,o=qf(n),pt(t,o,r),a=La[o],a!==0&&(n-=Ta[o],Fe(t,n,a)));while(s<t.sym_next);pt(t,Dc,e)},Ec=(t,e)=>{let r=e.dyn_tree,n=e.stat_desc.static_tree,i=e.stat_desc.has_stree,s=e.stat_desc.elems,o,a,u=-1,l;for(t.heap_len=0,t.heap_max=Vf,o=0;o<s;o++)r[o*2]!==0?(t.heap[++t.heap_len]=u=o,t.depth[o]=0):r[o*2+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=u<2?++u:0,r[l*2]=1,t.depth[l]=0,t.opt_len--,i&&(t.static_len-=n[l*2+1]);for(e.max_code=u,o=t.heap_len>>1;o>=1;o--)mc(t,r,o);l=s;do o=t.heap[1],t.heap[1]=t.heap[t.heap_len--],mc(t,r,1),a=t.heap[1],t.heap[--t.heap_max]=o,t.heap[--t.heap_max]=a,r[l*2]=r[o*2]+r[a*2],t.depth[l]=(t.depth[o]>=t.depth[a]?t.depth[o]:t.depth[a])+1,r[o*2+1]=r[a*2+1]=l,t.heap[1]=l++,mc(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],lg(t,e),Qf(r,u,t.bl_count)},sf=(t,e,r)=>{let n,i=-1,s,o=e[1],a=0,u=7,l=4;for(o===0&&(u=138,l=3),e[(r+1)*2+1]=65535,n=0;n<=r;n++)s=o,o=e[(n+1)*2+1],!(++a<u&&s===o)&&(a<l?t.bl_tree[s*2]+=a:s!==0?(s!==i&&t.bl_tree[s*2]++,t.bl_tree[Gf*2]++):a<=10?t.bl_tree[Wf*2]++:t.bl_tree[Xf*2]++,a=0,i=s,o===0?(u=138,l=3):s===o?(u=6,l=3):(u=7,l=4))},of=(t,e,r)=>{let n,i=-1,s,o=e[1],a=0,u=7,l=4;for(o===0&&(u=138,l=3),n=0;n<=r;n++)if(s=o,o=e[(n+1)*2+1],!(++a<u&&s===o)){if(a<l)do pt(t,s,t.bl_tree);while(--a!==0);else s!==0?(s!==i&&(pt(t,s,t.bl_tree),a--),pt(t,Gf,t.bl_tree),Fe(t,a-3,2)):a<=10?(pt(t,Wf,t.bl_tree),Fe(t,a-3,3)):(pt(t,Xf,t.bl_tree),Fe(t,a-11,7));a=0,i=s,o===0?(u=138,l=3):s===o?(u=6,l=3):(u=7,l=4)}},ug=t=>{let e;for(sf(t,t.dyn_ltree,t.l_desc.max_code),sf(t,t.dyn_dtree,t.d_desc.max_code),Ec(t,t.bl_desc),e=Pc-1;e>=3&&t.bl_tree[Kf[e]*2+1]===0;e--);return t.opt_len+=3*(e+1)+5+5+4,e},dg=(t,e,r,n)=>{let i;for(Fe(t,e-257,5),Fe(t,r-1,5),Fe(t,n-4,4),i=0;i<n;i++)Fe(t,t.bl_tree[Kf[i]*2+1],3);of(t,t.dyn_ltree,e-1),of(t,t.dyn_dtree,r-1)},fg=t=>{let e=4093624447,r;for(r=0;r<=31;r++,e>>>=1)if(e&1&&t.dyn_ltree[r*2]!==0)return 0;if(t.dyn_ltree[18]!==0||t.dyn_ltree[20]!==0||t.dyn_ltree[26]!==0)return 1;for(r=32;r<Vs;r++)if(t.dyn_ltree[r*2]!==0)return 1;return 0},af=!1,hg=t=>{af||(cg(),af=!0),t.l_desc=new hc(t.dyn_ltree,$f),t.d_desc=new hc(t.dyn_dtree,Zf),t.bl_desc=new hc(t.bl_tree,Yf),t.bi_buf=0,t.bi_valid=0,Jf(t)},th=(t,e,r,n)=>{Fe(t,(eg<<1)+(n?1:0),3),eh(t),Bs(t,r),Bs(t,~r),r&&t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r},mg=t=>{Fe(t,Hf<<1,3),pt(t,Dc,Nt),ag(t)},pg=(t,e,r,n)=>{let i,s,o=0;t.level>0?(t.strm.data_type===2&&(t.strm.data_type=fg(t)),Ec(t,t.l_desc),Ec(t,t.d_desc),o=ug(t),i=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=i&&(i=s)):i=s=r+5,r+4<=i&&e!==-1?th(t,e,r,n):t.strategy===4||s===i?(Fe(t,(Hf<<1)+(n?1:0),3),nf(t,Nt,Is)):(Fe(t,(tg<<1)+(n?1:0),3),dg(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),nf(t,t.dyn_ltree,t.dyn_dtree)),Jf(t),n&&eh(t)},gg=(t,e,r)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=r,e===0?t.dyn_ltree[r*2]++:(t.matches++,e--,t.dyn_ltree[(Ds[r]+Vs+1)*2]++,t.dyn_dtree[qf(e)*2]++),t.sym_next===t.sym_end),yg=hg,bg=th,xg=pg,_g=gg,vg=mg,wg={_tr_init:yg,_tr_stored_block:bg,_tr_flush_block:xg,_tr_tally:_g,_tr_align:vg},Sg=(t,e,r,n)=>{let i=t&65535|0,s=t>>>16&65535|0,o=0;for(;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+e[n++]|0,s=s+i|0;while(--o);i%=65521,s%=65521}return i|s<<16|0},Os=Sg,Ag=()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;e[r]=t}return e},Mg=new Uint32Array(Ag()),Eg=(t,e,r,n)=>{let i=Mg,s=n+r;t^=-1;for(let o=n;o<s;o++)t=t>>>8^i[(t^e[o])&255];return t^-1},he=Eg,un={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},hn={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:Lg,_tr_stored_block:Lc,_tr_flush_block:Tg,_tr_tally:hr,_tr_align:kg}=wg,{Z_NO_FLUSH:mr,Z_PARTIAL_FLUSH:Cg,Z_FULL_FLUSH:Ig,Z_FINISH:Qe,Z_BLOCK:lf,Z_OK:me,Z_STREAM_END:cf,Z_STREAM_ERROR:gt,Z_DATA_ERROR:Rg,Z_BUF_ERROR:pc,Z_DEFAULT_COMPRESSION:Fg,Z_FILTERED:zg,Z_HUFFMAN_ONLY:wa,Z_RLE:Pg,Z_FIXED:Dg,Z_DEFAULT_STRATEGY:Bg,Z_UNKNOWN:Og,Z_DEFLATED:Ia}=hn,Ng=9,Ug=15,Hg=8,Vg=29,Gg=256,Tc=Gg+1+Vg,Wg=30,Xg=19,Kg=2*Tc+1,$g=15,W=3,fr=258,yt=fr+W+1,Zg=32,ai=42,Oc=57,kc=69,Cc=73,Ic=91,Rc=103,ln=113,ks=666,ke=1,ui=2,dn=3,di=4,Yg=3,cn=(t,e)=>(t.msg=un[e],e),uf=t=>t*2-(t>4?9:0),dr=t=>{let e=t.length;for(;--e>=0;)t[e]=0},qg=t=>{let e,r,n,i=t.w_size;e=t.hash_size,n=e;do r=t.head[--n],t.head[n]=r>=i?r-i:0;while(--e);e=i,n=e;do r=t.prev[--n],t.prev[n]=r>=i?r-i:0;while(--e)},jg=(t,e,r)=>(e<<t.hash_shift^r)&t.hash_mask,pr=jg,Ne=t=>{let e=t.state,r=e.pending;r>t.avail_out&&(r=t.avail_out),r!==0&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,e.pending===0&&(e.pending_out=0))},Ue=(t,e)=>{Tg(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Ne(t.strm)},Z=(t,e)=>{t.pending_buf[t.pending++]=e},Ts=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=e&255},Fc=(t,e,r,n)=>{let i=t.avail_in;return i>n&&(i=n),i===0?0:(t.avail_in-=i,e.set(t.input.subarray(t.next_in,t.next_in+i),r),t.state.wrap===1?t.adler=Os(t.adler,e,i,r):t.state.wrap===2&&(t.adler=he(t.adler,e,i,r)),t.next_in+=i,t.total_in+=i,i)},rh=(t,e)=>{let r=t.max_chain_length,n=t.strstart,i,s,o=t.prev_length,a=t.nice_match,u=t.strstart>t.w_size-yt?t.strstart-(t.w_size-yt):0,l=t.window,c=t.w_mask,f=t.prev,d=t.strstart+fr,h=l[n+o-1],m=l[n+o];t.prev_length>=t.good_match&&(r>>=2),a>t.lookahead&&(a=t.lookahead);do if(i=e,!(l[i+o]!==m||l[i+o-1]!==h||l[i]!==l[n]||l[++i]!==l[n+1])){n+=2,i++;do;while(l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&l[++n]===l[++i]&&n<d);if(s=fr-(d-n),n=d-fr,s>o){if(t.match_start=e,o=s,s>=a)break;h=l[n+o-1],m=l[n+o]}}while((e=f[e&c])>u&&--r!==0);return o<=t.lookahead?o:t.lookahead},li=t=>{let e=t.w_size,r,n,i;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-yt)&&(t.window.set(t.window.subarray(e,e+e-n),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),qg(t),n+=e),t.strm.avail_in===0)break;if(r=Fc(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=r,t.lookahead+t.insert>=W)for(i=t.strstart-t.insert,t.ins_h=t.window[i],t.ins_h=pr(t,t.ins_h,t.window[i+1]);t.insert&&(t.ins_h=pr(t,t.ins_h,t.window[i+W-1]),t.prev[i&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=i,i++,t.insert--,!(t.lookahead+t.insert<W)););}while(t.lookahead<yt&&t.strm.avail_in!==0)},nh=(t,e)=>{let r=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,n,i,s,o=0,a=t.strm.avail_in;do{if(n=65535,s=t.bi_valid+42>>3,t.strm.avail_out<s||(s=t.strm.avail_out-s,i=t.strstart-t.block_start,n>i+t.strm.avail_in&&(n=i+t.strm.avail_in),n>s&&(n=s),n<r&&(n===0&&e!==Qe||e===mr||n!==i+t.strm.avail_in)))break;o=e===Qe&&n===i+t.strm.avail_in?1:0,Lc(t,0,0,o),t.pending_buf[t.pending-4]=n,t.pending_buf[t.pending-3]=n>>8,t.pending_buf[t.pending-2]=~n,t.pending_buf[t.pending-1]=~n>>8,Ne(t.strm),i&&(i>n&&(i=n),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,n-=i),n&&(Fc(t.strm,t.strm.output,t.strm.next_out,n),t.strm.next_out+=n,t.strm.avail_out-=n,t.strm.total_out+=n)}while(o===0);return a-=t.strm.avail_in,a&&(a>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=a&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-a,t.strm.next_in),t.strstart),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),o?di:e!==mr&&e!==Qe&&t.strm.avail_in===0&&t.strstart===t.block_start?ui:(s=t.window_size-t.strstart,t.strm.avail_in>s&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,s+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),s>t.strm.avail_in&&(s=t.strm.avail_in),s&&(Fc(t.strm,t.window,t.strstart,s),t.strstart+=s,t.insert+=s>t.w_size-t.insert?t.w_size-t.insert:s),t.high_water<t.strstart&&(t.high_water=t.strstart),s=t.bi_valid+42>>3,s=t.pending_buf_size-s>65535?65535:t.pending_buf_size-s,r=s>t.w_size?t.w_size:s,i=t.strstart-t.block_start,(i>=r||(i||e===Qe)&&e!==mr&&t.strm.avail_in===0&&i<=s)&&(n=i>s?s:i,o=e===Qe&&t.strm.avail_in===0&&n===i?1:0,Lc(t,t.block_start,n,o),t.block_start+=n,Ne(t.strm)),o?dn:ke)},gc=(t,e)=>{let r,n;for(;;){if(t.lookahead<yt){if(li(t),t.lookahead<yt&&e===mr)return ke;if(t.lookahead===0)break}if(r=0,t.lookahead>=W&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),r!==0&&t.strstart-r<=t.w_size-yt&&(t.match_length=rh(t,r)),t.match_length>=W)if(n=hr(t,t.strstart-t.match_start,t.match_length-W),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=W){t.match_length--;do t.strstart++,t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart;while(--t.match_length!==0);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=pr(t,t.ins_h,t.window[t.strstart+1]);else n=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=t.strstart<W-1?t.strstart:W-1,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},ii=(t,e)=>{let r,n,i;for(;;){if(t.lookahead<yt){if(li(t),t.lookahead<yt&&e===mr)return ke;if(t.lookahead===0)break}if(r=0,t.lookahead>=W&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=W-1,r!==0&&t.prev_length<t.max_lazy_match&&t.strstart-r<=t.w_size-yt&&(t.match_length=rh(t,r),t.match_length<=5&&(t.strategy===zg||t.match_length===W&&t.strstart-t.match_start>4096)&&(t.match_length=W-1)),t.prev_length>=W&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-W,n=hr(t,t.strstart-1-t.prev_match,t.prev_length-W),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=i&&(t.ins_h=pr(t,t.ins_h,t.window[t.strstart+W-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart);while(--t.prev_length!==0);if(t.match_available=0,t.match_length=W-1,t.strstart++,n&&(Ue(t,!1),t.strm.avail_out===0))return ke}else if(t.match_available){if(n=hr(t,0,t.window[t.strstart-1]),n&&Ue(t,!1),t.strstart++,t.lookahead--,t.strm.avail_out===0)return ke}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=hr(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<W-1?t.strstart:W-1,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},Qg=(t,e)=>{let r,n,i,s,o=t.window;for(;;){if(t.lookahead<=fr){if(li(t),t.lookahead<=fr&&e===mr)return ke;if(t.lookahead===0)break}if(t.match_length=0,t.lookahead>=W&&t.strstart>0&&(i=t.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){s=t.strstart+fr;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<s);t.match_length=fr-(s-i),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=W?(r=hr(t,1,t.match_length-W),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=0,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui},Jg=(t,e)=>{let r;for(;;){if(t.lookahead===0&&(li(t),t.lookahead===0)){if(e===mr)return ke;break}if(t.match_length=0,r=hr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(Ue(t,!1),t.strm.avail_out===0))return ke}return t.insert=0,e===Qe?(Ue(t,!0),t.strm.avail_out===0?dn:di):t.sym_next&&(Ue(t,!1),t.strm.avail_out===0)?ke:ui};function mt(t,e,r,n,i){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=n,this.func=i}var Cs=[new mt(0,0,0,0,nh),new mt(4,4,8,4,gc),new mt(4,5,16,8,gc),new mt(4,6,32,32,gc),new mt(4,4,16,16,ii),new mt(8,16,32,32,ii),new mt(8,16,128,128,ii),new mt(8,32,128,256,ii),new mt(32,128,258,1024,ii),new mt(32,258,258,4096,ii)],ey=t=>{t.window_size=2*t.w_size,dr(t.head),t.max_lazy_match=Cs[t.level].max_lazy,t.good_match=Cs[t.level].good_length,t.nice_match=Cs[t.level].nice_length,t.max_chain_length=Cs[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=W-1,t.match_available=0,t.ins_h=0};function ty(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ia,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(Kg*2),this.dyn_dtree=new Uint16Array((2*Wg+1)*2),this.bl_tree=new Uint16Array((2*Xg+1)*2),dr(this.dyn_ltree),dr(this.dyn_dtree),dr(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array($g+1),this.heap=new Uint16Array(2*Tc+1),dr(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*Tc+1),dr(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}var Gs=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.status!==ai&&e.status!==Oc&&e.status!==kc&&e.status!==Cc&&e.status!==Ic&&e.status!==Rc&&e.status!==ln&&e.status!==ks?1:0},ih=t=>{if(Gs(t))return cn(t,gt);t.total_in=t.total_out=0,t.data_type=Og;let e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap===2?Oc:e.wrap?ai:ln,t.adler=e.wrap===2?0:1,e.last_flush=-2,Lg(e),me},sh=t=>{let e=ih(t);return e===me&&ey(t.state),e},ry=(t,e)=>Gs(t)||t.state.wrap!==2?gt:(t.state.gzhead=e,me),oh=(t,e,r,n,i,s)=>{if(!t)return gt;let o=1;if(e===Fg&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>Ng||r!==Ia||n<8||n>15||e<0||e>9||s<0||s>Dg||n===8&&o!==1)return cn(t,gt);n===8&&(n=9);let a=new ty;return t.state=a,a.strm=t,a.status=ai,a.wrap=o,a.gzhead=null,a.w_bits=n,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=i+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+W-1)/W),a.window=new Uint8Array(a.w_size*2),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<i+6,a.pending_buf_size=a.lit_bufsize*4,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=(a.lit_bufsize-1)*3,a.level=e,a.strategy=s,a.method=r,sh(t)},ny=(t,e)=>oh(t,e,Ia,Ug,Hg,Bg),iy=(t,e)=>{if(Gs(t)||e>lf||e<0)return t?cn(t,gt):gt;let r=t.state;if(!t.output||t.avail_in!==0&&!t.input||r.status===ks&&e!==Qe)return cn(t,t.avail_out===0?pc:gt);let n=r.last_flush;if(r.last_flush=e,r.pending!==0){if(Ne(t),t.avail_out===0)return r.last_flush=-1,me}else if(t.avail_in===0&&uf(e)<=uf(n)&&e!==Qe)return cn(t,pc);if(r.status===ks&&t.avail_in!==0)return cn(t,pc);if(r.status===ai&&r.wrap===0&&(r.status=ln),r.status===ai){let i=Ia+(r.w_bits-8<<4)<<8,s=-1;if(r.strategy>=wa||r.level<2?s=0:r.level<6?s=1:r.level===6?s=2:s=3,i|=s<<6,r.strstart!==0&&(i|=Zg),i+=31-i%31,Ts(r,i),r.strstart!==0&&(Ts(r,t.adler>>>16),Ts(r,t.adler&65535)),t.adler=1,r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(r.status===Oc){if(t.adler=0,Z(r,31),Z(r,139),Z(r,8),r.gzhead)Z(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Z(r,r.gzhead.time&255),Z(r,r.gzhead.time>>8&255),Z(r,r.gzhead.time>>16&255),Z(r,r.gzhead.time>>24&255),Z(r,r.level===9?2:r.strategy>=wa||r.level<2?4:0),Z(r,r.gzhead.os&255),r.gzhead.extra&&r.gzhead.extra.length&&(Z(r,r.gzhead.extra.length&255),Z(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(t.adler=he(t.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=kc;else if(Z(r,0),Z(r,0),Z(r,0),Z(r,0),Z(r,0),Z(r,r.level===9?2:r.strategy>=wa||r.level<2?4:0),Z(r,Yg),r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(r.status===kc){if(r.gzhead.extra){let i=r.pending,s=(r.gzhead.extra.length&65535)-r.gzindex;for(;r.pending+s>r.pending_buf_size;){let a=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+a),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex+=a,Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0,s-=a}let o=new Uint8Array(r.gzhead.extra);r.pending_buf.set(o.subarray(r.gzindex,r.gzindex+s),r.pending),r.pending+=s,r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Cc}if(r.status===Cc){if(r.gzhead.name){let i=r.pending,s;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0}r.gzindex<r.gzhead.name.length?s=r.gzhead.name.charCodeAt(r.gzindex++)&255:s=0,Z(r,s)}while(s!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),r.gzindex=0}r.status=Ic}if(r.status===Ic){if(r.gzhead.comment){let i=r.pending,s;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i)),Ne(t),r.pending!==0)return r.last_flush=-1,me;i=0}r.gzindex<r.gzhead.comment.length?s=r.gzhead.comment.charCodeAt(r.gzindex++)&255:s=0,Z(r,s)}while(s!==0);r.gzhead.hcrc&&r.pending>i&&(t.adler=he(t.adler,r.pending_buf,r.pending-i,i))}r.status=Rc}if(r.status===Rc){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&(Ne(t),r.pending!==0))return r.last_flush=-1,me;Z(r,t.adler&255),Z(r,t.adler>>8&255),t.adler=0}if(r.status=ln,Ne(t),r.pending!==0)return r.last_flush=-1,me}if(t.avail_in!==0||r.lookahead!==0||e!==mr&&r.status!==ks){let i=r.level===0?nh(r,e):r.strategy===wa?Jg(r,e):r.strategy===Pg?Qg(r,e):Cs[r.level].func(r,e);if((i===dn||i===di)&&(r.status=ks),i===ke||i===dn)return t.avail_out===0&&(r.last_flush=-1),me;if(i===ui&&(e===Cg?kg(r):e!==lf&&(Lc(r,0,0,!1),e===Ig&&(dr(r.head),r.lookahead===0&&(r.strstart=0,r.block_start=0,r.insert=0))),Ne(t),t.avail_out===0))return r.last_flush=-1,me}return e!==Qe?me:r.wrap<=0?cf:(r.wrap===2?(Z(r,t.adler&255),Z(r,t.adler>>8&255),Z(r,t.adler>>16&255),Z(r,t.adler>>24&255),Z(r,t.total_in&255),Z(r,t.total_in>>8&255),Z(r,t.total_in>>16&255),Z(r,t.total_in>>24&255)):(Ts(r,t.adler>>>16),Ts(r,t.adler&65535)),Ne(t),r.wrap>0&&(r.wrap=-r.wrap),r.pending!==0?me:cf)},sy=t=>{if(Gs(t))return gt;let e=t.state.status;return t.state=null,e===ln?cn(t,Rg):me},oy=(t,e)=>{let r=e.length;if(Gs(t))return gt;let n=t.state,i=n.wrap;if(i===2||i===1&&n.status!==ai||n.lookahead)return gt;if(i===1&&(t.adler=Os(t.adler,e,r,0)),n.wrap=0,r>=n.w_size){i===0&&(dr(n.head),n.strstart=0,n.block_start=0,n.insert=0);let u=new Uint8Array(n.w_size);u.set(e.subarray(r-n.w_size,r),0),e=u,r=n.w_size}let s=t.avail_in,o=t.next_in,a=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,li(n);n.lookahead>=W;){let u=n.strstart,l=n.lookahead-(W-1);do n.ins_h=pr(n,n.ins_h,n.window[u+W-1]),n.prev[u&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=u,u++;while(--l);n.strstart=u,n.lookahead=W-1,li(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=W-1,n.match_available=0,t.next_in=o,t.input=a,t.avail_in=s,n.wrap=i,me},ay=ny,ly=oh,cy=sh,uy=ih,dy=ry,fy=iy,hy=sy,my=oy,py="pako deflate (from Nodeca project)",Rs={deflateInit:ay,deflateInit2:ly,deflateReset:cy,deflateResetKeep:uy,deflateSetHeader:dy,deflate:fy,deflateEnd:hy,deflateSetDictionary:my,deflateInfo:py},gy=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),yy=function(t){let e=Array.prototype.slice.call(arguments,1);for(;e.length;){let r=e.shift();if(r){if(typeof r!="object")throw new TypeError(r+"must be non-object");for(let n in r)gy(r,n)&&(t[n]=r[n])}}return t},by=t=>{let e=0;for(let n=0,i=t.length;n<i;n++)e+=t[n].length;let r=new Uint8Array(e);for(let n=0,i=0,s=t.length;n<s;n++){let o=t[n];r.set(o,i),i+=o.length}return r},Ra={assign:yy,flattenChunks:by},ah=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{ah=!1}var Ns=new Uint8Array(256);for(let t=0;t<256;t++)Ns[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;Ns[254]=Ns[254]=1;var xy=t=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(t);let e,r,n,i,s,o=t.length,a=0;for(i=0;i<o;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),a+=r<128?1:r<2048?2:r<65536?3:4;for(e=new Uint8Array(a),s=0,i=0;s<a;i++)r=t.charCodeAt(i),(r&64512)===55296&&i+1<o&&(n=t.charCodeAt(i+1),(n&64512)===56320&&(r=65536+(r-55296<<10)+(n-56320),i++)),r<128?e[s++]=r:r<2048?(e[s++]=192|r>>>6,e[s++]=128|r&63):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|r&63):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|r&63);return e},_y=(t,e)=>{if(e<65534&&t.subarray&&ah)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let n=0;n<e;n++)r+=String.fromCharCode(t[n]);return r},vy=(t,e)=>{let r=e||t.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(t.subarray(0,e));let n,i,s=new Array(r*2);for(i=0,n=0;n<r;){let o=t[n++];if(o<128){s[i++]=o;continue}let a=Ns[o];if(a>4){s[i++]=65533,n+=a-1;continue}for(o&=a===2?31:a===3?15:7;a>1&&n<r;)o=o<<6|t[n++]&63,a--;if(a>1){s[i++]=65533;continue}o<65536?s[i++]=o:(o-=65536,s[i++]=55296|o>>10&1023,s[i++]=56320|o&1023)}return _y(s,i)},wy=(t,e)=>{e=e||t.length,e>t.length&&(e=t.length);let r=e-1;for(;r>=0&&(t[r]&192)===128;)r--;return r<0||r===0?e:r+Ns[t[r]]>e?r:e},Us={string2buf:xy,buf2string:vy,utf8border:wy};function Sy(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var lh=Sy,ch=Object.prototype.toString,{Z_NO_FLUSH:Ay,Z_SYNC_FLUSH:My,Z_FULL_FLUSH:Ey,Z_FINISH:Ly,Z_OK:ka,Z_STREAM_END:Ty,Z_DEFAULT_COMPRESSION:ky,Z_DEFAULT_STRATEGY:Cy,Z_DEFLATED:Iy}=hn;function Ws(t){this.options=Ra.assign({level:ky,method:Iy,chunkSize:16384,windowBits:15,memLevel:8,strategy:Cy},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new lh,this.strm.avail_out=0;let r=Rs.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==ka)throw new Error(un[r]);if(e.header&&Rs.deflateSetHeader(this.strm,e.header),e.dictionary){let n;if(typeof e.dictionary=="string"?n=Us.string2buf(e.dictionary):ch.call(e.dictionary)==="[object ArrayBuffer]"?n=new Uint8Array(e.dictionary):n=e.dictionary,r=Rs.deflateSetDictionary(this.strm,n),r!==ka)throw new Error(un[r]);this._dict_set=!0}}Ws.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i,s;if(this.ended)return!1;for(e===~~e?s=e:s=e===!0?Ly:Ay,typeof t=="string"?r.input=Us.string2buf(t):ch.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){if(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),(s===My||s===Ey)&&r.avail_out<=6){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(i=Rs.deflate(r,s),i===Ty)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),i=Rs.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===ka;if(r.avail_out===0){this.onData(r.output);continue}if(s>0&&r.next_out>0){this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;continue}if(r.avail_in===0)break}return!0};Ws.prototype.onData=function(t){this.chunks.push(t)};Ws.prototype.onEnd=function(t){t===ka&&(this.result=Ra.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Nc(t,e){let r=new Ws(e);if(r.push(t,!0),r.err)throw r.msg||un[r.err];return r.result}function Ry(t,e){return e=e||{},e.raw=!0,Nc(t,e)}function Fy(t,e){return e=e||{},e.gzip=!0,Nc(t,e)}var zy=Ws,Py=Nc,Dy=Ry,By=Fy,Oy=hn,Ny={Deflate:zy,deflate:Py,deflateRaw:Dy,gzip:By,constants:Oy},Sa=16209,Uy=16191,Hy=function(e,r){let n,i,s,o,a,u,l,c,f,d,h,m,g,p,y,_,x,b,v,S,w,M,L,A,T=e.state;n=e.next_in,L=e.input,i=n+(e.avail_in-5),s=e.next_out,A=e.output,o=s-(r-e.avail_out),a=s+(e.avail_out-257),u=T.dmax,l=T.wsize,c=T.whave,f=T.wnext,d=T.window,h=T.hold,m=T.bits,g=T.lencode,p=T.distcode,y=(1<<T.lenbits)-1,_=(1<<T.distbits)-1;e:do{m<15&&(h+=L[n++]<<m,m+=8,h+=L[n++]<<m,m+=8),x=g[h&y];t:for(;;){if(b=x>>>24,h>>>=b,m-=b,b=x>>>16&255,b===0)A[s++]=x&65535;else if(b&16){v=x&65535,b&=15,b&&(m<b&&(h+=L[n++]<<m,m+=8),v+=h&(1<<b)-1,h>>>=b,m-=b),m<15&&(h+=L[n++]<<m,m+=8,h+=L[n++]<<m,m+=8),x=p[h&_];r:for(;;){if(b=x>>>24,h>>>=b,m-=b,b=x>>>16&255,b&16){if(S=x&65535,b&=15,m<b&&(h+=L[n++]<<m,m+=8,m<b&&(h+=L[n++]<<m,m+=8)),S+=h&(1<<b)-1,S>u){e.msg="invalid distance too far back",T.mode=Sa;break e}if(h>>>=b,m-=b,b=s-o,S>b){if(b=S-b,b>c&&T.sane){e.msg="invalid distance too far back",T.mode=Sa;break e}if(w=0,M=d,f===0){if(w+=l-b,b<v){v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}}else if(f<b){if(w+=l+f-b,b-=f,b<v){v-=b;do A[s++]=d[w++];while(--b);if(w=0,f<v){b=f,v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}}}else if(w+=f-b,b<v){v-=b;do A[s++]=d[w++];while(--b);w=s-S,M=A}for(;v>2;)A[s++]=M[w++],A[s++]=M[w++],A[s++]=M[w++],v-=3;v&&(A[s++]=M[w++],v>1&&(A[s++]=M[w++]))}else{w=s-S;do A[s++]=A[w++],A[s++]=A[w++],A[s++]=A[w++],v-=3;while(v>2);v&&(A[s++]=A[w++],v>1&&(A[s++]=A[w++]))}}else if((b&64)===0){x=p[(x&65535)+(h&(1<<b)-1)];continue r}else{e.msg="invalid distance code",T.mode=Sa;break e}break}}else if((b&64)===0){x=g[(x&65535)+(h&(1<<b)-1)];continue t}else if(b&32){T.mode=Uy;break e}else{e.msg="invalid literal/length code",T.mode=Sa;break e}break}}while(n<i&&s<a);v=m>>3,n-=v,m-=v<<3,h&=(1<<m)-1,e.next_in=n,e.next_out=s,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=s<a?257+(a-s):257-(s-a),T.hold=h,T.bits=m},si=15,df=852,ff=592,hf=0,yc=1,mf=2,Vy=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Gy=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Wy=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),Xy=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),Ky=(t,e,r,n,i,s,o,a)=>{let u=a.bits,l=0,c=0,f=0,d=0,h=0,m=0,g=0,p=0,y=0,_=0,x,b,v,S,w,M=null,L,A=new Uint16Array(si+1),T=new Uint16Array(si+1),I=null,z,C,V;for(l=0;l<=si;l++)A[l]=0;for(c=0;c<n;c++)A[e[r+c]]++;for(h=u,d=si;d>=1&&A[d]===0;d--);if(h>d&&(h=d),d===0)return i[s++]=1<<24|64<<16|0,i[s++]=1<<24|64<<16|0,a.bits=1,0;for(f=1;f<d&&A[f]===0;f++);for(h<f&&(h=f),p=1,l=1;l<=si;l++)if(p<<=1,p-=A[l],p<0)return-1;if(p>0&&(t===hf||d!==1))return-1;for(T[1]=0,l=1;l<si;l++)T[l+1]=T[l]+A[l];for(c=0;c<n;c++)e[r+c]!==0&&(o[T[e[r+c]]++]=c);if(t===hf?(M=I=o,L=20):t===yc?(M=Vy,I=Gy,L=257):(M=Wy,I=Xy,L=0),_=0,c=0,l=f,w=s,m=h,g=0,v=-1,y=1<<h,S=y-1,t===yc&&y>df||t===mf&&y>ff)return 1;for(;;){z=l-g,o[c]+1<L?(C=0,V=o[c]):o[c]>=L?(C=I[o[c]-L],V=M[o[c]-L]):(C=96,V=0),x=1<<l-g,b=1<<m,f=b;do b-=x,i[w+(_>>g)+b]=z<<24|C<<16|V|0;while(b!==0);for(x=1<<l-1;_&x;)x>>=1;if(x!==0?(_&=x-1,_+=x):_=0,c++,--A[l]===0){if(l===d)break;l=e[r+o[c]]}if(l>h&&(_&S)!==v){for(g===0&&(g=h),w+=f,m=l-g,p=1<<m;m+g<d&&(p-=A[m+g],!(p<=0));)m++,p<<=1;if(y+=1<<m,t===yc&&y>df||t===mf&&y>ff)return 1;v=_&S,i[v]=h<<24|m<<16|w-s|0}}return _!==0&&(i[w+_]=l-g<<24|64<<16|0),a.bits=h,0},Fs=Ky,$y=0,uh=1,dh=2,{Z_FINISH:pf,Z_BLOCK:Zy,Z_TREES:Aa,Z_OK:fn,Z_STREAM_END:Yy,Z_NEED_DICT:qy,Z_STREAM_ERROR:Je,Z_DATA_ERROR:fh,Z_MEM_ERROR:hh,Z_BUF_ERROR:jy,Z_DEFLATED:gf}=hn,Fa=16180,yf=16181,bf=16182,xf=16183,_f=16184,vf=16185,wf=16186,Sf=16187,Af=16188,Mf=16189,Ca=16190,Ot=16191,bc=16192,Ef=16193,xc=16194,Lf=16195,Tf=16196,kf=16197,Cf=16198,Ma=16199,Ea=16200,If=16201,Rf=16202,Ff=16203,zf=16204,Pf=16205,_c=16206,Df=16207,Bf=16208,ie=16209,mh=16210,ph=16211,Qy=852,Jy=592,eb=15,tb=eb,Of=t=>(t>>>24&255)+(t>>>8&65280)+((t&65280)<<8)+((t&255)<<24);function rb(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var mn=t=>{if(!t)return 1;let e=t.state;return!e||e.strm!==t||e.mode<Fa||e.mode>ph?1:0},gh=t=>{if(mn(t))return Je;let e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=e.wrap&1),e.mode=Fa,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Qy),e.distcode=e.distdyn=new Int32Array(Jy),e.sane=1,e.back=-1,fn},yh=t=>{if(mn(t))return Je;let e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,gh(t)},bh=(t,e)=>{let r;if(mn(t))return Je;let n=t.state;return e<0?(r=0,e=-e):(r=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?Je:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=r,n.wbits=e,yh(t))},xh=(t,e)=>{if(!t)return Je;let r=new rb;t.state=r,r.strm=t,r.window=null,r.mode=Fa;let n=bh(t,e);return n!==fn&&(t.state=null),n},nb=t=>xh(t,tb),Nf=!0,vc,wc,ib=t=>{if(Nf){vc=new Int32Array(512),wc=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Fs(uh,t.lens,0,288,vc,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Fs(dh,t.lens,0,32,wc,0,t.work,{bits:5}),Nf=!1}t.lencode=vc,t.lenbits=9,t.distcode=wc,t.distbits=5},_h=(t,e,r,n)=>{let i,s=t.state;return s.window===null&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),n>=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(i=s.wsize-s.wnext,i>n&&(i=n),s.window.set(e.subarray(r-n,r-n+i),s.wnext),n-=i,n?(s.window.set(e.subarray(r-n,r),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=i))),0},sb=(t,e)=>{let r,n,i,s,o,a,u,l,c,f,d,h,m,g,p=0,y,_,x,b,v,S,w,M,L=new Uint8Array(4),A,T,I=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(mn(t)||!t.output||!t.input&&t.avail_in!==0)return Je;r=t.state,r.mode===Ot&&(r.mode=bc),o=t.next_out,i=t.output,u=t.avail_out,s=t.next_in,n=t.input,a=t.avail_in,l=r.hold,c=r.bits,f=a,d=u,M=fn;e:for(;;)switch(r.mode){case Fa:if(r.wrap===0){r.mode=bc;break}for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&2&&l===35615){r.wbits===0&&(r.wbits=15),r.check=0,L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0),l=0,c=0,r.mode=yf;break}if(r.head&&(r.head.done=!1),!(r.wrap&1)||(((l&255)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=ie;break}if((l&15)!==gf){t.msg="unknown compression method",r.mode=ie;break}if(l>>>=4,c-=4,w=(l&15)+8,r.wbits===0&&(r.wbits=w),w>15||w>r.wbits){t.msg="invalid window size",r.mode=ie;break}r.dmax=1<<r.wbits,r.flags=0,t.adler=r.check=1,r.mode=l&512?Mf:Ot,l=0,c=0;break;case yf:for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.flags=l,(r.flags&255)!==gf){t.msg="unknown compression method",r.mode=ie;break}if(r.flags&57344){t.msg="unknown header flags set",r.mode=ie;break}r.head&&(r.head.text=l>>8&1),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0,r.mode=bf;case bf:for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.head&&(r.head.time=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,L[2]=l>>>16&255,L[3]=l>>>24&255,r.check=he(r.check,L,4,0)),l=0,c=0,r.mode=xf;case xf:for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.head&&(r.head.xflags=l&255,r.head.os=l>>8),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0,r.mode=_f;case _f:if(r.flags&1024){for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.length=l,r.head&&(r.head.extra_len=l),r.flags&512&&r.wrap&4&&(L[0]=l&255,L[1]=l>>>8&255,r.check=he(r.check,L,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=vf;case vf:if(r.flags&1024&&(h=r.length,h>a&&(h=a),h&&(r.head&&(w=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(s,s+h),w)),r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,r.length-=h),r.length))break e;r.length=0,r.mode=wf;case wf:if(r.flags&2048){if(a===0)break e;h=0;do w=n[s+h++],r.head&&w&&r.length<65536&&(r.head.name+=String.fromCharCode(w));while(w&&h<a);if(r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,w)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Sf;case Sf:if(r.flags&4096){if(a===0)break e;h=0;do w=n[s+h++],r.head&&w&&r.length<65536&&(r.head.comment+=String.fromCharCode(w));while(w&&h<a);if(r.flags&512&&r.wrap&4&&(r.check=he(r.check,n,h,s)),a-=h,s+=h,w)break e}else r.head&&(r.head.comment=null);r.mode=Af;case Af:if(r.flags&512){for(;c<16;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&4&&l!==(r.check&65535)){t.msg="header crc mismatch",r.mode=ie;break}l=0,c=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=Ot;break;case Mf:for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}t.adler=r.check=Of(l),l=0,c=0,r.mode=Ca;case Ca:if(r.havedict===0)return t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,qy;t.adler=r.check=1,r.mode=Ot;case Ot:if(e===Zy||e===Aa)break e;case bc:if(r.last){l>>>=c&7,c-=c&7,r.mode=_c;break}for(;c<3;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}switch(r.last=l&1,l>>>=1,c-=1,l&3){case 0:r.mode=Ef;break;case 1:if(ib(r),r.mode=Ma,e===Aa){l>>>=2,c-=2;break e}break;case 2:r.mode=Tf;break;case 3:t.msg="invalid block type",r.mode=ie}l>>>=2,c-=2;break;case Ef:for(l>>>=c&7,c-=c&7;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if((l&65535)!==(l>>>16^65535)){t.msg="invalid stored block lengths",r.mode=ie;break}if(r.length=l&65535,l=0,c=0,r.mode=xc,e===Aa)break e;case xc:r.mode=Lf;case Lf:if(h=r.length,h){if(h>a&&(h=a),h>u&&(h=u),h===0)break e;i.set(n.subarray(s,s+h),o),a-=h,s+=h,u-=h,o+=h,r.length-=h;break}r.mode=Ot;break;case Tf:for(;c<14;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.nlen=(l&31)+257,l>>>=5,c-=5,r.ndist=(l&31)+1,l>>>=5,c-=5,r.ncode=(l&15)+4,l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=ie;break}r.have=0,r.mode=kf;case kf:for(;r.have<r.ncode;){for(;c<3;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.lens[I[r.have++]]=l&7,l>>>=3,c-=3}for(;r.have<19;)r.lens[I[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},M=Fs($y,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,M){t.msg="invalid code lengths set",r.mode=ie;break}r.have=0,r.mode=Cf;case Cf:for(;r.have<r.nlen+r.ndist;){for(;p=r.lencode[l&(1<<r.lenbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(x<16)l>>>=y,c-=y,r.lens[r.have++]=x;else{if(x===16){for(T=y+2;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(l>>>=y,c-=y,r.have===0){t.msg="invalid bit length repeat",r.mode=ie;break}w=r.lens[r.have-1],h=3+(l&3),l>>>=2,c-=2}else if(x===17){for(T=y+3;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=y,c-=y,w=0,h=3+(l&7),l>>>=3,c-=3}else{for(T=y+7;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=y,c-=y,w=0,h=11+(l&127),l>>>=7,c-=7}if(r.have+h>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=ie;break}for(;h--;)r.lens[r.have++]=w}}if(r.mode===ie)break;if(r.lens[256]===0){t.msg="invalid code -- missing end-of-block",r.mode=ie;break}if(r.lenbits=9,A={bits:r.lenbits},M=Fs(uh,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,M){t.msg="invalid literal/lengths set",r.mode=ie;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},M=Fs(dh,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,M){t.msg="invalid distances set",r.mode=ie;break}if(r.mode=Ma,e===Aa)break e;case Ma:r.mode=Ea;case Ea:if(a>=6&&u>=258){t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,Hy(t,d),o=t.next_out,i=t.output,u=t.avail_out,s=t.next_in,n=t.input,a=t.avail_in,l=r.hold,c=r.bits,r.mode===Ot&&(r.back=-1);break}for(r.back=0;p=r.lencode[l&(1<<r.lenbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(_&&(_&240)===0){for(b=y,v=_,S=x;p=r.lencode[S+((l&(1<<b+v)-1)>>b)],y=p>>>24,_=p>>>16&255,x=p&65535,!(b+y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=y,c-=y,r.back+=y,r.length=x,_===0){r.mode=Pf;break}if(_&32){r.back=-1,r.mode=Ot;break}if(_&64){t.msg="invalid literal/length code",r.mode=ie;break}r.extra=_&15,r.mode=If;case If:if(r.extra){for(T=r.extra;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=Rf;case Rf:for(;p=r.distcode[l&(1<<r.distbits)-1],y=p>>>24,_=p>>>16&255,x=p&65535,!(y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if((_&240)===0){for(b=y,v=_,S=x;p=r.distcode[S+((l&(1<<b+v)-1)>>b)],y=p>>>24,_=p>>>16&255,x=p&65535,!(b+y<=c);){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=y,c-=y,r.back+=y,_&64){t.msg="invalid distance code",r.mode=ie;break}r.offset=x,r.extra=_&15,r.mode=Ff;case Ff:if(r.extra){for(T=r.extra;c<T;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=ie;break}r.mode=zf;case zf:if(u===0)break e;if(h=d-u,r.offset>h){if(h=r.offset-h,h>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=ie;break}h>r.wnext?(h-=r.wnext,m=r.wsize-h):m=r.wnext-h,h>r.length&&(h=r.length),g=r.window}else g=i,m=o-r.offset,h=r.length;h>u&&(h=u),u-=h,r.length-=h;do i[o++]=g[m++];while(--h);r.length===0&&(r.mode=Ea);break;case Pf:if(u===0)break e;i[o++]=r.length,u--,r.mode=Ea;break;case _c:if(r.wrap){for(;c<32;){if(a===0)break e;a--,l|=n[s++]<<c,c+=8}if(d-=u,t.total_out+=d,r.total+=d,r.wrap&4&&d&&(t.adler=r.check=r.flags?he(r.check,i,d,o-d):Os(r.check,i,d,o-d)),d=u,r.wrap&4&&(r.flags?l:Of(l))!==r.check){t.msg="incorrect data check",r.mode=ie;break}l=0,c=0}r.mode=Df;case Df:if(r.wrap&&r.flags){for(;c<32;){if(a===0)break e;a--,l+=n[s++]<<c,c+=8}if(r.wrap&4&&l!==(r.total&4294967295)){t.msg="incorrect length check",r.mode=ie;break}l=0,c=0}r.mode=Bf;case Bf:M=Yy;break e;case ie:M=fh;break e;case mh:return hh;case ph:default:return Je}return t.next_out=o,t.avail_out=u,t.next_in=s,t.avail_in=a,r.hold=l,r.bits=c,(r.wsize||d!==t.avail_out&&r.mode<ie&&(r.mode<_c||e!==pf))&&_h(t,t.output,t.next_out,d-t.avail_out),f-=t.avail_in,d-=t.avail_out,t.total_in+=f,t.total_out+=d,r.total+=d,r.wrap&4&&d&&(t.adler=r.check=r.flags?he(r.check,i,d,t.next_out-d):Os(r.check,i,d,t.next_out-d)),t.data_type=r.bits+(r.last?64:0)+(r.mode===Ot?128:0)+(r.mode===Ma||r.mode===xc?256:0),(f===0&&d===0||e===pf)&&M===fn&&(M=jy),M},ob=t=>{if(mn(t))return Je;let e=t.state;return e.window&&(e.window=null),t.state=null,fn},ab=(t,e)=>{if(mn(t))return Je;let r=t.state;return(r.wrap&2)===0?Je:(r.head=e,e.done=!1,fn)},lb=(t,e)=>{let r=e.length,n,i,s;return mn(t)||(n=t.state,n.wrap!==0&&n.mode!==Ca)?Je:n.mode===Ca&&(i=1,i=Os(i,e,r,0),i!==n.check)?fh:(s=_h(t,e,r,r),s?(n.mode=mh,hh):(n.havedict=1,fn))},cb=yh,ub=bh,db=gh,fb=nb,hb=xh,mb=sb,pb=ob,gb=ab,yb=lb,bb="pako inflate (from Nodeca project)",Ut={inflateReset:cb,inflateReset2:ub,inflateResetKeep:db,inflateInit:fb,inflateInit2:hb,inflate:mb,inflateEnd:pb,inflateGetHeader:gb,inflateSetDictionary:yb,inflateInfo:bb};function xb(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var _b=xb,vh=Object.prototype.toString,{Z_NO_FLUSH:vb,Z_FINISH:wb,Z_OK:Hs,Z_STREAM_END:Sc,Z_NEED_DICT:Ac,Z_STREAM_ERROR:Sb,Z_DATA_ERROR:Uf,Z_MEM_ERROR:Ab}=hn;function Xs(t){this.options=Ra.assign({chunkSize:1024*64,windowBits:15,to:""},t||{});let e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(t&&t.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new lh,this.strm.avail_out=0;let r=Ut.inflateInit2(this.strm,e.windowBits);if(r!==Hs)throw new Error(un[r]);if(this.header=new _b,Ut.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=Us.string2buf(e.dictionary):vh.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=Ut.inflateSetDictionary(this.strm,e.dictionary),r!==Hs)))throw new Error(un[r])}Xs.prototype.push=function(t,e){let r=this.strm,n=this.options.chunkSize,i=this.options.dictionary,s,o,a;if(this.ended)return!1;for(e===~~e?o=e:o=e===!0?wb:vb,vh.call(t)==="[object ArrayBuffer]"?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(r.avail_out===0&&(r.output=new Uint8Array(n),r.next_out=0,r.avail_out=n),s=Ut.inflate(r,o),s===Ac&&i&&(s=Ut.inflateSetDictionary(r,i),s===Hs?s=Ut.inflate(r,o):s===Uf&&(s=Ac));r.avail_in>0&&s===Sc&&r.state.wrap>0&&t[r.next_in]!==0;)Ut.inflateReset(r),s=Ut.inflate(r,o);switch(s){case Sb:case Uf:case Ac:case Ab:return this.onEnd(s),this.ended=!0,!1}if(a=r.avail_out,r.next_out&&(r.avail_out===0||s===Sc))if(this.options.to==="string"){let u=Us.utf8border(r.output,r.next_out),l=r.next_out-u,c=Us.buf2string(r.output,u);r.next_out=l,r.avail_out=n-l,l&&r.output.set(r.output.subarray(u,u+l),0),this.onData(c)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(!(s===Hs&&a===0)){if(s===Sc)return s=Ut.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(r.avail_in===0)break}}return!0};Xs.prototype.onData=function(t){this.chunks.push(t)};Xs.prototype.onEnd=function(t){t===Hs&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=Ra.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};function Uc(t,e){let r=new Xs(e);if(r.push(t),r.err)throw r.msg||un[r.err];return r.result}function Mb(t,e){return e=e||{},e.raw=!0,Uc(t,e)}var Eb=Xs,Lb=Uc,Tb=Mb,kb=Uc,Cb=hn,Ib={Inflate:Eb,inflate:Lb,inflateRaw:Tb,ungzip:kb,constants:Cb},{Deflate:Rb,deflate:Fb,deflateRaw:zb,gzip:Pb}=Ny,{Inflate:Db,inflate:Bb,inflateRaw:Ob,ungzip:Nb}=Ib,Ub=Rb,Hb=Fb,Vb=zb,Gb=Pb,Wb=Db,Xb=Bb,Kb=Ob,$b=Nb,Zb=hn,Hc={Deflate:Ub,deflate:Hb,deflateRaw:Vb,gzip:Gb,Inflate:Wb,inflate:Xb,inflateRaw:Kb,ungzip:$b,constants:Zb};var fi=class fi{constructor(e=fi.INITIAL_SIZE){this.buffer=new Uint8Array(e),this.readOffset=0,this.writeOffset=0}append(e){let r=e instanceof Uint8Array?e:new Uint8Array(e),n=this.writeOffset+r.length;n>this.buffer.length&&this.grow(n),this.buffer.set(r,this.writeOffset),this.writeOffset+=r.length}hasBytes(e){return this.writeOffset-this.readOffset>=e}available(){return this.writeOffset-this.readOffset}readByte(){if(!this.hasBytes(1))throw new Error("Buffer underflow");return this.buffer[this.readOffset++]}readShort(){if(!this.hasBytes(2))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8;return this.readOffset+=2,e>32767?e-65536:e}readLong(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let e=this.buffer[this.readOffset]|this.buffer[this.readOffset+1]<<8|this.buffer[this.readOffset+2]<<16|this.buffer[this.readOffset+3]<<24;return this.readOffset+=4,e}readFloat(){if(!this.hasBytes(4))throw new Error("Buffer underflow");let r=new DataView(this.buffer.buffer,this.buffer.byteOffset+this.readOffset,4).getFloat32(0,!0);return this.readOffset+=4,r}readString(){let e=Math.min(fi.MAX_STRING_LENGTH,this.writeOffset-this.readOffset),r=0;for(;r<e&&this.buffer[this.readOffset+r]!==0;)r++;if(r>=e)throw this.writeOffset-this.readOffset<=e?new Error("Buffer underflow"):new Error("String exceeds max length");let n=this.buffer.slice(this.readOffset,this.readOffset+r);return this.readOffset+=r+1,new TextDecoder("latin1").decode(n)}peekBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");return this.buffer.slice(this.readOffset,this.readOffset+e)}readBytes(e){if(!this.hasBytes(e))throw new Error("Buffer underflow");let r=this.buffer.slice(this.readOffset,this.readOffset+e);return this.readOffset+=e,r}readData(e){return this.readBytes(e)}getReadPosition(){return this.readOffset}getWritePosition(){return this.writeOffset}setReadPosition(e){if(e<0||e>this.writeOffset)throw new Error("Invalid read position");this.readOffset=e}grow(e){let r=e?Math.max(e,this.buffer.length*2):this.buffer.length*2,n=new Uint8Array(r);n.set(this.buffer),this.buffer=n}compact(){if(this.readOffset===0)return;let e=this.writeOffset-this.readOffset;if(e===0){this.readOffset=0,this.writeOffset=0;return}this.buffer.copyWithin(0,this.readOffset,this.writeOffset),this.readOffset=0,this.writeOffset=e}getCapacity(){return this.buffer.length}reset(){this.readOffset=0,this.writeOffset=0}};fi.INITIAL_SIZE=64*1024,fi.MAX_STRING_LENGTH=2048;var za=fi;var hi=2023,gr=1,yr=2,br=4,xr=8,_r=16,vr=32,$s=64,Ks=128,Pa=256,wr=512,Sr=1024,Ar=2048,bt=4096,Mr=8192,xt=16384,Da=32768,_t=65536,Er=1<<17,vt=1<<18,wt=1<<19,Lr=1<<20,Tr=1<<21,kr=1<<22,Ba=1<<23,Cr=1<<24,St=1<<25,Ir=1<<26,Rr=1<<27,Fr=1<<28,zr=1<<29,Pr=1<<30,Oa=-2147483648,Dr=1,Br=2,Or=4;var Yb=1,qb=2,jb=128,Ht=()=>({number:0,modelindex:0,modelindex2:0,modelindex3:0,modelindex4:0,frame:0,skinnum:0,effects:0,renderfx:0,origin:{x:0,y:0,z:0},old_origin:{x:0,y:0,z:0},angles:{x:0,y:0,z:0},sound:0,event:0,solid:0,bits:0,bitsHigh:0,alpha:0,scale:0,instanceBits:0,loopVolume:0,loopAttenuation:0,owner:0,oldFrame:0}),pn=()=>({pm_type:0,origin:{x:0,y:0,z:0},velocity:{x:0,y:0,z:0},pm_time:0,pm_flags:0,gravity:0,delta_angles:{x:0,y:0,z:0},viewoffset:{x:0,y:0,z:0},viewangles:{x:0,y:0,z:0},kick_angles:{x:0,y:0,z:0},gun_index:0,gun_frame:0,gun_offset:{x:0,y:0,z:0},gun_angles:{x:0,y:0,z:0},blend:[0,0,0,0],fov:0,rdflags:0,stats:new Array(32).fill(0),gunskin:0,gunrate:0,damage_blend:[0,0,0,0],team_id:0}),Vc=class extends za{constructor(r){super(0);this.stream=r}readByte(){return this.stream.readByte()}readShort(){return this.stream.readShort()}readLong(){return this.stream.readLong()}readFloat(){return this.stream.readFloat()}readString(){return this.stream.readString()}readData(r){return this.stream.readData(r)}hasBytes(r){return this.stream.hasMore()}available(){return this.stream.getRemaining()}getReadPosition(){return this.stream.getPosition()}peekBytes(r){throw new Error("peekBytes not implemented for BinaryStreamAdapter")}},it=class t{constructor(e,r,n=!1){this.protocolVersion=0;this.isDemo=Yb;this.strictMode=!1;this.errorCount=0;e instanceof vn?this.stream=new Vc(e):this.stream=e,this.handler=r,this.strictMode=n}setProtocolVersion(e){this.protocolVersion=e}getProtocolVersion(){return this.protocolVersion}getErrorCount(){return this.errorCount}translateCommand(e){if(this.protocolVersion===0)return e===7?k.serverdata:e===12?k.serverdata:e;if(this.protocolVersion===hi)return e;if(this.protocolVersion===25||this.protocolVersion===26){if(e===0)return k.bad;let r=e+5;return r>=k.nop&&r<=k.frame?r:k.bad}return this.protocolVersion===34?e<=k.frame?e:k.bad:e}parseMessage(){for(;this.stream.hasBytes(1);){let e=this.stream.getReadPosition(),r=-1;try{if(r=this.stream.readByte(),r===-1)break;let n=r;switch(r=this.translateCommand(r),r){case k.bad:return;case k.nop:break;case k.disconnect:this.handler?.onDisconnect&&this.handler.onDisconnect();break;case k.reconnect:this.handler?.onReconnect&&this.handler.onReconnect();break;case k.print:this.parsePrint();break;case k.serverdata:this.parseServerData();break;case k.configstring:this.parseConfigString();break;case k.spawnbaseline:this.parseSpawnBaseline();break;case k.centerprint:this.parseCenterPrint();break;case k.download:this.parseDownload();break;case k.frame:this.parseFrame();break;case k.packetentities:this.parsePacketEntities(!1);break;case k.deltapacketentities:this.parsePacketEntities(!0);break;case k.playerinfo:this.parsePlayerState();break;case k.stufftext:this.parseStuffText();break;case k.layout:this.parseLayout();break;case k.inventory:this.parseInventory();break;case k.sound:this.parseSound();break;case k.muzzleflash:this.parseMuzzleFlash();break;case k.muzzleflash2:this.parseMuzzleFlash2();break;case k.temp_entity:this.parseTempEntity();break;case k.splitclient:this.parseSplitClient();break;case k.configblast:this.parseConfigBlast();break;case k.spawnbaselineblast:this.parseSpawnBaselineBlast();break;case k.level_restart:this.handler?.onLevelRestart&&this.handler.onLevelRestart();break;case k.damage:this.parseDamage();break;case k.locprint:this.parseLocPrint();break;case k.fog:this.parseFog();break;case k.waitingforplayers:this.parseWaitingForPlayers();break;case k.bot_chat:this.parseBotChat();break;case k.poi:this.parsePoi();break;case k.help_path:this.parseHelpPath();break;case k.muzzleflash3:this.parseMuzzleFlash3();break;case k.achievement:this.parseAchievement();break;default:let i=`Unknown server command: ${n} (translated: ${r}) at offset ${e}`;if(this.strictMode)throw new Error(i);console.warn(i),this.errorCount++;return}}catch(n){let i=n.message;if(i==="Buffer underflow"||i.includes("StreamingBuffer")){try{this.stream.setReadPosition(e)}catch(o){console.error("Failed to rollback stream position",o)}return}let s=`offset ${e}, cmd ${r}, protocol ${this.protocolVersion}`;if(console.warn(`Error parsing command ${r} (${s}): ${i}`),this.errorCount++,this.strictMode)throw n;return}}}readAngle16(){return this.stream.readShort()*(360/65536)}readCoord(){return this.stream.readShort()*.125}readAngle(){return this.stream.readByte()*(360/256)}readPos(e){e.x=this.stream.readShort()*.125,e.y=this.stream.readShort()*.125,e.z=this.stream.readShort()*.125}readDir(e){let r=this.stream.readByte();if(r>=bn.length)e.x=0,e.y=0,e.z=0;else{let n=bn[r];e.x=n[0],e.y=n[1],e.z=n[2]}}parsePrint(){let e=this.stream.readByte(),r=this.stream.readString();this.handler&&this.handler.onPrint(e,r)}parseStuffText(){let e=this.stream.readString();this.handler&&this.handler.onStuffText(e)}parseLayout(){let e=this.stream.readString();this.handler&&this.handler.onLayout(e)}parseCenterPrint(){let e=this.stream.readString();this.handler&&this.handler.onCenterPrint(e)}parseServerData(){if(this.protocolVersion=this.stream.readLong(),this.protocolVersion===hi){let e=this.stream.readLong(),r=this.stream.readByte();this.isDemo=r;let n=this.stream.readByte(),i=this.stream.readString(),s=this.stream.readShort();if(s===-2){let a=this.stream.readShort();for(let u=0;u<a;u++)this.stream.readShort();s=0}else s===-1&&(s=-1);let o=this.stream.readString();this.handler&&this.handler.onServerData(this.protocolVersion,e,0,i,s,o,n,r)}else{let e=this.stream.readLong(),r=this.stream.readByte();this.isDemo=r;let n=this.stream.readString(),i=this.stream.readShort(),s=this.stream.readString();this.handler&&this.handler.onServerData(this.protocolVersion,e,r,n,i,s)}}parseConfigString(){let e=this.stream.readShort(),r=this.stream.readString();this.handler&&this.handler.onConfigString(e,r)}parseSplitClient(){let e=this.stream.readByte();this.handler?.onSplitClient&&this.handler.onSplitClient(e)}parseConfigBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=Hc.inflate(n),s=new vn(i.buffer);for(;s.hasMore();){let o=s.readUShort(),a=s.readString();this.handler&&this.handler.onConfigString(o,a)}}catch(i){console.error("svc_configblast error",i)}}parseSpawnBaselineBlast(){let e=this.stream.readShort(),r=this.stream.readShort(),n=this.stream.readData(e);try{let i=Hc.inflate(n),s=new vn(i.buffer),o=new t(s,this.handler,this.strictMode);for(o.setProtocolVersion(this.protocolVersion);s.hasMore();)o.parseSpawnBaseline()}catch(i){console.error("svc_spawnbaselineblast error",i)}}parseLocPrint(){let e=this.stream.readByte(),r=this.stream.readString(),n=this.stream.readByte(),i=[];for(let s=0;s<n;s++)i.push(this.stream.readString());this.handler?.onLocPrint&&this.handler.onLocPrint(e,r,i)}parseWaitingForPlayers(){let e=this.stream.readByte();this.handler?.onWaitingForPlayers&&this.handler.onWaitingForPlayers(e)}parseBotChat(){let e=this.stream.readString(),r=this.stream.readShort(),n=this.stream.readString();this.handler?.onBotChat&&this.handler.onBotChat(n)}parsePoi(){let e=this.stream.readShort(),r=this.stream.readShort(),n={x:0,y:0,z:0};this.readPos(n);let i=this.stream.readShort(),s=this.stream.readByte(),o=this.stream.readByte();this.handler?.onPoi&&this.handler.onPoi(o,n)}parseHelpPath(){let e=this.stream.readByte(),r={x:0,y:0,z:0};this.readPos(r);let n={x:0,y:0,z:0};this.readDir(n),this.handler?.onHelpPath&&this.handler.onHelpPath(r)}parseAchievement(){let e=this.stream.readString();this.handler?.onAchievement&&this.handler.onAchievement(e)}parseDownload(){let e=this.stream.readShort(),r=this.stream.readByte(),n;e>0&&(n=this.stream.readData(e)),this.handler&&this.handler.onDownload(e,r,n)}parseInventory(){let r=new Array(256);for(let n=0;n<256;n++)r[n]=this.stream.readShort();this.handler&&this.handler.onInventory(r)}parseSound(){let e=this.stream.readByte(),r=this.stream.readByte(),n,i,s,o,a;if(e&1&&(n=this.stream.readByte()),e&2&&(i=this.stream.readByte()),e&16&&(s=this.stream.readByte()),e&8&&(o=this.stream.readShort()),e&4){let u={x:0,y:0,z:0};this.readPos(u),a=u}this.handler&&this.handler.onSound(e,r,n,i,s,o,a)}parseMuzzleFlash(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash(e,r)}parseMuzzleFlash2(){let e=this.stream.readShort(),r=this.stream.readByte();this.handler&&this.handler.onMuzzleFlash2(e,r)}parseMuzzleFlash3(){let e=this.stream.readShort(),r=this.stream.readShort();this.handler?.onMuzzleFlash3&&this.handler.onMuzzleFlash3(e,r)}parseFog(){let e=this.stream.readByte();if(e&128){let n=this.stream.readByte();e|=n<<8}let r={};e&1&&(r.density=this.stream.readFloat(),r.skyfactor=this.stream.readByte()),e&2&&(r.red=this.stream.readByte()),e&4&&(r.green=this.stream.readByte()),e&8&&(r.blue=this.stream.readByte()),e&16&&(r.time=this.stream.readShort()),e&32&&(r.hf_falloff=this.stream.readFloat()),e&64&&(r.hf_density=this.stream.readFloat()),e&256&&(r.hf_start_r=this.stream.readByte()),e&512&&(r.hf_start_g=this.stream.readByte()),e&1024&&(r.hf_start_b=this.stream.readByte()),e&2048&&(r.hf_start_dist=this.stream.readLong()),e&4096&&(r.hf_end_r=this.stream.readByte()),e&8192&&(r.hf_end_g=this.stream.readByte()),e&16384&&(r.hf_end_b=this.stream.readByte()),e&32768&&(r.hf_end_dist=this.stream.readLong()),this.handler?.onFog&&this.handler.onFog(r)}parseDamage(){let e=this.stream.readByte(),r=[];for(let n=0;n<e;n++){let i=this.stream.readByte(),s={x:0,y:0,z:0};this.readDir(s);let o=i&31,a=(i&32)!==0,u=(i&64)!==0,l=(i&128)!==0;r.push({damage:o,health:a,armor:u,power:l,dir:s})}this.handler?.onDamage&&this.handler.onDamage(r)}parseTempEntity(){let e=this.stream.readByte(),r={x:0,y:0,z:0},n={x:0,y:0,z:0},i={x:0,y:0,z:0},s,o,a,u,l;switch(e){case R.EXPLOSION1:case R.EXPLOSION2:case R.ROCKET_EXPLOSION:case R.GRENADE_EXPLOSION:case R.ROCKET_EXPLOSION_WATER:case R.GRENADE_EXPLOSION_WATER:case R.BFG_EXPLOSION:case R.BFG_BIGEXPLOSION:case R.BOSSTPORT:case R.PLASMA_EXPLOSION:case R.PLAIN_EXPLOSION:case R.CHAINFIST_SMOKE:case R.TRACKER_EXPLOSION:case R.TELEPORT_EFFECT:case R.DBALL_GOAL:case R.NUKEBLAST:case R.WIDOWSPLASH:case R.EXPLOSION1_BIG:case R.EXPLOSION1_NP:this.readPos(r);break;case R.GUNSHOT:case R.BLOOD:case R.BLASTER:case R.SHOTGUN:case R.SPARKS:case R.BULLET_SPARKS:case R.SCREEN_SPARKS:case R.SHIELD_SPARKS:case R.BLASTER2:case R.FLECHETTE:case R.MOREBLOOD:case R.ELECTRIC_SPARKS:case R.HEATBEAM_SPARKS:case R.HEATBEAM_STEAM:this.readPos(r),this.readDir(i);break;case R.SPLASH:case R.LASER_SPARKS:case R.WELDING_SPARKS:case R.TUNNEL_SPARKS:s=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte();break;case R.BLUEHYPERBLASTER:this.protocolVersion>=32?(this.readPos(r),this.readPos(n)):(this.readPos(r),this.readDir(i));break;case R.GREENBLOOD:this.protocolVersion>=32?(this.readPos(r),this.readDir(i)):(this.readPos(r),this.readPos(n));break;case R.RAILTRAIL:case R.BUBBLETRAIL:case R.BFG_LASER:case R.DEBUGTRAIL:case R.BUBBLETRAIL2:this.readPos(r),this.readPos(n);break;case R.PARASITE_ATTACK:case R.MEDIC_CABLE_ATTACK:this.stream.readShort(),this.readPos(r),this.readPos(n);break;case R.GRAPPLE_CABLE:a=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readPos(i);break;case R.LIGHTNING:u=this.stream.readShort(),l=this.stream.readShort(),this.readPos(r),this.readPos(n);break;case R.FLASHLIGHT:this.readPos(r),a=this.stream.readShort();break;case R.FORCEWALL:this.readPos(r),this.readPos(n),o=this.stream.readByte();break;case R.STEAM:let c=this.stream.readShort();s=this.stream.readByte(),this.readPos(r),this.readDir(i),o=this.stream.readByte(),this.stream.readShort(),c!==-1&&this.stream.readLong();break;case R.WIDOWBEAMOUT:this.stream.readShort();case R.HEATBEAM:case R.MONSTER_HEATBEAM:a=this.stream.readShort(),this.readPos(r),this.readPos(n),this.readDir(i);break}this.handler&&this.handler.onTempEntity(e,r,n,i,s,o,a,u,l)}parseSpawnBaseline(){let e=this.parseEntityBits(),r=Ht();this.parseDelta(Ht(),r,e.number,e.bits,e.bitsHigh),this.handler&&this.handler.onSpawnBaseline(r)}parseFrame(){let e=this.stream.readLong(),r=this.stream.readLong(),n=0;this.protocolVersion!==26&&this.protocolVersion!==25&&(n=this.stream.readByte());let i=this.stream.readByte(),s=this.stream.readData(i),o=this.stream.readByte();if(o=this.translateCommand(o),o!==k.playerinfo){if(this.strictMode)throw new Error(`Expected svc_playerinfo after svc_frame, got ${o}`);return}let a=this.parsePlayerState(),u=this.stream.readByte();if(u=this.translateCommand(u),u!==k.packetentities){if(this.strictMode)throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${u}`);return}let l=this.collectPacketEntities();if(this.isDemo===jb){let c=this.stream.readByte();for(let f=0;f<c;f++)this.stream.readByte()}this.isDemo===qb&&this.stream.readLong(),this.handler&&this.handler.onFrame({serverFrame:e,deltaFrame:r,surpressCount:n,areaBytes:i,areaBits:s,playerState:a,packetEntities:{delta:!0,entities:l}})}parsePlayerState(){let e=pn(),r=this.stream.readShort();r&1&&(e.pm_type=this.stream.readByte()),r&2&&(e.origin.x=this.readCoord(),e.origin.y=this.readCoord(),e.origin.z=this.readCoord()),r&4&&(e.velocity.x=this.readCoord(),e.velocity.y=this.readCoord(),e.velocity.z=this.readCoord()),r&8&&(e.pm_time=this.stream.readByte()),r&16&&(e.pm_flags=this.stream.readByte()),r&32&&(e.gravity=this.stream.readShort()),r&64&&(e.delta_angles.x=this.stream.readShort()*(180/32768),e.delta_angles.y=this.stream.readShort()*(180/32768),e.delta_angles.z=this.stream.readShort()*(180/32768)),r&128&&(e.viewoffset.x=(this.stream.readByte()<<24>>24)*.25,e.viewoffset.y=(this.stream.readByte()<<24>>24)*.25,e.viewoffset.z=(this.stream.readByte()<<24>>24)*.25),r&256&&(e.viewangles.x=this.readAngle16(),e.viewangles.y=this.readAngle16(),e.viewangles.z=this.readAngle16()),r&512&&(e.kick_angles.x=(this.stream.readByte()<<24>>24)*.25,e.kick_angles.y=(this.stream.readByte()<<24>>24)*.25,e.kick_angles.z=(this.stream.readByte()<<24>>24)*.25),r&4096&&(e.gun_index=this.stream.readByte()),r&8192&&(e.gun_frame=this.stream.readByte(),e.gun_offset.x=(this.stream.readByte()<<24>>24)*.25,e.gun_offset.y=(this.stream.readByte()<<24>>24)*.25,e.gun_offset.z=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.x=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.y=(this.stream.readByte()<<24>>24)*.25,e.gun_angles.z=(this.stream.readByte()<<24>>24)*.25),r&1024&&(e.blend[0]=this.stream.readByte(),e.blend[1]=this.stream.readByte(),e.blend[2]=this.stream.readByte(),e.blend[3]=this.stream.readByte()),r&2048&&(e.fov=this.stream.readByte()),r&16384&&(e.rdflags=this.stream.readByte());let n=this.stream.readLong();for(let i=0;i<32;i++)n&1<<i&&(e.stats[i]=this.stream.readShort());return e}parsePacketEntities(e){let r=this.collectPacketEntities();this.handler&&this.handler.onFrame({serverFrame:0,deltaFrame:0,surpressCount:0,areaBytes:0,areaBits:new Uint8Array,playerState:pn(),packetEntities:{delta:e,entities:r}})}collectPacketEntities(){let e=[];for(;;){let r=this.parseEntityBits();if(r.bits&$s){if(r.number===0)break;continue}let n=Ht(),i=r.number===0&&!(r.bits&Ks);if((r.number!==0||i)&&this.parseDelta(Ht(),n,r.number,r.bits,r.bitsHigh),r.number===0)break;e.push(n)}return e}parseEntityBits(){let e=this.stream.readByte();e&Ks&&(e|=this.stream.readByte()<<8),e&Da&&(e|=this.stream.readByte()<<16),e&Ba&&(e|=this.stream.readByte()<<24);let r=0;this.protocolVersion===hi&&e&Oa&&(r=this.stream.readByte());let n;return e&Pa?n=this.stream.readShort():n=this.stream.readByte(),{number:n,bits:e,bitsHigh:r}}parseDelta(e,r,n,i,s=0){r.number=e.number,r.modelindex=e.modelindex,r.modelindex2=e.modelindex2,r.modelindex3=e.modelindex3,r.modelindex4=e.modelindex4,r.frame=e.frame,r.skinnum=e.skinnum,r.effects=e.effects,r.renderfx=e.renderfx,r.origin.x=e.origin.x,r.origin.y=e.origin.y,r.origin.z=e.origin.z,r.old_origin.x=e.origin.x,r.old_origin.y=e.origin.y,r.old_origin.z=e.origin.z,r.angles.x=e.angles.x,r.angles.y=e.angles.y,r.angles.z=e.angles.z,r.sound=e.sound,r.event=e.event,r.solid=e.solid,r.alpha=e.alpha,r.scale=e.scale,r.instanceBits=e.instanceBits,r.loopVolume=e.loopVolume,r.loopAttenuation=e.loopAttenuation,r.owner=e.owner,r.oldFrame=e.oldFrame,r.number=n,r.bits=i,r.bitsHigh=s,i&Ar&&(r.modelindex=this.stream.readByte()),i&Lr&&(r.modelindex2=this.stream.readByte()),i&Tr&&(r.modelindex3=this.stream.readByte()),i&kr&&(r.modelindex4=this.stream.readByte()),i&_r&&(r.frame=this.stream.readByte()),i&Er&&(r.frame=this.stream.readShort()),i&_t&&i&St?r.skinnum=this.stream.readLong():i&_t?r.skinnum=this.stream.readByte():i&St&&(r.skinnum=this.stream.readShort()),i&xt&&i&wt?r.effects=this.stream.readLong():i&xt?r.effects=this.stream.readByte():i&wt&&(r.effects=this.stream.readShort()),i&bt&&i&vt?r.renderfx=this.stream.readLong():i&bt?r.renderfx=this.stream.readByte():i&vt&&(r.renderfx=this.stream.readShort()),i&gr&&(r.origin.x=this.readCoord()),i&yr&&(r.origin.y=this.readCoord()),i&wr&&(r.origin.z=this.readCoord()),i&Sr&&(r.angles.x=this.readAngle()),i&br&&(r.angles.y=this.readAngle()),i&xr&&(r.angles.z=this.readAngle()),i&Cr&&this.readPos(r.old_origin),i&Ir&&(r.sound=this.stream.readByte()),i&vr?r.event=this.stream.readByte():r.event=0,i&Rr&&(r.solid=this.stream.readShort()),this.protocolVersion===hi&&(i&Mr&&(r.alpha=this.stream.readByte()/255),i&Fr&&(r.scale=this.stream.readFloat()),i&zr&&(r.instanceBits=this.stream.readLong()),i&Pr&&(r.loopVolume=this.stream.readByte()/255),s&Dr&&(r.loopAttenuation=this.stream.readByte()/255),s&Br&&(r.owner=this.stream.readShort()),s&Or&&(r.oldFrame=this.stream.readShort()))}};var Gc=(c=>(c.WeaponFire="weapon_fire",c.DamageDealt="damage_dealt",c.DamageReceived="damage_received",c.Pickup="pickup",c.Death="death",c.Kill="kill",c.Spawn="spawn",c.PlayerInfo="player_info",c.Chat="chat",c.Objective="objective",c))(Gc||{});var mi=class{constructor(e){this.events=[];this.summary={totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map};this.header=null;this.configStrings=new Map;this.serverInfo={};this.statistics=null;this.playerStats=new Map;this.weaponStats=new Map;this.activeEntities=new Set;this.buffer=e}analyze(){let e=new je(this.buffer),r=-1,n=0,i=.1,s=0,o={onServerData:(a,u,l,c,f,d,h,m)=>{s=a,this.header={protocolVersion:a,gameDir:c,levelName:d,playerNum:f,serverCount:u,spawnCount:u,tickRate:h,demoType:m},h&&h>0&&(i=1/h)},onConfigString:(a,u)=>{this.configStrings.set(a,u),a===0&&this.parseServerInfo(u)},onSpawnBaseline:a=>{},onFrame:a=>{let u=new Set;if(a.packetEntities&&a.packetEntities.entities)for(let l of a.packetEntities.entities)u.add(l.number),this.activeEntities.has(l.number)||this.recordEvent({type:"spawn",frame:r,time:n,entityId:l.number,position:{x:l.origin.x,y:l.origin.y,z:l.origin.z},description:`Entity ${l.number} spawned`});this.activeEntities=u,a.playerState&&this.header},onPrint:(a,u)=>{let l=u.replace(/\n/g," ").trim();l.includes("died")||l.includes("killed")||l.includes("suicide")?(this.summary.totalDeaths++,this.recordEvent({type:"death",frame:r,time:n,description:l})):l.startsWith("You got the ")?this.recordEvent({type:"pickup",frame:r,time:n,description:l}):(a===3||a===2)&&this.recordEvent({type:"chat",frame:r,time:n,description:l,data:{level:a}})},onCenterPrint:a=>{this.recordEvent({type:"objective",frame:r,time:n,description:a.trim()})},onStuffText:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onMuzzleFlash2:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onMuzzleFlash3:(a,u)=>{this.handleWeaponFire(a,u,r,n)},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{},onDamage:a=>{for(let u of a)if(this.recordEvent({type:"damage_received",frame:r,time:n,value:u.damage,position:u.dir,description:`Took ${u.damage} damage`}),this.summary.damageReceived+=u.damage,this.header){let l=this.getOrCreatePlayerStats(this.header.playerNum);l.damageReceived+=u.damage}}};for(;e.hasMore();){let a=e.readNextBlock();if(!a)break;r++,n=r*i;let u=new it(a.data,o);u.setProtocolVersion(s),u.parseMessage(),s=u.getProtocolVersion()}return this.statistics={duration:n,frameCount:r+1,averageFps:(r+1)/(n||1),mapName:this.header?.levelName||"unknown",playerCount:1},{events:this.events,summary:this.summary,header:this.header,configStrings:this.configStrings,serverInfo:this.serverInfo,statistics:this.statistics,playerStats:this.playerStats,weaponStats:this.weaponStats}}handleWeaponFire(e,r,n,i){this.recordEvent({type:"weapon_fire",frame:n,time:i,entityId:e,value:r,description:`Weapon ${r} fired by ${e}`});let s=this.summary.weaponUsage.get(r)||0;this.summary.weaponUsage.set(r,s+1);let o=this.getOrCreateWeaponStat(e,r);o.shotsFired++}recordEvent(e){this.events.push(e)}parseServerInfo(e){let r=e.split("\\");for(let n=1;n<r.length;n+=2)n+1<r.length&&(this.serverInfo[r[n]]=r[n+1])}getOrCreatePlayerStats(e){let r=this.playerStats.get(e);return r||(r={kills:0,deaths:0,damageDealt:0,damageReceived:0,suicides:0},this.playerStats.set(e,r)),r}getOrCreateWeaponStat(e,r){let n=this.weaponStats.get(e);n||(n=[],this.weaponStats.set(e,n));let i=n.find(s=>s.weaponId===r);return i||(i={weaponId:r,shotsFired:0,hits:0,kills:0},n.push(i)),i}};var Wc=(i=>(i[i.FirstPerson=0]="FirstPerson",i[i.ThirdPerson=1]="ThirdPerson",i[i.Free=2]="Free",i[i.Follow=3]="Follow",i))(Wc||{});var Na=(i=>(i[i.Stopped=0]="Stopped",i[i.Playing=1]="Playing",i[i.Paused=2]="Paused",i[i.Finished=3]="Finished",i))(Na||{}),Qb=()=>({onServerData:()=>{},onConfigString:()=>{},onSpawnBaseline:()=>{},onFrame:()=>{},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}}),Vt=class{constructor(){this.reader=null;this.buffer=null;this.state=0;this.playbackSpeed=1;this.currentProtocolVersion=0;this.currentFrameIndex=-1;this.lastFrameData=null;this.accumulatedTime=0;this.frameDuration=100;this.snapshotInterval=100;this.snapshots=new Map;this.cachedEvents=null;this.cachedSummary=null;this.cachedHeader=null;this.cachedConfigStrings=null;this.cachedServerInfo=null;this.cachedStatistics=null;this.cachedPlayerStats=null;this.cachedWeaponStats=null;this.tracker=null;this.cameraMode=0;this.thirdPersonDistance=80;this.thirdPersonOffset={x:0,y:0,z:0}}setHandler(e){this.handler=e}setCallbacks(e){this.callbacks=e}loadDemo(e){this.buffer=e,this.reader=new je(e),this.transitionState(0),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.snapshots.clear(),this.lastFrameData=null,this.cachedEvents=null,this.cachedSummary=null,this.cachedHeader=null,this.cachedConfigStrings=null,this.cachedServerInfo=null,this.cachedStatistics=null,this.cachedPlayerStats=null,this.cachedWeaponStats=null}play(){this.reader&&this.state!==1&&this.transitionState(1)}pause(){this.state===1&&this.transitionState(2)}stop(){this.transitionState(0),this.reader&&this.reader.reset(),this.accumulatedTime=0,this.currentProtocolVersion=0,this.currentFrameIndex=-1,this.lastFrameData=null}transitionState(e){this.state!==e&&(this.state=e,this.callbacks?.onPlaybackStateChange&&this.callbacks.onPlaybackStateChange(e))}setFrameDuration(e){this.frameDuration=e}setSpeed(e){this.playbackSpeed=Math.max(.1,Math.min(e,16))}getSpeed(){return this.playbackSpeed}getPlaybackSpeed(){return this.playbackSpeed}getInterpolationFactor(){return this.frameDuration<=0?0:Math.max(0,Math.min(1,this.accumulatedTime/this.frameDuration))}update(e){if(!(this.state!==1||!this.reader))for(this.accumulatedTime+=e*1e3*this.playbackSpeed;this.accumulatedTime>=this.frameDuration;){if(!this.processNextFrame())return;this.accumulatedTime-=this.frameDuration,this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}}stepForward(){this.reader&&(this.processNextFrame(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime()))}stepBackward(){this.reader&&this.currentFrameIndex>0&&this.seek(this.currentFrameIndex-1)}seekToTime(e){let r=this.timeToFrame(e);this.seek(r)}seekToFrame(e){this.seek(e)}frameToTime(e){return e*this.frameDuration/1e3}timeToFrame(e){return Math.floor(e*1e3/this.frameDuration)}playFrom(e){if(e.type==="frame")this.seek(e.frame);else if(e.type==="time")this.seekToTime(e.seconds);else throw new Error(`Invalid offset type: ${e.type}`);this.play()}playRange(e,r){let n=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),i=r.type==="frame"?r.frame:this.timeToFrame(r.seconds),s=this.getTotalFrames(),o=Math.max(0,s-1);if(n<0)throw new Error(`Invalid start offset: ${n}`);if(i<n)throw new Error(`End offset (${i}) cannot be before start offset (${n})`);this.playFrom(e);let a=this.callbacks?.onFrameUpdate,u={...this.callbacks,onFrameUpdate:l=>{a&&a(l),this.currentFrameIndex>=i&&(this.pause(),this.callbacks===u&&this.setCallbacks({...this.callbacks,onFrameUpdate:a}),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete())}};this.setCallbacks(u)}seek(e){if(!this.reader)return;let r=this.getTotalFrames();if(r>0&&e>=r&&(e=r-1),e<0&&(e=0),e===this.currentFrameIndex+1){this.processNextFrame(),this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}if(e===this.currentFrameIndex){this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete();return}let n=-1,i=null;if(e>this.currentFrameIndex&&this.currentFrameIndex!==-1&&(n=this.currentFrameIndex),this.callbacks?.onRestoreSnapshot)for(let[s,o]of this.snapshots)s<=e&&s>n&&(n=s,i=o);for(n===-1&&this.currentFrameIndex>e?(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0):n===-1&&(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0),i&&this.callbacks?.onRestoreSnapshot&&(this.callbacks.onRestoreSnapshot(i),this.reader.seekToMessage(n+1)?this.currentFrameIndex=n:(this.reader.reset(),this.currentFrameIndex=-1,this.currentProtocolVersion=0));this.currentFrameIndex<e&&(this.callbacks?.onCaptureSnapshot&&(this.currentFrameIndex+1)%this.snapshotInterval,!!this.processNextFrame()););this.accumulatedTime=0,this.callbacks?.onSeekComplete&&this.callbacks.onSeekComplete(),this.callbacks?.onTimeUpdate&&this.callbacks.onTimeUpdate(this.getCurrentTime())}processNextFrame(){if(!this.reader||!this.reader.hasMore())return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;let e=this.reader.readNextBlock();if(!e)return this.transitionState(3),this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),!1;this.currentFrameIndex++,this.tracker&&(this.tracker.setCurrentFrame(this.currentFrameIndex),this.tracker.setCurrentTime(this.getCurrentTime()));try{let r={...this.handler||Qb(),onFrame:i=>{this.lastFrameData=i,this.handler?.onFrame&&this.handler.onFrame(i),this.callbacks?.onFrameUpdate&&this.callbacks.onFrameUpdate(i)}},n=new it(e.data,r);if(n.setProtocolVersion(this.currentProtocolVersion),n.parseMessage(),this.currentProtocolVersion=n.getProtocolVersion(),this.callbacks?.onCaptureSnapshot&&this.currentFrameIndex%this.snapshotInterval===0&&this.currentFrameIndex>0){let i=this.callbacks.onCaptureSnapshot(this.currentFrameIndex);i&&this.snapshots.set(this.currentFrameIndex,i)}}catch(r){return console.error("Error processing demo frame",r),this.callbacks?.onPlaybackError&&this.callbacks.onPlaybackError(r instanceof Error?r:new Error(String(r))),!1}return!0}getState(){return this.state}getCurrentTime(){return this.currentFrameIndex<0?this.accumulatedTime:this.currentFrameIndex*this.frameDuration+this.accumulatedTime}getFrameCount(){return this.reader?this.reader.getMessageCount():0}getTotalFrames(){return this.getFrameCount()}getCurrentFrame(){return this.currentFrameIndex<0?0:this.currentFrameIndex}getDuration(){return this.getFrameCount()*this.frameDuration/1e3}getTotalBytes(){return this.reader?this.reader.getProgress().total:0}getProcessedBytes(){return this.reader?this.reader.getOffset():0}getFrameData(e){if(e===this.currentFrameIndex&&this.lastFrameData)return this.lastFrameData;let r=this.state;return this.pause(),this.seek(e),r===1&&this.play(),this.lastFrameData}getFramePlayerState(e){if(e===this.currentFrameIndex&&this.handler?.getPlayerState){let n=this.handler.getPlayerState();if(n)return n}let r=this.getFrameData(e);return r?r.playerState:null}getFrameEntities(e){if(e===this.currentFrameIndex&&this.handler?.getEntities){let r=this.handler.getEntities();if(r)return Array.from(r.values())}if(this.seek(e),this.handler?.getEntities){let r=this.handler.getEntities();return r?Array.from(r.values()):[]}return[]}compareFrames(e,r){let n=this.getFramePlayerState(e),i=this.getFrameEntities(e),s=new Map;i.forEach(c=>s.set(c.number,c));let o=this.getFramePlayerState(r),a=this.getFrameEntities(r),u=new Map;a.forEach(c=>u.set(c.number,c));let l={frameA:e,frameB:r,playerStateDiff:{origin:null,viewangles:null,health:null,ammo:null},entityDiffs:{added:[],removed:[],moved:[]}};n&&o&&((n.origin.x!==o.origin.x||n.origin.y!==o.origin.y||n.origin.z!==o.origin.z)&&(l.playerStateDiff.origin={x:o.origin.x-n.origin.x,y:o.origin.y-n.origin.y,z:o.origin.z-n.origin.z}),n.stats[1]!==o.stats[1]&&(l.playerStateDiff.health=o.stats[1]-n.stats[1]),n.stats[2]!==o.stats[2]&&(l.playerStateDiff.ammo=o.stats[2]-n.stats[2]));for(let[c,f]of u){let d=s.get(c);d?(d.origin.x!==f.origin.x||d.origin.y!==f.origin.y||d.origin.z!==f.origin.z)&&l.entityDiffs.moved.push({id:c,delta:{x:f.origin.x-d.origin.x,y:f.origin.y-d.origin.y,z:f.origin.z-d.origin.z}}):l.entityDiffs.added.push(c)}for(let[c,f]of s)u.has(c)||l.entityDiffs.removed.push(c);return l}getEntityTrajectory(e,r,n){let i=[],s=this.getCurrentFrame();for(this.seek(r);this.getCurrentFrame()<=n&&this.state!==3;){let o=null;if(e===-1){let a=this.getFramePlayerState(this.getCurrentFrame());a&&(o={...a.origin})}else if(this.handler?.getEntities){let a=this.handler.getEntities().get(e);a&&(o={...a.origin})}if(o&&i.push(o),this.getCurrentFrame()===n)break;this.stepForward()}return this.seek(s),i}getEvents(){return this.ensureAnalysis(),this.cachedEvents||[]}getDemoEvents(){return this.getEvents()}filterEvents(e,r){return this.getDemoEvents().filter(i=>!(i.type!==e||r!==void 0&&i.entityId!==r))}getEventSummary(){return this.ensureAnalysis(),this.cachedSummary||{totalKills:0,totalDeaths:0,damageDealt:0,damageReceived:0,weaponUsage:new Map}}getMetadata(){let e=this.getDemoHeader();if(!e)return null;let r=this.getDemoServerInfo(),n="Unknown";return this.cachedConfigStrings,{mapName:e.levelName,playerName:n,serverName:r.hostname,demoVersion:e.protocolVersion,tickRate:e.tickRate||10}}getDemoHeader(){return this.ensureAnalysis(),this.cachedHeader}getDemoConfigStrings(){return this.ensureAnalysis(),this.cachedConfigStrings||new Map}getDemoServerInfo(){return this.ensureAnalysis(),this.cachedServerInfo||{}}getDemoStatistics(){return this.ensureAnalysis(),this.cachedStatistics}getPlayerStatistics(e){return this.ensureAnalysis(),this.cachedPlayerStats?.get(e)||null}getWeaponStatistics(e){return this.ensureAnalysis(),this.cachedWeaponStats?.get(e)||null}ensureAnalysis(){if(!this.cachedEvents&&this.buffer){let r=new mi(this.buffer).analyze();this.cachedEvents=r.events,this.cachedSummary=r.summary,this.cachedHeader=r.header,this.cachedConfigStrings=r.configStrings,this.cachedServerInfo=r.serverInfo,this.cachedStatistics=r.statistics,this.cachedPlayerStats=r.playerStats,this.cachedWeaponStats=r.weaponStats}}setCameraMode(e){this.cameraMode=e}getCameraMode(){return this.cameraMode}setThirdPersonDistance(e){this.thirdPersonDistance=e}setThirdPersonOffset(e){this.thirdPersonOffset=e}async playWithTracking(e,r={}){if(this.tracker=e,e.startTracking(),r.fastForward)try{this.state===0&&this.reader,this.transitionState(1);let n=100,i=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let s=0;for(;s<n;){if(!this.processNextFrame()){let o=e.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),o}s++}return await new Promise(o=>setTimeout(o,0)),i()};return await i()}catch(n){throw e.stopTracking(),this.tracker=null,n}else return new Promise((n,i)=>{let s=this.callbacks?.onPlaybackComplete,o=this.callbacks?.onPlaybackError,a=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:s,onPlaybackError:o}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let u=e.stopTracking();s&&s(),a(),n(u)},onPlaybackError:u=>{e.stopTracking(),o&&o(u),a(),i(u)}}),this.play()})}async playRangeWithTracking(e,r,n,i={}){this.tracker=n,n.startTracking();let s=e.type==="frame"?e.frame:this.timeToFrame(e.seconds),o=r.type==="frame"?r.frame:this.timeToFrame(r.seconds);if(i.fastForward)try{this.playFrom(e),this.transitionState(1);let a=100,u=async()=>{if(this.state!==1)throw new Error("Playback stopped unexpectedly during fast forward");let l=0;for(;l<a;){if(this.currentFrameIndex>=o||!this.processNextFrame()){let c=n.stopTracking();return this.tracker=null,this.callbacks?.onPlaybackComplete&&this.callbacks.onPlaybackComplete(),c}l++}return await new Promise(c=>setTimeout(c,0)),u()};return await u()}catch(a){throw n.stopTracking(),this.tracker=null,a}else return new Promise((a,u)=>{let l=this.callbacks?.onPlaybackComplete,c=this.callbacks?.onPlaybackError,f=()=>{this.setCallbacks({...this.callbacks,onPlaybackComplete:l,onPlaybackError:c}),this.tracker=null};this.setCallbacks({...this.callbacks,onPlaybackComplete:()=>{let d=n.stopTracking();l&&l(),f(),a(d)},onPlaybackError:d=>{n.stopTracking(),c&&c(d),f(),u(d)}}),this.playRange(e,r)})}};var Zs=class{constructor(){this.isRecording=!1;this.startTime=0;this.frameCount=0;this.filename=null;this.lastMessageSize=-1;this.messageBuffer=new Hr(1024*1024)}startRecording(e,r=0){this.isRecording||(this.isRecording=!0,this.filename=e,this.startTime=r,this.frameCount=0,this.messageBuffer.reset(),console.log(`DemoRecorder: Started recording to ${e}`))}recordMessage(e){if(this.isRecording){this.messageBuffer.writeLong(e.byteLength);for(let r=0;r<e.length;r++)this.messageBuffer.writeByte(e[r]);this.frameCount++}}stopRecording(){return this.isRecording?(this.isRecording=!1,this.messageBuffer.writeLong(-1),console.log(`DemoRecorder: Stopped recording. Frames: ${this.frameCount}, Size: ${this.messageBuffer.getOffset()} bytes`),this.messageBuffer.getData()):null}getIsRecording(){return this.isRecording}};var Ua=class{static validate(e,r){if(r&&!r.toLowerCase().endsWith(".dm2"))return{valid:!1,error:"Invalid file extension (expected .dm2)"};if(e.byteLength<5)return{valid:!1,error:"File too small to be a valid demo"};let n=new DataView(e),i=n.getInt32(0,!0);if(i<=0||i>e.byteLength-4)return{valid:!1,error:`Invalid first block length: ${i}`};let s=n.getUint8(4);if(s!==k.serverdata)return{valid:!1,error:`First command is not svc_serverdata (expected ${k.serverdata}, got ${s})`};let o=-1;return i>=5&&(o=n.getInt32(5,!0)),{valid:!0,version:o}}};var Ys=class{constructor(){this.writer=new Hr}getData(){return this.writer.getData()}writeServerData(e,r,n,i,s,o){this.writer.writeByte(k.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeString(i),this.writer.writeShort(s),this.writer.writeString(o)}writeServerDataRerelease(e,r,n,i,s,o,a){this.writer.writeByte(k.serverdata),this.writer.writeLong(e),this.writer.writeLong(r),this.writer.writeByte(n),this.writer.writeByte(i),this.writer.writeString(s),this.writer.writeShort(o),this.writer.writeString(a)}writeConfigString(e,r){this.writer.writeByte(k.configstring),this.writer.writeShort(e),this.writer.writeString(r)}writeSpawnBaseline(e,r){this.writer.writeByte(k.spawnbaseline),this.writeEntityState(e,null,!0,r)}writeStuffText(e){this.writer.writeByte(k.stufftext),this.writer.writeString(e)}writeCenterPrint(e){this.writer.writeByte(k.centerprint),this.writer.writeString(e)}writePrint(e,r){this.writer.writeByte(k.print),this.writer.writeByte(e),this.writer.writeString(r)}writeLayout(e){this.writer.writeByte(k.layout),this.writer.writeString(e)}writeInventory(e){this.writer.writeByte(k.inventory);for(let r=0;r<256;r++)this.writer.writeShort(e[r]||0)}writeMuzzleFlash(e,r){this.writer.writeByte(k.muzzleflash),this.writer.writeShort(e),this.writer.writeByte(r)}writeMuzzleFlash2(e,r){this.writer.writeByte(k.muzzleflash2),this.writer.writeShort(e),this.writer.writeByte(r)}writeTempEntity(e,r,n,i,s,o,a,u,l){console.warn("writeTempEntity not implemented - skipping message")}writeSound(e,r,n,i,s,o,a){this.writer.writeByte(k.sound),this.writer.writeByte(e),this.writer.writeByte(r),e&1&&this.writer.writeByte(n||0),e&2&&this.writer.writeByte(i||0),e&16&&this.writer.writeByte(s||0),e&8&&this.writer.writeShort(o||0),e&4&&a&&(this.writer.writeCoord(a.x),this.writer.writeCoord(a.y),this.writer.writeCoord(a.z))}writeDisconnect(){this.writer.writeByte(k.disconnect)}writeReconnect(){this.writer.writeByte(k.reconnect)}writeFrame(e,r){this.writer.writeByte(k.frame),this.writer.writeLong(e.serverFrame),this.writer.writeLong(e.deltaFrame),r!==25&&r!==26&&this.writer.writeByte(e.surpressCount),this.writer.writeByte(e.areaBytes),e.areaBytes>0&&this.writer.writeBytes(e.areaBits),this.writer.writeByte(k.playerinfo),this.writePlayerState(e.playerState),this.writePacketEntities(e.packetEntities.entities,e.packetEntities.delta,r)}writePlayerState(e){let r=0;e.pm_type!==0&&(r|=1),(e.origin.x!==0||e.origin.y!==0||e.origin.z!==0)&&(r|=2),(e.velocity.x!==0||e.velocity.y!==0||e.velocity.z!==0)&&(r|=4),e.pm_time!==0&&(r|=8),e.pm_flags!==0&&(r|=16),e.gravity!==0&&(r|=32),(e.delta_angles.x!==0||e.delta_angles.y!==0||e.delta_angles.z!==0)&&(r|=64),(e.viewoffset.x!==0||e.viewoffset.y!==0||e.viewoffset.z!==0)&&(r|=128),(e.viewangles.x!==0||e.viewangles.y!==0||e.viewangles.z!==0)&&(r|=256),(e.kick_angles.x!==0||e.kick_angles.y!==0||e.kick_angles.z!==0)&&(r|=512),(e.blend[0]!==0||e.blend[1]!==0||e.blend[2]!==0||e.blend[3]!==0)&&(r|=1024),e.gun_index!==0&&(r|=4096),(e.gun_frame!==0||e.gun_offset.x!==0||e.gun_offset.y!==0||e.gun_offset.z!==0||e.gun_angles.x!==0||e.gun_angles.y!==0||e.gun_angles.z!==0)&&(r|=8192),e.fov!==0&&(r|=2048),e.rdflags!==0&&(r|=16384),this.writer.writeShort(r),r&1&&this.writer.writeByte(e.pm_type),r&2&&(this.writer.writeCoord(e.origin.x),this.writer.writeCoord(e.origin.y),this.writer.writeCoord(e.origin.z)),r&4&&(this.writer.writeCoord(e.velocity.x),this.writer.writeCoord(e.velocity.y),this.writer.writeCoord(e.velocity.z)),r&8&&this.writer.writeByte(e.pm_time),r&16&&this.writer.writeByte(e.pm_flags),r&32&&this.writer.writeShort(e.gravity),r&64&&(this.writer.writeShort(Math.round(e.delta_angles.x*(32768/180))),this.writer.writeShort(Math.round(e.delta_angles.y*(32768/180))),this.writer.writeShort(Math.round(e.delta_angles.z*(32768/180)))),r&128&&(this.writer.writeChar(Math.round(e.viewoffset.x*4)),this.writer.writeChar(Math.round(e.viewoffset.y*4)),this.writer.writeChar(Math.round(e.viewoffset.z*4))),r&256&&(this.writer.writeAngle16(e.viewangles.x),this.writer.writeAngle16(e.viewangles.y),this.writer.writeAngle16(e.viewangles.z)),r&512&&(this.writer.writeChar(Math.round(e.kick_angles.x*4)),this.writer.writeChar(Math.round(e.kick_angles.y*4)),this.writer.writeChar(Math.round(e.kick_angles.z*4))),r&4096&&this.writer.writeByte(e.gun_index),r&8192&&(this.writer.writeByte(e.gun_frame),this.writer.writeChar(Math.round(e.gun_offset.x*4)),this.writer.writeChar(Math.round(e.gun_offset.y*4)),this.writer.writeChar(Math.round(e.gun_offset.z*4)),this.writer.writeChar(Math.round(e.gun_angles.x*4)),this.writer.writeChar(Math.round(e.gun_angles.y*4)),this.writer.writeChar(Math.round(e.gun_angles.z*4))),r&1024&&(this.writer.writeByte(e.blend[0]),this.writer.writeByte(e.blend[1]),this.writer.writeByte(e.blend[2]),this.writer.writeByte(e.blend[3])),r&2048&&this.writer.writeByte(e.fov),r&16384&&this.writer.writeByte(e.rdflags);let n=0;for(let i=0;i<32;i++)e.stats[i]!==0&&(n|=1<<i);this.writer.writeLong(n);for(let i=0;i<32;i++)n&1<<i&&this.writer.writeShort(e.stats[i])}writePacketEntities(e,r,n){this.writer.writeByte(r?k.deltapacketentities:k.packetentities);for(let i of e){let s=!r;this.writeEntityState(i,null,s,n)}this.writer.writeShort(0)}writeEntityState(e,r,n,i){let s=0,o=0;e.bits!==0&&!n?(s=e.bits,o=e.bitsHigh):(e.modelindex!==0&&(s|=Ar),e.modelindex2!==0&&(s|=Lr),e.modelindex3!==0&&(s|=Tr),e.modelindex4!==0&&(s|=kr),e.frame!==0&&(e.frame>=256?s|=Er:s|=_r),e.skinnum!==0&&(e.skinnum>=256?s|=St:s|=_t),e.effects!==0&&(e.effects>=256?s|=wt:s|=xt),e.renderfx!==0&&(e.renderfx>=256?s|=vt:s|=bt),e.origin.x!==0&&(s|=gr),e.origin.y!==0&&(s|=yr),e.origin.z!==0&&(s|=wr),e.angles.x!==0&&(s|=Sr),e.angles.y!==0&&(s|=br),e.angles.z!==0&&(s|=xr),(e.old_origin.x!==0||e.old_origin.y!==0||e.old_origin.z!==0)&&(s|=Cr),e.sound!==0&&(s|=Ir),e.event!==0&&(s|=vr),e.solid!==0&&(s|=Rr),i>=2023&&(e.alpha!==0&&(s|=Mr),e.scale!==0&&(s|=Fr),e.instanceBits!==0&&(s|=zr),e.loopVolume!==0&&(s|=Pr),e.loopAttenuation!==0&&(o|=Dr),e.owner!==0&&(o|=Br),e.oldFrame!==0&&(o|=Or)),e.number>=256&&(s|=Pa)),o!==0&&(s|=Oa),(s&4278190080)!==0&&(s|=Ba),(s&16711680)!==0&&(s|=Da),(s&65280)!==0&&(s|=Ks),this.writer.writeByte(s&255),s&Ks&&this.writer.writeByte(s>>8&255),s&Da&&this.writer.writeByte(s>>16&255),s&Ba&&this.writer.writeByte(s>>24&255),i>=2023&&s&Oa&&this.writer.writeByte(o&255),s&Pa?this.writer.writeShort(e.number):this.writer.writeByte(e.number),s&Ar&&this.writer.writeByte(e.modelindex),s&Lr&&this.writer.writeByte(e.modelindex2),s&Tr&&this.writer.writeByte(e.modelindex3),s&kr&&this.writer.writeByte(e.modelindex4),s&_r&&this.writer.writeByte(e.frame),s&Er&&this.writer.writeShort(e.frame),s&_t&&s&St?this.writer.writeLong(e.skinnum):s&_t?this.writer.writeByte(e.skinnum):s&St&&this.writer.writeShort(e.skinnum),s&xt&&s&wt?this.writer.writeLong(e.effects):s&xt?this.writer.writeByte(e.effects):s&wt&&this.writer.writeShort(e.effects),s&bt&&s&vt?this.writer.writeLong(e.renderfx):s&bt?this.writer.writeByte(e.renderfx):s&vt&&this.writer.writeShort(e.renderfx),s&gr&&this.writer.writeCoord(e.origin.x),s&yr&&this.writer.writeCoord(e.origin.y),s&wr&&this.writer.writeCoord(e.origin.z),s&Sr&&this.writer.writeAngle(e.angles.x),s&br&&this.writer.writeAngle(e.angles.y),s&xr&&this.writer.writeAngle(e.angles.z),s&Cr&&(this.writer.writeCoord(e.old_origin.x),this.writer.writeCoord(e.old_origin.y),this.writer.writeCoord(e.old_origin.z)),s&Ir&&this.writer.writeByte(e.sound),s&vr&&this.writer.writeByte(e.event),s&Rr&&this.writer.writeShort(e.solid),i>=2023&&(s&Mr&&this.writer.writeByte(Math.round(e.alpha*255)),s&Fr&&this.writer.writeFloat(e.scale),s&zr&&this.writer.writeLong(e.instanceBits),s&Pr&&this.writer.writeByte(Math.round(e.loopVolume*255)),o&Dr&&this.writer.writeByte(Math.round(e.loopAttenuation*255)),o&Br&&this.writer.writeShort(e.owner),o&Or&&this.writer.writeShort(e.oldFrame))}};var Ha=class{constructor(){this.writer=new Hr}writeBlock(e){this.writer.writeLong(e.byteLength),this.writer.writeBytes(e)}writeEOF(){this.writer.writeLong(-1)}getData(){return this.writer.getData()}};function Va(t,e){let r=e.bits,n=e.bitsHigh;t.number=e.number,r&Ar&&(t.modelindex=e.modelindex),r&Lr&&(t.modelindex2=e.modelindex2),r&Tr&&(t.modelindex3=e.modelindex3),r&kr&&(t.modelindex4=e.modelindex4),r&_r&&(t.frame=e.frame),r&Er&&(t.frame=e.frame),(r&_t||r&St)&&(t.skinnum=e.skinnum),(r&xt||r&wt)&&(t.effects=e.effects),(r&bt||r&vt)&&(t.renderfx=e.renderfx),r&gr&&(t.origin.x=e.origin.x),r&yr&&(t.origin.y=e.origin.y),r&wr&&(t.origin.z=e.origin.z),r&Sr&&(t.angles.x=e.angles.x),r&br&&(t.angles.y=e.angles.y),r&xr&&(t.angles.z=e.angles.z),r&Cr&&(t.old_origin.x=e.old_origin.x,t.old_origin.y=e.old_origin.y,t.old_origin.z=e.old_origin.z),r&Ir&&(t.sound=e.sound),r&vr&&(t.event=e.event),r&Rr&&(t.solid=e.solid),r&Mr&&(t.alpha=e.alpha),r&Fr&&(t.scale=e.scale),r&zr&&(t.instanceBits=e.instanceBits),r&Pr&&(t.loopVolume=e.loopVolume),n&Dr&&(t.loopAttenuation=e.loopAttenuation),n&Br&&(t.owner=e.owner),n&Or&&(t.oldFrame=e.oldFrame)}var Ga=class{extractClip(e,r,n,i){let s=new je(e.buffer),o=r.type==="frame"?r.frame:i.timeToFrame(r.seconds),a=n.type==="frame"?n.frame:i.timeToFrame(n.seconds);if(!s.seekToMessage(o))throw new Error(`Start frame ${o} out of bounds`);let u=s.getOffset(),l=e.byteLength;s.seekToMessage(a+1)&&(l=s.getOffset());let c=e.slice(u,l),f=new Uint8Array(c.length+4);return f.set(c),new DataView(f.buffer).setInt32(c.length,-1,!0),f}extractDemoRange(e,r,n){let i=new Vt;return i.loadDemo(e.buffer),this.extractClip(e,{type:"frame",frame:r},{type:"frame",frame:n},i)}async captureWorldState(e,r){let n=new Vt;n.loadDemo(e.buffer);let i={serverData:{protocol:0,serverCount:0,attractLoop:0,gameDir:"",playerNum:0,levelName:""},configStrings:new Map,entityBaselines:new Map,playerState:pn(),currentEntities:new Map,currentFrameNumber:0},s={onServerData:(a,u,l,c,f,d,h,m)=>{i.serverData={protocol:a,serverCount:u,attractLoop:l,gameDir:c,playerNum:f,levelName:d,tickRate:h,demoType:m}},onConfigString:(a,u)=>{i.configStrings.set(a,u)},onSpawnBaseline:a=>{i.entityBaselines.set(a.number,{...a})},onFrame:a=>{i.playerState={...a.playerState},i.currentFrameNumber=a.serverFrame,a.packetEntities.delta||i.currentEntities.clear();let u=new Map;if(a.packetEntities.delta)for(let[l,c]of i.currentEntities)u.set(l,c);for(let l of a.packetEntities.entities){if(l.bits&$s){u.delete(l.number);continue}let c=u.get(l.number);if(c)c={...c};else{let f=i.entityBaselines.get(l.number);f?c={...f}:(c=Ht(),c.number=l.number)}Va(c,l),u.set(l.number,c)}i.currentEntities=u},onCenterPrint:()=>{},onStuffText:()=>{},onPrint:()=>{},onSound:()=>{},onTempEntity:()=>{},onLayout:()=>{},onInventory:()=>{},onMuzzleFlash:()=>{},onMuzzleFlash2:()=>{},onDisconnect:()=>{},onReconnect:()=>{},onDownload:()=>{}};n.setHandler(s);let o=r.type==="frame"?r.frame:n.timeToFrame(r.seconds);return n.seek(o),i}extractStandaloneClip(e,r,n,i){let s=new Ha,o=new Ys,a=new Vt;a.loadDemo(e.buffer);let u=r.type==="frame"?r.frame:a.timeToFrame(r.seconds),l=n.type==="frame"?n.frame:a.timeToFrame(n.seconds),{serverData:c}=i;c.protocol>=2023?o.writeServerDataRerelease(c.protocol,c.serverCount,c.demoType||0,c.tickRate||10,c.gameDir,c.playerNum,c.levelName):o.writeServerData(c.protocol,c.serverCount,c.attractLoop,c.gameDir,c.playerNum,c.levelName);for(let[g,p]of i.configStrings)o.writeConfigString(g,p);for(let g of i.entityBaselines.values())o.writeSpawnBaseline(g,c.protocol);let f=Array.from(i.currentEntities.values()),d={serverFrame:0,deltaFrame:-1,surpressCount:0,areaBytes:0,areaBits:new Uint8Array(0),playerState:i.playerState,packetEntities:{delta:!1,entities:f}};o.writeFrame(d,c.protocol),s.writeBlock(o.getData());let h=new Map;h.set(u,0);let m=new je(e.buffer);if(m.seekToMessage(u+1)){let g=u+1;for(;g<=l&&m.nextBlock();){let y=m.getBlock().data,_=new Ys,x={onServerData:()=>{},onConfigString:(S,w)=>_.writeConfigString(S,w),onSpawnBaseline:S=>_.writeSpawnBaseline(S,c.protocol),onCenterPrint:S=>_.writeCenterPrint(S),onStuffText:S=>_.writeStuffText(S),onPrint:(S,w)=>_.writePrint(S,w),onSound:(S,w,M,L,A,T,I)=>_.writeSound(S,w,M,L,A,T,I),onLayout:S=>_.writeLayout(S),onInventory:S=>_.writeInventory(S),onMuzzleFlash:(S,w)=>_.writeMuzzleFlash(S,w),onMuzzleFlash2:(S,w)=>_.writeMuzzleFlash2(S,w),onTempEntity:(S,w,M,L,A,T,I,z,C)=>_.writeTempEntity(S,w,M,L,A,T,I,z,C),onDisconnect:()=>_.writeDisconnect(),onReconnect:()=>_.writeReconnect(),onDownload:()=>{},onFrame:S=>{let w=S.serverFrame,M=S.deltaFrame,L=g-u,A=-1;h.has(M)?A=h.get(M):S.packetEntities.delta=!1,h.set(w,L),S.serverFrame=L,S.deltaFrame=A,_.writeFrame(S,c.protocol)}},b=new it(y,x,!1);b.setProtocolVersion(c.protocol),b.parseMessage();let v=_.getData();v.byteLength>0&&s.writeBlock(v),g++}}return s.writeEOF(),s.getData()}};var Xc=(d=>(d.Unknown="unknown",d.BSP="bsp",d.MD2="md2",d.MD3="md3",d.WAL="wal",d.PCX="pcx",d.TGA="tga",d.WAV="wav",d.OGG="ogg",d.TXT="txt",d.CFG="cfg",d.DEM="dem",d))(Xc||{}),wh={".bsp":"bsp",".md2":"md2",".md3":"md3",".wal":"wal",".pcx":"pcx",".tga":"tga",".wav":"wav",".ogg":"ogg",".txt":"txt",".cfg":"cfg",".dm2":"dem"};function qs(t,e){if(t.length<e.length)return!1;for(let r=0;r<e.length;r++)if(t[r]!==e[r])return!1;return!0}var Jb=[73,66,83,80],ex=[73,68,80,50],tx=[73,68,80,51];var rx=[82,73,70,70];var nx=[79,103,103,83];function Kc(t,e){let r=t.slice(t.lastIndexOf(".")).toLowerCase();if(e){if(qs(e,Jb))return"bsp";if(qs(e,ex))return"md2";if(qs(e,tx))return"md3";if(qs(e,nx))return"ogg";if(e.length>128&&e[0]===10&&e[1]<6)return"pcx";if(qs(e,rx)&&e.length>=12&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69)return"wav"}return wh[r]?wh[r]:"unknown"}function $c(t){let e=Kc(t);return e==="txt"||e==="cfg"}function Sh(t){return!$c(t)}function ix(t,e,r,n,i){let s=new Uint8ClampedArray(n*i*4),o=e/n,a=r/i;for(let u=0;u<i;u++)for(let l=0;l<n;l++){let c=l*o,f=u*a,d=Math.floor(c),h=Math.floor(f),m=c-d,g=f-h,p=Math.min(d+1,e-1),y=Math.min(h+1,r-1),_=(h*e+d)*4,x=(h*e+p)*4,b=(y*e+d)*4,v=(y*e+p)*4,S=(u*n+l)*4;for(let w=0;w<4;w++){let M=t[_+w],L=t[x+w],A=t[b+w],T=t[v+w],I=M*(1-m)+L*m,z=A*(1-m)+T*m,C=I*(1-g)+z*g;s[S+w]=C}}return s}function sx(t,e,r,n,i,s,o,a,u,l,c){n=Math.floor(n),i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);let f=Math.abs(s-n),d=Math.abs(o-i),h=n<s?1:-1,m=i<o?1:-1,g=f-d;for(;;){if(n>=0&&n<e&&i>=0&&i<r){let y=(i*e+n)*4,_=1-c/255;t[y]=a*(c/255)+t[y]*_,t[y+1]=u*(c/255)+t[y+1]*_,t[y+2]=l*(c/255)+t[y+2]*_,t[y+3]=255}if(n===s&&i===o)break;let p=2*g;p>-d&&(g-=d,n+=h),p<f&&(g+=f,i+=m)}}function Ah(t,e,r,n,i){let a=(t.x-n.x)*.707-(t.y-n.y)*.707,u=(t.x-n.x)*.707+(t.y-n.y)*.707,l=t.z-n.z,c=.866,f=.5,d=u*c-l*f,h=u*f+l*c,m=e/2+a*i,g=r/2-h*i;return{x:m,y:g}}var Wa=class{constructor(e){this.assetManager=e}async generateTextureThumbnail(e,r){try{let n=await this.assetManager.loadTexture(e);if(!n||n.levels.length===0)return null;let i=n.levels[0],s=i.width/i.height,o=r,a=r;s>1?a=Math.floor(r/s):o=Math.floor(r*s),o=Math.max(1,o),a=Math.max(1,a);let u=ix(i.rgba,i.width,i.height,o,a);return new ImageData(u,o,a)}catch(n){return console.error(`Failed to generate thumbnail for ${e}`,n),null}}async generateModelThumbnail(e,r){try{let n=[],i=[],s=e.split(".").pop()?.toLowerCase();if(s==="md2"){let p=await this.assetManager.loadMd2Model(e);if(!p||p.frames.length===0)return null;n=p.frames[0].vertices.map(_=>_.position);for(let _ of p.triangles)i.push(_.vertexIndices[0],_.vertexIndices[1]),i.push(_.vertexIndices[1],_.vertexIndices[2]),i.push(_.vertexIndices[2],_.vertexIndices[0])}else if(s==="md3"){let p=await this.assetManager.loadMd3Model(e);if(!p||p.surfaces.length===0)return null;let y=0;for(let _ of p.surfaces){if(_.vertices.length===0)continue;let x=_.vertices[0];n.push(...x.map(b=>({x:b.position.x,y:b.position.y,z:b.position.z})));for(let b of _.triangles)i.push(y+b.indices[0],y+b.indices[1]),i.push(y+b.indices[1],y+b.indices[2]),i.push(y+b.indices[2],y+b.indices[0]);y+=x.length}}else return null;if(n.length===0)return null;let o={x:1/0,y:1/0,z:1/0},a={x:-1/0,y:-1/0,z:-1/0};for(let p of n)o.x=Math.min(o.x,p.x),o.y=Math.min(o.y,p.y),o.z=Math.min(o.z,p.z),a.x=Math.max(a.x,p.x),a.y=Math.max(a.y,p.y),a.z=Math.max(a.z,p.z);let u={x:(o.x+a.x)/2,y:(o.y+a.y)/2,z:(o.z+a.z)/2},l=a.x-o.x,c=a.y-o.y,f=a.z-o.z,d=Math.max(l,c,f),h=Math.max(d,.001),m=r*.8/h,g=new Uint8ClampedArray(r*r*4);for(let p=0;p<i.length;p+=2){let y=i[p],_=i[p+1],x=n[y],b=n[_],v=Ah(x,r,r,u,m),S=Ah(b,r,r,u,m);sx(g,r,r,v.x,v.y,S.x,S.y,0,255,0,255)}return new ImageData(g,r,r)}catch(n){return console.error(`Failed to generate model thumbnail for ${e}`,n),null}}async getMapBounds(e,r){try{let n=Ai(r);if(n.models.length>0){let i=n.models[0];return{mins:{x:i.mins[0],y:i.mins[1],z:i.mins[2]},maxs:{x:i.maxs[0],y:i.maxs[1],z:i.maxs[2]}}}return null}catch(n){return console.error("Failed to get map bounds",n),null}}async extractMapScreenshot(e){return null}};var Xa=class{constructor(e){this.loader=e}async getMapStatistics(e){let r=await this.loader.load(e),n=r.faces.filter(o=>o.lightOffset!==-1).length,i=r.models[0],s=i?{mins:i.mins,maxs:i.maxs}:{mins:[0,0,0],maxs:[0,0,0]};return{entityCount:r.entities.entities.length,surfaceCount:r.faces.length,lightmapCount:n,vertexCount:r.vertices.length,bounds:s}}async getUsedTextures(e){let r=await this.loader.load(e),n=new Set;for(let i of r.texInfo)i.texture&&n.add(i.texture);return Array.from(n).sort()}async getUsedModels(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities)i.properties.model&&!i.properties.model.startsWith("*")&&n.add(i.properties.model);return Array.from(n).sort()}async getUsedSounds(e){let r=await this.loader.load(e),n=new Set;for(let i of r.entities.entities){i.properties.noise&&n.add(i.properties.noise);for(let[s,o]of Object.entries(i.properties))(s==="noise"||s.endsWith("_sound")||s==="sound")&&typeof o=="string"&&n.add(o)}return Array.from(n).sort()}};function Mh(t){let e=[],r=0,n=t.length;function i(){for(;r<n&&/\s/.test(t[r]);)r++}function s(){if(i(),r>=n)return null;if(t[r]==='"'){r++;let o=r;for(;r<n&&t[r]!=='"';)t[r],r++;let a=t.substring(o,r);return r++,a}else{if(t[r]==="{"||t[r]==="}")return t[r++];{if(t.startsWith("//",r)){for(;r<n&&t[r]!==`
583
583
  `;)r++;return s()}let o=r;for(;r<n&&!/\s/.test(t[r])&&t[r]!=="}"&&t[r]!=="{";)r++;return t.substring(o,r)}}}for(;r<n;){let o=s();if(o===null)break;if(o==="{"){let a={};for(;;){let u=r,l=s();if(l==="}"||l===null)break;if(l==="{"){r=u;break}let c=s();if(c===null||c==="}"||c==="{"){c==="}"&&r--,c==="{"&&r--;break}a[l]=c}e.push({classname:a.classname,properties:a})}}return e}function Eh(t){let e="";for(let r of t){e+=`{
584
584
  `;let i=Object.keys(r.properties).sort((s,o)=>s==="classname"?-1:o==="classname"?1:s==="origin"?-1:o==="origin"?1:s.localeCompare(o));for(let s of i){let o=r.properties[s];e+=`"${s}" "${o}"
585
585
  `}e+=`}