@vgai/editor 0.2.0
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/LICENSE +661 -0
- package/README.md +35 -0
- package/dist/a/b/c/test-nested.json +1 -0
- package/dist/assets/CCDIKSolver-Dz-ysxZF.js +1 -0
- package/dist/assets/SelectionBox-BXsv_6aH.js +1 -0
- package/dist/assets/browser-project-scripts-DOru4L1x.js +2 -0
- package/dist/assets/browserAll-CEkWYlFk.js +1 -0
- package/dist/assets/collision-world-DniMB0qq.glb +0 -0
- package/dist/assets/create-runtime-DYIWr3va.js +1 -0
- package/dist/assets/data-asset-Bb9sIM7i.js +5 -0
- package/dist/assets/esbuild-BHljloGq.wasm +0 -0
- package/dist/assets/fake-three-BMTQ9rl_.js +1 -0
- package/dist/assets/game-8SDZPPgH.js +1 -0
- package/dist/assets/game-BI111o5f.js +10 -0
- package/dist/assets/game-CevorxyV.js +1 -0
- package/dist/assets/game-Di1H0gFj.js +1 -0
- package/dist/assets/game-Di7XlywD.js +1 -0
- package/dist/assets/game-DjnCaw8R.js +1 -0
- package/dist/assets/game-Q9A0aXSV.js +1 -0
- package/dist/assets/game-pt_1lQLv.js +1 -0
- package/dist/assets/game-source-CvidN7AB.js +1 -0
- package/dist/assets/game-xsOho_wg.js +83 -0
- package/dist/assets/index-Bp5cecD6.js +12 -0
- package/dist/assets/index-CPVV6pjw.js +1 -0
- package/dist/assets/index-CpOnYyeD.js +213 -0
- package/dist/assets/index-Cs8xwv3e.js +1 -0
- package/dist/assets/index-DL7RcQ0n.js +27 -0
- package/dist/assets/index-Dr8H_6Rl.js +1 -0
- package/dist/assets/index-_bCaipUk.js +13650 -0
- package/dist/assets/ingest-siblings-Dz8eEqrV.js +1 -0
- package/dist/assets/mount-manifest-Bhk0ohsl.js +1 -0
- package/dist/assets/recast-navigation.wasm-compat-CvP4UGK6.js +1 -0
- package/dist/assets/scene-query-BivAHhJu.js +1 -0
- package/dist/assets/stats.module--VATS4Kh.js +1 -0
- package/dist/assets/webworkerAll-BLrH0F6F.js +1 -0
- package/dist/assets/xstate-animation-binding-1NGLmw6y.js +1 -0
- package/dist/assets/xstate.esm-BgUD33nl.js +3 -0
- package/dist/index.html +37 -0
- package/dist/ingest/racing-game/UPSTREAM.md +68 -0
- package/dist/ingest/racing-game/a/Inter-Black.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Black.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-BlackItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-BlackItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Bold.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Bold.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-BoldItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-BoldItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraBold.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraBold.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraBoldItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraBoldItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraLight.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraLight.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraLightItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-ExtraLightItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Italic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Italic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Light.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Light.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-LightItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-LightItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Medium.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Medium.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-MediumItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-MediumItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Regular.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Regular.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-SemiBold.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-SemiBold.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-SemiBoldItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-SemiBoldItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-Thin.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-Thin.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-ThinItalic.woff +0 -0
- package/dist/ingest/racing-game/a/Inter-ThinItalic.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-italic.var.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter-roman.var.woff2 +0 -0
- package/dist/ingest/racing-game/a/Inter.var.woff2 +0 -0
- package/dist/ingest/racing-game/a/index.css +1 -0
- package/dist/ingest/racing-game/images/bronze.png +0 -0
- package/dist/ingest/racing-game/images/gold.png +0 -0
- package/dist/ingest/racing-game/images/silver.png +0 -0
- package/dist/ingest/racing-game/index.html +15 -0
- package/dist/ingest/racing-game/models/chassis-draco.glb +0 -0
- package/dist/ingest/racing-game/models/track-draco.glb +0 -0
- package/dist/ingest/racing-game/models/wheel-draco.glb +0 -0
- package/dist/ingest/racing-game/rg-entry.js +1 -0
- package/dist/ingest/racing-game/sounds/accelerate.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/boost.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/crash.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/engine.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/honk.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/tire-brake.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/train.mp3 +0 -0
- package/dist/ingest/racing-game/sounds/water.mp3 +0 -0
- package/dist/ingest/racing-game/textures/cursor.svg +3 -0
- package/dist/ingest/racing-game/textures/dikhololo_night_1k.hdr +0 -0
- package/dist/ingest/racing-game/textures/heightmap_1024.png +0 -0
- package/dist/ingest/racing-game/textures/mask.svg +11 -0
- package/dist/ingest/racing-game/textures/no_sound.png +0 -0
- package/dist/ingest/racing-game/three-r139.module.js +50617 -0
- package/dist/ingest/racing-game/vendor.js +179 -0
- package/dist/ingest/racing-game/vgai.game.json +20 -0
- package/dist/ingest/simcity/UPSTREAM.md +65 -0
- package/dist/ingest/simcity/favicon.ico +0 -0
- package/dist/ingest/simcity/fonts/Bebas-Regular.otf +0 -0
- package/dist/ingest/simcity/fonts/Digitalt.otf +0 -0
- package/dist/ingest/simcity/fonts/Stanberry.ttf +0 -0
- package/dist/ingest/simcity/icons/bulldozer-color.png +0 -0
- package/dist/ingest/simcity/icons/bulldozer.png +0 -0
- package/dist/ingest/simcity/icons/calendar.png +0 -0
- package/dist/ingest/simcity/icons/factory-color.png +0 -0
- package/dist/ingest/simcity/icons/factory.png +0 -0
- package/dist/ingest/simcity/icons/house-color.png +0 -0
- package/dist/ingest/simcity/icons/house.png +0 -0
- package/dist/ingest/simcity/icons/job.png +0 -0
- package/dist/ingest/simcity/icons/office.png +0 -0
- package/dist/ingest/simcity/icons/pause-color.png +0 -0
- package/dist/ingest/simcity/icons/pause.png +0 -0
- package/dist/ingest/simcity/icons/person.png +0 -0
- package/dist/ingest/simcity/icons/play-color.png +0 -0
- package/dist/ingest/simcity/icons/play.png +0 -0
- package/dist/ingest/simcity/icons/power-color.png +0 -0
- package/dist/ingest/simcity/icons/power-line-color.png +0 -0
- package/dist/ingest/simcity/icons/power.png +0 -0
- package/dist/ingest/simcity/icons/road-color.png +0 -0
- package/dist/ingest/simcity/icons/road.png +0 -0
- package/dist/ingest/simcity/icons/select-color.png +0 -0
- package/dist/ingest/simcity/icons/select.png +0 -0
- package/dist/ingest/simcity/icons/store-color.png +0 -0
- package/dist/ingest/simcity/index.html +94 -0
- package/dist/ingest/simcity/index.js +58 -0
- package/dist/ingest/simcity/main.css +233 -0
- package/dist/ingest/simcity/models/armored-truck.glb +0 -0
- package/dist/ingest/simcity/models/building-block-4floor-corner.glb +0 -0
- package/dist/ingest/simcity/models/building-block-4floor-short.glb +0 -0
- package/dist/ingest/simcity/models/building-block-5floor.glb +0 -0
- package/dist/ingest/simcity/models/building-burger-joint.glb +0 -0
- package/dist/ingest/simcity/models/building-cafe.glb +0 -0
- package/dist/ingest/simcity/models/building-casino.glb +0 -0
- package/dist/ingest/simcity/models/building-cinema.glb +0 -0
- package/dist/ingest/simcity/models/building-house-block-big.glb +0 -0
- package/dist/ingest/simcity/models/building-house-family-large.glb +0 -0
- package/dist/ingest/simcity/models/building-house-family-small.glb +0 -0
- package/dist/ingest/simcity/models/building-office-balcony.glb +0 -0
- package/dist/ingest/simcity/models/building-office-big.glb +0 -0
- package/dist/ingest/simcity/models/building-office-pyramid.glb +0 -0
- package/dist/ingest/simcity/models/building-office-tall.glb +0 -0
- package/dist/ingest/simcity/models/building-office.glb +0 -0
- package/dist/ingest/simcity/models/building-restaurant.glb +0 -0
- package/dist/ingest/simcity/models/building-skyscraper.glb +0 -0
- package/dist/ingest/simcity/models/car-ambulance-pickup.glb +0 -0
- package/dist/ingest/simcity/models/car-baywatch.glb +0 -0
- package/dist/ingest/simcity/models/car-hippie-van.glb +0 -0
- package/dist/ingest/simcity/models/car-passenger-race.glb +0 -0
- package/dist/ingest/simcity/models/car-passenger.glb +0 -0
- package/dist/ingest/simcity/models/car-police.glb +0 -0
- package/dist/ingest/simcity/models/car-taxi.glb +0 -0
- package/dist/ingest/simcity/models/car-tow-truck.glb +0 -0
- package/dist/ingest/simcity/models/car-truck-dump.glb +0 -0
- package/dist/ingest/simcity/models/car-veteran.glb +0 -0
- package/dist/ingest/simcity/models/construction-small.glb +0 -0
- package/dist/ingest/simcity/models/data-center.glb +0 -0
- package/dist/ingest/simcity/models/industry-factory-old.glb +0 -0
- package/dist/ingest/simcity/models/industry-factory.glb +0 -0
- package/dist/ingest/simcity/models/industry-refinery.glb +0 -0
- package/dist/ingest/simcity/models/industry-warehouse.glb +0 -0
- package/dist/ingest/simcity/models/power_line_pole_modified.glb +0 -0
- package/dist/ingest/simcity/models/tile-plain_grass.glb +0 -0
- package/dist/ingest/simcity/models/tile-road-curve.glb +0 -0
- package/dist/ingest/simcity/models/tile-road-end.glb +0 -0
- package/dist/ingest/simcity/models/tile-road-intersection-t.glb +0 -0
- package/dist/ingest/simcity/models/tile-road-intersection.glb +0 -0
- package/dist/ingest/simcity/models/tile-road-straight.glb +0 -0
- package/dist/ingest/simcity/models/truck.glb +0 -0
- package/dist/ingest/simcity/statusIcons/no-power.png +0 -0
- package/dist/ingest/simcity/statusIcons/no-road-access.png +0 -0
- package/dist/ingest/simcity/textures/base.png +0 -0
- package/dist/ingest/simcity/textures/grid.png +0 -0
- package/dist/ingest/simcity/textures/specular.png +0 -0
- package/dist/ingest/simcity/three-r155.module.js +51466 -0
- package/dist/ingest/simcity/vgai.game.json +20 -0
- package/dist/ingest/tanks/UPSTREAM.md +69 -0
- package/dist/ingest/tanks/index.html +214 -0
- package/dist/ingest/tanks/models/pixelTank.fbx +0 -0
- package/dist/ingest/tanks/tanks-entry.js +92 -0
- package/dist/ingest/tanks/three-r170.module.js +54571 -0
- package/dist/ingest/tanks/vgai.game.json +20 -0
- package/dist/inputmaps/default.inputmap.json +41 -0
- package/dist/jsm/libs/draco/gltf/draco_decoder.js +33 -0
- package/dist/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/dist/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/dist/scenes/untitled.vscn.json +29 -0
- package/dist/textures/waternormals.jpg +0 -0
- package/dist-server/packaged.mjs +18155 -0
- package/package.json +36 -0
- package/server/asset-library-routes.ts +833 -0
- package/server/canonical-path.ts +50 -0
- package/server/cloud-asset-catalog.ts +101 -0
- package/server/dev.ts +350 -0
- package/server/editor-server.ts +1537 -0
- package/server/editor-sse.ts +73 -0
- package/server/game-globals-shadow.ts +58 -0
- package/server/local-asset-catalog.ts +163 -0
- package/server/packaged.ts +571 -0
- package/server/prod.ts +75 -0
- package/server/project-optimize-deps-entries.ts +149 -0
- package/server/project-view.ts +65 -0
- package/server/server-utils.ts +430 -0
- package/server/session-registry.ts +93 -0
- package/src/EditorContext.tsx +87 -0
- package/src/achieved-tier.ts +126 -0
- package/src/action-registry.ts +268 -0
- package/src/adapter-resolver.ts +1858 -0
- package/src/asset-events.ts +100 -0
- package/src/authoring/active-adapter.ts +98 -0
- package/src/authoring/active-systems.ts +50 -0
- package/src/authoring/boundary-authoring-adapter.ts +178 -0
- package/src/authoring/composite-authoring-adapter.ts +891 -0
- package/src/authoring/design-time-layers.ts +776 -0
- package/src/authoring/edit-mode-authoring.ts +643 -0
- package/src/authoring/embed-only-adapter.ts +57 -0
- package/src/authoring/ephemeral-persistence.ts +26 -0
- package/src/authoring/eyedropper-session.ts +69 -0
- package/src/authoring/first-party-hierarchy-menu.ts +74 -0
- package/src/authoring/first-party-inspector/AddSectionMenu.tsx +118 -0
- package/src/authoring/first-party-inspector/EnvironmentSection.tsx +550 -0
- package/src/authoring/first-party-inspector/HeaderSection.tsx +329 -0
- package/src/authoring/first-party-inspector/is-first-party-selection.ts +44 -0
- package/src/authoring/first-party-inspector/register.tsx +108 -0
- package/src/authoring/ingest-authoring-adapter.ts +475 -0
- package/src/authoring/ingest-capture.ts +94 -0
- package/src/authoring/ingest-game-adapter.ts +291 -0
- package/src/authoring/ingest-iframe-adapter.ts +38 -0
- package/src/authoring/ingest-iframe-reachable-adapter.ts +401 -0
- package/src/authoring/ingest-overlay.ts +193 -0
- package/src/authoring/layered-pick.ts +87 -0
- package/src/authoring/mount-failure-report.ts +112 -0
- package/src/authoring/overlay-report.ts +52 -0
- package/src/authoring/project-scenes.ts +111 -0
- package/src/authoring/react-dom-authoring-adapter.ts +795 -0
- package/src/authoring/react-inspector-section.tsx +1041 -0
- package/src/authoring/react-world-authoring-adapter.ts +2400 -0
- package/src/authoring/root-activation.ts +61 -0
- package/src/authoring/scene-ui-layer.ts +485 -0
- package/src/authoring/story-overlay.ts +48 -0
- package/src/authoring/ui-authoring-adapter.ts +325 -0
- package/src/authoring/ui-hierarchy-menu.ts +40 -0
- package/src/authoring/ui-inspector-sections.tsx +156 -0
- package/src/authoring/undo-timeline.ts +145 -0
- package/src/authoring/vgai-scene-authoring-adapter.ts +746 -0
- package/src/authoring/viewport-pick-context.ts +31 -0
- package/src/authoring/viewport-raycast.ts +80 -0
- package/src/authoring/world-overlay.ts +76 -0
- package/src/authoring/world-pan-state.ts +115 -0
- package/src/authoring/world-session-state.ts +102 -0
- package/src/authoring/world2d-authoring-adapter.ts +313 -0
- package/src/browser-external-watch.ts +98 -0
- package/src/browser-play-entry.ts +112 -0
- package/src/browser-project-scripts.ts +112 -0
- package/src/browser-transpile.ts +246 -0
- package/src/browser-watch-reload.ts +100 -0
- package/src/command-listener.ts +326 -0
- package/src/components/AlignToolbar.tsx +189 -0
- package/src/components/AppRoot.tsx +73 -0
- package/src/components/AssetBrowser.tsx +502 -0
- package/src/components/BottomPanel.tsx +326 -0
- package/src/components/BuildPanel.tsx +455 -0
- package/src/components/CameraInfo.tsx +56 -0
- package/src/components/CommandPalette.tsx +265 -0
- package/src/components/ConsolePanel.tsx +272 -0
- package/src/components/DataPanel.tsx +1268 -0
- package/src/components/DefaultEditorLayout.tsx +509 -0
- package/src/components/FolderTree.tsx +179 -0
- package/src/components/GameHierarchy.tsx +1349 -0
- package/src/components/Inspector.tsx +671 -0
- package/src/components/InspectorToolSection.tsx +74 -0
- package/src/components/MountFailureBanner.tsx +110 -0
- package/src/components/NetworkSection.tsx +109 -0
- package/src/components/OnlineAssetBrowser.tsx +448 -0
- package/src/components/OverlayReportBanner.tsx +122 -0
- package/src/components/PlayBar.tsx +356 -0
- package/src/components/PrefabSaveDialog.tsx +201 -0
- package/src/components/ProjectHeader.tsx +174 -0
- package/src/components/ProjectScreen.tsx +1004 -0
- package/src/components/RightPanel.tsx +166 -0
- package/src/components/RootActivateDialog.tsx +105 -0
- package/src/components/SaveDialog.tsx +197 -0
- package/src/components/SaveStatus.tsx +69 -0
- package/src/components/StatsOverlay.tsx +35 -0
- package/src/components/ToolHost.tsx +80 -0
- package/src/components/Toolbar.tsx +307 -0
- package/src/components/ViewportOverlay.tsx +234 -0
- package/src/components/ViewportPanel.tsx +369 -0
- package/src/components/WorldContextMenu.tsx +257 -0
- package/src/components/WorldSelectionOverlay.tsx +2003 -0
- package/src/components/WorldTextEditor.tsx +86 -0
- package/src/components/asset-viewers/AssetViewer.tsx +38 -0
- package/src/components/asset-viewers/AudioViewer.tsx +149 -0
- package/src/components/asset-viewers/GenericJsonViewer.tsx +77 -0
- package/src/components/asset-viewers/ImageViewer.tsx +65 -0
- package/src/components/asset-viewers/InputMapViewer.tsx +206 -0
- package/src/components/asset-viewers/ModelViewer.tsx +180 -0
- package/src/components/asset-viewers/OnlineAssetDetail.tsx +236 -0
- package/src/components/data-csv.ts +301 -0
- package/src/components/entity-name-commit.ts +18 -0
- package/src/components/inspector-property-grouping.ts +65 -0
- package/src/components/inspector-widgets/AlignmentGrid.tsx +188 -0
- package/src/components/inspector-widgets/BorderEditor.tsx +305 -0
- package/src/components/inspector-widgets/ColorPicker.tsx +548 -0
- package/src/components/inspector-widgets/FilterEditor.tsx +108 -0
- package/src/components/inspector-widgets/FontPicker.tsx +196 -0
- package/src/components/inspector-widgets/GradientEditor.tsx +277 -0
- package/src/components/inspector-widgets/ScrubbableInput.tsx +152 -0
- package/src/components/inspector-widgets/ShadowEditor.tsx +332 -0
- package/src/components/inspector-widgets/color-utils.ts +202 -0
- package/src/components/inspector-widgets/gallery-main.tsx +167 -0
- package/src/components/inspector-widgets/index.ts +22 -0
- package/src/components/inspector-widgets/shared.tsx +135 -0
- package/src/components/inspectors/AnimationSection.tsx +143 -0
- package/src/components/inspectors/AudioSection.tsx +215 -0
- package/src/components/inspectors/BoneAttachmentSection.tsx +82 -0
- package/src/components/inspectors/CameraSection.tsx +105 -0
- package/src/components/inspectors/ComponentsSection.tsx +358 -0
- package/src/components/inspectors/JointsSection.tsx +255 -0
- package/src/components/inspectors/LightSection.tsx +116 -0
- package/src/components/inspectors/MaterialSection.tsx +1189 -0
- package/src/components/inspectors/MeshSection.tsx +99 -0
- package/src/components/inspectors/NavigationSection.tsx +58 -0
- package/src/components/inspectors/ParticleSection.tsx +681 -0
- package/src/components/inspectors/PhysicsSection.tsx +326 -0
- package/src/components/inspectors/PostProcessingSection.tsx +1290 -0
- package/src/components/inspectors/RenderingSection.tsx +109 -0
- package/src/components/inspectors/ShadowSection.tsx +84 -0
- package/src/components/inspectors/SplineSection.tsx +191 -0
- package/src/components/inspectors/TransformSection.tsx +191 -0
- package/src/components/inspectors/json-schema-fields.ts +281 -0
- package/src/components/inspectors/multi-edit-utils.ts +49 -0
- package/src/components/inspectors/zod-fields.ts +184 -0
- package/src/components/primitives/ColorInput.tsx +109 -0
- package/src/components/primitives/JsonInput.tsx +98 -0
- package/src/components/primitives/NumberInput.tsx +164 -0
- package/src/components/primitives/Panel.tsx +68 -0
- package/src/components/primitives/SectionHeader.tsx +45 -0
- package/src/components/primitives/Tooltip.tsx +82 -0
- package/src/components/primitives/Vec3Input.tsx +62 -0
- package/src/components/world-overlay-gestures.ts +1438 -0
- package/src/doctor/data-checks.ts +285 -0
- package/src/doctor/report.ts +386 -0
- package/src/editor-api.ts +700 -0
- package/src/editor-console.ts +194 -0
- package/src/editor-hotkeys.ts +441 -0
- package/src/editor-layers.ts +2 -0
- package/src/editor-mode.ts +28 -0
- package/src/editor-store.ts +2225 -0
- package/src/editor-viewport.ts +1924 -0
- package/src/entity-factory.ts +221 -0
- package/src/game-globals-prelude.ts +27 -0
- package/src/gated-globals.ts +131 -0
- package/src/generated/setup-by-example.generated.ts +53 -0
- package/src/gizmo-registry.ts +608 -0
- package/src/handle-system.ts +221 -0
- package/src/hierarchy-menu-registry.ts +70 -0
- package/src/hierarchy-rows.ts +73 -0
- package/src/hosted-example.ts +160 -0
- package/src/hotkeys.ts +142 -0
- package/src/ingest/discovery-react.ts +132 -0
- package/src/ingest/discovery.ts +205 -0
- package/src/ingest/discovery2d.ts +204 -0
- package/src/ingest/esm-entry-resolution.ts +102 -0
- package/src/ingest/games/bloom-composer/game.js +99 -0
- package/src/ingest/games/bloom-composer/vgai.game.json +21 -0
- package/src/ingest/games/embed-bundle/embed.html +10 -0
- package/src/ingest/games/embed-bundle/vgai.game.json +21 -0
- package/src/ingest/games/games-fps/assets/collision-world.glb +0 -0
- package/src/ingest/games/games-fps/game.js +479 -0
- package/src/ingest/games/games-fps/vgai.game.json +24 -0
- package/src/ingest/games/iframe-reachable/game-source.js +58 -0
- package/src/ingest/games/iframe-reachable/vgai.game.json +21 -0
- package/src/ingest/games/interactive-cubes/game.js +139 -0
- package/src/ingest/games/interactive-cubes/vgai.game.json +21 -0
- package/src/ingest/games/mismatched-three/fake-three.js +38 -0
- package/src/ingest/games/mismatched-three/game.js +10 -0
- package/src/ingest/games/mismatched-three/vgai.game.json +22 -0
- package/src/ingest/games/own-three-bundled/game.js +43 -0
- package/src/ingest/games/own-three-bundled/vgai.game.json +21 -0
- package/src/ingest/games/pointerlock-maze/game.js +288 -0
- package/src/ingest/games/pointerlock-maze/vgai.game.json +22 -0
- package/src/ingest/games-2d/_fixtures/first-party-scene.scn2d.json +124 -0
- package/src/ingest/games-2d/bubbo-bubbo/vgai.game.json +25 -0
- package/src/ingest/games-2d/bunnymark/game.ts +88 -0
- package/src/ingest/games-2d/bunnymark/vgai.game.json +21 -0
- package/src/ingest/games-2d/flappy/game.ts +148 -0
- package/src/ingest/games-2d/flappy/vgai.game.json +21 -0
- package/src/ingest/games-2d/flappy-pixi/vgai.game.json +25 -0
- package/src/ingest/games-2d/puzzling-potions/vgai.game.json +25 -0
- package/src/ingest/games-2d/tilemap-camera/game.ts +115 -0
- package/src/ingest/games-2d/tilemap-camera/vgai.game.json +21 -0
- package/src/ingest/games-react/react-rpg/entry.tsx +185 -0
- package/src/ingest/games-react/react-rpg/shims.d.ts +26 -0
- package/src/ingest/games-react/react-rpg/src/ui/game-state.tsx +129 -0
- package/src/ingest/games-react/react-rpg/vgai.game.json +21 -0
- package/src/ingest/host-namespace-registry.ts +196 -0
- package/src/ingest/types.ts +127 -0
- package/src/ingest-hierarchy-rows.ts +207 -0
- package/src/ingest-mode.ts +2092 -0
- package/src/ingest-siblings.ts +466 -0
- package/src/initial-scene.ts +194 -0
- package/src/inspector-section-registry.ts +117 -0
- package/src/interactive-edit-scope.ts +34 -0
- package/src/main.tsx +23 -0
- package/src/manifest-project.ts +43 -0
- package/src/model-thumbnail.ts +156 -0
- package/src/module-mode.ts +513 -0
- package/src/navmesh-handler.ts +94 -0
- package/src/packaged-runtime.ts +49 -0
- package/src/play-mode.ts +1148 -0
- package/src/playground/main.ts +206 -0
- package/src/project-manager.ts +173 -0
- package/src/scene-diff.ts +112 -0
- package/src/scene-serializer.ts +144 -0
- package/src/scene-sync.ts +587 -0
- package/src/scene-ui-mode/active-scene-ui.ts +58 -0
- package/src/scene-ui-mode/scene-ui-palette-panel.tsx +152 -0
- package/src/scene-ui-mode/scene-ui-timeline-tab.tsx +29 -0
- package/src/scene-ui-mode/ui-prefab-dialog-host.tsx +74 -0
- package/src/scene-ui-mode/ui-prefab-hierarchy-menu.ts +49 -0
- package/src/scene-ui-mode/ui-prefab-io.ts +76 -0
- package/src/script-loader.ts +143 -0
- package/src/storage/fsa-storage.ts +55 -0
- package/src/storage/handle-storage.ts +150 -0
- package/src/storage/handle-store.ts +116 -0
- package/src/storage/http-storage.ts +137 -0
- package/src/storage/index.ts +147 -0
- package/src/storage/mem-storage.ts +135 -0
- package/src/storage/opfs-storage.ts +25 -0
- package/src/storage/paths.ts +26 -0
- package/src/storage/seed.ts +106 -0
- package/src/storage/types.ts +110 -0
- package/src/tool-loader.ts +291 -0
- package/src/ui-editor/inspector.tsx +563 -0
- package/src/ui-editor/node-ops.ts +266 -0
- package/src/ui-editor/overlay.tsx +380 -0
- package/src/ui-editor/palette.tsx +114 -0
- package/src/ui-editor/react-store.ts +78 -0
- package/src/ui-editor/timeline-panel.tsx +443 -0
- package/src/ui-editor/ui-edit-store.ts +552 -0
- package/src/ui-editor/ui-prefab.ts +95 -0
- package/src/ui-source/inspect.ts +544 -0
- package/src/ui-source/oid-transform.ts +133 -0
- package/src/ui-source/source-write-backend.ts +203 -0
- package/src/ui-source/tailwind-map.ts +174 -0
- package/src/ui-source/writer.ts +1175 -0
- package/src/widgets/index.ts +73 -0
- package/template/.claude/skills/editor/SKILL.md +252 -0
- package/template/CLAUDE.md +512 -0
- package/template/LICENSE +30 -0
- package/template/emit-schemas.ts +42 -0
- package/template/index.html +17 -0
- package/template/package.json +53 -0
- package/template/project.json +9 -0
- package/template/public/audio/ambient-arena.wav +0 -0
- package/template/public/audio/ambient-music.wav +0 -0
- package/template/public/audio/ambient-nature.wav +0 -0
- package/template/public/audio/ambient-wind.wav +0 -0
- package/template/public/inputmaps/default.inputmap.json +41 -0
- package/template/public/jsm/libs/draco/gltf/draco_decoder.js +33 -0
- package/template/public/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/template/public/jsm/libs/draco/gltf/draco_encoder.js +33 -0
- package/template/public/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/template/public/scenes/default.vscn.json +43 -0
- package/template/public/scenes/untitled.vscn.json +29 -0
- package/template/public/textures/waternormals.jpg +0 -0
- package/template/server/colyseus-setup.ts +85 -0
- package/template/server/main.ts +34 -0
- package/template/server/rooms/arena-room.ts +420 -0
- package/template/server/rooms/game-room.ts +162 -0
- package/template/server/rooms.ts +15 -0
- package/template/server/tsconfig.json +19 -0
- package/template/src/data/README.md +40 -0
- package/template/src/data/assets.ts +31 -0
- package/template/src/data/tuning.data.json +5 -0
- package/template/src/data/tuning.schema.json +21 -0
- package/template/src/data/tuning.schema.ts +34 -0
- package/template/src/data/tuning.ts +24 -0
- package/template/src/main.ts +157 -0
- package/template/src/scripts/components/data-spinner.ts +45 -0
- package/template/src/scripts/components/scene-camera.ts +40 -0
- package/template/src/scripts/main.ts +94 -0
- package/template/src/scripts/registry.ts +46 -0
- package/template/src/tools/README.md +14 -0
- package/template/src/tools/example.tool.tsx +91 -0
- package/template/src/tools/spin.tool.tsx +101 -0
- package/template/src/ui/Button.tsx +27 -0
- package/template/src/ui/DefaultHud.tsx +40 -0
- package/template/src/ui/KeyHint.tsx +25 -0
- package/template/src/ui/Panel.tsx +52 -0
- package/template/src/ui/RebindPanel.tsx +129 -0
- package/template/src/ui/Slider.tsx +28 -0
- package/template/src/ui/StatusDot.tsx +22 -0
- package/template/src/ui/Toggle.tsx +19 -0
- package/template/src/ui/game-state.tsx +37 -0
- package/template/src/ui/index.ts +7 -0
- package/template/src/ui/mount-default-hud.tsx +19 -0
- package/template/src/ui/mount-ui.ts +15 -0
- package/template/tsconfig.json +36 -0
- package/template/validate-asset-content.ts +78 -0
- package/template/validate-manifest.ts +55 -0
- package/template/validate-scenes.ts +211 -0
- package/template/vgai.game.json +21 -0
- package/template/vite.config.ts +128 -0
- package/vite-plugin-example-assets.ts +60 -0
- package/vite-plugin-game-globals.ts +46 -0
- package/vite-plugin-game-static.ts +71 -0
- package/vite-plugin-project-game-static.ts +84 -0
- package/vite-plugin-react-game-static.ts +98 -0
- package/vite-plugin-react-world-provider.ts +81 -0
- package/vite-plugin-react-world-runtime.ts +76 -0
- package/vite-plugin-ui-oid.ts +561 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var no=Object.defineProperty;var zs=i=>{throw TypeError(i)};var so=(i,e,t)=>e in i?no(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var E=(i,e,t)=>so(i,typeof e!="symbol"?e+"":e,t),_s=(i,e,t)=>e.has(i)||zs("Cannot "+t);var $e=(i,e,t)=>(_s(i,e,"read from private field"),t?t.call(i):e.get(i)),Ct=(i,e,t)=>e.has(i)?zs("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),lt=(i,e,t,n)=>(_s(i,e,"write to private field"),n?n.call(i,t):e.set(i,t),t);import*as A from"/ingest/tanks/three-r170.module.js";import{Vector4 as cn,Vector3 as Pe,Curve as ro,Loader as ss,LoaderUtils as io,FileLoader as oo,TextureLoader as ao,RepeatWrapping as Us,ClampToEdgeWrapping as Ns,Texture as lo,MeshPhongMaterial as Yn,MeshLambertMaterial as co,ColorManagement as dt,Color as et,SRGBColorSpace as Ae,EquirectangularReflectionMapping as fo,Matrix4 as fe,Group as Vs,Bone as js,PropertyBinding as On,Object3D as kn,PerspectiveCamera as ho,PointLight as Hs,MathUtils as Te,SpotLight as uo,DirectionalLight as po,SkinnedMesh as go,Mesh as mo,LineBasicMaterial as yo,Line as xo,Skeleton as vo,AmbientLight as wo,BufferGeometry as qn,Float32BufferAttribute as Ut,Uint16BufferAttribute as bo,Matrix3 as Eo,Vector2 as Co,ShapeUtils as So,Euler as kt,AnimationClip as To,Quaternion as ct,VectorKeyframeTrack as ko,QuaternionKeyframeTrack as Ws,NumberKeyframeTrack as Io}from"/ingest/tanks/three-r170.module.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function t(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=t(s);fetch(s.href,r)}})();var Ee={JOIN_ROOM:10,ERROR:11,LEAVE_ROOM:12,ROOM_DATA:13,ROOM_STATE:14,ROOM_STATE_PATCH:15,ROOM_DATA_BYTES:17,PING:18},Ne={GOING_AWAY:1001,NO_STATUS_RECEIVED:1005,ABNORMAL_CLOSURE:1006,CONSENTED:4e3,FAILED_TO_RECONNECT:4003,MAY_TRY_RECONNECT:4010};class on extends Error{constructor(t,n,s){super(n);E(this,"code");E(this,"headers");E(this,"status");E(this,"response");E(this,"data");this.name="ServerError",this.code=t,s&&(this.headers=s.headers,this.status=s.status,this.response=s.response,this.data=s.data)}}class xs extends Error{constructor(t,n){super(t);E(this,"code");this.code=n,this.name="MatchMakeError",Object.setPrototypeOf(this,xs.prototype)}}const Fn=255,Gr=213;var k;(function(i){i[i.ADD=128]="ADD",i[i.REPLACE=0]="REPLACE",i[i.DELETE=64]="DELETE",i[i.DELETE_AND_MOVE=96]="DELETE_AND_MOVE",i[i.MOVE_AND_ADD=160]="MOVE_AND_ADD",i[i.DELETE_AND_ADD=192]="DELETE_AND_ADD",i[i.CLEAR=10]="CLEAR",i[i.REVERSE=15]="REVERSE",i[i.MOVE=32]="MOVE",i[i.DELETE_BY_REFID=33]="DELETE_BY_REFID",i[i.ADD_BY_REFID=129]="ADD_BY_REFID"})(k||(k={}));Symbol.metadata??(Symbol.metadata=Symbol.for("Symbol.metadata"));const G="~refId",Jt="~track",Ye="~encoder",qe="~decoder",nn="~filter",Fe="~getByIndex",Pt="~deleteByIndex",R="~changes",ne="~childType",Zt="~onEncodeEnd",rs="~onDecodeEnd",ht="~descriptors",He="~__numFields",It="~__refTypeFieldIndexes",tt="~__viewFieldIndexes",Nt="$__fieldIndexesByViewTag";let Mo;try{Mo=new TextEncoder}catch{}const Un=new ArrayBuffer(8),Rt=new Int32Array(Un),is=new Float32Array(Un),Ao=new Float64Array(Un),Xr=new BigInt64Array(Un),Ro=typeof Buffer<"u"&&Buffer.byteLength,Yr=Ro?Buffer.byteLength:function(i,e){for(var t=0,n=0,s=0,r=i.length;s<r;s++)t=i.charCodeAt(s),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(s++,n+=4);return n};function qr(i,e,t){for(var n=0,s=0,r=e.length;s<r;s++)n=e.charCodeAt(s),n<128?i[t.offset++]=n:n<2048?(i[t.offset]=192|n>>6,i[t.offset+1]=128|n&63,t.offset+=2):n<55296||n>=57344?(i[t.offset]=224|n>>12,i[t.offset+1]=128|n>>6&63,i[t.offset+2]=128|n&63,t.offset+=3):(s++,n=65536+((n&1023)<<10|e.charCodeAt(s)&1023),i[t.offset]=240|n>>18,i[t.offset+1]=128|n>>12&63,i[t.offset+2]=128|n>>6&63,i[t.offset+3]=128|n&63,t.offset+=4)}function Jr(i,e,t){i[t.offset++]=e&255}function Do(i,e,t){i[t.offset++]=e&255}function Kr(i,e,t){i[t.offset++]=e&255,i[t.offset++]=e>>8&255}function vs(i,e,t){i[t.offset++]=e&255,i[t.offset++]=e>>8&255}function it(i,e,t){i[t.offset++]=e&255,i[t.offset++]=e>>8&255,i[t.offset++]=e>>16&255,i[t.offset++]=e>>24&255}function Dt(i,e,t){const n=e>>24,s=e>>16,r=e>>8,o=e;i[t.offset++]=o&255,i[t.offset++]=r&255,i[t.offset++]=s&255,i[t.offset++]=n&255}function Zr(i,e,t){const n=Math.floor(e/Math.pow(2,32)),s=e>>>0;Dt(i,s,t),Dt(i,n,t)}function Qr(i,e,t){const n=e/Math.pow(2,32)>>0,s=e>>>0;Dt(i,s,t),Dt(i,n,t)}function Bo(i,e,t){Xr[0]=BigInt.asIntN(64,e),it(i,Rt[0],t),it(i,Rt[1],t)}function Lo(i,e,t){Xr[0]=BigInt.asIntN(64,e),it(i,Rt[0],t),it(i,Rt[1],t)}function ei(i,e,t){is[0]=e,it(i,Rt[0],t)}function ti(i,e,t){Ao[0]=e,it(i,Rt[0],t),it(i,Rt[1],t)}function Po(i,e,t){i[t.offset++]=e?1:0}function Oo(i,e,t){e||(e="");let n=Yr(e,"utf8"),s=0;if(n<32)i[t.offset++]=n|160,s=1;else if(n<256)i[t.offset++]=217,i[t.offset++]=n,s=2;else if(n<65536)i[t.offset++]=218,vs(i,n,t),s=3;else if(n<4294967296)i[t.offset++]=219,Dt(i,n,t),s=5;else throw new Error("String too long");return qr(i,e,t),s+n}function os(i,e,t){if(isNaN(e))return os(i,0,t);if(isFinite(e)){if(e!==(e|0))return Math.abs(e)<=34028235e31&&(is[0]=e,Math.abs(Math.abs(is[0])-Math.abs(e))<1e-4)?(i[t.offset++]=202,ei(i,e,t),5):(i[t.offset++]=203,ti(i,e,t),9)}else return os(i,e>0?Number.MAX_SAFE_INTEGER:-Number.MAX_SAFE_INTEGER,t);return e>=0?e<128?(i[t.offset++]=e&255,1):e<256?(i[t.offset++]=204,i[t.offset++]=e&255,2):e<65536?(i[t.offset++]=205,vs(i,e,t),3):e<4294967296?(i[t.offset++]=206,Dt(i,e,t),5):(i[t.offset++]=207,Qr(i,e,t),9):e>=-32?(i[t.offset++]=224|e+32,1):e>=-128?(i[t.offset++]=208,Jr(i,e,t),2):e>=-32768?(i[t.offset++]=209,Kr(i,e,t),3):e>=-2147483648?(i[t.offset++]=210,it(i,e,t),5):(i[t.offset++]=211,Zr(i,e,t),9)}const ae={int8:Jr,uint8:Do,int16:Kr,uint16:vs,int32:it,uint32:Dt,int64:Zr,uint64:Qr,bigint64:Bo,biguint64:Lo,float32:ei,float64:ti,boolean:Po,string:Oo,number:os,utf8Write:qr,utf8Length:Yr},xn=new ArrayBuffer(8),Bt=new Int32Array(xn),Fo=new Float32Array(xn),$o=new Float64Array(xn),zo=new BigUint64Array(xn),_o=new BigInt64Array(xn);function ni(i,e,t){t>i.length-e.offset&&(t=i.length-e.offset);for(var n="",s=0,r=e.offset,o=e.offset+t;r<o;r++){var a=i[r];if((a&128)===0){n+=String.fromCharCode(a);continue}if((a&224)===192){n+=String.fromCharCode((a&31)<<6|i[++r]&63);continue}if((a&240)===224){n+=String.fromCharCode((a&15)<<12|(i[++r]&63)<<6|(i[++r]&63)<<0);continue}if((a&248)===240){s=(a&7)<<18|(i[++r]&63)<<12|(i[++r]&63)<<6|(i[++r]&63)<<0,s>=65536?(s-=65536,n+=String.fromCharCode((s>>>10)+55296,(s&1023)+56320)):n+=String.fromCharCode(s);continue}console.error("decode.utf8Read(): Invalid byte "+a+" at offset "+r+". Skip to end of string: "+(e.offset+t));break}return e.offset+=t,n}function si(i,e){return vn(i,e)<<24>>24}function vn(i,e){return i[e.offset++]}function ri(i,e){return Nn(i,e)<<16>>16}function Nn(i,e){return i[e.offset++]|i[e.offset++]<<8}function Ve(i,e){return i[e.offset++]|i[e.offset++]<<8|i[e.offset++]<<16|i[e.offset++]<<24}function Qt(i,e){return Ve(i,e)>>>0}function ii(i,e){return Bt[0]=Ve(i,e),Fo[0]}function oi(i,e){return Bt[0]=Ve(i,e),Bt[1]=Ve(i,e),$o[0]}function ai(i,e){const t=Qt(i,e);return Ve(i,e)*Math.pow(2,32)+t}function li(i,e){const t=Qt(i,e);return Qt(i,e)*Math.pow(2,32)+t}function Uo(i,e){return Bt[0]=Ve(i,e),Bt[1]=Ve(i,e),_o[0]}function No(i,e){return Bt[0]=Ve(i,e),Bt[1]=Ve(i,e),zo[0]}function Vo(i,e){return vn(i,e)>0}function jo(i,e){const t=i[e.offset++];let n;return t<192?n=t&31:t===217?n=vn(i,e):t===218?n=Nn(i,e):t===219&&(n=Qt(i,e)),ni(i,e,n)}function Ho(i,e){const t=i[e.offset++];if(t<128)return t;if(t===202)return ii(i,e);if(t===203)return oi(i,e);if(t===204)return vn(i,e);if(t===205)return Nn(i,e);if(t===206)return Qt(i,e);if(t===207)return li(i,e);if(t===208)return si(i,e);if(t===209)return ri(i,e);if(t===210)return Ve(i,e);if(t===211)return ai(i,e);if(t>223)return(255-t+1)*-1}function Wo(i,e){const t=i[e.offset];return t<192&&t>160||t===217||t===218||t===219}const oe={utf8Read:ni,int8:si,uint8:vn,int16:ri,uint16:Nn,int32:Ve,uint32:Qt,float32:ii,float64:oi,int64:ai,uint64:li,bigint64:Uo,biguint64:No,boolean:Vo,string:jo,number:Ho,stringCheck:Wo},ws={},Go=new Map;function xt(i,e){e.constructor&&(Go.set(e.constructor,i),ws[i]=e),e.encode&&(ae[i]=e.encode),e.decode&&(oe[i]=e.decode)}function ci(i){return ws[i]}const We=class We{constructor(e){E(this,"types",{});E(this,"schemas",new Map);E(this,"hasFilters",!1);E(this,"parentFiltered",{});e&&this.discoverTypes(e)}static register(e){const t=Object.getPrototypeOf(e);if(t!==ue){let n=We.inheritedTypes.get(t);n||(n=new Set,We.inheritedTypes.set(t,n)),n.add(e)}}static cache(e){let t=We.cachedContexts.get(e);return t||(t=new We(e),We.cachedContexts.set(e,t)),t}has(e){return this.schemas.has(e)}get(e){return this.types[e]}add(e,t=this.schemas.size){return this.schemas.has(e)?!1:(this.types[t]=e,e[Symbol.metadata]===void 0&&Oe.initialize(e),this.schemas.set(e,t),!0)}getTypeId(e){return this.schemas.get(e)}discoverTypes(e,t,n,s){var a,l;if(s&&this.registerFilteredByParent(e,t,n),!this.add(e))return;(a=We.inheritedTypes.get(e))==null||a.forEach(d=>{this.discoverTypes(d,t,n,s)});let r=e;for(;(r=Object.getPrototypeOf(r))&&r!==ue&&r!==Function.prototype;)this.discoverTypes(r);const o=e[l=Symbol.metadata]??(e[l]={});o[tt]&&(this.hasFilters=!0);for(const d in o){const c=d,f=o[c].type,h=o[c].tag!==void 0;if(typeof f!="string")if(typeof f=="function")this.discoverTypes(f,e,c,s||h);else{const p=Object.values(f)[0];if(typeof p=="string")continue;this.discoverTypes(p,e,c,s||h)}}}registerFilteredByParent(e,t,n){let r=`${this.schemas.get(e)??this.schemas.size}`;t&&(r+=`-${this.schemas.get(t)}`),r+=`-${n}`,this.parentFiltered[r]=!0}debug(){let e="";for(const t in this.parentFiltered){const n=t.split("-").map(Number),s=n.pop();e+=`
|
|
2
|
+
`,e+=`${t}: ${n.reverse().map((r,o)=>{const a=this.types[r],l=a[Symbol.metadata];let d=a.name;return o===0&&(d+=`[${l[s].name}]`),`${d}`}).join(" -> ")}`}return`TypeContext ->
|
|
3
|
+
Schema types: ${this.schemas.size}
|
|
4
|
+
hasFilters: ${this.hasFilters}
|
|
5
|
+
parentFiltered:${e}`}};E(We,"inheritedTypes",new Map),E(We,"cachedContexts",new Map);let Lt=We;function At(i){if(Array.isArray(i))return{array:At(i[0])};if(typeof i.type<"u")return i.type;if(Xo(i))return Object.keys(i).every(e=>typeof i[e]=="string")?"string":"number";if(typeof i=="object"&&i!==null){const e=Object.keys(i).find(t=>ws[t]!==void 0);if(e)return i[e]=At(i[e]),i}return i}function Xo(i){if(typeof i=="function"&&i[Symbol.metadata])return!1;const e=Object.keys(i),t=e.filter(n=>/\d+/.test(n));return!!(t.length>0&&t.length===e.length/2&&i[i[t[0]]]==t[0]||e.length>0&&e.every(n=>typeof i[n]=="string"&&i[n]===n))}const Oe={addField(i,e,t,n,s){if(e>64)throw new Error(`Can't define field '${t}'.
|
|
6
|
+
Schema instances may only have up to 64 fields.`);i[e]=Object.assign(i[e]||{},{type:At(n),index:e,name:t}),Object.defineProperty(i,ht,{value:i[ht]||{},enumerable:!1,configurable:!0}),s?(i[ht][t]=s,i[ht][`_${t}`]={value:void 0,writable:!0,enumerable:!1,configurable:!0}):i[ht][t]={value:void 0,writable:!0,enumerable:!0,configurable:!0},Object.defineProperty(i,He,{value:e,enumerable:!1,configurable:!0}),Object.defineProperty(i,t,{value:e,enumerable:!1,configurable:!0}),typeof i[e].type!="string"&&(i[It]===void 0&&Object.defineProperty(i,It,{value:[],enumerable:!1,configurable:!0}),i[It].push(e))},setTag(i,e,t){const n=i[e],s=i[n];s.tag=t,i[tt]||(Object.defineProperty(i,tt,{value:[],enumerable:!1,configurable:!0}),Object.defineProperty(i,Nt,{value:{},enumerable:!1,configurable:!0})),i[tt].push(n),i[Nt][t]||(i[Nt][t]=[]),i[Nt][t].push(n)},setFields(i,e){const t=i.prototype.constructor;Lt.register(t);const n=Object.getPrototypeOf(t),s=n&&n[Symbol.metadata],r=Oe.initialize(t);t[Jt]||(t[Jt]=ue[Jt]),t[Ye]||(t[Ye]=ue[Ye]),t[qe]||(t[qe]=ue[qe]),t.prototype.toJSON||(t.prototype.toJSON=ue.prototype.toJSON);let o=r[He]??(s&&s[He])??-1;o++;for(const a in e){const l=At(e[a]),d=typeof Object.keys(l)[0]=="string"&&ci(Object.keys(l)[0]),c=d?Object.values(l)[0]:l;Oe.addField(r,o,a,l,ta(`_${a}`,o,c,d)),o++}return i},isDeprecated(i,e){return i[e].deprecated===!0},init(i){const e={};i[Symbol.metadata]=e,Object.defineProperty(e,He,{value:0,enumerable:!1,configurable:!0})},initialize(i){const e=Object.getPrototypeOf(i),t=e[Symbol.metadata];let n=i[Symbol.metadata]??Object.create(null);return e!==ue&&n===t&&(n=Object.create(null),t&&(Object.setPrototypeOf(n,t),Object.defineProperty(n,He,{value:t[He],enumerable:!1,configurable:!0,writable:!0}),t[tt]!==void 0&&(Object.defineProperty(n,tt,{value:[...t[tt]],enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(n,Nt,{value:{...t[Nt]},enumerable:!1,configurable:!0,writable:!0})),t[It]!==void 0&&Object.defineProperty(n,It,{value:[...t[It]],enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(n,ht,{value:{...t[ht]},enumerable:!1,configurable:!0,writable:!0}))),Object.defineProperty(i,Symbol.metadata,{value:n,writable:!1,configurable:!0}),n},isValidInstance(i){return i.constructor[Symbol.metadata]&&Object.prototype.hasOwnProperty.call(i.constructor[Symbol.metadata],He)},getFields(i){const e=i[Symbol.metadata],t={};for(let n=0;n<=e[He];n++)t[e[n].name]=e[n].type;return t},hasViewTagAtIndex(i,e){var t;return(t=i==null?void 0:i[tt])==null?void 0:t.includes(e)}};function Qe(i){return{indexes:{},operations:[],queueRootNode:i}}function Wt(){return{next:void 0,tail:void 0}}function Re(i,e){const t=i.indexes[e];t===void 0?i.indexes[e]=i.operations.push(e)-1:i.operations[t]=e}function Gs(i,e){var n;let t=i.indexes[e];t===void 0&&(t=Object.values(i.indexes).at(-1),e=(n=Object.entries(i.indexes).find(([s,r])=>r===t))==null?void 0:n[0]),i.operations[t]=void 0,delete i.indexes[e]}class wn{constructor(e){E(this,"ref");E(this,"metadata");E(this,"root");E(this,"parentChain");E(this,"isFiltered",!1);E(this,"isVisibilitySharedWithParent");E(this,"indexedOperations",{});E(this,"changes",{indexes:{},operations:[]});E(this,"allChanges",{indexes:{},operations:[]});E(this,"filteredChanges");E(this,"allFilteredChanges");E(this,"indexes");E(this,"isNew",!0);var t;this.ref=e,this.metadata=e.constructor[Symbol.metadata],(t=this.metadata)!=null&&t[tt]&&(this.allFilteredChanges={indexes:{},operations:[]},this.filteredChanges={indexes:{},operations:[]})}setRoot(e){this.root=e;const t=this.root.add(this);this.checkIsFiltered(this.parent,this.parentIndex,t),t&&this.forEachChild((n,s)=>{n.root!==e?n.setRoot(e):e.add(n)})}setParent(e,t,n){if(this.addParent(e,n),!t)return;const s=t.add(this);t!==this.root&&(this.root=t,this.checkIsFiltered(e,n,s)),s&&this.forEachChild((r,o)=>{if(r.root===t){t.add(r),t.moveNextToParent(r);return}r.setParent(this.ref,t,o)})}forEachChild(e){var t,n;if(this.ref[ne]){if(typeof this.ref[ne]!="string")for(const[s,r]of this.ref.entries())r&&e(r[R],((t=this.indexes)==null?void 0:t[s])??s)}else for(const s of((n=this.metadata)==null?void 0:n[It])??[]){const r=this.metadata[s],o=this.ref[r.name];o&&e(o[R],s)}}operation(e){var t,n;this.filteredChanges!==void 0?(this.filteredChanges.operations.push(-e),(t=this.root)==null||t.enqueueChangeTree(this,"filteredChanges")):(this.changes.operations.push(-e),(n=this.root)==null||n.enqueueChangeTree(this,"changes"))}change(e,t=k.ADD){var o,a,l;const n=this.isFiltered||((a=(o=this.metadata)==null?void 0:o[e])==null?void 0:a.tag)!==void 0,s=n?this.filteredChanges:this.changes,r=this.indexedOperations[e];if(!r||r===k.DELETE){const d=r&&r===k.DELETE?k.DELETE_AND_ADD:t;this.indexedOperations[e]=d}Re(s,e),n?(Re(this.allFilteredChanges,e),this.root&&(this.root.enqueueChangeTree(this,"filteredChanges"),this.root.enqueueChangeTree(this,"allFilteredChanges"))):(Re(this.allChanges,e),(l=this.root)==null||l.enqueueChangeTree(this,"changes"))}shiftChangeIndexes(e){const t=this.isFiltered?this.filteredChanges:this.changes,n={},s={};for(const r in this.indexedOperations)n[Number(r)+e]=this.indexedOperations[r],s[Number(r)+e]=t.indexes[r];this.indexedOperations=n,t.indexes=s,t.operations=t.operations.map(r=>r+e)}shiftAllChangeIndexes(e,t=0){this.filteredChanges!==void 0?(this._shiftAllChangeIndexes(e,t,this.allFilteredChanges),this._shiftAllChangeIndexes(e,t,this.allChanges)):this._shiftAllChangeIndexes(e,t,this.allChanges)}_shiftAllChangeIndexes(e,t=0,n){const s={};let r=0;for(const o in n.indexes)s[r++]=n.indexes[o];n.indexes=s;for(let o=0;o<n.operations.length;o++){const a=n.operations[o];a>t&&(n.operations[o]=a+e)}}indexedOperation(e,t,n=e){var s,r;this.indexedOperations[e]=t,this.filteredChanges!==void 0?(Re(this.allFilteredChanges,n),Re(this.filteredChanges,e),(s=this.root)==null||s.enqueueChangeTree(this,"filteredChanges")):(Re(this.allChanges,n),Re(this.changes,e),(r=this.root)==null||r.enqueueChangeTree(this,"changes"))}getType(e){return this.ref[ne]||this.metadata[e].type}getChange(e){return this.indexedOperations[e]}getValue(e,t=!1){return this.ref[Fe](e,t)}delete(e,t,n=e){var o,a,l;if(e===void 0){try{throw new Error(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index '${e}'`)}catch(d){console.warn(d)}return}const s=this.filteredChanges!==void 0?this.filteredChanges:this.changes;this.indexedOperations[e]=t??k.DELETE,Re(s,e),Gs(this.allChanges,n);const r=this.getValue(e);return r&&r[R]&&((o=this.root)==null||o.remove(r[R])),this.filteredChanges!==void 0?(Gs(this.allFilteredChanges,n),(a=this.root)==null||a.enqueueChangeTree(this,"filteredChanges")):(l=this.root)==null||l.enqueueChangeTree(this,"changes"),r}endEncode(e){var t,n;this.indexedOperations={},this[e]=Qe(),(n=(t=this.ref)[Zt])==null||n.call(t),this.isNew=!1}discard(e=!1){var t,n;(n=(t=this.ref)[Zt])==null||n.call(t),this.indexedOperations={},this.changes=Qe(this.changes.queueRootNode),this.filteredChanges!==void 0&&(this.filteredChanges=Qe(this.filteredChanges.queueRootNode)),e&&(this.allChanges=Qe(this.allChanges.queueRootNode),this.allFilteredChanges!==void 0&&(this.allFilteredChanges=Qe(this.allFilteredChanges.queueRootNode)))}discardAll(){const e=Object.keys(this.indexedOperations);for(let t=0,n=e.length;t<n;t++){const s=this.getValue(Number(e[t]));s&&s[R]&&s[R].discardAll()}this.discard()}get changed(){return Object.entries(this.indexedOperations).length>0}checkIsFiltered(e,t,n){var s,r,o,a;this.root.types.hasFilters&&(this._checkFilteredByParent(e,t),this.filteredChanges!==void 0&&((s=this.root)==null||s.enqueueChangeTree(this,"filteredChanges"),n&&((r=this.root)==null||r.enqueueChangeTree(this,"allFilteredChanges")))),this.isFiltered||((o=this.root)==null||o.enqueueChangeTree(this,"changes"),n&&((a=this.root)==null||a.enqueueChangeTree(this,"allChanges")))}_checkFilteredByParent(e,t){if(!e)return;const n=Oe.isValidInstance(this.ref)?this.ref.constructor:this.ref[ne];let s,r=!Oe.isValidInstance(e);r?(s=e[R],e=s.parent,t=s.parentIndex):s=e[R];const o=e.constructor;let a=`${this.root.types.getTypeId(n)}`;o&&(a+=`-${this.root.types.schemas.get(o)}`),a+=`-${t}`;const l=Oe.hasViewTagAtIndex(o==null?void 0:o[Symbol.metadata],t);this.isFiltered=e[R].isFiltered||this.root.types.parentFiltered[a]||l,this.isFiltered&&(this.isVisibilitySharedWithParent=s.isFiltered&&typeof n!="string"&&!l&&r,this.filteredChanges||(this.filteredChanges=Qe(),this.allFilteredChanges=Qe()),this.changes.operations.length>0&&(this.changes.operations.forEach(d=>Re(this.filteredChanges,d)),this.allChanges.operations.forEach(d=>Re(this.allFilteredChanges,d)),this.changes=Qe(),this.allChanges=Qe()))}get parent(){var e;return(e=this.parentChain)==null?void 0:e.ref}get parentIndex(){var e;return(e=this.parentChain)==null?void 0:e.index}addParent(e,t){if(this.hasParent((n,s)=>n[R]===e[R])){this.parentChain.index=t;return}this.parentChain={ref:e,index:t,next:this.parentChain}}removeParent(e=this.parent){let t=this.parentChain,n=null;for(;t;){if(t.ref[R]===e[R])return n?n.next=t.next:this.parentChain=t.next,!0;n=t,t=t.next}return this.parentChain===void 0}findParent(e){let t=this.parentChain;for(;t;){if(e(t.ref,t.index))return t;t=t.next}}hasParent(e){return this.findParent(e)!==void 0}getAllParents(){const e=[];let t=this.parentChain;for(;t;)e.push({ref:t.ref,index:t.index}),t=t.next;return e}}function bs(i,e,t,n,s,r){var o;typeof t=="string"?(o=ae[t])==null||o.call(ae,e,n,r):t[Symbol.metadata]!==void 0?(ae.number(e,n[G],r),(s&k.ADD)===k.ADD&&i.tryEncodeTypeId(e,t,n.constructor,r)):ae.number(e,n[G],r)}const Yo=function(i,e,t,n,s,r,o,a,l){if(e[r.offset++]=(n|s)&255,s===k.DELETE)return;const d=t.ref,c=l[n];bs(i,e,l[n].type,d[c.name],s,r)},Es=function(i,e,t,n,s,r){if(e[r.offset++]=s&255,ae.number(e,n,r),s===k.DELETE)return;const o=t.ref;if((s&k.ADD)===k.ADD&&typeof o.set=="function"){const d=t.ref.$indexes.get(n);ae.string(e,d,r)}const a=o[ne],l=o[Fe](n);bs(i,e,a,l,s,r)},qo=function(i,e,t,n,s,r,o,a){const l=t.ref,d=a&&t.isFiltered&&typeof t.getType(n)!="string";let c;if(d){const p=l.tmpItems[n];if(!p)return;c=p[G],s===k.DELETE?s=k.DELETE_BY_REFID:s===k.ADD&&(s=k.ADD_BY_REFID)}else c=n;if(e[r.offset++]=s&255,ae.number(e,c,r),s===k.DELETE||s===k.DELETE_BY_REFID)return;const f=t.getType(n),h=t.getValue(n,o);bs(i,e,f,h,s,r)},fi=-1;function Cs(i,e,t,n,s,r,o,a){const l=i.root,d=t[Fe](n);let c;if((e&k.DELETE)===k.DELETE){const f=d==null?void 0:d[G];f!==void 0&&l.removeRef(f),e!==k.DELETE_AND_ADD&&t[Pt](n),c=void 0}if(e!==k.DELETE)if(ue.is(s)){const f=oe.number(r,o);if(c=l.refs.get(f),(e&k.ADD)===k.ADD){const h=i.getInstanceType(r,o,s);c||(c=i.createInstanceOfType(h)),l.addRef(f,c,c!==d||e===k.DELETE_AND_ADD&&c===d)}}else if(typeof s=="string")c=oe[s](r,o);else{const f=ci(Object.keys(s)[0]),h=oe.number(r,o),p=l.refs.has(h)?d||l.refs.get(h):new f.constructor;if(c=p.clone(!0),c[ne]=Object.values(s)[0],d){let m=d[G];if(m!==void 0&&h!==m){const u=d.entries();let g;for(;(g=u.next())&&!g.done;){const[b,S]=g.value;typeof S=="object"&&(m=S[G],l.removeRef(m)),a.push({ref:d,refId:m,op:k.DELETE,field:b,value:void 0,previousValue:S})}}}l.addRef(h,c,p!==d||e===k.DELETE_AND_ADD&&p===d)}return{value:c,previousValue:d}}const Jo=function(i,e,t,n,s){const r=e[t.offset++],o=n.constructor[Symbol.metadata],a=r>>6<<6,l=r%(a||255),d=o[l];if(d===void 0)return console.warn("@colyseus/schema: field not defined at",{index:l,ref:n.constructor.name,metadata:o}),fi;const{value:c,previousValue:f}=Cs(i,a,n,l,d.type,e,t,s);c!=null&&(n[d.name]=c),f!==c&&s.push({ref:n,refId:i.currentRefId,op:a,field:d.name,value:c,previousValue:f})},Ss=function(i,e,t,n,s){const r=e[t.offset++];if(r===k.CLEAR){i.removeChildRefs(n,s),n.clear();return}const o=oe.number(e,t),a=n[ne];let l;(r&k.ADD)===k.ADD?typeof n.set=="function"?(l=oe.string(e,t),n.setIndex(o,l)):l=o:l=n.getIndex(o);const{value:d,previousValue:c}=Cs(i,r,n,o,a,e,t,s);if(d!=null){if(typeof n.set=="function")n.$items.set(l,d);else if(typeof n.$setAt=="function")n.$setAt(o,d,r);else if(typeof n.add=="function"){const f=n.add(d);typeof f=="number"&&n.setIndex(f,f)}}c!==d&&s.push({ref:n,refId:i.currentRefId,op:r,field:"",dynamicIndex:l,value:d,previousValue:c})},Ko=function(i,e,t,n,s){let r=e[t.offset++],o;if(r===k.CLEAR){i.removeChildRefs(n,s),n.clear();return}else if(r===k.REVERSE){n.reverse();return}else if(r===k.DELETE_BY_REFID){const f=oe.number(e,t),h=i.root.refs.get(f);o=n.findIndex(p=>p===h),n[Pt](o),s.push({ref:n,refId:i.currentRefId,op:k.DELETE,field:"",dynamicIndex:o,value:void 0,previousValue:h});return}else if(r===k.ADD_BY_REFID){const f=oe.number(e,t),h=i.root.refs.get(f);h&&(o=n.findIndex(p=>p===h)),(o===-1||o===void 0)&&(o=n.length)}else o=oe.number(e,t);const a=n[ne];let l=o;const{value:d,previousValue:c}=Cs(i,r,n,o,a,e,t,s);d!=null&&d!==c&&n.$setAt(o,d,r),c!==d&&s.push({ref:n,refId:i.currentRefId,op:r,field:"",dynamicIndex:l,value:d,previousValue:c})};class di extends Error{}function Zo(i,e,t,n){let s,r=!1;switch(e){case"number":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":case"int64":case"uint64":case"float32":case"float64":s="number",isNaN(i)&&console.log(`trying to encode "NaN" in ${t.constructor.name}#${n}`);break;case"bigint64":case"biguint64":s="bigint";break;case"string":s="string",r=!0;break;case"boolean":return;default:return}if(typeof i!==s&&(!r||r&&i!==null)){let o=`'${JSON.stringify(i)}'${i&&i.constructor&&` (${i.constructor.name})`||""}`;throw new di(`a '${s}' was expected, but ${o} was provided in ${t.constructor.name}#${n}`)}}function $n(i,e,t,n){if(!(i instanceof e))throw new di(`a '${e.name}' was expected, but '${i&&i.constructor.name}' was provided in ${t.constructor.name}#${n}`)}const Qo=(i,e)=>{const t=i.toString(),n=e.toString();return t<n?-1:t>n?1:0};var wr,br,Er,Cr,Sr,Tr;const _e=class _e{constructor(...e){E(this,Tr);E(this,Sr);E(this,Cr);E(this,"items",[]);E(this,"tmpItems",[]);E(this,"deletedIndexes",{});E(this,"isMovingItems",!1);E(this,wr);Object.defineProperty(this,ne,{value:void 0,enumerable:!1,writable:!0,configurable:!0});const t=new Proxy(this,{get:(n,s)=>typeof s!="symbol"&&!isNaN(s)?this.items[s]:Reflect.get(n,s),set:(n,s,r)=>{var o;if(typeof s!="symbol"&&!isNaN(s)){if(r==null)n.$deleteAt(s);else{if(r[R]){$n(r,n[ne],n,s);const a=n.items[s];n.isMovingItems?(a!==void 0?r[R].isNew?n[R].indexedOperation(Number(s),k.MOVE_AND_ADD):(n[R].getChange(Number(s))&k.DELETE)===k.DELETE?n[R].indexedOperation(Number(s),k.DELETE_AND_MOVE):n[R].indexedOperation(Number(s),k.MOVE):r[R].isNew&&n[R].indexedOperation(Number(s),k.ADD),r[R].setParent(this,n[R].root,s)):n.$changeAt(Number(s),r),a!==void 0&&((o=a[R].root)==null||o.remove(a[R]))}else n.$changeAt(Number(s),r);n.items[s]=r,n.tmpItems[s]=r}return!0}else return Reflect.set(n,s,r)},deleteProperty:(n,s)=>(typeof s=="number"?n.$deleteAt(s):delete n[s],!0),has:(n,s)=>typeof s!="symbol"&&!isNaN(Number(s))?Reflect.has(this.items,s):Reflect.has(n,s)});return Object.defineProperty(this,R,{value:new wn(t),enumerable:!1,writable:!0}),e.length>0&&this.push(...e),t}static[(Tr=R,Sr=G,Cr=ne,Er=Ye,br=qe,nn)](e,t,n){var s;return!n||typeof e[ne]=="string"||n.isChangeTreeVisible((s=e.tmpItems[t])==null?void 0:s[R])}static is(e){return Array.isArray(e)||e.array!==void 0}static from(e){return new _e(...Array.from(e))}set length(e){e===0?this.clear():e<this.items.length?this.splice(e,this.length-e):console.warn("ArraySchema: can't set .length to a higher value than its length.")}get length(){return this.items.length}push(...e){var s;let t=this.tmpItems.length;const n=this[R];for(let r=0,o=e.length;r<o;r++,t++){const a=e[r];if(a==null)return;typeof a=="object"&&this[ne]&&$n(a,this[ne],this,r),n.indexedOperation(t,k.ADD,this.items.length),this.items.push(a),this.tmpItems.push(a),(s=a[R])==null||s.setParent(this,n.root,t)}return t}pop(){let e=-1;for(let t=this.tmpItems.length-1;t>=0;t--)if(this.deletedIndexes[t]!==!0){e=t;break}if(!(e<0))return this[R].delete(e,void 0,this.items.length-1),this.deletedIndexes[e]=!0,this.items.pop()}at(e){return e<0&&(e+=this.length),this.items[e]}$changeAt(e,t){var r;if(t==null){console.error("ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.");return}if(this.items[e]===t)return;const n=this.items[e]!==void 0?typeof t=="object"?k.DELETE_AND_ADD:k.REPLACE:k.ADD,s=this[R];s.change(e,n),(r=t[R])==null||r.setParent(this,s.root,e)}$deleteAt(e,t){this[R].delete(e,t)}$setAt(e,t,n){e===0&&n===k.ADD&&this.items[e]!==void 0?this.items.unshift(t):n===k.DELETE_AND_MOVE?(this.items.splice(e,1),this.items[e]=t):this.items[e]=t}clear(){if(this.items.length===0)return;const e=this[R];e.forEachChild((t,n)=>{var s;(s=e.root)==null||s.remove(t)}),e.discard(!0),e.operation(k.CLEAR),this.items.length=0,this.tmpItems.length=0}concat(...e){return new _e(...this.items.concat(...e))}join(e){return this.items.join(e)}reverse(){return this[R].operation(k.REVERSE),this.items.reverse(),this.tmpItems.reverse(),this}shift(){if(this.items.length===0)return;const e=this[R],t=this.tmpItems.findIndex(s=>s===this.items[0]),n=this.items.findIndex(s=>s===this.items[0]);return e.delete(t,k.DELETE,n),e.shiftAllChangeIndexes(-1,n),this.deletedIndexes[t]=!0,this.items.shift()}slice(e,t){const n=new _e;return n.push(...this.items.slice(e,t)),n}sort(e=Qo){this.isMovingItems=!0;const t=this[R];return this.items.sort(e).forEach((s,r)=>t.change(r,k.REPLACE)),this.tmpItems.sort(e),this.isMovingItems=!1,this}splice(e,t,...n){var d,c,f;const s=this[R],r=this.items.length,o=this.tmpItems.length,a=n.length,l=[];for(let h=0;h<o;h++)this.deletedIndexes[h]!==!0&&l.push(h);if(r>e){t===void 0&&(t=r-e);for(let h=e;h<e+t;h++){const p=l[h];s.delete(p,k.DELETE),this.deletedIndexes[p]=!0}}else t=0;if(a>0){if(a>t)throw console.error("Inserting more elements than deleting during ArraySchema#splice()"),new Error("ArraySchema#splice(): insertCount must be equal or lower than deleteCount.");for(let h=0;h<a;h++){const p=(l[e]??r)+h;s.indexedOperation(p,this.deletedIndexes[p]?k.DELETE_AND_ADD:k.ADD),(d=n[h][R])==null||d.setParent(this,s.root,p)}}return t>a&&s.shiftAllChangeIndexes(-(t-a),l[e+a]),s.filteredChanges!==void 0?(c=s.root)==null||c.enqueueChangeTree(s,"filteredChanges"):(f=s.root)==null||f.enqueueChangeTree(s,"changes"),this.items.splice(e,t,...n)}unshift(...e){const t=this[R];return t.shiftChangeIndexes(e.length),t.isFiltered?Re(t.filteredChanges,this.items.length):Re(t.allChanges,this.items.length),e.forEach((n,s)=>{t.change(s,k.ADD)}),this.tmpItems.unshift(...e),this.items.unshift(...e)}indexOf(e,t){return this.items.indexOf(e,t)}lastIndexOf(e,t=this.length-1){return this.items.lastIndexOf(e,t)}every(e,t){return this.items.every(e,t)}some(e,t){return this.items.some(e,t)}forEach(e,t){return this.items.forEach(e,t)}map(e,t){return this.items.map(e,t)}filter(e,t){return this.items.filter(e,t)}reduce(e,t){return this.items.reduce(e,t)}reduceRight(e,t){return this.items.reduceRight(e,t)}find(e,t){return this.items.find(e,t)}findIndex(e,t){return this.items.findIndex(e,t)}fill(e,t,n){throw new Error("ArraySchema#fill() not implemented")}copyWithin(e,t,n){throw new Error("ArraySchema#copyWithin() not implemented")}toString(){return this.items.toString()}toLocaleString(){return this.items.toLocaleString()}[Symbol.iterator](){return this.items[Symbol.iterator]()}static get[Symbol.species](){return _e}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}includes(e,t){return this.items.includes(e,t)}flatMap(e,t){throw new Error("ArraySchema#flatMap() is not supported.")}flat(e){throw new Error("ArraySchema#flat() is not supported.")}findLast(){return this.items.findLast.apply(this.items,arguments)}findLastIndex(...e){return this.items.findLastIndex.apply(this.items,arguments)}with(e,t){const n=this.items.slice();return e<0&&(e+=this.length),n[e]=t,new _e(...n)}toReversed(){return this.items.slice().reverse()}toSorted(e){return this.items.slice().sort(e)}toSpliced(e,t,...n){return this.items.toSpliced.apply(copy,arguments)}shuffle(){return this.move(e=>{let t=this.items.length;for(;t!=0;){let n=Math.floor(Math.random()*t);t--,[this[t],this[n]]=[this[n],this[t]]}})}move(e){return this.isMovingItems=!0,e(this),this.isMovingItems=!1,this}[(wr=Symbol.unscopables,Fe)](e,t=!1){return t?this.items[e]:this.deletedIndexes[e]?this.items[e]:this.tmpItems[e]||this.items[e]}[Pt](e){this.items[e]=void 0,this.tmpItems[e]=void 0}[Zt](){this.tmpItems=this.items.slice(),this.deletedIndexes={}}[rs](){this.items=this.items.filter(e=>e!==void 0),this.tmpItems=this.items.slice()}toArray(){return this.items.slice(0)}toJSON(){return this.toArray().map(e=>typeof e.toJSON=="function"?e.toJSON():e)}clone(e){let t;return e?(t=new _e,t.push(...this.items)):t=new _e(...this.map(n=>n[R]?n.clone():n)),t}};E(_e,Er,qo),E(_e,br,Ko);let gt=_e;xt("array",{constructor:gt});var kr,Ir,Mr,Ar,Rr;const ut=class ut{constructor(e){E(this,Rr);E(this,Ar);E(this,"childType");E(this,Mr);E(this,"$items",new Map);E(this,"$indexes",new Map);E(this,"deletedItems",{});const t=new wn(this);if(t.indexes={},Object.defineProperty(this,R,{value:t,enumerable:!1,writable:!0}),e)if(e instanceof Map||e instanceof ut)e.forEach((n,s)=>this.set(s,n));else for(const n in e)this.set(n,e[n]);Object.defineProperty(this,ne,{value:void 0,enumerable:!1,writable:!0,configurable:!0})}static[(Rr=R,Ar=G,Mr=ne,Ir=Ye,kr=qe,nn)](e,t,n){return!n||typeof e[ne]=="string"||n.isChangeTreeVisible((e[Fe](t)??e.deletedItems[t])[R])}static is(e){return e.map!==void 0}[Symbol.iterator](){return this.$items[Symbol.iterator]()}get[Symbol.toStringTag](){return this.$items[Symbol.toStringTag]}static get[Symbol.species](){return ut}set(e,t){var a;if(t==null)throw new Error(`MapSchema#set('${e}', ${t}): trying to set ${t} value on '${e}'.`);typeof t=="object"&&this[ne]&&$n(t,this[ne],this,e),e=e.toString();const n=this[R],s=t[R]!==void 0;let r,o;if(typeof n.indexes[e]<"u"){r=n.indexes[e],o=k.REPLACE;const l=this.$items.get(e);if(l===t)return;s&&(o=k.DELETE_AND_ADD,l!==void 0&&((a=l[R].root)==null||a.remove(l[R]))),this.deletedItems[r]&&delete this.deletedItems[r]}else r=n.indexes[He]??0,o=k.ADD,this.$indexes.set(r,e),n.indexes[e]=r,n.indexes[He]=r+1;return this.$items.set(e,t),n.change(r,o),s&&t[R].setParent(this,n.root,r),this}get(e){return this.$items.get(e)}delete(e){if(!this.$items.has(e))return!1;const t=this[R].indexes[e];return this.deletedItems[t]=this[R].delete(t),this.$items.delete(e)}clear(){const e=this[R];e.discard(!0),e.indexes={},e.forEachChild((t,n)=>{var s;(s=e.root)==null||s.remove(t)}),this.$indexes.clear(),this.$items.clear(),e.operation(k.CLEAR)}has(e){return this.$items.has(e)}forEach(e){this.$items.forEach(e)}entries(){return this.$items.entries()}keys(){return this.$items.keys()}values(){return this.$items.values()}get size(){return this.$items.size}setIndex(e,t){this.$indexes.set(e,t)}getIndex(e){return this.$indexes.get(e)}[Fe](e){return this.$items.get(this.$indexes.get(e))}[Pt](e){const t=this.$indexes.get(e);this.$items.delete(t),this.$indexes.delete(e)}[Zt](){const e=this[R];for(const t in this.deletedItems){const n=parseInt(t),s=this.$indexes.get(n);delete e.indexes[s],this.$indexes.delete(n)}this.deletedItems={}}toJSON(){const e={};return this.forEach((t,n)=>{e[n]=typeof t.toJSON=="function"?t.toJSON():t}),e}clone(e){let t;return e?t=Object.assign(new ut,this):(t=new ut,this.forEach((n,s)=>{n[R]?t.set(s,n.clone()):t.set(s,n)})),t}};E(ut,Ir,Es),E(ut,kr,Ss);let mt=ut;xt("map",{constructor:mt});var Dr,Br,Lr,Pr,Or;const Xt=class Xt{constructor(e){E(this,Or);E(this,Pr);E(this,Lr);E(this,"$items",new Map);E(this,"$indexes",new Map);E(this,"deletedItems",{});E(this,"$refId",0);this[R]=new wn(this),this[R].indexes={},e&&e.forEach(t=>this.add(t)),Object.defineProperty(this,ne,{value:void 0,enumerable:!1,writable:!0,configurable:!0})}static[(Or=R,Pr=G,Lr=ne,Br=Ye,Dr=qe,nn)](e,t,n){return!n||typeof e[ne]=="string"||n.isChangeTreeVisible((e[Fe](t)??e.deletedItems[t])[R])}static is(e){return e.collection!==void 0}add(e){const t=this.$refId++;return e[R]!==void 0&&e[R].setParent(this,this[R].root,t),this[R].indexes[t]=t,this.$indexes.set(t,t),this.$items.set(t,e),this[R].change(t),t}at(e){const t=Array.from(this.$items.keys())[e];return this.$items.get(t)}entries(){return this.$items.entries()}delete(e){const t=this.$items.entries();let n,s;for(;(s=t.next())&&!s.done;)if(e===s.value[1]){n=s.value[0];break}return n===void 0?!1:(this.deletedItems[n]=this[R].delete(n),this.$indexes.delete(n),this.$items.delete(n))}clear(){const e=this[R];e.discard(!0),e.indexes={},e.forEachChild((t,n)=>{var s;(s=e.root)==null||s.remove(t)}),this.$indexes.clear(),this.$items.clear(),e.operation(k.CLEAR)}has(e){return Array.from(this.$items.values()).some(t=>t===e)}forEach(e){this.$items.forEach((t,n,s)=>e(t,n,this))}values(){return this.$items.values()}get size(){return this.$items.size}[Symbol.iterator](){return this.$items.values()}setIndex(e,t){this.$indexes.set(e,t)}getIndex(e){return this.$indexes.get(e)}[Fe](e){return this.$items.get(this.$indexes.get(e))}[Pt](e){const t=this.$indexes.get(e);this.$items.delete(t),this.$indexes.delete(e)}[Zt](){this.deletedItems={}}toArray(){return Array.from(this.$items.values())}toJSON(){const e=[];return this.forEach((t,n)=>{e.push(typeof t.toJSON=="function"?t.toJSON():t)}),e}clone(e){let t;return e?t=Object.assign(new Xt,this):(t=new Xt,this.forEach(n=>{n[R]?t.add(n.clone()):t.add(n)})),t}};E(Xt,Br,Es),E(Xt,Dr,Ss);let fn=Xt;xt("collection",{constructor:fn});var Fr,$r,zr,_r,Ur;const Yt=class Yt{constructor(e){E(this,Ur);E(this,_r);E(this,zr);E(this,"$items",new Map);E(this,"$indexes",new Map);E(this,"deletedItems",{});E(this,"$refId",0);this[R]=new wn(this),this[R].indexes={},e&&e.forEach(t=>this.add(t)),Object.defineProperty(this,ne,{value:void 0,enumerable:!1,writable:!0,configurable:!0})}static[(Ur=R,_r=G,zr=ne,$r=Ye,Fr=qe,nn)](e,t,n){return!n||typeof e[ne]=="string"||n.visible.has((e[Fe](t)??e.deletedItems[t])[R])}static is(e){return e.set!==void 0}add(e){var s;if(this.has(e))return!1;const t=this.$refId++;e[R]!==void 0&&e[R].setParent(this,this[R].root,t);const n=((s=this[R].indexes[t])==null?void 0:s.op)??k.ADD;return this[R].indexes[t]=t,this.$indexes.set(t,t),this.$items.set(t,e),this[R].change(t,n),t}entries(){return this.$items.entries()}delete(e){const t=this.$items.entries();let n,s;for(;(s=t.next())&&!s.done;)if(e===s.value[1]){n=s.value[0];break}return n===void 0?!1:(this.deletedItems[n]=this[R].delete(n),this.$indexes.delete(n),this.$items.delete(n))}clear(){const e=this[R];e.discard(!0),e.indexes={},this.$indexes.clear(),this.$items.clear(),e.operation(k.CLEAR)}has(e){const t=this.$items.values();let n=!1,s;for(;(s=t.next())&&!s.done;)if(e===s.value){n=!0;break}return n}forEach(e){this.$items.forEach((t,n,s)=>e(t,n,this))}values(){return this.$items.values()}get size(){return this.$items.size}[Symbol.iterator](){return this.$items.values()}setIndex(e,t){this.$indexes.set(e,t)}getIndex(e){return this.$indexes.get(e)}[Fe](e){return this.$items.get(this.$indexes.get(e))}[Pt](e){const t=this.$indexes.get(e);this.$items.delete(t),this.$indexes.delete(e)}[Zt](){this.deletedItems={}}toArray(){return Array.from(this.$items.values())}toJSON(){const e=[];return this.forEach((t,n)=>{e.push(typeof t.toJSON=="function"?t.toJSON():t)}),e}clone(e){let t;return e?t=Object.assign(new Yt,this):(t=new Yt,this.forEach(n=>{n[R]?t.add(n.clone()):t.add(n)})),t}};E(Yt,$r,Es),E(Yt,Fr,Ss);let dn=Yt;xt("set",{constructor:dn});const Ts=-1;function ea(i=Ts){return function(e,t){var a;const n=e.constructor,r=Object.getPrototypeOf(n)[Symbol.metadata],o=n[a=Symbol.metadata]??(n[a]=Object.assign({},n[Symbol.metadata],r??Object.create(null)));Oe.setTag(o,t,i)}}function ta(i,e,t,n){return{get:function(){return this[i]},set:function(s){var o,a;const r=this[i]??void 0;if(s!==r){if(s!=null){n?(n.constructor===gt&&!(s instanceof gt)&&(s=new gt(...s)),n.constructor===mt&&!(s instanceof mt)&&(s=new mt(s)),s[ne]=t):typeof t!="string"?$n(s,t,this,i.substring(1)):Zo(s,t,this,i.substring(1));const l=this[R];r!==void 0&&r[R]?((o=l.root)==null||o.remove(r[R]),this.constructor[Jt](l,e,k.DELETE_AND_ADD)):this.constructor[Jt](l,e,k.ADD),(a=s[R])==null||a.setParent(this,l.root,e)}else r!==void 0&&this[R].delete(e);this[i]=s}},enumerable:!0,configurable:!0}}function Vn(i,e,t=ue){const n={},s={},r={},o={};for(let c in i){const f=i[c];typeof f=="object"?(f.view!==void 0&&(o[c]=typeof f.view=="boolean"?Ts:f.view),f.sync!==!1&&(n[c]=At(f)),Object.prototype.hasOwnProperty.call(f,"default")?r[c]=f.default:Array.isArray(f)||f.array!==void 0?r[c]=new gt:f.map!==void 0?r[c]=new mt:f.collection!==void 0?r[c]=new fn:f.set!==void 0?r[c]=new dn:f.type!==void 0&&ue.is(f.type)&&(!f.type.prototype.initialize||f.type.prototype.initialize.length===0)&&(r[c]=new f.type)):typeof f=="function"?ue.is(f)?((!f.prototype.initialize||f.prototype.initialize.length===0)&&(r[c]=new f),n[c]=At(f)):s[c]=f:n[c]=At(f)}const a=()=>{const c={};for(const f in r){const h=r[f];h&&typeof h.clone=="function"?c[f]=h.clone():c[f]=h}return c},l=c=>{const f=Object.keys(n),h={};for(const p in c)f.includes(p)||(h[p]=c[p]);return h},d=Oe.setFields(class extends t{constructor(...c){s.initialize&&typeof s.initialize=="function"?(super(Object.assign({},a(),l(c[0]||{}))),new.target===d&&s.initialize.apply(this,c)):super(Object.assign({},a(),c[0]||{}))}},n);d._getDefaultValues=a,Object.assign(d.prototype,s);for(let c in o)ea(o[c])(d.prototype,c);return e&&Object.defineProperty(d,"name",{value:e}),d.extends=(c,f)=>Vn(c,f,d),d}function In(i){return new Array(i).fill(0).map((e,t)=>t===i-1?"└─ ":" ").join("")}var Nr,Vr,jr,Hr;const Ge=class Ge{constructor(e){E(this,Nr);Ge.initialize(this),e&&Object.assign(this,e)}static initialize(e){var t;Object.defineProperty(e,R,{value:new wn(e),enumerable:!1,writable:!0}),Object.defineProperties(e,((t=e.constructor[Symbol.metadata])==null?void 0:t[ht])||{})}static is(e){return typeof e[Symbol.metadata]=="object"}static isSchema(e){return typeof(e==null?void 0:e.assign)=="function"}static[(Hr=Symbol.metadata,jr=Ye,Vr=qe,Nr=G,Jt)](e,t,n=k.ADD){e.change(t,n)}static[nn](e,t,n){var o,a;const r=(o=e.constructor[Symbol.metadata][t])==null?void 0:o.tag;if(n===void 0)return r===void 0;if(r===void 0)return!0;if(r===Ts)return n.isChangeTreeVisible(e[R]);{const l=(a=n.tags)==null?void 0:a.get(e[R]);return l&&l.has(r)}}assign(e){return Object.assign(this,e),this}restore(e){const t=this.constructor[Symbol.metadata];for(const n in t){const s=t[n],r=s.name,o=s.type,a=e[r];if(a!=null){if(typeof o=="string")this[r]=a;else if(Ge.is(o)){const l=new o;l.restore(a),this[r]=l}else if(typeof o=="object"){const l=Object.keys(o)[0],d=o[l];if(l==="map"){const c=this[r];for(const f in a)if(Ge.is(d)){const h=new d;h.restore(a[f]),c.set(f,h)}else c.set(f,a[f])}else if(l==="array"){const c=this[r];for(let f=0;f<a.length;f++)if(Ge.is(d)){const h=new d;h.restore(a[f]),c.push(h)}else c.push(a[f])}}}}return this}setDirty(e,t){const n=this.constructor[Symbol.metadata];this[R].change(n[n[e]].index,t)}clone(){var n;const e=Object.create(this.constructor.prototype);Ge.initialize(e);const t=this.constructor[Symbol.metadata];for(const s in t){const r=t[s].name;typeof this[r]=="object"&&typeof((n=this[r])==null?void 0:n.clone)=="function"?e[r]=this[r].clone():e[r]=this[r]}return e}toJSON(){const e={},t=this.constructor[Symbol.metadata];for(const n in t){const s=t[n],r=s.name;!s.deprecated&&this[r]!==null&&typeof this[r]<"u"&&(e[r]=typeof this[r].toJSON=="function"?this[r].toJSON():this[r])}return e}discardAllChanges(){this[R].discardAll()}[Fe](e){const t=this.constructor[Symbol.metadata];return this[t[e].name]}[Pt](e){const t=this.constructor[Symbol.metadata];this[t[e].name]=void 0}static debugRefIds(e,t=!1,n=0,s,r=""){var h;const o=t?` - ${JSON.stringify(e.toJSON())}`:"",a=e[R],l=e[G],d=s?s.root:a.root,c=((h=d==null?void 0:d.refCount)==null?void 0:h[l])>1?` [×${d.refCount[l]}]`:"";let f=`${In(n)}${r}${e.constructor.name} (refId: ${l})${c}${o}
|
|
7
|
+
`;return a.forEachChild((p,m)=>{let u=m;typeof m=="number"&&e.$indexes&&(u=e.$indexes.get(m)??m);const g=e.forEach!==void 0&&u!==void 0?`["${u}"]: `:"";f+=this.debugRefIds(p.ref,t,n+1,s,g)}),f}static debugRefIdEncodingOrder(e,t="allChanges"){let n=[],s=e[R].root[t].next;for(;s;)s.changeTree&&n.push(s.changeTree.ref[G]),s=s.next;return n}static debugRefIdsFromDecoder(e){return this.debugRefIds(e.state,!1,0,e)}static debugChanges(e,t=!1){const n=e[R],s=t?n.allChanges:n.changes,r=t?"allChanges":"changes";let o=`${e.constructor.name} (${e[G]}) -> .${r}:
|
|
8
|
+
`;function a(l){l.operations.filter(d=>d).forEach(d=>{const c=n.indexedOperations[d];o+=`- [${d}]: ${k[c]} (${JSON.stringify(n.getValue(Number(d),t))})
|
|
9
|
+
`})}return a(s),!t&&n.filteredChanges&&n.filteredChanges.operations.filter(l=>l).length>0&&(o+=`${e.constructor.name} (${e[G]}) -> .filteredChanges:
|
|
10
|
+
`,a(n.filteredChanges)),t&&n.allFilteredChanges&&n.allFilteredChanges.operations.filter(l=>l).length>0&&(o+=`${e.constructor.name} (${e[G]}) -> .allFilteredChanges:
|
|
11
|
+
`,a(n.allFilteredChanges)),o}static debugChangesDeep(e,t="changes"){var c,f;let n="";const s=e[R],r=s.root,o=new Map,a=[];let l=0;for(const[h,p]of Object.entries(r[t])){const m=r.changeTrees[h];if(!m)continue;let u=!1,g=[],b=(c=m.parent)==null?void 0:c[R];if(m===s)u=!0;else for(;b!==void 0;){if(g.push(b),b.ref===e){u=!0;break}b=(f=b.parent)==null?void 0:f[R]}u&&(a.push(m.ref[G]),l+=Object.keys(p).length,o.set(m,g.reverse()))}n+=`---
|
|
12
|
+
`,n+=`root refId: ${s.ref[G]}
|
|
13
|
+
`,n+=`Total instances: ${a.length} (refIds: ${a.join(", ")})
|
|
14
|
+
`,n+=`Total changes: ${l}
|
|
15
|
+
`,n+=`---
|
|
16
|
+
`;const d=new WeakSet;for(const[h,p]of o.entries()){p.forEach((S,C)=>{d.has(S)||(n+=`${In(C)}${S.ref.constructor.name} (refId: ${S.ref[G]})
|
|
17
|
+
`,d.add(S))});const m=h.indexedOperations,u=p.length,g=In(u),b=u>0?`(${h.parentIndex}) `:"";n+=`${g}${b}${h.ref.constructor.name} (refId: ${h.ref[G]}) - changes: ${Object.keys(m).length}
|
|
18
|
+
`;for(const S in m){const C=m[S];n+=`${In(u+1)}${k[C]}: ${S}
|
|
19
|
+
`}}return`${n}`}};E(Ge,Hr),E(Ge,jr,Yo),E(Ge,Vr,Jo);let ue=Ge;class na{constructor(e){E(this,"types");E(this,"nextUniqueId",0);E(this,"refCount",{});E(this,"changeTrees",{});E(this,"allChanges",Wt());E(this,"allFilteredChanges",Wt());E(this,"changes",Wt());E(this,"filteredChanges",Wt());this.types=e}getNextUniqueId(){return this.nextUniqueId++}add(e){const t=e.ref;t[G]===void 0&&Object.defineProperty(t,G,{value:this.getNextUniqueId(),enumerable:!1,writable:!0});const n=t[G],s=this.changeTrees[n]===void 0;s&&(this.changeTrees[n]=e);const r=this.refCount[n];if(r===0){const o=e.allChanges.operations;let a=o.length;for(;a--;)e.indexedOperations[o[a]]=k.ADD,Re(e.changes,a)}return this.refCount[n]=(r||0)+1,s}remove(e){const t=e.ref[G],n=this.refCount[t]-1;return n<=0?(e.root=void 0,delete this.changeTrees[t],this.removeChangeFromChangeSet("allChanges",e),this.removeChangeFromChangeSet("changes",e),e.filteredChanges&&(this.removeChangeFromChangeSet("allFilteredChanges",e),this.removeChangeFromChangeSet("filteredChanges",e)),this.refCount[t]=0,e.forEachChild((s,r)=>{s.removeParent(e.ref)&&(s.parentChain===void 0||s.parentChain&&this.refCount[s.ref[G]]>0?this.remove(s):s.parentChain&&this.moveNextToParent(s))})):(this.refCount[t]=n,this.recursivelyMoveNextToParent(e)),n}recursivelyMoveNextToParent(e){this.moveNextToParent(e),e.forEachChild((t,n)=>this.recursivelyMoveNextToParent(t))}moveNextToParent(e){e.filteredChanges?(this.moveNextToParentInChangeTreeList("filteredChanges",e),this.moveNextToParentInChangeTreeList("allFilteredChanges",e)):(this.moveNextToParentInChangeTreeList("changes",e),this.moveNextToParentInChangeTreeList("allChanges",e))}moveNextToParentInChangeTreeList(e,t){var d;const n=this[e],s=t[e].queueRootNode;if(!s)return;const r=t.parent;if(!r||!r[R])return;const o=(d=r[R][e])==null?void 0:d.queueRootNode;if(!o||o===s)return;const a=o.position;s.position>a||(s.prev?s.prev.next=s.next:n.next=s.next,s.next?s.next.prev=s.prev:n.tail=s.prev,s.prev=o,s.next=o.next,o.next?o.next.prev=s:n.tail=s,o.next=s,this.updatePositionsAfterMove(n,s,a+1))}enqueueChangeTree(e,t,n=e[t].queueRootNode){n||(e[t].queueRootNode=this.addToChangeTreeList(this[t],e))}addToChangeTreeList(e,t){const n={changeTree:t,next:void 0,prev:void 0,position:e.tail?e.tail.position+1:0};return e.next?(n.prev=e.tail,e.tail.next=n,e.tail=n):(e.next=n,e.tail=n),n}updatePositionsAfterRemoval(e,t){let n=e.next,s=0;for(;n;)s>=t&&(n.position=s),n=n.next,s++}updatePositionsAfterMove(e,t,n){let s=e.next,r=0;for(;s;)s.position=r,s=s.next,r++}removeChangeFromChangeSet(e,t){const n=this[e],s=t[e].queueRootNode;if(s&&s.changeTree===t){const r=s.position;return s.prev?s.prev.next=s.next:n.next=s.next,s.next?s.next.prev=s.prev:n.tail=s.prev,this.updatePositionsAfterRemoval(n,r),t[e].queueRootNode=void 0,!0}return!1}}function Xs(i,e){const t=new Uint8Array(i.length+e.length);return t.set(i,0),t.set(e,i.length),t}const qt=class qt{constructor(e){E(this,"sharedBuffer",new Uint8Array(qt.BUFFER_SIZE));E(this,"context");E(this,"state");E(this,"root");this.context=Lt.cache(e.constructor),this.root=new na(this.context),this.setState(e)}setState(e){this.state=e,this.state[R].setRoot(this.root)}encode(e={offset:0},t,n=this.sharedBuffer,s="changes",r=s==="allChanges",o=e.offset){const a=t!==void 0,l=this.state[R];let d=this.root[s];for(;d=d.next;){const c=d.changeTree;if(a){if(!t.isChangeTreeVisible(c)){t.invisible.add(c);continue}t.invisible.delete(c)}const f=c[s],h=c.ref,p=f.operations.length;if(p===0)continue;const m=h.constructor,u=m[Ye],g=m[nn],b=m[Symbol.metadata];(a||e.offset>o||c!==l)&&(n[e.offset++]=Fn&255,ae.number(n,h[G],e));for(let S=0;S<p;S++){const C=f.operations[S];if(C<0){n[e.offset++]=Math.abs(C)&255;continue}const I=r?k.ADD:c.indexedOperations[C];C===void 0||I===void 0||g&&!g(h,C,t)||u(this,n,c,C,I,e,r,a,b)}}if(e.offset>n.byteLength){const c=Math.ceil(e.offset/qt.BUFFER_SIZE)*qt.BUFFER_SIZE;console.warn(`@colyseus/schema buffer overflow. Encoded state is higher than default BUFFER_SIZE. Use the following to increase default BUFFER_SIZE:
|
|
20
|
+
|
|
21
|
+
import { Encoder } from "@colyseus/schema";
|
|
22
|
+
Encoder.BUFFER_SIZE = ${Math.round(c/1024)} * 1024; // ${Math.round(c/1024)} KB
|
|
23
|
+
`);const f=new Uint8Array(c);return f.set(n),n=f,n===this.sharedBuffer&&(this.sharedBuffer=n),this.encode({offset:o},t,n,s,r)}else return n.subarray(0,e.offset)}encodeAll(e={offset:0},t=this.sharedBuffer){return this.encode(e,void 0,t,"allChanges",!0)}encodeAllView(e,t,n,s=this.sharedBuffer){const r=n.offset;return this.encode(n,e,s,"allFilteredChanges",!0,r),Xs(s.subarray(0,t),s.subarray(r,n.offset))}encodeView(e,t,n,s=this.sharedBuffer){const r=n.offset;for(const[o,a]of e.changes){const l=this.root.changeTrees[o];if(l===void 0){e.changes.delete(o);continue}const d=Object.keys(a);if(d.length===0)continue;const c=l.ref,f=c.constructor,h=f[Ye],p=f[Symbol.metadata];s[n.offset++]=Fn&255,ae.number(s,c[G],n);for(let m=0,u=d.length;m<u;m++){const g=Number(d[m]),S=l.ref[Fe](g)!==void 0&&a[g]||k.DELETE;h(this,s,l,g,S,n,!1,!0,p)}}return e.changes.clear(),this.encode(n,e,s,"filteredChanges",!1,r),Xs(s.subarray(0,t),s.subarray(r,n.offset))}discardChanges(){let e=this.root.changes.next;for(;e;)e.changeTree.endEncode("changes"),e=e.next;for(this.root.changes=Wt(),e=this.root.filteredChanges.next;e;)e.changeTree.endEncode("filteredChanges"),e=e.next;this.root.filteredChanges=Wt()}tryEncodeTypeId(e,t,n,s){const r=this.context.getTypeId(t),o=this.context.getTypeId(n);if(o===void 0){console.warn(`@colyseus/schema WARNING: Class "${n.name}" is not registered on TypeRegistry - Please either tag the class with @entity or define a @type() field.`);return}r!==o&&(e[s.offset++]=Gr&255,ae.number(e,o,s))}get hasChanges(){return this.root.changes.next!==void 0||this.root.filteredChanges.next!==void 0}};E(qt,"BUFFER_SIZE",8*1024);let as=qt;function sa(i,e){if(e===-1||e>=i.length)return!1;const t=i.length-1;for(let n=e;n<t;n++)i[n]=i[n+1];return i.length=t,!0}class Ys extends Error{constructor(e){super(e),this.name="DecodingWarning"}}class ra{constructor(){E(this,"refs",new Map);E(this,"refCount",{});E(this,"deletedRefs",new Set);E(this,"callbacks",{});E(this,"nextUniqueId",0)}getNextUniqueId(){return this.nextUniqueId++}addRef(e,t,n=!0){this.refs.set(e,t),Object.defineProperty(t,G,{value:e,enumerable:!1,writable:!0}),n&&(this.refCount[e]=(this.refCount[e]||0)+1),this.deletedRefs.has(e)&&this.deletedRefs.delete(e)}removeRef(e){const t=this.refCount[e];if(t===void 0){try{throw new Ys("trying to remove refId that doesn't exist: "+e)}catch(n){console.warn(n)}return}if(t===0){try{const n=this.refs.get(e);throw new Ys(`trying to remove refId '${e}' with 0 refCount (${n.constructor.name}: ${JSON.stringify(n)})`)}catch(n){console.warn(n)}return}(this.refCount[e]=t-1)<=0&&this.deletedRefs.add(e)}clearRefs(){this.refs.clear(),this.deletedRefs.clear(),this.callbacks={},this.refCount={}}garbageCollectDeletedRefs(){this.deletedRefs.forEach(e=>{if(this.refCount[e]>0)return;const t=this.refs.get(e);if(t.constructor[Symbol.metadata]!==void 0){const n=t.constructor[Symbol.metadata];for(const s in n){const r=n[s].name,o=t[r];if(typeof o=="object"&&o){const a=o[G];a!==void 0&&!this.deletedRefs.has(a)&&this.removeRef(a)}}}else typeof t[ne]=="function"&&Array.from(t.values()).forEach(n=>{const s=n[G];s!==void 0&&!this.deletedRefs.has(s)&&this.removeRef(s)});this.refs.delete(e),delete this.refCount[e],delete this.callbacks[e]}),this.deletedRefs.clear()}addCallback(e,t,n){if(e===void 0){const s=typeof t=="number"?k[t]:t;throw new Error(`Can't addCallback on '${s}' (refId is undefined)`)}return this.callbacks[e]||(this.callbacks[e]={}),this.callbacks[e][t]||(this.callbacks[e][t]=[]),this.callbacks[e][t].push(n),()=>this.removeCallback(e,t,n)}removeCallback(e,t,n){var r,o,a;const s=(a=(o=(r=this.callbacks)==null?void 0:r[e])==null?void 0:o[t])==null?void 0:a.indexOf(n);s!==void 0&&s!==-1&&sa(this.callbacks[e][t],s)}}class en{constructor(e,t){E(this,"context");E(this,"state");E(this,"root");E(this,"currentRefId",0);E(this,"triggerChanges");this.setState(e),this.context=t||new Lt(e.constructor)}setState(e){this.state=e,this.root=new ra,this.root.addRef(0,e)}decode(e,t={offset:0},n=this.state){var l,d,c;const s=[],r=this.root,o=e.byteLength;let a=n.constructor[qe];for(this.currentRefId=0;t.offset<o;){if(e[t.offset]==Fn){t.offset++,(l=n[rs])==null||l.call(n);const h=oe.number(e,t),p=r.refs.get(h);p?(n=p,a=n.constructor[qe],this.currentRefId=h):(console.error(`"refId" not found: ${h}`,{previousRef:n,previousRefId:this.currentRefId}),console.warn("Please report this issue to the developers."),this.skipCurrentStructure(e,t,o));continue}if(a(this,e,t,n,s)===fi){console.warn("@colyseus/schema: definition mismatch"),this.skipCurrentStructure(e,t,o);continue}}return(d=n[rs])==null||d.call(n),(c=this.triggerChanges)==null||c.call(this,s),r.garbageCollectDeletedRefs(),s}skipCurrentStructure(e,t,n){const s={offset:t.offset};for(;t.offset<n&&!(e[t.offset]===Fn&&(s.offset=t.offset+1,this.root.refs.has(oe.number(e,s))));)t.offset++}getInstanceType(e,t,n){let s;if(e[t.offset]===Gr){t.offset++;const r=oe.number(e,t);s=this.context.get(r)}return s||n}createInstanceOfType(e){return new e}removeChildRefs(e,t){const n=typeof e[ne]!="string",s=e[G];e.forEach((r,o)=>{t.push({ref:e,refId:s,op:k.DELETE,field:o,value:void 0,previousValue:r}),n&&this.root.removeRef(r[G])})}}const hi=Vn({name:"string",type:"string",referencedType:"number"}),ui=Vn({id:"number",extendsId:"number",fields:[hi]}),tn=Vn({types:[ui],rootType:"number"});tn.encode=function(i,e={offset:0}){const t=i.context,n=new tn,s=new as(n),r=t.schemas.get(i.state.constructor);r>0&&(n.rootType=r);const o=new Set,a={},l=c=>{if(c.extendsId===void 0||o.has(c.extendsId)){o.add(c.id),n.types.push(c);const f=a[c.id];f!==void 0&&(delete a[c.id],f.forEach(h=>l(h)))}else a[c.extendsId]===void 0&&(a[c.extendsId]=[]),a[c.extendsId].push(c)};t.schemas.forEach((c,f)=>{const h=new ui;h.id=Number(c);const p=Object.getPrototypeOf(f);p!==ue&&(h.extendsId=t.schemas.get(p));const m=f[Symbol.metadata];if(m!==p[Symbol.metadata])for(const u in m){const g=Number(u),b=m[g].name;if(!Object.prototype.hasOwnProperty.call(m,b))continue;const S=new hi;S.name=b;let C;const I=m[g];if(typeof I.type=="string")C=I.type;else{let N;ue.is(I.type)?(C="ref",N=I.type):(C=Object.keys(I.type)[0],typeof I.type[C]=="string"?C+=":"+I.type[C]:N=I.type[C]),S.referencedType=N?t.getTypeId(N):-1}S.type=C,h.fields.push(S)}l(h)});for(const c in a)a[c].forEach(f=>n.types.push(f));return s.encodeAll(e).slice(0,e.offset)};tn.decode=function(i,e){const t=new tn;new en(t).decode(i,e);const s=new Lt;t.types.forEach(a=>{const l=s.get(a.extendsId)??ue,d=class extends l{};Lt.register(d),s.add(d,a.id)},{});const r=(a,l,d)=>{l.fields.forEach((c,f)=>{const h=d+f;if(c.referencedType!==void 0){let p=c.type,m=s.get(c.referencedType);if(!m){const u=c.type.split(":");p=u[0],m=u[1]}p==="ref"?Oe.addField(a,h,c.name,m):Oe.addField(a,h,c.name,{[p]:m})}else Oe.addField(a,h,c.name,c.type)})};t.types.forEach(a=>{const l=s.get(a.id),d=Oe.initialize(l),c=[];let f=a;do c.push(f),f=t.types.find(p=>p.id===f.extendsId);while(f);let h=0;c.reverse().forEach(p=>{r(d,p,h),h+=p.fields.length})});const o=new(s.get(t.rootType||0));return new en(o,s)};function qs(i){const e=i.root,t=e.callbacks,n=new WeakMap;let s;i.triggerChanges=function(a){var d;const l=new Set;for(let c=0,f=a.length;c<f;c++){const h=a[c],p=h.refId,m=h.ref,u=t[p];if(u){if((h.op&k.DELETE)===k.DELETE&&ue.isSchema(h.previousValue)){const g=(d=t[h.previousValue[G]])==null?void 0:d[k.DELETE];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b]()}if(ue.isSchema(m)){if(!l.has(p)){const g=u==null?void 0:u[k.REPLACE];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b]()}if(u.hasOwnProperty(h.field)){const g=u[h.field];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b](h.value,h.previousValue)}}else{if((h.op&k.DELETE)===k.DELETE){if(h.previousValue!==void 0){const g=u[k.DELETE];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b](h.previousValue,h.dynamicIndex??h.field)}if((h.op&k.ADD)===k.ADD){const g=u[k.ADD];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b](h.value,h.dynamicIndex??h.field)}}else if((h.op&k.ADD)===k.ADD&&h.previousValue!==h.value){const g=u[k.ADD];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b](h.value,h.dynamicIndex??h.field)}if(h.value!==h.previousValue&&(h.value!==void 0||h.previousValue!==void 0)){const g=u[k.REPLACE];for(let b=(g==null?void 0:g.length)-1;b>=0;b--)g[b](h.value,h.dynamicIndex??h.field)}}l.add(p)}}};function r(a,l){var f;let d=((f=l.instance)==null?void 0:f.constructor[Symbol.metadata])||a,c=l.instance&&typeof l.instance.forEach=="function"||a&&typeof a[Symbol.metadata]>"u";if(d&&!c){const h=function(p,m,u,g){return g&&l.instance[m]!==void 0&&!n.has(s)&&u(l.instance[m],void 0),e.addCallback(p[G],m,u)};return new Proxy({listen:function(m,u,g=!0){if(l.instance)return h(l.instance,m,u,g);{let b=()=>{};return l.onInstanceAvailable((S,C)=>{b=h(S,m,u,g&&C&&!n.has(s))}),()=>b()}},onChange:function(m){return e.addCallback(l.instance[G],k.REPLACE,m)},bindTo:function(m,u){return u||(u=Object.keys(d).map(g=>d[g].name)),e.addCallback(l.instance[G],k.REPLACE,()=>{u.forEach(g=>m[g]=l.instance[g])})}},{get(p,m){var g;const u=d[d[m]];if(u){const b=(g=l.instance)==null?void 0:g[m],S=(C=>{const I=o(l.instance).listen(m,(N,F)=>{C(N,!1),I==null||I()},!1);(b==null?void 0:b[G])!==void 0&&C(b,!0)});return r(u.type,{instance:(b==null?void 0:b[G])!==void 0&&b,parentInstance:l.instance,onInstanceAvailable:S})}else return p[m]},has(p,m){return d[m]!==void 0},set(p,m,u){throw new Error("not allowed")},deleteProperty(p,m){throw new Error("not allowed")}})}else{const h=function(u,g,b){return b&&u.forEach((S,C)=>g(S,C)),e.addCallback(u[G],k.ADD,(S,C)=>{n.set(g,!0),s=g,g(S,C),n.delete(g),s=void 0})},p=function(u,g){return e.addCallback(u[G],k.DELETE,g)},m=function(u,g){return e.addCallback(u[G],k.REPLACE,g)};return new Proxy({onAdd:function(u,g=!0){if(l.instance)return h(l.instance,u,g&&!n.has(s));if(l.onInstanceAvailable){let b=()=>{};return l.onInstanceAvailable((S,C)=>{b=h(S,u,g&&C&&!n.has(s))}),()=>b()}},onRemove:function(u){if(l.instance)return p(l.instance,u);if(l.onInstanceAvailable){let g=()=>{};return l.onInstanceAvailable(b=>{g=p(b,u)}),()=>g()}},onChange:function(u){if(l.instance)return m(l.instance,u);if(l.onInstanceAvailable){let g=()=>{};return l.onInstanceAvailable(b=>{g=m(b,u)}),()=>g()}}},{get(u,g){if(!u[g])throw new Error(`Can't access '${g}' through callback proxy. access the instance directly.`);return u[g]},has(u,g){return u[g]!==void 0},set(u,g,b){throw new Error("not allowed")},deleteProperty(u,g){throw new Error("not allowed")}})}}function o(a){return r(void 0,{instance:a})}return o}function ia(i,e){i.triggerChanges=e}class Js{constructor(e){E(this,"decoder");E(this,"uniqueRefIds",new Set);E(this,"isTriggering",!1);this.decoder=e,this.decoder.triggerChanges=this.triggerChanges.bind(this)}get callbacks(){return this.decoder.root.callbacks}get state(){return this.decoder.state}addCallback(e,t,n){return this.decoder.root.addCallback(e,t,n)}addCallbackOrWaitCollectionAvailable(e,t,n,s,r=!0){let o=()=>{};const a=()=>o(),l=e[t];if(!l||l[G]===void 0){let d;return d=this.addCallback(e[G],t,(c,f)=>{c!=null&&(d(),o=this.addCallback(c[G],n,s))}),o=d,a}else return r=r&&this.isTriggering===!1,n===k.ADD&&r&&l.forEach((d,c)=>{s(d,c)}),this.addCallback(l[G],n,s)}listen(...e){return typeof e[0]=="string"?this.listenInstance(this.state,e[0],e[1],e[2]):this.listenInstance(e[0],e[1],e[2],e[3])}listenInstance(e,t,n,s=!0){s=s&&this.isTriggering===!1;const r=e[t];return s&&r!==null&&r!==void 0&&n(r,void 0),this.addCallback(e[G],t,n)}onChange(...e){if(e.length===2&&typeof e[0]!="string"){const t=e[0],n=e[1];return this.addCallback(t[G],k.REPLACE,n)}return typeof e[0]=="string"?this.addCallbackOrWaitCollectionAvailable(this.state,e[0],k.REPLACE,e[1]):this.addCallbackOrWaitCollectionAvailable(e[0],e[1],k.REPLACE,e[2])}onAdd(...e){return typeof e[0]=="string"?this.addCallbackOrWaitCollectionAvailable(this.state,e[0],k.ADD,e[1],e[2]!==!1):this.addCallbackOrWaitCollectionAvailable(e[0],e[1],k.ADD,e[2],e[3]!==!1)}onRemove(...e){return typeof e[0]=="string"?this.addCallbackOrWaitCollectionAvailable(this.state,e[0],k.DELETE,e[1]):this.addCallbackOrWaitCollectionAvailable(e[0],e[1],k.DELETE,e[2])}bindTo(e,t,n,s=!0){const r=e.constructor[Symbol.metadata];n||(n=Object.keys(r).filter(a=>!isNaN(Number(a))).map(a=>r[a].name));const o=()=>{for(const a of n){const l=e[a];l!==void 0&&(t[a]=l)}};return s&&o(),this.addCallback(e[G],k.REPLACE,o)}triggerChanges(e){var t;this.uniqueRefIds.clear();for(let n=0,s=e.length;n<s;n++){const r=e[n],o=r.refId,a=r.ref,l=this.callbacks[o];if(l){if((r.op&k.DELETE)===k.DELETE&&ue.isSchema(r.previousValue)){const d=r.previousValue[G],c=(t=this.callbacks[d])==null?void 0:t[k.DELETE];if(c)for(let f=c.length-1;f>=0;f--)c[f]()}if(ue.isSchema(a)){if(!this.uniqueRefIds.has(o)){const c=l[k.REPLACE];if(c)for(let f=c.length-1;f>=0;f--)try{c[f]()}catch(h){console.error(h)}}const d=l[r.field];if(d)for(let c=d.length-1;c>=0;c--)try{this.isTriggering=!0,d[c](r.value,r.previousValue)}catch(f){console.error(f)}finally{this.isTriggering=!1}}else{const d=r.dynamicIndex??r.field;if((r.op&k.DELETE)===k.DELETE){if(r.previousValue!==void 0){const c=l[k.DELETE];if(c)for(let f=c.length-1;f>=0;f--)c[f](r.previousValue,d)}if((r.op&k.ADD)===k.ADD){const c=l[k.ADD];if(c){this.isTriggering=!0;for(let f=c.length-1;f>=0;f--)c[f](r.value,d);this.isTriggering=!1}}}else if((r.op&k.ADD)===k.ADD&&r.previousValue!==r.value){const c=l[k.ADD];if(c){this.isTriggering=!0;for(let f=c.length-1;f>=0;f--)c[f](r.value,d);this.isTriggering=!1}}if(r.value!==r.previousValue){const c=l[k.REPLACE];if(c)for(let f=c.length-1;f>=0;f--)c[f](d,r.value)}}this.uniqueRefIds.add(o)}}}}const oa={get(i){if(i instanceof en)return new Js(i);if("decoder"in i.serializer)return new Js(i.serializer.decoder);throw new Error("Invalid room or decoder")},getLegacy(i){if(i instanceof en)return qs(i);if("decoder"in i.serializer)return qs(i.serializer.decoder)},getRawChanges(i,e){return ia(i,e)}};xt("map",{constructor:mt});xt("array",{constructor:gt});xt("set",{constructor:dn});xt("collection",{constructor:fn});var ls;try{ls=new TextDecoder}catch{}var O,Je,y=0,re={},Q,pt,Be=0,Xe=0,me,rt,Me=[],Z,Ks={useRecords:!1,mapsAsObjects:!0};class pi{}const gi=new pi;gi.name="MessagePack 0xC1";var yt=!1,mi=2,aa;try{new Function("")}catch{mi=1/0}class hn{constructor(e){e&&(e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.sequential&&e.trusted!==!1&&(e.trusted=!0,!e.structures&&e.useRecords!=!1&&(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,t){if(O)return Ei(()=>(fs(),this?this.unpack(e,t):hn.prototype.unpack.call(Ks,e,t)));!e.buffer&&e.constructor===ArrayBuffer&&(e=typeof Buffer<"u"?Buffer.from(e):new Uint8Array(e)),typeof t=="object"?(Je=t.end||e.length,y=t.start||0):(y=0,Je=t>-1?t:e.length),Xe=0,pt=null,me=null,O=e;try{Z=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(n){throw O=null,e instanceof Uint8Array?n:new Error("Source must be a Uint8Array or Buffer but was a "+(e&&typeof e=="object"?e.constructor.name:typeof e))}if(this instanceof hn){if(re=this,this.structures)return Q=this.structures,Mn(t);(!Q||Q.length>0)&&(Q=[])}else re=Ks,(!Q||Q.length>0)&&(Q=[]);return Mn(t)}unpackMultiple(e,t){let n,s=0;try{yt=!0;let r=e.length,o=this?this.unpack(e,r):jn.unpack(e,r);if(t){if(t(o,s,y)===!1)return;for(;y<r;)if(s=y,t(Mn(),s,y)===!1)return}else{for(n=[o];y<r;)s=y,n.push(Mn());return n}}catch(r){throw r.lastPosition=s,r.values=n,r}finally{yt=!1,fs()}}_mergeStructures(e,t){e=e||[],Object.isFrozen(e)&&(e=e.map(n=>n.slice(0)));for(let n=0,s=e.length;n<s;n++){let r=e[n];r&&(r.isShared=!0,n>=32&&(r.highByte=n-32>>5))}e.sharedLength=e.length;for(let n in t||[])if(n>=0){let s=e[n],r=t[n];r&&(s&&((e.restoreStructures||(e.restoreStructures=[]))[n]=s),e[n]=r)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}function Mn(i){try{if(!re.trusted&&!yt){let t=Q.sharedLength||0;t<Q.length&&(Q.length=t)}let e;if(re.randomAccessStructure&&O[y]<64&&O[y]>=32&&aa||(e=he()),me&&(y=me.postBundlePosition,me=null),yt&&(Q.restoreStructures=null),y==Je)Q&&Q.restoreStructures&&Zs(),Q=null,O=null,rt&&(rt=null);else{if(y>Je)throw new Error("Unexpected end of MessagePack data");if(!yt){let t;try{t=JSON.stringify(e,(n,s)=>typeof s=="bigint"?`${s}n`:s).slice(0,100)}catch(n){t="(JSON view not available "+n+")"}throw new Error("Data read, but end of buffer not reached "+t)}}return e}catch(e){throw Q&&Q.restoreStructures&&Zs(),fs(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||y>Je)&&(e.incomplete=!0),e}}function Zs(){for(let i in Q.restoreStructures)Q[i]=Q.restoreStructures[i];Q.restoreStructures=null}function he(){let i=O[y++];if(i<160)if(i<128){if(i<64)return i;{let e=Q[i&63]||re.getStructures&&yi()[i&63];return e?(e.read||(e.read=ks(e,i&63)),e.read()):i}}else if(i<144)if(i-=128,re.mapsAsObjects){let e={};for(let t=0;t<i;t++){let n=vi();n==="__proto__"&&(n="__proto_"),e[n]=he()}return e}else{let e=new Map;for(let t=0;t<i;t++)e.set(he(),he());return e}else{i-=144;let e=new Array(i);for(let t=0;t<i;t++)e[t]=he();return re.freezeData?Object.freeze(e):e}else if(i<192){let e=i-160;if(Xe>=y)return pt.slice(y-Be,(y+=e)-Be);if(Xe==0&&Je<140){let t=e<16?Is(e):xi(e);if(t!=null)return t}return cs(e)}else{let e;switch(i){case 192:return null;case 193:return me?(e=he(),e>0?me[1].slice(me.position1,me.position1+=e):me[0].slice(me.position0,me.position0-=e)):gi;case 194:return!1;case 195:return!0;case 196:if(e=O[y++],e===void 0)throw new Error("Unexpected end of buffer");return Jn(e);case 197:return e=Z.getUint16(y),y+=2,Jn(e);case 198:return e=Z.getUint32(y),y+=4,Jn(e);case 199:return St(O[y++]);case 200:return e=Z.getUint16(y),y+=2,St(e);case 201:return e=Z.getUint32(y),y+=4,St(e);case 202:if(e=Z.getFloat32(y),re.useFloat32>2){let t=Ms[(O[y]&127)<<1|O[y+1]>>7];return y+=4,(t*e+(e>0?.5:-.5)>>0)/t}return y+=4,e;case 203:return e=Z.getFloat64(y),y+=8,e;case 204:return O[y++];case 205:return e=Z.getUint16(y),y+=2,e;case 206:return e=Z.getUint32(y),y+=4,e;case 207:return re.int64AsType==="number"?(e=Z.getUint32(y)*4294967296,e+=Z.getUint32(y+4)):re.int64AsType==="string"?e=Z.getBigUint64(y).toString():re.int64AsType==="auto"?(e=Z.getBigUint64(y),e<=BigInt(2)<<BigInt(52)&&(e=Number(e))):e=Z.getBigUint64(y),y+=8,e;case 208:return Z.getInt8(y++);case 209:return e=Z.getInt16(y),y+=2,e;case 210:return e=Z.getInt32(y),y+=4,e;case 211:return re.int64AsType==="number"?(e=Z.getInt32(y)*4294967296,e+=Z.getUint32(y+4)):re.int64AsType==="string"?e=Z.getBigInt64(y).toString():re.int64AsType==="auto"?(e=Z.getBigInt64(y),e>=BigInt(-2)<<BigInt(52)&&e<=BigInt(2)<<BigInt(52)&&(e=Number(e))):e=Z.getBigInt64(y),y+=8,e;case 212:if(e=O[y++],e==114)return rr(O[y++]&63);{let t=Me[e];if(t)return t.read?(y++,t.read(he())):t.noBuffer?(y++,t()):t(O.subarray(y,++y));throw new Error("Unknown extension "+e)}case 213:return e=O[y],e==114?(y++,rr(O[y++]&63,O[y++])):St(2);case 214:return St(4);case 215:return St(8);case 216:return St(16);case 217:return e=O[y++],Xe>=y?pt.slice(y-Be,(y+=e)-Be):ca(e);case 218:return e=Z.getUint16(y),y+=2,Xe>=y?pt.slice(y-Be,(y+=e)-Be):fa(e);case 219:return e=Z.getUint32(y),y+=4,Xe>=y?pt.slice(y-Be,(y+=e)-Be):da(e);case 220:return e=Z.getUint16(y),y+=2,er(e);case 221:return e=Z.getUint32(y),y+=4,er(e);case 222:return e=Z.getUint16(y),y+=2,tr(e);case 223:return e=Z.getUint32(y),y+=4,tr(e);default:if(i>=224)return i-256;if(i===void 0){let t=new Error("Unexpected end of MessagePack data");throw t.incomplete=!0,t}throw new Error("Unknown MessagePack token "+i)}}}const la=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function ks(i,e){function t(){if(t.count++>mi){let s=i.read=new Function("r","return function(){return "+(re.freezeData?"Object.freeze":"")+"({"+i.map(r=>r==="__proto__"?"__proto_:r()":la.test(r)?r+":r()":"["+JSON.stringify(r)+"]:r()").join(",")+"})}")(he);return i.highByte===0&&(i.read=Qs(e,i.read)),s()}let n={};for(let s=0,r=i.length;s<r;s++){let o=i[s];o==="__proto__"&&(o="__proto_"),n[o]=he()}return re.freezeData?Object.freeze(n):n}return t.count=0,i.highByte===0?Qs(e,t):t}const Qs=(i,e)=>function(){let t=O[y++];if(t===0)return e();let n=i<32?-(i+(t<<5)):i+(t<<5),s=Q[n]||yi()[n];if(!s)throw new Error("Record id is not defined for "+n);return s.read||(s.read=ks(s,i)),s.read()};function yi(){let i=Ei(()=>(O=null,re.getStructures()));return Q=re._mergeStructures(i,Q)}var cs=bn,ca=bn,fa=bn,da=bn;function bn(i){let e;if(i<16&&(e=Is(i)))return e;if(i>64&&ls)return ls.decode(O.subarray(y,y+=i));const t=y+i,n=[];for(e="";y<t;){const s=O[y++];if((s&128)===0)n.push(s);else if((s&224)===192){const r=O[y++]&63;n.push((s&31)<<6|r)}else if((s&240)===224){const r=O[y++]&63,o=O[y++]&63;n.push((s&31)<<12|r<<6|o)}else if((s&248)===240){const r=O[y++]&63,o=O[y++]&63,a=O[y++]&63;let l=(s&7)<<18|r<<12|o<<6|a;l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|l&1023),n.push(l)}else n.push(s);n.length>=4096&&(e+=ge.apply(String,n),n.length=0)}return n.length>0&&(e+=ge.apply(String,n)),e}function er(i){let e=new Array(i);for(let t=0;t<i;t++)e[t]=he();return re.freezeData?Object.freeze(e):e}function tr(i){if(re.mapsAsObjects){let e={};for(let t=0;t<i;t++){let n=vi();n==="__proto__"&&(n="__proto_"),e[n]=he()}return e}else{let e=new Map;for(let t=0;t<i;t++)e.set(he(),he());return e}}var ge=String.fromCharCode;function xi(i){let e=y,t=new Array(i);for(let n=0;n<i;n++){const s=O[y++];if((s&128)>0){y=e;return}t[n]=s}return ge.apply(String,t)}function Is(i){if(i<4)if(i<2){if(i===0)return"";{let e=O[y++];if((e&128)>1){y-=1;return}return ge(e)}}else{let e=O[y++],t=O[y++];if((e&128)>0||(t&128)>0){y-=2;return}if(i<3)return ge(e,t);let n=O[y++];if((n&128)>0){y-=3;return}return ge(e,t,n)}else{let e=O[y++],t=O[y++],n=O[y++],s=O[y++];if((e&128)>0||(t&128)>0||(n&128)>0||(s&128)>0){y-=4;return}if(i<6){if(i===4)return ge(e,t,n,s);{let r=O[y++];if((r&128)>0){y-=5;return}return ge(e,t,n,s,r)}}else if(i<8){let r=O[y++],o=O[y++];if((r&128)>0||(o&128)>0){y-=6;return}if(i<7)return ge(e,t,n,s,r,o);let a=O[y++];if((a&128)>0){y-=7;return}return ge(e,t,n,s,r,o,a)}else{let r=O[y++],o=O[y++],a=O[y++],l=O[y++];if((r&128)>0||(o&128)>0||(a&128)>0||(l&128)>0){y-=8;return}if(i<10){if(i===8)return ge(e,t,n,s,r,o,a,l);{let d=O[y++];if((d&128)>0){y-=9;return}return ge(e,t,n,s,r,o,a,l,d)}}else if(i<12){let d=O[y++],c=O[y++];if((d&128)>0||(c&128)>0){y-=10;return}if(i<11)return ge(e,t,n,s,r,o,a,l,d,c);let f=O[y++];if((f&128)>0){y-=11;return}return ge(e,t,n,s,r,o,a,l,d,c,f)}else{let d=O[y++],c=O[y++],f=O[y++],h=O[y++];if((d&128)>0||(c&128)>0||(f&128)>0||(h&128)>0){y-=12;return}if(i<14){if(i===12)return ge(e,t,n,s,r,o,a,l,d,c,f,h);{let p=O[y++];if((p&128)>0){y-=13;return}return ge(e,t,n,s,r,o,a,l,d,c,f,h,p)}}else{let p=O[y++],m=O[y++];if((p&128)>0||(m&128)>0){y-=14;return}if(i<15)return ge(e,t,n,s,r,o,a,l,d,c,f,h,p,m);let u=O[y++];if((u&128)>0){y-=15;return}return ge(e,t,n,s,r,o,a,l,d,c,f,h,p,m,u)}}}}}function nr(){let i=O[y++],e;if(i<192)e=i-160;else switch(i){case 217:e=O[y++];break;case 218:e=Z.getUint16(y),y+=2;break;case 219:e=Z.getUint32(y),y+=4;break;default:throw new Error("Expected string")}return bn(e)}function Jn(i){return re.copyBuffers?Uint8Array.prototype.slice.call(O,y,y+=i):O.subarray(y,y+=i)}function St(i){let e=O[y++];if(Me[e]){let t;return Me[e](O.subarray(y,t=y+=i),n=>{y=n;try{return he()}finally{y=t}})}else throw new Error("Unknown extension type "+e)}var sr=new Array(4096);function vi(){let i=O[y++];if(i>=160&&i<192){if(i=i-160,Xe>=y)return pt.slice(y-Be,(y+=i)-Be);if(!(Xe==0&&Je<180))return cs(i)}else return y--,wi(he());let e=(i<<5^(i>1?Z.getUint16(y):i>0?O[y]:0))&4095,t=sr[e],n=y,s=y+i-3,r,o=0;if(t&&t.bytes==i){for(;n<s;){if(r=Z.getUint32(n),r!=t[o++]){n=1879048192;break}n+=4}for(s+=3;n<s;)if(r=O[n++],r!=t[o++]){n=1879048192;break}if(n===s)return y=n,t.string;s-=3,n=y}for(t=[],sr[e]=t,t.bytes=i;n<s;)r=Z.getUint32(n),t.push(r),n+=4;for(s+=3;n<s;)r=O[n++],t.push(r);let a=i<16?Is(i):xi(i);return a!=null?t.string=a:t.string=cs(i)}function wi(i){if(typeof i=="string")return i;if(typeof i=="number"||typeof i=="boolean"||typeof i=="bigint")return i.toString();if(i==null)return i+"";if(re.allowArraysInMapKeys&&Array.isArray(i)&&i.flat().every(e=>["string","number","boolean","bigint"].includes(typeof e)))return i.flat().toString();throw new Error(`Invalid property type for record: ${typeof i}`)}const rr=(i,e)=>{let t=he().map(wi),n=i;e!==void 0&&(i=i<32?-((e<<5)+i):(e<<5)+i,t.highByte=e);let s=Q[i];return s&&(s.isShared||yt)&&((Q.restoreStructures||(Q.restoreStructures=[]))[i]=s),Q[i]=t,t.read=ks(t,n),t.read()};Me[0]=()=>{};Me[0].noBuffer=!0;Me[66]=i=>{let e=i.length,t=BigInt(i[0]&128?i[0]-256:i[0]);for(let n=1;n<e;n++)t<<=BigInt(8),t+=BigInt(i[n]);return t};let ha={Error,TypeError,ReferenceError};Me[101]=()=>{let i=he();return(ha[i[0]]||Error)(i[1],{cause:i[2]})};Me[105]=i=>{if(re.structuredClone===!1)throw new Error("Structured clone extension is disabled");let e=Z.getUint32(y-4);rt||(rt=new Map);let t=O[y],n;t>=144&&t<160||t==220||t==221?n=[]:n={};let s={target:n};rt.set(e,s);let r=he();return s.used?Object.assign(n,r):(s.target=r,r)};Me[112]=i=>{if(re.structuredClone===!1)throw new Error("Structured clone extension is disabled");let e=Z.getUint32(y-4),t=rt.get(e);return t.used=!0,t.target};Me[115]=()=>new Set(he());const bi=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(i=>i+"Array");let ua=typeof globalThis=="object"?globalThis:window;Me[116]=i=>{let e=i[0],t=bi[e];if(!t){if(e===16){let n=new ArrayBuffer(i.length-1);return new Uint8Array(n).set(i.subarray(1)),n}throw new Error("Could not find typed array for code "+e)}return new ua[t](Uint8Array.prototype.slice.call(i,1).buffer)};Me[120]=()=>{let i=he();return new RegExp(i[0],i[1])};const pa=[];Me[98]=i=>{let e=(i[0]<<24)+(i[1]<<16)+(i[2]<<8)+i[3],t=y;return y+=e-i.length,me=pa,me=[nr(),nr()],me.position0=0,me.position1=0,me.postBundlePosition=y,y=t,he()};Me[255]=i=>i.length==4?new Date((i[0]*16777216+(i[1]<<16)+(i[2]<<8)+i[3])*1e3):i.length==8?new Date(((i[0]<<22)+(i[1]<<14)+(i[2]<<6)+(i[3]>>2))/1e6+((i[3]&3)*4294967296+i[4]*16777216+(i[5]<<16)+(i[6]<<8)+i[7])*1e3):i.length==12?new Date(((i[0]<<24)+(i[1]<<16)+(i[2]<<8)+i[3])/1e6+((i[4]&128?-281474976710656:0)+i[6]*1099511627776+i[7]*4294967296+i[8]*16777216+(i[9]<<16)+(i[10]<<8)+i[11])*1e3):new Date("invalid");function Ei(i){let e=Je,t=y,n=Be,s=Xe,r=pt,o=rt,a=me,l=new Uint8Array(O.slice(0,Je)),d=Q,c=Q.slice(0,Q.length),f=re,h=yt,p=i();return Je=e,y=t,Be=n,Xe=s,pt=r,rt=o,me=a,O=l,yt=h,Q=d,Q.splice(0,Q.length,...c),re=f,Z=new DataView(O.buffer,O.byteOffset,O.byteLength),p}function fs(){O=null,rt=null,Q=null}const Ms=new Array(147);for(let i=0;i<256;i++)Ms[i]=+("1e"+Math.floor(45.15-i*.30103));var jn=new hn({useRecords:!1});const ga=jn.unpack;jn.unpackMultiple;jn.unpack;let ma=new Float32Array(1);new Uint8Array(ma.buffer,0,4);let Bn;try{Bn=new TextEncoder}catch{}let ds,Ci;const Hn=typeof Buffer<"u",An=Hn?function(i){return Buffer.allocUnsafeSlow(i)}:Uint8Array,Si=Hn?Buffer:Uint8Array,ir=Hn?4294967296:2144337920;let v,rn,se,x=0,Ce,ce=null,ya;const xa=21760,va=/[\u0080-\uFFFF]/,Vt=Symbol("record-id");class Ti extends hn{constructor(e){super(e),this.offset=0;let t,n,s,r,o=Si.prototype.utf8Write?function(w,P){return v.utf8Write(w,P,v.byteLength-P)}:Bn&&Bn.encodeInto?function(w,P){return Bn.encodeInto(w,v.subarray(P)).written}:!1,a=this;e||(e={});let l=e&&e.sequential,d=e.structures||e.saveStructures,c=e.maxSharedStructures;if(c==null&&(c=d?32:0),c>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&e.moreTypes==null&&(this.moreTypes=!0);let f=e.maxOwnStructures;f==null&&(f=d?32:64),!this.structures&&e.useRecords!=!1&&(this.structures=[]);let h=c>32||f+c>64,p=c+64,m=c+f+64;if(m>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let u=[],g=0,b=0;this.pack=this.encode=function(w,P){if(v||(v=new An(8192),se=v.dataView||(v.dataView=new DataView(v.buffer,0,8192)),x=0),Ce=v.length-10,Ce-x<2048?(v=new An(v.length),se=v.dataView||(v.dataView=new DataView(v.buffer,0,v.length)),Ce=v.length-10,x=0):x=x+7&2147483640,t=x,P&Ta&&(x+=P&255),r=a.structuredClone?new Map:null,a.bundleStrings&&typeof w!="string"?(ce=[],ce.size=1/0):ce=null,s=a.structures,s){s.uninitialized&&(s=a._mergeStructures(a.getStructures()));let T=s.sharedLength||0;if(T>c)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+s.sharedLength);if(!s.transitions){s.transitions=Object.create(null);for(let L=0;L<T;L++){let _=s[L];if(!_)continue;let V,U=s.transitions;for(let z=0,X=_.length;z<X;z++){let le=_[z];V=U[le],V||(V=U[le]=Object.create(null)),U=V}U[Vt]=L+64}this.lastNamedStructuresLength=T}l||(s.nextId=T+64)}n&&(n=!1);let M;try{a.randomAccessStructure&&w&&w.constructor&&w.constructor===Object?ve(w):I(w);let T=ce;if(ce&&lr(t,I,0),r&&r.idsToInsert){let L=r.idsToInsert.sort((z,X)=>z.offset>X.offset?1:-1),_=L.length,V=-1;for(;T&&_>0;){let z=L[--_].offset+t;z<T.stringsPosition+t&&V===-1&&(V=0),z>T.position+t?V>=0&&(V+=6):(V>=0&&(se.setUint32(T.position+t,se.getUint32(T.position+t)+V),V=-1),T=T.previous,_++)}V>=0&&T&&se.setUint32(T.position+t,se.getUint32(T.position+t)+V),x+=L.length*6,x>Ce&&K(x),a.offset=x;let U=ba(v.subarray(t,x),L);return r=null,U}return a.offset=x,P&Ca?(v.start=t,v.end=x,v):v.subarray(t,x)}catch(T){throw M=T,T}finally{if(s&&(S(),n&&a.saveStructures)){let T=s.sharedLength||0,L=v.subarray(t,x),_=Ea(s,a);if(!M)return a.saveStructures(_,_.isCompatible)===!1?a.pack(w,P):(a.lastNamedStructuresLength=T,v.length>1073741824&&(v=null),L)}v.length>1073741824&&(v=null),P&Sa&&(x=t)}};const S=()=>{b<10&&b++;let w=s.sharedLength||0;if(s.length>w&&!l&&(s.length=w),g>1e4)s.transitions=null,b=0,g=0,u.length>0&&(u=[]);else if(u.length>0&&!l){for(let P=0,M=u.length;P<M;P++)u[P][Vt]=0;u=[]}},C=w=>{var P=w.length;P<16?v[x++]=144|P:P<65536?(v[x++]=220,v[x++]=P>>8,v[x++]=P&255):(v[x++]=221,se.setUint32(x,P),x+=4);for(let M=0;M<P;M++)I(w[M])},I=w=>{x>Ce&&(v=K(x));var P=typeof w,M;if(P==="string"){let T=w.length;if(ce&&T>=4&&T<4096){if((ce.size+=T)>xa){let U,z=(ce[0]?ce[0].length*3+ce[1].length:0)+10;x+z>Ce&&(v=K(x+z));let X;ce.position?(X=ce,v[x]=200,x+=3,v[x++]=98,U=x-t,x+=4,lr(t,I,0),se.setUint16(U+t-3,x-t-U)):(v[x++]=214,v[x++]=98,U=x-t,x+=4),ce=["",""],ce.previous=X,ce.size=0,ce.position=U}let V=va.test(w);ce[V?0:1]+=w,v[x++]=193,I(V?-T:T);return}let L;T<32?L=1:T<256?L=2:T<65536?L=3:L=5;let _=T*3;if(x+_>Ce&&(v=K(x+_)),T<64||!o){let V,U,z,X=x+L;for(V=0;V<T;V++)U=w.charCodeAt(V),U<128?v[X++]=U:U<2048?(v[X++]=U>>6|192,v[X++]=U&63|128):(U&64512)===55296&&((z=w.charCodeAt(V+1))&64512)===56320?(U=65536+((U&1023)<<10)+(z&1023),V++,v[X++]=U>>18|240,v[X++]=U>>12&63|128,v[X++]=U>>6&63|128,v[X++]=U&63|128):(v[X++]=U>>12|224,v[X++]=U>>6&63|128,v[X++]=U&63|128);M=X-x-L}else M=o(w,x+L);M<32?v[x++]=160|M:M<256?(L<2&&v.copyWithin(x+2,x+1,x+1+M),v[x++]=217,v[x++]=M):M<65536?(L<3&&v.copyWithin(x+3,x+2,x+2+M),v[x++]=218,v[x++]=M>>8,v[x++]=M&255):(L<5&&v.copyWithin(x+5,x+3,x+3+M),v[x++]=219,se.setUint32(x,M),x+=4),x+=M}else if(P==="number")if(w>>>0===w)w<32||w<128&&this.useRecords===!1||w<64&&!this.randomAccessStructure?v[x++]=w:w<256?(v[x++]=204,v[x++]=w):w<65536?(v[x++]=205,v[x++]=w>>8,v[x++]=w&255):(v[x++]=206,se.setUint32(x,w),x+=4);else if(w>>0===w)w>=-32?v[x++]=256+w:w>=-128?(v[x++]=208,v[x++]=w+256):w>=-32768?(v[x++]=209,se.setInt16(x,w),x+=2):(v[x++]=210,se.setInt32(x,w),x+=4);else{let T;if((T=this.useFloat32)>0&&w<4294967296&&w>=-2147483648){v[x++]=202,se.setFloat32(x,w);let L;if(T<4||(L=w*Ms[(v[x]&127)<<1|v[x+1]>>7])>>0===L){x+=4;return}else x--}v[x++]=203,se.setFloat64(x,w),x+=8}else if(P==="object"||P==="function")if(!w)v[x++]=192;else{if(r){let L=r.get(w);if(L){if(!L.id){let _=r.idsToInsert||(r.idsToInsert=[]);L.id=_.push(L)}v[x++]=214,v[x++]=112,se.setUint32(x,L.id),x+=4;return}else r.set(w,{offset:x-t})}let T=w.constructor;if(T===Object)$(w);else if(T===Array)C(w);else if(T===Map)if(this.mapAsEmptyObject)v[x++]=128;else{M=w.size,M<16?v[x++]=128|M:M<65536?(v[x++]=222,v[x++]=M>>8,v[x++]=M&255):(v[x++]=223,se.setUint32(x,M),x+=4);for(let[L,_]of w)I(L),I(_)}else{for(let L=0,_=ds.length;L<_;L++){let V=Ci[L];if(w instanceof V){let U=ds[L];if(U.write){U.type&&(v[x++]=212,v[x++]=U.type,v[x++]=0);let ke=U.write.call(this,w);ke===w?Array.isArray(w)?C(w):$(w):I(ke);return}let z=v,X=se,le=x;v=null;let we;try{we=U.pack.call(this,w,ke=>(v=z,z=null,x+=ke,x>Ce&&K(x),{target:v,targetView:se,position:x-ke}),I)}finally{z&&(v=z,se=X,x=le,Ce=v.length-10)}we&&(we.length+x>Ce&&K(we.length+x),x=wa(we,v,x,U.type));return}}if(Array.isArray(w))C(w);else{if(w.toJSON){const L=w.toJSON();if(L!==w)return I(L)}if(P==="function")return I(this.writeFunction&&this.writeFunction(w));$(w)}}}else if(P==="boolean")v[x++]=w?195:194;else if(P==="bigint"){if(w<BigInt(1)<<BigInt(63)&&w>=-(BigInt(1)<<BigInt(63)))v[x++]=211,se.setBigInt64(x,w);else if(w<BigInt(1)<<BigInt(64)&&w>0)v[x++]=207,se.setBigUint64(x,w);else if(this.largeBigIntToFloat)v[x++]=203,se.setFloat64(x,Number(w));else{if(this.largeBigIntToString)return I(w.toString());if(this.useBigIntExtension&&w<BigInt(2)**BigInt(1023)&&w>-(BigInt(2)**BigInt(1023))){v[x++]=199,x++,v[x++]=66;let T=[],L;do{let _=w&BigInt(255);L=(_&BigInt(128))===(w<BigInt(0)?BigInt(128):BigInt(0)),T.push(_),w>>=BigInt(8)}while(!((w===BigInt(0)||w===BigInt(-1))&&L));v[x-2]=T.length;for(let _=T.length;_>0;)v[x++]=Number(T[--_]);return}else throw new RangeError(w+" 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")}x+=8}else if(P==="undefined")this.encodeUndefinedAsNil?v[x++]=192:(v[x++]=212,v[x++]=0,v[x++]=0);else throw new Error("Unknown type: "+P)},N=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?w=>{let P;if(this.skipValues){P=[];for(let L in w)(typeof w.hasOwnProperty!="function"||w.hasOwnProperty(L))&&!this.skipValues.includes(w[L])&&P.push(L)}else P=Object.keys(w);let M=P.length;M<16?v[x++]=128|M:M<65536?(v[x++]=222,v[x++]=M>>8,v[x++]=M&255):(v[x++]=223,se.setUint32(x,M),x+=4);let T;if(this.coercibleKeyAsNumber)for(let L=0;L<M;L++){T=P[L];let _=Number(T);I(isNaN(_)?T:_),I(w[T])}else for(let L=0;L<M;L++)I(T=P[L]),I(w[T])}:w=>{v[x++]=222;let P=x-t;x+=2;let M=0;for(let T in w)(typeof w.hasOwnProperty!="function"||w.hasOwnProperty(T))&&(I(T),I(w[T]),M++);if(M>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');v[P+++t]=M>>8,v[P+t]=M&255},F=this.useRecords===!1?N:e.progressiveRecords&&!h?w=>{let P,M=s.transitions||(s.transitions=Object.create(null)),T=x++-t,L;for(let _ in w)if(typeof w.hasOwnProperty!="function"||w.hasOwnProperty(_)){if(P=M[_],P)M=P;else{let V=Object.keys(w),U=M;M=s.transitions;let z=0;for(let X=0,le=V.length;X<le;X++){let we=V[X];P=M[we],P||(P=M[we]=Object.create(null),z++),M=P}T+t+1==x?(x--,j(M,V,z)):Y(M,V,T,z),L=!0,M=U[_]}I(w[_])}if(!L){let _=M[Vt];_?v[T+t]=_:Y(M,Object.keys(w),T,0)}}:w=>{let P,M=s.transitions||(s.transitions=Object.create(null)),T=0;for(let _ in w)(typeof w.hasOwnProperty!="function"||w.hasOwnProperty(_))&&(P=M[_],P||(P=M[_]=Object.create(null),T++),M=P);let L=M[Vt];L?L>=96&&h?(v[x++]=((L-=96)&31)+96,v[x++]=L>>5):v[x++]=L:j(M,M.__keys__||Object.keys(w),T);for(let _ in w)(typeof w.hasOwnProperty!="function"||w.hasOwnProperty(_))&&I(w[_])},H=typeof this.useRecords=="function"&&this.useRecords,$=H?w=>{H(w)?F(w):N(w)}:F,K=w=>{let P;if(w>16777216){if(w-t>ir)throw new Error("Packed buffer would be larger than maximum buffer size");P=Math.min(ir,Math.round(Math.max((w-t)*(w>67108864?1.25:2),4194304)/4096)*4096)}else P=(Math.max(w-t<<2,v.length-1)>>12)+1<<12;let M=new An(P);return se=M.dataView||(M.dataView=new DataView(M.buffer,0,P)),w=Math.min(w,v.length),v.copy?v.copy(M,0,t,w):M.set(v.slice(t,w)),x-=t,t=0,Ce=M.length-10,v=M},j=(w,P,M)=>{let T=s.nextId;T||(T=64),T<p&&this.shouldShareStructure&&!this.shouldShareStructure(P)?(T=s.nextOwnId,T<m||(T=p),s.nextOwnId=T+1):(T>=m&&(T=p),s.nextId=T+1);let L=P.highByte=T>=96&&h?T-96>>5:-1;w[Vt]=T,w.__keys__=P,s[T-64]=P,T<p?(P.isShared=!0,s.sharedLength=T-63,n=!0,L>=0?(v[x++]=(T&31)+96,v[x++]=L):v[x++]=T):(L>=0?(v[x++]=213,v[x++]=114,v[x++]=(T&31)+96,v[x++]=L):(v[x++]=212,v[x++]=114,v[x++]=T),M&&(g+=b*M),u.length>=f&&(u.shift()[Vt]=0),u.push(w),I(P))},Y=(w,P,M,T)=>{let L=v,_=x,V=Ce,U=t;v=rn,x=0,t=0,v||(rn=v=new An(8192)),Ce=v.length-10,j(w,P,T),rn=v;let z=x;if(v=L,x=_,Ce=V,t=U,z>1){let X=x+z-1;X>Ce&&K(X);let le=M+t;v.copyWithin(le+z,le+1,x),v.set(rn.slice(0,z),le),x=X}else v[M+t]=rn[0]},ve=w=>{let P=ya(w,v,t,x,s,K,(M,T,L)=>{if(L)return n=!0;x=T;let _=v;return I(M),S(),_!==v?{position:x,targetView:se,target:v}:x},this);if(P===0)return $(w);x=P}}useBuffer(e){v=e,v.dataView||(v.dataView=new DataView(v.buffer,v.byteOffset,v.byteLength)),x=0}set position(e){x=e}get position(){return x}set buffer(e){v=e}get buffer(){return v}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}Ci=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,pi];ds=[{pack(i,e,t){let n=i.getTime()/1e3;if((this.useTimestamp32||i.getMilliseconds()===0)&&n>=0&&n<4294967296){let{target:s,targetView:r,position:o}=e(6);s[o++]=214,s[o++]=255,r.setUint32(o,n)}else if(n>0&&n<4294967296){let{target:s,targetView:r,position:o}=e(10);s[o++]=215,s[o++]=255,r.setUint32(o,i.getMilliseconds()*4e6+(n/1e3/4294967296>>0)),r.setUint32(o+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return e(0),t(this.onInvalidDate());let{target:s,targetView:r,position:o}=e(3);s[o++]=212,s[o++]=255,s[o++]=255}else{let{target:s,targetView:r,position:o}=e(15);s[o++]=199,s[o++]=12,s[o++]=255,r.setUint32(o,i.getMilliseconds()*1e6),r.setBigInt64(o+4,BigInt(Math.floor(n)))}}},{pack(i,e,t){if(this.setAsEmptyObject)return e(0),t({});let n=Array.from(i),{target:s,position:r}=e(this.moreTypes?3:0);this.moreTypes&&(s[r++]=212,s[r++]=115,s[r++]=0),t(n)}},{pack(i,e,t){let{target:n,position:s}=e(this.moreTypes?3:0);this.moreTypes&&(n[s++]=212,n[s++]=101,n[s++]=0),t([i.name,i.message,i.cause])}},{pack(i,e,t){let{target:n,position:s}=e(this.moreTypes?3:0);this.moreTypes&&(n[s++]=212,n[s++]=120,n[s++]=0),t([i.source,i.flags])}},{pack(i,e){this.moreTypes?or(i,16,e):ar(Hn?Buffer.from(i):new Uint8Array(i),e)}},{pack(i,e){let t=i.constructor;t!==Si&&this.moreTypes?or(i,bi.indexOf(t.name),e):ar(i,e)}},{pack(i,e){let{target:t,position:n}=e(1);t[n]=193}}];function or(i,e,t,n){let s=i.byteLength;if(s+1<256){var{target:r,position:o}=t(4+s);r[o++]=199,r[o++]=s+1}else if(s+1<65536){var{target:r,position:o}=t(5+s);r[o++]=200,r[o++]=s+1>>8,r[o++]=s+1&255}else{var{target:r,position:o,targetView:a}=t(7+s);r[o++]=201,a.setUint32(o,s+1),o+=4}r[o++]=116,r[o++]=e,i.buffer||(i=new Uint8Array(i)),r.set(new Uint8Array(i.buffer,i.byteOffset,i.byteLength),o)}function ar(i,e){let t=i.byteLength;var n,s;if(t<256){var{target:n,position:s}=e(t+2);n[s++]=196,n[s++]=t}else if(t<65536){var{target:n,position:s}=e(t+3);n[s++]=197,n[s++]=t>>8,n[s++]=t&255}else{var{target:n,position:s,targetView:r}=e(t+5);n[s++]=198,r.setUint32(s,t),s+=4}n.set(i,s)}function wa(i,e,t,n){let s=i.length;switch(s){case 1:e[t++]=212;break;case 2:e[t++]=213;break;case 4:e[t++]=214;break;case 8:e[t++]=215;break;case 16:e[t++]=216;break;default:s<256?(e[t++]=199,e[t++]=s):s<65536?(e[t++]=200,e[t++]=s>>8,e[t++]=s&255):(e[t++]=201,e[t++]=s>>24,e[t++]=s>>16&255,e[t++]=s>>8&255,e[t++]=s&255)}return e[t++]=n,e.set(i,t),t+=s,t}function ba(i,e){let t,n=e.length*6,s=i.length-n;for(;t=e.pop();){let r=t.offset,o=t.id;i.copyWithin(r+n,r,s),n-=6;let a=r+n;i[a++]=214,i[a++]=105,i[a++]=o>>24,i[a++]=o>>16&255,i[a++]=o>>8&255,i[a++]=o&255,s=r}return i}function lr(i,e,t){if(ce.length>0){se.setUint32(ce.position+i,x+t-ce.position-i),ce.stringsPosition=x-i;let n=ce;ce=null,e(n[0]),e(n[1])}}function Ea(i,e){return i.isCompatible=t=>{let n=!t||(e.lastNamedStructuresLength||0)===t.length;return n||e._mergeStructures(t),n},i}let ki=new Ti({useRecords:!1});ki.pack;ki.pack;const Ca=512,Sa=1024,Ta=2048;class ka{constructor(e){E(this,"wt");E(this,"isOpen",!1);E(this,"events");E(this,"reader");E(this,"writer");E(this,"unreliableReader");E(this,"unreliableWriter");E(this,"lengthPrefixBuffer",new Uint8Array(9));this.events=e}connect(e,t={}){const n=t.fingerprint&&{serverCertificateHashes:[{algorithm:"sha-256",value:new Uint8Array(t.fingerprint).buffer}]}||void 0;this.wt=new WebTransport(e,n),this.wt.ready.then(s=>{console.log("WebTransport ready!",s),this.isOpen=!0,this.unreliableReader=this.wt.datagrams.readable.getReader(),this.unreliableWriter=this.wt.datagrams.writable.getWriter(),this.wt.incomingBidirectionalStreams.getReader().read().then(o=>{this.reader=o.value.readable.getReader(),this.writer=o.value.writable.getWriter(),this.sendSeatReservation(t.roomId,t.sessionId,t.reconnectionToken,t.skipHandshake),this.readIncomingData(),this.readIncomingUnreliableData()}).catch(o=>{console.error("failed to read incoming stream",o),console.error("TODO: close the connection")})}).catch(s=>{console.log("WebTransport not ready!",s),this._close()}),this.wt.closed.then(s=>{console.log("WebTransport closed w/ success",s),this.events.onclose({code:s.closeCode,reason:s.reason})}).catch(s=>{console.log("WebTransport closed w/ error",s),this.events.onerror(s),this.events.onclose({code:s.closeCode,reason:s.reason})}).finally(()=>{this._close()})}send(e){const t=ae.number(this.lengthPrefixBuffer,e.length,{offset:0}),n=new Uint8Array(t+e.length);n.set(this.lengthPrefixBuffer.subarray(0,t),0),n.set(e,t),this.writer.write(n)}sendUnreliable(e){const t=ae.number(this.lengthPrefixBuffer,e.length,{offset:0}),n=new Uint8Array(t+e.length);n.set(this.lengthPrefixBuffer.subarray(0,t),0),n.set(e,t),this.unreliableWriter.write(n)}close(e,t){try{this.wt.close({closeCode:e,reason:t})}catch(n){console.error(n)}}async readIncomingData(){let e;for(;this.isOpen;){try{e=await this.reader.read();const t=e.value,n={offset:0};do{const s=oe.number(t,n);this.events.onmessage({data:t.subarray(n.offset,n.offset+s)}),n.offset+=s}while(n.offset<t.length)}catch(t){t.message.indexOf("session is closed")===-1&&console.error("H3Transport: failed to read incoming data",t);break}if(e.done)break}}async readIncomingUnreliableData(){let e;for(;this.isOpen;){try{e=await this.unreliableReader.read();const t=e.value,n={offset:0};do{const s=oe.number(t,n);this.events.onmessage({data:t.subarray(n.offset,n.offset+s)}),n.offset+=s}while(n.offset<t.length)}catch(t){t.message.indexOf("session is closed")===-1&&console.error("H3Transport: failed to read incoming data",t);break}if(e.done)break}}sendSeatReservation(e,t,n,s){const r={offset:0},o=[];ae.string(o,e,r),ae.string(o,t,r),n&&ae.string(o,n,r),s&&ae.boolean(o,1,r),this.writer.write(new Uint8Array(o).buffer)}_close(){this.isOpen=!1}}function Ia(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Kn,cr;function Ma(){return cr||(cr=1,Kn=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}),Kn}var Aa=Ma();const Ra=Ia(Aa),Zn=globalThis.WebSocket||Ra;class Da{constructor(e){E(this,"ws");E(this,"protocols");E(this,"events");this.events=e}send(e){this.ws.send(e)}sendUnreliable(e){console.warn("@colyseus/sdk: The WebSocket transport does not support unreliable messages")}connect(e,t){try{this.ws=new Zn(e,{headers:t,protocols:this.protocols})}catch{this.ws=new Zn(e,this.protocols)}this.ws.binaryType="arraybuffer",this.ws.onopen=n=>{var s,r;return(r=(s=this.events).onopen)==null?void 0:r.call(s,n)},this.ws.onmessage=n=>{var s,r;return(r=(s=this.events).onmessage)==null?void 0:r.call(s,n)},this.ws.onclose=n=>{var s,r;return(r=(s=this.events).onclose)==null?void 0:r.call(s,n)},this.ws.onerror=n=>{var s,r;return(r=(s=this.events).onerror)==null?void 0:r.call(s,n)}}close(e,t){e===Ne.MAY_TRY_RECONNECT&&this.events.onclose&&(this.ws.onclose=null,this.events.onclose({code:e,reason:t})),this.ws.close(e,t)}get isOpen(){return this.ws.readyState===Zn.OPEN}}const an=[],hs=typeof addEventListener=="function"&&typeof removeEventListener=="function";hs&&addEventListener("offline",()=>{console.warn(`@colyseus/sdk: 🛑 Network offline. Closing ${an.length} connection(s)`),an.forEach(i=>i())},!1);var pn;class Ii{constructor(e){E(this,"transport");E(this,"events",{});E(this,"url");E(this,"options");Ct(this,pn,hs?()=>this.close(Ne.MAY_TRY_RECONNECT):null);switch(e){case"h3":this.transport=new ka(this.events);break;default:this.transport=new Da(this.events);break}}connect(e,t){if(hs){const n=this.events.onopen;this.events.onopen=r=>{an.push($e(this,pn)),n==null||n(r)};const s=this.events.onclose;this.events.onclose=r=>{an.splice(an.indexOf($e(this,pn)),1),s==null||s(r)}}this.url=e,this.options=t,this.transport.connect(e,t)}send(e){this.transport.send(e)}sendUnreliable(e){this.transport.sendUnreliable(e)}reconnect(e){const t=new URL(this.url);for(const n in e)t.searchParams.set(n,e[n]);this.transport.connect(t.toString(),this.options)}close(e,t){this.transport.close(e,t)}get isOpen(){return this.transport.isOpen}}pn=new WeakMap;const Mi={};function Ai(i,e){Mi[i]=e}function fr(i){const e=Mi[i];if(!e)throw new Error("missing serializer: "+i);return e}const Ri=()=>({emit(i,...e){let t=this.events[i]||[];for(let n=0,s=t.length;n<s;n++)t[n](...e)},events:{},on(i,e){var t;return(t=this.events[i])!=null&&t.push(e)||(this.events[i]=[e]),()=>{var n;this.events[i]=(n=this.events[i])==null?void 0:n.filter(s=>e!==s)}}});class Ba{constructor(){E(this,"handlers",[])}register(e,t=!1){return this.handlers.push(e),this}invoke(...e){this.handlers.forEach(t=>t.apply(this,e))}invokeAsync(...e){return Promise.all(this.handlers.map(t=>t.apply(this,e)))}remove(e){const t=this.handlers.indexOf(e);this.handlers[t]=this.handlers[this.handlers.length-1],this.handlers.pop()}clear(){this.handlers=[]}}function jt(){const i=new Ba;function e(t){return i.register(t,this===null)}return e.once=t=>{const n=function(...s){t.apply(this,s),i.remove(n)};i.register(n)},e.remove=t=>i.remove(t),e.invoke=(...t)=>i.invoke(...t),e.invokeAsync=(...t)=>i.invokeAsync(...t),e.clear=()=>i.clear(),e}class Di{constructor(){E(this,"state");E(this,"decoder")}setState(e,t){this.decoder.decode(e,t)}getState(){return this.state}patch(e,t){return this.decoder.decode(e,t)}teardown(){this.decoder.root.clearRefs()}handshake(e,t){this.state?(tn.decode(e,t),this.decoder=new en(this.state)):(this.decoder=tn.decode(e,t),this.state=this.decoder.state)}}function dr(){return typeof performance<"u"?performance.now():Date.now()}var gn,Kt;class La{constructor(e,t){E(this,"roomId");E(this,"sessionId");E(this,"reconnectionToken");E(this,"name");E(this,"connection");E(this,"onStateChange",jt());E(this,"onError",jt());E(this,"onLeave",jt());E(this,"onReconnect",jt());E(this,"onDrop",jt());E(this,"onJoin",jt());E(this,"serializerId");E(this,"serializer");E(this,"reconnection",{enabled:!0,retryCount:0,maxRetries:15,delay:100,minDelay:100,maxDelay:5e3,minUptime:5e3,backoff:Pa,maxEnqueuedMessages:10,enqueuedMessages:[],isReconnecting:!1});E(this,"joinedAtTime",0);E(this,"onMessageHandlers",Ri());E(this,"packr");Ct(this,gn,0);Ct(this,Kt);if(this.name=e,this.packr=new Ti,this.packr.encode(void 0),t){const n=new(fr("schema"));this.serializer=n;const s=new t;n.state=s,n.decoder=new en(s)}this.onLeave(()=>{this.removeAllListeners(),this.destroy()})}connect(e,t,n){var r;this.connection=new Ii(t.protocol),this.connection.events.onmessage=this.onMessageCallback.bind(this),this.connection.events.onclose=o=>{var a;if(this.joinedAtTime===0){(a=console.warn)==null||a.call(console,`Room connection was closed unexpectedly (${o.code}): ${o.reason}`),this.onError.invoke(o.code,o.reason);return}o.code===Ne.NO_STATUS_RECEIVED||o.code===Ne.ABNORMAL_CLOSURE||o.code===Ne.GOING_AWAY||o.code===Ne.MAY_TRY_RECONNECT?(this.onDrop.invoke(o.code,o.reason),this.handleReconnection(o.code,o.reason)):this.onLeave.invoke(o.code,o.reason)},this.connection.events.onerror=o=>{this.onError.invoke(o.code,o.reason)};const s=((r=this.serializer)==null?void 0:r.getState())!==void 0;if(t.protocol==="h3"){const o=new URL(e);this.connection.connect(o.origin,{...t,skipHandshake:s})}else this.connection.connect(`${e}${s?"&skipHandshake=1":""}`,n)}leave(e=!0){return new Promise(t=>{this.onLeave(n=>t(n)),this.connection?e?(this.packr.buffer[0]=Ee.LEAVE_ROOM,this.connection.send(this.packr.buffer.subarray(0,1))):this.connection.close():this.onLeave.invoke(Ne.CONSENTED)})}onMessage(e,t){return this.onMessageHandlers.on(this.getMessageHandlerKey(e),t)}ping(e){var t;(t=this.connection)!=null&&t.isOpen&&(lt(this,gn,dr()),lt(this,Kt,e),this.packr.buffer[0]=Ee.PING,this.connection.send(this.packr.buffer.subarray(0,1)))}send(e,t){const n={offset:1};this.packr.buffer[0]=Ee.ROOM_DATA,typeof e=="string"?ae.string(this.packr.buffer,e,n):ae.number(this.packr.buffer,e,n),this.packr.position=0;const s=t!==void 0?this.packr.pack(t,2048+n.offset):this.packr.buffer.subarray(0,n.offset);this.connection.isOpen?this.connection.send(s):hr(this,new Uint8Array(s))}sendUnreliable(e,t){if(!this.connection.isOpen)return;const n={offset:1};this.packr.buffer[0]=Ee.ROOM_DATA,typeof e=="string"?ae.string(this.packr.buffer,e,n):ae.number(this.packr.buffer,e,n),this.packr.position=0;const s=t!==void 0?this.packr.pack(t,2048+n.offset):this.packr.buffer.subarray(0,n.offset);this.connection.sendUnreliable(s)}sendBytes(e,t){const n={offset:1};if(this.packr.buffer[0]=Ee.ROOM_DATA_BYTES,typeof e=="string"?ae.string(this.packr.buffer,e,n):ae.number(this.packr.buffer,e,n),t.byteLength+n.offset>this.packr.buffer.byteLength){const s=new Uint8Array(n.offset+t.byteLength);s.set(this.packr.buffer),this.packr.useBuffer(s)}this.packr.buffer.set(t,n.offset),this.connection.isOpen?this.connection.send(this.packr.buffer.subarray(0,n.offset+t.byteLength)):hr(this,this.packr.buffer.subarray(0,n.offset+t.byteLength))}get state(){return this.serializer.getState()}removeAllListeners(){this.onJoin.clear(),this.onStateChange.clear(),this.onError.clear(),this.onLeave.clear(),this.onReconnect.clear(),this.onDrop.clear(),this.onMessageHandlers.events={},this.serializer instanceof Di&&(this.serializer.decoder.root.callbacks={})}onMessageCallback(e){var r;const t=new Uint8Array(e.data),n={offset:1},s=t[0];if(s===Ee.JOIN_ROOM){const o=oe.utf8Read(t,n,t[n.offset++]);if(this.serializerId=oe.utf8Read(t,n,t[n.offset++]),!this.serializer){const a=fr(this.serializerId);this.serializer=new a}if(t.byteLength>n.offset&&this.serializer.handshake&&this.serializer.handshake(t,n),this.joinedAtTime===0?(this.joinedAtTime=Date.now(),this.onJoin.invoke()):(console.info(`[Colyseus reconnection]: ${String.fromCodePoint(9989)} reconnection successful!`),this.reconnection.isReconnecting=!1,this.onReconnect.invoke()),this.reconnectionToken=`${this.roomId}:${o}`,this.packr.buffer[0]=Ee.JOIN_ROOM,this.connection.send(this.packr.buffer.subarray(0,1)),this.reconnection.enqueuedMessages.length>0){for(const a of this.reconnection.enqueuedMessages)this.connection.send(a.data);this.reconnection.enqueuedMessages=[]}}else if(s===Ee.ERROR){const o=oe.number(t,n),a=oe.string(t,n);this.onError.invoke(o,a)}else if(s===Ee.LEAVE_ROOM)this.leave();else if(s===Ee.ROOM_STATE)this.serializer.setState(t,n),this.onStateChange.invoke(this.serializer.getState());else if(s===Ee.ROOM_STATE_PATCH)this.serializer.patch(t,n),this.onStateChange.invoke(this.serializer.getState());else if(s===Ee.ROOM_DATA){const o=oe.stringCheck(t,n)?oe.string(t,n):oe.number(t,n),a=t.byteLength>n.offset?ga(t,{start:n.offset}):void 0;this.dispatchMessage(o,a)}else if(s===Ee.ROOM_DATA_BYTES){const o=oe.stringCheck(t,n)?oe.string(t,n):oe.number(t,n);this.dispatchMessage(o,t.subarray(n.offset))}else s===Ee.PING&&((r=$e(this,Kt))==null||r.call(this,Math.round(dr()-$e(this,gn))),lt(this,Kt,void 0))}dispatchMessage(e,t){var s;const n=this.getMessageHandlerKey(e);this.onMessageHandlers.events[n]?this.onMessageHandlers.emit(n,t):this.onMessageHandlers.events["*"]?this.onMessageHandlers.emit("*",e,t):n.startsWith("__")||(s=console.warn)==null||s.call(console,`@colyseus/sdk: onMessage() not registered for type '${e}'.`)}destroy(){this.serializer&&this.serializer.teardown()}getMessageHandlerKey(e){switch(typeof e){case"string":return e;case"number":return`i${e}`;default:throw new Error("invalid message type.")}}handleReconnection(e,t){if(!this.reconnection.enabled){this.onLeave.invoke(e,t);return}if(Date.now()-this.joinedAtTime<this.reconnection.minUptime){console.info(`[Colyseus reconnection]: ${String.fromCodePoint(10060)} Room has not been up for long enough for automatic reconnection. (min uptime: ${this.reconnection.minUptime}ms)`),this.onLeave.invoke(Ne.ABNORMAL_CLOSURE,"Room uptime too short for reconnection.");return}this.reconnection.isReconnecting||(this.reconnection.retryCount=0,this.reconnection.isReconnecting=!0),this.retryReconnection()}retryReconnection(){if(this.reconnection.retryCount>=this.reconnection.maxRetries){console.info(`[Colyseus reconnection]: ${String.fromCodePoint(10060)} ❌ Reconnection failed after ${this.reconnection.maxRetries} attempts.`),this.reconnection.isReconnecting=!1,this.onLeave.invoke(Ne.FAILED_TO_RECONNECT,"No more retries. Reconnection failed.");return}this.reconnection.retryCount++;const e=Math.min(this.reconnection.maxDelay,Math.max(this.reconnection.minDelay,this.reconnection.backoff(this.reconnection.retryCount,this.reconnection.delay)));console.info(`[Colyseus reconnection]: ${String.fromCodePoint(9203)} will retry in ${(e/1e3).toFixed(1)} seconds...`),setTimeout(()=>{try{console.info(`[Colyseus reconnection]: ${String.fromCodePoint(128260)} Re-establishing sessionId '${this.sessionId}' with roomId '${this.roomId}'... (attempt ${this.reconnection.retryCount} of ${this.reconnection.maxRetries})`),this.connection.reconnect({reconnectionToken:this.reconnectionToken.split(":")[1],skipHandshake:!0})}catch{this.retryReconnection()}},e)}}gn=new WeakMap,Kt=new WeakMap;const Pa=(i,e)=>Math.floor(Math.pow(2,i)*e);function hr(i,e){i.reconnection.enqueuedMessages.push({data:e}),i.reconnection.enqueuedMessages.length>i.reconnection.maxEnqueuedMessages&&i.reconnection.enqueuedMessages.shift()}function Oa(i){if(i===void 0)return!1;const e=typeof i;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(i)?!0:i.buffer?!1:i.constructor&&i.constructor.name==="Object"||typeof i.toJSON=="function"}function Fa(i,e){const{params:t,query:n}=e||{},[s,r]=i.split("?");let o=s;if(t)if(Array.isArray(t)){const d=o.split("/").filter(c=>c.startsWith(":"));for(const[c,f]of d.entries()){const h=t[c];o=o.replace(f,h)}}else for(const[d,c]of Object.entries(t))o=o.replace(`:${d}`,String(c));const a=new URLSearchParams(r);if(n)for(const[d,c]of Object.entries(n))c!=null&&a.set(d,String(c));let l=a.toString();return l=l.length>0?`?${l}`.replace(/\+/g,"%20"):"",`${o}${l}`}class $a{constructor(e,t){E(this,"authToken");E(this,"options");E(this,"sdk");E(this,"del",this.delete);this.sdk=e,this.options=t}async request(e,t,n){return this.executeRequest(e,t,n)}get(e,t){return this.request("GET",e,t)}post(e,t){return this.request("POST",e,t)}delete(e,t){return this.request("DELETE",e,t)}patch(e,t){return this.request("PATCH",e,t)}put(e,t){return this.request("PUT",e,t)}async executeRequest(e,t,n){var p;let s=this.options.body?{...this.options.body,...(n==null?void 0:n.body)||{}}:n==null?void 0:n.body;const r=this.options.query?{...this.options.query,...(n==null?void 0:n.query)||{}}:n==null?void 0:n.query,o=this.options.params?{...this.options.params,...(n==null?void 0:n.params)||{}}:n==null?void 0:n.params,a=new Headers(this.options.headers?{...this.options.headers,...(n==null?void 0:n.headers)||{}}:n==null?void 0:n.headers);if(this.authToken&&!a.has("authorization")&&a.set("authorization",`Bearer ${this.authToken}`),Oa(s)&&typeof s=="object"&&s!==null){a.has("content-type")||a.set("content-type","application/json");for(const[m,u]of Object.entries(s))u instanceof Date&&(s[m]=u.toISOString());s=JSON.stringify(s)}const l={credentials:(n==null?void 0:n.credentials)||"include",...this.options,...n,query:r,params:o,headers:a,body:s,method:e},d=Fa(this.sdk.getHttpEndpoint(t.toString()),l);let c;try{c=await fetch(d,l)}catch(m){if(m.name==="AbortError")throw m;const u=new on(((p=m.cause)==null?void 0:p.code)||m.code,m.message);throw u.response=c,u.cause=m.cause,u}const f=c.headers.get("content-type");let h;if(f!=null&&f.indexOf("json")?h=await c.json():f!=null&&f.indexOf("text")?h=await c.text():h=await c.blob(),!c.ok)throw new on(c.status,h.message??h.error??c.statusText,{headers:c.headers,status:c.status,response:c,data:h});return{raw:c,data:h,headers:c.headers,status:c.status,statusText:c.statusText}}}let Tt;function As(){if(!Tt)try{Tt=typeof cc<"u"&&cc.sys&&cc.sys.localStorage?cc.sys.localStorage:window.localStorage}catch{}return!Tt&&typeof globalThis.indexedDB<"u"&&(Tt=new Na),Tt||(Tt={cache:{},setItem:function(i,e){this.cache[i]=e},getItem:function(i){this.cache[i]},removeItem:function(i){delete this.cache[i]}}),Tt}function za(i,e){As().setItem(i,e)}function _a(i){As().removeItem(i)}function Ua(i,e){const t=As().getItem(i);typeof Promise>"u"||!(t instanceof Promise)?e(t):t.then(n=>e(n))}class Na{constructor(){E(this,"dbPromise",new Promise(e=>{const t=indexedDB.open("_colyseus_storage",1);t.onupgradeneeded=()=>t.result.createObjectStore("store"),t.onsuccess=()=>e(t.result)}))}async tx(e,t){const s=(await this.dbPromise).transaction("store",e).objectStore("store");return t(s)}setItem(e,t){return this.tx("readwrite",n=>n.put(t,e)).then()}async getItem(e){const t=await this.tx("readonly",n=>n.get(e));return new Promise(n=>{t.onsuccess=()=>n(t.result)})}removeItem(e){return this.tx("readwrite",t=>t.delete(e)).then()}}var mn,nt,yn;class Va{constructor(e){E(this,"settings",{path:"/auth",key:"colyseus-auth-token"});Ct(this,mn,!1);Ct(this,nt,null);Ct(this,yn,Ri());E(this,"http");this.http=e,Ua(this.settings.key,t=>this.token=t)}set token(e){this.http.authToken=e}get token(){return this.http.authToken}onChange(e){const t=$e(this,yn).on("change",e);return $e(this,mn)||this.getUserData().then(n=>{this.emitChange({...n,token:this.token})}).catch(n=>{this.emitChange({user:null,token:void 0})}),lt(this,mn,!0),t}async getUserData(){if(this.token)return(await this.http.get(`${this.settings.path}/userdata`)).data;throw new Error("missing auth.token")}async registerWithEmailAndPassword(e,t,n){const s=(await this.http.post(`${this.settings.path}/register`,{body:{email:e,password:t,options:n}})).data;return this.emitChange(s),s}async signInWithEmailAndPassword(e,t){const n=(await this.http.post(`${this.settings.path}/login`,{body:{email:e,password:t}})).data;return this.emitChange(n),n}async signInAnonymously(e){const t=(await this.http.post(`${this.settings.path}/anonymous`,{body:{options:e}})).data;return this.emitChange(t),t}async sendPasswordResetEmail(e){return(await this.http.post(`${this.settings.path}/forgot-password`,{body:{email:e}})).data}async signInWithProvider(e,t={}){return new Promise((n,s)=>{const r=t.width||480,o=t.height||768,a=this.token?`?token=${this.token}`:"",l=`Login with ${e[0].toUpperCase()+e.substring(1)}`,d=this.http.sdk.getHttpEndpoint(`${t.prefix||`${this.settings.path}/provider`}/${e}${a}`),c=screen.width/2-r/2,f=screen.height/2-o/2;lt(this,nt,window.open(d,l,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+r+", height="+o+", top="+f+", left="+c));const h=m=>{var u;m.data.user===void 0&&m.data.token===void 0||(clearInterval(p),(u=$e(this,nt))==null||u.close(),lt(this,nt,null),window.removeEventListener("message",h),m.data.error!==void 0?s(m.data.error):(n(m.data),this.emitChange(m.data)))},p=setInterval(()=>{(!$e(this,nt)||$e(this,nt).closed)&&(lt(this,nt,null),s("cancelled"),window.removeEventListener("message",h))},200);window.addEventListener("message",h)})}async signOut(){this.emitChange({user:null,token:null})}emitChange(e){e.token!==void 0&&(this.token=e.token,e.token===null?_a(this.settings.key):za(this.settings.key,e.token)),$e(this,yn).emit("change",e)}}mn=new WeakMap,nt=new WeakMap,yn=new WeakMap;function ja(i){var s;const e=((s=window==null?void 0:window.location)==null?void 0:s.hostname)||"localhost",t=i.hostname.split("."),n=!i.hostname.includes("trycloudflare.com")&&!i.hostname.includes("discordsays.com")&&t.length>2?`/${t[0]}`:"";return i.pathname.startsWith("/.proxy")?`${i.protocol}//${e}${n}${i.pathname}${i.search}`:`${i.protocol}//${e}/.proxy/colyseus${n}${i.pathname}${i.search}`}var Wr;const ur=typeof window<"u"&&typeof((Wr=window==null?void 0:window.location)==null?void 0:Wr.hostname)<"u"?`${window.location.protocol.replace("http","ws")}//${window.location.hostname}${window.location.port&&`:${window.location.port}`}`:"ws://127.0.0.1:2567",_n=class _n{constructor(e=ur,t){E(this,"http");E(this,"auth");E(this,"settings");E(this,"urlBuilder");var n,s;if(typeof e=="string"){const r=e.startsWith("/")?new URL(e,ur):new URL(e),o=r.protocol==="https:"||r.protocol==="wss:",a=Number(r.port||(o?443:80));this.settings={hostname:r.hostname,pathname:r.pathname,port:a,secure:o,searchParams:r.searchParams.toString()||void 0}}else e.port===void 0&&(e.port=e.secure?443:80),e.pathname===void 0&&(e.pathname=""),this.settings=e;this.settings.pathname.endsWith("/")&&(this.settings.pathname=this.settings.pathname.slice(0,-1)),t!=null&&t.protocol&&(this.settings.protocol=t.protocol),this.http=new $a(this,{headers:(t==null?void 0:t.headers)||{}}),this.auth=new Va(this.http),this.urlBuilder=t==null?void 0:t.urlBuilder,!this.urlBuilder&&typeof window<"u"&&((s=(n=window==null?void 0:window.location)==null?void 0:n.hostname)!=null&&s.includes("discordsays.com"))&&(this.urlBuilder=ja,console.log("Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder."))}static async selectByLatency(e,t,n={}){const s=e.map(o=>new _n(o,t)),r=(await Promise.allSettled(s.map((o,a)=>o.getLatency(n).then(l=>{const d=s[a].settings;return console.log(`🛜 Endpoint Latency: ${l}ms - ${d.hostname}:${d.port}${d.pathname}`),[a,l]})))).filter(o=>o.status==="fulfilled").map(o=>o.value);if(r.length===0)throw new Error("All endpoints failed to respond");return s[r.sort((o,a)=>o[1]-a[1])[0][0]]}async joinOrCreate(e,t={},n){return await this.createMatchMakeRequest("joinOrCreate",e,t,n)}async create(e,t={},n){return await this.createMatchMakeRequest("create",e,t,n)}async join(e,t={},n){return await this.createMatchMakeRequest("join",e,t,n)}async joinById(e,t={},n){return await this.createMatchMakeRequest("joinById",e,t,n)}async reconnect(e,t){if(typeof e=="string"&&typeof t=="string")throw new Error("DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\nYou can get this token from previously connected `room.reconnectionToken`");const[n,s]=e.split(":");if(!n||!s)throw new Error(`Invalid reconnection token format.
|
|
24
|
+
The format should be roomId:reconnectionToken`);return await this.createMatchMakeRequest("reconnect",n,{reconnectionToken:s},t)}async consumeSeatReservation(e,t){const n=this.createRoom(e.name,t);n.roomId=e.roomId,n.sessionId=e.sessionId;const s={sessionId:n.sessionId};return e.reconnectionToken&&(s.reconnectionToken=e.reconnectionToken),n.connect(this.buildEndpoint(e,s),e,this.http.options.headers),new Promise((r,o)=>{const a=(l,d)=>o(new on(l,d));n.onError.once(a),n.onJoin.once(()=>{n.onError.remove(a),r(n)})})}getLatency(e={}){const t=e.protocol??"ws",n=e.pingCount??1;return new Promise((s,r)=>{const o=new Ii(t),a=[];let l=0;o.events.onopen=()=>{l=Date.now(),o.send(new Uint8Array([Ee.PING]))},o.events.onmessage=d=>{if(a.push(Date.now()-l),a.length<n)l=Date.now(),o.send(new Uint8Array([Ee.PING]));else{o.close();const c=a.reduce((f,h)=>f+h,0)/a.length;s(c)}},o.events.onerror=d=>{r(new on(Ne.ABNORMAL_CLOSURE,`Failed to get latency: ${d.message}`))},o.connect(this.getHttpEndpoint())})}async createMatchMakeRequest(e,t,n={},s){try{if(!t)throw new Error("Must provide a room name");const o=(await this.http.post(`/matchmake/${e}/${t}`,{headers:{Accept:"application/json","Content-Type":"application/json"},body:n})).data;return e==="reconnect"&&(o.reconnectionToken=n.reconnectionToken),await this.consumeSeatReservation(o,s)}catch(r){throw r instanceof on?new xs(r.message,r.code):r}}createRoom(e,t){return new La(e,t)}buildEndpoint(e,t={}){let n=this.settings.protocol||"ws",s=this.settings.searchParams||"";this.http.authToken&&(t._authToken=this.http.authToken);for(const a in t)t.hasOwnProperty(a)&&(s+=(s?"&":"")+`${a}=${t[a]}`);n==="h3"&&(n="http");let r=this.settings.secure?`${n}s://`:`${n}://`;e.publicAddress?r+=`${e.publicAddress}`:r+=`${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;const o=`${r}/${e.processId}/${e.roomId}?${s}`;return this.urlBuilder?this.urlBuilder(new URL(o)):o}getHttpEndpoint(e=""){const t=e.startsWith("/")?e:`/${e}`;let n=`${this.settings.secure?"https":"http"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${t}`;return this.settings.searchParams&&(n+=`?${this.settings.searchParams}`),this.urlBuilder?this.urlBuilder(new URL(n)):n}getEndpointPort(){return this.settings.port!==80&&this.settings.port!==443?`:${this.settings.port}`:""}};E(_n,"VERSION","0.17");let us=_n;const ps=us,Ha=`<svg viewBox="0 0 488.94 541.2" style="width: 100%; height: 100%;">
|
|
25
|
+
<g>
|
|
26
|
+
<g>
|
|
27
|
+
<path fill="#ffffff" d="m80.42,197.14c13.82,11.25,30.56,22.25,50.78,32.11,14.87-28.67,72.09-100.71,233.32-79.68l-14.4-55.35c-200.24-17.18-257.81,77.11-269.7,102.92Z"/>
|
|
28
|
+
<path fill="#ffffff" d="m44.53,167.77c22.44-40.73,99.17-124.23,290.19-105.83L310.19,1.59S109.9-21.63,8.9,109.47c3.62,10.55,13.31,33.34,35.63,58.29Z"/>
|
|
29
|
+
<path fill="#ffffff" d="m407.7,291.25c-32.14,3.35-62.02,4.95-89.63,4.95C123.09,296.2,36.78,219.6,0,164.95v251.98s15.77,162.98,488.94,115.66l-81.24-241.33Z"/>
|
|
30
|
+
</g>
|
|
31
|
+
</g>
|
|
32
|
+
</svg>`,Wa='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v4.5a.5.5 0 0 1-1 0V5.383l-7 4.2-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h5.5a.5.5 0 0 1 0 1H2a2 2 0 0 1-2-1.99zm1 7.105 4.708-2.897L1 5.383zM1 4v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1"></path><path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m.354-5.354 1.25 1.25a.5.5 0 0 1-.708.708L13 12.207V14a.5.5 0 0 1-1 0v-1.717l-.28.305a.5.5 0 0 1-.737-.676l1.149-1.25a.5.5 0 0 1 .722-.016"></path></svg>',Ga='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v4.5a.5.5 0 0 1-1 0V5.383l-7 4.2-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h5.5a.5.5 0 0 1 0 1H2a2 2 0 0 1-2-1.99zm1 7.105 4.708-2.897L1 5.383zM1 4v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1"></path><path d="M12.5 16a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7m.354-1.646a.5.5 0 0 1-.722-.016l-1.149-1.25a.5.5 0 1 1 .737-.676l.28.305V11a.5.5 0 0 1 1 0v1.793l.396-.397a.5.5 0 0 1 .708.708z"></path></svg>',Xa='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/></svg>',Ya='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 256 256" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M160,136v-8H88v64a8,8,0,0,0,8,8h64v-8a16,16,0,0,1,16-16h32a16,16,0,0,1,16,16v32a16,16,0,0,1-16,16H176a16,16,0,0,1-16-16v-8H96a24,24,0,0,1-24-24V80H64A16,16,0,0,1,48,64V32A16,16,0,0,1,64,16H96a16,16,0,0,1,16,16V64A16,16,0,0,1,96,80H88v32h72v-8a16,16,0,0,1,16-16h32a16,16,0,0,1,16,16v32a16,16,0,0,1-16,16H176A16,16,0,0,1,160,136Z"></path></svg>',qa='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M256 48C141.2 48 48 141.2 48 256s93.2 208 208 208 208-93.2 208-208S370.8 48 256 48zm21 312h-42V235h42v125zm0-166h-42v-42h42v42z"></path></svg>',Ja='<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="200px" width="200px" xmlns="http://www.w3.org/2000/svg"><path d="M12.003 21c-.732 .001 -1.465 -.438 -1.678 -1.317a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c.886 .215 1.325 .957 1.318 1.694"></path><path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path><path d="M19.001 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path><path d="M19.001 15.5v1.5"></path><path d="M19.001 21v1.5"></path><path d="M22.032 17.25l-1.299 .75"></path><path d="M17.27 20l-1.3 .75"></path><path d="M15.97 17.25l1.3 .75"></path><path d="M20.733 20l1.3 .75"></path></svg>',Ka='<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>',Za='<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M400 145.49 366.51 112 256 222.51 145.49 112 112 145.49 222.51 256 112 366.51 145.49 400 256 289.49 366.51 400 400 366.51 289.49 256 400 145.49z"></path></svg>',Qa='<svg fill="currentColor" viewBox="0 0 36 36" height="200px" width="200px"><path fill="currentColor" d="M18 24.42a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2" class="clr-i-outline clr-i-outline-path-1"></path><path fill="currentColor" d="M26.21 21.85a1 1 0 0 0-.23-1.4a13.6 13.6 0 0 0-5-2.23l3.87 3.87a1 1 0 0 0 1.36-.24" class="clr-i-outline clr-i-outline-path-2"></path><path fill="currentColor" d="M18.05 10.72a21 21 0 0 0-4.16.43l1.74 1.74a19 19 0 0 1 2.42-.17A18.76 18.76 0 0 1 28.64 16a1 1 0 0 0 1.12-1.65a20.75 20.75 0 0 0-11.71-3.63" class="clr-i-outline clr-i-outline-path-3"></path><path fill="currentColor" d="M33.55 8.2A28.11 28.11 0 0 0 8.11 5.36l1.58 1.57a26 26 0 0 1 22.76 2.94a1 1 0 0 0 1.1-1.67" class="clr-i-outline clr-i-outline-path-4"></path><path fill="currentColor" d="m1.84 4.75l2.43 2.43c-.62.34-1.23.7-1.83 1.1a1 1 0 1 0 1.12 1.66C4.26 9.47 5 9 5.74 8.65l3.87 3.87a20.6 20.6 0 0 0-3.38 1.88A1 1 0 0 0 7.36 16a18.8 18.8 0 0 1 3.77-2l4.16 4.16A13.5 13.5 0 0 0 10 20.55a1 1 0 0 0 1.18 1.61A11.5 11.5 0 0 1 17 20l10.8 10.8l1.41-1.41l-26-26Z" class="clr-i-outline clr-i-outline-path-5"></path><path fill="none" d="M0 0h36v36H0z"></path></svg>',Ke=new Map;let Mt=null;const ee={maxLatency:350,latencySimulation:{enabled:!1,delay:0},panelPosition:{position:"top-right"}};function el(){try{const i=localStorage.getItem("colyseus-debug-preferences")||"{}",e=JSON.parse(i);if(e.position&&["bottom-right","bottom-left","top-left","top-right"].includes(e.position)&&(ee.panelPosition.position=e.position),e.latency!==void 0&&e.latency!==null){const t=parseInt(e.latency,10);!isNaN(t)&&t>=0&&t<=500&&(ee.latencySimulation.delay=t,ee.latencySimulation.enabled=t>0)}sessionStorage.getItem("colyseus-debug-hidden")==="true"&&(sn=!0)}catch{}}function Rs(){try{localStorage.setItem("colyseus-debug-preferences",JSON.stringify({position:ee.panelPosition.position,latency:ee.latencySimulation.delay})),sessionStorage.setItem("colyseus-debug-hidden",sn?"true":"false")}catch{}}let sn=!1,st=[];const Ds=1e4;el();function zn(i){if(!i)return;const e=st.indexOf(i);e>-1&&st.splice(e,1),st.push(i),st.forEach((t,n)=>{document.body.contains(t)&&(t.style.zIndex=(Ds+n).toString())})}function Bi(i){const e=st.indexOf(i);e>-1&&st.splice(e,1)}document.addEventListener("keydown",function(i){if(i.key==="Escape"&&st.length>0){const e=st[st.length-1];e&&document.body.contains(e)&&e.remove()}});function tl(){var i=document.createElement("div");return i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.right="0",i.style.bottom="0",i.style.backgroundColor="rgba(0, 0, 0, 0.5)",i.style.zIndex=Ds.toString(),i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i}function Li(i){var e=i||{},t=document.createElement("div");e.id&&(t.id=e.id),t.style.position="fixed",t.style.backgroundColor=e.backgroundColor||"#1e1e1e",t.style.borderRadius="8px",t.style.boxShadow="0 8px 32px rgba(0, 0, 0, 0.5)",t.style.color="#fff",t.style.fontFamily="system-ui, -apple-system, sans-serif",t.style.zIndex=Ds.toString(),t.style.display="flex",t.style.flexDirection="column",t.style.overflow="hidden",e.width&&(t.style.width=e.width),e.height&&(t.style.height=e.height),e.minWidth&&(t.style.minWidth=e.minWidth),e.minHeight&&(t.style.minHeight=e.minHeight),e.maxWidth&&(t.style.maxWidth=e.maxWidth),e.maxHeight&&(t.style.maxHeight=e.maxHeight),t.style.top=e.top||"50%",t.style.left=e.left||"50%",t.style.transform=e.transform||"translate(-50%, -50%)",t.addEventListener("mousedown",function(s){zn(t)}),zn(t);var n=t.remove.bind(t);return t.remove=function(){if(Bi(t),e.room&&e.trackOnLeave&&e.onLeaveCallback){var s=e.onLeaveCallback.current||e.onLeaveCallback;e.room.onLeave.remove(s)}e.onRemove&&e.onRemove(),n()},t}function Pi(i){var e=i||{},t=document.createElement("div");t.style.display="flex",t.style.justifyContent="space-between",t.style.alignItems="center",t.style.padding=e.padding||"8px",t.style.borderBottom="1px solid rgba(255, 255, 255, 0.15)",t.style.paddingBottom=e.paddingBottom||"4px",t.style.marginBottom=e.marginBottom||"6px",t.style.cursor=e.draggable!==!1?"move":"default",t.style.userSelect="none",t.style.flexShrink="0",t.style.position="relative",t.style.zIndex="1";var n=document.createElement("div");if(n.textContent=e.title||"",n.style.margin="0",n.style.fontSize=e.titleSize||"11px",n.style.fontWeight="bold",n.style.fontFamily=e.titleFont||"monospace",n.style.flex="1",n.style.display="flex",n.style.alignItems="center",e.statusDot){var s=document.createElement("div");s.style.width="8px",s.style.height="8px",s.style.borderRadius="50%",s.style.marginRight="8px",s.style.flexShrink="0",s.style.transition="background-color 0.3s",s.style.backgroundColor=e.statusColor||"#22c55e",n.insertBefore(s,n.firstChild),e.statusDotRef&&(e.statusDotRef.element=s)}var r=document.createElement("button");return r.innerHTML=Za,r.style.background="none",r.style.border="none",r.style.color="#fff",r.style.fontSize="18px",r.style.cursor="pointer",r.style.padding="0",r.style.margin="auto",r.style.width="20px",r.style.height="20px",r.style.display="flex",r.style.alignItems="center",r.style.justifyContent="center",r.style.borderRadius="4px",r.style.transition="background-color 0.2s",r.style.opacity="0.6",r.addEventListener("mouseenter",function(){r.style.backgroundColor="rgba(255, 255, 255, 0.1)",r.style.opacity="1"}),r.addEventListener("mouseleave",function(){r.style.backgroundColor="transparent",r.style.opacity="0.6"}),r.addEventListener("click",function(o){o.stopPropagation(),e.onClose?e.onClose():e.modal&&e.modal.remove()}),t.appendChild(n),t.appendChild(r),{header:t,title:n,closeButton:r}}function nl(i,e){var t=!1,n=0,s=0;e.addEventListener("mousedown",function(a){t=!0;var l=i.getBoundingClientRect();n=a.clientX-l.left,s=a.clientY-l.top,i.style.left=l.left+"px",i.style.top=l.top+"px",i.style.transform="none",a.preventDefault()});var r=function(a){if(t){var l=a.clientX-n,d=a.clientY-s;i.style.left=l+"px",i.style.top=d+"px"}},o=function(){t=!1};return document.addEventListener("mousemove",r),document.addEventListener("mouseup",o),function(){document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",o)}}function Ln(i,e){var t=ee.maxLatency,n=i/t,s,r,o=0;if(n<=.5){var a=n*2;s=Math.round(a*200),r=200}else{var a=(n-.5)*2;s=200,r=Math.round((1-a)*200)}return"rgba("+s+", "+r+", "+o+", "+e+")"}function pr(){if(!sn){var i=document.createElement("div");i.id="debug-logo-container",i.style.position="fixed",i.style.zIndex="1000",i.style.width="21px",i.style.height="21px",i.style.backgroundColor="rgba(0, 0, 0, 0.7)",i.style.border="3px solid "+Ln(ee.latencySimulation.delay,.7),i.style.borderRadius="50%",i.style.padding="10px",i.style.boxSizing="content-box",i.style.display="flex",i.style.justifyContent="center",i.style.alignItems="center",i.style.boxShadow="0 2px 8px rgba(0, 0, 0, 0.3)",i.style.transition="border-color 0.3s ease, background-color 0.3s ease",i.style.cursor="pointer",gs(),i.addEventListener("mouseenter",function(){i.style.backgroundColor="rgba(0, 0, 0, 0.9)",i.style.borderColor=Ln(ee.latencySimulation.delay,.9)}),i.addEventListener("mouseleave",function(){i.style.backgroundColor="rgba(0, 0, 0, 0.7)",i.style.borderColor=Ln(ee.latencySimulation.delay,.7)});var e=document.createElement("div");e.style.width="100%",e.style.height="100%",e.style.display="flex",e.style.justifyContent="center",e.style.alignItems="center",e.insertAdjacentHTML("beforeend",Ha),i.appendChild(e),document.body.appendChild(i),sl(i),gs()}}function sl(i){var e=document.createElement("div");e.id="debug-menu",e.style.position="fixed",e.style.backgroundColor="rgba(0, 0, 0, 0.95)",e.style.color="#fff",e.style.padding="0 0 8px 0",e.style.borderRadius="6px",e.style.fontFamily="system-ui, -apple-system, sans-serif",e.style.fontSize="12px",e.style.zIndex="1001",e.style.minWidth="200px",e.style.boxShadow="0 4px 12px rgba(0, 0, 0, 0.5)",e.style.display="none",e.style.overflow="hidden";var t=document.createElement("div");t.style.padding="6px 12px",t.style.cursor="default",t.style.backgroundColor="rgba(255, 255, 255, 0.1)",t.style.borderBottom="1px solid rgba(255, 255, 255, 0.15)",t.style.marginBottom="4px",t.style.borderTopLeftRadius="6px",t.style.borderTopRightRadius="6px";var n=document.createElement("div");n.id="debug-menu-host",n.style.fontSize="11px",n.style.color="#fff",n.style.fontFamily="monospace",n.style.whiteSpace="nowrap",n.style.overflow="hidden",n.style.textOverflow="ellipsis",n.style.textAlign="center",n.style.fontWeight="500";function s(){var I="N/A";if(Ke.size>0){var N=Ke.values().next().value;N&&N.host&&(I=N.host)}n.textContent=I}s(),t.appendChild(n),e.appendChild(t);var r=document.createElement("div");r.style.padding="8px 12px",r.style.cursor="default";var o=document.createElement("div");o.style.marginBottom="8px",o.style.display="flex",o.style.alignItems="center",o.style.justifyContent="space-between";var a=document.createElement("span");a.id="latency-value",a.style.color="#888",a.style.fontSize="11px",a.textContent=ee.latencySimulation.delay+"ms";var l=document.createElement("span");l.textContent="Simulate latency",o.appendChild(l),o.appendChild(a);var d=document.createElement("input");d.type="range",d.min="0",d.max=ee.maxLatency.toString(),d.value=ee.latencySimulation.delay.toString(),d.style.border="none",d.style.width="100%",d.style.height="20px",d.style.padding="0",d.style.margin="0",d.style.outline="none",d.style.cursor="pointer",d.style.webkitAppearance="none",d.style.appearance="none",d.style.background="transparent",d.id="latency-slider";function c(I,N,F){var H=(I-N)/(F-N),$,K,j=0;if(H<=.5){var Y=H*2;$=Math.round(Y*200),K=200}else{var Y=(H-.5)*2;$=200,K=Math.round((1-Y)*200)}return"rgb("+$+", "+K+", "+j+")"}function f(I){var N=c(I,0,ee.maxLatency),F=I/ee.maxLatency*100,H=50,$;if(I<=ee.maxLatency/2){var K=c(ee.maxLatency/2,0,ee.maxLatency);$=`linear-gradient(to right, #00c800 0%, ${K} ${F}%, #333 ${F}%, #333 100%)`}else{var K=c(ee.maxLatency/2,0,ee.maxLatency);$=`linear-gradient(to right, #00c800 0%, ${K} ${H}%, ${N} ${F}%, #333 ${F}%, #333 100%)`}var j="latency-slider-style",Y=document.getElementById(j);Y&&Y.remove();var ve=document.createElement("style");ve.id=j,ve.textContent=`
|
|
33
|
+
#latency-slider::-webkit-slider-runnable-track {
|
|
34
|
+
background: ${$};
|
|
35
|
+
height: 6px;
|
|
36
|
+
border-radius: 3px;
|
|
37
|
+
border: none;
|
|
38
|
+
}
|
|
39
|
+
#latency-slider::-moz-range-track {
|
|
40
|
+
background: ${$};
|
|
41
|
+
height: 6px;
|
|
42
|
+
border-radius: 3px;
|
|
43
|
+
border: none;
|
|
44
|
+
}
|
|
45
|
+
`,document.head.appendChild(ve)}f(parseInt(d.value));var h=document.createElement("style");h.textContent=`
|
|
46
|
+
#latency-slider {
|
|
47
|
+
background: transparent !important;
|
|
48
|
+
background-color: transparent !important;
|
|
49
|
+
}
|
|
50
|
+
#latency-slider::-webkit-slider-thumb {
|
|
51
|
+
-webkit-appearance: none;
|
|
52
|
+
appearance: none;
|
|
53
|
+
width: 16px;
|
|
54
|
+
height: 16px;
|
|
55
|
+
border-radius: 50%;
|
|
56
|
+
background: #fff;
|
|
57
|
+
background-color: #fff;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
border: 2px solid #888;
|
|
60
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
61
|
+
transition: transform 0.1s ease, box-shadow 0.1s ease;
|
|
62
|
+
margin-top: -5px;
|
|
63
|
+
}
|
|
64
|
+
#latency-slider::-webkit-slider-thumb:hover {
|
|
65
|
+
transform: scale(1.1);
|
|
66
|
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
|
|
67
|
+
}
|
|
68
|
+
#latency-slider::-moz-range-thumb {
|
|
69
|
+
width: 16px;
|
|
70
|
+
height: 16px;
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
background: #fff;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
border: 2px solid #888;
|
|
75
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
76
|
+
transition: transform 0.1s ease, box-shadow 0.1s ease;
|
|
77
|
+
}
|
|
78
|
+
#latency-slider::-moz-range-thumb:hover {
|
|
79
|
+
transform: scale(1.1);
|
|
80
|
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
|
|
81
|
+
}
|
|
82
|
+
`,document.head.appendChild(h);function p(){var I=document.getElementById("debug-logo-container");I&&(I.style.borderColor=Ln(ee.latencySimulation.delay,.7))}d.addEventListener("input",function(){var I=parseInt(d.value);a.textContent=I+"ms",ee.latencySimulation.delay=I,ee.latencySimulation.enabled=I>0,f(I),p(),Rs()}),r.appendChild(o),r.appendChild(d),e.appendChild(r);var m=document.createElement("div");m.style.height="1px",m.style.backgroundColor="rgba(255, 255, 255, 0.15)",m.style.margin="4px 0",e.appendChild(m);var u=document.createElement("div");u.style.padding="8px 12px",u.style.cursor="pointer",u.style.transition="background-color 0.2s",u.style.display="flex",u.style.alignItems="center",u.style.gap="8px";var g=document.createElement("span");g.style.display="inline-flex",g.style.alignItems="center",g.style.width="16px",g.style.height="16px",g.innerHTML=Ja.replace('height="200px" width="200px"','height="16" width="16"');var b=document.createElement("span");b.textContent="Preferences",u.appendChild(g),u.appendChild(b),u.addEventListener("mouseenter",function(){u.style.backgroundColor="rgba(255, 255, 255, 0.1)"}),u.addEventListener("mouseleave",function(){u.style.backgroundColor="transparent"}),u.addEventListener("click",function(I){I.stopPropagation(),S=!1,e.style.display="none",C&&(clearInterval(C),C=null),rl()}),e.appendChild(u),document.body.appendChild(e);var S=!1,C=null;i.addEventListener("click",function(I){I.stopPropagation(),S=!S,e.style.display=S?"block":"none",S?(s(),C=setInterval(s,1e3)):C&&(clearInterval(C),C=null)}),document.addEventListener("click",function(I){S&&!e.contains(I.target)&&!i.contains(I.target)&&(S=!1,e.style.display="none",C&&(clearInterval(C),C=null))})}function rl(){var i=document.getElementById("debug-settings-modal");i&&i.remove();var e=tl();e.id="debug-settings-overlay";var t=document.createElement("div");t.id="debug-settings-modal",t.style.position="relative",t.style.backgroundColor="rgba(30, 30, 30, 0.98)",t.style.borderRadius="8px",t.style.width="90%",t.style.maxWidth="500px",t.style.maxHeight="90vh",t.style.overflowY="auto",t.style.boxShadow="0 8px 32px rgba(0, 0, 0, 0.5)",t.style.color="#fff",t.style.fontFamily="system-ui, -apple-system, sans-serif";var n=document.createElement("div");n.style.display="flex",n.style.justifyContent="space-between",n.style.alignItems="center",n.style.padding="20px 24px",n.style.borderBottom="1px solid rgba(255, 255, 255, 0.1)";var s=document.createElement("h2");s.textContent="Preferences",s.style.margin="0",s.style.fontSize="18px",s.style.fontWeight="600";var r=document.createElement("button");r.innerHTML="×",r.style.background="none",r.style.border="none",r.style.color="#fff",r.style.fontSize="24px",r.style.cursor="pointer",r.style.padding="0",r.style.width="32px",r.style.height="32px",r.style.display="flex",r.style.alignItems="center",r.style.justifyContent="center",r.style.borderRadius="4px",r.style.transition="background-color 0.2s",r.addEventListener("mouseenter",function(){r.style.backgroundColor="rgba(255, 255, 255, 0.1)"}),r.addEventListener("mouseleave",function(){r.style.backgroundColor="transparent"}),r.addEventListener("click",function(){e.remove()}),n.appendChild(s),n.appendChild(r),t.appendChild(n);var o=document.createElement("div");o.style.padding="20px 24px",o.style.borderBottom="1px solid rgba(255, 255, 255, 0.1)",o.style.display="flex",o.style.justifyContent="space-between",o.style.alignItems="center",o.style.gap="16px";var a=document.createElement("div");a.style.flex="1";var l=document.createElement("div");l.style.fontSize="14px",l.style.fontWeight="600",l.style.marginBottom="4px",l.textContent="Position";var d=document.createElement("div");d.style.fontSize="12px",d.style.color="rgba(255, 255, 255, 0.7)",d.textContent="Adjust the placement of the panels.",a.appendChild(l),a.appendChild(d);var c=document.createElement("select");c.style.minWidth="150px",c.style.padding="8px 12px",c.style.backgroundColor="rgba(255, 255, 255, 0.1)",c.style.border="1px solid rgba(255, 255, 255, 0.2)",c.style.borderRadius="4px",c.style.color="#fff",c.style.fontSize="14px",c.style.cursor="pointer",c.style.outline="none";var f=[{value:"bottom-left",label:"Bottom Left"},{value:"bottom-right",label:"Bottom Right"},{value:"top-left",label:"Top Left"},{value:"top-right",label:"Top Right"}];f.forEach(function(N){var F=document.createElement("option");F.value=N.value,F.textContent=N.label,ee.panelPosition.position===N.value&&(F.selected=!0),c.appendChild(F)}),c.addEventListener("change",function(){ee.panelPosition.position=c.value,gs(),Rs()}),o.appendChild(a),o.appendChild(c),t.appendChild(o);var h=document.createElement("div");h.style.padding="20px 24px",h.style.borderBottom="1px solid rgba(255, 255, 255, 0.1)";var p=document.createElement("div");p.style.fontSize="14px",p.style.fontWeight="600",p.style.marginBottom="4px",p.textContent="Disable Dev Tools";var m=document.createElement("div");m.style.fontSize="12px",m.style.color="rgba(255, 255, 255, 0.7)",m.style.marginBottom="8px",m.innerHTML='To disable this UI completely, remove the <code style="background: rgba(255, 255, 255, 0.1); padding: 2px 6px; border-radius: 3px; font-family: monospace; font-size: 11px;">debug.js</code> script from your HTML file.',h.appendChild(p),h.appendChild(m),t.appendChild(h);var u=document.createElement("div");u.style.padding="20px 24px",u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="center",u.style.gap="16px";var g=document.createElement("div");g.style.flex="1";var b=document.createElement("div");b.style.fontSize="14px",b.style.fontWeight="600",b.style.marginBottom="4px",b.textContent="Hide Dev Tools for this session";var S=document.createElement("div");S.style.fontSize="12px",S.style.color="rgba(255, 255, 255, 0.7)",S.textContent="Hide Dev Tools until you refresh the page.",g.appendChild(b),g.appendChild(S);var C=document.createElement("button");C.textContent="Hide",C.style.padding="8px 16px",C.style.backgroundColor="rgba(255, 255, 255, 0.1)",C.style.border="1px solid rgba(255, 255, 255, 0.2)",C.style.borderRadius="4px",C.style.color="#fff",C.style.fontSize="14px",C.style.cursor="pointer",C.style.transition="background-color 0.2s",C.style.display="flex",C.style.alignItems="center",C.style.gap="8px",C.style.flexShrink="0",C.insertAdjacentHTML("afterbegin",Ka),C.addEventListener("mouseenter",function(){C.style.backgroundColor="rgba(255, 255, 255, 0.15)"}),C.addEventListener("mouseleave",function(){C.style.backgroundColor="rgba(255, 255, 255, 0.1)"}),C.addEventListener("click",function(){al(),e.remove()}),u.appendChild(g),u.appendChild(C),t.appendChild(u),e.appendChild(t),document.body.appendChild(e),zn(e);var I=e.remove.bind(e);e.remove=function(){Bi(e),I()},t.addEventListener("mousedown",function(N){zn(e)}),e.addEventListener("click",function(N){N.target===e&&e.remove()})}function il(i){var P;var e=Ke.get(i);if(!e||!e.room){console.warn("Room not found for panel:",i);return}var t=e.room,n=e.messageTypes;if(!n){console.warn("No message types available for this room");return}var s=document.getElementById("debug-send-messages-modal");s&&s.remove();var r={},o=null,a={current:null};const l=()=>{var M;r.element&&(r.element.style.backgroundColor=(M=t.connection)!=null&&M.isOpen?"#22c55e":"#ef4444")};a.current=l,t.onLeave(l);const d=Li({id:"debug-send-messages-modal",width:"400px",minWidth:"300px",maxWidth:"90vw",maxHeight:"90vh",room:t,trackOnLeave:!0,onLeaveCallback:a}),c=Pi({title:e.roomName+" - Send Message",modal:d,statusDot:!0,statusColor:(P=t.connection)!=null&&P.isOpen?"#22c55e":"#ef4444",statusDotRef:r});d.appendChild(c.header),nl(d,c.header),l();var f=document.createElement("div");f.style.padding="8px",f.style.overflowY="auto",f.style.backgroundColor="#1e1e1e";var h=document.createElement("label");h.textContent="Message Type",h.style.display="block",h.style.fontSize="11px",h.style.fontWeight="600",h.style.marginBottom="4px",h.style.color="rgba(255, 255, 255, 0.9)";var p=document.createElement("select");p.style.width="100%",p.style.padding="6px 8px",p.style.backgroundColor="rgba(255, 255, 255, 0.1)",p.style.border="1px solid rgba(255, 255, 255, 0.2)",p.style.borderRadius="4px",p.style.color="#fff",p.style.fontSize="12px",p.style.cursor="pointer",p.style.outline="none",p.style.marginBottom="12px";var m=document.createElement("option");m.value="",m.textContent="Select a message type",m.disabled=!0,m.selected=!0,p.appendChild(m),Object.keys(n).forEach(function(M){var T=document.createElement("option");T.value=M,T.style.color="#000",T.textContent=M,p.appendChild(T)});var u=document.createElement("option");u.value="*",u.textContent="* (Custom)",p.appendChild(u),f.appendChild(h),f.appendChild(p);var g=document.createElement("div");g.style.display="none",g.style.marginBottom="12px";var b=document.createElement("label");b.textContent="Message Type",b.style.display="block",b.style.fontSize="11px",b.style.fontWeight="600",b.style.marginBottom="4px",b.style.color="rgba(255, 255, 255, 0.9)";var S=document.createElement("input");S.type="text",S.placeholder="Enter message type name",S.style.width="100%",S.style.padding="6px 8px",S.style.backgroundColor="rgba(255, 255, 255, 0.05)",S.style.border="1px solid rgba(255, 255, 255, 0.2)",S.style.borderRadius="4px",S.style.color="#fff",S.style.fontSize="11px",S.style.fontFamily="monospace",S.style.outline="none",g.appendChild(b),g.appendChild(S),f.appendChild(g);var C=document.createElement("div");C.style.display="none",C.style.marginBottom="12px";var I=document.createElement("label");I.textContent="Payload",I.style.display="block",I.style.fontSize="11px",I.style.fontWeight="600",I.style.marginBottom="4px",I.style.color="rgba(255, 255, 255, 0.9)";var N=document.createElement("div");N.style.backgroundColor="rgba(255, 255, 255, 0.05)",N.style.border="1px solid rgba(255, 255, 255, 0.2)",N.style.borderRadius="4px",N.style.padding="8px",N.style.fontFamily="monospace",N.style.fontSize="11px";var F=document.createElement("textarea");F.style.width="100%",F.style.minHeight="80px",F.style.padding="6px 8px",F.style.backgroundColor="rgba(255, 255, 255, 0.05)",F.style.border="1px solid rgba(255, 255, 255, 0.2)",F.style.borderRadius="4px",F.style.color="#fff",F.style.fontSize="11px",F.style.fontFamily="monospace",F.style.outline="none",F.style.resize="vertical",F.placeholder="{}",F.value="{}",C.appendChild(I),C.appendChild(N),C.appendChild(F),f.appendChild(C);var H=document.createElement("div");H.style.display="none",H.style.padding="6px 8px",H.style.backgroundColor="rgba(220, 38, 38, 0.2)",H.style.border="1px solid rgba(220, 38, 38, 0.4)",H.style.borderRadius="4px",H.style.marginBottom="8px",H.style.fontSize="11px",H.style.color="#fca5a5",f.appendChild(H);var $={},K="";p.addEventListener("change",function(){var M=p.value;if(K=M,M){M==="*"?(g.style.display="block",S.focus()):g.style.display="none",C.style.display="block",H.style.display="none",$={},N.innerHTML="";var T=n[M];T&&T.properties&&Object.keys(T.properties).length>0?(F.style.display="none",N.style.display="block",Object.keys(T.properties).forEach(function(L){var _=T.properties[L],V=document.createElement("div");V.style.marginBottom="8px";var U=document.createElement("label");U.textContent=L,T.required&&T.required.includes(L)&&(U.textContent+=" *"),U.style.display="block",U.style.fontSize="10px",U.style.marginBottom="3px",U.style.color="rgba(255, 255, 255, 0.8)";var z;if(_.type==="boolean"?(z=document.createElement("input"),z.type="checkbox",z.style.width="16px",z.style.height="16px",z.style.cursor="pointer"):_.type==="number"||_.type==="integer"?(z=document.createElement("input"),z.type="number",_.type==="integer"&&(z.step="1"),z.style.width="100%",z.style.padding="4px 6px",z.style.backgroundColor="rgba(255, 255, 255, 0.05)",z.style.border="1px solid rgba(255, 255, 255, 0.2)",z.style.borderRadius="3px",z.style.color="#fff",z.style.fontSize="11px",z.style.outline="none"):(z=document.createElement("input"),z.type="text",z.style.width="100%",z.style.padding="4px 6px",z.style.backgroundColor="rgba(255, 255, 255, 0.05)",z.style.border="1px solid rgba(255, 255, 255, 0.2)",z.style.borderRadius="3px",z.style.color="#fff",z.style.fontSize="11px",z.style.outline="none"),_.description){var X=document.createElement("div");X.textContent=_.description,X.style.fontSize="9px",X.style.color="rgba(255, 255, 255, 0.5)",X.style.marginTop="2px",V.appendChild(U),V.appendChild(z),V.appendChild(X)}else V.appendChild(U),V.appendChild(z);N.appendChild(V),$[L]={input:z,schema:_}})):(F.style.display="block",N.style.display="none",F.value="{}",T?F.placeholder="{}":F.placeholder=`Enter JSON payload (no message format defined)
|
|
83
|
+
|
|
84
|
+
Example:
|
|
85
|
+
{
|
|
86
|
+
"key": "value"
|
|
87
|
+
}`)}else C.style.display="none"});var j=document.createElement("button");j.textContent="Send",j.style.width="100%",j.style.padding="8px 12px",j.style.backgroundColor="#8b5cf6",j.style.border="none",j.style.borderRadius="4px",j.style.color="#fff",j.style.fontSize="12px",j.style.fontWeight="600",j.style.cursor="pointer",j.style.transition="background-color 0.2s";var Y=!1,ve="#7c3aed",w="#8b5cf6";j.addEventListener("mouseenter",function(){!Y&&!j.disabled&&(j.style.backgroundColor=ve)}),j.addEventListener("mouseleave",function(){!Y&&!j.disabled&&(j.style.backgroundColor=w)}),o=function(){var T;const M=(T=t.connection)==null?void 0:T.isOpen;r.element&&(r.element.style.backgroundColor=M?"#22c55e":"#ef4444"),j.disabled=!M,M?Y||(j.style.backgroundColor=w,j.style.cursor="pointer",j.style.opacity="1"):(j.style.backgroundColor="#6b7280",j.style.cursor="not-allowed",j.style.opacity="0.5")},t.onLeave.remove(a.current),t.onLeave(o),a.current=o,o(),j.addEventListener("click",function(){var le;if(H.style.display="none",!((le=t.connection)!=null&&le.isOpen)){H.textContent="Cannot send message: Room is not connected",H.style.display="block";return}if(!K){H.textContent="Please select a message type",H.style.display="block";return}var M=K;if(K==="*"&&(M=S.value.trim(),!M)){H.textContent="Please enter a message type name",H.style.display="block";return}try{var T;if(Object.keys($).length>0){T={};var L=n[K];for(var _ in $){var V=$[_],U=V.input,z=V.schema,X;z.type==="boolean"?X=U.checked:z.type==="number"||z.type==="integer"?X=U.value?parseFloat(U.value):void 0:X=U.value||void 0,(X!==void 0||L.required&&L.required.includes(_))&&(T[_]=X)}}else T=JSON.parse(F.value);t.send(M,T),Y=!0,j.textContent="Message sent!",j.style.backgroundColor="#22c55e",j.style.cursor="default",setTimeout(function(){Y=!1,j.textContent="Send",j.style.backgroundColor=w,j.style.cursor="pointer"},800)}catch(we){H.textContent="Error: "+we.message,H.style.display="block"}}),f.appendChild(j),d.appendChild(f),document.body.appendChild(d)}function ol(i){var Ps;var e=Ke.get(i);if(!e||!e.room){console.warn("Room not found for panel:",i);return}var t=e.room,n=document.getElementById("debug-state-inspector-modal");n&&n.remove();var s=null;try{var r=localStorage.getItem("colyseus-state-inspector-preferences");r&&(s=JSON.parse(r))}catch{}var o=600,a=500,l="50%",d="50%",c="translate(-50%, -50%)";if(s&&(s.width&&s.width>=300&&(o=s.width),s.height&&s.height>=200&&(a=s.height),s.left!==void 0&&s.top!==void 0)){var f=window.innerWidth-o,h=window.innerHeight-a,p=Math.max(0,Math.min(s.left,f)),m=Math.max(0,Math.min(s.top,h));l=p+"px",d=m+"px",c="none"}function u(){try{var B=S.getBoundingClientRect(),D={width:B.width,height:B.height,left:B.left,top:B.top};localStorage.setItem("colyseus-state-inspector-preferences",JSON.stringify(D))}catch{}}var g={};const b=()=>{var B;g.element&&(g.element.style.backgroundColor=(B=t.connection)!=null&&B.isOpen?"#22c55e":"#ef4444")};t.onLeave(b);const S=Li({id:"debug-state-inspector-modal",width:o+"px",height:a+"px",minWidth:"300px",minHeight:"200px",maxWidth:"90vw",maxHeight:"90vh",top:d,left:l,transform:c,room:t,trackOnLeave:!0,onLeaveCallback:b}),C=Pi({title:`${e.roomName} - State Viewer`,modal:S,statusDot:!0,statusColor:(Ps=t.connection)!=null&&Ps.isOpen?"#22c55e":"#ef4444",statusDotRef:g}),I=C.header,N=C.closeButton;S.appendChild(I),b();var F=document.createElement("div");F.style.padding="8px",F.style.overflowY="auto",F.style.flex="1",F.style.minHeight="0",F.style.backgroundColor="#1e1e1e",F.id="debug-state-content",F.addEventListener("click",function(B){var D=B.target.closest("[data-expand-button]");D&&(B.stopPropagation(),T(D))});var H=new Set;function $(B){var D=document.createElement("div");return D.textContent=B,D.innerHTML}function K(B){if(B==null)return!1;var D=typeof B,W=D==="object"&&!(B instanceof Array),q=D==="object"&&typeof B.forEach=="function",te=B instanceof Array;return W||te||q}function j(B){return typeof B=="string"&&B.startsWith('"')?"#CE9178":"#DCDCAA"}function Y(B,D){var W=B===0;return{isRoot:W,initialDisplay:W||D?"block":"none",initialIcon:W||D?"▼":"▶",rootClass:W?' data-root-node="true"':""}}function ve(B){return B!=null?'<span style="color: #909090; font-size: 11px; margin-left: 4px;">(ref: '+B+")</span>":""}function w(B,D,W,q){var te="<div data-expand-button"+B.rootClass+' style="display: flex; align-items: center; cursor: '+(B.isRoot?"default":"pointer")+'; user-select: none; margin: 0; padding: 1px 0;" onmouseover="'+(B.isRoot?"":"this.style.backgroundColor='rgba(255,255,255,0.05)'")+'" onmouseout="'+(B.isRoot?"":"this.style.backgroundColor='transparent'")+'">';return te+='<span data-expand-icon style="margin-right: 4px; color: #858585; font-size: 10px; width: 10px; display: inline-block; text-align: center; user-select: none;">'+B.initialIcon+"</span>",D&&(te+='<span style="color: '+j(D)+';">'+$(String(D))+"</span>"),q!=null&&q!=="?"&&(te+=' <span style="color: #858585;">('+q+") </span>"),te+=W,te+="</div>",te}function P(B,D,W,q,te,be){if(K(D))return te!==null?M(D,W,String(B),q,te):M(D,W,String(B),q);var ye=W*6,pe='<div style="margin-left: '+ye+'px; padding-left: 14px;">';if(te!==null){var Ie=be?"#CE9178":"#DCDCAA";pe+='<span style="color: '+Ie+';">'+(be?'"'+$(String(te))+'"':$(String(te)))+'</span><span style="color: #858585;">: </span>'}else pe+='<span style="color: #DCDCAA;">'+$(String(B))+'</span><span style="color: #858585;">: </span>';return pe+=M(D,W+1,String(B),q),pe+="</div>",pe}function M(B,D=0,W="",q="",te=null){var be=10;if(D>be)return'<span style="color: #858585; font-style: italic;">[Max depth reached]</span>';if(B===null)return'<span style="color: #858585;">null</span>';if(B===void 0)return'<span style="color: #858585;">undefined</span>';var ye=typeof B,pe=D*6,Ie=B["~refId"],je="state-node-"+Ie,at=q?q+"."+(W||""):W||"root",Os=H.has(at),Cn=ve(Ie);if(ye==="string")return'<span style="color: #CE9178;">"'+$(String(B))+'"</span>';if(ye==="number")return'<span style="color: #B5CEA8;">'+B+"</span>";if(ye==="boolean")return'<span style="color: #569CD6;">'+B+"</span>";var Fs=typeof B.forEach=="function",$s=Fs&&(B.size||B.length)||null;if(Fs){var Ki=$s!==null?$s:"?",Wn=je+"-content",Et=Y(D,Os),zt=te!==null?te:Et.isRoot?"State":"",xe='<div style="margin-left: '+pe+'px;" data-path="'+$(at)+'">';xe+=w(Et,zt,Cn,Ki),xe+='<div id="'+Wn+'" style="display: '+Et.initialDisplay+';">';var Zi=B instanceof Set||B.constructor&&B.constructor.name==="Set";try{B.forEach(function(Tn,_t){if(Zi)xe+=M(Tn,D+1,String(_t),at);else{var eo=typeof _t=="number",to=eo?"["+String(_t)+"]":String(_t);xe+=P(_t,Tn,D+1,at,to,typeof _t=="string")}})}catch(Tn){var Qi=(D+1)*6;xe+='<div style="margin-left: '+Qi+'px; color: #e74856;">Error iterating: '+$(Tn.message)+"</div>"}return xe+="</div>",xe+="</div>",xe}if(ye==="object"){var Gn=Object.keys(B),Wn=je+"-content",Et=Y(D,Os),zt=te!==null?te:Et.isRoot?"state":"",xe='<div style="margin-left: '+pe+'px;" data-path="'+$(at)+'">';if(Gn.length===0)zt?xe+='<span style="color: '+j(zt)+';">'+$(String(zt))+'</span><span style="color: #858585;"> {}</span>'+Cn:xe+='<span style="color: #858585;">{}</span>'+Cn;else{xe+=w(Et,zt,Cn,null),xe+='<div id="'+Wn+'" style="display: '+Et.initialDisplay+';">';for(var Xn=0;Xn<Gn.length;Xn++){var Sn=Gn[Xn];Sn!=="~refId"&&(xe+=P(Sn,B[Sn],D+1,at,Sn,!1))}xe+="</div>"}return xe+="</div>",xe}return'<span style="color: #858585;">'+$(String(B))+"</span>"}function T(B){var D=B.nextElementSibling,W=B.querySelector("[data-expand-icon]");if(D&&D.style){var q=D.style.display==="none";D.style.display=q?"block":"none",W&&(W.textContent=q?"▼":"▶");var te=B.closest("[data-path]");if(te){var be=te.getAttribute("data-path");q?H.add(be):H.delete(be)}}}function L(){try{for(var B=new Set,D=F.querySelectorAll("[data-expand-button]"),W=0;W<D.length;W++){var q=D[W],te=q.closest("[data-path]");if(te){var be=te.getAttribute("data-path"),ye=q.nextElementSibling;ye&&ye.style&&ye.style.display!=="none"&&B.add(be)}}var pe=new Set;H.forEach(function(je){pe.add(je)}),B.forEach(function(je){pe.add(je)}),H=pe;var Ie=t.state||{};F.innerHTML=`<div style="font-family: 'Consolas', 'Monaco', 'Courier New', monospace; font-size: 12px; line-height: 1.5; color: #d4d4d4; padding: 8px;">`+M(Ie)+"</div>"}catch(je){F.innerHTML='<div style="color: #e74856; padding: 20px;">Error accessing room state: '+$(je.message)+"</div>"}}function _(B,D){var W,q=0;return function(){var be=this,ye=arguments,pe=Date.now(),Ie=D-(pe-q);Ie<=0||Ie>D?(W&&(clearTimeout(W),W=null),q=pe,B.apply(be,ye)):W||(W=setTimeout(function(){q=Date.now(),W=null,B.apply(be,ye)},Ie))}}var V=_(L,200);H.add("root"),L();const U=t.serializer.decoder.triggerChanges;t.serializer.decoder.triggerChanges=function(B){U==null||U.apply(this,arguments),V()},S.appendChild(F),document.body.appendChild(S);var z=!1,X=0,le=0,we=0,ke=0,Ze=!1,De=null,Ot=0,Ft=0,vt=0,ot=0,wt=0,bt=0;I.addEventListener("mousedown",function(B){const D=B.target;if(!(D.classList&&D.classList.contains("resize-handle"))&&!(D===N||N.contains(D))){z=!0,X=B.clientX,le=B.clientY;var W=S.getBoundingClientRect();we=W.left,ke=W.top,S.style.cursor="move",B.preventDefault()}});var Gi=function(B){if(Ze&&De){var D=B.clientX-Ot,W=B.clientY-Ft,q=vt,te=ot,be=wt,ye=bt;De.includes("e")&&(q=vt+D),De.includes("w")&&(q=vt-D,be=wt+D),De.includes("s")&&(te=ot+W),De.includes("n")&&(te=ot-W,ye=bt+W),q=Math.max(parseInt(S.style.minWidth)||300,Math.min(q,window.innerWidth-be)),te=Math.max(parseInt(S.style.minHeight)||200,Math.min(te,window.innerHeight-ye)),S.style.width=q+"px",S.style.height=te+"px",S.style.left=be+"px",S.style.top=ye+"px",S.style.transform="none"}else if(z){var D=B.clientX-X,W=B.clientY-le,pe=we+D,Ie=ke+W,je=window.innerWidth-S.offsetWidth,at=window.innerHeight-S.offsetHeight;pe=Math.max(0,Math.min(pe,je)),Ie=Math.max(0,Math.min(Ie,at)),S.style.left=pe+"px",S.style.top=Ie+"px",S.style.transform="none"}};document.addEventListener("mousemove",Gi);var Xi=function(){z&&(z=!1,S.style.cursor="",u()),Ze&&(Ze=!1,De=null,u())};document.addEventListener("mouseup",Xi);var Ls=8,$t=12,Yi=["n","s","e","w"],qi=["nw","ne","sw","se"];Yi.forEach(function(B){var D=document.createElement("div");D.className="resize-handle resize-"+B,D.style.position="absolute",D.style.backgroundColor="transparent",D.style.zIndex="10000",D.style.pointerEvents="auto",B==="n"||B==="s"?(D.style.height=Ls+"px",D.style.left=$t+"px",D.style.right=$t+"px",B==="n"?(D.style.top="0",D.style.cursor="n-resize"):(D.style.bottom="0",D.style.cursor="s-resize")):(D.style.width=Ls+"px",D.style.top=$t+"px",D.style.bottom=$t+"px",B==="e"?(D.style.right="0",D.style.cursor="e-resize"):(D.style.left="0",D.style.cursor="w-resize")),D.addEventListener("mousedown",function(W){W.stopPropagation(),W.preventDefault(),Ze=!0,De=B,Ot=W.clientX,Ft=W.clientY;var q=S.getBoundingClientRect();vt=q.width,ot=q.height,wt=q.left,bt=q.top}),S.appendChild(D)}),qi.forEach(function(B){var D=document.createElement("div");D.className="resize-handle resize-"+B,D.style.position="absolute",D.style.backgroundColor="transparent",D.style.zIndex="10002",D.style.pointerEvents="auto",D.style.width=$t+"px",D.style.height=$t+"px",B==="nw"?(D.style.top="0",D.style.left="0",D.style.cursor="nw-resize"):B==="ne"?(D.style.top="0",D.style.right="0",D.style.cursor="ne-resize"):B==="sw"?(D.style.bottom="0",D.style.left="0",D.style.cursor="sw-resize"):B==="se"&&(D.style.bottom="0",D.style.right="0",D.style.cursor="se-resize"),D.addEventListener("mousedown",function(W){W.stopPropagation(),W.preventDefault(),Ze=!0,De=B,Ot=W.clientX,Ft=W.clientY;var q=S.getBoundingClientRect();vt=q.width,ot=q.height,wt=q.left,bt=q.top}),S.appendChild(D)});var Ji=S.remove;S.remove=function(){t.serializer.decoder.triggerChanges=U,Ji.call(this)}}function gs(){var i=document.getElementById("debug-logo-container"),e=document.getElementById("debug-menu");document.querySelectorAll('[id^="debug-panel-"]');var t={"bottom-right":{bottom:"14px",right:"14px",top:"auto",left:"auto"},"bottom-left":{bottom:"14px",left:"14px",top:"auto",right:"auto"},"top-left":{top:"14px",left:"14px",bottom:"auto",right:"auto"},"top-right":{top:"14px",right:"14px",bottom:"auto",left:"auto"}},n=t[ee.panelPosition.position]||t["bottom-right"];i&&(i.style.bottom=n.bottom,i.style.right=n.right,i.style.top=n.top,i.style.left=n.left),e&&(ee.panelPosition.position.startsWith("bottom")?(e.style.bottom="60px",e.style.top="auto"):(e.style.top="60px",e.style.bottom="auto"),e.style.right=n.right,e.style.left=n.left),Bs()}function al(){sn=!0,Rs();var i=document.getElementById("debug-logo-container"),e=document.getElementById("debug-menu"),t=document.querySelectorAll('[id^="debug-panel-"]');i&&(i.style.display="none"),e&&(e.style.display="none"),t.forEach(function(n){n.style.display="none"})}function gr(i){if(i)i<1&&(i=1);else return"0 B";var e=1024,t=["B","KB","MB","GB"],n=Math.floor(Math.log(i)/Math.log(e));return(Math.round(i)/Math.pow(e,n)).toFixed(1)+" "+t[n]}function ll(i,e){var t=document.getElementById("debug-panel-"+i);if(t)return t;var n=document.createElement("div");n.id="debug-panel-"+i,n.style.position="fixed",n.style.backgroundColor="rgba(0, 0, 0, 0.85)",n.style.color="#fff",n.style.padding="8px",n.style.borderRadius="6px",n.style.fontFamily="monospace",n.style.fontSize="11px",n.style.zIndex="999",n.style.minWidth="180px",n.style.marginRight="6px",n.style.boxShadow="0 4px 12px rgba(0, 0, 0, 0.5)",n.style.display=sn?"none":"block";var s=document.createElement("div");s.id="debug-title-"+i,s.style.fontWeight="bold",s.style.marginBottom="6px",s.style.borderBottom="1px solid rgba(255, 255, 255, 0.15)",s.style.paddingBottom="4px",s.style.display="flex",s.style.alignItems="center",s.style.justifyContent="space-between",s.style.gap="8px",s.style.position="relative",s.innerHTML='<span id="debug-title-text-'+i+'"><span class="debug-room-name"></span><span class="debug-info-icon" style="display: inline-flex; align-items: center; margin-left: 4px; cursor: pointer; opacity: 0.6; vertical-align: middle;">'+qa.replace('height="200px" width="200px"','height="10" width="10"')+'</span></span><span id="debug-ping-'+i+'" style="font-size: 10px; font-weight: normal; color: #888;" title="Ping time">--</span>';var r=document.createElement("div");r.id="debug-tooltip-"+i,r.style.position="absolute",r.style.top="100%",r.style.left="0",r.style.marginTop="4px",r.style.padding="6px 8px",r.style.backgroundColor="rgba(0, 0, 0, 0.95)",r.style.color="#fff",r.style.borderRadius="4px",r.style.fontSize="10px",r.style.fontFamily="monospace",r.style.zIndex="1000",r.style.display="none",r.style.boxShadow="0 2px 8px rgba(0, 0, 0, 0.5)",r.style.lineHeight="1.4",r.innerHTML="<div><strong>Room ID:</strong> "+e.roomId+"</div><div><strong>Session ID:</strong> N/A</div>";var o=document.createElement("div");o.id="debug-content-"+i;var a=document.createElement("div");a.id="debug-actions-"+i,a.style.display="flex",a.style.gap="4px",a.style.marginTop="8px",a.style.paddingTop="6px",a.style.borderTop="1px solid rgba(255, 255, 255, 0.15)",a.style.position="relative";function l(I,N,F,H){var $=document.createElement("button");return $.id=I,$.style.display="flex",$.style.alignItems="center",$.style.gap="4px",$.style.padding="4px 8px",$.style.border="1px solid rgba(255, 255, 255, 0.2)",$.style.borderRadius="4px",$.style.background="rgba(255, 255, 255, 0.05)",$.style.color="#fff",$.style.fontSize="9px",$.style.cursor="pointer",$.style.transition="background 0.2s, border-color 0.2s",$.innerHTML='<span style="display: inline-flex; align-items: center; width: 12px; height: 12px;">'+N+"</span><span>"+F+"</span>",$.addEventListener("mouseenter",function(){$.style.background="rgba(255, 255, 255, 0.15)",$.style.borderColor="rgba(255, 255, 255, 0.3)"}),$.addEventListener("mouseleave",function(){$.style.background="rgba(255, 255, 255, 0.05)",$.style.borderColor="rgba(255, 255, 255, 0.2)"}),$.addEventListener("click",function(K){K.stopPropagation(),H()}),$}var d=l("debug-state-btn-"+i,Ya.replace('height="200px" width="200px"','height="12" width="12"'),"State",function(){ol(i)}),c=l("debug-message-btn-"+i,Xa.replace('height="200px" width="200px"','height="12" width="12"'),"Send",function(){il(i)});c.style.display="none";var f=l("debug-disconnect-btn-"+i,Qa.replace('height="200px" width="200px"','height="12" width="12"'),"Drop",function(){var I=Ke.get(i);I&&I.room&&I.room.connection&&I.room.connection.close(Ne.MAY_TRY_RECONNECT)}),h=!1;function p(){f.style.background="rgba(239, 68, 68, 0.2)",f.style.borderColor="rgba(239, 68, 68, 0.5)",f.style.color="#ef4444",f.style.animation="",f.style.pointerEvents="auto",f.style.opacity="1";var I=f.querySelector("span:last-child");I&&(I.textContent="Drop")}function m(){f.style.background="rgba(251, 146, 60, 0.3)",f.style.borderColor="rgba(251, 146, 60, 0.6)",f.style.color="#fb923c",f.style.animation="debug-pulse 1.5s ease-in-out infinite",f.style.pointerEvents="none",f.style.opacity="0.8";var I=f.querySelector("span:last-child");I&&(I.textContent="Reconnecting...")}if(!document.getElementById("debug-pulse-animation")){var u=document.createElement("style");u.id="debug-pulse-animation",u.textContent="@keyframes debug-pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }",document.head.appendChild(u)}p(),e.room&&(e.room.onDrop(function(){h=!0,m()}),e.room.onReconnect(function(){h=!1,p()})),f.addEventListener("mouseenter",function(){h||(f.style.background="rgba(239, 68, 68, 0.35)",f.style.borderColor="rgba(239, 68, 68, 0.7)")}),f.addEventListener("mouseleave",function(){h||(f.style.background="rgba(239, 68, 68, 0.2)",f.style.borderColor="rgba(239, 68, 68, 0.5)")}),s.appendChild(r);var g=s.querySelector(".debug-info-icon"),b=null,S=function(){b&&(clearTimeout(b),b=null),r.style.display="block"},C=function(){b=setTimeout(function(){r.style.display="none"},100)};return g&&(g.addEventListener("mouseenter",S),g.addEventListener("mouseleave",C)),r.style.pointerEvents="auto",r.addEventListener("mouseenter",S),r.addEventListener("mouseleave",C),a.appendChild(d),a.appendChild(c),a.appendChild(f),n.appendChild(s),n.appendChild(o),n.appendChild(a),document.body.firstChild?document.body.insertBefore(n,document.body.firstChild):document.body.appendChild(n),n}function Bs(){if(!sn){var i=Array.from(document.querySelectorAll('[id^="debug-panel-"]')).filter(function(o){return o.style.display!=="none"}).reverse(),e=48,t={"bottom-right":{start:{bottom:"14px",right:"14px",top:"auto",left:"auto"},offset:function(o,a){return{right:a+"px",left:"auto"}}},"bottom-left":{start:{bottom:"14px",left:"14px",top:"auto",right:"auto"},offset:function(o,a){return{left:a+"px",right:"auto"}}},"top-left":{start:{top:"14px",left:"14px",bottom:"auto",right:"auto"},offset:function(o,a){return{left:a+"px",right:"auto"}}},"top-right":{start:{top:"14px",right:"14px",bottom:"auto",left:"auto"},offset:function(o,a){return{right:a+"px",left:"auto"}}}},n=t[ee.panelPosition.position]||t["bottom-right"],s=14+e,r=s;i.forEach(function(o){Object.keys(n.start).forEach(function(l){o.style[l]=n.start[l]});var a=n.offset(o,r);Object.keys(a).forEach(function(l){o.style[l]=a[l]}),r+=o.offsetWidth+6})}}function Oi(i,e){var t="debug-content-"+i,n="debug-panel-"+i,s="debug-title-"+i,r=document.getElementById(t),o=document.getElementById(n);document.getElementById(s),(!r||!o)&&(o?(r=document.getElementById(t),document.getElementById(s)):(ll(i,e),r=document.getElementById(t),document.getElementById(s),Bs()));var a=document.getElementById("debug-title-text-"+i),l=a==null?void 0:a.querySelector(".debug-room-name");l&&(l.textContent=e.roomName),document.getElementById("debug-tooltip-"+i).innerHTML="<div><strong>Room ID:</strong> "+e.roomId+"</div><div><strong>Session ID:</strong> "+e.sessionId+"</div>";var d=e.pingMs!==null?e.pingMs+"ms":"--",c=e.pingMs!==null?e.pingMs<100?"#22c55e":e.pingMs<200?"#eab308":"#ef4444":"#888",f=document.getElementById("debug-ping-"+i);f&&(f.textContent=d,f.style.color=c);var h='<div style="line-height: 1.3;">';h+='<div style="font-size: 10px; display: flex; gap: 8px;">',h+='<div style="flex: 1;">',h+='<div style="margin-bottom: 4px;"><div style="display: flex; align-items: center; gap: 6px;"><span style="display: inline-flex; align-items: center; width: 18px; height: 18px; color: #FF9800;">'+Wa+'</span><span style="color: #FF9800;">'+gr(e.bytesSentPerSec)+'/s</span></div><div style="margin-left: 24px; opacity: 0.7; font-size: 9px;">'+e.messagesSentPerSec.toFixed(0)+" messages</div></div>",h+='<div><div style="display: flex; align-items: center; gap: 6px;"><span style="display: inline-flex; align-items: center; width: 18px; height: 18px; color: #2196F3;">'+Ga+'</span><span style="color: #2196F3;">'+gr(e.bytesReceivedPerSec)+'/s</span></div><div style="margin-left: 24px; opacity: 0.7; font-size: 9px;">'+e.messagesReceivedPerSec.toFixed(0)+" messages</div></div>",h+="</div>",h+='<div style="display: flex; flex-direction: column; gap: 4px; align-items: flex-end;">',h+='<canvas id="graph-sent-'+i+'" width="80" height="30" style="display: block;"></canvas>',h+='<canvas id="graph-received-'+i+'" width="80" height="30" style="display: block;"></canvas>',h+="</div>",h+="</div>",h+="</div>",r.innerHTML=h,setTimeout(function(){mr("graph-sent-"+i,e.bytesSentHistory,"#FF9800"),mr("graph-received-"+i,e.bytesReceivedHistory,"#2196F3")},10)}function mr(i,e,t){var n=document.getElementById(i);if(n){var s=n.getContext("2d"),r=n.width,o=n.height;if(s.clearRect(0,0,r,o),!(!e||e.length===0)){var a=Math.max.apply(Math,e),l=Math.min.apply(Math,e),d=a-l||1,c=2,f=r-c*2,h=o-c*2;s.strokeStyle="rgba(255, 255, 255, 0.1)",s.lineWidth=.5;for(var p=0;p<=4;p++){var m=c+h/4*p;s.beginPath(),s.moveTo(c,m),s.lineTo(r-c,m),s.stroke()}s.strokeStyle=t,s.lineWidth=1.5,s.beginPath();for(var p=0;p<e.length;p++){var u=c+f/(e.length-1||1)*p,g=(e[p]-l)/d,m=c+h-g*h;p===0?s.moveTo(u,m):s.lineTo(u,m)}s.stroke(),e.length>0&&(s.lineTo(r-c,o-c),s.lineTo(c,o-c),s.closePath(),s.fillStyle=t,s.globalAlpha=.2,s.fill(),s.globalAlpha=1)}}}function cl(i){var e=Date.now(),t=(e-i.lastUpdate)/1e3;if(t>0){i.bytesSentPerSec=i.bytesSentDelta/t,i.bytesReceivedPerSec=i.bytesReceivedDelta/t,i.messagesSentPerSec=i.messagesSentDelta/t,i.messagesReceivedPerSec=i.messagesReceivedDelta/t,i.bytesSentHistory.push(i.bytesSentPerSec),i.bytesReceivedHistory.push(i.bytesReceivedPerSec);var n=i.maxHistoryLength||60;i.bytesSentHistory.length>n&&(i.bytesSentHistory.shift(),i.bytesReceivedHistory.shift()),i.bytesSentDelta=0,i.bytesReceivedDelta=0,i.messagesSentDelta=0,i.messagesReceivedDelta=0,i.lastUpdate=e}Oi(i.uniquePanelId,i)}function fl(){Mt===null&&(Mt=setInterval(function(){Ke.forEach(function(i,e){cl(i)}),Ke.size===0&&(clearInterval(Mt),Mt=null)},1e3))}function dl(){function i(t){var p,m;if(!t)return t;const n=t.roomId,s=t.sessionId,r=s&&s!=="N/A"&&s!==""?s:n+"-"+Date.now()+"-"+Math.random().toString(36).substring(2,9),o=(p=t.connection)==null?void 0:p.transport,a=((m=o.ws)==null?void 0:m.url)||"N/A",l={uniquePanelId:r,roomId:n,roomName:t.name||"N/A",sessionId:s||"N/A",endpoint:a,host:new URL(a).host,room:t,bytesSent:0,bytesReceived:0,messagesSent:0,messagesReceived:0,bytesSentDelta:0,bytesReceivedDelta:0,messagesSentDelta:0,messagesReceivedDelta:0,bytesSentPerSec:0,bytesReceivedPerSec:0,messagesSentPerSec:0,messagesReceivedPerSec:0,lastUpdate:Date.now(),bytesSentHistory:[],bytesReceivedHistory:[],maxHistoryLength:60,messageTypes:null,pingMs:null,pingInterval:null};Ke.set(r,l),l.pingInterval=setInterval(()=>{t.ping(u=>{l.pingMs=u})},2e3),t.ping(u=>{l.pingMs=u}),t.onMessage("__playground_message_types",u=>{l.messageTypes=u;var g=document.getElementById("debug-message-btn-"+r);g&&(g.style.display=u?"flex":"none")});function d(u){var g=0;if(u instanceof Blob)g=u.size;else if(u instanceof ArrayBuffer)g=u.byteLength;else if(typeof u=="string")g=new Blob([u]).size;else if(u)try{g=new Blob([JSON.stringify(u)]).size}catch{g=new Blob([String(u)]).size}l.messagesReceived++,l.messagesReceivedDelta++,l.bytesReceived+=g,l.bytesReceivedDelta+=g}function c(u){u instanceof Blob?u.size:u instanceof ArrayBuffer?u.byteLength:typeof u=="string"&&new Blob([u]).size,l.messagesSent++,l.messagesSentDelta++,l.bytesSent+=u.length,l.bytesSentDelta+=u.length}const f=o.events.onmessage;o.events.onmessage=function(u){var g=u.data;if(g instanceof Blob?g=g.slice():g instanceof ArrayBuffer?g=g.slice(0):typeof g=="string"&&(g=g),d(g),ee.latencySimulation.enabled&&ee.latencySimulation.delay>0)setTimeout(function(){var b={data:g,target:u.target,currentTarget:u.currentTarget,type:"message"};f.call(u.target,b)},ee.latencySimulation.delay);else return f.apply(this,arguments)};const h=t.connection.send.bind(t.connection);return t.connection.send=function(u){if(c(u),ee.latencySimulation.enabled&&ee.latencySimulation.delay>0){var g=u;u instanceof ArrayBuffer||u instanceof Blob?g=u.slice(0):(u instanceof Uint8Array||u instanceof DataView||u.buffer&&u.buffer instanceof ArrayBuffer)&&(g=new Uint8Array(u).buffer),setTimeout(function(){h(g)},ee.latencySimulation.delay/2)}else return h(u)},Oi(r,l),fl(),t.onLeave.once(()=>{l.pingInterval!==null&&(clearInterval(l.pingInterval),l.pingInterval=null),Ke.delete(r);var u=document.getElementById("debug-panel-"+r);u&&(u.remove(),Bs()),Ke.size===0&&Mt!==null&&(clearInterval(Mt),Mt=null)}),t}var e=ps.prototype.consumeSeatReservation;ps.prototype.consumeSeatReservation=function(){var t=e.apply(this,arguments);return t.then(n=>i(n))}}dl();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",pr):pr();ArrayBuffer.isView||(ArrayBuffer.isView=i=>i!==null&&typeof i=="object"&&i.buffer instanceof ArrayBuffer);typeof globalThis>"u"&&typeof window<"u"&&(window.globalThis=window);typeof FormData>"u"&&(globalThis.FormData=class{});class hl{setState(e){}getState(){return null}patch(e){}teardown(){}handshake(e){}}Ai("schema",Di);Ai("none",hl);class ul{constructor(e){this.client=new ps(e)}async connect(){return this.room=await this.client.joinOrCreate("battle"),this.room}sendMove(e,t){var n;(n=this.room)==null||n.send("move",{x:e,y:t})}sendTarget(e){var t;(t=this.room)==null||t.send("target",e)}sendShoot(e){var t;(t=this.room)==null||t.send("shoot",e)}sendName(e){var t;(t=this.room)==null||t.send("name",e)}}/*!
|
|
88
|
+
fflate - fast JavaScript compression/decompression
|
|
89
|
+
<https://101arrowz.github.io/fflate>
|
|
90
|
+
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
91
|
+
version 0.8.2
|
|
92
|
+
*/var Le=Uint8Array,Gt=Uint16Array,pl=Int32Array,Fi=new Le([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),$i=new Le([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),gl=new Le([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zi=function(i,e){for(var t=new Gt(31),n=0;n<31;++n)t[n]=e+=1<<i[n-1];for(var s=new pl(t[30]),n=1;n<30;++n)for(var r=t[n];r<t[n+1];++r)s[r]=r-t[n]<<5|n;return{b:t,r:s}},_i=zi(Fi,2),Ui=_i.b,ml=_i.r;Ui[28]=258,ml[258]=28;var yl=zi($i,0),xl=yl.b,ms=new Gt(32768);for(var ie=0;ie<32768;++ie){var ft=(ie&43690)>>1|(ie&21845)<<1;ft=(ft&52428)>>2|(ft&13107)<<2,ft=(ft&61680)>>4|(ft&3855)<<4,ms[ie]=((ft&65280)>>8|(ft&255)<<8)>>1}var ln=(function(i,e,t){for(var n=i.length,s=0,r=new Gt(e);s<n;++s)i[s]&&++r[i[s]-1];var o=new Gt(e);for(s=1;s<e;++s)o[s]=o[s-1]+r[s-1]<<1;var a;if(t){a=new Gt(1<<e);var l=15-e;for(s=0;s<n;++s)if(i[s])for(var d=s<<4|i[s],c=e-i[s],f=o[i[s]-1]++<<c,h=f|(1<<c)-1;f<=h;++f)a[ms[f]>>l]=d}else for(a=new Gt(n),s=0;s<n;++s)i[s]&&(a[s]=ms[o[i[s]-1]++]>>15-i[s]);return a}),En=new Le(288);for(var ie=0;ie<144;++ie)En[ie]=8;for(var ie=144;ie<256;++ie)En[ie]=9;for(var ie=256;ie<280;++ie)En[ie]=7;for(var ie=280;ie<288;++ie)En[ie]=8;var Ni=new Le(32);for(var ie=0;ie<32;++ie)Ni[ie]=5;var vl=ln(En,9,1),wl=ln(Ni,5,1),Qn=function(i){for(var e=i[0],t=1;t<i.length;++t)i[t]>e&&(e=i[t]);return e},ze=function(i,e,t){var n=e/8|0;return(i[n]|i[n+1]<<8)>>(e&7)&t},es=function(i,e){var t=e/8|0;return(i[t]|i[t+1]<<8|i[t+2]<<16)>>(e&7)},bl=function(i){return(i+7)/8|0},El=function(i,e,t){return(t==null||t>i.length)&&(t=i.length),new Le(i.subarray(e,t))},Cl=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ue=function(i,e,t){var n=new Error(e||Cl[i]);if(n.code=i,Error.captureStackTrace&&Error.captureStackTrace(n,Ue),!t)throw n;return n},Sl=function(i,e,t,n){var s=i.length,r=0;if(!s||e.f&&!e.l)return t||new Le(0);var o=!t,a=o||e.i!=2,l=e.i;o&&(t=new Le(s*3));var d=function(ot){var wt=t.length;if(ot>wt){var bt=new Le(Math.max(wt*2,ot));bt.set(t),t=bt}},c=e.f||0,f=e.p||0,h=e.b||0,p=e.l,m=e.d,u=e.m,g=e.n,b=s*8;do{if(!p){c=ze(i,f,1);var S=ze(i,f+1,3);if(f+=3,S)if(S==1)p=vl,m=wl,u=9,g=5;else if(S==2){var F=ze(i,f,31)+257,H=ze(i,f+10,15)+4,$=F+ze(i,f+5,31)+1;f+=14;for(var K=new Le($),j=new Le(19),Y=0;Y<H;++Y)j[gl[Y]]=ze(i,f+Y*3,7);f+=H*3;for(var ve=Qn(j),w=(1<<ve)-1,P=ln(j,ve,1),Y=0;Y<$;){var M=P[ze(i,f,w)];f+=M&15;var C=M>>4;if(C<16)K[Y++]=C;else{var T=0,L=0;for(C==16?(L=3+ze(i,f,3),f+=2,T=K[Y-1]):C==17?(L=3+ze(i,f,7),f+=3):C==18&&(L=11+ze(i,f,127),f+=7);L--;)K[Y++]=T}}var _=K.subarray(0,F),V=K.subarray(F);u=Qn(_),g=Qn(V),p=ln(_,u,1),m=ln(V,g,1)}else Ue(1);else{var C=bl(f)+4,I=i[C-4]|i[C-3]<<8,N=C+I;if(N>s){l&&Ue(0);break}a&&d(h+I),t.set(i.subarray(C,N),h),e.b=h+=I,e.p=f=N*8,e.f=c;continue}if(f>b){l&&Ue(0);break}}a&&d(h+131072);for(var U=(1<<u)-1,z=(1<<g)-1,X=f;;X=f){var T=p[es(i,f)&U],le=T>>4;if(f+=T&15,f>b){l&&Ue(0);break}if(T||Ue(2),le<256)t[h++]=le;else if(le==256){X=f,p=null;break}else{var we=le-254;if(le>264){var Y=le-257,ke=Fi[Y];we=ze(i,f,(1<<ke)-1)+Ui[Y],f+=ke}var Ze=m[es(i,f)&z],De=Ze>>4;Ze||Ue(3),f+=Ze&15;var V=xl[De];if(De>3){var ke=$i[De];V+=es(i,f)&(1<<ke)-1,f+=ke}if(f>b){l&&Ue(0);break}a&&d(h+131072);var Ot=h+we;if(h<V){var Ft=r-V,vt=Math.min(V,Ot);for(Ft+h<0&&Ue(3);h<vt;++h)t[h]=n[Ft+h]}for(;h<Ot;++h)t[h]=t[h-V]}}e.l=p,e.p=X,e.b=h,e.f=c,p&&(c=1,e.m=u,e.d=m,e.n=g)}while(!c);return h!=t.length&&o?El(t,0,h):t.subarray(0,h)},Tl=new Le(0),kl=function(i,e){return((i[0]&15)!=8||i[0]>>4>7||(i[0]<<8|i[1])%31)&&Ue(6,"invalid zlib data"),(i[1]>>5&1)==1&&Ue(6,"invalid zlib data: "+(i[1]&32?"need":"unexpected")+" dictionary"),(i[1]>>3&4)+2};function Il(i,e){return Sl(i.subarray(kl(i),-4),{i:2},e,e)}var Ml=typeof TextDecoder<"u"&&new TextDecoder,Al=0;try{Ml.decode(Tl,{stream:!0}),Al=1}catch{}function Vi(i,e,t){const n=t.length-i-1;if(e>=t[n])return n-1;if(e<=t[i])return i;let s=i,r=n,o=Math.floor((s+r)/2);for(;e<t[o]||e>=t[o+1];)e<t[o]?r=o:s=o,o=Math.floor((s+r)/2);return o}function Rl(i,e,t,n){const s=[],r=[],o=[];s[0]=1;for(let a=1;a<=t;++a){r[a]=e-n[i+1-a],o[a]=n[i+a]-e;let l=0;for(let d=0;d<a;++d){const c=o[d+1],f=r[a-d],h=s[d]/(c+f);s[d]=l+c*h,l=f*h}s[a]=l}return s}function Dl(i,e,t,n){const s=Vi(i,n,e),r=Rl(s,n,i,e),o=new cn(0,0,0,0);for(let a=0;a<=i;++a){const l=t[s-i+a],d=r[a],c=l.w*d;o.x+=l.x*c,o.y+=l.y*c,o.z+=l.z*c,o.w+=l.w*d}return o}function Bl(i,e,t,n,s){const r=[];for(let f=0;f<=t;++f)r[f]=0;const o=[];for(let f=0;f<=n;++f)o[f]=r.slice(0);const a=[];for(let f=0;f<=t;++f)a[f]=r.slice(0);a[0][0]=1;const l=r.slice(0),d=r.slice(0);for(let f=1;f<=t;++f){l[f]=e-s[i+1-f],d[f]=s[i+f]-e;let h=0;for(let p=0;p<f;++p){const m=d[p+1],u=l[f-p];a[f][p]=m+u;const g=a[p][f-1]/a[f][p];a[p][f]=h+m*g,h=u*g}a[f][f]=h}for(let f=0;f<=t;++f)o[0][f]=a[f][t];for(let f=0;f<=t;++f){let h=0,p=1;const m=[];for(let u=0;u<=t;++u)m[u]=r.slice(0);m[0][0]=1;for(let u=1;u<=n;++u){let g=0;const b=f-u,S=t-u;f>=u&&(m[p][0]=m[h][0]/a[S+1][b],g=m[p][0]*a[b][S]);const C=b>=-1?1:-b,I=f-1<=S?u-1:t-f;for(let F=C;F<=I;++F)m[p][F]=(m[h][F]-m[h][F-1])/a[S+1][b+F],g+=m[p][F]*a[b+F][S];f<=S&&(m[p][u]=-m[h][u-1]/a[S+1][f],g+=m[p][u]*a[f][S]),o[u][f]=g;const N=h;h=p,p=N}}let c=t;for(let f=1;f<=n;++f){for(let h=0;h<=t;++h)o[f][h]*=c;c*=t-f}return o}function Ll(i,e,t,n,s){const r=s<i?s:i,o=[],a=Vi(i,n,e),l=Bl(a,n,i,r,e),d=[];for(let c=0;c<t.length;++c){const f=t[c].clone(),h=f.w;f.x*=h,f.y*=h,f.z*=h,d[c]=f}for(let c=0;c<=r;++c){const f=d[a-i].clone().multiplyScalar(l[c][0]);for(let h=1;h<=i;++h)f.add(d[a-i+h].clone().multiplyScalar(l[c][h]));o[c]=f}for(let c=r+1;c<=s+1;++c)o[c]=new cn(0,0,0);return o}function Pl(i,e){let t=1;for(let s=2;s<=i;++s)t*=s;let n=1;for(let s=2;s<=e;++s)n*=s;for(let s=2;s<=i-e;++s)n*=s;return t/n}function Ol(i){const e=i.length,t=[],n=[];for(let r=0;r<e;++r){const o=i[r];t[r]=new Pe(o.x,o.y,o.z),n[r]=o.w}const s=[];for(let r=0;r<e;++r){const o=t[r].clone();for(let a=1;a<=r;++a)o.sub(s[r-a].clone().multiplyScalar(Pl(r,a)*n[a]));s[r]=o.divideScalar(n[0])}return s}function Fl(i,e,t,n,s){const r=Ll(i,e,t,n,s);return Ol(r)}class $l extends ro{constructor(e,t,n,s,r){super();const o=t?t.length-1:0,a=n?n.length:0;this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=s||0,this.endKnot=r||o;for(let l=0;l<a;++l){const d=n[l];this.controlPoints[l]=new cn(d.x,d.y,d.z,d.w)}}getPoint(e,t=new Pe){const n=t,s=this.knots[this.startKnot]+e*(this.knots[this.endKnot]-this.knots[this.startKnot]),r=Dl(this.degree,this.knots,this.controlPoints,s);return r.w!==1&&r.divideScalar(r.w),n.set(r.x,r.y,r.z)}getTangent(e,t=new Pe){const n=t,s=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),r=Fl(this.degree,this.knots,this.controlPoints,s,1);return n.copy(r[1]).normalize(),n}toJSON(){const e=super.toJSON();return e.degree=this.degree,e.knots=[...this.knots],e.controlPoints=this.controlPoints.map(t=>t.toArray()),e.startKnot=this.startKnot,e.endKnot=this.endKnot,e}fromJSON(e){return super.fromJSON(e),this.degree=e.degree,this.knots=[...e.knots],this.controlPoints=e.controlPoints.map(t=>new cn(t[0],t[1],t[2],t[3])),this.startKnot=e.startKnot,this.endKnot=e.endKnot,this}}let J,de,Se;class zl extends ss{constructor(e){super(e)}load(e,t,n,s){const r=this,o=r.path===""?io.extractUrlBase(e):r.path,a=new oo(this.manager);a.setPath(r.path),a.setResponseType("arraybuffer"),a.setRequestHeader(r.requestHeader),a.setWithCredentials(r.withCredentials),a.load(e,function(l){try{t(r.parse(l,o))}catch(d){s?s(d):console.error(d),r.manager.itemError(e)}},n,s)}parse(e,t){if(Hl(e))J=new jl().parse(e);else{const s=Wi(e);if(!Wl(s))throw new Error("THREE.FBXLoader: Unknown format.");if(xr(s)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+xr(s));J=new Vl().parse(s)}const n=new ao(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new _l(n,this.manager).parse(J)}}class _l{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){de=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),n=this.parseMaterials(t),s=this.parseDeformers(),r=new Ul().parse(s);return this.parseScene(s,r,n),Se}parseConnections(){const e=new Map;return"Connections"in J&&J.Connections.connections.forEach(function(n){const s=n[0],r=n[1],o=n[2];e.has(s)||e.set(s,{parents:[],children:[]});const a={ID:r,relationship:o};e.get(s).parents.push(a),e.has(r)||e.set(r,{parents:[],children:[]});const l={ID:s,relationship:o};e.get(r).children.push(l)}),e}parseImages(){const e={},t={};if("Video"in J.Objects){const n=J.Objects.Video;for(const s in n){const r=n[s],o=parseInt(s);if(e[o]=r.RelativeFilename||r.Filename,"Content"in r){const a=r.Content instanceof ArrayBuffer&&r.Content.byteLength>0,l=typeof r.Content=="string"&&r.Content!=="";if(a||l){const d=this.parseImage(n[s]);t[r.RelativeFilename||r.Filename]=d}}}}for(const n in e){const s=e[n];t[s]!==void 0?e[n]=t[s]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,s=n.slice(n.lastIndexOf(".")+1).toLowerCase();let r;switch(s){case"bmp":r="image/bmp";break;case"jpg":case"jpeg":r="image/jpeg";break;case"png":r="image/png";break;case"tif":r="image/tiff";break;case"tga":this.manager.getHandler(".tga")===null&&console.warn("FBXLoader: TGA loader not found, skipping ",n),r="image/tga";break;default:console.warn('FBXLoader: Image type "'+s+'" is not supported.');return}if(typeof t=="string")return"data:"+r+";base64,"+t;{const o=new Uint8Array(t);return window.URL.createObjectURL(new Blob([o],{type:r}))}}parseTextures(e){const t=new Map;if("Texture"in J.Objects){const n=J.Objects.Texture;for(const s in n){const r=this.parseTexture(n[s],e);t.set(parseInt(s),r)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const s=e.WrapModeU,r=e.WrapModeV,o=s!==void 0?s.value:0,a=r!==void 0?r.value:0;if(n.wrapS=o===0?Us:Ns,n.wrapT=a===0?Us:Ns,"Scaling"in e){const l=e.Scaling.value;n.repeat.x=l[0],n.repeat.y=l[1]}if("Translation"in e){const l=e.Translation.value;n.offset.x=l[0],n.offset.y=l[1]}return n}loadTexture(e,t){const n=new Set(["tga","tif","tiff","exr","dds","hdr","ktx2"]),s=e.FileName.split(".").pop().toLowerCase(),r=n.has(s)?this.manager.getHandler(`.${s}`):this.textureLoader;if(!r)return console.warn(`FBXLoader: ${s.toUpperCase()} loader not found, creating placeholder texture for`,e.RelativeFilename),new lo;const o=r.path;o||r.setPath(this.textureLoader.path);const a=de.get(e.id).children;let l;a!==void 0&&a.length>0&&t[a[0].ID]!==void 0&&(l=t[a[0].ID],(l.indexOf("blob:")===0||l.indexOf("data:")===0)&&r.setPath(void 0));const d=r.load(l);return r.setPath(o),d}parseMaterials(e){const t=new Map;if("Material"in J.Objects){const n=J.Objects.Material;for(const s in n){const r=this.parseMaterial(n[s],e);r!==null&&t.set(parseInt(s),r)}}return t}parseMaterial(e,t){const n=e.id,s=e.attrName;let r=e.ShadingModel;if(typeof r=="object"&&(r=r.value),!de.has(n))return null;const o=this.parseParameters(e,t,n);let a;switch(r.toLowerCase()){case"phong":a=new Yn;break;case"lambert":a=new co;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',r),a=new Yn;break}return a.setValues(o),a.name=s,a}parseParameters(e,t,n){const s={};e.BumpFactor&&(s.bumpScale=e.BumpFactor.value),e.Diffuse?s.color=dt.toWorkingColorSpace(new et().fromArray(e.Diffuse.value),Ae):e.DiffuseColor&&(e.DiffuseColor.type==="Color"||e.DiffuseColor.type==="ColorRGB")&&(s.color=dt.toWorkingColorSpace(new et().fromArray(e.DiffuseColor.value),Ae)),e.DisplacementFactor&&(s.displacementScale=e.DisplacementFactor.value),e.Emissive?s.emissive=dt.toWorkingColorSpace(new et().fromArray(e.Emissive.value),Ae):e.EmissiveColor&&(e.EmissiveColor.type==="Color"||e.EmissiveColor.type==="ColorRGB")&&(s.emissive=dt.toWorkingColorSpace(new et().fromArray(e.EmissiveColor.value),Ae)),e.EmissiveFactor&&(s.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),s.opacity=1-(e.TransparencyFactor?parseFloat(e.TransparencyFactor.value):0),(s.opacity===1||s.opacity===0)&&(s.opacity=e.Opacity?parseFloat(e.Opacity.value):null,s.opacity===null&&(s.opacity=1-(e.TransparentColor?parseFloat(e.TransparentColor.value[0]):0))),s.opacity<1&&(s.transparent=!0),e.ReflectionFactor&&(s.reflectivity=e.ReflectionFactor.value),e.Shininess&&(s.shininess=e.Shininess.value),e.Specular?s.specular=dt.toWorkingColorSpace(new et().fromArray(e.Specular.value),Ae):e.SpecularColor&&e.SpecularColor.type==="Color"&&(s.specular=dt.toWorkingColorSpace(new et().fromArray(e.SpecularColor.value),Ae));const r=this;return de.get(n).children.forEach(function(o){const a=o.relationship;switch(a){case"Bump":s.bumpMap=r.getTexture(t,o.ID);break;case"Maya|TEX_ao_map":s.aoMap=r.getTexture(t,o.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":s.map=r.getTexture(t,o.ID),s.map!==void 0&&(s.map.colorSpace=Ae);break;case"DisplacementColor":s.displacementMap=r.getTexture(t,o.ID);break;case"EmissiveColor":s.emissiveMap=r.getTexture(t,o.ID),s.emissiveMap!==void 0&&(s.emissiveMap.colorSpace=Ae);break;case"NormalMap":case"Maya|TEX_normal_map":s.normalMap=r.getTexture(t,o.ID);break;case"ReflectionColor":s.envMap=r.getTexture(t,o.ID),s.envMap!==void 0&&(s.envMap.mapping=fo,s.envMap.colorSpace=Ae);break;case"SpecularColor":s.specularMap=r.getTexture(t,o.ID),s.specularMap!==void 0&&(s.specularMap.colorSpace=Ae);break;case"TransparentColor":case"TransparencyFactor":s.alphaMap=r.getTexture(t,o.ID),s.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",a);break}}),s}getTexture(e,t){return"LayeredTexture"in J.Objects&&t in J.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=de.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in J.Objects){const n=J.Objects.Deformer;for(const s in n){const r=n[s],o=de.get(parseInt(s));if(r.attrType==="Skin"){const a=this.parseSkeleton(o,n);a.ID=s,o.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),a.geometryID=o.parents[0].ID,e[s]=a}else if(r.attrType==="BlendShape"){const a={id:s};a.rawTargets=this.parseMorphTargets(o,n),a.id=s,o.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[s]=a}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(s){const r=t[s.ID];if(r.attrType!=="Cluster")return;const o={ID:s.ID,indices:[],weights:[],transformLink:new fe().fromArray(r.TransformLink.a)};"Indexes"in r&&(o.indices=r.Indexes.a,o.weights=r.Weights.a),n.push(o)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let s=0;s<e.children.length;s++){const r=e.children[s],o=t[r.ID],a={name:o.attrName,initialWeight:o.DeformPercent,id:o.id,fullWeights:o.FullWeights.a};if(o.attrType!=="BlendShapeChannel")return;a.geoID=de.get(parseInt(r.ID)).children.filter(function(l){return l.relationship===void 0})[0].ID,n.push(a)}return n}parseScene(e,t,n){Se=new Vs;const s=this.parseModels(e.skeletons,t,n),r=J.Objects.Model,o=this;s.forEach(function(l){const d=r[l.ID];o.setLookAtProperties(l,d),de.get(l.ID).parents.forEach(function(f){const h=s.get(f.ID);h!==void 0&&h.add(l)}),l.parent===null&&Se.add(l)}),this.bindSkeleton(e.skeletons,t,s),this.addGlobalSceneSettings(),Se.traverse(function(l){if(l.userData.transformData){l.parent&&(l.userData.transformData.parentMatrix=l.parent.matrix,l.userData.transformData.parentMatrixWorld=l.parent.matrixWorld);const d=Hi(l.userData.transformData);l.applyMatrix4(d),l.updateWorldMatrix()}});const a=new Nl().parse();Se.children.length===1&&Se.children[0].isGroup&&(Se.children[0].animations=a,Se=Se.children[0]),Se.animations=a}parseModels(e,t,n){const s=new Map,r=J.Objects.Model;for(const o in r){const a=parseInt(o),l=r[o],d=de.get(a);let c=this.buildSkeleton(d,e,a,l.attrName);if(!c){switch(l.attrType){case"Camera":c=this.createCamera(d);break;case"Light":c=this.createLight(d);break;case"Mesh":c=this.createMesh(d,t,n);break;case"NurbsCurve":c=this.createCurve(d,t);break;case"LimbNode":case"Root":c=new js;break;case"Null":default:c=new Vs;break}c.name=l.attrName?On.sanitizeNodeName(l.attrName):"",c.userData.originalName=l.attrName,c.ID=a}this.getTransformData(c,l),s.set(a,c)}return s}buildSkeleton(e,t,n,s){let r=null;return e.parents.forEach(function(o){for(const a in t){const l=t[a];l.rawBones.forEach(function(d,c){if(d.ID===o.ID){const f=r;r=new js,r.matrixWorld.copy(d.transformLink),r.name=s?On.sanitizeNodeName(s):"",r.userData.originalName=s,r.ID=n,l.bones[c]=r,f!==null&&r.add(f)}})}}),r}createCamera(e){let t,n;if(e.children.forEach(function(s){const r=J.Objects.NodeAttribute[s.ID];r!==void 0&&(n=r)}),n===void 0)t=new kn;else{let s=0;n.CameraProjectionType!==void 0&&n.CameraProjectionType.value===1&&(s=1);let r=1;n.NearPlane!==void 0&&(r=n.NearPlane.value/1e3);let o=1e3;n.FarPlane!==void 0&&(o=n.FarPlane.value/1e3);let a=window.innerWidth,l=window.innerHeight;n.AspectWidth!==void 0&&n.AspectHeight!==void 0&&(a=n.AspectWidth.value,l=n.AspectHeight.value);const d=a/l;let c=45;n.FieldOfView!==void 0&&(c=n.FieldOfView.value);const f=n.FocalLength?n.FocalLength.value:null;switch(s){case 0:t=new ho(c,d,r,o),f!==null&&t.setFocalLength(f);break;case 1:console.warn("THREE.FBXLoader: Orthographic cameras not supported yet."),t=new kn;break;default:console.warn("THREE.FBXLoader: Unknown camera type "+s+"."),t=new kn;break}}return t}createLight(e){let t,n;if(e.children.forEach(function(s){const r=J.Objects.NodeAttribute[s.ID];r!==void 0&&(n=r)}),n===void 0)t=new kn;else{let s;n.LightType===void 0?s=0:s=n.LightType.value;let r=16777215;n.Color!==void 0&&(r=dt.toWorkingColorSpace(new et().fromArray(n.Color.value),Ae));let o=n.Intensity===void 0?1:n.Intensity.value/100;n.CastLightOnObject!==void 0&&n.CastLightOnObject.value===0&&(o=0);let a=0;n.FarAttenuationEnd!==void 0&&(n.EnableFarAttenuation!==void 0&&n.EnableFarAttenuation.value===0?a=0:a=n.FarAttenuationEnd.value);const l=1;switch(s){case 0:t=new Hs(r,o,a,l);break;case 1:t=new po(r,o);break;case 2:let d=Math.PI/3;n.InnerAngle!==void 0&&(d=Te.degToRad(n.InnerAngle.value));let c=0;n.OuterAngle!==void 0&&(c=Te.degToRad(n.OuterAngle.value),c=Math.max(c,1)),t=new uo(r,o,a,d,c,l);break;default:console.warn("THREE.FBXLoader: Unknown light type "+n.LightType.value+", defaulting to a PointLight."),t=new Hs(r,o);break}n.CastShadows!==void 0&&n.CastShadows.value===1&&(t.castShadow=!0)}return t}createMesh(e,t,n){let s,r=null,o=null;const a=[];return e.children.forEach(function(l){t.has(l.ID)&&(r=t.get(l.ID)),n.has(l.ID)&&a.push(n.get(l.ID))}),a.length>1?o=a:a.length>0?o=a[0]:(o=new Yn({name:ss.DEFAULT_MATERIAL_NAME,color:13421772}),a.push(o)),"color"in r.attributes&&a.forEach(function(l){l.vertexColors=!0}),r.FBX_Deformer?(s=new go(r,o),s.normalizeSkinWeights()):s=new mo(r,o),s}createCurve(e,t){const n=e.children.reduce(function(r,o){return t.has(o.ID)&&(r=t.get(o.ID)),r},null),s=new yo({name:ss.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new xo(n,s)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),"RotationOrder"in t?n.eulerOrder=un(t.RotationOrder.value):n.eulerOrder=un(0),"Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){"LookAtProperty"in t&&de.get(e.ID).children.forEach(function(s){if(s.relationship==="LookAtProperty"){const r=J.Objects.Model[s.ID];if("Lcl_Translation"in r){const o=r.Lcl_Translation.value;e.target!==void 0?(e.target.position.fromArray(o),Se.add(e.target)):e.lookAt(new Pe().fromArray(o))}}})}bindSkeleton(e,t,n){const s=this.parsePoseNodes();for(const r in e){const o=e[r];de.get(parseInt(o.ID)).parents.forEach(function(l){if(t.has(l.ID)){const d=l.ID;de.get(d).parents.forEach(function(f){n.has(f.ID)&&n.get(f.ID).bind(new vo(o.bones),s[f.ID])})}})}}parsePoseNodes(){const e={};if("Pose"in J.Objects){const t=J.Objects.Pose;for(const n in t)if(t[n].attrType==="BindPose"&&t[n].NbPoseNodes>0){const s=t[n].PoseNode;Array.isArray(s)?s.forEach(function(r){e[r.Node]=new fe().fromArray(r.Matrix.a)}):e[s.Node]=new fe().fromArray(s.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in J){if("AmbientColor"in J.GlobalSettings){const e=J.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],s=e[2];if(t!==0||n!==0||s!==0){const r=new et().setRGB(t,n,s,Ae);Se.add(new wo(r,1))}}"UnitScaleFactor"in J.GlobalSettings&&(Se.userData.unitScaleFactor=J.GlobalSettings.UnitScaleFactor.value)}}}class Ul{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in J.Objects){const n=J.Objects.Geometry;for(const s in n){const r=de.get(parseInt(s)),o=this.parseGeometry(r,n[s],e);t.set(parseInt(s),o)}}return this.negativeMaterialIndices===!0&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const s=n.skeletons,r=[],o=e.parents.map(function(f){return J.Objects.Model[f.ID]});if(o.length===0)return;const a=e.children.reduce(function(f,h){return s[h.ID]!==void 0&&(f=s[h.ID]),f},null);e.children.forEach(function(f){n.morphTargets[f.ID]!==void 0&&r.push(n.morphTargets[f.ID])});const l=o[0],d={};"RotationOrder"in l&&(d.eulerOrder=un(l.RotationOrder.value)),"InheritType"in l&&(d.inheritType=parseInt(l.InheritType.value)),"GeometricTranslation"in l&&(d.translation=l.GeometricTranslation.value),"GeometricRotation"in l&&(d.rotation=l.GeometricRotation.value),"GeometricScaling"in l&&(d.scale=l.GeometricScaling.value);const c=Hi(d);return this.genGeometry(t,a,r,c)}genGeometry(e,t,n,s){const r=new qn;e.attrName&&(r.name=e.attrName);const o=this.parseGeoNode(e,t),a=this.genBuffers(o),l=new Ut(a.vertex,3);if(l.applyMatrix4(s),r.setAttribute("position",l),a.colors.length>0&&r.setAttribute("color",new Ut(a.colors,3)),t&&(r.setAttribute("skinIndex",new bo(a.weightsIndices,4)),r.setAttribute("skinWeight",new Ut(a.vertexWeights,4)),r.FBX_Deformer=t),a.normal.length>0){const d=new Eo().getNormalMatrix(s),c=new Ut(a.normal,3);c.applyNormalMatrix(d),r.setAttribute("normal",c)}if(a.uvs.forEach(function(d,c){const f=c===0?"uv":`uv${c}`;r.setAttribute(f,new Ut(a.uvs[c],2))}),o.material&&o.material.mappingType!=="AllSame"){let d=a.materialIndex[0],c=0;if(a.materialIndex.forEach(function(f,h){f!==d&&(r.addGroup(c,h-c,d),d=f,c=h)}),r.groups.length>0){const f=r.groups[r.groups.length-1],h=f.start+f.count;h!==a.materialIndex.length&&r.addGroup(h,a.materialIndex.length-h,d)}r.groups.length===0&&r.addGroup(0,a.materialIndex.length,a.materialIndex[0])}return this.addMorphTargets(r,e,n,s),r}parseGeoNode(e,t){const n={};if(n.vertexPositions=e.Vertices!==void 0?e.Vertices.a:[],n.vertexIndices=e.PolygonVertexIndex!==void 0?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let s=0;for(;e.LayerElementUV[s];)e.LayerElementUV[s].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[s])),s++}return n.weightTable={},t!==null&&(n.skeleton=t,t.rawBones.forEach(function(s,r){s.indices.forEach(function(o,a){n.weightTable[o]===void 0&&(n.weightTable[o]=[]),n.weightTable[o].push({id:r,weight:s.weights[a]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,s=0,r=!1,o=[],a=[],l=[],d=[],c=[],f=[];const h=this;return e.vertexIndices.forEach(function(p,m){let u,g=!1;p<0&&(p=p^-1,g=!0);let b=[],S=[];if(o.push(p*3,p*3+1,p*3+2),e.color){const C=Rn(m,n,p,e.color);l.push(C[0],C[1],C[2])}if(e.skeleton){if(e.weightTable[p]!==void 0&&e.weightTable[p].forEach(function(C){S.push(C.weight),b.push(C.id)}),S.length>4){r||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),r=!0);const C=[0,0,0,0],I=[0,0,0,0];S.forEach(function(N,F){let H=N,$=b[F];I.forEach(function(K,j,Y){if(H>K){Y[j]=H,H=K;const ve=C[j];C[j]=$,$=ve}})}),b=C,S=I}for(;S.length<4;)S.push(0),b.push(0);for(let C=0;C<4;++C)c.push(S[C]),f.push(b[C])}if(e.normal){const C=Rn(m,n,p,e.normal);a.push(C[0],C[1],C[2])}e.material&&e.material.mappingType!=="AllSame"&&(u=Rn(m,n,p,e.material)[0],u<0&&(h.negativeMaterialIndices=!0,u=0)),e.uv&&e.uv.forEach(function(C,I){const N=Rn(m,n,p,C);d[I]===void 0&&(d[I]=[]),d[I].push(N[0]),d[I].push(N[1])}),s++,g&&(h.genFace(t,e,o,u,a,l,d,c,f,s),n++,s=0,o=[],a=[],l=[],d=[],c=[],f=[])}),t}getNormalNewell(e){const t=new Pe(0,0,0);for(let n=0;n<e.length;n++){const s=e[n],r=e[(n+1)%e.length];t.x+=(s.y-r.y)*(s.z+r.z),t.y+=(s.z-r.z)*(s.x+r.x),t.z+=(s.x-r.x)*(s.y+r.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),s=(Math.abs(t.z)>.5?new Pe(0,1,0):new Pe(0,0,1)).cross(t).normalize(),r=t.clone().cross(s).normalize();return{normal:t,tangent:s,bitangent:r}}flattenVertex(e,t,n){return new Co(e.dot(t),e.dot(n))}genFace(e,t,n,s,r,o,a,l,d,c){let f;if(c>3){const h=[],p=t.baseVertexPositions||t.vertexPositions;for(let b=0;b<n.length;b+=3)h.push(new Pe(p[n[b]],p[n[b+1]],p[n[b+2]]));const{tangent:m,bitangent:u}=this.getNormalTangentAndBitangent(h),g=[];for(const b of h)g.push(this.flattenVertex(b,m,u));f=So.triangulateShape(g,[])}else f=[[0,1,2]];for(const[h,p,m]of f)e.vertex.push(t.vertexPositions[n[h*3]]),e.vertex.push(t.vertexPositions[n[h*3+1]]),e.vertex.push(t.vertexPositions[n[h*3+2]]),e.vertex.push(t.vertexPositions[n[p*3]]),e.vertex.push(t.vertexPositions[n[p*3+1]]),e.vertex.push(t.vertexPositions[n[p*3+2]]),e.vertex.push(t.vertexPositions[n[m*3]]),e.vertex.push(t.vertexPositions[n[m*3+1]]),e.vertex.push(t.vertexPositions[n[m*3+2]]),t.skeleton&&(e.vertexWeights.push(l[h*4]),e.vertexWeights.push(l[h*4+1]),e.vertexWeights.push(l[h*4+2]),e.vertexWeights.push(l[h*4+3]),e.vertexWeights.push(l[p*4]),e.vertexWeights.push(l[p*4+1]),e.vertexWeights.push(l[p*4+2]),e.vertexWeights.push(l[p*4+3]),e.vertexWeights.push(l[m*4]),e.vertexWeights.push(l[m*4+1]),e.vertexWeights.push(l[m*4+2]),e.vertexWeights.push(l[m*4+3]),e.weightsIndices.push(d[h*4]),e.weightsIndices.push(d[h*4+1]),e.weightsIndices.push(d[h*4+2]),e.weightsIndices.push(d[h*4+3]),e.weightsIndices.push(d[p*4]),e.weightsIndices.push(d[p*4+1]),e.weightsIndices.push(d[p*4+2]),e.weightsIndices.push(d[p*4+3]),e.weightsIndices.push(d[m*4]),e.weightsIndices.push(d[m*4+1]),e.weightsIndices.push(d[m*4+2]),e.weightsIndices.push(d[m*4+3])),t.color&&(e.colors.push(o[h*3]),e.colors.push(o[h*3+1]),e.colors.push(o[h*3+2]),e.colors.push(o[p*3]),e.colors.push(o[p*3+1]),e.colors.push(o[p*3+2]),e.colors.push(o[m*3]),e.colors.push(o[m*3+1]),e.colors.push(o[m*3+2])),t.material&&t.material.mappingType!=="AllSame"&&(e.materialIndex.push(s),e.materialIndex.push(s),e.materialIndex.push(s)),t.normal&&(e.normal.push(r[h*3]),e.normal.push(r[h*3+1]),e.normal.push(r[h*3+2]),e.normal.push(r[p*3]),e.normal.push(r[p*3+1]),e.normal.push(r[p*3+2]),e.normal.push(r[m*3]),e.normal.push(r[m*3+1]),e.normal.push(r[m*3+2])),t.uv&&t.uv.forEach(function(u,g){e.uvs[g]===void 0&&(e.uvs[g]=[]),e.uvs[g].push(a[g][h*2]),e.uvs[g].push(a[g][h*2+1]),e.uvs[g].push(a[g][p*2]),e.uvs[g].push(a[g][p*2+1]),e.uvs[g].push(a[g][m*2]),e.uvs[g].push(a[g][m*2+1])})}addMorphTargets(e,t,n,s){if(n.length===0)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const r=this;n.forEach(function(o){o.rawTargets.forEach(function(a){const l=J.Objects.Geometry[a.geoID];l!==void 0&&r.genMorphGeometry(e,t,l,s,a.name)})})}genMorphGeometry(e,t,n,s,r){const o=t.Vertices!==void 0?t.Vertices.a:[],a=t.PolygonVertexIndex!==void 0?t.PolygonVertexIndex.a:[],l=n.Vertices!==void 0?n.Vertices.a:[],d=n.Indexes!==void 0?n.Indexes.a:[],c=e.attributes.position.count*3,f=new Float32Array(c);for(let u=0;u<d.length;u++){const g=d[u]*3;f[g]=l[u*3],f[g+1]=l[u*3+1],f[g+2]=l[u*3+2]}const h={vertexIndices:a,vertexPositions:f,baseVertexPositions:o},p=this.genBuffers(h),m=new Ut(p.vertex,3);m.name=r||n.attrName,m.applyMatrix4(s),e.morphAttributes.position.push(m)}parseNormals(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,s=e.Normals.a;let r=[];return n==="IndexToDirect"&&("NormalIndex"in e?r=e.NormalIndex.a:"NormalsIndex"in e&&(r=e.NormalsIndex.a)),{dataSize:3,buffer:s,indices:r,mappingType:t,referenceType:n}}parseUVs(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,s=e.UV.a;let r=[];return n==="IndexToDirect"&&(r=e.UVIndex.a),{dataSize:2,buffer:s,indices:r,mappingType:t,referenceType:n}}parseVertexColors(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,s=e.Colors.a;let r=[];n==="IndexToDirect"&&(r=e.ColorIndex.a);for(let o=0,a=new et;o<s.length;o+=4)a.fromArray(s,o),dt.toWorkingColorSpace(a,Ae),a.toArray(s,o);return{dataSize:4,buffer:s,indices:r,mappingType:t,referenceType:n}}parseMaterialIndices(e){const t=e.MappingInformationType,n=e.ReferenceInformationType;if(t==="NoMappingInformation")return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:n};const s=e.Materials.a,r=[];for(let o=0;o<s.length;++o)r.push(o);return{dataSize:1,buffer:s,indices:r,mappingType:t,referenceType:n}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new qn;const n=t-1,s=e.KnotVector.a,r=[],o=e.Points.a;for(let f=0,h=o.length;f<h;f+=4)r.push(new cn().fromArray(o,f));let a,l;if(e.Form==="Closed")r.push(r[0]);else if(e.Form==="Periodic"){a=n,l=s.length-1-a;for(let f=0;f<n;++f)r.push(r[f])}const c=new $l(n,s,r,a,l).getPoints(r.length*12);return new qn().setFromPoints(c)}}class Nl{parse(){const e=[],t=this.parseClips();if(t!==void 0)for(const n in t){const s=t[n],r=this.addClip(s);e.push(r)}return e}parseClips(){if(J.Objects.AnimationCurve===void 0)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=J.Objects.AnimationCurveNode,t=new Map;for(const n in e){const s=e[n];if(s.attrName.match(/S|R|T|DeformPercent/)!==null){const r={id:s.id,attr:s.attrName,curves:{}};t.set(r.id,r)}}return t}parseAnimationCurves(e){const t=J.Objects.AnimationCurve;for(const n in t){const s={id:t[n].id,times:t[n].KeyTime.a.map(Gl),values:t[n].KeyValueFloat.a},r=de.get(s.id);if(r!==void 0){const o=r.parents[0].ID,a=r.parents[0].relationship;a.match(/X/)?e.get(o).curves.x=s:a.match(/Y/)?e.get(o).curves.y=s:a.match(/Z/)?e.get(o).curves.z=s:a.match(/DeformPercent/)&&e.has(o)&&(e.get(o).curves.morph=s)}}}parseAnimationLayers(e){const t=J.Objects.AnimationLayer,n=new Map;for(const s in t){const r=[],o=de.get(parseInt(s));o!==void 0&&(o.children.forEach(function(l,d){if(e.has(l.ID)){const c=e.get(l.ID);if(c.curves.x!==void 0||c.curves.y!==void 0||c.curves.z!==void 0){if(r[d]===void 0){const f=de.get(l.ID).parents.filter(function(h){return h.relationship!==void 0})[0].ID;if(f!==void 0){const h=J.Objects.Model[f.toString()];if(h===void 0){console.warn("THREE.FBXLoader: Encountered a unused curve.",l);return}const p={modelName:h.attrName?On.sanitizeNodeName(h.attrName):"",ID:h.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};Se.traverse(function(m){m.ID===h.id&&(p.transform=m.matrix,m.userData.transformData&&(p.eulerOrder=m.userData.transformData.eulerOrder))}),p.transform||(p.transform=new fe),"PreRotation"in h&&(p.preRotation=h.PreRotation.value),"PostRotation"in h&&(p.postRotation=h.PostRotation.value),r[d]=p}}r[d]&&(r[d][c.attr]=c)}else if(c.curves.morph!==void 0){if(r[d]===void 0){const f=de.get(l.ID).parents.filter(function(b){return b.relationship!==void 0})[0].ID,h=de.get(f).parents[0].ID,p=de.get(h).parents[0].ID,m=de.get(p).parents[0].ID,u=J.Objects.Model[m],g={modelName:u.attrName?On.sanitizeNodeName(u.attrName):"",morphName:J.Objects.Deformer[f].attrName};r[d]=g}r[d][c.attr]=c}}}),n.set(parseInt(s),r))}return n}parseAnimStacks(e){const t=J.Objects.AnimationStack,n={};for(const s in t){const r=de.get(parseInt(s)).children;r.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const o=e.get(r[0].ID);n[s]={name:t[s].attrName,layer:o}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(s){t=t.concat(n.generateTracks(s))}),new To(e.name,-1,t)}generateTracks(e){const t=[];let n=new Pe,s=new Pe;if(e.transform&&e.transform.decompose(n,new ct,s),n=n.toArray(),s=s.toArray(),e.T!==void 0&&Object.keys(e.T.curves).length>0){const r=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");r!==void 0&&t.push(r)}if(e.R!==void 0&&Object.keys(e.R.curves).length>0){const r=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);r!==void 0&&t.push(r)}if(e.S!==void 0&&Object.keys(e.S.curves).length>0){const r=this.generateVectorTrack(e.modelName,e.S.curves,s,"scale");r!==void 0&&t.push(r)}if(e.DeformPercent!==void 0){const r=this.generateMorphTrack(e);r!==void 0&&t.push(r)}return t}generateVectorTrack(e,t,n,s){const r=this.getTimesForAllAxes(t),o=this.getKeyframeTrackValues(r,t,n);return new ko(e+"."+s,r,o)}generateRotationTrack(e,t,n,s,r){let o,a;if(t.x!==void 0&&t.y!==void 0&&t.z!==void 0){const h=this.interpolateRotations(t.x,t.y,t.z,r);o=h[0],a=h[1]}const l=un(0);n!==void 0&&(n=n.map(Te.degToRad),n.push(l),n=new kt().fromArray(n),n=new ct().setFromEuler(n)),s!==void 0&&(s=s.map(Te.degToRad),s.push(l),s=new kt().fromArray(s),s=new ct().setFromEuler(s).invert());const d=new ct,c=new kt,f=[];if(!a||!o)return new Ws(e+".quaternion",[0],[0]);for(let h=0;h<a.length;h+=3)c.set(a[h],a[h+1],a[h+2],r),d.setFromEuler(c),n!==void 0&&d.premultiply(n),s!==void 0&&d.multiply(s),h>2&&new ct().fromArray(f,(h-3)/3*4).dot(d)<0&&d.set(-d.x,-d.y,-d.z,-d.w),d.toArray(f,h/3*4);return new Ws(e+".quaternion",o,f)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(r){return r/100}),s=Se.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new Io(e.modelName+".morphTargetInfluences["+s+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(e.x!==void 0&&(t=t.concat(e.x.times)),e.y!==void 0&&(t=t.concat(e.y.times)),e.z!==void 0&&(t=t.concat(e.z.times)),t=t.sort(function(n,s){return n-s}),t.length>1){let n=1,s=t[0];for(let r=1;r<t.length;r++){const o=t[r];o!==s&&(t[n]=o,s=o,n++)}t=t.slice(0,n)}return t}getKeyframeTrackValues(e,t,n){const s=n,r=[];let o=-1,a=-1,l=-1;return e.forEach(function(d){if(t.x&&(o=t.x.times.indexOf(d)),t.y&&(a=t.y.times.indexOf(d)),t.z&&(l=t.z.times.indexOf(d)),o!==-1){const c=t.x.values[o];r.push(c),s[0]=c}else r.push(s[0]);if(a!==-1){const c=t.y.values[a];r.push(c),s[1]=c}else r.push(s[1]);if(l!==-1){const c=t.z.values[l];r.push(c),s[2]=c}else r.push(s[2])}),r}interpolateRotations(e,t,n,s){const r=[],o=[];r.push(e.times[0]),o.push(Te.degToRad(e.values[0])),o.push(Te.degToRad(t.values[0])),o.push(Te.degToRad(n.values[0]));for(let a=1;a<e.values.length;a++){const l=[e.values[a-1],t.values[a-1],n.values[a-1]];if(isNaN(l[0])||isNaN(l[1])||isNaN(l[2]))continue;const d=l.map(Te.degToRad),c=[e.values[a],t.values[a],n.values[a]];if(isNaN(c[0])||isNaN(c[1])||isNaN(c[2]))continue;const f=c.map(Te.degToRad),h=[c[0]-l[0],c[1]-l[1],c[2]-l[2]],p=[Math.abs(h[0]),Math.abs(h[1]),Math.abs(h[2])];if(p[0]>=180||p[1]>=180||p[2]>=180){const u=Math.max(...p)/180,g=new kt(...d,s),b=new kt(...f,s),S=new ct().setFromEuler(g),C=new ct().setFromEuler(b);S.dot(C)&&C.set(-C.x,-C.y,-C.z,-C.w);const I=e.times[a-1],N=e.times[a]-I,F=new ct,H=new kt;for(let $=0;$<1;$+=1/u)F.copy(S.clone().slerp(C.clone(),$)),r.push(I+$*N),H.setFromQuaternion(F,s),o.push(H.x),o.push(H.y),o.push(H.z)}else r.push(e.times[a]),o.push(Te.degToRad(e.values[a])),o.push(Te.degToRad(t.values[a])),o.push(Te.degToRad(n.values[a]))}return[r,o]}}class Vl{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new ji,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(s,r){const o=s.match(/^[\s\t]*;/),a=s.match(/^[\s\t]*$/);if(o||a)return;const l=s.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),d=s.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),c=s.match("^\\t{"+(t.currentIndent-1)+"}}");l?t.parseNodeBegin(s,l):d?t.parseNodeProperty(s,d,n[++r]):c?t.popStack():s.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(s)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),s=t[2].split(",").map(function(l){return l.trim().replace(/^"/,"").replace(/"$/,"")}),r={name:n},o=this.parseNodeAttr(s),a=this.getCurrentNode();this.currentIndent===0?this.allNodes.add(n,r):n in a?(n==="PoseNode"?a.PoseNode.push(r):a[n].id!==void 0&&(a[n]={},a[n][a[n].id]=a[n]),o.id!==""&&(a[n][o.id]=r)):typeof o.id=="number"?(a[n]={},a[n][o.id]=r):n!=="Properties70"&&(n==="PoseNode"?a[n]=[r]:a[n]=r),typeof o.id=="number"&&(r.id=o.id),o.name!==""&&(r.attrName=o.name),o.type!==""&&(r.attrType=o.type),this.pushStack(r)}parseNodeAttr(e){let t=e[0];e[0]!==""&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",s="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),s=e[2]),{id:t,name:n,type:s}}parseNodeProperty(e,t,n){let s=t[1].replace(/^"/,"").replace(/"$/,"").trim(),r=t[2].replace(/^"/,"").replace(/"$/,"").trim();s==="Content"&&r===","&&(r=n.replace(/"/g,"").replace(/,$/,"").trim());const o=this.getCurrentNode();if(o.name==="Properties70"){this.parseNodeSpecialProperty(e,s,r);return}if(s==="C"){const l=r.split(",").slice(1),d=parseInt(l[0]),c=parseInt(l[1]);let f=r.split(",").slice(3);f=f.map(function(h){return h.trim().replace(/^"/,"")}),s="connections",r=[d,c],Yl(r,f),o[s]===void 0&&(o[s]=[])}s==="Node"&&(o.id=r),s in o&&Array.isArray(o[s])?o[s].push(r):s!=="a"?o[s]=r:o.a=r,this.setCurrentProp(o,s),s==="a"&&r.slice(-1)!==","&&(o.a=ns(r))}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,e.slice(-1)!==","&&(t.a=ns(t.a))}parseNodeSpecialProperty(e,t,n){const s=n.split('",').map(function(c){return c.trim().replace(/^\"/,"").replace(/\s/,"_")}),r=s[0],o=s[1],a=s[2],l=s[3];let d=s[4];switch(o){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":d=parseFloat(d);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":d=ns(d);break}this.getPrevNode()[r]={type:o,type2:a,flag:l,value:d},this.setCurrentProp(this.getPrevNode(),r)}}class jl{parse(e){const t=new yr(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const s=new ji;for(;!this.endOfContent(t);){const r=this.parseNode(t,n);r!==null&&s.add(r.name,r)}return s}endOfContent(e){return e.size()%16===0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},s=t>=7500?e.getUint64():e.getUint32(),r=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const o=e.getUint8(),a=e.getString(o);if(s===0)return null;const l=[];for(let h=0;h<r;h++)l.push(this.parseProperty(e));const d=l.length>0?l[0]:"",c=l.length>1?l[1]:"",f=l.length>2?l[2]:"";for(n.singleProperty=r===1&&e.getOffset()===s;s>e.getOffset();){const h=this.parseNode(e,t);h!==null&&this.parseSubNode(a,n,h)}return n.propertyList=l,typeof d=="number"&&(n.id=d),c!==""&&(n.attrName=c),f!==""&&(n.attrType=f),a!==""&&(n.name=a),n}parseSubNode(e,t,n){if(n.singleProperty===!0){const s=n.propertyList[0];Array.isArray(s)?(t[n.name]=n,n.a=s):t[n.name]=s}else if(e==="Connections"&&n.name==="C"){const s=[];n.propertyList.forEach(function(r,o){o!==0&&s.push(r)}),t.connections===void 0&&(t.connections=[]),t.connections.push(s)}else if(n.name==="Properties70")Object.keys(n).forEach(function(r){t[r]=n[r]});else if(e==="Properties70"&&n.name==="P"){let s=n.propertyList[0],r=n.propertyList[1];const o=n.propertyList[2],a=n.propertyList[3];let l;s.indexOf("Lcl ")===0&&(s=s.replace("Lcl ","Lcl_")),r.indexOf("Lcl ")===0&&(r=r.replace("Lcl ","Lcl_")),r==="Color"||r==="ColorRGB"||r==="Vector"||r==="Vector3D"||r.indexOf("Lcl_")===0?l=[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:l=n.propertyList[4],t[s]={type:r,type2:o,flag:a,value:l}}else t[n.name]===void 0?typeof n.id=="number"?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:n.name==="PoseNode"?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):t[n.name][n.id]===void 0&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const s=e.getUint32(),r=e.getUint32(),o=e.getUint32();if(r===0)switch(t){case"b":case"c":return e.getBooleanArray(s);case"d":return e.getFloat64Array(s);case"f":return e.getFloat32Array(s);case"i":return e.getInt32Array(s);case"l":return e.getInt64Array(s)}const a=Il(new Uint8Array(e.getArrayBuffer(o))),l=new yr(a.buffer);switch(t){case"b":case"c":return l.getBooleanArray(s);case"d":return l.getFloat64Array(s);case"f":return l.getFloat32Array(s);case"i":return l.getInt32Array(s);case"l":return l.getInt64Array(s)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class yr{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=t!==void 0?t:!0,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return(this.getUint8()&1)===1}getBooleanArray(e){const t=[];for(let n=0;n<e;n++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t&2147483648?(t=~t&4294967295,e=~e&4294967295,e===4294967295&&(t=t+1&4294967295),e=e+1&4294967295,-(t*4294967296+e)):t*4294967296+e}getInt64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t*4294967296+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let n=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const s=n.indexOf(0);return s>=0&&(n=new Uint8Array(this.dv.buffer,t,s)),this._textDecoder.decode(n)}}class ji{add(e,t){this[e]=t}}function Hl(i){const e="Kaydara FBX Binary \0";return i.byteLength>=e.length&&e===Wi(i,0,e.length)}function Wl(i){const e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let t=0;function n(s){const r=i[s-1];return i=i.slice(t+s),t++,r}for(let s=0;s<e.length;++s)if(n(1)===e[s])return!1;return!0}function xr(i){const e=/FBXVersion: (\d+)/,t=i.match(e);if(t)return parseInt(t[1]);throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function Gl(i){return i/46186158e3}const Xl=[];function Rn(i,e,t,n){let s;switch(n.mappingType){case"ByPolygonVertex":s=i;break;case"ByPolygon":s=e;break;case"ByVertice":s=t;break;case"AllSame":s=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}n.referenceType==="IndexToDirect"&&(s=n.indices[s]);const r=s*n.dataSize,o=r+n.dataSize;return ql(Xl,n.buffer,r,o)}const ts=new kt,Ht=new Pe;function Hi(i){const e=new fe,t=new fe,n=new fe,s=new fe,r=new fe,o=new fe,a=new fe,l=new fe,d=new fe,c=new fe,f=new fe,h=new fe,p=i.inheritType?i.inheritType:0;i.translation&&e.setPosition(Ht.fromArray(i.translation));const m=un(0);if(i.preRotation){const Y=i.preRotation.map(Te.degToRad);Y.push(m),t.makeRotationFromEuler(ts.fromArray(Y))}if(i.rotation){const Y=i.rotation.map(Te.degToRad);Y.push(i.eulerOrder||m),n.makeRotationFromEuler(ts.fromArray(Y))}if(i.postRotation){const Y=i.postRotation.map(Te.degToRad);Y.push(m),s.makeRotationFromEuler(ts.fromArray(Y)),s.invert()}i.scale&&r.scale(Ht.fromArray(i.scale)),i.scalingOffset&&a.setPosition(Ht.fromArray(i.scalingOffset)),i.scalingPivot&&o.setPosition(Ht.fromArray(i.scalingPivot)),i.rotationOffset&&l.setPosition(Ht.fromArray(i.rotationOffset)),i.rotationPivot&&d.setPosition(Ht.fromArray(i.rotationPivot)),i.parentMatrixWorld&&(f.copy(i.parentMatrix),c.copy(i.parentMatrixWorld));const u=t.clone().multiply(n).multiply(s),g=new fe;g.extractRotation(c);const b=new fe;b.copyPosition(c);const S=b.clone().invert().multiply(c),C=g.clone().invert().multiply(S),I=r,N=new fe;if(p===0)N.copy(g).multiply(u).multiply(C).multiply(I);else if(p===1)N.copy(g).multiply(C).multiply(u).multiply(I);else{const ve=new fe().scale(new Pe().setFromMatrixScale(f)).clone().invert(),w=C.clone().multiply(ve);N.copy(g).multiply(u).multiply(w).multiply(I)}const F=d.clone().invert(),H=o.clone().invert();let $=e.clone().multiply(l).multiply(d).multiply(t).multiply(n).multiply(s).multiply(F).multiply(a).multiply(o).multiply(r).multiply(H);const K=new fe().copyPosition($),j=c.clone().multiply(K);return h.copyPosition(j),$=h.clone().multiply(N),$.premultiply(c.invert()),$}function un(i){i=i||0;const e=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return i===6?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),e[0]):e[i]}function ns(i){return i.split(",").map(function(t){return parseFloat(t)})}function Wi(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=i.byteLength),new TextDecoder().decode(new Uint8Array(i,e,t))}function Yl(i,e){for(let t=0,n=i.length,s=e.length;t<s;t++,n++)i[n]=e[t]}function ql(i,e,t,n){for(let s=t,r=0;s<n;s++,r++)i[r]=e[s];return i}const Jl=[16729156,4491519,4521796,16777028],Kl=["./models/T_pixelTank_red.png","./models/T_pixelTank_blue.png","./models/T_pixelTank_green.png","./models/T_pixelTank_yellow.png"];let Pn=null,ys=[],Dn=null;function Zl(){return Dn||(Dn=new Promise((i,e)=>{const t=new zl,n=new A.TextureLoader;ys=Kl.map(s=>{const r=n.load(s);return r.magFilter=A.NearestFilter,r.minFilter=A.NearestFilter,r.colorSpace=A.SRGBColorSpace,r}),t.load("./models/pixelTank.fbx",s=>{s.scale.setScalar(.012),s.traverse(r=>{r.isMesh&&(r.castShadow=!0)}),Pn=s,i(s)},void 0,e)}),Dn)}function Ql(i){return new A.MeshStandardMaterial({map:ys[i]||ys[2],roughness:.8,metalness:.1})}class ec{constructor(e){if(this.group=new A.Group,this.body=new A.Group,this.turret=new A.Group,this.targetX=0,this.targetZ=0,this.targetAngle=0,this.currentTurretAngle=0,this.targetBodyAngle=0,this.currentBodyAngle=0,this.dead=!1,this.shieldActive=!1,this.shieldBreakTime=0,this.shieldFragments=[],this.explosionTime=0,this.explosionParts=[],this.team=0,this.team=e,Pn){const a=Pn.clone(),l=Pn.clone(),d=Ql(e);a.traverse(c=>{c.name.toLowerCase().includes("turret")?c.visible=!1:c.isMesh&&(c.material=d)}),l.traverse(c=>{c.isMesh&&!c.name.toLowerCase().includes("turret")?c.material=new A.MeshBasicMaterial({visible:!1}):c.isMesh&&(c.material=d)}),this.body.add(a),this.turret.position.set(0,0,-.3),l.position.z+=.3,this.turret.add(l)}else this.createFallbackTank();this.group.add(this.body),this.group.add(this.turret);const t=new A.RingGeometry(.9,1.2,20);t.rotateX(-Math.PI/2),this.teamIndicator=new A.Mesh(t,new A.MeshBasicMaterial({color:Jl[e]||16777215,transparent:!0,opacity:.7})),this.teamIndicator.position.y=.02,this.group.add(this.teamIndicator);const n=new A.SpriteMaterial({color:3355443,transparent:!0,opacity:.6});this.healthBg=new A.Sprite(n),this.healthBg.scale.set(1.4,.15,1),this.healthBg.position.y=2.2,this.group.add(this.healthBg);const s=new A.SpriteMaterial({color:4521796});this.healthBar=new A.Sprite(s),this.healthBar.scale.set(1.4,.15,1),this.healthBar.position.y=2.2,this.group.add(this.healthBar);const r=new A.CylinderGeometry(1.4,1.4,2.6,20,1,!0),o=new A.MeshBasicMaterial({color:4508927,transparent:!0,opacity:.12,side:A.DoubleSide,depthWrite:!1});this.shieldBubble=new A.Mesh(r,o),this.shieldBubble.position.y=1.3,this.shieldBubble.visible=!1,this.group.add(this.shieldBubble)}createFallbackTank(){const e=new A.BoxGeometry(1,.4,1.4),t=new A.MeshStandardMaterial({color:6719590,roughness:.7}),n=new A.Mesh(e,t);n.position.y=.3,n.castShadow=!0,this.body.add(n);for(const l of[-.55,.55]){const d=new A.BoxGeometry(.2,.25,1.5),c=new A.Mesh(d,new A.MeshStandardMaterial({color:4473924}));c.position.set(l,.2,0),c.castShadow=!0,this.body.add(c)}const s=new A.CylinderGeometry(.35,.4,.25,8),r=new A.Mesh(s,new A.MeshStandardMaterial({color:5601109}));r.position.y=.55,this.turret.add(r);const o=new A.CylinderGeometry(.06,.08,1,6);o.rotateX(Math.PI/2),o.translate(0,0,.5);const a=new A.Mesh(o,new A.MeshStandardMaterial({color:5592405}));a.position.y=.55,this.turret.add(a)}update(e){const t=this.targetX-this.group.position.x,n=this.targetZ-this.group.position.z,s=Math.sqrt(t*t+n*n);this.group.position.x=A.MathUtils.lerp(this.group.position.x,this.targetX,.2),this.group.position.z=A.MathUtils.lerp(this.group.position.z,this.targetZ,.2),s>.02&&(this.targetBodyAngle=Math.atan2(t,n));let r=this.targetBodyAngle-this.currentBodyAngle;for(;r>Math.PI;)r-=Math.PI*2;for(;r<-Math.PI;)r+=Math.PI*2;this.currentBodyAngle+=r*.15,this.body.rotation.y=this.currentBodyAngle;let a=this.targetAngle*(Math.PI/180)-this.currentTurretAngle;for(;a>Math.PI;)a-=Math.PI*2;for(;a<-Math.PI;)a+=Math.PI*2;this.currentTurretAngle+=a*.25,this.turret.rotation.y=this.currentTurretAngle;const l=-.3;if(this.turret.position.x=l*Math.sin(this.currentBodyAngle),this.turret.position.z=l*Math.cos(this.currentBodyAngle),this.shieldActive){this.shieldBubble.visible=!0;const c=.1+Math.sin(Date.now()*.004)*.05;this.shieldBubble.material.opacity=c,this.shieldBubble.material.color.setHex(4508927),this.shieldBubble.scale.set(1,1,1),this.shieldBubble.rotation.y+=.008}else if(this.shieldBreakTime>0){const c=Date.now()-this.shieldBreakTime,h=Math.min(c/250,1);this.shieldBubble.visible=!0;const p=1+h*.5;this.shieldBubble.scale.set(p,1+h*.15,p);const m=this.shieldBubble.material;m.color.setHex(16777215),m.opacity=.35*(1-h);for(const u of this.shieldFragments){const g=u._vel;u.position.add(g.clone().multiplyScalar(.016)),g.y-=.06;const b=u.material;b.opacity=.7*(1-h),u.rotation.x+=.1,u.rotation.z+=.15}if(h>=1){this.shieldBreakTime=0,this.shieldBubble.visible=!1;for(const u of this.shieldFragments)this.group.remove(u),u.geometry.dispose();this.shieldFragments=[]}}else this.shieldBubble.visible=!1;if(this.explosionTime>0){const c=Date.now()-this.explosionTime,h=Math.min(c/600,1),p=1-(1-h)*(1-h);for(const m of this.explosionParts){const u=m;if(u._type==="fireball"){const g=1+p*3;m.scale.set(g,g,g);const b=m.material;b.opacity=.9*(1-h*h);const S=1-h*.6,C=.6-h*.6,I=.1*(1-h);b.color.setRGB(S,Math.max(0,C),Math.max(0,I))}else if(u._type==="debris"){const g=u._vel;m.position.add(g.clone().multiplyScalar(.016)),g.y-=.08,m.rotation.x+=u._spin.x,m.rotation.z+=u._spin.z;const b=m.material;b.opacity=.9*(1-h)}else if(u._type==="ring"){const g=1+p*4;m.scale.set(g,1,g);const b=m.material;b.opacity=.5*(1-h)}}if(h>=1){this.explosionTime=0;for(const m of this.explosionParts)this.group.remove(m),m.geometry&&m.geometry.dispose();this.explosionParts=[]}}const d=!this.dead||Date.now()%500<250;this.body.visible=d,this.turret.visible=d,this.teamIndicator.visible=d,this.healthBar.visible=d,this.healthBg.visible=d}setDead(e){const t=this.dead;if(this.dead=e,e&&!t){this.explosionTime=Date.now();const n=new A.SphereGeometry(.5,10,10),s=new A.MeshBasicMaterial({color:16755234,transparent:!0,opacity:.8,depthWrite:!1}),r=new A.Mesh(n,s);r.position.y=1,r._type="fireball",this.group.add(r),this.explosionParts.push(r);const o=new A.RingGeometry(.4,.7,20);o.rotateX(-Math.PI/2);const a=new A.MeshBasicMaterial({color:16737792,transparent:!0,opacity:.5,side:A.DoubleSide,depthWrite:!1}),l=new A.Mesh(o,a);l.position.y=.05,l._type="ring",this.group.add(l),this.explosionParts.push(l);for(let d=0;d<10;d++){const c=d/10*Math.PI*2+Math.random()*.5,f=.1+Math.random()*.15,h=new A.BoxGeometry(f,f,f),p=new A.MeshBasicMaterial({color:Math.random()>.5?4473924:8939059,transparent:!0,opacity:.9,depthWrite:!1}),m=new A.Mesh(h,p);m.position.set(Math.cos(c)*.4,.5+Math.random()*1,Math.sin(c)*.4);const u=.15+Math.random()*.15;m._type="debris",m._vel=new A.Vector3(Math.cos(c)*u,.12+Math.random()*.15,Math.sin(c)*u),m._spin={x:(Math.random()-.5)*.3,z:(Math.random()-.5)*.3},this.group.add(m),this.explosionParts.push(m)}}}setShield(e){const t=this.shieldActive;if(this.shieldActive=e>0,t&&!this.shieldActive){this.shieldBreakTime=Date.now();for(let n=0;n<8;n++){const s=n/8*Math.PI*2,r=new A.PlaneGeometry(.25,.35),o=new A.MeshBasicMaterial({color:4508927,transparent:!0,opacity:.7,side:A.DoubleSide,depthWrite:!1}),a=new A.Mesh(r,o);a.position.set(Math.cos(s)*1.4,1+Math.random()*1.2,Math.sin(s)*1.4),a.rotation.set(Math.random()*Math.PI,s,Math.random()*Math.PI);const l=.12+Math.random()*.08;a._vel=new A.Vector3(Math.cos(s)*l,.06+Math.random()*.1,Math.sin(s)*l),this.group.add(a),this.shieldFragments.push(a)}}}setHealth(e){const t=Math.max(0,e/10);this.healthBar.scale.set(1.4*t,.15,1),this.healthBar.position.x=-(1.4*(1-t))/2;const n=this.healthBar.material;t>.5?n.color.setHex(4521796):t>.25?n.color.setHex(16755268):n.color.setHex(16729156)}dispose(){this.group.traverse(e=>{var t;e.isMesh&&((t=e.geometry)==null||t.dispose())})}}const tc=[[13.5,2,1,4],[13.5,12,1,2],[12.5,13.5,3,1],[2,13.5,4,1],[11.5,15,1,2],[11.5,23.5,1,5],[10,26.5,4,1],[6,26.5,4,1],[2,34.5,4,1],[12.5,34.5,3,1],[13.5,36,1,2],[15,36.5,2,1],[13.5,46,1,4],[23.5,36.5,5,1],[26.5,38,1,4],[26.5,42,1,4],[34.5,46,1,4],[34.5,36,1,2],[35.5,34.5,3,1],[36.5,33,1,2],[46,34.5,4,1],[36.5,24.5,1,5],[38,21.5,4,1],[42,21.5,4,1],[46,13.5,4,1],[35.5,13.5,3,1],[34.5,12,1,2],[33,11.5,2,1],[34.5,2,1,4],[24.5,11.5,5,1],[21.5,10,1,4],[21.5,6,1,4],[18.5,22,1,6],[19,18.5,2,1],[26,18.5,6,1],[29.5,19,1,2],[29.5,26,1,6],[29,29.5,2,1],[22,29.5,6,1],[18.5,29,1,2]];class nc{constructor(e){this.group=new A.Group,this.buildGround(),this.buildBlocks(),this.buildBoundary(),e.add(this.group)}buildGround(){const e=new A.PlaneGeometry(48,48,1,48);e.rotateX(-Math.PI/2);const t=new Float32Array(e.attributes.position.count*3),n=e.attributes.position;for(let d=0;d<n.count;d++){const f=(n.getZ(d)+24)/48;t[d*3]=.92-f*.72,t[d*3+1]=.94-f*.59,t[d*3+2]=.96-f*.36}e.setAttribute("color",new A.BufferAttribute(t,3));const s=new A.MeshStandardMaterial({vertexColors:!0,roughness:.4,metalness:.05}),r=new A.Mesh(e,s);r.position.set(24,-.01,24),r.receiveShadow=!0,this.group.add(r);const o=new A.PlaneGeometry(48,48,48,48),a=new A.MeshBasicMaterial({color:4491468,wireframe:!0,transparent:!0,opacity:.12}),l=new A.Mesh(o,a);l.rotation.x=-Math.PI/2,l.position.set(24,.01,24),this.group.add(l)}buildBlocks(){const e=new A.MeshStandardMaterial({color:2254506,roughness:.3,metalness:.2,transparent:!0,opacity:.85}),t=new A.MeshBasicMaterial({color:6732799,wireframe:!0,transparent:!0,opacity:.5});for(const[n,s,r,o]of tc){const a=new A.BoxGeometry(r,1.2,o),l=new A.Mesh(a,e);l.position.set(n,.6,s),l.castShadow=!0,l.receiveShadow=!0,this.group.add(l);const d=new A.Mesh(a,t);d.position.set(n,.6,s),this.group.add(d)}}buildBoundary(){const n=new A.MeshStandardMaterial({color:1721480,roughness:.3,metalness:.3,transparent:!0,opacity:.8}),s=new A.MeshBasicMaterial({color:5614335,wireframe:!0,transparent:!0,opacity:.4}),r=[[24,-1.5/2,48+1.5*2,1.5,2],[24,48+1.5/2,48+1.5*2,1.5,2],[-1.5/2,24,1.5,48+1.5*2,2],[48+1.5/2,24,1.5,48+1.5*2,2]];for(const[o,a,l,d,c]of r){const f=new A.BoxGeometry(l,c,d),h=new A.Mesh(f,n);h.position.set(o,c/2,a),h.castShadow=!0,this.group.add(h);const p=new A.Mesh(f,s);p.position.set(o,c/2,a),this.group.add(p)}}}class sc{constructor(){this.ctx=new AudioContext;const e=()=>{this.ctx.resume(),window.removeEventListener("click",e),window.removeEventListener("keydown",e)};window.addEventListener("click",e),window.addEventListener("keydown",e)}shoot(){this.noise(.08,800,200,.15)}shootSpecial(){this.noise(.12,1200,300,.2)}hit(e=.25){this.noise(.15,200,60,e)}explosion(){const e=this.ctx.currentTime,t=this.ctx.createOscillator(),n=this.ctx.createGain();t.type="square",t.frequency.setValueAtTime(60+Math.random()*30,e),t.frequency.exponentialRampToValueAtTime(18,e+.8),n.gain.setValueAtTime(.3,e),n.gain.exponentialRampToValueAtTime(.001,e+.8),t.connect(n).connect(this.ctx.destination),t.start(e),t.stop(e+.8);for(let o=0;o<3;o++){const a=this.ctx.createOscillator(),l=this.ctx.createGain();a.type="sawtooth";const d=100+Math.random()*200;a.frequency.setValueAtTime(d,e);const c=.15+Math.random()*.2;a.frequency.exponentialRampToValueAtTime(20+Math.random()*30,e+c),a.frequency.setValueAtTime(60+Math.random()*80,e+c),a.frequency.exponentialRampToValueAtTime(15,e+.7),l.gain.setValueAtTime(.12,e+o*.03),l.gain.exponentialRampToValueAtTime(.001,e+.5+Math.random()*.3),a.connect(l).connect(this.ctx.destination),a.start(e+o*.03),a.stop(e+.8)}const s=this.ctx.createOscillator(),r=this.ctx.createGain();s.type="sawtooth",s.frequency.setValueAtTime(300+Math.random()*200,e),s.frequency.exponentialRampToValueAtTime(30,e+.25),r.gain.setValueAtTime(.15,e),r.gain.exponentialRampToValueAtTime(.001,e+.25),s.connect(r).connect(this.ctx.destination),s.start(e),s.stop(e+.25)}pickupRepair(){this.tone(.12,520,780,.13),setTimeout(()=>this.tone(.14,780,1040,.13),80)}pickupShield(){this.tone(.18,400,1200,.1),setTimeout(()=>this.tone(.15,900,1400,.08),50)}pickupDamage(){this.noise(.1,300,100,.2),setTimeout(()=>this.noise(.06,900,400,.12),40)}noise(e,t,n,s){const r=this.ctx.currentTime,o=this.ctx.createOscillator(),a=this.ctx.createGain();o.type="sawtooth",o.frequency.setValueAtTime(t,r),o.frequency.exponentialRampToValueAtTime(n,r+e),a.gain.setValueAtTime(s,r),a.gain.exponentialRampToValueAtTime(.001,r+e),o.connect(a).connect(this.ctx.destination),o.start(r),o.stop(r+e)}tone(e,t,n,s){const r=this.ctx.currentTime,o=this.ctx.createOscillator(),a=this.ctx.createGain();o.type="sine",o.frequency.setValueAtTime(t,r),o.frequency.linearRampToValueAtTime(n,r+e),a.gain.setValueAtTime(s,r),a.gain.linearRampToValueAtTime(0,r+e),o.connect(a).connect(this.ctx.destination),o.start(r),o.stop(r+e)}}const rc=[16729156,4491519,4521796,16777028],vr=["Red","Blue","Green","Yellow"];class ic{constructor(){this.tanks=new Map,this.bulletMeshes=new Map,this.pickableMeshes=new Map,this.mySessionId="",this.keys=new Set,this.mouseX=0,this.mouseY=0,this.mouseDown=!1,this.lastSentDirX=-999,this.lastSentDirY=-999,this.lastSentAngle=-999,this.lastTargetSendTime=0,this.raycaster=new A.Raycaster,this.groundPlane=new A.Plane(new A.Vector3(0,1,0),0),this.scoreElements=new Map,this.animate=()=>{requestAnimationFrame(this.animate),this.room&&this.sendInput();for(const[,d]of this.tanks)d.update(.016);const a=Date.now()*.001;for(const[,d]of this.pickableMeshes)d.position.y=.6+Math.sin(a*2)*.15,d.rotation.y=a;for(const[,d]of this.bulletMeshes){const c=d;c._sx!==void 0&&(d.position.x=A.MathUtils.lerp(d.position.x,c._sx,.4),d.position.z=A.MathUtils.lerp(d.position.z,c._sy,.4))}const l=this.tanks.get(this.mySessionId);if(l){const d=l.group.position.x,c=l.group.position.z,f=this.mouseX/window.innerWidth*2-1,h=this.mouseY/window.innerHeight*2-1,p=3,m=(f+h)*.707*p,u=(-f+h)*.707*p;this.camera.position.x=A.MathUtils.lerp(this.camera.position.x,d+20+m,.08),this.camera.position.z=A.MathUtils.lerp(this.camera.position.z,c+20+u,.08),this.camera.position.y=20,this.camera.lookAt(this.camera.position.x-20,0,this.camera.position.z-20)}this.renderer.render(this.scene,this.camera)},this.scene=new A.Scene,this.scene.background=new A.Color(858922),this.scene.fog=new A.Fog(858922,35,65);const e=22,t=window.innerWidth/window.innerHeight;this.camera=new A.OrthographicCamera(-e*t/2,e*t/2,e/2,-e/2,.1,200),this.camera.position.set(44,20,44),this.camera.lookAt(24,0,24),this.renderer=new A.WebGLRenderer({antialias:!0}),this.renderer.setSize(window.innerWidth,window.innerHeight),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=A.PCFSoftShadowMap,document.body.prepend(this.renderer.domElement);const n=new A.AmbientLight(8947882,.7);this.scene.add(n);const s=new A.DirectionalLight(16772829,1.2);s.position.set(30,40,20),s.castShadow=!0,s.shadow.mapSize.set(2048,2048),s.shadow.camera.left=-30,s.shadow.camera.right=30,s.shadow.camera.top=30,s.shadow.camera.bottom=-30,this.scene.add(s),this.map=new nc(this.scene),this.sound=new sc;const o=new URLSearchParams(window.location.search).get("server")||void 0||`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.hostname}:2567`;this.network=new ul(o),this.healthFill=document.getElementById("health-fill"),this.shieldFill=document.getElementById("shield-fill"),this.scoresList=document.getElementById("scores-list"),this.deathScreen=document.getElementById("death-screen"),this.winnerScreen=document.getElementById("winner-screen"),this.ammoDisplay=document.getElementById("ammo-display"),this.connectStatus=document.getElementById("connect-status"),this.setupInput(),window.addEventListener("resize",()=>this.onResize())}async start(){await Zl();try{this.room=await this.network.connect(),this.mySessionId=this.room.sessionId,this.connectStatus.style.display="none",this.bindRoomEvents()}catch(e){this.connectStatus.textContent="Failed to connect. Is server running?",console.error(e);return}this.animate()}bindRoomEvents(){const e=this.room.state,t=oa.get(this.room);t.onAdd("tanks",(n,s)=>{const r=new ec(n.team);r.targetX=n.x,r.targetZ=n.y,r.group.position.set(n.x,0,n.y),r.dead=n.dead,r.setHealth(n.hp),this.scene.add(r.group),this.tanks.set(s,r),t.listen(n,"x",o=>r.targetX=o),t.listen(n,"y",o=>r.targetZ=o),t.listen(n,"angle",o=>{s!==this.mySessionId&&(r.targetAngle=o)}),t.listen(n,"dead",(o,a)=>{r.setDead(o),o&&a===!1&&this.sound.explosion(),s===this.mySessionId&&(o&&a===!1?this.deathScreen.style.display="block":o||(this.deathScreen.style.display="none"))}),t.listen(n,"hp",(o,a)=>{if(r.setHealth(o),o<a){const l=this.tanks.get(this.mySessionId);if(l){const d=r.group.position.x-l.group.position.x,c=r.group.position.z-l.group.position.z,f=Math.sqrt(d*d+c*c),h=Math.max(0,.25*(1-f/25));h>.01&&this.sound.hit(h)}}s===this.mySessionId&&(this.healthFill.style.width=`${Math.max(0,o)*10}%`)}),t.listen(n,"shield",o=>{r.setShield(o),s===this.mySessionId&&(this.shieldFill.style.width=`${Math.max(0,o)*10}%`)}),t.listen(n,"score",o=>{this.updateScores()})}),t.onRemove("tanks",(n,s)=>{const r=this.tanks.get(s);r&&(this.scene.remove(r.group),r.dispose(),this.tanks.delete(s))}),t.onAdd("bullets",(n,s)=>{const r=n.special;let o=r?16746496:16777062;const a=e.tanks.get(n.owner);a&&(o=r?16746496:rc[a.team]||16777062);const l=new A.SphereGeometry(r?.2:.12,6,6),d=new A.MeshBasicMaterial({color:o}),c=new A.Mesh(l,d);c.position.set(n.x,1.5,n.y),c._tx=n.tx,c._ty=n.ty,c._speed=n.speed,c._sx=n.x,c._sy=n.y,this.scene.add(c),this.bulletMeshes.set(s,c),t.listen(n,"x",f=>{c._sx=f}),t.listen(n,"y",f=>{c._sy=f}),n.owner===this.mySessionId&&(r?this.sound.shootSpecial():this.sound.shoot())}),t.onRemove("bullets",(n,s)=>{const r=this.bulletMeshes.get(s);r&&(this.scene.remove(r),r.geometry.dispose(),this.bulletMeshes.delete(s))}),t.onAdd("pickables",(n,s)=>{const r=new A.Group,a={repair:4521796,damage:16729156,shield:4491519}[n.type]||16777215,l=new A.MeshStandardMaterial({color:a,emissive:a,emissiveIntensity:.4});if(n.type==="repair"){const f=new A.Mesh(new A.BoxGeometry(.7,.2,.15),l),h=new A.Mesh(new A.BoxGeometry(.2,.7,.15),l);r.add(f),r.add(h)}else if(n.type==="shield"){const f=new A.Shape;f.moveTo(0,.4),f.lineTo(.35,.25),f.lineTo(.35,0),f.quadraticCurveTo(.3,-.3,0,-.45),f.quadraticCurveTo(-.3,-.3,-.35,0),f.lineTo(-.35,.25),f.closePath();const h=new A.ExtrudeGeometry(f,{depth:.12,bevelEnabled:!1});h.center();const p=new A.Mesh(h,l);r.add(p)}else{const f=new A.Mesh(new A.OctahedronGeometry(.35),l);r.add(f)}const d=new A.SphereGeometry(.5,8,8),c=new A.MeshBasicMaterial({color:a,transparent:!0,opacity:.15});r.add(new A.Mesh(d,c)),r.position.set(n.x,.6,n.y),this.scene.add(r),this.pickableMeshes.set(s,r)}),t.onRemove("pickables",(n,s)=>{const r=this.pickableMeshes.get(s);r&&(this.scene.remove(r),this.pickableMeshes.delete(s),n.type==="repair"?this.sound.pickupRepair():n.type==="shield"?this.sound.pickupShield():n.type==="damage"&&this.sound.pickupDamage())}),window.game=this,t.listen("winnerTeam",n=>{n>=0&&this.showWinnerScreen(n)}),t.onAdd("teams",n=>{t.listen(n,"score",()=>this.updateScores())})}updateScores(){const e=this.room.state,t=[];for(let s=0;s<4;s++){const r=e.teams[s];r&&t.push({id:s,score:r.score})}t.sort((s,r)=>r.score-s.score);const n=28;for(const s of t)if(!this.scoreElements.has(s.id)){const r=document.createElement("div");r.className=`team-score team-${s.id}`,r.innerHTML=`<span class="team-name">${vr[s.id]}</span><span class="team-pts">0</span>`,this.scoresList.appendChild(r),this.scoreElements.set(s.id,r)}for(let s=0;s<t.length;s++){const r=t[s],o=this.scoreElements.get(r.id);o.style.top=`${s*n}px`,o.querySelector(".team-pts").textContent=`${r.score}`}this.scoresList.style.height=`${t.length*n}px`}showWinnerScreen(e){const t=["rgba(200,40,40,0.92)","rgba(40,100,220,0.92)","rgba(40,180,40,0.92)","rgba(200,200,40,0.92)"],n=["rgba(255,120,120,0.8)","rgba(100,170,255,0.8)","rgba(100,255,100,0.8)","rgba(255,255,100,0.8)"],s=["rgba(255,0,0,0.08)","rgba(0,80,255,0.08)","rgba(0,200,0,0.08)","rgba(200,200,0,0.08)"],r=this.room.state.tanks.get(this.mySessionId),o=r&&r.team===e,a=document.getElementById("winner-label"),l=document.getElementById("winner-team"),d=document.getElementById("winner-stripe"),c=document.getElementById("winner-line-top"),f=document.getElementById("winner-line-bot"),h=document.getElementById("winner-tint");a.textContent=o?"VICTORY":"DEFEAT",a.style.color="#fff",l.textContent=`${vr[e]} Team Wins`,l.style.color="rgba(255,255,255,0.9)",d.style.background=t[e]||t[0],c.style.background=n[e]||n[0],f.style.background=n[e]||n[0],h.style.background=s[e]||s[0],this.winnerScreen.className="ready",this.winnerScreen.offsetWidth,this.winnerScreen.className="ready active",setTimeout(()=>{this.winnerScreen.className="exit",setTimeout(()=>{this.winnerScreen.className=""},800)},2800)}setupInput(){window.addEventListener("keydown",e=>{this.keys.add(e.key.toLowerCase())}),window.addEventListener("keyup",e=>{this.keys.delete(e.key.toLowerCase())}),window.addEventListener("mousemove",e=>{this.mouseX=e.clientX,this.mouseY=e.clientY}),window.addEventListener("mousedown",e=>{e.button===0&&(this.mouseDown=!0,this.network.sendShoot(!0))}),window.addEventListener("mouseup",e=>{e.button===0&&(this.mouseDown=!1,this.network.sendShoot(!1))}),window.addEventListener("contextmenu",e=>e.preventDefault())}sendInput(){let e=0,t=0;(this.keys.has("w")||this.keys.has("arrowup"))&&(t-=1),(this.keys.has("s")||this.keys.has("arrowdown"))&&(t+=1),(this.keys.has("a")||this.keys.has("arrowleft"))&&(e-=1),(this.keys.has("d")||this.keys.has("arrowright"))&&(e+=1);const n=-Math.PI/4,s=Math.cos(n),r=Math.sin(n),o=Math.round(e*s-t*r),a=Math.round(e*r+t*s);(o!==this.lastSentDirX||a!==this.lastSentDirY)&&(this.network.sendMove(o,a),this.lastSentDirX=o,this.lastSentDirY=a);const l=this.tanks.get(this.mySessionId);if(l){const d=new A.Vector2(this.mouseX/window.innerWidth*2-1,-(this.mouseY/window.innerHeight)*2+1);this.raycaster.setFromCamera(d,this.camera);const c=new A.Vector3;if(this.raycaster.ray.intersectPlane(this.groundPlane,c),c){const f=c.x-l.group.position.x,h=c.z-l.group.position.z;let p=Math.atan2(f,h)*(180/Math.PI);p=(p%360+360)%360,l.targetAngle=p;const m=performance.now();Math.abs(p-this.lastSentAngle)>1&&m-this.lastTargetSendTime>=100&&(this.network.sendTarget(p),this.lastSentAngle=p,this.lastTargetSendTime=m)}}}onResize(){const t=window.innerWidth/window.innerHeight;this.camera.left=-22*t/2,this.camera.right=22*t/2,this.camera.top=22/2,this.camera.bottom=-22/2,this.camera.updateProjectionMatrix(),this.renderer.setSize(window.innerWidth,window.innerHeight)}}const oc=new ic;oc.start();
|