const DEFAULT_DURATION_MS = 3500; const LEAVE_MS = 280; /** * Temporary top-of-screen toast messages (play HUD). */ export function initToasts () { const root = document.getElementById("toast-stack"); if (!root) { return { show () {} }; } function show (message, options = {}) { const text = String(message ?? "").trim(); if (!text) { return; } const durationMs = Math.max(800, options.durationMs ?? DEFAULT_DURATION_MS); const el = document.createElement("div"); el.className = "toast"; el.setAttribute("role", "status"); el.textContent = text; root.appendChild(el); requestAnimationFrame(() => { el.classList.add("toast-visible"); }); window.setTimeout(() => { el.classList.remove("toast-visible"); el.classList.add("toast-leaving"); window.setTimeout(() => el.remove(), LEAVE_MS); }, durationMs); } return { show }; }