@dreamboard-games/sdk 0.4.0-alpha.1 → 0.4.0-alpha.2
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/REFERENCE.md +1215 -125
- package/dist/{ResourceCounter-BTXklCEZ.d.ts → ResourceCounter-BuiNstXs.d.ts} +5 -1
- package/dist/{ThemeProvider-DvMl17Ny.d.ts → ThemeProvider-B1sIoBlX.d.ts} +1 -1
- package/dist/{attributes-BrZtP9az.d.ts → attributes-DbvyMbXw.d.ts} +17 -2
- package/dist/authoring/index.d.ts +66 -0
- package/dist/authoring/index.js +560 -0
- package/dist/authoring/index.js.map +1 -0
- package/dist/browser-interaction.d.ts +205 -5
- package/dist/browser-interaction.js +14 -2
- package/dist/{chunk-7W6TQO3X.js → chunk-45FI6XII.js} +613 -366
- package/dist/chunk-45FI6XII.js.map +1 -0
- package/dist/{chunk-3K362ZKR.js → chunk-6JQFGSLD.js} +202 -38
- package/dist/chunk-6JQFGSLD.js.map +1 -0
- package/dist/{chunk-XXBSIPJX.js → chunk-CP35NPPY.js} +131 -59
- package/dist/chunk-CP35NPPY.js.map +1 -0
- package/dist/{chunk-XJYUSD5F.js → chunk-FWVV2X74.js} +2 -2
- package/dist/{chunk-IUGKW2GS.js → chunk-HWJS3VOJ.js} +6 -2
- package/dist/chunk-HWJS3VOJ.js.map +1 -0
- package/dist/chunk-K5ZRJTZZ.js +328 -0
- package/dist/chunk-K5ZRJTZZ.js.map +1 -0
- package/dist/{chunk-7LZZEI25.js → chunk-N6ZDIMRB.js} +1 -1
- package/dist/chunk-N6ZDIMRB.js.map +1 -0
- package/dist/chunk-O6M6PN4E.js +1225 -0
- package/dist/chunk-O6M6PN4E.js.map +1 -0
- package/dist/{chunk-AEUXCFGM.js → chunk-PF7L4BMG.js} +1 -8
- package/dist/{chunk-AEUXCFGM.js.map → chunk-PF7L4BMG.js.map} +1 -1
- package/dist/{chunk-CZMFAS3E.js → chunk-WOWFONLZ.js} +517 -1274
- package/dist/chunk-WOWFONLZ.js.map +1 -0
- package/dist/{chunk-MALRKLRR.js → chunk-WUIVY2KE.js} +301 -12
- package/dist/chunk-WUIVY2KE.js.map +1 -0
- package/dist/chunk-ZAS2SENW.js +12 -0
- package/dist/chunk-ZAS2SENW.js.map +1 -0
- package/dist/codegen.d.ts +11 -3
- package/dist/codegen.js +1 -1
- package/dist/{components-Dqr_LuZJ.d.ts → components-BbWPnZCF.d.ts} +37 -6
- package/dist/{hex-board-view-UCUjMALd.d.ts → hex-board-view-Kz9Q_zsv.d.ts} +1 -1
- package/dist/index.js +2 -1
- package/dist/package-set.d.ts +2 -2
- package/dist/package-set.js +2 -1
- package/dist/player-state-Cqpyeql0.d.ts +371 -0
- package/dist/protocol-BP193lva.d.ts +267 -0
- package/dist/reducer/advanced.js +1 -1
- package/dist/reducer-contract.js +1 -1
- package/dist/reducer.js +2 -2
- package/dist/reducer.js.map +1 -1
- package/dist/runtime/primitives.d.ts +10 -10
- package/dist/runtime/primitives.js +9 -7
- package/dist/runtime/runtime-api.d.ts +2 -2
- package/dist/runtime/workspace-contract.d.ts +23 -12
- package/dist/runtime/workspace-contract.js +7 -6
- package/dist/runtime-api-BJharVaj.d.ts +198 -0
- package/dist/runtime-api-C6aWo9c0.d.ts +95 -0
- package/dist/runtime.d.ts +35 -31
- package/dist/runtime.js +87 -797
- package/dist/runtime.js.map +1 -1
- package/dist/testing.d.ts +254 -140
- package/dist/testing.js +964 -149
- package/dist/testing.js.map +1 -1
- package/dist/types-CYeN0wLK.d.ts +29 -0
- package/dist/{types-BqzHkNMA.d.ts → types-DJj5MJkl.d.ts} +32 -5
- package/dist/types.d.ts +13 -8
- package/dist/ui/components.d.ts +4 -5
- package/dist/ui/components.js +19 -1
- package/dist/ui/player-state.d.ts +2 -365
- package/dist/{ui-contract-W2-kxObe.d.ts → ui-contract-CY7cxsCC.d.ts} +16 -26
- package/dist/ui.d.ts +7 -8
- package/dist/ui.js +20 -2
- package/package.json +25 -19
- package/dist/chunk-3K362ZKR.js.map +0 -1
- package/dist/chunk-7LZZEI25.js.map +0 -1
- package/dist/chunk-7W6TQO3X.js.map +0 -1
- package/dist/chunk-CZMFAS3E.js.map +0 -1
- package/dist/chunk-IUGKW2GS.js.map +0 -1
- package/dist/chunk-MALRKLRR.js.map +0 -1
- package/dist/chunk-XXBSIPJX.js.map +0 -1
- package/dist/hex-color-MhOyuY-o.d.ts +0 -8
- package/dist/runtime-api-BXd70c2e.d.ts +0 -490
- /package/dist/{chunk-XJYUSD5F.js.map → chunk-FWVV2X74.js.map} +0 -0
|
@@ -0,0 +1,1225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BROWSER_INTERACTION_ATTRIBUTES,
|
|
3
|
+
DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
|
|
4
|
+
GAMEPLAY_BROWSER_INTERACTION_SURFACE
|
|
5
|
+
} from "./chunk-WUIVY2KE.js";
|
|
6
|
+
|
|
7
|
+
// ../plugin-runtime-contract/dist/chunk-LCXQNYOL.js
|
|
8
|
+
function canonicalizePluginRuntimeJson(value) {
|
|
9
|
+
assertRuntimeJson(value);
|
|
10
|
+
return canonicalizeJson(value);
|
|
11
|
+
}
|
|
12
|
+
function encodeCanonicalPluginRuntimeJson(value) {
|
|
13
|
+
return JSON.stringify(canonicalizePluginRuntimeJson(value));
|
|
14
|
+
}
|
|
15
|
+
function digestPluginRuntimeJson(value) {
|
|
16
|
+
return `sha256:${sha256Hex(encodeCanonicalPluginRuntimeJson(value))}`;
|
|
17
|
+
}
|
|
18
|
+
function canonicalizeJson(value) {
|
|
19
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === "number") {
|
|
23
|
+
if (!Number.isFinite(value)) {
|
|
24
|
+
throw new Error("canonical JSON contains a non-finite number");
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
return value.map((item) => canonicalizeJson(item));
|
|
30
|
+
}
|
|
31
|
+
return Object.fromEntries(
|
|
32
|
+
Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, canonicalizeJson(item)])
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
function assertRuntimeJson(value) {
|
|
36
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "number") {
|
|
40
|
+
if (!Number.isFinite(value)) {
|
|
41
|
+
throw new Error("runtime JSON contains a non-finite number");
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
value.forEach(assertRuntimeJson);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === "object") {
|
|
50
|
+
Object.values(value).forEach((item) => {
|
|
51
|
+
if (item !== void 0) {
|
|
52
|
+
assertRuntimeJson(item);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`runtime JSON contains unsupported ${typeof value} value`);
|
|
58
|
+
}
|
|
59
|
+
var SHA256_K = [
|
|
60
|
+
1116352408,
|
|
61
|
+
1899447441,
|
|
62
|
+
3049323471,
|
|
63
|
+
3921009573,
|
|
64
|
+
961987163,
|
|
65
|
+
1508970993,
|
|
66
|
+
2453635748,
|
|
67
|
+
2870763221,
|
|
68
|
+
3624381080,
|
|
69
|
+
310598401,
|
|
70
|
+
607225278,
|
|
71
|
+
1426881987,
|
|
72
|
+
1925078388,
|
|
73
|
+
2162078206,
|
|
74
|
+
2614888103,
|
|
75
|
+
3248222580,
|
|
76
|
+
3835390401,
|
|
77
|
+
4022224774,
|
|
78
|
+
264347078,
|
|
79
|
+
604807628,
|
|
80
|
+
770255983,
|
|
81
|
+
1249150122,
|
|
82
|
+
1555081692,
|
|
83
|
+
1996064986,
|
|
84
|
+
2554220882,
|
|
85
|
+
2821834349,
|
|
86
|
+
2952996808,
|
|
87
|
+
3210313671,
|
|
88
|
+
3336571891,
|
|
89
|
+
3584528711,
|
|
90
|
+
113926993,
|
|
91
|
+
338241895,
|
|
92
|
+
666307205,
|
|
93
|
+
773529912,
|
|
94
|
+
1294757372,
|
|
95
|
+
1396182291,
|
|
96
|
+
1695183700,
|
|
97
|
+
1986661051,
|
|
98
|
+
2177026350,
|
|
99
|
+
2456956037,
|
|
100
|
+
2730485921,
|
|
101
|
+
2820302411,
|
|
102
|
+
3259730800,
|
|
103
|
+
3345764771,
|
|
104
|
+
3516065817,
|
|
105
|
+
3600352804,
|
|
106
|
+
4094571909,
|
|
107
|
+
275423344,
|
|
108
|
+
430227734,
|
|
109
|
+
506948616,
|
|
110
|
+
659060556,
|
|
111
|
+
883997877,
|
|
112
|
+
958139571,
|
|
113
|
+
1322822218,
|
|
114
|
+
1537002063,
|
|
115
|
+
1747873779,
|
|
116
|
+
1955562222,
|
|
117
|
+
2024104815,
|
|
118
|
+
2227730452,
|
|
119
|
+
2361852424,
|
|
120
|
+
2428436474,
|
|
121
|
+
2756734187,
|
|
122
|
+
3204031479,
|
|
123
|
+
3329325298
|
|
124
|
+
];
|
|
125
|
+
function sha256Hex(input) {
|
|
126
|
+
const bytes = utf8Bytes(input);
|
|
127
|
+
const bitLength = bytes.length * 8;
|
|
128
|
+
bytes.push(128);
|
|
129
|
+
while (bytes.length % 64 !== 56) {
|
|
130
|
+
bytes.push(0);
|
|
131
|
+
}
|
|
132
|
+
for (let shift = 56; shift >= 0; shift -= 8) {
|
|
133
|
+
bytes.push(Math.floor(bitLength / 2 ** shift) & 255);
|
|
134
|
+
}
|
|
135
|
+
let h0 = 1779033703;
|
|
136
|
+
let h1 = 3144134277;
|
|
137
|
+
let h2 = 1013904242;
|
|
138
|
+
let h3 = 2773480762;
|
|
139
|
+
let h4 = 1359893119;
|
|
140
|
+
let h5 = 2600822924;
|
|
141
|
+
let h6 = 528734635;
|
|
142
|
+
let h7 = 1541459225;
|
|
143
|
+
const words = new Array(64);
|
|
144
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
145
|
+
for (let i = 0; i < 16; i += 1) {
|
|
146
|
+
const index = offset + i * 4;
|
|
147
|
+
words[i] = (bytes[index] ?? 0) << 24 | (bytes[index + 1] ?? 0) << 16 | (bytes[index + 2] ?? 0) << 8 | (bytes[index + 3] ?? 0);
|
|
148
|
+
}
|
|
149
|
+
for (let i = 16; i < 64; i += 1) {
|
|
150
|
+
const s0 = rightRotate(words[i - 15] ?? 0, 7) ^ rightRotate(words[i - 15] ?? 0, 18) ^ (words[i - 15] ?? 0) >>> 3;
|
|
151
|
+
const s1 = rightRotate(words[i - 2] ?? 0, 17) ^ rightRotate(words[i - 2] ?? 0, 19) ^ (words[i - 2] ?? 0) >>> 10;
|
|
152
|
+
words[i] = (words[i - 16] ?? 0) + s0 + (words[i - 7] ?? 0) + s1 >>> 0;
|
|
153
|
+
}
|
|
154
|
+
let a = h0;
|
|
155
|
+
let b = h1;
|
|
156
|
+
let c = h2;
|
|
157
|
+
let d = h3;
|
|
158
|
+
let e = h4;
|
|
159
|
+
let f = h5;
|
|
160
|
+
let g = h6;
|
|
161
|
+
let h = h7;
|
|
162
|
+
for (let i = 0; i < 64; i += 1) {
|
|
163
|
+
const s1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
|
|
164
|
+
const ch = e & f ^ ~e & g;
|
|
165
|
+
const temp1 = h + s1 + ch + (SHA256_K[i] ?? 0) + (words[i] ?? 0) >>> 0;
|
|
166
|
+
const s0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
|
|
167
|
+
const maj = a & b ^ a & c ^ b & c;
|
|
168
|
+
const temp2 = s0 + maj >>> 0;
|
|
169
|
+
h = g;
|
|
170
|
+
g = f;
|
|
171
|
+
f = e;
|
|
172
|
+
e = d + temp1 >>> 0;
|
|
173
|
+
d = c;
|
|
174
|
+
c = b;
|
|
175
|
+
b = a;
|
|
176
|
+
a = temp1 + temp2 >>> 0;
|
|
177
|
+
}
|
|
178
|
+
h0 = h0 + a >>> 0;
|
|
179
|
+
h1 = h1 + b >>> 0;
|
|
180
|
+
h2 = h2 + c >>> 0;
|
|
181
|
+
h3 = h3 + d >>> 0;
|
|
182
|
+
h4 = h4 + e >>> 0;
|
|
183
|
+
h5 = h5 + f >>> 0;
|
|
184
|
+
h6 = h6 + g >>> 0;
|
|
185
|
+
h7 = h7 + h >>> 0;
|
|
186
|
+
}
|
|
187
|
+
return [h0, h1, h2, h3, h4, h5, h6, h7].map((word) => word.toString(16).padStart(8, "0")).join("");
|
|
188
|
+
}
|
|
189
|
+
function rightRotate(value, bits) {
|
|
190
|
+
return value >>> bits | value << 32 - bits;
|
|
191
|
+
}
|
|
192
|
+
function utf8Bytes(input) {
|
|
193
|
+
const bytes = [];
|
|
194
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
195
|
+
const code = input.charCodeAt(i);
|
|
196
|
+
if (code < 128) {
|
|
197
|
+
bytes.push(code);
|
|
198
|
+
} else if (code < 2048) {
|
|
199
|
+
bytes.push(192 | code >> 6, 128 | code & 63);
|
|
200
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
201
|
+
const next = input.charCodeAt(i += 1);
|
|
202
|
+
const point = 65536 + ((code & 1023) << 10 | next & 1023);
|
|
203
|
+
bytes.push(
|
|
204
|
+
240 | point >> 18,
|
|
205
|
+
128 | point >> 12 & 63,
|
|
206
|
+
128 | point >> 6 & 63,
|
|
207
|
+
128 | point & 63
|
|
208
|
+
);
|
|
209
|
+
} else {
|
|
210
|
+
bytes.push(
|
|
211
|
+
224 | code >> 12,
|
|
212
|
+
128 | code >> 6 & 63,
|
|
213
|
+
128 | code & 63
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return bytes;
|
|
218
|
+
}
|
|
219
|
+
function computePluginActionSetVersion(input) {
|
|
220
|
+
return digestPluginRuntimeJson({
|
|
221
|
+
digestVersion: "plugin-action-set@3",
|
|
222
|
+
gameVersion: input.gameVersion,
|
|
223
|
+
availableInteractions: input.availableInteractions
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function digestPluginGameplayFrame(frame) {
|
|
227
|
+
return digestPluginRuntimeJson({
|
|
228
|
+
digestVersion: "plugin-gameplay-frame@3",
|
|
229
|
+
frame
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ../plugin-runtime-contract/dist/chunk-MKR6YUC7.js
|
|
234
|
+
import { z } from "zod";
|
|
235
|
+
var DREAMBOARD_PLUGIN_PROTOCOL = "dreamboard-plugin";
|
|
236
|
+
var DREAMBOARD_PLUGIN_PROTOCOL_VERSION = 3;
|
|
237
|
+
var RuntimeJsonSchema = z.lazy(
|
|
238
|
+
() => z.union([
|
|
239
|
+
z.null(),
|
|
240
|
+
z.boolean(),
|
|
241
|
+
z.number().finite(),
|
|
242
|
+
z.string(),
|
|
243
|
+
z.array(RuntimeJsonSchema),
|
|
244
|
+
z.record(z.string(), RuntimeJsonSchema)
|
|
245
|
+
])
|
|
246
|
+
);
|
|
247
|
+
var BoardStaticProjectionSchema = z.object({
|
|
248
|
+
view: RuntimeJsonSchema,
|
|
249
|
+
hash: z.string().optional(),
|
|
250
|
+
manifestVersion: z.string().optional()
|
|
251
|
+
}).strict();
|
|
252
|
+
var SeatProjectionBundleSchema = z.object({
|
|
253
|
+
currentStage: z.string().nullable().optional(),
|
|
254
|
+
stageSeats: z.array(z.string()).optional(),
|
|
255
|
+
simultaneousPhase: z.unknown().nullable().optional(),
|
|
256
|
+
interactionsByRef: z.record(z.string(), z.unknown()).optional(),
|
|
257
|
+
seats: z.record(
|
|
258
|
+
z.string(),
|
|
259
|
+
z.object({
|
|
260
|
+
view: z.unknown().optional(),
|
|
261
|
+
availableInteractionRefs: z.array(z.string()).optional(),
|
|
262
|
+
zones: z.unknown().optional()
|
|
263
|
+
}).strict()
|
|
264
|
+
)
|
|
265
|
+
}).strict();
|
|
266
|
+
var PlayerIdSchema = z.string().min(1);
|
|
267
|
+
var PluginPlayerSummarySchema = z.object({
|
|
268
|
+
playerId: PlayerIdSchema,
|
|
269
|
+
displayName: z.string(),
|
|
270
|
+
color: z.string().optional()
|
|
271
|
+
}).strict();
|
|
272
|
+
var PluginSessionDescriptorSchema = z.object({
|
|
273
|
+
sessionId: z.string().min(1),
|
|
274
|
+
players: z.array(PluginPlayerSummarySchema)
|
|
275
|
+
}).strict();
|
|
276
|
+
var InteractionCommitPolicySchema = z.discriminatedUnion("mode", [
|
|
277
|
+
z.object({ mode: z.literal("manual") }).strict(),
|
|
278
|
+
z.object({ mode: z.literal("autoWhenReady") }).strict()
|
|
279
|
+
]);
|
|
280
|
+
var InputSelectionSchema = z.discriminatedUnion("mode", [
|
|
281
|
+
z.object({ mode: z.literal("single") }).strict(),
|
|
282
|
+
z.object({
|
|
283
|
+
mode: z.literal("many"),
|
|
284
|
+
min: z.number().int(),
|
|
285
|
+
max: z.number().int().optional(),
|
|
286
|
+
distinct: z.boolean().optional()
|
|
287
|
+
}).strict()
|
|
288
|
+
]);
|
|
289
|
+
var InputDomainDependencyCaseSchema = z.lazy(
|
|
290
|
+
() => z.object({
|
|
291
|
+
when: z.record(z.string(), z.string()),
|
|
292
|
+
domain: InputDomainSchema
|
|
293
|
+
}).strict()
|
|
294
|
+
);
|
|
295
|
+
var InputDomainDependenciesSchema = z.discriminatedUnion("mode", [
|
|
296
|
+
z.object({
|
|
297
|
+
mode: z.literal("eager"),
|
|
298
|
+
dependentCases: z.array(InputDomainDependencyCaseSchema)
|
|
299
|
+
}).strict(),
|
|
300
|
+
z.object({
|
|
301
|
+
mode: z.literal("lazy"),
|
|
302
|
+
dependsOn: z.array(z.string()),
|
|
303
|
+
resolver: z.object({
|
|
304
|
+
interactionKey: z.string().optional(),
|
|
305
|
+
inputKey: z.string()
|
|
306
|
+
}).strict()
|
|
307
|
+
}).strict()
|
|
308
|
+
]);
|
|
309
|
+
var InputDomainSchema = z.object({
|
|
310
|
+
type: z.string(),
|
|
311
|
+
selection: InputSelectionSchema.optional(),
|
|
312
|
+
dependencies: InputDomainDependenciesSchema.optional()
|
|
313
|
+
}).catchall(RuntimeJsonSchema);
|
|
314
|
+
var InteractionChoiceOptionSchema = z.object({
|
|
315
|
+
value: z.string().nullable(),
|
|
316
|
+
label: z.string(),
|
|
317
|
+
icon: z.string().optional(),
|
|
318
|
+
badge: z.string().optional(),
|
|
319
|
+
description: z.string().optional(),
|
|
320
|
+
disabled: z.boolean().optional(),
|
|
321
|
+
disabledReason: z.string().optional()
|
|
322
|
+
}).strict();
|
|
323
|
+
var InteractionInputDescriptorSchema = z.object({
|
|
324
|
+
key: z.string().min(1),
|
|
325
|
+
kind: z.string().min(1),
|
|
326
|
+
domain: InputDomainSchema,
|
|
327
|
+
defaultValue: RuntimeJsonSchema.optional()
|
|
328
|
+
}).strict();
|
|
329
|
+
var InteractionAvailabilitySchema = z.discriminatedUnion("status", [
|
|
330
|
+
z.object({ status: z.literal("available") }).strict(),
|
|
331
|
+
z.object({ status: z.literal("notYourTurn"), reason: z.string() }).strict(),
|
|
332
|
+
z.object({
|
|
333
|
+
status: z.literal("insufficientResources"),
|
|
334
|
+
reason: z.string(),
|
|
335
|
+
missingResources: z.record(z.string(), z.number().finite())
|
|
336
|
+
}).strict(),
|
|
337
|
+
z.object({
|
|
338
|
+
status: z.literal("blocked"),
|
|
339
|
+
reason: z.string(),
|
|
340
|
+
code: z.string().optional()
|
|
341
|
+
}).strict()
|
|
342
|
+
]);
|
|
343
|
+
var InteractionBaseSchema = z.object({
|
|
344
|
+
phaseName: z.string().min(1),
|
|
345
|
+
interactionKey: z.string().min(1),
|
|
346
|
+
interactionId: z.string().min(1),
|
|
347
|
+
zoneId: z.string().optional(),
|
|
348
|
+
zoneIds: z.array(z.string()).optional(),
|
|
349
|
+
commit: InteractionCommitPolicySchema,
|
|
350
|
+
descriptorDigest: z.string().optional(),
|
|
351
|
+
actorSeat: z.number().int().optional(),
|
|
352
|
+
draftDigest: z.string().optional(),
|
|
353
|
+
inputs: z.array(InteractionInputDescriptorSchema),
|
|
354
|
+
cost: z.record(z.string(), RuntimeJsonSchema).optional(),
|
|
355
|
+
currentResources: z.record(z.string(), RuntimeJsonSchema).optional(),
|
|
356
|
+
availability: InteractionAvailabilitySchema,
|
|
357
|
+
reasons: z.array(
|
|
358
|
+
z.object({
|
|
359
|
+
ruleId: z.string(),
|
|
360
|
+
errorCode: z.string()
|
|
361
|
+
}).strict()
|
|
362
|
+
).optional()
|
|
363
|
+
}).strict();
|
|
364
|
+
var InteractionContextSchema = z.object({
|
|
365
|
+
to: z.string().min(1),
|
|
366
|
+
title: z.string().optional(),
|
|
367
|
+
payload: z.record(z.string(), RuntimeJsonSchema).optional(),
|
|
368
|
+
options: z.array(
|
|
369
|
+
z.object({
|
|
370
|
+
id: z.string(),
|
|
371
|
+
label: z.string().optional()
|
|
372
|
+
}).strict()
|
|
373
|
+
).optional()
|
|
374
|
+
}).strict();
|
|
375
|
+
var InteractionDescriptorSchema = z.discriminatedUnion("kind", [
|
|
376
|
+
InteractionBaseSchema.extend({ kind: z.literal("action") }).strict(),
|
|
377
|
+
InteractionBaseSchema.extend({
|
|
378
|
+
kind: z.literal("prompt"),
|
|
379
|
+
context: InteractionContextSchema
|
|
380
|
+
}).strict()
|
|
381
|
+
]);
|
|
382
|
+
var ZoneHandlesSnapshotSchema = z.object({
|
|
383
|
+
cardIds: z.array(z.string()),
|
|
384
|
+
cardViewsById: z.record(z.string(), z.string()),
|
|
385
|
+
playableByCardId: z.record(
|
|
386
|
+
z.string(),
|
|
387
|
+
z.array(InteractionDescriptorSchema)
|
|
388
|
+
)
|
|
389
|
+
}).strict();
|
|
390
|
+
var SimultaneousPhaseSnapshotSchema = z.object({
|
|
391
|
+
phaseName: z.string().min(1),
|
|
392
|
+
interactionId: z.string().min(1),
|
|
393
|
+
actorIds: z.array(PlayerIdSchema),
|
|
394
|
+
sealedPlayerIds: z.array(PlayerIdSchema),
|
|
395
|
+
pendingPlayerIds: z.array(PlayerIdSchema)
|
|
396
|
+
}).strict();
|
|
397
|
+
var PluginGameplayFrameSchema = z.object({
|
|
398
|
+
gameVersion: z.number().int().nonnegative(),
|
|
399
|
+
actionSetVersion: z.string().min(1),
|
|
400
|
+
perspectivePlayerId: PlayerIdSchema.nullable(),
|
|
401
|
+
view: RuntimeJsonSchema.nullable(),
|
|
402
|
+
flow: z.object({
|
|
403
|
+
currentPhase: z.string().nullable(),
|
|
404
|
+
currentStage: z.string().nullable(),
|
|
405
|
+
activePlayers: z.array(PlayerIdSchema),
|
|
406
|
+
simultaneousPhase: SimultaneousPhaseSnapshotSchema.nullable()
|
|
407
|
+
}).strict(),
|
|
408
|
+
availableInteractions: z.array(InteractionDescriptorSchema),
|
|
409
|
+
zones: z.record(z.string(), ZoneHandlesSnapshotSchema)
|
|
410
|
+
}).strict();
|
|
411
|
+
var ValidationResultSchema = z.object({
|
|
412
|
+
valid: z.boolean(),
|
|
413
|
+
errorCode: z.string().optional(),
|
|
414
|
+
message: z.string().optional()
|
|
415
|
+
}).strict();
|
|
416
|
+
var SubmissionResultSchema = z.discriminatedUnion("accepted", [
|
|
417
|
+
z.object({ accepted: z.literal(true) }).strict(),
|
|
418
|
+
z.object({
|
|
419
|
+
accepted: z.literal(false),
|
|
420
|
+
errorCode: z.string().min(1),
|
|
421
|
+
message: z.string().optional()
|
|
422
|
+
}).strict()
|
|
423
|
+
]);
|
|
424
|
+
var PluginInteractionBasisSchema = z.object({
|
|
425
|
+
gameVersion: z.number().int().nonnegative(),
|
|
426
|
+
actionSetVersion: z.string().min(1),
|
|
427
|
+
perspectivePlayerId: PlayerIdSchema.nullable()
|
|
428
|
+
}).strict();
|
|
429
|
+
var ValidateInteractionCommandSchema = z.object({
|
|
430
|
+
type: z.literal("interaction.validate"),
|
|
431
|
+
requestId: z.string().min(1),
|
|
432
|
+
basis: PluginInteractionBasisSchema,
|
|
433
|
+
interactionId: z.string().min(1),
|
|
434
|
+
params: RuntimeJsonSchema
|
|
435
|
+
}).strict();
|
|
436
|
+
var SubmitInteractionCommandSchema = z.object({
|
|
437
|
+
type: z.literal("interaction.submit"),
|
|
438
|
+
requestId: z.string().min(1),
|
|
439
|
+
basis: PluginInteractionBasisSchema,
|
|
440
|
+
interactionId: z.string().min(1),
|
|
441
|
+
params: RuntimeJsonSchema
|
|
442
|
+
}).strict();
|
|
443
|
+
var HostToPluginPayloadSchema = z.discriminatedUnion("type", [
|
|
444
|
+
z.object({
|
|
445
|
+
type: z.literal("runtime.init"),
|
|
446
|
+
session: PluginSessionDescriptorSchema
|
|
447
|
+
}).strict(),
|
|
448
|
+
z.object({
|
|
449
|
+
type: z.literal("gameplay.frame"),
|
|
450
|
+
frame: PluginGameplayFrameSchema
|
|
451
|
+
}).strict(),
|
|
452
|
+
z.object({
|
|
453
|
+
type: z.literal("interaction.validation-result"),
|
|
454
|
+
requestId: z.string().min(1),
|
|
455
|
+
result: ValidationResultSchema
|
|
456
|
+
}).strict(),
|
|
457
|
+
z.object({
|
|
458
|
+
type: z.literal("interaction.submit-result"),
|
|
459
|
+
requestId: z.string().min(1),
|
|
460
|
+
result: SubmissionResultSchema
|
|
461
|
+
}).strict()
|
|
462
|
+
]);
|
|
463
|
+
var PluginToHostPayloadSchema = z.discriminatedUnion("type", [
|
|
464
|
+
z.object({ type: z.literal("runtime.ready") }).strict(),
|
|
465
|
+
z.object({
|
|
466
|
+
type: z.literal("runtime.ack"),
|
|
467
|
+
sequence: z.number().int().nonnegative(),
|
|
468
|
+
clientReceivedAtMs: z.number().finite().optional(),
|
|
469
|
+
clientRenderedAtMs: z.number().finite().optional()
|
|
470
|
+
}).strict(),
|
|
471
|
+
ValidateInteractionCommandSchema,
|
|
472
|
+
SubmitInteractionCommandSchema,
|
|
473
|
+
z.object({
|
|
474
|
+
type: z.literal("runtime.error"),
|
|
475
|
+
message: z.string(),
|
|
476
|
+
code: z.string().optional()
|
|
477
|
+
}).strict()
|
|
478
|
+
]);
|
|
479
|
+
function createPluginProtocolEnvelopeSchema(payloadSchema) {
|
|
480
|
+
return z.object({
|
|
481
|
+
protocol: z.literal(DREAMBOARD_PLUGIN_PROTOCOL),
|
|
482
|
+
version: z.literal(DREAMBOARD_PLUGIN_PROTOCOL_VERSION),
|
|
483
|
+
channelId: z.string().min(1),
|
|
484
|
+
sequence: z.number().int().nonnegative(),
|
|
485
|
+
payload: payloadSchema
|
|
486
|
+
}).strict();
|
|
487
|
+
}
|
|
488
|
+
var HostToPluginEnvelopeSchema = createPluginProtocolEnvelopeSchema(
|
|
489
|
+
HostToPluginPayloadSchema
|
|
490
|
+
);
|
|
491
|
+
var PluginToHostEnvelopeSchema = createPluginProtocolEnvelopeSchema(
|
|
492
|
+
PluginToHostPayloadSchema
|
|
493
|
+
);
|
|
494
|
+
var PluginProtocolFrameSchema = z.object({
|
|
495
|
+
id: z.string().min(1),
|
|
496
|
+
frame: PluginGameplayFrameSchema,
|
|
497
|
+
projectionDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/)
|
|
498
|
+
}).strict();
|
|
499
|
+
var PluginProtocolStepSchema = z.discriminatedUnion("kind", [
|
|
500
|
+
z.object({
|
|
501
|
+
id: z.string().min(1),
|
|
502
|
+
kind: z.literal("host.frame"),
|
|
503
|
+
frameId: z.string().min(1)
|
|
504
|
+
}).strict(),
|
|
505
|
+
z.object({
|
|
506
|
+
id: z.string().min(1),
|
|
507
|
+
kind: z.literal("client.validate"),
|
|
508
|
+
fromFrameId: z.string().min(1),
|
|
509
|
+
requestDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
510
|
+
response: ValidationResultSchema
|
|
511
|
+
}).strict(),
|
|
512
|
+
z.object({
|
|
513
|
+
id: z.string().min(1),
|
|
514
|
+
kind: z.literal("client.submit"),
|
|
515
|
+
fromFrameId: z.string().min(1),
|
|
516
|
+
requestDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
517
|
+
response: SubmissionResultSchema
|
|
518
|
+
}).strict()
|
|
519
|
+
]);
|
|
520
|
+
var PluginProtocolTapeSchema = z.object({
|
|
521
|
+
session: PluginSessionDescriptorSchema,
|
|
522
|
+
frames: z.array(PluginProtocolFrameSchema),
|
|
523
|
+
steps: z.array(PluginProtocolStepSchema)
|
|
524
|
+
}).strict();
|
|
525
|
+
|
|
526
|
+
// ../plugin-runtime-contract/dist/index.js
|
|
527
|
+
function materializePluginGameplayFrame(input) {
|
|
528
|
+
const dynamicProjection = SeatProjectionBundleSchema.parse(
|
|
529
|
+
input.dynamicProjection
|
|
530
|
+
);
|
|
531
|
+
const staticProjection = input.staticProjection == null ? null : BoardStaticProjectionSchema.parse(
|
|
532
|
+
input.staticProjection
|
|
533
|
+
);
|
|
534
|
+
const registry = parseInteractionRegistry(
|
|
535
|
+
dynamicProjection.interactionsByRef
|
|
536
|
+
);
|
|
537
|
+
const seat = input.perspectivePlayerId == null ? null : dynamicProjection.seats[input.perspectivePlayerId] ?? null;
|
|
538
|
+
const availableInteractions = seat == null ? [] : hydrateInteractionRefs(
|
|
539
|
+
registry,
|
|
540
|
+
seat.availableInteractionRefs,
|
|
541
|
+
"availableInteractionRefs"
|
|
542
|
+
);
|
|
543
|
+
const zones = seat?.zones == null ? {} : hydrateZones(registry, seat.zones, "zones");
|
|
544
|
+
const frame = {
|
|
545
|
+
gameVersion: input.gameVersion,
|
|
546
|
+
actionSetVersion: input.actionSetVersion,
|
|
547
|
+
perspectivePlayerId: input.perspectivePlayerId,
|
|
548
|
+
view: composeProjectionView(staticProjection, seat?.view),
|
|
549
|
+
flow: {
|
|
550
|
+
currentPhase: input.currentPhase,
|
|
551
|
+
currentStage: dynamicProjection.currentStage ?? null,
|
|
552
|
+
activePlayers: [...input.activePlayers],
|
|
553
|
+
simultaneousPhase: dynamicProjection.simultaneousPhase ?? null
|
|
554
|
+
},
|
|
555
|
+
availableInteractions,
|
|
556
|
+
zones
|
|
557
|
+
};
|
|
558
|
+
return PluginGameplayFrameSchema.parse(frame);
|
|
559
|
+
}
|
|
560
|
+
function parseInteractionRegistry(value) {
|
|
561
|
+
if (value == null) return {};
|
|
562
|
+
if (!isRecord(value)) {
|
|
563
|
+
throw new Error("Seat projection interactionsByRef must be an object.");
|
|
564
|
+
}
|
|
565
|
+
return Object.fromEntries(
|
|
566
|
+
Object.entries(value).map(([ref, descriptor]) => [
|
|
567
|
+
ref,
|
|
568
|
+
InteractionDescriptorSchema.parse(descriptor)
|
|
569
|
+
])
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
function hydrateZones(registry, value, path) {
|
|
573
|
+
if (!isRecord(value)) {
|
|
574
|
+
throw new Error(`Seat projection ${path} must be an object.`);
|
|
575
|
+
}
|
|
576
|
+
return Object.fromEntries(
|
|
577
|
+
Object.entries(value).map(([zoneId, zoneValue]) => [
|
|
578
|
+
zoneId,
|
|
579
|
+
hydrateZone(registry, zoneValue, `${path}.${zoneId}`)
|
|
580
|
+
])
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
function hydrateZone(registry, value, path) {
|
|
584
|
+
if (!isRecord(value)) {
|
|
585
|
+
throw new Error(`Seat projection ${path} must be an object.`);
|
|
586
|
+
}
|
|
587
|
+
const cardIds = arrayOfStrings(value.cardIds, `${path}.cardIds`);
|
|
588
|
+
const cardViewsById = stringRecord(
|
|
589
|
+
value.cardViewsById,
|
|
590
|
+
`${path}.cardViewsById`
|
|
591
|
+
);
|
|
592
|
+
if (!isRecord(value.playableByCardId)) {
|
|
593
|
+
throw new Error(
|
|
594
|
+
`Seat projection ${path}.playableByCardId must be an object.`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
const playableByCardId = Object.fromEntries(
|
|
598
|
+
Object.entries(value.playableByCardId).map(([cardId, refs]) => [
|
|
599
|
+
cardId,
|
|
600
|
+
hydrateInteractionRefs(
|
|
601
|
+
registry,
|
|
602
|
+
refs,
|
|
603
|
+
`${path}.playableByCardId.${cardId}`
|
|
604
|
+
)
|
|
605
|
+
])
|
|
606
|
+
);
|
|
607
|
+
return ZoneHandlesSnapshotSchema.parse({
|
|
608
|
+
cardIds,
|
|
609
|
+
cardViewsById,
|
|
610
|
+
playableByCardId
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function hydrateInteractionRefs(registry, value, path) {
|
|
614
|
+
if (!Array.isArray(value)) {
|
|
615
|
+
throw new Error(`Seat projection ${path} must be an array of refs.`);
|
|
616
|
+
}
|
|
617
|
+
return value.map((ref, index) => {
|
|
618
|
+
if (typeof ref !== "string") {
|
|
619
|
+
throw new Error(
|
|
620
|
+
`Seat projection ${path}[${index}] must be a ref string.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
const descriptor = registry[ref];
|
|
624
|
+
if (!descriptor) {
|
|
625
|
+
throw new Error(
|
|
626
|
+
`Seat projection ${path}[${index}] references '${ref}', which is missing from interactionsByRef.`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return descriptor;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function composeProjectionView(staticProjection, dynamicView) {
|
|
633
|
+
const normalizedDynamicView = dynamicView === void 0 ? null : dynamicView;
|
|
634
|
+
if (staticProjection == null) {
|
|
635
|
+
return normalizedDynamicView;
|
|
636
|
+
}
|
|
637
|
+
if (normalizedDynamicView == null) {
|
|
638
|
+
return staticProjection.view;
|
|
639
|
+
}
|
|
640
|
+
if (isRecord(staticProjection.view) && isRecord(normalizedDynamicView)) {
|
|
641
|
+
return {
|
|
642
|
+
...staticProjection.view,
|
|
643
|
+
...normalizedDynamicView
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
static: staticProjection.view,
|
|
648
|
+
dynamic: normalizedDynamicView
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
function arrayOfStrings(value, path) {
|
|
652
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
653
|
+
throw new Error(`Seat projection ${path} must be an array of strings.`);
|
|
654
|
+
}
|
|
655
|
+
return value;
|
|
656
|
+
}
|
|
657
|
+
function stringRecord(value, path) {
|
|
658
|
+
if (!isRecord(value)) {
|
|
659
|
+
throw new Error(`Seat projection ${path} must be an object.`);
|
|
660
|
+
}
|
|
661
|
+
const result = {};
|
|
662
|
+
for (const [key, item] of Object.entries(value)) {
|
|
663
|
+
if (typeof item !== "string") {
|
|
664
|
+
throw new Error(`Seat projection ${path}.${key} must be a string.`);
|
|
665
|
+
}
|
|
666
|
+
result[key] = item;
|
|
667
|
+
}
|
|
668
|
+
return result;
|
|
669
|
+
}
|
|
670
|
+
function isRecord(value) {
|
|
671
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// src/runtime/context/PluginGameplayFrameContext.tsx
|
|
675
|
+
import {
|
|
676
|
+
createContext,
|
|
677
|
+
useContext,
|
|
678
|
+
useMemo as useMemo2,
|
|
679
|
+
useSyncExternalStore as useSyncExternalStore2
|
|
680
|
+
} from "react";
|
|
681
|
+
|
|
682
|
+
// src/runtime/hooks/useRuntimeSnapshotSelector.ts
|
|
683
|
+
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
684
|
+
function defaultRuntimeSnapshotEquality(left, right) {
|
|
685
|
+
return Object.is(left, right);
|
|
686
|
+
}
|
|
687
|
+
function useRuntimeSnapshotSelector(subscribe, getSnapshot, getServerSnapshot, selector, equalityFn = defaultRuntimeSnapshotEquality) {
|
|
688
|
+
const cache = useMemo(
|
|
689
|
+
() => ({ current: null, selector, equalityFn }),
|
|
690
|
+
[equalityFn, selector]
|
|
691
|
+
);
|
|
692
|
+
const getSelectedFromSnapshot = useCallback(
|
|
693
|
+
(snapshot) => {
|
|
694
|
+
const cached = cache.current;
|
|
695
|
+
if (cached && cached.snapshot === snapshot) {
|
|
696
|
+
return cached.selection;
|
|
697
|
+
}
|
|
698
|
+
const nextSelection = selector(snapshot);
|
|
699
|
+
if (cached && equalityFn(cached.selection, nextSelection)) {
|
|
700
|
+
cache.current = {
|
|
701
|
+
snapshot,
|
|
702
|
+
selection: cached.selection
|
|
703
|
+
};
|
|
704
|
+
return cached.selection;
|
|
705
|
+
}
|
|
706
|
+
cache.current = {
|
|
707
|
+
snapshot,
|
|
708
|
+
selection: nextSelection
|
|
709
|
+
};
|
|
710
|
+
return nextSelection;
|
|
711
|
+
},
|
|
712
|
+
[cache, equalityFn, selector]
|
|
713
|
+
);
|
|
714
|
+
const getSelectedSnapshot = useCallback(
|
|
715
|
+
() => getSelectedFromSnapshot(getSnapshot()),
|
|
716
|
+
[getSelectedFromSnapshot, getSnapshot]
|
|
717
|
+
);
|
|
718
|
+
const getSelectedServerSnapshot = useCallback(
|
|
719
|
+
() => selector(getServerSnapshot()),
|
|
720
|
+
[getServerSnapshot, selector]
|
|
721
|
+
);
|
|
722
|
+
const subscribeSelected = useCallback(
|
|
723
|
+
(onStoreChange) => subscribe(() => {
|
|
724
|
+
const previous = cache.current;
|
|
725
|
+
const nextSelection = getSelectedSnapshot();
|
|
726
|
+
if (!previous || !equalityFn(previous.selection, nextSelection)) {
|
|
727
|
+
onStoreChange();
|
|
728
|
+
}
|
|
729
|
+
}),
|
|
730
|
+
[cache, equalityFn, getSelectedSnapshot, subscribe]
|
|
731
|
+
);
|
|
732
|
+
return useSyncExternalStore(
|
|
733
|
+
subscribeSelected,
|
|
734
|
+
getSelectedSnapshot,
|
|
735
|
+
getSelectedServerSnapshot
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// src/runtime/context/PluginGameplayFrameContext.tsx
|
|
740
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
741
|
+
var PluginGameplayFrameStoreContext = createContext(null);
|
|
742
|
+
var PluginGameplayFrameContext = createContext(
|
|
743
|
+
null
|
|
744
|
+
);
|
|
745
|
+
function DefaultLoadingScreen() {
|
|
746
|
+
return /* @__PURE__ */ jsx(
|
|
747
|
+
"div",
|
|
748
|
+
{
|
|
749
|
+
style: {
|
|
750
|
+
display: "flex",
|
|
751
|
+
alignItems: "center",
|
|
752
|
+
justifyContent: "center",
|
|
753
|
+
height: "100%",
|
|
754
|
+
width: "100%",
|
|
755
|
+
color: "#666"
|
|
756
|
+
},
|
|
757
|
+
children: /* @__PURE__ */ jsxs("div", { style: { textAlign: "center" }, children: [
|
|
758
|
+
/* @__PURE__ */ jsx(
|
|
759
|
+
"div",
|
|
760
|
+
{
|
|
761
|
+
style: {
|
|
762
|
+
width: "40px",
|
|
763
|
+
height: "40px",
|
|
764
|
+
border: "3px solid #e0e0e0",
|
|
765
|
+
borderTopColor: "#666",
|
|
766
|
+
borderRadius: "50%",
|
|
767
|
+
animation: "spin 1s linear infinite",
|
|
768
|
+
margin: "0 auto 12px"
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
),
|
|
772
|
+
/* @__PURE__ */ jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` }),
|
|
773
|
+
/* @__PURE__ */ jsx("p", { children: "Loading game view..." })
|
|
774
|
+
] })
|
|
775
|
+
}
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
function PluginGameplayFrameProvider({
|
|
779
|
+
runtime,
|
|
780
|
+
children,
|
|
781
|
+
loadingComponent = /* @__PURE__ */ jsx(DefaultLoadingScreen, {})
|
|
782
|
+
}) {
|
|
783
|
+
const storeApi = useMemo2(() => {
|
|
784
|
+
let current = runtime.getFrame();
|
|
785
|
+
return {
|
|
786
|
+
subscribe: (onStoreChange) => runtime.subscribeFrame(() => {
|
|
787
|
+
current = runtime.getFrame();
|
|
788
|
+
onStoreChange();
|
|
789
|
+
}),
|
|
790
|
+
getSnapshot: () => current,
|
|
791
|
+
getServerSnapshot: () => current
|
|
792
|
+
};
|
|
793
|
+
}, [runtime]);
|
|
794
|
+
return /* @__PURE__ */ jsx(
|
|
795
|
+
PluginGameplayFrameStoreProvider,
|
|
796
|
+
{
|
|
797
|
+
store: storeApi,
|
|
798
|
+
loadingComponent,
|
|
799
|
+
children
|
|
800
|
+
}
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
function PluginGameplayFrameStoreProvider({
|
|
804
|
+
store,
|
|
805
|
+
children,
|
|
806
|
+
loadingComponent
|
|
807
|
+
}) {
|
|
808
|
+
const frame = useSyncExternalStore2(
|
|
809
|
+
store.subscribe,
|
|
810
|
+
store.getSnapshot,
|
|
811
|
+
store.getServerSnapshot
|
|
812
|
+
);
|
|
813
|
+
if (!frame) {
|
|
814
|
+
return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
|
|
815
|
+
}
|
|
816
|
+
return /* @__PURE__ */ jsx(PluginGameplayFrameStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsxs(PluginGameplayFrameContext.Provider, { value: frame, children: [
|
|
817
|
+
/* @__PURE__ */ jsx(SemanticGameplayFrameMarker, { frame }),
|
|
818
|
+
children
|
|
819
|
+
] }) });
|
|
820
|
+
}
|
|
821
|
+
function usePluginGameplayFrameSelector(selector, equalityFn = defaultRuntimeSnapshotEquality) {
|
|
822
|
+
const store = useContext(PluginGameplayFrameStoreContext);
|
|
823
|
+
if (!store) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
"usePluginGameplayFrameSelector must be used within PluginGameplayFrameProvider."
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
return useRuntimeSnapshotSelector(
|
|
829
|
+
store.subscribe,
|
|
830
|
+
store.getSnapshot,
|
|
831
|
+
store.getServerSnapshot,
|
|
832
|
+
(frame) => selector(requirePluginGameplayFrame(frame)),
|
|
833
|
+
equalityFn
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
function useAuthoredPluginGameplayFrameSelector(selector, equalityFn = defaultRuntimeSnapshotEquality) {
|
|
837
|
+
return usePluginGameplayFrameSelector(
|
|
838
|
+
(frame) => selector(frame),
|
|
839
|
+
equalityFn
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
function requirePluginGameplayFrame(frame) {
|
|
843
|
+
if (!frame) {
|
|
844
|
+
throw new Error("Plugin gameplay frame is not available.");
|
|
845
|
+
}
|
|
846
|
+
return frame;
|
|
847
|
+
}
|
|
848
|
+
var GAMEPLAY_BROWSER_SCOPE_ID = "runtime";
|
|
849
|
+
var BROWSER_PROJECTION_DIGEST_ATTRIBUTE = "data-dreamboard-projection-digest";
|
|
850
|
+
function SemanticGameplayFrameMarker({
|
|
851
|
+
frame
|
|
852
|
+
}) {
|
|
853
|
+
const digest = digestPluginGameplayFrame(frame);
|
|
854
|
+
return /* @__PURE__ */ jsx(
|
|
855
|
+
"span",
|
|
856
|
+
{
|
|
857
|
+
"aria-hidden": "true",
|
|
858
|
+
style: { display: "none" },
|
|
859
|
+
...{
|
|
860
|
+
[BROWSER_INTERACTION_ATTRIBUTES.protocol]: DREAMBOARD_BROWSER_INTERACTION_PROTOCOL_VERSION,
|
|
861
|
+
[BROWSER_INTERACTION_ATTRIBUTES.surface]: GAMEPLAY_BROWSER_INTERACTION_SURFACE,
|
|
862
|
+
[BROWSER_INTERACTION_ATTRIBUTES.scope]: GAMEPLAY_BROWSER_SCOPE_ID,
|
|
863
|
+
[BROWSER_INTERACTION_ATTRIBUTES.role]: "projection",
|
|
864
|
+
[BROWSER_PROJECTION_DIGEST_ATTRIBUTE]: digest
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/runtime/context/InteractionDraftContext.tsx
|
|
871
|
+
import { createContext as createContext2, useContext as useContext2, useMemo as useMemo3 } from "react";
|
|
872
|
+
import { useStore } from "zustand";
|
|
873
|
+
import { createStore } from "zustand/vanilla";
|
|
874
|
+
import { useShallow } from "zustand/shallow";
|
|
875
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
876
|
+
var EMPTY_DRAFT = Object.freeze({});
|
|
877
|
+
function omitRecordKey(record, key) {
|
|
878
|
+
const next = { ...record };
|
|
879
|
+
delete next[key];
|
|
880
|
+
return next;
|
|
881
|
+
}
|
|
882
|
+
function createInteractionUiStore() {
|
|
883
|
+
const store = createStore()(() => ({
|
|
884
|
+
drafts: {},
|
|
885
|
+
arms: {},
|
|
886
|
+
submitting: {},
|
|
887
|
+
pendingInteractionKey: null,
|
|
888
|
+
pendingInteractionRevision: 0
|
|
889
|
+
}));
|
|
890
|
+
const api = {
|
|
891
|
+
getDraft(interactionId) {
|
|
892
|
+
return store.getState().drafts[interactionId] ?? EMPTY_DRAFT;
|
|
893
|
+
},
|
|
894
|
+
setInput(interactionId, key, value) {
|
|
895
|
+
store.setState((prev) => {
|
|
896
|
+
const current = prev.drafts[interactionId];
|
|
897
|
+
if (current && current[key] === value) return prev;
|
|
898
|
+
return {
|
|
899
|
+
...prev,
|
|
900
|
+
drafts: {
|
|
901
|
+
...prev.drafts,
|
|
902
|
+
[interactionId]: { ...current ?? {}, [key]: value }
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
});
|
|
906
|
+
},
|
|
907
|
+
clearInput(interactionId, key) {
|
|
908
|
+
store.setState((prev) => {
|
|
909
|
+
const current = prev.drafts[interactionId];
|
|
910
|
+
if (!current) return prev;
|
|
911
|
+
if (key === void 0) {
|
|
912
|
+
return { ...prev, drafts: omitRecordKey(prev.drafts, interactionId) };
|
|
913
|
+
}
|
|
914
|
+
if (!(key in current)) return prev;
|
|
915
|
+
const remainingKeys = omitRecordKey(current, key);
|
|
916
|
+
if (Object.keys(remainingKeys).length === 0) {
|
|
917
|
+
return { ...prev, drafts: omitRecordKey(prev.drafts, interactionId) };
|
|
918
|
+
}
|
|
919
|
+
return {
|
|
920
|
+
...prev,
|
|
921
|
+
drafts: { ...prev.drafts, [interactionId]: remainingKeys }
|
|
922
|
+
};
|
|
923
|
+
});
|
|
924
|
+
},
|
|
925
|
+
clearAll() {
|
|
926
|
+
store.setState((prev) => {
|
|
927
|
+
if (Object.keys(prev.drafts).length === 0 && Object.keys(prev.arms).length === 0 && Object.keys(prev.submitting).length === 0 && prev.pendingInteractionKey === null) {
|
|
928
|
+
return prev;
|
|
929
|
+
}
|
|
930
|
+
return {
|
|
931
|
+
drafts: {},
|
|
932
|
+
arms: {},
|
|
933
|
+
submitting: {},
|
|
934
|
+
pendingInteractionKey: null,
|
|
935
|
+
pendingInteractionRevision: prev.pendingInteractionRevision + 1
|
|
936
|
+
};
|
|
937
|
+
});
|
|
938
|
+
},
|
|
939
|
+
getArmed(surface) {
|
|
940
|
+
return store.getState().arms[surface] ?? null;
|
|
941
|
+
},
|
|
942
|
+
arm(surface, interactionId) {
|
|
943
|
+
store.setState((prev) => {
|
|
944
|
+
const current = prev.arms[surface] ?? null;
|
|
945
|
+
if (current === interactionId) return prev;
|
|
946
|
+
if (interactionId === null) {
|
|
947
|
+
return { ...prev, arms: omitRecordKey(prev.arms, surface) };
|
|
948
|
+
}
|
|
949
|
+
return { ...prev, arms: { ...prev.arms, [surface]: interactionId } };
|
|
950
|
+
});
|
|
951
|
+
},
|
|
952
|
+
getPendingInteraction() {
|
|
953
|
+
return store.getState().pendingInteractionKey;
|
|
954
|
+
},
|
|
955
|
+
setPendingInteraction(interactionId) {
|
|
956
|
+
store.setState((prev) => {
|
|
957
|
+
if (prev.pendingInteractionKey === interactionId) {
|
|
958
|
+
return interactionId === null ? prev : {
|
|
959
|
+
...prev,
|
|
960
|
+
pendingInteractionRevision: prev.pendingInteractionRevision + 1
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
return {
|
|
964
|
+
...prev,
|
|
965
|
+
pendingInteractionKey: interactionId,
|
|
966
|
+
pendingInteractionRevision: prev.pendingInteractionRevision + 1
|
|
967
|
+
};
|
|
968
|
+
});
|
|
969
|
+
},
|
|
970
|
+
getPendingInteractionRevision() {
|
|
971
|
+
return store.getState().pendingInteractionRevision;
|
|
972
|
+
},
|
|
973
|
+
isSubmitting(interactionId) {
|
|
974
|
+
return store.getState().submitting[interactionId] === true;
|
|
975
|
+
},
|
|
976
|
+
claimSubmitting(interactionId) {
|
|
977
|
+
let claimed = false;
|
|
978
|
+
store.setState((prev) => {
|
|
979
|
+
if (prev.submitting[interactionId] === true) return prev;
|
|
980
|
+
claimed = true;
|
|
981
|
+
return {
|
|
982
|
+
...prev,
|
|
983
|
+
submitting: { ...prev.submitting, [interactionId]: true }
|
|
984
|
+
};
|
|
985
|
+
});
|
|
986
|
+
return claimed;
|
|
987
|
+
},
|
|
988
|
+
setSubmitting(interactionId, submitting) {
|
|
989
|
+
store.setState((prev) => {
|
|
990
|
+
const current = prev.submitting[interactionId] === true;
|
|
991
|
+
if (current === submitting) return prev;
|
|
992
|
+
if (!submitting) {
|
|
993
|
+
return {
|
|
994
|
+
...prev,
|
|
995
|
+
submitting: omitRecordKey(prev.submitting, interactionId)
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
return {
|
|
999
|
+
...prev,
|
|
1000
|
+
submitting: { ...prev.submitting, [interactionId]: true }
|
|
1001
|
+
};
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
return Object.assign(store, api);
|
|
1006
|
+
}
|
|
1007
|
+
var InteractionUiCtx = createContext2(null);
|
|
1008
|
+
function InteractionUiProvider({
|
|
1009
|
+
children,
|
|
1010
|
+
store
|
|
1011
|
+
}) {
|
|
1012
|
+
const ownedStore = useMemo3(() => createInteractionUiStore(), []);
|
|
1013
|
+
return /* @__PURE__ */ jsx2(InteractionUiCtx.Provider, { value: store ?? ownedStore, children });
|
|
1014
|
+
}
|
|
1015
|
+
function useInteractionUiStore() {
|
|
1016
|
+
const ctx = useContext2(InteractionUiCtx);
|
|
1017
|
+
const fallback = useMemo3(() => createInteractionUiStore(), []);
|
|
1018
|
+
return ctx ?? fallback;
|
|
1019
|
+
}
|
|
1020
|
+
function useInteractionDraft(interactionId) {
|
|
1021
|
+
const store = useInteractionUiStore();
|
|
1022
|
+
useStore(
|
|
1023
|
+
store,
|
|
1024
|
+
useShallow(
|
|
1025
|
+
(state) => state.drafts[interactionId] ?? EMPTY_DRAFT
|
|
1026
|
+
)
|
|
1027
|
+
);
|
|
1028
|
+
return store.getDraft(interactionId);
|
|
1029
|
+
}
|
|
1030
|
+
function useArmedInteraction(surface) {
|
|
1031
|
+
const store = useInteractionUiStore();
|
|
1032
|
+
return useStore(store, (state) => state.arms[surface] ?? null);
|
|
1033
|
+
}
|
|
1034
|
+
function usePendingInteractionKey() {
|
|
1035
|
+
const store = useInteractionUiStore();
|
|
1036
|
+
const subscribed = useStore(
|
|
1037
|
+
store,
|
|
1038
|
+
(state) => state.pendingInteractionKey ?? null
|
|
1039
|
+
);
|
|
1040
|
+
return store.getPendingInteraction() ?? subscribed;
|
|
1041
|
+
}
|
|
1042
|
+
function usePendingInteractionRevision() {
|
|
1043
|
+
const store = useInteractionUiStore();
|
|
1044
|
+
const subscribed = useStore(
|
|
1045
|
+
store,
|
|
1046
|
+
(state) => state.pendingInteractionRevision
|
|
1047
|
+
);
|
|
1048
|
+
return Math.max(store.getPendingInteractionRevision(), subscribed);
|
|
1049
|
+
}
|
|
1050
|
+
function useInteractionSubmitting(interactionId) {
|
|
1051
|
+
const store = useInteractionUiStore();
|
|
1052
|
+
return useStore(
|
|
1053
|
+
store,
|
|
1054
|
+
(state) => state.submitting[interactionId] === true
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// src/runtime/context/PluginSessionContext.tsx
|
|
1059
|
+
import {
|
|
1060
|
+
createContext as createContext3,
|
|
1061
|
+
useContext as useContext3,
|
|
1062
|
+
useMemo as useMemo4,
|
|
1063
|
+
useSyncExternalStore as useSyncExternalStore3
|
|
1064
|
+
} from "react";
|
|
1065
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1066
|
+
var PluginSessionContext = createContext3(
|
|
1067
|
+
null
|
|
1068
|
+
);
|
|
1069
|
+
var PluginSessionDescriptorContext = createContext3(null);
|
|
1070
|
+
function sessionStateFromClient(runtime) {
|
|
1071
|
+
const session = runtime.getSession();
|
|
1072
|
+
const frame = runtime.getFrame();
|
|
1073
|
+
return {
|
|
1074
|
+
status: session ? "ready" : "loading",
|
|
1075
|
+
sessionId: session?.sessionId ?? null,
|
|
1076
|
+
controllingPlayerId: frame?.perspectivePlayerId ?? null
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function pluginSessionStatesEqual(left, right) {
|
|
1080
|
+
if (left.status !== right.status || left.sessionId !== right.sessionId || left.controllingPlayerId !== right.controllingPlayerId) {
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
return true;
|
|
1084
|
+
}
|
|
1085
|
+
function pluginSessionDescriptorsEqual(left, right) {
|
|
1086
|
+
if (left === right) return true;
|
|
1087
|
+
if (!left || !right) return false;
|
|
1088
|
+
if (left.sessionId !== right.sessionId || left.players.length !== right.players.length) {
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
return left.players.every((player, index) => {
|
|
1092
|
+
const next = right.players[index];
|
|
1093
|
+
return player.playerId === next?.playerId && player.displayName === next.displayName && player.color === next.color;
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
function PluginSessionProvider({
|
|
1097
|
+
runtime,
|
|
1098
|
+
children
|
|
1099
|
+
}) {
|
|
1100
|
+
const sessionStore = useMemo4(
|
|
1101
|
+
() => {
|
|
1102
|
+
let current = sessionStateFromClient(runtime);
|
|
1103
|
+
return {
|
|
1104
|
+
subscribe: (onStoreChange) => {
|
|
1105
|
+
const refresh = () => {
|
|
1106
|
+
const next = sessionStateFromClient(runtime);
|
|
1107
|
+
if (pluginSessionStatesEqual(current, next)) {
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
current = next;
|
|
1111
|
+
onStoreChange();
|
|
1112
|
+
};
|
|
1113
|
+
const unsubscribeSession = runtime.subscribeSession(refresh);
|
|
1114
|
+
const unsubscribeFrame = runtime.subscribeFrame(refresh);
|
|
1115
|
+
return () => {
|
|
1116
|
+
unsubscribeFrame();
|
|
1117
|
+
unsubscribeSession();
|
|
1118
|
+
};
|
|
1119
|
+
},
|
|
1120
|
+
getSnapshot: () => current,
|
|
1121
|
+
getServerSnapshot: () => current
|
|
1122
|
+
};
|
|
1123
|
+
},
|
|
1124
|
+
[runtime]
|
|
1125
|
+
);
|
|
1126
|
+
const descriptorStore = useMemo4(
|
|
1127
|
+
() => {
|
|
1128
|
+
let current = runtime.getSession();
|
|
1129
|
+
return {
|
|
1130
|
+
subscribe: (onStoreChange) => {
|
|
1131
|
+
const refresh = () => {
|
|
1132
|
+
const next = runtime.getSession();
|
|
1133
|
+
if (pluginSessionDescriptorsEqual(current, next)) {
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
current = next;
|
|
1137
|
+
onStoreChange();
|
|
1138
|
+
};
|
|
1139
|
+
const unsubscribeSession = runtime.subscribeSession(refresh);
|
|
1140
|
+
return () => {
|
|
1141
|
+
unsubscribeSession();
|
|
1142
|
+
};
|
|
1143
|
+
},
|
|
1144
|
+
getSnapshot: () => current,
|
|
1145
|
+
getServerSnapshot: () => current
|
|
1146
|
+
};
|
|
1147
|
+
},
|
|
1148
|
+
[runtime]
|
|
1149
|
+
);
|
|
1150
|
+
const sessionState = useSyncExternalStore3(
|
|
1151
|
+
sessionStore.subscribe,
|
|
1152
|
+
sessionStore.getSnapshot,
|
|
1153
|
+
sessionStore.getServerSnapshot
|
|
1154
|
+
);
|
|
1155
|
+
const sessionDescriptor = useSyncExternalStore3(
|
|
1156
|
+
descriptorStore.subscribe,
|
|
1157
|
+
descriptorStore.getSnapshot,
|
|
1158
|
+
descriptorStore.getServerSnapshot
|
|
1159
|
+
);
|
|
1160
|
+
return /* @__PURE__ */ jsx3(PluginSessionContext.Provider, { value: sessionState, children: /* @__PURE__ */ jsx3(PluginSessionDescriptorContext.Provider, { value: sessionDescriptor, children }) });
|
|
1161
|
+
}
|
|
1162
|
+
function usePluginSession() {
|
|
1163
|
+
const context = useContext3(PluginSessionContext);
|
|
1164
|
+
if (context === null) {
|
|
1165
|
+
throw new Error(
|
|
1166
|
+
"usePluginSession must be used within a PluginSessionContext.Provider (provided by RuntimeContext)"
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
return context;
|
|
1170
|
+
}
|
|
1171
|
+
function useOptionalPluginSessionDescriptor() {
|
|
1172
|
+
return useContext3(PluginSessionDescriptorContext);
|
|
1173
|
+
}
|
|
1174
|
+
function usePluginSessionDescriptor() {
|
|
1175
|
+
const descriptor = useOptionalPluginSessionDescriptor();
|
|
1176
|
+
if (!descriptor) {
|
|
1177
|
+
throw new Error(
|
|
1178
|
+
"usePluginSessionDescriptor must be used within PluginSessionProvider."
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
return descriptor;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// src/runtime/context/RuntimeContext.tsx
|
|
1185
|
+
import { createContext as createContext4, useContext as useContext4, useState, useEffect } from "react";
|
|
1186
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1187
|
+
var RuntimeContext = createContext4(null);
|
|
1188
|
+
function useRuntimeContext() {
|
|
1189
|
+
const context = useContext4(RuntimeContext);
|
|
1190
|
+
if (!context) {
|
|
1191
|
+
throw new Error(
|
|
1192
|
+
"useRuntimeContext must be used within a RuntimeContext.Provider"
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
return context;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
export {
|
|
1199
|
+
computePluginActionSetVersion,
|
|
1200
|
+
DREAMBOARD_PLUGIN_PROTOCOL,
|
|
1201
|
+
DREAMBOARD_PLUGIN_PROTOCOL_VERSION,
|
|
1202
|
+
RuntimeJsonSchema,
|
|
1203
|
+
HostToPluginEnvelopeSchema,
|
|
1204
|
+
PluginProtocolFrameSchema,
|
|
1205
|
+
PluginProtocolStepSchema,
|
|
1206
|
+
PluginProtocolTapeSchema,
|
|
1207
|
+
materializePluginGameplayFrame,
|
|
1208
|
+
defaultRuntimeSnapshotEquality,
|
|
1209
|
+
PluginGameplayFrameProvider,
|
|
1210
|
+
usePluginGameplayFrameSelector,
|
|
1211
|
+
useAuthoredPluginGameplayFrameSelector,
|
|
1212
|
+
InteractionUiProvider,
|
|
1213
|
+
useInteractionUiStore,
|
|
1214
|
+
useInteractionDraft,
|
|
1215
|
+
useArmedInteraction,
|
|
1216
|
+
usePendingInteractionKey,
|
|
1217
|
+
usePendingInteractionRevision,
|
|
1218
|
+
useInteractionSubmitting,
|
|
1219
|
+
PluginSessionProvider,
|
|
1220
|
+
usePluginSession,
|
|
1221
|
+
usePluginSessionDescriptor,
|
|
1222
|
+
RuntimeContext,
|
|
1223
|
+
useRuntimeContext
|
|
1224
|
+
};
|
|
1225
|
+
//# sourceMappingURL=chunk-O6M6PN4E.js.map
|