fixed # 更改休息处和商店的样式

This commit is contained in:
2026-11-19 18:32:47 +08:00
parent 8848f6524c
commit 9c3687fe7f
9 changed files with 1349 additions and 77 deletions
+25 -20
View File
@@ -2,12 +2,34 @@ import { ui } from "../../../../noname.js";
import { mountMenu } from "./navigation.js";
import { createRelicIcon } from "./relic-icon.js";
export const chooseButtons = (title, choices, description = "", options = {}) => new Promise(resolve => {
export const chooseFlow = (title, render, { back } = {}) => new Promise(resolve => {
const previousFocus = document.activeElement;
const overlay = ui.create.div(".mengsan-overlay-shuying.mengsan-flow-overlay-shuying", ui.window);
overlay.setAttribute("role", "dialog");
overlay.setAttribute("aria-modal", "true");
overlay.setAttribute("aria-label", title);
const finish = id => {
if (overlay.dataset.resolved) return;
overlay.dataset.resolved = "true";
overlay.remove();
if (previousFocus?.isConnected) previousFocus.focus();
resolve(id);
};
const initialFocus = render(overlay, finish);
overlay.addEventListener("keydown", event => {
if (event.key === "Escape" && back) {
event.preventDefault(); finish(back); return;
}
if (event.key !== "Tab") return;
const focusable = [...overlay.querySelectorAll("button:not(:disabled)")];
const first = focusable[0], last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
});
initialFocus?.focus();
});
export const chooseButtons = (title, choices, description = "", options = {}) => chooseFlow(title, (overlay, finish) => {
const panel = ui.create.div(".mengsan-panel-shuying.mengsan-flow-panel-shuying", overlay);
const eyebrow = document.createElement("p");
eyebrow.className = "mengsan-flow-eyebrow-shuying";
@@ -22,13 +44,6 @@ export const chooseButtons = (title, choices, description = "", options = {}) =>
summary.textContent = description;
}
const buttons = ui.create.div(".mengsan-choice-list-shuying", panel);
const finish = id => {
if (overlay.dataset.resolved) return;
overlay.dataset.resolved = "true";
overlay.remove();
if (previousFocus?.isConnected) previousFocus.focus();
resolve(id);
};
choices.forEach(choice => {
const button = document.createElement("button");
button.type = "button";
@@ -51,15 +66,5 @@ export const chooseButtons = (title, choices, description = "", options = {}) =>
buttons.appendChild(button);
});
if (options.menu !== false) mountMenu(overlay);
overlay.addEventListener("keydown", event => {
if (event.key === "Escape" && options.back) {
event.preventDefault(); finish(options.back); return;
}
if (event.key !== "Tab") return;
const focusable = [...overlay.querySelectorAll("button:not(:disabled)")];
const first = focusable[0], last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
});
buttons.querySelector("button:not(:disabled)")?.focus();
});
return buttons.querySelector("button:not(:disabled)");
}, options);