Add the Sokko TCG collectible card mini-game

Add the server-backed card game: Discord login, recharging pack openings,
album, trades, gifts, stardust shop, campaign codes and its administration,
stored in SQLite and disabled in production until configured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-05 17:47:35 +01:00
parent 243465720f
commit 5ce35cd7ba
193 changed files with 12159 additions and 28 deletions

View file

@ -1,5 +1,6 @@
// Rôle : fournit un dropdown compact réutilisable pour menus d'icônes, couleurs et actions rapides.
import { useEffect, useRef, useState } from "react";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import { placeDropdownMenu } from "./dropdownPlacement.js";
export function CompactDropdown({
className = "",
@ -9,12 +10,14 @@ export function CompactDropdown({
openOnHover = false,
closeOnMouseLeave = false,
preventMouseDown = false,
autoPlace = false,
renderTrigger,
children
}) {
const [open, setOpen] = useState(false);
const rootRef = useRef(null);
const triggerRef = useRef(null);
const menuRef = useRef(null);
const internalPointerDownRef = useRef(false);
useEffect(() => {
@ -39,6 +42,23 @@ export function CompactDropdown({
};
}, [open]);
// `autoPlace` : le menu reste entièrement visible, quel que soit le bord dont il est proche.
useLayoutEffect(() => {
if (!open || !autoPlace || !menuRef.current) return undefined;
const place = () => placeDropdownMenu(menuRef.current, triggerRef.current || rootRef.current);
// Le défilement interne du menu ne change pas sa place : le recalcul remettrait sa liste en haut.
const placeOnOuterScroll = (event) => {
if (!menuRef.current?.contains(event.target)) place();
};
place();
window.addEventListener("resize", place);
window.addEventListener("scroll", placeOnOuterScroll, true);
return () => {
window.removeEventListener("resize", place);
window.removeEventListener("scroll", placeOnOuterScroll, true);
};
}, [open, autoPlace]);
function close() {
setOpen(false);
}
@ -68,7 +88,7 @@ export function CompactDropdown({
>
{renderTrigger({ open, toggle, close, triggerRef })}
{open && (
<div {...menuProps} className={`${menuClassName} ${menuProps.className || ""} is-open`.trim()} aria-label={menuProps["aria-label"] || (menuProps["aria-labelledby"] ? undefined : label)}>
<div {...menuProps} ref={menuRef} className={`${menuClassName} ${menuProps.className || ""} is-open`.trim()} aria-label={menuProps["aria-label"] || (menuProps["aria-labelledby"] ? undefined : label)}>
{children({ close })}
</div>
)}

View file

@ -0,0 +1,56 @@
// Rôle : sélecteur à choix unique du design system (`nds-select-trigger` et `nds-popover`), à utiliser à la place d'un `<select>` natif.
import { useRef } from "react";
import { CompactDropdown } from "./CompactDropdown.jsx";
function moveFocus(event) {
const options = [...event.currentTarget.querySelectorAll('[role="option"]')];
const current = options.indexOf(globalThis.document.activeElement);
const targets = { ArrowDown: options[current + 1], ArrowUp: options[current - 1], Home: options[0], End: options.at(-1) };
if (!(event.key in targets)) return;
event.preventDefault();
targets[event.key]?.focus();
}
// `options` : [{ value, label }]. `hideLabel` masque l'intitulé visible en conservant le nom accessible ; `align="end"` ouvre le menu vers la gauche, près du bord droit.
export function SelectDropdown({ label, hideLabel = false, value, options, onChange, placeholder = "", disabled = false, size = "md", align = "start", className = "" }) {
const triggerElement = useRef(null);
const selected = options.find((option) => option.value === value);
const text = selected?.label ?? placeholder;
const focusedValue = selected ? value : options[0]?.value;
return <div className={`nds-select-field ${className}`.trim()} data-align={align}>
{!hideLabel && <span aria-hidden="true">{label}</span>}
<CompactDropdown
className="nds-select-dropdown"
autoPlace
menuClassName="nds-select-menu nds-popover"
menuProps={{ role: "listbox", "aria-label": label, onKeyDown: moveFocus }}
label={label}
renderTrigger={({ open, toggle, triggerRef }) => <button
ref={(element) => { triggerRef.current = element; triggerElement.current = element; }}
className={`nds-select-trigger ${open ? "active" : ""}`}
data-size={size}
type="button"
disabled={disabled}
aria-haspopup="listbox"
aria-expanded={open}
aria-label={`${label} : ${text}`}
onClick={toggle}
><span className="nds-select-dropdown-value">{text}</span></button>}
>
{({ close }) => options.map((option) => <button
key={option.value}
className={`nds-select-option ${option.value === value ? "active" : ""}`}
type="button"
role="option"
aria-selected={option.value === value}
autoFocus={option.value === focusedValue}
onClick={() => {
onChange(option.value);
close();
triggerElement.current?.focus();
}}
>{option.label}</button>)}
</CompactDropdown>
</div>;
}

View file

@ -4,10 +4,10 @@ import { Icon } from "./Icon.jsx";
import { ImportButton } from "./ImportButton.jsx";
import { Tooltip } from "./Tooltip.jsx";
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, actions, onOpenAutoBackup, children }) {
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, cardsEnabled = false, actions, onOpenAutoBackup, children }) {
const gameId = route.split("/")[1] === "games" ? route.split("/")[2] || "" : "";
const game = games.find((item) => item.id === gameId);
const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : content.topbar.dashboard;
const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : route.startsWith("/cards") ? content.topbar.cards : content.topbar.dashboard;
const toolboxOpen = Boolean(game && drawerGameId === game.id && drawerVisible);
const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox";
const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen));
@ -52,6 +52,7 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
<Tooltip as="a" className={`nav-item ${route === "/" ? "active" : ""}`} content={compactSidebar ? content.navigation.home : ""} position="right" href="#/" aria-label={content.navigation.home}><span className="nav-icon nav-icon-home" aria-hidden="true" /><strong>{content.navigation.home}</strong></Tooltip>
<Tooltip as="a" className={`nav-item ${route.startsWith("/games") ? "active" : ""}`} content={compactSidebar ? content.navigation.games : ""} position="right" href="#/games" aria-label={content.navigation.games}><span className="nav-icon nav-icon-controller" aria-hidden="true" /><strong>{content.navigation.games}</strong></Tooltip>
<Tooltip as="a" className={`nav-item ${route.startsWith("/toolboxes") || route.startsWith("/toolbox") ? "active" : ""}`} content={compactSidebar ? content.navigation.toolboxes : ""} position="right" href="#/toolboxes" aria-label={content.navigation.toolboxes}><span className="nav-icon nav-icon-toolbox" aria-hidden="true" /><strong>{content.navigation.toolboxes}</strong></Tooltip>
{cardsEnabled && <Tooltip as="a" className={`nav-item ${route.startsWith("/cards") ? "active" : ""}`} content={compactSidebar ? content.navigation.cards : ""} position="right" href="#/cards" aria-label={content.navigation.cards}><span className="nav-icon nav-icon-cards" aria-hidden="true" /><strong>{content.navigation.cards}</strong></Tooltip>}
</nav>
<div className="sidebar-mascot" aria-hidden="true">
<img src="/static/img/dragon-sidebar.webp" alt="" />

View file

@ -6,13 +6,14 @@ import { ImportButton } from "./ImportButton.jsx";
import { Modal } from "./Modal.jsx";
import { ToastPositionSwitch } from "./ToastPositionSwitch.jsx";
export function ConfirmModal({ title, message, confirmLabel = "Confirmer", cancelLabel = "Annuler", danger = false, onClose }) {
export function ConfirmModal({ title, message, children = null, confirmLabel = "Confirmer", cancelLabel = "Annuler", danger = false, onClose }) {
const titleId = useId();
const messageId = useId();
return (
<Modal labelledBy={titleId} describedBy={messageId} onRequestClose={() => onClose(false)}>
<header><h2 id={titleId}>{title}</h2></header>
<p id={messageId}>{message}</p>
{children}
<footer className="nds-modal-footer">
<button className="nds-button" data-size="sm" data-modal-initial-focus={danger ? "" : undefined} onClick={() => onClose(false)}>{cancelLabel}</button>
<button className="confirm-danger nds-button" data-size="sm" data-variant={danger ? "danger" : "primary"} onClick={() => onClose(true)}>{confirmLabel}</button>

View file

@ -0,0 +1,44 @@
// Rôle : place un menu flottant dans la zone réellement visible : décalage horizontal, ouverture vers le haut et hauteur limitée.
const EDGE_GAP = 8;
// Zone visible : la fenêtre, sous la barre supérieure collante, réduite par les ancêtres qui coupent leur contenu.
function visibleArea(element) {
const area = { top: EDGE_GAP, right: window.innerWidth - EDGE_GAP, bottom: window.innerHeight - EDGE_GAP, left: EDGE_GAP };
const topbar = element.ownerDocument.querySelector(".topbar");
if (topbar) area.top = Math.max(area.top, topbar.getBoundingClientRect().bottom + EDGE_GAP);
for (let parent = element.parentElement; parent && parent !== element.ownerDocument.documentElement; parent = parent.parentElement) {
const style = window.getComputedStyle(parent);
const bounds = parent.getBoundingClientRect();
if (style.overflowX !== "visible") {
area.left = Math.max(area.left, bounds.left + EDGE_GAP);
area.right = Math.min(area.right, bounds.right - EDGE_GAP);
}
if (style.overflowY !== "visible") {
area.top = Math.max(area.top, bounds.top + EDGE_GAP);
area.bottom = Math.min(area.bottom, bounds.bottom - EDGE_GAP);
}
}
return area;
}
export function placeDropdownMenu(menu, trigger) {
// Repartir de la position prévue par le style : chaque calcul mesure le menu tel qu'il s'ouvrirait naturellement.
Object.assign(menu.style, { translate: "", top: "", bottom: "", maxHeight: "", overflowY: "" });
const area = visibleArea(menu);
const box = menu.getBoundingClientRect();
let shift = 0;
if (box.right > area.right) shift = area.right - box.right;
if (box.left + shift < area.left) shift = area.left - box.left;
if (shift) menu.style.translate = `${Math.round(shift)}px 0`;
if (box.bottom <= area.bottom) return;
const anchor = trigger.getBoundingClientRect();
const gap = box.top - anchor.bottom;
const below = area.bottom - anchor.bottom - gap;
const above = anchor.top - area.top - gap;
const openAbove = box.height <= above || above > below;
if (openAbove) Object.assign(menu.style, { top: "auto", bottom: `calc(100% + ${Math.round(gap)}px)` });
const room = Math.floor(openAbove ? above : below);
if (box.height > room) Object.assign(menu.style, { maxHeight: `${Math.max(room, 80)}px`, overflowY: "auto" });
}