@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,1165 @@
|
|
|
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
|
+
|
|
6
|
+
import { useMemo, useState, type ReactNode } from "react";
|
|
7
|
+
import { clsx } from "clsx";
|
|
8
|
+
import { usePanZoom } from "../../hooks/usePanZoom.js";
|
|
9
|
+
import { handleKeyboardActivation } from "./interaction-accessibility.js";
|
|
10
|
+
import {
|
|
11
|
+
interactiveTargetRenderState,
|
|
12
|
+
isInteractiveTargetSelectable,
|
|
13
|
+
type InteractiveTargetLayer,
|
|
14
|
+
type InteractiveTargetRenderState,
|
|
15
|
+
} from "./target-layer.js";
|
|
16
|
+
import type { SquarePieceState } from "../../types/player-state.js";
|
|
17
|
+
import {
|
|
18
|
+
type AuthoredSquareBoardInput,
|
|
19
|
+
type AnySquareBoardInput,
|
|
20
|
+
type GeneratedSquareBoardInput,
|
|
21
|
+
type NormalizedSquareBoard,
|
|
22
|
+
type NormalizedSquareCellOf,
|
|
23
|
+
type NormalizedSquareEdgeOf,
|
|
24
|
+
type NormalizedSquarePieceOf,
|
|
25
|
+
type NormalizedSquareVertexOf,
|
|
26
|
+
normalizeSquareBoardInput,
|
|
27
|
+
} from "../../types/tiled-board.js";
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
InteractiveTargetLayer,
|
|
31
|
+
InteractiveTargetRenderState,
|
|
32
|
+
} from "./target-layer.js";
|
|
33
|
+
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Types
|
|
36
|
+
// ============================================================================
|
|
37
|
+
|
|
38
|
+
interface SquareCellWithId {
|
|
39
|
+
id: string;
|
|
40
|
+
row: number;
|
|
41
|
+
col: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SquareEdgePosition {
|
|
45
|
+
x1: number;
|
|
46
|
+
y1: number;
|
|
47
|
+
x2: number;
|
|
48
|
+
y2: number;
|
|
49
|
+
midX: number;
|
|
50
|
+
midY: number;
|
|
51
|
+
angle: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface SquareVertexPosition {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface InteractiveSquareEdge<
|
|
60
|
+
TBoard extends AnySquareBoardInput = AnySquareBoardInput,
|
|
61
|
+
> extends NormalizedSquareEdgeOf<TBoard> {
|
|
62
|
+
position: SquareEdgePosition;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface InteractiveSquareVertex<
|
|
66
|
+
TBoard extends AnySquareBoardInput = AnySquareBoardInput,
|
|
67
|
+
> extends NormalizedSquareVertexOf<TBoard> {
|
|
68
|
+
position: SquareVertexPosition;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type InteractiveSquareSpace<
|
|
72
|
+
TBoard extends AnySquareBoardInput = AnySquareBoardInput,
|
|
73
|
+
> = NormalizedSquareCellOf<TBoard>;
|
|
74
|
+
|
|
75
|
+
interface SquareGeneratedGridInputProps {
|
|
76
|
+
id?: string;
|
|
77
|
+
layout?: "square";
|
|
78
|
+
spaces: Extract<AnySquareBoardInput, { spaces: unknown }>["spaces"];
|
|
79
|
+
pieces?: AnySquareBoardInput["pieces"];
|
|
80
|
+
edges?: AnySquareBoardInput["edges"];
|
|
81
|
+
vertices?: AnySquareBoardInput["vertices"];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface SquareAuthoredGridInputProps {
|
|
85
|
+
id?: string;
|
|
86
|
+
layout?: "square";
|
|
87
|
+
rows?: number;
|
|
88
|
+
cols?: number;
|
|
89
|
+
cells: Extract<AnySquareBoardInput, { cells: unknown }>["cells"];
|
|
90
|
+
pieces?: readonly SquarePieceState[];
|
|
91
|
+
edges?: AnySquareBoardInput["edges"];
|
|
92
|
+
vertices?: AnySquareBoardInput["vertices"];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type SquareGridInputProps =
|
|
96
|
+
| SquareGeneratedGridInputProps
|
|
97
|
+
| SquareAuthoredGridInputProps;
|
|
98
|
+
|
|
99
|
+
type ResolvedSquareArrayProp<Value> =
|
|
100
|
+
Exclude<Value, undefined> extends readonly unknown[]
|
|
101
|
+
? Exclude<Value, undefined>
|
|
102
|
+
: readonly [];
|
|
103
|
+
|
|
104
|
+
type SquareBoardLikeOfProps<TProps extends SquareGridInputProps> =
|
|
105
|
+
TProps extends {
|
|
106
|
+
id?: infer Id;
|
|
107
|
+
layout?: infer Layout;
|
|
108
|
+
spaces: infer Spaces;
|
|
109
|
+
pieces?: infer Pieces;
|
|
110
|
+
edges?: infer Edges;
|
|
111
|
+
vertices?: infer Vertices;
|
|
112
|
+
}
|
|
113
|
+
? {
|
|
114
|
+
id: Extract<Id, string> extends never ? string : Extract<Id, string>;
|
|
115
|
+
layout?: Extract<Layout, "square">;
|
|
116
|
+
spaces: Spaces;
|
|
117
|
+
pieces: ResolvedSquareArrayProp<Pieces>;
|
|
118
|
+
edges: ResolvedSquareArrayProp<Edges>;
|
|
119
|
+
vertices: ResolvedSquareArrayProp<Vertices>;
|
|
120
|
+
} & GeneratedSquareBoardInput
|
|
121
|
+
: TProps extends {
|
|
122
|
+
id?: infer Id;
|
|
123
|
+
layout?: infer Layout;
|
|
124
|
+
rows?: infer Rows;
|
|
125
|
+
cols?: infer Cols;
|
|
126
|
+
cells: infer Cells;
|
|
127
|
+
pieces?: infer Pieces;
|
|
128
|
+
edges?: infer Edges;
|
|
129
|
+
vertices?: infer Vertices;
|
|
130
|
+
}
|
|
131
|
+
? {
|
|
132
|
+
id: Extract<Id, string> extends never ? string : Extract<Id, string>;
|
|
133
|
+
layout?: Extract<Layout, "square">;
|
|
134
|
+
rows: Extract<Rows, number> extends never
|
|
135
|
+
? number
|
|
136
|
+
: Extract<Rows, number>;
|
|
137
|
+
cols: Extract<Cols, number> extends never
|
|
138
|
+
? number
|
|
139
|
+
: Extract<Cols, number>;
|
|
140
|
+
cells: Cells;
|
|
141
|
+
pieces: ResolvedSquareArrayProp<Pieces>;
|
|
142
|
+
edges: ResolvedSquareArrayProp<Edges>;
|
|
143
|
+
vertices: ResolvedSquareArrayProp<Vertices>;
|
|
144
|
+
} & AuthoredSquareBoardInput
|
|
145
|
+
: never;
|
|
146
|
+
|
|
147
|
+
export type SquareGridProps<
|
|
148
|
+
TProps extends SquareGridInputProps = SquareGridInputProps,
|
|
149
|
+
> = TProps & {
|
|
150
|
+
cellSize?: number;
|
|
151
|
+
/** Receives row/col with transform centered at cell position */
|
|
152
|
+
renderCell: (row: number, col: number) => ReactNode;
|
|
153
|
+
/** Receives piece with transform centered at cell center */
|
|
154
|
+
renderPiece: (
|
|
155
|
+
piece: NormalizedSquarePieceOf<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
156
|
+
) => ReactNode;
|
|
157
|
+
renderEdge?: (
|
|
158
|
+
edge: NormalizedSquareEdgeOf<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
159
|
+
position: SquareEdgePosition,
|
|
160
|
+
) => ReactNode;
|
|
161
|
+
renderVertex?: (
|
|
162
|
+
vertex: NormalizedSquareVertexOf<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
163
|
+
position: SquareVertexPosition,
|
|
164
|
+
) => ReactNode;
|
|
165
|
+
showCoordinates?: boolean;
|
|
166
|
+
coordinateStyle?: "algebraic" | "numeric" | "none";
|
|
167
|
+
width?: number | string;
|
|
168
|
+
height?: number | string;
|
|
169
|
+
enablePanZoom?: boolean;
|
|
170
|
+
initialZoom?: number;
|
|
171
|
+
minZoom?: number;
|
|
172
|
+
maxZoom?: number;
|
|
173
|
+
className?: string;
|
|
174
|
+
interactiveSpaces?: InteractiveTargetLayer;
|
|
175
|
+
interactiveEdges?: InteractiveTargetLayer;
|
|
176
|
+
interactiveVertices?: InteractiveTargetLayer;
|
|
177
|
+
renderInteractiveSpace?: (
|
|
178
|
+
space: InteractiveSquareSpace<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
179
|
+
state: InteractiveTargetRenderState,
|
|
180
|
+
) => ReactNode;
|
|
181
|
+
renderInteractiveEdge?: (
|
|
182
|
+
edge: InteractiveSquareEdge<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
183
|
+
position: SquareEdgePosition,
|
|
184
|
+
state: InteractiveTargetRenderState,
|
|
185
|
+
) => ReactNode;
|
|
186
|
+
renderInteractiveVertex?: (
|
|
187
|
+
vertex: InteractiveSquareVertex<NoInfer<SquareBoardLikeOfProps<TProps>>>,
|
|
188
|
+
position: SquareVertexPosition,
|
|
189
|
+
state: InteractiveTargetRenderState,
|
|
190
|
+
) => ReactNode;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export interface SquareGridBoardProps<
|
|
194
|
+
TBoard extends AnySquareBoardInput = AnySquareBoardInput,
|
|
195
|
+
> {
|
|
196
|
+
board: TBoard;
|
|
197
|
+
cellSize?: number;
|
|
198
|
+
renderCell: (row: number, col: number) => ReactNode;
|
|
199
|
+
renderPiece: (piece: NormalizedSquarePieceOf<NoInfer<TBoard>>) => ReactNode;
|
|
200
|
+
renderEdge?: (
|
|
201
|
+
edge: NormalizedSquareEdgeOf<NoInfer<TBoard>>,
|
|
202
|
+
position: SquareEdgePosition,
|
|
203
|
+
) => ReactNode;
|
|
204
|
+
renderVertex?: (
|
|
205
|
+
vertex: NormalizedSquareVertexOf<NoInfer<TBoard>>,
|
|
206
|
+
position: SquareVertexPosition,
|
|
207
|
+
) => ReactNode;
|
|
208
|
+
showCoordinates?: boolean;
|
|
209
|
+
coordinateStyle?: "algebraic" | "numeric" | "none";
|
|
210
|
+
width?: number | string;
|
|
211
|
+
height?: number | string;
|
|
212
|
+
enablePanZoom?: boolean;
|
|
213
|
+
initialZoom?: number;
|
|
214
|
+
minZoom?: number;
|
|
215
|
+
maxZoom?: number;
|
|
216
|
+
className?: string;
|
|
217
|
+
interactiveSpaces?: InteractiveTargetLayer;
|
|
218
|
+
interactiveEdges?: InteractiveTargetLayer;
|
|
219
|
+
interactiveVertices?: InteractiveTargetLayer;
|
|
220
|
+
renderInteractiveSpace?: (
|
|
221
|
+
space: InteractiveSquareSpace<NoInfer<TBoard>>,
|
|
222
|
+
state: InteractiveTargetRenderState,
|
|
223
|
+
) => ReactNode;
|
|
224
|
+
renderInteractiveEdge?: (
|
|
225
|
+
edge: InteractiveSquareEdge<NoInfer<TBoard>>,
|
|
226
|
+
position: SquareEdgePosition,
|
|
227
|
+
state: InteractiveTargetRenderState,
|
|
228
|
+
) => ReactNode;
|
|
229
|
+
renderInteractiveVertex?: (
|
|
230
|
+
vertex: InteractiveSquareVertex<NoInfer<TBoard>>,
|
|
231
|
+
position: SquareVertexPosition,
|
|
232
|
+
state: InteractiveTargetRenderState,
|
|
233
|
+
) => ReactNode;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ============================================================================
|
|
237
|
+
// Pre-built Helper Components
|
|
238
|
+
// ============================================================================
|
|
239
|
+
|
|
240
|
+
export interface DefaultGridCellProps {
|
|
241
|
+
size: number;
|
|
242
|
+
isLight?: boolean;
|
|
243
|
+
lightColor?: string;
|
|
244
|
+
darkColor?: string;
|
|
245
|
+
isHighlighted?: boolean;
|
|
246
|
+
highlightColor?: string;
|
|
247
|
+
isSelected?: boolean;
|
|
248
|
+
selectedColor?: string;
|
|
249
|
+
isValidMove?: boolean;
|
|
250
|
+
isCapture?: boolean;
|
|
251
|
+
onClick?: () => void;
|
|
252
|
+
onPointerEnter?: () => void;
|
|
253
|
+
onPointerLeave?: () => void;
|
|
254
|
+
className?: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Pre-built grid cell component for use in `renderCell`. */
|
|
258
|
+
export function DefaultGridCell({
|
|
259
|
+
size,
|
|
260
|
+
isLight = true,
|
|
261
|
+
lightColor = "#f0d9b5",
|
|
262
|
+
darkColor = "#b58863",
|
|
263
|
+
isHighlighted = false,
|
|
264
|
+
highlightColor = "rgba(250, 204, 21, 0.4)",
|
|
265
|
+
isSelected = false,
|
|
266
|
+
selectedColor = "rgba(59, 130, 246, 0.5)",
|
|
267
|
+
isValidMove = false,
|
|
268
|
+
isCapture = false,
|
|
269
|
+
onClick,
|
|
270
|
+
onPointerEnter,
|
|
271
|
+
onPointerLeave,
|
|
272
|
+
className,
|
|
273
|
+
}: DefaultGridCellProps) {
|
|
274
|
+
const baseColor = isLight ? lightColor : darkColor;
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<g
|
|
278
|
+
onClick={onClick}
|
|
279
|
+
onPointerEnter={onPointerEnter}
|
|
280
|
+
onPointerLeave={onPointerLeave}
|
|
281
|
+
onKeyDown={(event) => handleKeyboardActivation(event, onClick)}
|
|
282
|
+
className={clsx(
|
|
283
|
+
"transition-colors duration-100",
|
|
284
|
+
onClick && "cursor-pointer",
|
|
285
|
+
className,
|
|
286
|
+
)}
|
|
287
|
+
role={onClick ? "button" : undefined}
|
|
288
|
+
tabIndex={onClick ? 0 : undefined}
|
|
289
|
+
aria-label={onClick ? "Grid cell" : undefined}
|
|
290
|
+
>
|
|
291
|
+
{/* Base cell */}
|
|
292
|
+
<rect width={size} height={size} fill={baseColor} />
|
|
293
|
+
|
|
294
|
+
{/* Selected overlay */}
|
|
295
|
+
{isSelected && (
|
|
296
|
+
<rect
|
|
297
|
+
width={size}
|
|
298
|
+
height={size}
|
|
299
|
+
fill={selectedColor}
|
|
300
|
+
pointerEvents="none"
|
|
301
|
+
/>
|
|
302
|
+
)}
|
|
303
|
+
|
|
304
|
+
{/* Highlight overlay */}
|
|
305
|
+
{isHighlighted && !isSelected && (
|
|
306
|
+
<rect
|
|
307
|
+
width={size}
|
|
308
|
+
height={size}
|
|
309
|
+
fill={highlightColor}
|
|
310
|
+
pointerEvents="none"
|
|
311
|
+
/>
|
|
312
|
+
)}
|
|
313
|
+
|
|
314
|
+
{/* Valid move indicator (dot) */}
|
|
315
|
+
{isValidMove && !isCapture && (
|
|
316
|
+
<circle
|
|
317
|
+
cx={size / 2}
|
|
318
|
+
cy={size / 2}
|
|
319
|
+
r={size * 0.15}
|
|
320
|
+
fill="rgba(34, 197, 94, 0.6)"
|
|
321
|
+
pointerEvents="none"
|
|
322
|
+
/>
|
|
323
|
+
)}
|
|
324
|
+
|
|
325
|
+
{/* Capture indicator (ring) */}
|
|
326
|
+
{isCapture && (
|
|
327
|
+
<circle
|
|
328
|
+
cx={size / 2}
|
|
329
|
+
cy={size / 2}
|
|
330
|
+
r={size * 0.42}
|
|
331
|
+
fill="none"
|
|
332
|
+
stroke="rgba(239, 68, 68, 0.8)"
|
|
333
|
+
strokeWidth={size * 0.08}
|
|
334
|
+
pointerEvents="none"
|
|
335
|
+
/>
|
|
336
|
+
)}
|
|
337
|
+
</g>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface DefaultGridPieceProps {
|
|
342
|
+
size: number;
|
|
343
|
+
color?: string;
|
|
344
|
+
strokeColor?: string;
|
|
345
|
+
label?: string;
|
|
346
|
+
isDragging?: boolean;
|
|
347
|
+
onClick?: () => void;
|
|
348
|
+
onPointerDown?: (e: React.PointerEvent) => void;
|
|
349
|
+
className?: string;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Pre-built grid piece component for use in `renderPiece`. */
|
|
353
|
+
export function DefaultGridPiece({
|
|
354
|
+
size,
|
|
355
|
+
color = "#94a3b8",
|
|
356
|
+
strokeColor,
|
|
357
|
+
label,
|
|
358
|
+
isDragging = false,
|
|
359
|
+
onClick,
|
|
360
|
+
onPointerDown,
|
|
361
|
+
className,
|
|
362
|
+
}: DefaultGridPieceProps) {
|
|
363
|
+
const radius = size * 0.38;
|
|
364
|
+
const effectiveStroke =
|
|
365
|
+
strokeColor ??
|
|
366
|
+
(color === "#f8fafc" || color === "#ffffff" ? "#1e293b" : "#f8fafc");
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<g
|
|
370
|
+
onClick={onClick}
|
|
371
|
+
onPointerDown={onPointerDown}
|
|
372
|
+
onKeyDown={(event) => handleKeyboardActivation(event, onClick)}
|
|
373
|
+
className={clsx(
|
|
374
|
+
"transition-transform duration-150",
|
|
375
|
+
(onClick || onPointerDown) && "cursor-pointer hover:scale-105",
|
|
376
|
+
className,
|
|
377
|
+
)}
|
|
378
|
+
opacity={isDragging ? 0.8 : 1}
|
|
379
|
+
role={onClick ? "button" : undefined}
|
|
380
|
+
tabIndex={onClick ? 0 : undefined}
|
|
381
|
+
aria-label={onClick ? (label ?? "Grid piece") : undefined}
|
|
382
|
+
>
|
|
383
|
+
<circle
|
|
384
|
+
r={isDragging ? radius * 1.1 : radius}
|
|
385
|
+
fill={color}
|
|
386
|
+
stroke={effectiveStroke}
|
|
387
|
+
strokeWidth={2}
|
|
388
|
+
style={{ filter: "drop-shadow(1px 2px 2px rgba(0,0,0,0.4))" }}
|
|
389
|
+
/>
|
|
390
|
+
{label && (
|
|
391
|
+
<text
|
|
392
|
+
y={4}
|
|
393
|
+
textAnchor="middle"
|
|
394
|
+
fill={effectiveStroke}
|
|
395
|
+
fontSize={size * 0.35}
|
|
396
|
+
fontWeight="bold"
|
|
397
|
+
pointerEvents="none"
|
|
398
|
+
>
|
|
399
|
+
{label}
|
|
400
|
+
</text>
|
|
401
|
+
)}
|
|
402
|
+
</g>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface DefaultChessPieceProps {
|
|
407
|
+
size: number;
|
|
408
|
+
type: string;
|
|
409
|
+
owner: "white" | "black";
|
|
410
|
+
onClick?: () => void;
|
|
411
|
+
onPointerDown?: (e: React.PointerEvent) => void;
|
|
412
|
+
className?: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const CHESS_SYMBOLS: Record<string, Record<string, string>> = {
|
|
416
|
+
white: {
|
|
417
|
+
king: "♔",
|
|
418
|
+
queen: "♕",
|
|
419
|
+
rook: "♖",
|
|
420
|
+
bishop: "♗",
|
|
421
|
+
knight: "♘",
|
|
422
|
+
pawn: "♙",
|
|
423
|
+
},
|
|
424
|
+
black: {
|
|
425
|
+
king: "♚",
|
|
426
|
+
queen: "♛",
|
|
427
|
+
rook: "♜",
|
|
428
|
+
bishop: "♝",
|
|
429
|
+
knight: "♞",
|
|
430
|
+
pawn: "♟",
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
/** Pre-built chess piece component using Unicode symbols. */
|
|
435
|
+
export function DefaultChessPiece({
|
|
436
|
+
size,
|
|
437
|
+
type,
|
|
438
|
+
owner,
|
|
439
|
+
onClick,
|
|
440
|
+
onPointerDown,
|
|
441
|
+
className,
|
|
442
|
+
}: DefaultChessPieceProps) {
|
|
443
|
+
const symbol = CHESS_SYMBOLS[owner]?.[type] ?? "?";
|
|
444
|
+
const textColor = owner === "white" ? "#f8fafc" : "#1e293b";
|
|
445
|
+
const shadowFilter =
|
|
446
|
+
owner === "white"
|
|
447
|
+
? "drop-shadow(1px 1px 1px rgba(0,0,0,0.5))"
|
|
448
|
+
: "drop-shadow(1px 1px 1px rgba(255,255,255,0.3))";
|
|
449
|
+
|
|
450
|
+
return (
|
|
451
|
+
<g
|
|
452
|
+
onClick={onClick}
|
|
453
|
+
onPointerDown={onPointerDown}
|
|
454
|
+
onKeyDown={(event) => handleKeyboardActivation(event, onClick)}
|
|
455
|
+
className={clsx(
|
|
456
|
+
(onClick || onPointerDown) && "cursor-pointer",
|
|
457
|
+
className,
|
|
458
|
+
)}
|
|
459
|
+
role={onClick ? "button" : undefined}
|
|
460
|
+
tabIndex={onClick ? 0 : undefined}
|
|
461
|
+
aria-label={onClick ? `${owner} ${type}` : undefined}
|
|
462
|
+
>
|
|
463
|
+
<text
|
|
464
|
+
textAnchor="middle"
|
|
465
|
+
dominantBaseline="middle"
|
|
466
|
+
fontSize={size * 0.7}
|
|
467
|
+
fill={textColor}
|
|
468
|
+
style={{ filter: shadowFilter }}
|
|
469
|
+
>
|
|
470
|
+
{symbol}
|
|
471
|
+
</text>
|
|
472
|
+
</g>
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// ============================================================================
|
|
477
|
+
// Utilities
|
|
478
|
+
// ============================================================================
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Convert row/col to algebraic notation (a1, b2, etc.)
|
|
482
|
+
*/
|
|
483
|
+
export function toAlgebraic(
|
|
484
|
+
row: number,
|
|
485
|
+
col: number,
|
|
486
|
+
totalRows: number,
|
|
487
|
+
): string {
|
|
488
|
+
const file = String.fromCharCode(97 + col); // a, b, c, ...
|
|
489
|
+
const rank = totalRows - row; // 8, 7, 6, ... (bottom to top)
|
|
490
|
+
return `${file}${rank}`;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Convert row/col to numeric notation (1,1, 2,3, etc.)
|
|
495
|
+
*/
|
|
496
|
+
export function toNumeric(row: number, col: number): string {
|
|
497
|
+
return `${row + 1},${col + 1}`;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function getCellId(cell: { id: string }): string {
|
|
501
|
+
return cell.id;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function edgePositionForCells(
|
|
505
|
+
firstCell: { row: number; col: number },
|
|
506
|
+
secondCell: { row: number; col: number },
|
|
507
|
+
cellSize: number,
|
|
508
|
+
labelMargin: number,
|
|
509
|
+
): SquareEdgePosition | null {
|
|
510
|
+
if (
|
|
511
|
+
Math.abs(firstCell.row - secondCell.row) +
|
|
512
|
+
Math.abs(firstCell.col - secondCell.col) !==
|
|
513
|
+
1
|
|
514
|
+
) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const minRow = Math.min(firstCell.row, secondCell.row);
|
|
519
|
+
const minCol = Math.min(firstCell.col, secondCell.col);
|
|
520
|
+
|
|
521
|
+
if (firstCell.row === secondCell.row) {
|
|
522
|
+
const x = labelMargin + (minCol + 1) * cellSize;
|
|
523
|
+
const y1 = minRow * cellSize;
|
|
524
|
+
const y2 = y1 + cellSize;
|
|
525
|
+
return {
|
|
526
|
+
x1: x,
|
|
527
|
+
y1,
|
|
528
|
+
x2: x,
|
|
529
|
+
y2,
|
|
530
|
+
midX: x,
|
|
531
|
+
midY: (y1 + y2) / 2,
|
|
532
|
+
angle: 90,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const y = (minRow + 1) * cellSize;
|
|
537
|
+
const x1 = labelMargin + minCol * cellSize;
|
|
538
|
+
const x2 = x1 + cellSize;
|
|
539
|
+
return {
|
|
540
|
+
x1,
|
|
541
|
+
y1: y,
|
|
542
|
+
x2,
|
|
543
|
+
y2: y,
|
|
544
|
+
midX: (x1 + x2) / 2,
|
|
545
|
+
midY: y,
|
|
546
|
+
angle: 0,
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function cornerKeysForCell(cell: {
|
|
551
|
+
row: number;
|
|
552
|
+
col: number;
|
|
553
|
+
}): Record<string, SquareVertexPosition> {
|
|
554
|
+
return {
|
|
555
|
+
[`${cell.col},${cell.row}`]: { x: cell.col, y: cell.row },
|
|
556
|
+
[`${cell.col + 1},${cell.row}`]: { x: cell.col + 1, y: cell.row },
|
|
557
|
+
[`${cell.col + 1},${cell.row + 1}`]: {
|
|
558
|
+
x: cell.col + 1,
|
|
559
|
+
y: cell.row + 1,
|
|
560
|
+
},
|
|
561
|
+
[`${cell.col},${cell.row + 1}`]: { x: cell.col, y: cell.row + 1 },
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function vertexPositionForCells(
|
|
566
|
+
cells: readonly SquareCellWithId[],
|
|
567
|
+
cellSize: number,
|
|
568
|
+
labelMargin: number,
|
|
569
|
+
): SquareVertexPosition | null {
|
|
570
|
+
if (cells.length === 0) {
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const candidateKeys = cells.map(
|
|
575
|
+
(cell) => new Set(Object.keys(cornerKeysForCell(cell))),
|
|
576
|
+
);
|
|
577
|
+
const firstKeySet = candidateKeys[0];
|
|
578
|
+
if (firstKeySet === undefined) {
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
const sharedKeys = [...firstKeySet].filter((key) =>
|
|
582
|
+
candidateKeys.every((keySet) => keySet.has(key)),
|
|
583
|
+
);
|
|
584
|
+
if (sharedKeys.length !== 1) {
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const sharedKey = sharedKeys[0];
|
|
589
|
+
if (!sharedKey) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
const [colToken, rowToken] = sharedKey.split(",");
|
|
593
|
+
if (colToken === undefined || rowToken === undefined) {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
const col = Number(colToken);
|
|
597
|
+
const row = Number(rowToken);
|
|
598
|
+
if (!Number.isFinite(col) || !Number.isFinite(row)) {
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
x: labelMargin + col * cellSize,
|
|
604
|
+
y: row * cellSize,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// ============================================================================
|
|
609
|
+
// Component
|
|
610
|
+
// ============================================================================
|
|
611
|
+
|
|
612
|
+
export interface SquareGridComponent {
|
|
613
|
+
<const TBoard extends AnySquareBoardInput>(
|
|
614
|
+
props: SquareGridBoardProps<TBoard>,
|
|
615
|
+
): ReactNode;
|
|
616
|
+
<const TProps extends SquareGeneratedGridInputProps>(
|
|
617
|
+
props: SquareGridProps<TProps>,
|
|
618
|
+
): ReactNode;
|
|
619
|
+
<const TProps extends SquareAuthoredGridInputProps>(
|
|
620
|
+
props: SquareGridProps<TProps>,
|
|
621
|
+
): ReactNode;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function SquareGridImpl(
|
|
625
|
+
props:
|
|
626
|
+
| SquareGridBoardProps<AnySquareBoardInput>
|
|
627
|
+
| SquareGridProps<SquareGridInputProps>,
|
|
628
|
+
) {
|
|
629
|
+
const {
|
|
630
|
+
cellSize = 60,
|
|
631
|
+
renderCell,
|
|
632
|
+
renderPiece,
|
|
633
|
+
renderEdge,
|
|
634
|
+
renderVertex,
|
|
635
|
+
showCoordinates = true,
|
|
636
|
+
coordinateStyle = "algebraic",
|
|
637
|
+
width,
|
|
638
|
+
height,
|
|
639
|
+
enablePanZoom = false,
|
|
640
|
+
initialZoom = 1,
|
|
641
|
+
minZoom = 0.5,
|
|
642
|
+
maxZoom = 3,
|
|
643
|
+
className,
|
|
644
|
+
interactiveSpaces,
|
|
645
|
+
interactiveEdges,
|
|
646
|
+
interactiveVertices,
|
|
647
|
+
renderInteractiveSpace,
|
|
648
|
+
renderInteractiveEdge,
|
|
649
|
+
renderInteractiveVertex,
|
|
650
|
+
} = props;
|
|
651
|
+
const board =
|
|
652
|
+
"board" in props
|
|
653
|
+
? props.board
|
|
654
|
+
: (("spaces" in props
|
|
655
|
+
? {
|
|
656
|
+
id: "__square-grid__",
|
|
657
|
+
spaces: props.spaces,
|
|
658
|
+
pieces: props.pieces ?? [],
|
|
659
|
+
edges: props.edges ?? [],
|
|
660
|
+
vertices: props.vertices ?? [],
|
|
661
|
+
}
|
|
662
|
+
: {
|
|
663
|
+
id: "__square-grid__",
|
|
664
|
+
rows: props.rows ?? 0,
|
|
665
|
+
cols: props.cols ?? 0,
|
|
666
|
+
cells: props.cells,
|
|
667
|
+
pieces: props.pieces ?? [],
|
|
668
|
+
edges: props.edges ?? [],
|
|
669
|
+
vertices: props.vertices ?? [],
|
|
670
|
+
}) satisfies AnySquareBoardInput);
|
|
671
|
+
const [hoveredInteractiveSpaceId, setHoveredInteractiveSpaceId] = useState<
|
|
672
|
+
string | null
|
|
673
|
+
>(null);
|
|
674
|
+
const [hoveredInteractiveEdgeId, setHoveredInteractiveEdgeId] = useState<
|
|
675
|
+
string | null
|
|
676
|
+
>(null);
|
|
677
|
+
const [hoveredInteractiveVertexId, setHoveredInteractiveVertexId] = useState<
|
|
678
|
+
string | null
|
|
679
|
+
>(null);
|
|
680
|
+
|
|
681
|
+
// Use the unified pan/zoom hook
|
|
682
|
+
const {
|
|
683
|
+
transform,
|
|
684
|
+
bind,
|
|
685
|
+
isDragging: isPanning,
|
|
686
|
+
} = usePanZoom({
|
|
687
|
+
enabled: enablePanZoom,
|
|
688
|
+
initialZoom,
|
|
689
|
+
minZoom,
|
|
690
|
+
maxZoom,
|
|
691
|
+
mode: "viewbox",
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// Coordinate label margin
|
|
695
|
+
const labelMargin = showCoordinates && coordinateStyle !== "none" ? 24 : 0;
|
|
696
|
+
|
|
697
|
+
const normalizedBoard = useMemo<NormalizedSquareBoard<AnySquareBoardInput>>(
|
|
698
|
+
() => normalizeSquareBoardInput(board),
|
|
699
|
+
[board],
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
const rows = normalizedBoard.rows;
|
|
703
|
+
const cols = normalizedBoard.cols;
|
|
704
|
+
const resolvedEdges = normalizedBoard.edges as Array<
|
|
705
|
+
NormalizedSquareEdgeOf<AnySquareBoardInput>
|
|
706
|
+
>;
|
|
707
|
+
const resolvedVertices = normalizedBoard.vertices as Array<
|
|
708
|
+
NormalizedSquareVertexOf<AnySquareBoardInput>
|
|
709
|
+
>;
|
|
710
|
+
const resolvedPieces = normalizedBoard.pieces as Array<
|
|
711
|
+
NormalizedSquarePieceOf<AnySquareBoardInput>
|
|
712
|
+
>;
|
|
713
|
+
|
|
714
|
+
// Calculate grid dimensions
|
|
715
|
+
const gridWidth = cols * cellSize;
|
|
716
|
+
const gridHeight = rows * cellSize;
|
|
717
|
+
const totalWidth = gridWidth + labelMargin;
|
|
718
|
+
const totalHeight = gridHeight + labelMargin;
|
|
719
|
+
|
|
720
|
+
const renderableCells = useMemo(() => {
|
|
721
|
+
const result: Array<{ row: number; col: number }> = [];
|
|
722
|
+
for (let row = 0; row < rows; row++) {
|
|
723
|
+
for (let col = 0; col < cols; col++) {
|
|
724
|
+
result.push({ row, col });
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return result;
|
|
728
|
+
}, [rows, cols]);
|
|
729
|
+
|
|
730
|
+
const resolvedCells = useMemo<SquareCellWithId[]>(() => {
|
|
731
|
+
if (normalizedBoard.cells.length > 0) {
|
|
732
|
+
return normalizedBoard.cells.map((cell) => ({
|
|
733
|
+
...cell,
|
|
734
|
+
id: getCellId(cell),
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
return renderableCells.map(({ row, col }) => ({
|
|
739
|
+
id: `${row},${col}`,
|
|
740
|
+
row,
|
|
741
|
+
col,
|
|
742
|
+
}));
|
|
743
|
+
}, [normalizedBoard.cells, renderableCells]);
|
|
744
|
+
|
|
745
|
+
const cellsById = useMemo(
|
|
746
|
+
() => new Map(resolvedCells.map((cell) => [cell.id, cell] as const)),
|
|
747
|
+
[resolvedCells],
|
|
748
|
+
);
|
|
749
|
+
|
|
750
|
+
const resolvedEdgePositions = useMemo(
|
|
751
|
+
() =>
|
|
752
|
+
resolvedEdges.flatMap((edge) => {
|
|
753
|
+
if (edge.spaceIds.length < 2) {
|
|
754
|
+
return [];
|
|
755
|
+
}
|
|
756
|
+
const firstCell = cellsById.get(edge.spaceIds[0] ?? "");
|
|
757
|
+
const secondCell = cellsById.get(edge.spaceIds[1] ?? "");
|
|
758
|
+
if (!firstCell || !secondCell) {
|
|
759
|
+
return [];
|
|
760
|
+
}
|
|
761
|
+
const position = edgePositionForCells(
|
|
762
|
+
firstCell,
|
|
763
|
+
secondCell,
|
|
764
|
+
cellSize,
|
|
765
|
+
labelMargin,
|
|
766
|
+
);
|
|
767
|
+
return position
|
|
768
|
+
? [
|
|
769
|
+
{
|
|
770
|
+
edge,
|
|
771
|
+
interactiveEdge: {
|
|
772
|
+
...edge,
|
|
773
|
+
position,
|
|
774
|
+
} as InteractiveSquareEdge<AnySquareBoardInput>,
|
|
775
|
+
},
|
|
776
|
+
]
|
|
777
|
+
: [];
|
|
778
|
+
}),
|
|
779
|
+
[cellSize, cellsById, resolvedEdges, labelMargin],
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
const resolvedVertexPositions = useMemo(
|
|
783
|
+
() =>
|
|
784
|
+
resolvedVertices.flatMap((vertex) => {
|
|
785
|
+
const vertexCells = vertex.spaceIds.flatMap((spaceId) => {
|
|
786
|
+
const cell = cellsById.get(spaceId);
|
|
787
|
+
return cell ? [cell] : [];
|
|
788
|
+
});
|
|
789
|
+
const position = vertexPositionForCells(
|
|
790
|
+
vertexCells,
|
|
791
|
+
cellSize,
|
|
792
|
+
labelMargin,
|
|
793
|
+
);
|
|
794
|
+
return position
|
|
795
|
+
? [
|
|
796
|
+
{
|
|
797
|
+
vertex,
|
|
798
|
+
interactiveVertex: {
|
|
799
|
+
...vertex,
|
|
800
|
+
position,
|
|
801
|
+
} as InteractiveSquareVertex<AnySquareBoardInput>,
|
|
802
|
+
},
|
|
803
|
+
]
|
|
804
|
+
: [];
|
|
805
|
+
}),
|
|
806
|
+
[cellSize, cellsById, labelMargin, resolvedVertices],
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
// Calculate viewBox for pan/zoom
|
|
810
|
+
const viewBoxWidth = totalWidth / transform.zoom;
|
|
811
|
+
const viewBoxHeight = totalHeight / transform.zoom;
|
|
812
|
+
const viewBoxX = (totalWidth - viewBoxWidth) / 2 - transform.pan.x;
|
|
813
|
+
const viewBoxY = (totalHeight - viewBoxHeight) / 2 - transform.pan.y;
|
|
814
|
+
|
|
815
|
+
// Determine SVG dimensions
|
|
816
|
+
const svgWidth = width ?? totalWidth;
|
|
817
|
+
const svgHeight = height ?? totalHeight;
|
|
818
|
+
|
|
819
|
+
return (
|
|
820
|
+
<svg
|
|
821
|
+
width={svgWidth}
|
|
822
|
+
height={svgHeight}
|
|
823
|
+
viewBox={
|
|
824
|
+
enablePanZoom
|
|
825
|
+
? `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`
|
|
826
|
+
: `0 0 ${totalWidth} ${totalHeight}`
|
|
827
|
+
}
|
|
828
|
+
className={clsx(
|
|
829
|
+
"square-grid",
|
|
830
|
+
enablePanZoom && "touch-none",
|
|
831
|
+
isPanning && "cursor-grabbing",
|
|
832
|
+
enablePanZoom && !isPanning && "cursor-grab",
|
|
833
|
+
className,
|
|
834
|
+
)}
|
|
835
|
+
{...bind()}
|
|
836
|
+
role="img"
|
|
837
|
+
aria-label={`${rows}x${cols} game grid`}
|
|
838
|
+
>
|
|
839
|
+
<defs>
|
|
840
|
+
{/* Drop shadow for pieces */}
|
|
841
|
+
<filter id="pieceShadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
842
|
+
<feDropShadow dx="1" dy="2" stdDeviation="2" floodOpacity="0.4" />
|
|
843
|
+
</filter>
|
|
844
|
+
</defs>
|
|
845
|
+
|
|
846
|
+
{/* Cells layer */}
|
|
847
|
+
<g className="cells" role="list" aria-label="Grid cells">
|
|
848
|
+
{renderableCells.map(({ row, col }) => {
|
|
849
|
+
const x = labelMargin + col * cellSize;
|
|
850
|
+
const y = row * cellSize;
|
|
851
|
+
|
|
852
|
+
return (
|
|
853
|
+
<g
|
|
854
|
+
key={`${row}-${col}`}
|
|
855
|
+
transform={`translate(${x}, ${y})`}
|
|
856
|
+
role="listitem"
|
|
857
|
+
aria-label={
|
|
858
|
+
coordinateStyle === "algebraic"
|
|
859
|
+
? toAlgebraic(row, col, rows)
|
|
860
|
+
: toNumeric(row, col)
|
|
861
|
+
}
|
|
862
|
+
>
|
|
863
|
+
{renderCell(row, col)}
|
|
864
|
+
</g>
|
|
865
|
+
);
|
|
866
|
+
})}
|
|
867
|
+
</g>
|
|
868
|
+
|
|
869
|
+
{interactiveSpaces && (
|
|
870
|
+
<g className="interactive-spaces" aria-label="Interactive spaces">
|
|
871
|
+
{resolvedCells.map((space) => {
|
|
872
|
+
const state = interactiveTargetRenderState(
|
|
873
|
+
interactiveSpaces,
|
|
874
|
+
space.id,
|
|
875
|
+
hoveredInteractiveSpaceId === space.id,
|
|
876
|
+
);
|
|
877
|
+
const isSelectable = isInteractiveTargetSelectable(
|
|
878
|
+
interactiveSpaces,
|
|
879
|
+
state,
|
|
880
|
+
);
|
|
881
|
+
const x = labelMargin + space.col * cellSize;
|
|
882
|
+
const y = space.row * cellSize;
|
|
883
|
+
return (
|
|
884
|
+
<g
|
|
885
|
+
key={space.id}
|
|
886
|
+
transform={`translate(${x}, ${y})`}
|
|
887
|
+
onClick={
|
|
888
|
+
isSelectable
|
|
889
|
+
? () => {
|
|
890
|
+
void interactiveSpaces.selectTargetId?.(space.id);
|
|
891
|
+
}
|
|
892
|
+
: undefined
|
|
893
|
+
}
|
|
894
|
+
onKeyDown={(event) =>
|
|
895
|
+
handleKeyboardActivation(
|
|
896
|
+
event,
|
|
897
|
+
isSelectable
|
|
898
|
+
? () => {
|
|
899
|
+
void interactiveSpaces.selectTargetId?.(space.id);
|
|
900
|
+
}
|
|
901
|
+
: undefined,
|
|
902
|
+
)
|
|
903
|
+
}
|
|
904
|
+
onPointerEnter={() => setHoveredInteractiveSpaceId(space.id)}
|
|
905
|
+
onPointerLeave={() =>
|
|
906
|
+
setHoveredInteractiveSpaceId((currentId) =>
|
|
907
|
+
currentId === space.id ? null : currentId,
|
|
908
|
+
)
|
|
909
|
+
}
|
|
910
|
+
className={clsx(isSelectable && "cursor-pointer")}
|
|
911
|
+
role={isSelectable ? "button" : undefined}
|
|
912
|
+
tabIndex={isSelectable ? 0 : undefined}
|
|
913
|
+
aria-label={
|
|
914
|
+
isSelectable ? `Select space ${space.id}` : undefined
|
|
915
|
+
}
|
|
916
|
+
>
|
|
917
|
+
{isSelectable && (
|
|
918
|
+
<rect
|
|
919
|
+
x={0}
|
|
920
|
+
y={0}
|
|
921
|
+
width={cellSize}
|
|
922
|
+
height={cellSize}
|
|
923
|
+
fill="rgba(255,255,255,0.001)"
|
|
924
|
+
pointerEvents="all"
|
|
925
|
+
/>
|
|
926
|
+
)}
|
|
927
|
+
{renderInteractiveSpace
|
|
928
|
+
? renderInteractiveSpace(space, state)
|
|
929
|
+
: null}
|
|
930
|
+
</g>
|
|
931
|
+
);
|
|
932
|
+
})}
|
|
933
|
+
</g>
|
|
934
|
+
)}
|
|
935
|
+
|
|
936
|
+
{renderEdge && resolvedEdgePositions.length > 0 && (
|
|
937
|
+
<g className="edges" aria-label="Board edges">
|
|
938
|
+
{resolvedEdgePositions.map(({ edge, interactiveEdge }) => (
|
|
939
|
+
<g key={edge.id}>{renderEdge(edge, interactiveEdge.position)}</g>
|
|
940
|
+
))}
|
|
941
|
+
</g>
|
|
942
|
+
)}
|
|
943
|
+
|
|
944
|
+
{interactiveEdges && (
|
|
945
|
+
<g className="interactive-edges" aria-label="Interactive edges">
|
|
946
|
+
{resolvedEdgePositions.map(({ interactiveEdge: edge }) => {
|
|
947
|
+
const state = interactiveTargetRenderState(
|
|
948
|
+
interactiveEdges,
|
|
949
|
+
edge.id,
|
|
950
|
+
hoveredInteractiveEdgeId === edge.id,
|
|
951
|
+
);
|
|
952
|
+
const isSelectable = isInteractiveTargetSelectable(
|
|
953
|
+
interactiveEdges,
|
|
954
|
+
state,
|
|
955
|
+
);
|
|
956
|
+
return (
|
|
957
|
+
<g
|
|
958
|
+
key={edge.id}
|
|
959
|
+
onClick={
|
|
960
|
+
isSelectable
|
|
961
|
+
? () => {
|
|
962
|
+
void interactiveEdges.selectTargetId?.(edge.id);
|
|
963
|
+
}
|
|
964
|
+
: undefined
|
|
965
|
+
}
|
|
966
|
+
onKeyDown={(event) =>
|
|
967
|
+
handleKeyboardActivation(
|
|
968
|
+
event,
|
|
969
|
+
isSelectable
|
|
970
|
+
? () => {
|
|
971
|
+
void interactiveEdges.selectTargetId?.(edge.id);
|
|
972
|
+
}
|
|
973
|
+
: undefined,
|
|
974
|
+
)
|
|
975
|
+
}
|
|
976
|
+
onPointerEnter={() => setHoveredInteractiveEdgeId(edge.id)}
|
|
977
|
+
onPointerLeave={() =>
|
|
978
|
+
setHoveredInteractiveEdgeId((currentId) =>
|
|
979
|
+
currentId === edge.id ? null : currentId,
|
|
980
|
+
)
|
|
981
|
+
}
|
|
982
|
+
className={clsx(isSelectable && "cursor-pointer")}
|
|
983
|
+
role={isSelectable ? "button" : undefined}
|
|
984
|
+
tabIndex={isSelectable ? 0 : undefined}
|
|
985
|
+
aria-label={isSelectable ? `Select edge ${edge.id}` : undefined}
|
|
986
|
+
>
|
|
987
|
+
{renderInteractiveEdge ? (
|
|
988
|
+
renderInteractiveEdge(edge, edge.position, state)
|
|
989
|
+
) : state.isEnabled && state.isEligible ? (
|
|
990
|
+
<line
|
|
991
|
+
x1={edge.position.x1}
|
|
992
|
+
y1={edge.position.y1}
|
|
993
|
+
x2={edge.position.x2}
|
|
994
|
+
y2={edge.position.y2}
|
|
995
|
+
stroke="rgba(255,255,255,0.001)"
|
|
996
|
+
strokeWidth={Math.max(12, cellSize * 0.18)}
|
|
997
|
+
pointerEvents="stroke"
|
|
998
|
+
/>
|
|
999
|
+
) : null}
|
|
1000
|
+
</g>
|
|
1001
|
+
);
|
|
1002
|
+
})}
|
|
1003
|
+
</g>
|
|
1004
|
+
)}
|
|
1005
|
+
|
|
1006
|
+
{renderVertex && resolvedVertexPositions.length > 0 && (
|
|
1007
|
+
<g className="vertices" aria-label="Board vertices">
|
|
1008
|
+
{resolvedVertexPositions.map(({ vertex, interactiveVertex }) => (
|
|
1009
|
+
<g key={vertex.id}>
|
|
1010
|
+
{renderVertex(vertex, interactiveVertex.position)}
|
|
1011
|
+
</g>
|
|
1012
|
+
))}
|
|
1013
|
+
</g>
|
|
1014
|
+
)}
|
|
1015
|
+
|
|
1016
|
+
{interactiveVertices && (
|
|
1017
|
+
<g className="interactive-vertices" aria-label="Interactive vertices">
|
|
1018
|
+
{resolvedVertexPositions.map(({ interactiveVertex: vertex }) => {
|
|
1019
|
+
const state = interactiveTargetRenderState(
|
|
1020
|
+
interactiveVertices,
|
|
1021
|
+
vertex.id,
|
|
1022
|
+
hoveredInteractiveVertexId === vertex.id,
|
|
1023
|
+
);
|
|
1024
|
+
const isSelectable = isInteractiveTargetSelectable(
|
|
1025
|
+
interactiveVertices,
|
|
1026
|
+
state,
|
|
1027
|
+
);
|
|
1028
|
+
return (
|
|
1029
|
+
<g
|
|
1030
|
+
key={vertex.id}
|
|
1031
|
+
onClick={
|
|
1032
|
+
isSelectable
|
|
1033
|
+
? () => {
|
|
1034
|
+
void interactiveVertices.selectTargetId?.(vertex.id);
|
|
1035
|
+
}
|
|
1036
|
+
: undefined
|
|
1037
|
+
}
|
|
1038
|
+
onKeyDown={(event) =>
|
|
1039
|
+
handleKeyboardActivation(
|
|
1040
|
+
event,
|
|
1041
|
+
isSelectable
|
|
1042
|
+
? () => {
|
|
1043
|
+
void interactiveVertices.selectTargetId?.(vertex.id);
|
|
1044
|
+
}
|
|
1045
|
+
: undefined,
|
|
1046
|
+
)
|
|
1047
|
+
}
|
|
1048
|
+
onPointerEnter={() => setHoveredInteractiveVertexId(vertex.id)}
|
|
1049
|
+
onPointerLeave={() =>
|
|
1050
|
+
setHoveredInteractiveVertexId((currentId) =>
|
|
1051
|
+
currentId === vertex.id ? null : currentId,
|
|
1052
|
+
)
|
|
1053
|
+
}
|
|
1054
|
+
className={clsx(isSelectable && "cursor-pointer")}
|
|
1055
|
+
role={isSelectable ? "button" : undefined}
|
|
1056
|
+
tabIndex={isSelectable ? 0 : undefined}
|
|
1057
|
+
aria-label={
|
|
1058
|
+
isSelectable ? `Select vertex ${vertex.id}` : undefined
|
|
1059
|
+
}
|
|
1060
|
+
>
|
|
1061
|
+
{renderInteractiveVertex ? (
|
|
1062
|
+
renderInteractiveVertex(vertex, vertex.position, state)
|
|
1063
|
+
) : state.isEnabled && state.isEligible ? (
|
|
1064
|
+
<circle
|
|
1065
|
+
cx={vertex.position.x}
|
|
1066
|
+
cy={vertex.position.y}
|
|
1067
|
+
r={Math.max(8, cellSize * 0.12)}
|
|
1068
|
+
fill="rgba(255,255,255,0.001)"
|
|
1069
|
+
pointerEvents="all"
|
|
1070
|
+
/>
|
|
1071
|
+
) : null}
|
|
1072
|
+
</g>
|
|
1073
|
+
);
|
|
1074
|
+
})}
|
|
1075
|
+
</g>
|
|
1076
|
+
)}
|
|
1077
|
+
|
|
1078
|
+
{/* Coordinate labels */}
|
|
1079
|
+
{showCoordinates && coordinateStyle !== "none" && (
|
|
1080
|
+
<g className="coordinates" aria-hidden="true">
|
|
1081
|
+
{/* File labels (a-h) - bottom */}
|
|
1082
|
+
{Array.from({ length: cols }).map((_, col) => {
|
|
1083
|
+
const label =
|
|
1084
|
+
coordinateStyle === "algebraic"
|
|
1085
|
+
? String.fromCharCode(97 + col)
|
|
1086
|
+
: String(col + 1);
|
|
1087
|
+
return (
|
|
1088
|
+
<text
|
|
1089
|
+
key={`file-${col}`}
|
|
1090
|
+
x={labelMargin + col * cellSize + cellSize / 2}
|
|
1091
|
+
y={gridHeight + 16}
|
|
1092
|
+
textAnchor="middle"
|
|
1093
|
+
fill="#64748b"
|
|
1094
|
+
fontSize={12}
|
|
1095
|
+
fontWeight="500"
|
|
1096
|
+
>
|
|
1097
|
+
{label}
|
|
1098
|
+
</text>
|
|
1099
|
+
);
|
|
1100
|
+
})}
|
|
1101
|
+
{/* Rank labels (1-8) - left */}
|
|
1102
|
+
{Array.from({ length: rows }).map((_, row) => {
|
|
1103
|
+
const label =
|
|
1104
|
+
coordinateStyle === "algebraic"
|
|
1105
|
+
? String(rows - row)
|
|
1106
|
+
: String(row + 1);
|
|
1107
|
+
return (
|
|
1108
|
+
<text
|
|
1109
|
+
key={`rank-${row}`}
|
|
1110
|
+
x={10}
|
|
1111
|
+
y={row * cellSize + cellSize / 2 + 4}
|
|
1112
|
+
textAnchor="middle"
|
|
1113
|
+
fill="#64748b"
|
|
1114
|
+
fontSize={12}
|
|
1115
|
+
fontWeight="500"
|
|
1116
|
+
>
|
|
1117
|
+
{label}
|
|
1118
|
+
</text>
|
|
1119
|
+
);
|
|
1120
|
+
})}
|
|
1121
|
+
</g>
|
|
1122
|
+
)}
|
|
1123
|
+
|
|
1124
|
+
{/* Pieces layer */}
|
|
1125
|
+
<g className="pieces" role="list" aria-label="Game pieces">
|
|
1126
|
+
{resolvedPieces.map((piece) => {
|
|
1127
|
+
const x = labelMargin + piece.col * cellSize + cellSize / 2;
|
|
1128
|
+
const y = piece.row * cellSize + cellSize / 2;
|
|
1129
|
+
|
|
1130
|
+
return (
|
|
1131
|
+
<g
|
|
1132
|
+
key={piece.id}
|
|
1133
|
+
transform={`translate(${x}, ${y})`}
|
|
1134
|
+
role="listitem"
|
|
1135
|
+
aria-label={`${piece.owner ?? ""} ${piece.typeId}`}
|
|
1136
|
+
>
|
|
1137
|
+
{renderPiece(piece)}
|
|
1138
|
+
</g>
|
|
1139
|
+
);
|
|
1140
|
+
})}
|
|
1141
|
+
</g>
|
|
1142
|
+
|
|
1143
|
+
{/* Zoom indicator */}
|
|
1144
|
+
{enablePanZoom && transform.zoom !== 1 && (
|
|
1145
|
+
<g
|
|
1146
|
+
transform={`translate(${viewBoxX + 10}, ${viewBoxY + viewBoxHeight - 30})`}
|
|
1147
|
+
>
|
|
1148
|
+
<rect
|
|
1149
|
+
x={0}
|
|
1150
|
+
y={0}
|
|
1151
|
+
width={60}
|
|
1152
|
+
height={20}
|
|
1153
|
+
rx={4}
|
|
1154
|
+
fill="rgba(0,0,0,0.6)"
|
|
1155
|
+
/>
|
|
1156
|
+
<text x={30} y={14} textAnchor="middle" fill="white" fontSize={12}>
|
|
1157
|
+
{Math.round(transform.zoom * 100)}%
|
|
1158
|
+
</text>
|
|
1159
|
+
</g>
|
|
1160
|
+
)}
|
|
1161
|
+
</svg>
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
export const SquareGrid = SquareGridImpl as SquareGridComponent;
|