@dreamboard-games/sdk 0.5.0-alpha.2 → 0.5.0-alpha.3
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 +136 -45
- package/dist/chunk-DMFVAZI2.js +16 -0
- package/dist/chunk-DMFVAZI2.js.map +1 -0
- package/dist/chunk-FMM5LVJW.js +833 -0
- package/dist/chunk-FMM5LVJW.js.map +1 -0
- package/dist/{chunk-S2JEDVWH.js → chunk-LRILEVKC.js} +6113 -6489
- package/dist/chunk-LRILEVKC.js.map +1 -0
- package/dist/chunk-SP234IY4.js +1363 -0
- package/dist/chunk-SP234IY4.js.map +1 -0
- package/dist/chunk-VUWNJXLJ.js +52 -0
- package/dist/chunk-VUWNJXLJ.js.map +1 -0
- package/dist/chunk-ZPRKWPEP.js +511 -0
- package/dist/chunk-ZPRKWPEP.js.map +1 -0
- package/dist/definition-BaHNPZol.d.ts +4639 -0
- package/dist/diagnostics-B0lgnuZ6.d.ts +65 -0
- package/dist/index.d.ts +3553 -1
- package/dist/index.js +1045 -6
- package/dist/index.js.map +1 -1
- package/dist/model-BHro6yXu.d.ts +288 -0
- package/dist/react.d.ts +32 -0
- package/dist/react.js +80 -0
- package/dist/react.js.map +1 -0
- package/dist/reducer.d.ts +1194 -79
- package/dist/reducer.js +4326 -121
- package/dist/reducer.js.map +1 -1
- package/dist/testing.d.ts +518 -564
- package/dist/testing.js +2448 -915
- package/dist/testing.js.map +1 -1
- package/dist/types-DimqnJBq.d.ts +86 -0
- package/package.json +26 -131
- package/dist/HandView-Bi2lxzQP.d.ts +0 -79
- package/dist/ResourceCounter-BFxJknqp.d.ts +0 -98
- package/dist/ThemeProvider-CElaL2ik.d.ts +0 -99
- package/dist/attributes-DbvyMbXw.d.ts +0 -68
- package/dist/browser-interaction.d.ts +0 -910
- package/dist/browser-interaction.js +0 -119
- package/dist/browser-interaction.js.map +0 -1
- package/dist/chunk-32PFKDV7.js +0 -11705
- package/dist/chunk-32PFKDV7.js.map +0 -1
- package/dist/chunk-3BAD4VC2.js +0 -263
- package/dist/chunk-3BAD4VC2.js.map +0 -1
- package/dist/chunk-3SKDNDPG.js +0 -104
- package/dist/chunk-3SKDNDPG.js.map +0 -1
- package/dist/chunk-5YV2WHJ4.js +0 -25
- package/dist/chunk-5YV2WHJ4.js.map +0 -1
- package/dist/chunk-ANRB4XKA.js +0 -90
- package/dist/chunk-ANRB4XKA.js.map +0 -1
- package/dist/chunk-BI4G3PM2.js +0 -1864
- package/dist/chunk-BI4G3PM2.js.map +0 -1
- package/dist/chunk-EVCLTY4Q.js +0 -935
- package/dist/chunk-EVCLTY4Q.js.map +0 -1
- package/dist/chunk-GDPKTBUR.js +0 -564
- package/dist/chunk-GDPKTBUR.js.map +0 -1
- package/dist/chunk-H6VDGFL5.js +0 -2903
- package/dist/chunk-H6VDGFL5.js.map +0 -1
- package/dist/chunk-LR3ZTWQF.js +0 -5960
- package/dist/chunk-LR3ZTWQF.js.map +0 -1
- package/dist/chunk-PF7L4BMG.js +0 -117
- package/dist/chunk-PF7L4BMG.js.map +0 -1
- package/dist/chunk-PN5O6GG2.js +0 -32
- package/dist/chunk-PN5O6GG2.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-S2JEDVWH.js.map +0 -1
- package/dist/chunk-T3ZKNUZ7.js +0 -1
- package/dist/chunk-T3ZKNUZ7.js.map +0 -1
- package/dist/chunk-UGH54WZ2.js +0 -223
- package/dist/chunk-UGH54WZ2.js.map +0 -1
- package/dist/chunk-VCDWP5VL.js +0 -746
- package/dist/chunk-VCDWP5VL.js.map +0 -1
- package/dist/chunk-VDXOF4FW.js +0 -69
- package/dist/chunk-VDXOF4FW.js.map +0 -1
- package/dist/chunk-WHR5UW3F.js +0 -1988
- package/dist/chunk-WHR5UW3F.js.map +0 -1
- package/dist/chunk-Y75CFE77.js +0 -17
- package/dist/chunk-Y75CFE77.js.map +0 -1
- package/dist/chunk-Z7QCREWI.js +0 -3435
- package/dist/chunk-Z7QCREWI.js.map +0 -1
- package/dist/chunk-ZZGN2ATS.js +0 -1941
- package/dist/chunk-ZZGN2ATS.js.map +0 -1
- package/dist/components-gAbIz7hK.d.ts +0 -1284
- package/dist/definitions-BgmV_GhC.d.ts +0 -300
- package/dist/diagnostics-DIi3ina7.d.ts +0 -50
- package/dist/digest.d.ts +0 -8
- package/dist/game-CsZScpcn.d.ts +0 -763
- package/dist/hex-board-view-aKkblDp6.d.ts +0 -1228
- package/dist/index-CcT9Q7N7.d.ts +0 -193
- package/dist/index.d-DjzoK7zn.d.ts +0 -2101
- package/dist/package-set.d.ts +0 -13
- package/dist/package-set.js +0 -12
- package/dist/package-set.js.map +0 -1
- package/dist/player-state-Cqpyeql0.d.ts +0 -371
- package/dist/plugin-runtime-contract.d.ts +0 -17
- package/dist/plugin-runtime-contract.js +0 -92
- package/dist/plugin-runtime-contract.js.map +0 -1
- package/dist/primitive-props-BNHDkgd7.d.ts +0 -16
- package/dist/protocol-dYgafTYY.d.ts +0 -314
- package/dist/reducer/advanced.d.ts +0 -82
- package/dist/reducer/advanced.js +0 -51
- package/dist/reducer/advanced.js.map +0 -1
- package/dist/reducer-contract.d.ts +0 -11
- package/dist/reducer-contract.js +0 -16
- package/dist/reducer-contract.js.map +0 -1
- package/dist/reference-games/index.d.ts +0 -31
- package/dist/reference-games/index.js +0 -48
- package/dist/reference-games/index.js.map +0 -1
- package/dist/runtime/primitives.d.ts +0 -250
- package/dist/runtime/primitives.js +0 -189
- package/dist/runtime/primitives.js.map +0 -1
- package/dist/runtime/runtime-api.d.ts +0 -2
- package/dist/runtime/runtime-api.js +0 -1
- package/dist/runtime/runtime-api.js.map +0 -1
- package/dist/runtime/workspace-contract.d.ts +0 -392
- package/dist/runtime/workspace-contract.js +0 -28
- package/dist/runtime/workspace-contract.js.map +0 -1
- package/dist/runtime-RJ5orDJU.d.ts +0 -1699
- package/dist/runtime-api-Bz5pwNU_.d.ts +0 -296
- package/dist/runtime-json-CQ9QbLZ5.d.ts +0 -5
- package/dist/runtime.d.ts +0 -83
- package/dist/runtime.js +0 -242
- package/dist/runtime.js.map +0 -1
- package/dist/schema.d.ts +0 -379
- package/dist/stale-contract-artifact-error-XLaweZtF.d.ts +0 -18
- package/dist/testing-compiler.d.ts +0 -37
- package/dist/testing-compiler.js +0 -272
- package/dist/testing-compiler.js.map +0 -1
- package/dist/testing-runtime.d.ts +0 -119
- package/dist/testing-runtime.js +0 -212
- package/dist/testing-runtime.js.map +0 -1
- package/dist/types-DJj5MJkl.d.ts +0 -256
- package/dist/types-DR7DoB1x.d.ts +0 -28
- package/dist/types-JWCYHmu7.d.ts +0 -122
- package/dist/types.d.ts +0 -1958
- package/dist/types.js +0 -14
- package/dist/types.js.map +0 -1
- package/dist/ui/components.d.ts +0 -17
- package/dist/ui/components.js +0 -216
- package/dist/ui/components.js.map +0 -1
- package/dist/ui/defaults.d.ts +0 -19
- package/dist/ui/defaults.js +0 -104
- package/dist/ui/defaults.js.map +0 -1
- package/dist/ui/player-state.d.ts +0 -2
- package/dist/ui/player-state.js +0 -1
- package/dist/ui/player-state.js.map +0 -1
- package/dist/ui/plugin-styles.css +0 -2
- package/dist/ui-contract-GTUPkf8z.d.ts +0 -1168
- package/dist/ui.d.ts +0 -317
- package/dist/ui.js +0 -277
- package/dist/ui.js.map +0 -1
- package/dist/views-BpuWcOyN.d.ts +0 -1641
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/package-set.ts","../src/headless/sources/iframe.ts","../src/shared/protocol/gameplay-wire.ts","../src/headless/sources/host-websocket.ts","../src/headless/features/hand.ts","../src/headless/features/board.ts","../src/headless/features/pointer-session.ts","../src/headless/features/drag.ts","../src/headless/features/pan-zoom.ts"],"sourcesContent":["declare const __DREAMBOARD_SDK_VERSION__: string;\n\nexport const DREAMBOARD_SDK_VERSION =\n typeof __DREAMBOARD_SDK_VERSION__ === \"string\"\n ? __DREAMBOARD_SDK_VERSION__\n : \"0.0.0-development\";\n\nexport const DREAMBOARD_SDK_PACKAGES = {\n \"@dreamboard-games/sdk\": DREAMBOARD_SDK_VERSION,\n} as const;\n\nexport type DreamboardSdkPackageName = keyof typeof DREAMBOARD_SDK_PACKAGES;\n\nexport type DreamboardSdkPackageSet = {\n version: 1;\n sdkVersion: string;\n packages: Record<DreamboardSdkPackageName, string>;\n};\n\nexport const DREAMBOARD_SDK_PACKAGE_SET: DreamboardSdkPackageSet = {\n version: 1,\n sdkVersion: DREAMBOARD_SDK_VERSION,\n packages: DREAMBOARD_SDK_PACKAGES,\n};\n","import {\n DREAMBOARD_PLUGIN_PROTOCOL,\n DREAMBOARD_PLUGIN_PROTOCOL_VERSION,\n} from \"../../shared/protocol/protocol.js\";\nimport { HostToPluginEnvelopeSchema } from \"../../shared/protocol/schema.js\";\nimport type { PluginToHostPayload } from \"../../shared/protocol/protocol.js\";\nimport { createSourceLifecycle } from \"./lifecycle.js\";\nimport type { CommandSource } from \"./types.js\";\n\n/** Pins its parent window, origin and channel at the first valid initialization. */\nexport function iframeSource(\n options: {\n timeoutMs?: number;\n } = {},\n): CommandSource {\n const target = window;\n const parent = target.parent;\n let channel: { id: string; origin: string } | null = null;\n let sequence = 0;\n let receivedSequence = -1;\n const send = (payload: PluginToHostPayload) => {\n if (!channel) throw new Error(\"Iframe source is not initialized.\");\n parent.postMessage(\n {\n protocol: DREAMBOARD_PLUGIN_PROTOCOL,\n version: DREAMBOARD_PLUGIN_PROTOCOL_VERSION,\n channelId: channel.id,\n sequence: ++sequence,\n payload,\n },\n channel.origin,\n );\n };\n const lifecycle = createSourceLifecycle({\n timeoutMs: options.timeoutMs,\n send,\n recover: () => send({ type: \"runtime.resume\" }),\n close: () => target.removeEventListener(\"message\", receive),\n });\n function receive(event: MessageEvent) {\n if (event.source !== parent) return;\n const parsed = HostToPluginEnvelopeSchema.safeParse(event.data);\n if (!parsed.success) {\n const data: unknown = event.data;\n if (\n channel &&\n event.origin === channel.origin &&\n typeof data === \"object\" &&\n data !== null &&\n \"channelId\" in data &&\n data.channelId === channel.id\n ) {\n try {\n send({\n type: \"runtime.error\",\n code: \"host-runtime-protocol-mismatch\",\n message: \"Iframe source received an invalid host envelope.\",\n });\n } finally {\n lifecycle.fail(new Error(\"Invalid iframe host envelope.\"));\n }\n }\n return;\n }\n const envelope = parsed.data;\n if (!channel) {\n if (envelope.payload.type !== \"runtime.init\") return;\n channel = { id: envelope.channelId, origin: event.origin };\n }\n if (\n channel.id !== envelope.channelId ||\n channel.origin !== event.origin ||\n envelope.sequence <= receivedSequence\n )\n return;\n receivedSequence = envelope.sequence;\n const payload = envelope.payload;\n if (payload.type === \"runtime.init\") {\n lifecycle.session(payload.session);\n if (lifecycle.source.store.get().connection !== \"closed\")\n send({ type: \"runtime.ready\" });\n } else if (payload.type === \"gameplay.frame\")\n lifecycle.frame(payload.frame);\n else lifecycle.result(payload);\n if (lifecycle.source.store.get().connection !== \"closed\")\n send({ type: \"runtime.ack\", sequence: envelope.sequence });\n }\n target.addEventListener(\"message\", receive);\n return lifecycle.source;\n}\n","import { z } from \"zod\";\nimport {\n InteractionResultSchema,\n PluginGameplayFrameSchema,\n SubmitInteractionCommandSchema,\n CancelInteractionCommandSchema,\n} from \"./schema.js\";\nexport const GameplayCloseCode = {\n GoingAway: 1001,\n CredentialExpired: 4000,\n CredentialInvalid: 4001,\n RefreshContextMismatch: 4002,\n PermissionDenied: 4100,\n ProtocolViolation: 4200,\n FrameBeforeAuth: 4201,\n SlowConsumer: 4300,\n TooManyRequests: 4301,\n} as const;\n\nexport const GameplayCredentialSchema = z.discriminatedUnion(\"kind\", [\n z\n .object({ kind: z.literal(\"user\"), token: z.string().min(1).max(16384) })\n .strict(),\n z\n .object({ kind: z.literal(\"demo\"), secret: z.string().min(1).max(1024) })\n .strict(),\n]);\nexport const AuthConnectFrameSchema = z\n .object({\n type: z.literal(\"auth.connect\"),\n credential: GameplayCredentialSchema,\n sessionId: z.string().uuid(),\n playerId: z.string().min(1).max(128),\n })\n .strict();\nexport const AuthRefreshFrameSchema = z\n .object({\n type: z.literal(\"auth.refresh\"),\n credential: GameplayCredentialSchema,\n })\n .strict();\n\nexport const SessionResumeFrameSchema = z.object({\n type: z.literal(\"session.resume\"),\n lastSeenLogCursor: z.number().int().nonnegative().nullable(),\n unacknowledgedClientActionIds: z.array(z.string().min(1)).max(32),\n});\n\nexport const AuthAcceptedFrameSchema = z.object({\n type: z.literal(\"auth.accepted\"),\n expiresAt: z.string().datetime(),\n});\n\nexport const GameplayBackpressureReasonSchema = z.enum([\n \"queue_full\",\n \"capacity_full\",\n]);\n\nexport const GameplayBackpressureOperationSchema = z.enum([\n \"session.resume\",\n \"interaction.submit\",\n \"interaction.cancel\",\n]);\nexport const GameplayBackpressureFrameSchema = z.object({\n type: z.literal(\"gameplay.backpressure\"),\n reason: GameplayBackpressureReasonSchema,\n retryAfterMs: z.number().int().positive(),\n message: z.string().min(1),\n operation: GameplayBackpressureOperationSchema,\n clientActionId: z.string().min(1).optional(),\n});\nexport const SessionSnapshotFrameSchema = z.object({\n type: z.literal(\"session.snapshot\"),\n frame: PluginGameplayFrameSchema,\n});\nexport const ClientGameplayFrameSchema = z.discriminatedUnion(\"type\", [\n AuthConnectFrameSchema,\n AuthRefreshFrameSchema,\n SessionResumeFrameSchema,\n SubmitInteractionCommandSchema,\n CancelInteractionCommandSchema,\n]);\nexport const ServerGameplayFrameSchema = z.discriminatedUnion(\"type\", [\n AuthAcceptedFrameSchema,\n GameplayBackpressureFrameSchema,\n SessionSnapshotFrameSchema,\n InteractionResultSchema,\n]);\nexport type GameplayCredential = z.infer<typeof GameplayCredentialSchema>;\nexport type ClientGameplayFrame = z.infer<typeof ClientGameplayFrameSchema>;\nexport type ServerGameplayFrame = z.infer<typeof ServerGameplayFrameSchema>;\n","import type { PluginSessionDescriptor } from \"../../shared/protocol/frame.js\";\nimport {\n ClientGameplayFrameSchema,\n ServerGameplayFrameSchema,\n GameplayCloseCode,\n type ClientGameplayFrame,\n type GameplayCredential,\n} from \"../../shared/protocol/gameplay-wire.js\";\nimport { createSourceLifecycle } from \"./lifecycle.js\";\nimport type { CommandSource, SourceCommand } from \"./types.js\";\n\nexport function hostSource(options: {\n url: string;\n session: PluginSessionDescriptor;\n playerId: string;\n getCredential(): Promise<GameplayCredential>;\n timeoutMs?: number;\n}): CommandSource {\n const { url, playerId, getCredential } = options;\n const sessionId = options.session.sessionId;\n let socket: WebSocket | null = null;\n let generation = 0;\n let disposed = false;\n let authenticated = false;\n let queued: SourceCommand | null = null;\n let reconnects = 0;\n let refreshTimer: ReturnType<typeof setTimeout> | undefined;\n let snapshotTimer: ReturnType<typeof setTimeout> | undefined;\n let openTimer: ReturnType<typeof setTimeout> | undefined;\n let cleanup = () => {};\n const timeoutMs = options.timeoutMs ?? 10_000;\n const send = (frame: ClientGameplayFrame) => {\n if (!socket || socket.readyState !== WebSocket.OPEN)\n throw new Error(\"Gameplay socket is not open.\");\n socket.send(JSON.stringify(ClientGameplayFrameSchema.parse(frame)));\n };\n const resume = () =>\n send({\n type: \"session.resume\",\n lastSeenLogCursor: null,\n unacknowledgedClientActionIds: queued ? [queued.clientActionId] : [],\n });\n const lifecycle = createSourceLifecycle({\n context: {\n sessionId,\n playerId,\n },\n timeoutMs,\n send(command) {\n if (!authenticated) {\n queued = command;\n return;\n }\n send(command);\n },\n recover() {\n if (authenticated) resume();\n else if (!openTimer) void connect();\n },\n close() {\n disposed = true;\n generation++;\n clearTimeout(refreshTimer);\n clearTimeout(openTimer);\n clearTimeout(snapshotTimer);\n cleanup();\n socket?.close();\n socket = null;\n queued = null;\n },\n });\n lifecycle.session(options.session);\n async function connect() {\n if (disposed) return;\n const current = ++generation;\n authenticated = false;\n clearTimeout(refreshTimer);\n clearTimeout(openTimer);\n clearTimeout(snapshotTimer);\n cleanup();\n socket?.close();\n socket = null;\n openTimer = setTimeout(\n () =>\n lifecycle.fail(new Error(\"Gameplay socket authentication timed out.\")),\n timeoutMs,\n );\n try {\n const credential = await getCredential();\n if (disposed || current !== generation) return;\n const next = new WebSocket(url);\n socket = next;\n const active = () => !disposed && current === generation;\n const onOpen = () => {\n if (!active()) return;\n try {\n send({\n type: \"auth.connect\",\n credential,\n sessionId,\n playerId,\n });\n } catch (error) {\n lifecycle.fail(asError(error));\n }\n };\n const onMessage = (event: MessageEvent) => {\n if (!active()) return;\n try {\n const value: unknown = JSON.parse(String(event.data));\n if (typeof value !== \"object\" || value === null || !(\"type\" in value))\n throw new Error(\"Invalid gameplay frame.\");\n if (\n ![\n \"auth.accepted\",\n \"session.snapshot\",\n \"interaction.result\",\n \"gameplay.backpressure\",\n ].includes(String(value.type))\n )\n return;\n const frame = ServerGameplayFrameSchema.parse(value);\n if (frame.type === \"auth.accepted\") {\n clearTimeout(openTimer);\n openTimer = undefined;\n const first = !authenticated;\n authenticated = true;\n if (first) {\n snapshotTimer = setTimeout(\n () => lifecycle.fail(new Error(\"Gameplay snapshot timed out.\")),\n timeoutMs,\n );\n resume();\n if (queued) {\n send(queued);\n queued = null;\n }\n }\n clearTimeout(refreshTimer);\n if (credential.kind === \"user\") {\n const ttl = Date.parse(frame.expiresAt) - Date.now();\n if (ttl <= 0)\n throw new Error(\"Gameplay credential is already expired.\");\n refreshTimer = setTimeout(\n () => {\n openTimer = setTimeout(\n () =>\n lifecycle.fail(\n new Error(\"Gameplay credential refresh timed out.\"),\n ),\n timeoutMs,\n );\n void getCredential()\n .then((updated) => {\n if (active())\n send({ type: \"auth.refresh\", credential: updated });\n })\n .catch((error) => {\n if (active()) lifecycle.fail(asError(error));\n });\n },\n Math.max(0, ttl - Math.min(60_000, ttl * 0.2)),\n );\n }\n } else if (!authenticated)\n throw new Error(\"Gameplay frame arrived before authentication.\");\n else if (frame.type === \"session.snapshot\") {\n clearTimeout(snapshotTimer);\n snapshotTimer = undefined;\n reconnects = 0;\n lifecycle.frame(frame.frame);\n } else if (frame.type === \"interaction.result\")\n lifecycle.result(frame);\n else lifecycle.fail(new Error(frame.message));\n } catch (error) {\n lifecycle.fail(asError(error));\n }\n };\n const onClose = (event: CloseEvent) => {\n if (!active()) return;\n authenticated = false;\n lifecycle.recovering();\n if (\n new Set<number>([\n GameplayCloseCode.CredentialInvalid,\n GameplayCloseCode.RefreshContextMismatch,\n GameplayCloseCode.PermissionDenied,\n GameplayCloseCode.ProtocolViolation,\n GameplayCloseCode.FrameBeforeAuth,\n ]).has(event.code) ||\n reconnects++ > 0\n ) {\n lifecycle.fail(new Error(`Gameplay socket closed (${event.code}).`));\n return;\n }\n void connect();\n lifecycle.retry();\n };\n const onError = () => {\n if (active()) next.close();\n };\n next.addEventListener(\"open\", onOpen);\n next.addEventListener(\"message\", onMessage);\n next.addEventListener(\"close\", onClose);\n next.addEventListener(\"error\", onError);\n cleanup = () => {\n next.removeEventListener(\"open\", onOpen);\n next.removeEventListener(\"message\", onMessage);\n next.removeEventListener(\"close\", onClose);\n next.removeEventListener(\"error\", onError);\n };\n } catch (error) {\n if (!disposed && current === generation) lifecycle.fail(asError(error));\n }\n }\n void connect();\n return lifecycle.source;\n}\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n","import type { Card, CoreInstance, IdOf, Zone } from \"../model.js\";\n\nexport interface HandOptions<G> {\n /** Compare projected card data only; hidden cards never expose private fields. */\n readonly sort?: (\n left: Card<G, Record<never, never>>,\n right: Card<G, Record<never, never>>,\n ) => number;\n}\n\n/** Optional hand helpers reuse the zone order and the core selection router. */\nexport function handFeature<G>(\n _game: CoreInstance<G>,\n options: HandOptions<G> = {},\n) {\n return {\n zone: {\n getSortedCardIds(\n this: Zone<G, Record<never, never>>,\n ): readonly IdOf<G, \"cardId\">[] {\n return this.getCards({ sort: options.sort }).map((card) => card.id);\n },\n getSelectedCardIds(\n this: Zone<G, Record<never, never>>,\n ): readonly IdOf<G, \"cardId\">[] {\n return this.getCards()\n .filter((card) => card.getIsSelected())\n .map((card) => card.id);\n },\n getSelectableCardIds(\n this: Zone<G, Record<never, never>>,\n ): readonly IdOf<G, \"cardId\">[] {\n return this.getCards()\n .filter((card) => card.getCanSelect())\n .map((card) => card.id);\n },\n },\n };\n}\n","import { createHexBoardGeometry } from \"../../shared/hex-board.js\";\nimport type {\n RuntimeBoardCollections,\n RuntimeBoardState,\n RuntimeSquareBoardState,\n} from \"../../reducer/model/table.js\";\nimport type {\n BoardBase,\n BoardCollection,\n CoreInstance,\n FeatureContext,\n IdOf,\n InteractionKey,\n ReadModel,\n} from \"../model.js\";\nimport type { Point } from \"./pointer-session.js\";\nimport type { ViewportTransform } from \"./pan-zoom.js\";\n\ntype TargetKind = \"space\" | \"edge\" | \"vertex\";\nexport interface BoardLayoutOptions {\n /** Hex radius, or square cell width and height. */\n readonly hexSize: number;\n readonly origin?: Point;\n readonly viewport?: ViewportTransform;\n}\ninterface Geometry {\n readonly viewBox: { x: number; y: number; width: number; height: number };\n readonly spaces: readonly {\n id: string;\n center: Point;\n corners: readonly Point[];\n }[];\n readonly edges: readonly { id: string; from: Point; to: Point }[];\n readonly vertices: readonly { id: string; center: Point }[];\n pointToSpace(point: Point): string | undefined;\n}\n\nfunction squareGeometry(\n board: RuntimeSquareBoardState,\n size: number,\n origin: Point,\n): Geometry {\n const spaces = Object.values(board.spaces).map((space) => {\n const x = origin.x + space.col * size;\n const y = origin.y + space.row * size;\n return {\n id: space.id,\n center: { x: x + size / 2, y: y + size / 2 },\n corners: [\n { x, y },\n { x: x + size, y },\n { x: x + size, y: y + size },\n { x, y: y + size },\n ],\n };\n });\n const byId = new Map(spaces.map((space) => [space.id, space]));\n function sharedCorners(ids: readonly string[]) {\n const first = byId.get(ids[0] ?? \"\")?.corners ?? [];\n return first.filter((point) =>\n ids.every((id) =>\n byId\n .get(id)\n ?.corners.some(\n (candidate) => candidate.x === point.x && candidate.y === point.y,\n ),\n ),\n );\n }\n const points = spaces.flatMap((space) => space.corners);\n const xs = points.map((point) => point.x);\n const ys = points.map((point) => point.y);\n const x = xs.length ? Math.min(...xs) : 0;\n const y = ys.length ? Math.min(...ys) : 0;\n return {\n viewBox: {\n x,\n y,\n width: xs.length ? Math.max(...xs) - x : 0,\n height: ys.length ? Math.max(...ys) - y : 0,\n },\n spaces,\n // Incidence is authored. Only a unique geometric line/point is representable.\n edges: board.edges.flatMap((edge) => {\n const corners = sharedCorners(edge.spaceIds);\n return corners.length === 2\n ? [{ id: edge.id, from: corners[0]!, to: corners[1]! }]\n : [];\n }),\n vertices: board.vertices.flatMap((vertex) => {\n const corners = sharedCorners(vertex.spaceIds);\n return corners.length === 1\n ? [{ id: vertex.id, center: corners[0]! }]\n : [];\n }),\n pointToSpace(point) {\n const col = Math.floor((point.x - origin.x) / size);\n const row = Math.floor((point.y - origin.y) / size);\n return Object.values(board.spaces).find(\n (space) => space.col === col && space.row === row,\n )?.id;\n },\n };\n}\n\n/** Static topology plus captured seat selection. Generic boards remain data-only. */\nexport function boardFeature<G>(\n game: CoreInstance<G>,\n context: FeatureContext<G>,\n) {\n const captures = new WeakMap<\n object,\n {\n model: ReadModel<G>;\n source: ReturnType<typeof game.getOptions>[\"source\"];\n geometry?: ReturnType<typeof createHexBoardGeometry>;\n }\n >();\n const geometries = new WeakMap<\n object,\n ReturnType<typeof createHexBoardGeometry>\n >();\n let cached:\n | {\n view: unknown;\n interactions: ReadModel<G>[\"interactions\"];\n source: ReturnType<typeof game.getOptions>[\"source\"];\n collection: BoardCollection<G>;\n }\n | undefined;\n function collection(): BoardCollection<G> {\n const model = game.getSnapshot();\n const source = game.getOptions().source;\n if (\n cached?.view === model.view &&\n cached.interactions === model.interactions &&\n cached.source === source\n )\n return cached.collection;\n // The canonical materializer joins manifest.staticBoards at view.boards.\n // Do not infer topology from arbitrary authored overlay fields.\n const projected = model.view as {\n boards?: Pick<RuntimeBoardCollections, \"byId\" | \"hex\" | \"square\">;\n } | null;\n const boards = Object.values(projected?.boards?.byId ?? {}).map((data) => {\n const board = context.createBoard(data.id as IdOf<G, \"boardId\">, data);\n let geometry = geometries.get(data);\n if (!geometry && data.layout === \"hex\") {\n geometry = createHexBoardGeometry({\n id: data.baseId ?? data.id,\n orientation: data.orientation,\n spaces: Object.values(data.spaces),\n });\n geometries.set(data, geometry);\n }\n captures.set(board, { model, source, geometry });\n return board;\n });\n const byId = new Map(boards.map((board) => [board.id, board]));\n const result: BoardCollection<G> = Object.freeze({\n get<K extends IdOf<G, \"boardId\">>(id: K) {\n return byId.get(id) as\n | (BoardBase<G, K> & { readonly game: CoreInstance<G> })\n | undefined;\n },\n getAll: () => Object.freeze(boards),\n });\n cached = {\n view: model.view,\n interactions: model.interactions,\n source,\n collection: result,\n };\n return result;\n }\n return {\n root: {\n get boards() {\n return collection();\n },\n },\n board: {\n getLayout(this: BoardBase<G>, options: BoardLayoutOptions) {\n const board = this.data as RuntimeBoardState;\n if (board.layout === \"generic\")\n throw new Error(\n `Board '${board.id}' has no spatial geometry; read its data instead.`,\n );\n const {\n hexSize,\n origin: suppliedOrigin = { x: 0, y: 0 },\n viewport: suppliedViewport = { x: 0, y: 0, scale: 1 },\n } = options;\n const origin = { ...suppliedOrigin };\n const viewport = { ...suppliedViewport };\n if (!Number.isFinite(hexSize) || hexSize <= 0)\n throw new Error(\"hexSize must be positive and finite.\");\n if (\n ![origin.x, origin.y, viewport.x, viewport.y, viewport.scale].every(\n Number.isFinite,\n ) ||\n viewport.scale <= 0\n )\n throw new Error(\n \"Layout transform must be finite with positive scale.\",\n );\n const captured = captures.get(this)!;\n const geometry: Geometry =\n board.layout === \"hex\"\n ? captured.geometry!.getLayout({ hexSize, origin })\n : squareGeometry(board, hexSize, origin);\n const point = (value: Point): Point =>\n Object.freeze({\n x: value.x * viewport.scale + viewport.x,\n y: value.y * viewport.scale + viewport.y,\n });\n function matchingTargets(model: ReadModel<G>, kind: TargetKind) {\n const inputKinds = kind === \"space\" ? [\"space\", \"tile\"] : [kind];\n return model.interactions.list().flatMap((interaction) =>\n interaction\n .getInputs()\n .filter((input) => {\n const domain = input.getDomain();\n return (\n domain.type === \"boardTarget\" &&\n inputKinds.includes(String(domain.targetKind)) &&\n (domain.boardId === board.id ||\n domain.boardId === board.baseId) &&\n (board.scope !== \"perPlayer\" ||\n board.playerId === model.me?.id)\n );\n })\n .map((input) => ({ interaction, input })),\n );\n }\n function target(kind: TargetKind, id: string) {\n const matches = matchingTargets(captured.model, kind);\n const eligible = matches.some(({ input }) => input.getIsEligible(id));\n const selected = matches.some(({ input }) => input.getIsSelected(id));\n const selectable = matches.some(\n ({ input }) => !input.getTargetProps(id).disabled,\n );\n function select(options?: { interaction?: InteractionKey<G> }) {\n if (\n game.getOptions().source !== captured.source ||\n game.snapshot?.me !== captured.model.snapshot?.me\n )\n return;\n const matching = matchingTargets(game.getSnapshot(), kind).filter(\n ({ interaction, input }) =>\n (!options?.interaction ||\n options.interaction === interaction.key) &&\n !input.getTargetProps(id).disabled,\n );\n if (!matching.length) return;\n const domain = matching[0]!.input.getDomain();\n if (domain.type !== \"boardTarget\") return;\n context.routeTarget(kind, id, {\n ...options,\n boardId: String(domain.boardId) as IdOf<G, \"boardId\">,\n });\n }\n return {\n id,\n getIsEligible: () => eligible,\n getIsSelectable: () => selectable,\n getIsSelected: () => selected,\n getSelectHandler:\n (options?: { interaction?: InteractionKey<G> }) => () =>\n select(options),\n getTargetProps(options?: { interaction?: InteractionKey<G> }) {\n const candidates = matches.filter(\n ({ interaction, input }) =>\n (!options?.interaction ||\n interaction.key === options.interaction) &&\n !input.getTargetProps(id).disabled,\n );\n const only = candidates.length === 1 ? candidates[0] : undefined;\n return {\n type: \"button\" as const,\n disabled: candidates.length === 0,\n \"data-action\": \"select\",\n \"data-value\": id,\n \"data-board\": board.id,\n \"data-interaction\":\n options?.interaction ?? only?.interaction.key,\n \"data-input\": only?.input.key,\n \"data-eligible\": eligible,\n \"data-selected\": selected,\n \"data-disabled\": candidates.length === 0,\n onClick: () => select(options),\n };\n },\n };\n }\n const spaces = Object.freeze(\n geometry.spaces.map((space) => {\n const corners = Object.freeze(space.corners.map(point));\n const center = point(space.center);\n return Object.freeze({\n ...target(\"space\", space.id),\n data: board.spaces[space.id],\n center,\n points: () => corners,\n transform: `translate(${center.x} ${center.y})`,\n });\n }),\n );\n const edges = Object.freeze(\n geometry.edges.map((edge) =>\n Object.freeze({\n ...target(\"edge\", edge.id),\n data: board.edges.find((data) => data.id === edge.id),\n center: point({\n x: (edge.from.x + edge.to.x) / 2,\n y: (edge.from.y + edge.to.y) / 2,\n }),\n line: Object.freeze([point(edge.from), point(edge.to)] as const),\n }),\n ),\n );\n const vertices = Object.freeze(\n geometry.vertices.map((vertex) =>\n Object.freeze({\n ...target(\"vertex\", vertex.id),\n data: board.vertices.find((data) => data.id === vertex.id),\n center: point(vertex.center),\n }),\n ),\n );\n return Object.freeze({\n viewBox: Object.freeze({ ...geometry.viewBox }),\n getSpaces: () => spaces,\n getEdges: () => edges,\n getVertices: () => vertices,\n pointToSpace(x: number, y: number) {\n return geometry.pointToSpace({\n x: (x - viewport.x) / viewport.scale,\n y: (y - viewport.y) / viewport.scale,\n });\n },\n });\n },\n },\n };\n}\n","/** Native pointer surface; importing a feature never requires browser globals. */\nexport interface PointerSurface {\n setPointerCapture(pointerId: number): void;\n hasPointerCapture(pointerId: number): boolean;\n releasePointerCapture(pointerId: number): void;\n}\n\nexport interface PointerInput {\n readonly pointerId: number;\n readonly button: number;\n readonly clientX: number;\n readonly clientY: number;\n readonly currentTarget: PointerSurface;\n preventDefault(): void;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport interface PointerMove {\n readonly origin: Point;\n readonly point: Point;\n readonly delta: Point;\n}\n\n/** One captured gesture. Pointer cancellation and disposal never commit a drop. */\nexport function createPointerSession(callbacks: {\n move(value: PointerMove): void;\n end(value: PointerMove): void;\n cancel(): void;\n}) {\n let disposed = false;\n let active:\n | { id: number; surface: PointerSurface; origin: Point; point: Point }\n | undefined;\n\n function value(): PointerMove {\n const { origin, point } = active!;\n return {\n origin,\n point,\n delta: { x: point.x - origin.x, y: point.y - origin.y },\n };\n }\n\n function release() {\n const previous = active;\n active = undefined;\n if (previous?.surface.hasPointerCapture(previous.id)) {\n previous.surface.releasePointerCapture(previous.id);\n }\n }\n\n function cancel() {\n if (!active) return;\n release();\n callbacks.cancel();\n }\n\n return {\n start(event: PointerInput): boolean {\n if (disposed || active || event.button !== 0) return false;\n event.currentTarget.setPointerCapture(event.pointerId);\n const point = { x: event.clientX, y: event.clientY };\n active = {\n id: event.pointerId,\n surface: event.currentTarget,\n origin: point,\n point,\n };\n event.preventDefault();\n return true;\n },\n move(event: PointerInput) {\n if (event.pointerId !== active?.id) return;\n active.point = { x: event.clientX, y: event.clientY };\n event.preventDefault();\n callbacks.move(value());\n },\n end(event: PointerInput) {\n if (event.pointerId !== active?.id) return;\n active.point = { x: event.clientX, y: event.clientY };\n const result = value();\n release();\n callbacks.end(result);\n },\n cancel(event?: Pick<PointerInput, \"pointerId\">) {\n if (event && event.pointerId !== active?.id) return;\n cancel();\n },\n dispose() {\n disposed = true;\n cancel();\n },\n };\n}\n","import type {\n CardBase,\n CoreInstance,\n FeatureContext,\n IdOf,\n InteractionKey,\n} from \"../model.js\";\nimport {\n createPointerSession,\n type Point,\n type PointerInput,\n} from \"./pointer-session.js\";\n\nexport interface DropTarget<G> {\n readonly kind: \"space\" | \"edge\" | \"vertex\" | \"tile\";\n readonly id: string;\n readonly boardId: IdOf<G, \"boardId\">;\n readonly interaction: InteractionKey<G>;\n}\nexport interface DragState<G> {\n readonly cardId: IdOf<G, \"cardId\">;\n readonly offset: Point;\n readonly target: DropTarget<G> | null;\n}\n\n/** Card drag state and native props. The core router owns atomic card/drop writes. */\nexport function dragFeature<G>(\n game: CoreInstance<G>,\n context: FeatureContext<G>,\n) {\n let active: DragState<G> | null = null;\n let interaction: InteractionKey<G> | undefined;\n let source = game.getOptions().source;\n let seat = game.snapshot?.me;\n let disposed = false;\n let suppressPointerClick = false;\n let dragged = false;\n let lastInteractions = game.interactions;\n let lastCards = game.cards;\n let branch = snapshot();\n function update(next: DragState<G> | null) {\n if (disposed) return;\n active =\n next === null\n ? null\n : Object.freeze({ ...next, offset: Object.freeze(next.offset) });\n branch = snapshot();\n context.invalidate();\n }\n function targets(): readonly DropTarget<G>[] {\n if (!active) return [];\n const cardId = active.cardId;\n return (game.cards.get(cardId)?.getInteractions() ?? [])\n .filter(\n (candidate) =>\n candidate.getIsAvailable() &&\n (!interaction || candidate.key === interaction) &&\n candidate\n .getInputs()\n .some(\n (input) =>\n input.getDomain().type === \"cardTarget\" &&\n input.getIsEligible(cardId),\n ),\n )\n .flatMap((candidate) =>\n candidate.getInputs().flatMap((input): DropTarget<G>[] => {\n const domain = input.getDomain();\n if (\n domain.type !== \"boardTarget\" ||\n ![\"space\", \"edge\", \"vertex\", \"tile\"].includes(\n String(domain.targetKind),\n )\n )\n return [];\n return input\n .getEligibleTargets()\n .filter(\n (id): id is string =>\n typeof id === \"string\" && !input.getTargetProps(id).disabled,\n )\n .map((id) =>\n Object.freeze({\n kind: domain.targetKind as DropTarget<G>[\"kind\"],\n id,\n boardId: String(domain.boardId) as IdOf<G, \"boardId\">,\n interaction: candidate.key,\n }),\n );\n }),\n );\n }\n function sameTarget(left: DropTarget<G>, right: DropTarget<G>) {\n return (\n left.kind === right.kind &&\n left.id === right.id &&\n left.boardId === right.boardId &&\n left.interaction === right.interaction\n );\n }\n const pointer = createPointerSession({\n move: ({ delta }) => {\n if (Math.hypot(delta.x, delta.y) >= 5) dragged = true;\n if (active) update({ ...active, offset: delta });\n },\n end({ delta }) {\n if (Math.hypot(delta.x, delta.y) >= 5) dragged = true;\n suppressPointerClick = true;\n const finished = active;\n update(null);\n if (!finished) return;\n if (dragged) {\n if (finished.target)\n context.routeCardDrop(finished.cardId, finished.target);\n } else context.routeTarget(\"card\", finished.cardId, { interaction });\n },\n cancel: () => {\n suppressPointerClick = true;\n update(null);\n },\n });\n function snapshot() {\n const captured = active;\n const dropTargets = Object.freeze(targets());\n return Object.freeze({\n active: captured,\n getDropTargets: () => dropTargets,\n setDropTarget(target: DropTarget<G> | null) {\n if (!active || disposed) return;\n if (\n target &&\n !targets().some((candidate) => sameTarget(candidate, target))\n )\n return;\n update({ ...active, target });\n },\n cancel: () => pointer.cancel(),\n });\n }\n const unsubscribe = game.subscribe(() => {\n const nextSource = game.getOptions().source;\n const nextSeat = game.snapshot?.me;\n if (nextSource !== source || nextSeat !== seat) {\n source = nextSource;\n seat = nextSeat;\n pointer.cancel();\n }\n });\n return {\n root: {\n get drag() {\n if (\n lastInteractions !== game.interactions ||\n lastCards !== game.cards\n ) {\n lastInteractions = game.interactions;\n lastCards = game.cards;\n branch = snapshot();\n }\n return branch;\n },\n },\n card: {\n getDragProps(\n this: CardBase<G>,\n options?: { interaction?: InteractionKey<G> },\n ) {\n return {\n style: {\n touchAction: \"none\" as const,\n transform:\n active?.cardId === this.id\n ? `translate(${active.offset.x}px, ${active.offset.y}px)`\n : undefined,\n },\n \"data-drag-card\": this.id,\n onPointerDown: (event: PointerInput) => {\n if (\n disposed ||\n game.cards.get(this.id) !== this ||\n !this.getCanSelect()\n )\n return;\n if (!pointer.start(event)) return;\n suppressPointerClick = false;\n dragged = false;\n interaction = options?.interaction;\n update({ cardId: this.id, offset: { x: 0, y: 0 }, target: null });\n },\n onClick: (event: { detail: number; preventDefault(): void }) => {\n if (disposed) return;\n if (event.detail !== 0 && suppressPointerClick) {\n suppressPointerClick = false;\n event.preventDefault();\n return;\n }\n this.select(options);\n },\n onPointerMove: pointer.move,\n onPointerUp: pointer.end,\n onPointerCancel: pointer.cancel,\n onLostPointerCapture: pointer.cancel,\n };\n },\n },\n dispose() {\n unsubscribe();\n pointer.dispose();\n disposed = true;\n },\n };\n}\n","import type { CoreInstance, FeatureContext } from \"../model.js\";\nimport {\n createPointerSession,\n type PointerInput,\n type PointerSurface,\n} from \"./pointer-session.js\";\n\nexport interface ViewportTransform {\n readonly x: number;\n readonly y: number;\n readonly scale: number;\n}\nexport interface ViewportSurface extends PointerSurface {\n getBoundingClientRect(): {\n readonly left: number;\n readonly top: number;\n readonly height: number;\n };\n}\nexport interface WheelInput {\n readonly clientX: number;\n readonly clientY: number;\n readonly deltaY: number;\n readonly deltaMode: number;\n readonly currentTarget: ViewportSurface;\n preventDefault(): void;\n}\nexport interface PanZoomOptions {\n readonly initial?: ViewportTransform;\n readonly minScale?: number;\n readonly maxScale?: number;\n}\n\n/** Native pointer panning and wheel zoom around the cursor. No document listeners. */\nexport function panZoomFeature<G>(\n game: CoreInstance<G>,\n context: FeatureContext<G>,\n options: PanZoomOptions = {},\n) {\n const minScale = options.minScale ?? 0.25;\n const maxScale = options.maxScale ?? 4;\n if (\n !Number.isFinite(minScale) ||\n !Number.isFinite(maxScale) ||\n minScale <= 0 ||\n maxScale < minScale\n ) {\n throw new Error(\n \"Viewport scale limits must be positive, finite, and ordered.\",\n );\n }\n const initial = options.initial ?? { x: 0, y: 0, scale: 1 };\n let disposed = false;\n let source = game.getOptions().source;\n let seat = game.snapshot?.me;\n let dragOrigin = initial;\n let transform = admit(initial);\n let branch = snapshot();\n\n function admit(value: ViewportTransform): ViewportTransform {\n if (\n ![value.x, value.y, value.scale].every(Number.isFinite) ||\n value.scale <= 0\n ) {\n throw new Error(\n \"Viewport transform must have finite coordinates and positive scale.\",\n );\n }\n return Object.freeze({\n x: value.x,\n y: value.y,\n scale: Math.min(maxScale, Math.max(minScale, value.scale)),\n });\n }\n function update(value: ViewportTransform) {\n if (disposed) return;\n const next = admit(value);\n if (\n next.x === transform.x &&\n next.y === transform.y &&\n next.scale === transform.scale\n )\n return;\n transform = next;\n branch = snapshot();\n context.invalidate();\n }\n const pointer = createPointerSession({\n move: ({ delta }) =>\n update({\n ...dragOrigin,\n x: dragOrigin.x + delta.x,\n y: dragOrigin.y + delta.y,\n }),\n end: ({ delta }) =>\n update({\n ...dragOrigin,\n x: dragOrigin.x + delta.x,\n y: dragOrigin.y + delta.y,\n }),\n cancel() {},\n });\n function props() {\n return {\n style: { touchAction: \"none\" as const },\n onPointerDown(event: PointerInput) {\n if (pointer.start(event)) dragOrigin = transform;\n },\n onPointerMove: pointer.move,\n onPointerUp: pointer.end,\n onPointerCancel: pointer.cancel,\n onLostPointerCapture: pointer.cancel,\n onWheel(event: WheelInput) {\n if (disposed) return;\n event.preventDefault();\n const rect = event.currentTarget.getBoundingClientRect();\n const unit =\n event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? rect.height : 1;\n const scale = Math.min(\n maxScale,\n Math.max(\n minScale,\n transform.scale * Math.exp(-event.deltaY * unit * 0.002),\n ),\n );\n const x = event.clientX - rect.left;\n const y = event.clientY - rect.top;\n const ratio = scale / transform.scale;\n update({\n x: x - (x - transform.x) * ratio,\n y: y - (y - transform.y) * ratio,\n scale,\n });\n },\n };\n }\n function snapshot() {\n const captured = transform;\n return Object.freeze({\n transform: captured,\n getTransform: () => captured,\n getProps: props,\n setTransform: update,\n reset: () => {\n pointer.cancel();\n update(initial);\n },\n });\n }\n const unsubscribe = game.subscribe(() => {\n const nextSource = game.getOptions().source;\n const nextSeat = game.snapshot?.me;\n if (nextSource !== source || nextSeat !== seat) {\n source = nextSource;\n seat = nextSeat;\n pointer.cancel();\n update(initial);\n }\n });\n return {\n root: {\n get viewport() {\n return branch;\n },\n },\n dispose() {\n disposed = true;\n unsubscribe();\n pointer.dispose();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAM,yBACX,OACI,kBACA;AAEC,IAAM,0BAA0B;AAAA,EACrC,yBAAyB;AAC3B;AAUO,IAAM,6BAAsD;AAAA,EACjE,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,UAAU;AACZ;;;ACbO,SAAS,aACd,UAEI,CAAC,GACU;AACf,QAAM,SAAS;AACf,QAAM,SAAS,OAAO;AACtB,MAAI,UAAiD;AACrD,MAAI,WAAW;AACf,MAAI,mB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AO;AAAA,IACL,MAAM;AAAA,MACJ,IAAI,WAAW;AACb,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,UAAU;AACR,iBAAW;AACX,kBAAY;AACZ,cAAQ,QAAQ;AAAA,IAClB;AAAA,EACF;AACF;","names":["x","y","options"]}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Store } from '@tanstack/store';
|
|
3
|
+
import { aY as ViewOfDefinition, a6 as PhaseNamesOfDefinition, O as InteractionIdOfDefinitionPhase, av as RuntimeJson, g as ClientParamsOfInteractionOfDefinition, u as InputDomain, G as GameEvent } from './definition-BaHNPZol.js';
|
|
4
|
+
import { g as SourceSnapshot, h as SourceState, I as InteractionDescriptor, i as SubmitResult, G as GameSource } from './types-DimqnJBq.js';
|
|
5
|
+
|
|
6
|
+
type PhaseName<G> = [PhaseNamesOfDefinition<G>] extends [never] ? string : PhaseNamesOfDefinition<G>;
|
|
7
|
+
type InteractionKey<G> = unknown extends G ? string : [PhaseNamesOfDefinition<G>] extends [never] ? string : {
|
|
8
|
+
[P in PhaseNamesOfDefinition<G>]: `${P}.${InteractionIdOfDefinitionPhase<G, P>}`;
|
|
9
|
+
}[PhaseNamesOfDefinition<G>];
|
|
10
|
+
type InteractionParams<G, K extends InteractionKey<G>> = unknown extends G ? Record<string, RuntimeJson> : K extends `${infer P}.${infer I}` ? P extends PhaseNamesOfDefinition<G> ? I extends InteractionIdOfDefinitionPhase<G, P> ? ClientParamsOfInteractionOfDefinition<G, P, I> : never : Record<string, RuntimeJson> : Record<string, RuntimeJson>;
|
|
11
|
+
type InputKey<G, K extends InteractionKey<G>> = keyof InteractionParams<G, K> & string;
|
|
12
|
+
type IdOf<G, K extends string> = G extends {
|
|
13
|
+
contract: {
|
|
14
|
+
manifest: {
|
|
15
|
+
ids: Record<K, infer Schema extends z.ZodType>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
} ? z.output<Schema> & string : string;
|
|
19
|
+
type ViewOf<G> = [ViewOfDefinition<G>] extends [never] ? unknown : ViewOfDefinition<G>;
|
|
20
|
+
type Drafts<G> = Readonly<Partial<{
|
|
21
|
+
[K in InteractionKey<G>]: Readonly<Partial<InteractionParams<G, K>>>;
|
|
22
|
+
}>>;
|
|
23
|
+
interface LocalState<G> {
|
|
24
|
+
readonly drafts: Drafts<G>;
|
|
25
|
+
readonly activeInteraction: InteractionKey<G> | null;
|
|
26
|
+
}
|
|
27
|
+
interface Feature {
|
|
28
|
+
readonly root?: object;
|
|
29
|
+
readonly interaction?: object;
|
|
30
|
+
readonly input?: object;
|
|
31
|
+
readonly zone?: object;
|
|
32
|
+
readonly card?: object;
|
|
33
|
+
readonly board?: object;
|
|
34
|
+
readonly dispose?: () => void;
|
|
35
|
+
}
|
|
36
|
+
type Features = Readonly<Record<string, Feature>>;
|
|
37
|
+
type Intersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
|
|
38
|
+
type Hook<F extends Features, H extends keyof Feature> = keyof F extends never ? Record<never, never> : Intersection<{
|
|
39
|
+
[K in keyof F]: F[K] extends Record<H, infer A> ? A : Record<never, never>;
|
|
40
|
+
}[keyof F]>;
|
|
41
|
+
interface BoardBase<G, K extends IdOf<G, "boardId"> = IdOf<G, "boardId">> {
|
|
42
|
+
readonly id: K;
|
|
43
|
+
readonly game: CoreInstance<G>;
|
|
44
|
+
readonly data: Readonly<object>;
|
|
45
|
+
}
|
|
46
|
+
type Board<G, F extends Features, K extends IdOf<G, "boardId"> = IdOf<G, "boardId">> = BoardBase<G, K> & Hook<F, "board"> & {
|
|
47
|
+
readonly game: GameInstance<G, F>;
|
|
48
|
+
};
|
|
49
|
+
interface BoardCollection<G, F extends Features = Record<never, never>> {
|
|
50
|
+
get<K extends IdOf<G, "boardId">>(id: K): Board<G, F, K> | undefined;
|
|
51
|
+
getAll(): readonly Board<G, F>[];
|
|
52
|
+
}
|
|
53
|
+
type RootHooks<G, F extends Features> = {
|
|
54
|
+
[K in keyof Hook<F, "root">]: Hook<F, "root">[K] extends BoardCollection<G> ? BoardCollection<G, F> : Hook<F, "root">[K];
|
|
55
|
+
};
|
|
56
|
+
interface FeatureContext<G> {
|
|
57
|
+
createBoard<K extends IdOf<G, "boardId">, Data extends object>(id: K, data: Data): BoardBase<G, K> & {
|
|
58
|
+
readonly data: Readonly<Data>;
|
|
59
|
+
};
|
|
60
|
+
routeTarget(kind: "card" | "space" | "edge" | "vertex" | "tile", id: string, options?: {
|
|
61
|
+
interaction?: InteractionKey<G>;
|
|
62
|
+
boardId?: IdOf<G, "boardId">;
|
|
63
|
+
}): void;
|
|
64
|
+
routeCardDrop(cardId: IdOf<G, "cardId">, target: {
|
|
65
|
+
kind: "space" | "edge" | "vertex" | "tile";
|
|
66
|
+
id: string;
|
|
67
|
+
boardId?: IdOf<G, "boardId">;
|
|
68
|
+
interaction?: InteractionKey<G>;
|
|
69
|
+
}): void;
|
|
70
|
+
invalidate(): void;
|
|
71
|
+
}
|
|
72
|
+
interface NativeEvent {
|
|
73
|
+
preventDefault(): void;
|
|
74
|
+
}
|
|
75
|
+
interface FieldEvent {
|
|
76
|
+
readonly currentTarget: {
|
|
77
|
+
readonly value: string;
|
|
78
|
+
readonly valueAsNumber?: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
type ActionProps = {
|
|
82
|
+
readonly onClick: (event?: NativeEvent) => void;
|
|
83
|
+
readonly disabled: boolean;
|
|
84
|
+
readonly type: "button";
|
|
85
|
+
readonly [key: `data-${string}`]: string | number | boolean | undefined;
|
|
86
|
+
};
|
|
87
|
+
interface Player<G> {
|
|
88
|
+
readonly id: IdOf<G, "playerId">;
|
|
89
|
+
readonly index: number;
|
|
90
|
+
readonly name: string;
|
|
91
|
+
readonly color?: string;
|
|
92
|
+
readonly isMe: boolean;
|
|
93
|
+
readonly game: CoreInstance<G>;
|
|
94
|
+
}
|
|
95
|
+
interface Phase<G> {
|
|
96
|
+
readonly current: PhaseName<G> | null;
|
|
97
|
+
is(name: PhaseName<G>): boolean;
|
|
98
|
+
switch<R>(routes: {
|
|
99
|
+
[P in PhaseName<G>]: () => R;
|
|
100
|
+
}): R | null;
|
|
101
|
+
}
|
|
102
|
+
interface Turn<G> {
|
|
103
|
+
readonly activePlayerIds: readonly IdOf<G, "playerId">[];
|
|
104
|
+
readonly currentPlayerId: IdOf<G, "playerId"> | null;
|
|
105
|
+
readonly order: readonly IdOf<G, "playerId">[];
|
|
106
|
+
readonly isMine: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface InputBase<G, K extends InteractionKey<G>, N extends InputKey<G, K>> {
|
|
109
|
+
readonly key: N;
|
|
110
|
+
readonly kind: string;
|
|
111
|
+
readonly game: CoreInstance<G>;
|
|
112
|
+
readonly interaction: InteractionBase<G, K>;
|
|
113
|
+
getDomain(): InputDomain;
|
|
114
|
+
getValue(): InteractionParams<G, K>[N] | undefined;
|
|
115
|
+
setValue(value: Exclude<InteractionParams<G, K>[N], undefined>): void;
|
|
116
|
+
clear(): void;
|
|
117
|
+
getIsReady(): boolean;
|
|
118
|
+
getEligibleTargets(): readonly RuntimeJson[];
|
|
119
|
+
getIsEligible(value: RuntimeJson): boolean;
|
|
120
|
+
getIsSelected(value: RuntimeJson): boolean;
|
|
121
|
+
getSelectHandler(value: RuntimeJson): () => void;
|
|
122
|
+
getTargetProps(value: RuntimeJson): ActionProps;
|
|
123
|
+
getFieldProps(): {
|
|
124
|
+
value: InteractionParams<G, K>[N] | "";
|
|
125
|
+
disabled: boolean;
|
|
126
|
+
onChange(event: FieldEvent): void;
|
|
127
|
+
readonly [key: `data-${string}`]: string | number | boolean | undefined;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
type Input<G, F extends Features, K extends InteractionKey<G>, N extends InputKey<G, K>> = Omit<InputBase<G, K, N>, "interaction" | "game"> & Hook<F, "input"> & {
|
|
131
|
+
readonly game: GameInstance<G, F>;
|
|
132
|
+
readonly interaction: Interaction<G, F, K>;
|
|
133
|
+
};
|
|
134
|
+
interface InteractionBase<G, K extends InteractionKey<G>> {
|
|
135
|
+
readonly key: K;
|
|
136
|
+
readonly id: string;
|
|
137
|
+
readonly phase: PhaseName<G>;
|
|
138
|
+
readonly label: string;
|
|
139
|
+
readonly help?: string;
|
|
140
|
+
readonly kind: "inputs" | "steps";
|
|
141
|
+
readonly game: CoreInstance<G>;
|
|
142
|
+
getAvailability(): InteractionDescriptor["availability"];
|
|
143
|
+
getIsAvailable(): boolean;
|
|
144
|
+
getUnavailableReason(): string | null;
|
|
145
|
+
getStep(): InteractionDescriptor["step"] | null;
|
|
146
|
+
getStepIndex(): number | null;
|
|
147
|
+
getIsReady(): boolean;
|
|
148
|
+
getMissingInputs(): readonly string[];
|
|
149
|
+
getStatus(): "open" | "submitting" | "submitted";
|
|
150
|
+
submit(): Promise<SubmitResult>;
|
|
151
|
+
cancel(): Promise<SubmitResult>;
|
|
152
|
+
reset(): void;
|
|
153
|
+
activate(): void;
|
|
154
|
+
getSubmitHandler(): (event?: NativeEvent) => void;
|
|
155
|
+
getSubmitProps(): ActionProps;
|
|
156
|
+
}
|
|
157
|
+
type Interaction<G, F extends Features, K extends InteractionKey<G>> = InteractionBase<G, K> & Hook<F, "interaction"> & {
|
|
158
|
+
readonly game: GameInstance<G, F>;
|
|
159
|
+
getInput<N extends InputKey<G, K>>(key: N): Input<G, F, K, N> | undefined;
|
|
160
|
+
getInputs(): readonly Input<G, F, K, InputKey<G, K>>[];
|
|
161
|
+
};
|
|
162
|
+
type ReadonlyData<T> = T extends readonly (infer Item)[] ? readonly ReadonlyData<Item>[] : T extends object ? {
|
|
163
|
+
readonly [K in keyof T]: ReadonlyData<T[K]>;
|
|
164
|
+
} : T;
|
|
165
|
+
type CardDataOf<G, K extends string> = G extends {
|
|
166
|
+
contract: {
|
|
167
|
+
manifest: {
|
|
168
|
+
tableSchema: infer Schema extends z.ZodType;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
} ? z.output<Schema> extends {
|
|
172
|
+
cards: infer Cards;
|
|
173
|
+
} ? K extends keyof Cards ? ReadonlyData<Cards[K]> : never : never : Readonly<Record<string, RuntimeJson>>;
|
|
174
|
+
interface CardBase<G, K extends IdOf<G, "cardId"> = IdOf<G, "cardId">> {
|
|
175
|
+
readonly id: K;
|
|
176
|
+
readonly zone: IdOf<G, "zoneId">;
|
|
177
|
+
readonly index: number;
|
|
178
|
+
readonly view: CardDataOf<G, K> | null;
|
|
179
|
+
readonly hidden: boolean;
|
|
180
|
+
readonly game: CoreInstance<G>;
|
|
181
|
+
getInteractions(): readonly InteractionBase<G, InteractionKey<G>>[];
|
|
182
|
+
getIsEligible(): boolean;
|
|
183
|
+
getIsSelected(): boolean;
|
|
184
|
+
getCanSelect(): boolean;
|
|
185
|
+
select(options?: {
|
|
186
|
+
interaction?: InteractionKey<G>;
|
|
187
|
+
}): void;
|
|
188
|
+
getSelectHandler(options?: {
|
|
189
|
+
interaction?: InteractionKey<G>;
|
|
190
|
+
}): () => void;
|
|
191
|
+
getProps(options?: {
|
|
192
|
+
interaction?: InteractionKey<G>;
|
|
193
|
+
}): ActionProps;
|
|
194
|
+
}
|
|
195
|
+
type Card<G, F extends Features, K extends IdOf<G, "cardId"> = IdOf<G, "cardId">> = Omit<CardBase<G, K>, "getInteractions" | "game"> & Hook<F, "card"> & {
|
|
196
|
+
readonly game: GameInstance<G, F>;
|
|
197
|
+
getInteractions(): readonly Interaction<G, F, InteractionKey<G>>[];
|
|
198
|
+
};
|
|
199
|
+
interface ZoneBase<G> {
|
|
200
|
+
readonly id: IdOf<G, "zoneId">;
|
|
201
|
+
readonly count: number;
|
|
202
|
+
readonly game: CoreInstance<G>;
|
|
203
|
+
getIsEmpty(): boolean;
|
|
204
|
+
}
|
|
205
|
+
type Zone<G, F extends Features> = ZoneBase<G> & Hook<F, "zone"> & {
|
|
206
|
+
readonly game: GameInstance<G, F>;
|
|
207
|
+
getCards(options?: {
|
|
208
|
+
sort?: (a: Card<G, F>, b: Card<G, F>) => number;
|
|
209
|
+
}): readonly Card<G, F>[];
|
|
210
|
+
getCard<K extends IdOf<G, "cardId">>(id: K): Card<G, F, K> | undefined;
|
|
211
|
+
};
|
|
212
|
+
interface ReadModel<G, F extends Features = Record<never, never>> {
|
|
213
|
+
readonly snapshot: SourceSnapshot | null;
|
|
214
|
+
readonly view: ViewOf<G> | null;
|
|
215
|
+
readonly version: number | null;
|
|
216
|
+
readonly connection: SourceState["connection"];
|
|
217
|
+
readonly request: SourceState["request"];
|
|
218
|
+
readonly state: LocalState<G>;
|
|
219
|
+
readonly phase: Phase<G>;
|
|
220
|
+
readonly turn: Turn<G>;
|
|
221
|
+
readonly me: {
|
|
222
|
+
readonly id: IdOf<G, "playerId">;
|
|
223
|
+
readonly player: Player<G>;
|
|
224
|
+
getCanAct(): boolean;
|
|
225
|
+
} | null;
|
|
226
|
+
readonly players: {
|
|
227
|
+
get(id: IdOf<G, "playerId">): Player<G> | undefined;
|
|
228
|
+
getAll(): readonly Player<G>[];
|
|
229
|
+
next(id: IdOf<G, "playerId">): Player<G> | undefined;
|
|
230
|
+
readonly order: readonly IdOf<G, "playerId">[];
|
|
231
|
+
};
|
|
232
|
+
readonly interactions: {
|
|
233
|
+
get<K extends InteractionKey<G>>(key: K): Interaction<G, F, K> | undefined;
|
|
234
|
+
list(): readonly Interaction<G, F, InteractionKey<G>>[];
|
|
235
|
+
listAvailable(): readonly Interaction<G, F, InteractionKey<G>>[];
|
|
236
|
+
};
|
|
237
|
+
readonly inputs: {
|
|
238
|
+
get<K extends InteractionKey<G>, N extends InputKey<G, K>>(interaction: K, input: N): Input<G, F, K, N> | undefined;
|
|
239
|
+
};
|
|
240
|
+
readonly zones: {
|
|
241
|
+
get(id: IdOf<G, "zoneId">): Zone<G, F> | undefined;
|
|
242
|
+
getAll(): readonly Zone<G, F>[];
|
|
243
|
+
};
|
|
244
|
+
readonly cards: {
|
|
245
|
+
get<K extends IdOf<G, "cardId">>(id: K): Card<G, F, K> | undefined;
|
|
246
|
+
};
|
|
247
|
+
readonly events: {
|
|
248
|
+
readonly recent: readonly GameEvent[];
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
interface InstanceOptions<G, S extends GameSource = GameSource> {
|
|
252
|
+
readonly source: S;
|
|
253
|
+
readonly initialState?: Partial<LocalState<G>>;
|
|
254
|
+
readonly state?: Partial<LocalState<G>>;
|
|
255
|
+
readonly onDraftsChange?: (drafts: Drafts<G>) => void;
|
|
256
|
+
readonly onActiveInteractionChange?: (key: InteractionKey<G> | null) => void;
|
|
257
|
+
readonly onError?: (error: unknown) => void;
|
|
258
|
+
readonly coverage?: Readonly<Record<InteractionKey<G>, unknown>>;
|
|
259
|
+
readonly debug?: boolean;
|
|
260
|
+
}
|
|
261
|
+
type CoreInstance<G> = ReadModel<G> & {
|
|
262
|
+
readonly store: Pick<Store<ReadModel<G>>, "get" | "subscribe">;
|
|
263
|
+
getSnapshot(): ReadModel<G>;
|
|
264
|
+
getOptions(): InstanceOptions<G>;
|
|
265
|
+
setOptions(options: InstanceOptions<G>): void;
|
|
266
|
+
subscribe(listener: () => void): () => void;
|
|
267
|
+
dispose(): void;
|
|
268
|
+
assertCoverage(): void;
|
|
269
|
+
inspect(): ReadModel<G>;
|
|
270
|
+
};
|
|
271
|
+
type GameSnapshot<G, F extends Features = Record<never, never>> = ReadModel<G, F> & RootHooks<G, F>;
|
|
272
|
+
type GameInstance<G, F extends Features = Record<never, never>, S extends GameSource = GameSource> = Omit<CoreInstance<G>, keyof ReadModel<G> | "store" | "getSnapshot" | "getOptions" | "setOptions" | "inspect"> & ReadModel<G, F> & RootHooks<G, F> & {
|
|
273
|
+
readonly store: Pick<Store<GameSnapshot<G, F>>, "get" | "subscribe">;
|
|
274
|
+
getSnapshot(): GameSnapshot<G, F>;
|
|
275
|
+
inspect(): GameSnapshot<G, F>;
|
|
276
|
+
getOptions(): InstanceOptions<G, S>;
|
|
277
|
+
setOptions(options: InstanceOptions<G, S>): void;
|
|
278
|
+
} & (S extends {
|
|
279
|
+
apply(action: infer A): infer R;
|
|
280
|
+
} ? {
|
|
281
|
+
apply(action: A): R;
|
|
282
|
+
} : Record<never, never>) & (S extends {
|
|
283
|
+
explore(...args: infer A): infer R;
|
|
284
|
+
} ? {
|
|
285
|
+
explore(...args: A): R;
|
|
286
|
+
} : Record<never, never>);
|
|
287
|
+
|
|
288
|
+
export type { ActionProps as A, Board as B, Card as C, Drafts as D, Feature as F, GameInstance as G, Hook as H, IdOf as I, LocalState as L, NativeEvent as N, Phase as P, ReadModel as R, Turn as T, ViewOf as V, Zone as Z, BoardBase as a, BoardCollection as b, CardBase as c, CardDataOf as d, CoreInstance as e, FeatureContext as f, Features as g, FieldEvent as h, GameSnapshot as i, Input as j, InputBase as k, InputKey as l, InstanceOptions as m, Interaction as n, InteractionBase as o, InteractionKey as p, InteractionParams as q, PhaseName as r, Player as s, ReadonlyData as t, ZoneBase as u };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { g as Features, m as InstanceOptions, e as CoreInstance, f as FeatureContext, G as GameInstance, i as GameSnapshot } from './model-BHro6yXu.js';
|
|
4
|
+
import { G as GameSource } from './types-DimqnJBq.js';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import '@tanstack/store';
|
|
7
|
+
import './definition-BaHNPZol.js';
|
|
8
|
+
import 'honeycomb-grid';
|
|
9
|
+
|
|
10
|
+
interface SelectionOptions<Value> {
|
|
11
|
+
readonly compare?: (previous: Value, next: Value) => boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Bind erased game types and features; each provider owns its source lifetime. */
|
|
14
|
+
declare function createGameHook<Game, Source extends GameSource = GameSource>(): <const Enabled extends Features = Record<never, never>>(defaults: Omit<InstanceOptions<Game, Source>, "source"> & {
|
|
15
|
+
features?: (core: CoreInstance<Game>, context: FeatureContext<Game>) => Enabled;
|
|
16
|
+
}) => {
|
|
17
|
+
GameProvider: ({ children, ...overrides }: Partial<Omit<InstanceOptions<Game, Source>, "source">> & {
|
|
18
|
+
source: Source;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
21
|
+
useGame: {
|
|
22
|
+
(): GameInstance<Game, Enabled, Source>;
|
|
23
|
+
<Value>(selector: (snapshot: GameSnapshot<Game, Enabled>) => Value, options?: SelectionOptions<Value>): Value;
|
|
24
|
+
};
|
|
25
|
+
Subscribe: <Value>({ selector, compare, children, }: {
|
|
26
|
+
selector: (snapshot: GameSnapshot<Game, Enabled>) => Value;
|
|
27
|
+
compare?: SelectionOptions<Value>["compare"];
|
|
28
|
+
children: (value: Value) => ReactNode;
|
|
29
|
+
}) => ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { type SelectionOptions, createGameHook };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createGameInstance
|
|
3
|
+
} from "./chunk-SP234IY4.js";
|
|
4
|
+
import "./chunk-DMFVAZI2.js";
|
|
5
|
+
import "./chunk-VUWNJXLJ.js";
|
|
6
|
+
|
|
7
|
+
// src/react/create-game-hook.tsx
|
|
8
|
+
import {
|
|
9
|
+
createContext,
|
|
10
|
+
useContext,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useState
|
|
14
|
+
} from "react";
|
|
15
|
+
import { useSelector } from "@tanstack/react-store";
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
function createGameHook() {
|
|
18
|
+
return function(defaults) {
|
|
19
|
+
const Context = createContext(null);
|
|
20
|
+
function GameProvider({ children, ...overrides }) {
|
|
21
|
+
const [instance, setInstance] = useState(null);
|
|
22
|
+
const lifetime = useRef(null);
|
|
23
|
+
const options = {
|
|
24
|
+
...defaults,
|
|
25
|
+
...overrides
|
|
26
|
+
};
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
let current = lifetime.current;
|
|
29
|
+
if (!current) {
|
|
30
|
+
current = {
|
|
31
|
+
instance: createGameInstance()(options),
|
|
32
|
+
generation: 0
|
|
33
|
+
};
|
|
34
|
+
lifetime.current = current;
|
|
35
|
+
setInstance(current.instance);
|
|
36
|
+
}
|
|
37
|
+
const owned = current;
|
|
38
|
+
++owned.generation;
|
|
39
|
+
return () => {
|
|
40
|
+
const generation = ++owned.generation;
|
|
41
|
+
queueMicrotask(() => {
|
|
42
|
+
if (owned.generation !== generation) return;
|
|
43
|
+
owned.instance.dispose();
|
|
44
|
+
if (lifetime.current === owned) lifetime.current = null;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
lifetime.current?.instance.setOptions(options);
|
|
50
|
+
});
|
|
51
|
+
return instance ? /* @__PURE__ */ jsx(Context.Provider, { value: instance, children }) : null;
|
|
52
|
+
}
|
|
53
|
+
function useInstance() {
|
|
54
|
+
const instance = useContext(Context);
|
|
55
|
+
if (!instance) throw new Error("useGame requires its GameProvider.");
|
|
56
|
+
return instance;
|
|
57
|
+
}
|
|
58
|
+
function useGame(selector, options) {
|
|
59
|
+
const instance = useInstance();
|
|
60
|
+
const selected = useSelector(
|
|
61
|
+
instance.store,
|
|
62
|
+
selector ?? ((snapshot) => snapshot),
|
|
63
|
+
options
|
|
64
|
+
);
|
|
65
|
+
return selector ? selected : instance;
|
|
66
|
+
}
|
|
67
|
+
function Subscribe({
|
|
68
|
+
selector,
|
|
69
|
+
compare,
|
|
70
|
+
children
|
|
71
|
+
}) {
|
|
72
|
+
return children(useGame(selector, { compare }));
|
|
73
|
+
}
|
|
74
|
+
return { GameProvider, useGame, Subscribe };
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
createGameHook
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/create-game-hook.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { useSelector } from \"@tanstack/react-store\";\nimport { createGameInstance } from \"../headless/instance.js\";\nimport type {\n CoreInstance,\n FeatureContext,\n Features,\n GameInstance,\n GameSnapshot,\n GameSource,\n InstanceOptions,\n} from \"../headless/model.js\";\n\nexport interface SelectionOptions<Value> {\n readonly compare?: (previous: Value, next: Value) => boolean;\n}\n\n/** Bind erased game types and features; each provider owns its source lifetime. */\nexport function createGameHook<Game, Source extends GameSource = GameSource>() {\n return function <const Enabled extends Features = Record<never, never>>(\n defaults: Omit<InstanceOptions<Game, Source>, \"source\"> & {\n features?: (\n core: CoreInstance<Game>,\n context: FeatureContext<Game>,\n ) => Enabled;\n },\n ) {\n type Instance = GameInstance<Game, Enabled, Source>;\n type Snapshot = GameSnapshot<Game, Enabled>;\n type ProviderProps = Partial<\n Omit<InstanceOptions<Game, Source>, \"source\">\n > & {\n source: Source;\n children?: ReactNode;\n };\n const Context = createContext<Instance | null>(null);\n\n /** Owns the source. Do not share it between independently mounted providers. */\n function GameProvider({ children, ...overrides }: ProviderProps) {\n const [instance, setInstance] = useState<Instance | null>(null);\n const lifetime = useRef<{\n instance: Instance;\n generation: number;\n } | null>(null);\n const options = {\n ...defaults,\n ...overrides,\n };\n useLayoutEffect(() => {\n let current = lifetime.current;\n if (!current) {\n current = {\n instance: createGameInstance<Game>()(options),\n generation: 0,\n };\n lifetime.current = current;\n setInstance(current.instance);\n }\n const owned = current;\n ++owned.generation;\n return () => {\n const generation = ++owned.generation;\n queueMicrotask(() => {\n if (owned.generation !== generation) return;\n owned.instance.dispose();\n if (lifetime.current === owned) lifetime.current = null;\n });\n };\n // Construction belongs to this committed provider lifetime. Current\n // options are installed separately without recreating features.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n useLayoutEffect(() => {\n lifetime.current?.instance.setOptions(options);\n });\n return instance ? (\n <Context.Provider value={instance}>{children}</Context.Provider>\n ) : null;\n }\n\n function useInstance(): Instance {\n const instance = useContext(Context);\n if (!instance) throw new Error(\"useGame requires its GameProvider.\");\n return instance;\n }\n\n function useGame(): Instance;\n function useGame<Value>(\n selector: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Value;\n function useGame<Value>(\n selector?: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Instance | Value {\n const instance = useInstance();\n const selected = useSelector(\n instance.store,\n selector ?? ((snapshot) => snapshot as unknown as Value),\n options,\n );\n return selector ? selected : instance;\n }\n\n function Subscribe<Value>({\n selector,\n compare,\n children,\n }: {\n selector: (snapshot: Snapshot) => Value;\n compare?: SelectionOptions<Value>[\"compare\"];\n children: (value: Value) => ReactNode;\n }) {\n return children(useGame(selector, { compare }));\n }\n\n return { GameProvider, useGame, Subscribe };\n };\n}\n"],"mappings":";;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;AA2EpB;AA1DD,SAAS,iBAA+D;AAC7E,SAAO,SACL,UAMA;AASA,UAAM,UAAU,cAA+B,IAAI;AAGnD,aAAS,aAAa,EAAE,UAAU,GAAG,UAAU,GAAkB;AAC/D,YAAM,CAAC,UAAU,WAAW,IAAI,SAA0B,IAAI;AAC9D,YAAM,WAAW,OAGP,IAAI;AACd,YAAM,UAAU;AAAA,QACd,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AACA,sBAAgB,MAAM;AACpB,YAAI,UAAU,SAAS;AACvB,YAAI,CAAC,SAAS;AACZ,oBAAU;AAAA,YACR,UAAU,mBAAyB,EAAE,OAAO;AAAA,YAC5C,YAAY;AAAA,UACd;AACA,mBAAS,UAAU;AACnB,sBAAY,QAAQ,QAAQ;AAAA,QAC9B;AACA,cAAM,QAAQ;AACd,UAAE,MAAM;AACR,eAAO,MAAM;AAC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