@caisual/kit 0.8.0 → 0.12.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.
- package/dist/kit.js +529 -56
- package/dist/node.js +297 -77
- package/dist/overlay.js +360 -53
- package/dist/runtime.js +248 -47
- package/dist/server.js +2 -0
- package/dist/types/api.d.ts +2 -1
- package/dist/types/contracts/i18n.d.ts +12 -0
- package/dist/types/contracts/immagine.d.ts +27 -0
- package/dist/types/contracts/index.d.ts +5 -0
- package/dist/types/contracts/manifest.d.ts +14 -6
- package/dist/types/contracts/match-result.d.ts +16 -0
- package/dist/types/contracts/overlay.d.ts +16 -2
- package/dist/types/contracts/player.d.ts +1 -0
- package/dist/types/contracts/room-limits.d.ts +13 -0
- package/dist/types/daily.d.ts +14 -0
- package/dist/types/handshake.d.ts +4 -0
- package/dist/types/index.d.ts +24 -2
- package/dist/types/kit.d.ts +2 -0
- package/dist/types/node/index.d.ts +5 -0
- package/dist/types/overlay/host-bridge.d.ts +16 -0
- package/dist/types/overlay/i18n.d.ts +13 -0
- package/dist/types/overlay/index.d.ts +1 -0
- package/dist/types/overlay/styles.d.ts +1 -1
- package/dist/types/overlay/ui-model.d.ts +4 -0
- package/dist/types/overlay/ui.d.ts +3 -1
- package/dist/types/protocollo.d.ts +13 -0
- package/dist/types/runtime/index.d.ts +6 -1
- package/dist/types/server/index.d.ts +17 -2
- package/dist/types/stanza/nucleo.d.ts +8 -2
- package/dist/types/stanza/tipi.d.ts +13 -0
- package/dist/types/text.d.ts +2 -0
- package/package.json +1 -1
package/dist/overlay.js
CHANGED
|
@@ -41,19 +41,55 @@ function isReservedSlug(value) {
|
|
|
41
41
|
return RISERVATI.has(value);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// ../contracts/src/i18n.ts
|
|
45
|
+
function normalizeLanguage(value) {
|
|
46
|
+
if (typeof value !== "string" || value.length > 128) return null;
|
|
47
|
+
try {
|
|
48
|
+
return Intl.getCanonicalLocales(value)[0] ?? null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function manifestLanguages(manifest) {
|
|
54
|
+
return manifest.languages?.length ? [...manifest.languages] : [manifest.language ?? "en"];
|
|
55
|
+
}
|
|
56
|
+
function languageFallbacks(language, defaultLanguage = "en") {
|
|
57
|
+
const result = [];
|
|
58
|
+
let tag = normalizeLanguage(language);
|
|
59
|
+
while (tag) {
|
|
60
|
+
result.push(tag);
|
|
61
|
+
const parts = tag.split("-");
|
|
62
|
+
parts.pop();
|
|
63
|
+
if (parts.at(-1)?.length === 1) parts.pop();
|
|
64
|
+
tag = parts.join("-");
|
|
65
|
+
}
|
|
66
|
+
result.push(normalizeLanguage(defaultLanguage) ?? defaultLanguage);
|
|
67
|
+
return [...new Set(result)];
|
|
68
|
+
}
|
|
69
|
+
function resolveText(value, language, defaultLanguage = "en", key = "") {
|
|
70
|
+
if (typeof value === "string") return value;
|
|
71
|
+
if (value) {
|
|
72
|
+
for (const tag of languageFallbacks(language, defaultLanguage)) {
|
|
73
|
+
const name = Object.keys(value).find((name2) => name2.toLowerCase() === tag.toLowerCase());
|
|
74
|
+
if (name !== void 0 && typeof value[name] === "string") return value[name];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return key;
|
|
78
|
+
}
|
|
79
|
+
|
|
44
80
|
// ../contracts/src/manifest.ts
|
|
45
81
|
function risolviModalita(manifest, mode) {
|
|
46
82
|
const scelta = mode === null ? void 0 : manifest.modes.find((voce) => voce.id === mode);
|
|
47
83
|
if (mode !== null && scelta === void 0) throw new Error("The selected game mode does not exist.");
|
|
48
84
|
return { players: { ...scelta?.players ?? manifest.players }, lobby: scelta?.lobby ?? manifest.lobby };
|
|
49
85
|
}
|
|
50
|
-
function risolviPresentazione(manifest, mode) {
|
|
86
|
+
function risolviPresentazione(manifest, mode, language = manifestLanguages(manifest)[0]) {
|
|
51
87
|
risolviModalita(manifest, mode);
|
|
52
88
|
const scelta = manifest.modes.find((voce) => voce.id === mode);
|
|
53
89
|
return {
|
|
54
90
|
execution: scelta?.execution ?? null,
|
|
55
|
-
label: scelta?.label
|
|
56
|
-
instructions: scelta?.instructions
|
|
91
|
+
label: resolveText(scelta?.label, language, manifestLanguages(manifest)[0], scelta?.id ?? manifest.name ?? "Play"),
|
|
92
|
+
instructions: resolveText(scelta?.instructions, language, manifestLanguages(manifest)[0]) || null
|
|
57
93
|
};
|
|
58
94
|
}
|
|
59
95
|
var TETTO_GIOCATORI = 24;
|
|
@@ -66,8 +102,11 @@ var CAMPI = /* @__PURE__ */ new Set([
|
|
|
66
102
|
"name",
|
|
67
103
|
"description",
|
|
68
104
|
"cover",
|
|
105
|
+
"card",
|
|
106
|
+
"icon",
|
|
69
107
|
"screenshots",
|
|
70
108
|
"tags",
|
|
109
|
+
"languages",
|
|
71
110
|
"language",
|
|
72
111
|
"platform",
|
|
73
112
|
"orientation",
|
|
@@ -134,12 +173,32 @@ function stringaDefault(dati, campo, valoreDefault, errori) {
|
|
|
134
173
|
}
|
|
135
174
|
function testoFacoltativo(value, key, max, path, errors) {
|
|
136
175
|
if (value[key] === void 0) return void 0;
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
176
|
+
const check = (text2, field2) => {
|
|
177
|
+
if (typeof text2 !== "string" || text2.trim().length === 0 || text2.trim().length > max || /[\r\n\u0000-\u001f]/.test(text2)) {
|
|
178
|
+
errors.push(`${field2}: must contain 1-${max} characters on one line.`);
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
return text2.trim();
|
|
182
|
+
};
|
|
183
|
+
const text = value[key], field = `${path}.${key}`;
|
|
184
|
+
if (typeof text === "string") return check(text, field);
|
|
185
|
+
const translations = oggetto(text);
|
|
186
|
+
if (!translations || Object.keys(translations).length === 0) {
|
|
187
|
+
errors.push(`${field}: must be a string or a non-empty language-to-text object.`);
|
|
140
188
|
return void 0;
|
|
141
189
|
}
|
|
142
|
-
|
|
190
|
+
const result = {};
|
|
191
|
+
for (const [raw, text2] of Object.entries(translations)) {
|
|
192
|
+
const tag = normalizeLanguage(raw);
|
|
193
|
+
if (!tag) {
|
|
194
|
+
errors.push(`${field}.${raw}: must be a BCP 47 language tag.`);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (Object.hasOwn(result, tag)) errors.push(`${field}.${raw}: duplicate language.`);
|
|
198
|
+
const checked = check(text2, `${field}.${raw}`);
|
|
199
|
+
if (checked !== void 0) result[tag] = checked;
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
143
202
|
}
|
|
144
203
|
function validaManifest(valore) {
|
|
145
204
|
const errori = [];
|
|
@@ -164,12 +223,21 @@ function validaManifest(valore) {
|
|
|
164
223
|
}
|
|
165
224
|
const description = stringaDefault(dati, "description", "", errori);
|
|
166
225
|
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
226
|
+
const immagini = { cover: "", card: "", icon: "" };
|
|
227
|
+
const usati = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const campo of ["cover", "card", "icon"]) {
|
|
229
|
+
const path = dati[campo];
|
|
230
|
+
if (path === void 0 || path === null) errori.push(`${campo}: is required.`);
|
|
231
|
+
else if (typeof path !== "string" || !percorsoRelativo(path)) errori.push(`${campo}: must be a relative file path inside client/ without query, fragment, or parent segments.`);
|
|
232
|
+
else {
|
|
233
|
+
if (!/\.(png|jpe?g|webp)$/i.test(path)) errori.push(`${campo}: must be a PNG, JPEG or WebP file.`);
|
|
234
|
+
const canonical = decodeURIComponent(path);
|
|
235
|
+
if (usati.has(canonical)) errori.push(`${campo}: each image must use a different file; cover, card and icon cannot share a path.`);
|
|
236
|
+
usati.add(canonical);
|
|
237
|
+
immagini[campo] = path;
|
|
238
|
+
}
|
|
172
239
|
}
|
|
240
|
+
const { cover, card, icon } = immagini;
|
|
173
241
|
const screenshots = [];
|
|
174
242
|
if (dati.screenshots !== void 0) {
|
|
175
243
|
if (!Array.isArray(dati.screenshots)) errori.push("screenshots: must be an array of relative file paths.");
|
|
@@ -194,10 +262,24 @@ function validaManifest(valore) {
|
|
|
194
262
|
}
|
|
195
263
|
}
|
|
196
264
|
}
|
|
197
|
-
const
|
|
198
|
-
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(
|
|
265
|
+
const legacyLanguage = stringaDefault(dati, "language", "en", errori);
|
|
266
|
+
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(legacyLanguage)) {
|
|
199
267
|
errori.push("language: must be a BCP 47 language tag such as en, it, or pt-BR.");
|
|
200
268
|
}
|
|
269
|
+
const languages2 = [];
|
|
270
|
+
if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
271
|
+
errori.push("languages: must be a non-empty array of BCP 47 language tags.");
|
|
272
|
+
} else for (const [index, raw] of dati.languages.entries()) {
|
|
273
|
+
const tag = normalizeLanguage(raw);
|
|
274
|
+
if (!tag) errori.push(`languages[${index}]: must be a BCP 47 language tag.`);
|
|
275
|
+
else if (languages2.includes(tag)) errori.push(`languages[${index}]: duplicate language ${tag}.`);
|
|
276
|
+
else languages2.push(tag);
|
|
277
|
+
}
|
|
278
|
+
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
279
|
+
const language = languages2[0] ?? legacyLanguage;
|
|
280
|
+
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
281
|
+
errori.push("language: must match the first entry in languages when both are present.");
|
|
282
|
+
}
|
|
201
283
|
let platform = "both";
|
|
202
284
|
if (dati.platform === void 0) errori.push("platform: is required.");
|
|
203
285
|
else if (typeof dati.platform !== "string" || !PLATFORM.has(dati.platform)) {
|
|
@@ -349,12 +431,14 @@ function validaManifest(valore) {
|
|
|
349
431
|
continue;
|
|
350
432
|
}
|
|
351
433
|
for (const campo of Object.keys(board)) {
|
|
352
|
-
if (!["source", "label", "periods"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
434
|
+
if (!["source", "label", "periods", "day"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
353
435
|
}
|
|
354
436
|
if (board.source !== "client" && board.source !== "server") {
|
|
355
437
|
errori.push(`boards.${id2}.source: must be "client" or "server".`);
|
|
356
438
|
valido = false;
|
|
357
439
|
}
|
|
440
|
+
if (board.day !== void 0 && board.day !== "submit" && board.day !== "start") errori.push(`boards.${id2}.day: must be "submit" or "start".`);
|
|
441
|
+
if (board.day === "start" && board.source !== "server") errori.push(`boards.${id2}.day: start requires source "server".`);
|
|
358
442
|
const label = testoFacoltativo(board, "label", 48, `boards.${id2}`, errori);
|
|
359
443
|
let periods = ["all-time"];
|
|
360
444
|
if (board.periods !== void 0) {
|
|
@@ -365,6 +449,7 @@ function validaManifest(valore) {
|
|
|
365
449
|
if (valido) Object.defineProperty(boards, id2, { value: {
|
|
366
450
|
source: board.source,
|
|
367
451
|
periods,
|
|
452
|
+
...board.day === void 0 ? {} : { day: board.day },
|
|
368
453
|
...label === void 0 ? {} : { label }
|
|
369
454
|
}, enumerable: true, configurable: true, writable: true });
|
|
370
455
|
}
|
|
@@ -561,8 +646,11 @@ function validaManifest(valore) {
|
|
|
561
646
|
name,
|
|
562
647
|
description,
|
|
563
648
|
cover,
|
|
649
|
+
card,
|
|
650
|
+
icon,
|
|
564
651
|
screenshots,
|
|
565
652
|
tags,
|
|
653
|
+
languages: languages2,
|
|
566
654
|
language,
|
|
567
655
|
platform,
|
|
568
656
|
orientation,
|
|
@@ -585,17 +673,21 @@ function validaManifest(valore) {
|
|
|
585
673
|
|
|
586
674
|
// ../contracts/src/overlay.ts
|
|
587
675
|
var OVERLAY_PANELS = ["home", "room", "invite", "friends", "voice", "boards"];
|
|
588
|
-
function overlayConfiguration(manifest, coverUrl = null, invite = null) {
|
|
676
|
+
function overlayConfiguration(manifest, coverUrl = null, invite = null, iconUrl = null) {
|
|
589
677
|
const validated = validaManifest(manifest);
|
|
590
678
|
if (!validated.ok) throw new Error("The overlay manifest is invalid.");
|
|
591
|
-
return { manifest: validated.manifest, coverUrl, invite };
|
|
679
|
+
return { manifest: validated.manifest, coverUrl, iconUrl, invite };
|
|
592
680
|
}
|
|
593
681
|
function record(value) {
|
|
594
682
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
595
683
|
}
|
|
684
|
+
function validSafeArea(value) {
|
|
685
|
+
const area = record(value);
|
|
686
|
+
return area !== null && Object.keys(area).length === 4 && ["top", "right", "bottom", "left"].every((key) => typeof area[key] === "number" && Number.isFinite(area[key]) && Number(area[key]) >= 0 && Number(area[key]) <= 1e5);
|
|
687
|
+
}
|
|
596
688
|
function validOverlayView(value) {
|
|
597
689
|
const data = record(value);
|
|
598
|
-
return data !== null && Object.keys(data).every((key) => ["inputBlocked", "reservedRects", "shortcutEnabled"].includes(key)) && (data.shortcutEnabled === void 0 || typeof data.shortcutEnabled === "boolean") && typeof data.inputBlocked === "boolean" && Array.isArray(data.reservedRects) && data.reservedRects.length <= 8 && data.reservedRects.every((value2) => {
|
|
690
|
+
return data !== null && Object.keys(data).every((key) => ["inputBlocked", "reservedRects", "safeArea", "shortcutEnabled"].includes(key)) && (data.safeArea === void 0 || validSafeArea(data.safeArea)) && (data.shortcutEnabled === void 0 || typeof data.shortcutEnabled === "boolean") && typeof data.inputBlocked === "boolean" && Array.isArray(data.reservedRects) && data.reservedRects.length <= 8 && data.reservedRects.every((value2) => {
|
|
599
691
|
const rect = record(value2);
|
|
600
692
|
return rect !== null && Object.keys(rect).length === 4 && ["x", "y", "width", "height"].every((key) => typeof rect[key] === "number" && Number.isFinite(rect[key]) && rect[key] >= 0 && rect[key] <= 1e5);
|
|
601
693
|
});
|
|
@@ -626,6 +718,7 @@ function validOverlayRequest(value) {
|
|
|
626
718
|
return keys("role") && text("role");
|
|
627
719
|
case "room.team":
|
|
628
720
|
return keys("team") && Number.isInteger(args.team) && args.team >= 1 && args.team <= 24;
|
|
721
|
+
case "room.restart":
|
|
629
722
|
case "room.start":
|
|
630
723
|
case "session.cancel":
|
|
631
724
|
case "session.leave":
|
|
@@ -663,9 +756,10 @@ function validOverlaySessionState(value) {
|
|
|
663
756
|
if (data.waiting !== null && (!exact(waiting, ["players", "min", "max"]) || !Object.values(waiting).every((v) => Number.isInteger(v) && Number(v) >= 0 && Number(v) <= 24))) return false;
|
|
664
757
|
if (data.resume !== null && (!exact(resume, ["version", "code", "mode", "updatedAt"]) || resume.version !== 1 || !text(resume.code) || !nullable(resume.mode) || !finite(resume.updatedAt))) return false;
|
|
665
758
|
if (data.room === null) return true;
|
|
666
|
-
if (!exact(room, ["code", "mode", "status", "host", "you", "players", "countdownAt", "connection", "closedCode", "limits", "lobby", "persistent", "delayMs", "requestRole"]) || !room) return false;
|
|
667
|
-
const limits = record(room.limits);
|
|
668
|
-
|
|
759
|
+
if (!exact(room, ["code", "mode", "status", "host", "you", "players", "countdownAt", "connection", "closedCode", "limits", "lobby", "persistent", "delayMs", "requestRole", ..."result" in (room ?? {}) ? ["result"] : [], ..."rematch" in (room ?? {}) ? ["rematch"] : []]) || !room) return false;
|
|
760
|
+
const limits = record(room.limits), rematch = record(room.rematch);
|
|
761
|
+
if (room.rematch !== void 0 && room.rematch !== null && (!exact(rematch, ["keepSetup", "autoStart"]) || typeof rematch.keepSetup !== "boolean" || typeof rematch.autoStart !== "boolean")) return false;
|
|
762
|
+
return text(room.code) && nullable(room.mode) && nullable(room.host) && nullable(room.you) && ["lobby", "countdown", "playing", "finished", "ended"].includes(String(room.status)) && ["connecting", "connected", "reconnecting", "disconnected", "ended", "closed", "replaced"].includes(String(room.connection)) && ["countdownAt", "closedCode", "delayMs"].every((key) => room[key] === null || finite(room[key])) && ["lobby", "persistent", "requestRole"].every((key) => typeof room[key] === "boolean") && exact(limits, ["min", "max"]) && Object.values(limits).every((v) => Number.isInteger(v) && Number(v) >= 1 && Number(v) <= 24) && Array.isArray(room.players) && room.players.length <= 24 && room.players.every((value2) => {
|
|
669
763
|
const player = record(value2);
|
|
670
764
|
return exact(player, ["id", "name", "guest", "role", "team", "ready", "connected"]) && player !== null && text(player.id) && text(player.name) && nullable(player.role) && (player.team === null || Number.isInteger(player.team) && Number(player.team) >= 1 && Number(player.team) <= 24) && ["guest", "ready", "connected"].every((key) => typeof player[key] === "boolean");
|
|
671
765
|
});
|
|
@@ -682,6 +776,32 @@ function validOverlayVoice(value) {
|
|
|
682
776
|
});
|
|
683
777
|
}
|
|
684
778
|
|
|
779
|
+
// ../contracts/src/match-result.ts
|
|
780
|
+
function readMatchResult(value, playerIds) {
|
|
781
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
782
|
+
const result = object(value);
|
|
783
|
+
if (!result || !Array.isArray(result.standings)) return null;
|
|
784
|
+
const known = new Set(playerIds), seen = /* @__PURE__ */ new Set();
|
|
785
|
+
const standings = [];
|
|
786
|
+
for (const item of result.standings) {
|
|
787
|
+
const row = object(item);
|
|
788
|
+
if (!row || typeof row.playerId !== "string" || !known.has(row.playerId) || seen.has(row.playerId)) continue;
|
|
789
|
+
seen.add(row.playerId);
|
|
790
|
+
standings.push({
|
|
791
|
+
playerId: row.playerId,
|
|
792
|
+
...typeof row.score === "number" && Number.isFinite(row.score) ? { score: row.score } : {},
|
|
793
|
+
...typeof row.rank === "number" && Number.isSafeInteger(row.rank) && row.rank > 0 ? { rank: row.rank } : {}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
if (!standings.length) return null;
|
|
797
|
+
return {
|
|
798
|
+
standings,
|
|
799
|
+
...Array.isArray(result.winners) ? { winners: [...new Set(result.winners.filter((id) => typeof id === "string" && seen.has(id)))] } : {},
|
|
800
|
+
...typeof result.draw === "boolean" ? { draw: result.draw } : {},
|
|
801
|
+
...typeof result.unit === "string" ? { unit: result.unit } : {}
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
685
805
|
// src/errors.ts
|
|
686
806
|
function creaErrore(code, message) {
|
|
687
807
|
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
@@ -817,6 +937,10 @@ function creaPonteOspite(input) {
|
|
|
817
937
|
ticket: input.ticket,
|
|
818
938
|
live: input.origineLive,
|
|
819
939
|
invite: input.invite,
|
|
940
|
+
// language resta disponibile ai kit pubblicati prima della separazione delle lingue.
|
|
941
|
+
...input.language ? { language: input.language, uiLanguage: input.language } : {},
|
|
942
|
+
...input.languagePreferences ? { languagePreferences: input.languagePreferences } : {},
|
|
943
|
+
...input.configuration ? { gameLanguages: manifestLanguages(input.configuration.manifest) } : {},
|
|
820
944
|
...input.configuration && data.overlayVersion === 1 ? { overlay: { v: 1, epoch, configuration: input.configuration } } : {}
|
|
821
945
|
}, input.origineGioco, [channel.port2]);
|
|
822
946
|
};
|
|
@@ -874,7 +998,7 @@ function creaPonteOspite(input) {
|
|
|
874
998
|
requestId: id,
|
|
875
999
|
op,
|
|
876
1000
|
args,
|
|
877
|
-
...["room.ready", "room.role", "room.requestRole", "room.team", "room.start", "session.leave", "session.disconnect", "voice.join", "voice.mute", "voice.leave", "voice.setVolume"].includes(op) ? { sessionId: state?.id ?? null } : {}
|
|
1001
|
+
...["room.ready", "room.role", "room.requestRole", "room.team", "room.start", "room.restart", "session.leave", "session.disconnect", "voice.join", "voice.mute", "voice.leave", "voice.setVolume"].includes(op) ? { sessionId: state?.id ?? null } : {}
|
|
878
1002
|
};
|
|
879
1003
|
if (!validOverlayRequest(request)) return Promise.reject(creaErrore("invalid_request", "The overlay request is invalid."));
|
|
880
1004
|
return new Promise((resolve, reject) => {
|
|
@@ -913,6 +1037,30 @@ function avviaHandshake(input) {
|
|
|
913
1037
|
const bridge = creaPonteOspite(input);
|
|
914
1038
|
return () => bridge.dispose();
|
|
915
1039
|
}
|
|
1040
|
+
function gameViewport(frame) {
|
|
1041
|
+
const rect = frame.getBoundingClientRect();
|
|
1042
|
+
const zoomX = frame.offsetWidth ? rect.width / frame.offsetWidth : 1;
|
|
1043
|
+
const zoomY = frame.offsetHeight ? rect.height / frame.offsetHeight : 1;
|
|
1044
|
+
const left = rect.left + frame.clientLeft * zoomX, top = rect.top + frame.clientTop * zoomY;
|
|
1045
|
+
return {
|
|
1046
|
+
left,
|
|
1047
|
+
top,
|
|
1048
|
+
right: left + frame.clientWidth * zoomX,
|
|
1049
|
+
bottom: top + frame.clientHeight * zoomY,
|
|
1050
|
+
scaleX: zoomX ? 1 / zoomX : 1,
|
|
1051
|
+
scaleY: zoomY ? 1 / zoomY : 1
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function measureSafeArea(frame, probe) {
|
|
1055
|
+
const win = frame.ownerDocument.defaultView, css = win.getComputedStyle(probe), viewport = gameViewport(frame);
|
|
1056
|
+
const clamp = (value, max) => Math.max(0, Math.min(max, value));
|
|
1057
|
+
return {
|
|
1058
|
+
top: clamp(((parseFloat(css.paddingTop) || 0) - viewport.top) * viewport.scaleY, frame.clientHeight),
|
|
1059
|
+
right: clamp((viewport.right - (win.innerWidth - (parseFloat(css.paddingRight) || 0))) * viewport.scaleX, frame.clientWidth),
|
|
1060
|
+
bottom: clamp((viewport.bottom - (win.innerHeight - (parseFloat(css.paddingBottom) || 0))) * viewport.scaleY, frame.clientHeight),
|
|
1061
|
+
left: clamp(((parseFloat(css.paddingLeft) || 0) - viewport.left) * viewport.scaleX, frame.clientWidth)
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
916
1064
|
|
|
917
1065
|
// src/overlay/boards.ts
|
|
918
1066
|
function createBoardController(input) {
|
|
@@ -1011,8 +1159,11 @@ function createBoardController(input) {
|
|
|
1011
1159
|
// src/overlay/i18n.ts
|
|
1012
1160
|
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
1013
1161
|
var words = {
|
|
1162
|
+
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
1014
1163
|
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
1164
|
+
loadingSlow: ["This game is taking longer than expected. You can wait a little longer or try again.", "Il gioco ci sta mettendo pi\xF9 del previsto. Puoi aspettare ancora un po\u2019 o riprovare.", "El juego est\xE1 tardando m\xE1s de lo esperado. Puedes esperar un poco m\xE1s o volver a intentarlo.", "Le jeu met plus de temps que pr\xE9vu. Vous pouvez patienter encore un peu ou r\xE9essayer.", "Das Spiel braucht l\xE4nger als erwartet. Du kannst noch etwas warten oder es erneut versuchen.", "O jogo est\xE1 demorando mais do que o esperado. Voc\xEA pode esperar mais um pouco ou tentar novamente."],
|
|
1015
1165
|
home: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
1166
|
+
homeMenu: ["Menu", "Menu", "Men\xFA", "Menu", "Men\xFC", "Menu"],
|
|
1016
1167
|
mode: ["Mode", "Modalit\xE0", "Modo", "Mode", "Modus", "Modo"],
|
|
1017
1168
|
play: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
1018
1169
|
friendsPlay: ["Play with friends", "Gioca con amici", "Jugar con amigos", "Jouer entre amis", "Mit Freunden spielen", "Jogar com amigos"],
|
|
@@ -1048,6 +1199,15 @@ var words = {
|
|
|
1048
1199
|
starting: ["Starting in", "Si inizia tra", "Empieza en", "D\xE9but dans", "Start in", "Come\xE7a em"],
|
|
1049
1200
|
playing: ["Playing", "In partita", "Jugando", "En jeu", "Im Spiel", "Jogando"],
|
|
1050
1201
|
ended: ["Game finished", "Partita conclusa", "Partida terminada", "Partie termin\xE9e", "Spiel beendet", "Partida encerrada"],
|
|
1202
|
+
rematchReady: ["{n}/{max} ready", "{n}/{max} pronti", "{n}/{max} listos", "{n}/{max} pr\xEAts", "{n}/{max} bereit", "{n}/{max} prontos"],
|
|
1203
|
+
rematchStart: ["Start rematch", "Avvia rivincita", "Iniciar revancha", "Lancer la revanche", "Revanche starten", "Iniciar revanche"],
|
|
1204
|
+
won: ["You won", "Hai vinto", "Has ganado", "Vous avez gagn\xE9", "Du hast gewonnen", "Voc\xEA venceu"],
|
|
1205
|
+
lost: ["You lost", "Hai perso", "Has perdido", "Vous avez perdu", "Du hast verloren", "Voc\xEA perdeu"],
|
|
1206
|
+
draw: ["Draw", "Pareggio", "Empate", "\xC9galit\xE9", "Unentschieden", "Empate"],
|
|
1207
|
+
standings: ["Standings", "Piazzamenti", "Posiciones", "R\xE9sultats", "Platzierungen", "Coloca\xE7\xF5es"],
|
|
1208
|
+
points: ["points", "punti", "puntos", "points", "Punkte", "pontos"],
|
|
1209
|
+
time: ["time", "tempo", "tiempo", "temps", "Zeit", "tempo"],
|
|
1210
|
+
distance: ["distance", "distanza", "distancia", "distance", "Distanz", "dist\xE2ncia"],
|
|
1051
1211
|
again: ["Play again", "Gioca ancora", "Jugar de nuevo", "Rejouer", "Erneut spielen", "Jogar novamente"],
|
|
1052
1212
|
newRoom: ["New room. Share the new invite.", "Nuova stanza. Condividi il nuovo invito.", "Nueva sala. Comparte la invitaci\xF3n.", "Nouvelle salle. Partagez le lien.", "Neuer Raum. Neue Einladung teilen.", "Nova sala. Compartilhe o convite."],
|
|
1053
1213
|
watching: ["Watching", "In osservazione", "Observando", "Spectateur", "Zuschauen", "Assistindo"],
|
|
@@ -1129,6 +1289,10 @@ function overlayLanguage(raw) {
|
|
|
1129
1289
|
const value = raw?.toLowerCase().split("-")[0];
|
|
1130
1290
|
return languages.includes(value) ? value : "en";
|
|
1131
1291
|
}
|
|
1292
|
+
function overlayLocale(raw) {
|
|
1293
|
+
const tag = normalizeLanguage(raw);
|
|
1294
|
+
return tag && languages.includes(tag.split("-")[0]) ? tag : "en";
|
|
1295
|
+
}
|
|
1132
1296
|
function translator(language) {
|
|
1133
1297
|
const dictionary = dictionaries[overlayLanguage(language)];
|
|
1134
1298
|
return (key, values = {}) => dictionary[key].replace(/\{(\w+)\}/g, (_all, name) => String(values[name] ?? ""));
|
|
@@ -1157,7 +1321,7 @@ function phase(session) {
|
|
|
1157
1321
|
if (session.kind === "attaching" || session.kind === "matching") return session.kind;
|
|
1158
1322
|
if (session.room && ["closed", "replaced"].includes(session.room.connection)) return "error";
|
|
1159
1323
|
if (session.kind === "local") return session.localStatus === "ended" ? "ended" : "playing";
|
|
1160
|
-
if (session.room?.status === "ended") return "ended";
|
|
1324
|
+
if (session.room?.status === "ended" || session.room?.status === "finished") return "ended";
|
|
1161
1325
|
if (session.kind === "watch") return "watching";
|
|
1162
1326
|
if (session.kind === "room" && session.room) return session.room.status;
|
|
1163
1327
|
return "home";
|
|
@@ -1171,7 +1335,7 @@ function reduceUi(model, action) {
|
|
|
1171
1335
|
const next = action.session, changed = next?.id !== model.session?.id || next === null;
|
|
1172
1336
|
const pending = next?.kind === "attaching" || next?.kind === "matching";
|
|
1173
1337
|
const nextPhase = phase(next), transition = phase(model.session) !== nextPhase;
|
|
1174
|
-
const automatic = transition && ["countdown", "playing", "ended"].includes(nextPhase) && [null, "auto", "room", "invite", "home"].includes(model.panel);
|
|
1338
|
+
const automatic = transition && ["lobby", "countdown", "playing", "ended"].includes(nextPhase) && [null, "auto", "room", "invite", "home"].includes(model.panel);
|
|
1175
1339
|
return {
|
|
1176
1340
|
...model,
|
|
1177
1341
|
session: next,
|
|
@@ -1198,7 +1362,9 @@ function reduceUi(model, action) {
|
|
|
1198
1362
|
function visiblePanel(model) {
|
|
1199
1363
|
const current = phase(model.session);
|
|
1200
1364
|
if (current === "boot" || current === "attaching" || current === "matching" || current === "error") return current;
|
|
1365
|
+
if (model.session?.room?.limits.max === 1 && ["room", "invite"].includes(model.panel ?? "")) return "home";
|
|
1201
1366
|
if (model.panel !== "auto") return model.panel;
|
|
1367
|
+
if (model.session?.room?.limits.max === 1 && current === "lobby") return null;
|
|
1202
1368
|
return current === "home" ? "home" : current === "lobby" ? "room" : current === "countdown" ? "countdown" : null;
|
|
1203
1369
|
}
|
|
1204
1370
|
function primaryAction(manifest, mode) {
|
|
@@ -1222,20 +1388,40 @@ function startReason(manifest, session) {
|
|
|
1222
1388
|
function canPlayAgain(session) {
|
|
1223
1389
|
if (phase(session) !== "ended") return false;
|
|
1224
1390
|
if (session?.kind === "local") return true;
|
|
1225
|
-
return session
|
|
1391
|
+
if (session?.room?.status === "finished") return session.kind === "room" && session.room.connection === "connected" && (session.room.limits.max === 1 || session.room.players.some((p) => p.id === session.room.you && p.connected && p.role !== "spectator" && !p.ready));
|
|
1392
|
+
return session?.kind === "room" && (session.room?.limits.max === 1 || !session.room?.lobby || session.room.host === session.room.you);
|
|
1226
1393
|
}
|
|
1227
1394
|
function normalizeInvite(code) {
|
|
1228
1395
|
const value = code.toUpperCase().replace(/[\s-]/g, "");
|
|
1229
1396
|
return /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(value) ? value : null;
|
|
1230
1397
|
}
|
|
1398
|
+
function matchPresentation(session) {
|
|
1399
|
+
const room = session?.room;
|
|
1400
|
+
if (!room || !["finished", "ended"].includes(room.status)) return null;
|
|
1401
|
+
const result = readMatchResult(room.result, room.players.map((p) => p.id));
|
|
1402
|
+
if (!result) return null;
|
|
1403
|
+
const own = session?.kind === "room" && room.players.some((p) => p.id === room.you && p.role !== "spectator") && result.standings.some((p) => p.playerId === room.you);
|
|
1404
|
+
const first = result.standings[0];
|
|
1405
|
+
const winners = result.winners ?? result.standings.filter((p, i) => i === 0 || first.rank !== void 0 && p.rank === first.rank).map((p) => p.playerId);
|
|
1406
|
+
return { result, outcome: !own ? "ended" : result.draw ? "draw" : winners.includes(room.you) ? "won" : "lost" };
|
|
1407
|
+
}
|
|
1231
1408
|
|
|
1232
1409
|
// src/overlay/styles.ts
|
|
1233
1410
|
var styles = `
|
|
1411
|
+
.game-icon{width:28px;height:28px;aspect-ratio:1;object-fit:contain;border-radius:7px;flex:none;vertical-align:middle}.game-icon-title{width:56px;height:56px;margin-bottom:12px}
|
|
1412
|
+
.safe-area-probe{position:fixed;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)}
|
|
1234
1413
|
:host{all:initial;position:fixed;inset:0;z-index:10000;pointer-events:none;font:15px/1.45 system-ui,sans-serif;color:#f4f4f1;color-scheme:dark;--accent:#a8efc5}
|
|
1235
|
-
[data-layout],[data-surface],.sr{pointer-events:none}*{box-sizing:border-box}button,input,select{font:inherit}button,a,input,select{touch-action:manipulation}button,select,input{border:1px solid #ffffff30;background:#25292b;color:inherit;border-radius:12px;min-height:44px;padding:10px 14px}button{cursor:pointer}button:disabled{opacity:.45;cursor:default}button:hover:not(:disabled){background:#343b3a}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid var(--accent);outline-offset:3px}a{color:var(--accent)}.primary{background:var(--accent);color:var(--accent-ink,#11221b);border-color:transparent;font-weight:700}.primary:hover:not(:disabled){filter:brightness(1.1);background:var(--accent)}.quiet{background:transparent}label{display:grid;gap:6px;text-align:left}select,input{width:100%;min-width:0}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);line-height:1.1;letter-spacing:-.035em}h2{font-size:20px}small,.muted{color:#bdc5c1}.stack{display:grid;gap:16px}.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.row>*{flex:0 1 auto}.row .grow,.grow{flex:1}.split{display:grid;grid-template-columns:1fr 1fr;gap:10px}.pill{position:absolute;top:max(10px,env(safe-area-inset-top));right:max(10px,env(safe-area-inset-right));display:flex;height:44px;border:1px solid #ffffff35;border-radius:24px;background:#171e20eF;box-shadow:0 4px 20px #0004;pointer-events:auto;overflow:hidden}.pill button{border:0;border-radius:0;padding:8px 13px;background:transparent}.pill
|
|
1414
|
+
[data-layout],[data-surface],.sr{pointer-events:none}*{box-sizing:border-box}button,input,select{font:inherit}button,a,input,select{touch-action:manipulation}button,select,input{border:1px solid #ffffff30;background:#25292b;color:inherit;border-radius:12px;min-height:44px;padding:10px 14px}button{cursor:pointer}button:disabled{opacity:.45;cursor:default}button:hover:not(:disabled){background:#343b3a}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid var(--accent);outline-offset:3px}a{color:var(--accent)}.primary{background:var(--accent);color:var(--accent-ink,#11221b);border-color:transparent;font-weight:700}.primary:hover:not(:disabled){filter:brightness(1.1);background:var(--accent)}.quiet{background:transparent}label{display:grid;gap:6px;text-align:left}select,input{width:100%;min-width:0}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);line-height:1.1;letter-spacing:-.035em}h2{font-size:20px}small,.muted{color:#bdc5c1}.stack{display:grid;gap:16px}.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.row>*{flex:0 1 auto}.row .grow,.grow{flex:1}.split{display:grid;grid-template-columns:1fr 1fr;gap:10px}.pill{position:absolute;top:max(10px,env(safe-area-inset-top));right:max(10px,env(safe-area-inset-right));display:flex;height:44px;border:1px solid #ffffff35;border-radius:24px;background:#171e20eF;box-shadow:0 4px 20px #0004;pointer-events:auto;overflow:hidden}.pill button{border:0;border-radius:0;padding:8px 13px;background:transparent}.pill button:focus-visible{outline-offset:-4px}.pill small{margin-left:8px}.backdrop{position:absolute;inset:0;background:#0b151ce8;backdrop-filter:blur(10px);pointer-events:auto;display:grid;place-items:center;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow:auto}.backdrop.home{background-color:#142127;background-size:contain;background-repeat:no-repeat;background-position:center}.dialog{position:relative;width:min(100%,540px);max-height:100%;overflow:auto;overscroll-behavior:contain;background:#141b1df5;border:1px solid #ffffff25;border-radius:22px;padding:24px;box-shadow:0 20px 80px #0005}.dialog.wide{width:min(100%,700px)}.top{display:flex;align-items:center;gap:12px;margin-bottom:18px}.top h2{flex:1}.tabs{display:flex;gap:6px;flex-wrap:wrap;border-bottom:1px solid #ffffff25;padding-bottom:12px}.tabs button{min-height:36px;padding:6px 10px}.tabs [aria-current=true]{border-color:var(--accent)}.roster{list-style:none;padding:0;margin:0;display:grid;gap:8px;max-height:32dvh;overflow:auto}.roster li{display:flex;align-items:center;gap:8px;padding:10px;background:#ffffff08;border-radius:10px}.roster .name{flex:1;overflow-wrap:anywhere}.badge{border:1px solid #ffffff30;border-radius:6px;padding:2px 6px;font-size:12px}.code{font-size:24px;letter-spacing:.13em;font-variant-numeric:tabular-nums}.notice,.error{border-radius:10px;padding:10px;background:#a8efc514;overflow-wrap:anywhere}.error{background:#ff8b7720;color:#ffd2c9}.countdown{font-size:88px;line-height:1;text-align:center;font-variant-numeric:tabular-nums}.ended{position:absolute;bottom:max(12px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);max-width:calc(100% - 24px);width:max-content;background:#171e20f5;pointer-events:auto;border:1px solid #ffffff30;border-radius:16px;padding:10px;display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap}.ended [data-rematch-players]{max-width:100%;max-height:3.2em;overflow:auto;overflow-wrap:anywhere}.standings{list-style:none;margin:0;padding:0;flex-basis:100%;max-height:20dvh;overflow:auto;font-size:13px}.standings li{display:flex;justify-content:space-between;gap:16px;overflow-wrap:anywhere}.ended{max-height:calc(100dvh - 80px);overflow:auto}.ended strong{padding:0 8px}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.table-wrap{overflow:auto;max-height:38dvh}table{width:100%;border-collapse:collapse;text-align:left}th,td{padding:9px 6px;border-bottom:1px solid #ffffff20}td:nth-child(3){text-align:right}td small{display:block}.self{background:#ffffff0a}.checkbox{display:flex;align-items:center;gap:8px;font-size:13px}.checkbox input{width:18px;min-height:18px}.full{width:100%}
|
|
1236
1415
|
[hidden]{display:none!important}.voice-peers{list-style:none;margin:0;padding:0;display:grid;gap:10px}.voice-peers li{border:1px solid #ffffff25;border-radius:12px;padding:12px;display:grid;gap:8px}.voice-peers [data-speaking=true]{border-color:var(--accent)}.voice-peers input{width:100%;accent-color:var(--accent);padding:0}.voice-peers label{font-size:13px}.pill .voice-toggle{width:44px;padding:8px}.voice-toggle[data-voice-state=on][data-muted=false]{color:var(--accent)}
|
|
1237
|
-
|
|
1238
|
-
|
|
1416
|
+
.boot{position:absolute;inset:0;z-index:2;isolation:isolate;display:grid;place-items:center;overflow:auto;overscroll-behavior:contain;padding:max(100px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)) max(48px,env(safe-area-inset-bottom)) max(24px,env(safe-area-inset-left));background:#0b151c;opacity:1;transition:opacity .4s ease;pointer-events:auto;outline:none}
|
|
1417
|
+
.boot::before,.boot::after{content:"";position:fixed;inset:0;pointer-events:none;z-index:-1}.boot::before{background:radial-gradient(ellipse at 50% 38%,color-mix(in srgb,var(--accent),transparent 80%),transparent 65%)}.boot::after{background:radial-gradient(ellipse at 50% 38%,#0b151c20,#0b151cd9 85%),linear-gradient(#0b151c66,#0b151cbf)}
|
|
1418
|
+
.boot-cover{position:fixed;inset:0;z-index:-2;width:100%;height:100%;aspect-ratio:3 / 2;object-fit:contain;filter:blur(20px);opacity:.65;pointer-events:none}
|
|
1419
|
+
.boot-brand{position:absolute;top:max(28px,env(safe-area-inset-top));left:max(32px,env(safe-area-inset-left));display:flex;align-items:center;gap:10px;font-size:14px;font-weight:650;letter-spacing:.02em;color:#f4f4f1b3}.boot-brand span{display:grid;place-items:center;width:36px;height:36px;border:1px solid #ffffff25;border-radius:12px;background:#171e20af;box-shadow:0 4px 20px #0004;color:var(--boot-accent);font-size:20px;font-weight:800}
|
|
1420
|
+
.boot-content{width:min(100%,900px);text-align:center;display:grid;justify-items:center;gap:24px}.boot h1{max-width:16ch;font-size:clamp(44px,8vw,108px);font-weight:800;line-height:1.04;letter-spacing:-.05em;overflow-wrap:anywhere;text-wrap:balance;color:var(--boot-accent);text-shadow:0 20px 80px #0005}
|
|
1421
|
+
.boot-progress{width:112px;height:3px;border-radius:12px;background:#ffffff20;overflow:hidden;margin-top:12px}.boot-progress span{display:block;width:44%;height:100%;border-radius:inherit;background:var(--boot-accent);animation:boot-progress 1.8s ease-in-out infinite}.boot-status{max-width:42ch;min-height:3em;font-size:14px;line-height:1.5;color:#d3dad6;text-wrap:balance}.boot-recovery{min-height:44px}.boot-recovery .row{justify-content:center}.boot-leaving{opacity:0;pointer-events:none}
|
|
1422
|
+
@keyframes boot-progress{0%{transform:translateX(-110%)}100%{transform:translateX(340%)}}
|
|
1423
|
+
@media(max-width:480px){.dialog{padding:18px;border-radius:18px}.split{grid-template-columns:1fr 1fr;gap:8px}.tabs{gap:4px}.tabs button{font-size:13px;padding:6px 8px}.pill button:focus-visible{outline-offset:-4px}.pill small{display:none}.ended{gap:6px}.standings{list-style:none;margin:0;padding:0;flex-basis:100%;max-height:20dvh;overflow:auto;font-size:13px}.standings li{display:flex;justify-content:space-between;gap:16px;overflow-wrap:anywhere}.ended{max-height:calc(100dvh - 80px);overflow:auto}.ended strong{font-size:13px}.ended button{padding:8px 10px;font-size:13px}.roster{max-height:28dvh}}
|
|
1424
|
+
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}.boot{transition:none}.boot-progress span{animation:none;transform:translateX(65%)}}
|
|
1239
1425
|
`;
|
|
1240
1426
|
|
|
1241
1427
|
// src/overlay/voice-panel.ts
|
|
@@ -1331,7 +1517,10 @@ function mountOverlay(input) {
|
|
|
1331
1517
|
elements.dataset.layout = "";
|
|
1332
1518
|
elements.style.pointerEvents = "none";
|
|
1333
1519
|
elements.innerHTML = `<div data-surface></div><div class="sr" role="status" aria-live="polite" data-live></div>`;
|
|
1334
|
-
|
|
1520
|
+
const safeProbe = document.createElement("div");
|
|
1521
|
+
safeProbe.className = "safe-area-probe";
|
|
1522
|
+
safeProbe.setAttribute("aria-hidden", "true");
|
|
1523
|
+
root.append(elements, safeProbe);
|
|
1335
1524
|
const surface = root.querySelector("[data-surface]"), live = root.querySelector("[data-live]");
|
|
1336
1525
|
surface.style.pointerEvents = "none";
|
|
1337
1526
|
live.style.pointerEvents = "none";
|
|
@@ -1340,9 +1529,11 @@ function mountOverlay(input) {
|
|
|
1340
1529
|
const rgb = [1, 3, 5].map((i) => parseInt(accent.slice(i, i + 2), 16) / 255).map((v) => v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
1341
1530
|
const luminance = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722;
|
|
1342
1531
|
host.style.setProperty("--accent-ink", luminance > 0.179 ? "#000000" : "#ffffff");
|
|
1532
|
+
host.style.setProperty("--boot-accent", luminance > 0.179 ? accent : `color-mix(in srgb, ${accent}, #ffffff 70%)`);
|
|
1343
1533
|
input.container.append(host);
|
|
1344
1534
|
let model = initialUi(manifest), disposed = false, operation = 0, lastView = "", geometryFrame = 0;
|
|
1345
1535
|
let lastPhase = "", wasModal = false, copyFallback = null;
|
|
1536
|
+
let boot = null, bootTimer = 0, bootFadeTimer = 0;
|
|
1346
1537
|
let voiceError = null, voicePending = null, voiceOperation = 0;
|
|
1347
1538
|
let codeDraft = input.configuration.invite ?? "";
|
|
1348
1539
|
const oldInert = Boolean(input.frame.inert), oldTabIndex = input.frame.getAttribute("tabindex");
|
|
@@ -1355,6 +1546,70 @@ function mountOverlay(input) {
|
|
|
1355
1546
|
const selectedMode = () => manifest.modes.find((mode) => mode.id === model.mode);
|
|
1356
1547
|
const disabled = () => model.busy ? " disabled" : "";
|
|
1357
1548
|
const button = (action, key, extra = "", off = false) => `<button type="button" data-action="${action}"${extra}${off || model.busy ? " disabled" : ""}>${t(key)}</button>`;
|
|
1549
|
+
function resetBootWait() {
|
|
1550
|
+
win.clearTimeout(bootTimer);
|
|
1551
|
+
if (!boot || phase(model.session) !== "boot") return;
|
|
1552
|
+
boot.querySelector("[data-boot-message]").textContent = t("loading");
|
|
1553
|
+
boot.querySelector("[data-boot-recovery]").hidden = true;
|
|
1554
|
+
bootTimer = win.setTimeout(() => {
|
|
1555
|
+
bootTimer = 0;
|
|
1556
|
+
if (disposed || !boot) return;
|
|
1557
|
+
boot.querySelector("[data-boot-message]").textContent = t("loadingSlow");
|
|
1558
|
+
boot.querySelector("[data-boot-recovery]").hidden = false;
|
|
1559
|
+
}, 9e3);
|
|
1560
|
+
}
|
|
1561
|
+
function updateBoot(loading) {
|
|
1562
|
+
if (loading) {
|
|
1563
|
+
if (boot) {
|
|
1564
|
+
win.clearTimeout(bootFadeTimer);
|
|
1565
|
+
bootFadeTimer = 0;
|
|
1566
|
+
boot.inert = false;
|
|
1567
|
+
boot.removeAttribute("aria-hidden");
|
|
1568
|
+
boot.style.pointerEvents = "auto";
|
|
1569
|
+
boot.classList.remove("boot-leaving");
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
boot = document.createElement("section");
|
|
1573
|
+
boot.className = "boot";
|
|
1574
|
+
boot.tabIndex = -1;
|
|
1575
|
+
boot.setAttribute("aria-labelledby", "boot-title");
|
|
1576
|
+
boot.setAttribute("aria-describedby", "boot-status");
|
|
1577
|
+
boot.style.pointerEvents = "auto";
|
|
1578
|
+
boot.innerHTML = `<div class="boot-brand" aria-hidden="true"><span>C</span>Caisual</div>
|
|
1579
|
+
<div class="boot-content"><h1 id="boot-title">${escape(manifest.name)}</h1>
|
|
1580
|
+
<div class="boot-progress" aria-hidden="true"><span></span></div>
|
|
1581
|
+
<p class="boot-status" id="boot-status" role="status" aria-live="polite" aria-atomic="true"><span class="sr">${escape(manifest.name)}. </span><span data-boot-message></span></p>
|
|
1582
|
+
<div class="boot-recovery"><div class="row" data-boot-recovery hidden>${button("reload", "retry", ' class="primary"')}${button("exit-now", "exit", ' class="quiet"')}</div></div>
|
|
1583
|
+
</div>`;
|
|
1584
|
+
if (input.configuration.coverUrl) {
|
|
1585
|
+
const cover = document.createElement("img");
|
|
1586
|
+
cover.className = "boot-cover";
|
|
1587
|
+
cover.alt = "";
|
|
1588
|
+
cover.setAttribute("aria-hidden", "true");
|
|
1589
|
+
cover.addEventListener("error", () => {
|
|
1590
|
+
cover.hidden = true;
|
|
1591
|
+
}, { once: true });
|
|
1592
|
+
cover.src = input.configuration.coverUrl;
|
|
1593
|
+
boot.prepend(cover);
|
|
1594
|
+
}
|
|
1595
|
+
elements.append(boot);
|
|
1596
|
+
resetBootWait();
|
|
1597
|
+
} else if (boot && !boot.inert) {
|
|
1598
|
+
boot.inert = true;
|
|
1599
|
+
boot.setAttribute("aria-hidden", "true");
|
|
1600
|
+
boot.style.pointerEvents = "none";
|
|
1601
|
+
boot.classList.add("boot-leaving");
|
|
1602
|
+
const remove = () => {
|
|
1603
|
+
win.clearTimeout(bootTimer);
|
|
1604
|
+
bootTimer = 0;
|
|
1605
|
+
boot?.remove();
|
|
1606
|
+
boot = null;
|
|
1607
|
+
bootFadeTimer = 0;
|
|
1608
|
+
};
|
|
1609
|
+
if (win.matchMedia?.("(prefers-reduced-motion: reduce)").matches) remove();
|
|
1610
|
+
else bootFadeTimer = win.setTimeout(remove, 420);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1358
1613
|
const dispatch = (action) => {
|
|
1359
1614
|
if (disposed) return;
|
|
1360
1615
|
model = reduceUi(model, action);
|
|
@@ -1364,7 +1619,9 @@ function mountOverlay(input) {
|
|
|
1364
1619
|
if (live.textContent !== text) live.textContent = text;
|
|
1365
1620
|
};
|
|
1366
1621
|
const controls = () => [...root.querySelectorAll('button:not(:disabled),a[href],input:not(:disabled),select:not(:disabled),[tabindex="0"]')].filter((el) => !el.closest("[hidden]"));
|
|
1367
|
-
const
|
|
1622
|
+
const soloMode = (mode) => (mode === null || manifest.modes.some((item) => item.id === mode)) && risolviModalita(manifest, mode).players.max === 1;
|
|
1623
|
+
const solo = () => model.session?.room?.limits.max === 1;
|
|
1624
|
+
const roomCode = () => solo() ? null : model.session?.room?.code ?? null;
|
|
1368
1625
|
const setPanel = (panel) => {
|
|
1369
1626
|
if (panel === "boards" && boards && !boards.state.query) {
|
|
1370
1627
|
const id = Object.keys(manifest.boards)[0];
|
|
@@ -1375,6 +1632,7 @@ function mountOverlay(input) {
|
|
|
1375
1632
|
};
|
|
1376
1633
|
const close = () => {
|
|
1377
1634
|
const current = phase(model.session), panel = visiblePanel(model);
|
|
1635
|
+
if (current === "boot") return;
|
|
1378
1636
|
if (current === "home") setPanel("home");
|
|
1379
1637
|
else if (current === "lobby" && panel !== "room") setPanel("room");
|
|
1380
1638
|
else setPanel(null);
|
|
@@ -1439,13 +1697,14 @@ function mountOverlay(input) {
|
|
|
1439
1697
|
}
|
|
1440
1698
|
}
|
|
1441
1699
|
function invitation() {
|
|
1700
|
+
if (solo()) return "";
|
|
1442
1701
|
const code = roomCode();
|
|
1443
1702
|
if (!code) return `<p>${t("noRoom")}</p>`;
|
|
1444
1703
|
return `<div class="row"><div class="grow"><small>${t("code")}</small><div class="code" data-room-code>${escape(code)}</div></div>${button("copy", "copy")}</div>${copyFallback ? `<label>${t("copyFailed")}<input data-control="invite-link" readonly value="${escape(copyFallback)}"></label>` : ""}`;
|
|
1445
1704
|
}
|
|
1446
1705
|
function navigation(panel) {
|
|
1447
1706
|
const items = [];
|
|
1448
|
-
if (model.session?.room) items.push(["room", "room"], ["invite", "copy"]);
|
|
1707
|
+
if (model.session?.room && !solo()) items.push(["room", "room"], ["invite", "copy"]);
|
|
1449
1708
|
items.push(["friends", "friends"]);
|
|
1450
1709
|
if (Object.keys(manifest.boards).length) items.push(["boards", "boards"]);
|
|
1451
1710
|
if (voiceEligible(manifest, model.session)) items.push(["voice", "voice"]);
|
|
@@ -1453,15 +1712,15 @@ function mountOverlay(input) {
|
|
|
1453
1712
|
}
|
|
1454
1713
|
function home() {
|
|
1455
1714
|
const selected = selectedMode(), action = primaryAction(manifest, model.mode), session = model.session;
|
|
1456
|
-
const hasRooms = manifest.modes.some((mode) => mode.execution === "room");
|
|
1457
|
-
return `<h1>${escape(manifest.name)}</h1><label>${t("mode")}<select data-control="mode"${disabled()}>${manifest.modes.map((mode) => `<option value="${escape(mode.id)}"${mode.id === model.mode ? " selected" : ""}>${escape(risolviPresentazione(manifest, mode.id).label)}</option>`).join("")}</select></label>
|
|
1458
|
-
${selected?.instructions ? `<p class="muted">${escape(selected.instructions)}</p>` : ""}
|
|
1715
|
+
const hasRooms = manifest.modes.some((mode) => mode.execution === "room" && risolviModalita(manifest, mode.id).players.max > 1);
|
|
1716
|
+
return `${input.configuration.iconUrl ? `<img class="game-icon game-icon-title" src="${escape(input.configuration.iconUrl)}" alt="" />` : ""}<h1>${escape(manifest.name)}</h1><p class="muted" data-game-languages>${t("gameLanguages")}: ${escape(manifestLanguages(manifest).join(" \xB7 "))}</p><label>${t("mode")}<select data-control="mode"${disabled()}>${manifest.modes.map((mode) => `<option value="${escape(mode.id)}"${mode.id === model.mode ? " selected" : ""}>${escape(risolviPresentazione(manifest, mode.id, input.language).label)}</option>`).join("")}</select></label>
|
|
1717
|
+
${selected?.instructions ? `<p class="muted">${escape(resolveText(selected.instructions, input.language, manifestLanguages(manifest)[0]))}</p>` : ""}
|
|
1459
1718
|
${input.configuration.invite && phase(session) === "home" ? button("join-invite", "joinInvite", ' class="primary"', !session?.ready) : ""}
|
|
1460
1719
|
${action ? button("play", action.friends ? "friendsPlay" : "play", ' class="primary"', !session?.ready) : ""}
|
|
1461
1720
|
${selected?.matchmaking ? button("match", "find", "", !selected.matchmaking.defaults || !session?.ready) : ""}
|
|
1462
|
-
${session?.resume ? button("resume", "resume", "", !session.ready) + `<small>${escape(session.resume.code)}</small>` : ""}
|
|
1463
|
-
${hasRooms ? `<div class="split">${button("panel:join", "join", "", !session?.ready)}${manifest.spectators ? button("panel:watch", "watch", "", !session?.ready) : ""}</div>` : ""}
|
|
1464
|
-
${navigation("home")}<label class="checkbox"><input type="checkbox" data-control="shortcut"${model.shortcutEnabled ? " checked" : ""}>${t("shortcut")}</label>`;
|
|
1721
|
+
${session?.resume ? button("resume", "resume", "", !session.ready) + `<small>${escape(solo() || soloMode(session.resume.mode) ? "" : session.resume.code)}</small>` : ""}
|
|
1722
|
+
${hasRooms && !solo() ? `<div class="split">${button("panel:join", "join", "", !session?.ready)}${manifest.spectators ? button("panel:watch", "watch", "", !session?.ready) : ""}</div>` : ""}
|
|
1723
|
+
${solo() ? button("panel:exit", "exit", ' class="quiet"') : ""}${navigation("home")}<label class="checkbox"><input type="checkbox" data-control="shortcut"${model.shortcutEnabled ? " checked" : ""}>${t("shortcut")}</label>`;
|
|
1465
1724
|
}
|
|
1466
1725
|
function room() {
|
|
1467
1726
|
const session = model.session, room2 = session?.room;
|
|
@@ -1469,8 +1728,8 @@ function mountOverlay(input) {
|
|
|
1469
1728
|
const own = room2.players.find((player) => player.id === room2.you), lobby = room2.status === "lobby" && session?.kind === "room";
|
|
1470
1729
|
const canRole = session?.kind === "room" && (lobby || room2.status === "playing" && room2.requestRole);
|
|
1471
1730
|
const reason = startReason(manifest, session);
|
|
1472
|
-
return `${invitation()}<ul class="roster" aria-label="${t("room")}">${room2.players.map((p) => `<li data-player-id="${escape(p.id)}"><span class="name">${escape(p.name)} ${p.id === room2.you ? `<small>(${t("you")})</small>` : ""}</span>${p.id === room2.host ? `<span class="badge">${t("host")}</span>` : ""}${p.role ? `<small>${escape(manifest.roles.find((r) => r.id === p.role)?.label
|
|
1473
|
-
${canRole && manifest.roles.length ? `<label>${t("role")}<select data-control="role"${disabled()}><option value="" disabled${!own?.role ? " selected" : ""}>${t("role")}</option>${manifest.roles.map((role) => `<option value="${escape(role.id)}"${role.id === own?.role ? " selected" : ""}>${escape(role.label
|
|
1731
|
+
return `${invitation()}<ul class="roster" aria-label="${t("room")}">${room2.players.map((p) => `<li data-player-id="${escape(p.id)}"><span class="name">${escape(p.name)} ${p.id === room2.you ? `<small>(${t("you")})</small>` : ""}</span>${p.id === room2.host ? `<span class="badge">${t("host")}</span>` : ""}${p.role ? `<small>${escape(resolveText(manifest.roles.find((r) => r.id === p.role)?.label, input.language, manifestLanguages(manifest)[0], p.role))}</small>` : ""}${p.team ? `<small>${t("team")} ${p.team}</small>` : ""}<small>${!p.connected ? t("away") : lobby ? t(p.ready ? "ready" : "unready") : ""}</small></li>`).join("")}</ul>
|
|
1732
|
+
${canRole && manifest.roles.length ? `<label>${t("role")}<select data-control="role"${disabled()}><option value="" disabled${!own?.role ? " selected" : ""}>${t("role")}</option>${manifest.roles.map((role) => `<option value="${escape(role.id)}"${role.id === own?.role ? " selected" : ""}>${escape(resolveText(role.label, input.language, manifestLanguages(manifest)[0], role.id))}</option>`).join("")}</select></label>` : ""}
|
|
1474
1733
|
${lobby && manifest.teams ? `<label>${t("team")}<select data-control="team"${disabled()}><option value="" disabled${!own?.team ? " selected" : ""}>${t("team")}</option>${Array.from({ length: manifest.teams.max }, (_, i) => `<option value="${i + 1}"${own?.team === i + 1 ? " selected" : ""}>${t("team")} ${i + 1}</option>`).join("")}</select></label>` : ""}
|
|
1475
1734
|
${lobby ? `<div class="row">${button("ready", own?.ready ? "unready" : "ready", ' class="primary"', room2.connection !== "connected")}${room2.host === room2.you ? button("start", "start", "", reason !== null) : ""}</div>${reason ? `<p class="muted" data-start-reason>${t(reason)}</p>` : ""}` : ""}
|
|
1476
1735
|
${session?.kind === "watch" ? `<p>${t("watching")} \xB7 ${t("delay", { n: (room2.delayMs ?? 0) / 1e3 })}</p>` : ""}
|
|
@@ -1480,17 +1739,17 @@ function mountOverlay(input) {
|
|
|
1480
1739
|
const provider = input.crew, state = provider?.getSnapshot();
|
|
1481
1740
|
if (!provider || provider.unavailable || !state?.you) return `<p>${t(provider?.unavailable === "local" ? "localCrew" : "loginCrew")}</p>`;
|
|
1482
1741
|
const online = state.friends.filter((friend) => friend.online), party = state.party;
|
|
1483
|
-
const person = (p) => `<li
|
|
1742
|
+
const person = (p) => `<li>${p.game ? `<img class="game-icon" src="${escape(p.game.iconUrl)}" alt="" />` : ""}<span class="name">${escape(p.name)}<small>${p.game ? ` \xB7 ${escape(p.game.name)}` : ""}</small></span>${p.room && p.game ? button("follow", "follow", ` data-code="${escape(p.room.code)}" data-game="${escape(p.game.slug)}"`) : ""}${party?.leader === state.you.id && !party.members.some((member) => member.id === p.id) ? button("party-invite", "inviteParty", ` data-player="${escape(p.id)}"`) : ""}</li>`;
|
|
1484
1743
|
return `${!state.connected ? `<p>${t("reconnecting")}</p>` : ""}${party ? `<ul class="roster">${party.members.map(person).join("")}</ul>${button("party-leave", "leaveParty")}` : button("party-create", "createParty")}
|
|
1485
1744
|
${state.invites.map((invite) => `<div class="row"><span class="grow">${escape(invite.from.name)}</span>${button("party-accept", "accept", ` data-party="${escape(invite.party)}"`)}${button("party-decline", "decline", ` data-party="${escape(invite.party)}"`)}</div>`).join("")}
|
|
1486
|
-
${state.follow ? `<div class="row"><span class="grow"
|
|
1745
|
+
${state.follow ? `<div class="row"><span class="grow"><img class="game-icon" src="${escape(state.follow.game.iconUrl)}" alt="" /> ${escape(state.follow.from.name)} \xB7 ${escape(state.follow.game.name)}</span>${button("follow", "follow", ` data-code="${escape(state.follow.code)}" data-game="${escape(state.follow.game.slug)}"`)}</div>` : ""}
|
|
1487
1746
|
<h2>${t("online")}</h2>${online.length ? `<ul class="roster">${online.map(person).join("")}</ul>` : `<p class="muted">${t("noFriends")}</p>`}`;
|
|
1488
1747
|
}
|
|
1489
1748
|
function leaderboard() {
|
|
1490
1749
|
if (!boards || !boards.state.query) return `<p>${t("unavailable")}</p>`;
|
|
1491
1750
|
const { query, data, loading, error, saving } = boards.state;
|
|
1492
1751
|
const board = manifest.boards[query.board];
|
|
1493
|
-
return `<label>${t("board")}<select data-control="board">${Object.entries(manifest.boards).map(([id, value]) => `<option value="${escape(id)}"${query.board === id ? " selected" : ""}>${escape(value.label
|
|
1752
|
+
return `<label>${t("board")}<select data-control="board">${Object.entries(manifest.boards).map(([id, value]) => `<option value="${escape(id)}"${query.board === id ? " selected" : ""}>${escape(resolveText(value.label, input.language, manifestLanguages(manifest)[0], id))}</option>`).join("")}</select></label>
|
|
1494
1753
|
<div class="split"><label>${t("period")}<select data-control="period">${(board.periods ?? ["all-time"]).map((period) => `<option value="${period}"${query.period === period ? " selected" : ""}>${t(period === "daily" ? "daily" : "allTime")}</option>`).join("")}</select></label><label>${t("category")}<select data-control="category"><option value="accounts"${!query.guests ? " selected" : ""}>${t("accounts")}</option><option value="guests"${query.guests ? " selected" : ""}>${t("guests")}</option></select></label></div>
|
|
1495
1754
|
${query.period === "daily" ? `<small data-board-day>${escape(data?.day ?? query.day ?? new Date(input.bridge.serverTime() ?? Date.now()).toISOString().slice(0, 10))}</small>` : ""}
|
|
1496
1755
|
${saving ? `<p role="status" data-saving>${t(saving)}</p>` : ""}${error ? `<p role="alert">${t("offline")}</p>` : ""}
|
|
@@ -1520,7 +1779,7 @@ function mountOverlay(input) {
|
|
|
1520
1779
|
case "countdown":
|
|
1521
1780
|
return `<p>${t("starting")}</p><div class="countdown" data-countdown></div>`;
|
|
1522
1781
|
case "boot":
|
|
1523
|
-
return
|
|
1782
|
+
return "";
|
|
1524
1783
|
case "error":
|
|
1525
1784
|
return `<p role="alert">${t(model.session?.room?.connection === "replaced" ? "replaced" : "noRoom")}</p>${button("leave", "home")}${button("exit-now", "exit")}`;
|
|
1526
1785
|
case "exit":
|
|
@@ -1543,22 +1802,52 @@ function mountOverlay(input) {
|
|
|
1543
1802
|
function geometry() {
|
|
1544
1803
|
geometryFrame = 0;
|
|
1545
1804
|
if (disposed || !input.bridge.epoch || !model.session) return;
|
|
1546
|
-
const frame = input.frame
|
|
1805
|
+
const frame = gameViewport(input.frame), { scaleX, scaleY } = frame;
|
|
1547
1806
|
const reservedRects = [...root.querySelectorAll("[data-reserve]")].map((el) => {
|
|
1548
1807
|
const rect = el.getBoundingClientRect(), left = Math.max(frame.left, rect.left), top = Math.max(frame.top, rect.top), right = Math.min(frame.right, rect.right), bottom = Math.min(frame.bottom, rect.bottom);
|
|
1549
1808
|
return { x: Math.max(0, Math.round((left - frame.left) * scaleX)), y: Math.max(0, Math.round((top - frame.top) * scaleY)), width: Math.max(0, Math.round((right - left) * scaleX)), height: Math.max(0, Math.round((bottom - top) * scaleY)) };
|
|
1550
1809
|
}).filter((rect) => rect.width && rect.height).slice(0, 8);
|
|
1551
|
-
const view = { inputBlocked: !!visiblePanel(model), reservedRects, shortcutEnabled: model.shortcutEnabled };
|
|
1810
|
+
const view = { inputBlocked: phase(model.session) === "boot" || !!visiblePanel(model), reservedRects, safeArea: measureSafeArea(input.frame, safeProbe), shortcutEnabled: model.shortcutEnabled };
|
|
1552
1811
|
const serialized = `${input.bridge.epoch}:${JSON.stringify(view)}`;
|
|
1553
1812
|
if (lastView === serialized) return;
|
|
1554
1813
|
lastView = serialized;
|
|
1555
|
-
void input.bridge.request("overlay.view", view).catch(() => {
|
|
1814
|
+
void input.bridge.request("overlay.view", view).catch(async (error) => {
|
|
1815
|
+
if (error?.code === "invalid_request" && lastView === serialized) {
|
|
1816
|
+
const { safeArea, ...legacy } = view;
|
|
1817
|
+
try {
|
|
1818
|
+
await input.bridge.request("overlay.view", legacy);
|
|
1819
|
+
return;
|
|
1820
|
+
} catch {
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1556
1823
|
if (lastView === serialized) lastView = "";
|
|
1557
1824
|
});
|
|
1558
1825
|
}
|
|
1559
1826
|
function resize() {
|
|
1560
1827
|
if (!geometryFrame) geometryFrame = win.requestAnimationFrame(geometry);
|
|
1561
1828
|
}
|
|
1829
|
+
function resultBar() {
|
|
1830
|
+
const presentation = matchPresentation(model.session);
|
|
1831
|
+
if (!presentation) return `<strong>${t("ended")}</strong>`;
|
|
1832
|
+
const room2 = model.session.room, { result } = presentation;
|
|
1833
|
+
const unit = result.unit && ["points", "time", "distance"].includes(result.unit) ? t(result.unit) : result.unit;
|
|
1834
|
+
const rows = result.standings.map((p, i) => {
|
|
1835
|
+
const name = room2.players.find((player) => player.id === p.playerId).name;
|
|
1836
|
+
const score = p.score === void 0 ? "" : `<span>${escape(String(p.score))}${unit ? ` ${escape(unit)}` : ""}</span>`;
|
|
1837
|
+
return `<li><span>${p.rank ?? i + 1}. ${escape(name)}</span>${score}</li>`;
|
|
1838
|
+
}).join("");
|
|
1839
|
+
return `<strong data-outcome>${t(presentation.outcome)}</strong><ol class="standings" aria-label="${t("standings")}">${rows}</ol>`;
|
|
1840
|
+
}
|
|
1841
|
+
function rematchBar() {
|
|
1842
|
+
const session = model.session, room2 = session?.room;
|
|
1843
|
+
if (!room2 || room2.status !== "finished" || solo()) return "";
|
|
1844
|
+
const active = room2.players.filter((p) => p.connected && p.role !== "spectator");
|
|
1845
|
+
const ready = active.filter((p) => p.ready), host2 = session.kind === "room" && room2.host === room2.you;
|
|
1846
|
+
const canStart = room2.connection === "connected" && active.length >= room2.limits.min && ready.length === active.length;
|
|
1847
|
+
return `<small role="status" data-rematch-ready>${t("rematchReady", { n: ready.length, max: active.length })}</small>
|
|
1848
|
+
${ready.length ? `<small data-rematch-players>${ready.map((p) => escape(p.name)).join(", ")}</small>` : ""}
|
|
1849
|
+
${room2.rematch?.autoStart ? "" : host2 ? button("restart", "rematchStart", ' class="primary"', !canStart) : `<small>${t("waitHost")}</small>`}`;
|
|
1850
|
+
}
|
|
1562
1851
|
function render() {
|
|
1563
1852
|
if (disposed) return;
|
|
1564
1853
|
const panel = visiblePanel(model), current = phase(model.session), room2 = model.session?.room;
|
|
@@ -1568,9 +1857,9 @@ function mountOverlay(input) {
|
|
|
1568
1857
|
const previousScroll = root.querySelector(".dialog")?.scrollTop ?? 0;
|
|
1569
1858
|
const selection = focused?.tagName === "INPUT" ? { start: focused.selectionStart, end: focused.selectionEnd } : null;
|
|
1570
1859
|
const crewState = input.crew?.getSnapshot(), invitations = (crewState?.invites.length ?? 0) + (crewState?.follow ? 1 : 0);
|
|
1571
|
-
const label = current === "watching" ? t("watching") : room2?.connection === "reconnecting" ? t("reconnecting") : room2?.code ?? "Caisual";
|
|
1572
|
-
surface.innerHTML = `<div class="pill" data-reserve><button type="button" data-action="menu" aria-label="${t("menu")}" aria-expanded="${!!panel}">C<span aria-hidden="true"><small>${escape(label)}</small></span></button>${voiceEligible(manifest, model.session) && model.session?.kind === "room" ? `<button type="button" class="voice-toggle" data-voice-toggle data-action="panel:voice"></button>` : ""}${invitations ? `<button type="button" data-action="panel:friends" aria-label="${t("friends")} (${invitations})">${invitations}</button>` : ""}
|
|
1573
|
-
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}"
|
|
1860
|
+
const label = current === "watching" ? t("watching") : room2?.connection === "reconnecting" ? t("reconnecting") : solo() ? "Caisual" : room2?.code ?? "Caisual";
|
|
1861
|
+
surface.innerHTML = current === "boot" ? "" : `<div class="pill" data-reserve><button type="button" data-action="menu" aria-label="${t("menu")}" aria-expanded="${!!panel}">C<span aria-hidden="true"><small>${escape(label)}</small></span></button>${voiceEligible(manifest, model.session) && model.session?.kind === "room" ? `<button type="button" class="voice-toggle" data-voice-toggle data-action="panel:voice"></button>` : ""}${invitations ? `<button type="button" data-action="panel:friends" aria-label="${t("friends")} (${invitations})">${invitations}</button>` : ""}</div>
|
|
1862
|
+
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}">${resultBar()}${boards?.state.saving ? `<small role="status" data-saving>${t(boards.state.saving)}</small>` : ""}${canPlayAgain(model.session) ? button("again", "again", ' class="primary"') : model.session?.kind === "room" && room2?.status !== "finished" && !solo() ? `<small>${t("waitHost")}</small>` : ""}${rematchBar()}${Object.keys(manifest.boards).length ? button("panel:boards", "boards") : ""}${button("panel:home", "homeMenu")}</div>` : ""}
|
|
1574
1863
|
${panel ? `<div class="backdrop${panel === "home" ? " home" : ""}"><section class="dialog${panel === "boards" || panel === "friends" ? " wide" : ""}" role="dialog" aria-modal="true" aria-labelledby="panel-title" tabindex="-1"><div class="top"><h2 id="panel-title">${title(panel)}</h2><button type="button" data-action="close" aria-label="${t("close")}">\xD7</button></div><div class="stack">${content(panel)}${model.error ? `<p class="error" role="alert" data-error>${t(errorText(model.error))}</p>` : ""}${model.session?.resumeError ? `<p class="error" role="alert">${t("saveFailed")}</p>` : ""}${model.notice ? `<p class="notice" role="status">${escape(model.notice)}</p>` : ""}</div></section></div>` : ""}`;
|
|
1575
1864
|
for (const element of surface.querySelectorAll(".pill,.backdrop,.ended")) element.style.pointerEvents = "auto";
|
|
1576
1865
|
const backdrop = root.querySelector(".backdrop.home");
|
|
@@ -1582,20 +1871,22 @@ function mountOverlay(input) {
|
|
|
1582
1871
|
else if (oldTabIndex === null) input.frame.removeAttribute("tabindex");
|
|
1583
1872
|
else input.frame.setAttribute("tabindex", oldTabIndex);
|
|
1584
1873
|
updateVoice();
|
|
1874
|
+
updateBoot(current === "boot");
|
|
1585
1875
|
const dialog = root.querySelector(".dialog");
|
|
1586
1876
|
if (dialog) dialog.scrollTop = previousScroll;
|
|
1877
|
+
const focusPanel = current === "boot" ? boot : dialog;
|
|
1587
1878
|
const matched = focusKey ? [...root.querySelectorAll(`[data-${focusKey[0]}]`)].find((el) => el.getAttribute(`data-${focusKey[0]}`) === focusKey[1] && el.dataset.peer === focusPeer) : null;
|
|
1588
1879
|
if (!panel && wasModal && !input.frame.inert && input.frame.isConnected) {
|
|
1589
1880
|
input.frame.focus({ preventScroll: true });
|
|
1590
1881
|
input.frame.contentWindow?.focus();
|
|
1591
|
-
} else if (matched && (!panel || matched
|
|
1882
|
+
} else if (matched && (!panel || focusPanel?.contains(matched)) && !matched.hasAttribute("disabled")) {
|
|
1592
1883
|
matched.focus({ preventScroll: true });
|
|
1593
1884
|
if (matched.tagName === "INPUT" && selection?.start !== null && selection?.end !== null && selection) matched.setSelectionRange(selection.start, selection.end);
|
|
1594
|
-
} else if (panel && (!wasModal || focused)) (dialog?.querySelector('select,input,button:not([data-action="close"]):not(:disabled)') ?? dialog)?.focus({ preventScroll: true });
|
|
1885
|
+
} else if (panel && (!wasModal || focused)) (current === "boot" ? boot : dialog?.querySelector('select,input,button:not([data-action="close"]):not(:disabled)') ?? dialog)?.focus({ preventScroll: true });
|
|
1595
1886
|
wasModal = !!panel;
|
|
1596
1887
|
if (lastPhase !== current) {
|
|
1597
1888
|
lastPhase = current;
|
|
1598
|
-
announce(
|
|
1889
|
+
announce(current === "boot" ? "" : t({ home: "home", attaching: "joining", matching: "matching", lobby: "room", countdown: "starting", playing: "playing", ended: "ended", watching: "watching", error: "error" }[current]));
|
|
1599
1890
|
}
|
|
1600
1891
|
updateCountdown();
|
|
1601
1892
|
resize();
|
|
@@ -1639,6 +1930,9 @@ function mountOverlay(input) {
|
|
|
1639
1930
|
case "start":
|
|
1640
1931
|
void perform("room.start", {});
|
|
1641
1932
|
break;
|
|
1933
|
+
case "restart":
|
|
1934
|
+
void perform("room.restart", {});
|
|
1935
|
+
break;
|
|
1642
1936
|
case "copy":
|
|
1643
1937
|
void copyInvite();
|
|
1644
1938
|
break;
|
|
@@ -1654,6 +1948,8 @@ function mountOverlay(input) {
|
|
|
1654
1948
|
case "again": {
|
|
1655
1949
|
if (!canPlayAgain(model.session)) break;
|
|
1656
1950
|
if (model.session?.kind === "local") void perform("local.start", { mode: model.session.mode ?? model.mode });
|
|
1951
|
+
else if (model.session?.room?.status === "finished") void perform("room.restart", {});
|
|
1952
|
+
else if (solo()) void perform("room.create", { mode: model.session?.room?.mode ?? null });
|
|
1657
1953
|
else void perform("room.create", { mode: model.session?.room?.mode ?? null }, async () => {
|
|
1658
1954
|
setPanel("invite");
|
|
1659
1955
|
dispatch({ type: "notice", notice: t("newRoom") });
|
|
@@ -1674,6 +1970,8 @@ function mountOverlay(input) {
|
|
|
1674
1970
|
input.exit();
|
|
1675
1971
|
break;
|
|
1676
1972
|
case "reload":
|
|
1973
|
+
boot?.focus({ preventScroll: true });
|
|
1974
|
+
resetBootWait();
|
|
1677
1975
|
input.frame.src = input.frame.src;
|
|
1678
1976
|
break;
|
|
1679
1977
|
case "refresh":
|
|
@@ -1756,7 +2054,7 @@ function mountOverlay(input) {
|
|
|
1756
2054
|
return;
|
|
1757
2055
|
}
|
|
1758
2056
|
if (panel && event.key === "Tab") {
|
|
1759
|
-
const items = controls().filter((el) => el.closest(".dialog")), first = items[0], last = items.at(-1);
|
|
2057
|
+
const items = controls().filter((el) => el.closest(panel === "boot" ? ".boot" : ".dialog")), first = items[0], last = items.at(-1);
|
|
1760
2058
|
if (!first) {
|
|
1761
2059
|
event.preventDefault();
|
|
1762
2060
|
return;
|
|
@@ -1783,6 +2081,9 @@ function mountOverlay(input) {
|
|
|
1783
2081
|
root.addEventListener("submit", submit);
|
|
1784
2082
|
win.addEventListener("keydown", keydown, true);
|
|
1785
2083
|
win.addEventListener("resize", resize);
|
|
2084
|
+
win.addEventListener("scroll", resize, true);
|
|
2085
|
+
win.visualViewport?.addEventListener("resize", resize);
|
|
2086
|
+
win.visualViewport?.addEventListener("scroll", resize);
|
|
1786
2087
|
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
|
|
1787
2088
|
observer?.observe(input.frame);
|
|
1788
2089
|
const countdownTimer = win.setInterval(updateCountdown, 250);
|
|
@@ -1823,8 +2124,13 @@ function mountOverlay(input) {
|
|
|
1823
2124
|
observer?.disconnect();
|
|
1824
2125
|
win.clearInterval(countdownTimer);
|
|
1825
2126
|
win.cancelAnimationFrame(geometryFrame);
|
|
2127
|
+
win.clearTimeout(bootTimer);
|
|
2128
|
+
win.clearTimeout(bootFadeTimer);
|
|
1826
2129
|
win.removeEventListener("keydown", keydown, true);
|
|
1827
2130
|
win.removeEventListener("resize", resize);
|
|
2131
|
+
win.removeEventListener("scroll", resize, true);
|
|
2132
|
+
win.visualViewport?.removeEventListener("resize", resize);
|
|
2133
|
+
win.visualViewport?.removeEventListener("scroll", resize);
|
|
1828
2134
|
input.frame.inert = oldInert;
|
|
1829
2135
|
if (oldTabIndex === null) input.frame.removeAttribute("tabindex");
|
|
1830
2136
|
else input.frame.setAttribute("tabindex", oldTabIndex);
|
|
@@ -1841,6 +2147,7 @@ export {
|
|
|
1841
2147
|
mountOverlay,
|
|
1842
2148
|
overlayConfiguration,
|
|
1843
2149
|
overlayLanguage,
|
|
2150
|
+
overlayLocale,
|
|
1844
2151
|
styles as overlayStyles,
|
|
1845
2152
|
stanzaDaMessaggio
|
|
1846
2153
|
};
|