ball2d 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +144 -16
  2. package/dist/browser.js +4051 -0
  3. package/dist/core.wasm +0 -0
  4. package/dist/licenses/fflate.txt +21 -0
  5. package/dist/licenses/json5.txt +23 -0
  6. package/dist/licenses/native.json +236 -0
  7. package/dist/licenses/werift.txt +21 -0
  8. package/dist/node.js +43399 -0
  9. package/dist/stadiums/big.hbs +85 -0
  10. package/dist/stadiums/big_easy.hbs +85 -0
  11. package/dist/stadiums/big_hockey.hbs +87 -0
  12. package/dist/stadiums/big_rounded.hbs +100 -0
  13. package/dist/stadiums/classic.hbs +85 -0
  14. package/dist/stadiums/easy.hbs +85 -0
  15. package/dist/stadiums/hockey.hbs +87 -0
  16. package/dist/stadiums/huge.hbs +85 -0
  17. package/dist/stadiums/provenance.json +46 -0
  18. package/dist/stadiums/rounded.hbs +100 -0
  19. package/dist/stadiums/small.hbs +85 -0
  20. package/dist/types/client/announcement.d.ts +10 -0
  21. package/dist/types/client/connection-stats.d.ts +11 -0
  22. package/dist/types/client/headless.d.ts +130 -0
  23. package/dist/types/client/host-config.d.ts +11 -0
  24. package/dist/types/client/host-runtime.d.ts +10 -0
  25. package/dist/types/client/network-runtime.d.ts +8 -0
  26. package/dist/types/client/network.d.ts +91 -0
  27. package/dist/types/client/stadium-library.d.ts +4 -0
  28. package/dist/types/client/startup-scope.d.ts +6 -0
  29. package/dist/types/client/traffic.d.ts +9 -0
  30. package/dist/types/core/avatar.d.ts +2 -0
  31. package/dist/types/core/build-id.d.ts +2 -0
  32. package/dist/types/core/control.d.ts +5 -0
  33. package/dist/types/core/disc-properties.d.ts +7 -0
  34. package/dist/types/core/engine.d.ts +68 -0
  35. package/dist/types/core/host-types.d.ts +21 -0
  36. package/dist/types/core/match-state.d.ts +17 -0
  37. package/dist/types/core/protocol.d.ts +24 -0
  38. package/dist/types/core/replay-codec.d.ts +6 -0
  39. package/dist/types/core/replay-types.d.ts +41 -0
  40. package/dist/types/core/replay-wire.d.ts +5 -0
  41. package/dist/types/core/replay.d.ts +48 -0
  42. package/dist/types/core/stadium.d.ts +91 -0
  43. package/dist/types/core/team-colors.d.ts +8 -0
  44. package/dist/types/sdk/browser.d.ts +11 -0
  45. package/dist/types/sdk/command-queue.d.ts +11 -0
  46. package/dist/types/sdk/config.d.ts +6 -0
  47. package/dist/types/sdk/create-options.d.ts +4 -0
  48. package/dist/types/sdk/node-transport.d.ts +4 -0
  49. package/dist/types/sdk/node.d.ts +18 -0
  50. package/dist/types/sdk/replay.d.ts +4 -0
  51. package/dist/types/sdk/room.d.ts +7 -0
  52. package/dist/types/sdk/stadium.d.ts +9 -0
  53. package/dist/types/sdk/types.d.ts +78 -0
  54. package/dist/types/shared/room-link.d.ts +6 -0
  55. package/package.json +21 -13
@@ -0,0 +1,4051 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, i, o, s) => {
3
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
4
+ get: ((e) => i[e]).bind(null, d),
5
+ enumerable: !(s = n(i, d)) || s.enumerable
6
+ });
7
+ return e;
8
+ }, c = (n, r, o) => (o = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
9
+ value: n,
10
+ enumerable: !0
11
+ }) : o, n));
12
+ //#endregion
13
+ //#region src/client/startup-scope.ts
14
+ function l(e) {
15
+ let t = new AbortController(), n = () => t.abort(e?.reason);
16
+ e?.aborted ? n() : e?.addEventListener("abort", n, { once: !0 });
17
+ let r = setTimeout(() => t.abort(new DOMException("Room startup timed out", "TimeoutError")), 15e3);
18
+ return {
19
+ signal: t.signal,
20
+ async run(e) {
21
+ let n, r = new Promise((e, t) => {
22
+ n = t;
23
+ }), i = () => n(t.signal.reason);
24
+ t.signal.addEventListener("abort", i, { once: !0 }), t.signal.aborted && i();
25
+ try {
26
+ return await Promise.race([e, r]);
27
+ } finally {
28
+ t.signal.removeEventListener("abort", i);
29
+ }
30
+ },
31
+ dispose() {
32
+ clearTimeout(r), e?.removeEventListener("abort", n);
33
+ }
34
+ };
35
+ }
36
+ //#endregion
37
+ //#region src/client/host-config.ts
38
+ var u = /* @__PURE__ */ new Set([
39
+ "noPlayer",
40
+ "playerName",
41
+ "roomName",
42
+ "maxPlayers",
43
+ "password",
44
+ "public",
45
+ "stadium"
46
+ ]);
47
+ function d(e) {
48
+ if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Room configuration must be an object");
49
+ for (let t of Object.keys(e)) {
50
+ if (t === "token") throw Error("External service tokens are not supported. Ball2D join verification is configured on the room.");
51
+ if (t === "geo") throw Error("Geolocation overrides are not supported. Room country comes from the host connection.");
52
+ if (!u.has(t)) throw Error(`Unknown room setting: ${t}`);
53
+ }
54
+ let t = { ...e };
55
+ if (typeof t.roomName != "string" || !t.roomName.trim() || t.roomName.length > 64) throw Error("Room name must contain 1–64 characters");
56
+ for (let e of ["public", "noPlayer"]) if (t[e] !== void 0 && typeof t[e] != "boolean") throw Error(`Invalid ${e} setting: expected a boolean`);
57
+ if (t.maxPlayers !== void 0 && (typeof t.maxPlayers != "number" || !Number.isInteger(t.maxPlayers) || t.maxPlayers < 2 || t.maxPlayers > 32)) throw Error("maxPlayers must be an integer between 2 and 32");
58
+ if (t.password !== void 0 && (typeof t.password != "string" || t.password.length > 64)) throw Error("Password must be a string of at most 64 characters");
59
+ if (t.stadium !== void 0 && typeof t.stadium != "string") throw Error("Stadium must be an HBS source string");
60
+ if (t.noPlayer === !1 && t.playerName !== void 0 && (typeof t.playerName != "string" || !t.playerName.trim() || t.playerName.length > 24)) throw Error("Invalid host player name");
61
+ return {
62
+ roomName: t.roomName,
63
+ maxPlayers: t.maxPlayers ?? 16,
64
+ password: t.password ?? "",
65
+ public: t.public ?? !0,
66
+ noPlayer: t.noPlayer ?? !0,
67
+ playerName: t.noPlayer === !1 ? (t.playerName ?? "Host").trim() : void 0,
68
+ stadium: t.stadium
69
+ };
70
+ }
71
+ //#endregion
72
+ //#region src/shared/room-link.ts
73
+ function f(e) {
74
+ return /^(?:[0-9a-f]{10}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i.test(e) ? e.toLowerCase() : null;
75
+ }
76
+ function p(e) {
77
+ let t = f(e);
78
+ if (!t) throw Error("Invalid room code");
79
+ return `/r/${t}`;
80
+ }
81
+ //#endregion
82
+ //#region src/core/team-colors.ts
83
+ function m(e, t, n) {
84
+ if (!Number.isFinite(e) || !Number.isInteger(t) || t < 0 || t > 16777215 || !Array.isArray(n) || n.length < 1 || n.length > 3 || n.some((e) => !Number.isInteger(e) || e < 0 || e > 16777215)) throw Error("Invalid team colors");
85
+ return {
86
+ angle: (e % 360 + 360) % 360,
87
+ textColor: t,
88
+ colors: [...n]
89
+ };
90
+ }
91
+ function h(e) {
92
+ if (e === void 0) return [null, null];
93
+ if (!Array.isArray(e) || e.length !== 2) throw Error("Invalid team styles");
94
+ return e.map((e) => e === null ? null : m(e.angle, e.textColor, e.colors));
95
+ }
96
+ //#endregion
97
+ //#region src/client/announcement.ts
98
+ var g = [
99
+ "normal",
100
+ "bold",
101
+ "italic",
102
+ "small",
103
+ "small-bold",
104
+ "small-italic"
105
+ ];
106
+ function _(e, t, n, r) {
107
+ if (typeof e != "string" || e.length > 1e3) throw Error("Announcement exceeds 1000 characters");
108
+ if (t != null && (!Number.isInteger(t) || t < 0 || t > 16777215)) throw Error("Invalid announcement color");
109
+ if (n != null && !g.includes(n)) throw Error("Invalid announcement style");
110
+ if (r != null && ![
111
+ 0,
112
+ 1,
113
+ 2
114
+ ].includes(r)) throw Error("Invalid announcement sound");
115
+ return {
116
+ type: "announcement",
117
+ text: e,
118
+ color: t ?? null,
119
+ style: n ?? "normal",
120
+ sound: r ?? 1
121
+ };
122
+ }
123
+ //#endregion
124
+ //#region src/core/avatar.ts
125
+ function v(e) {
126
+ return e === null || typeof e == "string" && Array.from(e).length <= 2 && !/[\p{Cc}\p{Cf}]/u.test(e);
127
+ }
128
+ //#endregion
129
+ //#region src/core/disc-properties.ts
130
+ var y = [
131
+ [
132
+ "x",
133
+ 0,
134
+ -8192,
135
+ 8192
136
+ ],
137
+ [
138
+ "y",
139
+ 1,
140
+ -8192,
141
+ 8192
142
+ ],
143
+ [
144
+ "xspeed",
145
+ 2,
146
+ -8192,
147
+ 8192
148
+ ],
149
+ [
150
+ "yspeed",
151
+ 3,
152
+ -8192,
153
+ 8192
154
+ ],
155
+ [
156
+ "xgravity",
157
+ 8,
158
+ -8192,
159
+ 8192
160
+ ],
161
+ [
162
+ "ygravity",
163
+ 9,
164
+ -8192,
165
+ 8192
166
+ ],
167
+ [
168
+ "radius",
169
+ 4,
170
+ .5,
171
+ 100
172
+ ],
173
+ [
174
+ "bCoeff",
175
+ 7,
176
+ -1,
177
+ 8192
178
+ ],
179
+ [
180
+ "invMass",
181
+ 5,
182
+ 0,
183
+ 8192
184
+ ],
185
+ [
186
+ "damping",
187
+ 6,
188
+ 0,
189
+ 8192
190
+ ],
191
+ [
192
+ "color",
193
+ -1,
194
+ -1,
195
+ 16777215
196
+ ],
197
+ [
198
+ "cMask",
199
+ 11,
200
+ -2147483648,
201
+ 2147483647
202
+ ],
203
+ [
204
+ "cGroup",
205
+ 10,
206
+ -2147483648,
207
+ 2147483647
208
+ ]
209
+ ];
210
+ function b(e) {
211
+ if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Invalid disc property update");
212
+ let t = e, n = {};
213
+ for (let e = 0; e < y.length; e++) {
214
+ let [r, , i, a] = y[e], o = t[r];
215
+ if (o == null) continue;
216
+ if (typeof o != "number" || !Number.isFinite(o)) throw Error(`Invalid disc property: ${r}`);
217
+ let s = e < 10 ? Math.fround(o) : o | 0;
218
+ if (!Number.isFinite(s) || s < Math.fround(i) || s > a) throw Error(`Invalid disc property: ${r}`);
219
+ n[r] = s;
220
+ }
221
+ return n;
222
+ }
223
+ //#endregion
224
+ //#region src/core/build-id.ts
225
+ var x = "3de72bdcf92ccb0d235a", S = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
226
+ (function(n, r) {
227
+ typeof e == "object" && t !== void 0 ? t.exports = r() : typeof define == "function" && define.amd ? define(r) : n.JSON5 = r();
228
+ })(e, (function() {
229
+ function e(e, t) {
230
+ return t = { exports: {} }, e(t, t.exports), t.exports;
231
+ }
232
+ var t = e(function(e) {
233
+ var t = e.exports = typeof window < "u" && window.Math == Math ? window : typeof self < "u" && self.Math == Math ? self : Function("return this")();
234
+ typeof __g == "number" && (__g = t);
235
+ }), n = e(function(e) {
236
+ var t = e.exports = { version: "2.6.5" };
237
+ typeof __e == "number" && (__e = t);
238
+ });
239
+ n.version;
240
+ var r = function(e) {
241
+ return typeof e == "object" ? e !== null : typeof e == "function";
242
+ }, i = function(e) {
243
+ if (!r(e)) throw TypeError(e + " is not an object!");
244
+ return e;
245
+ }, a = function(e) {
246
+ try {
247
+ return !!e();
248
+ } catch {
249
+ return !0;
250
+ }
251
+ }, o = !a(function() {
252
+ return Object.defineProperty({}, "a", { get: function() {
253
+ return 7;
254
+ } }).a != 7;
255
+ }), s = t.document, c = r(s) && r(s.createElement), l = function(e) {
256
+ return c ? s.createElement(e) : {};
257
+ }, u = !o && !a(function() {
258
+ return Object.defineProperty(l("div"), "a", { get: function() {
259
+ return 7;
260
+ } }).a != 7;
261
+ }), d = function(e, t) {
262
+ if (!r(e)) return e;
263
+ var n, i;
264
+ if (t && typeof (n = e.toString) == "function" && !r(i = n.call(e)) || typeof (n = e.valueOf) == "function" && !r(i = n.call(e)) || !t && typeof (n = e.toString) == "function" && !r(i = n.call(e))) return i;
265
+ throw TypeError("Can't convert object to primitive value");
266
+ }, f = Object.defineProperty, p = { f: o ? Object.defineProperty : function(e, t, n) {
267
+ if (i(e), t = d(t, !0), i(n), u) try {
268
+ return f(e, t, n);
269
+ } catch {}
270
+ if ("get" in n || "set" in n) throw TypeError("Accessors not supported!");
271
+ return "value" in n && (e[t] = n.value), e;
272
+ } }, m = function(e, t) {
273
+ return {
274
+ enumerable: !(e & 1),
275
+ configurable: !(e & 2),
276
+ writable: !(e & 4),
277
+ value: t
278
+ };
279
+ }, h = o ? function(e, t, n) {
280
+ return p.f(e, t, m(1, n));
281
+ } : function(e, t, n) {
282
+ return e[t] = n, e;
283
+ }, g = {}.hasOwnProperty, _ = function(e, t) {
284
+ return g.call(e, t);
285
+ }, v = 0, y = Math.random(), b = function(e) {
286
+ return `Symbol(${e === void 0 ? "" : e})_${(++v + y).toString(36)}`;
287
+ }, x = e(function(e) {
288
+ var r = "__core-js_shared__", i = t[r] || (t[r] = {});
289
+ (e.exports = function(e, t) {
290
+ return i[e] || (i[e] = t === void 0 ? {} : t);
291
+ })("versions", []).push({
292
+ version: n.version,
293
+ mode: "global",
294
+ copyright: "© 2019 Denis Pushkarev (zloirock.ru)"
295
+ });
296
+ })("native-function-to-string", Function.toString), S = e(function(e) {
297
+ var r = b("src"), i = "toString", a = ("" + x).split(i);
298
+ n.inspectSource = function(e) {
299
+ return x.call(e);
300
+ }, (e.exports = function(e, n, i, o) {
301
+ var s = typeof i == "function";
302
+ s && (_(i, "name") || h(i, "name", n)), e[n] !== i && (s && (_(i, r) || h(i, r, e[n] ? "" + e[n] : a.join(String(n)))), e === t ? e[n] = i : o ? e[n] ? e[n] = i : h(e, n, i) : (delete e[n], h(e, n, i)));
303
+ })(Function.prototype, i, function() {
304
+ return typeof this == "function" && this[r] || x.call(this);
305
+ });
306
+ }), C = function(e) {
307
+ if (typeof e != "function") throw TypeError(e + " is not a function!");
308
+ return e;
309
+ }, w = function(e, t, n) {
310
+ if (C(e), t === void 0) return e;
311
+ switch (n) {
312
+ case 1: return function(n) {
313
+ return e.call(t, n);
314
+ };
315
+ case 2: return function(n, r) {
316
+ return e.call(t, n, r);
317
+ };
318
+ case 3: return function(n, r, i) {
319
+ return e.call(t, n, r, i);
320
+ };
321
+ }
322
+ return function() {
323
+ return e.apply(t, arguments);
324
+ };
325
+ }, T = "prototype", E = function(e, r, i) {
326
+ var a = e & E.F, o = e & E.G, s = e & E.S, c = e & E.P, l = e & E.B, u = o ? t : s ? t[r] || (t[r] = {}) : (t[r] || {})[T], d = o ? n : n[r] || (n[r] = {}), f = d[T] || (d[T] = {}), p, m, g, _;
327
+ for (p in o && (i = r), i) m = !a && u && u[p] !== void 0, g = (m ? u : i)[p], _ = l && m ? w(g, t) : c && typeof g == "function" ? w(Function.call, g) : g, u && S(u, p, g, e & E.U), d[p] != g && h(d, p, _), c && f[p] != g && (f[p] = g);
328
+ };
329
+ t.core = n, E.F = 1, E.G = 2, E.S = 4, E.P = 8, E.B = 16, E.W = 32, E.U = 64, E.R = 128;
330
+ var D = E, O = Math.ceil, k = Math.floor, A = function(e) {
331
+ return isNaN(e = +e) ? 0 : (e > 0 ? k : O)(e);
332
+ }, j = function(e) {
333
+ if (e == null) throw TypeError("Can't call method on " + e);
334
+ return e;
335
+ }, M = function(e) {
336
+ return function(t, n) {
337
+ var r = String(j(t)), i = A(n), a = r.length, o, s;
338
+ return i < 0 || i >= a ? e ? "" : void 0 : (o = r.charCodeAt(i), o < 55296 || o > 56319 || i + 1 === a || (s = r.charCodeAt(i + 1)) < 56320 || s > 57343 ? e ? r.charAt(i) : o : e ? r.slice(i, i + 2) : (o - 55296 << 10) + (s - 56320) + 65536);
339
+ };
340
+ }(!1);
341
+ D(D.P, "String", { codePointAt: function(e) {
342
+ return M(this, e);
343
+ } }), n.String.codePointAt;
344
+ var N = Math.max, P = Math.min, F = function(e, t) {
345
+ return e = A(e), e < 0 ? N(e + t, 0) : P(e, t);
346
+ }, ee = String.fromCharCode, I = String.fromCodePoint;
347
+ D(D.S + D.F * (!!I && I.length != 1), "String", { fromCodePoint: function(e) {
348
+ for (var t = arguments, n = [], r = arguments.length, i = 0, a; r > i;) {
349
+ if (a = +t[i++], F(a, 1114111) !== a) throw RangeError(a + " is not a valid code point");
350
+ n.push(a < 65536 ? ee(a) : ee(((a -= 65536) >> 10) + 55296, a % 1024 + 56320));
351
+ }
352
+ return n.join("");
353
+ } }), n.String.fromCodePoint;
354
+ var L = {
355
+ Space_Separator: /[\u1680\u2000-\u200A\u202F\u205F\u3000]/,
356
+ ID_Start: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,
357
+ ID_Continue: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
358
+ }, R = {
359
+ isSpaceSeparator: function(e) {
360
+ return typeof e == "string" && L.Space_Separator.test(e);
361
+ },
362
+ isIdStartChar: function(e) {
363
+ return typeof e == "string" && (e >= "a" && e <= "z" || e >= "A" && e <= "Z" || e === "$" || e === "_" || L.ID_Start.test(e));
364
+ },
365
+ isIdContinueChar: function(e) {
366
+ return typeof e == "string" && (e >= "a" && e <= "z" || e >= "A" && e <= "Z" || e >= "0" && e <= "9" || e === "$" || e === "_" || e === "‌" || e === "‍" || L.ID_Continue.test(e));
367
+ },
368
+ isDigit: function(e) {
369
+ return typeof e == "string" && /[0-9]/.test(e);
370
+ },
371
+ isHexDigit: function(e) {
372
+ return typeof e == "string" && /[0-9A-Fa-f]/.test(e);
373
+ }
374
+ }, z, B, V, te, H, U, W, G, ne, re = function(e, t) {
375
+ z = String(e), B = "start", V = [], te = 0, H = 1, U = 0, W = void 0, G = void 0, ne = void 0;
376
+ do
377
+ W = se(), pe[B]();
378
+ while (W.type !== "eof");
379
+ return typeof t == "function" ? ie({ "": ne }, "", t) : ne;
380
+ };
381
+ function ie(e, t, n) {
382
+ var r = e[t];
383
+ if (typeof r == "object" && r) {
384
+ if (Array.isArray(r)) for (var i = 0; i < r.length; i++) {
385
+ var a = String(i), o = ie(r, a, n);
386
+ o === void 0 ? delete r[a] : Object.defineProperty(r, a, {
387
+ value: o,
388
+ writable: !0,
389
+ enumerable: !0,
390
+ configurable: !0
391
+ });
392
+ }
393
+ else for (var s in r) {
394
+ var c = ie(r, s, n);
395
+ c === void 0 ? delete r[s] : Object.defineProperty(r, s, {
396
+ value: c,
397
+ writable: !0,
398
+ enumerable: !0,
399
+ configurable: !0
400
+ });
401
+ }
402
+ }
403
+ return n.call(e, t, r);
404
+ }
405
+ var K, q, ae, oe, J;
406
+ function se() {
407
+ for (K = "default", q = "", ae = !1, oe = 1;;) {
408
+ J = ce();
409
+ var e = le[K]();
410
+ if (e) return e;
411
+ }
412
+ }
413
+ function ce() {
414
+ if (z[te]) return String.fromCodePoint(z.codePointAt(te));
415
+ }
416
+ function Y() {
417
+ var e = ce();
418
+ return e === "\n" ? (H++, U = 0) : e ? U += e.length : U++, e && (te += e.length), e;
419
+ }
420
+ var le = {
421
+ default: function() {
422
+ switch (J) {
423
+ case " ":
424
+ case "\v":
425
+ case "\f":
426
+ case " ":
427
+ case "\xA0":
428
+ case "":
429
+ case "\n":
430
+ case "\r":
431
+ case "\u2028":
432
+ case "\u2029":
433
+ Y();
434
+ return;
435
+ case "/":
436
+ Y(), K = "comment";
437
+ return;
438
+ case void 0: return Y(), X("eof");
439
+ }
440
+ if (R.isSpaceSeparator(J)) {
441
+ Y();
442
+ return;
443
+ }
444
+ return le[B]();
445
+ },
446
+ comment: function() {
447
+ switch (J) {
448
+ case "*":
449
+ Y(), K = "multiLineComment";
450
+ return;
451
+ case "/":
452
+ Y(), K = "singleLineComment";
453
+ return;
454
+ }
455
+ throw Q(Y());
456
+ },
457
+ multiLineComment: function() {
458
+ switch (J) {
459
+ case "*":
460
+ Y(), K = "multiLineCommentAsterisk";
461
+ return;
462
+ case void 0: throw Q(Y());
463
+ }
464
+ Y();
465
+ },
466
+ multiLineCommentAsterisk: function() {
467
+ switch (J) {
468
+ case "*":
469
+ Y();
470
+ return;
471
+ case "/":
472
+ Y(), K = "default";
473
+ return;
474
+ case void 0: throw Q(Y());
475
+ }
476
+ Y(), K = "multiLineComment";
477
+ },
478
+ singleLineComment: function() {
479
+ switch (J) {
480
+ case "\n":
481
+ case "\r":
482
+ case "\u2028":
483
+ case "\u2029":
484
+ Y(), K = "default";
485
+ return;
486
+ case void 0: return Y(), X("eof");
487
+ }
488
+ Y();
489
+ },
490
+ value: function() {
491
+ switch (J) {
492
+ case "{":
493
+ case "[": return X("punctuator", Y());
494
+ case "n": return Y(), Z("ull"), X("null", null);
495
+ case "t": return Y(), Z("rue"), X("boolean", !0);
496
+ case "f": return Y(), Z("alse"), X("boolean", !1);
497
+ case "-":
498
+ case "+":
499
+ Y() === "-" && (oe = -1), K = "sign";
500
+ return;
501
+ case ".":
502
+ q = Y(), K = "decimalPointLeading";
503
+ return;
504
+ case "0":
505
+ q = Y(), K = "zero";
506
+ return;
507
+ case "1":
508
+ case "2":
509
+ case "3":
510
+ case "4":
511
+ case "5":
512
+ case "6":
513
+ case "7":
514
+ case "8":
515
+ case "9":
516
+ q = Y(), K = "decimalInteger";
517
+ return;
518
+ case "I": return Y(), Z("nfinity"), X("numeric", Infinity);
519
+ case "N": return Y(), Z("aN"), X("numeric", NaN);
520
+ case "\"":
521
+ case "'":
522
+ ae = Y() === "\"", q = "", K = "string";
523
+ return;
524
+ }
525
+ throw Q(Y());
526
+ },
527
+ identifierNameStartEscape: function() {
528
+ if (J !== "u") throw Q(Y());
529
+ Y();
530
+ var e = fe();
531
+ switch (e) {
532
+ case "$":
533
+ case "_": break;
534
+ default: if (!R.isIdStartChar(e)) throw $();
535
+ }
536
+ q += e, K = "identifierName";
537
+ },
538
+ identifierName: function() {
539
+ switch (J) {
540
+ case "$":
541
+ case "_":
542
+ case "‌":
543
+ case "‍":
544
+ q += Y();
545
+ return;
546
+ case "\\":
547
+ Y(), K = "identifierNameEscape";
548
+ return;
549
+ }
550
+ if (R.isIdContinueChar(J)) {
551
+ q += Y();
552
+ return;
553
+ }
554
+ return X("identifier", q);
555
+ },
556
+ identifierNameEscape: function() {
557
+ if (J !== "u") throw Q(Y());
558
+ Y();
559
+ var e = fe();
560
+ switch (e) {
561
+ case "$":
562
+ case "_":
563
+ case "‌":
564
+ case "‍": break;
565
+ default: if (!R.isIdContinueChar(e)) throw $();
566
+ }
567
+ q += e, K = "identifierName";
568
+ },
569
+ sign: function() {
570
+ switch (J) {
571
+ case ".":
572
+ q = Y(), K = "decimalPointLeading";
573
+ return;
574
+ case "0":
575
+ q = Y(), K = "zero";
576
+ return;
577
+ case "1":
578
+ case "2":
579
+ case "3":
580
+ case "4":
581
+ case "5":
582
+ case "6":
583
+ case "7":
584
+ case "8":
585
+ case "9":
586
+ q = Y(), K = "decimalInteger";
587
+ return;
588
+ case "I": return Y(), Z("nfinity"), X("numeric", oe * Infinity);
589
+ case "N": return Y(), Z("aN"), X("numeric", NaN);
590
+ }
591
+ throw Q(Y());
592
+ },
593
+ zero: function() {
594
+ switch (J) {
595
+ case ".":
596
+ q += Y(), K = "decimalPoint";
597
+ return;
598
+ case "e":
599
+ case "E":
600
+ q += Y(), K = "decimalExponent";
601
+ return;
602
+ case "x":
603
+ case "X":
604
+ q += Y(), K = "hexadecimal";
605
+ return;
606
+ }
607
+ return X("numeric", oe * 0);
608
+ },
609
+ decimalInteger: function() {
610
+ switch (J) {
611
+ case ".":
612
+ q += Y(), K = "decimalPoint";
613
+ return;
614
+ case "e":
615
+ case "E":
616
+ q += Y(), K = "decimalExponent";
617
+ return;
618
+ }
619
+ if (R.isDigit(J)) {
620
+ q += Y();
621
+ return;
622
+ }
623
+ return X("numeric", oe * Number(q));
624
+ },
625
+ decimalPointLeading: function() {
626
+ if (R.isDigit(J)) {
627
+ q += Y(), K = "decimalFraction";
628
+ return;
629
+ }
630
+ throw Q(Y());
631
+ },
632
+ decimalPoint: function() {
633
+ switch (J) {
634
+ case "e":
635
+ case "E":
636
+ q += Y(), K = "decimalExponent";
637
+ return;
638
+ }
639
+ if (R.isDigit(J)) {
640
+ q += Y(), K = "decimalFraction";
641
+ return;
642
+ }
643
+ return X("numeric", oe * Number(q));
644
+ },
645
+ decimalFraction: function() {
646
+ switch (J) {
647
+ case "e":
648
+ case "E":
649
+ q += Y(), K = "decimalExponent";
650
+ return;
651
+ }
652
+ if (R.isDigit(J)) {
653
+ q += Y();
654
+ return;
655
+ }
656
+ return X("numeric", oe * Number(q));
657
+ },
658
+ decimalExponent: function() {
659
+ switch (J) {
660
+ case "+":
661
+ case "-":
662
+ q += Y(), K = "decimalExponentSign";
663
+ return;
664
+ }
665
+ if (R.isDigit(J)) {
666
+ q += Y(), K = "decimalExponentInteger";
667
+ return;
668
+ }
669
+ throw Q(Y());
670
+ },
671
+ decimalExponentSign: function() {
672
+ if (R.isDigit(J)) {
673
+ q += Y(), K = "decimalExponentInteger";
674
+ return;
675
+ }
676
+ throw Q(Y());
677
+ },
678
+ decimalExponentInteger: function() {
679
+ if (R.isDigit(J)) {
680
+ q += Y();
681
+ return;
682
+ }
683
+ return X("numeric", oe * Number(q));
684
+ },
685
+ hexadecimal: function() {
686
+ if (R.isHexDigit(J)) {
687
+ q += Y(), K = "hexadecimalInteger";
688
+ return;
689
+ }
690
+ throw Q(Y());
691
+ },
692
+ hexadecimalInteger: function() {
693
+ if (R.isHexDigit(J)) {
694
+ q += Y();
695
+ return;
696
+ }
697
+ return X("numeric", oe * Number(q));
698
+ },
699
+ string: function() {
700
+ switch (J) {
701
+ case "\\":
702
+ Y(), q += ue();
703
+ return;
704
+ case "\"":
705
+ if (ae) return Y(), X("string", q);
706
+ q += Y();
707
+ return;
708
+ case "'":
709
+ if (!ae) return Y(), X("string", q);
710
+ q += Y();
711
+ return;
712
+ case "\n":
713
+ case "\r": throw Q(Y());
714
+ case "\u2028":
715
+ case "\u2029":
716
+ _e(J);
717
+ break;
718
+ case void 0: throw Q(Y());
719
+ }
720
+ q += Y();
721
+ },
722
+ start: function() {
723
+ switch (J) {
724
+ case "{":
725
+ case "[": return X("punctuator", Y());
726
+ }
727
+ K = "value";
728
+ },
729
+ beforePropertyName: function() {
730
+ switch (J) {
731
+ case "$":
732
+ case "_":
733
+ q = Y(), K = "identifierName";
734
+ return;
735
+ case "\\":
736
+ Y(), K = "identifierNameStartEscape";
737
+ return;
738
+ case "}": return X("punctuator", Y());
739
+ case "\"":
740
+ case "'":
741
+ ae = Y() === "\"", K = "string";
742
+ return;
743
+ }
744
+ if (R.isIdStartChar(J)) {
745
+ q += Y(), K = "identifierName";
746
+ return;
747
+ }
748
+ throw Q(Y());
749
+ },
750
+ afterPropertyName: function() {
751
+ if (J === ":") return X("punctuator", Y());
752
+ throw Q(Y());
753
+ },
754
+ beforePropertyValue: function() {
755
+ K = "value";
756
+ },
757
+ afterPropertyValue: function() {
758
+ switch (J) {
759
+ case ",":
760
+ case "}": return X("punctuator", Y());
761
+ }
762
+ throw Q(Y());
763
+ },
764
+ beforeArrayValue: function() {
765
+ if (J === "]") return X("punctuator", Y());
766
+ K = "value";
767
+ },
768
+ afterArrayValue: function() {
769
+ switch (J) {
770
+ case ",":
771
+ case "]": return X("punctuator", Y());
772
+ }
773
+ throw Q(Y());
774
+ },
775
+ end: function() {
776
+ throw Q(Y());
777
+ }
778
+ };
779
+ function X(e, t) {
780
+ return {
781
+ type: e,
782
+ value: t,
783
+ line: H,
784
+ column: U
785
+ };
786
+ }
787
+ function Z(e) {
788
+ for (var t = 0, n = e; t < n.length; t += 1) {
789
+ var r = n[t];
790
+ if (ce() !== r) throw Q(Y());
791
+ Y();
792
+ }
793
+ }
794
+ function ue() {
795
+ switch (ce()) {
796
+ case "b": return Y(), "\b";
797
+ case "f": return Y(), "\f";
798
+ case "n": return Y(), "\n";
799
+ case "r": return Y(), "\r";
800
+ case "t": return Y(), " ";
801
+ case "v": return Y(), "\v";
802
+ case "0":
803
+ if (Y(), R.isDigit(ce())) throw Q(Y());
804
+ return "\0";
805
+ case "x": return Y(), de();
806
+ case "u": return Y(), fe();
807
+ case "\n":
808
+ case "\u2028":
809
+ case "\u2029": return Y(), "";
810
+ case "\r": return Y(), ce() === "\n" && Y(), "";
811
+ case "1":
812
+ case "2":
813
+ case "3":
814
+ case "4":
815
+ case "5":
816
+ case "6":
817
+ case "7":
818
+ case "8":
819
+ case "9": throw Q(Y());
820
+ case void 0: throw Q(Y());
821
+ }
822
+ return Y();
823
+ }
824
+ function de() {
825
+ var e = "", t = ce();
826
+ if (!R.isHexDigit(t) || (e += Y(), t = ce(), !R.isHexDigit(t))) throw Q(Y());
827
+ return e += Y(), String.fromCodePoint(parseInt(e, 16));
828
+ }
829
+ function fe() {
830
+ for (var e = "", t = 4; t-- > 0;) {
831
+ var n = ce();
832
+ if (!R.isHexDigit(n)) throw Q(Y());
833
+ e += Y();
834
+ }
835
+ return String.fromCodePoint(parseInt(e, 16));
836
+ }
837
+ var pe = {
838
+ start: function() {
839
+ if (W.type === "eof") throw ge();
840
+ me();
841
+ },
842
+ beforePropertyName: function() {
843
+ switch (W.type) {
844
+ case "identifier":
845
+ case "string":
846
+ G = W.value, B = "afterPropertyName";
847
+ return;
848
+ case "punctuator":
849
+ he();
850
+ return;
851
+ case "eof": throw ge();
852
+ }
853
+ },
854
+ afterPropertyName: function() {
855
+ if (W.type === "eof") throw ge();
856
+ B = "beforePropertyValue";
857
+ },
858
+ beforePropertyValue: function() {
859
+ if (W.type === "eof") throw ge();
860
+ me();
861
+ },
862
+ beforeArrayValue: function() {
863
+ if (W.type === "eof") throw ge();
864
+ if (W.type === "punctuator" && W.value === "]") {
865
+ he();
866
+ return;
867
+ }
868
+ me();
869
+ },
870
+ afterPropertyValue: function() {
871
+ if (W.type === "eof") throw ge();
872
+ switch (W.value) {
873
+ case ",":
874
+ B = "beforePropertyName";
875
+ return;
876
+ case "}": he();
877
+ }
878
+ },
879
+ afterArrayValue: function() {
880
+ if (W.type === "eof") throw ge();
881
+ switch (W.value) {
882
+ case ",":
883
+ B = "beforeArrayValue";
884
+ return;
885
+ case "]": he();
886
+ }
887
+ },
888
+ end: function() {}
889
+ };
890
+ function me() {
891
+ var e;
892
+ switch (W.type) {
893
+ case "punctuator":
894
+ switch (W.value) {
895
+ case "{":
896
+ e = {};
897
+ break;
898
+ case "[": e = [];
899
+ }
900
+ break;
901
+ case "null":
902
+ case "boolean":
903
+ case "numeric":
904
+ case "string": e = W.value;
905
+ }
906
+ if (ne === void 0) ne = e;
907
+ else {
908
+ var t = V[V.length - 1];
909
+ Array.isArray(t) ? t.push(e) : Object.defineProperty(t, G, {
910
+ value: e,
911
+ writable: !0,
912
+ enumerable: !0,
913
+ configurable: !0
914
+ });
915
+ }
916
+ if (typeof e == "object" && e) V.push(e), B = Array.isArray(e) ? "beforeArrayValue" : "beforePropertyName";
917
+ else {
918
+ var n = V[V.length - 1];
919
+ B = n == null ? "end" : Array.isArray(n) ? "afterArrayValue" : "afterPropertyValue";
920
+ }
921
+ }
922
+ function he() {
923
+ V.pop();
924
+ var e = V[V.length - 1];
925
+ B = e == null ? "end" : Array.isArray(e) ? "afterArrayValue" : "afterPropertyValue";
926
+ }
927
+ function Q(e) {
928
+ return ye(e === void 0 ? "JSON5: invalid end of input at " + H + ":" + U : "JSON5: invalid character '" + ve(e) + "' at " + H + ":" + U);
929
+ }
930
+ function ge() {
931
+ return ye("JSON5: invalid end of input at " + H + ":" + U);
932
+ }
933
+ function $() {
934
+ return U -= 5, ye("JSON5: invalid identifier character at " + H + ":" + U);
935
+ }
936
+ function _e(e) {
937
+ console.warn("JSON5: '" + ve(e) + "' in strings is not valid ECMAScript; consider escaping");
938
+ }
939
+ function ve(e) {
940
+ var t = {
941
+ "'": "\\'",
942
+ "\"": "\\\"",
943
+ "\\": "\\\\",
944
+ "\b": "\\b",
945
+ "\f": "\\f",
946
+ "\n": "\\n",
947
+ "\r": "\\r",
948
+ " ": "\\t",
949
+ "\v": "\\v",
950
+ "\0": "\\0",
951
+ "\u2028": "\\u2028",
952
+ "\u2029": "\\u2029"
953
+ };
954
+ if (t[e]) return t[e];
955
+ if (e < " ") {
956
+ var n = e.charCodeAt(0).toString(16);
957
+ return "\\x" + ("00" + n).substring(n.length);
958
+ }
959
+ return e;
960
+ }
961
+ function ye(e) {
962
+ var t = SyntaxError(e);
963
+ return t.lineNumber = H, t.columnNumber = U, t;
964
+ }
965
+ return {
966
+ parse: re,
967
+ stringify: function(e, t, n) {
968
+ var r = [], i = "", a, o, s = "", c;
969
+ if (typeof t == "object" && t && !Array.isArray(t) && (n = t.space, c = t.quote, t = t.replacer), typeof t == "function") o = t;
970
+ else if (Array.isArray(t)) {
971
+ a = [];
972
+ for (var l = 0, u = t; l < u.length; l += 1) {
973
+ var d = u[l], f = void 0;
974
+ typeof d == "string" ? f = d : (typeof d == "number" || d instanceof String || d instanceof Number) && (f = String(d)), f !== void 0 && a.indexOf(f) < 0 && a.push(f);
975
+ }
976
+ }
977
+ return n instanceof Number ? n = Number(n) : n instanceof String && (n = String(n)), typeof n == "number" ? n > 0 && (n = Math.min(10, Math.floor(n)), s = " ".substr(0, n)) : typeof n == "string" && (s = n.substr(0, 10)), p("", { "": e });
978
+ function p(e, t) {
979
+ var n = t[e];
980
+ switch (n != null && (typeof n.toJSON5 == "function" ? n = n.toJSON5(e) : typeof n.toJSON == "function" && (n = n.toJSON(e))), o && (n = o.call(t, e, n)), n instanceof Number ? n = Number(n) : n instanceof String ? n = String(n) : n instanceof Boolean && (n = n.valueOf()), n) {
981
+ case null: return "null";
982
+ case !0: return "true";
983
+ case !1: return "false";
984
+ }
985
+ if (typeof n == "string") return m(n, !1);
986
+ if (typeof n == "number") return String(n);
987
+ if (typeof n == "object") return Array.isArray(n) ? _(n) : h(n);
988
+ }
989
+ function m(e) {
990
+ for (var t = {
991
+ "'": .1,
992
+ "\"": .2
993
+ }, n = {
994
+ "'": "\\'",
995
+ "\"": "\\\"",
996
+ "\\": "\\\\",
997
+ "\b": "\\b",
998
+ "\f": "\\f",
999
+ "\n": "\\n",
1000
+ "\r": "\\r",
1001
+ " ": "\\t",
1002
+ "\v": "\\v",
1003
+ "\0": "\\0",
1004
+ "\u2028": "\\u2028",
1005
+ "\u2029": "\\u2029"
1006
+ }, r = "", i = 0; i < e.length; i++) {
1007
+ var a = e[i];
1008
+ switch (a) {
1009
+ case "'":
1010
+ case "\"":
1011
+ t[a]++, r += a;
1012
+ continue;
1013
+ case "\0": if (R.isDigit(e[i + 1])) {
1014
+ r += "\\x00";
1015
+ continue;
1016
+ }
1017
+ }
1018
+ if (n[a]) {
1019
+ r += n[a];
1020
+ continue;
1021
+ }
1022
+ if (a < " ") {
1023
+ var o = a.charCodeAt(0).toString(16);
1024
+ r += "\\x" + ("00" + o).substring(o.length);
1025
+ continue;
1026
+ }
1027
+ r += a;
1028
+ }
1029
+ var s = c || Object.keys(t).reduce(function(e, n) {
1030
+ return t[e] < t[n] ? e : n;
1031
+ });
1032
+ return r = r.replace(new RegExp(s, "g"), n[s]), s + r + s;
1033
+ }
1034
+ function h(e) {
1035
+ if (r.indexOf(e) >= 0) throw TypeError("Converting circular structure to JSON5");
1036
+ r.push(e);
1037
+ var t = i;
1038
+ i += s;
1039
+ for (var n = a || Object.keys(e), o = [], c = 0, l = n; c < l.length; c += 1) {
1040
+ var u = l[c], d = p(u, e);
1041
+ if (d !== void 0) {
1042
+ var f = g(u) + ":";
1043
+ s !== "" && (f += " "), f += d, o.push(f);
1044
+ }
1045
+ }
1046
+ var m;
1047
+ if (o.length === 0) m = "{}";
1048
+ else {
1049
+ var h;
1050
+ if (s === "") h = o.join(","), m = "{" + h + "}";
1051
+ else {
1052
+ var _ = ",\n" + i;
1053
+ h = o.join(_), m = "{\n" + i + h + ",\n" + t + "}";
1054
+ }
1055
+ }
1056
+ return r.pop(), i = t, m;
1057
+ }
1058
+ function g(e) {
1059
+ if (e.length === 0) return m(e, !0);
1060
+ var t = String.fromCodePoint(e.codePointAt(0));
1061
+ if (!R.isIdStartChar(t)) return m(e, !0);
1062
+ for (var n = t.length; n < e.length; n++) if (!R.isIdContinueChar(String.fromCodePoint(e.codePointAt(n)))) return m(e, !0);
1063
+ return e;
1064
+ }
1065
+ function _(e) {
1066
+ if (r.indexOf(e) >= 0) throw TypeError("Converting circular structure to JSON5");
1067
+ r.push(e);
1068
+ var t = i;
1069
+ i += s;
1070
+ for (var n = [], a = 0; a < e.length; a++) {
1071
+ var o = p(String(a), e);
1072
+ n.push(o === void 0 ? "null" : o);
1073
+ }
1074
+ var c;
1075
+ if (n.length === 0) c = "[]";
1076
+ else if (s === "") c = "[" + n.join(",") + "]";
1077
+ else {
1078
+ var l = ",\n" + i, u = n.join(l);
1079
+ c = "[\n" + i + u + ",\n" + t + "]";
1080
+ }
1081
+ return r.pop(), i = t, c;
1082
+ }
1083
+ }
1084
+ };
1085
+ }));
1086
+ })))(), 1), C = {
1087
+ ball: 1,
1088
+ red: 2,
1089
+ blue: 4,
1090
+ redKO: 8,
1091
+ blueKO: 16,
1092
+ wall: 32,
1093
+ kick: 64,
1094
+ score: 128,
1095
+ c0: 268435456,
1096
+ c1: 536870912,
1097
+ c2: 1073741824,
1098
+ c3: -2147483648,
1099
+ all: 63
1100
+ }, w = (e) => {
1101
+ if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Expected an object");
1102
+ return e;
1103
+ }, T = (e, t, n = -4096, r = 4096) => {
1104
+ let i = e === void 0 ? t : e;
1105
+ if (typeof i != "number" || !Number.isFinite(i) || i < n || i > r) throw Error(`Number must be between ${n} and ${r}`);
1106
+ return i;
1107
+ }, E = (e, t = [0, 0]) => {
1108
+ if (e === void 0) return [...t];
1109
+ if (!Array.isArray(e) || e.length !== 2) throw Error("Expected [x, y]");
1110
+ return [T(e[0], 0), T(e[1], 0)];
1111
+ }, D = (e, t) => {
1112
+ if (e === void 0) return [];
1113
+ if (!Array.isArray(e) || e.length > t) throw Error(`Array limit: ${t}`);
1114
+ return e;
1115
+ };
1116
+ function O(e, t) {
1117
+ return e === void 0 ? t : typeof e == "number" ? T(e, t, -2147483648, 4294967295) | 0 : D(e, 16).reduce((e, t) => {
1118
+ if (typeof t != "string" || !Object.hasOwn(C, t)) throw Error("Unknown collision flag");
1119
+ return e | C[t];
1120
+ }, 0);
1121
+ }
1122
+ function k(e, t = "FFFFFF") {
1123
+ if (e === void 0) return t;
1124
+ if (e === "transparent") return e;
1125
+ if (Array.isArray(e) && e.length === 3) return e.map((e) => Math.round(T(e, 0, 0, 255)).toString(16).padStart(2, "0")).join("");
1126
+ if (typeof e == "string" && /^[0-9a-f]{6}$/i.test(e)) return e;
1127
+ throw Error("Invalid color");
1128
+ }
1129
+ var A = Object.fromEntries(Object.entries({
1130
+ root: "version physicsMode name width height maxViewWidth cameraFollow spawnDistance canBeStored kickOffReset bg traits vertexes segments goals discs planes joints redSpawnPoints blueSpawnPoints playerPhysics ballPhysics",
1131
+ bg: "type width height kickOffRadius cornerRadius goalLine color",
1132
+ vertexes: "trait x y bCoef cMask cGroup",
1133
+ segments: "trait v0 v1 bCoef cMask cGroup curve curveF bias color vis",
1134
+ discs: "trait pos speed gravity radius invMass damping bCoef cGroup cMask color",
1135
+ planes: "trait normal dist bCoef cMask cGroup",
1136
+ goals: "trait p0 p1 team",
1137
+ joints: "trait d0 d1 length strength color",
1138
+ playerPhysics: "trait pos speed gravity radius invMass damping bCoef cGroup cMask color acceleration kickingAcceleration kickingDamping kickStrength kickback"
1139
+ }).map(([e, t]) => [e, new Set(t.split(" "))])), j = new Set([
1140
+ "vertexes",
1141
+ "segments",
1142
+ "discs",
1143
+ "planes",
1144
+ "goals",
1145
+ "joints",
1146
+ "playerPhysics"
1147
+ ].flatMap((e) => [...A[e]]));
1148
+ function M(e) {
1149
+ let t = [], n = (e, t) => {
1150
+ let n = t.length > 80 ? t.slice(0, 80) + "…" : t;
1151
+ return e + (/^[A-Za-z_$][\w$]*$/.test(n) ? "." + n : "[" + JSON.stringify(n) + "]");
1152
+ }, r = (e, r, i) => {
1153
+ if (e && typeof e == "object" && !Array.isArray(e)) for (let a of Object.keys(e)) r.has(a) || (t.length < 64 ? t.push("Unsupported stadium field: " + n(i, a)) : t.length === 64 && t.push("Additional unsupported stadium fields omitted."));
1154
+ };
1155
+ r(e, A.root, "$"), r(e.bg, A.bg, "$.bg");
1156
+ for (let t of [
1157
+ "vertexes",
1158
+ "segments",
1159
+ "discs",
1160
+ "planes",
1161
+ "goals",
1162
+ "joints"
1163
+ ]) {
1164
+ let n = e[t];
1165
+ Array.isArray(n) && n.forEach((e, n) => r(e, A[t], "$." + t + "[" + n + "]"));
1166
+ }
1167
+ if (r(e.ballPhysics, A.discs, "$.ballPhysics"), r(e.playerPhysics, A.playerPhysics, "$.playerPhysics"), e.traits && typeof e.traits == "object" && !Array.isArray(e.traits)) for (let [t, i] of Object.entries(e.traits)) r(i, j, n("$.traits", t));
1168
+ return t;
1169
+ }
1170
+ function N(e, t, n, r, i) {
1171
+ let a = e === "hbs" ? 1 : Math.ceil(2 * Math.SQRT2 * 100 / Math.min(10, i));
1172
+ if ((t + 32) * (n + t + 32 + r) * a > 2e6) throw Error("Stadium collision complexity exceeds the room budget");
1173
+ }
1174
+ function P(e) {
1175
+ if (new TextEncoder().encode(e).length > 262144) throw Error("Stadium exceeds 256 KB");
1176
+ let t = w(S.default.parse(e));
1177
+ if (t.physicsMode !== void 0 && t.physicsMode !== "hbs" && t.physicsMode !== "substeps") throw Error("Invalid physics mode");
1178
+ let n = t.physicsMode === "substeps" ? "substeps" : "hbs";
1179
+ if (t.version !== void 0 && t.version !== 1) throw Error("Unsupported stadium version");
1180
+ let r = t.traits === void 0 ? {} : w(t.traits), i = (e) => {
1181
+ let t = w(e);
1182
+ if (t.trait === void 0) return t;
1183
+ if (typeof t.trait != "string" || !Object.hasOwn(r, t.trait)) throw Error("Unknown trait");
1184
+ return {
1185
+ ...w(r[t.trait]),
1186
+ ...t
1187
+ };
1188
+ }, a = (e, t = !1) => ({
1189
+ pos: E(e.pos),
1190
+ speed: E(e.speed),
1191
+ gravity: E(e.gravity),
1192
+ radius: T(e.radius, 10, .5, 100),
1193
+ invMass: T(e.invMass, 1, 0, 8192),
1194
+ damping: T(e.damping, .99, 0, 8192),
1195
+ bCoef: T(e.bCoef, .5, -1, 8192),
1196
+ cGroup: O(e.cGroup, t ? 193 : 63),
1197
+ cMask: O(e.cMask, 63),
1198
+ color: k(e.color)
1199
+ }), o = D(t.discs, 63).map((e) => a(i(e)));
1200
+ if (t.ballPhysics !== "disc0") {
1201
+ let e = a(t.ballPhysics === void 0 ? {} : i(t.ballPhysics), !0);
1202
+ e.cGroup |= 192, o.unshift(e);
1203
+ } else if (!o.length) throw Error("disc0 needs a disc");
1204
+ let s = D(t.vertexes, 1024).map((e) => i(e)), c = [], l = [], u = M(t);
1205
+ for (let e of s) c.push({
1206
+ a: [T(e.x, 0), T(e.y, 0)],
1207
+ b: [T(e.x, 0), T(e.y, 0)],
1208
+ bCoef: T(e.bCoef, 1, -1, 8192),
1209
+ cGroup: O(e.cGroup, 32),
1210
+ cMask: O(e.cMask, 63),
1211
+ bias: 0,
1212
+ color: "transparent",
1213
+ vis: !1
1214
+ });
1215
+ let d = [...c];
1216
+ for (let e of D(t.segments, 1024)) {
1217
+ let t = i(e), n = T(t.v0, -1, 0, s.length - 1), r = T(t.v1, -1, 0, s.length - 1);
1218
+ if (!Number.isInteger(n) || !Number.isInteger(r)) throw Error("Vertex indices must be integers");
1219
+ let a = [T(s[n].x, 0), T(s[n].y, 0)], o = [T(s[r].x, 0), T(s[r].y, 0)], u = {
1220
+ bCoef: T(t.bCoef, 1, -1, 8192),
1221
+ cGroup: O(t.cGroup, 32),
1222
+ cMask: O(t.cMask, 63),
1223
+ bias: T(t.bias, 0, -100, 100),
1224
+ color: k(t.color, "000000"),
1225
+ vis: t.vis !== !1
1226
+ }, f = t.curveF === void 0 ? T(t.curve, 0, -359, 359) : 2 * Math.atan2(1, T(t.curveF, 0, -1e8, 1e8)) * 180 / Math.PI;
1227
+ if (Math.abs(f) < 1e-4) {
1228
+ let e = {
1229
+ a,
1230
+ b: o,
1231
+ ...u
1232
+ };
1233
+ c.push(e), (a[0] !== o[0] || a[1] !== o[1]) && d.push(e);
1234
+ continue;
1235
+ }
1236
+ let p = f * Math.PI / 180, m = o[0] - a[0], h = o[1] - a[1];
1237
+ if (Math.hypot(m, h) < .001) throw Error("Arc endpoints overlap");
1238
+ let g = 1 / (2 * Math.tan(p / 2)), _ = [(a[0] + o[0]) / 2 - h * g, (a[1] + o[1]) / 2 + m * g], v = Math.hypot(a[0] - _[0], a[1] - _[1]), y = Math.atan2(a[1] - _[1], a[0] - _[0]), b = Math.ceil(Math.abs(p) / Math.max(1e-8, 2 * Math.acos(Math.max(-1, 1 - .15 / v))));
1239
+ if (c.length + b > 4096) throw Error("Compiled geometry exceeds 4096 segments");
1240
+ let x = {
1241
+ a,
1242
+ b: o,
1243
+ ...u,
1244
+ center: _,
1245
+ radius: v,
1246
+ start: y,
1247
+ sweep: p,
1248
+ major: t.curveF === void 0 ? Math.abs(f) > 180 : Number(t.curveF) <= 0
1249
+ };
1250
+ l.push(x), d.push(x);
1251
+ let S = a;
1252
+ for (let e = 1; e <= b; e++) {
1253
+ let t = e === b ? o : [_[0] + v * Math.cos(y + p * e / b), _[1] + v * Math.sin(y + p * e / b)];
1254
+ c.push({
1255
+ a: S,
1256
+ b: t,
1257
+ ...u,
1258
+ renderOnly: !0
1259
+ }), S = t;
1260
+ }
1261
+ }
1262
+ if (c.length > 4096) throw Error("Compiled geometry exceeds 4096 segments");
1263
+ let f = t.playerPhysics === void 0 ? {} : i(t.playerPhysics), p = {
1264
+ ...a({
1265
+ ...f,
1266
+ radius: f.radius ?? 15,
1267
+ invMass: f.invMass ?? .5,
1268
+ damping: f.damping ?? .96,
1269
+ cGroup: f.cGroup ?? 0
1270
+ }),
1271
+ acceleration: T(f.acceleration, .1, -8192, 8192),
1272
+ kickingAcceleration: T(f.kickingAcceleration, .07, -8192, 8192),
1273
+ kickingDamping: T(f.kickingDamping, .96, 0, 8192),
1274
+ kickStrength: T(f.kickStrength, 5, -8192, 8192),
1275
+ kickback: T(f.kickback, 0, -8192, 8192)
1276
+ };
1277
+ N(n, o.length, c.length, D(t.planes, 64).length + D(t.joints, 128).length, Math.min(p.radius, ...o.map((e) => e.radius)));
1278
+ let m = t.bg === void 0 ? {} : w(t.bg);
1279
+ return {
1280
+ version: 1,
1281
+ physicsMode: n,
1282
+ name: typeof t.name == "string" ? t.name.slice(0, 64) : "Untitled stadium",
1283
+ canBeStored: t.canBeStored !== !1,
1284
+ width: T(t.width, 520, 100, 2048),
1285
+ height: T(t.height, 300, 80, 2048),
1286
+ maxViewWidth: T(t.maxViewWidth, 0, 0, 4096),
1287
+ cameraFollow: t.cameraFollow === "player" ? "player" : "ball",
1288
+ bg: {
1289
+ type: m.type === "grass" ? "grass" : m.type === "hockey" ? "hockey" : "none",
1290
+ cornerRadius: T(m.cornerRadius, 0, 0, 500),
1291
+ goalLine: T(m.goalLine, 0, 0, 2048),
1292
+ width: T(m.width, 0, 0, 2048),
1293
+ height: T(m.height, 0, 0, 2048),
1294
+ color: k(m.color, "718C5A"),
1295
+ kickOffRadius: T(m.kickOffRadius, 0, 0, 500)
1296
+ },
1297
+ discs: o,
1298
+ segments: c,
1299
+ arcs: l,
1300
+ colliders: d,
1301
+ player: p,
1302
+ spawnDistance: T(t.spawnDistance, 200, 0, 1500),
1303
+ kickOffReset: t.kickOffReset === "full" ? "full" : "partial",
1304
+ redSpawnPoints: D(t.redSpawnPoints, 32).map((e) => E(e)),
1305
+ blueSpawnPoints: D(t.blueSpawnPoints, 32).map((e) => E(e)),
1306
+ warnings: u,
1307
+ planes: D(t.planes, 64).map((e) => {
1308
+ let t = i(e), n = E(t.normal);
1309
+ if (Math.hypot(...n) < 1e-6) throw Error("Plane normal is zero");
1310
+ return {
1311
+ normal: n,
1312
+ dist: T(t.dist, 0),
1313
+ bCoef: T(t.bCoef, 1, -1, 8192),
1314
+ cGroup: O(t.cGroup, 32),
1315
+ cMask: O(t.cMask, 63)
1316
+ };
1317
+ }),
1318
+ goals: D(t.goals, 16).map((e) => {
1319
+ let t = i(e);
1320
+ if (t.team !== "red" && t.team !== "blue") throw Error("Invalid goal team");
1321
+ let n = E(t.p0), r = E(t.p1);
1322
+ if (Math.hypot(r[0] - n[0], r[1] - n[1]) < 1) throw Error("Goal has zero length");
1323
+ return {
1324
+ p0: n,
1325
+ p1: r,
1326
+ team: t.team === "red" ? 1 : 2
1327
+ };
1328
+ }),
1329
+ joints: D(t.joints, 128).map((e) => {
1330
+ let t = i(e), n = T(t.d0, -1, 0, o.length - 1), r = T(t.d1, -1, 0, o.length - 1);
1331
+ if (!Number.isInteger(n) || !Number.isInteger(r) || n === r) throw Error("Invalid joint indices");
1332
+ let a = Math.hypot(o[r].pos[0] - o[n].pos[0], o[r].pos[1] - o[n].pos[1]), s = t.length == null ? [a, a] : typeof t.length == "number" ? [t.length, t.length] : E(t.length);
1333
+ return {
1334
+ d0: n,
1335
+ d1: r,
1336
+ min: T(s[0], 0, 0),
1337
+ max: T(s[1], 0, 0),
1338
+ strength: t.strength === void 0 || t.strength === "rigid" ? "rigid" : T(t.strength, 0, -8192, 8192),
1339
+ color: k(t.color, "000000")
1340
+ };
1341
+ })
1342
+ };
1343
+ }
1344
+ function F(e = "Emerald Arena", t = 440, n = 220) {
1345
+ let r = [
1346
+ [-t, -n],
1347
+ [t, -n],
1348
+ [-t, n],
1349
+ [t, n],
1350
+ [-t, -70],
1351
+ [-t, 70],
1352
+ [t, -70],
1353
+ [t, 70],
1354
+ [-t - 30, -70],
1355
+ [-t - 30, 70],
1356
+ [t + 30, -70],
1357
+ [t + 30, 70],
1358
+ [0, -n - 40],
1359
+ [0, -65],
1360
+ [0, 65],
1361
+ [0, n + 40]
1362
+ ];
1363
+ return JSON.stringify({
1364
+ version: 1,
1365
+ physicsMode: "substeps",
1366
+ name: e,
1367
+ width: t + 75,
1368
+ height: n + 65,
1369
+ spawnDistance: t * .4,
1370
+ bg: {
1371
+ type: "grass",
1372
+ width: t,
1373
+ height: n,
1374
+ kickOffRadius: 65,
1375
+ color: "285B35"
1376
+ },
1377
+ vertexes: r.map(([e, t], n) => ({
1378
+ x: e,
1379
+ y: t,
1380
+ ...n >= 12 ? {
1381
+ cGroup: ["redKO", "blueKO"],
1382
+ cMask: ["red", "blue"]
1383
+ } : {}
1384
+ })),
1385
+ segments: [
1386
+ ...[
1387
+ [0, 1],
1388
+ [2, 3],
1389
+ [0, 4],
1390
+ [5, 2],
1391
+ [1, 6],
1392
+ [7, 3],
1393
+ [4, 8],
1394
+ [8, 9],
1395
+ [9, 5],
1396
+ [6, 10],
1397
+ [10, 11],
1398
+ [11, 7]
1399
+ ].map(([e, t], n) => ({
1400
+ v0: e,
1401
+ v1: t,
1402
+ cMask: ["ball"],
1403
+ color: n < 6 ? "72A99C" : "3D7267",
1404
+ bCoef: n < 6 ? .8 : .15
1405
+ })),
1406
+ {
1407
+ v0: 12,
1408
+ v1: 13,
1409
+ vis: !1,
1410
+ cGroup: ["redKO", "blueKO"],
1411
+ cMask: ["red", "blue"]
1412
+ },
1413
+ {
1414
+ v0: 14,
1415
+ v1: 15,
1416
+ vis: !1,
1417
+ cGroup: ["redKO", "blueKO"],
1418
+ cMask: ["red", "blue"]
1419
+ },
1420
+ {
1421
+ v0: 14,
1422
+ v1: 13,
1423
+ curve: -180,
1424
+ vis: !1,
1425
+ cGroup: ["redKO"],
1426
+ cMask: ["red", "blue"]
1427
+ },
1428
+ {
1429
+ v0: 14,
1430
+ v1: 13,
1431
+ curve: 180,
1432
+ vis: !1,
1433
+ cGroup: ["blueKO"],
1434
+ cMask: ["red", "blue"]
1435
+ }
1436
+ ],
1437
+ planes: [
1438
+ {
1439
+ normal: [0, 1],
1440
+ dist: -n - 40
1441
+ },
1442
+ {
1443
+ normal: [0, -1],
1444
+ dist: -n - 40
1445
+ },
1446
+ {
1447
+ normal: [1, 0],
1448
+ dist: -t - 50
1449
+ },
1450
+ {
1451
+ normal: [-1, 0],
1452
+ dist: -t - 50
1453
+ }
1454
+ ],
1455
+ goals: [{
1456
+ p0: [-t, -70],
1457
+ p1: [-t, 70],
1458
+ team: "red"
1459
+ }, {
1460
+ p0: [t, -70],
1461
+ p1: [t, 70],
1462
+ team: "blue"
1463
+ }],
1464
+ discs: [...[-t, t].flatMap((e) => [-70, 70].map((t) => ({
1465
+ pos: [e, t],
1466
+ radius: 6,
1467
+ invMass: 0,
1468
+ color: "DAEEE4",
1469
+ bCoef: .5
1470
+ })))],
1471
+ ballPhysics: {
1472
+ radius: 9,
1473
+ damping: .991,
1474
+ bCoef: .6
1475
+ },
1476
+ playerPhysics: {
1477
+ radius: 15,
1478
+ acceleration: .11,
1479
+ damping: .96,
1480
+ kickStrength: 5.5
1481
+ }
1482
+ }, null, 2);
1483
+ }
1484
+ var ee = `ball2d-core/1/${x}`, I = class e {
1485
+ core;
1486
+ stadium;
1487
+ source = "";
1488
+ colors = [];
1489
+ tick = 0;
1490
+ elapsed = 0;
1491
+ ballKicks = [];
1492
+ red = 0;
1493
+ blue = 0;
1494
+ phase = "lobby";
1495
+ paused = !1;
1496
+ resumeTicks = 0;
1497
+ countdown = 0;
1498
+ kickoff = 1;
1499
+ kickoffActive = !0;
1500
+ scoreLimit = 5;
1501
+ timeLimit = 300;
1502
+ lastGoal = 0;
1503
+ kickRate = 2;
1504
+ setKickRateLimit(e, t, n) {
1505
+ this.kickRate = L(e, t, n), this.core.kick_limits(this.kickRate & 255, this.kickRate >>> 8 & 255, this.kickRate >>> 16);
1506
+ }
1507
+ constructor(e) {
1508
+ this.core = e.exports;
1509
+ }
1510
+ static async create(t, n) {
1511
+ let r = t ?? await (await fetch("/core.wasm?v=3de72bdcf92ccb0d235a", { signal: n })).arrayBuffer();
1512
+ if (Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", r))).map((e) => e.toString(16).padStart(2, "0")).join("") !== "18e0600cd78f6896249e672d14fefbc34e88826b1febf0b794dc5367f176e338") throw Error("Physics build changed. Refresh the page to load a matching version.");
1513
+ return new e(await WebAssembly.instantiate(await WebAssembly.compile(r)));
1514
+ }
1515
+ get data() {
1516
+ return new Float64Array(this.core.memory.buffer, this.core.data_ptr(), this.core.count() * 18);
1517
+ }
1518
+ load(e) {
1519
+ this.stadium = P(e), this.source = e, this.core.reset(), this.colors = [], this.core.physics_mode(+(this.stadium.physicsMode === "substeps")), this.tick = 0, this.elapsed = 0, this.red = this.blue = 0, this.phase = "lobby", this.paused = !1, this.resumeTicks = 0, this.countdown = 0, this.kickoffActive = !0;
1520
+ for (let e of this.stadium.discs) this.add(e);
1521
+ for (let e = 0; e < 32; e++) this.add(this.stadium.player, e + 1);
1522
+ for (let e of this.stadium.colliders) if ("center" in e) {
1523
+ let t = e;
1524
+ this.core.arc(...t.center, t.radius, ...t.a, ...t.b, t.sweep, +t.major, t.bCoef, t.cGroup, t.cMask, t.bias);
1525
+ } else {
1526
+ let t = e;
1527
+ this.core.wall(...t.a, ...t.b, t.bCoef, t.cGroup, t.cMask, t.bias);
1528
+ }
1529
+ for (let e of this.stadium.planes) this.core.plane(...e.normal, e.dist, e.bCoef, e.cGroup, e.cMask);
1530
+ for (let e of this.stadium.joints) this.core.joint(e.d0, e.d1, e.min, e.max, e.strength === "rigid" ? Infinity : e.strength);
1531
+ for (let e of this.stadium.goals) this.core.goal(...e.p0, ...e.p1, e.team);
1532
+ let t = this.stadium.player;
1533
+ this.core.configure(t.acceleration, t.kickStrength, t.kickingAcceleration, t.kickingDamping, t.kickback, this.kickRate & 255), this.setKickRateLimit(this.kickRate & 255, this.kickRate >>> 8 & 255, this.kickRate >>> 16);
1534
+ }
1535
+ add(e, t = 0) {
1536
+ let n = this.core.add_disc();
1537
+ if (n < 0) throw Error("Disc capacity exceeded");
1538
+ this.colors.push(e.color === "transparent" ? -1 : parseInt(e.color, 16)), [
1539
+ ...e.pos,
1540
+ ...e.speed,
1541
+ e.radius,
1542
+ e.invMass,
1543
+ e.damping,
1544
+ e.bCoef,
1545
+ ...e.gravity,
1546
+ e.cGroup,
1547
+ e.cMask,
1548
+ t,
1549
+ 0,
1550
+ 0,
1551
+ 0,
1552
+ e.pos[0],
1553
+ t ? 0 : e.pos[1]
1554
+ ].forEach((e, t) => this.core.set_disc(n, t, e));
1555
+ }
1556
+ index(e) {
1557
+ if (!Number.isInteger(e) || e < 0 || e >= 32) throw Error("Invalid slot");
1558
+ return this.stadium.discs.length + e;
1559
+ }
1560
+ joinPlayer(e) {
1561
+ let t = this.index(e) * 18;
1562
+ this.data[t + 15] = 0, this.data[t + 17] = 0, this.setTeam(e, 0);
1563
+ }
1564
+ setTeam(e, t) {
1565
+ if (![
1566
+ 0,
1567
+ 1,
1568
+ 2
1569
+ ].includes(t)) throw Error("Invalid team");
1570
+ let n = this.index(e), r = this.data;
1571
+ r[n * 18 + 13] = t, r[n * 18 + 10] = this.stadium.player.cGroup | (t === 1 ? 2 : t === 2 ? 4 : 0), r[n * 18 + 14] = 0, this.spawn(n, e, t, this.phase !== "lobby");
1572
+ }
1573
+ input(e, t) {
1574
+ let n = this.data, r = this.index(e) * 18, i = t & 31;
1575
+ i & 16 ? n[r + 14] & 16 || (n[r + 15] = n[r + 15] | 1024) : n[r + 15] = n[r + 15] & 1023, n[r + 14] = i;
1576
+ }
1577
+ applyDiscProperties(e, t) {
1578
+ let n = this.data;
1579
+ if (this.phase === "lobby" || !Number.isInteger(e) || e < 0 || e >= this.colors.length || n[e * 18 + 12] > 0 && n[e * 18 + 13] === 0) return !1;
1580
+ let r = b(t), i = !1;
1581
+ for (let [t, a] of y) {
1582
+ let o = r[t];
1583
+ if (o === void 0) continue;
1584
+ let s = a === -1 ? this.colors[e] : n[e * 18 + a];
1585
+ Object.is(s, o) || (i = !0);
1586
+ }
1587
+ if (!i) return !1;
1588
+ if (r.radius !== void 0) {
1589
+ let t = r.radius;
1590
+ for (let r = 0; r < this.colors.length; r++) r !== e && (t = Math.min(t, n[r * 18 + 4]));
1591
+ N(this.stadium.physicsMode, this.stadium.discs.length, this.stadium.segments.length, this.stadium.planes.length + this.stadium.joints.length, t);
1592
+ }
1593
+ for (let [t, i] of y) {
1594
+ let a = r[t];
1595
+ a !== void 0 && (i === -1 ? this.colors[e] = a : n[e * 18 + i] = a);
1596
+ }
1597
+ return !0;
1598
+ }
1599
+ restoreDiscProperties(e, t) {
1600
+ let n = e * 18, r = this.data;
1601
+ this.colors[e] = t.color === "transparent" ? -1 : parseInt(t.color, 16), r[n + 4] = t.radius, r[n + 5] = t.invMass, r[n + 6] = t.damping, r[n + 7] = t.bCoef, r[n + 8] = t.gravity[0], r[n + 9] = t.gravity[1], r[n + 10] = t.cGroup, r[n + 11] = t.cMask;
1602
+ }
1603
+ spawn(e, t, n, r = !1) {
1604
+ this.restoreDiscProperties(e, this.stadium.player), this.colors[e] = n === 1 ? 16087152 : n === 2 ? 7516147 : 16777215, this.data[e * 18 + 10] |= n === 1 ? 2 : n === 2 ? 4 : 0;
1605
+ let i = n === 1 ? this.stadium.redSpawnPoints : this.stadium.blueSpawnPoints, a = this.data, o = 0;
1606
+ for (let e = 0; e < t; e++) a[this.index(e) * 18 + 13] === n && o++;
1607
+ let s = n === 1 ? -1 : 1, c = i.length ? i[r ? i.length - 1 : Math.min(o, i.length - 1)] : r ? [s * this.stadium.width, 0] : [s * this.stadium.spawnDistance, o ? Math.ceil(o / 2) * 55 * (o % 2 ? 1 : -1) : 0];
1608
+ a[e * 18] = c[0], a[e * 18 + 1] = c[1], a[e * 18 + 2] = a[e * 18 + 3] = a[e * 18 + 14] = 0, a[e * 18 + 15] &= 1023, a[e * 18 + 11] = this.stadium.player.cMask & -25;
1609
+ }
1610
+ resetPositions(e = !1) {
1611
+ this.kickoffActive = !0;
1612
+ let t = this.data;
1613
+ for (let n = 0; n < this.stadium.discs.length; n++) {
1614
+ let r = this.stadium.discs[n];
1615
+ (e || n === 0 || this.stadium.kickOffReset === "full") && (this.restoreDiscProperties(n, r), t[n * 18] = r.pos[0], t[n * 18 + 1] = r.pos[1], t[n * 18 + 2] = r.speed[0], t[n * 18 + 3] = r.speed[1]);
1616
+ }
1617
+ for (let e = 0; e < 32; e++) {
1618
+ let n = this.index(e);
1619
+ this.spawn(n, e, t[n * 18 + 13]);
1620
+ }
1621
+ }
1622
+ start() {
1623
+ (this.phase === "lobby" || this.phase === "finished") && (this.red = this.blue = this.elapsed = 0, this.phase = "playing", this.paused = !1, this.resumeTicks = 0, this.kickoff = 1, this.countdown = 0, this.resetPositions(!0));
1624
+ }
1625
+ stop() {
1626
+ this.phase = "lobby", this.paused = !1, this.resumeTicks = 0;
1627
+ }
1628
+ setPaused(e) {
1629
+ this.phase !== "lobby" && (e = !!e, this.paused !== e && (this.paused = e, this.resumeTicks = e ? 0 : 119));
1630
+ }
1631
+ finish() {
1632
+ this.phase = "finished", this.countdown = 300;
1633
+ }
1634
+ step() {
1635
+ if (this.ballKicks.length = 0, this.tick++, this.paused || this.phase === "lobby") return;
1636
+ if (this.resumeTicks > 0) {
1637
+ this.resumeTicks--;
1638
+ return;
1639
+ }
1640
+ let e = this.data;
1641
+ this.core.step();
1642
+ for (let e = this.core.ball_kick_events() >>> 0, t = 0; e; e >>>= 1, t++) e & 1 && this.ballKicks.push(t);
1643
+ if (this.phase === "finished") {
1644
+ --this.countdown <= 0 && this.stop();
1645
+ return;
1646
+ }
1647
+ if (this.phase === "goal") {
1648
+ --this.countdown <= 0 && (this.scoreLimit > 0 && Math.max(this.red, this.blue) >= this.scoreLimit || this.timeLimit > 0 && this.elapsed >= this.timeLimit * 60 && this.red !== this.blue ? this.finish() : (this.phase = "playing", this.resetPositions()));
1649
+ return;
1650
+ }
1651
+ for (let t = 0; t < 32; t++) {
1652
+ let n = this.index(t) * 18, r = this.stadium.player.cMask;
1653
+ e[n + 11] = r & -25 | (this.kickoffActive ? r & (this.kickoff === 1 ? 8 : 16) : 0);
1654
+ }
1655
+ if (this.kickoffActive) {
1656
+ e[2] * e[2] + e[3] * e[3] > 0 && (this.kickoffActive = !1);
1657
+ return;
1658
+ }
1659
+ this.elapsed++;
1660
+ let t = this.core.goal_event();
1661
+ if (t === 1 || t === 2) {
1662
+ t === 1 ? this.red++ : this.blue++, this.kickoff = t === 1 ? 2 : 1, this.phase = "goal", this.countdown = 150, this.lastGoal = this.tick;
1663
+ return;
1664
+ }
1665
+ this.timeLimit > 0 && this.elapsed >= this.timeLimit * 60 && this.red !== this.blue && this.finish();
1666
+ }
1667
+ snapshot() {
1668
+ return {
1669
+ tick: this.tick,
1670
+ elapsed: this.elapsed,
1671
+ red: this.red,
1672
+ blue: this.blue,
1673
+ phase: this.phase,
1674
+ paused: this.paused,
1675
+ resumeTicks: this.resumeTicks,
1676
+ countdown: this.countdown,
1677
+ kickoff: this.kickoff,
1678
+ kickoffActive: this.kickoffActive,
1679
+ scoreLimit: this.scoreLimit,
1680
+ timeLimit: this.timeLimit,
1681
+ kickRate: this.kickRate,
1682
+ discs: Array.from(this.data),
1683
+ colors: [...this.colors]
1684
+ };
1685
+ }
1686
+ restore(e) {
1687
+ if (!e || typeof e != "object" || !Array.isArray(e.discs) || e.discs.length !== this.data.length || !e.discs.every((e, t) => typeof e == "number" && Number.isFinite(e) && Math.abs(e) <= (t % 18 == 10 || t % 18 == 11 ? 2147483648 : t % 18 == 17 ? 25500 : 8192))) throw Error("Invalid state");
1688
+ if (!Array.isArray(e.colors) || e.colors.length !== e.discs.length / 18 || e.colors.some((e) => !Number.isInteger(e) || e < -1 || e > 16777215)) throw Error("Invalid disc colors");
1689
+ let t = (e, t, n = 0) => Number.isInteger(e) && e >= n && e <= t;
1690
+ if (!t(e.kickRate, 6619135) || !t(e.tick, 4294967295) || !t(e.elapsed, 4294967295) || !t(e.red, 65535) || !t(e.blue, 65535) || !t(e.countdown, 300) || !t(e.resumeTicks, 119) || (e.paused || e.phase === "lobby") && e.resumeTicks !== 0 || !t(e.scoreLimit, 99) || !t(e.timeLimit, 5940) || ![
1691
+ "lobby",
1692
+ "playing",
1693
+ "goal",
1694
+ "finished"
1695
+ ].includes(e.phase) || typeof e.paused != "boolean" || typeof e.kickoffActive != "boolean" || ![1, 2].includes(e.kickoff)) throw Error("Invalid match metadata");
1696
+ for (let n = 0; n < e.discs.length; n += 18) if (e.discs[n + 4] < .5 || e.discs[n + 4] > 100 || e.discs[n + 5] < 0 || e.discs[n + 5] > 8192 || e.discs[n + 6] < 0 || e.discs[n + 6] > 8192 || e.discs[n + 7] < -1 || e.discs[n + 7] > 8192 || !t(e.discs[n + 10], 2147483647, -2147483648) || !t(e.discs[n + 11], 2147483647, -2147483648) || !t(e.discs[n + 13], 2) || !t(e.discs[n + 14], 31) || !t(e.discs[n + 15], 2047) || e.discs[n + 12] > 0 && (!Number.isInteger(e.discs[n + 17]) || e.discs[n + 17] < -255 || e.discs[n + 17] > 25500)) throw Error("Invalid disc properties");
1697
+ let n = 10;
1698
+ for (let t = 4; t < e.discs.length; t += 18) n = Math.min(n, e.discs[t]);
1699
+ N(this.stadium.physicsMode, this.stadium.discs.length, this.stadium.segments.length, this.stadium.planes.length + this.stadium.joints.length, n), this.setKickRateLimit(e.kickRate & 255, e.kickRate >>> 8 & 255, e.kickRate >>> 16), this.tick = e.tick, this.elapsed = e.elapsed, this.red = e.red, this.blue = e.blue, this.phase = e.phase, this.paused = e.paused, this.resumeTicks = e.resumeTicks, this.countdown = e.countdown, this.kickoff = e.kickoff, this.kickoffActive = e.kickoffActive, this.scoreLimit = e.scoreLimit, this.timeLimit = e.timeLimit, this.data.set(e.discs), this.colors = [...e.colors];
1700
+ }
1701
+ };
1702
+ function L(e, t, n) {
1703
+ if (![
1704
+ e,
1705
+ t,
1706
+ n
1707
+ ].every(Number.isInteger)) throw Error("Invalid kick rate limit");
1708
+ return Math.max(0, Math.min(255, e)) | Math.max(0, Math.min(255, t)) << 8 | Math.max(0, Math.min(100, n)) << 16;
1709
+ }
1710
+ //#endregion
1711
+ //#region src/client/network-runtime.ts
1712
+ function R(e) {
1713
+ let t = new URL(e);
1714
+ if (!["http:", "https:"].includes(t.protocol) || t.username || t.password || t.pathname !== "/" || t.search || t.hash) throw Error("Expected an HTTP(S) service origin without credentials or a path");
1715
+ return t.origin;
1716
+ }
1717
+ function z() {
1718
+ return {
1719
+ serviceOrigin: location.origin,
1720
+ createWebSocket: (e) => new WebSocket(e),
1721
+ createPeerConnection: (e) => new RTCPeerConnection(e)
1722
+ };
1723
+ }
1724
+ //#endregion
1725
+ //#region src/client/stadium-library.ts
1726
+ var B = [
1727
+ ["classic", "Classic"],
1728
+ ["easy", "Easy"],
1729
+ ["small", "Small"],
1730
+ ["big", "Big"],
1731
+ ["rounded", "Rounded"],
1732
+ ["hockey", "Hockey"],
1733
+ ["big_easy", "Big Easy"],
1734
+ ["big_rounded", "Big Rounded"],
1735
+ ["big_hockey", "Big Hockey"],
1736
+ ["huge", "Huge"]
1737
+ ];
1738
+ function V(e) {
1739
+ let t = /* @__PURE__ */ new Map();
1740
+ return async (n) => {
1741
+ let r = B.find(([e, t]) => e === n || t === n);
1742
+ if (!r) throw Error("Unknown default stadium");
1743
+ let i = t.get(r[0]);
1744
+ return i || (i = (async () => {
1745
+ let t = await e(`/stadiums/${r[0]}.hbs`);
1746
+ if (!t.ok) throw Error("Could not load stadium");
1747
+ let n = await t.text();
1748
+ return P(n), n;
1749
+ })(), t.set(r[0], i), i.catch(() => t.delete(r[0]))), i;
1750
+ };
1751
+ }
1752
+ //#endregion
1753
+ //#region src/client/host-runtime.ts
1754
+ function te() {
1755
+ let e = z(), t = (e, t) => fetch(e, t);
1756
+ return {
1757
+ network: e,
1758
+ request: t,
1759
+ loadEngine: (e) => I.create(void 0, e),
1760
+ loadStadium: V((n) => t(new URL(n, e.serviceOrigin)))
1761
+ };
1762
+ }
1763
+ //#endregion
1764
+ //#region src/client/traffic.ts
1765
+ var H = {
1766
+ message: {
1767
+ burst: 240,
1768
+ perSecond: 160
1769
+ },
1770
+ action: {
1771
+ burst: 12,
1772
+ perSecond: 6
1773
+ },
1774
+ chat: {
1775
+ burst: 4,
1776
+ perSecond: 1
1777
+ }
1778
+ }, U = class {
1779
+ peers = /* @__PURE__ */ new Map();
1780
+ allow(e, t, n = performance.now()) {
1781
+ let r = this.peers.get(e);
1782
+ r || (r = {}, this.peers.set(e, r));
1783
+ let { burst: i, perSecond: a } = H[t], o = r[t] ?? {
1784
+ tokens: i,
1785
+ at: n
1786
+ };
1787
+ return o.tokens = Math.min(i, o.tokens + Math.max(0, n - o.at) * a / 1e3), o.at = Math.max(o.at, n), r[t] = o, o.tokens < 1 ? !1 : (o.tokens--, !0);
1788
+ }
1789
+ delete(e) {
1790
+ this.peers.delete(e);
1791
+ }
1792
+ clear() {
1793
+ this.peers.clear();
1794
+ }
1795
+ }, W = Uint8Array, G = Uint16Array, ne = Int32Array, re = new W([
1796
+ 0,
1797
+ 0,
1798
+ 0,
1799
+ 0,
1800
+ 0,
1801
+ 0,
1802
+ 0,
1803
+ 0,
1804
+ 1,
1805
+ 1,
1806
+ 1,
1807
+ 1,
1808
+ 2,
1809
+ 2,
1810
+ 2,
1811
+ 2,
1812
+ 3,
1813
+ 3,
1814
+ 3,
1815
+ 3,
1816
+ 4,
1817
+ 4,
1818
+ 4,
1819
+ 4,
1820
+ 5,
1821
+ 5,
1822
+ 5,
1823
+ 5,
1824
+ 0,
1825
+ 0,
1826
+ 0,
1827
+ 0
1828
+ ]), ie = new W([
1829
+ 0,
1830
+ 0,
1831
+ 0,
1832
+ 0,
1833
+ 1,
1834
+ 1,
1835
+ 2,
1836
+ 2,
1837
+ 3,
1838
+ 3,
1839
+ 4,
1840
+ 4,
1841
+ 5,
1842
+ 5,
1843
+ 6,
1844
+ 6,
1845
+ 7,
1846
+ 7,
1847
+ 8,
1848
+ 8,
1849
+ 9,
1850
+ 9,
1851
+ 10,
1852
+ 10,
1853
+ 11,
1854
+ 11,
1855
+ 12,
1856
+ 12,
1857
+ 13,
1858
+ 13,
1859
+ 0,
1860
+ 0
1861
+ ]), K = new W([
1862
+ 16,
1863
+ 17,
1864
+ 18,
1865
+ 0,
1866
+ 8,
1867
+ 7,
1868
+ 9,
1869
+ 6,
1870
+ 10,
1871
+ 5,
1872
+ 11,
1873
+ 4,
1874
+ 12,
1875
+ 3,
1876
+ 13,
1877
+ 2,
1878
+ 14,
1879
+ 1,
1880
+ 15
1881
+ ]), q = function(e, t) {
1882
+ for (var n = new G(31), r = 0; r < 31; ++r) n[r] = t += 1 << e[r - 1];
1883
+ for (var i = new ne(n[30]), r = 1; r < 30; ++r) for (var a = n[r]; a < n[r + 1]; ++a) i[a] = a - n[r] << 5 | r;
1884
+ return {
1885
+ b: n,
1886
+ r: i
1887
+ };
1888
+ }, ae = q(re, 2), oe = ae.b, J = ae.r;
1889
+ oe[28] = 258, J[258] = 28;
1890
+ for (var se = q(ie, 0), ce = se.b, Y = se.r, le = new G(32768), X = 0; X < 32768; ++X) {
1891
+ var Z = (X & 43690) >> 1 | (X & 21845) << 1;
1892
+ Z = (Z & 52428) >> 2 | (Z & 13107) << 2, Z = (Z & 61680) >> 4 | (Z & 3855) << 4, le[X] = ((Z & 65280) >> 8 | (Z & 255) << 8) >> 1;
1893
+ }
1894
+ for (var ue = (function(e, t, n) {
1895
+ for (var r = e.length, i = 0, a = new G(t); i < r; ++i) e[i] && ++a[e[i] - 1];
1896
+ var o = new G(t);
1897
+ for (i = 1; i < t; ++i) o[i] = o[i - 1] + a[i - 1] << 1;
1898
+ var s;
1899
+ if (n) {
1900
+ s = new G(1 << t);
1901
+ var c = 15 - t;
1902
+ for (i = 0; i < r; ++i) if (e[i]) for (var l = i << 4 | e[i], u = t - e[i], d = o[e[i] - 1]++ << u, f = d | (1 << u) - 1; d <= f; ++d) s[le[d] >> c] = l;
1903
+ } else for (s = new G(r), i = 0; i < r; ++i) e[i] && (s[i] = le[o[e[i] - 1]++] >> 15 - e[i]);
1904
+ return s;
1905
+ }), de = new W(288), X = 0; X < 144; ++X) de[X] = 8;
1906
+ for (var X = 144; X < 256; ++X) de[X] = 9;
1907
+ for (var X = 256; X < 280; ++X) de[X] = 7;
1908
+ for (var X = 280; X < 288; ++X) de[X] = 8;
1909
+ for (var fe = new W(32), X = 0; X < 32; ++X) fe[X] = 5;
1910
+ var pe = /*#__PURE__*/ ue(de, 9, 0), me = /*#__PURE__*/ ue(de, 9, 1), he = /*#__PURE__*/ ue(fe, 5, 0), Q = /*#__PURE__*/ ue(fe, 5, 1), ge = function(e) {
1911
+ for (var t = e[0], n = 1; n < e.length; ++n) e[n] > t && (t = e[n]);
1912
+ return t;
1913
+ }, $ = function(e, t, n) {
1914
+ var r = t / 8 | 0;
1915
+ return (e[r] | e[r + 1] << 8) >> (t & 7) & n;
1916
+ }, _e = function(e, t) {
1917
+ var n = t / 8 | 0;
1918
+ return (e[n] | e[n + 1] << 8 | e[n + 2] << 16) >> (t & 7);
1919
+ }, ve = function(e) {
1920
+ return (e + 7) / 8 | 0;
1921
+ }, ye = function(e, t, n) {
1922
+ return (t == null || t < 0) && (t = 0), (n == null || n > e.length) && (n = e.length), new W(e.subarray(t, n));
1923
+ }, be = [
1924
+ "unexpected EOF",
1925
+ "invalid block type",
1926
+ "invalid length/literal",
1927
+ "invalid distance",
1928
+ "stream finished",
1929
+ "no stream handler",
1930
+ ,
1931
+ "no callback",
1932
+ "invalid UTF-8 data",
1933
+ "extra field too long",
1934
+ "date not in range 1980-2099",
1935
+ "filename too long",
1936
+ "stream finishing",
1937
+ "invalid zip data"
1938
+ ], xe = function(e, t, n) {
1939
+ var r = Error(t || be[e]);
1940
+ if (r.code = e, Error.captureStackTrace && Error.captureStackTrace(r, xe), !n) throw r;
1941
+ return r;
1942
+ }, Se = function(e, t, n, r) {
1943
+ var i = e.length, a = r ? r.length : 0;
1944
+ if (!i || t.f && !t.l) return n || new W(0);
1945
+ var o = !n, s = o || t.i != 2, c = t.i;
1946
+ o && (n = new W(i * 3));
1947
+ var l = function(e) {
1948
+ var t = n.length;
1949
+ if (e > t) {
1950
+ var r = new W(Math.max(t * 2, e));
1951
+ r.set(n), n = r;
1952
+ }
1953
+ }, u = t.f || 0, d = t.p || 0, f = t.b || 0, p = t.l, m = t.d, h = t.m, g = t.n, _ = i * 8;
1954
+ do {
1955
+ if (!p) {
1956
+ u = $(e, d, 1);
1957
+ var v = $(e, d + 1, 3);
1958
+ if (d += 3, !v) {
1959
+ var y = ve(d) + 4, b = e[y - 4] | e[y - 3] << 8, x = y + b;
1960
+ if (x > i) {
1961
+ c && xe(0);
1962
+ break;
1963
+ }
1964
+ s && l(f + b), n.set(e.subarray(y, x), f), t.b = f += b, t.p = d = x * 8, t.f = u;
1965
+ continue;
1966
+ }
1967
+ if (v == 1) p = me, m = Q, h = 9, g = 5;
1968
+ else if (v == 2) {
1969
+ var S = $(e, d, 31) + 257, C = $(e, d + 10, 15) + 4, w = S + $(e, d + 5, 31) + 1;
1970
+ d += 14;
1971
+ for (var T = new W(w), E = new W(19), D = 0; D < C; ++D) E[K[D]] = $(e, d + D * 3, 7);
1972
+ d += C * 3;
1973
+ for (var O = ge(E), k = (1 << O) - 1, A = ue(E, O, 1), D = 0; D < w;) {
1974
+ var j = A[$(e, d, k)];
1975
+ d += j & 15;
1976
+ var y = j >> 4;
1977
+ if (y < 16) T[D++] = y;
1978
+ else {
1979
+ var M = 0, N = 0;
1980
+ for (y == 16 ? (N = 3 + $(e, d, 3), d += 2, M = T[D - 1]) : y == 17 ? (N = 3 + $(e, d, 7), d += 3) : y == 18 && (N = 11 + $(e, d, 127), d += 7); N--;) T[D++] = M;
1981
+ }
1982
+ }
1983
+ var P = T.subarray(0, S), F = T.subarray(S);
1984
+ h = ge(P), g = ge(F), p = ue(P, h, 1), m = ue(F, g, 1);
1985
+ } else xe(1);
1986
+ if (d > _) {
1987
+ c && xe(0);
1988
+ break;
1989
+ }
1990
+ }
1991
+ s && l(f + 131072);
1992
+ for (var ee = (1 << h) - 1, I = (1 << g) - 1, L = d;; L = d) {
1993
+ var M = p[_e(e, d) & ee], R = M >> 4;
1994
+ if (d += M & 15, d > _) {
1995
+ c && xe(0);
1996
+ break;
1997
+ }
1998
+ if (M || xe(2), R < 256) n[f++] = R;
1999
+ else if (R == 256) {
2000
+ L = d, p = null;
2001
+ break;
2002
+ } else {
2003
+ var z = R - 254;
2004
+ if (R > 264) {
2005
+ var D = R - 257, B = re[D];
2006
+ z = $(e, d, (1 << B) - 1) + oe[D], d += B;
2007
+ }
2008
+ var V = m[_e(e, d) & I], te = V >> 4;
2009
+ V || xe(3), d += V & 15;
2010
+ var F = ce[te];
2011
+ if (te > 3) {
2012
+ var B = ie[te];
2013
+ F += _e(e, d) & (1 << B) - 1, d += B;
2014
+ }
2015
+ if (d > _) {
2016
+ c && xe(0);
2017
+ break;
2018
+ }
2019
+ s && l(f + 131072);
2020
+ var H = f + z;
2021
+ if (f < F) {
2022
+ var U = a - F, G = Math.min(F, H);
2023
+ for (U + f < 0 && xe(3); f < G; ++f) n[f] = r[U + f];
2024
+ }
2025
+ for (; f < H; ++f) n[f] = n[f - F];
2026
+ }
2027
+ }
2028
+ t.l = p, t.p = L, t.b = f, t.f = u, p && (u = 1, t.m = h, t.d = m, t.n = g);
2029
+ } while (!u);
2030
+ return f != n.length && o ? ye(n, 0, f) : n.subarray(0, f);
2031
+ }, Ce = function(e, t, n) {
2032
+ n <<= t & 7;
2033
+ var r = t / 8 | 0;
2034
+ e[r] |= n, e[r + 1] |= n >> 8;
2035
+ }, we = function(e, t, n) {
2036
+ n <<= t & 7;
2037
+ var r = t / 8 | 0;
2038
+ e[r] |= n, e[r + 1] |= n >> 8, e[r + 2] |= n >> 16;
2039
+ }, Te = function(e, t) {
2040
+ for (var n = [], r = 0; r < e.length; ++r) e[r] && n.push({
2041
+ s: r,
2042
+ f: e[r]
2043
+ });
2044
+ var i = n.length, a = n.slice();
2045
+ if (!i) return {
2046
+ t: Me,
2047
+ l: 0
2048
+ };
2049
+ if (i == 1) {
2050
+ var o = new W(n[0].s + 1);
2051
+ return o[n[0].s] = 1, {
2052
+ t: o,
2053
+ l: 1
2054
+ };
2055
+ }
2056
+ n.sort(function(e, t) {
2057
+ return e.f - t.f;
2058
+ }), n.push({
2059
+ s: -1,
2060
+ f: 25001
2061
+ });
2062
+ var s = n[0], c = n[1], l = 0, u = 1, d = 2;
2063
+ for (n[0] = {
2064
+ s: -1,
2065
+ f: s.f + c.f,
2066
+ l: s,
2067
+ r: c
2068
+ }; u != i - 1;) s = n[n[l].f < n[d].f ? l++ : d++], c = n[l != u && n[l].f < n[d].f ? l++ : d++], n[u++] = {
2069
+ s: -1,
2070
+ f: s.f + c.f,
2071
+ l: s,
2072
+ r: c
2073
+ };
2074
+ for (var f = a[0].s, r = 1; r < i; ++r) a[r].s > f && (f = a[r].s);
2075
+ var p = new G(f + 1), m = Ee(n[u - 1], p, 0);
2076
+ if (m > t) {
2077
+ var r = 0, h = 0, g = m - t, _ = 1 << g;
2078
+ for (a.sort(function(e, t) {
2079
+ return p[t.s] - p[e.s] || e.f - t.f;
2080
+ }); r < i; ++r) {
2081
+ var v = a[r].s;
2082
+ if (p[v] > t) h += _ - (1 << m - p[v]), p[v] = t;
2083
+ else break;
2084
+ }
2085
+ for (h >>= g; h > 0;) {
2086
+ var y = a[r].s;
2087
+ p[y] < t ? h -= 1 << t - p[y]++ - 1 : ++r;
2088
+ }
2089
+ for (; r >= 0 && h; --r) {
2090
+ var b = a[r].s;
2091
+ p[b] == t && (--p[b], ++h);
2092
+ }
2093
+ m = t;
2094
+ }
2095
+ return {
2096
+ t: new W(p),
2097
+ l: m
2098
+ };
2099
+ }, Ee = function(e, t, n) {
2100
+ return e.s == -1 ? Math.max(Ee(e.l, t, n + 1), Ee(e.r, t, n + 1)) : t[e.s] = n;
2101
+ }, De = function(e) {
2102
+ for (var t = e.length; t && !e[--t];);
2103
+ for (var n = new G(++t), r = 0, i = e[0], a = 1, o = function(e) {
2104
+ n[r++] = e;
2105
+ }, s = 1; s <= t; ++s) if (e[s] == i && s != t) ++a;
2106
+ else {
2107
+ if (!i && a > 2) {
2108
+ for (; a > 138; a -= 138) o(32754);
2109
+ a > 2 && (o(a > 10 ? a - 11 << 5 | 28690 : a - 3 << 5 | 12305), a = 0);
2110
+ } else if (a > 3) {
2111
+ for (o(i), --a; a > 6; a -= 6) o(8304);
2112
+ a > 2 && (o(a - 3 << 5 | 8208), a = 0);
2113
+ }
2114
+ for (; a--;) o(i);
2115
+ a = 1, i = e[s];
2116
+ }
2117
+ return {
2118
+ c: n.subarray(0, r),
2119
+ n: t
2120
+ };
2121
+ }, Oe = function(e, t) {
2122
+ for (var n = 0, r = 0; r < t.length; ++r) n += e[r] * t[r];
2123
+ return n;
2124
+ }, ke = function(e, t, n) {
2125
+ var r = n.length, i = ve(t + 2);
2126
+ e[i] = r & 255, e[i + 1] = r >> 8, e[i + 2] = e[i] ^ 255, e[i + 3] = e[i + 1] ^ 255;
2127
+ for (var a = 0; a < r; ++a) e[i + a + 4] = n[a];
2128
+ return (i + 4 + r) * 8;
2129
+ }, Ae = function(e, t, n, r, i, a, o, s, c, l, u) {
2130
+ Ce(t, u++, n), ++i[256];
2131
+ for (var d = Te(i, 15), f = d.t, p = d.l, m = Te(a, 15), h = m.t, g = m.l, _ = De(f), v = _.c, y = _.n, b = De(h), x = b.c, S = b.n, C = new G(19), w = 0; w < v.length; ++w) ++C[v[w] & 31];
2132
+ for (var w = 0; w < x.length; ++w) ++C[x[w] & 31];
2133
+ for (var T = Te(C, 7), E = T.t, D = T.l, O = 19; O > 4 && !E[K[O - 1]]; --O);
2134
+ var k = l + 5 << 3, A = Oe(i, de) + Oe(a, fe) + o, j = Oe(i, f) + Oe(a, h) + o + 14 + 3 * O + Oe(C, E) + 2 * C[16] + 3 * C[17] + 7 * C[18];
2135
+ if (c >= 0 && k <= A && k <= j) return ke(t, u, e.subarray(c, c + l));
2136
+ var M, N, P, F;
2137
+ if (Ce(t, u, 1 + (j < A)), u += 2, j < A) {
2138
+ M = ue(f, p, 0), N = f, P = ue(h, g, 0), F = h;
2139
+ var ee = ue(E, D, 0);
2140
+ Ce(t, u, y - 257), Ce(t, u + 5, S - 1), Ce(t, u + 10, O - 4), u += 14;
2141
+ for (var w = 0; w < O; ++w) Ce(t, u + 3 * w, E[K[w]]);
2142
+ u += 3 * O;
2143
+ for (var I = [v, x], L = 0; L < 2; ++L) for (var R = I[L], w = 0; w < R.length; ++w) {
2144
+ var z = R[w] & 31;
2145
+ Ce(t, u, ee[z]), u += E[z], z > 15 && (Ce(t, u, R[w] >> 5 & 127), u += R[w] >> 12);
2146
+ }
2147
+ } else M = pe, N = de, P = he, F = fe;
2148
+ for (var w = 0; w < s; ++w) {
2149
+ var B = r[w];
2150
+ if (B > 255) {
2151
+ var z = B >> 18 & 31;
2152
+ we(t, u, M[z + 257]), u += N[z + 257], z > 7 && (Ce(t, u, B >> 23 & 31), u += re[z]);
2153
+ var V = B & 31;
2154
+ we(t, u, P[V]), u += F[V], V > 3 && (we(t, u, B >> 5 & 8191), u += ie[V]);
2155
+ } else we(t, u, M[B]), u += N[B];
2156
+ }
2157
+ return we(t, u, M[256]), u + N[256];
2158
+ }, je = /*#__PURE__*/ new ne([
2159
+ 65540,
2160
+ 131080,
2161
+ 131088,
2162
+ 131104,
2163
+ 262176,
2164
+ 1048704,
2165
+ 1048832,
2166
+ 2114560,
2167
+ 2117632
2168
+ ]), Me = /*#__PURE__*/ new W(0), Ne = function(e, t, n, r, i, a) {
2169
+ var o = a.z || e.length, s = new W(r + o + 5 * (1 + Math.ceil(o / 7e3)) + i), c = s.subarray(r, s.length - i), l = a.l, u = (a.r || 0) & 7;
2170
+ if (t) {
2171
+ u && (c[0] = a.r >> 3);
2172
+ for (var d = je[t - 1], f = d >> 13, p = d & 8191, m = (1 << n) - 1, h = a.p || new G(32768), g = a.h || new G(m + 1), _ = Math.ceil(n / 3), v = 2 * _, y = function(t) {
2173
+ return (e[t] ^ e[t + 1] << _ ^ e[t + 2] << v) & m;
2174
+ }, b = new ne(25e3), x = new G(288), S = new G(32), C = 0, w = 0, T = a.i || 0, E = 0, D = a.w || 0, O = 0; T + 2 < o; ++T) {
2175
+ var k = y(T), A = T & 32767, j = g[k];
2176
+ if (h[A] = j, g[k] = A, D <= T) {
2177
+ var M = o - T;
2178
+ if ((C > 7e3 || E > 24576) && (M > 423 || !l)) {
2179
+ u = Ae(e, c, 0, b, x, S, w, E, O, T - O, u), E = C = w = 0, O = T;
2180
+ for (var N = 0; N < 286; ++N) x[N] = 0;
2181
+ for (var N = 0; N < 30; ++N) S[N] = 0;
2182
+ }
2183
+ var P = 2, F = 0, ee = p, I = A - j & 32767;
2184
+ if (M > 2 && k == y(T - I)) for (var L = Math.min(f, M) - 1, R = Math.min(32767, T), z = Math.min(258, M); I <= R && --ee && A != j;) {
2185
+ if (e[T + P] == e[T + P - I]) {
2186
+ for (var B = 0; B < z && e[T + B] == e[T + B - I]; ++B);
2187
+ if (B > P) {
2188
+ if (P = B, F = I, B > L) break;
2189
+ for (var V = Math.min(I, B - 2), te = 0, N = 0; N < V; ++N) {
2190
+ var H = T - I + N & 32767, U = H - h[H] & 32767;
2191
+ U > te && (te = U, j = H);
2192
+ }
2193
+ }
2194
+ }
2195
+ A = j, j = h[A], I += A - j & 32767;
2196
+ }
2197
+ if (F) {
2198
+ b[E++] = 268435456 | J[P] << 18 | Y[F];
2199
+ var K = J[P] & 31, q = Y[F] & 31;
2200
+ w += re[K] + ie[q], ++x[257 + K], ++S[q], D = T + P, ++C;
2201
+ } else b[E++] = e[T], ++x[e[T]];
2202
+ }
2203
+ }
2204
+ for (T = Math.max(T, D); T < o; ++T) b[E++] = e[T], ++x[e[T]];
2205
+ u = Ae(e, c, l, b, x, S, w, E, O, T - O, u), l || (a.r = u & 7 | c[u / 8 | 0] << 3, u -= 7, a.h = g, a.p = h, a.i = T, a.w = D);
2206
+ } else {
2207
+ for (var T = a.w || 0; T < o + l; T += 65535) {
2208
+ var ae = T + 65535;
2209
+ ae >= o && (c[u / 8 | 0] = l, ae = o), u = ke(c, u + 1, e.subarray(T, ae));
2210
+ }
2211
+ a.i = o;
2212
+ }
2213
+ return ye(s, 0, r + ve(u) + i);
2214
+ }, Pe = function(e, t, n, r, i) {
2215
+ if (!i && (i = { l: 1 }, t.dictionary)) {
2216
+ var a = t.dictionary.subarray(-32768), o = new W(a.length + e.length);
2217
+ o.set(a), o.set(e, a.length), e = o, i.w = a.length;
2218
+ }
2219
+ return Ne(e, t.level == null ? 6 : t.level, t.mem == null ? i.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(e.length))) * 1.5) : 20 : 12 + t.mem, n, r, i);
2220
+ };
2221
+ function Fe(e, t) {
2222
+ return Pe(e, t || {}, 0, 0);
2223
+ }
2224
+ var Ie = /* @__PURE__ */ function() {
2225
+ function e(e, t) {
2226
+ typeof e == "function" && (t = e, e = {}), this.ondata = t;
2227
+ var n = e && e.dictionary && e.dictionary.subarray(-32768);
2228
+ this.s = {
2229
+ i: 0,
2230
+ b: n ? n.length : 0
2231
+ }, this.o = new W(32768), this.p = new W(0), n && this.o.set(n);
2232
+ }
2233
+ return e.prototype.e = function(e) {
2234
+ if (this.ondata || xe(5), this.d && xe(4), !this.p.length) this.p = e;
2235
+ else if (e.length) {
2236
+ var t = new W(this.p.length + e.length);
2237
+ t.set(this.p), t.set(e, this.p.length), this.p = t;
2238
+ }
2239
+ }, e.prototype.c = function(e) {
2240
+ this.s.i = +(this.d = e || !1);
2241
+ var t = this.s.b, n = Se(this.p, this.s, this.o);
2242
+ this.ondata(ye(n, t, this.s.b), this.d), this.o = ye(n, this.s.b - 32768), this.s.b = this.o.length, this.p = ye(this.p, this.s.p / 8 | 0), this.s.p &= 7;
2243
+ }, e.prototype.push = function(e, t) {
2244
+ this.e(e), this.c(t);
2245
+ }, e;
2246
+ }(), Le = typeof TextDecoder < "u" && /*#__PURE__*/ new TextDecoder();
2247
+ try {
2248
+ Le.decode(Me, { stream: !0 });
2249
+ } catch {}
2250
+ //#endregion
2251
+ //#region src/core/replay-codec.ts
2252
+ var Re = 33554432, ze = new TextEncoder();
2253
+ new TextDecoder("utf-8", { fatal: !0 });
2254
+ function Be(e) {
2255
+ let t = 2166136261;
2256
+ for (let n of e) t = Math.imul(t ^ n, 16777619);
2257
+ return t >>> 0;
2258
+ }
2259
+ function Ve(e) {
2260
+ if (e.length > 33554432) throw Error("Replay exceeds 32 MB");
2261
+ let t = Fe(e, { level: 6 }), n = new Uint8Array(16 + t.length), r = new DataView(n.buffer);
2262
+ return n.set([
2263
+ 66,
2264
+ 50,
2265
+ 68,
2266
+ 90,
2267
+ 1,
2268
+ 0,
2269
+ 0,
2270
+ 0
2271
+ ]), r.setUint32(8, e.length, !0), r.setUint32(12, Be(e), !0), n.set(t, 16), n;
2272
+ }
2273
+ function He(e) {
2274
+ if (typeof e == "string") {
2275
+ if (ze.encode(e).length > 33554432) throw Error("Replay exceeds 32 MB");
2276
+ return ze.encode(e);
2277
+ }
2278
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
2279
+ if (t.length > 33554432) throw Error("Replay exceeds 32 MB");
2280
+ if (t[0] !== 66 || t[1] !== 50 || t[2] !== 68 || t[3] !== 90) return t;
2281
+ if (t.length < 17 || t[4] !== 1 || t[5] || t[6] || t[7]) throw Error("Invalid compressed replay header");
2282
+ let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(8, !0);
2283
+ if (!r || r > 33554432) throw Error("Invalid expanded replay size");
2284
+ let i = new Uint8Array(r), a = 0, o = !1, s = new Ie((e, t) => {
2285
+ if (a + e.length > r) throw Error("Expanded replay exceeds declared size");
2286
+ i.set(e, a), a += e.length, o = t;
2287
+ });
2288
+ for (let e = 16; e < t.length; e += 1024) s.push(t.subarray(e, e + 1024), e + 1024 >= t.length);
2289
+ if (!o || a !== r || Be(i) !== n.getUint32(12, !0)) throw Error("Compressed replay integrity failure");
2290
+ return i;
2291
+ }
2292
+ //#endregion
2293
+ //#region src/core/replay-wire.ts
2294
+ var Ue = [
2295
+ "input",
2296
+ "team",
2297
+ "start",
2298
+ "stop",
2299
+ "pause",
2300
+ "scoreLimit",
2301
+ "timeLimit",
2302
+ "kickRate",
2303
+ "join",
2304
+ "disc"
2305
+ ], We = new TextEncoder(), Ge = new TextDecoder("utf-8", { fatal: !0 });
2306
+ function Ke(e) {
2307
+ return Ve(qe(e));
2308
+ }
2309
+ function qe(e) {
2310
+ let { commands: t, ...n } = e, r = t.some((e) => e.kind === "disc") ? 3 : e.checkpoints.length ? 2 : 1, i = 0, a = e.checkpoints.map((e) => {
2311
+ let t = e.state.discs;
2312
+ if (!Array.isArray(t) || t.length > 1728 || t.some((e) => !Number.isFinite(e))) throw Error("Invalid checkpoint discs");
2313
+ return i += t.length * 8, {
2314
+ ...e,
2315
+ state: {
2316
+ ...e.state,
2317
+ discs: t.length
2318
+ }
2319
+ };
2320
+ });
2321
+ if (a.length > 721) throw Error("Too many replay checkpoints");
2322
+ let o = We.encode(JSON.stringify(r >= 2 ? {
2323
+ ...n,
2324
+ checkpoints: a
2325
+ } : n));
2326
+ if (t.length > 5e5 || o.length + 16 > 33554432) throw Error("Replay exceeds bounds");
2327
+ let s = t.length * 12 + t.filter((e) => e.kind === "disc").length * 106, c = new Uint8Array(Math.min(Re, s)), l = new DataView(c.buffer), u = (e) => {
2328
+ if (d + e > c.length) throw Error("Replay exceeds bounds");
2329
+ }, d = 0, f = e.initial.tick, p = (e) => {
2330
+ if (!Number.isInteger(e) || e < 0 || e > 4294967295) throw Error("Invalid replay integer");
2331
+ do {
2332
+ u(1);
2333
+ let t = Math.floor(e / 128);
2334
+ c[d++] = e % 128 | (t ? 128 : 0), e = t;
2335
+ } while (e);
2336
+ };
2337
+ for (let e of t) {
2338
+ let t = Ue.indexOf(r < 3 && e.kind === "join" ? "team" : e.kind);
2339
+ if (e.kind === "join" && e.value !== 0 || e.kind === "team" && e.value > 2) throw Error("Invalid replay team command");
2340
+ if (t < 0 || !Number.isInteger(e.slot) || e.slot < 0 || e.slot > (e.kind === "disc" ? 95 : 31)) throw Error("Invalid replay command");
2341
+ if (p(e.tick - f), u(1), c[d++] = r === 3 ? t : t << 5 | e.slot, r === 3 && p(e.slot), p(r < 3 && e.kind === "join" ? 3 : e.value), e.kind === "disc") {
2342
+ let t = b(e.properties), n = 0;
2343
+ y.forEach(([e], r) => {
2344
+ t[e] !== void 0 && (n |= 1 << r);
2345
+ }), p(n);
2346
+ for (let [e] of y) {
2347
+ let n = t[e];
2348
+ n !== void 0 && (u(8), l.setFloat64(d, n, !0), d += 8);
2349
+ }
2350
+ }
2351
+ f = e.tick;
2352
+ }
2353
+ let m = 16 + o.length + i + d;
2354
+ if (m > 33554432) throw Error("Replay exceeds 32 MB");
2355
+ let h = new Uint8Array(m), g = new DataView(h.buffer);
2356
+ h.set([
2357
+ 66,
2358
+ 50,
2359
+ 68,
2360
+ 80,
2361
+ r,
2362
+ 0,
2363
+ 0,
2364
+ 0
2365
+ ]), g.setUint32(8, o.length, !0), g.setUint32(12, t.length, !0), h.set(o, 16);
2366
+ let _ = 16 + o.length;
2367
+ for (let t of e.checkpoints) for (let e of t.state.discs) g.setFloat64(_, e, !0), _ += 8;
2368
+ return h.set(c.subarray(0, d), _), h;
2369
+ }
2370
+ function Je(e) {
2371
+ let t = He(e);
2372
+ if (t[0] !== 66 || t[1] !== 50 || t[2] !== 68 || t[3] !== 80) return JSON.parse(Ge.decode(t));
2373
+ if (t.length < 16 || ![
2374
+ 1,
2375
+ 2,
2376
+ 3
2377
+ ].includes(t[4]) || t[5] || t[6] || t[7]) throw Error("Invalid packed replay header");
2378
+ let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(8, !0), i = n.getUint32(12, !0);
2379
+ if (r > t.length - 16 || i > 5e5 || i > (t.length - 16 - r) / 3) throw Error("Invalid packed replay bounds");
2380
+ let a = JSON.parse(Ge.decode(t.subarray(16, 16 + r)));
2381
+ if (!a || !Number.isSafeInteger(a.initial?.tick) || a.initial.tick < 0) throw Error("Invalid replay initial tick");
2382
+ a.commands = [];
2383
+ let o = 16 + r, s = a.initial.tick;
2384
+ if (t[4] >= 2) {
2385
+ if (!Array.isArray(a.checkpoints) || a.checkpoints.length > 721) throw Error("Invalid packed checkpoints");
2386
+ let e = 0;
2387
+ for (let t of a.checkpoints) {
2388
+ let n = t?.state?.discs;
2389
+ if (typeof n != "number" || !Number.isInteger(n) || n < 0 || n > 1728) throw Error("Invalid checkpoint disc count");
2390
+ e += n * 8;
2391
+ }
2392
+ if (e > t.length - o - i * 3) throw Error("Truncated checkpoint discs");
2393
+ for (let e of a.checkpoints) {
2394
+ let t = e.state.discs, r = Array(t);
2395
+ for (let e = 0; e < t; e++) {
2396
+ let t = n.getFloat64(o, !0);
2397
+ if (!Number.isFinite(t)) throw Error("Nonfinite checkpoint disc");
2398
+ r[e] = t, o += 8;
2399
+ }
2400
+ e.state.discs = r;
2401
+ }
2402
+ }
2403
+ let c = () => {
2404
+ let e = 0;
2405
+ for (let n = 0; n <= 28; n += 7) {
2406
+ if (o >= t.length) throw Error("Truncated replay command");
2407
+ let r = t[o++];
2408
+ if (n === 28 && r > 15) throw Error("Replay integer overflow");
2409
+ if (e += (r & 127) * 2 ** n, !(r & 128)) {
2410
+ if (n && r === 0) throw Error("Noncanonical replay integer");
2411
+ return e;
2412
+ }
2413
+ }
2414
+ throw Error("Invalid replay integer");
2415
+ };
2416
+ for (let e = 0; e < i; e++) {
2417
+ if (s += c(), !Number.isSafeInteger(s) || o >= t.length) throw Error("Invalid replay tick");
2418
+ let e = t[o++], r = Ue[t[4] === 3 ? e : e >> 5];
2419
+ if (!r) throw Error("Unknown replay command");
2420
+ let i = t[4] === 3 ? c() : e & 31, l = c();
2421
+ if (r === "disc") {
2422
+ let e = c();
2423
+ if (e > 8191) throw Error("Invalid disc property mask");
2424
+ let u = {};
2425
+ y.forEach(([r], i) => {
2426
+ if (e & 1 << i) {
2427
+ if (o + 8 > t.length) throw Error("Truncated disc properties");
2428
+ u[r] = n.getFloat64(o, !0), o += 8;
2429
+ }
2430
+ }), a.commands.push({
2431
+ tick: s,
2432
+ kind: r,
2433
+ slot: i,
2434
+ value: l,
2435
+ properties: b(u)
2436
+ });
2437
+ continue;
2438
+ }
2439
+ a.commands.push(t[4] < 3 && r === "team" && l === 3 ? {
2440
+ tick: s,
2441
+ kind: "join",
2442
+ slot: i,
2443
+ value: 0
2444
+ } : {
2445
+ tick: s,
2446
+ kind: r,
2447
+ slot: i,
2448
+ value: l
2449
+ });
2450
+ }
2451
+ if (o !== t.length) throw Error("Trailing replay command data");
2452
+ return a;
2453
+ }
2454
+ //#endregion
2455
+ //#region src/core/replay.ts
2456
+ function Ye(e) {
2457
+ let t = JSON.stringify(e), n = 2166136261;
2458
+ for (let e = 0; e < t.length; e++) n ^= t.charCodeAt(e), n = Math.imul(n, 16777619);
2459
+ return (n >>> 0).toString(16).padStart(8, "0");
2460
+ }
2461
+ function Xe(e, t) {
2462
+ switch (t.kind) {
2463
+ case "disc":
2464
+ e.applyDiscProperties(t.slot, t.properties);
2465
+ break;
2466
+ case "input":
2467
+ e.input(t.slot, t.value);
2468
+ break;
2469
+ case "join":
2470
+ e.joinPlayer(t.slot);
2471
+ break;
2472
+ case "team":
2473
+ e.setTeam(t.slot, t.value);
2474
+ break;
2475
+ case "start":
2476
+ e.start();
2477
+ break;
2478
+ case "stop":
2479
+ e.stop();
2480
+ break;
2481
+ case "scoreLimit":
2482
+ e.scoreLimit = t.value;
2483
+ break;
2484
+ case "timeLimit":
2485
+ e.timeLimit = t.value;
2486
+ break;
2487
+ case "kickRate":
2488
+ e.setKickRateLimit(t.value & 255, t.value >>> 8 & 255, t.value >>> 16);
2489
+ break;
2490
+ case "pause": e.setPaused(!!t.value);
2491
+ }
2492
+ }
2493
+ var Ze = class {
2494
+ replay;
2495
+ playerOrder = [];
2496
+ lastInputs = /* @__PURE__ */ new Map();
2497
+ bytes = 0;
2498
+ full = !1;
2499
+ canRecord(e) {
2500
+ return !this.full && e.tick - this.replay.initial.tick < 216e3;
2501
+ }
2502
+ constructor(e, t = [], n = [null, null]) {
2503
+ let r = e.snapshot();
2504
+ this.playerOrder = t.map((e) => e.slot), this.replay = {
2505
+ magic: "B2DR",
2506
+ version: 1,
2507
+ engine: ee,
2508
+ stadium: e.source,
2509
+ initial: r,
2510
+ commands: [],
2511
+ checkpoints: [],
2512
+ roster: t.map((e) => ({
2513
+ ...e,
2514
+ tick: r.tick
2515
+ })),
2516
+ styles: [{
2517
+ tick: r.tick,
2518
+ teams: h(n)
2519
+ }],
2520
+ orders: [{
2521
+ tick: r.tick,
2522
+ slots: [...this.playerOrder]
2523
+ }],
2524
+ end: r.tick,
2525
+ finalHash: Ye(r)
2526
+ }, this.bytes = new TextEncoder().encode(JSON.stringify(this.replay)).length;
2527
+ for (let t = 0; t < 32; t++) this.lastInputs.set(t, e.data[e.index(t) * 18 + 14]);
2528
+ }
2529
+ reserve(e) {
2530
+ let t = new TextEncoder().encode(JSON.stringify(e)).length + 1;
2531
+ return this.full || this.bytes + t > 31457280 ? (this.full = !0, !1) : (this.bytes += t, !0);
2532
+ }
2533
+ player(e, t, n, r) {
2534
+ let i = {
2535
+ tick: e,
2536
+ slot: t,
2537
+ name: n,
2538
+ avatar: r
2539
+ };
2540
+ return this.replay.roster.length >= 4096 || !this.reserve(i) ? (this.full = !0, !1) : (this.replay.roster.push(i), n === null ? this.order(e, this.playerOrder.filter((e) => e !== t)) : this.playerOrder.includes(t) ? !0 : this.order(e, [...this.playerOrder, t]));
2541
+ }
2542
+ style(e, t) {
2543
+ let n = {
2544
+ tick: e,
2545
+ teams: h(t)
2546
+ }, r = this.replay.styles;
2547
+ return r.length >= 4096 || !this.reserve(n) ? (this.full = !0, !1) : (r.push(n), !0);
2548
+ }
2549
+ order(e, t) {
2550
+ if (t.length === this.playerOrder.length && t.every((e, t) => e === this.playerOrder[t])) return !0;
2551
+ let n = {
2552
+ tick: e,
2553
+ slots: [...t]
2554
+ }, r = this.replay.orders;
2555
+ return r.length >= 4096 || !this.reserve(n) ? (this.full = !0, !1) : (this.playerOrder = [...t], r.push(n), !0);
2556
+ }
2557
+ command(e) {
2558
+ return e.kind === "input" && this.lastInputs.get(e.slot) === e.value ? !0 : this.replay.commands.length >= 5e5 || !this.reserve(e) ? (this.full = !0, !1) : (e.kind === "input" && this.lastInputs.set(e.slot, e.value), (e.kind === "team" || e.kind === "join") && this.lastInputs.set(e.slot, 0), e.kind === "start" && this.lastInputs.clear(), this.replay.commands.push(e.kind === "disc" ? {
2559
+ ...e,
2560
+ properties: b(e.properties)
2561
+ } : { ...e }), !0);
2562
+ }
2563
+ step(e) {
2564
+ for (let t = 0; t < 32; t++) this.lastInputs.set(t, e.data[e.index(t) * 18 + 14]);
2565
+ if (e.tick % 300 == 0) {
2566
+ let t = e.snapshot(), n = {
2567
+ tick: e.tick,
2568
+ state: t,
2569
+ hash: Ye(t)
2570
+ };
2571
+ this.reserve(n) && this.replay.checkpoints.push(n);
2572
+ }
2573
+ this.replay.end = e.tick;
2574
+ }
2575
+ pack(e) {
2576
+ return this.replay.end = e.tick, this.replay.finalHash = Ye(e.snapshot()), qe(this.replay);
2577
+ }
2578
+ finish(e) {
2579
+ return this.replay.end = e.tick, this.replay.finalHash = Ye(e.snapshot()), new Blob([Ke(this.replay)], { type: "application/x-ball2d-replay" });
2580
+ }
2581
+ };
2582
+ async function Qe(e) {
2583
+ if (e.size > 33554432) throw Error("Replay exceeds 32 MB");
2584
+ return $e(await e.arrayBuffer());
2585
+ }
2586
+ function $e(e) {
2587
+ let t = Je(e);
2588
+ if (t.magic !== "B2DR" || t.version !== 1 || t.engine !== ee) throw Error("Unsupported replay engine/version");
2589
+ if (!Array.isArray(t.commands) || t.commands.length > 5e5 || !Array.isArray(t.checkpoints) || t.checkpoints.length > 721 || !Number.isInteger(t.end) || t.end < t.initial.tick || t.end - t.initial.tick > 216e3) throw Error("Invalid replay bounds");
2590
+ let n = t.initial.tick;
2591
+ for (let e of t.commands) {
2592
+ if (!Number.isInteger(e.tick) || e.tick < n || e.tick > t.end || ![
2593
+ "input",
2594
+ "team",
2595
+ "start",
2596
+ "stop",
2597
+ "pause",
2598
+ "scoreLimit",
2599
+ "timeLimit",
2600
+ "kickRate",
2601
+ "join",
2602
+ "disc"
2603
+ ].includes(e.kind) || !Number.isInteger(e.slot) || e.slot < 0 || e.slot > (e.kind === "disc" ? 95 : 31) || !Number.isInteger(e.value) || e.value < 0 || e.value > (e.kind === "disc" || e.kind === "join" ? 0 : e.kind === "kickRate" ? 6619135 : e.kind === "timeLimit" ? 5940 : e.kind === "scoreLimit" ? 99 : e.kind === "team" ? 2 : e.kind === "pause" ? 1 : 31)) throw Error("Invalid replay command");
2604
+ e.kind === "disc" && (e.properties = b(e.properties)), n = e.tick;
2605
+ }
2606
+ if (!Array.isArray(t.roster) || t.roster.length > 4096) throw Error("Invalid replay roster");
2607
+ n = t.initial.tick;
2608
+ for (let e of t.roster) {
2609
+ if (!Number.isInteger(e.tick) || e.tick < n || e.tick > t.end || !Number.isInteger(e.slot) || e.slot < 0 || e.slot > 31 || e.name !== null && (typeof e.name != "string" || e.name.length > 24) || e.avatar !== void 0 && !v(e.avatar)) throw Error("Invalid roster event");
2610
+ n = e.tick;
2611
+ }
2612
+ if (t.styles !== void 0) {
2613
+ if (!Array.isArray(t.styles) || t.styles.length > 4096) throw Error("Invalid replay styles");
2614
+ let e = t.initial.tick;
2615
+ for (let n of t.styles) {
2616
+ if (!n || !Number.isInteger(n.tick) || n.tick < e || n.tick > t.end || n.teams === void 0) throw Error("Invalid replay style");
2617
+ n.teams = h(n.teams), e = n.tick;
2618
+ }
2619
+ }
2620
+ if (t.orders !== void 0) {
2621
+ if (!Array.isArray(t.orders) || t.orders.length > 4096) throw Error("Invalid replay orders");
2622
+ let e = t.initial.tick;
2623
+ for (let n of t.orders) {
2624
+ if (!n || !Number.isInteger(n.tick) || n.tick < e || n.tick > t.end || !Array.isArray(n.slots) || n.slots.length > 32 || n.slots.some((e) => !Number.isInteger(e) || e < 0 || e > 31) || new Set(n.slots).size !== n.slots.length) throw Error("Invalid replay order");
2625
+ e = n.tick;
2626
+ }
2627
+ }
2628
+ let r = t.initial.tick;
2629
+ for (let e of t.checkpoints) {
2630
+ if (!Number.isInteger(e.tick) || e.tick <= r || e.tick > t.end || e.state.tick !== e.tick || typeof e.hash != "string") throw Error("Invalid checkpoint");
2631
+ r = e.tick;
2632
+ }
2633
+ return t;
2634
+ }
2635
+ //#endregion
2636
+ //#region src/client/connection-stats.ts
2637
+ function et(e) {
2638
+ let t = [...e], n = new Set(t.filter((e) => e.type === "transport" && e.selectedCandidatePairId).map((e) => e.selectedCandidatePairId)), r = t.filter((e) => e.type === "candidate-pair" && e.state === "succeeded"), i = n.size ? r.filter((e) => n.has(e.id)) : r.filter((e) => e.nominated === !0);
2639
+ if (i.length !== 1) return null;
2640
+ let a = i[0].currentRoundTripTime;
2641
+ return typeof a == "number" && Number.isFinite(a) && a >= 0 ? a * 1e3 : null;
2642
+ }
2643
+ //#endregion
2644
+ //#region src/core/control.ts
2645
+ var tt = 524288, nt = 16384, rt = 12;
2646
+ function it(e, t) {
2647
+ let n = JSON.stringify(e);
2648
+ if (n === void 0) throw Error("Missing control message");
2649
+ let r = new TextEncoder().encode(n);
2650
+ if (r.length > tt) throw Error("Control message exceeds 512 KB");
2651
+ if (r.length <= nt) return [n];
2652
+ let i = Math.ceil(r.length / nt), a = [];
2653
+ for (let e = 0; e < i; e++) {
2654
+ let n = r.subarray(e * nt, (e + 1) * nt), o = new ArrayBuffer(rt + n.length), s = new DataView(o);
2655
+ s.setUint16(0, 45635), s.setUint8(2, 1), s.setUint32(4, t, !0), s.setUint16(8, e, !0), s.setUint16(10, i, !0), new Uint8Array(o, rt).set(n), a.push(o);
2656
+ }
2657
+ return a;
2658
+ }
2659
+ var at = class {
2660
+ partial;
2661
+ push(e, t = performance.now()) {
2662
+ if (typeof e == "string") {
2663
+ if (this.partial || new TextEncoder().encode(e).length > nt) throw Error("Invalid control message");
2664
+ return JSON.parse(e);
2665
+ }
2666
+ if (e.byteLength < 13 || e.byteLength > 16396) throw Error("Control fragment length");
2667
+ let n = new DataView(e);
2668
+ if (n.getUint16(0) !== 45635 || n.getUint8(2) !== 1 || n.getUint8(3) !== 0) throw Error("Control fragment version");
2669
+ let r = n.getUint32(4, !0), i = n.getUint16(8, !0), a = n.getUint16(10, !0);
2670
+ if (a < 2 || a > 32 || i >= a) throw Error("Control fragment bounds");
2671
+ if (!this.partial) {
2672
+ if (i !== 0) throw Error("Missing first fragment");
2673
+ this.partial = {
2674
+ id: r,
2675
+ count: a,
2676
+ next: 0,
2677
+ bytes: 0,
2678
+ parts: [],
2679
+ since: t
2680
+ };
2681
+ }
2682
+ let o = this.partial;
2683
+ if (o.id !== r || o.count !== a || o.next !== i || t - o.since > 1e4) throw Error("Control fragment sequence");
2684
+ if (o.next++, o.bytes += e.byteLength - rt, o.bytes > tt) throw Error("Control size limit");
2685
+ if (o.parts.push(new Uint8Array(e.slice(rt))), o.next !== a) return;
2686
+ let s = new Uint8Array(o.bytes), c = 0;
2687
+ for (let e of o.parts) s.set(e, c), c += e.length;
2688
+ return this.partial = void 0, JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(s));
2689
+ }
2690
+ }, ot = class extends Error {}, st = 1, ct = class {
2691
+ room;
2692
+ credentials;
2693
+ hooks;
2694
+ runtime;
2695
+ ws;
2696
+ peers = /* @__PURE__ */ new Map();
2697
+ id = "";
2698
+ host = !1;
2699
+ hostId = "";
2700
+ closed = !1;
2701
+ timer;
2702
+ bytesSent = 0;
2703
+ bytesReceived = 0;
2704
+ pollingStats = !1;
2705
+ verificationState = null;
2706
+ get requireVerification() {
2707
+ return this.verificationState;
2708
+ }
2709
+ verificationSequence = 0;
2710
+ verificationRequest;
2711
+ challenge;
2712
+ rejectVerification(e, t = !0) {
2713
+ let n = this.verificationRequest;
2714
+ n && (this.verificationRequest = void 0, clearTimeout(n.timer), t && (this.verificationState = null), n.reject(Error(e)));
2715
+ }
2716
+ setRequireVerification(e) {
2717
+ return typeof e == "boolean" ? this.closed || !this.host || this.ws.readyState !== st ? Promise.reject(Error("An active room-owner connection is required.")) : this.verificationRequest ? Promise.reject(Error("A verification update is already pending.")) : new Promise((t, n) => {
2718
+ let r = ++this.verificationSequence, i = setTimeout(() => this.rejectVerification("Verification update was not confirmed."), 1e4);
2719
+ this.verificationRequest = {
2720
+ id: r,
2721
+ timer: i,
2722
+ resolve: t,
2723
+ reject: n
2724
+ };
2725
+ try {
2726
+ this.signal({
2727
+ type: "setVerification",
2728
+ required: e,
2729
+ requestId: r
2730
+ });
2731
+ } catch {
2732
+ this.rejectVerification("Verification update could not be sent.");
2733
+ }
2734
+ }) : Promise.reject(Error("Expected a boolean."));
2735
+ }
2736
+ passwordRequestId = 0;
2737
+ passwordRequest;
2738
+ rejectPasswordUpdate(e) {
2739
+ let t = this.passwordRequest;
2740
+ t && (this.passwordRequest = void 0, clearTimeout(t.timer), t.reject(Error(e)));
2741
+ }
2742
+ setPassword(e) {
2743
+ return e !== null && (typeof e != "string" || e.length > 64) ? Promise.reject(Error("Password must contain at most 64 characters.")) : this.closed || !this.host || this.ws.readyState !== st ? Promise.reject(Error("An active room-owner connection is required.")) : this.passwordRequest ? Promise.reject(Error("A password update is already pending.")) : new Promise((t, n) => {
2744
+ let r = ++this.passwordRequestId, i = setTimeout(() => this.rejectPasswordUpdate("Password update was not confirmed."), 1e4);
2745
+ this.passwordRequest = {
2746
+ id: r,
2747
+ timer: i,
2748
+ resolve: t,
2749
+ reject: n
2750
+ };
2751
+ try {
2752
+ this.signal({
2753
+ type: "setPassword",
2754
+ requestId: r,
2755
+ password: e ?? ""
2756
+ });
2757
+ } catch {
2758
+ this.rejectPasswordUpdate("Password update could not be sent.");
2759
+ }
2760
+ });
2761
+ }
2762
+ banSequence = 0;
2763
+ banRequest;
2764
+ rejectBan(e, t = !0) {
2765
+ let n = this.banRequest;
2766
+ n && (this.banRequest = void 0, clearTimeout(n.timer), n.reject(t ? new ot(e) : Error(e)));
2767
+ }
2768
+ updateBan(e, t) {
2769
+ return this.closed || !this.host || this.ws.readyState !== st ? Promise.reject(Error("An active room-owner connection is required.")) : this.banRequest ? Promise.reject(Error("A ban operation is already pending.")) : new Promise((n, r) => {
2770
+ let i = ++this.banSequence, a = setTimeout(() => this.rejectBan("Ban operation was not confirmed."), 1e4);
2771
+ this.banRequest = {
2772
+ id: i,
2773
+ resolve: n,
2774
+ reject: r,
2775
+ timer: a
2776
+ };
2777
+ try {
2778
+ this.signal({
2779
+ type: e,
2780
+ id: t,
2781
+ requestId: i
2782
+ });
2783
+ } catch {
2784
+ this.rejectBan("Ban operation could not be sent.");
2785
+ }
2786
+ });
2787
+ }
2788
+ get rtt() {
2789
+ let e = [...this.peers.values()].filter((e) => e.connected && e.lostAt === void 0).map((e) => e.rtt).filter((e) => typeof e == "number");
2790
+ return e.length ? Math.max(...e) : null;
2791
+ }
2792
+ signalQueue = Promise.resolve();
2793
+ lastHeartbeat = 0;
2794
+ controlId = 0;
2795
+ controlAssemblers = /* @__PURE__ */ new Map();
2796
+ constructor(e, t, n, r = z()) {
2797
+ this.room = e, this.credentials = t, this.hooks = n, this.runtime = r;
2798
+ let i = new URL(`/api/rooms/${encodeURIComponent(e)}/signal`, R(r.serviceOrigin));
2799
+ i.protocol = i.protocol === "https:" ? "wss:" : "ws:", this.ws = r.createWebSocket(i), this.ws.onopen = () => this.signal({
2800
+ type: "hello",
2801
+ ...t
2802
+ }), this.ws.onmessage = (e) => {
2803
+ this.signalQueue = this.signalQueue.then(() => this.message(JSON.parse(e.data))).catch(() => {
2804
+ this.closed || n.status("Connection negotiation failed. Try another room or network.");
2805
+ });
2806
+ }, this.ws.onclose = (e) => {
2807
+ if (this.challenge?.abort(), this.rejectVerification("Signaling disconnected before verification confirmation."), this.rejectBan("Signaling disconnected before ban confirmation."), this.rejectPasswordUpdate("Signaling disconnected before password confirmation."), !this.closed && (!this.id || [
2808
+ 1001,
2809
+ 1008,
2810
+ 1009
2811
+ ].includes(e.code))) {
2812
+ this.close(), this.hooks.ended?.(e.reason || "Room connection ended.");
2813
+ return;
2814
+ }
2815
+ this.closed || n.status(e.reason || "Signaling disconnected. Established matches can continue; new joins are unavailable.");
2816
+ }, this.ws.onerror = () => n.status("Room service is unavailable."), this.timer = setInterval(() => {
2817
+ this.ws.readyState === st && performance.now() - this.lastHeartbeat >= 3e4 && (this.signal({ type: "heartbeat" }), this.lastHeartbeat = performance.now());
2818
+ for (let e of this.peers.values()) {
2819
+ if (!e.connected && performance.now() - e.created > 2e4) {
2820
+ n.status("Direct connection failed. This network pair may require a relay; this game does not use TURN."), this.remove(e.id);
2821
+ continue;
2822
+ }
2823
+ e.lostAt !== void 0 && (performance.now() - e.lostAt > 2e4 ? (n.status("The direct connection could not be recovered. Rejoin the room."), this.remove(e.id)) : this.host && performance.now() - e.lastRestart > 5e3 && this.restartPeer(e.id));
2824
+ }
2825
+ }, 5e3);
2826
+ }
2827
+ signal(e) {
2828
+ !this.closed && this.ws.readyState === st && this.ws.send(JSON.stringify(e));
2829
+ }
2830
+ async message(e) {
2831
+ if (this.closed) return;
2832
+ if (e.type === "verificationUpdated" && this.verificationRequest && this.verificationRequest.id === e.requestId) {
2833
+ if (e.ok !== !0 || typeof e.required != "boolean") this.rejectVerification(typeof e.error == "string" ? e.error : "Verification update failed.", e.ok !== !1);
2834
+ else {
2835
+ let t = this.verificationRequest;
2836
+ this.verificationRequest = void 0, clearTimeout(t.timer), this.verificationState = e.required, t.resolve(e.required);
2837
+ }
2838
+ return;
2839
+ }
2840
+ if (e.type === "verificationRequired") {
2841
+ if (this.closed || this.id || this.credentials.hostToken || this.challenge || e.roomId !== this.room || typeof e.siteKey != "string" || !/^[A-Za-z0-9_-]{1,100}$/.test(e.siteKey)) return;
2842
+ if (!this.hooks.verify) {
2843
+ this.close(), this.hooks.ended?.("This client cannot complete the room verification challenge.");
2844
+ return;
2845
+ }
2846
+ let t = new AbortController();
2847
+ this.challenge = t;
2848
+ try {
2849
+ let n = await this.hooks.verify({
2850
+ siteKey: e.siteKey,
2851
+ roomId: this.room
2852
+ }, t.signal);
2853
+ if (t.signal.aborted || this.closed || this.ws.readyState !== st) return;
2854
+ if (typeof n != "string" || n.length === 0 || n.length > 2048) throw Error("Invalid verification response.");
2855
+ this.signal({
2856
+ type: "hello",
2857
+ ...this.credentials,
2858
+ verificationToken: n
2859
+ });
2860
+ } catch (e) {
2861
+ this.closed || (this.close(), this.hooks.ended?.(e instanceof Error ? e.message : "Room verification failed."));
2862
+ } finally {
2863
+ this.challenge === t && (this.challenge = void 0);
2864
+ }
2865
+ return;
2866
+ }
2867
+ if (e.type === "passwordUpdated" && typeof e.locked == "boolean" && this.passwordRequest && this.passwordRequest.id === e.requestId) {
2868
+ let t = this.passwordRequest;
2869
+ this.passwordRequest = void 0, clearTimeout(t.timer), t.resolve(e.locked);
2870
+ return;
2871
+ }
2872
+ if (e.type === "banResult" && this.banRequest && this.banRequest.id === e.requestId) {
2873
+ if (e.ok !== !0) this.rejectBan(typeof e.error == "string" ? e.error : "Ban operation failed.", !1);
2874
+ else {
2875
+ let e = this.banRequest;
2876
+ this.banRequest = void 0, clearTimeout(e.timer), e.resolve();
2877
+ }
2878
+ return;
2879
+ }
2880
+ if (e.type === "ready") {
2881
+ this.id = e.id, this.host = e.role === "host", this.hostId = e.hostId, this.verificationState = typeof e.requireVerification == "boolean" ? e.requireVerification : null, this.hooks.ready(this.id, this.host);
2882
+ return;
2883
+ }
2884
+ if (e.type === "peer" && this.host) {
2885
+ let t = this.make(e.id);
2886
+ this.bind(t, t.pc.createDataChannel("control", { ordered: !0 })), this.bind(t, t.pc.createDataChannel("realtime", {
2887
+ ordered: !1,
2888
+ maxRetransmits: 0
2889
+ }));
2890
+ let n = await t.pc.createOffer();
2891
+ if (!this.current(t) || (await t.pc.setLocalDescription(n), !this.current(t))) return;
2892
+ this.signal({
2893
+ type: "signal",
2894
+ to: t.id,
2895
+ signal: {
2896
+ type: "offer",
2897
+ sdp: t.pc.localDescription.sdp
2898
+ }
2899
+ });
2900
+ return;
2901
+ }
2902
+ if (e.type === "leave") {
2903
+ this.remove(e.id);
2904
+ return;
2905
+ }
2906
+ if (e.type !== "signal") return;
2907
+ let t = this.peers.get(e.from);
2908
+ if (!t) {
2909
+ if (this.host || e.from !== this.hostId || !["offer", "candidate"].includes(e.signal.type)) return;
2910
+ t = this.make(e.from);
2911
+ }
2912
+ if (e.signal.type === "offer") {
2913
+ if (this.host) throw Error("Only the host can offer");
2914
+ if (await t.pc.setRemoteDescription({
2915
+ type: "offer",
2916
+ sdp: e.signal.sdp
2917
+ }), !this.current(t) || (await this.flushCandidates(t), !this.current(t))) return;
2918
+ let n = await t.pc.createAnswer();
2919
+ if (!this.current(t) || (await t.pc.setLocalDescription(n), !this.current(t))) return;
2920
+ this.signal({
2921
+ type: "signal",
2922
+ to: t.id,
2923
+ signal: {
2924
+ type: "answer",
2925
+ sdp: t.pc.localDescription.sdp
2926
+ }
2927
+ });
2928
+ } else if (e.signal.type === "answer") {
2929
+ if (!this.host) throw Error("Only guests can answer");
2930
+ if (await t.pc.setRemoteDescription({
2931
+ type: "answer",
2932
+ sdp: e.signal.sdp
2933
+ }), !this.current(t)) return;
2934
+ await this.flushCandidates(t), this.noteHealthy(t);
2935
+ } else if (e.signal.type === "candidate" && e.signal.candidate) {
2936
+ if (!t.pc.remoteDescription) this.queueCandidate(t, e.signal.candidate);
2937
+ else try {
2938
+ await t.pc.addIceCandidate(e.signal.candidate);
2939
+ } catch {
2940
+ this.queueCandidate(t, e.signal.candidate);
2941
+ }
2942
+ }
2943
+ }
2944
+ current(e) {
2945
+ return !this.closed && this.peers.get(e.id) === e;
2946
+ }
2947
+ queueCandidate(e, t) {
2948
+ if (this.current(e)) {
2949
+ if (e.candidates.length >= 128) throw Error("Too many pending ICE candidates");
2950
+ e.candidates.push(t);
2951
+ }
2952
+ }
2953
+ noteHealthy(e) {
2954
+ if (!this.current(e) || e.pc.connectionState !== "connected" || !["connected", "completed"].includes(e.pc.iceConnectionState)) return;
2955
+ let t = e.lostAt !== void 0;
2956
+ e.lostAt = void 0, e.restarts = 0, t && this.hooks.status("Direct connection restored.");
2957
+ }
2958
+ async flushCandidates(e) {
2959
+ let t = e.candidates.splice(0);
2960
+ for (let n of t) {
2961
+ if (!this.current(e)) return;
2962
+ try {
2963
+ await e.pc.addIceCandidate(n);
2964
+ } catch {}
2965
+ }
2966
+ }
2967
+ async restartPeer(e) {
2968
+ let t = this.peers.get(e);
2969
+ if (this.closed || !this.host || !t || t.restarting || t.restarts >= 2 || t.pc.signalingState !== "stable" || this.ws.readyState !== st) return !1;
2970
+ t.restarting = !0, t.lastRestart = performance.now(), t.lostAt ??= t.lastRestart, t.restarts++;
2971
+ try {
2972
+ let n = await t.pc.createOffer({ iceRestart: !0 });
2973
+ return this.closed || this.peers.get(e) !== t || (await t.pc.setLocalDescription(n), this.closed || this.peers.get(e) !== t) ? !1 : (this.signal({
2974
+ type: "signal",
2975
+ to: t.id,
2976
+ signal: {
2977
+ type: "offer",
2978
+ sdp: t.pc.localDescription.sdp
2979
+ }
2980
+ }), !0);
2981
+ } catch {
2982
+ return !this.closed && this.peers.get(e) === t && this.hooks.status("Direct connection recovery is still pending."), !1;
2983
+ } finally {
2984
+ t.restarting = !1;
2985
+ }
2986
+ }
2987
+ make(e) {
2988
+ let t = this.runtime.createPeerConnection({
2989
+ iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
2990
+ bundlePolicy: "max-bundle"
2991
+ }), n = {
2992
+ id: e,
2993
+ pc: t,
2994
+ connected: !1,
2995
+ created: performance.now(),
2996
+ candidates: [],
2997
+ lastRestart: 0,
2998
+ restarts: 0,
2999
+ restarting: !1
3000
+ };
3001
+ this.peers.set(e, n), t.onicecandidate = (t) => {
3002
+ this.closed || this.peers.get(e) !== n || t.candidate && this.signal({
3003
+ type: "signal",
3004
+ to: e,
3005
+ signal: {
3006
+ type: "candidate",
3007
+ candidate: t.candidate.toJSON()
3008
+ }
3009
+ });
3010
+ }, t.ondatachannel = (e) => this.bind(n, e.channel);
3011
+ let r = () => {
3012
+ this.closed || this.peers.get(e) !== n || (t.connectionState === "closed" ? (this.hooks.status("A peer disconnected."), this.remove(e)) : t.connectionState === "connected" && ["connected", "completed"].includes(t.iceConnectionState) ? this.noteHealthy(n) : (["failed", "disconnected"].includes(t.connectionState) || ["failed", "disconnected"].includes(t.iceConnectionState)) && (n.lostAt ??= performance.now(), this.hooks.status("Direct connection interrupted. Attempting recovery…")));
3013
+ };
3014
+ return t.onconnectionstatechange = r, t.oniceconnectionstatechange = r, n;
3015
+ }
3016
+ bind(e, t) {
3017
+ if (this.closed || this.peers.get(e.id) !== e || !["control", "realtime"].includes(t.label)) {
3018
+ t.close();
3019
+ return;
3020
+ }
3021
+ if (t.maxPacketLifeTime !== null || t.label === "control" && (t.ordered !== !0 || t.maxRetransmits !== null) || t.label === "realtime" && (t.ordered !== !1 || t.maxRetransmits !== 0) || (t.label === "control" ? e.control : e.fast)) {
3022
+ t.close(), this.remove(e.id);
3023
+ return;
3024
+ }
3025
+ t.binaryType = "arraybuffer", t.label === "control" ? e.control = t : e.fast = t, t.onclose = () => {
3026
+ !this.closed && this.peers.get(e.id) === e && (this.hooks.status("A peer closed its game channel."), this.remove(e.id));
3027
+ }, t.onopen = () => {
3028
+ this.closed || this.peers.get(e.id) !== e || e.control?.readyState === "open" && e.fast?.readyState === "open" && !e.connected && (e.connected = !0, this.host && (e.admissionTimer = setTimeout(() => {
3029
+ this.closed || this.peers.get(e.id) !== e || (this.hooks.status("A peer did not complete room admission."), this.remove(e.id));
3030
+ }, 1e4)), this.hooks.open(e));
3031
+ }, t.onmessage = (n) => {
3032
+ if (!(this.closed || this.peers.get(e.id) !== e)) {
3033
+ this.bytesReceived += typeof n.data == "string" ? n.data.length : n.data.byteLength;
3034
+ try {
3035
+ if (t.label === "control") {
3036
+ let t = typeof n.data != "string" || new TextEncoder().encode(n.data).length > 4096;
3037
+ if (this.host && t && !this.hooks.allowStadiumUpload?.(e)) throw Error("Guest control size or permission");
3038
+ if (typeof n.data != "string" && !(n.data instanceof ArrayBuffer)) throw Error("Invalid control type");
3039
+ let r = this.controlAssemblers.get(e.id);
3040
+ r || (r = new at(), this.controlAssemblers.set(e.id, r));
3041
+ let i = r.push(n.data);
3042
+ if (i !== void 0) {
3043
+ if (this.host && t && (!i || typeof i != "object" || i.type !== "action" || i.action !== "customStadium")) throw Error("Invalid bulk action");
3044
+ this.hooks.control(e, i);
3045
+ }
3046
+ } else if (n.data instanceof ArrayBuffer && n.data.byteLength <= 1200) this.hooks.fast(e, n.data);
3047
+ else throw Error();
3048
+ } catch {
3049
+ this.hooks.status("Invalid peer message rejected."), this.remove(e.id);
3050
+ }
3051
+ }
3052
+ };
3053
+ }
3054
+ admit(e) {
3055
+ clearTimeout(e.admissionTimer), e.admissionTimer = void 0;
3056
+ }
3057
+ control(e, t) {
3058
+ if (e.control?.readyState !== "open") return;
3059
+ let n = it(t, this.controlId++), r = n.reduce((e, t) => e + (typeof t == "string" ? new TextEncoder().encode(t).length : t.byteLength), 0);
3060
+ if (e.control.bufferedAmount + r > 1048576) {
3061
+ this.remove(e.id);
3062
+ return;
3063
+ }
3064
+ for (let t of n) e.control.send(t);
3065
+ this.bytesSent += r;
3066
+ }
3067
+ fast(e, t) {
3068
+ e.fast?.readyState === "open" && e.fast.bufferedAmount < 32768 && (e.fast.send(t), this.bytesSent += t.byteLength);
3069
+ }
3070
+ broadcast(e) {
3071
+ for (let t of this.peers.values()) this.control(t, e);
3072
+ }
3073
+ async stats() {
3074
+ if (!(this.pollingStats || this.closed)) {
3075
+ this.pollingStats = !0;
3076
+ try {
3077
+ await Promise.allSettled([...this.peers.values()].map(async (e) => {
3078
+ if (!e.connected || e.lostAt !== void 0) {
3079
+ e.rtt = null;
3080
+ return;
3081
+ }
3082
+ try {
3083
+ let t = await e.pc.getStats();
3084
+ !this.closed && this.peers.get(e.id) === e && (e.rtt = et(t.values()));
3085
+ } catch {
3086
+ e.rtt = null;
3087
+ }
3088
+ }));
3089
+ } finally {
3090
+ this.pollingStats = !1;
3091
+ }
3092
+ }
3093
+ }
3094
+ remove(e) {
3095
+ let t = this.peers.get(e);
3096
+ t && (clearTimeout(t.admissionTimer), this.peers.delete(e), this.controlAssemblers.delete(e), t.pc.close(), this.host ? this.signal({
3097
+ type: "evict",
3098
+ id: e
3099
+ }) : this.close(), this.hooks.leave(e), this.host || this.hooks.ended?.("The host connection ended."));
3100
+ }
3101
+ close() {
3102
+ this.challenge?.abort(), this.rejectVerification("Room closed before verification confirmation."), this.verificationState = null, this.rejectBan("Room closed before ban confirmation."), this.rejectPasswordUpdate("Room closed before password confirmation."), this.closed = !0, clearInterval(this.timer), this.ws.close(1e3, "Left room");
3103
+ for (let e of this.peers.values()) clearTimeout(e.admissionTimer), e.pc.close();
3104
+ this.peers.clear(), this.controlAssemblers.clear();
3105
+ }
3106
+ };
3107
+ function lt(e, t) {
3108
+ return e !== t && e - t >>> 0 < 2147483648;
3109
+ }
3110
+ function ut(e) {
3111
+ if (e.byteLength !== 14) throw Error("Input length");
3112
+ let t = new DataView(e);
3113
+ if (t.getUint8(0) !== 1 || t.getUint8(1) !== 5 || t.getUint8(6) > 31 || t.getUint8(7)) throw Error("Input format");
3114
+ return {
3115
+ seq: t.getUint32(2, !0),
3116
+ keys: t.getUint8(6),
3117
+ time: t.getUint32(8, !0),
3118
+ epoch: t.getUint16(12, !0)
3119
+ };
3120
+ }
3121
+ function dt(e, t, n = 0) {
3122
+ let r = [];
3123
+ for (let t = 0; t < e.discs.length / 18; t++) {
3124
+ let n = t * 18, i = e.discs, a = i[n + 5] > 0 || i[n + 2] !== 0 || i[n + 3] !== 0 || i[n + 8] !== 0 || i[n + 9] !== 0 || i[n] !== i[n + 16] || i[n + 1] !== i[n + 17];
3125
+ (i[n + 12] > 0 ? i[n + 13] > 0 : a) && r.push(t);
3126
+ }
3127
+ let i = [
3128
+ "lobby",
3129
+ "playing",
3130
+ "goal",
3131
+ "finished"
3132
+ ], a = /* @__PURE__ */ new ArrayBuffer(36 + r.length * 24), o = new DataView(a);
3133
+ o.setUint32(0, e.tick, !0), o.setUint32(4, e.elapsed, !0), o.setUint16(8, e.red, !0), o.setUint16(10, e.blue, !0), o.setUint8(12, i.indexOf(e.phase)), o.setUint8(13, +e.paused), o.setUint8(14, e.kickoff), o.setUint8(15, +e.kickoffActive), o.setUint16(16, e.countdown, !0), o.setUint16(18, e.scoreLimit, !0), o.setUint16(20, e.timeLimit, !0), o.setUint16(22, e.discs.length / 18, !0), o.setUint32(24, t, !0), o.setUint16(28, r.length, !0), o.setUint16(30, e.resumeTicks, !0), o.setUint32(32, e.kickRate, !0), r.forEach((t, n) => {
3134
+ let r = t * 18, i = 36 + n * 24;
3135
+ o.setUint16(i, t, !0), o.setUint8(i + 2, e.discs[r + 13]), o.setUint8(i + 3, e.discs[r + 14] | (e.discs[r + 12] > 0 ? (e.discs[r + 11] & 24) << 2 : 0));
3136
+ for (let t = 0; t < 4; t++) o.setFloat32(i + 4 + t * 4, e.discs[r + t], !0);
3137
+ o.setUint16(i + 20, e.discs[r + 15], !0), e.discs[r + 12] > 0 && o.setUint16(i + 22, e.discs[r + 17] + 255, !0);
3138
+ });
3139
+ let s = new Uint8Array(a), c = [], l = Math.ceil(s.length / 1188);
3140
+ for (let t = 0; t < l; t++) {
3141
+ let r = s.subarray(t * 1188, (t + 1) * 1188), i = new ArrayBuffer(12 + r.length), a = new DataView(i);
3142
+ a.setUint8(0, 2), a.setUint8(1, 5), a.setUint32(2, e.tick, !0), a.setUint8(6, t), a.setUint8(7, l), a.setUint16(8, n, !0), a.setUint16(10, r.length, !0), new Uint8Array(i, 12).set(r), c.push(i);
3143
+ }
3144
+ return c;
3145
+ }
3146
+ //#endregion
3147
+ //#region src/client/headless.ts
3148
+ var ft = Object.freeze({ ...C }), pt = class e {
3149
+ runtime;
3150
+ engine;
3151
+ network;
3152
+ roomId = "";
3153
+ roomLink = "";
3154
+ roomName = "";
3155
+ epoch = 0;
3156
+ stadiumSelection = 0;
3157
+ players = [];
3158
+ nextPlayerId = 0;
3159
+ bans = /* @__PURE__ */ new Map();
3160
+ loop;
3161
+ linkNotification;
3162
+ last = performance.now();
3163
+ accumulator = 0;
3164
+ recorder;
3165
+ closed = !1;
3166
+ closeController = new AbortController();
3167
+ signal = this.closeController.signal;
3168
+ finishingRecording = !1;
3169
+ lastRecording = null;
3170
+ onRecordingComplete;
3171
+ locked = !1;
3172
+ teamStyles = [null, null];
3173
+ inputs = /* @__PURE__ */ new Map();
3174
+ traffic = new U();
3175
+ onRoomLink;
3176
+ onPlayerJoin;
3177
+ onPlayerTeamChange;
3178
+ onPlayerAdminChange;
3179
+ onGameStart;
3180
+ onGameStop;
3181
+ onTeamVictory;
3182
+ onGameVictory;
3183
+ onGamePauseChange;
3184
+ onGamePause;
3185
+ onGameUnpause;
3186
+ onPlayerLeave;
3187
+ onPlayerKicked;
3188
+ onPlayerActivity;
3189
+ onPlayerChat;
3190
+ onPlayerBallKick;
3191
+ onTeamGoal;
3192
+ onPositionsReset;
3193
+ onStadiumChange;
3194
+ onTeamsLockChange;
3195
+ onKickRateLimitSet;
3196
+ onGameTick;
3197
+ onError;
3198
+ report(e) {
3199
+ try {
3200
+ let t = this.onError?.(e);
3201
+ t instanceof Promise && t.catch(() => {});
3202
+ } catch {}
3203
+ }
3204
+ invoke(e, t, ...n) {
3205
+ if (!(this.closed && e !== "onRecordingComplete")) try {
3206
+ let r = t?.apply(this, n);
3207
+ return r instanceof Promise && r.catch((t) => this.report(`${e}: ${String(t)}`)), r;
3208
+ } catch (t) {
3209
+ this.report(`${e}: ${String(t)}`);
3210
+ return;
3211
+ }
3212
+ }
3213
+ constructor(e, t) {
3214
+ this.runtime = t, this.engine = e;
3215
+ }
3216
+ static async create(t, n = te(), r) {
3217
+ let i = R(n.network.serviceOrigin);
3218
+ if (t = d(t), t.noPlayer !== void 0 && typeof t.noPlayer != "boolean") throw Error("Invalid noPlayer setting");
3219
+ let a = t.noPlayer === !1, o = t.playerName ?? "Host";
3220
+ if (a && (typeof o != "string" || !o.trim() || o.length > 24)) throw Error("Invalid host player name");
3221
+ let s = l(r), c;
3222
+ try {
3223
+ s.signal.throwIfAborted();
3224
+ let r = await s.run(n.loadEngine(s.signal));
3225
+ r.load(t.stadium ?? F()), c = new e(r, n);
3226
+ let l = c, u = await s.run(n.request(new URL("/api/rooms", i), {
3227
+ signal: s.signal,
3228
+ method: "POST",
3229
+ headers: { "Content-Type": "application/json" },
3230
+ body: JSON.stringify({
3231
+ name: t.roomName,
3232
+ maxPlayers: t.maxPlayers ?? 16,
3233
+ password: t.password ?? "",
3234
+ private: t.public === !1,
3235
+ hostPlayer: a
3236
+ })
3237
+ }));
3238
+ if (!u.ok) throw Error(`Room creation failed (${u.status})`);
3239
+ let d = await s.run(u.json());
3240
+ l.roomId = d.id, l.roomName = t.roomName, l.roomLink = `${i}${p(d.id)}`;
3241
+ let f;
3242
+ try {
3243
+ await s.run(new Promise((e, t) => {
3244
+ f = setTimeout(() => t(Error("Signaling timed out")), 12e3), l.network = new ct(d.id, { hostToken: d.hostToken }, {
3245
+ ready: (n, r) => {
3246
+ if (!r) {
3247
+ t(Error("Host authority was not granted"));
3248
+ return;
3249
+ }
3250
+ a && (l.players.push({
3251
+ id: l.nextPlayerId++,
3252
+ slot: 0,
3253
+ peerId: n,
3254
+ name: o.trim(),
3255
+ team: 0,
3256
+ admin: !0
3257
+ }), l.engine.joinPlayer(0)), clearTimeout(f), e();
3258
+ },
3259
+ allowStadiumUpload: (e) => !!l.players.find((t) => t.peerId === e.id)?.admin && ["lobby", "finished"].includes(l.engine.phase) && l.traffic.allow(e.id, "message"),
3260
+ open: () => {},
3261
+ control: (e, t) => l.control(e, t),
3262
+ fast: (e, t) => l.fast(e, t),
3263
+ leave: (e) => l.leave(e),
3264
+ status: (e) => l.report(e),
3265
+ ended: (e) => {
3266
+ clearTimeout(f), t(Error(e)), l.close(), l.report(e);
3267
+ }
3268
+ }, n.network);
3269
+ }));
3270
+ } catch (e) {
3271
+ throw l.close(), e;
3272
+ } finally {
3273
+ clearTimeout(f);
3274
+ }
3275
+ if (l.closed) throw Error("Room closed during startup");
3276
+ l.last = performance.now(), l.loop = setInterval(() => l.advance(), 1e3 / 60);
3277
+ let m = l.roomLink;
3278
+ return l.linkNotification = setTimeout(() => {
3279
+ l.linkNotification = void 0, l.invoke("onRoomLink", l.onRoomLink, m);
3280
+ }, 0), c;
3281
+ } catch (e) {
3282
+ throw c?.close(), e;
3283
+ } finally {
3284
+ s.dispose();
3285
+ }
3286
+ }
3287
+ advance() {
3288
+ if (this.closed) return;
3289
+ let e = performance.now(), t = e - this.last;
3290
+ this.last = e, t > 500 && this.engine.phase === "playing" && !this.engine.paused && (this.pauseGame(!0), this.report("Host scheduler stalled; match paused.")), this.accumulator += Math.max(0, Math.min(t, 500));
3291
+ let n = 0;
3292
+ try {
3293
+ for (; !this.closed && this.accumulator >= 1e3 / 60 && n++ < 32;) {
3294
+ for (let t of this.players) {
3295
+ let n = this.inputs.get(t.peerId);
3296
+ n && e - n.received > 250 && this.engine.data[this.engine.index(t.slot) * 18 + 14] && this.command("input", t.slot, 0);
3297
+ }
3298
+ if (this.recorder && !this.recorder.canRecord(this.engine) && this.finishRecording("Recording limit reached"), this.closed || (this.engine.phase !== "lobby" && !this.engine.paused && !this.engine.resumeTicks && this.invoke("onGameTick", this.onGameTick), this.closed)) break;
3299
+ let t = this.engine.red, n = this.engine.blue, r = this.engine.phase;
3300
+ this.engine.step(), this.recorder?.step(this.engine), this.engine.phase !== r && this.state();
3301
+ let i = r === "goal" && this.engine.phase === "playing";
3302
+ r === "finished" && this.engine.phase === "lobby" && this.invoke("onGameStop", this.onGameStop, null);
3303
+ let a = this.engine.ballKicks.map((e) => {
3304
+ let t = this.players.find((t) => t.slot === e);
3305
+ return t ? this.playerCopy(t) : null;
3306
+ }).filter((e) => !!e), o = r !== "finished" && this.engine.phase === "finished" ? this.getScores() : null;
3307
+ o && (this.invoke("onTeamVictory", this.onTeamVictory, { ...o }), this.invoke("onGameVictory", this.onGameVictory, { ...o }));
3308
+ for (let e of a) this.invoke("onPlayerBallKick", this.onPlayerBallKick, e);
3309
+ if (this.engine.red > t && this.invoke("onTeamGoal", this.onTeamGoal, 1), this.engine.blue > n && this.invoke("onTeamGoal", this.onTeamGoal, 2), i && this.invoke("onPositionsReset", this.onPositionsReset), this.closed) break;
3310
+ if (this.engine.tick % 2 == 0) {
3311
+ let e = this.engine.snapshot();
3312
+ for (let t of this.network.peers.values()) for (let n of dt(e, this.inputs.get(t.id)?.seq ?? 0, this.epoch)) this.network.fast(t, n);
3313
+ }
3314
+ this.accumulator -= 1e3 / 60;
3315
+ }
3316
+ } catch (e) {
3317
+ this.closed || (this.engine.setPaused(!0), this.report(String(e)));
3318
+ }
3319
+ }
3320
+ allowed(e) {
3321
+ return this.traffic.allow(e.id, "message") ? !0 : (this.network.remove(e.id), !1);
3322
+ }
3323
+ control(e, t) {
3324
+ if (!this.allowed(e) || !t || typeof t != "object") return;
3325
+ let n = t, r = this.players.find((t) => t.peerId === e.id);
3326
+ if (n.type === "join" && !r) {
3327
+ if (n.version !== 1 || n.engine !== ee || typeof n.name != "string" || !n.name.trim() || n.name.length > 24) {
3328
+ this.network.remove(e.id);
3329
+ return;
3330
+ }
3331
+ let t = Array.from({ length: 32 }, (e, t) => t).find((e) => !this.players.some((t) => t.slot === e));
3332
+ if (t === void 0) {
3333
+ this.network.remove(e.id);
3334
+ return;
3335
+ }
3336
+ r = {
3337
+ id: this.nextPlayerId++,
3338
+ slot: t,
3339
+ peerId: e.id,
3340
+ name: n.name.trim(),
3341
+ team: 0,
3342
+ admin: !1
3343
+ }, this.players.push(r), this.network.admit(e), this.recorder?.player(this.engine.tick, r.slot, r.name), this.command("join", t, 0), this.network.control(e, {
3344
+ type: "welcome",
3345
+ epoch: this.epoch,
3346
+ roomName: this.roomName,
3347
+ engine: ee,
3348
+ slot: t,
3349
+ stadium: this.engine.source,
3350
+ state: this.engine.snapshot(),
3351
+ players: this.roster(),
3352
+ teamStyles: this.teamStyles,
3353
+ locked: this.locked
3354
+ }), this.sync(), this.invoke("onPlayerJoin", this.onPlayerJoin, this.playerCopy(r));
3355
+ return;
3356
+ }
3357
+ if (r && n.type === "action") {
3358
+ if (n.action === "chat" && typeof n.text == "string" && n.text.length <= 200) {
3359
+ if (!n.text.trim() || !this.traffic.allow(e.id, "chat") || (this.invoke("onPlayerActivity", this.onPlayerActivity, this.playerCopy(r)), this.closed || !this.players.includes(r))) return;
3360
+ this.invoke("onPlayerChat", this.onPlayerChat, this.playerCopy(r), n.text) !== !1 && this.network.broadcast({
3361
+ type: "chat",
3362
+ name: r.name,
3363
+ text: n.text
3364
+ });
3365
+ }
3366
+ if (n.action === "chat" || this.traffic.allow(e.id, "action")) {
3367
+ if (n.action === "avatar" && v(n.avatar)) {
3368
+ r.avatar = n.avatar, this.recorder?.player(this.engine.tick, r.slot, r.name, r.avatarOverride ?? r.avatar), this.sync();
3369
+ return;
3370
+ }
3371
+ if (n.action === "team" && (!this.locked || r.admin) && [
3372
+ 0,
3373
+ 1,
3374
+ 2
3375
+ ].includes(Number(n.team))) {
3376
+ let e = n.slot === void 0 ? r : this.players.find((e) => e.slot === n.slot);
3377
+ e && (e === r || r.admin) && this.changeTeam(e.id, Number(n.team), r);
3378
+ }
3379
+ if (n.action === "defaultStadium" || n.action === "customStadium") {
3380
+ let t = (t) => {
3381
+ !this.closed && this.players.includes(r) && this.network.control(e, {
3382
+ type: "stadiumResult",
3383
+ text: t
3384
+ });
3385
+ };
3386
+ if (!r.admin || !["lobby", "finished"].includes(this.engine.phase)) {
3387
+ t("Stadium change rejected: admin permission and a stopped match are required.");
3388
+ return;
3389
+ }
3390
+ if (n.action === "defaultStadium" ? typeof n.name != "string" : typeof n.source != "string") return;
3391
+ let i = ++this.stadiumSelection;
3392
+ (n.action === "defaultStadium" ? this.runtime.loadStadium(n.name) : Promise.resolve(n.source)).then((e) => {
3393
+ if (!this.closed && this.players.includes(r)) {
3394
+ if (i !== this.stadiumSelection || !r.admin || !["lobby", "finished"].includes(this.engine.phase)) {
3395
+ t("Stadium change cancelled: room state or permissions changed.");
3396
+ return;
3397
+ }
3398
+ this.changeStadium(e, this.playerCopy(r)), t("Stadium applied.");
3399
+ }
3400
+ }).catch(() => t("Stadium could not be loaded. Please try again."));
3401
+ return;
3402
+ }
3403
+ if (r.admin) {
3404
+ if (n.action === "ban" || n.action === "clearBans") {
3405
+ let t = this.players.find((e) => e.slot === n.slot);
3406
+ if (n.action === "ban" && (!t || t === r || t.peerId === this.network.hostId)) return;
3407
+ let i = (t) => {
3408
+ !this.closed && this.network.peers.has(e.id) && this.network.control(e, {
3409
+ type: "moderationResult",
3410
+ text: t
3411
+ });
3412
+ };
3413
+ if (n.action === "clearBans") {
3414
+ i("Only the room owner can clear bans.");
3415
+ return;
3416
+ }
3417
+ this.banPlayer(t.id, "Removed by admin", this.playerCopy(r)).then(() => i("Player banned.")).catch((e) => i(e instanceof Error ? e.message : "Moderation failed."));
3418
+ return;
3419
+ }
3420
+ if (n.action === "teamColors" && (n.team === 1 || n.team === 2)) {
3421
+ let e = n.palette;
3422
+ this.changeTeamColors(n.team, e === null ? null : m(e.angle, e.textColor, e.colors));
3423
+ }
3424
+ if (n.action === "kickRate" && Number.isInteger(n.value) && Number(n.value) >= 0 && Number(n.value) <= 6619135) {
3425
+ let e = Number(n.value);
3426
+ this.changeKickRateLimit(e & 255, e >>> 8 & 255, e >>> 16, this.playerCopy(r));
3427
+ }
3428
+ if (n.action === "start" && this.beginGame(r), n.action === "stop" && this.endGame(r), n.action === "pause" && (n.paused === void 0 || typeof n.paused == "boolean") && this.changePause(n.paused === void 0 ? !this.engine.paused : n.paused, this.playerCopy(r)), n.action === "settings" && ["lobby", "finished"].includes(this.engine.phase)) {
3429
+ let e = Number(n.score), t = Number(n.minutes);
3430
+ if (Number.isInteger(e) && e >= 0 && e <= 99 && Number.isInteger(t) && t >= 0 && t <= 99 && (n.kickRate === void 0 || Number.isInteger(n.kickRate) && Number(n.kickRate) >= 0 && Number(n.kickRate) <= 6619135)) {
3431
+ if (this.setScoreLimit(e), this.setTimeLimit(t), this.changeTeamsLock(!!n.locked, this.playerCopy(r)), this.closed) return;
3432
+ if (n.kickRate !== void 0 && n.kickRate !== this.engine.kickRate) {
3433
+ let e = Number(n.kickRate);
3434
+ this.changeKickRateLimit(e & 255, e >>> 8 & 255, e >>> 16, this.playerCopy(r));
3435
+ }
3436
+ }
3437
+ }
3438
+ if (n.action === "kick" && typeof n.slot == "number" && n.slot !== r.slot) {
3439
+ let e = this.players.find((e) => e.slot === n.slot);
3440
+ e && this.removePlayer(e.id, "Removed by host", this.playerCopy(r));
3441
+ }
3442
+ }
3443
+ }
3444
+ }
3445
+ }
3446
+ fast(e, t) {
3447
+ if (!this.allowed(e)) return;
3448
+ let n = this.players.find((t) => t.peerId === e.id);
3449
+ if (!n) return;
3450
+ let r = ut(t);
3451
+ if (r.epoch !== this.epoch) return;
3452
+ let i = this.inputs.get(e.id);
3453
+ (!i || lt(r.seq, i.seq)) && (this.inputs.set(e.id, {
3454
+ seq: r.seq,
3455
+ received: performance.now(),
3456
+ keys: r.keys
3457
+ }), this.command("input", n.slot, r.keys), r.keys !== (i?.keys ?? 0) && this.invoke("onPlayerActivity", this.onPlayerActivity, this.playerCopy(n)));
3458
+ }
3459
+ command(e, t = 0, n = 0) {
3460
+ if (this.closed) throw Error("Room is closed");
3461
+ let r = {
3462
+ tick: this.engine.tick,
3463
+ kind: e,
3464
+ slot: t,
3465
+ value: n
3466
+ };
3467
+ if (this.recorder && (!this.recorder.canRecord(this.engine) || !this.recorder.command(r)) && this.finishRecording("Recording limit reached"), this.closed) throw Error("Room is closed");
3468
+ Xe(this.engine, r);
3469
+ }
3470
+ roster() {
3471
+ return this.players.map((e) => ({
3472
+ avatar: e.avatarOverride ?? e.avatar ?? null,
3473
+ id: e.peerId,
3474
+ slot: e.slot,
3475
+ name: e.name,
3476
+ team: e.team,
3477
+ admin: e.admin
3478
+ }));
3479
+ }
3480
+ sync() {
3481
+ this.network.broadcast({
3482
+ type: "lobby",
3483
+ players: this.roster(),
3484
+ teamStyles: this.teamStyles,
3485
+ locked: this.locked,
3486
+ scoreLimit: this.engine.scoreLimit,
3487
+ timeLimit: this.engine.timeLimit
3488
+ });
3489
+ }
3490
+ state() {
3491
+ this.network.broadcast({
3492
+ type: "state",
3493
+ epoch: this.epoch,
3494
+ state: this.engine.snapshot()
3495
+ });
3496
+ }
3497
+ leave(e) {
3498
+ this.traffic.delete(e);
3499
+ let t = this.players.find((t) => t.peerId === e);
3500
+ t && (this.recorder?.player(this.engine.tick, t.slot, null), this.command("team", t.slot, 0), this.players = this.players.filter((t) => t.peerId !== e), this.inputs.delete(e), this.sync(), this.invoke("onPlayerLeave", this.onPlayerLeave, this.playerCopy(t)));
3501
+ }
3502
+ playerCopy(e) {
3503
+ let t = this.engine.index(e.slot) * 18, n = !this.closed && this.engine.phase !== "lobby" && this.engine.data[t + 13] > 0, { slot: r, avatarOverride: i, ...a } = e;
3504
+ return {
3505
+ ...a,
3506
+ avatar: e.avatarOverride ?? e.avatar ?? null,
3507
+ position: n ? {
3508
+ x: this.engine.data[t],
3509
+ y: this.engine.data[t + 1]
3510
+ } : null
3511
+ };
3512
+ }
3513
+ getPlayerList() {
3514
+ return this.players.map((e) => this.playerCopy(e));
3515
+ }
3516
+ getPlayer(e) {
3517
+ let t = this.players.find((t) => t.id === e);
3518
+ return t ? this.playerCopy(t) : null;
3519
+ }
3520
+ setTeamColors(e, t, n, r) {
3521
+ this.changeTeamColors(e, m(t, n, r));
3522
+ }
3523
+ changeTeamColors(e, t) {
3524
+ if (this.closed) throw Error("Room is closed");
3525
+ if (e !== 1 && e !== 2) throw Error("Invalid team");
3526
+ JSON.stringify(this.teamStyles[e - 1]) !== JSON.stringify(t) && (this.teamStyles[e - 1] = t, this.recorder?.style(this.engine.tick, this.teamStyles), this.sync());
3527
+ }
3528
+ reorderPlayers(e, t) {
3529
+ if (this.closed) throw Error("Room is closed");
3530
+ if (!Array.isArray(e) || e.length > 32 || e.some((e) => !Number.isSafeInteger(e) || e < 0) || typeof t != "boolean") throw Error("Invalid player order");
3531
+ let n = new Set(e), r = [...n].flatMap((e) => {
3532
+ let t = this.players.find((t) => t.id === e);
3533
+ return t ? [t] : [];
3534
+ }), i = this.players.filter((e) => !n.has(e.id)), a = t ? [...r, ...i] : [...i, ...r];
3535
+ a.every((e, t) => e === this.players[t]) || (this.players = a, this.recorder?.order(this.engine.tick, a.map((e) => e.slot)), this.sync());
3536
+ }
3537
+ setPlayerAvatar(e, t) {
3538
+ if (this.closed) throw Error("Room is closed");
3539
+ if (!v(t)) throw Error("Avatar must be null or at most two visible characters.");
3540
+ let n = this.players.find((t) => t.id === e);
3541
+ n && (n.avatarOverride = t, this.recorder?.player(this.engine.tick, n.slot, n.name, t ?? n.avatar), this.sync());
3542
+ }
3543
+ setPlayerTeam(e, t) {
3544
+ this.changeTeam(e, t, null);
3545
+ }
3546
+ changeTeam(e, t, n) {
3547
+ if (this.closed) throw Error("Room is closed");
3548
+ if (![
3549
+ 0,
3550
+ 1,
3551
+ 2
3552
+ ].includes(t)) throw Error("Invalid team");
3553
+ let r = this.players.find((t) => t.id === e);
3554
+ r && r.team !== t && (r.team = t, this.command("team", r.slot, t), this.sync(), this.invoke("onPlayerTeamChange", this.onPlayerTeamChange, this.playerCopy(r), n ? this.playerCopy(n) : null));
3555
+ }
3556
+ setPlayerAdmin(e, t) {
3557
+ if (this.closed) throw Error("Room is closed");
3558
+ let n = this.players.find((t) => t.id === e);
3559
+ n && n.admin !== !!t && (n.admin = !!t, this.sync(), this.invoke("onPlayerAdminChange", this.onPlayerAdminChange, this.playerCopy(n), null));
3560
+ }
3561
+ setTeamsLock(e) {
3562
+ this.changeTeamsLock(e, null);
3563
+ }
3564
+ changeTeamsLock(e, t) {
3565
+ if (this.closed) throw Error("Room is closed");
3566
+ this.locked !== !!e && (this.locked = !!e, this.sync(), this.invoke("onTeamsLockChange", this.onTeamsLockChange, this.locked, t));
3567
+ }
3568
+ kickPlayer(e, t = "Removed by host", n = !1) {
3569
+ if (this.closed) throw Error("Room is closed");
3570
+ if (typeof n != "boolean") throw Error("Invalid ban flag");
3571
+ if (n) return this.banPlayer(e, t);
3572
+ this.removePlayer(e, t, null);
3573
+ }
3574
+ async banPlayer(e, t, n = null) {
3575
+ if (typeof t != "string") throw Error("Invalid kick reason");
3576
+ let r = this.players.find((t) => t.id === e);
3577
+ if (!r || r.peerId === this.network.hostId) return;
3578
+ let i = this.playerCopy(r), a = t.slice(0, 100);
3579
+ if (this.bans.size >= 256 && !this.bans.has(e)) throw Error("Clear existing bans before adding more.");
3580
+ try {
3581
+ await this.network.updateBan("ban", r.peerId);
3582
+ } catch (t) {
3583
+ throw t instanceof ot && this.bans.set(e, r.peerId), t;
3584
+ }
3585
+ this.bans.set(e, r.peerId), this.network.remove(r.peerId), this.invoke("onPlayerKicked", this.onPlayerKicked, i, a, !0, n);
3586
+ }
3587
+ async clearBan(e) {
3588
+ if (this.closed) throw Error("Room is closed");
3589
+ let t = this.bans.get(e);
3590
+ t && (await this.network.updateBan("clearBan", t), this.bans.delete(e));
3591
+ }
3592
+ async clearBans() {
3593
+ if (this.closed) throw Error("Room is closed");
3594
+ await this.network.updateBan("clearBans"), this.bans.clear();
3595
+ }
3596
+ removePlayer(e, t, n) {
3597
+ if (this.closed) throw Error("Room is closed");
3598
+ if (typeof t != "string") throw Error("Invalid kick reason");
3599
+ let r = this.players.find((t) => t.id === e);
3600
+ if (r && r.peerId !== this.network.hostId) {
3601
+ let e = this.playerCopy(r), i = t.slice(0, 100), a = this.network.peers.get(r.peerId);
3602
+ a && this.network.control(a, {
3603
+ type: "kicked",
3604
+ reason: i
3605
+ }), this.network.remove(r.peerId), this.players.includes(r) || this.invoke("onPlayerKicked", this.onPlayerKicked, e, i, !1, n);
3606
+ }
3607
+ }
3608
+ sendChat(e, t) {
3609
+ if (this.closed) throw Error("Room is closed");
3610
+ if (typeof e != "string" || e.length > 200) throw Error("Chat must contain at most 200 characters");
3611
+ if (t != null && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid chat target");
3612
+ let n = this.players.find((e) => e.peerId === this.network.hostId);
3613
+ if (!n) throw Error("sendChat requires a host player; use sendAnnouncement");
3614
+ if (!e.trim()) return;
3615
+ let r = {
3616
+ type: "chat",
3617
+ name: n.name,
3618
+ text: e
3619
+ };
3620
+ if (t == null) this.network.broadcast(r);
3621
+ else {
3622
+ let e = this.players.find((e) => e.id === t), n = e && this.network.peers.get(e.peerId);
3623
+ n && this.network.control(n, r);
3624
+ }
3625
+ }
3626
+ sendAnnouncement(e, t, n, r, i) {
3627
+ if (this.closed) throw Error("Room is closed");
3628
+ let a = _(e, n, r, i);
3629
+ if (t != null && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid announcement target");
3630
+ if (t == null) this.network.broadcast(a);
3631
+ else {
3632
+ let e = this.players.find((e) => e.id === t), n = e && this.network.peers.get(e.peerId);
3633
+ n && this.network.control(n, a);
3634
+ }
3635
+ }
3636
+ startGame() {
3637
+ this.beginGame(null);
3638
+ }
3639
+ beginGame(e) {
3640
+ if (this.closed) throw Error("Room is closed");
3641
+ let t = this.engine.phase;
3642
+ (t === "lobby" || t === "finished") && (this.command("start"), this.stadiumSelection++, this.state(), t !== this.engine.phase && this.engine.phase === "playing" && this.invoke("onGameStart", this.onGameStart, e ? this.playerCopy(e) : null));
3643
+ }
3644
+ stopGame() {
3645
+ this.endGame(null);
3646
+ }
3647
+ endGame(e) {
3648
+ if (this.closed) throw Error("Room is closed");
3649
+ let t = this.engine.phase !== "lobby";
3650
+ (t || this.engine.paused) && (this.command("stop"), this.state(), t && this.invoke("onGameStop", this.onGameStop, e ? this.playerCopy(e) : null));
3651
+ }
3652
+ pauseGame(e) {
3653
+ this.changePause(e, null);
3654
+ }
3655
+ changePause(e, t) {
3656
+ if (this.closed) throw Error("Room is closed");
3657
+ this.engine.phase !== "lobby" && (e = !!e, this.engine.paused !== e && (this.command("pause", 0, +e), this.state(), e ? this.invoke("onGamePause", this.onGamePause, t) : this.invoke("onGameUnpause", this.onGameUnpause, t), this.invoke("onGamePauseChange", this.onGamePauseChange, e)));
3658
+ }
3659
+ setKickRateLimit(e = 2, t = 0, n = 0) {
3660
+ this.changeKickRateLimit(e, t, n, null);
3661
+ }
3662
+ changeKickRateLimit(e, t, n, r) {
3663
+ if (this.closed) throw Error("Room is closed");
3664
+ let i = L(e, t, n);
3665
+ i !== this.engine.kickRate && (this.command("kickRate", 0, i), this.state(), this.invoke("onKickRateLimitSet", this.onKickRateLimitSet, i & 255, i >>> 8 & 255, i >>> 16, r));
3666
+ }
3667
+ async setPassword(e) {
3668
+ if (this.closed) throw Error("Room is closed");
3669
+ await this.network.setPassword(e);
3670
+ }
3671
+ get requireVerification() {
3672
+ return this.network.requireVerification;
3673
+ }
3674
+ async setRequireVerification(e) {
3675
+ if (this.closed) throw Error("Room is closed");
3676
+ await this.network.setRequireVerification(e);
3677
+ }
3678
+ async setRequireRecaptcha(e) {
3679
+ await this.setRequireVerification(e);
3680
+ }
3681
+ setScoreLimit(e) {
3682
+ if (this.closed) throw Error("Room is closed");
3683
+ if (["lobby", "finished"].includes(this.engine.phase)) {
3684
+ if (!Number.isInteger(e) || e < 0 || e > 99) throw Error("Invalid limit");
3685
+ e !== this.engine.scoreLimit && (this.command("scoreLimit", 0, e), this.sync());
3686
+ }
3687
+ }
3688
+ setTimeLimit(e) {
3689
+ if (this.closed) throw Error("Room is closed");
3690
+ if (["lobby", "finished"].includes(this.engine.phase)) {
3691
+ if (!Number.isInteger(e) || e < 0 || e > 99) throw Error("Invalid time limit");
3692
+ e * 60 !== this.engine.timeLimit && (this.command("timeLimit", 0, e * 60), this.sync());
3693
+ }
3694
+ }
3695
+ async setDefaultStadium(e) {
3696
+ if (this.closed) throw Error("Room is closed");
3697
+ if (!["lobby", "finished"].includes(this.engine.phase)) return;
3698
+ let t = ++this.stadiumSelection, n = await this.runtime.loadStadium(e);
3699
+ if (this.closed) throw Error("Room is closed");
3700
+ if (t !== this.stadiumSelection) throw Error("Stadium selection superseded");
3701
+ this.setCustomStadium(n);
3702
+ }
3703
+ setCustomStadium(e) {
3704
+ this.changeStadium(e, null);
3705
+ }
3706
+ changeStadium(e, t) {
3707
+ if (this.closed) throw Error("Room is closed");
3708
+ if (!["lobby", "finished"].includes(this.engine.phase)) return;
3709
+ P(e);
3710
+ let n = ++this.stadiumSelection;
3711
+ if (this.recorder && this.finishRecording("Stadium changed"), this.closed) throw Error("Room is closed");
3712
+ if (["lobby", "finished"].includes(this.engine.phase)) {
3713
+ if (n !== this.stadiumSelection) throw Error("Stadium selection superseded");
3714
+ this.engine.load(e);
3715
+ for (let e of this.players) this.engine.setTeam(e.slot, e.team);
3716
+ this.epoch = this.epoch + 1 & 65535, this.inputs.clear(), this.network.broadcast({
3717
+ type: "stadium",
3718
+ epoch: this.epoch,
3719
+ source: e,
3720
+ state: this.engine.snapshot()
3721
+ }), this.invoke("onStadiumChange", this.onStadiumChange, this.engine.stadium.name, t);
3722
+ }
3723
+ }
3724
+ getScores() {
3725
+ let e = this.engine;
3726
+ return this.closed || e.phase === "lobby" ? null : {
3727
+ red: e.red,
3728
+ blue: e.blue,
3729
+ time: e.elapsed / 60,
3730
+ scoreLimit: e.scoreLimit,
3731
+ timeLimit: e.timeLimit
3732
+ };
3733
+ }
3734
+ getBallPosition() {
3735
+ return this.closed || this.engine.phase === "lobby" ? null : {
3736
+ x: this.engine.data[0],
3737
+ y: this.engine.data[1]
3738
+ };
3739
+ }
3740
+ readDisc(e) {
3741
+ let t = this.engine.data, n = e * 18;
3742
+ return {
3743
+ x: t[n],
3744
+ y: t[n + 1],
3745
+ xspeed: t[n + 2],
3746
+ yspeed: t[n + 3],
3747
+ radius: t[n + 4],
3748
+ invMass: t[n + 5],
3749
+ damping: t[n + 6],
3750
+ bCoeff: t[n + 7],
3751
+ xgravity: t[n + 8],
3752
+ ygravity: t[n + 9],
3753
+ cGroup: t[n + 10],
3754
+ cMask: t[n + 11],
3755
+ color: this.engine.colors[e]
3756
+ };
3757
+ }
3758
+ get CollisionFlags() {
3759
+ return ft;
3760
+ }
3761
+ getDiscCount() {
3762
+ return this.closed || this.engine.phase === "lobby" ? 0 : this.engine.stadium.discs.length + this.players.filter((e) => e.team !== 0).length;
3763
+ }
3764
+ getDiscProperties(e) {
3765
+ if (!Number.isInteger(e) || e < 0 || e >= this.getDiscCount()) return null;
3766
+ let t = this.engine.stadium.discs.length;
3767
+ if (e < t) return this.readDisc(e);
3768
+ let n = this.players.filter((e) => e.team !== 0)[e - t];
3769
+ return this.readDisc(this.engine.index(n.slot));
3770
+ }
3771
+ setDiscProperties(e, t) {
3772
+ if (this.closed) throw Error("Room is closed");
3773
+ if (!Number.isInteger(e) || e < 0 || e >= this.getDiscCount()) return;
3774
+ let n = this.engine.stadium.discs.length, r = e < n ? e : this.engine.index(this.players.filter((e) => e.team !== 0)[e - n].slot);
3775
+ this.changeDisc(r, t);
3776
+ }
3777
+ setPlayerDiscProperties(e, t) {
3778
+ if (this.closed) throw Error("Room is closed");
3779
+ if (this.engine.phase === "lobby") return;
3780
+ let n = this.players.find((t) => t.id === e && t.team !== 0);
3781
+ n && this.changeDisc(this.engine.index(n.slot), t);
3782
+ }
3783
+ changeDisc(e, t) {
3784
+ let n = b(t), r = this.readDisc(e);
3785
+ if (Object.entries(n).every(([e, t]) => r[e] === t)) return;
3786
+ let i = {
3787
+ tick: this.engine.tick,
3788
+ kind: "disc",
3789
+ slot: e,
3790
+ value: 0,
3791
+ properties: n
3792
+ };
3793
+ if (this.recorder && (!this.recorder.canRecord(this.engine) || !this.recorder.command(i)) && this.finishRecording("Recording limit reached"), this.closed) throw Error("Room is closed");
3794
+ Xe(this.engine, i), this.state();
3795
+ }
3796
+ getPlayerDiscProperties(e) {
3797
+ if (this.closed || this.engine.phase === "lobby") return null;
3798
+ let t = this.players.find((t) => t.id === e && t.team !== 0);
3799
+ return t ? this.readDisc(this.engine.index(t.slot)) : null;
3800
+ }
3801
+ getState() {
3802
+ return this.engine.snapshot();
3803
+ }
3804
+ startRecording() {
3805
+ if (this.closed) throw Error("Room is closed");
3806
+ if (this.finishingRecording) throw Error("Recording completion is in progress");
3807
+ if (this.recorder) throw Error("Recording is already active");
3808
+ this.recorder = new Ze(this.engine, this.players.map((e) => ({
3809
+ slot: e.slot,
3810
+ name: e.name,
3811
+ avatar: e.avatarOverride ?? e.avatar
3812
+ })), this.teamStyles);
3813
+ }
3814
+ finishRecording(e) {
3815
+ this.finishingRecording = !0;
3816
+ try {
3817
+ let t = this.stopRecording();
3818
+ t && (this.lastRecording = t, this.invoke("onRecordingComplete", this.onRecordingComplete, t, e));
3819
+ } finally {
3820
+ this.finishingRecording = !1;
3821
+ }
3822
+ }
3823
+ stopRecording() {
3824
+ let e = this.recorder?.finish(this.engine) ?? null;
3825
+ return this.recorder = void 0, e;
3826
+ }
3827
+ close() {
3828
+ if (!this.closed) {
3829
+ this.closed = !0, this.closeController.abort();
3830
+ try {
3831
+ this.recorder && this.finishRecording("Room closed");
3832
+ } finally {
3833
+ clearInterval(this.loop), clearTimeout(this.linkNotification), this.linkNotification = void 0, this.network?.close(), this.players = [], this.traffic.clear();
3834
+ }
3835
+ }
3836
+ }
3837
+ };
3838
+ //#endregion
3839
+ //#region src/sdk/config.ts
3840
+ function mt(e) {
3841
+ if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Room configuration must be an object");
3842
+ let t = { ...e }, n = t.maxPlayers ?? 12;
3843
+ if (typeof n != "number" || !Number.isFinite(n) || !Number.isInteger(n)) throw Error("maxPlayers must be a finite integer");
3844
+ return d({
3845
+ ...t,
3846
+ roomName: t.roomName ?? "Headless Room",
3847
+ playerName: t.playerName ?? "Host",
3848
+ noPlayer: t.noPlayer ?? !1,
3849
+ public: t.public ?? !1,
3850
+ maxPlayers: Math.max(2, Math.min(30, n)),
3851
+ password: t.password ?? ""
3852
+ });
3853
+ }
3854
+ //#endregion
3855
+ //#region src/sdk/command-queue.ts
3856
+ var ht = class {
3857
+ onError;
3858
+ pending = [];
3859
+ active;
3860
+ scheduled = !1;
3861
+ closed = !1;
3862
+ constructor(e = () => {}) {
3863
+ this.onError = e;
3864
+ }
3865
+ enqueue(e) {
3866
+ let t = new Promise((t, n) => {
3867
+ if (this.closed) {
3868
+ n(Error("Room is closed"));
3869
+ return;
3870
+ }
3871
+ if (this.pending.length >= 256) {
3872
+ n(Error("Room command queue is full"));
3873
+ return;
3874
+ }
3875
+ this.pending.push({
3876
+ run: e,
3877
+ resolve: (e) => t(e),
3878
+ reject: n
3879
+ }), this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
3880
+ this.drain();
3881
+ }));
3882
+ });
3883
+ return t.catch((e) => {
3884
+ if (!this.closed) try {
3885
+ this.onError(e);
3886
+ } catch {}
3887
+ }), t;
3888
+ }
3889
+ async drain() {
3890
+ for (; !this.closed && this.pending.length;) {
3891
+ let e = this.pending.shift();
3892
+ this.active = e;
3893
+ try {
3894
+ e.resolve(await e.run());
3895
+ } catch (t) {
3896
+ e.reject(t);
3897
+ }
3898
+ this.active = void 0;
3899
+ }
3900
+ this.scheduled = !1;
3901
+ }
3902
+ close() {
3903
+ if (this.closed) return;
3904
+ this.closed = !0;
3905
+ let e = Error("Room is closed");
3906
+ this.active?.reject(e);
3907
+ for (let t of this.pending.splice(0)) t.reject(e);
3908
+ }
3909
+ }, gt = [
3910
+ "sendChat",
3911
+ "sendAnnouncement",
3912
+ "setPlayerAdmin",
3913
+ "setPlayerTeam",
3914
+ "kickPlayer",
3915
+ "clearBan",
3916
+ "clearBans",
3917
+ "setScoreLimit",
3918
+ "setTimeLimit",
3919
+ "setCustomStadium",
3920
+ "setDefaultStadium",
3921
+ "setTeamsLock",
3922
+ "setTeamColors",
3923
+ "startGame",
3924
+ "stopGame",
3925
+ "pauseGame",
3926
+ "setPassword",
3927
+ "setRequireVerification",
3928
+ "setRequireRecaptcha",
3929
+ "reorderPlayers",
3930
+ "setKickRateLimit",
3931
+ "setPlayerAvatar",
3932
+ "setDiscProperties",
3933
+ "setPlayerDiscProperties"
3934
+ ];
3935
+ function _t(e, t) {
3936
+ let n = Object.create(null);
3937
+ t && Object.defineProperty(n, "closed", {
3938
+ enumerable: !0,
3939
+ value: t
3940
+ });
3941
+ let r = new ht((t) => {
3942
+ let n = e.onError?.(String(t));
3943
+ n instanceof Promise && n.catch(() => {});
3944
+ });
3945
+ e.signal.addEventListener("abort", () => r.close(), { once: !0 }), e.signal.aborted && r.close();
3946
+ for (let t of gt) Object.defineProperty(n, t, {
3947
+ enumerable: !0,
3948
+ value: (...n) => {
3949
+ try {
3950
+ let i = structuredClone(n);
3951
+ return (t === "setScoreLimit" || t === "setTimeLimit") && typeof i[0] == "number" && Number.isInteger(i[0]) && (i[0] = Math.max(0, Math.min(99, i[0]))), r.enqueue(() => Reflect.apply(e[t], e, i));
3952
+ } catch (e) {
3953
+ return r.enqueue(() => {
3954
+ throw e;
3955
+ });
3956
+ }
3957
+ }
3958
+ });
3959
+ for (let t of [
3960
+ "getPlayer",
3961
+ "getPlayerList",
3962
+ "getScores",
3963
+ "getBallPosition",
3964
+ "getDiscCount",
3965
+ "getDiscProperties",
3966
+ "getPlayerDiscProperties",
3967
+ "getState",
3968
+ "startRecording",
3969
+ "stopRecording"
3970
+ ]) Object.defineProperty(n, t, {
3971
+ enumerable: !0,
3972
+ value: e[t].bind(e)
3973
+ });
3974
+ for (let t of [
3975
+ "roomId",
3976
+ "roomLink",
3977
+ "roomName",
3978
+ "lastRecording",
3979
+ "requireVerification",
3980
+ "CollisionFlags",
3981
+ "signal"
3982
+ ]) Object.defineProperty(n, t, {
3983
+ enumerable: !0,
3984
+ get: () => e[t]
3985
+ });
3986
+ for (let t of [
3987
+ "onRoomLink",
3988
+ "onPlayerJoin",
3989
+ "onPlayerLeave",
3990
+ "onPlayerChat",
3991
+ "onPlayerTeamChange",
3992
+ "onPlayerAdminChange",
3993
+ "onPlayerKicked",
3994
+ "onPlayerActivity",
3995
+ "onPlayerBallKick",
3996
+ "onTeamGoal",
3997
+ "onTeamVictory",
3998
+ "onGameVictory",
3999
+ "onGameStart",
4000
+ "onGameStop",
4001
+ "onGameTick",
4002
+ "onGamePause",
4003
+ "onGameUnpause",
4004
+ "onGamePauseChange",
4005
+ "onPositionsReset",
4006
+ "onStadiumChange",
4007
+ "onTeamsLockChange",
4008
+ "onKickRateLimitSet",
4009
+ "onRecordingComplete",
4010
+ "onError"
4011
+ ]) {
4012
+ let r;
4013
+ Object.defineProperty(n, t, {
4014
+ enumerable: !0,
4015
+ get: () => r,
4016
+ set: (i) => {
4017
+ if (i != null && typeof i != "function") throw Error("Callback must be a function");
4018
+ r = i, Reflect.set(e, t, i == null ? void 0 : (...e) => Reflect.apply(i, n, e));
4019
+ }
4020
+ });
4021
+ }
4022
+ return Object.defineProperty(n, "close", {
4023
+ enumerable: !0,
4024
+ value: () => {
4025
+ r.close(), e.close();
4026
+ }
4027
+ }), Object.preventExtensions(n);
4028
+ }
4029
+ //#endregion
4030
+ //#region src/sdk/replay.ts
4031
+ function vt(e) {
4032
+ return Qe(e);
4033
+ }
4034
+ //#endregion
4035
+ //#region src/sdk/stadium.ts
4036
+ function yt(e) {
4037
+ if (typeof e != "string") throw TypeError("Stadium source must be a string");
4038
+ let t = P(e);
4039
+ return Object.freeze({
4040
+ name: t.name,
4041
+ canBeStored: t.canBeStored,
4042
+ warnings: Object.freeze([...t.warnings])
4043
+ });
4044
+ }
4045
+ //#endregion
4046
+ //#region src/sdk/browser.ts
4047
+ async function bt(e = {}, t = {}) {
4048
+ return _t(await pt.create(mt(e), void 0, t.signal));
4049
+ }
4050
+ //#endregion
4051
+ export { bt as createRoom, vt as readReplay, yt as validateStadium };