@vgai/editor 0.2.0 → 0.4.0-canary.20260715.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/README.md +24 -0
- package/dist/assets/axe-C7YBtOuM.js +30 -0
- package/dist/assets/browserAll-DDtGGE48.js +1 -0
- package/dist/assets/create-runtime-DbTlBlKG.js +1 -0
- package/dist/assets/{game-BI111o5f.js → game-BE0r7DMI.js} +3 -3
- package/dist/assets/game-BdTHR2_X.js +1 -0
- package/dist/assets/{game-pt_1lQLv.js → game-C3iQGSqo.js} +1 -1
- package/dist/assets/game-CcHfYxjP.js +1 -0
- package/dist/assets/game-Cqzj_lpD.js +1 -0
- package/dist/assets/game-DSZdeCHu.js +1 -0
- package/dist/assets/game-Dch9sAPc.js +1 -0
- package/dist/assets/{game-xsOho_wg.js → game-SAFn90pA.js} +3 -3
- package/dist/assets/game-loop-DMIgSMV-.js +1 -0
- package/dist/assets/{game-source-CvidN7AB.js → game-source-Dk83w26t.js} +1 -1
- package/dist/assets/{index-Bp5cecD6.js → index-4idIsHHJ.js} +2 -2
- package/dist/assets/{index-DL7RcQ0n.js → index-C-LhOTBN.js} +1 -1
- package/dist/assets/{index-Cs8xwv3e.js → index-CDkxceqE.js} +1 -1
- package/dist/assets/index-CQEfi217.js +15412 -0
- package/dist/assets/index-Dvi-V0NE.css +1 -0
- package/dist/assets/ingest-siblings-s0P5I1Ub.js +1 -0
- package/dist/assets/mount-manifest-DXMOlF79.js +1 -0
- package/dist/assets/react-18-C9eHn8x1.js +1 -0
- package/dist/assets/webworkerAll-Fn0e-ouF.js +1 -0
- package/dist/assets/world-documents-GM0a9Kv7.js +1 -0
- package/dist/index.html +15 -13
- package/dist/ingest/racing-game/vgai.game.json +5 -4
- package/dist/ingest/simcity/vgai.game.json +5 -4
- package/dist/ingest/tanks/vgai.game.json +5 -4
- package/dist/project-scripts.bundle.js +3917 -0
- package/dist/scenes/untitled.vscn.json +2 -0
- package/dist-server/packaged.mjs +7697 -3435
- package/package.json +31 -4
- package/scripts/probe-reporter.ts +349 -0
- package/scripts/run-probe.ts +2260 -0
- package/server/asset-catalog-audit.ts +268 -0
- package/server/asset-catalog-v2.ts +146 -0
- package/server/asset-library-routes.ts +276 -58
- package/server/canonical-path.ts +1 -1
- package/server/dev.ts +148 -44
- package/server/editor-server.ts +888 -61
- package/server/editor-sse.ts +115 -4
- package/server/harness-chat-service.ts +796 -0
- package/server/local-asset-catalog.ts +157 -22
- package/server/packaged.ts +51 -21
- package/server/process-shutdown.ts +136 -0
- package/server/prod.ts +9 -6
- package/server/project-hmr-files.ts +41 -0
- package/server/project-operations.ts +343 -0
- package/server/project-optimize-deps-entries.ts +4 -4
- package/server/project-output-writer.ts +156 -0
- package/server/project-validation.ts +140 -0
- package/server/project-view.ts +8 -50
- package/server/server-utils.ts +75 -10
- package/server/session-registry.ts +12 -0
- package/src/EditorContext.tsx +107 -3
- package/src/action-registry.ts +115 -17
- package/src/adapter-resolver.ts +213 -478
- package/src/asset-events.ts +64 -1
- package/src/asset-preview.ts +906 -0
- package/src/asset-selection.ts +121 -0
- package/src/asset-workflow/asset-capabilities.ts +259 -0
- package/src/asset-workflow/asset-editor-errors.ts +46 -0
- package/src/asset-workflow/asset-import-pipeline.ts +176 -0
- package/src/asset-workflow/asset-library-query.ts +107 -0
- package/src/asset-workflow/asset-types.ts +192 -0
- package/src/asset-workflow/asset-workflow-quality.ts +65 -0
- package/src/asset-workflow/import-contract.ts +113 -0
- package/src/asset-workflow/model-conversion.ts +126 -0
- package/src/asset-workflow/model-inspection.ts +185 -0
- package/src/asset-workflow/project-asset-commands.ts +23 -0
- package/src/asset-workflow/project-asset-health.ts +153 -0
- package/src/asset-workflow/project-asset-operations.ts +119 -0
- package/src/asset-workflow/thumbnail-system.ts +172 -0
- package/src/authoring/active-systems.ts +15 -0
- package/src/authoring/boundary-authoring-adapter.ts +16 -5
- package/src/authoring/composite-authoring-adapter.ts +305 -124
- package/src/authoring/design-time-layers.ts +300 -117
- package/src/authoring/edit-mode-authoring.ts +278 -293
- package/src/authoring/embed-only-adapter.ts +4 -2
- package/src/authoring/first-party-hierarchy-menu.ts +7 -2
- package/src/authoring/first-party-inspector/AddSectionMenu.tsx +5 -12
- package/src/authoring/first-party-inspector/EnvironmentSection.tsx +53 -126
- package/src/authoring/first-party-inspector/HeaderSection.tsx +54 -65
- package/src/authoring/first-party-inspector/is-first-party-selection.ts +30 -11
- package/src/authoring/first-party-inspector/register.tsx +13 -2
- package/src/authoring/ingest-authoring-adapter.ts +142 -45
- package/src/authoring/mount-failure-report.ts +5 -5
- package/src/authoring/provenance.ts +41 -0
- package/src/authoring/react-dom-authoring-adapter.ts +92 -92
- package/src/authoring/react-inspector-section.tsx +489 -51
- package/src/authoring/react-world-authoring-adapter.ts +541 -306
- package/src/authoring/story-overlay.ts +1 -1
- package/src/authoring/story-types.ts +11 -0
- package/src/authoring/vgai-scene-authoring-adapter.ts +54 -25
- package/src/authoring/viewport-tool-context.ts +78 -0
- package/src/authoring/world-canvas-viewport-state.ts +35 -0
- package/src/authoring/world-hidden-viewport.ts +186 -0
- package/src/authoring/world-pan-state.ts +33 -17
- package/src/authoring/world-session-state.ts +1 -1
- package/src/authoring/world2d-authoring-adapter.ts +109 -52
- package/src/availability-tick.ts +56 -0
- package/src/browser-play-entry.ts +5 -5
- package/src/browser-project-scripts.ts +1 -0
- package/src/build-identity.ts +15 -0
- package/src/command-listener.ts +893 -19
- package/src/components/AlignToolbar.tsx +74 -63
- package/src/components/AppRoot.tsx +193 -26
- package/src/components/ApplicationMenus.tsx +272 -0
- package/src/components/AssetBrowser.tsx +1450 -293
- package/src/components/AssetEditorShell.tsx +141 -0
- package/src/components/AssetImportDetails.tsx +218 -0
- package/src/components/AssetLibraryPanel.tsx +14 -0
- package/src/components/CameraInfo.tsx +11 -20
- package/src/components/CenterDocuments.tsx +585 -0
- package/src/components/CommandPalette.tsx +75 -30
- package/src/components/ConsolePanel.css +55 -0
- package/src/components/ConsolePanel.tsx +57 -112
- package/src/components/DebugConsolePanel.tsx +461 -0
- package/src/components/DebuggerPanel.tsx +165 -0
- package/src/components/DefaultEditorLayout.tsx +167 -231
- package/src/components/GameHierarchy.tsx +873 -290
- package/src/components/GamePerformanceOverlay.tsx +46 -0
- package/src/components/HarnessChatPanel.tsx +2352 -0
- package/src/components/HistoryPanel.tsx +226 -0
- package/src/components/Inspector.tsx +153 -99
- package/src/components/InspectorToolSection.tsx +6 -4
- package/src/components/MountFailureBanner.tsx +31 -48
- package/src/components/NetworkSection.tsx +25 -14
- package/src/components/OnlineAssetBrowser.tsx +794 -343
- package/src/components/OverlayReportBanner.tsx +38 -64
- package/src/components/PerformancePanel.tsx +206 -0
- package/src/components/PlayBar.tsx +93 -263
- package/src/components/PrefabSaveDialog.tsx +55 -127
- package/src/components/ProjectHeader.css +60 -0
- package/src/components/ProjectHeader.tsx +170 -105
- package/src/components/ProjectScreen.tsx +246 -184
- package/src/components/ReactCanvasControls.tsx +185 -0
- package/src/components/ResolutionPicker.tsx +85 -0
- package/src/components/RootActivateDialog.tsx +39 -68
- package/src/components/SaveDialog.tsx +55 -127
- package/src/components/SaveStatus.tsx +11 -29
- package/src/components/StartupLoadingScreen.tsx +96 -0
- package/src/components/StateWatchPanel.tsx +302 -0
- package/src/components/StatsOverlay.tsx +12 -5
- package/src/components/StatusBar.tsx +64 -0
- package/src/components/ThemeManagerDialog.css +89 -0
- package/src/components/ThemeManagerDialog.tsx +371 -0
- package/src/components/ToolHost.tsx +26 -15
- package/src/components/Toolbar.tsx +117 -214
- package/src/components/VgaiVoxelLogo.tsx +89 -0
- package/src/components/ViewportOverlay.tsx +97 -172
- package/src/components/ViewportPanel.tsx +130 -31
- package/src/components/WorkspaceDock.tsx +891 -0
- package/src/components/WorldSelectionOverlay.tsx +51 -63
- package/src/components/WorldTextEditor.tsx +9 -5
- package/src/components/asset-documents.tsx +390 -0
- package/src/components/asset-editor-persistence.ts +44 -0
- package/src/components/asset-selection-section.tsx +338 -0
- package/src/components/asset-viewers/AudioViewer.tsx +73 -21
- package/src/components/asset-viewers/GenericJsonViewer.tsx +26 -11
- package/src/components/asset-viewers/ImageViewer.tsx +43 -11
- package/src/components/asset-viewers/InputMapViewer.tsx +512 -134
- package/src/components/asset-viewers/MaterialAssetEditor.tsx +540 -0
- package/src/components/asset-viewers/ModelViewer.tsx +805 -121
- package/src/components/asset-viewers/OnlineAssetDetail.tsx +177 -60
- package/src/components/asset-viewers/SourceAssetViewer.tsx +121 -0
- package/src/components/asset-workflow.css +506 -0
- package/src/components/build-documents.tsx +696 -0
- package/src/components/core-utilities.tsx +75 -0
- package/src/components/data-documents.tsx +364 -0
- package/src/components/{DataPanel.tsx → data-editor.tsx} +138 -288
- package/src/components/debugger-panel-state.ts +57 -0
- package/src/components/inspector-widgets/AlignmentGrid.tsx +8 -14
- package/src/components/inspector-widgets/BorderEditor.tsx +41 -33
- package/src/components/inspector-widgets/ColorPicker.tsx +39 -39
- package/src/components/inspector-widgets/FontPicker.tsx +13 -21
- package/src/components/inspector-widgets/GradientEditor.tsx +11 -19
- package/src/components/inspector-widgets/ScrubbableInput.tsx +6 -3
- package/src/components/inspector-widgets/ShadowEditor.tsx +20 -33
- package/src/components/inspector-widgets/shared.tsx +90 -49
- package/src/components/inspectors/AnimationSection.tsx +39 -40
- package/src/components/inspectors/AudioSection.tsx +28 -39
- package/src/components/inspectors/BoneAttachmentSection.tsx +19 -24
- package/src/components/inspectors/CameraSection.tsx +14 -23
- package/src/components/inspectors/ComponentsSection.tsx +39 -43
- package/src/components/inspectors/JointsSection.tsx +34 -43
- package/src/components/inspectors/LightSection.tsx +90 -35
- package/src/components/inspectors/MaterialSection.tsx +137 -174
- package/src/components/inspectors/MeshSection.tsx +9 -17
- package/src/components/inspectors/NavigationSection.tsx +8 -15
- package/src/components/inspectors/ParticleSection.tsx +91 -76
- package/src/components/inspectors/PhysicsSection.tsx +42 -46
- package/src/components/inspectors/PostProcessingSection.tsx +28 -36
- package/src/components/inspectors/RenderingSection.tsx +12 -20
- package/src/components/inspectors/ShadowSection.tsx +7 -8
- package/src/components/inspectors/SplineSection.tsx +31 -42
- package/src/components/inspectors/TransformSection.tsx +14 -22
- package/src/components/patterns/Dialog.tsx +95 -0
- package/src/components/patterns/Fields.tsx +44 -0
- package/src/components/patterns/List.tsx +25 -0
- package/src/components/patterns/StateSurface.tsx +40 -0
- package/src/components/patterns/Surfaces.tsx +115 -0
- package/src/components/patterns/Tabs.tsx +80 -0
- package/src/components/patterns/Toolbar.tsx +51 -0
- package/src/components/patterns/Tree.tsx +72 -0
- package/src/components/primitives/Button.tsx +46 -0
- package/src/components/primitives/ColorInput.tsx +11 -47
- package/src/components/primitives/EditorIcon.tsx +99 -0
- package/src/components/primitives/FormControls.tsx +71 -0
- package/src/components/primitives/JsonInput.tsx +15 -2
- package/src/components/primitives/Layout.tsx +100 -0
- package/src/components/primitives/Menu.tsx +105 -0
- package/src/components/primitives/NumberInput.tsx +8 -35
- package/src/components/primitives/Panel.tsx +49 -44
- package/src/components/primitives/SectionHeader.tsx +10 -28
- package/src/components/primitives/Text.tsx +46 -0
- package/src/components/primitives/Tooltip.tsx +20 -12
- package/src/components/primitives/Vec3Input.tsx +3 -0
- package/src/components/primitives/banner-tones.ts +33 -0
- package/src/components/primitives/editor-icons.ts +102 -0
- package/src/components/primitives/panel-header-styles.ts +30 -0
- package/src/components/project-operation-documents.tsx +226 -0
- package/src/components/status-contributions.tsx +175 -0
- package/src/components/story-documents-register.ts +15 -0
- package/src/components/story-documents.tsx +1185 -0
- package/src/components/tool-documents.tsx +110 -0
- package/src/components/workspace-dock.css +293 -0
- package/src/components/workspace-history.ts +33 -0
- package/src/components/world-documents.tsx +145 -0
- package/src/components/xstate-documents.tsx +209 -0
- package/src/composite-screenshot.ts +248 -0
- package/src/design-system/index.ts +70 -0
- package/src/design-system-stories/Foundation.stories.tsx +183 -0
- package/src/design-system-stories/Patterns.stories.tsx +251 -0
- package/src/design-system-stories/Workspace.stories.tsx +538 -0
- package/src/doctor/report.ts +57 -13
- package/src/editor-api.ts +295 -31
- package/src/editor-compatibility.ts +200 -0
- package/src/editor-console.ts +35 -17
- package/src/editor-hotkeys.ts +85 -33
- package/src/editor-store.ts +538 -233
- package/src/editor-viewport.ts +160 -34
- package/src/entity-factory.ts +14 -3
- package/src/gizmo-registry.ts +21 -5
- package/src/harness-chat-editor-context.ts +37 -0
- package/src/harness-chat-indicator.ts +68 -0
- package/src/harness-chat-layout.ts +53 -0
- package/src/harness-chat-lifecycle.ts +170 -0
- package/src/harness-chat-reconnect.ts +85 -0
- package/src/harness-chat-types.ts +409 -0
- package/src/hierarchy-drop.ts +50 -0
- package/src/hierarchy-expansion-state.ts +100 -0
- package/src/hierarchy-menu-registry.ts +1 -1
- package/src/hierarchy-projection.ts +76 -0
- package/src/history/editor-session.ts +21 -0
- package/src/history/history-commands.ts +147 -0
- package/src/history/history-service.ts +904 -0
- package/src/history/json-history-resource.ts +165 -0
- package/src/history/persistence-coordinator.ts +35 -0
- package/src/history/project-file-history.ts +266 -0
- package/src/history/project-root-history-backends.ts +53 -0
- package/src/history/resource-registry.ts +209 -0
- package/src/history/snapshot-store.ts +108 -0
- package/src/history/source-history-backend.ts +374 -0
- package/src/history/types.ts +100 -0
- package/src/hmr-registration-group.ts +67 -0
- package/src/hmr-stable-react-context.ts +23 -0
- package/src/hosted-example.ts +12 -2
- package/src/hotkeys.ts +89 -18
- package/src/ingest/discovery-react.ts +9 -10
- package/src/ingest/discovery.ts +4 -4
- package/src/ingest/discovery2d.ts +5 -5
- package/src/ingest/games/bloom-composer/vgai.game.json +3 -3
- package/src/ingest/games/embed-bundle/vgai.game.json +3 -3
- package/src/ingest/games/games-fps/vgai.game.json +3 -3
- package/src/ingest/games/iframe-reachable/vgai.game.json +3 -3
- package/src/ingest/games/interactive-cubes/vgai.game.json +3 -3
- package/src/ingest/games/mismatched-three/vgai.game.json +3 -3
- package/src/ingest/games/own-three-bundled/vgai.game.json +3 -3
- package/src/ingest/games/pointerlock-maze/vgai.game.json +7 -4
- package/src/ingest/games-2d/bubbo-bubbo/vgai.game.json +3 -3
- package/src/ingest/games-2d/bunnymark/vgai.game.json +3 -3
- package/src/ingest/games-2d/flappy/vgai.game.json +3 -3
- package/src/ingest/games-2d/flappy-pixi/vgai.game.json +3 -3
- package/src/ingest/games-2d/puzzling-potions/vgai.game.json +3 -3
- package/src/ingest/games-2d/tilemap-camera/vgai.game.json +3 -3
- package/src/ingest/games-react/react-rpg/vgai.game.json +3 -3
- package/src/ingest/types.ts +1 -1
- package/src/ingest-mode.ts +47 -52
- package/src/ingest-siblings.ts +23 -33
- package/src/initial-scene.ts +1 -2
- package/src/main.tsx +16 -8
- package/src/manifest-project.ts +10 -12
- package/src/model-thumbnail.ts +261 -26
- package/src/module-mode.ts +44 -50
- package/src/play-log-events.ts +26 -0
- package/src/play-mode.ts +495 -401
- package/src/play-scene-adoption.ts +23 -0
- package/src/playground/main.ts +68 -24
- package/src/playwright-shim.ts +473 -0
- package/src/project-manager.ts +90 -10
- package/src/project-operations.ts +112 -0
- package/src/project-story-discovery.ts +25 -0
- package/src/project-tool-discovery.ts +43 -0
- package/src/scene-serializer.ts +0 -6
- package/src/scene-sync.ts +7 -2
- package/src/script-loader.ts +3 -3
- package/src/skeleton-helper.ts +57 -0
- package/src/storage/seed.ts +68 -8
- package/src/stories/StoryPreviewMount.tsx +265 -0
- package/src/stories/action-stories.fixture.tsx +44 -0
- package/src/stories/button-stories.fixture.tsx +50 -0
- package/src/stories/compose-project-stories.ts +182 -0
- package/src/stories/loader-stories.fixture.tsx +53 -0
- package/src/stories/story-discovery.ts +130 -0
- package/src/stories/story-registry.ts +146 -0
- package/src/theme-css.ts +1049 -0
- package/src/theme-library.ts +238 -0
- package/src/theme-preference.ts +130 -0
- package/src/theme.ts +527 -0
- package/src/tool-loader.ts +80 -24
- package/src/ui-source/inspect.ts +27 -4
- package/src/ui-source/source-write-backend.ts +83 -22
- package/src/widgets/index.ts +9 -18
- package/src/workspace-aux-commands.ts +11 -0
- package/src/workspace-dock-controller.ts +64 -0
- package/src/workspace-document-ids.ts +5 -0
- package/src/workspace-document-registry.ts +367 -0
- package/src/workspace-state-persistence.ts +455 -0
- package/src/workspace-status-registry.ts +110 -0
- package/src/workspace-utility-commands.ts +49 -0
- package/src/workspace-utility-registry.ts +161 -0
- package/src/world-document-routing.ts +16 -0
- package/src/xstate-inspect/XStateMachineInspector.tsx +544 -0
- package/src/xstate-inspect/character-animation-machine.fixture.ts +74 -0
- package/src/xstate-inspect/use-live-actor-state.ts +39 -0
- package/src/xstate-inspect/xstate-graph.ts +265 -0
- package/src/xstate-inspect/xstate-layout.ts +76 -0
- package/src/z-index.ts +26 -0
- package/template/.claude/skills/editor/SKILL.md +129 -90
- package/template/AGENTS.md +1110 -0
- package/template/CLAUDE.md +1 -512
- package/template/IDIOMS.md +50 -0
- package/template/check-idioms.ts +706 -0
- package/template/manifest-entry-modules-plugin.ts +53 -0
- package/template/package.json +13 -4
- package/template/public/scenes/default.scn2d.json +6 -0
- package/template/public/scenes/default.vscn.json +7 -1
- package/template/public/scenes/untitled.vscn.json +10 -0
- package/template/scripts/playtest.ts +40 -0
- package/template/server/loopback.ts +75 -0
- package/template/server/rooms/arena-room.ts +69 -1
- package/template/server/rooms/game-room.ts +68 -1
- package/template/src/data/README.md +9 -4
- package/template/src/data/data-ref.ts +35 -0
- package/template/src/data/tuning.schema.ts +1 -1
- package/template/src/main.ts +41 -62
- package/template/src/manifest-entry-modules.d.ts +3 -0
- package/template/src/operations/README.md +88 -0
- package/template/src/runtime/pixi-adapter.ts +24 -0
- package/template/src/scripts/components/data-spinner.ts +43 -2
- package/template/src/scripts/components/spin-lap-math.ts +27 -0
- package/template/src/tools/README.md +5 -3
- package/template/src/tools/example.tool.tsx +13 -7
- package/template/src/ui/Button.stories.tsx +66 -0
- package/template/src/ui/RebindPanel.tsx +2 -6
- package/template/src/ui/game.tsx +17 -0
- package/template/tests/acceptance/example.spec.ts +64 -0
- package/template/tests/logic/example.test.ts +31 -0
- package/template/tests/logic/room.test.ts +100 -0
- package/template/tests/tsconfig.json +30 -0
- package/template/validate-manifest.ts +5 -5
- package/template/validate-scenes.ts +50 -18
- package/template/vgai.game.json +20 -13
- package/template/vite.config.ts +77 -16
- package/vite-plugin-ui-oid.ts +261 -17
- package/dist/assets/CCDIKSolver-Dz-ysxZF.js +0 -1
- package/dist/assets/SelectionBox-BXsv_6aH.js +0 -1
- package/dist/assets/browser-project-scripts-DOru4L1x.js +0 -2
- package/dist/assets/browserAll-CEkWYlFk.js +0 -1
- package/dist/assets/create-runtime-DYIWr3va.js +0 -1
- package/dist/assets/data-asset-Bb9sIM7i.js +0 -5
- package/dist/assets/game-8SDZPPgH.js +0 -1
- package/dist/assets/game-CevorxyV.js +0 -1
- package/dist/assets/game-Di7XlywD.js +0 -1
- package/dist/assets/game-DjnCaw8R.js +0 -1
- package/dist/assets/game-Q9A0aXSV.js +0 -1
- package/dist/assets/index-CPVV6pjw.js +0 -1
- package/dist/assets/index-CpOnYyeD.js +0 -213
- package/dist/assets/index-Dr8H_6Rl.js +0 -1
- package/dist/assets/index-_bCaipUk.js +0 -13650
- package/dist/assets/ingest-siblings-Dz8eEqrV.js +0 -1
- package/dist/assets/mount-manifest-Bhk0ohsl.js +0 -1
- package/dist/assets/scene-query-BivAHhJu.js +0 -1
- package/dist/assets/webworkerAll-BLrH0F6F.js +0 -1
- package/dist/assets/xstate-animation-binding-1NGLmw6y.js +0 -1
- package/dist/assets/xstate.esm-BgUD33nl.js +0 -3
- package/src/authoring/scene-ui-layer.ts +0 -485
- package/src/authoring/ui-authoring-adapter.ts +0 -325
- package/src/authoring/ui-hierarchy-menu.ts +0 -40
- package/src/authoring/ui-inspector-sections.tsx +0 -156
- package/src/authoring/undo-timeline.ts +0 -145
- package/src/components/BottomPanel.tsx +0 -326
- package/src/components/BuildPanel.tsx +0 -455
- package/src/components/FolderTree.tsx +0 -179
- package/src/components/RightPanel.tsx +0 -166
- package/src/components/WorldContextMenu.tsx +0 -257
- package/src/components/asset-viewers/AssetViewer.tsx +0 -38
- package/src/ingest/games-react/react-rpg/src/ui/game-state.tsx +0 -129
- package/src/scene-ui-mode/active-scene-ui.ts +0 -58
- package/src/scene-ui-mode/scene-ui-palette-panel.tsx +0 -152
- package/src/scene-ui-mode/scene-ui-timeline-tab.tsx +0 -29
- package/src/scene-ui-mode/ui-prefab-dialog-host.tsx +0 -74
- package/src/scene-ui-mode/ui-prefab-hierarchy-menu.ts +0 -49
- package/src/scene-ui-mode/ui-prefab-io.ts +0 -76
- package/src/ui-editor/inspector.tsx +0 -563
- package/src/ui-editor/node-ops.ts +0 -266
- package/src/ui-editor/overlay.tsx +0 -380
- package/src/ui-editor/palette.tsx +0 -114
- package/src/ui-editor/react-store.ts +0 -78
- package/src/ui-editor/timeline-panel.tsx +0 -443
- package/src/ui-editor/ui-edit-store.ts +0 -552
- package/src/ui-editor/ui-prefab.ts +0 -95
- package/template/project.json +0 -9
- package/template/src/scripts/main.ts +0 -94
- package/template/src/ui/DefaultHud.tsx +0 -40
- package/template/src/ui/game-state.tsx +0 -37
- package/template/src/ui/mount-default-hud.tsx +0 -19
- package/template/src/ui/mount-ui.ts +0 -15
- package/vite-plugin-react-world-provider.ts +0 -81
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{q as f,t as b,u as S,v as A,w as D,I as w,x as h,y as m,z as y,A as I,B as R,W as x,C as W,D as O,E as k,F as C,G as g,H as $,R as G,J as M,K as z}from"./index-_bCaipUk.js";class F extends g.Component{constructor(){super(...arguments),this.state={crashed:!1}}static getDerivedStateFromError(){return{crashed:!0}}componentDidCatch(t){this.props.onCaught(t)}render(){return this.state.crashed?null:this.props.children}}function v(e,t,s){e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.zIndex=String(t.zOrder??0),e.style.pointerEvents=s}async function P(e,t,s,o){const r=await O(e,s),n=document.createElement("div");v(n,e,"none"),t.appendChild(n),f.log(`react sibling "${e.id}": no native Game beside an ingest world — useGameState unavailable`,"ingest");const a=k.createRoot(n);let d=null;if(C.flushSync(()=>{a.render(g.createElement(F,{onCaught:i=>{d=i},children:g.createElement(r)}))}),d!==null)throw a.unmount(),n.remove(),d instanceof Error?d:new Error(String(d));let u;return o&&(u=$(n).nodes.size>0?new G(n,o,{}):new M(n,o,{overlay:await y(e.id),persist:p=>m(e.id,p),destination:h(e.id)})),{worldId:e.id,...u?{authoring:u}:{},dispose(){u&&z(u),a.unmount(),n.remove()}}}async function T(e,t,s,o,r){const n=document.createElement("div");v(n,t,"auto"),s.appendChild(n);try{const a=s.clientWidth||800,d=s.clientHeight||600,{session:u}=await A(e,t,o,n,a,d),i=u.game.worlds[0],p=i.mounted.authoring;let l;if(r)if(p)l=D(p,r);else if(i.kind==="threejs")l=new w(r,i.threeRoot(),{overlay:await y(i.id),persist:c=>m(i.id,c),destination:h(i.id)});else if(i.kind==="pixijs"){const c=I(i.physics2d??R());l=new x(i.pixiRoot(),c,r,{overlay:await y(i.id),persist:E=>m(i.id,E),destination:h(i.id)})}else l=W(r,`${t.id} (no authoring surface)`);return{worldId:t.id,...l?{authoring:l}:{},setPaused(c){c?u.pause():u.resume()},dispose(){u.stop(),n.remove()}}}catch(a){throw n.remove(),a}}function B(e){throw new Error(`sibling world "${e.id}" (kind: ${e.kind}, adapter identity: "${e.adapter.identity}") has no known composite-sibling mount path — every currently-resolvable identity (default-three/default-pixi/default-react/module) is routed above; this is reached only for a genuinely unroutable shape (docs/WAVE5-MULTIWORLD-INGEST-DESIGN.md D-V7, updated by docs/WAVE6-DOCTOR-DESIGN.md D-B3).`)}async function L(e,t,s,o,r){if(t.adapter.type==="module"||t.adapter.identity==="default-three"||t.adapter.identity==="default-pixi")return T(e,t,s,o,r);if(t.adapter.identity==="default-react")return P(t,s,o,r);B(t)}async function U(e,t,s,o,r){const n=[];for(const a of e.worlds)if(a.id!==t)try{n.push(await L(e,a,s,o,r))}catch(d){f.error(`Composite sibling "${a.id}" failed to mount: ${d}`,"ingest"),b({worldId:a.id,kind:a.kind,identity:a.adapter.identity,message:S(d)})}return n}export{U as mountIngestSiblings};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{l as a,a as s,f as o,V as d}from"./index-_bCaipUk.js";import{createGameRuntime as u}from"./create-runtime-DYIWr3va.js";function p(e){if(typeof e!="object"||e===null)return!1;const t=e.worlds;return!Array.isArray(t)||t.length===0?!1:t.every(r=>{if(typeof r!="object"||r===null)return!1;const n=r.adapter;if(typeof n!="object"||n===null)return!1;const i=n.type;return i==="default"||i==="module"||i==="ingest"})}function c(e){return p(e)?e:a(e)}function f(e,t){if(t?.adapter)return t.adapter;if(e.adapter.type==="module")throw new Error(`mountManifestWorlds: world "${e.id}" (threejs) declares a { module } adapter ("${e.adapter.module}") — mountManifestWorlds never imports an arbitrary module path itself (no \`/@fs/\`, no dev server). Import the module yourself and supply the constructed adapter via entries["${e.id}"] = { kind: 'threejs', adapter }.`);if(e.adapter.type==="ingest")throw new Error(`mountManifestWorlds: world "${e.id}" (threejs) declares an { ingest } adapter — ingest worlds require the editor's dev-server-backed mount machinery (an EditorStore plus iframe/DOM capture, see adapter-resolver.ts's resolveIngestThreeAdapter) and are not supported by mountManifestWorlds (docs/WAVE3-ADAPTER-PLUMBING-DESIGN.md D-Z7 — no porting aids, no hosted ingest routes).`);if(e.entry!==void 0){if(!t?.setup)throw new Error(`mountManifestWorlds: world "${e.id}" (threejs) declares \`entry\` "${e.entry}" — supply entries["${e.id}"] = { kind: 'threejs', setup } (the entry module's exported \`setup\` function) or { kind: 'threejs', adapter } for full control. Got ${t===void 0?"no entry at all":"an entry with neither `setup` nor `adapter`"}.`);return o(e.id,t.setup)}if(e.scene!==void 0)return new d({id:e.id,scenePath:e.scene,componentRegistry:t?.componentRegistry});throw new Error(`mountManifestWorlds: world "${e.id}" is default-three with neither \`scene\` nor \`entry\` — this should have been rejected by manifest validation.`)}function l(e,t){if(t?.adapter)return t.adapter;throw new Error(`mountManifestWorlds: world "${e.id}" (pixijs) has no entries["${e.id}"] — a pixijs world always needs a caller-supplied, already-constructed adapter (entries["${e.id}"] = { kind: 'pixijs', adapter }, e.g. \`new PixiSceneGameAdapter(...)\` built from your own already-imported '@engine/world2d') — mountManifestWorlds never value-imports pixi.js (mirrors create-runtime.ts's own pixi-free-core discipline).`)}function m(e,t){if(t?.adapter)return t.adapter;throw new Error(`mountManifestWorlds: world "${e.id}" (react) has no entries["${e.id}"] — a react world always needs a caller-supplied, already-constructed \`ReactWorldAdapter\` (entries["${e.id}"] = { kind: 'react', adapter }, mounting via your own already-imported react-dom \`createRoot\` + your own \`<GameProvider>\`) — mountManifestWorlds never value-imports react/react-dom (mirrors create-runtime.ts's own react-free-core discipline; see docs/REACT-STATE-BRIDGE.md §2-3).`)}function h(e,t){if(t!==void 0&&t.kind!==e.kind)throw new Error(`mountManifestWorlds: entries["${e.id}"] declares kind "${t.kind}" but the manifest's world "${e.id}" is kind "${e.kind}" — fix the entries key (or the manifest) so the two agree.`);const r={id:e.id,zOrder:e.zOrder,pausable:e.pausable,loop:e.loop};return e.kind==="threejs"?{...r,kind:"threejs",adapter:f(e,t)}:e.kind==="pixijs"?{...r,kind:"pixijs",adapter:l(e,t)}:e.kind==="react"?{...r,kind:"react",adapter:m(e,t)}:s(e.kind,"mountManifestWorlds")}async function k(e){const t=c(e.manifest);if(t.worlds.length===0)throw new Error("mountManifestWorlds: manifest declares no worlds — nothing to mount.");const r=e.entries??{},n=t.worlds.map(i=>h(i,r[i.id]));return u({container:e.container,worlds:n,width:e.width??t.resolution?.width,height:e.height??t.resolution?.height,headless:e.headless})}export{k as mountManifestWorlds,c as resolveManifest};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ao as s}from"./index-_bCaipUk.js";function c(r){const e=s(r,"tags");if(Array.isArray(e))return e;const t=s(r,"entity")?.tags;return Array.isArray(t)?t:[]}function o(r){const e=s(r,"components");if(Array.isArray(e))return e;if(e&&typeof e=="object")return Object.keys(e);const t=s(r,"entity")?.components;return t&&typeof t=="object"?Object.keys(t):[]}function i(r,e){const t=[];return r.traverse(n=>{c(n).includes(e)&&t.push(n)}),t}function u(r,e){const t=[];return r.traverse(n=>{n.name===e&&t.push(n)}),t}function f(r,e){const t=[];return r.traverse(n=>{o(n).includes(e)&&t.push(n)}),t}export{f as queryByComponent,u as queryByName,i as queryByTag};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ax as a,iL as i,iM as s,iN as e}from"./index-_bCaipUk.js";a.add(i,s);a.add(e);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{aD as V,aE as v,aF as w,aG as j,aH as y,aI as q,aJ as T,aK as B,aL as K,aM as z}from"./index-_bCaipUk.js";function C(e,s){switch(e.type){case"1D":return G(e,s);case"2D":return J(e,s);case"direct":return U(e);default:return e.children.map(n=>({clip:n.clip,weight:1/e.children.length}))}}function G(e,s){const n=Number(s.get(e.parameter)??0),a=[...e.children].sort((h,f)=>h.threshold-f.threshold),o=a.map(h=>({clip:h.clip,weight:0}));if(a.length===0)return o;if(a.length===1||n<=a[0].threshold)return o[0].weight=1,o;if(n>=a[a.length-1].threshold)return o[o.length-1].weight=1,o;for(let h=0;h<a.length-1;h++){const f=a[h],p=a[h+1];if(n>=f.threshold&&n<=p.threshold){const m=p.threshold-f.threshold,g=m>0?(n-f.threshold)/m:0;return o[h].weight=1-g,o[h+1].weight=g,o}}return o}function J(e,s){const n=Number(s.get(e.parameter)??0),a=Number(s.get(e.parameterY??"")??0),o=e.children,h=o.map(m=>({clip:m.clip,weight:0}));let f=0;const p=[];for(const m of o){const g=n-m.threshold,d=a-(m.thresholdY??0),b=Math.sqrt(g*g+d*d),S=b<.001?1e3:1/b;p.push(S),f+=S}if(f>0)for(let m=0;m<h.length;m++)h[m].weight=p[m]/f;return h}function U(e){const s=e.children.map(a=>({clip:a.clip,weight:a.weight??0})),n=s.reduce((a,o)=>a+o.weight,0);if(n>0)for(const a of s)a.weight/=n;return s}const W=v({clip:y().min(1).describe("Animation clip name this child plays"),threshold:w().describe("1D/2D blend position on the primary parameter axis"),thresholdY:w().optional().describe("2D blend position on the secondary parameter axis (2D blend trees only)"),weight:w().min(0).optional().describe('Explicit weight for "direct" blend trees (ignored by 1D/2D)')}).strict(),Q=v({type:B("1D").describe("Interpolates linearly between sorted children by threshold"),parameter:y().min(1).describe("Context/selector value driving the blend"),children:T(W).min(2,"1D blend tree needs at least 2 children to interpolate between")}).strict(),Z=v({type:B("2D").describe("Inverse-distance-weights children by (parameter, parameterY) position"),parameter:y().min(1).describe("Primary axis context/selector value"),parameterY:y().min(1).describe("Secondary axis context/selector value"),children:T(W.extend({thresholdY:w()})).min(1,"2D blend tree needs at least 1 child")}).strict(),_=v({type:B("direct").describe("Each child has an explicit weight, normalized to sum to 1"),parameter:y().default(""),children:T(W.extend({weight:w().min(0)})).min(1,"direct blend tree needs at least 1 child")}).strict(),ee=q("type",[Q,Z,_]),L=v({duration:w().min(0).default(0).describe("Seconds to blend from the previously active clip into this state on entry, applied via native `AnimationAction.crossFadeTo`/`fadeIn` (E2). 0 = instant activation, no fade."),warp:j().default(!1).describe("Passed through to AnimationAction.crossFadeTo's `warp` param — linearly warps timeScale across the two clips during the blend so differing clip lengths line up. Default false.")}).strict().describe("Blend-in/out/crossfade timing for entering this state"),te=v({clip:y().min(1).describe("Single clip to play while this XState state is active"),loop:j().default(!0).describe("Loop the clip (THREE.LoopRepeat) vs play once (THREE.LoopOnce, clamped on last frame)"),speed:w().positive().default(1).describe("Playback speed multiplier (AnimationAction.timeScale)"),crossfade:L.optional()}).strict(),ie=v({blendTree:ee.describe("Multiple clips blended by a live context/selector-driven parameter"),crossfade:L.optional()}).strict(),ne=V([te,ie]);function ae(e){return"clip"in e}function A(e){return"blendTree"in e}class se extends Error{constructor(s,n,a){super(s),this.stateId=n,this.issues=a,this.name="AnimationMetaValidationError"}}function oe(e,s){const n=ne.safeParse(s);if(!n.success){const a=n.error.issues.map(o=>`${o.path.length?o.path.join("."):"(root)"}: ${o.message}`).join("; ");throw new se(`[xstate-animation] invalid meta.animation for state "${e}": ${a}`,e,n.error.issues)}return n.data}function re(e){const s=[],n=a=>{a.meta&&"animation"in a.meta&&a.meta.animation!==void 0&&s.push({stateId:a.id,meta:oe(a.id,a.meta.animation)});for(const o of Object.values(a.states??{}))n(o)};return n(e),s}function ce(e){return ae(e)?[e.clip]:e.blendTree.children.map(s=>s.clip)}class I extends Error{constructor(s,n){super(s),this.stateId=n,this.name="AnimationBindingError"}}function le(e){return e.reduce((s,n)=>n.weight>s.weight?n:s,e[0])}function de(e){return A(e)?[]:[{clip:e.clip,weight:1}]}function pe(e,s,n,a={}){const o=e.logic.root,h=re(o),f=new Map(h.map(t=>[t.stateId,t.meta]));for(const t of h)for(const i of ce(t.meta))if(!n.has(i))throw new I(`[bindXStateAnimation] state "${t.stateId}" references clip "${i}", which is not present in the supplied clips map. Known clips: ${[...n.keys()].join(", ")||"(none)"}`,t.stateId);const p=new Map;function m(t,i,c){let r=p.get(t);if(!r){const l=n.get(t);if(!l)throw new I(`[bindXStateAnimation] clip "${t}" not found`);r=s.clipAction(l),r.setEffectiveWeight(0),r.play(),p.set(t,r)}return r.setLoop(i?K:z,1/0),r.clampWhenFinished=!i,r.timeScale=c,r}function g(t){const i=a.selectParameters?a.selectParameters(t):t;return new Map(Object.entries(i??{}))}let d=null,b=!1;function S(t,i,c){for(const{clip:r}of t){if(r===i)continue;const l=p.get(r);l&&(c>0?l.fadeOut(c):l.setEffectiveWeight(0))}}function N(t,i,c,r){for(const{clip:u}of t)m(u,c,r);const l=p.get(i);l.reset(),l.setEffectiveWeight(1);for(const{clip:u}of t){if(u===i)continue;const D=p.get(u);D.reset(),D.setEffectiveWeight(0)}return l}function P(t,i,c,r){if(!i){c>0?t.fadeIn(c):t.setEffectiveWeight(1);return}S(i.natural,i.dominantClip,c);const l=p.get(i.dominantClip);if(l&&c>0){l.crossFadeTo(t,c,r);return}l?.setEffectiveWeight(0),t.setEffectiveWeight(1)}function O(t,i,c){const r=A(i),l=r?C(i.blendTree,g(c)):de(i),u=le(l),D=r?!0:i.loop,X=r?1:i.speed,k=N(l,u.clip,D,X),M=i.crossfade?.duration??0,H=i.crossfade?.warp??!1;P(k,d,M,H),d={stateId:t,meta:i,natural:l,dominantClip:u.clip,crossfadeRemaining:M},r&&M<=0&&E(d,c)}function E(t,i){if(!A(t.meta))return;const c=g(i),r=C(t.meta.blendTree,c);t.natural=r;for(const{clip:l,weight:u}of r)p.get(l)?.setEffectiveWeight(u)}const R=e.getSnapshot(),x=$(R,f);x&&O(x,f.get(x),R.context);const Y=e.subscribe(t=>{if(b)return;const i=$(t,f),c=i?f.get(i):void 0;c&&i&&i!==d?.stateId&&O(i,c,t.context)});function F(t){b||(d&&d.crossfadeRemaining>0?(d.crossfadeRemaining=Math.max(0,d.crossfadeRemaining-t),d.crossfadeRemaining<=0&&A(d.meta)&&E(d,e.getSnapshot().context)):d&&A(d.meta)&&E(d,e.getSnapshot().context),s.update(t))}return{tick:F,actor:e,dispose(){if(!b){b=!0,Y.unsubscribe();for(const[t,i]of p)i.stop(),s.uncacheAction(i.getClip(),i.getRoot()),p.delete(t);d=null}}}}function $(e,s){const n=Object.keys(e.getMeta()).filter(a=>s.has(a));if(n.length>1)throw new I(`[bindXStateAnimation] more than one animated state is simultaneously active (${n.join(", ")}) — parallel-region animation composition is not supported by this binding; exactly one active meta.animation state is required.`);return n[0]}export{I as AnimationBindingError,pe as bindXStateAnimation};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
function te(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function ee(){const n=te();if(n.__xstate__)return n.__xstate__}const ne=n=>{if(typeof window>"u")return;const t=ee();t&&t.register(n)};class vt{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current){this._last.next=e,this._last=e;return}this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Ot=".",se="",Mt="",ie="#",re="*",Rt="xstate.init",oe="xstate.error",w="xstate.stop";function ce(n,t){return{type:`xstate.after.${n}.${t}`}}function et(n,t){return{type:`xstate.done.state.${n}`,output:t}}function ae(n,t){return{type:`xstate.done.actor.${n}`,output:t,actorId:n}}function jt(n,t){return{type:`xstate.error.actor.${n}`,error:t,actorId:n}}function ot(n){return{type:Rt,input:n}}function v(n){setTimeout(()=>{throw n})}const ue=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Ct(n,t){const e=_t(n),s=_t(t);return typeof s=="string"?typeof e=="string"?s===e:!1:typeof e=="string"?e in s:Object.keys(e).every(i=>i in s?Ct(e[i],s[i]):!1)}function ct(n){if(Lt(n))return n;const t=[];let e="";for(let s=0;s<n.length;s++){switch(n.charCodeAt(s)){case 92:e+=n[s+1],s++;continue;case 46:t.push(e),e="";continue}e+=n[s]}return t.push(e),t}function _t(n){if(He(n))return n.value;if(typeof n!="string")return n;const t=ct(n);return fe(t)}function fe(n){if(n.length===1)return n[0];const t={};let e=t;for(let s=0;s<n.length-1;s++)if(s===n.length-2)e[n[s]]=n[s+1];else{const i=e;e={},i[n[s]]=e}return t}function St(n,t){const e={},s=Object.keys(n);for(let i=0;i<s.length;i++){const r=s[i];e[r]=t(n[r],r,n,i)}return e}function Dt(n){return Lt(n)?n:[n]}function _(n){return n===void 0?[]:Dt(n)}function nt(n,t,e,s){return typeof n=="function"?n({context:t,event:e,self:s}):n}function Lt(n){return Array.isArray(n)}function de(n){return n.type.startsWith("xstate.error.actor")}function O(n){return Dt(n).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Bt(n){if(!(n===void 0||n===se))return _(n)}function X(n,t,e){const s=typeof n=="object",i=s?n:void 0;return{next:(s?n.next:n)?.bind(i),error:(s?n.error:t)?.bind(i),complete:(s?n.complete:e)?.bind(i)}}function bt(n,t){return`${t}.${n}`}function at(n,t){const e=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!e)return n.implementations.actors[t];const[,s,i]=e,o=n.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[s]:o).src}function wn(n){return[...new Set([...n._nodes.flatMap(t=>t.ownEvents)])]}function Pt(n,t){if(t===n||t===re)return!0;if(!t.endsWith(".*"))return!1;const e=t.split("."),s=n.split(".");for(let i=0;i<e.length;i++){const r=e[i],o=s[i];if(r==="*")return i===e.length-1;if(r!==o)return!1}return!0}function xt(n,t){return`${n.sessionId}.${t}`}let he=0;function Jt(n,t){const e=new Map,s=new Map,i=new WeakMap,r=new Set,o={},{clock:c,logger:u}=t,h={schedule:(a,d,l,y,g=Math.random().toString(36).slice(2))=>{const A={source:a,target:d,event:l,delay:y,id:g,startedAt:Date.now()},k=xt(a,g);f._snapshot._scheduledEvents[k]=A;const Nt=c.setTimeout(()=>{delete o[k],delete f._snapshot._scheduledEvents[k],f._relay(a,d,l)},y);o[k]=Nt},cancel:(a,d)=>{const l=xt(a,d),y=o[l];delete o[l],delete f._snapshot._scheduledEvents[l],y!==void 0&&c.clearTimeout(y)},cancelAll:a=>{for(const d in f._snapshot._scheduledEvents){const l=f._snapshot._scheduledEvents[d];l.source===a&&h.cancel(a,l.id)}}},p=a=>{if(!r.size)return;const d={...a,rootId:n.sessionId};r.forEach(l=>l.next?.(d))},f={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${he++}`,_register:(a,d)=>(e.set(a,d),a),_unregister:a=>{e.delete(a.sessionId);const d=i.get(a);d!==void 0&&(s.delete(d),i.delete(a))},get:a=>s.get(a),getAll:()=>Object.fromEntries(s.entries()),_set:(a,d)=>{const l=s.get(a);if(l&&l!==d)throw new Error(`Actor with system ID '${a}' already exists.`);s.set(a,d),i.set(d,a)},inspect:a=>{const d=X(a);return r.add(d),{unsubscribe(){r.delete(d)}}},_sendInspectionEvent:p,_relay:(a,d,l)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:a,actorRef:d,event:l}),d._send(l)},scheduler:h,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const a=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const d in a){const{source:l,target:y,event:g,delay:A,id:k}=a[d];h.schedule(l,y,g,A,k)}},_clock:c,_logger:u};return f}let Q=!1;const ut=1;let m=(function(n){return n[n.NotStarted=0]="NotStarted",n[n.Running=1]="Running",n[n.Stopped=2]="Stopped",n})({});const le={clock:{setTimeout:(n,t)=>setTimeout(n,t),clearTimeout:n=>clearTimeout(n)},logger:console.log.bind(console),devTools:!1};class pe{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new vt(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=m.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const s={...le,...e},{clock:i,logger:r,parent:o,syncSnapshot:c,id:u,systemId:h,inspect:p}=s;this.system=o?o.system:Jt(this,{clock:i,logger:r}),p&&!o&&this.system.inspect(X(p)),this.sessionId=this.system._bookId(),this.id=u??this.sessionId,this.logger=e?.logger??this.system._logger,this.clock=e?.clock??this.system._clock,this._parent=o,this._syncSnapshot=c,this.options=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:f=>{this._deferred.push(f)},system:this.system,stopChild:f=>{if(f._parent!==this)throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);f._stop()},emit:f=>{const a=this.eventListeners.get(f.type),d=this.eventListeners.get("*");if(!a&&!d)return;const l=[...a?a.values():[],...d?d.values():[]];for(const y of l)try{y(f)}catch(g){v(g)}},actionExecutor:f=>{const a=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:f.type,params:f.params}}),!f.exec)return;const d=Q;try{Q=!0,f.exec(f.info,f.params)}finally{Q=d}};this._processingStatus===m.Running?a():this._deferred.push(a)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),h&&(this.systemId=h,this.system._set(h,this)),this._initState(e?.snapshot??e?.state),h&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(e){this._snapshot={status:"error",output:void 0,error:e}}}update(t,e){this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}catch(i){this._deferred.length=0,this._snapshot={...t,status:"error",error:i}}switch(this._snapshot.status){case"active":for(const i of this.observers)try{i.next?.(t)}catch(r){v(r)}break;case"done":for(const i of this.observers)try{i.next?.(t)}catch(r){v(r)}this._stopProcedure(),this._complete(),this._doneEvent=ae(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const i=X(t,e,s);if(this._processingStatus!==m.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(r){v(r)}break;case"error":{const r=this._snapshot.error;if(!i.error)v(r);else try{i.error(r)}catch(o){v(o)}break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const i=e.bind(void 0);return s.add(i),{unsubscribe:()=>{s.delete(i)}}}select(t,e=Object.is){return{subscribe:s=>{const i=X(s),r=this.getSnapshot();let o=t(r);return this.subscribe(c=>{const u=t(c);e(o,u)||(o=u,i.next?.(u))})},get:()=>t(this.getSnapshot())}}start(){if(this._processingStatus===m.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=m.Running;const t=ot(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(i){s={err:i}}if(s){const{err:i}=s;this._snapshot={...this._snapshot,status:"error",error:i},this._error(i);return}this.update(e,t),t.type===w&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===m.Stopped?this:(this.mailbox.clear(),this._processingStatus===m.NotStarted?(this._processingStatus=m.Stopped,this):(this.mailbox.enqueue({type:w}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(e){v(e)}this.observers.clear(),this.eventListeners.clear()}_reportError(t){if(!this.observers.size){this._parent||v(t),this.eventListeners.clear();return}let e=!1;for(const s of this.observers){const i=s.error;e||=!i;try{i?.(t)}catch(r){v(r)}}this.observers.clear(),this.eventListeners.clear(),e&&v(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,jt(this.id,t))}_stopProcedure(){return this._processingStatus!==m.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new vt(this._process.bind(this)),this._processingStatus=m.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==m.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:ne)(this)}toJSON(){return{xstate$$type:ut,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[ue](){return this}getSnapshot(){return this._snapshot}}function E(n,...[t]){return new pe(n,t)}const En=E;function ye(n,t,e,s,{sendId:i}){const r=typeof i=="function"?i(e,s):i;return[t,{sendId:r},void 0]}function ge(n,t){n.defer(()=>{n.system.scheduler.cancel(n.self,t.sendId)})}function ft(n){function t(e,s){}return t.type="xstate.cancel",t.sendId=n,t.resolve=ye,t.execute=ge,t}function me(n,t,e,s,{id:i,systemId:r,src:o,input:c,syncSnapshot:u}){const h=typeof o=="string"?at(t.machine,o):o,p=typeof i=="function"?i(e):i;let f,a;return h&&(a=typeof c=="function"?c({context:t.context,event:e.event,self:n.self}):c,f=E(h,{id:p,src:o,parent:n.self,syncSnapshot:u,systemId:r,input:a})),[T(t,{children:{...t.children,[p]:f}}),{id:i,systemId:r,actorRef:f,src:o,input:a},void 0]}function ve(n,{actorRef:t}){t&&n.defer(()=>{t._processingStatus!==m.Stopped&&t.start()})}function dt(...[n,{id:t,systemId:e,input:s,syncSnapshot:i=!1}={}]){function r(o,c){}return r.type="xstate.spawnChild",r.id=t,r.systemId=e,r.src=n,r.input=s,r.syncSnapshot=i,r.resolve=me,r.execute=ve,r}function _e(n,t,e,s,{actorRef:i}){const r=typeof i=="function"?i(e,s):i,o=typeof r=="string"?t.children[r]:r;let c=t.children;return o&&(c={...c},delete c[o.id]),[T(t,{children:c}),o,void 0]}function zt(n,t){const e=t.getSnapshot();if(e&&"children"in e)for(const s of Object.values(e.children))zt(n,s);n.system._unregister(t)}function Se(n,t){if(t){if(zt(n,t),t._processingStatus!==m.Running){n.stopChild(t);return}n.defer(()=>{n.stopChild(t)})}}function z(n){function t(e,s){}return t.type="xstate.stopChild",t.actorRef=n,t.resolve=_e,t.execute=Se,t}const Tn=z;function be(n,t,{stateValue:e}){if(typeof e=="string"&&W(e)){const s=n.machine.getStateNodeById(e);return n._nodes.some(i=>i===s)}return n.matches(e)}function In(n){function t(){return!1}return t.check=be,t.stateValue=n,t}function xe(n,{context:t,event:e},{guards:s}){return!I(s[0],t,e,n)}function An(n){function t(e,s){return!1}return t.check=xe,t.guards=[n],t}function we(n,{context:t,event:e},{guards:s}){return s.every(i=>I(i,t,e,n))}function Ee(n){function t(e,s){return!1}return t.check=we,t.guards=n,t}function Te(n,{context:t,event:e},{guards:s}){return s.some(i=>I(i,t,e,n))}function kn(n){function t(e,s){return!1}return t.check=Te,t.guards=n,t}function I(n,t,e,s){const{machine:i}=s,r=typeof n=="function",o=r?n:i.implementations.guards[typeof n=="string"?n:n.type];if(!r&&!o)throw new Error(`Guard '${typeof n=="string"?n:n.type}' is not implemented.'.`);if(typeof o!="function")return I(o,t,e,s);const c={context:t,event:e},u=r||typeof n=="string"?void 0:"params"in n?typeof n.params=="function"?n.params({context:t,event:e}):n.params:void 0;return"check"in o?o.check(s,c,o):o(c,u)}function q(n){return n.type==="atomic"||n.type==="final"}function R(n){return Object.values(n.states).filter(t=>t.type!=="history")}function D(n,t){const e=[];if(t===n)return e;let s=n.parent;for(;s&&s!==t;)e.push(s),s=s.parent;return e}function U(n){const t=new Set(n),e=Wt(t);for(const s of t)if(s.type==="compound"&&(!e.get(s)||!e.get(s).length))wt(s).forEach(i=>t.add(i));else if(s.type==="parallel"){for(const i of R(s))if(i.type!=="history"&&!t.has(i)){const r=wt(i);for(const o of r)t.add(o)}}for(const s of t){let i=s.parent;for(;i;)t.add(i),i=i.parent}return t}function qt(n,t){const e=t.get(n);if(!e)return{};if(n.type==="compound"){const i=e[0];if(i){if(q(i))return i.key}else return{}}const s={};for(const i of e)s[i.key]=qt(i,t);return s}function Wt(n){const t=new Map;for(const e of n)t.has(e)||t.set(e,[]),e.parent&&(t.has(e.parent)||t.set(e.parent,[]),t.get(e.parent).push(e));return t}function Xt(n,t){const e=U(t);return qt(n,Wt(e))}function ht(n,t){return t.type==="compound"?R(t).some(e=>e.type==="final"&&n.has(e)):t.type==="parallel"?R(t).every(e=>ht(n,e)):t.type==="final"}const W=n=>n[0]===ie;function Ie(n,t){const e=n.transitions.get(t),s=[...n.transitions.keys()].filter(i=>i!==t&&Pt(t,i)).sort((i,r)=>r.length-i.length).flatMap(i=>n.transitions.get(i));return e?[...e,...s]:s}function Ae(n){const t=n.config.after;if(!t)return[];const e=i=>{const r=ce(i,n.id),o=r.type;return n.entry.push(yt(r,{id:o,delay:i})),n.exit.push(ft(o)),o};return Object.keys(t).flatMap(i=>{const r=t[i],o=typeof r=="string"?{target:r}:r,c=Number.isNaN(+i)?i:+i,u=e(c);return _(o).map(h=>({...h,event:u,delay:c}))}).map(i=>{const{delay:r}=i;return{...S(n,i.event,i),delay:r}})}function S(n,t,e){const s=Bt(e.target),i=e.reenter??!1,r=Me(n,s),o={...e,actions:_(e.actions),guard:e.guard,target:r,source:n,reenter:i,eventType:t,toJSON:()=>({...o,source:`#${n.id}`,target:r?r.map(c=>`#${c.id}`):void 0})};return o}function ke(n){const t=new Map;if(n.config.on)for(const e of Object.keys(n.config.on)){if(e===Mt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=n.config.on[e];t.set(e,O(s).map(i=>S(n,e,i)))}if(n.config.onDone){const e=`xstate.done.state.${n.id}`;t.set(e,O(n.config.onDone).map(s=>S(n,e,s)))}for(const e of n.invoke){if(e.onDone){const s=`xstate.done.actor.${e.id}`;t.set(s,O(e.onDone).map(i=>S(n,s,i)))}if(e.onError){const s=`xstate.error.actor.${e.id}`;t.set(s,O(e.onError).map(i=>S(n,s,i)))}if(e.onSnapshot){const s=`xstate.snapshot.${e.id}`;t.set(s,O(e.onSnapshot).map(i=>S(n,s,i)))}}for(const e of n.after){let s=t.get(e.eventType);s||(s=[],t.set(e.eventType,s)),s.push(e)}return t}function $e(n){const t=[],e=s=>{Object.values(s).forEach(i=>{if(i.config.route&&i.config.id){const r=i.config.id,o=i.config.route.guard,c=({event:h})=>h.to===`#${r}`,u={...i.config.route,guard:o?Ee([c,o]):c,target:`#${r}`};t.push(S(n,"xstate.route",u))}i.states&&e(i.states)})};e(n.states),t.length>0&&n.transitions.set("xstate.route",t)}function Oe(n,t){const e=typeof t=="string"?n.states[t]:t?n.states[t.target]:void 0;if(!e&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${n.id}`);const s={source:n,actions:!t||typeof t=="string"?[]:_(t.actions),eventType:null,reenter:!1,target:e?[e]:[],toJSON:()=>({...s,source:`#${n.id}`,target:e?[`#${e.id}`]:[]})};return s}function Me(n,t){if(t!==void 0)return t.map(e=>{if(typeof e!="string")return e;if(W(e))return n.machine.getStateNodeById(e);const s=e[0]===Ot;if(s&&!n.parent)return H(n,e.slice(1));const i=s?n.key+e:e;if(n.parent)try{return H(n.parent,i)}catch(r){throw new Error(`Invalid transition definition for state node '${n.id}':
|
|
2
|
-
${r.message}`)}else throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`)})}function Gt(n){const t=Bt(n.config.target);return t?{target:t.map(e=>typeof e=="string"?H(n.parent,e):e)}:n.parent.type==="parallel"?{target:[n.parent]}:n.parent.initial}function x(n){return n.type==="history"}function wt(n){const t=Ut(n);for(const e of t)for(const s of D(e,n))t.add(s);return t}function Ut(n){const t=new Set;function e(s){if(!t.has(s)){if(t.add(s),s.type==="compound")e(s.initial.target[0]);else if(s.type==="parallel")for(const i of R(s))e(i)}}return e(n),t}function j(n,t){if(W(t))return n.machine.getStateNodeById(t);if(!n.states)throw new Error(`Unable to retrieve child state '${t}' from '${n.id}'; no child states exist.`);const e=n.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${n.id}'`);return e}function H(n,t){if(typeof t=="string"&&W(t))try{return n.machine.getStateNodeById(t)}catch{}const e=ct(t).slice();let s=n;for(;e.length;){const i=e.shift();if(!i.length)break;s=j(s,i)}return s}function Y(n,t){if(typeof t=="string"){const i=n.states[t];if(!i)throw new Error(`State '${t}' does not exist on '${n.id}'`);return[n,i]}const e=Object.keys(t),s=e.map(i=>j(n,i)).filter(Boolean);return[n.machine.root,n].concat(s,e.reduce((i,r)=>{const o=j(n,r);if(!o)return i;const c=Y(o,t[r]);return i.concat(c)},[]))}function Re(n,t,e,s){const r=j(n,t).next(e,s);return!r||!r.length?n.next(e,s):r}function je(n,t,e,s){const i=Object.keys(t),r=j(n,i[0]),o=lt(r,t[i[0]],e,s);return!o||!o.length?n.next(e,s):o}function Ce(n,t,e,s){const i=[];for(const r of Object.keys(t)){const o=t[r];if(!o)continue;const c=j(n,r),u=lt(c,o,e,s);u&&i.push(...u)}return i.length?i:n.next(e,s)}function lt(n,t,e,s){return typeof t=="string"?Re(n,t,e,s):Object.keys(t).length===1?je(n,t,e,s):Ce(n,t,e,s)}function De(n){return Object.keys(n.states).map(t=>n.states[t]).filter(t=>t.type==="history")}function b(n,t){let e=n;for(;e.parent&&e.parent!==t;)e=e.parent;return e.parent===t}function Le(n,t){const e=new Set(n),s=new Set(t);for(const i of e)if(s.has(i))return!0;for(const i of s)if(e.has(i))return!0;return!1}function Ht(n,t,e){const s=new Set;for(const i of n){let r=!1;const o=new Set;for(const c of s)if(Le(st([i],t,e),st([c],t,e)))if(b(i.source,c.source))o.add(c);else{r=!0;break}if(!r){for(const c of o)s.delete(c);s.add(i)}}return Array.from(s)}function Be(n){const[t,...e]=n;for(const s of D(t,void 0))if(e.every(i=>b(i,s)))return s}function pt(n,t){if(!n.target)return[];const e=new Set;for(const s of n.target)if(x(s))if(t[s.id])for(const i of t[s.id])e.add(i);else for(const i of pt(Gt(s),t))e.add(i);else e.add(s);return[...e]}function Yt(n,t){const e=pt(n,t);if(!e)return;if(!n.reenter&&e.every(i=>i===n.source||b(i,n.source)))return n.source;const s=Be(e.concat(n.source));if(s)return s;if(!n.reenter)return n.source.machine.root}function st(n,t,e){const s=new Set;for(const i of n)if(i.target?.length){const r=Yt(i,e);i.reenter&&i.source===r&&s.add(r);for(const o of t)b(o,r)&&s.add(o)}return[...s]}function Pe(n,t){if(n.length!==t.size)return!1;for(const e of n)if(!t.has(e))return!1;return!0}function Kt(n,t,e,s,i){return it([{target:[...Ut(n)],source:n,reenter:!0,actions:[],eventType:null,toJSON:null}],t,e,s,!0,i)}function it(n,t,e,s,i,r){const o=[];if(!n.length)return[t,o];const c=e.actionExecutor;e.actionExecutor=u=>{o.push(u),c(u)};try{const u=new Set(t._nodes);let h=t.historyValue;const p=Ht(n,u,h);let f=t;i||([f,h]=We(f,s,e,p,u,h,r,e.actionExecutor)),f=C(f,s,e,p.flatMap(d=>d.actions),r,void 0),f=ze(f,s,e,p,u,r,h,i);const a=[...u];f.status==="done"&&(f=C(f,s,e,a.sort((d,l)=>l.order-d.order).flatMap(d=>d.exit),r,void 0));try{return h===t.historyValue&&Pe(t._nodes,u)?[f,o]:[T(f,{_nodes:a,historyValue:h}),o]}catch(d){throw d}}finally{e.actionExecutor=c}}function Je(n,t,e,s,i){if(s.output===void 0)return;const r=et(i.id,i.output!==void 0&&i.parent?nt(i.output,n.context,t,e.self):void 0);return nt(s.output,n.context,r,e.self)}function ze(n,t,e,s,i,r,o,c){let u=n;const h=new Set,p=new Set;qe(s,o,p,h),c&&p.add(n.machine.root);const f=new Set;for(const a of[...h].sort((d,l)=>d.order-l.order)){i.add(a);const d=[];d.push(...a.entry);for(const l of a.invoke)d.push(dt(l.src,{...l,syncSnapshot:!!l.onSnapshot}));if(p.has(a)){const l=a.initial.actions;d.push(...l)}if(u=C(u,t,e,d,r,a.invoke.map(l=>l.id)),a.type==="final"){const l=a.parent;let y=l?.type==="parallel"?l:l?.parent,g=y||a;for(l?.type==="compound"&&r.push(et(l.id,a.output!==void 0?nt(a.output,u.context,t,e.self):void 0));y?.type==="parallel"&&!f.has(y)&&ht(i,y);)f.add(y),r.push(et(y.id)),g=y,y=y.parent;if(y)continue;u=T(u,{status:"done",output:Je(u,t,e,u.machine.root,g)})}}return u}function qe(n,t,e,s){for(const i of n){const r=Yt(i,t);for(const c of i.target||[])!x(c)&&(i.source!==c||i.source!==r||i.reenter)&&(s.add(c),e.add(c)),M(c,t,e,s);const o=pt(i,t);for(const c of o){const u=D(c,r);r?.type==="parallel"&&u.push(r),Zt(s,t,e,u,!i.source.parent&&i.reenter?void 0:r)}}}function M(n,t,e,s){if(x(n))if(t[n.id]){const i=t[n.id];for(const r of i)s.add(r),M(r,t,e,s);for(const r of i)N(r,n.parent,s,t,e)}else{const i=Gt(n);for(const r of i.target)s.add(r),i===n.parent?.initial&&e.add(n.parent),M(r,t,e,s);for(const r of i.target)N(r,n.parent,s,t,e)}else if(n.type==="compound"){const[i]=n.initial.target;x(i)||(s.add(i),e.add(i)),M(i,t,e,s),N(i,n,s,t,e)}else if(n.type==="parallel")for(const i of R(n).filter(r=>!x(r)))[...s].some(r=>b(r,i))||(x(i)||(s.add(i),e.add(i)),M(i,t,e,s))}function Zt(n,t,e,s,i){for(const r of s)if((!i||b(r,i))&&n.add(r),r.type==="parallel")for(const o of R(r).filter(c=>!x(c)))[...n].some(c=>b(c,o))||(n.add(o),M(o,t,e,n))}function N(n,t,e,s,i){Zt(e,s,i,D(n,t))}function We(n,t,e,s,i,r,o,c){let u=n;const h=st(s,i,r);h.sort((f,a)=>a.order-f.order);let p;for(const f of h)for(const a of De(f)){let d;a.history==="deep"?d=l=>q(l)&&b(l,f):d=l=>l.parent===f,p??={...r},p[a.id]=Array.from(i).filter(d)}for(const f of h)u=C(u,t,e,[...f.exit,...f.invoke.map(a=>z(a.id))],o,void 0),i.delete(f);return[u,p||r]}function Xe(n,t){return n.implementations.actions[t]}function Ft(n,t,e,s,i,r){const{machine:o}=n;let c=n;for(const u of s){const h=typeof u=="function",p=h?u:Xe(o,typeof u=="string"?u:u.type),f={context:c.context,event:t,self:e.self,system:e.system},a=h||typeof u=="string"?void 0:"params"in u?typeof u.params=="function"?u.params({context:c.context,event:t}):u.params:void 0;if(!p||!("resolve"in p)){e.actionExecutor({type:typeof u=="string"?u:typeof u=="object"?u.type:u.name||"(anonymous)",info:f,params:a,exec:p});continue}const d=p,[l,y,g]=d.resolve(e,c,f,a,p,i);c=l,"retryResolve"in d&&r?.push([d,y]),"execute"in d&&e.actionExecutor({type:d.type,info:f,params:y,exec:d.execute.bind(null,e,y)}),g&&(c=Ft(c,t,e,g,i,r))}return c}function C(n,t,e,s,i,r){const o=r?[]:void 0,c=Ft(n,t,e,s,{internalQueue:i,deferredActorIds:r},o);return o?.forEach(([u,h])=>{u.retryResolve(e,c,h)}),c}function J(n,t,e,s){let i=n;const r=[];function o(f,a,d){e.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:e.self,event:a,snapshot:f[0],_transitions:d}),r.push(f)}if(t.type===w)return i=T(Et(i,t,e),{status:"stopped"}),o([i,[]],t,[]),{snapshot:i,microsteps:r};let c=t;if(c.type!==Rt){const f=c,a=de(f),d=Tt(f,i);if(a&&!d.length)return i=T(n,{status:"error",error:f.error}),o([i,[]],f,[]),{snapshot:i,microsteps:r};const l=it(d,n,e,c,!1,s);i=l[0],o(l,f,d)}let u=!0;const h=n.machine.options?.maxIterations??1/0;let p=0;for(;i.status==="active";){if(p++,p>h)throw new Error(`Infinite loop detected: the machine has processed more than ${h} microsteps without reaching a stable state. This usually happens when there's a cycle of transitions (e.g., eventless transitions or raised events causing state A -> B -> C -> A).`);let f=u?Ge(i,c):[];const a=f.length?i:void 0;if(!f.length){if(!s.length)break;c=s.shift(),f=Tt(c,i)}const d=it(f,i,e,c,!1,s);i=d[0],u=i!==a,o(d,c,f)}return i.status!=="active"&&Et(i,c,e),{snapshot:i,microsteps:r}}function Et(n,t,e){return C(n,t,e,Object.values(n.children).map(s=>z(s)),[],void 0)}function Tt(n,t){return t.machine.getTransitionData(t,n)}function Ge(n,t){const e=new Set,s=n._nodes.filter(q);for(const i of s)t:for(const r of[i].concat(D(i,void 0)))if(r.always){for(const o of r.always)if(o.guard===void 0||I(o.guard,n.context,t,n)){e.add(o);break t}}return Ht(Array.from(e),new Set(n._nodes),n.historyValue)}function Ue(n,t){const e=U(Y(n,t));return Xt(n,[...e])}function He(n){return!!n&&typeof n=="object"&&"machine"in n&&"value"in n}const Ye=function(t){return Ct(t,this.value)},Ke=function(t){return this.tags.has(t)},Ze=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some(s=>s.target!==void 0||s.actions.length)},Fe=function(){const{_nodes:t,tags:e,machine:s,getMeta:i,toJSON:r,can:o,hasTag:c,matches:u,...h}=this;return{...h,tags:Array.from(e)}},Ve=function(){return this._nodes.reduce((t,e)=>(e.meta!==void 0&&(t[e.id]=e.meta),t),{})};function G(n,t){return{status:n.status,output:n.output,error:n.error,machine:t,context:n.context,_nodes:n._nodes,value:Xt(t.root,n._nodes),tags:new Set(n._nodes.flatMap(e=>e.tags)),children:n.children,historyValue:n.historyValue||{},matches:Ye,hasTag:Ke,can:Ze,getMeta:Ve,toJSON:Fe}}function T(n,t={}){return G({...n,...t},n.machine)}function Qe(n){if(typeof n!="object"||n===null)return{};const t={};for(const e in n){const s=n[e];Array.isArray(s)&&(t[e]=s.map(i=>({id:i.id})))}return t}function Ne(n,t){const{_nodes:e,tags:s,machine:i,children:r,context:o,can:c,hasTag:u,matches:h,getMeta:p,toJSON:f,...a}=n,d={};for(const y in r){const g=r[y];d[y]={snapshot:g.getPersistedSnapshot(t),src:g.src,systemId:g.systemId,syncSnapshot:g._syncSnapshot}}return{...a,context:Vt(o),children:d,historyValue:Qe(a.historyValue)}}function Vt(n){let t;for(const e in n){const s=n[e];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)t??=Array.isArray(n)?n.slice():{...n},t[e]={xstate$$type:ut,id:s.id};else{const i=Vt(s);i!==s&&(t??=Array.isArray(n)?n.slice():{...n},t[e]=i)}}return t??n}function tn(n,t,e,s,{event:i,id:r,delay:o},{internalQueue:c}){const u=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const h=typeof i=="function"?i(e,s):i;let p;if(typeof o=="string"){const f=u&&u[o];p=typeof f=="function"?f(e,s):f}else p=typeof o=="function"?o(e,s):o;return typeof p!="number"&&c.push(h),[t,{event:h,id:r,delay:p},void 0]}function en(n,t){const{event:e,delay:s,id:i}=t;if(typeof s=="number"){n.defer(()=>{const r=n.self;n.system.scheduler.schedule(r,r,e,s,i)});return}}function yt(n,t){function e(s,i){}return e.type="xstate.raise",e.event=n,e.id=t?.id,e.delay=t?.delay,e.resolve=tn,e.execute=en,e}function nn(n,t){return{config:n,transition:(e,s,i)=>({...e,context:n(e.context,s,i)}),getInitialSnapshot:(e,s)=>({status:"active",output:void 0,error:void 0,context:typeof t=="function"?t({input:s}):t}),getPersistedSnapshot:e=>e,restoreSnapshot:e=>e}}const tt=new WeakMap;function $n(n){return{config:n,start:(e,s)=>{const{self:i,system:r,emit:o}=s,c={receivers:void 0,dispose:void 0};tt.set(i,c),c.dispose=n({input:e.input,system:r,self:i,sendBack:u=>{i.getSnapshot().status!=="stopped"&&i._parent&&r._relay(i,i._parent,u)},receive:u=>{c.receivers??=new Set,c.receivers.add(u)},emit:o})},transition:(e,s,i)=>{const r=tt.get(i.self);return s.type===w?(e={...e,status:"stopped",error:void 0},tt.delete(i.self),r.receivers?.clear(),r.dispose?.(),e):(r.receivers?.forEach(o=>o(s)),e)},getInitialSnapshot:(e,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:e=>e,restoreSnapshot:e=>e}}const It="xstate.observable.next",K="xstate.observable.error",Z="xstate.observable.complete";function On(n){return{config:n,transition:(e,s)=>{if(e.status!=="active")return e;switch(s.type){case It:return{...e,context:s.data};case K:return{...e,status:"error",error:s.data,input:void 0,_subscription:void 0};case Z:return{...e,status:"done",input:void 0,_subscription:void 0};case w:return e._subscription.unsubscribe(),{...e,status:"stopped",input:void 0,_subscription:void 0};default:return e}},getInitialSnapshot:(e,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(e,{self:s,system:i,emit:r})=>{e.status!=="done"&&(e._subscription=n({input:e.input,system:i,self:s,emit:r}).subscribe({next:o=>{i._relay(s,s,{type:It,data:o})},error:o=>{i._relay(s,s,{type:K,data:o})},complete:()=>{i._relay(s,s,{type:Z})}}))},getPersistedSnapshot:({_subscription:e,...s})=>s,restoreSnapshot:e=>({...e,_subscription:void 0})}}function Mn(n){return{config:n,transition:(e,s)=>{if(e.status!=="active")return e;switch(s.type){case K:return{...e,status:"error",error:s.data,input:void 0,_subscription:void 0};case Z:return{...e,status:"done",input:void 0,_subscription:void 0};case w:return e._subscription.unsubscribe(),{...e,status:"stopped",input:void 0,_subscription:void 0};default:return e}},getInitialSnapshot:(e,s)=>({status:"active",output:void 0,error:void 0,context:void 0,input:s,_subscription:void 0}),start:(e,{self:s,system:i,emit:r})=>{e.status!=="done"&&(e._subscription=n({input:e.input,system:i,self:s,emit:r}).subscribe({next:o=>{s._parent&&i._relay(s,s._parent,o)},error:o=>{i._relay(s,s,{type:K,data:o})},complete:()=>{i._relay(s,s,{type:Z})}}))},getPersistedSnapshot:({_subscription:e,...s})=>s,restoreSnapshot:e=>({...e,_subscription:void 0})}}const At="xstate.promise.resolve",kt="xstate.promise.reject",B=new WeakMap;function Rn(n){return{config:n,transition:(e,s,i)=>{if(e.status!=="active")return e;switch(s.type){case At:{const r=s.data;return{...e,status:"done",output:r,input:void 0}}case kt:return{...e,status:"error",error:s.data,input:void 0};case w:return B.get(i.self)?.abort(),B.delete(i.self),{...e,status:"stopped",input:void 0};default:return e}},start:(e,{self:s,system:i,emit:r})=>{if(e.status!=="active")return;const o=new AbortController;B.set(s,o),Promise.resolve(n({input:e.input,system:i,self:s,signal:o.signal,emit:r})).then(u=>{s.getSnapshot().status==="active"&&(B.delete(s),i._relay(s,s,{type:At,data:u}))},u=>{s.getSnapshot().status==="active"&&(B.delete(s),i._relay(s,s,{type:kt,data:u}))})},getInitialSnapshot:(e,s)=>({status:"active",output:void 0,error:void 0,input:s}),getPersistedSnapshot:e=>e,restoreSnapshot:e=>e}}const sn=nn(n=>{},void 0);function jn(){return E(sn)}function rn(n,{machine:t,context:e},s,i){const r=(o,c)=>{if(typeof o=="string"){const u=at(t,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const h=E(u,{id:c?.id,parent:n.self,syncSnapshot:c?.syncSnapshot,input:typeof c?.input=="function"?c.input({context:e,event:s,self:n.self}):c?.input,src:o,systemId:c?.systemId});return i[h.id]=h,h}else return E(o,{id:c?.id,parent:n.self,syncSnapshot:c?.syncSnapshot,input:c?.input,src:o,systemId:c?.systemId})};return(o,c)=>{const u=r(o,c);return i[u.id]=u,n.defer(()=>{u._processingStatus!==m.Stopped&&u.start()}),u}}function on(n,t,e,s,{assignment:i}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={},o={context:t.context,event:e.event,spawn:rn(n,t,e.event,r),self:n.self,system:n.system};let c={};if(typeof i=="function")c=i(o,s);else for(const h of Object.keys(i)){const p=i[h];c[h]=typeof p=="function"?p(o,s):p}const u=Object.assign({},t.context,c);return[T(t,{context:u,children:Object.keys(r).length?{...t.children,...r}:t.children}),void 0,void 0]}function gt(n){function t(e,s){}return t.type="xstate.assign",t.assignment=n,t.resolve=on,t}const $t=new WeakMap;function $(n,t,e){let s=$t.get(n);return s?t in s||(s[t]=e()):(s={[t]:e()},$t.set(n,s)),s[t]}const cn={},P=n=>typeof n=="string"?{type:n}:typeof n=="function"?"resolve"in n?{type:n.type}:{type:n.name}:n;class F{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Ot),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?St(this.config.states,(s,i)=>new F(s,{_parent:this,_key:i,_machine:this.machine})):cn,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=_(this.config.entry).slice(),this.exit=_(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=_(t.tags).slice()}_initialize(){this.transitions=ke(this),this.config.always&&(this.always=O(this.config.always).map(t=>S(this,Mt,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(P),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(P),eventType:null})}:void 0,history:this.history,states:St(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(P)})),entry:this.entry.map(P),exit:this.exit.map(P),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return $(this,"invoke",()=>_(this.config.invoke).map((t,e)=>{const{src:s,systemId:i}=t,r=t.id??bt(this.id,e),o=typeof s=="string"?s:`xstate.invoke.${bt(this.id,e)}`;return{...t,src:o,id:r,systemId:i,toJSON(){const{onDone:c,onError:u,...h}=t;return{...h,type:"xstate.invoke",src:o,id:r}}}}))}get on(){return $(this,"on",()=>[...this.transitions].flatMap(([e,s])=>s.map(i=>[e,i])).reduce((e,[s,i])=>(e[s]=e[s]||[],e[s].push(i),e),{}))}get after(){return $(this,"delayedTransitions",()=>Ae(this))}get initial(){return $(this,"initial",()=>Oe(this,this.config.initial))}next(t,e){const s=e.type,i=[];let r;const o=$(this,`candidates-${s}`,()=>Ie(this,s));for(const c of o){const{guard:u}=c,h=t.context;let p=!1;try{p=!u||I(u,h,e,t)}catch(f){const a=typeof u=="string"?u:typeof u=="object"?u.type:void 0;throw new Error(`Unable to evaluate guard ${a?`'${a}' `:""}in transition for event '${s}' in state node '${this.id}':
|
|
3
|
-
${f.message}`)}if(p){i.push(...c.actions),r=c;break}}return r?[r]:void 0}get events(){return $(this,"events",()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const i=t[s];if(i.states)for(const r of i.events)e.add(`${r}`)}return Array.from(e)})}get ownEvents(){const t=Object.keys(Object.fromEntries(this.transitions)),e=new Set(t.filter(s=>this.transitions.get(s).some(i=>!(!i.target&&!i.actions.length&&!i.reenter))));return Array.from(e)}}const an="#";class mt{constructor(t,e){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.options=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.options={maxIterations:1/0,...this.config.options},this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new F(t,{_key:this.id,_machine:this}),this.root._initialize(),$e(this.root),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:s,actors:i,delays:r}=this.implementations;return new mt(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...i,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const e=Ue(this.root,t.value),s=U(Y(this.root,e));return G({_nodes:[...s],context:t.context||{},children:{},status:ht(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return J(t,e,s,[]).snapshot}microstep(t,e,s){return J(t,e,s,[]).microsteps.map(([i])=>i)}getTransitionData(t,e){return lt(this.root,t.value,t,e)||[]}_getPreInitialState(t,e,s){const{context:i}=this.config,r=G({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?C(r,e,t,[gt(({spawn:c,event:u,self:h})=>i({spawn:c,input:u.input,self:h}))],s,void 0):r}getInitialSnapshot(t,e){const s=ot(e),i=[],r=this._getPreInitialState(t,s,i),[o]=Kt(this.root,r,t,s,i),{snapshot:c}=J(o,s,t,i);return c}start(t){Object.values(t.children).forEach(e=>{e.getSnapshot().status==="active"&&e.start()})}getStateNodeById(t){const e=ct(t),s=e.slice(1),i=W(e[0])?e[0].slice(an.length):e[0],r=this.idMap.get(i);if(!r)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return H(r,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return Ne(t,e)}restoreSnapshot(t,e){const s={},i=t.children;Object.keys(i).forEach(f=>{const a=i[f],d=a.snapshot,l=a.src,y=typeof l=="string"?at(this,l):l;if(!y)return;const g=E(y,{id:f,parent:e.self,syncSnapshot:a.syncSnapshot,snapshot:d,src:l,systemId:a.systemId});s[f]=g});function r(f,a){if(a instanceof F)return a;try{return f.machine.getStateNodeById(a.id)}catch{}}function o(f,a){if(!a||typeof a!="object")return{};const d={};for(const l in a){const y=a[l];for(const g of y){const A=r(f,g);A&&(d[l]??=[],d[l].push(A))}}return d}const c=o(this.root,t.historyValue),u=G({...t,children:s,_nodes:Array.from(U(Y(this.root,t.value))),historyValue:c},this),h=new Set;function p(f,a){if(!h.has(f)){h.add(f);for(const d in f){const l=f[d];if(l&&typeof l=="object"){if("xstate$$type"in l&&l.xstate$$type===ut){f[d]=a[l.id];continue}p(l,a)}}}}return p(u.context,s),u}}function un(n,t,e,s,{event:i}){const r=typeof i=="function"?i(e,s):i;return[t,{event:r},void 0]}function fn(n,{event:t}){n.defer(()=>n.emit(t))}function Qt(n){function t(e,s){}return t.type="xstate.emit",t.event=n,t.resolve=un,t.execute=fn,t}let rt=(function(n){return n.Parent="#_parent",n.Internal="#_internal",n})({});function dn(n,t,e,s,{to:i,event:r,id:o,delay:c},u){const h=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${r}" }) instead`);const p=typeof r=="function"?r(e,s):r;let f;if(typeof c=="string"){const l=h&&h[c];f=typeof l=="function"?l(e,s):l}else f=typeof c=="function"?c(e,s):c;const a=typeof i=="function"?i(e,s):i;let d;if(typeof a=="string"){if(a===rt.Parent?d=n.self._parent:a===rt.Internal?d=n.self:a.startsWith("#_")?d=t.children[a.slice(2)]:d=u.deferredActorIds?.includes(a)?a:t.children[a],!d)throw new Error(`Unable to send event to actor '${a}' from machine '${t.machine.id}'.`)}else d=a||n.self;return[t,{to:d,targetId:typeof a=="string"?a:void 0,event:p,id:o,delay:f},void 0]}function hn(n,t,e){typeof e.to=="string"&&(e.to=t.children[e.to])}function ln(n,t){n.defer(()=>{const{to:e,event:s,delay:i,id:r}=t;if(typeof i=="number"){n.system.scheduler.schedule(n.self,e,s,i,r);return}n.system._relay(n.self,e,s.type===oe?jt(n.self.id,s.data):s)})}function V(n,t,e){function s(i,r){}return s.type="xstate.sendTo",s.to=n,s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=dn,s.retryResolve=hn,s.execute=ln,s}function pn(n,t){return V(rt.Parent,n,t)}function Cn(n,t){return V(n,({event:e})=>e,t)}function yn(n,t,e,s,{collect:i}){const r=[],o=function(u){r.push(u)};return o.assign=(...c)=>{r.push(gt(...c))},o.cancel=(...c)=>{r.push(ft(...c))},o.raise=(...c)=>{r.push(yt(...c))},o.sendTo=(...c)=>{r.push(V(...c))},o.sendParent=(...c)=>{r.push(pn(...c))},o.spawnChild=(...c)=>{r.push(dt(...c))},o.stopChild=(...c)=>{r.push(z(...c))},o.emit=(...c)=>{r.push(Qt(...c))},i({context:e.context,event:e.event,enqueue:o,check:c=>I(c,t.context,e.event,t),self:n.self,system:n.system},s),[t,void 0,r]}function gn(n){function t(e,s){}return t.type="xstate.enqueueActions",t.collect=n,t.resolve=yn,t}function mn(n,t,e,s,{value:i,label:r}){return[t,{value:typeof i=="function"?i(e,s):i,label:r},void 0]}function vn({logger:n},{value:t,label:e}){e?n(e,t):n(t)}function _n(n=({context:e,event:s})=>({context:e,event:s}),t){function e(s,i){}return e.type="xstate.log",e.value=n,e.label=t,e.resolve=mn,e.execute=vn,e}function Dn(n,t){const e=_(t);if(!e.some(i=>Pt(n.type,i))){const i=e.length===1?`type matching "${e[0]}"`:`one of types matching "${e.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(n)} to have ${i}`)}}function Sn(n,t){return new mt(n,t)}function Ln(n,t){const e=[],s=(r,o)=>{let c=r;for(const u of o){if(!c?.states)return;const h=c.states;if(!(u in h))return;c=h[u]}return c},i=new Set;for(const r of n._nodes.filter(q)){let o=r;for(;o&&!i.has(o);){i.add(o);const c=s(t,o.path);c?.map&&e.push({stateNode:o,result:c.map(n)}),o=o.parent}}return e}function L(n){const t=E(n),e=Jt(t,{clock:t.system._clock,logger:t.system._logger});return t.system=e,{self:t,defer:()=>{},id:"",logger:()=>{},sessionId:"",stopChild:()=>{},system:e,emit:()=>{},actionExecutor:()=>{}}}function Bn(n,...[t]){const e=L(n);return n.getInitialSnapshot(e,t)}function Pn(n,t,e){const s=L(n);return s.self._snapshot=t,n.transition(t,e,s)}function bn({schemas:n,actors:t,actions:e,guards:s,delays:i}){return{assign:gt,sendTo:V,raise:yt,log:_n,cancel:ft,stopChild:z,enqueueActions:gn,emit:Qt,spawnChild:dt,createStateConfig:r=>r,createAction:r=>r,createMachine:r=>Sn({...r,schemas:n},{actors:t,actions:e,guards:s,delays:i}),extend:r=>bn({schemas:n,actors:t,actions:{...e,...r.actions},guards:{...s,...r.guards},delays:{...i,...r.delays}})}}class Jn{constructor(){this.timeouts=new Map,this._now=0,this._id=0,this._flushing=!1,this._flushingInvalidated=!1}now(){return this._now}getId(){return this._id++}setTimeout(t,e){this._flushingInvalidated=this._flushing;const s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}clearTimeout(t){this._flushingInvalidated=this._flushing,this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){if(this._flushing){this._flushingInvalidated=!0;return}this._flushing=!0;const t=[...this.timeouts].sort(([e,s],[i,r])=>{const o=s.start+s.timeout;return r.start+r.timeout>o?-1:1});for(const[e,s]of t){if(this._flushingInvalidated){this._flushingInvalidated=!1,this._flushing=!1,this.flushTimeouts();return}this.now()-s.start>=s.timeout&&(this.timeouts.delete(e),s.fn.call(null))}this._flushing=!1}increment(t){this._now+=t,this.flushTimeouts()}}function zn(n){return new Promise((t,e)=>{n.subscribe({complete:()=>{t(n.getSnapshot().output)},error:e})})}function qn(n,t,e){const s=[],i=L(n);return i.actionExecutor=o=>{s.push(o)},[n.transition(t,e,i),s]}function Wn(n,...[t]){const e=[],s=L(n);return s.actionExecutor=r=>{e.push(r)},[n.getInitialSnapshot(s,t),e]}function Xn(n,t,e){const s=L(n),{microsteps:i}=J(t,e,s,[]);return i}function Gn(n,...[t]){const e=L(n),s=ot(t),i=[],r=n._getPreInitialState(e,s,i),o=Kt(n.root,r,e,s,i),{microsteps:c}=J(o[0],s,e,i);return[o,...c]}function Un(n){const t=[],e=n._nodes.filter(q),s=new Set;for(const i of e)for(const r of[i].concat(D(i,void 0)))if(!s.has(r.id)){s.add(r.id);for(const[,o]of r.transitions)t.push(...o);r.always&&t.push(...r.always)}return t}const xn={timeout:1/0};function Hn(n,t,e){const s={...xn,...e};return new Promise((i,r)=>{const{signal:o}=s;if(o?.aborted){r(o.reason);return}let c=!1;const u=s.timeout===1/0?void 0:setTimeout(()=>{h(),r(new Error(`Timeout of ${s.timeout} ms exceeded`))},s.timeout),h=()=>{clearTimeout(u),c=!0,a?.unsubscribe(),f&&o.removeEventListener("abort",f)};function p(d){t(d)&&(h(),i(d))}let f,a;p(n.getSnapshot()),!c&&(o&&(f=()=>{h(),r(o.reason)},o.addEventListener("abort",f)),a=n.subscribe({next:p,error:d=>{h(),r(d)},complete:()=>{h(),r(new Error("Actor terminated without satisfying predicate"))}}),c&&a.unsubscribe())})}export{pe as Actor,Jn as SimulatedClock,rt as SpecialTargets,mt as StateMachine,F as StateNode,wn as __unsafe_getAllOwnEventDescriptors,Ee as and,Dn as assertEvent,gt as assign,ft as cancel,E as createActor,jn as createEmptyActor,Sn as createMachine,Qt as emit,gn as enqueueActions,Cn as forwardTo,$n as fromCallback,Mn as fromEventObservable,On as fromObservable,Rn as fromPromise,nn as fromTransition,Gn as getInitialMicrosteps,Bn as getInitialSnapshot,Xn as getMicrosteps,Pn as getNextSnapshot,Un as getNextTransitions,Y as getStateNodes,Wn as initialTransition,En as interpret,He as isMachineSnapshot,_n as log,Ln as mapState,Ct as matchesState,An as not,kn as or,fe as pathToStateValue,yt as raise,pn as sendParent,V as sendTo,bn as setup,dt as spawnChild,In as stateIn,Tn as stop,z as stopChild,X as toObserver,zn as toPromise,qn as transition,Hn as waitFor};
|
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scene-UI design-time layer (C3, docs/unified-world-editor/26-unified-
|
|
3
|
-
* editor-spec.md §4 C3) — the box-model overlay + stage guides "in the
|
|
4
|
-
* normal viewport" the spec calls for, replacing the retired standalone
|
|
5
|
-
* UI-edit mode's fullscreen `#ui-edit-mode-layer`. Sibling of
|
|
6
|
-
* `design-time-layers.ts`, but
|
|
7
|
-
* mounts the scene-UI composite child (`edit-mode-authoring.ts`'s `kind:
|
|
8
|
-
* 'scene-ui'` child) instead of a react/pixi world: that child already
|
|
9
|
-
* carries a LIVE `UIAuthoringAdapter` at composite-install time (there is no
|
|
10
|
-
* Boundary-to-live upgrade dance here, unlike react/pixi) — this module only
|
|
11
|
-
* gives it a DOM layer, a pick surface (D12/B4), and keeps the shared
|
|
12
|
-
* `EditorStore` and the child's own `UIEditStore` in lockstep.
|
|
13
|
-
*
|
|
14
|
-
* Reuses EVERY existing building block — no new UI runtime, no fork:
|
|
15
|
-
* - `SceneUITree` (the exact runtime that renders at game-time) in `editMode`.
|
|
16
|
-
* - `SelectionOverlay` (`ui-editor/overlay.tsx`) — hover/selection/marquee/
|
|
17
|
-
* resize boxes + the `Measure` spacing guide — IS the box-model overlay;
|
|
18
|
-
* it renders boxes only while `store.selection` is non-empty, so it
|
|
19
|
-
* "activates contextually on UI-node selection" for free.
|
|
20
|
-
* - `UIAuthoringAdapter.pickable` (added by C3) backed by `hitTest`
|
|
21
|
-
* (`ui-editor/react-store.ts`), the same geometric primitive the overlay
|
|
22
|
-
* itself uses for hover/click.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import type { UIRoot } from '@engine/scene/schema';
|
|
26
|
-
import type { UIAnimationController } from '@vgai/scene-ui/animation';
|
|
27
|
-
import { SceneUITree } from '@vgai/scene-ui/mount';
|
|
28
|
-
import type { ProjectUIRegistry } from '@vgai/scene-ui/registry';
|
|
29
|
-
import { createElement, useEffect, useRef, useState } from 'react';
|
|
30
|
-
import { createRoot } from 'react-dom/client';
|
|
31
|
-
import {
|
|
32
|
-
getCachedProjectUIRegistry,
|
|
33
|
-
loadProjectUIRegistry,
|
|
34
|
-
setCachedProjectUIRegistry,
|
|
35
|
-
} from '../adapter-resolver';
|
|
36
|
-
import type { EditorStore } from '../editor-store';
|
|
37
|
-
import { getCurrentProject } from '../project-manager';
|
|
38
|
-
import { findNode } from '../ui-editor/node-ops';
|
|
39
|
-
import { SelectionOverlay } from '../ui-editor/overlay';
|
|
40
|
-
import { useUIStore } from '../ui-editor/react-store';
|
|
41
|
-
import type { UIEditStore } from '../ui-editor/ui-edit-store';
|
|
42
|
-
import type { UIAuthoringAdapter } from './ui-authoring-adapter';
|
|
43
|
-
import { isWorldHidden, isWorldInteractive } from './world-session-state';
|
|
44
|
-
|
|
45
|
-
/** Container-ish UI kinds (mirrors `ui-editor/palette.tsx`'s own unexported
|
|
46
|
-
* `isContainer` — a project-registry component insert (below) targets the
|
|
47
|
-
* primary selection when it's one of these, else the first root, exactly
|
|
48
|
-
* like the harness palette's own "add under selected container" rule. */
|
|
49
|
-
const CONTAINER_KINDS = new Set([
|
|
50
|
-
'canvas',
|
|
51
|
-
'box',
|
|
52
|
-
'grid',
|
|
53
|
-
'stack',
|
|
54
|
-
'scroll',
|
|
55
|
-
'panel',
|
|
56
|
-
'center',
|
|
57
|
-
'wrap',
|
|
58
|
-
'aspect',
|
|
59
|
-
'sizebox',
|
|
60
|
-
'tab',
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
/** Pure (DOM-free) equality check for the R3 echo guard — exported for unit
|
|
64
|
-
* testing without a browser: `uiStore.onCommit -> store.setSceneUI -> store
|
|
65
|
-
* notify -> this module's sync sees "changed" -> uiStore.load()` would wipe
|
|
66
|
-
* selection + undo after every edit unless the sync SKIPS a no-op round
|
|
67
|
-
* trip (the just-committed content already matches). */
|
|
68
|
-
export function sceneUIChanged(a: readonly UIRoot[], b: readonly UIRoot[]): boolean {
|
|
69
|
-
return JSON.stringify(a) !== JSON.stringify(b);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The content-sync decision for the viewport layer's `EditorStore`
|
|
74
|
-
* subscription (C3 skeptic fix): reload the UI child from the committed
|
|
75
|
-
* document ONLY when it genuinely diverged AND no interactive gesture owns the
|
|
76
|
-
* preview `_roots`. During a live drag/resize `uiStore.serialize()` reflects
|
|
77
|
-
* uncommitted preview state, so `sceneUIChanged` is true and a naive reload
|
|
78
|
-
* would revert the drag and wipe selection/local-undo mid-motion (reachable
|
|
79
|
-
* whenever any `EditorStore` notify — e.g. the previous commit's async
|
|
80
|
-
* autosave — lands inside the gesture window). `endEdit()` commits through
|
|
81
|
-
* `setSceneUI`, after which content matches and no reload is needed. Exported
|
|
82
|
-
* so the wiring in `mountSceneUILayer` is unit-testable against a real
|
|
83
|
-
* `UIEditStore`'s gesture state (the subscription closure otherwise is not).
|
|
84
|
-
*/
|
|
85
|
-
export function shouldReloadUIChild(
|
|
86
|
-
sceneUI: readonly UIRoot[],
|
|
87
|
-
uiStore: Pick<UIEditStore, 'inGesture' | 'serialize'>,
|
|
88
|
-
): boolean {
|
|
89
|
-
return !uiStore.inGesture && sceneUIChanged(sceneUI, uiStore.serialize());
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** E1 "lose nothing" migration (§8 "board-state/responsive/locale preview") —
|
|
93
|
-
* the harness's fixed-resolution device presets (`UIEditor.tsx`'s
|
|
94
|
-
* `RES_PRESETS`/`I3`), ported verbatim so the unified editor's scene-UI
|
|
95
|
-
* chrome doesn't drop the responsive-preview affordance. `fit` (the default)
|
|
96
|
-
* keeps today's full-bleed `inset:0` stage untouched — only picking an
|
|
97
|
-
* explicit preset switches the stage to a centered, fixed-size box. */
|
|
98
|
-
const RES_PRESETS: Record<string, { width: number; height: number } | null> = {
|
|
99
|
-
fit: null,
|
|
100
|
-
'1920×1080': { width: 1920, height: 1080 },
|
|
101
|
-
'1280×720': { width: 1280, height: 720 },
|
|
102
|
-
'375×812 (phone)': { width: 375, height: 812 },
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** Fit a fixed preset's ASPECT into a capped display box (verbatim from
|
|
106
|
-
* `UIEditor.tsx`) so a resolution preview never clips against the
|
|
107
|
-
* design-time layer's own (usually much larger) bounds. */
|
|
108
|
-
function fitDisplaySize(res: { width: number; height: number }): { width: number; height: number } {
|
|
109
|
-
const maxW = 960;
|
|
110
|
-
const maxH = 560;
|
|
111
|
-
const s = Math.min(maxW / res.width, maxH / res.height, 1);
|
|
112
|
-
return { width: Math.round(res.width * s), height: Math.round(res.height * s) };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function createStageLayer(container: HTMLElement, worldId: string, zIndex: number): HTMLElement {
|
|
116
|
-
const layer = document.createElement('div');
|
|
117
|
-
layer.dataset['worldId'] = worldId;
|
|
118
|
-
layer.style.position = 'absolute';
|
|
119
|
-
layer.style.top = '0';
|
|
120
|
-
layer.style.left = '0';
|
|
121
|
-
layer.style.width = '100%';
|
|
122
|
-
layer.style.height = '100%';
|
|
123
|
-
layer.style.zIndex = String(zIndex);
|
|
124
|
-
layer.style.display = isWorldHidden(worldId) ? 'none' : 'block';
|
|
125
|
-
// B1 semantics: `pointer-events:none` at rest — plain click-select goes
|
|
126
|
-
// through B4 (`layered-pick.ts`, via `UIAuthoringAdapter.pickable`)
|
|
127
|
-
// instead, so the overlay's own drag/resize/marquee handlers only need to
|
|
128
|
-
// receive real pointer events while the layer's `interactive` toggle is on.
|
|
129
|
-
layer.style.pointerEvents = isWorldInteractive(worldId) ? 'auto' : 'none';
|
|
130
|
-
container.appendChild(layer);
|
|
131
|
-
return layer;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
interface SceneUILayerRootProps {
|
|
135
|
-
uiStore: UIEditStore;
|
|
136
|
-
projectRoot: string | undefined;
|
|
137
|
-
/** E1.b — the child's ONE animation controller, owned by `UIAuthoringAdapter`
|
|
138
|
-
* (shared with the timeline panel, `scene-ui-mode/scene-ui-timeline-tab.tsx`)
|
|
139
|
-
* instead of a `useMemo`'d local instance — see that adapter field's doc
|
|
140
|
-
* comment for why the two mounts must share one instance. */
|
|
141
|
-
anim: UIAnimationController;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** The stage + overlay, composed exactly like `UIEditor.tsx`'s center stage
|
|
145
|
-
* (`:259-283`), minus the chrome — plus a project-registry load (§3.3),
|
|
146
|
-
* mirroring the retired standalone UI-edit mode's own registry resolution
|
|
147
|
-
* (components/strings/states) without its demo-fixture fallback branch
|
|
148
|
-
* (dropped by design, Q3). */
|
|
149
|
-
function SceneUILayerRoot({ uiStore, projectRoot, anim }: SceneUILayerRootProps): React.ReactNode {
|
|
150
|
-
useUIStore(uiStore);
|
|
151
|
-
const stageRef = useRef<HTMLDivElement>(null);
|
|
152
|
-
const [registry, setRegistry] = useState<ProjectUIRegistry | null>(() =>
|
|
153
|
-
getCachedProjectUIRegistry(),
|
|
154
|
-
);
|
|
155
|
-
// I3/G5 "lose nothing" migration — resolution/locale preview (see
|
|
156
|
-
// `RES_PRESETS`'s doc comment above); session-local UI state (not
|
|
157
|
-
// persisted), same as the harness toolbar's own `useState`.
|
|
158
|
-
const [resKey, setResKey] = useState('fit');
|
|
159
|
-
const previewRes = RES_PRESETS[resKey] ?? null;
|
|
160
|
-
const display = previewRes ? fitDisplaySize(previewRes) : null;
|
|
161
|
-
|
|
162
|
-
// E1.R2 review follow-up: this used to also call `uiStore.setPreviewResolution
|
|
163
|
-
// (previewRes)` on every `previewRes` change. `UIEditStore.previewResolution`
|
|
164
|
-
// (the field that write feeds) has ZERO readers anywhere in the repo — the
|
|
165
|
-
// stage resize below is driven entirely by the LOCAL `display`/`resKey` React
|
|
166
|
-
// state, never by that store field — so the write was dead-ported state left
|
|
167
|
-
// over from the harness (`UIEditor.tsx`, which still calls it, unreviewed
|
|
168
|
-
// here) and has been dropped rather than pinned by a test that could never
|
|
169
|
-
// observe anything.
|
|
170
|
-
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
if (!projectRoot) return;
|
|
173
|
-
let cancelled = false;
|
|
174
|
-
void loadProjectUIRegistry(projectRoot).then((r) => {
|
|
175
|
-
// Cache regardless of the registry's outcome (present/absent/broken) —
|
|
176
|
-
// the SAME cache slot the broken-registry loud warn reads from
|
|
177
|
-
// (`adapter-resolver.ts`), preserving 24-ui-registry's assertion.
|
|
178
|
-
setCachedProjectUIRegistry(r);
|
|
179
|
-
if (cancelled) return;
|
|
180
|
-
setRegistry(r);
|
|
181
|
-
if (r?.states) {
|
|
182
|
-
for (const [name, data] of Object.entries(r.states)) uiStore.defineState(name, data);
|
|
183
|
-
// 'default' (else the first entry) seeds the binding preview — same
|
|
184
|
-
// resolution order the retired standalone UI-edit mode used.
|
|
185
|
-
const first = r.states['default'] ? 'default' : Object.keys(r.states)[0];
|
|
186
|
-
if (first) uiStore.loadState(first);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
return () => {
|
|
190
|
-
cancelled = true;
|
|
191
|
-
};
|
|
192
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- one-shot load per mount
|
|
193
|
-
}, [projectRoot]);
|
|
194
|
-
|
|
195
|
-
// Board-state switching (C12) — a minimal always-on strip (NOT the richer
|
|
196
|
-
// harness toolbar, `UIEditor.tsx`'s `state-${s}` buttons, which stays
|
|
197
|
-
// harness-only): the registry's named states need SOME surface in the
|
|
198
|
-
// unified editor so a binding preview is actually reachable, per §6's
|
|
199
|
-
// "24-ui-registry" testing note. Kept `pointer-events: auto` explicitly —
|
|
200
|
-
// out of the B1 `interactive` toggle's scope (that gates the SelectionOverlay's
|
|
201
|
-
// drag/resize/marquee, spec-27 Phase B/C/D territory; a state switcher is a
|
|
202
|
-
// small, always-on affordance, not that).
|
|
203
|
-
const stateNames = registry?.states ? Object.keys(registry.states) : [];
|
|
204
|
-
const stateStrip =
|
|
205
|
-
stateNames.length > 0
|
|
206
|
-
? createElement(
|
|
207
|
-
'div',
|
|
208
|
-
{
|
|
209
|
-
'data-testid': 'scene-ui-states',
|
|
210
|
-
style: {
|
|
211
|
-
position: 'absolute',
|
|
212
|
-
top: 0,
|
|
213
|
-
left: 0,
|
|
214
|
-
zIndex: 20,
|
|
215
|
-
display: 'flex',
|
|
216
|
-
gap: 4,
|
|
217
|
-
padding: 4,
|
|
218
|
-
pointerEvents: 'auto',
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
...stateNames.map((name) =>
|
|
222
|
-
createElement(
|
|
223
|
-
'button',
|
|
224
|
-
{
|
|
225
|
-
key: name,
|
|
226
|
-
'data-testid': `scene-ui-state-${name}`,
|
|
227
|
-
onClick: () => uiStore.loadState(name),
|
|
228
|
-
style: { fontSize: 10 },
|
|
229
|
-
},
|
|
230
|
-
name,
|
|
231
|
-
),
|
|
232
|
-
),
|
|
233
|
-
)
|
|
234
|
-
: null;
|
|
235
|
-
|
|
236
|
-
// Registry-component insertion — a minimal always-on strip, same rationale
|
|
237
|
-
// as the state strip above: `structure.creatableKinds` (the hierarchy's
|
|
238
|
-
// "Create ▸" menu) only knows the fixed built-in kinds (`CREATABLE_KINDS`,
|
|
239
|
-
// `ui-authoring-adapter.ts`), never a project's OWN named registry
|
|
240
|
-
// components — inserting one needs SOME surface (the harness has none
|
|
241
|
-
// either; both a project registry AND a component-insert UI are new to
|
|
242
|
-
// this task). Targets the primary selection when it's a container, else
|
|
243
|
-
// the first root — the same rule `ui-editor/palette.tsx`'s own `add` uses.
|
|
244
|
-
const componentNames = registry?.components ? Object.keys(registry.components) : [];
|
|
245
|
-
const componentStrip =
|
|
246
|
-
componentNames.length > 0
|
|
247
|
-
? createElement(
|
|
248
|
-
'div',
|
|
249
|
-
{
|
|
250
|
-
'data-testid': 'scene-ui-components',
|
|
251
|
-
style: {
|
|
252
|
-
position: 'absolute',
|
|
253
|
-
top: 0,
|
|
254
|
-
right: 0,
|
|
255
|
-
zIndex: 20,
|
|
256
|
-
display: 'flex',
|
|
257
|
-
gap: 4,
|
|
258
|
-
padding: 4,
|
|
259
|
-
pointerEvents: 'auto',
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
...componentNames.map((name) =>
|
|
263
|
-
createElement(
|
|
264
|
-
'button',
|
|
265
|
-
{
|
|
266
|
-
key: name,
|
|
267
|
-
'data-testid': `scene-ui-insert-${name}`,
|
|
268
|
-
onClick: () => {
|
|
269
|
-
const primary = uiStore.primary;
|
|
270
|
-
const primaryLoc = primary ? findNode(uiStore.roots, primary) : null;
|
|
271
|
-
const parentId =
|
|
272
|
-
primaryLoc && CONTAINER_KINDS.has(primaryLoc.node.kind)
|
|
273
|
-
? primary!
|
|
274
|
-
: ((uiStore.roots[0]?.id as string | undefined) ?? null);
|
|
275
|
-
if (parentId) {
|
|
276
|
-
uiStore.addNodeValue(parentId, { kind: 'component', name, component: name });
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
style: { fontSize: 10 },
|
|
280
|
-
},
|
|
281
|
-
name,
|
|
282
|
-
),
|
|
283
|
-
),
|
|
284
|
-
)
|
|
285
|
-
: null;
|
|
286
|
-
|
|
287
|
-
// I3/G5 — a minimal always-on strip for the responsive/locale preview
|
|
288
|
-
// (§8's "board-state/responsive/locale preview" MIGRATE row), same
|
|
289
|
-
// rationale/placement discipline as `stateStrip`/`componentStrip` above:
|
|
290
|
-
// the harness's richer toolbar (`UIEditor.tsx`'s `tb-res`/`tb-locale`)
|
|
291
|
-
// stays harness-only; the unified editor needs SOME surface so the
|
|
292
|
-
// affordance isn't silently dropped. Locale options come from the
|
|
293
|
-
// registry's own `strings` tables — the same source the harness reads
|
|
294
|
-
// (`Object.keys(strings ?? { en: {} })`).
|
|
295
|
-
const localeNames = registry?.strings ? Object.keys(registry.strings) : ['en'];
|
|
296
|
-
const previewStrip = createElement(
|
|
297
|
-
'div',
|
|
298
|
-
{
|
|
299
|
-
'data-testid': 'scene-ui-preview-controls',
|
|
300
|
-
style: {
|
|
301
|
-
position: 'absolute',
|
|
302
|
-
top: 0,
|
|
303
|
-
left: '50%',
|
|
304
|
-
transform: 'translateX(-50%)',
|
|
305
|
-
zIndex: 20,
|
|
306
|
-
display: 'flex',
|
|
307
|
-
gap: 4,
|
|
308
|
-
padding: 4,
|
|
309
|
-
pointerEvents: 'auto',
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
createElement(
|
|
313
|
-
'select',
|
|
314
|
-
{
|
|
315
|
-
'data-testid': 'scene-ui-res-preset',
|
|
316
|
-
value: resKey,
|
|
317
|
-
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => setResKey(e.target.value),
|
|
318
|
-
style: { fontSize: 10 },
|
|
319
|
-
},
|
|
320
|
-
...Object.keys(RES_PRESETS).map((k) => createElement('option', { key: k, value: k }, k)),
|
|
321
|
-
),
|
|
322
|
-
createElement(
|
|
323
|
-
'select',
|
|
324
|
-
{
|
|
325
|
-
'data-testid': 'scene-ui-locale',
|
|
326
|
-
value: uiStore.locale,
|
|
327
|
-
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => uiStore.setLocale(e.target.value),
|
|
328
|
-
style: { fontSize: 10 },
|
|
329
|
-
},
|
|
330
|
-
...localeNames.map((l) => createElement('option', { key: l, value: l }, l)),
|
|
331
|
-
),
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
return createElement(
|
|
335
|
-
'div',
|
|
336
|
-
{
|
|
337
|
-
// Default ('fit', `display === null`) — an unchanged full-bleed box
|
|
338
|
-
// (byte-identical to pre-migration layout: `position:absolute;inset:0`
|
|
339
|
-
// containing a 100%x100% stage, no flex). A picked preset instead
|
|
340
|
-
// centers the fixed-size stage box within the same full-bleed area.
|
|
341
|
-
style: display
|
|
342
|
-
? {
|
|
343
|
-
position: 'absolute',
|
|
344
|
-
inset: 0,
|
|
345
|
-
display: 'flex',
|
|
346
|
-
alignItems: 'center',
|
|
347
|
-
justifyContent: 'center',
|
|
348
|
-
}
|
|
349
|
-
: { position: 'absolute', inset: 0 },
|
|
350
|
-
},
|
|
351
|
-
createElement(
|
|
352
|
-
'div',
|
|
353
|
-
{
|
|
354
|
-
ref: stageRef,
|
|
355
|
-
'data-ui-stage': true,
|
|
356
|
-
style: display
|
|
357
|
-
? {
|
|
358
|
-
position: 'relative',
|
|
359
|
-
width: display.width,
|
|
360
|
-
height: display.height,
|
|
361
|
-
outline: '1px dashed #4a90d9',
|
|
362
|
-
}
|
|
363
|
-
: { position: 'relative', width: '100%', height: '100%' },
|
|
364
|
-
},
|
|
365
|
-
createElement(SceneUITree, {
|
|
366
|
-
roots: uiStore.roots,
|
|
367
|
-
data: uiStore.data,
|
|
368
|
-
components: registry?.components,
|
|
369
|
-
strings: registry?.strings,
|
|
370
|
-
locale: uiStore.locale,
|
|
371
|
-
editMode: true,
|
|
372
|
-
viewportOverride: display ?? undefined,
|
|
373
|
-
anim,
|
|
374
|
-
}),
|
|
375
|
-
createElement(SelectionOverlay, { store: uiStore, stageRef }),
|
|
376
|
-
),
|
|
377
|
-
stateStrip,
|
|
378
|
-
componentStrip,
|
|
379
|
-
previewStrip,
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Mount the scene-UI design-time layer for `worldId` (the composite's
|
|
385
|
-
* `scene-ui` child) into `container` (`ViewportPanel`'s own container — the
|
|
386
|
-
* same one `design-time-layers.ts`'s react/pixi layers use). Returns a
|
|
387
|
-
* disposer. Call it once per composite install; `design-time-layers.ts`'s
|
|
388
|
-
* `mountDesignTimeLayers` is the one production call site.
|
|
389
|
-
*/
|
|
390
|
-
export function mountSceneUILayer(
|
|
391
|
-
container: HTMLElement,
|
|
392
|
-
worldId: string,
|
|
393
|
-
uiAdapter: UIAuthoringAdapter,
|
|
394
|
-
store: EditorStore,
|
|
395
|
-
zIndex: number,
|
|
396
|
-
): () => void {
|
|
397
|
-
const projectRoot = getCurrentProject()?.rootPath;
|
|
398
|
-
const uiStore = uiAdapter.uiStore;
|
|
399
|
-
const layer = createStageLayer(container, worldId, zIndex);
|
|
400
|
-
uiAdapter.attachPickSurface(layer);
|
|
401
|
-
|
|
402
|
-
const root = createRoot(layer);
|
|
403
|
-
root.render(createElement(SceneUILayerRoot, { uiStore, projectRoot, anim: uiAdapter.anim }));
|
|
404
|
-
|
|
405
|
-
// R3 (echo guard) + R4-adjacent selection bridge: `uiStore.select()` can be
|
|
406
|
-
// reached WITHOUT going through `UIAuthoringAdapter.selection.set` (e.g.
|
|
407
|
-
// `SelectionOverlay`'s own click handler, `UIEditStore.addNode`'s
|
|
408
|
-
// auto-select) — mirroring `uiStore.selection` outward keeps the SHARED
|
|
409
|
-
// `EditorStore.selectedEntityIds` (what `Inspector.tsx`/`GameHierarchy`
|
|
410
|
-
// read) in lockstep no matter which surface drove the change. `suppressing`
|
|
411
|
-
// breaks the two-way ping-pong: each direction's write happens INSIDE the
|
|
412
|
-
// flag, so the other direction's listener (which fires synchronously,
|
|
413
|
-
// re-entrantly) sees it set and no-ops.
|
|
414
|
-
let suppressing = false;
|
|
415
|
-
let lastMirroredUiSelectionKey = uiStore.selection.join('\u0000');
|
|
416
|
-
|
|
417
|
-
const unsubUI = uiStore.subscribe(() => {
|
|
418
|
-
if (suppressing) return;
|
|
419
|
-
const key = uiStore.selection.join('\u0000');
|
|
420
|
-
if (key === lastMirroredUiSelectionKey) return;
|
|
421
|
-
lastMirroredUiSelectionKey = key;
|
|
422
|
-
suppressing = true;
|
|
423
|
-
try {
|
|
424
|
-
store.selectMultiple(uiStore.selection);
|
|
425
|
-
} finally {
|
|
426
|
-
suppressing = false;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
const unsubStore = store.subscribe(() => {
|
|
431
|
-
// C9 content sync — external changes (undo/redo of the whole document,
|
|
432
|
-
// scene switch) reload the UI child; the equality check IS the R3 guard
|
|
433
|
-
// against the commit echo (`onCommit -> setSceneUI -> notify -> here`
|
|
434
|
-
// sees the just-committed content already matches, skips `load()`).
|
|
435
|
-
//
|
|
436
|
-
// The `inGesture` gate is the C3 skeptic fix: during a live drag/resize,
|
|
437
|
-
// `uiStore.serialize()` reflects the uncommitted preview `_roots`, so it
|
|
438
|
-
// differs from the committed `getSceneUI()` and this branch would call
|
|
439
|
-
// `load()` — reverting the drag and wiping selection/local-undo mid-motion.
|
|
440
|
-
// Any `EditorStore` notify can reach here mid-gesture (most reachably the
|
|
441
|
-
// previous commit's async autosave resolving inside the next drag's
|
|
442
|
-
// window). Skip the reload while a gesture owns `_roots`; `endEdit()`
|
|
443
|
-
// commits through `setSceneUI`, after which content matches and no reload
|
|
444
|
-
// is needed. (A genuine external doc change arriving mid-gesture — vanishing
|
|
445
|
-
// rare — is simply deferred, never allowed to destroy the active gesture.)
|
|
446
|
-
const sceneUI = store.getSceneUI();
|
|
447
|
-
if (shouldReloadUIChild(sceneUI, uiStore)) {
|
|
448
|
-
uiStore.load(sceneUI);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (!suppressing) {
|
|
452
|
-
const ids = [...store.selectedEntityIds];
|
|
453
|
-
const uiOwnsSelection = ids.length > 0 && ids.every((id) => uiStore.find(id) != null);
|
|
454
|
-
if (uiOwnsSelection) {
|
|
455
|
-
// Already reflects (or will reflect, via the mirror above) uiStore's
|
|
456
|
-
// own selection — nothing to clear, and don't let a stale key here
|
|
457
|
-
// cause a redundant re-mirror on the next uiStore notify.
|
|
458
|
-
lastMirroredUiSelectionKey = ids.join('\u0000');
|
|
459
|
-
} else if (uiStore.selection.length > 0) {
|
|
460
|
-
// A non-UI (or empty) selection landed on the shared store — the UI
|
|
461
|
-
// child no longer owns it. Clear the UI selection so a stale
|
|
462
|
-
// highlighted node doesn't linger and the inspector never
|
|
463
|
-
// double-matches (R4's "one inspector" discipline).
|
|
464
|
-
lastMirroredUiSelectionKey = '';
|
|
465
|
-
suppressing = true;
|
|
466
|
-
try {
|
|
467
|
-
uiStore.select([]);
|
|
468
|
-
} finally {
|
|
469
|
-
suppressing = false;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
layer.style.display = isWorldHidden(worldId) ? 'none' : 'block';
|
|
475
|
-
layer.style.pointerEvents = isWorldInteractive(worldId) ? 'auto' : 'none';
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
return () => {
|
|
479
|
-
unsubUI();
|
|
480
|
-
unsubStore();
|
|
481
|
-
uiAdapter.detachPickSurface();
|
|
482
|
-
root.unmount();
|
|
483
|
-
layer.remove();
|
|
484
|
-
};
|
|
485
|
-
}
|