hytopia 0.14.1 → 0.14.3
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/boilerplate/assets/ui/index.html +1 -0
- package/package.json +1 -1
- package/server.mjs +2 -2
package/package.json
CHANGED
package/server.mjs
CHANGED
|
@@ -409,7 +409,7 @@ globstar while`,J,z,$,H,v),this.matchOne(J.slice(z),$.slice(H),X))return this.de
|
|
|
409
409
|
characterSettings { skinTone hairColor eyeColor hairStyle }
|
|
410
410
|
equippedItems { slot item { slots { flags type modelUrl textureUrl } } }
|
|
411
411
|
}
|
|
412
|
-
}`});try{let Y=(await $.next()).value?.data?.userById;if(!Y)return n.warning(`PlatformGateway.getPlayerCosmetics(): No cosmetic data returned for user id "${J}".`);let Q=Y.equippedItems.map((Z)=>({slot:Z.slot,item:Z.item.slots.find((G)=>G.type===Z.slot)})).filter((Z)=>!!Z.item),W=Number(Y.characterSettings?.hairStyle?.split("_")[1]||1),K=`https://d3qkovarww0lj1.cloudfront.net/?skin_tone=${Y.characterSettings?.skinTone||"SKIN_COLOR_1"}&clothing=${Y.characterSettings?.clothing||"CLOTHING_1"}&hair_style=${Y.characterSettings?.hairStyle||"HAIR_STYLE_1"}&hair_color=${Y.characterSettings?.hairColor||"HAIR_COLOR_1"}&eye_color=${Y.characterSettings?.eyeColor||"00FF00"}`;return{equippedItems:Q,hairStyle:W,skinTextureUri:K}}finally{await $.return?.()}}async getPlayerSession(J){if(!this._creativeGateway)return;return await this._creativeGateway.getSession(J)}async scheduleNotification(J,$,X){if(!AO)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_NOTIFICATION_SERVICE_URL is not set. Unable to schedule notification in this environment.");if(!this.gameId||!this.creatorApiKey)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_GAME_ID or HYTOPIA_API_KEY is not set. Unable to schedule notification in this environment.");try{let Y=await fetch(`${AO}/notifications`,{method:"POST",headers:{"Content-Type":"application/json","X-Game-Id":this.gameId,"X-Creator-Api-Key":this.creatorApiKey},body:JSON.stringify({hytopiaUserId:J,type:$,scheduledFor:X})});if(!Y.ok)return n.warning(`PlatformGateway.scheduleNotification(): Failed ${Y.status}: ${await Y.text()}`);return(await Y.json()).id}catch(Y){return n.warning(`PlatformGateway.scheduleNotification(): Failed to schedule notification: ${Y}`)}}async setGlobalData(J,$){if($.error)return n.warning("PlatformGateway.setGlobalData(): Cannot set data with an error property.");if(!this._creativeGateway&&process.env.NODE_ENV==="production")return n.warning("PlatformGateway.setGlobalData(): 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,$):this._writeDevGlobalDataLocally(J,$)}async unscheduleNotification(J){if(!AO)return n.warning("PlatformGateway.unscheduleNotification(): HYTOPIA_NOTIFICATION_SERVICE_URL is not set."),!1;if(!this.gameId||!this.creatorApiKey)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_GAME_ID or HYTOPIA_API_KEY is not set."),!1;try{let $=await fetch(`${AO}/notifications/${J}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-Game-Id":this.gameId,"X-Creator-Api-Key":this.creatorApiKey}});if(!$.ok)return n.warning(`PlatformGateway.unscheduleNotification(): Failed ${$.status}: ${await $.text()}`),!1;return!0}catch($){return n.warning(`PlatformGateway.unscheduleNotification(): Failed to unschedule notification: ${$}`),!1}}_readDevGlobalDataLocally(J){try{if(!gZ.existsSync(qU))return{error:{code:"keyNotFound",message:"Local data directory not found."}};let $=Fq0.join(qU,`${J}.json`);return JSON.parse(gZ.readFileSync($,"utf8"))}catch($){return n.warning(`PlatformGateway._readDevGlobalDataLocally(): Failed to read data for key "${J}": ${$}`),{error:{code:"gatewayError",message:"Failed to read data for key."}}}}_writeDevGlobalDataLocally(J,$){try{if(!gZ.existsSync(qU))gZ.mkdirSync(qU,{recursive:!0});let X=Fq0.join(qU,`${J}.json`),Y={};if(gZ.existsSync(X))Y=JSON.parse(gZ.readFileSync(X,"utf8"));let Q={...Y,...$};gZ.writeFileSync(X,JSON.stringify(Q,null,2),"utf8")}catch(X){n.warning(`PlatformGateway._writeDevGlobalDataLocally(): Failed to write data for key "${J}": ${X}`)}}}class CW{static instance=new CW;_saveStatesClient;constructor(){this._saveStatesClient=new jq0.SaveStatesClient}async getGlobalData(J,$=3){for(let X=0;X<=$;X++){let Y=await k7.instance.getGlobalData(J);if(Y&&!Y.error)return Y;if(Y.error.code==="keyNotFound")return{};if(X<$)n.warning(`PersistenceManager.getGlobalData(): Failed to get global data, retrying. Response: ${JSON.stringify(Y)}`),await new Promise((Q)=>setTimeout(Q,500))}n.warning(`PersistenceManager.getGlobalData(): Failed to get global data after ${$} attempts.`);return}async getPlayerData(J){let $=await this._saveStatesClient.load(this._getPlayerKey(J));if(!$)return n.warning(`PersistenceManager.getPlayerData(): Failed to get player data for player ${J.id}. Persistence service may be down.`),{};return $}async setGlobalData(J,$){let X=await k7.instance.setGlobalData(J,$);if(!X||X.error){if(X?.error)n.warning(`PersistenceManager.setGlobalData(): ${X.error.message}`)}}async setPlayerData(J,$){let X=await this.getPlayerData(J);for(let[Y,Q]of Object.entries($))X[Y]=Q}async unloadPlayerData(J){await this._saveStatesClient.unload(this._getPlayerKey(J))}_getPlayerKey(J){return`player-${J.id}`}}var Bq0;((Y)=>{Y[Y.FIRST_PERSON=0]="FIRST_PERSON";Y[Y.THIRD_PERSON=1]="THIRD_PERSON";Y[Y.SPECTATOR=2]="SPECTATOR"})(Bq0||={});var Sh;((U)=>{U.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";U.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";U.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";U.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";U.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";U.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";U.SET_FOV="PLAYER_CAMERA.SET_FOV";U.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";U.SET_MODEL_SHOWN_NODES="PLAYER_CAMERA.SET_MODEL_SHOWN_NODES";U.SET_MODE="PLAYER_CAMERA.SET_MODE";U.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";U.SET_SHOULDER_ANGLE="PLAYER_CAMERA.SET_SHOULDER_ANGLE";U.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";U.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";U.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(Sh||={});class HU extends $1{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_modelShownNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_shoulderAngle=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 facingQuaternion(){let J=this._orientation.pitch*0.5,$=this._orientation.yaw*0.5,X=Math.cos(J),Y=Math.sin(J),Q=Math.cos($),W=Math.sin($);return{x:Y*Q,y:X*W,z:-Y*W,w:X*Q}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get modelShownNodes(){return this._modelShownNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get shoulderAngle(){return this._shoulderAngle}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){if(!this._requirePlayerWorld("lookAtEntity"))return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){if(!this._requirePlayerWorld("lookAtPosition"))return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}reset(){this._attachedToEntity=void 0,this._attachedToPosition=void 0,this._orientation={pitch:0,yaw:0},this._trackedEntity=void 0,this._trackedPosition=void 0}setAttachedToEntity(J){if(!this._requirePlayerWorld("setAttachedToEntity"))return;if(!J.isSpawned)return n.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("setAttachedToPosition"))return;this._attachedToPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){if(!this._requirePlayerWorld("setFilmOffset"))return;this._filmOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){if(!this._requirePlayerWorld("setForwardOffset"))return;this._forwardOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){if(!this._requirePlayerWorld("setFov"))return;this._fov=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){if(!this._requirePlayerWorld("setModelHiddenNodes"))return;this._modelHiddenNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setModelShownNodes(J){if(!this._requirePlayerWorld("setModelShownNodes"))return;this._modelShownNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_SHOWN_NODES",{playerCamera:this,modelShownNodes:this._modelShownNodes})}setMode(J){if(!this._requirePlayerWorld("setMode"))return;this._mode=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){if(!this._requirePlayerWorld("setOffset"))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}setShoulderAngle(J){if(!this._requirePlayerWorld("setShoulderAngle"))return;this._shoulderAngle=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_SHOULDER_ANGLE",{playerCamera:this,shoulderAngle:J})}setTrackedEntity(J){if(!this._requirePlayerWorld("setTrackedEntity"))return;this._trackedEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){if(!this._requirePlayerWorld("setTrackedPosition"))return;this._trackedPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){if(!this._requirePlayerWorld("setZoom"))return;this._zoom=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return V1.serializePlayerCamera(this)}_requirePlayerWorld(J){if(!this.player.world)n.error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world, invoked method: ${J}()`);return!!this.player.world}}var cO;((Q)=>{Q.DATA="PLAYER_UI.DATA";Q.LOAD="PLAYER_UI.LOAD";Q.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";Q.SEND_DATA="PLAYER_UI.SEND_DATA"})(cO||={});class zU extends $1{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})}}var x78=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","u","i","o","j","k","l","n","m","1","2","3","4","5","6","7","8","9","0","cp","cy","jd"],vU;((K)=>{K.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";K.JOINED_WORLD="PLAYER.JOINED_WORLD";K.LEFT_WORLD="PLAYER.LEFT_WORLD";K.RECONNECTED_WORLD="PLAYER.RECONNECTED_WORLD";K.REQUEST_NOTIFICATION_PERMISSION="PLAYER.REQUEST_NOTIFICATION_PERMISSION";K.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(vU||={});class kq extends $1{static _devNextPlayerId=1;id;username;profilePictureUrl;camera;connection;cosmetics;ui;_input={};_lastUnreliableInputSequenceNumber=0;_persistedData;_world;_worldSwitched=!1;constructor(J,$){super();this.id=$?.user.id??`player-${kq._devNextPlayerId++}`,this.username=$?.user.username??this.id,this.profilePictureUrl=$?.user.profilePictureURL??void 0,this.camera=new HU(this),this.connection=J,this.cosmetics=k7.instance.getPlayerCosmetics(this.id),this.ui=new zU(this),J.onPacket(_0.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(_0.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(_0.PacketId.INPUT,this._onInputPacket),J.onPacket(_0.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(_0.PacketId.UI_DATA_SEND,this._onUIDataSendPacket)}get input(){return this._input}get world(){return this._world}disconnect(){this._leaveWorld(),this.connection.disconnect()}getPersistedData(){if(!this._persistedData)return;let J=Object.keys(this._persistedData);if(J.length===0||J.length===1&&J[0]==="__version")return;return this._persistedData}joinWorld(J){if(this._world===J)return;if(!this._world)this._world=J,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world});else{for(let $ of this._world.entityManager.getPlayerEntitiesByPlayer(this))if($.isSpawned)$.despawn();this.disconnect(),this._world=J,this._worldSwitched=!0}}async scheduleNotification(J,$){if(!this._world)return n.warning("Player.scheduleNotification(): Player must be in a world to schedule a notification.");return this.emitWithWorld(this._world,"PLAYER.REQUEST_NOTIFICATION_PERMISSION",{player:this}),k7.instance.scheduleNotification(this.id,J,$)}async unscheduleNotification(J){if(!J)return!1;return k7.instance.unscheduleNotification(J)}async loadInitialPersistedData(){if(this._persistedData)return;this._persistedData=await CW.instance.getPlayerData(this)}reconnected(){if(!this._world)return;if(this._lastUnreliableInputSequenceNumber=0,!this._worldSwitched)this.emitWithWorld(this._world,"PLAYER.RECONNECTED_WORLD",{player:this,world:this._world});else this._worldSwitched=!1,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world})}resetInputs(){this._input={}}setPersistedData(J){if(!this._persistedData){n.warning(`Player.setPersistedData(): Persisted data not found for player ${this.id}`);return}for(let[$,X]of Object.entries(J))this._persistedData[$]=X}serialize(){return V1.serializePlayer(this)}_leaveWorld(){if(!this._world)return;this.emitWithWorld(this._world,"PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}_onChatMessageSendPacket=(J)=>{if(!this._world)return;let $=J[1].m;if(this._world.chatManager.handleCommand(this,$)){this._world.chatManager.sendPlayerMessage(this,`Command Entered: ${$}`,"CCCCCC");return}if(this.id.startsWith("guest")){this._world.chatManager.sendPlayerMessage(this,"You need to create a HYTOPIA account to send messages in chat.","FFAA00");return}this.emitWithWorld(this._world,"PLAYER.CHAT_MESSAGE_SEND",{player:this,message:$})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let $=J[1];if($.sq!==void 0){if($.sq<this._lastUnreliableInputSequenceNumber)return;this._lastUnreliableInputSequenceNumber=$.sq}if(Object.assign(this._input,$),$.cp!==void 0)this.camera.setOrientationPitch($.cp);if($.cy!==void 0)this.camera.setOrientationYaw($.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 Ah;((X)=>{X.BROADCAST_MESSAGE="CHAT.BROADCAST_MESSAGE";X.PLAYER_MESSAGE="CHAT.PLAYER_MESSAGE"})(Ah||={});class FU extends $1{_commandCallbacks={};_world;constructor(J){super();this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,$){this._commandCallbacks[J]=$}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,$){this._sendBroadcastMessage(void 0,J,$)}handleCommand(J,$){let[X,...Y]=$.split(" "),Q=this._commandCallbacks[X];if(Q)return Q(J,Y,$),!0;return!1}sendPlayerMessage(J,$,X){this.emitWithWorld(this._world,"CHAT.PLAYER_MESSAGE",{player:J,message:$,color:X})}_subscribeToPlayerEvents(){this._world.on("PLAYER.CHAT_MESSAGE_SEND",(J)=>{let{player:$,message:X}=J;this._sendBroadcastMessage($,X)})}_sendBroadcastMessage(J,$,X){this.emitWithWorld(this._world,"CHAT.BROADCAST_MESSAGE",{player:J,message:$,color:X})}}var f9=16,ch=f9-1,P78=f9**3;class X9{_blocks;_originCoordinate;constructor(J){this._blocks=new Uint8Array(P78),this._originCoordinate=J}get blocks(){return this._blocks}get originCoordinate(){return this._originCoordinate}static blockIndexToLocalCoordinate(J){return{x:J%f9,y:(J/f9|0)%f9,z:J/(f9*f9)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&f9-1,y:J.y&f9-1,z:J.z&f9-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(f9-1),y:J.y&~(f9-1),z:J.z&~(f9-1)}}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,$){if(!this._isValidLocalCoordinate(J))return n.error("Chunk.setBlock(): Block local coordinate is out of bounds");let X=this._getIndex(J);this._blocks[X]=$}serialize(){return V1.serializeChunk(this)}_getIndex(J){return J.x+(J.y<<4)+(J.z<<8)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=ch&&J.y>=0&&J.y<=ch&&J.z>=0&&J.z<=ch}}var _h;((Y)=>{Y.ADD_CHUNK="CHUNK_LATTICE.ADD_CHUNK";Y.REMOVE_CHUNK="CHUNK_LATTICE.REMOVE_CHUNK";Y.SET_BLOCK="CHUNK_LATTICE.SET_BLOCK"})(_h||={});class UU extends $1{_blockTypeColliders=new Map;_blockTypeCounts=new Map;_chunks=new Map;_rigidBody;_world;constructor(J){super();this._world=J}get chunkCount(){return this._chunks.size}clear(){for(let J of this._blockTypeColliders.values())this._world.simulation.colliderMap.removeColliderBlockType(J),J.removeFromSimulation();this._chunks.forEach((J)=>{this.emitWithWorld(this._world,"CHUNK_LATTICE.REMOVE_CHUNK",{chunkLattice:this,chunk:J})}),this._blockTypeColliders.clear(),this._blockTypeCounts.clear(),this._chunks.clear()}getBlockId(J){let $=this.getChunk(X9.globalCoordinateToOriginCoordinate(J));if(!$)return 0;return $.getBlockId(X9.globalCoordinateToLocalCoordinate(J))}getBlockTypeCollider(J){return this._blockTypeColliders.get(J)}getBlockType(J){let $=this.getBlockId(J);return $?this._world.blockTypeRegistry.getBlockType($):null}getBlockTypeCount(J){return this._blockTypeCounts.get(J)??0}getChunk(J){return this._chunks.get(this._getChunkKey(X9.globalCoordinateToOriginCoordinate(J)))}getOrCreateBlockTypeCollider(J,$){let X=this._blockTypeColliders.get(J);if(X)return X;let Q=this._world.blockTypeRegistry.getBlockType(J).createCollider($);return this._blockTypeColliders.set(J,Q),Q}getOrCreateChunk(J){let $=X9.globalCoordinateToOriginCoordinate(J),X=this._chunks.get(this._getChunkKey($));if(X)return X;return X=new X9($),this._chunks.set(this._getChunkKey($),X),this.emitWithWorld(this._world,"CHUNK_LATTICE.ADD_CHUNK",{chunkLattice:this,chunk:X}),X}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let $=this.getChunk(X9.globalCoordinateToOriginCoordinate(J));if(!$)return!1;return $.hasBlock(X9.globalCoordinateToLocalCoordinate(J))}hasChunk(J){let $=X9.globalCoordinateToOriginCoordinate(J);return this._chunks.has(this._getChunkKey($))}initializeBlocks(J){if(this.clear(),!this._rigidBody)this._rigidBody=new FW({type:"fixed"}),this._rigidBody.addToSimulation(this._world.simulation);for(let $ in J){let X=Number($),Y=J[X];if(Y.length===0)continue;let Q=this.getOrCreateBlockTypeCollider(X,Y);Q.addToSimulation(this._world.simulation,this._rigidBody);let W=this._world.blockTypeRegistry.getBlockType(X);this._world.simulation.colliderMap.setColliderBlockType(Q,W),this._blockTypeCounts.set(X,Y.length);for(let K=0;K<Y.length;K++){let Z=Y[K],G=X9.globalCoordinateToLocalCoordinate(Z),V=this.getOrCreateChunk(Z);V.setBlock(G,X),this.emitWithWorld(this._world,"CHUNK_LATTICE.SET_BLOCK",{chunkLattice:this,chunk:V,globalCoordinate:Z,localCoordinate:G,blockTypeId:X})}this._combineVoxelStates(Q)}}setBlock(J,$){let X=X9.globalCoordinateToLocalCoordinate(J),Y=this.getOrCreateChunk(J),Q=Y.getBlockId(X);if(Q===$)return;if(Y.setBlock(X,$),!this._rigidBody)this._rigidBody=new FW({type:"fixed"}),this._rigidBody.addToSimulation(this._world.simulation);if(Q!==0){let W=Math.max(0,(this._blockTypeCounts.get(Q)??0)-1),K=this.getBlockTypeCollider(Q);if(K)if(W===0)this._world.simulation.colliderMap.removeColliderBlockType(K),K.removeFromSimulation(),this._blockTypeColliders.delete(Q);else K.setVoxel(J,!1),this._propagateVoxelChange(K,J);this._blockTypeCounts.set(Q,W)}if($!==0){let W=(this._blockTypeCounts.get($)??0)+1,K=this.getOrCreateBlockTypeCollider($,[J]);if(W===1){let Z=this._world.blockTypeRegistry.getBlockType($);K.addToSimulation(this._world.simulation,this._rigidBody),this._world.simulation.colliderMap.setColliderBlockType(K,Z),this._combineVoxelStates(K)}else K.setVoxel(J,!0),this._propagateVoxelChange(K,J);this._blockTypeCounts.set($,W)}this.emitWithWorld(this._world,"CHUNK_LATTICE.SET_BLOCK",{chunkLattice:this,chunk:Y,globalCoordinate:J,localCoordinate:X,blockTypeId:$})}_combineVoxelStates(J){if(J.isSensor)return;for(let $ of this._blockTypeColliders.values()){if($===J||$.isSensor)continue;J.combineVoxelStates($)}}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}_propagateVoxelChange(J,$){if(J.isSensor)return;for(let X of this._blockTypeColliders.values()){if(X===J||X.isSensor)continue;J.propagateVoxelChange(X,$)}}}class jU{_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,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleBlockType(J.rawCollider.handle,$)}setColliderCollisionCallback(J,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleCollisionCallback(J.rawCollider.handle,$)}setColliderEntity(J,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleEntity(J.rawCollider.handle,$)}setColliderHandleBlockType(J,$){this._colliderHandleBlockTypeMap.set(J,$),this._cleanupBlockTypeColliderHandles.delete(J),this._pendingCleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,$){this._colliderHandleCollisionCallbackMap.set(J,$),this._cleanupCollisionCallbackColliderHandles.delete(J),this._pendingCleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,$){this._colliderHandleEntityMap.set(J,$),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);if(this._cleanupBlockTypeColliderHandles.size>0)this._cleanupBlockTypeColliderHandles.clear();for(let J of this._cleanupCollisionCallbackColliderHandles)this._colliderHandleCollisionCallbackMap.delete(J);if(this._cleanupCollisionCallbackColliderHandles.size>0)this._cleanupCollisionCallbackColliderHandles.clear();for(let J of this._cleanupEntityColliderHandles)this._colliderHandleEntityMap.delete(J);if(this._cleanupEntityColliderHandles.size>0)this._cleanupEntityColliderHandles.clear();for(let J of this._pendingCleanupBlockTypeColliderHandles)this._cleanupBlockTypeColliderHandles.add(J);if(this._pendingCleanupBlockTypeColliderHandles.size>0)this._pendingCleanupBlockTypeColliderHandles.clear();for(let J of this._pendingCleanupCollisionCallbackColliderHandles)this._cleanupCollisionCallbackColliderHandles.add(J);if(this._pendingCleanupCollisionCallbackColliderHandles.size>0)this._pendingCleanupCollisionCallbackColliderHandles.clear();for(let J of this._pendingCleanupEntityColliderHandles)this._cleanupEntityColliderHandles.add(J);if(this._pendingCleanupEntityColliderHandles.size>0)this._pendingCleanupEntityColliderHandles.clear()}_requireSimulatedCollider(J){if(!J.rawCollider)n.error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.");return!!J.rawCollider}}var wq0={type:"dynamic",softCcdPrediction:1},Lq0=0.015625,Mq0=Math.cos(0.026),BU;((R)=>{R.BLOCK_COLLISION="ENTITY.BLOCK_COLLISION";R.BLOCK_CONTACT_FORCE="ENTITY.BLOCK_CONTACT_FORCE";R.DESPAWN="ENTITY.DESPAWN";R.ENTITY_COLLISION="ENTITY.ENTITY_COLLISION";R.ENTITY_CONTACT_FORCE="ENTITY.ENTITY_CONTACT_FORCE";R.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";R.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";R.SET_MODEL_SCALE="ENTITY.SET_MODEL_SCALE";R.SET_MODEL_SHOWN_NODES="ENTITY.SET_MODEL_SHOWN_NODES";R.SET_MODEL_TEXTURE_URI="ENTITY.SET_MODEL_TEXTURE_URI";R.SET_OPACITY="ENTITY.SET_OPACITY";R.SET_PARENT="ENTITY.SET_PARENT";R.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";R.SPAWN="ENTITY.SPAWN";R.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";R.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";R.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";R.TICK="ENTITY.TICK";R.UPDATE_POSITION="ENTITY.UPDATE_POSITION";R.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})(BU||={});class b6 extends FW{_id;_blockHalfExtents;_blockTextureUri;_controller;_isEnvironmental=!1;_modelAnimationsPlaybackRate=1;_modelHiddenNodes=new Set;_modelLoopedAnimations=new Set;_modelOneshotAnimations=new Set;_modelPreferredShape;_modelScale={x:1,y:1,z:1};_modelShownNodes=new Set;_modelTextureUri;_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;_positionUpdateThresholdSq;_rotationUpdateThreshold;constructor(J){let $="blockTextureUri"in J,X="modelUri"in J;if(!$===!X)n.fatalError("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if($&&!J.blockHalfExtents)n.fatalError("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)n.fatalError("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!k5.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))n.fatalError(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??wq0);if($)this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri;if(X){let Y=this._modelScale=typeof J.modelScale==="number"?{x:J.modelScale,y:J.modelScale,z:J.modelScale}:J.modelScale??{x:1,y:1,z:1};if(this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelPreferredShape=J.modelPreferredShape,this._modelScale=Y,this._modelTextureUri=J.modelTextureUri,this._modelUri=J.modelUri,!this._modelUri.startsWith("http")&&!k5.instance.hasModel(this._modelUri))n.error(`Entity.constructor(): Model ${this._modelUri} does not exist!`);J.modelHiddenNodes?.forEach((Q)=>this._modelHiddenNodes.add(Q.toLowerCase())),J.modelLoopedAnimations?.forEach((Q)=>this._modelLoopedAnimations.add(Q)),J.modelShownNodes?.forEach((Q)=>this._modelShownNodes.add(Q.toLowerCase()))}if(this._isEnvironmental=J.isEnvironmental??!1,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,this._positionUpdateThresholdSq=Lq0,this._rotationUpdateThreshold=Mq0,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 depth(){return this.isModelEntity?k5.instance.getDepth(this._modelUri)*this._modelScale.z:this._blockHalfExtents.z*2}get height(){return this.isModelEntity?k5.instance.getHeight(this._modelUri)*this._modelScale.y:this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelPreferredShape(){return this._modelPreferredShape}get modelScale(){return this._modelScale}get modelShownNodes(){return this._modelShownNodes}get modelTextureUri(){return this._modelTextureUri}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 isEnvironmental(){return this._isEnvironmental}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get width(){return this.isModelEntity?k5.instance.getWidth(this._modelUri)*this._modelScale.x:this._blockHalfExtents.x*2}get world(){return this._world}spawn(J,$,X){if(this.isSpawned)return n.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 S9(S9.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0&&this._modelPreferredShape!=="none")this.addChildColliderToSimulation(new S9(S9.optionsFromModelUri(this._modelUri,this._modelScale,this._modelPreferredShape)));if(this.colliders.forEach((Y)=>{if(this.hasListeners("ENTITY.BLOCK_COLLISION")||this.hasListeners("ENTITY.ENTITY_COLLISION"))Y.enableCollisionEvents(!0);if(this.hasListeners("ENTITY.BLOCK_CONTACT_FORCE")||this.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))Y.enableContactForceEvents(!0);if(cJ.isDefaultCollisionGroups(Y.collisionGroups)){let Q=this.isEnvironmental?[8]:[Y.isSensor?4:2],W=this.isEnvironmental?[65535&~8&~1]:[65535];Y.setCollisionGroups({belongsTo:Q,collidesWith:W})}}),this.setPosition($),X)this.setRotation(X);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);this.colliders.forEach((Y)=>{J.simulation.colliderMap.setColliderEntity(Y,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.particleEmitterManager.despawnEntityAttachedParticleEmitters(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}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})}setModelHiddenNodes(J){if(!this._requireSpawned("setModelHiddenNodes"))return;if(!this.isModelEntity)return;this._modelHiddenNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setModelScale(J){if(!this._requireSpawned("setModelScale"))return;if(typeof J==="number")J={x:J,y:J,z:J};if(!this.isModelEntity||this._modelScale===J)return;let $={x:J.x/this._modelScale.x,y:J.y/this._modelScale.y,z:J.z/this._modelScale.z};this._modelScale=J,this.colliders.forEach((X)=>X.setScale($)),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_SCALE",{entity:this,modelScale:J})}setModelShownNodes(J){if(!this._requireSpawned("setModelShownNodes"))return;if(!this.isModelEntity)return;this._modelShownNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_SHOWN_NODES",{entity:this,modelShownNodes:this._modelShownNodes})}setModelTextureUri(J){if(!this._requireSpawned("setModelTextureUri"))return;if(!this.isModelEntity||this._modelTextureUri===J)return;this._modelTextureUri=J,this.emitWithWorld(this._world,"ENTITY.SET_MODEL_TEXTURE_URI",{entity:this,modelTextureUri:J})}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){if(!this._requireSpawned("setParent"))return;if(J&&!J.isSpawned)return n.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=$,this.colliders.forEach((Q)=>Q.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(X??{x:0,y:0,z:0}),this.setRotation(Y??{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:$})}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(($)=>!this._modelLoopedAnimations.has($)))return;J.forEach(($)=>{this._modelLoopedAnimations.add($)}),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(($)=>{this._modelOneshotAnimations.add($)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopAllModelAnimations(J=[]){if(!this._requireSpawned("stopAllModelAnimations"))return;this._stopAnimationsFromSets([this._modelLoopedAnimations,this._modelOneshotAnimations],J)}stopAllModelLoopedAnimations(J=[]){if(!this._requireSpawned("stopAllModelLoopedAnimations"))return;this._stopAnimationsFromSets([this._modelLoopedAnimations],J)}stopAllModelOneshotAnimations(J=[]){if(!this._requireSpawned("stopAllModelOneshotAnimations"))return;this._stopAnimationsFromSets([this._modelOneshotAnimations],J)}stopModelAnimations(J){if(!this._requireSpawned("stopModelAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some(($)=>this._modelLoopedAnimations.has($))&&!J.some(($)=>this._modelOneshotAnimations.has($)))return;J.forEach(($)=>{this._modelLoopedAnimations.delete($),this._modelOneshotAnimations.delete($)}),this.emitWithWorld(this._world,"ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return V1.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,$=this.rotation;if(this._rotationExceedsThreshold($,this._lastUpdatedRotation))this._lastUpdatedRotation=$,this.emitWithWorld(this._world,"ENTITY.UPDATE_ROTATION",{entity:this,rotation:$});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this.emitWithWorld(this._world,"ENTITY.UPDATE_POSITION",{entity:this,position:J})}_positionExceedsThreshold(J,$){let X=J.x-$.x,Y=J.y-$.y,Q=J.z-$.z;return X*X+Y*Y+Q*Q>this._positionUpdateThresholdSq}_requireSpawned(J){if(!this.isSpawned)n.error(`Entity._requireSpawned(): Entity ${this._name} is not spawned, cannot invoke ${J}()!`);return this.isSpawned}_rotationExceedsThreshold(J,$){return Math.abs(J.x*$.x+J.y*$.y+J.z*$.z+J.w*$.w)<this._rotationUpdateThreshold}_stopAnimationsFromSets(J,$=[]){if(!this.isModelEntity)return;let X=new Set($),Y=[];for(let Q of J)for(let W of Q)if(!X.has(W))Y.push(W);if(Y.length>0)this.stopModelAnimations(Y)}}class m8 extends iK{static BASE_ENTITY_HEIGHT=1.5;static GROUND_SENSOR_HEIGHT_SCALE=0.125;static GROUND_SENSOR_RADIUS_SCALE=0.23;static JUMP_LAND_HEAVY_VELOCITY_THRESHOLD=-12;static WALL_COLLIDER_HEIGHT_SCALE=0.33;static WALL_COLLIDER_RADIUS_SCALE=0.4;static MOVEMENT_ROTATIONS={wa:Math.PI/4,wd:-Math.PI/4,sa:Math.PI-Math.PI/4,sd:Math.PI+Math.PI/4,s:Math.PI,asd:Math.PI,a:Math.PI/2,d:-Math.PI/2};static EXTERNAL_IMPULSE_DECAY_RATE=0.253;static SWIM_UPWARD_COOLDOWN_MS=600;static SWIMMING_DRAG_FACTOR=0.05;static WATER_ENTRY_SINKING_FACTOR=0.8;static WATER_ENTRY_SINKING_MS=250;applyDirectionalMovementRotations=!0;autoCancelMouseLeftClick=!0;canJump=()=>!0;canRun=()=>!0;canSwim=()=>!0;canWalk=()=>!0;faceForwardOnStop=!0;idleLoopedAnimations=["idle-upper","idle-lower"];interactOneshotAnimations=["simple-interact"];jumpLandHeavyOneshotAnimations=["jump-post-heavy"];jumpLandLightOneshotAnimations=["jump-post-light"];jumpOneshotAnimations=["jump-loop"];jumpVelocity=10;runLoopedAnimations=["run-upper","run-lower"];runVelocity=8;sticksToPlatforms=!0;swimFastVelocity=5;swimGravity=0;swimIdleLoopedAnimations=["swim-idle"];swimLoopedAnimations=["swim-forward"];swimMaxGravityVelocity=-1;swimSlowVelocity=3;swimUpwardVelocity=2;walkLoopedAnimations=["walk-upper","walk-lower"];walkVelocity=4;_externalVelocity={x:0,y:0,z:0};_magnitudeYTracker=0;_groundContactCount=0;_internalApplyImpulse=()=>{};_isActivelyMoving=!1;_isFullySubmerged=!1;_justSubmergedUntil=0;_liquidContactCount=0;_platform;_reusableImpulse={x:0,y:0,z:0};_reusablePlatformVelocity={x:0,y:0,z:0};_reusableTargetVelocities={x:0,y:0,z:0};_reusableVelocityClamp={x:0,y:0,z:0};_stepAudio;_swimUpwardCooldownAt=0;constructor(J={}){super();this.applyDirectionalMovementRotations=J.applyDirectionalMovementRotations??this.applyDirectionalMovementRotations,this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.faceForwardOnStop=J.faceForwardOnStop??this.faceForwardOnStop,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms,this.canJump=J.canJump??this.canJump,this.canRun=J.canRun??this.canRun,this.canSwim=J.canSwim??this.canSwim,this.canWalk=J.canWalk??this.canWalk,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.swimFastVelocity=J.swimFastVelocity??this.swimFastVelocity,this.swimSlowVelocity=J.swimSlowVelocity??this.swimSlowVelocity,this.swimUpwardVelocity=J.swimUpwardVelocity??this.swimUpwardVelocity,this.swimGravity=J.swimGravity??this.swimGravity,this.swimMaxGravityVelocity=J.swimMaxGravityVelocity??this.swimMaxGravityVelocity,this.idleLoopedAnimations=J.idleLoopedAnimations??this.idleLoopedAnimations,this.interactOneshotAnimations=J.interactOneshotAnimations??this.interactOneshotAnimations,this.jumpOneshotAnimations=J.jumpOneshotAnimations??this.jumpOneshotAnimations,this.jumpLandHeavyOneshotAnimations=J.jumpLandHeavyOneshotAnimations??this.jumpLandHeavyOneshotAnimations,this.jumpLandLightOneshotAnimations=J.jumpLandLightOneshotAnimations??this.jumpLandLightOneshotAnimations,this.runLoopedAnimations=J.runLoopedAnimations??this.runLoopedAnimations,this.swimLoopedAnimations=J.swimLoopedAnimations??this.swimLoopedAnimations,this.swimIdleLoopedAnimations=J.swimIdleLoopedAnimations??this.swimIdleLoopedAnimations,this.walkLoopedAnimations=J.walkLoopedAnimations??this.walkLoopedAnimations}get isActivelyMoving(){return this._isActivelyMoving}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get isSwimming(){return this._liquidContactCount>0}get platform(){return this._platform}attach(J){super.attach(J),this._internalApplyImpulse=J.applyImpulse.bind(J),J.applyImpulse=($)=>{let X=J.mass||1;this._externalVelocity.x+=$.x/X,this._externalVelocity.y+=$.y/X,this._externalVelocity.z+=$.z/X},this._stepAudio=new zz({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(),J.on("ENTITY.BLOCK_COLLISION",({blockType:$,started:X})=>{if(!$.isLiquid||!this.canSwim(this))return;if(this._liquidContactCount<=0&&X){let Y=J.linearVelocity;J.setLinearVelocity({x:Y.x*this.swimGravity,y:Y.y*this.swimGravity,z:Y.z*this.swimGravity})}if(this._liquidContactCount+=X?1:-1,this._liquidContactCount>0)J.setGravityScale(this.swimGravity),J.stopAllModelLoopedAnimations(this.swimLoopedAnimations),this._swimUpwardCooldownAt=performance.now()+m8.SWIM_UPWARD_COOLDOWN_MS;else J.setGravityScale(1),J.stopModelAnimations(this.swimLoopedAnimations)})}spawn(J){if(!J.isSpawned)return n.error("DefaultPlayerEntityController.spawn(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:m8.GROUND_SENSOR_RADIUS_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),halfHeight:m8.GROUND_SENSOR_HEIGHT_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),collisionGroups:{belongsTo:[4],collidesWith:[1,2,8]},isSensor:!0,relativePosition:{x:0,y:-J.height/2,z:0},tag:"groundSensor",onCollision:($,X)=>{if(!J.isSpawned)return;if(!($ instanceof A9)||!$.isLiquid){if(X&&this._groundContactCount===0&&J.linearVelocity.y<-1)if(J.linearVelocity.y<m8.JUMP_LAND_HEAVY_VELOCITY_THRESHOLD)J.startModelOneshotAnimations(this.jumpLandHeavyOneshotAnimations);else J.startModelOneshotAnimations(this.jumpLandLightOneshotAnimations);this._groundContactCount+=X?1:-1}if(!this._groundContactCount&&!this.isSwimming)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!($ instanceof b6))return;if(X&&this.sticksToPlatforms)this._platform=$;else if($===this._platform&&!X)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:m8.WALL_COLLIDER_HEIGHT_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),radius:m8.WALL_COLLIDER_RADIUS_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),collisionGroups:{belongsTo:[4],collidesWith:[1,2,8]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,$,X,Y){if(!J.isSpawned||!J.world)return;if(super.tickWithPlayerInput(J,$,X,Y),J.parent)return;let{w:Q,a:W,s:K,d:Z,c:G,sp:V,sh:q,ml:z,jd:H}=$,{yaw:v}=X,F=J.linearVelocity;this._reusableTargetVelocities.x=0,this._reusableTargetVelocities.y=0,this._reusableTargetVelocities.z=0;let U=typeof H==="number";this._isActivelyMoving=U||!!(Q||W||K||Z);let j=q,B=!U&&(W&&Z&&!Q&&!K||Q&&K&&!W&&!Z),w=j&&this.canRun(this)||!j&&this.canWalk(this);if(this.isSwimming&&!this._isFullySubmerged)this._isFullySubmerged=!0,this._justSubmergedUntil=performance.now()+m8.WATER_ENTRY_SINKING_MS;else if(!this.isSwimming)this._isFullySubmerged=!1,this._justSubmergedUntil=0;if(this.isGrounded&&!this.isSwimming&&this._isActivelyMoving&&!B&&w){let x=j?this.runLoopedAnimations:this.walkLoopedAnimations;J.stopAllModelLoopedAnimations(x),J.startModelLoopedAnimations(x),this._stepAudio?.setPlaybackRate(j?0.75:0.51),this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else if(this._isFullySubmerged&&this.canSwim(this))if(this._stepAudio?.pause(),this._isActivelyMoving)J.stopAllModelLoopedAnimations(this.swimLoopedAnimations),J.startModelLoopedAnimations(this.swimLoopedAnimations);else J.stopAllModelLoopedAnimations(this.swimIdleLoopedAnimations),J.startModelLoopedAnimations(this.swimIdleLoopedAnimations);else this._stepAudio?.pause(),J.stopAllModelLoopedAnimations(this.idleLoopedAnimations),J.startModelLoopedAnimations(this.idleLoopedAnimations);let M;if(this.applyDirectionalMovementRotations&&w){if(U)M=H;else if(Q&&W&&!Z&&!K)M=m8.MOVEMENT_ROTATIONS.wa;else if(Q&&Z&&!W&&!K)M=m8.MOVEMENT_ROTATIONS.wd;else if(K&&W&&!Q&&!Z)M=m8.MOVEMENT_ROTATIONS.sa;else if(K&&Z&&!Q&&!W)M=m8.MOVEMENT_ROTATIONS.sd;else if(K&&!Q&&!W&&!Z||W&&K&&Z&&!Q)M=m8.MOVEMENT_ROTATIONS.s;else if(W&&!Q&&!K&&!Z)M=m8.MOVEMENT_ROTATIONS.a;else if(Z&&!Q&&!W&&!K)M=m8.MOVEMENT_ROTATIONS.d}if(z)J.startModelOneshotAnimations(this.interactOneshotAnimations),$.ml=!this.autoCancelMouseLeftClick;if(w){let x=!this.isSwimming?j?this.runVelocity:this.walkVelocity:j?this.swimFastVelocity:this.swimSlowVelocity;if(U){let T=v+H;this._reusableTargetVelocities.x=-x*Math.sin(T),this._reusableTargetVelocities.z=-x*Math.cos(T)}else{let T=Math.sin(v),S=Math.cos(v);if(Q)this._reusableTargetVelocities.x-=x*T,this._reusableTargetVelocities.z-=x*S;if(K)this._reusableTargetVelocities.x+=x*T,this._reusableTargetVelocities.z+=x*S;if(W)this._reusableTargetVelocities.x-=x*S,this._reusableTargetVelocities.z+=x*T;if(Z)this._reusableTargetVelocities.x+=x*S,this._reusableTargetVelocities.z-=x*T;let C=Math.sqrt(this._reusableTargetVelocities.x*this._reusableTargetVelocities.x+this._reusableTargetVelocities.z*this._reusableTargetVelocities.z);if(C>x){let I=x/C;this._reusableTargetVelocities.x*=I,this._reusableTargetVelocities.z*=I}}}if(this.isSwimming){if(F.y<this.swimMaxGravityVelocity)this._reusableVelocityClamp.x=F.x,this._reusableVelocityClamp.y=this.swimMaxGravityVelocity,this._reusableVelocityClamp.z=F.z,J.setLinearVelocity(this._reusableVelocityClamp);if(F.y>this.swimUpwardVelocity*2)this._reusableVelocityClamp.x=F.x,this._reusableVelocityClamp.y=this.swimUpwardVelocity*2,this._reusableVelocityClamp.z=F.z,J.setLinearVelocity(this._reusableVelocityClamp);if(G)this._reusableTargetVelocities.y=-this.swimUpwardVelocity;else if(performance.now()<this._justSubmergedUntil)this._reusableTargetVelocities.y=-this.swimUpwardVelocity*m8.WATER_ENTRY_SINKING_FACTOR;else if(!V)this._reusableTargetVelocities.y=-F.y*m8.SWIMMING_DRAG_FACTOR}if(V&&this.canJump(this)){if(this.isGrounded&&!this.isSwimming&&F.y>-0.001&&F.y<=3)this._reusableTargetVelocities.y=this.jumpVelocity;else if(this.isSwimming&&performance.now()>this._swimUpwardCooldownAt)this._reusableTargetVelocities.y=this.swimUpwardVelocity}let R=this._platform?.linearVelocity??this._reusablePlatformVelocity;if(this._externalVelocity.y!==0)this._magnitudeYTracker+=this._externalVelocity.y;if(this._externalVelocity.x!==0||this._externalVelocity.y!==0||this._externalVelocity.z!==0){if(this.isGrounded){let x=Math.sqrt(this._externalVelocity.x*this._externalVelocity.x+this._magnitudeYTracker*this._magnitudeYTracker+this._externalVelocity.z*this._externalVelocity.z);if(x>0.01){let S=Math.max(0,x-m8.EXTERNAL_IMPULSE_DECAY_RATE)/x;this._externalVelocity.x*=S,this._magnitudeYTracker*=S,this._externalVelocity.z*=S}else this._externalVelocity.x=0,this._externalVelocity.y=0,this._magnitudeYTracker=0,this._externalVelocity.z=0}}let N=this._reusableTargetVelocities.x+this._externalVelocity.x-F.x+R.x,L=this._reusableTargetVelocities.y+this._externalVelocity.y+R.y,O=this._reusableTargetVelocities.z+this._externalVelocity.z-F.z+R.z;if(this._externalVelocity.y=0,N!==0||L!==0||O!==0){let x=J.mass;this._reusableImpulse.x=N*x,this._reusableImpulse.y=L*x,this._reusableImpulse.z=O*x,this._internalApplyImpulse(this._reusableImpulse)}if(v!==void 0&&(this.faceForwardOnStop||this.isActivelyMoving)){let T=(M!==void 0?v+M:v)*0.5;J.setRotation({x:0,y:Math.sin(T),z:0,w:Math.cos(T)})}}}var hh;((Z)=>{Z.LOAD="SCENE_UI.LOAD";Z.SET_ATTACHED_TO_ENTITY="SCENE_UI.SET_ATTACHED_TO_ENTITY";Z.SET_OFFSET="SCENE_UI.SET_OFFSET";Z.SET_POSITION="SCENE_UI.SET_POSITION";Z.SET_STATE="SCENE_UI.SET_STATE";Z.SET_VIEW_DISTANCE="SCENE_UI.SET_VIEW_DISTANCE";Z.UNLOAD="SCENE_UI.UNLOAD"})(hh||={});class wU extends $1{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.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 n.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 n.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 V1.serializeSceneUI(this)}}var Nq0=0.010000000000000002,Oq0=Math.cos(0.026);class o$ extends b6{player;nametagSceneUI;constructor(J){super(J);this._positionUpdateThresholdSq=Nq0,this._rotationUpdateThreshold=Oq0,this.player=J.player,this.nametagSceneUI=new wU({templateId:"hytopia:nametag",attachedToEntity:this,offset:{x:0,y:1,z:0},viewDistance:15,state:{username:this.player.username,profilePictureUrl:this.player.profilePictureUrl}})}spawn(J,$,X){super.spawn(J,$,X),this.nametagSceneUI.load(J),this.player.on("PLAYER.CHAT_MESSAGE_SEND",({message:Y})=>{this.nametagSceneUI.setState({chat:Y})})}tick(J){if(!this.isSpawned||!this.world)return;if(!this.controller)return n.error(`PlayerEntity.tick(): PlayerEntity "${this.name}" must have a controller.`);let{input:$,camera:X}=this.player;this.controller.tickWithPlayerInput(this,$,X.orientation,J),super.tick(J)}}var Rq0="models/players/player.gltf",C78={BACK:"back-anchor",HEAD:"head-anchor",LEFT_ARM:"arm-left-anchor",LEFT_FOOT:"foot-left-anchor",LEFT_HAND:"hand-left-anchor",LEFT_ITEM:"hand-left-anchor",LEFT_LEG:"leg-left-anchor",RIGHT_ARM:"arm-right-anchor",RIGHT_FOOT:"foot-right-anchor",RIGHT_HAND:"hand-right-anchor",RIGHT_ITEM:"hand-right-anchor",RIGHT_LEG:"leg-right-anchor",TORSO:"torso-anchor"};class fh extends o${_cosmeticHiddenSlots;constructor(J){super({modelUri:Rq0,modelLoopedAnimations:["idle_lower","idle_upper"],modelHiddenNodes:["hair-"],modelShownNodes:["hair-0003"],...J});if(this._cosmeticHiddenSlots=J.cosmeticHiddenSlots??[],!J.controller)this.setController(new m8)}get cosmeticHiddenSlots(){return this._cosmeticHiddenSlots}spawn(J,$,X){super.spawn(J,$,X),this.player.cosmetics.then((Y)=>{if(!Y||!this.modelUri)return;let Q=this.modelShownNodes.values().toArray().filter((Z)=>!Z.includes("hair-"));if(!(Y.equippedItems.some((Z)=>Z.item.flags.includes("HIDES_HAIR"))&&!this._cosmeticHiddenSlots.includes("ALL")&&!this._cosmeticHiddenSlots.includes("HEAD")))Q.push(`hair-${String(Y.hairStyle).padStart(4,"0")}`);if(this.setModelShownNodes(Q),this.modelUri===Rq0)this.setModelTextureUri(Y.skinTextureUri);if(this._cosmeticHiddenSlots.includes("ALL"))return;let K=[];for(let Z of Y.equippedItems){let{item:G,slot:V}=Z;if(this._cosmeticHiddenSlots.includes(V))continue;let q=C78[V];if(!q||!k5.instance.modelHasNode(this.modelUri,q))continue;if(G.flags.includes("REPLACES_LIMB")){let H=q.split("-").slice(0,-1).join("-");K.push(`${H}-clothing`,`${H}-geometry`)}new b6({modelUri:G.modelUrl,modelPreferredShape:"none",parent:this,parentNodeName:q}).spawn(J,{x:0,y:0,z:0})}if(K.length>0)this.setModelHiddenNodes([...this.modelHiddenNodes.values().toArray(),...K])}).catch((Y)=>n.warning(`DefaultPlayerEntity.spawn(): Failed to get player cosmetics: ${Y}`))}}class LU{_activeEntities=new Set;_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get entityCount(){return this._entities.size}get world(){return this._world}registerEntity(J){if(J.id!==void 0)n.fatalError(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let $=this._nextEntityId;if(this._entities.set($,J),this._nextEntityId++,!J.isEnvironmental)this._activeEntities.add(J);return $}unregisterEntity(J){if(J.id===void 0)return n.error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);if(this._entities.delete(J.id),!J.isEnvironmental)this._activeEntities.delete(J)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach(($)=>{if($ instanceof o$)J.push($)}),J}getPlayerEntitiesByPlayer(J){let $=[];return this._entities.forEach((X)=>{if(X instanceof o$&&X.player===J)$.push(X)}),$}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let $=[];return this._entities.forEach((X)=>{if(X.tag===J)$.push(X)}),$}getEntitiesByTagSubstring(J){let $=[];return this._entities.forEach((X)=>{if(X.tag?.includes(J))$.push(X)}),$}getEntityChildren(J){let $=[];return this._entities.forEach((X)=>{if(X.parent===J)$.push(X)}),$}tickEntities(J){for(let $ of this._activeEntities)$.tick(J)}checkAndEmitUpdates(){for(let J of this._activeEntities)J.checkAndEmitUpdates()}}import{gzipSync as EC6}from"zlib";var P4=M0(CH0(),1),VZ5=P4.default.v1,qZ5=P4.default.v1ToV6,HZ5=P4.default.v3,TH0=P4.default.v4,zZ5=P4.default.v5,vZ5=P4.default.v6,FZ5=P4.default.v6ToV1,UZ5=P4.default.v7,jZ5=P4.default.NIL,BZ5=P4.default.MAX,wZ5=P4.default.version,LZ5=P4.default.validate,MZ5=P4.default.stringify,NZ5=P4.default.parse;var dh;try{dh=new TextDecoder}catch(J){}var E0,y9,r=0;var sh=[],dZ=sh,OU=0,_8={},G8,cY,b9=0,E7=0,Y5,_Y,Q9=[],J8,kH0={useRecords:!1,mapsAsObjects:!0};class lO{}var oh=new lO;oh.name="MessagePack 0xC1";var TW=!1,fH0=2,ih,nh,ah;try{Function("")}catch(J){fH0=1/0}class hY{constructor(J){if(J){if(J.useRecords===!1&&J.mapsAsObjects===void 0)J.mapsAsObjects=!0;if(J.sequential&&J.trusted!==!1){if(J.trusted=!0,!J.structures&&J.useRecords!=!1){if(J.structures=[],!J.maxSharedStructures)J.maxSharedStructures=0}}if(J.structures)J.structures.sharedLength=J.structures.length;else if(J.getStructures)(J.structures=[]).uninitialized=!0,J.structures.sharedLength=0;if(J.int64AsNumber)J.int64AsType="number"}Object.assign(this,J)}unpack(J,$){if(E0)return nH0(()=>{return uO(),this?this.unpack(J,$):hY.prototype.unpack.call(kH0,J,$)});if(!J.buffer&&J.constructor===ArrayBuffer)J=typeof Buffer<"u"?Buffer.from(J):new Uint8Array(J);if(typeof $==="object")y9=$.end||J.length,r=$.start||0;else r=0,y9=$>-1?$:J.length;OU=0,E7=0,cY=null,dZ=sh,Y5=null,E0=J;try{J8=J.dataView||(J.dataView=new DataView(J.buffer,J.byteOffset,J.byteLength))}catch(X){if(E0=null,J instanceof Uint8Array)throw X;throw Error("Source must be a Uint8Array or Buffer but was a "+(J&&typeof J=="object"?J.constructor.name:typeof J))}if(this instanceof hY){if(_8=this,this.structures)return G8=this.structures,yO($);else if(!G8||G8.length>0)G8=[]}else if(_8=kH0,!G8||G8.length>0)G8=[];return yO($)}unpackMultiple(J,$){let X,Y=0;try{TW=!0;let Q=J.length,W=this?this.unpack(J,Q):pO.unpack(J,Q);if($){if($(W,Y,r)===!1)return;while(r<Q)if(Y=r,$(yO(),Y,r)===!1)return}else{X=[W];while(r<Q)Y=r,X.push(yO());return X}}catch(Q){throw Q.lastPosition=Y,Q.values=X,Q}finally{TW=!1,uO()}}_mergeStructures(J,$){if(nh)J=nh.call(this,J);if(J=J||[],Object.isFrozen(J))J=J.map((X)=>X.slice(0));for(let X=0,Y=J.length;X<Y;X++){let Q=J[X];if(Q){if(Q.isShared=!0,X>=32)Q.highByte=X-32>>5}}J.sharedLength=J.length;for(let X in $||[])if(X>=0){let Y=J[X],Q=$[X];if(Q){if(Y)(J.restoreStructures||(J.restoreStructures=[]))[X]=Y;J[X]=Q}}return this.structures=J}decode(J,$){return this.unpack(J,$)}}function yO(J){try{if(!_8.trusted&&!TW){let X=G8.sharedLength||0;if(X<G8.length)G8.length=X}let $;if(_8.randomAccessStructure&&E0[r]<64&&E0[r]>=32&&ih){if($=ih(E0,r,y9,_8),E0=null,!(J&&J.lazy)&&$)$=$.toJSON();r=y9}else $=y6();if(Y5)r=Y5.postBundlePosition,Y5=null;if(TW)G8.restoreStructures=null;if(r==y9){if(G8&&G8.restoreStructures)EH0();if(G8=null,E0=null,_Y)_Y=null}else if(r>y9)throw Error("Unexpected end of MessagePack data");else if(!TW){let X;try{X=JSON.stringify($,(Y,Q)=>typeof Q==="bigint"?`${Q}n`:Q).slice(0,100)}catch(Y){X="(JSON view not available "+Y+")"}throw Error("Data read, but end of buffer not reached "+X)}return $}catch($){if(G8&&G8.restoreStructures)EH0();if(uO(),$ instanceof RangeError||$.message.startsWith("Unexpected end of buffer")||r>y9)$.incomplete=!0;throw $}}function EH0(){for(let J in G8.restoreStructures)G8[J]=G8.restoreStructures[J];G8.restoreStructures=null}function y6(){let J=E0[r++];if(J<160)if(J<128)if(J<64)return J;else{let $=G8[J&63]||_8.getStructures&&bH0()[J&63];if($){if(!$.read)$.read=rh($,J&63);return $.read()}else return J}else if(J<144)if(J-=128,_8.mapsAsObjects){let $={};for(let X=0;X<J;X++){let Y=dH0();if(Y==="__proto__")Y="__proto_";$[Y]=y6()}return $}else{let $=new Map;for(let X=0;X<J;X++)$.set(y6(),y6());return $}else{J-=144;let $=Array(J);for(let X=0;X<J;X++)$[X]=y6();if(_8.freezeData)return Object.freeze($);return $}else if(J<192){let $=J-160;if(E7>=r)return cY.slice(r-b9,(r+=$)-b9);if(E7==0&&y9<140){let X=$<16?th($):pH0($);if(X!=null)return X}return mO($)}else{let $;switch(J){case 192:return null;case 193:if(Y5)if($=y6(),$>0)return Y5[1].slice(Y5.position1,Y5.position1+=$);else return Y5[0].slice(Y5.position0,Y5.position0-=$);return oh;case 194:return!1;case 195:return!0;case 196:if($=E0[r++],$===void 0)throw Error("Unexpected end of buffer");return ph($);case 197:return $=J8.getUint16(r),r+=2,ph($);case 198:return $=J8.getUint32(r),r+=4,ph($);case 199:return pZ(E0[r++]);case 200:return $=J8.getUint16(r),r+=2,pZ($);case 201:return $=J8.getUint32(r),r+=4,pZ($);case 202:if($=J8.getFloat32(r),_8.useFloat32>2){let X=nZ[(E0[r]&127)<<1|E0[r+1]>>7];return r+=4,(X*$+($>0?0.5:-0.5)>>0)/X}return r+=4,$;case 203:return $=J8.getFloat64(r),r+=8,$;case 204:return E0[r++];case 205:return $=J8.getUint16(r),r+=2,$;case 206:return $=J8.getUint32(r),r+=4,$;case 207:if(_8.int64AsType==="number")$=J8.getUint32(r)*4294967296,$+=J8.getUint32(r+4);else if(_8.int64AsType==="string")$=J8.getBigUint64(r).toString();else if(_8.int64AsType==="auto"){if($=J8.getBigUint64(r),$<=BigInt(2)<<BigInt(52))$=Number($)}else $=J8.getBigUint64(r);return r+=8,$;case 208:return J8.getInt8(r++);case 209:return $=J8.getInt16(r),r+=2,$;case 210:return $=J8.getInt32(r),r+=4,$;case 211:if(_8.int64AsType==="number")$=J8.getInt32(r)*4294967296,$+=J8.getUint32(r+4);else if(_8.int64AsType==="string")$=J8.getBigInt64(r).toString();else if(_8.int64AsType==="auto"){if($=J8.getBigInt64(r),$>=BigInt(-2)<<BigInt(52)&&$<=BigInt(2)<<BigInt(52))$=Number($)}else $=J8.getBigInt64(r);return r+=8,$;case 212:if($=E0[r++],$==114)return hH0(E0[r++]&63);else{let X=Q9[$];if(X)if(X.read)return r++,X.read(y6());else if(X.noBuffer)return r++,X();else return X(E0.subarray(r,++r));else throw Error("Unknown extension "+$)}case 213:if($=E0[r],$==114)return r++,hH0(E0[r++]&63,E0[r++]);else return pZ(2);case 214:return pZ(4);case 215:return pZ(8);case 216:return pZ(16);case 217:if($=E0[r++],E7>=r)return cY.slice(r-b9,(r+=$)-b9);return yH0($);case 218:if($=J8.getUint16(r),r+=2,E7>=r)return cY.slice(r-b9,(r+=$)-b9);return mH0($);case 219:if($=J8.getUint32(r),r+=4,E7>=r)return cY.slice(r-b9,(r+=$)-b9);return uH0($);case 220:return $=J8.getUint16(r),r+=2,SH0($);case 221:return $=J8.getUint32(r),r+=4,SH0($);case 222:return $=J8.getUint16(r),r+=2,AH0($);case 223:return $=J8.getUint32(r),r+=4,AH0($);default:if(J>=224)return J-256;if(J===void 0){let X=Error("Unexpected end of MessagePack data");throw X.incomplete=!0,X}throw Error("Unknown MessagePack token "+J)}}}var X$8=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function rh(J,$){function X(){if(X.count++>fH0){let Q=J.read=Function("r","return function(){return "+(_8.freezeData?"Object.freeze":"")+"({"+J.map((W)=>W==="__proto__"?"__proto_:r()":X$8.test(W)?W+":r()":"["+JSON.stringify(W)+"]:r()").join(",")+"})}")(y6);if(J.highByte===0)J.read=IH0($,J.read);return Q()}let Y={};for(let Q=0,W=J.length;Q<W;Q++){let K=J[Q];if(K==="__proto__")K="__proto_";Y[K]=y6()}if(_8.freezeData)return Object.freeze(Y);return Y}if(X.count=0,J.highByte===0)return IH0($,X);return X}var IH0=(J,$)=>{return function(){let X=E0[r++];if(X===0)return $();let Y=J<32?-(J+(X<<5)):J+(X<<5),Q=G8[Y]||bH0()[Y];if(!Q)throw Error("Record id is not defined for "+Y);if(!Q.read)Q.read=rh(Q,J);return Q.read()}};function bH0(){let J=nH0(()=>{return E0=null,_8.getStructures()});return G8=_8._mergeStructures(J,G8)}var mO=iZ,yH0=iZ,mH0=iZ,uH0=iZ,gO=!1;function lH0(J){gO=!0,mO=$(1),yH0=$(2),mH0=$(3),uH0=$(5);function $(X){return function(Q){let W=dZ[OU++];if(W==null){if(Y5)return iZ(Q);let Z=E0.byteOffset,G=J(r-X+Z,y9+Z,E0.buffer);if(typeof G=="string")W=G,dZ=sh;else if(dZ=G,OU=1,E7=1,W=dZ[0],W===void 0)throw Error("Unexpected end of buffer")}let K=W.length;if(K<=Q)return r+=Q,W;return cY=W,b9=r,E7=r+K,r+=Q,W.slice(0,Q)}}}function iZ(J){let $;if(J<16){if($=th(J))return $}if(J>64&&dh)return dh.decode(E0.subarray(r,r+=J));let X=r+J,Y=[];$="";while(r<X){let Q=E0[r++];if((Q&128)===0)Y.push(Q);else if((Q&224)===192){let W=E0[r++]&63;Y.push((Q&31)<<6|W)}else if((Q&240)===224){let W=E0[r++]&63,K=E0[r++]&63;Y.push((Q&31)<<12|W<<6|K)}else if((Q&248)===240){let W=E0[r++]&63,K=E0[r++]&63,Z=E0[r++]&63,G=(Q&7)<<18|W<<12|K<<6|Z;if(G>65535)G-=65536,Y.push(G>>>10&1023|55296),G=56320|G&1023;Y.push(G)}else Y.push(Q);if(Y.length>=4096)$+=F5.apply(String,Y),Y.length=0}if(Y.length>0)$+=F5.apply(String,Y);return $}function gH0(J,$,X){let Y=E0;E0=J,r=$;try{return iZ(X)}finally{E0=Y}}function SH0(J){let $=Array(J);for(let X=0;X<J;X++)$[X]=y6();if(_8.freezeData)return Object.freeze($);return $}function AH0(J){if(_8.mapsAsObjects){let $={};for(let X=0;X<J;X++){let Y=dH0();if(Y==="__proto__")Y="__proto_";$[Y]=y6()}return $}else{let $=new Map;for(let X=0;X<J;X++)$.set(y6(),y6());return $}}var F5=String.fromCharCode;function pH0(J){let $=r,X=Array(J);for(let Y=0;Y<J;Y++){let Q=E0[r++];if((Q&128)>0){r=$;return}X[Y]=Q}return F5.apply(String,X)}function th(J){if(J<4)if(J<2)if(J===0)return"";else{let $=E0[r++];if(($&128)>1){r-=1;return}return F5($)}else{let $=E0[r++],X=E0[r++];if(($&128)>0||(X&128)>0){r-=2;return}if(J<3)return F5($,X);let Y=E0[r++];if((Y&128)>0){r-=3;return}return F5($,X,Y)}else{let $=E0[r++],X=E0[r++],Y=E0[r++],Q=E0[r++];if(($&128)>0||(X&128)>0||(Y&128)>0||(Q&128)>0){r-=4;return}if(J<6)if(J===4)return F5($,X,Y,Q);else{let W=E0[r++];if((W&128)>0){r-=5;return}return F5($,X,Y,Q,W)}else if(J<8){let W=E0[r++],K=E0[r++];if((W&128)>0||(K&128)>0){r-=6;return}if(J<7)return F5($,X,Y,Q,W,K);let Z=E0[r++];if((Z&128)>0){r-=7;return}return F5($,X,Y,Q,W,K,Z)}else{let W=E0[r++],K=E0[r++],Z=E0[r++],G=E0[r++];if((W&128)>0||(K&128)>0||(Z&128)>0||(G&128)>0){r-=8;return}if(J<10)if(J===8)return F5($,X,Y,Q,W,K,Z,G);else{let V=E0[r++];if((V&128)>0){r-=9;return}return F5($,X,Y,Q,W,K,Z,G,V)}else if(J<12){let V=E0[r++],q=E0[r++];if((V&128)>0||(q&128)>0){r-=10;return}if(J<11)return F5($,X,Y,Q,W,K,Z,G,V,q);let z=E0[r++];if((z&128)>0){r-=11;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z)}else{let V=E0[r++],q=E0[r++],z=E0[r++],H=E0[r++];if((V&128)>0||(q&128)>0||(z&128)>0||(H&128)>0){r-=12;return}if(J<14)if(J===12)return F5($,X,Y,Q,W,K,Z,G,V,q,z,H);else{let v=E0[r++];if((v&128)>0){r-=13;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v)}else{let v=E0[r++],F=E0[r++];if((v&128)>0||(F&128)>0){r-=14;return}if(J<15)return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v,F);let U=E0[r++];if((U&128)>0){r-=15;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U)}}}}}function cH0(){let J=E0[r++],$;if(J<192)$=J-160;else switch(J){case 217:$=E0[r++];break;case 218:$=J8.getUint16(r),r+=2;break;case 219:$=J8.getUint32(r),r+=4;break;default:throw Error("Expected string")}return iZ($)}function ph(J){return _8.copyBuffers?Uint8Array.prototype.slice.call(E0,r,r+=J):E0.subarray(r,r+=J)}function pZ(J){let $=E0[r++];if(Q9[$]){let X;return Q9[$](E0.subarray(r,X=r+=J),(Y)=>{r=Y;try{return y6()}finally{r=X}})}else throw Error("Unknown extension type "+$)}var _H0=Array(4096);function dH0(){let J=E0[r++];if(J>=160&&J<192){if(J=J-160,E7>=r)return cY.slice(r-b9,(r+=J)-b9);else if(!(E7==0&&y9<180))return mO(J)}else return r--,iH0(y6());let $=(J<<5^(J>1?J8.getUint16(r):J>0?E0[r]:0))&4095,X=_H0[$],Y=r,Q=r+J-3,W,K=0;if(X&&X.bytes==J){while(Y<Q){if(W=J8.getUint32(Y),W!=X[K++]){Y=1879048192;break}Y+=4}Q+=3;while(Y<Q)if(W=E0[Y++],W!=X[K++]){Y=1879048192;break}if(Y===Q)return r=Y,X.string;Q-=3,Y=r}X=[],_H0[$]=X,X.bytes=J;while(Y<Q)W=J8.getUint32(Y),X.push(W),Y+=4;Q+=3;while(Y<Q)W=E0[Y++],X.push(W);let Z=J<16?th(J):pH0(J);if(Z!=null)return X.string=Z;return X.string=mO(J)}function iH0(J){if(typeof J==="string")return J;if(typeof J==="number"||typeof J==="boolean"||typeof J==="bigint")return J.toString();if(J==null)return J+"";if(_8.allowArraysInMapKeys&&Array.isArray(J)&&J.flat().every(($)=>["string","number","boolean","bigint"].includes(typeof $)))return J.flat().toString();throw Error(`Invalid property type for record: ${typeof J}`)}var hH0=(J,$)=>{let X=y6().map(iH0),Y=J;if($!==void 0)J=J<32?-(($<<5)+J):($<<5)+J,X.highByte=$;let Q=G8[J];if(Q&&(Q.isShared||TW))(G8.restoreStructures||(G8.restoreStructures=[]))[J]=Q;return G8[J]=X,X.read=rh(X,Y),X.read()};Q9[0]=()=>{};Q9[0].noBuffer=!0;Q9[66]=(J)=>{let $=J.length,X=BigInt(J[0]&128?J[0]-256:J[0]);for(let Y=1;Y<$;Y++)X<<=BigInt(8),X+=BigInt(J[Y]);return X};var Y$8={Error,TypeError,ReferenceError};Q9[101]=()=>{let J=y6();return(Y$8[J[0]]||Error)(J[1],{cause:J[2]})};Q9[105]=(J)=>{if(_8.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=J8.getUint32(r-4);if(!_Y)_Y=new Map;let X=E0[r],Y;if(X>=144&&X<160||X==220||X==221)Y=[];else if(X>=128&&X<144||X==222||X==223)Y=new Map;else if((X>=199&&X<=201||X>=212&&X<=216)&&E0[r+1]===115)Y=new Set;else Y={};let Q={target:Y};_Y.set($,Q);let W=y6();if(!Q.used)return Q.target=W;else Object.assign(Y,W);if(Y instanceof Map)for(let[K,Z]of W.entries())Y.set(K,Z);if(Y instanceof Set)for(let K of Array.from(W))Y.add(K);return Y};Q9[112]=(J)=>{if(_8.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=J8.getUint32(r-4),X=_Y.get($);return X.used=!0,X.target};Q9[115]=()=>new Set(y6());var eh=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((J)=>J+"Array"),Q$8=typeof globalThis==="object"?globalThis:window;Q9[116]=(J)=>{let $=J[0],X=Uint8Array.prototype.slice.call(J,1).buffer,Y=eh[$];if(!Y){if($===16)return X;if($===17)return new DataView(X);throw Error("Could not find typed array for code "+$)}return new Q$8[Y](X)};Q9[120]=()=>{let J=y6();return new RegExp(J[0],J[1])};var W$8=[];Q9[98]=(J)=>{let $=(J[0]<<24)+(J[1]<<16)+(J[2]<<8)+J[3],X=r;return r+=$-J.length,Y5=W$8,Y5=[cH0(),cH0()],Y5.position0=0,Y5.position1=0,Y5.postBundlePosition=r,r=X,y6()};Q9[255]=(J)=>{if(J.length==4)return new Date((J[0]*16777216+(J[1]<<16)+(J[2]<<8)+J[3])*1000);else if(J.length==8)return new Date(((J[0]<<22)+(J[1]<<14)+(J[2]<<6)+(J[3]>>2))/1e6+((J[3]&3)*4294967296+J[4]*16777216+(J[5]<<16)+(J[6]<<8)+J[7])*1000);else if(J.length==12)return new Date(((J[0]<<24)+(J[1]<<16)+(J[2]<<8)+J[3])/1e6+((J[4]&128?-281474976710656:0)+J[6]*1099511627776+J[7]*4294967296+J[8]*16777216+(J[9]<<16)+(J[10]<<8)+J[11])*1000);else return new Date("invalid")};function nH0(J){if(ah)ah();let $=y9,X=r,Y=OU,Q=b9,W=E7,K=cY,Z=dZ,G=_Y,V=Y5,q=new Uint8Array(E0.slice(0,y9)),z=G8,H=G8.slice(0,G8.length),v=_8,F=TW,U=J();return y9=$,r=X,OU=Y,b9=Q,E7=W,cY=K,dZ=Z,_Y=G,Y5=V,E0=q,TW=F,G8=z,G8.splice(0,G8.length,...H),_8=v,J8=new DataView(E0.buffer,E0.byteOffset,E0.byteLength),U}function uO(){E0=null,_Y=null,G8=null}var nZ=Array(147);for(let J=0;J<256;J++)nZ[J]=+("1e"+Math.floor(45.15-J*0.30103));var pO=new hY({useRecords:!1}),K$8=pO.unpack,Z$8=pO.unpackMultiple,G$8=pO.unpack,RU={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},V$8=new Float32Array(1),RZ5=new Uint8Array(V$8.buffer,0,4);function aH0(J,$,X){ih=J,nh=$,ah=X}var iO;try{iO=new TextEncoder}catch(J){}var Xf,rH0,xU=typeof Buffer<"u",dO=xU?function(J){return Buffer.allocUnsafeSlow(J)}:Uint8Array,tH0=xU?Buffer:Uint8Array,sH0=xU?4294967296:2144337920,q0,DU,u8,X0=0,C4,v6=null,eH0,q$8=21760,H$8=/[\u0080-\uFFFF]/,r$=Symbol("record-id");class aZ extends hY{constructor(J){super(J);this.offset=0;let $,X,Y,Q,W,K=tH0.prototype.utf8Write?function(k,E){return q0.utf8Write(k,E,q0.byteLength-E)}:iO&&iO.encodeInto?function(k,E){return iO.encodeInto(k,q0.subarray(E)).written}:!1,Z=this;if(!J)J={};let G=J&&J.sequential,V=J.structures||J.saveStructures,q=J.maxSharedStructures;if(q==null)q=V?32:0;if(q>8160)throw Error("Maximum maxSharedStructure is 8160");if(J.structuredClone&&J.moreTypes==null)this.moreTypes=!0;let z=J.maxOwnStructures;if(z==null)z=V?32:64;if(!this.structures&&J.useRecords!=!1)this.structures=[];let H=q>32||z+q>64,v=q+64,F=q+z+64;if(F>8256)throw Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let U=[],j=0,B=0;this.pack=this.encode=function(k,E){if(!q0)q0=new dO(8192),u8=q0.dataView||(q0.dataView=new DataView(q0.buffer,0,8192)),X0=0;if(C4=q0.length-10,C4-X0<2048)q0=new dO(q0.length),u8=q0.dataView||(q0.dataView=new DataView(q0.buffer,0,q0.length)),C4=q0.length-10,X0=0;else X0=X0+7&2147483640;if(X=X0,E&w$8)X0+=E&255;if(W=Z.structuredClone?new Map:null,Z.bundleStrings&&typeof k!=="string")v6=[],v6.size=1/0;else v6=null;if(Q=Z.structures,Q){if(Q.uninitialized)Q=Z._mergeStructures(Z.getStructures());let A=Q.sharedLength||0;if(A>q)throw Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+Q.sharedLength);if(!Q.transitions){Q.transitions=Object.create(null);for(let h=0;h<A;h++){let _=Q[h];if(!_)continue;let m,p=Q.transitions;for(let g=0,J0=_.length;g<J0;g++){let u=_[g];if(m=p[u],!m)m=p[u]=Object.create(null);p=m}p[r$]=h+64}this.lastNamedStructuresLength=A}if(!G)Q.nextId=A+64}if(Y)Y=!1;let c;try{if(Z.randomAccessStructure&&k&&k.constructor&&k.constructor===Object)I(k);else R(k);let A=v6;if(v6)oH0(X,R,0);if(W&&W.idsToInsert){let h=W.idsToInsert.sort((g,J0)=>g.offset>J0.offset?1:-1),_=h.length,m=-1;while(A&&_>0){let g=h[--_].offset+X;if(g<A.stringsPosition+X&&m===-1)m=0;if(g>A.position+X){if(m>=0)m+=6}else{if(m>=0)u8.setUint32(A.position+X,u8.getUint32(A.position+X)+m),m=-1;A=A.previous,_++}}if(m>=0&&A)u8.setUint32(A.position+X,u8.getUint32(A.position+X)+m);if(X0+=h.length*6,X0>C4)T(X0);Z.offset=X0;let p=v$8(q0.subarray(X,X0),h);return W=null,p}if(Z.offset=X0,E&j$8)return q0.start=X,q0.end=X0,q0;return q0.subarray(X,X0)}catch(A){throw c=A,A}finally{if(Q){if(w(),Y&&Z.saveStructures){let A=Q.sharedLength||0,h=q0.subarray(X,X0),_=Jz0(Q,Z);if(!c){if(Z.saveStructures(_,_.isCompatible)===!1)return Z.pack(k,E);if(Z.lastNamedStructuresLength=A,q0.length>1073741824)q0=null;return h}}}if(q0.length>1073741824)q0=null;if(E&B$8)X0=X}};let w=()=>{if(B<10)B++;let k=Q.sharedLength||0;if(Q.length>k&&!G)Q.length=k;if(j>1e4){if(Q.transitions=null,B=0,j=0,U.length>0)U=[]}else if(U.length>0&&!G){for(let E=0,c=U.length;E<c;E++)U[E][r$]=0;U=[]}},M=(k)=>{var E=k.length;if(E<16)q0[X0++]=144|E;else if(E<65536)q0[X0++]=220,q0[X0++]=E>>8,q0[X0++]=E&255;else q0[X0++]=221,u8.setUint32(X0,E),X0+=4;for(let c=0;c<E;c++)R(k[c])},R=(k)=>{if(X0>C4)q0=T(X0);var E=typeof k,c;if(E==="string"){let A=k.length;if(v6&&A>=4&&A<4096){if((v6.size+=A)>q$8){let p,g=(v6[0]?v6[0].length*3+v6[1].length:0)+10;if(X0+g>C4)q0=T(X0+g);let J0;if(v6.position)J0=v6,q0[X0]=200,X0+=3,q0[X0++]=98,p=X0-X,X0+=4,oH0(X,R,0),u8.setUint16(p+X-3,X0-X-p);else q0[X0++]=214,q0[X0++]=98,p=X0-X,X0+=4;v6=["",""],v6.previous=J0,v6.size=0,v6.position=p}let m=H$8.test(k);v6[m?0:1]+=k,q0[X0++]=193,R(m?-A:A);return}let h;if(A<32)h=1;else if(A<256)h=2;else if(A<65536)h=3;else h=5;let _=A*3;if(X0+_>C4)q0=T(X0+_);if(A<64||!K){let m,p,g,J0=X0+h;for(m=0;m<A;m++)if(p=k.charCodeAt(m),p<128)q0[J0++]=p;else if(p<2048)q0[J0++]=p>>6|192,q0[J0++]=p&63|128;else if((p&64512)===55296&&((g=k.charCodeAt(m+1))&64512)===56320)p=65536+((p&1023)<<10)+(g&1023),m++,q0[J0++]=p>>18|240,q0[J0++]=p>>12&63|128,q0[J0++]=p>>6&63|128,q0[J0++]=p&63|128;else q0[J0++]=p>>12|224,q0[J0++]=p>>6&63|128,q0[J0++]=p&63|128;c=J0-X0-h}else c=K(k,X0+h);if(c<32)q0[X0++]=160|c;else if(c<256){if(h<2)q0.copyWithin(X0+2,X0+1,X0+1+c);q0[X0++]=217,q0[X0++]=c}else if(c<65536){if(h<3)q0.copyWithin(X0+3,X0+2,X0+2+c);q0[X0++]=218,q0[X0++]=c>>8,q0[X0++]=c&255}else{if(h<5)q0.copyWithin(X0+5,X0+3,X0+3+c);q0[X0++]=219,u8.setUint32(X0,c),X0+=4}X0+=c}else if(E==="number")if(k>>>0===k)if(k<32||k<128&&this.useRecords===!1||k<64&&!this.randomAccessStructure)q0[X0++]=k;else if(k<256)q0[X0++]=204,q0[X0++]=k;else if(k<65536)q0[X0++]=205,q0[X0++]=k>>8,q0[X0++]=k&255;else q0[X0++]=206,u8.setUint32(X0,k),X0+=4;else if(k>>0===k)if(k>=-32)q0[X0++]=256+k;else if(k>=-128)q0[X0++]=208,q0[X0++]=k+256;else if(k>=-32768)q0[X0++]=209,u8.setInt16(X0,k),X0+=2;else q0[X0++]=210,u8.setInt32(X0,k),X0+=4;else{let A;if((A=this.useFloat32)>0&&k<4294967296&&k>=-2147483648){q0[X0++]=202,u8.setFloat32(X0,k);let h;if(A<4||(h=k*nZ[(q0[X0]&127)<<1|q0[X0+1]>>7])>>0===h){X0+=4;return}else X0--}q0[X0++]=203,u8.setFloat64(X0,k),X0+=8}else if(E==="object"||E==="function")if(!k)q0[X0++]=192;else{if(W){let h=W.get(k);if(h){if(!h.id){let _=W.idsToInsert||(W.idsToInsert=[]);h.id=_.push(h)}q0[X0++]=214,q0[X0++]=112,u8.setUint32(X0,h.id),X0+=4;return}else W.set(k,{offset:X0-X})}let A=k.constructor;if(A===Object)x(k);else if(A===Array)M(k);else if(A===Map)if(this.mapAsEmptyObject)q0[X0++]=128;else{if(c=k.size,c<16)q0[X0++]=128|c;else if(c<65536)q0[X0++]=222,q0[X0++]=c>>8,q0[X0++]=c&255;else q0[X0++]=223,u8.setUint32(X0,c),X0+=4;for(let[h,_]of k)R(h),R(_)}else{for(let h=0,_=Xf.length;h<_;h++){let m=rH0[h];if(k instanceof m){let p=Xf[h];if(p.write){if(p.type)q0[X0++]=212,q0[X0++]=p.type,q0[X0++]=0;let y=p.write.call(this,k);if(y===k)if(Array.isArray(k))M(k);else x(k);else R(y);return}let g=q0,J0=u8,u=X0;q0=null;let f;try{f=p.pack.call(this,k,(y)=>{if(q0=g,g=null,X0+=y,X0>C4)T(X0);return{target:q0,targetView:u8,position:X0-y}},R)}finally{if(g)q0=g,u8=J0,X0=u,C4=q0.length-10}if(f){if(f.length+X0>C4)T(f.length+X0);X0=z$8(f,q0,X0,p.type)}return}}if(Array.isArray(k))M(k);else{if(k.toJSON){let h=k.toJSON();if(h!==k)return R(h)}if(E==="function")return R(this.writeFunction&&this.writeFunction(k));x(k)}}}else if(E==="boolean")q0[X0++]=k?195:194;else if(E==="bigint"){if(k<9223372036854776000&&k>=-9223372036854776000)q0[X0++]=211,u8.setBigInt64(X0,k);else if(k<18446744073709552000&&k>0)q0[X0++]=207,u8.setBigUint64(X0,k);else if(this.largeBigIntToFloat)q0[X0++]=203,u8.setFloat64(X0,Number(k));else if(this.largeBigIntToString)return R(k.toString());else if((this.useBigIntExtension||this.moreTypes)&&k<BigInt(2)**BigInt(1023)&&k>-(BigInt(2)**BigInt(1023))){q0[X0++]=199,X0++,q0[X0++]=66;let A=[],h;do{let _=k&BigInt(255);h=(_&BigInt(128))===(k<BigInt(0)?BigInt(128):BigInt(0)),A.push(_),k>>=BigInt(8)}while(!((k===BigInt(0)||k===BigInt(-1))&&h));q0[X0-2]=A.length;for(let _=A.length;_>0;)q0[X0++]=Number(A[--_]);return}else throw RangeError(k+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string");X0+=8}else if(E==="undefined")if(this.encodeUndefinedAsNil)q0[X0++]=192;else q0[X0++]=212,q0[X0++]=0,q0[X0++]=0;else throw Error("Unknown type: "+E)},N=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?(k)=>{let E;if(this.skipValues){E=[];for(let h in k)if((typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(h))&&!this.skipValues.includes(k[h]))E.push(h)}else E=Object.keys(k);let c=E.length;if(c<16)q0[X0++]=128|c;else if(c<65536)q0[X0++]=222,q0[X0++]=c>>8,q0[X0++]=c&255;else q0[X0++]=223,u8.setUint32(X0,c),X0+=4;let A;if(this.coercibleKeyAsNumber)for(let h=0;h<c;h++){A=E[h];let _=Number(A);R(isNaN(_)?A:_),R(k[A])}else for(let h=0;h<c;h++)R(A=E[h]),R(k[A])}:(k)=>{q0[X0++]=222;let E=X0-X;X0+=2;let c=0;for(let A in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(A))R(A),R(k[A]),c++;if(c>65535)throw Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');q0[E+++X]=c>>8,q0[E+X]=c&255},L=this.useRecords===!1?N:J.progressiveRecords&&!H?(k)=>{let E,c=Q.transitions||(Q.transitions=Object.create(null)),A=X0++-X,h;for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_)){if(E=c[_],E)c=E;else{let m=Object.keys(k),p=c;c=Q.transitions;let g=0;for(let J0=0,u=m.length;J0<u;J0++){let f=m[J0];if(E=c[f],!E)E=c[f]=Object.create(null),g++;c=E}if(A+X+1==X0)X0--,S(c,m,g);else C(c,m,A,g);h=!0,c=p[_]}R(k[_])}if(!h){let _=c[r$];if(_)q0[A+X]=_;else C(c,Object.keys(k),A,0)}}:(k)=>{let E,c=Q.transitions||(Q.transitions=Object.create(null)),A=0;for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_)){if(E=c[_],!E)E=c[_]=Object.create(null),A++;c=E}let h=c[r$];if(h)if(h>=96&&H)q0[X0++]=((h-=96)&31)+96,q0[X0++]=h>>5;else q0[X0++]=h;else S(c,c.__keys__||Object.keys(k),A);for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_))R(k[_])},O=typeof this.useRecords=="function"&&this.useRecords,x=O?(k)=>{O(k)?L(k):N(k)}:L,T=(k)=>{let E;if(k>16777216){if(k-X>sH0)throw Error("Packed buffer would be larger than maximum buffer size");E=Math.min(sH0,Math.round(Math.max((k-X)*(k>67108864?1.25:2),4194304)/4096)*4096)}else E=(Math.max(k-X<<2,q0.length-1)>>12)+1<<12;let c=new dO(E);if(u8=c.dataView||(c.dataView=new DataView(c.buffer,0,E)),k=Math.min(k,q0.length),q0.copy)q0.copy(c,0,X,k);else c.set(q0.slice(X,k));return X0-=X,X=0,C4=c.length-10,q0=c},S=(k,E,c)=>{let A=Q.nextId;if(!A)A=64;if(A<v&&this.shouldShareStructure&&!this.shouldShareStructure(E)){if(A=Q.nextOwnId,!(A<F))A=v;Q.nextOwnId=A+1}else{if(A>=F)A=v;Q.nextId=A+1}let h=E.highByte=A>=96&&H?A-96>>5:-1;if(k[r$]=A,k.__keys__=E,Q[A-64]=E,A<v)if(E.isShared=!0,Q.sharedLength=A-63,Y=!0,h>=0)q0[X0++]=(A&31)+96,q0[X0++]=h;else q0[X0++]=A;else{if(h>=0)q0[X0++]=213,q0[X0++]=114,q0[X0++]=(A&31)+96,q0[X0++]=h;else q0[X0++]=212,q0[X0++]=114,q0[X0++]=A;if(c)j+=B*c;if(U.length>=z)U.shift()[r$]=0;U.push(k),R(E)}},C=(k,E,c,A)=>{let h=q0,_=X0,m=C4,p=X;if(q0=DU,X0=0,X=0,!q0)DU=q0=new dO(8192);C4=q0.length-10,S(k,E,A),DU=q0;let g=X0;if(q0=h,X0=_,C4=m,X=p,g>1){let J0=X0+g-1;if(J0>C4)T(J0);let u=c+X;q0.copyWithin(u+g,u+1,X0),q0.set(DU.slice(0,g),u),X0=J0}else q0[c+X]=DU[0]},I=(k)=>{let E=eH0(k,q0,X,X0,Q,T,(c,A,h)=>{if(h)return Y=!0;X0=A;let _=q0;if(R(c),w(),_!==q0)return{position:X0,targetView:u8,target:q0};return X0},this);if(E===0)return x(k);X0=E}}useBuffer(J){q0=J,q0.dataView||(q0.dataView=new DataView(q0.buffer,q0.byteOffset,q0.byteLength)),X0=0}set position(J){X0=J}get position(){return X0}clearSharedData(){if(this.structures)this.structures=[];if(this.typedStructs)this.typedStructs=[]}}rH0=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,lO];Xf=[{pack(J,$,X){let Y=J.getTime()/1000;if((this.useTimestamp32||J.getMilliseconds()===0)&&Y>=0&&Y<4294967296){let{target:Q,targetView:W,position:K}=$(6);Q[K++]=214,Q[K++]=255,W.setUint32(K,Y)}else if(Y>0&&Y<4294967296){let{target:Q,targetView:W,position:K}=$(10);Q[K++]=215,Q[K++]=255,W.setUint32(K,J.getMilliseconds()*4000000+(Y/1000/4294967296>>0)),W.setUint32(K+4,Y)}else if(isNaN(Y)){if(this.onInvalidDate)return $(0),X(this.onInvalidDate());let{target:Q,targetView:W,position:K}=$(3);Q[K++]=212,Q[K++]=255,Q[K++]=255}else{let{target:Q,targetView:W,position:K}=$(15);Q[K++]=199,Q[K++]=12,Q[K++]=255,W.setUint32(K,J.getMilliseconds()*1e6),W.setBigInt64(K+4,BigInt(Math.floor(Y)))}}},{pack(J,$,X){if(this.setAsEmptyObject)return $(0),X({});let Y=Array.from(J),{target:Q,position:W}=$(this.moreTypes?3:0);if(this.moreTypes)Q[W++]=212,Q[W++]=115,Q[W++]=0;X(Y)}},{pack(J,$,X){let{target:Y,position:Q}=$(this.moreTypes?3:0);if(this.moreTypes)Y[Q++]=212,Y[Q++]=101,Y[Q++]=0;X([J.name,J.message,J.cause])}},{pack(J,$,X){let{target:Y,position:Q}=$(this.moreTypes?3:0);if(this.moreTypes)Y[Q++]=212,Y[Q++]=120,Y[Q++]=0;X([J.source,J.flags])}},{pack(J,$){if(this.moreTypes)Jf(J,16,$);else $f(xU?Buffer.from(J):new Uint8Array(J),$)}},{pack(J,$){let X=J.constructor;if(X!==tH0&&this.moreTypes)Jf(J,eh.indexOf(X.name),$);else $f(J,$)}},{pack(J,$){if(this.moreTypes)Jf(J,17,$);else $f(xU?Buffer.from(J):new Uint8Array(J),$)}},{pack(J,$){let{target:X,position:Y}=$(1);X[Y]=193}}];function Jf(J,$,X,Y){let Q=J.byteLength;if(Q+1<256){var{target:W,position:K}=X(4+Q);W[K++]=199,W[K++]=Q+1}else if(Q+1<65536){var{target:W,position:K}=X(5+Q);W[K++]=200,W[K++]=Q+1>>8,W[K++]=Q+1&255}else{var{target:W,position:K,targetView:Z}=X(7+Q);W[K++]=201,Z.setUint32(K,Q+1),K+=4}if(W[K++]=116,W[K++]=$,!J.buffer)J=new Uint8Array(J);W.set(new Uint8Array(J.buffer,J.byteOffset,J.byteLength),K)}function $f(J,$){let X=J.byteLength;var Y,Q;if(X<256){var{target:Y,position:Q}=$(X+2);Y[Q++]=196,Y[Q++]=X}else if(X<65536){var{target:Y,position:Q}=$(X+3);Y[Q++]=197,Y[Q++]=X>>8,Y[Q++]=X&255}else{var{target:Y,position:Q,targetView:W}=$(X+5);Y[Q++]=198,W.setUint32(Q,X),Q+=4}Y.set(J,Q)}function z$8(J,$,X,Y){let Q=J.length;switch(Q){case 1:$[X++]=212;break;case 2:$[X++]=213;break;case 4:$[X++]=214;break;case 8:$[X++]=215;break;case 16:$[X++]=216;break;default:if(Q<256)$[X++]=199,$[X++]=Q;else if(Q<65536)$[X++]=200,$[X++]=Q>>8,$[X++]=Q&255;else $[X++]=201,$[X++]=Q>>24,$[X++]=Q>>16&255,$[X++]=Q>>8&255,$[X++]=Q&255}return $[X++]=Y,$.set(J,X),X+=Q,X}function v$8(J,$){let X,Y=$.length*6,Q=J.length-Y;while(X=$.pop()){let{offset:W,id:K}=X;J.copyWithin(W+Y,W,Q),Y-=6;let Z=W+Y;J[Z++]=214,J[Z++]=105,J[Z++]=K>>24,J[Z++]=K>>16&255,J[Z++]=K>>8&255,J[Z++]=K&255,Q=W}return J}function oH0(J,$,X){if(v6.length>0){u8.setUint32(v6.position+J,X0+X-v6.position-J),v6.stringsPosition=X0-J;let Y=v6;v6=null,$(Y[0]),$(Y[1])}}function Jz0(J,$){return J.isCompatible=(X)=>{let Y=!X||($.lastNamedStructuresLength||0)===X.length;if(!Y)$._mergeStructures(X);return Y},J}function $z0(J,$){eH0=J,Jz0=$}var Xz0=new aZ({useRecords:!1}),F$8=Xz0.pack,U$8=Xz0.pack;var j$8=512,B$8=1024,w$8=2048;var Yf=3,Iq=0,PU=2,nO=1,Wf=16,Qz0=["num","object","string","ascii"];Qz0[Wf]="date";var M$8=[!1,!0,!0,!1,!1,!0,!0,!1],Wz0;try{Function(""),Wz0=!0}catch(J){}var sZ,N$8=typeof Buffer<"u",aO,t$;try{aO=new TextEncoder}catch(J){}var O$8=N$8?function(J,$,X){return J.utf8Write($,X,J.byteLength-X)}:aO&&aO.encodeInto?function(J,$,X){return aO.encodeInto($,J.subarray(X)).written}:!1,SZ5=Symbol("type"),AZ5=Symbol("parent");$z0(Kz0,C$8);function Kz0(J,$,X,Y,Q,W,K,Z){let G=Z.typedStructs||(Z.typedStructs=[]),V=$.dataView,q=(G.lastStringStart||100)+Y,z=$.length-10,H=Y;if(Y>z)$=W(Y),V=$.dataView,Y-=X,H-=X,q-=X,X=0,z=$.length-10;let v,F=q,U=G.transitions||(G.transitions=Object.create(null)),j=G.nextId||G.length,B=j<15?1:j<240?2:j<61440?3:j<15728640?4:0;if(B===0)return 0;Y+=B;let w=[],M,R=0;for(let L in J){let O=J[L],x=U[L];if(!x)U[L]=x={key:L,parent:U,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null};if(Y>z)$=W(Y),V=$.dataView,Y-=X,H-=X,q-=X,F-=X,X=0,z=$.length-10;switch(typeof O){case"number":let T=O;if(j<200||!x.num64){if(T>>0===T&&T<536870912&&T>-520093696){if(T<246&&T>=0&&(x.num8&&!(j>200&&x.num32)||T<32&&!x.num32))U=x.num8||W9(x,Iq,1),$[Y++]=T;else U=x.num32||W9(x,Iq,4),V.setUint32(Y,T,!0),Y+=4;break}else if(T<4294967296&&T>=-2147483648){if(V.setFloat32(Y,T,!0),M$8[$[Y+3]>>>5]){let k;if((k=T*nZ[($[Y+3]&127)<<1|$[Y+2]>>7])>>0===k){U=x.num32||W9(x,Iq,4),Y+=4;break}}}}U=x.num64||W9(x,Iq,8),V.setFloat64(Y,T,!0),Y+=8;break;case"string":let S=O.length;if(v=F-q,(S<<2)+F>z)$=W((S<<2)+F),V=$.dataView,Y-=X,H-=X,q-=X,F-=X,X=0,z=$.length-10;if(S>65280+v>>2){w.push(L,O,Y-H);break}let C,I=F;if(S<64){let k,E,c;for(k=0;k<S;k++)if(E=O.charCodeAt(k),E<128)$[F++]=E;else if(E<2048)C=!0,$[F++]=E>>6|192,$[F++]=E&63|128;else if((E&64512)===55296&&((c=O.charCodeAt(k+1))&64512)===56320)C=!0,E=65536+((E&1023)<<10)+(c&1023),k++,$[F++]=E>>18|240,$[F++]=E>>12&63|128,$[F++]=E>>6&63|128,$[F++]=E&63|128;else C=!0,$[F++]=E>>12|224,$[F++]=E>>6&63|128,$[F++]=E&63|128}else F+=O$8($,O,F),C=F-I>S;if(v<160||v<246&&(x.ascii8||x.string8)){if(C){if(!(U=x.string8))if(G.length>10&&(U=x.ascii8))U.__type=PU,x.ascii8=null,x.string8=U,K(null,0,!0);else U=W9(x,PU,1)}else if(v===0&&!M){M=!0,U=x.ascii0||W9(x,Yf,0);break}else if(!(U=x.ascii8)&&!(G.length>10&&(U=x.string8)))U=W9(x,Yf,1);$[Y++]=v}else U=x.string16||W9(x,PU,2),V.setUint16(Y,v,!0),Y+=2;break;case"object":if(O){if(O.constructor===Date)U=x.date64||W9(x,Wf,8),V.setFloat64(Y,O.getTime(),!0),Y+=8;else w.push(L,O,R);break}else if(x=Yz0(x,Y,V,-10),x)U=x,Y=sZ;else w.push(L,O,R);break;case"boolean":U=x.num8||x.ascii8||W9(x,Iq,1),$[Y++]=O?249:248;break;case"undefined":if(x=Yz0(x,Y,V,-9),x)U=x,Y=sZ;else w.push(L,O,R);break;default:w.push(L,O,R)}R++}for(let L=0,O=w.length;L<O;){let x=w[L++],T=w[L++],S=w[L++],C=U[x];if(!C)U[x]=C={key:x,parent:U,enumerationOffset:S-R,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null};let I;if(T){let k;if(v=F-q,v<65280)if(U=C.object16,U)k=2;else if(U=C.object32)k=4;else U=W9(C,nO,2),k=2;else U=C.object32||W9(C,nO,4),k=4;if(I=K(T,F),typeof I==="object")F=I.position,V=I.targetView,$=I.target,q-=X,Y-=X,H-=X,X=0;else F=I;if(k===2)V.setUint16(Y,v,!0),Y+=2;else V.setUint32(Y,v,!0),Y+=4}else U=C.object16||W9(C,nO,2),V.setInt16(Y,T===null?-10:-9,!0),Y+=2;R++}let N=U[r$];if(N==null){N=Z.typedStructs.length;let L=[],O=U,x,T;while((T=O.__type)!==void 0){let S=O.__size;O=O.__parent,x=O.key;let C=[T,S,x];if(O.enumerationOffset)C.push(O.enumerationOffset);L.push(C),O=O.parent}L.reverse(),U[r$]=N,Z.typedStructs[N]=L,K(null,0,!0)}switch(B){case 1:if(N>=16)return 0;$[H]=N+32;break;case 2:if(N>=256)return 0;$[H]=56,$[H+1]=N;break;case 3:if(N>=65536)return 0;$[H]=57,V.setUint16(H+1,N,!0);break;case 4:if(N>=16777216)return 0;V.setUint32(H,(N<<8)+58,!0);break}if(Y<q){if(q===F)return Y;$.copyWithin(Y,q,F),F+=Y-q,G.lastStringStart=Y-H}else if(Y>q){if(q===F)return Y;return G.lastStringStart=Y-H,Kz0(J,$,X,H,Q,W,K,Z)}return F}function Yz0(J,$,X,Y){let Q;if(Q=J.ascii8||J.num8)return X.setInt8($,Y,!0),sZ=$+1,Q;if(Q=J.string16||J.object16)return X.setInt16($,Y,!0),sZ=$+2,Q;if(Q=J.num32)return X.setUint32($,3758096640+Y,!0),sZ=$+4,Q;if(Q=J.num64)return X.setFloat64($,NaN,!0),X.setInt8($,Y),sZ=$+8,Q;sZ=$;return}function W9(J,$,X){let Y=Qz0[$]+(X<<3),Q=J[Y]||(J[Y]=Object.create(null));return Q.__type=$,Q.__size=X,Q.__parent=J,Q}function R$8(J){if(!(J instanceof Map))return J;let $=J.get("typed")||[];if(Object.isFrozen($))$=$.map((Q)=>Q.slice(0));let X=J.get("named"),Y=Object.create(null);for(let Q=0,W=$.length;Q<W;Q++){let K=$[Q],Z=Y;for(let[G,V,q]of K){let z=Z[q];if(!z)Z[q]=z={key:q,parent:Z,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null};Z=W9(z,G,V)}Z[r$]=Q}return $.transitions=Y,this.typedStructs=$,this.lastTypedStructuresLength=$.length,X}var Qf=Symbol.for("source");function D$8(J,$,X,Y){let Q=J[$++]-32;if(Q>=24)switch(Q){case 24:Q=J[$++];break;case 25:Q=J[$++]+(J[$++]<<8);break;case 26:Q=J[$++]+(J[$++]<<8)+(J[$++]<<16);break;case 27:Q=J[$++]+(J[$++]<<8)+(J[$++]<<16)+(J[$++]<<24);break}let W=Y.typedStructs&&Y.typedStructs[Q];if(!W){if(J=Uint8Array.prototype.slice.call(J,$,X),X-=$,$=0,!Y.getStructures)throw Error(`Reference to shared structure ${Q} without getStructures method`);if(Y._mergeStructures(Y.getStructures()),!Y.typedStructs)throw Error("Could not find any shared typed structures");if(Y.lastTypedStructuresLength=Y.typedStructs.length,W=Y.typedStructs[Q],!W)throw Error("Could not find typed structure "+Q)}var{construct:K,fullConstruct:Z}=W;if(!K){K=W.construct=function(){},Z=W.fullConstruct=function(){},Z.prototype=Y.structPrototype??{};var G=K.prototype=Y.structPrototype?Object.create(Y.structPrototype):{};let q=[],z=0,H;for(let v=0,F=W.length;v<F;v++){let U=W[v],[j,B,w,M]=U;if(w==="__proto__")w="__proto_";let R={key:w,offset:z};if(M)q.splice(v+M,0,R);else q.push(R);let N;switch(B){case 0:N=()=>0;break;case 1:N=(O,x)=>{let T=O.bytes[x+R.offset];return T>=246?Eq(T):T};break;case 2:N=(O,x)=>{let T=O.bytes,C=(T.dataView||(T.dataView=new DataView(T.buffer,T.byteOffset,T.byteLength))).getUint16(x+R.offset,!0);return C>=65280?Eq(C&255):C};break;case 4:N=(O,x)=>{let T=O.bytes,C=(T.dataView||(T.dataView=new DataView(T.buffer,T.byteOffset,T.byteLength))).getUint32(x+R.offset,!0);return C>=4294967040?Eq(C&255):C};break}R.getRef=N,z+=B;let L;switch(j){case Yf:if(H&&!H.next)H.next=R;H=R,R.multiGetCount=0,L=function(O){let{bytes:x,position:T}=O,S=z+T,C=N(O,T);if(typeof C!=="number")return C;let I,k=R.next;while(k){if(I=k.getRef(O,T),typeof I==="number")break;else I=null;k=k.next}if(I==null)I=O.bytesEnd-S;if(O.srcString)return O.srcString.slice(C,I);return gH0(x,C+S,I-C)};break;case PU:case nO:if(H&&!H.next)H.next=R;H=R,L=function(O){let x=O.position,T=z+x,S=N(O,x);if(typeof S!=="number")return S;let C=O.bytes,I,k=R.next;while(k){if(I=k.getRef(O,x),typeof I==="number")break;else I=null;k=k.next}if(I==null)I=O.bytesEnd-T;if(j===PU)return C.toString("utf8",S+T,I+T);else{t$=O;try{return Y.unpack(C,{start:S+T,end:I+T})}finally{t$=null}}};break;case Iq:switch(B){case 4:L=function(O){let x=O.bytes,T=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength)),S=O.position+R.offset,C=T.getInt32(S,!0);if(C<536870912){if(C>-520093696)return C;if(C>-536870912)return Eq(C&255)}let I=T.getFloat32(S,!0),k=nZ[(x[S+3]&127)<<1|x[S+2]>>7];return(k*I+(I>0?0.5:-0.5)>>0)/k};break;case 8:L=function(O){let x=O.bytes,S=(x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength))).getFloat64(O.position+R.offset,!0);if(isNaN(S)){let C=x[O.position+R.offset];if(C>=246)return Eq(C)}return S};break;case 1:L=function(O){let T=O.bytes[O.position+R.offset];return T<246?T:Eq(T)};break}break;case Wf:L=function(O){let x=O.bytes,T=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength));return new Date(T.getFloat64(O.position+R.offset,!0))};break}R.get=L}if(Wz0){let v=[],F=[],U=0,j;for(let w of q){if(Y.alwaysLazyProperty&&Y.alwaysLazyProperty(w.key)){j=!0;continue}Object.defineProperty(G,w.key,{get:x$8(w.get),enumerable:!0});let M="v"+U++;F.push(M),v.push("o["+JSON.stringify(w.key)+"]="+M+"(s)")}if(j)v.push("__proto__:this");let B=Function(...F,"var c=this;return function(s){var o=new c();"+v.join(";")+";return o;}").apply(Z,q.map((w)=>w.get));Object.defineProperty(G,"toJSON",{value(w){return B.call(this,this[Qf])}})}else Object.defineProperty(G,"toJSON",{value(v){let F={};for(let U=0,j=q.length;U<j;U++){let B=q[U].key;F[B]=this[B]}return F}})}var V=new K;return V[Qf]={bytes:J,position:$,srcString:"",bytesEnd:X},V}function Eq(J){switch(J){case 246:return null;case 247:return;case 248:return!1;case 249:return!0}throw Error("Unknown constant")}function x$8(J){return function(){return J(this[Qf])}}function P$8(){if(t$)t$.bytes=Uint8Array.prototype.slice.call(t$.bytes,t$.position,t$.bytesEnd),t$.position=0,t$.bytesEnd=t$.bytes.length}function C$8(J,$){if($.typedStructs){let Y=new Map;Y.set("named",J),Y.set("typed",$.typedStructs),J=Y}let X=$.lastTypedStructuresLength||0;return J.isCompatible=(Y)=>{let Q=!0;if(Y instanceof Map){if((Y.get("named")||[]).length!==($.lastNamedStructuresLength||0))Q=!1;if((Y.get("typed")||[]).length!==X)Q=!1}else if(Y instanceof Array||Array.isArray(Y)){if(Y.length!==($.lastNamedStructuresLength||0))Q=!1}if(!Q)$._mergeStructures(Y);return Q},$.lastTypedStructuresLength=$.typedStructs&&$.typedStructs.length,J}aH0(D$8,R$8,P$8);var b$8=process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED!==void 0&&process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase()==="true";if(!b$8){let J;try{if(J=Rz0(),J)lH0(J.extractStrings)}catch($){}}var hp={};DQ(hp,{zodErrorsIntegration:()=>_b,wrapMcpServerWithSentry:()=>mb,withScope:()=>g9,withMonitor:()=>$X,withIsolationScope:()=>uY,withActiveSpan:()=>mW,vercelAIIntegration:()=>OP,validateOpenTelemetrySetup:()=>_p,updateSpanName:()=>Tf,trpcMiddleware:()=>fb,tediousIntegration:()=>jP,suppressTracing:()=>lU,supabaseIntegration:()=>cb,startSpanManual:()=>uU,startSpan:()=>h7,startSession:()=>sU,startNewTrace:()=>sf,startInactiveSpan:()=>nf,spotlightIntegration:()=>HP,spanToTraceHeader:()=>SU,spanToJSON:()=>t0,spanToBaggageHeader:()=>hf,setupKoaErrorHandler:()=>_z1,setupHapiErrorHandler:()=>Vz1,setupFastifyErrorHandler:()=>OG1,setupExpressErrorHandler:()=>EZ1,setupConnectErrorHandler:()=>Qv1,setUser:()=>Wb,setTags:()=>Yb,setTag:()=>Qb,setNodeAsyncContextStrategy:()=>$x,setMeasurement:()=>pf,setHttpStatus:()=>yq,setExtras:()=>$b,setExtra:()=>Xb,setCurrentClient:()=>Lb,setContext:()=>Jb,rewriteFramesIntegration:()=>Ab,requestDataIntegration:()=>eU,redisIntegration:()=>sx,profiler:()=>hb,prismaIntegration:()=>$P,preloadOpenTelemetry:()=>FU1,postgresIntegration:()=>ex,parameterize:()=>RR,onUnhandledRejectionIntegration:()=>Lx,onUncaughtExceptionIntegration:()=>wx,nodeContextIntegration:()=>zx,nativeNodeFetchIntegration:()=>Vx,mysqlIntegration:()=>dx,mysql2Integration:()=>nx,mongooseIntegration:()=>gx,mongoIntegration:()=>ux,modulesIntegration:()=>Bx,makeNodeTransport:()=>kP,lruMemoizerIntegration:()=>mx,logger:()=>pb,localVariablesIntegration:()=>jx,linkedErrorsIntegration:()=>tU,lastEventId:()=>Kb,koaIntegration:()=>GP,knexIntegration:()=>Cv1,kafkaIntegration:()=>yx,isInitialized:()=>nU,instrumentSupabaseClient:()=>kR,initWithoutDefaultIntegrations:()=>jU1,initOpenTelemetry:()=>cP,init:()=>_P,inboundFiltersIntegration:()=>rU,httpIntegration:()=>Wx,hapiIntegration:()=>WP,graphqlIntegration:()=>bx,getTraceMetaTags:()=>Rb,getTraceData:()=>pY,getSpanStatusFromHttpCode:()=>bq,getSpanDescendants:()=>AU,getSentryRelease:()=>SP,getRootSpan:()=>i8,getIsolationScope:()=>w1,getGlobalScope:()=>mY,getDefaultIntegrationsWithoutPerformance:()=>Ap,getDefaultIntegrations:()=>cp,getCurrentScope:()=>b1,getClient:()=>A0,getAutoPerformanceIntegrations:()=>PP,getActiveSpan:()=>oJ,genericPoolIntegration:()=>BP,generateInstrumentOnce:()=>G1,functionToStringIntegration:()=>oU,fsIntegration:()=>EK1,flush:()=>Zb,fastifyIntegration:()=>cx,extraErrorDataIntegration:()=>Tb,expressIntegration:()=>xx,expressErrorHandler:()=>Yg,eventFiltersIntegration:()=>xR,endSession:()=>GG,disableAnrDetectionForCallback:()=>sK1,defaultStackParser:()=>AP,dedupeIntegration:()=>Cb,dataloaderIntegration:()=>wF1,cron:()=>OU1,createTransport:()=>iq,createSentryWinstonTransport:()=>gF1,createGetModuleFromFilename:()=>IP,continueTrace:()=>af,contextLinesIntegration:()=>vx,consoleLoggingIntegration:()=>lb,consoleIntegration:()=>J2,connectIntegration:()=>qP,close:()=>Gb,childProcessIntegration:()=>RP,captureSession:()=>qb,captureMessage:()=>dq,captureFeedback:()=>ub,captureException:()=>F8,captureEvent:()=>iU,captureConsoleIntegration:()=>Pb,captureCheckIn:()=>dU,anrIntegration:()=>aK1,amqplibIntegration:()=>MP,addIntegration:()=>Fb,addEventProcessor:()=>Vb,addBreadcrumb:()=>k4,SentryContextManager:()=>xP,Scope:()=>S5,SEMANTIC_ATTRIBUTE_SENTRY_SOURCE:()=>h8,SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE:()=>_7,SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN:()=>v1,SEMANTIC_ATTRIBUTE_SENTRY_OP:()=>X1,SDK_VERSION:()=>N6,NodeClient:()=>Dj});var pb={};DQ(pb,{warn:()=>LQ8,trace:()=>jQ8,info:()=>wQ8,fmt:()=>Nb,fatal:()=>NQ8,error:()=>MQ8,debug:()=>BQ8});import{format as UQ8}from"node:util";var x0=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;var N6="9.22.0";var e0=globalThis;function r5(){return kW(e0),e0}function kW(J){let $=J.__SENTRY__=J.__SENTRY__||{};return $.version=$.version||N6,$[N6]=$[N6]||{}}function oZ(J,$,X=e0){let Y=X.__SENTRY__=X.__SENTRY__||{},Q=Y[N6]=Y[N6]||{};return Q[J]||(Q[J]=$())}var Dz0=Object.prototype.toString;function dJ(J){switch(Dz0.call(J)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object WebAssembly.Exception]":return!0;default:return fY(J,Error)}}function rO(J,$){return Dz0.call(J)===`[object ${$}]`}function xz0(J){return rO(J,"ErrorEvent")}function rZ(J){return rO(J,"String")}function tZ(J){return typeof J==="object"&&J!==null&&"__sentry_template_string__"in J&&"__sentry_template_values__"in J}function CU(J){return J===null||tZ(J)||typeof J!=="object"&&typeof J!=="function"}function I7(J){return rO(J,"Object")}function Pz0(J){return typeof Event<"u"&&fY(J,Event)}function Cz0(J){return typeof Element<"u"&&fY(J,Element)}function Tz0(J){return rO(J,"RegExp")}function S7(J){return Boolean(J?.then&&typeof J.then==="function")}function kz0(J){return I7(J)&&"nativeEvent"in J&&"preventDefault"in J&&"stopPropagation"in J}function fY(J,$){try{return J instanceof $}catch(X){return!1}}function tO(J){return!!(typeof J==="object"&&J!==null&&(J.__isVue||J._isVue))}var y$8=e0,m$8=80;function Ez0(J,$={}){if(!J)return"<unknown>";try{let X=J,Y=5,Q=[],W=0,K=0,Z=" > ",G=Z.length,V,q=Array.isArray($)?$:$.keyAttrs,z=!Array.isArray($)&&$.maxStringLength||m$8;while(X&&W++<Y){if(V=u$8(X,q),V==="html"||W>1&&K+Q.length*G+V.length>=z)break;Q.push(V),K+=V.length,X=X.parentNode}return Q.reverse().join(Z)}catch(X){return"<unknown>"}}function u$8(J,$){let X=J,Y=[];if(!X?.tagName)return"";if(y$8.HTMLElement){if(X instanceof HTMLElement&&X.dataset){if(X.dataset.sentryComponent)return X.dataset.sentryComponent;if(X.dataset.sentryElement)return X.dataset.sentryElement}}Y.push(X.tagName.toLowerCase());let Q=$?.length?$.filter((K)=>X.getAttribute(K)).map((K)=>[K,X.getAttribute(K)]):null;if(Q?.length)Q.forEach((K)=>{Y.push(`[${K[0]}="${K[1]}"]`)});else{if(X.id)Y.push(`#${X.id}`);let K=X.className;if(K&&rZ(K)){let Z=K.split(/\s+/);for(let G of Z)Y.push(`.${G}`)}}let W=["aria-label","type","name","title","alt"];for(let K of W){let Z=X.getAttribute(K);if(Z)Y.push(`[${K}="${Z}"]`)}return Y.join("")}var l$8="Sentry Logger ",iJ=["debug","info","warn","error","log","assert","trace"],Sq={};function F6(J){if(!("console"in e0))return J();let $=e0.console,X={},Y=Object.keys(Sq);Y.forEach((Q)=>{let W=Sq[Q];X[Q]=$[Q],$[Q]=W});try{return J()}finally{Y.forEach((Q)=>{$[Q]=X[Q]})}}function g$8(){let J=!1,$={enable:()=>{J=!0},disable:()=>{J=!1},isEnabled:()=>J};if(x0)iJ.forEach((X)=>{$[X]=(...Y)=>{if(J)F6(()=>{e0.console[X](`${l$8}[${X}]:`,...Y)})}});else iJ.forEach((X)=>{$[X]=()=>{return}});return $}var t=oZ("logger",g$8);function K9(J,$=0){if(typeof J!=="string"||$===0)return J;return J.length<=$?J:`${J.slice(0,$)}...`}function vf(J,$){let X=J,Y=X.length;if(Y<=150)return X;if($>Y)$=Y;let Q=Math.max($-60,0);if(Q<5)Q=0;let W=Math.min(Q+140,Y);if(W>Y-5)W=Y;if(W===Y)Q=Math.max(W-140,0);if(X=X.slice(Q,W),Q>0)X=`'{snip} ${X}`;if(W<Y)X+=" {snip}";return X}function EW(J,$){if(!Array.isArray(J))return"";let X=[];for(let Y=0;Y<J.length;Y++){let Q=J[Y];try{if(tO(Q))X.push("[VueViewModel]");else X.push(String(Q))}catch(W){X.push("[value cannot be serialized]")}}return X.join($)}function Iz0(J,$,X=!1){if(!rZ(J))return!1;if(Tz0($))return $.test(J);if(rZ($))return X?J===$:J.includes($);return!1}function IW(J,$=[],X=!1){return $.some((Y)=>Iz0(J,Y,X))}function Ff(J,$,X){if(!($ in J))return;let Y=J[$];if(typeof Y!=="function")return;let Q=X(Y);if(typeof Q==="function")cz0(Q,Y);try{J[$]=Q}catch{x0&&t.log(`Failed to replace method "${$}" in object`,J)}}function O6(J,$,X){try{Object.defineProperty(J,$,{value:X,writable:!0,configurable:!0})}catch(Y){x0&&t.log(`Failed to add non-enumerable property "${$}" to object`,J)}}function cz0(J,$){try{let X=$.prototype||{};J.prototype=$.prototype=X,O6(J,"__sentry_original__",$)}catch(X){}}function Uf(J){return J.__sentry_original__}function eO(J){if(dJ(J))return{message:J.message,name:J.name,stack:J.stack,...Az0(J)};else if(Pz0(J)){let $={type:J.type,target:Sz0(J.target),currentTarget:Sz0(J.currentTarget),...Az0(J)};if(typeof CustomEvent<"u"&&fY(J,CustomEvent))$.detail=J.detail;return $}else return J}function Sz0(J){try{return Cz0(J)?Ez0(J):Object.prototype.toString.call(J)}catch($){return"<unknown>"}}function Az0(J){if(typeof J==="object"&&J!==null){let $={};for(let X in J)if(Object.prototype.hasOwnProperty.call(J,X))$[X]=J[X];return $}else return{}}function jf(J,$=40){let X=Object.keys(eO(J));X.sort();let Y=X[0];if(!Y)return"[object has no keys]";if(Y.length>=$)return K9(Y,$);for(let Q=X.length;Q>0;Q--){let W=X.slice(0,Q).join(", ");if(W.length>$)continue;if(Q===X.length)return W;return K9(W,$)}return""}function p$8(){let J=e0;return J.crypto||J.msCrypto}function m6(J=p$8()){let $=()=>Math.random()*16;try{if(J?.randomUUID)return J.randomUUID().replace(/-/g,"");if(J?.getRandomValues)$=()=>{let X=new Uint8Array(1);return J.getRandomValues(X),X[0]}}catch(X){}return([1e7]+1000+4000+8000+100000000000).replace(/[018]/g,(X)=>(X^($()&15)>>X/4).toString(16))}function _z0(J){return J.exception?.values?.[0]}function SW(J){let{message:$,event_id:X}=J;if($)return $;let Y=_z0(J);if(Y){if(Y.type&&Y.value)return`${Y.type}: ${Y.value}`;return Y.type||Y.value||X||"<unknown>"}return X||"<unknown>"}function wf(J,$,X){let Y=J.exception=J.exception||{},Q=Y.values=Y.values||[],W=Q[0]=Q[0]||{};if(!W.value)W.value=$||"";if(!W.type)W.type=X||"Error"}function AW(J,$){let X=_z0(J);if(!X)return;let Y={type:"generic",handled:!0},Q=X.mechanism;if(X.mechanism={...Y,...Q,...$},$&&"data"in $){let W={...Q?.data,...$.data};X.mechanism.data=W}}var d$8=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function Bf(J){return parseInt(J||"",10)}function Lf(J){let $=J.match(d$8)||[],X=Bf($[1]),Y=Bf($[2]),Q=Bf($[3]);return{buildmetadata:$[5],major:isNaN(X)?void 0:X,minor:isNaN(Y)?void 0:Y,patch:isNaN(Q)?void 0:Q,prerelease:$[4]}}function JR(J){if(i$8(J))return!0;try{O6(J,"__sentry_captured__",!0)}catch($){}return!1}function i$8(J){try{return J.__sentry_captured__}catch{}}var hz0=1000;function bY(){return Date.now()/hz0}function n$8(){let{performance:J}=e0;if(!J?.now)return bY;let $=Date.now()-J.now(),X=J.timeOrigin==null?$:J.timeOrigin;return()=>{return(X+J.now())/hz0}}var m9=n$8();function fz0(J){let $=m9(),X={sid:m6(),init:!0,timestamp:$,started:$,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>a$8(X)};if(J)yY(X,J);return X}function yY(J,$={}){if($.user){if(!J.ipAddress&&$.user.ip_address)J.ipAddress=$.user.ip_address;if(!J.did&&!$.did)J.did=$.user.id||$.user.email||$.user.username}if(J.timestamp=$.timestamp||m9(),$.abnormal_mechanism)J.abnormal_mechanism=$.abnormal_mechanism;if($.ignoreDuration)J.ignoreDuration=$.ignoreDuration;if($.sid)J.sid=$.sid.length===32?$.sid:m6();if($.init!==void 0)J.init=$.init;if(!J.did&&$.did)J.did=`${$.did}`;if(typeof $.started==="number")J.started=$.started;if(J.ignoreDuration)J.duration=void 0;else if(typeof $.duration==="number")J.duration=$.duration;else{let X=J.timestamp-J.started;J.duration=X>=0?X:0}if($.release)J.release=$.release;if($.environment)J.environment=$.environment;if(!J.ipAddress&&$.ipAddress)J.ipAddress=$.ipAddress;if(!J.userAgent&&$.userAgent)J.userAgent=$.userAgent;if(typeof $.errors==="number")J.errors=$.errors;if($.status)J.status=$.status}function bz0(J,$){let X={};if($)X={status:$};else if(J.status==="ok")X={status:"exited"};yY(J,X)}function a$8(J){return{sid:`${J.sid}`,init:J.init,started:new Date(J.started*1000).toISOString(),timestamp:new Date(J.timestamp*1000).toISOString(),status:J.status,errors:J.errors,did:typeof J.did==="number"||typeof J.did==="string"?`${J.did}`:void 0,duration:J.duration,abnormal_mechanism:J.abnormal_mechanism,attrs:{release:J.release,environment:J.environment,ip_address:J.ipAddress,user_agent:J.userAgent}}}function cW(J,$,X=2){if(!$||typeof $!=="object"||X<=0)return $;if(J&&Object.keys($).length===0)return J;let Y={...J};for(let Q in $)if(Object.prototype.hasOwnProperty.call($,Q))Y[Q]=cW(Y[Q],$[Q],X-1);return Y}var Mf="_sentrySpan";function eZ(J,$){if($)O6(J,Mf,$);else delete J[Mf]}function nJ(J){return J[Mf]}function u9(){return m6()}function l9(){return m6().substring(16)}var s$8=100;class S5{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:u9(),sampleRand:Math.random()}}clone(){let J=new S5;if(J._breadcrumbs=[...this._breadcrumbs],J._tags={...this._tags},J._extra={...this._extra},J._contexts={...this._contexts},this._contexts.flags)J._contexts.flags={values:[...this._contexts.flags.values]};return J._user=this._user,J._level=this._level,J._session=this._session,J._transactionName=this._transactionName,J._fingerprint=this._fingerprint,J._eventProcessors=[...this._eventProcessors],J._attachments=[...this._attachments],J._sdkProcessingMetadata={...this._sdkProcessingMetadata},J._propagationContext={...this._propagationContext},J._client=this._client,J._lastEventId=this._lastEventId,eZ(J,nJ(this)),J}setClient(J){this._client=J}setLastEventId(J){this._lastEventId=J}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(J){this._scopeListeners.push(J)}addEventProcessor(J){return this._eventProcessors.push(J),this}setUser(J){if(this._user=J||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session)yY(this._session,{user:J});return this._notifyScopeListeners(),this}getUser(){return this._user}setTags(J){return this._tags={...this._tags,...J},this._notifyScopeListeners(),this}setTag(J,$){return this._tags={...this._tags,[J]:$},this._notifyScopeListeners(),this}setExtras(J){return this._extra={...this._extra,...J},this._notifyScopeListeners(),this}setExtra(J,$){return this._extra={...this._extra,[J]:$},this._notifyScopeListeners(),this}setFingerprint(J){return this._fingerprint=J,this._notifyScopeListeners(),this}setLevel(J){return this._level=J,this._notifyScopeListeners(),this}setTransactionName(J){return this._transactionName=J,this._notifyScopeListeners(),this}setContext(J,$){if($===null)delete this._contexts[J];else this._contexts[J]=$;return this._notifyScopeListeners(),this}setSession(J){if(!J)delete this._session;else this._session=J;return this._notifyScopeListeners(),this}getSession(){return this._session}update(J){if(!J)return this;let $=typeof J==="function"?J(this):J,X=$ instanceof S5?$.getScopeData():I7($)?J:void 0,{tags:Y,extra:Q,user:W,contexts:K,level:Z,fingerprint:G=[],propagationContext:V}=X||{};if(this._tags={...this._tags,...Y},this._extra={...this._extra,...Q},this._contexts={...this._contexts,...K},W&&Object.keys(W).length)this._user=W;if(Z)this._level=Z;if(G.length)this._fingerprint=G;if(V)this._propagationContext=V;return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._session=void 0,eZ(this,void 0),this._attachments=[],this.setPropagationContext({traceId:u9(),sampleRand:Math.random()}),this._notifyScopeListeners(),this}addBreadcrumb(J,$){let X=typeof $==="number"?$:s$8;if(X<=0)return this;let Y={timestamp:bY(),...J,message:J.message?K9(J.message,2048):J.message};if(this._breadcrumbs.push(Y),this._breadcrumbs.length>X)this._breadcrumbs=this._breadcrumbs.slice(-X),this._client?.recordDroppedEvent("buffer_overflow","log_item");return this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(J){return this._attachments.push(J),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:nJ(this)}}setSDKProcessingMetadata(J){return this._sdkProcessingMetadata=cW(this._sdkProcessingMetadata,J,2),this}setPropagationContext(J){return this._propagationContext=J,this}getPropagationContext(){return this._propagationContext}captureException(J,$){let X=$?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture exception!"),X;let Y=Error("Sentry syntheticException");return this._client.captureException(J,{originalException:J,syntheticException:Y,...$,event_id:X},this),X}captureMessage(J,$,X){let Y=X?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture message!"),Y;let Q=Error(J);return this._client.captureMessage(J,$,{originalException:J,syntheticException:Q,...X,event_id:Y},this),Y}captureEvent(J,$){let X=$?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture event!"),X;return this._client.captureEvent(J,{...$,event_id:X},this),X}_notifyScopeListeners(){if(!this._notifyingListeners)this._notifyingListeners=!0,this._scopeListeners.forEach((J)=>{J(this)}),this._notifyingListeners=!1}}function Aq(){return oZ("defaultCurrentScope",()=>new S5)}function A7(){return oZ("defaultIsolationScope",()=>new S5)}class mz0{constructor(J,$){let X;if(!J)X=new S5;else X=J;let Y;if(!$)Y=new S5;else Y=$;this._stack=[{scope:X}],this._isolationScope=Y}withScope(J){let $=this._pushScope(),X;try{X=J($)}catch(Y){throw this._popScope(),Y}if(S7(X))return X.then((Y)=>{return this._popScope(),Y},(Y)=>{throw this._popScope(),Y});return this._popScope(),X}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){let J=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:J}),J}_popScope(){if(this._stack.length<=1)return!1;return!!this._stack.pop()}}function cq(){let J=r5(),$=kW(J);return $.stack=$.stack||new mz0(Aq(),A7())}function o$8(J){return cq().withScope(J)}function r$8(J,$){let X=cq();return X.withScope(()=>{return X.getStackTop().scope=J,$(J)})}function yz0(J){return cq().withScope(()=>{return J(cq().getIsolationScope())})}function uz0(){return{withIsolationScope:yz0,withScope:o$8,withSetScope:r$8,withSetIsolationScope:(J,$)=>{return yz0($)},getCurrentScope:()=>cq().getScope(),getIsolationScope:()=>cq().getIsolationScope()}}function Nf(J){let $=r5(),X=kW($);X.acs=J}function c7(J){let $=kW(J);if($.acs)return $.acs;return uz0()}function b1(){let J=r5();return c7(J).getCurrentScope()}function w1(){let J=r5();return c7(J).getIsolationScope()}function mY(){return oZ("globalScope",()=>new S5)}function g9(...J){let $=r5(),X=c7($);if(J.length===2){let[Y,Q]=J;if(!Y)return X.withScope(Q);return X.withSetScope(Y,Q)}return X.withScope(J[0])}function uY(...J){let $=r5(),X=c7($);if(J.length===2){let[Y,Q]=J;if(!Y)return X.withIsolationScope(Q);return X.withSetIsolationScope(Y,Q)}return X.withIsolationScope(J[0])}function A0(){return b1().getClient()}function _q(J){let $=J.getPropagationContext(),{traceId:X,parentSpanId:Y,propagationSpanId:Q}=$,W={trace_id:X,span_id:Q||l9()};if(Y)W.parent_span_id=Y;return W}var h8="sentry.source",_7="sentry.sample_rate",Of="sentry.previous_trace_sample_rate",X1="sentry.op",v1="sentry.origin";var $R="sentry.measurement_unit",XR="sentry.measurement_value",aJ="sentry.custom_span_name",hq="sentry.profile_id",fq="sentry.exclusive_time",Rf="cache.hit",Df="cache.key",xf="cache.item_size";var Pf=0,_W=1,Z9=2;function bq(J){if(J<400&&J>=100)return{code:1};if(J>=400&&J<500)switch(J){case 401:return{code:2,message:"unauthenticated"};case 403:return{code:2,message:"permission_denied"};case 404:return{code:2,message:"not_found"};case 409:return{code:2,message:"already_exists"};case 413:return{code:2,message:"failed_precondition"};case 429:return{code:2,message:"resource_exhausted"};case 499:return{code:2,message:"cancelled"};default:return{code:2,message:"invalid_argument"}}if(J>=500&&J<600)switch(J){case 501:return{code:2,message:"unimplemented"};case 503:return{code:2,message:"unavailable"};case 504:return{code:2,message:"deadline_exceeded"};default:return{code:2,message:"internal_error"}}return{code:2,message:"unknown_error"}}function yq(J,$){J.setAttribute("http.response.status_code",$);let X=bq($);if(X.message!=="unknown_error")J.setStatus(X)}var lz0="_sentryScope",gz0="_sentryIsolationScope";function TU(J,$,X){if(J)O6(J,gz0,X),O6(J,lz0,$)}function sJ(J){return{scope:J[lz0],isolationScope:J[gz0]}}function p9(J){if(typeof J==="boolean")return Number(J);let $=typeof J==="string"?parseFloat(J):J;if(typeof $!=="number"||isNaN($)||$<0||$>1)return;return $}var kU="sentry-",dz0=/^sentry-/,iz0=8192;function hW(J){let $=JG(J);if(!$)return;let X=Object.entries($).reduce((Y,[Q,W])=>{if(Q.match(dz0)){let K=Q.slice(kU.length);Y[K]=W}return Y},{});if(Object.keys(X).length>0)return X;else return}function fW(J){if(!J)return;let $=Object.entries(J).reduce((X,[Y,Q])=>{if(Q)X[`${kU}${Y}`]=Q;return X},{});return YR($)}function JG(J){if(!J||!rZ(J)&&!Array.isArray(J))return;if(Array.isArray(J))return J.reduce(($,X)=>{let Y=pz0(X);return Object.entries(Y).forEach(([Q,W])=>{$[Q]=W}),$},{});return pz0(J)}function pz0(J){return J.split(",").map(($)=>$.split("=").map((X)=>{try{return decodeURIComponent(X.trim())}catch{return}})).reduce(($,[X,Y])=>{if(X&&Y)$[X]=Y;return $},{})}function YR(J){if(Object.keys(J).length===0)return;return Object.entries(J).reduce(($,[X,Y],Q)=>{let W=`${encodeURIComponent(X)}=${encodeURIComponent(Y)}`,K=Q===0?W:`${$},${W}`;if(K.length>iz0)return x0&&t.warn(`Not adding key: ${X} with val: ${Y} to baggage header due to exceeding baggage size limits.`),$;else return K},"")}var EU=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function nz0(J){if(!J)return;let $=J.match(EU);if(!$)return;let X;if($[3]==="1")X=!0;else if($[3]==="0")X=!1;return{traceId:$[1],parentSampled:X,parentSpanId:$[2]}}function $G(J,$){let X=nz0(J),Y=hW($);if(!X?.traceId)return{traceId:u9(),sampleRand:Math.random()};let Q=t$8(X,Y);if(Y)Y.sample_rand=Q.toString();let{traceId:W,parentSpanId:K,parentSampled:Z}=X;return{traceId:W,parentSpanId:K,sampled:Z,dsc:Y||{},sampleRand:Q}}function bW(J=u9(),$=l9(),X){let Y="";if(X!==void 0)Y=X?"-1":"-0";return`${J}-${$}${Y}`}function t$8(J,$){let X=p9($?.sample_rand);if(X!==void 0)return X;let Y=p9($?.sample_rate);if(Y&&J?.parentSampled!==void 0)return J.parentSampled?Math.random()*Y:Y+Math.random()*(1-Y);else return Math.random()}var QR=0,WR=1,az0=!1;function oz0(J){let{spanId:$,traceId:X}=J.spanContext(),{data:Y,op:Q,parent_span_id:W,status:K,origin:Z,links:G}=t0(J);return{parent_span_id:W,span_id:$,trace_id:X,data:Y,op:Q,status:K,origin:Z,links:G}}function yW(J){let{spanId:$,traceId:X,isRemote:Y}=J.spanContext(),Q=Y?$:t0(J).parent_span_id,W=sJ(J).scope,K=Y?W?.getPropagationContext().propagationSpanId||l9():$;return{parent_span_id:Q,span_id:K,trace_id:X}}function SU(J){let{traceId:$,spanId:X}=J.spanContext(),Y=JX(J);return bW($,X,Y)}function XG(J){if(J&&J.length>0)return J.map(({context:{spanId:$,traceId:X,traceFlags:Y,...Q},attributes:W})=>({span_id:$,trace_id:X,sampled:Y===WR,attributes:W,...Q}));else return}function G9(J){if(typeof J==="number")return sz0(J);if(Array.isArray(J))return J[0]+J[1]/1e9;if(J instanceof Date)return sz0(J.getTime());return m9()}function sz0(J){return J>9999999999?J/1000:J}function t0(J){if(JX8(J))return J.getSpanJSON();let{spanId:$,traceId:X}=J.spanContext();if(e$8(J)){let{attributes:Y,startTime:Q,name:W,endTime:K,status:Z,links:G}=J,V="parentSpanId"in J?J.parentSpanId:("parentSpanContext"in J)?J.parentSpanContext?.spanId:void 0;return{span_id:$,trace_id:X,data:Y,description:W,parent_span_id:V,start_timestamp:G9(Q),timestamp:G9(K)||void 0,status:YG(Z),op:Y[X1],origin:Y[v1],links:XG(G)}}return{span_id:$,trace_id:X,start_timestamp:0,data:{}}}function e$8(J){let $=J;return!!$.attributes&&!!$.startTime&&!!$.name&&!!$.endTime&&!!$.status}function JX8(J){return typeof J.getSpanJSON==="function"}function JX(J){let{traceFlags:$}=J.spanContext();return $===WR}function YG(J){if(!J||J.code===Pf)return;if(J.code===_W)return"ok";return J.message||"unknown_error"}var IU="_sentryChildSpans",Cf="_sentryRootSpan";function mq(J,$){let X=J[Cf]||J;if(O6($,Cf,X),J[IU])J[IU].add($);else O6(J,IU,new Set([$]))}function AU(J){let $=new Set;function X(Y){if($.has(Y))return;else if(JX(Y)){$.add(Y);let Q=Y[IU]?Array.from(Y[IU]):[];for(let W of Q)X(W)}}return X(J),Array.from($)}function i8(J){return J[Cf]||J}function oJ(){let J=r5(),$=c7(J);if($.getActiveSpan)return $.getActiveSpan();return nJ(b1())}function cU(){if(!az0)F6(()=>{console.warn("[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.")}),az0=!0}function Tf(J,$){J.updateName($),J.setAttributes({[h8]:"custom",[aJ]:$})}var Ef="?",rz0=/\(error: (.*)\)/,tz0=/captureMessage|captureException/;function ZR(...J){let $=J.sort((X,Y)=>X[0]-Y[0]).map((X)=>X[1]);return(X,Y=0,Q=0)=>{let W=[],K=X.split(`
|
|
412
|
+
}`});try{let Y=(await $.next()).value?.data?.userById;if(!Y)return n.warning(`PlatformGateway.getPlayerCosmetics(): No cosmetic data returned for user id "${J}".`);let Q=Y.equippedItems.map((Z)=>({slot:Z.slot,item:Z.item.slots.find((G)=>G.type===Z.slot)})).filter((Z)=>!!Z.item),W=Number(Y.characterSettings?.hairStyle?.split("_")[1]||1),K=`https://d3qkovarww0lj1.cloudfront.net/?skin_tone=${Y.characterSettings?.skinTone||"SKIN_COLOR_1"}&clothing=${Y.characterSettings?.clothing||"CLOTHING_1"}&hair_style=${Y.characterSettings?.hairStyle||"HAIR_STYLE_1"}&hair_color=${Y.characterSettings?.hairColor||"HAIR_COLOR_1"}&eye_color=${Y.characterSettings?.eyeColor||"00FF00"}`;return{equippedItems:Q,hairStyle:W,skinTextureUri:K}}finally{await $.return?.()}}async getPlayerSession(J){if(!this._creativeGateway)return;return await this._creativeGateway.getSession(J)}async scheduleNotification(J,$,X){if(!AO)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_NOTIFICATION_SERVICE_URL is not set. Unable to schedule notification in this environment.");if(!this.gameId||!this.creatorApiKey)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_GAME_ID or HYTOPIA_API_KEY is not set. Unable to schedule notification in this environment.");try{let Y=await fetch(`${AO}/notifications`,{method:"POST",headers:{"Content-Type":"application/json","X-Game-Id":this.gameId,"X-Creator-Api-Key":this.creatorApiKey},body:JSON.stringify({hytopiaUserId:J,type:$,scheduledFor:X})});if(!Y.ok)return n.warning(`PlatformGateway.scheduleNotification(): Failed ${Y.status}: ${await Y.text()}`);return(await Y.json()).id}catch(Y){return n.warning(`PlatformGateway.scheduleNotification(): Failed to schedule notification: ${Y}`)}}async setGlobalData(J,$){if($.error)return n.warning("PlatformGateway.setGlobalData(): Cannot set data with an error property.");if(!this._creativeGateway&&process.env.NODE_ENV==="production")return n.warning("PlatformGateway.setGlobalData(): 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,$):this._writeDevGlobalDataLocally(J,$)}async unscheduleNotification(J){if(!AO)return n.warning("PlatformGateway.unscheduleNotification(): HYTOPIA_NOTIFICATION_SERVICE_URL is not set."),!1;if(!this.gameId||!this.creatorApiKey)return n.warning("PlatformGateway.scheduleNotification(): HYTOPIA_GAME_ID or HYTOPIA_API_KEY is not set."),!1;try{let $=await fetch(`${AO}/notifications/${J}`,{method:"DELETE",headers:{"Content-Type":"application/json","X-Game-Id":this.gameId,"X-Creator-Api-Key":this.creatorApiKey}});if(!$.ok)return n.warning(`PlatformGateway.unscheduleNotification(): Failed ${$.status}: ${await $.text()}`),!1;return!0}catch($){return n.warning(`PlatformGateway.unscheduleNotification(): Failed to unschedule notification: ${$}`),!1}}_readDevGlobalDataLocally(J){try{if(!gZ.existsSync(qU))return{error:{code:"keyNotFound",message:"Local data directory not found."}};let $=Fq0.join(qU,`${J}.json`);return JSON.parse(gZ.readFileSync($,"utf8"))}catch($){return n.warning(`PlatformGateway._readDevGlobalDataLocally(): Failed to read data for key "${J}": ${$}`),{error:{code:"gatewayError",message:"Failed to read data for key."}}}}_writeDevGlobalDataLocally(J,$){try{if(!gZ.existsSync(qU))gZ.mkdirSync(qU,{recursive:!0});let X=Fq0.join(qU,`${J}.json`),Y={};if(gZ.existsSync(X))Y=JSON.parse(gZ.readFileSync(X,"utf8"));let Q={...Y,...$};gZ.writeFileSync(X,JSON.stringify(Q,null,2),"utf8")}catch(X){n.warning(`PlatformGateway._writeDevGlobalDataLocally(): Failed to write data for key "${J}": ${X}`)}}}class CW{static instance=new CW;_saveStatesClient;constructor(){this._saveStatesClient=new jq0.SaveStatesClient}async getGlobalData(J,$=3){for(let X=0;X<=$;X++){let Y=await k7.instance.getGlobalData(J);if(Y&&!Y.error)return Y;if(Y.error.code==="keyNotFound")return{};if(X<$)n.warning(`PersistenceManager.getGlobalData(): Failed to get global data, retrying. Response: ${JSON.stringify(Y)}`),await new Promise((Q)=>setTimeout(Q,500))}n.warning(`PersistenceManager.getGlobalData(): Failed to get global data after ${$} attempts.`);return}async getPlayerData(J){let $=await this._saveStatesClient.load(this._getPlayerKey(J));if(!$)return n.warning(`PersistenceManager.getPlayerData(): Failed to get player data for player ${J.id}. Persistence service may be down.`),{};return $}async setGlobalData(J,$){let X=await k7.instance.setGlobalData(J,$);if(!X||X.error){if(X?.error)n.warning(`PersistenceManager.setGlobalData(): ${X.error.message}`)}}async setPlayerData(J,$){let X=await this.getPlayerData(J);for(let[Y,Q]of Object.entries($))X[Y]=Q}async unloadPlayerData(J){await this._saveStatesClient.unload(this._getPlayerKey(J))}_getPlayerKey(J){return`player-${J.id}`}}var Bq0;((Y)=>{Y[Y.FIRST_PERSON=0]="FIRST_PERSON";Y[Y.THIRD_PERSON=1]="THIRD_PERSON";Y[Y.SPECTATOR=2]="SPECTATOR"})(Bq0||={});var Sh;((U)=>{U.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";U.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";U.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";U.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";U.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";U.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";U.SET_FOV="PLAYER_CAMERA.SET_FOV";U.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";U.SET_MODEL_SHOWN_NODES="PLAYER_CAMERA.SET_MODEL_SHOWN_NODES";U.SET_MODE="PLAYER_CAMERA.SET_MODE";U.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";U.SET_SHOULDER_ANGLE="PLAYER_CAMERA.SET_SHOULDER_ANGLE";U.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";U.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";U.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(Sh||={});class HU extends $1{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_modelShownNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_shoulderAngle=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 facingQuaternion(){let J=this._orientation.pitch*0.5,$=this._orientation.yaw*0.5,X=Math.cos(J),Y=Math.sin(J),Q=Math.cos($),W=Math.sin($);return{x:Y*Q,y:X*W,z:-Y*W,w:X*Q}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get modelShownNodes(){return this._modelShownNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get shoulderAngle(){return this._shoulderAngle}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){if(!this._requirePlayerWorld("lookAtEntity"))return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){if(!this._requirePlayerWorld("lookAtPosition"))return;this.emitWithWorld(this.player.world,"PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}reset(){this._attachedToEntity=void 0,this._attachedToPosition=void 0,this._orientation={pitch:0,yaw:0},this._trackedEntity=void 0,this._trackedPosition=void 0}setAttachedToEntity(J){if(!this._requirePlayerWorld("setAttachedToEntity"))return;if(!J.isSpawned)return n.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("setAttachedToPosition"))return;this._attachedToPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){if(!this._requirePlayerWorld("setFilmOffset"))return;this._filmOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){if(!this._requirePlayerWorld("setForwardOffset"))return;this._forwardOffset=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){if(!this._requirePlayerWorld("setFov"))return;this._fov=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){if(!this._requirePlayerWorld("setModelHiddenNodes"))return;this._modelHiddenNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setModelShownNodes(J){if(!this._requirePlayerWorld("setModelShownNodes"))return;this._modelShownNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODEL_SHOWN_NODES",{playerCamera:this,modelShownNodes:this._modelShownNodes})}setMode(J){if(!this._requirePlayerWorld("setMode"))return;this._mode=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){if(!this._requirePlayerWorld("setOffset"))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}setShoulderAngle(J){if(!this._requirePlayerWorld("setShoulderAngle"))return;this._shoulderAngle=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_SHOULDER_ANGLE",{playerCamera:this,shoulderAngle:J})}setTrackedEntity(J){if(!this._requirePlayerWorld("setTrackedEntity"))return;this._trackedEntity=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){if(!this._requirePlayerWorld("setTrackedPosition"))return;this._trackedPosition=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){if(!this._requirePlayerWorld("setZoom"))return;this._zoom=J,this.emitWithWorld(this.player.world,"PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return V1.serializePlayerCamera(this)}_requirePlayerWorld(J){if(!this.player.world)n.error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world, invoked method: ${J}()`);return!!this.player.world}}var cO;((Q)=>{Q.DATA="PLAYER_UI.DATA";Q.LOAD="PLAYER_UI.LOAD";Q.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";Q.SEND_DATA="PLAYER_UI.SEND_DATA"})(cO||={});class zU extends $1{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})}}var x78=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","u","i","o","j","k","l","n","m","1","2","3","4","5","6","7","8","9","0","cp","cy","jd"],vU;((K)=>{K.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";K.JOINED_WORLD="PLAYER.JOINED_WORLD";K.LEFT_WORLD="PLAYER.LEFT_WORLD";K.RECONNECTED_WORLD="PLAYER.RECONNECTED_WORLD";K.REQUEST_NOTIFICATION_PERMISSION="PLAYER.REQUEST_NOTIFICATION_PERMISSION";K.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(vU||={});class kq extends $1{static _devNextPlayerId=1;id;username;profilePictureUrl;camera;connection;cosmetics;ui;_input={};_lastUnreliableInputSequenceNumber=0;_persistedData;_world;_worldSwitched=!1;constructor(J,$){super();this.id=$?.user.id??`player-${kq._devNextPlayerId++}`,this.username=$?.user.username??this.id,this.profilePictureUrl=$?.user.profilePictureURL??void 0,this.camera=new HU(this),this.connection=J,this.cosmetics=k7.instance.getPlayerCosmetics(this.id),this.ui=new zU(this),J.onPacket(_0.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(_0.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(_0.PacketId.INPUT,this._onInputPacket),J.onPacket(_0.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(_0.PacketId.UI_DATA_SEND,this._onUIDataSendPacket)}get input(){return this._input}get world(){return this._world}disconnect(){this._leaveWorld(),this.connection.disconnect()}getPersistedData(){if(!this._persistedData)return;let J=Object.keys(this._persistedData);if(J.length===0||J.length===1&&J[0]==="__version")return;return this._persistedData}joinWorld(J){if(this._world===J)return;if(!this._world)this._world=J,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world});else{for(let $ of this._world.entityManager.getPlayerEntitiesByPlayer(this))if($.isSpawned)$.despawn();this.disconnect(),this._world=J,this._worldSwitched=!0}}async scheduleNotification(J,$){if(!this._world)return n.warning("Player.scheduleNotification(): Player must be in a world to schedule a notification.");return this.emitWithWorld(this._world,"PLAYER.REQUEST_NOTIFICATION_PERMISSION",{player:this}),k7.instance.scheduleNotification(this.id,J,$)}async unscheduleNotification(J){if(!J)return!1;return k7.instance.unscheduleNotification(J)}async loadInitialPersistedData(){if(this._persistedData)return;this._persistedData=await CW.instance.getPlayerData(this)}reconnected(){if(!this._world)return;if(this._lastUnreliableInputSequenceNumber=0,!this._worldSwitched)this.emitWithWorld(this._world,"PLAYER.RECONNECTED_WORLD",{player:this,world:this._world});else this._worldSwitched=!1,this.emitWithWorld(this._world,"PLAYER.JOINED_WORLD",{player:this,world:this._world})}resetInputs(){this._input={}}setPersistedData(J){if(!this._persistedData){n.warning(`Player.setPersistedData(): Persisted data not found for player ${this.id}`);return}for(let[$,X]of Object.entries(J))this._persistedData[$]=X}serialize(){return V1.serializePlayer(this)}_leaveWorld(){if(!this._world)return;this.emitWithWorld(this._world,"PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}_onChatMessageSendPacket=(J)=>{if(!this._world)return;let $=J[1].m;if(this._world.chatManager.handleCommand(this,$)){this._world.chatManager.sendPlayerMessage(this,`Command Entered: ${$}`,"CCCCCC");return}if(this.id.startsWith("guest")){this._world.chatManager.sendPlayerMessage(this,"You need to create a HYTOPIA account to send messages in chat.","FFAA00");return}this.emitWithWorld(this._world,"PLAYER.CHAT_MESSAGE_SEND",{player:this,message:$})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let $=J[1];if($.sq!==void 0){if($.sq<this._lastUnreliableInputSequenceNumber)return;this._lastUnreliableInputSequenceNumber=$.sq}if(Object.assign(this._input,$),$.cp!==void 0)this.camera.setOrientationPitch($.cp);if($.cy!==void 0)this.camera.setOrientationYaw($.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 Ah;((X)=>{X.BROADCAST_MESSAGE="CHAT.BROADCAST_MESSAGE";X.PLAYER_MESSAGE="CHAT.PLAYER_MESSAGE"})(Ah||={});class FU extends $1{_commandCallbacks={};_world;constructor(J){super();this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,$){this._commandCallbacks[J]=$}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,$){this._sendBroadcastMessage(void 0,J,$)}handleCommand(J,$){let[X,...Y]=$.split(" "),Q=this._commandCallbacks[X];if(Q)return Q(J,Y,$),!0;return!1}sendPlayerMessage(J,$,X){this.emitWithWorld(this._world,"CHAT.PLAYER_MESSAGE",{player:J,message:$,color:X})}_subscribeToPlayerEvents(){this._world.on("PLAYER.CHAT_MESSAGE_SEND",(J)=>{let{player:$,message:X}=J;this._sendBroadcastMessage($,X)})}_sendBroadcastMessage(J,$,X){this.emitWithWorld(this._world,"CHAT.BROADCAST_MESSAGE",{player:J,message:$,color:X})}}var f9=16,ch=f9-1,P78=f9**3;class X9{_blocks;_originCoordinate;constructor(J){this._blocks=new Uint8Array(P78),this._originCoordinate=J}get blocks(){return this._blocks}get originCoordinate(){return this._originCoordinate}static blockIndexToLocalCoordinate(J){return{x:J%f9,y:(J/f9|0)%f9,z:J/(f9*f9)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&f9-1,y:J.y&f9-1,z:J.z&f9-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(f9-1),y:J.y&~(f9-1),z:J.z&~(f9-1)}}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,$){if(!this._isValidLocalCoordinate(J))return n.error("Chunk.setBlock(): Block local coordinate is out of bounds");let X=this._getIndex(J);this._blocks[X]=$}serialize(){return V1.serializeChunk(this)}_getIndex(J){return J.x+(J.y<<4)+(J.z<<8)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=ch&&J.y>=0&&J.y<=ch&&J.z>=0&&J.z<=ch}}var _h;((Y)=>{Y.ADD_CHUNK="CHUNK_LATTICE.ADD_CHUNK";Y.REMOVE_CHUNK="CHUNK_LATTICE.REMOVE_CHUNK";Y.SET_BLOCK="CHUNK_LATTICE.SET_BLOCK"})(_h||={});class UU extends $1{_blockTypeColliders=new Map;_blockTypeCounts=new Map;_chunks=new Map;_rigidBody;_world;constructor(J){super();this._world=J}get chunkCount(){return this._chunks.size}clear(){for(let J of this._blockTypeColliders.values())J.removeFromSimulation();this._chunks.forEach((J)=>{this.emitWithWorld(this._world,"CHUNK_LATTICE.REMOVE_CHUNK",{chunkLattice:this,chunk:J})}),this._blockTypeColliders.clear(),this._blockTypeCounts.clear(),this._chunks.clear()}getBlockId(J){let $=this.getChunk(X9.globalCoordinateToOriginCoordinate(J));if(!$)return 0;return $.getBlockId(X9.globalCoordinateToLocalCoordinate(J))}getBlockTypeCollider(J){return this._blockTypeColliders.get(J)}getBlockType(J){let $=this.getBlockId(J);return $?this._world.blockTypeRegistry.getBlockType($):null}getBlockTypeCount(J){return this._blockTypeCounts.get(J)??0}getChunk(J){return this._chunks.get(this._getChunkKey(X9.globalCoordinateToOriginCoordinate(J)))}getOrCreateBlockTypeCollider(J,$){let X=this._blockTypeColliders.get(J);if(X)return X;let Q=this._world.blockTypeRegistry.getBlockType(J).createCollider($);return this._blockTypeColliders.set(J,Q),Q}getOrCreateChunk(J){let $=X9.globalCoordinateToOriginCoordinate(J),X=this._chunks.get(this._getChunkKey($));if(X)return X;return X=new X9($),this._chunks.set(this._getChunkKey($),X),this.emitWithWorld(this._world,"CHUNK_LATTICE.ADD_CHUNK",{chunkLattice:this,chunk:X}),X}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let $=this.getChunk(X9.globalCoordinateToOriginCoordinate(J));if(!$)return!1;return $.hasBlock(X9.globalCoordinateToLocalCoordinate(J))}hasChunk(J){let $=X9.globalCoordinateToOriginCoordinate(J);return this._chunks.has(this._getChunkKey($))}initializeBlocks(J){if(this.clear(),!this._rigidBody)this._rigidBody=new FW({type:"fixed"}),this._rigidBody.addToSimulation(this._world.simulation);for(let $ in J){let X=Number($),Y=J[X];if(Y.length===0)continue;let Q=this.getOrCreateBlockTypeCollider(X,Y);Q.addToSimulation(this._world.simulation,this._rigidBody);let W=this._world.blockTypeRegistry.getBlockType(X);this._world.simulation.colliderMap.setColliderBlockType(Q,W),this._blockTypeCounts.set(X,Y.length);for(let K=0;K<Y.length;K++){let Z=Y[K],G=X9.globalCoordinateToLocalCoordinate(Z),V=this.getOrCreateChunk(Z);V.setBlock(G,X),this.emitWithWorld(this._world,"CHUNK_LATTICE.SET_BLOCK",{chunkLattice:this,chunk:V,globalCoordinate:Z,localCoordinate:G,blockTypeId:X})}this._combineVoxelStates(Q)}}setBlock(J,$){let X=X9.globalCoordinateToLocalCoordinate(J),Y=this.getOrCreateChunk(J),Q=Y.getBlockId(X);if(Q===$)return;if(Y.setBlock(X,$),!this._rigidBody)this._rigidBody=new FW({type:"fixed"}),this._rigidBody.addToSimulation(this._world.simulation);if(Q!==0){let W=Math.max(0,(this._blockTypeCounts.get(Q)??0)-1),K=this.getBlockTypeCollider(Q);if(K)if(W===0)this._world.simulation.colliderMap.removeColliderBlockType(K),K.removeFromSimulation(),this._blockTypeColliders.delete(Q);else K.setVoxel(J,!1),this._propagateVoxelChange(K,J);this._blockTypeCounts.set(Q,W)}if($!==0){let W=(this._blockTypeCounts.get($)??0)+1,K=this.getOrCreateBlockTypeCollider($,[J]);if(W===1){let Z=this._world.blockTypeRegistry.getBlockType($);K.addToSimulation(this._world.simulation,this._rigidBody),this._world.simulation.colliderMap.setColliderBlockType(K,Z),this._combineVoxelStates(K)}else K.setVoxel(J,!0),this._propagateVoxelChange(K,J);this._blockTypeCounts.set($,W)}this.emitWithWorld(this._world,"CHUNK_LATTICE.SET_BLOCK",{chunkLattice:this,chunk:Y,globalCoordinate:J,localCoordinate:X,blockTypeId:$})}_combineVoxelStates(J){if(J.isSensor)return;for(let $ of this._blockTypeColliders.values()){if($===J||$.isSensor)continue;J.combineVoxelStates($)}}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}_propagateVoxelChange(J,$){if(J.isSensor)return;for(let X of this._blockTypeColliders.values()){if(X===J||X.isSensor)continue;J.propagateVoxelChange(X,$)}}}class jU{_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,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleBlockType(J.rawCollider.handle,$)}setColliderCollisionCallback(J,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleCollisionCallback(J.rawCollider.handle,$)}setColliderEntity(J,$){if(!this._requireSimulatedCollider(J))return;this.setColliderHandleEntity(J.rawCollider.handle,$)}setColliderHandleBlockType(J,$){this._colliderHandleBlockTypeMap.set(J,$),this._cleanupBlockTypeColliderHandles.delete(J),this._pendingCleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,$){this._colliderHandleCollisionCallbackMap.set(J,$),this._cleanupCollisionCallbackColliderHandles.delete(J),this._pendingCleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,$){this._colliderHandleEntityMap.set(J,$),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);if(this._cleanupBlockTypeColliderHandles.size>0)this._cleanupBlockTypeColliderHandles.clear();for(let J of this._cleanupCollisionCallbackColliderHandles)this._colliderHandleCollisionCallbackMap.delete(J);if(this._cleanupCollisionCallbackColliderHandles.size>0)this._cleanupCollisionCallbackColliderHandles.clear();for(let J of this._cleanupEntityColliderHandles)this._colliderHandleEntityMap.delete(J);if(this._cleanupEntityColliderHandles.size>0)this._cleanupEntityColliderHandles.clear();for(let J of this._pendingCleanupBlockTypeColliderHandles)this._cleanupBlockTypeColliderHandles.add(J);if(this._pendingCleanupBlockTypeColliderHandles.size>0)this._pendingCleanupBlockTypeColliderHandles.clear();for(let J of this._pendingCleanupCollisionCallbackColliderHandles)this._cleanupCollisionCallbackColliderHandles.add(J);if(this._pendingCleanupCollisionCallbackColliderHandles.size>0)this._pendingCleanupCollisionCallbackColliderHandles.clear();for(let J of this._pendingCleanupEntityColliderHandles)this._cleanupEntityColliderHandles.add(J);if(this._pendingCleanupEntityColliderHandles.size>0)this._pendingCleanupEntityColliderHandles.clear()}_requireSimulatedCollider(J){if(!J.rawCollider)n.error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.");return!!J.rawCollider}}var wq0={type:"dynamic",softCcdPrediction:1},Lq0=0.015625,Mq0=Math.cos(0.026),BU;((R)=>{R.BLOCK_COLLISION="ENTITY.BLOCK_COLLISION";R.BLOCK_CONTACT_FORCE="ENTITY.BLOCK_CONTACT_FORCE";R.DESPAWN="ENTITY.DESPAWN";R.ENTITY_COLLISION="ENTITY.ENTITY_COLLISION";R.ENTITY_CONTACT_FORCE="ENTITY.ENTITY_CONTACT_FORCE";R.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";R.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";R.SET_MODEL_SCALE="ENTITY.SET_MODEL_SCALE";R.SET_MODEL_SHOWN_NODES="ENTITY.SET_MODEL_SHOWN_NODES";R.SET_MODEL_TEXTURE_URI="ENTITY.SET_MODEL_TEXTURE_URI";R.SET_OPACITY="ENTITY.SET_OPACITY";R.SET_PARENT="ENTITY.SET_PARENT";R.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";R.SPAWN="ENTITY.SPAWN";R.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";R.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";R.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";R.TICK="ENTITY.TICK";R.UPDATE_POSITION="ENTITY.UPDATE_POSITION";R.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})(BU||={});class b6 extends FW{_id;_blockHalfExtents;_blockTextureUri;_controller;_isEnvironmental=!1;_modelAnimationsPlaybackRate=1;_modelHiddenNodes=new Set;_modelLoopedAnimations=new Set;_modelOneshotAnimations=new Set;_modelPreferredShape;_modelScale={x:1,y:1,z:1};_modelShownNodes=new Set;_modelTextureUri;_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;_positionUpdateThresholdSq;_rotationUpdateThreshold;constructor(J){let $="blockTextureUri"in J,X="modelUri"in J;if(!$===!X)n.fatalError("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if($&&!J.blockHalfExtents)n.fatalError("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)n.fatalError("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!k5.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))n.fatalError(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??wq0);if($)this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri;if(X){let Y=this._modelScale=typeof J.modelScale==="number"?{x:J.modelScale,y:J.modelScale,z:J.modelScale}:J.modelScale??{x:1,y:1,z:1};if(this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelPreferredShape=J.modelPreferredShape,this._modelScale=Y,this._modelTextureUri=J.modelTextureUri,this._modelUri=J.modelUri,!this._modelUri.startsWith("http")&&!k5.instance.hasModel(this._modelUri))n.error(`Entity.constructor(): Model ${this._modelUri} does not exist!`);J.modelHiddenNodes?.forEach((Q)=>this._modelHiddenNodes.add(Q.toLowerCase())),J.modelLoopedAnimations?.forEach((Q)=>this._modelLoopedAnimations.add(Q)),J.modelShownNodes?.forEach((Q)=>this._modelShownNodes.add(Q.toLowerCase()))}if(this._isEnvironmental=J.isEnvironmental??!1,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,this._positionUpdateThresholdSq=Lq0,this._rotationUpdateThreshold=Mq0,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 depth(){return this.isModelEntity?k5.instance.getDepth(this._modelUri)*this._modelScale.z:this._blockHalfExtents.z*2}get height(){return this.isModelEntity?k5.instance.getHeight(this._modelUri)*this._modelScale.y:this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelPreferredShape(){return this._modelPreferredShape}get modelScale(){return this._modelScale}get modelShownNodes(){return this._modelShownNodes}get modelTextureUri(){return this._modelTextureUri}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 isEnvironmental(){return this._isEnvironmental}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get width(){return this.isModelEntity?k5.instance.getWidth(this._modelUri)*this._modelScale.x:this._blockHalfExtents.x*2}get world(){return this._world}spawn(J,$,X){if(this.isSpawned)return n.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 S9(S9.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0&&this._modelPreferredShape!=="none")this.addChildColliderToSimulation(new S9(S9.optionsFromModelUri(this._modelUri,this._modelScale,this._modelPreferredShape)));if(this.colliders.forEach((Y)=>{if(this.hasListeners("ENTITY.BLOCK_COLLISION")||this.hasListeners("ENTITY.ENTITY_COLLISION"))Y.enableCollisionEvents(!0);if(this.hasListeners("ENTITY.BLOCK_CONTACT_FORCE")||this.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))Y.enableContactForceEvents(!0);if(cJ.isDefaultCollisionGroups(Y.collisionGroups)){let Q=this.isEnvironmental?[8]:[Y.isSensor?4:2],W=this.isEnvironmental?[65535&~8&~1]:[65535];Y.setCollisionGroups({belongsTo:Q,collidesWith:W})}}),this.setPosition($),X)this.setRotation(X);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);this.colliders.forEach((Y)=>{J.simulation.colliderMap.setColliderEntity(Y,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.particleEmitterManager.despawnEntityAttachedParticleEmitters(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}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})}setModelHiddenNodes(J){if(!this._requireSpawned("setModelHiddenNodes"))return;if(!this.isModelEntity)return;this._modelHiddenNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setModelScale(J){if(!this._requireSpawned("setModelScale"))return;if(typeof J==="number")J={x:J,y:J,z:J};if(!this.isModelEntity||this._modelScale===J)return;let $={x:J.x/this._modelScale.x,y:J.y/this._modelScale.y,z:J.z/this._modelScale.z};this._modelScale=J,this.colliders.forEach((X)=>X.setScale($)),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_SCALE",{entity:this,modelScale:J})}setModelShownNodes(J){if(!this._requireSpawned("setModelShownNodes"))return;if(!this.isModelEntity)return;this._modelShownNodes=new Set(J.map(($)=>$.toLowerCase())),this.emitWithWorld(this._world,"ENTITY.SET_MODEL_SHOWN_NODES",{entity:this,modelShownNodes:this._modelShownNodes})}setModelTextureUri(J){if(!this._requireSpawned("setModelTextureUri"))return;if(!this.isModelEntity||this._modelTextureUri===J)return;this._modelTextureUri=J,this.emitWithWorld(this._world,"ENTITY.SET_MODEL_TEXTURE_URI",{entity:this,modelTextureUri:J})}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){if(!this._requireSpawned("setParent"))return;if(J&&!J.isSpawned)return n.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=$,this.colliders.forEach((Q)=>Q.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(X??{x:0,y:0,z:0}),this.setRotation(Y??{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:$})}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(($)=>!this._modelLoopedAnimations.has($)))return;J.forEach(($)=>{this._modelLoopedAnimations.add($)}),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(($)=>{this._modelOneshotAnimations.add($)}),this.emitWithWorld(this._world,"ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopAllModelAnimations(J=[]){if(!this._requireSpawned("stopAllModelAnimations"))return;this._stopAnimationsFromSets([this._modelLoopedAnimations,this._modelOneshotAnimations],J)}stopAllModelLoopedAnimations(J=[]){if(!this._requireSpawned("stopAllModelLoopedAnimations"))return;this._stopAnimationsFromSets([this._modelLoopedAnimations],J)}stopAllModelOneshotAnimations(J=[]){if(!this._requireSpawned("stopAllModelOneshotAnimations"))return;this._stopAnimationsFromSets([this._modelOneshotAnimations],J)}stopModelAnimations(J){if(!this._requireSpawned("stopModelAnimations"))return;if(!this.isModelEntity||!J.length)return;if(!J.some(($)=>this._modelLoopedAnimations.has($))&&!J.some(($)=>this._modelOneshotAnimations.has($)))return;J.forEach(($)=>{this._modelLoopedAnimations.delete($),this._modelOneshotAnimations.delete($)}),this.emitWithWorld(this._world,"ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return V1.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,$=this.rotation;if(this._rotationExceedsThreshold($,this._lastUpdatedRotation))this._lastUpdatedRotation=$,this.emitWithWorld(this._world,"ENTITY.UPDATE_ROTATION",{entity:this,rotation:$});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this.emitWithWorld(this._world,"ENTITY.UPDATE_POSITION",{entity:this,position:J})}_positionExceedsThreshold(J,$){let X=J.x-$.x,Y=J.y-$.y,Q=J.z-$.z;return X*X+Y*Y+Q*Q>this._positionUpdateThresholdSq}_requireSpawned(J){if(!this.isSpawned)n.error(`Entity._requireSpawned(): Entity ${this._name} is not spawned, cannot invoke ${J}()!`);return this.isSpawned}_rotationExceedsThreshold(J,$){return Math.abs(J.x*$.x+J.y*$.y+J.z*$.z+J.w*$.w)<this._rotationUpdateThreshold}_stopAnimationsFromSets(J,$=[]){if(!this.isModelEntity)return;let X=new Set($),Y=[];for(let Q of J)for(let W of Q)if(!X.has(W))Y.push(W);if(Y.length>0)this.stopModelAnimations(Y)}}class m8 extends iK{static BASE_ENTITY_HEIGHT=1.5;static GROUND_SENSOR_HEIGHT_SCALE=0.125;static GROUND_SENSOR_RADIUS_SCALE=0.23;static JUMP_LAND_HEAVY_VELOCITY_THRESHOLD=-12;static WALL_COLLIDER_HEIGHT_SCALE=0.33;static WALL_COLLIDER_RADIUS_SCALE=0.4;static MOVEMENT_ROTATIONS={wa:Math.PI/4,wd:-Math.PI/4,sa:Math.PI-Math.PI/4,sd:Math.PI+Math.PI/4,s:Math.PI,asd:Math.PI,a:Math.PI/2,d:-Math.PI/2};static EXTERNAL_IMPULSE_DECAY_RATE=0.253;static SWIM_UPWARD_COOLDOWN_MS=600;static SWIMMING_DRAG_FACTOR=0.05;static WATER_ENTRY_SINKING_FACTOR=0.8;static WATER_ENTRY_SINKING_MS=250;applyDirectionalMovementRotations=!0;autoCancelMouseLeftClick=!0;canJump=()=>!0;canRun=()=>!0;canSwim=()=>!0;canWalk=()=>!0;faceForwardOnStop=!0;idleLoopedAnimations=["idle-upper","idle-lower"];interactOneshotAnimations=["simple-interact"];jumpLandHeavyOneshotAnimations=["jump-post-heavy"];jumpLandLightOneshotAnimations=["jump-post-light"];jumpOneshotAnimations=["jump-loop"];jumpVelocity=10;runLoopedAnimations=["run-upper","run-lower"];runVelocity=8;sticksToPlatforms=!0;swimFastVelocity=5;swimGravity=0;swimIdleLoopedAnimations=["swim-idle"];swimLoopedAnimations=["swim-forward"];swimMaxGravityVelocity=-1;swimSlowVelocity=3;swimUpwardVelocity=2;walkLoopedAnimations=["walk-upper","walk-lower"];walkVelocity=4;_externalVelocity={x:0,y:0,z:0};_magnitudeYTracker=0;_groundContactCount=0;_internalApplyImpulse=()=>{};_isActivelyMoving=!1;_isFullySubmerged=!1;_justSubmergedUntil=0;_liquidContactCount=0;_platform;_reusableImpulse={x:0,y:0,z:0};_reusablePlatformVelocity={x:0,y:0,z:0};_reusableTargetVelocities={x:0,y:0,z:0};_reusableVelocityClamp={x:0,y:0,z:0};_stepAudio;_swimUpwardCooldownAt=0;constructor(J={}){super();this.applyDirectionalMovementRotations=J.applyDirectionalMovementRotations??this.applyDirectionalMovementRotations,this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.faceForwardOnStop=J.faceForwardOnStop??this.faceForwardOnStop,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms,this.canJump=J.canJump??this.canJump,this.canRun=J.canRun??this.canRun,this.canSwim=J.canSwim??this.canSwim,this.canWalk=J.canWalk??this.canWalk,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.swimFastVelocity=J.swimFastVelocity??this.swimFastVelocity,this.swimSlowVelocity=J.swimSlowVelocity??this.swimSlowVelocity,this.swimUpwardVelocity=J.swimUpwardVelocity??this.swimUpwardVelocity,this.swimGravity=J.swimGravity??this.swimGravity,this.swimMaxGravityVelocity=J.swimMaxGravityVelocity??this.swimMaxGravityVelocity,this.idleLoopedAnimations=J.idleLoopedAnimations??this.idleLoopedAnimations,this.interactOneshotAnimations=J.interactOneshotAnimations??this.interactOneshotAnimations,this.jumpOneshotAnimations=J.jumpOneshotAnimations??this.jumpOneshotAnimations,this.jumpLandHeavyOneshotAnimations=J.jumpLandHeavyOneshotAnimations??this.jumpLandHeavyOneshotAnimations,this.jumpLandLightOneshotAnimations=J.jumpLandLightOneshotAnimations??this.jumpLandLightOneshotAnimations,this.runLoopedAnimations=J.runLoopedAnimations??this.runLoopedAnimations,this.swimLoopedAnimations=J.swimLoopedAnimations??this.swimLoopedAnimations,this.swimIdleLoopedAnimations=J.swimIdleLoopedAnimations??this.swimIdleLoopedAnimations,this.walkLoopedAnimations=J.walkLoopedAnimations??this.walkLoopedAnimations}get isActivelyMoving(){return this._isActivelyMoving}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get isSwimming(){return this._liquidContactCount>0}get platform(){return this._platform}attach(J){super.attach(J),this._internalApplyImpulse=J.applyImpulse.bind(J),J.applyImpulse=($)=>{let X=J.mass||1;this._externalVelocity.x+=$.x/X,this._externalVelocity.y+=$.y/X,this._externalVelocity.z+=$.z/X},this._stepAudio=new zz({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(),J.on("ENTITY.BLOCK_COLLISION",({blockType:$,started:X})=>{if(!$.isLiquid||!this.canSwim(this))return;if(this._liquidContactCount<=0&&X){let Y=J.linearVelocity;J.setLinearVelocity({x:Y.x*this.swimGravity,y:Y.y*this.swimGravity,z:Y.z*this.swimGravity})}if(this._liquidContactCount+=X?1:-1,this._liquidContactCount>0)J.setGravityScale(this.swimGravity),J.stopAllModelLoopedAnimations(this.swimLoopedAnimations),this._swimUpwardCooldownAt=performance.now()+m8.SWIM_UPWARD_COOLDOWN_MS;else J.setGravityScale(1),J.stopModelAnimations(this.swimLoopedAnimations)})}spawn(J){if(!J.isSpawned)return n.error("DefaultPlayerEntityController.spawn(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:m8.GROUND_SENSOR_RADIUS_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),halfHeight:m8.GROUND_SENSOR_HEIGHT_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),collisionGroups:{belongsTo:[4],collidesWith:[1,2,8]},isSensor:!0,relativePosition:{x:0,y:-J.height/2,z:0},tag:"groundSensor",onCollision:($,X)=>{if(!J.isSpawned)return;if(!($ instanceof A9)||!$.isLiquid){if(X&&this._groundContactCount===0&&J.linearVelocity.y<-1)if(J.linearVelocity.y<m8.JUMP_LAND_HEAVY_VELOCITY_THRESHOLD)J.startModelOneshotAnimations(this.jumpLandHeavyOneshotAnimations);else J.startModelOneshotAnimations(this.jumpLandLightOneshotAnimations);this._groundContactCount+=X?1:-1}if(!this._groundContactCount&&!this.isSwimming)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!($ instanceof b6))return;if(X&&this.sticksToPlatforms)this._platform=$;else if($===this._platform&&!X)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:m8.WALL_COLLIDER_HEIGHT_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),radius:m8.WALL_COLLIDER_RADIUS_SCALE*(J.height/m8.BASE_ENTITY_HEIGHT),collisionGroups:{belongsTo:[4],collidesWith:[1,2,8]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,$,X,Y){if(!J.isSpawned||!J.world)return;if(super.tickWithPlayerInput(J,$,X,Y),J.parent)return;let{w:Q,a:W,s:K,d:Z,c:G,sp:V,sh:q,ml:z,jd:H}=$,{yaw:v}=X,F=J.linearVelocity;this._reusableTargetVelocities.x=0,this._reusableTargetVelocities.y=0,this._reusableTargetVelocities.z=0;let U=typeof H==="number";this._isActivelyMoving=U||!!(Q||W||K||Z);let j=q,B=!U&&(W&&Z&&!Q&&!K||Q&&K&&!W&&!Z),w=j&&this.canRun(this)||!j&&this.canWalk(this);if(this.isSwimming&&!this._isFullySubmerged)this._isFullySubmerged=!0,this._justSubmergedUntil=performance.now()+m8.WATER_ENTRY_SINKING_MS;else if(!this.isSwimming)this._isFullySubmerged=!1,this._justSubmergedUntil=0;if(this.isGrounded&&!this.isSwimming&&this._isActivelyMoving&&!B&&w){let x=j?this.runLoopedAnimations:this.walkLoopedAnimations;J.stopAllModelLoopedAnimations(x),J.startModelLoopedAnimations(x),this._stepAudio?.setPlaybackRate(j?0.75:0.51),this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else if(this._isFullySubmerged&&this.canSwim(this))if(this._stepAudio?.pause(),this._isActivelyMoving)J.stopAllModelLoopedAnimations(this.swimLoopedAnimations),J.startModelLoopedAnimations(this.swimLoopedAnimations);else J.stopAllModelLoopedAnimations(this.swimIdleLoopedAnimations),J.startModelLoopedAnimations(this.swimIdleLoopedAnimations);else this._stepAudio?.pause(),J.stopAllModelLoopedAnimations(this.idleLoopedAnimations),J.startModelLoopedAnimations(this.idleLoopedAnimations);let M;if(this.applyDirectionalMovementRotations&&w){if(U)M=H;else if(Q&&W&&!Z&&!K)M=m8.MOVEMENT_ROTATIONS.wa;else if(Q&&Z&&!W&&!K)M=m8.MOVEMENT_ROTATIONS.wd;else if(K&&W&&!Q&&!Z)M=m8.MOVEMENT_ROTATIONS.sa;else if(K&&Z&&!Q&&!W)M=m8.MOVEMENT_ROTATIONS.sd;else if(K&&!Q&&!W&&!Z||W&&K&&Z&&!Q)M=m8.MOVEMENT_ROTATIONS.s;else if(W&&!Q&&!K&&!Z)M=m8.MOVEMENT_ROTATIONS.a;else if(Z&&!Q&&!W&&!K)M=m8.MOVEMENT_ROTATIONS.d}if(z)J.startModelOneshotAnimations(this.interactOneshotAnimations),$.ml=!this.autoCancelMouseLeftClick;if(w){let x=!this.isSwimming?j?this.runVelocity:this.walkVelocity:j?this.swimFastVelocity:this.swimSlowVelocity;if(U){let T=v+H;this._reusableTargetVelocities.x=-x*Math.sin(T),this._reusableTargetVelocities.z=-x*Math.cos(T)}else{let T=Math.sin(v),S=Math.cos(v);if(Q)this._reusableTargetVelocities.x-=x*T,this._reusableTargetVelocities.z-=x*S;if(K)this._reusableTargetVelocities.x+=x*T,this._reusableTargetVelocities.z+=x*S;if(W)this._reusableTargetVelocities.x-=x*S,this._reusableTargetVelocities.z+=x*T;if(Z)this._reusableTargetVelocities.x+=x*S,this._reusableTargetVelocities.z-=x*T;let C=Math.sqrt(this._reusableTargetVelocities.x*this._reusableTargetVelocities.x+this._reusableTargetVelocities.z*this._reusableTargetVelocities.z);if(C>x){let I=x/C;this._reusableTargetVelocities.x*=I,this._reusableTargetVelocities.z*=I}}}if(this.isSwimming){if(F.y<this.swimMaxGravityVelocity)this._reusableVelocityClamp.x=F.x,this._reusableVelocityClamp.y=this.swimMaxGravityVelocity,this._reusableVelocityClamp.z=F.z,J.setLinearVelocity(this._reusableVelocityClamp);if(F.y>this.swimUpwardVelocity*2)this._reusableVelocityClamp.x=F.x,this._reusableVelocityClamp.y=this.swimUpwardVelocity*2,this._reusableVelocityClamp.z=F.z,J.setLinearVelocity(this._reusableVelocityClamp);if(G)this._reusableTargetVelocities.y=-this.swimUpwardVelocity;else if(performance.now()<this._justSubmergedUntil)this._reusableTargetVelocities.y=-this.swimUpwardVelocity*m8.WATER_ENTRY_SINKING_FACTOR;else if(!V)this._reusableTargetVelocities.y=-F.y*m8.SWIMMING_DRAG_FACTOR}if(V&&this.canJump(this)){if(this.isGrounded&&!this.isSwimming&&F.y>-0.001&&F.y<=3)this._reusableTargetVelocities.y=this.jumpVelocity;else if(this.isSwimming&&performance.now()>this._swimUpwardCooldownAt)this._reusableTargetVelocities.y=this.swimUpwardVelocity}let R=this._platform?.linearVelocity??this._reusablePlatformVelocity;if(this._externalVelocity.y!==0)this._magnitudeYTracker+=this._externalVelocity.y;if(this._externalVelocity.x!==0||this._externalVelocity.y!==0||this._externalVelocity.z!==0){if(this.isGrounded){let x=Math.sqrt(this._externalVelocity.x*this._externalVelocity.x+this._magnitudeYTracker*this._magnitudeYTracker+this._externalVelocity.z*this._externalVelocity.z);if(x>0.01){let S=Math.max(0,x-m8.EXTERNAL_IMPULSE_DECAY_RATE)/x;this._externalVelocity.x*=S,this._magnitudeYTracker*=S,this._externalVelocity.z*=S}else this._externalVelocity.x=0,this._externalVelocity.y=0,this._magnitudeYTracker=0,this._externalVelocity.z=0}}let N=this._reusableTargetVelocities.x+this._externalVelocity.x-F.x+R.x,L=this._reusableTargetVelocities.y+this._externalVelocity.y+R.y,O=this._reusableTargetVelocities.z+this._externalVelocity.z-F.z+R.z;if(this._externalVelocity.y=0,N!==0||L!==0||O!==0){let x=J.mass;this._reusableImpulse.x=N*x,this._reusableImpulse.y=L*x,this._reusableImpulse.z=O*x,this._internalApplyImpulse(this._reusableImpulse)}if(v!==void 0&&(this.faceForwardOnStop||this.isActivelyMoving)){let T=(M!==void 0?v+M:v)*0.5;J.setRotation({x:0,y:Math.sin(T),z:0,w:Math.cos(T)})}}}var hh;((Z)=>{Z.LOAD="SCENE_UI.LOAD";Z.SET_ATTACHED_TO_ENTITY="SCENE_UI.SET_ATTACHED_TO_ENTITY";Z.SET_OFFSET="SCENE_UI.SET_OFFSET";Z.SET_POSITION="SCENE_UI.SET_POSITION";Z.SET_STATE="SCENE_UI.SET_STATE";Z.SET_VIEW_DISTANCE="SCENE_UI.SET_VIEW_DISTANCE";Z.UNLOAD="SCENE_UI.UNLOAD"})(hh||={});class wU extends $1{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.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 n.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 n.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 V1.serializeSceneUI(this)}}var Nq0=0.010000000000000002,Oq0=Math.cos(0.026);class o$ extends b6{player;nametagSceneUI;constructor(J){super(J);this._positionUpdateThresholdSq=Nq0,this._rotationUpdateThreshold=Oq0,this.player=J.player,this.nametagSceneUI=new wU({templateId:"hytopia:nametag",attachedToEntity:this,offset:{x:0,y:1,z:0},viewDistance:15,state:{username:this.player.username,profilePictureUrl:this.player.profilePictureUrl}})}spawn(J,$,X){super.spawn(J,$,X),this.nametagSceneUI.load(J),this.player.on("PLAYER.CHAT_MESSAGE_SEND",({message:Y})=>{this.nametagSceneUI.setState({chat:Y})})}tick(J){if(!this.isSpawned||!this.world)return;if(!this.controller)return n.error(`PlayerEntity.tick(): PlayerEntity "${this.name}" must have a controller.`);let{input:$,camera:X}=this.player;this.controller.tickWithPlayerInput(this,$,X.orientation,J),super.tick(J)}}var Rq0="models/players/player.gltf",C78={BACK:"back-anchor",HEAD:"head-anchor",LEFT_ARM:"arm-left-anchor",LEFT_FOOT:"foot-left-anchor",LEFT_HAND:"hand-left-anchor",LEFT_ITEM:"hand-left-anchor",LEFT_LEG:"leg-left-anchor",RIGHT_ARM:"arm-right-anchor",RIGHT_FOOT:"foot-right-anchor",RIGHT_HAND:"hand-right-anchor",RIGHT_ITEM:"hand-right-anchor",RIGHT_LEG:"leg-right-anchor",TORSO:"torso-anchor"};class fh extends o${_cosmeticHiddenSlots;constructor(J){super({modelUri:Rq0,modelLoopedAnimations:["idle_lower","idle_upper"],modelHiddenNodes:["hair-"],modelShownNodes:["hair-0003"],...J});if(this._cosmeticHiddenSlots=J.cosmeticHiddenSlots??[],!J.controller)this.setController(new m8)}get cosmeticHiddenSlots(){return this._cosmeticHiddenSlots}spawn(J,$,X){super.spawn(J,$,X),this.player.cosmetics.then((Y)=>{if(!Y||!this.modelUri)return;let Q=this.modelShownNodes.values().toArray().filter((Z)=>!Z.includes("hair-"));if(!(Y.equippedItems.some((Z)=>Z.item.flags.includes("HIDES_HAIR"))&&!this._cosmeticHiddenSlots.includes("ALL")&&!this._cosmeticHiddenSlots.includes("HEAD")))Q.push(`hair-${String(Y.hairStyle).padStart(4,"0")}`);if(this.setModelShownNodes(Q),this.modelUri===Rq0)this.setModelTextureUri(Y.skinTextureUri);if(this._cosmeticHiddenSlots.includes("ALL"))return;let K=[];for(let Z of Y.equippedItems){let{item:G,slot:V}=Z;if(this._cosmeticHiddenSlots.includes(V))continue;let q=C78[V];if(!q||!k5.instance.modelHasNode(this.modelUri,q))continue;if(G.flags.includes("REPLACES_LIMB")){let H=q.split("-").slice(0,-1).join("-");K.push(`${H}-clothing`,`${H}-geometry`)}new b6({modelUri:G.modelUrl,modelPreferredShape:"none",parent:this,parentNodeName:q}).spawn(J,{x:0,y:0,z:0})}if(K.length>0)this.setModelHiddenNodes([...this.modelHiddenNodes.values().toArray(),...K])}).catch((Y)=>n.warning(`DefaultPlayerEntity.spawn(): Failed to get player cosmetics: ${Y}`))}}class LU{_activeEntities=new Set;_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get entityCount(){return this._entities.size}get world(){return this._world}registerEntity(J){if(J.id!==void 0)n.fatalError(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let $=this._nextEntityId;if(this._entities.set($,J),this._nextEntityId++,!J.isEnvironmental)this._activeEntities.add(J);return $}unregisterEntity(J){if(J.id===void 0)return n.error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);if(this._entities.delete(J.id),!J.isEnvironmental)this._activeEntities.delete(J)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach(($)=>{if($ instanceof o$)J.push($)}),J}getPlayerEntitiesByPlayer(J){let $=[];return this._entities.forEach((X)=>{if(X instanceof o$&&X.player===J)$.push(X)}),$}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let $=[];return this._entities.forEach((X)=>{if(X.tag===J)$.push(X)}),$}getEntitiesByTagSubstring(J){let $=[];return this._entities.forEach((X)=>{if(X.tag?.includes(J))$.push(X)}),$}getEntityChildren(J){let $=[];return this._entities.forEach((X)=>{if(X.parent===J)$.push(X)}),$}tickEntities(J){for(let $ of this._activeEntities)$.tick(J)}checkAndEmitUpdates(){for(let J of this._activeEntities)J.checkAndEmitUpdates()}}import{gzipSync as EC6}from"zlib";var P4=M0(CH0(),1),VZ5=P4.default.v1,qZ5=P4.default.v1ToV6,HZ5=P4.default.v3,TH0=P4.default.v4,zZ5=P4.default.v5,vZ5=P4.default.v6,FZ5=P4.default.v6ToV1,UZ5=P4.default.v7,jZ5=P4.default.NIL,BZ5=P4.default.MAX,wZ5=P4.default.version,LZ5=P4.default.validate,MZ5=P4.default.stringify,NZ5=P4.default.parse;var dh;try{dh=new TextDecoder}catch(J){}var E0,y9,r=0;var sh=[],dZ=sh,OU=0,_8={},G8,cY,b9=0,E7=0,Y5,_Y,Q9=[],J8,kH0={useRecords:!1,mapsAsObjects:!0};class lO{}var oh=new lO;oh.name="MessagePack 0xC1";var TW=!1,fH0=2,ih,nh,ah;try{Function("")}catch(J){fH0=1/0}class hY{constructor(J){if(J){if(J.useRecords===!1&&J.mapsAsObjects===void 0)J.mapsAsObjects=!0;if(J.sequential&&J.trusted!==!1){if(J.trusted=!0,!J.structures&&J.useRecords!=!1){if(J.structures=[],!J.maxSharedStructures)J.maxSharedStructures=0}}if(J.structures)J.structures.sharedLength=J.structures.length;else if(J.getStructures)(J.structures=[]).uninitialized=!0,J.structures.sharedLength=0;if(J.int64AsNumber)J.int64AsType="number"}Object.assign(this,J)}unpack(J,$){if(E0)return nH0(()=>{return uO(),this?this.unpack(J,$):hY.prototype.unpack.call(kH0,J,$)});if(!J.buffer&&J.constructor===ArrayBuffer)J=typeof Buffer<"u"?Buffer.from(J):new Uint8Array(J);if(typeof $==="object")y9=$.end||J.length,r=$.start||0;else r=0,y9=$>-1?$:J.length;OU=0,E7=0,cY=null,dZ=sh,Y5=null,E0=J;try{J8=J.dataView||(J.dataView=new DataView(J.buffer,J.byteOffset,J.byteLength))}catch(X){if(E0=null,J instanceof Uint8Array)throw X;throw Error("Source must be a Uint8Array or Buffer but was a "+(J&&typeof J=="object"?J.constructor.name:typeof J))}if(this instanceof hY){if(_8=this,this.structures)return G8=this.structures,yO($);else if(!G8||G8.length>0)G8=[]}else if(_8=kH0,!G8||G8.length>0)G8=[];return yO($)}unpackMultiple(J,$){let X,Y=0;try{TW=!0;let Q=J.length,W=this?this.unpack(J,Q):pO.unpack(J,Q);if($){if($(W,Y,r)===!1)return;while(r<Q)if(Y=r,$(yO(),Y,r)===!1)return}else{X=[W];while(r<Q)Y=r,X.push(yO());return X}}catch(Q){throw Q.lastPosition=Y,Q.values=X,Q}finally{TW=!1,uO()}}_mergeStructures(J,$){if(nh)J=nh.call(this,J);if(J=J||[],Object.isFrozen(J))J=J.map((X)=>X.slice(0));for(let X=0,Y=J.length;X<Y;X++){let Q=J[X];if(Q){if(Q.isShared=!0,X>=32)Q.highByte=X-32>>5}}J.sharedLength=J.length;for(let X in $||[])if(X>=0){let Y=J[X],Q=$[X];if(Q){if(Y)(J.restoreStructures||(J.restoreStructures=[]))[X]=Y;J[X]=Q}}return this.structures=J}decode(J,$){return this.unpack(J,$)}}function yO(J){try{if(!_8.trusted&&!TW){let X=G8.sharedLength||0;if(X<G8.length)G8.length=X}let $;if(_8.randomAccessStructure&&E0[r]<64&&E0[r]>=32&&ih){if($=ih(E0,r,y9,_8),E0=null,!(J&&J.lazy)&&$)$=$.toJSON();r=y9}else $=y6();if(Y5)r=Y5.postBundlePosition,Y5=null;if(TW)G8.restoreStructures=null;if(r==y9){if(G8&&G8.restoreStructures)EH0();if(G8=null,E0=null,_Y)_Y=null}else if(r>y9)throw Error("Unexpected end of MessagePack data");else if(!TW){let X;try{X=JSON.stringify($,(Y,Q)=>typeof Q==="bigint"?`${Q}n`:Q).slice(0,100)}catch(Y){X="(JSON view not available "+Y+")"}throw Error("Data read, but end of buffer not reached "+X)}return $}catch($){if(G8&&G8.restoreStructures)EH0();if(uO(),$ instanceof RangeError||$.message.startsWith("Unexpected end of buffer")||r>y9)$.incomplete=!0;throw $}}function EH0(){for(let J in G8.restoreStructures)G8[J]=G8.restoreStructures[J];G8.restoreStructures=null}function y6(){let J=E0[r++];if(J<160)if(J<128)if(J<64)return J;else{let $=G8[J&63]||_8.getStructures&&bH0()[J&63];if($){if(!$.read)$.read=rh($,J&63);return $.read()}else return J}else if(J<144)if(J-=128,_8.mapsAsObjects){let $={};for(let X=0;X<J;X++){let Y=dH0();if(Y==="__proto__")Y="__proto_";$[Y]=y6()}return $}else{let $=new Map;for(let X=0;X<J;X++)$.set(y6(),y6());return $}else{J-=144;let $=Array(J);for(let X=0;X<J;X++)$[X]=y6();if(_8.freezeData)return Object.freeze($);return $}else if(J<192){let $=J-160;if(E7>=r)return cY.slice(r-b9,(r+=$)-b9);if(E7==0&&y9<140){let X=$<16?th($):pH0($);if(X!=null)return X}return mO($)}else{let $;switch(J){case 192:return null;case 193:if(Y5)if($=y6(),$>0)return Y5[1].slice(Y5.position1,Y5.position1+=$);else return Y5[0].slice(Y5.position0,Y5.position0-=$);return oh;case 194:return!1;case 195:return!0;case 196:if($=E0[r++],$===void 0)throw Error("Unexpected end of buffer");return ph($);case 197:return $=J8.getUint16(r),r+=2,ph($);case 198:return $=J8.getUint32(r),r+=4,ph($);case 199:return pZ(E0[r++]);case 200:return $=J8.getUint16(r),r+=2,pZ($);case 201:return $=J8.getUint32(r),r+=4,pZ($);case 202:if($=J8.getFloat32(r),_8.useFloat32>2){let X=nZ[(E0[r]&127)<<1|E0[r+1]>>7];return r+=4,(X*$+($>0?0.5:-0.5)>>0)/X}return r+=4,$;case 203:return $=J8.getFloat64(r),r+=8,$;case 204:return E0[r++];case 205:return $=J8.getUint16(r),r+=2,$;case 206:return $=J8.getUint32(r),r+=4,$;case 207:if(_8.int64AsType==="number")$=J8.getUint32(r)*4294967296,$+=J8.getUint32(r+4);else if(_8.int64AsType==="string")$=J8.getBigUint64(r).toString();else if(_8.int64AsType==="auto"){if($=J8.getBigUint64(r),$<=BigInt(2)<<BigInt(52))$=Number($)}else $=J8.getBigUint64(r);return r+=8,$;case 208:return J8.getInt8(r++);case 209:return $=J8.getInt16(r),r+=2,$;case 210:return $=J8.getInt32(r),r+=4,$;case 211:if(_8.int64AsType==="number")$=J8.getInt32(r)*4294967296,$+=J8.getUint32(r+4);else if(_8.int64AsType==="string")$=J8.getBigInt64(r).toString();else if(_8.int64AsType==="auto"){if($=J8.getBigInt64(r),$>=BigInt(-2)<<BigInt(52)&&$<=BigInt(2)<<BigInt(52))$=Number($)}else $=J8.getBigInt64(r);return r+=8,$;case 212:if($=E0[r++],$==114)return hH0(E0[r++]&63);else{let X=Q9[$];if(X)if(X.read)return r++,X.read(y6());else if(X.noBuffer)return r++,X();else return X(E0.subarray(r,++r));else throw Error("Unknown extension "+$)}case 213:if($=E0[r],$==114)return r++,hH0(E0[r++]&63,E0[r++]);else return pZ(2);case 214:return pZ(4);case 215:return pZ(8);case 216:return pZ(16);case 217:if($=E0[r++],E7>=r)return cY.slice(r-b9,(r+=$)-b9);return yH0($);case 218:if($=J8.getUint16(r),r+=2,E7>=r)return cY.slice(r-b9,(r+=$)-b9);return mH0($);case 219:if($=J8.getUint32(r),r+=4,E7>=r)return cY.slice(r-b9,(r+=$)-b9);return uH0($);case 220:return $=J8.getUint16(r),r+=2,SH0($);case 221:return $=J8.getUint32(r),r+=4,SH0($);case 222:return $=J8.getUint16(r),r+=2,AH0($);case 223:return $=J8.getUint32(r),r+=4,AH0($);default:if(J>=224)return J-256;if(J===void 0){let X=Error("Unexpected end of MessagePack data");throw X.incomplete=!0,X}throw Error("Unknown MessagePack token "+J)}}}var X$8=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function rh(J,$){function X(){if(X.count++>fH0){let Q=J.read=Function("r","return function(){return "+(_8.freezeData?"Object.freeze":"")+"({"+J.map((W)=>W==="__proto__"?"__proto_:r()":X$8.test(W)?W+":r()":"["+JSON.stringify(W)+"]:r()").join(",")+"})}")(y6);if(J.highByte===0)J.read=IH0($,J.read);return Q()}let Y={};for(let Q=0,W=J.length;Q<W;Q++){let K=J[Q];if(K==="__proto__")K="__proto_";Y[K]=y6()}if(_8.freezeData)return Object.freeze(Y);return Y}if(X.count=0,J.highByte===0)return IH0($,X);return X}var IH0=(J,$)=>{return function(){let X=E0[r++];if(X===0)return $();let Y=J<32?-(J+(X<<5)):J+(X<<5),Q=G8[Y]||bH0()[Y];if(!Q)throw Error("Record id is not defined for "+Y);if(!Q.read)Q.read=rh(Q,J);return Q.read()}};function bH0(){let J=nH0(()=>{return E0=null,_8.getStructures()});return G8=_8._mergeStructures(J,G8)}var mO=iZ,yH0=iZ,mH0=iZ,uH0=iZ,gO=!1;function lH0(J){gO=!0,mO=$(1),yH0=$(2),mH0=$(3),uH0=$(5);function $(X){return function(Q){let W=dZ[OU++];if(W==null){if(Y5)return iZ(Q);let Z=E0.byteOffset,G=J(r-X+Z,y9+Z,E0.buffer);if(typeof G=="string")W=G,dZ=sh;else if(dZ=G,OU=1,E7=1,W=dZ[0],W===void 0)throw Error("Unexpected end of buffer")}let K=W.length;if(K<=Q)return r+=Q,W;return cY=W,b9=r,E7=r+K,r+=Q,W.slice(0,Q)}}}function iZ(J){let $;if(J<16){if($=th(J))return $}if(J>64&&dh)return dh.decode(E0.subarray(r,r+=J));let X=r+J,Y=[];$="";while(r<X){let Q=E0[r++];if((Q&128)===0)Y.push(Q);else if((Q&224)===192){let W=E0[r++]&63;Y.push((Q&31)<<6|W)}else if((Q&240)===224){let W=E0[r++]&63,K=E0[r++]&63;Y.push((Q&31)<<12|W<<6|K)}else if((Q&248)===240){let W=E0[r++]&63,K=E0[r++]&63,Z=E0[r++]&63,G=(Q&7)<<18|W<<12|K<<6|Z;if(G>65535)G-=65536,Y.push(G>>>10&1023|55296),G=56320|G&1023;Y.push(G)}else Y.push(Q);if(Y.length>=4096)$+=F5.apply(String,Y),Y.length=0}if(Y.length>0)$+=F5.apply(String,Y);return $}function gH0(J,$,X){let Y=E0;E0=J,r=$;try{return iZ(X)}finally{E0=Y}}function SH0(J){let $=Array(J);for(let X=0;X<J;X++)$[X]=y6();if(_8.freezeData)return Object.freeze($);return $}function AH0(J){if(_8.mapsAsObjects){let $={};for(let X=0;X<J;X++){let Y=dH0();if(Y==="__proto__")Y="__proto_";$[Y]=y6()}return $}else{let $=new Map;for(let X=0;X<J;X++)$.set(y6(),y6());return $}}var F5=String.fromCharCode;function pH0(J){let $=r,X=Array(J);for(let Y=0;Y<J;Y++){let Q=E0[r++];if((Q&128)>0){r=$;return}X[Y]=Q}return F5.apply(String,X)}function th(J){if(J<4)if(J<2)if(J===0)return"";else{let $=E0[r++];if(($&128)>1){r-=1;return}return F5($)}else{let $=E0[r++],X=E0[r++];if(($&128)>0||(X&128)>0){r-=2;return}if(J<3)return F5($,X);let Y=E0[r++];if((Y&128)>0){r-=3;return}return F5($,X,Y)}else{let $=E0[r++],X=E0[r++],Y=E0[r++],Q=E0[r++];if(($&128)>0||(X&128)>0||(Y&128)>0||(Q&128)>0){r-=4;return}if(J<6)if(J===4)return F5($,X,Y,Q);else{let W=E0[r++];if((W&128)>0){r-=5;return}return F5($,X,Y,Q,W)}else if(J<8){let W=E0[r++],K=E0[r++];if((W&128)>0||(K&128)>0){r-=6;return}if(J<7)return F5($,X,Y,Q,W,K);let Z=E0[r++];if((Z&128)>0){r-=7;return}return F5($,X,Y,Q,W,K,Z)}else{let W=E0[r++],K=E0[r++],Z=E0[r++],G=E0[r++];if((W&128)>0||(K&128)>0||(Z&128)>0||(G&128)>0){r-=8;return}if(J<10)if(J===8)return F5($,X,Y,Q,W,K,Z,G);else{let V=E0[r++];if((V&128)>0){r-=9;return}return F5($,X,Y,Q,W,K,Z,G,V)}else if(J<12){let V=E0[r++],q=E0[r++];if((V&128)>0||(q&128)>0){r-=10;return}if(J<11)return F5($,X,Y,Q,W,K,Z,G,V,q);let z=E0[r++];if((z&128)>0){r-=11;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z)}else{let V=E0[r++],q=E0[r++],z=E0[r++],H=E0[r++];if((V&128)>0||(q&128)>0||(z&128)>0||(H&128)>0){r-=12;return}if(J<14)if(J===12)return F5($,X,Y,Q,W,K,Z,G,V,q,z,H);else{let v=E0[r++];if((v&128)>0){r-=13;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v)}else{let v=E0[r++],F=E0[r++];if((v&128)>0||(F&128)>0){r-=14;return}if(J<15)return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v,F);let U=E0[r++];if((U&128)>0){r-=15;return}return F5($,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U)}}}}}function cH0(){let J=E0[r++],$;if(J<192)$=J-160;else switch(J){case 217:$=E0[r++];break;case 218:$=J8.getUint16(r),r+=2;break;case 219:$=J8.getUint32(r),r+=4;break;default:throw Error("Expected string")}return iZ($)}function ph(J){return _8.copyBuffers?Uint8Array.prototype.slice.call(E0,r,r+=J):E0.subarray(r,r+=J)}function pZ(J){let $=E0[r++];if(Q9[$]){let X;return Q9[$](E0.subarray(r,X=r+=J),(Y)=>{r=Y;try{return y6()}finally{r=X}})}else throw Error("Unknown extension type "+$)}var _H0=Array(4096);function dH0(){let J=E0[r++];if(J>=160&&J<192){if(J=J-160,E7>=r)return cY.slice(r-b9,(r+=J)-b9);else if(!(E7==0&&y9<180))return mO(J)}else return r--,iH0(y6());let $=(J<<5^(J>1?J8.getUint16(r):J>0?E0[r]:0))&4095,X=_H0[$],Y=r,Q=r+J-3,W,K=0;if(X&&X.bytes==J){while(Y<Q){if(W=J8.getUint32(Y),W!=X[K++]){Y=1879048192;break}Y+=4}Q+=3;while(Y<Q)if(W=E0[Y++],W!=X[K++]){Y=1879048192;break}if(Y===Q)return r=Y,X.string;Q-=3,Y=r}X=[],_H0[$]=X,X.bytes=J;while(Y<Q)W=J8.getUint32(Y),X.push(W),Y+=4;Q+=3;while(Y<Q)W=E0[Y++],X.push(W);let Z=J<16?th(J):pH0(J);if(Z!=null)return X.string=Z;return X.string=mO(J)}function iH0(J){if(typeof J==="string")return J;if(typeof J==="number"||typeof J==="boolean"||typeof J==="bigint")return J.toString();if(J==null)return J+"";if(_8.allowArraysInMapKeys&&Array.isArray(J)&&J.flat().every(($)=>["string","number","boolean","bigint"].includes(typeof $)))return J.flat().toString();throw Error(`Invalid property type for record: ${typeof J}`)}var hH0=(J,$)=>{let X=y6().map(iH0),Y=J;if($!==void 0)J=J<32?-(($<<5)+J):($<<5)+J,X.highByte=$;let Q=G8[J];if(Q&&(Q.isShared||TW))(G8.restoreStructures||(G8.restoreStructures=[]))[J]=Q;return G8[J]=X,X.read=rh(X,Y),X.read()};Q9[0]=()=>{};Q9[0].noBuffer=!0;Q9[66]=(J)=>{let $=J.length,X=BigInt(J[0]&128?J[0]-256:J[0]);for(let Y=1;Y<$;Y++)X<<=BigInt(8),X+=BigInt(J[Y]);return X};var Y$8={Error,TypeError,ReferenceError};Q9[101]=()=>{let J=y6();return(Y$8[J[0]]||Error)(J[1],{cause:J[2]})};Q9[105]=(J)=>{if(_8.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=J8.getUint32(r-4);if(!_Y)_Y=new Map;let X=E0[r],Y;if(X>=144&&X<160||X==220||X==221)Y=[];else if(X>=128&&X<144||X==222||X==223)Y=new Map;else if((X>=199&&X<=201||X>=212&&X<=216)&&E0[r+1]===115)Y=new Set;else Y={};let Q={target:Y};_Y.set($,Q);let W=y6();if(!Q.used)return Q.target=W;else Object.assign(Y,W);if(Y instanceof Map)for(let[K,Z]of W.entries())Y.set(K,Z);if(Y instanceof Set)for(let K of Array.from(W))Y.add(K);return Y};Q9[112]=(J)=>{if(_8.structuredClone===!1)throw Error("Structured clone extension is disabled");let $=J8.getUint32(r-4),X=_Y.get($);return X.used=!0,X.target};Q9[115]=()=>new Set(y6());var eh=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((J)=>J+"Array"),Q$8=typeof globalThis==="object"?globalThis:window;Q9[116]=(J)=>{let $=J[0],X=Uint8Array.prototype.slice.call(J,1).buffer,Y=eh[$];if(!Y){if($===16)return X;if($===17)return new DataView(X);throw Error("Could not find typed array for code "+$)}return new Q$8[Y](X)};Q9[120]=()=>{let J=y6();return new RegExp(J[0],J[1])};var W$8=[];Q9[98]=(J)=>{let $=(J[0]<<24)+(J[1]<<16)+(J[2]<<8)+J[3],X=r;return r+=$-J.length,Y5=W$8,Y5=[cH0(),cH0()],Y5.position0=0,Y5.position1=0,Y5.postBundlePosition=r,r=X,y6()};Q9[255]=(J)=>{if(J.length==4)return new Date((J[0]*16777216+(J[1]<<16)+(J[2]<<8)+J[3])*1000);else if(J.length==8)return new Date(((J[0]<<22)+(J[1]<<14)+(J[2]<<6)+(J[3]>>2))/1e6+((J[3]&3)*4294967296+J[4]*16777216+(J[5]<<16)+(J[6]<<8)+J[7])*1000);else if(J.length==12)return new Date(((J[0]<<24)+(J[1]<<16)+(J[2]<<8)+J[3])/1e6+((J[4]&128?-281474976710656:0)+J[6]*1099511627776+J[7]*4294967296+J[8]*16777216+(J[9]<<16)+(J[10]<<8)+J[11])*1000);else return new Date("invalid")};function nH0(J){if(ah)ah();let $=y9,X=r,Y=OU,Q=b9,W=E7,K=cY,Z=dZ,G=_Y,V=Y5,q=new Uint8Array(E0.slice(0,y9)),z=G8,H=G8.slice(0,G8.length),v=_8,F=TW,U=J();return y9=$,r=X,OU=Y,b9=Q,E7=W,cY=K,dZ=Z,_Y=G,Y5=V,E0=q,TW=F,G8=z,G8.splice(0,G8.length,...H),_8=v,J8=new DataView(E0.buffer,E0.byteOffset,E0.byteLength),U}function uO(){E0=null,_Y=null,G8=null}var nZ=Array(147);for(let J=0;J<256;J++)nZ[J]=+("1e"+Math.floor(45.15-J*0.30103));var pO=new hY({useRecords:!1}),K$8=pO.unpack,Z$8=pO.unpackMultiple,G$8=pO.unpack,RU={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},V$8=new Float32Array(1),RZ5=new Uint8Array(V$8.buffer,0,4);function aH0(J,$,X){ih=J,nh=$,ah=X}var iO;try{iO=new TextEncoder}catch(J){}var Xf,rH0,xU=typeof Buffer<"u",dO=xU?function(J){return Buffer.allocUnsafeSlow(J)}:Uint8Array,tH0=xU?Buffer:Uint8Array,sH0=xU?4294967296:2144337920,q0,DU,u8,X0=0,C4,v6=null,eH0,q$8=21760,H$8=/[\u0080-\uFFFF]/,r$=Symbol("record-id");class aZ extends hY{constructor(J){super(J);this.offset=0;let $,X,Y,Q,W,K=tH0.prototype.utf8Write?function(k,E){return q0.utf8Write(k,E,q0.byteLength-E)}:iO&&iO.encodeInto?function(k,E){return iO.encodeInto(k,q0.subarray(E)).written}:!1,Z=this;if(!J)J={};let G=J&&J.sequential,V=J.structures||J.saveStructures,q=J.maxSharedStructures;if(q==null)q=V?32:0;if(q>8160)throw Error("Maximum maxSharedStructure is 8160");if(J.structuredClone&&J.moreTypes==null)this.moreTypes=!0;let z=J.maxOwnStructures;if(z==null)z=V?32:64;if(!this.structures&&J.useRecords!=!1)this.structures=[];let H=q>32||z+q>64,v=q+64,F=q+z+64;if(F>8256)throw Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let U=[],j=0,B=0;this.pack=this.encode=function(k,E){if(!q0)q0=new dO(8192),u8=q0.dataView||(q0.dataView=new DataView(q0.buffer,0,8192)),X0=0;if(C4=q0.length-10,C4-X0<2048)q0=new dO(q0.length),u8=q0.dataView||(q0.dataView=new DataView(q0.buffer,0,q0.length)),C4=q0.length-10,X0=0;else X0=X0+7&2147483640;if(X=X0,E&w$8)X0+=E&255;if(W=Z.structuredClone?new Map:null,Z.bundleStrings&&typeof k!=="string")v6=[],v6.size=1/0;else v6=null;if(Q=Z.structures,Q){if(Q.uninitialized)Q=Z._mergeStructures(Z.getStructures());let A=Q.sharedLength||0;if(A>q)throw Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+Q.sharedLength);if(!Q.transitions){Q.transitions=Object.create(null);for(let h=0;h<A;h++){let _=Q[h];if(!_)continue;let m,p=Q.transitions;for(let g=0,J0=_.length;g<J0;g++){let u=_[g];if(m=p[u],!m)m=p[u]=Object.create(null);p=m}p[r$]=h+64}this.lastNamedStructuresLength=A}if(!G)Q.nextId=A+64}if(Y)Y=!1;let c;try{if(Z.randomAccessStructure&&k&&k.constructor&&k.constructor===Object)I(k);else R(k);let A=v6;if(v6)oH0(X,R,0);if(W&&W.idsToInsert){let h=W.idsToInsert.sort((g,J0)=>g.offset>J0.offset?1:-1),_=h.length,m=-1;while(A&&_>0){let g=h[--_].offset+X;if(g<A.stringsPosition+X&&m===-1)m=0;if(g>A.position+X){if(m>=0)m+=6}else{if(m>=0)u8.setUint32(A.position+X,u8.getUint32(A.position+X)+m),m=-1;A=A.previous,_++}}if(m>=0&&A)u8.setUint32(A.position+X,u8.getUint32(A.position+X)+m);if(X0+=h.length*6,X0>C4)T(X0);Z.offset=X0;let p=v$8(q0.subarray(X,X0),h);return W=null,p}if(Z.offset=X0,E&j$8)return q0.start=X,q0.end=X0,q0;return q0.subarray(X,X0)}catch(A){throw c=A,A}finally{if(Q){if(w(),Y&&Z.saveStructures){let A=Q.sharedLength||0,h=q0.subarray(X,X0),_=Jz0(Q,Z);if(!c){if(Z.saveStructures(_,_.isCompatible)===!1)return Z.pack(k,E);if(Z.lastNamedStructuresLength=A,q0.length>1073741824)q0=null;return h}}}if(q0.length>1073741824)q0=null;if(E&B$8)X0=X}};let w=()=>{if(B<10)B++;let k=Q.sharedLength||0;if(Q.length>k&&!G)Q.length=k;if(j>1e4){if(Q.transitions=null,B=0,j=0,U.length>0)U=[]}else if(U.length>0&&!G){for(let E=0,c=U.length;E<c;E++)U[E][r$]=0;U=[]}},M=(k)=>{var E=k.length;if(E<16)q0[X0++]=144|E;else if(E<65536)q0[X0++]=220,q0[X0++]=E>>8,q0[X0++]=E&255;else q0[X0++]=221,u8.setUint32(X0,E),X0+=4;for(let c=0;c<E;c++)R(k[c])},R=(k)=>{if(X0>C4)q0=T(X0);var E=typeof k,c;if(E==="string"){let A=k.length;if(v6&&A>=4&&A<4096){if((v6.size+=A)>q$8){let p,g=(v6[0]?v6[0].length*3+v6[1].length:0)+10;if(X0+g>C4)q0=T(X0+g);let J0;if(v6.position)J0=v6,q0[X0]=200,X0+=3,q0[X0++]=98,p=X0-X,X0+=4,oH0(X,R,0),u8.setUint16(p+X-3,X0-X-p);else q0[X0++]=214,q0[X0++]=98,p=X0-X,X0+=4;v6=["",""],v6.previous=J0,v6.size=0,v6.position=p}let m=H$8.test(k);v6[m?0:1]+=k,q0[X0++]=193,R(m?-A:A);return}let h;if(A<32)h=1;else if(A<256)h=2;else if(A<65536)h=3;else h=5;let _=A*3;if(X0+_>C4)q0=T(X0+_);if(A<64||!K){let m,p,g,J0=X0+h;for(m=0;m<A;m++)if(p=k.charCodeAt(m),p<128)q0[J0++]=p;else if(p<2048)q0[J0++]=p>>6|192,q0[J0++]=p&63|128;else if((p&64512)===55296&&((g=k.charCodeAt(m+1))&64512)===56320)p=65536+((p&1023)<<10)+(g&1023),m++,q0[J0++]=p>>18|240,q0[J0++]=p>>12&63|128,q0[J0++]=p>>6&63|128,q0[J0++]=p&63|128;else q0[J0++]=p>>12|224,q0[J0++]=p>>6&63|128,q0[J0++]=p&63|128;c=J0-X0-h}else c=K(k,X0+h);if(c<32)q0[X0++]=160|c;else if(c<256){if(h<2)q0.copyWithin(X0+2,X0+1,X0+1+c);q0[X0++]=217,q0[X0++]=c}else if(c<65536){if(h<3)q0.copyWithin(X0+3,X0+2,X0+2+c);q0[X0++]=218,q0[X0++]=c>>8,q0[X0++]=c&255}else{if(h<5)q0.copyWithin(X0+5,X0+3,X0+3+c);q0[X0++]=219,u8.setUint32(X0,c),X0+=4}X0+=c}else if(E==="number")if(k>>>0===k)if(k<32||k<128&&this.useRecords===!1||k<64&&!this.randomAccessStructure)q0[X0++]=k;else if(k<256)q0[X0++]=204,q0[X0++]=k;else if(k<65536)q0[X0++]=205,q0[X0++]=k>>8,q0[X0++]=k&255;else q0[X0++]=206,u8.setUint32(X0,k),X0+=4;else if(k>>0===k)if(k>=-32)q0[X0++]=256+k;else if(k>=-128)q0[X0++]=208,q0[X0++]=k+256;else if(k>=-32768)q0[X0++]=209,u8.setInt16(X0,k),X0+=2;else q0[X0++]=210,u8.setInt32(X0,k),X0+=4;else{let A;if((A=this.useFloat32)>0&&k<4294967296&&k>=-2147483648){q0[X0++]=202,u8.setFloat32(X0,k);let h;if(A<4||(h=k*nZ[(q0[X0]&127)<<1|q0[X0+1]>>7])>>0===h){X0+=4;return}else X0--}q0[X0++]=203,u8.setFloat64(X0,k),X0+=8}else if(E==="object"||E==="function")if(!k)q0[X0++]=192;else{if(W){let h=W.get(k);if(h){if(!h.id){let _=W.idsToInsert||(W.idsToInsert=[]);h.id=_.push(h)}q0[X0++]=214,q0[X0++]=112,u8.setUint32(X0,h.id),X0+=4;return}else W.set(k,{offset:X0-X})}let A=k.constructor;if(A===Object)x(k);else if(A===Array)M(k);else if(A===Map)if(this.mapAsEmptyObject)q0[X0++]=128;else{if(c=k.size,c<16)q0[X0++]=128|c;else if(c<65536)q0[X0++]=222,q0[X0++]=c>>8,q0[X0++]=c&255;else q0[X0++]=223,u8.setUint32(X0,c),X0+=4;for(let[h,_]of k)R(h),R(_)}else{for(let h=0,_=Xf.length;h<_;h++){let m=rH0[h];if(k instanceof m){let p=Xf[h];if(p.write){if(p.type)q0[X0++]=212,q0[X0++]=p.type,q0[X0++]=0;let y=p.write.call(this,k);if(y===k)if(Array.isArray(k))M(k);else x(k);else R(y);return}let g=q0,J0=u8,u=X0;q0=null;let f;try{f=p.pack.call(this,k,(y)=>{if(q0=g,g=null,X0+=y,X0>C4)T(X0);return{target:q0,targetView:u8,position:X0-y}},R)}finally{if(g)q0=g,u8=J0,X0=u,C4=q0.length-10}if(f){if(f.length+X0>C4)T(f.length+X0);X0=z$8(f,q0,X0,p.type)}return}}if(Array.isArray(k))M(k);else{if(k.toJSON){let h=k.toJSON();if(h!==k)return R(h)}if(E==="function")return R(this.writeFunction&&this.writeFunction(k));x(k)}}}else if(E==="boolean")q0[X0++]=k?195:194;else if(E==="bigint"){if(k<9223372036854776000&&k>=-9223372036854776000)q0[X0++]=211,u8.setBigInt64(X0,k);else if(k<18446744073709552000&&k>0)q0[X0++]=207,u8.setBigUint64(X0,k);else if(this.largeBigIntToFloat)q0[X0++]=203,u8.setFloat64(X0,Number(k));else if(this.largeBigIntToString)return R(k.toString());else if((this.useBigIntExtension||this.moreTypes)&&k<BigInt(2)**BigInt(1023)&&k>-(BigInt(2)**BigInt(1023))){q0[X0++]=199,X0++,q0[X0++]=66;let A=[],h;do{let _=k&BigInt(255);h=(_&BigInt(128))===(k<BigInt(0)?BigInt(128):BigInt(0)),A.push(_),k>>=BigInt(8)}while(!((k===BigInt(0)||k===BigInt(-1))&&h));q0[X0-2]=A.length;for(let _=A.length;_>0;)q0[X0++]=Number(A[--_]);return}else throw RangeError(k+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string");X0+=8}else if(E==="undefined")if(this.encodeUndefinedAsNil)q0[X0++]=192;else q0[X0++]=212,q0[X0++]=0,q0[X0++]=0;else throw Error("Unknown type: "+E)},N=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?(k)=>{let E;if(this.skipValues){E=[];for(let h in k)if((typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(h))&&!this.skipValues.includes(k[h]))E.push(h)}else E=Object.keys(k);let c=E.length;if(c<16)q0[X0++]=128|c;else if(c<65536)q0[X0++]=222,q0[X0++]=c>>8,q0[X0++]=c&255;else q0[X0++]=223,u8.setUint32(X0,c),X0+=4;let A;if(this.coercibleKeyAsNumber)for(let h=0;h<c;h++){A=E[h];let _=Number(A);R(isNaN(_)?A:_),R(k[A])}else for(let h=0;h<c;h++)R(A=E[h]),R(k[A])}:(k)=>{q0[X0++]=222;let E=X0-X;X0+=2;let c=0;for(let A in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(A))R(A),R(k[A]),c++;if(c>65535)throw Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');q0[E+++X]=c>>8,q0[E+X]=c&255},L=this.useRecords===!1?N:J.progressiveRecords&&!H?(k)=>{let E,c=Q.transitions||(Q.transitions=Object.create(null)),A=X0++-X,h;for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_)){if(E=c[_],E)c=E;else{let m=Object.keys(k),p=c;c=Q.transitions;let g=0;for(let J0=0,u=m.length;J0<u;J0++){let f=m[J0];if(E=c[f],!E)E=c[f]=Object.create(null),g++;c=E}if(A+X+1==X0)X0--,S(c,m,g);else C(c,m,A,g);h=!0,c=p[_]}R(k[_])}if(!h){let _=c[r$];if(_)q0[A+X]=_;else C(c,Object.keys(k),A,0)}}:(k)=>{let E,c=Q.transitions||(Q.transitions=Object.create(null)),A=0;for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_)){if(E=c[_],!E)E=c[_]=Object.create(null),A++;c=E}let h=c[r$];if(h)if(h>=96&&H)q0[X0++]=((h-=96)&31)+96,q0[X0++]=h>>5;else q0[X0++]=h;else S(c,c.__keys__||Object.keys(k),A);for(let _ in k)if(typeof k.hasOwnProperty!=="function"||k.hasOwnProperty(_))R(k[_])},O=typeof this.useRecords=="function"&&this.useRecords,x=O?(k)=>{O(k)?L(k):N(k)}:L,T=(k)=>{let E;if(k>16777216){if(k-X>sH0)throw Error("Packed buffer would be larger than maximum buffer size");E=Math.min(sH0,Math.round(Math.max((k-X)*(k>67108864?1.25:2),4194304)/4096)*4096)}else E=(Math.max(k-X<<2,q0.length-1)>>12)+1<<12;let c=new dO(E);if(u8=c.dataView||(c.dataView=new DataView(c.buffer,0,E)),k=Math.min(k,q0.length),q0.copy)q0.copy(c,0,X,k);else c.set(q0.slice(X,k));return X0-=X,X=0,C4=c.length-10,q0=c},S=(k,E,c)=>{let A=Q.nextId;if(!A)A=64;if(A<v&&this.shouldShareStructure&&!this.shouldShareStructure(E)){if(A=Q.nextOwnId,!(A<F))A=v;Q.nextOwnId=A+1}else{if(A>=F)A=v;Q.nextId=A+1}let h=E.highByte=A>=96&&H?A-96>>5:-1;if(k[r$]=A,k.__keys__=E,Q[A-64]=E,A<v)if(E.isShared=!0,Q.sharedLength=A-63,Y=!0,h>=0)q0[X0++]=(A&31)+96,q0[X0++]=h;else q0[X0++]=A;else{if(h>=0)q0[X0++]=213,q0[X0++]=114,q0[X0++]=(A&31)+96,q0[X0++]=h;else q0[X0++]=212,q0[X0++]=114,q0[X0++]=A;if(c)j+=B*c;if(U.length>=z)U.shift()[r$]=0;U.push(k),R(E)}},C=(k,E,c,A)=>{let h=q0,_=X0,m=C4,p=X;if(q0=DU,X0=0,X=0,!q0)DU=q0=new dO(8192);C4=q0.length-10,S(k,E,A),DU=q0;let g=X0;if(q0=h,X0=_,C4=m,X=p,g>1){let J0=X0+g-1;if(J0>C4)T(J0);let u=c+X;q0.copyWithin(u+g,u+1,X0),q0.set(DU.slice(0,g),u),X0=J0}else q0[c+X]=DU[0]},I=(k)=>{let E=eH0(k,q0,X,X0,Q,T,(c,A,h)=>{if(h)return Y=!0;X0=A;let _=q0;if(R(c),w(),_!==q0)return{position:X0,targetView:u8,target:q0};return X0},this);if(E===0)return x(k);X0=E}}useBuffer(J){q0=J,q0.dataView||(q0.dataView=new DataView(q0.buffer,q0.byteOffset,q0.byteLength)),X0=0}set position(J){X0=J}get position(){return X0}clearSharedData(){if(this.structures)this.structures=[];if(this.typedStructs)this.typedStructs=[]}}rH0=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,lO];Xf=[{pack(J,$,X){let Y=J.getTime()/1000;if((this.useTimestamp32||J.getMilliseconds()===0)&&Y>=0&&Y<4294967296){let{target:Q,targetView:W,position:K}=$(6);Q[K++]=214,Q[K++]=255,W.setUint32(K,Y)}else if(Y>0&&Y<4294967296){let{target:Q,targetView:W,position:K}=$(10);Q[K++]=215,Q[K++]=255,W.setUint32(K,J.getMilliseconds()*4000000+(Y/1000/4294967296>>0)),W.setUint32(K+4,Y)}else if(isNaN(Y)){if(this.onInvalidDate)return $(0),X(this.onInvalidDate());let{target:Q,targetView:W,position:K}=$(3);Q[K++]=212,Q[K++]=255,Q[K++]=255}else{let{target:Q,targetView:W,position:K}=$(15);Q[K++]=199,Q[K++]=12,Q[K++]=255,W.setUint32(K,J.getMilliseconds()*1e6),W.setBigInt64(K+4,BigInt(Math.floor(Y)))}}},{pack(J,$,X){if(this.setAsEmptyObject)return $(0),X({});let Y=Array.from(J),{target:Q,position:W}=$(this.moreTypes?3:0);if(this.moreTypes)Q[W++]=212,Q[W++]=115,Q[W++]=0;X(Y)}},{pack(J,$,X){let{target:Y,position:Q}=$(this.moreTypes?3:0);if(this.moreTypes)Y[Q++]=212,Y[Q++]=101,Y[Q++]=0;X([J.name,J.message,J.cause])}},{pack(J,$,X){let{target:Y,position:Q}=$(this.moreTypes?3:0);if(this.moreTypes)Y[Q++]=212,Y[Q++]=120,Y[Q++]=0;X([J.source,J.flags])}},{pack(J,$){if(this.moreTypes)Jf(J,16,$);else $f(xU?Buffer.from(J):new Uint8Array(J),$)}},{pack(J,$){let X=J.constructor;if(X!==tH0&&this.moreTypes)Jf(J,eh.indexOf(X.name),$);else $f(J,$)}},{pack(J,$){if(this.moreTypes)Jf(J,17,$);else $f(xU?Buffer.from(J):new Uint8Array(J),$)}},{pack(J,$){let{target:X,position:Y}=$(1);X[Y]=193}}];function Jf(J,$,X,Y){let Q=J.byteLength;if(Q+1<256){var{target:W,position:K}=X(4+Q);W[K++]=199,W[K++]=Q+1}else if(Q+1<65536){var{target:W,position:K}=X(5+Q);W[K++]=200,W[K++]=Q+1>>8,W[K++]=Q+1&255}else{var{target:W,position:K,targetView:Z}=X(7+Q);W[K++]=201,Z.setUint32(K,Q+1),K+=4}if(W[K++]=116,W[K++]=$,!J.buffer)J=new Uint8Array(J);W.set(new Uint8Array(J.buffer,J.byteOffset,J.byteLength),K)}function $f(J,$){let X=J.byteLength;var Y,Q;if(X<256){var{target:Y,position:Q}=$(X+2);Y[Q++]=196,Y[Q++]=X}else if(X<65536){var{target:Y,position:Q}=$(X+3);Y[Q++]=197,Y[Q++]=X>>8,Y[Q++]=X&255}else{var{target:Y,position:Q,targetView:W}=$(X+5);Y[Q++]=198,W.setUint32(Q,X),Q+=4}Y.set(J,Q)}function z$8(J,$,X,Y){let Q=J.length;switch(Q){case 1:$[X++]=212;break;case 2:$[X++]=213;break;case 4:$[X++]=214;break;case 8:$[X++]=215;break;case 16:$[X++]=216;break;default:if(Q<256)$[X++]=199,$[X++]=Q;else if(Q<65536)$[X++]=200,$[X++]=Q>>8,$[X++]=Q&255;else $[X++]=201,$[X++]=Q>>24,$[X++]=Q>>16&255,$[X++]=Q>>8&255,$[X++]=Q&255}return $[X++]=Y,$.set(J,X),X+=Q,X}function v$8(J,$){let X,Y=$.length*6,Q=J.length-Y;while(X=$.pop()){let{offset:W,id:K}=X;J.copyWithin(W+Y,W,Q),Y-=6;let Z=W+Y;J[Z++]=214,J[Z++]=105,J[Z++]=K>>24,J[Z++]=K>>16&255,J[Z++]=K>>8&255,J[Z++]=K&255,Q=W}return J}function oH0(J,$,X){if(v6.length>0){u8.setUint32(v6.position+J,X0+X-v6.position-J),v6.stringsPosition=X0-J;let Y=v6;v6=null,$(Y[0]),$(Y[1])}}function Jz0(J,$){return J.isCompatible=(X)=>{let Y=!X||($.lastNamedStructuresLength||0)===X.length;if(!Y)$._mergeStructures(X);return Y},J}function $z0(J,$){eH0=J,Jz0=$}var Xz0=new aZ({useRecords:!1}),F$8=Xz0.pack,U$8=Xz0.pack;var j$8=512,B$8=1024,w$8=2048;var Yf=3,Iq=0,PU=2,nO=1,Wf=16,Qz0=["num","object","string","ascii"];Qz0[Wf]="date";var M$8=[!1,!0,!0,!1,!1,!0,!0,!1],Wz0;try{Function(""),Wz0=!0}catch(J){}var sZ,N$8=typeof Buffer<"u",aO,t$;try{aO=new TextEncoder}catch(J){}var O$8=N$8?function(J,$,X){return J.utf8Write($,X,J.byteLength-X)}:aO&&aO.encodeInto?function(J,$,X){return aO.encodeInto($,J.subarray(X)).written}:!1,SZ5=Symbol("type"),AZ5=Symbol("parent");$z0(Kz0,C$8);function Kz0(J,$,X,Y,Q,W,K,Z){let G=Z.typedStructs||(Z.typedStructs=[]),V=$.dataView,q=(G.lastStringStart||100)+Y,z=$.length-10,H=Y;if(Y>z)$=W(Y),V=$.dataView,Y-=X,H-=X,q-=X,X=0,z=$.length-10;let v,F=q,U=G.transitions||(G.transitions=Object.create(null)),j=G.nextId||G.length,B=j<15?1:j<240?2:j<61440?3:j<15728640?4:0;if(B===0)return 0;Y+=B;let w=[],M,R=0;for(let L in J){let O=J[L],x=U[L];if(!x)U[L]=x={key:L,parent:U,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null};if(Y>z)$=W(Y),V=$.dataView,Y-=X,H-=X,q-=X,F-=X,X=0,z=$.length-10;switch(typeof O){case"number":let T=O;if(j<200||!x.num64){if(T>>0===T&&T<536870912&&T>-520093696){if(T<246&&T>=0&&(x.num8&&!(j>200&&x.num32)||T<32&&!x.num32))U=x.num8||W9(x,Iq,1),$[Y++]=T;else U=x.num32||W9(x,Iq,4),V.setUint32(Y,T,!0),Y+=4;break}else if(T<4294967296&&T>=-2147483648){if(V.setFloat32(Y,T,!0),M$8[$[Y+3]>>>5]){let k;if((k=T*nZ[($[Y+3]&127)<<1|$[Y+2]>>7])>>0===k){U=x.num32||W9(x,Iq,4),Y+=4;break}}}}U=x.num64||W9(x,Iq,8),V.setFloat64(Y,T,!0),Y+=8;break;case"string":let S=O.length;if(v=F-q,(S<<2)+F>z)$=W((S<<2)+F),V=$.dataView,Y-=X,H-=X,q-=X,F-=X,X=0,z=$.length-10;if(S>65280+v>>2){w.push(L,O,Y-H);break}let C,I=F;if(S<64){let k,E,c;for(k=0;k<S;k++)if(E=O.charCodeAt(k),E<128)$[F++]=E;else if(E<2048)C=!0,$[F++]=E>>6|192,$[F++]=E&63|128;else if((E&64512)===55296&&((c=O.charCodeAt(k+1))&64512)===56320)C=!0,E=65536+((E&1023)<<10)+(c&1023),k++,$[F++]=E>>18|240,$[F++]=E>>12&63|128,$[F++]=E>>6&63|128,$[F++]=E&63|128;else C=!0,$[F++]=E>>12|224,$[F++]=E>>6&63|128,$[F++]=E&63|128}else F+=O$8($,O,F),C=F-I>S;if(v<160||v<246&&(x.ascii8||x.string8)){if(C){if(!(U=x.string8))if(G.length>10&&(U=x.ascii8))U.__type=PU,x.ascii8=null,x.string8=U,K(null,0,!0);else U=W9(x,PU,1)}else if(v===0&&!M){M=!0,U=x.ascii0||W9(x,Yf,0);break}else if(!(U=x.ascii8)&&!(G.length>10&&(U=x.string8)))U=W9(x,Yf,1);$[Y++]=v}else U=x.string16||W9(x,PU,2),V.setUint16(Y,v,!0),Y+=2;break;case"object":if(O){if(O.constructor===Date)U=x.date64||W9(x,Wf,8),V.setFloat64(Y,O.getTime(),!0),Y+=8;else w.push(L,O,R);break}else if(x=Yz0(x,Y,V,-10),x)U=x,Y=sZ;else w.push(L,O,R);break;case"boolean":U=x.num8||x.ascii8||W9(x,Iq,1),$[Y++]=O?249:248;break;case"undefined":if(x=Yz0(x,Y,V,-9),x)U=x,Y=sZ;else w.push(L,O,R);break;default:w.push(L,O,R)}R++}for(let L=0,O=w.length;L<O;){let x=w[L++],T=w[L++],S=w[L++],C=U[x];if(!C)U[x]=C={key:x,parent:U,enumerationOffset:S-R,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null};let I;if(T){let k;if(v=F-q,v<65280)if(U=C.object16,U)k=2;else if(U=C.object32)k=4;else U=W9(C,nO,2),k=2;else U=C.object32||W9(C,nO,4),k=4;if(I=K(T,F),typeof I==="object")F=I.position,V=I.targetView,$=I.target,q-=X,Y-=X,H-=X,X=0;else F=I;if(k===2)V.setUint16(Y,v,!0),Y+=2;else V.setUint32(Y,v,!0),Y+=4}else U=C.object16||W9(C,nO,2),V.setInt16(Y,T===null?-10:-9,!0),Y+=2;R++}let N=U[r$];if(N==null){N=Z.typedStructs.length;let L=[],O=U,x,T;while((T=O.__type)!==void 0){let S=O.__size;O=O.__parent,x=O.key;let C=[T,S,x];if(O.enumerationOffset)C.push(O.enumerationOffset);L.push(C),O=O.parent}L.reverse(),U[r$]=N,Z.typedStructs[N]=L,K(null,0,!0)}switch(B){case 1:if(N>=16)return 0;$[H]=N+32;break;case 2:if(N>=256)return 0;$[H]=56,$[H+1]=N;break;case 3:if(N>=65536)return 0;$[H]=57,V.setUint16(H+1,N,!0);break;case 4:if(N>=16777216)return 0;V.setUint32(H,(N<<8)+58,!0);break}if(Y<q){if(q===F)return Y;$.copyWithin(Y,q,F),F+=Y-q,G.lastStringStart=Y-H}else if(Y>q){if(q===F)return Y;return G.lastStringStart=Y-H,Kz0(J,$,X,H,Q,W,K,Z)}return F}function Yz0(J,$,X,Y){let Q;if(Q=J.ascii8||J.num8)return X.setInt8($,Y,!0),sZ=$+1,Q;if(Q=J.string16||J.object16)return X.setInt16($,Y,!0),sZ=$+2,Q;if(Q=J.num32)return X.setUint32($,3758096640+Y,!0),sZ=$+4,Q;if(Q=J.num64)return X.setFloat64($,NaN,!0),X.setInt8($,Y),sZ=$+8,Q;sZ=$;return}function W9(J,$,X){let Y=Qz0[$]+(X<<3),Q=J[Y]||(J[Y]=Object.create(null));return Q.__type=$,Q.__size=X,Q.__parent=J,Q}function R$8(J){if(!(J instanceof Map))return J;let $=J.get("typed")||[];if(Object.isFrozen($))$=$.map((Q)=>Q.slice(0));let X=J.get("named"),Y=Object.create(null);for(let Q=0,W=$.length;Q<W;Q++){let K=$[Q],Z=Y;for(let[G,V,q]of K){let z=Z[q];if(!z)Z[q]=z={key:q,parent:Z,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null};Z=W9(z,G,V)}Z[r$]=Q}return $.transitions=Y,this.typedStructs=$,this.lastTypedStructuresLength=$.length,X}var Qf=Symbol.for("source");function D$8(J,$,X,Y){let Q=J[$++]-32;if(Q>=24)switch(Q){case 24:Q=J[$++];break;case 25:Q=J[$++]+(J[$++]<<8);break;case 26:Q=J[$++]+(J[$++]<<8)+(J[$++]<<16);break;case 27:Q=J[$++]+(J[$++]<<8)+(J[$++]<<16)+(J[$++]<<24);break}let W=Y.typedStructs&&Y.typedStructs[Q];if(!W){if(J=Uint8Array.prototype.slice.call(J,$,X),X-=$,$=0,!Y.getStructures)throw Error(`Reference to shared structure ${Q} without getStructures method`);if(Y._mergeStructures(Y.getStructures()),!Y.typedStructs)throw Error("Could not find any shared typed structures");if(Y.lastTypedStructuresLength=Y.typedStructs.length,W=Y.typedStructs[Q],!W)throw Error("Could not find typed structure "+Q)}var{construct:K,fullConstruct:Z}=W;if(!K){K=W.construct=function(){},Z=W.fullConstruct=function(){},Z.prototype=Y.structPrototype??{};var G=K.prototype=Y.structPrototype?Object.create(Y.structPrototype):{};let q=[],z=0,H;for(let v=0,F=W.length;v<F;v++){let U=W[v],[j,B,w,M]=U;if(w==="__proto__")w="__proto_";let R={key:w,offset:z};if(M)q.splice(v+M,0,R);else q.push(R);let N;switch(B){case 0:N=()=>0;break;case 1:N=(O,x)=>{let T=O.bytes[x+R.offset];return T>=246?Eq(T):T};break;case 2:N=(O,x)=>{let T=O.bytes,C=(T.dataView||(T.dataView=new DataView(T.buffer,T.byteOffset,T.byteLength))).getUint16(x+R.offset,!0);return C>=65280?Eq(C&255):C};break;case 4:N=(O,x)=>{let T=O.bytes,C=(T.dataView||(T.dataView=new DataView(T.buffer,T.byteOffset,T.byteLength))).getUint32(x+R.offset,!0);return C>=4294967040?Eq(C&255):C};break}R.getRef=N,z+=B;let L;switch(j){case Yf:if(H&&!H.next)H.next=R;H=R,R.multiGetCount=0,L=function(O){let{bytes:x,position:T}=O,S=z+T,C=N(O,T);if(typeof C!=="number")return C;let I,k=R.next;while(k){if(I=k.getRef(O,T),typeof I==="number")break;else I=null;k=k.next}if(I==null)I=O.bytesEnd-S;if(O.srcString)return O.srcString.slice(C,I);return gH0(x,C+S,I-C)};break;case PU:case nO:if(H&&!H.next)H.next=R;H=R,L=function(O){let x=O.position,T=z+x,S=N(O,x);if(typeof S!=="number")return S;let C=O.bytes,I,k=R.next;while(k){if(I=k.getRef(O,x),typeof I==="number")break;else I=null;k=k.next}if(I==null)I=O.bytesEnd-T;if(j===PU)return C.toString("utf8",S+T,I+T);else{t$=O;try{return Y.unpack(C,{start:S+T,end:I+T})}finally{t$=null}}};break;case Iq:switch(B){case 4:L=function(O){let x=O.bytes,T=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength)),S=O.position+R.offset,C=T.getInt32(S,!0);if(C<536870912){if(C>-520093696)return C;if(C>-536870912)return Eq(C&255)}let I=T.getFloat32(S,!0),k=nZ[(x[S+3]&127)<<1|x[S+2]>>7];return(k*I+(I>0?0.5:-0.5)>>0)/k};break;case 8:L=function(O){let x=O.bytes,S=(x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength))).getFloat64(O.position+R.offset,!0);if(isNaN(S)){let C=x[O.position+R.offset];if(C>=246)return Eq(C)}return S};break;case 1:L=function(O){let T=O.bytes[O.position+R.offset];return T<246?T:Eq(T)};break}break;case Wf:L=function(O){let x=O.bytes,T=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength));return new Date(T.getFloat64(O.position+R.offset,!0))};break}R.get=L}if(Wz0){let v=[],F=[],U=0,j;for(let w of q){if(Y.alwaysLazyProperty&&Y.alwaysLazyProperty(w.key)){j=!0;continue}Object.defineProperty(G,w.key,{get:x$8(w.get),enumerable:!0});let M="v"+U++;F.push(M),v.push("o["+JSON.stringify(w.key)+"]="+M+"(s)")}if(j)v.push("__proto__:this");let B=Function(...F,"var c=this;return function(s){var o=new c();"+v.join(";")+";return o;}").apply(Z,q.map((w)=>w.get));Object.defineProperty(G,"toJSON",{value(w){return B.call(this,this[Qf])}})}else Object.defineProperty(G,"toJSON",{value(v){let F={};for(let U=0,j=q.length;U<j;U++){let B=q[U].key;F[B]=this[B]}return F}})}var V=new K;return V[Qf]={bytes:J,position:$,srcString:"",bytesEnd:X},V}function Eq(J){switch(J){case 246:return null;case 247:return;case 248:return!1;case 249:return!0}throw Error("Unknown constant")}function x$8(J){return function(){return J(this[Qf])}}function P$8(){if(t$)t$.bytes=Uint8Array.prototype.slice.call(t$.bytes,t$.position,t$.bytesEnd),t$.position=0,t$.bytesEnd=t$.bytes.length}function C$8(J,$){if($.typedStructs){let Y=new Map;Y.set("named",J),Y.set("typed",$.typedStructs),J=Y}let X=$.lastTypedStructuresLength||0;return J.isCompatible=(Y)=>{let Q=!0;if(Y instanceof Map){if((Y.get("named")||[]).length!==($.lastNamedStructuresLength||0))Q=!1;if((Y.get("typed")||[]).length!==X)Q=!1}else if(Y instanceof Array||Array.isArray(Y)){if(Y.length!==($.lastNamedStructuresLength||0))Q=!1}if(!Q)$._mergeStructures(Y);return Q},$.lastTypedStructuresLength=$.typedStructs&&$.typedStructs.length,J}aH0(D$8,R$8,P$8);var b$8=process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED!==void 0&&process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase()==="true";if(!b$8){let J;try{if(J=Rz0(),J)lH0(J.extractStrings)}catch($){}}var hp={};DQ(hp,{zodErrorsIntegration:()=>_b,wrapMcpServerWithSentry:()=>mb,withScope:()=>g9,withMonitor:()=>$X,withIsolationScope:()=>uY,withActiveSpan:()=>mW,vercelAIIntegration:()=>OP,validateOpenTelemetrySetup:()=>_p,updateSpanName:()=>Tf,trpcMiddleware:()=>fb,tediousIntegration:()=>jP,suppressTracing:()=>lU,supabaseIntegration:()=>cb,startSpanManual:()=>uU,startSpan:()=>h7,startSession:()=>sU,startNewTrace:()=>sf,startInactiveSpan:()=>nf,spotlightIntegration:()=>HP,spanToTraceHeader:()=>SU,spanToJSON:()=>t0,spanToBaggageHeader:()=>hf,setupKoaErrorHandler:()=>_z1,setupHapiErrorHandler:()=>Vz1,setupFastifyErrorHandler:()=>OG1,setupExpressErrorHandler:()=>EZ1,setupConnectErrorHandler:()=>Qv1,setUser:()=>Wb,setTags:()=>Yb,setTag:()=>Qb,setNodeAsyncContextStrategy:()=>$x,setMeasurement:()=>pf,setHttpStatus:()=>yq,setExtras:()=>$b,setExtra:()=>Xb,setCurrentClient:()=>Lb,setContext:()=>Jb,rewriteFramesIntegration:()=>Ab,requestDataIntegration:()=>eU,redisIntegration:()=>sx,profiler:()=>hb,prismaIntegration:()=>$P,preloadOpenTelemetry:()=>FU1,postgresIntegration:()=>ex,parameterize:()=>RR,onUnhandledRejectionIntegration:()=>Lx,onUncaughtExceptionIntegration:()=>wx,nodeContextIntegration:()=>zx,nativeNodeFetchIntegration:()=>Vx,mysqlIntegration:()=>dx,mysql2Integration:()=>nx,mongooseIntegration:()=>gx,mongoIntegration:()=>ux,modulesIntegration:()=>Bx,makeNodeTransport:()=>kP,lruMemoizerIntegration:()=>mx,logger:()=>pb,localVariablesIntegration:()=>jx,linkedErrorsIntegration:()=>tU,lastEventId:()=>Kb,koaIntegration:()=>GP,knexIntegration:()=>Cv1,kafkaIntegration:()=>yx,isInitialized:()=>nU,instrumentSupabaseClient:()=>kR,initWithoutDefaultIntegrations:()=>jU1,initOpenTelemetry:()=>cP,init:()=>_P,inboundFiltersIntegration:()=>rU,httpIntegration:()=>Wx,hapiIntegration:()=>WP,graphqlIntegration:()=>bx,getTraceMetaTags:()=>Rb,getTraceData:()=>pY,getSpanStatusFromHttpCode:()=>bq,getSpanDescendants:()=>AU,getSentryRelease:()=>SP,getRootSpan:()=>i8,getIsolationScope:()=>w1,getGlobalScope:()=>mY,getDefaultIntegrationsWithoutPerformance:()=>Ap,getDefaultIntegrations:()=>cp,getCurrentScope:()=>b1,getClient:()=>A0,getAutoPerformanceIntegrations:()=>PP,getActiveSpan:()=>oJ,genericPoolIntegration:()=>BP,generateInstrumentOnce:()=>G1,functionToStringIntegration:()=>oU,fsIntegration:()=>EK1,flush:()=>Zb,fastifyIntegration:()=>cx,extraErrorDataIntegration:()=>Tb,expressIntegration:()=>xx,expressErrorHandler:()=>Yg,eventFiltersIntegration:()=>xR,endSession:()=>GG,disableAnrDetectionForCallback:()=>sK1,defaultStackParser:()=>AP,dedupeIntegration:()=>Cb,dataloaderIntegration:()=>wF1,cron:()=>OU1,createTransport:()=>iq,createSentryWinstonTransport:()=>gF1,createGetModuleFromFilename:()=>IP,continueTrace:()=>af,contextLinesIntegration:()=>vx,consoleLoggingIntegration:()=>lb,consoleIntegration:()=>J2,connectIntegration:()=>qP,close:()=>Gb,childProcessIntegration:()=>RP,captureSession:()=>qb,captureMessage:()=>dq,captureFeedback:()=>ub,captureException:()=>F8,captureEvent:()=>iU,captureConsoleIntegration:()=>Pb,captureCheckIn:()=>dU,anrIntegration:()=>aK1,amqplibIntegration:()=>MP,addIntegration:()=>Fb,addEventProcessor:()=>Vb,addBreadcrumb:()=>k4,SentryContextManager:()=>xP,Scope:()=>S5,SEMANTIC_ATTRIBUTE_SENTRY_SOURCE:()=>h8,SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE:()=>_7,SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN:()=>v1,SEMANTIC_ATTRIBUTE_SENTRY_OP:()=>X1,SDK_VERSION:()=>N6,NodeClient:()=>Dj});var pb={};DQ(pb,{warn:()=>LQ8,trace:()=>jQ8,info:()=>wQ8,fmt:()=>Nb,fatal:()=>NQ8,error:()=>MQ8,debug:()=>BQ8});import{format as UQ8}from"node:util";var x0=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;var N6="9.22.0";var e0=globalThis;function r5(){return kW(e0),e0}function kW(J){let $=J.__SENTRY__=J.__SENTRY__||{};return $.version=$.version||N6,$[N6]=$[N6]||{}}function oZ(J,$,X=e0){let Y=X.__SENTRY__=X.__SENTRY__||{},Q=Y[N6]=Y[N6]||{};return Q[J]||(Q[J]=$())}var Dz0=Object.prototype.toString;function dJ(J){switch(Dz0.call(J)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object WebAssembly.Exception]":return!0;default:return fY(J,Error)}}function rO(J,$){return Dz0.call(J)===`[object ${$}]`}function xz0(J){return rO(J,"ErrorEvent")}function rZ(J){return rO(J,"String")}function tZ(J){return typeof J==="object"&&J!==null&&"__sentry_template_string__"in J&&"__sentry_template_values__"in J}function CU(J){return J===null||tZ(J)||typeof J!=="object"&&typeof J!=="function"}function I7(J){return rO(J,"Object")}function Pz0(J){return typeof Event<"u"&&fY(J,Event)}function Cz0(J){return typeof Element<"u"&&fY(J,Element)}function Tz0(J){return rO(J,"RegExp")}function S7(J){return Boolean(J?.then&&typeof J.then==="function")}function kz0(J){return I7(J)&&"nativeEvent"in J&&"preventDefault"in J&&"stopPropagation"in J}function fY(J,$){try{return J instanceof $}catch(X){return!1}}function tO(J){return!!(typeof J==="object"&&J!==null&&(J.__isVue||J._isVue))}var y$8=e0,m$8=80;function Ez0(J,$={}){if(!J)return"<unknown>";try{let X=J,Y=5,Q=[],W=0,K=0,Z=" > ",G=Z.length,V,q=Array.isArray($)?$:$.keyAttrs,z=!Array.isArray($)&&$.maxStringLength||m$8;while(X&&W++<Y){if(V=u$8(X,q),V==="html"||W>1&&K+Q.length*G+V.length>=z)break;Q.push(V),K+=V.length,X=X.parentNode}return Q.reverse().join(Z)}catch(X){return"<unknown>"}}function u$8(J,$){let X=J,Y=[];if(!X?.tagName)return"";if(y$8.HTMLElement){if(X instanceof HTMLElement&&X.dataset){if(X.dataset.sentryComponent)return X.dataset.sentryComponent;if(X.dataset.sentryElement)return X.dataset.sentryElement}}Y.push(X.tagName.toLowerCase());let Q=$?.length?$.filter((K)=>X.getAttribute(K)).map((K)=>[K,X.getAttribute(K)]):null;if(Q?.length)Q.forEach((K)=>{Y.push(`[${K[0]}="${K[1]}"]`)});else{if(X.id)Y.push(`#${X.id}`);let K=X.className;if(K&&rZ(K)){let Z=K.split(/\s+/);for(let G of Z)Y.push(`.${G}`)}}let W=["aria-label","type","name","title","alt"];for(let K of W){let Z=X.getAttribute(K);if(Z)Y.push(`[${K}="${Z}"]`)}return Y.join("")}var l$8="Sentry Logger ",iJ=["debug","info","warn","error","log","assert","trace"],Sq={};function F6(J){if(!("console"in e0))return J();let $=e0.console,X={},Y=Object.keys(Sq);Y.forEach((Q)=>{let W=Sq[Q];X[Q]=$[Q],$[Q]=W});try{return J()}finally{Y.forEach((Q)=>{$[Q]=X[Q]})}}function g$8(){let J=!1,$={enable:()=>{J=!0},disable:()=>{J=!1},isEnabled:()=>J};if(x0)iJ.forEach((X)=>{$[X]=(...Y)=>{if(J)F6(()=>{e0.console[X](`${l$8}[${X}]:`,...Y)})}});else iJ.forEach((X)=>{$[X]=()=>{return}});return $}var t=oZ("logger",g$8);function K9(J,$=0){if(typeof J!=="string"||$===0)return J;return J.length<=$?J:`${J.slice(0,$)}...`}function vf(J,$){let X=J,Y=X.length;if(Y<=150)return X;if($>Y)$=Y;let Q=Math.max($-60,0);if(Q<5)Q=0;let W=Math.min(Q+140,Y);if(W>Y-5)W=Y;if(W===Y)Q=Math.max(W-140,0);if(X=X.slice(Q,W),Q>0)X=`'{snip} ${X}`;if(W<Y)X+=" {snip}";return X}function EW(J,$){if(!Array.isArray(J))return"";let X=[];for(let Y=0;Y<J.length;Y++){let Q=J[Y];try{if(tO(Q))X.push("[VueViewModel]");else X.push(String(Q))}catch(W){X.push("[value cannot be serialized]")}}return X.join($)}function Iz0(J,$,X=!1){if(!rZ(J))return!1;if(Tz0($))return $.test(J);if(rZ($))return X?J===$:J.includes($);return!1}function IW(J,$=[],X=!1){return $.some((Y)=>Iz0(J,Y,X))}function Ff(J,$,X){if(!($ in J))return;let Y=J[$];if(typeof Y!=="function")return;let Q=X(Y);if(typeof Q==="function")cz0(Q,Y);try{J[$]=Q}catch{x0&&t.log(`Failed to replace method "${$}" in object`,J)}}function O6(J,$,X){try{Object.defineProperty(J,$,{value:X,writable:!0,configurable:!0})}catch(Y){x0&&t.log(`Failed to add non-enumerable property "${$}" to object`,J)}}function cz0(J,$){try{let X=$.prototype||{};J.prototype=$.prototype=X,O6(J,"__sentry_original__",$)}catch(X){}}function Uf(J){return J.__sentry_original__}function eO(J){if(dJ(J))return{message:J.message,name:J.name,stack:J.stack,...Az0(J)};else if(Pz0(J)){let $={type:J.type,target:Sz0(J.target),currentTarget:Sz0(J.currentTarget),...Az0(J)};if(typeof CustomEvent<"u"&&fY(J,CustomEvent))$.detail=J.detail;return $}else return J}function Sz0(J){try{return Cz0(J)?Ez0(J):Object.prototype.toString.call(J)}catch($){return"<unknown>"}}function Az0(J){if(typeof J==="object"&&J!==null){let $={};for(let X in J)if(Object.prototype.hasOwnProperty.call(J,X))$[X]=J[X];return $}else return{}}function jf(J,$=40){let X=Object.keys(eO(J));X.sort();let Y=X[0];if(!Y)return"[object has no keys]";if(Y.length>=$)return K9(Y,$);for(let Q=X.length;Q>0;Q--){let W=X.slice(0,Q).join(", ");if(W.length>$)continue;if(Q===X.length)return W;return K9(W,$)}return""}function p$8(){let J=e0;return J.crypto||J.msCrypto}function m6(J=p$8()){let $=()=>Math.random()*16;try{if(J?.randomUUID)return J.randomUUID().replace(/-/g,"");if(J?.getRandomValues)$=()=>{let X=new Uint8Array(1);return J.getRandomValues(X),X[0]}}catch(X){}return([1e7]+1000+4000+8000+100000000000).replace(/[018]/g,(X)=>(X^($()&15)>>X/4).toString(16))}function _z0(J){return J.exception?.values?.[0]}function SW(J){let{message:$,event_id:X}=J;if($)return $;let Y=_z0(J);if(Y){if(Y.type&&Y.value)return`${Y.type}: ${Y.value}`;return Y.type||Y.value||X||"<unknown>"}return X||"<unknown>"}function wf(J,$,X){let Y=J.exception=J.exception||{},Q=Y.values=Y.values||[],W=Q[0]=Q[0]||{};if(!W.value)W.value=$||"";if(!W.type)W.type=X||"Error"}function AW(J,$){let X=_z0(J);if(!X)return;let Y={type:"generic",handled:!0},Q=X.mechanism;if(X.mechanism={...Y,...Q,...$},$&&"data"in $){let W={...Q?.data,...$.data};X.mechanism.data=W}}var d$8=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function Bf(J){return parseInt(J||"",10)}function Lf(J){let $=J.match(d$8)||[],X=Bf($[1]),Y=Bf($[2]),Q=Bf($[3]);return{buildmetadata:$[5],major:isNaN(X)?void 0:X,minor:isNaN(Y)?void 0:Y,patch:isNaN(Q)?void 0:Q,prerelease:$[4]}}function JR(J){if(i$8(J))return!0;try{O6(J,"__sentry_captured__",!0)}catch($){}return!1}function i$8(J){try{return J.__sentry_captured__}catch{}}var hz0=1000;function bY(){return Date.now()/hz0}function n$8(){let{performance:J}=e0;if(!J?.now)return bY;let $=Date.now()-J.now(),X=J.timeOrigin==null?$:J.timeOrigin;return()=>{return(X+J.now())/hz0}}var m9=n$8();function fz0(J){let $=m9(),X={sid:m6(),init:!0,timestamp:$,started:$,duration:0,status:"ok",errors:0,ignoreDuration:!1,toJSON:()=>a$8(X)};if(J)yY(X,J);return X}function yY(J,$={}){if($.user){if(!J.ipAddress&&$.user.ip_address)J.ipAddress=$.user.ip_address;if(!J.did&&!$.did)J.did=$.user.id||$.user.email||$.user.username}if(J.timestamp=$.timestamp||m9(),$.abnormal_mechanism)J.abnormal_mechanism=$.abnormal_mechanism;if($.ignoreDuration)J.ignoreDuration=$.ignoreDuration;if($.sid)J.sid=$.sid.length===32?$.sid:m6();if($.init!==void 0)J.init=$.init;if(!J.did&&$.did)J.did=`${$.did}`;if(typeof $.started==="number")J.started=$.started;if(J.ignoreDuration)J.duration=void 0;else if(typeof $.duration==="number")J.duration=$.duration;else{let X=J.timestamp-J.started;J.duration=X>=0?X:0}if($.release)J.release=$.release;if($.environment)J.environment=$.environment;if(!J.ipAddress&&$.ipAddress)J.ipAddress=$.ipAddress;if(!J.userAgent&&$.userAgent)J.userAgent=$.userAgent;if(typeof $.errors==="number")J.errors=$.errors;if($.status)J.status=$.status}function bz0(J,$){let X={};if($)X={status:$};else if(J.status==="ok")X={status:"exited"};yY(J,X)}function a$8(J){return{sid:`${J.sid}`,init:J.init,started:new Date(J.started*1000).toISOString(),timestamp:new Date(J.timestamp*1000).toISOString(),status:J.status,errors:J.errors,did:typeof J.did==="number"||typeof J.did==="string"?`${J.did}`:void 0,duration:J.duration,abnormal_mechanism:J.abnormal_mechanism,attrs:{release:J.release,environment:J.environment,ip_address:J.ipAddress,user_agent:J.userAgent}}}function cW(J,$,X=2){if(!$||typeof $!=="object"||X<=0)return $;if(J&&Object.keys($).length===0)return J;let Y={...J};for(let Q in $)if(Object.prototype.hasOwnProperty.call($,Q))Y[Q]=cW(Y[Q],$[Q],X-1);return Y}var Mf="_sentrySpan";function eZ(J,$){if($)O6(J,Mf,$);else delete J[Mf]}function nJ(J){return J[Mf]}function u9(){return m6()}function l9(){return m6().substring(16)}var s$8=100;class S5{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:u9(),sampleRand:Math.random()}}clone(){let J=new S5;if(J._breadcrumbs=[...this._breadcrumbs],J._tags={...this._tags},J._extra={...this._extra},J._contexts={...this._contexts},this._contexts.flags)J._contexts.flags={values:[...this._contexts.flags.values]};return J._user=this._user,J._level=this._level,J._session=this._session,J._transactionName=this._transactionName,J._fingerprint=this._fingerprint,J._eventProcessors=[...this._eventProcessors],J._attachments=[...this._attachments],J._sdkProcessingMetadata={...this._sdkProcessingMetadata},J._propagationContext={...this._propagationContext},J._client=this._client,J._lastEventId=this._lastEventId,eZ(J,nJ(this)),J}setClient(J){this._client=J}setLastEventId(J){this._lastEventId=J}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(J){this._scopeListeners.push(J)}addEventProcessor(J){return this._eventProcessors.push(J),this}setUser(J){if(this._user=J||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session)yY(this._session,{user:J});return this._notifyScopeListeners(),this}getUser(){return this._user}setTags(J){return this._tags={...this._tags,...J},this._notifyScopeListeners(),this}setTag(J,$){return this._tags={...this._tags,[J]:$},this._notifyScopeListeners(),this}setExtras(J){return this._extra={...this._extra,...J},this._notifyScopeListeners(),this}setExtra(J,$){return this._extra={...this._extra,[J]:$},this._notifyScopeListeners(),this}setFingerprint(J){return this._fingerprint=J,this._notifyScopeListeners(),this}setLevel(J){return this._level=J,this._notifyScopeListeners(),this}setTransactionName(J){return this._transactionName=J,this._notifyScopeListeners(),this}setContext(J,$){if($===null)delete this._contexts[J];else this._contexts[J]=$;return this._notifyScopeListeners(),this}setSession(J){if(!J)delete this._session;else this._session=J;return this._notifyScopeListeners(),this}getSession(){return this._session}update(J){if(!J)return this;let $=typeof J==="function"?J(this):J,X=$ instanceof S5?$.getScopeData():I7($)?J:void 0,{tags:Y,extra:Q,user:W,contexts:K,level:Z,fingerprint:G=[],propagationContext:V}=X||{};if(this._tags={...this._tags,...Y},this._extra={...this._extra,...Q},this._contexts={...this._contexts,...K},W&&Object.keys(W).length)this._user=W;if(Z)this._level=Z;if(G.length)this._fingerprint=G;if(V)this._propagationContext=V;return this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._session=void 0,eZ(this,void 0),this._attachments=[],this.setPropagationContext({traceId:u9(),sampleRand:Math.random()}),this._notifyScopeListeners(),this}addBreadcrumb(J,$){let X=typeof $==="number"?$:s$8;if(X<=0)return this;let Y={timestamp:bY(),...J,message:J.message?K9(J.message,2048):J.message};if(this._breadcrumbs.push(Y),this._breadcrumbs.length>X)this._breadcrumbs=this._breadcrumbs.slice(-X),this._client?.recordDroppedEvent("buffer_overflow","log_item");return this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(J){return this._attachments.push(J),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:nJ(this)}}setSDKProcessingMetadata(J){return this._sdkProcessingMetadata=cW(this._sdkProcessingMetadata,J,2),this}setPropagationContext(J){return this._propagationContext=J,this}getPropagationContext(){return this._propagationContext}captureException(J,$){let X=$?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture exception!"),X;let Y=Error("Sentry syntheticException");return this._client.captureException(J,{originalException:J,syntheticException:Y,...$,event_id:X},this),X}captureMessage(J,$,X){let Y=X?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture message!"),Y;let Q=Error(J);return this._client.captureMessage(J,$,{originalException:J,syntheticException:Q,...X,event_id:Y},this),Y}captureEvent(J,$){let X=$?.event_id||m6();if(!this._client)return t.warn("No client configured on scope - will not capture event!"),X;return this._client.captureEvent(J,{...$,event_id:X},this),X}_notifyScopeListeners(){if(!this._notifyingListeners)this._notifyingListeners=!0,this._scopeListeners.forEach((J)=>{J(this)}),this._notifyingListeners=!1}}function Aq(){return oZ("defaultCurrentScope",()=>new S5)}function A7(){return oZ("defaultIsolationScope",()=>new S5)}class mz0{constructor(J,$){let X;if(!J)X=new S5;else X=J;let Y;if(!$)Y=new S5;else Y=$;this._stack=[{scope:X}],this._isolationScope=Y}withScope(J){let $=this._pushScope(),X;try{X=J($)}catch(Y){throw this._popScope(),Y}if(S7(X))return X.then((Y)=>{return this._popScope(),Y},(Y)=>{throw this._popScope(),Y});return this._popScope(),X}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){let J=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:J}),J}_popScope(){if(this._stack.length<=1)return!1;return!!this._stack.pop()}}function cq(){let J=r5(),$=kW(J);return $.stack=$.stack||new mz0(Aq(),A7())}function o$8(J){return cq().withScope(J)}function r$8(J,$){let X=cq();return X.withScope(()=>{return X.getStackTop().scope=J,$(J)})}function yz0(J){return cq().withScope(()=>{return J(cq().getIsolationScope())})}function uz0(){return{withIsolationScope:yz0,withScope:o$8,withSetScope:r$8,withSetIsolationScope:(J,$)=>{return yz0($)},getCurrentScope:()=>cq().getScope(),getIsolationScope:()=>cq().getIsolationScope()}}function Nf(J){let $=r5(),X=kW($);X.acs=J}function c7(J){let $=kW(J);if($.acs)return $.acs;return uz0()}function b1(){let J=r5();return c7(J).getCurrentScope()}function w1(){let J=r5();return c7(J).getIsolationScope()}function mY(){return oZ("globalScope",()=>new S5)}function g9(...J){let $=r5(),X=c7($);if(J.length===2){let[Y,Q]=J;if(!Y)return X.withScope(Q);return X.withSetScope(Y,Q)}return X.withScope(J[0])}function uY(...J){let $=r5(),X=c7($);if(J.length===2){let[Y,Q]=J;if(!Y)return X.withIsolationScope(Q);return X.withSetIsolationScope(Y,Q)}return X.withIsolationScope(J[0])}function A0(){return b1().getClient()}function _q(J){let $=J.getPropagationContext(),{traceId:X,parentSpanId:Y,propagationSpanId:Q}=$,W={trace_id:X,span_id:Q||l9()};if(Y)W.parent_span_id=Y;return W}var h8="sentry.source",_7="sentry.sample_rate",Of="sentry.previous_trace_sample_rate",X1="sentry.op",v1="sentry.origin";var $R="sentry.measurement_unit",XR="sentry.measurement_value",aJ="sentry.custom_span_name",hq="sentry.profile_id",fq="sentry.exclusive_time",Rf="cache.hit",Df="cache.key",xf="cache.item_size";var Pf=0,_W=1,Z9=2;function bq(J){if(J<400&&J>=100)return{code:1};if(J>=400&&J<500)switch(J){case 401:return{code:2,message:"unauthenticated"};case 403:return{code:2,message:"permission_denied"};case 404:return{code:2,message:"not_found"};case 409:return{code:2,message:"already_exists"};case 413:return{code:2,message:"failed_precondition"};case 429:return{code:2,message:"resource_exhausted"};case 499:return{code:2,message:"cancelled"};default:return{code:2,message:"invalid_argument"}}if(J>=500&&J<600)switch(J){case 501:return{code:2,message:"unimplemented"};case 503:return{code:2,message:"unavailable"};case 504:return{code:2,message:"deadline_exceeded"};default:return{code:2,message:"internal_error"}}return{code:2,message:"unknown_error"}}function yq(J,$){J.setAttribute("http.response.status_code",$);let X=bq($);if(X.message!=="unknown_error")J.setStatus(X)}var lz0="_sentryScope",gz0="_sentryIsolationScope";function TU(J,$,X){if(J)O6(J,gz0,X),O6(J,lz0,$)}function sJ(J){return{scope:J[lz0],isolationScope:J[gz0]}}function p9(J){if(typeof J==="boolean")return Number(J);let $=typeof J==="string"?parseFloat(J):J;if(typeof $!=="number"||isNaN($)||$<0||$>1)return;return $}var kU="sentry-",dz0=/^sentry-/,iz0=8192;function hW(J){let $=JG(J);if(!$)return;let X=Object.entries($).reduce((Y,[Q,W])=>{if(Q.match(dz0)){let K=Q.slice(kU.length);Y[K]=W}return Y},{});if(Object.keys(X).length>0)return X;else return}function fW(J){if(!J)return;let $=Object.entries(J).reduce((X,[Y,Q])=>{if(Q)X[`${kU}${Y}`]=Q;return X},{});return YR($)}function JG(J){if(!J||!rZ(J)&&!Array.isArray(J))return;if(Array.isArray(J))return J.reduce(($,X)=>{let Y=pz0(X);return Object.entries(Y).forEach(([Q,W])=>{$[Q]=W}),$},{});return pz0(J)}function pz0(J){return J.split(",").map(($)=>$.split("=").map((X)=>{try{return decodeURIComponent(X.trim())}catch{return}})).reduce(($,[X,Y])=>{if(X&&Y)$[X]=Y;return $},{})}function YR(J){if(Object.keys(J).length===0)return;return Object.entries(J).reduce(($,[X,Y],Q)=>{let W=`${encodeURIComponent(X)}=${encodeURIComponent(Y)}`,K=Q===0?W:`${$},${W}`;if(K.length>iz0)return x0&&t.warn(`Not adding key: ${X} with val: ${Y} to baggage header due to exceeding baggage size limits.`),$;else return K},"")}var EU=new RegExp("^[ \\t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ \\t]*$");function nz0(J){if(!J)return;let $=J.match(EU);if(!$)return;let X;if($[3]==="1")X=!0;else if($[3]==="0")X=!1;return{traceId:$[1],parentSampled:X,parentSpanId:$[2]}}function $G(J,$){let X=nz0(J),Y=hW($);if(!X?.traceId)return{traceId:u9(),sampleRand:Math.random()};let Q=t$8(X,Y);if(Y)Y.sample_rand=Q.toString();let{traceId:W,parentSpanId:K,parentSampled:Z}=X;return{traceId:W,parentSpanId:K,sampled:Z,dsc:Y||{},sampleRand:Q}}function bW(J=u9(),$=l9(),X){let Y="";if(X!==void 0)Y=X?"-1":"-0";return`${J}-${$}${Y}`}function t$8(J,$){let X=p9($?.sample_rand);if(X!==void 0)return X;let Y=p9($?.sample_rate);if(Y&&J?.parentSampled!==void 0)return J.parentSampled?Math.random()*Y:Y+Math.random()*(1-Y);else return Math.random()}var QR=0,WR=1,az0=!1;function oz0(J){let{spanId:$,traceId:X}=J.spanContext(),{data:Y,op:Q,parent_span_id:W,status:K,origin:Z,links:G}=t0(J);return{parent_span_id:W,span_id:$,trace_id:X,data:Y,op:Q,status:K,origin:Z,links:G}}function yW(J){let{spanId:$,traceId:X,isRemote:Y}=J.spanContext(),Q=Y?$:t0(J).parent_span_id,W=sJ(J).scope,K=Y?W?.getPropagationContext().propagationSpanId||l9():$;return{parent_span_id:Q,span_id:K,trace_id:X}}function SU(J){let{traceId:$,spanId:X}=J.spanContext(),Y=JX(J);return bW($,X,Y)}function XG(J){if(J&&J.length>0)return J.map(({context:{spanId:$,traceId:X,traceFlags:Y,...Q},attributes:W})=>({span_id:$,trace_id:X,sampled:Y===WR,attributes:W,...Q}));else return}function G9(J){if(typeof J==="number")return sz0(J);if(Array.isArray(J))return J[0]+J[1]/1e9;if(J instanceof Date)return sz0(J.getTime());return m9()}function sz0(J){return J>9999999999?J/1000:J}function t0(J){if(JX8(J))return J.getSpanJSON();let{spanId:$,traceId:X}=J.spanContext();if(e$8(J)){let{attributes:Y,startTime:Q,name:W,endTime:K,status:Z,links:G}=J,V="parentSpanId"in J?J.parentSpanId:("parentSpanContext"in J)?J.parentSpanContext?.spanId:void 0;return{span_id:$,trace_id:X,data:Y,description:W,parent_span_id:V,start_timestamp:G9(Q),timestamp:G9(K)||void 0,status:YG(Z),op:Y[X1],origin:Y[v1],links:XG(G)}}return{span_id:$,trace_id:X,start_timestamp:0,data:{}}}function e$8(J){let $=J;return!!$.attributes&&!!$.startTime&&!!$.name&&!!$.endTime&&!!$.status}function JX8(J){return typeof J.getSpanJSON==="function"}function JX(J){let{traceFlags:$}=J.spanContext();return $===WR}function YG(J){if(!J||J.code===Pf)return;if(J.code===_W)return"ok";return J.message||"unknown_error"}var IU="_sentryChildSpans",Cf="_sentryRootSpan";function mq(J,$){let X=J[Cf]||J;if(O6($,Cf,X),J[IU])J[IU].add($);else O6(J,IU,new Set([$]))}function AU(J){let $=new Set;function X(Y){if($.has(Y))return;else if(JX(Y)){$.add(Y);let Q=Y[IU]?Array.from(Y[IU]):[];for(let W of Q)X(W)}}return X(J),Array.from($)}function i8(J){return J[Cf]||J}function oJ(){let J=r5(),$=c7(J);if($.getActiveSpan)return $.getActiveSpan();return nJ(b1())}function cU(){if(!az0)F6(()=>{console.warn("[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.")}),az0=!0}function Tf(J,$){J.updateName($),J.setAttributes({[h8]:"custom",[aJ]:$})}var Ef="?",rz0=/\(error: (.*)\)/,tz0=/captureMessage|captureException/;function ZR(...J){let $=J.sort((X,Y)=>X[0]-Y[0]).map((X)=>X[1]);return(X,Y=0,Q=0)=>{let W=[],K=X.split(`
|
|
413
413
|
`);for(let Z=Y;Z<K.length;Z++){let G=K[Z];if(G.length>1024)continue;let V=rz0.test(G)?G.replace(rz0,"$1"):G;if(V.match(/\S*Error: /))continue;for(let q of $){let z=q(V);if(z){W.push(z);break}}if(W.length>=50+Q)break}return ez0(W.slice(Q))}}function If(J){if(Array.isArray(J))return ZR(...J);return J}function ez0(J){if(!J.length)return[];let $=Array.from(J);if(/sentryWrapped/.test(KR($).function||""))$.pop();if($.reverse(),tz0.test(KR($).function||"")){if($.pop(),tz0.test(KR($).function||""))$.pop()}return $.slice(0,50).map((X)=>({...X,filename:X.filename||KR($).filename,function:X.function||"?"}))}function KR(J){return J[J.length-1]||{}}var kf="<anonymous>";function _U(J){try{if(!J||typeof J!=="function")return kf;return J.name||kf}catch($){return kf}}function GR(J){let $=J.exception;if($){let X=[];try{return $.values.forEach((Y)=>{if(Y.stacktrace.frames)X.push(...Y.stacktrace.frames)}),X}catch(Y){return}}return}var VR={},Jv0={};function uq(J,$){VR[J]=VR[J]||[],VR[J].push($)}function lq(J,$){if(!Jv0[J]){Jv0[J]=!0;try{$()}catch(X){x0&&t.error(`Error while instrumenting ${J}`,X)}}}function gq(J,$){let X=J&&VR[J];if(!X)return;for(let Y of X)try{Y($)}catch(Q){x0&&t.error(`Error while triggering instrumentation handler.
|
|
414
414
|
Type: ${J}
|
|
415
415
|
Name: ${_U(Y)}
|
|
@@ -551,4 +551,4 @@ wzUfQXDpZndkqxHilERgvPXLEsTTCMF/W+C8gsO9AoGAZWt+CU6zQhqMBB5MMGZf
|
|
|
551
551
|
UE5WUS/oOd4jHBqwVxBTLOAPlmnQSp1uiTu2K0NrnnvZ6Zi/+tIsjbtxhomeOmnH
|
|
552
552
|
+wsk9n+Bif4P7VTvwqc9FY4Ya79PEJK+J/xx/mldUEz3R63RiRXZAaDddO7yCQFX
|
|
553
553
|
W8eeuIMLKU6dSq0yu22+nyU=
|
|
554
|
-
-----END PRIVATE KEY-----`;var SC=process.env.PORT??8080,ni="0.14.1",ai;((Q)=>{Q.READY="WEBSERVER.READY";Q.STOPPED="WEBSERVER.STOPPED";Q.ERROR="WEBSERVER.ERROR";Q.UPGRADE="WEBSERVER.UPGRADE"})(ai||={});class Qz extends $1{static instance=new Qz;_webserver=IC.default();_internalHttpServer;constructor(){super();this._webserver.use(($,X,Y)=>{X.header("Access-Control-Allow-Origin","*"),Y()}),this._webserver.get("/",($,X)=>{X.json({status:"OK",version:ni,runtime:"node"})}),this._webserver.use(IC.default.static("assets",{dotfiles:"allow"}));let J=dK.instance.assetsLibraryPath;if(process.env.NODE_ENV!=="production"&&J)this._webserver.use(($,X,Y)=>{let Q=kC6.join(J,$.path);dK.instance.syncAsset(Q),Y()}),this._webserver.use(IC.default.static(J,{dotfiles:"allow"}))}start(){if(!this._internalHttpServer)this._internalHttpServer=TC6.createServer({key:EC,cert:kC},this._webserver),this._internalHttpServer.on("upgrade",this._onUpgrade),this._internalHttpServer.on("error",this._onError),this._internalHttpServer.on("close",this._onStopped);else n.warning("WebServer.start(): server already started!");this._internalHttpServer.listen(SC,this._onStarted),console.info(`WebServer.start(): Server running on port ${SC}.`)}stop(){if(this._internalHttpServer)return new Promise((J,$)=>{this._internalHttpServer.close((X)=>{if(X)$(X);else J(!0)})});else return n.warning("WebServer.stop(): server not started."),Promise.resolve(!1)}_onStarted=()=>{this.emitWithGlobal("WEBSERVER.READY",{})};_onUpgrade=(J,$,X)=>{this.emitWithGlobal("WEBSERVER.UPGRADE",{req:J,socket:$,head:X})};_onError=(J)=>{n.error(`WebServer._onError(): ${J.message}`),this.emitWithGlobal("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{this.emitWithGlobal("WEBSERVER.STOPPED",{})}}var B3;((U)=>{U.BUILD_PACKETS="build_packets";U.ENTITIES_EMIT_UPDATES="entities_emit_updates";U.ENTITIES_TICK="entities_tick";U.NETWORK_SYNCHRONIZE="network_synchronize";U.NETWORK_SYNCHRONIZE_CLEANUP="network_synchronize_cleanup";U.PHYSICS_CLEANUP="physics_cleanup";U.PHYSICS_STEP="physics_step";U.SEND_ALL_PACKETS="send_all_packets";U.SEND_PACKETS="send_packets";U.SERIALIZE_FREE_BUFFERS="serialize_free_buffers";U.SERIALIZE_PACKETS="serialize_packets";U.SERIALIZE_PACKETS_ENCODE="serialize_packets_encode";U.SIMULATION_STEP="simulation_step";U.TICKER_TICK="ticker_tick";U.WORLD_TICK="world_tick"})(B3||={});class T6{static getProcessStats(J=!1){let $=process.memoryUsage(),X={jsHeapSizeMb:{value:$.heapUsed/1024/1024,unit:"megabyte"},jsHeapCapacityMb:{value:$.heapTotal/1024/1024,unit:"megabyte"},jsHeapUsagePercent:{value:$.heapUsed/$.heapTotal,unit:"percent"},processHeapSizeMb:{value:$.heapUsed/1024/1024,unit:"megabyte"},rssSizeMb:{value:$.rss/1024/1024,unit:"megabyte"}};if(J)return X;return Object.fromEntries(Object.entries(X).map(([Y,Q])=>[Y,Q.value]))}static initializeSentry(J,$=50){_P({dsn:J,release:ni,environment:process.env.NODE_ENV||"development",tracesSampleRate:1,initialScope:{tags:{gameId:process.env.HYTOPIA_GAME_ID??"unknown",gameSlug:process.env.HYTOPIA_GAME_SLUG??"unknown",lobbyId:process.env.HYTOPIA_LOBBY_ID??"unknown",region:process.env.REGION??"unknown"}},beforeSend:(X)=>{return X.extra=T6.getProcessStats(),X},beforeSendTransaction:(X)=>{if(X.contexts?.trace?.op==="ticker_tick"){let Q=X?.start_timestamp,W=X?.timestamp;if(!Q||!W)return null;if((W-Q)*1000>$)return X.measurements=T6.getProcessStats(!0),X}return null}})}static startSpan(J,$){if(nU())return h7({attributes:J.attributes,name:J.operation,op:J.operation},$);else return $()}static sentry(){return hp}}if(!gO)console.warn("Connection: msgpackr native acceleration is not enabled, using fallback implementation.");var tN1=new aZ({useFloat32:RU.ALWAYS}),IC6=5000;class v$ extends $1{static _cachedPacketsSerializedBuffer=new Map;_closeTimeout=null;_ws;_wsBinding=!1;_wt;_wtBinding=!1;_wtReliableReader;_wtReliableWriter;_wtUnreliableReader;_wtUnreliableWriter;id;constructor(J,$,X){super();this.id=TH0(),this.onPacket(_0.PacketId.HEARTBEAT,this._onHeartbeatPacket);let Y=()=>{$1.globalInstance.emit("CONNECTION.OPENED",{connection:this,session:X})};if(J)this.bindWs(J),Y();else if($)this.bindWt($).then(Y).catch((Q)=>{this._onClose(),n.error(`Connection.constructor(): Failed to bind WebTransport. Error: ${Q}`)})}static clearCachedPacketsSerializedBuffers(){if(v$._cachedPacketsSerializedBuffer.size>0)v$._cachedPacketsSerializedBuffer.clear()}static serializePackets(J){for(let X of J)if(!_0.isValidPacket(X))return n.error(`Connection.serializePackets(): Invalid packet payload: ${JSON.stringify(X)}`);let $=v$._cachedPacketsSerializedBuffer.get(J);if($)return $;return T6.startSpan({operation:"serialize_packets",attributes:{packets:J.length,packetIds:J.map((X)=>X[0]).join(",")}},(X)=>{let Y=tN1.pack(J);if(Y.byteLength>65536)Y=EC6(Y,{level:1});return X?.setAttribute("serializedBytes",Y.byteLength),v$._cachedPacketsSerializedBuffer.set(J,Y),Y})}bindWs(J){this._wsBinding=!0;let $=this._handleReconnect();if(this._cleanupConnections(),this._ws=J,this._ws.binaryType="nodebuffer",this._ws.onmessage=(X)=>this._onMessage(X.data),this._ws.onclose=this._onClose,this._ws.onerror=this._onError,this._wsBinding=!1,this._signalConnectionId(),$)this.emitWithGlobal("CONNECTION.RECONNECTED",{connection:this})}async bindWt(J){this._wtBinding=!0;let $=this._handleReconnect();this._cleanupConnections(),J.userData.onclose=this._onClose,J.closed.catch(()=>{}).finally(()=>J.userData.onclose?.()),this._wt=J,await this._wt.ready;let X=this._wt.incomingBidirectionalStreams.getReader();try{let{value:Y}=await X.read();if(Y)this._wtReliableReader=Y.readable,this._wtReliableWriter=Y.writable.getWriter()}finally{X.releaseLock()}if(this._wtUnreliableReader=this._wt.datagrams.readable,this._wtUnreliableWriter=this._wt.datagrams.createWritable().getWriter(),(async()=>{if(!this._wtReliableReader)return;let Y=this._wt,Q=_0.createPacketBufferUnframer();for await(let W of this._wtReliableReader){if(Y!==this._wt)return;for(let K of Q(W))this._onMessage(K)}})().catch(()=>this._wt?.close()),(async()=>{if(!this._wtUnreliableReader)return;let Y=this._wt;for await(let Q of this._wtUnreliableReader){if(Y!==this._wt)return;this._onMessage(Q)}})().catch(()=>this._wt?.close()),this._wtBinding=!1,this._signalConnectionId(),$)this.emitWithGlobal("CONNECTION.RECONNECTED",{connection:this})}disconnect(){try{this._ws?.close(),this._wt?.close()}catch(J){n.error(`Connection.disconnect(): Connection disconnect failed. Error: ${J}`)}}onPacket(J,$){this.on("CONNECTION.PACKET_RECEIVED",({packet:X})=>{if(X[0]===J)$(X)})}send(J,$=!0){if(this._closeTimeout||this._wsBinding||this._wtBinding)return;if(!this._ws&&!this._wt)return;let X=this._ws&&this._ws.readyState===Cq.default.OPEN,Y=this._wt&&(this._wt.state==="connected"||this._wt.state==="draining");if(!X&&!Y)return;T6.startSpan({operation:"send_packets"},()=>{try{let Q=v$.serializePackets(J);if(!Q)return;if(Y)if($)this._wtReliableWriter?.write(_0.framePacketBuffer(Q)).catch(()=>{n.error("Connection.send(): WebTransport reliable write failed, connection closing?")});else this._wtUnreliableWriter?.write(Q).catch(()=>{n.error("Connection.send(): WebTransport unreliable write failed, connection closing?")});else this._ws.send(Q);this.emitWithGlobal("CONNECTION.PACKETS_SENT",{connection:this,packets:J})}catch(Q){n.error(`Connection.send(): Packet send failed. Error: ${Q}`)}})}_onHeartbeatPacket=()=>{this.send([_0.createPacket(_0.bidirectionalPackets.heartbeatPacketDefinition,null)],!0)};_onMessage=(J)=>{try{let $=this._deserialize(J);if(!$)return;this.emitWithGlobal("CONNECTION.PACKET_RECEIVED",{connection:this,packet:$})}catch($){n.error(`Connection._ws.onmessage(): Error: ${$}`)}};_onClose=()=>{this.emitWithGlobal("CONNECTION.DISCONNECTED",{connection:this}),this._closeTimeout=setTimeout(()=>{this.emitWithGlobal("CONNECTION.CLOSED",{connection:this}),this.offAll()},IC6)};_onError=(J)=>{this.emitWithGlobal("CONNECTION.ERROR",{connection:this,error:J})};_cleanupConnections(){if(this._ws)this._ws.onmessage=()=>{},this._ws.onclose=()=>{},this._ws.onerror=()=>{};if(this._wt)this._wt.userData.onclose=()=>{};this._signalKill(),this._ws=void 0,this._wt=void 0,this._wtReliableReader=void 0,this._wtReliableWriter=void 0,this._wtUnreliableReader=void 0,this._wtUnreliableWriter=void 0}_deserialize(J){let $=tN1.unpack(J);if(!$||typeof $!=="object"||typeof $[0]!=="number")return n.error(`Connection._deserialize(): Invalid packet format. Packet: ${JSON.stringify($)}`);if(!_0.isValidPacket($))return n.error(`Connection._deserialize(): Invalid packet payload. Packet: ${JSON.stringify($)}`);return $}_handleReconnect(){let J=!!this._ws||!!this._wt;if(J&&this._closeTimeout)clearTimeout(this._closeTimeout),this._closeTimeout=null;return J}_signalConnectionId(){this.send([_0.createPacket(_0.bidirectionalPackets.connectionPacketDefinition,{i:this.id})])}_signalKill(){this.send([_0.createPacket(_0.bidirectionalPackets.connectionPacketDefinition,{k:!0})])}}class JB{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach(($)=>{$.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter(($)=>$.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let $=this._nextLightId;return this._lights.set($,J),this._nextLightId++,$}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}class w5{_map=new Map;_values=[];_isDirty=!1;get size(){return this._map.size}get valuesArray(){if(this._isDirty)this._syncArray();return this._values}get(J){return this._map.get(J)}set(J,$){let X=this._map.has(J);if(this._map.set(J,$),!X)this._values.push($);else this._isDirty=!0;return this}has(J){return this._map.has(J)}delete(J){let $=this._map.delete(J);if($)this._isDirty=!0;return $}clear(){this._map.clear(),this._values.length=0,this._isDirty=!1}forEach(J,$){this._map.forEach((X,Y)=>{J.call($,X,Y,this)})}keys(){return this._map.keys()}values(){return this._map.values()}entries(){return this._map.entries()}[Symbol.iterator](){return this._map[Symbol.iterator]()}_syncArray(){this._values.length=0;for(let J of this._map.values())this._values.push(J);this._isDirty=!1}}var eN1;((X)=>{X[X.POINTLIGHT=0]="POINTLIGHT";X[X.SPOTLIGHT=1]="SPOTLIGHT"})(eN1||={});var si;((H)=>{H.DESPAWN="LIGHT.DESPAWN";H.SET_ANGLE="LIGHT.SET_ANGLE";H.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";H.SET_COLOR="LIGHT.SET_COLOR";H.SET_DISTANCE="LIGHT.SET_DISTANCE";H.SET_INTENSITY="LIGHT.SET_INTENSITY";H.SET_OFFSET="LIGHT.SET_OFFSET";H.SET_PENUMBRA="LIGHT.SET_PENUMBRA";H.SET_POSITION="LIGHT.SET_POSITION";H.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";H.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";H.SPAWN="LIGHT.SPAWN"})(si||={});class oi extends $1{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.fatalError("Either attachedToEntity or position must be set, but not both.");super();n.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 n.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&&this._offset.x===J.x&&this._offset.y===J.y&&this._offset.z===J.z)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&&this._position.x===J.x&&this._position.y===J.y&&this._position.z===J.z)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 n.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 n.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 V1.serializeLight(this)}}var ri;((A)=>{A.BURST="PARTICLE_EMITTER.BURST";A.DESPAWN="PARTICLE_EMITTER.DESPAWN";A.SET_ALPHA_TEST="PARTICLE_EMITTER.SET_ALPHA_TEST";A.SET_ATTACHED_TO_ENTITY="PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY";A.SET_ATTACHED_TO_ENTITY_NODE_NAME="PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME";A.SET_COLOR_END="PARTICLE_EMITTER.SET_COLOR_END";A.SET_COLOR_END_VARIANCE="PARTICLE_EMITTER.SET_COLOR_END_VARIANCE";A.SET_COLOR_START="PARTICLE_EMITTER.SET_COLOR_START";A.SET_COLOR_START_VARIANCE="PARTICLE_EMITTER.SET_COLOR_START_VARIANCE";A.SET_GRAVITY="PARTICLE_EMITTER.SET_GRAVITY";A.SET_LIFETIME="PARTICLE_EMITTER.SET_LIFETIME";A.SET_LIFETIME_VARIANCE="PARTICLE_EMITTER.SET_LIFETIME_VARIANCE";A.SET_MAX_PARTICLES="PARTICLE_EMITTER.SET_MAX_PARTICLES";A.SET_OFFSET="PARTICLE_EMITTER.SET_OFFSET";A.SET_OPACITY_END="PARTICLE_EMITTER.SET_OPACITY_END";A.SET_OPACITY_END_VARIANCE="PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE";A.SET_OPACITY_START="PARTICLE_EMITTER.SET_OPACITY_START";A.SET_OPACITY_START_VARIANCE="PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE";A.SET_PAUSED="PARTICLE_EMITTER.SET_PAUSED";A.SET_POSITION="PARTICLE_EMITTER.SET_POSITION";A.SET_POSITION_VARIANCE="PARTICLE_EMITTER.SET_POSITION_VARIANCE";A.SET_RATE="PARTICLE_EMITTER.SET_RATE";A.SET_RATE_VARIANCE="PARTICLE_EMITTER.SET_RATE_VARIANCE";A.SET_SIZE_END="PARTICLE_EMITTER.SET_SIZE_END";A.SET_SIZE_END_VARIANCE="PARTICLE_EMITTER.SET_SIZE_END_VARIANCE";A.SET_SIZE_START="PARTICLE_EMITTER.SET_SIZE_START";A.SET_SIZE_START_VARIANCE="PARTICLE_EMITTER.SET_SIZE_START_VARIANCE";A.SET_TEXTURE_URI="PARTICLE_EMITTER.SET_TEXTURE_URI";A.SET_TRANSPARENT="PARTICLE_EMITTER.SET_TRANSPARENT";A.SET_VELOCITY="PARTICLE_EMITTER.SET_VELOCITY";A.SET_VELOCITY_VARIANCE="PARTICLE_EMITTER.SET_VELOCITY_VARIANCE";A.SPAWN="PARTICLE_EMITTER.SPAWN"})(ri||={});class ti extends $1{_id;_alphaTest;_attachedToEntity;_attachedToEntityNodeName;_colorEnd;_colorEndVariance;_colorStart;_colorStartVariance;_gravity;_lifetime;_lifetimeVariance;_maxParticles;_offset;_opacityEnd;_opacityEndVariance;_opacityStart;_opacityStartVariance;_paused;_position;_positionVariance;_rate;_rateVariance;_sizeEnd;_sizeEndVariance;_sizeStart;_sizeStartVariance;_sizeVariance;_textureUri;_transparent;_velocity;_velocityVariance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.fatalError("Either attachedToEntity or position must be set, but not both.");if(!J.textureUri)n.fatalError("ParticleEmitter.constructor(): textureUri must be provided.");super();this._alphaTest=J.alphaTest??0.05,this._attachedToEntity=J.attachedToEntity,this._attachedToEntityNodeName=J.attachedToEntityNodeName,this._colorEnd=J.colorEnd,this._colorEndVariance=J.colorEndVariance,this._colorStart=J.colorStart,this._colorStartVariance=J.colorStartVariance,this._gravity=J.gravity,this._lifetime=J.lifetime,this._lifetimeVariance=J.lifetimeVariance,this._maxParticles=J.maxParticles,this._offset=J.offset,this._opacityEnd=J.opacityEnd,this._opacityEndVariance=J.opacityEndVariance,this._opacityStart=J.opacityStart,this._opacityStartVariance=J.opacityStartVariance,this._paused=!1,this._position=J.position,this._positionVariance=J.positionVariance,this._rate=J.rate,this._rateVariance=J.rateVariance,this._sizeEnd=J.sizeEnd,this._sizeEndVariance=J.sizeEndVariance,this._sizeStart=J.sizeStart,this._sizeStartVariance=J.sizeStartVariance,this._textureUri=J.textureUri,this._transparent=J.transparent,this._velocity=J.velocity,this._velocityVariance=J.velocityVariance}get id(){return this._id}get alphaTest(){return this._alphaTest}get attachedToEntity(){return this._attachedToEntity}get attachedToEntityNodeName(){return this._attachedToEntityNodeName}get colorEnd(){return this._colorEnd}get colorEndVariance(){return this._colorEndVariance}get colorStart(){return this._colorStart}get colorStartVariance(){return this._colorStartVariance}get gravity(){return this._gravity}get isSpawned(){return this._id!==void 0}get lifetime(){return this._lifetime}get lifetimeVariance(){return this._lifetimeVariance}get maxParticles(){return this._maxParticles}get offset(){return this._offset}get opacityEnd(){return this._opacityEnd}get opacityEndVariance(){return this._opacityEndVariance}get opacityStart(){return this._opacityStart}get opacityStartVariance(){return this._opacityStartVariance}get paused(){return this._paused}get position(){return this._position}get positionVariance(){return this._positionVariance}get rate(){return this._rate}get rateVariance(){return this._rateVariance}get sizeEnd(){return this._sizeEnd}get sizeEndVariance(){return this._sizeEndVariance}get sizeStart(){return this._sizeStart}get sizeStartVariance(){return this._sizeStartVariance}get sizeVariance(){return this._sizeVariance}get textureUri(){return this._textureUri}get transparent(){return this._transparent}get velocity(){return this._velocity}get velocityVariance(){return this._velocityVariance}get world(){return this._world}setAlphaTest(J){if(this._alphaTest===J)return;if(this._alphaTest=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_ALPHA_TEST",{particleEmitter:this,alphaTest:J})}setAttachedToEntity(J){if(!J.isSpawned)return n.error(`ParticleEmitter.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,"PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY",{particleEmitter:this,entity:J})}setAttachedToEntityNodeName(J){if(this._attachedToEntityNodeName===J)return;if(this._attachedToEntityNodeName=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME",{particleEmitter:this,attachedToEntityNodeName:J})}setColorEnd(J){if(this._colorEnd&&this._colorEnd.r===J.r&&this._colorEnd.g===J.g&&this._colorEnd.b===J.b)return;if(this._colorEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_END",{particleEmitter:this,colorEnd:J})}setColorEndVariance(J){if(this._colorEndVariance&&this._colorEndVariance.r===J.r&&this._colorEndVariance.g===J.g&&this._colorEndVariance.b===J.b)return;if(this._colorEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_END_VARIANCE",{particleEmitter:this,colorEndVariance:J})}setColorStart(J){if(this._colorStart&&this._colorStart.r===J.r&&this._colorStart.g===J.g&&this._colorStart.b===J.b)return;if(this._colorStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_START",{particleEmitter:this,colorStart:J})}setColorStartVariance(J){if(this._colorStartVariance&&this._colorStartVariance.r===J.r&&this._colorStartVariance.g===J.g&&this._colorStartVariance.b===J.b)return;if(this._colorStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_START_VARIANCE",{particleEmitter:this,colorStartVariance:J})}setGravity(J){if(this._gravity&&this._gravity.x===J.x&&this._gravity.y===J.y&&this._gravity.z===J.z)return;if(this._gravity=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_GRAVITY",{particleEmitter:this,gravity:J})}setLifetime(J){if(this._lifetime===J)return;if(this._lifetime=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_LIFETIME",{particleEmitter:this,lifetime:J})}setLifetimeVariance(J){if(this._lifetimeVariance===J)return;if(this._lifetimeVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_LIFETIME_VARIANCE",{particleEmitter:this,lifetimeVariance:J})}setMaxParticles(J){if(this._maxParticles===J)return;if(this._maxParticles=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_MAX_PARTICLES",{particleEmitter:this,maxParticles:J})}setOffset(J){if(this._offset&&this._offset.x===J.x&&this._offset.y===J.y&&this._offset.z===J.z)return;if(this._offset=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OFFSET",{particleEmitter:this,offset:J})}setOpacityEnd(J){if(this._opacityEnd===J)return;if(this._opacityEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_END",{particleEmitter:this,opacityEnd:J})}setOpacityEndVariance(J){if(this._opacityEndVariance===J)return;if(this._opacityEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE",{particleEmitter:this,opacityEndVariance:J})}setOpacityStart(J){if(this._opacityStart===J)return;if(this._opacityStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_START",{particleEmitter:this,opacityStart:J})}setOpacityStartVariance(J){if(this._opacityStartVariance===J)return;if(this._opacityStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE",{particleEmitter:this,opacityStartVariance:J})}setPosition(J){if(this._position&&this._position.x===J.x&&this._position.y===J.y&&this._position.z===J.z)return;if(this._position=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_POSITION",{particleEmitter:this,position:J})}setPositionVariance(J){if(this._positionVariance&&this._positionVariance.x===J.x&&this._positionVariance.y===J.y&&this._positionVariance.z===J.z)return;if(this._positionVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_POSITION_VARIANCE",{particleEmitter:this,positionVariance:J})}setRate(J){if(this._rate===J)return;if(this._rate=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_RATE",{particleEmitter:this,rate:J})}setRateVariance(J){if(this._rateVariance===J)return;if(this._rateVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_RATE_VARIANCE",{particleEmitter:this,rateVariance:J})}setSizeEnd(J){if(this._sizeEnd===J)return;if(this._sizeEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_END",{particleEmitter:this,sizeEnd:J})}setSizeEndVariance(J){if(this._sizeEndVariance===J)return;if(this._sizeEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_END_VARIANCE",{particleEmitter:this,sizeEndVariance:J})}setSizeStart(J){if(this._sizeStart===J)return;if(this._sizeStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_START",{particleEmitter:this,sizeStart:J})}setSizeStartVariance(J){if(this._sizeStartVariance===J)return;if(this._sizeStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_START_VARIANCE",{particleEmitter:this,sizeStartVariance:J})}setTextureUri(J){if(this._textureUri===J)return;if(this._textureUri=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_TEXTURE_URI",{particleEmitter:this,textureUri:J})}setTransparent(J){if(this._transparent===J)return;if(this._transparent=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_TRANSPARENT",{particleEmitter:this,transparent:J})}setVelocity(J){if(this._velocity&&this._velocity.x===J.x&&this._velocity.y===J.y&&this._velocity.z===J.z)return;if(this._velocity=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_VELOCITY",{particleEmitter:this,velocity:J})}setVelocityVariance(J){if(this._velocityVariance&&this._velocityVariance.x===J.x&&this._velocityVariance.y===J.y&&this._velocityVariance.z===J.z)return;if(this._velocityVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_VELOCITY_VARIANCE",{particleEmitter:this,velocityVariance:J})}burst(J){if(this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.BURST",{particleEmitter:this,count:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.particleEmitterManager.unregisterParticleEmitter(this),this.emitWithWorld(this._world,"PARTICLE_EMITTER.DESPAWN",{particleEmitter:this}),this._id=void 0,this._world=void 0}restart(){if(!this._paused)return;if(this._paused=!1,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_PAUSED",{particleEmitter:this,paused:this._paused})}stop(){if(this._paused)return;if(this._paused=!0,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_PAUSED",{particleEmitter:this,paused:this._paused})}spawn(J){if(this.isSpawned)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return n.error(`ParticleEmitter.spawn(): Attached entity ${this._attachedToEntity.id} must be spawned before spawning ParticleEmitter!`);this._id=J.particleEmitterManager.registerParticleEmitter(this),this._world=J,this.emitWithWorld(J,"PARTICLE_EMITTER.SPAWN",{particleEmitter:this})}serialize(){return V1.serializeParticleEmitter(this)}}var SC6={x:0,y:-32,z:0},ei=60,Jn;((Q)=>{Q.STEP_START="SIMULATION.STEP_START";Q.STEP_END="SIMULATION.STEP_END";Q.DEBUG_RAYCAST="SIMULATION.DEBUG_RAYCAST";Q.DEBUG_RENDER="SIMULATION.DEBUG_RENDER"})(Jn||={});class $B extends $1{_colliderMap=new jU;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_debugRenderingFilterFlags;_rapierEventQueue;_rapierSimulation;_world;constructor(J,$=ei,X=SC6){super();this._rapierEventQueue=new W8.EventQueue(!0),this._rapierSimulation=new W8.World(X),this._rapierSimulation.timestep=Math.fround(1/$),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}createRawCollider(J,$){return this._rapierSimulation.createCollider(J,$)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J,$=W8.QueryFilterFlags.EXCLUDE_FIXED){this._debugRenderingEnabled=J,this._debugRenderingFilterFlags=$}getContactManifolds(J,$){let X=[];return this._rapierSimulation.narrowPhase.contactPair(J,$,(Y,Q)=>{if(Y.numContacts()===0)return;let W=Y.normal(),K=[];for(let Z=0;Z<Y.numSolverContacts();Z++)K.push(Y.solverContactPoint(Z));X.push({contactPoints:K,localNormalA:!Q?Y.localNormal1():Y.localNormal2(),localNormalB:!Q?Y.localNormal2():Y.localNormal1(),normal:!Q?W:{x:-W.x,y:-W.y,z:-W.z}})}),X}intersectionsWithRawShape(J,$,X,Y={}){let Q=new Set,W=[];return this._rapierSimulation.intersectionsWithShape($,X,J,(K)=>{let Z=this._colliderMap.getColliderHandleBlockType(K.handle);if(Z&&!Q.has(Z))return Q.add(Z),W.push({intersectedBlockType:Z}),!0;let G=this._colliderMap.getColliderHandleEntity(K.handle);if(G&&!Q.has(G))return Q.add(G),W.push({intersectedEntity:G}),!0;return!0},Y.filterFlags,Y.filterGroups,Y.filterExcludeCollider,Y.filterExcludeRigidBody,Y.filterPredicate),W}raycast(J,$,X,Y={}){let Q=new W8.Ray(J,$),W=this._rapierSimulation.castRay(Q,X,Y.solidMode??!0,Y.filterFlags,Y.filterGroups,Y.filterExcludeCollider,Y.filterExcludeRigidBody,Y.filterPredicate);if(this._debugRaycastingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:$,length:X,hit:!!W});if(!W)return null;let K=Q.pointAt(W.timeOfImpact),Z=W.timeOfImpact,G=W.collider,V=this._colliderMap.getColliderHandleBlockType(G.handle);if(V)return{hitBlock:R3.fromGlobalCoordinate({x:Math.floor(K.x-(Q.dir.x<0?0.0001:-0.0001)),y:Math.floor(K.y-(Q.dir.y<0?0.0001:-0.0001)),z:Math.floor(K.z-(Q.dir.z<0?0.0001:-0.0001))},V),hitPoint:K,hitDistance:Z};let q=this._colliderMap.getColliderHandleEntity(G.handle);if(q)return{hitEntity:q,hitPoint:K,hitDistance:Z};return null}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 $=performance.now();if(T6.startSpan({operation:"physics_step"},()=>{this._rapierSimulation.step(this._rapierEventQueue)}),T6.startSpan({operation:"physics_cleanup"},()=>{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()-$}),this._debugRenderingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender(this._debugRenderingFilterFlags)})};_onCollisionEvent=(J,$,X)=>{let[Y,Q]=this._getCollisionObjects(J,$);if(!Y||!Q)return;let W=(K,Z)=>{if(K instanceof A9&&Z instanceof b6&&K.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))K.emit("BLOCK_TYPE.ENTITY_COLLISION",{blockType:K,entity:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(K instanceof b6&&Z instanceof A9&&K.hasListeners("ENTITY.BLOCK_COLLISION"))K.emit("ENTITY.BLOCK_COLLISION",{entity:K,blockType:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(K instanceof b6&&Z instanceof b6&&K.hasListeners("ENTITY.ENTITY_COLLISION"))K.emit("ENTITY.ENTITY_COLLISION",{entity:K,otherEntity:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(typeof K==="function"&&(Z instanceof b6||Z instanceof A9))K(Z,X,J,$)};W(Y,Q),W(Q,Y)};_onContactForceEvent=(J)=>{let[$,X]=this._getCollisionObjects(J.collider1(),J.collider2());if(!$||typeof $==="function"||!X||typeof X==="function")return;let Y={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},Q=(W,K)=>{if(W instanceof A9&&K instanceof b6&&W.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))W.emit("BLOCK_TYPE.ENTITY_CONTACT_FORCE",{blockType:W,entity:K,contactForceData:Y});else if(W instanceof b6&&K instanceof A9&&W.hasListeners("ENTITY.BLOCK_CONTACT_FORCE"))W.emit("ENTITY.BLOCK_CONTACT_FORCE",{entity:W,blockType:K,contactForceData:Y});else if(W instanceof b6&&K instanceof b6&&W.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))W.emit("ENTITY.ENTITY_CONTACT_FORCE",{entity:W,otherEntity:K,contactForceData:Y})};Q($,X),Q(X,$)};_getCollisionObjects(J,$){let X=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),Y=this._colliderMap.getColliderHandleBlockType($)??this._colliderMap.getColliderHandleCollisionCallback($)??this._colliderMap.getColliderHandleEntity($);return[X,Y]}}class AC{_synchronizedPlayerReliablePackets=new w5;_queuedBroadcasts=[];_queuedAudioSynchronizations=new w5;_queuedBlockSynchronizations=new w5;_queuedBlockTypeSynchronizations=new w5;_queuedChunkSynchronizations=new w5;_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations=new w5;_queuedLightSynchronizations=new w5;_queuedParticleEmitterSynchronizations=new w5;_queuedPerPlayerSynchronizations=new w5;_queuedPerPlayerCameraSynchronizations=new w5;_queuedPerPlayerUISynchronizations=new w5;_queuedPerPlayerUIDatasSynchronizations=new w5;_queuedPlayerSynchronizations=new w5;_queuedSceneUISynchronizations=new w5;_queuedWorldSynchronization;_loadedSceneUIs=new Set;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkLatticeEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToParticleEmitterEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){let J=[],$=[],X=this._world.loop.currentTick;if(this._queuedPerPlayerSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerSynchronizations)this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(...Q);if(this._queuedEntitySynchronizations.size>0){let Y=[],Q=[];for(let W of this._queuedEntitySynchronizations.valuesArray){let K=!1;for(let Z in W)if(Z!=="i"&&Z!=="p"&&Z!=="r"){K=!0;break}if(K)Y.push(W);else Q.push(W)}if(Q.length>0){let W=_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,Q,X);$.push(W)}if(Y.length>0){let W=_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,Y,X);J.push(W);for(let K of this._synchronizedPlayerReliablePackets.valuesArray)K.push(W)}}if(this._queuedAudioSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.audiosPacketDefinition,this._queuedAudioSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBlockTypeSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.blockTypesPacketDefinition,this._queuedBlockTypeSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedChunkSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.chunksPacketDefinition,this._queuedChunkSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBlockSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.blocksPacketDefinition,this._queuedBlockSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedLightSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.lightsPacketDefinition,this._queuedLightSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedParticleEmitterSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.particleEmittersPacketDefinition,this._queuedParticleEmitterSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedPerPlayerUISynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerUISynchronizations){let W=_0.createPacket(_0.outboundPackets.uiPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedPerPlayerUIDatasSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerUIDatasSynchronizations){let W=_0.createPacket(_0.outboundPackets.uiDatasPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedSceneUISynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.sceneUIsPacketDefinition,this._queuedSceneUISynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedWorldSynchronization){let Y=_0.createPacket(_0.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedPerPlayerCameraSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerCameraSynchronizations){let W=_0.createPacket(_0.outboundPackets.cameraPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedPlayerSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.playersPacketDefinition,this._queuedPlayerSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBroadcasts.length>0)for(let Y of this._queuedBroadcasts){J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedDebugRaycastSynchronizations.length>0){let Y=_0.createPacket(_0.outboundPackets.physicsDebugRaycastsPacketDefinition,this._queuedDebugRaycastSynchronizations,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}T6.startSpan({operation:"send_all_packets"},()=>{for(let Y of F$.instance.getConnectedPlayersByWorld(this._world)){let Q=this._synchronizedPlayerReliablePackets.get(Y)??J;if(Q.length>0)Y.connection.send(Q);if($.length>0)Y.connection.send($,!1)}}),T6.startSpan({operation:"network_synchronize_cleanup"},()=>{if(this._queuedBroadcasts.length>0)this._queuedBroadcasts.length=0;if(this._queuedAudioSynchronizations.size>0)this._queuedAudioSynchronizations.clear();if(this._queuedBlockSynchronizations.size>0)this._queuedBlockSynchronizations.clear();if(this._queuedBlockTypeSynchronizations.size>0)this._queuedBlockTypeSynchronizations.clear();if(this._queuedChunkSynchronizations.size>0)this._queuedChunkSynchronizations.clear();if(this._queuedDebugRaycastSynchronizations.length>0)this._queuedDebugRaycastSynchronizations.length=0;if(this._queuedEntitySynchronizations.size>0)this._queuedEntitySynchronizations.clear();if(this._queuedLightSynchronizations.size>0)this._queuedLightSynchronizations.clear();if(this._queuedParticleEmitterSynchronizations.size>0)this._queuedParticleEmitterSynchronizations.clear();if(this._queuedPerPlayerSynchronizations.size>0)this._queuedPerPlayerSynchronizations.clear();if(this._queuedPerPlayerCameraSynchronizations.size>0)this._queuedPerPlayerCameraSynchronizations.clear();if(this._queuedPerPlayerUISynchronizations.size>0)this._queuedPerPlayerUISynchronizations.clear();if(this._queuedPerPlayerUIDatasSynchronizations.size>0)this._queuedPerPlayerUIDatasSynchronizations.clear();if(this._queuedPlayerSynchronizations.size>0)this._queuedPlayerSynchronizations.clear();if(this._queuedSceneUISynchronizations.size>0)this._queuedSceneUISynchronizations.clear();if(this._queuedWorldSynchronization)this._queuedWorldSynchronization=void 0;if(this._loadedSceneUIs.size>0)this._loadedSceneUIs.clear();if(this._spawnedChunks.size>0)this._spawnedChunks.clear();if(this._spawnedEntities.size>0)this._spawnedEntities.clear();if(this._synchronizedPlayerReliablePackets.size>0)this._synchronizedPlayerReliablePackets.clear();v$.clearCachedPacketsSerializedBuffers()})}_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)}_subscribeToChunkLatticeEvents(){this._world.final("CHUNK_LATTICE.ADD_CHUNK",this._onChunkLatticeAddChunk),this._world.final("CHUNK_LATTICE.REMOVE_CHUNK",this._onChunkLatticeRemoveChunk),this._world.final("CHUNK_LATTICE.SET_BLOCK",this._onChunkLatticeSetBlock)}_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_MODEL_SCALE",this._onEntitySetModelScale),this._world.final("ENTITY.SET_MODEL_SHOWN_NODES",this._onEntitySetModelShownNodes),this._world.final("ENTITY.SET_MODEL_TEXTURE_URI",this._onEntitySetModelTextureUri),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)}_subscribeToParticleEmitterEvents(){this._world.final("PARTICLE_EMITTER.DESPAWN",this._onParticleEmitterDespawn),this._world.final("PARTICLE_EMITTER.BURST",this._onParticleEmitterBurst),this._world.final("PARTICLE_EMITTER.SET_ALPHA_TEST",this._onParticleEmitterSetAlphaTest),this._world.final("PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY",this._onParticleEmitterSetAttachedToEntity),this._world.final("PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME",this._onParticleEmitterSetAttachedToEntityNodeName),this._world.final("PARTICLE_EMITTER.SET_COLOR_END",this._onParticleEmitterSetColorEnd),this._world.final("PARTICLE_EMITTER.SET_COLOR_END_VARIANCE",this._onParticleEmitterSetColorEndVariance),this._world.final("PARTICLE_EMITTER.SET_COLOR_START",this._onParticleEmitterSetColorStart),this._world.final("PARTICLE_EMITTER.SET_COLOR_START_VARIANCE",this._onParticleEmitterSetColorStartVariance),this._world.final("PARTICLE_EMITTER.SET_GRAVITY",this._onParticleEmitterSetGravity),this._world.final("PARTICLE_EMITTER.SET_LIFETIME",this._onParticleEmitterSetLifetime),this._world.final("PARTICLE_EMITTER.SET_LIFETIME_VARIANCE",this._onParticleEmitterSetLifetimeVariance),this._world.final("PARTICLE_EMITTER.SET_MAX_PARTICLES",this._onParticleEmitterSetMaxParticles),this._world.final("PARTICLE_EMITTER.SET_OFFSET",this._onParticleEmitterSetOffset),this._world.final("PARTICLE_EMITTER.SET_OPACITY_END",this._onParticleEmitterSetOpacityEnd),this._world.final("PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE",this._onParticleEmitterSetOpacityEndVariance),this._world.final("PARTICLE_EMITTER.SET_OPACITY_START",this._onParticleEmitterSetOpacityStart),this._world.final("PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE",this._onParticleEmitterSetOpacityStartVariance),this._world.final("PARTICLE_EMITTER.SET_PAUSED",this._onParticleEmitterSetPaused),this._world.final("PARTICLE_EMITTER.SET_POSITION",this._onParticleEmitterSetPosition),this._world.final("PARTICLE_EMITTER.SET_POSITION_VARIANCE",this._onParticleEmitterSetPositionVariance),this._world.final("PARTICLE_EMITTER.SET_RATE",this._onParticleEmitterSetRate),this._world.final("PARTICLE_EMITTER.SET_RATE_VARIANCE",this._onParticleEmitterSetRateVariance),this._world.final("PARTICLE_EMITTER.SET_SIZE_END",this._onParticleEmitterSetSizeEnd),this._world.final("PARTICLE_EMITTER.SET_SIZE_END_VARIANCE",this._onParticleEmitterSetSizeEndVariance),this._world.final("PARTICLE_EMITTER.SET_SIZE_START",this._onParticleEmitterSetSizeStart),this._world.final("PARTICLE_EMITTER.SET_SIZE_START_VARIANCE",this._onParticleEmitterSetSizeStartVariance),this._world.final("PARTICLE_EMITTER.SET_TEXTURE_URI",this._onParticleEmitterSetTextureUri),this._world.final("PARTICLE_EMITTER.SET_TRANSPARENT",this._onParticleEmitterSetTransparent),this._world.final("PARTICLE_EMITTER.SET_VELOCITY",this._onParticleEmitterSetVelocity),this._world.final("PARTICLE_EMITTER.SET_VELOCITY_VARIANCE",this._onParticleEmitterSetVelocityVariance),this._world.final("PARTICLE_EMITTER.SPAWN",this._onParticleEmitterSpawn)}_subscribeToPlayerEvents(){this._world.final("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.final("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.final("PLAYER.RECONNECTED_WORLD",this._onPlayerReconnectedWorld),this._world.final("PLAYER.REQUEST_NOTIFICATION_PERMISSION",this._onPlayerRequestNotificationPermission),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_MODEL_SHOWN_NODES",this._onPlayerCameraSetModelShownNodes),this._world.final("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.final("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.final("PLAYER_CAMERA.SET_SHOULDER_ANGLE",this._onPlayerCameraSetShoulderAngle),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),this._world.final("WORLD.SET_FOG_COLOR",this._onWorldSetFogColor),this._world.final("WORLD.SET_FOG_FAR",this._onWorldSetFogFar),this._world.final("WORLD.SET_FOG_NEAR",this._onWorldSetFogNear),this._world.final("WORLD.SET_SKYBOX_INTENSITY",this._onWorldSetSkyboxIntensity),this._world.final("WORLD.SET_SKYBOX_URI",this._onWorldSetSkyboxUri)}_onAudioPause=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.pa=!0,delete $.pl,delete $.r};_onAudioPlay=(J)=>{let $=J.audio.serialize();$.pl=!0,delete $.pa,delete $.r,this._queuedAudioSynchronizations.set($.i,$)};_onAudioPlayRestart=(J)=>{let $=J.audio.serialize();$.r=!0,delete $.pa,delete $.pl,this._queuedAudioSynchronizations.set($.i,$)};_onAudioSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onAudioSetCutoffDistance=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.cd=J.cutoffDistance};_onAudioSetDetune=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.de=J.detune};_onAudioSetDistortion=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.di=J.distortion};_onAudioSetPosition=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.e=J.position?void 0:$.e,$.p=J.position?V1.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let $=J.blockType.serialize();this._queuedBlockTypeSynchronizations.set(J.blockType.id,$)};_onChatSendBroadcastMessage=(J)=>{let{player:$,message:X,color:Y}=J;this._queuedBroadcasts.push(_0.createPacket(_0.outboundPackets.chatMessagesPacketDefinition,[{m:X,c:Y,p:$?.id}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:$,message:X,color:Y}=J,Q=this._queuedPerPlayerSynchronizations.get($)??[];Q.push(_0.createPacket(_0.outboundPackets.chatMessagesPacketDefinition,[{m:X,c:Y}],this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set($,Q)};_onChunkLatticeAddChunk=(J)=>{let $=this._createOrGetQueuedChunkSync(J.chunk);$.b=Array.from(J.chunk.blocks),$.rm=void 0,this._spawnedChunks.add($.c.join(","))};_onChunkLatticeRemoveChunk=(J)=>{let $=this._createOrGetQueuedChunkSync(J.chunk),X=$.c.join(",");if(this._spawnedChunks.has(X))this._queuedChunkSynchronizations.delete(X),this._spawnedChunks.delete(X);else $.rm=!0};_onChunkLatticeSetBlock=(J)=>{let $=this._createOrGetQueuedBlockSync(J.globalCoordinate);$.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.ap=J.playbackRate};_onEntitySpawn=(J)=>{let $=J.entity.serialize();this._queuedEntitySynchronizations.set($.i,$),this._spawnedEntities.add($.i)};_onEntityDespawn=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has($.i))this._queuedEntitySynchronizations.delete($.i),this._spawnedEntities.delete($.i);else $.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.h=Array.from(J.modelHiddenNodes)};_onEntitySetModelScale=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.sv=J.modelScale?V1.serializeVector(J.modelScale):void 0};_onEntitySetModelShownNodes=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.sn=Array.from(J.modelShownNodes)};_onEntitySetModelTextureUri=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.mt=J.modelTextureUri};_onEntitySetOpacity=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.o=J.opacity};_onEntitySetParent=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.pe=J.parent?J.parent.id:void 0,$.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.t=J.tintColor?V1.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.al=Array.from(new Set([...$.al??[],...J.animations])),$.as)$.as=$.as.filter((X)=>!J.animations.has(X)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.ao=Array.from(new Set([...$.ao??[],...J.animations])),$.as)$.as=$.as.filter((X)=>!J.animations.has(X)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.al)$.al=$.al.filter((X)=>!J.animations.has(X)).filter(Boolean);if($.ao)$.ao=$.ao.filter((X)=>!J.animations.has(X)).filter(Boolean);$.as=Array.from(new Set([...$.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.rm=!0};_onLightSetAngle=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onLightSetColor=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.c=V1.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.d=J.distance};_onLightSetIntensity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.n=J.intensity};_onLightSetOffset=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.pe=J.penumbra};_onLightSetPosition=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e};_onLightSetTrackedEntity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.te=J.entity?J.entity.id:void 0,$.tp=J.entity?void 0:$.tp};_onLightSetTrackedPosition=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.tp=J.position?V1.serializeVector(J.position):void 0,$.te=J.position?void 0:$.te};_onLightSpawn=(J)=>{let $=J.light.serialize();this._queuedLightSynchronizations.set($.i,$)};_onParticleEmitterBurst=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.b=J.count};_onParticleEmitterDespawn=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.rm=!0};_onParticleEmitterSetAlphaTest=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.at=J.alphaTest};_onParticleEmitterSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onParticleEmitterSetAttachedToEntityNodeName=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.en=J.attachedToEntityNodeName};_onParticleEmitterSetColorEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ce=J.colorEnd?V1.serializeRgbColor(J.colorEnd):void 0};_onParticleEmitterSetColorEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.cev=J.colorEndVariance?V1.serializeRgbColor(J.colorEndVariance):void 0};_onParticleEmitterSetColorStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.cs=J.colorStart?V1.serializeRgbColor(J.colorStart):void 0};_onParticleEmitterSetColorStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.csv=J.colorStartVariance?V1.serializeRgbColor(J.colorStartVariance):void 0};_onParticleEmitterSetGravity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.g=J.gravity?V1.serializeVector(J.gravity):void 0};_onParticleEmitterSetLifetime=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.l=J.lifetime};_onParticleEmitterSetLifetimeVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.lv=J.lifetimeVariance};_onParticleEmitterSetMaxParticles=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.mp=J.maxParticles};_onParticleEmitterSetOffset=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onParticleEmitterSetOpacityEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.oe=J.opacityEnd};_onParticleEmitterSetOpacityEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.oev=J.opacityEndVariance};_onParticleEmitterSetOpacityStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.os=J.opacityStart};_onParticleEmitterSetOpacityStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.osv=J.opacityStartVariance};_onParticleEmitterSetPaused=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.pa=J.paused};_onParticleEmitterSetPosition=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e,$.en=J.position?void 0:$.en};_onParticleEmitterSetPositionVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.pv=J.positionVariance?V1.serializeVector(J.positionVariance):void 0};_onParticleEmitterSetRate=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.r=J.rate};_onParticleEmitterSetRateVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.rv=J.rateVariance};_onParticleEmitterSetSizeEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.se=J.sizeEnd};_onParticleEmitterSetSizeEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.sev=J.sizeEndVariance};_onParticleEmitterSetSizeStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ss=J.sizeStart};_onParticleEmitterSetSizeStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ssv=J.sizeStartVariance};_onParticleEmitterSetTextureUri=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.tu=J.textureUri};_onParticleEmitterSetTransparent=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.t=J.transparent};_onParticleEmitterSetVelocity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.v=J.velocity?V1.serializeVector(J.velocity):void 0};_onParticleEmitterSetVelocityVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.vv=J.velocityVariance?V1.serializeVector(J.velocityVariance):void 0};_onParticleEmitterSpawn=(J)=>{let $=J.particleEmitter.serialize();this._queuedParticleEmitterSynchronizations.set($.i,$)};_onPlayerCameraLookAtEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pl=V1.serializeVector(J.entity.position),delete $.et,delete $.pt};_onPlayerCameraLookAtPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pl=J.position?V1.serializeVector(J.position):void 0,delete $.et,delete $.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.e=J.entity.id,delete $.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.p=J.position?V1.serializeVector(J.position):void 0,delete $.e};_onPlayerCameraSetFilmOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetModelShownNodes=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.s=Array.from(J.modelShownNodes)};_onPlayerCameraSetMode=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onPlayerCameraSetShoulderAngle=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.sa=J.shoulderAngle};_onPlayerCameraSetTrackedEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.et=J.entity?J.entity.id:void 0,delete $.pl,delete $.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pt=J.position?V1.serializeVector(J.position):void 0,delete $.et,delete $.pl};_onPlayerCameraSetZoom=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:$}=J,X=this._queuedPerPlayerSynchronizations.get($)??[];X.push(_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((Q)=>{if($.camera.attachedToEntity===void 0&&Q instanceof o$&&Q.player===$)$.camera.setAttachedToEntity(Q);return Q.serialize()}),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllAudios().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.particleEmittersPacketDefinition,this._world.particleEmitterManager.getAllParticleEmitters().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.playersPacketDefinition,F$.instance.getConnectedPlayers().map((Q)=>Q.serialize()),this._world.loop.currentTick));let Y=this._createOrGetQueuedPlayerCameraSync($.camera);this._queuedPerPlayerCameraSynchronizations.set($,{...$.camera.serialize(),...Y}),this._queuedPerPlayerSynchronizations.set($,X),this._queuedPlayerSynchronizations.set($.id,$.serialize())};_onPlayerLeftWorld=(J)=>{let $=this._createOrGetQueuedPlayerSync(J.player);$.rm=!0};_onPlayerReconnectedWorld=(J)=>{this._onPlayerJoinedWorld(J)};_onPlayerRequestNotificationPermission=(J)=>{let{player:$}=J,X=this._queuedPerPlayerSynchronizations.get($)??[];X.push(_0.createPacket(_0.outboundPackets.notificationPermissionRequestPacketDefinition,null,this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set($,X)};_onPlayerRequestSync=(J)=>{J.player.connection.send([_0.createPacket(_0.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 $=this._createOrGetQueuedPlayerUISync(J.playerUI);$.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let $=this._createOrGetQueuedPlayerUISync(J.playerUI);$.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let $=J.sceneUI.serialize();this._queuedSceneUISynchronizations.set($.i,$),this._loadedSceneUIs.add($.i)};_onSceneUISetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onSceneUISetOffset=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e};_onSceneUISetState=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.s=J.state};_onSceneUISetViewDistance=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.v=J.viewDistance};_onSceneUIUnload=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);if(this._loadedSceneUIs.has($.i))this._queuedSceneUISynchronizations.delete($.i),this._loadedSceneUIs.delete($.i);else $.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(V1.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(_0.createPacket(_0.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ac=V1.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.dc=V1.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.dp=V1.serializeVector(J.position)};_onWorldSetFogColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.fc=V1.serializeRgbColor(J.color)};_onWorldSetFogFar=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ff=J.far};_onWorldSetFogNear=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.fn=J.near};_onWorldSetSkyboxIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.si=J.intensity};_onWorldSetSkyboxUri=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.s=J.uri};_createOrGetQueuedAudioSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");let $=this._queuedAudioSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedAudioSynchronizations.set(J.id,$);return $}_createOrGetQueuedBlockSync(J){let{x:$,y:X,z:Y}=J,Q=`${$},${X},${Y}`,W=this._queuedBlockSynchronizations.get(Q);if(!W)W={i:0,c:[$,X,Y]},this._queuedBlockSynchronizations.set(Q,W);return W}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)n.fatalError("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:$,y:X,z:Y}=J.originCoordinate,Q=`${$},${X},${Y}`,W=this._queuedChunkSynchronizations.get(Q);if(!W)W={c:[$,X,Y]},this._queuedChunkSynchronizations.set(Q,W);return W}_createOrGetQueuedEntitySync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");let $=this._queuedEntitySynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedEntitySynchronizations.set(J.id,$);return $}_createOrGetQueuedLightSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");let $=this._queuedLightSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedLightSynchronizations.set(J.id,$);return $}_createOrGetQueuedParticleEmitterSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedParticleEmitterSync(): ParticleEmitter has no id!");let $=this._queuedParticleEmitterSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedParticleEmitterSynchronizations.set(J.id,$);return $}_createOrGetQueuedPlayerSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedPlayerSync(): Player has no id!");let $=this._queuedPlayerSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedPlayerSynchronizations.set(J.id,$);return $}_createOrGetQueuedPlayerCameraSync(J){let $=this._queuedPerPlayerCameraSynchronizations.get(J.player);if(!$)$={},this._queuedPerPlayerCameraSynchronizations.set(J.player,$);return $}_createOrGetQueuedPlayerUISync(J){let $=this._queuedPerPlayerUISynchronizations.get(J.player);if(!$)$={},this._queuedPerPlayerUISynchronizations.set(J.player,$);return $}_createOrGetQueuedPlayerUIDatasSync(J){let $=this._queuedPerPlayerUIDatasSynchronizations.get(J.player);if(!$)$=[],this._queuedPerPlayerUIDatasSynchronizations.set(J.player,$);return $}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");let $=this._queuedSceneUISynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedSceneUISynchronizations.set(J.id,$);return $}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)n.fatalError("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}_createOrGetSynchronizedPlayerReliablePackets(J,$){let X=this._synchronizedPlayerReliablePackets.get(J);if(!X)X=[...$],this._synchronizedPlayerReliablePackets.set(J,X);return X}}class XB{_particleEmitters=new Map;_nextParticleEmitterId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedParticleEmitters(J){this.getAllEntityAttachedParticleEmitters(J).forEach(($)=>{$.despawn()})}getAllParticleEmitters(){return Array.from(this._particleEmitters.values())}getAllEntityAttachedParticleEmitters(J){return this.getAllParticleEmitters().filter(($)=>$.attachedToEntity===J)}registerParticleEmitter(J){if(J.id!==void 0)return J.id;let $=this._nextParticleEmitterId;return this._particleEmitters.set($,J),this._nextParticleEmitterId++,$}unregisterParticleEmitter(J){if(J.id===void 0)return;this._particleEmitters.delete(J.id)}}class YB{_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(($)=>$.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let $=this._nextSceneUIId;return this._sceneUIs.set($,J),this._nextSceneUIId++,$}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach(($)=>{$.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}var AC6=2,cC6=3;class QB{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_maxAccumulatorMs;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,$,X){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._maxAccumulatorMs=this._fixedTimestepMs*cC6,this._tickFunction=$,this._tickErrorCallback=X}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get isStarted(){return!!this._tickHandle}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return;this._lastLoopTimeMs=performance.now();let J=()=>{let $=performance.now(),X=$-this._lastLoopTimeMs;if(this._lastLoopTimeMs=$,this._accumulatorMs+=X,this._accumulatorMs>this._maxAccumulatorMs)this._accumulatorMs=this._maxAccumulatorMs;if(this._accumulatorMs>=this._fixedTimestepMs)T6.startSpan({operation:"ticker_tick"},()=>{let Y=0;while(this._accumulatorMs>=this._fixedTimestepMs&&Y<AC6)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs,Y++});this._nextTickMs=Math.max(0,this._fixedTimestepMs-this._accumulatorMs),this._tickHandle=setTimeout(J,this._nextTickMs)};J()}stop(){if(!this._tickHandle)return;clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch($){if($ instanceof Error&&this._tickErrorCallback)this._tickErrorCallback($);else n.warning(`Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error: ${$}`)}}}var JO1;((W)=>{W.START="WORLD_LOOP.START";W.STOP="WORLD_LOOP.STOP";W.TICK_START="WORLD_LOOP.TICK_START";W.TICK_END="WORLD_LOOP.TICK_END";W.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(JO1||={});class WB extends $1{_currentTick=0;_ticker;_world;constructor(J,$=ei){super();this._ticker=new QB($,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get isStarted(){return this._ticker.isStarted}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 $=performance.now();T6.startSpan({operation:"world_tick",attributes:{serverPlayerCount:F$.instance.playerCount,targetTickRate:this._ticker.targetTicksPerSecond,targetTickRateMs:this._ticker.fixedTimestepMs,worldId:this._world.id,worldName:this._world.name,worldChunkCount:this._world.chunkLattice.chunkCount,worldEntityCount:this._world.entityManager.entityCount,worldLoopTick:this._currentTick}},()=>{T6.startSpan({operation:"entities_tick"},()=>this._world.entityManager.tickEntities(J)),T6.startSpan({operation:"simulation_step"},()=>this._world.simulation.step(J)),T6.startSpan({operation:"entities_emit_updates"},()=>this._world.entityManager.checkAndEmitUpdates()),T6.startSpan({operation:"network_synchronize"},()=>this._world.networkSynchronizer.synchronize())}),this._currentTick++,this.emitWithWorld(this._world,"WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-$})};_onTickError=(J)=>{n.error(`WorldLoop._onTickError(): Error: ${J}`),this.emitWithWorld(this._world,"WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}var $n;((H)=>{H.SET_AMBIENT_LIGHT_COLOR="WORLD.SET_AMBIENT_LIGHT_COLOR";H.SET_AMBIENT_LIGHT_INTENSITY="WORLD.SET_AMBIENT_LIGHT_INTENSITY";H.SET_DIRECTIONAL_LIGHT_COLOR="WORLD.SET_DIRECTIONAL_LIGHT_COLOR";H.SET_DIRECTIONAL_LIGHT_INTENSITY="WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY";H.SET_DIRECTIONAL_LIGHT_POSITION="WORLD.SET_DIRECTIONAL_LIGHT_POSITION";H.SET_FOG_COLOR="WORLD.SET_FOG_COLOR";H.SET_FOG_FAR="WORLD.SET_FOG_FAR";H.SET_FOG_NEAR="WORLD.SET_FOG_NEAR";H.SET_SKYBOX_INTENSITY="WORLD.SET_SKYBOX_INTENSITY";H.SET_SKYBOX_URI="WORLD.SET_SKYBOX_URI";H.START="WORLD.START";H.STOP="WORLD.STOP"})($n||={});class KB extends $1{_id;_ambientLightColor;_ambientLightIntensity;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_entityManager;_fogColor;_fogFar;_fogNear;_lightManager;_loop;_name;_networkSynchronizer;_particleEmitterManager;_sceneUIManager;_simulation;_skyboxIntensity;_skyboxUri;_tag;constructor(J){super();if(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._fogColor=J.fogColor,this._fogFar=J.fogFar??550,this._fogNear=J.fogNear??500,this._name=J.name,this._skyboxIntensity=J.skyboxIntensity??1,this._skyboxUri=J.skyboxUri,this._tag=J.tag,this._audioManager=new vz(this),this._blockTypeRegistry=new EF(this),this._chatManager=new FU(this),this._chunkLattice=new UU(this),this._entityManager=new LU(this),this._lightManager=new JB(this),this._loop=new WB(this,J.tickRate),this._networkSynchronizer=new AC(this),this._particleEmitterManager=new XB(this),this._sceneUIManager=new YB(this),this._simulation=new $B(this,J.tickRate,J.gravity),J.map)this.loadMap(J.map)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get entityManager(){return this._entityManager}get fogColor(){return this._fogColor}get fogFar(){return this._fogFar}get fogNear(){return this._fogNear}get lightManager(){return this._lightManager}get loop(){return this._loop}get name(){return this._name}get networkSynchronizer(){return this._networkSynchronizer}get particleEmitterManager(){return this._particleEmitterManager}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}get skyboxIntensity(){return this._skyboxIntensity}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get tag(){return this._tag}loadMap(J){if(this.chunkLattice.clear(),J.blockTypes)for(let $ of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:$.id,isLiquid:$.isLiquid,lightLevel:$.lightLevel,name:$.name,textureUri:$.textureUri});if(J.blocks){let $={};for(let X in J.blocks){let Y=J.blocks[X],Q=X.indexOf(","),W=X.indexOf(",",Q+1),K=Number(X.slice(0,Q)),Z=Number(X.slice(Q+1,W)),G=Number(X.slice(W+1));if(!$[Y])$[Y]=[];$[Y].push({x:K,y:Z,z:G})}this.chunkLattice.initializeBlocks($)}if(J.entities)for(let $ in J.entities){let X=J.entities[$],Y=$.indexOf(","),Q=$.indexOf(",",Y+1),W=Number($.slice(0,Y)),K=Number($.slice(Y+1,Q)),Z=Number($.slice(Q+1));new b6({isEnvironmental:!0,...X}).spawn(this,{x:W,y:K,z: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})}setFogColor(J){this._fogColor=J,this.emit("WORLD.SET_FOG_COLOR",{world:this,color:J})}setFogFar(J){this._fogFar=J,this.emit("WORLD.SET_FOG_FAR",{world:this,far:J})}setFogNear(J){this._fogNear=J,this.emit("WORLD.SET_FOG_NEAR",{world:this,near:J})}setSkyboxIntensity(J){this._skyboxIntensity=J,this.emit("WORLD.SET_SKYBOX_INTENSITY",{world:this,intensity:J})}setSkyboxUri(J){this._skyboxUri=J,this.emit("WORLD.SET_SKYBOX_URI",{world:this,uri:J})}start(){if(this._loop.isStarted)return;this._loop.start(),this.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){if(!this._loop.isStarted)return;this._loop.stop(),this.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return V1.serializeWorld(this)}}var $O1;(($)=>$.WORLD_CREATED="WORLD_MANAGER.WORLD_CREATED")($O1||={});class bK{static instance=new bK;_defaultWorld;_nextWorldId=1;_worlds=new Map;createWorld(J){let $=new KB({...J,id:this._nextWorldId++});return $.start(),this._worlds.set($.id,$),$1.globalInstance.emit("WORLD_MANAGER.WORLD_CREATED",{world:$}),$}getAllWorlds(){return Array.from(this._worlds.values())}getDefaultWorld(){return this._defaultWorld??=this.createWorld({name:"Default World",skyboxUri:"skyboxes/partly-cloudy"}),this._defaultWorld}getWorldsByTag(J){let $=[];return this._worlds.forEach((X)=>{if(X.tag===J)$.push(X)}),$}getWorld(J){return this._worlds.get(J)}setDefaultWorld(J){this._defaultWorld=J}}var XO1;((Y)=>{Y.PLAYER_CONNECTED="PLAYER_MANAGER.PLAYER_CONNECTED";Y.PLAYER_DISCONNECTED="PLAYER_MANAGER.PLAYER_DISCONNECTED";Y.PLAYER_RECONNECTED="PLAYER_MANAGER.PLAYER_RECONNECTED"})(XO1||={});class F${static instance=new F$;worldSelectionHandler;_connectionPlayers=new Map;constructor(){$1.globalInstance.on("CONNECTION.OPENED",({connection:J,session:$})=>{this._onConnectionOpened(J,$)}),$1.globalInstance.on("CONNECTION.DISCONNECTED",({connection:J})=>{this._onConnectionDisconnected(J)}),$1.globalInstance.on("CONNECTION.RECONNECTED",({connection:J})=>{this._onConnectionReconnected(J)}),$1.globalInstance.on("CONNECTION.CLOSED",({connection:J})=>{this._onConnectionClosed(J)})}get playerCount(){return this._connectionPlayers.size}getConnectedPlayers(){return Array.from(this._connectionPlayers.values())}getConnectedPlayersByWorld(J){return this.getConnectedPlayers().filter(($)=>$.world===J)}getConnectedPlayerByUsername(J){return Array.from(this._connectionPlayers.values()).find(($)=>{return $.username.toLowerCase()===J.toLowerCase()})}async _onConnectionOpened(J,$){let X=new kq(J,$);await X.loadInitialPersistedData(),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_CONNECTED",{player:X});let Y=await this.worldSelectionHandler?.(X);X.joinWorld(Y??bK.instance.getDefaultWorld()),this._connectionPlayers.set(J,X)}_onConnectionDisconnected(J){let $=this._connectionPlayers.get(J);if($)$.resetInputs(),$.camera.reset()}_onConnectionReconnected(J){let $=this._connectionPlayers.get(J);if($)$.reconnected(),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_RECONNECTED",{player:$});else n.warning(`PlayerManager._onConnectionReconnected(): Connection ${J.id} not in the PlayerManager._connectionPlayers map.`)}_onConnectionClosed(J){let $=this._connectionPlayers.get(J);if($)$.disconnect(),this._connectionPlayers.delete(J),CW.instance.unloadPlayerData($).catch((X)=>{n.warning(`PlayerManager._onConnectionClosed(): Failed to unload player data for player ${$.id}. Error: ${X}`)}),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_DISCONNECTED",{player:$});else n.warning(`PlayerManager._onConnectionClosed(): Connection ${J.id} not in the PlayerManager._connectionPlayers map.`)}}import{randomBytes as hC6}from"crypto";import{Http3Server as fC6}from"@fails-components/webtransport";class ZB extends $1{static instance=new ZB;_connectionIdConnections=new Map;_userIdConnections=new Map;_wss;_wts;constructor(){super();this._wss=new Ch.default({noServer:!0}),this._wss.on("connection",(J,$)=>this._onConnection(J,void 0,$.connectionId,$.session)),this._wts=new fC6({port:SC,host:"0.0.0.0",secret:hC6(32).toString("hex"),cert:kC,privKey:EC,defaultDatagramsReadableMode:"bytes",initialStreamFlowControlWindow:1048576,streamShouldAutoTuneReceiveWindow:!0,streamFlowControlWindowSizeLimit:6291456,initialSessionFlowControlWindow:2097152,sessionShouldAutoTuneReceiveWindow:!0,sessionFlowControlWindowSizeLimit:15728640}),this._wts.setRequestCallback(this._onWebTransportRequest),this._startWebTransport().catch((J)=>{n.error(`Socket: WebTransport server failed to start or crashed while listening for sessions. Error: ${J}`)}),$1.globalInstance.on("WEBSERVER.UPGRADE",async({req:J,socket:$,head:X})=>{await this._authorizeAndConnectWebsocket(J,$,X)})}async _authorizeAndConnectWebsocket(J,$,X){let Y=await this._authorizeConnection(J.url??"");if(Y.error){$.end();return}J.connectionId=Y.connectionId,J.session=Y.session,$.setNoDelay(!0),this._wss.handleUpgrade(J,$,X,(Q)=>{if(Q.readyState!==Cq.default.OPEN)Q.once("open",()=>this._wss.emit("connection",Q,J));else this._wss.emit("connection",Q,J)})}async _authorizeConnection(J){let $=J.includes("?")?J.slice(J.indexOf("?")):"",X=new URLSearchParams($),Y=X.get("connectionId")??void 0,Q=X.get("sessionToken")??"";if(Y&&this._isValidConnectionId(Y))return{connectionId:Y};else{let W=await k7.instance.getPlayerSession(Q);if(W?.error)return{error:W.error};else if(W)return{session:W}}return{}}_isValidConnectionId(J){return this._connectionIdConnections.has(J)}_onConnection=(J,$,X,Y)=>{let Q=Y?.user.id,W=(X&&this._connectionIdConnections.get(X))??(Q&&this._userIdConnections.get(Q));if(W){if(J)W.bindWs(J);if($)W.bindWt($).catch((K)=>{n.error(`Socket._onConnection(): WebTransport binding failed. Error: ${K}`)})}else{let K=new v$(J,$,Y);if(K.on("CONNECTION.CLOSED",()=>{if(this._connectionIdConnections.delete(K.id),Q)this._userIdConnections.delete(Q)}),this._connectionIdConnections.set(K.id,K),Q)this._userIdConnections.set(Q,K)}};_onWebTransportRequest=async({header:J})=>{let{connectionId:$,session:X,error:Y}=await this._authorizeConnection(J[":path"]??"");return{status:Y?401:200,path:"/",userData:{connectionId:$,session:X}}};async _startWebTransport(){this._wts.startServer();for await(let J of this._wts.sessionStream("/"))try{let{connectionId:$,session:X}=J.userData;this._onConnection(void 0,J,$,X)}catch($){n.error(`Socket._startWebTransport(): WebTransport connection failed. Error: ${$}`)}}}Buffer.poolSize=134217728;var YO1;((X)=>{X.START="GAMESERVER.START";X.STOP="GAMESERVER.STOP"})(YO1||={});function bC6(J){W8.init().then(()=>{return yK.instance.blockTextureRegistry.preloadAtlas()}).then(()=>{return yK.instance.modelRegistry.preloadModels()}).then(()=>{if(J.length>0)J(yK.instance.worldManager.getDefaultWorld());else J();yK.instance.start()}).catch(($)=>{n.fatalError(`Failed to initialize the game engine, exiting. Error: ${$}`)})}class yK{static _instance;_blockTextureRegistry=eQ.instance;_modelRegistry=k5.instance;_playerManager=F$.instance;_socket=ZB.instance;_worldManager=bK.instance;_webServer=Qz.instance;constructor(){}static get instance(){if(!this._instance)this._instance=new yK;return this._instance}get blockTextureRegistry(){return this._blockTextureRegistry}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worldManager(){return this._worldManager}start(){if($1.globalInstance.emit("GAMESERVER.START",{startedAtMs:performance.now()}),this._webServer.start(),process.env.NODE_ENV!=="production")console.log("---"),console.log("\uD83D\uDFE2 Server Running: You can test & play it at: https://hytopia.com/play")}}var L5=M0(M3(),1);class N3 extends Float32Array{constructor(J,$,X,Y){super([J,$,X,Y])}get determinant(){return L5.mat2.determinant(this)}get frobeniusNorm(){return L5.mat2.frob(this)}static create(){let J=new N3(0,0,0,0);return L5.mat2.identity(J),J}static fromRotation(J){let $=N3.create();return L5.mat2.fromRotation($,J),$}static fromScaling(J){let $=N3.create();return L5.mat2.fromScaling($,J),$}add(J){return L5.mat2.add(this,this,J),this}adjoint(){return L5.mat2.adjoint(this,this),this}clone(){return new N3(this[0],this[1],this[2],this[3])}copy(J){return L5.mat2.copy(this,J),this}equals(J){return L5.mat2.equals(this,J)}exactEquals(J){return L5.mat2.exactEquals(this,J)}identity(){return L5.mat2.identity(this),this}invert(){return L5.mat2.invert(this,this),this}multiply(J){return L5.mat2.mul(this,this,J),this}multiplyScalar(J){return L5.mat2.multiplyScalar(this,this,J),this}rotate(J){return L5.mat2.rotate(this,this,J),this}subtract(J){return L5.mat2.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return L5.mat2.transpose(this,this),this}}var k6=M0(M3(),1);class xX extends Float32Array{constructor(J,$,X,Y,Q,W,K,Z,G){super([J,$,X,Y,Q,W,K,Z,G])}get determinant(){return k6.mat3.determinant(this)}get frobeniusNorm(){return k6.mat3.frob(this)}static create(){let J=new xX(0,0,0,0,0,0,0,0,0);return k6.mat3.identity(J),J}static fromMatrix4(J){let $=xX.create();return k6.mat3.fromMat4($,J),$}static fromQuaternion(J){let $=xX.create();return k6.mat3.fromQuat($,J),$}static fromRotation(J){let $=xX.create();return k6.mat3.fromRotation($,J),$}static fromScaling(J){let $=xX.create();return k6.mat3.fromScaling($,J),$}static fromTranslation(J){let $=xX.create();return k6.mat3.fromTranslation($,J),$}add(J){return k6.mat3.add(this,this,J),this}adjoint(){return k6.mat3.adjoint(this,this),this}clone(){return new xX(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return k6.mat3.copy(this,J),this}equals(J){return k6.mat3.equals(this,J)}exactEquals(J){return k6.mat3.exactEquals(this,J)}identity(){return k6.mat3.identity(this),this}invert(){return k6.mat3.invert(this,this),this}multiply(J){return k6.mat3.mul(this,this,J),this}multiplyScalar(J){return k6.mat3.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,$){return k6.mat3.projection(this,J,$),this}rotate(J){return k6.mat3.rotate(this,this,J),this}subtract(J){return k6.mat3.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 k6.mat3.transpose(this,this),this}}var $8=M0(M3(),1);class u4 extends Float32Array{constructor(J,$,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U){super([J,$,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U])}get determinant(){return $8.mat4.determinant(this)}get frobeniusNorm(){return $8.mat4.frob(this)}static create(){let J=new u4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return $8.mat4.identity(J),J}static fromQuaternion(J){let $=u4.create();return $8.mat4.fromQuat($,J),$}static fromRotation(J,$){let X=u4.create();return $8.mat4.fromRotation(X,J,$),X}static fromRotationTranslation(J,$){let X=u4.create();return $8.mat4.fromRotationTranslation(X,J,$),X}static fromRotationTranslationScale(J,$,X){let Y=u4.create();return $8.mat4.fromRotationTranslationScale(Y,J,$,X),Y}static fromRotationTranslationScaleOrigin(J,$,X,Y){let Q=u4.create();return $8.mat4.fromRotationTranslationScaleOrigin(Q,J,$,X,Y),Q}static fromScaling(J){let $=u4.create();return $8.mat4.fromScaling($,J),$}static fromTranslation(J){let $=u4.create();return $8.mat4.fromTranslation($,J),$}static fromXRotation(J){let $=u4.create();return $8.mat4.fromXRotation($,J),$}static fromYRotation(J){let $=u4.create();return $8.mat4.fromYRotation($,J),$}static fromZRotation(J){let $=u4.create();return $8.mat4.fromZRotation($,J),$}add(J){return $8.mat4.add(this,this,J),this}adjoint(){return $8.mat4.adjoint(this,this),this}clone(){return new u4(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 $8.mat4.copy(this,J),this}equals(J){return $8.mat4.equals(this,J)}exactEquals(J){return $8.mat4.exactEquals(this,J)}frustrum(J,$,X,Y,Q,W){return $8.mat4.frustum(this,J,$,X,Y,Q,W),this}identity(){return $8.mat4.identity(this),this}invert(){return $8.mat4.invert(this,this),this}lookAt(J,$,X){return $8.mat4.lookAt(this,J,$,X),this}multiply(J){return $8.mat4.mul(this,this,J),this}multiplyScalar(J){return $8.mat4.multiplyScalar(this,this,J),this}orthographic(J,$,X,Y,Q,W){return $8.mat4.ortho(this,J,$,X,Y,Q,W),this}perspective(J,$,X,Y){return $8.mat4.perspective(this,J,$,X,Y),this}rotate(J,$){return $8.mat4.rotate(this,this,J,$),this}rotateX(J){return $8.mat4.rotateX(this,this,J),this}rotateY(J){return $8.mat4.rotateY(this,this,J),this}rotateZ(J){return $8.mat4.rotateZ(this,this,J),this}scale(J){return $8.mat4.scale(this,this,J),this}subtract(J){return $8.mat4.sub(this,this,J),this}targetTo(J,$,X){return $8.mat4.targetTo(this,J,$,X),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 $8.mat4.translate(this,this,J),this}transpose(){return $8.mat4.transpose(this,this),this}}var b8=M0(M3(),1);class Wz extends Float32Array{constructor(J,$,X,Y){super([J,$,X,Y])}get length(){return b8.quat.length(this)}get squaredLength(){return b8.quat.squaredLength(this)}get magnitude(){return b8.quat.length(this)}get squaredMagnitude(){return b8.quat.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){let Y=b8.quat.fromEuler(new Float32Array(4),J,$,X);return new Wz(Y[0],Y[1],Y[2],Y[3])}static fromQuaternionLike(J){return new Wz(J.x,J.y,J.z,J.w)}clone(){return new Wz(this.x,this.y,this.z,this.w)}conjugate(){return b8.quat.conjugate(this,this),this}copy(J){return b8.quat.copy(this,J),this}dot(J){return b8.quat.dot(this,J)}exponential(){return b8.quat.exp(this,this),this}equals(J){return b8.quat.equals(this,J)}exactEquals(J){return b8.quat.exactEquals(this,J)}getAngle(J){return b8.quat.getAngle(this,J)}identity(){return b8.quat.identity(this),this}invert(){return b8.quat.invert(this,this),this}lerp(J,$){return b8.quat.lerp(this,this,J,$),this}logarithm(){return b8.quat.ln(this,this),this}multiply(J){return b8.quat.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return b8.quat.normalize(this,this),this}power(J){return b8.quat.pow(this,this,J),this}randomize(){return b8.quat.random(this),this}rotateX(J){return b8.quat.rotateX(this,this,J),this}rotateY(J){return b8.quat.rotateY(this,this,J),this}rotateZ(J){return b8.quat.rotateZ(this,this,J),this}scale(J){return b8.quat.scale(this,this,J),this}setAxisAngle(J,$){return b8.quat.setAxisAngle(this,J,$),this}slerp(J,$){return b8.quat.slerp(this,this,J,$),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}var w8=M0(M3(),1);class GB extends Float32Array{constructor(J,$){super([J,$])}get length(){return w8.vec2.length(this)}get squaredLength(){return w8.vec2.squaredLength(this)}get magnitude(){return w8.vec2.length(this)}get squaredMagnitude(){return w8.vec2.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 GB(0,0)}add(J){return w8.vec2.add(this,this,J),this}angle(J){return w8.vec2.angle(this,J)}ceil(){return w8.vec2.ceil(this,this),this}clone(){return new GB(this.x,this.y)}copy(J){return w8.vec2.copy(this,J),this}distance(J){return w8.vec2.distance(this,J)}divide(J){return w8.vec2.divide(this,this,J),this}dot(J){return w8.vec2.dot(this,J)}equals(J){return w8.vec2.equals(this,J)}exactEquals(J){return w8.vec2.exactEquals(this,J)}floor(){return w8.vec2.floor(this,this),this}invert(){return w8.vec2.inverse(this,this),this}lerp(J,$){return w8.vec2.lerp(this,this,J,$),this}max(J){return w8.vec2.max(this,this,J),this}min(J){return w8.vec2.min(this,this,J),this}multiply(J){return w8.vec2.mul(this,this,J),this}negate(){return w8.vec2.negate(this,this),this}normalize(){return w8.vec2.normalize(this,this),this}randomize(J){return w8.vec2.random(this,J),this}rotate(J,$){return w8.vec2.rotate(this,this,J,$),this}round(){return w8.vec2.round(this,this),this}scale(J){return w8.vec2.scale(this,this,J),this}scaleAndAdd(J,$){return w8.vec2.scaleAndAdd(this,this,J,$),this}subtract(J){return w8.vec2.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return w8.vec2.transformMat2(this,this,J),this}transformMatrix3(J){return w8.vec2.transformMat3(this,this,J),this}transformMatrix4(J){return w8.vec2.transformMat4(this,this,J),this}zero(){return w8.vec2.zero(this),this}}var z8=M0(M3(),1);class Kz extends Float32Array{constructor(J,$,X){super([J,$,X])}get length(){return z8.vec3.length(this)}get squaredLength(){return z8.vec3.squaredLength(this)}get magnitude(){return z8.vec3.length(this)}get squaredMagnitude(){return z8.vec3.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 Kz(0,0,0)}static fromVector3Like(J){return new Kz(J.x,J.y,J.z)}add(J){return z8.vec3.add(this,this,J),this}ceil(){return z8.vec3.ceil(this,this),this}clone(){return new Kz(this.x,this.y,this.z)}copy(J){return z8.vec3.copy(this,J),this}cross(J){return z8.vec3.cross(this,this,J),this}distance(J){return z8.vec3.distance(this,J)}divide(J){return z8.vec3.div(this,this,J),this}dot(J){return z8.vec3.dot(this,J)}equals(J){return z8.vec3.equals(this,J)}exactEquals(J){return z8.vec3.exactEquals(this,J)}floor(){return z8.vec3.floor(this,this),this}invert(){return z8.vec3.inverse(this,this),this}lerp(J,$){return z8.vec3.lerp(this,this,J,$),this}max(J){return z8.vec3.max(this,this,J),this}min(J){return z8.vec3.min(this,this,J),this}multiply(J){return z8.vec3.mul(this,this,J),this}negate(){return z8.vec3.negate(this,this),this}normalize(){return z8.vec3.normalize(this,this),this}randomize(J){return z8.vec3.random(this,J),this}rotateX(J,$){return z8.vec3.rotateX(this,this,J,$),this}rotateY(J,$){return z8.vec3.rotateY(this,this,J,$),this}rotateZ(J,$){return z8.vec3.rotateZ(this,this,J,$),this}round(){return z8.vec3.round(this,this),this}scale(J){return z8.vec3.scale(this,this,J),this}scaleAndAdd(J,$){return z8.vec3.scaleAndAdd(this,this,J,$),this}subtract(J){return z8.vec3.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return z8.vec3.transformMat3(this,this,J),this}transformMatrix4(J){return z8.vec3.transformMat4(this,this,J),this}transformQuaternion(J){return z8.vec3.transformQuat(this,this,J),this}zero(){return z8.vec3.zero(this),this}}var dR1=M0(gR1(),1);var pR1=0.099856;class VB extends iK{faceSpeed=0;idleLoopedAnimations=[];idleLoopedAnimationsSpeed;jumpOneshotAnimations=[];moveLoopedAnimations=[];moveLoopedAnimationsSpeed;moveSpeed=0;_faceTarget;_jumpHeight=0;_moveCompletesWhenStuck=!1;_moveIgnoreAxes={};_moveStartMoveAnimations=!1;_moveStartIdleAnimationsOnCompletion=!0;_moveStoppingDistanceSquared=pR1;_moveStuckAccumulatorMs=0;_moveStuckLastPosition;_moveTarget;_onFace;_onFaceComplete;_onMove;_onMoveComplete;_stopFaceRequested=!1;_stopMoveRequested=!1;constructor(J={}){super();this.idleLoopedAnimations=J.idleLoopedAnimations??this.idleLoopedAnimations,this.idleLoopedAnimationsSpeed=J.idleLoopedAnimationsSpeed??this.idleLoopedAnimationsSpeed,this.jumpOneshotAnimations=J.jumpOneshotAnimations??this.jumpOneshotAnimations,this.moveLoopedAnimations=J.moveLoopedAnimations??this.moveLoopedAnimations,this.moveLoopedAnimationsSpeed=J.moveLoopedAnimationsSpeed??this.moveLoopedAnimationsSpeed}spawn(J){super.spawn(J),this._startIdleAnimations(J)}face(J,$,X){this._faceTarget=J,this.faceSpeed=$,this._onFace=X?.faceCallback,this._onFaceComplete=X?.faceCompleteCallback}jump(J){this._jumpHeight=J}move(J,$,X){this.moveSpeed=$,this._moveCompletesWhenStuck=X?.moveCompletesWhenStuck??!1,this._moveIgnoreAxes=X?.moveIgnoreAxes??{},this._moveStartIdleAnimationsOnCompletion=X?.moveStartIdleAnimationsOnCompletion??!0,this._moveStartMoveAnimations=!0,this._moveStoppingDistanceSquared=X?.moveStoppingDistance?X.moveStoppingDistance**2:pR1,this._moveTarget=J,this._onMove=X?.moveCallback,this._onMoveComplete=X?.moveCompleteCallback,this._moveStuckAccumulatorMs=0,this._moveStuckLastPosition=void 0}stopFace(){this._stopFaceRequested=!0}stopMove(){this._stopMoveRequested=!0}tick(J,$){if(super.tick(J,$),!this._moveTarget&&!this._faceTarget&&!this._jumpHeight)return;if(this._moveStartMoveAnimations)this._startMoveAnimations(J),this._moveStartMoveAnimations=!1;let X=$/1000,Y=J.position;if(J.isDynamic&&this._jumpHeight>0){let Q=Math.abs(J.world.simulation.gravity.y),W=Math.sqrt(2*Q*this._jumpHeight);J.applyImpulse({x:0,y:W*J.mass,z:0}),this._jumpHeight=0,this._startJumpAnimations(J)}if(this._moveTarget){let Q={x:this._moveIgnoreAxes.x?0:this._moveTarget.x-Y.x,y:this._moveIgnoreAxes.y?0:this._moveTarget.y-Y.y,z:this._moveIgnoreAxes.z?0:this._moveTarget.z-Y.z},W=Q.x*Q.x+Q.y*Q.y+Q.z*Q.z,K=!1;if(this._moveCompletesWhenStuck){if(this._moveStuckAccumulatorMs+=$,this._moveStuckAccumulatorMs>=500){if(this._moveStuckLastPosition){let Z=Y.x-this._moveStuckLastPosition.x,G=Y.y-this._moveStuckLastPosition.y,V=Y.z-this._moveStuckLastPosition.z;K=Math.sqrt(Z*Z+G*G+V*V)<this.moveSpeed*0.1}this._moveStuckLastPosition=Y,this._moveStuckAccumulatorMs=0}}if(W>this._moveStoppingDistanceSquared&&!this._stopMoveRequested&&!K){let Z=Math.sqrt(W),G=this.moveSpeed*X,q=Math.min(Z,G)/Z,z={x:Y.x+Q.x*q,y:Y.y+Q.y*q,z:Y.z+Q.z*q};if(J.setPosition(z),this._onMove)this._onMove(z,this._moveTarget)}else{if(this._moveStuckAccumulatorMs=0,this._moveStuckLastPosition=void 0,this._moveTarget=void 0,this._stopMoveRequested=!1,this._moveStartIdleAnimationsOnCompletion)this._startIdleAnimations(J);if(this._onMoveComplete){let Z=this._onMoveComplete;this._onMove=void 0,this._onMoveComplete=void 0,Z(Y)}}}if(this._faceTarget){let Q={x:this._faceTarget.x-Y.x,z:this._faceTarget.z-Y.z},W=Math.atan2(-Q.x,-Q.z),K=J.rotation,Z=Math.atan2(2*(K.w*K.y),1-2*(K.y*K.y)),G=W-Z;while(G>Math.PI)G-=2*Math.PI;while(G<-Math.PI)G+=2*Math.PI;if(Math.abs(G)>0.01&&!this._stopFaceRequested){let V=this.faceSpeed*X,q=Math.abs(G)<V?G:Math.sign(G)*V,H=(Z+q)/2,v={x:0,y:Math.fround(Math.sin(H)),z:0,w:Math.fround(Math.cos(H))};if(J.setRotation(v),this._onFace)this._onFace(K,v)}else if(this._faceTarget=void 0,this._stopFaceRequested=!1,this._onFaceComplete){let V=this._onFaceComplete;this._onFace=void 0,this._onFaceComplete=void 0,V(J.rotation)}}}_startIdleAnimations(J){if(this.idleLoopedAnimationsSpeed)J.setModelAnimationsPlaybackRate(this.idleLoopedAnimationsSpeed);J.stopModelAnimations(this.moveLoopedAnimations),J.stopModelAnimations(this.jumpOneshotAnimations),J.startModelLoopedAnimations(this.idleLoopedAnimations)}_startJumpAnimations(J){J.stopModelAnimations(this.moveLoopedAnimations),J.stopModelAnimations(this.idleLoopedAnimations),J.startModelOneshotAnimations(this.jumpOneshotAnimations)}_startMoveAnimations(J){if(this.moveLoopedAnimationsSpeed)J.setModelAnimationsPlaybackRate(this.moveLoopedAnimationsSpeed);J.stopModelAnimations(this.jumpOneshotAnimations),J.stopModelAnimations(this.idleLoopedAnimations),J.startModelLoopedAnimations(this.moveLoopedAnimations)}}class qn extends VB{_debug=!1;_entity;_maxFall=0;_maxJump=0;_maxOpenSetIterations=200;_onPathfindAbort;_onPathfindComplete;_onWaypointMoveComplete;_onWaypointMoveSkipped;_speed=0;_target;_verticalPenalty=0;_waypoints=[];_waypointNextIndex=0;_waypointStoppingDistance;_waypointTimeoutMs=2000;constructor(J={}){super(J)}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){if(this._target=J,this._speed=$,this._debug=X?.debug??!1,this._maxFall=X?.maxFall?-Math.abs(X.maxFall):0,this._maxJump=X?.maxJump?Math.abs(X.maxJump):0,this._maxOpenSetIterations=X?.maxOpenSetIterations??200,this._onPathfindAbort=X?.pathfindAbortCallback,this._onPathfindComplete=X?.pathfindCompleteCallback,this._onWaypointMoveComplete=X?.waypointMoveCompleteCallback,this._onWaypointMoveSkipped=X?.waypointMoveSkippedCallback,this._verticalPenalty=X?.verticalPenalty??0,this._waypoints=[],this._waypointNextIndex=0,this._waypointStoppingDistance=X?.waypointStoppingDistance,this._waypointTimeoutMs=X?.waypointTimeoutMs??2000/$,!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}_calculatePath(){if(!this._target||!this._entity?.world)return n.error("PathfindingEntityController._calculatePath: No target or world"),!1;let J=this._entity.height,$=this._findGroundedStart();if(!$){if(this._debug)n.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 X={x:Math.floor(this._target.x),y:Math.floor(this._target.y),z:Math.floor(this._target.z)},Y=Math.abs(X.x-$.x),Q=Math.abs(X.y-$.y),W=Math.abs(X.z-$.z);if(Y<=2&&Q<=2&&W<=2&&!this._isNeighborCoordinateBlocked($,X,this._entity.height))return this._waypoints=[{x:$.x+0.5,y:$.y+J/2,z:$.z+0.5},{x:X.x+0.5,y:X.y+J/2,z:X.z+0.5}],!0;if($.x===X.x&&$.y===X.y&&$.z===X.z)return this._waypoints=[{x:$.x+0.5,y:$.y+J/2,z:$.z+0.5}],!0;let Z=this._coordinateToKey($),G=new Map,V=new Map([[Z,0]]),q=new Map([[Z,this._pathfindingHeuristic($,X)]]),z=new Set,H=new dR1.Heap((M,R)=>{let N=q.get(M[0])??1/0,L=q.get(R[0])??1/0;return N-L});H.push([Z,$]);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}],F=[];for(let M=this._maxJump;M>=this._maxFall;M--){if(M===0)continue;let R=Math.abs($.y+M-X.y);F.push({y:M,distanceToTargetY:R})}F.sort((M,R)=>M.distanceToTargetY-R.distanceToTargetY);let U=[...v,...F.flatMap(({y:M})=>v.map((R)=>({...R,y:M})))],j=0,B=Math.abs(X.x-$.x)+Math.abs(X.y-$.y)+Math.abs(X.z-$.z),w=Math.min(this._maxOpenSetIterations,B*20);while(!H.isEmpty()&&j<w){j++;let[M,R]=H.pop();if(R.x===X.x&&R.y===X.y&&R.z===X.z){let O=this._reconstructPath(G,R);if(this._waypoints=O.map((x)=>({x:x.x+0.5,y:x.y+J/2,z:x.z+0.5})),this._debug)console.log(`PathfindingEntityController._calculatePath: Path found after ${j} open set iterations. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`);return!0}z.add(M);let N=V.get(M),L=new Map;for(let O of U){let x=`${O.x},${O.z}`,T=O.y<0;if(T&&L.has(x))continue;let S={x:R.x+O.x,y:R.y+O.y,z:R.z+O.z};if(Math.abs(X.x-S.x)+Math.abs(X.y-S.y)+Math.abs(X.z-S.z)>B*1.5)continue;let I=this._coordinateToKey(S);if(z.has(I))continue;let k=this._isNeighborCoordinateBlocked(R,S,this._entity.height);if(T&&k){L.set(x,!0);continue}if(k)continue;let E=Math.abs(O.x),c=Math.abs(O.y),A=Math.abs(O.z),h=c===0?0:this._verticalPenalty,_=(Math.max(E,c,A)===1&&E+c+A>1?1.4:1)+h,m=N+_,p=V.get(I)??1/0;if(m>=p)continue;G.set(I,R),V.set(I,m);let g=m+this._pathfindingHeuristic(S,X);q.set(I,g),H.push([I,S])}}if(j>=w){if(this._onPathfindAbort?.(),this._debug)n.warning(`PathfindingEntityController._calculatePath: Maximum open set iterations reached (${w}), path search aborted. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`)}else if(this._debug)n.warning(`PathfindingEntityController._calculatePath: No valid path found. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`);return this._target=void 0,this._waypoints=[],!1}_reconstructPath(J,$){let X=[$],Y=$;while(J.has(this._coordinateToKey(Y)))Y=J.get(this._coordinateToKey(Y)),X.unshift(Y);return X}_coordinateToKey(J){return`${J.x},${J.y},${J.z}`}_moveToNextWaypoint(){let J=this._waypointNextIndex>0?this._waypoints[this._waypointNextIndex-1]:void 0,$=this._waypoints[this._waypointNextIndex];if(!$||!this._entity)return;let X=0;if(this._entity.isDynamic&&J&&$.y>J.y){let Y=$.y-J.y,Q=Math.min(Y,this._maxJump)+0.75;this.jump(Q);let W=Math.abs(this._entity.world.simulation.gravity.y),K=Math.sqrt(2*W*Q),Z=J.x+0.5,G=J.z+0.5,V=$.x+0.5,q=$.z+0.5,z=V-Z,H=q-G,v=Math.sqrt(z*z+H*H),F=K/W,U=v/this._speed;X=Math.min(F*0.8,U)*1000}setTimeout(()=>{if(!this._entity)return;let Y=Date.now();this.face($,this._speed),this.move($,this._speed,{moveCompletesWhenStuck:!0,moveIgnoreAxes:{y:this._entity.isDynamic},moveStartIdleAnimationsOnCompletion:this._waypointNextIndex===this._waypoints.length-1,moveStoppingDistance:this._waypointStoppingDistance,moveCallback:()=>{if(Date.now()-Y>this._waypointTimeoutMs&&this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveSkipped?.($,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint()},moveCompleteCallback:()=>{if(this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveComplete?.($,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint();else this._onPathfindComplete?.()}})},X)}_pathfindingHeuristic(J,$){return Math.abs(J.x-$.x)+Math.abs(J.y-$.y)+Math.abs(J.z-$.z)}_isNeighborCoordinateBlocked(J,$,X){if(!this._entity?.world)return!1;let Y=this._entity.world,Q=Math.floor($.x),W=Math.floor($.y),K=Math.floor($.z),Z=Math.floor(J.x),G=Math.floor(J.z);if(!Y.chunkLattice.hasBlock({x:Q,y:W-1,z:K}))return!0;for(let V=0;V<X;V++)if(Y.chunkLattice.hasBlock({x:Q,y:W+V,z:K}))return!0;if(Q!==Z&&K!==G)for(let V=0;V<X;V++){let q=Y.chunkLattice.hasBlock({x:Q,y:W+V,z:G}),z=Y.chunkLattice.hasBlock({x:Z,y:W+V,z:K});if(q||z)return!0}return!1}_findGroundedStart(){if(!this._entity?.world)return;let{x:J,y:$,z:X}=this._entity.position,Y={x:Math.floor(J),y:Math.floor($),z:Math.floor(X)};for(let Q=0;Q<=Math.abs(this._maxFall);Q++)if(this._entity.world.chunkLattice.hasBlock({...Y,y:Y.y-Q-1}))return{...Y,y:Y.y-Q};return}}export{bC6 as startServer,$O1 as WorldManagerEvent,bK as WorldManager,JO1 as WorldLoopEvent,WB as WorldLoop,$n as WorldEvent,KB as World,ai as WebServerEvent,Qz as WebServer,Kz as Vector3,GB as Vector2,QB as Ticker,B3 as TelemetrySpanOperation,T6 as Telemetry,Jn as SimulationEvent,$B as Simulation,VB as SimpleEntityController,YB as SceneUIManager,hh as SceneUIEvent,wU as SceneUI,x78 as SUPPORTED_INPUTS,kF as RigidBodyType,FW as RigidBody,Wz as Quaternion,cO as PlayerUIEvent,zU as PlayerUI,XO1 as PlayerManagerEvent,F$ as PlayerManager,vU as PlayerEvent,o$ as PlayerEntity,Bq0 as PlayerCameraMode,Sh as PlayerCameraEvent,HU as PlayerCamera,kq as Player,CW as PersistenceManager,qn as PathfindingEntityController,XB as ParticleEmitterManager,ri as ParticleEmitterEvent,ti as ParticleEmitter,Oq0 as PLAYER_ROTATION_UPDATE_THRESHOLD,Nq0 as PLAYER_POSITION_UPDATE_THRESHOLD_SQ,k5 as ModelRegistry,u4 as Matrix4,xX as Matrix3,N3 as Matrix2,eN1 as LightType,JB as LightManager,si as LightEvent,oi as Light,w5 as IterationMap,YO1 as GameServerEvent,yK as GameServer,$1 as EventRouter,n as ErrorHandler,LU as EntityManager,BU as EntityEvent,b6 as Entity,Mq0 as ENTITY_ROTATION_UPDATE_THRESHOLD,Lq0 as ENTITY_POSITION_UPDATE_THRESHOLD_SQ,m8 as DefaultPlayerEntityController,fh as DefaultPlayerEntity,wq0 as DEFAULT_ENTITY_RIGID_BODY_OPTIONS,cJ as CollisionGroupsBuilder,OZ as CollisionGroup,Gq as ColliderShape,jU as ColliderMap,S9 as Collider,Cc as CoefficientCombineRule,_h as ChunkLatticeEvent,UU as ChunkLattice,X9 as Chunk,FU as ChatManager,Ah as ChatEvent,kc as BlockTypeRegistryEvent,EF as BlockTypeRegistry,Tc as BlockTypeEvent,A9 as BlockType,eQ as BlockTextureRegistry,R3 as Block,Nn as BaseEntityControllerEvent,iK as BaseEntityController,vz as AudioManager,rC as AudioEvent,zz as Audio,dK as AssetsLibrary};
|
|
554
|
+
-----END PRIVATE KEY-----`;var SC=process.env.PORT??8080,ni="0.14.3",ai;((Q)=>{Q.READY="WEBSERVER.READY";Q.STOPPED="WEBSERVER.STOPPED";Q.ERROR="WEBSERVER.ERROR";Q.UPGRADE="WEBSERVER.UPGRADE"})(ai||={});class Qz extends $1{static instance=new Qz;_webserver=IC.default();_internalHttpServer;constructor(){super();this._webserver.use(($,X,Y)=>{X.header("Access-Control-Allow-Origin","*"),Y()}),this._webserver.get("/",($,X)=>{X.json({status:"OK",version:ni,runtime:"node"})}),this._webserver.use(IC.default.static("assets",{dotfiles:"allow"}));let J=dK.instance.assetsLibraryPath;if(process.env.NODE_ENV!=="production"&&J)this._webserver.use(($,X,Y)=>{let Q=kC6.join(J,$.path);dK.instance.syncAsset(Q),Y()}),this._webserver.use(IC.default.static(J,{dotfiles:"allow"}))}start(){if(!this._internalHttpServer)this._internalHttpServer=TC6.createServer({key:EC,cert:kC},this._webserver),this._internalHttpServer.on("upgrade",this._onUpgrade),this._internalHttpServer.on("error",this._onError),this._internalHttpServer.on("close",this._onStopped);else n.warning("WebServer.start(): server already started!");this._internalHttpServer.listen(SC,this._onStarted),console.info(`WebServer.start(): Server running on port ${SC}.`)}stop(){if(this._internalHttpServer)return new Promise((J,$)=>{this._internalHttpServer.close((X)=>{if(X)$(X);else J(!0)})});else return n.warning("WebServer.stop(): server not started."),Promise.resolve(!1)}_onStarted=()=>{this.emitWithGlobal("WEBSERVER.READY",{})};_onUpgrade=(J,$,X)=>{this.emitWithGlobal("WEBSERVER.UPGRADE",{req:J,socket:$,head:X})};_onError=(J)=>{n.error(`WebServer._onError(): ${J.message}`),this.emitWithGlobal("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{this.emitWithGlobal("WEBSERVER.STOPPED",{})}}var B3;((U)=>{U.BUILD_PACKETS="build_packets";U.ENTITIES_EMIT_UPDATES="entities_emit_updates";U.ENTITIES_TICK="entities_tick";U.NETWORK_SYNCHRONIZE="network_synchronize";U.NETWORK_SYNCHRONIZE_CLEANUP="network_synchronize_cleanup";U.PHYSICS_CLEANUP="physics_cleanup";U.PHYSICS_STEP="physics_step";U.SEND_ALL_PACKETS="send_all_packets";U.SEND_PACKETS="send_packets";U.SERIALIZE_FREE_BUFFERS="serialize_free_buffers";U.SERIALIZE_PACKETS="serialize_packets";U.SERIALIZE_PACKETS_ENCODE="serialize_packets_encode";U.SIMULATION_STEP="simulation_step";U.TICKER_TICK="ticker_tick";U.WORLD_TICK="world_tick"})(B3||={});class T6{static getProcessStats(J=!1){let $=process.memoryUsage(),X={jsHeapSizeMb:{value:$.heapUsed/1024/1024,unit:"megabyte"},jsHeapCapacityMb:{value:$.heapTotal/1024/1024,unit:"megabyte"},jsHeapUsagePercent:{value:$.heapUsed/$.heapTotal,unit:"percent"},processHeapSizeMb:{value:$.heapUsed/1024/1024,unit:"megabyte"},rssSizeMb:{value:$.rss/1024/1024,unit:"megabyte"}};if(J)return X;return Object.fromEntries(Object.entries(X).map(([Y,Q])=>[Y,Q.value]))}static initializeSentry(J,$=50){_P({dsn:J,release:ni,environment:process.env.NODE_ENV||"development",tracesSampleRate:1,initialScope:{tags:{gameId:process.env.HYTOPIA_GAME_ID??"unknown",gameSlug:process.env.HYTOPIA_GAME_SLUG??"unknown",lobbyId:process.env.HYTOPIA_LOBBY_ID??"unknown",region:process.env.REGION??"unknown"}},beforeSend:(X)=>{return X.extra=T6.getProcessStats(),X},beforeSendTransaction:(X)=>{if(X.contexts?.trace?.op==="ticker_tick"){let Q=X?.start_timestamp,W=X?.timestamp;if(!Q||!W)return null;if((W-Q)*1000>$)return X.measurements=T6.getProcessStats(!0),X}return null}})}static startSpan(J,$){if(nU())return h7({attributes:J.attributes,name:J.operation,op:J.operation},$);else return $()}static sentry(){return hp}}if(!gO)console.warn("Connection: msgpackr native acceleration is not enabled, using fallback implementation.");var tN1=new aZ({useFloat32:RU.ALWAYS}),IC6=5000;class v$ extends $1{static _cachedPacketsSerializedBuffer=new Map;_closeTimeout=null;_ws;_wsBinding=!1;_wt;_wtBinding=!1;_wtReliableReader;_wtReliableWriter;_wtUnreliableReader;_wtUnreliableWriter;id;constructor(J,$,X){super();this.id=TH0(),this.onPacket(_0.PacketId.HEARTBEAT,this._onHeartbeatPacket);let Y=()=>{$1.globalInstance.emit("CONNECTION.OPENED",{connection:this,session:X})};if(J)this.bindWs(J),Y();else if($)this.bindWt($).then(Y).catch((Q)=>{this._onClose(),n.error(`Connection.constructor(): Failed to bind WebTransport. Error: ${Q}`)})}static clearCachedPacketsSerializedBuffers(){if(v$._cachedPacketsSerializedBuffer.size>0)v$._cachedPacketsSerializedBuffer.clear()}static serializePackets(J){for(let X of J)if(!_0.isValidPacket(X))return n.error(`Connection.serializePackets(): Invalid packet payload: ${JSON.stringify(X)}`);let $=v$._cachedPacketsSerializedBuffer.get(J);if($)return $;return T6.startSpan({operation:"serialize_packets",attributes:{packets:J.length,packetIds:J.map((X)=>X[0]).join(",")}},(X)=>{let Y=tN1.pack(J);if(Y.byteLength>65536)Y=EC6(Y,{level:1});return X?.setAttribute("serializedBytes",Y.byteLength),v$._cachedPacketsSerializedBuffer.set(J,Y),Y})}bindWs(J){this._wsBinding=!0;let $=this._handleReconnect();if(this._cleanupConnections(),this._ws=J,this._ws.binaryType="nodebuffer",this._ws.onmessage=(X)=>this._onMessage(X.data),this._ws.onclose=this._onClose,this._ws.onerror=this._onError,this._wsBinding=!1,this._signalConnectionId(),$)this.emitWithGlobal("CONNECTION.RECONNECTED",{connection:this})}async bindWt(J){this._wtBinding=!0;let $=this._handleReconnect();this._cleanupConnections(),J.userData.onclose=this._onClose,J.closed.catch(()=>{}).finally(()=>J.userData.onclose?.()),this._wt=J,await this._wt.ready;let X=this._wt.incomingBidirectionalStreams.getReader();try{let{value:Y}=await X.read();if(Y)this._wtReliableReader=Y.readable,this._wtReliableWriter=Y.writable.getWriter()}finally{X.releaseLock()}if(this._wtUnreliableReader=this._wt.datagrams.readable,this._wtUnreliableWriter=this._wt.datagrams.createWritable().getWriter(),(async()=>{if(!this._wtReliableReader)return;let Y=this._wt,Q=_0.createPacketBufferUnframer();for await(let W of this._wtReliableReader){if(Y!==this._wt)return;for(let K of Q(W))this._onMessage(K)}})().catch(()=>this._wt?.close()),(async()=>{if(!this._wtUnreliableReader)return;let Y=this._wt;for await(let Q of this._wtUnreliableReader){if(Y!==this._wt)return;this._onMessage(Q)}})().catch(()=>this._wt?.close()),this._wtBinding=!1,this._signalConnectionId(),$)this.emitWithGlobal("CONNECTION.RECONNECTED",{connection:this})}disconnect(){try{this._ws?.close(),this._wt?.close()}catch(J){n.error(`Connection.disconnect(): Connection disconnect failed. Error: ${J}`)}}onPacket(J,$){this.on("CONNECTION.PACKET_RECEIVED",({packet:X})=>{if(X[0]===J)$(X)})}send(J,$=!0){if(this._closeTimeout||this._wsBinding||this._wtBinding)return;if(!this._ws&&!this._wt)return;let X=this._ws&&this._ws.readyState===Cq.default.OPEN,Y=this._wt&&(this._wt.state==="connected"||this._wt.state==="draining");if(!X&&!Y)return;T6.startSpan({operation:"send_packets"},()=>{try{let Q=v$.serializePackets(J);if(!Q)return;if(Y)if($||Q.byteLength>1200)this._wtReliableWriter?.write(_0.framePacketBuffer(Q)).catch(()=>{n.error("Connection.send(): WebTransport reliable write failed, connection closing?")});else this._wtUnreliableWriter?.write(Q).catch(()=>{n.error("Connection.send(): WebTransport unreliable write failed, connection closing?")});else this._ws.send(Q);this.emitWithGlobal("CONNECTION.PACKETS_SENT",{connection:this,packets:J})}catch(Q){n.error(`Connection.send(): Packet send failed. Error: ${Q}`)}})}_onHeartbeatPacket=()=>{this.send([_0.createPacket(_0.bidirectionalPackets.heartbeatPacketDefinition,null)],!0)};_onMessage=(J)=>{try{let $=this._deserialize(J);if(!$)return;this.emitWithGlobal("CONNECTION.PACKET_RECEIVED",{connection:this,packet:$})}catch($){n.error(`Connection._ws.onmessage(): Error: ${$}`)}};_onClose=()=>{this.emitWithGlobal("CONNECTION.DISCONNECTED",{connection:this}),this._closeTimeout=setTimeout(()=>{this.emitWithGlobal("CONNECTION.CLOSED",{connection:this}),this.offAll()},IC6)};_onError=(J)=>{this.emitWithGlobal("CONNECTION.ERROR",{connection:this,error:J})};_cleanupConnections(){if(this._ws)this._ws.onmessage=()=>{},this._ws.onclose=()=>{},this._ws.onerror=()=>{};if(this._wt)this._wt.userData.onclose=()=>{};this._signalKill(),this._ws=void 0,this._wt=void 0,this._wtReliableReader=void 0,this._wtReliableWriter=void 0,this._wtUnreliableReader=void 0,this._wtUnreliableWriter=void 0}_deserialize(J){let $=tN1.unpack(J);if(!$||typeof $!=="object"||typeof $[0]!=="number")return n.error(`Connection._deserialize(): Invalid packet format. Packet: ${JSON.stringify($)}`);if(!_0.isValidPacket($))return n.error(`Connection._deserialize(): Invalid packet payload. Packet: ${JSON.stringify($)}`);return $}_handleReconnect(){let J=!!this._ws||!!this._wt;if(J&&this._closeTimeout)clearTimeout(this._closeTimeout),this._closeTimeout=null;return J}_signalConnectionId(){this.send([_0.createPacket(_0.bidirectionalPackets.connectionPacketDefinition,{i:this.id})])}_signalKill(){this.send([_0.createPacket(_0.bidirectionalPackets.connectionPacketDefinition,{k:!0})])}}class JB{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach(($)=>{$.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter(($)=>$.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let $=this._nextLightId;return this._lights.set($,J),this._nextLightId++,$}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}class w5{_map=new Map;_values=[];_isDirty=!1;get size(){return this._map.size}get valuesArray(){if(this._isDirty)this._syncArray();return this._values}get(J){return this._map.get(J)}set(J,$){let X=this._map.has(J);if(this._map.set(J,$),!X)this._values.push($);else this._isDirty=!0;return this}has(J){return this._map.has(J)}delete(J){let $=this._map.delete(J);if($)this._isDirty=!0;return $}clear(){this._map.clear(),this._values.length=0,this._isDirty=!1}forEach(J,$){this._map.forEach((X,Y)=>{J.call($,X,Y,this)})}keys(){return this._map.keys()}values(){return this._map.values()}entries(){return this._map.entries()}[Symbol.iterator](){return this._map[Symbol.iterator]()}_syncArray(){this._values.length=0;for(let J of this._map.values())this._values.push(J);this._isDirty=!1}}var eN1;((X)=>{X[X.POINTLIGHT=0]="POINTLIGHT";X[X.SPOTLIGHT=1]="SPOTLIGHT"})(eN1||={});var si;((H)=>{H.DESPAWN="LIGHT.DESPAWN";H.SET_ANGLE="LIGHT.SET_ANGLE";H.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";H.SET_COLOR="LIGHT.SET_COLOR";H.SET_DISTANCE="LIGHT.SET_DISTANCE";H.SET_INTENSITY="LIGHT.SET_INTENSITY";H.SET_OFFSET="LIGHT.SET_OFFSET";H.SET_PENUMBRA="LIGHT.SET_PENUMBRA";H.SET_POSITION="LIGHT.SET_POSITION";H.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";H.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";H.SPAWN="LIGHT.SPAWN"})(si||={});class oi extends $1{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.fatalError("Either attachedToEntity or position must be set, but not both.");super();n.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 n.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&&this._offset.x===J.x&&this._offset.y===J.y&&this._offset.z===J.z)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&&this._position.x===J.x&&this._position.y===J.y&&this._position.z===J.z)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 n.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 n.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 V1.serializeLight(this)}}var ri;((A)=>{A.BURST="PARTICLE_EMITTER.BURST";A.DESPAWN="PARTICLE_EMITTER.DESPAWN";A.SET_ALPHA_TEST="PARTICLE_EMITTER.SET_ALPHA_TEST";A.SET_ATTACHED_TO_ENTITY="PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY";A.SET_ATTACHED_TO_ENTITY_NODE_NAME="PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME";A.SET_COLOR_END="PARTICLE_EMITTER.SET_COLOR_END";A.SET_COLOR_END_VARIANCE="PARTICLE_EMITTER.SET_COLOR_END_VARIANCE";A.SET_COLOR_START="PARTICLE_EMITTER.SET_COLOR_START";A.SET_COLOR_START_VARIANCE="PARTICLE_EMITTER.SET_COLOR_START_VARIANCE";A.SET_GRAVITY="PARTICLE_EMITTER.SET_GRAVITY";A.SET_LIFETIME="PARTICLE_EMITTER.SET_LIFETIME";A.SET_LIFETIME_VARIANCE="PARTICLE_EMITTER.SET_LIFETIME_VARIANCE";A.SET_MAX_PARTICLES="PARTICLE_EMITTER.SET_MAX_PARTICLES";A.SET_OFFSET="PARTICLE_EMITTER.SET_OFFSET";A.SET_OPACITY_END="PARTICLE_EMITTER.SET_OPACITY_END";A.SET_OPACITY_END_VARIANCE="PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE";A.SET_OPACITY_START="PARTICLE_EMITTER.SET_OPACITY_START";A.SET_OPACITY_START_VARIANCE="PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE";A.SET_PAUSED="PARTICLE_EMITTER.SET_PAUSED";A.SET_POSITION="PARTICLE_EMITTER.SET_POSITION";A.SET_POSITION_VARIANCE="PARTICLE_EMITTER.SET_POSITION_VARIANCE";A.SET_RATE="PARTICLE_EMITTER.SET_RATE";A.SET_RATE_VARIANCE="PARTICLE_EMITTER.SET_RATE_VARIANCE";A.SET_SIZE_END="PARTICLE_EMITTER.SET_SIZE_END";A.SET_SIZE_END_VARIANCE="PARTICLE_EMITTER.SET_SIZE_END_VARIANCE";A.SET_SIZE_START="PARTICLE_EMITTER.SET_SIZE_START";A.SET_SIZE_START_VARIANCE="PARTICLE_EMITTER.SET_SIZE_START_VARIANCE";A.SET_TEXTURE_URI="PARTICLE_EMITTER.SET_TEXTURE_URI";A.SET_TRANSPARENT="PARTICLE_EMITTER.SET_TRANSPARENT";A.SET_VELOCITY="PARTICLE_EMITTER.SET_VELOCITY";A.SET_VELOCITY_VARIANCE="PARTICLE_EMITTER.SET_VELOCITY_VARIANCE";A.SPAWN="PARTICLE_EMITTER.SPAWN"})(ri||={});class ti extends $1{_id;_alphaTest;_attachedToEntity;_attachedToEntityNodeName;_colorEnd;_colorEndVariance;_colorStart;_colorStartVariance;_gravity;_lifetime;_lifetimeVariance;_maxParticles;_offset;_opacityEnd;_opacityEndVariance;_opacityStart;_opacityStartVariance;_paused;_position;_positionVariance;_rate;_rateVariance;_sizeEnd;_sizeEndVariance;_sizeStart;_sizeStartVariance;_sizeVariance;_textureUri;_transparent;_velocity;_velocityVariance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)n.fatalError("Either attachedToEntity or position must be set, but not both.");if(!J.textureUri)n.fatalError("ParticleEmitter.constructor(): textureUri must be provided.");super();this._alphaTest=J.alphaTest??0.05,this._attachedToEntity=J.attachedToEntity,this._attachedToEntityNodeName=J.attachedToEntityNodeName,this._colorEnd=J.colorEnd,this._colorEndVariance=J.colorEndVariance,this._colorStart=J.colorStart,this._colorStartVariance=J.colorStartVariance,this._gravity=J.gravity,this._lifetime=J.lifetime,this._lifetimeVariance=J.lifetimeVariance,this._maxParticles=J.maxParticles,this._offset=J.offset,this._opacityEnd=J.opacityEnd,this._opacityEndVariance=J.opacityEndVariance,this._opacityStart=J.opacityStart,this._opacityStartVariance=J.opacityStartVariance,this._paused=!1,this._position=J.position,this._positionVariance=J.positionVariance,this._rate=J.rate,this._rateVariance=J.rateVariance,this._sizeEnd=J.sizeEnd,this._sizeEndVariance=J.sizeEndVariance,this._sizeStart=J.sizeStart,this._sizeStartVariance=J.sizeStartVariance,this._textureUri=J.textureUri,this._transparent=J.transparent,this._velocity=J.velocity,this._velocityVariance=J.velocityVariance}get id(){return this._id}get alphaTest(){return this._alphaTest}get attachedToEntity(){return this._attachedToEntity}get attachedToEntityNodeName(){return this._attachedToEntityNodeName}get colorEnd(){return this._colorEnd}get colorEndVariance(){return this._colorEndVariance}get colorStart(){return this._colorStart}get colorStartVariance(){return this._colorStartVariance}get gravity(){return this._gravity}get isSpawned(){return this._id!==void 0}get lifetime(){return this._lifetime}get lifetimeVariance(){return this._lifetimeVariance}get maxParticles(){return this._maxParticles}get offset(){return this._offset}get opacityEnd(){return this._opacityEnd}get opacityEndVariance(){return this._opacityEndVariance}get opacityStart(){return this._opacityStart}get opacityStartVariance(){return this._opacityStartVariance}get paused(){return this._paused}get position(){return this._position}get positionVariance(){return this._positionVariance}get rate(){return this._rate}get rateVariance(){return this._rateVariance}get sizeEnd(){return this._sizeEnd}get sizeEndVariance(){return this._sizeEndVariance}get sizeStart(){return this._sizeStart}get sizeStartVariance(){return this._sizeStartVariance}get sizeVariance(){return this._sizeVariance}get textureUri(){return this._textureUri}get transparent(){return this._transparent}get velocity(){return this._velocity}get velocityVariance(){return this._velocityVariance}get world(){return this._world}setAlphaTest(J){if(this._alphaTest===J)return;if(this._alphaTest=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_ALPHA_TEST",{particleEmitter:this,alphaTest:J})}setAttachedToEntity(J){if(!J.isSpawned)return n.error(`ParticleEmitter.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,"PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY",{particleEmitter:this,entity:J})}setAttachedToEntityNodeName(J){if(this._attachedToEntityNodeName===J)return;if(this._attachedToEntityNodeName=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME",{particleEmitter:this,attachedToEntityNodeName:J})}setColorEnd(J){if(this._colorEnd&&this._colorEnd.r===J.r&&this._colorEnd.g===J.g&&this._colorEnd.b===J.b)return;if(this._colorEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_END",{particleEmitter:this,colorEnd:J})}setColorEndVariance(J){if(this._colorEndVariance&&this._colorEndVariance.r===J.r&&this._colorEndVariance.g===J.g&&this._colorEndVariance.b===J.b)return;if(this._colorEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_END_VARIANCE",{particleEmitter:this,colorEndVariance:J})}setColorStart(J){if(this._colorStart&&this._colorStart.r===J.r&&this._colorStart.g===J.g&&this._colorStart.b===J.b)return;if(this._colorStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_START",{particleEmitter:this,colorStart:J})}setColorStartVariance(J){if(this._colorStartVariance&&this._colorStartVariance.r===J.r&&this._colorStartVariance.g===J.g&&this._colorStartVariance.b===J.b)return;if(this._colorStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_COLOR_START_VARIANCE",{particleEmitter:this,colorStartVariance:J})}setGravity(J){if(this._gravity&&this._gravity.x===J.x&&this._gravity.y===J.y&&this._gravity.z===J.z)return;if(this._gravity=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_GRAVITY",{particleEmitter:this,gravity:J})}setLifetime(J){if(this._lifetime===J)return;if(this._lifetime=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_LIFETIME",{particleEmitter:this,lifetime:J})}setLifetimeVariance(J){if(this._lifetimeVariance===J)return;if(this._lifetimeVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_LIFETIME_VARIANCE",{particleEmitter:this,lifetimeVariance:J})}setMaxParticles(J){if(this._maxParticles===J)return;if(this._maxParticles=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_MAX_PARTICLES",{particleEmitter:this,maxParticles:J})}setOffset(J){if(this._offset&&this._offset.x===J.x&&this._offset.y===J.y&&this._offset.z===J.z)return;if(this._offset=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OFFSET",{particleEmitter:this,offset:J})}setOpacityEnd(J){if(this._opacityEnd===J)return;if(this._opacityEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_END",{particleEmitter:this,opacityEnd:J})}setOpacityEndVariance(J){if(this._opacityEndVariance===J)return;if(this._opacityEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE",{particleEmitter:this,opacityEndVariance:J})}setOpacityStart(J){if(this._opacityStart===J)return;if(this._opacityStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_START",{particleEmitter:this,opacityStart:J})}setOpacityStartVariance(J){if(this._opacityStartVariance===J)return;if(this._opacityStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE",{particleEmitter:this,opacityStartVariance:J})}setPosition(J){if(this._position&&this._position.x===J.x&&this._position.y===J.y&&this._position.z===J.z)return;if(this._position=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_POSITION",{particleEmitter:this,position:J})}setPositionVariance(J){if(this._positionVariance&&this._positionVariance.x===J.x&&this._positionVariance.y===J.y&&this._positionVariance.z===J.z)return;if(this._positionVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_POSITION_VARIANCE",{particleEmitter:this,positionVariance:J})}setRate(J){if(this._rate===J)return;if(this._rate=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_RATE",{particleEmitter:this,rate:J})}setRateVariance(J){if(this._rateVariance===J)return;if(this._rateVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_RATE_VARIANCE",{particleEmitter:this,rateVariance:J})}setSizeEnd(J){if(this._sizeEnd===J)return;if(this._sizeEnd=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_END",{particleEmitter:this,sizeEnd:J})}setSizeEndVariance(J){if(this._sizeEndVariance===J)return;if(this._sizeEndVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_END_VARIANCE",{particleEmitter:this,sizeEndVariance:J})}setSizeStart(J){if(this._sizeStart===J)return;if(this._sizeStart=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_START",{particleEmitter:this,sizeStart:J})}setSizeStartVariance(J){if(this._sizeStartVariance===J)return;if(this._sizeStartVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_SIZE_START_VARIANCE",{particleEmitter:this,sizeStartVariance:J})}setTextureUri(J){if(this._textureUri===J)return;if(this._textureUri=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_TEXTURE_URI",{particleEmitter:this,textureUri:J})}setTransparent(J){if(this._transparent===J)return;if(this._transparent=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_TRANSPARENT",{particleEmitter:this,transparent:J})}setVelocity(J){if(this._velocity&&this._velocity.x===J.x&&this._velocity.y===J.y&&this._velocity.z===J.z)return;if(this._velocity=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_VELOCITY",{particleEmitter:this,velocity:J})}setVelocityVariance(J){if(this._velocityVariance&&this._velocityVariance.x===J.x&&this._velocityVariance.y===J.y&&this._velocityVariance.z===J.z)return;if(this._velocityVariance=J,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_VELOCITY_VARIANCE",{particleEmitter:this,velocityVariance:J})}burst(J){if(this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.BURST",{particleEmitter:this,count:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.particleEmitterManager.unregisterParticleEmitter(this),this.emitWithWorld(this._world,"PARTICLE_EMITTER.DESPAWN",{particleEmitter:this}),this._id=void 0,this._world=void 0}restart(){if(!this._paused)return;if(this._paused=!1,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_PAUSED",{particleEmitter:this,paused:this._paused})}stop(){if(this._paused)return;if(this._paused=!0,this.isSpawned)this.emitWithWorld(this._world,"PARTICLE_EMITTER.SET_PAUSED",{particleEmitter:this,paused:this._paused})}spawn(J){if(this.isSpawned)return;if(this._attachedToEntity&&!this._attachedToEntity.isSpawned)return n.error(`ParticleEmitter.spawn(): Attached entity ${this._attachedToEntity.id} must be spawned before spawning ParticleEmitter!`);this._id=J.particleEmitterManager.registerParticleEmitter(this),this._world=J,this.emitWithWorld(J,"PARTICLE_EMITTER.SPAWN",{particleEmitter:this})}serialize(){return V1.serializeParticleEmitter(this)}}var SC6={x:0,y:-32,z:0},ei=60,Jn;((Q)=>{Q.STEP_START="SIMULATION.STEP_START";Q.STEP_END="SIMULATION.STEP_END";Q.DEBUG_RAYCAST="SIMULATION.DEBUG_RAYCAST";Q.DEBUG_RENDER="SIMULATION.DEBUG_RENDER"})(Jn||={});class $B extends $1{_colliderMap=new jU;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_debugRenderingFilterFlags;_rapierEventQueue;_rapierSimulation;_world;constructor(J,$=ei,X=SC6){super();this._rapierEventQueue=new W8.EventQueue(!0),this._rapierSimulation=new W8.World(X),this._rapierSimulation.timestep=Math.fround(1/$),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}createRawCollider(J,$){return this._rapierSimulation.createCollider(J,$)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J,$=W8.QueryFilterFlags.EXCLUDE_FIXED){this._debugRenderingEnabled=J,this._debugRenderingFilterFlags=$}getContactManifolds(J,$){let X=[];return this._rapierSimulation.narrowPhase.contactPair(J,$,(Y,Q)=>{if(Y.numContacts()===0)return;let W=Y.normal(),K=[];for(let Z=0;Z<Y.numSolverContacts();Z++)K.push(Y.solverContactPoint(Z));X.push({contactPoints:K,localNormalA:!Q?Y.localNormal1():Y.localNormal2(),localNormalB:!Q?Y.localNormal2():Y.localNormal1(),normal:!Q?W:{x:-W.x,y:-W.y,z:-W.z}})}),X}intersectionsWithRawShape(J,$,X,Y={}){let Q=new Set,W=[];return this._rapierSimulation.intersectionsWithShape($,X,J,(K)=>{let Z=this._colliderMap.getColliderHandleBlockType(K.handle);if(Z&&!Q.has(Z))return Q.add(Z),W.push({intersectedBlockType:Z}),!0;let G=this._colliderMap.getColliderHandleEntity(K.handle);if(G&&!Q.has(G))return Q.add(G),W.push({intersectedEntity:G}),!0;return!0},Y.filterFlags,Y.filterGroups,Y.filterExcludeCollider,Y.filterExcludeRigidBody,Y.filterPredicate),W}raycast(J,$,X,Y={}){let Q=new W8.Ray(J,$),W=this._rapierSimulation.castRay(Q,X,Y.solidMode??!0,Y.filterFlags,Y.filterGroups,Y.filterExcludeCollider,Y.filterExcludeRigidBody,Y.filterPredicate);if(this._debugRaycastingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:$,length:X,hit:!!W});if(!W)return null;let K=Q.pointAt(W.timeOfImpact),Z=W.timeOfImpact,G=W.collider,V=this._colliderMap.getColliderHandleBlockType(G.handle);if(V)return{hitBlock:R3.fromGlobalCoordinate({x:Math.floor(K.x-(Q.dir.x<0?0.0001:-0.0001)),y:Math.floor(K.y-(Q.dir.y<0?0.0001:-0.0001)),z:Math.floor(K.z-(Q.dir.z<0?0.0001:-0.0001))},V),hitPoint:K,hitDistance:Z};let q=this._colliderMap.getColliderHandleEntity(G.handle);if(q)return{hitEntity:q,hitPoint:K,hitDistance:Z};return null}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 $=performance.now();if(T6.startSpan({operation:"physics_step"},()=>{this._rapierSimulation.step(this._rapierEventQueue)}),T6.startSpan({operation:"physics_cleanup"},()=>{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()-$}),this._debugRenderingEnabled)this.emitWithWorld(this._world,"SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender(this._debugRenderingFilterFlags)})};_onCollisionEvent=(J,$,X)=>{let[Y,Q]=this._getCollisionObjects(J,$);if(!Y||!Q)return;let W=(K,Z)=>{if(K instanceof A9&&Z instanceof b6&&K.hasListeners("BLOCK_TYPE.ENTITY_COLLISION"))K.emit("BLOCK_TYPE.ENTITY_COLLISION",{blockType:K,entity:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(K instanceof b6&&Z instanceof A9&&K.hasListeners("ENTITY.BLOCK_COLLISION"))K.emit("ENTITY.BLOCK_COLLISION",{entity:K,blockType:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(K instanceof b6&&Z instanceof b6&&K.hasListeners("ENTITY.ENTITY_COLLISION"))K.emit("ENTITY.ENTITY_COLLISION",{entity:K,otherEntity:Z,started:X,colliderHandleA:J,colliderHandleB:$});else if(typeof K==="function"&&(Z instanceof b6||Z instanceof A9))K(Z,X,J,$)};W(Y,Q),W(Q,Y)};_onContactForceEvent=(J)=>{let[$,X]=this._getCollisionObjects(J.collider1(),J.collider2());if(!$||typeof $==="function"||!X||typeof X==="function")return;let Y={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},Q=(W,K)=>{if(W instanceof A9&&K instanceof b6&&W.hasListeners("BLOCK_TYPE.ENTITY_CONTACT_FORCE"))W.emit("BLOCK_TYPE.ENTITY_CONTACT_FORCE",{blockType:W,entity:K,contactForceData:Y});else if(W instanceof b6&&K instanceof A9&&W.hasListeners("ENTITY.BLOCK_CONTACT_FORCE"))W.emit("ENTITY.BLOCK_CONTACT_FORCE",{entity:W,blockType:K,contactForceData:Y});else if(W instanceof b6&&K instanceof b6&&W.hasListeners("ENTITY.ENTITY_CONTACT_FORCE"))W.emit("ENTITY.ENTITY_CONTACT_FORCE",{entity:W,otherEntity:K,contactForceData:Y})};Q($,X),Q(X,$)};_getCollisionObjects(J,$){let X=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),Y=this._colliderMap.getColliderHandleBlockType($)??this._colliderMap.getColliderHandleCollisionCallback($)??this._colliderMap.getColliderHandleEntity($);return[X,Y]}}class AC{_synchronizedPlayerReliablePackets=new w5;_queuedBroadcasts=[];_queuedAudioSynchronizations=new w5;_queuedBlockSynchronizations=new w5;_queuedBlockTypeSynchronizations=new w5;_queuedChunkSynchronizations=new w5;_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations=new w5;_queuedLightSynchronizations=new w5;_queuedParticleEmitterSynchronizations=new w5;_queuedPerPlayerSynchronizations=new w5;_queuedPerPlayerCameraSynchronizations=new w5;_queuedPerPlayerUISynchronizations=new w5;_queuedPerPlayerUIDatasSynchronizations=new w5;_queuedPlayerSynchronizations=new w5;_queuedSceneUISynchronizations=new w5;_queuedWorldSynchronization;_loadedSceneUIs=new Set;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkLatticeEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToParticleEmitterEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){let J=[],$=[],X=this._world.loop.currentTick;if(this._queuedPerPlayerSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerSynchronizations)this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(...Q);if(this._queuedEntitySynchronizations.size>0){let Y=[],Q=[];for(let W of this._queuedEntitySynchronizations.valuesArray){let K=!1;for(let Z in W)if(Z!=="i"&&Z!=="p"&&Z!=="r"){K=!0;break}if(K)Y.push(W);else Q.push(W)}if(Q.length>0){let W=_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,Q,X);$.push(W)}if(Y.length>0){let W=_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,Y,X);J.push(W);for(let K of this._synchronizedPlayerReliablePackets.valuesArray)K.push(W)}}if(this._queuedAudioSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.audiosPacketDefinition,this._queuedAudioSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBlockTypeSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.blockTypesPacketDefinition,this._queuedBlockTypeSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedChunkSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.chunksPacketDefinition,this._queuedChunkSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBlockSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.blocksPacketDefinition,this._queuedBlockSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedLightSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.lightsPacketDefinition,this._queuedLightSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedParticleEmitterSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.particleEmittersPacketDefinition,this._queuedParticleEmitterSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedPerPlayerUISynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerUISynchronizations){let W=_0.createPacket(_0.outboundPackets.uiPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedPerPlayerUIDatasSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerUIDatasSynchronizations){let W=_0.createPacket(_0.outboundPackets.uiDatasPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedSceneUISynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.sceneUIsPacketDefinition,this._queuedSceneUISynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedWorldSynchronization){let Y=_0.createPacket(_0.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedPerPlayerCameraSynchronizations.size>0)for(let[Y,Q]of this._queuedPerPlayerCameraSynchronizations){let W=_0.createPacket(_0.outboundPackets.cameraPacketDefinition,Q,X);this._createOrGetSynchronizedPlayerReliablePackets(Y,J).push(W)}if(this._queuedPlayerSynchronizations.size>0){let Y=_0.createPacket(_0.outboundPackets.playersPacketDefinition,this._queuedPlayerSynchronizations.valuesArray,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedBroadcasts.length>0)for(let Y of this._queuedBroadcasts){J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}if(this._queuedDebugRaycastSynchronizations.length>0){let Y=_0.createPacket(_0.outboundPackets.physicsDebugRaycastsPacketDefinition,this._queuedDebugRaycastSynchronizations,X);J.push(Y);for(let Q of this._synchronizedPlayerReliablePackets.valuesArray)Q.push(Y)}T6.startSpan({operation:"send_all_packets"},()=>{for(let Y of F$.instance.getConnectedPlayersByWorld(this._world)){let Q=this._synchronizedPlayerReliablePackets.get(Y)??J;if(Q.length>0)Y.connection.send(Q);if($.length>0)Y.connection.send($,!1)}}),T6.startSpan({operation:"network_synchronize_cleanup"},()=>{if(this._queuedBroadcasts.length>0)this._queuedBroadcasts.length=0;if(this._queuedAudioSynchronizations.size>0)this._queuedAudioSynchronizations.clear();if(this._queuedBlockSynchronizations.size>0)this._queuedBlockSynchronizations.clear();if(this._queuedBlockTypeSynchronizations.size>0)this._queuedBlockTypeSynchronizations.clear();if(this._queuedChunkSynchronizations.size>0)this._queuedChunkSynchronizations.clear();if(this._queuedDebugRaycastSynchronizations.length>0)this._queuedDebugRaycastSynchronizations.length=0;if(this._queuedEntitySynchronizations.size>0)this._queuedEntitySynchronizations.clear();if(this._queuedLightSynchronizations.size>0)this._queuedLightSynchronizations.clear();if(this._queuedParticleEmitterSynchronizations.size>0)this._queuedParticleEmitterSynchronizations.clear();if(this._queuedPerPlayerSynchronizations.size>0)this._queuedPerPlayerSynchronizations.clear();if(this._queuedPerPlayerCameraSynchronizations.size>0)this._queuedPerPlayerCameraSynchronizations.clear();if(this._queuedPerPlayerUISynchronizations.size>0)this._queuedPerPlayerUISynchronizations.clear();if(this._queuedPerPlayerUIDatasSynchronizations.size>0)this._queuedPerPlayerUIDatasSynchronizations.clear();if(this._queuedPlayerSynchronizations.size>0)this._queuedPlayerSynchronizations.clear();if(this._queuedSceneUISynchronizations.size>0)this._queuedSceneUISynchronizations.clear();if(this._queuedWorldSynchronization)this._queuedWorldSynchronization=void 0;if(this._loadedSceneUIs.size>0)this._loadedSceneUIs.clear();if(this._spawnedChunks.size>0)this._spawnedChunks.clear();if(this._spawnedEntities.size>0)this._spawnedEntities.clear();if(this._synchronizedPlayerReliablePackets.size>0)this._synchronizedPlayerReliablePackets.clear();v$.clearCachedPacketsSerializedBuffers()})}_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)}_subscribeToChunkLatticeEvents(){this._world.final("CHUNK_LATTICE.ADD_CHUNK",this._onChunkLatticeAddChunk),this._world.final("CHUNK_LATTICE.REMOVE_CHUNK",this._onChunkLatticeRemoveChunk),this._world.final("CHUNK_LATTICE.SET_BLOCK",this._onChunkLatticeSetBlock)}_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_MODEL_SCALE",this._onEntitySetModelScale),this._world.final("ENTITY.SET_MODEL_SHOWN_NODES",this._onEntitySetModelShownNodes),this._world.final("ENTITY.SET_MODEL_TEXTURE_URI",this._onEntitySetModelTextureUri),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)}_subscribeToParticleEmitterEvents(){this._world.final("PARTICLE_EMITTER.DESPAWN",this._onParticleEmitterDespawn),this._world.final("PARTICLE_EMITTER.BURST",this._onParticleEmitterBurst),this._world.final("PARTICLE_EMITTER.SET_ALPHA_TEST",this._onParticleEmitterSetAlphaTest),this._world.final("PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY",this._onParticleEmitterSetAttachedToEntity),this._world.final("PARTICLE_EMITTER.SET_ATTACHED_TO_ENTITY_NODE_NAME",this._onParticleEmitterSetAttachedToEntityNodeName),this._world.final("PARTICLE_EMITTER.SET_COLOR_END",this._onParticleEmitterSetColorEnd),this._world.final("PARTICLE_EMITTER.SET_COLOR_END_VARIANCE",this._onParticleEmitterSetColorEndVariance),this._world.final("PARTICLE_EMITTER.SET_COLOR_START",this._onParticleEmitterSetColorStart),this._world.final("PARTICLE_EMITTER.SET_COLOR_START_VARIANCE",this._onParticleEmitterSetColorStartVariance),this._world.final("PARTICLE_EMITTER.SET_GRAVITY",this._onParticleEmitterSetGravity),this._world.final("PARTICLE_EMITTER.SET_LIFETIME",this._onParticleEmitterSetLifetime),this._world.final("PARTICLE_EMITTER.SET_LIFETIME_VARIANCE",this._onParticleEmitterSetLifetimeVariance),this._world.final("PARTICLE_EMITTER.SET_MAX_PARTICLES",this._onParticleEmitterSetMaxParticles),this._world.final("PARTICLE_EMITTER.SET_OFFSET",this._onParticleEmitterSetOffset),this._world.final("PARTICLE_EMITTER.SET_OPACITY_END",this._onParticleEmitterSetOpacityEnd),this._world.final("PARTICLE_EMITTER.SET_OPACITY_END_VARIANCE",this._onParticleEmitterSetOpacityEndVariance),this._world.final("PARTICLE_EMITTER.SET_OPACITY_START",this._onParticleEmitterSetOpacityStart),this._world.final("PARTICLE_EMITTER.SET_OPACITY_START_VARIANCE",this._onParticleEmitterSetOpacityStartVariance),this._world.final("PARTICLE_EMITTER.SET_PAUSED",this._onParticleEmitterSetPaused),this._world.final("PARTICLE_EMITTER.SET_POSITION",this._onParticleEmitterSetPosition),this._world.final("PARTICLE_EMITTER.SET_POSITION_VARIANCE",this._onParticleEmitterSetPositionVariance),this._world.final("PARTICLE_EMITTER.SET_RATE",this._onParticleEmitterSetRate),this._world.final("PARTICLE_EMITTER.SET_RATE_VARIANCE",this._onParticleEmitterSetRateVariance),this._world.final("PARTICLE_EMITTER.SET_SIZE_END",this._onParticleEmitterSetSizeEnd),this._world.final("PARTICLE_EMITTER.SET_SIZE_END_VARIANCE",this._onParticleEmitterSetSizeEndVariance),this._world.final("PARTICLE_EMITTER.SET_SIZE_START",this._onParticleEmitterSetSizeStart),this._world.final("PARTICLE_EMITTER.SET_SIZE_START_VARIANCE",this._onParticleEmitterSetSizeStartVariance),this._world.final("PARTICLE_EMITTER.SET_TEXTURE_URI",this._onParticleEmitterSetTextureUri),this._world.final("PARTICLE_EMITTER.SET_TRANSPARENT",this._onParticleEmitterSetTransparent),this._world.final("PARTICLE_EMITTER.SET_VELOCITY",this._onParticleEmitterSetVelocity),this._world.final("PARTICLE_EMITTER.SET_VELOCITY_VARIANCE",this._onParticleEmitterSetVelocityVariance),this._world.final("PARTICLE_EMITTER.SPAWN",this._onParticleEmitterSpawn)}_subscribeToPlayerEvents(){this._world.final("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.final("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.final("PLAYER.RECONNECTED_WORLD",this._onPlayerReconnectedWorld),this._world.final("PLAYER.REQUEST_NOTIFICATION_PERMISSION",this._onPlayerRequestNotificationPermission),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_MODEL_SHOWN_NODES",this._onPlayerCameraSetModelShownNodes),this._world.final("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.final("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.final("PLAYER_CAMERA.SET_SHOULDER_ANGLE",this._onPlayerCameraSetShoulderAngle),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),this._world.final("WORLD.SET_FOG_COLOR",this._onWorldSetFogColor),this._world.final("WORLD.SET_FOG_FAR",this._onWorldSetFogFar),this._world.final("WORLD.SET_FOG_NEAR",this._onWorldSetFogNear),this._world.final("WORLD.SET_SKYBOX_INTENSITY",this._onWorldSetSkyboxIntensity),this._world.final("WORLD.SET_SKYBOX_URI",this._onWorldSetSkyboxUri)}_onAudioPause=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.pa=!0,delete $.pl,delete $.r};_onAudioPlay=(J)=>{let $=J.audio.serialize();$.pl=!0,delete $.pa,delete $.r,this._queuedAudioSynchronizations.set($.i,$)};_onAudioPlayRestart=(J)=>{let $=J.audio.serialize();$.r=!0,delete $.pa,delete $.pl,this._queuedAudioSynchronizations.set($.i,$)};_onAudioSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onAudioSetCutoffDistance=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.cd=J.cutoffDistance};_onAudioSetDetune=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.de=J.detune};_onAudioSetDistortion=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.di=J.distortion};_onAudioSetPosition=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.e=J.position?void 0:$.e,$.p=J.position?V1.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let $=this._createOrGetQueuedAudioSync(J.audio);$.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let $=J.blockType.serialize();this._queuedBlockTypeSynchronizations.set(J.blockType.id,$)};_onChatSendBroadcastMessage=(J)=>{let{player:$,message:X,color:Y}=J;this._queuedBroadcasts.push(_0.createPacket(_0.outboundPackets.chatMessagesPacketDefinition,[{m:X,c:Y,p:$?.id}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:$,message:X,color:Y}=J,Q=this._queuedPerPlayerSynchronizations.get($)??[];Q.push(_0.createPacket(_0.outboundPackets.chatMessagesPacketDefinition,[{m:X,c:Y}],this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set($,Q)};_onChunkLatticeAddChunk=(J)=>{let $=this._createOrGetQueuedChunkSync(J.chunk);$.b=Array.from(J.chunk.blocks),$.rm=void 0,this._spawnedChunks.add($.c.join(","))};_onChunkLatticeRemoveChunk=(J)=>{let $=this._createOrGetQueuedChunkSync(J.chunk),X=$.c.join(",");if(this._spawnedChunks.has(X))this._queuedChunkSynchronizations.delete(X),this._spawnedChunks.delete(X);else $.rm=!0};_onChunkLatticeSetBlock=(J)=>{let $=this._createOrGetQueuedBlockSync(J.globalCoordinate);$.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.ap=J.playbackRate};_onEntitySpawn=(J)=>{let $=J.entity.serialize();this._queuedEntitySynchronizations.set($.i,$),this._spawnedEntities.add($.i)};_onEntityDespawn=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has($.i))this._queuedEntitySynchronizations.delete($.i),this._spawnedEntities.delete($.i);else $.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.h=Array.from(J.modelHiddenNodes)};_onEntitySetModelScale=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.sv=J.modelScale?V1.serializeVector(J.modelScale):void 0};_onEntitySetModelShownNodes=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.sn=Array.from(J.modelShownNodes)};_onEntitySetModelTextureUri=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.mt=J.modelTextureUri};_onEntitySetOpacity=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.o=J.opacity};_onEntitySetParent=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.pe=J.parent?J.parent.id:void 0,$.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.t=J.tintColor?V1.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.al=Array.from(new Set([...$.al??[],...J.animations])),$.as)$.as=$.as.filter((X)=>!J.animations.has(X)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.ao=Array.from(new Set([...$.ao??[],...J.animations])),$.as)$.as=$.as.filter((X)=>!J.animations.has(X)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);if($.al)$.al=$.al.filter((X)=>!J.animations.has(X)).filter(Boolean);if($.ao)$.ao=$.ao.filter((X)=>!J.animations.has(X)).filter(Boolean);$.as=Array.from(new Set([...$.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let $=this._createOrGetQueuedEntitySync(J.entity);$.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.rm=!0};_onLightSetAngle=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onLightSetColor=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.c=V1.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.d=J.distance};_onLightSetIntensity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.n=J.intensity};_onLightSetOffset=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.pe=J.penumbra};_onLightSetPosition=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e};_onLightSetTrackedEntity=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.te=J.entity?J.entity.id:void 0,$.tp=J.entity?void 0:$.tp};_onLightSetTrackedPosition=(J)=>{let $=this._createOrGetQueuedLightSync(J.light);$.tp=J.position?V1.serializeVector(J.position):void 0,$.te=J.position?void 0:$.te};_onLightSpawn=(J)=>{let $=J.light.serialize();this._queuedLightSynchronizations.set($.i,$)};_onParticleEmitterBurst=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.b=J.count};_onParticleEmitterDespawn=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.rm=!0};_onParticleEmitterSetAlphaTest=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.at=J.alphaTest};_onParticleEmitterSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onParticleEmitterSetAttachedToEntityNodeName=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.en=J.attachedToEntityNodeName};_onParticleEmitterSetColorEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ce=J.colorEnd?V1.serializeRgbColor(J.colorEnd):void 0};_onParticleEmitterSetColorEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.cev=J.colorEndVariance?V1.serializeRgbColor(J.colorEndVariance):void 0};_onParticleEmitterSetColorStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.cs=J.colorStart?V1.serializeRgbColor(J.colorStart):void 0};_onParticleEmitterSetColorStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.csv=J.colorStartVariance?V1.serializeRgbColor(J.colorStartVariance):void 0};_onParticleEmitterSetGravity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.g=J.gravity?V1.serializeVector(J.gravity):void 0};_onParticleEmitterSetLifetime=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.l=J.lifetime};_onParticleEmitterSetLifetimeVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.lv=J.lifetimeVariance};_onParticleEmitterSetMaxParticles=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.mp=J.maxParticles};_onParticleEmitterSetOffset=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onParticleEmitterSetOpacityEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.oe=J.opacityEnd};_onParticleEmitterSetOpacityEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.oev=J.opacityEndVariance};_onParticleEmitterSetOpacityStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.os=J.opacityStart};_onParticleEmitterSetOpacityStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.osv=J.opacityStartVariance};_onParticleEmitterSetPaused=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.pa=J.paused};_onParticleEmitterSetPosition=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e,$.en=J.position?void 0:$.en};_onParticleEmitterSetPositionVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.pv=J.positionVariance?V1.serializeVector(J.positionVariance):void 0};_onParticleEmitterSetRate=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.r=J.rate};_onParticleEmitterSetRateVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.rv=J.rateVariance};_onParticleEmitterSetSizeEnd=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.se=J.sizeEnd};_onParticleEmitterSetSizeEndVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.sev=J.sizeEndVariance};_onParticleEmitterSetSizeStart=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ss=J.sizeStart};_onParticleEmitterSetSizeStartVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.ssv=J.sizeStartVariance};_onParticleEmitterSetTextureUri=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.tu=J.textureUri};_onParticleEmitterSetTransparent=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.t=J.transparent};_onParticleEmitterSetVelocity=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.v=J.velocity?V1.serializeVector(J.velocity):void 0};_onParticleEmitterSetVelocityVariance=(J)=>{let $=this._createOrGetQueuedParticleEmitterSync(J.particleEmitter);$.vv=J.velocityVariance?V1.serializeVector(J.velocityVariance):void 0};_onParticleEmitterSpawn=(J)=>{let $=J.particleEmitter.serialize();this._queuedParticleEmitterSynchronizations.set($.i,$)};_onPlayerCameraLookAtEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pl=V1.serializeVector(J.entity.position),delete $.et,delete $.pt};_onPlayerCameraLookAtPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pl=J.position?V1.serializeVector(J.position):void 0,delete $.et,delete $.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.e=J.entity.id,delete $.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.p=J.position?V1.serializeVector(J.position):void 0,delete $.e};_onPlayerCameraSetFilmOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetModelShownNodes=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.s=Array.from(J.modelShownNodes)};_onPlayerCameraSetMode=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onPlayerCameraSetShoulderAngle=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.sa=J.shoulderAngle};_onPlayerCameraSetTrackedEntity=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.et=J.entity?J.entity.id:void 0,delete $.pl,delete $.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.pt=J.position?V1.serializeVector(J.position):void 0,delete $.et,delete $.pl};_onPlayerCameraSetZoom=(J)=>{let $=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);$.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:$}=J,X=this._queuedPerPlayerSynchronizations.get($)??[];X.push(_0.createPacket(_0.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((Q)=>{if($.camera.attachedToEntity===void 0&&Q instanceof o$&&Q.player===$)$.camera.setAttachedToEntity(Q);return Q.serialize()}),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllAudios().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.particleEmittersPacketDefinition,this._world.particleEmitterManager.getAllParticleEmitters().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((Q)=>Q.serialize()),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),X.push(_0.createPacket(_0.outboundPackets.playersPacketDefinition,F$.instance.getConnectedPlayers().map((Q)=>Q.serialize()),this._world.loop.currentTick));let Y=this._createOrGetQueuedPlayerCameraSync($.camera);this._queuedPerPlayerCameraSynchronizations.set($,{...$.camera.serialize(),...Y}),this._queuedPerPlayerSynchronizations.set($,X),this._queuedPlayerSynchronizations.set($.id,$.serialize())};_onPlayerLeftWorld=(J)=>{let $=this._createOrGetQueuedPlayerSync(J.player);$.rm=!0};_onPlayerReconnectedWorld=(J)=>{this._onPlayerJoinedWorld(J)};_onPlayerRequestNotificationPermission=(J)=>{let{player:$}=J,X=this._queuedPerPlayerSynchronizations.get($)??[];X.push(_0.createPacket(_0.outboundPackets.notificationPermissionRequestPacketDefinition,null,this._world.loop.currentTick)),this._queuedPerPlayerSynchronizations.set($,X)};_onPlayerRequestSync=(J)=>{J.player.connection.send([_0.createPacket(_0.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 $=this._createOrGetQueuedPlayerUISync(J.playerUI);$.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let $=this._createOrGetQueuedPlayerUISync(J.playerUI);$.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let $=J.sceneUI.serialize();this._queuedSceneUISynchronizations.set($.i,$),this._loadedSceneUIs.add($.i)};_onSceneUISetAttachedToEntity=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.e=J.entity?J.entity.id:void 0,$.p=J.entity?void 0:$.p};_onSceneUISetOffset=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.o=J.offset?V1.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.p=J.position?V1.serializeVector(J.position):void 0,$.e=J.position?void 0:$.e};_onSceneUISetState=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.s=J.state};_onSceneUISetViewDistance=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);$.v=J.viewDistance};_onSceneUIUnload=(J)=>{let $=this._createOrGetQueuedSceneUISync(J.sceneUI);if(this._loadedSceneUIs.has($.i))this._queuedSceneUISynchronizations.delete($.i),this._loadedSceneUIs.delete($.i);else $.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(V1.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(_0.createPacket(_0.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ac=V1.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.dc=V1.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.dp=V1.serializeVector(J.position)};_onWorldSetFogColor=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.fc=V1.serializeRgbColor(J.color)};_onWorldSetFogFar=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.ff=J.far};_onWorldSetFogNear=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.fn=J.near};_onWorldSetSkyboxIntensity=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.si=J.intensity};_onWorldSetSkyboxUri=(J)=>{let $=this._createOrGetQueuedWorldSync(J.world);$.s=J.uri};_createOrGetQueuedAudioSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");let $=this._queuedAudioSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedAudioSynchronizations.set(J.id,$);return $}_createOrGetQueuedBlockSync(J){let{x:$,y:X,z:Y}=J,Q=`${$},${X},${Y}`,W=this._queuedBlockSynchronizations.get(Q);if(!W)W={i:0,c:[$,X,Y]},this._queuedBlockSynchronizations.set(Q,W);return W}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)n.fatalError("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:$,y:X,z:Y}=J.originCoordinate,Q=`${$},${X},${Y}`,W=this._queuedChunkSynchronizations.get(Q);if(!W)W={c:[$,X,Y]},this._queuedChunkSynchronizations.set(Q,W);return W}_createOrGetQueuedEntitySync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");let $=this._queuedEntitySynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedEntitySynchronizations.set(J.id,$);return $}_createOrGetQueuedLightSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");let $=this._queuedLightSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedLightSynchronizations.set(J.id,$);return $}_createOrGetQueuedParticleEmitterSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedParticleEmitterSync(): ParticleEmitter has no id!");let $=this._queuedParticleEmitterSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedParticleEmitterSynchronizations.set(J.id,$);return $}_createOrGetQueuedPlayerSync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedPlayerSync(): Player has no id!");let $=this._queuedPlayerSynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedPlayerSynchronizations.set(J.id,$);return $}_createOrGetQueuedPlayerCameraSync(J){let $=this._queuedPerPlayerCameraSynchronizations.get(J.player);if(!$)$={},this._queuedPerPlayerCameraSynchronizations.set(J.player,$);return $}_createOrGetQueuedPlayerUISync(J){let $=this._queuedPerPlayerUISynchronizations.get(J.player);if(!$)$={},this._queuedPerPlayerUISynchronizations.set(J.player,$);return $}_createOrGetQueuedPlayerUIDatasSync(J){let $=this._queuedPerPlayerUIDatasSynchronizations.get(J.player);if(!$)$=[],this._queuedPerPlayerUIDatasSynchronizations.set(J.player,$);return $}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)n.fatalError("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");let $=this._queuedSceneUISynchronizations.get(J.id);if(!$)$={i:J.id},this._queuedSceneUISynchronizations.set(J.id,$);return $}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)n.fatalError("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}_createOrGetSynchronizedPlayerReliablePackets(J,$){let X=this._synchronizedPlayerReliablePackets.get(J);if(!X)X=[...$],this._synchronizedPlayerReliablePackets.set(J,X);return X}}class XB{_particleEmitters=new Map;_nextParticleEmitterId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedParticleEmitters(J){this.getAllEntityAttachedParticleEmitters(J).forEach(($)=>{$.despawn()})}getAllParticleEmitters(){return Array.from(this._particleEmitters.values())}getAllEntityAttachedParticleEmitters(J){return this.getAllParticleEmitters().filter(($)=>$.attachedToEntity===J)}registerParticleEmitter(J){if(J.id!==void 0)return J.id;let $=this._nextParticleEmitterId;return this._particleEmitters.set($,J),this._nextParticleEmitterId++,$}unregisterParticleEmitter(J){if(J.id===void 0)return;this._particleEmitters.delete(J.id)}}class YB{_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(($)=>$.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let $=this._nextSceneUIId;return this._sceneUIs.set($,J),this._nextSceneUIId++,$}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach(($)=>{$.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}var AC6=2,cC6=3;class QB{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_maxAccumulatorMs;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,$,X){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._maxAccumulatorMs=this._fixedTimestepMs*cC6,this._tickFunction=$,this._tickErrorCallback=X}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get isStarted(){return!!this._tickHandle}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return;this._lastLoopTimeMs=performance.now();let J=()=>{let $=performance.now(),X=$-this._lastLoopTimeMs;if(this._lastLoopTimeMs=$,this._accumulatorMs+=X,this._accumulatorMs>this._maxAccumulatorMs)this._accumulatorMs=this._maxAccumulatorMs;if(this._accumulatorMs>=this._fixedTimestepMs)T6.startSpan({operation:"ticker_tick"},()=>{let Y=0;while(this._accumulatorMs>=this._fixedTimestepMs&&Y<AC6)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs,Y++});this._nextTickMs=Math.max(0,this._fixedTimestepMs-this._accumulatorMs),this._tickHandle=setTimeout(J,this._nextTickMs)};J()}stop(){if(!this._tickHandle)return;clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch($){if($ instanceof Error&&this._tickErrorCallback)this._tickErrorCallback($);else n.warning(`Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error: ${$}`)}}}var JO1;((W)=>{W.START="WORLD_LOOP.START";W.STOP="WORLD_LOOP.STOP";W.TICK_START="WORLD_LOOP.TICK_START";W.TICK_END="WORLD_LOOP.TICK_END";W.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(JO1||={});class WB extends $1{_currentTick=0;_ticker;_world;constructor(J,$=ei){super();this._ticker=new QB($,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get isStarted(){return this._ticker.isStarted}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 $=performance.now();T6.startSpan({operation:"world_tick",attributes:{serverPlayerCount:F$.instance.playerCount,targetTickRate:this._ticker.targetTicksPerSecond,targetTickRateMs:this._ticker.fixedTimestepMs,worldId:this._world.id,worldName:this._world.name,worldChunkCount:this._world.chunkLattice.chunkCount,worldEntityCount:this._world.entityManager.entityCount,worldLoopTick:this._currentTick}},()=>{T6.startSpan({operation:"entities_tick"},()=>this._world.entityManager.tickEntities(J)),T6.startSpan({operation:"simulation_step"},()=>this._world.simulation.step(J)),T6.startSpan({operation:"entities_emit_updates"},()=>this._world.entityManager.checkAndEmitUpdates()),T6.startSpan({operation:"network_synchronize"},()=>this._world.networkSynchronizer.synchronize())}),this._currentTick++,this.emitWithWorld(this._world,"WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-$})};_onTickError=(J)=>{n.error(`WorldLoop._onTickError(): Error: ${J}`),this.emitWithWorld(this._world,"WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}var $n;((H)=>{H.SET_AMBIENT_LIGHT_COLOR="WORLD.SET_AMBIENT_LIGHT_COLOR";H.SET_AMBIENT_LIGHT_INTENSITY="WORLD.SET_AMBIENT_LIGHT_INTENSITY";H.SET_DIRECTIONAL_LIGHT_COLOR="WORLD.SET_DIRECTIONAL_LIGHT_COLOR";H.SET_DIRECTIONAL_LIGHT_INTENSITY="WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY";H.SET_DIRECTIONAL_LIGHT_POSITION="WORLD.SET_DIRECTIONAL_LIGHT_POSITION";H.SET_FOG_COLOR="WORLD.SET_FOG_COLOR";H.SET_FOG_FAR="WORLD.SET_FOG_FAR";H.SET_FOG_NEAR="WORLD.SET_FOG_NEAR";H.SET_SKYBOX_INTENSITY="WORLD.SET_SKYBOX_INTENSITY";H.SET_SKYBOX_URI="WORLD.SET_SKYBOX_URI";H.START="WORLD.START";H.STOP="WORLD.STOP"})($n||={});class KB extends $1{_id;_ambientLightColor;_ambientLightIntensity;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_entityManager;_fogColor;_fogFar;_fogNear;_lightManager;_loop;_name;_networkSynchronizer;_particleEmitterManager;_sceneUIManager;_simulation;_skyboxIntensity;_skyboxUri;_tag;constructor(J){super();if(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._fogColor=J.fogColor,this._fogFar=J.fogFar??550,this._fogNear=J.fogNear??500,this._name=J.name,this._skyboxIntensity=J.skyboxIntensity??1,this._skyboxUri=J.skyboxUri,this._tag=J.tag,this._audioManager=new vz(this),this._blockTypeRegistry=new EF(this),this._chatManager=new FU(this),this._chunkLattice=new UU(this),this._entityManager=new LU(this),this._lightManager=new JB(this),this._loop=new WB(this,J.tickRate),this._networkSynchronizer=new AC(this),this._particleEmitterManager=new XB(this),this._sceneUIManager=new YB(this),this._simulation=new $B(this,J.tickRate,J.gravity),J.map)this.loadMap(J.map)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get entityManager(){return this._entityManager}get fogColor(){return this._fogColor}get fogFar(){return this._fogFar}get fogNear(){return this._fogNear}get lightManager(){return this._lightManager}get loop(){return this._loop}get name(){return this._name}get networkSynchronizer(){return this._networkSynchronizer}get particleEmitterManager(){return this._particleEmitterManager}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}get skyboxIntensity(){return this._skyboxIntensity}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get tag(){return this._tag}loadMap(J){if(this.chunkLattice.clear(),J.blockTypes)for(let $ of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:$.id,isLiquid:$.isLiquid,lightLevel:$.lightLevel,name:$.name,textureUri:$.textureUri});if(J.blocks){let $={};for(let X in J.blocks){let Y=J.blocks[X],Q=X.indexOf(","),W=X.indexOf(",",Q+1),K=Number(X.slice(0,Q)),Z=Number(X.slice(Q+1,W)),G=Number(X.slice(W+1));if(!$[Y])$[Y]=[];$[Y].push({x:K,y:Z,z:G})}this.chunkLattice.initializeBlocks($)}if(J.entities)for(let $ in J.entities){let X=J.entities[$],Y=$.indexOf(","),Q=$.indexOf(",",Y+1),W=Number($.slice(0,Y)),K=Number($.slice(Y+1,Q)),Z=Number($.slice(Q+1));new b6({isEnvironmental:!0,...X}).spawn(this,{x:W,y:K,z: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})}setFogColor(J){this._fogColor=J,this.emit("WORLD.SET_FOG_COLOR",{world:this,color:J})}setFogFar(J){this._fogFar=J,this.emit("WORLD.SET_FOG_FAR",{world:this,far:J})}setFogNear(J){this._fogNear=J,this.emit("WORLD.SET_FOG_NEAR",{world:this,near:J})}setSkyboxIntensity(J){this._skyboxIntensity=J,this.emit("WORLD.SET_SKYBOX_INTENSITY",{world:this,intensity:J})}setSkyboxUri(J){this._skyboxUri=J,this.emit("WORLD.SET_SKYBOX_URI",{world:this,uri:J})}start(){if(this._loop.isStarted)return;this._loop.start(),this.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){if(!this._loop.isStarted)return;this._loop.stop(),this.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return V1.serializeWorld(this)}}var $O1;(($)=>$.WORLD_CREATED="WORLD_MANAGER.WORLD_CREATED")($O1||={});class bK{static instance=new bK;_defaultWorld;_nextWorldId=1;_worlds=new Map;createWorld(J){let $=new KB({...J,id:this._nextWorldId++});return $.start(),this._worlds.set($.id,$),$1.globalInstance.emit("WORLD_MANAGER.WORLD_CREATED",{world:$}),$}getAllWorlds(){return Array.from(this._worlds.values())}getDefaultWorld(){return this._defaultWorld??=this.createWorld({name:"Default World",skyboxUri:"skyboxes/partly-cloudy"}),this._defaultWorld}getWorldsByTag(J){let $=[];return this._worlds.forEach((X)=>{if(X.tag===J)$.push(X)}),$}getWorld(J){return this._worlds.get(J)}setDefaultWorld(J){this._defaultWorld=J}}var XO1;((Y)=>{Y.PLAYER_CONNECTED="PLAYER_MANAGER.PLAYER_CONNECTED";Y.PLAYER_DISCONNECTED="PLAYER_MANAGER.PLAYER_DISCONNECTED";Y.PLAYER_RECONNECTED="PLAYER_MANAGER.PLAYER_RECONNECTED"})(XO1||={});class F${static instance=new F$;worldSelectionHandler;_connectionPlayers=new Map;constructor(){$1.globalInstance.on("CONNECTION.OPENED",({connection:J,session:$})=>{this._onConnectionOpened(J,$)}),$1.globalInstance.on("CONNECTION.DISCONNECTED",({connection:J})=>{this._onConnectionDisconnected(J)}),$1.globalInstance.on("CONNECTION.RECONNECTED",({connection:J})=>{this._onConnectionReconnected(J)}),$1.globalInstance.on("CONNECTION.CLOSED",({connection:J})=>{this._onConnectionClosed(J)})}get playerCount(){return this._connectionPlayers.size}getConnectedPlayers(){return Array.from(this._connectionPlayers.values())}getConnectedPlayersByWorld(J){return this.getConnectedPlayers().filter(($)=>$.world===J)}getConnectedPlayerByUsername(J){return Array.from(this._connectionPlayers.values()).find(($)=>{return $.username.toLowerCase()===J.toLowerCase()})}async _onConnectionOpened(J,$){let X=new kq(J,$);await X.loadInitialPersistedData(),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_CONNECTED",{player:X});let Y=await this.worldSelectionHandler?.(X);X.joinWorld(Y??bK.instance.getDefaultWorld()),this._connectionPlayers.set(J,X)}_onConnectionDisconnected(J){let $=this._connectionPlayers.get(J);if($)$.resetInputs(),$.camera.reset()}_onConnectionReconnected(J){let $=this._connectionPlayers.get(J);if($)$.reconnected(),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_RECONNECTED",{player:$});else n.warning(`PlayerManager._onConnectionReconnected(): Connection ${J.id} not in the PlayerManager._connectionPlayers map.`)}_onConnectionClosed(J){let $=this._connectionPlayers.get(J);if($)$.disconnect(),this._connectionPlayers.delete(J),CW.instance.unloadPlayerData($).catch((X)=>{n.warning(`PlayerManager._onConnectionClosed(): Failed to unload player data for player ${$.id}. Error: ${X}`)}),$1.globalInstance.emit("PLAYER_MANAGER.PLAYER_DISCONNECTED",{player:$});else n.warning(`PlayerManager._onConnectionClosed(): Connection ${J.id} not in the PlayerManager._connectionPlayers map.`)}}import{randomBytes as hC6}from"crypto";import{Http3Server as fC6}from"@fails-components/webtransport";class ZB extends $1{static instance=new ZB;_connectionIdConnections=new Map;_userIdConnections=new Map;_wss;_wts;constructor(){super();this._wss=new Ch.default({noServer:!0}),this._wss.on("connection",(J,$)=>this._onConnection(J,void 0,$.connectionId,$.session)),this._wts=new fC6({port:SC,host:"0.0.0.0",secret:hC6(32).toString("hex"),cert:kC,privKey:EC,defaultDatagramsReadableMode:"bytes",initialStreamFlowControlWindow:1048576,streamShouldAutoTuneReceiveWindow:!0,streamFlowControlWindowSizeLimit:6291456,initialSessionFlowControlWindow:2097152,sessionShouldAutoTuneReceiveWindow:!0,sessionFlowControlWindowSizeLimit:15728640}),this._wts.setRequestCallback(this._onWebTransportRequest),this._startWebTransport().catch((J)=>{n.error(`Socket: WebTransport server failed to start or crashed while listening for sessions. Error: ${J}`)}),$1.globalInstance.on("WEBSERVER.UPGRADE",async({req:J,socket:$,head:X})=>{await this._authorizeAndConnectWebsocket(J,$,X)})}async _authorizeAndConnectWebsocket(J,$,X){let Y=await this._authorizeConnection(J.url??"");if(Y.error){$.end();return}J.connectionId=Y.connectionId,J.session=Y.session,$.setNoDelay(!0),this._wss.handleUpgrade(J,$,X,(Q)=>{if(Q.readyState!==Cq.default.OPEN)Q.once("open",()=>this._wss.emit("connection",Q,J));else this._wss.emit("connection",Q,J)})}async _authorizeConnection(J){let $=J.includes("?")?J.slice(J.indexOf("?")):"",X=new URLSearchParams($),Y=X.get("connectionId")??void 0,Q=X.get("sessionToken")??"";if(Y&&this._isValidConnectionId(Y))return{connectionId:Y};else{let W=await k7.instance.getPlayerSession(Q);if(W?.error)return{error:W.error};else if(W)return{session:W}}return{}}_isValidConnectionId(J){return this._connectionIdConnections.has(J)}_onConnection=(J,$,X,Y)=>{let Q=Y?.user.id,W=(X&&this._connectionIdConnections.get(X))??(Q&&this._userIdConnections.get(Q));if(W){if(J)W.bindWs(J);if($)W.bindWt($).catch((K)=>{n.error(`Socket._onConnection(): WebTransport binding failed. Error: ${K}`)})}else{let K=new v$(J,$,Y);if(K.on("CONNECTION.CLOSED",()=>{if(this._connectionIdConnections.delete(K.id),Q)this._userIdConnections.delete(Q)}),this._connectionIdConnections.set(K.id,K),Q)this._userIdConnections.set(Q,K)}};_onWebTransportRequest=async({header:J})=>{let{connectionId:$,session:X,error:Y}=await this._authorizeConnection(J[":path"]??"");return{status:Y?401:200,path:"/",userData:{connectionId:$,session:X}}};async _startWebTransport(){this._wts.startServer();for await(let J of this._wts.sessionStream("/"))try{let{connectionId:$,session:X}=J.userData;this._onConnection(void 0,J,$,X)}catch($){n.error(`Socket._startWebTransport(): WebTransport connection failed. Error: ${$}`)}}}Buffer.poolSize=134217728;var YO1;((X)=>{X.START="GAMESERVER.START";X.STOP="GAMESERVER.STOP"})(YO1||={});function bC6(J){W8.init().then(()=>{return yK.instance.blockTextureRegistry.preloadAtlas()}).then(()=>{return yK.instance.modelRegistry.preloadModels()}).then(()=>{if(J.length>0)J(yK.instance.worldManager.getDefaultWorld());else J();yK.instance.start()}).catch(($)=>{n.fatalError(`Failed to initialize the game engine, exiting. Error: ${$}`)})}class yK{static _instance;_blockTextureRegistry=eQ.instance;_modelRegistry=k5.instance;_playerManager=F$.instance;_socket=ZB.instance;_worldManager=bK.instance;_webServer=Qz.instance;constructor(){}static get instance(){if(!this._instance)this._instance=new yK;return this._instance}get blockTextureRegistry(){return this._blockTextureRegistry}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worldManager(){return this._worldManager}start(){if($1.globalInstance.emit("GAMESERVER.START",{startedAtMs:performance.now()}),this._webServer.start(),process.env.NODE_ENV!=="production")console.log("---"),console.log("\uD83D\uDFE2 Server Running: You can test & play it at: https://hytopia.com/play")}}var L5=M0(M3(),1);class N3 extends Float32Array{constructor(J,$,X,Y){super([J,$,X,Y])}get determinant(){return L5.mat2.determinant(this)}get frobeniusNorm(){return L5.mat2.frob(this)}static create(){let J=new N3(0,0,0,0);return L5.mat2.identity(J),J}static fromRotation(J){let $=N3.create();return L5.mat2.fromRotation($,J),$}static fromScaling(J){let $=N3.create();return L5.mat2.fromScaling($,J),$}add(J){return L5.mat2.add(this,this,J),this}adjoint(){return L5.mat2.adjoint(this,this),this}clone(){return new N3(this[0],this[1],this[2],this[3])}copy(J){return L5.mat2.copy(this,J),this}equals(J){return L5.mat2.equals(this,J)}exactEquals(J){return L5.mat2.exactEquals(this,J)}identity(){return L5.mat2.identity(this),this}invert(){return L5.mat2.invert(this,this),this}multiply(J){return L5.mat2.mul(this,this,J),this}multiplyScalar(J){return L5.mat2.multiplyScalar(this,this,J),this}rotate(J){return L5.mat2.rotate(this,this,J),this}subtract(J){return L5.mat2.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return L5.mat2.transpose(this,this),this}}var k6=M0(M3(),1);class xX extends Float32Array{constructor(J,$,X,Y,Q,W,K,Z,G){super([J,$,X,Y,Q,W,K,Z,G])}get determinant(){return k6.mat3.determinant(this)}get frobeniusNorm(){return k6.mat3.frob(this)}static create(){let J=new xX(0,0,0,0,0,0,0,0,0);return k6.mat3.identity(J),J}static fromMatrix4(J){let $=xX.create();return k6.mat3.fromMat4($,J),$}static fromQuaternion(J){let $=xX.create();return k6.mat3.fromQuat($,J),$}static fromRotation(J){let $=xX.create();return k6.mat3.fromRotation($,J),$}static fromScaling(J){let $=xX.create();return k6.mat3.fromScaling($,J),$}static fromTranslation(J){let $=xX.create();return k6.mat3.fromTranslation($,J),$}add(J){return k6.mat3.add(this,this,J),this}adjoint(){return k6.mat3.adjoint(this,this),this}clone(){return new xX(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return k6.mat3.copy(this,J),this}equals(J){return k6.mat3.equals(this,J)}exactEquals(J){return k6.mat3.exactEquals(this,J)}identity(){return k6.mat3.identity(this),this}invert(){return k6.mat3.invert(this,this),this}multiply(J){return k6.mat3.mul(this,this,J),this}multiplyScalar(J){return k6.mat3.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,$){return k6.mat3.projection(this,J,$),this}rotate(J){return k6.mat3.rotate(this,this,J),this}subtract(J){return k6.mat3.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 k6.mat3.transpose(this,this),this}}var $8=M0(M3(),1);class u4 extends Float32Array{constructor(J,$,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U){super([J,$,X,Y,Q,W,K,Z,G,V,q,z,H,v,F,U])}get determinant(){return $8.mat4.determinant(this)}get frobeniusNorm(){return $8.mat4.frob(this)}static create(){let J=new u4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return $8.mat4.identity(J),J}static fromQuaternion(J){let $=u4.create();return $8.mat4.fromQuat($,J),$}static fromRotation(J,$){let X=u4.create();return $8.mat4.fromRotation(X,J,$),X}static fromRotationTranslation(J,$){let X=u4.create();return $8.mat4.fromRotationTranslation(X,J,$),X}static fromRotationTranslationScale(J,$,X){let Y=u4.create();return $8.mat4.fromRotationTranslationScale(Y,J,$,X),Y}static fromRotationTranslationScaleOrigin(J,$,X,Y){let Q=u4.create();return $8.mat4.fromRotationTranslationScaleOrigin(Q,J,$,X,Y),Q}static fromScaling(J){let $=u4.create();return $8.mat4.fromScaling($,J),$}static fromTranslation(J){let $=u4.create();return $8.mat4.fromTranslation($,J),$}static fromXRotation(J){let $=u4.create();return $8.mat4.fromXRotation($,J),$}static fromYRotation(J){let $=u4.create();return $8.mat4.fromYRotation($,J),$}static fromZRotation(J){let $=u4.create();return $8.mat4.fromZRotation($,J),$}add(J){return $8.mat4.add(this,this,J),this}adjoint(){return $8.mat4.adjoint(this,this),this}clone(){return new u4(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 $8.mat4.copy(this,J),this}equals(J){return $8.mat4.equals(this,J)}exactEquals(J){return $8.mat4.exactEquals(this,J)}frustrum(J,$,X,Y,Q,W){return $8.mat4.frustum(this,J,$,X,Y,Q,W),this}identity(){return $8.mat4.identity(this),this}invert(){return $8.mat4.invert(this,this),this}lookAt(J,$,X){return $8.mat4.lookAt(this,J,$,X),this}multiply(J){return $8.mat4.mul(this,this,J),this}multiplyScalar(J){return $8.mat4.multiplyScalar(this,this,J),this}orthographic(J,$,X,Y,Q,W){return $8.mat4.ortho(this,J,$,X,Y,Q,W),this}perspective(J,$,X,Y){return $8.mat4.perspective(this,J,$,X,Y),this}rotate(J,$){return $8.mat4.rotate(this,this,J,$),this}rotateX(J){return $8.mat4.rotateX(this,this,J),this}rotateY(J){return $8.mat4.rotateY(this,this,J),this}rotateZ(J){return $8.mat4.rotateZ(this,this,J),this}scale(J){return $8.mat4.scale(this,this,J),this}subtract(J){return $8.mat4.sub(this,this,J),this}targetTo(J,$,X){return $8.mat4.targetTo(this,J,$,X),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 $8.mat4.translate(this,this,J),this}transpose(){return $8.mat4.transpose(this,this),this}}var b8=M0(M3(),1);class Wz extends Float32Array{constructor(J,$,X,Y){super([J,$,X,Y])}get length(){return b8.quat.length(this)}get squaredLength(){return b8.quat.squaredLength(this)}get magnitude(){return b8.quat.length(this)}get squaredMagnitude(){return b8.quat.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){let Y=b8.quat.fromEuler(new Float32Array(4),J,$,X);return new Wz(Y[0],Y[1],Y[2],Y[3])}static fromQuaternionLike(J){return new Wz(J.x,J.y,J.z,J.w)}clone(){return new Wz(this.x,this.y,this.z,this.w)}conjugate(){return b8.quat.conjugate(this,this),this}copy(J){return b8.quat.copy(this,J),this}dot(J){return b8.quat.dot(this,J)}exponential(){return b8.quat.exp(this,this),this}equals(J){return b8.quat.equals(this,J)}exactEquals(J){return b8.quat.exactEquals(this,J)}getAngle(J){return b8.quat.getAngle(this,J)}identity(){return b8.quat.identity(this),this}invert(){return b8.quat.invert(this,this),this}lerp(J,$){return b8.quat.lerp(this,this,J,$),this}logarithm(){return b8.quat.ln(this,this),this}multiply(J){return b8.quat.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return b8.quat.normalize(this,this),this}power(J){return b8.quat.pow(this,this,J),this}randomize(){return b8.quat.random(this),this}rotateX(J){return b8.quat.rotateX(this,this,J),this}rotateY(J){return b8.quat.rotateY(this,this,J),this}rotateZ(J){return b8.quat.rotateZ(this,this,J),this}scale(J){return b8.quat.scale(this,this,J),this}setAxisAngle(J,$){return b8.quat.setAxisAngle(this,J,$),this}slerp(J,$){return b8.quat.slerp(this,this,J,$),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}var w8=M0(M3(),1);class GB extends Float32Array{constructor(J,$){super([J,$])}get length(){return w8.vec2.length(this)}get squaredLength(){return w8.vec2.squaredLength(this)}get magnitude(){return w8.vec2.length(this)}get squaredMagnitude(){return w8.vec2.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 GB(0,0)}add(J){return w8.vec2.add(this,this,J),this}angle(J){return w8.vec2.angle(this,J)}ceil(){return w8.vec2.ceil(this,this),this}clone(){return new GB(this.x,this.y)}copy(J){return w8.vec2.copy(this,J),this}distance(J){return w8.vec2.distance(this,J)}divide(J){return w8.vec2.divide(this,this,J),this}dot(J){return w8.vec2.dot(this,J)}equals(J){return w8.vec2.equals(this,J)}exactEquals(J){return w8.vec2.exactEquals(this,J)}floor(){return w8.vec2.floor(this,this),this}invert(){return w8.vec2.inverse(this,this),this}lerp(J,$){return w8.vec2.lerp(this,this,J,$),this}max(J){return w8.vec2.max(this,this,J),this}min(J){return w8.vec2.min(this,this,J),this}multiply(J){return w8.vec2.mul(this,this,J),this}negate(){return w8.vec2.negate(this,this),this}normalize(){return w8.vec2.normalize(this,this),this}randomize(J){return w8.vec2.random(this,J),this}rotate(J,$){return w8.vec2.rotate(this,this,J,$),this}round(){return w8.vec2.round(this,this),this}scale(J){return w8.vec2.scale(this,this,J),this}scaleAndAdd(J,$){return w8.vec2.scaleAndAdd(this,this,J,$),this}subtract(J){return w8.vec2.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return w8.vec2.transformMat2(this,this,J),this}transformMatrix3(J){return w8.vec2.transformMat3(this,this,J),this}transformMatrix4(J){return w8.vec2.transformMat4(this,this,J),this}zero(){return w8.vec2.zero(this),this}}var z8=M0(M3(),1);class Kz extends Float32Array{constructor(J,$,X){super([J,$,X])}get length(){return z8.vec3.length(this)}get squaredLength(){return z8.vec3.squaredLength(this)}get magnitude(){return z8.vec3.length(this)}get squaredMagnitude(){return z8.vec3.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 Kz(0,0,0)}static fromVector3Like(J){return new Kz(J.x,J.y,J.z)}add(J){return z8.vec3.add(this,this,J),this}ceil(){return z8.vec3.ceil(this,this),this}clone(){return new Kz(this.x,this.y,this.z)}copy(J){return z8.vec3.copy(this,J),this}cross(J){return z8.vec3.cross(this,this,J),this}distance(J){return z8.vec3.distance(this,J)}divide(J){return z8.vec3.div(this,this,J),this}dot(J){return z8.vec3.dot(this,J)}equals(J){return z8.vec3.equals(this,J)}exactEquals(J){return z8.vec3.exactEquals(this,J)}floor(){return z8.vec3.floor(this,this),this}invert(){return z8.vec3.inverse(this,this),this}lerp(J,$){return z8.vec3.lerp(this,this,J,$),this}max(J){return z8.vec3.max(this,this,J),this}min(J){return z8.vec3.min(this,this,J),this}multiply(J){return z8.vec3.mul(this,this,J),this}negate(){return z8.vec3.negate(this,this),this}normalize(){return z8.vec3.normalize(this,this),this}randomize(J){return z8.vec3.random(this,J),this}rotateX(J,$){return z8.vec3.rotateX(this,this,J,$),this}rotateY(J,$){return z8.vec3.rotateY(this,this,J,$),this}rotateZ(J,$){return z8.vec3.rotateZ(this,this,J,$),this}round(){return z8.vec3.round(this,this),this}scale(J){return z8.vec3.scale(this,this,J),this}scaleAndAdd(J,$){return z8.vec3.scaleAndAdd(this,this,J,$),this}subtract(J){return z8.vec3.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return z8.vec3.transformMat3(this,this,J),this}transformMatrix4(J){return z8.vec3.transformMat4(this,this,J),this}transformQuaternion(J){return z8.vec3.transformQuat(this,this,J),this}zero(){return z8.vec3.zero(this),this}}var dR1=M0(gR1(),1);var pR1=0.099856;class VB extends iK{faceSpeed=0;idleLoopedAnimations=[];idleLoopedAnimationsSpeed;jumpOneshotAnimations=[];moveLoopedAnimations=[];moveLoopedAnimationsSpeed;moveSpeed=0;_faceTarget;_jumpHeight=0;_moveCompletesWhenStuck=!1;_moveIgnoreAxes={};_moveStartMoveAnimations=!1;_moveStartIdleAnimationsOnCompletion=!0;_moveStoppingDistanceSquared=pR1;_moveStuckAccumulatorMs=0;_moveStuckLastPosition;_moveTarget;_onFace;_onFaceComplete;_onMove;_onMoveComplete;_stopFaceRequested=!1;_stopMoveRequested=!1;constructor(J={}){super();this.idleLoopedAnimations=J.idleLoopedAnimations??this.idleLoopedAnimations,this.idleLoopedAnimationsSpeed=J.idleLoopedAnimationsSpeed??this.idleLoopedAnimationsSpeed,this.jumpOneshotAnimations=J.jumpOneshotAnimations??this.jumpOneshotAnimations,this.moveLoopedAnimations=J.moveLoopedAnimations??this.moveLoopedAnimations,this.moveLoopedAnimationsSpeed=J.moveLoopedAnimationsSpeed??this.moveLoopedAnimationsSpeed}spawn(J){super.spawn(J),this._startIdleAnimations(J)}face(J,$,X){this._faceTarget=J,this.faceSpeed=$,this._onFace=X?.faceCallback,this._onFaceComplete=X?.faceCompleteCallback}jump(J){this._jumpHeight=J}move(J,$,X){this.moveSpeed=$,this._moveCompletesWhenStuck=X?.moveCompletesWhenStuck??!1,this._moveIgnoreAxes=X?.moveIgnoreAxes??{},this._moveStartIdleAnimationsOnCompletion=X?.moveStartIdleAnimationsOnCompletion??!0,this._moveStartMoveAnimations=!0,this._moveStoppingDistanceSquared=X?.moveStoppingDistance?X.moveStoppingDistance**2:pR1,this._moveTarget=J,this._onMove=X?.moveCallback,this._onMoveComplete=X?.moveCompleteCallback,this._moveStuckAccumulatorMs=0,this._moveStuckLastPosition=void 0}stopFace(){this._stopFaceRequested=!0}stopMove(){this._stopMoveRequested=!0}tick(J,$){if(super.tick(J,$),!this._moveTarget&&!this._faceTarget&&!this._jumpHeight)return;if(this._moveStartMoveAnimations)this._startMoveAnimations(J),this._moveStartMoveAnimations=!1;let X=$/1000,Y=J.position;if(J.isDynamic&&this._jumpHeight>0){let Q=Math.abs(J.world.simulation.gravity.y),W=Math.sqrt(2*Q*this._jumpHeight);J.applyImpulse({x:0,y:W*J.mass,z:0}),this._jumpHeight=0,this._startJumpAnimations(J)}if(this._moveTarget){let Q={x:this._moveIgnoreAxes.x?0:this._moveTarget.x-Y.x,y:this._moveIgnoreAxes.y?0:this._moveTarget.y-Y.y,z:this._moveIgnoreAxes.z?0:this._moveTarget.z-Y.z},W=Q.x*Q.x+Q.y*Q.y+Q.z*Q.z,K=!1;if(this._moveCompletesWhenStuck){if(this._moveStuckAccumulatorMs+=$,this._moveStuckAccumulatorMs>=500){if(this._moveStuckLastPosition){let Z=Y.x-this._moveStuckLastPosition.x,G=Y.y-this._moveStuckLastPosition.y,V=Y.z-this._moveStuckLastPosition.z;K=Math.sqrt(Z*Z+G*G+V*V)<this.moveSpeed*0.1}this._moveStuckLastPosition=Y,this._moveStuckAccumulatorMs=0}}if(W>this._moveStoppingDistanceSquared&&!this._stopMoveRequested&&!K){let Z=Math.sqrt(W),G=this.moveSpeed*X,q=Math.min(Z,G)/Z,z={x:Y.x+Q.x*q,y:Y.y+Q.y*q,z:Y.z+Q.z*q};if(J.setPosition(z),this._onMove)this._onMove(z,this._moveTarget)}else{if(this._moveStuckAccumulatorMs=0,this._moveStuckLastPosition=void 0,this._moveTarget=void 0,this._stopMoveRequested=!1,this._moveStartIdleAnimationsOnCompletion)this._startIdleAnimations(J);if(this._onMoveComplete){let Z=this._onMoveComplete;this._onMove=void 0,this._onMoveComplete=void 0,Z(Y)}}}if(this._faceTarget){let Q={x:this._faceTarget.x-Y.x,z:this._faceTarget.z-Y.z},W=Math.atan2(-Q.x,-Q.z),K=J.rotation,Z=Math.atan2(2*(K.w*K.y),1-2*(K.y*K.y)),G=W-Z;while(G>Math.PI)G-=2*Math.PI;while(G<-Math.PI)G+=2*Math.PI;if(Math.abs(G)>0.01&&!this._stopFaceRequested){let V=this.faceSpeed*X,q=Math.abs(G)<V?G:Math.sign(G)*V,H=(Z+q)/2,v={x:0,y:Math.fround(Math.sin(H)),z:0,w:Math.fround(Math.cos(H))};if(J.setRotation(v),this._onFace)this._onFace(K,v)}else if(this._faceTarget=void 0,this._stopFaceRequested=!1,this._onFaceComplete){let V=this._onFaceComplete;this._onFace=void 0,this._onFaceComplete=void 0,V(J.rotation)}}}_startIdleAnimations(J){if(this.idleLoopedAnimationsSpeed)J.setModelAnimationsPlaybackRate(this.idleLoopedAnimationsSpeed);J.stopModelAnimations(this.moveLoopedAnimations),J.stopModelAnimations(this.jumpOneshotAnimations),J.startModelLoopedAnimations(this.idleLoopedAnimations)}_startJumpAnimations(J){J.stopModelAnimations(this.moveLoopedAnimations),J.stopModelAnimations(this.idleLoopedAnimations),J.startModelOneshotAnimations(this.jumpOneshotAnimations)}_startMoveAnimations(J){if(this.moveLoopedAnimationsSpeed)J.setModelAnimationsPlaybackRate(this.moveLoopedAnimationsSpeed);J.stopModelAnimations(this.jumpOneshotAnimations),J.stopModelAnimations(this.idleLoopedAnimations),J.startModelLoopedAnimations(this.moveLoopedAnimations)}}class qn extends VB{_debug=!1;_entity;_maxFall=0;_maxJump=0;_maxOpenSetIterations=200;_onPathfindAbort;_onPathfindComplete;_onWaypointMoveComplete;_onWaypointMoveSkipped;_speed=0;_target;_verticalPenalty=0;_waypoints=[];_waypointNextIndex=0;_waypointStoppingDistance;_waypointTimeoutMs=2000;constructor(J={}){super(J)}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){if(this._target=J,this._speed=$,this._debug=X?.debug??!1,this._maxFall=X?.maxFall?-Math.abs(X.maxFall):0,this._maxJump=X?.maxJump?Math.abs(X.maxJump):0,this._maxOpenSetIterations=X?.maxOpenSetIterations??200,this._onPathfindAbort=X?.pathfindAbortCallback,this._onPathfindComplete=X?.pathfindCompleteCallback,this._onWaypointMoveComplete=X?.waypointMoveCompleteCallback,this._onWaypointMoveSkipped=X?.waypointMoveSkippedCallback,this._verticalPenalty=X?.verticalPenalty??0,this._waypoints=[],this._waypointNextIndex=0,this._waypointStoppingDistance=X?.waypointStoppingDistance,this._waypointTimeoutMs=X?.waypointTimeoutMs??2000/$,!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}_calculatePath(){if(!this._target||!this._entity?.world)return n.error("PathfindingEntityController._calculatePath: No target or world"),!1;let J=this._entity.height,$=this._findGroundedStart();if(!$){if(this._debug)n.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 X={x:Math.floor(this._target.x),y:Math.floor(this._target.y),z:Math.floor(this._target.z)},Y=Math.abs(X.x-$.x),Q=Math.abs(X.y-$.y),W=Math.abs(X.z-$.z);if(Y<=2&&Q<=2&&W<=2&&!this._isNeighborCoordinateBlocked($,X,this._entity.height))return this._waypoints=[{x:$.x+0.5,y:$.y+J/2,z:$.z+0.5},{x:X.x+0.5,y:X.y+J/2,z:X.z+0.5}],!0;if($.x===X.x&&$.y===X.y&&$.z===X.z)return this._waypoints=[{x:$.x+0.5,y:$.y+J/2,z:$.z+0.5}],!0;let Z=this._coordinateToKey($),G=new Map,V=new Map([[Z,0]]),q=new Map([[Z,this._pathfindingHeuristic($,X)]]),z=new Set,H=new dR1.Heap((M,R)=>{let N=q.get(M[0])??1/0,L=q.get(R[0])??1/0;return N-L});H.push([Z,$]);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}],F=[];for(let M=this._maxJump;M>=this._maxFall;M--){if(M===0)continue;let R=Math.abs($.y+M-X.y);F.push({y:M,distanceToTargetY:R})}F.sort((M,R)=>M.distanceToTargetY-R.distanceToTargetY);let U=[...v,...F.flatMap(({y:M})=>v.map((R)=>({...R,y:M})))],j=0,B=Math.abs(X.x-$.x)+Math.abs(X.y-$.y)+Math.abs(X.z-$.z),w=Math.min(this._maxOpenSetIterations,B*20);while(!H.isEmpty()&&j<w){j++;let[M,R]=H.pop();if(R.x===X.x&&R.y===X.y&&R.z===X.z){let O=this._reconstructPath(G,R);if(this._waypoints=O.map((x)=>({x:x.x+0.5,y:x.y+J/2,z:x.z+0.5})),this._debug)console.log(`PathfindingEntityController._calculatePath: Path found after ${j} open set iterations. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`);return!0}z.add(M);let N=V.get(M),L=new Map;for(let O of U){let x=`${O.x},${O.z}`,T=O.y<0;if(T&&L.has(x))continue;let S={x:R.x+O.x,y:R.y+O.y,z:R.z+O.z};if(Math.abs(X.x-S.x)+Math.abs(X.y-S.y)+Math.abs(X.z-S.z)>B*1.5)continue;let I=this._coordinateToKey(S);if(z.has(I))continue;let k=this._isNeighborCoordinateBlocked(R,S,this._entity.height);if(T&&k){L.set(x,!0);continue}if(k)continue;let E=Math.abs(O.x),c=Math.abs(O.y),A=Math.abs(O.z),h=c===0?0:this._verticalPenalty,_=(Math.max(E,c,A)===1&&E+c+A>1?1.4:1)+h,m=N+_,p=V.get(I)??1/0;if(m>=p)continue;G.set(I,R),V.set(I,m);let g=m+this._pathfindingHeuristic(S,X);q.set(I,g),H.push([I,S])}}if(j>=w){if(this._onPathfindAbort?.(),this._debug)n.warning(`PathfindingEntityController._calculatePath: Maximum open set iterations reached (${w}), path search aborted. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`)}else if(this._debug)n.warning(`PathfindingEntityController._calculatePath: No valid path found. Start: ${this._coordinateToKey($)}, Target: ${this._coordinateToKey(this._target)}`);return this._target=void 0,this._waypoints=[],!1}_reconstructPath(J,$){let X=[$],Y=$;while(J.has(this._coordinateToKey(Y)))Y=J.get(this._coordinateToKey(Y)),X.unshift(Y);return X}_coordinateToKey(J){return`${J.x},${J.y},${J.z}`}_moveToNextWaypoint(){let J=this._waypointNextIndex>0?this._waypoints[this._waypointNextIndex-1]:void 0,$=this._waypoints[this._waypointNextIndex];if(!$||!this._entity)return;let X=0;if(this._entity.isDynamic&&J&&$.y>J.y){let Y=$.y-J.y,Q=Math.min(Y,this._maxJump)+0.75;this.jump(Q);let W=Math.abs(this._entity.world.simulation.gravity.y),K=Math.sqrt(2*W*Q),Z=J.x+0.5,G=J.z+0.5,V=$.x+0.5,q=$.z+0.5,z=V-Z,H=q-G,v=Math.sqrt(z*z+H*H),F=K/W,U=v/this._speed;X=Math.min(F*0.8,U)*1000}setTimeout(()=>{if(!this._entity)return;let Y=Date.now();this.face($,this._speed),this.move($,this._speed,{moveCompletesWhenStuck:!0,moveIgnoreAxes:{y:this._entity.isDynamic},moveStartIdleAnimationsOnCompletion:this._waypointNextIndex===this._waypoints.length-1,moveStoppingDistance:this._waypointStoppingDistance,moveCallback:()=>{if(Date.now()-Y>this._waypointTimeoutMs&&this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveSkipped?.($,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint()},moveCompleteCallback:()=>{if(this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveComplete?.($,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint();else this._onPathfindComplete?.()}})},X)}_pathfindingHeuristic(J,$){return Math.abs(J.x-$.x)+Math.abs(J.y-$.y)+Math.abs(J.z-$.z)}_isNeighborCoordinateBlocked(J,$,X){if(!this._entity?.world)return!1;let Y=this._entity.world,Q=Math.floor($.x),W=Math.floor($.y),K=Math.floor($.z),Z=Math.floor(J.x),G=Math.floor(J.z);if(!Y.chunkLattice.hasBlock({x:Q,y:W-1,z:K}))return!0;for(let V=0;V<X;V++)if(Y.chunkLattice.hasBlock({x:Q,y:W+V,z:K}))return!0;if(Q!==Z&&K!==G)for(let V=0;V<X;V++){let q=Y.chunkLattice.hasBlock({x:Q,y:W+V,z:G}),z=Y.chunkLattice.hasBlock({x:Z,y:W+V,z:K});if(q||z)return!0}return!1}_findGroundedStart(){if(!this._entity?.world)return;let{x:J,y:$,z:X}=this._entity.position,Y={x:Math.floor(J),y:Math.floor($),z:Math.floor(X)};for(let Q=0;Q<=Math.abs(this._maxFall);Q++)if(this._entity.world.chunkLattice.hasBlock({...Y,y:Y.y-Q-1}))return{...Y,y:Y.y-Q};return}}export{bC6 as startServer,$O1 as WorldManagerEvent,bK as WorldManager,JO1 as WorldLoopEvent,WB as WorldLoop,$n as WorldEvent,KB as World,ai as WebServerEvent,Qz as WebServer,Kz as Vector3,GB as Vector2,QB as Ticker,B3 as TelemetrySpanOperation,T6 as Telemetry,Jn as SimulationEvent,$B as Simulation,VB as SimpleEntityController,YB as SceneUIManager,hh as SceneUIEvent,wU as SceneUI,x78 as SUPPORTED_INPUTS,kF as RigidBodyType,FW as RigidBody,Wz as Quaternion,cO as PlayerUIEvent,zU as PlayerUI,XO1 as PlayerManagerEvent,F$ as PlayerManager,vU as PlayerEvent,o$ as PlayerEntity,Bq0 as PlayerCameraMode,Sh as PlayerCameraEvent,HU as PlayerCamera,kq as Player,CW as PersistenceManager,qn as PathfindingEntityController,XB as ParticleEmitterManager,ri as ParticleEmitterEvent,ti as ParticleEmitter,Oq0 as PLAYER_ROTATION_UPDATE_THRESHOLD,Nq0 as PLAYER_POSITION_UPDATE_THRESHOLD_SQ,k5 as ModelRegistry,u4 as Matrix4,xX as Matrix3,N3 as Matrix2,eN1 as LightType,JB as LightManager,si as LightEvent,oi as Light,w5 as IterationMap,YO1 as GameServerEvent,yK as GameServer,$1 as EventRouter,n as ErrorHandler,LU as EntityManager,BU as EntityEvent,b6 as Entity,Mq0 as ENTITY_ROTATION_UPDATE_THRESHOLD,Lq0 as ENTITY_POSITION_UPDATE_THRESHOLD_SQ,m8 as DefaultPlayerEntityController,fh as DefaultPlayerEntity,wq0 as DEFAULT_ENTITY_RIGID_BODY_OPTIONS,cJ as CollisionGroupsBuilder,OZ as CollisionGroup,Gq as ColliderShape,jU as ColliderMap,S9 as Collider,Cc as CoefficientCombineRule,_h as ChunkLatticeEvent,UU as ChunkLattice,X9 as Chunk,FU as ChatManager,Ah as ChatEvent,kc as BlockTypeRegistryEvent,EF as BlockTypeRegistry,Tc as BlockTypeEvent,A9 as BlockType,eQ as BlockTextureRegistry,R3 as Block,Nn as BaseEntityControllerEvent,iK as BaseEntityController,vz as AudioManager,rC as AudioEvent,zz as Audio,dK as AssetsLibrary};
|