@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 @@
|
|
|
1
|
+
{"version":3,"file":"SlotSystem.d.ts","sourceRoot":"","sources":["../../../src/components/board/SlotSystem.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO9D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,E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AI,EACJ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,WAAmB,EACnB,WAAkB,EAClB,aAAqB,EACrB,UAAkB,EAClB,SAAS,EACT,WAAW,EACX,eAAe,EACf,OAAO,EACP,cAAc,EACd,cAAc,EACd,SAAS,GACV,EAAE,oBAAoB,2CAmFtB;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,wBAAgB,mBAAmB,CAAC,EAClC,KAAiB,EACjB,IAAS,EACT,KAAgB,EAChB,KAAK,EACL,OAAO,EACP,SAAS,GACV,EAAE,wBAAwB,2CAsB1B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,wBAAgB,gBAAgB,CAAC,EAC/B,IAAS,EACT,SAAS,GACV,EAAE,qBAAqB,2CAavB;AAMD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAgC,EAChC,UAAU,EACV,MAAe,EACf,KAAK,EACL,MAAM,EACN,YAAkB,EAClB,SAAS,GACV,EAAE,eAAe,2CA0FjB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Worker placement visualization for Euro games (Agricola, Viticulture, Lords of Waterdeep).
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { clsx } from "clsx";
|
|
7
|
+
import { Users, Lock, Gift, Coins } from "lucide-react";
|
|
8
|
+
import { handleKeyboardActivation } from "./interaction-accessibility.js";
|
|
9
|
+
const EMPTY_SLOT_OCCUPANTS = [];
|
|
10
|
+
/** Pre-built slot item for use in `renderSlot`. */
|
|
11
|
+
export function DefaultSlotItem({ name, description, capacity, occupantCount, isExclusive = false, isAvailable = true, isHighlighted = false, isSelected = false, costLabel, rewardLabel, renderOccupants, onClick, onPointerEnter, onPointerLeave, className, }) {
|
|
12
|
+
const isFull = occupantCount >= capacity;
|
|
13
|
+
return (_jsxs("div", { onClick: isAvailable ? onClick : undefined, onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, onKeyDown: (event) => handleKeyboardActivation(event, isAvailable ? onClick : undefined), className: clsx("p-4 rounded-lg border-2 transition-all",
|
|
14
|
+
// Availability styling
|
|
15
|
+
isAvailable && onClick && "cursor-pointer hover:bg-blue-500/10", isAvailable ? "border-blue-500" : "border-slate-600",
|
|
16
|
+
// State styling
|
|
17
|
+
isFull && "border-red-500/50 bg-slate-800/50", isHighlighted && "ring-2 ring-yellow-500", isSelected && "ring-2 ring-blue-500 bg-blue-500/10", className), role: isAvailable && onClick ? "button" : "listitem", "aria-label": name, "aria-disabled": !isAvailable, tabIndex: isAvailable && onClick ? 0 : undefined, children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-bold text-white", children: name }), description && (_jsx("p", { className: "text-xs text-slate-400 mt-0.5", children: description }))] }), _jsxs("div", { className: "flex items-center gap-1", children: [isExclusive && (_jsx(Lock, { className: "w-4 h-4 text-amber-500", "aria-label": "Exclusive slot" })), capacity > 1 && (_jsxs("div", { className: "flex items-center gap-0.5 text-xs text-slate-400", title: `Capacity: ${capacity}`, children: [_jsx(Users, { className: "w-3 h-3" }), _jsx("span", { children: capacity })] }))] })] }), (costLabel || rewardLabel) && (_jsxs("div", { className: "mt-2 flex flex-wrap gap-2 text-xs", children: [costLabel && (_jsxs("div", { className: "flex items-center gap-1 text-red-400", children: [_jsx(Coins, { className: "w-3 h-3", "aria-hidden": "true" }), _jsx("span", { children: costLabel })] })), rewardLabel && (_jsxs("div", { className: "flex items-center gap-1 text-green-400", children: [_jsx(Gift, { className: "w-3 h-3", "aria-hidden": "true" }), _jsx("span", { children: rewardLabel })] }))] })), renderOccupants && _jsx("div", { className: "mt-2", children: renderOccupants() }), !isAvailable && !isFull && (_jsx("div", { className: "mt-2 text-xs text-slate-500", children: "Not available" }))] }));
|
|
18
|
+
}
|
|
19
|
+
export function DefaultSlotOccupant({ color = "#3b82f6", size = 24, shape = "circle", label, onClick, className, }) {
|
|
20
|
+
return (_jsx("div", { onClick: onClick, onKeyDown: (event) => handleKeyboardActivation(event, onClick), className: clsx("transition-all", shape === "circle" ? "rounded-full" : "rounded", onClick && "cursor-pointer hover:scale-110", className), style: {
|
|
21
|
+
width: size,
|
|
22
|
+
height: size,
|
|
23
|
+
backgroundColor: color,
|
|
24
|
+
}, title: label, role: onClick ? "button" : "img", "aria-label": label ?? "Occupant", tabIndex: onClick ? 0 : undefined }));
|
|
25
|
+
}
|
|
26
|
+
export function DefaultEmptySlot({ size = 24, className, }) {
|
|
27
|
+
return (_jsx("div", { className: clsx("rounded-full border-2 border-dashed border-slate-600", className), style: { width: size, height: size }, title: "Empty slot", role: "img", "aria-label": "Empty slot" }));
|
|
28
|
+
}
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Component
|
|
31
|
+
// ============================================================================
|
|
32
|
+
export function SlotSystem({ slots, occupants = EMPTY_SLOT_OCCUPANTS, renderSlot, layout = "grid", width, height, minSlotWidth = 280, className, }) {
|
|
33
|
+
// Group occupants by slot
|
|
34
|
+
const occupantsBySlot = useMemo(() => {
|
|
35
|
+
const map = {};
|
|
36
|
+
occupants.forEach((o) => {
|
|
37
|
+
const slotId = o.slotId;
|
|
38
|
+
const existing = map[slotId];
|
|
39
|
+
if (existing) {
|
|
40
|
+
existing.push(o);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
map[slotId] = [o];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return map;
|
|
47
|
+
}, [occupants]);
|
|
48
|
+
// Group slots by group property for grouped layout
|
|
49
|
+
const slotGroups = useMemo(() => {
|
|
50
|
+
if (layout !== "grouped")
|
|
51
|
+
return null;
|
|
52
|
+
const groups = {};
|
|
53
|
+
slots.forEach((slot) => {
|
|
54
|
+
const group = slot.group ?? "Other";
|
|
55
|
+
const existing = groups[group];
|
|
56
|
+
if (existing) {
|
|
57
|
+
existing.push(slot);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
groups[group] = [slot];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return groups;
|
|
64
|
+
}, [slots, layout]);
|
|
65
|
+
// Render a single slot
|
|
66
|
+
const renderSlotItem = (slot) => {
|
|
67
|
+
const slotOccupants = occupantsBySlot[slot.id] ?? [];
|
|
68
|
+
return (_jsx("div", { role: "listitem", "aria-label": slot.name, children: renderSlot(slot, slotOccupants) }, slot.id));
|
|
69
|
+
};
|
|
70
|
+
// Responsive grid style - uses auto-fit to stack items when they don't fit
|
|
71
|
+
const responsiveGridStyle = {
|
|
72
|
+
display: "grid",
|
|
73
|
+
gridTemplateColumns: `repeat(auto-fit, minmax(${minSlotWidth}px, 1fr))`,
|
|
74
|
+
gap: "1rem",
|
|
75
|
+
};
|
|
76
|
+
// Container wrapper
|
|
77
|
+
const wrapContent = (content) => (_jsx("div", { style: { width, height }, className: clsx("slot-system", className), children: content }));
|
|
78
|
+
// Render based on layout
|
|
79
|
+
if (layout === "grouped" && slotGroups) {
|
|
80
|
+
return wrapContent(_jsx("div", { className: "space-y-6", role: "list", children: Object.entries(slotGroups).map(([groupName, groupSlots]) => (_jsxs("div", { children: [_jsx("h3", { className: "text-lg font-semibold text-slate-300 mb-3", children: groupName }), _jsx("div", { style: responsiveGridStyle, children: groupSlots.map(renderSlotItem) })] }, groupName))) }));
|
|
81
|
+
}
|
|
82
|
+
if (layout === "list") {
|
|
83
|
+
return wrapContent(_jsx("div", { className: "flex flex-col gap-2", role: "list", children: slots.map(renderSlotItem) }));
|
|
84
|
+
}
|
|
85
|
+
// Default grid layout - responsive by default
|
|
86
|
+
return wrapContent(_jsx("div", { style: responsiveGridStyle, role: "list", children: slots.map(renderSlotItem) }));
|
|
87
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG-based square grid for grid-based games (Chess, Checkers, Go, Scrabble, Battleship).
|
|
3
|
+
* All rendering controlled by parent via required render functions.
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from "react";
|
|
6
|
+
import { type InteractiveTargetLayer, type InteractiveTargetRenderState } from "./target-layer.js";
|
|
7
|
+
import type { SquarePieceState } from "../../types/player-state.js";
|
|
8
|
+
import { type AuthoredSquareBoardInput, type AnySquareBoardInput, type GeneratedSquareBoardInput, type NormalizedSquareCellOf, type NormalizedSquareEdgeOf, type NormalizedSquarePieceOf, type NormalizedSquareVertexOf } from "../../types/tiled-board.js";
|
|
9
|
+
export type { InteractiveTargetLayer, InteractiveTargetRenderState, } from "./target-layer.js";
|
|
10
|
+
export interface SquareEdgePosition {
|
|
11
|
+
x1: number;
|
|
12
|
+
y1: number;
|
|
13
|
+
x2: number;
|
|
14
|
+
y2: number;
|
|
15
|
+
midX: number;
|
|
16
|
+
midY: number;
|
|
17
|
+
angle: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SquareVertexPosition {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}
|
|
23
|
+
export interface InteractiveSquareEdge<TBoard extends AnySquareBoardInput = AnySquareBoardInput> extends NormalizedSquareEdgeOf<TBoard> {
|
|
24
|
+
position: SquareEdgePosition;
|
|
25
|
+
}
|
|
26
|
+
export interface InteractiveSquareVertex<TBoard extends AnySquareBoardInput = AnySquareBoardInput> extends NormalizedSquareVertexOf<TBoard> {
|
|
27
|
+
position: SquareVertexPosition;
|
|
28
|
+
}
|
|
29
|
+
export type InteractiveSquareSpace<TBoard extends AnySquareBoardInput = AnySquareBoardInput> = NormalizedSquareCellOf<TBoard>;
|
|
30
|
+
interface SquareGeneratedGridInputProps {
|
|
31
|
+
id?: string;
|
|
32
|
+
layout?: "square";
|
|
33
|
+
spaces: Extract<AnySquareBoardInput, {
|
|
34
|
+
spaces: unknown;
|
|
35
|
+
}>["spaces"];
|
|
36
|
+
pieces?: AnySquareBoardInput["pieces"];
|
|
37
|
+
edges?: AnySquareBoardInput["edges"];
|
|
38
|
+
vertices?: AnySquareBoardInput["vertices"];
|
|
39
|
+
}
|
|
40
|
+
interface SquareAuthoredGridInputProps {
|
|
41
|
+
id?: string;
|
|
42
|
+
layout?: "square";
|
|
43
|
+
rows?: number;
|
|
44
|
+
cols?: number;
|
|
45
|
+
cells: Extract<AnySquareBoardInput, {
|
|
46
|
+
cells: unknown;
|
|
47
|
+
}>["cells"];
|
|
48
|
+
pieces?: readonly SquarePieceState[];
|
|
49
|
+
edges?: AnySquareBoardInput["edges"];
|
|
50
|
+
vertices?: AnySquareBoardInput["vertices"];
|
|
51
|
+
}
|
|
52
|
+
type SquareGridInputProps = SquareGeneratedGridInputProps | SquareAuthoredGridInputProps;
|
|
53
|
+
type ResolvedSquareArrayProp<Value> = Exclude<Value, undefined> extends readonly unknown[] ? Exclude<Value, undefined> : readonly [];
|
|
54
|
+
type SquareBoardLikeOfProps<TProps extends SquareGridInputProps> = TProps extends {
|
|
55
|
+
id?: infer Id;
|
|
56
|
+
layout?: infer Layout;
|
|
57
|
+
spaces: infer Spaces;
|
|
58
|
+
pieces?: infer Pieces;
|
|
59
|
+
edges?: infer Edges;
|
|
60
|
+
vertices?: infer Vertices;
|
|
61
|
+
} ? {
|
|
62
|
+
id: Extract<Id, string> extends never ? string : Extract<Id, string>;
|
|
63
|
+
layout?: Extract<Layout, "square">;
|
|
64
|
+
spaces: Spaces;
|
|
65
|
+
pieces: ResolvedSquareArrayProp<Pieces>;
|
|
66
|
+
edges: ResolvedSquareArrayProp<Edges>;
|
|
67
|
+
vertices: ResolvedSquareArrayProp<Vertices>;
|
|
68
|
+
} & GeneratedSquareBoardInput : TProps extends {
|
|
69
|
+
id?: infer Id;
|
|
70
|
+
layout?: infer Layout;
|
|
71
|
+
rows?: infer Rows;
|
|
72
|
+
cols?: infer Cols;
|
|
73
|
+
cells: infer Cells;
|
|
74
|
+
pieces?: infer Pieces;
|
|
75
|
+
edges?: infer Edges;
|
|
76
|
+
vertices?: infer Vertices;
|
|
77
|
+
} ? {
|
|
78
|
+
id: Extract<Id, string> extends never ? string : Extract<Id, string>;
|
|
79
|
+
layout?: Extract<Layout, "square">;
|
|
80
|
+
rows: Extract<Rows, number> extends never ? number : Extract<Rows, number>;
|
|
81
|
+
cols: Extract<Cols, number> extends never ? number : Extract<Cols, number>;
|
|
82
|
+
cells: Cells;
|
|
83
|
+
pieces: ResolvedSquareArrayProp<Pieces>;
|
|
84
|
+
edges: ResolvedSquareArrayProp<Edges>;
|
|
85
|
+
vertices: ResolvedSquareArrayProp<Vertices>;
|
|
86
|
+
} & AuthoredSquareBoardInput : never;
|
|
87
|
+
export type SquareGridProps<TProps extends SquareGridInputProps = SquareGridInputProps> = TProps & {
|
|
88
|
+
cellSize?: number;
|
|
89
|
+
/** Receives row/col with transform centered at cell position */
|
|
90
|
+
renderCell: (row: number, col: number) => ReactNode;
|
|
91
|
+
/** Receives piece with transform centered at cell center */
|
|
92
|
+
renderPiece: (piece: NormalizedSquarePieceOf<NoInfer<SquareBoardLikeOfProps<TProps>>>) => ReactNode;
|
|
93
|
+
renderEdge?: (edge: NormalizedSquareEdgeOf<NoInfer<SquareBoardLikeOfProps<TProps>>>, position: SquareEdgePosition) => ReactNode;
|
|
94
|
+
renderVertex?: (vertex: NormalizedSquareVertexOf<NoInfer<SquareBoardLikeOfProps<TProps>>>, position: SquareVertexPosition) => ReactNode;
|
|
95
|
+
showCoordinates?: boolean;
|
|
96
|
+
coordinateStyle?: "algebraic" | "numeric" | "none";
|
|
97
|
+
width?: number | string;
|
|
98
|
+
height?: number | string;
|
|
99
|
+
enablePanZoom?: boolean;
|
|
100
|
+
initialZoom?: number;
|
|
101
|
+
minZoom?: number;
|
|
102
|
+
maxZoom?: number;
|
|
103
|
+
className?: string;
|
|
104
|
+
interactiveSpaces?: InteractiveTargetLayer;
|
|
105
|
+
interactiveEdges?: InteractiveTargetLayer;
|
|
106
|
+
interactiveVertices?: InteractiveTargetLayer;
|
|
107
|
+
renderInteractiveSpace?: (space: InteractiveSquareSpace<NoInfer<SquareBoardLikeOfProps<TProps>>>, state: InteractiveTargetRenderState) => ReactNode;
|
|
108
|
+
renderInteractiveEdge?: (edge: InteractiveSquareEdge<NoInfer<SquareBoardLikeOfProps<TProps>>>, position: SquareEdgePosition, state: InteractiveTargetRenderState) => ReactNode;
|
|
109
|
+
renderInteractiveVertex?: (vertex: InteractiveSquareVertex<NoInfer<SquareBoardLikeOfProps<TProps>>>, position: SquareVertexPosition, state: InteractiveTargetRenderState) => ReactNode;
|
|
110
|
+
};
|
|
111
|
+
export interface SquareGridBoardProps<TBoard extends AnySquareBoardInput = AnySquareBoardInput> {
|
|
112
|
+
board: TBoard;
|
|
113
|
+
cellSize?: number;
|
|
114
|
+
renderCell: (row: number, col: number) => ReactNode;
|
|
115
|
+
renderPiece: (piece: NormalizedSquarePieceOf<NoInfer<TBoard>>) => ReactNode;
|
|
116
|
+
renderEdge?: (edge: NormalizedSquareEdgeOf<NoInfer<TBoard>>, position: SquareEdgePosition) => ReactNode;
|
|
117
|
+
renderVertex?: (vertex: NormalizedSquareVertexOf<NoInfer<TBoard>>, position: SquareVertexPosition) => ReactNode;
|
|
118
|
+
showCoordinates?: boolean;
|
|
119
|
+
coordinateStyle?: "algebraic" | "numeric" | "none";
|
|
120
|
+
width?: number | string;
|
|
121
|
+
height?: number | string;
|
|
122
|
+
enablePanZoom?: boolean;
|
|
123
|
+
initialZoom?: number;
|
|
124
|
+
minZoom?: number;
|
|
125
|
+
maxZoom?: number;
|
|
126
|
+
className?: string;
|
|
127
|
+
interactiveSpaces?: InteractiveTargetLayer;
|
|
128
|
+
interactiveEdges?: InteractiveTargetLayer;
|
|
129
|
+
interactiveVertices?: InteractiveTargetLayer;
|
|
130
|
+
renderInteractiveSpace?: (space: InteractiveSquareSpace<NoInfer<TBoard>>, state: InteractiveTargetRenderState) => ReactNode;
|
|
131
|
+
renderInteractiveEdge?: (edge: InteractiveSquareEdge<NoInfer<TBoard>>, position: SquareEdgePosition, state: InteractiveTargetRenderState) => ReactNode;
|
|
132
|
+
renderInteractiveVertex?: (vertex: InteractiveSquareVertex<NoInfer<TBoard>>, position: SquareVertexPosition, state: InteractiveTargetRenderState) => ReactNode;
|
|
133
|
+
}
|
|
134
|
+
export interface DefaultGridCellProps {
|
|
135
|
+
size: number;
|
|
136
|
+
isLight?: boolean;
|
|
137
|
+
lightColor?: string;
|
|
138
|
+
darkColor?: string;
|
|
139
|
+
isHighlighted?: boolean;
|
|
140
|
+
highlightColor?: string;
|
|
141
|
+
isSelected?: boolean;
|
|
142
|
+
selectedColor?: string;
|
|
143
|
+
isValidMove?: boolean;
|
|
144
|
+
isCapture?: boolean;
|
|
145
|
+
onClick?: () => void;
|
|
146
|
+
onPointerEnter?: () => void;
|
|
147
|
+
onPointerLeave?: () => void;
|
|
148
|
+
className?: string;
|
|
149
|
+
}
|
|
150
|
+
/** Pre-built grid cell component for use in `renderCell`. */
|
|
151
|
+
export declare function DefaultGridCell({ size, isLight, lightColor, darkColor, isHighlighted, highlightColor, isSelected, selectedColor, isValidMove, isCapture, onClick, onPointerEnter, onPointerLeave, className, }: DefaultGridCellProps): import("react/jsx-runtime").JSX.Element;
|
|
152
|
+
export interface DefaultGridPieceProps {
|
|
153
|
+
size: number;
|
|
154
|
+
color?: string;
|
|
155
|
+
strokeColor?: string;
|
|
156
|
+
label?: string;
|
|
157
|
+
isDragging?: boolean;
|
|
158
|
+
onClick?: () => void;
|
|
159
|
+
onPointerDown?: (e: React.PointerEvent) => void;
|
|
160
|
+
className?: string;
|
|
161
|
+
}
|
|
162
|
+
/** Pre-built grid piece component for use in `renderPiece`. */
|
|
163
|
+
export declare function DefaultGridPiece({ size, color, strokeColor, label, isDragging, onClick, onPointerDown, className, }: DefaultGridPieceProps): import("react/jsx-runtime").JSX.Element;
|
|
164
|
+
export interface DefaultChessPieceProps {
|
|
165
|
+
size: number;
|
|
166
|
+
type: string;
|
|
167
|
+
owner: "white" | "black";
|
|
168
|
+
onClick?: () => void;
|
|
169
|
+
onPointerDown?: (e: React.PointerEvent) => void;
|
|
170
|
+
className?: string;
|
|
171
|
+
}
|
|
172
|
+
/** Pre-built chess piece component using Unicode symbols. */
|
|
173
|
+
export declare function DefaultChessPiece({ size, type, owner, onClick, onPointerDown, className, }: DefaultChessPieceProps): import("react/jsx-runtime").JSX.Element;
|
|
174
|
+
/**
|
|
175
|
+
* Convert row/col to algebraic notation (a1, b2, etc.)
|
|
176
|
+
*/
|
|
177
|
+
export declare function toAlgebraic(row: number, col: number, totalRows: number): string;
|
|
178
|
+
/**
|
|
179
|
+
* Convert row/col to numeric notation (1,1, 2,3, etc.)
|
|
180
|
+
*/
|
|
181
|
+
export declare function toNumeric(row: number, col: number): string;
|
|
182
|
+
export interface SquareGridComponent {
|
|
183
|
+
<const TBoard extends AnySquareBoardInput>(props: SquareGridBoardProps<TBoard>): ReactNode;
|
|
184
|
+
<const TProps extends SquareGeneratedGridInputProps>(props: SquareGridProps<TProps>): ReactNode;
|
|
185
|
+
<const TProps extends SquareAuthoredGridInputProps>(props: SquareGridProps<TProps>): ReactNode;
|
|
186
|
+
}
|
|
187
|
+
export declare const SquareGrid: SquareGridComponent;
|
|
188
|
+
//# sourceMappingURL=SquareGrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SquareGrid.d.ts","sourceRoot":"","sources":["../../../src/components/board/SquareGrid.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI1D,OAAO,EAGL,KAAK,sBAAs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AAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqBD,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,OAAO,EACP,aAAa,EACb,SAAS,GACV,EAAE,sBAAsB,2CAgCxB;AAMD;;GAEG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAkHD,MAAM,WAAW,mBAAmB;IAClC,CAAC,KAAK,CAAC,MAAM,SAAS,mBAAmB,EACvC,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAClC,SAAS,CAAC;IACb,CAAC,KAAK,CAAC,MAAM,SAAS,6BAA6B,EACjD,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC,GAC7B,SAAS,CAAC;IACb,CAAC,KAAK,CAAC,MAAM,SAAS,4BAA4B,EAChD,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC,GAC7B,SAAS,CAAC;CACd;AA+hBD,eAAO,MAAM,UAAU,EAAqB,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* SVG-based square grid for grid-based games (Chess, Checkers, Go, Scrabble, Battleship).
|
|
4
|
+
* All rendering controlled by parent via required render functions.
|
|
5
|
+
*/
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { clsx } from "clsx";
|
|
8
|
+
import { usePanZoom } from "../../hooks/usePanZoom.js";
|
|
9
|
+
import { handleKeyboardActivation } from "./interaction-accessibility.js";
|
|
10
|
+
import { interactiveTargetRenderState, isInteractiveTargetSelectable, } from "./target-layer.js";
|
|
11
|
+
import { normalizeSquareBoardInput, } from "../../types/tiled-board.js";
|
|
12
|
+
/** Pre-built grid cell component for use in `renderCell`. */
|
|
13
|
+
export function DefaultGridCell({ size, isLight = true, lightColor = "#f0d9b5", darkColor = "#b58863", isHighlighted = false, highlightColor = "rgba(250, 204, 21, 0.4)", isSelected = false, selectedColor = "rgba(59, 130, 246, 0.5)", isValidMove = false, isCapture = false, onClick, onPointerEnter, onPointerLeave, className, }) {
|
|
14
|
+
const baseColor = isLight ? lightColor : darkColor;
|
|
15
|
+
return (_jsxs("g", { onClick: onClick, onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, onKeyDown: (event) => handleKeyboardActivation(event, onClick), className: clsx("transition-colors duration-100", onClick && "cursor-pointer", className), role: onClick ? "button" : undefined, tabIndex: onClick ? 0 : undefined, "aria-label": onClick ? "Grid cell" : undefined, children: [_jsx("rect", { width: size, height: size, fill: baseColor }), isSelected && (_jsx("rect", { width: size, height: size, fill: selectedColor, pointerEvents: "none" })), isHighlighted && !isSelected && (_jsx("rect", { width: size, height: size, fill: highlightColor, pointerEvents: "none" })), isValidMove && !isCapture && (_jsx("circle", { cx: size / 2, cy: size / 2, r: size * 0.15, fill: "rgba(34, 197, 94, 0.6)", pointerEvents: "none" })), isCapture && (_jsx("circle", { cx: size / 2, cy: size / 2, r: size * 0.42, fill: "none", stroke: "rgba(239, 68, 68, 0.8)", strokeWidth: size * 0.08, pointerEvents: "none" }))] }));
|
|
16
|
+
}
|
|
17
|
+
/** Pre-built grid piece component for use in `renderPiece`. */
|
|
18
|
+
export function DefaultGridPiece({ size, color = "#94a3b8", strokeColor, label, isDragging = false, onClick, onPointerDown, className, }) {
|
|
19
|
+
const radius = size * 0.38;
|
|
20
|
+
const effectiveStroke = strokeColor ??
|
|
21
|
+
(color === "#f8fafc" || color === "#ffffff" ? "#1e293b" : "#f8fafc");
|
|
22
|
+
return (_jsxs("g", { onClick: onClick, onPointerDown: onPointerDown, onKeyDown: (event) => handleKeyboardActivation(event, onClick), className: clsx("transition-transform duration-150", (onClick || onPointerDown) && "cursor-pointer hover:scale-105", className), opacity: isDragging ? 0.8 : 1, role: onClick ? "button" : undefined, tabIndex: onClick ? 0 : undefined, "aria-label": onClick ? (label ?? "Grid piece") : undefined, children: [_jsx("circle", { r: isDragging ? radius * 1.1 : radius, fill: color, stroke: effectiveStroke, strokeWidth: 2, style: { filter: "drop-shadow(1px 2px 2px rgba(0,0,0,0.4))" } }), label && (_jsx("text", { y: 4, textAnchor: "middle", fill: effectiveStroke, fontSize: size * 0.35, fontWeight: "bold", pointerEvents: "none", children: label }))] }));
|
|
23
|
+
}
|
|
24
|
+
const CHESS_SYMBOLS = {
|
|
25
|
+
white: {
|
|
26
|
+
king: "♔",
|
|
27
|
+
queen: "♕",
|
|
28
|
+
rook: "♖",
|
|
29
|
+
bishop: "♗",
|
|
30
|
+
knight: "♘",
|
|
31
|
+
pawn: "♙",
|
|
32
|
+
},
|
|
33
|
+
black: {
|
|
34
|
+
king: "♚",
|
|
35
|
+
queen: "♛",
|
|
36
|
+
rook: "♜",
|
|
37
|
+
bishop: "♝",
|
|
38
|
+
knight: "♞",
|
|
39
|
+
pawn: "♟",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
/** Pre-built chess piece component using Unicode symbols. */
|
|
43
|
+
export function DefaultChessPiece({ size, type, owner, onClick, onPointerDown, className, }) {
|
|
44
|
+
const symbol = CHESS_SYMBOLS[owner]?.[type] ?? "?";
|
|
45
|
+
const textColor = owner === "white" ? "#f8fafc" : "#1e293b";
|
|
46
|
+
const shadowFilter = owner === "white"
|
|
47
|
+
? "drop-shadow(1px 1px 1px rgba(0,0,0,0.5))"
|
|
48
|
+
: "drop-shadow(1px 1px 1px rgba(255,255,255,0.3))";
|
|
49
|
+
return (_jsx("g", { onClick: onClick, onPointerDown: onPointerDown, onKeyDown: (event) => handleKeyboardActivation(event, onClick), className: clsx((onClick || onPointerDown) && "cursor-pointer", className), role: onClick ? "button" : undefined, tabIndex: onClick ? 0 : undefined, "aria-label": onClick ? `${owner} ${type}` : undefined, children: _jsx("text", { textAnchor: "middle", dominantBaseline: "middle", fontSize: size * 0.7, fill: textColor, style: { filter: shadowFilter }, children: symbol }) }));
|
|
50
|
+
}
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Utilities
|
|
53
|
+
// ============================================================================
|
|
54
|
+
/**
|
|
55
|
+
* Convert row/col to algebraic notation (a1, b2, etc.)
|
|
56
|
+
*/
|
|
57
|
+
export function toAlgebraic(row, col, totalRows) {
|
|
58
|
+
const file = String.fromCharCode(97 + col); // a, b, c, ...
|
|
59
|
+
const rank = totalRows - row; // 8, 7, 6, ... (bottom to top)
|
|
60
|
+
return `${file}${rank}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert row/col to numeric notation (1,1, 2,3, etc.)
|
|
64
|
+
*/
|
|
65
|
+
export function toNumeric(row, col) {
|
|
66
|
+
return `${row + 1},${col + 1}`;
|
|
67
|
+
}
|
|
68
|
+
function getCellId(cell) {
|
|
69
|
+
return cell.id;
|
|
70
|
+
}
|
|
71
|
+
function edgePositionForCells(firstCell, secondCell, cellSize, labelMargin) {
|
|
72
|
+
if (Math.abs(firstCell.row - secondCell.row) +
|
|
73
|
+
Math.abs(firstCell.col - secondCell.col) !==
|
|
74
|
+
1) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const minRow = Math.min(firstCell.row, secondCell.row);
|
|
78
|
+
const minCol = Math.min(firstCell.col, secondCell.col);
|
|
79
|
+
if (firstCell.row === secondCell.row) {
|
|
80
|
+
const x = labelMargin + (minCol + 1) * cellSize;
|
|
81
|
+
const y1 = minRow * cellSize;
|
|
82
|
+
const y2 = y1 + cellSize;
|
|
83
|
+
return {
|
|
84
|
+
x1: x,
|
|
85
|
+
y1,
|
|
86
|
+
x2: x,
|
|
87
|
+
y2,
|
|
88
|
+
midX: x,
|
|
89
|
+
midY: (y1 + y2) / 2,
|
|
90
|
+
angle: 90,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const y = (minRow + 1) * cellSize;
|
|
94
|
+
const x1 = labelMargin + minCol * cellSize;
|
|
95
|
+
const x2 = x1 + cellSize;
|
|
96
|
+
return {
|
|
97
|
+
x1,
|
|
98
|
+
y1: y,
|
|
99
|
+
x2,
|
|
100
|
+
y2: y,
|
|
101
|
+
midX: (x1 + x2) / 2,
|
|
102
|
+
midY: y,
|
|
103
|
+
angle: 0,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function cornerKeysForCell(cell) {
|
|
107
|
+
return {
|
|
108
|
+
[`${cell.col},${cell.row}`]: { x: cell.col, y: cell.row },
|
|
109
|
+
[`${cell.col + 1},${cell.row}`]: { x: cell.col + 1, y: cell.row },
|
|
110
|
+
[`${cell.col + 1},${cell.row + 1}`]: {
|
|
111
|
+
x: cell.col + 1,
|
|
112
|
+
y: cell.row + 1,
|
|
113
|
+
},
|
|
114
|
+
[`${cell.col},${cell.row + 1}`]: { x: cell.col, y: cell.row + 1 },
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function vertexPositionForCells(cells, cellSize, labelMargin) {
|
|
118
|
+
if (cells.length === 0) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const candidateKeys = cells.map((cell) => new Set(Object.keys(cornerKeysForCell(cell))));
|
|
122
|
+
const firstKeySet = candidateKeys[0];
|
|
123
|
+
if (firstKeySet === undefined) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const sharedKeys = [...firstKeySet].filter((key) => candidateKeys.every((keySet) => keySet.has(key)));
|
|
127
|
+
if (sharedKeys.length !== 1) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const sharedKey = sharedKeys[0];
|
|
131
|
+
if (!sharedKey) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const [colToken, rowToken] = sharedKey.split(",");
|
|
135
|
+
if (colToken === undefined || rowToken === undefined) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const col = Number(colToken);
|
|
139
|
+
const row = Number(rowToken);
|
|
140
|
+
if (!Number.isFinite(col) || !Number.isFinite(row)) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
x: labelMargin + col * cellSize,
|
|
145
|
+
y: row * cellSize,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function SquareGridImpl(props) {
|
|
149
|
+
const { cellSize = 60, renderCell, renderPiece, renderEdge, renderVertex, showCoordinates = true, coordinateStyle = "algebraic", width, height, enablePanZoom = false, initialZoom = 1, minZoom = 0.5, maxZoom = 3, className, interactiveSpaces, interactiveEdges, interactiveVertices, renderInteractiveSpace, renderInteractiveEdge, renderInteractiveVertex, } = props;
|
|
150
|
+
const board = "board" in props
|
|
151
|
+
? props.board
|
|
152
|
+
: ("spaces" in props
|
|
153
|
+
? {
|
|
154
|
+
id: "__square-grid__",
|
|
155
|
+
spaces: props.spaces,
|
|
156
|
+
pieces: props.pieces ?? [],
|
|
157
|
+
edges: props.edges ?? [],
|
|
158
|
+
vertices: props.vertices ?? [],
|
|
159
|
+
}
|
|
160
|
+
: {
|
|
161
|
+
id: "__square-grid__",
|
|
162
|
+
rows: props.rows ?? 0,
|
|
163
|
+
cols: props.cols ?? 0,
|
|
164
|
+
cells: props.cells,
|
|
165
|
+
pieces: props.pieces ?? [],
|
|
166
|
+
edges: props.edges ?? [],
|
|
167
|
+
vertices: props.vertices ?? [],
|
|
168
|
+
});
|
|
169
|
+
const [hoveredInteractiveSpaceId, setHoveredInteractiveSpaceId] = useState(null);
|
|
170
|
+
const [hoveredInteractiveEdgeId, setHoveredInteractiveEdgeId] = useState(null);
|
|
171
|
+
const [hoveredInteractiveVertexId, setHoveredInteractiveVertexId] = useState(null);
|
|
172
|
+
// Use the unified pan/zoom hook
|
|
173
|
+
const { transform, bind, isDragging: isPanning, } = usePanZoom({
|
|
174
|
+
enabled: enablePanZoom,
|
|
175
|
+
initialZoom,
|
|
176
|
+
minZoom,
|
|
177
|
+
maxZoom,
|
|
178
|
+
mode: "viewbox",
|
|
179
|
+
});
|
|
180
|
+
// Coordinate label margin
|
|
181
|
+
const labelMargin = showCoordinates && coordinateStyle !== "none" ? 24 : 0;
|
|
182
|
+
const normalizedBoard = useMemo(() => normalizeSquareBoardInput(board), [board]);
|
|
183
|
+
const rows = normalizedBoard.rows;
|
|
184
|
+
const cols = normalizedBoard.cols;
|
|
185
|
+
const resolvedEdges = normalizedBoard.edges;
|
|
186
|
+
const resolvedVertices = normalizedBoard.vertices;
|
|
187
|
+
const resolvedPieces = normalizedBoard.pieces;
|
|
188
|
+
// Calculate grid dimensions
|
|
189
|
+
const gridWidth = cols * cellSize;
|
|
190
|
+
const gridHeight = rows * cellSize;
|
|
191
|
+
const totalWidth = gridWidth + labelMargin;
|
|
192
|
+
const totalHeight = gridHeight + labelMargin;
|
|
193
|
+
const renderableCells = useMemo(() => {
|
|
194
|
+
const result = [];
|
|
195
|
+
for (let row = 0; row < rows; row++) {
|
|
196
|
+
for (let col = 0; col < cols; col++) {
|
|
197
|
+
result.push({ row, col });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}, [rows, cols]);
|
|
202
|
+
const resolvedCells = useMemo(() => {
|
|
203
|
+
if (normalizedBoard.cells.length > 0) {
|
|
204
|
+
return normalizedBoard.cells.map((cell) => ({
|
|
205
|
+
...cell,
|
|
206
|
+
id: getCellId(cell),
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
return renderableCells.map(({ row, col }) => ({
|
|
210
|
+
id: `${row},${col}`,
|
|
211
|
+
row,
|
|
212
|
+
col,
|
|
213
|
+
}));
|
|
214
|
+
}, [normalizedBoard.cells, renderableCells]);
|
|
215
|
+
const cellsById = useMemo(() => new Map(resolvedCells.map((cell) => [cell.id, cell])), [resolvedCells]);
|
|
216
|
+
const resolvedEdgePositions = useMemo(() => resolvedEdges.flatMap((edge) => {
|
|
217
|
+
if (edge.spaceIds.length < 2) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
const firstCell = cellsById.get(edge.spaceIds[0] ?? "");
|
|
221
|
+
const secondCell = cellsById.get(edge.spaceIds[1] ?? "");
|
|
222
|
+
if (!firstCell || !secondCell) {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
const position = edgePositionForCells(firstCell, secondCell, cellSize, labelMargin);
|
|
226
|
+
return position
|
|
227
|
+
? [
|
|
228
|
+
{
|
|
229
|
+
edge,
|
|
230
|
+
interactiveEdge: {
|
|
231
|
+
...edge,
|
|
232
|
+
position,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
: [];
|
|
237
|
+
}), [cellSize, cellsById, resolvedEdges, labelMargin]);
|
|
238
|
+
const resolvedVertexPositions = useMemo(() => resolvedVertices.flatMap((vertex) => {
|
|
239
|
+
const vertexCells = vertex.spaceIds.flatMap((spaceId) => {
|
|
240
|
+
const cell = cellsById.get(spaceId);
|
|
241
|
+
return cell ? [cell] : [];
|
|
242
|
+
});
|
|
243
|
+
const position = vertexPositionForCells(vertexCells, cellSize, labelMargin);
|
|
244
|
+
return position
|
|
245
|
+
? [
|
|
246
|
+
{
|
|
247
|
+
vertex,
|
|
248
|
+
interactiveVertex: {
|
|
249
|
+
...vertex,
|
|
250
|
+
position,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
]
|
|
254
|
+
: [];
|
|
255
|
+
}), [cellSize, cellsById, labelMargin, resolvedVertices]);
|
|
256
|
+
// Calculate viewBox for pan/zoom
|
|
257
|
+
const viewBoxWidth = totalWidth / transform.zoom;
|
|
258
|
+
const viewBoxHeight = totalHeight / transform.zoom;
|
|
259
|
+
const viewBoxX = (totalWidth - viewBoxWidth) / 2 - transform.pan.x;
|
|
260
|
+
const viewBoxY = (totalHeight - viewBoxHeight) / 2 - transform.pan.y;
|
|
261
|
+
// Determine SVG dimensions
|
|
262
|
+
const svgWidth = width ?? totalWidth;
|
|
263
|
+
const svgHeight = height ?? totalHeight;
|
|
264
|
+
return (_jsxs("svg", { width: svgWidth, height: svgHeight, viewBox: enablePanZoom
|
|
265
|
+
? `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`
|
|
266
|
+
: `0 0 ${totalWidth} ${totalHeight}`, className: clsx("square-grid", enablePanZoom && "touch-none", isPanning && "cursor-grabbing", enablePanZoom && !isPanning && "cursor-grab", className), ...bind(), role: "img", "aria-label": `${rows}x${cols} game grid`, children: [_jsx("defs", { children: _jsx("filter", { id: "pieceShadow", x: "-20%", y: "-20%", width: "140%", height: "140%", children: _jsx("feDropShadow", { dx: "1", dy: "2", stdDeviation: "2", floodOpacity: "0.4" }) }) }), _jsx("g", { className: "cells", role: "list", "aria-label": "Grid cells", children: renderableCells.map(({ row, col }) => {
|
|
267
|
+
const x = labelMargin + col * cellSize;
|
|
268
|
+
const y = row * cellSize;
|
|
269
|
+
return (_jsx("g", { transform: `translate(${x}, ${y})`, role: "listitem", "aria-label": coordinateStyle === "algebraic"
|
|
270
|
+
? toAlgebraic(row, col, rows)
|
|
271
|
+
: toNumeric(row, col), children: renderCell(row, col) }, `${row}-${col}`));
|
|
272
|
+
}) }), interactiveSpaces && (_jsx("g", { className: "interactive-spaces", "aria-label": "Interactive spaces", children: resolvedCells.map((space) => {
|
|
273
|
+
const state = interactiveTargetRenderState(interactiveSpaces, space.id, hoveredInteractiveSpaceId === space.id);
|
|
274
|
+
const isSelectable = isInteractiveTargetSelectable(interactiveSpaces, state);
|
|
275
|
+
const x = labelMargin + space.col * cellSize;
|
|
276
|
+
const y = space.row * cellSize;
|
|
277
|
+
return (_jsxs("g", { transform: `translate(${x}, ${y})`, onClick: isSelectable
|
|
278
|
+
? () => {
|
|
279
|
+
void interactiveSpaces.selectTargetId?.(space.id);
|
|
280
|
+
}
|
|
281
|
+
: undefined, onKeyDown: (event) => handleKeyboardActivation(event, isSelectable
|
|
282
|
+
? () => {
|
|
283
|
+
void interactiveSpaces.selectTargetId?.(space.id);
|
|
284
|
+
}
|
|
285
|
+
: undefined), onPointerEnter: () => setHoveredInteractiveSpaceId(space.id), onPointerLeave: () => setHoveredInteractiveSpaceId((currentId) => currentId === space.id ? null : currentId), className: clsx(isSelectable && "cursor-pointer"), role: isSelectable ? "button" : undefined, tabIndex: isSelectable ? 0 : undefined, "aria-label": isSelectable ? `Select space ${space.id}` : undefined, children: [isSelectable && (_jsx("rect", { x: 0, y: 0, width: cellSize, height: cellSize, fill: "rgba(255,255,255,0.001)", pointerEvents: "all" })), renderInteractiveSpace
|
|
286
|
+
? renderInteractiveSpace(space, state)
|
|
287
|
+
: null] }, space.id));
|
|
288
|
+
}) })), renderEdge && resolvedEdgePositions.length > 0 && (_jsx("g", { className: "edges", "aria-label": "Board edges", children: resolvedEdgePositions.map(({ edge, interactiveEdge }) => (_jsx("g", { children: renderEdge(edge, interactiveEdge.position) }, edge.id))) })), interactiveEdges && (_jsx("g", { className: "interactive-edges", "aria-label": "Interactive edges", children: resolvedEdgePositions.map(({ interactiveEdge: edge }) => {
|
|
289
|
+
const state = interactiveTargetRenderState(interactiveEdges, edge.id, hoveredInteractiveEdgeId === edge.id);
|
|
290
|
+
const isSelectable = isInteractiveTargetSelectable(interactiveEdges, state);
|
|
291
|
+
return (_jsx("g", { onClick: isSelectable
|
|
292
|
+
? () => {
|
|
293
|
+
void interactiveEdges.selectTargetId?.(edge.id);
|
|
294
|
+
}
|
|
295
|
+
: undefined, onKeyDown: (event) => handleKeyboardActivation(event, isSelectable
|
|
296
|
+
? () => {
|
|
297
|
+
void interactiveEdges.selectTargetId?.(edge.id);
|
|
298
|
+
}
|
|
299
|
+
: undefined), onPointerEnter: () => setHoveredInteractiveEdgeId(edge.id), onPointerLeave: () => setHoveredInteractiveEdgeId((currentId) => currentId === edge.id ? null : currentId), className: clsx(isSelectable && "cursor-pointer"), role: isSelectable ? "button" : undefined, tabIndex: isSelectable ? 0 : undefined, "aria-label": isSelectable ? `Select edge ${edge.id}` : undefined, children: renderInteractiveEdge ? (renderInteractiveEdge(edge, edge.position, state)) : state.isEnabled && state.isEligible ? (_jsx("line", { x1: edge.position.x1, y1: edge.position.y1, x2: edge.position.x2, y2: edge.position.y2, stroke: "rgba(255,255,255,0.001)", strokeWidth: Math.max(12, cellSize * 0.18), pointerEvents: "stroke" })) : null }, edge.id));
|
|
300
|
+
}) })), renderVertex && resolvedVertexPositions.length > 0 && (_jsx("g", { className: "vertices", "aria-label": "Board vertices", children: resolvedVertexPositions.map(({ vertex, interactiveVertex }) => (_jsx("g", { children: renderVertex(vertex, interactiveVertex.position) }, vertex.id))) })), interactiveVertices && (_jsx("g", { className: "interactive-vertices", "aria-label": "Interactive vertices", children: resolvedVertexPositions.map(({ interactiveVertex: vertex }) => {
|
|
301
|
+
const state = interactiveTargetRenderState(interactiveVertices, vertex.id, hoveredInteractiveVertexId === vertex.id);
|
|
302
|
+
const isSelectable = isInteractiveTargetSelectable(interactiveVertices, state);
|
|
303
|
+
return (_jsx("g", { onClick: isSelectable
|
|
304
|
+
? () => {
|
|
305
|
+
void interactiveVertices.selectTargetId?.(vertex.id);
|
|
306
|
+
}
|
|
307
|
+
: undefined, onKeyDown: (event) => handleKeyboardActivation(event, isSelectable
|
|
308
|
+
? () => {
|
|
309
|
+
void interactiveVertices.selectTargetId?.(vertex.id);
|
|
310
|
+
}
|
|
311
|
+
: undefined), onPointerEnter: () => setHoveredInteractiveVertexId(vertex.id), onPointerLeave: () => setHoveredInteractiveVertexId((currentId) => currentId === vertex.id ? null : currentId), className: clsx(isSelectable && "cursor-pointer"), role: isSelectable ? "button" : undefined, tabIndex: isSelectable ? 0 : undefined, "aria-label": isSelectable ? `Select vertex ${vertex.id}` : undefined, children: renderInteractiveVertex ? (renderInteractiveVertex(vertex, vertex.position, state)) : state.isEnabled && state.isEligible ? (_jsx("circle", { cx: vertex.position.x, cy: vertex.position.y, r: Math.max(8, cellSize * 0.12), fill: "rgba(255,255,255,0.001)", pointerEvents: "all" })) : null }, vertex.id));
|
|
312
|
+
}) })), showCoordinates && coordinateStyle !== "none" && (_jsxs("g", { className: "coordinates", "aria-hidden": "true", children: [Array.from({ length: cols }).map((_, col) => {
|
|
313
|
+
const label = coordinateStyle === "algebraic"
|
|
314
|
+
? String.fromCharCode(97 + col)
|
|
315
|
+
: String(col + 1);
|
|
316
|
+
return (_jsx("text", { x: labelMargin + col * cellSize + cellSize / 2, y: gridHeight + 16, textAnchor: "middle", fill: "#64748b", fontSize: 12, fontWeight: "500", children: label }, `file-${col}`));
|
|
317
|
+
}), Array.from({ length: rows }).map((_, row) => {
|
|
318
|
+
const label = coordinateStyle === "algebraic"
|
|
319
|
+
? String(rows - row)
|
|
320
|
+
: String(row + 1);
|
|
321
|
+
return (_jsx("text", { x: 10, y: row * cellSize + cellSize / 2 + 4, textAnchor: "middle", fill: "#64748b", fontSize: 12, fontWeight: "500", children: label }, `rank-${row}`));
|
|
322
|
+
})] })), _jsx("g", { className: "pieces", role: "list", "aria-label": "Game pieces", children: resolvedPieces.map((piece) => {
|
|
323
|
+
const x = labelMargin + piece.col * cellSize + cellSize / 2;
|
|
324
|
+
const y = piece.row * cellSize + cellSize / 2;
|
|
325
|
+
return (_jsx("g", { transform: `translate(${x}, ${y})`, role: "listitem", "aria-label": `${piece.owner ?? ""} ${piece.typeId}`, children: renderPiece(piece) }, piece.id));
|
|
326
|
+
}) }), enablePanZoom && transform.zoom !== 1 && (_jsxs("g", { transform: `translate(${viewBoxX + 10}, ${viewBoxY + viewBoxHeight - 30})`, children: [_jsx("rect", { x: 0, y: 0, width: 60, height: 20, rx: 4, fill: "rgba(0,0,0,0.6)" }), _jsxs("text", { x: 30, y: 14, textAnchor: "middle", fill: "white", fontSize: 12, children: [Math.round(transform.zoom * 100), "%"] })] }))] }));
|
|
327
|
+
}
|
|
328
|
+
export const SquareGrid = SquareGridImpl;
|