@dreamboard-games/sdk 0.2.1-alpha.1 → 0.3.0-alpha.1

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 (372) hide show
  1. package/dist/{HandView-ncJIVLhN.d.ts → HandView-PYDmehVD.d.ts} +1 -1
  2. package/dist/{ResourceCounter-CTREyF73.d.ts → ResourceCounter-BTXklCEZ.d.ts} +1 -1
  3. package/dist/{ThemeProvider-BBMVT3KG.d.ts → ThemeProvider-DvMl17Ny.d.ts} +1 -1
  4. package/dist/{chunk-NKCRKGR2.js → chunk-3RQEICD3.js} +2 -2
  5. package/dist/{chunk-ZABVH7AO.js → chunk-ADYH6PVT.js} +1336 -1363
  6. package/dist/chunk-ADYH6PVT.js.map +1 -0
  7. package/dist/{chunk-PEI3FIL2.js → chunk-P7VMTJ5D.js} +2 -2
  8. package/dist/{chunk-PEI3FIL2.js.map → chunk-P7VMTJ5D.js.map} +1 -1
  9. package/dist/{chunk-WG4JQL3S.js → chunk-QZ6X4B5P.js} +1177 -1109
  10. package/dist/chunk-QZ6X4B5P.js.map +1 -0
  11. package/dist/{chunk-MZNVHMJ5.js → chunk-TXXLS3OI.js} +405 -309
  12. package/dist/chunk-TXXLS3OI.js.map +1 -0
  13. package/dist/{chunk-FDNZTDD6.js → chunk-W6SGFWXH.js} +48 -44
  14. package/dist/chunk-W6SGFWXH.js.map +1 -0
  15. package/dist/{chunk-MKXPVOUT.js → chunk-Y2AFYBMB.js} +48 -4
  16. package/dist/chunk-Y2AFYBMB.js.map +1 -0
  17. package/dist/{index-BwqPQtBu.d.ts → codegen.d.ts} +57 -565
  18. package/dist/{infrastructure/workspace-codegen.js → codegen.js} +3 -3
  19. package/dist/{components-BoiVSYqx.d.ts → components-DaIqi9QM.d.ts} +48 -37
  20. package/dist/{hex-board-view-1iAyJRFn.d.ts → hex-board-view-UCUjMALd.d.ts} +2 -2
  21. package/dist/{infrastructure/reducer-bundle-abi.d.ts → index.d-BGqVifr_.d.ts} +289 -10
  22. package/dist/index.js +1 -1
  23. package/dist/package-set.d.ts +2 -2
  24. package/dist/package-set.js +1 -1
  25. package/dist/primitive-props-BNHDkgd7.d.ts +16 -0
  26. package/dist/reducer-contract.d.ts +3 -0
  27. package/dist/{infrastructure/reducer-bundle-abi.js → reducer-contract.js} +4 -4
  28. package/dist/reducer.d.ts +185 -179
  29. package/dist/reducer.js +1363 -1372
  30. package/dist/reducer.js.map +1 -1
  31. package/dist/runtime/primitives.d.ts +9 -9
  32. package/dist/runtime/primitives.js +7 -7
  33. package/dist/runtime/runtime-api.d.ts +2 -0
  34. package/dist/runtime/runtime-api.js +1 -0
  35. package/dist/runtime/workspace-contract.d.ts +62 -17
  36. package/dist/runtime/workspace-contract.js +5 -6
  37. package/dist/{runtime-api-CPLm_XDG.d.ts → runtime-api-tGL3ArsB.d.ts} +103 -4
  38. package/dist/runtime.d.ts +11 -57
  39. package/dist/runtime.js +487 -8
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/testing.d.ts +4 -4
  42. package/dist/testing.js.map +1 -1
  43. package/dist/types.d.ts +1531 -85
  44. package/dist/types.js +1 -3
  45. package/dist/types.js.map +1 -1
  46. package/dist/ui/components.d.ts +7 -8
  47. package/dist/ui/components.js +1 -1
  48. package/dist/ui/defaults.d.ts +1 -1
  49. package/dist/ui/{types/player-state.d.ts → player-state.d.ts} +2 -2
  50. package/dist/{ui-contract-rzKBwOLC.d.ts → ui-contract-SctM4ibF.d.ts} +155 -150
  51. package/dist/ui.d.ts +10 -11
  52. package/dist/ui.js +2 -2
  53. package/package.json +30 -75
  54. package/dist/bundle-CDd5FKeD.d.ts +0 -283
  55. package/dist/cards-Sl3b40Mv.d.ts +0 -13
  56. package/dist/chunk-326PGVAA.js +0 -34
  57. package/dist/chunk-326PGVAA.js.map +0 -1
  58. package/dist/chunk-FDNZTDD6.js.map +0 -1
  59. package/dist/chunk-I46YJSOD.js +0 -1
  60. package/dist/chunk-MKXPVOUT.js.map +0 -1
  61. package/dist/chunk-MZNVHMJ5.js.map +0 -1
  62. package/dist/chunk-T52J5RMF.js +0 -1
  63. package/dist/chunk-WG4JQL3S.js.map +0 -1
  64. package/dist/chunk-XV6D3ET4.js +0 -485
  65. package/dist/chunk-XV6D3ET4.js.map +0 -1
  66. package/dist/chunk-ZABVH7AO.js.map +0 -1
  67. package/dist/generated/runtime/primitives.d.ts +0 -13
  68. package/dist/generated/runtime/primitives.js +0 -181
  69. package/dist/generated/runtime/primitives.js.map +0 -1
  70. package/dist/generated/runtime-api.d.ts +0 -3
  71. package/dist/generated/runtime-api.js +0 -2
  72. package/dist/generated/runtime.d.ts +0 -15
  73. package/dist/generated/runtime.js +0 -19
  74. package/dist/generated/runtime.js.map +0 -1
  75. package/dist/generated/workspace-contract.d.ts +0 -15
  76. package/dist/generated/workspace-contract.js +0 -15
  77. package/dist/generated/workspace-contract.js.map +0 -1
  78. package/dist/infrastructure/reducer-bundle-abi.js.map +0 -1
  79. package/dist/infrastructure/workspace-codegen.d.ts +0 -53
  80. package/dist/infrastructure/workspace-codegen.js.map +0 -1
  81. package/dist/manifest-contract-BNHVGFtU.d.ts +0 -9
  82. package/dist/primitive-props-DpKs-GCr.d.ts +0 -11
  83. package/dist/runtime/types/runtime-api.d.ts +0 -1
  84. package/dist/runtime/types/runtime-api.js +0 -2
  85. package/dist/runtime/types/runtime-api.js.map +0 -1
  86. package/dist/runtime-api-3dshj6kK.d.ts +0 -101
  87. package/dist/slots-1GPGihk8.d.ts +0 -8
  88. package/src/browser-interaction/attributes.ts +0 -211
  89. package/src/browser-interaction/canonical.ts +0 -77
  90. package/src/browser-interaction/constants.ts +0 -77
  91. package/src/browser-interaction/effects.ts +0 -176
  92. package/src/browser-interaction/index.ts +0 -111
  93. package/src/browser-interaction/normalize.ts +0 -997
  94. package/src/browser-interaction/registry.ts +0 -70
  95. package/src/browser-interaction/resolve.ts +0 -596
  96. package/src/browser-interaction/schemas.ts +0 -152
  97. package/src/browser-interaction/types.ts +0 -304
  98. package/src/browser-interaction.ts +0 -1
  99. package/src/generated/reducer-contract/builders.ts +0 -90
  100. package/src/generated/reducer-contract/version.ts +0 -9
  101. package/src/generated/reducer-contract/wire.ts +0 -100
  102. package/src/generated/reducer-contract/zod.ts +0 -103
  103. package/src/generated/runtime/primitives.ts +0 -2
  104. package/src/generated/runtime-api.ts +0 -5
  105. package/src/generated/runtime.ts +0 -35
  106. package/src/generated/workspace-contract.ts +0 -2
  107. package/src/index.ts +0 -7
  108. package/src/infrastructure/reducer-bundle-abi.ts +0 -8
  109. package/src/infrastructure/reducer-contract/bundle.ts +0 -37
  110. package/src/infrastructure/workspace-codegen/hex-geometry.ts +0 -69
  111. package/src/infrastructure/workspace-codegen/index.ts +0 -64
  112. package/src/infrastructure/workspace-codegen/manifest-contract.ts +0 -6632
  113. package/src/infrastructure/workspace-codegen/manifest-validation.ts +0 -795
  114. package/src/infrastructure/workspace-codegen/ownership.ts +0 -131
  115. package/src/infrastructure/workspace-codegen/preset-card-sets.ts +0 -169
  116. package/src/infrastructure/workspace-codegen/seeds.ts +0 -1705
  117. package/src/infrastructure/workspace-codegen.ts +0 -1
  118. package/src/package-set.ts +0 -19
  119. package/src/reducer/authoring/contract.ts +0 -157
  120. package/src/reducer/authoring/effect.ts +0 -224
  121. package/src/reducer/authoring/game.ts +0 -23
  122. package/src/reducer/authoring/interaction.ts +0 -98
  123. package/src/reducer/authoring/phase.ts +0 -300
  124. package/src/reducer/authoring/types.ts +0 -70
  125. package/src/reducer/authoring/validation.ts +0 -382
  126. package/src/reducer/authoring/view-stage.ts +0 -68
  127. package/src/reducer/authoring.ts +0 -29
  128. package/src/reducer/bundle/ingress-bundle.ts +0 -491
  129. package/src/reducer/bundle/trusted/engine-instruction-resolver.ts +0 -254
  130. package/src/reducer/bundle/trusted/flow-instruction-resolver.ts +0 -73
  131. package/src/reducer/bundle/trusted/instruction-runner.ts +0 -414
  132. package/src/reducer/bundle/trusted/interaction-authorization.ts +0 -137
  133. package/src/reducer/bundle/trusted/interaction-collectors.ts +0 -859
  134. package/src/reducer/bundle/trusted/interaction-decision.ts +0 -747
  135. package/src/reducer/bundle/trusted/interaction-resolver.ts +0 -95
  136. package/src/reducer/bundle/trusted/interaction-types.ts +0 -174
  137. package/src/reducer/bundle/trusted/lifecycle-runner.ts +0 -427
  138. package/src/reducer/bundle/trusted/projection-builder.ts +0 -680
  139. package/src/reducer/bundle/trusted/projection-context.ts +0 -39
  140. package/src/reducer/bundle/trusted/rng-sampler.ts +0 -150
  141. package/src/reducer/bundle/trusted/runtime-registry.ts +0 -120
  142. package/src/reducer/bundle/trusted/runtime-scope.ts +0 -336
  143. package/src/reducer/bundle/trusted/simultaneous-player.ts +0 -97
  144. package/src/reducer/bundle/trusted/stage-resolver.ts +0 -87
  145. package/src/reducer/bundle/trusted/static-projection.ts +0 -116
  146. package/src/reducer/bundle/trusted/trusted-runtime-args.ts +0 -97
  147. package/src/reducer/bundle/trusted/trusted-runtime-result.ts +0 -39
  148. package/src/reducer/bundle/trusted/trusted-setup-profiles.ts +0 -43
  149. package/src/reducer/bundle/trusted/trusted-state-codec.ts +0 -48
  150. package/src/reducer/bundle/trusted-bundle.ts +0 -97
  151. package/src/reducer/bundle/types.ts +0 -171
  152. package/src/reducer/bundle.ts +0 -2
  153. package/src/reducer/client-param-schemas.ts +0 -57
  154. package/src/reducer/compose.ts +0 -34
  155. package/src/reducer/core/runtime-input.ts +0 -30
  156. package/src/reducer/core/runtime-instruction.ts +0 -59
  157. package/src/reducer/core/types.ts +0 -62
  158. package/src/reducer/definition-index.ts +0 -277
  159. package/src/reducer/derived.ts +0 -106
  160. package/src/reducer/effects.ts +0 -92
  161. package/src/reducer/engine/runtime-instruction-engine.ts +0 -155
  162. package/src/reducer/ingress/decode-runtime-input.ts +0 -7
  163. package/src/reducer/ingress/decode-session-state.ts +0 -9
  164. package/src/reducer/ingress/encode-session-state.ts +0 -6
  165. package/src/reducer/ingress/input-codec.ts +0 -18
  166. package/src/reducer/ingress/phase-schemas.ts +0 -62
  167. package/src/reducer/ingress/raw-types.ts +0 -107
  168. package/src/reducer/ingress/runtime-codec.ts +0 -14
  169. package/src/reducer/ingress/runtime-payload.ts +0 -13
  170. package/src/reducer/ingress/session-codec.ts +0 -392
  171. package/src/reducer/ingress/types.ts +0 -6
  172. package/src/reducer/inputs/boardInput.ts +0 -217
  173. package/src/reducer/inputs/boardTarget.ts +0 -190
  174. package/src/reducer/inputs/cardInput.ts +0 -86
  175. package/src/reducer/inputs/cardTarget.ts +0 -101
  176. package/src/reducer/inputs/choiceTarget.ts +0 -104
  177. package/src/reducer/inputs/defineInputs.ts +0 -71
  178. package/src/reducer/inputs/formInput.ts +0 -809
  179. package/src/reducer/inputs/many.ts +0 -120
  180. package/src/reducer/inputs/promptInput.ts +0 -87
  181. package/src/reducer/inputs/rngInput.ts +0 -58
  182. package/src/reducer/inputs/targetRule.ts +0 -123
  183. package/src/reducer/inputs.ts +0 -41
  184. package/src/reducer/model/definition.ts +0 -1072
  185. package/src/reducer/model/extract.ts +0 -745
  186. package/src/reducer/model/manifest.ts +0 -570
  187. package/src/reducer/model/queries.ts +0 -641
  188. package/src/reducer/model/runtime.ts +0 -264
  189. package/src/reducer/model/spec.ts +0 -1386
  190. package/src/reducer/model/table.ts +0 -260
  191. package/src/reducer/model.ts +0 -7
  192. package/src/reducer/ops.ts +0 -1034
  193. package/src/reducer/parse-utils.ts +0 -28
  194. package/src/reducer/per-player.ts +0 -422
  195. package/src/reducer/rng.ts +0 -69
  196. package/src/reducer/schema-helpers.ts +0 -185
  197. package/src/reducer/setup-bootstrap-helpers.ts +0 -171
  198. package/src/reducer/setup-bootstrap.ts +0 -481
  199. package/src/reducer/table-ops.ts +0 -2671
  200. package/src/reducer/table-queries.ts +0 -372
  201. package/src/reducer/transaction.ts +0 -120
  202. package/src/reducer.ts +0 -314
  203. package/src/runtime/primitives.ts +0 -1
  204. package/src/runtime/types/runtime-api.ts +0 -1
  205. package/src/runtime/workspace-contract.ts +0 -32
  206. package/src/runtime-internal/components/InteractionForm.tsx +0 -1647
  207. package/src/runtime-internal/components/PluginRuntime.tsx +0 -105
  208. package/src/runtime-internal/components/board/target-layer.ts +0 -72
  209. package/src/runtime-internal/context/ClientParamSchemaContext.tsx +0 -44
  210. package/src/runtime-internal/context/InteractionDraftContext.tsx +0 -279
  211. package/src/runtime-internal/context/PluginSessionContext.tsx +0 -47
  212. package/src/runtime-internal/context/PluginStateContext.tsx +0 -303
  213. package/src/runtime-internal/context/RuntimeContext.tsx +0 -96
  214. package/src/runtime-internal/defaults/components.tsx +0 -409
  215. package/src/runtime-internal/defaults/index.ts +0 -11
  216. package/src/runtime-internal/errors/ValidationError.ts +0 -29
  217. package/src/runtime-internal/hooks/useActivePlayers.ts +0 -33
  218. package/src/runtime-internal/hooks/useBoardInteractions.ts +0 -727
  219. package/src/runtime-internal/hooks/useGameSelector.ts +0 -105
  220. package/src/runtime-internal/hooks/useGameView.ts +0 -9
  221. package/src/runtime-internal/hooks/useInteractionByKey.ts +0 -354
  222. package/src/runtime-internal/hooks/useInteractionHandle.ts +0 -438
  223. package/src/runtime-internal/hooks/useIsMyTurn.ts +0 -20
  224. package/src/runtime-internal/hooks/useLobby.ts +0 -76
  225. package/src/runtime-internal/hooks/useMe.ts +0 -48
  226. package/src/runtime-internal/hooks/usePlayerInfo.ts +0 -28
  227. package/src/runtime-internal/hooks/usePlayerTurnOrder.ts +0 -23
  228. package/src/runtime-internal/hooks/usePluginRuntime.ts +0 -147
  229. package/src/runtime-internal/hooks/useSeatInbox.ts +0 -61
  230. package/src/runtime-internal/hooks/useSimultaneousPhase.ts +0 -10
  231. package/src/runtime-internal/index.ts +0 -42
  232. package/src/runtime-internal/internal.ts +0 -43
  233. package/src/runtime-internal/plugin-styles.css +0 -250
  234. package/src/runtime-internal/primitives/board.tsx +0 -530
  235. package/src/runtime-internal/primitives/dialog-lifecycle.ts +0 -58
  236. package/src/runtime-internal/primitives/dice.tsx +0 -79
  237. package/src/runtime-internal/primitives/game-ui-provider.tsx +0 -35
  238. package/src/runtime-internal/primitives/game.tsx +0 -387
  239. package/src/runtime-internal/primitives/hand-intent-adapter.ts +0 -147
  240. package/src/runtime-internal/primitives/hand-surface.tsx +0 -594
  241. package/src/runtime-internal/primitives/index.ts +0 -196
  242. package/src/runtime-internal/primitives/interaction-form-binding.tsx +0 -56
  243. package/src/runtime-internal/primitives/interaction-submit.ts +0 -90
  244. package/src/runtime-internal/primitives/interaction.tsx +0 -1146
  245. package/src/runtime-internal/primitives/phase.tsx +0 -43
  246. package/src/runtime-internal/primitives/player-roster.tsx +0 -302
  247. package/src/runtime-internal/primitives/primitive-props.tsx +0 -101
  248. package/src/runtime-internal/primitives/prompt.tsx +0 -255
  249. package/src/runtime-internal/primitives/ui.tsx +0 -60
  250. package/src/runtime-internal/primitives/zone.tsx +0 -791
  251. package/src/runtime-internal/reducer.ts +0 -30
  252. package/src/runtime-internal/runtime/createPluginRuntimeAPI.ts +0 -605
  253. package/src/runtime-internal/types/plugin-state.ts +0 -514
  254. package/src/runtime-internal/types/reducer-state.ts +0 -24
  255. package/src/runtime-internal/types/runtime-api.ts +0 -114
  256. package/src/runtime-internal/ui-contract.ts +0 -519
  257. package/src/runtime-internal/utils/browser-interaction-effects.ts +0 -240
  258. package/src/runtime-internal/utils/card-intent-adapter.ts +0 -546
  259. package/src/runtime-internal/utils/interaction-draft-digest.ts +0 -252
  260. package/src/runtime-internal/utils/interaction-inputs.ts +0 -492
  261. package/src/runtime-internal/utils/interaction-labels.ts +0 -23
  262. package/src/runtime-internal/utils/interaction-router.ts +0 -273
  263. package/src/runtime-internal/utils/interaction-status.ts +0 -74
  264. package/src/runtime-internal/utils/semantic-projection-digest.ts +0 -407
  265. package/src/runtime-internal/workspace-contract.ts +0 -1170
  266. package/src/runtime.ts +0 -34
  267. package/src/testing/create-expect-api.ts +0 -352
  268. package/src/testing/create-test-runtime.ts +0 -381
  269. package/src/testing/definitions.ts +0 -127
  270. package/src/testing/index.ts +0 -3
  271. package/src/testing.ts +0 -1
  272. package/src/type-stubs/manifest-contract.d.ts +0 -42
  273. package/src/type-stubs/manifest-contract.js +0 -72
  274. package/src/type-stubs/ui-contract.d.ts +0 -5
  275. package/src/type-stubs/ui-contract.js +0 -1
  276. package/src/types/authoring-card-properties.type-test.ts +0 -266
  277. package/src/types/authoring.ts +0 -1282
  278. package/src/types/cards.ts +0 -19
  279. package/src/types/contracts.ts +0 -1550
  280. package/src/types/generated-helpers.ts +0 -35
  281. package/src/types/index.ts +0 -147
  282. package/src/types/slots.ts +0 -11
  283. package/src/types.ts +0 -1
  284. package/src/ui/components/ActionButton.tsx +0 -97
  285. package/src/ui/components/ActionPanel.tsx +0 -315
  286. package/src/ui/components/Card.tsx +0 -378
  287. package/src/ui/components/CardDragSurface.tsx +0 -1076
  288. package/src/ui/components/ChromeSuppressionContext.tsx +0 -70
  289. package/src/ui/components/CostDisplay.tsx +0 -145
  290. package/src/ui/components/DiceRoller.tsx +0 -581
  291. package/src/ui/components/Drawer.tsx +0 -180
  292. package/src/ui/components/ErrorBoundary.tsx +0 -275
  293. package/src/ui/components/GameEndDisplay.tsx +0 -398
  294. package/src/ui/components/GameSkeleton.tsx +0 -260
  295. package/src/ui/components/Hand.tsx +0 -468
  296. package/src/ui/components/HandDock.tsx +0 -299
  297. package/src/ui/components/HandView.tsx +0 -441
  298. package/src/ui/components/MobileHandTray.tsx +0 -381
  299. package/src/ui/components/MoreActions.tsx +0 -143
  300. package/src/ui/components/PhaseIndicator.tsx +0 -341
  301. package/src/ui/components/PlayArea.tsx +0 -146
  302. package/src/ui/components/PrimaryActionButton.tsx +0 -336
  303. package/src/ui/components/PrimaryButton.tsx +0 -45
  304. package/src/ui/components/ResourceCounter.tsx +0 -270
  305. package/src/ui/components/StagingZone.tsx +0 -134
  306. package/src/ui/components/ThemedButton.tsx +0 -113
  307. package/src/ui/components/Toast.tsx +0 -264
  308. package/src/ui/components/board/HexGrid.tsx +0 -1297
  309. package/src/ui/components/board/NetworkGraph.tsx +0 -476
  310. package/src/ui/components/board/SlotSystem.tsx +0 -388
  311. package/src/ui/components/board/SquareGrid.tsx +0 -1165
  312. package/src/ui/components/board/TrackBoard.tsx +0 -496
  313. package/src/ui/components/board/ZoneMap.tsx +0 -448
  314. package/src/ui/components/board/hex-board-view.ts +0 -123
  315. package/src/ui/components/board/index.ts +0 -142
  316. package/src/ui/components/board/interaction-accessibility.ts +0 -21
  317. package/src/ui/components/board/target-layer.ts +0 -67
  318. package/src/ui/components/card-render-content.type-test.ts +0 -27
  319. package/src/ui/components/hand-layout-math.ts +0 -163
  320. package/src/ui/components/hand-pointer-engine.ts +0 -413
  321. package/src/ui/components/index.ts +0 -245
  322. package/src/ui/components.ts +0 -1
  323. package/src/ui/defaults/components.tsx +0 -106
  324. package/src/ui/defaults/index.ts +0 -8
  325. package/src/ui/defaults.ts +0 -1
  326. package/src/ui/errors/ValidationError.ts +0 -29
  327. package/src/ui/helpers/cards.ts +0 -19
  328. package/src/ui/helpers/track-board.ts +0 -211
  329. package/src/ui/hooks/useBoardTopology.ts +0 -316
  330. package/src/ui/hooks/useCards.ts +0 -10
  331. package/src/ui/hooks/useHandCardPointer.ts +0 -381
  332. package/src/ui/hooks/useHandLayout.ts +0 -378
  333. package/src/ui/hooks/useHandPresentation.ts +0 -121
  334. package/src/ui/hooks/useHexBoard.ts +0 -74
  335. package/src/ui/hooks/useHexGrid.ts +0 -185
  336. package/src/ui/hooks/useIsMobile.ts +0 -35
  337. package/src/ui/hooks/usePanZoom.ts +0 -278
  338. package/src/ui/hooks/useSquareBoard.ts +0 -124
  339. package/src/ui/hooks/useSquareGrid.ts +0 -328
  340. package/src/ui/index.ts +0 -98
  341. package/src/ui/internal/ui/alert.tsx +0 -51
  342. package/src/ui/internal/ui/button.tsx +0 -58
  343. package/src/ui/internal/ui/dialog.tsx +0 -134
  344. package/src/ui/internal/ui/input.tsx +0 -21
  345. package/src/ui/internal/ui/label.tsx +0 -21
  346. package/src/ui/internal/ui/select.tsx +0 -129
  347. package/src/ui/internal/ui/tooltip.tsx +0 -54
  348. package/src/ui/internal/ui/utils.ts +0 -5
  349. package/src/ui/plugin-styles.css +0 -250
  350. package/src/ui/primitives/dialog-lifecycle.ts +0 -58
  351. package/src/ui/primitives/dice.tsx +0 -79
  352. package/src/ui/primitives/primitive-props.tsx +0 -101
  353. package/src/ui/theme/ThemeProvider.tsx +0 -252
  354. package/src/ui/theme/board.ts +0 -61
  355. package/src/ui/theme/css-vars.ts +0 -105
  356. package/src/ui/theme/derive.ts +0 -240
  357. package/src/ui/theme/index.ts +0 -61
  358. package/src/ui/theme/presets/arcade.ts +0 -261
  359. package/src/ui/theme/presets/studio.ts +0 -261
  360. package/src/ui/theme/presets/tabletop.ts +0 -266
  361. package/src/ui/theme/tokens.ts +0 -392
  362. package/src/ui/types/hex-color.ts +0 -20
  363. package/src/ui/types/player-state.ts +0 -463
  364. package/src/ui/types/tiled-board.ts +0 -785
  365. package/src/ui/types/visual-state.ts +0 -137
  366. package/src/ui.ts +0 -1
  367. /package/dist/{chunk-NKCRKGR2.js.map → chunk-3RQEICD3.js.map} +0 -0
  368. /package/dist/{chunk-I46YJSOD.js.map → codegen.js.map} +0 -0
  369. /package/dist/{chunk-T52J5RMF.js.map → reducer-contract.js.map} +0 -0
  370. /package/dist/{generated → runtime}/runtime-api.js.map +0 -0
  371. /package/dist/ui/{types/player-state.js → player-state.js} +0 -0
  372. /package/dist/ui/{types/player-state.js.map → player-state.js.map} +0 -0
@@ -1,997 +0,0 @@
1
- import {
2
- BROWSER_INTERACTION_ACTUATOR_KINDS,
3
- BROWSER_INTERACTION_ATTRIBUTES,
4
- BROWSER_INTERACTION_CANDIDATE_STATES,
5
- BROWSER_INTERACTION_READINESS_VALUES,
6
- DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME,
7
- DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
8
- GAMEPLAY_BROWSER_INTERACTION_SURFACE,
9
- } from "./constants.js";
10
- import {
11
- decodeCanonicalCandidateValue,
12
- encodeCanonicalCandidateValue,
13
- } from "./canonical.js";
14
- import {
15
- browserInteractionEffectPatternMatches,
16
- decodeBrowserInteractionEffect,
17
- decodeBrowserInteractionEffectPattern,
18
- encodeBrowserInteractionEffect,
19
- encodeBrowserInteractionEffectPattern,
20
- } from "./effects.js";
21
- import { createBrowserInteractionActuatorKey } from "./attributes.js";
22
- import { defaultBrowserInteractionRegistry } from "./registry.js";
23
- import type {
24
- BrowserInteractionActuator,
25
- BrowserInteractionActuatorKind,
26
- BrowserInteractionCandidateState,
27
- BrowserInteractionDiagnostic,
28
- BrowserInteractionEffectPattern,
29
- BrowserInteractionEntity,
30
- BrowserInteractionRawRecord,
31
- BrowserInteractionReadiness,
32
- BrowserInteractionRegistry,
33
- BrowserInteractionSemanticSurfaceSnapshot,
34
- BrowserInteractionSnapshot,
35
- BrowserInteractionSurfaceEffect,
36
- BrowserInteractionSurface,
37
- BrowserInteractionSurfaceSnapshot,
38
- } from "./types.js";
39
-
40
- interface PendingInteraction {
41
- interactionKey: string;
42
- interactionId: string;
43
- descriptorDigest?: string;
44
- draftDigest?: string;
45
- readiness: BrowserInteractionReadiness;
46
- rootSeen: boolean;
47
- actuators: BrowserInteractionActuator[];
48
- diagnostics: BrowserInteractionDiagnostic[];
49
- }
50
-
51
- interface PendingSemanticSurface {
52
- kind: "semantic";
53
- surface: BrowserInteractionSurface;
54
- scopeId: string;
55
- interactions: Map<string, PendingInteraction>;
56
- diagnostics: BrowserInteractionDiagnostic[];
57
- }
58
-
59
- interface PendingUnknownSurface {
60
- kind: "unknown";
61
- surface: BrowserInteractionSurface;
62
- scopeId: string;
63
- diagnostics: BrowserInteractionDiagnostic[];
64
- }
65
-
66
- type PendingSurface = PendingSemanticSurface | PendingUnknownSurface;
67
-
68
- export interface NormalizeBrowserInteractionRecordsOptions {
69
- readonly registry?: BrowserInteractionRegistry;
70
- }
71
-
72
- export function normalizeBrowserInteractionRecords(
73
- records: readonly BrowserInteractionRawRecord[],
74
- options: NormalizeBrowserInteractionRecordsOptions = {},
75
- ): BrowserInteractionSnapshot {
76
- const registry = options.registry ?? defaultBrowserInteractionRegistry;
77
- const diagnostics: BrowserInteractionDiagnostic[] = [];
78
- const surfaces = new Map<string, PendingSurface>();
79
-
80
- const getSurface = (
81
- surface: string,
82
- scopeId: string,
83
- ): PendingSurface | null => {
84
- const registered = registry.surfaces.get(surface);
85
- const key = `${surface}\0${scopeId}`;
86
- const existing = surfaces.get(key);
87
- if (existing) return existing;
88
- if (!registered) {
89
- const diagnostic = diagnosticFor({
90
- code: "unknown-surface",
91
- message: `Unknown browser interaction surface '${surface}'.`,
92
- surface,
93
- scopeId,
94
- });
95
- diagnostics.push(diagnostic);
96
- const pending: PendingUnknownSurface = {
97
- kind: "unknown",
98
- surface,
99
- scopeId,
100
- diagnostics: [diagnostic],
101
- };
102
- surfaces.set(key, pending);
103
- return pending;
104
- }
105
- const pending: PendingSemanticSurface = {
106
- kind: "semantic",
107
- surface,
108
- scopeId,
109
- interactions: new Map(),
110
- diagnostics: [],
111
- };
112
- surfaces.set(key, pending);
113
- return pending;
114
- };
115
-
116
- for (const record of records) {
117
- const attributes = record.attributes;
118
- const protocol = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.protocol);
119
- const surface = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.surface);
120
- const scopeId = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.scope);
121
- const role = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.role);
122
-
123
- if (protocol !== DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION) {
124
- diagnostics.push(
125
- diagnosticFor({
126
- code: "invalid-protocol",
127
- message: `Expected browser interaction protocol ${DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION}.`,
128
- surface,
129
- scopeId,
130
- }),
131
- );
132
- continue;
133
- }
134
- if (
135
- !surface ||
136
- !scopeId ||
137
- (role !== "interaction" && role !== "actuator")
138
- ) {
139
- diagnostics.push(
140
- diagnosticFor({
141
- code: "invalid-record",
142
- message:
143
- "Browser interaction records require protocol, surface, scope and role.",
144
- surface,
145
- scopeId,
146
- }),
147
- );
148
- continue;
149
- }
150
-
151
- const pendingSurface = getSurface(surface, scopeId);
152
- if (!pendingSurface || pendingSurface.kind !== "semantic") {
153
- continue;
154
- }
155
- const interactionKey = text(
156
- attributes,
157
- BROWSER_INTERACTION_ATTRIBUTES.interactionKey,
158
- );
159
- const interactionId = text(
160
- attributes,
161
- BROWSER_INTERACTION_ATTRIBUTES.interactionId,
162
- );
163
- if (!interactionKey || !interactionId) {
164
- pushSurfaceDiagnostic(
165
- pendingSurface,
166
- diagnostics,
167
- diagnosticFor({
168
- code: "invalid-record",
169
- message:
170
- "Browser interaction records require interaction key and id.",
171
- surface,
172
- scopeId,
173
- }),
174
- );
175
- continue;
176
- }
177
- const interaction = getInteraction(
178
- pendingSurface,
179
- interactionKey,
180
- interactionId,
181
- );
182
-
183
- if (role === "interaction") {
184
- interaction.rootSeen = true;
185
- interaction.descriptorDigest = optionalText(
186
- attributes,
187
- BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest,
188
- );
189
- interaction.draftDigest = optionalText(
190
- attributes,
191
- BROWSER_INTERACTION_ATTRIBUTES.draftDigest,
192
- );
193
- interaction.readiness = parseReadiness(
194
- text(attributes, BROWSER_INTERACTION_ATTRIBUTES.readiness),
195
- );
196
- continue;
197
- }
198
-
199
- const actuator = parseGameplayActuator(attributes, {
200
- surface,
201
- scopeId,
202
- interactionKey,
203
- interactionId,
204
- });
205
- if (actuator.diagnostics.length > 0) {
206
- interaction.diagnostics.push(...actuator.diagnostics);
207
- diagnostics.push(...actuator.diagnostics);
208
- }
209
- const registered = registry.surfaces.get(surface);
210
- if (registered && !registered.intents.includes(actuator.intent)) {
211
- const diagnostic = diagnosticFor({
212
- code: "unknown-intent",
213
- message: `Unknown browser interaction intent '${actuator.intent}' for surface '${surface}'.`,
214
- surface,
215
- scopeId,
216
- interactionKey,
217
- intent: actuator.intent,
218
- actuatorId: actuator.actuatorId,
219
- });
220
- interaction.diagnostics.push(diagnostic);
221
- diagnostics.push(diagnostic);
222
- }
223
- if (registered?.effectKinds) {
224
- for (const effect of actuator.semanticEffects) {
225
- if (!registered.effectKinds.includes(effect.kind)) {
226
- const diagnostic = diagnosticFor({
227
- code: "unknown-surface-effect",
228
- message: `Unknown browser interaction effect '${effect.kind}' for surface '${surface}'.`,
229
- surface,
230
- scopeId,
231
- interactionKey,
232
- intent: actuator.intent,
233
- actuatorId: actuator.actuatorId,
234
- });
235
- interaction.diagnostics.push(diagnostic);
236
- diagnostics.push(diagnostic);
237
- }
238
- }
239
- for (const pattern of [
240
- ...actuator.acceptedEffectPatterns,
241
- ...actuator.preparationPatterns,
242
- ]) {
243
- const effectKind =
244
- pattern.kind === "exact" ? pattern.effect.kind : pattern.effectKind;
245
- if (!registered.effectKinds.includes(effectKind)) {
246
- const diagnostic = diagnosticFor({
247
- code: "unknown-surface-effect",
248
- message: `Unknown browser interaction effect '${effectKind}' for surface '${surface}'.`,
249
- surface,
250
- scopeId,
251
- interactionKey,
252
- intent: actuator.intent,
253
- actuatorId: actuator.actuatorId,
254
- });
255
- interaction.diagnostics.push(diagnostic);
256
- diagnostics.push(diagnostic);
257
- }
258
- }
259
- }
260
- interaction.actuators.push(actuator);
261
- }
262
-
263
- for (const surface of surfaces.values()) {
264
- if (surface.kind !== "semantic") continue;
265
- for (const interaction of surface.interactions.values()) {
266
- if (interaction.rootSeen || interaction.actuators.length === 0) continue;
267
- const diagnostic = diagnosticFor({
268
- code: "orphan-actuator",
269
- message:
270
- "Browser interaction actuators require a rendered semantic root.",
271
- surface: surface.surface,
272
- scopeId: surface.scopeId,
273
- interactionKey: interaction.interactionKey,
274
- });
275
- interaction.diagnostics.push(diagnostic);
276
- diagnostics.push(diagnostic);
277
- }
278
- }
279
-
280
- const snapshot: BrowserInteractionSnapshot = {
281
- protocol: {
282
- name: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME,
283
- version: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
284
- },
285
- surfaces: [...surfaces.values()].map(finalizeSurface).sort(compareSurface),
286
- diagnostics: [],
287
- };
288
- const validationDiagnostics = validateBrowserInteractionSnapshot(snapshot);
289
- return {
290
- ...snapshot,
291
- diagnostics: [...diagnostics, ...validationDiagnostics].sort(
292
- compareDiagnostic,
293
- ),
294
- };
295
- }
296
-
297
- export function validateBrowserInteractionSnapshot(
298
- snapshot: BrowserInteractionSnapshot,
299
- ): readonly BrowserInteractionDiagnostic[] {
300
- const diagnostics: BrowserInteractionDiagnostic[] = [];
301
- for (const surface of snapshot.surfaces) {
302
- if (!isSemanticSurfaceSnapshot(surface)) continue;
303
- for (const interaction of surface.interactions) {
304
- const enabledByKey = new Map<string, BrowserInteractionActuator[]>();
305
- for (const actuator of interaction.actuators) {
306
- if (!actuator.enabled) continue;
307
- const key = actuatorIdentityKey({
308
- surface: surface.surface,
309
- scopeId: surface.scopeId,
310
- interactionKey: interaction.interactionKey,
311
- actuator,
312
- });
313
- const group = enabledByKey.get(key) ?? [];
314
- group.push(actuator);
315
- enabledByKey.set(key, group);
316
- }
317
- for (const [key, actuators] of enabledByKey) {
318
- if (actuators.length > 1) {
319
- diagnostics.push(
320
- diagnosticFor({
321
- code: "duplicate-enabled-actuator",
322
- message: `Duplicate enabled actuator for '${key}'.`,
323
- surface: surface.surface,
324
- scopeId: surface.scopeId,
325
- interactionKey: interaction.interactionKey,
326
- intent: actuators[0]?.intent,
327
- actuatorId: actuators[0]?.actuatorId,
328
- }),
329
- );
330
- }
331
- }
332
- diagnostics.push(
333
- ...diagnosticsForPreparationCycles(surface, interaction),
334
- ...diagnosticsForPreparationPatternAmbiguity(surface, interaction),
335
- ...diagnosticsForInvalidAcceptedPatterns(surface, interaction),
336
- ...diagnosticsForGameplayEffectCompatibility(surface, interaction),
337
- );
338
- }
339
- }
340
- return diagnostics.sort(compareDiagnostic);
341
- }
342
-
343
- function diagnosticsForInvalidAcceptedPatterns(
344
- surface: BrowserInteractionSemanticSurfaceSnapshot,
345
- interaction: BrowserInteractionEntity,
346
- ): BrowserInteractionDiagnostic[] {
347
- const diagnostics: BrowserInteractionDiagnostic[] = [];
348
- for (const actuator of interaction.actuators) {
349
- for (const pattern of actuator.acceptedEffectPatterns) {
350
- if (
351
- pattern.kind === "match" &&
352
- Object.keys(pattern.fields ?? {}).length === 0 &&
353
- pattern.scalar === undefined
354
- ) {
355
- diagnostics.push(
356
- diagnosticFor({
357
- code: "invalid-effect-pattern",
358
- message:
359
- "Accepted-effect match patterns must be bounded by fields or scalar constraints.",
360
- surface: surface.surface,
361
- scopeId: surface.scopeId,
362
- interactionKey: interaction.interactionKey,
363
- intent: actuator.intent,
364
- actuatorId: actuator.actuatorId,
365
- }),
366
- );
367
- }
368
- }
369
- }
370
- return diagnostics;
371
- }
372
-
373
- function diagnosticsForGameplayEffectCompatibility(
374
- surface: BrowserInteractionSemanticSurfaceSnapshot,
375
- interaction: BrowserInteractionEntity,
376
- ): BrowserInteractionDiagnostic[] {
377
- if (surface.surface !== GAMEPLAY_BROWSER_INTERACTION_SURFACE) return [];
378
- const diagnostics: BrowserInteractionDiagnostic[] = [];
379
- for (const actuator of interaction.actuators) {
380
- for (const effect of actuator.semanticEffects) {
381
- if (!gameplayIntentCanPerformEffect(actuator.intent, effect.kind)) {
382
- diagnostics.push(
383
- diagnosticFor({
384
- code: "effect-intent-incompatibility",
385
- message:
386
- "Gameplay browser interaction intent is incompatible with its semantic effect.",
387
- surface: surface.surface,
388
- scopeId: surface.scopeId,
389
- interactionKey: interaction.interactionKey,
390
- intent: actuator.intent,
391
- actuatorId: actuator.actuatorId,
392
- }),
393
- );
394
- }
395
- }
396
- }
397
- return diagnostics;
398
- }
399
-
400
- function gameplayIntentCanPerformEffect(intent: string, effectKind: string) {
401
- switch (effectKind) {
402
- case "setCandidate":
403
- return intent === "select" || intent === "toggle";
404
- case "adjustResource":
405
- return intent === "increment" || intent === "decrement";
406
- case "setScalar":
407
- return (
408
- intent === "fill" || intent === "increment" || intent === "decrement"
409
- );
410
- case "commit":
411
- return intent === "submit" || intent === "invoke";
412
- case "invoke":
413
- return intent === "invoke" || intent === "select" || intent === "toggle";
414
- default:
415
- return true;
416
- }
417
- }
418
-
419
- function parseGameplayActuator(
420
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
421
- context: {
422
- surface: string;
423
- scopeId: string;
424
- interactionKey: string;
425
- interactionId: string;
426
- },
427
- ): BrowserInteractionActuator {
428
- const diagnostics: BrowserInteractionDiagnostic[] = [];
429
- const intent = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.intent);
430
- const actuatorKind = parseActuatorKind(
431
- text(attributes, BROWSER_INTERACTION_ATTRIBUTES.actuatorKind),
432
- );
433
- const inputKey = optionalText(
434
- attributes,
435
- BROWSER_INTERACTION_ATTRIBUTES.inputKey,
436
- );
437
- const candidate = parseCandidate(
438
- attributes,
439
- BROWSER_INTERACTION_ATTRIBUTES.candidateValue,
440
- context,
441
- intent,
442
- diagnostics,
443
- );
444
- const candidateState = parseCandidateState(
445
- optionalText(attributes, BROWSER_INTERACTION_ATTRIBUTES.candidateState),
446
- );
447
- const explicitId = optionalText(
448
- attributes,
449
- BROWSER_INTERACTION_ATTRIBUTES.actuatorId,
450
- );
451
- const enabled = parseEnabled(
452
- attributes[BROWSER_INTERACTION_ATTRIBUTES.enabled],
453
- );
454
- const actuatorId =
455
- explicitId ??
456
- createBrowserInteractionActuatorKey({
457
- surface: context.surface,
458
- scopeId: context.scopeId,
459
- interactionKey: context.interactionKey,
460
- intent,
461
- inputKey,
462
- candidateValueKey: candidate?.candidateValueKey,
463
- actuatorKind,
464
- });
465
- const preparesIntent = optionalText(
466
- attributes,
467
- BROWSER_INTERACTION_ATTRIBUTES.preparesIntent,
468
- );
469
- const preparesCandidate = parseCandidate(
470
- attributes,
471
- BROWSER_INTERACTION_ATTRIBUTES.preparesCandidateValue,
472
- context,
473
- preparesIntent ?? intent,
474
- diagnostics,
475
- );
476
- const prepares =
477
- preparesIntent === undefined
478
- ? undefined
479
- : {
480
- intent: preparesIntent,
481
- inputKey: optionalText(
482
- attributes,
483
- BROWSER_INTERACTION_ATTRIBUTES.preparesInputKey,
484
- ),
485
- candidateValue: preparesCandidate?.candidateValue,
486
- candidateValueKey: preparesCandidate?.candidateValueKey,
487
- actuatorKind: parseOptionalActuatorKind(
488
- optionalText(
489
- attributes,
490
- BROWSER_INTERACTION_ATTRIBUTES.preparesActuatorKind,
491
- ),
492
- ),
493
- };
494
- const semanticEffects = parseEffectList(
495
- attributes,
496
- BROWSER_INTERACTION_ATTRIBUTES.semanticEffects,
497
- context,
498
- intent,
499
- diagnostics,
500
- );
501
- const acceptedEffectPatterns = parseEffectPatternList(
502
- attributes,
503
- BROWSER_INTERACTION_ATTRIBUTES.acceptedEffectPatterns,
504
- context,
505
- intent,
506
- diagnostics,
507
- );
508
- const preparationPatterns = parseEffectPatternList(
509
- attributes,
510
- BROWSER_INTERACTION_ATTRIBUTES.preparationPatterns,
511
- context,
512
- intent,
513
- diagnostics,
514
- );
515
-
516
- if (!intent) {
517
- diagnostics.push(
518
- diagnosticFor({
519
- code: "invalid-record",
520
- message: "Browser interaction actuator records require an intent.",
521
- ...context,
522
- }),
523
- );
524
- }
525
-
526
- return {
527
- actuatorId,
528
- intent,
529
- descriptorDigest: optionalText(
530
- attributes,
531
- BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest,
532
- ),
533
- draftDigest: optionalText(
534
- attributes,
535
- BROWSER_INTERACTION_ATTRIBUTES.draftDigest,
536
- ),
537
- inputKey,
538
- candidateValue: candidate?.candidateValue,
539
- candidateValueKey: candidate?.candidateValueKey,
540
- candidateState,
541
- enabled,
542
- actuatorKind,
543
- semanticEffects,
544
- acceptedEffectPatterns,
545
- preparationPatterns,
546
- prepares,
547
- diagnostics: diagnostics.sort(compareDiagnostic),
548
- };
549
- }
550
-
551
- function parseEffectList(
552
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
553
- attribute: string,
554
- context: {
555
- surface: string;
556
- scopeId: string;
557
- interactionKey: string;
558
- },
559
- intent: string,
560
- diagnostics: BrowserInteractionDiagnostic[],
561
- ): BrowserInteractionSurfaceEffect[] {
562
- const encodedList = optionalText(attributes, attribute);
563
- if (encodedList === undefined) return [];
564
- try {
565
- const raw = JSON.parse(encodedList) as unknown;
566
- if (!Array.isArray(raw) || raw.some((item) => typeof item !== "string")) {
567
- throw new Error("Expected encoded effect array.");
568
- }
569
- return raw
570
- .map((encoded) => decodeBrowserInteractionEffect(encoded))
571
- .sort((a, b) =>
572
- encodeBrowserInteractionEffect(a).localeCompare(
573
- encodeBrowserInteractionEffect(b),
574
- ),
575
- );
576
- } catch {
577
- diagnostics.push(
578
- diagnosticFor({
579
- code: "invalid-effect-payload",
580
- message: "Invalid browser interaction semantic effect payload.",
581
- ...context,
582
- intent,
583
- }),
584
- );
585
- return [];
586
- }
587
- }
588
-
589
- function parseEffectPatternList(
590
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
591
- attribute: string,
592
- context: {
593
- surface: string;
594
- scopeId: string;
595
- interactionKey: string;
596
- },
597
- intent: string,
598
- diagnostics: BrowserInteractionDiagnostic[],
599
- ): BrowserInteractionEffectPattern[] {
600
- const encodedList = optionalText(attributes, attribute);
601
- if (encodedList === undefined) return [];
602
- try {
603
- const raw = JSON.parse(encodedList) as unknown;
604
- if (!Array.isArray(raw) || raw.some((item) => typeof item !== "string")) {
605
- throw new Error("Expected encoded effect pattern array.");
606
- }
607
- return raw
608
- .map((encoded) => decodeBrowserInteractionEffectPattern(encoded))
609
- .sort((a, b) =>
610
- encodeBrowserInteractionEffectPattern(a).localeCompare(
611
- encodeBrowserInteractionEffectPattern(b),
612
- ),
613
- );
614
- } catch {
615
- diagnostics.push(
616
- diagnosticFor({
617
- code: "invalid-effect-pattern",
618
- message: "Invalid browser interaction semantic effect pattern.",
619
- ...context,
620
- intent,
621
- }),
622
- );
623
- return [];
624
- }
625
- }
626
-
627
- function parseCandidate(
628
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
629
- attribute: string,
630
- context: {
631
- surface: string;
632
- scopeId: string;
633
- interactionKey: string;
634
- },
635
- intent: string,
636
- diagnostics: BrowserInteractionDiagnostic[],
637
- ) {
638
- const encoded = optionalText(attributes, attribute);
639
- if (encoded === undefined) return undefined;
640
- try {
641
- const candidateValue = decodeCanonicalCandidateValue(encoded);
642
- return {
643
- candidateValue,
644
- candidateValueKey: encodeCanonicalCandidateValue(candidateValue),
645
- };
646
- } catch {
647
- diagnostics.push(
648
- diagnosticFor({
649
- code: "invalid-candidate",
650
- message: `Invalid canonical browser interaction candidate '${encoded}'.`,
651
- ...context,
652
- intent,
653
- }),
654
- );
655
- return undefined;
656
- }
657
- }
658
-
659
- function getInteraction(
660
- surface: PendingSemanticSurface,
661
- interactionKey: string,
662
- interactionId: string,
663
- ): PendingInteraction {
664
- const existing = surface.interactions.get(interactionKey);
665
- if (existing) return existing;
666
- const next: PendingInteraction = {
667
- interactionKey,
668
- interactionId,
669
- readiness: "ready",
670
- rootSeen: false,
671
- actuators: [],
672
- diagnostics: [],
673
- };
674
- surface.interactions.set(interactionKey, next);
675
- return next;
676
- }
677
-
678
- function finalizeSurface(
679
- surface: PendingSurface,
680
- ): BrowserInteractionSurfaceSnapshot {
681
- if (surface.kind !== "semantic") {
682
- return {
683
- surface: surface.surface,
684
- scopeId: surface.scopeId,
685
- diagnostics: surface.diagnostics.sort(compareDiagnostic),
686
- };
687
- }
688
- const interactions: BrowserInteractionEntity[] = [
689
- ...surface.interactions.values(),
690
- ]
691
- .map((interaction) => ({
692
- interactionKey: interaction.interactionKey,
693
- interactionId: interaction.interactionId,
694
- descriptorDigest: interaction.descriptorDigest,
695
- draftDigest: interaction.draftDigest,
696
- readiness: interaction.readiness,
697
- actuators: interaction.actuators.sort(compareActuator),
698
- diagnostics: interaction.diagnostics.sort(compareDiagnostic),
699
- }))
700
- .sort((a, b) => a.interactionKey.localeCompare(b.interactionKey));
701
- return {
702
- surface: surface.surface,
703
- scopeId: surface.scopeId,
704
- interactions,
705
- diagnostics: surface.diagnostics.sort(compareDiagnostic),
706
- };
707
- }
708
-
709
- function diagnosticsForPreparationCycles(
710
- surface: BrowserInteractionSemanticSurfaceSnapshot,
711
- interaction: BrowserInteractionEntity,
712
- ): BrowserInteractionDiagnostic[] {
713
- const diagnostics: BrowserInteractionDiagnostic[] = [];
714
- diagnostics.push(
715
- ...diagnosticsForEffectPreparationCycles(surface, interaction),
716
- );
717
- const actuators = new Map<string, BrowserInteractionActuator>();
718
- for (const actuator of interaction.actuators) {
719
- actuators.set(
720
- actuatorIdentityKey({
721
- surface: surface.surface,
722
- scopeId: surface.scopeId,
723
- interactionKey: interaction.interactionKey,
724
- actuator,
725
- }),
726
- actuator,
727
- );
728
- }
729
- for (const actuator of interaction.actuators) {
730
- const visited = new Set<string>();
731
- let current: BrowserInteractionActuator | undefined = actuator;
732
- while (current?.prepares) {
733
- const key = actuatorIdentityKey({
734
- surface: surface.surface,
735
- scopeId: surface.scopeId,
736
- interactionKey: interaction.interactionKey,
737
- actuator: current,
738
- });
739
- if (visited.has(key)) {
740
- diagnostics.push(
741
- diagnosticFor({
742
- code: "preparation-cycle",
743
- message: `Preparation cycle detected for actuator '${current.actuatorId}'.`,
744
- surface: surface.surface,
745
- scopeId: surface.scopeId,
746
- interactionKey: interaction.interactionKey,
747
- intent: current.intent,
748
- actuatorId: current.actuatorId,
749
- }),
750
- );
751
- break;
752
- }
753
- visited.add(key);
754
- current = actuators.get(
755
- targetIdentityKey({
756
- surface: surface.surface,
757
- scopeId: surface.scopeId,
758
- interactionKey: interaction.interactionKey,
759
- target: current.prepares,
760
- }),
761
- );
762
- }
763
- }
764
- return diagnostics;
765
- }
766
-
767
- function diagnosticsForEffectPreparationCycles(
768
- surface: BrowserInteractionSemanticSurfaceSnapshot,
769
- interaction: BrowserInteractionEntity,
770
- ): BrowserInteractionDiagnostic[] {
771
- const diagnostics: BrowserInteractionDiagnostic[] = [];
772
- const actuatorKeys = new Map<BrowserInteractionActuator, string>();
773
- interaction.actuators.forEach((actuator, index) => {
774
- actuatorKeys.set(actuator, `${actuator.actuatorId}\0${index}`);
775
- });
776
- for (const actuator of interaction.actuators) {
777
- const visited = new Set<string>();
778
- let current: BrowserInteractionActuator | undefined = actuator;
779
- while (current) {
780
- const key = actuatorKeys.get(current);
781
- if (!key) break;
782
- if (visited.has(key)) {
783
- diagnostics.push(
784
- diagnosticFor({
785
- code: "preparation-cycle",
786
- message: `Semantic preparation cycle detected for actuator '${current.actuatorId}'.`,
787
- surface: surface.surface,
788
- scopeId: surface.scopeId,
789
- interactionKey: interaction.interactionKey,
790
- intent: current.intent,
791
- actuatorId: current.actuatorId,
792
- }),
793
- );
794
- break;
795
- }
796
- visited.add(key);
797
- current = interaction.actuators.find((candidate) =>
798
- current?.preparationPatterns.some((pattern) =>
799
- candidate.semanticEffects.some((effect) =>
800
- browserInteractionEffectPatternMatches(pattern, effect),
801
- ),
802
- ),
803
- );
804
- }
805
- }
806
- return diagnostics;
807
- }
808
-
809
- function diagnosticsForPreparationPatternAmbiguity(
810
- surface: BrowserInteractionSemanticSurfaceSnapshot,
811
- interaction: BrowserInteractionEntity,
812
- ): BrowserInteractionDiagnostic[] {
813
- const diagnostics: BrowserInteractionDiagnostic[] = [];
814
- for (const target of interaction.actuators) {
815
- for (const effect of target.semanticEffects) {
816
- const matches = interaction.actuators.filter((actuator) =>
817
- actuator.preparationPatterns.some((pattern) =>
818
- browserInteractionEffectPatternMatches(pattern, effect),
819
- ),
820
- );
821
- const uniqueActuatorIds = new Set(
822
- matches.map((match) => match.actuatorId),
823
- );
824
- if (uniqueActuatorIds.size > 1) {
825
- diagnostics.push(
826
- diagnosticFor({
827
- code: "ambiguous-preparation-pattern",
828
- message:
829
- "Multiple preparation patterns can prepare the same semantic effect.",
830
- surface: surface.surface,
831
- scopeId: surface.scopeId,
832
- interactionKey: interaction.interactionKey,
833
- intent: target.intent,
834
- actuatorId: target.actuatorId,
835
- }),
836
- );
837
- }
838
- }
839
- }
840
- return diagnostics;
841
- }
842
-
843
- export function actuatorIdentityKey(input: {
844
- readonly surface: string;
845
- readonly scopeId: string;
846
- readonly interactionKey: string;
847
- readonly actuator: Pick<
848
- BrowserInteractionActuator,
849
- "intent" | "inputKey" | "candidateValueKey" | "actuatorKind"
850
- >;
851
- }): string {
852
- return createBrowserInteractionActuatorKey({
853
- surface: input.surface,
854
- scopeId: input.scopeId,
855
- interactionKey: input.interactionKey,
856
- intent: input.actuator.intent,
857
- inputKey: input.actuator.inputKey,
858
- candidateValueKey: input.actuator.candidateValueKey,
859
- actuatorKind: input.actuator.actuatorKind,
860
- });
861
- }
862
-
863
- export function isGameplaySurfaceSnapshot(
864
- surface: BrowserInteractionSurfaceSnapshot,
865
- ): surface is BrowserInteractionSemanticSurfaceSnapshot<
866
- typeof GAMEPLAY_BROWSER_INTERACTION_SURFACE
867
- > {
868
- return surface.surface === GAMEPLAY_BROWSER_INTERACTION_SURFACE;
869
- }
870
-
871
- export function isSemanticSurfaceSnapshot(
872
- surface: BrowserInteractionSurfaceSnapshot,
873
- ): surface is BrowserInteractionSemanticSurfaceSnapshot {
874
- return "interactions" in surface;
875
- }
876
-
877
- export function targetIdentityKey(input: {
878
- readonly surface: string;
879
- readonly scopeId: string;
880
- readonly interactionKey: string;
881
- readonly target: {
882
- readonly intent: string;
883
- readonly inputKey?: string;
884
- readonly candidateValueKey?: string;
885
- readonly actuatorKind?: BrowserInteractionActuatorKind;
886
- };
887
- }): string {
888
- return createBrowserInteractionActuatorKey({
889
- surface: input.surface,
890
- scopeId: input.scopeId,
891
- interactionKey: input.interactionKey,
892
- intent: input.target.intent,
893
- inputKey: input.target.inputKey,
894
- candidateValueKey: input.target.candidateValueKey,
895
- actuatorKind: input.target.actuatorKind ?? "click",
896
- });
897
- }
898
-
899
- function pushSurfaceDiagnostic(
900
- surface: PendingSemanticSurface,
901
- all: BrowserInteractionDiagnostic[],
902
- diagnostic: BrowserInteractionDiagnostic,
903
- ) {
904
- surface.diagnostics.push(diagnostic);
905
- all.push(diagnostic);
906
- }
907
-
908
- function diagnosticFor(
909
- input: Omit<BrowserInteractionDiagnostic, "severity">,
910
- ): BrowserInteractionDiagnostic {
911
- return { severity: "error", ...input };
912
- }
913
-
914
- function text(
915
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
916
- key: string,
917
- ): string {
918
- const value = attributes[key];
919
- if (typeof value === "boolean") return value ? "true" : "false";
920
- return value ?? "";
921
- }
922
-
923
- function optionalText(
924
- attributes: Readonly<Record<string, string | boolean | null | undefined>>,
925
- key: string,
926
- ): string | undefined {
927
- const value = text(attributes, key);
928
- return value === "" ? undefined : value;
929
- }
930
-
931
- function parseReadiness(value: string): BrowserInteractionReadiness {
932
- return BROWSER_INTERACTION_READINESS_VALUES.includes(
933
- value as BrowserInteractionReadiness,
934
- )
935
- ? (value as BrowserInteractionReadiness)
936
- : "blocked";
937
- }
938
-
939
- function parseCandidateState(
940
- value: string | undefined,
941
- ): BrowserInteractionCandidateState | undefined {
942
- return BROWSER_INTERACTION_CANDIDATE_STATES.includes(
943
- value as BrowserInteractionCandidateState,
944
- )
945
- ? (value as BrowserInteractionCandidateState)
946
- : undefined;
947
- }
948
-
949
- function parseActuatorKind(value: string): BrowserInteractionActuatorKind {
950
- return parseOptionalActuatorKind(value) ?? "click";
951
- }
952
-
953
- function parseOptionalActuatorKind(
954
- value: string | undefined,
955
- ): BrowserInteractionActuatorKind | undefined {
956
- return BROWSER_INTERACTION_ACTUATOR_KINDS.includes(
957
- value as BrowserInteractionActuatorKind,
958
- )
959
- ? (value as BrowserInteractionActuatorKind)
960
- : undefined;
961
- }
962
-
963
- function parseEnabled(value: string | boolean | null | undefined): boolean {
964
- if (value === false || value === "false") return false;
965
- return true;
966
- }
967
-
968
- function compareSurface(
969
- a: BrowserInteractionSurfaceSnapshot,
970
- b: BrowserInteractionSurfaceSnapshot,
971
- ): number {
972
- return (
973
- a.surface.localeCompare(b.surface) || a.scopeId.localeCompare(b.scopeId)
974
- );
975
- }
976
-
977
- function compareActuator(
978
- a: BrowserInteractionActuator,
979
- b: BrowserInteractionActuator,
980
- ): number {
981
- return a.actuatorId.localeCompare(b.actuatorId);
982
- }
983
-
984
- function compareDiagnostic(
985
- a: BrowserInteractionDiagnostic,
986
- b: BrowserInteractionDiagnostic,
987
- ): number {
988
- return (
989
- a.code.localeCompare(b.code) ||
990
- (a.surface ?? "").localeCompare(b.surface ?? "") ||
991
- (a.scopeId ?? "").localeCompare(b.scopeId ?? "") ||
992
- (a.interactionKey ?? "").localeCompare(b.interactionKey ?? "") ||
993
- (a.intent ?? "").localeCompare(b.intent ?? "") ||
994
- (a.actuatorId ?? "").localeCompare(b.actuatorId ?? "") ||
995
- a.message.localeCompare(b.message)
996
- );
997
- }