@dreamboard-games/sdk 0.5.0-alpha.11 → 0.5.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -349,13 +349,80 @@ install the React adapter. The `/react` entry delegates selectors to that packag
349
349
  the application bundler resolves its supported React subscription dependencies.
350
350
 
351
351
  `/react` classifies each card press as a tap, hold, drag or browse. Enable
352
- `dragFeature`, export `useCardGesture`, `useDropArea` and `useDragOverlay` from the
352
+ `dragFeature`, export `useCardGesture`, `useActiveCard`, `useDropArea` and `useDragOverlay` from the
353
353
  binding, and use the copied Hand and BoardTargets components or your own renderer.
354
354
  The SDK prescribes no layout. Headless `game.drag` remains browser-free and handles
355
355
  atomic domain routing. `fanLayout` computes arc positions for a hand, and
356
356
  `originsFeature` adds `card.getOrigin()` so a newly shown card can animate from
357
357
  the zone or player it came from.
358
358
 
359
+ ## Opt-in game shortcuts
360
+
361
+ Install `shortcutsFeature` in the same `createGameHook<Definition>()` binding as
362
+ other features, and export its inferred `useGameShortcuts` and
363
+ `useShortcutTarget` and `useShortcutHints` hooks. A child inside the bound `GameProvider` installs the
364
+ app's bindings once:
365
+
366
+ ```tsx
367
+ function AppShortcuts() {
368
+ useGameShortcuts({
369
+ bindings: [
370
+ {
371
+ keys: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
372
+ label: "Draw cards",
373
+ target: "zone",
374
+ zoneId: "deck",
375
+ interaction: "play.draw",
376
+ inputs: ({ key }) => ({ count: Number(key) }),
377
+ },
378
+ {
379
+ keys: ["f"],
380
+ label: "Flip card",
381
+ target: "card",
382
+ input: "card",
383
+ interaction: "play.flip",
384
+ inputs: ({ target }) => ({ card: target.value }),
385
+ },
386
+ ],
387
+ });
388
+ return null;
389
+ }
390
+ ```
391
+
392
+ These interaction and input names are examples from an authored reducer. The
393
+ binding's discriminated types derive from that reducer: interaction names,
394
+ input keys, target kinds, and every required payload field must match. A game
395
+ that exposes a counted draw submits one `count` payload; shortcuts never repeat
396
+ a draw-one action. No actions or keys are supplied by default.
397
+
398
+ Card controls using `useCardGesture` share its canonical pointer and keyboard
399
+ focus. Zone controls spread
400
+ `useShortcutTarget({ kind: "zone", zoneId: "deck", hostId: "table" }).props`;
401
+ `hostId` must be the actual host allowed by that zone's attachment. Selectable
402
+ board and tile controls can use the same hook with their canonical
403
+ `SelectionTarget`. Hidden cards retain their opaque seat references.
404
+
405
+ Keys are exact browser `event.key` strings. The adapter ignores held repeats,
406
+ composition, editing controls, modifier combinations, and open modal or menu
407
+ surfaces. It prevents the browser default only when a single eligible binding
408
+ handles the key. Source and seat changes clear the gesture target; unmounting
409
+ removes the listener and binding hints.
410
+
411
+ Input factories must be pure: eligibility and hints evaluate them against the
412
+ current projected domains. `game.shortcuts.getHints(target)` returns only
413
+ currently usable, unambiguous keys with their labels and typed interaction
414
+ names, for menus or help. `useShortcutHints(target)` reads those hints reactively
415
+ and returns no hints when the feature is absent. The mounted
416
+ `useGameShortcuts` hook returns `{ target, hints }` for a reserved help/status
417
+ area. Rejected actions and transport failures use the binding's existing
418
+ `onError` handler; callbacks from an old source, seat, or unmounted child are
419
+ ignored. `game.shortcuts.handle(key, target)` uses the same
420
+ atomic `interaction.submit(params)` path available to authored action buttons.
421
+ Explicit params are validated against the current projected descriptor without
422
+ mutating drafts. Existing `submit()` continues to submit the interaction draft
423
+ and defaults; both forms share availability and in-flight lifecycle barriers.
424
+ The headless feature installs no DOM listeners.
425
+
359
426
  ## Local development and tests
360
427
 
361
428
  `localSource(game, { players, seed, as, options })` executes the production reducer
@@ -324,8 +324,9 @@ var InteractionObject = class {
324
324
  getAvailability() {
325
325
  return this.descriptor.availability;
326
326
  }
327
- getIsAvailable() {
328
- return this.descriptor.availability.status === "available";
327
+ getIsAvailable(params) {
328
+ const descriptor = params === void 0 ? this.descriptor : this.owner.descriptorFor(this.descriptor, params);
329
+ return descriptor.availability.status === "available";
329
330
  }
330
331
  getUnavailableReason() {
331
332
  return this.descriptor.availability.status === "available" ? null : this.descriptor.availability.reason;
@@ -349,11 +350,14 @@ var InteractionObject = class {
349
350
  getInputs() {
350
351
  return this.inputObjects;
351
352
  }
352
- readiness() {
353
- return getInteractionDraftReadiness(this.descriptor, this.draft);
353
+ readiness(params = this.draft) {
354
+ return getInteractionDraftReadiness(
355
+ this.owner.descriptorFor(this.descriptor, params),
356
+ params
357
+ );
354
358
  }
355
- getIsReady() {
356
- return this.readiness().ready;
359
+ getIsReady(params) {
360
+ return this.readiness(params).ready;
357
361
  }
358
362
  getMissingInputs() {
359
363
  return this.readiness().missingInputs;
@@ -364,8 +368,8 @@ var InteractionObject = class {
364
368
  currentLifetime() {
365
369
  return this.source === this.owner.options.source && this.epoch === this.owner.epoch && !this.owner.disposed;
366
370
  }
367
- submit() {
368
- return this.currentLifetime() ? this.owner.submit(this.key, false) : Promise.resolve({ accepted: false, errorCode: "CLOSED" });
371
+ submit(params) {
372
+ return this.currentLifetime() ? this.owner.submit(this.key, false, params) : Promise.resolve({ accepted: false, errorCode: "CLOSED" });
369
373
  }
370
374
  cancel() {
371
375
  return this.currentLifetime() ? this.owner.submit(this.key, true) : Promise.resolve({ accepted: false, errorCode: "CLOSED" });
@@ -1129,13 +1133,13 @@ var Controller = class {
1129
1133
  }
1130
1134
  );
1131
1135
  }
1132
- async submit(key, cancel) {
1136
+ async submit(key, cancel, params) {
1133
1137
  const source = this.options.source;
1134
1138
  const interaction = this.current(key);
1135
1139
  if (this.disposed || this.sourceState.connection !== "ready" || this.sourceState.request || this.pending)
1136
1140
  return { accepted: false, errorCode: "BUSY" };
1137
1141
  if (!interaction) return { accepted: false, errorCode: "UNAVAILABLE" };
1138
- if (cancel ? !interaction.getStep()?.canCancel : !interaction.getIsAvailable() || !interaction.getIsReady())
1142
+ if (cancel ? !interaction.getStep()?.canCancel : !interaction.getIsAvailable(params) || !interaction.getIsReady(params))
1139
1143
  return { accepted: false, errorCode: "UNAVAILABLE" };
1140
1144
  if (!("submit" in source) || !("cancel" in source))
1141
1145
  return { accepted: false, errorCode: "READ_ONLY" };
@@ -1143,8 +1147,7 @@ var Controller = class {
1143
1147
  const operation = {
1144
1148
  source,
1145
1149
  key,
1146
- draft: this.drafts()[key] ?? EMPTY,
1147
- revision: this.revisions.get(key) ?? 0,
1150
+ draftRevision: params === void 0 ? this.revisions.get(key) ?? 0 : void 0,
1148
1151
  version: this.sourceState.snapshot.version,
1149
1152
  epoch: this.epoch,
1150
1153
  accepted: false,
@@ -1154,7 +1157,7 @@ var Controller = class {
1154
1157
  try {
1155
1158
  const result = await (cancel ? commandSource.cancel(interaction.id) : commandSource.submit(
1156
1159
  interaction.id,
1157
- interaction.readiness().values
1160
+ interaction.readiness(params).values
1158
1161
  ));
1159
1162
  if (this.pending !== operation) return result;
1160
1163
  if (!result.accepted) {
@@ -1185,7 +1188,7 @@ var Controller = class {
1185
1188
  if (this.sourceState.connection !== "ready" || (this.sourceState.snapshot?.version ?? -1) <= operation.version)
1186
1189
  return;
1187
1190
  this.pending = null;
1188
- if ((this.revisions.get(operation.key) ?? 0) === operation.revision)
1191
+ if (operation.draftRevision !== void 0 && (this.revisions.get(operation.key) ?? 0) === operation.draftRevision)
1189
1192
  this.reset(operation.key);
1190
1193
  else this.refresh();
1191
1194
  }
@@ -1708,4 +1711,4 @@ export {
1708
1711
  createGestureRecognizer,
1709
1712
  magneticDropPoint
1710
1713
  };
1711
- //# sourceMappingURL=chunk-2IGXAYW4.js.map
1714
+ //# sourceMappingURL=chunk-W5G6VMMQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/headless/runtime-features.ts","../src/headless/input-control.ts","../src/headless/instance.ts","../src/headless/interaction-inputs.ts","../src/headless/interaction-router.ts","../src/headless/gesture.ts","../src/headless/drop-targets.ts"],"sourcesContent":["import type { SeatBoardTopology } from \"../shared/seat-topology-schema.js\";\nimport type { ActionProps } from \"./model.js\";\nimport type { InputDomain } from \"../shared/protocol/frame.js\";\nimport type { RuntimeJson } from \"../shared/runtime-json.js\";\nimport type {\n GameSource,\n SourceSnapshot,\n SourceState,\n SubmitResult,\n} from \"./sources/types.js\";\nimport type {\n RuntimeSelectionTarget,\n RuntimeDropTarget,\n RuntimeTargetOptions,\n} from \"./targets.js\";\n\n/** Internal operations over admitted projections; never a game facade widened to unknown. */\nexport const runtimeFeatures = Symbol(\"runtimeFeatures\");\nexport interface RuntimeInput {\n readonly key: string;\n readonly kind: import(\"./model.js\").InteractionInputDescriptor[\"kind\"];\n getDomain(): InputDomain;\n getIsEligible(value: RuntimeJson): boolean;\n getIsSelected(value: RuntimeJson): boolean;\n getTargetProps(value: RuntimeJson): ActionProps;\n}\nexport interface RuntimeInteraction {\n readonly key: string;\n getIsAvailable(params?: Readonly<Record<string, RuntimeJson>>): boolean;\n getIsReady(params?: Readonly<Record<string, RuntimeJson>>): boolean;\n getStatus(): \"open\" | \"submitting\" | \"submitted\";\n submit(params?: Readonly<Record<string, RuntimeJson>>): Promise<SubmitResult>;\n getInputs(): readonly RuntimeInput[];\n}\nexport interface RuntimeFeatureSnapshot {\n readonly view: unknown;\n readonly snapshot: SourceSnapshot | null;\n readonly connection: SourceState[\"connection\"];\n readonly request: SourceState[\"request\"];\n readonly interactions: { list(): readonly RuntimeInteraction[] };\n readonly zones: {\n find(id: string, hostId: string): { readonly count: number } | undefined;\n };\n readonly cards: {\n find(\n id: string,\n ): { getInteractions(): readonly RuntimeInteraction[] } | undefined;\n };\n}\nexport interface RuntimeFeatureGame extends RuntimeFeatureSnapshot {\n getSnapshot(): RuntimeFeatureSnapshot;\n getOptions(): { readonly source: GameSource };\n subscribe(listener: () => void): () => void;\n}\nexport interface RuntimeBoard {\n readonly id: string;\n readonly data: SeatBoardTopology;\n readonly game: RuntimeFeatureGame;\n}\nexport interface RuntimeCollection<Value> {\n get(id: string): Value;\n find(id: string): Value | undefined;\n getAll(): readonly Value[];\n}\nexport interface RuntimeFeatureContext {\n readonly game: RuntimeFeatureGame;\n getBoards(): Readonly<Record<string, SeatBoardTopology>>;\n createBoard(data: SeatBoardTopology): RuntimeBoard;\n routeTarget(\n target: RuntimeSelectionTarget,\n options?: RuntimeTargetOptions,\n ): void;\n routeCardDrop(cardId: string, target: RuntimeDropTarget): void;\n invalidate(): void;\n}\n","import type { ActionProps } from \"./model.js\";\nimport type { InputDomain } from \"../shared/protocol/frame.js\";\nimport type { RuntimeJson } from \"../shared/runtime-json.js\";\n\ntype Domain<Type extends InputDomain[\"type\"]> = Extract<\n InputDomain,\n { type: Type }\n>;\ntype Editable<Value> = {\n readonly value: Value;\n readonly setValue: (value: Value) => void;\n};\ntype Control<Type extends \"boundedNumber\" | \"resourceMap\", Value> = {\n readonly type: Type;\n readonly domain: Domain<Type>;\n} & (\n | ({ readonly mode: \"single\" } & Editable<Value | undefined>)\n | ({ readonly mode: \"many\" } & Editable<Value[]>)\n);\nexport interface InputTargetOption<Value = RuntimeJson> {\n readonly value: Value;\n readonly label: string;\n readonly selected: boolean;\n readonly props: ActionProps;\n}\n/** A captured, descriptor-driven editor. Its handlers retain the input's lifetime. */\nexport type InputControl = {\n readonly key: string;\n readonly disabled: boolean;\n readonly props: {\n readonly disabled: boolean;\n readonly [key: `data-${string}`]: string | number | boolean | undefined;\n };\n} & (\n | Control<\"boundedNumber\", number>\n | Control<\"resourceMap\", Record<string, number>>\n | { readonly type: \"targets\"; readonly options: readonly InputTargetOption[] }\n);\n\ninterface ControlInput {\n readonly key: string;\n getDomain(): InputDomain;\n getValue(): RuntimeJson | undefined;\n setValue(value: RuntimeJson): void;\n clear(): void;\n getTargetOptions(): readonly InputTargetOption[];\n}\n/** Drafts can contain incomplete edits, so normalize only the displayed field values. */\nfunction resourceValue(\n domain: Domain<\"resourceMap\">,\n value: RuntimeJson | undefined,\n): Record<string, number> {\n const record =\n value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value\n : {};\n return Object.fromEntries(\n domain.resources.map((resource) => {\n const amount = record[resource.resourceId];\n return [resource.resourceId, typeof amount === \"number\" ? amount : 0];\n }),\n );\n}\nexport function createInputControl(\n input: ControlInput,\n props: InputControl[\"props\"],\n): InputControl {\n const domain = input.getDomain();\n const current = input.getValue();\n const common = { key: input.key, disabled: props.disabled, props };\n if (domain.type === \"boundedNumber\") {\n if (domain.selection?.mode === \"many\")\n return {\n ...common,\n type: \"boundedNumber\",\n domain,\n mode: \"many\",\n value: Array.isArray(current)\n ? current.filter(\n (value): value is number => typeof value === \"number\",\n )\n : [],\n setValue: (value) => input.setValue(value),\n };\n return {\n ...common,\n type: \"boundedNumber\",\n domain,\n mode: \"single\",\n value: typeof current === \"number\" ? current : undefined,\n setValue: (value) =>\n value === undefined ? input.clear() : input.setValue(value),\n };\n }\n if (domain.type === \"resourceMap\") {\n if (domain.selection?.mode === \"many\")\n return {\n ...common,\n type: \"resourceMap\",\n domain,\n mode: \"many\",\n value: Array.isArray(current)\n ? current.map((value) => resourceValue(domain, value))\n : [],\n setValue: (value) => input.setValue(value),\n };\n return {\n ...common,\n type: \"resourceMap\",\n domain,\n mode: \"single\",\n value: current === undefined ? undefined : resourceValue(domain, current),\n setValue: (value) =>\n value === undefined ? input.clear() : input.setValue(value),\n };\n }\n return { ...common, type: \"targets\", options: input.getTargetOptions() };\n}\n","import { BoardProjectionSchema } from \"../shared/seat-topology-schema.js\";\nimport type { ProjectedTile } from \"../shared/seat-topology-schema.js\";\nimport type { SeatTileRef } from \"../shared/domain/seat-reference.js\";\nimport type { SeatBoardTopology } from \"../shared/seat-topology-schema.js\";\nimport type { ViewCard } from \"../shared/domain/cards.js\";\nimport {\n runtimeFeatures,\n type RuntimeFeatureContext,\n type RuntimeCollection,\n} from \"./runtime-features.js\";\nimport type { ReadonlyData } from \"./model.js\";\nimport { createInputControl } from \"./input-control.js\";\nimport { requireLookup } from \"../shared/lookup.js\";\nimport type {\n RuntimeBoardTarget,\n RuntimeSelectionTarget,\n RuntimeTargetOptions,\n RuntimeDropTarget,\n} from \"./targets.js\";\nimport { immutableCopy } from \"../shared/immutable.js\";\nimport { createStore } from \"@tanstack/store\";\nimport {\n inputTargetInDomain,\n inputValueKey,\n inputValueInDomain,\n} from \"../shared/input-domain.js\";\nimport {\n getInteractionDraftReadiness,\n routeInteractionTarget,\n routeCardInputIntent,\n shouldAutoSubmitInteraction,\n} from \"./interaction-router.js\";\nimport {\n inputSelection,\n isManyInput,\n isManyTargetSelectable,\n} from \"./interaction-inputs.js\";\nimport type { RuntimeJson } from \"../shared/runtime-json.js\";\nimport type {\n Features,\n FeatureContext,\n GameInstance,\n CoreInstance,\n InstanceOptions,\n GameSource,\n SourceState,\n SourceSnapshot,\n SubmitResult,\n InteractionDescriptor,\n InteractionInputDescriptor,\n NativeEvent,\n} from \"./model.js\";\n\ntype Values = Readonly<Record<string, RuntimeJson>>;\ntype DraftMap = Readonly<Record<string, Values | undefined>>;\ntype RuntimeLocalState = { drafts: DraftMap; activeInteraction: string | null };\n/** Concrete controller options; game-specific keys are bound by createGameInstance. */\ntype RuntimeOptions = {\n readonly source: GameSource;\n readonly initialState?: Partial<RuntimeLocalState>;\n readonly state?: Partial<RuntimeLocalState>;\n readonly onDraftsChange?: (drafts: DraftMap) => void;\n readonly onActiveInteractionChange?: (key: string | null) => void;\n readonly onError?: (error: unknown) => void;\n readonly debug?: boolean;\n};\nconst EMPTY: Values = Object.freeze({});\nconst EMPTY_DRAFTS: DraftMap = Object.freeze({});\nconst equalValue = (a: unknown, b: unknown) =>\n Object.is(a, b) ||\n (typeof a === \"object\" &&\n typeof b === \"object\" &&\n inputValueKey(a) === inputValueKey(b));\nfunction inDomain(\n input: InteractionInputDescriptor,\n value: unknown,\n partial = false,\n) {\n return inputValueInDomain(input.domain, value, input.domain.selection, {\n ignoreMinimum: partial,\n });\n}\nfunction matchesBoardTarget(\n input: InteractionInputDescriptor,\n target: RuntimeBoardTarget,\n) {\n const domain = input.domain;\n return (\n domain.type === \"boardTarget\" &&\n domain.valueKind === target.valueKind &&\n domain.targetKind === target.kind &&\n (domain.valueKind === \"board-id\" && target.valueKind === \"board-id\"\n ? domain.boardId === target.boardId\n : domain.valueKind === \"board-space\" &&\n target.valueKind === \"board-space\" &&\n domain.eligibleTargets.some(\n (candidate) => candidate.boardId === target.value.boardId,\n ))\n );\n}\nfunction immutableValues(value: Values): Values {\n return immutableCopy(value);\n}\nfunction data(\n action: string,\n interaction: string,\n input?: string,\n value?: RuntimeJson,\n) {\n return {\n \"data-action\": action,\n \"data-interaction\": interaction,\n ...(input ? { \"data-input\": input } : {}),\n ...(value === undefined\n ? {}\n : {\n \"data-value\":\n typeof value === \"string\" ? value : JSON.stringify(value),\n }),\n };\n}\nexport class AmbiguousTargetError extends Error {\n constructor(id: string) {\n super(\n `Target '${id}' belongs to more than one eligible input. Choose an interaction and input explicitly.`,\n );\n this.name = \"AmbiguousTargetError\";\n }\n}\n\nclass InteractionObject {\n readonly key: string;\n readonly id: string;\n readonly phase: string;\n readonly label: string;\n readonly help?: string;\n readonly kind: \"inputs\" | \"steps\";\n readonly inputObjects: readonly InputObject[];\n readonly seat: number;\n readonly draft: Values;\n readonly draftIdentity: Values;\n readonly source: GameSource;\n readonly epoch: number;\n constructor(\n readonly owner: Controller,\n readonly descriptor: InteractionDescriptor,\n draft: Values,\n readonly status: \"open\" | \"submitting\" | \"submitted\",\n readonly connected: boolean,\n ) {\n this.seat =\n descriptor.actorSeat ??\n owner.sourceState.snapshot?.players.findIndex(\n (player) => player.playerId === owner.sourceState.snapshot?.me,\n ) ??\n -1;\n this.draftIdentity = draft;\n this.draft = immutableValues(draft);\n this.source = owner.options.source;\n this.epoch = owner.epoch;\n this.key = descriptor.interactionKey;\n this.id = descriptor.interactionId;\n this.phase = descriptor.phaseName;\n this.label = descriptor.label;\n this.help = descriptor.help;\n this.kind = descriptor.step ? \"steps\" : \"inputs\";\n this.inputObjects = Object.freeze(\n descriptor.inputs.map((input) =>\n owner.object(\"input\", new InputObject(this, input)),\n ),\n );\n }\n get game() {\n return this.owner.instance;\n }\n getAvailability() {\n return this.descriptor.availability;\n }\n getIsAvailable(params?: Values) {\n const descriptor =\n params === undefined\n ? this.descriptor\n : this.owner.descriptorFor(this.descriptor, params);\n return descriptor.availability.status === \"available\";\n }\n getUnavailableReason() {\n return this.descriptor.availability.status === \"available\"\n ? null\n : this.descriptor.availability.reason;\n }\n getStep() {\n return this.descriptor.step ?? null;\n }\n getStepIndex() {\n return this.descriptor.step?.index ?? null;\n }\n getInput(key: string) {\n return requireLookup(\n this.findInput(key),\n `Input in interaction ${this.key}`,\n key,\n );\n }\n findInput(key: string) {\n return this.inputObjects.find((input) => input.key === key);\n }\n getInputs() {\n return this.inputObjects;\n }\n readiness(params = this.draft) {\n return getInteractionDraftReadiness(\n this.owner.descriptorFor(this.descriptor, params),\n params,\n );\n }\n getIsReady(params?: Values) {\n return this.readiness(params).ready;\n }\n getMissingInputs() {\n return this.readiness().missingInputs;\n }\n getStatus() {\n return this.status;\n }\n currentLifetime() {\n return (\n this.source === this.owner.options.source &&\n this.epoch === this.owner.epoch &&\n !this.owner.disposed\n );\n }\n submit(params?: Values) {\n return this.currentLifetime()\n ? this.owner.submit(this.key, false, params)\n : Promise.resolve({ accepted: false as const, errorCode: \"CLOSED\" });\n }\n cancel() {\n return this.currentLifetime()\n ? this.owner.submit(this.key, true)\n : Promise.resolve({ accepted: false as const, errorCode: \"CLOSED\" });\n }\n reset() {\n if (this.currentLifetime()) this.owner.reset(this.key);\n }\n activate() {\n if (this.currentLifetime()) this.owner.activate(this.key);\n }\n getSubmitHandler() {\n return (event?: NativeEvent) => {\n event?.preventDefault();\n this.owner.handle(() => this.submit());\n };\n }\n getSubmitProps() {\n const disabled =\n !this.getIsAvailable() ||\n !this.getIsReady() ||\n this.status !== \"open\" ||\n !this.connected;\n return {\n ...data(\"submit\", this.key),\n \"data-seat\": this.seat,\n type: \"button\" as const,\n disabled,\n \"data-ready\": this.getIsReady(),\n \"data-disabled\": disabled,\n onClick: this.getSubmitHandler(),\n };\n }\n}\nfunction createInputTargetLabels(\n domain: InteractionInputDescriptor[\"domain\"],\n snapshot: SourceSnapshot | null,\n boards: Readonly<Record<string, SeatBoardTopology>>,\n): ReadonlyMap<string, string> {\n const targetLabels = new Map<string, string>();\n const hosts = Object.values(snapshot?.frame.zones ?? {}).flatMap((zones) =>\n Object.values(zones),\n );\n if (domain.type === \"cardTarget\") {\n domain.eligibleTargets.forEach((id, index) => {\n const card = hosts\n .map((zone) => zone.cardViewsById[id])\n .find((card) => card !== undefined);\n targetLabels.set(\n inputValueKey(id),\n card ? card.name || `Card ${index + 1}` : `Card back ${index + 1}`,\n );\n });\n }\n if (domain.type === \"tileTarget\" || domain.type === \"boardTarget\") {\n if (domain.type === \"tileTarget\") {\n const presentations = [\n ...hosts.flatMap((zone) => zone.tiles),\n ...Object.values(boards).flatMap((board) =>\n board.layout === \"generic\" ? [] : board.tiles,\n ),\n ];\n domain.eligibleTargets.forEach((ref, index) => {\n const tile = presentations.find((tile) => tile.ref === ref);\n targetLabels.set(\n inputValueKey(ref),\n tile?.disclosure === \"visible\"\n ? tile.name || `Tile ${index + 1}`\n : `Tile back ${index + 1}`,\n );\n });\n } else {\n domain.eligibleTargets.forEach((value, index) => {\n const boardId =\n typeof value === \"string\"\n ? domain.valueKind === \"board-id\"\n ? domain.boardId\n : undefined\n : value.boardId;\n const id = typeof value === \"string\" ? value : value.spaceId;\n const board = boardId === undefined ? undefined : boards[boardId];\n const name =\n domain.targetKind === \"space\"\n ? board?.spaces[id]?.name\n : board && board.layout !== \"generic\"\n ? (domain.targetKind === \"edge\"\n ? board.edges\n : board.vertices\n ).find((target) => target.id === id)?.label\n : undefined;\n const kind =\n domain.targetKind === \"space\"\n ? \"Space\"\n : domain.targetKind === \"edge\"\n ? \"Edge\"\n : \"Vertex\";\n targetLabels.set(inputValueKey(value), name || `${kind} ${index + 1}`);\n });\n }\n }\n return targetLabels;\n}\nclass InputObject {\n readonly targetLabels: ReadonlyMap<string, string>;\n readonly snapshot: SourceSnapshot | null;\n readonly key: string;\n readonly kind: InteractionInputDescriptor[\"kind\"];\n constructor(\n readonly interaction: InteractionObject,\n readonly descriptor: InteractionInputDescriptor,\n ) {\n this.key = descriptor.key;\n this.kind = descriptor.kind;\n const snapshot = interaction.owner.sourceState.snapshot;\n this.snapshot = snapshot;\n this.targetLabels = createInputTargetLabels(\n descriptor.domain,\n snapshot,\n descriptor.domain.type === \"tileTarget\" ||\n descriptor.domain.type === \"boardTarget\"\n ? interaction.owner.getBoardProjections(snapshot?.frame.view)\n : {},\n );\n }\n currentLifetime() {\n return (\n this.interaction.currentLifetime() &&\n (this.descriptor.domain.type !== \"tileTarget\" ||\n this.snapshot === this.interaction.owner.sourceState.snapshot)\n );\n }\n get game() {\n return this.interaction.game;\n }\n get domainType() {\n return this.descriptor.domain.type;\n }\n get selectionMode() {\n return isManyInput(this.descriptor) ? \"many\" : \"single\";\n }\n getTargetOptions() {\n const domain = this.getDomain();\n return this.getEligibleTargets().map((value) => ({\n value,\n label:\n this.targetLabels.get(inputValueKey(value)) ??\n (domain.type === \"choice\" || domain.type === \"choiceList\"\n ? domain.choices.find((choice) => Object.is(choice.value, value))\n ?.label\n : undefined) ??\n (value === null\n ? \"None\"\n : typeof value === \"object\"\n ? JSON.stringify(value)\n : String(value)),\n selected: this.getIsSelected(value),\n props: this.getTargetProps(value),\n }));\n }\n getDomain() {\n return this.descriptor.domain;\n }\n getValue(): RuntimeJson | undefined {\n return (\n this.interaction.draft[this.key] ??\n (Object.hasOwn(this.interaction.draft, this.key)\n ? null\n : this.descriptor.defaultValue)\n );\n }\n setValue(value: RuntimeJson) {\n if (!this.currentLifetime()) return;\n this.interaction.owner.setInput(this.interaction.key, this.key, value);\n }\n clear() {\n if (!this.currentLifetime()) return;\n this.interaction.owner.clearInput(this.interaction.key, this.key);\n }\n getIsReady() {\n const descriptor = {\n ...this.interaction.descriptor,\n inputs: [this.descriptor],\n };\n return getInteractionDraftReadiness(descriptor, {\n [this.key]: this.getValue(),\n }).ready;\n }\n getEligibleTargets(): readonly RuntimeJson[] {\n const domain = this.descriptor.domain;\n if (\n domain.type === \"cardTarget\" ||\n domain.type === \"boardTarget\" ||\n domain.type === \"tileTarget\"\n )\n return domain.eligibleTargets;\n if (domain.type === \"choice\" || domain.type === \"choiceList\")\n return domain.choices\n .filter((choice) => !choice.disabled)\n .map((choice) => choice.value);\n return [];\n }\n getIsEligible(value: RuntimeJson) {\n const input = this.descriptor;\n return (\n inputTargetInDomain(input.domain, value) &&\n isManyTargetSelectable(input, this.getValue(), value)\n );\n }\n getIsSelected(value: RuntimeJson) {\n const current = this.getValue();\n return isManyInput(this.descriptor) && Array.isArray(current)\n ? current.some((item) => equalValue(item, value))\n : equalValue(current, value);\n }\n getSelectHandler(value: RuntimeJson) {\n return () => {\n if (this.currentLifetime())\n this.interaction.owner.select(this.interaction.key, this.key, value);\n };\n }\n getTargetProps(value: RuntimeJson) {\n const eligible = this.getIsEligible(value);\n const disabled =\n !eligible ||\n !this.interaction.getIsAvailable() ||\n this.interaction.status !== \"open\" ||\n !this.interaction.connected;\n return {\n ...data(\"select\", this.interaction.key, this.key, value),\n \"data-seat\": this.interaction.seat,\n type: \"button\" as const,\n disabled,\n \"data-eligible\": eligible,\n \"data-selected\": this.getIsSelected(value),\n \"data-disabled\": disabled,\n onClick: () => this.getSelectHandler(value)(),\n };\n }\n getControl() {\n const disabled =\n !this.interaction.getIsAvailable() ||\n this.interaction.status !== \"open\" ||\n !this.interaction.connected;\n return createInputControl(this, {\n ...data(\"option\", this.interaction.key, this.key),\n \"data-seat\": this.interaction.seat,\n disabled,\n \"data-disabled\": disabled,\n });\n }\n}\nclass CardObject {\n readonly epoch: number;\n readonly seat: number;\n readonly view: ReadonlyData<ViewCard> | null;\n readonly hidden: boolean;\n readonly backImage: string | null;\n constructor(\n readonly owner: Controller,\n readonly id: string,\n readonly zone: string,\n readonly hostId: string,\n readonly index: number,\n view: ReadonlyData<ViewCard> | undefined,\n backImage: string | undefined,\n readonly routes: readonly InteractionObject[],\n ) {\n this.epoch = owner.epoch;\n this.seat =\n owner.sourceState.snapshot?.players.findIndex(\n (player) => player.playerId === owner.sourceState.snapshot?.me,\n ) ?? -1;\n this.view = view ?? null;\n this.hidden = this.view === null;\n this.backImage = backImage ?? null;\n }\n get game() {\n return this.owner.instance;\n }\n getInteractions() {\n return this.routes;\n }\n getIsEligible() {\n return this.routes.some((route) => route.getIsAvailable());\n }\n getIsSelected() {\n return this.routes.some((route) =>\n route\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type === \"cardTarget\" &&\n input.getIsSelected(this.id),\n ),\n );\n }\n getCanSelect(options?: RuntimeTargetOptions) {\n return this.routes.some(\n (route) =>\n route.getIsAvailable() &&\n (!options?.interaction || route.key === options.interaction) &&\n route.status === \"open\" &&\n route.connected &&\n route\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type === \"cardTarget\" &&\n (!options?.input || input.key === options.input) &&\n input.getIsEligible(this.id),\n ),\n );\n }\n select(options?: RuntimeTargetOptions) {\n if (this.epoch !== this.owner.epoch || this.owner.disposed) return;\n this.owner.selectCard(this.id, options);\n }\n getSelectHandler(options?: RuntimeTargetOptions) {\n return () => this.select(options);\n }\n getProps(options?: RuntimeTargetOptions) {\n return {\n type: \"button\" as const,\n disabled: !this.getCanSelect(options),\n \"data-action\": \"select\",\n \"data-value\": this.id,\n \"data-interaction\": options?.interaction,\n \"data-input\": options?.input,\n \"data-eligible\": this.getIsEligible(),\n \"data-selected\": this.getIsSelected(),\n \"data-disabled\": !this.getCanSelect(options),\n \"data-hidden\": this.hidden,\n \"data-seat\": this.seat,\n onClick: this.getSelectHandler(options),\n };\n }\n}\nclass TileObject {\n readonly epoch: number;\n readonly snapshot: SourceSnapshot | null;\n constructor(\n readonly owner: Controller,\n readonly data: ProjectedTile,\n readonly zone: string,\n readonly hostId: string,\n readonly index: number,\n readonly routes: readonly InteractionObject[],\n ) {\n this.epoch = owner.epoch;\n this.snapshot = owner.sourceState.snapshot;\n }\n get ref() {\n return this.data.ref;\n }\n get game() {\n return this.owner.instance;\n }\n getInteractions() {\n return this.routes;\n }\n getIsEligible() {\n return this.routes.some((route) =>\n route\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type === \"tileTarget\" &&\n input.getIsEligible(this.ref),\n ),\n );\n }\n getIsSelected() {\n return this.routes.some((route) =>\n route\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type === \"tileTarget\" &&\n input.getIsSelected(this.ref),\n ),\n );\n }\n getCanSelect(options?: RuntimeTargetOptions) {\n return this.routes.some(\n (route) =>\n route.getIsAvailable() &&\n (!options?.interaction || route.key === options.interaction) &&\n route\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type === \"tileTarget\" &&\n (!options?.input || input.key === options.input) &&\n !input.getTargetProps(this.ref).disabled,\n ),\n );\n }\n select(options?: RuntimeTargetOptions) {\n if (\n this.owner.disposed ||\n this.epoch !== this.owner.epoch ||\n this.snapshot !== this.owner.sourceState.snapshot\n )\n return;\n this.owner.routeTarget({ kind: \"tile\", value: this.ref }, options);\n }\n getSelectHandler(options?: RuntimeTargetOptions) {\n return () => this.select(options);\n }\n getTargetProps(options?: RuntimeTargetOptions) {\n const disabled = !this.getCanSelect(options);\n return {\n type: \"button\" as const,\n disabled,\n \"data-action\": \"select\",\n \"data-value\": this.ref,\n \"data-interaction\": options?.interaction,\n \"data-input\": options?.input,\n \"data-eligible\": this.getIsEligible(),\n \"data-selected\": this.getIsSelected(),\n \"data-disabled\": disabled,\n \"data-hidden\": this.data.disclosure === \"concealed\",\n onClick: this.getSelectHandler(options),\n };\n }\n}\nclass ZoneObject {\n constructor(\n readonly owner: Controller,\n readonly id: string,\n readonly hostId: string,\n readonly cards: readonly CardObject[],\n readonly tiles: readonly TileObject[],\n ) {}\n get game() {\n return this.owner.instance;\n }\n get count() {\n return this.cards.length + this.tiles.length;\n }\n getIsEmpty() {\n return this.count === 0;\n }\n getTiles() {\n return this.tiles;\n }\n getTile(ref: SeatTileRef) {\n return requireLookup(this.findTile(ref), `Tile in zone ${this.id}`, ref);\n }\n findTile(ref: SeatTileRef) {\n return this.tiles.find((tile) => tile.ref === ref);\n }\n getCard(id: string) {\n return requireLookup(this.findCard(id), `Card in zone ${this.id}`, id);\n }\n findCard(id: string) {\n return this.cards.find((card) => card.id === id);\n }\n getCards(options?: { sort?: (a: CardObject, b: CardObject) => number }) {\n return options?.sort ? [...this.cards].sort(options.sort) : this.cards;\n }\n}\nclass PlayerObject {\n readonly id: string;\n readonly name: string;\n readonly color?: string;\n constructor(\n readonly owner: Controller,\n summary: SourceSnapshot[\"players\"][number],\n readonly index: number,\n readonly isMe: boolean,\n readonly active: boolean,\n ) {\n this.id = summary.playerId;\n this.name = summary.displayName;\n this.color = summary.color;\n }\n get game() {\n return this.owner.instance;\n }\n}\nclass PhaseObject {\n constructor(readonly current: string | null) {}\n is(name: string) {\n return this.current === name;\n }\n switch<R>(routes: Record<string, () => R>): R | null {\n return this.current === null ? null : routes[this.current]();\n }\n}\n\ninterface RuntimeModel {\n readonly snapshot: SourceSnapshot | null;\n readonly view: SourceSnapshot[\"frame\"][\"view\"] | null;\n readonly version: number | null;\n readonly connection: SourceState[\"connection\"];\n readonly request: SourceState[\"request\"];\n readonly failure: SourceState[\"failure\"];\n readonly state: {\n readonly drafts: DraftMap;\n readonly activeInteraction: string | null;\n };\n readonly phase: PhaseObject;\n readonly turn: {\n readonly activePlayerIds: readonly string[];\n readonly currentPlayerId: string | null;\n readonly order: readonly string[];\n readonly isMine: boolean;\n };\n readonly me: {\n readonly id: string;\n readonly player: PlayerObject;\n getCanAct(): boolean;\n } | null;\n readonly players: RuntimeCollection<PlayerObject> & {\n readonly order: readonly string[];\n next(id: string): PlayerObject;\n };\n readonly interactions: {\n get(key: string): InteractionObject;\n find(key: string): InteractionObject | undefined;\n list(): readonly InteractionObject[];\n listAvailable(): readonly InteractionObject[];\n };\n readonly inputs: {\n get(key: string, name: string): InputObject;\n find(key: string, name: string): InputObject | undefined;\n };\n readonly zones: {\n get(id: string, hostId: string): ZoneObject;\n find(id: string, hostId: string): ZoneObject | undefined;\n getAll(): readonly ZoneObject[];\n };\n readonly cards: Pick<RuntimeCollection<CardObject>, \"get\" | \"find\">;\n readonly events: { readonly recent: SourceSnapshot[\"frame\"][\"events\"] };\n}\ninterface RuntimeCore extends RuntimeModel {\n readonly store: Pick<\n ReturnType<typeof createStore<RuntimeModel>>,\n \"get\" | \"subscribe\"\n >;\n getSnapshot(): RuntimeModel;\n getOptions(): RuntimeOptions;\n setOptions(options: RuntimeOptions): void;\n subscribe(listener: () => void): () => void;\n dispose(): void;\n assertCoverage(): void;\n}\ninterface RuntimeContext extends Omit<\n RuntimeFeatureContext,\n \"game\" | \"getBoards\"\n> {\n readonly [runtimeFeatures]: RuntimeFeatureContext;\n}\n\nclass Controller {\n readonly boardProjections = new WeakMap<\n object,\n Readonly<Record<string, SeatBoardTopology>>\n >();\n getBoardProjections(\n view: unknown,\n ): Readonly<Record<string, SeatBoardTopology>> {\n if (view === null || typeof view !== \"object\" || Array.isArray(view))\n return {};\n const cached = this.boardProjections.get(view);\n if (cached) return cached;\n const payload: unknown = Reflect.get(view, \"boards\");\n const boards =\n payload === undefined\n ? {}\n : immutableCopy(BoardProjectionSchema.parse(payload));\n this.boardProjections.set(view, boards);\n return boards;\n }\n epoch = 0;\n options: RuntimeOptions;\n localDrafts: DraftMap;\n localActive: string | null;\n disposed = false;\n readonly instance: RuntimeCore;\n readonly store: ReturnType<typeof createStore<RuntimeModel>>;\n readonly prototypes = {\n interaction: Object.create(InteractionObject.prototype) as object,\n input: Object.create(InputObject.prototype) as object,\n card: Object.create(CardObject.prototype) as object,\n zone: Object.create(ZoneObject.prototype) as object,\n board: {},\n };\n subscription: { unsubscribe(): void } | undefined;\n sourceState: SourceState;\n reportedFailures = new WeakMap<GameSource, Readonly<Error>>();\n pending: {\n source: GameSource;\n key: string;\n draftRevision: number | undefined;\n version: number;\n epoch: number;\n accepted: boolean;\n cancel: boolean;\n } | null = null;\n building: RuntimeModel | undefined;\n rootProperties = new Map<PropertyKey, PropertyDescriptor>();\n featureDisposals: (() => void)[] = [];\n warned = new Set<string>();\n invalidControlledState: RuntimeOptions[\"state\"] | undefined;\n observed = new Set<string>();\n revisions = new Map<string, number>();\n lastDrafts: DraftMap = EMPTY_DRAFTS;\n lastInteractions: readonly InteractionObject[] = [];\n lastSnapshotDrafts: DraftMap | undefined;\n trackDrafts() {\n const drafts = this.drafts();\n for (const key of new Set([\n ...Object.keys(this.lastDrafts),\n ...Object.keys(drafts),\n ]))\n if (this.lastDrafts[key] !== drafts[key])\n this.revisions.set(key, (this.revisions.get(key) ?? 0) + 1);\n this.lastDrafts = drafts;\n }\n constructor(\n options: RuntimeOptions,\n features?: (core: RuntimeCore, context: RuntimeContext) => Features,\n ) {\n this.options = options;\n this.localDrafts = options.initialState?.drafts ?? EMPTY_DRAFTS;\n this.localActive = options.initialState?.activeInteraction ?? null;\n this.sourceState = options.source.store.get();\n const current = () => this.building ?? this.store.get();\n const root: RuntimeCore = {\n get snapshot() {\n return current().snapshot;\n },\n get view() {\n return current().view;\n },\n get version() {\n return current().version;\n },\n get connection() {\n return current().connection;\n },\n get failure() {\n return current().failure;\n },\n get request() {\n return current().request;\n },\n get state() {\n return current().state;\n },\n get phase() {\n return current().phase;\n },\n get turn() {\n return current().turn;\n },\n get me() {\n return current().me;\n },\n get players() {\n return current().players;\n },\n get interactions() {\n return current().interactions;\n },\n get inputs() {\n return current().inputs;\n },\n get zones() {\n return current().zones;\n },\n get cards() {\n return current().cards;\n },\n get events() {\n return current().events;\n },\n store: {\n get: () => this.store.get(),\n subscribe: (listener: () => void) => this.store.subscribe(listener),\n },\n getSnapshot: () => this.building ?? this.store.get(),\n getOptions: () => this.options,\n setOptions: (next: RuntimeOptions) => this.setOptions(next),\n subscribe: (listener: () => void) => {\n const sub = this.store.subscribe(listener);\n return () => sub.unsubscribe();\n },\n dispose: () => this.dispose(),\n assertCoverage: () => this.assertCoverage(),\n };\n // Keep live projections out of enumeration, spreads, and serialization.\n for (const [key, descriptor] of Object.entries(\n Object.getOwnPropertyDescriptors(root),\n )) {\n if (descriptor.get) {\n Object.defineProperty(root, key, {\n enumerable: false,\n configurable: false,\n });\n }\n }\n Object.defineProperty(root, \"store\", {\n enumerable: false,\n configurable: false,\n writable: false,\n });\n this.instance = root;\n this.store = createStore(Object.freeze(this.build()));\n if (\"apply\" in options.source)\n Object.defineProperty(root, \"apply\", {\n value: (action: unknown) =>\n (\n this.options.source as GameSource & {\n apply(action: unknown): unknown;\n }\n ).apply(action),\n });\n if (\"explore\" in options.source)\n Object.defineProperty(root, \"explore\", {\n value: (...args: unknown[]) =>\n (\n this.options.source as GameSource & {\n explore(...args: unknown[]): unknown;\n }\n ).explore(...args),\n });\n const runtime: RuntimeFeatureContext = {\n game: this.instance,\n getBoards: () => this.getBoardProjections(this.instance.view),\n createBoard: (data: SeatBoardTopology) =>\n this.object(\"board\", {\n id: data.id,\n data: immutableCopy(data),\n game: this.instance,\n }),\n routeTarget: (target, options) => this.routeTarget(target, options),\n routeCardDrop: (cardId, target) => this.routeCardDrop(cardId, target),\n invalidate: () => {\n if (!this.disposed) this.refresh();\n },\n };\n const context: RuntimeContext = { ...runtime, [runtimeFeatures]: runtime };\n for (const feature of Object.values(\n features?.(this.instance, context) ?? {},\n )) {\n if (feature.root)\n for (const key of Reflect.ownKeys(feature.root)) {\n if (key in root || this.rootProperties.has(key))\n throw new Error(`Overlapping feature property '${String(key)}'.`);\n this.rootProperties.set(\n key,\n Object.getOwnPropertyDescriptor(feature.root, key)!,\n );\n Object.defineProperty(root, key, {\n get: (): unknown =>\n Reflect.get(this.building ?? this.store.get(), key),\n });\n }\n for (const hook of [\n \"interaction\",\n \"input\",\n \"zone\",\n \"card\",\n \"board\",\n ] as const)\n this.install(this.prototypes[hook], feature[hook]);\n if (feature.dispose) this.featureDisposals.push(feature.dispose);\n }\n this.refresh();\n this.subscribeSource();\n this.reportSourceFailure();\n }\n install(target: object, extension: object | undefined) {\n if (!extension) return;\n for (const key of Reflect.ownKeys(extension)) {\n if (\n key in target ||\n [\n \"game\",\n \"owner\",\n \"descriptor\",\n \"draft\",\n \"inputObjects\",\n \"status\",\n \"connected\",\n \"key\",\n \"id\",\n \"phase\",\n \"label\",\n \"help\",\n \"kind\",\n \"interaction\",\n \"view\",\n \"hidden\",\n \"zone\",\n \"index\",\n \"routes\",\n \"cards\",\n ].includes(String(key))\n )\n throw new Error(`Overlapping feature property '${String(key)}'.`);\n }\n Object.defineProperties(\n target,\n Object.getOwnPropertyDescriptors(extension),\n );\n }\n object<T extends object>(hook: keyof Controller[\"prototypes\"], value: T): T {\n Object.setPrototypeOf(value, this.prototypes[hook]);\n return Object.freeze(value);\n }\n drafts() {\n if (\n this.options.state &&\n this.options.state === this.invalidControlledState\n )\n return EMPTY_DRAFTS;\n return this.options.state?.drafts ?? this.localDrafts;\n }\n active() {\n if (\n this.options.state &&\n this.options.state === this.invalidControlledState\n )\n return null;\n return this.options.state?.activeInteraction !== undefined\n ? this.options.state.activeInteraction\n : this.localActive;\n }\n writeDrafts(next: DraftMap) {\n if (this.options.state?.drafts === undefined) this.localDrafts = next;\n this.options.onDraftsChange?.(next);\n this.refresh();\n }\n writeDraft(key: string, value: Values | undefined) {\n const drafts = this.drafts();\n const next = { ...drafts };\n if (value === undefined) delete next[key];\n else next[key] = immutableValues(value);\n this.writeDrafts(Object.freeze(next));\n }\n activate(key: string | null) {\n if (this.disposed || (key !== null && !this.current(key))) return;\n if (this.options.state?.activeInteraction === undefined)\n this.localActive = key;\n this.options.onActiveInteractionChange?.(key);\n this.refresh();\n }\n descriptorFor(base: InteractionDescriptor, draft: Values) {\n const zones = this.sourceState.snapshot?.frame.zones ?? {};\n for (const input of base.inputs) {\n const card = draft[input.key];\n if (input.domain.type !== \"cardTarget\" || typeof card !== \"string\")\n continue;\n for (const zone of Object.values(zones).flatMap((hosts) =>\n Object.values(hosts),\n )) {\n const route = zone.playableByCardId[card]?.find(\n (value) => value.interactionKey === base.interactionKey,\n );\n if (route) return route;\n }\n }\n return base;\n }\n current(key: string) {\n return this.store.get().interactions.find(key);\n }\n editable(key: string) {\n const interaction = this.current(key);\n return !this.disposed &&\n this.sourceState.connection === \"ready\" &&\n !this.sourceState.request &&\n interaction?.getIsAvailable()\n ? interaction\n : undefined;\n }\n setInput(key: string, inputKey: string, value: RuntimeJson) {\n const interaction = this.editable(key);\n if (!interaction?.findInput(inputKey)) return;\n this.writeDraft(key, { ...this.drafts()[key], [inputKey]: value });\n }\n clearInput(key: string, inputKey: string) {\n if (!this.editable(key)?.findInput(inputKey)) return;\n const value = { ...this.drafts()[key] };\n delete value[inputKey];\n this.writeDraft(key, value);\n }\n reset(key: string) {\n if (this.disposed) return;\n this.writeDraft(key, undefined);\n if (this.active() === key) this.activate(null);\n }\n select(\n key: string,\n inputKey: string,\n value: RuntimeJson,\n route?: InteractionObject,\n ) {\n const interaction = route ?? this.editable(key);\n if (\n route &&\n (!route.currentLifetime() ||\n !route.getIsAvailable() ||\n this.sourceState.connection !== \"ready\" ||\n this.sourceState.request ||\n this.pending)\n )\n return;\n const input = interaction?.findInput(inputKey);\n if (!interaction || !input?.getIsEligible(value)) return;\n if (\n isManyInput(input.descriptor) ||\n (typeof value === \"string\" &&\n (input.descriptor.domain.type === \"cardTarget\" ||\n input.descriptor.domain.type === \"boardTarget\" ||\n input.descriptor.domain.type === \"tileTarget\"))\n ) {\n let next: Record<string, unknown> = { ...this.drafts()[key] };\n routeInteractionTarget(\n {\n getDraft: () => next,\n setInput: (_key, k, v) => {\n next = { ...next, [k]: v };\n },\n clearInput: (_key, k) => {\n if (k) delete next[k];\n },\n },\n interaction.descriptor,\n { inputKey, value },\n );\n this.writeDraft(key, next as Values);\n } else this.setInput(key, inputKey, value);\n this.activate(key);\n const current = this.current(key);\n if (\n current &&\n Object.hasOwn(this.drafts()[key] ?? EMPTY, inputKey) &&\n shouldAutoSubmitInteraction(current.descriptor) &&\n current.getIsReady()\n )\n this.handle(() => this.submit(key, false));\n }\n selectCard(id: string, options?: RuntimeTargetOptions) {\n const card = this.store.get().cards.find(id);\n if (\n !card ||\n this.sourceState.request ||\n this.sourceState.connection !== \"ready\"\n )\n return;\n const candidates = card.routes.flatMap((interaction) => {\n if (\n !interaction.getIsAvailable() ||\n !interaction.currentLifetime() ||\n (options?.interaction && interaction.key !== options.interaction)\n )\n return [];\n return interaction\n .getInputs()\n .filter(\n (input) =>\n input.descriptor.domain.type === \"cardTarget\" &&\n (!options?.input || input.key === options.input) &&\n input.getIsEligible(id),\n )\n .map((input) => ({ interaction, input }));\n });\n if (candidates.length > 1) throw new AmbiguousTargetError(id);\n const candidate = candidates[0];\n if (candidate)\n this.select(\n candidate.interaction.key,\n candidate.input.key,\n id,\n candidate.interaction,\n );\n }\n handle(submit: () => Promise<SubmitResult>) {\n const source = this.options.source;\n const active = () => !this.disposed && this.options.source === source;\n void submit().then(\n (result) => {\n if (active() && !result.accepted)\n this.options.onError?.(\n new Error(result.message ?? result.errorCode, { cause: result }),\n );\n },\n (error) => {\n if (!active()) return;\n const state = source.store.get();\n if (state.failure === error || state.connection === \"closed\") return;\n this.options.onError?.(error);\n },\n );\n }\n async submit(\n key: string,\n cancel: boolean,\n params?: Values,\n ): Promise<SubmitResult> {\n const source = this.options.source;\n const interaction = this.current(key);\n if (\n this.disposed ||\n this.sourceState.connection !== \"ready\" ||\n this.sourceState.request ||\n this.pending\n )\n return { accepted: false, errorCode: \"BUSY\" };\n if (!interaction) return { accepted: false, errorCode: \"UNAVAILABLE\" };\n if (\n cancel\n ? !interaction.getStep()?.canCancel\n : !interaction.getIsAvailable(params) || !interaction.getIsReady(params)\n )\n return { accepted: false, errorCode: \"UNAVAILABLE\" };\n if (!(\"submit\" in source) || !(\"cancel\" in source))\n return { accepted: false, errorCode: \"READ_ONLY\" };\n const commandSource = source as GameSource & {\n submit(id: string, params: RuntimeJson): Promise<SubmitResult>;\n cancel(id: string): Promise<SubmitResult>;\n };\n const operation = {\n source,\n key,\n draftRevision:\n params === undefined ? (this.revisions.get(key) ?? 0) : undefined,\n version: this.sourceState.snapshot.version,\n epoch: this.epoch,\n accepted: false,\n cancel,\n };\n this.pending = operation;\n try {\n const result = await (cancel\n ? commandSource.cancel(interaction.id)\n : commandSource.submit(\n interaction.id,\n interaction.readiness(params).values as RuntimeJson,\n ));\n if (this.pending !== operation) return result;\n if (!result.accepted) {\n this.pending = null;\n this.refresh();\n return result;\n }\n operation.accepted = true;\n this.finishBarrier();\n return result;\n } catch (error) {\n if (this.pending === operation) {\n this.pending = null;\n this.refresh();\n }\n throw error;\n }\n }\n finishBarrier() {\n const operation = this.pending;\n if (\n !operation?.accepted ||\n this.sourceState.request ||\n operation.source !== this.options.source ||\n operation.epoch !== this.epoch\n )\n return;\n if (\n this.sourceState.connection === \"closed\" ||\n this.sourceState.connection === \"failed\"\n ) {\n this.pending = null;\n this.refresh();\n return;\n }\n if (\n this.sourceState.connection !== \"ready\" ||\n (this.sourceState.snapshot?.version ?? -1) <= operation.version\n )\n return;\n this.pending = null;\n if (\n operation.draftRevision !== undefined &&\n (this.revisions.get(operation.key) ?? 0) === operation.draftRevision\n )\n this.reset(operation.key);\n else this.refresh();\n }\n reportSourceFailure() {\n const failure = this.sourceState.failure;\n if (\n !failure ||\n !this.options.onError ||\n this.reportedFailures.get(this.options.source) === failure\n )\n return;\n this.reportedFailures.set(this.options.source, failure);\n this.options.onError?.(failure);\n }\n subscribeSource() {\n const source = this.options.source;\n this.subscription = source.store.subscribe(() => {\n if (this.disposed || this.options.source !== source) return;\n const next = source.store.get();\n const previousSnapshot = this.sourceState.snapshot;\n this.sourceState = next;\n if (\n previousSnapshot &&\n next.snapshot &&\n previousSnapshot.me !== next.snapshot.me\n ) {\n this.epoch++;\n this.invalidControlledState = this.options.state;\n this.pending = null;\n this.localDrafts = EMPTY_DRAFTS;\n this.localActive = null;\n this.options.onDraftsChange?.({});\n this.options.onActiveInteractionChange?.(null);\n }\n this.reconcile();\n this.refresh();\n this.finishBarrier();\n this.reportSourceFailure();\n });\n }\n setOptions(next: RuntimeOptions) {\n if (this.disposed) throw new Error(\"Game instance is disposed.\");\n const changed = next.source !== this.options.source;\n if (changed) {\n this.epoch++;\n this.subscription?.unsubscribe();\n this.options.source.dispose();\n this.pending = null;\n }\n this.options = next;\n if (changed) {\n this.invalidControlledState = next.state;\n this.localDrafts = EMPTY_DRAFTS;\n this.localActive = null;\n this.sourceState = next.source.store.get();\n this.options.onDraftsChange?.({});\n this.options.onActiveInteractionChange?.(null);\n this.subscribeSource();\n }\n this.reconcile();\n this.refresh();\n this.reportSourceFailure();\n }\n reconcile() {\n const snapshot = this.sourceState.snapshot;\n if (!snapshot) return;\n const drafts = this.drafts();\n let changed = false;\n const next: Record<string, Values | undefined> = { ...drafts };\n for (const [key, values] of Object.entries(drafts)) {\n if (!values) continue;\n const base = snapshot.frame.availableInteractions.find(\n (value) => value.interactionKey === key,\n );\n if (!base) {\n if (this.pending?.key !== key) {\n delete next[key];\n changed = true;\n }\n continue;\n }\n const descriptor = this.descriptorFor(base, values);\n const kept = { ...values };\n let fieldChanged = false;\n for (const [name, value] of Object.entries(values)) {\n const input = descriptor.inputs.find((input) => input.key === name);\n if (!input && this.pending?.key === key) continue;\n const selection = input && inputSelection(input);\n if (input && selection?.mode === \"many\" && Array.isArray(value)) {\n const eligible = value.filter((item) =>\n inputTargetInDomain(input.domain, item),\n );\n const max = selection.max;\n const retained =\n max === undefined ? eligible : eligible.slice(0, max);\n if (retained.length !== value.length) {\n kept[name] = retained;\n changed = true;\n fieldChanged = true;\n }\n continue;\n }\n if (!input || !inDomain(input, value, true)) {\n delete kept[name];\n changed = true;\n fieldChanged = true;\n }\n }\n if (fieldChanged) next[key] = immutableValues(kept);\n }\n if (changed) this.writeDrafts(Object.freeze(next));\n const active = this.active();\n if (\n active &&\n !snapshot.frame.availableInteractions.some(\n (value) => value.interactionKey === active,\n )\n )\n this.activate(null);\n }\n dispose() {\n if (this.disposed) return;\n this.disposed = true;\n this.featureDisposals.forEach((dispose) => dispose());\n this.subscription?.unsubscribe();\n this.pending = null;\n this.options.source.dispose();\n this.sourceState = this.options.source.store.get();\n this.refresh();\n }\n assertCoverage() {\n const missing =\n this.sourceState.snapshot?.frame.availableInteractions\n .filter(\n (d) =>\n d.availability.status === \"available\" &&\n !this.observed.has(d.interactionKey),\n )\n .map((d) => d.interactionKey) ?? [];\n if (missing.length)\n throw new Error(`Interactions not read: ${missing.join(\", \")}`);\n }\n routeTarget(target: RuntimeSelectionTarget, options?: RuntimeTargetOptions) {\n if (target.kind === \"card\") {\n this.selectCard(target.value, options);\n return;\n }\n const candidates = this.lastInteractions.flatMap((interaction) =>\n interaction\n .getInputs()\n .filter(\n (input) =>\n (target.kind === \"tile\"\n ? input.descriptor.domain.type === \"tileTarget\"\n : matchesBoardTarget(input.descriptor, target)) &&\n input.getIsEligible(target.value) &&\n interaction.getIsAvailable() &&\n (!options?.interaction ||\n interaction.key === options.interaction) &&\n (!options?.input || input.key === options.input),\n )\n .map((input) => ({ interaction, input })),\n );\n if (candidates.length > 1)\n throw new AmbiguousTargetError(JSON.stringify(target.value));\n const match = candidates[0];\n if (match)\n this.select(match.interaction.key, match.input.key, target.value);\n }\n routeCardDrop(cardId: string, target: RuntimeDropTarget) {\n if (\n this.disposed ||\n this.sourceState.request ||\n this.pending ||\n this.sourceState.connection !== \"ready\"\n )\n return;\n const card = this.store.get().cards.find(cardId);\n const interaction = card?.routes.find(\n (route) => route.key === target.interactionKey,\n );\n if (!interaction?.currentLifetime() || !interaction.getIsAvailable())\n return;\n const cardInput = interaction.findInput(target.cardInputKey);\n if (\n !cardInput ||\n cardInput.descriptor.domain.type !== \"cardTarget\" ||\n !cardInput.getIsEligible(cardId)\n )\n return;\n const input =\n target.kind === \"interaction\"\n ? undefined\n : interaction.findInput(target.inputKey);\n if (\n target.kind !== \"interaction\" &&\n (!input ||\n !matchesBoardTarget(input.descriptor, target) ||\n !input.getIsEligible(target.value))\n )\n return;\n let next: Record<string, unknown> = { ...this.drafts()[interaction.key] };\n const chosen = next[cardInput.key];\n // Dropping adds a card; it never toggles an already chosen card back out.\n if (\n !input &&\n isManyInput(cardInput.descriptor) &&\n Array.isArray(chosen) &&\n chosen.includes(cardId)\n ) {\n this.activate(interaction.key);\n return;\n }\n routeCardInputIntent(\n {\n getDraft: () => next,\n setInput: (_key, key, value) => {\n next = { ...next, [key]: value };\n },\n clearInput: (_key, key) => {\n if (key) delete next[key];\n },\n },\n interaction.descriptor,\n {\n cardId,\n cardInputKey: cardInput.key,\n dropTarget:\n input && target.kind !== \"interaction\"\n ? { inputKey: input.key, value: target.value }\n : undefined,\n },\n );\n this.writeDraft(interaction.key, next as Values);\n this.activate(interaction.key);\n const current = this.current(interaction.key);\n if (\n current &&\n shouldAutoSubmitInteraction(current.descriptor) &&\n current.getIsReady()\n )\n this.handle(() => current.submit());\n }\n warnUnread() {\n const environment =\n (import.meta as { env?: { DEV?: boolean } }).env?.DEV ??\n (globalThis as { process?: { env?: { NODE_ENV?: string } } }).process?.env\n ?.NODE_ENV === \"development\";\n if (!(this.options.debug ?? environment)) return;\n queueMicrotask(() => {\n if (this.disposed) return;\n for (const descriptor of this.sourceState.snapshot?.frame\n .availableInteractions ?? []) {\n const key = descriptor.interactionKey;\n if (\n descriptor.availability.status === \"available\" &&\n !this.observed.has(key) &&\n !this.warned.has(key)\n ) {\n this.warned.add(key);\n console.warn(`Available interaction '${key}' has not been read.`);\n }\n }\n });\n }\n build(previous?: RuntimeModel): RuntimeModel {\n this.trackDrafts();\n const { snapshot, connection, request, failure } = this.sourceState;\n const old = previous?.snapshot;\n const drafts = this.drafts();\n const active = this.active();\n const sameSnapshot = snapshot === old;\n const sameActors = sameSnapshot;\n const summaries = snapshot?.players ?? [];\n const activeIds = snapshot?.frame.flow.activePlayers ?? [];\n const playerObjects =\n sameActors && previous\n ? previous.players.getAll()\n : Object.freeze(\n summaries.map((player, index) =>\n Object.freeze(\n new PlayerObject(\n this,\n player,\n index,\n player.playerId === snapshot?.me,\n activeIds.includes(player.playerId),\n ),\n ),\n ),\n );\n const players =\n sameActors && previous\n ? previous.players\n : {\n order: Object.freeze(playerObjects.map((p) => p.id)),\n get: (id: string) =>\n requireLookup(\n playerObjects.find((p) => p.id === id),\n \"Player\",\n id,\n ),\n find: (id: string) => playerObjects.find((p) => p.id === id),\n getAll: () => playerObjects,\n next: (id: string) => {\n const index = playerObjects.findIndex((p) => p.id === id);\n return requireLookup(\n index < 0\n ? undefined\n : playerObjects[(index + 1) % playerObjects.length],\n \"Next player after\",\n id,\n );\n },\n };\n const me =\n sameActors && previous\n ? previous.me\n : snapshot\n ? {\n id: snapshot.me,\n player: players.get(snapshot.me),\n getCanAct: () =>\n snapshot.frame.availableInteractions.some(\n (value) => value.availability.status === \"available\",\n ),\n }\n : null;\n const descriptors = snapshot?.frame.availableInteractions ?? [];\n const interactionObjects = descriptors.map((base) => {\n const key = base.interactionKey;\n const draft = drafts[key] ?? EMPTY;\n const descriptor = this.descriptorFor(base, draft);\n const status =\n request || this.pending\n ? request?.interactionId === descriptor.interactionId &&\n request.phase === \"awaiting-frame\"\n ? \"submitted\"\n : \"submitting\"\n : \"open\";\n const oldObject = this.lastInteractions.find(\n (value) => value.key === key,\n );\n return oldObject?.descriptor === descriptor &&\n oldObject.epoch === this.epoch &&\n oldObject.source === this.options.source &&\n oldObject.draftIdentity === draft &&\n oldObject.status === status &&\n oldObject.connected === (connection === \"ready\")\n ? oldObject\n : this.object(\n \"interaction\",\n new InteractionObject(\n this,\n descriptor,\n draft,\n status,\n connection === \"ready\",\n ),\n );\n });\n const interactionsSame =\n previous &&\n interactionObjects.length === this.lastInteractions.length &&\n interactionObjects.every(\n (value, index) => value === this.lastInteractions[index],\n );\n this.lastInteractions = Object.freeze(interactionObjects);\n const interactions = interactionsSame\n ? previous.interactions\n : {\n get: (key: string) => {\n this.observed.add(key);\n return requireLookup(\n interactionObjects.find((value) => value.key === key),\n \"Interaction\",\n key,\n );\n },\n find: (key: string) => {\n this.observed.add(key);\n return interactionObjects.find((value) => value.key === key);\n },\n list: () => {\n interactionObjects.forEach((value) => this.observed.add(value.key));\n return Object.freeze(interactionObjects);\n },\n listAvailable: () => {\n const available = interactionObjects.filter((value) =>\n value.getIsAvailable(),\n );\n available.forEach((value) => this.observed.add(value.key));\n return Object.freeze(available);\n },\n };\n const inputs =\n interactionsSame && previous\n ? previous.inputs\n : {\n get: (key: string, name: string) =>\n requireLookup(\n interactions.find(key)?.findInput(name),\n `Input in interaction ${key}`,\n name,\n ),\n find: (key: string, name: string) =>\n interactions.find(key)?.findInput(name),\n };\n const zonesSame = sameSnapshot && interactionsSame && previous;\n const zones = zonesSame\n ? previous.zones\n : (() => {\n const objects = Object.entries(snapshot?.frame.zones ?? {}).flatMap(\n ([id, hosts]) =>\n Object.entries(hosts).map(([hostId, zone]) =>\n this.object(\n \"zone\",\n new ZoneObject(\n this,\n id,\n hostId,\n Object.freeze(\n zone.cardIds.map((cardId, index) =>\n this.object(\n \"card\",\n new CardObject(\n this,\n cardId,\n id,\n hostId,\n index,\n zone.cardViewsById[cardId],\n zone.cardBacksById[cardId],\n Object.freeze(\n (zone.playableByCardId[cardId] ?? []).map(\n (descriptor) =>\n this.object(\n \"interaction\",\n new InteractionObject(\n this,\n descriptor,\n drafts[descriptor.interactionKey] ??\n EMPTY,\n request || this.pending\n ? \"submitting\"\n : \"open\",\n connection === \"ready\",\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n Object.freeze(\n zone.tiles.map(\n (tile, index) =>\n new TileObject(\n this,\n tile,\n id,\n hostId,\n index,\n Object.freeze(\n interactionObjects.filter((interaction) =>\n interaction\n .getInputs()\n .some(\n (input) =>\n input.descriptor.domain.type ===\n \"tileTarget\" &&\n input.getIsEligible(tile.ref),\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n ),\n );\n const find = (id: string, hostId: string) =>\n objects.find((zone) => zone.id === id && zone.hostId === hostId);\n return {\n get: (id: string, hostId: string) =>\n requireLookup(find(id, hostId), \"Zone\", id),\n find,\n getAll: () => Object.freeze(objects),\n };\n })();\n const cards = zonesSame\n ? previous.cards\n : {\n get: (id: string) =>\n requireLookup(\n zones\n .getAll()\n .map((zone) => zone.findCard(id))\n .find((card) => card !== undefined),\n \"Card\",\n id,\n ),\n find: (id: string) =>\n zones\n .getAll()\n .map((zone) => zone.findCard(id))\n .find((card) => card !== undefined),\n };\n const capturedState =\n this.lastSnapshotDrafts === drafts &&\n previous?.state.activeInteraction === active\n ? previous.state\n : immutableCopy({ drafts, activeInteraction: active });\n this.lastSnapshotDrafts = drafts;\n for (const value of [players, me, interactions, inputs, zones, cards])\n if (value) Object.freeze(value);\n const model: RuntimeModel = {\n snapshot,\n view: snapshot?.frame.view ?? null,\n version: snapshot?.version ?? null,\n connection,\n request,\n failure,\n state: capturedState,\n phase:\n sameSnapshot && previous\n ? previous.phase\n : Object.freeze(\n new PhaseObject(snapshot?.frame.flow.currentPhase ?? null),\n ),\n turn:\n sameSnapshot && previous\n ? previous.turn\n : Object.freeze({\n activePlayerIds: activeIds,\n currentPlayerId: activeIds.length === 1 ? activeIds[0] : null,\n order: players.order,\n isMine: snapshot ? activeIds.includes(snapshot.me) : false,\n }),\n me,\n players,\n interactions,\n inputs,\n zones,\n cards,\n events:\n sameSnapshot && previous\n ? previous.events\n : Object.freeze({\n recent: snapshot?.frame.events ?? Object.freeze([]),\n }),\n };\n this.building = model;\n try {\n for (const [key, descriptor] of this.rootProperties)\n Object.defineProperty(model, key, {\n value: descriptor.get\n ? descriptor.get.call(this.instance)\n : descriptor.value,\n enumerable: true,\n });\n } finally {\n this.building = undefined;\n }\n return model;\n }\n refresh() {\n if (!this.store) return;\n this.store.setState((previous) => Object.freeze(this.build(previous)));\n this.warnUnread();\n }\n}\nexport function createGameInstance<G>() {\n return function <\n const F extends Features = Record<never, never>,\n S extends GameSource = GameSource,\n >(\n options: InstanceOptions<G, S> & {\n features?: (core: CoreInstance<G>, context: FeatureContext<G>) => F;\n },\n ): GameInstance<G, F, S> {\n // Composition boundary: callers bind this source and feature callbacks to G.\n // Runtime classes keep concrete descriptor contracts; only this facade exposes G/F.\n const controller = new Controller(\n options as RuntimeOptions,\n options.features as\n ((core: RuntimeCore, context: RuntimeContext) => Features) | undefined,\n );\n // eslint-disable-next-line no-restricted-syntax -- Controller construction binds this source and feature map to the public G/F/S facade.\n return controller.instance as unknown as GameInstance<G, F, S>;\n };\n}\n","import type {\n InteractionDescriptor,\n InteractionInputDescriptor,\n InputSelection,\n} from \"../shared/protocol/frame.js\";\nimport { inputDomainErrors, inputValueKey } from \"../shared/input-domain.js\";\nimport type { RuntimeJson } from \"../shared/runtime-json.js\";\n\nexport function interactionInputKeys(\n descriptor: Pick<InteractionDescriptor, \"inputs\">,\n): string[] {\n return descriptor.inputs.map((input) => input.key);\n}\n\nexport function applyInteractionInputDefaults<\n Params extends Record<string, unknown>,\n>(\n descriptor: Pick<InteractionDescriptor, \"inputs\" | \"step\">,\n params: Readonly<Partial<Params>>,\n): Partial<Params> {\n const next: Record<string, unknown> = descriptor.step\n ? Object.fromEntries(\n Object.entries(params).filter(([key]) =>\n descriptor.inputs.some((input) => input.key === key),\n ),\n )\n : { ...params };\n for (const input of descriptor.inputs) {\n if (next[input.key] !== undefined) continue;\n if (!(\"defaultValue\" in input)) continue;\n next[input.key] = input.defaultValue;\n }\n return next as Partial<Params>;\n}\n\nexport function validateInteractionInputDomains(\n descriptor: Pick<InteractionDescriptor, \"inputs\">,\n params: Readonly<Record<string, unknown>>,\n): Partial<Record<string, readonly string[]>> {\n const fieldErrors: Record<string, string[]> = {};\n\n for (const rawInput of descriptor.inputs) {\n const input = rawInput;\n const value = params[input.key];\n if (value === undefined) continue;\n for (const error of inputDomainErrors(\n input.domain,\n value,\n input.domain.selection,\n ))\n pushFieldError(fieldErrors, input.key, error);\n }\n\n return fieldErrors;\n}\n\nexport function isInputValueReady(\n input: InteractionInputDescriptor,\n value: unknown,\n): boolean {\n if (value === undefined) return false;\n if (value === null)\n return (\n input.domain.type === \"choice\" &&\n (input.domain.choices ?? []).some(\n (choice) => choice.value === null && !choice.disabled,\n )\n );\n const selection = inputSelection(input);\n if (selection?.mode !== \"many\") return true;\n return Array.isArray(value) && value.length >= selection.min;\n}\n\nexport function isManyInput(input: InteractionInputDescriptor): boolean {\n return inputSelection(input)?.mode === \"many\";\n}\n\nexport function toggleManyValue(\n current: unknown,\n value: RuntimeJson,\n selection: InputSelection,\n): RuntimeJson[] {\n if (selection.mode !== \"many\") return [value];\n const previous = Array.isArray(current) ? (current as RuntimeJson[]) : [];\n const existing = previous.findIndex((item) => sameValue(item, value));\n if (existing >= 0) {\n return previous.filter((item) => !sameValue(item, value));\n }\n if (selection.max !== undefined && previous.length >= selection.max) {\n return previous;\n }\n return [...previous, value];\n}\n\nexport function isManyTargetSelectable(\n input: InteractionInputDescriptor,\n current: unknown,\n targetId: RuntimeJson,\n): boolean {\n const selection = inputSelection(input);\n if (selection?.mode !== \"many\") return true;\n const currentValues = Array.isArray(current)\n ? (current as RuntimeJson[])\n : [];\n if (currentValues.some((item) => sameValue(item, targetId))) return true;\n return selection.max === undefined || currentValues.length < selection.max;\n}\n\nexport function hasInteractionFieldErrors(\n fieldErrors: Partial<Record<string, readonly string[]>>,\n): boolean {\n return Object.values(fieldErrors).some(\n (messages) => (messages?.length ?? 0) > 0,\n );\n}\n\nexport function inputByKey(\n descriptor: Pick<InteractionDescriptor, \"inputs\">,\n key: string,\n): InteractionInputDescriptor | undefined {\n return descriptor.inputs.find((input) => input.key === key);\n}\n\nexport function inputSelection(\n input: InteractionInputDescriptor,\n): InputSelection | undefined {\n if (input.domain.selection) return input.domain.selection;\n // choiceList is already an array domain; expose its selection bounds for toggling and reconciliation.\n if (input.domain.type === \"choiceList\")\n return {\n mode: \"many\",\n min: input.domain.min ?? 0,\n max: input.domain.max ?? input.domain.choices.length,\n };\n return undefined;\n}\n\nfunction pushFieldError(\n fieldErrors: Record<string, string[]>,\n key: string,\n message: string,\n): void {\n fieldErrors[key] = [...(fieldErrors[key] ?? []), message];\n}\n\nfunction sameValue(left: RuntimeJson, right: RuntimeJson): boolean {\n return inputValueKey(left) === inputValueKey(right);\n}\n","import type { InteractionDescriptor } from \"../shared/protocol/frame.js\";\nimport {\n applyInteractionInputDefaults,\n hasInteractionFieldErrors,\n inputByKey,\n interactionInputKeys,\n inputSelection,\n isInputValueReady,\n toggleManyValue,\n validateInteractionInputDomains,\n} from \"./interaction-inputs.js\";\nimport type { RuntimeJson } from \"../shared/runtime-json.js\";\n\nexport interface InteractionDraftMutation {\n key: string;\n value: unknown;\n}\n\nexport interface InteractionDraftReadiness {\n values: Record<string, unknown>;\n missingInputs: readonly string[];\n fieldErrors: Partial<Record<string, readonly string[]>>;\n ready: boolean;\n}\n\nexport interface RoutedInteractionTarget {\n inputKey: string;\n value: RuntimeJson;\n extraInputs?: Record<string, unknown>;\n}\n\nexport interface RoutedCardInputIntent {\n cardInputKey: string;\n cardId: string;\n dropTarget?: {\n inputKey: string;\n value: RuntimeJson;\n };\n}\n\nexport interface RoutedInteractionTargetResult {\n params: Record<string, unknown>;\n readiness: InteractionDraftReadiness;\n}\n\nexport function applyInteractionDraftMutation(\n store: DraftStore,\n descriptor: InteractionDescriptor,\n mutations: readonly InteractionDraftMutation[],\n): Record<string, unknown> {\n const originalDraft: Record<string, unknown> = {\n ...store.getDraft(descriptor.interactionKey),\n };\n const nextDraft: Record<string, unknown> = {\n ...originalDraft,\n };\n\n const currentKeys = new Set(interactionInputKeys(descriptor));\n for (const { key, value } of mutations) {\n if (!descriptor.step || currentKeys.has(key)) nextDraft[key] = value;\n }\n if (descriptor.step) {\n for (const key of Object.keys(nextDraft))\n if (!currentKeys.has(key)) delete nextDraft[key];\n }\n\n const allKeys = new Set([\n ...Object.keys(originalDraft),\n ...Object.keys(nextDraft),\n ]);\n for (const key of allKeys) {\n if (!(key in nextDraft)) {\n store.clearInput(descriptor.interactionKey, key);\n continue;\n }\n if (originalDraft[key] !== nextDraft[key]) {\n store.setInput(descriptor.interactionKey, key, nextDraft[key]);\n }\n }\n\n return nextDraft;\n}\n\nexport function getInteractionDraftReadiness(\n descriptor: InteractionDescriptor,\n draft: Readonly<Record<string, unknown>>,\n): InteractionDraftReadiness {\n const values = applyInteractionInputDefaults<Record<string, unknown>>(\n descriptor,\n draft,\n ) as Record<string, unknown>;\n const missingInputs = interactionInputKeys(descriptor).filter((key) => {\n const input = inputByKey(descriptor, key);\n const value = values[key];\n return input\n ? !isInputValueReady(input, value)\n : value === null || value === undefined;\n });\n const fieldErrors = validateInteractionInputDomains(descriptor, values);\n return {\n values,\n missingInputs,\n fieldErrors,\n ready:\n missingInputs.length === 0 && !hasInteractionFieldErrors(fieldErrors),\n };\n}\n\nexport function routeInteractionTarget(\n store: DraftStore,\n descriptor: InteractionDescriptor,\n target: RoutedInteractionTarget,\n): RoutedInteractionTargetResult {\n const input = inputByKey(descriptor, target.inputKey);\n const currentDraft = store.getDraft(descriptor.interactionKey);\n const selection = input ? inputSelection(input) : undefined;\n const targetValue =\n selection?.mode === \"many\"\n ? toggleManyValue(\n currentDraft[target.inputKey] ?? input?.defaultValue,\n target.value,\n selection,\n )\n : target.value;\n const params = applyInteractionDraftMutation(store, descriptor, [\n ...Object.entries(target.extraInputs ?? {}).map(([key, value]) => ({\n key,\n value,\n })),\n { key: target.inputKey, value: targetValue },\n ]);\n return {\n params,\n readiness: getInteractionDraftReadiness(descriptor, params),\n };\n}\n\nexport function routeCardInputIntent(\n store: DraftStore,\n descriptor: InteractionDescriptor,\n intent: RoutedCardInputIntent,\n): RoutedInteractionTargetResult {\n return routeInteractionTarget(store, descriptor, {\n inputKey: intent.cardInputKey,\n value: intent.cardId,\n extraInputs: intent.dropTarget\n ? { [intent.dropTarget.inputKey]: intent.dropTarget.value }\n : undefined,\n });\n}\n\nexport function shouldAutoSubmitInteraction(\n descriptor: InteractionDescriptor,\n): boolean {\n return (\n descriptor.commit.mode === \"autoWhenReady\" &&\n !descriptor.inputs.some((input) => input.domain.selection?.mode === \"many\")\n );\n}\n\ninterface DraftStore {\n getDraft(key: string): Record<string, unknown>;\n setInput(interaction: string, key: string, value: unknown): void;\n clearInput(interaction: string, key: string): void;\n}\n","import type { Point } from \"./features/pointer-session.js\";\n\n/** Measured with emulated touch; confirm on physical devices before changing. */\nexport const GESTURE_THRESHOLDS = Object.freeze({\n /** Movement, in CSS pixels, before a press becomes a drag or a browse. */\n slop: 8,\n /** A touch or pen held this long without moving inspects the card. */\n holdMs: 350,\n /** A mouse resting on a card this long inspects it. */\n hoverMs: 250,\n /** A finger drags when upward travel exceeds this multiple of sideways travel. */\n axisBias: 1.25,\n});\n\nexport interface GesturePointer {\n readonly pointerId: number;\n readonly pointerType: string;\n readonly clientX: number;\n readonly clientY: number;\n}\n\n/**\n * How a press ended. A tap leaves selection to the native click; a hold\n * inspected the card; a browse handed sideways movement to native scrolling.\n */\nexport type GestureKind = \"tap\" | \"hold\" | \"drag\" | \"browse\";\n\nexport interface GestureCallbacks {\n /** A touch or pen stayed still for `holdMs`. */\n hold(): void;\n /** Return false when the card cannot be dragged; the press then browses. */\n dragStart(origin: Point): boolean;\n dragMove(point: Point): void;\n /** The pointer lifted. */\n end(kind: GestureKind, point: Point): void;\n /** The browser or the caller cancelled. A cancelled drag never drops. */\n cancel(kind: GestureKind): void;\n}\n\nexport interface GestureRecognizer {\n move(event: GesturePointer): void;\n up(event: GesturePointer): void;\n cancel(event?: Pick<GesturePointer, \"pointerId\">): void;\n}\n\nexport interface GestureOptions {\n /** Hands keep sideways scrolling; piles can be dragged toward any destination. */\n readonly dragDirection?: \"up\" | \"any\";\n}\n\n/**\n * Classifies one press. A mouse drags in any direction and never holds. A\n * finger drags upward, browses sideways and holds when still, so cards can use\n * `touch-action: pan-x` and keep native sideways scrolling.\n */\nexport function createGestureRecognizer(\n down: GesturePointer,\n callbacks: GestureCallbacks,\n options: GestureOptions = {},\n): GestureRecognizer {\n const origin = { x: down.clientX, y: down.clientY };\n const mouse = down.pointerType === \"mouse\";\n let kind: GestureKind = \"tap\";\n let finished = false;\n const holdTimer = mouse\n ? undefined\n : setTimeout(() => {\n kind = \"hold\";\n callbacks.hold();\n }, GESTURE_THRESHOLDS.holdMs);\n const point = (event: GesturePointer) => ({\n x: event.clientX,\n y: event.clientY,\n });\n const ours = (event?: Pick<GesturePointer, \"pointerId\">) =>\n !finished && (!event || event.pointerId === down.pointerId);\n function finish() {\n finished = true;\n clearTimeout(holdTimer);\n }\n return {\n move(event) {\n if (!ours(event)) return;\n if (kind === \"drag\") return callbacks.dragMove(point(event));\n const dx = event.clientX - origin.x;\n const dy = event.clientY - origin.y;\n if (kind !== \"tap\" || Math.hypot(dx, dy) < GESTURE_THRESHOLDS.slop)\n return;\n clearTimeout(holdTimer);\n const lifts =\n mouse ||\n options.dragDirection === \"any\" ||\n -dy > GESTURE_THRESHOLDS.axisBias * Math.abs(dx);\n if (lifts && callbacks.dragStart(origin)) {\n kind = \"drag\";\n callbacks.dragMove(point(event));\n } else kind = \"browse\";\n },\n up(event) {\n if (!ours(event)) return;\n finish();\n callbacks.end(kind, point(event));\n },\n cancel(event) {\n if (!ours(event)) return;\n finish();\n callbacks.cancel(kind);\n },\n };\n}\n\n/** Magnetic rectangular UI targets. A wider exit band prevents edge flicker.\n * Call only for eligible targets; SVG board spaces keep native hit testing. */\nexport function magneticDropPoint(\n point: Point,\n box: { x: number; y: number; width: number; height: number },\n retained: boolean,\n coarse: boolean,\n): Point | null {\n const radius = coarse ? (retained ? 52 : 28) : retained ? 36 : 18;\n if (box.width <= 0 || box.height <= 0) return null;\n const x = Math.max(box.x, Math.min(point.x, box.x + box.width));\n const y = Math.max(box.y, Math.min(point.y, box.y + box.height));\n return Math.hypot(point.x - x, point.y - y) <= radius ? { x, y } : null;\n}\n","import { inputValueKey } from \"../shared/input-domain.js\";\nimport type { RuntimeDropTarget } from \"./targets.js\";\n\n/** Targets are rebuilt with every frame; compare their route and destination. */\nexport function isSameDropTarget(\n left: RuntimeDropTarget,\n right: RuntimeDropTarget,\n): boolean {\n if (\n left.interactionKey !== right.interactionKey ||\n left.cardInputKey !== right.cardInputKey\n )\n return false;\n if (left.kind === \"interaction\" || right.kind === \"interaction\")\n return left.kind === right.kind;\n return (\n left.kind === right.kind &&\n left.valueKind === right.valueKind &&\n inputValueKey(left.value) === inputValueKey(right.value) &&\n (left.valueKind !== \"board-id\" ||\n (right.valueKind === \"board-id\" && left.boardId === right.boardId)) &&\n left.inputKey === right.inputKey\n );\n}\n"],"mappings":";;;;;;;;;;;AAiBO,IAAM,kBAAkB,uBAAO,iBAAiB;;;AC+BvD,SAAS,cACP,QACA,OACwB;AACxB,QAAM,SACJ,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC/D,QACA,CAAC;AACP,SAAO,OAAO;AAAA,IACZ,OAAO,UAAU,IAAI,CAAC,aAAa;AACjC,YAAM,SAAS,OAAO,SAAS,UAAU;AACzC,aAAO,CAAC,SAAS,YAAY,OAAO,WAAW,WAAW,SAAS,CAAC;AAAA,IACtE,CAAC;AAAA,EACH;AACF;AACO,SAAS,mBACd,OACA,OACc;AACd,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,UAAU,MAAM,SAAS;AAC/B,QAAM,SAAS,EAAE,KAAK,MAAM,KAAK,UAAU,MAAM,UAAU,MAAM;AACjE,MAAI,OAAO,SAAS,iBAAiB;AACnC,QAAI,OAAO,WAAW,SAAS;AAC7B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN;AAAA,QACA,MAAM;AAAA,QACN,OAAO,MAAM,QAAQ,OAAO,IACxB,QAAQ;AAAA,UACN,CAAC,UAA2B,OAAO,UAAU;AAAA,QAC/C,IACA,CAAC;AAAA,QACL,UAAU,CAAC,UAAU,MAAM,SAAS,KAAK;AAAA,MAC3C;AACF,WAAO;AAAA,MACL,GAAG;AAAA,MACH,MAAM;AAAA,MACN;AAAA,MACA,MAAM;AAAA,MACN,OAAO,OAAO,YAAY,WAAW,UAAU;AAAA,MAC/C,UAAU,CAAC,UACT,UAAU,SAAY,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cACjB,MAAM,cAAc,cAAc,KAAK,YAAY,MAAM,YAC5D,KAAK,aAAa,MAAM;AAE5B;","names":["card","tile","data","options","input"]}
@@ -483,22 +483,32 @@ function createSourceLifecycle(options) {
483
483
  fail(new Error("Gameplay authority session changed."));
484
484
  return;
485
485
  }
486
- if (parsed.basis.perspectivePlayerId !== context.playerId) {
486
+ const changedSeat = parsed.basis.perspectivePlayerId !== context.playerId;
487
+ if (changedSeat && !options.followHostSeat) {
487
488
  fail(new Error("Gameplay perspective changed."));
488
489
  return;
489
490
  }
490
- if (!session.players.some((player) => player.playerId === context.playerId)) {
491
+ if (!session.players.some(
492
+ (player) => player.playerId === parsed.basis.perspectivePlayerId
493
+ )) {
491
494
  fail(new Error("Gameplay seat is absent from session."));
492
495
  return;
493
496
  }
494
497
  if (basis && parsed.basis.version < basis.version) return;
498
+ if (changedSeat) {
499
+ clearTimer();
500
+ pending?.reject(new Error("Gameplay perspective changed."));
501
+ pending = null;
502
+ recovered = false;
503
+ context = { ...context, playerId: parsed.basis.perspectivePlayerId };
504
+ }
495
505
  const { basis: nextBasis, ...frame } = immutableCopy(
496
506
  withCardImageUrls(parsed, assetUrls)
497
507
  );
498
508
  basis = nextBasis;
499
509
  publish({
500
510
  failure: null,
501
- request: store.get().request,
511
+ request: changedSeat ? null : store.get().request,
502
512
  snapshot: Object.freeze({
503
513
  me: context.playerId,
504
514
  players: session.players,
@@ -622,4 +632,4 @@ export {
622
632
  digestPluginCommandRequest,
623
633
  materializePluginGameplayFrame
624
634
  };
625
- //# sourceMappingURL=chunk-D3F3GCMF.js.map
635
+ //# sourceMappingURL=chunk-YUEMDRIH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/protocol/protocol.ts","../src/shared/protocol/schema.ts","../src/headless/sources/static.ts","../src/shared/protocol/digest.ts","../src/shared/protocol/projection.ts","../src/headless/sources/lifecycle.ts"],"sourcesContent":["import type {\n GameplayBasis,\n InteractionDescriptor,\n PluginGameplayFrame,\n PluginSessionDescriptor,\n} from \"./frame.js\";\nimport type { RuntimeJson } from \"../runtime-json.js\";\n\nexport const DREAMBOARD_PLUGIN_PROTOCOL = \"dreamboard-plugin\" as const;\nexport const DREAMBOARD_PLUGIN_PROTOCOL_VERSION = 10 as const;\n\nexport type InteractionResult =\n | {\n readonly type: \"interaction.result\";\n readonly clientActionId: string;\n readonly accepted: true;\n }\n | {\n readonly type: \"interaction.result\";\n readonly clientActionId: string;\n readonly accepted: false;\n readonly errorCode: string;\n readonly message?: string;\n };\n\nexport interface SubmitInteractionCommand {\n readonly type: \"interaction.submit\";\n readonly clientActionId: string;\n readonly basis: GameplayBasis;\n readonly interactionId: string;\n readonly params: RuntimeJson;\n}\n\nexport interface CancelInteractionCommand {\n readonly type: \"interaction.cancel\";\n readonly clientActionId: string;\n readonly basis: GameplayBasis;\n readonly interactionId: string;\n}\n\nexport type HostToPluginPayload =\n | {\n readonly type: \"runtime.init\";\n readonly session: PluginSessionDescriptor;\n }\n | {\n readonly type: \"gameplay.frame\";\n readonly frame: PluginGameplayFrame;\n }\n | InteractionResult;\n\nexport type PluginToHostPayload =\n | { readonly type: \"runtime.ready\" }\n | { readonly type: \"runtime.resume\" }\n | {\n readonly type: \"runtime.ack\";\n /** Echoes the host envelope sequence. It is delivery order only. */\n readonly sequence: number;\n readonly clientReceivedAtMs?: number;\n readonly clientRenderedAtMs?: number;\n }\n | SubmitInteractionCommand\n | CancelInteractionCommand\n | {\n readonly type: \"runtime.error\";\n readonly message: string;\n readonly code?: string;\n };\n\nexport interface PluginProtocolEnvelope<Payload> {\n readonly protocol: typeof DREAMBOARD_PLUGIN_PROTOCOL;\n readonly version: typeof DREAMBOARD_PLUGIN_PROTOCOL_VERSION;\n readonly channelId: string;\n /** Delivery order only. It is not a game revision. */\n readonly sequence: number;\n readonly payload: Payload;\n}\n\nexport type HostToPluginEnvelope = PluginProtocolEnvelope<HostToPluginPayload>;\nexport type PluginToHostEnvelope = PluginProtocolEnvelope<PluginToHostPayload>;\n\nexport type ActionSetVersionInput = {\n readonly version: number;\n readonly availableInteractions: readonly InteractionDescriptor[];\n};\n","import { PlayerIdSchema } from \"../domain/player-identity.js\";\nimport { ViewCardSchema } from \"../domain/cards.js\";\nimport * as ReducerWireZod from \"../runtime-schema\";\nimport * as z from \"zod\";\nimport {\n DREAMBOARD_PLUGIN_PROTOCOL,\n DREAMBOARD_PLUGIN_PROTOCOL_VERSION,\n} from \"./protocol.js\";\nimport { RuntimeJsonSchema } from \"../runtime-json.js\";\nimport {\n BoardProjectionSchema,\n ProjectedTileSchema,\n} from \"../seat-topology-schema.js\";\nimport type {\n GameOutcome,\n GameplayBasis,\n PluginGameplayFrame,\n PluginSessionDescriptor,\n ZoneHandlesSnapshot,\n} from \"./frame.js\";\nimport type {\n HostToPluginPayload,\n InteractionResult,\n PluginProtocolEnvelope,\n PluginToHostPayload,\n} from \"./protocol.js\";\n\nexport const GameEventDetailSchema =\n ReducerWireZod.ProjectedGameEventDetailSchema;\nexport const SystemActionEventSchema = ReducerWireZod.SystemActionEventSchema;\nexport const GameEventSchema = ReducerWireZod.ProjectedGameEventSchema;\nexport const SeatProjectionBundleSchema =\n ReducerWireZod.SeatProjectionBundleSchema;\n\nexport { PlayerIdSchema } from \"../domain/player-identity.js\";\n\nexport const PluginPlayerSummarySchema = z\n .object({\n playerId: PlayerIdSchema,\n displayName: z.string(),\n color: z.string().optional(),\n })\n .strict();\n\nexport const PluginSessionDescriptorSchema = z\n .object({\n sessionId: z.string().min(1),\n players: z.array(PluginPlayerSummarySchema),\n assets: z.record(z.string(), z.instanceof(Blob)).optional(),\n })\n .strict() satisfies z.ZodType<PluginSessionDescriptor>;\n\nexport {\n InteractionCommitPolicySchema,\n InputSelectionSchema,\n InputDomainSchema,\n InteractionChoiceOptionSchema,\n InteractionInputDescriptorSchema,\n InteractionAvailabilitySchema,\n InteractionDescriptorSchema,\n} from \"../interaction-schema.js\";\nimport { InteractionDescriptorSchema } from \"../interaction-schema.js\";\n\nexport const ZoneHandlesSnapshotSchema = z\n .object({\n tiles: z.array(ProjectedTileSchema),\n cardIds: z.array(z.string()),\n cardViewsById: z.record(z.string(), ViewCardSchema),\n cardBacksById: z.record(z.string(), z.string()),\n playableByCardId: z.record(\n z.string(),\n z.array(InteractionDescriptorSchema),\n ),\n })\n .strict() satisfies z.ZodType<ZoneHandlesSnapshot>;\n\nexport const SimultaneousPhaseSnapshotSchema =\n ReducerWireZod.SimultaneousPhaseProjectionSchema;\n\nexport const GameplayBasisSchema = z\n .object({\n sessionId: z.string().min(1),\n version: z.number().int().nonnegative(),\n actionSetVersion: z.string().min(1),\n perspectivePlayerId: PlayerIdSchema,\n })\n .strict() satisfies z.ZodType<GameplayBasis>;\n\nexport const GameOutcomeSchema =\n ReducerWireZod.GameOutcomeSchema satisfies z.ZodType<GameOutcome>;\n\nconst ProjectedViewSchema = z\n .record(z.string(), RuntimeJsonSchema)\n .superRefine((view, context) => {\n if (!Object.hasOwn(view, \"boards\")) return;\n const boards = BoardProjectionSchema.safeParse(view.boards);\n if (!boards.success) {\n for (const issue of boards.error.issues) {\n context.addIssue({\n code: \"custom\",\n path: [\"boards\", ...issue.path],\n message: issue.message,\n });\n }\n }\n });\n\nexport const SeatFrameSchema = z\n .object({\n events: z.array(GameEventSchema).max(32),\n view: ProjectedViewSchema.nullable(),\n flow: z\n .object({\n currentPhase: z.string().nullable(),\n activePlayers: z.array(PlayerIdSchema),\n simultaneousPhase: SimultaneousPhaseSnapshotSchema.nullable(),\n })\n .strict(),\n availableInteractions: z.array(InteractionDescriptorSchema),\n zones: z.record(\n z.string(),\n z.record(z.string(), ZoneHandlesSnapshotSchema),\n ),\n })\n .strict();\n\nexport const PluginGameplayFrameSchema = SeatFrameSchema.extend({\n basis: GameplayBasisSchema,\n}) satisfies z.ZodType<PluginGameplayFrame>;\n\nexport const InteractionResultSchema = z.discriminatedUnion(\"accepted\", [\n z\n .object({\n type: z.literal(\"interaction.result\"),\n clientActionId: z.string().min(1),\n accepted: z.literal(true),\n })\n .strict(),\n z\n .object({\n type: z.literal(\"interaction.result\"),\n clientActionId: z.string().min(1),\n accepted: z.literal(false),\n errorCode: z.string().min(1),\n message: z.string().optional(),\n })\n .strict(),\n]) satisfies z.ZodType<InteractionResult>;\n\nexport const SubmitInteractionCommandSchema = z\n .object({\n type: z.literal(\"interaction.submit\"),\n clientActionId: z.string().min(1),\n basis: GameplayBasisSchema,\n interactionId: z.string().min(1),\n params: RuntimeJsonSchema,\n })\n .strict();\n\nexport const CancelInteractionCommandSchema =\n SubmitInteractionCommandSchema.omit({ params: true })\n .extend({ type: z.literal(\"interaction.cancel\") })\n .strict();\n\nexport const HostToPluginPayloadSchema = z.discriminatedUnion(\"type\", [\n z\n .object({\n type: z.literal(\"runtime.init\"),\n session: PluginSessionDescriptorSchema,\n })\n .strict(),\n z\n .object({\n type: z.literal(\"gameplay.frame\"),\n frame: PluginGameplayFrameSchema,\n })\n .strict(),\n InteractionResultSchema,\n]) satisfies z.ZodType<HostToPluginPayload>;\n\nexport const PluginToHostPayloadSchema = z.discriminatedUnion(\"type\", [\n z.object({ type: z.literal(\"runtime.ready\") }).strict(),\n z.object({ type: z.literal(\"runtime.resume\") }).strict(),\n z\n .object({\n type: z.literal(\"runtime.ack\"),\n sequence: z.number().int().nonnegative(),\n clientReceivedAtMs: z.number().finite().optional(),\n clientRenderedAtMs: z.number().finite().optional(),\n })\n .strict(),\n SubmitInteractionCommandSchema,\n CancelInteractionCommandSchema,\n z\n .object({\n type: z.literal(\"runtime.error\"),\n message: z.string(),\n code: z.string().optional(),\n })\n .strict(),\n]) satisfies z.ZodType<PluginToHostPayload>;\n\nexport function createPluginProtocolEnvelopeSchema<Payload>(\n payloadSchema: z.ZodType<Payload>,\n): z.ZodType<PluginProtocolEnvelope<Payload>> {\n return z\n .object({\n protocol: z.literal(DREAMBOARD_PLUGIN_PROTOCOL),\n version: z.literal(DREAMBOARD_PLUGIN_PROTOCOL_VERSION),\n channelId: z.string().min(1),\n sequence: z.number().int().nonnegative(),\n payload: payloadSchema,\n })\n .strict();\n}\n\nexport const HostToPluginEnvelopeSchema = createPluginProtocolEnvelopeSchema(\n HostToPluginPayloadSchema,\n);\n\nexport const PluginToHostEnvelopeSchema = createPluginProtocolEnvelopeSchema(\n PluginToHostPayloadSchema,\n);\n\nexport function parsePluginSessionDescriptor(\n value: unknown,\n): PluginSessionDescriptor {\n return PluginSessionDescriptorSchema.parse(value);\n}\n\nexport function parsePluginGameplayFrame(value: unknown): PluginGameplayFrame {\n return PluginGameplayFrameSchema.parse(value);\n}\n\nexport function parseHostToPluginEnvelope(\n value: unknown,\n): PluginProtocolEnvelope<HostToPluginPayload> {\n return HostToPluginEnvelopeSchema.parse(value);\n}\n\nexport function parsePluginToHostEnvelope(\n value: unknown,\n): PluginProtocolEnvelope<PluginToHostPayload> {\n return PluginToHostEnvelopeSchema.parse(value);\n}\n","import { createStore } from \"@tanstack/store\";\nimport * as z from \"zod\";\nimport {\n SeatFrameSchema,\n PluginPlayerSummarySchema,\n} from \"../../shared/protocol/schema.js\";\nimport { immutableCopy } from \"../../shared/immutable.js\";\nimport type { GameSource, SourceSnapshot, SourceState } from \"./types.js\";\n\nexport const SourceSnapshotSchema = z\n .object({\n me: z.string().min(1),\n players: z.array(PluginPlayerSummarySchema),\n frame: SeatFrameSchema,\n version: z.number().int().nonnegative(),\n })\n .strict();\n\n/** A read-only fixture source accepts the public seat snapshot, never wire basis. */\nexport function staticSource(input: SourceSnapshot): GameSource {\n const snapshot = immutableCopy(SourceSnapshotSchema.parse(input));\n if (!snapshot.players.some((player) => player.playerId === snapshot.me))\n throw new Error(\"Gameplay seat is absent from session.\");\n const store = createStore<SourceState>(\n Object.freeze({\n snapshot,\n connection: \"ready\",\n request: null,\n failure: null,\n }),\n );\n return {\n store: {\n get: () => store.get(),\n subscribe: (listener) => store.subscribe(listener),\n },\n dispose() {\n store.setState((state) =>\n Object.freeze({\n snapshot: state.snapshot,\n connection: \"closed\",\n request: null,\n failure: null,\n }),\n );\n },\n };\n}\n","import type { PluginGameplayFrame } from \"./frame.js\";\nimport {\n type ActionSetVersionInput,\n type SubmitInteractionCommand,\n type CancelInteractionCommand,\n} from \"./protocol.js\";\nimport {\n canonicalizePluginRuntimeJson,\n digestPluginRuntimeJson,\n encodeCanonicalPluginRuntimeJson,\n} from \"./json.js\";\n\nexport {\n canonicalizePluginRuntimeJson,\n digestPluginRuntimeJson,\n encodeCanonicalPluginRuntimeJson,\n};\n\nexport function computePluginActionSetVersion(\n input: ActionSetVersionInput,\n): string {\n return digestPluginRuntimeJson({\n digestVersion: \"plugin-action-set@6\",\n version: input.version,\n availableInteractions: input.availableInteractions,\n });\n}\n\nexport function digestPluginGameplayFrame(frame: PluginGameplayFrame): string {\n return digestPluginRuntimeJson({\n digestVersion: \"plugin-gameplay-frame@6\",\n frame,\n });\n}\n\nexport function digestPluginCommandRequest(\n command: SubmitInteractionCommand | CancelInteractionCommand,\n): string {\n return digestPluginRuntimeJson({\n digestVersion: \"plugin-command-request@6\",\n command,\n });\n}\n","import { canonicalizePluginRuntimeJson } from \"./json\";\nimport {\n PluginGameplayFrameSchema,\n SeatProjectionBundleSchema,\n} from \"./schema.js\";\nimport type {\n InteractionDescriptor,\n PlayerId,\n PluginGameplayFrame,\n ReducerSeatProjectionBundle,\n ZoneHandlesSnapshot,\n} from \"./frame.js\";\nimport type { RuntimeJson } from \"../runtime-json.js\";\n\nexport interface MaterializePluginGameplayFrameInput {\n readonly currentPhase: string | null;\n readonly activePlayers: readonly PlayerId[];\n readonly dynamicProjection: ReducerSeatProjectionBundle;\n readonly perspectivePlayerId: PlayerId;\n\n readonly sessionId: string;\n readonly version: number;\n readonly actionSetVersion: string;\n}\n\nexport function materializePluginGameplayFrame(\n input: MaterializePluginGameplayFrameInput,\n): PluginGameplayFrame {\n const dynamicProjection = SeatProjectionBundleSchema.parse(\n canonicalizePluginRuntimeJson(input.dynamicProjection),\n );\n if (\n dynamicProjection.referenceBasis.sessionId !== input.sessionId ||\n dynamicProjection.referenceBasis.version !== input.version\n ) {\n throw new Error(\n \"Projection reference basis does not match the frame basis.\",\n );\n }\n const registry = dynamicProjection.interactionsByRef ?? {};\n const seat = dynamicProjection.seats[input.perspectivePlayerId] ?? null;\n\n const availableInteractions =\n seat == null\n ? []\n : hydrateInteractionRefs(\n registry,\n seat.availableInteractionRefs ?? [],\n \"availableInteractionRefs\",\n );\n const zones =\n seat?.zones == null ? {} : hydrateZones(registry, seat.zones, \"zones\");\n\n const frame = {\n events: seat?.events ?? [],\n basis: {\n sessionId: input.sessionId,\n version: input.version,\n actionSetVersion: input.actionSetVersion,\n perspectivePlayerId: input.perspectivePlayerId,\n },\n view: materializeView(seat?.view, seat?.boards),\n flow: {\n currentPhase: input.currentPhase,\n activePlayers: [...input.activePlayers],\n simultaneousPhase: dynamicProjection.simultaneousPhase ?? null,\n },\n availableInteractions,\n zones,\n } satisfies PluginGameplayFrame;\n\n return PluginGameplayFrameSchema.parse(frame);\n}\n\nfunction materializeView(\n seatView: unknown,\n seatBoards: ReducerSeatProjectionBundle[\"seats\"][string][\"boards\"],\n): RuntimeJson | null {\n const parts = [\n seatView,\n seatBoards === undefined ? undefined : { boards: seatBoards },\n ].filter((part) => part !== undefined && part !== null);\n if (parts.length === 0) return null;\n // Admitting schemas guarantee records and reject authored `boards` fields.\n return Object.assign({}, ...parts) as Record<string, RuntimeJson>;\n}\n\nfunction hydrateZones(\n registry: Readonly<Record<string, InteractionDescriptor>>,\n value: NonNullable<ReducerSeatProjectionBundle[\"seats\"][string][\"zones\"]>,\n path: string,\n): Record<string, Record<string, ZoneHandlesSnapshot>> {\n return Object.fromEntries(\n Object.entries(value).map(([zoneId, hosts]) => [\n zoneId,\n Object.fromEntries(\n Object.entries(hosts).map(([hostId, zone]) => [\n hostId,\n {\n tiles: zone.tiles,\n cardIds: zone.cardIds,\n cardViewsById: zone.cardViewsById,\n cardBacksById: zone.cardBacksById,\n playableByCardId: Object.fromEntries(\n Object.entries(zone.playableByCardId).map(([cardId, refs]) => [\n cardId,\n hydrateInteractionRefs(\n registry,\n refs,\n `${path}.${zoneId}.${hostId}.playableByCardId.${cardId}`,\n ),\n ]),\n ),\n },\n ]),\n ),\n ]),\n );\n}\n\nfunction hydrateInteractionRefs(\n registry: Readonly<Record<string, InteractionDescriptor>>,\n value: readonly string[],\n path: string,\n): InteractionDescriptor[] {\n return value.map((ref, index) => {\n const descriptor = registry[ref];\n if (!descriptor) {\n throw new Error(\n `Seat projection ${path}[${index}] references '${ref}', which is missing from interactionsByRef.`,\n );\n }\n return descriptor;\n });\n}\n","import { createStore } from \"@tanstack/store\";\nimport {\n PluginGameplayFrameSchema,\n PluginSessionDescriptorSchema,\n InteractionResultSchema,\n PluginToHostPayloadSchema,\n} from \"../../shared/protocol/schema.js\";\nimport type {\n GameplayBasis,\n PluginGameplayFrame,\n PluginSessionDescriptor,\n} from \"../../shared/protocol/frame.js\";\nimport { immutableCopy } from \"../../shared/immutable.js\";\nimport type {\n CommandSource,\n SourceCommand,\n SourceContext,\n SourceState,\n SubmitResult,\n} from \"./types.js\";\n\ninterface Pending {\n readonly command: SourceCommand;\n readonly resolve: (result: SubmitResult) => void;\n readonly reject: (error: Error) => void;\n accepted: boolean;\n}\n\n/** Adapter-private lifecycle. Transport callbacks must belong to this lifetime. */\nexport function createSourceLifecycle(options: {\n context?: SourceContext;\n send(command: SourceCommand): void;\n recover(): void;\n close(): void;\n timeoutMs?: number;\n followHostSeat?: boolean;\n}) {\n let context = options.context ? immutableCopy(options.context) : null;\n const store = createStore<SourceState>(\n Object.freeze({\n snapshot: null,\n connection: \"connecting\",\n request: null,\n failure: null,\n }),\n );\n let session: Omit<PluginSessionDescriptor, \"assets\"> | null = null;\n let assetUrls: Readonly<Record<string, string>> | null = null;\n let basis: GameplayBasis | null = null;\n let pending: Pending | null = null;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let recovered = false;\n let closed = false;\n const clearTimer = () => {\n clearTimeout(timer);\n timer = undefined;\n };\n const publish = (state: SourceState) => {\n if (state.request) Object.freeze(state.request);\n store.setState(() => Object.freeze(state));\n };\n const recovering = () => {\n if (closed) return;\n publish({ ...store.get(), connection: \"recovering\", failure: null });\n };\n const close = (failure: Error | null) => {\n if (closed) return;\n closed = true;\n clearTimer();\n for (const url of Object.values(assetUrls ?? {})) URL.revokeObjectURL(url);\n pending?.reject(failure ?? new Error(\"Gameplay source disposed.\"));\n pending = null;\n options.close();\n const snapshot = store.get().snapshot;\n publish(\n failure\n ? {\n connection: \"failed\",\n snapshot,\n request: null,\n failure: Object.freeze(failure),\n }\n : { connection: \"closed\", snapshot, request: null, failure: null },\n );\n };\n const fail = (error: Error) => close(error);\n const arm = () => {\n clearTimer();\n timer = setTimeout(() => {\n if (recovered) {\n fail(new Error(\"Gameplay source recovery timed out.\"));\n return;\n }\n recovered = true;\n recovering();\n try {\n options.recover();\n if (pending && !pending.accepted) options.send(pending.command);\n arm();\n } catch (error) {\n fail(asError(error));\n }\n }, options.timeoutMs ?? 10_000);\n };\n const finishBarrier = () => {\n if (!pending?.accepted) return;\n const frame = store.get().snapshot;\n if (!frame || frame.version <= pending.command.basis.version) return;\n clearTimer();\n pending = null;\n publish({\n snapshot: frame,\n request: null,\n connection: \"ready\",\n failure: null,\n });\n };\n const start = async (\n operation: \"submit\" | \"cancel\",\n interactionId: string,\n params?: unknown,\n ) => {\n const state = store.get();\n if (closed || state.connection !== \"ready\" || !basis)\n return Promise.reject(new Error(\"Gameplay source is not open.\"));\n if (pending)\n return Promise.reject(\n new Error(\"A gameplay interaction is already pending.\"),\n );\n const command = immutableCopy(\n PluginToHostPayloadSchema.parse({\n type:\n operation === \"cancel\" ? \"interaction.cancel\" : \"interaction.submit\",\n clientActionId: crypto.randomUUID(),\n basis,\n interactionId,\n ...(operation === \"cancel\" ? {} : { params }),\n }) as SourceCommand,\n );\n recovered = false;\n const promise = new Promise<SubmitResult>((resolve, reject) => {\n pending = { command, resolve, reject, accepted: false };\n });\n publish({\n ...state,\n request: {\n interactionId,\n operation,\n phase: \"awaiting-result\",\n },\n });\n arm();\n try {\n options.send(command);\n } catch (error) {\n fail(asError(error));\n }\n return promise;\n };\n const source: CommandSource = {\n store: {\n get: () => store.get(),\n subscribe: (listener) => store.subscribe(listener),\n },\n submit: (interactionId, params) => start(\"submit\", interactionId, params),\n cancel: (interactionId) => start(\"cancel\", interactionId),\n dispose: () => close(null),\n };\n return {\n source,\n retry() {\n if (closed || !pending) return;\n try {\n if (pending.accepted) options.recover();\n else options.send(pending.command);\n } catch (error) {\n fail(asError(error));\n }\n },\n fail,\n recovering,\n session(value: unknown) {\n if (closed) return;\n const { assets, ...parsed } = PluginSessionDescriptorSchema.parse(value);\n if (\n (context?.sessionId ?? session?.sessionId) &&\n parsed.sessionId !== (context?.sessionId ?? session?.sessionId)\n ) {\n fail(new Error(\"Gameplay session changed.\"));\n return;\n }\n if (\n context &&\n !parsed.players.some((player) => player.playerId === context!.playerId)\n ) {\n fail(new Error(\"Gameplay seat is absent from session.\"));\n return;\n }\n session = immutableCopy(parsed);\n // Hosts repeat initialization until ready; the first delivery wins.\n assetUrls ??= Object.fromEntries(\n Object.entries(assets ?? {}).map(([path, blob]) => [\n path,\n URL.createObjectURL(blob),\n ]),\n );\n },\n frame(value: unknown) {\n if (closed) return;\n const parsed = PluginGameplayFrameSchema.parse(value);\n if (!session) {\n fail(new Error(\"Gameplay frame arrived before session metadata.\"));\n return;\n }\n context ??= {\n sessionId: session.sessionId,\n playerId: parsed.basis.perspectivePlayerId,\n };\n if (parsed.basis.sessionId !== context.sessionId) {\n fail(new Error(\"Gameplay authority session changed.\"));\n return;\n }\n const changedSeat = parsed.basis.perspectivePlayerId !== context.playerId;\n if (changedSeat && !options.followHostSeat) {\n fail(new Error(\"Gameplay perspective changed.\"));\n return;\n }\n if (\n !session.players.some(\n (player) => player.playerId === parsed.basis.perspectivePlayerId,\n )\n ) {\n fail(new Error(\"Gameplay seat is absent from session.\"));\n return;\n }\n if (basis && parsed.basis.version < basis.version) return;\n if (changedSeat) {\n clearTimer();\n pending?.reject(new Error(\"Gameplay perspective changed.\"));\n pending = null;\n recovered = false;\n context = { ...context, playerId: parsed.basis.perspectivePlayerId };\n }\n const { basis: nextBasis, ...frame } = immutableCopy(\n withCardImageUrls(parsed, assetUrls),\n );\n basis = nextBasis;\n publish({\n failure: null,\n request: changedSeat ? null : store.get().request,\n snapshot: Object.freeze({\n me: context.playerId,\n players: session.players,\n frame: Object.freeze(frame),\n version: basis.version,\n }),\n connection: \"ready\",\n });\n finishBarrier();\n },\n result(value: unknown) {\n if (closed) return;\n const result = InteractionResultSchema.parse(value);\n if (\n !pending ||\n result.clientActionId !== pending.command.clientActionId ||\n pending.accepted\n )\n return;\n pending.resolve(\n immutableCopy(\n result.accepted\n ? { accepted: true }\n : {\n accepted: false,\n errorCode: result.errorCode,\n ...(result.message === undefined\n ? {}\n : { message: result.message }),\n },\n ),\n );\n if (!result.accepted) {\n clearTimer();\n pending = null;\n publish({\n snapshot: store.get().snapshot!,\n request: null,\n connection: \"ready\",\n failure: null,\n });\n return;\n }\n pending.accepted = true;\n recovered = false;\n const state = store.get();\n // A pending command was submitted from ready, so its snapshot exists.\n publish({\n connection: state.connection === \"recovering\" ? \"recovering\" : \"ready\",\n snapshot: state.snapshot!,\n failure: null,\n request: { ...state.request!, phase: \"awaiting-frame\" },\n });\n arm();\n finishBarrier();\n },\n };\n}\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n\n/** Replaces card image paths in card views and hidden card backs with delivered URLs. */\nfunction withCardImageUrls(\n frame: PluginGameplayFrame,\n urls: Readonly<Record<string, string>> | null,\n): PluginGameplayFrame {\n if (urls === null || Object.keys(urls).length === 0) return frame;\n return {\n ...frame,\n zones: Object.fromEntries(\n Object.entries(frame.zones).map(([zoneId, hosts]) => [\n zoneId,\n Object.fromEntries(\n Object.entries(hosts).map(([hostId, zone]) => [\n hostId,\n {\n ...zone,\n cardViewsById: Object.fromEntries(\n Object.entries(zone.cardViewsById).map(([cardId, card]) => [\n cardId,\n {\n ...card,\n frontImage:\n card.frontImage === undefined\n ? undefined\n : (urls[card.frontImage] ?? card.frontImage),\n backImage:\n card.backImage === undefined\n ? undefined\n : (urls[card.backImage] ?? card.backImage),\n },\n ]),\n ),\n cardBacksById: Object.fromEntries(\n Object.entries(zone.cardBacksById).map(([cardId, path]) => [\n cardId,\n urls[path] ?? path,\n ]),\n ),\n },\n ]),\n ),\n ]),\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQO,IAAM,6BAA6B;AACnC,IAAM,qCAAqC;;;ACNlD,YAAY,OAAO;AAwBZ,IAAM,wBACI;AACV,IAAMA,2BAAyC;AAC/C,IAAM,kBAAiC;AACvC,IAAMC,8BACI;AAIV,IAAM,4BACV,SAAO;AAAA,EACN,UAAU;AAAA,EACV,aAAe,SAAO;AAAA,EACtB,OAAS,SAAO,EAAE,SAAS;AAC7B,CAAC,EACA,OAAO;AAEH,IAAM,gCACV,SAAO;AAAA,EACN,WAAa,SAAO,EAAE,IAAI,CAAC;AAAA,EAC3B,SAAW,QAAM,yBAAyB;AAAA,EAC1C,QAAU,SAAS,SAAO,GAAK,aAAW,IAAI,CAAC,EAAE,SAAS;AAC5D,CAAC,EACA,OAAO;AAaH,IAAM,4BACV,SAAO;AAAA,EACN,OAAS,QAAM,mBAAmB;AAAA,EAClC,SAAW,QAAQ,SAAO,CAAC;AAAA,EAC3B,eAAiB,SAAS,SAAO,GAAG,cAAc;AAAA,EAClD,eAAiB,SAAS,SAAO,GAAK,SAAO,CAAC;AAAA,EAC9C,kBAAoB;AAAA,IAChB,SAAO;AAAA,IACP,QAAM,2BAA2B;AAAA,EACrC;AACF,CAAC,EACA,OAAO;AAEH,IAAM,kCACI;AAEV,IAAM,sBACV,SAAO;AAAA,EACN,WAAa,SAAO,EAAE,IAAI,CAAC;AAAA,EAC3B,SAAW,SAAO,EAAE,IAAI,EAAE,YAAY;AAAA,EACtC,kBAAoB,SAAO,EAAE,IAAI,C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G,MAAM,SAAU,OAAO,iBAAiB;AAAA,MACxD,CAAC;AACD,UAAI;AACJ,oBAAc;AAAA,IAChB;AAAA,EACF;AACF;AACA,SAAS,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;AAGA,SAAS,kBACP,OACA,MACqB;AACrB,MAAI,SAAS,QAAQ,OAAO,KAAK,IAAI,EAAE,WAAW,EAAG,QAAO;AAC5D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,OAAO;AAAA,MACZ,OAAO,QAAQ,MAAM,KAAK,EAAE,IAAI,CAAC,CAAC,QAAQ,KAAK,MAAM;AAAA,QACnD;AAAA,QACA,OAAO;AAAA,UACL,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM;AAAA,YAC5C;AAAA,YACA;AAAA,cACE,GAAG;AAAA,cACH,eAAe,OAAO;AAAA,gBACpB,OAAO,QAAQ,KAAK,aAAa,EAAE,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM;AAAA,kBACzD;AAAA,kBACA;AAAA,oBACE,GAAG;AAAA,oBACH,YACE,KAAK,eAAe,SAChB,SACC,KAAK,KAAK,UAAU,KAAK,KAAK;AAAA,oBACrC,WACE,KAAK,cAAc,SACf,SACC,KAAK,KAAK,SAAS,KAAK,KAAK;AAAA,kBACtC;AAAA,gBACF,CAAC;AAAA,cACH;AAAA,cACA,eAAe,OAAO;AAAA,gBACpB,OAAO,QAAQ,KAAK,aAAa,EAAE,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM;AAAA,kBACzD;AAAA,kBACA,KAAK,IAAI,KAAK;AAAA,gBAChB,CAAC;AAAA,cACH;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["SystemActionEventSchema","SeatProjectionBundleSchema","GameOutcomeSchema","z","SeatProjectionBundleSchema","createStore","createStore"]}