hytopia 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/server.chunklattice.clear.md +17 -0
- package/docs/server.chunklattice.md +14 -0
- package/docs/server.world.loadmap.md +1 -1
- package/docs/server.world.md +1 -1
- package/docs/server.worldmap.entities.md +5 -1
- package/docs/server.worldmap.md +1 -1
- package/package.json +1 -1
- package/server.api.json +70 -3
- package/server.d.ts +10 -2
- package/server.js +2 -2
package/server.js
CHANGED
@@ -376,12 +376,12 @@ For example, you can use the \`pathToFileURL()\` method of the \`url\` core modu
|
|
376
376
|
`,LF:`
|
377
377
|
`,concatBytes:UK},Dp=(J,X)=>{let Y=new Uint8Array(J.length+X.length);return Y.set(J,0),Y.set(X,J.length),Y},_p={windowsNewline:new Uint8Array([13,10]),unixNewline:new Uint8Array([10]),LF:10,concatBytes:Dp};import{Buffer as Ep}from"buffer";var sV=(J,X)=>J?void 0:Cp.bind(void 0,X),Cp=function*(J,X){if(typeof X!=="string"&&!J8(X)&&!Ep.isBuffer(X))throw new TypeError(`The \`${J}\` option's transform must use "objectMode: true" to receive as input: ${typeof X}.`);yield X},oV=(J,X)=>J?Sp.bind(void 0,X):Ip.bind(void 0,X),Sp=function*(J,X){rV(J,X),yield X},Ip=function*(J,X){if(rV(J,X),typeof X!=="string"&&!J8(X))throw new TypeError(`The \`${J}\` option's function must yield a string or an Uint8Array, not ${typeof X}.`);yield X},rV=(J,X)=>{if(X===null||X===void 0)throw new TypeError(`The \`${J}\` option's function must not call \`yield ${X}\`.
|
378
378
|
Instead, \`yield\` should either be called with a value, or not be called at all. For example:
|
379
|
-
if (condition) { yield value; }`)};import{Buffer as hp}from"buffer";import{StringDecoder as fp}from"string_decoder";var wY=(J,X,Y)=>{if(Y)return;if(J)return{transform:bp.bind(void 0,new TextEncoder)};let Z=new fp(X);return{transform:pp.bind(void 0,Z),final:Ap.bind(void 0,Z)}},bp=function*(J,X){if(hp.isBuffer(X))yield e6(X);else if(typeof X==="string")yield J.encode(X);else yield X},pp=function*(J,X){yield J8(X)?J.write(X):X},Ap=function*(J){let X=J.end();if(X!=="")yield X};import{callbackify as tV}from"util";var MK=tV(async(J,X,Y,Z)=>{X.currentIterable=J(...Y);try{for await(let W of X.currentIterable)Z.push(W)}finally{delete X.currentIterable}}),OY=async function*(J,X,Y){if(Y===X.length){yield J;return}let{transform:Z=gp}=X[Y];for await(let W of Z(J))yield*OY(W,X,Y+1)},eV=async function*(J){for(let[X,{final:Y}]of Object.entries(J))yield*yp(Y,Number(X),J)},yp=async function*(J,X,Y){if(J===void 0)return;for await(let Z of J())yield*OY(Z,Y,X+1)},JM=tV(async({currentIterable:J},X)=>{if(J!==void 0){await(X?J.throw(X):J.return());return}if(X)throw X}),gp=function*(J){yield J};var RK=(J,X,Y,Z)=>{try{for(let W of J(...X))Y.push(W);Z()}catch(W){Z(W)}},XM=(J,X)=>[...X.flatMap((Y)=>[...W9(Y,J,0)]),...h4(J)],W9=function*(J,X,Y){if(Y===X.length){yield J;return}let{transform:Z=mp}=X[Y];for(let W of Z(J))yield*W9(W,X,Y+1)},h4=function*(J){for(let[X,{final:Y}]of Object.entries(J))yield*cp(Y,Number(X),J)},cp=function*(J,X,Y){if(J===void 0)return;for(let Z of J())yield*W9(Z,Y,X+1)},mp=function*(J){yield J};var wK=({value:J,value:{transform:X,final:Y,writableObjectMode:Z,readableObjectMode:W},optionName:$},{encoding:Q})=>{let K={},G=ZM(J,Q,$),F=Z9(X),q=Z9(Y),H=F?MK.bind(void 0,OY,K):RK.bind(void 0,W9),z=F||q?MK.bind(void 0,eV,K):RK.bind(void 0,h4),V=F||q?JM.bind(void 0,K):void 0;return{stream:new lp({writableObjectMode:Z,writableHighWaterMark:YM(Z),readableObjectMode:W,readableHighWaterMark:YM(W),transform(R,L,w){H([R,G,0],this,w)},flush(R){z([G],this,R)},destroy:V})}},xY=(J,X,Y,Z)=>{let W=X.filter(({type:Q})=>Q==="generator"),$=Z?W.reverse():W;for(let{value:Q,optionName:K}of $){let G=ZM(Q,Y,K);J=XM(G,J)}return J},ZM=({transform:J,final:X,binary:Y,writableObjectMode:Z,readableObjectMode:W,preserveNewlines:$},Q,K)=>{let G={};return[{transform:sV(Z,K)},wY(Y,Q,Z),RY(Y,$,Z,G),{transform:J,final:X},{transform:oV(W,K)},aV({binary:Y,preserveNewlines:$,readableObjectMode:W,state:G})].filter(Boolean)};var WM=(J,X)=>{for(let Y of up(J))dp(J,Y,X)},up=(J)=>new Set(Object.entries(J).filter(([,{direction:X}])=>X==="input").map(([X])=>Number(X))),dp=(J,X,Y)=>{let{stdioItems:Z}=J[X],W=Z.filter(({contents:K})=>K!==void 0);if(W.length===0)return;if(X!==0){let[{type:K,optionName:G}]=W;throw new TypeError(`Only the \`stdin\` option, not \`${G}\`, can be ${B1[K]} with synchronous methods.`)}let Q=W.map(({contents:K})=>K).map((K)=>ip(K,Z));Y.input=k4(Q)},ip=(J,X)=>{let Y=xY(J,X,"utf8",!0);return np(Y),k4(Y)},np=(J)=>{let X=J.find((Y)=>typeof Y!=="string"&&!J8(Y));if(X!==void 0)throw new TypeError(`The \`stdin\` option is invalid: when passing objects as input, a transform must be used to serialize them to strings or Uint8Arrays: ${X}.`)};import{writeFileSync as rp,appendFileSync as tp}from"fs";var PY=({stdioItems:J,encoding:X,verboseInfo:Y,fdNumber:Z})=>Z!=="all"&&d9(Y,Z)&&!l8.has(X)&&ap(Z)&&(J.some(({type:W,value:$})=>W==="native"&&sp.has($))||J.every(({type:W})=>s8.has(W))),ap=(J)=>J===1||J===2,sp=new Set(["pipe","overlapped"]),$M=async(J,X,Y,Z)=>{for await(let W of J)if(!op(X))KM(W,Y,Z)},QM=(J,X,Y)=>{for(let Z of J)KM(Z,X,Y)},op=(J)=>J._readableState.pipes.length>0,KM=(J,X,Y)=>{let Z=SX(J);D6({type:"output",verboseMessage:Z,fdNumber:X,verboseInfo:Y})};var GM=({fileDescriptors:J,syncResult:{output:X},options:Y,isMaxBuffer:Z,verboseInfo:W})=>{if(X===null)return{output:Array.from({length:3})};let $={},Q=new Set([]);return{output:X.map((G,F)=>ep({result:G,fileDescriptors:J,fdNumber:F,state:$,outputFiles:Q,isMaxBuffer:Z,verboseInfo:W},Y)),...$}},ep=({result:J,fileDescriptors:X,fdNumber:Y,state:Z,outputFiles:W,isMaxBuffer:$,verboseInfo:Q},{buffer:K,encoding:G,lines:F,stripFinalNewline:q,maxBuffer:H})=>{if(J===null)return;let z=FV(J,$,H),V=e6(z),{stdioItems:M,objectMode:R}=X[Y],L=JA([V],M,G,Z),{serializedResult:w,finalResult:P=w}=XA({chunks:L,objectMode:R,encoding:G,lines:F,stripFinalNewline:q,fdNumber:Y});YA({serializedResult:w,fdNumber:Y,state:Z,verboseInfo:Q,encoding:G,stdioItems:M,objectMode:R});let N=K[Y]?P:void 0;try{if(Z.error===void 0)ZA(w,M,W);return N}catch(v){return Z.error=v,N}},JA=(J,X,Y,Z)=>{try{return xY(J,X,Y,!1)}catch(W){return Z.error=W,J}},XA=({chunks:J,objectMode:X,encoding:Y,lines:Z,stripFinalNewline:W,fdNumber:$})=>{if(X)return{serializedResult:J};if(Y==="buffer")return{serializedResult:k4(J)};let Q=vz(J,Y);if(Z[$])return{serializedResult:Q,finalResult:VK(Q,!W[$],X)};return{serializedResult:Q}},YA=({serializedResult:J,fdNumber:X,state:Y,verboseInfo:Z,encoding:W,stdioItems:$,objectMode:Q})=>{if(!PY({stdioItems:$,encoding:W,verboseInfo:Z,fdNumber:X}))return;let K=VK(J,!1,Q);try{QM(K,X,Z)}catch(G){Y.error??=G}},ZA=(J,X,Y)=>{for(let{path:Z,append:W}of X.filter(({type:$})=>VY.has($))){let $=typeof Z==="string"?Z:Z.toString();if(W||Y.has($))tp(Z,J);else Y.add($),rp(Z,J)}};var FM=([,J,X],Y)=>{if(!Y.all)return;if(J===void 0)return X;if(X===void 0)return J;if(Array.isArray(J))return Array.isArray(X)?[...J,...X]:[...J,Z1(X,Y,"all")];if(Array.isArray(X))return[Z1(J,Y,"all"),...X];if(J8(J)&&J8(X))return BQ([J,X]);return`${J}${X}`};import{once as OK}from"events";var qM=async(J,X)=>{let[Y,Z]=await WA(J);return X.isForcefullyTerminated??=!1,[Y,Z]},WA=async(J)=>{let[X,Y]=await Promise.allSettled([OK(J,"spawn"),OK(J,"exit")]);if(X.status==="rejected")return[];return Y.status==="rejected"?HM(J):Y.value},HM=async(J)=>{try{return await OK(J,"exit")}catch{return HM(J)}},zM=async(J)=>{let[X,Y]=await J;if(!$A(X,Y)&&xK(X,Y))throw new _6;return[X,Y]},$A=(J,X)=>J===void 0&&X===void 0,xK=(J,X)=>J!==0||X!==null;var LM=({error:J,status:X,signal:Y,output:Z},{maxBuffer:W})=>{let $=QA(J,X,Y),Q=$?.code==="ETIMEDOUT",K=GV($,Z,W);return{resultError:$,exitCode:X,signal:Y,timedOut:Q,isMaxBuffer:K}},QA=(J,X,Y)=>{if(J!==void 0)return J;return xK(X,Y)?new _6:void 0};var UM=(J,X,Y)=>{let{file:Z,commandArguments:W,command:$,escapedCommand:Q,startTime:K,verboseInfo:G,options:F,fileDescriptors:q}=GA(J,X,Y),H=HA({file:Z,commandArguments:W,options:F,command:$,escapedCommand:Q,verboseInfo:G,fileDescriptors:q,startTime:K});return J5(H,G,F)},GA=(J,X,Y)=>{let{command:Z,escapedCommand:W,startTime:$,verboseInfo:Q}=hX(J,X,Y),K=FA(Y),{file:G,commandArguments:F,options:q}=ZY(J,X,K);qA(q);let H=uV(q,Q);return{file:G,commandArguments:F,command:Z,escapedCommand:W,startTime:$,verboseInfo:Q,options:q,fileDescriptors:H}},FA=(J)=>J.node&&!J.ipc?{...J,ipc:!1}:J,qA=({ipc:J,ipcInput:X,detached:Y,cancelSignal:Z})=>{if(X)NY("ipcInput");if(J)NY("ipc: true");if(Y)NY("detached: true");if(Z)NY("cancelSignal")},NY=(J)=>{throw new TypeError(`The "${J}" option cannot be used with synchronous methods.`)},HA=({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,verboseInfo:$,fileDescriptors:Q,startTime:K})=>{let G=zA({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,fileDescriptors:Q,startTime:K});if(G.failed)return G;let{resultError:F,exitCode:q,signal:H,timedOut:z,isMaxBuffer:V}=LM(G,Y),{output:M,error:R=F}=GM({fileDescriptors:Q,syncResult:G,options:Y,isMaxBuffer:V,verboseInfo:$}),L=M.map((P,N)=>Z1(P,Y,N)),w=Z1(FM(M,Y),Y,"all");return UA({error:R,exitCode:q,signal:H,timedOut:z,isMaxBuffer:V,stdio:L,all:w,options:Y,command:Z,escapedCommand:W,startTime:K})},zA=({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,fileDescriptors:$,startTime:Q})=>{try{WM($,Y);let K=LA(Y);return KA(J,X,K)}catch(K){return e9({error:K,command:Z,escapedCommand:W,fileDescriptors:$,options:Y,startTime:Q,isSync:!0})}},LA=({encoding:J,maxBuffer:X,...Y})=>({...Y,encoding:"buffer",maxBuffer:HY(X)}),UA=({error:J,exitCode:X,signal:Y,timedOut:Z,isMaxBuffer:W,stdio:$,all:Q,options:K,command:G,escapedCommand:F,startTime:q})=>J===void 0?zY({command:G,escapedCommand:F,stdio:$,all:Q,ipcOutput:[],options:K,startTime:q}):I4({error:J,command:G,escapedCommand:F,timedOut:Z,isCanceled:!1,isGracefullyCanceled:!1,isMaxBuffer:W,isForcefullyTerminated:!1,exitCode:X,signal:Y,stdio:$,all:Q,ipcOutput:[],options:K,startTime:q,isSync:!0});import{setMaxListeners as Xg}from"events";import{spawn as Yg}from"child_process";import OM from"process";import{once as PK,on as VA}from"events";var VM=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z},{reference:W=!0,filter:$}={})=>{return a9({methodName:"getOneMessage",isSubprocess:Y,ipc:Z,isConnected:rX(J)}),MA({anyProcess:J,channel:X,isSubprocess:Y,filter:$,reference:W})},MA=async({anyProcess:J,channel:X,isSubprocess:Y,filter:Z,reference:W})=>{nX(X,W);let $=v1(J,X,Y),Q=new AbortController;try{return await Promise.race([RA($,Z,Q),wA($,Y,Q),OA($,Y,Q)])}catch(K){throw s9(J),K}finally{Q.abort(),aX(X,W)}},RA=async(J,X,{signal:Y})=>{if(X===void 0){let[Z]=await PK(J,"message",{signal:Y});return Z}for await(let[Z]of VA(J,"message",{signal:Y}))if(X(Z))return Z},wA=async(J,X,{signal:Y})=>{await PK(J,"disconnect",{signal:Y}),JU(X)},OA=async(J,X,{signal:Y})=>{let[Z]=await PK(J,"strict:error",{signal:Y});throw uX(Z,X)};import{once as RM,on as xA}from"events";var wM=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z},{reference:W=!0}={})=>NK({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z,shouldAwait:!Y,reference:W}),NK=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z,shouldAwait:W,reference:$})=>{a9({methodName:"getEachMessage",isSubprocess:Y,ipc:Z,isConnected:rX(J)}),nX(X,$);let Q=v1(J,X,Y),K=new AbortController,G={};return PA(J,Q,K),NA({ipcEmitter:Q,isSubprocess:Y,controller:K,state:G}),vA({anyProcess:J,channel:X,ipcEmitter:Q,isSubprocess:Y,shouldAwait:W,controller:K,state:G,reference:$})},PA=async(J,X,Y)=>{try{await RM(X,"disconnect",{signal:Y.signal}),Y.abort()}catch{}},NA=async({ipcEmitter:J,isSubprocess:X,controller:Y,state:Z})=>{try{let[W]=await RM(J,"strict:error",{signal:Y.signal});Z.error=uX(W,X),Y.abort()}catch{}},vA=async function*({anyProcess:J,channel:X,ipcEmitter:Y,isSubprocess:Z,shouldAwait:W,controller:$,state:Q,reference:K}){try{for await(let[G]of xA(Y,"message",{signal:$.signal}))MM(Q),yield G}catch{MM(Q)}finally{if($.abort(),aX(X,K),!Z)s9(J);if(W)await J}},MM=({error:J})=>{if(J)throw J};var xM=(J,{ipc:X})=>{Object.assign(J,NM(J,!1,X))},PM=()=>{let J=OM,X=!0,Y=OM.channel!==void 0;return{...NM(J,!0,Y),getCancelSignal:TU.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:!0,ipc:Y})}},NM=(J,X,Y)=>({sendMessage:XY.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y}),getOneMessage:VM.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y}),getEachMessage:wM.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y})});import{ChildProcess as BA}from"child_process";import{PassThrough as jA,Readable as kA,Writable as TA,Duplex as DA}from"stream";var vM=({error:J,command:X,escapedCommand:Y,fileDescriptors:Z,options:W,startTime:$,verboseInfo:Q})=>{zK(Z);let K=new BA;_A(K,Z),Object.assign(K,{readable:EA,writable:CA,duplex:SA});let G=e9({error:J,command:X,escapedCommand:Y,fileDescriptors:Z,options:W,startTime:$,isSync:!1}),F=IA(G,Q,W);return{subprocess:K,promise:F}},_A=(J,X)=>{let Y=f4(),Z=f4(),W=f4(),$=Array.from({length:X.length-3},f4),Q=f4(),K=[Y,Z,W,...$];Object.assign(J,{stdin:Y,stdout:Z,stderr:W,all:Q,stdio:K})},f4=()=>{let J=new jA;return J.end(),J},EA=()=>new kA({read(){}}),CA=()=>new TA({write(){}}),SA=()=>new DA({read(){},write(){}}),IA=async(J,X,Y)=>J5(J,X,Y);import{createReadStream as BM,createWriteStream as jM}from"fs";import{Buffer as hA}from"buffer";import{Readable as b4,Writable as fA,Duplex as bA}from"stream";var TM=(J,X)=>MY(pA,J,X,!1),p4=({type:J,optionName:X})=>{throw new TypeError(`The \`${X}\` option cannot be ${B1[J]}.`)},kM={fileNumber:p4,generator:wK,asyncGenerator:wK,nodeStream:({value:J})=>({stream:J}),webTransform({value:{transform:J,writableObjectMode:X,readableObjectMode:Y}}){let Z=X||Y;return{stream:bA.fromWeb(J,{objectMode:Z})}},duplex:({value:{transform:J}})=>({stream:J}),native(){}},pA={input:{...kM,fileUrl:({value:J})=>({stream:BM(J)}),filePath:({value:{file:J}})=>({stream:BM(J)}),webStream:({value:J})=>({stream:b4.fromWeb(J)}),iterable:({value:J})=>({stream:b4.from(J)}),asyncIterable:({value:J})=>({stream:b4.from(J)}),string:({value:J})=>({stream:b4.from(J)}),uint8Array:({value:J})=>({stream:b4.from(hA.from(J))})},output:{...kM,fileUrl:({value:J})=>({stream:jM(J)}),filePath:({value:{file:J,append:X}})=>({stream:jM(J,X?{flags:"a"}:{})}),webStream:({value:J})=>({stream:fA.fromWeb(J)}),iterable:p4,asyncIterable:p4,string:p4,uint8Array:p4}};import{on as AA,once as DM}from"events";import{PassThrough as yA,getDefaultHighWaterMark as gA}from"stream";import{finished as CM}from"stream/promises";function $9(J){if(!Array.isArray(J))throw new TypeError(`Expected an array, got \`${typeof J}\`.`);for(let W of J)vK(W);let X=J.some(({readableObjectMode:W})=>W),Y=cA(J,X),Z=new SM({objectMode:X,writableHighWaterMark:Y,readableHighWaterMark:Y});for(let W of J)Z.add(W);return Z}var cA=(J,X)=>{if(J.length===0)return gA(X);let Y=J.filter(({readableObjectMode:Z})=>Z===X).map(({readableHighWaterMark:Z})=>Z);return Math.max(...Y)};class SM extends yA{#X=new Set([]);#Y=new Set([]);#J=new Set([]);#Z;#$=Symbol("unpipe");#W=new WeakMap;add(J){if(vK(J),this.#X.has(J))return;this.#X.add(J),this.#Z??=mA(this,this.#X,this.#$);let X=dA({passThroughStream:this,stream:J,streams:this.#X,ended:this.#Y,aborted:this.#J,onFinished:this.#Z,unpipeEvent:this.#$});this.#W.set(J,X),J.pipe(this,{end:!1})}async remove(J){if(vK(J),!this.#X.has(J))return!1;let X=this.#W.get(J);if(X===void 0)return!1;return this.#W.delete(J),J.unpipe(this),await X,!0}}var mA=async(J,X,Y)=>{vY(J,_M);let Z=new AbortController;try{await Promise.race([lA(J,Z),uA(J,X,Y,Z)])}finally{Z.abort(),vY(J,-_M)}},lA=async(J,{signal:X})=>{try{await CM(J,{signal:X,cleanup:!0})}catch(Y){throw IM(J,Y),Y}},uA=async(J,X,Y,{signal:Z})=>{for await(let[W]of AA(J,"unpipe",{signal:Z}))if(X.has(W))W.emit(Y)},vK=(J)=>{if(typeof J?.pipe!=="function")throw new TypeError(`Expected a readable stream, got: \`${typeof J}\`.`)},dA=async({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,onFinished:$,unpipeEvent:Q})=>{vY(J,EM);let K=new AbortController;try{await Promise.race([iA($,X,K),nA({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,controller:K}),aA({stream:X,streams:Y,ended:Z,aborted:W,unpipeEvent:Q,controller:K})])}finally{K.abort(),vY(J,-EM)}if(Y.size>0&&Y.size===Z.size+W.size)if(Z.size===0&&W.size>0)BK(J);else sA(J)},iA=async(J,X,{signal:Y})=>{try{if(await J,!Y.aborted)BK(X)}catch(Z){if(!Y.aborted)IM(X,Z)}},nA=async({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,controller:{signal:$}})=>{try{if(await CM(X,{signal:$,cleanup:!0,readable:!0,writable:!1}),Y.has(X))Z.add(X)}catch(Q){if($.aborted||!Y.has(X))return;if(hM(Q))W.add(X);else fM(J,Q)}},aA=async({stream:J,streams:X,ended:Y,aborted:Z,unpipeEvent:W,controller:{signal:$}})=>{if(await DM(J,W,{signal:$}),!J.readable)return DM($,"abort",{signal:$});X.delete(J),Y.delete(J),Z.delete(J)},sA=(J)=>{if(J.writable)J.end()},IM=(J,X)=>{if(hM(X))BK(J);else fM(J,X)},hM=(J)=>J?.code==="ERR_STREAM_PREMATURE_CLOSE",BK=(J)=>{if(J.readable||J.writable)J.destroy()},fM=(J,X)=>{if(!J.destroyed)J.once("error",oA),J.destroy(X)},oA=()=>{},vY=(J,X)=>{let Y=J.getMaxListeners();if(Y!==0&&Y!==Number.POSITIVE_INFINITY)J.setMaxListeners(Y+X)},_M=2,EM=1;import{finished as bM}from"stream/promises";var Y5=(J,X)=>{J.pipe(X),rA(J,X),tA(J,X)},rA=async(J,X)=>{if(H6(J)||H6(X))return;try{await bM(J,{cleanup:!0,readable:!0,writable:!1})}catch{}jK(X)},jK=(J)=>{if(J.writable)J.end()},tA=async(J,X)=>{if(H6(J)||H6(X))return;try{await bM(X,{cleanup:!0,readable:!1,writable:!0})}catch{}kK(J)},kK=(J)=>{if(J.readable)J.destroy()};var pM=(J,X,Y)=>{let Z=new Map;for(let[W,{stdioItems:$,direction:Q}]of Object.entries(X)){for(let{stream:K}of $.filter(({type:G})=>s8.has(G)))eA(J,K,Q,W);for(let{stream:K}of $.filter(({type:G})=>!s8.has(G)))Xy({subprocess:J,stream:K,direction:Q,fdNumber:W,pipeGroups:Z,controller:Y})}for(let[W,$]of Z.entries()){let Q=$.length===1?$[0]:$9($);Y5(Q,W)}},eA=(J,X,Y,Z)=>{if(Y==="output")Y5(J.stdio[Z],X);else Y5(X,J.stdio[Z]);let W=Jy[Z];if(W!==void 0)J[W]=X;J.stdio[Z]=X},Jy=["stdin","stdout","stderr"],Xy=({subprocess:J,stream:X,direction:Y,fdNumber:Z,pipeGroups:W,controller:$})=>{if(X===void 0)return;Yy(X,$);let[Q,K]=Y==="output"?[X,J.stdio[Z]]:[J.stdio[Z],X],G=W.get(Q)??[];W.set(Q,[...G,K])},Yy=(J,{signal:X})=>{if(H6(J))X9(J,Zy,X)},Zy=2;import{addAbortListener as Qy}from"events";var Q9=[];Q9.push("SIGHUP","SIGINT","SIGTERM");if(process.platform!=="win32")Q9.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(process.platform==="linux")Q9.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var BY=(J)=>!!J&&typeof J==="object"&&typeof J.removeListener==="function"&&typeof J.emit==="function"&&typeof J.reallyExit==="function"&&typeof J.listeners==="function"&&typeof J.kill==="function"&&typeof J.pid==="number"&&typeof J.on==="function",TK=Symbol.for("signal-exit emitter"),DK=globalThis,Wy=Object.defineProperty.bind(Object);class AM{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(DK[TK])return DK[TK];Wy(DK,TK,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(J,X){this.listeners[J].push(X)}removeListener(J,X){let Y=this.listeners[J],Z=Y.indexOf(X);if(Z===-1)return;if(Z===0&&Y.length===1)Y.length=0;else Y.splice(Z,1)}emit(J,X,Y){if(this.emitted[J])return!1;this.emitted[J]=!0;let Z=!1;for(let W of this.listeners[J])Z=W(X,Y)===!0||Z;if(J==="exit")Z=this.emit("afterExit",X,Y)||Z;return Z}}class EK{}var $y=(J)=>{return{onExit(X,Y){return J.onExit(X,Y)},load(){return J.load()},unload(){return J.unload()}}};class yM extends EK{onExit(){return()=>{}}load(){}unload(){}}class gM extends EK{#X=_K.platform==="win32"?"SIGINT":"SIGHUP";#Y=new AM;#J;#Z;#$;#W={};#Q=!1;constructor(J){super();this.#J=J,this.#W={};for(let X of Q9)this.#W[X]=()=>{let Y=this.#J.listeners(X),{count:Z}=this.#Y,W=J;if(typeof W.__signal_exit_emitter__==="object"&&typeof W.__signal_exit_emitter__.count==="number")Z+=W.__signal_exit_emitter__.count;if(Y.length===Z){this.unload();let $=this.#Y.emit("exit",null,X),Q=X==="SIGHUP"?this.#X:X;if(!$)J.kill(J.pid,Q)}};this.#$=J.reallyExit,this.#Z=J.emit}onExit(J,X){if(!BY(this.#J))return()=>{};if(this.#Q===!1)this.load();let Y=X?.alwaysLast?"afterExit":"exit";return this.#Y.on(Y,J),()=>{if(this.#Y.removeListener(Y,J),this.#Y.listeners.exit.length===0&&this.#Y.listeners.afterExit.length===0)this.unload()}}load(){if(this.#Q)return;this.#Q=!0,this.#Y.count+=1;for(let J of Q9)try{let X=this.#W[J];if(X)this.#J.on(J,X)}catch(X){}this.#J.emit=(J,...X)=>{return this.#G(J,...X)},this.#J.reallyExit=(J)=>{return this.#K(J)}}unload(){if(!this.#Q)return;this.#Q=!1,Q9.forEach((J)=>{let X=this.#W[J];if(!X)throw new Error("Listener not defined for signal: "+J);try{this.#J.removeListener(J,X)}catch(Y){}}),this.#J.emit=this.#Z,this.#J.reallyExit=this.#$,this.#Y.count-=1}#K(J){if(!BY(this.#J))return 0;return this.#J.exitCode=J||0,this.#Y.emit("exit",this.#J.exitCode,null),this.#$.call(this.#J,this.#J.exitCode)}#G(J,...X){let Y=this.#Z;if(J==="exit"&&BY(this.#J)){if(typeof X[0]==="number")this.#J.exitCode=X[0];let Z=Y.call(this.#J,J,...X);return this.#Y.emit("exit",this.#J.exitCode,null),Z}else return Y.call(this.#J,J,...X)}}var _K=globalThis.process,{onExit:cM,load:oz0,unload:rz0}=$y(BY(_K)?new gM(_K):new yM);var mM=(J,{cleanup:X,detached:Y},{signal:Z})=>{if(!X||Y)return;let W=cM(()=>{J.kill()});Qy(Z,()=>{W()})};var uM=({source:J,sourcePromise:X,boundOptions:Y,createNested:Z},...W)=>{let $=IX(),{destination:Q,destinationStream:K,destinationError:G,from:F,unpipeSignal:q}=Ky(Y,Z,W),{sourceStream:H,sourceError:z}=Fy(J,F),{options:V,fileDescriptors:M}=C6.get(J);return{sourcePromise:X,sourceStream:H,sourceOptions:V,sourceError:z,destination:Q,destinationStream:K,destinationError:G,unpipeSignal:q,fileDescriptors:M,startTime:$}},Ky=(J,X,Y)=>{try{let{destination:Z,pipeOptions:{from:W,to:$,unpipeSignal:Q}={}}=Gy(J,X,...Y),K=iX(Z,$);return{destination:Z,destinationStream:K,from:W,unpipeSignal:Q}}catch(Z){return{destinationError:Z}}},Gy=(J,X,Y,...Z)=>{if(Array.isArray(Y))return{destination:X(lM,J)(Y,...Z),pipeOptions:J};if(typeof Y==="string"||Y instanceof URL||NQ(Y)){if(Object.keys(J).length>0)throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');let[W,$,Q]=vX(Y,...Z);return{destination:X(lM)(W,$,Q),pipeOptions:Q}}if(C6.has(Y)){if(Object.keys(J).length>0)throw new TypeError("Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).");return{destination:Y,pipeOptions:Z[0]}}throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${Y}`)},lM=({options:J})=>({options:{...J,stdin:"pipe",piped:!0}}),Fy=(J,X)=>{try{return{sourceStream:o9(J,X)}}catch(Y){return{sourceError:Y}}};var iM=({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z,fileDescriptors:W,sourceOptions:$,startTime:Q})=>{let K=qy({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z});if(K!==void 0)throw CK({error:K,fileDescriptors:W,sourceOptions:$,startTime:Q})},qy=({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z})=>{if(X!==void 0&&Z!==void 0)return Z;if(Z!==void 0)return kK(J),Z;if(X!==void 0)return jK(Y),X},CK=({error:J,fileDescriptors:X,sourceOptions:Y,startTime:Z})=>e9({error:J,command:dM,escapedCommand:dM,fileDescriptors:X,options:Y,startTime:Z,isSync:!1}),dM="source.pipe(destination)";var nM=async(J)=>{let[{status:X,reason:Y,value:Z=Y},{status:W,reason:$,value:Q=$}]=await J;if(!Q.pipedFrom.includes(Z))Q.pipedFrom.push(Z);if(W==="rejected")throw Q;if(X==="rejected")throw Z;return Q};import{finished as Hy}from"stream/promises";var aM=(J,X,Y)=>{let Z=jY.has(X)?Ly(J,X):zy(J,X);return X9(J,Vy,Y.signal),X9(X,My,Y.signal),Uy(X),Z},zy=(J,X)=>{let Y=$9([J]);return Y5(Y,X),jY.set(X,Y),Y},Ly=(J,X)=>{let Y=jY.get(X);return Y.add(J),Y},Uy=async(J)=>{try{await Hy(J,{cleanup:!0,readable:!1,writable:!0})}catch{}jY.delete(J)},jY=new WeakMap,Vy=2,My=1;import{aborted as Ry}from"util";var sM=(J,X)=>J===void 0?[]:[wy(J,X)],wy=async(J,{sourceStream:X,mergedStream:Y,fileDescriptors:Z,sourceOptions:W,startTime:$})=>{await Ry(J,X),await Y.remove(X);let Q=new Error("Pipe canceled by `unpipeSignal` option.");throw CK({error:Q,fileDescriptors:Z,sourceOptions:W,startTime:$})};var kY=(J,...X)=>{if(d0(X[0]))return kY.bind(void 0,{...J,boundOptions:{...J.boundOptions,...X[0]}});let{destination:Y,...Z}=uM(J,...X),W=Oy({...Z,destination:Y});return W.pipe=kY.bind(void 0,{...J,source:Y,sourcePromise:W,boundOptions:{}}),W},Oy=async({sourcePromise:J,sourceStream:X,sourceOptions:Y,sourceError:Z,destination:W,destinationStream:$,destinationError:Q,unpipeSignal:K,fileDescriptors:G,startTime:F})=>{let q=xy(J,W);iM({sourceStream:X,sourceError:Z,destinationStream:$,destinationError:Q,fileDescriptors:G,sourceOptions:Y,startTime:F});let H=new AbortController;try{let z=aM(X,$,H);return await Promise.race([nM(q),...sM(K,{sourceStream:X,mergedStream:z,sourceOptions:Y,fileDescriptors:G,startTime:F})])}finally{H.abort()}},xy=(J,X)=>Promise.allSettled([J,X]);import{setImmediate as Ty}from"timers/promises";import{on as Py}from"events";import{getDefaultHighWaterMark as Ny}from"stream";var TY=({subprocessStdout:J,subprocess:X,binary:Y,shouldEncode:Z,encoding:W,preserveNewlines:$})=>{let Q=new AbortController;return vy(X,Q),rM({stream:J,controller:Q,binary:Y,shouldEncode:!J.readableObjectMode&&Z,encoding:W,shouldSplit:!J.readableObjectMode,preserveNewlines:$})},vy=async(J,X)=>{try{await J}catch{}finally{X.abort()}},SK=({stream:J,onStreamEnd:X,lines:Y,encoding:Z,stripFinalNewline:W,allMixed:$})=>{let Q=new AbortController;By(X,Q,J);let K=J.readableObjectMode&&!$;return rM({stream:J,controller:Q,binary:Z==="buffer",shouldEncode:!K,encoding:Z,shouldSplit:!K&&Y,preserveNewlines:!W})},By=async(J,X,Y)=>{try{await J}catch{Y.destroy()}finally{X.abort()}},rM=({stream:J,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q})=>{let K=Py(J,"data",{signal:X.signal,highWaterMark:oM,highWatermark:oM});return jy({onStdoutChunk:K,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q})},IK=Ny(!0),oM=IK,jy=async function*({onStdoutChunk:J,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q}){let K=ky({binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q});try{for await(let[G]of J)yield*W9(G,K,0)}catch(G){if(!X.signal.aborted)throw G}finally{yield*h4(K)}},ky=({binary:J,shouldEncode:X,encoding:Y,shouldSplit:Z,preserveNewlines:W})=>[wY(J,Y,!X),RY(J,W,!Z,{})].filter(Boolean);var tM=async({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,buffer:W,maxBuffer:$,lines:Q,allMixed:K,stripFinalNewline:G,verboseInfo:F,streamInfo:q})=>{let H=Dy({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,allMixed:K,verboseInfo:F,streamInfo:q});if(!W){await Promise.all([_y(J),H]);return}let z=LK(G,Y),V=SK({stream:J,onStreamEnd:X,lines:Q,encoding:Z,stripFinalNewline:z,allMixed:K}),[M]=await Promise.all([Ey({stream:J,iterable:V,fdNumber:Y,encoding:Z,maxBuffer:$,lines:Q}),H]);return M},Dy=async({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,allMixed:W,verboseInfo:$,streamInfo:{fileDescriptors:Q}})=>{if(!PY({stdioItems:Q[Y]?.stdioItems,encoding:Z,verboseInfo:$,fdNumber:Y}))return;let K=SK({stream:J,onStreamEnd:X,lines:!0,encoding:Z,stripFinalNewline:!0,allMixed:W});await $M(K,J,Y,$)},_y=async(J)=>{if(await Ty(),J.readableFlowing===null)J.resume()},Ey=async({stream:J,stream:{readableObjectMode:X},iterable:Y,fdNumber:Z,encoding:W,maxBuffer:$,lines:Q})=>{try{if(X||Q)return await KY(Y,{maxBuffer:$});if(W==="buffer")return new Uint8Array(await GY(Y,{maxBuffer:$}));return await qY(Y,{maxBuffer:$})}catch(K){return eM($V({error:K,stream:J,readableObjectMode:X,lines:Q,encoding:W,fdNumber:Z}))}},hK=async(J)=>{try{return await J}catch(X){return eM(X)}},eM=({bufferedData:J})=>Pz(J)?new Uint8Array(J):J;import{finished as Cy}from"stream/promises";var A4=async(J,X,Y,{isSameDirection:Z,stopOnExit:W=!1}={})=>{let $=Sy(J,Y),Q=new AbortController;try{await Promise.race([...W?[Y.exitPromise]:[],Cy(J,{cleanup:!0,signal:Q.signal})])}catch(K){if(!$.stdinCleanedUp)fy(K,X,Y,Z)}finally{Q.abort()}},Sy=(J,{originalStreams:[X],subprocess:Y})=>{let Z={stdinCleanedUp:!1};if(J===X)Iy(J,Y,Z);return Z},Iy=(J,X,Y)=>{let{_destroy:Z}=J;J._destroy=(...W)=>{hy(X,Y),Z.call(J,...W)}},hy=({exitCode:J,signalCode:X},Y)=>{if(J!==null||X!==null)Y.stdinCleanedUp=!0},fy=(J,X,Y,Z)=>{if(!by(J,X,Y,Z))throw J},by=(J,X,Y,Z=!0)=>{if(Y.propagating)return JR(J)||DY(J);return Y.propagating=!0,fK(Y,X)===Z?JR(J):DY(J)},fK=({fileDescriptors:J},X)=>X!=="all"&&J[X].direction==="input",DY=(J)=>J?.code==="ERR_STREAM_PREMATURE_CLOSE",JR=(J)=>J?.code==="EPIPE";var XR=({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})=>J.stdio.map((G,F)=>bK({stream:G,fdNumber:F,encoding:X,buffer:Y[F],maxBuffer:Z[F],lines:W[F],allMixed:!1,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})),bK=async({stream:J,fdNumber:X,encoding:Y,buffer:Z,maxBuffer:W,lines:$,allMixed:Q,stripFinalNewline:K,verboseInfo:G,streamInfo:F})=>{if(!J)return;let q=A4(J,X,F);if(fK(F,X)){await q;return}let[H]=await Promise.all([tM({stream:J,onStreamEnd:q,fdNumber:X,encoding:Y,buffer:Z,maxBuffer:W,lines:$,allMixed:Q,stripFinalNewline:K,verboseInfo:G,streamInfo:F}),q]);return H};var YR=({stdout:J,stderr:X},{all:Y})=>Y&&(J||X)?$9([J,X].filter(Boolean)):void 0,ZR=({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})=>bK({...py(J,Y),fdNumber:"all",encoding:X,maxBuffer:Z[1]+Z[2],lines:W[1]||W[2],allMixed:Ay(J),stripFinalNewline:$,verboseInfo:Q,streamInfo:K}),py=({stdout:J,stderr:X,all:Y},[,Z,W])=>{let $=Z||W;if(!$)return{stream:Y,buffer:$};if(!Z)return{stream:X,buffer:$};if(!W)return{stream:J,buffer:$};return{stream:Y,buffer:$}},Ay=({all:J,stdout:X,stderr:Y})=>J&&X&&Y&&X.readableObjectMode!==Y.readableObjectMode;import{once as yy}from"events";var WR=(J)=>d9(J,"ipc"),$R=(J,X)=>{let Y=SX(J);D6({type:"ipc",verboseMessage:Y,fdNumber:"ipc",verboseInfo:X})};var QR=async({subprocess:J,buffer:X,maxBuffer:Y,ipc:Z,ipcOutput:W,verboseInfo:$})=>{if(!Z)return W;let Q=WR($),K=J1(X,"ipc"),G=J1(Y,"ipc");for await(let F of NK({anyProcess:J,channel:J.channel,isSubprocess:!1,ipc:Z,shouldAwait:!1,reference:!0})){if(K)QV(J,W,G),W.push(F);if(Q)$R(F,$)}return W},KR=async(J,X)=>{return await Promise.allSettled([J]),X};var GR=async({subprocess:J,options:{encoding:X,buffer:Y,maxBuffer:Z,lines:W,timeoutDuration:$,cancelSignal:Q,gracefulCancel:K,forceKillAfterDelay:G,stripFinalNewline:F,ipc:q,ipcInput:H},context:z,verboseInfo:V,fileDescriptors:M,originalStreams:R,onInternalError:L,controller:w})=>{let P=qM(J,z),N={originalStreams:R,fileDescriptors:M,subprocess:J,exitPromise:P,propagating:!1},v=XR({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:F,verboseInfo:V,streamInfo:N}),j=ZR({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:F,verboseInfo:V,streamInfo:N}),O=[],D=QR({subprocess:J,buffer:Y,maxBuffer:Z,ipc:q,ipcOutput:O,verboseInfo:V}),_=gy(R,J,N),C=cy(M,N);try{return await Promise.race([Promise.all([{},zM(P),Promise.all(v),j,D,pU(J,H),..._,...C]),L,my(J,w),...SU(J,$,z,w),...eL({subprocess:J,cancelSignal:Q,gracefulCancel:K,context:z,controller:w}),...EU({subprocess:J,cancelSignal:Q,gracefulCancel:K,forceKillAfterDelay:G,context:z,controller:w})])}catch(S){return z.terminationReason??="other",Promise.all([{error:S},P,Promise.all(v.map((I)=>hK(I))),hK(j),KR(D,O),Promise.allSettled(_),Promise.allSettled(C)])}},gy=(J,X,Y)=>J.map((Z,W)=>Z===X.stdio[W]?void 0:A4(Z,W,Y)),cy=(J,X)=>J.flatMap(({stdioItems:Y},Z)=>Y.filter(({value:W,stream:$=W})=>L6($,{checkOpen:!1})&&!H6($)).map(({type:W,value:$,stream:Q=$})=>A4(Q,Z,X,{isSameDirection:s8.has(W),stopOnExit:W==="native"}))),my=async(J,{signal:X})=>{let[Y]=await yy(J,"error",{signal:X});throw Y};var FR=()=>({readableDestroy:new WeakMap,writableFinal:new WeakMap,writableDestroy:new WeakMap}),y4=(J,X,Y)=>{let Z=J[Y];if(!Z.has(X))Z.set(X,[]);let W=Z.get(X),$=E6();return W.push($),{resolve:$.resolve.bind($),promises:W}},Z5=async({resolve:J,promises:X},Y)=>{J();let[Z]=await Promise.race([Promise.allSettled([!0,Y]),Promise.all([!1,...X])]);return!Z};import{Readable as ly}from"stream";import{callbackify as uy}from"util";import{finished as qR}from"stream/promises";var pK=async(J)=>{if(J===void 0)return;try{await AK(J)}catch{}},HR=async(J)=>{if(J===void 0)return;try{await yK(J)}catch{}},AK=async(J)=>{await qR(J,{cleanup:!0,readable:!1,writable:!0})},yK=async(J)=>{await qR(J,{cleanup:!0,readable:!0,writable:!1})},_Y=async(J,X)=>{if(await J,X)throw X},EY=(J,X,Y)=>{if(Y&&!DY(Y))J.destroy(Y);else if(X)J.destroy()};var zR=({subprocess:J,concurrentStreams:X,encoding:Y},{from:Z,binary:W=!0,preserveNewlines:$=!0}={})=>{let Q=W||l8.has(Y),{subprocessStdout:K,waitReadableDestroy:G}=gK(J,Z,X),{readableEncoding:F,readableObjectMode:q,readableHighWaterMark:H}=cK(K,Q),{read:z,onStdoutDataDone:V}=mK({subprocessStdout:K,subprocess:J,binary:Q,encoding:Y,preserveNewlines:$}),M=new ly({read:z,destroy:uy(uK.bind(void 0,{subprocessStdout:K,subprocess:J,waitReadableDestroy:G})),highWaterMark:H,objectMode:q,encoding:F});return lK({subprocessStdout:K,onStdoutDataDone:V,readable:M,subprocess:J}),M},gK=(J,X,Y)=>{let Z=o9(J,X),W=y4(Y,Z,"readableDestroy");return{subprocessStdout:Z,waitReadableDestroy:W}},cK=({readableEncoding:J,readableObjectMode:X,readableHighWaterMark:Y},Z)=>Z?{readableEncoding:J,readableObjectMode:X,readableHighWaterMark:Y}:{readableEncoding:J,readableObjectMode:!0,readableHighWaterMark:IK},mK=({subprocessStdout:J,subprocess:X,binary:Y,encoding:Z,preserveNewlines:W})=>{let $=E6(),Q=TY({subprocessStdout:J,subprocess:X,binary:Y,shouldEncode:!Y,encoding:Z,preserveNewlines:W});return{read(){dy(this,Q,$)},onStdoutDataDone:$}},dy=async(J,X,Y)=>{try{let{value:Z,done:W}=await X.next();if(W)Y.resolve();else J.push(Z)}catch{}},lK=async({subprocessStdout:J,onStdoutDataDone:X,readable:Y,subprocess:Z,subprocessStdin:W})=>{try{if(await yK(J),await Z,await pK(W),await X,Y.readable)Y.push(null)}catch($){await pK(W),LR(Y,$)}},uK=async({subprocessStdout:J,subprocess:X,waitReadableDestroy:Y},Z)=>{if(await Z5(Y,X))LR(J,Z),await _Y(X,Z)},LR=(J,X)=>{EY(J,J.readable,X)};import{Writable as iy}from"stream";import{callbackify as UR}from"util";var VR=({subprocess:J,concurrentStreams:X},{to:Y}={})=>{let{subprocessStdin:Z,waitWritableFinal:W,waitWritableDestroy:$}=dK(J,Y,X),Q=new iy({...iK(Z,J,W),destroy:UR(aK.bind(void 0,{subprocessStdin:Z,subprocess:J,waitWritableFinal:W,waitWritableDestroy:$})),highWaterMark:Z.writableHighWaterMark,objectMode:Z.writableObjectMode});return nK(Z,Q),Q},dK=(J,X,Y)=>{let Z=iX(J,X),W=y4(Y,Z,"writableFinal"),$=y4(Y,Z,"writableDestroy");return{subprocessStdin:Z,waitWritableFinal:W,waitWritableDestroy:$}},iK=(J,X,Y)=>({write:ny.bind(void 0,J),final:UR(ay.bind(void 0,J,X,Y))}),ny=(J,X,Y,Z)=>{if(J.write(X,Y))Z();else J.once("drain",Z)},ay=async(J,X,Y)=>{if(await Z5(Y,X)){if(J.writable)J.end();await X}},nK=async(J,X,Y)=>{try{if(await AK(J),X.writable)X.end()}catch(Z){await HR(Y),MR(X,Z)}},aK=async({subprocessStdin:J,subprocess:X,waitWritableFinal:Y,waitWritableDestroy:Z},W)=>{if(await Z5(Y,X),await Z5(Z,X))MR(J,W),await _Y(X,W)},MR=(J,X)=>{EY(J,J.writable,X)};import{Duplex as sy}from"stream";import{callbackify as oy}from"util";var RR=({subprocess:J,concurrentStreams:X,encoding:Y},{from:Z,to:W,binary:$=!0,preserveNewlines:Q=!0}={})=>{let K=$||l8.has(Y),{subprocessStdout:G,waitReadableDestroy:F}=gK(J,Z,X),{subprocessStdin:q,waitWritableFinal:H,waitWritableDestroy:z}=dK(J,W,X),{readableEncoding:V,readableObjectMode:M,readableHighWaterMark:R}=cK(G,K),{read:L,onStdoutDataDone:w}=mK({subprocessStdout:G,subprocess:J,binary:K,encoding:Y,preserveNewlines:Q}),P=new sy({read:L,...iK(q,J,H),destroy:oy(ry.bind(void 0,{subprocessStdout:G,subprocessStdin:q,subprocess:J,waitReadableDestroy:F,waitWritableFinal:H,waitWritableDestroy:z})),readableHighWaterMark:R,writableHighWaterMark:q.writableHighWaterMark,readableObjectMode:M,writableObjectMode:q.writableObjectMode,encoding:V});return lK({subprocessStdout:G,onStdoutDataDone:w,readable:P,subprocess:J,subprocessStdin:q}),nK(q,P,G),P},ry=async({subprocessStdout:J,subprocessStdin:X,subprocess:Y,waitReadableDestroy:Z,waitWritableFinal:W,waitWritableDestroy:$},Q)=>{await Promise.all([uK({subprocessStdout:J,subprocess:Y,waitReadableDestroy:Z},Q),aK({subprocessStdin:X,subprocess:Y,waitWritableFinal:W,waitWritableDestroy:$},Q)])};var sK=(J,X,{from:Y,binary:Z=!1,preserveNewlines:W=!1}={})=>{let $=Z||l8.has(X),Q=o9(J,Y),K=TY({subprocessStdout:Q,subprocess:J,binary:$,shouldEncode:!0,encoding:X,preserveNewlines:W});return ty(K,Q,J)},ty=async function*(J,X,Y){try{yield*J}finally{if(X.readable)X.destroy();await Y}};var wR=(J,{encoding:X})=>{let Y=FR();J.readable=zR.bind(void 0,{subprocess:J,concurrentStreams:Y,encoding:X}),J.writable=VR.bind(void 0,{subprocess:J,concurrentStreams:Y}),J.duplex=RR.bind(void 0,{subprocess:J,concurrentStreams:Y,encoding:X}),J.iterable=sK.bind(void 0,J,X),J[Symbol.asyncIterator]=sK.bind(void 0,J,X,{})};var OR=(J,X)=>{for(let[Y,Z]of Jg){let W=Z.value.bind(X);Reflect.defineProperty(J,Y,{...Z,value:W})}},ey=(async()=>{})().constructor.prototype,Jg=["then","catch","finally"].map((J)=>[J,Reflect.getOwnPropertyDescriptor(ey,J)]);var xR=(J,X,Y,Z)=>{let{file:W,commandArguments:$,command:Q,escapedCommand:K,startTime:G,verboseInfo:F,options:q,fileDescriptors:H}=Zg(J,X,Y),{subprocess:z,promise:V}=$g({file:W,commandArguments:$,options:q,startTime:G,verboseInfo:F,command:Q,escapedCommand:K,fileDescriptors:H});return z.pipe=kY.bind(void 0,{source:z,sourcePromise:V,boundOptions:{},createNested:Z}),OR(z,V),C6.set(z,{options:q,fileDescriptors:H}),z},Zg=(J,X,Y)=>{let{command:Z,escapedCommand:W,startTime:$,verboseInfo:Q}=hX(J,X,Y),{file:K,commandArguments:G,options:F}=ZY(J,X,Y),q=Wg(F),H=TM(q,Q);return{file:K,commandArguments:G,command:Z,escapedCommand:W,startTime:$,verboseInfo:Q,options:q,fileDescriptors:H}},Wg=({timeout:J,signal:X,...Y})=>{if(X!==void 0)throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');return{...Y,timeoutDuration:J}},$g=({file:J,commandArguments:X,options:Y,startTime:Z,verboseInfo:W,command:$,escapedCommand:Q,fileDescriptors:K})=>{let G;try{G=Yg(J,X,Y)}catch(M){return vM({error:M,command:$,escapedCommand:Q,fileDescriptors:K,options:Y,startTime:Z,verboseInfo:W})}let F=new AbortController;Xg(Number.POSITIVE_INFINITY,F.signal);let q=[...G.stdio];pM(G,K,F),mM(G,Y,F);let H={},z=E6();G.kill=rL.bind(void 0,{kill:G.kill.bind(G),options:Y,onInternalError:z,context:H,controller:F}),G.all=YR(G,Y),wR(G,Y),xM(G,Y);let V=Qg({subprocess:G,options:Y,startTime:Z,verboseInfo:W,fileDescriptors:K,originalStreams:q,command:$,escapedCommand:Q,context:H,onInternalError:z,controller:F});return{subprocess:G,promise:V}},Qg=async({subprocess:J,options:X,startTime:Y,verboseInfo:Z,fileDescriptors:W,originalStreams:$,command:Q,escapedCommand:K,context:G,onInternalError:F,controller:q})=>{let[H,[z,V],M,R,L]=await GR({subprocess:J,options:X,context:G,verboseInfo:Z,fileDescriptors:W,originalStreams:$,onInternalError:F,controller:q});q.abort(),F.resolve();let w=M.map((v,j)=>Z1(v,X,j)),P=Z1(R,X,"all"),N=Kg({errorInfo:H,exitCode:z,signal:V,stdio:w,all:P,ipcOutput:L,context:G,options:X,command:Q,escapedCommand:K,startTime:Y});return J5(N,Z,X)},Kg=({errorInfo:J,exitCode:X,signal:Y,stdio:Z,all:W,ipcOutput:$,context:Q,options:K,command:G,escapedCommand:F,startTime:q})=>("error"in J)?I4({error:J.error,command:G,escapedCommand:F,timedOut:Q.terminationReason==="timeout",isCanceled:Q.terminationReason==="cancel"||Q.terminationReason==="gracefulCancel",isGracefullyCanceled:Q.terminationReason==="gracefulCancel",isMaxBuffer:J.error instanceof X1,isForcefullyTerminated:Q.isForcefullyTerminated,exitCode:X,signal:Y,stdio:Z,all:W,ipcOutput:$,options:K,startTime:q,isSync:!1}):zY({command:G,escapedCommand:F,stdio:Z,all:W,ipcOutput:$,options:K,startTime:q});var CY=(J,X)=>{let Y=Object.fromEntries(Object.entries(X).map(([Z,W])=>[Z,Gg(Z,J[Z],W)]));return{...J,...Y}},Gg=(J,X,Y)=>{if(Fg.has(J)&&d0(X)&&d0(Y))return{...X,...Y};return Y},Fg=new Set(["env",...DQ]);var j1=(J,X,Y,Z)=>{let W=(Q,K,G)=>j1(Q,K,Y,G),$=(...Q)=>qg({mapArguments:J,deepOptions:Y,boundOptions:X,setBoundExeca:Z,createNested:W},...Q);if(Z!==void 0)Z($,W,X);return $},qg=({mapArguments:J,deepOptions:X={},boundOptions:Y={},setBoundExeca:Z,createNested:W},$,...Q)=>{if(d0($))return W(J,CY(Y,$),Z);let{file:K,commandArguments:G,options:F,isSync:q}=Hg({mapArguments:J,firstArgument:$,nextArguments:Q,deepOptions:X,boundOptions:Y});return q?UM(K,G,F):xR(K,G,F,W)},Hg=({mapArguments:J,firstArgument:X,nextArguments:Y,deepOptions:Z,boundOptions:W})=>{let $=Tz(X)?Dz(X,Y):[X,...Y],[Q,K,G]=vX(...$),F=CY(CY(Z,W),G),{file:q=Q,commandArguments:H=K,options:z=F,isSync:V=!1}=J({file:Q,commandArguments:K,options:F});return{file:q,commandArguments:H,options:z,isSync:V}};var PR=({file:J,commandArguments:X})=>vR(J,X),NR=({file:J,commandArguments:X})=>({...vR(J,X),isSync:!0}),vR=(J,X)=>{if(X.length>0)throw new TypeError(`The command and its arguments must be passed as a single string: ${J} ${X}.`);let[Y,...Z]=zg(J);return{file:Y,commandArguments:Z}},zg=(J)=>{if(typeof J!=="string")throw new TypeError(`The command must be a string: ${String(J)}.`);let X=J.trim();if(X==="")return[];let Y=[];for(let Z of X.split(Lg)){let W=Y.at(-1);if(W&&W.endsWith("\\"))Y[Y.length-1]=`${W.slice(0,-1)} ${Z}`;else Y.push(Z)}return Y},Lg=/ +/g;var BR=(J,X,Y)=>{J.sync=X(Ug,Y),J.s=J.sync},jR=({options:J})=>kR(J),Ug=({options:J})=>({...kR(J),isSync:!0}),kR=(J)=>({options:{...Vg(J),...J}}),Vg=({input:J,inputFile:X,stdio:Y})=>J===void 0&&X===void 0&&Y===void 0?{stdin:"inherit"}:{},TR={preferLocal:!0};var DR=j1(()=>({})),yV0=j1(()=>({isSync:!0})),gV0=j1(PR),cV0=j1(NR),mV0=j1(hU),lV0=j1(jR,{},TR,BR),{sendMessage:uV0,getOneMessage:dV0,getEachMessage:iV0,getCancelSignal:nV0}=PM();var{Glob:Mc}=globalThis.Bun;class oK{constructor(){this._listeners={}}addEventListener(J,X){let Y=this._listeners;if(Y[J]===void 0)Y[J]=[];if(Y[J].indexOf(X)===-1)Y[J].push(X);return this}removeEventListener(J,X){let Z=this._listeners[J];if(Z!==void 0){let W=Z.indexOf(X);if(W!==-1)Z.splice(W,1)}return this}dispatchEvent(J){let Y=this._listeners[J.type];if(Y!==void 0){let Z=Y.slice(0);for(let W=0,$=Z.length;W<$;W++)Z[W].call(this,J)}return this}dispose(){for(let J in this._listeners)delete this._listeners[J]}}class T1{constructor(J,X,Y,Z={}){if(this._name=void 0,this._parent=void 0,this._child=void 0,this._attributes=void 0,this._disposed=!1,this._name=J,this._parent=X,this._child=Y,this._attributes=Z,!X.isOnGraph(Y))throw new Error("Cannot connect disconnected graphs.")}getName(){return this._name}getParent(){return this._parent}getChild(){return this._child}setChild(J){return this._child=J,this}getAttributes(){return this._attributes}dispose(){if(this._disposed)return;this._parent._destroyRef(this),this._disposed=!0}isDisposed(){return this._disposed}}class rK extends oK{constructor(...J){super(...J);this._emptySet=new Set,this._edges=new Set,this._parentEdges=new Map,this._childEdges=new Map}listEdges(){return Array.from(this._edges)}listParentEdges(J){return Array.from(this._childEdges.get(J)||this._emptySet)}listParents(J){let X=new Set;for(let Y of this.listParentEdges(J))X.add(Y.getParent());return Array.from(X)}listChildEdges(J){return Array.from(this._parentEdges.get(J)||this._emptySet)}listChildren(J){let X=new Set;for(let Y of this.listChildEdges(J))X.add(Y.getChild());return Array.from(X)}disconnectParents(J,X){for(let Y of this.listParentEdges(J))if(!X||X(Y.getParent()))Y.dispose();return this}_createEdge(J,X,Y,Z){let W=new T1(J,X,Y,Z);this._edges.add(W);let $=W.getParent();if(!this._parentEdges.has($))this._parentEdges.set($,new Set);this._parentEdges.get($).add(W);let Q=W.getChild();if(!this._childEdges.has(Q))this._childEdges.set(Q,new Set);return this._childEdges.get(Q).add(W),W}_destroyEdge(J){return this._edges.delete(J),this._parentEdges.get(J.getParent()).delete(J),this._childEdges.get(J.getChild()).delete(J),this}}function g4(){return g4=Object.assign||function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)if(Object.prototype.hasOwnProperty.call(Y,Z))J[Z]=Y[Z]}return J},g4.apply(this,arguments)}class I6{constructor(J){if(this.list=[],J)for(let X of J)this.list.push(X)}add(J){this.list.push(J)}remove(J){let X=this.list.indexOf(J);if(X>=0)this.list.splice(X,1)}removeChild(J){let X=[];for(let Y of this.list)if(Y.getChild()===J)X.push(Y);for(let Y of X)this.remove(Y);return X}listRefsByChild(J){let X=[];for(let Y of this.list)if(Y.getChild()===J)X.push(Y);return X}values(){return this.list}}class _0{constructor(J){if(this.set=new Set,this.map=new Map,J)for(let X of J)this.add(X)}add(J){let X=J.getChild();this.removeChild(X),this.set.add(J),this.map.set(X,J)}remove(J){this.set.delete(J),this.map.delete(J.getChild())}removeChild(J){let X=this.map.get(J)||null;if(X)this.remove(X);return X}getRefByChild(J){return this.map.get(J)||null}values(){return Array.from(this.set)}}class o8{constructor(J){if(this.map={},J)Object.assign(this.map,J)}set(J,X){this.map[J]=X}delete(J){delete this.map[J]}get(J){return this.map[J]||null}keys(){return Object.keys(this.map)}values(){return Object.values(this.map)}}var L0=Symbol("attributes"),k1=Symbol("immutableKeys");class SY extends oK{constructor(J){super();this._disposed=!1,this.graph=void 0,this[L0]=void 0,this[k1]=void 0,this.graph=J,this[k1]=new Set,this[L0]=this._createAttributes()}getDefaults(){return{}}_createAttributes(){let J=this.getDefaults(),X={};for(let Y in J){let Z=J[Y];if(Z instanceof SY){let W=this.graph._createEdge(Y,this,Z);this[k1].add(Y),X[Y]=W}else X[Y]=Z}return X}isOnGraph(J){return this.graph===J.graph}isDisposed(){return this._disposed}dispose(){if(this._disposed)return;this.graph.listChildEdges(this).forEach((J)=>J.dispose()),this.graph.disconnectParents(this),this._disposed=!0,this.dispatchEvent({type:"dispose"})}detach(){return this.graph.disconnectParents(this),this}swap(J,X){for(let Y in this[L0]){let Z=this[L0][Y];if(Z instanceof T1){let W=Z;if(W.getChild()===J)this.setRef(Y,X,W.getAttributes())}else if(Z instanceof I6)for(let W of Z.listRefsByChild(J)){let $=W.getAttributes();this.removeRef(Y,J),this.addRef(Y,X,$)}else if(Z instanceof _0){let W=Z.getRefByChild(J);if(W){let $=W.getAttributes();this.removeRef(Y,J),this.addRef(Y,X,$)}}else if(Z instanceof o8)for(let W of Z.keys()){let $=Z.get(W);if($.getChild()===J)this.setRefMap(Y,W,X,$.getAttributes())}}return this}get(J){return this[L0][J]}set(J,X){return this[L0][J]=X,this.dispatchEvent({type:"change",attribute:J})}getRef(J){let X=this[L0][J];return X?X.getChild():null}setRef(J,X,Y){if(this[k1].has(J))throw new Error(`Cannot overwrite immutable attribute, "${J}".`);let Z=this[L0][J];if(Z)Z.dispose();if(!X)return this;let W=this.graph._createEdge(J,this,X,Y);return this[L0][J]=W,this.dispatchEvent({type:"change",attribute:J})}listRefs(J){return this.assertRefList(J).values().map((Y)=>Y.getChild())}addRef(J,X,Y){let Z=this.graph._createEdge(J,this,X,Y);return this.assertRefList(J).add(Z),this.dispatchEvent({type:"change",attribute:J})}removeRef(J,X){let Y=this.assertRefList(J);if(Y instanceof I6)for(let Z of Y.listRefsByChild(X))Z.dispose();else{let Z=Y.getRefByChild(X);if(Z)Z.dispose()}return this}assertRefList(J){let X=this[L0][J];if(X instanceof I6||X instanceof _0)return X;throw new Error(`Expected RefList or RefSet for attribute "${J}"`)}listRefMapKeys(J){return this.assertRefMap(J).keys()}listRefMapValues(J){return this.assertRefMap(J).values().map((X)=>X.getChild())}getRefMap(J,X){let Z=this.assertRefMap(J).get(X);return Z?Z.getChild():null}setRefMap(J,X,Y,Z){let W=this.assertRefMap(J),$=W.get(X);if($)$.dispose();if(!Y)return this;Z=Object.assign(Z||{},{key:X});let Q=this.graph._createEdge(J,this,Y,g4({},Z,{key:X}));return W.set(X,Q),this.dispatchEvent({type:"change",attribute:J,key:X})}assertRefMap(J){let X=this[L0][J];if(X instanceof o8)return X;throw new Error(`Expected RefMap for attribute "${J}"`)}dispatchEvent(J){return super.dispatchEvent(g4({},J,{target:this})),this.graph.dispatchEvent(g4({},J,{target:this,type:`node:${J.type}`})),this}_destroyRef(J){let X=J.getName();if(this[L0][X]===J){if(this[L0][X]=null,this[k1].has(X))J.getChild().dispose()}else if(this[L0][X]instanceof I6)this[L0][X].remove(J);else if(this[L0][X]instanceof _0)this[L0][X].remove(J);else if(this[L0][X]instanceof o8){let Y=this[L0][X];for(let Z of Y.keys())if(Y.get(Z)===J)Y.delete(Z)}else return;this.graph._destroyEdge(J),this.dispatchEvent({type:"change",attribute:X})}}var fR="v4.1.1",AY="@glb.bin",p;(function(J){J.ACCESSOR="Accessor",J.ANIMATION="Animation",J.ANIMATION_CHANNEL="AnimationChannel",J.ANIMATION_SAMPLER="AnimationSampler",J.BUFFER="Buffer",J.CAMERA="Camera",J.MATERIAL="Material",J.MESH="Mesh",J.PRIMITIVE="Primitive",J.PRIMITIVE_TARGET="PrimitiveTarget",J.NODE="Node",J.ROOT="Root",J.SCENE="Scene",J.SKIN="Skin",J.TEXTURE="Texture",J.TEXTURE_INFO="TextureInfo"})(p||(p={}));var yY;(function(J){J.INTERLEAVED="interleaved",J.SEPARATE="separate"})(yY||(yY={}));var u8;(function(J){J.ARRAY_BUFFER="ARRAY_BUFFER",J.ELEMENT_ARRAY_BUFFER="ELEMENT_ARRAY_BUFFER",J.INVERSE_BIND_MATRICES="INVERSE_BIND_MATRICES",J.OTHER="OTHER",J.SPARSE="SPARSE"})(u8||(u8={}));var gY;(function(J){J[J.R=4096]="R",J[J.G=256]="G",J[J.B=16]="B",J[J.A=1]="A"})(gY||(gY={}));var W1;(function(J){J.GLTF="GLTF",J.GLB="GLB"})(W1||(W1={}));var m4={"5120":Int8Array,"5121":Uint8Array,"5122":Int16Array,"5123":Uint16Array,"5125":Uint32Array,"5126":Float32Array},eK=typeof Float32Array!=="undefined"?Float32Array:Array;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};function Mg(){var J=new eK(3);if(eK!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function tK(J){var X=J[0],Y=J[1],Z=J[2];return Math.hypot(X,Y,Z)}function Rg(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[3]*Z+Y[7]*W+Y[11]*$+Y[15];return Q=Q||1,J[0]=(Y[0]*Z+Y[4]*W+Y[8]*$+Y[12])/Q,J[1]=(Y[1]*Z+Y[5]*W+Y[9]*$+Y[13])/Q,J[2]=(Y[2]*Z+Y[6]*W+Y[10]*$+Y[14])/Q,J}(function(){var J=Mg();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}})();function bR(J){let X=pR(),Y=J.propertyType===p.NODE?[J]:J.listChildren();for(let Z of Y)Z.traverse((W)=>{let $=W.getMesh();if(!$)return;let Q=wg($,W.getWorldMatrix());if(Q.min.every(isFinite)&&Q.max.every(isFinite))JG(Q.min,X),JG(Q.max,X)});return X}function wg(J,X){let Y=pR();for(let Z of J.listPrimitives()){let W=Z.getAttribute("POSITION"),$=Z.getIndices();if(!W)continue;let Q=[0,0,0],K=[0,0,0];for(let G=0,F=$?$.getCount():W.getCount();G<F;G++){let q=$?$.getScalar(G):G;Q=W.getElement(q,Q),K=Rg(K,Q,X),JG(K,Y)}}return Y}function JG(J,X){for(let Y=0;Y<3;Y++)X.min[Y]=Math.min(J[Y],X.min[Y]),X.max[Y]=Math.max(J[Y],X.max[Y])}function pR(){return{min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}}class G0{static createBufferFromDataURI(J){if(typeof Buffer==="undefined"){let X=atob(J.split(",")[1]),Y=new Uint8Array(X.length);for(let Z=0;Z<X.length;Z++)Y[Z]=X.charCodeAt(Z);return Y}else{let X=J.split(",")[1],Y=J.indexOf("base64")>=0;return Buffer.from(X,Y?"base64":"utf8")}}static encodeText(J){return new TextEncoder().encode(J)}static decodeText(J){return new TextDecoder().decode(J)}static concat(J){let X=0;for(let W of J)X+=W.byteLength;let Y=new Uint8Array(X),Z=0;for(let W of J)Y.set(W,Z),Z+=W.byteLength;return Y}static pad(J,X=0){let Y=this.padNumber(J.byteLength);if(Y===J.byteLength)return J;let Z=new Uint8Array(Y);if(Z.set(J),X!==0)for(let W=J.byteLength;W<Y;W++)Z[W]=X;return Z}static padNumber(J){return Math.ceil(J/4)*4}static equals(J,X){if(J===X)return!0;if(J.byteLength!==X.byteLength)return!1;let Y=J.byteLength;while(Y--)if(J[Y]!==X[Y])return!1;return!0}static toView(J,X=0,Y=1/0){return new Uint8Array(J.buffer,J.byteOffset+X,Math.min(J.byteLength,Y))}static assertView(J){if(J&&!ArrayBuffer.isView(J))throw new Error(`Method requires Uint8Array parameter; received "${typeof J}".`);return J}}class AR{match(J){return J.length>=3&&J[0]===255&&J[1]===216&&J[2]===255}getSize(J){let X=new DataView(J.buffer,J.byteOffset+4),Y,Z;while(X.byteLength){if(Y=X.getUint16(0,!1),Og(X,Y),Z=X.getUint8(Y+1),Z===192||Z===193||Z===194)return[X.getUint16(Y+7,!1),X.getUint16(Y+5,!1)];X=new DataView(J.buffer,X.byteOffset+Y+2)}throw new TypeError("Invalid JPG, no size found")}getChannels(J){return 3}}class lY{match(J){return J.length>=8&&J[0]===137&&J[1]===80&&J[2]===78&&J[3]===71&&J[4]===13&&J[5]===10&&J[6]===26&&J[7]===10}getSize(J){let X=new DataView(J.buffer,J.byteOffset);if(G0.decodeText(J.slice(12,16))===lY.PNG_FRIED_CHUNK_NAME)return[X.getUint32(32,!1),X.getUint32(36,!1)];return[X.getUint32(16,!1),X.getUint32(20,!1)]}getChannels(J){return 4}}lY.PNG_FRIED_CHUNK_NAME="CgBI";class $1{static registerFormat(J,X){this.impls[J]=X}static getMimeType(J){for(let X in this.impls)if(this.impls[X].match(J))return X;return null}static getSize(J,X){if(!this.impls[X])return null;return this.impls[X].getSize(J)}static getChannels(J,X){if(!this.impls[X])return null;return this.impls[X].getChannels(J)}static getVRAMByteLength(J,X){if(!this.impls[X])return null;if(this.impls[X].getVRAMByteLength)return this.impls[X].getVRAMByteLength(J);let Y=0,Z=4,W=this.getSize(J,X);if(!W)return null;while(W[0]>1||W[1]>1)Y+=W[0]*W[1]*Z,W[0]=Math.max(Math.floor(W[0]/2),1),W[1]=Math.max(Math.floor(W[1]/2),1);return Y+=1*Z,Y}static mimeTypeToExtension(J){if(J==="image/jpeg")return"jpg";return J.split("/").pop()}static extensionToMimeType(J){if(J==="jpg")return"image/jpeg";if(!J)return"";return`image/${J}`}}$1.impls={"image/jpeg":new AR,"image/png":new lY};function Og(J,X){if(X>J.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(J.getUint8(X)!==255)throw new TypeError("Invalid JPG, marker table corrupted");return J}class Q1{static basename(J){let X=J.split(/[\\/]/).pop();return X.substring(0,X.lastIndexOf("."))}static extension(J){if(J.startsWith("data:image/")){let X=J.match(/data:(image\/\w+)/)[1];return $1.mimeTypeToExtension(X)}else if(J.startsWith("data:model/gltf+json"))return"gltf";else if(J.startsWith("data:model/gltf-binary"))return"glb";else if(J.startsWith("data:application/"))return"bin";return J.split(/[\\/]/).pop().split(/[.]/).pop()}}function _R(J){return Object.prototype.toString.call(J)==="[object Object]"}function K9(J){if(_R(J)===!1)return!1;let X=J.constructor;if(X===void 0)return!0;let Y=X.prototype;if(_R(Y)===!1)return!1;if(Object.prototype.hasOwnProperty.call(Y,"isPrototypeOf")===!1)return!1;return!0}var XG,YG;(function(J){J[J.SILENT=4]="SILENT",J[J.ERROR=3]="ERROR",J[J.WARN=2]="WARN",J[J.INFO=1]="INFO",J[J.DEBUG=0]="DEBUG"})(YG||(YG={}));class e8{constructor(J){this.verbosity=void 0,this.verbosity=J}debug(J){if(this.verbosity<=e8.Verbosity.DEBUG)console.debug(J)}info(J){if(this.verbosity<=e8.Verbosity.INFO)console.info(J)}warn(J){if(this.verbosity<=e8.Verbosity.WARN)console.warn(J)}error(J){if(this.verbosity<=e8.Verbosity.ERROR)console.error(J)}}XG=e8;e8.Verbosity=YG;e8.DEFAULT_INSTANCE=new XG(XG.Verbosity.INFO);function xg(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8],q=J[9],H=J[10],z=J[11],V=J[12],M=J[13],R=J[14],L=J[15],w=X*Q-Y*$,P=X*K-Z*$,N=X*G-W*$,v=Y*K-Z*Q,j=Y*G-W*Q,O=Z*G-W*K,D=F*M-q*V,_=F*R-H*V,C=F*L-z*V,S=q*R-H*M,I=q*L-z*M,f=H*L-z*R;return w*f-P*I+N*S+v*C-j*_+O*D}function Pg(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=X[9],V=X[10],M=X[11],R=X[12],L=X[13],w=X[14],P=X[15],N=Y[0],v=Y[1],j=Y[2],O=Y[3];return J[0]=N*Z+v*K+j*H+O*R,J[1]=N*W+v*G+j*z+O*L,J[2]=N*$+v*F+j*V+O*w,J[3]=N*Q+v*q+j*M+O*P,N=Y[4],v=Y[5],j=Y[6],O=Y[7],J[4]=N*Z+v*K+j*H+O*R,J[5]=N*W+v*G+j*z+O*L,J[6]=N*$+v*F+j*V+O*w,J[7]=N*Q+v*q+j*M+O*P,N=Y[8],v=Y[9],j=Y[10],O=Y[11],J[8]=N*Z+v*K+j*H+O*R,J[9]=N*W+v*G+j*z+O*L,J[10]=N*$+v*F+j*V+O*w,J[11]=N*Q+v*q+j*M+O*P,N=Y[12],v=Y[13],j=Y[14],O=Y[15],J[12]=N*Z+v*K+j*H+O*R,J[13]=N*W+v*G+j*z+O*L,J[14]=N*$+v*F+j*V+O*w,J[15]=N*Q+v*q+j*M+O*P,J}function Ng(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[4],Q=X[5],K=X[6],G=X[8],F=X[9],q=X[10];return J[0]=Math.hypot(Y,Z,W),J[1]=Math.hypot($,Q,K),J[2]=Math.hypot(G,F,q),J}function vg(J,X){var Y=new eK(3);Ng(Y,X);var Z=1/Y[0],W=1/Y[1],$=1/Y[2],Q=X[0]*Z,K=X[1]*W,G=X[2]*$,F=X[4]*Z,q=X[5]*W,H=X[6]*$,z=X[8]*Z,V=X[9]*W,M=X[10]*$,R=Q+q+M,L=0;if(R>0)L=Math.sqrt(R+1)*2,J[3]=0.25*L,J[0]=(H-V)/L,J[1]=(z-G)/L,J[2]=(K-F)/L;else if(Q>q&&Q>M)L=Math.sqrt(1+Q-q-M)*2,J[3]=(H-V)/L,J[0]=0.25*L,J[1]=(K+F)/L,J[2]=(z+G)/L;else if(q>M)L=Math.sqrt(1+q-Q-M)*2,J[3]=(z-G)/L,J[0]=(K+F)/L,J[1]=0.25*L,J[2]=(H+V)/L;else L=Math.sqrt(1+M-Q-q)*2,J[3]=(K-F)/L,J[0]=(z+G)/L,J[1]=(H+V)/L,J[2]=0.25*L;return J}class b0{static identity(J){return J}static eq(J,X,Y=0.00001){if(J.length!==X.length)return!1;for(let Z=0;Z<J.length;Z++)if(Math.abs(J[Z]-X[Z])>Y)return!1;return!0}static clamp(J,X,Y){if(J<X)return X;if(J>Y)return Y;return J}static decodeNormalizedInt(J,X){switch(X){case 5126:return J;case 5123:return J/65535;case 5121:return J/255;case 5122:return Math.max(J/32767,-1);case 5120:return Math.max(J/127,-1);default:throw new Error("Invalid component type.")}}static encodeNormalizedInt(J,X){switch(X){case 5126:return J;case 5123:return Math.round(b0.clamp(J,0,1)*65535);case 5121:return Math.round(b0.clamp(J,0,1)*255);case 5122:return Math.round(b0.clamp(J,-1,1)*32767);case 5120:return Math.round(b0.clamp(J,-1,1)*127);default:throw new Error("Invalid component type.")}}static decompose(J,X,Y,Z){let W=tK([J[0],J[1],J[2]]),$=tK([J[4],J[5],J[6]]),Q=tK([J[8],J[9],J[10]]);if(xg(J)<0)W=-W;X[0]=J[12],X[1]=J[13],X[2]=J[14];let G=J.slice(),F=1/W,q=1/$,H=1/Q;G[0]*=F,G[1]*=F,G[2]*=F,G[4]*=q,G[5]*=q,G[6]*=q,G[8]*=H,G[9]*=H,G[10]*=H,vg(Y,G),Z[0]=W,Z[1]=$,Z[2]=Q}static compose(J,X,Y,Z){let W=Z,$=X[0],Q=X[1],K=X[2],G=X[3],F=$+$,q=Q+Q,H=K+K,z=$*F,V=$*q,M=$*H,R=Q*q,L=Q*H,w=K*H,P=G*F,N=G*q,v=G*H,j=Y[0],O=Y[1],D=Y[2];return W[0]=(1-(R+w))*j,W[1]=(V+v)*j,W[2]=(M-N)*j,W[3]=0,W[4]=(V-v)*O,W[5]=(1-(z+w))*O,W[6]=(L+P)*O,W[7]=0,W[8]=(M+N)*D,W[9]=(L-P)*D,W[10]=(1-(z+R))*D,W[11]=0,W[12]=J[0],W[13]=J[1],W[14]=J[2],W[15]=1,W}}function Bg(J,X){if(!!J!==!!X)return!1;let Y=J.getChild(),Z=X.getChild();return Y===Z||Y.equals(Z)}function jg(J,X){if(!!J!==!!X)return!1;let Y=J.values(),Z=X.values();if(Y.length!==Z.length)return!1;for(let W=0;W<Y.length;W++){let $=Y[W],Q=Z[W];if($.getChild()===Q.getChild())continue;if(!$.getChild().equals(Q.getChild()))return!1}return!0}function kg(J,X){if(!!J!==!!X)return!1;let Y=J.keys(),Z=X.keys();if(Y.length!==Z.length)return!1;for(let W of Y){let $=J.get(W),Q=X.get(W);if(!!$!==!!Q)return!1;let K=$.getChild(),G=Q.getChild();if(K===G)continue;if(!K.equals(G))return!1}return!0}function yR(J,X){if(J===X)return!0;if(!!J!==!!X||!J||!X)return!1;if(J.length!==X.length)return!1;for(let Y=0;Y<J.length;Y++)if(J[Y]!==X[Y])return!1;return!0}function gR(J,X){if(J===X)return!0;if(!!J!==!!X)return!1;if(!K9(J)||!K9(X))return J===X;let Y=J,Z=X,W=0,$=0,Q;for(Q in Y)W++;for(Q in Z)$++;if(W!==$)return!1;for(Q in Y){let K=Y[Q],G=Z[Q];if(cY(K)&&cY(G)){if(!yR(K,G))return!1}else if(K9(K)&&K9(G)){if(!gR(K,G))return!1}else if(K!==G)return!1}return!0}function cY(J){return Array.isArray(J)||ArrayBuffer.isView(J)}var ER="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",Tg=999,Dg=6,CR=new Set,_g=function J(){let X="";for(let Y=0;Y<Dg;Y++)X+=ER.charAt(Math.floor(Math.random()*ER.length));return X},cR=function J(){for(let X=0;X<Tg;X++){let Y=_g();if(!CR.has(Y))return CR.add(Y),Y}return""},SR="https://null.example";class r8{static dirname(J){let X=J.lastIndexOf("/");if(X===-1)return"./";return J.substring(0,X+1)}static basename(J){return Q1.basename(new URL(J,SR).pathname)}static extension(J){return Q1.extension(new URL(J,SR).pathname)}static resolve(J,X){if(!this.isRelativePath(X))return X;let Y=J.split("/"),Z=X.split("/");Y.pop();for(let W=0;W<Z.length;W++){if(Z[W]===".")continue;if(Z[W]==="..")Y.pop();else Y.push(Z[W])}return Y.join("/")}static isAbsoluteURL(J){return this.PROTOCOL_REGEXP.test(J)}static isRelativePath(J){return!/^(?:[a-zA-Z]+:)?\//.test(J)}}r8.DEFAULT_INIT={};r8.PROTOCOL_REGEXP=/^[a-zA-Z]+:\/\//;var _1=(J)=>J,Eg=new Set;class uY extends SY{constructor(J,X=""){super(J);this[L0].name=X,this.init(),this.dispatchEvent({type:"create"})}getGraph(){return this.graph}getDefaults(){return Object.assign(super.getDefaults(),{name:"",extras:{}})}set(J,X){if(Array.isArray(X))X=X.slice();return super.set(J,X)}getName(){return this.get("name")}setName(J){return this.set("name",J)}getExtras(){return this.get("extras")}setExtras(J){return this.set("extras",J)}clone(){return new this.constructor(this.graph).copy(this,_1)}copy(J,X=_1){for(let Y in this[L0]){let Z=this[L0][Y];if(Z instanceof T1){if(!this[k1].has(Y))Z.dispose()}else if(Z instanceof I6||Z instanceof _0)for(let W of Z.values())W.dispose();else if(Z instanceof o8)for(let W of Z.values())W.dispose()}for(let Y in J[L0]){let Z=this[L0][Y],W=J[L0][Y];if(W instanceof T1)if(this[k1].has(Y))Z.getChild().copy(X(W.getChild()),X);else this.setRef(Y,X(W.getChild()),W.getAttributes());else if(W instanceof _0||W instanceof I6)for(let $ of W.values())this.addRef(Y,X($.getChild()),$.getAttributes());else if(W instanceof o8)for(let $ of W.keys()){let Q=W.get($);this.setRefMap(Y,$,X(Q.getChild()),Q.getAttributes())}else if(K9(W))this[L0][Y]=JSON.parse(JSON.stringify(W));else if(Array.isArray(W)||W instanceof ArrayBuffer||ArrayBuffer.isView(W))this[L0][Y]=W.slice();else this[L0][Y]=W}return this}equals(J,X=Eg){if(this===J)return!0;if(this.propertyType!==J.propertyType)return!1;for(let Y in this[L0]){if(X.has(Y))continue;let Z=this[L0][Y],W=J[L0][Y];if(Z instanceof T1||W instanceof T1){if(!Bg(Z,W))return!1}else if(Z instanceof _0||W instanceof _0||Z instanceof I6||W instanceof I6){if(!jg(Z,W))return!1}else if(Z instanceof o8||W instanceof o8){if(!kg(Z,W))return!1}else if(K9(Z)||K9(W)){if(!gR(Z,W))return!1}else if(cY(Z)||cY(W)){if(!yR(Z,W))return!1}else if(Z!==W)return!1}return!0}detach(){return this.graph.disconnectParents(this,(J)=>J.propertyType!=="Root"),this}listParents(){return this.graph.listParents(this)}}class V8 extends uY{getDefaults(){return Object.assign(super.getDefaults(),{extensions:new o8})}getExtension(J){return this.getRefMap("extensions",J)}setExtension(J,X){if(X)X._validateParent(this);return this.setRefMap("extensions",J,X)}listExtensions(){return this.listRefMapValues("extensions")}}class i extends V8{init(){this.propertyType=p.ACCESSOR}getDefaults(){return Object.assign(super.getDefaults(),{array:null,type:i.Type.SCALAR,componentType:i.ComponentType.FLOAT,normalized:!1,sparse:!1,buffer:null})}static getElementSize(J){switch(J){case i.Type.SCALAR:return 1;case i.Type.VEC2:return 2;case i.Type.VEC3:return 3;case i.Type.VEC4:return 4;case i.Type.MAT2:return 4;case i.Type.MAT3:return 9;case i.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+J)}}static getComponentSize(J){switch(J){case i.ComponentType.BYTE:return 1;case i.ComponentType.UNSIGNED_BYTE:return 1;case i.ComponentType.SHORT:return 2;case i.ComponentType.UNSIGNED_SHORT:return 2;case i.ComponentType.UNSIGNED_INT:return 4;case i.ComponentType.FLOAT:return 4;default:throw new Error("Unexpected component type: "+J)}}getMinNormalized(J){let X=this.getNormalized(),Y=this.getElementSize(),Z=this.getComponentType();if(this.getMin(J),X)for(let W=0;W<Y;W++)J[W]=b0.decodeNormalizedInt(J[W],Z);return J}getMin(J){let X=this.getArray(),Y=this.getCount(),Z=this.getElementSize();for(let W=0;W<Z;W++)J[W]=1/0;for(let W=0;W<Y*Z;W+=Z)for(let $=0;$<Z;$++){let Q=X[W+$];if(Number.isFinite(Q))J[$]=Math.min(J[$],Q)}return J}getMaxNormalized(J){let X=this.getNormalized(),Y=this.getElementSize(),Z=this.getComponentType();if(this.getMax(J),X)for(let W=0;W<Y;W++)J[W]=b0.decodeNormalizedInt(J[W],Z);return J}getMax(J){let X=this.get("array"),Y=this.getCount(),Z=this.getElementSize();for(let W=0;W<Z;W++)J[W]=-1/0;for(let W=0;W<Y*Z;W+=Z)for(let $=0;$<Z;$++){let Q=X[W+$];if(Number.isFinite(Q))J[$]=Math.max(J[$],Q)}return J}getCount(){let J=this.get("array");return J?J.length/this.getElementSize():0}getType(){return this.get("type")}setType(J){return this.set("type",J)}getElementSize(){return i.getElementSize(this.get("type"))}getComponentSize(){return this.get("array").BYTES_PER_ELEMENT}getComponentType(){return this.get("componentType")}getNormalized(){return this.get("normalized")}setNormalized(J){return this.set("normalized",J)}getScalar(J){let X=this.getElementSize(),Y=this.getComponentType(),Z=this.getArray();if(this.getNormalized())return b0.decodeNormalizedInt(Z[J*X],Y);return Z[J*X]}setScalar(J,X){let Y=this.getElementSize(),Z=this.getComponentType(),W=this.getArray();if(this.getNormalized())W[J*Y]=b0.encodeNormalizedInt(X,Z);else W[J*Y]=X;return this}getElement(J,X){let Y=this.getNormalized(),Z=this.getElementSize(),W=this.getComponentType(),$=this.getArray();for(let Q=0;Q<Z;Q++)if(Y)X[Q]=b0.decodeNormalizedInt($[J*Z+Q],W);else X[Q]=$[J*Z+Q];return X}setElement(J,X){let Y=this.getNormalized(),Z=this.getElementSize(),W=this.getComponentType(),$=this.getArray();for(let Q=0;Q<Z;Q++)if(Y)$[J*Z+Q]=b0.encodeNormalizedInt(X[Q],W);else $[J*Z+Q]=X[Q];return this}getSparse(){return this.get("sparse")}setSparse(J){return this.set("sparse",J)}getBuffer(){return this.getRef("buffer")}setBuffer(J){return this.setRef("buffer",J)}getArray(){return this.get("array")}setArray(J){return this.set("componentType",J?Cg(J):i.ComponentType.FLOAT),this.set("array",J),this}getByteLength(){let J=this.get("array");return J?J.byteLength:0}}i.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"};i.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126};function Cg(J){switch(J.constructor){case Float32Array:return i.ComponentType.FLOAT;case Uint32Array:return i.ComponentType.UNSIGNED_INT;case Uint16Array:return i.ComponentType.UNSIGNED_SHORT;case Uint8Array:return i.ComponentType.UNSIGNED_BYTE;case Int16Array:return i.ComponentType.SHORT;case Int8Array:return i.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}class WG extends V8{init(){this.propertyType=p.ANIMATION}getDefaults(){return Object.assign(super.getDefaults(),{channels:new _0,samplers:new _0})}addChannel(J){return this.addRef("channels",J)}removeChannel(J){return this.removeRef("channels",J)}listChannels(){return this.listRefs("channels")}addSampler(J){return this.addRef("samplers",J)}removeSampler(J){return this.removeRef("samplers",J)}listSamplers(){return this.listRefs("samplers")}}class l4 extends V8{init(){this.propertyType=p.ANIMATION_CHANNEL}getDefaults(){return Object.assign(super.getDefaults(),{targetPath:null,targetNode:null,sampler:null})}getTargetPath(){return this.get("targetPath")}setTargetPath(J){return this.set("targetPath",J)}getTargetNode(){return this.getRef("targetNode")}setTargetNode(J){return this.setRef("targetNode",J)}getSampler(){return this.getRef("sampler")}setSampler(J){return this.setRef("sampler",J)}}l4.TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"};class $5 extends V8{init(){this.propertyType=p.ANIMATION_SAMPLER}getDefaultAttributes(){return Object.assign(super.getDefaults(),{interpolation:$5.Interpolation.LINEAR,input:null,output:null})}getInterpolation(){return this.get("interpolation")}setInterpolation(J){return this.set("interpolation",J)}getInput(){return this.getRef("input")}setInput(J){return this.setRef("input",J,{usage:u8.OTHER})}getOutput(){return this.getRef("output")}setOutput(J){return this.setRef("output",J,{usage:u8.OTHER})}}$5.Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"};class $G extends V8{init(){this.propertyType=p.BUFFER}getDefaults(){return Object.assign(super.getDefaults(),{uri:""})}getURI(){return this.get("uri")}setURI(J){return this.set("uri",J)}}class G9 extends V8{init(){this.propertyType=p.CAMERA}getDefaults(){return Object.assign(super.getDefaults(),{type:G9.Type.PERSPECTIVE,znear:0.1,zfar:100,aspectRatio:null,yfov:Math.PI*2*50/360,xmag:1,ymag:1})}getType(){return this.get("type")}setType(J){return this.set("type",J)}getZNear(){return this.get("znear")}setZNear(J){return this.set("znear",J)}getZFar(){return this.get("zfar")}setZFar(J){return this.set("zfar",J)}getAspectRatio(){return this.get("aspectRatio")}setAspectRatio(J){return this.set("aspectRatio",J)}getYFov(){return this.get("yfov")}setYFov(J){return this.set("yfov",J)}getXMag(){return this.get("xmag")}setXMag(J){return this.set("xmag",J)}getYMag(){return this.get("ymag")}setYMag(J){return this.set("ymag",J)}}G9.Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};class dY extends uY{_validateParent(J){if(!this.parentTypes.includes(J.propertyType))throw new Error(`Parent "${J.propertyType}" invalid for child "${this.propertyType}".`)}}dY.EXTENSION_NAME=void 0;class t8 extends V8{init(){this.propertyType=p.TEXTURE_INFO}getDefaults(){return Object.assign(super.getDefaults(),{texCoord:0,magFilter:null,minFilter:null,wrapS:t8.WrapMode.REPEAT,wrapT:t8.WrapMode.REPEAT})}getTexCoord(){return this.get("texCoord")}setTexCoord(J){return this.set("texCoord",J)}getMagFilter(){return this.get("magFilter")}setMagFilter(J){return this.set("magFilter",J)}getMinFilter(){return this.get("minFilter")}setMinFilter(J){return this.set("minFilter",J)}getWrapS(){return this.get("wrapS")}setWrapS(J){return this.set("wrapS",J)}getWrapT(){return this.get("wrapT")}setWrapT(J){return this.set("wrapT",J)}}t8.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497};t8.MagFilter={NEAREST:9728,LINEAR:9729};t8.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var{R:IY,G:hY,B:fY,A:Sg}=gY;class E1 extends V8{init(){this.propertyType=p.MATERIAL}getDefaults(){return Object.assign(super.getDefaults(),{alphaMode:E1.AlphaMode.OPAQUE,alphaCutoff:0.5,doubleSided:!1,baseColorFactor:[1,1,1,1],baseColorTexture:null,baseColorTextureInfo:new t8(this.graph,"baseColorTextureInfo"),emissiveFactor:[0,0,0],emissiveTexture:null,emissiveTextureInfo:new t8(this.graph,"emissiveTextureInfo"),normalScale:1,normalTexture:null,normalTextureInfo:new t8(this.graph,"normalTextureInfo"),occlusionStrength:1,occlusionTexture:null,occlusionTextureInfo:new t8(this.graph,"occlusionTextureInfo"),roughnessFactor:1,metallicFactor:1,metallicRoughnessTexture:null,metallicRoughnessTextureInfo:new t8(this.graph,"metallicRoughnessTextureInfo")})}getDoubleSided(){return this.get("doubleSided")}setDoubleSided(J){return this.set("doubleSided",J)}getAlpha(){return this.get("baseColorFactor")[3]}setAlpha(J){let X=this.get("baseColorFactor").slice();return X[3]=J,this.set("baseColorFactor",X)}getAlphaMode(){return this.get("alphaMode")}setAlphaMode(J){return this.set("alphaMode",J)}getAlphaCutoff(){return this.get("alphaCutoff")}setAlphaCutoff(J){return this.set("alphaCutoff",J)}getBaseColorFactor(){return this.get("baseColorFactor")}setBaseColorFactor(J){return this.set("baseColorFactor",J)}getBaseColorTexture(){return this.getRef("baseColorTexture")}getBaseColorTextureInfo(){return this.getRef("baseColorTexture")?this.getRef("baseColorTextureInfo"):null}setBaseColorTexture(J){return this.setRef("baseColorTexture",J,{channels:IY|hY|fY|Sg,isColor:!0})}getEmissiveFactor(){return this.get("emissiveFactor")}setEmissiveFactor(J){return this.set("emissiveFactor",J)}getEmissiveTexture(){return this.getRef("emissiveTexture")}getEmissiveTextureInfo(){return this.getRef("emissiveTexture")?this.getRef("emissiveTextureInfo"):null}setEmissiveTexture(J){return this.setRef("emissiveTexture",J,{channels:IY|hY|fY,isColor:!0})}getNormalScale(){return this.get("normalScale")}setNormalScale(J){return this.set("normalScale",J)}getNormalTexture(){return this.getRef("normalTexture")}getNormalTextureInfo(){return this.getRef("normalTexture")?this.getRef("normalTextureInfo"):null}setNormalTexture(J){return this.setRef("normalTexture",J,{channels:IY|hY|fY})}getOcclusionStrength(){return this.get("occlusionStrength")}setOcclusionStrength(J){return this.set("occlusionStrength",J)}getOcclusionTexture(){return this.getRef("occlusionTexture")}getOcclusionTextureInfo(){return this.getRef("occlusionTexture")?this.getRef("occlusionTextureInfo"):null}setOcclusionTexture(J){return this.setRef("occlusionTexture",J,{channels:IY})}getRoughnessFactor(){return this.get("roughnessFactor")}setRoughnessFactor(J){return this.set("roughnessFactor",J)}getMetallicFactor(){return this.get("metallicFactor")}setMetallicFactor(J){return this.set("metallicFactor",J)}getMetallicRoughnessTexture(){return this.getRef("metallicRoughnessTexture")}getMetallicRoughnessTextureInfo(){return this.getRef("metallicRoughnessTexture")?this.getRef("metallicRoughnessTextureInfo"):null}setMetallicRoughnessTexture(J){return this.setRef("metallicRoughnessTexture",J,{channels:hY|fY})}}E1.AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};class iY extends V8{init(){this.propertyType=p.MESH}getDefaults(){return Object.assign(super.getDefaults(),{weights:[],primitives:new _0})}addPrimitive(J){return this.addRef("primitives",J)}removePrimitive(J){return this.removeRef("primitives",J)}listPrimitives(){return this.listRefs("primitives")}getWeights(){return this.get("weights")}setWeights(J){return this.set("weights",J)}}class nY extends V8{init(){this.propertyType=p.NODE}getDefaults(){return Object.assign(super.getDefaults(),{translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1],weights:[],camera:null,mesh:null,skin:null,children:new _0})}copy(J,X=_1){if(X===_1)throw new Error("Node cannot be copied.");return super.copy(J,X)}getTranslation(){return this.get("translation")}getRotation(){return this.get("rotation")}getScale(){return this.get("scale")}setTranslation(J){return this.set("translation",J)}setRotation(J){return this.set("rotation",J)}setScale(J){return this.set("scale",J)}getMatrix(){return b0.compose(this.get("translation"),this.get("rotation"),this.get("scale"),[])}setMatrix(J){let X=this.get("translation").slice(),Y=this.get("rotation").slice(),Z=this.get("scale").slice();return b0.decompose(J,X,Y,Z),this.set("translation",X).set("rotation",Y).set("scale",Z)}getWorldTranslation(){let J=[0,0,0];return b0.decompose(this.getWorldMatrix(),J,[0,0,0,1],[1,1,1]),J}getWorldRotation(){let J=[0,0,0,1];return b0.decompose(this.getWorldMatrix(),[0,0,0],J,[1,1,1]),J}getWorldScale(){let J=[1,1,1];return b0.decompose(this.getWorldMatrix(),[0,0,0],[0,0,0,1],J),J}getWorldMatrix(){let J=[];for(let Z=this;Z!=null;Z=Z.getParentNode())J.push(Z);let X,Y=J.pop().getMatrix();while(X=J.pop())Pg(Y,Y,X.getMatrix());return Y}addChild(J){let X=J.getParentNode();if(X)X.removeChild(J);for(let Y of J.listParents())if(Y.propertyType===p.SCENE)Y.removeChild(J);return this.addRef("children",J)}removeChild(J){return this.removeRef("children",J)}listChildren(){return this.listRefs("children")}getParentNode(){for(let J of this.listParents())if(J.propertyType===p.NODE)return J;return null}getMesh(){return this.getRef("mesh")}setMesh(J){return this.setRef("mesh",J)}getCamera(){return this.getRef("camera")}setCamera(J){return this.setRef("camera",J)}getSkin(){return this.getRef("skin")}setSkin(J){return this.setRef("skin",J)}getWeights(){return this.get("weights")}setWeights(J){return this.set("weights",J)}traverse(J){J(this);for(let X of this.listChildren())X.traverse(J);return this}}class K1 extends V8{init(){this.propertyType=p.PRIMITIVE}getDefaults(){return Object.assign(super.getDefaults(),{mode:K1.Mode.TRIANGLES,material:null,indices:null,attributes:new o8,targets:new _0})}getIndices(){return this.getRef("indices")}setIndices(J){return this.setRef("indices",J,{usage:u8.ELEMENT_ARRAY_BUFFER})}getAttribute(J){return this.getRefMap("attributes",J)}setAttribute(J,X){return this.setRefMap("attributes",J,X,{usage:u8.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}getMaterial(){return this.getRef("material")}setMaterial(J){return this.setRef("material",J)}getMode(){return this.get("mode")}setMode(J){return this.set("mode",J)}listTargets(){return this.listRefs("targets")}addTarget(J){return this.addRef("targets",J)}removeTarget(J){return this.removeRef("targets",J)}}K1.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6};class QG extends uY{init(){this.propertyType=p.PRIMITIVE_TARGET}getDefaults(){return Object.assign(super.getDefaults(),{attributes:new o8})}getAttribute(J){return this.getRefMap("attributes",J)}setAttribute(J,X){return this.setRefMap("attributes",J,X,{usage:u8.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}function P8(){return P8=Object.assign?Object.assign.bind():function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)({}).hasOwnProperty.call(Y,Z)&&(J[Z]=Y[Z])}return J},P8.apply(null,arguments)}class aY extends V8{init(){this.propertyType=p.SCENE}getDefaults(){return Object.assign(super.getDefaults(),{children:new _0})}copy(J,X=_1){if(X===_1)throw new Error("Scene cannot be copied.");return super.copy(J,X)}addChild(J){let X=J.getParentNode();if(X)X.removeChild(J);return this.addRef("children",J)}removeChild(J){return this.removeRef("children",J)}listChildren(){return this.listRefs("children")}traverse(J){for(let X of this.listChildren())X.traverse(J);return this}}class KG extends V8{init(){this.propertyType=p.SKIN}getDefaults(){return Object.assign(super.getDefaults(),{skeleton:null,inverseBindMatrices:null,joints:new _0})}getSkeleton(){return this.getRef("skeleton")}setSkeleton(J){return this.setRef("skeleton",J)}getInverseBindMatrices(){return this.getRef("inverseBindMatrices")}setInverseBindMatrices(J){return this.setRef("inverseBindMatrices",J,{usage:u8.INVERSE_BIND_MATRICES})}addJoint(J){return this.addRef("joints",J)}removeJoint(J){return this.removeRef("joints",J)}listJoints(){return this.listRefs("joints")}}class sY extends V8{init(){this.propertyType=p.TEXTURE}getDefaults(){return Object.assign(super.getDefaults(),{image:null,mimeType:"",uri:""})}getMimeType(){return this.get("mimeType")||$1.extensionToMimeType(Q1.extension(this.get("uri")))}setMimeType(J){return this.set("mimeType",J)}getURI(){return this.get("uri")}setURI(J){this.set("uri",J);let X=$1.extensionToMimeType(Q1.extension(J));if(X)this.set("mimeType",X);return this}getImage(){return this.get("image")}setImage(J){return this.set("image",G0.assertView(J))}getSize(){let J=this.get("image");if(!J)return null;return $1.getSize(J,this.getMimeType())}}class GG extends V8{init(){this.propertyType=p.ROOT}getDefaults(){return Object.assign(super.getDefaults(),{asset:{generator:`glTF-Transform ${fR}`,version:"2.0"},defaultScene:null,accessors:new _0,animations:new _0,buffers:new _0,cameras:new _0,materials:new _0,meshes:new _0,nodes:new _0,scenes:new _0,skins:new _0,textures:new _0})}constructor(J){super(J);this._extensions=new Set,J.addEventListener("node:create",(X)=>{this._addChildOfRoot(X.target)})}clone(){throw new Error("Root cannot be cloned.")}copy(J,X=_1){if(X===_1)throw new Error("Root cannot be copied.");this.set("asset",P8({},J.get("asset"))),this.setName(J.getName()),this.setExtras(P8({},J.getExtras())),this.setDefaultScene(J.getDefaultScene()?X(J.getDefaultScene()):null);for(let Y of J.listRefMapKeys("extensions")){let Z=J.getExtension(Y);this.setExtension(Y,X(Z))}return this}_addChildOfRoot(J){if(J instanceof aY)this.addRef("scenes",J);else if(J instanceof nY)this.addRef("nodes",J);else if(J instanceof G9)this.addRef("cameras",J);else if(J instanceof KG)this.addRef("skins",J);else if(J instanceof iY)this.addRef("meshes",J);else if(J instanceof E1)this.addRef("materials",J);else if(J instanceof sY)this.addRef("textures",J);else if(J instanceof WG)this.addRef("animations",J);else if(J instanceof i)this.addRef("accessors",J);else if(J instanceof $G)this.addRef("buffers",J);return this}getAsset(){return this.get("asset")}listExtensionsUsed(){return Array.from(this._extensions)}listExtensionsRequired(){return this.listExtensionsUsed().filter((J)=>J.isRequired())}_enableExtension(J){return this._extensions.add(J),this}_disableExtension(J){return this._extensions.delete(J),this}listScenes(){return this.listRefs("scenes")}setDefaultScene(J){return this.setRef("defaultScene",J)}getDefaultScene(){return this.getRef("defaultScene")}listNodes(){return this.listRefs("nodes")}listCameras(){return this.listRefs("cameras")}listSkins(){return this.listRefs("skins")}listMeshes(){return this.listRefs("meshes")}listMaterials(){return this.listRefs("materials")}listTextures(){return this.listRefs("textures")}listAnimations(){return this.listRefs("animations")}listAccessors(){return this.listRefs("accessors")}listBuffers(){return this.listRefs("buffers")}}class W5{static fromGraph(J){return W5._GRAPH_DOCUMENTS.get(J)||null}constructor(){this._graph=new rK,this._root=new GG(this._graph),this._logger=e8.DEFAULT_INSTANCE,W5._GRAPH_DOCUMENTS.set(this._graph,this)}getRoot(){return this._root}getGraph(){return this._graph}getLogger(){return this._logger}setLogger(J){return this._logger=J,this}clone(){throw new Error("Use 'cloneDocument(source)' from '@gltf-transform/functions'.")}merge(J){throw new Error("Use 'mergeDocuments(target, source)' from '@gltf-transform/functions'.")}async transform(...J){let X=J.map((Y)=>Y.name);for(let Y of J)await Y(this,{stack:X});return this}createExtension(J){let X=J.EXTENSION_NAME;return this.getRoot().listExtensionsUsed().find((Z)=>Z.extensionName===X)||new J(this)}createScene(J=""){return new aY(this._graph,J)}createNode(J=""){return new nY(this._graph,J)}createCamera(J=""){return new G9(this._graph,J)}createSkin(J=""){return new KG(this._graph,J)}createMesh(J=""){return new iY(this._graph,J)}createPrimitive(){return new K1(this._graph)}createPrimitiveTarget(J=""){return new QG(this._graph,J)}createMaterial(J=""){return new E1(this._graph,J)}createTexture(J=""){return new sY(this._graph,J)}createAnimation(J=""){return new WG(this._graph,J)}createAnimationChannel(J=""){return new l4(this._graph,J)}createAnimationSampler(J=""){return new $5(this._graph,J)}createAccessor(J="",X=null){if(!X)X=this.getRoot().listBuffers()[0];return new i(this._graph,J).setBuffer(X)}createBuffer(J=""){return new $G(this._graph,J)}}W5._GRAPH_DOCUMENTS=new WeakMap;class mR{constructor(J){this.extensionName="",this.prereadTypes=[],this.prewriteTypes=[],this.readDependencies=[],this.writeDependencies=[],this.document=void 0,this.required=!1,this.properties=new Set,this._listener=void 0,this.document=J,J.getRoot()._enableExtension(this),this._listener=(Y)=>{let Z=Y,W=Z.target;if(W instanceof dY&&W.extensionName===this.extensionName){if(Z.type==="node:create")this._addExtensionProperty(W);if(Z.type==="node:dispose")this._removeExtensionProperty(W)}};let X=J.getGraph();X.addEventListener("node:create",this._listener),X.addEventListener("node:dispose",this._listener)}dispose(){this.document.getRoot()._disableExtension(this);let J=this.document.getGraph();J.removeEventListener("node:create",this._listener),J.removeEventListener("node:dispose",this._listener);for(let X of this.properties)X.dispose()}static register(){}isRequired(){return this.required}setRequired(J){return this.required=J,this}listProperties(){return Array.from(this.properties)}_addExtensionProperty(J){return this.properties.add(J),this}_removeExtensionProperty(J){return this.properties.delete(J),this}install(J,X){return this}preread(J,X){return this}prewrite(J,X){return this}}mR.EXTENSION_NAME=void 0;class lR{constructor(J){this.jsonDoc=void 0,this.buffers=[],this.bufferViews=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[],this.jsonDoc=J}setTextureInfo(J,X){if(this.textureInfos.set(J,X),X.texCoord!==void 0)J.setTexCoord(X.texCoord);if(X.extras!==void 0)J.setExtras(X.extras);let Y=this.jsonDoc.json.textures[X.index];if(Y.sampler===void 0)return;let Z=this.jsonDoc.json.samplers[Y.sampler];if(Z.magFilter!==void 0)J.setMagFilter(Z.magFilter);if(Z.minFilter!==void 0)J.setMinFilter(Z.minFilter);if(Z.wrapS!==void 0)J.setWrapS(Z.wrapS);if(Z.wrapT!==void 0)J.setWrapT(Z.wrapT)}}var IR={logger:e8.DEFAULT_INSTANCE,extensions:[],dependencies:{}},Ig=new Set([p.BUFFER,p.TEXTURE,p.MATERIAL,p.MESH,p.PRIMITIVE,p.NODE,p.SCENE]);class uR{static read(J,X=IR){let Y=P8({},IR,X),{json:Z}=J,W=new W5().setLogger(Y.logger);this.validate(J,Y);let $=new lR(J),Q=Z.asset,K=W.getRoot().getAsset();if(Q.copyright)K.copyright=Q.copyright;if(Q.extras)K.extras=Q.extras;if(Z.extras!==void 0)W.getRoot().setExtras(P8({},Z.extras));let G=Z.extensionsUsed||[],F=Z.extensionsRequired||[];Y.extensions.sort((O,D)=>O.EXTENSION_NAME>D.EXTENSION_NAME?1:-1);for(let O of Y.extensions)if(G.includes(O.EXTENSION_NAME)){let D=W.createExtension(O).setRequired(F.includes(O.EXTENSION_NAME)),_=D.prereadTypes.filter((C)=>!Ig.has(C));if(_.length)Y.logger.warn(`Preread hooks for some types (${_.join()}), requested by extension ${D.extensionName}, are unsupported. Please file an issue or a PR.`);for(let C of D.readDependencies)D.install(C,Y.dependencies[C])}let q=Z.buffers||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.BUFFER)).forEach((O)=>O.preread($,p.BUFFER)),$.buffers=q.map((O)=>{let D=W.createBuffer(O.name);if(O.extras)D.setExtras(O.extras);if(O.uri&&O.uri.indexOf("__")!==0)D.setURI(O.uri);return D});let H=Z.bufferViews||[];$.bufferViewBuffers=H.map((O,D)=>{if(!$.bufferViews[D]){let _=J.json.buffers[O.buffer],C=_.uri?J.resources[_.uri]:J.resources[AY],S=O.byteOffset||0;$.bufferViews[D]=G0.toView(C,S,O.byteLength)}return $.buffers[O.buffer]});let z=Z.accessors||[];$.accessors=z.map((O)=>{let D=$.bufferViewBuffers[O.bufferView],_=W.createAccessor(O.name,D).setType(O.type);if(O.extras)_.setExtras(O.extras);if(O.normalized!==void 0)_.setNormalized(O.normalized);if(O.bufferView===void 0)return _;return _.setArray(pY(O,$)),_});let V=Z.images||[],M=Z.textures||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.TEXTURE)).forEach((O)=>O.preread($,p.TEXTURE)),$.textures=V.map((O)=>{let D=W.createTexture(O.name);if(O.extras)D.setExtras(O.extras);if(O.bufferView!==void 0){let _=Z.bufferViews[O.bufferView],C=J.json.buffers[_.buffer],S=C.uri?J.resources[C.uri]:J.resources[AY],I=_.byteOffset||0,f=_.byteLength,y=S.slice(I,I+f);D.setImage(y)}else if(O.uri!==void 0){if(D.setImage(J.resources[O.uri]),O.uri.indexOf("__")!==0)D.setURI(O.uri)}if(O.mimeType!==void 0)D.setMimeType(O.mimeType);else if(O.uri){let _=Q1.extension(O.uri);D.setMimeType($1.extensionToMimeType(_))}return D}),W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.MATERIAL)).forEach((O)=>O.preread($,p.MATERIAL));let R=Z.materials||[];$.materials=R.map((O)=>{let D=W.createMaterial(O.name);if(O.extras)D.setExtras(O.extras);if(O.alphaMode!==void 0)D.setAlphaMode(O.alphaMode);if(O.alphaCutoff!==void 0)D.setAlphaCutoff(O.alphaCutoff);if(O.doubleSided!==void 0)D.setDoubleSided(O.doubleSided);let _=O.pbrMetallicRoughness||{};if(_.baseColorFactor!==void 0)D.setBaseColorFactor(_.baseColorFactor);if(O.emissiveFactor!==void 0)D.setEmissiveFactor(O.emissiveFactor);if(_.metallicFactor!==void 0)D.setMetallicFactor(_.metallicFactor);if(_.roughnessFactor!==void 0)D.setRoughnessFactor(_.roughnessFactor);if(_.baseColorTexture!==void 0){let C=_.baseColorTexture,S=$.textures[M[C.index].source];D.setBaseColorTexture(S),$.setTextureInfo(D.getBaseColorTextureInfo(),C)}if(O.emissiveTexture!==void 0){let C=O.emissiveTexture,S=$.textures[M[C.index].source];D.setEmissiveTexture(S),$.setTextureInfo(D.getEmissiveTextureInfo(),C)}if(O.normalTexture!==void 0){let C=O.normalTexture,S=$.textures[M[C.index].source];if(D.setNormalTexture(S),$.setTextureInfo(D.getNormalTextureInfo(),C),O.normalTexture.scale!==void 0)D.setNormalScale(O.normalTexture.scale)}if(O.occlusionTexture!==void 0){let C=O.occlusionTexture,S=$.textures[M[C.index].source];if(D.setOcclusionTexture(S),$.setTextureInfo(D.getOcclusionTextureInfo(),C),O.occlusionTexture.strength!==void 0)D.setOcclusionStrength(O.occlusionTexture.strength)}if(_.metallicRoughnessTexture!==void 0){let C=_.metallicRoughnessTexture,S=$.textures[M[C.index].source];D.setMetallicRoughnessTexture(S),$.setTextureInfo(D.getMetallicRoughnessTextureInfo(),C)}return D}),W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.MESH)).forEach((O)=>O.preread($,p.MESH));let L=Z.meshes||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.PRIMITIVE)).forEach((O)=>O.preread($,p.PRIMITIVE)),$.meshes=L.map((O)=>{let D=W.createMesh(O.name);if(O.extras)D.setExtras(O.extras);if(O.weights!==void 0)D.setWeights(O.weights);return(O.primitives||[]).forEach((C)=>{let S=W.createPrimitive();if(C.extras)S.setExtras(C.extras);if(C.material!==void 0)S.setMaterial($.materials[C.material]);if(C.mode!==void 0)S.setMode(C.mode);for(let[y,h]of Object.entries(C.attributes||{}))S.setAttribute(y,$.accessors[h]);if(C.indices!==void 0)S.setIndices($.accessors[C.indices]);let I=O.extras&&O.extras.targetNames||[];(C.targets||[]).forEach((y,h)=>{let g=I[h]||h.toString(),J0=W.createPrimitiveTarget(g);for(let[p0,a0]of Object.entries(y))J0.setAttribute(p0,$.accessors[a0]);S.addTarget(J0)}),D.addPrimitive(S)}),D});let w=Z.cameras||[];$.cameras=w.map((O)=>{let D=W.createCamera(O.name).setType(O.type);if(O.extras)D.setExtras(O.extras);if(O.type===G9.Type.PERSPECTIVE){let _=O.perspective;if(D.setYFov(_.yfov),D.setZNear(_.znear),_.zfar!==void 0)D.setZFar(_.zfar);if(_.aspectRatio!==void 0)D.setAspectRatio(_.aspectRatio)}else{let _=O.orthographic;D.setZNear(_.znear).setZFar(_.zfar).setXMag(_.xmag).setYMag(_.ymag)}return D});let P=Z.nodes||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.NODE)).forEach((O)=>O.preread($,p.NODE)),$.nodes=P.map((O)=>{let D=W.createNode(O.name);if(O.extras)D.setExtras(O.extras);if(O.translation!==void 0)D.setTranslation(O.translation);if(O.rotation!==void 0)D.setRotation(O.rotation);if(O.scale!==void 0)D.setScale(O.scale);if(O.matrix!==void 0){let _=[0,0,0],C=[0,0,0,1],S=[1,1,1];b0.decompose(O.matrix,_,C,S),D.setTranslation(_),D.setRotation(C),D.setScale(S)}if(O.weights!==void 0)D.setWeights(O.weights);return D});let N=Z.skins||[];$.skins=N.map((O)=>{let D=W.createSkin(O.name);if(O.extras)D.setExtras(O.extras);if(O.inverseBindMatrices!==void 0)D.setInverseBindMatrices($.accessors[O.inverseBindMatrices]);if(O.skeleton!==void 0)D.setSkeleton($.nodes[O.skeleton]);for(let _ of O.joints)D.addJoint($.nodes[_]);return D}),P.map((O,D)=>{let _=$.nodes[D];if((O.children||[]).forEach((S)=>_.addChild($.nodes[S])),O.mesh!==void 0)_.setMesh($.meshes[O.mesh]);if(O.camera!==void 0)_.setCamera($.cameras[O.camera]);if(O.skin!==void 0)_.setSkin($.skins[O.skin])});let v=Z.animations||[];$.animations=v.map((O)=>{let D=W.createAnimation(O.name);if(O.extras)D.setExtras(O.extras);let C=(O.samplers||[]).map((I)=>{let f=W.createAnimationSampler().setInput($.accessors[I.input]).setOutput($.accessors[I.output]).setInterpolation(I.interpolation||$5.Interpolation.LINEAR);if(I.extras)f.setExtras(I.extras);return D.addSampler(f),f});return(O.channels||[]).forEach((I)=>{let f=W.createAnimationChannel().setSampler(C[I.sampler]).setTargetPath(I.target.path);if(I.target.node!==void 0)f.setTargetNode($.nodes[I.target.node]);if(I.extras)f.setExtras(I.extras);D.addChannel(f)}),D});let j=Z.scenes||[];if(W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.SCENE)).forEach((O)=>O.preread($,p.SCENE)),$.scenes=j.map((O)=>{let D=W.createScene(O.name);if(O.extras)D.setExtras(O.extras);return(O.nodes||[]).map((C)=>$.nodes[C]).forEach((C)=>D.addChild(C)),D}),Z.scene!==void 0)W.getRoot().setDefaultScene($.scenes[Z.scene]);return W.getRoot().listExtensionsUsed().forEach((O)=>O.read($)),z.forEach((O,D)=>{let _=$.accessors[D],C=!!O.sparse,S=!O.bufferView&&!_.getArray();if(C||S)_.setSparse(!0).setArray(fg(O,$))}),W}static validate(J,X){let Y=J.json;if(Y.asset.version!=="2.0")throw new Error(`Unsupported glTF version, "${Y.asset.version}".`);if(Y.extensionsRequired){for(let Z of Y.extensionsRequired)if(!X.extensions.find((W)=>W.EXTENSION_NAME===Z))throw new Error(`Missing required extension, "${Z}".`)}if(Y.extensionsUsed){for(let Z of Y.extensionsUsed)if(!X.extensions.find((W)=>W.EXTENSION_NAME===Z))X.logger.warn(`Missing optional extension, "${Z}".`)}}}function hg(J,X){let Y=X.jsonDoc,Z=X.bufferViews[J.bufferView],W=Y.json.bufferViews[J.bufferView],$=m4[J.componentType],Q=i.getElementSize(J.type),K=$.BYTES_PER_ELEMENT,G=J.byteOffset||0,F=new $(J.count*Q),q=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),H=W.byteStride;for(let z=0;z<J.count;z++)for(let V=0;V<Q;V++){let M=G+z*H+V*K,R;switch(J.componentType){case i.ComponentType.FLOAT:R=q.getFloat32(M,!0);break;case i.ComponentType.UNSIGNED_INT:R=q.getUint32(M,!0);break;case i.ComponentType.UNSIGNED_SHORT:R=q.getUint16(M,!0);break;case i.ComponentType.UNSIGNED_BYTE:R=q.getUint8(M);break;case i.ComponentType.SHORT:R=q.getInt16(M,!0);break;case i.ComponentType.BYTE:R=q.getInt8(M);break;default:throw new Error(`Unexpected componentType "${J.componentType}".`)}F[z*Q+V]=R}return F}function pY(J,X){let Y=X.jsonDoc,Z=X.bufferViews[J.bufferView],W=Y.json.bufferViews[J.bufferView],$=m4[J.componentType],Q=i.getElementSize(J.type),K=$.BYTES_PER_ELEMENT,G=Q*K;if(W.byteStride!==void 0&&W.byteStride!==G)return hg(J,X);let F=Z.byteOffset+(J.byteOffset||0),q=J.count*Q*K;return new $(Z.buffer.slice(F,F+q))}function fg(J,X){let Y=m4[J.componentType],Z=i.getElementSize(J.type),W;if(J.bufferView!==void 0)W=pY(J,X);else W=new Y(J.count*Z);let $=J.sparse;if(!$)return W;let Q=$.count,K=P8({},J,$.indices,{count:Q,type:"SCALAR"}),G=P8({},J,$.values,{count:Q}),F=pY(K,X),q=pY(G,X);for(let H=0;H<K.count;H++)for(let z=0;z<Z;z++)W[F[H]*Z+z]=q[H*Z+z];return W}var c4;(function(J){J[J.ARRAY_BUFFER=34962]="ARRAY_BUFFER",J[J.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER"})(c4||(c4={}));class D1{constructor(J,X,Y){this._doc=void 0,this.jsonDoc=void 0,this.options=void 0,this.accessorIndexMap=new Map,this.animationIndexMap=new Map,this.bufferIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.textureInfoDefMap=new Map,this.samplerDefIndexMap=new Map,this.sceneIndexMap=new Map,this.imageBufferViews=[],this.otherBufferViews=new Map,this.otherBufferViewsIndexMap=new Map,this.extensionData={},this.bufferURIGenerator=void 0,this.imageURIGenerator=void 0,this.logger=void 0,this._accessorUsageMap=new Map,this.accessorUsageGroupedByParent=new Set(["ARRAY_BUFFER"]),this.accessorParents=new Map,this._doc=J,this.jsonDoc=X,this.options=Y;let Z=J.getRoot(),W=Z.listBuffers().length,$=Z.listTextures().length;this.bufferURIGenerator=new ZG(W>1,()=>Y.basename||"buffer"),this.imageURIGenerator=new ZG($>1,(Q)=>bg(J,Q)||Y.basename||"texture"),this.logger=J.getLogger()}createTextureInfoDef(J,X){let Y={magFilter:X.getMagFilter()||void 0,minFilter:X.getMinFilter()||void 0,wrapS:X.getWrapS(),wrapT:X.getWrapT()},Z=JSON.stringify(Y);if(!this.samplerDefIndexMap.has(Z))this.samplerDefIndexMap.set(Z,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(Y);let W={source:this.imageIndexMap.get(J),sampler:this.samplerDefIndexMap.get(Z)},$=JSON.stringify(W);if(!this.textureDefIndexMap.has($))this.textureDefIndexMap.set($,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(W);let Q={index:this.textureDefIndexMap.get($)};if(X.getTexCoord()!==0)Q.texCoord=X.getTexCoord();if(Object.keys(X.getExtras()).length>0)Q.extras=X.getExtras();return this.textureInfoDefMap.set(X,Q),Q}createPropertyDef(J){let X={};if(J.getName())X.name=J.getName();if(Object.keys(J.getExtras()).length>0)X.extras=J.getExtras();return X}createAccessorDef(J){let X=this.createPropertyDef(J);if(X.type=J.getType(),X.componentType=J.getComponentType(),X.count=J.getCount(),this._doc.getGraph().listParentEdges(J).some((Z)=>Z.getName()==="attributes"&&Z.getAttributes().key==="POSITION"||Z.getName()==="input"))X.max=J.getMax([]).map(Math.fround),X.min=J.getMin([]).map(Math.fround);if(J.getNormalized())X.normalized=J.getNormalized();return X}createImageData(J,X,Y){if(this.options.format===W1.GLB)this.imageBufferViews.push(X),J.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:X.byteLength});else{let Z=$1.mimeTypeToExtension(Y.getMimeType());J.uri=this.imageURIGenerator.createURI(Y,Z),this.assignResourceURI(J.uri,X,!1)}}assignResourceURI(J,X,Y){let Z=this.jsonDoc.resources;if(!(J in Z)){Z[J]=X;return}if(X===Z[J]){this.logger.warn(`Duplicate resource URI, "${J}".`);return}let W=`Resource URI "${J}" already assigned to different data.`;if(!Y){this.logger.warn(W);return}throw new Error(W)}getAccessorUsage(J){let X=this._accessorUsageMap.get(J);if(X)return X;if(J.getSparse())return u8.SPARSE;for(let Y of this._doc.getGraph().listParentEdges(J)){let{usage:Z}=Y.getAttributes();if(Z)return Z;if(Y.getParent().propertyType!==p.ROOT)this.logger.warn(`Missing attribute ".usage" on edge, "${Y.getName()}".`)}return u8.OTHER}addAccessorToUsageGroup(J,X){let Y=this._accessorUsageMap.get(J);if(Y&&Y!==X)throw new Error(`Accessor with usage "${Y}" cannot be reused as "${X}".`);return this._accessorUsageMap.set(J,X),this}}D1.BufferViewTarget=c4;D1.BufferViewUsage=u8;D1.USAGE_TO_TARGET={[u8.ARRAY_BUFFER]:c4.ARRAY_BUFFER,[u8.ELEMENT_ARRAY_BUFFER]:c4.ELEMENT_ARRAY_BUFFER};class ZG{constructor(J,X){this.multiple=void 0,this.basename=void 0,this.counter={},this.multiple=J,this.basename=X}createURI(J,X){if(J.getURI())return J.getURI();else if(!this.multiple)return`${this.basename(J)}.${X}`;else{let Y=this.basename(J);return this.counter[Y]=this.counter[Y]||1,`${Y}_${this.counter[Y]++}.${X}`}}}function bg(J,X){let Y=J.getGraph().listParentEdges(X).find((Z)=>Z.getParent()!==J.getRoot());return Y?Y.getName().replace(/texture$/i,""):""}var{BufferViewUsage:bY}=D1,{UNSIGNED_INT:pg,UNSIGNED_SHORT:Ag,UNSIGNED_BYTE:yg}=i.ComponentType,gg=new Set([p.ACCESSOR,p.BUFFER,p.MATERIAL,p.MESH]);class dR{static write(J,X){let Y=J.getGraph(),Z=J.getRoot(),W={asset:P8({generator:`glTF-Transform ${fR}`},Z.getAsset()),extras:P8({},Z.getExtras())},$={json:W,resources:{}},Q=new D1(J,$,X),K=X.logger||e8.DEFAULT_INSTANCE,G=new Set(X.extensions.map((L)=>L.EXTENSION_NAME)),F=J.getRoot().listExtensionsUsed().filter((L)=>G.has(L.extensionName)).sort((L,w)=>L.extensionName>w.extensionName?1:-1),q=J.getRoot().listExtensionsRequired().filter((L)=>G.has(L.extensionName)).sort((L,w)=>L.extensionName>w.extensionName?1:-1);if(F.length<J.getRoot().listExtensionsUsed().length)K.warn("Some extensions were not registered for I/O, and will not be written.");for(let L of F){let w=L.prewriteTypes.filter((P)=>!gg.has(P));if(w.length)K.warn(`Prewrite hooks for some types (${w.join()}), requested by extension ${L.extensionName}, are unsupported. Please file an issue or a PR.`);for(let P of L.writeDependencies)L.install(P,X.dependencies[P])}function H(L,w,P,N){let v=[],j=0;for(let _ of L){let C=Q.createAccessorDef(_);C.bufferView=W.bufferViews.length;let S=_.getArray(),I=G0.pad(G0.toView(S));C.byteOffset=j,j+=I.byteLength,v.push(I),Q.accessorIndexMap.set(_,W.accessors.length),W.accessors.push(C)}let O=G0.concat(v),D={buffer:w,byteOffset:P,byteLength:O.byteLength};if(N)D.target=N;return W.bufferViews.push(D),{buffers:v,byteLength:j}}function z(L,w,P){let N=L[0].getCount(),v=0;for(let C of L){let S=Q.createAccessorDef(C);S.bufferView=W.bufferViews.length,S.byteOffset=v;let I=C.getElementSize(),f=C.getComponentSize();v+=G0.padNumber(I*f),Q.accessorIndexMap.set(C,W.accessors.length),W.accessors.push(S)}let j=N*v,O=new ArrayBuffer(j),D=new DataView(O);for(let C=0;C<N;C++){let S=0;for(let I of L){let f=I.getElementSize(),y=I.getComponentSize(),h=I.getComponentType(),g=I.getArray();for(let J0=0;J0<f;J0++){let p0=C*v+S+J0*y,a0=g[C*f+J0];switch(h){case i.ComponentType.FLOAT:D.setFloat32(p0,a0,!0);break;case i.ComponentType.BYTE:D.setInt8(p0,a0);break;case i.ComponentType.SHORT:D.setInt16(p0,a0,!0);break;case i.ComponentType.UNSIGNED_BYTE:D.setUint8(p0,a0);break;case i.ComponentType.UNSIGNED_SHORT:D.setUint16(p0,a0,!0);break;case i.ComponentType.UNSIGNED_INT:D.setUint32(p0,a0,!0);break;default:throw new Error("Unexpected component type: "+h)}}S+=G0.padNumber(f*y)}}let _={buffer:w,byteOffset:P,byteLength:j,byteStride:v,target:D1.BufferViewTarget.ARRAY_BUFFER};return W.bufferViews.push(_),{byteLength:j,buffers:[new Uint8Array(O)]}}function V(L,w,P){let N=[],v=0,j=new Map,O=-1/0,D=!1;for(let h of L){let g=Q.createAccessorDef(h);W.accessors.push(g),Q.accessorIndexMap.set(h,W.accessors.length-1);let J0=[],p0=[],a0=[],Q6=new Array(h.getElementSize()).fill(0);for(let Z4=0,DS=h.getCount();Z4<DS;Z4++){if(h.getElement(Z4,a0),b0.eq(a0,Q6,0))continue;O=Math.max(Z4,O),J0.push(Z4);for(let z$=0;z$<a0.length;z$++)p0.push(a0[z$])}let n6=J0.length,Y4={accessorDef:g,count:n6};if(j.set(h,Y4),n6===0)continue;if(n6>h.getCount()/2)D=!0;let TS=m4[h.getComponentType()];Y4.indices=J0,Y4.values=new TS(p0)}if(!Number.isFinite(O))return{buffers:N,byteLength:v};if(D)K.warn("Some sparse accessors have >50% non-zero elements, which may increase file size.");let _=O<255?Uint8Array:O<65535?Uint16Array:Uint32Array,C=O<255?yg:O<65535?Ag:pg,S={buffer:w,byteOffset:P+v,byteLength:0};for(let h of L){let g=j.get(h);if(g.count===0)continue;g.indicesByteOffset=S.byteLength;let J0=G0.pad(G0.toView(new _(g.indices)));N.push(J0),v+=J0.byteLength,S.byteLength+=J0.byteLength}W.bufferViews.push(S);let I=W.bufferViews.length-1,f={buffer:w,byteOffset:P+v,byteLength:0};for(let h of L){let g=j.get(h);if(g.count===0)continue;g.valuesByteOffset=f.byteLength;let J0=G0.pad(G0.toView(g.values));N.push(J0),v+=J0.byteLength,f.byteLength+=J0.byteLength}W.bufferViews.push(f);let y=W.bufferViews.length-1;for(let h of L){let g=j.get(h);if(g.count===0)continue;g.accessorDef.sparse={count:g.count,indices:{bufferView:I,byteOffset:g.indicesByteOffset,componentType:C},values:{bufferView:y,byteOffset:g.valuesByteOffset}}}return{buffers:N,byteLength:v}}if(W.accessors=[],W.bufferViews=[],W.samplers=[],W.textures=[],W.images=Z.listTextures().map((L,w)=>{let P=Q.createPropertyDef(L);if(L.getMimeType())P.mimeType=L.getMimeType();let N=L.getImage();if(N)Q.createImageData(P,N,L);return Q.imageIndexMap.set(L,w),P}),F.filter((L)=>L.prewriteTypes.includes(p.ACCESSOR)).forEach((L)=>L.prewrite(Q,p.ACCESSOR)),Z.listAccessors().forEach((L)=>{let{accessorUsageGroupedByParent:w,accessorParents:P}=Q;if(Q.accessorIndexMap.has(L))return;let N=Q.getAccessorUsage(L);if(Q.addAccessorToUsageGroup(L,N),w.has(N)){let v=Y.listParents(L).find((j)=>j.propertyType!==p.ROOT);P.set(L,v)}}),F.filter((L)=>L.prewriteTypes.includes(p.BUFFER)).forEach((L)=>L.prewrite(Q,p.BUFFER)),(Z.listAccessors().length>0||Q.otherBufferViews.size>0||Z.listTextures().length>0&&X.format===W1.GLB)&&Z.listBuffers().length===0)throw new Error("Buffer required for Document resources, but none was found.");if(W.buffers=[],Z.listBuffers().forEach((L,w)=>{let P=Q.createPropertyDef(L),N=Q.accessorUsageGroupedByParent,v=L.listParents().filter((f)=>f instanceof i),j=new Set(v.map((f)=>Q.accessorParents.get(f))),O=new Map(Array.from(j).map((f,y)=>[f,y])),D={};for(let f of v){var _;if(Q.accessorIndexMap.has(f))continue;let y=Q.getAccessorUsage(f),h=y;if(N.has(y)){let g=Q.accessorParents.get(f);h+=`:${O.get(g)}`}D[_=h]||(D[_]={usage:y,accessors:[]}),D[h].accessors.push(f)}let C=[],S=W.buffers.length,I=0;for(let{usage:f,accessors:y}of Object.values(D))if(f===bY.ARRAY_BUFFER&&X.vertexLayout===yY.INTERLEAVED){let h=z(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}else if(f===bY.ARRAY_BUFFER)for(let h of y){let g=z([h],S,I);I+=g.byteLength;for(let J0 of g.buffers)C.push(J0)}else if(f===bY.SPARSE){let h=V(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}else if(f===bY.ELEMENT_ARRAY_BUFFER){let h=D1.BufferViewTarget.ELEMENT_ARRAY_BUFFER,g=H(y,S,I,h);I+=g.byteLength;for(let J0 of g.buffers)C.push(J0)}else{let h=H(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}if(Q.imageBufferViews.length&&w===0){for(let f=0;f<Q.imageBufferViews.length;f++)if(W.bufferViews[W.images[f].bufferView].byteOffset=I,I+=Q.imageBufferViews[f].byteLength,C.push(Q.imageBufferViews[f]),I%8){let y=8-I%8;I+=y,C.push(new Uint8Array(y))}}if(Q.otherBufferViews.has(L))for(let f of Q.otherBufferViews.get(L))W.bufferViews.push({buffer:S,byteOffset:I,byteLength:f.byteLength}),Q.otherBufferViewsIndexMap.set(f,W.bufferViews.length-1),I+=f.byteLength,C.push(f);if(I){let f;if(X.format===W1.GLB)f=AY;else f=Q.bufferURIGenerator.createURI(L,"bin"),P.uri=f;P.byteLength=I,Q.assignResourceURI(f,G0.concat(C),!0)}W.buffers.push(P),Q.bufferIndexMap.set(L,w)}),Z.listAccessors().find((L)=>!L.getBuffer()))K.warn("Skipped writing one or more Accessors: no Buffer assigned.");F.filter((L)=>L.prewriteTypes.includes(p.MATERIAL)).forEach((L)=>L.prewrite(Q,p.MATERIAL)),W.materials=Z.listMaterials().map((L,w)=>{let P=Q.createPropertyDef(L);if(L.getAlphaMode()!==E1.AlphaMode.OPAQUE)P.alphaMode=L.getAlphaMode();if(L.getAlphaMode()===E1.AlphaMode.MASK)P.alphaCutoff=L.getAlphaCutoff();if(L.getDoubleSided())P.doubleSided=!0;if(P.pbrMetallicRoughness={},!b0.eq(L.getBaseColorFactor(),[1,1,1,1]))P.pbrMetallicRoughness.baseColorFactor=L.getBaseColorFactor();if(!b0.eq(L.getEmissiveFactor(),[0,0,0]))P.emissiveFactor=L.getEmissiveFactor();if(L.getRoughnessFactor()!==1)P.pbrMetallicRoughness.roughnessFactor=L.getRoughnessFactor();if(L.getMetallicFactor()!==1)P.pbrMetallicRoughness.metallicFactor=L.getMetallicFactor();if(L.getBaseColorTexture()){let N=L.getBaseColorTexture(),v=L.getBaseColorTextureInfo();P.pbrMetallicRoughness.baseColorTexture=Q.createTextureInfoDef(N,v)}if(L.getEmissiveTexture()){let N=L.getEmissiveTexture(),v=L.getEmissiveTextureInfo();P.emissiveTexture=Q.createTextureInfoDef(N,v)}if(L.getNormalTexture()){let N=L.getNormalTexture(),v=L.getNormalTextureInfo(),j=Q.createTextureInfoDef(N,v);if(L.getNormalScale()!==1)j.scale=L.getNormalScale();P.normalTexture=j}if(L.getOcclusionTexture()){let N=L.getOcclusionTexture(),v=L.getOcclusionTextureInfo(),j=Q.createTextureInfoDef(N,v);if(L.getOcclusionStrength()!==1)j.strength=L.getOcclusionStrength();P.occlusionTexture=j}if(L.getMetallicRoughnessTexture()){let N=L.getMetallicRoughnessTexture(),v=L.getMetallicRoughnessTextureInfo();P.pbrMetallicRoughness.metallicRoughnessTexture=Q.createTextureInfoDef(N,v)}return Q.materialIndexMap.set(L,w),P}),F.filter((L)=>L.prewriteTypes.includes(p.MESH)).forEach((L)=>L.prewrite(Q,p.MESH)),W.meshes=Z.listMeshes().map((L,w)=>{let P=Q.createPropertyDef(L),N=null;if(P.primitives=L.listPrimitives().map((v)=>{let j={attributes:{}};j.mode=v.getMode();let O=v.getMaterial();if(O)j.material=Q.materialIndexMap.get(O);if(Object.keys(v.getExtras()).length)j.extras=v.getExtras();let D=v.getIndices();if(D)j.indices=Q.accessorIndexMap.get(D);for(let _ of v.listSemantics())j.attributes[_]=Q.accessorIndexMap.get(v.getAttribute(_));for(let _ of v.listTargets()){let C={};for(let S of _.listSemantics())C[S]=Q.accessorIndexMap.get(_.getAttribute(S));j.targets=j.targets||[],j.targets.push(C)}if(v.listTargets().length&&!N)N=v.listTargets().map((_)=>_.getName());return j}),L.getWeights().length)P.weights=L.getWeights();if(N)P.extras=P.extras||{},P.extras.targetNames=N;return Q.meshIndexMap.set(L,w),P}),W.cameras=Z.listCameras().map((L,w)=>{let P=Q.createPropertyDef(L);if(P.type=L.getType(),P.type===G9.Type.PERSPECTIVE){P.perspective={znear:L.getZNear(),zfar:L.getZFar(),yfov:L.getYFov()};let N=L.getAspectRatio();if(N!==null)P.perspective.aspectRatio=N}else P.orthographic={znear:L.getZNear(),zfar:L.getZFar(),xmag:L.getXMag(),ymag:L.getYMag()};return Q.cameraIndexMap.set(L,w),P}),W.nodes=Z.listNodes().map((L,w)=>{let P=Q.createPropertyDef(L);if(!b0.eq(L.getTranslation(),[0,0,0]))P.translation=L.getTranslation();if(!b0.eq(L.getRotation(),[0,0,0,1]))P.rotation=L.getRotation();if(!b0.eq(L.getScale(),[1,1,1]))P.scale=L.getScale();if(L.getWeights().length)P.weights=L.getWeights();return Q.nodeIndexMap.set(L,w),P}),W.skins=Z.listSkins().map((L,w)=>{let P=Q.createPropertyDef(L),N=L.getInverseBindMatrices();if(N)P.inverseBindMatrices=Q.accessorIndexMap.get(N);let v=L.getSkeleton();if(v)P.skeleton=Q.nodeIndexMap.get(v);return P.joints=L.listJoints().map((j)=>Q.nodeIndexMap.get(j)),Q.skinIndexMap.set(L,w),P}),Z.listNodes().forEach((L,w)=>{let P=W.nodes[w],N=L.getMesh();if(N)P.mesh=Q.meshIndexMap.get(N);let v=L.getCamera();if(v)P.camera=Q.cameraIndexMap.get(v);let j=L.getSkin();if(j)P.skin=Q.skinIndexMap.get(j);if(L.listChildren().length>0)P.children=L.listChildren().map((O)=>Q.nodeIndexMap.get(O))}),W.animations=Z.listAnimations().map((L,w)=>{let P=Q.createPropertyDef(L),N=new Map;return P.samplers=L.listSamplers().map((v,j)=>{let O=Q.createPropertyDef(v);return O.input=Q.accessorIndexMap.get(v.getInput()),O.output=Q.accessorIndexMap.get(v.getOutput()),O.interpolation=v.getInterpolation(),N.set(v,j),O}),P.channels=L.listChannels().map((v)=>{let j=Q.createPropertyDef(v);return j.sampler=N.get(v.getSampler()),j.target={node:Q.nodeIndexMap.get(v.getTargetNode()),path:v.getTargetPath()},j}),Q.animationIndexMap.set(L,w),P}),W.scenes=Z.listScenes().map((L,w)=>{let P=Q.createPropertyDef(L);return P.nodes=L.listChildren().map((N)=>Q.nodeIndexMap.get(N)),Q.sceneIndexMap.set(L,w),P});let R=Z.getDefaultScene();if(R)W.scene=Z.listScenes().indexOf(R);return W.extensionsUsed=F.map((L)=>L.extensionName),W.extensionsRequired=q.map((L)=>L.extensionName),F.forEach((L)=>L.write(Q)),cg(W),$}}function cg(J){let X=[];for(let Y in J){let Z=J[Y];if(Array.isArray(Z)&&Z.length===0)X.push(Y);else if(Z===null||Z==="")X.push(Y);else if(Z&&typeof Z==="object"&&Object.keys(Z).length===0)X.push(Y)}for(let Y of X)delete J[Y]}var mY;(function(J){J[J.JSON=1313821514]="JSON",J[J.BIN=5130562]="BIN"})(mY||(mY={}));class iR{constructor(){this._logger=e8.DEFAULT_INSTANCE,this._extensions=new Set,this._dependencies={},this._vertexLayout=yY.INTERLEAVED,this.lastReadBytes=0,this.lastWriteBytes=0}setLogger(J){return this._logger=J,this}registerExtensions(J){for(let X of J)this._extensions.add(X),X.register();return this}registerDependencies(J){return Object.assign(this._dependencies,J),this}setVertexLayout(J){return this._vertexLayout=J,this}async read(J){return await this.readJSON(await this.readAsJSON(J))}async readAsJSON(J){let X=await this.readURI(J,"view");this.lastReadBytes=X.byteLength;let Y=hR(X)?this._binaryToJSON(X):{json:JSON.parse(G0.decodeText(X)),resources:{}};return await this._readResourcesExternal(Y,this.dirname(J)),this._readResourcesInternal(Y),Y}async readJSON(J){return J=this._copyJSON(J),this._readResourcesInternal(J),uR.read(J,{extensions:Array.from(this._extensions),dependencies:this._dependencies,logger:this._logger})}async binaryToJSON(J){let X=this._binaryToJSON(G0.assertView(J));this._readResourcesInternal(X);let Y=X.json;if(Y.buffers&&Y.buffers.some((Z)=>mg(X,Z)))throw new Error("Cannot resolve external buffers with binaryToJSON().");else if(Y.images&&Y.images.some((Z)=>lg(X,Z)))throw new Error("Cannot resolve external images with binaryToJSON().");return X}async readBinary(J){return this.readJSON(await this.binaryToJSON(G0.assertView(J)))}async writeJSON(J,X={}){if(X.format===W1.GLB&&J.getRoot().listBuffers().length>1)throw new Error("GLB must have 0\u20131 buffers.");return dR.write(J,{format:X.format||W1.GLTF,basename:X.basename||"",logger:this._logger,vertexLayout:this._vertexLayout,dependencies:P8({},this._dependencies),extensions:Array.from(this._extensions)})}async writeBinary(J){let{json:X,resources:Y}=await this.writeJSON(J,{format:W1.GLB}),Z=new Uint32Array([1179937895,2,12]),W=JSON.stringify(X),$=G0.pad(G0.encodeText(W),32),Q=G0.toView(new Uint32Array([$.byteLength,1313821514])),K=G0.concat([Q,$]);Z[Z.length-1]+=K.byteLength;let G=Object.values(Y)[0];if(!G||!G.byteLength)return G0.concat([G0.toView(Z),K]);let F=G0.pad(G,0),q=G0.toView(new Uint32Array([F.byteLength,5130562])),H=G0.concat([q,F]);return Z[Z.length-1]+=H.byteLength,G0.concat([G0.toView(Z),K,H])}async _readResourcesExternal(J,X){var Y=this;let Z=J.json.images||[],W=J.json.buffers||[],$=[...Z,...W].map(async function(Q){let K=Q.uri;if(!K||K.match(/data:/))return Promise.resolve();J.resources[K]=await Y.readURI(Y.resolve(X,K),"view"),Y.lastReadBytes+=J.resources[K].byteLength});await Promise.all($)}_readResourcesInternal(J){function X(W){if(!W.uri)return;if(W.uri in J.resources){G0.assertView(J.resources[W.uri]);return}if(W.uri.match(/data:/)){let $=`__${cR()}.${Q1.extension(W.uri)}`;J.resources[$]=G0.createBufferFromDataURI(W.uri),W.uri=$}}(J.json.images||[]).forEach((W)=>{if(W.bufferView===void 0&&W.uri===void 0)throw new Error("Missing resource URI or buffer view.");X(W)}),(J.json.buffers||[]).forEach(X)}_copyJSON(J){let{images:X,buffers:Y}=J.json;if(J={json:P8({},J.json),resources:P8({},J.resources)},X)J.json.images=X.map((Z)=>P8({},Z));if(Y)J.json.buffers=Y.map((Z)=>P8({},Z));return J}_binaryToJSON(J){if(!hR(J))throw new Error("Invalid glTF 2.0 binary.");let X=new Uint32Array(J.buffer,J.byteOffset+12,2);if(X[1]!==mY.JSON)throw new Error("Missing required GLB JSON chunk.");let Y=20,Z=X[0],W=G0.decodeText(G0.toView(J,Y,Z)),$=JSON.parse(W),Q=Y+Z;if(J.byteLength<=Q)return{json:$,resources:{}};let K=new Uint32Array(J.buffer,J.byteOffset+Q,2);if(K[1]!==mY.BIN)return{json:$,resources:{}};let G=K[0],F=G0.toView(J,Q+8,G);return{json:$,resources:{[AY]:F}}}}function mg(J,X){return X.uri!==void 0&&!(X.uri in J.resources)}function lg(J,X){return X.uri!==void 0&&!(X.uri in J.resources)&&X.bufferView===void 0}function hR(J){if(J.byteLength<3*Uint32Array.BYTES_PER_ELEMENT)return!1;let X=new Uint32Array(J.buffer,J.byteOffset,3);return X[0]===1179937895&&X[1]===2}class FG extends iR{constructor(J=null,X=r8.DEFAULT_INIT){super();this._fetch=void 0,this._fetchConfig=void 0,this._init=void 0,this._fetchEnabled=!1,this._fetch=J,this._fetchConfig=X,this._init=this.init()}async init(){if(this._init)return this._init;return Promise.all([import("fs"),import("path")]).then(([J,X])=>{this._fs=J.promises,this._path=X})}setAllowNetwork(J){if(J&&!this._fetch)throw new Error("NodeIO requires a Fetch API implementation for HTTP requests.");return this._fetchEnabled=J,this}async readURI(J,X){if(await this.init(),r8.isAbsoluteURL(J)){if(!this._fetchEnabled||!this._fetch)throw new Error("Network request blocked. Allow HTTP requests explicitly, if needed.");let Y=await this._fetch(J,this._fetchConfig);switch(X){case"view":return new Uint8Array(await Y.arrayBuffer());case"text":return Y.text()}}else switch(X){case"view":return this._fs.readFile(J);case"text":return this._fs.readFile(J,"utf8")}}resolve(J,X){if(r8.isAbsoluteURL(J)||r8.isAbsoluteURL(X))return r8.resolve(J,X);return this._path.resolve(J,decodeURIComponent(X))}dirname(J){if(r8.isAbsoluteURL(J))return r8.dirname(J);return this._path.dirname(J)}async write(J,X){await this.init(),await(!!J.match(/\.glb$/)?this._writeGLB(J,X):this._writeGLTF(J,X))}async _writeGLTF(J,X){var Y=this;this.lastWriteBytes=0;let{json:Z,resources:W}=await this.writeJSON(X,{format:W1.GLTF,basename:Q1.basename(J)}),{_fs:$,_path:Q}=this,K=Q.dirname(J),G=JSON.stringify(Z,null,2);await $.writeFile(J,G),this.lastWriteBytes+=G.length;for(let F of ug(Object.keys(W),10))await Promise.all(F.map(async function(q){if(r8.isAbsoluteURL(q)){if(r8.extension(q)==="bin")throw new Error(`Cannot write buffer to path "${q}".`);return}let H=Q.join(K,decodeURIComponent(q));await $.mkdir(Q.dirname(H),{recursive:!0}),await $.writeFile(H,W[q]),Y.lastWriteBytes+=W[q].byteLength}))}async _writeGLB(J,X){let Y=await this.writeBinary(X);await this._fs.writeFile(J,Y),this.lastWriteBytes=Y.byteLength}}function ug(J,X){let Y=[];for(let Z=0,W=J.length;Z<W;Z+=X){let $=[];for(let Q=0;Q<X&&Z+Q<W;Q++)$.push(J[Z+Q]);Y.push($)}return Y}var Xc=a6(eR(),1);function qG(){return qG=Object.assign?Object.assign.bind():function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)({}).hasOwnProperty.call(Y,Z)&&(J[Z]=Y[Z])}return J},qG.apply(null,arguments)}var{POINTS:Jw,LINES:rY,LINE_STRIP:Yc,LINE_LOOP:Zc,TRIANGLES:tY,TRIANGLE_STRIP:Wc,TRIANGLE_FAN:$c}=K1.Mode;var ZM0=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});var WM0={[Jw]:Jw,[rY]:rY,[Yc]:rY,[Zc]:rY,[tY]:tY,[Wc]:tY,[$c]:tY};var JZ=typeof Float32Array!=="undefined"?Float32Array:Array;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};function Qc(){var J=new JZ(3);if(JZ!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}(function(){var J=Qc();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}})();var $M0={keepUniqueNames:!1,propertyTypes:[p.ACCESSOR,p.MESH,p.TEXTURE,p.MATERIAL,p.SKIN]};function Kc(){var J=new JZ(4);if(JZ!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}(function(){var J=Kc();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=4;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],J[3]=X[K+3],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2],X[K+3]=J[3];return X}})();var QM0={propertyTypes:[p.NODE,p.SKIN,p.MESH,p.CAMERA,p.PRIMITIVE,p.PRIMITIVE_TARGET,p.ANIMATION,p.MATERIAL,p.TEXTURE,p.ACCESSOR,p.BUFFER],keepLeaves:!1,keepAttributes:!1,keepIndices:!1,keepSolidTextures:!1,keepExtras:!1};var Xw;(function(J){J.RENDER="render",J.RENDER_CACHED="render-cached",J.UPLOAD="upload",J.UPLOAD_NAIVE="upload-naive",J.DISTINCT="distinct",J.DISTINCT_POSITION="distinct-position",J.UNUSED="unused"})(Xw||(Xw={}));var{FLOAT:KM0}=i.ComponentType;var{LINES:GM0,LINE_STRIP:FM0,LINE_LOOP:qM0,TRIANGLES:HM0,TRIANGLE_STRIP:zM0,TRIANGLE_FAN:LM0}=K1.Mode;function $w(J){return bR(J)}var{LINE_STRIP:UM0,LINE_LOOP:VM0,TRIANGLE_STRIP:MM0,TRIANGLE_FAN:RM0}=K1.Mode;var{TRANSLATION:wM0,ROTATION:OM0,SCALE:xM0,WEIGHTS:PM0}=l4.TargetPath;var Gc={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12,normalizeWeights:!0,cleanup:!0};var NM0=qG({level:"high"},Gc);var Yw;(function(J){J[J.STEP=0]="STEP",J[J.LERP=1]="LERP",J[J.SLERP=2]="SLERP"})(Yw||(Yw={}));var Fc=0.000001;function qc(J,X,Y,Z=0.0001){let W=X.length/J.length,$=new Array(W).fill(0),Q=new Array(W).fill(0),K=new Array(W).fill(0),G=new Array(W).fill(0),F=J.length-1,q=1;for(let H=1;H<F;++H){let z=J[q-1],V=J[H],M=J[H+1],R=(V-z)/(M-z),L=!1;if(V!==M&&(H!==1||V!==J[0])){if(u4(X,q-1,G),u4(X,H,Q),u4(X,H+1,K),Y==="slerp"){let w=Lc($,G,K,R),P=Ww(G,Q)+Ww(Q,K);L=!eY(Q,w,Z)||P+Number.EPSILON>=Math.PI}else if(Y==="lerp"){let w=zc($,G,K,R);L=!eY(Q,w,Z)}else if(Y==="step")L=!eY(Q,G)||!eY(Q,K)}if(L){if(H!==q)J[q]=J[H],Zw(X,q,u4(X,H,$));q++}}if(F>0)J[q]=J[F],Zw(X,q,u4(X,F,$)),q++;return q}function u4(J,X,Y){for(let Z=0,W=Y.length;Z<W;Z++)Y[Z]=J[X*W+Z];return Y}function Zw(J,X,Y){for(let Z=0,W=Y.length;Z<W;Z++)J[X*W+Z]=Y[Z]}function eY(J,X,Y=0){if(J.length!==X.length)return!1;for(let Z=0;Z<J.length;Z++)if(Math.abs(J[Z]-X[Z])>Y)return!1;return!0}function Hc(J,X,Y){return J*(1-Y)+X*Y}function zc(J,X,Y,Z){for(let W=0;W<X.length;W++)J[W]=Hc(X[W],Y[W],Z);return J}function Lc(J,X,Y,Z){let W=X[0],$=X[1],Q=X[2],K=X[3],G=Y[0],F=Y[1],q=Y[2],H=Y[3],z,V,M,R,L;if(V=W*G+$*F+Q*q+K*H,V<0)V=-V,G=-G,F=-F,q=-q,H=-H;if(1-V>Fc)z=Math.acos(V),M=Math.sin(z),R=Math.sin((1-Z)*z)/M,L=Math.sin(Z*z)/M;else R=1-Z,L=Z;return J[0]=R*W+L*G,J[1]=R*$+L*F,J[2]=R*Q+L*q,J[3]=R*K+L*H,J}function Ww(J,X){let Y=Uc(J,X);return Math.acos(2*Y*Y-1)}function Uc(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]+J[3]*X[3]}var vM0=new Float32Array(0),BM0={ready:Promise.resolve(),resample:qc,tolerance:0.0001,cleanup:!0};var{POINTS:jM0,LINES:kM0,LINE_STRIP:TM0,LINE_LOOP:DM0,TRIANGLES:_M0,TRIANGLE_STRIP:EM0,TRIANGLE_FAN:CM0}=K1.Mode;var HG;(function(J){J.LANCZOS3="lanczos3",J.LANCZOS2="lanczos2"})(HG||(HG={}));var SM0={resizeFilter:HG.LANCZOS3,pattern:void 0,formats:void 0,slots:void 0,quality:void 0,effort:void 0,lossless:!1,nearLossless:!1,limitInputPixels:!0};var Q5={OPTIMIZED_DIR:".optimized",CHECKSUM_EXT:".md5",DIRECTORIES:[G1.normalize("node_modules/@hytopia.com/assets"),G1.normalize("assets")],OPTIMIZER_RUNS:[{suffix:"",options:["--compress","false","--instance","false","--simplify","false"]},{suffix:"-named-nodes",options:["--compress","false","--instance","false","--simplify","false","--join","true","--join-named","false"]}]};class U6{static instance=new U6;optimize=!0;optimizeEveryStart=!1;_modelUriDocuments=new Map;_modelUriBoundingBoxes=new Map;_modelUriNodeNames=new Map;constructor(){}async preloadModels(){let J=await this._getAbsoluteModelPaths();console.log(`ModelRegistry.preloadModels(): Preloading ${J.length} models...`);for(let X of J){if(this.optimize)await this._resolveOptimizedModelPath(X);await this._loadModelData(X)}console.log(`ModelRegistry.preloadModels(): Preloaded ${J.length} models!`)}getBoundingBox(J){let X=this._modelUriBoundingBoxes.get(J);if(!X)E.fatalError(`ModelRegistry.getBoundingBox(): Model ${J} not found!`);return X}getHeight(J){let X=this.getBoundingBox(J);return X.max.y-X.min.y}getNodeNames(J){let X=this._modelUriNodeNames.get(J);if(!X)E.fatalError(`ModelRegistry.getNodeNames(): Model ${J} not found!`);return X}modelHasNode(J,X){let Y=this._modelUriNodeNames.get(J);if(!Y)E.fatalError(`ModelRegistry.modelHasNode(): Model ${J} not found!`);return Y.includes(X)}_absoluteModelPathToModelUri(J){let X=G1.relative(process.cwd(),J),Y=Q5.DIRECTORIES.find((W)=>X.startsWith(W));return(Y?G1.relative(Y,X):X).split(G1.sep).join("/")}async _getAbsoluteModelPaths(){let J=[],X=new Mc("**/*.{gltf,glb}");for(let Y of Q5.DIRECTORIES){let Z=G1.resolve(process.cwd(),Y);if(!C1.existsSync(Z))continue;for await(let W of X.scan(Z))J.push(G1.join(Z,W))}return J}async _loadModelData(J){let X=await new FG().read(J),Y=$w(X.getRoot().listScenes()[0]),Z=X.getRoot().listNodes().map(($)=>$.getName()),W=this._absoluteModelPathToModelUri(J);this._modelUriDocuments.set(W,X),this._modelUriBoundingBoxes.set(W,{min:{x:Y.min[0],y:Y.min[1],z:Y.min[2]},max:{x:Y.max[0],y:Y.max[1],z:Y.max[2]}}),this._modelUriNodeNames.set(W,Z)}async _resolveOptimizedModelPath(J){let X=this._buildOptimizedModelPath(J);if(!this.optimizeEveryStart&&this._isOptimizedVersionValid(J))return X;return await this._optimizeModel(J,X)}_isOptimizedVersionValid(J){let X=`${this._buildOptimizedModelPath(J)}${Q5.CHECKSUM_EXT}`;if(!C1.existsSync(X))return!1;let Y=this._calculateChecksum(J),Z=C1.readFileSync(X,"utf8");return Y===Z}_calculateChecksum(J){if(!C1.existsSync(J))return"";let X=C1.readFileSync(J);return Vc.createHash("sha256").update(X.toString("base64")).digest("hex")}_buildOptimizedModelPath(J){let X=G1.basename(J),Y=X.replace(/\.[^/.]+$/,""),Z=`${Q5.OPTIMIZED_DIR}/${Y}`;return J.replace(/[^/\\]+$/,`${Z}/${X}`)}async _optimizeModel(J,X){let Y=G1.dirname(X);C1.rmSync(Y,{recursive:!0,force:!0}),C1.mkdirSync(Y,{recursive:!0}),console.log(`ModelRegistry: Optimizing model ${this._absoluteModelPathToModelUri(J)}...`);for(let Z of Q5.OPTIMIZER_RUNS){let W=X.replace(/(\.[^/.]+)$/,`${Z.suffix}$1`),{stderr:$}=await DR("bunx",["gltf-transform","optimize",J,W,...Z.options]);if($)return E.warning(`ModelRegistry._optimizeModel(): Error optimizing model ${this._absoluteModelPathToModelUri(J)}, defaulting to unoptimized model. Error: ${$}`),J}return C1.writeFileSync(`${X}${Q5.CHECKSUM_EXT}`,this._calculateChecksum(J)),X}}var zG;((W)=>{W[W.Average=0]="Average";W[W.Min=1]="Min";W[W.Multiply=2]="Multiply";W[W.Max=3]="Max"})(zG||={});var XZ;((G)=>{G.NONE="none";G.BALL="ball";G.BLOCK="block";G.CAPSULE="capsule";G.CONE="cone";G.CYLINDER="cylinder";G.ROUND_CYLINDER="round-cylinder";G.TRIMESH="trimesh"})(XZ||={});class d8 extends s{_collider;_colliderDesc;_onCollision;_parentRigidBody;_shape;_simulation;_tag;constructor(J){super();this._colliderDesc=this._createColliderDesc(J),this._shape=J.shape,this._applyColliderOptions(J),this._autoAddToSimulation(J)}static optionsFromBlockHalfExtents(J){return{shape:"block",halfExtents:J}}static optionsFromModelUri(J,X=1){let Y=U6.instance.getBoundingBox(J),Z=Y.max.x-Y.min.x,W=Y.max.y-Y.min.y,$=Y.max.z-Y.min.z,Q=Math.max(Z,$),K=Math.min(Z,$);if(Q/K>2)return{shape:"block",halfExtents:{x:Math.max(0.01,Z*X/2),y:Math.max(0.01,W*X/2),z:Math.max(0.01,$*X/2)}};let F=Q*X/2;if(Q/W>1.5)return{shape:"round-cylinder",radius:Math.max(0.01,F),halfHeight:Math.max(0.01,W*X/2),borderRadius:Math.max(0.01,F*0.1)};return{shape:"capsule",radius:Math.max(0.01,F),halfHeight:Math.max(0.01,W*X/2-F)}}get bounciness(){if(!this._requireNotRemoved("bounciness"))return 0;return this._collider?this._collider.restitution():this._colliderDesc.restitution}get bouncinessCombineRule(){if(!this._requireNotRemoved("bouncinessCombineRule"))return 0;return this._collider?this._collider.restitutionCombineRule():this._colliderDesc.restitutionCombineRule}get collisionGroups(){if(!this._requireNotRemoved("collisionGroups"))return{belongsTo:[],collidesWith:[]};return this._collider?q6.decodeRawCollisionGroups(this._collider.collisionGroups()):q6.decodeRawCollisionGroups(this._colliderDesc.collisionGroups)}get friction(){if(!this._requireNotRemoved("friction"))return 0;return this._collider?this._collider.friction():this._colliderDesc.friction}get frictionCombineRule(){if(!this._requireNotRemoved("frictionCombineRule"))return 0;return this._collider?this._collider.frictionCombineRule():this._colliderDesc.frictionCombineRule}get isEnabled(){if(!this._requireNotRemoved("isEnabled"))return!1;return this._collider?this._collider.isEnabled():this._colliderDesc.enabled}get isRemoved(){return!this._collider&&!this._colliderDesc}get isSensor(){if(!this._requireNotRemoved("isSensor"))return!1;return this._collider?this._collider.isSensor():this._colliderDesc.isSensor}get isSimulated(){if(!this._requireNotRemoved("isSimulated"))return!1;return!!this._collider}get parentRigidBody(){if(!this._requireNotRemoved("parentRigidBody"))return;return this._parentRigidBody}get rawCollider(){if(!this._requireNotRemoved("rawCollider"))return;return this._collider}get relativePosition(){if(!this._requireNotRemoved("relativePosition"))return{x:0,y:0,z:0};return this._collider?this._collider.translation():this._colliderDesc.translation}get relativeRotation(){if(!this._requireNotRemoved("relativeRotation"))return{x:0,y:0,z:0,w:1};return this._collider?this._collider.rotation():this._colliderDesc.rotation}get shape(){if(!this._requireNotRemoved("shape"))return"none";return this._shape}get tag(){if(!this._requireNotRemoved("tag"))return;return this._tag}setBounciness(J){if(!this._requireNotRemoved("setBounciness"))return;this._collider?this._collider.setRestitution(J):this._colliderDesc.setRestitution(J)}setBouncinessCombineRule(J){if(!this._requireNotRemoved("setBouncinessCombineRule"))return;this._collider?this._collider.setRestitutionCombineRule(J):this._colliderDesc.setRestitutionCombineRule(J)}setCollisionGroups(J){if(!this._requireNotRemoved("setCollisionGroups"))return;let X=q6.buildRawCollisionGroups(J);this._collider?this._collider.setCollisionGroups(X):this._colliderDesc.setCollisionGroups(X)}setEnabled(J){if(!this._requireNotRemoved("setEnabled"))return;this._collider?this._collider.setEnabled(J):this._colliderDesc.setEnabled(J)}setFriction(J){if(!this._requireNotRemoved("setFriction"))return;this._collider?this._collider.setFriction(J):this._colliderDesc.setFriction(J)}setFrictionCombineRule(J){if(!this._requireNotRemoved("setFrictionCombineRule"))return;this._collider?this._collider.setFrictionCombineRule(J):this._colliderDesc.setFrictionCombineRule(J)}setMass(J){if(!this._requireNotRemoved("setMass"))return;this._collider?this._collider.setMass(J):this._colliderDesc.setMass(J)}setOnCollision(J){if(!this._requireNotRemoved("setOnCollision"))return;if(this._onCollision=J,this.isSimulated)if(this.enableCollisionEvents(!!J),J)this._simulation.colliderMap.setColliderCollisionCallback(this,J);else this._simulation.colliderMap.removeColliderCollisionCallback(this)}setRelativeRotation(J){if(!this._requireNotRemoved("setRelativeRotation"))return;this._collider?this._collider.setRotation(J):this._colliderDesc.setRotation(J)}setRelativePosition(J){if(!this._requireNotRemoved("setRelativePosition"))return;this._collider?this._collider.setTranslation(J):this._colliderDesc.setTranslation(J.x,J.y,J.z)}setSensor(J){if(!this._requireNotRemoved("setSensor"))return;this._collider?this._collider.setSensor(J):this._colliderDesc.setSensor(J)}setTag(J){if(!this._requireNotRemoved("setTag"))return;this._tag=J}addToSimulation(J,X){if(!this._requireNotRemoved("addToSimulation"))return;if(!this._requireUnsimulated("addToSimulation"))return;if(X&&!X.isSimulated)return E.error("Collider.addToSimulation(): Rigid body must be simulated before adding a collider to it!");if(this._simulation=J,this._parentRigidBody=X,this._collider=this._simulation.createRawCollider(this._colliderDesc,X?.rawRigidBody),this._colliderDesc=void 0,X)X.linkCollider(this);if(this._onCollision)this.setOnCollision(this._onCollision)}enableCollisionEvents(J){if(!this._requireNotRemoved("enableCollisionEvents"))return;let X=this._collider?this._collider.activeEvents():this._colliderDesc.activeEvents,Y=J?X|z0.ActiveEvents.COLLISION_EVENTS:X&~z0.ActiveEvents.COLLISION_EVENTS;(this._collider??this._colliderDesc).setActiveEvents(Y),this._setActiveCollisionTypes()}enableContactForceEvents(J){if(!this._requireNotRemoved("enableContactForceEvents"))return;let X=this._collider?this._collider.activeEvents():this._colliderDesc.activeEvents,Y=J?X|z0.ActiveEvents.CONTACT_FORCE_EVENTS:X&~z0.ActiveEvents.CONTACT_FORCE_EVENTS;(this._collider??this._colliderDesc).setActiveEvents(Y),this._setActiveCollisionTypes()}removeFromSimulation(){if(!this._requireNotRemoved("removeFromSimulation"))return;if(!this._requireSimulated("removeFromSimulation"))return;if(this._simulation.removeRawCollider(this._collider),this._simulation=void 0,this._collider=void 0,this._parentRigidBody)this._parentRigidBody.unlinkCollider(this);this._parentRigidBody=void 0}_applyColliderOptions(J){[["bounciness",this.setBounciness.bind(this)],["bouncinessCombineRule",this.setBouncinessCombineRule.bind(this)],["collisionGroups",this.setCollisionGroups.bind(this)],["enabled",this.setEnabled.bind(this)],["friction",this.setFriction.bind(this)],["frictionCombineRule",this.setFrictionCombineRule.bind(this)],["isSensor",this.setSensor.bind(this)],["mass",this.setMass.bind(this)],["onCollision",this.setOnCollision.bind(this)],["relativePosition",this.setRelativePosition.bind(this)],["relativeRotation",this.setRelativeRotation.bind(this)],["tag",this.setTag.bind(this)]].forEach(([Y,Z])=>{if(J[Y]!==void 0)Z.call(this,J[Y])})}_autoAddToSimulation(J){if(J.simulation)this.addToSimulation(J.simulation,J.parentRigidBody)}_createColliderDesc(J){let{shape:X,flags:Y}=J;switch(X){case"ball":{if(!J.radius)E.fatalError("Ball collider must have a radius!");return z0.ColliderDesc.ball(J.radius)}case"block":{if(!J.halfExtents)E.fatalError("Block collider must have halfExtents!");return z0.ColliderDesc.cuboid(J.halfExtents.x,J.halfExtents.y,J.halfExtents.z)}case"capsule":{if(!J.halfHeight||!J.radius)E.fatalError("Capsule collider must have halfHeight and radius!");return z0.ColliderDesc.capsule(J.halfHeight,J.radius)}case"cone":{if(!J.radius||!J.halfHeight)E.fatalError("Cone collider must have radius and halfHeight!");return z0.ColliderDesc.cone(J.halfHeight,J.radius)}case"cylinder":{if(!J.radius||!J.halfHeight)E.fatalError("Cylinder collider must have radius and halfHeight!");return z0.ColliderDesc.cylinder(J.halfHeight,J.radius)}case"round-cylinder":{if(!J.radius||!J.halfHeight||!J.borderRadius)E.fatalError("Round cylinder collider must have radius, halfHeight, and borderRadius!");return z0.ColliderDesc.roundCylinder(J.halfHeight,J.radius,J.borderRadius)}case"trimesh":{if(!J.indices||!J.vertices)E.fatalError("Trimesh collider must have vertices and indices!");return z0.ColliderDesc.trimesh(J.vertices,J.indices,Y)}default:E.fatalError(`Collider._createColliderDesc(): ${X} is not a valid collider shape!`)}}_requireSimulated(J){if(!this.isSimulated)E.error(`Collider._requireSimulated(): Collider is not simulated, invoked method: ${J}()`);return this.isSimulated}_requireUnsimulated(J){if(this.isSimulated)E.error(`Collider._requireUnsimulated(): Collider is already simulated, invoked method: ${J}()`);return!this.isSimulated}_requireNotRemoved(J){if(this.isRemoved)E.error(`Collider._requireNotRemoved(): Collider is removed, invoked method: ${J}()`);return!this.isRemoved}_setActiveCollisionTypes(){(this._collider??this._colliderDesc).setActiveCollisionTypes(z0.ActiveCollisionTypes.DYNAMIC_DYNAMIC|z0.ActiveCollisionTypes.DYNAMIC_KINEMATIC|z0.ActiveCollisionTypes.DYNAMIC_FIXED|z0.ActiveCollisionTypes.KINEMATIC_KINEMATIC|z0.ActiveCollisionTypes.KINEMATIC_FIXED)}}var Rc={shape:"trimesh",flags:R4.FIX_INTERNAL_EDGES},wc=new Uint32Array([0,1,2,2,3,0,4,5,6,6,7,4,8,9,10,10,11,8,12,13,14,14,15,12,16,17,18,18,19,16,20,21,22,22,23,20]),Oc=new Float32Array([-0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.5,-0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5]),LG;((Y)=>{Y.ENTITY_COLLISION="BLOCK_TYPE.ENTITY_COLLISION";Y.ENTITY_CONTACT_FORCE="BLOCK_TYPE.ENTITY_CONTACT_FORCE"})(LG||={});class V6 extends s{_id;_customColliderOptions;_isLiquid;_name;_textureUri;constructor(J={id:-1,textureUri:"textures/missing.png",name:"Unknown"}){if(J.id<0)E.fatalError("BlockType.constructor(): BlockType id not set.");super();this._id=J.id,this._customColliderOptions=J.customColliderOptions,this._isLiquid=J.isLiquid??!1,this._name=J.name,this._textureUri=J.textureUri}get id(){return this._id}get colliderOptions(){return{...this._customColliderOptions,...Rc}}get isLiquid(){return this._isLiquid}get isMeshable(){return!this._customColliderOptions}get name(){return this._name}get textureUri(){return this._textureUri}createCollider(J=wc,X=Oc){let Y=new d8({...this.colliderOptions,indices:J,vertices:X});if(this.isLiquid)Y.setSensor(!0);if(this.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))Y.enableCollisionEvents(!0);if(this.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))Y.enableContactForceEvents(!0);if(q6.isDefaultCollisionGroups(Y.collisionGroups))Y.setCollisionGroups({belongsTo:[1],collidesWith:[65535&~1]});return Y}serialize(){return t.serializeBlockType(this)}}var UG;((X)=>X.REGISTER_BLOCK_TYPE="BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE")(UG||={});class d4 extends s{_blockTypes=new Map;_world;constructor(J){super();this._world=J}get world(){return this._world}getAllBlockTypes(){return Array.from(this._blockTypes.values())}getBlockType(J){let X=this._blockTypes.get(J);if(!X)E.fatalError(`BlockTypeRegistry.getBlockType(): BlockType with id ${J} not found.`);return X}registerGenericBlockType(J){let Y=new class extends V6{constructor(Z=J){super(Z)}};return this.registerBlockType(Y),Y}registerBlockType(J){this._blockTypes.set(J.id,J),this.emitWithWorld(this._world,"BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",{blockTypeRegistry:this,id:J.id,blockType:J})}serialize(){return t.serializeBlockTypeRegistry(this)}}var lF={};k6(lF,{worldSchema:()=>mF,worldPacketDefinition:()=>rP,vectorSchema:()=>T0,vectorBooleanSchema:()=>ws,uiSchema:()=>gF,uiPacketDefinition:()=>sP,uiDatasSchema:()=>cF,uiDatasPacketDefinition:()=>oP,uiDataSendPacketDefinition:()=>fP,uiDataSchema:()=>V7,syncResponseSchema:()=>yF,syncResponsePacketDefinition:()=>aP,syncRequestSchema:()=>VF,syncRequestPacketDefinition:()=>hP,stateRequestSchema:()=>UF,stateRequestPacketDefinition:()=>IP,sceneUIsSchema:()=>AF,sceneUIsPacketDefinition:()=>nP,sceneUISchema:()=>pF,rgbColorSchema:()=>b6,registeredPackets:()=>cZ,quaternionSchema:()=>TF,playersSchema:()=>bF,playersPacketDefinition:()=>iP,playerSchema:()=>fF,physicsDebugRenderSchema:()=>hF,physicsDebugRenderPacketDefinition:()=>uP,physicsDebugRaycastsSchema:()=>IF,physicsDebugRaycastsPacketDefinition:()=>dP,physicsDebugRaycastSchema:()=>SF,outboundPackets:()=>gZ,modelNodeOverrideSchema:()=>kF,lightsSchema:()=>CF,lightsPacketDefinition:()=>lP,lightSchema:()=>EF,isValidPacket:()=>xs,inputSchema:()=>LF,inputPacketDefinition:()=>SP,inboundPackets:()=>yZ,hexColorSchema:()=>HF,heartbeatSchema:()=>qF,heartbeatPacketDefinition:()=>_P,entitySchema:()=>DF,entitiesSchema:()=>_F,entitiesPacketDefinition:()=>mP,definePacket:()=>d,debugConfigSchema:()=>zF,debugConfigPacketDefinition:()=>CP,createPacket:()=>Gs,connectionSchema:()=>FF,connectionPacketDefinition:()=>DP,chunksSchema:()=>jF,chunksPacketDefinition:()=>cP,chunkSchema:()=>BF,chatMessagesSchema:()=>vF,chatMessagesPacketDefinition:()=>gP,chatMessageSendPacketDefinition:()=>EP,chatMessageSchema:()=>U7,cameraSchema:()=>NF,cameraPacketDefinition:()=>yP,blocksSchema:()=>OF,blocksPacketDefinition:()=>pP,blockTypesSchema:()=>PF,blockTypesPacketDefinition:()=>AP,blockTypeSchema:()=>xF,blockSchema:()=>wF,bidirectionalPackets:()=>AZ,audiosSchema:()=>RF,audiosPacketDefinition:()=>bP,audioSchema:()=>MF,PacketId:()=>E0});var AZ={};k6(AZ,{heartbeatPacketDefinition:()=>_P,connectionPacketDefinition:()=>DP});var KF=a6(kP(),1);class GF extends KF.default{static instance=new KF.default}var E0;((_)=>{_[_.SYNC_REQUEST=0]="SYNC_REQUEST";_[_.INPUT=1]="INPUT";_[_.STATE_REQUEST=2]="STATE_REQUEST";_[_.CHAT_MESSAGE_SEND=3]="CHAT_MESSAGE_SEND";_[_.UI_DATA_SEND=4]="UI_DATA_SEND";_[_.SYNC_RESPONSE=32]="SYNC_RESPONSE";_[_.AUDIOS=33]="AUDIOS";_[_.BLOCKS=34]="BLOCKS";_[_.BLOCK_TYPES=35]="BLOCK_TYPES";_[_.CHAT_MESSAGES=36]="CHAT_MESSAGES";_[_.CHUNKS=37]="CHUNKS";_[_.ENTITIES=38]="ENTITIES";_[_.WORLD=39]="WORLD";_[_.CAMERA=40]="CAMERA";_[_.UI=41]="UI";_[_.UI_DATAS=42]="UI_DATAS";_[_.SCENE_UIS=43]="SCENE_UIS";_[_.LIGHTS=44]="LIGHTS";_[_.PLAYERS=45]="PLAYERS";_[_.CONNECTION=116]="CONNECTION";_[_.HEARTBEAT=117]="HEARTBEAT";_[_.DEBUG_CONFIG=128]="DEBUG_CONFIG";_[_.PHYSICS_DEBUG_RENDER=192]="PHYSICS_DEBUG_RENDER";_[_.PHYSICS_DEBUG_RAYCASTS=193]="PHYSICS_DEBUG_RAYCASTS"})(E0||={});function Gs(J,X,Y){if(!J.validate(X))throw new Error(`Invalid payload for packet with id ${J.id}. Error: ${GF.instance.errorsText(J.validate.errors)}`);let Z=[J.id,X];if(typeof Y==="number")Z.push(Y);return Z}function d(J,X){return{id:J,schema:X,validate:GF.instance.compile(X)}}var Fs={type:"object",properties:{i:{type:"string"}},required:["i"],additionalProperties:!1},TP={type:"object",properties:{role:{type:"string",enum:["auto","client","server"],nullable:!0},fingerprints:{type:"array",items:{type:"object",properties:{algorithm:{type:"string",enum:["sha-1","sha-224","sha-256","sha-384","sha-512"]},value:{type:"string"}},required:["algorithm","value"]}}},required:["fingerprints"],additionalProperties:!1},qs={type:"object",properties:{foundation:{type:"string"},priority:{type:"number"},ip:{type:"string"},address:{type:"string"},protocol:{type:"string",enum:["udp","tcp"]},port:{type:"number"},type:{type:"string",enum:["host"]},tcpType:{type:"string",enum:["passive"],nullable:!0}},required:["foundation","priority","ip","address","protocol","port","type"],additionalProperties:!1},Hs={type:"object",properties:{usernameFragment:{type:"string"},password:{type:"string"},iceLite:{type:"boolean",nullable:!0}},required:["usernameFragment","password"],additionalProperties:!1},zs={type:"object",properties:{i:{type:"string"},l:{type:"string"}},required:["i","l"],additionalProperties:!1},Ls={type:"object",properties:{port:{type:"number"},OS:{type:"number"},MIS:{type:"number"},maxMessageSize:{type:"number"}},required:["port","OS","MIS","maxMessageSize"],additionalProperties:!0},Us={type:"object",properties:{streamId:{type:"number"},ordered:{type:"boolean",nullable:!0},maxPacketLifeTime:{type:"number",nullable:!0},maxRetransmits:{type:"number",nullable:!0}},required:["streamId"],additionalProperties:!1},Vs={type:"object",properties:{i:{type:"string"},f:{type:"string",enum:["cs","sc"]},ip:Hs,ic:{type:"array",items:qs},d:TP,s:Ls},required:["i","f","ip","ic","d","s"],additionalProperties:!1},Ms={type:"object",properties:{i:{type:"string"},d:TP},required:["i","d"],additionalProperties:!1},Rs={type:"object",properties:{i:{type:"string",nullable:!0},pi:{type:"string",nullable:!0},l:{type:"string"},s:Us},required:["l","s"],additionalProperties:!1},FF={type:"object",properties:{c:{...Ms,nullable:!0},ca:{...Fs,nullable:!0},d:{type:"array",items:{...Rs},nullable:!0},pa:{...zs,nullable:!0},t:{type:"array",items:{...Vs},nullable:!0}},additionalProperties:!1};var DP=d(116,FF);var qF={type:"null",nullable:!0};var _P=d(117,qF);var yZ={};k6(yZ,{uiDataSendPacketDefinition:()=>fP,syncRequestPacketDefinition:()=>hP,stateRequestPacketDefinition:()=>IP,inputPacketDefinition:()=>SP,debugConfigPacketDefinition:()=>CP,chatMessageSendPacketDefinition:()=>EP});var HF={type:"string",pattern:"^[0-9A-Fa-f]{6}$"};var U7={type:"object",properties:{m:{type:"string"},c:{...HF,nullable:!0},p:{type:"string",nullable:!0}},required:["m"],additionalProperties:!1};var EP=d(3,U7);var zF={type:"object",properties:{pdr:{type:"boolean",nullable:!0}},additionalProperties:!1};var CP=d(128,zF);var LF={type:"object",properties:{"1":{type:"boolean",nullable:!0},"2":{type:"boolean",nullable:!0},"3":{type:"boolean",nullable:!0},"4":{type:"boolean",nullable:!0},"5":{type:"boolean",nullable:!0},"6":{type:"boolean",nullable:!0},"7":{type:"boolean",nullable:!0},"8":{type:"boolean",nullable:!0},"9":{type:"boolean",nullable:!0},"0":{type:"boolean",nullable:!0},w:{type:"boolean",nullable:!0},a:{type:"boolean",nullable:!0},s:{type:"boolean",nullable:!0},d:{type:"boolean",nullable:!0},q:{type:"boolean",nullable:!0},e:{type:"boolean",nullable:!0},r:{type:"boolean",nullable:!0},f:{type:"boolean",nullable:!0},z:{type:"boolean",nullable:!0},x:{type:"boolean",nullable:!0},c:{type:"boolean",nullable:!0},v:{type:"boolean",nullable:!0},sp:{type:"boolean",nullable:!0},sh:{type:"boolean",nullable:!0},tb:{type:"boolean",nullable:!0},ml:{type:"boolean",nullable:!0},mr:{type:"boolean",nullable:!0},cp:{type:"number",nullable:!0},cy:{type:"number",nullable:!0},sq:{type:"number",nullable:!0}},additionalProperties:!1};var SP=d(1,LF);var UF={type:"object",properties:{},additionalProperties:!1};var IP=d(2,UF);var VF={type:"null",nullable:!0};var hP=d(0,VF);var V7={type:"object",properties:{},additionalProperties:!0};var fP=d(4,V7);var gZ={};k6(gZ,{worldPacketDefinition:()=>rP,uiPacketDefinition:()=>sP,uiDatasPacketDefinition:()=>oP,syncResponsePacketDefinition:()=>aP,sceneUIsPacketDefinition:()=>nP,playersPacketDefinition:()=>iP,physicsDebugRenderPacketDefinition:()=>uP,physicsDebugRaycastsPacketDefinition:()=>dP,lightsPacketDefinition:()=>lP,entitiesPacketDefinition:()=>mP,chunksPacketDefinition:()=>cP,chatMessagesPacketDefinition:()=>gP,cameraPacketDefinition:()=>yP,blocksPacketDefinition:()=>pP,blockTypesPacketDefinition:()=>AP,audiosPacketDefinition:()=>bP});var T0={type:"array",items:[{type:"number"},{type:"number"},{type:"number"}],minItems:3,maxItems:3};var MF={type:"object",properties:{i:{type:"number"},a:{type:"string",nullable:!0},cd:{type:"number",nullable:!0},d:{type:"number",nullable:!0},de:{type:"number",nullable:!0},di:{type:"number",minimum:0,nullable:!0},e:{type:"number",nullable:!0},l:{type:"boolean",nullable:!0},o:{type:"number",nullable:!0},p:{...T0,nullable:!0},pa:{type:"boolean",nullable:!0},pl:{type:"boolean",nullable:!0},pr:{type:"number",minimum:0,nullable:!0},r:{type:"boolean",nullable:!0},rd:{type:"number",nullable:!0},s:{type:"number",nullable:!0},v:{type:"number",minimum:0,maximum:1,nullable:!0}},required:["i"],additionalProperties:!1};var RF={type:"array",items:{...MF}};var bP=d(33,RF);var wF={type:"object",properties:{i:{type:"number"},c:T0},required:["i","c"],additionalProperties:!1};var OF={type:"array",items:{...wF}};var pP=d(34,OF);var xF={type:"object",properties:{i:{type:"number"},l:{type:"boolean",nullable:!0},n:{type:"string",nullable:!0},t:{type:"string",nullable:!0}},required:["i"],additionalProperties:!1};var PF={type:"array",items:{...xF}};var AP=d(35,PF);var NF={type:"object",properties:{m:{type:"number",nullable:!0},e:{type:"number",nullable:!0},et:{type:"number",nullable:!0},fo:{type:"number",nullable:!0},ffo:{type:"number",nullable:!0},fv:{type:"number",nullable:!0},p:{...T0,nullable:!0},pt:{...T0,nullable:!0},pl:{...T0,nullable:!0},h:{type:"array",items:{type:"string"},nullable:!0},o:{...T0,nullable:!0},z:{type:"number",nullable:!0}},additionalProperties:!1};var vF={type:"array",items:{...U7}};var BF={type:"object",properties:{c:T0,b:{type:"array",items:{type:"number",minimum:0,maximum:255},minItems:4096,maxItems:4096,nullable:!0},rm:{type:"boolean",nullable:!0}},required:["c"],additionalProperties:!1};var jF={type:"array",items:{...BF}};var b6={type:"array",items:[{type:"number",minimum:0,maximum:255},{type:"number",minimum:0,maximum:255},{type:"number",minimum:0,maximum:255}],minItems:3,maxItems:3};var kF={type:"object",properties:{n:{type:"string"},h:{type:"boolean",nullable:!0},o:{type:"number",minimum:0,maximum:1,nullable:!0},r:{type:"boolean",nullable:!0},s:{type:"number",nullable:!0},t:{...b6,nullable:!0}},required:["n"],additionalProperties:!1};var TF={type:"array",items:[{type:"number"},{type:"number"},{type:"number"},{type:"number"}],minItems:4,maxItems:4};var DF={type:"object",properties:{i:{type:"number"},al:{type:"array",items:{type:"string"},nullable:!0},ao:{type:"array",items:{type:"string"},nullable:!0},ap:{type:"number",nullable:!0},as:{type:"array",items:{type:"string"},nullable:!0},bh:{...T0,nullable:!0},bt:{type:"string",nullable:!0},h:{type:"array",items:{type:"string"},nullable:!0},m:{type:"string",nullable:!0},mo:{type:"array",items:{...kF},nullable:!0},n:{type:"string",nullable:!0},o:{type:"number",nullable:!0},p:{...T0,nullable:!0},pe:{type:"number",nullable:!0},pn:{type:"string",nullable:!0},r:{...TF,nullable:!0},rm:{type:"boolean",nullable:!0},s:{type:"number",nullable:!0},t:{...b6,nullable:!0}},required:["i"],additionalProperties:!1};var _F={type:"array",items:{...DF}};var EF={type:"object",properties:{i:{type:"number"},a:{type:"number",nullable:!0},e:{type:"number",nullable:!0},c:{...b6,nullable:!0},d:{type:"number",nullable:!0},n:{type:"number",nullable:!0},o:{...T0,nullable:!0},p:{...T0,nullable:!0},pe:{type:"number",minimum:0,maximum:1,nullable:!0},rm:{type:"boolean",nullable:!0},t:{type:"number",nullable:!0},te:{type:"number",nullable:!0},tp:{...T0,nullable:!0}},required:["i"],additionalProperties:!1};var CF={type:"array",items:{...EF}};var SF={type:"object",properties:{o:{...T0},d:{...T0},l:{type:"number"},h:{type:"boolean"}},required:["o","d","l","h"],additionalProperties:!1};var IF={type:"array",items:{...SF}};var hF={type:"object",properties:{v:{type:"array",items:{type:"number"}},c:{type:"array",items:{type:"number"}}},required:["v","c"],additionalProperties:!1};var fF={type:"object",properties:{i:{type:"string"},p:{type:"string",nullable:!0},rm:{type:"boolean",nullable:!0},u:{type:"string",nullable:!0}},required:["i"],additionalProperties:!1};var bF={type:"array",items:{...fF}};var pF={type:"object",properties:{i:{type:"number"},e:{type:"number",nullable:!0},o:{...T0,nullable:!0},p:{...T0,nullable:!0},rm:{type:"boolean",nullable:!0},s:{type:"object",nullable:!0},t:{type:"string",nullable:!0},v:{type:"number",nullable:!0}},required:["i"],additionalProperties:!1};var AF={type:"array",items:{...pF}};var yF={type:"object",properties:{r:{type:"number"},s:{type:"number"},p:{type:"number"},n:{type:"number"}},required:["r","s","p","n"],additionalProperties:!1};var gF={type:"object",properties:{p:{type:"boolean",nullable:!0},u:{type:"string",nullable:!0}},additionalProperties:!1};var cF={type:"array",items:{...V7}};var ws={type:"array",items:[{type:"boolean"},{type:"boolean"},{type:"boolean"}],minItems:3,maxItems:3};var mF={type:"object",properties:{i:{type:"number"},ac:{...b6,nullable:!0},ai:{type:"number",nullable:!0},dc:{...b6,nullable:!0},di:{type:"number",nullable:!0},dp:{...T0,nullable:!0},f:{type:"boolean",nullable:!0},n:{type:"string",nullable:!0},s:{type:"string",nullable:!0},t:{type:"number",nullable:!0}},required:["i"],additionalProperties:!1};var yP=d(40,NF);var gP=d(36,vF);var cP=d(37,jF);var mP=d(38,_F);var lP=d(44,CF);var uP=d(192,hF);var dP=d(193,IF);var iP=d(45,bF);var nP=d(43,AF);var aP=d(32,yF);var sP=d(41,gF);var oP=d(42,cF);var rP=d(39,mF);var cZ=new Map,Os={...AZ,...yZ,...gZ};for(let J of Object.values(Os))if("id"in J&&"schema"in J){let X=J;if(cZ.has(X.id))throw new Error(`Packet with id ${X.id} is already registered.`);cZ.set(X.id,X)}function xs(J){if(typeof J!=="object"||J===null||typeof J[0]!=="number"||J[0]<0||J[1]===void 0||J[2]!==void 0&&(typeof J[2]!=="number"||J[2]<0))return!1;let X=cZ.get(J[0]);return!!X&&X.validate(J[1])}var A=lF;import{WebSocket as mX0}from"ws";var B8=a6(Xv(),1),_N0=B8.default.v1,EN0=B8.default.v1ToV6,CN0=B8.default.v3,Yv=B8.default.v4,SN0=B8.default.v5,IN0=B8.default.v6,hN0=B8.default.v6ToV1,fN0=B8.default.v7,bN0=B8.default.NIL,pN0=B8.default.MAX,AN0=B8.default.version,yN0=B8.default.validate,gN0=B8.default.stringify,cN0=B8.default.parse;function Zv(J){let X=J.length,Y=0,Z=0;while(Z<X){let W=J.charCodeAt(Z++);if((W&4294967168)===0){Y++;continue}else if((W&4294965248)===0)Y+=2;else{if(W>=55296&&W<=56319){if(Z<X){let $=J.charCodeAt(Z);if(($&64512)===56320)++Z,W=((W&1023)<<10)+($&1023)+65536}}if((W&4294901760)===0)Y+=3;else Y+=4}}return Y}function oo(J,X,Y){let Z=J.length,W=Y,$=0;while($<Z){let Q=J.charCodeAt($++);if((Q&4294967168)===0){X[W++]=Q;continue}else if((Q&4294965248)===0)X[W++]=Q>>6&31|192;else{if(Q>=55296&&Q<=56319){if($<Z){let K=J.charCodeAt($);if((K&64512)===56320)++$,Q=((Q&1023)<<10)+(K&1023)+65536}}if((Q&4294901760)===0)X[W++]=Q>>12&15|224,X[W++]=Q>>6&63|128;else X[W++]=Q>>18&7|240,X[W++]=Q>>12&63|128,X[W++]=Q>>6&63|128}X[W++]=Q&63|128}}var ro=new TextEncoder,to=50;function eo(J,X,Y){ro.encodeInto(J,X.subarray(Y))}function Wv(J,X,Y){if(J.length>to)eo(J,X,Y);else oo(J,X,Y)}var Jr=4096;function oF(J,X,Y){let Z=X,W=Z+Y,$=[],Q="";while(Z<W){let K=J[Z++];if((K&128)===0)$.push(K);else if((K&224)===192){let G=J[Z++]&63;$.push((K&31)<<6|G)}else if((K&240)===224){let G=J[Z++]&63,F=J[Z++]&63;$.push((K&31)<<12|G<<6|F)}else if((K&248)===240){let G=J[Z++]&63,F=J[Z++]&63,q=J[Z++]&63,H=(K&7)<<18|G<<12|F<<6|q;if(H>65535)H-=65536,$.push(H>>>10&1023|55296),H=56320|H&1023;$.push(H)}else $.push(K);if($.length>=Jr)Q+=String.fromCharCode(...$),$.length=0}if($.length>0)Q+=String.fromCharCode(...$);return Q}var Xr=new TextDecoder,Yr=200;function Zr(J,X,Y){let Z=J.subarray(X,X+Y);return Xr.decode(Z)}function $v(J,X,Y){if(Y>Yr)return Zr(J,X,Y);else return oF(J,X,Y)}class R5{constructor(J,X){this.type=J,this.data=X}}class j8 extends Error{constructor(J){super(J);let X=Object.create(j8.prototype);Object.setPrototypeOf(this,X),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:j8.name})}}var w5=4294967295;function Qv(J,X,Y){let Z=Y/4294967296,W=Y;J.setUint32(X,Z),J.setUint32(X+4,W)}function iZ(J,X,Y){let Z=Math.floor(Y/4294967296),W=Y;J.setUint32(X,Z),J.setUint32(X+4,W)}function nZ(J,X){let Y=J.getInt32(X),Z=J.getUint32(X+4);return Y*4294967296+Z}function Kv(J,X){let Y=J.getUint32(X),Z=J.getUint32(X+4);return Y*4294967296+Z}var Wr=-1,$r=4294967295,Qr=17179869183;function Kr({sec:J,nsec:X}){if(J>=0&&X>=0&&J<=Qr)if(X===0&&J<=$r){let Y=new Uint8Array(4);return new DataView(Y.buffer).setUint32(0,J),Y}else{let Y=J/4294967296,Z=J&4294967295,W=new Uint8Array(8),$=new DataView(W.buffer);return $.setUint32(0,X<<2|Y&3),$.setUint32(4,Z),W}else{let Y=new Uint8Array(12),Z=new DataView(Y.buffer);return Z.setUint32(0,X),iZ(Z,4,J),Y}}function Gr(J){let X=J.getTime(),Y=Math.floor(X/1000),Z=(X-Y*1000)*1e6,W=Math.floor(Z/1e9);return{sec:Y+W,nsec:Z-W*1e9}}function Fr(J){if(J instanceof Date){let X=Gr(J);return Kr(X)}else return null}function qr(J){let X=new DataView(J.buffer,J.byteOffset,J.byteLength);switch(J.byteLength){case 4:{let Y=X.getUint32(0),Z=0;return{sec:Y,nsec:0}}case 8:{let Y=X.getUint32(0),Z=X.getUint32(4),W=(Y&3)*4294967296+Z,$=Y>>>2;return{sec:W,nsec:$}}case 12:{let Y=nZ(X,4),Z=X.getUint32(0);return{sec:Y,nsec:Z}}default:throw new j8(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${J.length}`)}}function Hr(J){let X=qr(J);return new Date(X.sec*1000+X.nsec/1e6)}var Gv={type:Wr,encode:Fr,decode:Hr};class V9{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Gv)}register({type:J,encode:X,decode:Y}){if(J>=0)this.encoders[J]=X,this.decoders[J]=Y;else{let Z=-1-J;this.builtInEncoders[Z]=X,this.builtInDecoders[Z]=Y}}tryToEncode(J,X){for(let Y=0;Y<this.builtInEncoders.length;Y++){let Z=this.builtInEncoders[Y];if(Z!=null){let W=Z(J,X);if(W!=null){let $=-1-Y;return new R5($,W)}}}for(let Y=0;Y<this.encoders.length;Y++){let Z=this.encoders[Y];if(Z!=null){let W=Z(J,X);if(W!=null)return new R5(Y,W)}}if(J instanceof R5)return J;return null}decode(J,X,Y){let Z=X<0?this.builtInDecoders[-1-X]:this.decoders[X];if(Z)return Z(J,X,Y);else return new R5(X,J)}}V9.defaultCodec=new V9;function zr(J){return J instanceof ArrayBuffer||typeof SharedArrayBuffer!=="undefined"&&J instanceof SharedArrayBuffer}function w7(J){if(J instanceof Uint8Array)return J;else if(ArrayBuffer.isView(J))return new Uint8Array(J.buffer,J.byteOffset,J.byteLength);else if(zr(J))return new Uint8Array(J);else return Uint8Array.from(J)}var Lr=100,Ur=2048;class aZ{constructor(J){this.entered=!1,this.extensionCodec=J?.extensionCodec??V9.defaultCodec,this.context=J?.context,this.useBigInt64=J?.useBigInt64??!1,this.maxDepth=J?.maxDepth??Lr,this.initialBufferSize=J?.initialBufferSize??Ur,this.sortKeys=J?.sortKeys??!1,this.forceFloat32=J?.forceFloat32??!1,this.ignoreUndefined=J?.ignoreUndefined??!1,this.forceIntegerToFloat=J?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new aZ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(J){if(this.entered)return this.clone().encodeSharedRef(J);try{return this.entered=!0,this.reinitializeState(),this.doEncode(J,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(J){if(this.entered)return this.clone().encode(J);try{return this.entered=!0,this.reinitializeState(),this.doEncode(J,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(J,X){if(X>this.maxDepth)throw new Error(`Too deep objects in depth ${X}`);if(J==null)this.encodeNil();else if(typeof J==="boolean")this.encodeBoolean(J);else if(typeof J==="number")if(!this.forceIntegerToFloat)this.encodeNumber(J);else this.encodeNumberAsFloat(J);else if(typeof J==="string")this.encodeString(J);else if(this.useBigInt64&&typeof J==="bigint")this.encodeBigInt64(J);else this.encodeObject(J,X)}ensureBufferSizeToWrite(J){let X=this.pos+J;if(this.view.byteLength<X)this.resizeBuffer(X*2)}resizeBuffer(J){let X=new ArrayBuffer(J),Y=new Uint8Array(X),Z=new DataView(X);Y.set(this.bytes),this.view=Z,this.bytes=Y}encodeNil(){this.writeU8(192)}encodeBoolean(J){if(J===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(J){if(!this.forceIntegerToFloat&&Number.isSafeInteger(J))if(J>=0)if(J<128)this.writeU8(J);else if(J<256)this.writeU8(204),this.writeU8(J);else if(J<65536)this.writeU8(205),this.writeU16(J);else if(J<4294967296)this.writeU8(206),this.writeU32(J);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(J);else this.encodeNumberAsFloat(J);else if(J>=-32)this.writeU8(224|J+32);else if(J>=-128)this.writeU8(208),this.writeI8(J);else if(J>=-32768)this.writeU8(209),this.writeI16(J);else if(J>=-2147483648)this.writeU8(210),this.writeI32(J);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(J);else this.encodeNumberAsFloat(J);else this.encodeNumberAsFloat(J)}encodeNumberAsFloat(J){if(this.forceFloat32)this.writeU8(202),this.writeF32(J);else this.writeU8(203),this.writeF64(J)}encodeBigInt64(J){if(J>=BigInt(0))this.writeU8(207),this.writeBigUint64(J);else this.writeU8(211),this.writeBigInt64(J)}writeStringHeader(J){if(J<32)this.writeU8(160+J);else if(J<256)this.writeU8(217),this.writeU8(J);else if(J<65536)this.writeU8(218),this.writeU16(J);else if(J<4294967296)this.writeU8(219),this.writeU32(J);else throw new Error(`Too long string: ${J} bytes in UTF-8`)}encodeString(J){let Y=Zv(J);this.ensureBufferSizeToWrite(5+Y),this.writeStringHeader(Y),Wv(J,this.bytes,this.pos),this.pos+=Y}encodeObject(J,X){let Y=this.extensionCodec.tryToEncode(J,this.context);if(Y!=null)this.encodeExtension(Y);else if(Array.isArray(J))this.encodeArray(J,X);else if(ArrayBuffer.isView(J))this.encodeBinary(J);else if(typeof J==="object")this.encodeMap(J,X);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(J)}`)}encodeBinary(J){let X=J.byteLength;if(X<256)this.writeU8(196),this.writeU8(X);else if(X<65536)this.writeU8(197),this.writeU16(X);else if(X<4294967296)this.writeU8(198),this.writeU32(X);else throw new Error(`Too large binary: ${X}`);let Y=w7(J);this.writeU8a(Y)}encodeArray(J,X){let Y=J.length;if(Y<16)this.writeU8(144+Y);else if(Y<65536)this.writeU8(220),this.writeU16(Y);else if(Y<4294967296)this.writeU8(221),this.writeU32(Y);else throw new Error(`Too large array: ${Y}`);for(let Z of J)this.doEncode(Z,X+1)}countWithoutUndefined(J,X){let Y=0;for(let Z of X)if(J[Z]!==void 0)Y++;return Y}encodeMap(J,X){let Y=Object.keys(J);if(this.sortKeys)Y.sort();let Z=this.ignoreUndefined?this.countWithoutUndefined(J,Y):Y.length;if(Z<16)this.writeU8(128+Z);else if(Z<65536)this.writeU8(222),this.writeU16(Z);else if(Z<4294967296)this.writeU8(223),this.writeU32(Z);else throw new Error(`Too large map object: ${Z}`);for(let W of Y){let $=J[W];if(!(this.ignoreUndefined&&$===void 0))this.encodeString(W),this.doEncode($,X+1)}}encodeExtension(J){if(typeof J.data==="function"){let Y=J.data(this.pos+6),Z=Y.length;if(Z>=4294967296)throw new Error(`Too large extension object: ${Z}`);this.writeU8(201),this.writeU32(Z),this.writeI8(J.type),this.writeU8a(Y);return}let X=J.data.length;if(X===1)this.writeU8(212);else if(X===2)this.writeU8(213);else if(X===4)this.writeU8(214);else if(X===8)this.writeU8(215);else if(X===16)this.writeU8(216);else if(X<256)this.writeU8(199),this.writeU8(X);else if(X<65536)this.writeU8(200),this.writeU16(X);else if(X<4294967296)this.writeU8(201),this.writeU32(X);else throw new Error(`Too large extension object: ${X}`);this.writeI8(J.type),this.writeU8a(J.data)}writeU8(J){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,J),this.pos++}writeU8a(J){let X=J.length;this.ensureBufferSizeToWrite(X),this.bytes.set(J,this.pos),this.pos+=X}writeI8(J){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,J),this.pos++}writeU16(J){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,J),this.pos+=2}writeI16(J){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,J),this.pos+=2}writeU32(J){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,J),this.pos+=4}writeI32(J){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,J),this.pos+=4}writeF32(J){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,J),this.pos+=4}writeF64(J){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,J),this.pos+=8}writeU64(J){this.ensureBufferSizeToWrite(8),Qv(this.view,this.pos,J),this.pos+=8}writeI64(J){this.ensureBufferSizeToWrite(8),iZ(this.view,this.pos,J),this.pos+=8}writeBigUint64(J){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,J),this.pos+=8}writeBigInt64(J){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,J),this.pos+=8}}function rF(J,X){return new aZ(X).encodeSharedRef(J)}function sZ(J){return`${J<0?"-":""}0x${Math.abs(J).toString(16).padStart(2,"0")}`}var Vr=16,Mr=16;class tF{constructor(J=Vr,X=Mr){this.hit=0,this.miss=0,this.maxKeyLength=J,this.maxLengthPerKey=X,this.caches=[];for(let Y=0;Y<this.maxKeyLength;Y++)this.caches.push([])}canBeCached(J){return J>0&&J<=this.maxKeyLength}find(J,X,Y){let Z=this.caches[Y-1];J:for(let W of Z){let $=W.bytes;for(let Q=0;Q<Y;Q++)if($[Q]!==J[X+Q])continue J;return W.str}return null}store(J,X){let Y=this.caches[J.length-1],Z={bytes:J,str:X};if(Y.length>=this.maxLengthPerKey)Y[Math.random()*Y.length|0]=Z;else Y.push(Z)}decode(J,X,Y){let Z=this.find(J,X,Y);if(Z!=null)return this.hit++,Z;this.miss++;let W=oF(J,X,Y),$=Uint8Array.prototype.slice.call(J,X,X+Y);return this.store($,W),W}}var eF="array",x7="map_key",qv="map_value",Rr=(J)=>{if(typeof J==="string"||typeof J==="number")return J;throw new j8("The type of key must be string or number but "+typeof J)};class Hv{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(J){let X=this.getUninitializedStateFromPool();X.type=eF,X.position=0,X.size=J,X.array=new Array(J)}pushMapState(J){let X=this.getUninitializedStateFromPool();X.type=x7,X.readCount=0,X.size=J,X.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let J={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(J)}return this.stack[this.stackHeadPosition]}release(J){if(this.stack[this.stackHeadPosition]!==J)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(J.type===eF){let Y=J;Y.size=0,Y.array=void 0,Y.position=0,Y.type=void 0}if(J.type===x7||J.type===qv){let Y=J;Y.size=0,Y.map=void 0,Y.readCount=0,Y.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var O7=-1,J3=new DataView(new ArrayBuffer(0)),wr=new Uint8Array(J3.buffer);try{J3.getInt8(0)}catch(J){if(!(J instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var Fv=new RangeError("Insufficient data"),Or=new tF;class oZ{constructor(J){this.totalPos=0,this.pos=0,this.view=J3,this.bytes=wr,this.headByte=O7,this.stack=new Hv,this.entered=!1,this.extensionCodec=J?.extensionCodec??V9.defaultCodec,this.context=J?.context,this.useBigInt64=J?.useBigInt64??!1,this.rawStrings=J?.rawStrings??!1,this.maxStrLength=J?.maxStrLength??w5,this.maxBinLength=J?.maxBinLength??w5,this.maxArrayLength=J?.maxArrayLength??w5,this.maxMapLength=J?.maxMapLength??w5,this.maxExtLength=J?.maxExtLength??w5,this.keyDecoder=J?.keyDecoder!==void 0?J.keyDecoder:Or,this.mapKeyConverter=J?.mapKeyConverter??Rr}clone(){return new oZ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=O7,this.stack.reset()}setBuffer(J){let X=w7(J);this.bytes=X,this.view=new DataView(X.buffer,X.byteOffset,X.byteLength),this.pos=0}appendBuffer(J){if(this.headByte===O7&&!this.hasRemaining(1))this.setBuffer(J);else{let X=this.bytes.subarray(this.pos),Y=w7(J),Z=new Uint8Array(X.length+Y.length);Z.set(X),Z.set(Y,X.length),this.setBuffer(Z)}}hasRemaining(J){return this.view.byteLength-this.pos>=J}createExtraByteError(J){let{view:X,pos:Y}=this;return new RangeError(`Extra ${X.byteLength-Y} of ${X.byteLength} byte(s) found at buffer[${J}]`)}decode(J){if(this.entered)return this.clone().decode(J);try{this.entered=!0,this.reinitializeState(),this.setBuffer(J);let X=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return X}finally{this.entered=!1}}*decodeMulti(J){if(this.entered){yield*this.clone().decodeMulti(J);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(J);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(J){if(this.entered)return this.clone().decodeAsync(J);try{this.entered=!0;let X=!1,Y;for await(let Q of J){if(X)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(Q);try{Y=this.doDecodeSync(),X=!0}catch(K){if(!(K instanceof RangeError))throw K}this.totalPos+=this.pos}if(X){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Y}let{headByte:Z,pos:W,totalPos:$}=this;throw new RangeError(`Insufficient data in parsing ${sZ(Z)} at ${$} (${W} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(J){return this.decodeMultiAsync(J,!0)}decodeStream(J){return this.decodeMultiAsync(J,!1)}async*decodeMultiAsync(J,X){if(this.entered){yield*this.clone().decodeMultiAsync(J,X);return}try{this.entered=!0;let Y=X,Z=-1;for await(let W of J){if(X&&Z===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(W),Y)Z=this.readArraySize(),Y=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Z===0)break}catch($){if(!($ instanceof RangeError))throw $}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){J:while(!0){let J=this.readHeadByte(),X;if(J>=224)X=J-256;else if(J<192)if(J<128)X=J;else if(J<144){let Z=J-128;if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J<160){let Z=J-144;if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else{let Z=J-160;X=this.decodeString(Z,0)}else if(J===192)X=null;else if(J===194)X=!1;else if(J===195)X=!0;else if(J===202)X=this.readF32();else if(J===203)X=this.readF64();else if(J===204)X=this.readU8();else if(J===205)X=this.readU16();else if(J===206)X=this.readU32();else if(J===207)if(this.useBigInt64)X=this.readU64AsBigInt();else X=this.readU64();else if(J===208)X=this.readI8();else if(J===209)X=this.readI16();else if(J===210)X=this.readI32();else if(J===211)if(this.useBigInt64)X=this.readI64AsBigInt();else X=this.readI64();else if(J===217){let Z=this.lookU8();X=this.decodeString(Z,1)}else if(J===218){let Z=this.lookU16();X=this.decodeString(Z,2)}else if(J===219){let Z=this.lookU32();X=this.decodeString(Z,4)}else if(J===220){let Z=this.readU16();if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else if(J===221){let Z=this.readU32();if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else if(J===222){let Z=this.readU16();if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J===223){let Z=this.readU32();if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J===196){let Z=this.lookU8();X=this.decodeBinary(Z,1)}else if(J===197){let Z=this.lookU16();X=this.decodeBinary(Z,2)}else if(J===198){let Z=this.lookU32();X=this.decodeBinary(Z,4)}else if(J===212)X=this.decodeExtension(1,0);else if(J===213)X=this.decodeExtension(2,0);else if(J===214)X=this.decodeExtension(4,0);else if(J===215)X=this.decodeExtension(8,0);else if(J===216)X=this.decodeExtension(16,0);else if(J===199){let Z=this.lookU8();X=this.decodeExtension(Z,1)}else if(J===200){let Z=this.lookU16();X=this.decodeExtension(Z,2)}else if(J===201){let Z=this.lookU32();X=this.decodeExtension(Z,4)}else throw new j8(`Unrecognized type byte: ${sZ(J)}`);this.complete();let Y=this.stack;while(Y.length>0){let Z=Y.top();if(Z.type===eF)if(Z.array[Z.position]=X,Z.position++,Z.position===Z.size)X=Z.array,Y.release(Z);else continue J;else if(Z.type===x7){if(X==="__proto__")throw new j8("The key __proto__ is not allowed");Z.key=this.mapKeyConverter(X),Z.type=qv;continue J}else if(Z.map[Z.key]=X,Z.readCount++,Z.readCount===Z.size)X=Z.map,Y.release(Z);else{Z.key=null,Z.type=x7;continue J}}return X}}readHeadByte(){if(this.headByte===O7)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=O7}readArraySize(){let J=this.readHeadByte();switch(J){case 220:return this.readU16();case 221:return this.readU32();default:if(J<160)return J-144;else throw new j8(`Unrecognized array type byte: ${sZ(J)}`)}}pushMapState(J){if(J>this.maxMapLength)throw new j8(`Max length exceeded: map length (${J}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(J)}pushArrayState(J){if(J>this.maxArrayLength)throw new j8(`Max length exceeded: array length (${J}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(J)}decodeString(J,X){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(J,X);return this.decodeBinary(J,X)}decodeUtf8String(J,X){if(J>this.maxStrLength)throw new j8(`Max length exceeded: UTF-8 byte length (${J}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+X+J)throw Fv;let Y=this.pos+X,Z;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(J))Z=this.keyDecoder.decode(this.bytes,Y,J);else Z=$v(this.bytes,Y,J);return this.pos+=X+J,Z}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===x7;return!1}decodeBinary(J,X){if(J>this.maxBinLength)throw new j8(`Max length exceeded: bin length (${J}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(J+X))throw Fv;let Y=this.pos+X,Z=this.bytes.subarray(Y,Y+J);return this.pos+=X+J,Z}decodeExtension(J,X){if(J>this.maxExtLength)throw new j8(`Max length exceeded: ext length (${J}) > maxExtLength (${this.maxExtLength})`);let Y=this.view.getInt8(this.pos+X),Z=this.decodeBinary(J,X+1);return this.extensionCodec.decode(Z,Y,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let J=this.view.getUint8(this.pos);return this.pos++,J}readI8(){let J=this.view.getInt8(this.pos);return this.pos++,J}readU16(){let J=this.view.getUint16(this.pos);return this.pos+=2,J}readI16(){let J=this.view.getInt16(this.pos);return this.pos+=2,J}readU32(){let J=this.view.getUint32(this.pos);return this.pos+=4,J}readI32(){let J=this.view.getInt32(this.pos);return this.pos+=4,J}readU64(){let J=Kv(this.view,this.pos);return this.pos+=8,J}readI64(){let J=nZ(this.view,this.pos);return this.pos+=8,J}readU64AsBigInt(){let J=this.view.getBigUint64(this.pos);return this.pos+=8,J}readI64AsBigInt(){let J=this.view.getBigInt64(this.pos);return this.pos+=8,J}readF32(){let J=this.view.getFloat32(this.pos);return this.pos+=4,J}readF64(){let J=this.view.getFloat64(this.pos);return this.pos+=8,J}}function X3(J,X){return new oZ(X).decode(J)}import{WebSocketServer as gX0}from"ws";import cX0 from"mediasoup";var Z$=a6(nE(),1);import bX0 from"http";import pX0 from"https";import I9 from"fs";import AX0 from"path";import yX0 from"url";var wC=a6(MC(),1);import S9 from"fs";import RC from"path";var xJ="./dev/persistence";class u6{static instance=new u6;gameId=process.env.HYTOPIA_GAME_ID;lobbyId=process.env.HYTOPIA_LOBBY_ID;_creativeGateway;constructor(){try{this._creativeGateway=new wC.CreativeGateway}catch{console.warn(["\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501","\uD83D\uDEA8 HYTOPIA PLATFORM GATEWAY IS NOT INITIALIZED \uD83D\uDEA8","","\uD83D\uDD27 Local development is still possible, but these features will be disabled:"," \u2022 \uD83D\uDC64 Player Accounts"," \u2022 \uD83C\uDFAD Player Cosmetics"," \u2022 \uD83D\uDC1B Crash Analytics & Debug Logs","","\uD83D\uDCA1 These features will be enabled but modified:"," \u2022 \uD83D\uDCBE Player & Global Persisted Data - Data will be persisted"," locally in the ./dev/persistence directory of your project."," Player ids for data persistence will begin at 1 for the first "," player to join your local server, and increments for each"," additional player. This means that if you restart your"," server, the first player id will be 1 again. This is to ensure"," that data persistence across server restarts can be easily"," tested and debugged in local development.","","To enable the HYTOPIA Platform Gateway locally:"," 1. Set these environment variables:"," HYTOPIA_API_KEY, HYTOPIA_GAME_ID, HYTOPIA_LOBBY_ID"," 2. You can find these values at: https://create.hytopia.com","","Note: In production, these environment variables will be auto-populated ","& the HYTOPIA Platform Gateway will automatically be initialized \uD83D\uDE80","\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",""].join(`
|
379
|
+
if (condition) { yield value; }`)};import{Buffer as hp}from"buffer";import{StringDecoder as fp}from"string_decoder";var wY=(J,X,Y)=>{if(Y)return;if(J)return{transform:bp.bind(void 0,new TextEncoder)};let Z=new fp(X);return{transform:pp.bind(void 0,Z),final:Ap.bind(void 0,Z)}},bp=function*(J,X){if(hp.isBuffer(X))yield e6(X);else if(typeof X==="string")yield J.encode(X);else yield X},pp=function*(J,X){yield J8(X)?J.write(X):X},Ap=function*(J){let X=J.end();if(X!=="")yield X};import{callbackify as tV}from"util";var MK=tV(async(J,X,Y,Z)=>{X.currentIterable=J(...Y);try{for await(let W of X.currentIterable)Z.push(W)}finally{delete X.currentIterable}}),OY=async function*(J,X,Y){if(Y===X.length){yield J;return}let{transform:Z=gp}=X[Y];for await(let W of Z(J))yield*OY(W,X,Y+1)},eV=async function*(J){for(let[X,{final:Y}]of Object.entries(J))yield*yp(Y,Number(X),J)},yp=async function*(J,X,Y){if(J===void 0)return;for await(let Z of J())yield*OY(Z,Y,X+1)},JM=tV(async({currentIterable:J},X)=>{if(J!==void 0){await(X?J.throw(X):J.return());return}if(X)throw X}),gp=function*(J){yield J};var RK=(J,X,Y,Z)=>{try{for(let W of J(...X))Y.push(W);Z()}catch(W){Z(W)}},XM=(J,X)=>[...X.flatMap((Y)=>[...W9(Y,J,0)]),...h4(J)],W9=function*(J,X,Y){if(Y===X.length){yield J;return}let{transform:Z=mp}=X[Y];for(let W of Z(J))yield*W9(W,X,Y+1)},h4=function*(J){for(let[X,{final:Y}]of Object.entries(J))yield*cp(Y,Number(X),J)},cp=function*(J,X,Y){if(J===void 0)return;for(let Z of J())yield*W9(Z,Y,X+1)},mp=function*(J){yield J};var wK=({value:J,value:{transform:X,final:Y,writableObjectMode:Z,readableObjectMode:W},optionName:$},{encoding:Q})=>{let K={},G=ZM(J,Q,$),F=Z9(X),q=Z9(Y),H=F?MK.bind(void 0,OY,K):RK.bind(void 0,W9),z=F||q?MK.bind(void 0,eV,K):RK.bind(void 0,h4),V=F||q?JM.bind(void 0,K):void 0;return{stream:new lp({writableObjectMode:Z,writableHighWaterMark:YM(Z),readableObjectMode:W,readableHighWaterMark:YM(W),transform(R,L,w){H([R,G,0],this,w)},flush(R){z([G],this,R)},destroy:V})}},xY=(J,X,Y,Z)=>{let W=X.filter(({type:Q})=>Q==="generator"),$=Z?W.reverse():W;for(let{value:Q,optionName:K}of $){let G=ZM(Q,Y,K);J=XM(G,J)}return J},ZM=({transform:J,final:X,binary:Y,writableObjectMode:Z,readableObjectMode:W,preserveNewlines:$},Q,K)=>{let G={};return[{transform:sV(Z,K)},wY(Y,Q,Z),RY(Y,$,Z,G),{transform:J,final:X},{transform:oV(W,K)},aV({binary:Y,preserveNewlines:$,readableObjectMode:W,state:G})].filter(Boolean)};var WM=(J,X)=>{for(let Y of up(J))dp(J,Y,X)},up=(J)=>new Set(Object.entries(J).filter(([,{direction:X}])=>X==="input").map(([X])=>Number(X))),dp=(J,X,Y)=>{let{stdioItems:Z}=J[X],W=Z.filter(({contents:K})=>K!==void 0);if(W.length===0)return;if(X!==0){let[{type:K,optionName:G}]=W;throw new TypeError(`Only the \`stdin\` option, not \`${G}\`, can be ${B1[K]} with synchronous methods.`)}let Q=W.map(({contents:K})=>K).map((K)=>ip(K,Z));Y.input=k4(Q)},ip=(J,X)=>{let Y=xY(J,X,"utf8",!0);return np(Y),k4(Y)},np=(J)=>{let X=J.find((Y)=>typeof Y!=="string"&&!J8(Y));if(X!==void 0)throw new TypeError(`The \`stdin\` option is invalid: when passing objects as input, a transform must be used to serialize them to strings or Uint8Arrays: ${X}.`)};import{writeFileSync as rp,appendFileSync as tp}from"fs";var PY=({stdioItems:J,encoding:X,verboseInfo:Y,fdNumber:Z})=>Z!=="all"&&d9(Y,Z)&&!l8.has(X)&&ap(Z)&&(J.some(({type:W,value:$})=>W==="native"&&sp.has($))||J.every(({type:W})=>s8.has(W))),ap=(J)=>J===1||J===2,sp=new Set(["pipe","overlapped"]),$M=async(J,X,Y,Z)=>{for await(let W of J)if(!op(X))KM(W,Y,Z)},QM=(J,X,Y)=>{for(let Z of J)KM(Z,X,Y)},op=(J)=>J._readableState.pipes.length>0,KM=(J,X,Y)=>{let Z=SX(J);D6({type:"output",verboseMessage:Z,fdNumber:X,verboseInfo:Y})};var GM=({fileDescriptors:J,syncResult:{output:X},options:Y,isMaxBuffer:Z,verboseInfo:W})=>{if(X===null)return{output:Array.from({length:3})};let $={},Q=new Set([]);return{output:X.map((G,F)=>ep({result:G,fileDescriptors:J,fdNumber:F,state:$,outputFiles:Q,isMaxBuffer:Z,verboseInfo:W},Y)),...$}},ep=({result:J,fileDescriptors:X,fdNumber:Y,state:Z,outputFiles:W,isMaxBuffer:$,verboseInfo:Q},{buffer:K,encoding:G,lines:F,stripFinalNewline:q,maxBuffer:H})=>{if(J===null)return;let z=FV(J,$,H),V=e6(z),{stdioItems:M,objectMode:R}=X[Y],L=JA([V],M,G,Z),{serializedResult:w,finalResult:P=w}=XA({chunks:L,objectMode:R,encoding:G,lines:F,stripFinalNewline:q,fdNumber:Y});YA({serializedResult:w,fdNumber:Y,state:Z,verboseInfo:Q,encoding:G,stdioItems:M,objectMode:R});let N=K[Y]?P:void 0;try{if(Z.error===void 0)ZA(w,M,W);return N}catch(v){return Z.error=v,N}},JA=(J,X,Y,Z)=>{try{return xY(J,X,Y,!1)}catch(W){return Z.error=W,J}},XA=({chunks:J,objectMode:X,encoding:Y,lines:Z,stripFinalNewline:W,fdNumber:$})=>{if(X)return{serializedResult:J};if(Y==="buffer")return{serializedResult:k4(J)};let Q=vz(J,Y);if(Z[$])return{serializedResult:Q,finalResult:VK(Q,!W[$],X)};return{serializedResult:Q}},YA=({serializedResult:J,fdNumber:X,state:Y,verboseInfo:Z,encoding:W,stdioItems:$,objectMode:Q})=>{if(!PY({stdioItems:$,encoding:W,verboseInfo:Z,fdNumber:X}))return;let K=VK(J,!1,Q);try{QM(K,X,Z)}catch(G){Y.error??=G}},ZA=(J,X,Y)=>{for(let{path:Z,append:W}of X.filter(({type:$})=>VY.has($))){let $=typeof Z==="string"?Z:Z.toString();if(W||Y.has($))tp(Z,J);else Y.add($),rp(Z,J)}};var FM=([,J,X],Y)=>{if(!Y.all)return;if(J===void 0)return X;if(X===void 0)return J;if(Array.isArray(J))return Array.isArray(X)?[...J,...X]:[...J,Z1(X,Y,"all")];if(Array.isArray(X))return[Z1(J,Y,"all"),...X];if(J8(J)&&J8(X))return BQ([J,X]);return`${J}${X}`};import{once as OK}from"events";var qM=async(J,X)=>{let[Y,Z]=await WA(J);return X.isForcefullyTerminated??=!1,[Y,Z]},WA=async(J)=>{let[X,Y]=await Promise.allSettled([OK(J,"spawn"),OK(J,"exit")]);if(X.status==="rejected")return[];return Y.status==="rejected"?HM(J):Y.value},HM=async(J)=>{try{return await OK(J,"exit")}catch{return HM(J)}},zM=async(J)=>{let[X,Y]=await J;if(!$A(X,Y)&&xK(X,Y))throw new _6;return[X,Y]},$A=(J,X)=>J===void 0&&X===void 0,xK=(J,X)=>J!==0||X!==null;var LM=({error:J,status:X,signal:Y,output:Z},{maxBuffer:W})=>{let $=QA(J,X,Y),Q=$?.code==="ETIMEDOUT",K=GV($,Z,W);return{resultError:$,exitCode:X,signal:Y,timedOut:Q,isMaxBuffer:K}},QA=(J,X,Y)=>{if(J!==void 0)return J;return xK(X,Y)?new _6:void 0};var UM=(J,X,Y)=>{let{file:Z,commandArguments:W,command:$,escapedCommand:Q,startTime:K,verboseInfo:G,options:F,fileDescriptors:q}=GA(J,X,Y),H=HA({file:Z,commandArguments:W,options:F,command:$,escapedCommand:Q,verboseInfo:G,fileDescriptors:q,startTime:K});return J5(H,G,F)},GA=(J,X,Y)=>{let{command:Z,escapedCommand:W,startTime:$,verboseInfo:Q}=hX(J,X,Y),K=FA(Y),{file:G,commandArguments:F,options:q}=ZY(J,X,K);qA(q);let H=uV(q,Q);return{file:G,commandArguments:F,command:Z,escapedCommand:W,startTime:$,verboseInfo:Q,options:q,fileDescriptors:H}},FA=(J)=>J.node&&!J.ipc?{...J,ipc:!1}:J,qA=({ipc:J,ipcInput:X,detached:Y,cancelSignal:Z})=>{if(X)NY("ipcInput");if(J)NY("ipc: true");if(Y)NY("detached: true");if(Z)NY("cancelSignal")},NY=(J)=>{throw new TypeError(`The "${J}" option cannot be used with synchronous methods.`)},HA=({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,verboseInfo:$,fileDescriptors:Q,startTime:K})=>{let G=zA({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,fileDescriptors:Q,startTime:K});if(G.failed)return G;let{resultError:F,exitCode:q,signal:H,timedOut:z,isMaxBuffer:V}=LM(G,Y),{output:M,error:R=F}=GM({fileDescriptors:Q,syncResult:G,options:Y,isMaxBuffer:V,verboseInfo:$}),L=M.map((P,N)=>Z1(P,Y,N)),w=Z1(FM(M,Y),Y,"all");return UA({error:R,exitCode:q,signal:H,timedOut:z,isMaxBuffer:V,stdio:L,all:w,options:Y,command:Z,escapedCommand:W,startTime:K})},zA=({file:J,commandArguments:X,options:Y,command:Z,escapedCommand:W,fileDescriptors:$,startTime:Q})=>{try{WM($,Y);let K=LA(Y);return KA(J,X,K)}catch(K){return e9({error:K,command:Z,escapedCommand:W,fileDescriptors:$,options:Y,startTime:Q,isSync:!0})}},LA=({encoding:J,maxBuffer:X,...Y})=>({...Y,encoding:"buffer",maxBuffer:HY(X)}),UA=({error:J,exitCode:X,signal:Y,timedOut:Z,isMaxBuffer:W,stdio:$,all:Q,options:K,command:G,escapedCommand:F,startTime:q})=>J===void 0?zY({command:G,escapedCommand:F,stdio:$,all:Q,ipcOutput:[],options:K,startTime:q}):I4({error:J,command:G,escapedCommand:F,timedOut:Z,isCanceled:!1,isGracefullyCanceled:!1,isMaxBuffer:W,isForcefullyTerminated:!1,exitCode:X,signal:Y,stdio:$,all:Q,ipcOutput:[],options:K,startTime:q,isSync:!0});import{setMaxListeners as Xg}from"events";import{spawn as Yg}from"child_process";import OM from"process";import{once as PK,on as VA}from"events";var VM=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z},{reference:W=!0,filter:$}={})=>{return a9({methodName:"getOneMessage",isSubprocess:Y,ipc:Z,isConnected:rX(J)}),MA({anyProcess:J,channel:X,isSubprocess:Y,filter:$,reference:W})},MA=async({anyProcess:J,channel:X,isSubprocess:Y,filter:Z,reference:W})=>{nX(X,W);let $=v1(J,X,Y),Q=new AbortController;try{return await Promise.race([RA($,Z,Q),wA($,Y,Q),OA($,Y,Q)])}catch(K){throw s9(J),K}finally{Q.abort(),aX(X,W)}},RA=async(J,X,{signal:Y})=>{if(X===void 0){let[Z]=await PK(J,"message",{signal:Y});return Z}for await(let[Z]of VA(J,"message",{signal:Y}))if(X(Z))return Z},wA=async(J,X,{signal:Y})=>{await PK(J,"disconnect",{signal:Y}),JU(X)},OA=async(J,X,{signal:Y})=>{let[Z]=await PK(J,"strict:error",{signal:Y});throw uX(Z,X)};import{once as RM,on as xA}from"events";var wM=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z},{reference:W=!0}={})=>NK({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z,shouldAwait:!Y,reference:W}),NK=({anyProcess:J,channel:X,isSubprocess:Y,ipc:Z,shouldAwait:W,reference:$})=>{a9({methodName:"getEachMessage",isSubprocess:Y,ipc:Z,isConnected:rX(J)}),nX(X,$);let Q=v1(J,X,Y),K=new AbortController,G={};return PA(J,Q,K),NA({ipcEmitter:Q,isSubprocess:Y,controller:K,state:G}),vA({anyProcess:J,channel:X,ipcEmitter:Q,isSubprocess:Y,shouldAwait:W,controller:K,state:G,reference:$})},PA=async(J,X,Y)=>{try{await RM(X,"disconnect",{signal:Y.signal}),Y.abort()}catch{}},NA=async({ipcEmitter:J,isSubprocess:X,controller:Y,state:Z})=>{try{let[W]=await RM(J,"strict:error",{signal:Y.signal});Z.error=uX(W,X),Y.abort()}catch{}},vA=async function*({anyProcess:J,channel:X,ipcEmitter:Y,isSubprocess:Z,shouldAwait:W,controller:$,state:Q,reference:K}){try{for await(let[G]of xA(Y,"message",{signal:$.signal}))MM(Q),yield G}catch{MM(Q)}finally{if($.abort(),aX(X,K),!Z)s9(J);if(W)await J}},MM=({error:J})=>{if(J)throw J};var xM=(J,{ipc:X})=>{Object.assign(J,NM(J,!1,X))},PM=()=>{let J=OM,X=!0,Y=OM.channel!==void 0;return{...NM(J,!0,Y),getCancelSignal:TU.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:!0,ipc:Y})}},NM=(J,X,Y)=>({sendMessage:XY.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y}),getOneMessage:VM.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y}),getEachMessage:wM.bind(void 0,{anyProcess:J,channel:J.channel,isSubprocess:X,ipc:Y})});import{ChildProcess as BA}from"child_process";import{PassThrough as jA,Readable as kA,Writable as TA,Duplex as DA}from"stream";var vM=({error:J,command:X,escapedCommand:Y,fileDescriptors:Z,options:W,startTime:$,verboseInfo:Q})=>{zK(Z);let K=new BA;_A(K,Z),Object.assign(K,{readable:EA,writable:CA,duplex:SA});let G=e9({error:J,command:X,escapedCommand:Y,fileDescriptors:Z,options:W,startTime:$,isSync:!1}),F=IA(G,Q,W);return{subprocess:K,promise:F}},_A=(J,X)=>{let Y=f4(),Z=f4(),W=f4(),$=Array.from({length:X.length-3},f4),Q=f4(),K=[Y,Z,W,...$];Object.assign(J,{stdin:Y,stdout:Z,stderr:W,all:Q,stdio:K})},f4=()=>{let J=new jA;return J.end(),J},EA=()=>new kA({read(){}}),CA=()=>new TA({write(){}}),SA=()=>new DA({read(){},write(){}}),IA=async(J,X,Y)=>J5(J,X,Y);import{createReadStream as BM,createWriteStream as jM}from"fs";import{Buffer as hA}from"buffer";import{Readable as b4,Writable as fA,Duplex as bA}from"stream";var TM=(J,X)=>MY(pA,J,X,!1),p4=({type:J,optionName:X})=>{throw new TypeError(`The \`${X}\` option cannot be ${B1[J]}.`)},kM={fileNumber:p4,generator:wK,asyncGenerator:wK,nodeStream:({value:J})=>({stream:J}),webTransform({value:{transform:J,writableObjectMode:X,readableObjectMode:Y}}){let Z=X||Y;return{stream:bA.fromWeb(J,{objectMode:Z})}},duplex:({value:{transform:J}})=>({stream:J}),native(){}},pA={input:{...kM,fileUrl:({value:J})=>({stream:BM(J)}),filePath:({value:{file:J}})=>({stream:BM(J)}),webStream:({value:J})=>({stream:b4.fromWeb(J)}),iterable:({value:J})=>({stream:b4.from(J)}),asyncIterable:({value:J})=>({stream:b4.from(J)}),string:({value:J})=>({stream:b4.from(J)}),uint8Array:({value:J})=>({stream:b4.from(hA.from(J))})},output:{...kM,fileUrl:({value:J})=>({stream:jM(J)}),filePath:({value:{file:J,append:X}})=>({stream:jM(J,X?{flags:"a"}:{})}),webStream:({value:J})=>({stream:fA.fromWeb(J)}),iterable:p4,asyncIterable:p4,string:p4,uint8Array:p4}};import{on as AA,once as DM}from"events";import{PassThrough as yA,getDefaultHighWaterMark as gA}from"stream";import{finished as CM}from"stream/promises";function $9(J){if(!Array.isArray(J))throw new TypeError(`Expected an array, got \`${typeof J}\`.`);for(let W of J)vK(W);let X=J.some(({readableObjectMode:W})=>W),Y=cA(J,X),Z=new SM({objectMode:X,writableHighWaterMark:Y,readableHighWaterMark:Y});for(let W of J)Z.add(W);return Z}var cA=(J,X)=>{if(J.length===0)return gA(X);let Y=J.filter(({readableObjectMode:Z})=>Z===X).map(({readableHighWaterMark:Z})=>Z);return Math.max(...Y)};class SM extends yA{#X=new Set([]);#Y=new Set([]);#J=new Set([]);#Z;#$=Symbol("unpipe");#W=new WeakMap;add(J){if(vK(J),this.#X.has(J))return;this.#X.add(J),this.#Z??=mA(this,this.#X,this.#$);let X=dA({passThroughStream:this,stream:J,streams:this.#X,ended:this.#Y,aborted:this.#J,onFinished:this.#Z,unpipeEvent:this.#$});this.#W.set(J,X),J.pipe(this,{end:!1})}async remove(J){if(vK(J),!this.#X.has(J))return!1;let X=this.#W.get(J);if(X===void 0)return!1;return this.#W.delete(J),J.unpipe(this),await X,!0}}var mA=async(J,X,Y)=>{vY(J,_M);let Z=new AbortController;try{await Promise.race([lA(J,Z),uA(J,X,Y,Z)])}finally{Z.abort(),vY(J,-_M)}},lA=async(J,{signal:X})=>{try{await CM(J,{signal:X,cleanup:!0})}catch(Y){throw IM(J,Y),Y}},uA=async(J,X,Y,{signal:Z})=>{for await(let[W]of AA(J,"unpipe",{signal:Z}))if(X.has(W))W.emit(Y)},vK=(J)=>{if(typeof J?.pipe!=="function")throw new TypeError(`Expected a readable stream, got: \`${typeof J}\`.`)},dA=async({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,onFinished:$,unpipeEvent:Q})=>{vY(J,EM);let K=new AbortController;try{await Promise.race([iA($,X,K),nA({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,controller:K}),aA({stream:X,streams:Y,ended:Z,aborted:W,unpipeEvent:Q,controller:K})])}finally{K.abort(),vY(J,-EM)}if(Y.size>0&&Y.size===Z.size+W.size)if(Z.size===0&&W.size>0)BK(J);else sA(J)},iA=async(J,X,{signal:Y})=>{try{if(await J,!Y.aborted)BK(X)}catch(Z){if(!Y.aborted)IM(X,Z)}},nA=async({passThroughStream:J,stream:X,streams:Y,ended:Z,aborted:W,controller:{signal:$}})=>{try{if(await CM(X,{signal:$,cleanup:!0,readable:!0,writable:!1}),Y.has(X))Z.add(X)}catch(Q){if($.aborted||!Y.has(X))return;if(hM(Q))W.add(X);else fM(J,Q)}},aA=async({stream:J,streams:X,ended:Y,aborted:Z,unpipeEvent:W,controller:{signal:$}})=>{if(await DM(J,W,{signal:$}),!J.readable)return DM($,"abort",{signal:$});X.delete(J),Y.delete(J),Z.delete(J)},sA=(J)=>{if(J.writable)J.end()},IM=(J,X)=>{if(hM(X))BK(J);else fM(J,X)},hM=(J)=>J?.code==="ERR_STREAM_PREMATURE_CLOSE",BK=(J)=>{if(J.readable||J.writable)J.destroy()},fM=(J,X)=>{if(!J.destroyed)J.once("error",oA),J.destroy(X)},oA=()=>{},vY=(J,X)=>{let Y=J.getMaxListeners();if(Y!==0&&Y!==Number.POSITIVE_INFINITY)J.setMaxListeners(Y+X)},_M=2,EM=1;import{finished as bM}from"stream/promises";var Y5=(J,X)=>{J.pipe(X),rA(J,X),tA(J,X)},rA=async(J,X)=>{if(H6(J)||H6(X))return;try{await bM(J,{cleanup:!0,readable:!0,writable:!1})}catch{}jK(X)},jK=(J)=>{if(J.writable)J.end()},tA=async(J,X)=>{if(H6(J)||H6(X))return;try{await bM(X,{cleanup:!0,readable:!1,writable:!0})}catch{}kK(J)},kK=(J)=>{if(J.readable)J.destroy()};var pM=(J,X,Y)=>{let Z=new Map;for(let[W,{stdioItems:$,direction:Q}]of Object.entries(X)){for(let{stream:K}of $.filter(({type:G})=>s8.has(G)))eA(J,K,Q,W);for(let{stream:K}of $.filter(({type:G})=>!s8.has(G)))Xy({subprocess:J,stream:K,direction:Q,fdNumber:W,pipeGroups:Z,controller:Y})}for(let[W,$]of Z.entries()){let Q=$.length===1?$[0]:$9($);Y5(Q,W)}},eA=(J,X,Y,Z)=>{if(Y==="output")Y5(J.stdio[Z],X);else Y5(X,J.stdio[Z]);let W=Jy[Z];if(W!==void 0)J[W]=X;J.stdio[Z]=X},Jy=["stdin","stdout","stderr"],Xy=({subprocess:J,stream:X,direction:Y,fdNumber:Z,pipeGroups:W,controller:$})=>{if(X===void 0)return;Yy(X,$);let[Q,K]=Y==="output"?[X,J.stdio[Z]]:[J.stdio[Z],X],G=W.get(Q)??[];W.set(Q,[...G,K])},Yy=(J,{signal:X})=>{if(H6(J))X9(J,Zy,X)},Zy=2;import{addAbortListener as Qy}from"events";var Q9=[];Q9.push("SIGHUP","SIGINT","SIGTERM");if(process.platform!=="win32")Q9.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(process.platform==="linux")Q9.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var BY=(J)=>!!J&&typeof J==="object"&&typeof J.removeListener==="function"&&typeof J.emit==="function"&&typeof J.reallyExit==="function"&&typeof J.listeners==="function"&&typeof J.kill==="function"&&typeof J.pid==="number"&&typeof J.on==="function",TK=Symbol.for("signal-exit emitter"),DK=globalThis,Wy=Object.defineProperty.bind(Object);class AM{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(DK[TK])return DK[TK];Wy(DK,TK,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(J,X){this.listeners[J].push(X)}removeListener(J,X){let Y=this.listeners[J],Z=Y.indexOf(X);if(Z===-1)return;if(Z===0&&Y.length===1)Y.length=0;else Y.splice(Z,1)}emit(J,X,Y){if(this.emitted[J])return!1;this.emitted[J]=!0;let Z=!1;for(let W of this.listeners[J])Z=W(X,Y)===!0||Z;if(J==="exit")Z=this.emit("afterExit",X,Y)||Z;return Z}}class EK{}var $y=(J)=>{return{onExit(X,Y){return J.onExit(X,Y)},load(){return J.load()},unload(){return J.unload()}}};class yM extends EK{onExit(){return()=>{}}load(){}unload(){}}class gM extends EK{#X=_K.platform==="win32"?"SIGINT":"SIGHUP";#Y=new AM;#J;#Z;#$;#W={};#Q=!1;constructor(J){super();this.#J=J,this.#W={};for(let X of Q9)this.#W[X]=()=>{let Y=this.#J.listeners(X),{count:Z}=this.#Y,W=J;if(typeof W.__signal_exit_emitter__==="object"&&typeof W.__signal_exit_emitter__.count==="number")Z+=W.__signal_exit_emitter__.count;if(Y.length===Z){this.unload();let $=this.#Y.emit("exit",null,X),Q=X==="SIGHUP"?this.#X:X;if(!$)J.kill(J.pid,Q)}};this.#$=J.reallyExit,this.#Z=J.emit}onExit(J,X){if(!BY(this.#J))return()=>{};if(this.#Q===!1)this.load();let Y=X?.alwaysLast?"afterExit":"exit";return this.#Y.on(Y,J),()=>{if(this.#Y.removeListener(Y,J),this.#Y.listeners.exit.length===0&&this.#Y.listeners.afterExit.length===0)this.unload()}}load(){if(this.#Q)return;this.#Q=!0,this.#Y.count+=1;for(let J of Q9)try{let X=this.#W[J];if(X)this.#J.on(J,X)}catch(X){}this.#J.emit=(J,...X)=>{return this.#G(J,...X)},this.#J.reallyExit=(J)=>{return this.#K(J)}}unload(){if(!this.#Q)return;this.#Q=!1,Q9.forEach((J)=>{let X=this.#W[J];if(!X)throw new Error("Listener not defined for signal: "+J);try{this.#J.removeListener(J,X)}catch(Y){}}),this.#J.emit=this.#Z,this.#J.reallyExit=this.#$,this.#Y.count-=1}#K(J){if(!BY(this.#J))return 0;return this.#J.exitCode=J||0,this.#Y.emit("exit",this.#J.exitCode,null),this.#$.call(this.#J,this.#J.exitCode)}#G(J,...X){let Y=this.#Z;if(J==="exit"&&BY(this.#J)){if(typeof X[0]==="number")this.#J.exitCode=X[0];let Z=Y.call(this.#J,J,...X);return this.#Y.emit("exit",this.#J.exitCode,null),Z}else return Y.call(this.#J,J,...X)}}var _K=globalThis.process,{onExit:cM,load:oz0,unload:rz0}=$y(BY(_K)?new gM(_K):new yM);var mM=(J,{cleanup:X,detached:Y},{signal:Z})=>{if(!X||Y)return;let W=cM(()=>{J.kill()});Qy(Z,()=>{W()})};var uM=({source:J,sourcePromise:X,boundOptions:Y,createNested:Z},...W)=>{let $=IX(),{destination:Q,destinationStream:K,destinationError:G,from:F,unpipeSignal:q}=Ky(Y,Z,W),{sourceStream:H,sourceError:z}=Fy(J,F),{options:V,fileDescriptors:M}=C6.get(J);return{sourcePromise:X,sourceStream:H,sourceOptions:V,sourceError:z,destination:Q,destinationStream:K,destinationError:G,unpipeSignal:q,fileDescriptors:M,startTime:$}},Ky=(J,X,Y)=>{try{let{destination:Z,pipeOptions:{from:W,to:$,unpipeSignal:Q}={}}=Gy(J,X,...Y),K=iX(Z,$);return{destination:Z,destinationStream:K,from:W,unpipeSignal:Q}}catch(Z){return{destinationError:Z}}},Gy=(J,X,Y,...Z)=>{if(Array.isArray(Y))return{destination:X(lM,J)(Y,...Z),pipeOptions:J};if(typeof Y==="string"||Y instanceof URL||NQ(Y)){if(Object.keys(J).length>0)throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');let[W,$,Q]=vX(Y,...Z);return{destination:X(lM)(W,$,Q),pipeOptions:Q}}if(C6.has(Y)){if(Object.keys(J).length>0)throw new TypeError("Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).");return{destination:Y,pipeOptions:Z[0]}}throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${Y}`)},lM=({options:J})=>({options:{...J,stdin:"pipe",piped:!0}}),Fy=(J,X)=>{try{return{sourceStream:o9(J,X)}}catch(Y){return{sourceError:Y}}};var iM=({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z,fileDescriptors:W,sourceOptions:$,startTime:Q})=>{let K=qy({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z});if(K!==void 0)throw CK({error:K,fileDescriptors:W,sourceOptions:$,startTime:Q})},qy=({sourceStream:J,sourceError:X,destinationStream:Y,destinationError:Z})=>{if(X!==void 0&&Z!==void 0)return Z;if(Z!==void 0)return kK(J),Z;if(X!==void 0)return jK(Y),X},CK=({error:J,fileDescriptors:X,sourceOptions:Y,startTime:Z})=>e9({error:J,command:dM,escapedCommand:dM,fileDescriptors:X,options:Y,startTime:Z,isSync:!1}),dM="source.pipe(destination)";var nM=async(J)=>{let[{status:X,reason:Y,value:Z=Y},{status:W,reason:$,value:Q=$}]=await J;if(!Q.pipedFrom.includes(Z))Q.pipedFrom.push(Z);if(W==="rejected")throw Q;if(X==="rejected")throw Z;return Q};import{finished as Hy}from"stream/promises";var aM=(J,X,Y)=>{let Z=jY.has(X)?Ly(J,X):zy(J,X);return X9(J,Vy,Y.signal),X9(X,My,Y.signal),Uy(X),Z},zy=(J,X)=>{let Y=$9([J]);return Y5(Y,X),jY.set(X,Y),Y},Ly=(J,X)=>{let Y=jY.get(X);return Y.add(J),Y},Uy=async(J)=>{try{await Hy(J,{cleanup:!0,readable:!1,writable:!0})}catch{}jY.delete(J)},jY=new WeakMap,Vy=2,My=1;import{aborted as Ry}from"util";var sM=(J,X)=>J===void 0?[]:[wy(J,X)],wy=async(J,{sourceStream:X,mergedStream:Y,fileDescriptors:Z,sourceOptions:W,startTime:$})=>{await Ry(J,X),await Y.remove(X);let Q=new Error("Pipe canceled by `unpipeSignal` option.");throw CK({error:Q,fileDescriptors:Z,sourceOptions:W,startTime:$})};var kY=(J,...X)=>{if(d0(X[0]))return kY.bind(void 0,{...J,boundOptions:{...J.boundOptions,...X[0]}});let{destination:Y,...Z}=uM(J,...X),W=Oy({...Z,destination:Y});return W.pipe=kY.bind(void 0,{...J,source:Y,sourcePromise:W,boundOptions:{}}),W},Oy=async({sourcePromise:J,sourceStream:X,sourceOptions:Y,sourceError:Z,destination:W,destinationStream:$,destinationError:Q,unpipeSignal:K,fileDescriptors:G,startTime:F})=>{let q=xy(J,W);iM({sourceStream:X,sourceError:Z,destinationStream:$,destinationError:Q,fileDescriptors:G,sourceOptions:Y,startTime:F});let H=new AbortController;try{let z=aM(X,$,H);return await Promise.race([nM(q),...sM(K,{sourceStream:X,mergedStream:z,sourceOptions:Y,fileDescriptors:G,startTime:F})])}finally{H.abort()}},xy=(J,X)=>Promise.allSettled([J,X]);import{setImmediate as Ty}from"timers/promises";import{on as Py}from"events";import{getDefaultHighWaterMark as Ny}from"stream";var TY=({subprocessStdout:J,subprocess:X,binary:Y,shouldEncode:Z,encoding:W,preserveNewlines:$})=>{let Q=new AbortController;return vy(X,Q),rM({stream:J,controller:Q,binary:Y,shouldEncode:!J.readableObjectMode&&Z,encoding:W,shouldSplit:!J.readableObjectMode,preserveNewlines:$})},vy=async(J,X)=>{try{await J}catch{}finally{X.abort()}},SK=({stream:J,onStreamEnd:X,lines:Y,encoding:Z,stripFinalNewline:W,allMixed:$})=>{let Q=new AbortController;By(X,Q,J);let K=J.readableObjectMode&&!$;return rM({stream:J,controller:Q,binary:Z==="buffer",shouldEncode:!K,encoding:Z,shouldSplit:!K&&Y,preserveNewlines:!W})},By=async(J,X,Y)=>{try{await J}catch{Y.destroy()}finally{X.abort()}},rM=({stream:J,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q})=>{let K=Py(J,"data",{signal:X.signal,highWaterMark:oM,highWatermark:oM});return jy({onStdoutChunk:K,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q})},IK=Ny(!0),oM=IK,jy=async function*({onStdoutChunk:J,controller:X,binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q}){let K=ky({binary:Y,shouldEncode:Z,encoding:W,shouldSplit:$,preserveNewlines:Q});try{for await(let[G]of J)yield*W9(G,K,0)}catch(G){if(!X.signal.aborted)throw G}finally{yield*h4(K)}},ky=({binary:J,shouldEncode:X,encoding:Y,shouldSplit:Z,preserveNewlines:W})=>[wY(J,Y,!X),RY(J,W,!Z,{})].filter(Boolean);var tM=async({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,buffer:W,maxBuffer:$,lines:Q,allMixed:K,stripFinalNewline:G,verboseInfo:F,streamInfo:q})=>{let H=Dy({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,allMixed:K,verboseInfo:F,streamInfo:q});if(!W){await Promise.all([_y(J),H]);return}let z=LK(G,Y),V=SK({stream:J,onStreamEnd:X,lines:Q,encoding:Z,stripFinalNewline:z,allMixed:K}),[M]=await Promise.all([Ey({stream:J,iterable:V,fdNumber:Y,encoding:Z,maxBuffer:$,lines:Q}),H]);return M},Dy=async({stream:J,onStreamEnd:X,fdNumber:Y,encoding:Z,allMixed:W,verboseInfo:$,streamInfo:{fileDescriptors:Q}})=>{if(!PY({stdioItems:Q[Y]?.stdioItems,encoding:Z,verboseInfo:$,fdNumber:Y}))return;let K=SK({stream:J,onStreamEnd:X,lines:!0,encoding:Z,stripFinalNewline:!0,allMixed:W});await $M(K,J,Y,$)},_y=async(J)=>{if(await Ty(),J.readableFlowing===null)J.resume()},Ey=async({stream:J,stream:{readableObjectMode:X},iterable:Y,fdNumber:Z,encoding:W,maxBuffer:$,lines:Q})=>{try{if(X||Q)return await KY(Y,{maxBuffer:$});if(W==="buffer")return new Uint8Array(await GY(Y,{maxBuffer:$}));return await qY(Y,{maxBuffer:$})}catch(K){return eM($V({error:K,stream:J,readableObjectMode:X,lines:Q,encoding:W,fdNumber:Z}))}},hK=async(J)=>{try{return await J}catch(X){return eM(X)}},eM=({bufferedData:J})=>Pz(J)?new Uint8Array(J):J;import{finished as Cy}from"stream/promises";var A4=async(J,X,Y,{isSameDirection:Z,stopOnExit:W=!1}={})=>{let $=Sy(J,Y),Q=new AbortController;try{await Promise.race([...W?[Y.exitPromise]:[],Cy(J,{cleanup:!0,signal:Q.signal})])}catch(K){if(!$.stdinCleanedUp)fy(K,X,Y,Z)}finally{Q.abort()}},Sy=(J,{originalStreams:[X],subprocess:Y})=>{let Z={stdinCleanedUp:!1};if(J===X)Iy(J,Y,Z);return Z},Iy=(J,X,Y)=>{let{_destroy:Z}=J;J._destroy=(...W)=>{hy(X,Y),Z.call(J,...W)}},hy=({exitCode:J,signalCode:X},Y)=>{if(J!==null||X!==null)Y.stdinCleanedUp=!0},fy=(J,X,Y,Z)=>{if(!by(J,X,Y,Z))throw J},by=(J,X,Y,Z=!0)=>{if(Y.propagating)return JR(J)||DY(J);return Y.propagating=!0,fK(Y,X)===Z?JR(J):DY(J)},fK=({fileDescriptors:J},X)=>X!=="all"&&J[X].direction==="input",DY=(J)=>J?.code==="ERR_STREAM_PREMATURE_CLOSE",JR=(J)=>J?.code==="EPIPE";var XR=({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})=>J.stdio.map((G,F)=>bK({stream:G,fdNumber:F,encoding:X,buffer:Y[F],maxBuffer:Z[F],lines:W[F],allMixed:!1,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})),bK=async({stream:J,fdNumber:X,encoding:Y,buffer:Z,maxBuffer:W,lines:$,allMixed:Q,stripFinalNewline:K,verboseInfo:G,streamInfo:F})=>{if(!J)return;let q=A4(J,X,F);if(fK(F,X)){await q;return}let[H]=await Promise.all([tM({stream:J,onStreamEnd:q,fdNumber:X,encoding:Y,buffer:Z,maxBuffer:W,lines:$,allMixed:Q,stripFinalNewline:K,verboseInfo:G,streamInfo:F}),q]);return H};var YR=({stdout:J,stderr:X},{all:Y})=>Y&&(J||X)?$9([J,X].filter(Boolean)):void 0,ZR=({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:$,verboseInfo:Q,streamInfo:K})=>bK({...py(J,Y),fdNumber:"all",encoding:X,maxBuffer:Z[1]+Z[2],lines:W[1]||W[2],allMixed:Ay(J),stripFinalNewline:$,verboseInfo:Q,streamInfo:K}),py=({stdout:J,stderr:X,all:Y},[,Z,W])=>{let $=Z||W;if(!$)return{stream:Y,buffer:$};if(!Z)return{stream:X,buffer:$};if(!W)return{stream:J,buffer:$};return{stream:Y,buffer:$}},Ay=({all:J,stdout:X,stderr:Y})=>J&&X&&Y&&X.readableObjectMode!==Y.readableObjectMode;import{once as yy}from"events";var WR=(J)=>d9(J,"ipc"),$R=(J,X)=>{let Y=SX(J);D6({type:"ipc",verboseMessage:Y,fdNumber:"ipc",verboseInfo:X})};var QR=async({subprocess:J,buffer:X,maxBuffer:Y,ipc:Z,ipcOutput:W,verboseInfo:$})=>{if(!Z)return W;let Q=WR($),K=J1(X,"ipc"),G=J1(Y,"ipc");for await(let F of NK({anyProcess:J,channel:J.channel,isSubprocess:!1,ipc:Z,shouldAwait:!1,reference:!0})){if(K)QV(J,W,G),W.push(F);if(Q)$R(F,$)}return W},KR=async(J,X)=>{return await Promise.allSettled([J]),X};var GR=async({subprocess:J,options:{encoding:X,buffer:Y,maxBuffer:Z,lines:W,timeoutDuration:$,cancelSignal:Q,gracefulCancel:K,forceKillAfterDelay:G,stripFinalNewline:F,ipc:q,ipcInput:H},context:z,verboseInfo:V,fileDescriptors:M,originalStreams:R,onInternalError:L,controller:w})=>{let P=qM(J,z),N={originalStreams:R,fileDescriptors:M,subprocess:J,exitPromise:P,propagating:!1},v=XR({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:F,verboseInfo:V,streamInfo:N}),j=ZR({subprocess:J,encoding:X,buffer:Y,maxBuffer:Z,lines:W,stripFinalNewline:F,verboseInfo:V,streamInfo:N}),O=[],D=QR({subprocess:J,buffer:Y,maxBuffer:Z,ipc:q,ipcOutput:O,verboseInfo:V}),_=gy(R,J,N),C=cy(M,N);try{return await Promise.race([Promise.all([{},zM(P),Promise.all(v),j,D,pU(J,H),..._,...C]),L,my(J,w),...SU(J,$,z,w),...eL({subprocess:J,cancelSignal:Q,gracefulCancel:K,context:z,controller:w}),...EU({subprocess:J,cancelSignal:Q,gracefulCancel:K,forceKillAfterDelay:G,context:z,controller:w})])}catch(S){return z.terminationReason??="other",Promise.all([{error:S},P,Promise.all(v.map((I)=>hK(I))),hK(j),KR(D,O),Promise.allSettled(_),Promise.allSettled(C)])}},gy=(J,X,Y)=>J.map((Z,W)=>Z===X.stdio[W]?void 0:A4(Z,W,Y)),cy=(J,X)=>J.flatMap(({stdioItems:Y},Z)=>Y.filter(({value:W,stream:$=W})=>L6($,{checkOpen:!1})&&!H6($)).map(({type:W,value:$,stream:Q=$})=>A4(Q,Z,X,{isSameDirection:s8.has(W),stopOnExit:W==="native"}))),my=async(J,{signal:X})=>{let[Y]=await yy(J,"error",{signal:X});throw Y};var FR=()=>({readableDestroy:new WeakMap,writableFinal:new WeakMap,writableDestroy:new WeakMap}),y4=(J,X,Y)=>{let Z=J[Y];if(!Z.has(X))Z.set(X,[]);let W=Z.get(X),$=E6();return W.push($),{resolve:$.resolve.bind($),promises:W}},Z5=async({resolve:J,promises:X},Y)=>{J();let[Z]=await Promise.race([Promise.allSettled([!0,Y]),Promise.all([!1,...X])]);return!Z};import{Readable as ly}from"stream";import{callbackify as uy}from"util";import{finished as qR}from"stream/promises";var pK=async(J)=>{if(J===void 0)return;try{await AK(J)}catch{}},HR=async(J)=>{if(J===void 0)return;try{await yK(J)}catch{}},AK=async(J)=>{await qR(J,{cleanup:!0,readable:!1,writable:!0})},yK=async(J)=>{await qR(J,{cleanup:!0,readable:!0,writable:!1})},_Y=async(J,X)=>{if(await J,X)throw X},EY=(J,X,Y)=>{if(Y&&!DY(Y))J.destroy(Y);else if(X)J.destroy()};var zR=({subprocess:J,concurrentStreams:X,encoding:Y},{from:Z,binary:W=!0,preserveNewlines:$=!0}={})=>{let Q=W||l8.has(Y),{subprocessStdout:K,waitReadableDestroy:G}=gK(J,Z,X),{readableEncoding:F,readableObjectMode:q,readableHighWaterMark:H}=cK(K,Q),{read:z,onStdoutDataDone:V}=mK({subprocessStdout:K,subprocess:J,binary:Q,encoding:Y,preserveNewlines:$}),M=new ly({read:z,destroy:uy(uK.bind(void 0,{subprocessStdout:K,subprocess:J,waitReadableDestroy:G})),highWaterMark:H,objectMode:q,encoding:F});return lK({subprocessStdout:K,onStdoutDataDone:V,readable:M,subprocess:J}),M},gK=(J,X,Y)=>{let Z=o9(J,X),W=y4(Y,Z,"readableDestroy");return{subprocessStdout:Z,waitReadableDestroy:W}},cK=({readableEncoding:J,readableObjectMode:X,readableHighWaterMark:Y},Z)=>Z?{readableEncoding:J,readableObjectMode:X,readableHighWaterMark:Y}:{readableEncoding:J,readableObjectMode:!0,readableHighWaterMark:IK},mK=({subprocessStdout:J,subprocess:X,binary:Y,encoding:Z,preserveNewlines:W})=>{let $=E6(),Q=TY({subprocessStdout:J,subprocess:X,binary:Y,shouldEncode:!Y,encoding:Z,preserveNewlines:W});return{read(){dy(this,Q,$)},onStdoutDataDone:$}},dy=async(J,X,Y)=>{try{let{value:Z,done:W}=await X.next();if(W)Y.resolve();else J.push(Z)}catch{}},lK=async({subprocessStdout:J,onStdoutDataDone:X,readable:Y,subprocess:Z,subprocessStdin:W})=>{try{if(await yK(J),await Z,await pK(W),await X,Y.readable)Y.push(null)}catch($){await pK(W),LR(Y,$)}},uK=async({subprocessStdout:J,subprocess:X,waitReadableDestroy:Y},Z)=>{if(await Z5(Y,X))LR(J,Z),await _Y(X,Z)},LR=(J,X)=>{EY(J,J.readable,X)};import{Writable as iy}from"stream";import{callbackify as UR}from"util";var VR=({subprocess:J,concurrentStreams:X},{to:Y}={})=>{let{subprocessStdin:Z,waitWritableFinal:W,waitWritableDestroy:$}=dK(J,Y,X),Q=new iy({...iK(Z,J,W),destroy:UR(aK.bind(void 0,{subprocessStdin:Z,subprocess:J,waitWritableFinal:W,waitWritableDestroy:$})),highWaterMark:Z.writableHighWaterMark,objectMode:Z.writableObjectMode});return nK(Z,Q),Q},dK=(J,X,Y)=>{let Z=iX(J,X),W=y4(Y,Z,"writableFinal"),$=y4(Y,Z,"writableDestroy");return{subprocessStdin:Z,waitWritableFinal:W,waitWritableDestroy:$}},iK=(J,X,Y)=>({write:ny.bind(void 0,J),final:UR(ay.bind(void 0,J,X,Y))}),ny=(J,X,Y,Z)=>{if(J.write(X,Y))Z();else J.once("drain",Z)},ay=async(J,X,Y)=>{if(await Z5(Y,X)){if(J.writable)J.end();await X}},nK=async(J,X,Y)=>{try{if(await AK(J),X.writable)X.end()}catch(Z){await HR(Y),MR(X,Z)}},aK=async({subprocessStdin:J,subprocess:X,waitWritableFinal:Y,waitWritableDestroy:Z},W)=>{if(await Z5(Y,X),await Z5(Z,X))MR(J,W),await _Y(X,W)},MR=(J,X)=>{EY(J,J.writable,X)};import{Duplex as sy}from"stream";import{callbackify as oy}from"util";var RR=({subprocess:J,concurrentStreams:X,encoding:Y},{from:Z,to:W,binary:$=!0,preserveNewlines:Q=!0}={})=>{let K=$||l8.has(Y),{subprocessStdout:G,waitReadableDestroy:F}=gK(J,Z,X),{subprocessStdin:q,waitWritableFinal:H,waitWritableDestroy:z}=dK(J,W,X),{readableEncoding:V,readableObjectMode:M,readableHighWaterMark:R}=cK(G,K),{read:L,onStdoutDataDone:w}=mK({subprocessStdout:G,subprocess:J,binary:K,encoding:Y,preserveNewlines:Q}),P=new sy({read:L,...iK(q,J,H),destroy:oy(ry.bind(void 0,{subprocessStdout:G,subprocessStdin:q,subprocess:J,waitReadableDestroy:F,waitWritableFinal:H,waitWritableDestroy:z})),readableHighWaterMark:R,writableHighWaterMark:q.writableHighWaterMark,readableObjectMode:M,writableObjectMode:q.writableObjectMode,encoding:V});return lK({subprocessStdout:G,onStdoutDataDone:w,readable:P,subprocess:J,subprocessStdin:q}),nK(q,P,G),P},ry=async({subprocessStdout:J,subprocessStdin:X,subprocess:Y,waitReadableDestroy:Z,waitWritableFinal:W,waitWritableDestroy:$},Q)=>{await Promise.all([uK({subprocessStdout:J,subprocess:Y,waitReadableDestroy:Z},Q),aK({subprocessStdin:X,subprocess:Y,waitWritableFinal:W,waitWritableDestroy:$},Q)])};var sK=(J,X,{from:Y,binary:Z=!1,preserveNewlines:W=!1}={})=>{let $=Z||l8.has(X),Q=o9(J,Y),K=TY({subprocessStdout:Q,subprocess:J,binary:$,shouldEncode:!0,encoding:X,preserveNewlines:W});return ty(K,Q,J)},ty=async function*(J,X,Y){try{yield*J}finally{if(X.readable)X.destroy();await Y}};var wR=(J,{encoding:X})=>{let Y=FR();J.readable=zR.bind(void 0,{subprocess:J,concurrentStreams:Y,encoding:X}),J.writable=VR.bind(void 0,{subprocess:J,concurrentStreams:Y}),J.duplex=RR.bind(void 0,{subprocess:J,concurrentStreams:Y,encoding:X}),J.iterable=sK.bind(void 0,J,X),J[Symbol.asyncIterator]=sK.bind(void 0,J,X,{})};var OR=(J,X)=>{for(let[Y,Z]of Jg){let W=Z.value.bind(X);Reflect.defineProperty(J,Y,{...Z,value:W})}},ey=(async()=>{})().constructor.prototype,Jg=["then","catch","finally"].map((J)=>[J,Reflect.getOwnPropertyDescriptor(ey,J)]);var xR=(J,X,Y,Z)=>{let{file:W,commandArguments:$,command:Q,escapedCommand:K,startTime:G,verboseInfo:F,options:q,fileDescriptors:H}=Zg(J,X,Y),{subprocess:z,promise:V}=$g({file:W,commandArguments:$,options:q,startTime:G,verboseInfo:F,command:Q,escapedCommand:K,fileDescriptors:H});return z.pipe=kY.bind(void 0,{source:z,sourcePromise:V,boundOptions:{},createNested:Z}),OR(z,V),C6.set(z,{options:q,fileDescriptors:H}),z},Zg=(J,X,Y)=>{let{command:Z,escapedCommand:W,startTime:$,verboseInfo:Q}=hX(J,X,Y),{file:K,commandArguments:G,options:F}=ZY(J,X,Y),q=Wg(F),H=TM(q,Q);return{file:K,commandArguments:G,command:Z,escapedCommand:W,startTime:$,verboseInfo:Q,options:q,fileDescriptors:H}},Wg=({timeout:J,signal:X,...Y})=>{if(X!==void 0)throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');return{...Y,timeoutDuration:J}},$g=({file:J,commandArguments:X,options:Y,startTime:Z,verboseInfo:W,command:$,escapedCommand:Q,fileDescriptors:K})=>{let G;try{G=Yg(J,X,Y)}catch(M){return vM({error:M,command:$,escapedCommand:Q,fileDescriptors:K,options:Y,startTime:Z,verboseInfo:W})}let F=new AbortController;Xg(Number.POSITIVE_INFINITY,F.signal);let q=[...G.stdio];pM(G,K,F),mM(G,Y,F);let H={},z=E6();G.kill=rL.bind(void 0,{kill:G.kill.bind(G),options:Y,onInternalError:z,context:H,controller:F}),G.all=YR(G,Y),wR(G,Y),xM(G,Y);let V=Qg({subprocess:G,options:Y,startTime:Z,verboseInfo:W,fileDescriptors:K,originalStreams:q,command:$,escapedCommand:Q,context:H,onInternalError:z,controller:F});return{subprocess:G,promise:V}},Qg=async({subprocess:J,options:X,startTime:Y,verboseInfo:Z,fileDescriptors:W,originalStreams:$,command:Q,escapedCommand:K,context:G,onInternalError:F,controller:q})=>{let[H,[z,V],M,R,L]=await GR({subprocess:J,options:X,context:G,verboseInfo:Z,fileDescriptors:W,originalStreams:$,onInternalError:F,controller:q});q.abort(),F.resolve();let w=M.map((v,j)=>Z1(v,X,j)),P=Z1(R,X,"all"),N=Kg({errorInfo:H,exitCode:z,signal:V,stdio:w,all:P,ipcOutput:L,context:G,options:X,command:Q,escapedCommand:K,startTime:Y});return J5(N,Z,X)},Kg=({errorInfo:J,exitCode:X,signal:Y,stdio:Z,all:W,ipcOutput:$,context:Q,options:K,command:G,escapedCommand:F,startTime:q})=>("error"in J)?I4({error:J.error,command:G,escapedCommand:F,timedOut:Q.terminationReason==="timeout",isCanceled:Q.terminationReason==="cancel"||Q.terminationReason==="gracefulCancel",isGracefullyCanceled:Q.terminationReason==="gracefulCancel",isMaxBuffer:J.error instanceof X1,isForcefullyTerminated:Q.isForcefullyTerminated,exitCode:X,signal:Y,stdio:Z,all:W,ipcOutput:$,options:K,startTime:q,isSync:!1}):zY({command:G,escapedCommand:F,stdio:Z,all:W,ipcOutput:$,options:K,startTime:q});var CY=(J,X)=>{let Y=Object.fromEntries(Object.entries(X).map(([Z,W])=>[Z,Gg(Z,J[Z],W)]));return{...J,...Y}},Gg=(J,X,Y)=>{if(Fg.has(J)&&d0(X)&&d0(Y))return{...X,...Y};return Y},Fg=new Set(["env",...DQ]);var j1=(J,X,Y,Z)=>{let W=(Q,K,G)=>j1(Q,K,Y,G),$=(...Q)=>qg({mapArguments:J,deepOptions:Y,boundOptions:X,setBoundExeca:Z,createNested:W},...Q);if(Z!==void 0)Z($,W,X);return $},qg=({mapArguments:J,deepOptions:X={},boundOptions:Y={},setBoundExeca:Z,createNested:W},$,...Q)=>{if(d0($))return W(J,CY(Y,$),Z);let{file:K,commandArguments:G,options:F,isSync:q}=Hg({mapArguments:J,firstArgument:$,nextArguments:Q,deepOptions:X,boundOptions:Y});return q?UM(K,G,F):xR(K,G,F,W)},Hg=({mapArguments:J,firstArgument:X,nextArguments:Y,deepOptions:Z,boundOptions:W})=>{let $=Tz(X)?Dz(X,Y):[X,...Y],[Q,K,G]=vX(...$),F=CY(CY(Z,W),G),{file:q=Q,commandArguments:H=K,options:z=F,isSync:V=!1}=J({file:Q,commandArguments:K,options:F});return{file:q,commandArguments:H,options:z,isSync:V}};var PR=({file:J,commandArguments:X})=>vR(J,X),NR=({file:J,commandArguments:X})=>({...vR(J,X),isSync:!0}),vR=(J,X)=>{if(X.length>0)throw new TypeError(`The command and its arguments must be passed as a single string: ${J} ${X}.`);let[Y,...Z]=zg(J);return{file:Y,commandArguments:Z}},zg=(J)=>{if(typeof J!=="string")throw new TypeError(`The command must be a string: ${String(J)}.`);let X=J.trim();if(X==="")return[];let Y=[];for(let Z of X.split(Lg)){let W=Y.at(-1);if(W&&W.endsWith("\\"))Y[Y.length-1]=`${W.slice(0,-1)} ${Z}`;else Y.push(Z)}return Y},Lg=/ +/g;var BR=(J,X,Y)=>{J.sync=X(Ug,Y),J.s=J.sync},jR=({options:J})=>kR(J),Ug=({options:J})=>({...kR(J),isSync:!0}),kR=(J)=>({options:{...Vg(J),...J}}),Vg=({input:J,inputFile:X,stdio:Y})=>J===void 0&&X===void 0&&Y===void 0?{stdin:"inherit"}:{},TR={preferLocal:!0};var DR=j1(()=>({})),yV0=j1(()=>({isSync:!0})),gV0=j1(PR),cV0=j1(NR),mV0=j1(hU),lV0=j1(jR,{},TR,BR),{sendMessage:uV0,getOneMessage:dV0,getEachMessage:iV0,getCancelSignal:nV0}=PM();var{Glob:Mc}=globalThis.Bun;class oK{constructor(){this._listeners={}}addEventListener(J,X){let Y=this._listeners;if(Y[J]===void 0)Y[J]=[];if(Y[J].indexOf(X)===-1)Y[J].push(X);return this}removeEventListener(J,X){let Z=this._listeners[J];if(Z!==void 0){let W=Z.indexOf(X);if(W!==-1)Z.splice(W,1)}return this}dispatchEvent(J){let Y=this._listeners[J.type];if(Y!==void 0){let Z=Y.slice(0);for(let W=0,$=Z.length;W<$;W++)Z[W].call(this,J)}return this}dispose(){for(let J in this._listeners)delete this._listeners[J]}}class T1{constructor(J,X,Y,Z={}){if(this._name=void 0,this._parent=void 0,this._child=void 0,this._attributes=void 0,this._disposed=!1,this._name=J,this._parent=X,this._child=Y,this._attributes=Z,!X.isOnGraph(Y))throw new Error("Cannot connect disconnected graphs.")}getName(){return this._name}getParent(){return this._parent}getChild(){return this._child}setChild(J){return this._child=J,this}getAttributes(){return this._attributes}dispose(){if(this._disposed)return;this._parent._destroyRef(this),this._disposed=!0}isDisposed(){return this._disposed}}class rK extends oK{constructor(...J){super(...J);this._emptySet=new Set,this._edges=new Set,this._parentEdges=new Map,this._childEdges=new Map}listEdges(){return Array.from(this._edges)}listParentEdges(J){return Array.from(this._childEdges.get(J)||this._emptySet)}listParents(J){let X=new Set;for(let Y of this.listParentEdges(J))X.add(Y.getParent());return Array.from(X)}listChildEdges(J){return Array.from(this._parentEdges.get(J)||this._emptySet)}listChildren(J){let X=new Set;for(let Y of this.listChildEdges(J))X.add(Y.getChild());return Array.from(X)}disconnectParents(J,X){for(let Y of this.listParentEdges(J))if(!X||X(Y.getParent()))Y.dispose();return this}_createEdge(J,X,Y,Z){let W=new T1(J,X,Y,Z);this._edges.add(W);let $=W.getParent();if(!this._parentEdges.has($))this._parentEdges.set($,new Set);this._parentEdges.get($).add(W);let Q=W.getChild();if(!this._childEdges.has(Q))this._childEdges.set(Q,new Set);return this._childEdges.get(Q).add(W),W}_destroyEdge(J){return this._edges.delete(J),this._parentEdges.get(J.getParent()).delete(J),this._childEdges.get(J.getChild()).delete(J),this}}function g4(){return g4=Object.assign||function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)if(Object.prototype.hasOwnProperty.call(Y,Z))J[Z]=Y[Z]}return J},g4.apply(this,arguments)}class I6{constructor(J){if(this.list=[],J)for(let X of J)this.list.push(X)}add(J){this.list.push(J)}remove(J){let X=this.list.indexOf(J);if(X>=0)this.list.splice(X,1)}removeChild(J){let X=[];for(let Y of this.list)if(Y.getChild()===J)X.push(Y);for(let Y of X)this.remove(Y);return X}listRefsByChild(J){let X=[];for(let Y of this.list)if(Y.getChild()===J)X.push(Y);return X}values(){return this.list}}class _0{constructor(J){if(this.set=new Set,this.map=new Map,J)for(let X of J)this.add(X)}add(J){let X=J.getChild();this.removeChild(X),this.set.add(J),this.map.set(X,J)}remove(J){this.set.delete(J),this.map.delete(J.getChild())}removeChild(J){let X=this.map.get(J)||null;if(X)this.remove(X);return X}getRefByChild(J){return this.map.get(J)||null}values(){return Array.from(this.set)}}class o8{constructor(J){if(this.map={},J)Object.assign(this.map,J)}set(J,X){this.map[J]=X}delete(J){delete this.map[J]}get(J){return this.map[J]||null}keys(){return Object.keys(this.map)}values(){return Object.values(this.map)}}var L0=Symbol("attributes"),k1=Symbol("immutableKeys");class SY extends oK{constructor(J){super();this._disposed=!1,this.graph=void 0,this[L0]=void 0,this[k1]=void 0,this.graph=J,this[k1]=new Set,this[L0]=this._createAttributes()}getDefaults(){return{}}_createAttributes(){let J=this.getDefaults(),X={};for(let Y in J){let Z=J[Y];if(Z instanceof SY){let W=this.graph._createEdge(Y,this,Z);this[k1].add(Y),X[Y]=W}else X[Y]=Z}return X}isOnGraph(J){return this.graph===J.graph}isDisposed(){return this._disposed}dispose(){if(this._disposed)return;this.graph.listChildEdges(this).forEach((J)=>J.dispose()),this.graph.disconnectParents(this),this._disposed=!0,this.dispatchEvent({type:"dispose"})}detach(){return this.graph.disconnectParents(this),this}swap(J,X){for(let Y in this[L0]){let Z=this[L0][Y];if(Z instanceof T1){let W=Z;if(W.getChild()===J)this.setRef(Y,X,W.getAttributes())}else if(Z instanceof I6)for(let W of Z.listRefsByChild(J)){let $=W.getAttributes();this.removeRef(Y,J),this.addRef(Y,X,$)}else if(Z instanceof _0){let W=Z.getRefByChild(J);if(W){let $=W.getAttributes();this.removeRef(Y,J),this.addRef(Y,X,$)}}else if(Z instanceof o8)for(let W of Z.keys()){let $=Z.get(W);if($.getChild()===J)this.setRefMap(Y,W,X,$.getAttributes())}}return this}get(J){return this[L0][J]}set(J,X){return this[L0][J]=X,this.dispatchEvent({type:"change",attribute:J})}getRef(J){let X=this[L0][J];return X?X.getChild():null}setRef(J,X,Y){if(this[k1].has(J))throw new Error(`Cannot overwrite immutable attribute, "${J}".`);let Z=this[L0][J];if(Z)Z.dispose();if(!X)return this;let W=this.graph._createEdge(J,this,X,Y);return this[L0][J]=W,this.dispatchEvent({type:"change",attribute:J})}listRefs(J){return this.assertRefList(J).values().map((Y)=>Y.getChild())}addRef(J,X,Y){let Z=this.graph._createEdge(J,this,X,Y);return this.assertRefList(J).add(Z),this.dispatchEvent({type:"change",attribute:J})}removeRef(J,X){let Y=this.assertRefList(J);if(Y instanceof I6)for(let Z of Y.listRefsByChild(X))Z.dispose();else{let Z=Y.getRefByChild(X);if(Z)Z.dispose()}return this}assertRefList(J){let X=this[L0][J];if(X instanceof I6||X instanceof _0)return X;throw new Error(`Expected RefList or RefSet for attribute "${J}"`)}listRefMapKeys(J){return this.assertRefMap(J).keys()}listRefMapValues(J){return this.assertRefMap(J).values().map((X)=>X.getChild())}getRefMap(J,X){let Z=this.assertRefMap(J).get(X);return Z?Z.getChild():null}setRefMap(J,X,Y,Z){let W=this.assertRefMap(J),$=W.get(X);if($)$.dispose();if(!Y)return this;Z=Object.assign(Z||{},{key:X});let Q=this.graph._createEdge(J,this,Y,g4({},Z,{key:X}));return W.set(X,Q),this.dispatchEvent({type:"change",attribute:J,key:X})}assertRefMap(J){let X=this[L0][J];if(X instanceof o8)return X;throw new Error(`Expected RefMap for attribute "${J}"`)}dispatchEvent(J){return super.dispatchEvent(g4({},J,{target:this})),this.graph.dispatchEvent(g4({},J,{target:this,type:`node:${J.type}`})),this}_destroyRef(J){let X=J.getName();if(this[L0][X]===J){if(this[L0][X]=null,this[k1].has(X))J.getChild().dispose()}else if(this[L0][X]instanceof I6)this[L0][X].remove(J);else if(this[L0][X]instanceof _0)this[L0][X].remove(J);else if(this[L0][X]instanceof o8){let Y=this[L0][X];for(let Z of Y.keys())if(Y.get(Z)===J)Y.delete(Z)}else return;this.graph._destroyEdge(J),this.dispatchEvent({type:"change",attribute:X})}}var fR="v4.1.1",AY="@glb.bin",p;(function(J){J.ACCESSOR="Accessor",J.ANIMATION="Animation",J.ANIMATION_CHANNEL="AnimationChannel",J.ANIMATION_SAMPLER="AnimationSampler",J.BUFFER="Buffer",J.CAMERA="Camera",J.MATERIAL="Material",J.MESH="Mesh",J.PRIMITIVE="Primitive",J.PRIMITIVE_TARGET="PrimitiveTarget",J.NODE="Node",J.ROOT="Root",J.SCENE="Scene",J.SKIN="Skin",J.TEXTURE="Texture",J.TEXTURE_INFO="TextureInfo"})(p||(p={}));var yY;(function(J){J.INTERLEAVED="interleaved",J.SEPARATE="separate"})(yY||(yY={}));var u8;(function(J){J.ARRAY_BUFFER="ARRAY_BUFFER",J.ELEMENT_ARRAY_BUFFER="ELEMENT_ARRAY_BUFFER",J.INVERSE_BIND_MATRICES="INVERSE_BIND_MATRICES",J.OTHER="OTHER",J.SPARSE="SPARSE"})(u8||(u8={}));var gY;(function(J){J[J.R=4096]="R",J[J.G=256]="G",J[J.B=16]="B",J[J.A=1]="A"})(gY||(gY={}));var W1;(function(J){J.GLTF="GLTF",J.GLB="GLB"})(W1||(W1={}));var m4={"5120":Int8Array,"5121":Uint8Array,"5122":Int16Array,"5123":Uint16Array,"5125":Uint32Array,"5126":Float32Array},eK=typeof Float32Array!=="undefined"?Float32Array:Array;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};function Mg(){var J=new eK(3);if(eK!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function tK(J){var X=J[0],Y=J[1],Z=J[2];return Math.hypot(X,Y,Z)}function Rg(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[3]*Z+Y[7]*W+Y[11]*$+Y[15];return Q=Q||1,J[0]=(Y[0]*Z+Y[4]*W+Y[8]*$+Y[12])/Q,J[1]=(Y[1]*Z+Y[5]*W+Y[9]*$+Y[13])/Q,J[2]=(Y[2]*Z+Y[6]*W+Y[10]*$+Y[14])/Q,J}(function(){var J=Mg();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}})();function bR(J){let X=pR(),Y=J.propertyType===p.NODE?[J]:J.listChildren();for(let Z of Y)Z.traverse((W)=>{let $=W.getMesh();if(!$)return;let Q=wg($,W.getWorldMatrix());if(Q.min.every(isFinite)&&Q.max.every(isFinite))JG(Q.min,X),JG(Q.max,X)});return X}function wg(J,X){let Y=pR();for(let Z of J.listPrimitives()){let W=Z.getAttribute("POSITION"),$=Z.getIndices();if(!W)continue;let Q=[0,0,0],K=[0,0,0];for(let G=0,F=$?$.getCount():W.getCount();G<F;G++){let q=$?$.getScalar(G):G;Q=W.getElement(q,Q),K=Rg(K,Q,X),JG(K,Y)}}return Y}function JG(J,X){for(let Y=0;Y<3;Y++)X.min[Y]=Math.min(J[Y],X.min[Y]),X.max[Y]=Math.max(J[Y],X.max[Y])}function pR(){return{min:[1/0,1/0,1/0],max:[-1/0,-1/0,-1/0]}}class G0{static createBufferFromDataURI(J){if(typeof Buffer==="undefined"){let X=atob(J.split(",")[1]),Y=new Uint8Array(X.length);for(let Z=0;Z<X.length;Z++)Y[Z]=X.charCodeAt(Z);return Y}else{let X=J.split(",")[1],Y=J.indexOf("base64")>=0;return Buffer.from(X,Y?"base64":"utf8")}}static encodeText(J){return new TextEncoder().encode(J)}static decodeText(J){return new TextDecoder().decode(J)}static concat(J){let X=0;for(let W of J)X+=W.byteLength;let Y=new Uint8Array(X),Z=0;for(let W of J)Y.set(W,Z),Z+=W.byteLength;return Y}static pad(J,X=0){let Y=this.padNumber(J.byteLength);if(Y===J.byteLength)return J;let Z=new Uint8Array(Y);if(Z.set(J),X!==0)for(let W=J.byteLength;W<Y;W++)Z[W]=X;return Z}static padNumber(J){return Math.ceil(J/4)*4}static equals(J,X){if(J===X)return!0;if(J.byteLength!==X.byteLength)return!1;let Y=J.byteLength;while(Y--)if(J[Y]!==X[Y])return!1;return!0}static toView(J,X=0,Y=1/0){return new Uint8Array(J.buffer,J.byteOffset+X,Math.min(J.byteLength,Y))}static assertView(J){if(J&&!ArrayBuffer.isView(J))throw new Error(`Method requires Uint8Array parameter; received "${typeof J}".`);return J}}class AR{match(J){return J.length>=3&&J[0]===255&&J[1]===216&&J[2]===255}getSize(J){let X=new DataView(J.buffer,J.byteOffset+4),Y,Z;while(X.byteLength){if(Y=X.getUint16(0,!1),Og(X,Y),Z=X.getUint8(Y+1),Z===192||Z===193||Z===194)return[X.getUint16(Y+7,!1),X.getUint16(Y+5,!1)];X=new DataView(J.buffer,X.byteOffset+Y+2)}throw new TypeError("Invalid JPG, no size found")}getChannels(J){return 3}}class lY{match(J){return J.length>=8&&J[0]===137&&J[1]===80&&J[2]===78&&J[3]===71&&J[4]===13&&J[5]===10&&J[6]===26&&J[7]===10}getSize(J){let X=new DataView(J.buffer,J.byteOffset);if(G0.decodeText(J.slice(12,16))===lY.PNG_FRIED_CHUNK_NAME)return[X.getUint32(32,!1),X.getUint32(36,!1)];return[X.getUint32(16,!1),X.getUint32(20,!1)]}getChannels(J){return 4}}lY.PNG_FRIED_CHUNK_NAME="CgBI";class $1{static registerFormat(J,X){this.impls[J]=X}static getMimeType(J){for(let X in this.impls)if(this.impls[X].match(J))return X;return null}static getSize(J,X){if(!this.impls[X])return null;return this.impls[X].getSize(J)}static getChannels(J,X){if(!this.impls[X])return null;return this.impls[X].getChannels(J)}static getVRAMByteLength(J,X){if(!this.impls[X])return null;if(this.impls[X].getVRAMByteLength)return this.impls[X].getVRAMByteLength(J);let Y=0,Z=4,W=this.getSize(J,X);if(!W)return null;while(W[0]>1||W[1]>1)Y+=W[0]*W[1]*Z,W[0]=Math.max(Math.floor(W[0]/2),1),W[1]=Math.max(Math.floor(W[1]/2),1);return Y+=1*Z,Y}static mimeTypeToExtension(J){if(J==="image/jpeg")return"jpg";return J.split("/").pop()}static extensionToMimeType(J){if(J==="jpg")return"image/jpeg";if(!J)return"";return`image/${J}`}}$1.impls={"image/jpeg":new AR,"image/png":new lY};function Og(J,X){if(X>J.byteLength)throw new TypeError("Corrupt JPG, exceeded buffer limits");if(J.getUint8(X)!==255)throw new TypeError("Invalid JPG, marker table corrupted");return J}class Q1{static basename(J){let X=J.split(/[\\/]/).pop();return X.substring(0,X.lastIndexOf("."))}static extension(J){if(J.startsWith("data:image/")){let X=J.match(/data:(image\/\w+)/)[1];return $1.mimeTypeToExtension(X)}else if(J.startsWith("data:model/gltf+json"))return"gltf";else if(J.startsWith("data:model/gltf-binary"))return"glb";else if(J.startsWith("data:application/"))return"bin";return J.split(/[\\/]/).pop().split(/[.]/).pop()}}function _R(J){return Object.prototype.toString.call(J)==="[object Object]"}function K9(J){if(_R(J)===!1)return!1;let X=J.constructor;if(X===void 0)return!0;let Y=X.prototype;if(_R(Y)===!1)return!1;if(Object.prototype.hasOwnProperty.call(Y,"isPrototypeOf")===!1)return!1;return!0}var XG,YG;(function(J){J[J.SILENT=4]="SILENT",J[J.ERROR=3]="ERROR",J[J.WARN=2]="WARN",J[J.INFO=1]="INFO",J[J.DEBUG=0]="DEBUG"})(YG||(YG={}));class e8{constructor(J){this.verbosity=void 0,this.verbosity=J}debug(J){if(this.verbosity<=e8.Verbosity.DEBUG)console.debug(J)}info(J){if(this.verbosity<=e8.Verbosity.INFO)console.info(J)}warn(J){if(this.verbosity<=e8.Verbosity.WARN)console.warn(J)}error(J){if(this.verbosity<=e8.Verbosity.ERROR)console.error(J)}}XG=e8;e8.Verbosity=YG;e8.DEFAULT_INSTANCE=new XG(XG.Verbosity.INFO);function xg(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8],q=J[9],H=J[10],z=J[11],V=J[12],M=J[13],R=J[14],L=J[15],w=X*Q-Y*$,P=X*K-Z*$,N=X*G-W*$,v=Y*K-Z*Q,j=Y*G-W*Q,O=Z*G-W*K,D=F*M-q*V,_=F*R-H*V,C=F*L-z*V,S=q*R-H*M,I=q*L-z*M,f=H*L-z*R;return w*f-P*I+N*S+v*C-j*_+O*D}function Pg(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=X[9],V=X[10],M=X[11],R=X[12],L=X[13],w=X[14],P=X[15],N=Y[0],v=Y[1],j=Y[2],O=Y[3];return J[0]=N*Z+v*K+j*H+O*R,J[1]=N*W+v*G+j*z+O*L,J[2]=N*$+v*F+j*V+O*w,J[3]=N*Q+v*q+j*M+O*P,N=Y[4],v=Y[5],j=Y[6],O=Y[7],J[4]=N*Z+v*K+j*H+O*R,J[5]=N*W+v*G+j*z+O*L,J[6]=N*$+v*F+j*V+O*w,J[7]=N*Q+v*q+j*M+O*P,N=Y[8],v=Y[9],j=Y[10],O=Y[11],J[8]=N*Z+v*K+j*H+O*R,J[9]=N*W+v*G+j*z+O*L,J[10]=N*$+v*F+j*V+O*w,J[11]=N*Q+v*q+j*M+O*P,N=Y[12],v=Y[13],j=Y[14],O=Y[15],J[12]=N*Z+v*K+j*H+O*R,J[13]=N*W+v*G+j*z+O*L,J[14]=N*$+v*F+j*V+O*w,J[15]=N*Q+v*q+j*M+O*P,J}function Ng(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[4],Q=X[5],K=X[6],G=X[8],F=X[9],q=X[10];return J[0]=Math.hypot(Y,Z,W),J[1]=Math.hypot($,Q,K),J[2]=Math.hypot(G,F,q),J}function vg(J,X){var Y=new eK(3);Ng(Y,X);var Z=1/Y[0],W=1/Y[1],$=1/Y[2],Q=X[0]*Z,K=X[1]*W,G=X[2]*$,F=X[4]*Z,q=X[5]*W,H=X[6]*$,z=X[8]*Z,V=X[9]*W,M=X[10]*$,R=Q+q+M,L=0;if(R>0)L=Math.sqrt(R+1)*2,J[3]=0.25*L,J[0]=(H-V)/L,J[1]=(z-G)/L,J[2]=(K-F)/L;else if(Q>q&&Q>M)L=Math.sqrt(1+Q-q-M)*2,J[3]=(H-V)/L,J[0]=0.25*L,J[1]=(K+F)/L,J[2]=(z+G)/L;else if(q>M)L=Math.sqrt(1+q-Q-M)*2,J[3]=(z-G)/L,J[0]=(K+F)/L,J[1]=0.25*L,J[2]=(H+V)/L;else L=Math.sqrt(1+M-Q-q)*2,J[3]=(K-F)/L,J[0]=(z+G)/L,J[1]=(H+V)/L,J[2]=0.25*L;return J}class b0{static identity(J){return J}static eq(J,X,Y=0.00001){if(J.length!==X.length)return!1;for(let Z=0;Z<J.length;Z++)if(Math.abs(J[Z]-X[Z])>Y)return!1;return!0}static clamp(J,X,Y){if(J<X)return X;if(J>Y)return Y;return J}static decodeNormalizedInt(J,X){switch(X){case 5126:return J;case 5123:return J/65535;case 5121:return J/255;case 5122:return Math.max(J/32767,-1);case 5120:return Math.max(J/127,-1);default:throw new Error("Invalid component type.")}}static encodeNormalizedInt(J,X){switch(X){case 5126:return J;case 5123:return Math.round(b0.clamp(J,0,1)*65535);case 5121:return Math.round(b0.clamp(J,0,1)*255);case 5122:return Math.round(b0.clamp(J,-1,1)*32767);case 5120:return Math.round(b0.clamp(J,-1,1)*127);default:throw new Error("Invalid component type.")}}static decompose(J,X,Y,Z){let W=tK([J[0],J[1],J[2]]),$=tK([J[4],J[5],J[6]]),Q=tK([J[8],J[9],J[10]]);if(xg(J)<0)W=-W;X[0]=J[12],X[1]=J[13],X[2]=J[14];let G=J.slice(),F=1/W,q=1/$,H=1/Q;G[0]*=F,G[1]*=F,G[2]*=F,G[4]*=q,G[5]*=q,G[6]*=q,G[8]*=H,G[9]*=H,G[10]*=H,vg(Y,G),Z[0]=W,Z[1]=$,Z[2]=Q}static compose(J,X,Y,Z){let W=Z,$=X[0],Q=X[1],K=X[2],G=X[3],F=$+$,q=Q+Q,H=K+K,z=$*F,V=$*q,M=$*H,R=Q*q,L=Q*H,w=K*H,P=G*F,N=G*q,v=G*H,j=Y[0],O=Y[1],D=Y[2];return W[0]=(1-(R+w))*j,W[1]=(V+v)*j,W[2]=(M-N)*j,W[3]=0,W[4]=(V-v)*O,W[5]=(1-(z+w))*O,W[6]=(L+P)*O,W[7]=0,W[8]=(M+N)*D,W[9]=(L-P)*D,W[10]=(1-(z+R))*D,W[11]=0,W[12]=J[0],W[13]=J[1],W[14]=J[2],W[15]=1,W}}function Bg(J,X){if(!!J!==!!X)return!1;let Y=J.getChild(),Z=X.getChild();return Y===Z||Y.equals(Z)}function jg(J,X){if(!!J!==!!X)return!1;let Y=J.values(),Z=X.values();if(Y.length!==Z.length)return!1;for(let W=0;W<Y.length;W++){let $=Y[W],Q=Z[W];if($.getChild()===Q.getChild())continue;if(!$.getChild().equals(Q.getChild()))return!1}return!0}function kg(J,X){if(!!J!==!!X)return!1;let Y=J.keys(),Z=X.keys();if(Y.length!==Z.length)return!1;for(let W of Y){let $=J.get(W),Q=X.get(W);if(!!$!==!!Q)return!1;let K=$.getChild(),G=Q.getChild();if(K===G)continue;if(!K.equals(G))return!1}return!0}function yR(J,X){if(J===X)return!0;if(!!J!==!!X||!J||!X)return!1;if(J.length!==X.length)return!1;for(let Y=0;Y<J.length;Y++)if(J[Y]!==X[Y])return!1;return!0}function gR(J,X){if(J===X)return!0;if(!!J!==!!X)return!1;if(!K9(J)||!K9(X))return J===X;let Y=J,Z=X,W=0,$=0,Q;for(Q in Y)W++;for(Q in Z)$++;if(W!==$)return!1;for(Q in Y){let K=Y[Q],G=Z[Q];if(cY(K)&&cY(G)){if(!yR(K,G))return!1}else if(K9(K)&&K9(G)){if(!gR(K,G))return!1}else if(K!==G)return!1}return!0}function cY(J){return Array.isArray(J)||ArrayBuffer.isView(J)}var ER="23456789abdegjkmnpqrvwxyzABDEGJKMNPQRVWXYZ",Tg=999,Dg=6,CR=new Set,_g=function J(){let X="";for(let Y=0;Y<Dg;Y++)X+=ER.charAt(Math.floor(Math.random()*ER.length));return X},cR=function J(){for(let X=0;X<Tg;X++){let Y=_g();if(!CR.has(Y))return CR.add(Y),Y}return""},SR="https://null.example";class r8{static dirname(J){let X=J.lastIndexOf("/");if(X===-1)return"./";return J.substring(0,X+1)}static basename(J){return Q1.basename(new URL(J,SR).pathname)}static extension(J){return Q1.extension(new URL(J,SR).pathname)}static resolve(J,X){if(!this.isRelativePath(X))return X;let Y=J.split("/"),Z=X.split("/");Y.pop();for(let W=0;W<Z.length;W++){if(Z[W]===".")continue;if(Z[W]==="..")Y.pop();else Y.push(Z[W])}return Y.join("/")}static isAbsoluteURL(J){return this.PROTOCOL_REGEXP.test(J)}static isRelativePath(J){return!/^(?:[a-zA-Z]+:)?\//.test(J)}}r8.DEFAULT_INIT={};r8.PROTOCOL_REGEXP=/^[a-zA-Z]+:\/\//;var _1=(J)=>J,Eg=new Set;class uY extends SY{constructor(J,X=""){super(J);this[L0].name=X,this.init(),this.dispatchEvent({type:"create"})}getGraph(){return this.graph}getDefaults(){return Object.assign(super.getDefaults(),{name:"",extras:{}})}set(J,X){if(Array.isArray(X))X=X.slice();return super.set(J,X)}getName(){return this.get("name")}setName(J){return this.set("name",J)}getExtras(){return this.get("extras")}setExtras(J){return this.set("extras",J)}clone(){return new this.constructor(this.graph).copy(this,_1)}copy(J,X=_1){for(let Y in this[L0]){let Z=this[L0][Y];if(Z instanceof T1){if(!this[k1].has(Y))Z.dispose()}else if(Z instanceof I6||Z instanceof _0)for(let W of Z.values())W.dispose();else if(Z instanceof o8)for(let W of Z.values())W.dispose()}for(let Y in J[L0]){let Z=this[L0][Y],W=J[L0][Y];if(W instanceof T1)if(this[k1].has(Y))Z.getChild().copy(X(W.getChild()),X);else this.setRef(Y,X(W.getChild()),W.getAttributes());else if(W instanceof _0||W instanceof I6)for(let $ of W.values())this.addRef(Y,X($.getChild()),$.getAttributes());else if(W instanceof o8)for(let $ of W.keys()){let Q=W.get($);this.setRefMap(Y,$,X(Q.getChild()),Q.getAttributes())}else if(K9(W))this[L0][Y]=JSON.parse(JSON.stringify(W));else if(Array.isArray(W)||W instanceof ArrayBuffer||ArrayBuffer.isView(W))this[L0][Y]=W.slice();else this[L0][Y]=W}return this}equals(J,X=Eg){if(this===J)return!0;if(this.propertyType!==J.propertyType)return!1;for(let Y in this[L0]){if(X.has(Y))continue;let Z=this[L0][Y],W=J[L0][Y];if(Z instanceof T1||W instanceof T1){if(!Bg(Z,W))return!1}else if(Z instanceof _0||W instanceof _0||Z instanceof I6||W instanceof I6){if(!jg(Z,W))return!1}else if(Z instanceof o8||W instanceof o8){if(!kg(Z,W))return!1}else if(K9(Z)||K9(W)){if(!gR(Z,W))return!1}else if(cY(Z)||cY(W)){if(!yR(Z,W))return!1}else if(Z!==W)return!1}return!0}detach(){return this.graph.disconnectParents(this,(J)=>J.propertyType!=="Root"),this}listParents(){return this.graph.listParents(this)}}class V8 extends uY{getDefaults(){return Object.assign(super.getDefaults(),{extensions:new o8})}getExtension(J){return this.getRefMap("extensions",J)}setExtension(J,X){if(X)X._validateParent(this);return this.setRefMap("extensions",J,X)}listExtensions(){return this.listRefMapValues("extensions")}}class i extends V8{init(){this.propertyType=p.ACCESSOR}getDefaults(){return Object.assign(super.getDefaults(),{array:null,type:i.Type.SCALAR,componentType:i.ComponentType.FLOAT,normalized:!1,sparse:!1,buffer:null})}static getElementSize(J){switch(J){case i.Type.SCALAR:return 1;case i.Type.VEC2:return 2;case i.Type.VEC3:return 3;case i.Type.VEC4:return 4;case i.Type.MAT2:return 4;case i.Type.MAT3:return 9;case i.Type.MAT4:return 16;default:throw new Error("Unexpected type: "+J)}}static getComponentSize(J){switch(J){case i.ComponentType.BYTE:return 1;case i.ComponentType.UNSIGNED_BYTE:return 1;case i.ComponentType.SHORT:return 2;case i.ComponentType.UNSIGNED_SHORT:return 2;case i.ComponentType.UNSIGNED_INT:return 4;case i.ComponentType.FLOAT:return 4;default:throw new Error("Unexpected component type: "+J)}}getMinNormalized(J){let X=this.getNormalized(),Y=this.getElementSize(),Z=this.getComponentType();if(this.getMin(J),X)for(let W=0;W<Y;W++)J[W]=b0.decodeNormalizedInt(J[W],Z);return J}getMin(J){let X=this.getArray(),Y=this.getCount(),Z=this.getElementSize();for(let W=0;W<Z;W++)J[W]=1/0;for(let W=0;W<Y*Z;W+=Z)for(let $=0;$<Z;$++){let Q=X[W+$];if(Number.isFinite(Q))J[$]=Math.min(J[$],Q)}return J}getMaxNormalized(J){let X=this.getNormalized(),Y=this.getElementSize(),Z=this.getComponentType();if(this.getMax(J),X)for(let W=0;W<Y;W++)J[W]=b0.decodeNormalizedInt(J[W],Z);return J}getMax(J){let X=this.get("array"),Y=this.getCount(),Z=this.getElementSize();for(let W=0;W<Z;W++)J[W]=-1/0;for(let W=0;W<Y*Z;W+=Z)for(let $=0;$<Z;$++){let Q=X[W+$];if(Number.isFinite(Q))J[$]=Math.max(J[$],Q)}return J}getCount(){let J=this.get("array");return J?J.length/this.getElementSize():0}getType(){return this.get("type")}setType(J){return this.set("type",J)}getElementSize(){return i.getElementSize(this.get("type"))}getComponentSize(){return this.get("array").BYTES_PER_ELEMENT}getComponentType(){return this.get("componentType")}getNormalized(){return this.get("normalized")}setNormalized(J){return this.set("normalized",J)}getScalar(J){let X=this.getElementSize(),Y=this.getComponentType(),Z=this.getArray();if(this.getNormalized())return b0.decodeNormalizedInt(Z[J*X],Y);return Z[J*X]}setScalar(J,X){let Y=this.getElementSize(),Z=this.getComponentType(),W=this.getArray();if(this.getNormalized())W[J*Y]=b0.encodeNormalizedInt(X,Z);else W[J*Y]=X;return this}getElement(J,X){let Y=this.getNormalized(),Z=this.getElementSize(),W=this.getComponentType(),$=this.getArray();for(let Q=0;Q<Z;Q++)if(Y)X[Q]=b0.decodeNormalizedInt($[J*Z+Q],W);else X[Q]=$[J*Z+Q];return X}setElement(J,X){let Y=this.getNormalized(),Z=this.getElementSize(),W=this.getComponentType(),$=this.getArray();for(let Q=0;Q<Z;Q++)if(Y)$[J*Z+Q]=b0.encodeNormalizedInt(X[Q],W);else $[J*Z+Q]=X[Q];return this}getSparse(){return this.get("sparse")}setSparse(J){return this.set("sparse",J)}getBuffer(){return this.getRef("buffer")}setBuffer(J){return this.setRef("buffer",J)}getArray(){return this.get("array")}setArray(J){return this.set("componentType",J?Cg(J):i.ComponentType.FLOAT),this.set("array",J),this}getByteLength(){let J=this.get("array");return J?J.byteLength:0}}i.Type={SCALAR:"SCALAR",VEC2:"VEC2",VEC3:"VEC3",VEC4:"VEC4",MAT2:"MAT2",MAT3:"MAT3",MAT4:"MAT4"};i.ComponentType={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126};function Cg(J){switch(J.constructor){case Float32Array:return i.ComponentType.FLOAT;case Uint32Array:return i.ComponentType.UNSIGNED_INT;case Uint16Array:return i.ComponentType.UNSIGNED_SHORT;case Uint8Array:return i.ComponentType.UNSIGNED_BYTE;case Int16Array:return i.ComponentType.SHORT;case Int8Array:return i.ComponentType.BYTE;default:throw new Error("Unknown accessor componentType.")}}class WG extends V8{init(){this.propertyType=p.ANIMATION}getDefaults(){return Object.assign(super.getDefaults(),{channels:new _0,samplers:new _0})}addChannel(J){return this.addRef("channels",J)}removeChannel(J){return this.removeRef("channels",J)}listChannels(){return this.listRefs("channels")}addSampler(J){return this.addRef("samplers",J)}removeSampler(J){return this.removeRef("samplers",J)}listSamplers(){return this.listRefs("samplers")}}class l4 extends V8{init(){this.propertyType=p.ANIMATION_CHANNEL}getDefaults(){return Object.assign(super.getDefaults(),{targetPath:null,targetNode:null,sampler:null})}getTargetPath(){return this.get("targetPath")}setTargetPath(J){return this.set("targetPath",J)}getTargetNode(){return this.getRef("targetNode")}setTargetNode(J){return this.setRef("targetNode",J)}getSampler(){return this.getRef("sampler")}setSampler(J){return this.setRef("sampler",J)}}l4.TargetPath={TRANSLATION:"translation",ROTATION:"rotation",SCALE:"scale",WEIGHTS:"weights"};class $5 extends V8{init(){this.propertyType=p.ANIMATION_SAMPLER}getDefaultAttributes(){return Object.assign(super.getDefaults(),{interpolation:$5.Interpolation.LINEAR,input:null,output:null})}getInterpolation(){return this.get("interpolation")}setInterpolation(J){return this.set("interpolation",J)}getInput(){return this.getRef("input")}setInput(J){return this.setRef("input",J,{usage:u8.OTHER})}getOutput(){return this.getRef("output")}setOutput(J){return this.setRef("output",J,{usage:u8.OTHER})}}$5.Interpolation={LINEAR:"LINEAR",STEP:"STEP",CUBICSPLINE:"CUBICSPLINE"};class $G extends V8{init(){this.propertyType=p.BUFFER}getDefaults(){return Object.assign(super.getDefaults(),{uri:""})}getURI(){return this.get("uri")}setURI(J){return this.set("uri",J)}}class G9 extends V8{init(){this.propertyType=p.CAMERA}getDefaults(){return Object.assign(super.getDefaults(),{type:G9.Type.PERSPECTIVE,znear:0.1,zfar:100,aspectRatio:null,yfov:Math.PI*2*50/360,xmag:1,ymag:1})}getType(){return this.get("type")}setType(J){return this.set("type",J)}getZNear(){return this.get("znear")}setZNear(J){return this.set("znear",J)}getZFar(){return this.get("zfar")}setZFar(J){return this.set("zfar",J)}getAspectRatio(){return this.get("aspectRatio")}setAspectRatio(J){return this.set("aspectRatio",J)}getYFov(){return this.get("yfov")}setYFov(J){return this.set("yfov",J)}getXMag(){return this.get("xmag")}setXMag(J){return this.set("xmag",J)}getYMag(){return this.get("ymag")}setYMag(J){return this.set("ymag",J)}}G9.Type={PERSPECTIVE:"perspective",ORTHOGRAPHIC:"orthographic"};class dY extends uY{_validateParent(J){if(!this.parentTypes.includes(J.propertyType))throw new Error(`Parent "${J.propertyType}" invalid for child "${this.propertyType}".`)}}dY.EXTENSION_NAME=void 0;class t8 extends V8{init(){this.propertyType=p.TEXTURE_INFO}getDefaults(){return Object.assign(super.getDefaults(),{texCoord:0,magFilter:null,minFilter:null,wrapS:t8.WrapMode.REPEAT,wrapT:t8.WrapMode.REPEAT})}getTexCoord(){return this.get("texCoord")}setTexCoord(J){return this.set("texCoord",J)}getMagFilter(){return this.get("magFilter")}setMagFilter(J){return this.set("magFilter",J)}getMinFilter(){return this.get("minFilter")}setMinFilter(J){return this.set("minFilter",J)}getWrapS(){return this.get("wrapS")}setWrapS(J){return this.set("wrapS",J)}getWrapT(){return this.get("wrapT")}setWrapT(J){return this.set("wrapT",J)}}t8.WrapMode={CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497};t8.MagFilter={NEAREST:9728,LINEAR:9729};t8.MinFilter={NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987};var{R:IY,G:hY,B:fY,A:Sg}=gY;class E1 extends V8{init(){this.propertyType=p.MATERIAL}getDefaults(){return Object.assign(super.getDefaults(),{alphaMode:E1.AlphaMode.OPAQUE,alphaCutoff:0.5,doubleSided:!1,baseColorFactor:[1,1,1,1],baseColorTexture:null,baseColorTextureInfo:new t8(this.graph,"baseColorTextureInfo"),emissiveFactor:[0,0,0],emissiveTexture:null,emissiveTextureInfo:new t8(this.graph,"emissiveTextureInfo"),normalScale:1,normalTexture:null,normalTextureInfo:new t8(this.graph,"normalTextureInfo"),occlusionStrength:1,occlusionTexture:null,occlusionTextureInfo:new t8(this.graph,"occlusionTextureInfo"),roughnessFactor:1,metallicFactor:1,metallicRoughnessTexture:null,metallicRoughnessTextureInfo:new t8(this.graph,"metallicRoughnessTextureInfo")})}getDoubleSided(){return this.get("doubleSided")}setDoubleSided(J){return this.set("doubleSided",J)}getAlpha(){return this.get("baseColorFactor")[3]}setAlpha(J){let X=this.get("baseColorFactor").slice();return X[3]=J,this.set("baseColorFactor",X)}getAlphaMode(){return this.get("alphaMode")}setAlphaMode(J){return this.set("alphaMode",J)}getAlphaCutoff(){return this.get("alphaCutoff")}setAlphaCutoff(J){return this.set("alphaCutoff",J)}getBaseColorFactor(){return this.get("baseColorFactor")}setBaseColorFactor(J){return this.set("baseColorFactor",J)}getBaseColorTexture(){return this.getRef("baseColorTexture")}getBaseColorTextureInfo(){return this.getRef("baseColorTexture")?this.getRef("baseColorTextureInfo"):null}setBaseColorTexture(J){return this.setRef("baseColorTexture",J,{channels:IY|hY|fY|Sg,isColor:!0})}getEmissiveFactor(){return this.get("emissiveFactor")}setEmissiveFactor(J){return this.set("emissiveFactor",J)}getEmissiveTexture(){return this.getRef("emissiveTexture")}getEmissiveTextureInfo(){return this.getRef("emissiveTexture")?this.getRef("emissiveTextureInfo"):null}setEmissiveTexture(J){return this.setRef("emissiveTexture",J,{channels:IY|hY|fY,isColor:!0})}getNormalScale(){return this.get("normalScale")}setNormalScale(J){return this.set("normalScale",J)}getNormalTexture(){return this.getRef("normalTexture")}getNormalTextureInfo(){return this.getRef("normalTexture")?this.getRef("normalTextureInfo"):null}setNormalTexture(J){return this.setRef("normalTexture",J,{channels:IY|hY|fY})}getOcclusionStrength(){return this.get("occlusionStrength")}setOcclusionStrength(J){return this.set("occlusionStrength",J)}getOcclusionTexture(){return this.getRef("occlusionTexture")}getOcclusionTextureInfo(){return this.getRef("occlusionTexture")?this.getRef("occlusionTextureInfo"):null}setOcclusionTexture(J){return this.setRef("occlusionTexture",J,{channels:IY})}getRoughnessFactor(){return this.get("roughnessFactor")}setRoughnessFactor(J){return this.set("roughnessFactor",J)}getMetallicFactor(){return this.get("metallicFactor")}setMetallicFactor(J){return this.set("metallicFactor",J)}getMetallicRoughnessTexture(){return this.getRef("metallicRoughnessTexture")}getMetallicRoughnessTextureInfo(){return this.getRef("metallicRoughnessTexture")?this.getRef("metallicRoughnessTextureInfo"):null}setMetallicRoughnessTexture(J){return this.setRef("metallicRoughnessTexture",J,{channels:hY|fY})}}E1.AlphaMode={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};class iY extends V8{init(){this.propertyType=p.MESH}getDefaults(){return Object.assign(super.getDefaults(),{weights:[],primitives:new _0})}addPrimitive(J){return this.addRef("primitives",J)}removePrimitive(J){return this.removeRef("primitives",J)}listPrimitives(){return this.listRefs("primitives")}getWeights(){return this.get("weights")}setWeights(J){return this.set("weights",J)}}class nY extends V8{init(){this.propertyType=p.NODE}getDefaults(){return Object.assign(super.getDefaults(),{translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1],weights:[],camera:null,mesh:null,skin:null,children:new _0})}copy(J,X=_1){if(X===_1)throw new Error("Node cannot be copied.");return super.copy(J,X)}getTranslation(){return this.get("translation")}getRotation(){return this.get("rotation")}getScale(){return this.get("scale")}setTranslation(J){return this.set("translation",J)}setRotation(J){return this.set("rotation",J)}setScale(J){return this.set("scale",J)}getMatrix(){return b0.compose(this.get("translation"),this.get("rotation"),this.get("scale"),[])}setMatrix(J){let X=this.get("translation").slice(),Y=this.get("rotation").slice(),Z=this.get("scale").slice();return b0.decompose(J,X,Y,Z),this.set("translation",X).set("rotation",Y).set("scale",Z)}getWorldTranslation(){let J=[0,0,0];return b0.decompose(this.getWorldMatrix(),J,[0,0,0,1],[1,1,1]),J}getWorldRotation(){let J=[0,0,0,1];return b0.decompose(this.getWorldMatrix(),[0,0,0],J,[1,1,1]),J}getWorldScale(){let J=[1,1,1];return b0.decompose(this.getWorldMatrix(),[0,0,0],[0,0,0,1],J),J}getWorldMatrix(){let J=[];for(let Z=this;Z!=null;Z=Z.getParentNode())J.push(Z);let X,Y=J.pop().getMatrix();while(X=J.pop())Pg(Y,Y,X.getMatrix());return Y}addChild(J){let X=J.getParentNode();if(X)X.removeChild(J);for(let Y of J.listParents())if(Y.propertyType===p.SCENE)Y.removeChild(J);return this.addRef("children",J)}removeChild(J){return this.removeRef("children",J)}listChildren(){return this.listRefs("children")}getParentNode(){for(let J of this.listParents())if(J.propertyType===p.NODE)return J;return null}getMesh(){return this.getRef("mesh")}setMesh(J){return this.setRef("mesh",J)}getCamera(){return this.getRef("camera")}setCamera(J){return this.setRef("camera",J)}getSkin(){return this.getRef("skin")}setSkin(J){return this.setRef("skin",J)}getWeights(){return this.get("weights")}setWeights(J){return this.set("weights",J)}traverse(J){J(this);for(let X of this.listChildren())X.traverse(J);return this}}class K1 extends V8{init(){this.propertyType=p.PRIMITIVE}getDefaults(){return Object.assign(super.getDefaults(),{mode:K1.Mode.TRIANGLES,material:null,indices:null,attributes:new o8,targets:new _0})}getIndices(){return this.getRef("indices")}setIndices(J){return this.setRef("indices",J,{usage:u8.ELEMENT_ARRAY_BUFFER})}getAttribute(J){return this.getRefMap("attributes",J)}setAttribute(J,X){return this.setRefMap("attributes",J,X,{usage:u8.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}getMaterial(){return this.getRef("material")}setMaterial(J){return this.setRef("material",J)}getMode(){return this.get("mode")}setMode(J){return this.set("mode",J)}listTargets(){return this.listRefs("targets")}addTarget(J){return this.addRef("targets",J)}removeTarget(J){return this.removeRef("targets",J)}}K1.Mode={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6};class QG extends uY{init(){this.propertyType=p.PRIMITIVE_TARGET}getDefaults(){return Object.assign(super.getDefaults(),{attributes:new o8})}getAttribute(J){return this.getRefMap("attributes",J)}setAttribute(J,X){return this.setRefMap("attributes",J,X,{usage:u8.ARRAY_BUFFER})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}function P8(){return P8=Object.assign?Object.assign.bind():function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)({}).hasOwnProperty.call(Y,Z)&&(J[Z]=Y[Z])}return J},P8.apply(null,arguments)}class aY extends V8{init(){this.propertyType=p.SCENE}getDefaults(){return Object.assign(super.getDefaults(),{children:new _0})}copy(J,X=_1){if(X===_1)throw new Error("Scene cannot be copied.");return super.copy(J,X)}addChild(J){let X=J.getParentNode();if(X)X.removeChild(J);return this.addRef("children",J)}removeChild(J){return this.removeRef("children",J)}listChildren(){return this.listRefs("children")}traverse(J){for(let X of this.listChildren())X.traverse(J);return this}}class KG extends V8{init(){this.propertyType=p.SKIN}getDefaults(){return Object.assign(super.getDefaults(),{skeleton:null,inverseBindMatrices:null,joints:new _0})}getSkeleton(){return this.getRef("skeleton")}setSkeleton(J){return this.setRef("skeleton",J)}getInverseBindMatrices(){return this.getRef("inverseBindMatrices")}setInverseBindMatrices(J){return this.setRef("inverseBindMatrices",J,{usage:u8.INVERSE_BIND_MATRICES})}addJoint(J){return this.addRef("joints",J)}removeJoint(J){return this.removeRef("joints",J)}listJoints(){return this.listRefs("joints")}}class sY extends V8{init(){this.propertyType=p.TEXTURE}getDefaults(){return Object.assign(super.getDefaults(),{image:null,mimeType:"",uri:""})}getMimeType(){return this.get("mimeType")||$1.extensionToMimeType(Q1.extension(this.get("uri")))}setMimeType(J){return this.set("mimeType",J)}getURI(){return this.get("uri")}setURI(J){this.set("uri",J);let X=$1.extensionToMimeType(Q1.extension(J));if(X)this.set("mimeType",X);return this}getImage(){return this.get("image")}setImage(J){return this.set("image",G0.assertView(J))}getSize(){let J=this.get("image");if(!J)return null;return $1.getSize(J,this.getMimeType())}}class GG extends V8{init(){this.propertyType=p.ROOT}getDefaults(){return Object.assign(super.getDefaults(),{asset:{generator:`glTF-Transform ${fR}`,version:"2.0"},defaultScene:null,accessors:new _0,animations:new _0,buffers:new _0,cameras:new _0,materials:new _0,meshes:new _0,nodes:new _0,scenes:new _0,skins:new _0,textures:new _0})}constructor(J){super(J);this._extensions=new Set,J.addEventListener("node:create",(X)=>{this._addChildOfRoot(X.target)})}clone(){throw new Error("Root cannot be cloned.")}copy(J,X=_1){if(X===_1)throw new Error("Root cannot be copied.");this.set("asset",P8({},J.get("asset"))),this.setName(J.getName()),this.setExtras(P8({},J.getExtras())),this.setDefaultScene(J.getDefaultScene()?X(J.getDefaultScene()):null);for(let Y of J.listRefMapKeys("extensions")){let Z=J.getExtension(Y);this.setExtension(Y,X(Z))}return this}_addChildOfRoot(J){if(J instanceof aY)this.addRef("scenes",J);else if(J instanceof nY)this.addRef("nodes",J);else if(J instanceof G9)this.addRef("cameras",J);else if(J instanceof KG)this.addRef("skins",J);else if(J instanceof iY)this.addRef("meshes",J);else if(J instanceof E1)this.addRef("materials",J);else if(J instanceof sY)this.addRef("textures",J);else if(J instanceof WG)this.addRef("animations",J);else if(J instanceof i)this.addRef("accessors",J);else if(J instanceof $G)this.addRef("buffers",J);return this}getAsset(){return this.get("asset")}listExtensionsUsed(){return Array.from(this._extensions)}listExtensionsRequired(){return this.listExtensionsUsed().filter((J)=>J.isRequired())}_enableExtension(J){return this._extensions.add(J),this}_disableExtension(J){return this._extensions.delete(J),this}listScenes(){return this.listRefs("scenes")}setDefaultScene(J){return this.setRef("defaultScene",J)}getDefaultScene(){return this.getRef("defaultScene")}listNodes(){return this.listRefs("nodes")}listCameras(){return this.listRefs("cameras")}listSkins(){return this.listRefs("skins")}listMeshes(){return this.listRefs("meshes")}listMaterials(){return this.listRefs("materials")}listTextures(){return this.listRefs("textures")}listAnimations(){return this.listRefs("animations")}listAccessors(){return this.listRefs("accessors")}listBuffers(){return this.listRefs("buffers")}}class W5{static fromGraph(J){return W5._GRAPH_DOCUMENTS.get(J)||null}constructor(){this._graph=new rK,this._root=new GG(this._graph),this._logger=e8.DEFAULT_INSTANCE,W5._GRAPH_DOCUMENTS.set(this._graph,this)}getRoot(){return this._root}getGraph(){return this._graph}getLogger(){return this._logger}setLogger(J){return this._logger=J,this}clone(){throw new Error("Use 'cloneDocument(source)' from '@gltf-transform/functions'.")}merge(J){throw new Error("Use 'mergeDocuments(target, source)' from '@gltf-transform/functions'.")}async transform(...J){let X=J.map((Y)=>Y.name);for(let Y of J)await Y(this,{stack:X});return this}createExtension(J){let X=J.EXTENSION_NAME;return this.getRoot().listExtensionsUsed().find((Z)=>Z.extensionName===X)||new J(this)}createScene(J=""){return new aY(this._graph,J)}createNode(J=""){return new nY(this._graph,J)}createCamera(J=""){return new G9(this._graph,J)}createSkin(J=""){return new KG(this._graph,J)}createMesh(J=""){return new iY(this._graph,J)}createPrimitive(){return new K1(this._graph)}createPrimitiveTarget(J=""){return new QG(this._graph,J)}createMaterial(J=""){return new E1(this._graph,J)}createTexture(J=""){return new sY(this._graph,J)}createAnimation(J=""){return new WG(this._graph,J)}createAnimationChannel(J=""){return new l4(this._graph,J)}createAnimationSampler(J=""){return new $5(this._graph,J)}createAccessor(J="",X=null){if(!X)X=this.getRoot().listBuffers()[0];return new i(this._graph,J).setBuffer(X)}createBuffer(J=""){return new $G(this._graph,J)}}W5._GRAPH_DOCUMENTS=new WeakMap;class mR{constructor(J){this.extensionName="",this.prereadTypes=[],this.prewriteTypes=[],this.readDependencies=[],this.writeDependencies=[],this.document=void 0,this.required=!1,this.properties=new Set,this._listener=void 0,this.document=J,J.getRoot()._enableExtension(this),this._listener=(Y)=>{let Z=Y,W=Z.target;if(W instanceof dY&&W.extensionName===this.extensionName){if(Z.type==="node:create")this._addExtensionProperty(W);if(Z.type==="node:dispose")this._removeExtensionProperty(W)}};let X=J.getGraph();X.addEventListener("node:create",this._listener),X.addEventListener("node:dispose",this._listener)}dispose(){this.document.getRoot()._disableExtension(this);let J=this.document.getGraph();J.removeEventListener("node:create",this._listener),J.removeEventListener("node:dispose",this._listener);for(let X of this.properties)X.dispose()}static register(){}isRequired(){return this.required}setRequired(J){return this.required=J,this}listProperties(){return Array.from(this.properties)}_addExtensionProperty(J){return this.properties.add(J),this}_removeExtensionProperty(J){return this.properties.delete(J),this}install(J,X){return this}preread(J,X){return this}prewrite(J,X){return this}}mR.EXTENSION_NAME=void 0;class lR{constructor(J){this.jsonDoc=void 0,this.buffers=[],this.bufferViews=[],this.bufferViewBuffers=[],this.accessors=[],this.textures=[],this.textureInfos=new Map,this.materials=[],this.meshes=[],this.cameras=[],this.nodes=[],this.skins=[],this.animations=[],this.scenes=[],this.jsonDoc=J}setTextureInfo(J,X){if(this.textureInfos.set(J,X),X.texCoord!==void 0)J.setTexCoord(X.texCoord);if(X.extras!==void 0)J.setExtras(X.extras);let Y=this.jsonDoc.json.textures[X.index];if(Y.sampler===void 0)return;let Z=this.jsonDoc.json.samplers[Y.sampler];if(Z.magFilter!==void 0)J.setMagFilter(Z.magFilter);if(Z.minFilter!==void 0)J.setMinFilter(Z.minFilter);if(Z.wrapS!==void 0)J.setWrapS(Z.wrapS);if(Z.wrapT!==void 0)J.setWrapT(Z.wrapT)}}var IR={logger:e8.DEFAULT_INSTANCE,extensions:[],dependencies:{}},Ig=new Set([p.BUFFER,p.TEXTURE,p.MATERIAL,p.MESH,p.PRIMITIVE,p.NODE,p.SCENE]);class uR{static read(J,X=IR){let Y=P8({},IR,X),{json:Z}=J,W=new W5().setLogger(Y.logger);this.validate(J,Y);let $=new lR(J),Q=Z.asset,K=W.getRoot().getAsset();if(Q.copyright)K.copyright=Q.copyright;if(Q.extras)K.extras=Q.extras;if(Z.extras!==void 0)W.getRoot().setExtras(P8({},Z.extras));let G=Z.extensionsUsed||[],F=Z.extensionsRequired||[];Y.extensions.sort((O,D)=>O.EXTENSION_NAME>D.EXTENSION_NAME?1:-1);for(let O of Y.extensions)if(G.includes(O.EXTENSION_NAME)){let D=W.createExtension(O).setRequired(F.includes(O.EXTENSION_NAME)),_=D.prereadTypes.filter((C)=>!Ig.has(C));if(_.length)Y.logger.warn(`Preread hooks for some types (${_.join()}), requested by extension ${D.extensionName}, are unsupported. Please file an issue or a PR.`);for(let C of D.readDependencies)D.install(C,Y.dependencies[C])}let q=Z.buffers||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.BUFFER)).forEach((O)=>O.preread($,p.BUFFER)),$.buffers=q.map((O)=>{let D=W.createBuffer(O.name);if(O.extras)D.setExtras(O.extras);if(O.uri&&O.uri.indexOf("__")!==0)D.setURI(O.uri);return D});let H=Z.bufferViews||[];$.bufferViewBuffers=H.map((O,D)=>{if(!$.bufferViews[D]){let _=J.json.buffers[O.buffer],C=_.uri?J.resources[_.uri]:J.resources[AY],S=O.byteOffset||0;$.bufferViews[D]=G0.toView(C,S,O.byteLength)}return $.buffers[O.buffer]});let z=Z.accessors||[];$.accessors=z.map((O)=>{let D=$.bufferViewBuffers[O.bufferView],_=W.createAccessor(O.name,D).setType(O.type);if(O.extras)_.setExtras(O.extras);if(O.normalized!==void 0)_.setNormalized(O.normalized);if(O.bufferView===void 0)return _;return _.setArray(pY(O,$)),_});let V=Z.images||[],M=Z.textures||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.TEXTURE)).forEach((O)=>O.preread($,p.TEXTURE)),$.textures=V.map((O)=>{let D=W.createTexture(O.name);if(O.extras)D.setExtras(O.extras);if(O.bufferView!==void 0){let _=Z.bufferViews[O.bufferView],C=J.json.buffers[_.buffer],S=C.uri?J.resources[C.uri]:J.resources[AY],I=_.byteOffset||0,f=_.byteLength,y=S.slice(I,I+f);D.setImage(y)}else if(O.uri!==void 0){if(D.setImage(J.resources[O.uri]),O.uri.indexOf("__")!==0)D.setURI(O.uri)}if(O.mimeType!==void 0)D.setMimeType(O.mimeType);else if(O.uri){let _=Q1.extension(O.uri);D.setMimeType($1.extensionToMimeType(_))}return D}),W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.MATERIAL)).forEach((O)=>O.preread($,p.MATERIAL));let R=Z.materials||[];$.materials=R.map((O)=>{let D=W.createMaterial(O.name);if(O.extras)D.setExtras(O.extras);if(O.alphaMode!==void 0)D.setAlphaMode(O.alphaMode);if(O.alphaCutoff!==void 0)D.setAlphaCutoff(O.alphaCutoff);if(O.doubleSided!==void 0)D.setDoubleSided(O.doubleSided);let _=O.pbrMetallicRoughness||{};if(_.baseColorFactor!==void 0)D.setBaseColorFactor(_.baseColorFactor);if(O.emissiveFactor!==void 0)D.setEmissiveFactor(O.emissiveFactor);if(_.metallicFactor!==void 0)D.setMetallicFactor(_.metallicFactor);if(_.roughnessFactor!==void 0)D.setRoughnessFactor(_.roughnessFactor);if(_.baseColorTexture!==void 0){let C=_.baseColorTexture,S=$.textures[M[C.index].source];D.setBaseColorTexture(S),$.setTextureInfo(D.getBaseColorTextureInfo(),C)}if(O.emissiveTexture!==void 0){let C=O.emissiveTexture,S=$.textures[M[C.index].source];D.setEmissiveTexture(S),$.setTextureInfo(D.getEmissiveTextureInfo(),C)}if(O.normalTexture!==void 0){let C=O.normalTexture,S=$.textures[M[C.index].source];if(D.setNormalTexture(S),$.setTextureInfo(D.getNormalTextureInfo(),C),O.normalTexture.scale!==void 0)D.setNormalScale(O.normalTexture.scale)}if(O.occlusionTexture!==void 0){let C=O.occlusionTexture,S=$.textures[M[C.index].source];if(D.setOcclusionTexture(S),$.setTextureInfo(D.getOcclusionTextureInfo(),C),O.occlusionTexture.strength!==void 0)D.setOcclusionStrength(O.occlusionTexture.strength)}if(_.metallicRoughnessTexture!==void 0){let C=_.metallicRoughnessTexture,S=$.textures[M[C.index].source];D.setMetallicRoughnessTexture(S),$.setTextureInfo(D.getMetallicRoughnessTextureInfo(),C)}return D}),W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.MESH)).forEach((O)=>O.preread($,p.MESH));let L=Z.meshes||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.PRIMITIVE)).forEach((O)=>O.preread($,p.PRIMITIVE)),$.meshes=L.map((O)=>{let D=W.createMesh(O.name);if(O.extras)D.setExtras(O.extras);if(O.weights!==void 0)D.setWeights(O.weights);return(O.primitives||[]).forEach((C)=>{let S=W.createPrimitive();if(C.extras)S.setExtras(C.extras);if(C.material!==void 0)S.setMaterial($.materials[C.material]);if(C.mode!==void 0)S.setMode(C.mode);for(let[y,h]of Object.entries(C.attributes||{}))S.setAttribute(y,$.accessors[h]);if(C.indices!==void 0)S.setIndices($.accessors[C.indices]);let I=O.extras&&O.extras.targetNames||[];(C.targets||[]).forEach((y,h)=>{let g=I[h]||h.toString(),J0=W.createPrimitiveTarget(g);for(let[p0,a0]of Object.entries(y))J0.setAttribute(p0,$.accessors[a0]);S.addTarget(J0)}),D.addPrimitive(S)}),D});let w=Z.cameras||[];$.cameras=w.map((O)=>{let D=W.createCamera(O.name).setType(O.type);if(O.extras)D.setExtras(O.extras);if(O.type===G9.Type.PERSPECTIVE){let _=O.perspective;if(D.setYFov(_.yfov),D.setZNear(_.znear),_.zfar!==void 0)D.setZFar(_.zfar);if(_.aspectRatio!==void 0)D.setAspectRatio(_.aspectRatio)}else{let _=O.orthographic;D.setZNear(_.znear).setZFar(_.zfar).setXMag(_.xmag).setYMag(_.ymag)}return D});let P=Z.nodes||[];W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.NODE)).forEach((O)=>O.preread($,p.NODE)),$.nodes=P.map((O)=>{let D=W.createNode(O.name);if(O.extras)D.setExtras(O.extras);if(O.translation!==void 0)D.setTranslation(O.translation);if(O.rotation!==void 0)D.setRotation(O.rotation);if(O.scale!==void 0)D.setScale(O.scale);if(O.matrix!==void 0){let _=[0,0,0],C=[0,0,0,1],S=[1,1,1];b0.decompose(O.matrix,_,C,S),D.setTranslation(_),D.setRotation(C),D.setScale(S)}if(O.weights!==void 0)D.setWeights(O.weights);return D});let N=Z.skins||[];$.skins=N.map((O)=>{let D=W.createSkin(O.name);if(O.extras)D.setExtras(O.extras);if(O.inverseBindMatrices!==void 0)D.setInverseBindMatrices($.accessors[O.inverseBindMatrices]);if(O.skeleton!==void 0)D.setSkeleton($.nodes[O.skeleton]);for(let _ of O.joints)D.addJoint($.nodes[_]);return D}),P.map((O,D)=>{let _=$.nodes[D];if((O.children||[]).forEach((S)=>_.addChild($.nodes[S])),O.mesh!==void 0)_.setMesh($.meshes[O.mesh]);if(O.camera!==void 0)_.setCamera($.cameras[O.camera]);if(O.skin!==void 0)_.setSkin($.skins[O.skin])});let v=Z.animations||[];$.animations=v.map((O)=>{let D=W.createAnimation(O.name);if(O.extras)D.setExtras(O.extras);let C=(O.samplers||[]).map((I)=>{let f=W.createAnimationSampler().setInput($.accessors[I.input]).setOutput($.accessors[I.output]).setInterpolation(I.interpolation||$5.Interpolation.LINEAR);if(I.extras)f.setExtras(I.extras);return D.addSampler(f),f});return(O.channels||[]).forEach((I)=>{let f=W.createAnimationChannel().setSampler(C[I.sampler]).setTargetPath(I.target.path);if(I.target.node!==void 0)f.setTargetNode($.nodes[I.target.node]);if(I.extras)f.setExtras(I.extras);D.addChannel(f)}),D});let j=Z.scenes||[];if(W.getRoot().listExtensionsUsed().filter((O)=>O.prereadTypes.includes(p.SCENE)).forEach((O)=>O.preread($,p.SCENE)),$.scenes=j.map((O)=>{let D=W.createScene(O.name);if(O.extras)D.setExtras(O.extras);return(O.nodes||[]).map((C)=>$.nodes[C]).forEach((C)=>D.addChild(C)),D}),Z.scene!==void 0)W.getRoot().setDefaultScene($.scenes[Z.scene]);return W.getRoot().listExtensionsUsed().forEach((O)=>O.read($)),z.forEach((O,D)=>{let _=$.accessors[D],C=!!O.sparse,S=!O.bufferView&&!_.getArray();if(C||S)_.setSparse(!0).setArray(fg(O,$))}),W}static validate(J,X){let Y=J.json;if(Y.asset.version!=="2.0")throw new Error(`Unsupported glTF version, "${Y.asset.version}".`);if(Y.extensionsRequired){for(let Z of Y.extensionsRequired)if(!X.extensions.find((W)=>W.EXTENSION_NAME===Z))throw new Error(`Missing required extension, "${Z}".`)}if(Y.extensionsUsed){for(let Z of Y.extensionsUsed)if(!X.extensions.find((W)=>W.EXTENSION_NAME===Z))X.logger.warn(`Missing optional extension, "${Z}".`)}}}function hg(J,X){let Y=X.jsonDoc,Z=X.bufferViews[J.bufferView],W=Y.json.bufferViews[J.bufferView],$=m4[J.componentType],Q=i.getElementSize(J.type),K=$.BYTES_PER_ELEMENT,G=J.byteOffset||0,F=new $(J.count*Q),q=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),H=W.byteStride;for(let z=0;z<J.count;z++)for(let V=0;V<Q;V++){let M=G+z*H+V*K,R;switch(J.componentType){case i.ComponentType.FLOAT:R=q.getFloat32(M,!0);break;case i.ComponentType.UNSIGNED_INT:R=q.getUint32(M,!0);break;case i.ComponentType.UNSIGNED_SHORT:R=q.getUint16(M,!0);break;case i.ComponentType.UNSIGNED_BYTE:R=q.getUint8(M);break;case i.ComponentType.SHORT:R=q.getInt16(M,!0);break;case i.ComponentType.BYTE:R=q.getInt8(M);break;default:throw new Error(`Unexpected componentType "${J.componentType}".`)}F[z*Q+V]=R}return F}function pY(J,X){let Y=X.jsonDoc,Z=X.bufferViews[J.bufferView],W=Y.json.bufferViews[J.bufferView],$=m4[J.componentType],Q=i.getElementSize(J.type),K=$.BYTES_PER_ELEMENT,G=Q*K;if(W.byteStride!==void 0&&W.byteStride!==G)return hg(J,X);let F=Z.byteOffset+(J.byteOffset||0),q=J.count*Q*K;return new $(Z.buffer.slice(F,F+q))}function fg(J,X){let Y=m4[J.componentType],Z=i.getElementSize(J.type),W;if(J.bufferView!==void 0)W=pY(J,X);else W=new Y(J.count*Z);let $=J.sparse;if(!$)return W;let Q=$.count,K=P8({},J,$.indices,{count:Q,type:"SCALAR"}),G=P8({},J,$.values,{count:Q}),F=pY(K,X),q=pY(G,X);for(let H=0;H<K.count;H++)for(let z=0;z<Z;z++)W[F[H]*Z+z]=q[H*Z+z];return W}var c4;(function(J){J[J.ARRAY_BUFFER=34962]="ARRAY_BUFFER",J[J.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER"})(c4||(c4={}));class D1{constructor(J,X,Y){this._doc=void 0,this.jsonDoc=void 0,this.options=void 0,this.accessorIndexMap=new Map,this.animationIndexMap=new Map,this.bufferIndexMap=new Map,this.cameraIndexMap=new Map,this.skinIndexMap=new Map,this.materialIndexMap=new Map,this.meshIndexMap=new Map,this.nodeIndexMap=new Map,this.imageIndexMap=new Map,this.textureDefIndexMap=new Map,this.textureInfoDefMap=new Map,this.samplerDefIndexMap=new Map,this.sceneIndexMap=new Map,this.imageBufferViews=[],this.otherBufferViews=new Map,this.otherBufferViewsIndexMap=new Map,this.extensionData={},this.bufferURIGenerator=void 0,this.imageURIGenerator=void 0,this.logger=void 0,this._accessorUsageMap=new Map,this.accessorUsageGroupedByParent=new Set(["ARRAY_BUFFER"]),this.accessorParents=new Map,this._doc=J,this.jsonDoc=X,this.options=Y;let Z=J.getRoot(),W=Z.listBuffers().length,$=Z.listTextures().length;this.bufferURIGenerator=new ZG(W>1,()=>Y.basename||"buffer"),this.imageURIGenerator=new ZG($>1,(Q)=>bg(J,Q)||Y.basename||"texture"),this.logger=J.getLogger()}createTextureInfoDef(J,X){let Y={magFilter:X.getMagFilter()||void 0,minFilter:X.getMinFilter()||void 0,wrapS:X.getWrapS(),wrapT:X.getWrapT()},Z=JSON.stringify(Y);if(!this.samplerDefIndexMap.has(Z))this.samplerDefIndexMap.set(Z,this.jsonDoc.json.samplers.length),this.jsonDoc.json.samplers.push(Y);let W={source:this.imageIndexMap.get(J),sampler:this.samplerDefIndexMap.get(Z)},$=JSON.stringify(W);if(!this.textureDefIndexMap.has($))this.textureDefIndexMap.set($,this.jsonDoc.json.textures.length),this.jsonDoc.json.textures.push(W);let Q={index:this.textureDefIndexMap.get($)};if(X.getTexCoord()!==0)Q.texCoord=X.getTexCoord();if(Object.keys(X.getExtras()).length>0)Q.extras=X.getExtras();return this.textureInfoDefMap.set(X,Q),Q}createPropertyDef(J){let X={};if(J.getName())X.name=J.getName();if(Object.keys(J.getExtras()).length>0)X.extras=J.getExtras();return X}createAccessorDef(J){let X=this.createPropertyDef(J);if(X.type=J.getType(),X.componentType=J.getComponentType(),X.count=J.getCount(),this._doc.getGraph().listParentEdges(J).some((Z)=>Z.getName()==="attributes"&&Z.getAttributes().key==="POSITION"||Z.getName()==="input"))X.max=J.getMax([]).map(Math.fround),X.min=J.getMin([]).map(Math.fround);if(J.getNormalized())X.normalized=J.getNormalized();return X}createImageData(J,X,Y){if(this.options.format===W1.GLB)this.imageBufferViews.push(X),J.bufferView=this.jsonDoc.json.bufferViews.length,this.jsonDoc.json.bufferViews.push({buffer:0,byteOffset:-1,byteLength:X.byteLength});else{let Z=$1.mimeTypeToExtension(Y.getMimeType());J.uri=this.imageURIGenerator.createURI(Y,Z),this.assignResourceURI(J.uri,X,!1)}}assignResourceURI(J,X,Y){let Z=this.jsonDoc.resources;if(!(J in Z)){Z[J]=X;return}if(X===Z[J]){this.logger.warn(`Duplicate resource URI, "${J}".`);return}let W=`Resource URI "${J}" already assigned to different data.`;if(!Y){this.logger.warn(W);return}throw new Error(W)}getAccessorUsage(J){let X=this._accessorUsageMap.get(J);if(X)return X;if(J.getSparse())return u8.SPARSE;for(let Y of this._doc.getGraph().listParentEdges(J)){let{usage:Z}=Y.getAttributes();if(Z)return Z;if(Y.getParent().propertyType!==p.ROOT)this.logger.warn(`Missing attribute ".usage" on edge, "${Y.getName()}".`)}return u8.OTHER}addAccessorToUsageGroup(J,X){let Y=this._accessorUsageMap.get(J);if(Y&&Y!==X)throw new Error(`Accessor with usage "${Y}" cannot be reused as "${X}".`);return this._accessorUsageMap.set(J,X),this}}D1.BufferViewTarget=c4;D1.BufferViewUsage=u8;D1.USAGE_TO_TARGET={[u8.ARRAY_BUFFER]:c4.ARRAY_BUFFER,[u8.ELEMENT_ARRAY_BUFFER]:c4.ELEMENT_ARRAY_BUFFER};class ZG{constructor(J,X){this.multiple=void 0,this.basename=void 0,this.counter={},this.multiple=J,this.basename=X}createURI(J,X){if(J.getURI())return J.getURI();else if(!this.multiple)return`${this.basename(J)}.${X}`;else{let Y=this.basename(J);return this.counter[Y]=this.counter[Y]||1,`${Y}_${this.counter[Y]++}.${X}`}}}function bg(J,X){let Y=J.getGraph().listParentEdges(X).find((Z)=>Z.getParent()!==J.getRoot());return Y?Y.getName().replace(/texture$/i,""):""}var{BufferViewUsage:bY}=D1,{UNSIGNED_INT:pg,UNSIGNED_SHORT:Ag,UNSIGNED_BYTE:yg}=i.ComponentType,gg=new Set([p.ACCESSOR,p.BUFFER,p.MATERIAL,p.MESH]);class dR{static write(J,X){let Y=J.getGraph(),Z=J.getRoot(),W={asset:P8({generator:`glTF-Transform ${fR}`},Z.getAsset()),extras:P8({},Z.getExtras())},$={json:W,resources:{}},Q=new D1(J,$,X),K=X.logger||e8.DEFAULT_INSTANCE,G=new Set(X.extensions.map((L)=>L.EXTENSION_NAME)),F=J.getRoot().listExtensionsUsed().filter((L)=>G.has(L.extensionName)).sort((L,w)=>L.extensionName>w.extensionName?1:-1),q=J.getRoot().listExtensionsRequired().filter((L)=>G.has(L.extensionName)).sort((L,w)=>L.extensionName>w.extensionName?1:-1);if(F.length<J.getRoot().listExtensionsUsed().length)K.warn("Some extensions were not registered for I/O, and will not be written.");for(let L of F){let w=L.prewriteTypes.filter((P)=>!gg.has(P));if(w.length)K.warn(`Prewrite hooks for some types (${w.join()}), requested by extension ${L.extensionName}, are unsupported. Please file an issue or a PR.`);for(let P of L.writeDependencies)L.install(P,X.dependencies[P])}function H(L,w,P,N){let v=[],j=0;for(let _ of L){let C=Q.createAccessorDef(_);C.bufferView=W.bufferViews.length;let S=_.getArray(),I=G0.pad(G0.toView(S));C.byteOffset=j,j+=I.byteLength,v.push(I),Q.accessorIndexMap.set(_,W.accessors.length),W.accessors.push(C)}let O=G0.concat(v),D={buffer:w,byteOffset:P,byteLength:O.byteLength};if(N)D.target=N;return W.bufferViews.push(D),{buffers:v,byteLength:j}}function z(L,w,P){let N=L[0].getCount(),v=0;for(let C of L){let S=Q.createAccessorDef(C);S.bufferView=W.bufferViews.length,S.byteOffset=v;let I=C.getElementSize(),f=C.getComponentSize();v+=G0.padNumber(I*f),Q.accessorIndexMap.set(C,W.accessors.length),W.accessors.push(S)}let j=N*v,O=new ArrayBuffer(j),D=new DataView(O);for(let C=0;C<N;C++){let S=0;for(let I of L){let f=I.getElementSize(),y=I.getComponentSize(),h=I.getComponentType(),g=I.getArray();for(let J0=0;J0<f;J0++){let p0=C*v+S+J0*y,a0=g[C*f+J0];switch(h){case i.ComponentType.FLOAT:D.setFloat32(p0,a0,!0);break;case i.ComponentType.BYTE:D.setInt8(p0,a0);break;case i.ComponentType.SHORT:D.setInt16(p0,a0,!0);break;case i.ComponentType.UNSIGNED_BYTE:D.setUint8(p0,a0);break;case i.ComponentType.UNSIGNED_SHORT:D.setUint16(p0,a0,!0);break;case i.ComponentType.UNSIGNED_INT:D.setUint32(p0,a0,!0);break;default:throw new Error("Unexpected component type: "+h)}}S+=G0.padNumber(f*y)}}let _={buffer:w,byteOffset:P,byteLength:j,byteStride:v,target:D1.BufferViewTarget.ARRAY_BUFFER};return W.bufferViews.push(_),{byteLength:j,buffers:[new Uint8Array(O)]}}function V(L,w,P){let N=[],v=0,j=new Map,O=-1/0,D=!1;for(let h of L){let g=Q.createAccessorDef(h);W.accessors.push(g),Q.accessorIndexMap.set(h,W.accessors.length-1);let J0=[],p0=[],a0=[],Q6=new Array(h.getElementSize()).fill(0);for(let Z4=0,DS=h.getCount();Z4<DS;Z4++){if(h.getElement(Z4,a0),b0.eq(a0,Q6,0))continue;O=Math.max(Z4,O),J0.push(Z4);for(let z$=0;z$<a0.length;z$++)p0.push(a0[z$])}let n6=J0.length,Y4={accessorDef:g,count:n6};if(j.set(h,Y4),n6===0)continue;if(n6>h.getCount()/2)D=!0;let TS=m4[h.getComponentType()];Y4.indices=J0,Y4.values=new TS(p0)}if(!Number.isFinite(O))return{buffers:N,byteLength:v};if(D)K.warn("Some sparse accessors have >50% non-zero elements, which may increase file size.");let _=O<255?Uint8Array:O<65535?Uint16Array:Uint32Array,C=O<255?yg:O<65535?Ag:pg,S={buffer:w,byteOffset:P+v,byteLength:0};for(let h of L){let g=j.get(h);if(g.count===0)continue;g.indicesByteOffset=S.byteLength;let J0=G0.pad(G0.toView(new _(g.indices)));N.push(J0),v+=J0.byteLength,S.byteLength+=J0.byteLength}W.bufferViews.push(S);let I=W.bufferViews.length-1,f={buffer:w,byteOffset:P+v,byteLength:0};for(let h of L){let g=j.get(h);if(g.count===0)continue;g.valuesByteOffset=f.byteLength;let J0=G0.pad(G0.toView(g.values));N.push(J0),v+=J0.byteLength,f.byteLength+=J0.byteLength}W.bufferViews.push(f);let y=W.bufferViews.length-1;for(let h of L){let g=j.get(h);if(g.count===0)continue;g.accessorDef.sparse={count:g.count,indices:{bufferView:I,byteOffset:g.indicesByteOffset,componentType:C},values:{bufferView:y,byteOffset:g.valuesByteOffset}}}return{buffers:N,byteLength:v}}if(W.accessors=[],W.bufferViews=[],W.samplers=[],W.textures=[],W.images=Z.listTextures().map((L,w)=>{let P=Q.createPropertyDef(L);if(L.getMimeType())P.mimeType=L.getMimeType();let N=L.getImage();if(N)Q.createImageData(P,N,L);return Q.imageIndexMap.set(L,w),P}),F.filter((L)=>L.prewriteTypes.includes(p.ACCESSOR)).forEach((L)=>L.prewrite(Q,p.ACCESSOR)),Z.listAccessors().forEach((L)=>{let{accessorUsageGroupedByParent:w,accessorParents:P}=Q;if(Q.accessorIndexMap.has(L))return;let N=Q.getAccessorUsage(L);if(Q.addAccessorToUsageGroup(L,N),w.has(N)){let v=Y.listParents(L).find((j)=>j.propertyType!==p.ROOT);P.set(L,v)}}),F.filter((L)=>L.prewriteTypes.includes(p.BUFFER)).forEach((L)=>L.prewrite(Q,p.BUFFER)),(Z.listAccessors().length>0||Q.otherBufferViews.size>0||Z.listTextures().length>0&&X.format===W1.GLB)&&Z.listBuffers().length===0)throw new Error("Buffer required for Document resources, but none was found.");if(W.buffers=[],Z.listBuffers().forEach((L,w)=>{let P=Q.createPropertyDef(L),N=Q.accessorUsageGroupedByParent,v=L.listParents().filter((f)=>f instanceof i),j=new Set(v.map((f)=>Q.accessorParents.get(f))),O=new Map(Array.from(j).map((f,y)=>[f,y])),D={};for(let f of v){var _;if(Q.accessorIndexMap.has(f))continue;let y=Q.getAccessorUsage(f),h=y;if(N.has(y)){let g=Q.accessorParents.get(f);h+=`:${O.get(g)}`}D[_=h]||(D[_]={usage:y,accessors:[]}),D[h].accessors.push(f)}let C=[],S=W.buffers.length,I=0;for(let{usage:f,accessors:y}of Object.values(D))if(f===bY.ARRAY_BUFFER&&X.vertexLayout===yY.INTERLEAVED){let h=z(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}else if(f===bY.ARRAY_BUFFER)for(let h of y){let g=z([h],S,I);I+=g.byteLength;for(let J0 of g.buffers)C.push(J0)}else if(f===bY.SPARSE){let h=V(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}else if(f===bY.ELEMENT_ARRAY_BUFFER){let h=D1.BufferViewTarget.ELEMENT_ARRAY_BUFFER,g=H(y,S,I,h);I+=g.byteLength;for(let J0 of g.buffers)C.push(J0)}else{let h=H(y,S,I);I+=h.byteLength;for(let g of h.buffers)C.push(g)}if(Q.imageBufferViews.length&&w===0){for(let f=0;f<Q.imageBufferViews.length;f++)if(W.bufferViews[W.images[f].bufferView].byteOffset=I,I+=Q.imageBufferViews[f].byteLength,C.push(Q.imageBufferViews[f]),I%8){let y=8-I%8;I+=y,C.push(new Uint8Array(y))}}if(Q.otherBufferViews.has(L))for(let f of Q.otherBufferViews.get(L))W.bufferViews.push({buffer:S,byteOffset:I,byteLength:f.byteLength}),Q.otherBufferViewsIndexMap.set(f,W.bufferViews.length-1),I+=f.byteLength,C.push(f);if(I){let f;if(X.format===W1.GLB)f=AY;else f=Q.bufferURIGenerator.createURI(L,"bin"),P.uri=f;P.byteLength=I,Q.assignResourceURI(f,G0.concat(C),!0)}W.buffers.push(P),Q.bufferIndexMap.set(L,w)}),Z.listAccessors().find((L)=>!L.getBuffer()))K.warn("Skipped writing one or more Accessors: no Buffer assigned.");F.filter((L)=>L.prewriteTypes.includes(p.MATERIAL)).forEach((L)=>L.prewrite(Q,p.MATERIAL)),W.materials=Z.listMaterials().map((L,w)=>{let P=Q.createPropertyDef(L);if(L.getAlphaMode()!==E1.AlphaMode.OPAQUE)P.alphaMode=L.getAlphaMode();if(L.getAlphaMode()===E1.AlphaMode.MASK)P.alphaCutoff=L.getAlphaCutoff();if(L.getDoubleSided())P.doubleSided=!0;if(P.pbrMetallicRoughness={},!b0.eq(L.getBaseColorFactor(),[1,1,1,1]))P.pbrMetallicRoughness.baseColorFactor=L.getBaseColorFactor();if(!b0.eq(L.getEmissiveFactor(),[0,0,0]))P.emissiveFactor=L.getEmissiveFactor();if(L.getRoughnessFactor()!==1)P.pbrMetallicRoughness.roughnessFactor=L.getRoughnessFactor();if(L.getMetallicFactor()!==1)P.pbrMetallicRoughness.metallicFactor=L.getMetallicFactor();if(L.getBaseColorTexture()){let N=L.getBaseColorTexture(),v=L.getBaseColorTextureInfo();P.pbrMetallicRoughness.baseColorTexture=Q.createTextureInfoDef(N,v)}if(L.getEmissiveTexture()){let N=L.getEmissiveTexture(),v=L.getEmissiveTextureInfo();P.emissiveTexture=Q.createTextureInfoDef(N,v)}if(L.getNormalTexture()){let N=L.getNormalTexture(),v=L.getNormalTextureInfo(),j=Q.createTextureInfoDef(N,v);if(L.getNormalScale()!==1)j.scale=L.getNormalScale();P.normalTexture=j}if(L.getOcclusionTexture()){let N=L.getOcclusionTexture(),v=L.getOcclusionTextureInfo(),j=Q.createTextureInfoDef(N,v);if(L.getOcclusionStrength()!==1)j.strength=L.getOcclusionStrength();P.occlusionTexture=j}if(L.getMetallicRoughnessTexture()){let N=L.getMetallicRoughnessTexture(),v=L.getMetallicRoughnessTextureInfo();P.pbrMetallicRoughness.metallicRoughnessTexture=Q.createTextureInfoDef(N,v)}return Q.materialIndexMap.set(L,w),P}),F.filter((L)=>L.prewriteTypes.includes(p.MESH)).forEach((L)=>L.prewrite(Q,p.MESH)),W.meshes=Z.listMeshes().map((L,w)=>{let P=Q.createPropertyDef(L),N=null;if(P.primitives=L.listPrimitives().map((v)=>{let j={attributes:{}};j.mode=v.getMode();let O=v.getMaterial();if(O)j.material=Q.materialIndexMap.get(O);if(Object.keys(v.getExtras()).length)j.extras=v.getExtras();let D=v.getIndices();if(D)j.indices=Q.accessorIndexMap.get(D);for(let _ of v.listSemantics())j.attributes[_]=Q.accessorIndexMap.get(v.getAttribute(_));for(let _ of v.listTargets()){let C={};for(let S of _.listSemantics())C[S]=Q.accessorIndexMap.get(_.getAttribute(S));j.targets=j.targets||[],j.targets.push(C)}if(v.listTargets().length&&!N)N=v.listTargets().map((_)=>_.getName());return j}),L.getWeights().length)P.weights=L.getWeights();if(N)P.extras=P.extras||{},P.extras.targetNames=N;return Q.meshIndexMap.set(L,w),P}),W.cameras=Z.listCameras().map((L,w)=>{let P=Q.createPropertyDef(L);if(P.type=L.getType(),P.type===G9.Type.PERSPECTIVE){P.perspective={znear:L.getZNear(),zfar:L.getZFar(),yfov:L.getYFov()};let N=L.getAspectRatio();if(N!==null)P.perspective.aspectRatio=N}else P.orthographic={znear:L.getZNear(),zfar:L.getZFar(),xmag:L.getXMag(),ymag:L.getYMag()};return Q.cameraIndexMap.set(L,w),P}),W.nodes=Z.listNodes().map((L,w)=>{let P=Q.createPropertyDef(L);if(!b0.eq(L.getTranslation(),[0,0,0]))P.translation=L.getTranslation();if(!b0.eq(L.getRotation(),[0,0,0,1]))P.rotation=L.getRotation();if(!b0.eq(L.getScale(),[1,1,1]))P.scale=L.getScale();if(L.getWeights().length)P.weights=L.getWeights();return Q.nodeIndexMap.set(L,w),P}),W.skins=Z.listSkins().map((L,w)=>{let P=Q.createPropertyDef(L),N=L.getInverseBindMatrices();if(N)P.inverseBindMatrices=Q.accessorIndexMap.get(N);let v=L.getSkeleton();if(v)P.skeleton=Q.nodeIndexMap.get(v);return P.joints=L.listJoints().map((j)=>Q.nodeIndexMap.get(j)),Q.skinIndexMap.set(L,w),P}),Z.listNodes().forEach((L,w)=>{let P=W.nodes[w],N=L.getMesh();if(N)P.mesh=Q.meshIndexMap.get(N);let v=L.getCamera();if(v)P.camera=Q.cameraIndexMap.get(v);let j=L.getSkin();if(j)P.skin=Q.skinIndexMap.get(j);if(L.listChildren().length>0)P.children=L.listChildren().map((O)=>Q.nodeIndexMap.get(O))}),W.animations=Z.listAnimations().map((L,w)=>{let P=Q.createPropertyDef(L),N=new Map;return P.samplers=L.listSamplers().map((v,j)=>{let O=Q.createPropertyDef(v);return O.input=Q.accessorIndexMap.get(v.getInput()),O.output=Q.accessorIndexMap.get(v.getOutput()),O.interpolation=v.getInterpolation(),N.set(v,j),O}),P.channels=L.listChannels().map((v)=>{let j=Q.createPropertyDef(v);return j.sampler=N.get(v.getSampler()),j.target={node:Q.nodeIndexMap.get(v.getTargetNode()),path:v.getTargetPath()},j}),Q.animationIndexMap.set(L,w),P}),W.scenes=Z.listScenes().map((L,w)=>{let P=Q.createPropertyDef(L);return P.nodes=L.listChildren().map((N)=>Q.nodeIndexMap.get(N)),Q.sceneIndexMap.set(L,w),P});let R=Z.getDefaultScene();if(R)W.scene=Z.listScenes().indexOf(R);return W.extensionsUsed=F.map((L)=>L.extensionName),W.extensionsRequired=q.map((L)=>L.extensionName),F.forEach((L)=>L.write(Q)),cg(W),$}}function cg(J){let X=[];for(let Y in J){let Z=J[Y];if(Array.isArray(Z)&&Z.length===0)X.push(Y);else if(Z===null||Z==="")X.push(Y);else if(Z&&typeof Z==="object"&&Object.keys(Z).length===0)X.push(Y)}for(let Y of X)delete J[Y]}var mY;(function(J){J[J.JSON=1313821514]="JSON",J[J.BIN=5130562]="BIN"})(mY||(mY={}));class iR{constructor(){this._logger=e8.DEFAULT_INSTANCE,this._extensions=new Set,this._dependencies={},this._vertexLayout=yY.INTERLEAVED,this.lastReadBytes=0,this.lastWriteBytes=0}setLogger(J){return this._logger=J,this}registerExtensions(J){for(let X of J)this._extensions.add(X),X.register();return this}registerDependencies(J){return Object.assign(this._dependencies,J),this}setVertexLayout(J){return this._vertexLayout=J,this}async read(J){return await this.readJSON(await this.readAsJSON(J))}async readAsJSON(J){let X=await this.readURI(J,"view");this.lastReadBytes=X.byteLength;let Y=hR(X)?this._binaryToJSON(X):{json:JSON.parse(G0.decodeText(X)),resources:{}};return await this._readResourcesExternal(Y,this.dirname(J)),this._readResourcesInternal(Y),Y}async readJSON(J){return J=this._copyJSON(J),this._readResourcesInternal(J),uR.read(J,{extensions:Array.from(this._extensions),dependencies:this._dependencies,logger:this._logger})}async binaryToJSON(J){let X=this._binaryToJSON(G0.assertView(J));this._readResourcesInternal(X);let Y=X.json;if(Y.buffers&&Y.buffers.some((Z)=>mg(X,Z)))throw new Error("Cannot resolve external buffers with binaryToJSON().");else if(Y.images&&Y.images.some((Z)=>lg(X,Z)))throw new Error("Cannot resolve external images with binaryToJSON().");return X}async readBinary(J){return this.readJSON(await this.binaryToJSON(G0.assertView(J)))}async writeJSON(J,X={}){if(X.format===W1.GLB&&J.getRoot().listBuffers().length>1)throw new Error("GLB must have 0\u20131 buffers.");return dR.write(J,{format:X.format||W1.GLTF,basename:X.basename||"",logger:this._logger,vertexLayout:this._vertexLayout,dependencies:P8({},this._dependencies),extensions:Array.from(this._extensions)})}async writeBinary(J){let{json:X,resources:Y}=await this.writeJSON(J,{format:W1.GLB}),Z=new Uint32Array([1179937895,2,12]),W=JSON.stringify(X),$=G0.pad(G0.encodeText(W),32),Q=G0.toView(new Uint32Array([$.byteLength,1313821514])),K=G0.concat([Q,$]);Z[Z.length-1]+=K.byteLength;let G=Object.values(Y)[0];if(!G||!G.byteLength)return G0.concat([G0.toView(Z),K]);let F=G0.pad(G,0),q=G0.toView(new Uint32Array([F.byteLength,5130562])),H=G0.concat([q,F]);return Z[Z.length-1]+=H.byteLength,G0.concat([G0.toView(Z),K,H])}async _readResourcesExternal(J,X){var Y=this;let Z=J.json.images||[],W=J.json.buffers||[],$=[...Z,...W].map(async function(Q){let K=Q.uri;if(!K||K.match(/data:/))return Promise.resolve();J.resources[K]=await Y.readURI(Y.resolve(X,K),"view"),Y.lastReadBytes+=J.resources[K].byteLength});await Promise.all($)}_readResourcesInternal(J){function X(W){if(!W.uri)return;if(W.uri in J.resources){G0.assertView(J.resources[W.uri]);return}if(W.uri.match(/data:/)){let $=`__${cR()}.${Q1.extension(W.uri)}`;J.resources[$]=G0.createBufferFromDataURI(W.uri),W.uri=$}}(J.json.images||[]).forEach((W)=>{if(W.bufferView===void 0&&W.uri===void 0)throw new Error("Missing resource URI or buffer view.");X(W)}),(J.json.buffers||[]).forEach(X)}_copyJSON(J){let{images:X,buffers:Y}=J.json;if(J={json:P8({},J.json),resources:P8({},J.resources)},X)J.json.images=X.map((Z)=>P8({},Z));if(Y)J.json.buffers=Y.map((Z)=>P8({},Z));return J}_binaryToJSON(J){if(!hR(J))throw new Error("Invalid glTF 2.0 binary.");let X=new Uint32Array(J.buffer,J.byteOffset+12,2);if(X[1]!==mY.JSON)throw new Error("Missing required GLB JSON chunk.");let Y=20,Z=X[0],W=G0.decodeText(G0.toView(J,Y,Z)),$=JSON.parse(W),Q=Y+Z;if(J.byteLength<=Q)return{json:$,resources:{}};let K=new Uint32Array(J.buffer,J.byteOffset+Q,2);if(K[1]!==mY.BIN)return{json:$,resources:{}};let G=K[0],F=G0.toView(J,Q+8,G);return{json:$,resources:{[AY]:F}}}}function mg(J,X){return X.uri!==void 0&&!(X.uri in J.resources)}function lg(J,X){return X.uri!==void 0&&!(X.uri in J.resources)&&X.bufferView===void 0}function hR(J){if(J.byteLength<3*Uint32Array.BYTES_PER_ELEMENT)return!1;let X=new Uint32Array(J.buffer,J.byteOffset,3);return X[0]===1179937895&&X[1]===2}class FG extends iR{constructor(J=null,X=r8.DEFAULT_INIT){super();this._fetch=void 0,this._fetchConfig=void 0,this._init=void 0,this._fetchEnabled=!1,this._fetch=J,this._fetchConfig=X,this._init=this.init()}async init(){if(this._init)return this._init;return Promise.all([import("fs"),import("path")]).then(([J,X])=>{this._fs=J.promises,this._path=X})}setAllowNetwork(J){if(J&&!this._fetch)throw new Error("NodeIO requires a Fetch API implementation for HTTP requests.");return this._fetchEnabled=J,this}async readURI(J,X){if(await this.init(),r8.isAbsoluteURL(J)){if(!this._fetchEnabled||!this._fetch)throw new Error("Network request blocked. Allow HTTP requests explicitly, if needed.");let Y=await this._fetch(J,this._fetchConfig);switch(X){case"view":return new Uint8Array(await Y.arrayBuffer());case"text":return Y.text()}}else switch(X){case"view":return this._fs.readFile(J);case"text":return this._fs.readFile(J,"utf8")}}resolve(J,X){if(r8.isAbsoluteURL(J)||r8.isAbsoluteURL(X))return r8.resolve(J,X);return this._path.resolve(J,decodeURIComponent(X))}dirname(J){if(r8.isAbsoluteURL(J))return r8.dirname(J);return this._path.dirname(J)}async write(J,X){await this.init(),await(!!J.match(/\.glb$/)?this._writeGLB(J,X):this._writeGLTF(J,X))}async _writeGLTF(J,X){var Y=this;this.lastWriteBytes=0;let{json:Z,resources:W}=await this.writeJSON(X,{format:W1.GLTF,basename:Q1.basename(J)}),{_fs:$,_path:Q}=this,K=Q.dirname(J),G=JSON.stringify(Z,null,2);await $.writeFile(J,G),this.lastWriteBytes+=G.length;for(let F of ug(Object.keys(W),10))await Promise.all(F.map(async function(q){if(r8.isAbsoluteURL(q)){if(r8.extension(q)==="bin")throw new Error(`Cannot write buffer to path "${q}".`);return}let H=Q.join(K,decodeURIComponent(q));await $.mkdir(Q.dirname(H),{recursive:!0}),await $.writeFile(H,W[q]),Y.lastWriteBytes+=W[q].byteLength}))}async _writeGLB(J,X){let Y=await this.writeBinary(X);await this._fs.writeFile(J,Y),this.lastWriteBytes=Y.byteLength}}function ug(J,X){let Y=[];for(let Z=0,W=J.length;Z<W;Z+=X){let $=[];for(let Q=0;Q<X&&Z+Q<W;Q++)$.push(J[Z+Q]);Y.push($)}return Y}var Xc=a6(eR(),1);function qG(){return qG=Object.assign?Object.assign.bind():function(J){for(var X=1;X<arguments.length;X++){var Y=arguments[X];for(var Z in Y)({}).hasOwnProperty.call(Y,Z)&&(J[Z]=Y[Z])}return J},qG.apply(null,arguments)}var{POINTS:Jw,LINES:rY,LINE_STRIP:Yc,LINE_LOOP:Zc,TRIANGLES:tY,TRIANGLE_STRIP:Wc,TRIANGLE_FAN:$c}=K1.Mode;var ZM0=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});var WM0={[Jw]:Jw,[rY]:rY,[Yc]:rY,[Zc]:rY,[tY]:tY,[Wc]:tY,[$c]:tY};var JZ=typeof Float32Array!=="undefined"?Float32Array:Array;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};function Qc(){var J=new JZ(3);if(JZ!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}(function(){var J=Qc();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}})();var $M0={keepUniqueNames:!1,propertyTypes:[p.ACCESSOR,p.MESH,p.TEXTURE,p.MATERIAL,p.SKIN]};function Kc(){var J=new JZ(4);if(JZ!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}(function(){var J=Kc();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=4;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],J[3]=X[K+3],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2],X[K+3]=J[3];return X}})();var QM0={propertyTypes:[p.NODE,p.SKIN,p.MESH,p.CAMERA,p.PRIMITIVE,p.PRIMITIVE_TARGET,p.ANIMATION,p.MATERIAL,p.TEXTURE,p.ACCESSOR,p.BUFFER],keepLeaves:!1,keepAttributes:!1,keepIndices:!1,keepSolidTextures:!1,keepExtras:!1};var Xw;(function(J){J.RENDER="render",J.RENDER_CACHED="render-cached",J.UPLOAD="upload",J.UPLOAD_NAIVE="upload-naive",J.DISTINCT="distinct",J.DISTINCT_POSITION="distinct-position",J.UNUSED="unused"})(Xw||(Xw={}));var{FLOAT:KM0}=i.ComponentType;var{LINES:GM0,LINE_STRIP:FM0,LINE_LOOP:qM0,TRIANGLES:HM0,TRIANGLE_STRIP:zM0,TRIANGLE_FAN:LM0}=K1.Mode;function $w(J){return bR(J)}var{LINE_STRIP:UM0,LINE_LOOP:VM0,TRIANGLE_STRIP:MM0,TRIANGLE_FAN:RM0}=K1.Mode;var{TRANSLATION:wM0,ROTATION:OM0,SCALE:xM0,WEIGHTS:PM0}=l4.TargetPath;var Gc={pattern:/.*/,quantizationVolume:"mesh",quantizePosition:14,quantizeNormal:10,quantizeTexcoord:12,quantizeColor:8,quantizeWeight:8,quantizeGeneric:12,normalizeWeights:!0,cleanup:!0};var NM0=qG({level:"high"},Gc);var Yw;(function(J){J[J.STEP=0]="STEP",J[J.LERP=1]="LERP",J[J.SLERP=2]="SLERP"})(Yw||(Yw={}));var Fc=0.000001;function qc(J,X,Y,Z=0.0001){let W=X.length/J.length,$=new Array(W).fill(0),Q=new Array(W).fill(0),K=new Array(W).fill(0),G=new Array(W).fill(0),F=J.length-1,q=1;for(let H=1;H<F;++H){let z=J[q-1],V=J[H],M=J[H+1],R=(V-z)/(M-z),L=!1;if(V!==M&&(H!==1||V!==J[0])){if(u4(X,q-1,G),u4(X,H,Q),u4(X,H+1,K),Y==="slerp"){let w=Lc($,G,K,R),P=Ww(G,Q)+Ww(Q,K);L=!eY(Q,w,Z)||P+Number.EPSILON>=Math.PI}else if(Y==="lerp"){let w=zc($,G,K,R);L=!eY(Q,w,Z)}else if(Y==="step")L=!eY(Q,G)||!eY(Q,K)}if(L){if(H!==q)J[q]=J[H],Zw(X,q,u4(X,H,$));q++}}if(F>0)J[q]=J[F],Zw(X,q,u4(X,F,$)),q++;return q}function u4(J,X,Y){for(let Z=0,W=Y.length;Z<W;Z++)Y[Z]=J[X*W+Z];return Y}function Zw(J,X,Y){for(let Z=0,W=Y.length;Z<W;Z++)J[X*W+Z]=Y[Z]}function eY(J,X,Y=0){if(J.length!==X.length)return!1;for(let Z=0;Z<J.length;Z++)if(Math.abs(J[Z]-X[Z])>Y)return!1;return!0}function Hc(J,X,Y){return J*(1-Y)+X*Y}function zc(J,X,Y,Z){for(let W=0;W<X.length;W++)J[W]=Hc(X[W],Y[W],Z);return J}function Lc(J,X,Y,Z){let W=X[0],$=X[1],Q=X[2],K=X[3],G=Y[0],F=Y[1],q=Y[2],H=Y[3],z,V,M,R,L;if(V=W*G+$*F+Q*q+K*H,V<0)V=-V,G=-G,F=-F,q=-q,H=-H;if(1-V>Fc)z=Math.acos(V),M=Math.sin(z),R=Math.sin((1-Z)*z)/M,L=Math.sin(Z*z)/M;else R=1-Z,L=Z;return J[0]=R*W+L*G,J[1]=R*$+L*F,J[2]=R*Q+L*q,J[3]=R*K+L*H,J}function Ww(J,X){let Y=Uc(J,X);return Math.acos(2*Y*Y-1)}function Uc(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]+J[3]*X[3]}var vM0=new Float32Array(0),BM0={ready:Promise.resolve(),resample:qc,tolerance:0.0001,cleanup:!0};var{POINTS:jM0,LINES:kM0,LINE_STRIP:TM0,LINE_LOOP:DM0,TRIANGLES:_M0,TRIANGLE_STRIP:EM0,TRIANGLE_FAN:CM0}=K1.Mode;var HG;(function(J){J.LANCZOS3="lanczos3",J.LANCZOS2="lanczos2"})(HG||(HG={}));var SM0={resizeFilter:HG.LANCZOS3,pattern:void 0,formats:void 0,slots:void 0,quality:void 0,effort:void 0,lossless:!1,nearLossless:!1,limitInputPixels:!0};var Q5={OPTIMIZED_DIR:".optimized",CHECKSUM_EXT:".md5",DIRECTORIES:[G1.normalize("node_modules/@hytopia.com/assets"),G1.normalize("assets")],OPTIMIZER_RUNS:[{suffix:"",options:["--compress","false","--instance","false","--simplify","false"]},{suffix:"-named-nodes",options:["--compress","false","--instance","false","--simplify","false","--join","true","--join-named","false"]}]};class U6{static instance=new U6;optimize=!0;optimizeEveryStart=!1;_modelUriDocuments=new Map;_modelUriBoundingBoxes=new Map;_modelUriNodeNames=new Map;constructor(){}async preloadModels(){let J=await this._getAbsoluteModelPaths();console.log(`ModelRegistry.preloadModels(): Preloading ${J.length} models...`);for(let X of J){if(this.optimize)await this._resolveOptimizedModelPath(X);await this._loadModelData(X)}console.log(`ModelRegistry.preloadModels(): Preloaded ${J.length} models!`)}getBoundingBox(J){let X=this._modelUriBoundingBoxes.get(J);if(!X)E.fatalError(`ModelRegistry.getBoundingBox(): Model ${J} not found!`);return X}getHeight(J){let X=this.getBoundingBox(J);return X.max.y-X.min.y}getNodeNames(J){let X=this._modelUriNodeNames.get(J);if(!X)E.fatalError(`ModelRegistry.getNodeNames(): Model ${J} not found!`);return X}modelHasNode(J,X){let Y=this._modelUriNodeNames.get(J);if(!Y)E.fatalError(`ModelRegistry.modelHasNode(): Model ${J} not found!`);return Y.includes(X)}_absoluteModelPathToModelUri(J){let X=G1.relative(process.cwd(),J),Y=Q5.DIRECTORIES.find((W)=>X.startsWith(W));return(Y?G1.relative(Y,X):X).split(G1.sep).join("/")}async _getAbsoluteModelPaths(){let J=[],X=new Mc("**/*.{gltf,glb}");for(let Y of Q5.DIRECTORIES){let Z=G1.resolve(process.cwd(),Y);if(!C1.existsSync(Z))continue;for await(let W of X.scan(Z))J.push(G1.join(Z,W))}return J}async _loadModelData(J){let X=await new FG().read(J),Y=$w(X.getRoot().listScenes()[0]),Z=X.getRoot().listNodes().map(($)=>$.getName()),W=this._absoluteModelPathToModelUri(J);this._modelUriDocuments.set(W,X),this._modelUriBoundingBoxes.set(W,{min:{x:Y.min[0],y:Y.min[1],z:Y.min[2]},max:{x:Y.max[0],y:Y.max[1],z:Y.max[2]}}),this._modelUriNodeNames.set(W,Z)}async _resolveOptimizedModelPath(J){let X=this._buildOptimizedModelPath(J);if(!this.optimizeEveryStart&&this._isOptimizedVersionValid(J))return X;return await this._optimizeModel(J,X)}_isOptimizedVersionValid(J){let X=`${this._buildOptimizedModelPath(J)}${Q5.CHECKSUM_EXT}`;if(!C1.existsSync(X))return!1;let Y=this._calculateChecksum(J),Z=C1.readFileSync(X,"utf8");return Y===Z}_calculateChecksum(J){if(!C1.existsSync(J))return"";let X=C1.readFileSync(J);return Vc.createHash("sha256").update(X.toString("base64")).digest("hex")}_buildOptimizedModelPath(J){let X=G1.basename(J),Y=X.replace(/\.[^/.]+$/,""),Z=`${Q5.OPTIMIZED_DIR}/${Y}`;return J.replace(/[^/\\]+$/,`${Z}/${X}`)}async _optimizeModel(J,X){let Y=G1.dirname(X);C1.rmSync(Y,{recursive:!0,force:!0}),C1.mkdirSync(Y,{recursive:!0}),console.log(`ModelRegistry: Optimizing model ${this._absoluteModelPathToModelUri(J)}...`);for(let Z of Q5.OPTIMIZER_RUNS){let W=X.replace(/(\.[^/.]+)$/,`${Z.suffix}$1`),{stderr:$}=await DR("bunx",["gltf-transform","optimize",J,W,...Z.options]);if($)return E.warning(`ModelRegistry._optimizeModel(): Error optimizing model ${this._absoluteModelPathToModelUri(J)}, defaulting to unoptimized model. Error: ${$}`),J}return C1.writeFileSync(`${X}${Q5.CHECKSUM_EXT}`,this._calculateChecksum(J)),X}}var zG;((W)=>{W[W.Average=0]="Average";W[W.Min=1]="Min";W[W.Multiply=2]="Multiply";W[W.Max=3]="Max"})(zG||={});var XZ;((G)=>{G.NONE="none";G.BALL="ball";G.BLOCK="block";G.CAPSULE="capsule";G.CONE="cone";G.CYLINDER="cylinder";G.ROUND_CYLINDER="round-cylinder";G.TRIMESH="trimesh"})(XZ||={});class d8 extends s{_collider;_colliderDesc;_onCollision;_parentRigidBody;_shape;_simulation;_tag;constructor(J){super();this._colliderDesc=this._createColliderDesc(J),this._shape=J.shape,this._applyColliderOptions(J),this._autoAddToSimulation(J)}static optionsFromBlockHalfExtents(J){return{shape:"block",halfExtents:J}}static optionsFromModelUri(J,X=1){let Y=U6.instance.getBoundingBox(J),Z=Y.max.x-Y.min.x,W=Y.max.y-Y.min.y,$=Y.max.z-Y.min.z,Q=Math.max(Z,$),K=Math.min(Z,$);if(Q/K>2)return{shape:"block",halfExtents:{x:Math.max(0.01,Z*X/2),y:Math.max(0.01,W*X/2),z:Math.max(0.01,$*X/2)}};let F=Q*X/2;if(Q/W>1.5)return{shape:"round-cylinder",radius:Math.max(0.01,F),halfHeight:Math.max(0.01,W*X/2),borderRadius:Math.max(0.01,F*0.1)};return{shape:"capsule",radius:Math.max(0.01,F),halfHeight:Math.max(0.01,W*X/2-F)}}get bounciness(){if(!this._requireNotRemoved("bounciness"))return 0;return this._collider?this._collider.restitution():this._colliderDesc.restitution}get bouncinessCombineRule(){if(!this._requireNotRemoved("bouncinessCombineRule"))return 0;return this._collider?this._collider.restitutionCombineRule():this._colliderDesc.restitutionCombineRule}get collisionGroups(){if(!this._requireNotRemoved("collisionGroups"))return{belongsTo:[],collidesWith:[]};return this._collider?q6.decodeRawCollisionGroups(this._collider.collisionGroups()):q6.decodeRawCollisionGroups(this._colliderDesc.collisionGroups)}get friction(){if(!this._requireNotRemoved("friction"))return 0;return this._collider?this._collider.friction():this._colliderDesc.friction}get frictionCombineRule(){if(!this._requireNotRemoved("frictionCombineRule"))return 0;return this._collider?this._collider.frictionCombineRule():this._colliderDesc.frictionCombineRule}get isEnabled(){if(!this._requireNotRemoved("isEnabled"))return!1;return this._collider?this._collider.isEnabled():this._colliderDesc.enabled}get isRemoved(){return!this._collider&&!this._colliderDesc}get isSensor(){if(!this._requireNotRemoved("isSensor"))return!1;return this._collider?this._collider.isSensor():this._colliderDesc.isSensor}get isSimulated(){if(!this._requireNotRemoved("isSimulated"))return!1;return!!this._collider}get parentRigidBody(){if(!this._requireNotRemoved("parentRigidBody"))return;return this._parentRigidBody}get rawCollider(){if(!this._requireNotRemoved("rawCollider"))return;return this._collider}get relativePosition(){if(!this._requireNotRemoved("relativePosition"))return{x:0,y:0,z:0};return this._collider?this._collider.translation():this._colliderDesc.translation}get relativeRotation(){if(!this._requireNotRemoved("relativeRotation"))return{x:0,y:0,z:0,w:1};return this._collider?this._collider.rotation():this._colliderDesc.rotation}get shape(){if(!this._requireNotRemoved("shape"))return"none";return this._shape}get tag(){if(!this._requireNotRemoved("tag"))return;return this._tag}setBounciness(J){if(!this._requireNotRemoved("setBounciness"))return;this._collider?this._collider.setRestitution(J):this._colliderDesc.setRestitution(J)}setBouncinessCombineRule(J){if(!this._requireNotRemoved("setBouncinessCombineRule"))return;this._collider?this._collider.setRestitutionCombineRule(J):this._colliderDesc.setRestitutionCombineRule(J)}setCollisionGroups(J){if(!this._requireNotRemoved("setCollisionGroups"))return;let X=q6.buildRawCollisionGroups(J);this._collider?this._collider.setCollisionGroups(X):this._colliderDesc.setCollisionGroups(X)}setEnabled(J){if(!this._requireNotRemoved("setEnabled"))return;this._collider?this._collider.setEnabled(J):this._colliderDesc.setEnabled(J)}setFriction(J){if(!this._requireNotRemoved("setFriction"))return;this._collider?this._collider.setFriction(J):this._colliderDesc.setFriction(J)}setFrictionCombineRule(J){if(!this._requireNotRemoved("setFrictionCombineRule"))return;this._collider?this._collider.setFrictionCombineRule(J):this._colliderDesc.setFrictionCombineRule(J)}setMass(J){if(!this._requireNotRemoved("setMass"))return;this._collider?this._collider.setMass(J):this._colliderDesc.setMass(J)}setOnCollision(J){if(!this._requireNotRemoved("setOnCollision"))return;if(this._onCollision=J,this.isSimulated)if(this.enableCollisionEvents(!!J),J)this._simulation.colliderMap.setColliderCollisionCallback(this,J);else this._simulation.colliderMap.removeColliderCollisionCallback(this)}setRelativeRotation(J){if(!this._requireNotRemoved("setRelativeRotation"))return;this._collider?this._collider.setRotation(J):this._colliderDesc.setRotation(J)}setRelativePosition(J){if(!this._requireNotRemoved("setRelativePosition"))return;this._collider?this._collider.setTranslation(J):this._colliderDesc.setTranslation(J.x,J.y,J.z)}setSensor(J){if(!this._requireNotRemoved("setSensor"))return;this._collider?this._collider.setSensor(J):this._colliderDesc.setSensor(J)}setTag(J){if(!this._requireNotRemoved("setTag"))return;this._tag=J}addToSimulation(J,X){if(!this._requireNotRemoved("addToSimulation"))return;if(!this._requireUnsimulated("addToSimulation"))return;if(X&&!X.isSimulated)return E.error("Collider.addToSimulation(): Rigid body must be simulated before adding a collider to it!");if(this._simulation=J,this._parentRigidBody=X,this._collider=this._simulation.createRawCollider(this._colliderDesc,X?.rawRigidBody),this._colliderDesc=void 0,X)X.linkCollider(this);if(this._onCollision)this.setOnCollision(this._onCollision)}enableCollisionEvents(J){if(!this._requireNotRemoved("enableCollisionEvents"))return;let X=this._collider?this._collider.activeEvents():this._colliderDesc.activeEvents,Y=J?X|z0.ActiveEvents.COLLISION_EVENTS:X&~z0.ActiveEvents.COLLISION_EVENTS;(this._collider??this._colliderDesc).setActiveEvents(Y),this._setActiveCollisionTypes()}enableContactForceEvents(J){if(!this._requireNotRemoved("enableContactForceEvents"))return;let X=this._collider?this._collider.activeEvents():this._colliderDesc.activeEvents,Y=J?X|z0.ActiveEvents.CONTACT_FORCE_EVENTS:X&~z0.ActiveEvents.CONTACT_FORCE_EVENTS;(this._collider??this._colliderDesc).setActiveEvents(Y),this._setActiveCollisionTypes()}removeFromSimulation(){if(!this._requireNotRemoved("removeFromSimulation"))return;if(!this._requireSimulated("removeFromSimulation"))return;if(this._simulation.removeRawCollider(this._collider),this._simulation=void 0,this._collider=void 0,this._parentRigidBody)this._parentRigidBody.unlinkCollider(this);this._parentRigidBody=void 0}_applyColliderOptions(J){[["bounciness",this.setBounciness.bind(this)],["bouncinessCombineRule",this.setBouncinessCombineRule.bind(this)],["collisionGroups",this.setCollisionGroups.bind(this)],["enabled",this.setEnabled.bind(this)],["friction",this.setFriction.bind(this)],["frictionCombineRule",this.setFrictionCombineRule.bind(this)],["isSensor",this.setSensor.bind(this)],["mass",this.setMass.bind(this)],["onCollision",this.setOnCollision.bind(this)],["relativePosition",this.setRelativePosition.bind(this)],["relativeRotation",this.setRelativeRotation.bind(this)],["tag",this.setTag.bind(this)]].forEach(([Y,Z])=>{if(J[Y]!==void 0)Z.call(this,J[Y])})}_autoAddToSimulation(J){if(J.simulation)this.addToSimulation(J.simulation,J.parentRigidBody)}_createColliderDesc(J){let{shape:X,flags:Y}=J;switch(X){case"ball":{if(!J.radius)E.fatalError("Ball collider must have a radius!");return z0.ColliderDesc.ball(J.radius)}case"block":{if(!J.halfExtents)E.fatalError("Block collider must have halfExtents!");return z0.ColliderDesc.cuboid(J.halfExtents.x,J.halfExtents.y,J.halfExtents.z)}case"capsule":{if(!J.halfHeight||!J.radius)E.fatalError("Capsule collider must have halfHeight and radius!");return z0.ColliderDesc.capsule(J.halfHeight,J.radius)}case"cone":{if(!J.radius||!J.halfHeight)E.fatalError("Cone collider must have radius and halfHeight!");return z0.ColliderDesc.cone(J.halfHeight,J.radius)}case"cylinder":{if(!J.radius||!J.halfHeight)E.fatalError("Cylinder collider must have radius and halfHeight!");return z0.ColliderDesc.cylinder(J.halfHeight,J.radius)}case"round-cylinder":{if(!J.radius||!J.halfHeight||!J.borderRadius)E.fatalError("Round cylinder collider must have radius, halfHeight, and borderRadius!");return z0.ColliderDesc.roundCylinder(J.halfHeight,J.radius,J.borderRadius)}case"trimesh":{if(!J.indices||!J.vertices)E.fatalError("Trimesh collider must have vertices and indices!");return z0.ColliderDesc.trimesh(J.vertices,J.indices,Y)}default:E.fatalError(`Collider._createColliderDesc(): ${X} is not a valid collider shape!`)}}_requireSimulated(J){if(!this.isSimulated)E.error(`Collider._requireSimulated(): Collider is not simulated, invoked method: ${J}()`);return this.isSimulated}_requireUnsimulated(J){if(this.isSimulated)E.error(`Collider._requireUnsimulated(): Collider is already simulated, invoked method: ${J}()`);return!this.isSimulated}_requireNotRemoved(J){if(this.isRemoved)E.error(`Collider._requireNotRemoved(): Collider is removed, invoked method: ${J}()`);return!this.isRemoved}_setActiveCollisionTypes(){(this._collider??this._colliderDesc).setActiveCollisionTypes(z0.ActiveCollisionTypes.DYNAMIC_DYNAMIC|z0.ActiveCollisionTypes.DYNAMIC_KINEMATIC|z0.ActiveCollisionTypes.DYNAMIC_FIXED|z0.ActiveCollisionTypes.KINEMATIC_KINEMATIC|z0.ActiveCollisionTypes.KINEMATIC_FIXED)}}var Rc={shape:"trimesh",flags:R4.FIX_INTERNAL_EDGES},wc=new Uint32Array([0,1,2,2,3,0,4,5,6,6,7,4,8,9,10,10,11,8,12,13,14,14,15,12,16,17,18,18,19,16,20,21,22,22,23,20]),Oc=new Float32Array([-0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.5,-0.5,-0.5,-0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5]),LG;((Y)=>{Y.ENTITY_COLLISION="BLOCK_TYPE.ENTITY_COLLISION";Y.ENTITY_CONTACT_FORCE="BLOCK_TYPE.ENTITY_CONTACT_FORCE"})(LG||={});class V6 extends s{_id;_customColliderOptions;_isLiquid;_name;_textureUri;constructor(J={id:-1,textureUri:"textures/missing.png",name:"Unknown"}){if(J.id<0)E.fatalError("BlockType.constructor(): BlockType id not set.");super();this._id=J.id,this._customColliderOptions=J.customColliderOptions,this._isLiquid=J.isLiquid??!1,this._name=J.name,this._textureUri=J.textureUri}get id(){return this._id}get colliderOptions(){return{...this._customColliderOptions,...Rc}}get isLiquid(){return this._isLiquid}get isMeshable(){return!this._customColliderOptions}get name(){return this._name}get textureUri(){return this._textureUri}createCollider(J=wc,X=Oc){let Y=new d8({...this.colliderOptions,indices:J,vertices:X});if(this.isLiquid)Y.setSensor(!0);if(this.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))Y.enableCollisionEvents(!0);if(this.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))Y.enableContactForceEvents(!0);if(q6.isDefaultCollisionGroups(Y.collisionGroups))Y.setCollisionGroups({belongsTo:[1],collidesWith:[65535&~1]});return Y}serialize(){return t.serializeBlockType(this)}}var UG;((X)=>X.REGISTER_BLOCK_TYPE="BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE")(UG||={});class d4 extends s{_blockTypes=new Map;_world;constructor(J){super();this._world=J}get world(){return this._world}getAllBlockTypes(){return Array.from(this._blockTypes.values())}getBlockType(J){let X=this._blockTypes.get(J);if(!X)E.fatalError(`BlockTypeRegistry.getBlockType(): BlockType with id ${J} not found.`);return X}registerGenericBlockType(J){let Y=new class extends V6{constructor(Z=J){super(Z)}};return this.registerBlockType(Y),Y}registerBlockType(J){this._blockTypes.set(J.id,J),this.emitWithWorld(this._world,"BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",{blockTypeRegistry:this,id:J.id,blockType:J})}serialize(){return t.serializeBlockTypeRegistry(this)}}var lF={};k6(lF,{worldSchema:()=>mF,worldPacketDefinition:()=>rP,vectorSchema:()=>T0,vectorBooleanSchema:()=>ws,uiSchema:()=>gF,uiPacketDefinition:()=>sP,uiDatasSchema:()=>cF,uiDatasPacketDefinition:()=>oP,uiDataSendPacketDefinition:()=>fP,uiDataSchema:()=>V7,syncResponseSchema:()=>yF,syncResponsePacketDefinition:()=>aP,syncRequestSchema:()=>VF,syncRequestPacketDefinition:()=>hP,stateRequestSchema:()=>UF,stateRequestPacketDefinition:()=>IP,sceneUIsSchema:()=>AF,sceneUIsPacketDefinition:()=>nP,sceneUISchema:()=>pF,rgbColorSchema:()=>b6,registeredPackets:()=>cZ,quaternionSchema:()=>TF,playersSchema:()=>bF,playersPacketDefinition:()=>iP,playerSchema:()=>fF,physicsDebugRenderSchema:()=>hF,physicsDebugRenderPacketDefinition:()=>uP,physicsDebugRaycastsSchema:()=>IF,physicsDebugRaycastsPacketDefinition:()=>dP,physicsDebugRaycastSchema:()=>SF,outboundPackets:()=>gZ,modelNodeOverrideSchema:()=>kF,lightsSchema:()=>CF,lightsPacketDefinition:()=>lP,lightSchema:()=>EF,isValidPacket:()=>xs,inputSchema:()=>LF,inputPacketDefinition:()=>SP,inboundPackets:()=>yZ,hexColorSchema:()=>HF,heartbeatSchema:()=>qF,heartbeatPacketDefinition:()=>_P,entitySchema:()=>DF,entitiesSchema:()=>_F,entitiesPacketDefinition:()=>mP,definePacket:()=>d,debugConfigSchema:()=>zF,debugConfigPacketDefinition:()=>CP,createPacket:()=>Gs,connectionSchema:()=>FF,connectionPacketDefinition:()=>DP,chunksSchema:()=>jF,chunksPacketDefinition:()=>cP,chunkSchema:()=>BF,chatMessagesSchema:()=>vF,chatMessagesPacketDefinition:()=>gP,chatMessageSendPacketDefinition:()=>EP,chatMessageSchema:()=>U7,cameraSchema:()=>NF,cameraPacketDefinition:()=>yP,blocksSchema:()=>OF,blocksPacketDefinition:()=>pP,blockTypesSchema:()=>PF,blockTypesPacketDefinition:()=>AP,blockTypeSchema:()=>xF,blockSchema:()=>wF,bidirectionalPackets:()=>AZ,audiosSchema:()=>RF,audiosPacketDefinition:()=>bP,audioSchema:()=>MF,PacketId:()=>E0});var AZ={};k6(AZ,{heartbeatPacketDefinition:()=>_P,connectionPacketDefinition:()=>DP});var KF=a6(kP(),1);class GF extends KF.default{static instance=new KF.default}var E0;((_)=>{_[_.SYNC_REQUEST=0]="SYNC_REQUEST";_[_.INPUT=1]="INPUT";_[_.STATE_REQUEST=2]="STATE_REQUEST";_[_.CHAT_MESSAGE_SEND=3]="CHAT_MESSAGE_SEND";_[_.UI_DATA_SEND=4]="UI_DATA_SEND";_[_.SYNC_RESPONSE=32]="SYNC_RESPONSE";_[_.AUDIOS=33]="AUDIOS";_[_.BLOCKS=34]="BLOCKS";_[_.BLOCK_TYPES=35]="BLOCK_TYPES";_[_.CHAT_MESSAGES=36]="CHAT_MESSAGES";_[_.CHUNKS=37]="CHUNKS";_[_.ENTITIES=38]="ENTITIES";_[_.WORLD=39]="WORLD";_[_.CAMERA=40]="CAMERA";_[_.UI=41]="UI";_[_.UI_DATAS=42]="UI_DATAS";_[_.SCENE_UIS=43]="SCENE_UIS";_[_.LIGHTS=44]="LIGHTS";_[_.PLAYERS=45]="PLAYERS";_[_.CONNECTION=116]="CONNECTION";_[_.HEARTBEAT=117]="HEARTBEAT";_[_.DEBUG_CONFIG=128]="DEBUG_CONFIG";_[_.PHYSICS_DEBUG_RENDER=192]="PHYSICS_DEBUG_RENDER";_[_.PHYSICS_DEBUG_RAYCASTS=193]="PHYSICS_DEBUG_RAYCASTS"})(E0||={});function Gs(J,X,Y){if(!J.validate(X))throw new Error(`Invalid payload for packet with id ${J.id}. Error: ${GF.instance.errorsText(J.validate.errors)}`);let Z=[J.id,X];if(typeof Y==="number")Z.push(Y);return Z}function d(J,X){return{id:J,schema:X,validate:GF.instance.compile(X)}}var Fs={type:"object",properties:{i:{type:"string"}},required:["i"],additionalProperties:!1},TP={type:"object",properties:{role:{type:"string",enum:["auto","client","server"],nullable:!0},fingerprints:{type:"array",items:{type:"object",properties:{algorithm:{type:"string",enum:["sha-1","sha-224","sha-256","sha-384","sha-512"]},value:{type:"string"}},required:["algorithm","value"]}}},required:["fingerprints"],additionalProperties:!1},qs={type:"object",properties:{foundation:{type:"string"},priority:{type:"number"},ip:{type:"string"},address:{type:"string"},protocol:{type:"string",enum:["udp","tcp"]},port:{type:"number"},type:{type:"string",enum:["host"]},tcpType:{type:"string",enum:["passive"],nullable:!0}},required:["foundation","priority","ip","address","protocol","port","type"],additionalProperties:!1},Hs={type:"object",properties:{usernameFragment:{type:"string"},password:{type:"string"},iceLite:{type:"boolean",nullable:!0}},required:["usernameFragment","password"],additionalProperties:!1},zs={type:"object",properties:{i:{type:"string"},l:{type:"string"}},required:["i","l"],additionalProperties:!1},Ls={type:"object",properties:{port:{type:"number"},OS:{type:"number"},MIS:{type:"number"},maxMessageSize:{type:"number"}},required:["port","OS","MIS","maxMessageSize"],additionalProperties:!0},Us={type:"object",properties:{streamId:{type:"number"},ordered:{type:"boolean",nullable:!0},maxPacketLifeTime:{type:"number",nullable:!0},maxRetransmits:{type:"number",nullable:!0}},required:["streamId"],additionalProperties:!1},Vs={type:"object",properties:{i:{type:"string"},f:{type:"string",enum:["cs","sc"]},ip:Hs,ic:{type:"array",items:qs},d:TP,s:Ls},required:["i","f","ip","ic","d","s"],additionalProperties:!1},Ms={type:"object",properties:{i:{type:"string"},d:TP},required:["i","d"],additionalProperties:!1},Rs={type:"object",properties:{i:{type:"string",nullable:!0},pi:{type:"string",nullable:!0},l:{type:"string"},s:Us},required:["l","s"],additionalProperties:!1},FF={type:"object",properties:{c:{...Ms,nullable:!0},ca:{...Fs,nullable:!0},d:{type:"array",items:{...Rs},nullable:!0},pa:{...zs,nullable:!0},t:{type:"array",items:{...Vs},nullable:!0}},additionalProperties:!1};var DP=d(116,FF);var qF={type:"null",nullable:!0};var _P=d(117,qF);var yZ={};k6(yZ,{uiDataSendPacketDefinition:()=>fP,syncRequestPacketDefinition:()=>hP,stateRequestPacketDefinition:()=>IP,inputPacketDefinition:()=>SP,debugConfigPacketDefinition:()=>CP,chatMessageSendPacketDefinition:()=>EP});var HF={type:"string",pattern:"^[0-9A-Fa-f]{6}$"};var U7={type:"object",properties:{m:{type:"string"},c:{...HF,nullable:!0},p:{type:"string",nullable:!0}},required:["m"],additionalProperties:!1};var EP=d(3,U7);var zF={type:"object",properties:{pdr:{type:"boolean",nullable:!0}},additionalProperties:!1};var CP=d(128,zF);var LF={type:"object",properties:{"1":{type:"boolean",nullable:!0},"2":{type:"boolean",nullable:!0},"3":{type:"boolean",nullable:!0},"4":{type:"boolean",nullable:!0},"5":{type:"boolean",nullable:!0},"6":{type:"boolean",nullable:!0},"7":{type:"boolean",nullable:!0},"8":{type:"boolean",nullable:!0},"9":{type:"boolean",nullable:!0},"0":{type:"boolean",nullable:!0},w:{type:"boolean",nullable:!0},a:{type:"boolean",nullable:!0},s:{type:"boolean",nullable:!0},d:{type:"boolean",nullable:!0},q:{type:"boolean",nullable:!0},e:{type:"boolean",nullable:!0},r:{type:"boolean",nullable:!0},f:{type:"boolean",nullable:!0},z:{type:"boolean",nullable:!0},x:{type:"boolean",nullable:!0},c:{type:"boolean",nullable:!0},v:{type:"boolean",nullable:!0},sp:{type:"boolean",nullable:!0},sh:{type:"boolean",nullable:!0},tb:{type:"boolean",nullable:!0},ml:{type:"boolean",nullable:!0},mr:{type:"boolean",nullable:!0},cp:{type:"number",nullable:!0},cy:{type:"number",nullable:!0},sq:{type:"number",nullable:!0}},additionalProperties:!1};var SP=d(1,LF);var UF={type:"object",properties:{},additionalProperties:!1};var IP=d(2,UF);var VF={type:"null",nullable:!0};var hP=d(0,VF);var V7={type:"object",properties:{},additionalProperties:!0};var fP=d(4,V7);var gZ={};k6(gZ,{worldPacketDefinition:()=>rP,uiPacketDefinition:()=>sP,uiDatasPacketDefinition:()=>oP,syncResponsePacketDefinition:()=>aP,sceneUIsPacketDefinition:()=>nP,playersPacketDefinition:()=>iP,physicsDebugRenderPacketDefinition:()=>uP,physicsDebugRaycastsPacketDefinition:()=>dP,lightsPacketDefinition:()=>lP,entitiesPacketDefinition:()=>mP,chunksPacketDefinition:()=>cP,chatMessagesPacketDefinition:()=>gP,cameraPacketDefinition:()=>yP,blocksPacketDefinition:()=>pP,blockTypesPacketDefinition:()=>AP,audiosPacketDefinition:()=>bP});var T0={type:"array",items:[{type:"number"},{type:"number"},{type:"number"}],minItems:3,maxItems:3};var MF={type:"object",properties:{i:{type:"number"},a:{type:"string",nullable:!0},cd:{type:"number",nullable:!0},d:{type:"number",nullable:!0},de:{type:"number",nullable:!0},di:{type:"number",minimum:0,nullable:!0},e:{type:"number",nullable:!0},l:{type:"boolean",nullable:!0},o:{type:"number",nullable:!0},p:{...T0,nullable:!0},pa:{type:"boolean",nullable:!0},pl:{type:"boolean",nullable:!0},pr:{type:"number",minimum:0,nullable:!0},r:{type:"boolean",nullable:!0},rd:{type:"number",nullable:!0},s:{type:"number",nullable:!0},v:{type:"number",minimum:0,maximum:1,nullable:!0}},required:["i"],additionalProperties:!1};var RF={type:"array",items:{...MF}};var bP=d(33,RF);var wF={type:"object",properties:{i:{type:"number"},c:T0},required:["i","c"],additionalProperties:!1};var OF={type:"array",items:{...wF}};var pP=d(34,OF);var xF={type:"object",properties:{i:{type:"number"},l:{type:"boolean",nullable:!0},n:{type:"string",nullable:!0},t:{type:"string",nullable:!0}},required:["i"],additionalProperties:!1};var PF={type:"array",items:{...xF}};var AP=d(35,PF);var NF={type:"object",properties:{m:{type:"number",nullable:!0},e:{type:"number",nullable:!0},et:{type:"number",nullable:!0},fo:{type:"number",nullable:!0},ffo:{type:"number",nullable:!0},fv:{type:"number",nullable:!0},p:{...T0,nullable:!0},pt:{...T0,nullable:!0},pl:{...T0,nullable:!0},h:{type:"array",items:{type:"string"},nullable:!0},o:{...T0,nullable:!0},z:{type:"number",nullable:!0}},additionalProperties:!1};var vF={type:"array",items:{...U7}};var BF={type:"object",properties:{c:T0,b:{type:"array",items:{type:"number",minimum:0,maximum:255},minItems:4096,maxItems:4096,nullable:!0},rm:{type:"boolean",nullable:!0}},required:["c"],additionalProperties:!1};var jF={type:"array",items:{...BF}};var b6={type:"array",items:[{type:"number",minimum:0,maximum:255},{type:"number",minimum:0,maximum:255},{type:"number",minimum:0,maximum:255}],minItems:3,maxItems:3};var kF={type:"object",properties:{n:{type:"string"},h:{type:"boolean",nullable:!0},o:{type:"number",minimum:0,maximum:1,nullable:!0},r:{type:"boolean",nullable:!0},s:{type:"number",nullable:!0},t:{...b6,nullable:!0}},required:["n"],additionalProperties:!1};var TF={type:"array",items:[{type:"number"},{type:"number"},{type:"number"},{type:"number"}],minItems:4,maxItems:4};var DF={type:"object",properties:{i:{type:"number"},al:{type:"array",items:{type:"string"},nullable:!0},ao:{type:"array",items:{type:"string"},nullable:!0},ap:{type:"number",nullable:!0},as:{type:"array",items:{type:"string"},nullable:!0},bh:{...T0,nullable:!0},bt:{type:"string",nullable:!0},h:{type:"array",items:{type:"string"},nullable:!0},m:{type:"string",nullable:!0},mo:{type:"array",items:{...kF},nullable:!0},n:{type:"string",nullable:!0},o:{type:"number",nullable:!0},p:{...T0,nullable:!0},pe:{type:"number",nullable:!0},pn:{type:"string",nullable:!0},r:{...TF,nullable:!0},rm:{type:"boolean",nullable:!0},s:{type:"number",nullable:!0},t:{...b6,nullable:!0}},required:["i"],additionalProperties:!1};var _F={type:"array",items:{...DF}};var EF={type:"object",properties:{i:{type:"number"},a:{type:"number",nullable:!0},e:{type:"number",nullable:!0},c:{...b6,nullable:!0},d:{type:"number",nullable:!0},n:{type:"number",nullable:!0},o:{...T0,nullable:!0},p:{...T0,nullable:!0},pe:{type:"number",minimum:0,maximum:1,nullable:!0},rm:{type:"boolean",nullable:!0},t:{type:"number",nullable:!0},te:{type:"number",nullable:!0},tp:{...T0,nullable:!0}},required:["i"],additionalProperties:!1};var CF={type:"array",items:{...EF}};var SF={type:"object",properties:{o:{...T0},d:{...T0},l:{type:"number"},h:{type:"boolean"}},required:["o","d","l","h"],additionalProperties:!1};var IF={type:"array",items:{...SF}};var hF={type:"object",properties:{v:{type:"array",items:{type:"number"}},c:{type:"array",items:{type:"number"}}},required:["v","c"],additionalProperties:!1};var fF={type:"object",properties:{i:{type:"string"},p:{type:"string",nullable:!0},rm:{type:"boolean",nullable:!0},u:{type:"string",nullable:!0}},required:["i"],additionalProperties:!1};var bF={type:"array",items:{...fF}};var pF={type:"object",properties:{i:{type:"number"},e:{type:"number",nullable:!0},o:{...T0,nullable:!0},p:{...T0,nullable:!0},rm:{type:"boolean",nullable:!0},s:{type:"object",nullable:!0},t:{type:"string",nullable:!0},v:{type:"number",nullable:!0}},required:["i"],additionalProperties:!1};var AF={type:"array",items:{...pF}};var yF={type:"object",properties:{r:{type:"number"},s:{type:"number"},p:{type:"number"},n:{type:"number"}},required:["r","s","p","n"],additionalProperties:!1};var gF={type:"object",properties:{p:{type:"boolean",nullable:!0},u:{type:"string",nullable:!0}},additionalProperties:!1};var cF={type:"array",items:{...V7}};var ws={type:"array",items:[{type:"boolean"},{type:"boolean"},{type:"boolean"}],minItems:3,maxItems:3};var mF={type:"object",properties:{i:{type:"number"},ac:{...b6,nullable:!0},ai:{type:"number",nullable:!0},dc:{...b6,nullable:!0},di:{type:"number",nullable:!0},dp:{...T0,nullable:!0},j:{type:"boolean",nullable:!0},n:{type:"string",nullable:!0},s:{type:"string",nullable:!0},t:{type:"number",nullable:!0}},required:["i"],additionalProperties:!1};var yP=d(40,NF);var gP=d(36,vF);var cP=d(37,jF);var mP=d(38,_F);var lP=d(44,CF);var uP=d(192,hF);var dP=d(193,IF);var iP=d(45,bF);var nP=d(43,AF);var aP=d(32,yF);var sP=d(41,gF);var oP=d(42,cF);var rP=d(39,mF);var cZ=new Map,Os={...AZ,...yZ,...gZ};for(let J of Object.values(Os))if("id"in J&&"schema"in J){let X=J;if(cZ.has(X.id))throw new Error(`Packet with id ${X.id} is already registered.`);cZ.set(X.id,X)}function xs(J){if(typeof J!=="object"||J===null||typeof J[0]!=="number"||J[0]<0||J[1]===void 0||J[2]!==void 0&&(typeof J[2]!=="number"||J[2]<0))return!1;let X=cZ.get(J[0]);return!!X&&X.validate(J[1])}var A=lF;import{WebSocket as mX0}from"ws";var B8=a6(Xv(),1),_N0=B8.default.v1,EN0=B8.default.v1ToV6,CN0=B8.default.v3,Yv=B8.default.v4,SN0=B8.default.v5,IN0=B8.default.v6,hN0=B8.default.v6ToV1,fN0=B8.default.v7,bN0=B8.default.NIL,pN0=B8.default.MAX,AN0=B8.default.version,yN0=B8.default.validate,gN0=B8.default.stringify,cN0=B8.default.parse;function Zv(J){let X=J.length,Y=0,Z=0;while(Z<X){let W=J.charCodeAt(Z++);if((W&4294967168)===0){Y++;continue}else if((W&4294965248)===0)Y+=2;else{if(W>=55296&&W<=56319){if(Z<X){let $=J.charCodeAt(Z);if(($&64512)===56320)++Z,W=((W&1023)<<10)+($&1023)+65536}}if((W&4294901760)===0)Y+=3;else Y+=4}}return Y}function oo(J,X,Y){let Z=J.length,W=Y,$=0;while($<Z){let Q=J.charCodeAt($++);if((Q&4294967168)===0){X[W++]=Q;continue}else if((Q&4294965248)===0)X[W++]=Q>>6&31|192;else{if(Q>=55296&&Q<=56319){if($<Z){let K=J.charCodeAt($);if((K&64512)===56320)++$,Q=((Q&1023)<<10)+(K&1023)+65536}}if((Q&4294901760)===0)X[W++]=Q>>12&15|224,X[W++]=Q>>6&63|128;else X[W++]=Q>>18&7|240,X[W++]=Q>>12&63|128,X[W++]=Q>>6&63|128}X[W++]=Q&63|128}}var ro=new TextEncoder,to=50;function eo(J,X,Y){ro.encodeInto(J,X.subarray(Y))}function Wv(J,X,Y){if(J.length>to)eo(J,X,Y);else oo(J,X,Y)}var Jr=4096;function oF(J,X,Y){let Z=X,W=Z+Y,$=[],Q="";while(Z<W){let K=J[Z++];if((K&128)===0)$.push(K);else if((K&224)===192){let G=J[Z++]&63;$.push((K&31)<<6|G)}else if((K&240)===224){let G=J[Z++]&63,F=J[Z++]&63;$.push((K&31)<<12|G<<6|F)}else if((K&248)===240){let G=J[Z++]&63,F=J[Z++]&63,q=J[Z++]&63,H=(K&7)<<18|G<<12|F<<6|q;if(H>65535)H-=65536,$.push(H>>>10&1023|55296),H=56320|H&1023;$.push(H)}else $.push(K);if($.length>=Jr)Q+=String.fromCharCode(...$),$.length=0}if($.length>0)Q+=String.fromCharCode(...$);return Q}var Xr=new TextDecoder,Yr=200;function Zr(J,X,Y){let Z=J.subarray(X,X+Y);return Xr.decode(Z)}function $v(J,X,Y){if(Y>Yr)return Zr(J,X,Y);else return oF(J,X,Y)}class R5{constructor(J,X){this.type=J,this.data=X}}class j8 extends Error{constructor(J){super(J);let X=Object.create(j8.prototype);Object.setPrototypeOf(this,X),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:j8.name})}}var w5=4294967295;function Qv(J,X,Y){let Z=Y/4294967296,W=Y;J.setUint32(X,Z),J.setUint32(X+4,W)}function iZ(J,X,Y){let Z=Math.floor(Y/4294967296),W=Y;J.setUint32(X,Z),J.setUint32(X+4,W)}function nZ(J,X){let Y=J.getInt32(X),Z=J.getUint32(X+4);return Y*4294967296+Z}function Kv(J,X){let Y=J.getUint32(X),Z=J.getUint32(X+4);return Y*4294967296+Z}var Wr=-1,$r=4294967295,Qr=17179869183;function Kr({sec:J,nsec:X}){if(J>=0&&X>=0&&J<=Qr)if(X===0&&J<=$r){let Y=new Uint8Array(4);return new DataView(Y.buffer).setUint32(0,J),Y}else{let Y=J/4294967296,Z=J&4294967295,W=new Uint8Array(8),$=new DataView(W.buffer);return $.setUint32(0,X<<2|Y&3),$.setUint32(4,Z),W}else{let Y=new Uint8Array(12),Z=new DataView(Y.buffer);return Z.setUint32(0,X),iZ(Z,4,J),Y}}function Gr(J){let X=J.getTime(),Y=Math.floor(X/1000),Z=(X-Y*1000)*1e6,W=Math.floor(Z/1e9);return{sec:Y+W,nsec:Z-W*1e9}}function Fr(J){if(J instanceof Date){let X=Gr(J);return Kr(X)}else return null}function qr(J){let X=new DataView(J.buffer,J.byteOffset,J.byteLength);switch(J.byteLength){case 4:{let Y=X.getUint32(0),Z=0;return{sec:Y,nsec:0}}case 8:{let Y=X.getUint32(0),Z=X.getUint32(4),W=(Y&3)*4294967296+Z,$=Y>>>2;return{sec:W,nsec:$}}case 12:{let Y=nZ(X,4),Z=X.getUint32(0);return{sec:Y,nsec:Z}}default:throw new j8(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${J.length}`)}}function Hr(J){let X=qr(J);return new Date(X.sec*1000+X.nsec/1e6)}var Gv={type:Wr,encode:Fr,decode:Hr};class V9{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Gv)}register({type:J,encode:X,decode:Y}){if(J>=0)this.encoders[J]=X,this.decoders[J]=Y;else{let Z=-1-J;this.builtInEncoders[Z]=X,this.builtInDecoders[Z]=Y}}tryToEncode(J,X){for(let Y=0;Y<this.builtInEncoders.length;Y++){let Z=this.builtInEncoders[Y];if(Z!=null){let W=Z(J,X);if(W!=null){let $=-1-Y;return new R5($,W)}}}for(let Y=0;Y<this.encoders.length;Y++){let Z=this.encoders[Y];if(Z!=null){let W=Z(J,X);if(W!=null)return new R5(Y,W)}}if(J instanceof R5)return J;return null}decode(J,X,Y){let Z=X<0?this.builtInDecoders[-1-X]:this.decoders[X];if(Z)return Z(J,X,Y);else return new R5(X,J)}}V9.defaultCodec=new V9;function zr(J){return J instanceof ArrayBuffer||typeof SharedArrayBuffer!=="undefined"&&J instanceof SharedArrayBuffer}function w7(J){if(J instanceof Uint8Array)return J;else if(ArrayBuffer.isView(J))return new Uint8Array(J.buffer,J.byteOffset,J.byteLength);else if(zr(J))return new Uint8Array(J);else return Uint8Array.from(J)}var Lr=100,Ur=2048;class aZ{constructor(J){this.entered=!1,this.extensionCodec=J?.extensionCodec??V9.defaultCodec,this.context=J?.context,this.useBigInt64=J?.useBigInt64??!1,this.maxDepth=J?.maxDepth??Lr,this.initialBufferSize=J?.initialBufferSize??Ur,this.sortKeys=J?.sortKeys??!1,this.forceFloat32=J?.forceFloat32??!1,this.ignoreUndefined=J?.ignoreUndefined??!1,this.forceIntegerToFloat=J?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new aZ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(J){if(this.entered)return this.clone().encodeSharedRef(J);try{return this.entered=!0,this.reinitializeState(),this.doEncode(J,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(J){if(this.entered)return this.clone().encode(J);try{return this.entered=!0,this.reinitializeState(),this.doEncode(J,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(J,X){if(X>this.maxDepth)throw new Error(`Too deep objects in depth ${X}`);if(J==null)this.encodeNil();else if(typeof J==="boolean")this.encodeBoolean(J);else if(typeof J==="number")if(!this.forceIntegerToFloat)this.encodeNumber(J);else this.encodeNumberAsFloat(J);else if(typeof J==="string")this.encodeString(J);else if(this.useBigInt64&&typeof J==="bigint")this.encodeBigInt64(J);else this.encodeObject(J,X)}ensureBufferSizeToWrite(J){let X=this.pos+J;if(this.view.byteLength<X)this.resizeBuffer(X*2)}resizeBuffer(J){let X=new ArrayBuffer(J),Y=new Uint8Array(X),Z=new DataView(X);Y.set(this.bytes),this.view=Z,this.bytes=Y}encodeNil(){this.writeU8(192)}encodeBoolean(J){if(J===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(J){if(!this.forceIntegerToFloat&&Number.isSafeInteger(J))if(J>=0)if(J<128)this.writeU8(J);else if(J<256)this.writeU8(204),this.writeU8(J);else if(J<65536)this.writeU8(205),this.writeU16(J);else if(J<4294967296)this.writeU8(206),this.writeU32(J);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(J);else this.encodeNumberAsFloat(J);else if(J>=-32)this.writeU8(224|J+32);else if(J>=-128)this.writeU8(208),this.writeI8(J);else if(J>=-32768)this.writeU8(209),this.writeI16(J);else if(J>=-2147483648)this.writeU8(210),this.writeI32(J);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(J);else this.encodeNumberAsFloat(J);else this.encodeNumberAsFloat(J)}encodeNumberAsFloat(J){if(this.forceFloat32)this.writeU8(202),this.writeF32(J);else this.writeU8(203),this.writeF64(J)}encodeBigInt64(J){if(J>=BigInt(0))this.writeU8(207),this.writeBigUint64(J);else this.writeU8(211),this.writeBigInt64(J)}writeStringHeader(J){if(J<32)this.writeU8(160+J);else if(J<256)this.writeU8(217),this.writeU8(J);else if(J<65536)this.writeU8(218),this.writeU16(J);else if(J<4294967296)this.writeU8(219),this.writeU32(J);else throw new Error(`Too long string: ${J} bytes in UTF-8`)}encodeString(J){let Y=Zv(J);this.ensureBufferSizeToWrite(5+Y),this.writeStringHeader(Y),Wv(J,this.bytes,this.pos),this.pos+=Y}encodeObject(J,X){let Y=this.extensionCodec.tryToEncode(J,this.context);if(Y!=null)this.encodeExtension(Y);else if(Array.isArray(J))this.encodeArray(J,X);else if(ArrayBuffer.isView(J))this.encodeBinary(J);else if(typeof J==="object")this.encodeMap(J,X);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(J)}`)}encodeBinary(J){let X=J.byteLength;if(X<256)this.writeU8(196),this.writeU8(X);else if(X<65536)this.writeU8(197),this.writeU16(X);else if(X<4294967296)this.writeU8(198),this.writeU32(X);else throw new Error(`Too large binary: ${X}`);let Y=w7(J);this.writeU8a(Y)}encodeArray(J,X){let Y=J.length;if(Y<16)this.writeU8(144+Y);else if(Y<65536)this.writeU8(220),this.writeU16(Y);else if(Y<4294967296)this.writeU8(221),this.writeU32(Y);else throw new Error(`Too large array: ${Y}`);for(let Z of J)this.doEncode(Z,X+1)}countWithoutUndefined(J,X){let Y=0;for(let Z of X)if(J[Z]!==void 0)Y++;return Y}encodeMap(J,X){let Y=Object.keys(J);if(this.sortKeys)Y.sort();let Z=this.ignoreUndefined?this.countWithoutUndefined(J,Y):Y.length;if(Z<16)this.writeU8(128+Z);else if(Z<65536)this.writeU8(222),this.writeU16(Z);else if(Z<4294967296)this.writeU8(223),this.writeU32(Z);else throw new Error(`Too large map object: ${Z}`);for(let W of Y){let $=J[W];if(!(this.ignoreUndefined&&$===void 0))this.encodeString(W),this.doEncode($,X+1)}}encodeExtension(J){if(typeof J.data==="function"){let Y=J.data(this.pos+6),Z=Y.length;if(Z>=4294967296)throw new Error(`Too large extension object: ${Z}`);this.writeU8(201),this.writeU32(Z),this.writeI8(J.type),this.writeU8a(Y);return}let X=J.data.length;if(X===1)this.writeU8(212);else if(X===2)this.writeU8(213);else if(X===4)this.writeU8(214);else if(X===8)this.writeU8(215);else if(X===16)this.writeU8(216);else if(X<256)this.writeU8(199),this.writeU8(X);else if(X<65536)this.writeU8(200),this.writeU16(X);else if(X<4294967296)this.writeU8(201),this.writeU32(X);else throw new Error(`Too large extension object: ${X}`);this.writeI8(J.type),this.writeU8a(J.data)}writeU8(J){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,J),this.pos++}writeU8a(J){let X=J.length;this.ensureBufferSizeToWrite(X),this.bytes.set(J,this.pos),this.pos+=X}writeI8(J){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,J),this.pos++}writeU16(J){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,J),this.pos+=2}writeI16(J){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,J),this.pos+=2}writeU32(J){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,J),this.pos+=4}writeI32(J){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,J),this.pos+=4}writeF32(J){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,J),this.pos+=4}writeF64(J){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,J),this.pos+=8}writeU64(J){this.ensureBufferSizeToWrite(8),Qv(this.view,this.pos,J),this.pos+=8}writeI64(J){this.ensureBufferSizeToWrite(8),iZ(this.view,this.pos,J),this.pos+=8}writeBigUint64(J){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,J),this.pos+=8}writeBigInt64(J){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,J),this.pos+=8}}function rF(J,X){return new aZ(X).encodeSharedRef(J)}function sZ(J){return`${J<0?"-":""}0x${Math.abs(J).toString(16).padStart(2,"0")}`}var Vr=16,Mr=16;class tF{constructor(J=Vr,X=Mr){this.hit=0,this.miss=0,this.maxKeyLength=J,this.maxLengthPerKey=X,this.caches=[];for(let Y=0;Y<this.maxKeyLength;Y++)this.caches.push([])}canBeCached(J){return J>0&&J<=this.maxKeyLength}find(J,X,Y){let Z=this.caches[Y-1];J:for(let W of Z){let $=W.bytes;for(let Q=0;Q<Y;Q++)if($[Q]!==J[X+Q])continue J;return W.str}return null}store(J,X){let Y=this.caches[J.length-1],Z={bytes:J,str:X};if(Y.length>=this.maxLengthPerKey)Y[Math.random()*Y.length|0]=Z;else Y.push(Z)}decode(J,X,Y){let Z=this.find(J,X,Y);if(Z!=null)return this.hit++,Z;this.miss++;let W=oF(J,X,Y),$=Uint8Array.prototype.slice.call(J,X,X+Y);return this.store($,W),W}}var eF="array",x7="map_key",qv="map_value",Rr=(J)=>{if(typeof J==="string"||typeof J==="number")return J;throw new j8("The type of key must be string or number but "+typeof J)};class Hv{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(J){let X=this.getUninitializedStateFromPool();X.type=eF,X.position=0,X.size=J,X.array=new Array(J)}pushMapState(J){let X=this.getUninitializedStateFromPool();X.type=x7,X.readCount=0,X.size=J,X.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let J={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(J)}return this.stack[this.stackHeadPosition]}release(J){if(this.stack[this.stackHeadPosition]!==J)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(J.type===eF){let Y=J;Y.size=0,Y.array=void 0,Y.position=0,Y.type=void 0}if(J.type===x7||J.type===qv){let Y=J;Y.size=0,Y.map=void 0,Y.readCount=0,Y.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}var O7=-1,J3=new DataView(new ArrayBuffer(0)),wr=new Uint8Array(J3.buffer);try{J3.getInt8(0)}catch(J){if(!(J instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var Fv=new RangeError("Insufficient data"),Or=new tF;class oZ{constructor(J){this.totalPos=0,this.pos=0,this.view=J3,this.bytes=wr,this.headByte=O7,this.stack=new Hv,this.entered=!1,this.extensionCodec=J?.extensionCodec??V9.defaultCodec,this.context=J?.context,this.useBigInt64=J?.useBigInt64??!1,this.rawStrings=J?.rawStrings??!1,this.maxStrLength=J?.maxStrLength??w5,this.maxBinLength=J?.maxBinLength??w5,this.maxArrayLength=J?.maxArrayLength??w5,this.maxMapLength=J?.maxMapLength??w5,this.maxExtLength=J?.maxExtLength??w5,this.keyDecoder=J?.keyDecoder!==void 0?J.keyDecoder:Or,this.mapKeyConverter=J?.mapKeyConverter??Rr}clone(){return new oZ({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=O7,this.stack.reset()}setBuffer(J){let X=w7(J);this.bytes=X,this.view=new DataView(X.buffer,X.byteOffset,X.byteLength),this.pos=0}appendBuffer(J){if(this.headByte===O7&&!this.hasRemaining(1))this.setBuffer(J);else{let X=this.bytes.subarray(this.pos),Y=w7(J),Z=new Uint8Array(X.length+Y.length);Z.set(X),Z.set(Y,X.length),this.setBuffer(Z)}}hasRemaining(J){return this.view.byteLength-this.pos>=J}createExtraByteError(J){let{view:X,pos:Y}=this;return new RangeError(`Extra ${X.byteLength-Y} of ${X.byteLength} byte(s) found at buffer[${J}]`)}decode(J){if(this.entered)return this.clone().decode(J);try{this.entered=!0,this.reinitializeState(),this.setBuffer(J);let X=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return X}finally{this.entered=!1}}*decodeMulti(J){if(this.entered){yield*this.clone().decodeMulti(J);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(J);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(J){if(this.entered)return this.clone().decodeAsync(J);try{this.entered=!0;let X=!1,Y;for await(let Q of J){if(X)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(Q);try{Y=this.doDecodeSync(),X=!0}catch(K){if(!(K instanceof RangeError))throw K}this.totalPos+=this.pos}if(X){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Y}let{headByte:Z,pos:W,totalPos:$}=this;throw new RangeError(`Insufficient data in parsing ${sZ(Z)} at ${$} (${W} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(J){return this.decodeMultiAsync(J,!0)}decodeStream(J){return this.decodeMultiAsync(J,!1)}async*decodeMultiAsync(J,X){if(this.entered){yield*this.clone().decodeMultiAsync(J,X);return}try{this.entered=!0;let Y=X,Z=-1;for await(let W of J){if(X&&Z===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(W),Y)Z=this.readArraySize(),Y=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--Z===0)break}catch($){if(!($ instanceof RangeError))throw $}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){J:while(!0){let J=this.readHeadByte(),X;if(J>=224)X=J-256;else if(J<192)if(J<128)X=J;else if(J<144){let Z=J-128;if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J<160){let Z=J-144;if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else{let Z=J-160;X=this.decodeString(Z,0)}else if(J===192)X=null;else if(J===194)X=!1;else if(J===195)X=!0;else if(J===202)X=this.readF32();else if(J===203)X=this.readF64();else if(J===204)X=this.readU8();else if(J===205)X=this.readU16();else if(J===206)X=this.readU32();else if(J===207)if(this.useBigInt64)X=this.readU64AsBigInt();else X=this.readU64();else if(J===208)X=this.readI8();else if(J===209)X=this.readI16();else if(J===210)X=this.readI32();else if(J===211)if(this.useBigInt64)X=this.readI64AsBigInt();else X=this.readI64();else if(J===217){let Z=this.lookU8();X=this.decodeString(Z,1)}else if(J===218){let Z=this.lookU16();X=this.decodeString(Z,2)}else if(J===219){let Z=this.lookU32();X=this.decodeString(Z,4)}else if(J===220){let Z=this.readU16();if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else if(J===221){let Z=this.readU32();if(Z!==0){this.pushArrayState(Z),this.complete();continue J}else X=[]}else if(J===222){let Z=this.readU16();if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J===223){let Z=this.readU32();if(Z!==0){this.pushMapState(Z),this.complete();continue J}else X={}}else if(J===196){let Z=this.lookU8();X=this.decodeBinary(Z,1)}else if(J===197){let Z=this.lookU16();X=this.decodeBinary(Z,2)}else if(J===198){let Z=this.lookU32();X=this.decodeBinary(Z,4)}else if(J===212)X=this.decodeExtension(1,0);else if(J===213)X=this.decodeExtension(2,0);else if(J===214)X=this.decodeExtension(4,0);else if(J===215)X=this.decodeExtension(8,0);else if(J===216)X=this.decodeExtension(16,0);else if(J===199){let Z=this.lookU8();X=this.decodeExtension(Z,1)}else if(J===200){let Z=this.lookU16();X=this.decodeExtension(Z,2)}else if(J===201){let Z=this.lookU32();X=this.decodeExtension(Z,4)}else throw new j8(`Unrecognized type byte: ${sZ(J)}`);this.complete();let Y=this.stack;while(Y.length>0){let Z=Y.top();if(Z.type===eF)if(Z.array[Z.position]=X,Z.position++,Z.position===Z.size)X=Z.array,Y.release(Z);else continue J;else if(Z.type===x7){if(X==="__proto__")throw new j8("The key __proto__ is not allowed");Z.key=this.mapKeyConverter(X),Z.type=qv;continue J}else if(Z.map[Z.key]=X,Z.readCount++,Z.readCount===Z.size)X=Z.map,Y.release(Z);else{Z.key=null,Z.type=x7;continue J}}return X}}readHeadByte(){if(this.headByte===O7)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=O7}readArraySize(){let J=this.readHeadByte();switch(J){case 220:return this.readU16();case 221:return this.readU32();default:if(J<160)return J-144;else throw new j8(`Unrecognized array type byte: ${sZ(J)}`)}}pushMapState(J){if(J>this.maxMapLength)throw new j8(`Max length exceeded: map length (${J}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(J)}pushArrayState(J){if(J>this.maxArrayLength)throw new j8(`Max length exceeded: array length (${J}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(J)}decodeString(J,X){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(J,X);return this.decodeBinary(J,X)}decodeUtf8String(J,X){if(J>this.maxStrLength)throw new j8(`Max length exceeded: UTF-8 byte length (${J}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+X+J)throw Fv;let Y=this.pos+X,Z;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(J))Z=this.keyDecoder.decode(this.bytes,Y,J);else Z=$v(this.bytes,Y,J);return this.pos+=X+J,Z}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===x7;return!1}decodeBinary(J,X){if(J>this.maxBinLength)throw new j8(`Max length exceeded: bin length (${J}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(J+X))throw Fv;let Y=this.pos+X,Z=this.bytes.subarray(Y,Y+J);return this.pos+=X+J,Z}decodeExtension(J,X){if(J>this.maxExtLength)throw new j8(`Max length exceeded: ext length (${J}) > maxExtLength (${this.maxExtLength})`);let Y=this.view.getInt8(this.pos+X),Z=this.decodeBinary(J,X+1);return this.extensionCodec.decode(Z,Y,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let J=this.view.getUint8(this.pos);return this.pos++,J}readI8(){let J=this.view.getInt8(this.pos);return this.pos++,J}readU16(){let J=this.view.getUint16(this.pos);return this.pos+=2,J}readI16(){let J=this.view.getInt16(this.pos);return this.pos+=2,J}readU32(){let J=this.view.getUint32(this.pos);return this.pos+=4,J}readI32(){let J=this.view.getInt32(this.pos);return this.pos+=4,J}readU64(){let J=Kv(this.view,this.pos);return this.pos+=8,J}readI64(){let J=nZ(this.view,this.pos);return this.pos+=8,J}readU64AsBigInt(){let J=this.view.getBigUint64(this.pos);return this.pos+=8,J}readI64AsBigInt(){let J=this.view.getBigInt64(this.pos);return this.pos+=8,J}readF32(){let J=this.view.getFloat32(this.pos);return this.pos+=4,J}readF64(){let J=this.view.getFloat64(this.pos);return this.pos+=8,J}}function X3(J,X){return new oZ(X).decode(J)}import{WebSocketServer as gX0}from"ws";import cX0 from"mediasoup";var Z$=a6(nE(),1);import bX0 from"http";import pX0 from"https";import I9 from"fs";import AX0 from"path";import yX0 from"url";var wC=a6(MC(),1);import S9 from"fs";import RC from"path";var xJ="./dev/persistence";class u6{static instance=new u6;gameId=process.env.HYTOPIA_GAME_ID;lobbyId=process.env.HYTOPIA_LOBBY_ID;_creativeGateway;constructor(){try{this._creativeGateway=new wC.CreativeGateway}catch{console.warn(["\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501","\uD83D\uDEA8 HYTOPIA PLATFORM GATEWAY IS NOT INITIALIZED \uD83D\uDEA8","","\uD83D\uDD27 Local development is still possible, but these features will be disabled:"," \u2022 \uD83D\uDC64 Player Accounts"," \u2022 \uD83C\uDFAD Player Cosmetics"," \u2022 \uD83D\uDC1B Crash Analytics & Debug Logs","","\uD83D\uDCA1 These features will be enabled but modified:"," \u2022 \uD83D\uDCBE Player & Global Persisted Data - Data will be persisted"," locally in the ./dev/persistence directory of your project."," Player ids for data persistence will begin at 1 for the first "," player to join your local server, and increments for each"," additional player. This means that if you restart your"," server, the first player id will be 1 again. This is to ensure"," that data persistence across server restarts can be easily"," tested and debugged in local development.","","To enable the HYTOPIA Platform Gateway locally:"," 1. Set these environment variables:"," HYTOPIA_API_KEY, HYTOPIA_GAME_ID, HYTOPIA_LOBBY_ID"," 2. You can find these values at: https://create.hytopia.com","","Note: In production, these environment variables will be auto-populated ","& the HYTOPIA Platform Gateway will automatically be initialized \uD83D\uDE80","\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",""].join(`
|
380
380
|
`))}}get isGatewayAvailable(){return!!this._creativeGateway}async getData(J){if(!this._creativeGateway&&process.env.NODE_ENV==="production")return E.warning("PlatformGateway.getData(): You are running in production mode, but the Platform Gateway is not initialized! No data will be returned.");return this._creativeGateway?await this._creativeGateway.kv.get(J):this._readDevDataLocally(J)}async getPlayerLoadout(J){if(!this._creativeGateway)return;return await this._creativeGateway.getLoadout(J)}async getPlayerSession(J){if(!this._creativeGateway)return;return await this._creativeGateway.getSession(J)}async setData(J,X){if(X.error)return E.warning("PlatformGateway.setData(): Cannot set data with an error property.");if(!this._creativeGateway&&process.env.NODE_ENV==="production")return E.warning("PlatformGateway.setData(): You are running in production mode, but the Platform Gateway is not initialized! No data will be set.");return this._creativeGateway?await this._creativeGateway.kv.set(J,X):this._writeDevDataLocally(J,X)}_readDevDataLocally(J){try{if(!S9.existsSync(xJ))return;let X=RC.join(xJ,`${J}.json`);return JSON.parse(S9.readFileSync(X,"utf8"))}catch(X){E.warning(`PlatformGateway._readDevDataLocally(): Failed to read data for key "${J}": ${X}`)}}_writeDevDataLocally(J,X){try{if(!S9.existsSync(xJ))S9.mkdirSync(xJ,{recursive:!0});let Y=RC.join(xJ,`${J}.json`),Z={};if(S9.existsSync(Y))Z=JSON.parse(S9.readFileSync(Y,"utf8"));let W={...Z,...X};S9.writeFileSync(Y,JSON.stringify(W,null,2),"utf8")}catch(Y){E.warning(`PlatformGateway._writeDevDataLocally(): Failed to write data for key "${J}": ${Y}`)}}}var qH=process.env.PORT??8080,OC="DEV";try{let X=AX0.dirname(b.resolve("hytopia"));OC=JSON.parse(I9.readFileSync(X+"/package.json","utf8")).version}catch{}var HH;((W)=>{W.READY="WEBSERVER.READY";W.STOPPED="WEBSERVER.STOPPED";W.ERROR="WEBSERVER.ERROR";W.UPGRADE="WEBSERVER.UPGRADE"})(HH||={});class o5 extends s{static instance=new o5;_webserver=Z$.default();_internalHttpServer;constructor(){super();this._webserver.use((J,X,Y)=>{X.header("Access-Control-Allow-Origin","*"),Y()}),this._webserver.get("/",(J,X)=>{X.json({status:"OK",version:OC})}),this._webserver.use(Z$.default.static("assets")),this._webserver.use(Z$.default.static("node_modules/@hytopia.com/assets"))}start(){if(!this._internalHttpServer)this._internalHttpServer=process.env.NODE_ENV==="production"?bX0.createServer(this._webserver):pX0.createServer({key:I9.existsSync("assets/certs/localhost.key")?I9.readFileSync("assets/certs/localhost.key"):I9.readFileSync("node_modules/@hytopia.com/assets/certs/localhost.key"),cert:I9.existsSync("assets/certs/localhost.crt")?I9.readFileSync("assets/certs/localhost.crt"):I9.readFileSync("node_modules/@hytopia.com/assets/certs/localhost.crt")},this._webserver),this._internalHttpServer.on("upgrade",this._onUpgrade),this._internalHttpServer.on("error",this._onError),this._internalHttpServer.on("close",this._onStopped);else E.warning("WebServer.start(): server already started!");this._internalHttpServer.listen(qH,this._onStarted),console.info(`WebServer.start(): Server running on port ${qH}.`)}stop(){if(this._internalHttpServer)return new Promise((J,X)=>{this._internalHttpServer.close((Y)=>{if(Y)X(Y);else J(!0)})});else return E.warning("WebServer.stop(): server not started."),Promise.resolve(!1)}_onStarted=()=>{this.emitWithGlobal("WEBSERVER.READY",{})};_onUpgrade=async(J,X,Y)=>{let Z=yX0.parse(J.url??"",!0).query.sessionToken?.toString()??"",W=await u6.instance.getPlayerSession(Z);if(W)if(!W.error)J.session=W;else{let $=`${W.error.code}: ${W.error.message}`;X.write(`HTTP/1.1 401 Unauthorized\r
|
381
381
|
`),X.write(`Content-Type: text/plain\r
|
382
382
|
`),X.write(`Content-Length: ${$.length}\r
|
383
383
|
`),X.write(`Connection: close\r
|
384
384
|
`),X.write(`\r
|
385
|
-
`),X.write($),X.end();return}X.setNoDelay(!0),this.emitWithGlobal("WEBSERVER.UPGRADE",{req:J,socket:X,head:Y})};_onError=(J)=>{this.emitWithGlobal("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{this.emitWithGlobal("WEBSERVER.STOPPED",{})}}class i1 extends s{static instance=new i1;_wss;_wrtcMinPort=process.env.WRTC_MIN_PORT?parseInt(process.env.WRTC_MIN_PORT):40000;_wrtcMaxPort=process.env.WRTC_MAX_PORT?parseInt(process.env.WRTC_MAX_PORT):41023;_wrtcPublicIpv4=process.env.NODE_ENV==="production"?process.env.WRTC_PUBLIC_IPV4:"127.0.0.1";_wrtcPublicIpv6=process.env.NODE_ENV==="production"?process.env.WRTC_PUBLIC_IPV6:"::";_wrtcRouter=null;_wrtcWorker=null;constructor(){super();this._wss=new gX0({noServer:!0}),this._wss.on("connection",this._onConnection),this._wss.on("error",this._onError),this._initWrtc().catch((J)=>{E.warning(`Socket._constructor(): Failed to initialize WebRTC, falling back to Websockets. This can be ignored for local development. Error: ${J.message}`)}),m8.on("WEBSERVER.UPGRADE",({req:J,socket:X,head:Y})=>this._onUpgrade(J,X,Y))}get isWrtcEnabled(){return this._wrtcWorker&&!this._wrtcWorker.died&&this._wrtcRouter}get wrtcRouter(){return this._wrtcRouter}async createWrtcTransports(){if(!this.isWrtcEnabled)E.fatalError("Socket.createWrtcTransports(): WebRTC not enabled, unable to create transports.");let J={listenIps:[{ip:"::",announcedIp:this._wrtcPublicIpv6},{ip:"0.0.0.0",announcedIp:this._wrtcPublicIpv4}],preferUdp:!0,enableSctp:!0,enableTcp:!1},X=await this._wrtcRouter.createDirectTransport(),Y=await this._wrtcRouter.createWebRtcTransport(J),Z=await this._wrtcRouter.createWebRtcTransport(J);return{directTransport:X,clientServerTransport:Y,serverClientTransport:Z}}async _initWrtc(){if(!this._wrtcPublicIpv4||!this._wrtcPublicIpv6)throw new Error("Socket._initWrtc(): WebRTC disabled, falling back to Websockets. Env variables WRTC_PUBLIC_IPV4 and WRTC_PUBLIC_IPV6 must be set in production");this._wrtcWorker=await cX0.createWorker({rtcMinPort:this._wrtcMinPort,rtcMaxPort:this._wrtcMaxPort}),this._wrtcWorker.on("died",this._onWrtcWorkerDied),this._wrtcRouter=await this._wrtcWorker.createRouter({mediaCodecs:[]}),console.log("Socket._initWrtc(): WebRTC enabled and ready!")}_onConnection=(J,X)=>{new h9(J,X)};_onError=(J,X)=>{this.emitWithGlobal("SOCKET.ERROR",{ws:J,error:X})};_onUpgrade=(J,X,Y)=>{this._wss.handleUpgrade(J,X,Y,(Z)=>{this._wss.emit("connection",Z,J)})};_onWrtcWorkerDied=(J)=>{E.warning(`Socket._onWrtcWorkerDied(): WebRTC worker unexpectedly died, falling back to Websockets for all players. Internal error: ${J}`),j6.instance.getConnectedPlayers().forEach((X)=>{X.connection.closeWrtc()}),this._wrtcRouter?.close(),this._wrtcRouter=null,this._wrtcWorker?.close(),this._wrtcWorker=null}}class h9 extends s{static _serializedPackets=new WeakMap;_wrtcDirectTransport=null;_wrtcClientServerTransport=null;_wrtcClientServerDataProducers=[];_wrtcClientServerDataConsumers=[];_wrtcServerClientTransport=null;_wrtcServerClientReliableDataProducer=null;_wrtcServerClientUnreliableDataProducer=null;_wrtcServerClientDataConsumers=[];_ws;id;constructor(J,X){super();if(this.id=Yv(),this._ws=J,this._ws.binaryType="nodebuffer",this._ws.onmessage=(Y)=>this._onMessage(Y.data),this._ws.onclose=this._onWsClose,this._ws.onerror=this._onWsError,this.onPacket(A.PacketId.CONNECTION,this._onConnectionPacket),this.onPacket(A.PacketId.HEARTBEAT,this._onHeartbeatPacket),i1.instance.isWrtcEnabled)this._upgradeToWRTC();m8.emit("CONNECTION.OPENED",{connection:this,req:X})}static serializePackets(J){for(let W of J)if(!A.isValidPacket(W))return E.error(`Connection.serializePackets(): Invalid packet payload: ${JSON.stringify(W)}`);let X=h9._serializedPackets.get(J);if(X)return X;let Y=rF(J),Z=Buffer.from(Y.buffer,Y.byteOffset,Y.byteLength);return h9._serializedPackets.set(J,Z),Z}send(J,X=!0,Y=!1){if(this._ws.readyState!==mX0.OPEN)return E.warning("Connection.send(): Connection is not open.");try{let Z=h9.serializePackets(J);if(!Z)return;if(this._wrtcServerClientTransport?.iceState==="completed"&&!Y)try{(X?this._wrtcServerClientReliableDataProducer:this._wrtcServerClientUnreliableDataProducer).send(Z)}catch{this._ws.send(Z)}else this._ws.send(Z);this.emitWithGlobal("CONNECTION.PACKETS_SENT",{connection:this,packets:J})}catch(Z){E.error(`Connection.send(): Packet send failed. Error: ${Z}`)}}close(){try{this.offAll(),this._ws.close()}catch(J){E.error(`Connection.close(): Connection close failed. Error: ${J}`)}}closeWrtc(){this._closeWrtcClientServerTransport(),this._closeWrtcServerClientTransport()}onPacket(J,X){this.on("CONNECTION.PACKET_RECEIVED",({packet:Y})=>{if(Y[0]===J)X(Y)})}_closeWrtcClientServerTransport(){this._wrtcDirectTransport?.close(),this._wrtcDirectTransport=null,this._wrtcClientServerTransport?.close(),this._wrtcClientServerTransport=null,this._wrtcClientServerDataProducers.forEach((J)=>J.close()),this._wrtcClientServerDataProducers=[],this._wrtcClientServerDataConsumers.forEach((J)=>J.close()),this._wrtcClientServerDataConsumers=[]}_closeWrtcServerClientTransport(){this._wrtcServerClientTransport?.close(),this._wrtcServerClientTransport=null,this._wrtcServerClientDataConsumers.forEach((J)=>J.close()),this._wrtcServerClientDataConsumers=[],this._wrtcServerClientReliableDataProducer?.close(),this._wrtcServerClientReliableDataProducer=null,this._wrtcServerClientUnreliableDataProducer?.close(),this._wrtcServerClientUnreliableDataProducer=null}_onConnectionPacket=async(J)=>{let X=J[1],Y=X.c,Z=X.d;if(Y){let{i:W,d:$}=Y,Q=!1;if(W==this._wrtcClientServerTransport?.id)await this._wrtcClientServerTransport.connect({dtlsParameters:$}),Q=!0;if(W==this._wrtcServerClientTransport?.id)await this._wrtcServerClientTransport.connect({dtlsParameters:$}),Q=!0;if(Q)this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{ca:{i:W}})])}if(Z)for(let W of Z){let{s:$,l:Q}=W,K=await this._wrtcClientServerTransport.produceData({label:Q,sctpStreamParameters:$}),G=await this._wrtcDirectTransport.consumeData({dataProducerId:K.id});this._wrtcClientServerDataProducers.push(K),this._wrtcClientServerDataConsumers.push(G),G.on("message",(F)=>this._onMessage(F)),this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{pa:{i:K.id,l:Q}})])}};_onHeartbeatPacket=()=>{this.send([A.createPacket(A.bidirectionalPackets.heartbeatPacketDefinition,null)],!0,!0)};_onMessage=(J)=>{try{let X=this._deserialize(J);if(!X)return;this.emitWithGlobal("CONNECTION.PACKET_RECEIVED",{connection:this,packet:X})}catch(X){E.error(`Connection._ws.onmessage(): Error: ${X}`)}};_onWrtcIceStateChange=(J,X)=>{if(["disconnected","closed"].includes(X)){if(J==this._wrtcClientServerTransport)this._closeWrtcClientServerTransport();else if(J==this._wrtcServerClientTransport)this._closeWrtcServerClientTransport()}};_onWsClose=()=>{this.closeWrtc(),this.emitWithGlobal("CONNECTION.CLOSED",{connection:this}),this.offAll()};_onWsError=(J)=>{this.emitWithGlobal("CONNECTION.ERROR",{connection:this,error:J})};_upgradeToWRTC=async()=>{let J=await i1.instance.createWrtcTransports();if(!J)return!1;let{directTransport:X,clientServerTransport:Y,serverClientTransport:Z}=J;this._wrtcDirectTransport=X,this._wrtcClientServerTransport=Y,this._wrtcClientServerTransport.on("icestatechange",(Q)=>{this._onWrtcIceStateChange(this._wrtcClientServerTransport,Q)}),this._wrtcServerClientTransport=Z,this._wrtcServerClientTransport.on("icestatechange",(Q)=>{this._onWrtcIceStateChange(this._wrtcServerClientTransport,Q)}),this._wrtcServerClientReliableDataProducer=await this._wrtcServerClientTransport.produceData({label:"scr",sctpStreamParameters:{streamId:0,ordered:!0}}),this._wrtcServerClientUnreliableDataProducer=await this._wrtcServerClientTransport.produceData({label:"scu",sctpStreamParameters:{streamId:1,ordered:!1,maxRetransmits:0}});let W=await this._wrtcServerClientTransport.consumeData({dataProducerId:this._wrtcServerClientReliableDataProducer.id}),$=await this._wrtcServerClientTransport.consumeData({dataProducerId:this._wrtcServerClientUnreliableDataProducer.id});return this._wrtcServerClientDataConsumers.push(W,$),this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{d:[{i:W.id,pi:W.dataProducerId,l:"scr",s:W.sctpStreamParameters},{i:$.id,pi:$.dataProducerId,l:"scu",s:$.sctpStreamParameters}],t:[{i:this._wrtcClientServerTransport.id,f:"cs",d:this._wrtcClientServerTransport.dtlsParameters,ic:this._wrtcClientServerTransport.iceCandidates,ip:this._wrtcClientServerTransport.iceParameters,s:this._wrtcClientServerTransport.sctpParameters},{i:this._wrtcServerClientTransport.id,f:"sc",d:this._wrtcServerClientTransport.dtlsParameters,ic:this._wrtcServerClientTransport.iceCandidates,ip:this._wrtcServerClientTransport.iceParameters,s:this._wrtcServerClientTransport.sctpParameters}]})]),!0};_deserialize(J){let X=X3(J);if(!X||typeof X!=="object"||typeof X[0]!=="number")return E.error(`Connection._deserialize(): Invalid packet format. Packet: ${JSON.stringify(X)}`);if(!A.isValidPacket(X))return E.error(`Connection._deserialize(): Invalid packet payload. Packet: ${JSON.stringify(X)}`);return X}}var xC;((Y)=>{Y.PLAYER_CONNECTED="PLAYER_MANAGER.PLAYER_CONNECTED";Y.PLAYER_DISCONNECTED="PLAYER_MANAGER.PLAYER_DISCONNECTED"})(xC||={});class j6{static instance=new j6;_connectionPlayers=new Map;constructor(){m8.on("CONNECTION.OPENED",({connection:J,req:X})=>{this._onConnectionOpened(J,X.session)}),m8.on("CONNECTION.CLOSED",({connection:J})=>{this._onConnectionClosed(J)})}getConnectedPlayers(){return Array.from(this._connectionPlayers.values())}getConnectedPlayersByWorld(J){return this.getConnectedPlayers().filter((X)=>X.world===J)}getConnectedPlayerByUsername(J){return Array.from(this._connectionPlayers.values()).find((X)=>{return X.username.toLowerCase()===J.toLowerCase()})}_onConnectionOpened(J,X){let Y=new r5(J,X);this._connectionPlayers.set(J,Y),m8.emit("PLAYER_MANAGER.PLAYER_CONNECTED",{player:Y})}_onConnectionClosed(J){let X=this._connectionPlayers.get(J);if(X)X.disconnect(),this._connectionPlayers.delete(J),m8.emit("PLAYER_MANAGER.PLAYER_DISCONNECTED",{player:X});else E.warning(`PlayerManager._onConnectionClosed(): Connection ${J.id} but was not in the PlayerManager._connectionPlayers map.`)}}var W$;((W)=>{W.DYNAMIC="dynamic";W.FIXED="fixed";W.KINEMATIC_POSITION="kinematic_position";W.KINEMATIC_VELOCITY="kinematic_velocity"})(W$||={});var zH=0.001,PC="dynamic";class f9 extends s{_additionalMass=0;_colliders=new Set;_explicitSleep=!1;_enabledPositions={x:!0,y:!0,z:!0};_enabledRotations={x:!0,y:!0,z:!0};_rigidBody;_rigidBodyDesc;_rigidBodyType;_simulation;constructor(J){super();J.type??=PC,this._rigidBodyDesc=this._createRigidBodyDesc(J),this._rigidBodyType=J.type,this._applyRigidBodyOptions(J),this._autoAddToSimulation(J)}get additionalMass(){if(!this._requireNotRemoved("additionalMass"))return 0;return this._additionalMass}get additionalSolverIterations(){if(!this._requireNotRemoved("additionalSolverIterations"))return 0;return this._rigidBody?this._rigidBody.additionalSolverIterations():this._rigidBodyDesc.additionalSolverIterations}get angularDamping(){if(!this._requireNotRemoved("angularDamping"))return 0;return this._rigidBody?this._rigidBody.angularDamping():this._rigidBodyDesc.angularDamping}get angularVelocity(){if(!this._requireNotRemoved("angularVelocity"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.angvel():this._rigidBodyDesc.angvel}get colliders(){return this._colliders}get dominanceGroup(){if(!this._requireNotRemoved("dominanceGroup"))return 0;return this._rigidBody?this._rigidBody.dominanceGroup():this._rigidBodyDesc.dominanceGroup}get directionFromRotation(){let{x:J,y:X,z:Y,w:Z}=this.rotation;return{x:2*(J*Y+Z*X),y:2*(X*Y-Z*J),z:1-2*(J*J+X*X)}}get effectiveAngularInertia(){if(!this._requireNotRemoved("effectiveAngularInertia"))return;return this._rigidBody?this._rigidBody.effectiveAngularInertia():void 0}get effectiveInverseMass(){if(!this._requireNotRemoved("effectiveInverseMass"))return;return this._rigidBody?this._rigidBody.effectiveInvMass():void 0}get effectiveWorldInversePrincipalAngularInertiaSqrt(){if(!this._requireNotRemoved("effectiveWorldInversePrincipalAngularInertiaSqrt"))return;return this._rigidBody?this._rigidBody.effectiveWorldInvInertiaSqrt():void 0}get enabledRotations(){if(!this._requireNotRemoved("enabledRotations"))return{x:!0,y:!0,z:!0};return this._enabledRotations}get enabledPositions(){if(!this._requireNotRemoved("enabledPositions"))return{x:!0,y:!0,z:!0};return this._enabledPositions}get gravityScale(){if(!this._requireNotRemoved("gravityScale"))return 0;return this._rigidBody?this._rigidBody.gravityScale():this._rigidBodyDesc.gravityScale}get inverseMass(){if(!this._requireNotRemoved("inverseMass"))return;return this._rigidBody?this._rigidBody.invMass():void 0}get inversePrincipalAngularInertiaSqrt(){if(!this._requireNotRemoved("inversePrincipalAngularInertiaSqrt"))return;return this._rigidBody?this._rigidBody.invPrincipalInertiaSqrt():void 0}get isCcdEnabled(){if(!this._requireNotRemoved("isCcdEnabled"))return!1;return this._rigidBody?this._rigidBody.isCcdEnabled():this._rigidBodyDesc.ccdEnabled}get isDynamic(){if(!this._requireNotRemoved("isDynamic"))return!1;return this._rigidBodyType==="dynamic"}get isEnabled(){if(!this._requireNotRemoved("isEnabled"))return!1;return this._rigidBody?this._rigidBody.isEnabled():this._rigidBodyDesc.enabled}get isFixed(){if(!this._requireNotRemoved("isFixed"))return!1;return this._rigidBodyType==="fixed"}get isKinematic(){if(!this._requireNotRemoved("isKinematic"))return!1;return["kinematic_position","kinematic_velocity"].includes(this._rigidBodyType)}get isKinematicPositionBased(){if(!this._requireNotRemoved("isKinematicPositionBased"))return!1;return this._rigidBodyType==="kinematic_position"}get isKinematicVelocityBased(){if(!this._requireNotRemoved("isKinematicVelocityBased"))return!1;return this._rigidBodyType==="kinematic_velocity"}get isMoving(){if(!this._requireNotRemoved("isMoving"))return!1;return this._rigidBody?this._rigidBody.isMoving():!1}get isRemoved(){return!this._rigidBody&&!this._rigidBodyDesc}get isSimulated(){if(!this._requireNotRemoved("isSimulated"))return!1;return this._rigidBody?!0:!1}get isSleeping(){if(!this._requireNotRemoved("isSleeping"))return!1;return this._rigidBody?this._rigidBody.isSleeping():this._rigidBodyDesc.sleeping}get linearDamping(){if(!this._requireNotRemoved("linearDamping"))return 0;return this._rigidBody?this._rigidBody.linearDamping():this._rigidBodyDesc.linearDamping}get linearVelocity(){if(!this._requireNotRemoved("linearVelocity"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.linvel():this._rigidBodyDesc.linvel}get localCenterOfMass(){if(!this._requireNotRemoved("localCenterOfMass"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.localCom():this._rigidBodyDesc.centerOfMass}get mass(){if(!this._requireNotRemoved("mass"))return 0;return this._rigidBody?this._rigidBody.mass():this._rigidBodyDesc.mass}get nextKinematicRotation(){if(!this._requireNotRemoved("nextKinematicRotation"))return{x:0,y:0,z:0,w:1};return this._rigidBody?this._rigidBody.nextRotation():this._rigidBodyDesc.rotation}get nextKinematicPosition(){if(!this._requireNotRemoved("nextKinematicPosition"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.nextTranslation():this._rigidBodyDesc.translation}get numColliders(){return this._colliders.size}get principalAngularInertia(){if(!this._requireNotRemoved("principalAngularInertia"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.principalInertia():this._rigidBodyDesc.principalAngularInertia}get principalAngularInertiaLocalFrame(){if(!this._requireNotRemoved("principalAngularInertiaLocalFrame"))return;return this._rigidBody?this._rigidBody.principalInertiaLocalFrame():void 0}get position(){if(!this._requireNotRemoved("position"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.translation():this._rigidBodyDesc.translation}get rawRigidBody(){if(!this._requireNotRemoved("rawRigidBody"))return;return this._rigidBody}get rotation(){if(!this._requireNotRemoved("rotation"))return{x:0,y:0,z:0,w:1};return this._rigidBody?this._rigidBody.rotation():this._rigidBodyDesc.rotation}get softCcdPrediction(){if(!this._requireNotRemoved("softCcdPrediction"))return 0;return this._rigidBody?this._rigidBody.softCcdPrediction():this._rigidBodyDesc.softCcdPrediction}get type(){if(!this._requireNotRemoved("type"))return"dynamic";return this._rigidBodyType}get worldCenterOfMass(){if(!this._requireNotRemoved("worldCenterOfMass"))return;return this._rigidBody?this._rigidBody.worldCom():void 0}setAdditionalMass(J){if(!this._requireDynamic("setAdditionalMass"))return;if(!this._requireNotRemoved("setAdditionalMass"))return;this._rigidBody?this._rigidBody.setAdditionalMass(J,!this._explicitSleep):this._rigidBodyDesc.setAdditionalMass(J)}setAdditionalMassProperties(J){if(!this._requireDynamic("setAdditionalMassProperties"))return;if(!this._requireNotRemoved("setAdditionalMassProperties"))return;let{additionalMass:X,centerOfMass:Y,principalAngularInertia:Z,principalAngularInertiaLocalFrame:W}=J;this._rigidBody?this._rigidBody.setAdditionalMassProperties(X,Y,Z,W,!this._explicitSleep):this._rigidBodyDesc.setAdditionalMassProperties(X,Y,Z,W)}setAdditionalSolverIterations(J){if(!this._requireDynamic("setAdditionalSolverIterations"))return;if(!this._requireNotRemoved("setAdditionalSolverIterations"))return;this._rigidBody?this._rigidBody.setAdditionalSolverIterations(J):this._rigidBodyDesc.setAdditionalSolverIterations(J)}setAngularDamping(J){if(!this._requireDynamic("setAngularDamping"))return;if(!this._requireNotRemoved("setAngularDamping"))return;this._rigidBody?this._rigidBody.setAngularDamping(J):this._rigidBodyDesc.setAngularDamping(J)}setAngularVelocity(J){if(!this._requireNotKinematicPositionBased("setAngularVelocity"))return;if(!this._requireNotRemoved("setAngularVelocity"))return;this._rigidBody?this._rigidBody.setAngvel(J,!this._explicitSleep):this._rigidBodyDesc.setAngvel(J)}setCcdEnabled(J){if(!this._requireDynamic("setCcdEnabled"))return;if(!this._requireNotRemoved("setCcdEnabled"))return;this._rigidBody?this._rigidBody.enableCcd(J):this._rigidBodyDesc.setCcdEnabled(J)}setDominanceGroup(J){if(!this._requireDynamic("setDominanceGroup"))return;if(!this._requireNotRemoved("setDominanceGroup"))return;this._rigidBody?this._rigidBody.setDominanceGroup(J):this._rigidBodyDesc.setDominanceGroup(J)}setEnabled(J){if(!this._requireNotRemoved("setEnabled"))return;this._rigidBody?this._rigidBody.setEnabled(J):this._rigidBodyDesc.setEnabled(J)}setEnabledPositions(J){if(!this._requireDynamic("setEnabledPositions"))return;if(!this._requireNotRemoved("setEnabledPositions"))return;this._rigidBody?this._rigidBody.setEnabledTranslations(J.x,J.y,J.z,!this._explicitSleep):this._rigidBodyDesc.enabledTranslations(J.x,J.y,J.z),this._enabledPositions=J}setEnabledRotations(J){if(!this._requireDynamic("setEnabledRotations"))return;if(!this._requireNotRemoved("setEnabledRotations"))return;this._rigidBody?this._rigidBody.setEnabledRotations(J.x,J.y,J.z,!this._explicitSleep):this._rigidBodyDesc.enabledRotations(J.x,J.y,J.z),this._enabledRotations=J}setGravityScale(J){if(!this._requireDynamic("setGravityScale"))return;if(!this._requireNotRemoved("setGravityScale"))return;this._rigidBody?this._rigidBody.setGravityScale(J,!this._explicitSleep):this._rigidBodyDesc.setGravityScale(J)}setLinearDamping(J){if(!this._requireDynamic("setLinearDamping"))return;if(!this._requireNotRemoved("setLinearDamping"))return;this._rigidBody?this._rigidBody.setLinearDamping(J):this._rigidBodyDesc.setLinearDamping(J)}setLinearVelocity(J){if(!this._requireNotKinematicPositionBased("setLinearVelocity"))return;if(!this._requireNotRemoved("setLinearVelocity"))return;this._rigidBody?this._rigidBody.setLinvel(J,!this._explicitSleep):this._rigidBodyDesc.setLinvel(J.x,J.y,J.z)}setNextKinematicRotation(J){if(!this._requireKinematic("setNextKinematicRotation"))return;if(!this._requireNotRemoved("setNextKinematicRotation"))return;this._rigidBody?this._rigidBody.setNextKinematicRotation(J):this._rigidBodyDesc.setRotation(J)}setNextKinematicPosition(J){if(!this._requireKinematic("setNextKinematicPosition"))return;if(!this._requireNotRemoved("setNextKinematicPosition"))return;this._rigidBody?this._rigidBody.setNextKinematicTranslation(J):this._rigidBodyDesc.setTranslation(J.x,J.y,J.z)}setPosition(J){if(!this._requireNotRemoved("setPosition"))return;this._rigidBody?this._rigidBody.setTranslation(J,!this._explicitSleep):this._rigidBodyDesc.setTranslation(J.x,J.y,J.z)}setRotation(J){if(!this._requireNotRemoved("setRotation"))return;this._rigidBody?this._rigidBody.setRotation(J,!this._explicitSleep):this._rigidBodyDesc.setRotation(J)}setSleeping(J){if(!this._requireDynamic("setSleeping"))return;if(!this._requireNotRemoved("setSleeping"))return;this._rigidBody?J?this._rigidBody.sleep():this._rigidBody.wakeUp():this._rigidBodyDesc.sleeping=J,this._explicitSleep=J}setSoftCcdPrediction(J){if(!this._requireDynamic("setSoftCcdPrediction"))return;if(!this._requireNotRemoved("setSoftCcdPrediction"))return;this._rigidBody?this._rigidBody.setSoftCcdPrediction(J):this._rigidBodyDesc.setSoftCcdPrediction(J)}setCollisionGroupsForSolidColliders(J){if(!this._requireNotRemoved("setCollisionGroupsForSolidColliders"))return;this._colliders.forEach((X)=>{if(X.isSensor)return;X.setCollisionGroups(J)})}setCollisionGroupsForSensorColliders(J){if(!this._requireNotRemoved("setCollisionGroupsForSensorColliders"))return;this._colliders.forEach((X)=>{if(!X.isSensor)return;X.setCollisionGroups(J)})}setType(J){if(!this._requireNotRemoved("setType"))return;let Y={["dynamic"]:z0.RigidBodyType.Dynamic,["fixed"]:z0.RigidBodyType.Fixed,["kinematic_position"]:z0.RigidBodyType.KinematicPositionBased,["kinematic_velocity"]:z0.RigidBodyType.KinematicVelocityBased}[J];if(Y===void 0)return E.error(`Invalid RigidBodyType: ${J}`);this._rigidBody?this._rigidBody.setBodyType(Y,!this._explicitSleep):this._rigidBodyDesc.status=Y,this._rigidBodyType=J}addForce(J){if(!this._requireNotRemoved("addForce"))return;if(!this._requireCreated("addForce"))return;if(!this._requireDynamic("addForce"))return;if(this._isNegligibleVector(J))return;this._rigidBody.addForce(J,!this._explicitSleep)}addTorque(J){if(!this._requireNotRemoved("addTorque"))return;if(!this._requireCreated("addTorque"))return;if(!this._requireDynamic("addTorque"))return;if(this._isNegligibleVector(J))return;this._rigidBody.addTorque(J,!this._explicitSleep)}addChildColliderToSimulation(J){if(!this._requireNotRemoved("addChildColliderToSimulation"))return;if(!this._requireCreated("addChildColliderToSimulation"))return;J.addToSimulation(this._simulation,this)}addToSimulation(J){if(!this._requireNotRemoved("addToSimulation"))return;if(this._rigidBody)return E.error("RigidBody.addToSimulation(): Rigid body already exists in the simulation!");this._simulation=J,this._rigidBody=this._simulation.createRawRigidBody(this._rigidBodyDesc),this._colliders.forEach((X)=>{if(!X.isSimulated)X.addToSimulation(J,this)})}applyImpulse(J){if(!this._requireNotRemoved("applyImpulse"))return;if(!this._requireCreated("applyImpulse"))return;if(!this._requireDynamic("applyImpulse"))return;if(this._isNegligibleVector(J))return;this._rigidBody.applyImpulse(J,!this._explicitSleep)}applyImpulseAtPoint(J,X){if(!this._requireNotRemoved("applyImpulseAtPoint"))return;if(!this._requireCreated("applyImpulseAtPoint"))return;if(!this._requireDynamic("applyImpulseAtPoint"))return;if(this._isNegligibleVector(J))return;this._rigidBody.applyImpulseAtPoint(J,X,!this._explicitSleep)}applyTorqueImpulse(J){if(!this._requireNotRemoved("applyTorqueImpulse"))return;if(!this._requireCreated("applyTorqueImpulse"))return;if(!this._requireDynamic("applyTorqueImpulse"))return;this._rigidBody.applyTorqueImpulse(J,!this._explicitSleep)}createAndAddChildCollider(J){if(!this._requireNotRemoved("createAndAddChildCollider"))return null;return this._simulation?new d8({...J,parentRigidBody:this,simulation:this._simulation}):this._createAndAddPendingChildCollider(J)}createAndAddChildCollidersToSimulation(J){let X=[];return J.forEach((Y)=>{let Z=this.createAndAddChildCollider(Y);if(Z)X.push(Z)}),X}getCollidersByTag(J){let X=[];for(let Y of this._colliders)if(Y.tag===J)X.push(Y);return X}linkCollider(J){if(!this._requireNotRemoved("linkCollider"))return;if(J.parentRigidBody!==this)return E.error("RigidBody.linkCollider(): Collider cannot be linked because it is not a child of this rigid body!");this._colliders.add(J)}lockAllRotations(){if(!this._requireNotRemoved("lockAllRotations"))return;this.setEnabledRotations({x:!1,y:!1,z:!1})}lockAllPositions(){if(!this._requireNotRemoved("lockAllPositions"))return;this.setEnabledPositions({x:!1,y:!1,z:!1})}removeFromSimulation(){if(!this._requireNotRemoved("removeFromSimulation"))return;if(!this._rigidBody)return E.error("RigidBody.removeFromSimulation(): Rigid body does not exist in the simulation!");this._colliders.forEach((J)=>{J.removeFromSimulation()}),this._simulation.removeRawRigidBody(this._rigidBody),this._simulation=void 0,this._rigidBody=void 0}unlinkCollider(J){if(!this._requireNotRemoved("unlinkCollider"))return;if(!J.isRemoved)return E.error("RigidBody.unlinkCollider(): Collider is still simulated and therefore cannot be unlinked from this rigid body!");this._colliders.delete(J)}resetAngularVelocity(){if(!this._requireNotRemoved("resetAngularVelocity"))return;if(!this._requireCreated("resetAngularVelocity"))return;this.setAngularVelocity({x:0,y:0,z:0})}resetForces(){if(!this._requireNotRemoved("resetForces"))return;if(!this._requireCreated("resetForces"))return;this._rigidBody.resetForces(!this._explicitSleep)}resetLinearVelocity(){if(!this._requireNotRemoved("resetLinearVelocity"))return;if(!this._requireCreated("resetLinearVelocity"))return;this.setLinearVelocity({x:0,y:0,z:0})}resetTorques(){if(!this._requireNotRemoved("resetTorques"))return;if(!this._requireCreated("resetTorques"))return;this._rigidBody.resetTorques(!this._explicitSleep)}sleep(){if(!this._requireNotRemoved("sleep"))return;this.setSleeping(!0)}wakeUp(){if(!this._requireNotRemoved("wakeUp"))return;this.setSleeping(!1)}_applyRigidBodyOptions(J){[["additionalMass",this.setAdditionalMass.bind(this)],["additionalMassProperties",this.setAdditionalMassProperties.bind(this)],["additionalSolverIterations",this.setAdditionalSolverIterations.bind(this)],["angularDamping",this.setAngularDamping.bind(this)],["angularVelocity",this.setAngularVelocity.bind(this)],["dominanceGroup",this.setDominanceGroup.bind(this)],["ccdEnabled",this.setCcdEnabled.bind(this)],["enabled",this.setEnabled.bind(this)],["enabledPositions",this.setEnabledPositions.bind(this)],["enabledRotations",this.setEnabledRotations.bind(this)],["gravityScale",this.setGravityScale.bind(this)],["linearDamping",this.setLinearDamping.bind(this)],["linearVelocity",this.setLinearVelocity.bind(this)],["position",this.setPosition.bind(this)],["rotation",this.setRotation.bind(this)],["sleeping",this.setSleeping.bind(this)],["softCcdPrediction",this.setSoftCcdPrediction.bind(this)]].forEach(([Y,Z])=>{if(Y in J)Z(J[Y])})}_autoAddToSimulation(J){if(J.colliders)this._createAndAddPendingChildColliders(J.colliders);if(J.simulation)this.addToSimulation(J.simulation)}_createAndAddPendingChildCollider(J){if(!this._requireNotRemoved("createAndAddPendingChildCollider"))return null;if(!this._requireNotSimulated("createAndAddPendingChildCollider"))return null;let X=new d8(J);return this._colliders.add(X),X}_createAndAddPendingChildColliders(J){let X=[];return J.forEach((Y)=>{let Z=this._createAndAddPendingChildCollider(Y);if(Z)X.push(Z)}),X}_createRigidBodyDesc(J){let X=J.type??PC;return{["dynamic"]:()=>z0.RigidBodyDesc.dynamic(),["fixed"]:()=>z0.RigidBodyDesc.fixed(),["kinematic_position"]:()=>z0.RigidBodyDesc.kinematicPositionBased(),["kinematic_velocity"]:()=>z0.RigidBodyDesc.kinematicVelocityBased()}[X]()}_requireCreated(J){if(!this._rigidBody||!this._simulation)E.error(`RigidBody._requireCreated(): Rigid body has not been created and therefore does not support the invoked method: ${J}()`);return!!this._rigidBody&&!!this._simulation}_requireDynamic(J){if(!this.isDynamic)E.error(`RigidBody._requireDynamic(): Rigid body is not dynamic and therefore does not support the invoked method: ${J}()`);return this.isDynamic}_requireKinematic(J){if(!this.isKinematic)E.error(`RigidBody._requireKinematic(): Rigid body is not kinematic and therefore does not support the invoked method: ${J}()`);return this.isKinematic}_requireNotKinematicPositionBased(J){if(this.isKinematicPositionBased)E.error(`RigidBody._requireNotKinematicPositionBased(): Rigid body is kinematic position based and therefore does not support the invoked method: ${J}()`);return!this.isKinematicPositionBased}_requireNotRemoved(J){if(!this._rigidBody&&!this._rigidBodyDesc)E.error(`RigidBody._requireNotRemoved(): Rigid body has been removed and therefore does not support the invoked method: ${J}()`);return!!this._rigidBody||!!this._rigidBodyDesc}_requireNotSimulated(J){if(this.isSimulated)E.error(`RigidBody._requireNotSimulated(): Rigid body is simulated and therefore does not support the invoked method: ${J}()`);return!this.isSimulated}_isNegligibleVector(J){return Math.abs(J.x)<zH&&Math.abs(J.y)<zH&&Math.abs(J.z)<zH}}var n0=16,t5=n0-1,NC=n0**3,lX0=[{neighborOffset:[-1,0,0],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+0,X+0,Y+1,J+0,X+1,Y+0,J+0,X+1,Y+0,J+0,X+0,Y+1,J+0,X+1,Y+1]},{neighborOffset:[1,0,0],generateVertices:(J,X,Y)=>[J+1,X+0,Y+0,J+1,X+1,Y+0,J+1,X+0,Y+1,J+1,X+1,Y+0,J+1,X+1,Y+1,J+1,X+0,Y+1]},{neighborOffset:[0,-1,0],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+1,X+0,Y+0,J+0,X+0,Y+1,J+1,X+0,Y+0,J+1,X+0,Y+1,J+0,X+0,Y+1]},{neighborOffset:[0,1,0],generateVertices:(J,X,Y)=>[J+0,X+1,Y+0,J+0,X+1,Y+1,J+1,X+1,Y+0,J+1,X+1,Y+0,J+0,X+1,Y+1,J+1,X+1,Y+1]},{neighborOffset:[0,0,-1],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+0,X+1,Y+0,J+1,X+0,Y+0,J+0,X+1,Y+0,J+1,X+1,Y+0,J+1,X+0,Y+0]},{neighborOffset:[0,0,1],generateVertices:(J,X,Y)=>[J+0,X+0,Y+1,J+1,X+0,Y+1,J+0,X+1,Y+1,J+0,X+1,Y+1,J+1,X+0,Y+1,J+1,X+1,Y+1]}],LH;((Z)=>{Z.DESPAWN="CHUNK.DESPAWN";Z.SET_BLOCK="CHUNK.SET_BLOCK";Z.SPAWN="CHUNK.SPAWN"})(LH||={});class w8 extends s{_blocks;_originCoordinate;_requiresUpdate=!1;_rigidBody;_world;constructor(){super();this._blocks=new Uint8Array(NC)}get blocks(){return this._blocks}get requiresUpdate(){return this._requiresUpdate}get isSimulated(){return!!this._rigidBody}get isSpawned(){return!!this._originCoordinate&&!!this._world}get originCoordinate(){return this._originCoordinate}get world(){return this._world}static blockIndexToLocalCoordinate(J){return{x:J%n0,y:(J/n0|0)%n0,z:J/(n0*n0)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&n0-1,y:J.y&n0-1,z:J.z&n0-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(n0-1),y:J.y&~(n0-1),z:J.z&~(n0-1)}}static isValidOriginCoordinate(J){return J.x%n0===0&&J.y%n0===0&&J.z%n0===0}spawn(J,X){if(this.isSpawned){let{x:Y,y:Z,z:W}=this.originCoordinate;return E.error(`Chunk.spawn(): Chunk is already spawned at origin ${Y}, ${Z}, ${W}!`)}if(!w8.isValidOriginCoordinate(X))return E.error(`Chunk.spawn(): Chunk coordinates must be divisible by ${n0}`);this._originCoordinate=X,this._world=J,this._world.chunkLattice.registerChunk(this),this._requiresUpdate=!0}despawn(){if(!this.isSpawned)return E.error("Chunk.despawn(): Chunk has not been spawned and cannot be despawned!");this.emitWithWorld(this._world,"CHUNK.DESPAWN",{chunk:this}),this._removeFromSimulation(),this._world.chunkLattice.unregisterChunk(this),this._originCoordinate=void 0,this._world=void 0}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,X){if(!this._isValidLocalCoordinate(J))return E.error("Chunk.setBlock(): Block local coordinate is out of bounds");if(this._blocks[this._getIndex(J)]===X)return;if(this._blocks[this._getIndex(J)]=X,this.isSpawned&&this.isSimulated){this.emitWithWorld(this._world,"CHUNK.SET_BLOCK",{chunk:this,globalCoordinate:this._getGlobalCoordinate(J),localCoordinate:J,blockTypeId:X});let Y=this._getGlobalCoordinate(J),Z=[];if(J.x===0)Z.push({x:-1,y:0,z:0});if(J.y===0)Z.push({x:0,y:-1,z:0});if(J.z===0)Z.push({x:0,y:0,z:-1});if(J.x===t5)Z.push({x:1,y:0,z:0});if(J.y===t5)Z.push({x:0,y:1,z:0});if(J.z===t5)Z.push({x:0,y:0,z:1});for(let W of Z){let $={x:Y.x+W.x,y:Y.y+W.y,z:Y.z+W.z},Q=w8.globalCoordinateToOriginCoordinate($),K=this._world?.chunkLattice.getChunk(Q);if(!K?.hasBlock(w8.globalCoordinateToLocalCoordinate($)))continue;K.setRequiresUpdate(!0)}}this._requiresUpdate=!0}setRequiresUpdate(J){this._requiresUpdate=J}update(){if(!this._requiresUpdate)return;if(!this.isSpawned)return E.error("Chunk.update(): Chunk is not spawned and cannot be updated.");let J=!this._rigidBody,X=this._world.simulation;if(this._removeFromSimulation(),this._rigidBody=new f9({type:"fixed",position:this._originCoordinate,simulation:this._world.simulation}),this._meshColliders().map(([Y,Z])=>{if(!Y.isSimulated)Y.addToSimulation(X,this._rigidBody);X.colliderMap.setColliderBlockType(Y,Z)}),this._requiresUpdate=!1,J)this.emitWithWorld(this._world,"CHUNK.SPAWN",{chunk:this})}serialize(){return t.serializeChunk(this)}_meshColliders(){if(!this._world)return E.error("Chunk._meshColliders(): Chunk is not spawned and cannot be meshed."),[];let J=new Map,X=[];for(let Z=0;Z<NC;Z++){if(this._blocks[Z]===0)continue;let W=this._blocks[Z],$=this._world.blockTypeRegistry.getBlockType(W),{x:Q,y:K,z:G}=w8.blockIndexToLocalCoordinate(Z);if(!$.isMeshable){let q=$.createCollider();q.setRelativePosition({x:Q,y:K,z:G}),X.push([q,$]);continue}let F=J.get($)??{indices:[],vertices:[]};J.set($,F);for(let q of lX0){let[H,z,V]=q.neighborOffset,M={x:Q+H,y:K+z,z:G+V},R=this._getGlobalCoordinate(M),L=this._world.chunkLattice.getBlockType(R);if(L&&!L.isLiquid)continue;let w=F.indices.length;F.indices.push(w,w+1,w+2,w+3,w+4,w+5),F.vertices.push(...q.generateVertices(Q,K,G))}}let Y=[];return J.forEach((Z,W)=>{if(!Z.indices.length)return;let $=W.createCollider(new Uint32Array(Z.indices),new Float32Array(Z.vertices));Y.push([$,W])}),[...X,...Y]}_removeFromSimulation(){if(!this._rigidBody||!this._world)return;this._rigidBody.removeFromSimulation(),this._rigidBody=void 0}_getGlobalCoordinate(J){if(!this.originCoordinate)E.fatalError("Chunk._getGlobalCoordinate(): Chunk is not spawned, calculating global coordinate is impossible.");return{x:this.originCoordinate.x+J.x,y:this.originCoordinate.y+J.y,z:this.originCoordinate.z+J.z}}_getIndex(J){return J.x+n0*(J.y+n0*J.z)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=t5&&J.y>=0&&J.y<=t5&&J.z>=0&&J.z<=t5}}class PJ{_chunks=new Map;_world;constructor(J){this._world=J}registerChunk(J){if(!J.isSpawned)return E.error("ChunkLattice.registerChunk(): Chunk is not spawned.");if(this.hasChunk(J.originCoordinate)){let{x:X,y:Y,z:Z}=J.originCoordinate;return E.error(`ChunkLattice.registerChunk(): Chunk exists at origin (${X}, ${Y}, ${Z}), despawn the current chunk before registering another at the same origin.`)}if(J.world.id!==this._world.id)return E.error("ChunkLattice.registerChunk(): Chunk world does not match lattice world.");this._chunks.set(this._getChunkKey(J.originCoordinate),J)}unregisterChunk(J){if(!J.isSpawned)return E.error("ChunkLattice.unregisterChunk(): Chunk is not spawned.");if(J.world.id!==this._world.id)return E.error("ChunkLattice.unregisterChunk(): Chunk world does not match lattice world.");this._chunks.delete(this._getChunkKey(J.originCoordinate))}getBlockId(J){let X=this.getChunk(w8.globalCoordinateToOriginCoordinate(J));if(!X)return 0;return X.getBlockId(w8.globalCoordinateToLocalCoordinate(J))}getBlockType(J){let X=this.getBlockId(J);return X?this._world.blockTypeRegistry.getBlockType(X):null}getChunk(J){if(!w8.isValidOriginCoordinate(J)){E.error(`ChunkLattice.getChunk(): Chunk coordinates must be divisible by CHUNK_SIZE (${n0})`);return}return this._chunks.get(this._getChunkKey(J))}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let X=this.getChunk(w8.globalCoordinateToOriginCoordinate(J));if(!X)return!1;return X.hasBlock(w8.globalCoordinateToLocalCoordinate(J))}hasChunk(J){return this._chunks.has(this._getChunkKey(J))}setBlock(J,X){let Y=w8.globalCoordinateToLocalCoordinate(J),Z=w8.globalCoordinateToOriginCoordinate(J),W=this.getChunk(Z);if(!W)W=new w8,W.spawn(this._world,Z);W.setBlock(Y,X)}updateChunks(){this._chunks.forEach((J)=>{if(J.requiresUpdate)J.update()})}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}}var vC={type:"dynamic",softCcdPrediction:1},BC=0.0025000000000000005,jC=Math.cos(0.005),$$;((w)=>{w.BLOCK_COLLISION="ENTITY.BLOCK_COLLISION";w.BLOCK_CONTACT_FORCE="ENTITY.BLOCK_CONTACT_FORCE";w.DESPAWN="ENTITY.DESPAWN";w.ENTITY_COLLISION="ENTITY.ENTITY_COLLISION";w.ENTITY_CONTACT_FORCE="ENTITY.ENTITY_CONTACT_FORCE";w.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";w.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";w.SET_OPACITY="ENTITY.SET_OPACITY";w.SET_PARENT="ENTITY.SET_PARENT";w.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";w.SPAWN="ENTITY.SPAWN";w.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";w.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";w.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";w.TICK="ENTITY.TICK";w.UPDATE_POSITION="ENTITY.UPDATE_POSITION";w.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})($$||={});class Y8 extends f9{_id;_blockHalfExtents;_blockTextureUri;_controller;_modelAnimationsPlaybackRate=1;_modelHiddenNodes=new Set;_modelLoopedAnimations=new Set;_modelOneshotAnimations=new Set;_modelScale;_modelUri;_name;_opacity;_parent;_parentNodeName;_tag;_tintColor;_lastUpdatedPosition={x:0,y:0,z:0};_lastUpdatedRotation={x:0,y:0,z:0,w:1};_lastParentlessType="dynamic";_world;constructor(J){let X="blockTextureUri"in J,Y="modelUri"in J;if(!X===!Y)E.fatalError("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if(X&&!J.blockHalfExtents)E.fatalError("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)E.fatalError("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!U6.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))E.fatalError(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??vC);if(X)this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri;if(Y)this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelScale=J.modelScale,this._modelUri=J.modelUri,J.modelHiddenNodes?.forEach((Z)=>this._modelHiddenNodes.add(Z.toLowerCase())),J.modelLoopedAnimations?.forEach((Z)=>this._modelLoopedAnimations.add(Z));if(this._name=J.name??"Nameless",this._opacity=J.opacity??1,this._parent=J.parent,this._parentNodeName=J.parentNodeName,this._tag=J.tag,this._tintColor=J.tintColor,J.controller)this.setController(J.controller)}get id(){return this._id}get blockHalfExtents(){return this._blockHalfExtents}get blockTextureUri(){return this._blockTextureUri}get controller(){return this._controller}get height(){return this.isModelEntity?U6.instance.getHeight(this._modelUri)*(this._modelScale??1):this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelScale(){return this._modelScale}get modelUri(){return this._modelUri}get name(){return this._name}get opacity(){return this._opacity}get parent(){return this._parent}get parentNodeName(){return this._parentNodeName}get tag(){return this._tag}get tintColor(){return this._tintColor}get isBlockEntity(){return!!this._blockTextureUri}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get world(){return this._world}spawn(J,X,Y){if(this.isSpawned)return E.error(`Entity.spawn(): Entity ${this._name} is already spawned with id ${this._id}!`);if(!this.isSimulated)this.addToSimulation(J.simulation);if(this._blockTextureUri&&this._blockHalfExtents&&this.numColliders===0)this.addChildColliderToSimulation(new d8(d8.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0)this.addChildColliderToSimulation(new d8(d8.optionsFromModelUri(this._modelUri,this._modelScale)));if(this.colliders.forEach((Z)=>{if(this.hasListeners("ENTITY.BLOCK_COLLISION")||this.hasListeners("ENTITY.ENTITY_COLLISION"))Z.enableCollisionEvents(!0);if(this.hasListeners("ENTITY.BLOCK_CONTACT_FORCE")||this.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))Z.enableContactForceEvents(!0);if(q6.isDefaultCollisionGroups(Z.collisionGroups))Z.setCollisionGroups({belongsTo:[Z.isSensor?4:2],collidesWith:[65535]})}),this.setPosition(X),Y)this.setRotation(Y);if(this._id=J.entityManager.registerEntity(this),this._world=J,this._controller)this._controller.spawn(this);if(this._parent)this.setParent(this._parent,this._parentNodeName,X,Y);this.colliders.forEach((Z)=>{J.simulation.colliderMap.setColliderEntity(Z,this)}),this.emitWithWorld(J,"ENTITY.SPAWN",{entity:this})}despawn(){if(!this._requireSpawned("despawn"))return;if(this._world.entityManager.getEntityChildren(this).forEach((J)=>{J.despawn()}),this._controller)this._controller.detach(this),this._controller.despawn(this);if(this.emitWithWorld(this._world,"ENTITY.DESPAWN",{entity:this}),this.isSimulated)this.removeFromSimulation();this._world.entityManager.unregisterEntity(this),this._world.audioManager.unregisterEntityAttachedAudios(this),this._world.lightManager.despawnEntityAttachedLights(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setModelAnimationsPlaybackRate(J){if(!this._requireSpawned("setModelAnimationsPlaybackRate"))return;if(!this.isModelEntity||this._modelAnimationsPlaybackRate===J)return;this._modelAnimationsPlaybackRate=J,this.emitWithWorld(this._world,"ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",{entity:this,playbackRate:J})}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}setModelHiddenNodes(J){if(!this._requireSpawned("setModelHiddenNodes"))return;this._modelHiddenNodes=new Set(J.map((X)=>X.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setOpacity(J){if(!this._requireSpawned("setOpacity"))return;if(this._opacity===J)return;this._opacity=J,this.emitWithWorld(this._world,"ENTITY.SET_OPACITY",{entity:this,opacity:J})}setParent(J,X,Y,Z){if(!this._requireSpawned("setParent"))return;if(J&&!J.isSpawned)return E.error("Entity.setParent(): Parent entity is not spawned, cannot set parent!");if(!this._parent&&J)this._lastParentlessType=this.type;if(this._parent=J,this._parentNodeName=X,this.colliders.forEach((W)=>W.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(Y??{x:0,y:0,z:0}),this.setRotation(Z??{x:0,y:0,z:0,w:1}),!this.isKinematicPositionBased)this.resetAngularVelocity(),this.resetForces(),this.resetLinearVelocity(),this.resetTorques();this.emitWithWorld(this._world,"ENTITY.SET_PARENT",{entity:this,parent:J,parentNodeName:X})}setTintColor(J){if(!this._requireSpawned("setTintColor"))return;if(!J&&!this._tintColor||J&&this._tintColor&&J.r===this._tintColor.r&&J.g===this._tintColor.g&&J.b===this._tintColor.b)return;this._tintColor=J,this.emitWithWorld(this._world,"ENTITY.SET_TINT_COLOR",{entity:this,tintColor:J})}startModelLoopedAnimations(J){if(!this._requireSpawned("startModelLoopedAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some((X)=>!this._modelLoopedAnimations.has(X)))return;J.forEach((X)=>{this._modelLoopedAnimations.add(X)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_LOOPED_ANIMATIONS",{entity:this,animations:new Set(J)})}startModelOneshotAnimations(J){if(!this._requireSpawned("startModelOneshotAnimations"))return;if(!this.isModelEntity||!J.length)return;J.forEach((X)=>{this._modelOneshotAnimations.add(X)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopModelAnimations(J){if(!this._requireSpawned("stopModelAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some((X)=>this._modelLoopedAnimations.has(X))&&!J.some((X)=>this._modelOneshotAnimations.has(X)))return;J.forEach((X)=>{this._modelLoopedAnimations.delete(X),this._modelOneshotAnimations.delete(X)}),this.emitWithWorld(this._world,"ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return t.serializeEntity(this)}tick(J){if(this.emit("ENTITY.TICK",{entity:this,tickDeltaMs:J}),this._controller)this._controller.tick(this,J)}checkAndEmitUpdates(){if(!this._requireSpawned("checkAndEmitUpdates"))return;let J=this.position,X=this.rotation;if(this._rotationExceedsThreshold(X,this._lastUpdatedRotation))this._lastUpdatedRotation=X,this.emitWithWorld(this._world,"ENTITY.UPDATE_ROTATION",{entity:this,rotation:X});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this.emitWithWorld(this._world,"ENTITY.UPDATE_POSITION",{entity:this,position:J})}_requireSpawned(J){if(!this.isSpawned)E.error(`Entity._requireSpawned(): Entity ${this._name} is not spawned, cannot invoke ${J}()!`);return this.isSpawned}_positionExceedsThreshold(J,X){let Y=J.x-X.x,Z=J.y-X.y,W=J.z-X.z;return Y*Y+Z*Z+W*W>BC}_rotationExceedsThreshold(J,X){return Math.abs(J.x*X.x+J.y*X.y+J.z*X.z+J.w*X.w)<jC}}class NJ extends a1{autoCancelMouseLeftClick=!0;canWalk=()=>!0;canRun=()=>!0;canJump=()=>!0;idleLoopedAnimations=["idle_upper","idle_lower"];interactOneshotAnimations=["simple_interact"];jumpOneshotAnimations=["jump_loop"];jumpVelocity=10;runLoopedAnimations=["run_upper","run_lower"];runVelocity=8;sticksToPlatforms=!0;walkLoopedAnimations=["walk_upper","walk_lower"];walkVelocity=4;_stepAudio;_groundContactCount=0;_platform;constructor(J={}){super();this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.canWalk=J.canWalk??this.canWalk,this.canRun=J.canRun??this.canRun,this.canJump=J.canJump??this.canJump,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get platform(){return this._platform}attach(J){this._stepAudio=new $4({uri:"audio/sfx/step/stone/stone-step-04.mp3",loop:!0,volume:0.1,referenceDistance:2,cutoffDistance:15,attachedToEntity:J}),J.setCcdEnabled(!0),J.lockAllRotations()}spawn(J){if(!J.isSpawned)return E.error("PlayerEntityController.createColliders(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:0.23,halfHeight:0.125,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},isSensor:!0,relativePosition:{x:0,y:-0.75,z:0},tag:"groundSensor",onCollision:(X,Y)=>{if(!J.isSpawned)return;if(this._groundContactCount+=Y?1:-1,!this._groundContactCount)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!(X instanceof Y8)||!X.isKinematic)return;if(Y&&this.sticksToPlatforms)this._platform=X;else if(X===this._platform&&!Y)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:0.33,radius:0.4,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,X,Y,Z){if(!J.isSpawned||!J.world)return;if(super.tickWithPlayerInput(J,X,Y,Z),J.parent)return;let{w:W,a:$,s:Q,d:K,sp:G,sh:F,ml:q}=X,{yaw:H}=Y,z=J.linearVelocity,V={x:0,y:0,z:0},M=F;if(this.isGrounded&&(W||$||Q||K)){if(M)J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.runLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.runLoopedAnimations),this._stepAudio?.setPlaybackRate(0.75);else J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.walkLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.walkLoopedAnimations),this._stepAudio?.setPlaybackRate(0.51);this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else this._stepAudio?.pause(),J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.idleLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.idleLoopedAnimations);if(q)J.startModelOneshotAnimations(this.interactOneshotAnimations),X.ml=!this.autoCancelMouseLeftClick;if(M&&this.canRun(this)||!M&&this.canWalk(this)){let P=M?this.runVelocity:this.walkVelocity;if(W)V.x-=P*Math.sin(H),V.z-=P*Math.cos(H);if(Q)V.x+=P*Math.sin(H),V.z+=P*Math.cos(H);if($)V.x-=P*Math.cos(H),V.z+=P*Math.sin(H);if(K)V.x+=P*Math.cos(H),V.z-=P*Math.sin(H);let N=Math.sqrt(V.x*V.x+V.z*V.z);if(N>P){let v=P/N;V.x*=v,V.z*=v}}if(G&&this.canJump(this)){if(this.isGrounded&&z.y>-0.001&&z.y<=3)V.y=this.jumpVelocity}let R=this._platform?this._platform.linearVelocity:{x:0,y:0,z:0},L={x:V.x-z.x+R.x,y:V.y+R.y,z:V.z-z.z+R.z};if(!(this.runVelocity>0&&Math.abs(z.x)>this.runVelocity||this.jumpVelocity>0&&Math.abs(z.y)>this.jumpVelocity||this.runVelocity>0&&Math.abs(z.z)>this.runVelocity)||this.isOnPlatform){if(Object.values(L).some((P)=>P!==0)){let P=J.mass;J.applyImpulse({x:L.x*P,y:L.y*P,z:L.z*P})}}if(H!==void 0){let P=H/2;J.setRotation({x:0,y:Math.fround(Math.sin(P)),z:0,w:Math.fround(Math.cos(P))})}}}var UH;((K)=>{K.LOAD="SCENE_UI.LOAD";K.SET_ATTACHED_TO_ENTITY="SCENE_UI.SET_ATTACHED_TO_ENTITY";K.SET_OFFSET="SCENE_UI.SET_OFFSET";K.SET_POSITION="SCENE_UI.SET_POSITION";K.SET_STATE="SCENE_UI.SET_STATE";K.SET_VIEW_DISTANCE="SCENE_UI.SET_VIEW_DISTANCE";K.UNLOAD="SCENE_UI.UNLOAD"})(UH||={});class vJ extends s{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)E.fatalError("Either attachedToEntity or position must be set, but not both");super();this._attachedToEntity=J.attachedToEntity,this._offset=J.offset,this._position=J.position,this._state=J.state??{},this._templateId=J.templateId,this._viewDistance=J.viewDistance}get id(){return this._id}get attachedToEntity(){return this._attachedToEntity}get isLoaded(){return this._id!==void 0}get offset(){return this._offset}get position(){return this._position}get state(){return this._state}get templateId(){return this._templateId}get viewDistance(){return this._viewDistance}get world(){return this._world}load(J){if(this.isLoaded)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return E.error(`SceneUI.load(): Attached entity ${this._attachedToEntity.id} must be spawned before loading SceneUI!`);this._id=J.sceneUIManager.registerSceneUI(this),this._world=J,this.emitWithWorld(J,"SCENE_UI.LOAD",{sceneUI:this})}setAttachedToEntity(J){if(!J.isSpawned)return E.error(`SceneUI.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_ATTACHED_TO_ENTITY",{sceneUI:this,entity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_OFFSET",{sceneUI:this,offset:J})}setPosition(J){if(this._position===J)return;if(this._attachedToEntity=void 0,this._position=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_POSITION",{sceneUI:this,position:J})}setState(J){if(this._state={...this._state,...J},this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_STATE",{sceneUI:this,state:this._state})}setViewDistance(J){if(this._viewDistance=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_VIEW_DISTANCE",{sceneUI:this,viewDistance:J})}unload(){if(!this.isLoaded||!this._world)return;this._world.sceneUIManager.unregisterSceneUI(this),this.emitWithWorld(this._world,"SCENE_UI.UNLOAD",{sceneUI:this}),this._id=void 0,this._world=void 0}serialize(){return t.serializeSceneUI(this)}}class n1 extends Y8{player;nametagSceneUI;constructor(J){super(J);if(this.player=J.player,this.nametagSceneUI=new vJ({templateId:"hytopia:nametag",attachedToEntity:this,offset:{x:0,y:1,z:0},viewDistance:15,state:{username:this.player.username,profilePictureUrl:this.player.profilePictureUrl}}),!J.controller)this.setController(new NJ)}spawn(J,X,Y){super.spawn(J,X,Y),this.nametagSceneUI.load(J),this.player.on("PLAYER.CHAT_MESSAGE_SEND",({message:Z})=>{this.nametagSceneUI.setState({chat:Z})})}tick(J){if(!this.isSpawned||!this.world||!this.controller)return;let{input:X,camera:Y}=this.player;this.controller.tickWithPlayerInput(this,X,Y.orientation,J),super.tick(J)}}class jJ{_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get world(){return this._world}registerEntity(J){if(J.id!==void 0)E.fatalError(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let X=this._nextEntityId;return this._entities.set(X,J),this._nextEntityId++,X}unregisterEntity(J){if(J.id===void 0)return E.error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);this._entities.delete(J.id)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach((X)=>{if(X instanceof n1)J.push(X)}),J}getPlayerEntitiesByPlayer(J){let X=[];return this._entities.forEach((Y)=>{if(Y instanceof n1&&Y.player===J)X.push(Y)}),X}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let X=[];return this._entities.forEach((Y)=>{if(Y.tag===J)X.push(Y)}),X}getEntitiesByTagSubstring(J){let X=[];return this._entities.forEach((Y)=>{if(Y.tag?.includes(J))X.push(Y)}),X}getEntityChildren(J){let X=[];return this._entities.forEach((Y)=>{if(Y.parent===J)X.push(Y)}),X}tickEntities(J){this._entities.forEach((X)=>{X.tick(J)})}checkAndEmitUpdates(){this._entities.forEach((J)=>{if(!J.isSpawned)return;J.checkAndEmitUpdates()})}}class kJ{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach((X)=>{X.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter((X)=>X.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let X=this._nextLightId;return this._lights.set(X,J),this._nextLightId++,X}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}var kC;((Y)=>{Y[Y.POINTLIGHT=0]="POINTLIGHT";Y[Y.SPOTLIGHT=1]="SPOTLIGHT"})(kC||={});var VH;((z)=>{z.DESPAWN="LIGHT.DESPAWN";z.SET_ANGLE="LIGHT.SET_ANGLE";z.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";z.SET_COLOR="LIGHT.SET_COLOR";z.SET_DISTANCE="LIGHT.SET_DISTANCE";z.SET_INTENSITY="LIGHT.SET_INTENSITY";z.SET_OFFSET="LIGHT.SET_OFFSET";z.SET_PENUMBRA="LIGHT.SET_PENUMBRA";z.SET_POSITION="LIGHT.SET_POSITION";z.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";z.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";z.SPAWN="LIGHT.SPAWN"})(VH||={});class MH extends s{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)E.fatalError("Either attachedToEntity or position must be set, but not both");super();E.warning("WARNING: Lights are poorly optimized at this time. Using more than a few lights in your game can cause extremely bad performance (FPS) issues. Use lights sparingly!"),this._angle=J.angle,this._attachedToEntity=J.attachedToEntity,this._color=J.color??{r:255,g:255,b:255},this._distance=J.distance,this._intensity=J.intensity??1,this._offset=J.offset,this._penumbra=J.penumbra,this._position=J.position,this._trackedEntity=J.trackedEntity,this._trackedPosition=J.trackedPosition,this._type=J.type??0}get id(){return this._id}get angle(){return this._angle}get attachedToEntity(){return this._attachedToEntity}get color(){return this._color}get distance(){return this._distance}get intensity(){return this._intensity}get isSpawned(){return this._id!==void 0}get offset(){return this._offset}get penumbra(){return this._penumbra}get position(){return this._position}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get type(){return this._type}get world(){return this._world}setAngle(J){if(this._angle===J)return;if(this._angle=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_ANGLE",{light:this,angle:J})}setAttachedToEntity(J){if(!J.isSpawned)return E.error(`Light.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_ATTACHED_TO_ENTITY",{light:this,entity:J})}setColor(J){if(this._color.r===J.r&&this._color.g===J.g&&this._color.b===J.b)return;if(this._color=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_COLOR",{light:this,color:J})}setDistance(J){if(this._distance===J)return;if(this._distance=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_DISTANCE",{light:this,distance:J})}setIntensity(J){if(this._intensity===J)return;if(this._intensity=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_INTENSITY",{light:this,intensity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_OFFSET",{light:this,offset:J})}setPenumbra(J){if(this._penumbra===J)return;if(this._penumbra=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_PENUMBRA",{light:this,penumbra:J})}setPosition(J){if(this._position===J)return;if(this._position=J,this._attachedToEntity=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_POSITION",{light:this,position:J})}setTrackedEntity(J){if(!J.isSpawned)return E.error(`Light.setTrackedEntity(): Entity ${J.id} is not spawned!`);if(this._trackedEntity===J)return;if(this._trackedEntity=J,this._trackedPosition=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_TRACKED_ENTITY",{light:this,entity:J})}setTrackedPosition(J){if(this._trackedPosition===J)return;if(this._trackedPosition=J,this._trackedEntity=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_TRACKED_POSITION",{light:this,position:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.lightManager.unregisterLight(this),this.emitWithWorld(this._world,"LIGHT.DESPAWN",{light:this}),this._id=void 0,this._world=void 0}spawn(J){if(this.isSpawned)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return E.error(`Light.spawn(): Attached entity ${this._attachedToEntity.id} must be spawned before spawning Light!`);this._id=J.lightManager.registerLight(this),this._world=J,this.emitWithWorld(J,"LIGHT.SPAWN",{light:this})}serialize(){return t.serializeLight(this)}}var TC;((Z)=>{Z[Z.FIRST_PERSON=0]="FIRST_PERSON";Z[Z.THIRD_PERSON=1]="THIRD_PERSON";Z[Z.SPECTATOR=2]="SPECTATOR"})(TC||={});var RH;((V)=>{V.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";V.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";V.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";V.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";V.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";V.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";V.SET_FOV="PLAYER_CAMERA.SET_FOV";V.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";V.SET_MODE="PLAYER_CAMERA.SET_MODE";V.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";V.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";V.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";V.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(RH||={});class TJ extends s{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_trackedEntity;_trackedPosition;_zoom=1;constructor(J){super();this.player=J}get attachedToEntity(){return this._attachedToEntity}get attachedToPosition(){return this._attachedToPosition}get facingDirection(){return{x:-Math.sin(this._orientation.yaw)*Math.cos(this._orientation.pitch),y:Math.sin(this._orientation.pitch),z:-Math.cos(this._orientation.yaw)*Math.cos(this._orientation.pitch)}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){if(!this._requirePlayerWorld())return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){if(!this._requirePlayerWorld())return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}setAttachedToEntity(J){if(!this._requirePlayerWorld())return;if(!J.isSpawned)return E.error(`PlayerCamera.setAttachedToEntity(): Entity ${J.id} is not spawned!`);this._attachedToEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",{playerCamera:this,entity:J})}setAttachedToPosition(J){if(!this._requirePlayerWorld())return;this._attachedToPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){if(!this._requirePlayerWorld())return;this._filmOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){if(!this._requirePlayerWorld())return;this._forwardOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){if(!this._requirePlayerWorld())return;this._fov=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){if(!this._requirePlayerWorld())return;this._modelHiddenNodes=new Set(J.map((X)=>X.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setMode(J){if(!this._requirePlayerWorld())return;this._mode=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){if(!this._requirePlayerWorld())return;this._offset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_OFFSET",{playerCamera:this,offset:J})}setOrientationPitch(J){this._orientation.pitch=J}setOrientationYaw(J){this._orientation.yaw=J}setTrackedEntity(J){if(!this._requirePlayerWorld())return;this._trackedEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){if(!this._requirePlayerWorld())return;this._trackedPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){if(!this._requirePlayerWorld())return;this._zoom=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return t.serializePlayerCamera(this)}_requirePlayerWorld(){if(!this.player.world)E.error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world!`);return!!this.player.world}}var Q$;((W)=>{W.DATA="PLAYER_UI.DATA";W.LOAD="PLAYER_UI.LOAD";W.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";W.SEND_DATA="PLAYER_UI.SEND_DATA"})(Q$||={});class DJ extends s{player;constructor(J){super();this.player=J}load(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.LOAD",{playerUI:this,htmlUri:J})}lockPointer(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.LOCK_POINTER",{playerUI:this,lock:J})}sendData(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.SEND_DATA",{playerUI:this,data:J})}}class _J{_colliderHandleBlockTypeMap=new Map;_colliderHandleCollisionCallbackMap=new Map;_colliderHandleEntityMap=new Map;_cleanupBlockTypeColliderHandles=new Set;_pendingCleanupBlockTypeColliderHandles=new Set;_cleanupCollisionCallbackColliderHandles=new Set;_pendingCleanupCollisionCallbackColliderHandles=new Set;_cleanupEntityColliderHandles=new Set;_pendingCleanupEntityColliderHandles=new Set;getColliderBlockType(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleBlockTypeMap.get(J.rawCollider.handle)}getColliderCollisionCallback(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleCollisionCallbackMap.get(J.rawCollider.handle)}getColliderEntity(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleEntityMap.get(J.rawCollider.handle)}getColliderHandleBlockType(J){return this._colliderHandleBlockTypeMap.get(J)}getColliderHandleCollisionCallback(J){return this._colliderHandleCollisionCallbackMap.get(J)}getColliderHandleEntity(J){return this._colliderHandleEntityMap.get(J)}removeColliderBlockType(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleBlockType(J.rawCollider.handle)}removeColliderCollisionCallback(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleCollisionCallback(J.rawCollider.handle)}removeColliderEntity(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleEntity(J.rawCollider.handle)}removeColliderHandleBlockType(J){this._colliderHandleBlockTypeMap.delete(J)}removeColliderHandleCollisionCallback(J){this._colliderHandleCollisionCallbackMap.delete(J)}removeColliderHandleEntity(J){this._colliderHandleEntityMap.delete(J)}setColliderBlockType(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleBlockType(J.rawCollider.handle,X)}setColliderCollisionCallback(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleCollisionCallback(J.rawCollider.handle,X)}setColliderEntity(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleEntity(J.rawCollider.handle,X)}setColliderHandleBlockType(J,X){this._colliderHandleBlockTypeMap.set(J,X),this._cleanupBlockTypeColliderHandles.delete(J),this._pendingCleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,X){this._colliderHandleCollisionCallbackMap.set(J,X),this._cleanupCollisionCallbackColliderHandles.delete(J),this._pendingCleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,X){this._colliderHandleEntityMap.set(J,X),this._cleanupEntityColliderHandles.delete(J),this._pendingCleanupEntityColliderHandles.delete(J)}queueColliderHandleForCleanup(J){if(this._colliderHandleBlockTypeMap.has(J))this._pendingCleanupBlockTypeColliderHandles.add(J);if(this._colliderHandleCollisionCallbackMap.has(J))this._pendingCleanupCollisionCallbackColliderHandles.add(J);if(this._colliderHandleEntityMap.has(J))this._pendingCleanupEntityColliderHandles.add(J)}cleanup(){for(let J of this._cleanupBlockTypeColliderHandles)this._colliderHandleBlockTypeMap.delete(J);this._cleanupBlockTypeColliderHandles.clear();for(let J of this._cleanupCollisionCallbackColliderHandles)this._colliderHandleCollisionCallbackMap.delete(J);this._cleanupCollisionCallbackColliderHandles.clear();for(let J of this._cleanupEntityColliderHandles)this._colliderHandleEntityMap.delete(J);this._cleanupEntityColliderHandles.clear(),[[this._pendingCleanupBlockTypeColliderHandles,this._cleanupBlockTypeColliderHandles],[this._pendingCleanupCollisionCallbackColliderHandles,this._cleanupCollisionCallbackColliderHandles],[this._pendingCleanupEntityColliderHandles,this._cleanupEntityColliderHandles]].forEach(([J,X])=>{for(let Y of J.keys())X.add(Y);J.clear()})}_requireSimulatedCollider(J){if(!J.rawCollider)E.error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.");return!!J.rawCollider}}var uX0={x:0,y:-32,z:0},wH=60,OH;((W)=>{W.STEP_START="SIMULATION.STEP_START";W.STEP_END="SIMULATION.STEP_END";W.DEBUG_RAYCAST="SIMULATION.DEBUG_RAYCAST";W.DEBUG_RENDER="SIMULATION.DEBUG_RENDER"})(OH||={});class EJ extends s{_colliderMap=new _J;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_rapierEventQueue;_rapierSimulation;_world;constructor(J,X=wH,Y=uX0){super();this._rapierEventQueue=new z0.EventQueue(!0),this._rapierSimulation=new z0.World(Y),this._rapierSimulation.timestep=Math.fround(1/X),this._world=J}get colliderMap(){return this._colliderMap}get isDebugRaycastingEnabled(){return this._debugRaycastingEnabled}get isDebugRenderingEnabled(){return this._debugRenderingEnabled}get gravity(){return this._rapierSimulation.gravity}get timestepS(){return this._rapierSimulation.timestep}get world(){return this._world}raycast(J,X,Y,Z={}){let W=new z0.Ray(J,X),$=this._rapierSimulation.castRay(W,Y,Z.ignoresSensors??!0,Z.filterFlags,Z.filterGroups,Z.filterExcludeCollider,Z.filterExcludeRigidBody,Z.filterPredicate);if(this._debugRaycastingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:X,length:Y,hit:!!$});if(!$)return null;let Q=W.pointAt($.timeOfImpact),K=$.timeOfImpact,G=$.collider,F=this._colliderMap.getColliderHandleBlockType(G.handle);if(F)return{hitBlock:y9.fromGlobalCoordinate({x:Math.floor(Q.x-(W.dir.x<0?0.0001:-0.0001)),y:Math.floor(Q.y-(W.dir.y<0?0.0001:-0.0001)),z:Math.floor(Q.z-(W.dir.z<0?0.0001:-0.0001))},F),hitPoint:Q,hitDistance:K};let q=this._colliderMap.getColliderHandleEntity(G.handle);if(q)return{hitEntity:q,hitPoint:Q,hitDistance:K};return null}createRawCollider(J,X){return this._rapierSimulation.createCollider(J,X)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J){this._debugRenderingEnabled=J}getContactManifolds(J,X){let Y=[];return this._rapierSimulation.narrowPhase.contactPair(J,X,(Z,W)=>{if(Z.numContacts()===0)return;let $=Z.normal(),Q=[];for(let K=0;K<Z.numSolverContacts();K++)Q.push(Z.solverContactPoint(K));Y.push({contactPoints:Q,localNormalA:!W?Z.localNormal1():Z.localNormal2(),localNormalB:!W?Z.localNormal2():Z.localNormal1(),normal:!W?$:{x:-$.x,y:-$.y,z:-$.z}})}),Y}removeRawCollider(J){this._colliderMap.queueColliderHandleForCleanup(J.handle),this._rapierSimulation.removeCollider(J,!1)}removeRawRigidBody(J){this._rapierSimulation.removeRigidBody(J)}setGravity(J){this._rapierSimulation.gravity=J}step=(J)=>{this.emitWithWorld(this._world,"SIMULATION.STEP_START",{simulation:this,tickDeltaMs:J});let X=performance.now();if(this._rapierSimulation.step(this._rapierEventQueue),this._rapierEventQueue.drainContactForceEvents(this._onContactForceEvent),this._rapierEventQueue.drainCollisionEvents(this._onCollisionEvent),this._colliderMap.cleanup(),this.emitWithWorld(this._world,"SIMULATION.STEP_END",{simulation:this,stepDurationMs:performance.now()-X}),this._debugRenderingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender()})};_onCollisionEvent=(J,X,Y)=>{let[Z,W]=this._getCollisionObjects(J,X);if(!Z||!W)return;let $=(Q,K)=>{if(Q instanceof V6&&K instanceof Y8&&Q.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))Q.emit("BLOCK_TYPE.ENTITY_COLLISION",{blockType:Q,entity:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(Q instanceof Y8&&K instanceof V6&&Q.hasListeners("ENTITY.BLOCK_COLLISION"))Q.emit("ENTITY.BLOCK_COLLISION",{entity:Q,blockType:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(Q instanceof Y8&&K instanceof Y8&&Q.hasListeners("ENTITY.ENTITY_COLLISION"))Q.emit("ENTITY.ENTITY_COLLISION",{entity:Q,otherEntity:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(typeof Q==="function"&&(K instanceof Y8||K instanceof V6))Q(K,Y,J,X)};$(Z,W),$(W,Z)};_onContactForceEvent=(J)=>{let[X,Y]=this._getCollisionObjects(J.collider1(),J.collider2());if(!X||typeof X==="function"||!Y||typeof Y==="function")return;let Z={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},W=($,Q)=>{if($ instanceof V6&&Q instanceof Y8&&$.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))$.emit("BLOCK_TYPE.ENTITY_CONTACT_FORCE",{blockType:$,entity:Q,contactForceData:Z});else if($ instanceof Y8&&Q instanceof V6&&$.hasListeners("ENTITY.BLOCK_CONTACT_FORCE"))$.emit("ENTITY.BLOCK_CONTACT_FORCE",{entity:$,blockType:Q,contactForceData:Z});else if($ instanceof Y8&&Q instanceof Y8&&$.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))$.emit("ENTITY.ENTITY_CONTACT_FORCE",{entity:$,otherEntity:Q,contactForceData:Z})};W(X,Y),W(Y,X)};_getCollisionObjects(J,X){let Y=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),Z=this._colliderMap.getColliderHandleBlockType(X)??this._colliderMap.getColliderHandleCollisionCallback(X)??this._colliderMap.getColliderHandleEntity(X);return[Y,Z]}}class K${_synchronizedPlayerReliablePackets=new Map;_queuedBroadcasts=[];_queuedAudioSynchronizations={};_queuedBlockSynchronizations={};_queuedBlockTypeSynchronizations={};_queuedChunkSynchronizations={};_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations={};_queuedLightSynchronizations={};_queuedPerPlayerSynchronizations=new Map;_queuedPerPlayerCameraSynchronizations=new Map;_queuedPerPlayerUISynchronizations=new Map;_queuedPerPlayerUIDatasSynchronizations=new Map;_queuedPlayerSynchronizations={};_queuedSceneUISynchronizations={};_queuedWorldSynchronization;_loadedSceneUIs=new Set;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){let J=[],X=[],Y=this._world.loop.currentTick;this._queuedPerPlayerSynchronizations.forEach((z,V)=>{this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(...z)});let Z=Object.values(this._queuedEntitySynchronizations);if(Z.length>0){let[z,V]=Z.reduce(([M,R],L)=>{for(let w in L)if(w!=="i"&&w!=="p"&&w!=="r")return M.push(L),[M,R];return R.push(L),[M,R]},[[],[]]);if(V.length>0){let M=A.createPacket(A.outboundPackets.entitiesPacketDefinition,V,Y);X.push(M)}if(z.length>0){let M=A.createPacket(A.outboundPackets.entitiesPacketDefinition,z,Y);J.push(M),this._synchronizedPlayerReliablePackets.forEach((R)=>R.push(M))}}let W=Object.values(this._queuedAudioSynchronizations);if(W.length>0){let z=A.createPacket(A.outboundPackets.audiosPacketDefinition,W,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let $=Object.values(this._queuedBlockTypeSynchronizations);if($.length>0){let z=A.createPacket(A.outboundPackets.blockTypesPacketDefinition,$,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let Q=Object.values(this._queuedBlockSynchronizations);if(Q.length>0){let z=A.createPacket(A.outboundPackets.blocksPacketDefinition,Q,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let K=Object.values(this._queuedChunkSynchronizations);if(K.length>0){let z=A.createPacket(A.outboundPackets.chunksPacketDefinition,K,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let G=Object.values(this._queuedLightSynchronizations);if(G.length>0){let z=A.createPacket(A.outboundPackets.lightsPacketDefinition,G,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedPerPlayerUISynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.uiPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)}),this._queuedPerPlayerUIDatasSynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.uiDatasPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)});let F=Object.values(this._queuedSceneUISynchronizations);if(F.length>0){let z=A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,F,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}if(this._queuedWorldSynchronization){let z=A.createPacket(A.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedPerPlayerCameraSynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.cameraPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)});let q=Object.values(this._queuedPlayerSynchronizations);if(q.length>0){let z=A.createPacket(A.outboundPackets.playersPacketDefinition,q,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedBroadcasts.forEach((z)=>{J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))});let H=this._queuedDebugRaycastSynchronizations;if(H.length>0){let z=A.createPacket(A.outboundPackets.physicsDebugRaycastsPacketDefinition,H,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}j6.instance.getConnectedPlayersByWorld(this._world).forEach((z)=>{let V=this._synchronizedPlayerReliablePackets.get(z)??J;if(V.length>0)z.connection.send(V);if(X.length>0)z.connection.send(X,!1)}),this._queuedBroadcasts=[],this._queuedAudioSynchronizations={},this._queuedBlockSynchronizations={},this._queuedBlockTypeSynchronizations={},this._queuedChunkSynchronizations={},this._queuedDebugRaycastSynchronizations=[],this._queuedEntitySynchronizations={},this._queuedLightSynchronizations={},this._queuedPerPlayerSynchronizations.clear(),this._queuedPerPlayerCameraSynchronizations.clear(),this._queuedPerPlayerUISynchronizations.clear(),this._queuedPerPlayerUIDatasSynchronizations.clear(),this._queuedPlayerSynchronizations={},this._queuedSceneUISynchronizations={},this._queuedWorldSynchronization=void 0,this._loadedSceneUIs.clear(),this._spawnedChunks.clear(),this._spawnedEntities.clear(),this._synchronizedPlayerReliablePackets.clear()}_subscribeToAudioEvents(){this._world.final("AUDIO.PAUSE",this._onAudioPause),this._world.final("AUDIO.PLAY",this._onAudioPlay),this._world.final("AUDIO.PLAY_RESTART",this._onAudioPlayRestart),this._world.final("AUDIO.SET_ATTACHED_TO_ENTITY",this._onAudioSetAttachedToEntity),this._world.final("AUDIO.SET_CUTOFF_DISTANCE",this._onAudioSetCutoffDistance),this._world.final("AUDIO.SET_DETUNE",this._onAudioSetDetune),this._world.final("AUDIO.SET_DISTORTION",this._onAudioSetDistortion),this._world.final("AUDIO.SET_POSITION",this._onAudioSetPosition),this._world.final("AUDIO.SET_PLAYBACK_RATE",this._onAudioSetPlaybackRate),this._world.final("AUDIO.SET_REFERENCE_DISTANCE",this._onAudioSetReferenceDistance),this._world.final("AUDIO.SET_VOLUME",this._onAudioSetVolume)}_subscribeToBlockTypeRegistryEvents(){this._world.final("BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",this._onBlockTypeRegistryRegisterBlockType)}_subscribeToChatEvents(){this._world.final("CHAT.BROADCAST_MESSAGE",this._onChatSendBroadcastMessage),this._world.final("CHAT.PLAYER_MESSAGE",this._onChatSendPlayerMessage)}_subscribeToChunkEvents(){this._world.final("CHUNK.SPAWN",this._onChunkSpawn),this._world.final("CHUNK.DESPAWN",this._onChunkDespawn),this._world.final("CHUNK.SET_BLOCK",this._onChunkSetBlock)}_subscribeToEntityEvents(){this._world.final("ENTITY.SPAWN",this._onEntitySpawn),this._world.final("ENTITY.DESPAWN",this._onEntityDespawn),this._world.final("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",this._onEntitySetModelAnimationsPlaybackRate),this._world.final("ENTITY.SET_MODEL_HIDDEN_NODES",this._onEntitySetModelHiddenNodes),this._world.final("ENTITY.SET_OPACITY",this._onEntitySetOpacity),this._world.final("ENTITY.SET_PARENT",this._onEntitySetParent),this._world.final("ENTITY.SET_TINT_COLOR",this._onEntitySetTintColor),this._world.final("ENTITY.START_MODEL_LOOPED_ANIMATIONS",this._onEntityStartModelLoopedAnimations),this._world.final("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",this._onEntityStartModelOneshotAnimations),this._world.final("ENTITY.STOP_MODEL_ANIMATIONS",this._onEntityStopModelAnimations),this._world.final("ENTITY.UPDATE_POSITION",this._onEntityUpdatePosition),this._world.final("ENTITY.UPDATE_ROTATION",this._onEntityUpdateRotation)}_subscribeToLightEvents(){this._world.final("LIGHT.DESPAWN",this._onLightDespawn),this._world.final("LIGHT.SET_ANGLE",this._onLightSetAngle),this._world.final("LIGHT.SET_ATTACHED_TO_ENTITY",this._onLightSetAttachedToEntity),this._world.final("LIGHT.SET_COLOR",this._onLightSetColor),this._world.final("LIGHT.SET_DISTANCE",this._onLightSetDistance),this._world.final("LIGHT.SET_INTENSITY",this._onLightSetIntensity),this._world.final("LIGHT.SET_OFFSET",this._onLightSetOffset),this._world.final("LIGHT.SET_PENUMBRA",this._onLightSetPenumbra),this._world.final("LIGHT.SET_POSITION",this._onLightSetPosition),this._world.final("LIGHT.SET_TRACKED_ENTITY",this._onLightSetTrackedEntity),this._world.final("LIGHT.SET_TRACKED_POSITION",this._onLightSetTrackedPosition),this._world.final("LIGHT.SPAWN",this._onLightSpawn)}_subscribeToPlayerEvents(){this._world.final("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.final("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.final("PLAYER.REQUEST_SYNC",this._onPlayerRequestSync)}_subscribeToPlayerCameraEvents(){this._world.final("PLAYER_CAMERA.LOOK_AT_ENTITY",this._onPlayerCameraLookAtEntity),this._world.final("PLAYER_CAMERA.LOOK_AT_POSITION",this._onPlayerCameraLookAtPosition),this._world.final("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",this._onPlayerCameraSetAttachedToEntity),this._world.final("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",this._onPlayerCameraSetAttachedToPosition),this._world.final("PLAYER_CAMERA.SET_FILM_OFFSET",this._onPlayerCameraSetFilmOffset),this._world.final("PLAYER_CAMERA.SET_FORWARD_OFFSET",this._onPlayerCameraSetForwardOffset),this._world.final("PLAYER_CAMERA.SET_FOV",this._onPlayerCameraSetFov),this._world.final("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",this._onPlayerCameraSetModelHiddenNodes),this._world.final("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.final("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.final("PLAYER_CAMERA.SET_TRACKED_ENTITY",this._onPlayerCameraSetTrackedEntity),this._world.final("PLAYER_CAMERA.SET_TRACKED_POSITION",this._onPlayerCameraSetTrackedPosition),this._world.final("PLAYER_CAMERA.SET_ZOOM",this._onPlayerCameraSetZoom)}_subscribeToPlayerUIEvents(){this._world.final("PLAYER_UI.LOAD",this._onPlayerUILoad),this._world.final("PLAYER_UI.LOCK_POINTER",this._onPlayerUILockPointer),this._world.final("PLAYER_UI.SEND_DATA",this._onPlayerUISendData)}_subscribeToSceneUIEvents(){this._world.final("SCENE_UI.LOAD",this._onSceneUILoad),this._world.final("SCENE_UI.SET_ATTACHED_TO_ENTITY",this._onSceneUISetAttachedToEntity),this._world.final("SCENE_UI.SET_OFFSET",this._onSceneUISetOffset),this._world.final("SCENE_UI.SET_POSITION",this._onSceneUISetPosition),this._world.final("SCENE_UI.SET_STATE",this._onSceneUISetState),this._world.final("SCENE_UI.SET_VIEW_DISTANCE",this._onSceneUISetViewDistance),this._world.final("SCENE_UI.UNLOAD",this._onSceneUIUnload)}_subscribeToSimulationEvents(){this._world.final("SIMULATION.DEBUG_RAYCAST",this._onSimulationDebugRaycast),this._world.final("SIMULATION.DEBUG_RENDER",this._onSimulationDebugRender)}_subscribeToWorldEvents(){this._world.final("WORLD.SET_AMBIENT_LIGHT_COLOR",this._onWorldSetAmbientLightColor),this._world.final("WORLD.SET_AMBIENT_LIGHT_INTENSITY",this._onWorldSetAmbientLightIntensity),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",this._onWorldSetDirectionalLightColor),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",this._onWorldSetDirectionalLightIntensity),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",this._onWorldSetDirectionalLightPosition)}_onAudioPause=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.pa=!0,delete X.pl,delete X.r};_onAudioPlay=(J)=>{let X=J.audio.serialize();X.pl=!0,delete X.pa,delete X.r,this._queuedAudioSynchronizations[X.i]=X};_onAudioPlayRestart=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.r=!0,delete X.pa,delete X.pl,this._queuedAudioSynchronizations[X.i]=X};_onAudioSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onAudioSetCutoffDistance=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.cd=J.cutoffDistance};_onAudioSetDetune=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.de=J.detune};_onAudioSetDistortion=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.di=J.distortion};_onAudioSetPosition=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.e=J.position?void 0:X.e,X.p=J.position?t.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let X=J.blockType.serialize();this._queuedBlockTypeSynchronizations[J.blockType.id]=X};_onChatSendBroadcastMessage=(J)=>{let{player:X,message:Y,color:Z}=J;this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:Z,p:X?.id}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:X,message:Y,color:Z}=J,W=this._queuedPerPlayerSynchronizations.get(X)??[];W.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:Z}],this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set(X,W)};_onChunkSpawn=(J)=>{let X=this._createOrGetQueuedChunkSync(J.chunk);X.b=Array.from(J.chunk.blocks),X.rm=void 0,this._spawnedChunks.add(X.c.join(","))};_onChunkDespawn=(J)=>{let X=this._createOrGetQueuedChunkSync(J.chunk),Y=X.c.join(",");if(this._spawnedChunks.has(Y))delete this._queuedChunkSynchronizations[Y],this._spawnedChunks.delete(Y);else X.rm=!0};_onChunkSetBlock=(J)=>{let X=this._createOrGetQueuedBlockSync(J.globalCoordinate);X.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.ap=J.playbackRate};_onEntitySpawn=(J)=>{let X=J.entity.serialize();this._queuedEntitySynchronizations[X.i]=X,this._spawnedEntities.add(X.i)};_onEntityDespawn=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has(X.i))delete this._queuedEntitySynchronizations[X.i],this._spawnedEntities.delete(X.i);else X.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.h=Array.from(J.modelHiddenNodes)};_onEntitySetOpacity=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.o=J.opacity};_onEntitySetParent=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.pe=J.parent?J.parent.id:void 0,X.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.t=J.tintColor?t.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.al=Array.from(new Set([...X.al??[],...J.animations])),X.as)X.as=X.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.ao=Array.from(new Set([...X.ao??[],...J.animations])),X.as)X.as=X.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.al)X.al=X.al.filter((Y)=>!J.animations.has(Y)).filter(Boolean);if(X.ao)X.ao=X.ao.filter((Y)=>!J.animations.has(Y)).filter(Boolean);X.as=Array.from(new Set([...X.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.rm=!0};_onLightSetAngle=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onLightSetColor=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.c=t.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.d=J.distance};_onLightSetIntensity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.n=J.intensity};_onLightSetOffset=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.o=J.offset?t.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.pe=J.penumbra};_onLightSetPosition=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.p=J.position?t.serializeVector(J.position):void 0,X.e=J.position?void 0:X.e};_onLightSetTrackedEntity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.te=J.entity?J.entity.id:void 0,X.tp=J.entity?void 0:X.tp};_onLightSetTrackedPosition=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.tp=J.position?t.serializeVector(J.position):void 0,X.te=J.position?void 0:X.te};_onLightSpawn=(J)=>{let X=J.light.serialize();this._queuedLightSynchronizations[X.i]=X};_onPlayerCameraLookAtEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pl=t.serializeVector(J.entity.position),delete X.et,delete X.pt};_onPlayerCameraLookAtPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pl=J.position?t.serializeVector(J.position):void 0,delete X.et,delete X.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.e=J.entity.id,delete X.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.p=J.position?t.serializeVector(J.position):void 0,delete X.e};_onPlayerCameraSetFilmOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetMode=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.o=J.offset?t.serializeVector(J.offset):void 0};_onPlayerCameraSetTrackedEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.et=J.entity?J.entity.id:void 0,delete X.pl,delete X.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pt=J.position?t.serializeVector(J.position):void 0,delete X.et,delete X.pl};_onPlayerCameraSetZoom=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:X}=J,Y=this._queuedPerPlayerSynchronizations.get(X)??[];Y.push(A.createPacket(A.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((W)=>{if(X.camera.attachedToEntity===void 0&&W instanceof n1&&W.player===X)X.camera.setAttachedToEntity(W);return W.serialize()}),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllAudios().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.playersPacketDefinition,j6.instance.getConnectedPlayers().map((W)=>W.serialize()),this._world.loop.currentTick));let Z=this._createOrGetQueuedPlayerCameraSync(X.camera);this._queuedPerPlayerCameraSynchronizations.set(X,{...X.camera.serialize(),...Z}),this._queuedPerPlayerSynchronizations.set(X,Y),this._queuedPlayerSynchronizations[X.id]=X.serialize()};_onPlayerLeftWorld=(J)=>{let X=this._createOrGetQueuedPlayerSync(J.player);X.rm=!0};_onPlayerRequestSync=(J)=>{J.player.connection.send([A.createPacket(A.outboundPackets.syncResponsePacketDefinition,{r:J.receivedAt,s:Date.now(),p:performance.now()-J.receivedAtMs,n:this._world.loop.nextTickMs},this._world.loop.currentTick)])};_onPlayerUILoad=(J)=>{let X=this._createOrGetQueuedPlayerUISync(J.playerUI);X.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let X=this._createOrGetQueuedPlayerUISync(J.playerUI);X.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let X=J.sceneUI.serialize();this._queuedSceneUISynchronizations[X.i]=X,this._loadedSceneUIs.add(X.i)};_onSceneUISetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onSceneUISetOffset=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.o=J.offset?t.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.p=J.position?t.serializeVector(J.position):void 0,X.e=J.position?void 0:X.e};_onSceneUISetState=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.s=J.state};_onSceneUISetViewDistance=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.v=J.viewDistance};_onSceneUIUnload=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);if(this._loadedSceneUIs.has(X.i))delete this._queuedSceneUISynchronizations[X.i],this._loadedSceneUIs.delete(X.i);else X.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(t.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.ac=t.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.dc=t.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.dp=t.serializeVector(J.position)};_createOrGetQueuedAudioSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");return this._queuedAudioSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedBlockSync(J){let{x:X,y:Y,z:Z}=J;return this._queuedBlockSynchronizations[`${X},${Y},${Z}`]??={i:0,c:[X,Y,Z]}}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)E.fatalError("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:X,y:Y,z:Z}=J.originCoordinate;return this._queuedChunkSynchronizations[`${X},${Y},${Z}`]??={c:[X,Y,Z]}}_createOrGetQueuedEntitySync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");return this._queuedEntitySynchronizations[J.id]??={i:J.id}}_createOrGetQueuedLightSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");return this._queuedLightSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedPlayerSync(): Player has no id!");return this._queuedPlayerSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerCameraSync(J){let X=this._queuedPerPlayerCameraSynchronizations.get(J.player);if(!X)X={},this._queuedPerPlayerCameraSynchronizations.set(J.player,X);return X}_createOrGetQueuedPlayerUISync(J){let X=this._queuedPerPlayerUISynchronizations.get(J.player);if(!X)X={},this._queuedPerPlayerUISynchronizations.set(J.player,X);return X}_createOrGetQueuedPlayerUIDatasSync(J){let X=this._queuedPerPlayerUIDatasSynchronizations.get(J.player);if(!X)X=[],this._queuedPerPlayerUIDatasSynchronizations.set(J.player,X);return X}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");return this._queuedSceneUISynchronizations[J.id]??={i:J.id}}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)E.fatalError("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}_createOrGetSynchronizedPlayerReliablePackets(J,X){let Y=this._synchronizedPlayerReliablePackets.get(J);if(!Y)Y=[...X],this._synchronizedPlayerReliablePackets.set(J,Y);return Y}}class CJ{_sceneUIs=new Map;_nextSceneUIId=1;_world;constructor(J){this._world=J}get world(){return this._world}getAllSceneUIs(){return Array.from(this._sceneUIs.values())}getAllEntityAttachedSceneUIs(J){return this.getAllSceneUIs().filter((X)=>X.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let X=this._nextSceneUIId;return this._sceneUIs.set(X,J),this._nextSceneUIId++,X}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach((X)=>{X.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}class SJ{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,X,Y){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._tickFunction=X,this._tickErrorCallback=Y}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return E.warning("Ticker.start(): ticker already running.");this._lastLoopTimeMs=performance.now();let J=()=>{let X=performance.now(),Y=X-this._lastLoopTimeMs;if(this._lastLoopTimeMs=X,Y>250)Y=250;this._accumulatorMs+=Y;while(this._accumulatorMs>=this._fixedTimestepMs)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs;this._nextTickMs=this._fixedTimestepMs-this._accumulatorMs,this._tickHandle=setTimeout(J,0)};J()}stop(){if(!this._tickHandle)return E.warning("Ticker.stop(): ticker not running.");clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch(X){if(X instanceof Error&&this._tickErrorCallback)this._tickErrorCallback(X);else E.warning(`Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error: ${X}`)}}}var DC;(($)=>{$.START="WORLD_LOOP.START";$.STOP="WORLD_LOOP.STOP";$.TICK_START="WORLD_LOOP.TICK_START";$.TICK_END="WORLD_LOOP.TICK_END";$.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(DC||={});class IJ extends s{_currentTick=0;_ticker;_world;constructor(J,X=wH){super();this._ticker=new SJ(X,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get nextTickMs(){return this._ticker.nextTickMs}get timestepS(){return this._ticker.fixedTimestepS}get world(){return this._world}start(){this._ticker.start(),this.emitWithWorld(this._world,"WORLD_LOOP.START",{worldLoop:this})}stop(){this._ticker.stop(),this.emitWithWorld(this._world,"WORLD_LOOP.STOP",{worldLoop:this})}_tick=(J)=>{this.emitWithWorld(this._world,"WORLD_LOOP.TICK_START",{worldLoop:this,tickDeltaMs:J});let X=performance.now();this._world.chunkLattice.updateChunks(),this._world.entityManager.tickEntities(J),this._world.simulation.step(J),this._world.entityManager.checkAndEmitUpdates(),this._world.networkSynchronizer.synchronize(),this._currentTick++,this.emitWithWorld(this._world,"WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-X})};_onTickError=(J)=>{E.error(`WorldLoop._onTickError(): Error: ${J}`),this.emitWithWorld(this._world,"WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}var xH;((K)=>{K.SET_AMBIENT_LIGHT_COLOR="WORLD.SET_AMBIENT_LIGHT_COLOR";K.SET_AMBIENT_LIGHT_INTENSITY="WORLD.SET_AMBIENT_LIGHT_INTENSITY";K.SET_DIRECTIONAL_LIGHT_COLOR="WORLD.SET_DIRECTIONAL_LIGHT_COLOR";K.SET_DIRECTIONAL_LIGHT_INTENSITY="WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY";K.SET_DIRECTIONAL_LIGHT_POSITION="WORLD.SET_DIRECTIONAL_LIGHT_POSITION";K.START="WORLD.START";K.STOP="WORLD.STOP"})(xH||={});class hJ extends s{_id;_ambientLightColor;_ambientLightIntensity;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_name;_skyboxUri;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_entityManager;_lightManager;_loop;_networkSynchronizer;_sceneUIManager;_simulation;constructor(J){super();this._id=J.id,this._ambientLightColor=J.ambientLightColor??{r:255,g:255,b:255},this._ambientLightIntensity=J.ambientLightIntensity??1,this._directionalLightColor=J.directionalLightColor??{r:255,g:255,b:255},this._directionalLightIntensity=J.directionalLightIntensity??3,this._directionalLightPosition=J.directionalLightPosition??{x:100,y:150,z:100},this._name=J.name,this._skyboxUri=J.skyboxUri,this._audioManager=new Q4(this),this._blockTypeRegistry=new d4(this),this._chatManager=new fJ(this),this._chunkLattice=new PJ(this),this._entityManager=new jJ(this),this._lightManager=new kJ(this),this._loop=new IJ(this,J.tickRate),this._networkSynchronizer=new K$(this),this._sceneUIManager=new CJ(this),this._simulation=new EJ(this,J.tickRate,J.gravity)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get name(){return this._name}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get entityManager(){return this._entityManager}get lightManager(){return this._lightManager}get loop(){return this._loop}get networkSynchronizer(){return this._networkSynchronizer}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}loadMap(J){if(J.blockTypes)for(let X of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:X.id,isLiquid:X.isLiquid,name:X.name,textureUri:X.textureUri});if(J.blocks)for(let[X,Y]of Object.entries(J.blocks)){let[Z,W,$]=X.split(",").map(Number);this.chunkLattice.setBlock({x:Z,y:W,z:$},Y)}if(J.entities)for(let[X,Y]of Object.entries(J.entities)){let[Z,W,$]=X.split(",").map(Number);new Y8(Y).spawn(this,{x:Z,y:W,z:$})}}setAmbientLightColor(J){this._ambientLightColor=J,this.emit("WORLD.SET_AMBIENT_LIGHT_COLOR",{world:this,color:J})}setAmbientLightIntensity(J){this._ambientLightIntensity=J,this.emit("WORLD.SET_AMBIENT_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightColor(J){this._directionalLightColor=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",{world:this,color:J})}setDirectionalLightIntensity(J){this._directionalLightIntensity=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightPosition(J){this._directionalLightPosition=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",{world:this,position:J})}start(){this._loop.start(),this.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){this._loop.stop(),this.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return t.serializeWorld(this)}}var _C;((Y)=>{Y.START="GAMESERVER.START";Y.STOP="GAMESERVER.STOP"})(_C||={});function dX0(J){z0.init().then(()=>{return R1.instance.modelRegistry.preloadModels()}).then(()=>{J(R1.instance.worlds[0]),R1.instance.start()}).catch((X)=>{E.fatalError(`Failed to initialize the game engine, exiting. Error: ${X}`)})}class R1{static _instance;_modelRegistry=U6.instance;_playerManager=j6.instance;_socket=i1.instance;_webServer=o5.instance;_worlds={};constructor(){let J=new hJ({id:0,name:"Default World",skyboxUri:"skyboxes/partly-cloudy"});this._worlds[J.id]=J}static get instance(){if(!this._instance)this._instance=new R1;return this._instance}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worlds(){return this._worlds}start(){m8.emit("GAMESERVER.START",{startedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.start()),this._webServer.start()}stop(){m8.emit("GAMESERVER.STOP",{stoppedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.stop())}}class b9{static instance=new b9;constructor(){}async getGlobalData(J){let X=await u6.instance.getData(J);if(!X||X.error){if(X?.error)E.warning(`PersistenceManager.getGlobalData(): ${X.error.message}`);return}return X}async getPlayerData(J){let X=await u6.instance.getData(this._getPlayerKey(J));if(!X||X.error){if(X?.error)E.warning(`PersistenceManager.getPlayerData(): ${X.error.message}`);return}return X}async setGlobalData(J,X){let Y=await u6.instance.setData(J,X);if(!Y||Y.error){if(Y?.error)E.warning(`PersistenceManager.setGlobalData(): ${Y.error.message}`);return}return Y}async setPlayerData(J,X){let Y=await u6.instance.setData(this._getPlayerKey(J),X);if(!Y||Y.error){if(Y?.error)E.warning(`PersistenceManager.setPlayerData(): ${Y.error.message}`);return}return Y}_getPlayerKey(J){return`player-${J.id}`}}var EC=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","1","2","3","4","5","6","7","8","9","0"],BJ;((W)=>{W.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";W.JOINED_WORLD="PLAYER.JOINED_WORLD";W.LEFT_WORLD="PLAYER.LEFT_WORLD";W.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(BJ||={});class r5 extends s{static _devNextPlayerId=1;id;username;profilePictureUrl;camera;connection;ui;_input={};_lastUnreliableInputSequenceNumber=0;_world;constructor(J,X){super();this.id=X?.user.id??`player-${r5._devNextPlayerId++}`,this.username=X?.user.username??this.id,this.profilePictureUrl=X?.user.profilePictureURL??void 0,this.camera=new TJ(this),this.connection=J,this.ui=new DJ(this),J.onPacket(A.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(A.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(A.PacketId.INPUT,this._onInputPacket),J.onPacket(A.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(A.PacketId.UI_DATA_SEND,this._onUIDataSendPacket),this.joinWorld(R1.instance.worlds[0])}get input(){return this._input}get world(){return this._world}disconnect(){this.leaveWorld(),this.connection.close()}async getPersistedData(){return b9.instance.getPlayerData(this)}joinWorld(J){this.leaveWorld(),this._world=J,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world})}leaveWorld(){if(!this._world)return;this.emitWithWorld(this._world,"PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}async setPersistedData(J){return b9.instance.setPlayerData(this,J)}serialize(){return t.serializePlayer(this)}_onChatMessageSendPacket=(J)=>{if(this._world)this.emitWithWorld(this._world,"PLAYER.CHAT_MESSAGE_SEND",{player:this,message:J[1].m})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let X=J[1];if(X.sq!==void 0){if(X.sq<this._lastUnreliableInputSequenceNumber)return;this._lastUnreliableInputSequenceNumber=X.sq}if(EC.forEach((Y)=>{let Z=Y;if(X[Z]!==void 0)this._input[Z]=Boolean(X[Z])}),X.cp!==void 0)this.camera.setOrientationPitch(X.cp);if(X.cy!==void 0)this.camera.setOrientationYaw(X.cy)};_onSyncRequestPacket=()=>{if(this._world)this.emitWithWorld(this._world,"PLAYER.REQUEST_SYNC",{player:this,receivedAt:Date.now(),receivedAtMs:performance.now()})};_onUIDataSendPacket=(J)=>{this.ui.emit("PLAYER_UI.DATA",{playerUI:this.ui,data:J[1]})}}var PH;((Y)=>{Y.BROADCAST_MESSAGE="CHAT.BROADCAST_MESSAGE";Y.PLAYER_MESSAGE="CHAT.PLAYER_MESSAGE"})(PH||={});class fJ extends s{_commandCallbacks={};_world;constructor(J){super();this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,X){this._commandCallbacks[J]=X}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,X){this._sendBroadcastMessage(void 0,J,X)}sendPlayerMessage(J,X,Y){this.emitWithWorld(this._world,"CHAT.PLAYER_MESSAGE",{player:J,message:X,color:Y})}_subscribeToPlayerEvents(){this._world.on("PLAYER.CHAT_MESSAGE_SEND",(J)=>{let{player:X,message:Y}=J,[Z,...W]=Y.split(" "),$=this._commandCallbacks[Z];if($){$(X,W,Y);return}this._sendBroadcastMessage(X,Y)})}_sendBroadcastMessage(J,X,Y){this.emitWithWorld(this._world,"CHAT.BROADCAST_MESSAGE",{player:J,message:X,color:Y})}}var l=0.000001,Q0=typeof Float32Array!=="undefined"?Float32Array:Array,d6=Math.random;var L_0=Math.PI/180;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};var e0={};k6(e0,{transpose:()=>tX0,subtract:()=>SC,sub:()=>VY0,str:()=>QY0,set:()=>rX0,scale:()=>ZY0,rotate:()=>YY0,multiplyScalarAndAdd:()=>LY0,multiplyScalar:()=>zY0,multiply:()=>CC,mul:()=>UY0,invert:()=>eX0,identity:()=>sX0,fromValues:()=>oX0,fromScaling:()=>$Y0,fromRotation:()=>WY0,frob:()=>KY0,exactEquals:()=>qY0,equals:()=>HY0,determinant:()=>XY0,create:()=>iX0,copy:()=>aX0,clone:()=>nX0,adjoint:()=>JY0,add:()=>FY0,LDU:()=>GY0});function iX0(){var J=new Q0(4);if(Q0!=Float32Array)J[1]=0,J[2]=0;return J[0]=1,J[3]=1,J}function nX0(J){var X=new Q0(4);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X}function aX0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J}function sX0(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=1,J}function oX0(J,X,Y,Z){var W=new Q0(4);return W[0]=J,W[1]=X,W[2]=Y,W[3]=Z,W}function rX0(J,X,Y,Z,W){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J}function tX0(J,X){if(J===X){var Y=X[1];J[1]=X[2],J[2]=Y}else J[0]=X[0],J[1]=X[2],J[2]=X[1],J[3]=X[3];return J}function eX0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*$-W*Z;if(!Q)return null;return Q=1/Q,J[0]=$*Q,J[1]=-Z*Q,J[2]=-W*Q,J[3]=Y*Q,J}function JY0(J,X){var Y=X[0];return J[0]=X[3],J[1]=-X[1],J[2]=-X[2],J[3]=Y,J}function XY0(J){return J[0]*J[3]-J[2]*J[1]}function CC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1],F=Y[2],q=Y[3];return J[0]=Z*K+$*G,J[1]=W*K+Q*G,J[2]=Z*F+$*q,J[3]=W*F+Q*q,J}function YY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+$*K,J[1]=W*G+Q*K,J[2]=Z*-K+$*G,J[3]=W*-K+Q*G,J}function ZY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1];return J[0]=Z*K,J[1]=W*K,J[2]=$*G,J[3]=Q*G,J}function WY0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=-Y,J[3]=Z,J}function $Y0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=X[1],J}function QY0(J){return"mat2("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}function KY0(J){return Math.hypot(J[0],J[1],J[2],J[3])}function GY0(J,X,Y,Z){return J[2]=Z[2]/Z[0],Y[0]=Z[0],Y[1]=Z[1],Y[3]=Z[3]-J[2]*Y[1],[J,X,Y]}function FY0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J}function SC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J}function qY0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]}function HY0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=X[0],K=X[1],G=X[2],F=X[3];return Math.abs(Y-Q)<=l*Math.max(1,Math.abs(Y),Math.abs(Q))&&Math.abs(Z-K)<=l*Math.max(1,Math.abs(Z),Math.abs(K))&&Math.abs(W-G)<=l*Math.max(1,Math.abs(W),Math.abs(G))&&Math.abs($-F)<=l*Math.max(1,Math.abs($),Math.abs(F))}function zY0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J}function LY0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J}var UY0=CC,VY0=SC;var h0={};k6(h0,{transpose:()=>NY0,translate:()=>kY0,subtract:()=>hC,sub:()=>uY0,str:()=>bY0,set:()=>xY0,scale:()=>DY0,rotate:()=>TY0,projection:()=>fY0,normalFromMat4:()=>hY0,multiplyScalarAndAdd:()=>gY0,multiplyScalar:()=>yY0,multiply:()=>IC,mul:()=>lY0,invert:()=>vY0,identity:()=>PY0,fromValues:()=>OY0,fromTranslation:()=>_Y0,fromScaling:()=>CY0,fromRotation:()=>EY0,fromQuat:()=>IY0,fromMat4:()=>MY0,fromMat2d:()=>SY0,frob:()=>pY0,exactEquals:()=>cY0,equals:()=>mY0,determinant:()=>jY0,create:()=>NH,copy:()=>wY0,clone:()=>RY0,adjoint:()=>BY0,add:()=>AY0});function NH(){var J=new Q0(9);if(Q0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[5]=0,J[6]=0,J[7]=0;return J[0]=1,J[4]=1,J[8]=1,J}function MY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[4],J[4]=X[5],J[5]=X[6],J[6]=X[8],J[7]=X[9],J[8]=X[10],J}function RY0(J){var X=new Q0(9);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X[4]=J[4],X[5]=J[5],X[6]=J[6],X[7]=J[7],X[8]=J[8],X}function wY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J}function OY0(J,X,Y,Z,W,$,Q,K,G){var F=new Q0(9);return F[0]=J,F[1]=X,F[2]=Y,F[3]=Z,F[4]=W,F[5]=$,F[6]=Q,F[7]=K,F[8]=G,F}function xY0(J,X,Y,Z,W,$,Q,K,G,F){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J[4]=$,J[5]=Q,J[6]=K,J[7]=G,J[8]=F,J}function PY0(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function NY0(J,X){if(J===X){var Y=X[1],Z=X[2],W=X[5];J[1]=X[3],J[2]=X[6],J[3]=Y,J[5]=X[7],J[6]=Z,J[7]=W}else J[0]=X[0],J[1]=X[3],J[2]=X[6],J[3]=X[1],J[4]=X[4],J[5]=X[7],J[6]=X[2],J[7]=X[5],J[8]=X[8];return J}function vY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=q*Q-K*F,z=-q*$+K*G,V=F*$-Q*G,M=Y*H+Z*z+W*V;if(!M)return null;return M=1/M,J[0]=H*M,J[1]=(-q*Z+W*F)*M,J[2]=(K*Z-W*Q)*M,J[3]=z*M,J[4]=(q*Y-W*G)*M,J[5]=(-K*Y+W*$)*M,J[6]=V*M,J[7]=(-F*Y+Z*G)*M,J[8]=(Q*Y-Z*$)*M,J}function BY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8];return J[0]=Q*q-K*F,J[1]=W*F-Z*q,J[2]=Z*K-W*Q,J[3]=K*G-$*q,J[4]=Y*q-W*G,J[5]=W*$-Y*K,J[6]=$*F-Q*G,J[7]=Z*G-Y*F,J[8]=Y*Q-Z*$,J}function jY0(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8];return X*(F*$-Q*G)+Y*(-F*W+Q*K)+Z*(G*W-$*K)}function IC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Y[0],V=Y[1],M=Y[2],R=Y[3],L=Y[4],w=Y[5],P=Y[6],N=Y[7],v=Y[8];return J[0]=z*Z+V*Q+M*F,J[1]=z*W+V*K+M*q,J[2]=z*$+V*G+M*H,J[3]=R*Z+L*Q+w*F,J[4]=R*W+L*K+w*q,J[5]=R*$+L*G+w*H,J[6]=P*Z+N*Q+v*F,J[7]=P*W+N*K+v*q,J[8]=P*$+N*G+v*H,J}function kY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Y[0],V=Y[1];return J[0]=Z,J[1]=W,J[2]=$,J[3]=Q,J[4]=K,J[5]=G,J[6]=z*Z+V*Q+F,J[7]=z*W+V*K+q,J[8]=z*$+V*G+H,J}function TY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Math.sin(Y),V=Math.cos(Y);return J[0]=V*Z+z*Q,J[1]=V*W+z*K,J[2]=V*$+z*G,J[3]=V*Q-z*Z,J[4]=V*K-z*W,J[5]=V*G-z*$,J[6]=F,J[7]=q,J[8]=H,J}function DY0(J,X,Y){var Z=Y[0],W=Y[1];return J[0]=Z*X[0],J[1]=Z*X[1],J[2]=Z*X[2],J[3]=W*X[3],J[4]=W*X[4],J[5]=W*X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J}function _Y0(J,X){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=X[0],J[7]=X[1],J[8]=1,J}function EY0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=0,J[3]=-Y,J[4]=Z,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function CY0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=0,J[4]=X[1],J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function SY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=0,J[3]=X[2],J[4]=X[3],J[5]=0,J[6]=X[4],J[7]=X[5],J[8]=1,J}function IY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y+Y,K=Z+Z,G=W+W,F=Y*Q,q=Z*Q,H=Z*K,z=W*Q,V=W*K,M=W*G,R=$*Q,L=$*K,w=$*G;return J[0]=1-H-M,J[3]=q-w,J[6]=z+L,J[1]=q+w,J[4]=1-F-M,J[7]=V-R,J[2]=z-L,J[5]=V+R,J[8]=1-F-H,J}function hY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15],P=Y*K-Z*Q,N=Y*G-W*Q,v=Y*F-$*Q,j=Z*G-W*K,O=Z*F-$*K,D=W*F-$*G,_=q*R-H*M,C=q*L-z*M,S=q*w-V*M,I=H*L-z*R,f=H*w-V*R,y=z*w-V*L,h=P*y-N*f+v*I+j*S-O*C+D*_;if(!h)return null;return h=1/h,J[0]=(K*y-G*f+F*I)*h,J[1]=(G*S-Q*y-F*C)*h,J[2]=(Q*f-K*S+F*_)*h,J[3]=(W*f-Z*y-$*I)*h,J[4]=(Y*y-W*S+$*C)*h,J[5]=(Z*S-Y*f-$*_)*h,J[6]=(R*D-L*O+w*j)*h,J[7]=(L*v-M*D-w*N)*h,J[8]=(M*O-R*v+w*P)*h,J}function fY0(J,X,Y){return J[0]=2/X,J[1]=0,J[2]=0,J[3]=0,J[4]=-2/Y,J[5]=0,J[6]=-1,J[7]=1,J[8]=1,J}function bY0(J){return"mat3("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+")"}function pY0(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8])}function AY0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J[4]=X[4]+Y[4],J[5]=X[5]+Y[5],J[6]=X[6]+Y[6],J[7]=X[7]+Y[7],J[8]=X[8]+Y[8],J}function hC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J[4]=X[4]-Y[4],J[5]=X[5]-Y[5],J[6]=X[6]-Y[6],J[7]=X[7]-Y[7],J[8]=X[8]-Y[8],J}function yY0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J[4]=X[4]*Y,J[5]=X[5]*Y,J[6]=X[6]*Y,J[7]=X[7]*Y,J[8]=X[8]*Y,J}function gY0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J[4]=X[4]+Y[4]*Z,J[5]=X[5]+Y[5]*Z,J[6]=X[6]+Y[6]*Z,J[7]=X[7]+Y[7]*Z,J[8]=X[8]+Y[8]*Z,J}function cY0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]&&J[4]===X[4]&&J[5]===X[5]&&J[6]===X[6]&&J[7]===X[7]&&J[8]===X[8]}function mY0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=J[4],K=J[5],G=J[6],F=J[7],q=J[8],H=X[0],z=X[1],V=X[2],M=X[3],R=X[4],L=X[5],w=X[6],P=X[7],N=X[8];return Math.abs(Y-H)<=l*Math.max(1,Math.abs(Y),Math.abs(H))&&Math.abs(Z-z)<=l*Math.max(1,Math.abs(Z),Math.abs(z))&&Math.abs(W-V)<=l*Math.max(1,Math.abs(W),Math.abs(V))&&Math.abs($-M)<=l*Math.max(1,Math.abs($),Math.abs(M))&&Math.abs(Q-R)<=l*Math.max(1,Math.abs(Q),Math.abs(R))&&Math.abs(K-L)<=l*Math.max(1,Math.abs(K),Math.abs(L))&&Math.abs(G-w)<=l*Math.max(1,Math.abs(G),Math.abs(w))&&Math.abs(F-P)<=l*Math.max(1,Math.abs(F),Math.abs(P))&&Math.abs(q-N)<=l*Math.max(1,Math.abs(q),Math.abs(N))}var lY0=IC,uY0=hC;var Y0={};k6(Y0,{transpose:()=>oY0,translate:()=>JZ0,targetTo:()=>jZ0,subtract:()=>cC,sub:()=>hZ0,str:()=>kZ0,set:()=>sY0,scale:()=>XZ0,rotateZ:()=>$Z0,rotateY:()=>WZ0,rotateX:()=>ZZ0,rotate:()=>YZ0,perspectiveZO:()=>xZ0,perspectiveNO:()=>yC,perspectiveFromFieldOfView:()=>PZ0,perspective:()=>OZ0,orthoZO:()=>vZ0,orthoNO:()=>gC,ortho:()=>NZ0,multiplyScalarAndAdd:()=>EZ0,multiplyScalar:()=>_Z0,multiply:()=>bC,mul:()=>IZ0,lookAt:()=>BZ0,invert:()=>rY0,identity:()=>fC,getTranslation:()=>LZ0,getScaling:()=>AC,getRotation:()=>UZ0,frustum:()=>wZ0,fromZRotation:()=>HZ0,fromYRotation:()=>qZ0,fromXRotation:()=>FZ0,fromValues:()=>aY0,fromTranslation:()=>QZ0,fromScaling:()=>KZ0,fromRotationTranslationScaleOrigin:()=>MZ0,fromRotationTranslationScale:()=>VZ0,fromRotationTranslation:()=>pC,fromRotation:()=>GZ0,fromQuat2:()=>zZ0,fromQuat:()=>RZ0,frob:()=>TZ0,exactEquals:()=>CZ0,equals:()=>SZ0,determinant:()=>eY0,create:()=>dY0,copy:()=>nY0,clone:()=>iY0,adjoint:()=>tY0,add:()=>DZ0});function dY0(){var J=new Q0(16);if(Q0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=0,J[12]=0,J[13]=0,J[14]=0;return J[0]=1,J[5]=1,J[10]=1,J[15]=1,J}function iY0(J){var X=new Q0(16);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X[4]=J[4],X[5]=J[5],X[6]=J[6],X[7]=J[7],X[8]=J[8],X[9]=J[9],X[10]=J[10],X[11]=J[11],X[12]=J[12],X[13]=J[13],X[14]=J[14],X[15]=J[15],X}function nY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J[9]=X[9],J[10]=X[10],J[11]=X[11],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15],J}function aY0(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R){var L=new Q0(16);return L[0]=J,L[1]=X,L[2]=Y,L[3]=Z,L[4]=W,L[5]=$,L[6]=Q,L[7]=K,L[8]=G,L[9]=F,L[10]=q,L[11]=H,L[12]=z,L[13]=V,L[14]=M,L[15]=R,L}function sY0(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R,L){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J[4]=$,J[5]=Q,J[6]=K,J[7]=G,J[8]=F,J[9]=q,J[10]=H,J[11]=z,J[12]=V,J[13]=M,J[14]=R,J[15]=L,J}function fC(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function oY0(J,X){if(J===X){var Y=X[1],Z=X[2],W=X[3],$=X[6],Q=X[7],K=X[11];J[1]=X[4],J[2]=X[8],J[3]=X[12],J[4]=Y,J[6]=X[9],J[7]=X[13],J[8]=Z,J[9]=$,J[11]=X[14],J[12]=W,J[13]=Q,J[14]=K}else J[0]=X[0],J[1]=X[4],J[2]=X[8],J[3]=X[12],J[4]=X[1],J[5]=X[5],J[6]=X[9],J[7]=X[13],J[8]=X[2],J[9]=X[6],J[10]=X[10],J[11]=X[14],J[12]=X[3],J[13]=X[7],J[14]=X[11],J[15]=X[15];return J}function rY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15],P=Y*K-Z*Q,N=Y*G-W*Q,v=Y*F-$*Q,j=Z*G-W*K,O=Z*F-$*K,D=W*F-$*G,_=q*R-H*M,C=q*L-z*M,S=q*w-V*M,I=H*L-z*R,f=H*w-V*R,y=z*w-V*L,h=P*y-N*f+v*I+j*S-O*C+D*_;if(!h)return null;return h=1/h,J[0]=(K*y-G*f+F*I)*h,J[1]=(W*f-Z*y-$*I)*h,J[2]=(R*D-L*O+w*j)*h,J[3]=(z*O-H*D-V*j)*h,J[4]=(G*S-Q*y-F*C)*h,J[5]=(Y*y-W*S+$*C)*h,J[6]=(L*v-M*D-w*N)*h,J[7]=(q*D-z*v+V*N)*h,J[8]=(Q*f-K*S+F*_)*h,J[9]=(Z*S-Y*f-$*_)*h,J[10]=(M*O-R*v+w*P)*h,J[11]=(H*v-q*O-V*P)*h,J[12]=(K*C-Q*I-G*_)*h,J[13]=(Y*I-Z*C+W*_)*h,J[14]=(R*N-M*j-L*P)*h,J[15]=(q*j-H*N+z*P)*h,J}function tY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15];return J[0]=K*(z*w-V*L)-H*(G*w-F*L)+R*(G*V-F*z),J[1]=-(Z*(z*w-V*L)-H*(W*w-$*L)+R*(W*V-$*z)),J[2]=Z*(G*w-F*L)-K*(W*w-$*L)+R*(W*F-$*G),J[3]=-(Z*(G*V-F*z)-K*(W*V-$*z)+H*(W*F-$*G)),J[4]=-(Q*(z*w-V*L)-q*(G*w-F*L)+M*(G*V-F*z)),J[5]=Y*(z*w-V*L)-q*(W*w-$*L)+M*(W*V-$*z),J[6]=-(Y*(G*w-F*L)-Q*(W*w-$*L)+M*(W*F-$*G)),J[7]=Y*(G*V-F*z)-Q*(W*V-$*z)+q*(W*F-$*G),J[8]=Q*(H*w-V*R)-q*(K*w-F*R)+M*(K*V-F*H),J[9]=-(Y*(H*w-V*R)-q*(Z*w-$*R)+M*(Z*V-$*H)),J[10]=Y*(K*w-F*R)-Q*(Z*w-$*R)+M*(Z*F-$*K),J[11]=-(Y*(K*V-F*H)-Q*(Z*V-$*H)+q*(Z*F-$*K)),J[12]=-(Q*(H*L-z*R)-q*(K*L-G*R)+M*(K*z-G*H)),J[13]=Y*(H*L-z*R)-q*(Z*L-W*R)+M*(Z*z-W*H),J[14]=-(Y*(K*L-G*R)-Q*(Z*L-W*R)+M*(Z*G-W*K)),J[15]=Y*(K*z-G*H)-Q*(Z*z-W*H)+q*(Z*G-W*K),J}function eY0(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8],q=J[9],H=J[10],z=J[11],V=J[12],M=J[13],R=J[14],L=J[15],w=X*Q-Y*$,P=X*K-Z*$,N=X*G-W*$,v=Y*K-Z*Q,j=Y*G-W*Q,O=Z*G-W*K,D=F*M-q*V,_=F*R-H*V,C=F*L-z*V,S=q*R-H*M,I=q*L-z*M,f=H*L-z*R;return w*f-P*I+N*S+v*C-j*_+O*D}function bC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=X[9],V=X[10],M=X[11],R=X[12],L=X[13],w=X[14],P=X[15],N=Y[0],v=Y[1],j=Y[2],O=Y[3];return J[0]=N*Z+v*K+j*H+O*R,J[1]=N*W+v*G+j*z+O*L,J[2]=N*$+v*F+j*V+O*w,J[3]=N*Q+v*q+j*M+O*P,N=Y[4],v=Y[5],j=Y[6],O=Y[7],J[4]=N*Z+v*K+j*H+O*R,J[5]=N*W+v*G+j*z+O*L,J[6]=N*$+v*F+j*V+O*w,J[7]=N*Q+v*q+j*M+O*P,N=Y[8],v=Y[9],j=Y[10],O=Y[11],J[8]=N*Z+v*K+j*H+O*R,J[9]=N*W+v*G+j*z+O*L,J[10]=N*$+v*F+j*V+O*w,J[11]=N*Q+v*q+j*M+O*P,N=Y[12],v=Y[13],j=Y[14],O=Y[15],J[12]=N*Z+v*K+j*H+O*R,J[13]=N*W+v*G+j*z+O*L,J[14]=N*$+v*F+j*V+O*w,J[15]=N*Q+v*q+j*M+O*P,J}function JZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q,K,G,F,q,H,z,V,M,R,L,w;if(X===J)J[12]=X[0]*Z+X[4]*W+X[8]*$+X[12],J[13]=X[1]*Z+X[5]*W+X[9]*$+X[13],J[14]=X[2]*Z+X[6]*W+X[10]*$+X[14],J[15]=X[3]*Z+X[7]*W+X[11]*$+X[15];else Q=X[0],K=X[1],G=X[2],F=X[3],q=X[4],H=X[5],z=X[6],V=X[7],M=X[8],R=X[9],L=X[10],w=X[11],J[0]=Q,J[1]=K,J[2]=G,J[3]=F,J[4]=q,J[5]=H,J[6]=z,J[7]=V,J[8]=M,J[9]=R,J[10]=L,J[11]=w,J[12]=Q*Z+q*W+M*$+X[12],J[13]=K*Z+H*W+R*$+X[13],J[14]=G*Z+z*W+L*$+X[14],J[15]=F*Z+V*W+w*$+X[15];return J}function XZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2];return J[0]=X[0]*Z,J[1]=X[1]*Z,J[2]=X[2]*Z,J[3]=X[3]*Z,J[4]=X[4]*W,J[5]=X[5]*W,J[6]=X[6]*W,J[7]=X[7]*W,J[8]=X[8]*$,J[9]=X[9]*$,J[10]=X[10]*$,J[11]=X[11]*$,J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15],J}function YZ0(J,X,Y,Z){var W=Z[0],$=Z[1],Q=Z[2],K=Math.hypot(W,$,Q),G,F,q,H,z,V,M,R,L,w,P,N,v,j,O,D,_,C,S,I,f,y,h,g;if(K<l)return null;if(K=1/K,W*=K,$*=K,Q*=K,G=Math.sin(Y),F=Math.cos(Y),q=1-F,H=X[0],z=X[1],V=X[2],M=X[3],R=X[4],L=X[5],w=X[6],P=X[7],N=X[8],v=X[9],j=X[10],O=X[11],D=W*W*q+F,_=$*W*q+Q*G,C=Q*W*q-$*G,S=W*$*q-Q*G,I=$*$*q+F,f=Q*$*q+W*G,y=W*Q*q+$*G,h=$*Q*q-W*G,g=Q*Q*q+F,J[0]=H*D+R*_+N*C,J[1]=z*D+L*_+v*C,J[2]=V*D+w*_+j*C,J[3]=M*D+P*_+O*C,J[4]=H*S+R*I+N*f,J[5]=z*S+L*I+v*f,J[6]=V*S+w*I+j*f,J[7]=M*S+P*I+O*f,J[8]=H*y+R*h+N*g,J[9]=z*y+L*h+v*g,J[10]=V*y+w*h+j*g,J[11]=M*y+P*h+O*g,X!==J)J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J}function ZZ0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[4],Q=X[5],K=X[6],G=X[7],F=X[8],q=X[9],H=X[10],z=X[11];if(X!==J)J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[4]=$*W+F*Z,J[5]=Q*W+q*Z,J[6]=K*W+H*Z,J[7]=G*W+z*Z,J[8]=F*W-$*Z,J[9]=q*W-Q*Z,J[10]=H*W-K*Z,J[11]=z*W-G*Z,J}function WZ0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[0],Q=X[1],K=X[2],G=X[3],F=X[8],q=X[9],H=X[10],z=X[11];if(X!==J)J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[0]=$*W-F*Z,J[1]=Q*W-q*Z,J[2]=K*W-H*Z,J[3]=G*W-z*Z,J[8]=$*Z+F*W,J[9]=Q*Z+q*W,J[10]=K*Z+H*W,J[11]=G*Z+z*W,J}function $Z0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[0],Q=X[1],K=X[2],G=X[3],F=X[4],q=X[5],H=X[6],z=X[7];if(X!==J)J[8]=X[8],J[9]=X[9],J[10]=X[10],J[11]=X[11],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[0]=$*W+F*Z,J[1]=Q*W+q*Z,J[2]=K*W+H*Z,J[3]=G*W+z*Z,J[4]=F*W-$*Z,J[5]=q*W-Q*Z,J[6]=H*W-K*Z,J[7]=z*W-G*Z,J}function QZ0(J,X){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=X[0],J[13]=X[1],J[14]=X[2],J[15]=1,J}function KZ0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=X[1],J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=X[2],J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function GZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q=Math.hypot(Z,W,$),K,G,F;if(Q<l)return null;return Q=1/Q,Z*=Q,W*=Q,$*=Q,K=Math.sin(X),G=Math.cos(X),F=1-G,J[0]=Z*Z*F+G,J[1]=W*Z*F+$*K,J[2]=$*Z*F-W*K,J[3]=0,J[4]=Z*W*F-$*K,J[5]=W*W*F+G,J[6]=$*W*F+Z*K,J[7]=0,J[8]=Z*$*F+W*K,J[9]=W*$*F-Z*K,J[10]=$*$*F+G,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function FZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=Z,J[6]=Y,J[7]=0,J[8]=0,J[9]=-Y,J[10]=Z,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function qZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=0,J[2]=-Y,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=Y,J[9]=0,J[10]=Z,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function HZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=0,J[3]=0,J[4]=-Y,J[5]=Z,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function pC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Z+Z,G=W+W,F=$+$,q=Z*K,H=Z*G,z=Z*F,V=W*G,M=W*F,R=$*F,L=Q*K,w=Q*G,P=Q*F;return J[0]=1-(V+R),J[1]=H+P,J[2]=z-w,J[3]=0,J[4]=H-P,J[5]=1-(q+R),J[6]=M+L,J[7]=0,J[8]=z+w,J[9]=M-L,J[10]=1-(q+V),J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function zZ0(J,X){var Y=new Q0(3),Z=-X[0],W=-X[1],$=-X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=Z*Z+W*W+$*$+Q*Q;if(H>0)Y[0]=(K*Q+q*Z+G*$-F*W)*2/H,Y[1]=(G*Q+q*W+F*Z-K*$)*2/H,Y[2]=(F*Q+q*$+K*W-G*Z)*2/H;else Y[0]=(K*Q+q*Z+G*$-F*W)*2,Y[1]=(G*Q+q*W+F*Z-K*$)*2,Y[2]=(F*Q+q*$+K*W-G*Z)*2;return pC(J,X,Y),J}function LZ0(J,X){return J[0]=X[12],J[1]=X[13],J[2]=X[14],J}function AC(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[4],Q=X[5],K=X[6],G=X[8],F=X[9],q=X[10];return J[0]=Math.hypot(Y,Z,W),J[1]=Math.hypot($,Q,K),J[2]=Math.hypot(G,F,q),J}function UZ0(J,X){var Y=new Q0(3);AC(Y,X);var Z=1/Y[0],W=1/Y[1],$=1/Y[2],Q=X[0]*Z,K=X[1]*W,G=X[2]*$,F=X[4]*Z,q=X[5]*W,H=X[6]*$,z=X[8]*Z,V=X[9]*W,M=X[10]*$,R=Q+q+M,L=0;if(R>0)L=Math.sqrt(R+1)*2,J[3]=0.25*L,J[0]=(H-V)/L,J[1]=(z-G)/L,J[2]=(K-F)/L;else if(Q>q&&Q>M)L=Math.sqrt(1+Q-q-M)*2,J[3]=(H-V)/L,J[0]=0.25*L,J[1]=(K+F)/L,J[2]=(z+G)/L;else if(q>M)L=Math.sqrt(1+q-Q-M)*2,J[3]=(z-G)/L,J[0]=(K+F)/L,J[1]=0.25*L,J[2]=(H+V)/L;else L=Math.sqrt(1+M-Q-q)*2,J[3]=(K-F)/L,J[0]=(z+G)/L,J[1]=(H+V)/L,J[2]=0.25*L;return J}function VZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3],G=W+W,F=$+$,q=Q+Q,H=W*G,z=W*F,V=W*q,M=$*F,R=$*q,L=Q*q,w=K*G,P=K*F,N=K*q,v=Z[0],j=Z[1],O=Z[2];return J[0]=(1-(M+L))*v,J[1]=(z+N)*v,J[2]=(V-P)*v,J[3]=0,J[4]=(z-N)*j,J[5]=(1-(H+L))*j,J[6]=(R+w)*j,J[7]=0,J[8]=(V+P)*O,J[9]=(R-w)*O,J[10]=(1-(H+M))*O,J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function MZ0(J,X,Y,Z,W){var $=X[0],Q=X[1],K=X[2],G=X[3],F=$+$,q=Q+Q,H=K+K,z=$*F,V=$*q,M=$*H,R=Q*q,L=Q*H,w=K*H,P=G*F,N=G*q,v=G*H,j=Z[0],O=Z[1],D=Z[2],_=W[0],C=W[1],S=W[2],I=(1-(R+w))*j,f=(V+v)*j,y=(M-N)*j,h=(V-v)*O,g=(1-(z+w))*O,J0=(L+P)*O,p0=(M+N)*D,a0=(L-P)*D,Q6=(1-(z+R))*D;return J[0]=I,J[1]=f,J[2]=y,J[3]=0,J[4]=h,J[5]=g,J[6]=J0,J[7]=0,J[8]=p0,J[9]=a0,J[10]=Q6,J[11]=0,J[12]=Y[0]+_-(I*_+h*C+p0*S),J[13]=Y[1]+C-(f*_+g*C+a0*S),J[14]=Y[2]+S-(y*_+J0*C+Q6*S),J[15]=1,J}function RZ0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y+Y,K=Z+Z,G=W+W,F=Y*Q,q=Z*Q,H=Z*K,z=W*Q,V=W*K,M=W*G,R=$*Q,L=$*K,w=$*G;return J[0]=1-H-M,J[1]=q+w,J[2]=z-L,J[3]=0,J[4]=q-w,J[5]=1-F-M,J[6]=V+R,J[7]=0,J[8]=z+L,J[9]=V-R,J[10]=1-F-H,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function wZ0(J,X,Y,Z,W,$,Q){var K=1/(Y-X),G=1/(W-Z),F=1/($-Q);return J[0]=$*2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$*2*G,J[6]=0,J[7]=0,J[8]=(Y+X)*K,J[9]=(W+Z)*G,J[10]=(Q+$)*F,J[11]=-1,J[12]=0,J[13]=0,J[14]=Q*$*2*F,J[15]=0,J}function yC(J,X,Y,Z,W){var $=1/Math.tan(X/2),Q;if(J[0]=$/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,W!=null&&W!==1/0)Q=1/(Z-W),J[10]=(W+Z)*Q,J[14]=2*W*Z*Q;else J[10]=-1,J[14]=-2*Z;return J}var OZ0=yC;function xZ0(J,X,Y,Z,W){var $=1/Math.tan(X/2),Q;if(J[0]=$/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,W!=null&&W!==1/0)Q=1/(Z-W),J[10]=W*Q,J[14]=W*Z*Q;else J[10]=-1,J[14]=-Z;return J}function PZ0(J,X,Y,Z){var W=Math.tan(X.upDegrees*Math.PI/180),$=Math.tan(X.downDegrees*Math.PI/180),Q=Math.tan(X.leftDegrees*Math.PI/180),K=Math.tan(X.rightDegrees*Math.PI/180),G=2/(Q+K),F=2/(W+$);return J[0]=G,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=F,J[6]=0,J[7]=0,J[8]=-((Q-K)*G*0.5),J[9]=(W-$)*F*0.5,J[10]=Z/(Y-Z),J[11]=-1,J[12]=0,J[13]=0,J[14]=Z*Y/(Y-Z),J[15]=0,J}function gC(J,X,Y,Z,W,$,Q){var K=1/(X-Y),G=1/(Z-W),F=1/($-Q);return J[0]=-2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*G,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=2*F,J[11]=0,J[12]=(X+Y)*K,J[13]=(W+Z)*G,J[14]=(Q+$)*F,J[15]=1,J}var NZ0=gC;function vZ0(J,X,Y,Z,W,$,Q){var K=1/(X-Y),G=1/(Z-W),F=1/($-Q);return J[0]=-2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*G,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=F,J[11]=0,J[12]=(X+Y)*K,J[13]=(W+Z)*G,J[14]=$*F,J[15]=1,J}function BZ0(J,X,Y,Z){var W,$,Q,K,G,F,q,H,z,V,M=X[0],R=X[1],L=X[2],w=Z[0],P=Z[1],N=Z[2],v=Y[0],j=Y[1],O=Y[2];if(Math.abs(M-v)<l&&Math.abs(R-j)<l&&Math.abs(L-O)<l)return fC(J);if(q=M-v,H=R-j,z=L-O,V=1/Math.hypot(q,H,z),q*=V,H*=V,z*=V,W=P*z-N*H,$=N*q-w*z,Q=w*H-P*q,V=Math.hypot(W,$,Q),!V)W=0,$=0,Q=0;else V=1/V,W*=V,$*=V,Q*=V;if(K=H*Q-z*$,G=z*W-q*Q,F=q*$-H*W,V=Math.hypot(K,G,F),!V)K=0,G=0,F=0;else V=1/V,K*=V,G*=V,F*=V;return J[0]=W,J[1]=K,J[2]=q,J[3]=0,J[4]=$,J[5]=G,J[6]=H,J[7]=0,J[8]=Q,J[9]=F,J[10]=z,J[11]=0,J[12]=-(W*M+$*R+Q*L),J[13]=-(K*M+G*R+F*L),J[14]=-(q*M+H*R+z*L),J[15]=1,J}function jZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=Z[0],G=Z[1],F=Z[2],q=W-Y[0],H=$-Y[1],z=Q-Y[2],V=q*q+H*H+z*z;if(V>0)V=1/Math.sqrt(V),q*=V,H*=V,z*=V;var M=G*z-F*H,R=F*q-K*z,L=K*H-G*q;if(V=M*M+R*R+L*L,V>0)V=1/Math.sqrt(V),M*=V,R*=V,L*=V;return J[0]=M,J[1]=R,J[2]=L,J[3]=0,J[4]=H*L-z*R,J[5]=z*M-q*L,J[6]=q*R-H*M,J[7]=0,J[8]=q,J[9]=H,J[10]=z,J[11]=0,J[12]=W,J[13]=$,J[14]=Q,J[15]=1,J}function kZ0(J){return"mat4("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+", "+J[9]+", "+J[10]+", "+J[11]+", "+J[12]+", "+J[13]+", "+J[14]+", "+J[15]+")"}function TZ0(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8],J[9],J[10],J[11],J[12],J[13],J[14],J[15])}function DZ0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J[4]=X[4]+Y[4],J[5]=X[5]+Y[5],J[6]=X[6]+Y[6],J[7]=X[7]+Y[7],J[8]=X[8]+Y[8],J[9]=X[9]+Y[9],J[10]=X[10]+Y[10],J[11]=X[11]+Y[11],J[12]=X[12]+Y[12],J[13]=X[13]+Y[13],J[14]=X[14]+Y[14],J[15]=X[15]+Y[15],J}function cC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J[4]=X[4]-Y[4],J[5]=X[5]-Y[5],J[6]=X[6]-Y[6],J[7]=X[7]-Y[7],J[8]=X[8]-Y[8],J[9]=X[9]-Y[9],J[10]=X[10]-Y[10],J[11]=X[11]-Y[11],J[12]=X[12]-Y[12],J[13]=X[13]-Y[13],J[14]=X[14]-Y[14],J[15]=X[15]-Y[15],J}function _Z0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J[4]=X[4]*Y,J[5]=X[5]*Y,J[6]=X[6]*Y,J[7]=X[7]*Y,J[8]=X[8]*Y,J[9]=X[9]*Y,J[10]=X[10]*Y,J[11]=X[11]*Y,J[12]=X[12]*Y,J[13]=X[13]*Y,J[14]=X[14]*Y,J[15]=X[15]*Y,J}function EZ0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J[4]=X[4]+Y[4]*Z,J[5]=X[5]+Y[5]*Z,J[6]=X[6]+Y[6]*Z,J[7]=X[7]+Y[7]*Z,J[8]=X[8]+Y[8]*Z,J[9]=X[9]+Y[9]*Z,J[10]=X[10]+Y[10]*Z,J[11]=X[11]+Y[11]*Z,J[12]=X[12]+Y[12]*Z,J[13]=X[13]+Y[13]*Z,J[14]=X[14]+Y[14]*Z,J[15]=X[15]+Y[15]*Z,J}function CZ0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]&&J[4]===X[4]&&J[5]===X[5]&&J[6]===X[6]&&J[7]===X[7]&&J[8]===X[8]&&J[9]===X[9]&&J[10]===X[10]&&J[11]===X[11]&&J[12]===X[12]&&J[13]===X[13]&&J[14]===X[14]&&J[15]===X[15]}function SZ0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=J[4],K=J[5],G=J[6],F=J[7],q=J[8],H=J[9],z=J[10],V=J[11],M=J[12],R=J[13],L=J[14],w=J[15],P=X[0],N=X[1],v=X[2],j=X[3],O=X[4],D=X[5],_=X[6],C=X[7],S=X[8],I=X[9],f=X[10],y=X[11],h=X[12],g=X[13],J0=X[14],p0=X[15];return Math.abs(Y-P)<=l*Math.max(1,Math.abs(Y),Math.abs(P))&&Math.abs(Z-N)<=l*Math.max(1,Math.abs(Z),Math.abs(N))&&Math.abs(W-v)<=l*Math.max(1,Math.abs(W),Math.abs(v))&&Math.abs($-j)<=l*Math.max(1,Math.abs($),Math.abs(j))&&Math.abs(Q-O)<=l*Math.max(1,Math.abs(Q),Math.abs(O))&&Math.abs(K-D)<=l*Math.max(1,Math.abs(K),Math.abs(D))&&Math.abs(G-_)<=l*Math.max(1,Math.abs(G),Math.abs(_))&&Math.abs(F-C)<=l*Math.max(1,Math.abs(F),Math.abs(C))&&Math.abs(q-S)<=l*Math.max(1,Math.abs(q),Math.abs(S))&&Math.abs(H-I)<=l*Math.max(1,Math.abs(H),Math.abs(I))&&Math.abs(z-f)<=l*Math.max(1,Math.abs(z),Math.abs(f))&&Math.abs(V-y)<=l*Math.max(1,Math.abs(V),Math.abs(y))&&Math.abs(M-h)<=l*Math.max(1,Math.abs(M),Math.abs(h))&&Math.abs(R-g)<=l*Math.max(1,Math.abs(R),Math.abs(g))&&Math.abs(L-J0)<=l*Math.max(1,Math.abs(L),Math.abs(J0))&&Math.abs(w-p0)<=l*Math.max(1,Math.abs(w),Math.abs(p0))}var IZ0=bC,hZ0=cC;var N0={};k6(N0,{str:()=>EW0,squaredLength:()=>MS,sqrLen:()=>yW0,sqlerp:()=>lW0,slerp:()=>H$,setAxisAngle:()=>GS,setAxes:()=>uW0,set:()=>hW0,scale:()=>LS,rotationTo:()=>mW0,rotateZ:()=>vW0,rotateY:()=>NW0,rotateX:()=>PW0,random:()=>kW0,pow:()=>jW0,normalize:()=>kH,multiply:()=>FS,mul:()=>bW0,ln:()=>HS,lerp:()=>pW0,length:()=>VS,len:()=>AW0,invert:()=>TW0,identity:()=>wW0,getAxisAngle:()=>OW0,getAngle:()=>xW0,fromValues:()=>SW0,fromMat3:()=>zS,fromEuler:()=>_W0,exp:()=>qS,exactEquals:()=>gW0,equals:()=>cW0,dot:()=>US,create:()=>jH,copy:()=>IW0,conjugate:()=>DW0,clone:()=>CW0,calculateW:()=>BW0,add:()=>fW0});var W0={};k6(W0,{zero:()=>$W0,transformQuat:()=>JW0,transformMat4:()=>tZ0,transformMat3:()=>eZ0,subtract:()=>lC,sub:()=>FW0,str:()=>QW0,squaredLength:()=>aC,squaredDistance:()=>nC,sqrLen:()=>UW0,sqrDist:()=>LW0,set:()=>pZ0,scaleAndAdd:()=>dZ0,scale:()=>uZ0,round:()=>lZ0,rotateZ:()=>ZW0,rotateY:()=>YW0,rotateX:()=>XW0,random:()=>rZ0,normalize:()=>vH,negate:()=>iZ0,multiply:()=>uC,mul:()=>qW0,min:()=>cZ0,max:()=>mZ0,lerp:()=>aZ0,length:()=>mC,len:()=>BH,inverse:()=>nZ0,hermite:()=>sZ0,fromValues:()=>F$,forEach:()=>VW0,floor:()=>gZ0,exactEquals:()=>KW0,equals:()=>GW0,dot:()=>q$,divide:()=>dC,div:()=>HW0,distance:()=>iC,dist:()=>zW0,cross:()=>bJ,create:()=>G$,copy:()=>bZ0,clone:()=>fZ0,ceil:()=>yZ0,bezier:()=>oZ0,angle:()=>WW0,add:()=>AZ0});function G$(){var J=new Q0(3);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function fZ0(J){var X=new Q0(3);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X}function mC(J){var X=J[0],Y=J[1],Z=J[2];return Math.hypot(X,Y,Z)}function F$(J,X,Y){var Z=new Q0(3);return Z[0]=J,Z[1]=X,Z[2]=Y,Z}function bZ0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J}function pZ0(J,X,Y,Z){return J[0]=X,J[1]=Y,J[2]=Z,J}function AZ0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J}function lC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J}function uC(J,X,Y){return J[0]=X[0]*Y[0],J[1]=X[1]*Y[1],J[2]=X[2]*Y[2],J}function dC(J,X,Y){return J[0]=X[0]/Y[0],J[1]=X[1]/Y[1],J[2]=X[2]/Y[2],J}function yZ0(J,X){return J[0]=Math.ceil(X[0]),J[1]=Math.ceil(X[1]),J[2]=Math.ceil(X[2]),J}function gZ0(J,X){return J[0]=Math.floor(X[0]),J[1]=Math.floor(X[1]),J[2]=Math.floor(X[2]),J}function cZ0(J,X,Y){return J[0]=Math.min(X[0],Y[0]),J[1]=Math.min(X[1],Y[1]),J[2]=Math.min(X[2],Y[2]),J}function mZ0(J,X,Y){return J[0]=Math.max(X[0],Y[0]),J[1]=Math.max(X[1],Y[1]),J[2]=Math.max(X[2],Y[2]),J}function lZ0(J,X){return J[0]=Math.round(X[0]),J[1]=Math.round(X[1]),J[2]=Math.round(X[2]),J}function uZ0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J}function dZ0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J}function iC(J,X){var Y=X[0]-J[0],Z=X[1]-J[1],W=X[2]-J[2];return Math.hypot(Y,Z,W)}function nC(J,X){var Y=X[0]-J[0],Z=X[1]-J[1],W=X[2]-J[2];return Y*Y+Z*Z+W*W}function aC(J){var X=J[0],Y=J[1],Z=J[2];return X*X+Y*Y+Z*Z}function iZ0(J,X){return J[0]=-X[0],J[1]=-X[1],J[2]=-X[2],J}function nZ0(J,X){return J[0]=1/X[0],J[1]=1/X[1],J[2]=1/X[2],J}function vH(J,X){var Y=X[0],Z=X[1],W=X[2],$=Y*Y+Z*Z+W*W;if($>0)$=1/Math.sqrt($);return J[0]=X[0]*$,J[1]=X[1]*$,J[2]=X[2]*$,J}function q$(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]}function bJ(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[0],K=Y[1],G=Y[2];return J[0]=W*G-$*K,J[1]=$*Q-Z*G,J[2]=Z*K-W*Q,J}function aZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J[2]=Q+Z*(Y[2]-Q),J}function sZ0(J,X,Y,Z,W,$){var Q=$*$,K=Q*(2*$-3)+1,G=Q*($-2)+$,F=Q*($-1),q=Q*(3-2*$);return J[0]=X[0]*K+Y[0]*G+Z[0]*F+W[0]*q,J[1]=X[1]*K+Y[1]*G+Z[1]*F+W[1]*q,J[2]=X[2]*K+Y[2]*G+Z[2]*F+W[2]*q,J}function oZ0(J,X,Y,Z,W,$){var Q=1-$,K=Q*Q,G=$*$,F=K*Q,q=3*$*K,H=3*G*Q,z=G*$;return J[0]=X[0]*F+Y[0]*q+Z[0]*H+W[0]*z,J[1]=X[1]*F+Y[1]*q+Z[1]*H+W[1]*z,J[2]=X[2]*F+Y[2]*q+Z[2]*H+W[2]*z,J}function rZ0(J,X){X=X||1;var Y=d6()*2*Math.PI,Z=d6()*2-1,W=Math.sqrt(1-Z*Z)*X;return J[0]=Math.cos(Y)*W,J[1]=Math.sin(Y)*W,J[2]=Z*X,J}function tZ0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[3]*Z+Y[7]*W+Y[11]*$+Y[15];return Q=Q||1,J[0]=(Y[0]*Z+Y[4]*W+Y[8]*$+Y[12])/Q,J[1]=(Y[1]*Z+Y[5]*W+Y[9]*$+Y[13])/Q,J[2]=(Y[2]*Z+Y[6]*W+Y[10]*$+Y[14])/Q,J}function eZ0(J,X,Y){var Z=X[0],W=X[1],$=X[2];return J[0]=Z*Y[0]+W*Y[3]+$*Y[6],J[1]=Z*Y[1]+W*Y[4]+$*Y[7],J[2]=Z*Y[2]+W*Y[5]+$*Y[8],J}function JW0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q=Y[3],K=X[0],G=X[1],F=X[2],q=W*F-$*G,H=$*K-Z*F,z=Z*G-W*K,V=W*z-$*H,M=$*q-Z*z,R=Z*H-W*q,L=Q*2;return q*=L,H*=L,z*=L,V*=2,M*=2,R*=2,J[0]=K+q+V,J[1]=G+H+M,J[2]=F+z+R,J}function XW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[0],$[1]=W[1]*Math.cos(Z)-W[2]*Math.sin(Z),$[2]=W[1]*Math.sin(Z)+W[2]*Math.cos(Z),J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function YW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[2]*Math.sin(Z)+W[0]*Math.cos(Z),$[1]=W[1],$[2]=W[2]*Math.cos(Z)-W[0]*Math.sin(Z),J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function ZW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[0]*Math.cos(Z)-W[1]*Math.sin(Z),$[1]=W[0]*Math.sin(Z)+W[1]*Math.cos(Z),$[2]=W[2],J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function WW0(J,X){var Y=J[0],Z=J[1],W=J[2],$=X[0],Q=X[1],K=X[2],G=Math.sqrt(Y*Y+Z*Z+W*W),F=Math.sqrt($*$+Q*Q+K*K),q=G*F,H=q&&q$(J,X)/q;return Math.acos(Math.min(Math.max(H,-1),1))}function $W0(J){return J[0]=0,J[1]=0,J[2]=0,J}function QW0(J){return"vec3("+J[0]+", "+J[1]+", "+J[2]+")"}function KW0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]}function GW0(J,X){var Y=J[0],Z=J[1],W=J[2],$=X[0],Q=X[1],K=X[2];return Math.abs(Y-$)<=l*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(Z-Q)<=l*Math.max(1,Math.abs(Z),Math.abs(Q))&&Math.abs(W-K)<=l*Math.max(1,Math.abs(W),Math.abs(K))}var FW0=lC,qW0=uC,HW0=dC,zW0=iC,LW0=nC,BH=mC,UW0=aC,VW0=function(){var J=G$();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}}();function MW0(){var J=new Q0(4);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}function sC(J){var X=new Q0(4);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X}function oC(J,X,Y,Z){var W=new Q0(4);return W[0]=J,W[1]=X,W[2]=Y,W[3]=Z,W}function rC(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J}function tC(J,X,Y,Z,W){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J}function eC(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J}function JS(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J}function XS(J){var X=J[0],Y=J[1],Z=J[2],W=J[3];return Math.hypot(X,Y,Z,W)}function YS(J){var X=J[0],Y=J[1],Z=J[2],W=J[3];return X*X+Y*Y+Z*Z+W*W}function ZS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*Y+Z*Z+W*W+$*$;if(Q>0)Q=1/Math.sqrt(Q);return J[0]=Y*Q,J[1]=Z*Q,J[2]=W*Q,J[3]=$*Q,J}function WS(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]+J[3]*X[3]}function $S(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J[2]=Q+Z*(Y[2]-Q),J[3]=K+Z*(Y[3]-K),J}function QS(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]}function KS(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=X[0],K=X[1],G=X[2],F=X[3];return Math.abs(Y-Q)<=l*Math.max(1,Math.abs(Y),Math.abs(Q))&&Math.abs(Z-K)<=l*Math.max(1,Math.abs(Z),Math.abs(K))&&Math.abs(W-G)<=l*Math.max(1,Math.abs(W),Math.abs(G))&&Math.abs($-F)<=l*Math.max(1,Math.abs($),Math.abs(F))}var U_0=function(){var J=MW0();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=4;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],J[3]=X[K+3],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2],X[K+3]=J[3];return X}}();function jH(){var J=new Q0(4);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J[3]=1,J}function wW0(J){return J[0]=0,J[1]=0,J[2]=0,J[3]=1,J}function GS(J,X,Y){Y=Y*0.5;var Z=Math.sin(Y);return J[0]=Z*X[0],J[1]=Z*X[1],J[2]=Z*X[2],J[3]=Math.cos(Y),J}function OW0(J,X){var Y=Math.acos(X[3])*2,Z=Math.sin(Y/2);if(Z>l)J[0]=X[0]/Z,J[1]=X[1]/Z,J[2]=X[2]/Z;else J[0]=1,J[1]=0,J[2]=0;return Y}function xW0(J,X){var Y=US(J,X);return Math.acos(2*Y*Y-1)}function FS(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1],F=Y[2],q=Y[3];return J[0]=Z*q+Q*K+W*F-$*G,J[1]=W*q+Q*G+$*K-Z*F,J[2]=$*q+Q*F+Z*G-W*K,J[3]=Q*q-Z*K-W*G-$*F,J}function PW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+Q*K,J[1]=W*G+$*K,J[2]=$*G-W*K,J[3]=Q*G-Z*K,J}function NW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G-$*K,J[1]=W*G+Q*K,J[2]=$*G+Z*K,J[3]=Q*G-W*K,J}function vW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+W*K,J[1]=W*G-Z*K,J[2]=$*G+Q*K,J[3]=Q*G-$*K,J}function BW0(J,X){var Y=X[0],Z=X[1],W=X[2];return J[0]=Y,J[1]=Z,J[2]=W,J[3]=Math.sqrt(Math.abs(1-Y*Y-Z*Z-W*W)),J}function qS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Math.sqrt(Y*Y+Z*Z+W*W),K=Math.exp($),G=Q>0?K*Math.sin(Q)/Q:0;return J[0]=Y*G,J[1]=Z*G,J[2]=W*G,J[3]=K*Math.cos(Q),J}function HS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Math.sqrt(Y*Y+Z*Z+W*W),K=Q>0?Math.atan2(Q,$)/Q:0;return J[0]=Y*K,J[1]=Z*K,J[2]=W*K,J[3]=0.5*Math.log(Y*Y+Z*Z+W*W+$*$),J}function jW0(J,X,Y){return HS(J,X),LS(J,J,Y),qS(J,J),J}function H$(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3],G=Y[0],F=Y[1],q=Y[2],H=Y[3],z,V,M,R,L;if(V=W*G+$*F+Q*q+K*H,V<0)V=-V,G=-G,F=-F,q=-q,H=-H;if(1-V>l)z=Math.acos(V),M=Math.sin(z),R=Math.sin((1-Z)*z)/M,L=Math.sin(Z*z)/M;else R=1-Z,L=Z;return J[0]=R*W+L*G,J[1]=R*$+L*F,J[2]=R*Q+L*q,J[3]=R*K+L*H,J}function kW0(J){var X=d6(),Y=d6(),Z=d6(),W=Math.sqrt(1-X),$=Math.sqrt(X);return J[0]=W*Math.sin(2*Math.PI*Y),J[1]=W*Math.cos(2*Math.PI*Y),J[2]=$*Math.sin(2*Math.PI*Z),J[3]=$*Math.cos(2*Math.PI*Z),J}function TW0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*Y+Z*Z+W*W+$*$,K=Q?1/Q:0;return J[0]=-Y*K,J[1]=-Z*K,J[2]=-W*K,J[3]=$*K,J}function DW0(J,X){return J[0]=-X[0],J[1]=-X[1],J[2]=-X[2],J[3]=X[3],J}function zS(J,X){var Y=X[0]+X[4]+X[8],Z;if(Y>0)Z=Math.sqrt(Y+1),J[3]=0.5*Z,Z=0.5/Z,J[0]=(X[5]-X[7])*Z,J[1]=(X[6]-X[2])*Z,J[2]=(X[1]-X[3])*Z;else{var W=0;if(X[4]>X[0])W=1;if(X[8]>X[W*3+W])W=2;var $=(W+1)%3,Q=(W+2)%3;Z=Math.sqrt(X[W*3+W]-X[$*3+$]-X[Q*3+Q]+1),J[W]=0.5*Z,Z=0.5/Z,J[3]=(X[$*3+Q]-X[Q*3+$])*Z,J[$]=(X[$*3+W]+X[W*3+$])*Z,J[Q]=(X[Q*3+W]+X[W*3+Q])*Z}return J}function _W0(J,X,Y,Z){var W=0.5*Math.PI/180;X*=W,Y*=W,Z*=W;var $=Math.sin(X),Q=Math.cos(X),K=Math.sin(Y),G=Math.cos(Y),F=Math.sin(Z),q=Math.cos(Z);return J[0]=$*G*q-Q*K*F,J[1]=Q*K*q+$*G*F,J[2]=Q*G*F-$*K*q,J[3]=Q*G*q+$*K*F,J}function EW0(J){return"quat("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}var CW0=sC,SW0=oC,IW0=rC,hW0=tC,fW0=eC,bW0=FS,LS=JS,US=WS,pW0=$S,VS=XS,AW0=VS,MS=YS,yW0=MS,kH=ZS,gW0=QS,cW0=KS,mW0=function(){var J=G$(),X=F$(1,0,0),Y=F$(0,1,0);return function(Z,W,$){var Q=q$(W,$);if(Q<-0.999999){if(bJ(J,X,W),BH(J)<0.000001)bJ(J,Y,W);return vH(J,J),GS(Z,J,Math.PI),Z}else if(Q>0.999999)return Z[0]=0,Z[1]=0,Z[2]=0,Z[3]=1,Z;else return bJ(J,W,$),Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=1+Q,kH(Z,Z)}}(),lW0=function(){var J=jH(),X=jH();return function(Y,Z,W,$,Q,K){return H$(J,Z,Q,K),H$(X,W,$,K),H$(Y,J,X,2*K*(1-K)),Y}}(),uW0=function(){var J=NH();return function(X,Y,Z,W){return J[0]=Z[0],J[3]=Z[1],J[6]=Z[2],J[1]=W[0],J[4]=W[1],J[7]=W[2],J[2]=-Y[0],J[5]=-Y[1],J[8]=-Y[2],kH(X,zS(X,J))}}();var q0={};k6(q0,{zero:()=>M$0,transformMat4:()=>L$0,transformMat3:()=>z$0,transformMat2d:()=>H$0,transformMat2:()=>q$0,subtract:()=>wS,sub:()=>P$0,str:()=>R$0,squaredLength:()=>BS,squaredDistance:()=>NS,sqrLen:()=>k$0,sqrDist:()=>j$0,set:()=>aW0,scaleAndAdd:()=>Y$0,scale:()=>X$0,round:()=>J$0,rotate:()=>U$0,random:()=>F$0,normalize:()=>$$0,negate:()=>Z$0,multiply:()=>OS,mul:()=>N$0,min:()=>tW0,max:()=>eW0,lerp:()=>G$0,length:()=>vS,len:()=>x$0,inverse:()=>W$0,fromValues:()=>iW0,forEach:()=>T$0,floor:()=>rW0,exactEquals:()=>w$0,equals:()=>O$0,dot:()=>Q$0,divide:()=>xS,div:()=>v$0,distance:()=>PS,dist:()=>B$0,cross:()=>K$0,create:()=>RS,copy:()=>nW0,clone:()=>dW0,ceil:()=>oW0,angle:()=>V$0,add:()=>sW0});function RS(){var J=new Q0(2);if(Q0!=Float32Array)J[0]=0,J[1]=0;return J}function dW0(J){var X=new Q0(2);return X[0]=J[0],X[1]=J[1],X}function iW0(J,X){var Y=new Q0(2);return Y[0]=J,Y[1]=X,Y}function nW0(J,X){return J[0]=X[0],J[1]=X[1],J}function aW0(J,X,Y){return J[0]=X,J[1]=Y,J}function sW0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J}function wS(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J}function OS(J,X,Y){return J[0]=X[0]*Y[0],J[1]=X[1]*Y[1],J}function xS(J,X,Y){return J[0]=X[0]/Y[0],J[1]=X[1]/Y[1],J}function oW0(J,X){return J[0]=Math.ceil(X[0]),J[1]=Math.ceil(X[1]),J}function rW0(J,X){return J[0]=Math.floor(X[0]),J[1]=Math.floor(X[1]),J}function tW0(J,X,Y){return J[0]=Math.min(X[0],Y[0]),J[1]=Math.min(X[1],Y[1]),J}function eW0(J,X,Y){return J[0]=Math.max(X[0],Y[0]),J[1]=Math.max(X[1],Y[1]),J}function J$0(J,X){return J[0]=Math.round(X[0]),J[1]=Math.round(X[1]),J}function X$0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J}function Y$0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J}function PS(J,X){var Y=X[0]-J[0],Z=X[1]-J[1];return Math.hypot(Y,Z)}function NS(J,X){var Y=X[0]-J[0],Z=X[1]-J[1];return Y*Y+Z*Z}function vS(J){var X=J[0],Y=J[1];return Math.hypot(X,Y)}function BS(J){var X=J[0],Y=J[1];return X*X+Y*Y}function Z$0(J,X){return J[0]=-X[0],J[1]=-X[1],J}function W$0(J,X){return J[0]=1/X[0],J[1]=1/X[1],J}function $$0(J,X){var Y=X[0],Z=X[1],W=Y*Y+Z*Z;if(W>0)W=1/Math.sqrt(W);return J[0]=X[0]*W,J[1]=X[1]*W,J}function Q$0(J,X){return J[0]*X[0]+J[1]*X[1]}function K$0(J,X,Y){var Z=X[0]*Y[1]-X[1]*Y[0];return J[0]=J[1]=0,J[2]=Z,J}function G$0(J,X,Y,Z){var W=X[0],$=X[1];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J}function F$0(J,X){X=X||1;var Y=d6()*2*Math.PI;return J[0]=Math.cos(Y)*X,J[1]=Math.sin(Y)*X,J}function q$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[2]*W,J[1]=Y[1]*Z+Y[3]*W,J}function H$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[2]*W+Y[4],J[1]=Y[1]*Z+Y[3]*W+Y[5],J}function z$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[3]*W+Y[6],J[1]=Y[1]*Z+Y[4]*W+Y[7],J}function L$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[4]*W+Y[12],J[1]=Y[1]*Z+Y[5]*W+Y[13],J}function U$0(J,X,Y,Z){var W=X[0]-Y[0],$=X[1]-Y[1],Q=Math.sin(Z),K=Math.cos(Z);return J[0]=W*K-$*Q+Y[0],J[1]=W*Q+$*K+Y[1],J}function V$0(J,X){var Y=J[0],Z=J[1],W=X[0],$=X[1],Q=Math.sqrt(Y*Y+Z*Z)*Math.sqrt(W*W+$*$),K=Q&&(Y*W+Z*$)/Q;return Math.acos(Math.min(Math.max(K,-1),1))}function M$0(J){return J[0]=0,J[1]=0,J}function R$0(J){return"vec2("+J[0]+", "+J[1]+")"}function w$0(J,X){return J[0]===X[0]&&J[1]===X[1]}function O$0(J,X){var Y=J[0],Z=J[1],W=X[0],$=X[1];return Math.abs(Y-W)<=l*Math.max(1,Math.abs(Y),Math.abs(W))&&Math.abs(Z-$)<=l*Math.max(1,Math.abs(Z),Math.abs($))}var x$0=vS,P$0=wS,N$0=OS,v$0=xS,B$0=PS,j$0=NS,k$0=BS,T$0=function(){var J=RS();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=2;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],$(J,J,Q),X[K]=J[0],X[K+1]=J[1];return X}}();class A9 extends Float32Array{constructor(J,X,Y,Z){super([J,X,Y,Z])}get determinant(){return e0.determinant(this)}get frobeniusNorm(){return e0.frob(this)}static create(){let J=new A9(0,0,0,0);return e0.identity(J),J}static fromRotation(J){let X=A9.create();return e0.fromRotation(X,J),X}static fromScaling(J){let X=A9.create();return e0.fromScaling(X,J),X}add(J){return e0.add(this,this,J),this}adjoint(){return e0.adjoint(this,this),this}clone(){return new A9(this[0],this[1],this[2],this[3])}copy(J){return e0.copy(this,J),this}equals(J){return e0.equals(this,J)}exactEquals(J){return e0.exactEquals(this,J)}identity(){return e0.identity(this),this}invert(){return e0.invert(this,this),this}multiply(J){return e0.mul(this,this,J),this}multiplyScalar(J){return e0.multiplyScalar(this,this,J),this}rotate(J){return e0.rotate(this,this,J),this}subtract(J){return e0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return e0.transpose(this,this),this}}class i6 extends Float32Array{constructor(J,X,Y,Z,W,$,Q,K,G){super([J,X,Y,Z,W,$,Q,K,G])}get determinant(){return h0.determinant(this)}get frobeniusNorm(){return h0.frob(this)}static create(){let J=new i6(0,0,0,0,0,0,0,0,0);return h0.identity(J),J}static fromMatrix4(J){let X=i6.create();return h0.fromMat4(X,J),X}static fromQuaternion(J){let X=i6.create();return h0.fromQuat(X,J),X}static fromRotation(J){let X=i6.create();return h0.fromRotation(X,J),X}static fromScaling(J){let X=i6.create();return h0.fromScaling(X,J),X}static fromTranslation(J){let X=i6.create();return h0.fromTranslation(X,J),X}add(J){return h0.add(this,this,J),this}adjoint(){return h0.adjoint(this,this),this}clone(){return new i6(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return h0.copy(this,J),this}equals(J){return h0.equals(this,J)}exactEquals(J){return h0.exactEquals(this,J)}identity(){return h0.identity(this),this}invert(){return h0.invert(this,this),this}multiply(J){return h0.mul(this,this,J),this}multiplyScalar(J){return h0.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,X){return h0.projection(this,J,X),this}rotate(J){return h0.rotate(this,this,J),this}subtract(J){return h0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]},${this[2]}][${this[3]},${this[4]},${this[5]}][${this[6]},${this[7]},${this[8]}]`}transpose(){return h0.transpose(this,this),this}}class E8 extends Float32Array{constructor(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R){super([J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R])}get determinant(){return Y0.determinant(this)}get frobeniusNorm(){return Y0.frob(this)}static create(){let J=new E8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return Y0.identity(J),J}static fromQuaternion(J){let X=E8.create();return Y0.fromQuat(X,J),X}static fromRotation(J,X){let Y=E8.create();return Y0.fromRotation(Y,J,X),Y}static fromRotationTranslation(J,X){let Y=E8.create();return Y0.fromRotationTranslation(Y,J,X),Y}static fromRotationTranslationScale(J,X,Y){let Z=E8.create();return Y0.fromRotationTranslationScale(Z,J,X,Y),Z}static fromRotationTranslationScaleOrigin(J,X,Y,Z){let W=E8.create();return Y0.fromRotationTranslationScaleOrigin(W,J,X,Y,Z),W}static fromScaling(J){let X=E8.create();return Y0.fromScaling(X,J),X}static fromTranslation(J){let X=E8.create();return Y0.fromTranslation(X,J),X}static fromXRotation(J){let X=E8.create();return Y0.fromXRotation(X,J),X}static fromYRotation(J){let X=E8.create();return Y0.fromYRotation(X,J),X}static fromZRotation(J){let X=E8.create();return Y0.fromZRotation(X,J),X}add(J){return Y0.add(this,this,J),this}adjoint(){return Y0.adjoint(this,this),this}clone(){return new E8(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8],this[9],this[10],this[11],this[12],this[13],this[14],this[15])}copy(J){return Y0.copy(this,J),this}equals(J){return Y0.equals(this,J)}exactEquals(J){return Y0.exactEquals(this,J)}frustrum(J,X,Y,Z,W,$){return Y0.frustum(this,J,X,Y,Z,W,$),this}identity(){return Y0.identity(this),this}invert(){return Y0.invert(this,this),this}lookAt(J,X,Y){return Y0.lookAt(this,J,X,Y),this}multiply(J){return Y0.mul(this,this,J),this}multiplyScalar(J){return Y0.multiplyScalar(this,this,J),this}orthographic(J,X,Y,Z,W,$){return Y0.ortho(this,J,X,Y,Z,W,$),this}perspective(J,X,Y,Z){return Y0.perspective(this,J,X,Y,Z),this}rotate(J,X){return Y0.rotate(this,this,J,X),this}rotateX(J){return Y0.rotateX(this,this,J),this}rotateY(J){return Y0.rotateY(this,this,J),this}rotateZ(J){return Y0.rotateZ(this,this,J),this}scale(J){return Y0.scale(this,this,J),this}subtract(J){return Y0.sub(this,this,J),this}targetTo(J,X,Y){return Y0.targetTo(this,J,X,Y),this}toString(){return`[${this[0]},${this[1]},${this[2]},${this[3]}][${this[4]},${this[5]},${this[6]},${this[7]}][${this[8]},${this[9]},${this[10]},${this[11]}][${this[12]},${this[13]},${this[14]},${this[15]}]`}translate(J){return Y0.translate(this,this,J),this}transpose(){return Y0.transpose(this,this),this}}class J4 extends Float32Array{constructor(J,X,Y,Z){super([J,X,Y,Z])}get length(){return N0.length(this)}get squaredLength(){return N0.squaredLength(this)}get magnitude(){return N0.length(this)}get squaredMagnitude(){return N0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}get w(){return this[3]}set w(J){this[3]=J}static fromEuler(J,X,Y){let Z=N0.fromEuler(new Float32Array(4),J,X,Y);return new J4(Z[0],Z[1],Z[2],Z[3])}static fromQuaternionLike(J){return new J4(J.x,J.y,J.z,J.w)}clone(){return new J4(this.x,this.y,this.z,this.w)}conjugate(){return N0.conjugate(this,this),this}copy(J){return N0.copy(this,J),this}dot(J){return N0.dot(this,J)}exponential(){return N0.exp(this,this),this}equals(J){return N0.equals(this,J)}exactEquals(J){return N0.exactEquals(this,J)}getAngle(J){return N0.getAngle(this,J)}identity(){return N0.identity(this),this}invert(){return N0.invert(this,this),this}lerp(J,X){return N0.lerp(this,this,J,X),this}logarithm(){return N0.ln(this,this),this}multiply(J){return N0.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return N0.normalize(this,this),this}power(J){return N0.pow(this,this,J),this}randomize(){return N0.random(this),this}rotateX(J){return N0.rotateX(this,this,J),this}rotateY(J){return N0.rotateY(this,this,J),this}rotateZ(J){return N0.rotateZ(this,this,J),this}scale(J){return N0.scale(this,this,J),this}setAxisAngle(J,X){return N0.setAxisAngle(this,J,X),this}slerp(J,X){return N0.slerp(this,this,J,X),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}class pJ extends Float32Array{constructor(J,X){super([J,X])}get length(){return q0.length(this)}get squaredLength(){return q0.squaredLength(this)}get magnitude(){return q0.length(this)}get squaredMagnitude(){return q0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}static create(){return new pJ(0,0)}add(J){return q0.add(this,this,J),this}angle(J){return q0.angle(this,J)}ceil(){return q0.ceil(this,this),this}clone(){return new pJ(this.x,this.y)}copy(J){return q0.copy(this,J),this}distance(J){return q0.distance(this,J)}divide(J){return q0.divide(this,this,J),this}dot(J){return q0.dot(this,J)}equals(J){return q0.equals(this,J)}exactEquals(J){return q0.exactEquals(this,J)}floor(){return q0.floor(this,this),this}invert(){return q0.inverse(this,this),this}lerp(J,X){return q0.lerp(this,this,J,X),this}max(J){return q0.max(this,this,J),this}min(J){return q0.min(this,this,J),this}multiply(J){return q0.mul(this,this,J),this}negate(){return q0.negate(this,this),this}normalize(){return q0.normalize(this,this),this}randomize(J){return q0.random(this,J),this}rotate(J,X){return q0.rotate(this,this,J,X),this}round(){return q0.round(this,this),this}scale(J){return q0.scale(this,this,J),this}scaleAndAdd(J,X){return q0.scaleAndAdd(this,this,J,X),this}subtract(J){return q0.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return q0.transformMat2(this,this,J),this}transformMatrix3(J){return q0.transformMat3(this,this,J),this}transformMatrix4(J){return q0.transformMat4(this,this,J),this}zero(){return q0.zero(this),this}}class X4 extends Float32Array{constructor(J,X,Y){super([J,X,Y])}get length(){return W0.length(this)}get squaredLength(){return W0.squaredLength(this)}get magnitude(){return W0.length(this)}get squaredMagnitude(){return W0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}static create(){return new X4(0,0,0)}static fromVector3Like(J){return new X4(J.x,J.y,J.z)}add(J){return W0.add(this,this,J),this}ceil(){return W0.ceil(this,this),this}clone(){return new X4(this.x,this.y,this.z)}copy(J){return W0.copy(this,J),this}cross(J){return W0.cross(this,this,J),this}distance(J){return W0.distance(this,J)}divide(J){return W0.div(this,this,J),this}dot(J){return W0.dot(this,J)}equals(J){return W0.equals(this,J)}exactEquals(J){return W0.exactEquals(this,J)}floor(){return W0.floor(this,this),this}invert(){return W0.inverse(this,this),this}lerp(J,X){return W0.lerp(this,this,J,X),this}max(J){return W0.max(this,this,J),this}min(J){return W0.min(this,this,J),this}multiply(J){return W0.mul(this,this,J),this}negate(){return W0.negate(this,this),this}normalize(){return W0.normalize(this,this),this}randomize(J){return W0.random(this,J),this}rotateX(J,X){return W0.rotateX(this,this,J,X),this}rotateY(J,X){return W0.rotateY(this,this,J,X),this}rotateZ(J,X){return W0.rotateZ(this,this,J,X),this}round(){return W0.round(this,this),this}scale(J){return W0.scale(this,this,J),this}scaleAndAdd(J,X){return W0.scaleAndAdd(this,this,J,X),this}subtract(J){return W0.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return W0.transformMat3(this,this,J),this}transformMatrix4(J){return W0.transformMat4(this,this,J),this}transformQuaternion(J){return W0.transformQuat(this,this,J),this}zero(){return W0.zero(this),this}}var v0=function(J,X,Y,Z){function W($){return $ instanceof Y?$:new Y(function(Q){Q($)})}return new(Y||(Y=Promise))(function($,Q){function K(q){try{F(Z.next(q))}catch(H){Q(H)}}function G(q){try{F(Z.throw(q))}catch(H){Q(H)}}function F(q){q.done?$(q.value):W(q.value).then(K,G)}F((Z=Z.apply(J,X||[])).next())})},P0=function(J,X){var Y={label:0,sent:function(){if($[0]&1)throw $[1];return $[1]},trys:[],ops:[]},Z,W,$,Q=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return Q.next=K(0),Q.throw=K(1),Q.return=K(2),typeof Symbol==="function"&&(Q[Symbol.iterator]=function(){return this}),Q;function K(F){return function(q){return G([F,q])}}function G(F){if(Z)throw new TypeError("Generator is already executing.");while(Q&&(Q=0,F[0]&&(Y=0)),Y)try{if(Z=1,W&&($=F[0]&2?W.return:F[0]?W.throw||(($=W.return)&&$.call(W),0):W.next)&&!($=$.call(W,F[1])).done)return $;if(W=0,$)F=[F[0]&2,$.value];switch(F[0]){case 0:case 1:$=F;break;case 4:return Y.label++,{value:F[1],done:!1};case 5:Y.label++,W=F[1],F=[0];continue;case 7:F=Y.ops.pop(),Y.trys.pop();continue;default:if(($=Y.trys,!($=$.length>0&&$[$.length-1]))&&(F[0]===6||F[0]===2)){Y=0;continue}if(F[0]===3&&(!$||F[1]>$[0]&&F[1]<$[3])){Y.label=F[1];break}if(F[0]===6&&Y.label<$[1]){Y.label=$[1],$=F;break}if($&&Y.label<$[2]){Y.label=$[2],Y.ops.push(F);break}if($[2])Y.ops.pop();Y.trys.pop();continue}F=X.call(J,Y)}catch(q){F=[6,q],W=0}finally{Z=$=0}if(F[0]&5)throw F[1];return{value:F[0]?F[1]:void 0,done:!0}}},c8=function(J,X){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var Z=Y.call(J),W,$=[],Q;try{while((X===void 0||X-- >0)&&!(W=Z.next()).done)$.push(W.value)}catch(K){Q={error:K}}finally{try{if(W&&!W.done&&(Y=Z.return))Y.call(Z)}finally{if(Q)throw Q.error}}return $},$6=function(J,X,Y){if(Y||arguments.length===2){for(var Z=0,W=X.length,$;Z<W;Z++)if($||!(Z in X)){if(!$)$=Array.prototype.slice.call(X,0,Z);$[Z]=X[Z]}}return J.concat($||Array.prototype.slice.call(X))},jS=function(J){var X=typeof Symbol==="function"&&Symbol.iterator,Y=X&&J[X],Z=0;if(Y)return Y.call(J);if(J&&typeof J.length==="number")return{next:function(){if(J&&Z>=J.length)J=void 0;return{value:J&&J[Z++],done:!J}}};throw new TypeError(X?"Object is not iterable.":"Symbol.iterator is not defined.")},P_0=function(){function J(X){if(X===void 0)X=J.minComparator;var Y=this;this.compare=X,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(Z,W){return Y.compare(Z,W).then(function($){return-1*$})}}return J.getChildrenIndexOf=function(X){return[X*2+1,X*2+2]},J.getParentIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:2;return Math.floor((X-Y)/2)},J.getSiblingIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:-1;return X+Y},J.minComparator=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){if(X>Y)return[2,1];else if(X<Y)return[2,-1];else return[2,0]})})},J.maxComparator=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){if(Y>X)return[2,1];else if(Y<X)return[2,-1];else return[2,0]})})},J.minComparatorNumber=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,X-Y]})})},J.maxComparatorNumber=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,Y-X]})})},J.defaultIsEqual=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,X===Y]})})},J.print=function(X){function Y(q){var H=J.getParentIndexOf(q);return Math.floor(Math.log2(H+1))}function Z(q,H){var z="";for(;H>0;--H)z+=q;return z}var W=0,$=[],Q=Y(X.length-1)+2,K=0;while(W<X.length){var G=Y(W)+1;if(W===0)G=0;var F=String(X.get(W));if(F.length>K)K=F.length;$[G]=$[G]||[],$[G].push(F),W+=1}return $.map(function(q,H){var z=Math.pow(2,Q-H)-1;return Z(" ",Math.floor(z/2)*K)+q.map(function(V){var M=(K-V.length)/2;return Z(" ",Math.ceil(M))+V+Z(" ",Math.floor(M))}).join(Z(" ",z*K))}).join(`
|
385
|
+
`),X.write($),X.end();return}X.setNoDelay(!0),this.emitWithGlobal("WEBSERVER.UPGRADE",{req:J,socket:X,head:Y})};_onError=(J)=>{this.emitWithGlobal("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{this.emitWithGlobal("WEBSERVER.STOPPED",{})}}class i1 extends s{static instance=new i1;_wss;_wrtcMinPort=process.env.WRTC_MIN_PORT?parseInt(process.env.WRTC_MIN_PORT):40000;_wrtcMaxPort=process.env.WRTC_MAX_PORT?parseInt(process.env.WRTC_MAX_PORT):41023;_wrtcPublicIpv4=process.env.NODE_ENV==="production"?process.env.WRTC_PUBLIC_IPV4:"127.0.0.1";_wrtcPublicIpv6=process.env.NODE_ENV==="production"?process.env.WRTC_PUBLIC_IPV6:"::";_wrtcRouter=null;_wrtcWorker=null;constructor(){super();this._wss=new gX0({noServer:!0}),this._wss.on("connection",this._onConnection),this._wss.on("error",this._onError),this._initWrtc().catch((J)=>{E.warning(`Socket._constructor(): Failed to initialize WebRTC, falling back to Websockets. This can be ignored for local development. Error: ${J.message}`)}),m8.on("WEBSERVER.UPGRADE",({req:J,socket:X,head:Y})=>this._onUpgrade(J,X,Y))}get isWrtcEnabled(){return this._wrtcWorker&&!this._wrtcWorker.died&&this._wrtcRouter}get wrtcRouter(){return this._wrtcRouter}async createWrtcTransports(){if(!this.isWrtcEnabled)E.fatalError("Socket.createWrtcTransports(): WebRTC not enabled, unable to create transports.");let J={listenIps:[{ip:"::",announcedIp:this._wrtcPublicIpv6},{ip:"0.0.0.0",announcedIp:this._wrtcPublicIpv4}],preferUdp:!0,enableSctp:!0,enableTcp:!1},X=await this._wrtcRouter.createDirectTransport(),Y=await this._wrtcRouter.createWebRtcTransport(J),Z=await this._wrtcRouter.createWebRtcTransport(J);return{directTransport:X,clientServerTransport:Y,serverClientTransport:Z}}async _initWrtc(){if(!this._wrtcPublicIpv4||!this._wrtcPublicIpv6)throw new Error("Socket._initWrtc(): WebRTC disabled, falling back to Websockets. Env variables WRTC_PUBLIC_IPV4 and WRTC_PUBLIC_IPV6 must be set in production");this._wrtcWorker=await cX0.createWorker({rtcMinPort:this._wrtcMinPort,rtcMaxPort:this._wrtcMaxPort}),this._wrtcWorker.on("died",this._onWrtcWorkerDied),this._wrtcRouter=await this._wrtcWorker.createRouter({mediaCodecs:[]}),console.log("Socket._initWrtc(): WebRTC enabled and ready!")}_onConnection=(J,X)=>{new h9(J,X)};_onError=(J,X)=>{this.emitWithGlobal("SOCKET.ERROR",{ws:J,error:X})};_onUpgrade=(J,X,Y)=>{this._wss.handleUpgrade(J,X,Y,(Z)=>{this._wss.emit("connection",Z,J)})};_onWrtcWorkerDied=(J)=>{E.warning(`Socket._onWrtcWorkerDied(): WebRTC worker unexpectedly died, falling back to Websockets for all players. Internal error: ${J}`),j6.instance.getConnectedPlayers().forEach((X)=>{X.connection.closeWrtc()}),this._wrtcRouter?.close(),this._wrtcRouter=null,this._wrtcWorker?.close(),this._wrtcWorker=null}}class h9 extends s{static _serializedPackets=new WeakMap;_wrtcDirectTransport=null;_wrtcClientServerTransport=null;_wrtcClientServerDataProducers=[];_wrtcClientServerDataConsumers=[];_wrtcServerClientTransport=null;_wrtcServerClientReliableDataProducer=null;_wrtcServerClientUnreliableDataProducer=null;_wrtcServerClientDataConsumers=[];_ws;id;constructor(J,X){super();if(this.id=Yv(),this._ws=J,this._ws.binaryType="nodebuffer",this._ws.onmessage=(Y)=>this._onMessage(Y.data),this._ws.onclose=this._onWsClose,this._ws.onerror=this._onWsError,this.onPacket(A.PacketId.CONNECTION,this._onConnectionPacket),this.onPacket(A.PacketId.HEARTBEAT,this._onHeartbeatPacket),i1.instance.isWrtcEnabled)this._upgradeToWRTC();m8.emit("CONNECTION.OPENED",{connection:this,req:X})}static serializePackets(J){for(let W of J)if(!A.isValidPacket(W))return E.error(`Connection.serializePackets(): Invalid packet payload: ${JSON.stringify(W)}`);let X=h9._serializedPackets.get(J);if(X)return X;let Y=rF(J),Z=Buffer.from(Y.buffer,Y.byteOffset,Y.byteLength);return h9._serializedPackets.set(J,Z),Z}send(J,X=!0,Y=!1){if(this._ws.readyState!==mX0.OPEN)return E.warning("Connection.send(): Connection is not open.");try{let Z=h9.serializePackets(J);if(!Z)return;if(this._wrtcServerClientTransport?.iceState==="completed"&&Z.length<(this._wrtcServerClientTransport?.sctpParameters?.maxMessageSize??0)&&!Y)try{(X?this._wrtcServerClientReliableDataProducer:this._wrtcServerClientUnreliableDataProducer).send(Z)}catch{this._ws.send(Z)}else this._ws.send(Z);this.emitWithGlobal("CONNECTION.PACKETS_SENT",{connection:this,packets:J})}catch(Z){E.error(`Connection.send(): Packet send failed. Error: ${Z}`)}}close(){try{this.offAll(),this._ws.close()}catch(J){E.error(`Connection.close(): Connection close failed. Error: ${J}`)}}closeWrtc(){this._closeWrtcClientServerTransport(),this._closeWrtcServerClientTransport()}onPacket(J,X){this.on("CONNECTION.PACKET_RECEIVED",({packet:Y})=>{if(Y[0]===J)X(Y)})}_closeWrtcClientServerTransport(){this._wrtcDirectTransport?.close(),this._wrtcDirectTransport=null,this._wrtcClientServerTransport?.close(),this._wrtcClientServerTransport=null,this._wrtcClientServerDataProducers.forEach((J)=>J.close()),this._wrtcClientServerDataProducers=[],this._wrtcClientServerDataConsumers.forEach((J)=>J.close()),this._wrtcClientServerDataConsumers=[]}_closeWrtcServerClientTransport(){this._wrtcServerClientTransport?.close(),this._wrtcServerClientTransport=null,this._wrtcServerClientDataConsumers.forEach((J)=>J.close()),this._wrtcServerClientDataConsumers=[],this._wrtcServerClientReliableDataProducer?.close(),this._wrtcServerClientReliableDataProducer=null,this._wrtcServerClientUnreliableDataProducer?.close(),this._wrtcServerClientUnreliableDataProducer=null}_onConnectionPacket=async(J)=>{let X=J[1],Y=X.c,Z=X.d;if(Y){let{i:W,d:$}=Y,Q=!1;if(W==this._wrtcClientServerTransport?.id)await this._wrtcClientServerTransport.connect({dtlsParameters:$}),Q=!0;if(W==this._wrtcServerClientTransport?.id)await this._wrtcServerClientTransport.connect({dtlsParameters:$}),Q=!0;if(Q)this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{ca:{i:W}})])}if(Z)for(let W of Z){let{s:$,l:Q}=W,K=await this._wrtcClientServerTransport.produceData({label:Q,sctpStreamParameters:$}),G=await this._wrtcDirectTransport.consumeData({dataProducerId:K.id});this._wrtcClientServerDataProducers.push(K),this._wrtcClientServerDataConsumers.push(G),G.on("message",(F)=>this._onMessage(F)),this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{pa:{i:K.id,l:Q}})])}};_onHeartbeatPacket=()=>{this.send([A.createPacket(A.bidirectionalPackets.heartbeatPacketDefinition,null)],!0,!0)};_onMessage=(J)=>{try{let X=this._deserialize(J);if(!X)return;this.emitWithGlobal("CONNECTION.PACKET_RECEIVED",{connection:this,packet:X})}catch(X){E.error(`Connection._ws.onmessage(): Error: ${X}`)}};_onWrtcIceStateChange=(J,X)=>{if(["disconnected","closed"].includes(X)){if(J==this._wrtcClientServerTransport)this._closeWrtcClientServerTransport();else if(J==this._wrtcServerClientTransport)this._closeWrtcServerClientTransport()}};_onWsClose=()=>{this.closeWrtc(),this.emitWithGlobal("CONNECTION.CLOSED",{connection:this}),this.offAll()};_onWsError=(J)=>{this.emitWithGlobal("CONNECTION.ERROR",{connection:this,error:J})};_upgradeToWRTC=async()=>{let J=await i1.instance.createWrtcTransports();if(!J)return!1;let{directTransport:X,clientServerTransport:Y,serverClientTransport:Z}=J;this._wrtcDirectTransport=X,this._wrtcClientServerTransport=Y,this._wrtcClientServerTransport.on("icestatechange",(Q)=>{this._onWrtcIceStateChange(this._wrtcClientServerTransport,Q)}),this._wrtcServerClientTransport=Z,this._wrtcServerClientTransport.on("icestatechange",(Q)=>{this._onWrtcIceStateChange(this._wrtcServerClientTransport,Q)}),this._wrtcServerClientReliableDataProducer=await this._wrtcServerClientTransport.produceData({label:"scr",sctpStreamParameters:{streamId:0,ordered:!0}}),this._wrtcServerClientUnreliableDataProducer=await this._wrtcServerClientTransport.produceData({label:"scu",sctpStreamParameters:{streamId:1,ordered:!1,maxRetransmits:0}});let W=await this._wrtcServerClientTransport.consumeData({dataProducerId:this._wrtcServerClientReliableDataProducer.id}),$=await this._wrtcServerClientTransport.consumeData({dataProducerId:this._wrtcServerClientUnreliableDataProducer.id});return this._wrtcServerClientDataConsumers.push(W,$),this.send([A.createPacket(A.bidirectionalPackets.connectionPacketDefinition,{d:[{i:W.id,pi:W.dataProducerId,l:"scr",s:W.sctpStreamParameters},{i:$.id,pi:$.dataProducerId,l:"scu",s:$.sctpStreamParameters}],t:[{i:this._wrtcClientServerTransport.id,f:"cs",d:this._wrtcClientServerTransport.dtlsParameters,ic:this._wrtcClientServerTransport.iceCandidates,ip:this._wrtcClientServerTransport.iceParameters,s:this._wrtcClientServerTransport.sctpParameters},{i:this._wrtcServerClientTransport.id,f:"sc",d:this._wrtcServerClientTransport.dtlsParameters,ic:this._wrtcServerClientTransport.iceCandidates,ip:this._wrtcServerClientTransport.iceParameters,s:this._wrtcServerClientTransport.sctpParameters}]})]),!0};_deserialize(J){let X=X3(J);if(!X||typeof X!=="object"||typeof X[0]!=="number")return E.error(`Connection._deserialize(): Invalid packet format. Packet: ${JSON.stringify(X)}`);if(!A.isValidPacket(X))return E.error(`Connection._deserialize(): Invalid packet payload. Packet: ${JSON.stringify(X)}`);return X}}var xC;((Y)=>{Y.PLAYER_CONNECTED="PLAYER_MANAGER.PLAYER_CONNECTED";Y.PLAYER_DISCONNECTED="PLAYER_MANAGER.PLAYER_DISCONNECTED"})(xC||={});class j6{static instance=new j6;_connectionPlayers=new Map;constructor(){m8.on("CONNECTION.OPENED",({connection:J,req:X})=>{this._onConnectionOpened(J,X.session)}),m8.on("CONNECTION.CLOSED",({connection:J})=>{this._onConnectionClosed(J)})}getConnectedPlayers(){return Array.from(this._connectionPlayers.values())}getConnectedPlayersByWorld(J){return this.getConnectedPlayers().filter((X)=>X.world===J)}getConnectedPlayerByUsername(J){return Array.from(this._connectionPlayers.values()).find((X)=>{return X.username.toLowerCase()===J.toLowerCase()})}_onConnectionOpened(J,X){let Y=new r5(J,X);this._connectionPlayers.set(J,Y),m8.emit("PLAYER_MANAGER.PLAYER_CONNECTED",{player:Y})}_onConnectionClosed(J){let X=this._connectionPlayers.get(J);if(X)X.disconnect(),this._connectionPlayers.delete(J),m8.emit("PLAYER_MANAGER.PLAYER_DISCONNECTED",{player:X});else E.warning(`PlayerManager._onConnectionClosed(): Connection ${J.id} but was not in the PlayerManager._connectionPlayers map.`)}}var W$;((W)=>{W.DYNAMIC="dynamic";W.FIXED="fixed";W.KINEMATIC_POSITION="kinematic_position";W.KINEMATIC_VELOCITY="kinematic_velocity"})(W$||={});var zH=0.001,PC="dynamic";class f9 extends s{_additionalMass=0;_colliders=new Set;_explicitSleep=!1;_enabledPositions={x:!0,y:!0,z:!0};_enabledRotations={x:!0,y:!0,z:!0};_rigidBody;_rigidBodyDesc;_rigidBodyType;_simulation;constructor(J){super();J.type??=PC,this._rigidBodyDesc=this._createRigidBodyDesc(J),this._rigidBodyType=J.type,this._applyRigidBodyOptions(J),this._autoAddToSimulation(J)}get additionalMass(){if(!this._requireNotRemoved("additionalMass"))return 0;return this._additionalMass}get additionalSolverIterations(){if(!this._requireNotRemoved("additionalSolverIterations"))return 0;return this._rigidBody?this._rigidBody.additionalSolverIterations():this._rigidBodyDesc.additionalSolverIterations}get angularDamping(){if(!this._requireNotRemoved("angularDamping"))return 0;return this._rigidBody?this._rigidBody.angularDamping():this._rigidBodyDesc.angularDamping}get angularVelocity(){if(!this._requireNotRemoved("angularVelocity"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.angvel():this._rigidBodyDesc.angvel}get colliders(){return this._colliders}get dominanceGroup(){if(!this._requireNotRemoved("dominanceGroup"))return 0;return this._rigidBody?this._rigidBody.dominanceGroup():this._rigidBodyDesc.dominanceGroup}get directionFromRotation(){let{x:J,y:X,z:Y,w:Z}=this.rotation;return{x:2*(J*Y+Z*X),y:2*(X*Y-Z*J),z:1-2*(J*J+X*X)}}get effectiveAngularInertia(){if(!this._requireNotRemoved("effectiveAngularInertia"))return;return this._rigidBody?this._rigidBody.effectiveAngularInertia():void 0}get effectiveInverseMass(){if(!this._requireNotRemoved("effectiveInverseMass"))return;return this._rigidBody?this._rigidBody.effectiveInvMass():void 0}get effectiveWorldInversePrincipalAngularInertiaSqrt(){if(!this._requireNotRemoved("effectiveWorldInversePrincipalAngularInertiaSqrt"))return;return this._rigidBody?this._rigidBody.effectiveWorldInvInertiaSqrt():void 0}get enabledRotations(){if(!this._requireNotRemoved("enabledRotations"))return{x:!0,y:!0,z:!0};return this._enabledRotations}get enabledPositions(){if(!this._requireNotRemoved("enabledPositions"))return{x:!0,y:!0,z:!0};return this._enabledPositions}get gravityScale(){if(!this._requireNotRemoved("gravityScale"))return 0;return this._rigidBody?this._rigidBody.gravityScale():this._rigidBodyDesc.gravityScale}get inverseMass(){if(!this._requireNotRemoved("inverseMass"))return;return this._rigidBody?this._rigidBody.invMass():void 0}get inversePrincipalAngularInertiaSqrt(){if(!this._requireNotRemoved("inversePrincipalAngularInertiaSqrt"))return;return this._rigidBody?this._rigidBody.invPrincipalInertiaSqrt():void 0}get isCcdEnabled(){if(!this._requireNotRemoved("isCcdEnabled"))return!1;return this._rigidBody?this._rigidBody.isCcdEnabled():this._rigidBodyDesc.ccdEnabled}get isDynamic(){if(!this._requireNotRemoved("isDynamic"))return!1;return this._rigidBodyType==="dynamic"}get isEnabled(){if(!this._requireNotRemoved("isEnabled"))return!1;return this._rigidBody?this._rigidBody.isEnabled():this._rigidBodyDesc.enabled}get isFixed(){if(!this._requireNotRemoved("isFixed"))return!1;return this._rigidBodyType==="fixed"}get isKinematic(){if(!this._requireNotRemoved("isKinematic"))return!1;return["kinematic_position","kinematic_velocity"].includes(this._rigidBodyType)}get isKinematicPositionBased(){if(!this._requireNotRemoved("isKinematicPositionBased"))return!1;return this._rigidBodyType==="kinematic_position"}get isKinematicVelocityBased(){if(!this._requireNotRemoved("isKinematicVelocityBased"))return!1;return this._rigidBodyType==="kinematic_velocity"}get isMoving(){if(!this._requireNotRemoved("isMoving"))return!1;return this._rigidBody?this._rigidBody.isMoving():!1}get isRemoved(){return!this._rigidBody&&!this._rigidBodyDesc}get isSimulated(){if(!this._requireNotRemoved("isSimulated"))return!1;return this._rigidBody?!0:!1}get isSleeping(){if(!this._requireNotRemoved("isSleeping"))return!1;return this._rigidBody?this._rigidBody.isSleeping():this._rigidBodyDesc.sleeping}get linearDamping(){if(!this._requireNotRemoved("linearDamping"))return 0;return this._rigidBody?this._rigidBody.linearDamping():this._rigidBodyDesc.linearDamping}get linearVelocity(){if(!this._requireNotRemoved("linearVelocity"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.linvel():this._rigidBodyDesc.linvel}get localCenterOfMass(){if(!this._requireNotRemoved("localCenterOfMass"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.localCom():this._rigidBodyDesc.centerOfMass}get mass(){if(!this._requireNotRemoved("mass"))return 0;return this._rigidBody?this._rigidBody.mass():this._rigidBodyDesc.mass}get nextKinematicRotation(){if(!this._requireNotRemoved("nextKinematicRotation"))return{x:0,y:0,z:0,w:1};return this._rigidBody?this._rigidBody.nextRotation():this._rigidBodyDesc.rotation}get nextKinematicPosition(){if(!this._requireNotRemoved("nextKinematicPosition"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.nextTranslation():this._rigidBodyDesc.translation}get numColliders(){return this._colliders.size}get principalAngularInertia(){if(!this._requireNotRemoved("principalAngularInertia"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.principalInertia():this._rigidBodyDesc.principalAngularInertia}get principalAngularInertiaLocalFrame(){if(!this._requireNotRemoved("principalAngularInertiaLocalFrame"))return;return this._rigidBody?this._rigidBody.principalInertiaLocalFrame():void 0}get position(){if(!this._requireNotRemoved("position"))return{x:0,y:0,z:0};return this._rigidBody?this._rigidBody.translation():this._rigidBodyDesc.translation}get rawRigidBody(){if(!this._requireNotRemoved("rawRigidBody"))return;return this._rigidBody}get rotation(){if(!this._requireNotRemoved("rotation"))return{x:0,y:0,z:0,w:1};return this._rigidBody?this._rigidBody.rotation():this._rigidBodyDesc.rotation}get softCcdPrediction(){if(!this._requireNotRemoved("softCcdPrediction"))return 0;return this._rigidBody?this._rigidBody.softCcdPrediction():this._rigidBodyDesc.softCcdPrediction}get type(){if(!this._requireNotRemoved("type"))return"dynamic";return this._rigidBodyType}get worldCenterOfMass(){if(!this._requireNotRemoved("worldCenterOfMass"))return;return this._rigidBody?this._rigidBody.worldCom():void 0}setAdditionalMass(J){if(!this._requireDynamic("setAdditionalMass"))return;if(!this._requireNotRemoved("setAdditionalMass"))return;this._rigidBody?this._rigidBody.setAdditionalMass(J,!this._explicitSleep):this._rigidBodyDesc.setAdditionalMass(J)}setAdditionalMassProperties(J){if(!this._requireDynamic("setAdditionalMassProperties"))return;if(!this._requireNotRemoved("setAdditionalMassProperties"))return;let{additionalMass:X,centerOfMass:Y,principalAngularInertia:Z,principalAngularInertiaLocalFrame:W}=J;this._rigidBody?this._rigidBody.setAdditionalMassProperties(X,Y,Z,W,!this._explicitSleep):this._rigidBodyDesc.setAdditionalMassProperties(X,Y,Z,W)}setAdditionalSolverIterations(J){if(!this._requireDynamic("setAdditionalSolverIterations"))return;if(!this._requireNotRemoved("setAdditionalSolverIterations"))return;this._rigidBody?this._rigidBody.setAdditionalSolverIterations(J):this._rigidBodyDesc.setAdditionalSolverIterations(J)}setAngularDamping(J){if(!this._requireDynamic("setAngularDamping"))return;if(!this._requireNotRemoved("setAngularDamping"))return;this._rigidBody?this._rigidBody.setAngularDamping(J):this._rigidBodyDesc.setAngularDamping(J)}setAngularVelocity(J){if(!this._requireNotKinematicPositionBased("setAngularVelocity"))return;if(!this._requireNotRemoved("setAngularVelocity"))return;this._rigidBody?this._rigidBody.setAngvel(J,!this._explicitSleep):this._rigidBodyDesc.setAngvel(J)}setCcdEnabled(J){if(!this._requireDynamic("setCcdEnabled"))return;if(!this._requireNotRemoved("setCcdEnabled"))return;this._rigidBody?this._rigidBody.enableCcd(J):this._rigidBodyDesc.setCcdEnabled(J)}setDominanceGroup(J){if(!this._requireDynamic("setDominanceGroup"))return;if(!this._requireNotRemoved("setDominanceGroup"))return;this._rigidBody?this._rigidBody.setDominanceGroup(J):this._rigidBodyDesc.setDominanceGroup(J)}setEnabled(J){if(!this._requireNotRemoved("setEnabled"))return;this._rigidBody?this._rigidBody.setEnabled(J):this._rigidBodyDesc.setEnabled(J)}setEnabledPositions(J){if(!this._requireDynamic("setEnabledPositions"))return;if(!this._requireNotRemoved("setEnabledPositions"))return;this._rigidBody?this._rigidBody.setEnabledTranslations(J.x,J.y,J.z,!this._explicitSleep):this._rigidBodyDesc.enabledTranslations(J.x,J.y,J.z),this._enabledPositions=J}setEnabledRotations(J){if(!this._requireDynamic("setEnabledRotations"))return;if(!this._requireNotRemoved("setEnabledRotations"))return;this._rigidBody?this._rigidBody.setEnabledRotations(J.x,J.y,J.z,!this._explicitSleep):this._rigidBodyDesc.enabledRotations(J.x,J.y,J.z),this._enabledRotations=J}setGravityScale(J){if(!this._requireDynamic("setGravityScale"))return;if(!this._requireNotRemoved("setGravityScale"))return;this._rigidBody?this._rigidBody.setGravityScale(J,!this._explicitSleep):this._rigidBodyDesc.setGravityScale(J)}setLinearDamping(J){if(!this._requireDynamic("setLinearDamping"))return;if(!this._requireNotRemoved("setLinearDamping"))return;this._rigidBody?this._rigidBody.setLinearDamping(J):this._rigidBodyDesc.setLinearDamping(J)}setLinearVelocity(J){if(!this._requireNotKinematicPositionBased("setLinearVelocity"))return;if(!this._requireNotRemoved("setLinearVelocity"))return;this._rigidBody?this._rigidBody.setLinvel(J,!this._explicitSleep):this._rigidBodyDesc.setLinvel(J.x,J.y,J.z)}setNextKinematicRotation(J){if(!this._requireKinematic("setNextKinematicRotation"))return;if(!this._requireNotRemoved("setNextKinematicRotation"))return;this._rigidBody?this._rigidBody.setNextKinematicRotation(J):this._rigidBodyDesc.setRotation(J)}setNextKinematicPosition(J){if(!this._requireKinematic("setNextKinematicPosition"))return;if(!this._requireNotRemoved("setNextKinematicPosition"))return;this._rigidBody?this._rigidBody.setNextKinematicTranslation(J):this._rigidBodyDesc.setTranslation(J.x,J.y,J.z)}setPosition(J){if(!this._requireNotRemoved("setPosition"))return;this._rigidBody?this._rigidBody.setTranslation(J,!this._explicitSleep):this._rigidBodyDesc.setTranslation(J.x,J.y,J.z)}setRotation(J){if(!this._requireNotRemoved("setRotation"))return;this._rigidBody?this._rigidBody.setRotation(J,!this._explicitSleep):this._rigidBodyDesc.setRotation(J)}setSleeping(J){if(!this._requireDynamic("setSleeping"))return;if(!this._requireNotRemoved("setSleeping"))return;this._rigidBody?J?this._rigidBody.sleep():this._rigidBody.wakeUp():this._rigidBodyDesc.sleeping=J,this._explicitSleep=J}setSoftCcdPrediction(J){if(!this._requireDynamic("setSoftCcdPrediction"))return;if(!this._requireNotRemoved("setSoftCcdPrediction"))return;this._rigidBody?this._rigidBody.setSoftCcdPrediction(J):this._rigidBodyDesc.setSoftCcdPrediction(J)}setCollisionGroupsForSolidColliders(J){if(!this._requireNotRemoved("setCollisionGroupsForSolidColliders"))return;this._colliders.forEach((X)=>{if(X.isSensor)return;X.setCollisionGroups(J)})}setCollisionGroupsForSensorColliders(J){if(!this._requireNotRemoved("setCollisionGroupsForSensorColliders"))return;this._colliders.forEach((X)=>{if(!X.isSensor)return;X.setCollisionGroups(J)})}setType(J){if(!this._requireNotRemoved("setType"))return;let Y={["dynamic"]:z0.RigidBodyType.Dynamic,["fixed"]:z0.RigidBodyType.Fixed,["kinematic_position"]:z0.RigidBodyType.KinematicPositionBased,["kinematic_velocity"]:z0.RigidBodyType.KinematicVelocityBased}[J];if(Y===void 0)return E.error(`Invalid RigidBodyType: ${J}`);this._rigidBody?this._rigidBody.setBodyType(Y,!this._explicitSleep):this._rigidBodyDesc.status=Y,this._rigidBodyType=J}addForce(J){if(!this._requireNotRemoved("addForce"))return;if(!this._requireCreated("addForce"))return;if(!this._requireDynamic("addForce"))return;if(this._isNegligibleVector(J))return;this._rigidBody.addForce(J,!this._explicitSleep)}addTorque(J){if(!this._requireNotRemoved("addTorque"))return;if(!this._requireCreated("addTorque"))return;if(!this._requireDynamic("addTorque"))return;if(this._isNegligibleVector(J))return;this._rigidBody.addTorque(J,!this._explicitSleep)}addChildColliderToSimulation(J){if(!this._requireNotRemoved("addChildColliderToSimulation"))return;if(!this._requireCreated("addChildColliderToSimulation"))return;J.addToSimulation(this._simulation,this)}addToSimulation(J){if(!this._requireNotRemoved("addToSimulation"))return;if(this._rigidBody)return E.error("RigidBody.addToSimulation(): Rigid body already exists in the simulation!");this._simulation=J,this._rigidBody=this._simulation.createRawRigidBody(this._rigidBodyDesc),this._colliders.forEach((X)=>{if(!X.isSimulated)X.addToSimulation(J,this)})}applyImpulse(J){if(!this._requireNotRemoved("applyImpulse"))return;if(!this._requireCreated("applyImpulse"))return;if(!this._requireDynamic("applyImpulse"))return;if(this._isNegligibleVector(J))return;this._rigidBody.applyImpulse(J,!this._explicitSleep)}applyImpulseAtPoint(J,X){if(!this._requireNotRemoved("applyImpulseAtPoint"))return;if(!this._requireCreated("applyImpulseAtPoint"))return;if(!this._requireDynamic("applyImpulseAtPoint"))return;if(this._isNegligibleVector(J))return;this._rigidBody.applyImpulseAtPoint(J,X,!this._explicitSleep)}applyTorqueImpulse(J){if(!this._requireNotRemoved("applyTorqueImpulse"))return;if(!this._requireCreated("applyTorqueImpulse"))return;if(!this._requireDynamic("applyTorqueImpulse"))return;this._rigidBody.applyTorqueImpulse(J,!this._explicitSleep)}createAndAddChildCollider(J){if(!this._requireNotRemoved("createAndAddChildCollider"))return null;return this._simulation?new d8({...J,parentRigidBody:this,simulation:this._simulation}):this._createAndAddPendingChildCollider(J)}createAndAddChildCollidersToSimulation(J){let X=[];return J.forEach((Y)=>{let Z=this.createAndAddChildCollider(Y);if(Z)X.push(Z)}),X}getCollidersByTag(J){let X=[];for(let Y of this._colliders)if(Y.tag===J)X.push(Y);return X}linkCollider(J){if(!this._requireNotRemoved("linkCollider"))return;if(J.parentRigidBody!==this)return E.error("RigidBody.linkCollider(): Collider cannot be linked because it is not a child of this rigid body!");this._colliders.add(J)}lockAllRotations(){if(!this._requireNotRemoved("lockAllRotations"))return;this.setEnabledRotations({x:!1,y:!1,z:!1})}lockAllPositions(){if(!this._requireNotRemoved("lockAllPositions"))return;this.setEnabledPositions({x:!1,y:!1,z:!1})}removeFromSimulation(){if(!this._requireNotRemoved("removeFromSimulation"))return;if(!this._rigidBody)return E.error("RigidBody.removeFromSimulation(): Rigid body does not exist in the simulation!");this._colliders.forEach((J)=>{J.removeFromSimulation()}),this._simulation.removeRawRigidBody(this._rigidBody),this._simulation=void 0,this._rigidBody=void 0}unlinkCollider(J){if(!this._requireNotRemoved("unlinkCollider"))return;if(!J.isRemoved)return E.error("RigidBody.unlinkCollider(): Collider is still simulated and therefore cannot be unlinked from this rigid body!");this._colliders.delete(J)}resetAngularVelocity(){if(!this._requireNotRemoved("resetAngularVelocity"))return;if(!this._requireCreated("resetAngularVelocity"))return;this.setAngularVelocity({x:0,y:0,z:0})}resetForces(){if(!this._requireNotRemoved("resetForces"))return;if(!this._requireCreated("resetForces"))return;this._rigidBody.resetForces(!this._explicitSleep)}resetLinearVelocity(){if(!this._requireNotRemoved("resetLinearVelocity"))return;if(!this._requireCreated("resetLinearVelocity"))return;this.setLinearVelocity({x:0,y:0,z:0})}resetTorques(){if(!this._requireNotRemoved("resetTorques"))return;if(!this._requireCreated("resetTorques"))return;this._rigidBody.resetTorques(!this._explicitSleep)}sleep(){if(!this._requireNotRemoved("sleep"))return;this.setSleeping(!0)}wakeUp(){if(!this._requireNotRemoved("wakeUp"))return;this.setSleeping(!1)}_applyRigidBodyOptions(J){[["additionalMass",this.setAdditionalMass.bind(this)],["additionalMassProperties",this.setAdditionalMassProperties.bind(this)],["additionalSolverIterations",this.setAdditionalSolverIterations.bind(this)],["angularDamping",this.setAngularDamping.bind(this)],["angularVelocity",this.setAngularVelocity.bind(this)],["dominanceGroup",this.setDominanceGroup.bind(this)],["ccdEnabled",this.setCcdEnabled.bind(this)],["enabled",this.setEnabled.bind(this)],["enabledPositions",this.setEnabledPositions.bind(this)],["enabledRotations",this.setEnabledRotations.bind(this)],["gravityScale",this.setGravityScale.bind(this)],["linearDamping",this.setLinearDamping.bind(this)],["linearVelocity",this.setLinearVelocity.bind(this)],["position",this.setPosition.bind(this)],["rotation",this.setRotation.bind(this)],["sleeping",this.setSleeping.bind(this)],["softCcdPrediction",this.setSoftCcdPrediction.bind(this)]].forEach(([Y,Z])=>{if(Y in J)Z(J[Y])})}_autoAddToSimulation(J){if(J.colliders)this._createAndAddPendingChildColliders(J.colliders);if(J.simulation)this.addToSimulation(J.simulation)}_createAndAddPendingChildCollider(J){if(!this._requireNotRemoved("createAndAddPendingChildCollider"))return null;if(!this._requireNotSimulated("createAndAddPendingChildCollider"))return null;let X=new d8(J);return this._colliders.add(X),X}_createAndAddPendingChildColliders(J){let X=[];return J.forEach((Y)=>{let Z=this._createAndAddPendingChildCollider(Y);if(Z)X.push(Z)}),X}_createRigidBodyDesc(J){let X=J.type??PC;return{["dynamic"]:()=>z0.RigidBodyDesc.dynamic(),["fixed"]:()=>z0.RigidBodyDesc.fixed(),["kinematic_position"]:()=>z0.RigidBodyDesc.kinematicPositionBased(),["kinematic_velocity"]:()=>z0.RigidBodyDesc.kinematicVelocityBased()}[X]()}_requireCreated(J){if(!this._rigidBody||!this._simulation)E.error(`RigidBody._requireCreated(): Rigid body has not been created and therefore does not support the invoked method: ${J}()`);return!!this._rigidBody&&!!this._simulation}_requireDynamic(J){if(!this.isDynamic)E.error(`RigidBody._requireDynamic(): Rigid body is not dynamic and therefore does not support the invoked method: ${J}()`);return this.isDynamic}_requireKinematic(J){if(!this.isKinematic)E.error(`RigidBody._requireKinematic(): Rigid body is not kinematic and therefore does not support the invoked method: ${J}()`);return this.isKinematic}_requireNotKinematicPositionBased(J){if(this.isKinematicPositionBased)E.error(`RigidBody._requireNotKinematicPositionBased(): Rigid body is kinematic position based and therefore does not support the invoked method: ${J}()`);return!this.isKinematicPositionBased}_requireNotRemoved(J){if(!this._rigidBody&&!this._rigidBodyDesc)E.error(`RigidBody._requireNotRemoved(): Rigid body has been removed and therefore does not support the invoked method: ${J}()`);return!!this._rigidBody||!!this._rigidBodyDesc}_requireNotSimulated(J){if(this.isSimulated)E.error(`RigidBody._requireNotSimulated(): Rigid body is simulated and therefore does not support the invoked method: ${J}()`);return!this.isSimulated}_isNegligibleVector(J){return Math.abs(J.x)<zH&&Math.abs(J.y)<zH&&Math.abs(J.z)<zH}}var n0=16,t5=n0-1,NC=n0**3,lX0=[{neighborOffset:[-1,0,0],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+0,X+0,Y+1,J+0,X+1,Y+0,J+0,X+1,Y+0,J+0,X+0,Y+1,J+0,X+1,Y+1]},{neighborOffset:[1,0,0],generateVertices:(J,X,Y)=>[J+1,X+0,Y+0,J+1,X+1,Y+0,J+1,X+0,Y+1,J+1,X+1,Y+0,J+1,X+1,Y+1,J+1,X+0,Y+1]},{neighborOffset:[0,-1,0],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+1,X+0,Y+0,J+0,X+0,Y+1,J+1,X+0,Y+0,J+1,X+0,Y+1,J+0,X+0,Y+1]},{neighborOffset:[0,1,0],generateVertices:(J,X,Y)=>[J+0,X+1,Y+0,J+0,X+1,Y+1,J+1,X+1,Y+0,J+1,X+1,Y+0,J+0,X+1,Y+1,J+1,X+1,Y+1]},{neighborOffset:[0,0,-1],generateVertices:(J,X,Y)=>[J+0,X+0,Y+0,J+0,X+1,Y+0,J+1,X+0,Y+0,J+0,X+1,Y+0,J+1,X+1,Y+0,J+1,X+0,Y+0]},{neighborOffset:[0,0,1],generateVertices:(J,X,Y)=>[J+0,X+0,Y+1,J+1,X+0,Y+1,J+0,X+1,Y+1,J+0,X+1,Y+1,J+1,X+0,Y+1,J+1,X+1,Y+1]}],LH;((Z)=>{Z.DESPAWN="CHUNK.DESPAWN";Z.SET_BLOCK="CHUNK.SET_BLOCK";Z.SPAWN="CHUNK.SPAWN"})(LH||={});class w8 extends s{_blocks;_originCoordinate;_requiresUpdate=!1;_rigidBody;_world;constructor(){super();this._blocks=new Uint8Array(NC)}get blocks(){return this._blocks}get requiresUpdate(){return this._requiresUpdate}get isSimulated(){return!!this._rigidBody}get isSpawned(){return!!this._originCoordinate&&!!this._world}get originCoordinate(){return this._originCoordinate}get world(){return this._world}static blockIndexToLocalCoordinate(J){return{x:J%n0,y:(J/n0|0)%n0,z:J/(n0*n0)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&n0-1,y:J.y&n0-1,z:J.z&n0-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(n0-1),y:J.y&~(n0-1),z:J.z&~(n0-1)}}static isValidOriginCoordinate(J){return J.x%n0===0&&J.y%n0===0&&J.z%n0===0}spawn(J,X){if(this.isSpawned){let{x:Y,y:Z,z:W}=this.originCoordinate;return E.error(`Chunk.spawn(): Chunk is already spawned at origin ${Y}, ${Z}, ${W}!`)}if(!w8.isValidOriginCoordinate(X))return E.error(`Chunk.spawn(): Chunk coordinates must be divisible by ${n0}`);this._originCoordinate=X,this._world=J,this._world.chunkLattice.registerChunk(this),this._requiresUpdate=!0}despawn(){if(!this.isSpawned)return E.error("Chunk.despawn(): Chunk has not been spawned and cannot be despawned!");this.emitWithWorld(this._world,"CHUNK.DESPAWN",{chunk:this}),this._removeFromSimulation(),this._world.chunkLattice.unregisterChunk(this),this._originCoordinate=void 0,this._world=void 0}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,X){if(!this._isValidLocalCoordinate(J))return E.error("Chunk.setBlock(): Block local coordinate is out of bounds");if(this._blocks[this._getIndex(J)]===X)return;if(this._blocks[this._getIndex(J)]=X,this.isSpawned&&this.isSimulated){this.emitWithWorld(this._world,"CHUNK.SET_BLOCK",{chunk:this,globalCoordinate:this._getGlobalCoordinate(J),localCoordinate:J,blockTypeId:X});let Y=this._getGlobalCoordinate(J),Z=[];if(J.x===0)Z.push({x:-1,y:0,z:0});if(J.y===0)Z.push({x:0,y:-1,z:0});if(J.z===0)Z.push({x:0,y:0,z:-1});if(J.x===t5)Z.push({x:1,y:0,z:0});if(J.y===t5)Z.push({x:0,y:1,z:0});if(J.z===t5)Z.push({x:0,y:0,z:1});for(let W of Z){let $={x:Y.x+W.x,y:Y.y+W.y,z:Y.z+W.z},Q=w8.globalCoordinateToOriginCoordinate($),K=this._world?.chunkLattice.getChunk(Q);if(!K?.hasBlock(w8.globalCoordinateToLocalCoordinate($)))continue;K.setRequiresUpdate(!0)}}this._requiresUpdate=!0}setRequiresUpdate(J){this._requiresUpdate=J}update(){if(!this._requiresUpdate)return;if(!this.isSpawned)return E.error("Chunk.update(): Chunk is not spawned and cannot be updated.");let J=!this._rigidBody,X=this._world.simulation;if(this._removeFromSimulation(),this._rigidBody=new f9({type:"fixed",position:this._originCoordinate,simulation:this._world.simulation}),this._meshColliders().map(([Y,Z])=>{if(!Y.isSimulated)Y.addToSimulation(X,this._rigidBody);X.colliderMap.setColliderBlockType(Y,Z)}),this._requiresUpdate=!1,J)this.emitWithWorld(this._world,"CHUNK.SPAWN",{chunk:this})}serialize(){return t.serializeChunk(this)}_meshColliders(){if(!this._world)return E.error("Chunk._meshColliders(): Chunk is not spawned and cannot be meshed."),[];let J=new Map,X=[];for(let Z=0;Z<NC;Z++){if(this._blocks[Z]===0)continue;let W=this._blocks[Z],$=this._world.blockTypeRegistry.getBlockType(W),{x:Q,y:K,z:G}=w8.blockIndexToLocalCoordinate(Z);if(!$.isMeshable){let q=$.createCollider();q.setRelativePosition({x:Q,y:K,z:G}),X.push([q,$]);continue}let F=J.get($)??{indices:[],vertices:[]};J.set($,F);for(let q of lX0){let[H,z,V]=q.neighborOffset,M={x:Q+H,y:K+z,z:G+V},R=this._getGlobalCoordinate(M),L=this._world.chunkLattice.getBlockType(R);if(L&&!L.isLiquid)continue;let w=F.indices.length;F.indices.push(w,w+1,w+2,w+3,w+4,w+5),F.vertices.push(...q.generateVertices(Q,K,G))}}let Y=[];return J.forEach((Z,W)=>{if(!Z.indices.length)return;let $=W.createCollider(new Uint32Array(Z.indices),new Float32Array(Z.vertices));Y.push([$,W])}),[...X,...Y]}_removeFromSimulation(){if(!this._rigidBody||!this._world)return;this._rigidBody.removeFromSimulation(),this._rigidBody=void 0}_getGlobalCoordinate(J){if(!this.originCoordinate)E.fatalError("Chunk._getGlobalCoordinate(): Chunk is not spawned, calculating global coordinate is impossible.");return{x:this.originCoordinate.x+J.x,y:this.originCoordinate.y+J.y,z:this.originCoordinate.z+J.z}}_getIndex(J){return J.x+n0*(J.y+n0*J.z)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=t5&&J.y>=0&&J.y<=t5&&J.z>=0&&J.z<=t5}}class PJ{_chunks=new Map;_world;constructor(J){this._world=J}registerChunk(J){if(!J.isSpawned)return E.error("ChunkLattice.registerChunk(): Chunk is not spawned.");if(this.hasChunk(J.originCoordinate)){let{x:X,y:Y,z:Z}=J.originCoordinate;return E.error(`ChunkLattice.registerChunk(): Chunk exists at origin (${X}, ${Y}, ${Z}), despawn the current chunk before registering another at the same origin.`)}if(J.world.id!==this._world.id)return E.error("ChunkLattice.registerChunk(): Chunk world does not match lattice world.");this._chunks.set(this._getChunkKey(J.originCoordinate),J)}unregisterChunk(J){if(!J.isSpawned)return E.error("ChunkLattice.unregisterChunk(): Chunk is not spawned.");if(J.world.id!==this._world.id)return E.error("ChunkLattice.unregisterChunk(): Chunk world does not match lattice world.");this._chunks.delete(this._getChunkKey(J.originCoordinate))}clear(){this._chunks.forEach((J)=>J.despawn()),this._chunks.clear()}getBlockId(J){let X=this.getChunk(w8.globalCoordinateToOriginCoordinate(J));if(!X)return 0;return X.getBlockId(w8.globalCoordinateToLocalCoordinate(J))}getBlockType(J){let X=this.getBlockId(J);return X?this._world.blockTypeRegistry.getBlockType(X):null}getChunk(J){if(!w8.isValidOriginCoordinate(J)){E.error(`ChunkLattice.getChunk(): Chunk coordinates must be divisible by CHUNK_SIZE (${n0})`);return}return this._chunks.get(this._getChunkKey(J))}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let X=this.getChunk(w8.globalCoordinateToOriginCoordinate(J));if(!X)return!1;return X.hasBlock(w8.globalCoordinateToLocalCoordinate(J))}hasChunk(J){return this._chunks.has(this._getChunkKey(J))}setBlock(J,X){let Y=w8.globalCoordinateToLocalCoordinate(J),Z=w8.globalCoordinateToOriginCoordinate(J),W=this.getChunk(Z);if(!W)W=new w8,W.spawn(this._world,Z);W.setBlock(Y,X)}updateChunks(){this._chunks.forEach((J)=>{if(J.requiresUpdate)J.update()})}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}}var vC={type:"dynamic",softCcdPrediction:1},BC=0.0025000000000000005,jC=Math.cos(0.005),$$;((w)=>{w.BLOCK_COLLISION="ENTITY.BLOCK_COLLISION";w.BLOCK_CONTACT_FORCE="ENTITY.BLOCK_CONTACT_FORCE";w.DESPAWN="ENTITY.DESPAWN";w.ENTITY_COLLISION="ENTITY.ENTITY_COLLISION";w.ENTITY_CONTACT_FORCE="ENTITY.ENTITY_CONTACT_FORCE";w.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";w.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";w.SET_OPACITY="ENTITY.SET_OPACITY";w.SET_PARENT="ENTITY.SET_PARENT";w.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";w.SPAWN="ENTITY.SPAWN";w.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";w.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";w.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";w.TICK="ENTITY.TICK";w.UPDATE_POSITION="ENTITY.UPDATE_POSITION";w.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})($$||={});class Y8 extends f9{_id;_blockHalfExtents;_blockTextureUri;_controller;_modelAnimationsPlaybackRate=1;_modelHiddenNodes=new Set;_modelLoopedAnimations=new Set;_modelOneshotAnimations=new Set;_modelScale;_modelUri;_name;_opacity;_parent;_parentNodeName;_tag;_tintColor;_lastUpdatedPosition={x:0,y:0,z:0};_lastUpdatedRotation={x:0,y:0,z:0,w:1};_lastParentlessType="dynamic";_world;constructor(J){let X="blockTextureUri"in J,Y="modelUri"in J;if(!X===!Y)E.fatalError("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if(X&&!J.blockHalfExtents)E.fatalError("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)E.fatalError("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!U6.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))E.fatalError(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??vC);if(X)this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri;if(Y)this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelScale=J.modelScale,this._modelUri=J.modelUri,J.modelHiddenNodes?.forEach((Z)=>this._modelHiddenNodes.add(Z.toLowerCase())),J.modelLoopedAnimations?.forEach((Z)=>this._modelLoopedAnimations.add(Z));if(this._name=J.name??"Nameless",this._opacity=J.opacity??1,this._parent=J.parent,this._parentNodeName=J.parentNodeName,this._tag=J.tag,this._tintColor=J.tintColor,J.controller)this.setController(J.controller)}get id(){return this._id}get blockHalfExtents(){return this._blockHalfExtents}get blockTextureUri(){return this._blockTextureUri}get controller(){return this._controller}get height(){return this.isModelEntity?U6.instance.getHeight(this._modelUri)*(this._modelScale??1):this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelScale(){return this._modelScale}get modelUri(){return this._modelUri}get name(){return this._name}get opacity(){return this._opacity}get parent(){return this._parent}get parentNodeName(){return this._parentNodeName}get tag(){return this._tag}get tintColor(){return this._tintColor}get isBlockEntity(){return!!this._blockTextureUri}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get world(){return this._world}spawn(J,X,Y){if(this.isSpawned)return E.error(`Entity.spawn(): Entity ${this._name} is already spawned with id ${this._id}!`);if(!this.isSimulated)this.addToSimulation(J.simulation);if(this._blockTextureUri&&this._blockHalfExtents&&this.numColliders===0)this.addChildColliderToSimulation(new d8(d8.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0)this.addChildColliderToSimulation(new d8(d8.optionsFromModelUri(this._modelUri,this._modelScale)));if(this.colliders.forEach((Z)=>{if(this.hasListeners("ENTITY.BLOCK_COLLISION")||this.hasListeners("ENTITY.ENTITY_COLLISION"))Z.enableCollisionEvents(!0);if(this.hasListeners("ENTITY.BLOCK_CONTACT_FORCE")||this.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))Z.enableContactForceEvents(!0);if(q6.isDefaultCollisionGroups(Z.collisionGroups))Z.setCollisionGroups({belongsTo:[Z.isSensor?4:2],collidesWith:[65535]})}),this.setPosition(X),Y)this.setRotation(Y);if(this._id=J.entityManager.registerEntity(this),this._world=J,this._controller)this._controller.spawn(this);if(this._parent)this.setParent(this._parent,this._parentNodeName,X,Y);this.colliders.forEach((Z)=>{J.simulation.colliderMap.setColliderEntity(Z,this)}),this.emitWithWorld(J,"ENTITY.SPAWN",{entity:this})}despawn(){if(!this._requireSpawned("despawn"))return;if(this._world.entityManager.getEntityChildren(this).forEach((J)=>{J.despawn()}),this._controller)this._controller.detach(this),this._controller.despawn(this);if(this.emitWithWorld(this._world,"ENTITY.DESPAWN",{entity:this}),this.isSimulated)this.removeFromSimulation();this._world.entityManager.unregisterEntity(this),this._world.audioManager.unregisterEntityAttachedAudios(this),this._world.lightManager.despawnEntityAttachedLights(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setModelAnimationsPlaybackRate(J){if(!this._requireSpawned("setModelAnimationsPlaybackRate"))return;if(!this.isModelEntity||this._modelAnimationsPlaybackRate===J)return;this._modelAnimationsPlaybackRate=J,this.emitWithWorld(this._world,"ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",{entity:this,playbackRate:J})}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}setModelHiddenNodes(J){if(!this._requireSpawned("setModelHiddenNodes"))return;this._modelHiddenNodes=new Set(J.map((X)=>X.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setOpacity(J){if(!this._requireSpawned("setOpacity"))return;if(this._opacity===J)return;this._opacity=J,this.emitWithWorld(this._world,"ENTITY.SET_OPACITY",{entity:this,opacity:J})}setParent(J,X,Y,Z){if(!this._requireSpawned("setParent"))return;if(J&&!J.isSpawned)return E.error("Entity.setParent(): Parent entity is not spawned, cannot set parent!");if(!this._parent&&J)this._lastParentlessType=this.type;if(this._parent=J,this._parentNodeName=X,this.colliders.forEach((W)=>W.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(Y??{x:0,y:0,z:0}),this.setRotation(Z??{x:0,y:0,z:0,w:1}),!this.isKinematicPositionBased)this.resetAngularVelocity(),this.resetForces(),this.resetLinearVelocity(),this.resetTorques();this.emitWithWorld(this._world,"ENTITY.SET_PARENT",{entity:this,parent:J,parentNodeName:X})}setTintColor(J){if(!this._requireSpawned("setTintColor"))return;if(!J&&!this._tintColor||J&&this._tintColor&&J.r===this._tintColor.r&&J.g===this._tintColor.g&&J.b===this._tintColor.b)return;this._tintColor=J,this.emitWithWorld(this._world,"ENTITY.SET_TINT_COLOR",{entity:this,tintColor:J})}startModelLoopedAnimations(J){if(!this._requireSpawned("startModelLoopedAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some((X)=>!this._modelLoopedAnimations.has(X)))return;J.forEach((X)=>{this._modelLoopedAnimations.add(X)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_LOOPED_ANIMATIONS",{entity:this,animations:new Set(J)})}startModelOneshotAnimations(J){if(!this._requireSpawned("startModelOneshotAnimations"))return;if(!this.isModelEntity||!J.length)return;J.forEach((X)=>{this._modelOneshotAnimations.add(X)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopModelAnimations(J){if(!this._requireSpawned("stopModelAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some((X)=>this._modelLoopedAnimations.has(X))&&!J.some((X)=>this._modelOneshotAnimations.has(X)))return;J.forEach((X)=>{this._modelLoopedAnimations.delete(X),this._modelOneshotAnimations.delete(X)}),this.emitWithWorld(this._world,"ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return t.serializeEntity(this)}tick(J){if(this.emit("ENTITY.TICK",{entity:this,tickDeltaMs:J}),this._controller)this._controller.tick(this,J)}checkAndEmitUpdates(){if(!this._requireSpawned("checkAndEmitUpdates"))return;let J=this.position,X=this.rotation;if(this._rotationExceedsThreshold(X,this._lastUpdatedRotation))this._lastUpdatedRotation=X,this.emitWithWorld(this._world,"ENTITY.UPDATE_ROTATION",{entity:this,rotation:X});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this.emitWithWorld(this._world,"ENTITY.UPDATE_POSITION",{entity:this,position:J})}_requireSpawned(J){if(!this.isSpawned)E.error(`Entity._requireSpawned(): Entity ${this._name} is not spawned, cannot invoke ${J}()!`);return this.isSpawned}_positionExceedsThreshold(J,X){let Y=J.x-X.x,Z=J.y-X.y,W=J.z-X.z;return Y*Y+Z*Z+W*W>BC}_rotationExceedsThreshold(J,X){return Math.abs(J.x*X.x+J.y*X.y+J.z*X.z+J.w*X.w)<jC}}class NJ extends a1{autoCancelMouseLeftClick=!0;canWalk=()=>!0;canRun=()=>!0;canJump=()=>!0;idleLoopedAnimations=["idle_upper","idle_lower"];interactOneshotAnimations=["simple_interact"];jumpOneshotAnimations=["jump_loop"];jumpVelocity=10;runLoopedAnimations=["run_upper","run_lower"];runVelocity=8;sticksToPlatforms=!0;walkLoopedAnimations=["walk_upper","walk_lower"];walkVelocity=4;_stepAudio;_groundContactCount=0;_platform;constructor(J={}){super();this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.canWalk=J.canWalk??this.canWalk,this.canRun=J.canRun??this.canRun,this.canJump=J.canJump??this.canJump,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get platform(){return this._platform}attach(J){this._stepAudio=new $4({uri:"audio/sfx/step/stone/stone-step-04.mp3",loop:!0,volume:0.1,referenceDistance:2,cutoffDistance:15,attachedToEntity:J}),J.setCcdEnabled(!0),J.lockAllRotations()}spawn(J){if(!J.isSpawned)return E.error("PlayerEntityController.createColliders(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:0.23,halfHeight:0.125,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},isSensor:!0,relativePosition:{x:0,y:-0.75,z:0},tag:"groundSensor",onCollision:(X,Y)=>{if(!J.isSpawned)return;if(this._groundContactCount+=Y?1:-1,!this._groundContactCount)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!(X instanceof Y8)||!X.isKinematic)return;if(Y&&this.sticksToPlatforms)this._platform=X;else if(X===this._platform&&!Y)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:0.33,radius:0.4,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,X,Y,Z){if(!J.isSpawned||!J.world)return;if(super.tickWithPlayerInput(J,X,Y,Z),J.parent)return;let{w:W,a:$,s:Q,d:K,sp:G,sh:F,ml:q}=X,{yaw:H}=Y,z=J.linearVelocity,V={x:0,y:0,z:0},M=F;if(this.isGrounded&&(W||$||Q||K)){if(M)J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.runLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.runLoopedAnimations),this._stepAudio?.setPlaybackRate(0.75);else J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.walkLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.walkLoopedAnimations),this._stepAudio?.setPlaybackRate(0.51);this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else this._stepAudio?.pause(),J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((P)=>!this.idleLoopedAnimations.includes(P))),J.startModelLoopedAnimations(this.idleLoopedAnimations);if(q)J.startModelOneshotAnimations(this.interactOneshotAnimations),X.ml=!this.autoCancelMouseLeftClick;if(M&&this.canRun(this)||!M&&this.canWalk(this)){let P=M?this.runVelocity:this.walkVelocity;if(W)V.x-=P*Math.sin(H),V.z-=P*Math.cos(H);if(Q)V.x+=P*Math.sin(H),V.z+=P*Math.cos(H);if($)V.x-=P*Math.cos(H),V.z+=P*Math.sin(H);if(K)V.x+=P*Math.cos(H),V.z-=P*Math.sin(H);let N=Math.sqrt(V.x*V.x+V.z*V.z);if(N>P){let v=P/N;V.x*=v,V.z*=v}}if(G&&this.canJump(this)){if(this.isGrounded&&z.y>-0.001&&z.y<=3)V.y=this.jumpVelocity}let R=this._platform?this._platform.linearVelocity:{x:0,y:0,z:0},L={x:V.x-z.x+R.x,y:V.y+R.y,z:V.z-z.z+R.z};if(!(this.runVelocity>0&&Math.abs(z.x)>this.runVelocity||this.jumpVelocity>0&&Math.abs(z.y)>this.jumpVelocity||this.runVelocity>0&&Math.abs(z.z)>this.runVelocity)||this.isOnPlatform){if(Object.values(L).some((P)=>P!==0)){let P=J.mass;J.applyImpulse({x:L.x*P,y:L.y*P,z:L.z*P})}}if(H!==void 0){let P=H/2;J.setRotation({x:0,y:Math.fround(Math.sin(P)),z:0,w:Math.fround(Math.cos(P))})}}}var UH;((K)=>{K.LOAD="SCENE_UI.LOAD";K.SET_ATTACHED_TO_ENTITY="SCENE_UI.SET_ATTACHED_TO_ENTITY";K.SET_OFFSET="SCENE_UI.SET_OFFSET";K.SET_POSITION="SCENE_UI.SET_POSITION";K.SET_STATE="SCENE_UI.SET_STATE";K.SET_VIEW_DISTANCE="SCENE_UI.SET_VIEW_DISTANCE";K.UNLOAD="SCENE_UI.UNLOAD"})(UH||={});class vJ extends s{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)E.fatalError("Either attachedToEntity or position must be set, but not both");super();this._attachedToEntity=J.attachedToEntity,this._offset=J.offset,this._position=J.position,this._state=J.state??{},this._templateId=J.templateId,this._viewDistance=J.viewDistance}get id(){return this._id}get attachedToEntity(){return this._attachedToEntity}get isLoaded(){return this._id!==void 0}get offset(){return this._offset}get position(){return this._position}get state(){return this._state}get templateId(){return this._templateId}get viewDistance(){return this._viewDistance}get world(){return this._world}load(J){if(this.isLoaded)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return E.error(`SceneUI.load(): Attached entity ${this._attachedToEntity.id} must be spawned before loading SceneUI!`);this._id=J.sceneUIManager.registerSceneUI(this),this._world=J,this.emitWithWorld(J,"SCENE_UI.LOAD",{sceneUI:this})}setAttachedToEntity(J){if(!J.isSpawned)return E.error(`SceneUI.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_ATTACHED_TO_ENTITY",{sceneUI:this,entity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_OFFSET",{sceneUI:this,offset:J})}setPosition(J){if(this._position===J)return;if(this._attachedToEntity=void 0,this._position=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_POSITION",{sceneUI:this,position:J})}setState(J){if(this._state={...this._state,...J},this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_STATE",{sceneUI:this,state:this._state})}setViewDistance(J){if(this._viewDistance=J,this.isLoaded)this.emitWithWorld(this._world,"SCENE_UI.SET_VIEW_DISTANCE",{sceneUI:this,viewDistance:J})}unload(){if(!this.isLoaded||!this._world)return;this._world.sceneUIManager.unregisterSceneUI(this),this.emitWithWorld(this._world,"SCENE_UI.UNLOAD",{sceneUI:this}),this._id=void 0,this._world=void 0}serialize(){return t.serializeSceneUI(this)}}class n1 extends Y8{player;nametagSceneUI;constructor(J){super(J);if(this.player=J.player,this.nametagSceneUI=new vJ({templateId:"hytopia:nametag",attachedToEntity:this,offset:{x:0,y:1,z:0},viewDistance:15,state:{username:this.player.username,profilePictureUrl:this.player.profilePictureUrl}}),!J.controller)this.setController(new NJ)}spawn(J,X,Y){super.spawn(J,X,Y),this.nametagSceneUI.load(J),this.player.on("PLAYER.CHAT_MESSAGE_SEND",({message:Z})=>{this.nametagSceneUI.setState({chat:Z})})}tick(J){if(!this.isSpawned||!this.world||!this.controller)return;let{input:X,camera:Y}=this.player;this.controller.tickWithPlayerInput(this,X,Y.orientation,J),super.tick(J)}}class jJ{_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get world(){return this._world}registerEntity(J){if(J.id!==void 0)E.fatalError(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let X=this._nextEntityId;return this._entities.set(X,J),this._nextEntityId++,X}unregisterEntity(J){if(J.id===void 0)return E.error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);this._entities.delete(J.id)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach((X)=>{if(X instanceof n1)J.push(X)}),J}getPlayerEntitiesByPlayer(J){let X=[];return this._entities.forEach((Y)=>{if(Y instanceof n1&&Y.player===J)X.push(Y)}),X}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let X=[];return this._entities.forEach((Y)=>{if(Y.tag===J)X.push(Y)}),X}getEntitiesByTagSubstring(J){let X=[];return this._entities.forEach((Y)=>{if(Y.tag?.includes(J))X.push(Y)}),X}getEntityChildren(J){let X=[];return this._entities.forEach((Y)=>{if(Y.parent===J)X.push(Y)}),X}tickEntities(J){this._entities.forEach((X)=>{X.tick(J)})}checkAndEmitUpdates(){this._entities.forEach((J)=>{if(!J.isSpawned)return;J.checkAndEmitUpdates()})}}class kJ{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach((X)=>{X.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter((X)=>X.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let X=this._nextLightId;return this._lights.set(X,J),this._nextLightId++,X}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}var kC;((Y)=>{Y[Y.POINTLIGHT=0]="POINTLIGHT";Y[Y.SPOTLIGHT=1]="SPOTLIGHT"})(kC||={});var VH;((z)=>{z.DESPAWN="LIGHT.DESPAWN";z.SET_ANGLE="LIGHT.SET_ANGLE";z.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";z.SET_COLOR="LIGHT.SET_COLOR";z.SET_DISTANCE="LIGHT.SET_DISTANCE";z.SET_INTENSITY="LIGHT.SET_INTENSITY";z.SET_OFFSET="LIGHT.SET_OFFSET";z.SET_PENUMBRA="LIGHT.SET_PENUMBRA";z.SET_POSITION="LIGHT.SET_POSITION";z.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";z.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";z.SPAWN="LIGHT.SPAWN"})(VH||={});class MH extends s{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)E.fatalError("Either attachedToEntity or position must be set, but not both");super();E.warning("WARNING: Lights are poorly optimized at this time. Using more than a few lights in your game can cause extremely bad performance (FPS) issues. Use lights sparingly!"),this._angle=J.angle,this._attachedToEntity=J.attachedToEntity,this._color=J.color??{r:255,g:255,b:255},this._distance=J.distance,this._intensity=J.intensity??1,this._offset=J.offset,this._penumbra=J.penumbra,this._position=J.position,this._trackedEntity=J.trackedEntity,this._trackedPosition=J.trackedPosition,this._type=J.type??0}get id(){return this._id}get angle(){return this._angle}get attachedToEntity(){return this._attachedToEntity}get color(){return this._color}get distance(){return this._distance}get intensity(){return this._intensity}get isSpawned(){return this._id!==void 0}get offset(){return this._offset}get penumbra(){return this._penumbra}get position(){return this._position}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get type(){return this._type}get world(){return this._world}setAngle(J){if(this._angle===J)return;if(this._angle=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_ANGLE",{light:this,angle:J})}setAttachedToEntity(J){if(!J.isSpawned)return E.error(`Light.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_ATTACHED_TO_ENTITY",{light:this,entity:J})}setColor(J){if(this._color.r===J.r&&this._color.g===J.g&&this._color.b===J.b)return;if(this._color=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_COLOR",{light:this,color:J})}setDistance(J){if(this._distance===J)return;if(this._distance=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_DISTANCE",{light:this,distance:J})}setIntensity(J){if(this._intensity===J)return;if(this._intensity=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_INTENSITY",{light:this,intensity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_OFFSET",{light:this,offset:J})}setPenumbra(J){if(this._penumbra===J)return;if(this._penumbra=J,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_PENUMBRA",{light:this,penumbra:J})}setPosition(J){if(this._position===J)return;if(this._position=J,this._attachedToEntity=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_POSITION",{light:this,position:J})}setTrackedEntity(J){if(!J.isSpawned)return E.error(`Light.setTrackedEntity(): Entity ${J.id} is not spawned!`);if(this._trackedEntity===J)return;if(this._trackedEntity=J,this._trackedPosition=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_TRACKED_ENTITY",{light:this,entity:J})}setTrackedPosition(J){if(this._trackedPosition===J)return;if(this._trackedPosition=J,this._trackedEntity=void 0,this.isSpawned)this.emitWithWorld(this._world,"LIGHT.SET_TRACKED_POSITION",{light:this,position:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.lightManager.unregisterLight(this),this.emitWithWorld(this._world,"LIGHT.DESPAWN",{light:this}),this._id=void 0,this._world=void 0}spawn(J){if(this.isSpawned)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return E.error(`Light.spawn(): Attached entity ${this._attachedToEntity.id} must be spawned before spawning Light!`);this._id=J.lightManager.registerLight(this),this._world=J,this.emitWithWorld(J,"LIGHT.SPAWN",{light:this})}serialize(){return t.serializeLight(this)}}var TC;((Z)=>{Z[Z.FIRST_PERSON=0]="FIRST_PERSON";Z[Z.THIRD_PERSON=1]="THIRD_PERSON";Z[Z.SPECTATOR=2]="SPECTATOR"})(TC||={});var RH;((V)=>{V.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";V.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";V.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";V.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";V.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";V.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";V.SET_FOV="PLAYER_CAMERA.SET_FOV";V.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";V.SET_MODE="PLAYER_CAMERA.SET_MODE";V.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";V.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";V.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";V.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(RH||={});class TJ extends s{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_trackedEntity;_trackedPosition;_zoom=1;constructor(J){super();this.player=J}get attachedToEntity(){return this._attachedToEntity}get attachedToPosition(){return this._attachedToPosition}get facingDirection(){return{x:-Math.sin(this._orientation.yaw)*Math.cos(this._orientation.pitch),y:Math.sin(this._orientation.pitch),z:-Math.cos(this._orientation.yaw)*Math.cos(this._orientation.pitch)}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){if(!this._requirePlayerWorld())return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){if(!this._requirePlayerWorld())return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}setAttachedToEntity(J){if(!this._requirePlayerWorld())return;if(!J.isSpawned)return E.error(`PlayerCamera.setAttachedToEntity(): Entity ${J.id} is not spawned!`);this._attachedToEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",{playerCamera:this,entity:J})}setAttachedToPosition(J){if(!this._requirePlayerWorld())return;this._attachedToPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){if(!this._requirePlayerWorld())return;this._filmOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){if(!this._requirePlayerWorld())return;this._forwardOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){if(!this._requirePlayerWorld())return;this._fov=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){if(!this._requirePlayerWorld())return;this._modelHiddenNodes=new Set(J.map((X)=>X.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setMode(J){if(!this._requirePlayerWorld())return;this._mode=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){if(!this._requirePlayerWorld())return;this._offset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_OFFSET",{playerCamera:this,offset:J})}setOrientationPitch(J){this._orientation.pitch=J}setOrientationYaw(J){this._orientation.yaw=J}setTrackedEntity(J){if(!this._requirePlayerWorld())return;this._trackedEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){if(!this._requirePlayerWorld())return;this._trackedPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){if(!this._requirePlayerWorld())return;this._zoom=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return t.serializePlayerCamera(this)}_requirePlayerWorld(){if(!this.player.world)E.error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world!`);return!!this.player.world}}var Q$;((W)=>{W.DATA="PLAYER_UI.DATA";W.LOAD="PLAYER_UI.LOAD";W.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";W.SEND_DATA="PLAYER_UI.SEND_DATA"})(Q$||={});class DJ extends s{player;constructor(J){super();this.player=J}load(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.LOAD",{playerUI:this,htmlUri:J})}lockPointer(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.LOCK_POINTER",{playerUI:this,lock:J})}sendData(J){if(!this.player.world)return;this.emitWithWorld(this.player.world,"PLAYER_UI.SEND_DATA",{playerUI:this,data:J})}}class _J{_colliderHandleBlockTypeMap=new Map;_colliderHandleCollisionCallbackMap=new Map;_colliderHandleEntityMap=new Map;_cleanupBlockTypeColliderHandles=new Set;_pendingCleanupBlockTypeColliderHandles=new Set;_cleanupCollisionCallbackColliderHandles=new Set;_pendingCleanupCollisionCallbackColliderHandles=new Set;_cleanupEntityColliderHandles=new Set;_pendingCleanupEntityColliderHandles=new Set;getColliderBlockType(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleBlockTypeMap.get(J.rawCollider.handle)}getColliderCollisionCallback(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleCollisionCallbackMap.get(J.rawCollider.handle)}getColliderEntity(J){if(!this._requireSimulatedCollider(J))return;return this._colliderHandleEntityMap.get(J.rawCollider.handle)}getColliderHandleBlockType(J){return this._colliderHandleBlockTypeMap.get(J)}getColliderHandleCollisionCallback(J){return this._colliderHandleCollisionCallbackMap.get(J)}getColliderHandleEntity(J){return this._colliderHandleEntityMap.get(J)}removeColliderBlockType(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleBlockType(J.rawCollider.handle)}removeColliderCollisionCallback(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleCollisionCallback(J.rawCollider.handle)}removeColliderEntity(J){if(!this._requireSimulatedCollider(J))return;this.removeColliderHandleEntity(J.rawCollider.handle)}removeColliderHandleBlockType(J){this._colliderHandleBlockTypeMap.delete(J)}removeColliderHandleCollisionCallback(J){this._colliderHandleCollisionCallbackMap.delete(J)}removeColliderHandleEntity(J){this._colliderHandleEntityMap.delete(J)}setColliderBlockType(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleBlockType(J.rawCollider.handle,X)}setColliderCollisionCallback(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleCollisionCallback(J.rawCollider.handle,X)}setColliderEntity(J,X){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleEntity(J.rawCollider.handle,X)}setColliderHandleBlockType(J,X){this._colliderHandleBlockTypeMap.set(J,X),this._cleanupBlockTypeColliderHandles.delete(J),this._pendingCleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,X){this._colliderHandleCollisionCallbackMap.set(J,X),this._cleanupCollisionCallbackColliderHandles.delete(J),this._pendingCleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,X){this._colliderHandleEntityMap.set(J,X),this._cleanupEntityColliderHandles.delete(J),this._pendingCleanupEntityColliderHandles.delete(J)}queueColliderHandleForCleanup(J){if(this._colliderHandleBlockTypeMap.has(J))this._pendingCleanupBlockTypeColliderHandles.add(J);if(this._colliderHandleCollisionCallbackMap.has(J))this._pendingCleanupCollisionCallbackColliderHandles.add(J);if(this._colliderHandleEntityMap.has(J))this._pendingCleanupEntityColliderHandles.add(J)}cleanup(){for(let J of this._cleanupBlockTypeColliderHandles)this._colliderHandleBlockTypeMap.delete(J);this._cleanupBlockTypeColliderHandles.clear();for(let J of this._cleanupCollisionCallbackColliderHandles)this._colliderHandleCollisionCallbackMap.delete(J);this._cleanupCollisionCallbackColliderHandles.clear();for(let J of this._cleanupEntityColliderHandles)this._colliderHandleEntityMap.delete(J);this._cleanupEntityColliderHandles.clear(),[[this._pendingCleanupBlockTypeColliderHandles,this._cleanupBlockTypeColliderHandles],[this._pendingCleanupCollisionCallbackColliderHandles,this._cleanupCollisionCallbackColliderHandles],[this._pendingCleanupEntityColliderHandles,this._cleanupEntityColliderHandles]].forEach(([J,X])=>{for(let Y of J.keys())X.add(Y);J.clear()})}_requireSimulatedCollider(J){if(!J.rawCollider)E.error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.");return!!J.rawCollider}}var uX0={x:0,y:-32,z:0},wH=60,OH;((W)=>{W.STEP_START="SIMULATION.STEP_START";W.STEP_END="SIMULATION.STEP_END";W.DEBUG_RAYCAST="SIMULATION.DEBUG_RAYCAST";W.DEBUG_RENDER="SIMULATION.DEBUG_RENDER"})(OH||={});class EJ extends s{_colliderMap=new _J;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_rapierEventQueue;_rapierSimulation;_world;constructor(J,X=wH,Y=uX0){super();this._rapierEventQueue=new z0.EventQueue(!0),this._rapierSimulation=new z0.World(Y),this._rapierSimulation.timestep=Math.fround(1/X),this._world=J}get colliderMap(){return this._colliderMap}get isDebugRaycastingEnabled(){return this._debugRaycastingEnabled}get isDebugRenderingEnabled(){return this._debugRenderingEnabled}get gravity(){return this._rapierSimulation.gravity}get timestepS(){return this._rapierSimulation.timestep}get world(){return this._world}raycast(J,X,Y,Z={}){let W=new z0.Ray(J,X),$=this._rapierSimulation.castRay(W,Y,Z.ignoresSensors??!0,Z.filterFlags,Z.filterGroups,Z.filterExcludeCollider,Z.filterExcludeRigidBody,Z.filterPredicate);if(this._debugRaycastingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:X,length:Y,hit:!!$});if(!$)return null;let Q=W.pointAt($.timeOfImpact),K=$.timeOfImpact,G=$.collider,F=this._colliderMap.getColliderHandleBlockType(G.handle);if(F)return{hitBlock:y9.fromGlobalCoordinate({x:Math.floor(Q.x-(W.dir.x<0?0.0001:-0.0001)),y:Math.floor(Q.y-(W.dir.y<0?0.0001:-0.0001)),z:Math.floor(Q.z-(W.dir.z<0?0.0001:-0.0001))},F),hitPoint:Q,hitDistance:K};let q=this._colliderMap.getColliderHandleEntity(G.handle);if(q)return{hitEntity:q,hitPoint:Q,hitDistance:K};return null}createRawCollider(J,X){return this._rapierSimulation.createCollider(J,X)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J){this._debugRenderingEnabled=J}getContactManifolds(J,X){let Y=[];return this._rapierSimulation.narrowPhase.contactPair(J,X,(Z,W)=>{if(Z.numContacts()===0)return;let $=Z.normal(),Q=[];for(let K=0;K<Z.numSolverContacts();K++)Q.push(Z.solverContactPoint(K));Y.push({contactPoints:Q,localNormalA:!W?Z.localNormal1():Z.localNormal2(),localNormalB:!W?Z.localNormal2():Z.localNormal1(),normal:!W?$:{x:-$.x,y:-$.y,z:-$.z}})}),Y}removeRawCollider(J){this._colliderMap.queueColliderHandleForCleanup(J.handle),this._rapierSimulation.removeCollider(J,!1)}removeRawRigidBody(J){this._rapierSimulation.removeRigidBody(J)}setGravity(J){this._rapierSimulation.gravity=J}step=(J)=>{this.emitWithWorld(this._world,"SIMULATION.STEP_START",{simulation:this,tickDeltaMs:J});let X=performance.now();if(this._rapierSimulation.step(this._rapierEventQueue),this._rapierEventQueue.drainContactForceEvents(this._onContactForceEvent),this._rapierEventQueue.drainCollisionEvents(this._onCollisionEvent),this._colliderMap.cleanup(),this.emitWithWorld(this._world,"SIMULATION.STEP_END",{simulation:this,stepDurationMs:performance.now()-X}),this._debugRenderingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender()})};_onCollisionEvent=(J,X,Y)=>{let[Z,W]=this._getCollisionObjects(J,X);if(!Z||!W)return;let $=(Q,K)=>{if(Q instanceof V6&&K instanceof Y8&&Q.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))Q.emit("BLOCK_TYPE.ENTITY_COLLISION",{blockType:Q,entity:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(Q instanceof Y8&&K instanceof V6&&Q.hasListeners("ENTITY.BLOCK_COLLISION"))Q.emit("ENTITY.BLOCK_COLLISION",{entity:Q,blockType:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(Q instanceof Y8&&K instanceof Y8&&Q.hasListeners("ENTITY.ENTITY_COLLISION"))Q.emit("ENTITY.ENTITY_COLLISION",{entity:Q,otherEntity:K,started:Y,colliderHandleA:J,colliderHandleB:X});else if(typeof Q==="function"&&(K instanceof Y8||K instanceof V6))Q(K,Y,J,X)};$(Z,W),$(W,Z)};_onContactForceEvent=(J)=>{let[X,Y]=this._getCollisionObjects(J.collider1(),J.collider2());if(!X||typeof X==="function"||!Y||typeof Y==="function")return;let Z={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},W=($,Q)=>{if($ instanceof V6&&Q instanceof Y8&&$.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))$.emit("BLOCK_TYPE.ENTITY_CONTACT_FORCE",{blockType:$,entity:Q,contactForceData:Z});else if($ instanceof Y8&&Q instanceof V6&&$.hasListeners("ENTITY.BLOCK_CONTACT_FORCE"))$.emit("ENTITY.BLOCK_CONTACT_FORCE",{entity:$,blockType:Q,contactForceData:Z});else if($ instanceof Y8&&Q instanceof Y8&&$.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))$.emit("ENTITY.ENTITY_CONTACT_FORCE",{entity:$,otherEntity:Q,contactForceData:Z})};W(X,Y),W(Y,X)};_getCollisionObjects(J,X){let Y=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),Z=this._colliderMap.getColliderHandleBlockType(X)??this._colliderMap.getColliderHandleCollisionCallback(X)??this._colliderMap.getColliderHandleEntity(X);return[Y,Z]}}class K${_synchronizedPlayerReliablePackets=new Map;_queuedBroadcasts=[];_queuedAudioSynchronizations={};_queuedBlockSynchronizations={};_queuedBlockTypeSynchronizations={};_queuedChunkSynchronizations={};_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations={};_queuedLightSynchronizations={};_queuedPerPlayerSynchronizations=new Map;_queuedPerPlayerCameraSynchronizations=new Map;_queuedPerPlayerUISynchronizations=new Map;_queuedPerPlayerUIDatasSynchronizations=new Map;_queuedPlayerSynchronizations={};_queuedSceneUISynchronizations={};_queuedWorldSynchronization;_loadedSceneUIs=new Set;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){let J=[],X=[],Y=this._world.loop.currentTick;this._queuedPerPlayerSynchronizations.forEach((z,V)=>{this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(...z)});let Z=Object.values(this._queuedEntitySynchronizations);if(Z.length>0){let[z,V]=Z.reduce(([M,R],L)=>{for(let w in L)if(w!=="i"&&w!=="p"&&w!=="r")return M.push(L),[M,R];return R.push(L),[M,R]},[[],[]]);if(V.length>0){let M=A.createPacket(A.outboundPackets.entitiesPacketDefinition,V,Y);X.push(M)}if(z.length>0){let M=A.createPacket(A.outboundPackets.entitiesPacketDefinition,z,Y);J.push(M),this._synchronizedPlayerReliablePackets.forEach((R)=>R.push(M))}}let W=Object.values(this._queuedAudioSynchronizations);if(W.length>0){let z=A.createPacket(A.outboundPackets.audiosPacketDefinition,W,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let $=Object.values(this._queuedBlockTypeSynchronizations);if($.length>0){let z=A.createPacket(A.outboundPackets.blockTypesPacketDefinition,$,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let Q=Object.values(this._queuedBlockSynchronizations);if(Q.length>0){let z=A.createPacket(A.outboundPackets.blocksPacketDefinition,Q,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let K=Object.values(this._queuedChunkSynchronizations);if(K.length>0){let z=A.createPacket(A.outboundPackets.chunksPacketDefinition,K,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}let G=Object.values(this._queuedLightSynchronizations);if(G.length>0){let z=A.createPacket(A.outboundPackets.lightsPacketDefinition,G,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedPerPlayerUISynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.uiPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)}),this._queuedPerPlayerUIDatasSynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.uiDatasPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)});let F=Object.values(this._queuedSceneUISynchronizations);if(F.length>0){let z=A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,F,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}if(this._queuedWorldSynchronization){let z=A.createPacket(A.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedPerPlayerCameraSynchronizations.forEach((z,V)=>{let M=A.createPacket(A.outboundPackets.cameraPacketDefinition,z,Y);this._createOrGetSynchronizedPlayerReliablePackets(V,J).push(M)});let q=Object.values(this._queuedPlayerSynchronizations);if(q.length>0){let z=A.createPacket(A.outboundPackets.playersPacketDefinition,q,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}this._queuedBroadcasts.forEach((z)=>{J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))});let H=this._queuedDebugRaycastSynchronizations;if(H.length>0){let z=A.createPacket(A.outboundPackets.physicsDebugRaycastsPacketDefinition,H,Y);J.push(z),this._synchronizedPlayerReliablePackets.forEach((V)=>V.push(z))}j6.instance.getConnectedPlayersByWorld(this._world).forEach((z)=>{let V=this._synchronizedPlayerReliablePackets.get(z)??J;if(V.length>0)z.connection.send(V);if(X.length>0)z.connection.send(X,!1)}),this._queuedBroadcasts=[],this._queuedAudioSynchronizations={},this._queuedBlockSynchronizations={},this._queuedBlockTypeSynchronizations={},this._queuedChunkSynchronizations={},this._queuedDebugRaycastSynchronizations=[],this._queuedEntitySynchronizations={},this._queuedLightSynchronizations={},this._queuedPerPlayerSynchronizations.clear(),this._queuedPerPlayerCameraSynchronizations.clear(),this._queuedPerPlayerUISynchronizations.clear(),this._queuedPerPlayerUIDatasSynchronizations.clear(),this._queuedPlayerSynchronizations={},this._queuedSceneUISynchronizations={},this._queuedWorldSynchronization=void 0,this._loadedSceneUIs.clear(),this._spawnedChunks.clear(),this._spawnedEntities.clear(),this._synchronizedPlayerReliablePackets.clear()}_subscribeToAudioEvents(){this._world.final("AUDIO.PAUSE",this._onAudioPause),this._world.final("AUDIO.PLAY",this._onAudioPlay),this._world.final("AUDIO.PLAY_RESTART",this._onAudioPlayRestart),this._world.final("AUDIO.SET_ATTACHED_TO_ENTITY",this._onAudioSetAttachedToEntity),this._world.final("AUDIO.SET_CUTOFF_DISTANCE",this._onAudioSetCutoffDistance),this._world.final("AUDIO.SET_DETUNE",this._onAudioSetDetune),this._world.final("AUDIO.SET_DISTORTION",this._onAudioSetDistortion),this._world.final("AUDIO.SET_POSITION",this._onAudioSetPosition),this._world.final("AUDIO.SET_PLAYBACK_RATE",this._onAudioSetPlaybackRate),this._world.final("AUDIO.SET_REFERENCE_DISTANCE",this._onAudioSetReferenceDistance),this._world.final("AUDIO.SET_VOLUME",this._onAudioSetVolume)}_subscribeToBlockTypeRegistryEvents(){this._world.final("BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",this._onBlockTypeRegistryRegisterBlockType)}_subscribeToChatEvents(){this._world.final("CHAT.BROADCAST_MESSAGE",this._onChatSendBroadcastMessage),this._world.final("CHAT.PLAYER_MESSAGE",this._onChatSendPlayerMessage)}_subscribeToChunkEvents(){this._world.final("CHUNK.SPAWN",this._onChunkSpawn),this._world.final("CHUNK.DESPAWN",this._onChunkDespawn),this._world.final("CHUNK.SET_BLOCK",this._onChunkSetBlock)}_subscribeToEntityEvents(){this._world.final("ENTITY.SPAWN",this._onEntitySpawn),this._world.final("ENTITY.DESPAWN",this._onEntityDespawn),this._world.final("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",this._onEntitySetModelAnimationsPlaybackRate),this._world.final("ENTITY.SET_MODEL_HIDDEN_NODES",this._onEntitySetModelHiddenNodes),this._world.final("ENTITY.SET_OPACITY",this._onEntitySetOpacity),this._world.final("ENTITY.SET_PARENT",this._onEntitySetParent),this._world.final("ENTITY.SET_TINT_COLOR",this._onEntitySetTintColor),this._world.final("ENTITY.START_MODEL_LOOPED_ANIMATIONS",this._onEntityStartModelLoopedAnimations),this._world.final("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",this._onEntityStartModelOneshotAnimations),this._world.final("ENTITY.STOP_MODEL_ANIMATIONS",this._onEntityStopModelAnimations),this._world.final("ENTITY.UPDATE_POSITION",this._onEntityUpdatePosition),this._world.final("ENTITY.UPDATE_ROTATION",this._onEntityUpdateRotation)}_subscribeToLightEvents(){this._world.final("LIGHT.DESPAWN",this._onLightDespawn),this._world.final("LIGHT.SET_ANGLE",this._onLightSetAngle),this._world.final("LIGHT.SET_ATTACHED_TO_ENTITY",this._onLightSetAttachedToEntity),this._world.final("LIGHT.SET_COLOR",this._onLightSetColor),this._world.final("LIGHT.SET_DISTANCE",this._onLightSetDistance),this._world.final("LIGHT.SET_INTENSITY",this._onLightSetIntensity),this._world.final("LIGHT.SET_OFFSET",this._onLightSetOffset),this._world.final("LIGHT.SET_PENUMBRA",this._onLightSetPenumbra),this._world.final("LIGHT.SET_POSITION",this._onLightSetPosition),this._world.final("LIGHT.SET_TRACKED_ENTITY",this._onLightSetTrackedEntity),this._world.final("LIGHT.SET_TRACKED_POSITION",this._onLightSetTrackedPosition),this._world.final("LIGHT.SPAWN",this._onLightSpawn)}_subscribeToPlayerEvents(){this._world.final("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.final("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.final("PLAYER.REQUEST_SYNC",this._onPlayerRequestSync)}_subscribeToPlayerCameraEvents(){this._world.final("PLAYER_CAMERA.LOOK_AT_ENTITY",this._onPlayerCameraLookAtEntity),this._world.final("PLAYER_CAMERA.LOOK_AT_POSITION",this._onPlayerCameraLookAtPosition),this._world.final("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",this._onPlayerCameraSetAttachedToEntity),this._world.final("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",this._onPlayerCameraSetAttachedToPosition),this._world.final("PLAYER_CAMERA.SET_FILM_OFFSET",this._onPlayerCameraSetFilmOffset),this._world.final("PLAYER_CAMERA.SET_FORWARD_OFFSET",this._onPlayerCameraSetForwardOffset),this._world.final("PLAYER_CAMERA.SET_FOV",this._onPlayerCameraSetFov),this._world.final("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",this._onPlayerCameraSetModelHiddenNodes),this._world.final("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.final("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.final("PLAYER_CAMERA.SET_TRACKED_ENTITY",this._onPlayerCameraSetTrackedEntity),this._world.final("PLAYER_CAMERA.SET_TRACKED_POSITION",this._onPlayerCameraSetTrackedPosition),this._world.final("PLAYER_CAMERA.SET_ZOOM",this._onPlayerCameraSetZoom)}_subscribeToPlayerUIEvents(){this._world.final("PLAYER_UI.LOAD",this._onPlayerUILoad),this._world.final("PLAYER_UI.LOCK_POINTER",this._onPlayerUILockPointer),this._world.final("PLAYER_UI.SEND_DATA",this._onPlayerUISendData)}_subscribeToSceneUIEvents(){this._world.final("SCENE_UI.LOAD",this._onSceneUILoad),this._world.final("SCENE_UI.SET_ATTACHED_TO_ENTITY",this._onSceneUISetAttachedToEntity),this._world.final("SCENE_UI.SET_OFFSET",this._onSceneUISetOffset),this._world.final("SCENE_UI.SET_POSITION",this._onSceneUISetPosition),this._world.final("SCENE_UI.SET_STATE",this._onSceneUISetState),this._world.final("SCENE_UI.SET_VIEW_DISTANCE",this._onSceneUISetViewDistance),this._world.final("SCENE_UI.UNLOAD",this._onSceneUIUnload)}_subscribeToSimulationEvents(){this._world.final("SIMULATION.DEBUG_RAYCAST",this._onSimulationDebugRaycast),this._world.final("SIMULATION.DEBUG_RENDER",this._onSimulationDebugRender)}_subscribeToWorldEvents(){this._world.final("WORLD.SET_AMBIENT_LIGHT_COLOR",this._onWorldSetAmbientLightColor),this._world.final("WORLD.SET_AMBIENT_LIGHT_INTENSITY",this._onWorldSetAmbientLightIntensity),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",this._onWorldSetDirectionalLightColor),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",this._onWorldSetDirectionalLightIntensity),this._world.final("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",this._onWorldSetDirectionalLightPosition)}_onAudioPause=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.pa=!0,delete X.pl,delete X.r};_onAudioPlay=(J)=>{let X=J.audio.serialize();X.pl=!0,delete X.pa,delete X.r,this._queuedAudioSynchronizations[X.i]=X};_onAudioPlayRestart=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.r=!0,delete X.pa,delete X.pl,this._queuedAudioSynchronizations[X.i]=X};_onAudioSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onAudioSetCutoffDistance=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.cd=J.cutoffDistance};_onAudioSetDetune=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.de=J.detune};_onAudioSetDistortion=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.di=J.distortion};_onAudioSetPosition=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.e=J.position?void 0:X.e,X.p=J.position?t.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let X=this._createOrGetQueuedAudioSync(J.audio);X.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let X=J.blockType.serialize();this._queuedBlockTypeSynchronizations[J.blockType.id]=X};_onChatSendBroadcastMessage=(J)=>{let{player:X,message:Y,color:Z}=J;this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:Z,p:X?.id}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:X,message:Y,color:Z}=J,W=this._queuedPerPlayerSynchronizations.get(X)??[];W.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:Z}],this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set(X,W)};_onChunkSpawn=(J)=>{let X=this._createOrGetQueuedChunkSync(J.chunk);X.b=Array.from(J.chunk.blocks),X.rm=void 0,this._spawnedChunks.add(X.c.join(","))};_onChunkDespawn=(J)=>{let X=this._createOrGetQueuedChunkSync(J.chunk),Y=X.c.join(",");if(this._spawnedChunks.has(Y))delete this._queuedChunkSynchronizations[Y],this._spawnedChunks.delete(Y);else X.rm=!0};_onChunkSetBlock=(J)=>{let X=this._createOrGetQueuedBlockSync(J.globalCoordinate);X.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.ap=J.playbackRate};_onEntitySpawn=(J)=>{let X=J.entity.serialize();this._queuedEntitySynchronizations[X.i]=X,this._spawnedEntities.add(X.i)};_onEntityDespawn=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has(X.i))delete this._queuedEntitySynchronizations[X.i],this._spawnedEntities.delete(X.i);else X.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.h=Array.from(J.modelHiddenNodes)};_onEntitySetOpacity=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.o=J.opacity};_onEntitySetParent=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.pe=J.parent?J.parent.id:void 0,X.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.t=J.tintColor?t.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.al=Array.from(new Set([...X.al??[],...J.animations])),X.as)X.as=X.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.ao=Array.from(new Set([...X.ao??[],...J.animations])),X.as)X.as=X.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);if(X.al)X.al=X.al.filter((Y)=>!J.animations.has(Y)).filter(Boolean);if(X.ao)X.ao=X.ao.filter((Y)=>!J.animations.has(Y)).filter(Boolean);X.as=Array.from(new Set([...X.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let X=this._createOrGetQueuedEntitySync(J.entity);X.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.rm=!0};_onLightSetAngle=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onLightSetColor=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.c=t.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.d=J.distance};_onLightSetIntensity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.n=J.intensity};_onLightSetOffset=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.o=J.offset?t.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.pe=J.penumbra};_onLightSetPosition=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.p=J.position?t.serializeVector(J.position):void 0,X.e=J.position?void 0:X.e};_onLightSetTrackedEntity=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.te=J.entity?J.entity.id:void 0,X.tp=J.entity?void 0:X.tp};_onLightSetTrackedPosition=(J)=>{let X=this._createOrGetQueuedLightSync(J.light);X.tp=J.position?t.serializeVector(J.position):void 0,X.te=J.position?void 0:X.te};_onLightSpawn=(J)=>{let X=J.light.serialize();this._queuedLightSynchronizations[X.i]=X};_onPlayerCameraLookAtEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pl=t.serializeVector(J.entity.position),delete X.et,delete X.pt};_onPlayerCameraLookAtPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pl=J.position?t.serializeVector(J.position):void 0,delete X.et,delete X.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.e=J.entity.id,delete X.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.p=J.position?t.serializeVector(J.position):void 0,delete X.e};_onPlayerCameraSetFilmOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetMode=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.o=J.offset?t.serializeVector(J.offset):void 0};_onPlayerCameraSetTrackedEntity=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.et=J.entity?J.entity.id:void 0,delete X.pl,delete X.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.pt=J.position?t.serializeVector(J.position):void 0,delete X.et,delete X.pl};_onPlayerCameraSetZoom=(J)=>{let X=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);X.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:X}=J,Y=this._queuedPerPlayerSynchronizations.get(X)??[];Y.push(A.createPacket(A.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((W)=>{if(X.camera.attachedToEntity===void 0&&W instanceof n1&&W.player===X)X.camera.setAttachedToEntity(W);return W.serialize()}),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllAudios().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((W)=>W.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.playersPacketDefinition,j6.instance.getConnectedPlayers().map((W)=>W.serialize()),this._world.loop.currentTick));let Z=this._createOrGetQueuedPlayerCameraSync(X.camera);this._queuedPerPlayerCameraSynchronizations.set(X,{...X.camera.serialize(),...Z}),this._queuedPerPlayerSynchronizations.set(X,Y),this._queuedPlayerSynchronizations[X.id]=X.serialize()};_onPlayerLeftWorld=(J)=>{let X=this._createOrGetQueuedPlayerSync(J.player);X.rm=!0};_onPlayerRequestSync=(J)=>{J.player.connection.send([A.createPacket(A.outboundPackets.syncResponsePacketDefinition,{r:J.receivedAt,s:Date.now(),p:performance.now()-J.receivedAtMs,n:this._world.loop.nextTickMs},this._world.loop.currentTick)])};_onPlayerUILoad=(J)=>{let X=this._createOrGetQueuedPlayerUISync(J.playerUI);X.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let X=this._createOrGetQueuedPlayerUISync(J.playerUI);X.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let X=J.sceneUI.serialize();this._queuedSceneUISynchronizations[X.i]=X,this._loadedSceneUIs.add(X.i)};_onSceneUISetAttachedToEntity=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.e=J.entity?J.entity.id:void 0,X.p=J.entity?void 0:X.p};_onSceneUISetOffset=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.o=J.offset?t.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.p=J.position?t.serializeVector(J.position):void 0,X.e=J.position?void 0:X.e};_onSceneUISetState=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.s=J.state};_onSceneUISetViewDistance=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);X.v=J.viewDistance};_onSceneUIUnload=(J)=>{let X=this._createOrGetQueuedSceneUISync(J.sceneUI);if(this._loadedSceneUIs.has(X.i))delete this._queuedSceneUISynchronizations[X.i],this._loadedSceneUIs.delete(X.i);else X.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(t.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.ac=t.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.dc=t.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let X=this._createOrGetQueuedWorldSync(J.world);X.dp=t.serializeVector(J.position)};_createOrGetQueuedAudioSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");return this._queuedAudioSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedBlockSync(J){let{x:X,y:Y,z:Z}=J;return this._queuedBlockSynchronizations[`${X},${Y},${Z}`]??={i:0,c:[X,Y,Z]}}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)E.fatalError("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:X,y:Y,z:Z}=J.originCoordinate;return this._queuedChunkSynchronizations[`${X},${Y},${Z}`]??={c:[X,Y,Z]}}_createOrGetQueuedEntitySync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");return this._queuedEntitySynchronizations[J.id]??={i:J.id}}_createOrGetQueuedLightSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");return this._queuedLightSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerSync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedPlayerSync(): Player has no id!");return this._queuedPlayerSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerCameraSync(J){let X=this._queuedPerPlayerCameraSynchronizations.get(J.player);if(!X)X={},this._queuedPerPlayerCameraSynchronizations.set(J.player,X);return X}_createOrGetQueuedPlayerUISync(J){let X=this._queuedPerPlayerUISynchronizations.get(J.player);if(!X)X={},this._queuedPerPlayerUISynchronizations.set(J.player,X);return X}_createOrGetQueuedPlayerUIDatasSync(J){let X=this._queuedPerPlayerUIDatasSynchronizations.get(J.player);if(!X)X=[],this._queuedPerPlayerUIDatasSynchronizations.set(J.player,X);return X}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)E.fatalError("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");return this._queuedSceneUISynchronizations[J.id]??={i:J.id}}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)E.fatalError("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}_createOrGetSynchronizedPlayerReliablePackets(J,X){let Y=this._synchronizedPlayerReliablePackets.get(J);if(!Y)Y=[...X],this._synchronizedPlayerReliablePackets.set(J,Y);return Y}}class CJ{_sceneUIs=new Map;_nextSceneUIId=1;_world;constructor(J){this._world=J}get world(){return this._world}getAllSceneUIs(){return Array.from(this._sceneUIs.values())}getAllEntityAttachedSceneUIs(J){return this.getAllSceneUIs().filter((X)=>X.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let X=this._nextSceneUIId;return this._sceneUIs.set(X,J),this._nextSceneUIId++,X}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach((X)=>{X.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}class SJ{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,X,Y){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._tickFunction=X,this._tickErrorCallback=Y}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return E.warning("Ticker.start(): ticker already running.");this._lastLoopTimeMs=performance.now();let J=()=>{let X=performance.now(),Y=X-this._lastLoopTimeMs;if(this._lastLoopTimeMs=X,Y>250)Y=250;this._accumulatorMs+=Y;while(this._accumulatorMs>=this._fixedTimestepMs)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs;this._nextTickMs=this._fixedTimestepMs-this._accumulatorMs,this._tickHandle=setTimeout(J,0)};J()}stop(){if(!this._tickHandle)return E.warning("Ticker.stop(): ticker not running.");clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch(X){if(X instanceof Error&&this._tickErrorCallback)this._tickErrorCallback(X);else E.warning(`Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error: ${X}`)}}}var DC;(($)=>{$.START="WORLD_LOOP.START";$.STOP="WORLD_LOOP.STOP";$.TICK_START="WORLD_LOOP.TICK_START";$.TICK_END="WORLD_LOOP.TICK_END";$.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(DC||={});class IJ extends s{_currentTick=0;_ticker;_world;constructor(J,X=wH){super();this._ticker=new SJ(X,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get nextTickMs(){return this._ticker.nextTickMs}get timestepS(){return this._ticker.fixedTimestepS}get world(){return this._world}start(){this._ticker.start(),this.emitWithWorld(this._world,"WORLD_LOOP.START",{worldLoop:this})}stop(){this._ticker.stop(),this.emitWithWorld(this._world,"WORLD_LOOP.STOP",{worldLoop:this})}_tick=(J)=>{this.emitWithWorld(this._world,"WORLD_LOOP.TICK_START",{worldLoop:this,tickDeltaMs:J});let X=performance.now();this._world.chunkLattice.updateChunks(),this._world.entityManager.tickEntities(J),this._world.simulation.step(J),this._world.entityManager.checkAndEmitUpdates(),this._world.networkSynchronizer.synchronize(),this._currentTick++,this.emitWithWorld(this._world,"WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-X})};_onTickError=(J)=>{E.error(`WorldLoop._onTickError(): Error: ${J}`),this.emitWithWorld(this._world,"WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}var xH;((K)=>{K.SET_AMBIENT_LIGHT_COLOR="WORLD.SET_AMBIENT_LIGHT_COLOR";K.SET_AMBIENT_LIGHT_INTENSITY="WORLD.SET_AMBIENT_LIGHT_INTENSITY";K.SET_DIRECTIONAL_LIGHT_COLOR="WORLD.SET_DIRECTIONAL_LIGHT_COLOR";K.SET_DIRECTIONAL_LIGHT_INTENSITY="WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY";K.SET_DIRECTIONAL_LIGHT_POSITION="WORLD.SET_DIRECTIONAL_LIGHT_POSITION";K.START="WORLD.START";K.STOP="WORLD.STOP"})(xH||={});class hJ extends s{_id;_ambientLightColor;_ambientLightIntensity;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_name;_skyboxUri;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_entityManager;_lightManager;_loop;_networkSynchronizer;_sceneUIManager;_simulation;constructor(J){super();this._id=J.id,this._ambientLightColor=J.ambientLightColor??{r:255,g:255,b:255},this._ambientLightIntensity=J.ambientLightIntensity??1,this._directionalLightColor=J.directionalLightColor??{r:255,g:255,b:255},this._directionalLightIntensity=J.directionalLightIntensity??3,this._directionalLightPosition=J.directionalLightPosition??{x:100,y:150,z:100},this._name=J.name,this._skyboxUri=J.skyboxUri,this._audioManager=new Q4(this),this._blockTypeRegistry=new d4(this),this._chatManager=new fJ(this),this._chunkLattice=new PJ(this),this._entityManager=new jJ(this),this._lightManager=new kJ(this),this._loop=new IJ(this,J.tickRate),this._networkSynchronizer=new K$(this),this._sceneUIManager=new CJ(this),this._simulation=new EJ(this,J.tickRate,J.gravity)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get name(){return this._name}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get entityManager(){return this._entityManager}get lightManager(){return this._lightManager}get loop(){return this._loop}get networkSynchronizer(){return this._networkSynchronizer}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}loadMap(J){if(this.chunkLattice.clear(),J.blockTypes)for(let X of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:X.id,isLiquid:X.isLiquid,name:X.name,textureUri:X.textureUri});if(J.blocks)for(let[X,Y]of Object.entries(J.blocks)){let[Z,W,$]=X.split(",").map(Number);this.chunkLattice.setBlock({x:Z,y:W,z:$},Y)}if(J.entities)for(let[X,Y]of Object.entries(J.entities)){let[Z,W,$]=X.split(",").map(Number);new Y8(Y).spawn(this,{x:Z,y:W,z:$})}}setAmbientLightColor(J){this._ambientLightColor=J,this.emit("WORLD.SET_AMBIENT_LIGHT_COLOR",{world:this,color:J})}setAmbientLightIntensity(J){this._ambientLightIntensity=J,this.emit("WORLD.SET_AMBIENT_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightColor(J){this._directionalLightColor=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",{world:this,color:J})}setDirectionalLightIntensity(J){this._directionalLightIntensity=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightPosition(J){this._directionalLightPosition=J,this.emit("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",{world:this,position:J})}start(){this._loop.start(),this.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){this._loop.stop(),this.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return t.serializeWorld(this)}}var _C;((Y)=>{Y.START="GAMESERVER.START";Y.STOP="GAMESERVER.STOP"})(_C||={});function dX0(J){z0.init().then(()=>{return R1.instance.modelRegistry.preloadModels()}).then(()=>{J(R1.instance.worlds[0]),R1.instance.start()}).catch((X)=>{E.fatalError(`Failed to initialize the game engine, exiting. Error: ${X}`)})}class R1{static _instance;_modelRegistry=U6.instance;_playerManager=j6.instance;_socket=i1.instance;_webServer=o5.instance;_worlds={};constructor(){let J=new hJ({id:0,name:"Default World",skyboxUri:"skyboxes/partly-cloudy"});this._worlds[J.id]=J}static get instance(){if(!this._instance)this._instance=new R1;return this._instance}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worlds(){return this._worlds}start(){m8.emit("GAMESERVER.START",{startedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.start()),this._webServer.start()}stop(){m8.emit("GAMESERVER.STOP",{stoppedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.stop())}}class b9{static instance=new b9;constructor(){}async getGlobalData(J){let X=await u6.instance.getData(J);if(!X||X.error){if(X?.error)E.warning(`PersistenceManager.getGlobalData(): ${X.error.message}`);return}return X}async getPlayerData(J){let X=await u6.instance.getData(this._getPlayerKey(J));if(!X||X.error){if(X?.error)E.warning(`PersistenceManager.getPlayerData(): ${X.error.message}`);return}return X}async setGlobalData(J,X){let Y=await u6.instance.setData(J,X);if(!Y||Y.error){if(Y?.error)E.warning(`PersistenceManager.setGlobalData(): ${Y.error.message}`);return}return Y}async setPlayerData(J,X){let Y=await u6.instance.setData(this._getPlayerKey(J),X);if(!Y||Y.error){if(Y?.error)E.warning(`PersistenceManager.setPlayerData(): ${Y.error.message}`);return}return Y}_getPlayerKey(J){return`player-${J.id}`}}var EC=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","1","2","3","4","5","6","7","8","9","0"],BJ;((W)=>{W.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";W.JOINED_WORLD="PLAYER.JOINED_WORLD";W.LEFT_WORLD="PLAYER.LEFT_WORLD";W.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(BJ||={});class r5 extends s{static _devNextPlayerId=1;id;username;profilePictureUrl;camera;connection;ui;_input={};_lastUnreliableInputSequenceNumber=0;_world;constructor(J,X){super();this.id=X?.user.id??`player-${r5._devNextPlayerId++}`,this.username=X?.user.username??this.id,this.profilePictureUrl=X?.user.profilePictureURL??void 0,this.camera=new TJ(this),this.connection=J,this.ui=new DJ(this),J.onPacket(A.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(A.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(A.PacketId.INPUT,this._onInputPacket),J.onPacket(A.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(A.PacketId.UI_DATA_SEND,this._onUIDataSendPacket),this.joinWorld(R1.instance.worlds[0])}get input(){return this._input}get world(){return this._world}disconnect(){this.leaveWorld(),this.connection.close()}async getPersistedData(){return b9.instance.getPlayerData(this)}joinWorld(J){this.leaveWorld(),this._world=J,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world})}leaveWorld(){if(!this._world)return;this.emitWithWorld(this._world,"PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}async setPersistedData(J){return b9.instance.setPlayerData(this,J)}serialize(){return t.serializePlayer(this)}_onChatMessageSendPacket=(J)=>{if(this._world)this.emitWithWorld(this._world,"PLAYER.CHAT_MESSAGE_SEND",{player:this,message:J[1].m})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let X=J[1];if(X.sq!==void 0){if(X.sq<this._lastUnreliableInputSequenceNumber)return;this._lastUnreliableInputSequenceNumber=X.sq}if(EC.forEach((Y)=>{let Z=Y;if(X[Z]!==void 0)this._input[Z]=Boolean(X[Z])}),X.cp!==void 0)this.camera.setOrientationPitch(X.cp);if(X.cy!==void 0)this.camera.setOrientationYaw(X.cy)};_onSyncRequestPacket=()=>{if(this._world)this.emitWithWorld(this._world,"PLAYER.REQUEST_SYNC",{player:this,receivedAt:Date.now(),receivedAtMs:performance.now()})};_onUIDataSendPacket=(J)=>{this.ui.emit("PLAYER_UI.DATA",{playerUI:this.ui,data:J[1]})}}var PH;((Y)=>{Y.BROADCAST_MESSAGE="CHAT.BROADCAST_MESSAGE";Y.PLAYER_MESSAGE="CHAT.PLAYER_MESSAGE"})(PH||={});class fJ extends s{_commandCallbacks={};_world;constructor(J){super();this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,X){this._commandCallbacks[J]=X}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,X){this._sendBroadcastMessage(void 0,J,X)}sendPlayerMessage(J,X,Y){this.emitWithWorld(this._world,"CHAT.PLAYER_MESSAGE",{player:J,message:X,color:Y})}_subscribeToPlayerEvents(){this._world.on("PLAYER.CHAT_MESSAGE_SEND",(J)=>{let{player:X,message:Y}=J,[Z,...W]=Y.split(" "),$=this._commandCallbacks[Z];if($){$(X,W,Y);return}this._sendBroadcastMessage(X,Y)})}_sendBroadcastMessage(J,X,Y){this.emitWithWorld(this._world,"CHAT.BROADCAST_MESSAGE",{player:J,message:X,color:Y})}}var l=0.000001,Q0=typeof Float32Array!=="undefined"?Float32Array:Array,d6=Math.random;var L_0=Math.PI/180;if(!Math.hypot)Math.hypot=function(){var J=0,X=arguments.length;while(X--)J+=arguments[X]*arguments[X];return Math.sqrt(J)};var e0={};k6(e0,{transpose:()=>tX0,subtract:()=>SC,sub:()=>VY0,str:()=>QY0,set:()=>rX0,scale:()=>ZY0,rotate:()=>YY0,multiplyScalarAndAdd:()=>LY0,multiplyScalar:()=>zY0,multiply:()=>CC,mul:()=>UY0,invert:()=>eX0,identity:()=>sX0,fromValues:()=>oX0,fromScaling:()=>$Y0,fromRotation:()=>WY0,frob:()=>KY0,exactEquals:()=>qY0,equals:()=>HY0,determinant:()=>XY0,create:()=>iX0,copy:()=>aX0,clone:()=>nX0,adjoint:()=>JY0,add:()=>FY0,LDU:()=>GY0});function iX0(){var J=new Q0(4);if(Q0!=Float32Array)J[1]=0,J[2]=0;return J[0]=1,J[3]=1,J}function nX0(J){var X=new Q0(4);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X}function aX0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J}function sX0(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=1,J}function oX0(J,X,Y,Z){var W=new Q0(4);return W[0]=J,W[1]=X,W[2]=Y,W[3]=Z,W}function rX0(J,X,Y,Z,W){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J}function tX0(J,X){if(J===X){var Y=X[1];J[1]=X[2],J[2]=Y}else J[0]=X[0],J[1]=X[2],J[2]=X[1],J[3]=X[3];return J}function eX0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*$-W*Z;if(!Q)return null;return Q=1/Q,J[0]=$*Q,J[1]=-Z*Q,J[2]=-W*Q,J[3]=Y*Q,J}function JY0(J,X){var Y=X[0];return J[0]=X[3],J[1]=-X[1],J[2]=-X[2],J[3]=Y,J}function XY0(J){return J[0]*J[3]-J[2]*J[1]}function CC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1],F=Y[2],q=Y[3];return J[0]=Z*K+$*G,J[1]=W*K+Q*G,J[2]=Z*F+$*q,J[3]=W*F+Q*q,J}function YY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+$*K,J[1]=W*G+Q*K,J[2]=Z*-K+$*G,J[3]=W*-K+Q*G,J}function ZY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1];return J[0]=Z*K,J[1]=W*K,J[2]=$*G,J[3]=Q*G,J}function WY0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=-Y,J[3]=Z,J}function $Y0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=X[1],J}function QY0(J){return"mat2("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}function KY0(J){return Math.hypot(J[0],J[1],J[2],J[3])}function GY0(J,X,Y,Z){return J[2]=Z[2]/Z[0],Y[0]=Z[0],Y[1]=Z[1],Y[3]=Z[3]-J[2]*Y[1],[J,X,Y]}function FY0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J}function SC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J}function qY0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]}function HY0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=X[0],K=X[1],G=X[2],F=X[3];return Math.abs(Y-Q)<=l*Math.max(1,Math.abs(Y),Math.abs(Q))&&Math.abs(Z-K)<=l*Math.max(1,Math.abs(Z),Math.abs(K))&&Math.abs(W-G)<=l*Math.max(1,Math.abs(W),Math.abs(G))&&Math.abs($-F)<=l*Math.max(1,Math.abs($),Math.abs(F))}function zY0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J}function LY0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J}var UY0=CC,VY0=SC;var h0={};k6(h0,{transpose:()=>NY0,translate:()=>kY0,subtract:()=>hC,sub:()=>uY0,str:()=>bY0,set:()=>xY0,scale:()=>DY0,rotate:()=>TY0,projection:()=>fY0,normalFromMat4:()=>hY0,multiplyScalarAndAdd:()=>gY0,multiplyScalar:()=>yY0,multiply:()=>IC,mul:()=>lY0,invert:()=>vY0,identity:()=>PY0,fromValues:()=>OY0,fromTranslation:()=>_Y0,fromScaling:()=>CY0,fromRotation:()=>EY0,fromQuat:()=>IY0,fromMat4:()=>MY0,fromMat2d:()=>SY0,frob:()=>pY0,exactEquals:()=>cY0,equals:()=>mY0,determinant:()=>jY0,create:()=>NH,copy:()=>wY0,clone:()=>RY0,adjoint:()=>BY0,add:()=>AY0});function NH(){var J=new Q0(9);if(Q0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[5]=0,J[6]=0,J[7]=0;return J[0]=1,J[4]=1,J[8]=1,J}function MY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[4],J[4]=X[5],J[5]=X[6],J[6]=X[8],J[7]=X[9],J[8]=X[10],J}function RY0(J){var X=new Q0(9);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X[4]=J[4],X[5]=J[5],X[6]=J[6],X[7]=J[7],X[8]=J[8],X}function wY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J}function OY0(J,X,Y,Z,W,$,Q,K,G){var F=new Q0(9);return F[0]=J,F[1]=X,F[2]=Y,F[3]=Z,F[4]=W,F[5]=$,F[6]=Q,F[7]=K,F[8]=G,F}function xY0(J,X,Y,Z,W,$,Q,K,G,F){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J[4]=$,J[5]=Q,J[6]=K,J[7]=G,J[8]=F,J}function PY0(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function NY0(J,X){if(J===X){var Y=X[1],Z=X[2],W=X[5];J[1]=X[3],J[2]=X[6],J[3]=Y,J[5]=X[7],J[6]=Z,J[7]=W}else J[0]=X[0],J[1]=X[3],J[2]=X[6],J[3]=X[1],J[4]=X[4],J[5]=X[7],J[6]=X[2],J[7]=X[5],J[8]=X[8];return J}function vY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=q*Q-K*F,z=-q*$+K*G,V=F*$-Q*G,M=Y*H+Z*z+W*V;if(!M)return null;return M=1/M,J[0]=H*M,J[1]=(-q*Z+W*F)*M,J[2]=(K*Z-W*Q)*M,J[3]=z*M,J[4]=(q*Y-W*G)*M,J[5]=(-K*Y+W*$)*M,J[6]=V*M,J[7]=(-F*Y+Z*G)*M,J[8]=(Q*Y-Z*$)*M,J}function BY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8];return J[0]=Q*q-K*F,J[1]=W*F-Z*q,J[2]=Z*K-W*Q,J[3]=K*G-$*q,J[4]=Y*q-W*G,J[5]=W*$-Y*K,J[6]=$*F-Q*G,J[7]=Z*G-Y*F,J[8]=Y*Q-Z*$,J}function jY0(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8];return X*(F*$-Q*G)+Y*(-F*W+Q*K)+Z*(G*W-$*K)}function IC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Y[0],V=Y[1],M=Y[2],R=Y[3],L=Y[4],w=Y[5],P=Y[6],N=Y[7],v=Y[8];return J[0]=z*Z+V*Q+M*F,J[1]=z*W+V*K+M*q,J[2]=z*$+V*G+M*H,J[3]=R*Z+L*Q+w*F,J[4]=R*W+L*K+w*q,J[5]=R*$+L*G+w*H,J[6]=P*Z+N*Q+v*F,J[7]=P*W+N*K+v*q,J[8]=P*$+N*G+v*H,J}function kY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Y[0],V=Y[1];return J[0]=Z,J[1]=W,J[2]=$,J[3]=Q,J[4]=K,J[5]=G,J[6]=z*Z+V*Q+F,J[7]=z*W+V*K+q,J[8]=z*$+V*G+H,J}function TY0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=Math.sin(Y),V=Math.cos(Y);return J[0]=V*Z+z*Q,J[1]=V*W+z*K,J[2]=V*$+z*G,J[3]=V*Q-z*Z,J[4]=V*K-z*W,J[5]=V*G-z*$,J[6]=F,J[7]=q,J[8]=H,J}function DY0(J,X,Y){var Z=Y[0],W=Y[1];return J[0]=Z*X[0],J[1]=Z*X[1],J[2]=Z*X[2],J[3]=W*X[3],J[4]=W*X[4],J[5]=W*X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J}function _Y0(J,X){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=X[0],J[7]=X[1],J[8]=1,J}function EY0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=0,J[3]=-Y,J[4]=Z,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function CY0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=0,J[4]=X[1],J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function SY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=0,J[3]=X[2],J[4]=X[3],J[5]=0,J[6]=X[4],J[7]=X[5],J[8]=1,J}function IY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y+Y,K=Z+Z,G=W+W,F=Y*Q,q=Z*Q,H=Z*K,z=W*Q,V=W*K,M=W*G,R=$*Q,L=$*K,w=$*G;return J[0]=1-H-M,J[3]=q-w,J[6]=z+L,J[1]=q+w,J[4]=1-F-M,J[7]=V-R,J[2]=z-L,J[5]=V+R,J[8]=1-F-H,J}function hY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15],P=Y*K-Z*Q,N=Y*G-W*Q,v=Y*F-$*Q,j=Z*G-W*K,O=Z*F-$*K,D=W*F-$*G,_=q*R-H*M,C=q*L-z*M,S=q*w-V*M,I=H*L-z*R,f=H*w-V*R,y=z*w-V*L,h=P*y-N*f+v*I+j*S-O*C+D*_;if(!h)return null;return h=1/h,J[0]=(K*y-G*f+F*I)*h,J[1]=(G*S-Q*y-F*C)*h,J[2]=(Q*f-K*S+F*_)*h,J[3]=(W*f-Z*y-$*I)*h,J[4]=(Y*y-W*S+$*C)*h,J[5]=(Z*S-Y*f-$*_)*h,J[6]=(R*D-L*O+w*j)*h,J[7]=(L*v-M*D-w*N)*h,J[8]=(M*O-R*v+w*P)*h,J}function fY0(J,X,Y){return J[0]=2/X,J[1]=0,J[2]=0,J[3]=0,J[4]=-2/Y,J[5]=0,J[6]=-1,J[7]=1,J[8]=1,J}function bY0(J){return"mat3("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+")"}function pY0(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8])}function AY0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J[4]=X[4]+Y[4],J[5]=X[5]+Y[5],J[6]=X[6]+Y[6],J[7]=X[7]+Y[7],J[8]=X[8]+Y[8],J}function hC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J[4]=X[4]-Y[4],J[5]=X[5]-Y[5],J[6]=X[6]-Y[6],J[7]=X[7]-Y[7],J[8]=X[8]-Y[8],J}function yY0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J[4]=X[4]*Y,J[5]=X[5]*Y,J[6]=X[6]*Y,J[7]=X[7]*Y,J[8]=X[8]*Y,J}function gY0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J[4]=X[4]+Y[4]*Z,J[5]=X[5]+Y[5]*Z,J[6]=X[6]+Y[6]*Z,J[7]=X[7]+Y[7]*Z,J[8]=X[8]+Y[8]*Z,J}function cY0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]&&J[4]===X[4]&&J[5]===X[5]&&J[6]===X[6]&&J[7]===X[7]&&J[8]===X[8]}function mY0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=J[4],K=J[5],G=J[6],F=J[7],q=J[8],H=X[0],z=X[1],V=X[2],M=X[3],R=X[4],L=X[5],w=X[6],P=X[7],N=X[8];return Math.abs(Y-H)<=l*Math.max(1,Math.abs(Y),Math.abs(H))&&Math.abs(Z-z)<=l*Math.max(1,Math.abs(Z),Math.abs(z))&&Math.abs(W-V)<=l*Math.max(1,Math.abs(W),Math.abs(V))&&Math.abs($-M)<=l*Math.max(1,Math.abs($),Math.abs(M))&&Math.abs(Q-R)<=l*Math.max(1,Math.abs(Q),Math.abs(R))&&Math.abs(K-L)<=l*Math.max(1,Math.abs(K),Math.abs(L))&&Math.abs(G-w)<=l*Math.max(1,Math.abs(G),Math.abs(w))&&Math.abs(F-P)<=l*Math.max(1,Math.abs(F),Math.abs(P))&&Math.abs(q-N)<=l*Math.max(1,Math.abs(q),Math.abs(N))}var lY0=IC,uY0=hC;var Y0={};k6(Y0,{transpose:()=>oY0,translate:()=>JZ0,targetTo:()=>jZ0,subtract:()=>cC,sub:()=>hZ0,str:()=>kZ0,set:()=>sY0,scale:()=>XZ0,rotateZ:()=>$Z0,rotateY:()=>WZ0,rotateX:()=>ZZ0,rotate:()=>YZ0,perspectiveZO:()=>xZ0,perspectiveNO:()=>yC,perspectiveFromFieldOfView:()=>PZ0,perspective:()=>OZ0,orthoZO:()=>vZ0,orthoNO:()=>gC,ortho:()=>NZ0,multiplyScalarAndAdd:()=>EZ0,multiplyScalar:()=>_Z0,multiply:()=>bC,mul:()=>IZ0,lookAt:()=>BZ0,invert:()=>rY0,identity:()=>fC,getTranslation:()=>LZ0,getScaling:()=>AC,getRotation:()=>UZ0,frustum:()=>wZ0,fromZRotation:()=>HZ0,fromYRotation:()=>qZ0,fromXRotation:()=>FZ0,fromValues:()=>aY0,fromTranslation:()=>QZ0,fromScaling:()=>KZ0,fromRotationTranslationScaleOrigin:()=>MZ0,fromRotationTranslationScale:()=>VZ0,fromRotationTranslation:()=>pC,fromRotation:()=>GZ0,fromQuat2:()=>zZ0,fromQuat:()=>RZ0,frob:()=>TZ0,exactEquals:()=>CZ0,equals:()=>SZ0,determinant:()=>eY0,create:()=>dY0,copy:()=>nY0,clone:()=>iY0,adjoint:()=>tY0,add:()=>DZ0});function dY0(){var J=new Q0(16);if(Q0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=0,J[12]=0,J[13]=0,J[14]=0;return J[0]=1,J[5]=1,J[10]=1,J[15]=1,J}function iY0(J){var X=new Q0(16);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X[4]=J[4],X[5]=J[5],X[6]=J[6],X[7]=J[7],X[8]=J[8],X[9]=J[9],X[10]=J[10],X[11]=J[11],X[12]=J[12],X[13]=J[13],X[14]=J[14],X[15]=J[15],X}function nY0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[8]=X[8],J[9]=X[9],J[10]=X[10],J[11]=X[11],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15],J}function aY0(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R){var L=new Q0(16);return L[0]=J,L[1]=X,L[2]=Y,L[3]=Z,L[4]=W,L[5]=$,L[6]=Q,L[7]=K,L[8]=G,L[9]=F,L[10]=q,L[11]=H,L[12]=z,L[13]=V,L[14]=M,L[15]=R,L}function sY0(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R,L){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J[4]=$,J[5]=Q,J[6]=K,J[7]=G,J[8]=F,J[9]=q,J[10]=H,J[11]=z,J[12]=V,J[13]=M,J[14]=R,J[15]=L,J}function fC(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function oY0(J,X){if(J===X){var Y=X[1],Z=X[2],W=X[3],$=X[6],Q=X[7],K=X[11];J[1]=X[4],J[2]=X[8],J[3]=X[12],J[4]=Y,J[6]=X[9],J[7]=X[13],J[8]=Z,J[9]=$,J[11]=X[14],J[12]=W,J[13]=Q,J[14]=K}else J[0]=X[0],J[1]=X[4],J[2]=X[8],J[3]=X[12],J[4]=X[1],J[5]=X[5],J[6]=X[9],J[7]=X[13],J[8]=X[2],J[9]=X[6],J[10]=X[10],J[11]=X[14],J[12]=X[3],J[13]=X[7],J[14]=X[11],J[15]=X[15];return J}function rY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15],P=Y*K-Z*Q,N=Y*G-W*Q,v=Y*F-$*Q,j=Z*G-W*K,O=Z*F-$*K,D=W*F-$*G,_=q*R-H*M,C=q*L-z*M,S=q*w-V*M,I=H*L-z*R,f=H*w-V*R,y=z*w-V*L,h=P*y-N*f+v*I+j*S-O*C+D*_;if(!h)return null;return h=1/h,J[0]=(K*y-G*f+F*I)*h,J[1]=(W*f-Z*y-$*I)*h,J[2]=(R*D-L*O+w*j)*h,J[3]=(z*O-H*D-V*j)*h,J[4]=(G*S-Q*y-F*C)*h,J[5]=(Y*y-W*S+$*C)*h,J[6]=(L*v-M*D-w*N)*h,J[7]=(q*D-z*v+V*N)*h,J[8]=(Q*f-K*S+F*_)*h,J[9]=(Z*S-Y*f-$*_)*h,J[10]=(M*O-R*v+w*P)*h,J[11]=(H*v-q*O-V*P)*h,J[12]=(K*C-Q*I-G*_)*h,J[13]=(Y*I-Z*C+W*_)*h,J[14]=(R*N-M*j-L*P)*h,J[15]=(q*j-H*N+z*P)*h,J}function tY0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=X[4],K=X[5],G=X[6],F=X[7],q=X[8],H=X[9],z=X[10],V=X[11],M=X[12],R=X[13],L=X[14],w=X[15];return J[0]=K*(z*w-V*L)-H*(G*w-F*L)+R*(G*V-F*z),J[1]=-(Z*(z*w-V*L)-H*(W*w-$*L)+R*(W*V-$*z)),J[2]=Z*(G*w-F*L)-K*(W*w-$*L)+R*(W*F-$*G),J[3]=-(Z*(G*V-F*z)-K*(W*V-$*z)+H*(W*F-$*G)),J[4]=-(Q*(z*w-V*L)-q*(G*w-F*L)+M*(G*V-F*z)),J[5]=Y*(z*w-V*L)-q*(W*w-$*L)+M*(W*V-$*z),J[6]=-(Y*(G*w-F*L)-Q*(W*w-$*L)+M*(W*F-$*G)),J[7]=Y*(G*V-F*z)-Q*(W*V-$*z)+q*(W*F-$*G),J[8]=Q*(H*w-V*R)-q*(K*w-F*R)+M*(K*V-F*H),J[9]=-(Y*(H*w-V*R)-q*(Z*w-$*R)+M*(Z*V-$*H)),J[10]=Y*(K*w-F*R)-Q*(Z*w-$*R)+M*(Z*F-$*K),J[11]=-(Y*(K*V-F*H)-Q*(Z*V-$*H)+q*(Z*F-$*K)),J[12]=-(Q*(H*L-z*R)-q*(K*L-G*R)+M*(K*z-G*H)),J[13]=Y*(H*L-z*R)-q*(Z*L-W*R)+M*(Z*z-W*H),J[14]=-(Y*(K*L-G*R)-Q*(Z*L-W*R)+M*(Z*G-W*K)),J[15]=Y*(K*z-G*H)-Q*(Z*z-W*H)+q*(Z*G-W*K),J}function eY0(J){var X=J[0],Y=J[1],Z=J[2],W=J[3],$=J[4],Q=J[5],K=J[6],G=J[7],F=J[8],q=J[9],H=J[10],z=J[11],V=J[12],M=J[13],R=J[14],L=J[15],w=X*Q-Y*$,P=X*K-Z*$,N=X*G-W*$,v=Y*K-Z*Q,j=Y*G-W*Q,O=Z*G-W*K,D=F*M-q*V,_=F*R-H*V,C=F*L-z*V,S=q*R-H*M,I=q*L-z*M,f=H*L-z*R;return w*f-P*I+N*S+v*C-j*_+O*D}function bC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=X[8],z=X[9],V=X[10],M=X[11],R=X[12],L=X[13],w=X[14],P=X[15],N=Y[0],v=Y[1],j=Y[2],O=Y[3];return J[0]=N*Z+v*K+j*H+O*R,J[1]=N*W+v*G+j*z+O*L,J[2]=N*$+v*F+j*V+O*w,J[3]=N*Q+v*q+j*M+O*P,N=Y[4],v=Y[5],j=Y[6],O=Y[7],J[4]=N*Z+v*K+j*H+O*R,J[5]=N*W+v*G+j*z+O*L,J[6]=N*$+v*F+j*V+O*w,J[7]=N*Q+v*q+j*M+O*P,N=Y[8],v=Y[9],j=Y[10],O=Y[11],J[8]=N*Z+v*K+j*H+O*R,J[9]=N*W+v*G+j*z+O*L,J[10]=N*$+v*F+j*V+O*w,J[11]=N*Q+v*q+j*M+O*P,N=Y[12],v=Y[13],j=Y[14],O=Y[15],J[12]=N*Z+v*K+j*H+O*R,J[13]=N*W+v*G+j*z+O*L,J[14]=N*$+v*F+j*V+O*w,J[15]=N*Q+v*q+j*M+O*P,J}function JZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q,K,G,F,q,H,z,V,M,R,L,w;if(X===J)J[12]=X[0]*Z+X[4]*W+X[8]*$+X[12],J[13]=X[1]*Z+X[5]*W+X[9]*$+X[13],J[14]=X[2]*Z+X[6]*W+X[10]*$+X[14],J[15]=X[3]*Z+X[7]*W+X[11]*$+X[15];else Q=X[0],K=X[1],G=X[2],F=X[3],q=X[4],H=X[5],z=X[6],V=X[7],M=X[8],R=X[9],L=X[10],w=X[11],J[0]=Q,J[1]=K,J[2]=G,J[3]=F,J[4]=q,J[5]=H,J[6]=z,J[7]=V,J[8]=M,J[9]=R,J[10]=L,J[11]=w,J[12]=Q*Z+q*W+M*$+X[12],J[13]=K*Z+H*W+R*$+X[13],J[14]=G*Z+z*W+L*$+X[14],J[15]=F*Z+V*W+w*$+X[15];return J}function XZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2];return J[0]=X[0]*Z,J[1]=X[1]*Z,J[2]=X[2]*Z,J[3]=X[3]*Z,J[4]=X[4]*W,J[5]=X[5]*W,J[6]=X[6]*W,J[7]=X[7]*W,J[8]=X[8]*$,J[9]=X[9]*$,J[10]=X[10]*$,J[11]=X[11]*$,J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15],J}function YZ0(J,X,Y,Z){var W=Z[0],$=Z[1],Q=Z[2],K=Math.hypot(W,$,Q),G,F,q,H,z,V,M,R,L,w,P,N,v,j,O,D,_,C,S,I,f,y,h,g;if(K<l)return null;if(K=1/K,W*=K,$*=K,Q*=K,G=Math.sin(Y),F=Math.cos(Y),q=1-F,H=X[0],z=X[1],V=X[2],M=X[3],R=X[4],L=X[5],w=X[6],P=X[7],N=X[8],v=X[9],j=X[10],O=X[11],D=W*W*q+F,_=$*W*q+Q*G,C=Q*W*q-$*G,S=W*$*q-Q*G,I=$*$*q+F,f=Q*$*q+W*G,y=W*Q*q+$*G,h=$*Q*q-W*G,g=Q*Q*q+F,J[0]=H*D+R*_+N*C,J[1]=z*D+L*_+v*C,J[2]=V*D+w*_+j*C,J[3]=M*D+P*_+O*C,J[4]=H*S+R*I+N*f,J[5]=z*S+L*I+v*f,J[6]=V*S+w*I+j*f,J[7]=M*S+P*I+O*f,J[8]=H*y+R*h+N*g,J[9]=z*y+L*h+v*g,J[10]=V*y+w*h+j*g,J[11]=M*y+P*h+O*g,X!==J)J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J}function ZZ0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[4],Q=X[5],K=X[6],G=X[7],F=X[8],q=X[9],H=X[10],z=X[11];if(X!==J)J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[4]=$*W+F*Z,J[5]=Q*W+q*Z,J[6]=K*W+H*Z,J[7]=G*W+z*Z,J[8]=F*W-$*Z,J[9]=q*W-Q*Z,J[10]=H*W-K*Z,J[11]=z*W-G*Z,J}function WZ0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[0],Q=X[1],K=X[2],G=X[3],F=X[8],q=X[9],H=X[10],z=X[11];if(X!==J)J[4]=X[4],J[5]=X[5],J[6]=X[6],J[7]=X[7],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[0]=$*W-F*Z,J[1]=Q*W-q*Z,J[2]=K*W-H*Z,J[3]=G*W-z*Z,J[8]=$*Z+F*W,J[9]=Q*Z+q*W,J[10]=K*Z+H*W,J[11]=G*Z+z*W,J}function $Z0(J,X,Y){var Z=Math.sin(Y),W=Math.cos(Y),$=X[0],Q=X[1],K=X[2],G=X[3],F=X[4],q=X[5],H=X[6],z=X[7];if(X!==J)J[8]=X[8],J[9]=X[9],J[10]=X[10],J[11]=X[11],J[12]=X[12],J[13]=X[13],J[14]=X[14],J[15]=X[15];return J[0]=$*W+F*Z,J[1]=Q*W+q*Z,J[2]=K*W+H*Z,J[3]=G*W+z*Z,J[4]=F*W-$*Z,J[5]=q*W-Q*Z,J[6]=H*W-K*Z,J[7]=z*W-G*Z,J}function QZ0(J,X){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=X[0],J[13]=X[1],J[14]=X[2],J[15]=1,J}function KZ0(J,X){return J[0]=X[0],J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=X[1],J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=X[2],J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function GZ0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q=Math.hypot(Z,W,$),K,G,F;if(Q<l)return null;return Q=1/Q,Z*=Q,W*=Q,$*=Q,K=Math.sin(X),G=Math.cos(X),F=1-G,J[0]=Z*Z*F+G,J[1]=W*Z*F+$*K,J[2]=$*Z*F-W*K,J[3]=0,J[4]=Z*W*F-$*K,J[5]=W*W*F+G,J[6]=$*W*F+Z*K,J[7]=0,J[8]=Z*$*F+W*K,J[9]=W*$*F-Z*K,J[10]=$*$*F+G,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function FZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=Z,J[6]=Y,J[7]=0,J[8]=0,J[9]=-Y,J[10]=Z,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function qZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=0,J[2]=-Y,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=Y,J[9]=0,J[10]=Z,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function HZ0(J,X){var Y=Math.sin(X),Z=Math.cos(X);return J[0]=Z,J[1]=Y,J[2]=0,J[3]=0,J[4]=-Y,J[5]=Z,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function pC(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Z+Z,G=W+W,F=$+$,q=Z*K,H=Z*G,z=Z*F,V=W*G,M=W*F,R=$*F,L=Q*K,w=Q*G,P=Q*F;return J[0]=1-(V+R),J[1]=H+P,J[2]=z-w,J[3]=0,J[4]=H-P,J[5]=1-(q+R),J[6]=M+L,J[7]=0,J[8]=z+w,J[9]=M-L,J[10]=1-(q+V),J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function zZ0(J,X){var Y=new Q0(3),Z=-X[0],W=-X[1],$=-X[2],Q=X[3],K=X[4],G=X[5],F=X[6],q=X[7],H=Z*Z+W*W+$*$+Q*Q;if(H>0)Y[0]=(K*Q+q*Z+G*$-F*W)*2/H,Y[1]=(G*Q+q*W+F*Z-K*$)*2/H,Y[2]=(F*Q+q*$+K*W-G*Z)*2/H;else Y[0]=(K*Q+q*Z+G*$-F*W)*2,Y[1]=(G*Q+q*W+F*Z-K*$)*2,Y[2]=(F*Q+q*$+K*W-G*Z)*2;return pC(J,X,Y),J}function LZ0(J,X){return J[0]=X[12],J[1]=X[13],J[2]=X[14],J}function AC(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[4],Q=X[5],K=X[6],G=X[8],F=X[9],q=X[10];return J[0]=Math.hypot(Y,Z,W),J[1]=Math.hypot($,Q,K),J[2]=Math.hypot(G,F,q),J}function UZ0(J,X){var Y=new Q0(3);AC(Y,X);var Z=1/Y[0],W=1/Y[1],$=1/Y[2],Q=X[0]*Z,K=X[1]*W,G=X[2]*$,F=X[4]*Z,q=X[5]*W,H=X[6]*$,z=X[8]*Z,V=X[9]*W,M=X[10]*$,R=Q+q+M,L=0;if(R>0)L=Math.sqrt(R+1)*2,J[3]=0.25*L,J[0]=(H-V)/L,J[1]=(z-G)/L,J[2]=(K-F)/L;else if(Q>q&&Q>M)L=Math.sqrt(1+Q-q-M)*2,J[3]=(H-V)/L,J[0]=0.25*L,J[1]=(K+F)/L,J[2]=(z+G)/L;else if(q>M)L=Math.sqrt(1+q-Q-M)*2,J[3]=(z-G)/L,J[0]=(K+F)/L,J[1]=0.25*L,J[2]=(H+V)/L;else L=Math.sqrt(1+M-Q-q)*2,J[3]=(K-F)/L,J[0]=(z+G)/L,J[1]=(H+V)/L,J[2]=0.25*L;return J}function VZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3],G=W+W,F=$+$,q=Q+Q,H=W*G,z=W*F,V=W*q,M=$*F,R=$*q,L=Q*q,w=K*G,P=K*F,N=K*q,v=Z[0],j=Z[1],O=Z[2];return J[0]=(1-(M+L))*v,J[1]=(z+N)*v,J[2]=(V-P)*v,J[3]=0,J[4]=(z-N)*j,J[5]=(1-(H+L))*j,J[6]=(R+w)*j,J[7]=0,J[8]=(V+P)*O,J[9]=(R-w)*O,J[10]=(1-(H+M))*O,J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function MZ0(J,X,Y,Z,W){var $=X[0],Q=X[1],K=X[2],G=X[3],F=$+$,q=Q+Q,H=K+K,z=$*F,V=$*q,M=$*H,R=Q*q,L=Q*H,w=K*H,P=G*F,N=G*q,v=G*H,j=Z[0],O=Z[1],D=Z[2],_=W[0],C=W[1],S=W[2],I=(1-(R+w))*j,f=(V+v)*j,y=(M-N)*j,h=(V-v)*O,g=(1-(z+w))*O,J0=(L+P)*O,p0=(M+N)*D,a0=(L-P)*D,Q6=(1-(z+R))*D;return J[0]=I,J[1]=f,J[2]=y,J[3]=0,J[4]=h,J[5]=g,J[6]=J0,J[7]=0,J[8]=p0,J[9]=a0,J[10]=Q6,J[11]=0,J[12]=Y[0]+_-(I*_+h*C+p0*S),J[13]=Y[1]+C-(f*_+g*C+a0*S),J[14]=Y[2]+S-(y*_+J0*C+Q6*S),J[15]=1,J}function RZ0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y+Y,K=Z+Z,G=W+W,F=Y*Q,q=Z*Q,H=Z*K,z=W*Q,V=W*K,M=W*G,R=$*Q,L=$*K,w=$*G;return J[0]=1-H-M,J[1]=q+w,J[2]=z-L,J[3]=0,J[4]=q-w,J[5]=1-F-M,J[6]=V+R,J[7]=0,J[8]=z+L,J[9]=V-R,J[10]=1-F-H,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function wZ0(J,X,Y,Z,W,$,Q){var K=1/(Y-X),G=1/(W-Z),F=1/($-Q);return J[0]=$*2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$*2*G,J[6]=0,J[7]=0,J[8]=(Y+X)*K,J[9]=(W+Z)*G,J[10]=(Q+$)*F,J[11]=-1,J[12]=0,J[13]=0,J[14]=Q*$*2*F,J[15]=0,J}function yC(J,X,Y,Z,W){var $=1/Math.tan(X/2),Q;if(J[0]=$/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,W!=null&&W!==1/0)Q=1/(Z-W),J[10]=(W+Z)*Q,J[14]=2*W*Z*Q;else J[10]=-1,J[14]=-2*Z;return J}var OZ0=yC;function xZ0(J,X,Y,Z,W){var $=1/Math.tan(X/2),Q;if(J[0]=$/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=$,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,W!=null&&W!==1/0)Q=1/(Z-W),J[10]=W*Q,J[14]=W*Z*Q;else J[10]=-1,J[14]=-Z;return J}function PZ0(J,X,Y,Z){var W=Math.tan(X.upDegrees*Math.PI/180),$=Math.tan(X.downDegrees*Math.PI/180),Q=Math.tan(X.leftDegrees*Math.PI/180),K=Math.tan(X.rightDegrees*Math.PI/180),G=2/(Q+K),F=2/(W+$);return J[0]=G,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=F,J[6]=0,J[7]=0,J[8]=-((Q-K)*G*0.5),J[9]=(W-$)*F*0.5,J[10]=Z/(Y-Z),J[11]=-1,J[12]=0,J[13]=0,J[14]=Z*Y/(Y-Z),J[15]=0,J}function gC(J,X,Y,Z,W,$,Q){var K=1/(X-Y),G=1/(Z-W),F=1/($-Q);return J[0]=-2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*G,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=2*F,J[11]=0,J[12]=(X+Y)*K,J[13]=(W+Z)*G,J[14]=(Q+$)*F,J[15]=1,J}var NZ0=gC;function vZ0(J,X,Y,Z,W,$,Q){var K=1/(X-Y),G=1/(Z-W),F=1/($-Q);return J[0]=-2*K,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*G,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=F,J[11]=0,J[12]=(X+Y)*K,J[13]=(W+Z)*G,J[14]=$*F,J[15]=1,J}function BZ0(J,X,Y,Z){var W,$,Q,K,G,F,q,H,z,V,M=X[0],R=X[1],L=X[2],w=Z[0],P=Z[1],N=Z[2],v=Y[0],j=Y[1],O=Y[2];if(Math.abs(M-v)<l&&Math.abs(R-j)<l&&Math.abs(L-O)<l)return fC(J);if(q=M-v,H=R-j,z=L-O,V=1/Math.hypot(q,H,z),q*=V,H*=V,z*=V,W=P*z-N*H,$=N*q-w*z,Q=w*H-P*q,V=Math.hypot(W,$,Q),!V)W=0,$=0,Q=0;else V=1/V,W*=V,$*=V,Q*=V;if(K=H*Q-z*$,G=z*W-q*Q,F=q*$-H*W,V=Math.hypot(K,G,F),!V)K=0,G=0,F=0;else V=1/V,K*=V,G*=V,F*=V;return J[0]=W,J[1]=K,J[2]=q,J[3]=0,J[4]=$,J[5]=G,J[6]=H,J[7]=0,J[8]=Q,J[9]=F,J[10]=z,J[11]=0,J[12]=-(W*M+$*R+Q*L),J[13]=-(K*M+G*R+F*L),J[14]=-(q*M+H*R+z*L),J[15]=1,J}function jZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=Z[0],G=Z[1],F=Z[2],q=W-Y[0],H=$-Y[1],z=Q-Y[2],V=q*q+H*H+z*z;if(V>0)V=1/Math.sqrt(V),q*=V,H*=V,z*=V;var M=G*z-F*H,R=F*q-K*z,L=K*H-G*q;if(V=M*M+R*R+L*L,V>0)V=1/Math.sqrt(V),M*=V,R*=V,L*=V;return J[0]=M,J[1]=R,J[2]=L,J[3]=0,J[4]=H*L-z*R,J[5]=z*M-q*L,J[6]=q*R-H*M,J[7]=0,J[8]=q,J[9]=H,J[10]=z,J[11]=0,J[12]=W,J[13]=$,J[14]=Q,J[15]=1,J}function kZ0(J){return"mat4("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+", "+J[9]+", "+J[10]+", "+J[11]+", "+J[12]+", "+J[13]+", "+J[14]+", "+J[15]+")"}function TZ0(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8],J[9],J[10],J[11],J[12],J[13],J[14],J[15])}function DZ0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J[4]=X[4]+Y[4],J[5]=X[5]+Y[5],J[6]=X[6]+Y[6],J[7]=X[7]+Y[7],J[8]=X[8]+Y[8],J[9]=X[9]+Y[9],J[10]=X[10]+Y[10],J[11]=X[11]+Y[11],J[12]=X[12]+Y[12],J[13]=X[13]+Y[13],J[14]=X[14]+Y[14],J[15]=X[15]+Y[15],J}function cC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J[3]=X[3]-Y[3],J[4]=X[4]-Y[4],J[5]=X[5]-Y[5],J[6]=X[6]-Y[6],J[7]=X[7]-Y[7],J[8]=X[8]-Y[8],J[9]=X[9]-Y[9],J[10]=X[10]-Y[10],J[11]=X[11]-Y[11],J[12]=X[12]-Y[12],J[13]=X[13]-Y[13],J[14]=X[14]-Y[14],J[15]=X[15]-Y[15],J}function _Z0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J[4]=X[4]*Y,J[5]=X[5]*Y,J[6]=X[6]*Y,J[7]=X[7]*Y,J[8]=X[8]*Y,J[9]=X[9]*Y,J[10]=X[10]*Y,J[11]=X[11]*Y,J[12]=X[12]*Y,J[13]=X[13]*Y,J[14]=X[14]*Y,J[15]=X[15]*Y,J}function EZ0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J[3]=X[3]+Y[3]*Z,J[4]=X[4]+Y[4]*Z,J[5]=X[5]+Y[5]*Z,J[6]=X[6]+Y[6]*Z,J[7]=X[7]+Y[7]*Z,J[8]=X[8]+Y[8]*Z,J[9]=X[9]+Y[9]*Z,J[10]=X[10]+Y[10]*Z,J[11]=X[11]+Y[11]*Z,J[12]=X[12]+Y[12]*Z,J[13]=X[13]+Y[13]*Z,J[14]=X[14]+Y[14]*Z,J[15]=X[15]+Y[15]*Z,J}function CZ0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]&&J[4]===X[4]&&J[5]===X[5]&&J[6]===X[6]&&J[7]===X[7]&&J[8]===X[8]&&J[9]===X[9]&&J[10]===X[10]&&J[11]===X[11]&&J[12]===X[12]&&J[13]===X[13]&&J[14]===X[14]&&J[15]===X[15]}function SZ0(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=J[4],K=J[5],G=J[6],F=J[7],q=J[8],H=J[9],z=J[10],V=J[11],M=J[12],R=J[13],L=J[14],w=J[15],P=X[0],N=X[1],v=X[2],j=X[3],O=X[4],D=X[5],_=X[6],C=X[7],S=X[8],I=X[9],f=X[10],y=X[11],h=X[12],g=X[13],J0=X[14],p0=X[15];return Math.abs(Y-P)<=l*Math.max(1,Math.abs(Y),Math.abs(P))&&Math.abs(Z-N)<=l*Math.max(1,Math.abs(Z),Math.abs(N))&&Math.abs(W-v)<=l*Math.max(1,Math.abs(W),Math.abs(v))&&Math.abs($-j)<=l*Math.max(1,Math.abs($),Math.abs(j))&&Math.abs(Q-O)<=l*Math.max(1,Math.abs(Q),Math.abs(O))&&Math.abs(K-D)<=l*Math.max(1,Math.abs(K),Math.abs(D))&&Math.abs(G-_)<=l*Math.max(1,Math.abs(G),Math.abs(_))&&Math.abs(F-C)<=l*Math.max(1,Math.abs(F),Math.abs(C))&&Math.abs(q-S)<=l*Math.max(1,Math.abs(q),Math.abs(S))&&Math.abs(H-I)<=l*Math.max(1,Math.abs(H),Math.abs(I))&&Math.abs(z-f)<=l*Math.max(1,Math.abs(z),Math.abs(f))&&Math.abs(V-y)<=l*Math.max(1,Math.abs(V),Math.abs(y))&&Math.abs(M-h)<=l*Math.max(1,Math.abs(M),Math.abs(h))&&Math.abs(R-g)<=l*Math.max(1,Math.abs(R),Math.abs(g))&&Math.abs(L-J0)<=l*Math.max(1,Math.abs(L),Math.abs(J0))&&Math.abs(w-p0)<=l*Math.max(1,Math.abs(w),Math.abs(p0))}var IZ0=bC,hZ0=cC;var N0={};k6(N0,{str:()=>EW0,squaredLength:()=>MS,sqrLen:()=>yW0,sqlerp:()=>lW0,slerp:()=>H$,setAxisAngle:()=>GS,setAxes:()=>uW0,set:()=>hW0,scale:()=>LS,rotationTo:()=>mW0,rotateZ:()=>vW0,rotateY:()=>NW0,rotateX:()=>PW0,random:()=>kW0,pow:()=>jW0,normalize:()=>kH,multiply:()=>FS,mul:()=>bW0,ln:()=>HS,lerp:()=>pW0,length:()=>VS,len:()=>AW0,invert:()=>TW0,identity:()=>wW0,getAxisAngle:()=>OW0,getAngle:()=>xW0,fromValues:()=>SW0,fromMat3:()=>zS,fromEuler:()=>_W0,exp:()=>qS,exactEquals:()=>gW0,equals:()=>cW0,dot:()=>US,create:()=>jH,copy:()=>IW0,conjugate:()=>DW0,clone:()=>CW0,calculateW:()=>BW0,add:()=>fW0});var W0={};k6(W0,{zero:()=>$W0,transformQuat:()=>JW0,transformMat4:()=>tZ0,transformMat3:()=>eZ0,subtract:()=>lC,sub:()=>FW0,str:()=>QW0,squaredLength:()=>aC,squaredDistance:()=>nC,sqrLen:()=>UW0,sqrDist:()=>LW0,set:()=>pZ0,scaleAndAdd:()=>dZ0,scale:()=>uZ0,round:()=>lZ0,rotateZ:()=>ZW0,rotateY:()=>YW0,rotateX:()=>XW0,random:()=>rZ0,normalize:()=>vH,negate:()=>iZ0,multiply:()=>uC,mul:()=>qW0,min:()=>cZ0,max:()=>mZ0,lerp:()=>aZ0,length:()=>mC,len:()=>BH,inverse:()=>nZ0,hermite:()=>sZ0,fromValues:()=>F$,forEach:()=>VW0,floor:()=>gZ0,exactEquals:()=>KW0,equals:()=>GW0,dot:()=>q$,divide:()=>dC,div:()=>HW0,distance:()=>iC,dist:()=>zW0,cross:()=>bJ,create:()=>G$,copy:()=>bZ0,clone:()=>fZ0,ceil:()=>yZ0,bezier:()=>oZ0,angle:()=>WW0,add:()=>AZ0});function G$(){var J=new Q0(3);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function fZ0(J){var X=new Q0(3);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X}function mC(J){var X=J[0],Y=J[1],Z=J[2];return Math.hypot(X,Y,Z)}function F$(J,X,Y){var Z=new Q0(3);return Z[0]=J,Z[1]=X,Z[2]=Y,Z}function bZ0(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J}function pZ0(J,X,Y,Z){return J[0]=X,J[1]=Y,J[2]=Z,J}function AZ0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J}function lC(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J[2]=X[2]-Y[2],J}function uC(J,X,Y){return J[0]=X[0]*Y[0],J[1]=X[1]*Y[1],J[2]=X[2]*Y[2],J}function dC(J,X,Y){return J[0]=X[0]/Y[0],J[1]=X[1]/Y[1],J[2]=X[2]/Y[2],J}function yZ0(J,X){return J[0]=Math.ceil(X[0]),J[1]=Math.ceil(X[1]),J[2]=Math.ceil(X[2]),J}function gZ0(J,X){return J[0]=Math.floor(X[0]),J[1]=Math.floor(X[1]),J[2]=Math.floor(X[2]),J}function cZ0(J,X,Y){return J[0]=Math.min(X[0],Y[0]),J[1]=Math.min(X[1],Y[1]),J[2]=Math.min(X[2],Y[2]),J}function mZ0(J,X,Y){return J[0]=Math.max(X[0],Y[0]),J[1]=Math.max(X[1],Y[1]),J[2]=Math.max(X[2],Y[2]),J}function lZ0(J,X){return J[0]=Math.round(X[0]),J[1]=Math.round(X[1]),J[2]=Math.round(X[2]),J}function uZ0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J}function dZ0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J[2]=X[2]+Y[2]*Z,J}function iC(J,X){var Y=X[0]-J[0],Z=X[1]-J[1],W=X[2]-J[2];return Math.hypot(Y,Z,W)}function nC(J,X){var Y=X[0]-J[0],Z=X[1]-J[1],W=X[2]-J[2];return Y*Y+Z*Z+W*W}function aC(J){var X=J[0],Y=J[1],Z=J[2];return X*X+Y*Y+Z*Z}function iZ0(J,X){return J[0]=-X[0],J[1]=-X[1],J[2]=-X[2],J}function nZ0(J,X){return J[0]=1/X[0],J[1]=1/X[1],J[2]=1/X[2],J}function vH(J,X){var Y=X[0],Z=X[1],W=X[2],$=Y*Y+Z*Z+W*W;if($>0)$=1/Math.sqrt($);return J[0]=X[0]*$,J[1]=X[1]*$,J[2]=X[2]*$,J}function q$(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]}function bJ(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[0],K=Y[1],G=Y[2];return J[0]=W*G-$*K,J[1]=$*Q-Z*G,J[2]=Z*K-W*Q,J}function aZ0(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J[2]=Q+Z*(Y[2]-Q),J}function sZ0(J,X,Y,Z,W,$){var Q=$*$,K=Q*(2*$-3)+1,G=Q*($-2)+$,F=Q*($-1),q=Q*(3-2*$);return J[0]=X[0]*K+Y[0]*G+Z[0]*F+W[0]*q,J[1]=X[1]*K+Y[1]*G+Z[1]*F+W[1]*q,J[2]=X[2]*K+Y[2]*G+Z[2]*F+W[2]*q,J}function oZ0(J,X,Y,Z,W,$){var Q=1-$,K=Q*Q,G=$*$,F=K*Q,q=3*$*K,H=3*G*Q,z=G*$;return J[0]=X[0]*F+Y[0]*q+Z[0]*H+W[0]*z,J[1]=X[1]*F+Y[1]*q+Z[1]*H+W[1]*z,J[2]=X[2]*F+Y[2]*q+Z[2]*H+W[2]*z,J}function rZ0(J,X){X=X||1;var Y=d6()*2*Math.PI,Z=d6()*2-1,W=Math.sqrt(1-Z*Z)*X;return J[0]=Math.cos(Y)*W,J[1]=Math.sin(Y)*W,J[2]=Z*X,J}function tZ0(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=Y[3]*Z+Y[7]*W+Y[11]*$+Y[15];return Q=Q||1,J[0]=(Y[0]*Z+Y[4]*W+Y[8]*$+Y[12])/Q,J[1]=(Y[1]*Z+Y[5]*W+Y[9]*$+Y[13])/Q,J[2]=(Y[2]*Z+Y[6]*W+Y[10]*$+Y[14])/Q,J}function eZ0(J,X,Y){var Z=X[0],W=X[1],$=X[2];return J[0]=Z*Y[0]+W*Y[3]+$*Y[6],J[1]=Z*Y[1]+W*Y[4]+$*Y[7],J[2]=Z*Y[2]+W*Y[5]+$*Y[8],J}function JW0(J,X,Y){var Z=Y[0],W=Y[1],$=Y[2],Q=Y[3],K=X[0],G=X[1],F=X[2],q=W*F-$*G,H=$*K-Z*F,z=Z*G-W*K,V=W*z-$*H,M=$*q-Z*z,R=Z*H-W*q,L=Q*2;return q*=L,H*=L,z*=L,V*=2,M*=2,R*=2,J[0]=K+q+V,J[1]=G+H+M,J[2]=F+z+R,J}function XW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[0],$[1]=W[1]*Math.cos(Z)-W[2]*Math.sin(Z),$[2]=W[1]*Math.sin(Z)+W[2]*Math.cos(Z),J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function YW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[2]*Math.sin(Z)+W[0]*Math.cos(Z),$[1]=W[1],$[2]=W[2]*Math.cos(Z)-W[0]*Math.sin(Z),J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function ZW0(J,X,Y,Z){var W=[],$=[];return W[0]=X[0]-Y[0],W[1]=X[1]-Y[1],W[2]=X[2]-Y[2],$[0]=W[0]*Math.cos(Z)-W[1]*Math.sin(Z),$[1]=W[0]*Math.sin(Z)+W[1]*Math.cos(Z),$[2]=W[2],J[0]=$[0]+Y[0],J[1]=$[1]+Y[1],J[2]=$[2]+Y[2],J}function WW0(J,X){var Y=J[0],Z=J[1],W=J[2],$=X[0],Q=X[1],K=X[2],G=Math.sqrt(Y*Y+Z*Z+W*W),F=Math.sqrt($*$+Q*Q+K*K),q=G*F,H=q&&q$(J,X)/q;return Math.acos(Math.min(Math.max(H,-1),1))}function $W0(J){return J[0]=0,J[1]=0,J[2]=0,J}function QW0(J){return"vec3("+J[0]+", "+J[1]+", "+J[2]+")"}function KW0(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]}function GW0(J,X){var Y=J[0],Z=J[1],W=J[2],$=X[0],Q=X[1],K=X[2];return Math.abs(Y-$)<=l*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(Z-Q)<=l*Math.max(1,Math.abs(Z),Math.abs(Q))&&Math.abs(W-K)<=l*Math.max(1,Math.abs(W),Math.abs(K))}var FW0=lC,qW0=uC,HW0=dC,zW0=iC,LW0=nC,BH=mC,UW0=aC,VW0=function(){var J=G$();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=3;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2];return X}}();function MW0(){var J=new Q0(4);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}function sC(J){var X=new Q0(4);return X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=J[3],X}function oC(J,X,Y,Z){var W=new Q0(4);return W[0]=J,W[1]=X,W[2]=Y,W[3]=Z,W}function rC(J,X){return J[0]=X[0],J[1]=X[1],J[2]=X[2],J[3]=X[3],J}function tC(J,X,Y,Z,W){return J[0]=X,J[1]=Y,J[2]=Z,J[3]=W,J}function eC(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J[2]=X[2]+Y[2],J[3]=X[3]+Y[3],J}function JS(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J[2]=X[2]*Y,J[3]=X[3]*Y,J}function XS(J){var X=J[0],Y=J[1],Z=J[2],W=J[3];return Math.hypot(X,Y,Z,W)}function YS(J){var X=J[0],Y=J[1],Z=J[2],W=J[3];return X*X+Y*Y+Z*Z+W*W}function ZS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*Y+Z*Z+W*W+$*$;if(Q>0)Q=1/Math.sqrt(Q);return J[0]=Y*Q,J[1]=Z*Q,J[2]=W*Q,J[3]=$*Q,J}function WS(J,X){return J[0]*X[0]+J[1]*X[1]+J[2]*X[2]+J[3]*X[3]}function $S(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J[2]=Q+Z*(Y[2]-Q),J[3]=K+Z*(Y[3]-K),J}function QS(J,X){return J[0]===X[0]&&J[1]===X[1]&&J[2]===X[2]&&J[3]===X[3]}function KS(J,X){var Y=J[0],Z=J[1],W=J[2],$=J[3],Q=X[0],K=X[1],G=X[2],F=X[3];return Math.abs(Y-Q)<=l*Math.max(1,Math.abs(Y),Math.abs(Q))&&Math.abs(Z-K)<=l*Math.max(1,Math.abs(Z),Math.abs(K))&&Math.abs(W-G)<=l*Math.max(1,Math.abs(W),Math.abs(G))&&Math.abs($-F)<=l*Math.max(1,Math.abs($),Math.abs(F))}var U_0=function(){var J=MW0();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=4;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],J[2]=X[K+2],J[3]=X[K+3],$(J,J,Q),X[K]=J[0],X[K+1]=J[1],X[K+2]=J[2],X[K+3]=J[3];return X}}();function jH(){var J=new Q0(4);if(Q0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J[3]=1,J}function wW0(J){return J[0]=0,J[1]=0,J[2]=0,J[3]=1,J}function GS(J,X,Y){Y=Y*0.5;var Z=Math.sin(Y);return J[0]=Z*X[0],J[1]=Z*X[1],J[2]=Z*X[2],J[3]=Math.cos(Y),J}function OW0(J,X){var Y=Math.acos(X[3])*2,Z=Math.sin(Y/2);if(Z>l)J[0]=X[0]/Z,J[1]=X[1]/Z,J[2]=X[2]/Z;else J[0]=1,J[1]=0,J[2]=0;return Y}function xW0(J,X){var Y=US(J,X);return Math.acos(2*Y*Y-1)}function FS(J,X,Y){var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Y[0],G=Y[1],F=Y[2],q=Y[3];return J[0]=Z*q+Q*K+W*F-$*G,J[1]=W*q+Q*G+$*K-Z*F,J[2]=$*q+Q*F+Z*G-W*K,J[3]=Q*q-Z*K-W*G-$*F,J}function PW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+Q*K,J[1]=W*G+$*K,J[2]=$*G-W*K,J[3]=Q*G-Z*K,J}function NW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G-$*K,J[1]=W*G+Q*K,J[2]=$*G+Z*K,J[3]=Q*G-W*K,J}function vW0(J,X,Y){Y*=0.5;var Z=X[0],W=X[1],$=X[2],Q=X[3],K=Math.sin(Y),G=Math.cos(Y);return J[0]=Z*G+W*K,J[1]=W*G-Z*K,J[2]=$*G+Q*K,J[3]=Q*G-$*K,J}function BW0(J,X){var Y=X[0],Z=X[1],W=X[2];return J[0]=Y,J[1]=Z,J[2]=W,J[3]=Math.sqrt(Math.abs(1-Y*Y-Z*Z-W*W)),J}function qS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Math.sqrt(Y*Y+Z*Z+W*W),K=Math.exp($),G=Q>0?K*Math.sin(Q)/Q:0;return J[0]=Y*G,J[1]=Z*G,J[2]=W*G,J[3]=K*Math.cos(Q),J}function HS(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Math.sqrt(Y*Y+Z*Z+W*W),K=Q>0?Math.atan2(Q,$)/Q:0;return J[0]=Y*K,J[1]=Z*K,J[2]=W*K,J[3]=0.5*Math.log(Y*Y+Z*Z+W*W+$*$),J}function jW0(J,X,Y){return HS(J,X),LS(J,J,Y),qS(J,J),J}function H$(J,X,Y,Z){var W=X[0],$=X[1],Q=X[2],K=X[3],G=Y[0],F=Y[1],q=Y[2],H=Y[3],z,V,M,R,L;if(V=W*G+$*F+Q*q+K*H,V<0)V=-V,G=-G,F=-F,q=-q,H=-H;if(1-V>l)z=Math.acos(V),M=Math.sin(z),R=Math.sin((1-Z)*z)/M,L=Math.sin(Z*z)/M;else R=1-Z,L=Z;return J[0]=R*W+L*G,J[1]=R*$+L*F,J[2]=R*Q+L*q,J[3]=R*K+L*H,J}function kW0(J){var X=d6(),Y=d6(),Z=d6(),W=Math.sqrt(1-X),$=Math.sqrt(X);return J[0]=W*Math.sin(2*Math.PI*Y),J[1]=W*Math.cos(2*Math.PI*Y),J[2]=$*Math.sin(2*Math.PI*Z),J[3]=$*Math.cos(2*Math.PI*Z),J}function TW0(J,X){var Y=X[0],Z=X[1],W=X[2],$=X[3],Q=Y*Y+Z*Z+W*W+$*$,K=Q?1/Q:0;return J[0]=-Y*K,J[1]=-Z*K,J[2]=-W*K,J[3]=$*K,J}function DW0(J,X){return J[0]=-X[0],J[1]=-X[1],J[2]=-X[2],J[3]=X[3],J}function zS(J,X){var Y=X[0]+X[4]+X[8],Z;if(Y>0)Z=Math.sqrt(Y+1),J[3]=0.5*Z,Z=0.5/Z,J[0]=(X[5]-X[7])*Z,J[1]=(X[6]-X[2])*Z,J[2]=(X[1]-X[3])*Z;else{var W=0;if(X[4]>X[0])W=1;if(X[8]>X[W*3+W])W=2;var $=(W+1)%3,Q=(W+2)%3;Z=Math.sqrt(X[W*3+W]-X[$*3+$]-X[Q*3+Q]+1),J[W]=0.5*Z,Z=0.5/Z,J[3]=(X[$*3+Q]-X[Q*3+$])*Z,J[$]=(X[$*3+W]+X[W*3+$])*Z,J[Q]=(X[Q*3+W]+X[W*3+Q])*Z}return J}function _W0(J,X,Y,Z){var W=0.5*Math.PI/180;X*=W,Y*=W,Z*=W;var $=Math.sin(X),Q=Math.cos(X),K=Math.sin(Y),G=Math.cos(Y),F=Math.sin(Z),q=Math.cos(Z);return J[0]=$*G*q-Q*K*F,J[1]=Q*K*q+$*G*F,J[2]=Q*G*F-$*K*q,J[3]=Q*G*q+$*K*F,J}function EW0(J){return"quat("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}var CW0=sC,SW0=oC,IW0=rC,hW0=tC,fW0=eC,bW0=FS,LS=JS,US=WS,pW0=$S,VS=XS,AW0=VS,MS=YS,yW0=MS,kH=ZS,gW0=QS,cW0=KS,mW0=function(){var J=G$(),X=F$(1,0,0),Y=F$(0,1,0);return function(Z,W,$){var Q=q$(W,$);if(Q<-0.999999){if(bJ(J,X,W),BH(J)<0.000001)bJ(J,Y,W);return vH(J,J),GS(Z,J,Math.PI),Z}else if(Q>0.999999)return Z[0]=0,Z[1]=0,Z[2]=0,Z[3]=1,Z;else return bJ(J,W,$),Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=1+Q,kH(Z,Z)}}(),lW0=function(){var J=jH(),X=jH();return function(Y,Z,W,$,Q,K){return H$(J,Z,Q,K),H$(X,W,$,K),H$(Y,J,X,2*K*(1-K)),Y}}(),uW0=function(){var J=NH();return function(X,Y,Z,W){return J[0]=Z[0],J[3]=Z[1],J[6]=Z[2],J[1]=W[0],J[4]=W[1],J[7]=W[2],J[2]=-Y[0],J[5]=-Y[1],J[8]=-Y[2],kH(X,zS(X,J))}}();var q0={};k6(q0,{zero:()=>M$0,transformMat4:()=>L$0,transformMat3:()=>z$0,transformMat2d:()=>H$0,transformMat2:()=>q$0,subtract:()=>wS,sub:()=>P$0,str:()=>R$0,squaredLength:()=>BS,squaredDistance:()=>NS,sqrLen:()=>k$0,sqrDist:()=>j$0,set:()=>aW0,scaleAndAdd:()=>Y$0,scale:()=>X$0,round:()=>J$0,rotate:()=>U$0,random:()=>F$0,normalize:()=>$$0,negate:()=>Z$0,multiply:()=>OS,mul:()=>N$0,min:()=>tW0,max:()=>eW0,lerp:()=>G$0,length:()=>vS,len:()=>x$0,inverse:()=>W$0,fromValues:()=>iW0,forEach:()=>T$0,floor:()=>rW0,exactEquals:()=>w$0,equals:()=>O$0,dot:()=>Q$0,divide:()=>xS,div:()=>v$0,distance:()=>PS,dist:()=>B$0,cross:()=>K$0,create:()=>RS,copy:()=>nW0,clone:()=>dW0,ceil:()=>oW0,angle:()=>V$0,add:()=>sW0});function RS(){var J=new Q0(2);if(Q0!=Float32Array)J[0]=0,J[1]=0;return J}function dW0(J){var X=new Q0(2);return X[0]=J[0],X[1]=J[1],X}function iW0(J,X){var Y=new Q0(2);return Y[0]=J,Y[1]=X,Y}function nW0(J,X){return J[0]=X[0],J[1]=X[1],J}function aW0(J,X,Y){return J[0]=X,J[1]=Y,J}function sW0(J,X,Y){return J[0]=X[0]+Y[0],J[1]=X[1]+Y[1],J}function wS(J,X,Y){return J[0]=X[0]-Y[0],J[1]=X[1]-Y[1],J}function OS(J,X,Y){return J[0]=X[0]*Y[0],J[1]=X[1]*Y[1],J}function xS(J,X,Y){return J[0]=X[0]/Y[0],J[1]=X[1]/Y[1],J}function oW0(J,X){return J[0]=Math.ceil(X[0]),J[1]=Math.ceil(X[1]),J}function rW0(J,X){return J[0]=Math.floor(X[0]),J[1]=Math.floor(X[1]),J}function tW0(J,X,Y){return J[0]=Math.min(X[0],Y[0]),J[1]=Math.min(X[1],Y[1]),J}function eW0(J,X,Y){return J[0]=Math.max(X[0],Y[0]),J[1]=Math.max(X[1],Y[1]),J}function J$0(J,X){return J[0]=Math.round(X[0]),J[1]=Math.round(X[1]),J}function X$0(J,X,Y){return J[0]=X[0]*Y,J[1]=X[1]*Y,J}function Y$0(J,X,Y,Z){return J[0]=X[0]+Y[0]*Z,J[1]=X[1]+Y[1]*Z,J}function PS(J,X){var Y=X[0]-J[0],Z=X[1]-J[1];return Math.hypot(Y,Z)}function NS(J,X){var Y=X[0]-J[0],Z=X[1]-J[1];return Y*Y+Z*Z}function vS(J){var X=J[0],Y=J[1];return Math.hypot(X,Y)}function BS(J){var X=J[0],Y=J[1];return X*X+Y*Y}function Z$0(J,X){return J[0]=-X[0],J[1]=-X[1],J}function W$0(J,X){return J[0]=1/X[0],J[1]=1/X[1],J}function $$0(J,X){var Y=X[0],Z=X[1],W=Y*Y+Z*Z;if(W>0)W=1/Math.sqrt(W);return J[0]=X[0]*W,J[1]=X[1]*W,J}function Q$0(J,X){return J[0]*X[0]+J[1]*X[1]}function K$0(J,X,Y){var Z=X[0]*Y[1]-X[1]*Y[0];return J[0]=J[1]=0,J[2]=Z,J}function G$0(J,X,Y,Z){var W=X[0],$=X[1];return J[0]=W+Z*(Y[0]-W),J[1]=$+Z*(Y[1]-$),J}function F$0(J,X){X=X||1;var Y=d6()*2*Math.PI;return J[0]=Math.cos(Y)*X,J[1]=Math.sin(Y)*X,J}function q$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[2]*W,J[1]=Y[1]*Z+Y[3]*W,J}function H$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[2]*W+Y[4],J[1]=Y[1]*Z+Y[3]*W+Y[5],J}function z$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[3]*W+Y[6],J[1]=Y[1]*Z+Y[4]*W+Y[7],J}function L$0(J,X,Y){var Z=X[0],W=X[1];return J[0]=Y[0]*Z+Y[4]*W+Y[12],J[1]=Y[1]*Z+Y[5]*W+Y[13],J}function U$0(J,X,Y,Z){var W=X[0]-Y[0],$=X[1]-Y[1],Q=Math.sin(Z),K=Math.cos(Z);return J[0]=W*K-$*Q+Y[0],J[1]=W*Q+$*K+Y[1],J}function V$0(J,X){var Y=J[0],Z=J[1],W=X[0],$=X[1],Q=Math.sqrt(Y*Y+Z*Z)*Math.sqrt(W*W+$*$),K=Q&&(Y*W+Z*$)/Q;return Math.acos(Math.min(Math.max(K,-1),1))}function M$0(J){return J[0]=0,J[1]=0,J}function R$0(J){return"vec2("+J[0]+", "+J[1]+")"}function w$0(J,X){return J[0]===X[0]&&J[1]===X[1]}function O$0(J,X){var Y=J[0],Z=J[1],W=X[0],$=X[1];return Math.abs(Y-W)<=l*Math.max(1,Math.abs(Y),Math.abs(W))&&Math.abs(Z-$)<=l*Math.max(1,Math.abs(Z),Math.abs($))}var x$0=vS,P$0=wS,N$0=OS,v$0=xS,B$0=PS,j$0=NS,k$0=BS,T$0=function(){var J=RS();return function(X,Y,Z,W,$,Q){var K,G;if(!Y)Y=2;if(!Z)Z=0;if(W)G=Math.min(W*Y+Z,X.length);else G=X.length;for(K=Z;K<G;K+=Y)J[0]=X[K],J[1]=X[K+1],$(J,J,Q),X[K]=J[0],X[K+1]=J[1];return X}}();class A9 extends Float32Array{constructor(J,X,Y,Z){super([J,X,Y,Z])}get determinant(){return e0.determinant(this)}get frobeniusNorm(){return e0.frob(this)}static create(){let J=new A9(0,0,0,0);return e0.identity(J),J}static fromRotation(J){let X=A9.create();return e0.fromRotation(X,J),X}static fromScaling(J){let X=A9.create();return e0.fromScaling(X,J),X}add(J){return e0.add(this,this,J),this}adjoint(){return e0.adjoint(this,this),this}clone(){return new A9(this[0],this[1],this[2],this[3])}copy(J){return e0.copy(this,J),this}equals(J){return e0.equals(this,J)}exactEquals(J){return e0.exactEquals(this,J)}identity(){return e0.identity(this),this}invert(){return e0.invert(this,this),this}multiply(J){return e0.mul(this,this,J),this}multiplyScalar(J){return e0.multiplyScalar(this,this,J),this}rotate(J){return e0.rotate(this,this,J),this}subtract(J){return e0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return e0.transpose(this,this),this}}class i6 extends Float32Array{constructor(J,X,Y,Z,W,$,Q,K,G){super([J,X,Y,Z,W,$,Q,K,G])}get determinant(){return h0.determinant(this)}get frobeniusNorm(){return h0.frob(this)}static create(){let J=new i6(0,0,0,0,0,0,0,0,0);return h0.identity(J),J}static fromMatrix4(J){let X=i6.create();return h0.fromMat4(X,J),X}static fromQuaternion(J){let X=i6.create();return h0.fromQuat(X,J),X}static fromRotation(J){let X=i6.create();return h0.fromRotation(X,J),X}static fromScaling(J){let X=i6.create();return h0.fromScaling(X,J),X}static fromTranslation(J){let X=i6.create();return h0.fromTranslation(X,J),X}add(J){return h0.add(this,this,J),this}adjoint(){return h0.adjoint(this,this),this}clone(){return new i6(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return h0.copy(this,J),this}equals(J){return h0.equals(this,J)}exactEquals(J){return h0.exactEquals(this,J)}identity(){return h0.identity(this),this}invert(){return h0.invert(this,this),this}multiply(J){return h0.mul(this,this,J),this}multiplyScalar(J){return h0.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,X){return h0.projection(this,J,X),this}rotate(J){return h0.rotate(this,this,J),this}subtract(J){return h0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]},${this[2]}][${this[3]},${this[4]},${this[5]}][${this[6]},${this[7]},${this[8]}]`}transpose(){return h0.transpose(this,this),this}}class E8 extends Float32Array{constructor(J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R){super([J,X,Y,Z,W,$,Q,K,G,F,q,H,z,V,M,R])}get determinant(){return Y0.determinant(this)}get frobeniusNorm(){return Y0.frob(this)}static create(){let J=new E8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return Y0.identity(J),J}static fromQuaternion(J){let X=E8.create();return Y0.fromQuat(X,J),X}static fromRotation(J,X){let Y=E8.create();return Y0.fromRotation(Y,J,X),Y}static fromRotationTranslation(J,X){let Y=E8.create();return Y0.fromRotationTranslation(Y,J,X),Y}static fromRotationTranslationScale(J,X,Y){let Z=E8.create();return Y0.fromRotationTranslationScale(Z,J,X,Y),Z}static fromRotationTranslationScaleOrigin(J,X,Y,Z){let W=E8.create();return Y0.fromRotationTranslationScaleOrigin(W,J,X,Y,Z),W}static fromScaling(J){let X=E8.create();return Y0.fromScaling(X,J),X}static fromTranslation(J){let X=E8.create();return Y0.fromTranslation(X,J),X}static fromXRotation(J){let X=E8.create();return Y0.fromXRotation(X,J),X}static fromYRotation(J){let X=E8.create();return Y0.fromYRotation(X,J),X}static fromZRotation(J){let X=E8.create();return Y0.fromZRotation(X,J),X}add(J){return Y0.add(this,this,J),this}adjoint(){return Y0.adjoint(this,this),this}clone(){return new E8(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8],this[9],this[10],this[11],this[12],this[13],this[14],this[15])}copy(J){return Y0.copy(this,J),this}equals(J){return Y0.equals(this,J)}exactEquals(J){return Y0.exactEquals(this,J)}frustrum(J,X,Y,Z,W,$){return Y0.frustum(this,J,X,Y,Z,W,$),this}identity(){return Y0.identity(this),this}invert(){return Y0.invert(this,this),this}lookAt(J,X,Y){return Y0.lookAt(this,J,X,Y),this}multiply(J){return Y0.mul(this,this,J),this}multiplyScalar(J){return Y0.multiplyScalar(this,this,J),this}orthographic(J,X,Y,Z,W,$){return Y0.ortho(this,J,X,Y,Z,W,$),this}perspective(J,X,Y,Z){return Y0.perspective(this,J,X,Y,Z),this}rotate(J,X){return Y0.rotate(this,this,J,X),this}rotateX(J){return Y0.rotateX(this,this,J),this}rotateY(J){return Y0.rotateY(this,this,J),this}rotateZ(J){return Y0.rotateZ(this,this,J),this}scale(J){return Y0.scale(this,this,J),this}subtract(J){return Y0.sub(this,this,J),this}targetTo(J,X,Y){return Y0.targetTo(this,J,X,Y),this}toString(){return`[${this[0]},${this[1]},${this[2]},${this[3]}][${this[4]},${this[5]},${this[6]},${this[7]}][${this[8]},${this[9]},${this[10]},${this[11]}][${this[12]},${this[13]},${this[14]},${this[15]}]`}translate(J){return Y0.translate(this,this,J),this}transpose(){return Y0.transpose(this,this),this}}class J4 extends Float32Array{constructor(J,X,Y,Z){super([J,X,Y,Z])}get length(){return N0.length(this)}get squaredLength(){return N0.squaredLength(this)}get magnitude(){return N0.length(this)}get squaredMagnitude(){return N0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}get w(){return this[3]}set w(J){this[3]=J}static fromEuler(J,X,Y){let Z=N0.fromEuler(new Float32Array(4),J,X,Y);return new J4(Z[0],Z[1],Z[2],Z[3])}static fromQuaternionLike(J){return new J4(J.x,J.y,J.z,J.w)}clone(){return new J4(this.x,this.y,this.z,this.w)}conjugate(){return N0.conjugate(this,this),this}copy(J){return N0.copy(this,J),this}dot(J){return N0.dot(this,J)}exponential(){return N0.exp(this,this),this}equals(J){return N0.equals(this,J)}exactEquals(J){return N0.exactEquals(this,J)}getAngle(J){return N0.getAngle(this,J)}identity(){return N0.identity(this),this}invert(){return N0.invert(this,this),this}lerp(J,X){return N0.lerp(this,this,J,X),this}logarithm(){return N0.ln(this,this),this}multiply(J){return N0.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return N0.normalize(this,this),this}power(J){return N0.pow(this,this,J),this}randomize(){return N0.random(this),this}rotateX(J){return N0.rotateX(this,this,J),this}rotateY(J){return N0.rotateY(this,this,J),this}rotateZ(J){return N0.rotateZ(this,this,J),this}scale(J){return N0.scale(this,this,J),this}setAxisAngle(J,X){return N0.setAxisAngle(this,J,X),this}slerp(J,X){return N0.slerp(this,this,J,X),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}class pJ extends Float32Array{constructor(J,X){super([J,X])}get length(){return q0.length(this)}get squaredLength(){return q0.squaredLength(this)}get magnitude(){return q0.length(this)}get squaredMagnitude(){return q0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}static create(){return new pJ(0,0)}add(J){return q0.add(this,this,J),this}angle(J){return q0.angle(this,J)}ceil(){return q0.ceil(this,this),this}clone(){return new pJ(this.x,this.y)}copy(J){return q0.copy(this,J),this}distance(J){return q0.distance(this,J)}divide(J){return q0.divide(this,this,J),this}dot(J){return q0.dot(this,J)}equals(J){return q0.equals(this,J)}exactEquals(J){return q0.exactEquals(this,J)}floor(){return q0.floor(this,this),this}invert(){return q0.inverse(this,this),this}lerp(J,X){return q0.lerp(this,this,J,X),this}max(J){return q0.max(this,this,J),this}min(J){return q0.min(this,this,J),this}multiply(J){return q0.mul(this,this,J),this}negate(){return q0.negate(this,this),this}normalize(){return q0.normalize(this,this),this}randomize(J){return q0.random(this,J),this}rotate(J,X){return q0.rotate(this,this,J,X),this}round(){return q0.round(this,this),this}scale(J){return q0.scale(this,this,J),this}scaleAndAdd(J,X){return q0.scaleAndAdd(this,this,J,X),this}subtract(J){return q0.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return q0.transformMat2(this,this,J),this}transformMatrix3(J){return q0.transformMat3(this,this,J),this}transformMatrix4(J){return q0.transformMat4(this,this,J),this}zero(){return q0.zero(this),this}}class X4 extends Float32Array{constructor(J,X,Y){super([J,X,Y])}get length(){return W0.length(this)}get squaredLength(){return W0.squaredLength(this)}get magnitude(){return W0.length(this)}get squaredMagnitude(){return W0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}static create(){return new X4(0,0,0)}static fromVector3Like(J){return new X4(J.x,J.y,J.z)}add(J){return W0.add(this,this,J),this}ceil(){return W0.ceil(this,this),this}clone(){return new X4(this.x,this.y,this.z)}copy(J){return W0.copy(this,J),this}cross(J){return W0.cross(this,this,J),this}distance(J){return W0.distance(this,J)}divide(J){return W0.div(this,this,J),this}dot(J){return W0.dot(this,J)}equals(J){return W0.equals(this,J)}exactEquals(J){return W0.exactEquals(this,J)}floor(){return W0.floor(this,this),this}invert(){return W0.inverse(this,this),this}lerp(J,X){return W0.lerp(this,this,J,X),this}max(J){return W0.max(this,this,J),this}min(J){return W0.min(this,this,J),this}multiply(J){return W0.mul(this,this,J),this}negate(){return W0.negate(this,this),this}normalize(){return W0.normalize(this,this),this}randomize(J){return W0.random(this,J),this}rotateX(J,X){return W0.rotateX(this,this,J,X),this}rotateY(J,X){return W0.rotateY(this,this,J,X),this}rotateZ(J,X){return W0.rotateZ(this,this,J,X),this}round(){return W0.round(this,this),this}scale(J){return W0.scale(this,this,J),this}scaleAndAdd(J,X){return W0.scaleAndAdd(this,this,J,X),this}subtract(J){return W0.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return W0.transformMat3(this,this,J),this}transformMatrix4(J){return W0.transformMat4(this,this,J),this}transformQuaternion(J){return W0.transformQuat(this,this,J),this}zero(){return W0.zero(this),this}}var v0=function(J,X,Y,Z){function W($){return $ instanceof Y?$:new Y(function(Q){Q($)})}return new(Y||(Y=Promise))(function($,Q){function K(q){try{F(Z.next(q))}catch(H){Q(H)}}function G(q){try{F(Z.throw(q))}catch(H){Q(H)}}function F(q){q.done?$(q.value):W(q.value).then(K,G)}F((Z=Z.apply(J,X||[])).next())})},P0=function(J,X){var Y={label:0,sent:function(){if($[0]&1)throw $[1];return $[1]},trys:[],ops:[]},Z,W,$,Q=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return Q.next=K(0),Q.throw=K(1),Q.return=K(2),typeof Symbol==="function"&&(Q[Symbol.iterator]=function(){return this}),Q;function K(F){return function(q){return G([F,q])}}function G(F){if(Z)throw new TypeError("Generator is already executing.");while(Q&&(Q=0,F[0]&&(Y=0)),Y)try{if(Z=1,W&&($=F[0]&2?W.return:F[0]?W.throw||(($=W.return)&&$.call(W),0):W.next)&&!($=$.call(W,F[1])).done)return $;if(W=0,$)F=[F[0]&2,$.value];switch(F[0]){case 0:case 1:$=F;break;case 4:return Y.label++,{value:F[1],done:!1};case 5:Y.label++,W=F[1],F=[0];continue;case 7:F=Y.ops.pop(),Y.trys.pop();continue;default:if(($=Y.trys,!($=$.length>0&&$[$.length-1]))&&(F[0]===6||F[0]===2)){Y=0;continue}if(F[0]===3&&(!$||F[1]>$[0]&&F[1]<$[3])){Y.label=F[1];break}if(F[0]===6&&Y.label<$[1]){Y.label=$[1],$=F;break}if($&&Y.label<$[2]){Y.label=$[2],Y.ops.push(F);break}if($[2])Y.ops.pop();Y.trys.pop();continue}F=X.call(J,Y)}catch(q){F=[6,q],W=0}finally{Z=$=0}if(F[0]&5)throw F[1];return{value:F[0]?F[1]:void 0,done:!0}}},c8=function(J,X){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var Z=Y.call(J),W,$=[],Q;try{while((X===void 0||X-- >0)&&!(W=Z.next()).done)$.push(W.value)}catch(K){Q={error:K}}finally{try{if(W&&!W.done&&(Y=Z.return))Y.call(Z)}finally{if(Q)throw Q.error}}return $},$6=function(J,X,Y){if(Y||arguments.length===2){for(var Z=0,W=X.length,$;Z<W;Z++)if($||!(Z in X)){if(!$)$=Array.prototype.slice.call(X,0,Z);$[Z]=X[Z]}}return J.concat($||Array.prototype.slice.call(X))},jS=function(J){var X=typeof Symbol==="function"&&Symbol.iterator,Y=X&&J[X],Z=0;if(Y)return Y.call(J);if(J&&typeof J.length==="number")return{next:function(){if(J&&Z>=J.length)J=void 0;return{value:J&&J[Z++],done:!J}}};throw new TypeError(X?"Object is not iterable.":"Symbol.iterator is not defined.")},P_0=function(){function J(X){if(X===void 0)X=J.minComparator;var Y=this;this.compare=X,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(Z,W){return Y.compare(Z,W).then(function($){return-1*$})}}return J.getChildrenIndexOf=function(X){return[X*2+1,X*2+2]},J.getParentIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:2;return Math.floor((X-Y)/2)},J.getSiblingIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:-1;return X+Y},J.minComparator=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){if(X>Y)return[2,1];else if(X<Y)return[2,-1];else return[2,0]})})},J.maxComparator=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){if(Y>X)return[2,1];else if(Y<X)return[2,-1];else return[2,0]})})},J.minComparatorNumber=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,X-Y]})})},J.maxComparatorNumber=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,Y-X]})})},J.defaultIsEqual=function(X,Y){return v0(this,void 0,void 0,function(){return P0(this,function(Z){return[2,X===Y]})})},J.print=function(X){function Y(q){var H=J.getParentIndexOf(q);return Math.floor(Math.log2(H+1))}function Z(q,H){var z="";for(;H>0;--H)z+=q;return z}var W=0,$=[],Q=Y(X.length-1)+2,K=0;while(W<X.length){var G=Y(W)+1;if(W===0)G=0;var F=String(X.get(W));if(F.length>K)K=F.length;$[G]=$[G]||[],$[G].push(F),W+=1}return $.map(function(q,H){var z=Math.pow(2,Q-H)-1;return Z(" ",Math.floor(z/2)*K)+q.map(function(V){var M=(K-V.length)/2;return Z(" ",Math.ceil(M))+V+Z(" ",Math.floor(M))}).join(Z(" ",z*K))}).join(`
|
386
386
|
`)},J.heapify=function(X,Y){return v0(this,void 0,void 0,function(){var Z;return P0(this,function(W){switch(W.label){case 0:return Z=new J(Y),Z.heapArray=X,[4,Z.init()];case 1:return W.sent(),[2,Z]}})})},J.heappop=function(X,Y){var Z=new J(Y);return Z.heapArray=X,Z.pop()},J.heappush=function(X,Y,Z){return v0(this,void 0,void 0,function(){var W;return P0(this,function($){switch($.label){case 0:return W=new J(Z),W.heapArray=X,[4,W.push(Y)];case 1:return $.sent(),[2]}})})},J.heappushpop=function(X,Y,Z){var W=new J(Z);return W.heapArray=X,W.pushpop(Y)},J.heapreplace=function(X,Y,Z){var W=new J(Z);return W.heapArray=X,W.replace(Y)},J.heaptop=function(X,Y,Z){if(Y===void 0)Y=1;var W=new J(Z);return W.heapArray=X,W.top(Y)},J.heapbottom=function(X,Y,Z){if(Y===void 0)Y=1;var W=new J(Z);return W.heapArray=X,W.bottom(Y)},J.nlargest=function(X,Y,Z){return v0(this,void 0,void 0,function(){var W;return P0(this,function($){switch($.label){case 0:return W=new J(Z),W.heapArray=$6([],c8(Y),!1),[4,W.init()];case 1:return $.sent(),[2,W.top(X)]}})})},J.nsmallest=function(X,Y,Z){return v0(this,void 0,void 0,function(){var W;return P0(this,function($){switch($.label){case 0:return W=new J(Z),W.heapArray=$6([],c8(Y),!1),[4,W.init()];case 1:return $.sent(),[2,W.bottom(X)]}})})},J.prototype.add=function(X){return v0(this,void 0,void 0,function(){return P0(this,function(Y){switch(Y.label){case 0:return[4,this._sortNodeUp(this.heapArray.push(X)-1)];case 1:return Y.sent(),this._applyLimit(),[2,!0]}})})},J.prototype.addAll=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W;return P0(this,function($){switch($.label){case 0:Y=this.length,(W=this.heapArray).push.apply(W,$6([],c8(X),!1)),Z=this.length,$.label=1;case 1:if(!(Y<Z))return[3,4];return[4,this._sortNodeUp(Y)];case 2:$.sent(),$.label=3;case 3:return++Y,[3,1];case 4:return this._applyLimit(),[2,!0]}})})},J.prototype.bottom=function(){return v0(this,arguments,void 0,function(X){if(X===void 0)X=1;return P0(this,function(Y){if(this.heapArray.length===0||X<=0)return[2,[]];else if(this.heapArray.length===1)return[2,[this.heapArray[0]]];else if(X>=this.heapArray.length)return[2,$6([],c8(this.heapArray),!1)];else return[2,this._bottomN_push(~~X)]})})},J.prototype.check=function(){return v0(this,void 0,void 0,function(){var X,Y,Z,W,$,Q,K,G,F;return P0(this,function(q){switch(q.label){case 0:X=0,q.label=1;case 1:if(!(X<this.heapArray.length))return[3,10];Y=this.heapArray[X],Z=this.getChildrenOf(X),q.label=2;case 2:q.trys.push([2,7,8,9]),W=(G=void 0,jS(Z)),$=W.next(),q.label=3;case 3:if($.done)return[3,6];return Q=$.value,[4,this.compare(Y,Q)];case 4:if(q.sent()>0)return[2,Y];q.label=5;case 5:return $=W.next(),[3,3];case 6:return[3,9];case 7:return K=q.sent(),G={error:K},[3,9];case 8:try{if($&&!$.done&&(F=W.return))F.call(W)}finally{if(G)throw G.error}return[7];case 9:return++X,[3,1];case 10:return[2]}})})},J.prototype.clear=function(){this.heapArray=[]},J.prototype.clone=function(){var X=new J(this.comparator());return X.heapArray=this.toArray(),X._limit=this._limit,X},J.prototype.comparator=function(){return this.compare},J.prototype.contains=function(X){return v0(this,arguments,void 0,function(Y,Z){var W,$,Q,K,G,F;if(Z===void 0)Z=J.defaultIsEqual;return P0(this,function(q){switch(q.label){case 0:q.trys.push([0,5,6,7]),W=jS(this.heapArray),$=W.next(),q.label=1;case 1:if($.done)return[3,4];return Q=$.value,[4,Z(Q,Y)];case 2:if(q.sent())return[2,!0];q.label=3;case 3:return $=W.next(),[3,1];case 4:return[3,7];case 5:return K=q.sent(),G={error:K},[3,7];case 6:try{if($&&!$.done&&(F=W.return))F.call(W)}finally{if(G)throw G.error}return[7];case 7:return[2,!1]}})})},J.prototype.init=function(X){return v0(this,void 0,void 0,function(){var Y;return P0(this,function(Z){switch(Z.label){case 0:if(X)this.heapArray=$6([],c8(X),!1);Y=Math.floor(this.heapArray.length),Z.label=1;case 1:if(!(Y>=0))return[3,4];return[4,this._sortNodeDown(Y)];case 2:Z.sent(),Z.label=3;case 3:return--Y,[3,1];case 4:return this._applyLimit(),[2]}})})},J.prototype.isEmpty=function(){return this.length===0},J.prototype.leafs=function(){if(this.heapArray.length===0)return[];var X=J.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(X+1)},Object.defineProperty(J.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(J.prototype,"limit",{get:function(){return this._limit},set:function(X){this._limit=~~X,this._applyLimit()},enumerable:!1,configurable:!0}),J.prototype.peek=function(){return this.heapArray[0]},J.prototype.pop=function(){return v0(this,void 0,void 0,function(){var X;return P0(this,function(Y){if(X=this.heapArray.pop(),this.length>0&&X!==void 0)return[2,this.replace(X)];return[2,X]})})},J.prototype.push=function(){var X=[];for(var Y=0;Y<arguments.length;Y++)X[Y]=arguments[Y];return v0(this,void 0,void 0,function(){return P0(this,function(Z){if(X.length<1)return[2,!1];else if(X.length===1)return[2,this.add(X[0])];else return[2,this.addAll(X)]})})},J.prototype.pushpop=function(X){return v0(this,void 0,void 0,function(){var Y;return P0(this,function(Z){switch(Z.label){case 0:return[4,this.compare(this.heapArray[0],X)];case 1:if(!(Z.sent()<0))return[3,3];return Y=c8([this.heapArray[0],X],2),X=Y[0],this.heapArray[0]=Y[1],[4,this._sortNodeDown(0)];case 2:Z.sent(),Z.label=3;case 3:return[2,X]}})})},J.prototype.remove=function(X){return v0(this,arguments,void 0,function(Y,Z){var W,$,Q,K=this;if(Z===void 0)Z=J.defaultIsEqual;return P0(this,function(G){switch(G.label){case 0:if(!this.heapArray.length)return[2,!1];if(Y!==void 0)return[3,2];return[4,this.pop()];case 1:return G.sent(),[2,!0];case 2:W=[0],G.label=3;case 3:if(!W.length)return[3,13];return $=W.shift(),[4,Z(this.heapArray[$],Y)];case 4:if(!G.sent())return[3,11];if($!==0)return[3,6];return[4,this.pop()];case 5:return G.sent(),[3,10];case 6:if($!==this.heapArray.length-1)return[3,7];return this.heapArray.pop(),[3,10];case 7:return this.heapArray.splice($,1,this.heapArray.pop()),[4,this._sortNodeUp($)];case 8:return G.sent(),[4,this._sortNodeDown($)];case 9:G.sent(),G.label=10;case 10:return[2,!0];case 11:Q=J.getChildrenIndexOf($).filter(function(F){return F<K.heapArray.length}),W.push.apply(W,$6([],c8(Q),!1)),G.label=12;case 12:return[3,3];case 13:return[2,!1]}})})},J.prototype.replace=function(X){return v0(this,void 0,void 0,function(){var Y;return P0(this,function(Z){switch(Z.label){case 0:return Y=this.heapArray[0],this.heapArray[0]=X,[4,this._sortNodeDown(0)];case 1:return Z.sent(),[2,Y]}})})},J.prototype.size=function(){return this.length},J.prototype.top=function(){return v0(this,arguments,void 0,function(X){if(X===void 0)X=1;return P0(this,function(Y){if(this.heapArray.length===0||X<=0)return[2,[]];else if(this.heapArray.length===1||X===1)return[2,[this.heapArray[0]]];else if(X>=this.heapArray.length)return[2,$6([],c8(this.heapArray),!1)];else return[2,this._topN_push(~~X)]})})},J.prototype.toArray=function(){return $6([],c8(this.heapArray),!1)},J.prototype.toString=function(){return this.heapArray.toString()},J.prototype.get=function(X){return this.heapArray[X]},J.prototype.getChildrenOf=function(X){var Y=this;return J.getChildrenIndexOf(X).map(function(Z){return Y.heapArray[Z]}).filter(function(Z){return Z!==void 0})},J.prototype.getParentOf=function(X){var Y=J.getParentIndexOf(X);return this.heapArray[Y]},J.prototype[Symbol.iterator]=function(){return P0(this,function(X){switch(X.label){case 0:if(!this.length)return[3,2];return[4,this.pop()];case 1:return X.sent(),[3,0];case 2:return[2]}})},J.prototype.iterator=function(){return this},J.prototype._applyLimit=function(){if(this._limit&&this._limit<this.heapArray.length){var X=this.heapArray.length-this._limit;while(X)this.heapArray.pop(),--X}},J.prototype._bottomN_push=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$,K,Q,K;return P0(this,function(G){switch(G.label){case 0:return Y=new J(this.compare),Y.limit=X,Y.heapArray=this.heapArray.slice(-X),[4,Y.init()];case 1:G.sent(),Z=this.heapArray.length-1-X,W=J.getParentIndexOf(Z),$=[];for(K=Z;K>W;--K)$.push(K);Q=this.heapArray,G.label=2;case 2:if(!$.length)return[3,6];return K=$.shift(),[4,this.compare(Q[K],Y.peek())];case 3:if(!(G.sent()>0))return[3,5];return[4,Y.replace(Q[K])];case 4:if(G.sent(),K%2)$.push(J.getParentIndexOf(K));G.label=5;case 5:return[3,2];case 6:return[2,Y.toArray()]}})})},J.prototype._moveNode=function(X,Y){var Z;Z=c8([this.heapArray[Y],this.heapArray[X]],2),this.heapArray[X]=Z[0],this.heapArray[Y]=Z[1]},J.prototype._sortNodeDown=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$,Q,K;return P0(this,function(G){switch(G.label){case 0:Y=this.heapArray.length,G.label=1;case 1:if(Z=2*X+1,W=Z+1,$=X,Q=Z<Y,!Q)return[3,3];return[4,this.compare(this.heapArray[Z],this.heapArray[$])];case 2:Q=G.sent()<0,G.label=3;case 3:if(Q)$=Z;if(K=W<Y,!K)return[3,5];return[4,this.compare(this.heapArray[W],this.heapArray[$])];case 4:K=G.sent()<0,G.label=5;case 5:if(K)$=W;if($===X)return[3,7];this._moveNode(X,$),X=$,G.label=6;case 6:return[3,1];case 7:return[2]}})})},J.prototype._sortNodeUp=function(X){return v0(this,void 0,void 0,function(){var Y;return P0(this,function(Z){switch(Z.label){case 0:if(!(X>0))return[3,2];return Y=J.getParentIndexOf(X),[4,this.compare(this.heapArray[X],this.heapArray[Y])];case 1:if(Z.sent()<0)this._moveNode(X,Y),X=Y;else return[3,2];return[3,0];case 2:return[2]}})})},J.prototype._topN_push=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$;return P0(this,function(Q){switch(Q.label){case 0:Y=new J(this._invertedCompare),Y.limit=X,Z=[0],W=this.heapArray,Q.label=1;case 1:if(!Z.length)return[3,7];if($=Z.shift(),!($<W.length))return[3,6];if(!(Y.length<X))return[3,3];return[4,Y.push(W[$])];case 2:return Q.sent(),Z.push.apply(Z,$6([],c8(J.getChildrenIndexOf($)),!1)),[3,6];case 3:return[4,this.compare(W[$],Y.peek())];case 4:if(!(Q.sent()<0))return[3,6];return[4,Y.replace(W[$])];case 5:Q.sent(),Z.push.apply(Z,$6([],c8(J.getChildrenIndexOf($)),!1)),Q.label=6;case 6:return[3,1];case 7:return[2,Y.toArray()]}})})},J.prototype._topN_fill=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$,Q,Q;return P0(this,function(K){switch(K.label){case 0:return Y=this.heapArray,Z=new J(this._invertedCompare),Z.limit=X,Z.heapArray=Y.slice(0,X),[4,Z.init()];case 1:K.sent(),W=J.getParentIndexOf(X-1)+1,$=[];for(Q=W;Q<X;++Q)$.push.apply($,$6([],c8(J.getChildrenIndexOf(Q).filter(function(G){return G<Y.length})),!1));if((X-1)%2)$.push(X);K.label=2;case 2:if(!$.length)return[3,6];if(Q=$.shift(),!(Q<Y.length))return[3,5];return[4,this.compare(Y[Q],Z.peek())];case 3:if(!(K.sent()<0))return[3,5];return[4,Z.replace(Y[Q])];case 4:K.sent(),$.push.apply($,$6([],c8(J.getChildrenIndexOf(Q)),!1)),K.label=5;case 5:return[3,2];case 6:return[2,Z.toArray()]}})})},J.prototype._topN_heap=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$,Q;return P0(this,function(K){switch(K.label){case 0:Y=this.clone(),Z=[],W=0,K.label=1;case 1:if(!(W<X))return[3,4];return Q=($=Z).push,[4,Y.pop()];case 2:Q.apply($,[K.sent()]),K.label=3;case 3:return++W,[3,1];case 4:return[2,Z]}})})},J.prototype._topIdxOf=function(X){return v0(this,void 0,void 0,function(){var Y,Z,W,$;return P0(this,function(Q){switch(Q.label){case 0:if(!X.length)return[2,-1];Y=0,Z=X[Y],W=1,Q.label=1;case 1:if(!(W<X.length))return[3,4];return[4,this.compare(X[W],Z)];case 2:if($=Q.sent(),$<0)Y=W,Z=X[W];Q.label=3;case 3:return++W,[3,1];case 4:return[2,Y]}})})},J.prototype._topOf=function(){var X=[];for(var Y=0;Y<arguments.length;Y++)X[Y]=arguments[Y];return v0(this,void 0,void 0,function(){var Z;return P0(this,function(W){switch(W.label){case 0:return Z=new J(this.compare),[4,Z.init(X)];case 1:return W.sent(),[2,Z.peek()]}})})},J}(),D$0=function(J,X){var Y={label:0,sent:function(){if($[0]&1)throw $[1];return $[1]},trys:[],ops:[]},Z,W,$,Q=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return Q.next=K(0),Q.throw=K(1),Q.return=K(2),typeof Symbol==="function"&&(Q[Symbol.iterator]=function(){return this}),Q;function K(F){return function(q){return G([F,q])}}function G(F){if(Z)throw new TypeError("Generator is already executing.");while(Q&&(Q=0,F[0]&&(Y=0)),Y)try{if(Z=1,W&&($=F[0]&2?W.return:F[0]?W.throw||(($=W.return)&&$.call(W),0):W.next)&&!($=$.call(W,F[1])).done)return $;if(W=0,$)F=[F[0]&2,$.value];switch(F[0]){case 0:case 1:$=F;break;case 4:return Y.label++,{value:F[1],done:!1};case 5:Y.label++,W=F[1],F=[0];continue;case 7:F=Y.ops.pop(),Y.trys.pop();continue;default:if(($=Y.trys,!($=$.length>0&&$[$.length-1]))&&(F[0]===6||F[0]===2)){Y=0;continue}if(F[0]===3&&(!$||F[1]>$[0]&&F[1]<$[3])){Y.label=F[1];break}if(F[0]===6&&Y.label<$[1]){Y.label=$[1],$=F;break}if($&&Y.label<$[2]){Y.label=$[2],Y.ops.push(F);break}if($[2])Y.ops.pop();Y.trys.pop();continue}F=X.call(J,Y)}catch(q){F=[6,q],W=0}finally{Z=$=0}if(F[0]&5)throw F[1];return{value:F[0]?F[1]:void 0,done:!0}}},L8=function(J,X){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var Z=Y.call(J),W,$=[],Q;try{while((X===void 0||X-- >0)&&!(W=Z.next()).done)$.push(W.value)}catch(K){Q={error:K}}finally{try{if(W&&!W.done&&(Y=Z.return))Y.call(Z)}finally{if(Q)throw Q.error}}return $},C8=function(J,X,Y){if(Y||arguments.length===2){for(var Z=0,W=X.length,$;Z<W;Z++)if($||!(Z in X)){if(!$)$=Array.prototype.slice.call(X,0,Z);$[Z]=X[Z]}}return J.concat($||Array.prototype.slice.call(X))};var kS=function(){function J(X){if(X===void 0)X=J.minComparator;var Y=this;this.compare=X,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this.removeAll=this.clear,this._invertedCompare=function(Z,W){return-1*Y.compare(Z,W)}}return J.getChildrenIndexOf=function(X){return[X*2+1,X*2+2]},J.getParentIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:2;return Math.floor((X-Y)/2)},J.getSiblingIndexOf=function(X){if(X<=0)return-1;var Y=X%2?1:-1;return X+Y},J.minComparator=function(X,Y){if(X>Y)return 1;else if(X<Y)return-1;else return 0},J.maxComparator=function(X,Y){if(Y>X)return 1;else if(Y<X)return-1;else return 0},J.minComparatorNumber=function(X,Y){return X-Y},J.maxComparatorNumber=function(X,Y){return Y-X},J.defaultIsEqual=function(X,Y){return X===Y},J.print=function(X){function Y(q){var H=J.getParentIndexOf(q);return Math.floor(Math.log2(H+1))}function Z(q,H){var z="";for(;H>0;--H)z+=q;return z}var W=0,$=[],Q=Y(X.length-1)+2,K=0;while(W<X.length){var G=Y(W)+1;if(W===0)G=0;var F=String(X.get(W));if(F.length>K)K=F.length;$[G]=$[G]||[],$[G].push(F),W+=1}return $.map(function(q,H){var z=Math.pow(2,Q-H)-1;return Z(" ",Math.floor(z/2)*K)+q.map(function(V){var M=(K-V.length)/2;return Z(" ",Math.ceil(M))+V+Z(" ",Math.floor(M))}).join(Z(" ",z*K))}).join(`
|
387
387
|
`)},J.heapify=function(X,Y){var Z=new J(Y);return Z.heapArray=X,Z.init(),Z},J.heappop=function(X,Y){var Z=new J(Y);return Z.heapArray=X,Z.pop()},J.heappush=function(X,Y,Z){var W=new J(Z);W.heapArray=X,W.push(Y)},J.heappushpop=function(X,Y,Z){var W=new J(Z);return W.heapArray=X,W.pushpop(Y)},J.heapreplace=function(X,Y,Z){var W=new J(Z);return W.heapArray=X,W.replace(Y)},J.heaptop=function(X,Y,Z){if(Y===void 0)Y=1;var W=new J(Z);return W.heapArray=X,W.top(Y)},J.heapbottom=function(X,Y,Z){if(Y===void 0)Y=1;var W=new J(Z);return W.heapArray=X,W.bottom(Y)},J.nlargest=function(X,Y,Z){var W=new J(Z);return W.heapArray=C8([],L8(Y),!1),W.init(),W.top(X)},J.nsmallest=function(X,Y,Z){var W=new J(Z);return W.heapArray=C8([],L8(Y),!1),W.init(),W.bottom(X)},J.prototype.add=function(X){return this._sortNodeUp(this.heapArray.push(X)-1),this._applyLimit(),!0},J.prototype.addAll=function(X){var Y,Z=this.length;(Y=this.heapArray).push.apply(Y,C8([],L8(X),!1));for(var W=this.length;Z<W;++Z)this._sortNodeUp(Z);return this._applyLimit(),!0},J.prototype.bottom=function(X){if(X===void 0)X=1;if(this.heapArray.length===0||X<=0)return[];else if(this.heapArray.length===1)return[this.heapArray[0]];else if(X>=this.heapArray.length)return C8([],L8(this.heapArray),!1);else return this._bottomN_push(~~X)},J.prototype.check=function(){var X=this;return this.heapArray.find(function(Y,Z){return!!X.getChildrenOf(Z).find(function(W){return X.compare(Y,W)>0})})},J.prototype.clear=function(){this.heapArray=[]},J.prototype.clone=function(){var X=new J(this.comparator());return X.heapArray=this.toArray(),X._limit=this._limit,X},J.prototype.comparator=function(){return this.compare},J.prototype.contains=function(X,Y){if(Y===void 0)Y=J.defaultIsEqual;return this.indexOf(X,Y)!==-1},J.prototype.init=function(X){if(X)this.heapArray=C8([],L8(X),!1);for(var Y=Math.floor(this.heapArray.length);Y>=0;--Y)this._sortNodeDown(Y);this._applyLimit()},J.prototype.isEmpty=function(){return this.length===0},J.prototype.indexOf=function(X,Y){if(Y===void 0)Y=J.defaultIsEqual;if(this.heapArray.length===0)return-1;var Z=[],W=0;while(W<this.heapArray.length){var $=this.heapArray[W];if(Y($,X))return W;else if(this.compare($,X)<=0)Z.push.apply(Z,C8([],L8(J.getChildrenIndexOf(W)),!1));W=Z.shift()||this.heapArray.length}return-1},J.prototype.indexOfEvery=function(X,Y){if(Y===void 0)Y=J.defaultIsEqual;if(this.heapArray.length===0)return[];var Z=[],W=[],$=0;while($<this.heapArray.length){var Q=this.heapArray[$];if(Y(Q,X))W.push($),Z.push.apply(Z,C8([],L8(J.getChildrenIndexOf($)),!1));else if(this.compare(Q,X)<=0)Z.push.apply(Z,C8([],L8(J.getChildrenIndexOf($)),!1));$=Z.shift()||this.heapArray.length}return W},J.prototype.leafs=function(){if(this.heapArray.length===0)return[];var X=J.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(X+1)},Object.defineProperty(J.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(J.prototype,"limit",{get:function(){return this._limit},set:function(X){if(X<0||isNaN(X))this._limit=0;else this._limit=~~X;this._applyLimit()},enumerable:!1,configurable:!0}),J.prototype.setLimit=function(X){if(this.limit=X,X<0||isNaN(X))return NaN;else return this._limit},J.prototype.peek=function(){return this.heapArray[0]},J.prototype.pop=function(){var X=this.heapArray.pop();if(this.length>0&&X!==void 0)return this.replace(X);return X},J.prototype.push=function(){var X=[];for(var Y=0;Y<arguments.length;Y++)X[Y]=arguments[Y];if(X.length<1)return!1;else if(X.length===1)return this.add(X[0]);else return this.addAll(X)},J.prototype.pushpop=function(X){var Y;if(this.compare(this.heapArray[0],X)<0)Y=L8([this.heapArray[0],X],2),X=Y[0],this.heapArray[0]=Y[1],this._sortNodeDown(0);return X},J.prototype.remove=function(X,Y){var Z=this;if(Y===void 0)Y=J.defaultIsEqual;if(!this.heapArray.length)return!1;if(X===void 0)return this.pop(),!0;var W=[0];while(W.length){var $=W.shift();if(Y(this.heapArray[$],X)){if($===0)this.pop();else if($===this.heapArray.length-1)this.heapArray.pop();else this.heapArray.splice($,1,this.heapArray.pop()),this._sortNodeUp($),this._sortNodeDown($);return!0}else if(this.compare(this.heapArray[$],X)<=0){var Q=J.getChildrenIndexOf($).filter(function(K){return K<Z.heapArray.length});W.push.apply(W,C8([],L8(Q),!1))}}return!1},J.prototype.replace=function(X){var Y=this.heapArray[0];return this.heapArray[0]=X,this._sortNodeDown(0),Y},J.prototype.size=function(){return this.length},J.prototype.top=function(X){if(X===void 0)X=1;if(this.heapArray.length===0||X<=0)return[];else if(this.heapArray.length===1||X===1)return[this.heapArray[0]];else if(X>=this.heapArray.length)return C8([],L8(this.heapArray),!1);else return this._topN_push(~~X)},J.prototype.toArray=function(){return C8([],L8(this.heapArray),!1)},J.prototype.toString=function(){return this.heapArray.toString()},J.prototype.get=function(X){return this.heapArray[X]},J.prototype.getChildrenOf=function(X){var Y=this;return J.getChildrenIndexOf(X).map(function(Z){return Y.heapArray[Z]}).filter(function(Z){return Z!==void 0})},J.prototype.getParentOf=function(X){var Y=J.getParentIndexOf(X);return this.heapArray[Y]},J.prototype[Symbol.iterator]=function(){return D$0(this,function(X){switch(X.label){case 0:if(!this.length)return[3,2];return[4,this.pop()];case 1:return X.sent(),[3,0];case 2:return[2]}})},J.prototype.iterator=function(){return this.toArray()},J.prototype._applyLimit=function(){if(this._limit>0&&this._limit<this.heapArray.length){var X=this.heapArray.length-this._limit;while(X)this.heapArray.pop(),--X}},J.prototype._bottomN_push=function(X){var Y=new J(this.compare);Y.limit=X,Y.heapArray=this.heapArray.slice(-X),Y.init();var Z=this.heapArray.length-1-X,W=J.getParentIndexOf(Z),$=[];for(var Q=Z;Q>W;--Q)$.push(Q);var K=this.heapArray;while($.length){var Q=$.shift();if(this.compare(K[Q],Y.peek())>0){if(Y.replace(K[Q]),Q%2)$.push(J.getParentIndexOf(Q))}}return Y.toArray()},J.prototype._moveNode=function(X,Y){var Z;Z=L8([this.heapArray[Y],this.heapArray[X]],2),this.heapArray[X]=Z[0],this.heapArray[Y]=Z[1]},J.prototype._sortNodeDown=function(X){var Y=this.heapArray.length;while(!0){var Z=2*X+1,W=Z+1,$=X;if(Z<Y&&this.compare(this.heapArray[Z],this.heapArray[$])<0)$=Z;if(W<Y&&this.compare(this.heapArray[W],this.heapArray[$])<0)$=W;if($===X)break;this._moveNode(X,$),X=$}},J.prototype._sortNodeUp=function(X){while(X>0){var Y=J.getParentIndexOf(X);if(this.compare(this.heapArray[X],this.heapArray[Y])<0)this._moveNode(X,Y),X=Y;else break}},J.prototype._topN_push=function(X){var Y=new J(this._invertedCompare);Y.limit=X;var Z=[0],W=this.heapArray;while(Z.length){var $=Z.shift();if($<W.length){if(Y.length<X)Y.push(W[$]),Z.push.apply(Z,C8([],L8(J.getChildrenIndexOf($)),!1));else if(this.compare(W[$],Y.peek())<0)Y.replace(W[$]),Z.push.apply(Z,C8([],L8(J.getChildrenIndexOf($)),!1))}}return Y.toArray()},J.prototype._topN_fill=function(X){var Y=this.heapArray,Z=new J(this._invertedCompare);Z.limit=X,Z.heapArray=Y.slice(0,X),Z.init();var W=J.getParentIndexOf(X-1)+1,$=[];for(var Q=W;Q<X;++Q)$.push.apply($,C8([],L8(J.getChildrenIndexOf(Q).filter(function(K){return K<Y.length})),!1));if((X-1)%2)$.push(X);while($.length){var Q=$.shift();if(Q<Y.length){if(this.compare(Y[Q],Z.peek())<0)Z.replace(Y[Q]),$.push.apply($,C8([],L8(J.getChildrenIndexOf(Q)),!1))}}return Z.toArray()},J.prototype._topN_heap=function(X){var Y=this.clone(),Z=[];for(var W=0;W<X;++W)Z.push(Y.pop());return Z},J.prototype._topIdxOf=function(X){if(!X.length)return-1;var Y=0,Z=X[Y];for(var W=1;W<X.length;++W){var $=this.compare(X[W],Z);if($<0)Y=W,Z=X[W]}return Y},J.prototype._topOf=function(){var X=[];for(var Y=0;Y<arguments.length;Y++)X[Y]=arguments[Y];var Z=new J(this.compare);return Z.init(X),Z.peek()},J}();class AJ extends a1{_faceSpeed=0;_faceTarget;_jumpHeight=0;_moveSpeed=0;_moveTarget;_moveIgnoreAxes={};_onFace;_onFaceComplete;_onMove;_onMoveComplete;face(J,X,Y){this._faceTarget=J,this._faceSpeed=X,this._onFace=Y?.faceCallback,this._onFaceComplete=Y?.faceCompleteCallback}jump(J){this._jumpHeight=J}move(J,X,Y){this._moveTarget=J,this._moveSpeed=X,this._moveIgnoreAxes=Y?.moveIgnoreAxes??{},this._onMove=Y?.moveCallback,this._onMoveComplete=Y?.moveCompleteCallback}tick(J,X){if(super.tick(J,X),!this._moveTarget&&!this._faceTarget&&!this._jumpHeight)return;let Y=X/1000,Z=J.position;if(J.isDynamic&&this._jumpHeight>0){let W=Math.abs(J.world.simulation.gravity.y),$=Math.sqrt(2*W*this._jumpHeight);J.applyImpulse({x:0,y:$*J.mass,z:0}),this._jumpHeight=0}if(this._moveTarget){let W={x:this._moveIgnoreAxes.x?0:this._moveTarget.x-Z.x,y:this._moveIgnoreAxes.y?0:this._moveTarget.y-Z.y,z:this._moveIgnoreAxes.z?0:this._moveTarget.z-Z.z},$=W.x*W.x+W.y*W.y+W.z*W.z;if($>0.1){let Q=Math.sqrt($),K=this._moveSpeed*Y,F=Math.min(Q,K)/Q,q={x:Z.x+W.x*F,y:Z.y+W.y*F,z:Z.z+W.z*F};if(J.setPosition(q),this._onMove)this._onMove(q,this._moveTarget)}else if(this._moveTarget=void 0,this._onMoveComplete){let Q=this._onMoveComplete;this._onMove=void 0,this._onMoveComplete=void 0,Q(Z)}}if(this._faceTarget){let W={x:this._faceTarget.x-Z.x,z:this._faceTarget.z-Z.z},$=Math.atan2(-W.x,-W.z),Q=J.rotation,K=Math.atan2(2*(Q.w*Q.y),1-2*(Q.y*Q.y)),G=$-K;while(G>Math.PI)G-=2*Math.PI;while(G<-Math.PI)G+=2*Math.PI;if(Math.abs(G)>0.01){let F=this._faceSpeed*Y,q=Math.abs(G)<F?G:Math.sign(G)*F,z=(K+q)/2,V={x:0,y:Math.fround(Math.sin(z)),z:0,w:Math.fround(Math.cos(z))};if(J.setRotation(V),this._onFace)this._onFace(Q,V)}else if(this._faceTarget=void 0,this._onFaceComplete){let F=this._onFaceComplete;this._onFaceComplete=void 0,F(J.rotation)}}}}class TH extends AJ{_debug=!1;_entity;_maxFall=0;_maxJump=0;_maxOpenSetIterations=200;_onPathfindAbort;_onPathfindComplete;_onWaypointMoveComplete;_onWaypointMoveSkipped;_speed=0;_target;_verticalPenalty=0;_waypoints=[];_waypointNextIndex=0;_waypointTimeoutMs=2000;get debug(){return this._debug}get maxFall(){return this._maxFall}get maxJump(){return this._maxJump}get maxOpenSetIterations(){return this._maxOpenSetIterations}get speed(){return this._speed}get target(){return this._target}get verticalPenalty(){return this._verticalPenalty}get waypoints(){return this._waypoints}get waypointNextIndex(){return this._waypointNextIndex}get waypointTimeoutMs(){return this._waypointTimeoutMs}pathfind(J,X,Y){if(this._target=J,this._speed=X,this._debug=Y?.debug??!1,this._maxFall=Y?.maxFall?-Math.abs(Y.maxFall):0,this._maxJump=Y?.maxJump?Math.abs(Y.maxJump):0,this._maxOpenSetIterations=Y?.maxOpenSetIterations??200,this._onPathfindAbort=Y?.pathfindAbortCallback,this._onPathfindComplete=Y?.pathfindCompleteCallback,this._onWaypointMoveComplete=Y?.waypointMoveCompleteCallback,this._onWaypointMoveSkipped=Y?.waypointMoveSkippedCallback,this._verticalPenalty=Y?.verticalPenalty??0,this._waypoints=[],this._waypointNextIndex=0,this._waypointTimeoutMs=Y?.waypointTimeoutMs??2000/X,!this._calculatePath())return!1;return this._moveToNextWaypoint(),!0}attach(J){super.attach(J),this._entity=J}detach(J){super.detach(J),this._entity=void 0}tick(J,X){super.tick(J,X)}_calculatePath(){if(!this._target||!this._entity?.world)return E.error("PathfindingEntityController._calculatePath: No target or world"),!1;let J=this._entity.height,X=this._findGroundedStart();if(!X){if(this._debug)E.warning(`PathfindingEntityController._calculatePath: No valid grounded start found within maxFall distance, path search aborted. Start: ${this._coordinateToKey(this._target)}, Target: ${this._coordinateToKey(this._target)}`);return!1}let Y={x:Math.floor(this._target.x),y:Math.floor(this._target.y),z:Math.floor(this._target.z)},Z=Math.abs(Y.x-X.x),W=Math.abs(Y.y-X.y),$=Math.abs(Y.z-X.z);if(Z<=2&&W<=2&&$<=2&&!this._isNeighborCoordinateBlocked(X,Y,this._entity.height))return this._waypoints=[{x:X.x+0.5,y:X.y+J/2,z:X.z+0.5},{x:Y.x+0.5,y:Y.y+J/2,z:Y.z+0.5}],!0;if(X.x===Y.x&&X.y===Y.y&&X.z===Y.z)return this._waypoints=[{x:X.x+0.5,y:X.y+J/2,z:X.z+0.5}],!0;let K=this._coordinateToKey(X),G=new Map,F=new Map([[K,0]]),q=new Map([[K,this._pathfindingHeuristic(X,Y)]]),H=new Set,z=new kS((N,v)=>{let j=q.get(N[0])??1/0,O=q.get(v[0])??1/0;return j-O});z.push([K,X]);let V=[{x:0,y:0,z:1},{x:1,y:0,z:0},{x:0,y:0,z:-1},{x:-1,y:0,z:0},{x:1,y:0,z:1},{x:1,y:0,z:-1},{x:-1,y:0,z:1},{x:-1,y:0,z:-1}],M=[];for(let N=this._maxJump;N>=this._maxFall;N--){if(N===0)continue;let v=Math.abs(X.y+N-Y.y);M.push({y:N,distanceToTargetY:v})}M.sort((N,v)=>N.distanceToTargetY-v.distanceToTargetY);let R=[...V,...M.flatMap(({y:N})=>V.map((v)=>({...v,y:N})))],L=0,w=Math.abs(Y.x-X.x)+Math.abs(Y.y-X.y)+Math.abs(Y.z-X.z),P=Math.min(this._maxOpenSetIterations,w*20);while(!z.isEmpty()&&L<P){L++;let[N,v]=z.pop();if(v.x===Y.x&&v.y===Y.y&&v.z===Y.z){let D=this._reconstructPath(G,v);if(this._waypoints=D.map((_)=>({x:_.x+0.5,y:_.y+J/2,z:_.z+0.5})),this._debug)console.log(`PathfindingEntityController._calculatePath: Path found after ${L} open set iterations. Start: ${this._coordinateToKey(X)}, Target: ${this._coordinateToKey(this._target)}`);return!0}H.add(N);let j=F.get(N),O=new Map;for(let D of R){let _=`${D.x},${D.z}`,C=D.y<0;if(C&&O.has(_))continue;let S={x:v.x+D.x,y:v.y+D.y,z:v.z+D.z};if(Math.abs(Y.x-S.x)+Math.abs(Y.y-S.y)+Math.abs(Y.z-S.z)>w*1.5)continue;let f=this._coordinateToKey(S);if(H.has(f))continue;let y=this._isNeighborCoordinateBlocked(v,S,this._entity.height);if(C&&y){O.set(_,!0);continue}if(y)continue;let h=Math.abs(D.x),g=Math.abs(D.y),J0=Math.abs(D.z),p0=g===0?0:this._verticalPenalty,a0=(Math.max(h,g,J0)===1&&h+g+J0>1?1.4:1)+p0,Q6=j+a0,n6=F.get(f)??1/0;if(Q6>=n6)continue;G.set(f,v),F.set(f,Q6);let Y4=Q6+this._pathfindingHeuristic(S,Y);q.set(f,Y4),z.push([f,S])}}if(L>=P){if(this._onPathfindAbort?.(),this._debug)E.warning(`PathfindingEntityController._calculatePath: Maximum open set iterations reached (${P}), path search aborted. Start: ${this._coordinateToKey(X)}, Target: ${this._coordinateToKey(this._target)}`)}else if(this._debug)E.warning(`PathfindingEntityController._calculatePath: No valid path found. Start: ${this._coordinateToKey(X)}, Target: ${this._coordinateToKey(this._target)}`);return this._target=void 0,this._waypoints=[],!1}_reconstructPath(J,X){let Y=[X],Z=X;while(J.has(this._coordinateToKey(Z)))Z=J.get(this._coordinateToKey(Z)),Y.unshift(Z);return Y}_coordinateToKey(J){return`${J.x},${J.y},${J.z}`}_moveToNextWaypoint(){let J=this._waypointNextIndex>0?this._waypoints[this._waypointNextIndex-1]:void 0,X=this._waypoints[this._waypointNextIndex];if(!X||!this._entity)return;let Y=0;if(this._entity.isDynamic&&J&&X.y>J.y){let Z=X.y-J.y,W=Math.min(Z,this._maxJump)+0.75;this.jump(W);let $=Math.abs(this._entity.world.simulation.gravity.y),Q=Math.sqrt(2*$*W),K=J.x+0.5,G=J.z+0.5,F=X.x+0.5,q=X.z+0.5,H=F-K,z=q-G,V=Math.sqrt(H*H+z*z),M=Q/$,R=V/this._speed;Y=Math.min(M*0.8,R)*1000}setTimeout(()=>{if(!this._entity)return;let Z=Date.now();this.face(X,this._speed),this.move(X,this._speed,{moveIgnoreAxes:{y:this._entity.isDynamic},moveCallback:()=>{if(Date.now()-Z>this._waypointTimeoutMs&&this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveSkipped?.(X,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint()},moveCompleteCallback:()=>{if(this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveComplete?.(X,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint();else this._onPathfindComplete?.()}})},Y)}_pathfindingHeuristic(J,X){return Math.abs(J.x-X.x)+Math.abs(J.y-X.y)+Math.abs(J.z-X.z)}_isNeighborCoordinateBlocked(J,X,Y){if(!this._entity?.world)return!1;let Z=this._entity.world,W=Math.floor(X.x),$=Math.floor(X.y),Q=Math.floor(X.z),K=Math.floor(J.x),G=Math.floor(J.z);if(!Z.chunkLattice.hasBlock({x:W,y:$-1,z:Q}))return!0;for(let F=0;F<Y;F++)if(Z.chunkLattice.hasBlock({x:W,y:$+F,z:Q}))return!0;if(W!==K&&Q!==G)for(let F=0;F<Y;F++){let q=Z.chunkLattice.hasBlock({x:W,y:$+F,z:G}),H=Z.chunkLattice.hasBlock({x:K,y:$+F,z:Q});if(q||H)return!0}return!1}_findGroundedStart(){if(!this._entity?.world)return;let{x:J,y:X,z:Y}=this._entity.position,Z={x:Math.floor(J),y:Math.floor(X),z:Math.floor(Y)};for(let W=0;W<=Math.abs(this._maxFall);W++)if(this._entity.world.chunkLattice.hasBlock({...Z,y:Z.y-W-1}))return{...Z,y:Z.y-W};return}}export{dX0 as startServer,DC as WorldLoopEvent,IJ as WorldLoop,xH as WorldEvent,hJ as World,HH as WebServerEvent,o5 as WebServer,X4 as Vector3,pJ as Vector2,SJ as Ticker,OH as SimulationEvent,EJ as Simulation,AJ as SimpleEntityController,CJ as SceneUIManager,UH as SceneUIEvent,vJ as SceneUI,EC as SUPPORTED_INPUT_KEYS,W$ as RigidBodyType,f9 as RigidBody,jC as ROTATION_UPDATE_THRESHOLD,J4 as Quaternion,Q$ as PlayerUIEvent,DJ as PlayerUI,xC as PlayerManagerEvent,j6 as PlayerManager,BJ as PlayerEvent,NJ as PlayerEntityController,n1 as PlayerEntity,TC as PlayerCameraMode,RH as PlayerCameraEvent,TJ as PlayerCamera,r5 as Player,b9 as PersistenceManager,TH as PathfindingEntityController,BC as POSITION_UPDATE_THRESHOLD_SQ,qH as PORT,U6 as ModelRegistry,E8 as Matrix4,i6 as Matrix3,A9 as Matrix2,kC as LightType,kJ as LightManager,VH as LightEvent,MH as Light,_C as GameServerEvent,R1 as GameServer,s as EventRouter,E as ErrorHandler,jJ as EntityManager,$$ as EntityEvent,Y8 as Entity,vC as DEFAULT_ENTITY_RIGID_BODY_OPTIONS,q6 as CollisionGroupsBuilder,e1 as CollisionGroup,XZ as ColliderShape,_J as ColliderMap,d8 as Collider,zG as CoefficientCombineRule,PJ as ChunkLattice,LH as ChunkEvent,w8 as Chunk,fJ as ChatManager,PH as ChatEvent,UG as BlockTypeRegistryEvent,d4 as BlockTypeRegistry,LG as BlockTypeEvent,V6 as BlockType,y9 as Block,IH as BaseEntityControllerEvent,a1 as BaseEntityController,Q4 as AudioManager,V$ as AudioEvent,$4 as Audio};
|