@dreamboard-games/sdk 0.2.1-alpha.0 → 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 (363) 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-fy0_QzgO.d.ts → ThemeProvider-DvMl17Ny.d.ts} +1 -1
  4. package/dist/attributes-BeRyboMS.d.ts +279 -0
  5. package/dist/browser-interaction.d.ts +708 -0
  6. package/dist/browser-interaction.js +106 -0
  7. package/dist/{chunk-KAELH4KC.js → chunk-3RQEICD3.js} +2 -2
  8. package/dist/{chunk-TDSWKVZ4.js → chunk-ADYH6PVT.js} +2457 -1265
  9. package/dist/chunk-ADYH6PVT.js.map +1 -0
  10. package/dist/{chunk-YFY3RL52.js → chunk-P7VMTJ5D.js} +2 -2
  11. package/dist/{chunk-YFY3RL52.js.map → chunk-P7VMTJ5D.js.map} +1 -1
  12. package/dist/chunk-QLG6VEMW.js +1691 -0
  13. package/dist/chunk-QLG6VEMW.js.map +1 -0
  14. package/dist/{chunk-WYPQ3GG5.js → chunk-QZ6X4B5P.js} +1177 -1106
  15. package/dist/chunk-QZ6X4B5P.js.map +1 -0
  16. package/dist/{chunk-GKKBPPSW.js → chunk-TXXLS3OI.js} +405 -309
  17. package/dist/chunk-TXXLS3OI.js.map +1 -0
  18. package/dist/{chunk-FDNZTDD6.js → chunk-W6SGFWXH.js} +48 -44
  19. package/dist/chunk-W6SGFWXH.js.map +1 -0
  20. package/dist/{chunk-MKXPVOUT.js → chunk-Y2AFYBMB.js} +48 -4
  21. package/dist/chunk-Y2AFYBMB.js.map +1 -0
  22. package/dist/{index-BwqPQtBu.d.ts → codegen.d.ts} +57 -565
  23. package/dist/{infrastructure/workspace-codegen.js → codegen.js} +3 -3
  24. package/dist/{components-D5ZRE2Hl.d.ts → components-DaIqi9QM.d.ts} +48 -37
  25. package/dist/{hex-board-view-D_07hO6O.d.ts → hex-board-view-UCUjMALd.d.ts} +3 -2
  26. package/dist/{infrastructure/reducer-bundle-abi.d.ts → index.d-BGqVifr_.d.ts} +289 -10
  27. package/dist/index.js +1 -1
  28. package/dist/package-set.d.ts +2 -2
  29. package/dist/package-set.js +1 -1
  30. package/dist/primitive-props-BNHDkgd7.d.ts +16 -0
  31. package/dist/reducer-contract.d.ts +3 -0
  32. package/dist/{infrastructure/reducer-bundle-abi.js → reducer-contract.js} +4 -4
  33. package/dist/reducer.d.ts +185 -179
  34. package/dist/reducer.js +1637 -1353
  35. package/dist/reducer.js.map +1 -1
  36. package/dist/runtime/primitives.d.ts +10 -9
  37. package/dist/runtime/primitives.js +8 -7
  38. package/dist/runtime/runtime-api.d.ts +2 -0
  39. package/dist/runtime/runtime-api.js +1 -0
  40. package/dist/runtime/workspace-contract.d.ts +63 -17
  41. package/dist/runtime/workspace-contract.js +5 -5
  42. package/dist/{runtime-api-DWxvTr-O.d.ts → runtime-api-tGL3ArsB.d.ts} +109 -4
  43. package/dist/runtime.d.ts +12 -57
  44. package/dist/runtime.js +487 -7
  45. package/dist/runtime.js.map +1 -1
  46. package/dist/testing.d.ts +4 -4
  47. package/dist/testing.js.map +1 -1
  48. package/dist/types.d.ts +1531 -85
  49. package/dist/types.js +1 -3
  50. package/dist/types.js.map +1 -1
  51. package/dist/ui/components.d.ts +7 -8
  52. package/dist/ui/components.js +1 -1
  53. package/dist/ui/defaults.d.ts +1 -1
  54. package/dist/ui/{types/player-state.d.ts → player-state.d.ts} +2 -2
  55. package/dist/{ui-contract-iQfTtUSL.d.ts → ui-contract-SctM4ibF.d.ts} +157 -150
  56. package/dist/ui.d.ts +10 -11
  57. package/dist/ui.js +2 -2
  58. package/package.json +35 -74
  59. package/dist/bundle-CDd5FKeD.d.ts +0 -283
  60. package/dist/cards-Sl3b40Mv.d.ts +0 -13
  61. package/dist/chunk-7YAHLYBR.js +0 -481
  62. package/dist/chunk-7YAHLYBR.js.map +0 -1
  63. package/dist/chunk-FDNZTDD6.js.map +0 -1
  64. package/dist/chunk-GKKBPPSW.js.map +0 -1
  65. package/dist/chunk-I46YJSOD.js +0 -1
  66. package/dist/chunk-MKXPVOUT.js.map +0 -1
  67. package/dist/chunk-T52J5RMF.js +0 -1
  68. package/dist/chunk-TDSWKVZ4.js.map +0 -1
  69. package/dist/chunk-U5C6BONG.js +0 -34
  70. package/dist/chunk-U5C6BONG.js.map +0 -1
  71. package/dist/chunk-WYPQ3GG5.js.map +0 -1
  72. package/dist/generated/runtime/primitives.d.ts +0 -12
  73. package/dist/generated/runtime/primitives.js +0 -180
  74. package/dist/generated/runtime/primitives.js.map +0 -1
  75. package/dist/generated/runtime-api.d.ts +0 -3
  76. package/dist/generated/runtime-api.js +0 -2
  77. package/dist/generated/runtime.d.ts +0 -14
  78. package/dist/generated/runtime.js +0 -18
  79. package/dist/generated/runtime.js.map +0 -1
  80. package/dist/generated/workspace-contract.d.ts +0 -14
  81. package/dist/generated/workspace-contract.js +0 -14
  82. package/dist/generated/workspace-contract.js.map +0 -1
  83. package/dist/infrastructure/reducer-bundle-abi.js.map +0 -1
  84. package/dist/infrastructure/workspace-codegen.d.ts +0 -53
  85. package/dist/infrastructure/workspace-codegen.js.map +0 -1
  86. package/dist/manifest-contract-BNHVGFtU.d.ts +0 -9
  87. package/dist/primitive-props-DpKs-GCr.d.ts +0 -11
  88. package/dist/runtime/types/runtime-api.d.ts +0 -1
  89. package/dist/runtime/types/runtime-api.js +0 -2
  90. package/dist/runtime-api-3dshj6kK.d.ts +0 -101
  91. package/dist/slots-1GPGihk8.d.ts +0 -8
  92. package/src/generated/reducer-contract/builders.ts +0 -90
  93. package/src/generated/reducer-contract/version.ts +0 -9
  94. package/src/generated/reducer-contract/wire.ts +0 -100
  95. package/src/generated/reducer-contract/zod.ts +0 -103
  96. package/src/generated/runtime/primitives.ts +0 -2
  97. package/src/generated/runtime-api.ts +0 -5
  98. package/src/generated/runtime.ts +0 -35
  99. package/src/generated/workspace-contract.ts +0 -2
  100. package/src/index.ts +0 -7
  101. package/src/infrastructure/reducer-bundle-abi.ts +0 -8
  102. package/src/infrastructure/reducer-contract/bundle.ts +0 -37
  103. package/src/infrastructure/workspace-codegen/hex-geometry.ts +0 -69
  104. package/src/infrastructure/workspace-codegen/index.ts +0 -64
  105. package/src/infrastructure/workspace-codegen/manifest-contract.ts +0 -6632
  106. package/src/infrastructure/workspace-codegen/manifest-validation.ts +0 -795
  107. package/src/infrastructure/workspace-codegen/ownership.ts +0 -131
  108. package/src/infrastructure/workspace-codegen/preset-card-sets.ts +0 -169
  109. package/src/infrastructure/workspace-codegen/seeds.ts +0 -1705
  110. package/src/infrastructure/workspace-codegen.ts +0 -1
  111. package/src/package-set.ts +0 -19
  112. package/src/reducer/authoring/contract.ts +0 -157
  113. package/src/reducer/authoring/effect.ts +0 -224
  114. package/src/reducer/authoring/game.ts +0 -23
  115. package/src/reducer/authoring/interaction.ts +0 -98
  116. package/src/reducer/authoring/phase.ts +0 -300
  117. package/src/reducer/authoring/types.ts +0 -70
  118. package/src/reducer/authoring/validation.ts +0 -382
  119. package/src/reducer/authoring/view-stage.ts +0 -68
  120. package/src/reducer/authoring.ts +0 -29
  121. package/src/reducer/bundle/ingress-bundle.ts +0 -491
  122. package/src/reducer/bundle/trusted/engine-instruction-resolver.ts +0 -254
  123. package/src/reducer/bundle/trusted/flow-instruction-resolver.ts +0 -73
  124. package/src/reducer/bundle/trusted/instruction-runner.ts +0 -414
  125. package/src/reducer/bundle/trusted/interaction-authorization.ts +0 -137
  126. package/src/reducer/bundle/trusted/interaction-collectors.ts +0 -859
  127. package/src/reducer/bundle/trusted/interaction-decision.ts +0 -747
  128. package/src/reducer/bundle/trusted/interaction-resolver.ts +0 -95
  129. package/src/reducer/bundle/trusted/interaction-types.ts +0 -171
  130. package/src/reducer/bundle/trusted/lifecycle-runner.ts +0 -427
  131. package/src/reducer/bundle/trusted/projection-builder.ts +0 -356
  132. package/src/reducer/bundle/trusted/projection-context.ts +0 -39
  133. package/src/reducer/bundle/trusted/rng-sampler.ts +0 -150
  134. package/src/reducer/bundle/trusted/runtime-registry.ts +0 -120
  135. package/src/reducer/bundle/trusted/runtime-scope.ts +0 -336
  136. package/src/reducer/bundle/trusted/simultaneous-player.ts +0 -97
  137. package/src/reducer/bundle/trusted/stage-resolver.ts +0 -87
  138. package/src/reducer/bundle/trusted/static-projection.ts +0 -116
  139. package/src/reducer/bundle/trusted/trusted-runtime-args.ts +0 -97
  140. package/src/reducer/bundle/trusted/trusted-runtime-result.ts +0 -39
  141. package/src/reducer/bundle/trusted/trusted-setup-profiles.ts +0 -43
  142. package/src/reducer/bundle/trusted/trusted-state-codec.ts +0 -48
  143. package/src/reducer/bundle/trusted-bundle.ts +0 -97
  144. package/src/reducer/bundle/types.ts +0 -171
  145. package/src/reducer/bundle.ts +0 -2
  146. package/src/reducer/client-param-schemas.ts +0 -57
  147. package/src/reducer/compose.ts +0 -34
  148. package/src/reducer/core/runtime-input.ts +0 -30
  149. package/src/reducer/core/runtime-instruction.ts +0 -59
  150. package/src/reducer/core/types.ts +0 -62
  151. package/src/reducer/definition-index.ts +0 -277
  152. package/src/reducer/derived.ts +0 -106
  153. package/src/reducer/effects.ts +0 -92
  154. package/src/reducer/engine/runtime-instruction-engine.ts +0 -155
  155. package/src/reducer/ingress/decode-runtime-input.ts +0 -7
  156. package/src/reducer/ingress/decode-session-state.ts +0 -9
  157. package/src/reducer/ingress/encode-session-state.ts +0 -6
  158. package/src/reducer/ingress/input-codec.ts +0 -18
  159. package/src/reducer/ingress/phase-schemas.ts +0 -62
  160. package/src/reducer/ingress/raw-types.ts +0 -107
  161. package/src/reducer/ingress/runtime-codec.ts +0 -14
  162. package/src/reducer/ingress/runtime-payload.ts +0 -13
  163. package/src/reducer/ingress/session-codec.ts +0 -392
  164. package/src/reducer/ingress/types.ts +0 -6
  165. package/src/reducer/inputs/boardInput.ts +0 -217
  166. package/src/reducer/inputs/boardTarget.ts +0 -190
  167. package/src/reducer/inputs/cardInput.ts +0 -86
  168. package/src/reducer/inputs/cardTarget.ts +0 -101
  169. package/src/reducer/inputs/choiceTarget.ts +0 -104
  170. package/src/reducer/inputs/defineInputs.ts +0 -71
  171. package/src/reducer/inputs/formInput.ts +0 -809
  172. package/src/reducer/inputs/many.ts +0 -120
  173. package/src/reducer/inputs/promptInput.ts +0 -87
  174. package/src/reducer/inputs/rngInput.ts +0 -58
  175. package/src/reducer/inputs/targetRule.ts +0 -123
  176. package/src/reducer/inputs.ts +0 -41
  177. package/src/reducer/model/definition.ts +0 -1072
  178. package/src/reducer/model/extract.ts +0 -745
  179. package/src/reducer/model/manifest.ts +0 -570
  180. package/src/reducer/model/queries.ts +0 -641
  181. package/src/reducer/model/runtime.ts +0 -264
  182. package/src/reducer/model/spec.ts +0 -1386
  183. package/src/reducer/model/table.ts +0 -260
  184. package/src/reducer/model.ts +0 -7
  185. package/src/reducer/ops.ts +0 -1034
  186. package/src/reducer/parse-utils.ts +0 -28
  187. package/src/reducer/per-player.ts +0 -422
  188. package/src/reducer/rng.ts +0 -69
  189. package/src/reducer/schema-helpers.ts +0 -185
  190. package/src/reducer/setup-bootstrap-helpers.ts +0 -171
  191. package/src/reducer/setup-bootstrap.ts +0 -481
  192. package/src/reducer/table-ops.ts +0 -2671
  193. package/src/reducer/table-queries.ts +0 -372
  194. package/src/reducer/transaction.ts +0 -120
  195. package/src/reducer.ts +0 -314
  196. package/src/runtime/primitives.ts +0 -1
  197. package/src/runtime/types/runtime-api.ts +0 -1
  198. package/src/runtime/workspace-contract.ts +0 -32
  199. package/src/runtime-internal/components/InteractionForm.tsx +0 -1309
  200. package/src/runtime-internal/components/PluginRuntime.tsx +0 -103
  201. package/src/runtime-internal/components/board/target-layer.ts +0 -70
  202. package/src/runtime-internal/context/ClientParamSchemaContext.tsx +0 -44
  203. package/src/runtime-internal/context/InteractionDraftContext.tsx +0 -279
  204. package/src/runtime-internal/context/PluginSessionContext.tsx +0 -47
  205. package/src/runtime-internal/context/PluginStateContext.tsx +0 -262
  206. package/src/runtime-internal/context/RuntimeContext.tsx +0 -96
  207. package/src/runtime-internal/defaults/components.tsx +0 -409
  208. package/src/runtime-internal/defaults/index.ts +0 -11
  209. package/src/runtime-internal/errors/ValidationError.ts +0 -29
  210. package/src/runtime-internal/hooks/useActivePlayers.ts +0 -33
  211. package/src/runtime-internal/hooks/useBoardInteractions.ts +0 -665
  212. package/src/runtime-internal/hooks/useGameSelector.ts +0 -105
  213. package/src/runtime-internal/hooks/useGameView.ts +0 -9
  214. package/src/runtime-internal/hooks/useInteractionByKey.ts +0 -354
  215. package/src/runtime-internal/hooks/useInteractionHandle.ts +0 -438
  216. package/src/runtime-internal/hooks/useIsMyTurn.ts +0 -20
  217. package/src/runtime-internal/hooks/useLobby.ts +0 -76
  218. package/src/runtime-internal/hooks/useMe.ts +0 -48
  219. package/src/runtime-internal/hooks/usePlayerInfo.ts +0 -28
  220. package/src/runtime-internal/hooks/usePlayerTurnOrder.ts +0 -23
  221. package/src/runtime-internal/hooks/usePluginRuntime.ts +0 -147
  222. package/src/runtime-internal/hooks/useSeatInbox.ts +0 -61
  223. package/src/runtime-internal/hooks/useSimultaneousPhase.ts +0 -10
  224. package/src/runtime-internal/index.ts +0 -42
  225. package/src/runtime-internal/internal.ts +0 -43
  226. package/src/runtime-internal/plugin-styles.css +0 -250
  227. package/src/runtime-internal/primitives/board.tsx +0 -459
  228. package/src/runtime-internal/primitives/dialog-lifecycle.ts +0 -58
  229. package/src/runtime-internal/primitives/dice.tsx +0 -79
  230. package/src/runtime-internal/primitives/game-ui-provider.tsx +0 -35
  231. package/src/runtime-internal/primitives/game.tsx +0 -387
  232. package/src/runtime-internal/primitives/hand-intent-adapter.ts +0 -147
  233. package/src/runtime-internal/primitives/hand-surface.tsx +0 -594
  234. package/src/runtime-internal/primitives/index.ts +0 -196
  235. package/src/runtime-internal/primitives/interaction-form-binding.tsx +0 -56
  236. package/src/runtime-internal/primitives/interaction-submit.ts +0 -90
  237. package/src/runtime-internal/primitives/interaction.tsx +0 -987
  238. package/src/runtime-internal/primitives/phase.tsx +0 -43
  239. package/src/runtime-internal/primitives/player-roster.tsx +0 -302
  240. package/src/runtime-internal/primitives/primitive-props.tsx +0 -101
  241. package/src/runtime-internal/primitives/prompt.tsx +0 -255
  242. package/src/runtime-internal/primitives/ui.tsx +0 -60
  243. package/src/runtime-internal/primitives/zone.tsx +0 -791
  244. package/src/runtime-internal/reducer.ts +0 -30
  245. package/src/runtime-internal/runtime/createPluginRuntimeAPI.ts +0 -605
  246. package/src/runtime-internal/types/plugin-state.ts +0 -508
  247. package/src/runtime-internal/types/reducer-state.ts +0 -24
  248. package/src/runtime-internal/types/runtime-api.ts +0 -114
  249. package/src/runtime-internal/ui-contract.ts +0 -519
  250. package/src/runtime-internal/utils/card-intent-adapter.ts +0 -546
  251. package/src/runtime-internal/utils/interaction-inputs.ts +0 -492
  252. package/src/runtime-internal/utils/interaction-labels.ts +0 -23
  253. package/src/runtime-internal/utils/interaction-router.ts +0 -273
  254. package/src/runtime-internal/utils/interaction-status.ts +0 -74
  255. package/src/runtime-internal/workspace-contract.ts +0 -1170
  256. package/src/runtime.ts +0 -34
  257. package/src/testing/create-expect-api.ts +0 -352
  258. package/src/testing/create-test-runtime.ts +0 -381
  259. package/src/testing/definitions.ts +0 -127
  260. package/src/testing/index.ts +0 -3
  261. package/src/testing.ts +0 -1
  262. package/src/type-stubs/manifest-contract.d.ts +0 -42
  263. package/src/type-stubs/manifest-contract.js +0 -72
  264. package/src/type-stubs/ui-contract.d.ts +0 -5
  265. package/src/type-stubs/ui-contract.js +0 -1
  266. package/src/types/authoring-card-properties.type-test.ts +0 -266
  267. package/src/types/authoring.ts +0 -1282
  268. package/src/types/cards.ts +0 -19
  269. package/src/types/contracts.ts +0 -1550
  270. package/src/types/generated-helpers.ts +0 -35
  271. package/src/types/index.ts +0 -147
  272. package/src/types/slots.ts +0 -11
  273. package/src/types.ts +0 -1
  274. package/src/ui/components/ActionButton.tsx +0 -97
  275. package/src/ui/components/ActionPanel.tsx +0 -315
  276. package/src/ui/components/Card.tsx +0 -378
  277. package/src/ui/components/CardDragSurface.tsx +0 -1076
  278. package/src/ui/components/ChromeSuppressionContext.tsx +0 -70
  279. package/src/ui/components/CostDisplay.tsx +0 -145
  280. package/src/ui/components/DiceRoller.tsx +0 -581
  281. package/src/ui/components/Drawer.tsx +0 -180
  282. package/src/ui/components/ErrorBoundary.tsx +0 -275
  283. package/src/ui/components/GameEndDisplay.tsx +0 -398
  284. package/src/ui/components/GameSkeleton.tsx +0 -260
  285. package/src/ui/components/Hand.tsx +0 -468
  286. package/src/ui/components/HandDock.tsx +0 -299
  287. package/src/ui/components/HandView.tsx +0 -441
  288. package/src/ui/components/MobileHandTray.tsx +0 -381
  289. package/src/ui/components/MoreActions.tsx +0 -143
  290. package/src/ui/components/PhaseIndicator.tsx +0 -341
  291. package/src/ui/components/PlayArea.tsx +0 -146
  292. package/src/ui/components/PrimaryActionButton.tsx +0 -336
  293. package/src/ui/components/PrimaryButton.tsx +0 -45
  294. package/src/ui/components/ResourceCounter.tsx +0 -270
  295. package/src/ui/components/StagingZone.tsx +0 -134
  296. package/src/ui/components/ThemedButton.tsx +0 -113
  297. package/src/ui/components/Toast.tsx +0 -264
  298. package/src/ui/components/board/HexGrid.tsx +0 -1294
  299. package/src/ui/components/board/NetworkGraph.tsx +0 -476
  300. package/src/ui/components/board/SlotSystem.tsx +0 -388
  301. package/src/ui/components/board/SquareGrid.tsx +0 -1165
  302. package/src/ui/components/board/TrackBoard.tsx +0 -496
  303. package/src/ui/components/board/ZoneMap.tsx +0 -448
  304. package/src/ui/components/board/hex-board-view.ts +0 -123
  305. package/src/ui/components/board/index.ts +0 -142
  306. package/src/ui/components/board/interaction-accessibility.ts +0 -21
  307. package/src/ui/components/board/target-layer.ts +0 -66
  308. package/src/ui/components/card-render-content.type-test.ts +0 -27
  309. package/src/ui/components/hand-layout-math.ts +0 -163
  310. package/src/ui/components/hand-pointer-engine.ts +0 -413
  311. package/src/ui/components/index.ts +0 -245
  312. package/src/ui/components.ts +0 -1
  313. package/src/ui/defaults/components.tsx +0 -106
  314. package/src/ui/defaults/index.ts +0 -8
  315. package/src/ui/defaults.ts +0 -1
  316. package/src/ui/errors/ValidationError.ts +0 -29
  317. package/src/ui/helpers/cards.ts +0 -19
  318. package/src/ui/helpers/track-board.ts +0 -211
  319. package/src/ui/hooks/useBoardTopology.ts +0 -316
  320. package/src/ui/hooks/useCards.ts +0 -10
  321. package/src/ui/hooks/useHandCardPointer.ts +0 -381
  322. package/src/ui/hooks/useHandLayout.ts +0 -378
  323. package/src/ui/hooks/useHandPresentation.ts +0 -121
  324. package/src/ui/hooks/useHexBoard.ts +0 -74
  325. package/src/ui/hooks/useHexGrid.ts +0 -185
  326. package/src/ui/hooks/useIsMobile.ts +0 -35
  327. package/src/ui/hooks/usePanZoom.ts +0 -278
  328. package/src/ui/hooks/useSquareBoard.ts +0 -124
  329. package/src/ui/hooks/useSquareGrid.ts +0 -328
  330. package/src/ui/index.ts +0 -98
  331. package/src/ui/internal/ui/alert.tsx +0 -51
  332. package/src/ui/internal/ui/button.tsx +0 -58
  333. package/src/ui/internal/ui/dialog.tsx +0 -134
  334. package/src/ui/internal/ui/input.tsx +0 -21
  335. package/src/ui/internal/ui/label.tsx +0 -21
  336. package/src/ui/internal/ui/select.tsx +0 -129
  337. package/src/ui/internal/ui/tooltip.tsx +0 -54
  338. package/src/ui/internal/ui/utils.ts +0 -5
  339. package/src/ui/plugin-styles.css +0 -250
  340. package/src/ui/primitives/dialog-lifecycle.ts +0 -58
  341. package/src/ui/primitives/dice.tsx +0 -79
  342. package/src/ui/primitives/primitive-props.tsx +0 -101
  343. package/src/ui/theme/ThemeProvider.tsx +0 -252
  344. package/src/ui/theme/board.ts +0 -61
  345. package/src/ui/theme/css-vars.ts +0 -105
  346. package/src/ui/theme/derive.ts +0 -240
  347. package/src/ui/theme/index.ts +0 -61
  348. package/src/ui/theme/presets/arcade.ts +0 -261
  349. package/src/ui/theme/presets/studio.ts +0 -261
  350. package/src/ui/theme/presets/tabletop.ts +0 -266
  351. package/src/ui/theme/tokens.ts +0 -392
  352. package/src/ui/types/hex-color.ts +0 -20
  353. package/src/ui/types/player-state.ts +0 -463
  354. package/src/ui/types/tiled-board.ts +0 -785
  355. package/src/ui/types/visual-state.ts +0 -137
  356. package/src/ui.ts +0 -1
  357. /package/dist/{chunk-I46YJSOD.js.map → browser-interaction.js.map} +0 -0
  358. /package/dist/{chunk-KAELH4KC.js.map → chunk-3RQEICD3.js.map} +0 -0
  359. /package/dist/{chunk-T52J5RMF.js.map → codegen.js.map} +0 -0
  360. /package/dist/{generated/runtime-api.js.map → reducer-contract.js.map} +0 -0
  361. /package/dist/runtime/{types/runtime-api.js.map → runtime-api.js.map} +0 -0
  362. /package/dist/ui/{types/player-state.js → player-state.js} +0 -0
  363. /package/dist/ui/{types/player-state.js.map → player-state.js.map} +0 -0
@@ -0,0 +1,1691 @@
1
+ // src/browser-interaction/constants.ts
2
+ var DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME = "dreamboard-browser-interaction";
3
+ var DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION = "2.0.0";
4
+ var BROWSER_INTERACTION_ATTRIBUTES = {
5
+ protocol: "data-dreamboard-browser-protocol",
6
+ surface: "data-dreamboard-browser-surface",
7
+ scope: "data-dreamboard-browser-scope",
8
+ role: "data-dreamboard-browser-role",
9
+ intent: "data-dreamboard-browser-intent",
10
+ interactionKey: "data-dreamboard-interaction-key",
11
+ interactionId: "data-dreamboard-interaction-id",
12
+ descriptorDigest: "data-dreamboard-descriptor-digest",
13
+ draftDigest: "data-dreamboard-draft-digest",
14
+ readiness: "data-dreamboard-readiness",
15
+ inputKey: "data-dreamboard-input-key",
16
+ candidateValue: "data-dreamboard-candidate-value",
17
+ candidateState: "data-dreamboard-candidate-state",
18
+ actuatorKind: "data-dreamboard-actuator-kind",
19
+ enabled: "data-dreamboard-actuator-enabled",
20
+ actuatorId: "data-dreamboard-actuator-id",
21
+ semanticEffects: "data-dreamboard-semantic-effects",
22
+ acceptedEffectPatterns: "data-dreamboard-accepted-effect-patterns",
23
+ preparationPatterns: "data-dreamboard-preparation-patterns",
24
+ preparesIntent: "data-dreamboard-prepares-intent",
25
+ preparesInputKey: "data-dreamboard-prepares-input-key",
26
+ preparesCandidateValue: "data-dreamboard-prepares-candidate-value",
27
+ preparesActuatorKind: "data-dreamboard-prepares-actuator-kind",
28
+ diagnostic: "data-dreamboard-browser-diagnostic"
29
+ };
30
+ var BROWSER_INTERACTION_RECORD_ROLES = [
31
+ "interaction",
32
+ "actuator"
33
+ ];
34
+ var GAMEPLAY_BROWSER_INTERACTION_SURFACE = "gameplay";
35
+ var GAMEPLAY_BROWSER_INTERACTION_INTENTS = [
36
+ "arm",
37
+ "reveal",
38
+ "invoke",
39
+ "select",
40
+ "toggle",
41
+ "increment",
42
+ "decrement",
43
+ "fill",
44
+ "submit"
45
+ ];
46
+ var GAMEPLAY_BROWSER_INTERACTION_EFFECT_KINDS = [
47
+ "setCandidate",
48
+ "adjustResource",
49
+ "setScalar",
50
+ "commit",
51
+ "invoke"
52
+ ];
53
+ var BROWSER_INTERACTION_READINESS_VALUES = [
54
+ "ready",
55
+ "blocked",
56
+ "unavailable"
57
+ ];
58
+ var BROWSER_INTERACTION_CANDIDATE_STATES = [
59
+ "selected",
60
+ "unselected",
61
+ "mixed"
62
+ ];
63
+ var BROWSER_INTERACTION_ACTUATOR_KINDS = [
64
+ "click",
65
+ "fill",
66
+ "keyboard",
67
+ "pointer"
68
+ ];
69
+
70
+ // src/browser-interaction/canonical.ts
71
+ function assertCanonicalValue(value) {
72
+ if (value === null) return;
73
+ switch (typeof value) {
74
+ case "boolean":
75
+ case "string":
76
+ return;
77
+ case "number":
78
+ if (Number.isFinite(value)) return;
79
+ break;
80
+ case "object":
81
+ if (Array.isArray(value)) {
82
+ value.forEach(assertCanonicalValue);
83
+ return;
84
+ }
85
+ if (Object.getPrototypeOf(value) !== Object.prototype) break;
86
+ for (const [key, item] of Object.entries(value)) {
87
+ if (item === void 0) {
88
+ throw new Error(
89
+ `Browser interaction candidate '${key}' cannot be undefined.`
90
+ );
91
+ }
92
+ assertCanonicalValue(item);
93
+ }
94
+ return;
95
+ }
96
+ throw new Error(
97
+ `Browser interaction candidates must be JSON-serializable primitives, arrays or plain objects. Received ${typeof value}.`
98
+ );
99
+ }
100
+ function canonicalizeValue(value) {
101
+ if (Array.isArray(value)) {
102
+ return value.map(canonicalizeValue);
103
+ }
104
+ if (value && typeof value === "object") {
105
+ const objectValue = value;
106
+ return Object.fromEntries(
107
+ Object.keys(objectValue).sort().map((key) => [key, canonicalizeValue(objectValue[key])])
108
+ );
109
+ }
110
+ return value;
111
+ }
112
+ function encodeCanonicalCandidateValue(value) {
113
+ assertCanonicalValue(value);
114
+ return JSON.stringify(canonicalizeValue(value));
115
+ }
116
+ function decodeCanonicalCandidateValue(encoded) {
117
+ const parsed = JSON.parse(encoded);
118
+ assertCanonicalValue(parsed);
119
+ return canonicalizeValue(parsed);
120
+ }
121
+ function compareStableJson(a, b) {
122
+ const encodedA = encodeCanonicalCandidateValue(a);
123
+ const encodedB = encodeCanonicalCandidateValue(b);
124
+ return encodedA.localeCompare(encodedB);
125
+ }
126
+
127
+ // src/browser-interaction/effects.ts
128
+ function encodeBrowserInteractionEffect(effect) {
129
+ return encodeCanonicalCandidateValue(effect);
130
+ }
131
+ function decodeBrowserInteractionEffect(encoded) {
132
+ const decoded = decodeCanonicalCandidateValue(encoded);
133
+ if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) {
134
+ throw new Error("Browser interaction effect must be a canonical object.");
135
+ }
136
+ const decodedObject = decoded;
137
+ const kind = decodedObject.kind;
138
+ if (typeof kind !== "string" || kind.length === 0) {
139
+ throw new Error("Browser interaction effect requires a string kind.");
140
+ }
141
+ return decodedObject;
142
+ }
143
+ function encodeBrowserInteractionEffectPattern(pattern) {
144
+ return encodeCanonicalCandidateValue(pattern);
145
+ }
146
+ function decodeBrowserInteractionEffectPattern(encoded) {
147
+ const decoded = decodeCanonicalCandidateValue(encoded);
148
+ assertBrowserInteractionEffectPattern(decoded);
149
+ return decoded;
150
+ }
151
+ function browserInteractionEffectPatternMatches(pattern, effect) {
152
+ switch (pattern.kind) {
153
+ case "exact":
154
+ return encodeBrowserInteractionEffect(pattern.effect) === encodeBrowserInteractionEffect(effect);
155
+ case "match": {
156
+ if (effect.kind !== pattern.effectKind) return false;
157
+ for (const [field, expected] of Object.entries(pattern.fields ?? {})) {
158
+ const actual = effect[field];
159
+ if (actual === void 0) return false;
160
+ if (encodeCanonicalCandidateValue(actual) !== encodeCanonicalCandidateValue(expected)) {
161
+ return false;
162
+ }
163
+ }
164
+ const scalar = pattern.scalar;
165
+ if (scalar) {
166
+ const actual = effect[scalar.field];
167
+ if (typeof actual !== "number" || !Number.isFinite(actual)) {
168
+ return false;
169
+ }
170
+ if (scalar.integer === true && !Number.isInteger(actual)) {
171
+ return false;
172
+ }
173
+ if (scalar.min !== void 0 && actual < scalar.min) {
174
+ return false;
175
+ }
176
+ if (scalar.max !== void 0 && actual > scalar.max) {
177
+ return false;
178
+ }
179
+ }
180
+ return true;
181
+ }
182
+ }
183
+ }
184
+ function assertBrowserInteractionEffectPattern(value) {
185
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
186
+ throw new Error("Browser interaction effect pattern must be an object.");
187
+ }
188
+ const pattern = value;
189
+ if (pattern.kind === "exact") {
190
+ decodeBrowserInteractionEffect(
191
+ encodeCanonicalCandidateValue(pattern.effect)
192
+ );
193
+ return;
194
+ }
195
+ if (pattern.kind === "match") {
196
+ if (typeof pattern.effectKind !== "string" || pattern.effectKind.length === 0) {
197
+ throw new Error(
198
+ "Browser interaction match pattern requires an effectKind."
199
+ );
200
+ }
201
+ if (pattern.fields !== void 0) {
202
+ if (!pattern.fields || typeof pattern.fields !== "object" || Array.isArray(pattern.fields)) {
203
+ throw new Error(
204
+ "Browser interaction match pattern fields must be an object."
205
+ );
206
+ }
207
+ }
208
+ if (pattern.scalar !== void 0) {
209
+ if (!pattern.scalar || typeof pattern.scalar !== "object" || Array.isArray(pattern.scalar) || typeof pattern.scalar.field !== "string" || pattern.scalar.field.length === 0) {
210
+ throw new Error(
211
+ "Browser interaction scalar pattern requires a scalar field."
212
+ );
213
+ }
214
+ }
215
+ return;
216
+ }
217
+ throw new Error("Unknown browser interaction effect pattern kind.");
218
+ }
219
+ function gameplaySetCandidateEffect(input) {
220
+ return { kind: "setCandidate", ...input };
221
+ }
222
+ function gameplayAdjustResourceEffect(input) {
223
+ return { kind: "adjustResource", ...input };
224
+ }
225
+ function gameplaySetScalarEffect(input) {
226
+ return { kind: "setScalar", ...input };
227
+ }
228
+ function gameplayCommitEffect() {
229
+ return { kind: "commit" };
230
+ }
231
+ function gameplayInvokeEffect() {
232
+ return { kind: "invoke" };
233
+ }
234
+
235
+ // src/browser-interaction/attributes.ts
236
+ function baseGameplayAttributes(input) {
237
+ return {
238
+ [BROWSER_INTERACTION_ATTRIBUTES.protocol]: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
239
+ [BROWSER_INTERACTION_ATTRIBUTES.surface]: input.surface,
240
+ [BROWSER_INTERACTION_ATTRIBUTES.scope]: input.scopeId,
241
+ [BROWSER_INTERACTION_ATTRIBUTES.interactionKey]: input.interactionKey,
242
+ [BROWSER_INTERACTION_ATTRIBUTES.interactionId]: input.interactionId
243
+ };
244
+ }
245
+ function createBrowserInteractionRootAttributes(input) {
246
+ return {
247
+ ...baseGameplayAttributes(input),
248
+ [BROWSER_INTERACTION_ATTRIBUTES.role]: "interaction",
249
+ [BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest]: input.descriptorDigest ?? "",
250
+ [BROWSER_INTERACTION_ATTRIBUTES.draftDigest]: input.draftDigest ?? "",
251
+ [BROWSER_INTERACTION_ATTRIBUTES.readiness]: input.readiness
252
+ };
253
+ }
254
+ function createBrowserInteractionActuatorAttributes(input) {
255
+ const attrs = {
256
+ ...baseGameplayAttributes(input),
257
+ [BROWSER_INTERACTION_ATTRIBUTES.role]: "actuator",
258
+ [BROWSER_INTERACTION_ATTRIBUTES.intent]: input.intent,
259
+ [BROWSER_INTERACTION_ATTRIBUTES.actuatorKind]: input.actuatorKind,
260
+ [BROWSER_INTERACTION_ATTRIBUTES.enabled]: input.enabled === false ? "false" : "true"
261
+ };
262
+ if (input.descriptorDigest) {
263
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest] = input.descriptorDigest;
264
+ }
265
+ if (input.draftDigest) {
266
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.draftDigest] = input.draftDigest;
267
+ }
268
+ if (input.actuatorId) {
269
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.actuatorId] = input.actuatorId;
270
+ }
271
+ if (input.inputKey) {
272
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.inputKey] = input.inputKey;
273
+ }
274
+ if ("candidateValue" in input) {
275
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.candidateValue] = encodeCanonicalCandidateValue(input.candidateValue);
276
+ }
277
+ if (input.candidateState) {
278
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.candidateState] = input.candidateState;
279
+ }
280
+ if (input.semanticEffects && input.semanticEffects.length > 0) {
281
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.semanticEffects] = JSON.stringify(
282
+ input.semanticEffects.map(encodeBrowserInteractionEffect)
283
+ );
284
+ }
285
+ if (input.acceptedEffectPatterns && input.acceptedEffectPatterns.length > 0) {
286
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.acceptedEffectPatterns] = JSON.stringify(
287
+ input.acceptedEffectPatterns.map(encodeBrowserInteractionEffectPattern)
288
+ );
289
+ }
290
+ if (input.preparationPatterns && input.preparationPatterns.length > 0) {
291
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparationPatterns] = JSON.stringify(
292
+ input.preparationPatterns.map(encodeBrowserInteractionEffectPattern)
293
+ );
294
+ }
295
+ if (input.prepares) {
296
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparesIntent] = input.prepares.intent;
297
+ if (input.prepares.inputKey) {
298
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparesInputKey] = input.prepares.inputKey;
299
+ }
300
+ if (input.prepares.candidateValueKey) {
301
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparesCandidateValue] = input.prepares.candidateValueKey;
302
+ } else if ("candidateValue" in input.prepares) {
303
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparesCandidateValue] = encodeCanonicalCandidateValue(input.prepares.candidateValue);
304
+ }
305
+ if (input.prepares.actuatorKind) {
306
+ attrs[BROWSER_INTERACTION_ATTRIBUTES.preparesActuatorKind] = input.prepares.actuatorKind;
307
+ }
308
+ }
309
+ return attrs;
310
+ }
311
+ function createGameplayInteractionRootAttributes(input) {
312
+ return createBrowserInteractionRootAttributes({
313
+ ...input,
314
+ surface: GAMEPLAY_BROWSER_INTERACTION_SURFACE
315
+ });
316
+ }
317
+ function createGameplayActuatorAttributes(input) {
318
+ return createBrowserInteractionActuatorAttributes({
319
+ ...input,
320
+ surface: GAMEPLAY_BROWSER_INTERACTION_SURFACE
321
+ });
322
+ }
323
+ function createBrowserInteractionActuatorKey(input) {
324
+ return [
325
+ input.surface,
326
+ input.scopeId,
327
+ input.interactionKey,
328
+ input.intent,
329
+ input.inputKey ?? "",
330
+ input.candidateValueKey ?? "",
331
+ input.actuatorKind
332
+ ].map((part) => encodeURIComponent(part)).join("|");
333
+ }
334
+
335
+ // src/browser-interaction/registry.ts
336
+ function defineBrowserInteractionSurface(definition) {
337
+ const seen = /* @__PURE__ */ new Set();
338
+ for (const intent of definition.intents) {
339
+ if (seen.has(intent)) {
340
+ throw new Error(
341
+ `Browser interaction surface '${definition.surface}' declares duplicate intent '${intent}'.`
342
+ );
343
+ }
344
+ seen.add(intent);
345
+ }
346
+ return definition;
347
+ }
348
+ var gameplayBrowserInteractionSurface = defineBrowserInteractionSurface({
349
+ surface: GAMEPLAY_BROWSER_INTERACTION_SURFACE,
350
+ intents: GAMEPLAY_BROWSER_INTERACTION_INTENTS,
351
+ effectKinds: GAMEPLAY_BROWSER_INTERACTION_EFFECT_KINDS
352
+ });
353
+ function createBrowserInteractionRegistry(definitions = [
354
+ gameplayBrowserInteractionSurface
355
+ ]) {
356
+ const surfaces = /* @__PURE__ */ new Map();
357
+ for (const definition of definitions) {
358
+ const existing = surfaces.get(definition.surface);
359
+ if (existing) {
360
+ const existingIntents = existing.intents.join(",");
361
+ const nextIntents = definition.intents.join(",");
362
+ const existingEffectKinds = (existing.effectKinds ?? []).join(",");
363
+ const nextEffectKinds = (definition.effectKinds ?? []).join(",");
364
+ if (existingIntents !== nextIntents || existingEffectKinds !== nextEffectKinds) {
365
+ throw new Error(
366
+ `Browser interaction surface '${definition.surface}' is already registered with a different intent vocabulary or effect vocabulary.`
367
+ );
368
+ }
369
+ continue;
370
+ }
371
+ surfaces.set(definition.surface, definition);
372
+ }
373
+ return { surfaces };
374
+ }
375
+ var defaultBrowserInteractionRegistry = createBrowserInteractionRegistry();
376
+
377
+ // src/browser-interaction/normalize.ts
378
+ function normalizeBrowserInteractionRecords(records, options = {}) {
379
+ const registry = options.registry ?? defaultBrowserInteractionRegistry;
380
+ const diagnostics = [];
381
+ const surfaces = /* @__PURE__ */ new Map();
382
+ const getSurface = (surface, scopeId) => {
383
+ const registered = registry.surfaces.get(surface);
384
+ const key = `${surface}\0${scopeId}`;
385
+ const existing = surfaces.get(key);
386
+ if (existing) return existing;
387
+ if (!registered) {
388
+ const diagnostic = diagnosticFor({
389
+ code: "unknown-surface",
390
+ message: `Unknown browser interaction surface '${surface}'.`,
391
+ surface,
392
+ scopeId
393
+ });
394
+ diagnostics.push(diagnostic);
395
+ const pending2 = {
396
+ kind: "unknown",
397
+ surface,
398
+ scopeId,
399
+ diagnostics: [diagnostic]
400
+ };
401
+ surfaces.set(key, pending2);
402
+ return pending2;
403
+ }
404
+ const pending = {
405
+ kind: "semantic",
406
+ surface,
407
+ scopeId,
408
+ interactions: /* @__PURE__ */ new Map(),
409
+ diagnostics: []
410
+ };
411
+ surfaces.set(key, pending);
412
+ return pending;
413
+ };
414
+ for (const record of records) {
415
+ const attributes = record.attributes;
416
+ const protocol = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.protocol);
417
+ const surface = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.surface);
418
+ const scopeId = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.scope);
419
+ const role = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.role);
420
+ if (protocol !== DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION) {
421
+ diagnostics.push(
422
+ diagnosticFor({
423
+ code: "invalid-protocol",
424
+ message: `Expected browser interaction protocol ${DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION}.`,
425
+ surface,
426
+ scopeId
427
+ })
428
+ );
429
+ continue;
430
+ }
431
+ if (!surface || !scopeId || role !== "interaction" && role !== "actuator") {
432
+ diagnostics.push(
433
+ diagnosticFor({
434
+ code: "invalid-record",
435
+ message: "Browser interaction records require protocol, surface, scope and role.",
436
+ surface,
437
+ scopeId
438
+ })
439
+ );
440
+ continue;
441
+ }
442
+ const pendingSurface = getSurface(surface, scopeId);
443
+ if (!pendingSurface || pendingSurface.kind !== "semantic") {
444
+ continue;
445
+ }
446
+ const interactionKey = text(
447
+ attributes,
448
+ BROWSER_INTERACTION_ATTRIBUTES.interactionKey
449
+ );
450
+ const interactionId = text(
451
+ attributes,
452
+ BROWSER_INTERACTION_ATTRIBUTES.interactionId
453
+ );
454
+ if (!interactionKey || !interactionId) {
455
+ pushSurfaceDiagnostic(
456
+ pendingSurface,
457
+ diagnostics,
458
+ diagnosticFor({
459
+ code: "invalid-record",
460
+ message: "Browser interaction records require interaction key and id.",
461
+ surface,
462
+ scopeId
463
+ })
464
+ );
465
+ continue;
466
+ }
467
+ const interaction = getInteraction(
468
+ pendingSurface,
469
+ interactionKey,
470
+ interactionId
471
+ );
472
+ if (role === "interaction") {
473
+ interaction.rootSeen = true;
474
+ interaction.descriptorDigest = optionalText(
475
+ attributes,
476
+ BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest
477
+ );
478
+ interaction.draftDigest = optionalText(
479
+ attributes,
480
+ BROWSER_INTERACTION_ATTRIBUTES.draftDigest
481
+ );
482
+ interaction.readiness = parseReadiness(
483
+ text(attributes, BROWSER_INTERACTION_ATTRIBUTES.readiness)
484
+ );
485
+ continue;
486
+ }
487
+ const actuator = parseGameplayActuator(attributes, {
488
+ surface,
489
+ scopeId,
490
+ interactionKey,
491
+ interactionId
492
+ });
493
+ if (actuator.diagnostics.length > 0) {
494
+ interaction.diagnostics.push(...actuator.diagnostics);
495
+ diagnostics.push(...actuator.diagnostics);
496
+ }
497
+ const registered = registry.surfaces.get(surface);
498
+ if (registered && !registered.intents.includes(actuator.intent)) {
499
+ const diagnostic = diagnosticFor({
500
+ code: "unknown-intent",
501
+ message: `Unknown browser interaction intent '${actuator.intent}' for surface '${surface}'.`,
502
+ surface,
503
+ scopeId,
504
+ interactionKey,
505
+ intent: actuator.intent,
506
+ actuatorId: actuator.actuatorId
507
+ });
508
+ interaction.diagnostics.push(diagnostic);
509
+ diagnostics.push(diagnostic);
510
+ }
511
+ if (registered?.effectKinds) {
512
+ for (const effect of actuator.semanticEffects) {
513
+ if (!registered.effectKinds.includes(effect.kind)) {
514
+ const diagnostic = diagnosticFor({
515
+ code: "unknown-surface-effect",
516
+ message: `Unknown browser interaction effect '${effect.kind}' for surface '${surface}'.`,
517
+ surface,
518
+ scopeId,
519
+ interactionKey,
520
+ intent: actuator.intent,
521
+ actuatorId: actuator.actuatorId
522
+ });
523
+ interaction.diagnostics.push(diagnostic);
524
+ diagnostics.push(diagnostic);
525
+ }
526
+ }
527
+ for (const pattern of [
528
+ ...actuator.acceptedEffectPatterns,
529
+ ...actuator.preparationPatterns
530
+ ]) {
531
+ const effectKind = pattern.kind === "exact" ? pattern.effect.kind : pattern.effectKind;
532
+ if (!registered.effectKinds.includes(effectKind)) {
533
+ const diagnostic = diagnosticFor({
534
+ code: "unknown-surface-effect",
535
+ message: `Unknown browser interaction effect '${effectKind}' for surface '${surface}'.`,
536
+ surface,
537
+ scopeId,
538
+ interactionKey,
539
+ intent: actuator.intent,
540
+ actuatorId: actuator.actuatorId
541
+ });
542
+ interaction.diagnostics.push(diagnostic);
543
+ diagnostics.push(diagnostic);
544
+ }
545
+ }
546
+ }
547
+ interaction.actuators.push(actuator);
548
+ }
549
+ for (const surface of surfaces.values()) {
550
+ if (surface.kind !== "semantic") continue;
551
+ for (const interaction of surface.interactions.values()) {
552
+ if (interaction.rootSeen || interaction.actuators.length === 0) continue;
553
+ const diagnostic = diagnosticFor({
554
+ code: "orphan-actuator",
555
+ message: "Browser interaction actuators require a rendered semantic root.",
556
+ surface: surface.surface,
557
+ scopeId: surface.scopeId,
558
+ interactionKey: interaction.interactionKey
559
+ });
560
+ interaction.diagnostics.push(diagnostic);
561
+ diagnostics.push(diagnostic);
562
+ }
563
+ }
564
+ const snapshot = {
565
+ protocol: {
566
+ name: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME,
567
+ version: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION
568
+ },
569
+ surfaces: [...surfaces.values()].map(finalizeSurface).sort(compareSurface),
570
+ diagnostics: []
571
+ };
572
+ const validationDiagnostics = validateBrowserInteractionSnapshot(snapshot);
573
+ return {
574
+ ...snapshot,
575
+ diagnostics: [...diagnostics, ...validationDiagnostics].sort(
576
+ compareDiagnostic
577
+ )
578
+ };
579
+ }
580
+ function validateBrowserInteractionSnapshot(snapshot) {
581
+ const diagnostics = [];
582
+ for (const surface of snapshot.surfaces) {
583
+ if (!isSemanticSurfaceSnapshot(surface)) continue;
584
+ for (const interaction of surface.interactions) {
585
+ const enabledByKey = /* @__PURE__ */ new Map();
586
+ for (const actuator of interaction.actuators) {
587
+ if (!actuator.enabled) continue;
588
+ const key = actuatorIdentityKey({
589
+ surface: surface.surface,
590
+ scopeId: surface.scopeId,
591
+ interactionKey: interaction.interactionKey,
592
+ actuator
593
+ });
594
+ const group = enabledByKey.get(key) ?? [];
595
+ group.push(actuator);
596
+ enabledByKey.set(key, group);
597
+ }
598
+ for (const [key, actuators] of enabledByKey) {
599
+ if (actuators.length > 1) {
600
+ diagnostics.push(
601
+ diagnosticFor({
602
+ code: "duplicate-enabled-actuator",
603
+ message: `Duplicate enabled actuator for '${key}'.`,
604
+ surface: surface.surface,
605
+ scopeId: surface.scopeId,
606
+ interactionKey: interaction.interactionKey,
607
+ intent: actuators[0]?.intent,
608
+ actuatorId: actuators[0]?.actuatorId
609
+ })
610
+ );
611
+ }
612
+ }
613
+ diagnostics.push(
614
+ ...diagnosticsForPreparationCycles(surface, interaction),
615
+ ...diagnosticsForPreparationPatternAmbiguity(surface, interaction),
616
+ ...diagnosticsForInvalidAcceptedPatterns(surface, interaction),
617
+ ...diagnosticsForGameplayEffectCompatibility(surface, interaction)
618
+ );
619
+ }
620
+ }
621
+ return diagnostics.sort(compareDiagnostic);
622
+ }
623
+ function diagnosticsForInvalidAcceptedPatterns(surface, interaction) {
624
+ const diagnostics = [];
625
+ for (const actuator of interaction.actuators) {
626
+ for (const pattern of actuator.acceptedEffectPatterns) {
627
+ if (pattern.kind === "match" && Object.keys(pattern.fields ?? {}).length === 0 && pattern.scalar === void 0) {
628
+ diagnostics.push(
629
+ diagnosticFor({
630
+ code: "invalid-effect-pattern",
631
+ message: "Accepted-effect match patterns must be bounded by fields or scalar constraints.",
632
+ surface: surface.surface,
633
+ scopeId: surface.scopeId,
634
+ interactionKey: interaction.interactionKey,
635
+ intent: actuator.intent,
636
+ actuatorId: actuator.actuatorId
637
+ })
638
+ );
639
+ }
640
+ }
641
+ }
642
+ return diagnostics;
643
+ }
644
+ function diagnosticsForGameplayEffectCompatibility(surface, interaction) {
645
+ if (surface.surface !== GAMEPLAY_BROWSER_INTERACTION_SURFACE) return [];
646
+ const diagnostics = [];
647
+ for (const actuator of interaction.actuators) {
648
+ for (const effect of actuator.semanticEffects) {
649
+ if (!gameplayIntentCanPerformEffect(actuator.intent, effect.kind)) {
650
+ diagnostics.push(
651
+ diagnosticFor({
652
+ code: "effect-intent-incompatibility",
653
+ message: "Gameplay browser interaction intent is incompatible with its semantic effect.",
654
+ surface: surface.surface,
655
+ scopeId: surface.scopeId,
656
+ interactionKey: interaction.interactionKey,
657
+ intent: actuator.intent,
658
+ actuatorId: actuator.actuatorId
659
+ })
660
+ );
661
+ }
662
+ }
663
+ }
664
+ return diagnostics;
665
+ }
666
+ function gameplayIntentCanPerformEffect(intent, effectKind) {
667
+ switch (effectKind) {
668
+ case "setCandidate":
669
+ return intent === "select" || intent === "toggle";
670
+ case "adjustResource":
671
+ return intent === "increment" || intent === "decrement";
672
+ case "setScalar":
673
+ return intent === "fill" || intent === "increment" || intent === "decrement";
674
+ case "commit":
675
+ return intent === "submit" || intent === "invoke";
676
+ case "invoke":
677
+ return intent === "invoke" || intent === "select" || intent === "toggle";
678
+ default:
679
+ return true;
680
+ }
681
+ }
682
+ function parseGameplayActuator(attributes, context) {
683
+ const diagnostics = [];
684
+ const intent = text(attributes, BROWSER_INTERACTION_ATTRIBUTES.intent);
685
+ const actuatorKind = parseActuatorKind(
686
+ text(attributes, BROWSER_INTERACTION_ATTRIBUTES.actuatorKind)
687
+ );
688
+ const inputKey = optionalText(
689
+ attributes,
690
+ BROWSER_INTERACTION_ATTRIBUTES.inputKey
691
+ );
692
+ const candidate = parseCandidate(
693
+ attributes,
694
+ BROWSER_INTERACTION_ATTRIBUTES.candidateValue,
695
+ context,
696
+ intent,
697
+ diagnostics
698
+ );
699
+ const candidateState = parseCandidateState(
700
+ optionalText(attributes, BROWSER_INTERACTION_ATTRIBUTES.candidateState)
701
+ );
702
+ const explicitId = optionalText(
703
+ attributes,
704
+ BROWSER_INTERACTION_ATTRIBUTES.actuatorId
705
+ );
706
+ const enabled = parseEnabled(
707
+ attributes[BROWSER_INTERACTION_ATTRIBUTES.enabled]
708
+ );
709
+ const actuatorId = explicitId ?? createBrowserInteractionActuatorKey({
710
+ surface: context.surface,
711
+ scopeId: context.scopeId,
712
+ interactionKey: context.interactionKey,
713
+ intent,
714
+ inputKey,
715
+ candidateValueKey: candidate?.candidateValueKey,
716
+ actuatorKind
717
+ });
718
+ const preparesIntent = optionalText(
719
+ attributes,
720
+ BROWSER_INTERACTION_ATTRIBUTES.preparesIntent
721
+ );
722
+ const preparesCandidate = parseCandidate(
723
+ attributes,
724
+ BROWSER_INTERACTION_ATTRIBUTES.preparesCandidateValue,
725
+ context,
726
+ preparesIntent ?? intent,
727
+ diagnostics
728
+ );
729
+ const prepares = preparesIntent === void 0 ? void 0 : {
730
+ intent: preparesIntent,
731
+ inputKey: optionalText(
732
+ attributes,
733
+ BROWSER_INTERACTION_ATTRIBUTES.preparesInputKey
734
+ ),
735
+ candidateValue: preparesCandidate?.candidateValue,
736
+ candidateValueKey: preparesCandidate?.candidateValueKey,
737
+ actuatorKind: parseOptionalActuatorKind(
738
+ optionalText(
739
+ attributes,
740
+ BROWSER_INTERACTION_ATTRIBUTES.preparesActuatorKind
741
+ )
742
+ )
743
+ };
744
+ const semanticEffects = parseEffectList(
745
+ attributes,
746
+ BROWSER_INTERACTION_ATTRIBUTES.semanticEffects,
747
+ context,
748
+ intent,
749
+ diagnostics
750
+ );
751
+ const acceptedEffectPatterns = parseEffectPatternList(
752
+ attributes,
753
+ BROWSER_INTERACTION_ATTRIBUTES.acceptedEffectPatterns,
754
+ context,
755
+ intent,
756
+ diagnostics
757
+ );
758
+ const preparationPatterns = parseEffectPatternList(
759
+ attributes,
760
+ BROWSER_INTERACTION_ATTRIBUTES.preparationPatterns,
761
+ context,
762
+ intent,
763
+ diagnostics
764
+ );
765
+ if (!intent) {
766
+ diagnostics.push(
767
+ diagnosticFor({
768
+ code: "invalid-record",
769
+ message: "Browser interaction actuator records require an intent.",
770
+ ...context
771
+ })
772
+ );
773
+ }
774
+ return {
775
+ actuatorId,
776
+ intent,
777
+ descriptorDigest: optionalText(
778
+ attributes,
779
+ BROWSER_INTERACTION_ATTRIBUTES.descriptorDigest
780
+ ),
781
+ draftDigest: optionalText(
782
+ attributes,
783
+ BROWSER_INTERACTION_ATTRIBUTES.draftDigest
784
+ ),
785
+ inputKey,
786
+ candidateValue: candidate?.candidateValue,
787
+ candidateValueKey: candidate?.candidateValueKey,
788
+ candidateState,
789
+ enabled,
790
+ actuatorKind,
791
+ semanticEffects,
792
+ acceptedEffectPatterns,
793
+ preparationPatterns,
794
+ prepares,
795
+ diagnostics: diagnostics.sort(compareDiagnostic)
796
+ };
797
+ }
798
+ function parseEffectList(attributes, attribute, context, intent, diagnostics) {
799
+ const encodedList = optionalText(attributes, attribute);
800
+ if (encodedList === void 0) return [];
801
+ try {
802
+ const raw = JSON.parse(encodedList);
803
+ if (!Array.isArray(raw) || raw.some((item) => typeof item !== "string")) {
804
+ throw new Error("Expected encoded effect array.");
805
+ }
806
+ return raw.map((encoded) => decodeBrowserInteractionEffect(encoded)).sort(
807
+ (a, b) => encodeBrowserInteractionEffect(a).localeCompare(
808
+ encodeBrowserInteractionEffect(b)
809
+ )
810
+ );
811
+ } catch {
812
+ diagnostics.push(
813
+ diagnosticFor({
814
+ code: "invalid-effect-payload",
815
+ message: "Invalid browser interaction semantic effect payload.",
816
+ ...context,
817
+ intent
818
+ })
819
+ );
820
+ return [];
821
+ }
822
+ }
823
+ function parseEffectPatternList(attributes, attribute, context, intent, diagnostics) {
824
+ const encodedList = optionalText(attributes, attribute);
825
+ if (encodedList === void 0) return [];
826
+ try {
827
+ const raw = JSON.parse(encodedList);
828
+ if (!Array.isArray(raw) || raw.some((item) => typeof item !== "string")) {
829
+ throw new Error("Expected encoded effect pattern array.");
830
+ }
831
+ return raw.map((encoded) => decodeBrowserInteractionEffectPattern(encoded)).sort(
832
+ (a, b) => encodeBrowserInteractionEffectPattern(a).localeCompare(
833
+ encodeBrowserInteractionEffectPattern(b)
834
+ )
835
+ );
836
+ } catch {
837
+ diagnostics.push(
838
+ diagnosticFor({
839
+ code: "invalid-effect-pattern",
840
+ message: "Invalid browser interaction semantic effect pattern.",
841
+ ...context,
842
+ intent
843
+ })
844
+ );
845
+ return [];
846
+ }
847
+ }
848
+ function parseCandidate(attributes, attribute, context, intent, diagnostics) {
849
+ const encoded = optionalText(attributes, attribute);
850
+ if (encoded === void 0) return void 0;
851
+ try {
852
+ const candidateValue = decodeCanonicalCandidateValue(encoded);
853
+ return {
854
+ candidateValue,
855
+ candidateValueKey: encodeCanonicalCandidateValue(candidateValue)
856
+ };
857
+ } catch {
858
+ diagnostics.push(
859
+ diagnosticFor({
860
+ code: "invalid-candidate",
861
+ message: `Invalid canonical browser interaction candidate '${encoded}'.`,
862
+ ...context,
863
+ intent
864
+ })
865
+ );
866
+ return void 0;
867
+ }
868
+ }
869
+ function getInteraction(surface, interactionKey, interactionId) {
870
+ const existing = surface.interactions.get(interactionKey);
871
+ if (existing) return existing;
872
+ const next = {
873
+ interactionKey,
874
+ interactionId,
875
+ readiness: "ready",
876
+ rootSeen: false,
877
+ actuators: [],
878
+ diagnostics: []
879
+ };
880
+ surface.interactions.set(interactionKey, next);
881
+ return next;
882
+ }
883
+ function finalizeSurface(surface) {
884
+ if (surface.kind !== "semantic") {
885
+ return {
886
+ surface: surface.surface,
887
+ scopeId: surface.scopeId,
888
+ diagnostics: surface.diagnostics.sort(compareDiagnostic)
889
+ };
890
+ }
891
+ const interactions = [
892
+ ...surface.interactions.values()
893
+ ].map((interaction) => ({
894
+ interactionKey: interaction.interactionKey,
895
+ interactionId: interaction.interactionId,
896
+ descriptorDigest: interaction.descriptorDigest,
897
+ draftDigest: interaction.draftDigest,
898
+ readiness: interaction.readiness,
899
+ actuators: interaction.actuators.sort(compareActuator),
900
+ diagnostics: interaction.diagnostics.sort(compareDiagnostic)
901
+ })).sort((a, b) => a.interactionKey.localeCompare(b.interactionKey));
902
+ return {
903
+ surface: surface.surface,
904
+ scopeId: surface.scopeId,
905
+ interactions,
906
+ diagnostics: surface.diagnostics.sort(compareDiagnostic)
907
+ };
908
+ }
909
+ function diagnosticsForPreparationCycles(surface, interaction) {
910
+ const diagnostics = [];
911
+ diagnostics.push(
912
+ ...diagnosticsForEffectPreparationCycles(surface, interaction)
913
+ );
914
+ const actuators = /* @__PURE__ */ new Map();
915
+ for (const actuator of interaction.actuators) {
916
+ actuators.set(
917
+ actuatorIdentityKey({
918
+ surface: surface.surface,
919
+ scopeId: surface.scopeId,
920
+ interactionKey: interaction.interactionKey,
921
+ actuator
922
+ }),
923
+ actuator
924
+ );
925
+ }
926
+ for (const actuator of interaction.actuators) {
927
+ const visited = /* @__PURE__ */ new Set();
928
+ let current = actuator;
929
+ while (current?.prepares) {
930
+ const key = actuatorIdentityKey({
931
+ surface: surface.surface,
932
+ scopeId: surface.scopeId,
933
+ interactionKey: interaction.interactionKey,
934
+ actuator: current
935
+ });
936
+ if (visited.has(key)) {
937
+ diagnostics.push(
938
+ diagnosticFor({
939
+ code: "preparation-cycle",
940
+ message: `Preparation cycle detected for actuator '${current.actuatorId}'.`,
941
+ surface: surface.surface,
942
+ scopeId: surface.scopeId,
943
+ interactionKey: interaction.interactionKey,
944
+ intent: current.intent,
945
+ actuatorId: current.actuatorId
946
+ })
947
+ );
948
+ break;
949
+ }
950
+ visited.add(key);
951
+ current = actuators.get(
952
+ targetIdentityKey({
953
+ surface: surface.surface,
954
+ scopeId: surface.scopeId,
955
+ interactionKey: interaction.interactionKey,
956
+ target: current.prepares
957
+ })
958
+ );
959
+ }
960
+ }
961
+ return diagnostics;
962
+ }
963
+ function diagnosticsForEffectPreparationCycles(surface, interaction) {
964
+ const diagnostics = [];
965
+ const actuatorKeys = /* @__PURE__ */ new Map();
966
+ interaction.actuators.forEach((actuator, index) => {
967
+ actuatorKeys.set(actuator, `${actuator.actuatorId}\0${index}`);
968
+ });
969
+ for (const actuator of interaction.actuators) {
970
+ const visited = /* @__PURE__ */ new Set();
971
+ let current = actuator;
972
+ while (current) {
973
+ const key = actuatorKeys.get(current);
974
+ if (!key) break;
975
+ if (visited.has(key)) {
976
+ diagnostics.push(
977
+ diagnosticFor({
978
+ code: "preparation-cycle",
979
+ message: `Semantic preparation cycle detected for actuator '${current.actuatorId}'.`,
980
+ surface: surface.surface,
981
+ scopeId: surface.scopeId,
982
+ interactionKey: interaction.interactionKey,
983
+ intent: current.intent,
984
+ actuatorId: current.actuatorId
985
+ })
986
+ );
987
+ break;
988
+ }
989
+ visited.add(key);
990
+ current = interaction.actuators.find(
991
+ (candidate) => current?.preparationPatterns.some(
992
+ (pattern) => candidate.semanticEffects.some(
993
+ (effect) => browserInteractionEffectPatternMatches(pattern, effect)
994
+ )
995
+ )
996
+ );
997
+ }
998
+ }
999
+ return diagnostics;
1000
+ }
1001
+ function diagnosticsForPreparationPatternAmbiguity(surface, interaction) {
1002
+ const diagnostics = [];
1003
+ for (const target of interaction.actuators) {
1004
+ for (const effect of target.semanticEffects) {
1005
+ const matches = interaction.actuators.filter(
1006
+ (actuator) => actuator.preparationPatterns.some(
1007
+ (pattern) => browserInteractionEffectPatternMatches(pattern, effect)
1008
+ )
1009
+ );
1010
+ const uniqueActuatorIds = new Set(
1011
+ matches.map((match) => match.actuatorId)
1012
+ );
1013
+ if (uniqueActuatorIds.size > 1) {
1014
+ diagnostics.push(
1015
+ diagnosticFor({
1016
+ code: "ambiguous-preparation-pattern",
1017
+ message: "Multiple preparation patterns can prepare the same semantic effect.",
1018
+ surface: surface.surface,
1019
+ scopeId: surface.scopeId,
1020
+ interactionKey: interaction.interactionKey,
1021
+ intent: target.intent,
1022
+ actuatorId: target.actuatorId
1023
+ })
1024
+ );
1025
+ }
1026
+ }
1027
+ }
1028
+ return diagnostics;
1029
+ }
1030
+ function actuatorIdentityKey(input) {
1031
+ return createBrowserInteractionActuatorKey({
1032
+ surface: input.surface,
1033
+ scopeId: input.scopeId,
1034
+ interactionKey: input.interactionKey,
1035
+ intent: input.actuator.intent,
1036
+ inputKey: input.actuator.inputKey,
1037
+ candidateValueKey: input.actuator.candidateValueKey,
1038
+ actuatorKind: input.actuator.actuatorKind
1039
+ });
1040
+ }
1041
+ function isSemanticSurfaceSnapshot(surface) {
1042
+ return "interactions" in surface;
1043
+ }
1044
+ function targetIdentityKey(input) {
1045
+ return createBrowserInteractionActuatorKey({
1046
+ surface: input.surface,
1047
+ scopeId: input.scopeId,
1048
+ interactionKey: input.interactionKey,
1049
+ intent: input.target.intent,
1050
+ inputKey: input.target.inputKey,
1051
+ candidateValueKey: input.target.candidateValueKey,
1052
+ actuatorKind: input.target.actuatorKind ?? "click"
1053
+ });
1054
+ }
1055
+ function pushSurfaceDiagnostic(surface, all, diagnostic) {
1056
+ surface.diagnostics.push(diagnostic);
1057
+ all.push(diagnostic);
1058
+ }
1059
+ function diagnosticFor(input) {
1060
+ return { severity: "error", ...input };
1061
+ }
1062
+ function text(attributes, key) {
1063
+ const value = attributes[key];
1064
+ if (typeof value === "boolean") return value ? "true" : "false";
1065
+ return value ?? "";
1066
+ }
1067
+ function optionalText(attributes, key) {
1068
+ const value = text(attributes, key);
1069
+ return value === "" ? void 0 : value;
1070
+ }
1071
+ function parseReadiness(value) {
1072
+ return BROWSER_INTERACTION_READINESS_VALUES.includes(
1073
+ value
1074
+ ) ? value : "blocked";
1075
+ }
1076
+ function parseCandidateState(value) {
1077
+ return BROWSER_INTERACTION_CANDIDATE_STATES.includes(
1078
+ value
1079
+ ) ? value : void 0;
1080
+ }
1081
+ function parseActuatorKind(value) {
1082
+ return parseOptionalActuatorKind(value) ?? "click";
1083
+ }
1084
+ function parseOptionalActuatorKind(value) {
1085
+ return BROWSER_INTERACTION_ACTUATOR_KINDS.includes(
1086
+ value
1087
+ ) ? value : void 0;
1088
+ }
1089
+ function parseEnabled(value) {
1090
+ if (value === false || value === "false") return false;
1091
+ return true;
1092
+ }
1093
+ function compareSurface(a, b) {
1094
+ return a.surface.localeCompare(b.surface) || a.scopeId.localeCompare(b.scopeId);
1095
+ }
1096
+ function compareActuator(a, b) {
1097
+ return a.actuatorId.localeCompare(b.actuatorId);
1098
+ }
1099
+ function compareDiagnostic(a, b) {
1100
+ return a.code.localeCompare(b.code) || (a.surface ?? "").localeCompare(b.surface ?? "") || (a.scopeId ?? "").localeCompare(b.scopeId ?? "") || (a.interactionKey ?? "").localeCompare(b.interactionKey ?? "") || (a.intent ?? "").localeCompare(b.intent ?? "") || (a.actuatorId ?? "").localeCompare(b.actuatorId ?? "") || a.message.localeCompare(b.message);
1101
+ }
1102
+
1103
+ // src/browser-interaction/resolve.ts
1104
+ function resolveBrowserInteractionIntent(snapshot, request) {
1105
+ const snapshotDiagnostics = [
1106
+ ...snapshot.diagnostics,
1107
+ ...validateBrowserInteractionSnapshot(snapshot)
1108
+ ];
1109
+ if (snapshotDiagnostics.some((diagnostic) => diagnostic.severity === "error")) {
1110
+ return {
1111
+ ok: false,
1112
+ code: "invalid-snapshot",
1113
+ diagnostics: snapshotDiagnostics
1114
+ };
1115
+ }
1116
+ const candidateValueKey = request.candidateValueKey ?? ("candidateValue" in request ? encodeCanonicalCandidateValue(request.candidateValue) : void 0);
1117
+ const surfaces = snapshot.surfaces.filter(
1118
+ (surface) => isSemanticSurfaceSnapshot(surface) && surface.surface === request.surface && (request.scopeId === void 0 || surface.scopeId === request.scopeId)
1119
+ );
1120
+ const matches = surfaces.flatMap(
1121
+ (surface) => surface.interactions.flatMap((interaction) => {
1122
+ if (request.interactionKey !== void 0 && interaction.interactionKey !== request.interactionKey) {
1123
+ return [];
1124
+ }
1125
+ if (request.interactionId !== void 0 && interaction.interactionId !== request.interactionId) {
1126
+ return [];
1127
+ }
1128
+ return interaction.actuators.filter(
1129
+ (actuator) => actuatorMatchesRequest(actuator, request, candidateValueKey)
1130
+ ).map((actuator) => ({ surface, interaction, actuator }));
1131
+ })
1132
+ );
1133
+ const enabledMatches = matches.filter((match) => match.actuator.enabled);
1134
+ const actionable = request.allowDisabled === true ? matches : enabledMatches;
1135
+ if (actionable.length === 1) {
1136
+ const match = actionable[0];
1137
+ if (!match) throw new Error("unreachable browser interaction match");
1138
+ return {
1139
+ ok: true,
1140
+ actuator: match.actuator,
1141
+ surface: match.surface.surface,
1142
+ scopeId: match.surface.scopeId,
1143
+ interactionKey: match.interaction.interactionKey,
1144
+ diagnostics: []
1145
+ };
1146
+ }
1147
+ if (actionable.length > 1) {
1148
+ return {
1149
+ ok: false,
1150
+ code: "ambiguous",
1151
+ diagnostics: actionable.map(
1152
+ (match) => diagnosticFor2({
1153
+ code: "ambiguous-actuator",
1154
+ message: "Browser interaction intent resolved to multiple actuators.",
1155
+ surface: match.surface.surface,
1156
+ scopeId: match.surface.scopeId,
1157
+ interactionKey: match.interaction.interactionKey,
1158
+ intent: match.actuator.intent,
1159
+ actuatorId: match.actuator.actuatorId
1160
+ })
1161
+ )
1162
+ };
1163
+ }
1164
+ const preparation = findPreparationChain(
1165
+ surfaces,
1166
+ request,
1167
+ candidateValueKey
1168
+ );
1169
+ if (preparation.length > 0) {
1170
+ return {
1171
+ ok: false,
1172
+ code: "preparation-required",
1173
+ diagnostics: [
1174
+ diagnosticFor2({
1175
+ code: "unavailable-actuator",
1176
+ message: "Requested browser interaction intent requires preparation before its actuator is available.",
1177
+ surface: request.surface,
1178
+ scopeId: request.scopeId,
1179
+ interactionKey: request.interactionKey,
1180
+ intent: request.intent
1181
+ })
1182
+ ],
1183
+ preparation
1184
+ };
1185
+ }
1186
+ return {
1187
+ ok: false,
1188
+ code: matches.length > 0 ? "unavailable" : "not-found",
1189
+ diagnostics: [
1190
+ diagnosticFor2({
1191
+ code: "unavailable-actuator",
1192
+ message: matches.length > 0 ? "Browser interaction intent exists but has no enabled actuator." : "Browser interaction intent is not present in the current snapshot.",
1193
+ surface: request.surface,
1194
+ scopeId: request.scopeId,
1195
+ interactionKey: request.interactionKey,
1196
+ intent: request.intent
1197
+ })
1198
+ ]
1199
+ };
1200
+ }
1201
+ function resolveBrowserInteractionEffect(snapshot, request) {
1202
+ const snapshotDiagnostics = [
1203
+ ...snapshot.diagnostics,
1204
+ ...validateBrowserInteractionSnapshot(snapshot)
1205
+ ];
1206
+ if (snapshotDiagnostics.some((diagnostic) => diagnostic.severity === "error")) {
1207
+ return {
1208
+ ok: false,
1209
+ code: "invalid-snapshot",
1210
+ diagnostics: snapshotDiagnostics
1211
+ };
1212
+ }
1213
+ const effectDiagnostics = validateEffectRequest(request.effect, request);
1214
+ if (effectDiagnostics.length > 0) {
1215
+ return {
1216
+ ok: false,
1217
+ code: "invalid-effect",
1218
+ diagnostics: effectDiagnostics
1219
+ };
1220
+ }
1221
+ const surfaces = matchingSurfaces(snapshot, request);
1222
+ const matches = collectInteractionMatches(surfaces, request);
1223
+ const exactMatches = matches.filter(
1224
+ (match) => match.actuator.semanticEffects.some(
1225
+ (effect) => encodeBrowserInteractionEffect(effect) === encodeBrowserInteractionEffect(request.effect)
1226
+ )
1227
+ );
1228
+ const enabledExactMatches = exactMatches.filter(
1229
+ (match) => match.actuator.enabled
1230
+ );
1231
+ const actionableExactMatches = request.allowDisabled === true ? exactMatches : enabledExactMatches;
1232
+ if (actionableExactMatches.length === 1) {
1233
+ const match = actionableExactMatches[0];
1234
+ if (!match) throw new Error("unreachable browser effect match");
1235
+ return effectSuccess(match, request.effect, "exact");
1236
+ }
1237
+ if (actionableExactMatches.length > 1) {
1238
+ return effectAmbiguous(
1239
+ actionableExactMatches,
1240
+ "duplicate-enabled-effect-actuator",
1241
+ "Browser interaction effect resolved to multiple exact actuators."
1242
+ );
1243
+ }
1244
+ if (exactMatches.length > 0 && enabledExactMatches.length === 0) {
1245
+ return effectUnavailable(
1246
+ request,
1247
+ "disabled-effect-actuator",
1248
+ "Browser interaction effect exists but has no enabled actuator."
1249
+ );
1250
+ }
1251
+ const acceptedMatches = matches.filter(
1252
+ (match) => match.actuator.acceptedEffectPatterns.some(
1253
+ (pattern) => browserInteractionEffectPatternMatches(pattern, request.effect)
1254
+ )
1255
+ );
1256
+ const enabledAcceptedMatches = acceptedMatches.filter(
1257
+ (match) => match.actuator.enabled
1258
+ );
1259
+ const actionableAcceptedMatches = request.allowDisabled === true ? acceptedMatches : enabledAcceptedMatches;
1260
+ if (actionableAcceptedMatches.length === 1) {
1261
+ const match = actionableAcceptedMatches[0];
1262
+ if (!match) throw new Error("unreachable browser accepted effect match");
1263
+ return effectSuccess(match, request.effect, "accepted-pattern");
1264
+ }
1265
+ if (actionableAcceptedMatches.length > 1) {
1266
+ return effectAmbiguous(
1267
+ actionableAcceptedMatches,
1268
+ "duplicate-accepted-effect-pattern-match",
1269
+ "Browser interaction effect matched multiple accepted-effect patterns."
1270
+ );
1271
+ }
1272
+ if (acceptedMatches.length > 0 && enabledAcceptedMatches.length === 0) {
1273
+ return effectUnavailable(
1274
+ request,
1275
+ "disabled-effect-actuator",
1276
+ "Browser interaction effect pattern exists but has no enabled actuator."
1277
+ );
1278
+ }
1279
+ const preparation = findEffectPreparationChain(surfaces, request);
1280
+ if (preparation.ok) {
1281
+ return {
1282
+ ok: false,
1283
+ code: "preparation-required",
1284
+ diagnostics: [
1285
+ diagnosticFor2({
1286
+ code: "unavailable-actuator",
1287
+ message: "Requested browser interaction effect requires preparation before its actuator is available.",
1288
+ surface: request.surface,
1289
+ scopeId: request.scopeId,
1290
+ interactionKey: request.interactionKey
1291
+ })
1292
+ ],
1293
+ preparation: preparation.preparation
1294
+ };
1295
+ }
1296
+ if (preparation.diagnostics.length > 0) {
1297
+ return {
1298
+ ok: false,
1299
+ code: "ambiguous",
1300
+ diagnostics: preparation.diagnostics
1301
+ };
1302
+ }
1303
+ return {
1304
+ ok: false,
1305
+ code: "not-found",
1306
+ diagnostics: [
1307
+ diagnosticFor2({
1308
+ code: "missing-effect",
1309
+ message: "Browser interaction effect is not present in the current snapshot.",
1310
+ surface: request.surface,
1311
+ scopeId: request.scopeId,
1312
+ interactionKey: request.interactionKey
1313
+ })
1314
+ ]
1315
+ };
1316
+ }
1317
+ function actuatorMatchesRequest(actuator, request, candidateValueKey) {
1318
+ return actuator.intent === request.intent && (request.inputKey === void 0 || actuator.inputKey === request.inputKey) && (candidateValueKey === void 0 || actuator.candidateValueKey === candidateValueKey) && (request.actuatorKind === void 0 || actuator.actuatorKind === request.actuatorKind);
1319
+ }
1320
+ function findPreparationChain(surfaces, request, candidateValueKey) {
1321
+ const targetRequest = {
1322
+ ...request,
1323
+ candidateValueKey
1324
+ };
1325
+ const preparationMatches = surfaces.flatMap(
1326
+ (surface) => surface.interactions.flatMap((interaction) => {
1327
+ if (!interactionMatchesRequest(interaction, request)) return [];
1328
+ return interaction.actuators.filter(
1329
+ (actuator) => actuator.enabled && actuator.prepares && actuator.prepares.intent === targetRequest.intent && (targetRequest.inputKey === void 0 || actuator.prepares.inputKey === targetRequest.inputKey) && (targetRequest.candidateValueKey === void 0 || actuator.prepares.candidateValueKey === targetRequest.candidateValueKey) && (targetRequest.actuatorKind === void 0 || actuator.prepares.actuatorKind === targetRequest.actuatorKind)
1330
+ ).map((actuator) => ({ surface, interaction, actuator }));
1331
+ })
1332
+ );
1333
+ if (preparationMatches.length !== 1) return [];
1334
+ const match = preparationMatches[0];
1335
+ if (!match) return [];
1336
+ return expandPreparationChain(
1337
+ match.surface,
1338
+ match.interaction,
1339
+ match.actuator
1340
+ );
1341
+ }
1342
+ function expandPreparationChain(surface, interaction, actuator) {
1343
+ const byKey = /* @__PURE__ */ new Map();
1344
+ for (const candidate of interaction.actuators) {
1345
+ byKey.set(
1346
+ actuatorIdentityKey({
1347
+ surface: surface.surface,
1348
+ scopeId: surface.scopeId,
1349
+ interactionKey: interaction.interactionKey,
1350
+ actuator: candidate
1351
+ }),
1352
+ candidate
1353
+ );
1354
+ }
1355
+ const chain = [];
1356
+ const visited = /* @__PURE__ */ new Set();
1357
+ let current = actuator;
1358
+ while (current) {
1359
+ const key = actuatorIdentityKey({
1360
+ surface: surface.surface,
1361
+ scopeId: surface.scopeId,
1362
+ interactionKey: interaction.interactionKey,
1363
+ actuator: current
1364
+ });
1365
+ if (visited.has(key)) return [];
1366
+ visited.add(key);
1367
+ chain.push(current);
1368
+ current = current.prepares ? byKey.get(
1369
+ targetIdentityKey({
1370
+ surface: surface.surface,
1371
+ scopeId: surface.scopeId,
1372
+ interactionKey: interaction.interactionKey,
1373
+ target: current.prepares
1374
+ })
1375
+ ) : void 0;
1376
+ }
1377
+ return chain;
1378
+ }
1379
+ function interactionMatchesRequest(interaction, request) {
1380
+ return (request.interactionKey === void 0 || interaction.interactionKey === request.interactionKey) && (request.interactionId === void 0 || interaction.interactionId === request.interactionId);
1381
+ }
1382
+ function matchingSurfaces(snapshot, request) {
1383
+ return snapshot.surfaces.filter(
1384
+ (surface) => isSemanticSurfaceSnapshot(surface) && surface.surface === request.surface && (request.scopeId === void 0 || surface.scopeId === request.scopeId)
1385
+ );
1386
+ }
1387
+ function collectInteractionMatches(surfaces, request) {
1388
+ return surfaces.flatMap(
1389
+ (surface) => surface.interactions.flatMap((interaction) => {
1390
+ if (request.interactionKey !== void 0 && interaction.interactionKey !== request.interactionKey) {
1391
+ return [];
1392
+ }
1393
+ if (request.interactionId !== void 0 && interaction.interactionId !== request.interactionId) {
1394
+ return [];
1395
+ }
1396
+ return interaction.actuators.map((actuator) => ({
1397
+ surface,
1398
+ interaction,
1399
+ actuator
1400
+ }));
1401
+ })
1402
+ );
1403
+ }
1404
+ function effectSuccess(match, effect, kind) {
1405
+ return {
1406
+ ok: true,
1407
+ actuator: match.actuator,
1408
+ surface: match.surface.surface,
1409
+ scopeId: match.surface.scopeId,
1410
+ interactionKey: match.interaction.interactionKey,
1411
+ match: kind,
1412
+ effect,
1413
+ diagnostics: []
1414
+ };
1415
+ }
1416
+ function effectAmbiguous(matches, code, message) {
1417
+ return {
1418
+ ok: false,
1419
+ code: "ambiguous",
1420
+ diagnostics: matches.map(
1421
+ (match) => diagnosticFor2({
1422
+ code,
1423
+ message,
1424
+ surface: match.surface.surface,
1425
+ scopeId: match.surface.scopeId,
1426
+ interactionKey: match.interaction.interactionKey,
1427
+ intent: match.actuator.intent,
1428
+ actuatorId: match.actuator.actuatorId
1429
+ })
1430
+ )
1431
+ };
1432
+ }
1433
+ function effectUnavailable(request, code, message) {
1434
+ return {
1435
+ ok: false,
1436
+ code: "unavailable",
1437
+ diagnostics: [
1438
+ diagnosticFor2({
1439
+ code,
1440
+ message,
1441
+ surface: request.surface,
1442
+ scopeId: request.scopeId,
1443
+ interactionKey: request.interactionKey
1444
+ })
1445
+ ]
1446
+ };
1447
+ }
1448
+ function findEffectPreparationChain(surfaces, request) {
1449
+ const matches = collectInteractionMatches(surfaces, request).filter(
1450
+ (match) => match.actuator.preparationPatterns.some(
1451
+ (pattern) => browserInteractionEffectPatternMatches(pattern, request.effect)
1452
+ )
1453
+ );
1454
+ const enabledMatches = matches.filter((match) => match.actuator.enabled);
1455
+ if (enabledMatches.length === 1) {
1456
+ const match = enabledMatches[0];
1457
+ if (!match) return { ok: false, diagnostics: [] };
1458
+ return { ok: true, preparation: [match.actuator] };
1459
+ }
1460
+ if (enabledMatches.length > 1) {
1461
+ return {
1462
+ ok: false,
1463
+ diagnostics: enabledMatches.map(
1464
+ (match) => diagnosticFor2({
1465
+ code: "ambiguous-preparation-pattern",
1466
+ message: "Browser interaction effect resolved to multiple preparation actuators.",
1467
+ surface: match.surface.surface,
1468
+ scopeId: match.surface.scopeId,
1469
+ interactionKey: match.interaction.interactionKey,
1470
+ intent: match.actuator.intent,
1471
+ actuatorId: match.actuator.actuatorId
1472
+ })
1473
+ )
1474
+ };
1475
+ }
1476
+ return { ok: false, diagnostics: [] };
1477
+ }
1478
+ function validateEffectRequest(effect, request) {
1479
+ if (!effect || typeof effect.kind !== "string" || effect.kind.length === 0) {
1480
+ return [
1481
+ diagnosticFor2({
1482
+ code: "invalid-effect-payload",
1483
+ message: "Browser interaction effect requires a string kind.",
1484
+ surface: request.surface,
1485
+ scopeId: request.scopeId,
1486
+ interactionKey: request.interactionKey
1487
+ })
1488
+ ];
1489
+ }
1490
+ if (effect.kind === "setScalar") {
1491
+ const value = effect.value;
1492
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1493
+ return [
1494
+ diagnosticFor2({
1495
+ code: "invalid-scalar-argument",
1496
+ message: "setScalar browser interaction effects require a finite value.",
1497
+ surface: request.surface,
1498
+ scopeId: request.scopeId,
1499
+ interactionKey: request.interactionKey
1500
+ })
1501
+ ];
1502
+ }
1503
+ }
1504
+ return [];
1505
+ }
1506
+ function diagnosticFor2(input) {
1507
+ return { severity: "error", ...input };
1508
+ }
1509
+
1510
+ // src/browser-interaction/schemas.ts
1511
+ import { z } from "zod";
1512
+ var jsonValueSchema = z.lazy(
1513
+ () => z.union([
1514
+ z.null(),
1515
+ z.boolean(),
1516
+ z.number().finite(),
1517
+ z.string(),
1518
+ z.array(jsonValueSchema),
1519
+ z.record(z.string(), jsonValueSchema)
1520
+ ])
1521
+ );
1522
+ var browserInteractionEffectSchema = z.object({
1523
+ kind: z.string().min(1)
1524
+ }).catchall(jsonValueSchema);
1525
+ var browserInteractionEffectPatternSchema = z.union([
1526
+ z.object({
1527
+ kind: z.literal("exact"),
1528
+ effect: browserInteractionEffectSchema
1529
+ }),
1530
+ z.object({
1531
+ kind: z.literal("match"),
1532
+ effectKind: z.string().min(1),
1533
+ fields: z.record(z.string(), jsonValueSchema).optional(),
1534
+ scalar: z.object({
1535
+ field: z.string().min(1),
1536
+ min: z.number().finite().optional(),
1537
+ max: z.number().finite().optional(),
1538
+ integer: z.boolean().optional()
1539
+ }).optional()
1540
+ })
1541
+ ]);
1542
+ var gameplaySemanticEffectSchema = z.union([
1543
+ z.object({
1544
+ kind: z.literal("setCandidate"),
1545
+ inputKey: z.string(),
1546
+ candidateValue: jsonValueSchema,
1547
+ beforeSelected: z.boolean(),
1548
+ afterSelected: z.boolean()
1549
+ }),
1550
+ z.object({
1551
+ kind: z.literal("adjustResource"),
1552
+ inputKey: z.string(),
1553
+ resourceKey: jsonValueSchema,
1554
+ delta: z.union([z.literal(-1), z.literal(1)])
1555
+ }),
1556
+ z.object({
1557
+ kind: z.literal("setScalar"),
1558
+ inputKey: z.string(),
1559
+ value: z.number().finite()
1560
+ }),
1561
+ z.object({
1562
+ kind: z.literal("commit")
1563
+ }),
1564
+ z.object({
1565
+ kind: z.literal("invoke")
1566
+ })
1567
+ ]);
1568
+ var browserInteractionDiagnosticSchema = z.object({
1569
+ code: z.string(),
1570
+ severity: z.enum(["error", "warning"]),
1571
+ message: z.string(),
1572
+ surface: z.string().optional(),
1573
+ scopeId: z.string().optional(),
1574
+ interactionKey: z.string().optional(),
1575
+ intent: z.string().optional(),
1576
+ actuatorId: z.string().optional()
1577
+ });
1578
+ var browserInteractionActuatorSchema = z.object({
1579
+ actuatorId: z.string(),
1580
+ intent: z.string(),
1581
+ inputKey: z.string().optional(),
1582
+ candidateValue: jsonValueSchema.optional(),
1583
+ candidateValueKey: z.string().optional(),
1584
+ candidateState: z.enum(BROWSER_INTERACTION_CANDIDATE_STATES).optional(),
1585
+ enabled: z.boolean(),
1586
+ actuatorKind: z.enum(BROWSER_INTERACTION_ACTUATOR_KINDS),
1587
+ semanticEffects: z.array(browserInteractionEffectSchema),
1588
+ acceptedEffectPatterns: z.array(browserInteractionEffectPatternSchema),
1589
+ preparationPatterns: z.array(browserInteractionEffectPatternSchema),
1590
+ prepares: z.object({
1591
+ intent: z.string(),
1592
+ inputKey: z.string().optional(),
1593
+ candidateValue: jsonValueSchema.optional(),
1594
+ candidateValueKey: z.string().optional(),
1595
+ actuatorKind: z.enum(BROWSER_INTERACTION_ACTUATOR_KINDS).optional()
1596
+ }).optional(),
1597
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1598
+ });
1599
+ var browserGameplayInteractionSchema = z.object({
1600
+ interactionKey: z.string(),
1601
+ interactionId: z.string(),
1602
+ descriptorDigest: z.string().optional(),
1603
+ draftDigest: z.string().optional(),
1604
+ readiness: z.enum(BROWSER_INTERACTION_READINESS_VALUES),
1605
+ actuators: z.array(browserInteractionActuatorSchema),
1606
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1607
+ });
1608
+ var browserGameplaySurfaceSnapshotSchema = z.object({
1609
+ surface: z.literal(GAMEPLAY_BROWSER_INTERACTION_SURFACE),
1610
+ scopeId: z.string(),
1611
+ interactions: z.array(browserGameplayInteractionSchema),
1612
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1613
+ });
1614
+ var browserSemanticSurfaceSnapshotSchema = z.object({
1615
+ surface: z.string(),
1616
+ scopeId: z.string(),
1617
+ interactions: z.array(browserGameplayInteractionSchema),
1618
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1619
+ });
1620
+ var browserUnknownSurfaceSnapshotSchema = z.object({
1621
+ surface: z.string(),
1622
+ scopeId: z.string(),
1623
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1624
+ });
1625
+ var browserInteractionSnapshotSchema = z.object({
1626
+ protocol: z.object({
1627
+ name: z.literal(DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME),
1628
+ version: z.literal(DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION)
1629
+ }),
1630
+ surfaces: z.array(
1631
+ z.union([
1632
+ browserSemanticSurfaceSnapshotSchema,
1633
+ browserUnknownSurfaceSnapshotSchema
1634
+ ])
1635
+ ),
1636
+ diagnostics: z.array(browserInteractionDiagnosticSchema)
1637
+ });
1638
+
1639
+ export {
1640
+ DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_NAME,
1641
+ DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
1642
+ BROWSER_INTERACTION_ATTRIBUTES,
1643
+ BROWSER_INTERACTION_RECORD_ROLES,
1644
+ GAMEPLAY_BROWSER_INTERACTION_SURFACE,
1645
+ GAMEPLAY_BROWSER_INTERACTION_INTENTS,
1646
+ GAMEPLAY_BROWSER_INTERACTION_EFFECT_KINDS,
1647
+ BROWSER_INTERACTION_READINESS_VALUES,
1648
+ BROWSER_INTERACTION_CANDIDATE_STATES,
1649
+ BROWSER_INTERACTION_ACTUATOR_KINDS,
1650
+ encodeCanonicalCandidateValue,
1651
+ decodeCanonicalCandidateValue,
1652
+ compareStableJson,
1653
+ encodeBrowserInteractionEffect,
1654
+ decodeBrowserInteractionEffect,
1655
+ encodeBrowserInteractionEffectPattern,
1656
+ decodeBrowserInteractionEffectPattern,
1657
+ browserInteractionEffectPatternMatches,
1658
+ assertBrowserInteractionEffectPattern,
1659
+ gameplaySetCandidateEffect,
1660
+ gameplayAdjustResourceEffect,
1661
+ gameplaySetScalarEffect,
1662
+ gameplayCommitEffect,
1663
+ gameplayInvokeEffect,
1664
+ createBrowserInteractionRootAttributes,
1665
+ createBrowserInteractionActuatorAttributes,
1666
+ createGameplayInteractionRootAttributes,
1667
+ createGameplayActuatorAttributes,
1668
+ createBrowserInteractionActuatorKey,
1669
+ defineBrowserInteractionSurface,
1670
+ gameplayBrowserInteractionSurface,
1671
+ createBrowserInteractionRegistry,
1672
+ defaultBrowserInteractionRegistry,
1673
+ normalizeBrowserInteractionRecords,
1674
+ validateBrowserInteractionSnapshot,
1675
+ actuatorIdentityKey,
1676
+ isSemanticSurfaceSnapshot,
1677
+ targetIdentityKey,
1678
+ resolveBrowserInteractionIntent,
1679
+ resolveBrowserInteractionEffect,
1680
+ browserInteractionEffectSchema,
1681
+ browserInteractionEffectPatternSchema,
1682
+ gameplaySemanticEffectSchema,
1683
+ browserInteractionDiagnosticSchema,
1684
+ browserInteractionActuatorSchema,
1685
+ browserGameplayInteractionSchema,
1686
+ browserGameplaySurfaceSnapshotSchema,
1687
+ browserSemanticSurfaceSnapshotSchema,
1688
+ browserUnknownSurfaceSnapshotSchema,
1689
+ browserInteractionSnapshotSchema
1690
+ };
1691
+ //# sourceMappingURL=chunk-QLG6VEMW.js.map