// 小型游戏弹窗通用事件代理,收口各游戏头部关闭按钮内联 onclick。 let gamePanelEventsBound = false; /** * 关闭指定 Alpine 游戏面板。 * * @param {string} panelId 面板 DOM ID * @returns {void} */ function closeAlpineGamePanel(panelId) { const panel = document.getElementById(panelId); const panelData = panel && typeof window.Alpine?.$data === "function" ? window.Alpine.$data(panel) : null; if (!panelData) { return; } // 多数游戏面板提供 close(),占卜面板只暴露 show 状态,因此保留 show=false 兜底。 if (typeof panelData.close === "function") { panelData.close(); return; } panelData.show = false; } /** * 绑定小型游戏面板通用关闭事件。 * * @returns {void} */ export function bindGamePanelControls() { if (gamePanelEventsBound || typeof document === "undefined") { return; } gamePanelEventsBound = true; document.addEventListener("click", (event) => { if (!(event.target instanceof Element)) { return; } const closeButton = event.target.closest("[data-game-panel-close]"); if (!closeButton) { return; } event.preventDefault(); closeAlpineGamePanel(closeButton.getAttribute("data-game-panel-close") || ""); }); }