@pretty-chitty/core 1.2.18 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/components/ActionLogDisplay.d.ts.map +1 -1
- package/dist/components/ActionLogDisplay.js +1 -1
- package/dist/components/ActionLogDisplay.js.map +1 -1
- package/dist/components/BottomBarButton.d.ts +3 -1
- package/dist/components/BottomBarButton.d.ts.map +1 -1
- package/dist/components/BottomBarButton.js +3 -2
- package/dist/components/BottomBarButton.js.map +1 -1
- package/dist/components/ClientTrustMatchViewer.d.ts +14 -1
- package/dist/components/ClientTrustMatchViewer.d.ts.map +1 -1
- package/dist/components/ClientTrustMatchViewer.js +25 -2
- package/dist/components/ClientTrustMatchViewer.js.map +1 -1
- package/dist/components/ContextGalleryDisplay.d.ts.map +1 -1
- package/dist/components/ContextGalleryDisplay.js +1 -1
- package/dist/components/ContextGalleryDisplay.js.map +1 -1
- package/dist/components/DemoWrapper.d.ts +30 -2
- package/dist/components/DemoWrapper.d.ts.map +1 -1
- package/dist/components/DemoWrapper.js +79 -43
- package/dist/components/DemoWrapper.js.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.js +2 -2
- package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
- package/dist/components/Gallery/BuiltItem.d.ts +6 -2
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +31 -9
- package/dist/components/Gallery/BuiltItem.js.map +1 -1
- package/dist/components/Gallery/GalleryController.d.ts +18 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryController.js +70 -1
- package/dist/components/Gallery/GalleryController.js.map +1 -1
- package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryViewer.js +48 -10
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/Gallery/LayoutManager.d.ts +6 -0
- package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
- package/dist/components/Gallery/LayoutManager.js +23 -3
- package/dist/components/Gallery/LayoutManager.js.map +1 -1
- package/dist/components/Gallery/constants.d.ts +2 -0
- package/dist/components/Gallery/constants.d.ts.map +1 -1
- package/dist/components/Gallery/constants.js +2 -0
- package/dist/components/Gallery/constants.js.map +1 -1
- package/dist/components/Gallery/registry.d.ts +34 -0
- package/dist/components/Gallery/registry.d.ts.map +1 -0
- package/dist/components/Gallery/registry.js +17 -0
- package/dist/components/Gallery/registry.js.map +1 -0
- package/dist/components/GameDesigner.d.ts.map +1 -1
- package/dist/components/GameDesigner.js +42 -10
- package/dist/components/GameDesigner.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
- package/dist/components/InlineGalleryDisplay.js +2 -2
- package/dist/components/InlineGalleryDisplay.js.map +1 -1
- package/dist/components/LiveButton.d.ts.map +1 -1
- package/dist/components/LiveButton.js +5 -2
- package/dist/components/LiveButton.js.map +1 -1
- package/dist/components/MatchViewer.d.ts +6 -1
- package/dist/components/MatchViewer.d.ts.map +1 -1
- package/dist/components/MatchViewer.js +9 -3
- package/dist/components/MatchViewer.js.map +1 -1
- package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
- package/dist/components/Panel/MultiPanel.js +18 -0
- package/dist/components/Panel/MultiPanel.js.map +1 -1
- package/dist/components/Panel/PanelContents.d.ts.map +1 -1
- package/dist/components/Panel/PanelContents.js +92 -23
- package/dist/components/Panel/PanelContents.js.map +1 -1
- package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
- package/dist/components/Panel/PanelTabStack.js +1 -1
- package/dist/components/Panel/PanelTabStack.js.map +1 -1
- package/dist/components/PanelSpark.d.ts.map +1 -1
- package/dist/components/PanelSpark.js +3 -2
- package/dist/components/PanelSpark.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +46 -14
- package/dist/components/Playground.js.map +1 -1
- package/dist/components/PromptControls.d.ts.map +1 -1
- package/dist/components/PromptControls.js +4 -2
- package/dist/components/PromptControls.js.map +1 -1
- package/dist/components/SparkLineChart.d.ts.map +1 -1
- package/dist/components/SparkLineChart.js +22 -26
- package/dist/components/SparkLineChart.js.map +1 -1
- package/dist/components/TimeControlBar.d.ts.map +1 -1
- package/dist/components/TimeControlBar.js +5 -3
- package/dist/components/TimeControlBar.js.map +1 -1
- package/dist/components/TokenizedMarkdown.d.ts +23 -0
- package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
- package/dist/components/TokenizedMarkdown.js +144 -0
- package/dist/components/TokenizedMarkdown.js.map +1 -0
- package/dist/components/TokenizedMessage.d.ts +8 -6
- package/dist/components/TokenizedMessage.d.ts.map +1 -1
- package/dist/components/TokenizedMessage.js +21 -54
- package/dist/components/TokenizedMessage.js.map +1 -1
- package/dist/components/TopBarPlayers.d.ts.map +1 -1
- package/dist/components/TopBarPlayers.js +2 -2
- package/dist/components/TopBarPlayers.js.map +1 -1
- package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
- package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
- package/dist/components/Tutorial/BrowserNarration.js +240 -0
- package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
- package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
- package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialBox.js +239 -0
- package/dist/components/Tutorial/TutorialBox.js.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
- package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.js +1132 -0
- package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
- package/dist/components/Tutorial/targetRects.d.ts +67 -0
- package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
- package/dist/components/Tutorial/targetRects.js +241 -0
- package/dist/components/Tutorial/targetRects.js.map +1 -0
- package/dist/game/Chit.d.ts +7 -0
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +22 -7
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/ClientTimeState.d.ts +14 -0
- package/dist/game/ClientTimeState.d.ts.map +1 -1
- package/dist/game/ClientTimeState.js +17 -0
- package/dist/game/ClientTimeState.js.map +1 -1
- package/dist/game/ConnectionTransport.d.ts +3 -0
- package/dist/game/ConnectionTransport.d.ts.map +1 -1
- package/dist/game/ConnectionTransport.js +13 -4
- package/dist/game/ConnectionTransport.js.map +1 -1
- package/dist/game/Game.d.ts +14 -1
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/GameTheme.d.ts +3 -0
- package/dist/game/GameTheme.d.ts.map +1 -1
- package/dist/game/GameTheme.js +2 -0
- package/dist/game/GameTheme.js.map +1 -1
- package/dist/game/Match.d.ts +74 -2
- package/dist/game/Match.d.ts.map +1 -1
- package/dist/game/Match.js +155 -4
- package/dist/game/Match.js.map +1 -1
- package/dist/game/MatchStorage.d.ts +8 -1
- package/dist/game/MatchStorage.d.ts.map +1 -1
- package/dist/game/MatchStorage.js +11 -3
- package/dist/game/MatchStorage.js.map +1 -1
- package/dist/game/Pick.d.ts +16 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +32 -1
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/PlayerChit.d.ts +3 -0
- package/dist/game/PlayerChit.d.ts.map +1 -1
- package/dist/game/PlayerChit.js +3 -0
- package/dist/game/PlayerChit.js.map +1 -1
- package/dist/game/PlayerInfo.d.ts +8 -0
- package/dist/game/PlayerInfo.d.ts.map +1 -1
- package/dist/game/PlayerInfo.js +6 -3
- package/dist/game/PlayerInfo.js.map +1 -1
- package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
- package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
- package/dist/game/PlayerPromptStatusChit.js +8 -2
- package/dist/game/PlayerPromptStatusChit.js.map +1 -1
- package/dist/game/Prompt.d.ts +15 -0
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +16 -0
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/Turn.d.ts +20 -4
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +191 -67
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/TurnState.d.ts +20 -1
- package/dist/game/TurnState.d.ts.map +1 -1
- package/dist/game/TurnState.js +22 -3
- package/dist/game/TurnState.js.map +1 -1
- package/dist/game/ai/AiClientPrompts.d.ts +177 -0
- package/dist/game/ai/AiClientPrompts.d.ts.map +1 -0
- package/dist/game/ai/AiClientPrompts.js +561 -0
- package/dist/game/ai/AiClientPrompts.js.map +1 -0
- package/dist/game/ai/AiLiveView.d.ts +2 -0
- package/dist/game/ai/AiLiveView.d.ts.map +1 -0
- package/dist/game/ai/AiLiveView.js +48 -0
- package/dist/game/ai/AiLiveView.js.map +1 -0
- package/dist/game/ai/AiPlayerView.d.ts +2 -0
- package/dist/game/ai/AiPlayerView.d.ts.map +1 -0
- package/dist/game/ai/AiPlayerView.js +91 -0
- package/dist/game/ai/AiPlayerView.js.map +1 -0
- package/dist/game/ai/connectAiPlayer.d.ts +43 -0
- package/dist/game/ai/connectAiPlayer.d.ts.map +1 -0
- package/dist/game/ai/connectAiPlayer.js +58 -0
- package/dist/game/ai/connectAiPlayer.js.map +1 -0
- package/dist/game/ai/defineAi.d.ts +119 -0
- package/dist/game/ai/defineAi.d.ts.map +1 -0
- package/dist/game/ai/defineAi.js +122 -0
- package/dist/game/ai/defineAi.js.map +1 -0
- package/dist/game/ai/simulateMatches.d.ts +62 -0
- package/dist/game/ai/simulateMatches.d.ts.map +1 -0
- package/dist/game/ai/simulateMatches.js +108 -0
- package/dist/game/ai/simulateMatches.js.map +1 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.js +30 -1
- package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientTime.d.ts +13 -0
- package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientTime.js +51 -11
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/tutorial/TutorialController.d.ts +300 -0
- package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialController.js +1182 -0
- package/dist/game/tutorial/TutorialController.js.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.js +261 -0
- package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
- package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
- package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialTheme.js +39 -0
- package/dist/game/tutorial/TutorialTheme.js.map +1 -0
- package/dist/game/tutorial/allowed.d.ts +2 -0
- package/dist/game/tutorial/allowed.d.ts.map +1 -0
- package/dist/game/tutorial/allowed.js +119 -0
- package/dist/game/tutorial/allowed.js.map +1 -0
- package/dist/game/tutorial/checks.d.ts +58 -0
- package/dist/game/tutorial/checks.d.ts.map +1 -0
- package/dist/game/tutorial/checks.js +144 -0
- package/dist/game/tutorial/checks.js.map +1 -0
- package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
- package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
- package/dist/game/tutorial/createDemoMatch.js +67 -0
- package/dist/game/tutorial/createDemoMatch.js.map +1 -0
- package/dist/game/tutorial/defineTutorial.d.ts +353 -0
- package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/defineTutorial.js +86 -0
- package/dist/game/tutorial/defineTutorial.js.map +1 -0
- package/dist/game/tutorial/runTutorial.d.ts +63 -0
- package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/runTutorial.js +273 -0
- package/dist/game/tutorial/runTutorial.js.map +1 -0
- package/dist/hooks/usePanelNavigation.d.ts +28 -0
- package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
- package/dist/hooks/usePanelNavigation.js +36 -0
- package/dist/hooks/usePanelNavigation.js.map +1 -0
- package/dist/hooks/useTimeController.d.ts +2 -1
- package/dist/hooks/useTimeController.d.ts.map +1 -1
- package/dist/hooks/useTimeController.js +6 -2
- package/dist/hooks/useTimeController.js.map +1 -1
- package/dist/hooks/useTokenMap.d.ts +2 -4
- package/dist/hooks/useTokenMap.d.ts.map +1 -1
- package/dist/hooks/useTokenMap.js +2 -5
- package/dist/hooks/useTokenMap.js.map +1 -1
- package/dist/hooks/useTutorial.d.ts +48 -0
- package/dist/hooks/useTutorial.d.ts.map +1 -0
- package/dist/hooks/useTutorial.js +16 -0
- package/dist/hooks/useTutorial.js.map +1 -0
- package/dist/index.d.ts +57 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +12 -0
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
- package/dist/pretty-chitty.js +204513 -0
- package/dist/pretty-chitty.js.map +1 -0
- package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
- package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.js +16 -0
- package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.d.ts +1 -0
- package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +12 -0
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts +9 -1
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +28 -0
- package/dist/rendering/ChitRenderInstance.js.map +1 -1
- package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
- package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/RootChitRenderInstance.js +29 -0
- package/dist/rendering/RootChitRenderInstance.js.map +1 -1
- package/dist/utilities/Annotations.d.ts +15 -0
- package/dist/utilities/Annotations.d.ts.map +1 -1
- package/dist/utilities/Annotations.js +31 -7
- package/dist/utilities/Annotations.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.d.ts +13 -0
- package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.js +66 -15
- package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
- package/dist/utilities/TokenizedText.d.ts +55 -0
- package/dist/utilities/TokenizedText.d.ts.map +1 -0
- package/dist/utilities/TokenizedText.js +47 -0
- package/dist/utilities/TokenizedText.js.map +1 -0
- package/dist/utilities/zIndex.d.ts +1 -0
- package/dist/utilities/zIndex.d.ts.map +1 -1
- package/dist/utilities/zIndex.js +1 -0
- package/dist/utilities/zIndex.js.map +1 -1
- package/package.json +3 -2
- package/src/library/components/ActionLogDisplay.tsx +1 -0
- package/src/library/components/BottomBarButton.tsx +5 -0
- package/src/library/components/ClientTrustMatchViewer.tsx +32 -2
- package/src/library/components/ContextGalleryDisplay.tsx +2 -0
- package/src/library/components/DemoWrapper.tsx +147 -52
- package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
- package/src/library/components/Gallery/BuiltItem.ts +34 -9
- package/src/library/components/Gallery/GalleryController.ts +75 -2
- package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
- package/src/library/components/Gallery/LayoutManager.ts +30 -6
- package/src/library/components/Gallery/constants.ts +2 -0
- package/src/library/components/Gallery/registry.ts +44 -0
- package/src/library/components/GameDesigner.tsx +121 -12
- package/src/library/components/InlineGalleryDisplay.tsx +5 -0
- package/src/library/components/LiveButton.tsx +8 -5
- package/src/library/components/MatchViewer.tsx +14 -3
- package/src/library/components/Panel/MultiPanel.tsx +21 -0
- package/src/library/components/Panel/PanelContents.tsx +70 -1
- package/src/library/components/Panel/PanelTabStack.tsx +1 -0
- package/src/library/components/PanelSpark.tsx +9 -4
- package/src/library/components/Playground.tsx +125 -33
- package/src/library/components/PromptControls.tsx +7 -3
- package/src/library/components/SparkLineChart.tsx +23 -27
- package/src/library/components/TimeControlBar.tsx +5 -3
- package/src/library/components/TokenizedMarkdown.tsx +224 -0
- package/src/library/components/TokenizedMessage.tsx +30 -95
- package/src/library/components/TopBarPlayers.tsx +18 -10
- package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
- package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
- package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
- package/src/library/components/Tutorial/TutorialOverlay.tsx +1301 -0
- package/src/library/components/Tutorial/targetRects.ts +273 -0
- package/src/library/game/Chit.ts +23 -7
- package/src/library/game/ClientTimeState.ts +18 -0
- package/src/library/game/ConnectionTransport.ts +12 -3
- package/src/library/game/Game.ts +16 -1
- package/src/library/game/GameTheme.ts +4 -0
- package/src/library/game/Match.ts +174 -5
- package/src/library/game/MatchStorage.ts +14 -4
- package/src/library/game/Pick.ts +36 -1
- package/src/library/game/PlayerChit.ts +4 -1
- package/src/library/game/PlayerInfo.ts +13 -3
- package/src/library/game/PlayerPromptStatusChit.ts +8 -2
- package/src/library/game/Prompt.ts +20 -0
- package/src/library/game/Turn.ts +198 -68
- package/src/library/game/TurnState.ts +34 -3
- package/src/library/game/ai/AI_GUIDE.md +444 -0
- package/src/library/game/ai/AiClientPrompts.ts +730 -0
- package/src/library/game/ai/AiLiveView.ts +63 -0
- package/src/library/game/ai/AiPlayerView.ts +114 -0
- package/src/library/game/ai/ai.test.ts +475 -0
- package/src/library/game/ai/connectAiPlayer.ts +88 -0
- package/src/library/game/ai/defineAi.ts +230 -0
- package/src/library/game/ai/simulateMatches.ts +172 -0
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +3 -0
- package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
- package/src/library/game/clientTransport/ClientTime.ts +54 -13
- package/src/library/game/serialize.test.ts +275 -0
- package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
- package/src/library/game/tutorial/TutorialController.test.ts +731 -0
- package/src/library/game/tutorial/TutorialController.ts +1286 -0
- package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
- package/src/library/game/tutorial/TutorialTheme.ts +67 -0
- package/src/library/game/tutorial/allowed.ts +145 -0
- package/src/library/game/tutorial/checks.ts +186 -0
- package/src/library/game/tutorial/createDemoMatch.ts +115 -0
- package/src/library/game/tutorial/defineTutorial.ts +414 -0
- package/src/library/game/tutorial/runTutorial.ts +331 -0
- package/src/library/game/undo.test.ts +282 -0
- package/src/library/hooks/usePanelNavigation.tsx +65 -0
- package/src/library/hooks/useTimeController.tsx +6 -2
- package/src/library/hooks/useTokenMap.ts +2 -6
- package/src/library/hooks/useTutorial.tsx +76 -0
- package/src/library/index.ts +91 -4
- package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
- package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
- package/src/library/rendering/ChitRenderInstance.ts +34 -0
- package/src/library/rendering/RootChitRenderInstance.ts +30 -1
- package/src/library/utilities/Annotations.ts +35 -7
- package/src/library/utilities/CanvasStack/CanvasStack.ts +74 -29
- package/src/library/utilities/TokenizedText.test.ts +32 -0
- package/src/library/utilities/TokenizedText.ts +103 -0
- package/src/library/utilities/zIndex.ts +1 -0
|
@@ -21,6 +21,11 @@ import {
|
|
|
21
21
|
InputLabel,
|
|
22
22
|
IconButton,
|
|
23
23
|
Tooltip,
|
|
24
|
+
Checkbox,
|
|
25
|
+
FormControlLabel,
|
|
26
|
+
FormGroup,
|
|
27
|
+
FormLabel,
|
|
28
|
+
Typography,
|
|
24
29
|
} from "@mui/material";
|
|
25
30
|
import { Add, Delete, Refresh, GridOn, PhoneIphone, Tab as TabIcon, Upload, Download, LinkOff } from "@mui/icons-material";
|
|
26
31
|
import useLocalStorageState from "use-local-storage-state";
|
|
@@ -51,6 +56,8 @@ interface SavedMatchInfo {
|
|
|
51
56
|
playerCount: number;
|
|
52
57
|
matchOptions: any;
|
|
53
58
|
createdAt: number;
|
|
59
|
+
/** Seat indexes played by AI */
|
|
60
|
+
aiSeats?: number[];
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
// Helper functions for match storage
|
|
@@ -119,7 +126,7 @@ function NewMatchDialog({
|
|
|
119
126
|
}: {
|
|
120
127
|
open: boolean;
|
|
121
128
|
onClose: () => void;
|
|
122
|
-
onCreate: (name: string, playerCount: number, matchOptions: any) => void;
|
|
129
|
+
onCreate: (name: string, playerCount: number, matchOptions: any, aiSeats: number[]) => void;
|
|
123
130
|
configOptions: SelectablePropertyInfo[];
|
|
124
131
|
minPlayers: number;
|
|
125
132
|
maxPlayers: number;
|
|
@@ -129,17 +136,24 @@ function NewMatchDialog({
|
|
|
129
136
|
const [name, setName] = useState(`Match ${Date.now()}`);
|
|
130
137
|
const [playerCount, setPlayerCount] = useState(defaultPlayerCount);
|
|
131
138
|
const [matchOptions, setMatchOptions] = useState<any>({ ...defaultMatchOptions });
|
|
139
|
+
const [aiSeats, setAiSeats] = useState<number[]>([]);
|
|
132
140
|
|
|
133
141
|
useEffect(() => {
|
|
134
142
|
if (open) {
|
|
135
143
|
setName(`Match ${new Date().toLocaleString()}`);
|
|
136
144
|
setPlayerCount(defaultPlayerCount);
|
|
137
145
|
setMatchOptions({ ...defaultMatchOptions });
|
|
146
|
+
setAiSeats([]);
|
|
138
147
|
}
|
|
139
148
|
}, [open, defaultPlayerCount, defaultMatchOptions]);
|
|
140
149
|
|
|
141
150
|
const handleCreate = () => {
|
|
142
|
-
onCreate(
|
|
151
|
+
onCreate(
|
|
152
|
+
name,
|
|
153
|
+
playerCount,
|
|
154
|
+
matchOptions,
|
|
155
|
+
aiSeats.filter((seat) => seat < playerCount),
|
|
156
|
+
);
|
|
143
157
|
onClose();
|
|
144
158
|
};
|
|
145
159
|
|
|
@@ -174,27 +188,75 @@ function NewMatchDialog({
|
|
|
174
188
|
))}
|
|
175
189
|
</Select>
|
|
176
190
|
</FormControl>
|
|
177
|
-
|
|
178
|
-
<
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
</
|
|
197
|
-
|
|
191
|
+
<FormControl component="fieldset">
|
|
192
|
+
<FormLabel component="legend">AI players</FormLabel>
|
|
193
|
+
<FormGroup row>
|
|
194
|
+
{[...new Array(playerCount)].map((_, seat) => (
|
|
195
|
+
<FormControlLabel
|
|
196
|
+
key={seat}
|
|
197
|
+
label={generatePlayerName(seat)}
|
|
198
|
+
control={
|
|
199
|
+
<Checkbox
|
|
200
|
+
checked={aiSeats.includes(seat)}
|
|
201
|
+
onChange={(e) =>
|
|
202
|
+
setAiSeats((prev) =>
|
|
203
|
+
e.target.checked ? [...prev, seat] : prev.filter((s) => s !== seat),
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
/>
|
|
207
|
+
}
|
|
208
|
+
/>
|
|
209
|
+
))}
|
|
210
|
+
</FormGroup>
|
|
211
|
+
</FormControl>
|
|
212
|
+
{configOptions.map((option) => {
|
|
213
|
+
const setOption = (value: unknown) =>
|
|
214
|
+
setMatchOptions((prev: any) => ({ ...prev, [option.fieldName]: value }));
|
|
215
|
+
if (option.config.multiple) {
|
|
216
|
+
const selected: string[] = matchOptions[option.fieldName] ?? option.currentValue ?? [];
|
|
217
|
+
return (
|
|
218
|
+
<FormControl key={option.fieldName} component="fieldset">
|
|
219
|
+
<FormLabel component="legend">{option.config.label}</FormLabel>
|
|
220
|
+
<FormGroup>
|
|
221
|
+
{option.config.choices.map((choice) => (
|
|
222
|
+
<FormControlLabel
|
|
223
|
+
key={choice.id}
|
|
224
|
+
label={choice.label ?? choice.id}
|
|
225
|
+
control={
|
|
226
|
+
<Checkbox
|
|
227
|
+
checked={selected.includes(choice.id)}
|
|
228
|
+
onChange={(e) =>
|
|
229
|
+
setOption(
|
|
230
|
+
e.target.checked
|
|
231
|
+
? [...selected, choice.id]
|
|
232
|
+
: selected.filter((id) => id !== choice.id),
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
/>
|
|
236
|
+
}
|
|
237
|
+
/>
|
|
238
|
+
))}
|
|
239
|
+
</FormGroup>
|
|
240
|
+
</FormControl>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return (
|
|
244
|
+
<FormControl key={option.fieldName} fullWidth>
|
|
245
|
+
<InputLabel>{option.config.label}</InputLabel>
|
|
246
|
+
<Select
|
|
247
|
+
value={matchOptions[option.fieldName] ?? option.currentValue}
|
|
248
|
+
label={option.config.label}
|
|
249
|
+
onChange={(e) => setOption(e.target.value)}
|
|
250
|
+
>
|
|
251
|
+
{option.config.choices.map((choice) => (
|
|
252
|
+
<MenuItem key={choice.id} value={choice.id}>
|
|
253
|
+
{choice.label ?? choice.id}
|
|
254
|
+
</MenuItem>
|
|
255
|
+
))}
|
|
256
|
+
</Select>
|
|
257
|
+
</FormControl>
|
|
258
|
+
);
|
|
259
|
+
})}
|
|
198
260
|
</Stack>
|
|
199
261
|
</DialogContent>
|
|
200
262
|
<DialogActions>
|
|
@@ -477,9 +539,26 @@ function PlayerEditor({
|
|
|
477
539
|
);
|
|
478
540
|
}
|
|
479
541
|
|
|
542
|
+
/** Seats a person plays in the Playground. AI seats play themselves, so they get no view. */
|
|
543
|
+
function humanSeats(match: Match<any, any>) {
|
|
544
|
+
return match.players.filter((p) => !p.ai);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function NoHumanSeats() {
|
|
548
|
+
return (
|
|
549
|
+
<Box sx={{ p: 2 }}>
|
|
550
|
+
<Typography>Every seat in this match is played by AI, so there is nothing to show.</Typography>
|
|
551
|
+
</Box>
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
|
|
480
555
|
function MatchGrid({ match, disconnectSignal }: { match: Match<any, any>; disconnectSignal: number }) {
|
|
481
|
-
|
|
482
|
-
|
|
556
|
+
const seats = humanSeats(match);
|
|
557
|
+
if (seats.length === 0) {
|
|
558
|
+
return <NoHumanSeats />;
|
|
559
|
+
}
|
|
560
|
+
let rows = Math.ceil(Math.sqrt(seats.length));
|
|
561
|
+
let columns = Math.ceil(seats.length / rows);
|
|
483
562
|
|
|
484
563
|
if (rows > columns) {
|
|
485
564
|
const t = rows;
|
|
@@ -487,7 +566,7 @@ function MatchGrid({ match, disconnectSignal }: { match: Match<any, any>; discon
|
|
|
487
566
|
columns = t;
|
|
488
567
|
}
|
|
489
568
|
|
|
490
|
-
const playerRows =
|
|
569
|
+
const playerRows = seats.reduce((acc: PlayerInfo[][], player, i) => {
|
|
491
570
|
const rowIndex = Math.floor(i / columns);
|
|
492
571
|
acc[rowIndex] ??= [];
|
|
493
572
|
acc[rowIndex].push(player);
|
|
@@ -512,7 +591,11 @@ function MatchTabs({ match, disconnectSignal }: { match: Match<any, any>; discon
|
|
|
512
591
|
const [tabIndex, setTabIndex] = useLocalStorageState("selectedPlayerIndex", {
|
|
513
592
|
defaultValue: 0,
|
|
514
593
|
});
|
|
515
|
-
|
|
594
|
+
const seats = humanSeats(match);
|
|
595
|
+
if (seats.length === 0) {
|
|
596
|
+
return <NoHumanSeats />;
|
|
597
|
+
}
|
|
598
|
+
if (tabIndex >= seats.length && tabIndex > 0) {
|
|
516
599
|
setTabIndex(0);
|
|
517
600
|
return null;
|
|
518
601
|
}
|
|
@@ -526,12 +609,12 @@ function MatchTabs({ match, disconnectSignal }: { match: Match<any, any>; discon
|
|
|
526
609
|
textColor="inherit"
|
|
527
610
|
variant="fullWidth"
|
|
528
611
|
>
|
|
529
|
-
{
|
|
612
|
+
{seats.map((p) => (
|
|
530
613
|
<Tab label={p.name} key={p.id} />
|
|
531
614
|
))}
|
|
532
615
|
</Tabs>
|
|
533
616
|
<Box flex={1} sx={{ height: "100%" }}>
|
|
534
|
-
{[
|
|
617
|
+
{[seats[tabIndex].id].map((id) => (
|
|
535
618
|
<PlayerEditor key={id} playerId={id} match={match} disconnectSignal={disconnectSignal} />
|
|
536
619
|
))}
|
|
537
620
|
</Box>
|
|
@@ -540,10 +623,14 @@ function MatchTabs({ match, disconnectSignal }: { match: Match<any, any>; discon
|
|
|
540
623
|
}
|
|
541
624
|
|
|
542
625
|
function MatchPhone({ match, disconnectSignal }: { match: Match<any, any>; disconnectSignal: number }) {
|
|
626
|
+
const seats = humanSeats(match);
|
|
627
|
+
if (seats.length === 0) {
|
|
628
|
+
return <NoHumanSeats />;
|
|
629
|
+
}
|
|
543
630
|
return (
|
|
544
631
|
<Box sx={{ height: "100%", width: "100%", overflow: "scroll" }}>
|
|
545
|
-
<Stack direction={"row"} sx={{ width: `${390 *
|
|
546
|
-
{
|
|
632
|
+
<Stack direction={"row"} sx={{ width: `${390 * seats.length}px` }}>
|
|
633
|
+
{seats.map((p) => (
|
|
547
634
|
<Box key={p.id} sx={{ width: `390px`, height: "684px" }}>
|
|
548
635
|
<PlayerEditor showBack playerId={p.id} match={match} disconnectSignal={disconnectSignal} />
|
|
549
636
|
</Box>
|
|
@@ -575,7 +662,10 @@ function Editor({
|
|
|
575
662
|
|
|
576
663
|
const players: PlayerInfo[] = [];
|
|
577
664
|
for (let i = 0; i < matchInfo.playerCount; i++) {
|
|
578
|
-
|
|
665
|
+
const isAi = matchInfo.aiSeats?.includes(i);
|
|
666
|
+
const player = new PlayerInfo(`p${i}`, isAi ? `${generatePlayerName(i)} (AI)` : generatePlayerName(i));
|
|
667
|
+
player.ai = isAi ? {} : undefined;
|
|
668
|
+
players.push(player);
|
|
579
669
|
}
|
|
580
670
|
|
|
581
671
|
const newMatch = new Match(game, players, newStorage, matchInfo.matchOptions);
|
|
@@ -585,6 +675,7 @@ function Editor({
|
|
|
585
675
|
if (cancelled) {
|
|
586
676
|
return;
|
|
587
677
|
}
|
|
678
|
+
newMatch.seatAiPlayers({ thinkMs: [400, 900] });
|
|
588
679
|
newMatch.start();
|
|
589
680
|
setMatch(newMatch);
|
|
590
681
|
});
|
|
@@ -693,7 +784,7 @@ export default function Playground({ game }: { game: Game<any, any> }) {
|
|
|
693
784
|
});
|
|
694
785
|
}, [loadingStates]);
|
|
695
786
|
|
|
696
|
-
const handleCreateMatch = (name: string, playerCount: number, matchOptions: any) => {
|
|
787
|
+
const handleCreateMatch = (name: string, playerCount: number, matchOptions: any, aiSeats: number[]) => {
|
|
697
788
|
const matchId = generateMatchId();
|
|
698
789
|
const newMatchInfo: SavedMatchInfo = {
|
|
699
790
|
matchId,
|
|
@@ -701,6 +792,7 @@ export default function Playground({ game }: { game: Game<any, any> }) {
|
|
|
701
792
|
playerCount,
|
|
702
793
|
matchOptions,
|
|
703
794
|
createdAt: Date.now(),
|
|
795
|
+
aiSeats,
|
|
704
796
|
};
|
|
705
797
|
saveMatchMeta(gameName, newMatchInfo);
|
|
706
798
|
const matchIds = loadMatchList(gameName);
|
|
@@ -99,6 +99,8 @@ export default function PromptControls({ collapsible }: { collapsible?: boolean
|
|
|
99
99
|
const speed = useAnimationSpeedMultiplier();
|
|
100
100
|
const clientPrompt = useClientPrompts();
|
|
101
101
|
const [prompt] = useEventChannelState(clientPrompt.currentPrompt);
|
|
102
|
+
const [undoOverride] = useEventChannelState(clientPrompt.undoOverride);
|
|
103
|
+
const canUndo = !!prompt?.canReset;
|
|
102
104
|
const [promptSpec] = useEventChannelState(clientPrompt.getPromptEventChannelForPlayer(playerId));
|
|
103
105
|
const [expandedBecauseOfPrompt, setExpandedBecauseOfPrompt] = useState(!!prompt);
|
|
104
106
|
const [live] = useEventChannelState(timeState.live);
|
|
@@ -127,6 +129,7 @@ export default function PromptControls({ collapsible }: { collapsible?: boolean
|
|
|
127
129
|
return (
|
|
128
130
|
<Stack
|
|
129
131
|
direction="row"
|
|
132
|
+
data-tutorial-target="prompt"
|
|
130
133
|
sx={{
|
|
131
134
|
position: collapsible ? "absolute" : "static",
|
|
132
135
|
overflow: "hidden",
|
|
@@ -167,12 +170,13 @@ export default function PromptControls({ collapsible }: { collapsible?: boolean
|
|
|
167
170
|
</GameDialog>
|
|
168
171
|
)} */}
|
|
169
172
|
|
|
170
|
-
{prompt
|
|
173
|
+
{prompt && canUndo && (
|
|
171
174
|
<BottomBarButton
|
|
172
175
|
icon={Replay}
|
|
173
176
|
label="Undo"
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
tutorialTarget="undo"
|
|
178
|
+
onClick={() => (undoOverride ? undoOverride.undo() : prompt.stepBack())}
|
|
179
|
+
onLongClick={() => (undoOverride ? undoOverride.undo() : prompt.stepBack(true))}
|
|
176
180
|
/>
|
|
177
181
|
)}
|
|
178
182
|
<Box flex={1} />
|
|
@@ -28,32 +28,30 @@ interface SparkLineChartProps {
|
|
|
28
28
|
width?: number;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const HALO_OPACITY = 0.
|
|
31
|
+
const HALO_OPACITY = 0.85;
|
|
32
32
|
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// black and white read as arbitrary noise.
|
|
33
|
+
// The halo is the bg itself, made opaque — a knockout that cuts each line and
|
|
34
|
+
// label cleanly out of the grid and the lines it crosses, invisible against the
|
|
35
|
+
// bg. A halo opposite the bg reads as grey fuzz around everything.
|
|
37
36
|
function getUnifiedHaloColor(backgroundColor: string): string {
|
|
38
|
-
return Color(backgroundColor).
|
|
37
|
+
return Color(backgroundColor).alpha(1).hex();
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (candidate.contrast(halo) >= minRatio) return candidate.hex();
|
|
40
|
+
// A player colour too close to the bg's luminance (dark red on a dark dialog)
|
|
41
|
+
// would vanish, so step its HSL lightness away from the bg until WCAG contrast
|
|
42
|
+
// clears the large-text threshold (the 20px bold labels). Hue and saturation
|
|
43
|
+
// are kept, so the colour still reads as that player's; colours that already
|
|
44
|
+
// contrast are left untouched.
|
|
45
|
+
function adjustLineForBackground(lineColor: string, backgroundColor: string, minRatio = 3): string {
|
|
46
|
+
const bg = Color(backgroundColor).alpha(1);
|
|
47
|
+
const line = Color(lineColor).alpha(1);
|
|
48
|
+
if (line.contrast(bg) >= minRatio) return line.hex();
|
|
49
|
+
const step = bg.isDark() ? 5 : -5;
|
|
50
|
+
for (let l = line.lightness() + step; l > 0 && l < 100; l += step) {
|
|
51
|
+
const candidate = line.lightness(l);
|
|
52
|
+
if (candidate.contrast(bg) >= minRatio) return candidate.hex();
|
|
55
53
|
}
|
|
56
|
-
return
|
|
54
|
+
return bg.isDark() ? "#ffffff" : "#000000";
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
export function SparkLineChart({
|
|
@@ -168,14 +166,12 @@ export function SparkLineChart({
|
|
|
168
166
|
const getY = (value: number) => chartHeight - ((value - chartMinValue) / chartValueRange) * chartHeight;
|
|
169
167
|
const chartEndX = chartWidth;
|
|
170
168
|
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
// bg the halo is dark, all the light pastels keep their hue, and the lone
|
|
174
|
-
// dark line gets lightened until the dark halo can actually frame it.
|
|
169
|
+
// Lines keep their player colours unless they'd sink into the bg; the halo
|
|
170
|
+
// matches the bg so it separates without tinting anything.
|
|
175
171
|
const haloColor = getUnifiedHaloColor(backgroundColor);
|
|
176
172
|
const displayLines = lines.map((line) => ({
|
|
177
173
|
...line,
|
|
178
|
-
color:
|
|
174
|
+
color: adjustLineForBackground(line.color, backgroundColor),
|
|
179
175
|
}));
|
|
180
176
|
|
|
181
177
|
return (
|
|
@@ -231,7 +227,7 @@ export function SparkLineChart({
|
|
|
231
227
|
|
|
232
228
|
return (
|
|
233
229
|
<g key={line.id}>
|
|
234
|
-
{/*
|
|
230
|
+
{/* Bg-coloured knockout behind every line. */}
|
|
235
231
|
<path
|
|
236
232
|
d={extendedPathData}
|
|
237
233
|
fill="none"
|
|
@@ -15,11 +15,13 @@ export default function TimeControlBar({ autoLive = false }: { autoLive?: boolea
|
|
|
15
15
|
const [live, setLive] = useEventChannelState(timeState.live);
|
|
16
16
|
const [targetClock, setTargetClock] = useEventChannelState(timeState.targetClock);
|
|
17
17
|
const [maxClock] = useEventChannelState(timeController.maxClock);
|
|
18
|
+
const [hold] = useEventChannelState(timeState.timelineHold);
|
|
19
|
+
const end = hold === undefined ? maxClock.clock : Math.min(hold, maxClock.clock);
|
|
18
20
|
const modalState = useModalState();
|
|
19
21
|
const [settingsVisible, setSettingsVisible] = useEventChannelState(modalState.settingsVisible);
|
|
20
22
|
|
|
21
23
|
return (
|
|
22
|
-
<Box sx={{ width: "100%", height: "100%", position: "relative" }}>
|
|
24
|
+
<Box data-tutorial-target="time" sx={{ width: "100%", height: "100%", position: "relative" }}>
|
|
23
25
|
<Box sx={{ height: "6px", position: "absolute", width: "100%" }}>
|
|
24
26
|
{targetClock < maxClock.clock && !live && (
|
|
25
27
|
<Box
|
|
@@ -50,11 +52,11 @@ export default function TimeControlBar({ autoLive = false }: { autoLive?: boolea
|
|
|
50
52
|
}}
|
|
51
53
|
/>
|
|
52
54
|
<BottomBarButton
|
|
53
|
-
disabled={targetClock >=
|
|
55
|
+
disabled={targetClock >= end}
|
|
54
56
|
icon={FastForward}
|
|
55
57
|
label={"Forward"}
|
|
56
58
|
whileHolding={(n: number) => {
|
|
57
|
-
if (autoLive && targetClock + n >=
|
|
59
|
+
if (autoLive && targetClock + n >= end) {
|
|
58
60
|
setLive(true);
|
|
59
61
|
setTargetClock(targetClock + n);
|
|
60
62
|
} else {
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import Markdown, { Components } from "react-markdown";
|
|
3
|
+
import { Box } from "@mui/material";
|
|
4
|
+
import { Token } from "./TokenizedMessage";
|
|
5
|
+
import { TokenDefinition, TokenMap } from "../utilities/TokenizedText";
|
|
6
|
+
import { UpdatingCanvasImage } from "./UpdatingCanvasImage";
|
|
7
|
+
import { StaticImage } from "../utilities/StaticImage";
|
|
8
|
+
|
|
9
|
+
export interface TokenizedMarkdownProps {
|
|
10
|
+
/** Markdown. `:token:` references render as the game's icons, like log lines. */
|
|
11
|
+
text: string;
|
|
12
|
+
fontSize: number;
|
|
13
|
+
tokenMap?: TokenMap;
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Sentence to emphasise (0-based, counted across the whole text); others are dimmed. -1 for none. */
|
|
16
|
+
activeSentence?: number;
|
|
17
|
+
/** Opacity of sentences other than the active one. Default 0.55 */
|
|
18
|
+
dimmedOpacity?: number;
|
|
19
|
+
/** Colour of the active sentence. Default: inherit */
|
|
20
|
+
accent?: string;
|
|
21
|
+
/** Resolves relative image URLs. Default: unchanged */
|
|
22
|
+
resolveImage?: (src: string) => string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const TOKEN_REGEX = /:([a-zA-Z0-9_-]+):/g;
|
|
26
|
+
const SENTENCE_END = /[.!?]+["')\]]*(?=\s|$)/g;
|
|
27
|
+
|
|
28
|
+
type HastNode = {
|
|
29
|
+
type: string;
|
|
30
|
+
tagName?: string;
|
|
31
|
+
value?: string;
|
|
32
|
+
properties?: Record<string, unknown>;
|
|
33
|
+
children?: HastNode[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A rehype plugin that turns `:token:` text into `<span data-token>` and wraps the text of each
|
|
38
|
+
* sentence in `<span data-sentence>`, counting sentences in document order. Keeps the structure
|
|
39
|
+
* react-markdown produced; only text nodes change.
|
|
40
|
+
*/
|
|
41
|
+
function rehypeTokensAndSentences(tokenMap: TokenMap) {
|
|
42
|
+
return () => (tree: HastNode) => {
|
|
43
|
+
let sentence = 0;
|
|
44
|
+
const walk = (node: HastNode, insideCode: boolean) => {
|
|
45
|
+
if (node.type === "element" && (node.tagName === "code" || node.tagName === "pre")) {
|
|
46
|
+
insideCode = true;
|
|
47
|
+
}
|
|
48
|
+
if (!node.children) return;
|
|
49
|
+
const next: HastNode[] = [];
|
|
50
|
+
for (const child of node.children) {
|
|
51
|
+
if (child.type === "text" && !insideCode && child.value) {
|
|
52
|
+
next.push(...splitText(child.value));
|
|
53
|
+
} else {
|
|
54
|
+
walk(child, insideCode);
|
|
55
|
+
next.push(child);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
node.children = next;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const span = (properties: Record<string, unknown>, children: HastNode[]): HastNode => ({
|
|
62
|
+
type: "element",
|
|
63
|
+
tagName: "span",
|
|
64
|
+
properties,
|
|
65
|
+
children,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const splitText = (value: string): HastNode[] => {
|
|
69
|
+
const out: HastNode[] = [];
|
|
70
|
+
let buffer = "";
|
|
71
|
+
const flushText = () => {
|
|
72
|
+
if (buffer) {
|
|
73
|
+
out.push(span({ dataSentence: sentence }, [{ type: "text", value: buffer }]));
|
|
74
|
+
buffer = "";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
// Tokens first, then sentence ends inside the plain runs
|
|
78
|
+
let last = 0;
|
|
79
|
+
const tokenRegex = new RegExp(TOKEN_REGEX.source, "g");
|
|
80
|
+
let m: RegExpExecArray | null;
|
|
81
|
+
const pushRun = (run: string) => {
|
|
82
|
+
let runLast = 0;
|
|
83
|
+
const endRegex = new RegExp(SENTENCE_END.source, "g");
|
|
84
|
+
let e: RegExpExecArray | null;
|
|
85
|
+
while ((e = endRegex.exec(run)) !== null) {
|
|
86
|
+
buffer += run.substring(runLast, e.index + e[0].length);
|
|
87
|
+
runLast = e.index + e[0].length;
|
|
88
|
+
flushText();
|
|
89
|
+
sentence++;
|
|
90
|
+
}
|
|
91
|
+
buffer += run.substring(runLast);
|
|
92
|
+
};
|
|
93
|
+
while ((m = tokenRegex.exec(value)) !== null) {
|
|
94
|
+
const name = m[1];
|
|
95
|
+
if (!tokenMap[name]) continue;
|
|
96
|
+
pushRun(value.substring(last, m.index));
|
|
97
|
+
flushText();
|
|
98
|
+
out.push(span({ dataToken: name, dataSentence: sentence }, []));
|
|
99
|
+
last = m.index + m[0].length;
|
|
100
|
+
}
|
|
101
|
+
pushRun(value.substring(last));
|
|
102
|
+
flushText();
|
|
103
|
+
return out;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
walk(tree, false);
|
|
107
|
+
// Trailing text with no terminal punctuation still counts as a sentence; nothing to do.
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function MarkdownImage({
|
|
112
|
+
src,
|
|
113
|
+
alt,
|
|
114
|
+
tokenMap,
|
|
115
|
+
resolveImage,
|
|
116
|
+
}: {
|
|
117
|
+
src?: string;
|
|
118
|
+
alt?: string;
|
|
119
|
+
tokenMap: TokenMap;
|
|
120
|
+
resolveImage?: (src: string) => string;
|
|
121
|
+
}) {
|
|
122
|
+
if (!src) return null;
|
|
123
|
+
if (src.startsWith("token:")) {
|
|
124
|
+
const def: TokenDefinition | undefined = tokenMap[src.substring("token:".length)];
|
|
125
|
+
if (!def?.image) return <>{alt}</>;
|
|
126
|
+
if (typeof def.image === "string") {
|
|
127
|
+
return <Box component="img" src={def.image} alt={alt} sx={{ maxWidth: "100%", display: "block", my: 1 }} />;
|
|
128
|
+
}
|
|
129
|
+
const canvas = new StaticImage(def.image).get();
|
|
130
|
+
return (
|
|
131
|
+
<Box sx={{ my: 1 }}>
|
|
132
|
+
<UpdatingCanvasImage image={canvas} style={{ maxWidth: "100%", display: "block" }} />
|
|
133
|
+
</Box>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return (
|
|
137
|
+
<Box
|
|
138
|
+
component="img"
|
|
139
|
+
src={resolveImage ? resolveImage(src) : src}
|
|
140
|
+
alt={alt}
|
|
141
|
+
sx={{ maxWidth: "100%", height: "auto", display: "block", my: 1, borderRadius: 1 }}
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Markdown with the game's `:token:` icons inline, rendered with the same token map and `Token`
|
|
148
|
+
* component as the action log, plus optional per-sentence emphasis for narration. Images can be
|
|
149
|
+
* URLs or `token:<name>` to show a token's art at image size.
|
|
150
|
+
*/
|
|
151
|
+
export function TokenizedMarkdown({
|
|
152
|
+
text,
|
|
153
|
+
fontSize,
|
|
154
|
+
tokenMap = {},
|
|
155
|
+
color,
|
|
156
|
+
activeSentence = -1,
|
|
157
|
+
dimmedOpacity = 0.55,
|
|
158
|
+
accent,
|
|
159
|
+
resolveImage,
|
|
160
|
+
}: TokenizedMarkdownProps) {
|
|
161
|
+
const plugin = useMemo(() => rehypeTokensAndSentences(tokenMap), [tokenMap]);
|
|
162
|
+
|
|
163
|
+
const components = useMemo<Components>(
|
|
164
|
+
() => ({
|
|
165
|
+
// eslint-disable-next-line react/prop-types
|
|
166
|
+
span: (props) => {
|
|
167
|
+
// eslint-disable-next-line react/prop-types
|
|
168
|
+
const { node, children, ...rest } = props as any;
|
|
169
|
+
// eslint-disable-next-line react/prop-types
|
|
170
|
+
const p = node?.properties ?? {};
|
|
171
|
+
const tokenName = p.dataToken as string | undefined;
|
|
172
|
+
const sentence = p.dataSentence as number | undefined;
|
|
173
|
+
const emphasised = activeSentence < 0 || sentence === undefined || sentence === activeSentence;
|
|
174
|
+
const style: React.CSSProperties = {
|
|
175
|
+
opacity: emphasised ? 1 : dimmedOpacity,
|
|
176
|
+
color: emphasised && activeSentence >= 0 && accent ? accent : undefined,
|
|
177
|
+
transition: "opacity 0.25s linear, color 0.25s linear",
|
|
178
|
+
};
|
|
179
|
+
if (tokenName) {
|
|
180
|
+
return (
|
|
181
|
+
<span style={style}>
|
|
182
|
+
<Token name={tokenName} definition={tokenMap[tokenName]} fontSize={fontSize} />
|
|
183
|
+
</span>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return (
|
|
187
|
+
<span {...rest} style={style}>
|
|
188
|
+
{children}
|
|
189
|
+
</span>
|
|
190
|
+
);
|
|
191
|
+
},
|
|
192
|
+
// eslint-disable-next-line react/prop-types
|
|
193
|
+
img: (props) => {
|
|
194
|
+
// eslint-disable-next-line react/prop-types
|
|
195
|
+
const { src, alt } = props as any;
|
|
196
|
+
return <MarkdownImage src={src} alt={alt} tokenMap={tokenMap} resolveImage={resolveImage} />;
|
|
197
|
+
},
|
|
198
|
+
p: ({ children }) => <Box sx={{ my: 0.75, "&:first-of-type": { mt: 0 }, "&:last-of-type": { mb: 0 } }}>{children}</Box>,
|
|
199
|
+
ul: ({ children }) => <Box component="ul" sx={{ my: 0.5, pl: 2.5 }}>{children}</Box>,
|
|
200
|
+
ol: ({ children }) => <Box component="ol" sx={{ my: 0.5, pl: 2.5 }}>{children}</Box>,
|
|
201
|
+
li: ({ children }) => <Box component="li" sx={{ my: 0.25 }}>{children}</Box>,
|
|
202
|
+
h1: ({ children }) => <Box sx={{ fontSize: fontSize * 1.4, fontWeight: "bold", my: 0.5 }}>{children}</Box>,
|
|
203
|
+
h2: ({ children }) => <Box sx={{ fontSize: fontSize * 1.25, fontWeight: "bold", my: 0.5 }}>{children}</Box>,
|
|
204
|
+
h3: ({ children }) => <Box sx={{ fontSize: fontSize * 1.1, fontWeight: "bold", my: 0.5 }}>{children}</Box>,
|
|
205
|
+
a: ({ children, href }) => (
|
|
206
|
+
<a href={href} target="_blank" rel="noreferrer" style={{ color: accent ?? "inherit" }}>
|
|
207
|
+
{children}
|
|
208
|
+
</a>
|
|
209
|
+
),
|
|
210
|
+
blockquote: ({ children }) => (
|
|
211
|
+
<Box sx={{ borderLeft: `3px solid ${accent ?? "currentColor"}`, pl: 1.5, my: 0.75, opacity: 0.9 }}>{children}</Box>
|
|
212
|
+
),
|
|
213
|
+
}),
|
|
214
|
+
[activeSentence, dimmedOpacity, accent, tokenMap, fontSize, resolveImage],
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<Box sx={{ fontSize: `${fontSize}px`, lineHeight: 1.35, color }}>
|
|
219
|
+
<Markdown rehypePlugins={[plugin]} components={components} skipHtml>
|
|
220
|
+
{text}
|
|
221
|
+
</Markdown>
|
|
222
|
+
</Box>
|
|
223
|
+
);
|
|
224
|
+
}
|