@pretty-chitty/core 2.0.0 → 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.
Files changed (318) hide show
  1. package/README.md +8 -0
  2. package/dist/components/ActionLogDisplay.d.ts.map +1 -1
  3. package/dist/components/ActionLogDisplay.js +1 -1
  4. package/dist/components/ActionLogDisplay.js.map +1 -1
  5. package/dist/components/BottomBarButton.d.ts +3 -1
  6. package/dist/components/BottomBarButton.d.ts.map +1 -1
  7. package/dist/components/BottomBarButton.js +3 -2
  8. package/dist/components/BottomBarButton.js.map +1 -1
  9. package/dist/components/ContextGalleryDisplay.d.ts.map +1 -1
  10. package/dist/components/ContextGalleryDisplay.js +1 -1
  11. package/dist/components/ContextGalleryDisplay.js.map +1 -1
  12. package/dist/components/DemoWrapper.d.ts +30 -2
  13. package/dist/components/DemoWrapper.d.ts.map +1 -1
  14. package/dist/components/DemoWrapper.js +79 -36
  15. package/dist/components/DemoWrapper.js.map +1 -1
  16. package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
  17. package/dist/components/FullScreenGalleryDisplay.js +2 -2
  18. package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
  19. package/dist/components/Gallery/BuiltItem.d.ts +6 -2
  20. package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
  21. package/dist/components/Gallery/BuiltItem.js +28 -9
  22. package/dist/components/Gallery/BuiltItem.js.map +1 -1
  23. package/dist/components/Gallery/GalleryController.d.ts +18 -0
  24. package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
  25. package/dist/components/Gallery/GalleryController.js +67 -0
  26. package/dist/components/Gallery/GalleryController.js.map +1 -1
  27. package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
  28. package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
  29. package/dist/components/Gallery/GalleryViewer.js +48 -10
  30. package/dist/components/Gallery/GalleryViewer.js.map +1 -1
  31. package/dist/components/Gallery/LayoutManager.d.ts +6 -0
  32. package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
  33. package/dist/components/Gallery/LayoutManager.js +23 -3
  34. package/dist/components/Gallery/LayoutManager.js.map +1 -1
  35. package/dist/components/Gallery/constants.d.ts +2 -0
  36. package/dist/components/Gallery/constants.d.ts.map +1 -1
  37. package/dist/components/Gallery/constants.js +2 -0
  38. package/dist/components/Gallery/constants.js.map +1 -1
  39. package/dist/components/Gallery/registry.d.ts +34 -0
  40. package/dist/components/Gallery/registry.d.ts.map +1 -0
  41. package/dist/components/Gallery/registry.js +17 -0
  42. package/dist/components/Gallery/registry.js.map +1 -0
  43. package/dist/components/GameDesigner.d.ts.map +1 -1
  44. package/dist/components/GameDesigner.js +42 -10
  45. package/dist/components/GameDesigner.js.map +1 -1
  46. package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
  47. package/dist/components/InlineGalleryDisplay.js +2 -2
  48. package/dist/components/InlineGalleryDisplay.js.map +1 -1
  49. package/dist/components/LiveButton.d.ts.map +1 -1
  50. package/dist/components/LiveButton.js +5 -2
  51. package/dist/components/LiveButton.js.map +1 -1
  52. package/dist/components/MatchViewer.d.ts +6 -1
  53. package/dist/components/MatchViewer.d.ts.map +1 -1
  54. package/dist/components/MatchViewer.js +9 -3
  55. package/dist/components/MatchViewer.js.map +1 -1
  56. package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
  57. package/dist/components/Panel/MultiPanel.js +18 -0
  58. package/dist/components/Panel/MultiPanel.js.map +1 -1
  59. package/dist/components/Panel/PanelContents.d.ts.map +1 -1
  60. package/dist/components/Panel/PanelContents.js +92 -23
  61. package/dist/components/Panel/PanelContents.js.map +1 -1
  62. package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
  63. package/dist/components/Panel/PanelTabStack.js +1 -1
  64. package/dist/components/Panel/PanelTabStack.js.map +1 -1
  65. package/dist/components/PanelSpark.d.ts.map +1 -1
  66. package/dist/components/PanelSpark.js +3 -2
  67. package/dist/components/PanelSpark.js.map +1 -1
  68. package/dist/components/Playground.d.ts.map +1 -1
  69. package/dist/components/Playground.js +10 -4
  70. package/dist/components/Playground.js.map +1 -1
  71. package/dist/components/PromptControls.d.ts.map +1 -1
  72. package/dist/components/PromptControls.js +4 -2
  73. package/dist/components/PromptControls.js.map +1 -1
  74. package/dist/components/SparkLineChart.d.ts.map +1 -1
  75. package/dist/components/SparkLineChart.js +22 -26
  76. package/dist/components/SparkLineChart.js.map +1 -1
  77. package/dist/components/TimeControlBar.d.ts.map +1 -1
  78. package/dist/components/TimeControlBar.js +5 -3
  79. package/dist/components/TimeControlBar.js.map +1 -1
  80. package/dist/components/TokenizedMarkdown.d.ts +23 -0
  81. package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
  82. package/dist/components/TokenizedMarkdown.js +144 -0
  83. package/dist/components/TokenizedMarkdown.js.map +1 -0
  84. package/dist/components/TokenizedMessage.d.ts +6 -0
  85. package/dist/components/TokenizedMessage.d.ts.map +1 -1
  86. package/dist/components/TokenizedMessage.js +20 -19
  87. package/dist/components/TokenizedMessage.js.map +1 -1
  88. package/dist/components/TopBarPlayers.d.ts.map +1 -1
  89. package/dist/components/TopBarPlayers.js +1 -1
  90. package/dist/components/TopBarPlayers.js.map +1 -1
  91. package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
  92. package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
  93. package/dist/components/Tutorial/BrowserNarration.js +240 -0
  94. package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
  95. package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
  96. package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
  97. package/dist/components/Tutorial/TutorialBox.js +239 -0
  98. package/dist/components/Tutorial/TutorialBox.js.map +1 -0
  99. package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
  100. package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
  101. package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
  102. package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
  103. package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
  104. package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
  105. package/dist/components/Tutorial/TutorialOverlay.js +1132 -0
  106. package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
  107. package/dist/components/Tutorial/targetRects.d.ts +67 -0
  108. package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
  109. package/dist/components/Tutorial/targetRects.js +241 -0
  110. package/dist/components/Tutorial/targetRects.js.map +1 -0
  111. package/dist/game/Chit.d.ts +7 -0
  112. package/dist/game/Chit.d.ts.map +1 -1
  113. package/dist/game/Chit.js +20 -5
  114. package/dist/game/Chit.js.map +1 -1
  115. package/dist/game/ClientTimeState.d.ts +14 -0
  116. package/dist/game/ClientTimeState.d.ts.map +1 -1
  117. package/dist/game/ClientTimeState.js +17 -0
  118. package/dist/game/ClientTimeState.js.map +1 -1
  119. package/dist/game/Game.d.ts +6 -0
  120. package/dist/game/Game.d.ts.map +1 -1
  121. package/dist/game/GameTheme.d.ts +3 -0
  122. package/dist/game/GameTheme.d.ts.map +1 -1
  123. package/dist/game/GameTheme.js +2 -0
  124. package/dist/game/GameTheme.js.map +1 -1
  125. package/dist/game/Match.d.ts +8 -2
  126. package/dist/game/Match.d.ts.map +1 -1
  127. package/dist/game/Match.js +4 -1
  128. package/dist/game/Match.js.map +1 -1
  129. package/dist/game/Pick.d.ts +2 -0
  130. package/dist/game/Pick.d.ts.map +1 -1
  131. package/dist/game/Pick.js +17 -1
  132. package/dist/game/Pick.js.map +1 -1
  133. package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
  134. package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
  135. package/dist/game/PlayerPromptStatusChit.js +5 -1
  136. package/dist/game/PlayerPromptStatusChit.js.map +1 -1
  137. package/dist/game/Prompt.d.ts +15 -0
  138. package/dist/game/Prompt.d.ts.map +1 -1
  139. package/dist/game/Prompt.js +16 -0
  140. package/dist/game/Prompt.js.map +1 -1
  141. package/dist/game/Turn.d.ts +15 -4
  142. package/dist/game/Turn.d.ts.map +1 -1
  143. package/dist/game/Turn.js +173 -60
  144. package/dist/game/Turn.js.map +1 -1
  145. package/dist/game/TurnState.d.ts +12 -1
  146. package/dist/game/TurnState.d.ts.map +1 -1
  147. package/dist/game/TurnState.js +15 -3
  148. package/dist/game/TurnState.js.map +1 -1
  149. package/dist/game/ai/AiClientPrompts.d.ts +20 -3
  150. package/dist/game/ai/AiClientPrompts.d.ts.map +1 -1
  151. package/dist/game/ai/AiClientPrompts.js +42 -6
  152. package/dist/game/ai/AiClientPrompts.js.map +1 -1
  153. package/dist/game/ai/AiPlayerView.js +2 -0
  154. package/dist/game/ai/AiPlayerView.js.map +1 -1
  155. package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
  156. package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
  157. package/dist/game/clientTransport/ClientPrompts.js +30 -1
  158. package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
  159. package/dist/game/clientTransport/ClientTime.d.ts +13 -0
  160. package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
  161. package/dist/game/clientTransport/ClientTime.js +51 -11
  162. package/dist/game/clientTransport/ClientTime.js.map +1 -1
  163. package/dist/game/tutorial/TutorialController.d.ts +300 -0
  164. package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
  165. package/dist/game/tutorial/TutorialController.js +1182 -0
  166. package/dist/game/tutorial/TutorialController.js.map +1 -0
  167. package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
  168. package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
  169. package/dist/game/tutorial/TutorialRuntime.js +261 -0
  170. package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
  171. package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
  172. package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
  173. package/dist/game/tutorial/TutorialTheme.js +39 -0
  174. package/dist/game/tutorial/TutorialTheme.js.map +1 -0
  175. package/dist/game/tutorial/allowed.d.ts +2 -0
  176. package/dist/game/tutorial/allowed.d.ts.map +1 -0
  177. package/dist/game/tutorial/allowed.js +119 -0
  178. package/dist/game/tutorial/allowed.js.map +1 -0
  179. package/dist/game/tutorial/checks.d.ts +58 -0
  180. package/dist/game/tutorial/checks.d.ts.map +1 -0
  181. package/dist/game/tutorial/checks.js +144 -0
  182. package/dist/game/tutorial/checks.js.map +1 -0
  183. package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
  184. package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
  185. package/dist/game/tutorial/createDemoMatch.js +67 -0
  186. package/dist/game/tutorial/createDemoMatch.js.map +1 -0
  187. package/dist/game/tutorial/defineTutorial.d.ts +353 -0
  188. package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
  189. package/dist/game/tutorial/defineTutorial.js +86 -0
  190. package/dist/game/tutorial/defineTutorial.js.map +1 -0
  191. package/dist/game/tutorial/runTutorial.d.ts +63 -0
  192. package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
  193. package/dist/game/tutorial/runTutorial.js +273 -0
  194. package/dist/game/tutorial/runTutorial.js.map +1 -0
  195. package/dist/hooks/usePanelNavigation.d.ts +28 -0
  196. package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
  197. package/dist/hooks/usePanelNavigation.js +36 -0
  198. package/dist/hooks/usePanelNavigation.js.map +1 -0
  199. package/dist/hooks/useTimeController.d.ts +2 -1
  200. package/dist/hooks/useTimeController.d.ts.map +1 -1
  201. package/dist/hooks/useTimeController.js +6 -2
  202. package/dist/hooks/useTimeController.js.map +1 -1
  203. package/dist/hooks/useTutorial.d.ts +48 -0
  204. package/dist/hooks/useTutorial.d.ts.map +1 -0
  205. package/dist/hooks/useTutorial.js +16 -0
  206. package/dist/hooks/useTutorial.js.map +1 -0
  207. package/dist/index.d.ts +36 -0
  208. package/dist/index.d.ts.map +1 -1
  209. package/dist/index.html +12 -0
  210. package/dist/index.js +19 -2
  211. package/dist/index.js.map +1 -1
  212. package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
  213. package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
  214. package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
  215. package/dist/pretty-chitty.js +204513 -0
  216. package/dist/pretty-chitty.js.map +1 -0
  217. package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
  218. package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
  219. package/dist/rendering/CameraWrapperPerspective.js +16 -0
  220. package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
  221. package/dist/rendering/ChitGalleryItemInstance.d.ts +1 -0
  222. package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
  223. package/dist/rendering/ChitGalleryItemInstance.js +12 -0
  224. package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
  225. package/dist/rendering/ChitRenderInstance.d.ts +9 -1
  226. package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
  227. package/dist/rendering/ChitRenderInstance.js +28 -0
  228. package/dist/rendering/ChitRenderInstance.js.map +1 -1
  229. package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
  230. package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
  231. package/dist/rendering/RootChitRenderInstance.js +29 -0
  232. package/dist/rendering/RootChitRenderInstance.js.map +1 -1
  233. package/dist/utilities/Annotations.d.ts +15 -0
  234. package/dist/utilities/Annotations.d.ts.map +1 -1
  235. package/dist/utilities/Annotations.js +31 -7
  236. package/dist/utilities/Annotations.js.map +1 -1
  237. package/dist/utilities/CanvasStack/CanvasStack.d.ts +2 -0
  238. package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
  239. package/dist/utilities/CanvasStack/CanvasStack.js +4 -0
  240. package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
  241. package/dist/utilities/TokenizedText.d.ts +6 -0
  242. package/dist/utilities/TokenizedText.d.ts.map +1 -1
  243. package/dist/utilities/TokenizedText.js.map +1 -1
  244. package/dist/utilities/zIndex.d.ts +1 -0
  245. package/dist/utilities/zIndex.d.ts.map +1 -1
  246. package/dist/utilities/zIndex.js +1 -0
  247. package/dist/utilities/zIndex.js.map +1 -1
  248. package/package.json +3 -2
  249. package/src/library/components/ActionLogDisplay.tsx +1 -0
  250. package/src/library/components/BottomBarButton.tsx +5 -0
  251. package/src/library/components/ContextGalleryDisplay.tsx +2 -0
  252. package/src/library/components/DemoWrapper.tsx +147 -44
  253. package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
  254. package/src/library/components/Gallery/BuiltItem.ts +30 -9
  255. package/src/library/components/Gallery/GalleryController.ts +72 -1
  256. package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
  257. package/src/library/components/Gallery/LayoutManager.ts +30 -6
  258. package/src/library/components/Gallery/constants.ts +2 -0
  259. package/src/library/components/Gallery/registry.ts +44 -0
  260. package/src/library/components/GameDesigner.tsx +121 -12
  261. package/src/library/components/InlineGalleryDisplay.tsx +5 -0
  262. package/src/library/components/LiveButton.tsx +8 -5
  263. package/src/library/components/MatchViewer.tsx +14 -3
  264. package/src/library/components/Panel/MultiPanel.tsx +21 -0
  265. package/src/library/components/Panel/PanelContents.tsx +70 -1
  266. package/src/library/components/Panel/PanelTabStack.tsx +1 -0
  267. package/src/library/components/PanelSpark.tsx +9 -4
  268. package/src/library/components/Playground.tsx +48 -21
  269. package/src/library/components/PromptControls.tsx +7 -3
  270. package/src/library/components/SparkLineChart.tsx +23 -27
  271. package/src/library/components/TimeControlBar.tsx +5 -3
  272. package/src/library/components/TokenizedMarkdown.tsx +224 -0
  273. package/src/library/components/TokenizedMessage.tsx +28 -32
  274. package/src/library/components/TopBarPlayers.tsx +12 -9
  275. package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
  276. package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
  277. package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
  278. package/src/library/components/Tutorial/TutorialOverlay.tsx +1301 -0
  279. package/src/library/components/Tutorial/targetRects.ts +273 -0
  280. package/src/library/game/Chit.ts +21 -5
  281. package/src/library/game/ClientTimeState.ts +18 -0
  282. package/src/library/game/Game.ts +7 -0
  283. package/src/library/game/GameTheme.ts +4 -0
  284. package/src/library/game/Match.ts +12 -2
  285. package/src/library/game/Pick.ts +16 -1
  286. package/src/library/game/PlayerPromptStatusChit.ts +5 -1
  287. package/src/library/game/Prompt.ts +20 -0
  288. package/src/library/game/Turn.ts +179 -61
  289. package/src/library/game/TurnState.ts +26 -3
  290. package/src/library/game/ai/AI_GUIDE.md +10 -0
  291. package/src/library/game/ai/AiClientPrompts.ts +60 -11
  292. package/src/library/game/ai/AiPlayerView.ts +2 -0
  293. package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
  294. package/src/library/game/clientTransport/ClientTime.ts +54 -13
  295. package/src/library/game/serialize.test.ts +275 -0
  296. package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
  297. package/src/library/game/tutorial/TutorialController.test.ts +731 -0
  298. package/src/library/game/tutorial/TutorialController.ts +1286 -0
  299. package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
  300. package/src/library/game/tutorial/TutorialTheme.ts +67 -0
  301. package/src/library/game/tutorial/allowed.ts +145 -0
  302. package/src/library/game/tutorial/checks.ts +186 -0
  303. package/src/library/game/tutorial/createDemoMatch.ts +115 -0
  304. package/src/library/game/tutorial/defineTutorial.ts +414 -0
  305. package/src/library/game/tutorial/runTutorial.ts +331 -0
  306. package/src/library/game/undo.test.ts +282 -0
  307. package/src/library/hooks/usePanelNavigation.tsx +65 -0
  308. package/src/library/hooks/useTimeController.tsx +6 -2
  309. package/src/library/hooks/useTutorial.tsx +76 -0
  310. package/src/library/index.ts +57 -2
  311. package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
  312. package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
  313. package/src/library/rendering/ChitRenderInstance.ts +34 -0
  314. package/src/library/rendering/RootChitRenderInstance.ts +30 -1
  315. package/src/library/utilities/Annotations.ts +35 -7
  316. package/src/library/utilities/CanvasStack/CanvasStack.ts +6 -1
  317. package/src/library/utilities/TokenizedText.ts +6 -0
  318. package/src/library/utilities/zIndex.ts +1 -0
@@ -1,11 +1,117 @@
1
- import React from "react";
1
+ import React, { useState } from "react";
2
2
  import useLocalStorageState from "use-local-storage-state";
3
- import { AppBar, Tabs, Tab, CssBaseline, Stack } from "@mui/material";
3
+ import {
4
+ AppBar,
5
+ Tabs,
6
+ Tab,
7
+ CssBaseline,
8
+ Stack,
9
+ Box,
10
+ Paper,
11
+ Select,
12
+ MenuItem,
13
+ FormControl,
14
+ IconButton,
15
+ Tooltip,
16
+ ToggleButton,
17
+ } from "@mui/material";
18
+ import { OpenInNew, Refresh, Tune } from "@mui/icons-material";
4
19
  import CanvasLibraryViewer from "./CanvasLibraryViewer";
5
20
  import { Game } from "../game/Game";
6
21
  import ChitLibraryViewer from "./ChitLibraryViewer";
7
22
  import Playground from "./Playground";
8
23
  import { DemoWrapper } from "./DemoWrapper";
24
+ import { TutorialDevPanel } from "./Tutorial/TutorialDevPanel";
25
+
26
+ const NONE = "__none__";
27
+
28
+ /** The Demo tab: a demo game or any of the game's tutorials, with the tutorial workbench beside it. */
29
+ function DemoWorkbench({ game }: { game: Game<any, any> }) {
30
+ const tutorials = game.tutorials ?? [];
31
+ const [selected, setSelected] = useLocalStorageState<string>(`demo_${game.metadata.name}_tutorial`, {
32
+ defaultValue: tutorials[0] ? `${tutorials[0].id}|${tutorials[0].locale}` : NONE,
33
+ });
34
+ const [showDev, setShowDev] = useLocalStorageState<boolean>(`demo_${game.metadata.name}_devPanel`, {
35
+ defaultValue: true,
36
+ });
37
+ const [restartKey, setRestartKey] = useState(0);
38
+ const [startAt, setStartAt] = useState(0);
39
+
40
+ const [id, locale] = selected === NONE ? [undefined, undefined] : selected.split("|");
41
+ const spec = id ? tutorials.find((t) => t.id === id && t.locale === locale) : undefined;
42
+ const restart = (at = 0) => {
43
+ setStartAt(at);
44
+ setRestartKey((k) => k + 1);
45
+ };
46
+
47
+ const fullScreenUrl = spec ? `/demo?tutorial=${encodeURIComponent(spec.id)}&locale=${encodeURIComponent(spec.locale)}` : "/demo";
48
+
49
+ return (
50
+ <Stack sx={{ height: "100%", minHeight: 0 }}>
51
+ <Paper elevation={3} sx={{ position: "relative", zIndex: 1 }}>
52
+ <Stack direction="row" alignItems="center" spacing={1} sx={{ p: 1 }}>
53
+ <FormControl sx={{ minWidth: 240 }}>
54
+ <Select
55
+ variant="standard"
56
+ value={spec ? selected : NONE}
57
+ onChange={(e) => {
58
+ setSelected(e.target.value);
59
+ restart(0);
60
+ }}
61
+ >
62
+ <MenuItem value={NONE}>Demo (no tutorial)</MenuItem>
63
+ {tutorials.map((t) => (
64
+ <MenuItem key={`${t.id}|${t.locale}`} value={`${t.id}|${t.locale}`}>
65
+ {t.title} ({t.locale}) · {t.steps.length} steps
66
+ </MenuItem>
67
+ ))}
68
+ </Select>
69
+ </FormControl>
70
+ <Tooltip title="Restart">
71
+ <IconButton size="small" onClick={() => restart(0)}>
72
+ <Refresh />
73
+ </IconButton>
74
+ </Tooltip>
75
+ <Tooltip title="Open full screen">
76
+ <IconButton size="small" component="a" href={fullScreenUrl} target="_blank">
77
+ <OpenInNew />
78
+ </IconButton>
79
+ </Tooltip>
80
+ <Box flex={1} />
81
+ {spec && (
82
+ <Tooltip title="Tutorial workbench">
83
+ <ToggleButton size="small" value="dev" selected={showDev} onChange={() => setShowDev(!showDev)}>
84
+ <Tune fontSize="small" />
85
+ </ToggleButton>
86
+ </Tooltip>
87
+ )}
88
+ </Stack>
89
+ </Paper>
90
+ <Stack direction="row" sx={{ flex: 1, minHeight: 0 }}>
91
+ {/* The workbench sits beside the game, not over it: the tutorial's own layer (the dark start
92
+ screen, the box) stays inside the game and never covers the step list */}
93
+ <Box sx={{ flex: 1, minWidth: 0, position: "relative", display: "flex" }}>
94
+ <DemoWrapper key={`${selected}-${restartKey}`} game={game} tutorial={spec} startAt={startAt}>
95
+ {spec && showDev && (
96
+ <Box
97
+ sx={{
98
+ width: 360,
99
+ flexShrink: 0,
100
+ height: "100%",
101
+ bgcolor: "background.paper",
102
+ borderLeft: "1px solid rgba(0,0,0,0.12)",
103
+ overflow: "hidden",
104
+ }}
105
+ >
106
+ <TutorialDevPanel onRestart={restart} />
107
+ </Box>
108
+ )}
109
+ </DemoWrapper>
110
+ </Box>
111
+ </Stack>
112
+ </Stack>
113
+ );
114
+ }
9
115
 
10
116
  export function GameDesigner({ game }: { game: Game<any, any> }) {
11
117
  const [tabIndex, setTabIndex] = useLocalStorageState("selectedMainTab", {
@@ -15,9 +121,19 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
15
121
  const isDemo = window.location.pathname.endsWith("/demo");
16
122
 
17
123
  if (isDemo) {
124
+ const params = new URLSearchParams(window.location.search);
125
+ const tutorial = params.get("tutorial") ?? undefined;
126
+ const locale = params.get("locale") ?? undefined;
18
127
  return (
19
128
  <Stack sx={{ height: "100vh", maxHeight: "-webkit-fill-available", width: "100vw" }}>
20
- <DemoWrapper game={game} />
129
+ <DemoWrapper
130
+ game={game}
131
+ tutorial={tutorial}
132
+ locale={locale}
133
+ onBack={() => {
134
+ window.history.back();
135
+ }}
136
+ />
21
137
  </Stack>
22
138
  );
23
139
  }
@@ -29,13 +145,7 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
29
145
  <AppBar position="static">
30
146
  <Tabs
31
147
  value={tabIndex}
32
- onChange={(e, newValue) => {
33
- if (newValue === 3) {
34
- document.location.pathname = "/demo";
35
- } else {
36
- setTabIndex(newValue);
37
- }
38
- }}
148
+ onChange={(e, newValue) => setTabIndex(newValue)}
39
149
  indicatorColor="secondary"
40
150
  textColor="inherit"
41
151
  variant="fullWidth"
@@ -44,13 +154,12 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
44
154
  <Tab label="Chits" />
45
155
  <Tab label="Playground" />
46
156
  <Tab label="Demo" />
47
- {/* <Tab label="Gallery" /> */}
48
157
  </Tabs>
49
158
  </AppBar>
50
159
  {tabIndex === 0 && <CanvasLibraryViewer library={game.canvasLibrary} />}
51
160
  {tabIndex === 1 && <ChitLibraryViewer library={game.chitLibrary} />}
52
161
  {tabIndex === 2 && <Playground game={game} />}
53
- {/* {tabIndex === 3 && <GalleryPlayground game={game} />} */}
162
+ {tabIndex === 3 && <DemoWorkbench game={game} />}
54
163
  </Stack>
55
164
  );
56
165
  }
@@ -63,7 +63,9 @@ export function InlineGalleryDisplay() {
63
63
  >
64
64
  {
65
65
  <>
66
+ {inlineSource && (
66
67
  <IconButton
68
+ data-tutorial-target="gallery:toFullscreen"
67
69
  sx={{
68
70
  backgroundColor: theme.inlineGalleryButtonBackgroundColor,
69
71
  position: "absolute",
@@ -80,8 +82,11 @@ export function InlineGalleryDisplay() {
80
82
  >
81
83
  <ScreenshotMonitor sx={{ color: theme.inlineGalleryButtonForegroundColor }} />
82
84
  </IconButton>
85
+ )}
83
86
 
84
87
  <GalleryViewer
88
+ kind="inline"
89
+ tutorialTarget="gallery:inline"
85
90
  zFactor={0}
86
91
  onClose={() => {}}
87
92
  onLongPress={() => {
@@ -10,18 +10,21 @@ export default function LiveButton({ hideIfLive = true }: { hideIfLive?: boolean
10
10
  const [targetClock] = useEventChannelState(timeState.targetClock);
11
11
  const [maxClock] = useEventChannelState(timeController.maxClock);
12
12
  const [live] = useEventChannelState(timeState.live);
13
+ // A tutorial holding the board counts as the end: there is nothing to skip to past it
14
+ const [hold] = useEventChannelState(timeState.timelineHold);
15
+ const end = hold === undefined ? maxClock.clock : Math.min(hold, maxClock.clock);
13
16
 
14
- if (hideIfLive && targetClock >= maxClock.clock) {
17
+ if (hideIfLive && targetClock >= end) {
15
18
  return null;
16
19
  }
17
20
 
18
21
  return (
19
22
  <BottomBarButton
20
- disabled={targetClock >= maxClock.clock && live}
23
+ disabled={targetClock >= end && live}
21
24
  icon={SkipNext}
22
- label={live && targetClock < maxClock.clock ? "Skip" : "Live"}
23
- invisible={live && targetClock >= maxClock.clock}
24
- onClick={() => timeState.goLive(maxClock.clock)}
25
+ label={live && targetClock < end ? "Skip" : "Live"}
26
+ invisible={live && targetClock >= end}
27
+ onClick={() => timeState.goLive(end)}
25
28
  />
26
29
  );
27
30
  }
@@ -13,6 +13,7 @@ import { FullScreenGalleryDisplay } from "./FullScreenGalleryDisplay";
13
13
  import { ActionLogDisplay } from "./ActionLogDisplay";
14
14
  import { ActionLogHistoryDisplay } from "./ActionLogHistoryDisplay";
15
15
  import { PanelContents } from "./Panel/PanelContents";
16
+ import { PanelNavigationHolder } from "../hooks/usePanelNavigation";
16
17
  import useSize from "@react-hook/size";
17
18
  import { SettingsDisplay } from "./SettingsDisplay";
18
19
  import { ActionLogSidebar } from "./ActionLogSidebar";
@@ -20,6 +21,7 @@ import { InlineGalleryDisplay } from "./InlineGalleryDisplay";
20
21
  import { useLoadingState } from "../hooks/useLoadingStates";
21
22
  import { GameTheme } from "../game/GameTheme";
22
23
  import { ModalState } from "../game/ModalState";
24
+ import { TutorialOverlay } from "./Tutorial/TutorialOverlay";
23
25
 
24
26
  function createMuiTheme(gameTheme: GameTheme) {
25
27
  return createTheme({
@@ -104,22 +106,31 @@ function InnerMatchViewer({ onBack }: { onBack?: () => void }) {
104
106
  </Stack>
105
107
 
106
108
  {largeEnoughToShowLogSidebar && showLog && <ActionLogSidebar />}
109
+
110
+ <TutorialOverlay />
107
111
  </Stack>
108
112
  );
109
113
  }
110
114
 
111
- export function MatchViewer({ onBack }: { onBack?: () => void }) {
115
+ /**
116
+ * @param skipReplay Open live instead of replaying the moves since the player's last answer (a
117
+ * tutorial uses it after rebuilding the match for Back)
118
+ */
119
+ export function MatchViewer({ onBack, skipReplay = false }: { onBack?: () => void; skipReplay?: boolean }) {
112
120
  const game = useGame();
113
121
  const [modalState] = useState<ModalState>(new ModalState());
114
122
  const muiTheme = useMemo(() => createMuiTheme(game.theme), [game.theme]);
115
123
  return (
116
- <TimeControllerProvider>
124
+ <TimeControllerProvider skipReplay={skipReplay}>
117
125
  <PanelScaleProvider>
118
126
  <ModalProvider modalState={modalState}>
119
127
  <GameThemeProvider theme={game.theme}>
120
128
  <ThemeProvider theme={muiTheme}>
121
129
  <CssBaseline />
122
- <InnerMatchViewer onBack={onBack} />
130
+ {/* the tutorial overlay sits beside the panels and switches them through this */}
131
+ <PanelNavigationHolder>
132
+ <InnerMatchViewer onBack={onBack} />
133
+ </PanelNavigationHolder>
123
134
  </ThemeProvider>
124
135
  </GameThemeProvider>
125
136
  </ModalProvider>
@@ -16,6 +16,7 @@ import { PanelTabStack, TAB_HEIGHT } from "./PanelTabStack";
16
16
  import { usePanelPositioning } from "../../hooks/usePanelPositioning";
17
17
  import { useSmartDebouncedState } from "../../hooks/useSmartDebouncedState";
18
18
  import { ViewerZoomControls } from "./ViewerZoomControls";
19
+ import { usePanelNavigation } from "../../hooks/usePanelNavigation";
19
20
 
20
21
  const ANIMATION_DURATION = 0.125;
21
22
 
@@ -240,6 +241,26 @@ export function MultiPanel({
240
241
 
241
242
  const focusedRoot = focusedPanel?.renderInstance as RootChitRenderInstance;
242
243
 
244
+ // Let the tutorial overlay bring any of our panels to the front
245
+ const navigation = usePanelNavigation();
246
+ const selectRef = useRef(manuallyChangeSelectedIndex);
247
+ selectRef.current = manuallyChangeSelectedIndex;
248
+ useEffect(() => {
249
+ if (!navigation || !enabled) {
250
+ return;
251
+ }
252
+ const unregisters = chits.map((chit, index) =>
253
+ navigation.registerSelector(chit.id ?? "", () => {
254
+ selectRef.current(index);
255
+ // A tutorial asked for this panel: hold it against the automatic "show where something
256
+ // changed" switching for a while, prompt or not
257
+ setIgnoreChangesBefore(Date.now() + PANEL_ADJUST_IGNORE_DURATION);
258
+ }),
259
+ );
260
+ return () => unregisters.forEach((u) => u());
261
+ // eslint-disable-next-line react-hooks/exhaustive-deps
262
+ }, [navigation, chitIdsString, enabled]);
263
+
243
264
  return (
244
265
  <Stack
245
266
  sx={{
@@ -1,4 +1,4 @@
1
- import React, { useRef, useState, useEffect, useCallback, createContext, useContext } from "react";
1
+ import React, { useRef, useState, useEffect, useCallback, createContext, useContext, useMemo } from "react";
2
2
  import { Box } from "@mui/material";
3
3
  import useSize from "@react-hook/size";
4
4
  import { useGameTheme } from "../../hooks/useGameTheme";
@@ -11,6 +11,7 @@ import { Chit } from "../../game/Chit";
11
11
  import Hammer from "@egjs/hammerjs";
12
12
  import { PanelPositioningContext, ViewerPosition } from "../../hooks/usePanelPositioning";
13
13
  import { ViewerWrapper } from "./ViewerWrapper";
14
+ import { PanelNavigation, PanelNavigationContext, usePublishPanelNavigation } from "../../hooks/usePanelNavigation";
14
15
 
15
16
  // Types for gesture handling
16
17
  export interface ViewerGestureHandlers {
@@ -252,9 +253,76 @@ export function PanelContents({
252
253
  fullChitList.push(rootChit);
253
254
  }
254
255
 
256
+ // Panel navigation (used by the tutorial overlay to bring a chit's panel to the front)
257
+ const selectorsRef = useRef<Map<string, () => void>>(new Map());
258
+ const panelRootsRef = useRef<Chit[]>(tabChitList);
259
+ panelRootsRef.current = tabChitList;
260
+ const focusedPanelRef = useRef(focusedPanel);
261
+ focusedPanelRef.current = focusedPanel;
262
+ /** The panel root (a chit with its own viewer) that shows `chit` */
263
+ const panelOf = (chit: Chit): Chit | undefined => {
264
+ const roots = new Set(panelRootsRef.current.map((c) => c.id));
265
+ let panel: Chit | undefined = chit;
266
+ while (panel && !roots.has(panel.id)) {
267
+ panel = panel.parent;
268
+ }
269
+ return panel;
270
+ };
271
+ const navigation = useMemo<PanelNavigation>(
272
+ () => ({
273
+ registerSelector: (chitId, select) => {
274
+ selectorsRef.current.set(chitId, select);
275
+ return () => {
276
+ if (selectorsRef.current.get(chitId) === select) selectorsRef.current.delete(chitId);
277
+ };
278
+ },
279
+ panelRoots: () => panelRootsRef.current,
280
+ isFront: (chitId) => positionsRef.current.get(chitId)?.front ?? false,
281
+ revealChit: async (chit) => {
282
+ const panel = panelOf(chit);
283
+ if (!panel?.id) {
284
+ return false;
285
+ }
286
+ // Showing a panel full screen (the player zoomed in, or a tutorial focused it): that layout
287
+ // has every panel as a tab, so switch tabs there rather than leave it
288
+ const select = selectorsRef.current.get(panel.id);
289
+ if (select && !(positionsRef.current.get(panel.id)?.front ?? false)) {
290
+ select();
291
+ await new Promise((resolve) => setTimeout(resolve, 400));
292
+ }
293
+ return true;
294
+ },
295
+ keepFront: (chit) => {
296
+ // Selecting the tab already in front changes nothing but re-arms its hold against the
297
+ // automatic "show where something changed" switching
298
+ const panel = panelOf(chit);
299
+ if (panel?.id && (positionsRef.current.get(panel.id)?.front ?? false)) selectorsRef.current.get(panel.id)?.();
300
+ },
301
+ focusedPanel: () => focusedPanelRef.current,
302
+ focusPanelOf: async (chit) => {
303
+ const panel = chit ? panelOf(chit) : undefined;
304
+ if (chit && !panel?.id) return false;
305
+ if (focusedPanelRef.current === panel) return true;
306
+ if (!panel) {
307
+ setFocusedPanel(undefined);
308
+ } else if (focusedPanelRef.current) {
309
+ selectorsRef.current.get(panel.id!)?.(); // already full screen: switch to its tab
310
+ } else {
311
+ setFocusedPanel(panel);
312
+ }
313
+ await new Promise((resolve) => setTimeout(resolve, 400));
314
+ return true;
315
+ },
316
+ }),
317
+ [],
318
+ );
319
+ // The tutorial overlay is outside these panels: it reaches the navigation through the viewer
320
+ usePublishPanelNavigation(navigation);
321
+
255
322
  return (
256
323
  <GestureContext.Provider value={gestureContextValue}>
257
324
  <PanelPositioningContext.Provider value={positioningContextValue}>
325
+ <PanelNavigationContext.Provider value={navigation}>
258
326
  <Box
259
327
  sx={{
260
328
  position: "relative",
@@ -358,6 +426,7 @@ export function PanelContents({
358
426
  })}
359
427
  </Box>
360
428
  </Box>
429
+ </PanelNavigationContext.Provider>
361
430
  </PanelPositioningContext.Provider>
362
431
  </GestureContext.Provider>
363
432
  );
@@ -35,6 +35,7 @@ function PanelTab({ chit, onClick, selected }: { selected?: boolean; chit: Chit;
35
35
  return (
36
36
  <Box
37
37
  onMouseDown={onClick}
38
+ data-tutorial-target={`panelTab:${chit.id}`}
38
39
  sx={{ pt: 1, pb: 1, mt: -1, mb: -1, position: "relative", zIndex: ZINDEX_PANEL_CUTOUTS }}
39
40
  >
40
41
  <Box
@@ -42,10 +42,14 @@ export default function PanelSpark({ chit, paused, zIndex }: { zIndex: number; c
42
42
  const key = `spark${chit.id ?? "no id"}`;
43
43
  timeState.setAnimationState(key, true);
44
44
  setFlashed(true);
45
- setTimeout(() => {
46
- setFlashed(false);
47
- timeState.setAnimationState(key, false);
48
- }, DURATION);
45
+ // As fast as the board's other animations when they are hurried (going live, skipping ahead)
46
+ setTimeout(
47
+ () => {
48
+ setFlashed(false);
49
+ timeState.setAnimationState(key, false);
50
+ },
51
+ DURATION * (timeState.animationSpeedOverrideMultiplier.value ?? 1),
52
+ );
49
53
  }
50
54
  }
51
55
  }, [chit, timeState, paused, value, targetValue, DURATION]);
@@ -80,6 +84,7 @@ export default function PanelSpark({ chit, paused, zIndex }: { zIndex: number; c
80
84
  return (
81
85
  <Box
82
86
  ref={ref}
87
+ data-tutorial-target={`spark:${chit.id}`}
83
88
  sx={{
84
89
  position: "relative",
85
90
  background: flashed ? theme.sparkFlashColor : backgroundColor,
@@ -209,27 +209,54 @@ function NewMatchDialog({
209
209
  ))}
210
210
  </FormGroup>
211
211
  </FormControl>
212
- {configOptions.map((option) => (
213
- <FormControl key={option.fieldName} fullWidth>
214
- <InputLabel>{option.config.label}</InputLabel>
215
- <Select
216
- value={matchOptions[option.fieldName] ?? option.currentValue}
217
- label={option.config.label}
218
- onChange={(e) =>
219
- setMatchOptions((prev: any) => ({
220
- ...prev,
221
- [option.fieldName]: e.target.value,
222
- }))
223
- }
224
- >
225
- {option.config.choices.map((choice) => (
226
- <MenuItem key={choice.id} value={choice.id}>
227
- {choice.label ?? choice.id}
228
- </MenuItem>
229
- ))}
230
- </Select>
231
- </FormControl>
232
- ))}
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
+ })}
233
260
  </Stack>
234
261
  </DialogContent>
235
262
  <DialogActions>
@@ -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?.canReset && (
173
+ {prompt && canUndo && (
171
174
  <BottomBarButton
172
175
  icon={Replay}
173
176
  label="Undo"
174
- onClick={() => prompt.stepBack()}
175
- onLongClick={() => prompt.stepBack(true)}
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.35;
31
+ const HALO_OPACITY = 0.85;
32
32
 
33
- // One halo color for every line in the chart, picked as the extreme furthest
34
- // from the bg — so the halo is always visible against the bg and provides the
35
- // edge that separates each line from the bg. Per-line halos flipping between
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).isLight() ? "#000000" : "#ffffff";
37
+ return Color(backgroundColor).alpha(1).hex();
39
38
  }
40
39
 
41
- // The halo only does its job when every line clearly contrasts against it —
42
- // otherwise a dark line drowns into the dark halo and you get fuzz instead of
43
- // a crisp edge. Push any too-close line toward the halo's opposite (which is
44
- // also the bg side) in 5% steps until WCAG luminance contrast clears the
45
- // threshold. This is the "lighten the dark line until it's distinguishable"
46
- // step — only the dark-red-burger gets touched in a sea of light pastels.
47
- function adjustLineForHalo(lineColor: string, haloColor: string, minRatio = 7): string {
48
- const halo = Color(haloColor);
49
- const line = Color(lineColor);
50
- if (line.contrast(halo) >= minRatio) return line.hex();
51
- const target = halo.isDark() ? Color("#ffffff") : Color("#000000");
52
- for (let t = 0.05; t <= 1; t += 0.05) {
53
- const candidate = line.mix(target, t);
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 target.hex();
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
- // The chart always gets one unified halo (opposite of bg). Each line is then
172
- // shifted only if it sits too close to the halo's luminance — so on a light
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: adjustLineForHalo(line.color, haloColor),
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
- {/* Unified halo behind every line — soft glow opposite the bg. */}
230
+ {/* Bg-coloured knockout behind every line. */}
235
231
  <path
236
232
  d={extendedPathData}
237
233
  fill="none"