@dreamboard-games/ui-sdk 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +89 -0
- package/NOTICE +1 -0
- package/README.md +154 -0
- package/dist/components/ActionButton.d.ts +13 -0
- package/dist/components/ActionButton.d.ts.map +1 -0
- package/dist/components/ActionButton.js +14 -0
- package/dist/components/ActionPanel.d.ts +33 -0
- package/dist/components/ActionPanel.d.ts.map +1 -0
- package/dist/components/ActionPanel.js +148 -0
- package/dist/components/Card.d.ts +29 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +220 -0
- package/dist/components/ChromeSuppressionContext.d.ts +7 -0
- package/dist/components/ChromeSuppressionContext.d.ts.map +1 -0
- package/dist/components/ChromeSuppressionContext.js +34 -0
- package/dist/components/CostDisplay.d.ts +22 -0
- package/dist/components/CostDisplay.d.ts.map +1 -0
- package/dist/components/CostDisplay.js +41 -0
- package/dist/components/DiceRoller.d.ts +30 -0
- package/dist/components/DiceRoller.d.ts.map +1 -0
- package/dist/components/DiceRoller.js +319 -0
- package/dist/components/Drawer.d.ts +19 -0
- package/dist/components/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer.js +55 -0
- package/dist/components/ErrorBoundary.d.ts +24 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +37 -0
- package/dist/components/GameEndDisplay.d.ts +27 -0
- package/dist/components/GameEndDisplay.d.ts.map +1 -0
- package/dist/components/GameEndDisplay.js +185 -0
- package/dist/components/GameSkeleton.d.ts +12 -0
- package/dist/components/GameSkeleton.d.ts.map +1 -0
- package/dist/components/GameSkeleton.js +54 -0
- package/dist/components/Hand.d.ts +99 -0
- package/dist/components/Hand.d.ts.map +1 -0
- package/dist/components/Hand.js +162 -0
- package/dist/components/HandDock.d.ts +35 -0
- package/dist/components/HandDock.d.ts.map +1 -0
- package/dist/components/HandDock.js +124 -0
- package/dist/components/InteractionForm.d.ts +50 -0
- package/dist/components/InteractionForm.d.ts.map +1 -0
- package/dist/components/InteractionForm.js +402 -0
- package/dist/components/MoreActions.d.ts +49 -0
- package/dist/components/MoreActions.d.ts.map +1 -0
- package/dist/components/MoreActions.js +64 -0
- package/dist/components/PhaseIndicator.d.ts +35 -0
- package/dist/components/PhaseIndicator.d.ts.map +1 -0
- package/dist/components/PhaseIndicator.js +212 -0
- package/dist/components/PlayArea.d.ts +28 -0
- package/dist/components/PlayArea.d.ts.map +1 -0
- package/dist/components/PlayArea.js +48 -0
- package/dist/components/PluginRuntime.d.ts +37 -0
- package/dist/components/PluginRuntime.d.ts.map +1 -0
- package/dist/components/PluginRuntime.js +47 -0
- package/dist/components/PrimaryActionButton.d.ts +98 -0
- package/dist/components/PrimaryActionButton.d.ts.map +1 -0
- package/dist/components/PrimaryActionButton.js +183 -0
- package/dist/components/PrimaryButton.d.ts +20 -0
- package/dist/components/PrimaryButton.d.ts.map +1 -0
- package/dist/components/PrimaryButton.js +5 -0
- package/dist/components/PromptDialogHost.d.ts +15 -0
- package/dist/components/PromptDialogHost.d.ts.map +1 -0
- package/dist/components/PromptDialogHost.js +22 -0
- package/dist/components/ResourceCounter.d.ts +38 -0
- package/dist/components/ResourceCounter.d.ts.map +1 -0
- package/dist/components/ResourceCounter.js +118 -0
- package/dist/components/ThemedButton.d.ts +12 -0
- package/dist/components/ThemedButton.d.ts.map +1 -0
- package/dist/components/ThemedButton.js +38 -0
- package/dist/components/Toast.d.ts +35 -0
- package/dist/components/Toast.d.ts.map +1 -0
- package/dist/components/Toast.js +116 -0
- package/dist/components/board/HexGrid.d.ts +344 -0
- package/dist/components/board/HexGrid.d.ts.map +1 -0
- package/dist/components/board/HexGrid.js +340 -0
- package/dist/components/board/NetworkGraph.d.ts +100 -0
- package/dist/components/board/NetworkGraph.d.ts.map +1 -0
- package/dist/components/board/NetworkGraph.js +123 -0
- package/dist/components/board/SlotSystem.d.ts +71 -0
- package/dist/components/board/SlotSystem.d.ts.map +1 -0
- package/dist/components/board/SlotSystem.js +87 -0
- package/dist/components/board/SquareGrid.d.ts +188 -0
- package/dist/components/board/SquareGrid.d.ts.map +1 -0
- package/dist/components/board/SquareGrid.js +328 -0
- package/dist/components/board/TrackBoard.d.ts +113 -0
- package/dist/components/board/TrackBoard.d.ts.map +1 -0
- package/dist/components/board/TrackBoard.js +135 -0
- package/dist/components/board/ZoneMap.d.ts +88 -0
- package/dist/components/board/ZoneMap.d.ts.map +1 -0
- package/dist/components/board/ZoneMap.js +133 -0
- package/dist/components/board/hex-board-view.d.ts +69 -0
- package/dist/components/board/hex-board-view.d.ts.map +1 -0
- package/dist/components/board/hex-board-view.js +60 -0
- package/dist/components/board/index.d.ts +23 -0
- package/dist/components/board/index.d.ts.map +1 -0
- package/dist/components/board/index.js +40 -0
- package/dist/components/board/interaction-accessibility.d.ts +5 -0
- package/dist/components/board/interaction-accessibility.d.ts.map +1 -0
- package/dist/components/board/interaction-accessibility.js +13 -0
- package/dist/components/board/target-layer.d.ts +13 -0
- package/dist/components/board/target-layer.d.ts.map +1 -0
- package/dist/components/board/target-layer.js +10 -0
- package/dist/components/card-render-content.type-test.d.ts +2 -0
- package/dist/components/card-render-content.type-test.d.ts.map +1 -0
- package/dist/components/card-render-content.type-test.js +1 -0
- package/dist/components/index.d.ts +34 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +35 -0
- package/dist/components/interaction-dialog-behavior.d.ts +15 -0
- package/dist/components/interaction-dialog-behavior.d.ts.map +1 -0
- package/dist/components/interaction-dialog-behavior.js +9 -0
- package/dist/components/surfaces/BlockerSurface.d.ts +27 -0
- package/dist/components/surfaces/BlockerSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BlockerSurface.js +38 -0
- package/dist/components/surfaces/BoardSurface.d.ts +77 -0
- package/dist/components/surfaces/BoardSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BoardSurface.js +180 -0
- package/dist/components/surfaces/ChromeSurface.d.ts +29 -0
- package/dist/components/surfaces/ChromeSurface.d.ts.map +1 -0
- package/dist/components/surfaces/ChromeSurface.js +34 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts +32 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts.map +1 -0
- package/dist/components/surfaces/ExhaustivenessAudit.js +65 -0
- package/dist/components/surfaces/InboxSurface.d.ts +40 -0
- package/dist/components/surfaces/InboxSurface.d.ts.map +1 -0
- package/dist/components/surfaces/InboxSurface.js +99 -0
- package/dist/components/surfaces/MarketSurface.d.ts +62 -0
- package/dist/components/surfaces/MarketSurface.d.ts.map +1 -0
- package/dist/components/surfaces/MarketSurface.js +242 -0
- package/dist/components/surfaces/PanelSurface.d.ts +111 -0
- package/dist/components/surfaces/PanelSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PanelSurface.js +180 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts +104 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PlayerCardsSurface.js +178 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts +7 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts.map +1 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.js +9 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts +71 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts.map +1 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.js +82 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts +21 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts.map +1 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.js +202 -0
- package/dist/components/surfaces/types.d.ts +59 -0
- package/dist/components/surfaces/types.d.ts.map +1 -0
- package/dist/components/surfaces/types.js +1 -0
- package/dist/context/ClientParamSchemaContext.d.ts +21 -0
- package/dist/context/ClientParamSchemaContext.d.ts.map +1 -0
- package/dist/context/ClientParamSchemaContext.js +12 -0
- package/dist/context/InteractionDraftContext.d.ts +69 -0
- package/dist/context/InteractionDraftContext.d.ts.map +1 -0
- package/dist/context/InteractionDraftContext.js +145 -0
- package/dist/context/PluginSessionContext.d.ts +33 -0
- package/dist/context/PluginSessionContext.d.ts.map +1 -0
- package/dist/context/PluginSessionContext.js +38 -0
- package/dist/context/PluginStateContext.d.ts +116 -0
- package/dist/context/PluginStateContext.d.ts.map +1 -0
- package/dist/context/PluginStateContext.js +186 -0
- package/dist/context/RuntimeContext.d.ts +49 -0
- package/dist/context/RuntimeContext.d.ts.map +1 -0
- package/dist/context/RuntimeContext.js +67 -0
- package/dist/defaults/components.d.ts +52 -0
- package/dist/defaults/components.d.ts.map +1 -0
- package/dist/defaults/components.js +159 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/defaults/index.js +1 -0
- package/dist/errors/ValidationError.d.ts +10 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +23 -0
- package/dist/helpers/cards.d.ts +3 -0
- package/dist/helpers/cards.d.ts.map +1 -0
- package/dist/helpers/cards.js +11 -0
- package/dist/helpers/track-board.d.ts +79 -0
- package/dist/helpers/track-board.d.ts.map +1 -0
- package/dist/helpers/track-board.js +56 -0
- package/dist/hooks/useActivePlayers.d.ts +16 -0
- package/dist/hooks/useActivePlayers.d.ts.map +1 -0
- package/dist/hooks/useActivePlayers.js +17 -0
- package/dist/hooks/useBoardInteractions.d.ts +110 -0
- package/dist/hooks/useBoardInteractions.d.ts.map +1 -0
- package/dist/hooks/useBoardInteractions.js +248 -0
- package/dist/hooks/useBoardTopology.d.ts +23 -0
- package/dist/hooks/useBoardTopology.d.ts.map +1 -0
- package/dist/hooks/useBoardTopology.js +128 -0
- package/dist/hooks/useCards.d.ts +3 -0
- package/dist/hooks/useCards.d.ts.map +1 -0
- package/dist/hooks/useCards.js +5 -0
- package/dist/hooks/useGameSelector.d.ts +13 -0
- package/dist/hooks/useGameSelector.d.ts.map +1 -0
- package/dist/hooks/useGameSelector.js +67 -0
- package/dist/hooks/useGameView.d.ts +6 -0
- package/dist/hooks/useGameView.d.ts.map +1 -0
- package/dist/hooks/useGameView.js +7 -0
- package/dist/hooks/useHandLayout.d.ts +120 -0
- package/dist/hooks/useHandLayout.d.ts.map +1 -0
- package/dist/hooks/useHandLayout.js +235 -0
- package/dist/hooks/useHexBoard.d.ts +19 -0
- package/dist/hooks/useHexBoard.d.ts.map +1 -0
- package/dist/hooks/useHexBoard.js +28 -0
- package/dist/hooks/useHexGrid.d.ts +56 -0
- package/dist/hooks/useHexGrid.d.ts.map +1 -0
- package/dist/hooks/useHexGrid.js +112 -0
- package/dist/hooks/useInteractionByKey.d.ts +29 -0
- package/dist/hooks/useInteractionByKey.d.ts.map +1 -0
- package/dist/hooks/useInteractionByKey.js +263 -0
- package/dist/hooks/useInteractionHandle.d.ts +103 -0
- package/dist/hooks/useInteractionHandle.d.ts.map +1 -0
- package/dist/hooks/useInteractionHandle.js +254 -0
- package/dist/hooks/useIsMobile.d.ts +7 -0
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.js +29 -0
- package/dist/hooks/useIsMyTurn.d.ts +6 -0
- package/dist/hooks/useIsMyTurn.d.ts.map +1 -0
- package/dist/hooks/useIsMyTurn.js +11 -0
- package/dist/hooks/useLobby.d.ts +28 -0
- package/dist/hooks/useLobby.d.ts.map +1 -0
- package/dist/hooks/useLobby.js +60 -0
- package/dist/hooks/useMe.d.ts +11 -0
- package/dist/hooks/useMe.d.ts.map +1 -0
- package/dist/hooks/useMe.js +32 -0
- package/dist/hooks/usePanZoom.d.ts +113 -0
- package/dist/hooks/usePanZoom.d.ts.map +1 -0
- package/dist/hooks/usePanZoom.js +165 -0
- package/dist/hooks/usePlayerInfo.d.ts +4 -0
- package/dist/hooks/usePlayerInfo.d.ts.map +1 -0
- package/dist/hooks/usePlayerInfo.js +21 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts +15 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts.map +1 -0
- package/dist/hooks/usePlayerTurnOrder.js +22 -0
- package/dist/hooks/usePluginRuntime.d.ts +45 -0
- package/dist/hooks/usePluginRuntime.d.ts.map +1 -0
- package/dist/hooks/usePluginRuntime.js +92 -0
- package/dist/hooks/useSeatInbox.d.ts +22 -0
- package/dist/hooks/useSeatInbox.d.ts.map +1 -0
- package/dist/hooks/useSeatInbox.js +43 -0
- package/dist/hooks/useSimultaneousPhase.d.ts +7 -0
- package/dist/hooks/useSimultaneousPhase.d.ts.map +1 -0
- package/dist/hooks/useSimultaneousPhase.js +8 -0
- package/dist/hooks/useSquareBoard.d.ts +21 -0
- package/dist/hooks/useSquareBoard.d.ts.map +1 -0
- package/dist/hooks/useSquareBoard.js +67 -0
- package/dist/hooks/useSquareGrid.d.ts +96 -0
- package/dist/hooks/useSquareGrid.d.ts.map +1 -0
- package/dist/hooks/useSquareGrid.js +152 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/internal/ui/alert.d.ts +8 -0
- package/dist/internal/ui/alert.d.ts.map +1 -0
- package/dist/internal/ui/alert.js +11 -0
- package/dist/internal/ui/button.d.ts +10 -0
- package/dist/internal/ui/button.d.ts.map +1 -0
- package/dist/internal/ui/button.js +21 -0
- package/dist/internal/ui/dialog.d.ts +16 -0
- package/dist/internal/ui/dialog.d.ts.map +1 -0
- package/dist/internal/ui/dialog.js +35 -0
- package/dist/internal/ui/input.d.ts +3 -0
- package/dist/internal/ui/input.d.ts.map +1 -0
- package/dist/internal/ui/input.js +5 -0
- package/dist/internal/ui/label.d.ts +4 -0
- package/dist/internal/ui/label.d.ts.map +1 -0
- package/dist/internal/ui/label.js +7 -0
- package/dist/internal/ui/select.d.ts +9 -0
- package/dist/internal/ui/select.d.ts.map +1 -0
- package/dist/internal/ui/select.js +23 -0
- package/dist/internal/ui/tooltip.d.ts +7 -0
- package/dist/internal/ui/tooltip.d.ts.map +1 -0
- package/dist/internal/ui/tooltip.js +16 -0
- package/dist/internal/ui/utils.d.ts +3 -0
- package/dist/internal/ui/utils.d.ts.map +1 -0
- package/dist/internal/ui/utils.js +4 -0
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/plugin-styles.css +246 -0
- package/dist/primitives/board.d.ts +29 -0
- package/dist/primitives/board.d.ts.map +1 -0
- package/dist/primitives/board.js +163 -0
- package/dist/primitives/game-ui-provider.d.ts +12 -0
- package/dist/primitives/game-ui-provider.d.ts.map +1 -0
- package/dist/primitives/game-ui-provider.js +7 -0
- package/dist/primitives/index.d.ts +8 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +7 -0
- package/dist/primitives/interaction.d.ts +52 -0
- package/dist/primitives/interaction.d.ts.map +1 -0
- package/dist/primitives/interaction.js +250 -0
- package/dist/primitives/phase.d.ts +15 -0
- package/dist/primitives/phase.d.ts.map +1 -0
- package/dist/primitives/phase.js +18 -0
- package/dist/primitives/player-roster.d.ts +64 -0
- package/dist/primitives/player-roster.d.ts.map +1 -0
- package/dist/primitives/player-roster.js +149 -0
- package/dist/primitives/primitive-props.d.ts +15 -0
- package/dist/primitives/primitive-props.d.ts.map +1 -0
- package/dist/primitives/primitive-props.js +39 -0
- package/dist/primitives/prompt.d.ts +44 -0
- package/dist/primitives/prompt.d.ts.map +1 -0
- package/dist/primitives/prompt.js +101 -0
- package/dist/primitives/zone.d.ts +31 -0
- package/dist/primitives/zone.d.ts.map +1 -0
- package/dist/primitives/zone.js +58 -0
- package/dist/reducer.d.ts +21 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +14 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts +67 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts.map +1 -0
- package/dist/runtime/createPluginRuntimeAPI.js +419 -0
- package/dist/theme/ThemeProvider.d.ts +98 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +148 -0
- package/dist/theme/board.d.ts +42 -0
- package/dist/theme/board.d.ts.map +1 -0
- package/dist/theme/board.js +34 -0
- package/dist/theme/css-vars.d.ts +31 -0
- package/dist/theme/css-vars.d.ts.map +1 -0
- package/dist/theme/css-vars.js +88 -0
- package/dist/theme/derive.d.ts +66 -0
- package/dist/theme/derive.d.ts.map +1 -0
- package/dist/theme/derive.js +161 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/presets/arcade.d.ts +10 -0
- package/dist/theme/presets/arcade.d.ts.map +1 -0
- package/dist/theme/presets/arcade.js +257 -0
- package/dist/theme/presets/studio.d.ts +10 -0
- package/dist/theme/presets/studio.d.ts.map +1 -0
- package/dist/theme/presets/studio.js +257 -0
- package/dist/theme/presets/tabletop.d.ts +15 -0
- package/dist/theme/presets/tabletop.d.ts.map +1 -0
- package/dist/theme/presets/tabletop.js +262 -0
- package/dist/theme/tokens.d.ts +345 -0
- package/dist/theme/tokens.d.ts.map +1 -0
- package/dist/theme/tokens.js +57 -0
- package/dist/types/player-state.d.ts +337 -0
- package/dist/types/player-state.d.ts.map +1 -0
- package/dist/types/player-state.js +1 -0
- package/dist/types/plugin-state.d.ts +324 -0
- package/dist/types/plugin-state.d.ts.map +1 -0
- package/dist/types/plugin-state.js +1 -0
- package/dist/types/reducer-state.d.ts +10 -0
- package/dist/types/reducer-state.d.ts.map +1 -0
- package/dist/types/reducer-state.js +1 -0
- package/dist/types/runtime-api.d.ts +99 -0
- package/dist/types/runtime-api.d.ts.map +1 -0
- package/dist/types/runtime-api.js +1 -0
- package/dist/types/tiled-board.d.ts +187 -0
- package/dist/types/tiled-board.d.ts.map +1 -0
- package/dist/types/tiled-board.js +226 -0
- package/dist/ui-contract.d.ts +78 -0
- package/dist/ui-contract.d.ts.map +1 -0
- package/dist/ui-contract.js +15 -0
- package/dist/ui-sdk.d.ts +3409 -0
- package/dist/utils/interaction-inputs.d.ts +22 -0
- package/dist/utils/interaction-inputs.d.ts.map +1 -0
- package/dist/utils/interaction-inputs.js +219 -0
- package/dist/utils/interaction-labels.d.ts +4 -0
- package/dist/utils/interaction-labels.d.ts.map +1 -0
- package/dist/utils/interaction-labels.js +18 -0
- package/dist/utils/interaction-status.d.ts +15 -0
- package/dist/utils/interaction-status.d.ts.map +1 -0
- package/dist/utils/interaction-status.js +31 -0
- package/package.json +101 -0
- package/src/components/ActionButton.tsx +48 -0
- package/src/components/ActionPanel.tsx +310 -0
- package/src/components/Card.tsx +385 -0
- package/src/components/ChromeSuppressionContext.tsx +70 -0
- package/src/components/CostDisplay.test.tsx +23 -0
- package/src/components/CostDisplay.tsx +145 -0
- package/src/components/DiceRoller.tsx +601 -0
- package/src/components/Drawer.tsx +179 -0
- package/src/components/ErrorBoundary.tsx +119 -0
- package/src/components/GameEndDisplay.test.tsx +19 -0
- package/src/components/GameEndDisplay.tsx +398 -0
- package/src/components/GameSkeleton.tsx +260 -0
- package/src/components/Hand.tsx +387 -0
- package/src/components/HandDock.tsx +257 -0
- package/src/components/InteractionForm.test.tsx +303 -0
- package/src/components/InteractionForm.tsx +1029 -0
- package/src/components/MoreActions.test.tsx +93 -0
- package/src/components/MoreActions.tsx +143 -0
- package/src/components/PhaseIndicator.tsx +341 -0
- package/src/components/PlayArea.tsx +125 -0
- package/src/components/PluginRuntime.tsx +92 -0
- package/src/components/PrimaryActionButton.test.tsx +138 -0
- package/src/components/PrimaryActionButton.tsx +351 -0
- package/src/components/PrimaryButton.tsx +44 -0
- package/src/components/PromptDialogHost.tsx +92 -0
- package/src/components/ResourceCounter.test.tsx +29 -0
- package/src/components/ResourceCounter.tsx +275 -0
- package/src/components/ThemedButton.tsx +78 -0
- package/src/components/Toast.tsx +251 -0
- package/src/components/__fixtures__/ActionButton.fixture.tsx +234 -0
- package/src/components/__fixtures__/ActionPanel.fixture.tsx +298 -0
- package/src/components/__fixtures__/Card.fixture.tsx +185 -0
- package/src/components/__fixtures__/CostDisplay.fixture.tsx +156 -0
- package/src/components/__fixtures__/DiceRoller.fixture.tsx +435 -0
- package/src/components/__fixtures__/Drawer.fixture.tsx +113 -0
- package/src/components/__fixtures__/ErrorBoundary.fixture.tsx +82 -0
- package/src/components/__fixtures__/GameEndDisplay.fixture.tsx +188 -0
- package/src/components/__fixtures__/GameSkeleton.fixture.tsx +46 -0
- package/src/components/__fixtures__/Hand.fixture.tsx +522 -0
- package/src/components/__fixtures__/HexGrid.fixture.tsx +1181 -0
- package/src/components/__fixtures__/NetworkGraph.fixture.tsx +599 -0
- package/src/components/__fixtures__/PhaseIndicator.fixture.tsx +181 -0
- package/src/components/__fixtures__/PlayArea.fixture.tsx +221 -0
- package/src/components/__fixtures__/ResourceCounter.fixture.tsx +227 -0
- package/src/components/__fixtures__/SlotSystem.fixture.tsx +824 -0
- package/src/components/__fixtures__/SquareGrid.fixture.tsx +764 -0
- package/src/components/__fixtures__/Toast.fixture.tsx +97 -0
- package/src/components/__fixtures__/TrackBoard.fixture.tsx +685 -0
- package/src/components/__fixtures__/ZoneMap.fixture.tsx +754 -0
- package/src/components/board/HexGrid.tsx +1294 -0
- package/src/components/board/NetworkGraph.tsx +476 -0
- package/src/components/board/SlotSystem.tsx +339 -0
- package/src/components/board/SquareGrid.tsx +1165 -0
- package/src/components/board/TrackBoard.tsx +496 -0
- package/src/components/board/ZoneMap.tsx +448 -0
- package/src/components/board/hex-board-view.test.tsx +114 -0
- package/src/components/board/hex-board-view.ts +123 -0
- package/src/components/board/index.ts +142 -0
- package/src/components/board/interaction-accessibility.ts +21 -0
- package/src/components/board/target-layer-grids.test.tsx +420 -0
- package/src/components/board/target-layer.ts +30 -0
- package/src/components/card-render-content.type-test.ts +27 -0
- package/src/components/index.ts +208 -0
- package/src/components/interaction-dialog-behavior.test.ts +23 -0
- package/src/components/interaction-dialog-behavior.ts +22 -0
- package/src/components/surfaces/BlockerSurface.test.tsx +158 -0
- package/src/components/surfaces/BlockerSurface.tsx +127 -0
- package/src/components/surfaces/BoardSurface.tsx +340 -0
- package/src/components/surfaces/ChromeSurface.tsx +123 -0
- package/src/components/surfaces/ExhaustivenessAudit.tsx +91 -0
- package/src/components/surfaces/InboxSurface.test.tsx +149 -0
- package/src/components/surfaces/InboxSurface.tsx +245 -0
- package/src/components/surfaces/MarketSurface.tsx +544 -0
- package/src/components/surfaces/PanelSurface.test.tsx +496 -0
- package/src/components/surfaces/PanelSurface.tsx +458 -0
- package/src/components/surfaces/PlayerCardsSurface.tsx +525 -0
- package/src/components/surfaces/internal/CardZoneFollowUpForm.tsx +35 -0
- package/src/components/surfaces/internal/DefaultInteractionButton.tsx +219 -0
- package/src/components/surfaces/internal/useCardZoneInteractions.ts +311 -0
- package/src/components/surfaces/types.ts +100 -0
- package/src/context/ClientParamSchemaContext.tsx +44 -0
- package/src/context/InteractionDraftContext.tsx +204 -0
- package/src/context/PluginSessionContext.tsx +47 -0
- package/src/context/PluginStateContext.tsx +254 -0
- package/src/context/RuntimeContext.tsx +96 -0
- package/src/defaults/components.tsx +442 -0
- package/src/defaults/defaults.test.tsx +230 -0
- package/src/defaults/index.ts +1 -0
- package/src/errors/ValidationError.ts +29 -0
- package/src/helpers/cards.ts +19 -0
- package/src/helpers/track-board.ts +211 -0
- package/src/hooks/useActivePlayers.ts +19 -0
- package/src/hooks/useBoardInteractions.test.tsx +622 -0
- package/src/hooks/useBoardInteractions.ts +434 -0
- package/src/hooks/useBoardTopology.ts +316 -0
- package/src/hooks/useCards.test.tsx +129 -0
- package/src/hooks/useCards.ts +10 -0
- package/src/hooks/useGameSelector.ts +105 -0
- package/src/hooks/useGameView.ts +9 -0
- package/src/hooks/useHandLayout.ts +349 -0
- package/src/hooks/useHexBoard.ts +74 -0
- package/src/hooks/useHexGrid.ts +185 -0
- package/src/hooks/useInteractionByKey.ts +349 -0
- package/src/hooks/useInteractionHandle.ts +437 -0
- package/src/hooks/useIsMobile.ts +35 -0
- package/src/hooks/useIsMyTurn.test.tsx +99 -0
- package/src/hooks/useIsMyTurn.ts +15 -0
- package/src/hooks/useLobby.ts +76 -0
- package/src/hooks/useMe.ts +48 -0
- package/src/hooks/usePanZoom.ts +278 -0
- package/src/hooks/usePlayerInfo.ts +28 -0
- package/src/hooks/usePlayerTurnOrder.ts +23 -0
- package/src/hooks/usePluginRuntime.test.tsx +102 -0
- package/src/hooks/usePluginRuntime.ts +130 -0
- package/src/hooks/useSeatInbox.ts +61 -0
- package/src/hooks/useSimultaneousPhase.ts +10 -0
- package/src/hooks/useSquareBoard.ts +124 -0
- package/src/hooks/useSquareGrid.ts +328 -0
- package/src/index.test.ts +474 -0
- package/src/index.ts +148 -0
- package/src/internal/ui/alert.tsx +51 -0
- package/src/internal/ui/button.tsx +58 -0
- package/src/internal/ui/dialog.tsx +134 -0
- package/src/internal/ui/input.tsx +21 -0
- package/src/internal/ui/label.tsx +21 -0
- package/src/internal/ui/select.tsx +129 -0
- package/src/internal/ui/tooltip.tsx +54 -0
- package/src/internal/ui/utils.ts +5 -0
- package/src/internal.ts +18 -0
- package/src/plugin-styles.css +246 -0
- package/src/primitives/board.test.tsx +139 -0
- package/src/primitives/board.tsx +267 -0
- package/src/primitives/game-ui-provider.tsx +35 -0
- package/src/primitives/index.ts +83 -0
- package/src/primitives/interaction.test.tsx +420 -0
- package/src/primitives/interaction.tsx +405 -0
- package/src/primitives/phase.test.tsx +82 -0
- package/src/primitives/phase.tsx +43 -0
- package/src/primitives/player-roster.test.tsx +168 -0
- package/src/primitives/player-roster.tsx +301 -0
- package/src/primitives/primitive-props.tsx +82 -0
- package/src/primitives/prompt.test.tsx +159 -0
- package/src/primitives/prompt.tsx +203 -0
- package/src/primitives/zone.tsx +113 -0
- package/src/reducer.ts +42 -0
- package/src/runtime/createPluginRuntimeAPI.ts +605 -0
- package/src/theme/ThemeProvider.test.tsx +36 -0
- package/src/theme/ThemeProvider.tsx +252 -0
- package/src/theme/board.ts +61 -0
- package/src/theme/css-vars.ts +105 -0
- package/src/theme/derive.ts +240 -0
- package/src/theme/index.ts +61 -0
- package/src/theme/presets/arcade.ts +261 -0
- package/src/theme/presets/studio.ts +261 -0
- package/src/theme/presets/tabletop.ts +266 -0
- package/src/theme/theme.test.ts +258 -0
- package/src/theme/tokens.ts +392 -0
- package/src/types/player-state.ts +445 -0
- package/src/types/plugin-state.ts +407 -0
- package/src/types/reducer-state.ts +24 -0
- package/src/types/runtime-api.ts +114 -0
- package/src/types/tiled-board.ts +785 -0
- package/src/ui-contract.ts +168 -0
- package/src/utils/interaction-inputs.test.ts +109 -0
- package/src/utils/interaction-inputs.ts +331 -0
- package/src/utils/interaction-labels.ts +23 -0
- package/src/utils/interaction-status.ts +59 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG-based area control visualization for territory games (Risk, Small World, Diplomacy).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useMemo, type ReactNode } from "react";
|
|
6
|
+
import { clsx } from "clsx";
|
|
7
|
+
import { usePanZoom } from "../../hooks/usePanZoom.js";
|
|
8
|
+
import { handleKeyboardActivation } from "./interaction-accessibility.js";
|
|
9
|
+
|
|
10
|
+
export interface ZoneShape {
|
|
11
|
+
type: "polygon" | "path" | "circle";
|
|
12
|
+
points?: Array<{ x: number; y: number }>;
|
|
13
|
+
/** SVG path data */
|
|
14
|
+
path?: string;
|
|
15
|
+
center?: { x: number; y: number };
|
|
16
|
+
radius?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ZoneDefinition {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
adjacentTo: string[];
|
|
23
|
+
shape?: ZoneShape;
|
|
24
|
+
value?: number;
|
|
25
|
+
type?: string;
|
|
26
|
+
data?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ZonePiece {
|
|
30
|
+
id: string;
|
|
31
|
+
zoneId: string;
|
|
32
|
+
type: string;
|
|
33
|
+
owner?: string;
|
|
34
|
+
/** Count for stackable pieces (armies) */
|
|
35
|
+
count?: number;
|
|
36
|
+
data?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ZoneMapProps {
|
|
40
|
+
zones: ZoneDefinition[];
|
|
41
|
+
pieces: ZonePiece[];
|
|
42
|
+
renderZone: (zone: ZoneDefinition, pieces: ZonePiece[]) => ReactNode;
|
|
43
|
+
backgroundImage?: string;
|
|
44
|
+
width?: number | string;
|
|
45
|
+
height?: number | string;
|
|
46
|
+
enablePanZoom?: boolean;
|
|
47
|
+
initialZoom?: number;
|
|
48
|
+
minZoom?: number;
|
|
49
|
+
maxZoom?: number;
|
|
50
|
+
className?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Helper Components
|
|
55
|
+
// ============================================================================
|
|
56
|
+
|
|
57
|
+
export type ZoneHighlightType =
|
|
58
|
+
| "valid"
|
|
59
|
+
| "selected"
|
|
60
|
+
| "attack"
|
|
61
|
+
| "defend"
|
|
62
|
+
| "neutral";
|
|
63
|
+
|
|
64
|
+
// Highlight colors by type
|
|
65
|
+
const HIGHLIGHT_COLORS: Record<ZoneHighlightType, string> = {
|
|
66
|
+
valid: "rgba(34, 197, 94, 0.4)", // Green
|
|
67
|
+
selected: "rgba(59, 130, 246, 0.4)", // Blue
|
|
68
|
+
attack: "rgba(239, 68, 68, 0.4)", // Red
|
|
69
|
+
defend: "rgba(234, 179, 8, 0.4)", // Yellow
|
|
70
|
+
neutral: "rgba(148, 163, 184, 0.4)", // Slate
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const HIGHLIGHT_STROKES: Record<ZoneHighlightType, string> = {
|
|
74
|
+
valid: "#22c55e",
|
|
75
|
+
selected: "#3b82f6",
|
|
76
|
+
attack: "#ef4444",
|
|
77
|
+
defend: "#eab308",
|
|
78
|
+
neutral: "#94a3b8",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const EMPTY_PLAYER_COLORS: Record<string, string> = {};
|
|
82
|
+
|
|
83
|
+
export interface DefaultZoneProps {
|
|
84
|
+
zone: ZoneDefinition;
|
|
85
|
+
fill?: string;
|
|
86
|
+
stroke?: string;
|
|
87
|
+
strokeWidth?: number;
|
|
88
|
+
isHighlighted?: boolean;
|
|
89
|
+
highlightType?: ZoneHighlightType;
|
|
90
|
+
isSelected?: boolean;
|
|
91
|
+
showLabel?: boolean;
|
|
92
|
+
showValue?: boolean;
|
|
93
|
+
onClick?: () => void;
|
|
94
|
+
onHover?: (hovering: boolean) => void;
|
|
95
|
+
className?: string;
|
|
96
|
+
children?: ReactNode;
|
|
97
|
+
}
|
|
98
|
+
export function DefaultZone({
|
|
99
|
+
zone,
|
|
100
|
+
fill = "rgba(100, 116, 139, 0.2)",
|
|
101
|
+
stroke = "#475569",
|
|
102
|
+
strokeWidth = 1,
|
|
103
|
+
isHighlighted = false,
|
|
104
|
+
highlightType,
|
|
105
|
+
isSelected = false,
|
|
106
|
+
showLabel = true,
|
|
107
|
+
showValue = false,
|
|
108
|
+
onClick,
|
|
109
|
+
onHover,
|
|
110
|
+
className,
|
|
111
|
+
children,
|
|
112
|
+
}: DefaultZoneProps) {
|
|
113
|
+
// Calculate colors based on state
|
|
114
|
+
let computedFill = fill;
|
|
115
|
+
let computedStroke = stroke;
|
|
116
|
+
let computedStrokeWidth = strokeWidth;
|
|
117
|
+
|
|
118
|
+
if (isHighlighted && highlightType && HIGHLIGHT_COLORS[highlightType]) {
|
|
119
|
+
computedFill = HIGHLIGHT_COLORS[highlightType];
|
|
120
|
+
computedStroke = HIGHLIGHT_STROKES[highlightType];
|
|
121
|
+
computedStrokeWidth = 3;
|
|
122
|
+
} else if (isSelected) {
|
|
123
|
+
computedFill = HIGHLIGHT_COLORS.selected;
|
|
124
|
+
computedStroke = HIGHLIGHT_STROKES.selected;
|
|
125
|
+
computedStrokeWidth = 3;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Render zone shape
|
|
129
|
+
const renderShape = () => {
|
|
130
|
+
if (!zone.shape) return null;
|
|
131
|
+
|
|
132
|
+
switch (zone.shape.type) {
|
|
133
|
+
case "polygon":
|
|
134
|
+
if (!zone.shape.points) return null;
|
|
135
|
+
return (
|
|
136
|
+
<polygon
|
|
137
|
+
points={zone.shape.points.map((p) => `${p.x},${p.y}`).join(" ")}
|
|
138
|
+
fill={computedFill}
|
|
139
|
+
stroke={computedStroke}
|
|
140
|
+
strokeWidth={computedStrokeWidth}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
case "path":
|
|
145
|
+
if (!zone.shape.path) return null;
|
|
146
|
+
return (
|
|
147
|
+
<path
|
|
148
|
+
d={zone.shape.path}
|
|
149
|
+
fill={computedFill}
|
|
150
|
+
stroke={computedStroke}
|
|
151
|
+
strokeWidth={computedStrokeWidth}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
case "circle":
|
|
156
|
+
if (!zone.shape.center) return null;
|
|
157
|
+
return (
|
|
158
|
+
<circle
|
|
159
|
+
cx={zone.shape.center.x}
|
|
160
|
+
cy={zone.shape.center.y}
|
|
161
|
+
r={zone.shape.radius || 30}
|
|
162
|
+
fill={computedFill}
|
|
163
|
+
stroke={computedStroke}
|
|
164
|
+
strokeWidth={computedStrokeWidth}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
default:
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<g
|
|
175
|
+
onClick={onClick}
|
|
176
|
+
onMouseEnter={() => onHover?.(true)}
|
|
177
|
+
onMouseLeave={() => onHover?.(false)}
|
|
178
|
+
onKeyDown={(event) => handleKeyboardActivation(event, onClick)}
|
|
179
|
+
className={clsx(onClick && "cursor-pointer", className)}
|
|
180
|
+
role={onClick ? "button" : "listitem"}
|
|
181
|
+
aria-label={zone.name}
|
|
182
|
+
tabIndex={onClick ? 0 : undefined}
|
|
183
|
+
>
|
|
184
|
+
{/* Zone shape */}
|
|
185
|
+
{renderShape()}
|
|
186
|
+
|
|
187
|
+
{/* Zone label */}
|
|
188
|
+
{showLabel && zone.shape?.center && (
|
|
189
|
+
<text
|
|
190
|
+
x={zone.shape.center.x}
|
|
191
|
+
y={zone.shape.center.y - (showValue ? 8 : 0)}
|
|
192
|
+
textAnchor="middle"
|
|
193
|
+
dominantBaseline="middle"
|
|
194
|
+
fill="white"
|
|
195
|
+
fontSize={12}
|
|
196
|
+
fontWeight="bold"
|
|
197
|
+
style={{ textShadow: "1px 1px 2px rgba(0,0,0,0.8)" }}
|
|
198
|
+
>
|
|
199
|
+
{zone.name}
|
|
200
|
+
</text>
|
|
201
|
+
)}
|
|
202
|
+
|
|
203
|
+
{/* Zone value */}
|
|
204
|
+
{showValue && zone.value !== undefined && zone.shape?.center && (
|
|
205
|
+
<text
|
|
206
|
+
x={zone.shape.center.x}
|
|
207
|
+
y={zone.shape.center.y + 8}
|
|
208
|
+
textAnchor="middle"
|
|
209
|
+
dominantBaseline="middle"
|
|
210
|
+
fill="#fbbf24"
|
|
211
|
+
fontSize={10}
|
|
212
|
+
fontWeight="bold"
|
|
213
|
+
style={{ textShadow: "1px 1px 2px rgba(0,0,0,0.8)" }}
|
|
214
|
+
>
|
|
215
|
+
+{zone.value}
|
|
216
|
+
</text>
|
|
217
|
+
)}
|
|
218
|
+
|
|
219
|
+
{/* Children (pieces) */}
|
|
220
|
+
{children}
|
|
221
|
+
</g>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface DefaultZonePiecesProps {
|
|
226
|
+
pieces: ZonePiece[];
|
|
227
|
+
zone: ZoneDefinition;
|
|
228
|
+
playerColors?: Record<string, string>;
|
|
229
|
+
radius?: number;
|
|
230
|
+
spacing?: number;
|
|
231
|
+
yOffset?: number;
|
|
232
|
+
className?: string;
|
|
233
|
+
}
|
|
234
|
+
export function DefaultZonePieces({
|
|
235
|
+
pieces,
|
|
236
|
+
zone,
|
|
237
|
+
playerColors = EMPTY_PLAYER_COLORS,
|
|
238
|
+
radius = 14,
|
|
239
|
+
spacing = 25,
|
|
240
|
+
yOffset = 20,
|
|
241
|
+
className,
|
|
242
|
+
}: DefaultZonePiecesProps) {
|
|
243
|
+
if (pieces.length === 0 || !zone.shape?.center) return null;
|
|
244
|
+
|
|
245
|
+
const centerX = zone.shape.center.x;
|
|
246
|
+
const centerY = zone.shape.center.y;
|
|
247
|
+
|
|
248
|
+
// Group pieces by owner
|
|
249
|
+
const piecesByOwner: Record<string, ZonePiece[]> = {};
|
|
250
|
+
pieces.forEach((p) => {
|
|
251
|
+
const owner = p.owner || "neutral";
|
|
252
|
+
const existing = piecesByOwner[owner];
|
|
253
|
+
if (existing) {
|
|
254
|
+
existing.push(p);
|
|
255
|
+
} else {
|
|
256
|
+
piecesByOwner[owner] = [p];
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const owners = Object.keys(piecesByOwner);
|
|
261
|
+
const startOffset = -((owners.length - 1) * spacing) / 2;
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<g className={clsx("zone-pieces", className)}>
|
|
265
|
+
{owners.map((owner, i) => {
|
|
266
|
+
const ownerPieces = piecesByOwner[owner] || [];
|
|
267
|
+
const totalCount = ownerPieces.reduce(
|
|
268
|
+
(sum, p) => sum + (p.count || 1),
|
|
269
|
+
0,
|
|
270
|
+
);
|
|
271
|
+
const offsetX = startOffset + i * spacing;
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<g
|
|
275
|
+
key={owner}
|
|
276
|
+
transform={`translate(${centerX + offsetX}, ${centerY + yOffset})`}
|
|
277
|
+
>
|
|
278
|
+
{/* Piece circle */}
|
|
279
|
+
<circle
|
|
280
|
+
r={radius}
|
|
281
|
+
fill={playerColors[owner] || "#64748b"}
|
|
282
|
+
stroke="white"
|
|
283
|
+
strokeWidth={2}
|
|
284
|
+
/>
|
|
285
|
+
{/* Count */}
|
|
286
|
+
<text
|
|
287
|
+
textAnchor="middle"
|
|
288
|
+
dominantBaseline="central"
|
|
289
|
+
fill="white"
|
|
290
|
+
fontSize={10}
|
|
291
|
+
fontWeight="bold"
|
|
292
|
+
>
|
|
293
|
+
{totalCount}
|
|
294
|
+
</text>
|
|
295
|
+
</g>
|
|
296
|
+
);
|
|
297
|
+
})}
|
|
298
|
+
</g>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface DefaultZonePieceProps {
|
|
303
|
+
piece: ZonePiece;
|
|
304
|
+
x?: number;
|
|
305
|
+
y?: number;
|
|
306
|
+
radius?: number;
|
|
307
|
+
color?: string;
|
|
308
|
+
onClick?: () => void;
|
|
309
|
+
className?: string;
|
|
310
|
+
}
|
|
311
|
+
export function DefaultZonePiece({
|
|
312
|
+
piece,
|
|
313
|
+
x = 0,
|
|
314
|
+
y = 0,
|
|
315
|
+
radius = 14,
|
|
316
|
+
color = "#64748b",
|
|
317
|
+
onClick,
|
|
318
|
+
className,
|
|
319
|
+
}: DefaultZonePieceProps) {
|
|
320
|
+
const count = piece.count || 1;
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<g
|
|
324
|
+
transform={`translate(${x}, ${y})`}
|
|
325
|
+
onClick={(e) => {
|
|
326
|
+
e.stopPropagation();
|
|
327
|
+
onClick?.();
|
|
328
|
+
}}
|
|
329
|
+
onKeyDown={(event) =>
|
|
330
|
+
handleKeyboardActivation(event, onClick, { stopPropagation: true })
|
|
331
|
+
}
|
|
332
|
+
className={clsx(onClick && "cursor-pointer", className)}
|
|
333
|
+
role={onClick ? "button" : undefined}
|
|
334
|
+
tabIndex={onClick ? 0 : undefined}
|
|
335
|
+
aria-label={`Piece ${piece.id}`}
|
|
336
|
+
>
|
|
337
|
+
<circle r={radius} fill={color} stroke="white" strokeWidth={2} />
|
|
338
|
+
<text
|
|
339
|
+
textAnchor="middle"
|
|
340
|
+
dominantBaseline="central"
|
|
341
|
+
fill="white"
|
|
342
|
+
fontSize={10}
|
|
343
|
+
fontWeight="bold"
|
|
344
|
+
>
|
|
345
|
+
{count}
|
|
346
|
+
</text>
|
|
347
|
+
</g>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ============================================================================
|
|
352
|
+
// Main Component
|
|
353
|
+
// ============================================================================
|
|
354
|
+
|
|
355
|
+
export function ZoneMap({
|
|
356
|
+
zones,
|
|
357
|
+
pieces,
|
|
358
|
+
renderZone,
|
|
359
|
+
backgroundImage,
|
|
360
|
+
width = 800,
|
|
361
|
+
height = 600,
|
|
362
|
+
enablePanZoom = false,
|
|
363
|
+
initialZoom = 1,
|
|
364
|
+
minZoom = 0.5,
|
|
365
|
+
maxZoom = 3,
|
|
366
|
+
className,
|
|
367
|
+
}: ZoneMapProps) {
|
|
368
|
+
// Use the unified pan/zoom hook
|
|
369
|
+
const { transform, bind, isDragging } = usePanZoom({
|
|
370
|
+
enabled: enablePanZoom,
|
|
371
|
+
initialZoom,
|
|
372
|
+
minZoom,
|
|
373
|
+
maxZoom,
|
|
374
|
+
mode: "viewbox",
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Group pieces by zone
|
|
378
|
+
const piecesByZone = useMemo(() => {
|
|
379
|
+
const map: Record<string, ZonePiece[]> = {};
|
|
380
|
+
pieces.forEach((p) => {
|
|
381
|
+
const existing = map[p.zoneId];
|
|
382
|
+
if (existing) {
|
|
383
|
+
existing.push(p);
|
|
384
|
+
} else {
|
|
385
|
+
map[p.zoneId] = [p];
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
return map;
|
|
389
|
+
}, [pieces]);
|
|
390
|
+
|
|
391
|
+
// Calculate viewBox dimensions
|
|
392
|
+
const baseWidth = typeof width === "number" ? width : 800;
|
|
393
|
+
const baseHeight = typeof height === "number" ? height : 600;
|
|
394
|
+
const viewBoxWidth = baseWidth / transform.zoom;
|
|
395
|
+
const viewBoxHeight = baseHeight / transform.zoom;
|
|
396
|
+
const viewBoxX = (baseWidth - viewBoxWidth) / 2 - transform.pan.x;
|
|
397
|
+
const viewBoxY = (baseHeight - viewBoxHeight) / 2 - transform.pan.y;
|
|
398
|
+
|
|
399
|
+
return (
|
|
400
|
+
<svg
|
|
401
|
+
width={width}
|
|
402
|
+
height={height}
|
|
403
|
+
viewBox={`${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`}
|
|
404
|
+
className={clsx(
|
|
405
|
+
"overflow-visible",
|
|
406
|
+
enablePanZoom && "touch-none",
|
|
407
|
+
isDragging && "cursor-grabbing",
|
|
408
|
+
enablePanZoom && !isDragging && "cursor-grab",
|
|
409
|
+
className,
|
|
410
|
+
)}
|
|
411
|
+
{...bind()}
|
|
412
|
+
role="img"
|
|
413
|
+
aria-label="Zone map"
|
|
414
|
+
>
|
|
415
|
+
{/* Background image */}
|
|
416
|
+
{backgroundImage && (
|
|
417
|
+
<image href={backgroundImage} width={width} height={height} />
|
|
418
|
+
)}
|
|
419
|
+
|
|
420
|
+
{/* Zones */}
|
|
421
|
+
<g className="zones" role="list" aria-label="Map zones">
|
|
422
|
+
{zones.map((zone) => {
|
|
423
|
+
const zonePieces = piecesByZone[zone.id] || [];
|
|
424
|
+
return <g key={zone.id}>{renderZone(zone, zonePieces)}</g>;
|
|
425
|
+
})}
|
|
426
|
+
</g>
|
|
427
|
+
|
|
428
|
+
{/* Zoom indicator */}
|
|
429
|
+
{enablePanZoom && transform.zoom !== 1 && (
|
|
430
|
+
<g
|
|
431
|
+
transform={`translate(${viewBoxX + 10}, ${viewBoxY + viewBoxHeight - 30})`}
|
|
432
|
+
>
|
|
433
|
+
<rect
|
|
434
|
+
x={0}
|
|
435
|
+
y={0}
|
|
436
|
+
width={60}
|
|
437
|
+
height={20}
|
|
438
|
+
rx={4}
|
|
439
|
+
fill="rgba(0,0,0,0.6)"
|
|
440
|
+
/>
|
|
441
|
+
<text x={30} y={14} textAnchor="middle" fill="white" fontSize={12}>
|
|
442
|
+
{Math.round(transform.zoom * 100)}%
|
|
443
|
+
</text>
|
|
444
|
+
</g>
|
|
445
|
+
)}
|
|
446
|
+
</svg>
|
|
447
|
+
);
|
|
448
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { renderToString } from "react-dom/server";
|
|
3
|
+
import { createHexBoardView } from "./hex-board-view.js";
|
|
4
|
+
import { HexGrid, type HexGridBoardProps } from "./HexGrid.js";
|
|
5
|
+
|
|
6
|
+
const islandTopology = {
|
|
7
|
+
id: "island",
|
|
8
|
+
layout: "hex",
|
|
9
|
+
spaces: {
|
|
10
|
+
center: { id: "center", q: 0, r: 0, fields: { production: 2 } },
|
|
11
|
+
east: { id: "east", q: 1, r: -1, fields: { production: 1 } },
|
|
12
|
+
},
|
|
13
|
+
edges: [{ id: "edge-1", spaceIds: ["center", "east"] }],
|
|
14
|
+
vertices: [{ id: "vertex-1", spaceIds: ["center", "east"] }],
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
interface IslandSpaceView {
|
|
18
|
+
readonly id: "center" | "east";
|
|
19
|
+
readonly terrain: "forest" | "desert";
|
|
20
|
+
readonly numberToken: number | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("createHexBoardView", () => {
|
|
24
|
+
test("merges overlays onto normalized hex tiles", () => {
|
|
25
|
+
const view = createHexBoardView(islandTopology, {
|
|
26
|
+
spaces: [
|
|
27
|
+
{ id: "center", terrain: "forest", numberToken: 6 },
|
|
28
|
+
{ id: "east", terrain: "desert", numberToken: null },
|
|
29
|
+
] satisfies readonly IslandSpaceView[],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(view.id).toBe("island");
|
|
33
|
+
expect(view.tiles).toHaveLength(2);
|
|
34
|
+
const center = view.tiles.find((tile) => tile.id === "center");
|
|
35
|
+
expect(center?.q).toBe(0);
|
|
36
|
+
expect(center?.r).toBe(0);
|
|
37
|
+
expect(center?.properties?.production).toBe(2);
|
|
38
|
+
expect(center?.view).toEqual({
|
|
39
|
+
id: "center",
|
|
40
|
+
terrain: "forest",
|
|
41
|
+
numberToken: 6,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("throws when an overlay is missing for a board space", () => {
|
|
46
|
+
expect(() =>
|
|
47
|
+
createHexBoardView(islandTopology, {
|
|
48
|
+
spaces: [
|
|
49
|
+
{ id: "center", terrain: "forest", numberToken: 6 },
|
|
50
|
+
] satisfies readonly IslandSpaceView[],
|
|
51
|
+
}),
|
|
52
|
+
).toThrow(/missing overlay for space 'east'/);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("throws when the same space id is supplied twice", () => {
|
|
56
|
+
expect(() =>
|
|
57
|
+
createHexBoardView(islandTopology, {
|
|
58
|
+
spaces: [
|
|
59
|
+
{ id: "center", terrain: "forest", numberToken: 6 },
|
|
60
|
+
{ id: "center", terrain: "desert", numberToken: 8 },
|
|
61
|
+
{ id: "east", terrain: "desert", numberToken: null },
|
|
62
|
+
] satisfies readonly IslandSpaceView[],
|
|
63
|
+
}),
|
|
64
|
+
).toThrow(/duplicate overlay for space 'center'/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("throws when an overlay id is not on the board", () => {
|
|
68
|
+
expect(() =>
|
|
69
|
+
createHexBoardView(islandTopology, {
|
|
70
|
+
spaces: [
|
|
71
|
+
{ id: "center", terrain: "forest", numberToken: 6 },
|
|
72
|
+
{ id: "east", terrain: "desert", numberToken: null },
|
|
73
|
+
// @ts-expect-error -- exercising the runtime guard with an unknown id
|
|
74
|
+
{ id: "ghost", terrain: "forest", numberToken: 0 },
|
|
75
|
+
],
|
|
76
|
+
}),
|
|
77
|
+
).toThrow(/overlay 'ghost' is not on the board/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("preserves tile.view typing through HexGrid renderTile", () => {
|
|
81
|
+
const view = createHexBoardView(islandTopology, {
|
|
82
|
+
spaces: [
|
|
83
|
+
{ id: "center", terrain: "forest", numberToken: 6 },
|
|
84
|
+
{ id: "east", terrain: "desert", numberToken: null },
|
|
85
|
+
] satisfies readonly IslandSpaceView[],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const seenTerrains: string[] = [];
|
|
89
|
+
const seenTokens: Array<number | null> = [];
|
|
90
|
+
const seenProduction: Array<1 | 2 | undefined> = [];
|
|
91
|
+
|
|
92
|
+
const props = {
|
|
93
|
+
board: view,
|
|
94
|
+
hexSize: 30,
|
|
95
|
+
enablePanZoom: false,
|
|
96
|
+
renderTile: (tile) => {
|
|
97
|
+
// Statically typed: tile.view is IslandSpaceView, not unknown.
|
|
98
|
+
seenTerrains.push(tile.view.terrain);
|
|
99
|
+
seenTokens.push(tile.view.numberToken);
|
|
100
|
+
seenProduction.push(tile.properties?.production);
|
|
101
|
+
return null;
|
|
102
|
+
},
|
|
103
|
+
renderEdge: () => null,
|
|
104
|
+
renderVertex: () => null,
|
|
105
|
+
} satisfies HexGridBoardProps<typeof view>;
|
|
106
|
+
|
|
107
|
+
renderToString(<HexGrid {...props} />);
|
|
108
|
+
|
|
109
|
+
expect(seenTerrains.sort()).toEqual(["desert", "forest"]);
|
|
110
|
+
expect(seenTokens).toContain(6);
|
|
111
|
+
expect(seenTokens).toContain(null);
|
|
112
|
+
expect(seenProduction.sort()).toEqual([1, 2]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed adapter for joining static hex-board topology with a dynamic
|
|
3
|
+
* per-space view overlay. Use this to feed `HexGrid` a single board
|
|
4
|
+
* value whose tiles carry both static geometry (`q`, `r`, `id`) and
|
|
5
|
+
* the projected view fields the UI cares about (e.g. `terrain`,
|
|
6
|
+
* `numberToken`).
|
|
7
|
+
*
|
|
8
|
+
* The runtime is intentionally strict: every static space must have
|
|
9
|
+
* exactly one overlay, duplicates throw, and overlays for ids that
|
|
10
|
+
* are not on the board throw. There is no relaxed fallback in v1 —
|
|
11
|
+
* silent merge bugs are far more expensive than a loud throw at
|
|
12
|
+
* dev/CI time.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
AnyHexBoardInput,
|
|
17
|
+
BoardIdOf,
|
|
18
|
+
BoardSpaceIdOf,
|
|
19
|
+
NormalizedHexTileOf,
|
|
20
|
+
} from "../../types/tiled-board.js";
|
|
21
|
+
import { normalizeHexBoardInput } from "../../types/tiled-board.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Per-tile result produced by {@link createHexBoardView}. Each tile
|
|
25
|
+
* carries the static topology (`id`, `q`, `r`) plus the matched
|
|
26
|
+
* overlay row in `view`.
|
|
27
|
+
*
|
|
28
|
+
* Static board fields/properties are preserved from `TBoard`.
|
|
29
|
+
* Consumers should use `tile.properties` for authored static space
|
|
30
|
+
* fields and `tile.view` for dynamic per-space projection data.
|
|
31
|
+
*/
|
|
32
|
+
export type HexBoardViewTile<
|
|
33
|
+
TBoard extends AnyHexBoardInput,
|
|
34
|
+
TSpaceView extends { id: BoardSpaceIdOf<TBoard> },
|
|
35
|
+
> = Omit<NormalizedHexTileOf<TBoard>, "view"> & { view: TSpaceView };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Result of {@link createHexBoardView}. Shaped like an authored hex
|
|
39
|
+
* board so it can be passed straight to `<HexGrid board={...} />`
|
|
40
|
+
* without any further adapter work.
|
|
41
|
+
*
|
|
42
|
+
* The type-level board id and space id are preserved from `TBoard`,
|
|
43
|
+
* so `tile.id` stays narrow inside `renderTile`. `tile.view` is the
|
|
44
|
+
* authored overlay row, fully typed.
|
|
45
|
+
*/
|
|
46
|
+
export interface HexBoardView<
|
|
47
|
+
TBoard extends AnyHexBoardInput,
|
|
48
|
+
TSpaceView extends { id: BoardSpaceIdOf<TBoard> },
|
|
49
|
+
> {
|
|
50
|
+
id: BoardIdOf<TBoard>;
|
|
51
|
+
layout?: "hex";
|
|
52
|
+
orientation?: "pointy-top" | "flat-top";
|
|
53
|
+
tiles: ReadonlyArray<HexBoardViewTile<TBoard, TSpaceView>>;
|
|
54
|
+
edges: TBoard["edges"];
|
|
55
|
+
vertices: TBoard["vertices"];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface CreateHexBoardViewOptions<TSpaceView> {
|
|
59
|
+
spaces: readonly TSpaceView[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Join a static hex board topology with a dynamic per-space overlay.
|
|
64
|
+
*
|
|
65
|
+
* The result is suitable for direct use as the `board` prop on
|
|
66
|
+
* `<HexGrid>`. Every overlay is enforced 1-to-1 against the board's
|
|
67
|
+
* spaces:
|
|
68
|
+
*
|
|
69
|
+
* - missing overlay for a board space → throws
|
|
70
|
+
* - duplicate overlay (same `id` twice) → throws
|
|
71
|
+
* - overlay `id` not present on the board → throws
|
|
72
|
+
*
|
|
73
|
+
* Each tile in the result carries a `view` field with the matched
|
|
74
|
+
* overlay row.
|
|
75
|
+
*/
|
|
76
|
+
export function createHexBoardView<
|
|
77
|
+
const TBoard extends AnyHexBoardInput,
|
|
78
|
+
const TSpaceView extends { id: BoardSpaceIdOf<TBoard> },
|
|
79
|
+
>(
|
|
80
|
+
board: TBoard,
|
|
81
|
+
options: CreateHexBoardViewOptions<TSpaceView>,
|
|
82
|
+
): HexBoardView<TBoard, TSpaceView> {
|
|
83
|
+
const overlayById = new Map<string, TSpaceView>();
|
|
84
|
+
for (const overlay of options.spaces) {
|
|
85
|
+
if (overlayById.has(overlay.id)) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`createHexBoardView: duplicate overlay for space '${overlay.id}'.`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
overlayById.set(overlay.id, overlay);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const consumed = new Set<string>();
|
|
94
|
+
const normalizedBoard = normalizeHexBoardInput(board);
|
|
95
|
+
const tiles: Array<HexBoardViewTile<TBoard, TSpaceView>> =
|
|
96
|
+
normalizedBoard.tiles.map((tile) => {
|
|
97
|
+
const overlay = overlayById.get(tile.id);
|
|
98
|
+
if (!overlay) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`createHexBoardView: missing overlay for space '${tile.id}'.`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
consumed.add(tile.id);
|
|
104
|
+
return { ...tile, view: overlay };
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
for (const id of overlayById.keys()) {
|
|
108
|
+
if (!consumed.has(id)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`createHexBoardView: overlay '${id}' is not on the board.`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
id: normalizedBoard.id,
|
|
117
|
+
layout: "hex",
|
|
118
|
+
orientation: board.orientation,
|
|
119
|
+
tiles,
|
|
120
|
+
edges: board.edges,
|
|
121
|
+
vertices: board.vertices,
|
|
122
|
+
};
|
|
123
|
+
}
|