p2p-lockstep-kit-ui 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -349,7 +349,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
349
349
  }
350
350
  return i;
351
351
  };
352
- })), te = /* @__PURE__ */ o(((e) => {
352
+ })), w = /* @__PURE__ */ o(((e) => {
353
353
  var t = y(), n = [
354
354
  1,
355
355
  1,
@@ -690,7 +690,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
690
690
  default: return;
691
691
  }
692
692
  };
693
- })), w = /* @__PURE__ */ o(((e) => {
693
+ })), T = /* @__PURE__ */ o(((e) => {
694
694
  var t = new Uint8Array(512), n = new Uint8Array(256);
695
695
  (function() {
696
696
  let e = 1;
@@ -704,8 +704,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
704
704
  }, e.mul = function(e, r) {
705
705
  return e === 0 || r === 0 ? 0 : t[n[e] + n[r]];
706
706
  };
707
- })), ne = /* @__PURE__ */ o(((e) => {
708
- var t = w();
707
+ })), te = /* @__PURE__ */ o(((e) => {
708
+ var t = T();
709
709
  e.mul = function(e, n) {
710
710
  let r = new Uint8Array(e.length + n.length - 1);
711
711
  for (let i = 0; i < e.length; i++) for (let a = 0; a < n.length; a++) r[i + a] ^= t.mul(e[i], n[a]);
@@ -725,8 +725,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
725
725
  for (let i = 0; i < n; i++) r = e.mul(r, new Uint8Array([1, t.exp(i)]));
726
726
  return r;
727
727
  };
728
- })), re = /* @__PURE__ */ o(((e, t) => {
729
- var n = ne();
728
+ })), ne = /* @__PURE__ */ o(((e, t) => {
729
+ var n = te();
730
730
  function r(e) {
731
731
  this.genPoly = void 0, this.degree = e, this.degree && this.initialize(this.degree);
732
732
  }
@@ -743,11 +743,11 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
743
743
  }
744
744
  return r;
745
745
  }, t.exports = r;
746
- })), T = /* @__PURE__ */ o(((e) => {
746
+ })), E = /* @__PURE__ */ o(((e) => {
747
747
  e.isValid = function(e) {
748
748
  return !isNaN(e) && e >= 1 && e <= 40;
749
749
  };
750
- })), E = /* @__PURE__ */ o(((e) => {
750
+ })), D = /* @__PURE__ */ o(((e) => {
751
751
  var t = "[0-9]+", n = "[A-Z $%*+\\-./:]+", r = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
752
752
  r = r.replace(/u/g, "\\u");
753
753
  var i = "(?:(?![A-Z0-9 $%*+\\-./:]|" + r + ")(?:.|[\r\n]))+";
@@ -760,8 +760,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
760
760
  }, e.testAlphanumeric = function(e) {
761
761
  return s.test(e);
762
762
  };
763
- })), D = /* @__PURE__ */ o(((e) => {
764
- var t = T(), n = E();
763
+ })), O = /* @__PURE__ */ o(((e) => {
764
+ var t = E(), n = D();
765
765
  e.NUMERIC = {
766
766
  id: "Numeric",
767
767
  bit: 1,
@@ -824,8 +824,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
824
824
  return n;
825
825
  }
826
826
  };
827
- })), ie = /* @__PURE__ */ o(((e) => {
828
- var t = v(), n = te(), r = y(), i = D(), a = T(), o = 7973, s = t.getBCHDigit(o);
827
+ })), re = /* @__PURE__ */ o(((e) => {
828
+ var t = v(), n = w(), r = y(), i = O(), a = E(), o = 7973, s = t.getBCHDigit(o);
829
829
  function c(t, n, r) {
830
830
  for (let i = 1; i <= 40; i++) if (n <= e.getCapacity(i, r, t)) return i;
831
831
  }
@@ -871,15 +871,15 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
871
871
  for (; t.getBCHDigit(n) - s >= 0;) n ^= o << t.getBCHDigit(n) - s;
872
872
  return e << 12 | n;
873
873
  };
874
- })), ae = /* @__PURE__ */ o(((e) => {
874
+ })), ie = /* @__PURE__ */ o(((e) => {
875
875
  var t = v(), n = 1335, r = 21522, i = t.getBCHDigit(n);
876
876
  e.getEncodedBits = function(e, a) {
877
877
  let o = e.bit << 3 | a, s = o << 10;
878
878
  for (; t.getBCHDigit(s) - i >= 0;) s ^= n << t.getBCHDigit(s) - i;
879
879
  return (o << 10 | s) ^ r;
880
880
  };
881
- })), oe = /* @__PURE__ */ o(((e, t) => {
882
- var n = D();
881
+ })), ae = /* @__PURE__ */ o(((e, t) => {
882
+ var n = O();
883
883
  function r(e) {
884
884
  this.mode = n.NUMERIC, this.data = e.toString();
885
885
  }
@@ -895,8 +895,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
895
895
  let i = this.data.length - t;
896
896
  i > 0 && (n = this.data.substr(t), r = parseInt(n, 10), e.put(r, i * 3 + 1));
897
897
  }, t.exports = r;
898
- })), se = /* @__PURE__ */ o(((e, t) => {
899
- var n = D(), r = /* @__PURE__ */ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".split("");
898
+ })), oe = /* @__PURE__ */ o(((e, t) => {
899
+ var n = O(), r = /* @__PURE__ */ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".split("");
900
900
  function i(e) {
901
901
  this.mode = n.ALPHANUMERIC, this.data = e;
902
902
  }
@@ -914,8 +914,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
914
914
  }
915
915
  this.data.length % 2 && e.put(r.indexOf(this.data[t]), 6);
916
916
  }, t.exports = i;
917
- })), ce = /* @__PURE__ */ o(((e, t) => {
918
- var n = D();
917
+ })), se = /* @__PURE__ */ o(((e, t) => {
918
+ var n = O();
919
919
  function r(e) {
920
920
  this.mode = n.BYTE, typeof e == "string" ? this.data = new TextEncoder().encode(e) : this.data = new Uint8Array(e);
921
921
  }
@@ -928,8 +928,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
928
928
  }, r.prototype.write = function(e) {
929
929
  for (let t = 0, n = this.data.length; t < n; t++) e.put(this.data[t], 8);
930
930
  }, t.exports = r;
931
- })), le = /* @__PURE__ */ o(((e, t) => {
932
- var n = D(), r = v();
931
+ })), ce = /* @__PURE__ */ o(((e, t) => {
932
+ var n = O(), r = v();
933
933
  function i(e) {
934
934
  this.mode = n.KANJI, this.data = e;
935
935
  }
@@ -949,7 +949,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
949
949
  n = (n >>> 8 & 255) * 192 + (n & 255), e.put(n, 13);
950
950
  }
951
951
  }, t.exports = i;
952
- })), ue = /* @__PURE__ */ o(((e, t) => {
952
+ })), le = /* @__PURE__ */ o(((e, t) => {
953
953
  var n = {
954
954
  single_source_shortest_paths: function(e, t, r) {
955
955
  var i = {}, a = {};
@@ -1002,8 +1002,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1002
1002
  }
1003
1003
  };
1004
1004
  t !== void 0 && (t.exports = n);
1005
- })), de = /* @__PURE__ */ o(((e) => {
1006
- var t = D(), n = oe(), r = se(), i = ce(), a = le(), o = E(), s = v(), c = ue();
1005
+ })), ue = /* @__PURE__ */ o(((e) => {
1006
+ var t = O(), n = ae(), r = oe(), i = se(), a = ce(), o = D(), s = v(), c = le();
1007
1007
  function l(e) {
1008
1008
  return unescape(encodeURIComponent(e)).length;
1009
1009
  }
@@ -1130,8 +1130,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1130
1130
  }, e.rawSplit = function(t) {
1131
1131
  return e.fromArray(d(t, s.isKanjiModeEnabled()));
1132
1132
  };
1133
- })), fe = /* @__PURE__ */ o(((e) => {
1134
- var t = v(), n = y(), r = b(), i = x(), a = S(), o = C(), s = ee(), c = te(), l = re(), u = ie(), d = ae(), f = D(), p = de();
1133
+ })), de = /* @__PURE__ */ o(((e) => {
1134
+ var t = v(), n = y(), r = b(), i = x(), a = S(), o = C(), s = ee(), c = w(), l = ne(), u = re(), d = ie(), f = O(), p = ue();
1135
1135
  function m(e, t) {
1136
1136
  let n = e.size, r = o.getPositions(t);
1137
1137
  for (let t = 0; t < r.length; t++) {
@@ -1157,12 +1157,12 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1157
1157
  let n = e.size, r = u.getEncodedBits(t), i, a, o;
1158
1158
  for (let t = 0; t < 18; t++) i = Math.floor(t / 3), a = t % 3 + n - 8 - 3, o = (r >> t & 1) == 1, e.set(i, a, o, !0), e.set(a, i, o, !0);
1159
1159
  }
1160
- function w(e, t, n) {
1160
+ function T(e, t, n) {
1161
1161
  let r = e.size, i = d.getEncodedBits(t, n), a, o;
1162
1162
  for (a = 0; a < 15; a++) o = (i >> a & 1) == 1, a < 6 ? e.set(a, 8, o, !0) : a < 8 ? e.set(a + 1, 8, o, !0) : e.set(r - 15 + a, 8, o, !0), a < 8 ? e.set(8, r - a - 1, o, !0) : a < 9 ? e.set(8, 15 - a - 1 + 1, o, !0) : e.set(8, 15 - a - 1, o, !0);
1163
1163
  e.set(r - 8, 8, 1, !0);
1164
1164
  }
1165
- function ne(e, t) {
1165
+ function te(e, t) {
1166
1166
  let n = e.size, r = -1, i = n - 1, a = 7, o = 0;
1167
1167
  for (let s = n - 1; s > 0; s -= 2) for (s === 6 && s--;;) {
1168
1168
  for (let n = 0; n < 2; n++) if (!e.isReserved(i, s - n)) {
@@ -1175,7 +1175,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1175
1175
  }
1176
1176
  }
1177
1177
  }
1178
- function T(e, n, i) {
1178
+ function E(e, n, i) {
1179
1179
  let a = new r();
1180
1180
  i.forEach(function(t) {
1181
1181
  a.put(t.mode.bit, 4), a.put(t.getLength(), f.getCharCountIndicator(t.mode, e)), t.write(a);
@@ -1184,9 +1184,9 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1184
1184
  for (a.getLengthInBits() + 4 <= o && a.put(0, 4); a.getLengthInBits() % 8 != 0;) a.putBit(0);
1185
1185
  let s = (o - a.getLengthInBits()) / 8;
1186
1186
  for (let e = 0; e < s; e++) a.put(e % 2 ? 17 : 236, 8);
1187
- return E(a, e, n);
1187
+ return D(a, e, n);
1188
1188
  }
1189
- function E(e, n, r) {
1189
+ function D(e, n, r) {
1190
1190
  let i = t.getSymbolTotalCodewords(n), a = i - c.getTotalCodewordsCount(n, r), o = c.getBlocksCount(n, r), s = o - i % o, u = Math.floor(i / o), d = Math.floor(a / o), f = d + 1, p = u - d, m = new l(p), h = 0, g = Array(o), _ = Array(o), v = 0, y = new Uint8Array(e.buffer);
1191
1191
  for (let e = 0; e < o; e++) {
1192
1192
  let t = e < s ? d : f;
@@ -1197,7 +1197,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1197
1197
  for (S = 0; S < p; S++) for (C = 0; C < o; C++) b[x++] = _[C][S];
1198
1198
  return b;
1199
1199
  }
1200
- function oe(e, n, r, a) {
1200
+ function ae(e, n, r, a) {
1201
1201
  let o;
1202
1202
  if (Array.isArray(e)) o = p.fromArray(e);
1203
1203
  else if (typeof e == "string") {
@@ -1212,8 +1212,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1212
1212
  if (!c) throw Error("The amount of data is too big to be stored in a QR Code");
1213
1213
  if (!n) n = c;
1214
1214
  else if (n < c) throw Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + c + ".\n");
1215
- let l = T(n, r, o), d = new i(t.getSymbolSize(n));
1216
- return m(d, n), h(d), g(d, n), w(d, r, 0), n >= 7 && _(d, n), ne(d, l), isNaN(a) && (a = s.getBestMask(d, w.bind(null, d, r))), s.applyMask(a, d), w(d, r, a), {
1215
+ let l = E(n, r, o), d = new i(t.getSymbolSize(n));
1216
+ return m(d, n), h(d), g(d, n), T(d, r, 0), n >= 7 && _(d, n), te(d, l), isNaN(a) && (a = s.getBestMask(d, T.bind(null, d, r))), s.applyMask(a, d), T(d, r, a), {
1217
1217
  modules: d,
1218
1218
  version: n,
1219
1219
  errorCorrectionLevel: r,
@@ -1224,9 +1224,9 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1224
1224
  e.create = function(e, r) {
1225
1225
  if (e === void 0 || e === "") throw Error("No input text");
1226
1226
  let i = n.M, a, o;
1227
- return r !== void 0 && (i = n.from(r.errorCorrectionLevel, n.M), a = u.from(r.version), o = s.from(r.maskPattern), r.toSJISFunc && t.setToSJISFunction(r.toSJISFunc)), oe(e, a, i, o);
1227
+ return r !== void 0 && (i = n.from(r.errorCorrectionLevel, n.M), a = u.from(r.version), o = s.from(r.maskPattern), r.toSJISFunc && t.setToSJISFunction(r.toSJISFunc)), ae(e, a, i, o);
1228
1228
  };
1229
- })), pe = /* @__PURE__ */ o(((e) => {
1229
+ })), fe = /* @__PURE__ */ o(((e) => {
1230
1230
  function t(e) {
1231
1231
  if (typeof e == "number" && (e = e.toString()), typeof e != "string") throw Error("Color should be defined as hex string");
1232
1232
  let t = e.slice().replace("#", "").split("");
@@ -1273,8 +1273,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1273
1273
  t[u++] = d.r, t[u++] = d.g, t[u++] = d.b, t[u] = d.a;
1274
1274
  }
1275
1275
  };
1276
- })), me = /* @__PURE__ */ o(((e) => {
1277
- var t = pe();
1276
+ })), pe = /* @__PURE__ */ o(((e) => {
1277
+ var t = fe();
1278
1278
  function n(e, t, n) {
1279
1279
  e.clearRect(0, 0, t.width, t.height), t.style ||= {}, t.height = n, t.width = n, t.style.height = n + "px", t.style.width = n + "px";
1280
1280
  }
@@ -1296,8 +1296,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1296
1296
  let a = e.render(t, n, i), o = i.type || "image/png", s = i.rendererOpts || {};
1297
1297
  return a.toDataURL(o, s.quality);
1298
1298
  };
1299
- })), he = /* @__PURE__ */ o(((e) => {
1300
- var t = pe();
1299
+ })), me = /* @__PURE__ */ o(((e) => {
1300
+ var t = fe();
1301
1301
  function n(e, t) {
1302
1302
  let n = e.a / 255, r = t + "=\"" + e.hex + "\"";
1303
1303
  return n < 1 ? r + " " + t + "-opacity=\"" + n.toFixed(2).slice(1) + "\"" : r;
@@ -1318,8 +1318,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1318
1318
  let o = t.getOptions(r), s = e.modules.size, c = e.modules.data, l = s + o.margin * 2, u = o.color.light.a ? "<path " + n(o.color.light, "fill") + " d=\"M0 0h" + l + "v" + l + "H0z\"/>" : "", d = "<path " + n(o.color.dark, "stroke") + " d=\"" + i(c, s, o.margin) + "\"/>", f = "viewBox=\"0 0 " + l + " " + l + "\"", p = "<svg xmlns=\"http://www.w3.org/2000/svg\" " + (o.width ? "width=\"" + o.width + "\" height=\"" + o.width + "\" " : "") + f + " shape-rendering=\"crispEdges\">" + u + d + "</svg>\n";
1319
1319
  return typeof a == "function" && a(null, p), p;
1320
1320
  };
1321
- })), ge = /* @__PURE__ */ c((/* @__PURE__ */ o(((e) => {
1322
- var t = _(), n = fe(), r = me(), i = he();
1321
+ })), he = /* @__PURE__ */ c((/* @__PURE__ */ o(((e) => {
1322
+ var t = _(), n = de(), r = pe(), i = me();
1323
1323
  function a(e, r, i, a, o) {
1324
1324
  let s = [].slice.call(arguments, 1), c = s.length, l = typeof s[c - 1] == "function";
1325
1325
  if (!l && !t()) throw Error("Callback required as last argument");
@@ -1346,12 +1346,12 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1346
1346
  e.create = n.create, e.toCanvas = a.bind(null, r.render), e.toDataURL = a.bind(null, r.renderToDataURL), e.toString = a.bind(null, function(e, t, n) {
1347
1347
  return i.render(e, n);
1348
1348
  });
1349
- })))(), 1), _e = {
1349
+ })))(), 1), ge = {
1350
1350
  peerId: "",
1351
1351
  signalUrl: "",
1352
1352
  shareUrl: ""
1353
- }, ve = class extends HTMLElement {
1354
- #e = _e;
1353
+ }, k = class extends HTMLElement {
1354
+ #e = ge;
1355
1355
  #t = !1;
1356
1356
  connectedCallback() {
1357
1357
  this.#t || (this.#t = !0, this.addEventListener("click", this.#n), this.render());
@@ -1398,7 +1398,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1398
1398
  return;
1399
1399
  }
1400
1400
  try {
1401
- await ge.toCanvas(t, e, {
1401
+ await he.toCanvas(t, e, {
1402
1402
  width: 208,
1403
1403
  margin: 1,
1404
1404
  color: {
@@ -1413,7 +1413,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1413
1413
  #n = (e) => {
1414
1414
  e.target?.closest("[data-action='copy-share']") && l(this, "lockstep-copy-share", { value: this.#e.shareUrl });
1415
1415
  };
1416
- }, ye = {
1416
+ }, _e = {
1417
1417
  theme: "light",
1418
1418
  gameTitle: "P2P Lockstep",
1419
1419
  peerId: "",
@@ -1431,10 +1431,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1431
1431
  historyLength: 0,
1432
1432
  lastStart: null,
1433
1433
  lastError: ""
1434
- }, O = (e) => e === "me" ? "Your turn" : e === "peer" ? "Peer turn" : "Waiting", k = (e, t) => t === "ready" ? `${e} ready` : t === "could_start" ? e === "Me" ? "You can start" : "Peer can start" : `${e} idle`, A = (e, t) => {
1434
+ }, A = (e) => e === "me" ? "Your turn" : e === "peer" ? "Peer turn" : "Waiting", j = (e, t) => t === "ready" ? `${e} ready` : t === "could_start" ? e === "Me" ? "You can start" : "Peer can start" : `${e} idle`, ve = (e, t) => {
1435
1435
  let n = e === "Local" ? "You" : "Peer";
1436
1436
  return t === "idle" ? `${n} idle` : t === "ready" ? `${n} ready` : t === "could_start" ? `${n} can start` : `${n} ${t.replaceAll("_", " ")}`;
1437
- }, be = (e, t) => e || t === "connected" ? {
1437
+ }, ye = (e, t) => e || t === "connected" ? {
1438
1438
  label: "Live",
1439
1439
  detail: "connected",
1440
1440
  tone: "bg-[var(--lock-teal)]"
@@ -1462,8 +1462,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1462
1462
  label: "Standby",
1463
1463
  detail: "not registered",
1464
1464
  tone: "bg-[var(--lock-dim)]"
1465
- }, j = class extends HTMLElement {
1466
- #e = ye;
1465
+ }, be = class extends HTMLElement {
1466
+ #e = _e;
1467
1467
  #t = !1;
1468
1468
  connectedCallback() {
1469
1469
  this.#t || (this.#t = !0, this.addEventListener("click", this.#n), this.render());
@@ -1478,7 +1478,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1478
1478
  return this.#e;
1479
1479
  }
1480
1480
  render() {
1481
- let { connected: e, pendingAction: t } = this.#e, n = be(e, this.#e.connectionState), r = k("Me", this.#e.localState), i = k("Peer", this.#e.remoteState), a = A("Local", this.#e.localState), o = A("Remote", this.#e.remoteState), s = `${r} / ${i}`, c = this.#e.lastStart === "local" ? "You" : this.#e.lastStart === "remote" ? "Peer" : "Not started", l = `${this.#e.historyLength} move${this.#e.historyLength === 1 ? "" : "s"} / ${c}`;
1481
+ let { connected: e, pendingAction: t } = this.#e, n = ye(e, this.#e.connectionState), r = j("Me", this.#e.localState), i = j("Peer", this.#e.remoteState), a = ve("Local", this.#e.localState), o = ve("Remote", this.#e.remoteState), s = `${r} / ${i}`, c = this.#e.lastStart === "local" ? "You" : this.#e.lastStart === "remote" ? "Peer" : "Not started", l = `${this.#e.historyLength} move${this.#e.historyLength === 1 ? "" : "s"} / ${c}`;
1482
1482
  this.className = "block", this.innerHTML = `
1483
1483
  <section class="lock-panel relative rounded-[1.25rem] p-2.5 text-sm text-[var(--lock-muted)] sm:rounded-[1.5rem] sm:p-3 lg:rounded-[1.75rem] lg:p-2.5">
1484
1484
  <div class="flex items-center gap-2 lg:hidden">
@@ -1617,7 +1617,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1617
1617
  </article>
1618
1618
  </div>
1619
1619
  </section>
1620
- `, p(this, "[data-mobile-title]", this.#e.gameTitle), p(this, "[data-mobile-connection]", n.label), p(this, "[data-mobile-turn]", `#${this.#e.currentTurn} ${O(this.#e.turnOwner)}`), p(this, "[data-mobile-ready]", s), p(this, "[data-detail-connection]", n.label), p(this, "[data-detail-turn]", `#${this.#e.currentTurn} / ${O(this.#e.turnOwner)}`), p(this, "[data-detail-session]", this.#e.sessionId), p(this, "[data-detail-timeline]", l), p(this, "[data-detail-error]", this.#e.lastError), p(this, "[data-detail-peer]", this.#e.peerId || "not set"), p(this, "[data-detail-remote]", this.#e.remotePeerId || "not set"), p(this, "[data-detail-ready-self]", r), p(this, "[data-detail-ready-peer]", i), p(this, "[data-detail-local-state]", a), p(this, "[data-detail-remote-state]", o), p(this, "[data-title]", this.#e.gameTitle), p(this, "[data-match-meta]", l), p(this, "[data-error-message]", this.#e.lastError), p(this, "[data-connection-state]", n.detail), p(this, "[data-current-turn]", `#${this.#e.currentTurn}`), p(this, "[data-turn-owner]", O(this.#e.turnOwner)), p(this, "[data-session-id]", this.#e.sessionId), p(this, "[data-peer-id]", this.#e.peerId || "Local peer ID will appear after register.")?.setAttribute("title", this.#e.peerId), p(this, "[data-remote-peer-id]", this.#e.remotePeerId || "Remote peer not connected yet.")?.setAttribute("title", this.#e.remotePeerId), p(this, "[data-ready-self]", r), p(this, "[data-ready-peer]", i), p(this, "[data-local-state]", a), p(this, "[data-remote-state]", o);
1620
+ `, p(this, "[data-mobile-title]", this.#e.gameTitle), p(this, "[data-mobile-connection]", n.label), p(this, "[data-mobile-turn]", `#${this.#e.currentTurn} ${A(this.#e.turnOwner)}`), p(this, "[data-mobile-ready]", s), p(this, "[data-detail-connection]", n.label), p(this, "[data-detail-turn]", `#${this.#e.currentTurn} / ${A(this.#e.turnOwner)}`), p(this, "[data-detail-session]", this.#e.sessionId), p(this, "[data-detail-timeline]", l), p(this, "[data-detail-error]", this.#e.lastError), p(this, "[data-detail-peer]", this.#e.peerId || "not set"), p(this, "[data-detail-remote]", this.#e.remotePeerId || "not set"), p(this, "[data-detail-ready-self]", r), p(this, "[data-detail-ready-peer]", i), p(this, "[data-detail-local-state]", a), p(this, "[data-detail-remote-state]", o), p(this, "[data-title]", this.#e.gameTitle), p(this, "[data-match-meta]", l), p(this, "[data-error-message]", this.#e.lastError), p(this, "[data-connection-state]", n.detail), p(this, "[data-current-turn]", `#${this.#e.currentTurn}`), p(this, "[data-turn-owner]", A(this.#e.turnOwner)), p(this, "[data-session-id]", this.#e.sessionId), p(this, "[data-peer-id]", this.#e.peerId || "Local peer ID will appear after register.")?.setAttribute("title", this.#e.peerId), p(this, "[data-remote-peer-id]", this.#e.remotePeerId || "Remote peer not connected yet.")?.setAttribute("title", this.#e.remotePeerId), p(this, "[data-ready-self]", r), p(this, "[data-ready-peer]", i), p(this, "[data-local-state]", a), p(this, "[data-remote-state]", o);
1621
1621
  }
1622
1622
  #n = (e) => {
1623
1623
  let t = e.target?.closest("button[data-theme-mode]");
@@ -1626,7 +1626,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1626
1626
  }, xe = {
1627
1627
  open: !1,
1628
1628
  message: ""
1629
- }, M = class extends HTMLElement {
1629
+ }, Se = class extends HTMLElement {
1630
1630
  #e = xe;
1631
1631
  #t = !1;
1632
1632
  connectedCallback() {
@@ -1648,7 +1648,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1648
1648
  </div>
1649
1649
  `, p(this, "[data-message]", this.#e.message);
1650
1650
  }
1651
- }, N = class extends HTMLElement {
1651
+ }, Ce = class extends HTMLElement {
1652
1652
  #e = !1;
1653
1653
  #t = null;
1654
1654
  #n = null;
@@ -1671,18 +1671,18 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1671
1671
  render() {
1672
1672
  this.className = "block h-full", this.innerHTML = "\n <section class=\"relative h-full min-h-[15rem] overflow-visible rounded-[1.4rem] bg-transparent sm:min-h-[22rem] sm:rounded-[2.2rem] lg:min-h-[32rem] lg:rounded-[2rem]\">\n <div data-board-mount class=\"relative z-10 h-full\"></div>\n <div\n data-placeholder\n class=\"pointer-events-none absolute inset-0 z-20 flex items-center justify-center px-6 text-center text-sm leading-6 text-[var(--lock-muted)]\"\n >\n Board host ready\n </div>\n </section>\n ", this.#n = this.querySelector("[data-board-mount]");
1673
1673
  }
1674
- }, P = (e) => {
1674
+ }, M = (e) => {
1675
1675
  let t = e.hash.replace(/^#/, "");
1676
1676
  return new URLSearchParams(t || e.search);
1677
- }, Se = (e, t, n) => {
1677
+ }, we = (e, t, n) => {
1678
1678
  if (!e) return "";
1679
1679
  let r = new URL(n ?? window.location.href), i = new URLSearchParams();
1680
1680
  return i.set("id", e), t && i.set("url", t), r.hash = i.toString(), r.toString();
1681
- }, Ce = (e) => {
1681
+ }, Te = (e) => {
1682
1682
  let t = e.trim();
1683
1683
  if (!t || !t.includes("://")) return null;
1684
1684
  try {
1685
- let e = P(new URL(t)), n = e.get("id");
1685
+ let e = M(new URL(t)), n = e.get("id");
1686
1686
  return n ? {
1687
1687
  peerId: n,
1688
1688
  signalUrl: e.get("url") ?? ""
@@ -1690,13 +1690,13 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1690
1690
  } catch {
1691
1691
  return null;
1692
1692
  }
1693
- }, we = () => {
1694
- let e = P(new URL(window.location.href));
1693
+ }, N = () => {
1694
+ let e = M(new URL(window.location.href));
1695
1695
  return {
1696
1696
  peerId: e.get("id") ?? "",
1697
1697
  signalUrl: e.get("url") ?? ""
1698
1698
  };
1699
- }, Te = {
1699
+ }, Ee = {
1700
1700
  theme: "light",
1701
1701
  gameTitle: "P2P Lockstep",
1702
1702
  signalUrl: "",
@@ -1706,8 +1706,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1706
1706
  connectionState: "idle",
1707
1707
  registering: !1,
1708
1708
  connecting: !1
1709
- }, F = class extends HTMLElement {
1710
- #e = Te;
1709
+ }, P = class extends HTMLElement {
1710
+ #e = Ee;
1711
1711
  #t = !1;
1712
1712
  #n = !1;
1713
1713
  connectedCallback() {
@@ -1742,7 +1742,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1742
1742
  i && (i.state = {
1743
1743
  peerId: this.#e.peerId,
1744
1744
  signalUrl: this.#e.signalUrl,
1745
- shareUrl: Se(this.#e.peerId, this.#e.signalUrl)
1745
+ shareUrl: we(this.#e.peerId, this.#e.signalUrl)
1746
1746
  });
1747
1747
  }
1748
1748
  #i = (e) => {
@@ -1757,7 +1757,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1757
1757
  return;
1758
1758
  }
1759
1759
  if (t.dataset.field === "target-id") {
1760
- let e = Ce(t.value);
1760
+ let e = Te(t.value);
1761
1761
  if (e) {
1762
1762
  l(this, "lockstep-share-detected", e);
1763
1763
  return;
@@ -1766,7 +1766,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1766
1766
  }
1767
1767
  }
1768
1768
  };
1769
- }, Ee = {
1769
+ }, De = {
1770
1770
  theme: "light",
1771
1771
  gameTitle: "P2P Lockstep",
1772
1772
  peerId: "",
@@ -1789,8 +1789,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
1789
1789
  historyLength: 0,
1790
1790
  lastStart: null,
1791
1791
  lastError: ""
1792
- }, De = class extends HTMLElement {
1793
- #e = Ee;
1792
+ }, F = class extends HTMLElement {
1793
+ #e = De;
1794
1794
  #t = !1;
1795
1795
  #n = null;
1796
1796
  #r = null;
@@ -2267,15 +2267,15 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2267
2267
  console.error(`[rtc-peer] ${t} failed`, e), this.dispatchMedia("DISCONNECT"), this.dispatch("DISCONNECT");
2268
2268
  });
2269
2269
  }
2270
- }, R = "p2p-lockstep-kit:signal-session", Ie = 600 * 1e3, Le = () => {
2270
+ }, R = "p2p-lockstep-kit:signal-session", Ie = () => {
2271
2271
  if (typeof window > "u") return null;
2272
2272
  try {
2273
2273
  return window.localStorage;
2274
2274
  } catch {
2275
2275
  return null;
2276
2276
  }
2277
- }, Re = () => {
2278
- let e = Le();
2277
+ }, Le = () => {
2278
+ let e = Ie();
2279
2279
  if (!e) return null;
2280
2280
  let t = e.getItem(R);
2281
2281
  if (!t) return null;
@@ -2285,8 +2285,8 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2285
2285
  } catch {
2286
2286
  return null;
2287
2287
  }
2288
- }, ze = (e) => {
2289
- let t = Le();
2288
+ }, z = (e) => {
2289
+ let t = Ie();
2290
2290
  if (t) {
2291
2291
  if (!e) {
2292
2292
  t.removeItem(R);
@@ -2294,25 +2294,24 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2294
2294
  }
2295
2295
  t.setItem(R, JSON.stringify(e));
2296
2296
  }
2297
- }, Be = () => {
2298
- ze(null);
2299
- }, Ve = (e, t = Ie) => Date.now() - e.updatedAt > t, He = class {
2297
+ }, Re = () => {
2298
+ z(null);
2299
+ }, ze = class {
2300
2300
  constructor(e = new Ae()) {
2301
2301
  this.peer = null, this.onMessageHandler = null, this.onRemoteStreamHandler = null, this.pendingMediaStream = null, this.onStateChangeHandler = null, this.onMediaChangeHandler = null, this.getLocalPeerId = () => this.peer?.getPeerId() ?? null, this.getRemotePeerId = () => this.peer?.getRemoteId() ?? null, this.peerState = () => this.peer?.getPeerState() ?? "passive", this.mediaState = () => this.peer?.getMediaState() ?? "idle", this.signaling = e;
2302
2302
  }
2303
2303
  async register(e) {
2304
2304
  this.peer?.dispose(), this.peer = null, await this.signaling.connect(e);
2305
- let t = Re(), n = null;
2306
- if (t && Ve(t)) Be();
2307
- else if (t) try {
2305
+ let t = Le(), n = null;
2306
+ if (t) try {
2308
2307
  n = await this.signaling.resume({
2309
2308
  peerId: t.peerId,
2310
2309
  resumeToken: t.resumeToken
2311
2310
  });
2312
2311
  } catch {
2313
- Be();
2312
+ Re();
2314
2313
  }
2315
- n ||= await this.signaling.register(), n.resumeToken && ze({
2314
+ n ||= await this.signaling.register(), n.resumeToken && z({
2316
2315
  peerId: n.peerId,
2317
2316
  resumeToken: n.resumeToken,
2318
2317
  updatedAt: Date.now()
@@ -2361,19 +2360,24 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2361
2360
  onMediaChange(e) {
2362
2361
  this.onMediaChangeHandler = e, e(this.peer?.getMediaState() ?? "idle");
2363
2362
  }
2364
- }, z = (e) => (t, n) => {
2363
+ }, Be = Object.defineProperty, Ve = (e, t, n) => t in e ? Be(e, t, {
2364
+ enumerable: !0,
2365
+ configurable: !0,
2366
+ writable: !0,
2367
+ value: n
2368
+ }) : e[t] = n, B = (e, t, n) => Ve(e, typeof t == "symbol" ? t : t + "", n), V = (e) => (t, n) => {
2365
2369
  let r = e === "debug" ? console.info : console[e];
2366
2370
  if (n !== void 0) {
2367
2371
  r(t, n);
2368
2372
  return;
2369
2373
  }
2370
2374
  r(t);
2371
- }, B = {
2372
- debug: z("debug"),
2373
- info: z("info"),
2374
- warn: z("warn"),
2375
- error: z("error")
2376
- }, Ue = (e) => {
2375
+ }, H = {
2376
+ debug: V("debug"),
2377
+ info: V("info"),
2378
+ warn: V("warn"),
2379
+ error: V("error")
2380
+ }, He = (e) => {
2377
2381
  if (typeof e != "string") return {
2378
2382
  ok: !1,
2379
2383
  error: /* @__PURE__ */ TypeError("decodeSafe expects a serialized string")
@@ -2389,13 +2393,14 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2389
2393
  error: e
2390
2394
  };
2391
2395
  }
2392
- }, We = (e) => {
2396
+ }, Ue = (e) => {
2393
2397
  if (typeof e != "string") return !e || typeof e != "object" ? null : e;
2394
- let t = Ue(e);
2398
+ let t = He(e);
2395
2399
  return !t.ok || !t.value || typeof t.value != "object" ? null : t.value;
2396
- }, Ge = class {
2397
- handlers = {};
2398
- processingQueue = Promise.resolve();
2400
+ }, We = class {
2401
+ constructor() {
2402
+ B(this, "handlers", {}), B(this, "processingQueue", Promise.resolve());
2403
+ }
2399
2404
  emit(e, t, n = "local") {
2400
2405
  this.dispatch({
2401
2406
  type: e,
@@ -2404,11 +2409,11 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2404
2409
  });
2405
2410
  }
2406
2411
  register(e, t) {
2407
- this.handlers[e] = t, B.debug(`[session:bus] registered ${e}`);
2412
+ this.handlers[e] = t, H.debug(`[session:bus] registered ${e}`);
2408
2413
  }
2409
2414
  dispatch(e) {
2410
2415
  this.processingQueue = this.processingQueue.then(async () => {
2411
- B.debug(`[session:bus] dispatch ${e.type}`, {
2416
+ H.debug(`[session:bus] dispatch ${e.type}`, {
2412
2417
  from: e.from,
2413
2418
  payload: e.payload,
2414
2419
  turn: e.turn,
@@ -2417,16 +2422,16 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2417
2422
  let t = this.handlers[e.type];
2418
2423
  if (t) {
2419
2424
  try {
2420
- await t(e), B.debug(`[session:bus] handled ${e.type}`, { from: e.from });
2425
+ await t(e), H.debug(`[session:bus] handled ${e.type}`, { from: e.from });
2421
2426
  } catch (t) {
2422
2427
  console.error(`[CommandBus] Error in ${e.type}:`, t);
2423
2428
  }
2424
2429
  return;
2425
2430
  }
2426
- B.debug(`[session:bus] no handler for ${e.type}`, { from: e.from });
2431
+ H.debug(`[session:bus] no handler for ${e.type}`, { from: e.from });
2427
2432
  });
2428
2433
  }
2429
- }, V = [
2434
+ }, U = [
2430
2435
  {
2431
2436
  from: "idle",
2432
2437
  event: "READY",
@@ -2667,35 +2672,36 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2667
2672
  event: "ONLINE",
2668
2673
  to: "syncing"
2669
2674
  }
2670
- ], Ke = (e, t, n) => {
2671
- if (n) return V.find((r) => r.from === e && r.event === t && r.to === n) ? n : e;
2675
+ ], Ge = (e, t, n) => {
2676
+ if (n) return U.find((r) => r.from === e && r.event === t && r.to === n) ? n : e;
2672
2677
  {
2673
- let n = V.find((n) => n.from === e && n.event === t);
2678
+ let n = U.find((n) => n.from === e && n.event === t);
2674
2679
  return n ? n.to : e;
2675
2680
  }
2676
- }, qe = (e, t, n) => n ? !!V.find((r) => r.from === e && r.event === t && r.to === n) : !!V.find((n) => n.from === e && n.event === t), H = class {
2677
- state;
2681
+ }, Ke = (e, t, n) => n ? !!U.find((r) => r.from === e && r.event === t && r.to === n) : !!U.find((n) => n.from === e && n.event === t), W = class {
2678
2682
  constructor(e = "idle") {
2679
- this.state = e;
2683
+ B(this, "state"), this.state = e;
2680
2684
  }
2681
2685
  getState() {
2682
2686
  return this.state;
2683
2687
  }
2684
2688
  hasNextState(e, t) {
2685
- return qe(this.state, e, t);
2689
+ return Ke(this.state, e, t);
2686
2690
  }
2687
2691
  dispatch(e, t) {
2688
- this.state = Ke(this.state, e, t);
2692
+ this.state = Ge(this.state, e, t);
2689
2693
  }
2690
- }, Je = class {
2694
+ }, qe = class {
2691
2695
  validateMove() {
2692
2696
  return { valid: !0 };
2693
2697
  }
2694
2698
  checkWin() {
2695
2699
  return null;
2696
2700
  }
2697
- }, Ye = class {
2698
- observers = /* @__PURE__ */ new Set();
2701
+ }, Je = class {
2702
+ constructor() {
2703
+ B(this, "observers", /* @__PURE__ */ new Set());
2704
+ }
2699
2705
  subscribe(e) {
2700
2706
  this.observers.add(e);
2701
2707
  }
@@ -2723,9 +2729,10 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2723
2729
  console.error("[StateObserver]", e);
2724
2730
  }
2725
2731
  }
2726
- }, Xe = class {
2727
- observers = /* @__PURE__ */ new Set();
2728
- currentSnapshot = null;
2732
+ }, Ye = class {
2733
+ constructor() {
2734
+ B(this, "observers", /* @__PURE__ */ new Set()), B(this, "currentSnapshot", null);
2735
+ }
2729
2736
  subscribe(e) {
2730
2737
  return this.observers.add(e), () => {
2731
2738
  this.observers.delete(e);
@@ -2771,7 +2778,7 @@ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescr
2771
2778
  return this.observers.size;
2772
2779
  }
2773
2780
  };
2774
- function Ze(e, t = !1) {
2781
+ function Xe(e, t = !1) {
2775
2782
  return {
2776
2783
  localState: e.getState("local"),
2777
2784
  remoteState: e.getState("remote"),
@@ -2782,18 +2789,16 @@ function Ze(e, t = !1) {
2782
2789
  connected: t
2783
2790
  };
2784
2791
  }
2785
- var Qe = class {
2786
- lastNotificationTime = 0;
2787
- notificationThrottleMs = 0;
2792
+ var Ze = class {
2788
2793
  constructor(e, t, n = () => !1) {
2789
- this.stateRef = e, this.uiObserver = t, this.getConnected = n;
2794
+ B(this, "stateRef", e), B(this, "uiObserver", t), B(this, "getConnected", n), B(this, "lastNotificationTime", 0), B(this, "notificationThrottleMs", 0);
2790
2795
  }
2791
2796
  onStateChanged() {
2792
2797
  let e = Date.now();
2793
2798
  if (this.lastNotificationTime + this.notificationThrottleMs > e) return;
2794
2799
  this.lastNotificationTime = e;
2795
- let t = Ze(this.stateRef, this.getConnected());
2796
- B.debug("[session:observer] state snapshot", {
2800
+ let t = Xe(this.stateRef, this.getConnected());
2801
+ H.debug("[session:observer] state snapshot", {
2797
2802
  local: t.localState,
2798
2803
  remote: t.remoteState,
2799
2804
  turn: t.turn,
@@ -2811,20 +2816,9 @@ var Qe = class {
2811
2816
  emitEvent(e) {
2812
2817
  this.uiObserver.notifyGameEvent(e);
2813
2818
  }
2814
- }, $e = class {
2815
- local = new H("idle");
2816
- remote = new H("idle");
2817
- localId = null;
2818
- remoteId = null;
2819
- history = [];
2820
- pendingAction = null;
2821
- pendingUndoCount = null;
2822
- resumeTurn = null;
2823
- lastStart = null;
2824
- gamePlugin = new Je();
2825
- stateObserverManager = new Ye();
2819
+ }, Qe = class {
2826
2820
  constructor(e, t) {
2827
- e && (this.localId = e), t && (this.remoteId = t), B.debug("[session:state] created", {
2821
+ B(this, "local", new W("idle")), B(this, "remote", new W("idle")), B(this, "localId", null), B(this, "remoteId", null), B(this, "history", []), B(this, "pendingAction", null), B(this, "pendingUndoCount", null), B(this, "resumeTurn", null), B(this, "lastStart", null), B(this, "gamePlugin", new qe()), B(this, "stateObserverManager", new Je()), B(this, "gameSnapshot", null), e && (this.localId = e), t && (this.remoteId = t), H.debug("[session:state] created", {
2828
2822
  localId: e,
2829
2823
  remoteId: t
2830
2824
  });
@@ -2839,7 +2833,7 @@ var Qe = class {
2839
2833
  return this.remoteId;
2840
2834
  }
2841
2835
  setremoteId(e) {
2842
- this.remoteId = e, B.debug("[session:state] remote id set", { remoteId: e });
2836
+ this.remoteId = e, H.debug("[session:state] remote id set", { remoteId: e });
2843
2837
  }
2844
2838
  getState(e) {
2845
2839
  return this.getPlayerFsm(e).getState();
@@ -2851,7 +2845,7 @@ var Qe = class {
2851
2845
  return this.history.slice();
2852
2846
  }
2853
2847
  replaceHistory(e) {
2854
- B.debug("[session:history] replace", { count: e.length }), this.clearHistory(), e.forEach((e) => {
2848
+ H.debug("[session:history] replace", { count: e.length }), this.clearHistory(), e.forEach((e) => {
2855
2849
  this.pushHistory({
2856
2850
  turn: e.turn,
2857
2851
  player: e.player,
@@ -2861,10 +2855,10 @@ var Qe = class {
2861
2855
  }
2862
2856
  clearHistory() {
2863
2857
  let e = this.history.length;
2864
- this.history.splice(0, this.history.length), B.debug("[session:history] clear", { count: e }), this.notifyHistoryChanged();
2858
+ this.history.splice(0, this.history.length), H.debug("[session:history] clear", { count: e }), this.notifyHistoryChanged();
2865
2859
  }
2866
2860
  pushHistory(e) {
2867
- this.history.push(e), B.debug("[session:history] push", {
2861
+ this.history.push(e), H.debug("[session:history] push", {
2868
2862
  turn: e.turn,
2869
2863
  player: e.player,
2870
2864
  move: e.move,
@@ -2873,7 +2867,7 @@ var Qe = class {
2873
2867
  }
2874
2868
  popHistory() {
2875
2869
  let e = this.history.pop() ?? null;
2876
- return e && (B.debug("[session:history] pop", {
2870
+ return e && (H.debug("[session:history] pop", {
2877
2871
  turn: e.turn,
2878
2872
  player: e.player,
2879
2873
  move: e.move,
@@ -2887,7 +2881,7 @@ var Qe = class {
2887
2881
  let r = this.getState(e);
2888
2882
  this.getPlayerFsm(e).dispatch(t, n);
2889
2883
  let i = this.getState(e);
2890
- B.debug(`[session:fsm] ${e} ${t}`, {
2884
+ H.debug(`[session:fsm] ${e} ${t}`, {
2891
2885
  from: r,
2892
2886
  to: i,
2893
2887
  requested: n,
@@ -2899,7 +2893,7 @@ var Qe = class {
2899
2893
  }), this.notifyStateChanged();
2900
2894
  }
2901
2895
  setPendingAction(e) {
2902
- B.debug("[session:state] pending action set", {
2896
+ H.debug("[session:state] pending action set", {
2903
2897
  from: this.pendingAction,
2904
2898
  to: e
2905
2899
  }), this.pendingAction = e;
@@ -2908,7 +2902,7 @@ var Qe = class {
2908
2902
  return this.pendingAction;
2909
2903
  }
2910
2904
  setPendingUndoCount(e) {
2911
- B.debug("[session:state] pending undo count set", {
2905
+ H.debug("[session:state] pending undo count set", {
2912
2906
  from: this.pendingUndoCount,
2913
2907
  to: e
2914
2908
  }), this.pendingUndoCount = e;
@@ -2917,7 +2911,7 @@ var Qe = class {
2917
2911
  return this.pendingUndoCount;
2918
2912
  }
2919
2913
  setLastStart(e) {
2920
- B.debug("[session:state] last start set", {
2914
+ H.debug("[session:state] last start set", {
2921
2915
  from: this.lastStart,
2922
2916
  to: e
2923
2917
  }), this.lastStart = e;
@@ -2926,7 +2920,7 @@ var Qe = class {
2926
2920
  return this.lastStart;
2927
2921
  }
2928
2922
  setResumeTurn(e) {
2929
- B.debug("[session:state] resume turn set", {
2923
+ H.debug("[session:state] resume turn set", {
2930
2924
  from: this.resumeTurn,
2931
2925
  to: e
2932
2926
  }), this.resumeTurn = e;
@@ -2938,7 +2932,7 @@ var Qe = class {
2938
2932
  return e === "local" ? this.local : this.remote;
2939
2933
  }
2940
2934
  notifyStateChanged() {
2941
- B.debug("[session:state] notify state changed", {
2935
+ H.debug("[session:state] notify state changed", {
2942
2936
  local: this.getState("local"),
2943
2937
  remote: this.getState("remote"),
2944
2938
  turn: this.getTurnCount(),
@@ -2947,21 +2941,21 @@ var Qe = class {
2947
2941
  }), this.stateObserverManager.notifyStateChanged();
2948
2942
  }
2949
2943
  notifyHistoryChanged() {
2950
- B.debug("[session:state] notify history changed", {
2944
+ H.debug("[session:state] notify history changed", {
2951
2945
  turn: this.getTurnCount(),
2952
2946
  history: this.history.length,
2953
2947
  pending: this.pendingAction
2954
2948
  }), this.stateObserverManager.notifyHistoryChanged();
2955
2949
  }
2956
2950
  notifyGameReset() {
2957
- B.debug("[session:state] notify game reset"), this.stateObserverManager.notifyGameReset();
2951
+ H.debug("[session:state] notify game reset"), this.stateObserverManager.notifyGameReset();
2958
2952
  }
2959
2953
  dispatchPair(e, t, n, r) {
2960
2954
  let i = {
2961
2955
  local: this.local.getState(),
2962
2956
  remote: this.remote.getState()
2963
2957
  };
2964
- this.local.dispatch(e, t), this.remote.dispatch(n, r), B.debug("[session:fsm] pair dispatch", {
2958
+ this.local.dispatch(e, t), this.remote.dispatch(n, r), H.debug("[session:fsm] pair dispatch", {
2965
2959
  before: i,
2966
2960
  after: {
2967
2961
  local: this.local.getState(),
@@ -2976,34 +2970,33 @@ var Qe = class {
2976
2970
  pending: this.pendingAction
2977
2971
  }), this.notifyStateChanged();
2978
2972
  }
2979
- gameSnapshot = null;
2980
2973
  saveGameSnapshot(e) {
2981
- this.gameSnapshot = e, B.debug("[session:state] game snapshot saved", { snapshot: e });
2974
+ this.gameSnapshot = e, H.debug("[session:state] game snapshot saved", { snapshot: e });
2982
2975
  }
2983
2976
  getGameSnapshot() {
2984
2977
  return this.gameSnapshot;
2985
2978
  }
2986
2979
  clearGameSnapshot() {
2987
- this.gameSnapshot = null, B.debug("[session:state] game snapshot cleared");
2980
+ this.gameSnapshot = null, H.debug("[session:state] game snapshot cleared");
2988
2981
  }
2989
2982
  hasPendingAction() {
2990
2983
  return this.pendingAction !== null;
2991
2984
  }
2992
2985
  clearPendingStates() {
2993
- B.debug("[session:state] pending states cleared", {
2986
+ H.debug("[session:state] pending states cleared", {
2994
2987
  pending: this.pendingAction,
2995
2988
  pendingUndoCount: this.pendingUndoCount,
2996
2989
  resumeTurn: this.resumeTurn
2997
2990
  }), this.pendingAction = null, this.pendingUndoCount = null, this.resumeTurn = null, this.notifyStateChanged();
2998
2991
  }
2999
2992
  initializeUndoRequest(e, t) {
3000
- this.pendingAction = "undo", this.pendingUndoCount = e, this.resumeTurn = t, B.debug("[session:state] undo request initialized", {
2993
+ this.pendingAction = "undo", this.pendingUndoCount = e, this.resumeTurn = t, H.debug("[session:state] undo request initialized", {
3001
2994
  undoCount: e,
3002
2995
  resumeTurn: t
3003
2996
  });
3004
2997
  }
3005
2998
  initializeRestartRequest(e) {
3006
- this.pendingAction = "restart", this.resumeTurn = e, B.debug("[session:state] restart request initialized", { resumeTurn: e });
2999
+ this.pendingAction = "restart", this.resumeTurn = e, H.debug("[session:state] restart request initialized", { resumeTurn: e });
3007
3000
  }
3008
3001
  isPendingUndo() {
3009
3002
  return this.pendingAction === "undo";
@@ -3012,20 +3005,20 @@ var Qe = class {
3012
3005
  return this.pendingAction === "restart";
3013
3006
  }
3014
3007
  applyUndo(e = 1) {
3015
- B.debug("[session:history] apply undo", { count: e });
3008
+ H.debug("[session:history] apply undo", { count: e });
3016
3009
  for (let t = 0; t < e; t++) this.popHistory();
3017
3010
  }
3018
3011
  resetGame() {
3019
- B.debug("[session:state] reset game", {
3012
+ H.debug("[session:state] reset game", {
3020
3013
  local: this.getState("local"),
3021
3014
  remote: this.getState("remote"),
3022
3015
  history: this.history.length,
3023
3016
  lastStart: this.lastStart,
3024
3017
  pending: this.pendingAction
3025
- }), this.clearHistory(), this.local = new H("idle"), this.remote = new H("idle"), this.lastStart = null, this.pendingAction = null, this.pendingUndoCount = null, this.resumeTurn = null, this.notifyGameReset(), this.notifyStateChanged();
3018
+ }), this.clearHistory(), this.local = new W("idle"), this.remote = new W("idle"), this.lastStart = null, this.pendingAction = null, this.pendingUndoCount = null, this.resumeTurn = null, this.notifyGameReset(), this.notifyStateChanged();
3026
3019
  }
3027
3020
  recordStartPlayer(e) {
3028
- this.lastStart = e, B.debug("[session:state] start player recorded", { player: e });
3021
+ this.lastStart = e, H.debug("[session:state] start player recorded", { player: e });
3029
3022
  }
3030
3023
  getLastMove() {
3031
3024
  return this.history.length > 0 ? this.history[this.history.length - 1] : null;
@@ -3047,7 +3040,7 @@ var Qe = class {
3047
3040
  remote: this.remote.getState(),
3048
3041
  lastStart: this.lastStart
3049
3042
  };
3050
- e === "local" ? (this.local.dispatch("START", "turn"), this.remote.dispatch("START", "remote_turn"), this.lastStart = "local") : (this.local.dispatch("START", "remote_turn"), this.remote.dispatch("START", "turn"), this.lastStart = "remote"), B.debug("[session:fsm] start dispatch", {
3043
+ e === "local" ? (this.local.dispatch("START", "turn"), this.remote.dispatch("START", "remote_turn"), this.lastStart = "local") : (this.local.dispatch("START", "remote_turn"), this.remote.dispatch("START", "turn"), this.lastStart = "remote"), H.debug("[session:fsm] start dispatch", {
3051
3044
  before: t,
3052
3045
  firstPlayer: e,
3053
3046
  after: {
@@ -3061,7 +3054,7 @@ var Qe = class {
3061
3054
  e === "local" ? this.dispatchPair("SYNC_COMPLETE", "turn", "SYNC_COMPLETE", "remote_turn") : this.dispatchPair("SYNC_COMPLETE", "remote_turn", "SYNC_COMPLETE", "turn"), this.resumeTurn = null;
3062
3055
  }
3063
3056
  setGamePlugin(e) {
3064
- this.gamePlugin = e, B.debug("[session:plugin] game plugin set", {
3057
+ this.gamePlugin = e, H.debug("[session:plugin] game plugin set", {
3065
3058
  hasInitialize: !!e.initialize,
3066
3059
  hasCleanup: !!e.cleanup
3067
3060
  }), e.initialize && e.initialize();
@@ -3071,7 +3064,7 @@ var Qe = class {
3071
3064
  }
3072
3065
  validateMove(e) {
3073
3066
  let t = this.buildGameState(), n = this.gamePlugin.validateMove(e, t);
3074
- return B.debug("[session:plugin] validate move", {
3067
+ return H.debug("[session:plugin] validate move", {
3075
3068
  move: e,
3076
3069
  result: n,
3077
3070
  local: t.localState,
@@ -3082,14 +3075,14 @@ var Qe = class {
3082
3075
  }
3083
3076
  checkWin() {
3084
3077
  let e = this.buildGameState(), t = this.gamePlugin.checkWin(e, this.getHistory());
3085
- return B.debug("[session:plugin] check win", {
3078
+ return H.debug("[session:plugin] check win", {
3086
3079
  winner: t,
3087
3080
  turn: e.turn,
3088
3081
  history: e.history.length
3089
3082
  }), t;
3090
3083
  }
3091
3084
  cleanupGame() {
3092
- this.gamePlugin.cleanup && this.gamePlugin.cleanup(), B.debug("[session:plugin] cleanup game");
3085
+ this.gamePlugin.cleanup && this.gamePlugin.cleanup(), H.debug("[session:plugin] cleanup game");
3093
3086
  }
3094
3087
  buildGameState() {
3095
3088
  return {
@@ -3100,15 +3093,10 @@ var Qe = class {
3100
3093
  lastStart: this.getLastStart()
3101
3094
  };
3102
3095
  }
3103
- }, et = class {
3104
- localPeerId;
3105
- remotePeerId;
3106
- isConnected = !1;
3107
- connectionChangeListener = () => {};
3108
- mediaStateListener = () => {};
3096
+ }, $e = class {
3109
3097
  constructor(e, t, n) {
3110
- this.client = e, this.bus = t, this.localPeerId = n ?? null, this.remotePeerId = null, this.client.onMessage((e) => {
3111
- let t = We(e);
3098
+ B(this, "client", e), B(this, "bus", t), B(this, "localPeerId"), B(this, "remotePeerId"), B(this, "isConnected", !1), B(this, "connectionChangeListener", () => {}), B(this, "mediaStateListener", () => {}), this.localPeerId = n ?? null, this.remotePeerId = null, this.client.onMessage((e) => {
3099
+ let t = Ue(e);
3112
3100
  !t || typeof t != "object" || !t.type || this.bus.dispatch({
3113
3101
  ...t,
3114
3102
  type: t.type,
@@ -3151,13 +3139,9 @@ var Qe = class {
3151
3139
  onMediaStateChange(e) {
3152
3140
  this.mediaStateListener = e;
3153
3141
  }
3154
- }, tt = (e, t, n) => new et(e, t, n), nt = class {
3155
- state;
3156
- bus;
3157
- net;
3158
- sid;
3142
+ }, et = (e, t, n) => new $e(e, t, n), tt = class {
3159
3143
  constructor(e, t, n, r) {
3160
- this.state = e, this.bus = t, this.net = n, this.sid = r;
3144
+ B(this, "state"), B(this, "bus"), B(this, "net"), B(this, "sid"), this.state = e, this.bus = t, this.net = n, this.sid = r;
3161
3145
  }
3162
3146
  getState() {
3163
3147
  return this.state;
@@ -3171,14 +3155,14 @@ var Qe = class {
3171
3155
  getSid() {
3172
3156
  return this.sid;
3173
3157
  }
3174
- }, U = null, rt = (e, t, n, r) => {
3175
- U = new nt(e, t, n, r);
3176
- }, W = () => {
3177
- if (!U) throw Error("[SessionContext] Not initialized. Call initializeContext() first.");
3178
- return U;
3179
- }, G = () => W().getState(), K = () => W().getBus(), it = () => W().getSid(), q = (e) => W().getNet().send(e), at = (e) => {
3180
- let t = G(), n = K(), r = it();
3181
- if (B.debug("[session:ready] received", {
3158
+ }, G = null, nt = (e, t, n, r) => {
3159
+ G = new tt(e, t, n, r);
3160
+ }, K = () => {
3161
+ if (!G) throw Error("[SessionContext] Not initialized. Call initializeContext() first.");
3162
+ return G;
3163
+ }, q = () => K().getState(), J = () => K().getBus(), rt = () => K().getSid(), Y = (e) => K().getNet().send(e), it = (e) => {
3164
+ let t = q(), n = J(), r = rt();
3165
+ if (H.debug("[session:ready] received", {
3182
3166
  from: e.from,
3183
3167
  sid: e.sid,
3184
3168
  localSid: r,
@@ -3189,10 +3173,10 @@ var Qe = class {
3189
3173
  console.warn("[Ready] Cannot dispatch READY from current state", { state: t.getState("local") });
3190
3174
  return;
3191
3175
  }
3192
- t.dispatch("local", "READY"), t.dispatch("remote", "REMOTE_READY"), q({
3176
+ t.dispatch("local", "READY"), t.dispatch("remote", "REMOTE_READY"), Y({
3193
3177
  type: "READY",
3194
3178
  sid: r
3195
- }), B.debug("[session:ready] local toggled", {
3179
+ }), H.debug("[session:ready] local toggled", {
3196
3180
  local: t.getState("local"),
3197
3181
  remote: t.getState("remote")
3198
3182
  });
@@ -3210,13 +3194,13 @@ var Qe = class {
3210
3194
  console.warn("[Ready] Cannot dispatch READY for remote peer", { state: t.getState("remote") });
3211
3195
  return;
3212
3196
  }
3213
- t.dispatch("remote", "READY"), t.dispatch("local", "REMOTE_READY"), B.debug("[session:ready] remote toggled", {
3197
+ t.dispatch("remote", "READY"), t.dispatch("local", "REMOTE_READY"), H.debug("[session:ready] remote toggled", {
3214
3198
  local: t.getState("local"),
3215
3199
  remote: t.getState("remote")
3216
3200
  });
3217
- }, ot = (e) => e ? e === "local" ? "remote" : "local" : Math.random() < .5 ? "local" : "remote", st = (e) => {
3218
- let t = G();
3219
- if (B.debug("[session:start] received", {
3201
+ }, at = (e) => e ? e === "local" ? "remote" : "local" : Math.random() < .5 ? "local" : "remote", ot = (e) => {
3202
+ let t = q();
3203
+ if (H.debug("[session:start] received", {
3220
3204
  from: e.from,
3221
3205
  payload: e.payload,
3222
3206
  local: t.getState("local"),
@@ -3230,11 +3214,11 @@ var Qe = class {
3230
3214
  });
3231
3215
  return;
3232
3216
  }
3233
- let e = ot(t.getLastStart()), n = e === "local" ? "turn" : "remote_turn", r = e === "local" ? "remote_turn" : "turn";
3234
- t.getHistory().length > 0 && (t.clearHistory(), B.debug("[session:start] cleared previous match history")), t.setLastStart(e), t.dispatch("local", "START", n), t.dispatch("remote", "REMOTE_START", r), q({
3217
+ let e = at(t.getLastStart()), n = e === "local" ? "turn" : "remote_turn", r = e === "local" ? "remote_turn" : "turn";
3218
+ t.getHistory().length > 0 && (t.clearHistory(), H.debug("[session:start] cleared previous match history")), t.setLastStart(e), t.dispatch("local", "START", n), t.dispatch("remote", "REMOTE_START", r), Y({
3235
3219
  type: "START",
3236
3220
  payload: { starter: e === "local" ? "sender" : "receiver" }
3237
- }), B.debug("[session:start] local started", { nextStarter: e });
3221
+ }), H.debug("[session:start] local started", { nextStarter: e });
3238
3222
  return;
3239
3223
  }
3240
3224
  let n = e.payload?.starter;
@@ -3250,10 +3234,10 @@ var Qe = class {
3250
3234
  return;
3251
3235
  }
3252
3236
  let r = n === "sender" ? "remote" : "local", i = r === "local" ? "turn" : "remote_turn", a = r === "local" ? "remote_turn" : "turn";
3253
- t.getHistory().length > 0 && (t.clearHistory(), B.debug("[session:start] cleared previous match history")), t.setLastStart(r), t.dispatch("local", "REMOTE_START", i), t.dispatch("remote", "START", a), B.debug("[session:start] remote started", { starter: r });
3254
- }, ct = (e) => {
3255
- let t = G(), n = e.payload;
3256
- if (B.debug("[session:move] received", {
3237
+ t.getHistory().length > 0 && (t.clearHistory(), H.debug("[session:start] cleared previous match history")), t.setLastStart(r), t.dispatch("local", "REMOTE_START", i), t.dispatch("remote", "START", a), H.debug("[session:start] remote started", { starter: r });
3238
+ }, st = (e) => {
3239
+ let t = q(), n = e.payload;
3240
+ if (H.debug("[session:move] received", {
3257
3241
  from: e.from,
3258
3242
  payload: n,
3259
3243
  local: t.getState("local"),
@@ -3279,20 +3263,20 @@ var Qe = class {
3279
3263
  turn: r,
3280
3264
  player: "local",
3281
3265
  move: n
3282
- }), q({
3266
+ }), Y({
3283
3267
  type: "MOVE",
3284
3268
  turn: r,
3285
3269
  payload: n
3286
- }), B.debug("[session:move] local move sent", {
3270
+ }), H.debug("[session:move] local move sent", {
3287
3271
  turn: r,
3288
3272
  payload: n
3289
3273
  });
3290
3274
  let i = t.checkWin();
3291
3275
  if (i) {
3292
- B.debug("[session:move] game over detected", {
3276
+ H.debug("[session:move] game over detected", {
3293
3277
  winner: i,
3294
3278
  turn: r
3295
- }), t.dispatch("local", "GAME_OVER"), t.dispatch("remote", "GAME_OVER"), t.cleanupGame(), B.debug("[session:move] local game over applied", {
3279
+ }), t.dispatch("local", "GAME_OVER"), t.dispatch("remote", "GAME_OVER"), t.cleanupGame(), H.debug("[session:move] local game over applied", {
3296
3280
  winner: i,
3297
3281
  turn: r
3298
3282
  });
@@ -3321,23 +3305,23 @@ var Qe = class {
3321
3305
  });
3322
3306
  let a = t.checkWin();
3323
3307
  if (a) {
3324
- B.debug("[session:move] game over detected", {
3308
+ H.debug("[session:move] game over detected", {
3325
3309
  winner: a,
3326
3310
  turn: i
3327
- }), t.dispatch("local", "GAME_OVER"), t.dispatch("remote", "GAME_OVER"), t.cleanupGame(), B.debug("[session:move] remote game over applied", {
3311
+ }), t.dispatch("local", "GAME_OVER"), t.dispatch("remote", "GAME_OVER"), t.cleanupGame(), H.debug("[session:move] remote game over applied", {
3328
3312
  winner: a,
3329
3313
  turn: i
3330
3314
  });
3331
3315
  return;
3332
3316
  }
3333
- B.debug("[session:move] remote move applied", {
3317
+ H.debug("[session:move] remote move applied", {
3334
3318
  turn: i,
3335
3319
  payload: n
3336
3320
  });
3337
- }, lt = (e) => e === "undo" || e === "restart", ut = (e) => {
3321
+ }, ct = (e) => e === "undo" || e === "restart", lt = (e) => {
3338
3322
  if (e.type !== "APPROVE" && e.type !== "REJECT") return;
3339
- let t = G(), n = e.payload, r = t.getPendingAction(), i = r ?? (e.from === "local" && e.type === "REJECT" && lt(n?.action) ? n.action : null);
3340
- if (B.debug("[session:request] received", {
3323
+ let t = q(), n = e.payload, r = t.getPendingAction(), i = r ?? (e.from === "local" && e.type === "REJECT" && ct(n?.action) ? n.action : null);
3324
+ if (H.debug("[session:request] received", {
3341
3325
  type: e.type,
3342
3326
  from: e.from,
3343
3327
  action: i,
@@ -3357,13 +3341,13 @@ var Qe = class {
3357
3341
  }
3358
3342
  if (e.from === "local") {
3359
3343
  if (!r && e.type === "REJECT") {
3360
- q({
3344
+ Y({
3361
3345
  type: "REJECT",
3362
3346
  payload: {
3363
3347
  action: i,
3364
3348
  reason: n?.reason ?? "rejected"
3365
3349
  }
3366
- }), B.debug("[session:request] local auto rejected", {
3350
+ }), H.debug("[session:request] local auto rejected", {
3367
3351
  action: i,
3368
3352
  reason: n?.reason
3369
3353
  });
@@ -3374,23 +3358,23 @@ var Qe = class {
3374
3358
  console.warn("[Request] Cannot APPROVE from current state");
3375
3359
  return;
3376
3360
  }
3377
- t.dispatchApprove(), i === "undo" ? t.applyUndo(t.getPendingUndoCount() ?? 1) : i === "restart" && t.resetGame(), q({
3361
+ t.dispatchApprove(), i === "undo" ? t.applyUndo(t.getPendingUndoCount() ?? 1) : i === "restart" && t.resetGame(), Y({
3378
3362
  type: "APPROVE",
3379
3363
  payload: { action: i }
3380
- }), t.clearPendingStates(), B.debug("[session:request] local approved", { action: i });
3364
+ }), t.clearPendingStates(), H.debug("[session:request] local approved", { action: i });
3381
3365
  return;
3382
3366
  }
3383
3367
  if (!t.canAction("local", "REJECT")) {
3384
3368
  console.warn("[Request] Cannot REJECT from current state");
3385
3369
  return;
3386
3370
  }
3387
- t.dispatchReject(), q({
3371
+ t.dispatchReject(), Y({
3388
3372
  type: "REJECT",
3389
3373
  payload: {
3390
3374
  action: i,
3391
3375
  reason: n?.reason ?? "rejected"
3392
3376
  }
3393
- }), t.clearPendingStates(), B.debug("[session:request] local rejected", { action: i });
3377
+ }), t.clearPendingStates(), H.debug("[session:request] local rejected", { action: i });
3394
3378
  return;
3395
3379
  }
3396
3380
  if (e.type === "APPROVE") {
@@ -3398,58 +3382,58 @@ var Qe = class {
3398
3382
  console.warn("[Request] Cannot APPROVE from current state (remote approved)");
3399
3383
  return;
3400
3384
  }
3401
- t.dispatchApprove(), i === "undo" ? t.applyUndo(t.getPendingUndoCount() ?? 1) : i === "restart" && t.resetGame(), t.clearPendingStates(), B.debug("[session:request] remote approved", { action: i });
3385
+ t.dispatchApprove(), i === "undo" ? t.applyUndo(t.getPendingUndoCount() ?? 1) : i === "restart" && t.resetGame(), t.clearPendingStates(), H.debug("[session:request] remote approved", { action: i });
3402
3386
  return;
3403
3387
  }
3404
3388
  if (!t.canAction("local", "REJECT")) {
3405
3389
  console.warn("[Request] Cannot REJECT from current state (remote rejected)"), t.clearPendingStates();
3406
3390
  return;
3407
3391
  }
3408
- t.dispatchReject(), t.clearPendingStates(), B.debug("[session:request] remote rejected", { action: i });
3409
- }, dt = (e) => e === "local" ? "remote" : "local", ft = () => {
3410
- let e = G();
3392
+ t.dispatchReject(), t.clearPendingStates(), H.debug("[session:request] remote rejected", { action: i });
3393
+ }, ut = (e) => e === "local" ? "remote" : "local", dt = () => {
3394
+ let e = q();
3411
3395
  return e.getResumeTurn() ?? (e.getState("local") === "turn" ? "local" : "remote");
3412
- }, pt = () => {
3413
- let e = G(), t = ft();
3396
+ }, ft = () => {
3397
+ let e = q(), t = dt();
3414
3398
  return {
3415
3399
  history: e.getHistory(),
3416
3400
  lastStart: e.getLastStart(),
3417
3401
  turn: t,
3418
3402
  resumeTurn: e.getResumeTurn()
3419
3403
  };
3420
- }, mt = () => {
3421
- let e = G();
3404
+ }, pt = () => {
3405
+ let e = q();
3422
3406
  return e.getState("local") === "syncing" || e.getState("remote") === "syncing" || e.getState("remote") === "offline" || e.getResumeTurn() !== null;
3423
- }, ht = () => {
3424
- let e = G();
3407
+ }, mt = () => {
3408
+ let e = q();
3425
3409
  if (e.getState("local") !== "syncing") {
3426
- if (!e.canAction("local", "SYNC")) return B.debug("[session:sync] local cannot enter sync", { local: e.getState("local") }), !1;
3410
+ if (!e.canAction("local", "SYNC")) return H.debug("[session:sync] local cannot enter sync", { local: e.getState("local") }), !1;
3427
3411
  e.dispatch("local", "SYNC", "syncing");
3428
3412
  }
3429
3413
  if (e.getState("remote") === "offline") {
3430
- if (!e.canAction("remote", "ONLINE")) return B.debug("[session:sync] offline remote cannot enter sync", { remote: e.getState("remote") }), !1;
3414
+ if (!e.canAction("remote", "ONLINE")) return H.debug("[session:sync] offline remote cannot enter sync", { remote: e.getState("remote") }), !1;
3431
3415
  e.dispatch("remote", "ONLINE", "syncing");
3432
3416
  } else if (e.getState("remote") !== "syncing") {
3433
- if (!e.canAction("remote", "SYNC")) return B.debug("[session:sync] remote cannot enter sync", { remote: e.getState("remote") }), !1;
3417
+ if (!e.canAction("remote", "SYNC")) return H.debug("[session:sync] remote cannot enter sync", { remote: e.getState("remote") }), !1;
3434
3418
  e.dispatch("remote", "SYNC", "syncing");
3435
3419
  }
3436
3420
  return e.getState("local") === "syncing" && e.getState("remote") === "syncing";
3437
- }, J = (e, t) => {
3438
- let n = G(), r = t ? dt : (e) => e;
3421
+ }, X = (e, t) => {
3422
+ let n = q(), r = t ? ut : (e) => e;
3439
3423
  e.history && e.history.length > 0 ? n.replaceHistory(e.history.map((e) => ({
3440
3424
  ...e,
3441
3425
  player: r(e.player)
3442
3426
  }))) : n.clearHistory(), e.lastStart ? n.setLastStart(r(e.lastStart)) : n.setLastStart(null);
3443
- let i = e.resumeTurn ? r(e.resumeTurn) : e.turn ? r(e.turn) : ft();
3444
- B.debug("[session:sync] state restored", {
3427
+ let i = e.resumeTurn ? r(e.resumeTurn) : e.turn ? r(e.turn) : dt();
3428
+ H.debug("[session:sync] state restored", {
3445
3429
  historyLength: n.getHistory().length,
3446
3430
  lastStart: n.getLastStart(),
3447
3431
  nextTurnPlayer: i,
3448
3432
  mapped: t
3449
- }), ht() && n.dispatchSyncComplete(i);
3450
- }, gt = (e) => {
3451
- let t = G();
3452
- if (B.debug("[session:sync] received", {
3433
+ }), mt() && n.dispatchSyncComplete(i);
3434
+ }, ht = (e) => {
3435
+ let t = q();
3436
+ if (H.debug("[session:sync] received", {
3453
3437
  type: e.type,
3454
3438
  from: e.from,
3455
3439
  payload: e.payload,
@@ -3463,37 +3447,37 @@ var Qe = class {
3463
3447
  console.warn("[Sync] Cannot SYNC from current state");
3464
3448
  return;
3465
3449
  }
3466
- t.getState("local") !== "syncing" && t.dispatch("local", "SYNC", "syncing"), t.getState("remote") !== "syncing" && t.dispatch("remote", "SYNC", "syncing"), q({
3450
+ t.getState("local") !== "syncing" && t.dispatch("local", "SYNC", "syncing"), t.getState("remote") !== "syncing" && t.dispatch("remote", "SYNC", "syncing"), Y({
3467
3451
  type: "SYNC_REQUEST",
3468
3452
  from: "",
3469
3453
  payload: e.payload
3470
- }), B.debug("[session:sync] request sent");
3454
+ }), H.debug("[session:sync] request sent");
3471
3455
  return;
3472
3456
  }
3473
- let n = pt();
3474
- q({
3457
+ let n = ft();
3458
+ Y({
3475
3459
  type: "SYNC_STATE",
3476
3460
  from: "",
3477
3461
  payload: n
3478
- }), B.debug("[session:sync] state sent", n), mt() && J(n, !1);
3462
+ }), H.debug("[session:sync] state sent", n), pt() && X(n, !1);
3479
3463
  return;
3480
3464
  }
3481
3465
  if (e.type === "SYNC_STATE") {
3482
3466
  if (e.from === "local") {
3483
- let e = pt();
3484
- q({
3467
+ let e = ft();
3468
+ Y({
3485
3469
  type: "SYNC_STATE",
3486
3470
  from: "",
3487
3471
  payload: e
3488
- }), B.debug("[session:sync] state pushed", e), mt() && J(e, !1);
3472
+ }), H.debug("[session:sync] state pushed", e), pt() && X(e, !1);
3489
3473
  return;
3490
3474
  }
3491
- J(e.payload || {}, !0);
3475
+ X(e.payload || {}, !0);
3492
3476
  }
3493
- }, _t = (e) => {
3477
+ }, gt = (e) => {
3494
3478
  if (e.type !== "UNDO") return;
3495
- let t = G(), n = K();
3496
- if (B.debug("[session:undo] received", {
3479
+ let t = q(), n = J();
3480
+ if (H.debug("[session:undo] received", {
3497
3481
  from: e.from,
3498
3482
  local: t.getState("local"),
3499
3483
  remote: t.getState("remote"),
@@ -3510,10 +3494,10 @@ var Qe = class {
3510
3494
  console.warn("[Undo] Not enough history to undo", { count: n });
3511
3495
  return;
3512
3496
  }
3513
- t.initializeUndoRequest(n, r), t.dispatch("local", "UNDO"), t.dispatch("remote", "REMOTE_UNDO"), q({
3497
+ t.initializeUndoRequest(n, r), t.dispatch("local", "UNDO"), t.dispatch("remote", "REMOTE_UNDO"), Y({
3514
3498
  type: "UNDO",
3515
3499
  payload: { count: n }
3516
- }), B.debug("[session:undo] local requested", { undoCount: n });
3500
+ }), H.debug("[session:undo] local requested", { undoCount: n });
3517
3501
  return;
3518
3502
  }
3519
3503
  if (t.hasPendingAction()) {
@@ -3546,14 +3530,14 @@ var Qe = class {
3546
3530
  return;
3547
3531
  }
3548
3532
  let a = t.getState("local") === "turn" ? "local" : "remote";
3549
- t.initializeUndoRequest(i, a), t.dispatch("local", "REMOTE_UNDO"), t.dispatch("remote", "UNDO"), B.debug("[session:undo] remote requested", {
3533
+ t.initializeUndoRequest(i, a), t.dispatch("local", "REMOTE_UNDO"), t.dispatch("remote", "UNDO"), H.debug("[session:undo] remote requested", {
3550
3534
  count: i,
3551
3535
  resumePlayer: a
3552
3536
  });
3553
- }, vt = (e) => {
3537
+ }, _t = (e) => {
3554
3538
  if (e.type !== "RESTART") return;
3555
- let t = G(), n = K();
3556
- if (B.debug("[session:restart] received", {
3539
+ let t = q(), n = J();
3540
+ if (H.debug("[session:restart] received", {
3557
3541
  from: e.from,
3558
3542
  local: t.getState("local"),
3559
3543
  remote: t.getState("remote"),
@@ -3566,7 +3550,7 @@ var Qe = class {
3566
3550
  return;
3567
3551
  }
3568
3552
  let e = t.getState("local") === "turn" ? "local" : "remote";
3569
- t.initializeRestartRequest(e), t.dispatch("local", "RESTART"), t.dispatch("remote", "REMOTE_RESTART"), q({ type: "RESTART" }), B.debug("[session:restart] local requested", { resumePlayer: e });
3553
+ t.initializeRestartRequest(e), t.dispatch("local", "RESTART"), t.dispatch("remote", "REMOTE_RESTART"), Y({ type: "RESTART" }), H.debug("[session:restart] local requested", { resumePlayer: e });
3570
3554
  return;
3571
3555
  }
3572
3556
  if (t.hasPendingAction()) {
@@ -3584,11 +3568,11 @@ var Qe = class {
3584
3568
  return;
3585
3569
  }
3586
3570
  let r = t.getState("local") === "turn" ? "local" : "remote";
3587
- t.initializeRestartRequest(r), t.dispatch("local", "REMOTE_RESTART"), t.dispatch("remote", "RESTART"), B.debug("[session:restart] remote requested", { resumePlayer: r });
3588
- }, yt = (e) => {
3571
+ t.initializeRestartRequest(r), t.dispatch("local", "REMOTE_RESTART"), t.dispatch("remote", "RESTART"), H.debug("[session:restart] remote requested", { resumePlayer: r });
3572
+ }, vt = (e) => {
3589
3573
  if (e.type !== "OFFLINE" && e.type !== "ONLINE") return;
3590
- let t = G(), n = K();
3591
- if (B.debug("[session:connection] received", {
3574
+ let t = q(), n = J();
3575
+ if (H.debug("[session:connection] received", {
3592
3576
  type: e.type,
3593
3577
  from: e.from,
3594
3578
  local: t.getState("local"),
@@ -3605,23 +3589,23 @@ var Qe = class {
3605
3589
  return;
3606
3590
  }
3607
3591
  let e = t.getResumeTurn() ?? (t.getState("local") === "turn" ? "local" : "remote");
3608
- t.setResumeTurn(e), t.dispatch("remote", "OFFLINE", "offline"), B.debug("[session:connection] remote offline", { currentTurn: e });
3592
+ t.setResumeTurn(e), t.dispatch("remote", "OFFLINE", "offline"), H.debug("[session:connection] remote offline", { currentTurn: e });
3609
3593
  return;
3610
3594
  }
3611
3595
  if (t.getState("remote") !== "offline") {
3612
- B.debug("[session:connection] ignored online while remote is not offline", { remote: t.getState("remote") });
3596
+ H.debug("[session:connection] ignored online while remote is not offline", { remote: t.getState("remote") });
3613
3597
  return;
3614
3598
  }
3615
3599
  if (!t.canAction("remote", "ONLINE")) {
3616
3600
  console.warn("[Offline] Cannot transition to ONLINE from current state");
3617
3601
  return;
3618
3602
  }
3619
- t.dispatch("remote", "ONLINE", "syncing"), n.emit("SYNC_STATE", void 0, "local"), B.debug("[session:connection] remote online, sync state pushed");
3620
- }, bt = (e) => {
3621
- e.register("READY", at), e.register("START", st), e.register("MOVE", ct), e.register("UNDO", _t), e.register("RESTART", vt), e.register("SYNC_REQUEST", gt), e.register("SYNC_STATE", gt), e.register("OFFLINE", yt), e.register("ONLINE", yt), e.register("APPROVE", ut), e.register("REJECT", ut);
3622
- }, xt = class {
3603
+ t.dispatch("remote", "ONLINE", "syncing"), n.emit("SYNC_STATE", void 0, "local"), H.debug("[session:connection] remote online, sync state pushed");
3604
+ }, yt = (e) => {
3605
+ e.register("READY", it), e.register("START", ot), e.register("MOVE", st), e.register("UNDO", gt), e.register("RESTART", _t), e.register("SYNC_REQUEST", ht), e.register("SYNC_STATE", ht), e.register("OFFLINE", vt), e.register("ONLINE", vt), e.register("APPROVE", lt), e.register("REJECT", lt);
3606
+ }, bt = class {
3623
3607
  constructor(e) {
3624
- this.bus = e;
3608
+ B(this, "bus", e);
3625
3609
  }
3626
3610
  ready() {
3627
3611
  this.bus.emit("READY");
@@ -3644,12 +3628,12 @@ var Qe = class {
3644
3628
  reject() {
3645
3629
  this.bus.emit("REJECT");
3646
3630
  }
3647
- }, St = (e, t) => {
3648
- let n = new Ge(), r = new $e(null, null), i = new Xe(), a = tt(e, n, null), o = new Qe(r, i, () => a.getIsConnected());
3649
- r.subscribeStateObserver(o), rt(r, n, a, t), bt(n);
3650
- let s = new xt(n);
3631
+ }, xt = (e, t) => {
3632
+ let n = new We(), r = new Qe(null, null), i = new Ye(), a = et(e, n, null), o = new Ze(r, i, () => a.getIsConnected());
3633
+ r.subscribeStateObserver(o), nt(r, n, a, t), yt(n);
3634
+ let s = new bt(n);
3651
3635
  return a.onConnectionChange((e) => {
3652
- i.notifyConnectionChange(e), i.notifyStateChange(Ze(r, e));
3636
+ i.notifyConnectionChange(e), i.notifyStateChange(Xe(r, e));
3653
3637
  }), {
3654
3638
  bus: n,
3655
3639
  state: r,
@@ -3658,7 +3642,7 @@ var Qe = class {
3658
3642
  actions: s,
3659
3643
  send: a.send.bind(a)
3660
3644
  };
3661
- }, Ct = "wss://signal.jiahengli.xyz", Y = (e) => ({
3645
+ }, St = "wss://signal.jiahengli.xyz", Ct = (e) => ({
3662
3646
  screen: "pairing",
3663
3647
  theme: e?.theme || "light",
3664
3648
  gameTitle: e?.gameTitle || "P2P Lockstep",
@@ -3686,10 +3670,10 @@ var Qe = class {
3686
3670
  historyLength: 0,
3687
3671
  lastStart: null,
3688
3672
  lastError: ""
3689
- }), wt = "p2p-lockstep-theme", X = (e) => e === "light" || e === "dark", Tt = () => {
3673
+ }), wt = "p2p-lockstep-theme", Z = (e) => e === "light" || e === "dark", Tt = () => {
3690
3674
  try {
3691
3675
  let e = window.localStorage.getItem(wt);
3692
- return X(e) ? e : null;
3676
+ return Z(e) ? e : null;
3693
3677
  } catch {
3694
3678
  return null;
3695
3679
  }
@@ -3697,7 +3681,7 @@ var Qe = class {
3697
3681
  try {
3698
3682
  window.localStorage.setItem(wt, e);
3699
3683
  } catch {}
3700
- }, Z = {
3684
+ }, Q = {
3701
3685
  open: !1,
3702
3686
  title: "",
3703
3687
  description: "",
@@ -3722,38 +3706,43 @@ var Qe = class {
3722
3706
  ];
3723
3707
  }
3724
3708
  #e = !1;
3725
- #t = Y();
3726
- #n = Z;
3709
+ #t = Ct();
3710
+ #n = Q;
3727
3711
  #r = Dt;
3728
3712
  #i = null;
3729
3713
  #a = null;
3730
3714
  #o = null;
3731
3715
  #s = null;
3732
- #c = new He();
3716
+ #c = new ze();
3733
3717
  #l = null;
3734
3718
  #u = null;
3735
3719
  #d = null;
3736
3720
  #f = null;
3721
+ #p = !1;
3722
+ #m = null;
3737
3723
  connectedCallback() {
3738
3724
  if (this.#e) return;
3739
3725
  this.#e = !0;
3740
- let e = X(this.getAttribute("theme")) ? this.getAttribute("theme") : "light", t = Tt() ?? e;
3741
- this.#t = Y({
3726
+ let e = Z(this.getAttribute("theme")) ? this.getAttribute("theme") : "light", t = Tt() ?? e;
3727
+ this.#t = Ct({
3742
3728
  gameTitle: this.getAttribute("game-title") ?? void 0,
3743
3729
  sessionId: this.getAttribute("session-id") ?? void 0,
3744
3730
  signalUrl: this.getAttribute("signal-url") ?? void 0,
3745
3731
  theme: t
3746
- }), this.getAttribute("theme") !== t && this.setAttribute("theme", t), this.render(), this.addEventListener("lockstep-register", this.#C), this.addEventListener("lockstep-connect", this.#w), this.addEventListener("lockstep-signal-change", this.#T), this.addEventListener("lockstep-target-change", this.#E), this.addEventListener("lockstep-share-detected", this.#D), this.addEventListener("lockstep-copy-share", this.#O), this.addEventListener("lockstep-theme-change", this.#k), this.addEventListener("lockstep-ready", this.#A), this.addEventListener("lockstep-start", this.#j), this.addEventListener("lockstep-undo", this.#M), this.addEventListener("lockstep-restart", this.#N), this.addEventListener("lockstep-dialog-confirm", this.#P), this.addEventListener("lockstep-dialog-cancel", this.#F), this.#p(), this.#m();
3732
+ }), this.getAttribute("theme") !== t && this.setAttribute("theme", t), this.render(), this.addEventListener("lockstep-register", this.#D), this.addEventListener("lockstep-connect", this.#O), this.addEventListener("lockstep-signal-change", this.#k), this.addEventListener("lockstep-target-change", this.#A), this.addEventListener("lockstep-share-detected", this.#j), this.addEventListener("lockstep-copy-share", this.#M), this.addEventListener("lockstep-theme-change", this.#N), this.addEventListener("lockstep-ready", this.#P), this.addEventListener("lockstep-start", this.#F), this.addEventListener("lockstep-undo", this.#I), this.addEventListener("lockstep-restart", this.#L), this.addEventListener("lockstep-dialog-confirm", this.#R), this.addEventListener("lockstep-dialog-cancel", this.#z), document.addEventListener("visibilitychange", this.#B), window.addEventListener("pageshow", this.#V), this.#h(), this.#g();
3747
3733
  }
3748
3734
  disconnectedCallback() {
3749
- this.removeEventListener("lockstep-register", this.#C), this.removeEventListener("lockstep-connect", this.#w), this.removeEventListener("lockstep-signal-change", this.#T), this.removeEventListener("lockstep-target-change", this.#E), this.removeEventListener("lockstep-share-detected", this.#D), this.removeEventListener("lockstep-copy-share", this.#O), this.removeEventListener("lockstep-theme-change", this.#k), this.removeEventListener("lockstep-ready", this.#A), this.removeEventListener("lockstep-start", this.#j), this.removeEventListener("lockstep-undo", this.#M), this.removeEventListener("lockstep-restart", this.#N), this.removeEventListener("lockstep-dialog-confirm", this.#P), this.removeEventListener("lockstep-dialog-cancel", this.#F), this.#d &&= (window.clearTimeout(this.#d), null), this.#c.disconnect();
3735
+ this.removeEventListener("lockstep-register", this.#D), this.removeEventListener("lockstep-connect", this.#O), this.removeEventListener("lockstep-signal-change", this.#k), this.removeEventListener("lockstep-target-change", this.#A), this.removeEventListener("lockstep-share-detected", this.#j), this.removeEventListener("lockstep-copy-share", this.#M), this.removeEventListener("lockstep-theme-change", this.#N), this.removeEventListener("lockstep-ready", this.#P), this.removeEventListener("lockstep-start", this.#F), this.removeEventListener("lockstep-undo", this.#I), this.removeEventListener("lockstep-restart", this.#L), this.removeEventListener("lockstep-dialog-confirm", this.#R), this.removeEventListener("lockstep-dialog-cancel", this.#z), document.removeEventListener("visibilitychange", this.#B), window.removeEventListener("pageshow", this.#V), this.#d &&= (window.clearTimeout(this.#d), null), this.#c.disconnect();
3750
3736
  }
3751
3737
  attributeChangedCallback(e, t, n) {
3752
- this.#e && (e === "game-title" && n && this.#y({ gameTitle: n }), e === "session-id" && n && this.#y({ sessionId: n }), e === "signal-url" && n && this.#y({ signalUrl: n }), e === "theme" && X(n) && this.#y({ theme: n }));
3738
+ this.#e && (e === "game-title" && n && this.#C({ gameTitle: n }), e === "session-id" && n && this.#C({ sessionId: n }), e === "signal-url" && n && this.#C({ signalUrl: n }), e === "theme" && Z(n) && this.#C({ theme: n }));
3753
3739
  }
3754
3740
  getRuntime() {
3755
3741
  return this.#u;
3756
3742
  }
3743
+ resumeConnection() {
3744
+ this.#_();
3745
+ }
3757
3746
  getBoardHost() {
3758
3747
  return this.#a?.getBoardHost() ?? null;
3759
3748
  }
@@ -3784,10 +3773,10 @@ var Qe = class {
3784
3773
  <p2p-lockstep-confirm-dialog></p2p-lockstep-confirm-dialog>
3785
3774
  <p2p-lockstep-toast-message></p2p-lockstep-toast-message>
3786
3775
  </div>
3787
- `, this.#i = this.querySelector("p2p-lockstep-pairing-page"), this.#a = this.querySelector("p2p-lockstep-game-page"), this.#o = this.querySelector("p2p-lockstep-confirm-dialog"), this.#s = this.querySelector("p2p-lockstep-toast-message"), this.#b();
3776
+ `, this.#i = this.querySelector("p2p-lockstep-pairing-page"), this.#a = this.querySelector("p2p-lockstep-game-page"), this.#o = this.querySelector("p2p-lockstep-confirm-dialog"), this.#s = this.querySelector("p2p-lockstep-toast-message"), this.#w();
3788
3777
  }
3789
- #p() {
3790
- this.#l = St(this.#c, this.#t.sessionId), this.#u = {
3778
+ #h() {
3779
+ this.#l = xt(this.#c, this.#t.sessionId), this.#u = {
3791
3780
  setGamePlugin: (e) => this.#l?.state.setGamePlugin(e),
3792
3781
  actions: { move: (e) => this.#l?.actions.move(e) },
3793
3782
  observer: {
@@ -3800,29 +3789,46 @@ var Qe = class {
3800
3789
  getSnapshot: () => this.#l?.observer.getSnapshot() ?? null
3801
3790
  }
3802
3791
  }, this.#f = {
3803
- onStateChange: (e) => this.#_(e),
3804
- onConnectionChange: (e) => this.#v(e),
3792
+ onStateChange: (e) => this.#x(e),
3793
+ onConnectionChange: (e) => this.#S(e),
3805
3794
  onGameEvent: () => {},
3806
3795
  onError: (e) => {
3807
- this.#y({
3796
+ this.#C({
3808
3797
  lastError: e.message,
3809
3798
  connectionState: "error"
3810
- }), this.#x(e.message);
3799
+ }), this.#T(e.message);
3811
3800
  }
3812
- }, this.#l.observer.subscribe(this.#f), this.#y({
3801
+ }, this.#l.observer.subscribe(this.#f), this.#C({
3813
3802
  localState: "idle",
3814
3803
  remoteState: "idle",
3815
3804
  currentTurn: 1
3816
3805
  });
3817
3806
  }
3818
- async #m() {
3819
- let e = we();
3820
- e.signalUrl && this.#y({ signalUrl: e.signalUrl }), e.peerId && this.#y({ targetId: e.peerId }), this.#t.signalUrl && (await this.#h(this.#t.signalUrl, !0), e.peerId && await this.#g(e.peerId, !0));
3821
- }
3822
- async #h(e, t = !1) {
3807
+ async #g() {
3808
+ let e = N();
3809
+ e.signalUrl && this.#C({ signalUrl: e.signalUrl }), e.peerId && this.#C({ targetId: e.peerId }), this.#t.signalUrl && (await this.#y(this.#t.signalUrl, !0), e.peerId && await this.#b(e.peerId, !0));
3810
+ }
3811
+ #_() {
3812
+ if (this.#m || !this.isConnected) return;
3813
+ let e = N(), t = this.#c.getRemotePeerId() || this.#t.remotePeerId || e.peerId;
3814
+ this.#t.screen !== "game" || !this.#t.signalUrl || !t || (this.#m = this.#v(t).finally(() => {
3815
+ this.#m = null;
3816
+ }));
3817
+ }
3818
+ async #v(e) {
3819
+ this.#C({
3820
+ targetId: e,
3821
+ remotePeerId: e,
3822
+ connected: !1,
3823
+ connecting: !0,
3824
+ connectionState: "connecting",
3825
+ lastError: ""
3826
+ }), this.#T("Restoring peer connection."), await this.#y(this.#t.signalUrl, !0), this.#c.getLocalPeerId() && await this.#b(e, !0);
3827
+ }
3828
+ async #y(e, t = !1) {
3823
3829
  let n = e.trim();
3824
3830
  if (n) {
3825
- this.#y({
3831
+ this.#C({
3826
3832
  signalUrl: n,
3827
3833
  registering: !0,
3828
3834
  connectionState: "registering",
@@ -3833,48 +3839,47 @@ var Qe = class {
3833
3839
  this.#l?.net.setPeerIds({
3834
3840
  local: e,
3835
3841
  remote: this.#t.remotePeerId || null
3836
- }), this.#y({
3842
+ }), this.#C({
3837
3843
  peerId: e,
3838
3844
  registering: !1,
3839
3845
  connectionState: "registered"
3840
- }), t || this.#x("Peer registered. You can share the link now.");
3846
+ }), t || this.#T("Peer registered. You can share the link now.");
3841
3847
  } catch (e) {
3842
- this.#y({
3848
+ this.#C({
3843
3849
  registering: !1,
3844
3850
  connectionState: "error",
3845
3851
  lastError: e instanceof Error ? e.message : "Failed to register signaling session."
3846
- }), this.#x(this.#t.lastError || "Failed to register signaling session.");
3852
+ }), this.#T(this.#t.lastError || "Failed to register signaling session.");
3847
3853
  }
3848
3854
  }
3849
3855
  }
3850
- async #g(e, t = !1) {
3856
+ async #b(e, t = !1) {
3851
3857
  let n = e.trim();
3852
3858
  if (n) {
3853
- !this.#t.peerId && this.#t.signalUrl && await this.#h(this.#t.signalUrl, !0), this.#y({
3859
+ !this.#t.peerId && this.#t.signalUrl && await this.#y(this.#t.signalUrl, !0), this.#C({
3854
3860
  targetId: n,
3855
3861
  remotePeerId: n,
3856
3862
  connecting: !0,
3857
3863
  connectionState: "connecting",
3858
- screen: "game",
3859
3864
  lastError: ""
3860
3865
  }), this.#l?.net.setPeerIds({
3861
3866
  local: this.#t.peerId || null,
3862
3867
  remote: n
3863
3868
  });
3864
3869
  try {
3865
- await this.#c.connect(n), this.#y({ connecting: !1 }), t || this.#x("Connection request sent.");
3870
+ await this.#c.connect(n), this.#C({ connecting: !1 }), t || this.#T("Connection request sent.");
3866
3871
  } catch (e) {
3867
- this.#y({
3872
+ this.#C({
3868
3873
  connecting: !1,
3869
3874
  connectionState: "error",
3870
3875
  lastError: e instanceof Error ? e.message : "Failed to start peer connection."
3871
- }), this.#x(this.#t.lastError || "Failed to start peer connection.");
3876
+ }), this.#T(this.#t.lastError || "Failed to start peer connection.");
3872
3877
  }
3873
3878
  }
3874
3879
  }
3875
- #_(e) {
3880
+ #x(e) {
3876
3881
  let t = e.connected, n = e.localState === "ready", r = e.remoteState === "ready", i = t && e.localState === "idle", a = t && e.localState === "could_start", o = t && (e.localState === "turn" || e.localState === "remote_turn") && !e.pendingAction && e.history.length > 0, s = t && (e.localState === "turn" || e.localState === "remote_turn") && !e.pendingAction, c = Ot.includes(e.localState) || e.localState === "offline" && e.lastStart !== null, l = e.localState === "turn" ? "me" : e.localState === "remote_turn" ? "peer" : null;
3877
- this.#y({
3882
+ this.#C({
3878
3883
  readySelf: n,
3879
3884
  readyPeer: r,
3880
3885
  connected: t,
@@ -3898,26 +3903,26 @@ var Qe = class {
3898
3903
  description: e.pendingAction === "undo" ? "Your peer wants to roll the match back. Approve the undo or reject it and keep the current board." : "Your peer wants to restart the match. Approve to reset the board shell or reject to continue.",
3899
3904
  confirmLabel: "Approve",
3900
3905
  cancelLabel: "Reject"
3901
- } : this.#n.open && (this.#n = Z), this.#b();
3906
+ } : this.#n.open && (this.#n = Q), this.#w();
3902
3907
  }
3903
- #v(e) {
3904
- let t = this.#t.screen === "game", n = this.#c.peerState(), r = this.#c.getRemotePeerId() ?? this.#t.remotePeerId, i = this.#c.getLocalPeerId() ?? this.#t.peerId, a = e || n === "requesting" || t, o = n === "connected" ? "connected" : n === "requesting" ? "connecting" : t ? "offline" : i ? "registered" : "idle";
3905
- this.#y({
3908
+ #S(e) {
3909
+ let t = this.#t.screen === "game", n = this.#c.peerState(), r = this.#c.getRemotePeerId() ?? this.#t.remotePeerId, i = this.#c.getLocalPeerId() ?? this.#t.peerId, a = e || t, o = n === "connected" ? "connected" : n === "requesting" ? "connecting" : t ? "offline" : i ? "registered" : "idle";
3910
+ this.#C({
3906
3911
  peerId: i,
3907
3912
  remotePeerId: r,
3908
3913
  connected: e,
3909
3914
  connecting: n === "requesting",
3910
3915
  connectionState: o,
3911
3916
  screen: a ? "game" : "pairing"
3912
- }), e ? this.#x("Peer connected. Game page is live.") : n === "requesting" && !t ? this.#x("Peer connection request received.") : t && i && this.#x("Peer disconnected. Waiting for reconnect.");
3917
+ }), e ? this.#T("Peer connected. Game page is live.") : n === "requesting" && !t ? this.#T("Connecting to peer.") : t && i && this.#T("Peer disconnected. Waiting for reconnect.");
3913
3918
  }
3914
- #y(e) {
3919
+ #C(e) {
3915
3920
  this.#t = {
3916
3921
  ...this.#t,
3917
3922
  ...e
3918
- }, this.#e && this.#b();
3923
+ }, this.#e && this.#w();
3919
3924
  }
3920
- #b() {
3925
+ #w() {
3921
3926
  let e = this.#i, t = this.#a, n = this.#o, r = this.#s;
3922
3927
  if (!e || !t || !n || !r) return;
3923
3928
  e.toggleAttribute("hidden", this.#t.screen !== "pairing"), t.toggleAttribute("hidden", this.#t.screen !== "game");
@@ -3957,76 +3962,86 @@ var Qe = class {
3957
3962
  lastError: this.#t.lastError
3958
3963
  }, n.state = this.#n, r.state = this.#r;
3959
3964
  }
3960
- #x(e) {
3965
+ #T(e) {
3961
3966
  e && (this.#d && window.clearTimeout(this.#d), this.#r = {
3962
3967
  open: !0,
3963
3968
  message: e
3964
- }, this.#b(), this.#d = window.setTimeout(() => {
3965
- this.#r = Dt, this.#b(), this.#d = null;
3969
+ }, this.#w(), this.#d = window.setTimeout(() => {
3970
+ this.#r = Dt, this.#w(), this.#d = null;
3966
3971
  }, 2200));
3967
3972
  }
3968
- async #S(e) {
3973
+ async #E(e) {
3969
3974
  if (e) {
3970
3975
  try {
3971
3976
  if (navigator.clipboard?.writeText) {
3972
- await navigator.clipboard.writeText(e), this.#x("Copied to clipboard.");
3977
+ await navigator.clipboard.writeText(e), this.#T("Copied to clipboard.");
3973
3978
  return;
3974
3979
  }
3975
3980
  } catch {}
3976
3981
  window.prompt("Copy value", e);
3977
3982
  }
3978
3983
  }
3979
- #C = (e) => {
3980
- this.#h(e.detail.signalUrl);
3984
+ #D = (e) => {
3985
+ this.#y(e.detail.signalUrl);
3981
3986
  };
3982
- #w = (e) => {
3983
- this.#g(e.detail.targetId);
3987
+ #O = (e) => {
3988
+ this.#b(e.detail.targetId);
3984
3989
  };
3985
- #T = (e) => {
3986
- this.#y({ signalUrl: e.detail.signalUrl });
3990
+ #k = (e) => {
3991
+ this.#C({ signalUrl: e.detail.signalUrl });
3987
3992
  };
3988
- #E = (e) => {
3989
- this.#y({ targetId: e.detail.targetId });
3993
+ #A = (e) => {
3994
+ this.#C({ targetId: e.detail.targetId });
3990
3995
  };
3991
- #D = (e) => {
3992
- this.#y({
3996
+ #j = (e) => {
3997
+ this.#C({
3993
3998
  targetId: e.detail.peerId,
3994
3999
  signalUrl: e.detail.signalUrl || this.#t.signalUrl
3995
4000
  });
3996
4001
  };
3997
- #O = (e) => {
3998
- this.#S(e.detail.value);
4002
+ #M = (e) => {
4003
+ this.#E(e.detail.value);
3999
4004
  };
4000
- #k = (e) => {
4001
- if (!X(e.detail.theme) || e.detail.theme === this.#t.theme) return;
4005
+ #N = (e) => {
4006
+ if (!Z(e.detail.theme) || e.detail.theme === this.#t.theme) return;
4002
4007
  let t = e.detail.theme;
4003
- Et(t), this.setAttribute("theme", t), this.#x(`${t === "dark" ? "Night" : "Day"} mode enabled.`);
4008
+ Et(t), this.setAttribute("theme", t), this.#T(`${t === "dark" ? "Night" : "Day"} mode enabled.`);
4004
4009
  };
4005
- #A = () => {
4006
- this.#l?.actions.ready(), this.#x(this.#t.readySelf ? "Ready state cleared." : "Ready state sent.");
4010
+ #P = () => {
4011
+ this.#l?.actions.ready(), this.#T(this.#t.readySelf ? "Ready state cleared." : "Ready state sent.");
4007
4012
  };
4008
- #j = () => {
4009
- this.#l?.actions.start(), this.#x("Start request sent.");
4013
+ #F = () => {
4014
+ this.#l?.actions.start(), this.#T("Start request sent.");
4010
4015
  };
4011
- #M = () => {
4012
- this.#l?.actions.undo(), this.#x("Undo request sent.");
4016
+ #I = () => {
4017
+ this.#l?.actions.undo(), this.#T("Undo request sent.");
4013
4018
  };
4014
- #N = () => {
4015
- this.#l?.actions.restart(), this.#x("Restart request sent.");
4019
+ #L = () => {
4020
+ this.#l?.actions.restart(), this.#T("Restart request sent.");
4016
4021
  };
4017
- #P = () => {
4018
- this.#l?.actions.approve(), this.#n = Z, this.#b(), this.#x("Request approved.");
4022
+ #R = () => {
4023
+ this.#l?.actions.approve(), this.#n = Q, this.#w(), this.#T("Request approved.");
4019
4024
  };
4020
- #F = () => {
4021
- this.#l?.actions.reject(), this.#n = Z, this.#b(), this.#x("Request rejected.");
4025
+ #z = () => {
4026
+ this.#l?.actions.reject(), this.#n = Q, this.#w(), this.#T("Request rejected.");
4027
+ };
4028
+ #B = () => {
4029
+ if (document.visibilityState === "hidden") {
4030
+ this.#p = !0;
4031
+ return;
4032
+ }
4033
+ this.#p && (this.#p = !1, this.#_());
4034
+ };
4035
+ #V = (e) => {
4036
+ e.persisted && this.#_();
4022
4037
  };
4023
- }, Q = (e, t) => {
4038
+ }, $ = (e, t) => {
4024
4039
  customElements.get(e) || customElements.define(e, t);
4025
- }, $ = () => {
4026
- Q("p2p-lockstep-share-panel", ve), Q("p2p-lockstep-status-panel", j), Q("p2p-lockstep-action-bar", d), Q("p2p-lockstep-confirm-dialog", g), Q("p2p-lockstep-toast-message", M), Q("p2p-lockstep-board-host", N), Q("p2p-lockstep-pairing-page", F), Q("p2p-lockstep-game-page", De), Q("p2p-lockstep-app", kt);
4040
+ }, At = () => {
4041
+ $("p2p-lockstep-share-panel", k), $("p2p-lockstep-status-panel", be), $("p2p-lockstep-action-bar", d), $("p2p-lockstep-confirm-dialog", g), $("p2p-lockstep-toast-message", Se), $("p2p-lockstep-board-host", Ce), $("p2p-lockstep-pairing-page", P), $("p2p-lockstep-game-page", F), $("p2p-lockstep-app", kt);
4027
4042
  };
4028
- $();
4043
+ At();
4029
4044
  //#endregion
4030
- export { Ct as DEFAULT_SIGNAL_URL, d as P2PLockstepActionBarElement, kt as P2PLockstepAppElement, N as P2PLockstepBoardHostElement, g as P2PLockstepConfirmDialogElement, De as P2PLockstepGamePageElement, F as P2PLockstepPairingPageElement, ve as P2PLockstepSharePanelElement, j as P2PLockstepStatusPanelElement, M as P2PLockstepToastMessageElement, $ as defineP2PLockstepUi };
4045
+ export { St as DEFAULT_SIGNAL_URL, d as P2PLockstepActionBarElement, kt as P2PLockstepAppElement, Ce as P2PLockstepBoardHostElement, g as P2PLockstepConfirmDialogElement, F as P2PLockstepGamePageElement, P as P2PLockstepPairingPageElement, k as P2PLockstepSharePanelElement, be as P2PLockstepStatusPanelElement, Se as P2PLockstepToastMessageElement, At as defineP2PLockstepUi };
4031
4046
 
4032
4047
  //# sourceMappingURL=index.js.map