@caperjs/plugin-colyseus 0.1.0

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.
@@ -0,0 +1,2370 @@
1
+ import { Logger as e, Plugin as t } from "@caperjs/core";
2
+ //#region \0rolldown/runtime.js
3
+ var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescriptor, a = Object.getOwnPropertyNames, o = Object.getPrototypeOf, s = Object.prototype.hasOwnProperty, c = (e, t) => () => (e && (t = e(e = 0)), t), l = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), u = (e, t) => {
4
+ let n = {};
5
+ for (var i in e) r(n, i, {
6
+ get: e[i],
7
+ enumerable: !0
8
+ });
9
+ return t || r(n, Symbol.toStringTag, { value: "Module" }), n;
10
+ }, d = (e, t, n, o) => {
11
+ if (t && typeof t == "object" || typeof t == "function") for (var c = a(t), l = 0, u = c.length, d; l < u; l++) d = c[l], !s.call(e, d) && d !== n && r(e, d, {
12
+ get: ((e) => t[e]).bind(null, d),
13
+ enumerable: !(o = i(t, d)) || o.enumerable
14
+ });
15
+ return e;
16
+ }, f = (e, t, i) => (i = e == null ? {} : n(o(e)), d(t || !e || !e.__esModule ? r(i, "default", {
17
+ value: e,
18
+ enumerable: !0
19
+ }) : i, e)), p = (e) => s.call(e, "module.exports") ? e["module.exports"] : d(r({}, "__esModule", { value: !0 }), e), m = /* @__PURE__ */ l((() => {
20
+ ArrayBuffer.isView || (ArrayBuffer.isView = (e) => typeof e == "object" && !!e && e.buffer instanceof ArrayBuffer), typeof globalThis > "u" && typeof window < "u" && (window.globalThis = window);
21
+ })), h = /* @__PURE__ */ l(((e) => {
22
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.ServerError = e.CloseCode = void 0, (function(e) {
23
+ e[e.CONSENTED = 4e3] = "CONSENTED", e[e.DEVMODE_RESTART = 4010] = "DEVMODE_RESTART";
24
+ })(e.CloseCode ||= {}), e.ServerError = class extends Error {
25
+ constructor(e, t) {
26
+ super(t), this.name = "ServerError", this.code = e;
27
+ }
28
+ };
29
+ })), g = /* @__PURE__ */ l(((e) => {
30
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.decode = e.encode = void 0;
31
+ function t(e, t) {
32
+ if (this._offset = t, e instanceof ArrayBuffer) this._buffer = e, this._view = new DataView(this._buffer);
33
+ else if (ArrayBuffer.isView(e)) this._buffer = e.buffer, this._view = new DataView(this._buffer, e.byteOffset, e.byteLength);
34
+ else throw Error("Invalid argument");
35
+ }
36
+ function n(e, t, n) {
37
+ for (var r = "", i = 0, a = t, o = t + n; a < o; a++) {
38
+ var s = e.getUint8(a);
39
+ if (!(s & 128)) {
40
+ r += String.fromCharCode(s);
41
+ continue;
42
+ }
43
+ if ((s & 224) == 192) {
44
+ r += String.fromCharCode((s & 31) << 6 | e.getUint8(++a) & 63);
45
+ continue;
46
+ }
47
+ if ((s & 240) == 224) {
48
+ r += String.fromCharCode((s & 15) << 12 | (e.getUint8(++a) & 63) << 6 | (e.getUint8(++a) & 63) << 0);
49
+ continue;
50
+ }
51
+ if ((s & 248) == 240) {
52
+ i = (s & 7) << 18 | (e.getUint8(++a) & 63) << 12 | (e.getUint8(++a) & 63) << 6 | (e.getUint8(++a) & 63) << 0, i >= 65536 ? (i -= 65536, r += String.fromCharCode((i >>> 10) + 55296, (i & 1023) + 56320)) : r += String.fromCharCode(i);
53
+ continue;
54
+ }
55
+ throw Error("Invalid byte " + s.toString(16));
56
+ }
57
+ return r;
58
+ }
59
+ t.prototype._array = function(e) {
60
+ for (var t = Array(e), n = 0; n < e; n++) t[n] = this._parse();
61
+ return t;
62
+ }, t.prototype._map = function(e) {
63
+ for (var t = "", n = {}, r = 0; r < e; r++) t = this._parse(), n[t] = this._parse();
64
+ return n;
65
+ }, t.prototype._str = function(e) {
66
+ var t = n(this._view, this._offset, e);
67
+ return this._offset += e, t;
68
+ }, t.prototype._bin = function(e) {
69
+ var t = this._buffer.slice(this._offset, this._offset + e);
70
+ return this._offset += e, t;
71
+ }, t.prototype._parse = function() {
72
+ var e = this._view.getUint8(this._offset++), t, n = 0, r = 0, i = 0, a = 0;
73
+ if (e < 192) return e < 128 ? e : e < 144 ? this._map(e & 15) : e < 160 ? this._array(e & 15) : this._str(e & 31);
74
+ if (e > 223) return (255 - e + 1) * -1;
75
+ switch (e) {
76
+ case 192: return null;
77
+ case 194: return !1;
78
+ case 195: return !0;
79
+ case 196: return n = this._view.getUint8(this._offset), this._offset += 1, this._bin(n);
80
+ case 197: return n = this._view.getUint16(this._offset), this._offset += 2, this._bin(n);
81
+ case 198: return n = this._view.getUint32(this._offset), this._offset += 4, this._bin(n);
82
+ case 199:
83
+ if (n = this._view.getUint8(this._offset), r = this._view.getInt8(this._offset + 1), this._offset += 2, r === -1) {
84
+ var o = this._view.getUint32(this._offset);
85
+ return i = this._view.getInt32(this._offset + 4), a = this._view.getUint32(this._offset + 8), this._offset += 12, /* @__PURE__ */ new Date((i * 4294967296 + a) * 1e3 + o / 1e6);
86
+ }
87
+ return [r, this._bin(n)];
88
+ case 200: return n = this._view.getUint16(this._offset), r = this._view.getInt8(this._offset + 2), this._offset += 3, [r, this._bin(n)];
89
+ case 201: return n = this._view.getUint32(this._offset), r = this._view.getInt8(this._offset + 4), this._offset += 5, [r, this._bin(n)];
90
+ case 202: return t = this._view.getFloat32(this._offset), this._offset += 4, t;
91
+ case 203: return t = this._view.getFloat64(this._offset), this._offset += 8, t;
92
+ case 204: return t = this._view.getUint8(this._offset), this._offset += 1, t;
93
+ case 205: return t = this._view.getUint16(this._offset), this._offset += 2, t;
94
+ case 206: return t = this._view.getUint32(this._offset), this._offset += 4, t;
95
+ case 207: return i = this._view.getUint32(this._offset) * 2 ** 32, a = this._view.getUint32(this._offset + 4), this._offset += 8, i + a;
96
+ case 208: return t = this._view.getInt8(this._offset), this._offset += 1, t;
97
+ case 209: return t = this._view.getInt16(this._offset), this._offset += 2, t;
98
+ case 210: return t = this._view.getInt32(this._offset), this._offset += 4, t;
99
+ case 211: return i = this._view.getInt32(this._offset) * 2 ** 32, a = this._view.getUint32(this._offset + 4), this._offset += 8, i + a;
100
+ case 212:
101
+ if (r = this._view.getInt8(this._offset), this._offset += 1, r === 0) {
102
+ this._offset += 1;
103
+ return;
104
+ }
105
+ return [r, this._bin(1)];
106
+ case 213: return r = this._view.getInt8(this._offset), this._offset += 1, [r, this._bin(2)];
107
+ case 214: return r = this._view.getInt8(this._offset), this._offset += 1, r === -1 ? (t = this._view.getUint32(this._offset), this._offset += 4, /* @__PURE__ */ new Date(t * 1e3)) : [r, this._bin(4)];
108
+ case 215:
109
+ if (r = this._view.getInt8(this._offset), this._offset += 1, r === 0) return i = this._view.getInt32(this._offset) * 2 ** 32, a = this._view.getUint32(this._offset + 4), this._offset += 8, new Date(i + a);
110
+ if (r === -1) {
111
+ i = this._view.getUint32(this._offset), a = this._view.getUint32(this._offset + 4), this._offset += 8;
112
+ var s = (i & 3) * 4294967296 + a;
113
+ return /* @__PURE__ */ new Date(s * 1e3 + (i >>> 2) / 1e6);
114
+ }
115
+ return [r, this._bin(8)];
116
+ case 216: return r = this._view.getInt8(this._offset), this._offset += 1, [r, this._bin(16)];
117
+ case 217: return n = this._view.getUint8(this._offset), this._offset += 1, this._str(n);
118
+ case 218: return n = this._view.getUint16(this._offset), this._offset += 2, this._str(n);
119
+ case 219: return n = this._view.getUint32(this._offset), this._offset += 4, this._str(n);
120
+ case 220: return n = this._view.getUint16(this._offset), this._offset += 2, this._array(n);
121
+ case 221: return n = this._view.getUint32(this._offset), this._offset += 4, this._array(n);
122
+ case 222: return n = this._view.getUint16(this._offset), this._offset += 2, this._map(n);
123
+ case 223: return n = this._view.getUint32(this._offset), this._offset += 4, this._map(n);
124
+ }
125
+ throw Error("Could not parse");
126
+ };
127
+ function r(e, n = 0) {
128
+ var r = new t(e, n), i = r._parse();
129
+ if (r._offset !== e.byteLength) throw Error(e.byteLength - r._offset + " trailing bytes");
130
+ return i;
131
+ }
132
+ e.decode = r;
133
+ var i = 4294967295, a = 17179869183;
134
+ function o(e, t, n) {
135
+ for (var r = 0, i = 0, a = n.length; i < a; i++) r = n.charCodeAt(i), r < 128 ? e.setUint8(t++, r) : r < 2048 ? (e.setUint8(t++, 192 | r >> 6), e.setUint8(t++, 128 | r & 63)) : r < 55296 || r >= 57344 ? (e.setUint8(t++, 224 | r >> 12), e.setUint8(t++, 128 | r >> 6 & 63), e.setUint8(t++, 128 | r & 63)) : (i++, r = 65536 + ((r & 1023) << 10 | n.charCodeAt(i) & 1023), e.setUint8(t++, 240 | r >> 18), e.setUint8(t++, 128 | r >> 12 & 63), e.setUint8(t++, 128 | r >> 6 & 63), e.setUint8(t++, 128 | r & 63));
136
+ }
137
+ function s(e) {
138
+ for (var t = 0, n = 0, r = 0, i = e.length; r < i; r++) t = e.charCodeAt(r), t < 128 ? n += 1 : t < 2048 ? n += 2 : t < 55296 || t >= 57344 ? n += 3 : (r++, n += 4);
139
+ return n;
140
+ }
141
+ function c(e, t, n) {
142
+ var r = typeof n, o = 0, l = 0, u = 0, d = 0, f = 0, p = 0;
143
+ if (r === "string") {
144
+ if (f = s(n), f < 32) e.push(f | 160), p = 1;
145
+ else if (f < 256) e.push(217, f), p = 2;
146
+ else if (f < 65536) e.push(218, f >> 8, f), p = 3;
147
+ else if (f < 4294967296) e.push(219, f >> 24, f >> 16, f >> 8, f), p = 5;
148
+ else throw Error("String too long");
149
+ return t.push({
150
+ _str: n,
151
+ _length: f,
152
+ _offset: e.length
153
+ }), p + f;
154
+ }
155
+ if (r === "number") return Math.floor(n) !== n || !isFinite(n) ? (e.push(203), t.push({
156
+ _float: n,
157
+ _length: 8,
158
+ _offset: e.length
159
+ }), 9) : n >= 0 ? n < 128 ? (e.push(n), 1) : n < 256 ? (e.push(204, n), 2) : n < 65536 ? (e.push(205, n >> 8, n), 3) : n < 4294967296 ? (e.push(206, n >> 24, n >> 16, n >> 8, n), 5) : (u = n / 2 ** 32 >> 0, d = n >>> 0, e.push(207, u >> 24, u >> 16, u >> 8, u, d >> 24, d >> 16, d >> 8, d), 9) : n >= -32 ? (e.push(n), 1) : n >= -128 ? (e.push(208, n), 2) : n >= -32768 ? (e.push(209, n >> 8, n), 3) : n >= -2147483648 ? (e.push(210, n >> 24, n >> 16, n >> 8, n), 5) : (u = Math.floor(n / 2 ** 32), d = n >>> 0, e.push(211, u >> 24, u >> 16, u >> 8, u, d >> 24, d >> 16, d >> 8, d), 9);
160
+ if (r === "object") {
161
+ if (n === null) return e.push(192), 1;
162
+ if (Array.isArray(n)) {
163
+ if (f = n.length, f < 16) e.push(f | 144), p = 1;
164
+ else if (f < 65536) e.push(220, f >> 8, f), p = 3;
165
+ else if (f < 4294967296) e.push(221, f >> 24, f >> 16, f >> 8, f), p = 5;
166
+ else throw Error("Array too large");
167
+ for (o = 0; o < f; o++) p += c(e, t, n[o]);
168
+ return p;
169
+ }
170
+ if (n instanceof Date) {
171
+ var m = n.getTime(), h = Math.floor(m / 1e3), g = (m - h * 1e3) * 1e6;
172
+ return h >= 0 && g >= 0 && h <= a ? g === 0 && h <= i ? (e.push(214, 255, h >> 24, h >> 16, h >> 8, h), 6) : (u = h / 4294967296, d = h & 4294967295, e.push(215, 255, g >> 22, g >> 14, g >> 6, u, d >> 24, d >> 16, d >> 8, d), 10) : (u = Math.floor(h / 4294967296), d = h >>> 0, e.push(199, 12, 255, g >> 24, g >> 16, g >> 8, g, u >> 24, u >> 16, u >> 8, u, d >> 24, d >> 16, d >> 8, d), 15);
173
+ }
174
+ if (n instanceof ArrayBuffer) {
175
+ if (f = n.byteLength, f < 256) e.push(196, f), p = 2;
176
+ else if (f < 65536) e.push(197, f >> 8, f), p = 3;
177
+ else if (f < 4294967296) e.push(198, f >> 24, f >> 16, f >> 8, f), p = 5;
178
+ else throw Error("Buffer too large");
179
+ return t.push({
180
+ _bin: n,
181
+ _length: f,
182
+ _offset: e.length
183
+ }), p + f;
184
+ }
185
+ if (typeof n.toJSON == "function") return c(e, t, n.toJSON());
186
+ var _ = [], v = "", y = Object.keys(n);
187
+ for (o = 0, l = y.length; o < l; o++) v = y[o], n[v] !== void 0 && typeof n[v] != "function" && _.push(v);
188
+ if (f = _.length, f < 16) e.push(f | 128), p = 1;
189
+ else if (f < 65536) e.push(222, f >> 8, f), p = 3;
190
+ else if (f < 4294967296) e.push(223, f >> 24, f >> 16, f >> 8, f), p = 5;
191
+ else throw Error("Object too large");
192
+ for (o = 0; o < f; o++) v = _[o], p += c(e, t, v), p += c(e, t, n[v]);
193
+ return p;
194
+ }
195
+ if (r === "boolean") return e.push(n ? 195 : 194), 1;
196
+ if (r === "undefined") return e.push(192), 1;
197
+ if (typeof n.toJSON == "function") return c(e, t, n.toJSON());
198
+ throw Error("Could not encode");
199
+ }
200
+ function l(e) {
201
+ var t = [], n = [], r = c(t, n, e), i = new ArrayBuffer(r), a = new DataView(i), s = 0, l = 0, u = -1;
202
+ n.length > 0 && (u = n[0]._offset);
203
+ for (var d, f = 0, p = 0, m = 0, h = t.length; m < h; m++) if (a.setUint8(l + m, t[m]), m + 1 === u) {
204
+ if (d = n[s], f = d._length, p = l + u, d._bin) for (var g = new Uint8Array(d._bin), _ = 0; _ < f; _++) a.setUint8(p + _, g[_]);
205
+ else d._str ? o(a, p, d._str) : d._float !== void 0 && a.setFloat64(p, d._float);
206
+ s++, l += f, n[s] && (u = n[s]._offset);
207
+ }
208
+ return i;
209
+ }
210
+ e.encode = l;
211
+ })), _ = /* @__PURE__ */ l(((e, t) => {
212
+ t.exports = function() {
213
+ throw Error("ws does not work in the browser. Browser clients must use the native WebSocket object");
214
+ };
215
+ })), v = /* @__PURE__ */ l(((e) => {
216
+ var t = e && e.__importDefault || function(e) {
217
+ return e && e.__esModule ? e : { default: e };
218
+ };
219
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.WebSocketTransport = void 0;
220
+ var n = t(_()), r = globalThis.WebSocket || n.default;
221
+ e.WebSocketTransport = class {
222
+ constructor(e) {
223
+ this.events = e;
224
+ }
225
+ send(e) {
226
+ e instanceof ArrayBuffer ? this.ws.send(e) : Array.isArray(e) && this.ws.send(new Uint8Array(e).buffer);
227
+ }
228
+ connect(e, t) {
229
+ try {
230
+ this.ws = new r(e, {
231
+ headers: t,
232
+ protocols: this.protocols
233
+ });
234
+ } catch {
235
+ this.ws = new r(e, this.protocols);
236
+ }
237
+ this.ws.binaryType = "arraybuffer", this.ws.onopen = this.events.onopen, this.ws.onmessage = this.events.onmessage, this.ws.onclose = this.events.onclose, this.ws.onerror = this.events.onerror;
238
+ }
239
+ close(e, t) {
240
+ this.ws.close(e, t);
241
+ }
242
+ get isOpen() {
243
+ return this.ws.readyState === r.OPEN;
244
+ }
245
+ };
246
+ })), y = /* @__PURE__ */ l(((e) => {
247
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Connection = void 0;
248
+ var t = v();
249
+ e.Connection = class {
250
+ constructor() {
251
+ this.events = {}, this.transport = new t.WebSocketTransport(this.events);
252
+ }
253
+ send(e) {
254
+ this.transport.send(e);
255
+ }
256
+ connect(e, t) {
257
+ this.transport.connect(e, t);
258
+ }
259
+ close(e, t) {
260
+ this.transport.close(e, t);
261
+ }
262
+ get isOpen() {
263
+ return this.transport.isOpen;
264
+ }
265
+ };
266
+ })), b = /* @__PURE__ */ l(((e) => {
267
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.utf8Length = e.utf8Read = e.ErrorCode = e.Protocol = void 0, (function(e) {
268
+ e[e.HANDSHAKE = 9] = "HANDSHAKE", e[e.JOIN_ROOM = 10] = "JOIN_ROOM", e[e.ERROR = 11] = "ERROR", e[e.LEAVE_ROOM = 12] = "LEAVE_ROOM", e[e.ROOM_DATA = 13] = "ROOM_DATA", e[e.ROOM_STATE = 14] = "ROOM_STATE", e[e.ROOM_STATE_PATCH = 15] = "ROOM_STATE_PATCH", e[e.ROOM_DATA_SCHEMA = 16] = "ROOM_DATA_SCHEMA", e[e.ROOM_DATA_BYTES = 17] = "ROOM_DATA_BYTES";
269
+ })(e.Protocol ||= {}), (function(e) {
270
+ e[e.MATCHMAKE_NO_HANDLER = 4210] = "MATCHMAKE_NO_HANDLER", e[e.MATCHMAKE_INVALID_CRITERIA = 4211] = "MATCHMAKE_INVALID_CRITERIA", e[e.MATCHMAKE_INVALID_ROOM_ID = 4212] = "MATCHMAKE_INVALID_ROOM_ID", e[e.MATCHMAKE_UNHANDLED = 4213] = "MATCHMAKE_UNHANDLED", e[e.MATCHMAKE_EXPIRED = 4214] = "MATCHMAKE_EXPIRED", e[e.AUTH_FAILED = 4215] = "AUTH_FAILED", e[e.APPLICATION_ERROR = 4216] = "APPLICATION_ERROR";
271
+ })(e.ErrorCode ||= {});
272
+ function t(e, t) {
273
+ let n = e[t++];
274
+ for (var r = "", i = 0, a = t, o = t + n; a < o; a++) {
275
+ var s = e[a];
276
+ if (!(s & 128)) {
277
+ r += String.fromCharCode(s);
278
+ continue;
279
+ }
280
+ if ((s & 224) == 192) {
281
+ r += String.fromCharCode((s & 31) << 6 | e[++a] & 63);
282
+ continue;
283
+ }
284
+ if ((s & 240) == 224) {
285
+ r += String.fromCharCode((s & 15) << 12 | (e[++a] & 63) << 6 | (e[++a] & 63) << 0);
286
+ continue;
287
+ }
288
+ if ((s & 248) == 240) {
289
+ i = (s & 7) << 18 | (e[++a] & 63) << 12 | (e[++a] & 63) << 6 | (e[++a] & 63) << 0, i >= 65536 ? (i -= 65536, r += String.fromCharCode((i >>> 10) + 55296, (i & 1023) + 56320)) : r += String.fromCharCode(i);
290
+ continue;
291
+ }
292
+ throw Error("Invalid byte " + s.toString(16));
293
+ }
294
+ return r;
295
+ }
296
+ e.utf8Read = t;
297
+ function n(e = "") {
298
+ let t = 0, n = 0;
299
+ for (let r = 0, i = e.length; r < i; r++) t = e.charCodeAt(r), t < 128 ? n += 1 : t < 2048 ? n += 2 : t < 55296 || t >= 57344 ? n += 3 : (r++, n += 4);
300
+ return n + 1;
301
+ }
302
+ e.utf8Length = n;
303
+ })), x = /* @__PURE__ */ l(((e) => {
304
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.getSerializer = e.registerSerializer = void 0;
305
+ var t = {};
306
+ function n(e, n) {
307
+ t[e] = n;
308
+ }
309
+ e.registerSerializer = n;
310
+ function r(e) {
311
+ let n = t[e];
312
+ if (!n) throw Error("missing serializer: " + e);
313
+ return n;
314
+ }
315
+ e.getSerializer = r;
316
+ })), S = /* @__PURE__ */ l(((e) => {
317
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.createNanoEvents = void 0, e.createNanoEvents = () => ({
318
+ emit(e, ...t) {
319
+ let n = this.events[e] || [];
320
+ for (let e = 0, r = n.length; e < r; e++) n[e](...t);
321
+ },
322
+ events: {},
323
+ on(e, t) {
324
+ var n;
325
+ return (n = this.events[e]) != null && n.push(t) || (this.events[e] = [t]), () => {
326
+ this.events[e] = this.events[e]?.filter((e) => t !== e);
327
+ };
328
+ }
329
+ });
330
+ })), C = /* @__PURE__ */ l(((e) => {
331
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.createSignal = e.EventEmitter = void 0;
332
+ var t = class {
333
+ constructor() {
334
+ this.handlers = [];
335
+ }
336
+ register(e, t = !1) {
337
+ return this.handlers.push(e), this;
338
+ }
339
+ invoke(...e) {
340
+ this.handlers.forEach((t) => t.apply(this, e));
341
+ }
342
+ invokeAsync(...e) {
343
+ return Promise.all(this.handlers.map((t) => t.apply(this, e)));
344
+ }
345
+ remove(e) {
346
+ let t = this.handlers.indexOf(e);
347
+ this.handlers[t] = this.handlers[this.handlers.length - 1], this.handlers.pop();
348
+ }
349
+ clear() {
350
+ this.handlers = [];
351
+ }
352
+ };
353
+ e.EventEmitter = t;
354
+ function n() {
355
+ let e = new t();
356
+ function n(t) {
357
+ return e.register(t, this === null);
358
+ }
359
+ return n.once = (t) => {
360
+ let n = function(...r) {
361
+ t.apply(this, r), e.remove(n);
362
+ };
363
+ e.register(n);
364
+ }, n.remove = (t) => e.remove(t), n.invoke = (...t) => e.invoke(...t), n.invokeAsync = (...t) => e.invokeAsync(...t), n.clear = () => e.clear(), n;
365
+ }
366
+ e.createSignal = n;
367
+ })), w = /* @__PURE__ */ l(((e, t) => {
368
+ (function(n, r) {
369
+ typeof e == "object" && t !== void 0 ? r(e) : typeof define == "function" && define.amd ? define(["exports"], r) : (n = typeof globalThis < "u" ? globalThis : n || self, r(n.schema = {}));
370
+ })(e, (function(e) {
371
+ var t = function(e, n) {
372
+ return t = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, t) {
373
+ e.__proto__ = t;
374
+ } || function(e, t) {
375
+ for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
376
+ }, t(e, n);
377
+ };
378
+ function n(e, n) {
379
+ if (typeof n != "function" && n !== null) throw TypeError("Class extends value " + String(n) + " is not a constructor or null");
380
+ t(e, n);
381
+ function r() {
382
+ this.constructor = e;
383
+ }
384
+ e.prototype = n === null ? Object.create(n) : (r.prototype = n.prototype, new r());
385
+ }
386
+ function r(e, t, n, r) {
387
+ var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
388
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
389
+ else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
390
+ return i > 3 && a && Object.defineProperty(t, n, a), a;
391
+ }
392
+ function i(e, t, n) {
393
+ if (n || arguments.length === 2) for (var r = 0, i = t.length, a; r < i; r++) (a || !(r in t)) && (a ||= Array.prototype.slice.call(t, 0, r), a[r] = t[r]);
394
+ return e.concat(a || Array.prototype.slice.call(t));
395
+ }
396
+ var a = 255, o = 213;
397
+ e.OPERATION = void 0, (function(e) {
398
+ e[e.ADD = 128] = "ADD", e[e.REPLACE = 0] = "REPLACE", e[e.DELETE = 64] = "DELETE", e[e.DELETE_AND_ADD = 192] = "DELETE_AND_ADD", e[e.TOUCH = 1] = "TOUCH", e[e.CLEAR = 10] = "CLEAR";
399
+ })(e.OPERATION ||= {});
400
+ var s = function() {
401
+ function t(e, t, n) {
402
+ this.changed = !1, this.changes = /* @__PURE__ */ new Map(), this.allChanges = /* @__PURE__ */ new Set(), this.caches = {}, this.currentCustomOperation = 0, this.ref = e, this.setParent(t, n);
403
+ }
404
+ return t.prototype.setParent = function(e, t, n) {
405
+ var r = this;
406
+ if (this.indexes ||= this.ref instanceof Q ? this.ref._definition.indexes : {}, this.parent = e, this.parentIndex = n, t) if (this.root = t, this.ref instanceof Q) {
407
+ var i = this.ref._definition;
408
+ for (var a in i.schema) {
409
+ var o = this.ref[a];
410
+ if (o && o.$changes) {
411
+ var s = i.indexes[a];
412
+ o.$changes.setParent(this.ref, t, s);
413
+ }
414
+ }
415
+ } else typeof this.ref == "object" && this.ref.forEach(function(e, t) {
416
+ if (e instanceof Q) {
417
+ var n = e.$changes, i = r.ref.$changes.indexes[t];
418
+ n.setParent(r.ref, r.root, i);
419
+ }
420
+ });
421
+ }, t.prototype.operation = function(e) {
422
+ this.changes.set(--this.currentCustomOperation, e);
423
+ }, t.prototype.change = function(t, n) {
424
+ n === void 0 && (n = e.OPERATION.ADD);
425
+ var r = typeof t == "number" ? t : this.indexes[t];
426
+ this.assertValidIndex(r, t);
427
+ var i = this.changes.get(r);
428
+ (!i || i.op === e.OPERATION.DELETE || i.op === e.OPERATION.TOUCH) && this.changes.set(r, {
429
+ op: i && i.op === e.OPERATION.DELETE ? e.OPERATION.DELETE_AND_ADD : n,
430
+ index: r
431
+ }), this.allChanges.add(r), this.changed = !0, this.touchParents();
432
+ }, t.prototype.touch = function(t) {
433
+ var n = typeof t == "number" ? t : this.indexes[t];
434
+ this.assertValidIndex(n, t), this.changes.has(n) || this.changes.set(n, {
435
+ op: e.OPERATION.TOUCH,
436
+ index: n
437
+ }), this.allChanges.add(n), this.touchParents();
438
+ }, t.prototype.touchParents = function() {
439
+ this.parent && this.parent.$changes.touch(this.parentIndex);
440
+ }, t.prototype.getType = function(e) {
441
+ if (this.ref._definition) {
442
+ var t = this.ref._definition;
443
+ return t.schema[t.fieldsByIndex[e]];
444
+ } else {
445
+ var t = this.parent._definition, n = t.schema[t.fieldsByIndex[this.parentIndex]];
446
+ return Object.values(n)[0];
447
+ }
448
+ }, t.prototype.getChildrenFilter = function() {
449
+ var e = this.parent._definition.childFilters;
450
+ return e && e[this.parentIndex];
451
+ }, t.prototype.getValue = function(e) {
452
+ return this.ref.getByIndex(e);
453
+ }, t.prototype.delete = function(t) {
454
+ var n = typeof t == "number" ? t : this.indexes[t];
455
+ if (n === void 0) {
456
+ console.warn(`@colyseus/schema ${this.ref.constructor.name}: trying to delete non-existing index: ${t} (${n})`);
457
+ return;
458
+ }
459
+ var r = this.getValue(n);
460
+ this.changes.set(n, {
461
+ op: e.OPERATION.DELETE,
462
+ index: n
463
+ }), this.allChanges.delete(n), delete this.caches[n], r && r.$changes && (r.$changes.parent = void 0), this.changed = !0, this.touchParents();
464
+ }, t.prototype.discard = function(t, n) {
465
+ var r = this;
466
+ t === void 0 && (t = !1), n === void 0 && (n = !1), this.ref instanceof Q || this.changes.forEach(function(t) {
467
+ if (t.op === e.OPERATION.DELETE) {
468
+ var n = r.ref.getIndex(t.index);
469
+ delete r.indexes[n];
470
+ }
471
+ }), this.changes.clear(), this.changed = t, n && this.allChanges.clear(), this.currentCustomOperation = 0;
472
+ }, t.prototype.discardAll = function() {
473
+ var e = this;
474
+ this.changes.forEach(function(t) {
475
+ var n = e.getValue(t.index);
476
+ n && n.$changes && n.$changes.discardAll();
477
+ }), this.discard();
478
+ }, t.prototype.cache = function(e, t) {
479
+ this.caches[e] = t;
480
+ }, t.prototype.clone = function() {
481
+ return new t(this.ref, this.parent, this.root);
482
+ }, t.prototype.ensureRefId = function() {
483
+ this.refId === void 0 && (this.refId = this.root.getNextUniqueId());
484
+ }, t.prototype.assertValidIndex = function(e, t) {
485
+ if (e === void 0) throw Error(`ChangeTree: missing index for field "${t}"`);
486
+ }, t;
487
+ }();
488
+ function c(e, t, n, r) {
489
+ return e[t] || (e[t] = []), e[t].push(n), r?.forEach(function(e, t) {
490
+ return n(e, t);
491
+ }), function() {
492
+ return u(e[t], e[t].indexOf(n));
493
+ };
494
+ }
495
+ function l(t) {
496
+ var n = this, r = typeof this.$changes.getType() != "string";
497
+ this.$items.forEach(function(i, a) {
498
+ t.push({
499
+ refId: n.$changes.refId,
500
+ op: e.OPERATION.DELETE,
501
+ field: a,
502
+ value: void 0,
503
+ previousValue: i
504
+ }), r && n.$changes.root.removeRef(i.$changes.refId);
505
+ });
506
+ }
507
+ function u(e, t) {
508
+ if (t === -1 || t >= e.length) return !1;
509
+ for (var n = e.length - 1, r = t; r < n; r++) e[r] = e[r + 1];
510
+ return e.length = n, !0;
511
+ }
512
+ var d = function(e, t) {
513
+ var n = e.toString(), r = t.toString();
514
+ return n < r ? -1 : +(n > r);
515
+ };
516
+ function f(e) {
517
+ return e.$proxy = !0, e = new Proxy(e, {
518
+ get: function(e, t) {
519
+ return typeof t != "symbol" && !isNaN(t) ? e.at(t) : e[t];
520
+ },
521
+ set: function(e, t, n) {
522
+ if (typeof t != "symbol" && !isNaN(t)) {
523
+ var r = Array.from(e.$items.keys()), i = parseInt(r[t] || t);
524
+ n == null ? e.deleteAt(i) : e.setAt(i, n);
525
+ } else e[t] = n;
526
+ return !0;
527
+ },
528
+ deleteProperty: function(e, t) {
529
+ return typeof t == "number" ? e.deleteAt(t) : delete e[t], !0;
530
+ },
531
+ has: function(e, t) {
532
+ return typeof t != "symbol" && !isNaN(Number(t)) ? e.$items.has(Number(t)) : Reflect.has(e, t);
533
+ }
534
+ }), e;
535
+ }
536
+ var p = function() {
537
+ function t() {
538
+ var e = [...arguments];
539
+ this.$changes = new s(this), this.$items = /* @__PURE__ */ new Map(), this.$indexes = /* @__PURE__ */ new Map(), this.$refId = 0, this.push.apply(this, e);
540
+ }
541
+ return t.prototype.onAdd = function(t, n) {
542
+ return n === void 0 && (n = !0), c(this.$callbacks ||= {}, e.OPERATION.ADD, t, n ? this.$items : void 0);
543
+ }, t.prototype.onRemove = function(t) {
544
+ return c(this.$callbacks ||= {}, e.OPERATION.DELETE, t);
545
+ }, t.prototype.onChange = function(t) {
546
+ return c(this.$callbacks ||= {}, e.OPERATION.REPLACE, t);
547
+ }, t.is = function(e) {
548
+ return Array.isArray(e) || e.array !== void 0;
549
+ }, Object.defineProperty(t.prototype, "length", {
550
+ get: function() {
551
+ return this.$items.size;
552
+ },
553
+ set: function(e) {
554
+ e === 0 ? this.clear() : this.splice(e, this.length - e);
555
+ },
556
+ enumerable: !1,
557
+ configurable: !0
558
+ }), t.prototype.push = function() {
559
+ for (var e = this, t = [], n = 0; n < arguments.length; n++) t[n] = arguments[n];
560
+ var r;
561
+ return t.forEach(function(t) {
562
+ r = e.$refId++, e.setAt(r, t);
563
+ }), r;
564
+ }, t.prototype.pop = function() {
565
+ var e = Array.from(this.$indexes.values()).pop();
566
+ if (e !== void 0) {
567
+ this.$changes.delete(e), this.$indexes.delete(e);
568
+ var t = this.$items.get(e);
569
+ return this.$items.delete(e), t;
570
+ }
571
+ }, t.prototype.at = function(e) {
572
+ if (e = Math.trunc(e) || 0, e < 0 && (e += this.length), !(e < 0 || e >= this.length)) {
573
+ var t = Array.from(this.$items.keys())[e];
574
+ return this.$items.get(t);
575
+ }
576
+ }, t.prototype.setAt = function(t, n) {
577
+ if (n == null) {
578
+ console.error("ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.");
579
+ return;
580
+ }
581
+ if (this.$items.get(t) !== n) {
582
+ n.$changes !== void 0 && n.$changes.setParent(this, this.$changes.root, t);
583
+ var r = this.$changes.indexes[t]?.op ?? e.OPERATION.ADD;
584
+ this.$changes.indexes[t] = t, this.$indexes.set(t, t), this.$items.set(t, n), this.$changes.change(t, r);
585
+ }
586
+ }, t.prototype.deleteAt = function(e) {
587
+ var t = Array.from(this.$items.keys())[e];
588
+ return t === void 0 ? !1 : this.$deleteAt(t);
589
+ }, t.prototype.$deleteAt = function(e) {
590
+ return this.$changes.delete(e), this.$indexes.delete(e), this.$items.delete(e);
591
+ }, t.prototype.clear = function(t) {
592
+ this.$changes.discard(!0, !0), this.$changes.indexes = {}, this.$indexes.clear(), t && l.call(this, t), this.$items.clear(), this.$changes.operation({
593
+ index: 0,
594
+ op: e.OPERATION.CLEAR
595
+ }), this.$changes.touchParents();
596
+ }, t.prototype.concat = function() {
597
+ for (var e, n = [], r = 0; r < arguments.length; r++) n[r] = arguments[r];
598
+ return new (t.bind.apply(t, i([void 0], (e = Array.from(this.$items.values())).concat.apply(e, n), !1)))();
599
+ }, t.prototype.join = function(e) {
600
+ return Array.from(this.$items.values()).join(e);
601
+ }, t.prototype.reverse = function() {
602
+ var e = this, t = Array.from(this.$items.keys());
603
+ return Array.from(this.$items.values()).reverse().forEach(function(n, r) {
604
+ e.setAt(t[r], n);
605
+ }), this;
606
+ }, t.prototype.shift = function() {
607
+ var e = Array.from(this.$items.keys()).shift();
608
+ if (e !== void 0) {
609
+ var t = this.$items.get(e);
610
+ return this.$deleteAt(e), t;
611
+ }
612
+ }, t.prototype.slice = function(e, n) {
613
+ var r = new t();
614
+ return r.push.apply(r, Array.from(this.$items.values()).slice(e, n)), r;
615
+ }, t.prototype.sort = function(e) {
616
+ var t = this;
617
+ e === void 0 && (e = d);
618
+ var n = Array.from(this.$items.keys());
619
+ return Array.from(this.$items.values()).sort(e).forEach(function(e, r) {
620
+ t.setAt(n[r], e);
621
+ }), this;
622
+ }, t.prototype.splice = function(e, t) {
623
+ t === void 0 && (t = this.length - e);
624
+ for (var n = [...arguments].slice(2), r = Array.from(this.$items.keys()), i = [], a = e; a < e + t; a++) i.push(this.$items.get(r[a])), this.$deleteAt(r[a]);
625
+ for (var a = 0; a < n.length; a++) this.setAt(e + a, n[a]);
626
+ return i;
627
+ }, t.prototype.unshift = function() {
628
+ for (var e = this, t = [], n = 0; n < arguments.length; n++) t[n] = arguments[n];
629
+ var r = this.length, i = t.length, a = Array.from(this.$items.values());
630
+ return t.forEach(function(t, n) {
631
+ e.setAt(n, t);
632
+ }), a.forEach(function(t, n) {
633
+ e.setAt(i + n, t);
634
+ }), r + i;
635
+ }, t.prototype.indexOf = function(e, t) {
636
+ return Array.from(this.$items.values()).indexOf(e, t);
637
+ }, t.prototype.lastIndexOf = function(e, t) {
638
+ return t === void 0 && (t = this.length - 1), Array.from(this.$items.values()).lastIndexOf(e, t);
639
+ }, t.prototype.every = function(e, t) {
640
+ return Array.from(this.$items.values()).every(e, t);
641
+ }, t.prototype.some = function(e, t) {
642
+ return Array.from(this.$items.values()).some(e, t);
643
+ }, t.prototype.forEach = function(e, t) {
644
+ Array.from(this.$items.values()).forEach(e, t);
645
+ }, t.prototype.map = function(e, t) {
646
+ return Array.from(this.$items.values()).map(e, t);
647
+ }, t.prototype.filter = function(e, t) {
648
+ return Array.from(this.$items.values()).filter(e, t);
649
+ }, t.prototype.reduce = function(e, t) {
650
+ return Array.prototype.reduce.apply(Array.from(this.$items.values()), arguments);
651
+ }, t.prototype.reduceRight = function(e, t) {
652
+ return Array.prototype.reduceRight.apply(Array.from(this.$items.values()), arguments);
653
+ }, t.prototype.find = function(e, t) {
654
+ return Array.from(this.$items.values()).find(e, t);
655
+ }, t.prototype.findIndex = function(e, t) {
656
+ return Array.from(this.$items.values()).findIndex(e, t);
657
+ }, t.prototype.fill = function(e, t, n) {
658
+ throw Error("ArraySchema#fill() not implemented");
659
+ }, t.prototype.copyWithin = function(e, t, n) {
660
+ throw Error("ArraySchema#copyWithin() not implemented");
661
+ }, t.prototype.toString = function() {
662
+ return this.$items.toString();
663
+ }, t.prototype.toLocaleString = function() {
664
+ return this.$items.toLocaleString();
665
+ }, t.prototype[Symbol.iterator] = function() {
666
+ return Array.from(this.$items.values())[Symbol.iterator]();
667
+ }, Object.defineProperty(t, Symbol.species, {
668
+ get: function() {
669
+ return t;
670
+ },
671
+ enumerable: !1,
672
+ configurable: !0
673
+ }), t.prototype.entries = function() {
674
+ return this.$items.entries();
675
+ }, t.prototype.keys = function() {
676
+ return this.$items.keys();
677
+ }, t.prototype.values = function() {
678
+ return this.$items.values();
679
+ }, t.prototype.includes = function(e, t) {
680
+ return Array.from(this.$items.values()).includes(e, t);
681
+ }, t.prototype.flatMap = function(e, t) {
682
+ throw Error("ArraySchema#flatMap() is not supported.");
683
+ }, t.prototype.flat = function(e) {
684
+ throw Error("ArraySchema#flat() is not supported.");
685
+ }, t.prototype.findLast = function() {
686
+ var e = Array.from(this.$items.values());
687
+ return e.findLast.apply(e, arguments);
688
+ }, t.prototype.findLastIndex = function() {
689
+ var e = Array.from(this.$items.values());
690
+ return e.findLastIndex.apply(e, arguments);
691
+ }, t.prototype.with = function(e, n) {
692
+ var r = Array.from(this.$items.values());
693
+ return r[e] = n, new (t.bind.apply(t, i([void 0], r, !1)))();
694
+ }, t.prototype.toReversed = function() {
695
+ return Array.from(this.$items.values()).reverse();
696
+ }, t.prototype.toSorted = function(e) {
697
+ return Array.from(this.$items.values()).sort(e);
698
+ }, t.prototype.toSpliced = function(e, t) {
699
+ var n = Array.from(this.$items.values());
700
+ return n.toSpliced.apply(n, arguments);
701
+ }, t.prototype.setIndex = function(e, t) {
702
+ this.$indexes.set(e, t);
703
+ }, t.prototype.getIndex = function(e) {
704
+ return this.$indexes.get(e);
705
+ }, t.prototype.getByIndex = function(e) {
706
+ return this.$items.get(this.$indexes.get(e));
707
+ }, t.prototype.deleteByIndex = function(e) {
708
+ var t = this.$indexes.get(e);
709
+ this.$items.delete(t), this.$indexes.delete(e);
710
+ }, t.prototype.toArray = function() {
711
+ return Array.from(this.$items.values());
712
+ }, t.prototype.toJSON = function() {
713
+ return this.toArray().map(function(e) {
714
+ return typeof e.toJSON == "function" ? e.toJSON() : e;
715
+ });
716
+ }, t.prototype.clone = function(e) {
717
+ return e ? new (t.bind.apply(t, i([void 0], Array.from(this.$items.values()), !1)))() : new (t.bind.apply(t, i([void 0], this.map(function(e) {
718
+ return e.$changes ? e.clone() : e;
719
+ }), !1)))();
720
+ }, t;
721
+ }();
722
+ function m(e) {
723
+ return e.$proxy = !0, e = new Proxy(e, {
724
+ get: function(e, t) {
725
+ return typeof t != "symbol" && e[t] === void 0 ? e.get(t) : e[t];
726
+ },
727
+ set: function(e, t, n) {
728
+ return typeof t != "symbol" && t.indexOf("$") === -1 && t !== "onAdd" && t !== "onRemove" && t !== "onChange" ? e.set(t, n) : e[t] = n, !0;
729
+ },
730
+ deleteProperty: function(e, t) {
731
+ return e.delete(t), !0;
732
+ }
733
+ }), e;
734
+ }
735
+ var h = function() {
736
+ function t(e) {
737
+ var n = this;
738
+ if (this.$changes = new s(this), this.$items = /* @__PURE__ */ new Map(), this.$indexes = /* @__PURE__ */ new Map(), this.$refId = 0, e) if (e instanceof Map || e instanceof t) e.forEach(function(e, t) {
739
+ return n.set(t, e);
740
+ });
741
+ else for (var r in e) this.set(r, e[r]);
742
+ }
743
+ return t.prototype.onAdd = function(t, n) {
744
+ return n === void 0 && (n = !0), c(this.$callbacks ||= {}, e.OPERATION.ADD, t, n ? this.$items : void 0);
745
+ }, t.prototype.onRemove = function(t) {
746
+ return c(this.$callbacks ||= {}, e.OPERATION.DELETE, t);
747
+ }, t.prototype.onChange = function(t) {
748
+ return c(this.$callbacks ||= {}, e.OPERATION.REPLACE, t);
749
+ }, t.is = function(e) {
750
+ return e.map !== void 0;
751
+ }, t.prototype[Symbol.iterator] = function() {
752
+ return this.$items[Symbol.iterator]();
753
+ }, Object.defineProperty(t.prototype, Symbol.toStringTag, {
754
+ get: function() {
755
+ return this.$items[Symbol.toStringTag];
756
+ },
757
+ enumerable: !1,
758
+ configurable: !0
759
+ }), Object.defineProperty(t, Symbol.species, {
760
+ get: function() {
761
+ return t;
762
+ },
763
+ enumerable: !1,
764
+ configurable: !0
765
+ }), t.prototype.set = function(t, n) {
766
+ if (n == null) throw Error(`MapSchema#set('${t}', ${n}): trying to set ${n} value on '${t}'.`);
767
+ t = t.toString();
768
+ var r = this.$changes.indexes[t] !== void 0, i = r ? this.$changes.indexes[t] : this.$refId++, a = r ? e.OPERATION.REPLACE : e.OPERATION.ADD, o = n.$changes !== void 0;
769
+ if (o && n.$changes.setParent(this, this.$changes.root, i), !r) this.$changes.indexes[t] = i, this.$indexes.set(i, t);
770
+ else if (!o && this.$items.get(t) === n) return;
771
+ else o && this.$items.get(t) !== n && (a = e.OPERATION.ADD);
772
+ return this.$items.set(t, n), this.$changes.change(t, a), this;
773
+ }, t.prototype.get = function(e) {
774
+ return this.$items.get(e);
775
+ }, t.prototype.delete = function(e) {
776
+ return this.$changes.delete(e.toString()), this.$items.delete(e);
777
+ }, t.prototype.clear = function(t) {
778
+ this.$changes.discard(!0, !0), this.$changes.indexes = {}, this.$indexes.clear(), t && l.call(this, t), this.$items.clear(), this.$changes.operation({
779
+ index: 0,
780
+ op: e.OPERATION.CLEAR
781
+ }), this.$changes.touchParents();
782
+ }, t.prototype.has = function(e) {
783
+ return this.$items.has(e);
784
+ }, t.prototype.forEach = function(e) {
785
+ this.$items.forEach(e);
786
+ }, t.prototype.entries = function() {
787
+ return this.$items.entries();
788
+ }, t.prototype.keys = function() {
789
+ return this.$items.keys();
790
+ }, t.prototype.values = function() {
791
+ return this.$items.values();
792
+ }, Object.defineProperty(t.prototype, "size", {
793
+ get: function() {
794
+ return this.$items.size;
795
+ },
796
+ enumerable: !1,
797
+ configurable: !0
798
+ }), t.prototype.setIndex = function(e, t) {
799
+ this.$indexes.set(e, t);
800
+ }, t.prototype.getIndex = function(e) {
801
+ return this.$indexes.get(e);
802
+ }, t.prototype.getByIndex = function(e) {
803
+ return this.$items.get(this.$indexes.get(e));
804
+ }, t.prototype.deleteByIndex = function(e) {
805
+ var t = this.$indexes.get(e);
806
+ this.$items.delete(t), this.$indexes.delete(e);
807
+ }, t.prototype.toJSON = function() {
808
+ var e = {};
809
+ return this.forEach(function(t, n) {
810
+ e[n] = typeof t.toJSON == "function" ? t.toJSON() : t;
811
+ }), e;
812
+ }, t.prototype.clone = function(e) {
813
+ var n;
814
+ return e ? n = Object.assign(new t(), this) : (n = new t(), this.forEach(function(e, t) {
815
+ e.$changes ? n.set(t, e.clone()) : n.set(t, e);
816
+ })), n;
817
+ }, t;
818
+ }(), g = {};
819
+ function _(e, t) {
820
+ g[e] = t;
821
+ }
822
+ function v(e) {
823
+ return g[e];
824
+ }
825
+ var y = function() {
826
+ function e() {
827
+ this.indexes = {}, this.fieldsByIndex = {}, this.deprecated = {}, this.descriptors = {};
828
+ }
829
+ return e.create = function(t) {
830
+ var n = new e();
831
+ return n.schema = Object.assign({}, t && t.schema || {}), n.indexes = Object.assign({}, t && t.indexes || {}), n.fieldsByIndex = Object.assign({}, t && t.fieldsByIndex || {}), n.descriptors = Object.assign({}, t && t.descriptors || {}), n.deprecated = Object.assign({}, t && t.deprecated || {}), n;
832
+ }, e.prototype.addField = function(e, t) {
833
+ var n = this.getNextFieldIndex();
834
+ this.fieldsByIndex[n] = e, this.indexes[e] = n, this.schema[e] = Array.isArray(t) ? { array: t[0] } : t;
835
+ }, e.prototype.hasField = function(e) {
836
+ return this.indexes[e] !== void 0;
837
+ }, e.prototype.addFilter = function(e, t) {
838
+ return this.filters || (this.filters = {}, this.indexesWithFilters = []), this.filters[this.indexes[e]] = t, this.indexesWithFilters.push(this.indexes[e]), !0;
839
+ }, e.prototype.addChildrenFilter = function(e, t) {
840
+ var n = this.indexes[e], r = this.schema[e];
841
+ if (v(Object.keys(r)[0])) return this.childFilters ||= {}, this.childFilters[n] = t, !0;
842
+ console.warn(`@filterChildren: field '${e}' can't have children. Ignoring filter.`);
843
+ }, e.prototype.getChildrenFilter = function(e) {
844
+ return this.childFilters && this.childFilters[this.indexes[e]];
845
+ }, e.prototype.getNextFieldIndex = function() {
846
+ return Object.keys(this.schema || {}).length;
847
+ }, e;
848
+ }();
849
+ function b(e) {
850
+ return e._context && e._context.useFilters;
851
+ }
852
+ var x = function() {
853
+ function e() {
854
+ this.types = {}, this.schemas = /* @__PURE__ */ new Map(), this.useFilters = !1;
855
+ }
856
+ return e.prototype.has = function(e) {
857
+ return this.schemas.has(e);
858
+ }, e.prototype.get = function(e) {
859
+ return this.types[e];
860
+ }, e.prototype.add = function(e, t) {
861
+ t === void 0 && (t = this.schemas.size), e._definition = y.create(e._definition), e._typeid = t, this.types[t] = e, this.schemas.set(e, t);
862
+ }, e.create = function(t) {
863
+ return t === void 0 && (t = {}), function(n) {
864
+ return t.context ||= new e(), C(n, t);
865
+ };
866
+ }, e;
867
+ }(), S = new x();
868
+ function C(e, t) {
869
+ return t === void 0 && (t = {}), function(n, r) {
870
+ var a = t.context || S, o = n.constructor;
871
+ if (o._context = a, !e) throw Error(`${o.name}: @type() reference provided for "${r}" is undefined. Make sure you don't have any circular dependencies.`);
872
+ a.has(o) || a.add(o);
873
+ var s = o._definition;
874
+ if (s.addField(r, e), s.descriptors[r]) {
875
+ if (s.deprecated[r]) return;
876
+ try {
877
+ throw Error(`@colyseus/schema: Duplicate '${r}' definition on '${o.name}'.
878
+ Check @type() annotation`);
879
+ } catch (e) {
880
+ var c = e.stack.split("\n")[4].trim();
881
+ throw Error(`${e.message} ${c}`);
882
+ }
883
+ }
884
+ var l = p.is(e), u = !l && h.is(e);
885
+ if (typeof e != "string" && !Q.is(e)) {
886
+ var d = Object.values(e)[0];
887
+ typeof d != "string" && !a.has(d) && a.add(d);
888
+ }
889
+ if (t.manual) {
890
+ s.descriptors[r] = {
891
+ enumerable: !0,
892
+ configurable: !0,
893
+ writable: !0
894
+ };
895
+ return;
896
+ }
897
+ var g = `_${r}`;
898
+ s.descriptors[g] = {
899
+ enumerable: !1,
900
+ configurable: !1,
901
+ writable: !0
902
+ }, s.descriptors[r] = {
903
+ get: function() {
904
+ return this[g];
905
+ },
906
+ set: function(e) {
907
+ e !== this[g] && (e == null ? this[g] !== void 0 && this.$changes.delete(r) : (l && !(e instanceof p) && (e = new (p.bind.apply(p, i([void 0], e, !1)))()), u && !(e instanceof h) && (e = new h(e)), e.$proxy === void 0 && (u ? e = m(e) : l && (e = f(e))), this.$changes.change(r), e.$changes && e.$changes.setParent(this, this.$changes.root, this._definition.indexes[r])), this[g] = e);
908
+ },
909
+ enumerable: !0,
910
+ configurable: !0
911
+ };
912
+ };
913
+ }
914
+ function w(e) {
915
+ return function(t, n) {
916
+ var r = t.constructor;
917
+ r._definition.addFilter(n, e) && (r._context.useFilters = !0);
918
+ };
919
+ }
920
+ function T(e) {
921
+ return function(t, n) {
922
+ var r = t.constructor;
923
+ r._definition.addChildrenFilter(n, e) && (r._context.useFilters = !0);
924
+ };
925
+ }
926
+ function E(e) {
927
+ return e === void 0 && (e = !0), function(t, n) {
928
+ var r = t.constructor._definition;
929
+ r.deprecated[n] = !0, e && (r.descriptors[n] = {
930
+ get: function() {
931
+ throw Error(`${n} is deprecated.`);
932
+ },
933
+ set: function(e) {},
934
+ enumerable: !1,
935
+ configurable: !0
936
+ });
937
+ };
938
+ }
939
+ function D(e, t, n) {
940
+ for (var r in n === void 0 && (n = {}), n.context ||= e._context || n.context || S, t) C(t[r], n)(e.prototype, r);
941
+ return e;
942
+ }
943
+ function O(e) {
944
+ for (var t = 0, n = 0, r = 0, i = e.length; r < i; r++) t = e.charCodeAt(r), t < 128 ? n += 1 : t < 2048 ? n += 2 : t < 55296 || t >= 57344 ? n += 3 : (r++, n += 4);
945
+ return n;
946
+ }
947
+ function k(e, t, n) {
948
+ for (var r = 0, i = 0, a = n.length; i < a; i++) r = n.charCodeAt(i), r < 128 ? e[t++] = r : r < 2048 ? (e[t++] = 192 | r >> 6, e[t++] = 128 | r & 63) : r < 55296 || r >= 57344 ? (e[t++] = 224 | r >> 12, e[t++] = 128 | r >> 6 & 63, e[t++] = 128 | r & 63) : (i++, r = 65536 + ((r & 1023) << 10 | n.charCodeAt(i) & 1023), e[t++] = 240 | r >> 18, e[t++] = 128 | r >> 12 & 63, e[t++] = 128 | r >> 6 & 63, e[t++] = 128 | r & 63);
949
+ }
950
+ function A(e, t) {
951
+ e.push(t & 255);
952
+ }
953
+ function j(e, t) {
954
+ e.push(t & 255);
955
+ }
956
+ function M(e, t) {
957
+ e.push(t & 255), e.push(t >> 8 & 255);
958
+ }
959
+ function N(e, t) {
960
+ e.push(t & 255), e.push(t >> 8 & 255);
961
+ }
962
+ function P(e, t) {
963
+ e.push(t & 255), e.push(t >> 8 & 255), e.push(t >> 16 & 255), e.push(t >> 24 & 255);
964
+ }
965
+ function F(e, t) {
966
+ var n = t >> 24, r = t >> 16, i = t >> 8, a = t;
967
+ e.push(a & 255), e.push(i & 255), e.push(r & 255), e.push(n & 255);
968
+ }
969
+ function I(e, t) {
970
+ var n = Math.floor(t / 2 ** 32);
971
+ F(e, t >>> 0), F(e, n);
972
+ }
973
+ function L(e, t) {
974
+ var n = t / 2 ** 32 >> 0;
975
+ F(e, t >>> 0), F(e, n);
976
+ }
977
+ function ee(e, t) {
978
+ z(e, t);
979
+ }
980
+ function te(e, t) {
981
+ B(e, t);
982
+ }
983
+ var R = new Int32Array(2), ne = new Float32Array(R.buffer), re = new Float64Array(R.buffer);
984
+ function z(e, t) {
985
+ ne[0] = t, P(e, R[0]);
986
+ }
987
+ function B(e, t) {
988
+ re[0] = t, P(e, R[0]), P(e, R[1]);
989
+ }
990
+ function ie(e, t) {
991
+ return j(e, +!!t);
992
+ }
993
+ function V(e, t) {
994
+ t ||= "";
995
+ var n = O(t), r = 0;
996
+ if (n < 32) e.push(n | 160), r = 1;
997
+ else if (n < 256) e.push(217), j(e, n), r = 2;
998
+ else if (n < 65536) e.push(218), N(e, n), r = 3;
999
+ else if (n < 4294967296) e.push(219), F(e, n), r = 5;
1000
+ else throw Error("String too long");
1001
+ return k(e, e.length, t), r + n;
1002
+ }
1003
+ function H(e, t) {
1004
+ return isNaN(t) ? H(e, 0) : isFinite(t) ? t === (t | 0) ? t >= 0 ? t < 128 ? (j(e, t), 1) : t < 256 ? (e.push(204), j(e, t), 2) : t < 65536 ? (e.push(205), N(e, t), 3) : t < 4294967296 ? (e.push(206), F(e, t), 5) : (e.push(207), L(e, t), 9) : t >= -32 ? (e.push(224 | t + 32), 1) : t >= -128 ? (e.push(208), A(e, t), 2) : t >= -32768 ? (e.push(209), M(e, t), 3) : t >= -2147483648 ? (e.push(210), P(e, t), 5) : (e.push(211), I(e, t), 9) : (e.push(203), B(e, t), 9) : H(e, t > 0 ? 2 ** 53 - 1 : -(2 ** 53 - 1));
1005
+ }
1006
+ var ae = /* @__PURE__ */ Object.freeze({
1007
+ __proto__: null,
1008
+ boolean: ie,
1009
+ float32: ee,
1010
+ float64: te,
1011
+ int16: M,
1012
+ int32: P,
1013
+ int64: I,
1014
+ int8: A,
1015
+ number: H,
1016
+ string: V,
1017
+ uint16: N,
1018
+ uint32: F,
1019
+ uint64: L,
1020
+ uint8: j,
1021
+ utf8Write: k,
1022
+ writeFloat32: z,
1023
+ writeFloat64: B
1024
+ });
1025
+ function oe(e, t, n) {
1026
+ for (var r = "", i = 0, a = t, o = t + n; a < o; a++) {
1027
+ var s = e[a];
1028
+ if (!(s & 128)) {
1029
+ r += String.fromCharCode(s);
1030
+ continue;
1031
+ }
1032
+ if ((s & 224) == 192) {
1033
+ r += String.fromCharCode((s & 31) << 6 | e[++a] & 63);
1034
+ continue;
1035
+ }
1036
+ if ((s & 240) == 224) {
1037
+ r += String.fromCharCode((s & 15) << 12 | (e[++a] & 63) << 6 | (e[++a] & 63) << 0);
1038
+ continue;
1039
+ }
1040
+ if ((s & 248) == 240) {
1041
+ i = (s & 7) << 18 | (e[++a] & 63) << 12 | (e[++a] & 63) << 6 | (e[++a] & 63) << 0, i >= 65536 ? (i -= 65536, r += String.fromCharCode((i >>> 10) + 55296, (i & 1023) + 56320)) : r += String.fromCharCode(i);
1042
+ continue;
1043
+ }
1044
+ console.error("Invalid byte " + s.toString(16));
1045
+ }
1046
+ return r;
1047
+ }
1048
+ function se(e, t) {
1049
+ return U(e, t) << 24 >> 24;
1050
+ }
1051
+ function U(e, t) {
1052
+ return e[t.offset++];
1053
+ }
1054
+ function ce(e, t) {
1055
+ return W(e, t) << 16 >> 16;
1056
+ }
1057
+ function W(e, t) {
1058
+ return e[t.offset++] | e[t.offset++] << 8;
1059
+ }
1060
+ function G(e, t) {
1061
+ return e[t.offset++] | e[t.offset++] << 8 | e[t.offset++] << 16 | e[t.offset++] << 24;
1062
+ }
1063
+ function K(e, t) {
1064
+ return G(e, t) >>> 0;
1065
+ }
1066
+ function le(e, t) {
1067
+ return J(e, t);
1068
+ }
1069
+ function ue(e, t) {
1070
+ return Y(e, t);
1071
+ }
1072
+ function de(e, t) {
1073
+ var n = K(e, t);
1074
+ return G(e, t) * 2 ** 32 + n;
1075
+ }
1076
+ function fe(e, t) {
1077
+ var n = K(e, t);
1078
+ return K(e, t) * 2 ** 32 + n;
1079
+ }
1080
+ var q = new Int32Array(2), pe = new Float32Array(q.buffer), me = new Float64Array(q.buffer);
1081
+ function J(e, t) {
1082
+ return q[0] = G(e, t), pe[0];
1083
+ }
1084
+ function Y(e, t) {
1085
+ return q[0] = G(e, t), q[1] = G(e, t), me[0];
1086
+ }
1087
+ function he(e, t) {
1088
+ return U(e, t) > 0;
1089
+ }
1090
+ function ge(e, t) {
1091
+ var n = e[t.offset++], r;
1092
+ n < 192 ? r = n & 31 : n === 217 ? r = U(e, t) : n === 218 ? r = W(e, t) : n === 219 && (r = K(e, t));
1093
+ var i = oe(e, t.offset, r);
1094
+ return t.offset += r, i;
1095
+ }
1096
+ function _e(e, t) {
1097
+ var n = e[t.offset];
1098
+ return n < 192 && n > 160 || n === 217 || n === 218 || n === 219;
1099
+ }
1100
+ function X(e, t) {
1101
+ var n = e[t.offset++];
1102
+ if (n < 128) return n;
1103
+ if (n === 202) return J(e, t);
1104
+ if (n === 203) return Y(e, t);
1105
+ if (n === 204) return U(e, t);
1106
+ if (n === 205) return W(e, t);
1107
+ if (n === 206) return K(e, t);
1108
+ if (n === 207) return fe(e, t);
1109
+ if (n === 208) return se(e, t);
1110
+ if (n === 209) return ce(e, t);
1111
+ if (n === 210) return G(e, t);
1112
+ if (n === 211) return de(e, t);
1113
+ if (n > 223) return (255 - n + 1) * -1;
1114
+ }
1115
+ function ve(e, t) {
1116
+ var n = e[t.offset];
1117
+ return n < 128 || n >= 202 && n <= 211;
1118
+ }
1119
+ function ye(e, t) {
1120
+ return e[t.offset] < 160;
1121
+ }
1122
+ function be(e, t) {
1123
+ return e[t.offset - 1] === a && (e[t.offset] < 128 || e[t.offset] >= 202 && e[t.offset] <= 211);
1124
+ }
1125
+ var xe = /* @__PURE__ */ Object.freeze({
1126
+ __proto__: null,
1127
+ arrayCheck: ye,
1128
+ boolean: he,
1129
+ float32: le,
1130
+ float64: ue,
1131
+ int16: ce,
1132
+ int32: G,
1133
+ int64: de,
1134
+ int8: se,
1135
+ number: X,
1136
+ numberCheck: ve,
1137
+ readFloat32: J,
1138
+ readFloat64: Y,
1139
+ string: ge,
1140
+ stringCheck: _e,
1141
+ switchStructureCheck: be,
1142
+ uint16: W,
1143
+ uint32: K,
1144
+ uint64: fe,
1145
+ uint8: U
1146
+ }), Se = function() {
1147
+ function t(e) {
1148
+ var t = this;
1149
+ this.$changes = new s(this), this.$items = /* @__PURE__ */ new Map(), this.$indexes = /* @__PURE__ */ new Map(), this.$refId = 0, e && e.forEach(function(e) {
1150
+ return t.add(e);
1151
+ });
1152
+ }
1153
+ return t.prototype.onAdd = function(t, n) {
1154
+ return n === void 0 && (n = !0), c(this.$callbacks ||= [], e.OPERATION.ADD, t, n ? this.$items : void 0);
1155
+ }, t.prototype.onRemove = function(t) {
1156
+ return c(this.$callbacks ||= [], e.OPERATION.DELETE, t);
1157
+ }, t.prototype.onChange = function(t) {
1158
+ return c(this.$callbacks ||= [], e.OPERATION.REPLACE, t);
1159
+ }, t.is = function(e) {
1160
+ return e.collection !== void 0;
1161
+ }, t.prototype.add = function(e) {
1162
+ var t = this.$refId++;
1163
+ return e.$changes !== void 0 && e.$changes.setParent(this, this.$changes.root, t), this.$changes.indexes[t] = t, this.$indexes.set(t, t), this.$items.set(t, e), this.$changes.change(t), t;
1164
+ }, t.prototype.at = function(e) {
1165
+ var t = Array.from(this.$items.keys())[e];
1166
+ return this.$items.get(t);
1167
+ }, t.prototype.entries = function() {
1168
+ return this.$items.entries();
1169
+ }, t.prototype.delete = function(e) {
1170
+ for (var t = this.$items.entries(), n, r; (r = t.next()) && !r.done;) if (e === r.value[1]) {
1171
+ n = r.value[0];
1172
+ break;
1173
+ }
1174
+ return n === void 0 ? !1 : (this.$changes.delete(n), this.$indexes.delete(n), this.$items.delete(n));
1175
+ }, t.prototype.clear = function(t) {
1176
+ this.$changes.discard(!0, !0), this.$changes.indexes = {}, this.$indexes.clear(), t && l.call(this, t), this.$items.clear(), this.$changes.operation({
1177
+ index: 0,
1178
+ op: e.OPERATION.CLEAR
1179
+ }), this.$changes.touchParents();
1180
+ }, t.prototype.has = function(e) {
1181
+ return Array.from(this.$items.values()).some(function(t) {
1182
+ return t === e;
1183
+ });
1184
+ }, t.prototype.forEach = function(e) {
1185
+ var t = this;
1186
+ this.$items.forEach(function(n, r, i) {
1187
+ return e(n, r, t);
1188
+ });
1189
+ }, t.prototype.values = function() {
1190
+ return this.$items.values();
1191
+ }, Object.defineProperty(t.prototype, "size", {
1192
+ get: function() {
1193
+ return this.$items.size;
1194
+ },
1195
+ enumerable: !1,
1196
+ configurable: !0
1197
+ }), t.prototype.setIndex = function(e, t) {
1198
+ this.$indexes.set(e, t);
1199
+ }, t.prototype.getIndex = function(e) {
1200
+ return this.$indexes.get(e);
1201
+ }, t.prototype.getByIndex = function(e) {
1202
+ return this.$items.get(this.$indexes.get(e));
1203
+ }, t.prototype.deleteByIndex = function(e) {
1204
+ var t = this.$indexes.get(e);
1205
+ this.$items.delete(t), this.$indexes.delete(e);
1206
+ }, t.prototype.toArray = function() {
1207
+ return Array.from(this.$items.values());
1208
+ }, t.prototype.toJSON = function() {
1209
+ var e = [];
1210
+ return this.forEach(function(t, n) {
1211
+ e.push(typeof t.toJSON == "function" ? t.toJSON() : t);
1212
+ }), e;
1213
+ }, t.prototype.clone = function(e) {
1214
+ var n;
1215
+ return e ? n = Object.assign(new t(), this) : (n = new t(), this.forEach(function(e) {
1216
+ e.$changes ? n.add(e.clone()) : n.add(e);
1217
+ })), n;
1218
+ }, t;
1219
+ }(), Ce = function() {
1220
+ function t(e) {
1221
+ var t = this;
1222
+ this.$changes = new s(this), this.$items = /* @__PURE__ */ new Map(), this.$indexes = /* @__PURE__ */ new Map(), this.$refId = 0, e && e.forEach(function(e) {
1223
+ return t.add(e);
1224
+ });
1225
+ }
1226
+ return t.prototype.onAdd = function(t, n) {
1227
+ return n === void 0 && (n = !0), c(this.$callbacks ||= [], e.OPERATION.ADD, t, n ? this.$items : void 0);
1228
+ }, t.prototype.onRemove = function(t) {
1229
+ return c(this.$callbacks ||= [], e.OPERATION.DELETE, t);
1230
+ }, t.prototype.onChange = function(t) {
1231
+ return c(this.$callbacks ||= [], e.OPERATION.REPLACE, t);
1232
+ }, t.is = function(e) {
1233
+ return e.set !== void 0;
1234
+ }, t.prototype.add = function(t) {
1235
+ if (this.has(t)) return !1;
1236
+ var n = this.$refId++;
1237
+ t.$changes !== void 0 && t.$changes.setParent(this, this.$changes.root, n);
1238
+ var r = this.$changes.indexes[n]?.op ?? e.OPERATION.ADD;
1239
+ return this.$changes.indexes[n] = n, this.$indexes.set(n, n), this.$items.set(n, t), this.$changes.change(n, r), n;
1240
+ }, t.prototype.entries = function() {
1241
+ return this.$items.entries();
1242
+ }, t.prototype.delete = function(e) {
1243
+ for (var t = this.$items.entries(), n, r; (r = t.next()) && !r.done;) if (e === r.value[1]) {
1244
+ n = r.value[0];
1245
+ break;
1246
+ }
1247
+ return n === void 0 ? !1 : (this.$changes.delete(n), this.$indexes.delete(n), this.$items.delete(n));
1248
+ }, t.prototype.clear = function(t) {
1249
+ this.$changes.discard(!0, !0), this.$changes.indexes = {}, this.$indexes.clear(), t && l.call(this, t), this.$items.clear(), this.$changes.operation({
1250
+ index: 0,
1251
+ op: e.OPERATION.CLEAR
1252
+ }), this.$changes.touchParents();
1253
+ }, t.prototype.has = function(e) {
1254
+ for (var t = this.$items.values(), n = !1, r; (r = t.next()) && !r.done;) if (e === r.value) {
1255
+ n = !0;
1256
+ break;
1257
+ }
1258
+ return n;
1259
+ }, t.prototype.forEach = function(e) {
1260
+ var t = this;
1261
+ this.$items.forEach(function(n, r, i) {
1262
+ return e(n, r, t);
1263
+ });
1264
+ }, t.prototype.values = function() {
1265
+ return this.$items.values();
1266
+ }, Object.defineProperty(t.prototype, "size", {
1267
+ get: function() {
1268
+ return this.$items.size;
1269
+ },
1270
+ enumerable: !1,
1271
+ configurable: !0
1272
+ }), t.prototype.setIndex = function(e, t) {
1273
+ this.$indexes.set(e, t);
1274
+ }, t.prototype.getIndex = function(e) {
1275
+ return this.$indexes.get(e);
1276
+ }, t.prototype.getByIndex = function(e) {
1277
+ return this.$items.get(this.$indexes.get(e));
1278
+ }, t.prototype.deleteByIndex = function(e) {
1279
+ var t = this.$indexes.get(e);
1280
+ this.$items.delete(t), this.$indexes.delete(e);
1281
+ }, t.prototype.toArray = function() {
1282
+ return Array.from(this.$items.values());
1283
+ }, t.prototype.toJSON = function() {
1284
+ var e = [];
1285
+ return this.forEach(function(t, n) {
1286
+ e.push(typeof t.toJSON == "function" ? t.toJSON() : t);
1287
+ }), e;
1288
+ }, t.prototype.clone = function(e) {
1289
+ var n;
1290
+ return e ? n = Object.assign(new t(), this) : (n = new t(), this.forEach(function(e) {
1291
+ e.$changes ? n.add(e.clone()) : n.add(e);
1292
+ })), n;
1293
+ }, t;
1294
+ }(), we = function() {
1295
+ function e() {
1296
+ this.refIds = /* @__PURE__ */ new WeakSet(), this.containerIndexes = /* @__PURE__ */ new WeakMap();
1297
+ }
1298
+ return e.prototype.addRefId = function(e) {
1299
+ this.refIds.has(e) || (this.refIds.add(e), this.containerIndexes.set(e, /* @__PURE__ */ new Set()));
1300
+ }, e.get = function(t) {
1301
+ return t.$filterState === void 0 && (t.$filterState = new e()), t.$filterState;
1302
+ }, e;
1303
+ }(), Te = function() {
1304
+ function e() {
1305
+ this.refs = /* @__PURE__ */ new Map(), this.refCounts = {}, this.deletedRefs = /* @__PURE__ */ new Set(), this.nextUniqueId = 0;
1306
+ }
1307
+ return e.prototype.getNextUniqueId = function() {
1308
+ return this.nextUniqueId++;
1309
+ }, e.prototype.addRef = function(e, t, n) {
1310
+ n === void 0 && (n = !0), this.refs.set(e, t), n && (this.refCounts[e] = (this.refCounts[e] || 0) + 1);
1311
+ }, e.prototype.removeRef = function(e) {
1312
+ var t = this.refCounts[e];
1313
+ if (t === void 0) {
1314
+ console.warn(`trying to remove reference ${e} that doesn't exist`);
1315
+ return;
1316
+ }
1317
+ if (t === 0) {
1318
+ console.warn(`trying to remove reference ${e} with 0 refCount`);
1319
+ return;
1320
+ }
1321
+ this.refCounts[e] = t - 1, this.deletedRefs.add(e);
1322
+ }, e.prototype.clearRefs = function() {
1323
+ this.refs.clear(), this.deletedRefs.clear(), this.refCounts = {};
1324
+ }, e.prototype.garbageCollectDeletedRefs = function() {
1325
+ var e = this;
1326
+ this.deletedRefs.forEach(function(t) {
1327
+ if (!(e.refCounts[t] > 0)) {
1328
+ var n = e.refs.get(t);
1329
+ if (n instanceof Q) for (var r in n._definition.schema) typeof n._definition.schema[r] != "string" && n[r] && n[r].$changes && e.removeRef(n[r].$changes.refId);
1330
+ else {
1331
+ var i = n.$changes.parent._definition, a = i.schema[i.fieldsByIndex[n.$changes.parentIndex]];
1332
+ typeof Object.values(a)[0] == "function" && Array.from(n.values()).forEach(function(t) {
1333
+ return e.removeRef(t.$changes.refId);
1334
+ });
1335
+ }
1336
+ e.refs.delete(t), delete e.refCounts[t];
1337
+ }
1338
+ }), this.deletedRefs.clear();
1339
+ }, e;
1340
+ }(), Z = function(e) {
1341
+ n(t, e);
1342
+ function t() {
1343
+ return e !== null && e.apply(this, arguments) || this;
1344
+ }
1345
+ return t;
1346
+ }(Error);
1347
+ function Ee(e, t, n, r) {
1348
+ var i, a = !1;
1349
+ switch (t) {
1350
+ case "number":
1351
+ case "int8":
1352
+ case "uint8":
1353
+ case "int16":
1354
+ case "uint16":
1355
+ case "int32":
1356
+ case "uint32":
1357
+ case "int64":
1358
+ case "uint64":
1359
+ case "float32":
1360
+ case "float64":
1361
+ i = "number", isNaN(e) && console.log(`trying to encode "NaN" in ${n.constructor.name}#${r}`);
1362
+ break;
1363
+ case "string":
1364
+ i = "string", a = !0;
1365
+ break;
1366
+ case "boolean": return;
1367
+ }
1368
+ if (typeof e !== i && (!a || a && e !== null)) {
1369
+ var o = `'${JSON.stringify(e)}'${e && e.constructor && ` (${e.constructor.name})` || ""}`;
1370
+ throw new Z(`a '${i}' was expected, but ${o} was provided in ${n.constructor.name}#${r}`);
1371
+ }
1372
+ }
1373
+ function De(e, t, n, r) {
1374
+ if (!(e instanceof t)) throw new Z(`a '${t.name}' was expected, but '${e.constructor.name}' was provided in ${n.constructor.name}#${r}`);
1375
+ }
1376
+ function Oe(e, t, n, r, i) {
1377
+ Ee(n, e, r, i);
1378
+ var a = ae[e];
1379
+ if (a) a(t, n);
1380
+ else throw new Z(`a '${e}' was expected, but ${n} was provided in ${r.constructor.name}#${i}`);
1381
+ }
1382
+ function ke(e, t, n) {
1383
+ return xe[e](t, n);
1384
+ }
1385
+ var Q = function() {
1386
+ function t() {
1387
+ var e = [...arguments];
1388
+ Object.defineProperties(this, {
1389
+ $changes: {
1390
+ value: new s(this, void 0, new Te()),
1391
+ enumerable: !1,
1392
+ writable: !0
1393
+ },
1394
+ $callbacks: {
1395
+ value: void 0,
1396
+ enumerable: !1,
1397
+ writable: !0
1398
+ }
1399
+ });
1400
+ var t = this._definition.descriptors;
1401
+ t && Object.defineProperties(this, t), e[0] && this.assign(e[0]);
1402
+ }
1403
+ return t.onError = function(e) {
1404
+ console.error(e);
1405
+ }, t.is = function(e) {
1406
+ return e._definition && e._definition.schema !== void 0;
1407
+ }, t.prototype.onChange = function(t) {
1408
+ return c(this.$callbacks ||= {}, e.OPERATION.REPLACE, t);
1409
+ }, t.prototype.onRemove = function(t) {
1410
+ return c(this.$callbacks ||= {}, e.OPERATION.DELETE, t);
1411
+ }, t.prototype.assign = function(e) {
1412
+ return Object.assign(this, e), this;
1413
+ }, Object.defineProperty(t.prototype, "_definition", {
1414
+ get: function() {
1415
+ return this.constructor._definition;
1416
+ },
1417
+ enumerable: !1,
1418
+ configurable: !0
1419
+ }), t.prototype.setDirty = function(e, t) {
1420
+ this.$changes.change(e, t);
1421
+ }, t.prototype.listen = function(e, t, n) {
1422
+ var r = this;
1423
+ return n === void 0 && (n = !0), this.$callbacks ||= {}, this.$callbacks[e] || (this.$callbacks[e] = []), this.$callbacks[e].push(t), n && this[e] !== void 0 && t(this[e], void 0), function() {
1424
+ return u(r.$callbacks[e], r.$callbacks[e].indexOf(t));
1425
+ };
1426
+ }, t.prototype.decode = function(n, r, i) {
1427
+ r === void 0 && (r = { offset: 0 }), i === void 0 && (i = this);
1428
+ var o = [], s = this.$changes.root, c = n.length, l = 0;
1429
+ for (s.refs.set(l, this); r.offset < c;) {
1430
+ var u = n[r.offset++];
1431
+ if (u == a) {
1432
+ l = X(n, r);
1433
+ var d = s.refs.get(l);
1434
+ if (!d) throw Error(`"refId" not found: ${l}`);
1435
+ i = d;
1436
+ continue;
1437
+ }
1438
+ var f = i.$changes, m = i._definition !== void 0, g = m ? u >> 6 << 6 : u;
1439
+ if (g === e.OPERATION.CLEAR) {
1440
+ i.clear(o);
1441
+ continue;
1442
+ }
1443
+ var _ = m ? u % (g || 255) : X(n, r), y = m ? i._definition.fieldsByIndex[_] : "", b = f.getType(_), x = void 0, S = void 0, C = void 0;
1444
+ if (m ? S = i[`_${y}`] : (S = i.getByIndex(_), (g & e.OPERATION.ADD) === e.OPERATION.ADD ? (C = i instanceof h ? ge(n, r) : _, i.setIndex(_, C)) : C = i.getIndex(_)), (g & e.OPERATION.DELETE) === e.OPERATION.DELETE && (g !== e.OPERATION.DELETE_AND_ADD && i.deleteByIndex(_), S && S.$changes && s.removeRef(S.$changes.refId), x = null), y === void 0) {
1445
+ console.warn("@colyseus/schema: definition mismatch");
1446
+ for (var w = { offset: r.offset }; r.offset < c && !(be(n, r) && (w.offset = r.offset + 1, s.refs.has(X(n, w))));) r.offset++;
1447
+ continue;
1448
+ } else if (g !== e.OPERATION.DELETE) if (t.is(b)) {
1449
+ var T = X(n, r);
1450
+ if (x = s.refs.get(T), g !== e.OPERATION.REPLACE) {
1451
+ var E = this.getSchemaType(n, r, b);
1452
+ x || (x = this.createTypeInstance(E), x.$changes.refId = T, S && (x.$callbacks = S.$callbacks, S.$changes.refId && T !== S.$changes.refId && s.removeRef(S.$changes.refId))), s.addRef(T, x, x !== S);
1453
+ }
1454
+ } else if (typeof b == "string") x = ke(b, n, r);
1455
+ else {
1456
+ var D = v(Object.keys(b)[0]), O = X(n, r), k = s.refs.has(O) ? S || s.refs.get(O) : new D.constructor();
1457
+ if (x = k.clone(!0), x.$changes.refId = O, S && (x.$callbacks = S.$callbacks, S.$changes.refId && O !== S.$changes.refId)) {
1458
+ s.removeRef(S.$changes.refId);
1459
+ for (var A = S.entries(), j = void 0; (j = A.next()) && !j.done;) {
1460
+ var M = j.value, N = M[0], P = M[1];
1461
+ o.push({
1462
+ refId: O,
1463
+ op: e.OPERATION.DELETE,
1464
+ field: N,
1465
+ value: void 0,
1466
+ previousValue: P
1467
+ });
1468
+ }
1469
+ }
1470
+ s.addRef(O, x, k !== S);
1471
+ }
1472
+ if (x != null) {
1473
+ if (x.$changes && x.$changes.setParent(f.ref, f.root, _), i instanceof t) i[y] = x;
1474
+ else if (i instanceof h) {
1475
+ var N = C;
1476
+ i.$items.set(N, x), i.$changes.allChanges.add(_);
1477
+ } else if (i instanceof p) i.setAt(_, x);
1478
+ else if (i instanceof Se) {
1479
+ var F = i.add(x);
1480
+ i.setIndex(_, F);
1481
+ } else if (i instanceof Ce) {
1482
+ var F = i.add(x);
1483
+ F !== !1 && i.setIndex(_, F);
1484
+ }
1485
+ }
1486
+ S !== x && o.push({
1487
+ refId: l,
1488
+ op: g,
1489
+ field: y,
1490
+ dynamicIndex: C,
1491
+ value: x,
1492
+ previousValue: S
1493
+ });
1494
+ }
1495
+ return this._triggerChanges(o), s.garbageCollectDeletedRefs(), o;
1496
+ }, t.prototype.encode = function(n, r, i) {
1497
+ n === void 0 && (n = !1), r === void 0 && (r = []), i === void 0 && (i = !1);
1498
+ for (var o = this.$changes, s = /* @__PURE__ */ new WeakSet(), c = [o], l = 1, u = 0; u < l; u++) {
1499
+ var d = c[u], f = d.ref, p = f instanceof t;
1500
+ d.ensureRefId(), s.add(d), d !== o && (d.changed || n) && (j(r, a), H(r, d.refId));
1501
+ for (var m = n ? Array.from(d.allChanges) : Array.from(d.changes.values()), g = 0, _ = m.length; g < _; g++) {
1502
+ var y = n ? {
1503
+ op: e.OPERATION.ADD,
1504
+ index: m[g]
1505
+ } : m[g], b = y.index, x = p ? f._definition.fieldsByIndex && f._definition.fieldsByIndex[b] : b, S = r.length;
1506
+ if (y.op !== e.OPERATION.TOUCH) if (p) j(r, b | y.op);
1507
+ else {
1508
+ if (j(r, y.op), y.op === e.OPERATION.CLEAR) continue;
1509
+ H(r, b);
1510
+ }
1511
+ if (!p && (y.op & e.OPERATION.ADD) == e.OPERATION.ADD && f instanceof h) {
1512
+ var C = d.ref.$indexes.get(b);
1513
+ V(r, C);
1514
+ }
1515
+ if (y.op !== e.OPERATION.DELETE) {
1516
+ var w = d.getType(b), T = d.getValue(b);
1517
+ if (T && T.$changes && !s.has(T.$changes) && (c.push(T.$changes), T.$changes.ensureRefId(), l++), y.op !== e.OPERATION.TOUCH) {
1518
+ if (t.is(w)) De(T, w, f, x), H(r, T.$changes.refId), (y.op & e.OPERATION.ADD) === e.OPERATION.ADD && this.tryEncodeTypeId(r, w, T.constructor);
1519
+ else if (typeof w == "string") Oe(w, r, T, f, x);
1520
+ else {
1521
+ var E = v(Object.keys(w)[0]);
1522
+ De(f[`_${x}`], E.constructor, f, x), H(r, T.$changes.refId);
1523
+ }
1524
+ i && d.cache(b, r.slice(S));
1525
+ }
1526
+ }
1527
+ }
1528
+ !n && !i && d.discard();
1529
+ }
1530
+ return r;
1531
+ }, t.prototype.encodeAll = function(e) {
1532
+ return this.encode(!0, [], e);
1533
+ }, t.prototype.applyFilters = function(n, r) {
1534
+ r === void 0 && (r = !1);
1535
+ for (var i = this, o = /* @__PURE__ */ new Set(), s = we.get(n), c = [this.$changes], l = 1, u = [], d = function(d) {
1536
+ var f = c[d];
1537
+ if (o.has(f.refId)) return "continue";
1538
+ var p = f.ref, m = p instanceof t;
1539
+ j(u, a), H(u, f.refId);
1540
+ var g = s.refIds.has(f), _ = r || !g;
1541
+ s.addRefId(f);
1542
+ var v = s.containerIndexes.get(f), y = _ ? Array.from(f.allChanges) : Array.from(f.changes.values());
1543
+ !r && m && p._definition.indexesWithFilters && p._definition.indexesWithFilters.forEach(function(t) {
1544
+ !v.has(t) && f.allChanges.has(t) && (_ ? y.push(t) : y.push({
1545
+ op: e.OPERATION.ADD,
1546
+ index: t
1547
+ }));
1548
+ });
1549
+ for (var b = 0, x = y.length; b < x; b++) {
1550
+ var S = _ ? {
1551
+ op: e.OPERATION.ADD,
1552
+ index: y[b]
1553
+ } : y[b];
1554
+ if (S.op === e.OPERATION.CLEAR) {
1555
+ j(u, S.op);
1556
+ continue;
1557
+ }
1558
+ var C = S.index;
1559
+ if (S.op === e.OPERATION.DELETE) {
1560
+ m ? j(u, S.op | C) : (j(u, S.op), H(u, C));
1561
+ continue;
1562
+ }
1563
+ var w = f.getValue(C), T = f.getType(C);
1564
+ if (m) {
1565
+ var E = p._definition.filters && p._definition.filters[C];
1566
+ if (E && !E.call(p, n, w, i)) {
1567
+ w && w.$changes && o.add(w.$changes.refId);
1568
+ continue;
1569
+ }
1570
+ } else {
1571
+ var D = f.parent, E = f.getChildrenFilter();
1572
+ if (E && !E.call(D, n, p.$indexes.get(C), w, i)) {
1573
+ w && w.$changes && o.add(w.$changes.refId);
1574
+ continue;
1575
+ }
1576
+ }
1577
+ if (w.$changes && (c.push(w.$changes), l++), S.op !== e.OPERATION.TOUCH) if (S.op === e.OPERATION.ADD || m) u.push.apply(u, f.caches[C] ?? []), v.add(C);
1578
+ else if (v.has(C)) u.push.apply(u, f.caches[C] ?? []);
1579
+ else {
1580
+ if (v.add(C), j(u, e.OPERATION.ADD), H(u, C), p instanceof h) {
1581
+ var O = f.ref.$indexes.get(C);
1582
+ V(u, O);
1583
+ }
1584
+ w.$changes ? H(u, w.$changes.refId) : ae[T](u, w);
1585
+ }
1586
+ else if (w.$changes && !m) {
1587
+ if (j(u, e.OPERATION.ADD), H(u, C), p instanceof h) {
1588
+ var O = f.ref.$indexes.get(C);
1589
+ V(u, O);
1590
+ }
1591
+ H(u, w.$changes.refId);
1592
+ }
1593
+ }
1594
+ }, f = 0; f < l; f++) d(f);
1595
+ return u;
1596
+ }, t.prototype.clone = function() {
1597
+ var e = new this.constructor();
1598
+ for (var t in this._definition.schema) typeof this[t] == "object" && typeof this[t]?.clone == "function" ? e[t] = this[t].clone() : e[t] = this[t];
1599
+ return e;
1600
+ }, t.prototype.toJSON = function() {
1601
+ var e = this._definition.schema, t = this._definition.deprecated, n = {};
1602
+ for (var r in e) !t[r] && this[r] !== null && this[r] !== void 0 && (n[r] = typeof this[r].toJSON == "function" ? this[r].toJSON() : this[`_${r}`]);
1603
+ return n;
1604
+ }, t.prototype.discardAllChanges = function() {
1605
+ this.$changes.discardAll();
1606
+ }, t.prototype.getByIndex = function(e) {
1607
+ return this[this._definition.fieldsByIndex[e]];
1608
+ }, t.prototype.deleteByIndex = function(e) {
1609
+ this[this._definition.fieldsByIndex[e]] = void 0;
1610
+ }, t.prototype.tryEncodeTypeId = function(e, t, n) {
1611
+ t._typeid !== n._typeid && (j(e, o), H(e, n._typeid));
1612
+ }, t.prototype.getSchemaType = function(e, t, n) {
1613
+ var r;
1614
+ return e[t.offset] === o && (t.offset++, r = this.constructor._context.get(X(e, t))), r || n;
1615
+ }, t.prototype.createTypeInstance = function(e) {
1616
+ var t = new e();
1617
+ return t.$changes.root = this.$changes.root, t;
1618
+ }, t.prototype._triggerChanges = function(n) {
1619
+ for (var r, i, a, o, s, c, l, u, d = /* @__PURE__ */ new Set(), f = this.$changes.root.refs, p = function(p) {
1620
+ var m = n[p], h = m.refId, g = f.get(h), _ = g.$callbacks;
1621
+ if ((m.op & e.OPERATION.DELETE) === e.OPERATION.DELETE && m.previousValue instanceof t && ((r = m.previousValue.$callbacks?.[e.OPERATION.DELETE]) == null || r.forEach(function(e) {
1622
+ return e();
1623
+ })), !_) return "continue";
1624
+ if (g instanceof t) {
1625
+ if (!d.has(h)) try {
1626
+ (i = _?.[e.OPERATION.REPLACE]) == null || i.forEach(function(e) {
1627
+ return e();
1628
+ });
1629
+ } catch (e) {
1630
+ t.onError(e);
1631
+ }
1632
+ try {
1633
+ _.hasOwnProperty(m.field) && ((a = _[m.field]) == null || a.forEach(function(e) {
1634
+ return e(m.value, m.previousValue);
1635
+ }));
1636
+ } catch (e) {
1637
+ t.onError(e);
1638
+ }
1639
+ } else m.op === e.OPERATION.ADD && m.previousValue === void 0 ? (o = _[e.OPERATION.ADD]) == null || o.forEach(function(e) {
1640
+ return e(m.value, m.dynamicIndex ?? m.field);
1641
+ }) : m.op === e.OPERATION.DELETE ? m.previousValue !== void 0 && ((s = _[e.OPERATION.DELETE]) == null || s.forEach(function(e) {
1642
+ return e(m.previousValue, m.dynamicIndex ?? m.field);
1643
+ })) : m.op === e.OPERATION.DELETE_AND_ADD && (m.previousValue !== void 0 && ((c = _[e.OPERATION.DELETE]) == null || c.forEach(function(e) {
1644
+ return e(m.previousValue, m.dynamicIndex ?? m.field);
1645
+ })), (l = _[e.OPERATION.ADD]) == null || l.forEach(function(e) {
1646
+ return e(m.value, m.dynamicIndex ?? m.field);
1647
+ })), m.value !== m.previousValue && ((u = _[e.OPERATION.REPLACE]) == null || u.forEach(function(e) {
1648
+ return e(m.value, m.dynamicIndex ?? m.field);
1649
+ }));
1650
+ d.add(h);
1651
+ }, m = 0; m < n.length; m++) p(m);
1652
+ }, t._definition = y.create(), t;
1653
+ }();
1654
+ function Ae(e) {
1655
+ for (var t = [e.$changes], n = 1, r = {}, i = r, a = function(e) {
1656
+ var n = t[e];
1657
+ n.changes.forEach(function(e) {
1658
+ var t = n.ref, r = e.index, a = t._definition ? t._definition.fieldsByIndex[r] : t.$indexes.get(r);
1659
+ i[a] = n.getValue(r);
1660
+ });
1661
+ }, o = 0; o < n; o++) a(o);
1662
+ return r;
1663
+ }
1664
+ var $ = { context: new x() }, je = function(e) {
1665
+ n(t, e);
1666
+ function t() {
1667
+ return e !== null && e.apply(this, arguments) || this;
1668
+ }
1669
+ return r([C("string", $)], t.prototype, "name", void 0), r([C("string", $)], t.prototype, "type", void 0), r([C("number", $)], t.prototype, "referencedType", void 0), t;
1670
+ }(Q), Me = function(e) {
1671
+ n(t, e);
1672
+ function t() {
1673
+ var t = e !== null && e.apply(this, arguments) || this;
1674
+ return t.fields = new p(), t;
1675
+ }
1676
+ return r([C("number", $)], t.prototype, "id", void 0), r([C([je], $)], t.prototype, "fields", void 0), t;
1677
+ }(Q), Ne = function(e) {
1678
+ n(t, e);
1679
+ function t() {
1680
+ var t = e !== null && e.apply(this, arguments) || this;
1681
+ return t.types = new p(), t;
1682
+ }
1683
+ return t.encode = function(e) {
1684
+ var n = e.constructor, r = new t();
1685
+ r.rootType = n._typeid;
1686
+ var i = function(e, t) {
1687
+ for (var n in t) {
1688
+ var i = new je();
1689
+ i.name = n;
1690
+ var a = void 0;
1691
+ if (typeof t[n] == "string") a = t[n];
1692
+ else {
1693
+ var o = t[n], s = void 0;
1694
+ Q.is(o) ? (a = "ref", s = t[n]) : (a = Object.keys(o)[0], typeof o[a] == "string" ? a += ":" + o[a] : s = o[a]), i.referencedType = s ? s._typeid : -1;
1695
+ }
1696
+ i.type = a, e.fields.push(i);
1697
+ }
1698
+ r.types.push(e);
1699
+ }, a = n._context?.types;
1700
+ for (var o in a) {
1701
+ var s = new Me();
1702
+ s.id = Number(o), i(s, a[o]._definition.schema);
1703
+ }
1704
+ return r.encodeAll();
1705
+ }, t.decode = function(e, r) {
1706
+ var i = new x(), a = new t();
1707
+ a.decode(e, r);
1708
+ var o = a.types.reduce(function(e, t) {
1709
+ var r = function(e) {
1710
+ n(t, e);
1711
+ function t() {
1712
+ return e !== null && e.apply(this, arguments) || this;
1713
+ }
1714
+ return t;
1715
+ }(Q), a = t.id;
1716
+ return e[a] = r, i.add(r, a), e;
1717
+ }, {});
1718
+ a.types.forEach(function(e) {
1719
+ var t = o[e.id];
1720
+ e.fields.forEach(function(e) {
1721
+ var n;
1722
+ if (e.referencedType !== void 0) {
1723
+ var r = e.type, a = o[e.referencedType];
1724
+ if (!a) {
1725
+ var s = e.type.split(":");
1726
+ r = s[0], a = s[1];
1727
+ }
1728
+ r === "ref" ? C(a, { context: i })(t.prototype, e.name) : C((n = {}, n[r] = a, n), { context: i })(t.prototype, e.name);
1729
+ } else C(e.type, { context: i })(t.prototype, e.name);
1730
+ });
1731
+ });
1732
+ var s = o[a.rootType], c = new s();
1733
+ for (var l in s._definition.schema) {
1734
+ var u = s._definition.schema[l];
1735
+ typeof u != "string" && (c[l] = typeof u == "function" ? new u() : new (v(Object.keys(u)[0])).constructor());
1736
+ }
1737
+ return c;
1738
+ }, r([C([Me], $)], t.prototype, "types", void 0), r([C("number", $)], t.prototype, "rootType", void 0), t;
1739
+ }(Q);
1740
+ _("map", { constructor: h }), _("array", { constructor: p }), _("set", { constructor: Ce }), _("collection", { constructor: Se }), e.ArraySchema = p, e.CollectionSchema = Se, e.Context = x, e.MapSchema = h, e.Reflection = Ne, e.ReflectionField = je, e.ReflectionType = Me, e.Schema = Q, e.SchemaDefinition = y, e.SetSchema = Ce, e.decode = xe, e.defineTypes = D, e.deprecated = E, e.dumpChanges = Ae, e.encode = ae, e.filter = w, e.filterChildren = T, e.hasFilter = b, e.registerType = _, e.type = C;
1741
+ }));
1742
+ })), T = /* @__PURE__ */ l(((e) => {
1743
+ var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
1744
+ r === void 0 && (r = n);
1745
+ var i = Object.getOwnPropertyDescriptor(t, n);
1746
+ (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) && (i = {
1747
+ enumerable: !0,
1748
+ get: function() {
1749
+ return t[n];
1750
+ }
1751
+ }), Object.defineProperty(e, r, i);
1752
+ }) : (function(e, t, n, r) {
1753
+ r === void 0 && (r = n), e[r] = t[n];
1754
+ })), n = e && e.__setModuleDefault || (Object.create ? (function(e, t) {
1755
+ Object.defineProperty(e, "default", {
1756
+ enumerable: !0,
1757
+ value: t
1758
+ });
1759
+ }) : function(e, t) {
1760
+ e.default = t;
1761
+ }), r = e && e.__importStar || function(e) {
1762
+ if (e && e.__esModule) return e;
1763
+ var r = {};
1764
+ if (e != null) for (var i in e) i !== "default" && Object.prototype.hasOwnProperty.call(e, i) && t(r, e, i);
1765
+ return n(r, e), r;
1766
+ };
1767
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Room = void 0;
1768
+ var i = r(g()), a = y(), o = b(), s = x(), c = S(), l = C(), u = w(), d = h();
1769
+ e.Room = class e {
1770
+ constructor(e, t) {
1771
+ this.onStateChange = (0, l.createSignal)(), this.onError = (0, l.createSignal)(), this.onLeave = (0, l.createSignal)(), this.onJoin = (0, l.createSignal)(), this.hasJoined = !1, this.onMessageHandlers = (0, c.createNanoEvents)(), this.roomId = null, this.name = e, t && (this.serializer = new ((0, s.getSerializer)("schema"))(), this.rootSchema = t, this.serializer.state = new t()), this.onError((e, t) => console.warn?.call(console, `colyseus.js - onError => (${e}) ${t}`)), this.onLeave(() => this.removeAllListeners());
1772
+ }
1773
+ get id() {
1774
+ return this.roomId;
1775
+ }
1776
+ connect(t, n, r = this, i) {
1777
+ let o = new a.Connection();
1778
+ r.connection = o, o.events.onmessage = e.prototype.onMessageCallback.bind(r), o.events.onclose = function(e) {
1779
+ var t;
1780
+ if (!r.hasJoined) {
1781
+ (t = console.warn) == null || t.call(console, `Room connection was closed unexpectedly (${e.code}): ${e.reason}`), r.onError.invoke(e.code, e.reason);
1782
+ return;
1783
+ }
1784
+ e.code === d.CloseCode.DEVMODE_RESTART && n ? n() : (r.onLeave.invoke(e.code, e.reason), r.destroy());
1785
+ }, o.events.onerror = function(e) {
1786
+ var t;
1787
+ (t = console.warn) == null || t.call(console, `Room, onError (${e.code}): ${e.reason}`), r.onError.invoke(e.code, e.reason);
1788
+ }, o.connect(t, i);
1789
+ }
1790
+ leave(e = !0) {
1791
+ return new Promise((t) => {
1792
+ this.onLeave((e) => t(e)), this.connection ? e ? this.connection.send([o.Protocol.LEAVE_ROOM]) : this.connection.close() : this.onLeave.invoke(d.CloseCode.CONSENTED);
1793
+ });
1794
+ }
1795
+ onMessage(e, t) {
1796
+ return this.onMessageHandlers.on(this.getMessageHandlerKey(e), t);
1797
+ }
1798
+ send(e, t) {
1799
+ let n = [o.Protocol.ROOM_DATA];
1800
+ typeof e == "string" ? u.encode.string(n, e) : u.encode.number(n, e);
1801
+ let r;
1802
+ if (t !== void 0) {
1803
+ let e = i.encode(t);
1804
+ r = new Uint8Array(n.length + e.byteLength), r.set(new Uint8Array(n), 0), r.set(new Uint8Array(e), n.length);
1805
+ } else r = new Uint8Array(n);
1806
+ this.connection.send(r.buffer);
1807
+ }
1808
+ sendBytes(e, t) {
1809
+ let n = [o.Protocol.ROOM_DATA_BYTES];
1810
+ typeof e == "string" ? u.encode.string(n, e) : u.encode.number(n, e);
1811
+ let r;
1812
+ r = new Uint8Array(n.length + (t.byteLength || t.length)), r.set(new Uint8Array(n), 0), r.set(new Uint8Array(t), n.length), this.connection.send(r.buffer);
1813
+ }
1814
+ get state() {
1815
+ return this.serializer.getState();
1816
+ }
1817
+ removeAllListeners() {
1818
+ this.onJoin.clear(), this.onStateChange.clear(), this.onError.clear(), this.onLeave.clear(), this.onMessageHandlers.events = {};
1819
+ }
1820
+ onMessageCallback(e) {
1821
+ let t = Array.from(new Uint8Array(e.data)), n = t[0];
1822
+ if (n === o.Protocol.JOIN_ROOM) {
1823
+ let e = 1, n = (0, o.utf8Read)(t, e);
1824
+ e += (0, o.utf8Length)(n), this.serializerId = (0, o.utf8Read)(t, e), e += (0, o.utf8Length)(this.serializerId), this.serializer ||= new ((0, s.getSerializer)(this.serializerId))(), t.length > e && this.serializer.handshake && this.serializer.handshake(t, { offset: e }), this.reconnectionToken = `${this.roomId}:${n}`, this.hasJoined = !0, this.onJoin.invoke(), this.connection.send([o.Protocol.JOIN_ROOM]);
1825
+ } else if (n === o.Protocol.ERROR) {
1826
+ let e = { offset: 1 }, n = u.decode.number(t, e), r = u.decode.string(t, e);
1827
+ this.onError.invoke(n, r);
1828
+ } else if (n === o.Protocol.LEAVE_ROOM) this.leave();
1829
+ else if (n === o.Protocol.ROOM_DATA_SCHEMA) {
1830
+ let e = { offset: 1 }, n = this.serializer.getState().constructor._context.get(u.decode.number(t, e)), r = new n();
1831
+ r.decode(t, e), this.dispatchMessage(n, r);
1832
+ } else if (n === o.Protocol.ROOM_STATE) t.shift(), this.setState(t);
1833
+ else if (n === o.Protocol.ROOM_STATE_PATCH) t.shift(), this.patch(t);
1834
+ else if (n === o.Protocol.ROOM_DATA) {
1835
+ let n = { offset: 1 }, r = u.decode.stringCheck(t, n) ? u.decode.string(t, n) : u.decode.number(t, n), a = t.length > n.offset ? i.decode(e.data, n.offset) : void 0;
1836
+ this.dispatchMessage(r, a);
1837
+ } else if (n === o.Protocol.ROOM_DATA_BYTES) {
1838
+ let e = { offset: 1 }, n = u.decode.stringCheck(t, e) ? u.decode.string(t, e) : u.decode.number(t, e);
1839
+ this.dispatchMessage(n, new Uint8Array(t.slice(e.offset)));
1840
+ }
1841
+ }
1842
+ setState(e) {
1843
+ this.serializer.setState(e), this.onStateChange.invoke(this.serializer.getState());
1844
+ }
1845
+ patch(e) {
1846
+ this.serializer.patch(e), this.onStateChange.invoke(this.serializer.getState());
1847
+ }
1848
+ dispatchMessage(e, t) {
1849
+ var n;
1850
+ let r = this.getMessageHandlerKey(e);
1851
+ this.onMessageHandlers.events[r] ? this.onMessageHandlers.emit(r, t) : this.onMessageHandlers.events["*"] ? this.onMessageHandlers.emit("*", e, t) : (n = console.warn) == null || n.call(console, `colyseus.js: onMessage() not registered for type '${e}'.`);
1852
+ }
1853
+ destroy() {
1854
+ this.serializer && this.serializer.teardown();
1855
+ }
1856
+ getMessageHandlerKey(e) {
1857
+ switch (typeof e) {
1858
+ case "function": return `$${e._typeid}`;
1859
+ case "string": return e;
1860
+ case "number": return `i${e}`;
1861
+ default: throw Error("invalid message type.");
1862
+ }
1863
+ }
1864
+ };
1865
+ })), E = /* @__PURE__ */ u({
1866
+ del: () => M,
1867
+ get: () => k,
1868
+ patch: () => j,
1869
+ post: () => A,
1870
+ put: () => N,
1871
+ send: () => O
1872
+ });
1873
+ function D(e, t) {
1874
+ t.headers = e.headers || {}, t.statusMessage = e.statusText, t.statusCode = e.status, t.data = e.response;
1875
+ }
1876
+ function O(e, t, n) {
1877
+ return new Promise(function(r, i) {
1878
+ n ||= {};
1879
+ var a = new XMLHttpRequest(), o, s, c, l = n.body, u = n.headers || {};
1880
+ for (o in n.timeout && (a.timeout = n.timeout), a.ontimeout = a.onerror = function(e) {
1881
+ e.timeout = e.type == "timeout", i(e);
1882
+ }, a.open(e, t.href || t), a.onload = function() {
1883
+ for (c = a.getAllResponseHeaders().trim().split(/[\r\n]+/), D(a, a); s = c.shift();) s = s.split(": "), a.headers[s.shift().toLowerCase()] = s.join(": ");
1884
+ if (s = a.headers["content-type"], s && ~s.indexOf("application/json")) try {
1885
+ a.data = JSON.parse(a.data, n.reviver);
1886
+ } catch (e) {
1887
+ return D(a, e), i(e);
1888
+ }
1889
+ (a.status >= 400 ? i : r)(a);
1890
+ }, typeof FormData < "u" && l instanceof FormData || l && typeof l == "object" && (u["content-type"] = "application/json", l = JSON.stringify(l)), a.withCredentials = !!n.withCredentials, u) a.setRequestHeader(o, u[o]);
1891
+ a.send(l);
1892
+ });
1893
+ }
1894
+ var k, A, j, M, N, P = c((() => {
1895
+ k = /* @__PURE__ */ O.bind(O, "GET"), A = /* @__PURE__ */ O.bind(O, "POST"), j = /* @__PURE__ */ O.bind(O, "PATCH"), M = /* @__PURE__ */ O.bind(O, "DELETE"), N = /* @__PURE__ */ O.bind(O, "PUT");
1896
+ })), F = /* @__PURE__ */ l(((e) => {
1897
+ var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
1898
+ r === void 0 && (r = n);
1899
+ var i = Object.getOwnPropertyDescriptor(t, n);
1900
+ (!i || ("get" in i ? !t.__esModule : i.writable || i.configurable)) && (i = {
1901
+ enumerable: !0,
1902
+ get: function() {
1903
+ return t[n];
1904
+ }
1905
+ }), Object.defineProperty(e, r, i);
1906
+ }) : (function(e, t, n, r) {
1907
+ r === void 0 && (r = n), e[r] = t[n];
1908
+ })), n = e && e.__setModuleDefault || (Object.create ? (function(e, t) {
1909
+ Object.defineProperty(e, "default", {
1910
+ enumerable: !0,
1911
+ value: t
1912
+ });
1913
+ }) : function(e, t) {
1914
+ e.default = t;
1915
+ }), r = e && e.__importStar || function(e) {
1916
+ if (e && e.__esModule) return e;
1917
+ var r = {};
1918
+ if (e != null) for (var i in e) i !== "default" && Object.prototype.hasOwnProperty.call(e, i) && t(r, e, i);
1919
+ return n(r, e), r;
1920
+ };
1921
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.HTTP = void 0;
1922
+ var i = h(), a = r((P(), p(E)));
1923
+ e.HTTP = class {
1924
+ constructor(e, t = {}) {
1925
+ this.client = e, this.headers = t;
1926
+ }
1927
+ get(e, t = {}) {
1928
+ return this.request("get", e, t);
1929
+ }
1930
+ post(e, t = {}) {
1931
+ return this.request("post", e, t);
1932
+ }
1933
+ del(e, t = {}) {
1934
+ return this.request("del", e, t);
1935
+ }
1936
+ put(e, t = {}) {
1937
+ return this.request("put", e, t);
1938
+ }
1939
+ request(e, t, n = {}) {
1940
+ return a[e](this.client.getHttpEndpoint(t), this.getOptions(n)).catch((e) => {
1941
+ let t = e.statusCode, n = e.data?.error || e.statusMessage || e.message;
1942
+ throw !t && !n ? e : new i.ServerError(t, n);
1943
+ });
1944
+ }
1945
+ getOptions(e) {
1946
+ return e.headers = Object.assign({}, this.headers, e.headers), this.authToken && (e.headers.Authorization = `Bearer ${this.authToken}`), typeof cc < "u" && cc.sys && cc.sys.isNative || (e.withCredentials = !0), e;
1947
+ }
1948
+ };
1949
+ })), I = /* @__PURE__ */ l(((e) => {
1950
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.getItem = e.removeItem = e.setItem = void 0;
1951
+ var t;
1952
+ function n() {
1953
+ if (!t) try {
1954
+ t = typeof cc < "u" && cc.sys && cc.sys.localStorage ? cc.sys.localStorage : window.localStorage;
1955
+ } catch {}
1956
+ return t ||= {
1957
+ cache: {},
1958
+ setItem: function(e, t) {
1959
+ this.cache[e] = t;
1960
+ },
1961
+ getItem: function(e) {
1962
+ this.cache[e];
1963
+ },
1964
+ removeItem: function(e) {
1965
+ delete this.cache[e];
1966
+ }
1967
+ }, t;
1968
+ }
1969
+ function r(e, t) {
1970
+ n().setItem(e, t);
1971
+ }
1972
+ e.setItem = r;
1973
+ function i(e) {
1974
+ n().removeItem(e);
1975
+ }
1976
+ e.removeItem = i;
1977
+ function a(e, t) {
1978
+ let r = n().getItem(e);
1979
+ typeof Promise > "u" || !(r instanceof Promise) ? t(r) : r.then((e) => t(e));
1980
+ }
1981
+ e.getItem = a;
1982
+ })), L = /* @__PURE__ */ l(((e) => {
1983
+ var t = e && e.__awaiter || function(e, t, n, r) {
1984
+ function i(e) {
1985
+ return e instanceof n ? e : new n(function(t) {
1986
+ t(e);
1987
+ });
1988
+ }
1989
+ return new (n ||= Promise)(function(n, a) {
1990
+ function o(e) {
1991
+ try {
1992
+ c(r.next(e));
1993
+ } catch (e) {
1994
+ a(e);
1995
+ }
1996
+ }
1997
+ function s(e) {
1998
+ try {
1999
+ c(r.throw(e));
2000
+ } catch (e) {
2001
+ a(e);
2002
+ }
2003
+ }
2004
+ function c(e) {
2005
+ e.done ? n(e.value) : i(e.value).then(o, s);
2006
+ }
2007
+ c((r = r.apply(e, t || [])).next());
2008
+ });
2009
+ }, n = e && e.__classPrivateFieldGet || function(e, t, n, r) {
2010
+ if (n === "a" && !r) throw TypeError("Private accessor was defined without a getter");
2011
+ if (typeof t == "function" ? e !== t || !r : !t.has(e)) throw TypeError("Cannot read private member from an object whose class did not declare it");
2012
+ return n === "m" ? r : n === "a" ? r.call(e) : r ? r.value : t.get(e);
2013
+ }, r = e && e.__classPrivateFieldSet || function(e, t, n, r, i) {
2014
+ if (r === "m") throw TypeError("Private method is not writable");
2015
+ if (r === "a" && !i) throw TypeError("Private accessor was defined without a setter");
2016
+ if (typeof t == "function" ? e !== t || !i : !t.has(e)) throw TypeError("Cannot write private member to an object whose class did not declare it");
2017
+ return r === "a" ? i.call(e, n) : i ? i.value = n : t.set(e, n), n;
2018
+ }, i, a, o, s;
2019
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Auth = void 0;
2020
+ var c = I(), l = S();
2021
+ e.Auth = class {
2022
+ constructor(e) {
2023
+ this.http = e, this.settings = {
2024
+ path: "/auth",
2025
+ key: "colyseus-auth-token"
2026
+ }, i.set(this, !1), a.set(this, void 0), o.set(this, void 0), s.set(this, (0, l.createNanoEvents)()), (0, c.getItem)(this.settings.key, (e) => this.token = e);
2027
+ }
2028
+ set token(e) {
2029
+ this.http.authToken = e;
2030
+ }
2031
+ get token() {
2032
+ return this.http.authToken;
2033
+ }
2034
+ onChange(e) {
2035
+ let t = n(this, s, "f").on("change", e);
2036
+ return n(this, i, "f") || r(this, a, new Promise((e, t) => {
2037
+ this.getUserData().then((e) => {
2038
+ this.emitChange(Object.assign(Object.assign({}, e), { token: this.token }));
2039
+ }).catch((e) => {
2040
+ this.emitChange({
2041
+ user: null,
2042
+ token: void 0
2043
+ });
2044
+ }).finally(() => {
2045
+ e();
2046
+ });
2047
+ }), "f"), r(this, i, !0, "f"), t;
2048
+ }
2049
+ getUserData() {
2050
+ return t(this, void 0, void 0, function* () {
2051
+ if (this.token) return (yield this.http.get(`${this.settings.path}/userdata`)).data;
2052
+ throw Error("missing auth.token");
2053
+ });
2054
+ }
2055
+ registerWithEmailAndPassword(e, n, r) {
2056
+ return t(this, void 0, void 0, function* () {
2057
+ let t = (yield this.http.post(`${this.settings.path}/register`, { body: {
2058
+ email: e,
2059
+ password: n,
2060
+ options: r
2061
+ } })).data;
2062
+ return this.emitChange(t), t;
2063
+ });
2064
+ }
2065
+ signInWithEmailAndPassword(e, n) {
2066
+ return t(this, void 0, void 0, function* () {
2067
+ let t = (yield this.http.post(`${this.settings.path}/login`, { body: {
2068
+ email: e,
2069
+ password: n
2070
+ } })).data;
2071
+ return this.emitChange(t), t;
2072
+ });
2073
+ }
2074
+ signInAnonymously(e) {
2075
+ return t(this, void 0, void 0, function* () {
2076
+ let t = (yield this.http.post(`${this.settings.path}/anonymous`, { body: { options: e } })).data;
2077
+ return this.emitChange(t), t;
2078
+ });
2079
+ }
2080
+ sendPasswordResetEmail(e) {
2081
+ return t(this, void 0, void 0, function* () {
2082
+ return (yield this.http.post(`${this.settings.path}/forgot-password`, { body: { email: e } })).data;
2083
+ });
2084
+ }
2085
+ signInWithProvider(e, i = {}) {
2086
+ return t(this, void 0, void 0, function* () {
2087
+ return new Promise((t, a) => {
2088
+ let s = i.width || 480, c = i.height || 768, l = this.token ? `?token=${this.token}` : "", u = `Login with ${e[0].toUpperCase() + e.substring(1)}`, d = this.http.client.getHttpEndpoint(`${i.prefix || `${this.settings.path}/provider`}/${e}${l}`), f = screen.width / 2 - s / 2, p = screen.height / 2 - c / 2;
2089
+ r(this, o, window.open(d, u, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + s + ", height=" + c + ", top=" + p + ", left=" + f), "f");
2090
+ let m = (e) => {
2091
+ e.data.user === void 0 && e.data.token === void 0 || (clearInterval(h), n(this, o, "f").close(), r(this, o, void 0, "f"), window.removeEventListener("message", m), e.data.error === void 0 ? (t(e.data), this.emitChange(e.data)) : a(e.data.error));
2092
+ }, h = setInterval(() => {
2093
+ (!n(this, o, "f") || n(this, o, "f").closed) && (r(this, o, void 0, "f"), a("cancelled"), window.removeEventListener("message", m));
2094
+ }, 200);
2095
+ window.addEventListener("message", m);
2096
+ });
2097
+ });
2098
+ }
2099
+ signOut() {
2100
+ return t(this, void 0, void 0, function* () {
2101
+ this.emitChange({
2102
+ user: null,
2103
+ token: null
2104
+ });
2105
+ });
2106
+ }
2107
+ emitChange(e) {
2108
+ e.token !== void 0 && (this.token = e.token, e.token === null ? (0, c.removeItem)(this.settings.key) : (0, c.setItem)(this.settings.key, e.token)), n(this, s, "f").emit("change", e);
2109
+ }
2110
+ }, i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap();
2111
+ })), ee = /* @__PURE__ */ l(((e) => {
2112
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.discordURLBuilder = void 0;
2113
+ function t(e) {
2114
+ let t = (window == null ? void 0 : window.location)?.hostname || "localhost", n = e.hostname.split("."), r = !e.hostname.includes("trycloudflare.com") && !e.hostname.includes("discordsays.com") && n.length > 2 ? `/${n[0]}` : "";
2115
+ return e.pathname.startsWith("/.proxy") ? `${e.protocol}//${t}${r}${e.pathname}${e.search}` : `${e.protocol}//${t}/.proxy/colyseus${r}${e.pathname}${e.search}`;
2116
+ }
2117
+ e.discordURLBuilder = t;
2118
+ })), te = /* @__PURE__ */ l(((e) => {
2119
+ var t = e && e.__awaiter || function(e, t, n, r) {
2120
+ function i(e) {
2121
+ return e instanceof n ? e : new n(function(t) {
2122
+ t(e);
2123
+ });
2124
+ }
2125
+ return new (n ||= Promise)(function(n, a) {
2126
+ function o(e) {
2127
+ try {
2128
+ c(r.next(e));
2129
+ } catch (e) {
2130
+ a(e);
2131
+ }
2132
+ }
2133
+ function s(e) {
2134
+ try {
2135
+ c(r.throw(e));
2136
+ } catch (e) {
2137
+ a(e);
2138
+ }
2139
+ }
2140
+ function c(e) {
2141
+ e.done ? n(e.value) : i(e.value).then(o, s);
2142
+ }
2143
+ c((r = r.apply(e, t || [])).next());
2144
+ });
2145
+ };
2146
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.Client = e.MatchMakeError = void 0;
2147
+ var n = h(), r = T(), i = F(), a = L(), o = ee(), s = class e extends Error {
2148
+ constructor(t, n) {
2149
+ super(t), this.code = n, Object.setPrototypeOf(this, e.prototype);
2150
+ }
2151
+ };
2152
+ e.MatchMakeError = s;
2153
+ var c = typeof window < "u" && (window == null ? void 0 : window.location)?.hostname !== void 0 ? `${window.location.protocol.replace("http", "ws")}//${window.location.hostname}${window.location.port && `:${window.location.port}`}` : "ws://127.0.0.1:2567";
2154
+ e.Client = class {
2155
+ constructor(e = c, t) {
2156
+ if (typeof e == "string") {
2157
+ let t = e.startsWith("/") ? new URL(e, c) : new URL(e), n = t.protocol === "https:" || t.protocol === "wss:", r = Number(t.port || (n ? 443 : 80));
2158
+ this.settings = {
2159
+ hostname: t.hostname,
2160
+ pathname: t.pathname,
2161
+ port: r,
2162
+ secure: n
2163
+ };
2164
+ } else e.port === void 0 && (e.port = e.secure ? 443 : 80), e.pathname === void 0 && (e.pathname = ""), this.settings = e;
2165
+ this.settings.pathname.endsWith("/") && (this.settings.pathname = this.settings.pathname.slice(0, -1)), this.http = new i.HTTP(this, t?.headers || {}), this.auth = new a.Auth(this.http), this.urlBuilder = t?.urlBuilder, !this.urlBuilder && typeof window < "u" && ((window == null ? void 0 : window.location)?.hostname)?.includes("discordsays.com") && (this.urlBuilder = o.discordURLBuilder, console.log("Colyseus SDK: Discord Embedded SDK detected. Using custom URL builder."));
2166
+ }
2167
+ joinOrCreate(e, n = {}, r) {
2168
+ return t(this, void 0, void 0, function* () {
2169
+ return yield this.createMatchMakeRequest("joinOrCreate", e, n, r);
2170
+ });
2171
+ }
2172
+ create(e, n = {}, r) {
2173
+ return t(this, void 0, void 0, function* () {
2174
+ return yield this.createMatchMakeRequest("create", e, n, r);
2175
+ });
2176
+ }
2177
+ join(e, n = {}, r) {
2178
+ return t(this, void 0, void 0, function* () {
2179
+ return yield this.createMatchMakeRequest("join", e, n, r);
2180
+ });
2181
+ }
2182
+ joinById(e, n = {}, r) {
2183
+ return t(this, void 0, void 0, function* () {
2184
+ return yield this.createMatchMakeRequest("joinById", e, n, r);
2185
+ });
2186
+ }
2187
+ reconnect(e, n) {
2188
+ return t(this, void 0, void 0, function* () {
2189
+ if (typeof e == "string" && typeof n == "string") throw Error("DEPRECATED: .reconnect() now only accepts 'reconnectionToken' as argument.\nYou can get this token from previously connected `room.reconnectionToken`");
2190
+ let [t, r] = e.split(":");
2191
+ if (!t || !r) throw Error("Invalid reconnection token format.\nThe format should be roomId:reconnectionToken");
2192
+ return yield this.createMatchMakeRequest("reconnect", t, { reconnectionToken: r }, n);
2193
+ });
2194
+ }
2195
+ getAvailableRooms(e = "") {
2196
+ return t(this, void 0, void 0, function* () {
2197
+ return (yield this.http.get(`matchmake/${e}`, { headers: { Accept: "application/json" } })).data;
2198
+ });
2199
+ }
2200
+ consumeSeatReservation(e, r, i) {
2201
+ return t(this, void 0, void 0, function* () {
2202
+ let a = this.createRoom(e.room.name, r);
2203
+ a.roomId = e.room.roomId, a.sessionId = e.sessionId;
2204
+ let o = { sessionId: a.sessionId };
2205
+ e.reconnectionToken && (o.reconnectionToken = e.reconnectionToken);
2206
+ let s = i || a;
2207
+ return a.connect(this.buildEndpoint(e.room, o), e.devMode && (() => t(this, void 0, void 0, function* () {
2208
+ console.info(`[Colyseus devMode]: ${String.fromCodePoint(128260)} Re-establishing connection with room id '${a.roomId}'...`);
2209
+ let n = 0, i = () => t(this, void 0, void 0, function* () {
2210
+ n++;
2211
+ try {
2212
+ yield this.consumeSeatReservation(e, r, s), console.info(`[Colyseus devMode]: ${String.fromCodePoint(9989)} Successfully re-established connection with room '${a.roomId}'`);
2213
+ } catch {
2214
+ n < 8 ? (console.info(`[Colyseus devMode]: ${String.fromCodePoint(128260)} retrying... (${n} out of 8)`), setTimeout(i, 2e3)) : console.info(`[Colyseus devMode]: ${String.fromCodePoint(10060)} Failed to reconnect. Is your server running? Please check server logs.`);
2215
+ }
2216
+ });
2217
+ setTimeout(i, 2e3);
2218
+ })), s, this.http.headers), new Promise((e, t) => {
2219
+ let r = (e, r) => t(new n.ServerError(e, r));
2220
+ s.onError.once(r), s.onJoin.once(() => {
2221
+ s.onError.remove(r), e(s);
2222
+ });
2223
+ });
2224
+ });
2225
+ }
2226
+ createMatchMakeRequest(e, n, r = {}, i, a) {
2227
+ return t(this, void 0, void 0, function* () {
2228
+ let t = (yield this.http.post(`matchmake/${e}/${n}`, {
2229
+ headers: {
2230
+ Accept: "application/json",
2231
+ "Content-Type": "application/json"
2232
+ },
2233
+ body: JSON.stringify(r)
2234
+ })).data;
2235
+ if (t.error) throw new s(t.error, t.code);
2236
+ return e === "reconnect" && (t.reconnectionToken = r.reconnectionToken), yield this.consumeSeatReservation(t, i, a);
2237
+ });
2238
+ }
2239
+ createRoom(e, t) {
2240
+ return new r.Room(e, t);
2241
+ }
2242
+ buildEndpoint(e, t = {}) {
2243
+ let n = [];
2244
+ for (let e in t) t.hasOwnProperty(e) && n.push(`${e}=${t[e]}`);
2245
+ let r = this.settings.secure ? "wss://" : "ws://";
2246
+ e.publicAddress ? r += `${e.publicAddress}` : r += `${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}`;
2247
+ let i = `${r}/${e.processId}/${e.roomId}?${n.join("&")}`;
2248
+ return this.urlBuilder ? this.urlBuilder(new URL(i)) : i;
2249
+ }
2250
+ getHttpEndpoint(e = "") {
2251
+ let t = e.startsWith("/") ? e : `/${e}`, n = `${this.settings.secure ? "https" : "http"}://${this.settings.hostname}${this.getEndpointPort()}${this.settings.pathname}${t}`;
2252
+ return this.urlBuilder ? this.urlBuilder(new URL(n)) : n;
2253
+ }
2254
+ getEndpointPort() {
2255
+ return this.settings.port !== 80 && this.settings.port !== 443 ? `:${this.settings.port}` : "";
2256
+ }
2257
+ };
2258
+ })), R = /* @__PURE__ */ l(((e) => {
2259
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.SchemaSerializer = void 0;
2260
+ var t = w();
2261
+ e.SchemaSerializer = class {
2262
+ setState(e) {
2263
+ return this.state.decode(e);
2264
+ }
2265
+ getState() {
2266
+ return this.state;
2267
+ }
2268
+ patch(e) {
2269
+ return this.state.decode(e);
2270
+ }
2271
+ teardown() {
2272
+ var e;
2273
+ (e = this.state?.$changes) == null || e.root.clearRefs();
2274
+ }
2275
+ handshake(e, n) {
2276
+ this.state ? new t.Reflection().decode(e, n) : this.state = t.Reflection.decode(e, n);
2277
+ }
2278
+ };
2279
+ })), ne = /* @__PURE__ */ l(((e) => {
2280
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.NoneSerializer = void 0, e.NoneSerializer = class {
2281
+ setState(e) {}
2282
+ getState() {
2283
+ return null;
2284
+ }
2285
+ patch(e) {}
2286
+ teardown() {}
2287
+ handshake(e) {}
2288
+ };
2289
+ })), re = /* @__PURE__ */ f((/* @__PURE__ */ l(((e) => {
2290
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.SchemaSerializer = e.registerSerializer = e.Auth = e.Room = e.ErrorCode = e.Protocol = e.MatchMakeError = e.Client = void 0, m();
2291
+ var t = te();
2292
+ Object.defineProperty(e, "Client", {
2293
+ enumerable: !0,
2294
+ get: function() {
2295
+ return t.Client;
2296
+ }
2297
+ }), Object.defineProperty(e, "MatchMakeError", {
2298
+ enumerable: !0,
2299
+ get: function() {
2300
+ return t.MatchMakeError;
2301
+ }
2302
+ });
2303
+ var n = b();
2304
+ Object.defineProperty(e, "Protocol", {
2305
+ enumerable: !0,
2306
+ get: function() {
2307
+ return n.Protocol;
2308
+ }
2309
+ }), Object.defineProperty(e, "ErrorCode", {
2310
+ enumerable: !0,
2311
+ get: function() {
2312
+ return n.ErrorCode;
2313
+ }
2314
+ });
2315
+ var r = T();
2316
+ Object.defineProperty(e, "Room", {
2317
+ enumerable: !0,
2318
+ get: function() {
2319
+ return r.Room;
2320
+ }
2321
+ });
2322
+ var i = L();
2323
+ Object.defineProperty(e, "Auth", {
2324
+ enumerable: !0,
2325
+ get: function() {
2326
+ return i.Auth;
2327
+ }
2328
+ });
2329
+ var a = R();
2330
+ Object.defineProperty(e, "SchemaSerializer", {
2331
+ enumerable: !0,
2332
+ get: function() {
2333
+ return a.SchemaSerializer;
2334
+ }
2335
+ });
2336
+ var o = ne(), s = x();
2337
+ Object.defineProperty(e, "registerSerializer", {
2338
+ enumerable: !0,
2339
+ get: function() {
2340
+ return s.registerSerializer;
2341
+ }
2342
+ }), (0, s.registerSerializer)("schema", a.SchemaSerializer), (0, s.registerSerializer)("none", o.NoneSerializer);
2343
+ })))()), z = class extends t {
2344
+ get client() {
2345
+ return this._client;
2346
+ }
2347
+ async initialize(t, n) {
2348
+ if (!n) throw Error("Application instance is required for ColyseusPlugin initialization.");
2349
+ this._options = {
2350
+ port: n.env.VITE_COLYSEUS_PORT || n.env.COLYSEUS_PORT || "2567",
2351
+ ...t || {}
2352
+ }, e.log("Colyseus plugin initialized"), this._client ||= new re.Client(`ws://localhost:${this.options.port}`);
2353
+ }
2354
+ async joinOrCreate(e, t, n) {
2355
+ return this._client.joinOrCreate(e, t, n);
2356
+ }
2357
+ async join(e, t, n) {
2358
+ return this._client.join(e, t, n);
2359
+ }
2360
+ async joinById(e, t, n) {
2361
+ return this._client.joinById(e, t, n);
2362
+ }
2363
+ async create(e, t, n) {
2364
+ return this._client.joinById(e, t, n);
2365
+ }
2366
+ };
2367
+ //#endregion
2368
+ export { z as default };
2369
+
2370
+ //# sourceMappingURL=caper-plugin-colyseus.mjs.map