@caisual/kit 0.8.0 → 0.10.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 +407 -45
- package/dist/node.js +230 -69
- package/dist/overlay.js +260 -32
- package/dist/runtime.js +179 -39
- package/dist/server.js +2 -0
- package/dist/types/api.d.ts +1 -1
- package/dist/types/contracts/i18n.d.ts +12 -0
- package/dist/types/contracts/index.d.ts +3 -0
- package/dist/types/contracts/manifest.d.ts +10 -5
- package/dist/types/contracts/overlay.d.ts +9 -1
- package/dist/types/contracts/player.d.ts +1 -0
- package/dist/types/contracts/room-limits.d.ts +13 -0
- package/dist/types/handshake.d.ts +4 -0
- package/dist/types/index.d.ts +16 -2
- package/dist/types/kit.d.ts +2 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/overlay/host-bridge.d.ts +16 -0
- package/dist/types/overlay/i18n.d.ts +6 -0
- package/dist/types/overlay/index.d.ts +1 -0
- package/dist/types/overlay/styles.d.ts +1 -1
- package/dist/types/overlay/ui.d.ts +1 -1
- package/dist/types/protocollo.d.ts +5 -0
- package/dist/types/runtime/index.d.ts +2 -1
- package/dist/types/server/index.d.ts +6 -2
- package/dist/types/stanza/nucleo.d.ts +5 -2
- package/dist/types/stanza/tipi.d.ts +2 -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;
|
|
@@ -68,6 +104,7 @@ var CAMPI = /* @__PURE__ */ new Set([
|
|
|
68
104
|
"cover",
|
|
69
105
|
"screenshots",
|
|
70
106
|
"tags",
|
|
107
|
+
"languages",
|
|
71
108
|
"language",
|
|
72
109
|
"platform",
|
|
73
110
|
"orientation",
|
|
@@ -134,12 +171,32 @@ function stringaDefault(dati, campo, valoreDefault, errori) {
|
|
|
134
171
|
}
|
|
135
172
|
function testoFacoltativo(value, key, max, path, errors) {
|
|
136
173
|
if (value[key] === void 0) return void 0;
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
174
|
+
const check = (text2, field2) => {
|
|
175
|
+
if (typeof text2 !== "string" || text2.trim().length === 0 || text2.trim().length > max || /[\r\n\u0000-\u001f]/.test(text2)) {
|
|
176
|
+
errors.push(`${field2}: must contain 1-${max} characters on one line.`);
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
return text2.trim();
|
|
180
|
+
};
|
|
181
|
+
const text = value[key], field = `${path}.${key}`;
|
|
182
|
+
if (typeof text === "string") return check(text, field);
|
|
183
|
+
const translations = oggetto(text);
|
|
184
|
+
if (!translations || Object.keys(translations).length === 0) {
|
|
185
|
+
errors.push(`${field}: must be a string or a non-empty language-to-text object.`);
|
|
140
186
|
return void 0;
|
|
141
187
|
}
|
|
142
|
-
|
|
188
|
+
const result = {};
|
|
189
|
+
for (const [raw, text2] of Object.entries(translations)) {
|
|
190
|
+
const tag = normalizeLanguage(raw);
|
|
191
|
+
if (!tag) {
|
|
192
|
+
errors.push(`${field}.${raw}: must be a BCP 47 language tag.`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (Object.hasOwn(result, tag)) errors.push(`${field}.${raw}: duplicate language.`);
|
|
196
|
+
const checked = check(text2, `${field}.${raw}`);
|
|
197
|
+
if (checked !== void 0) result[tag] = checked;
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
143
200
|
}
|
|
144
201
|
function validaManifest(valore) {
|
|
145
202
|
const errori = [];
|
|
@@ -194,10 +251,24 @@ function validaManifest(valore) {
|
|
|
194
251
|
}
|
|
195
252
|
}
|
|
196
253
|
}
|
|
197
|
-
const
|
|
198
|
-
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(
|
|
254
|
+
const legacyLanguage = stringaDefault(dati, "language", "en", errori);
|
|
255
|
+
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(legacyLanguage)) {
|
|
199
256
|
errori.push("language: must be a BCP 47 language tag such as en, it, or pt-BR.");
|
|
200
257
|
}
|
|
258
|
+
const languages2 = [];
|
|
259
|
+
if (dati.languages === void 0) languages2.push(normalizeLanguage(legacyLanguage) ?? legacyLanguage);
|
|
260
|
+
else if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
261
|
+
errori.push("languages: must be a non-empty array of BCP 47 language tags.");
|
|
262
|
+
} else for (const [index, raw] of dati.languages.entries()) {
|
|
263
|
+
const tag = normalizeLanguage(raw);
|
|
264
|
+
if (!tag) errori.push(`languages[${index}]: must be a BCP 47 language tag.`);
|
|
265
|
+
else if (languages2.includes(tag)) errori.push(`languages[${index}]: duplicate language ${tag}.`);
|
|
266
|
+
else languages2.push(tag);
|
|
267
|
+
}
|
|
268
|
+
const language = languages2[0] ?? legacyLanguage;
|
|
269
|
+
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
270
|
+
errori.push("language: must match the first entry in languages when both are present.");
|
|
271
|
+
}
|
|
201
272
|
let platform = "both";
|
|
202
273
|
if (dati.platform === void 0) errori.push("platform: is required.");
|
|
203
274
|
else if (typeof dati.platform !== "string" || !PLATFORM.has(dati.platform)) {
|
|
@@ -563,6 +634,7 @@ function validaManifest(valore) {
|
|
|
563
634
|
cover,
|
|
564
635
|
screenshots,
|
|
565
636
|
tags,
|
|
637
|
+
languages: languages2,
|
|
566
638
|
language,
|
|
567
639
|
platform,
|
|
568
640
|
orientation,
|
|
@@ -593,9 +665,13 @@ function overlayConfiguration(manifest, coverUrl = null, invite = null) {
|
|
|
593
665
|
function record(value) {
|
|
594
666
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
595
667
|
}
|
|
668
|
+
function validSafeArea(value) {
|
|
669
|
+
const area = record(value);
|
|
670
|
+
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);
|
|
671
|
+
}
|
|
596
672
|
function validOverlayView(value) {
|
|
597
673
|
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) => {
|
|
674
|
+
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
675
|
const rect = record(value2);
|
|
600
676
|
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
677
|
});
|
|
@@ -626,6 +702,7 @@ function validOverlayRequest(value) {
|
|
|
626
702
|
return keys("role") && text("role");
|
|
627
703
|
case "room.team":
|
|
628
704
|
return keys("team") && Number.isInteger(args.team) && args.team >= 1 && args.team <= 24;
|
|
705
|
+
case "room.restart":
|
|
629
706
|
case "room.start":
|
|
630
707
|
case "session.cancel":
|
|
631
708
|
case "session.leave":
|
|
@@ -665,7 +742,7 @@ function validOverlaySessionState(value) {
|
|
|
665
742
|
if (data.room === null) return true;
|
|
666
743
|
if (!exact(room, ["code", "mode", "status", "host", "you", "players", "countdownAt", "connection", "closedCode", "limits", "lobby", "persistent", "delayMs", "requestRole"]) || !room) return false;
|
|
667
744
|
const limits = record(room.limits);
|
|
668
|
-
return text(room.code) && nullable(room.mode) && nullable(room.host) && nullable(room.you) && ["lobby", "countdown", "playing", "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) => {
|
|
745
|
+
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
746
|
const player = record(value2);
|
|
670
747
|
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
748
|
});
|
|
@@ -817,6 +894,10 @@ function creaPonteOspite(input) {
|
|
|
817
894
|
ticket: input.ticket,
|
|
818
895
|
live: input.origineLive,
|
|
819
896
|
invite: input.invite,
|
|
897
|
+
// language resta disponibile ai kit pubblicati prima della separazione delle lingue.
|
|
898
|
+
...input.language ? { language: input.language, uiLanguage: input.language } : {},
|
|
899
|
+
...input.languagePreferences ? { languagePreferences: input.languagePreferences } : {},
|
|
900
|
+
...input.configuration ? { gameLanguages: manifestLanguages(input.configuration.manifest) } : {},
|
|
820
901
|
...input.configuration && data.overlayVersion === 1 ? { overlay: { v: 1, epoch, configuration: input.configuration } } : {}
|
|
821
902
|
}, input.origineGioco, [channel.port2]);
|
|
822
903
|
};
|
|
@@ -874,7 +955,7 @@ function creaPonteOspite(input) {
|
|
|
874
955
|
requestId: id,
|
|
875
956
|
op,
|
|
876
957
|
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 } : {}
|
|
958
|
+
...["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
959
|
};
|
|
879
960
|
if (!validOverlayRequest(request)) return Promise.reject(creaErrore("invalid_request", "The overlay request is invalid."));
|
|
880
961
|
return new Promise((resolve, reject) => {
|
|
@@ -913,6 +994,30 @@ function avviaHandshake(input) {
|
|
|
913
994
|
const bridge = creaPonteOspite(input);
|
|
914
995
|
return () => bridge.dispose();
|
|
915
996
|
}
|
|
997
|
+
function gameViewport(frame) {
|
|
998
|
+
const rect = frame.getBoundingClientRect();
|
|
999
|
+
const zoomX = frame.offsetWidth ? rect.width / frame.offsetWidth : 1;
|
|
1000
|
+
const zoomY = frame.offsetHeight ? rect.height / frame.offsetHeight : 1;
|
|
1001
|
+
const left = rect.left + frame.clientLeft * zoomX, top = rect.top + frame.clientTop * zoomY;
|
|
1002
|
+
return {
|
|
1003
|
+
left,
|
|
1004
|
+
top,
|
|
1005
|
+
right: left + frame.clientWidth * zoomX,
|
|
1006
|
+
bottom: top + frame.clientHeight * zoomY,
|
|
1007
|
+
scaleX: zoomX ? 1 / zoomX : 1,
|
|
1008
|
+
scaleY: zoomY ? 1 / zoomY : 1
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function measureSafeArea(frame, probe) {
|
|
1012
|
+
const win = frame.ownerDocument.defaultView, css = win.getComputedStyle(probe), viewport = gameViewport(frame);
|
|
1013
|
+
const clamp = (value, max) => Math.max(0, Math.min(max, value));
|
|
1014
|
+
return {
|
|
1015
|
+
top: clamp(((parseFloat(css.paddingTop) || 0) - viewport.top) * viewport.scaleY, frame.clientHeight),
|
|
1016
|
+
right: clamp((viewport.right - (win.innerWidth - (parseFloat(css.paddingRight) || 0))) * viewport.scaleX, frame.clientWidth),
|
|
1017
|
+
bottom: clamp((viewport.bottom - (win.innerHeight - (parseFloat(css.paddingBottom) || 0))) * viewport.scaleY, frame.clientHeight),
|
|
1018
|
+
left: clamp(((parseFloat(css.paddingLeft) || 0) - viewport.left) * viewport.scaleX, frame.clientWidth)
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
916
1021
|
|
|
917
1022
|
// src/overlay/boards.ts
|
|
918
1023
|
function createBoardController(input) {
|
|
@@ -1011,8 +1116,11 @@ function createBoardController(input) {
|
|
|
1011
1116
|
// src/overlay/i18n.ts
|
|
1012
1117
|
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
1013
1118
|
var words = {
|
|
1119
|
+
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
1014
1120
|
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
1121
|
+
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
1122
|
home: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
1123
|
+
homeMenu: ["Menu", "Menu", "Men\xFA", "Menu", "Men\xFC", "Menu"],
|
|
1016
1124
|
mode: ["Mode", "Modalit\xE0", "Modo", "Mode", "Modus", "Modo"],
|
|
1017
1125
|
play: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
1018
1126
|
friendsPlay: ["Play with friends", "Gioca con amici", "Jugar con amigos", "Jouer entre amis", "Mit Freunden spielen", "Jogar com amigos"],
|
|
@@ -1048,6 +1156,8 @@ var words = {
|
|
|
1048
1156
|
starting: ["Starting in", "Si inizia tra", "Empieza en", "D\xE9but dans", "Start in", "Come\xE7a em"],
|
|
1049
1157
|
playing: ["Playing", "In partita", "Jugando", "En jeu", "Im Spiel", "Jogando"],
|
|
1050
1158
|
ended: ["Game finished", "Partita conclusa", "Partida terminada", "Partie termin\xE9e", "Spiel beendet", "Partida encerrada"],
|
|
1159
|
+
rematchReady: ["{n}/{max} ready", "{n}/{max} pronti", "{n}/{max} listos", "{n}/{max} pr\xEAts", "{n}/{max} bereit", "{n}/{max} prontos"],
|
|
1160
|
+
rematchStart: ["Start rematch", "Avvia rivincita", "Iniciar revancha", "Lancer la revanche", "Revanche starten", "Iniciar revanche"],
|
|
1051
1161
|
again: ["Play again", "Gioca ancora", "Jugar de nuevo", "Rejouer", "Erneut spielen", "Jogar novamente"],
|
|
1052
1162
|
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
1163
|
watching: ["Watching", "In osservazione", "Observando", "Spectateur", "Zuschauen", "Assistindo"],
|
|
@@ -1129,6 +1239,10 @@ function overlayLanguage(raw) {
|
|
|
1129
1239
|
const value = raw?.toLowerCase().split("-")[0];
|
|
1130
1240
|
return languages.includes(value) ? value : "en";
|
|
1131
1241
|
}
|
|
1242
|
+
function overlayLocale(raw) {
|
|
1243
|
+
const tag = normalizeLanguage(raw);
|
|
1244
|
+
return tag && languages.includes(tag.split("-")[0]) ? tag : "en";
|
|
1245
|
+
}
|
|
1132
1246
|
function translator(language) {
|
|
1133
1247
|
const dictionary = dictionaries[overlayLanguage(language)];
|
|
1134
1248
|
return (key, values = {}) => dictionary[key].replace(/\{(\w+)\}/g, (_all, name) => String(values[name] ?? ""));
|
|
@@ -1157,7 +1271,7 @@ function phase(session) {
|
|
|
1157
1271
|
if (session.kind === "attaching" || session.kind === "matching") return session.kind;
|
|
1158
1272
|
if (session.room && ["closed", "replaced"].includes(session.room.connection)) return "error";
|
|
1159
1273
|
if (session.kind === "local") return session.localStatus === "ended" ? "ended" : "playing";
|
|
1160
|
-
if (session.room?.status === "ended") return "ended";
|
|
1274
|
+
if (session.room?.status === "ended" || session.room?.status === "finished") return "ended";
|
|
1161
1275
|
if (session.kind === "watch") return "watching";
|
|
1162
1276
|
if (session.kind === "room" && session.room) return session.room.status;
|
|
1163
1277
|
return "home";
|
|
@@ -1171,7 +1285,7 @@ function reduceUi(model, action) {
|
|
|
1171
1285
|
const next = action.session, changed = next?.id !== model.session?.id || next === null;
|
|
1172
1286
|
const pending = next?.kind === "attaching" || next?.kind === "matching";
|
|
1173
1287
|
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);
|
|
1288
|
+
const automatic = transition && ["lobby", "countdown", "playing", "ended"].includes(nextPhase) && [null, "auto", "room", "invite", "home"].includes(model.panel);
|
|
1175
1289
|
return {
|
|
1176
1290
|
...model,
|
|
1177
1291
|
session: next,
|
|
@@ -1222,6 +1336,7 @@ function startReason(manifest, session) {
|
|
|
1222
1336
|
function canPlayAgain(session) {
|
|
1223
1337
|
if (phase(session) !== "ended") return false;
|
|
1224
1338
|
if (session?.kind === "local") return true;
|
|
1339
|
+
if (session?.room?.status === "finished") return session.kind === "room" && session.room.connection === "connected" && session.room.players.some((p) => p.id === session.room.you && p.connected && p.role !== "spectator" && !p.ready);
|
|
1225
1340
|
return session?.kind === "room" && (!session.room?.lobby || session.room.host === session.room.you);
|
|
1226
1341
|
}
|
|
1227
1342
|
function normalizeInvite(code) {
|
|
@@ -1231,11 +1346,19 @@ function normalizeInvite(code) {
|
|
|
1231
1346
|
|
|
1232
1347
|
// src/overlay/styles.ts
|
|
1233
1348
|
var styles = `
|
|
1349
|
+
.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
1350
|
: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
|
|
1351
|
+
[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:cover;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}.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
1352
|
[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)}
|
|
1353
|
+
.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}
|
|
1354
|
+
.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)}
|
|
1355
|
+
.boot-cover{position:fixed;inset:0;z-index:-2;width:100%;height:100%;object-fit:cover;filter:blur(20px);transform:scale(1.08);opacity:.65;pointer-events:none}
|
|
1356
|
+
.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}
|
|
1357
|
+
.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}
|
|
1358
|
+
.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}
|
|
1359
|
+
@keyframes boot-progress{0%{transform:translateX(-110%)}100%{transform:translateX(340%)}}
|
|
1237
1360
|
@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}.ended strong{font-size:13px}.ended button{padding:8px 10px;font-size:13px}.roster{max-height:28dvh}}
|
|
1238
|
-
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}}
|
|
1361
|
+
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}.boot{transition:none}.boot-progress span{animation:none;transform:translateX(65%)}}
|
|
1239
1362
|
`;
|
|
1240
1363
|
|
|
1241
1364
|
// src/overlay/voice-panel.ts
|
|
@@ -1331,7 +1454,10 @@ function mountOverlay(input) {
|
|
|
1331
1454
|
elements.dataset.layout = "";
|
|
1332
1455
|
elements.style.pointerEvents = "none";
|
|
1333
1456
|
elements.innerHTML = `<div data-surface></div><div class="sr" role="status" aria-live="polite" data-live></div>`;
|
|
1334
|
-
|
|
1457
|
+
const safeProbe = document.createElement("div");
|
|
1458
|
+
safeProbe.className = "safe-area-probe";
|
|
1459
|
+
safeProbe.setAttribute("aria-hidden", "true");
|
|
1460
|
+
root.append(elements, safeProbe);
|
|
1335
1461
|
const surface = root.querySelector("[data-surface]"), live = root.querySelector("[data-live]");
|
|
1336
1462
|
surface.style.pointerEvents = "none";
|
|
1337
1463
|
live.style.pointerEvents = "none";
|
|
@@ -1340,9 +1466,11 @@ function mountOverlay(input) {
|
|
|
1340
1466
|
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
1467
|
const luminance = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722;
|
|
1342
1468
|
host.style.setProperty("--accent-ink", luminance > 0.179 ? "#000000" : "#ffffff");
|
|
1469
|
+
host.style.setProperty("--boot-accent", luminance > 0.179 ? accent : `color-mix(in srgb, ${accent}, #ffffff 70%)`);
|
|
1343
1470
|
input.container.append(host);
|
|
1344
1471
|
let model = initialUi(manifest), disposed = false, operation = 0, lastView = "", geometryFrame = 0;
|
|
1345
1472
|
let lastPhase = "", wasModal = false, copyFallback = null;
|
|
1473
|
+
let boot = null, bootTimer = 0, bootFadeTimer = 0;
|
|
1346
1474
|
let voiceError = null, voicePending = null, voiceOperation = 0;
|
|
1347
1475
|
let codeDraft = input.configuration.invite ?? "";
|
|
1348
1476
|
const oldInert = Boolean(input.frame.inert), oldTabIndex = input.frame.getAttribute("tabindex");
|
|
@@ -1355,6 +1483,70 @@ function mountOverlay(input) {
|
|
|
1355
1483
|
const selectedMode = () => manifest.modes.find((mode) => mode.id === model.mode);
|
|
1356
1484
|
const disabled = () => model.busy ? " disabled" : "";
|
|
1357
1485
|
const button = (action, key, extra = "", off = false) => `<button type="button" data-action="${action}"${extra}${off || model.busy ? " disabled" : ""}>${t(key)}</button>`;
|
|
1486
|
+
function resetBootWait() {
|
|
1487
|
+
win.clearTimeout(bootTimer);
|
|
1488
|
+
if (!boot || phase(model.session) !== "boot") return;
|
|
1489
|
+
boot.querySelector("[data-boot-message]").textContent = t("loading");
|
|
1490
|
+
boot.querySelector("[data-boot-recovery]").hidden = true;
|
|
1491
|
+
bootTimer = win.setTimeout(() => {
|
|
1492
|
+
bootTimer = 0;
|
|
1493
|
+
if (disposed || !boot) return;
|
|
1494
|
+
boot.querySelector("[data-boot-message]").textContent = t("loadingSlow");
|
|
1495
|
+
boot.querySelector("[data-boot-recovery]").hidden = false;
|
|
1496
|
+
}, 9e3);
|
|
1497
|
+
}
|
|
1498
|
+
function updateBoot(loading) {
|
|
1499
|
+
if (loading) {
|
|
1500
|
+
if (boot) {
|
|
1501
|
+
win.clearTimeout(bootFadeTimer);
|
|
1502
|
+
bootFadeTimer = 0;
|
|
1503
|
+
boot.inert = false;
|
|
1504
|
+
boot.removeAttribute("aria-hidden");
|
|
1505
|
+
boot.style.pointerEvents = "auto";
|
|
1506
|
+
boot.classList.remove("boot-leaving");
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
boot = document.createElement("section");
|
|
1510
|
+
boot.className = "boot";
|
|
1511
|
+
boot.tabIndex = -1;
|
|
1512
|
+
boot.setAttribute("aria-labelledby", "boot-title");
|
|
1513
|
+
boot.setAttribute("aria-describedby", "boot-status");
|
|
1514
|
+
boot.style.pointerEvents = "auto";
|
|
1515
|
+
boot.innerHTML = `<div class="boot-brand" aria-hidden="true"><span>C</span>Caisual</div>
|
|
1516
|
+
<div class="boot-content"><h1 id="boot-title">${escape(manifest.name)}</h1>
|
|
1517
|
+
<div class="boot-progress" aria-hidden="true"><span></span></div>
|
|
1518
|
+
<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>
|
|
1519
|
+
<div class="boot-recovery"><div class="row" data-boot-recovery hidden>${button("reload", "retry", ' class="primary"')}${button("exit-now", "exit", ' class="quiet"')}</div></div>
|
|
1520
|
+
</div>`;
|
|
1521
|
+
if (input.configuration.coverUrl) {
|
|
1522
|
+
const cover = document.createElement("img");
|
|
1523
|
+
cover.className = "boot-cover";
|
|
1524
|
+
cover.alt = "";
|
|
1525
|
+
cover.setAttribute("aria-hidden", "true");
|
|
1526
|
+
cover.addEventListener("error", () => {
|
|
1527
|
+
cover.hidden = true;
|
|
1528
|
+
}, { once: true });
|
|
1529
|
+
cover.src = input.configuration.coverUrl;
|
|
1530
|
+
boot.prepend(cover);
|
|
1531
|
+
}
|
|
1532
|
+
elements.append(boot);
|
|
1533
|
+
resetBootWait();
|
|
1534
|
+
} else if (boot && !boot.inert) {
|
|
1535
|
+
boot.inert = true;
|
|
1536
|
+
boot.setAttribute("aria-hidden", "true");
|
|
1537
|
+
boot.style.pointerEvents = "none";
|
|
1538
|
+
boot.classList.add("boot-leaving");
|
|
1539
|
+
const remove = () => {
|
|
1540
|
+
win.clearTimeout(bootTimer);
|
|
1541
|
+
bootTimer = 0;
|
|
1542
|
+
boot?.remove();
|
|
1543
|
+
boot = null;
|
|
1544
|
+
bootFadeTimer = 0;
|
|
1545
|
+
};
|
|
1546
|
+
if (win.matchMedia?.("(prefers-reduced-motion: reduce)").matches) remove();
|
|
1547
|
+
else bootFadeTimer = win.setTimeout(remove, 420);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1358
1550
|
const dispatch = (action) => {
|
|
1359
1551
|
if (disposed) return;
|
|
1360
1552
|
model = reduceUi(model, action);
|
|
@@ -1375,6 +1567,7 @@ function mountOverlay(input) {
|
|
|
1375
1567
|
};
|
|
1376
1568
|
const close = () => {
|
|
1377
1569
|
const current = phase(model.session), panel = visiblePanel(model);
|
|
1570
|
+
if (current === "boot") return;
|
|
1378
1571
|
if (current === "home") setPanel("home");
|
|
1379
1572
|
else if (current === "lobby" && panel !== "room") setPanel("room");
|
|
1380
1573
|
else setPanel(null);
|
|
@@ -1454,8 +1647,8 @@ function mountOverlay(input) {
|
|
|
1454
1647
|
function home() {
|
|
1455
1648
|
const selected = selectedMode(), action = primaryAction(manifest, model.mode), session = model.session;
|
|
1456
1649
|
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>` : ""}
|
|
1650
|
+
return `<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>
|
|
1651
|
+
${selected?.instructions ? `<p class="muted">${escape(resolveText(selected.instructions, input.language, manifestLanguages(manifest)[0]))}</p>` : ""}
|
|
1459
1652
|
${input.configuration.invite && phase(session) === "home" ? button("join-invite", "joinInvite", ' class="primary"', !session?.ready) : ""}
|
|
1460
1653
|
${action ? button("play", action.friends ? "friendsPlay" : "play", ' class="primary"', !session?.ready) : ""}
|
|
1461
1654
|
${selected?.matchmaking ? button("match", "find", "", !selected.matchmaking.defaults || !session?.ready) : ""}
|
|
@@ -1469,8 +1662,8 @@ function mountOverlay(input) {
|
|
|
1469
1662
|
const own = room2.players.find((player) => player.id === room2.you), lobby = room2.status === "lobby" && session?.kind === "room";
|
|
1470
1663
|
const canRole = session?.kind === "room" && (lobby || room2.status === "playing" && room2.requestRole);
|
|
1471
1664
|
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
|
|
1665
|
+
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>
|
|
1666
|
+
${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
1667
|
${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
1668
|
${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
1669
|
${session?.kind === "watch" ? `<p>${t("watching")} \xB7 ${t("delay", { n: (room2.delayMs ?? 0) / 1e3 })}</p>` : ""}
|
|
@@ -1490,7 +1683,7 @@ function mountOverlay(input) {
|
|
|
1490
1683
|
if (!boards || !boards.state.query) return `<p>${t("unavailable")}</p>`;
|
|
1491
1684
|
const { query, data, loading, error, saving } = boards.state;
|
|
1492
1685
|
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
|
|
1686
|
+
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
1687
|
<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
1688
|
${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
1689
|
${saving ? `<p role="status" data-saving>${t(saving)}</p>` : ""}${error ? `<p role="alert">${t("offline")}</p>` : ""}
|
|
@@ -1520,7 +1713,7 @@ function mountOverlay(input) {
|
|
|
1520
1713
|
case "countdown":
|
|
1521
1714
|
return `<p>${t("starting")}</p><div class="countdown" data-countdown></div>`;
|
|
1522
1715
|
case "boot":
|
|
1523
|
-
return
|
|
1716
|
+
return "";
|
|
1524
1717
|
case "error":
|
|
1525
1718
|
return `<p role="alert">${t(model.session?.room?.connection === "replaced" ? "replaced" : "noRoom")}</p>${button("leave", "home")}${button("exit-now", "exit")}`;
|
|
1526
1719
|
case "exit":
|
|
@@ -1543,22 +1736,40 @@ function mountOverlay(input) {
|
|
|
1543
1736
|
function geometry() {
|
|
1544
1737
|
geometryFrame = 0;
|
|
1545
1738
|
if (disposed || !input.bridge.epoch || !model.session) return;
|
|
1546
|
-
const frame = input.frame
|
|
1739
|
+
const frame = gameViewport(input.frame), { scaleX, scaleY } = frame;
|
|
1547
1740
|
const reservedRects = [...root.querySelectorAll("[data-reserve]")].map((el) => {
|
|
1548
1741
|
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
1742
|
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
1743
|
}).filter((rect) => rect.width && rect.height).slice(0, 8);
|
|
1551
|
-
const view = { inputBlocked: !!visiblePanel(model), reservedRects, shortcutEnabled: model.shortcutEnabled };
|
|
1744
|
+
const view = { inputBlocked: phase(model.session) === "boot" || !!visiblePanel(model), reservedRects, safeArea: measureSafeArea(input.frame, safeProbe), shortcutEnabled: model.shortcutEnabled };
|
|
1552
1745
|
const serialized = `${input.bridge.epoch}:${JSON.stringify(view)}`;
|
|
1553
1746
|
if (lastView === serialized) return;
|
|
1554
1747
|
lastView = serialized;
|
|
1555
|
-
void input.bridge.request("overlay.view", view).catch(() => {
|
|
1748
|
+
void input.bridge.request("overlay.view", view).catch(async (error) => {
|
|
1749
|
+
if (error?.code === "invalid_request" && lastView === serialized) {
|
|
1750
|
+
const { safeArea, ...legacy } = view;
|
|
1751
|
+
try {
|
|
1752
|
+
await input.bridge.request("overlay.view", legacy);
|
|
1753
|
+
return;
|
|
1754
|
+
} catch {
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1556
1757
|
if (lastView === serialized) lastView = "";
|
|
1557
1758
|
});
|
|
1558
1759
|
}
|
|
1559
1760
|
function resize() {
|
|
1560
1761
|
if (!geometryFrame) geometryFrame = win.requestAnimationFrame(geometry);
|
|
1561
1762
|
}
|
|
1763
|
+
function rematchBar() {
|
|
1764
|
+
const session = model.session, room2 = session?.room;
|
|
1765
|
+
if (!room2 || room2.status !== "finished") return "";
|
|
1766
|
+
const active = room2.players.filter((p) => p.connected && p.role !== "spectator");
|
|
1767
|
+
const ready = active.filter((p) => p.ready), host2 = session.kind === "room" && room2.host === room2.you;
|
|
1768
|
+
const canStart = room2.connection === "connected" && active.length >= room2.limits.min && ready.length === active.length;
|
|
1769
|
+
return `<small role="status" data-rematch-ready>${t("rematchReady", { n: ready.length, max: active.length })}</small>
|
|
1770
|
+
${ready.length ? `<small data-rematch-players>${ready.map((p) => escape(p.name)).join(", ")}</small>` : ""}
|
|
1771
|
+
${host2 ? button("restart", "rematchStart", ' class="primary"', !canStart) : `<small>${t("waitHost")}</small>`}`;
|
|
1772
|
+
}
|
|
1562
1773
|
function render() {
|
|
1563
1774
|
if (disposed) return;
|
|
1564
1775
|
const panel = visiblePanel(model), current = phase(model.session), room2 = model.session?.room;
|
|
@@ -1569,8 +1780,8 @@ function mountOverlay(input) {
|
|
|
1569
1780
|
const selection = focused?.tagName === "INPUT" ? { start: focused.selectionStart, end: focused.selectionEnd } : null;
|
|
1570
1781
|
const crewState = input.crew?.getSnapshot(), invitations = (crewState?.invites.length ?? 0) + (crewState?.follow ? 1 : 0);
|
|
1571
1782
|
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")}"><strong>${t("ended")}</strong>${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" ? `<small>${t("waitHost")}</small>` : ""}${Object.keys(manifest.boards).length ? button("panel:boards", "boards") : ""}${button("panel:home", "
|
|
1783
|
+
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>
|
|
1784
|
+
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}"><strong>${t("ended")}</strong>${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" ? `<small>${t("waitHost")}</small>` : ""}${rematchBar()}${Object.keys(manifest.boards).length ? button("panel:boards", "boards") : ""}${button("panel:home", "homeMenu")}</div>` : ""}
|
|
1574
1785
|
${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
1786
|
for (const element of surface.querySelectorAll(".pill,.backdrop,.ended")) element.style.pointerEvents = "auto";
|
|
1576
1787
|
const backdrop = root.querySelector(".backdrop.home");
|
|
@@ -1582,20 +1793,22 @@ function mountOverlay(input) {
|
|
|
1582
1793
|
else if (oldTabIndex === null) input.frame.removeAttribute("tabindex");
|
|
1583
1794
|
else input.frame.setAttribute("tabindex", oldTabIndex);
|
|
1584
1795
|
updateVoice();
|
|
1796
|
+
updateBoot(current === "boot");
|
|
1585
1797
|
const dialog = root.querySelector(".dialog");
|
|
1586
1798
|
if (dialog) dialog.scrollTop = previousScroll;
|
|
1799
|
+
const focusPanel = current === "boot" ? boot : dialog;
|
|
1587
1800
|
const matched = focusKey ? [...root.querySelectorAll(`[data-${focusKey[0]}]`)].find((el) => el.getAttribute(`data-${focusKey[0]}`) === focusKey[1] && el.dataset.peer === focusPeer) : null;
|
|
1588
1801
|
if (!panel && wasModal && !input.frame.inert && input.frame.isConnected) {
|
|
1589
1802
|
input.frame.focus({ preventScroll: true });
|
|
1590
1803
|
input.frame.contentWindow?.focus();
|
|
1591
|
-
} else if (matched && (!panel || matched
|
|
1804
|
+
} else if (matched && (!panel || focusPanel?.contains(matched)) && !matched.hasAttribute("disabled")) {
|
|
1592
1805
|
matched.focus({ preventScroll: true });
|
|
1593
1806
|
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 });
|
|
1807
|
+
} else if (panel && (!wasModal || focused)) (current === "boot" ? boot : dialog?.querySelector('select,input,button:not([data-action="close"]):not(:disabled)') ?? dialog)?.focus({ preventScroll: true });
|
|
1595
1808
|
wasModal = !!panel;
|
|
1596
1809
|
if (lastPhase !== current) {
|
|
1597
1810
|
lastPhase = current;
|
|
1598
|
-
announce(
|
|
1811
|
+
announce(current === "boot" ? "" : t({ home: "home", attaching: "joining", matching: "matching", lobby: "room", countdown: "starting", playing: "playing", ended: "ended", watching: "watching", error: "error" }[current]));
|
|
1599
1812
|
}
|
|
1600
1813
|
updateCountdown();
|
|
1601
1814
|
resize();
|
|
@@ -1639,6 +1852,9 @@ function mountOverlay(input) {
|
|
|
1639
1852
|
case "start":
|
|
1640
1853
|
void perform("room.start", {});
|
|
1641
1854
|
break;
|
|
1855
|
+
case "restart":
|
|
1856
|
+
void perform("room.restart", {});
|
|
1857
|
+
break;
|
|
1642
1858
|
case "copy":
|
|
1643
1859
|
void copyInvite();
|
|
1644
1860
|
break;
|
|
@@ -1654,6 +1870,7 @@ function mountOverlay(input) {
|
|
|
1654
1870
|
case "again": {
|
|
1655
1871
|
if (!canPlayAgain(model.session)) break;
|
|
1656
1872
|
if (model.session?.kind === "local") void perform("local.start", { mode: model.session.mode ?? model.mode });
|
|
1873
|
+
else if (model.session?.room?.status === "finished") void perform("room.restart", {});
|
|
1657
1874
|
else void perform("room.create", { mode: model.session?.room?.mode ?? null }, async () => {
|
|
1658
1875
|
setPanel("invite");
|
|
1659
1876
|
dispatch({ type: "notice", notice: t("newRoom") });
|
|
@@ -1674,6 +1891,8 @@ function mountOverlay(input) {
|
|
|
1674
1891
|
input.exit();
|
|
1675
1892
|
break;
|
|
1676
1893
|
case "reload":
|
|
1894
|
+
boot?.focus({ preventScroll: true });
|
|
1895
|
+
resetBootWait();
|
|
1677
1896
|
input.frame.src = input.frame.src;
|
|
1678
1897
|
break;
|
|
1679
1898
|
case "refresh":
|
|
@@ -1756,7 +1975,7 @@ function mountOverlay(input) {
|
|
|
1756
1975
|
return;
|
|
1757
1976
|
}
|
|
1758
1977
|
if (panel && event.key === "Tab") {
|
|
1759
|
-
const items = controls().filter((el) => el.closest(".dialog")), first = items[0], last = items.at(-1);
|
|
1978
|
+
const items = controls().filter((el) => el.closest(panel === "boot" ? ".boot" : ".dialog")), first = items[0], last = items.at(-1);
|
|
1760
1979
|
if (!first) {
|
|
1761
1980
|
event.preventDefault();
|
|
1762
1981
|
return;
|
|
@@ -1783,6 +2002,9 @@ function mountOverlay(input) {
|
|
|
1783
2002
|
root.addEventListener("submit", submit);
|
|
1784
2003
|
win.addEventListener("keydown", keydown, true);
|
|
1785
2004
|
win.addEventListener("resize", resize);
|
|
2005
|
+
win.addEventListener("scroll", resize, true);
|
|
2006
|
+
win.visualViewport?.addEventListener("resize", resize);
|
|
2007
|
+
win.visualViewport?.addEventListener("scroll", resize);
|
|
1786
2008
|
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
|
|
1787
2009
|
observer?.observe(input.frame);
|
|
1788
2010
|
const countdownTimer = win.setInterval(updateCountdown, 250);
|
|
@@ -1823,8 +2045,13 @@ function mountOverlay(input) {
|
|
|
1823
2045
|
observer?.disconnect();
|
|
1824
2046
|
win.clearInterval(countdownTimer);
|
|
1825
2047
|
win.cancelAnimationFrame(geometryFrame);
|
|
2048
|
+
win.clearTimeout(bootTimer);
|
|
2049
|
+
win.clearTimeout(bootFadeTimer);
|
|
1826
2050
|
win.removeEventListener("keydown", keydown, true);
|
|
1827
2051
|
win.removeEventListener("resize", resize);
|
|
2052
|
+
win.removeEventListener("scroll", resize, true);
|
|
2053
|
+
win.visualViewport?.removeEventListener("resize", resize);
|
|
2054
|
+
win.visualViewport?.removeEventListener("scroll", resize);
|
|
1828
2055
|
input.frame.inert = oldInert;
|
|
1829
2056
|
if (oldTabIndex === null) input.frame.removeAttribute("tabindex");
|
|
1830
2057
|
else input.frame.setAttribute("tabindex", oldTabIndex);
|
|
@@ -1841,6 +2068,7 @@ export {
|
|
|
1841
2068
|
mountOverlay,
|
|
1842
2069
|
overlayConfiguration,
|
|
1843
2070
|
overlayLanguage,
|
|
2071
|
+
overlayLocale,
|
|
1844
2072
|
styles as overlayStyles,
|
|
1845
2073
|
stanzaDaMessaggio
|
|
1846
2074
|
};
|