@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
CHANGED
|
@@ -1,12 +1,1051 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
AmbiguousTargetError,
|
|
3
|
+
createGameInstance
|
|
4
|
+
} from "./chunk-SP234IY4.js";
|
|
5
|
+
import {
|
|
6
|
+
BoardStaticProjectionSchema,
|
|
7
|
+
CancelInteractionCommandSchema,
|
|
8
|
+
DREAMBOARD_PLUGIN_PROTOCOL,
|
|
9
|
+
DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
|
|
10
|
+
GameEventDetailSchema,
|
|
11
|
+
GameEventSchema,
|
|
12
|
+
GameOutcomeSchema,
|
|
13
|
+
GameplayBasisSchema,
|
|
14
|
+
HostToPluginEnvelopeSchema,
|
|
15
|
+
HostToPluginPayloadSchema,
|
|
16
|
+
InteractionResultSchema,
|
|
17
|
+
PluginGameplayFrameSchema,
|
|
18
|
+
PluginPlayerSummarySchema,
|
|
19
|
+
PluginSessionDescriptorSchema,
|
|
20
|
+
PluginToHostEnvelopeSchema,
|
|
21
|
+
PluginToHostPayloadSchema,
|
|
22
|
+
SeatFrameSchema,
|
|
23
|
+
SeatProjectionBundleSchema,
|
|
24
|
+
SimultaneousPhaseSnapshotSchema,
|
|
25
|
+
SubmitInteractionCommandSchema,
|
|
26
|
+
SystemActionEventSchema,
|
|
27
|
+
ZoneHandlesSnapshotSchema,
|
|
28
|
+
computePluginActionSetVersion,
|
|
29
|
+
createPluginProtocolEnvelopeSchema,
|
|
30
|
+
createSourceLifecycle,
|
|
31
|
+
digestPluginCommandRequest,
|
|
32
|
+
digestPluginGameplayFrame,
|
|
33
|
+
materializePluginGameplayFrame,
|
|
34
|
+
parseHostToPluginEnvelope,
|
|
35
|
+
parsePluginGameplayFrame,
|
|
36
|
+
parsePluginSessionDescriptor,
|
|
37
|
+
parsePluginToHostEnvelope,
|
|
38
|
+
staticSource
|
|
39
|
+
} from "./chunk-ZPRKWPEP.js";
|
|
40
|
+
import "./chunk-DMFVAZI2.js";
|
|
41
|
+
import {
|
|
42
|
+
InputDomainSchema,
|
|
43
|
+
InteractionAvailabilitySchema,
|
|
44
|
+
InteractionCommitPolicySchema,
|
|
45
|
+
InteractionDescriptorSchema,
|
|
46
|
+
InteractionInputDescriptorSchema,
|
|
47
|
+
RuntimeJsonSchema,
|
|
48
|
+
canonicalizePluginRuntimeJson,
|
|
49
|
+
createHexBoardGeometry,
|
|
50
|
+
digestPluginRuntimeJson,
|
|
51
|
+
encodeCanonicalPluginRuntimeJson
|
|
52
|
+
} from "./chunk-FMM5LVJW.js";
|
|
53
|
+
import "./chunk-VUWNJXLJ.js";
|
|
54
|
+
|
|
55
|
+
// src/package-set.ts
|
|
56
|
+
var DREAMBOARD_SDK_VERSION = true ? "0.5.0-alpha.3" : "0.0.0-development";
|
|
57
|
+
var DREAMBOARD_SDK_PACKAGES = {
|
|
58
|
+
"@dreamboard-games/sdk": DREAMBOARD_SDK_VERSION
|
|
59
|
+
};
|
|
60
|
+
var DREAMBOARD_SDK_PACKAGE_SET = {
|
|
61
|
+
version: 1,
|
|
62
|
+
sdkVersion: DREAMBOARD_SDK_VERSION,
|
|
63
|
+
packages: DREAMBOARD_SDK_PACKAGES
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/headless/sources/iframe.ts
|
|
67
|
+
function iframeSource(options = {}) {
|
|
68
|
+
const target = window;
|
|
69
|
+
const parent = target.parent;
|
|
70
|
+
let channel = null;
|
|
71
|
+
let sequence = 0;
|
|
72
|
+
let receivedSequence = -1;
|
|
73
|
+
const send = (payload) => {
|
|
74
|
+
if (!channel) throw new Error("Iframe source is not initialized.");
|
|
75
|
+
parent.postMessage(
|
|
76
|
+
{
|
|
77
|
+
protocol: DREAMBOARD_PLUGIN_PROTOCOL,
|
|
78
|
+
version: DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
|
|
79
|
+
channelId: channel.id,
|
|
80
|
+
sequence: ++sequence,
|
|
81
|
+
payload
|
|
82
|
+
},
|
|
83
|
+
channel.origin
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
const lifecycle = createSourceLifecycle({
|
|
87
|
+
timeoutMs: options.timeoutMs,
|
|
88
|
+
send,
|
|
89
|
+
recover: () => send({ type: "runtime.resume" }),
|
|
90
|
+
close: () => target.removeEventListener("message", receive)
|
|
91
|
+
});
|
|
92
|
+
function receive(event) {
|
|
93
|
+
if (event.source !== parent) return;
|
|
94
|
+
const parsed = HostToPluginEnvelopeSchema.safeParse(event.data);
|
|
95
|
+
if (!parsed.success) {
|
|
96
|
+
const data = event.data;
|
|
97
|
+
if (channel && event.origin === channel.origin && typeof data === "object" && data !== null && "channelId" in data && data.channelId === channel.id) {
|
|
98
|
+
try {
|
|
99
|
+
send({
|
|
100
|
+
type: "runtime.error",
|
|
101
|
+
code: "host-runtime-protocol-mismatch",
|
|
102
|
+
message: "Iframe source received an invalid host envelope."
|
|
103
|
+
});
|
|
104
|
+
} finally {
|
|
105
|
+
lifecycle.fail(new Error("Invalid iframe host envelope."));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const envelope = parsed.data;
|
|
111
|
+
if (!channel) {
|
|
112
|
+
if (envelope.payload.type !== "runtime.init") return;
|
|
113
|
+
channel = { id: envelope.channelId, origin: event.origin };
|
|
114
|
+
}
|
|
115
|
+
if (channel.id !== envelope.channelId || channel.origin !== event.origin || envelope.sequence <= receivedSequence)
|
|
116
|
+
return;
|
|
117
|
+
receivedSequence = envelope.sequence;
|
|
118
|
+
const payload = envelope.payload;
|
|
119
|
+
if (payload.type === "runtime.init") {
|
|
120
|
+
lifecycle.session(payload.session);
|
|
121
|
+
if (lifecycle.source.store.get().connection !== "closed")
|
|
122
|
+
send({ type: "runtime.ready" });
|
|
123
|
+
} else if (payload.type === "gameplay.frame")
|
|
124
|
+
lifecycle.frame(payload.frame);
|
|
125
|
+
else lifecycle.result(payload);
|
|
126
|
+
if (lifecycle.source.store.get().connection !== "closed")
|
|
127
|
+
send({ type: "runtime.ack", sequence: envelope.sequence });
|
|
128
|
+
}
|
|
129
|
+
target.addEventListener("message", receive);
|
|
130
|
+
return lifecycle.source;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/shared/protocol/gameplay-wire.ts
|
|
134
|
+
import { z } from "zod";
|
|
135
|
+
var GameplayCloseCode = {
|
|
136
|
+
GoingAway: 1001,
|
|
137
|
+
CredentialExpired: 4e3,
|
|
138
|
+
CredentialInvalid: 4001,
|
|
139
|
+
RefreshContextMismatch: 4002,
|
|
140
|
+
PermissionDenied: 4100,
|
|
141
|
+
ProtocolViolation: 4200,
|
|
142
|
+
FrameBeforeAuth: 4201,
|
|
143
|
+
SlowConsumer: 4300,
|
|
144
|
+
TooManyRequests: 4301
|
|
145
|
+
};
|
|
146
|
+
var GameplayCredentialSchema = z.discriminatedUnion("kind", [
|
|
147
|
+
z.object({ kind: z.literal("user"), token: z.string().min(1).max(16384) }).strict(),
|
|
148
|
+
z.object({ kind: z.literal("demo"), secret: z.string().min(1).max(1024) }).strict()
|
|
149
|
+
]);
|
|
150
|
+
var AuthConnectFrameSchema = z.object({
|
|
151
|
+
type: z.literal("auth.connect"),
|
|
152
|
+
credential: GameplayCredentialSchema,
|
|
153
|
+
sessionId: z.string().uuid(),
|
|
154
|
+
playerId: z.string().min(1).max(128)
|
|
155
|
+
}).strict();
|
|
156
|
+
var AuthRefreshFrameSchema = z.object({
|
|
157
|
+
type: z.literal("auth.refresh"),
|
|
158
|
+
credential: GameplayCredentialSchema
|
|
159
|
+
}).strict();
|
|
160
|
+
var SessionResumeFrameSchema = z.object({
|
|
161
|
+
type: z.literal("session.resume"),
|
|
162
|
+
lastSeenLogCursor: z.number().int().nonnegative().nullable(),
|
|
163
|
+
unacknowledgedClientActionIds: z.array(z.string().min(1)).max(32)
|
|
164
|
+
});
|
|
165
|
+
var AuthAcceptedFrameSchema = z.object({
|
|
166
|
+
type: z.literal("auth.accepted"),
|
|
167
|
+
expiresAt: z.string().datetime()
|
|
168
|
+
});
|
|
169
|
+
var GameplayBackpressureReasonSchema = z.enum([
|
|
170
|
+
"queue_full",
|
|
171
|
+
"capacity_full"
|
|
172
|
+
]);
|
|
173
|
+
var GameplayBackpressureOperationSchema = z.enum([
|
|
174
|
+
"session.resume",
|
|
175
|
+
"interaction.submit",
|
|
176
|
+
"interaction.cancel"
|
|
177
|
+
]);
|
|
178
|
+
var GameplayBackpressureFrameSchema = z.object({
|
|
179
|
+
type: z.literal("gameplay.backpressure"),
|
|
180
|
+
reason: GameplayBackpressureReasonSchema,
|
|
181
|
+
retryAfterMs: z.number().int().positive(),
|
|
182
|
+
message: z.string().min(1),
|
|
183
|
+
operation: GameplayBackpressureOperationSchema,
|
|
184
|
+
clientActionId: z.string().min(1).optional()
|
|
185
|
+
});
|
|
186
|
+
var SessionSnapshotFrameSchema = z.object({
|
|
187
|
+
type: z.literal("session.snapshot"),
|
|
188
|
+
frame: PluginGameplayFrameSchema
|
|
189
|
+
});
|
|
190
|
+
var ClientGameplayFrameSchema = z.discriminatedUnion("type", [
|
|
191
|
+
AuthConnectFrameSchema,
|
|
192
|
+
AuthRefreshFrameSchema,
|
|
193
|
+
SessionResumeFrameSchema,
|
|
194
|
+
SubmitInteractionCommandSchema,
|
|
195
|
+
CancelInteractionCommandSchema
|
|
196
|
+
]);
|
|
197
|
+
var ServerGameplayFrameSchema = z.discriminatedUnion("type", [
|
|
198
|
+
AuthAcceptedFrameSchema,
|
|
199
|
+
GameplayBackpressureFrameSchema,
|
|
200
|
+
SessionSnapshotFrameSchema,
|
|
201
|
+
InteractionResultSchema
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
// src/headless/sources/host-websocket.ts
|
|
205
|
+
function hostSource(options) {
|
|
206
|
+
const { url, playerId, getCredential } = options;
|
|
207
|
+
const sessionId = options.session.sessionId;
|
|
208
|
+
let socket = null;
|
|
209
|
+
let generation = 0;
|
|
210
|
+
let disposed = false;
|
|
211
|
+
let authenticated = false;
|
|
212
|
+
let queued = null;
|
|
213
|
+
let reconnects = 0;
|
|
214
|
+
let refreshTimer;
|
|
215
|
+
let snapshotTimer;
|
|
216
|
+
let openTimer;
|
|
217
|
+
let cleanup = () => {
|
|
218
|
+
};
|
|
219
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
220
|
+
const send = (frame) => {
|
|
221
|
+
if (!socket || socket.readyState !== WebSocket.OPEN)
|
|
222
|
+
throw new Error("Gameplay socket is not open.");
|
|
223
|
+
socket.send(JSON.stringify(ClientGameplayFrameSchema.parse(frame)));
|
|
224
|
+
};
|
|
225
|
+
const resume = () => send({
|
|
226
|
+
type: "session.resume",
|
|
227
|
+
lastSeenLogCursor: null,
|
|
228
|
+
unacknowledgedClientActionIds: queued ? [queued.clientActionId] : []
|
|
229
|
+
});
|
|
230
|
+
const lifecycle = createSourceLifecycle({
|
|
231
|
+
context: {
|
|
232
|
+
sessionId,
|
|
233
|
+
playerId
|
|
234
|
+
},
|
|
235
|
+
timeoutMs,
|
|
236
|
+
send(command) {
|
|
237
|
+
if (!authenticated) {
|
|
238
|
+
queued = command;
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
send(command);
|
|
242
|
+
},
|
|
243
|
+
recover() {
|
|
244
|
+
if (authenticated) resume();
|
|
245
|
+
else if (!openTimer) void connect();
|
|
246
|
+
},
|
|
247
|
+
close() {
|
|
248
|
+
disposed = true;
|
|
249
|
+
generation++;
|
|
250
|
+
clearTimeout(refreshTimer);
|
|
251
|
+
clearTimeout(openTimer);
|
|
252
|
+
clearTimeout(snapshotTimer);
|
|
253
|
+
cleanup();
|
|
254
|
+
socket?.close();
|
|
255
|
+
socket = null;
|
|
256
|
+
queued = null;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
lifecycle.session(options.session);
|
|
260
|
+
async function connect() {
|
|
261
|
+
if (disposed) return;
|
|
262
|
+
const current = ++generation;
|
|
263
|
+
authenticated = false;
|
|
264
|
+
clearTimeout(refreshTimer);
|
|
265
|
+
clearTimeout(openTimer);
|
|
266
|
+
clearTimeout(snapshotTimer);
|
|
267
|
+
cleanup();
|
|
268
|
+
socket?.close();
|
|
269
|
+
socket = null;
|
|
270
|
+
openTimer = setTimeout(
|
|
271
|
+
() => lifecycle.fail(new Error("Gameplay socket authentication timed out.")),
|
|
272
|
+
timeoutMs
|
|
273
|
+
);
|
|
274
|
+
try {
|
|
275
|
+
const credential = await getCredential();
|
|
276
|
+
if (disposed || current !== generation) return;
|
|
277
|
+
const next = new WebSocket(url);
|
|
278
|
+
socket = next;
|
|
279
|
+
const active = () => !disposed && current === generation;
|
|
280
|
+
const onOpen = () => {
|
|
281
|
+
if (!active()) return;
|
|
282
|
+
try {
|
|
283
|
+
send({
|
|
284
|
+
type: "auth.connect",
|
|
285
|
+
credential,
|
|
286
|
+
sessionId,
|
|
287
|
+
playerId
|
|
288
|
+
});
|
|
289
|
+
} catch (error) {
|
|
290
|
+
lifecycle.fail(asError(error));
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const onMessage = (event) => {
|
|
294
|
+
if (!active()) return;
|
|
295
|
+
try {
|
|
296
|
+
const value = JSON.parse(String(event.data));
|
|
297
|
+
if (typeof value !== "object" || value === null || !("type" in value))
|
|
298
|
+
throw new Error("Invalid gameplay frame.");
|
|
299
|
+
if (![
|
|
300
|
+
"auth.accepted",
|
|
301
|
+
"session.snapshot",
|
|
302
|
+
"interaction.result",
|
|
303
|
+
"gameplay.backpressure"
|
|
304
|
+
].includes(String(value.type)))
|
|
305
|
+
return;
|
|
306
|
+
const frame = ServerGameplayFrameSchema.parse(value);
|
|
307
|
+
if (frame.type === "auth.accepted") {
|
|
308
|
+
clearTimeout(openTimer);
|
|
309
|
+
openTimer = void 0;
|
|
310
|
+
const first = !authenticated;
|
|
311
|
+
authenticated = true;
|
|
312
|
+
if (first) {
|
|
313
|
+
snapshotTimer = setTimeout(
|
|
314
|
+
() => lifecycle.fail(new Error("Gameplay snapshot timed out.")),
|
|
315
|
+
timeoutMs
|
|
316
|
+
);
|
|
317
|
+
resume();
|
|
318
|
+
if (queued) {
|
|
319
|
+
send(queued);
|
|
320
|
+
queued = null;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
clearTimeout(refreshTimer);
|
|
324
|
+
if (credential.kind === "user") {
|
|
325
|
+
const ttl = Date.parse(frame.expiresAt) - Date.now();
|
|
326
|
+
if (ttl <= 0)
|
|
327
|
+
throw new Error("Gameplay credential is already expired.");
|
|
328
|
+
refreshTimer = setTimeout(
|
|
329
|
+
() => {
|
|
330
|
+
openTimer = setTimeout(
|
|
331
|
+
() => lifecycle.fail(
|
|
332
|
+
new Error("Gameplay credential refresh timed out.")
|
|
333
|
+
),
|
|
334
|
+
timeoutMs
|
|
335
|
+
);
|
|
336
|
+
void getCredential().then((updated) => {
|
|
337
|
+
if (active())
|
|
338
|
+
send({ type: "auth.refresh", credential: updated });
|
|
339
|
+
}).catch((error) => {
|
|
340
|
+
if (active()) lifecycle.fail(asError(error));
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
Math.max(0, ttl - Math.min(6e4, ttl * 0.2))
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
} else if (!authenticated)
|
|
347
|
+
throw new Error("Gameplay frame arrived before authentication.");
|
|
348
|
+
else if (frame.type === "session.snapshot") {
|
|
349
|
+
clearTimeout(snapshotTimer);
|
|
350
|
+
snapshotTimer = void 0;
|
|
351
|
+
reconnects = 0;
|
|
352
|
+
lifecycle.frame(frame.frame);
|
|
353
|
+
} else if (frame.type === "interaction.result")
|
|
354
|
+
lifecycle.result(frame);
|
|
355
|
+
else lifecycle.fail(new Error(frame.message));
|
|
356
|
+
} catch (error) {
|
|
357
|
+
lifecycle.fail(asError(error));
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const onClose = (event) => {
|
|
361
|
+
if (!active()) return;
|
|
362
|
+
authenticated = false;
|
|
363
|
+
lifecycle.recovering();
|
|
364
|
+
if ((/* @__PURE__ */ new Set([
|
|
365
|
+
GameplayCloseCode.CredentialInvalid,
|
|
366
|
+
GameplayCloseCode.RefreshContextMismatch,
|
|
367
|
+
GameplayCloseCode.PermissionDenied,
|
|
368
|
+
GameplayCloseCode.ProtocolViolation,
|
|
369
|
+
GameplayCloseCode.FrameBeforeAuth
|
|
370
|
+
])).has(event.code) || reconnects++ > 0) {
|
|
371
|
+
lifecycle.fail(new Error(`Gameplay socket closed (${event.code}).`));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
void connect();
|
|
375
|
+
lifecycle.retry();
|
|
376
|
+
};
|
|
377
|
+
const onError = () => {
|
|
378
|
+
if (active()) next.close();
|
|
379
|
+
};
|
|
380
|
+
next.addEventListener("open", onOpen);
|
|
381
|
+
next.addEventListener("message", onMessage);
|
|
382
|
+
next.addEventListener("close", onClose);
|
|
383
|
+
next.addEventListener("error", onError);
|
|
384
|
+
cleanup = () => {
|
|
385
|
+
next.removeEventListener("open", onOpen);
|
|
386
|
+
next.removeEventListener("message", onMessage);
|
|
387
|
+
next.removeEventListener("close", onClose);
|
|
388
|
+
next.removeEventListener("error", onError);
|
|
389
|
+
};
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (!disposed && current === generation) lifecycle.fail(asError(error));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
void connect();
|
|
395
|
+
return lifecycle.source;
|
|
396
|
+
}
|
|
397
|
+
function asError(error) {
|
|
398
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/headless/features/hand.ts
|
|
402
|
+
function handFeature(_game, options = {}) {
|
|
403
|
+
return {
|
|
404
|
+
zone: {
|
|
405
|
+
getSortedCardIds() {
|
|
406
|
+
return this.getCards({ sort: options.sort }).map((card) => card.id);
|
|
407
|
+
},
|
|
408
|
+
getSelectedCardIds() {
|
|
409
|
+
return this.getCards().filter((card) => card.getIsSelected()).map((card) => card.id);
|
|
410
|
+
},
|
|
411
|
+
getSelectableCardIds() {
|
|
412
|
+
return this.getCards().filter((card) => card.getCanSelect()).map((card) => card.id);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// src/headless/features/board.ts
|
|
419
|
+
function squareGeometry(board, size, origin) {
|
|
420
|
+
const spaces = Object.values(board.spaces).map((space) => {
|
|
421
|
+
const x2 = origin.x + space.col * size;
|
|
422
|
+
const y2 = origin.y + space.row * size;
|
|
423
|
+
return {
|
|
424
|
+
id: space.id,
|
|
425
|
+
center: { x: x2 + size / 2, y: y2 + size / 2 },
|
|
426
|
+
corners: [
|
|
427
|
+
{ x: x2, y: y2 },
|
|
428
|
+
{ x: x2 + size, y: y2 },
|
|
429
|
+
{ x: x2 + size, y: y2 + size },
|
|
430
|
+
{ x: x2, y: y2 + size }
|
|
431
|
+
]
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
const byId = new Map(spaces.map((space) => [space.id, space]));
|
|
435
|
+
function sharedCorners(ids) {
|
|
436
|
+
const first = byId.get(ids[0] ?? "")?.corners ?? [];
|
|
437
|
+
return first.filter(
|
|
438
|
+
(point) => ids.every(
|
|
439
|
+
(id) => byId.get(id)?.corners.some(
|
|
440
|
+
(candidate) => candidate.x === point.x && candidate.y === point.y
|
|
441
|
+
)
|
|
442
|
+
)
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
const points = spaces.flatMap((space) => space.corners);
|
|
446
|
+
const xs = points.map((point) => point.x);
|
|
447
|
+
const ys = points.map((point) => point.y);
|
|
448
|
+
const x = xs.length ? Math.min(...xs) : 0;
|
|
449
|
+
const y = ys.length ? Math.min(...ys) : 0;
|
|
450
|
+
return {
|
|
451
|
+
viewBox: {
|
|
452
|
+
x,
|
|
453
|
+
y,
|
|
454
|
+
width: xs.length ? Math.max(...xs) - x : 0,
|
|
455
|
+
height: ys.length ? Math.max(...ys) - y : 0
|
|
456
|
+
},
|
|
457
|
+
spaces,
|
|
458
|
+
// Incidence is authored. Only a unique geometric line/point is representable.
|
|
459
|
+
edges: board.edges.flatMap((edge) => {
|
|
460
|
+
const corners = sharedCorners(edge.spaceIds);
|
|
461
|
+
return corners.length === 2 ? [{ id: edge.id, from: corners[0], to: corners[1] }] : [];
|
|
462
|
+
}),
|
|
463
|
+
vertices: board.vertices.flatMap((vertex) => {
|
|
464
|
+
const corners = sharedCorners(vertex.spaceIds);
|
|
465
|
+
return corners.length === 1 ? [{ id: vertex.id, center: corners[0] }] : [];
|
|
466
|
+
}),
|
|
467
|
+
pointToSpace(point) {
|
|
468
|
+
const col = Math.floor((point.x - origin.x) / size);
|
|
469
|
+
const row = Math.floor((point.y - origin.y) / size);
|
|
470
|
+
return Object.values(board.spaces).find(
|
|
471
|
+
(space) => space.col === col && space.row === row
|
|
472
|
+
)?.id;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function boardFeature(game, context) {
|
|
477
|
+
const captures = /* @__PURE__ */ new WeakMap();
|
|
478
|
+
const geometries = /* @__PURE__ */ new WeakMap();
|
|
479
|
+
let cached;
|
|
480
|
+
function collection() {
|
|
481
|
+
const model = game.getSnapshot();
|
|
482
|
+
const source = game.getOptions().source;
|
|
483
|
+
if (cached?.view === model.view && cached.interactions === model.interactions && cached.source === source)
|
|
484
|
+
return cached.collection;
|
|
485
|
+
const projected = model.view;
|
|
486
|
+
const boards = Object.values(projected?.boards?.byId ?? {}).map((data) => {
|
|
487
|
+
const board = context.createBoard(data.id, data);
|
|
488
|
+
let geometry = geometries.get(data);
|
|
489
|
+
if (!geometry && data.layout === "hex") {
|
|
490
|
+
geometry = createHexBoardGeometry({
|
|
491
|
+
id: data.baseId ?? data.id,
|
|
492
|
+
orientation: data.orientation,
|
|
493
|
+
spaces: Object.values(data.spaces)
|
|
494
|
+
});
|
|
495
|
+
geometries.set(data, geometry);
|
|
496
|
+
}
|
|
497
|
+
captures.set(board, { model, source, geometry });
|
|
498
|
+
return board;
|
|
499
|
+
});
|
|
500
|
+
const byId = new Map(boards.map((board) => [board.id, board]));
|
|
501
|
+
const result = Object.freeze({
|
|
502
|
+
get(id) {
|
|
503
|
+
return byId.get(id);
|
|
504
|
+
},
|
|
505
|
+
getAll: () => Object.freeze(boards)
|
|
506
|
+
});
|
|
507
|
+
cached = {
|
|
508
|
+
view: model.view,
|
|
509
|
+
interactions: model.interactions,
|
|
510
|
+
source,
|
|
511
|
+
collection: result
|
|
512
|
+
};
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
root: {
|
|
517
|
+
get boards() {
|
|
518
|
+
return collection();
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
board: {
|
|
522
|
+
getLayout(options) {
|
|
523
|
+
const board = this.data;
|
|
524
|
+
if (board.layout === "generic")
|
|
525
|
+
throw new Error(
|
|
526
|
+
`Board '${board.id}' has no spatial geometry; read its data instead.`
|
|
527
|
+
);
|
|
528
|
+
const {
|
|
529
|
+
hexSize,
|
|
530
|
+
origin: suppliedOrigin = { x: 0, y: 0 },
|
|
531
|
+
viewport: suppliedViewport = { x: 0, y: 0, scale: 1 }
|
|
532
|
+
} = options;
|
|
533
|
+
const origin = { ...suppliedOrigin };
|
|
534
|
+
const viewport = { ...suppliedViewport };
|
|
535
|
+
if (!Number.isFinite(hexSize) || hexSize <= 0)
|
|
536
|
+
throw new Error("hexSize must be positive and finite.");
|
|
537
|
+
if (![origin.x, origin.y, viewport.x, viewport.y, viewport.scale].every(
|
|
538
|
+
Number.isFinite
|
|
539
|
+
) || viewport.scale <= 0)
|
|
540
|
+
throw new Error(
|
|
541
|
+
"Layout transform must be finite with positive scale."
|
|
542
|
+
);
|
|
543
|
+
const captured = captures.get(this);
|
|
544
|
+
const geometry = board.layout === "hex" ? captured.geometry.getLayout({ hexSize, origin }) : squareGeometry(board, hexSize, origin);
|
|
545
|
+
const point = (value) => Object.freeze({
|
|
546
|
+
x: value.x * viewport.scale + viewport.x,
|
|
547
|
+
y: value.y * viewport.scale + viewport.y
|
|
548
|
+
});
|
|
549
|
+
function matchingTargets(model, kind) {
|
|
550
|
+
const inputKinds = kind === "space" ? ["space", "tile"] : [kind];
|
|
551
|
+
return model.interactions.list().flatMap(
|
|
552
|
+
(interaction) => interaction.getInputs().filter((input) => {
|
|
553
|
+
const domain = input.getDomain();
|
|
554
|
+
return domain.type === "boardTarget" && inputKinds.includes(String(domain.targetKind)) && (domain.boardId === board.id || domain.boardId === board.baseId) && (board.scope !== "perPlayer" || board.playerId === model.me?.id);
|
|
555
|
+
}).map((input) => ({ interaction, input }))
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
function target(kind, id) {
|
|
559
|
+
const matches = matchingTargets(captured.model, kind);
|
|
560
|
+
const eligible = matches.some(({ input }) => input.getIsEligible(id));
|
|
561
|
+
const selected = matches.some(({ input }) => input.getIsSelected(id));
|
|
562
|
+
const selectable = matches.some(
|
|
563
|
+
({ input }) => !input.getTargetProps(id).disabled
|
|
564
|
+
);
|
|
565
|
+
function select(options2) {
|
|
566
|
+
if (game.getOptions().source !== captured.source || game.snapshot?.me !== captured.model.snapshot?.me)
|
|
567
|
+
return;
|
|
568
|
+
const matching = matchingTargets(game.getSnapshot(), kind).filter(
|
|
569
|
+
({ interaction, input }) => (!options2?.interaction || options2.interaction === interaction.key) && !input.getTargetProps(id).disabled
|
|
570
|
+
);
|
|
571
|
+
if (!matching.length) return;
|
|
572
|
+
const domain = matching[0].input.getDomain();
|
|
573
|
+
if (domain.type !== "boardTarget") return;
|
|
574
|
+
context.routeTarget(kind, id, {
|
|
575
|
+
...options2,
|
|
576
|
+
boardId: String(domain.boardId)
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return {
|
|
580
|
+
id,
|
|
581
|
+
getIsEligible: () => eligible,
|
|
582
|
+
getIsSelectable: () => selectable,
|
|
583
|
+
getIsSelected: () => selected,
|
|
584
|
+
getSelectHandler: (options2) => () => select(options2),
|
|
585
|
+
getTargetProps(options2) {
|
|
586
|
+
const candidates = matches.filter(
|
|
587
|
+
({ interaction, input }) => (!options2?.interaction || interaction.key === options2.interaction) && !input.getTargetProps(id).disabled
|
|
588
|
+
);
|
|
589
|
+
const only = candidates.length === 1 ? candidates[0] : void 0;
|
|
590
|
+
return {
|
|
591
|
+
type: "button",
|
|
592
|
+
disabled: candidates.length === 0,
|
|
593
|
+
"data-action": "select",
|
|
594
|
+
"data-value": id,
|
|
595
|
+
"data-board": board.id,
|
|
596
|
+
"data-interaction": options2?.interaction ?? only?.interaction.key,
|
|
597
|
+
"data-input": only?.input.key,
|
|
598
|
+
"data-eligible": eligible,
|
|
599
|
+
"data-selected": selected,
|
|
600
|
+
"data-disabled": candidates.length === 0,
|
|
601
|
+
onClick: () => select(options2)
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
const spaces = Object.freeze(
|
|
607
|
+
geometry.spaces.map((space) => {
|
|
608
|
+
const corners = Object.freeze(space.corners.map(point));
|
|
609
|
+
const center = point(space.center);
|
|
610
|
+
return Object.freeze({
|
|
611
|
+
...target("space", space.id),
|
|
612
|
+
data: board.spaces[space.id],
|
|
613
|
+
center,
|
|
614
|
+
points: () => corners,
|
|
615
|
+
transform: `translate(${center.x} ${center.y})`
|
|
616
|
+
});
|
|
617
|
+
})
|
|
618
|
+
);
|
|
619
|
+
const edges = Object.freeze(
|
|
620
|
+
geometry.edges.map(
|
|
621
|
+
(edge) => Object.freeze({
|
|
622
|
+
...target("edge", edge.id),
|
|
623
|
+
data: board.edges.find((data) => data.id === edge.id),
|
|
624
|
+
center: point({
|
|
625
|
+
x: (edge.from.x + edge.to.x) / 2,
|
|
626
|
+
y: (edge.from.y + edge.to.y) / 2
|
|
627
|
+
}),
|
|
628
|
+
line: Object.freeze([point(edge.from), point(edge.to)])
|
|
629
|
+
})
|
|
630
|
+
)
|
|
631
|
+
);
|
|
632
|
+
const vertices = Object.freeze(
|
|
633
|
+
geometry.vertices.map(
|
|
634
|
+
(vertex) => Object.freeze({
|
|
635
|
+
...target("vertex", vertex.id),
|
|
636
|
+
data: board.vertices.find((data) => data.id === vertex.id),
|
|
637
|
+
center: point(vertex.center)
|
|
638
|
+
})
|
|
639
|
+
)
|
|
640
|
+
);
|
|
641
|
+
return Object.freeze({
|
|
642
|
+
viewBox: Object.freeze({ ...geometry.viewBox }),
|
|
643
|
+
getSpaces: () => spaces,
|
|
644
|
+
getEdges: () => edges,
|
|
645
|
+
getVertices: () => vertices,
|
|
646
|
+
pointToSpace(x, y) {
|
|
647
|
+
return geometry.pointToSpace({
|
|
648
|
+
x: (x - viewport.x) / viewport.scale,
|
|
649
|
+
y: (y - viewport.y) / viewport.scale
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/headless/features/pointer-session.ts
|
|
659
|
+
function createPointerSession(callbacks) {
|
|
660
|
+
let disposed = false;
|
|
661
|
+
let active;
|
|
662
|
+
function value() {
|
|
663
|
+
const { origin, point } = active;
|
|
664
|
+
return {
|
|
665
|
+
origin,
|
|
666
|
+
point,
|
|
667
|
+
delta: { x: point.x - origin.x, y: point.y - origin.y }
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function release() {
|
|
671
|
+
const previous = active;
|
|
672
|
+
active = void 0;
|
|
673
|
+
if (previous?.surface.hasPointerCapture(previous.id)) {
|
|
674
|
+
previous.surface.releasePointerCapture(previous.id);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function cancel() {
|
|
678
|
+
if (!active) return;
|
|
679
|
+
release();
|
|
680
|
+
callbacks.cancel();
|
|
681
|
+
}
|
|
682
|
+
return {
|
|
683
|
+
start(event) {
|
|
684
|
+
if (disposed || active || event.button !== 0) return false;
|
|
685
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
686
|
+
const point = { x: event.clientX, y: event.clientY };
|
|
687
|
+
active = {
|
|
688
|
+
id: event.pointerId,
|
|
689
|
+
surface: event.currentTarget,
|
|
690
|
+
origin: point,
|
|
691
|
+
point
|
|
692
|
+
};
|
|
693
|
+
event.preventDefault();
|
|
694
|
+
return true;
|
|
695
|
+
},
|
|
696
|
+
move(event) {
|
|
697
|
+
if (event.pointerId !== active?.id) return;
|
|
698
|
+
active.point = { x: event.clientX, y: event.clientY };
|
|
699
|
+
event.preventDefault();
|
|
700
|
+
callbacks.move(value());
|
|
701
|
+
},
|
|
702
|
+
end(event) {
|
|
703
|
+
if (event.pointerId !== active?.id) return;
|
|
704
|
+
active.point = { x: event.clientX, y: event.clientY };
|
|
705
|
+
const result = value();
|
|
706
|
+
release();
|
|
707
|
+
callbacks.end(result);
|
|
708
|
+
},
|
|
709
|
+
cancel(event) {
|
|
710
|
+
if (event && event.pointerId !== active?.id) return;
|
|
711
|
+
cancel();
|
|
712
|
+
},
|
|
713
|
+
dispose() {
|
|
714
|
+
disposed = true;
|
|
715
|
+
cancel();
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// src/headless/features/drag.ts
|
|
721
|
+
function dragFeature(game, context) {
|
|
722
|
+
let active = null;
|
|
723
|
+
let interaction;
|
|
724
|
+
let source = game.getOptions().source;
|
|
725
|
+
let seat = game.snapshot?.me;
|
|
726
|
+
let disposed = false;
|
|
727
|
+
let suppressPointerClick = false;
|
|
728
|
+
let dragged = false;
|
|
729
|
+
let lastInteractions = game.interactions;
|
|
730
|
+
let lastCards = game.cards;
|
|
731
|
+
let branch = snapshot();
|
|
732
|
+
function update(next) {
|
|
733
|
+
if (disposed) return;
|
|
734
|
+
active = next === null ? null : Object.freeze({ ...next, offset: Object.freeze(next.offset) });
|
|
735
|
+
branch = snapshot();
|
|
736
|
+
context.invalidate();
|
|
737
|
+
}
|
|
738
|
+
function targets() {
|
|
739
|
+
if (!active) return [];
|
|
740
|
+
const cardId = active.cardId;
|
|
741
|
+
return (game.cards.get(cardId)?.getInteractions() ?? []).filter(
|
|
742
|
+
(candidate) => candidate.getIsAvailable() && (!interaction || candidate.key === interaction) && candidate.getInputs().some(
|
|
743
|
+
(input) => input.getDomain().type === "cardTarget" && input.getIsEligible(cardId)
|
|
744
|
+
)
|
|
745
|
+
).flatMap(
|
|
746
|
+
(candidate) => candidate.getInputs().flatMap((input) => {
|
|
747
|
+
const domain = input.getDomain();
|
|
748
|
+
if (domain.type !== "boardTarget" || !["space", "edge", "vertex", "tile"].includes(
|
|
749
|
+
String(domain.targetKind)
|
|
750
|
+
))
|
|
751
|
+
return [];
|
|
752
|
+
return input.getEligibleTargets().filter(
|
|
753
|
+
(id) => typeof id === "string" && !input.getTargetProps(id).disabled
|
|
754
|
+
).map(
|
|
755
|
+
(id) => Object.freeze({
|
|
756
|
+
kind: domain.targetKind,
|
|
757
|
+
id,
|
|
758
|
+
boardId: String(domain.boardId),
|
|
759
|
+
interaction: candidate.key
|
|
760
|
+
})
|
|
761
|
+
);
|
|
762
|
+
})
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
function sameTarget(left, right) {
|
|
766
|
+
return left.kind === right.kind && left.id === right.id && left.boardId === right.boardId && left.interaction === right.interaction;
|
|
767
|
+
}
|
|
768
|
+
const pointer = createPointerSession({
|
|
769
|
+
move: ({ delta }) => {
|
|
770
|
+
if (Math.hypot(delta.x, delta.y) >= 5) dragged = true;
|
|
771
|
+
if (active) update({ ...active, offset: delta });
|
|
772
|
+
},
|
|
773
|
+
end({ delta }) {
|
|
774
|
+
if (Math.hypot(delta.x, delta.y) >= 5) dragged = true;
|
|
775
|
+
suppressPointerClick = true;
|
|
776
|
+
const finished = active;
|
|
777
|
+
update(null);
|
|
778
|
+
if (!finished) return;
|
|
779
|
+
if (dragged) {
|
|
780
|
+
if (finished.target)
|
|
781
|
+
context.routeCardDrop(finished.cardId, finished.target);
|
|
782
|
+
} else context.routeTarget("card", finished.cardId, { interaction });
|
|
783
|
+
},
|
|
784
|
+
cancel: () => {
|
|
785
|
+
suppressPointerClick = true;
|
|
786
|
+
update(null);
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
function snapshot() {
|
|
790
|
+
const captured = active;
|
|
791
|
+
const dropTargets = Object.freeze(targets());
|
|
792
|
+
return Object.freeze({
|
|
793
|
+
active: captured,
|
|
794
|
+
getDropTargets: () => dropTargets,
|
|
795
|
+
setDropTarget(target) {
|
|
796
|
+
if (!active || disposed) return;
|
|
797
|
+
if (target && !targets().some((candidate) => sameTarget(candidate, target)))
|
|
798
|
+
return;
|
|
799
|
+
update({ ...active, target });
|
|
800
|
+
},
|
|
801
|
+
cancel: () => pointer.cancel()
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
const unsubscribe = game.subscribe(() => {
|
|
805
|
+
const nextSource = game.getOptions().source;
|
|
806
|
+
const nextSeat = game.snapshot?.me;
|
|
807
|
+
if (nextSource !== source || nextSeat !== seat) {
|
|
808
|
+
source = nextSource;
|
|
809
|
+
seat = nextSeat;
|
|
810
|
+
pointer.cancel();
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
return {
|
|
814
|
+
root: {
|
|
815
|
+
get drag() {
|
|
816
|
+
if (lastInteractions !== game.interactions || lastCards !== game.cards) {
|
|
817
|
+
lastInteractions = game.interactions;
|
|
818
|
+
lastCards = game.cards;
|
|
819
|
+
branch = snapshot();
|
|
820
|
+
}
|
|
821
|
+
return branch;
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
card: {
|
|
825
|
+
getDragProps(options) {
|
|
826
|
+
return {
|
|
827
|
+
style: {
|
|
828
|
+
touchAction: "none",
|
|
829
|
+
transform: active?.cardId === this.id ? `translate(${active.offset.x}px, ${active.offset.y}px)` : void 0
|
|
830
|
+
},
|
|
831
|
+
"data-drag-card": this.id,
|
|
832
|
+
onPointerDown: (event) => {
|
|
833
|
+
if (disposed || game.cards.get(this.id) !== this || !this.getCanSelect())
|
|
834
|
+
return;
|
|
835
|
+
if (!pointer.start(event)) return;
|
|
836
|
+
suppressPointerClick = false;
|
|
837
|
+
dragged = false;
|
|
838
|
+
interaction = options?.interaction;
|
|
839
|
+
update({ cardId: this.id, offset: { x: 0, y: 0 }, target: null });
|
|
840
|
+
},
|
|
841
|
+
onClick: (event) => {
|
|
842
|
+
if (disposed) return;
|
|
843
|
+
if (event.detail !== 0 && suppressPointerClick) {
|
|
844
|
+
suppressPointerClick = false;
|
|
845
|
+
event.preventDefault();
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
this.select(options);
|
|
849
|
+
},
|
|
850
|
+
onPointerMove: pointer.move,
|
|
851
|
+
onPointerUp: pointer.end,
|
|
852
|
+
onPointerCancel: pointer.cancel,
|
|
853
|
+
onLostPointerCapture: pointer.cancel
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
dispose() {
|
|
858
|
+
unsubscribe();
|
|
859
|
+
pointer.dispose();
|
|
860
|
+
disposed = true;
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// src/headless/features/pan-zoom.ts
|
|
866
|
+
function panZoomFeature(game, context, options = {}) {
|
|
867
|
+
const minScale = options.minScale ?? 0.25;
|
|
868
|
+
const maxScale = options.maxScale ?? 4;
|
|
869
|
+
if (!Number.isFinite(minScale) || !Number.isFinite(maxScale) || minScale <= 0 || maxScale < minScale) {
|
|
870
|
+
throw new Error(
|
|
871
|
+
"Viewport scale limits must be positive, finite, and ordered."
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
const initial = options.initial ?? { x: 0, y: 0, scale: 1 };
|
|
875
|
+
let disposed = false;
|
|
876
|
+
let source = game.getOptions().source;
|
|
877
|
+
let seat = game.snapshot?.me;
|
|
878
|
+
let dragOrigin = initial;
|
|
879
|
+
let transform = admit(initial);
|
|
880
|
+
let branch = snapshot();
|
|
881
|
+
function admit(value) {
|
|
882
|
+
if (![value.x, value.y, value.scale].every(Number.isFinite) || value.scale <= 0) {
|
|
883
|
+
throw new Error(
|
|
884
|
+
"Viewport transform must have finite coordinates and positive scale."
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
return Object.freeze({
|
|
888
|
+
x: value.x,
|
|
889
|
+
y: value.y,
|
|
890
|
+
scale: Math.min(maxScale, Math.max(minScale, value.scale))
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
function update(value) {
|
|
894
|
+
if (disposed) return;
|
|
895
|
+
const next = admit(value);
|
|
896
|
+
if (next.x === transform.x && next.y === transform.y && next.scale === transform.scale)
|
|
897
|
+
return;
|
|
898
|
+
transform = next;
|
|
899
|
+
branch = snapshot();
|
|
900
|
+
context.invalidate();
|
|
901
|
+
}
|
|
902
|
+
const pointer = createPointerSession({
|
|
903
|
+
move: ({ delta }) => update({
|
|
904
|
+
...dragOrigin,
|
|
905
|
+
x: dragOrigin.x + delta.x,
|
|
906
|
+
y: dragOrigin.y + delta.y
|
|
907
|
+
}),
|
|
908
|
+
end: ({ delta }) => update({
|
|
909
|
+
...dragOrigin,
|
|
910
|
+
x: dragOrigin.x + delta.x,
|
|
911
|
+
y: dragOrigin.y + delta.y
|
|
912
|
+
}),
|
|
913
|
+
cancel() {
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
function props() {
|
|
917
|
+
return {
|
|
918
|
+
style: { touchAction: "none" },
|
|
919
|
+
onPointerDown(event) {
|
|
920
|
+
if (pointer.start(event)) dragOrigin = transform;
|
|
921
|
+
},
|
|
922
|
+
onPointerMove: pointer.move,
|
|
923
|
+
onPointerUp: pointer.end,
|
|
924
|
+
onPointerCancel: pointer.cancel,
|
|
925
|
+
onLostPointerCapture: pointer.cancel,
|
|
926
|
+
onWheel(event) {
|
|
927
|
+
if (disposed) return;
|
|
928
|
+
event.preventDefault();
|
|
929
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
930
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? rect.height : 1;
|
|
931
|
+
const scale = Math.min(
|
|
932
|
+
maxScale,
|
|
933
|
+
Math.max(
|
|
934
|
+
minScale,
|
|
935
|
+
transform.scale * Math.exp(-event.deltaY * unit * 2e-3)
|
|
936
|
+
)
|
|
937
|
+
);
|
|
938
|
+
const x = event.clientX - rect.left;
|
|
939
|
+
const y = event.clientY - rect.top;
|
|
940
|
+
const ratio = scale / transform.scale;
|
|
941
|
+
update({
|
|
942
|
+
x: x - (x - transform.x) * ratio,
|
|
943
|
+
y: y - (y - transform.y) * ratio,
|
|
944
|
+
scale
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function snapshot() {
|
|
950
|
+
const captured = transform;
|
|
951
|
+
return Object.freeze({
|
|
952
|
+
transform: captured,
|
|
953
|
+
getTransform: () => captured,
|
|
954
|
+
getProps: props,
|
|
955
|
+
setTransform: update,
|
|
956
|
+
reset: () => {
|
|
957
|
+
pointer.cancel();
|
|
958
|
+
update(initial);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
const unsubscribe = game.subscribe(() => {
|
|
963
|
+
const nextSource = game.getOptions().source;
|
|
964
|
+
const nextSeat = game.snapshot?.me;
|
|
965
|
+
if (nextSource !== source || nextSeat !== seat) {
|
|
966
|
+
source = nextSource;
|
|
967
|
+
seat = nextSeat;
|
|
968
|
+
pointer.cancel();
|
|
969
|
+
update(initial);
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
return {
|
|
973
|
+
root: {
|
|
974
|
+
get viewport() {
|
|
975
|
+
return branch;
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
dispose() {
|
|
979
|
+
disposed = true;
|
|
980
|
+
unsubscribe();
|
|
981
|
+
pointer.dispose();
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
}
|
|
7
985
|
export {
|
|
986
|
+
AmbiguousTargetError,
|
|
987
|
+
AuthAcceptedFrameSchema,
|
|
988
|
+
AuthConnectFrameSchema,
|
|
989
|
+
AuthRefreshFrameSchema,
|
|
990
|
+
BoardStaticProjectionSchema,
|
|
991
|
+
CancelInteractionCommandSchema,
|
|
992
|
+
ClientGameplayFrameSchema,
|
|
993
|
+
DREAMBOARD_PLUGIN_PROTOCOL,
|
|
994
|
+
DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
|
|
8
995
|
DREAMBOARD_SDK_PACKAGES,
|
|
9
996
|
DREAMBOARD_SDK_PACKAGE_SET,
|
|
10
|
-
DREAMBOARD_SDK_VERSION
|
|
997
|
+
DREAMBOARD_SDK_VERSION,
|
|
998
|
+
GameEventDetailSchema,
|
|
999
|
+
GameEventSchema,
|
|
1000
|
+
GameOutcomeSchema,
|
|
1001
|
+
GameplayBackpressureFrameSchema,
|
|
1002
|
+
GameplayBackpressureOperationSchema,
|
|
1003
|
+
GameplayBackpressureReasonSchema,
|
|
1004
|
+
GameplayBasisSchema,
|
|
1005
|
+
GameplayCloseCode,
|
|
1006
|
+
GameplayCredentialSchema,
|
|
1007
|
+
HostToPluginEnvelopeSchema,
|
|
1008
|
+
HostToPluginPayloadSchema,
|
|
1009
|
+
InputDomainSchema,
|
|
1010
|
+
InteractionAvailabilitySchema,
|
|
1011
|
+
InteractionCommitPolicySchema,
|
|
1012
|
+
InteractionDescriptorSchema,
|
|
1013
|
+
InteractionInputDescriptorSchema,
|
|
1014
|
+
InteractionResultSchema,
|
|
1015
|
+
PluginGameplayFrameSchema,
|
|
1016
|
+
PluginPlayerSummarySchema,
|
|
1017
|
+
PluginSessionDescriptorSchema,
|
|
1018
|
+
PluginToHostEnvelopeSchema,
|
|
1019
|
+
PluginToHostPayloadSchema,
|
|
1020
|
+
RuntimeJsonSchema,
|
|
1021
|
+
SeatFrameSchema,
|
|
1022
|
+
SeatProjectionBundleSchema,
|
|
1023
|
+
ServerGameplayFrameSchema,
|
|
1024
|
+
SessionResumeFrameSchema,
|
|
1025
|
+
SessionSnapshotFrameSchema,
|
|
1026
|
+
SimultaneousPhaseSnapshotSchema,
|
|
1027
|
+
SubmitInteractionCommandSchema,
|
|
1028
|
+
SystemActionEventSchema,
|
|
1029
|
+
ZoneHandlesSnapshotSchema,
|
|
1030
|
+
boardFeature,
|
|
1031
|
+
canonicalizePluginRuntimeJson,
|
|
1032
|
+
computePluginActionSetVersion,
|
|
1033
|
+
createGameInstance,
|
|
1034
|
+
createPluginProtocolEnvelopeSchema,
|
|
1035
|
+
digestPluginCommandRequest,
|
|
1036
|
+
digestPluginGameplayFrame,
|
|
1037
|
+
digestPluginRuntimeJson,
|
|
1038
|
+
dragFeature,
|
|
1039
|
+
encodeCanonicalPluginRuntimeJson,
|
|
1040
|
+
handFeature,
|
|
1041
|
+
hostSource,
|
|
1042
|
+
iframeSource,
|
|
1043
|
+
materializePluginGameplayFrame,
|
|
1044
|
+
panZoomFeature,
|
|
1045
|
+
parseHostToPluginEnvelope,
|
|
1046
|
+
parsePluginGameplayFrame,
|
|
1047
|
+
parsePluginSessionDescriptor,
|
|
1048
|
+
parsePluginToHostEnvelope,
|
|
1049
|
+
staticSource
|
|
11
1050
|
};
|
|
12
1051
|
//# sourceMappingURL=index.js.map
|