vomebook commited on
Commit ·
472fce5
1
Parent(s): e6e90f2
Apply saved theme before search and Reader first paint
Browse files- static/app.js +16 -2
- static/index.html +21 -4
- static/reader.html +16 -0
- static/reader.js +4 -2
- static/reader/core/reader-bindings.mjs +40 -6
- static/reader/ui/reader-ui.mjs +5 -0
- static/search/shell/presentation/view.js +2 -0
- static/style.css +10 -5
- tests/reader/browser/test_reader_accessibility_browser.py +53 -0
- tests/reader/browser/test_reader_navigation_host.py +39 -0
- tests/search/ui/shell_contracts.mjs +7 -2
static/app.js
CHANGED
|
@@ -3678,6 +3678,22 @@ function setupResultDelegation() {
|
|
| 3678 |
|
| 3679 |
async function init() {
|
| 3680 |
cacheDOM();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3681 |
getSidebarScroll().install();
|
| 3682 |
syncSearchInputState();
|
| 3683 |
setupSearchInput();
|
|
@@ -3691,8 +3707,6 @@ async function init() {
|
|
| 3691 |
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
| 3692 |
await restoredSession;
|
| 3693 |
setupReaderIntentWarming();
|
| 3694 |
-
STATE.isDark = readSearchPreference("theme") !== "light";
|
| 3695 |
-
applyTheme();
|
| 3696 |
const savedMobile = readSearchPreference("mobileMode");
|
| 3697 |
if (savedMobile === "mobile") STATE.isMobile = true;
|
| 3698 |
else if (savedMobile === "desktop") STATE.isMobile = false;
|
|
|
|
| 3678 |
|
| 3679 |
async function init() {
|
| 3680 |
cacheDOM();
|
| 3681 |
+
const syncStoredTheme = () => {
|
| 3682 |
+
let theme;
|
| 3683 |
+
try { theme = localStorage.getItem("theme"); } catch (_) { return; }
|
| 3684 |
+
const isDark = theme !== "light";
|
| 3685 |
+
if (STATE.isDark === isDark) return;
|
| 3686 |
+
STATE.isDark = isDark;
|
| 3687 |
+
applyTheme();
|
| 3688 |
+
};
|
| 3689 |
+
STATE.isDark = document.documentElement.dataset.theme !== "light";
|
| 3690 |
+
// Storage may have changed while the deferred entry was loading.
|
| 3691 |
+
try { STATE.isDark = localStorage.getItem("theme") !== "light"; } catch (_) {}
|
| 3692 |
+
applyTheme();
|
| 3693 |
+
window.addEventListener("storage", event => {
|
| 3694 |
+
if (event.key === "theme" || event.key === null) syncStoredTheme();
|
| 3695 |
+
});
|
| 3696 |
+
window.addEventListener("pageshow", event => { if (event.persisted) syncStoredTheme(); });
|
| 3697 |
getSidebarScroll().install();
|
| 3698 |
syncSearchInputState();
|
| 3699 |
setupSearchInput();
|
|
|
|
| 3707 |
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
| 3708 |
await restoredSession;
|
| 3709 |
setupReaderIntentWarming();
|
|
|
|
|
|
|
| 3710 |
const savedMobile = readSearchPreference("mobileMode");
|
| 3711 |
if (savedMobile === "mobile") STATE.isMobile = true;
|
| 3712 |
else if (savedMobile === "desktop") STATE.isMobile = false;
|
static/index.html
CHANGED
|
@@ -3,7 +3,25 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<!-- SEO:HEAD -->
|
| 8 |
<title>VoiceOfML Search</title>
|
| 9 |
<meta name="description" content="检索 VoiceOfML 公开资料的文件名、路径和格式,浏览文库目录,在线阅读或下载原始文件。">
|
|
@@ -21,7 +39,6 @@
|
|
| 21 |
<!-- HF supplies the HTTP canonical; do not add a conflicting HTML canonical. -->
|
| 22 |
<!-- /SEO:HEAD -->
|
| 23 |
<link rel="manifest" href="/manifest.json">
|
| 24 |
-
<meta name="theme-color" content="#1a1c1e">
|
| 25 |
<meta name="mobile-web-app-capable" content="yes">
|
| 26 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 27 |
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
@@ -33,7 +50,7 @@
|
|
| 33 |
<script>fetch("/api/ping", { cache: "no-store" }).catch(() => {});</script>
|
| 34 |
<link rel="stylesheet" href="/static/style.css">
|
| 35 |
</head>
|
| 36 |
-
<body
|
| 37 |
<a class="skip-link" href="#results-container">跳转到搜索结果</a>
|
| 38 |
<div id="search-announcement" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>
|
| 39 |
|
|
@@ -107,7 +124,7 @@
|
|
| 107 |
</svg>
|
| 108 |
</button>
|
| 109 |
<button id="theme-btn" class="icon-btn" aria-label="切换主题" title="深色/浅色模式">
|
| 110 |
-
<svg id="theme-icon-light" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
| 111 |
<circle cx="12" cy="12" r="5"/>
|
| 112 |
<line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/>
|
| 113 |
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta name="theme-color" content="#1a1c1e">
|
| 7 |
+
<script>
|
| 8 |
+
(() => {
|
| 9 |
+
const root = document.documentElement;
|
| 10 |
+
root.dataset.theme = "dark";
|
| 11 |
+
try {
|
| 12 |
+
if (localStorage.getItem("theme") === "light") {
|
| 13 |
+
root.dataset.theme = "light";
|
| 14 |
+
document.querySelector('meta[name="theme-color"]').setAttribute("content", "#fdfbff");
|
| 15 |
+
}
|
| 16 |
+
} catch (_) {}
|
| 17 |
+
try { if (matchMedia("(max-width: 768px)").matches && localStorage.getItem("mobileMode") !== "desktop") document.documentElement.classList.add("mobile-boot"); }
|
| 18 |
+
catch (_) { if (matchMedia("(max-width: 768px)").matches) document.documentElement.classList.add("mobile-boot"); }
|
| 19 |
+
})();
|
| 20 |
+
</script>
|
| 21 |
+
<style>
|
| 22 |
+
:root { color-scheme: dark; background: #1a1c1e; }
|
| 23 |
+
:root[data-theme="light"] { color-scheme: light; background: #fdfbff; }
|
| 24 |
+
</style>
|
| 25 |
<!-- SEO:HEAD -->
|
| 26 |
<title>VoiceOfML Search</title>
|
| 27 |
<meta name="description" content="检索 VoiceOfML 公开资料的文件名、路径和格式,浏览文库目录,在线阅读或下载原始文件。">
|
|
|
|
| 39 |
<!-- HF supplies the HTTP canonical; do not add a conflicting HTML canonical. -->
|
| 40 |
<!-- /SEO:HEAD -->
|
| 41 |
<link rel="manifest" href="/manifest.json">
|
|
|
|
| 42 |
<meta name="mobile-web-app-capable" content="yes">
|
| 43 |
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 44 |
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
|
|
| 50 |
<script>fetch("/api/ping", { cache: "no-store" }).catch(() => {});</script>
|
| 51 |
<link rel="stylesheet" href="/static/style.css">
|
| 52 |
</head>
|
| 53 |
+
<body>
|
| 54 |
<a class="skip-link" href="#results-container">跳转到搜索结果</a>
|
| 55 |
<div id="search-announcement" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>
|
| 56 |
|
|
|
|
| 124 |
</svg>
|
| 125 |
</button>
|
| 126 |
<button id="theme-btn" class="icon-btn" aria-label="切换主题" title="深色/浅色模式">
|
| 127 |
+
<svg id="theme-icon-light" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
| 128 |
<circle cx="12" cy="12" r="5"/>
|
| 129 |
<line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/>
|
| 130 |
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
static/reader.html
CHANGED
|
@@ -9,6 +9,22 @@
|
|
| 9 |
content="default-src 'self'; base-uri 'self' blob:; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline' blob:; font-src 'self' blob:; img-src 'self' data: blob: https:; media-src 'self' https://voiceofml-search.hf.space https://hf-mirror.com https://huggingface.co https://*.hf.co https://*.huggingface.co https://vomebook-hitokoto.hf.space blob:; connect-src 'self' blob: https://huggingface.co https://*.hf.co https://*.huggingface.co https://voiceofml-search.hf.space https://hf-mirror.com https://vomebook-hitokoto.hf.space; frame-src 'self' blob:;"
|
| 10 |
/>
|
| 11 |
<title>VoiceOfML Reader</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
<script>
|
| 13 |
// Start source lookup before the Reader module graph loads; consume it once.
|
| 14 |
(() => {
|
|
|
|
| 9 |
content="default-src 'self'; base-uri 'self' blob:; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline' blob:; font-src 'self' blob:; img-src 'self' data: blob: https:; media-src 'self' https://voiceofml-search.hf.space https://hf-mirror.com https://huggingface.co https://*.hf.co https://*.huggingface.co https://vomebook-hitokoto.hf.space blob:; connect-src 'self' blob: https://huggingface.co https://*.hf.co https://*.huggingface.co https://voiceofml-search.hf.space https://hf-mirror.com https://vomebook-hitokoto.hf.space; frame-src 'self' blob:;"
|
| 10 |
/>
|
| 11 |
<title>VoiceOfML Reader</title>
|
| 12 |
+
<meta name="theme-color" content="#111315" />
|
| 13 |
+
<script>
|
| 14 |
+
(() => {
|
| 15 |
+
let theme;
|
| 16 |
+
try { if (parent !== window) theme = parent.document.documentElement.dataset.theme; } catch (_) {}
|
| 17 |
+
if (theme !== "light" && theme !== "dark") {
|
| 18 |
+
try { theme = localStorage.getItem("theme"); } catch (_) {}
|
| 19 |
+
}
|
| 20 |
+
document.documentElement.dataset.theme = theme === "light" ? "light" : "dark";
|
| 21 |
+
if (theme === "light") document.querySelector('meta[name="theme-color"]').setAttribute("content", "#f4f5f6");
|
| 22 |
+
})();
|
| 23 |
+
</script>
|
| 24 |
+
<style>
|
| 25 |
+
:root { color-scheme: dark; background: #111315; }
|
| 26 |
+
:root[data-theme="light"] { color-scheme: light; background: #f4f5f6; }
|
| 27 |
+
</style>
|
| 28 |
<script>
|
| 29 |
// Start source lookup before the Reader module graph loads; consume it once.
|
| 30 |
(() => {
|
static/reader.js
CHANGED
|
@@ -1060,8 +1060,10 @@ const mediaTab = document.createElement("button"),
|
|
| 1060 |
mediaPanel = document.createElement("section");
|
| 1061 |
readerBindings.mountMediaPanel();
|
| 1062 |
// Theme, toolbar, and document navigation.
|
| 1063 |
-
let readerTheme = "dark";
|
| 1064 |
-
|
|
|
|
|
|
|
| 1065 |
const THEME_SUN_ICON =
|
| 1066 |
'<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="5"/><path d="M12 1v2m0 18v2M4.22 4.22l1.42 1.42m12.72 12.72 1.42 1.42M1 12h2m18 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>';
|
| 1067 |
const THEME_MOON_ICON =
|
|
|
|
| 1060 |
mediaPanel = document.createElement("section");
|
| 1061 |
readerBindings.mountMediaPanel();
|
| 1062 |
// Theme, toolbar, and document navigation.
|
| 1063 |
+
let readerTheme = document.documentElement.dataset.theme === "light" ? "light" : "dark";
|
| 1064 |
+
if (!document.documentElement.dataset.theme) {
|
| 1065 |
+
try { if (localStorage.getItem("theme") === "light") readerTheme = "light"; } catch (_) {}
|
| 1066 |
+
}
|
| 1067 |
const THEME_SUN_ICON =
|
| 1068 |
'<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="5"/><path d="M12 1v2m0 18v2M4.22 4.22l1.42 1.42m12.72 12.72 1.42 1.42M1 12h2m18 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>';
|
| 1069 |
const THEME_MOON_ICON =
|
static/reader/core/reader-bindings.mjs
CHANGED
|
@@ -377,17 +377,50 @@ export function createReaderBindings(readerContext) {
|
|
| 377 |
readerContext.applyPageInversion();
|
| 378 |
}
|
| 379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
function restoreReaderThemeAndBindReturn() {
|
| 381 |
readerContext.readerThemeToggle.className = "theme-toggle";
|
| 382 |
|
| 383 |
-
readerContext.applyReaderTheme(
|
| 384 |
|
| 385 |
readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);
|
| 386 |
document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);
|
| 387 |
let closing = false;
|
| 388 |
-
window.addEventListener("pageshow", event => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
// A parked speech iframe is shown again without a document navigation.
|
| 390 |
-
window.addEventListener("voice-reader-overlay-resume", () => {
|
|
|
|
|
|
|
|
|
|
| 391 |
/** @type {Element} */ (document.querySelector("#back")).addEventListener("click", async () => {
|
| 392 |
if (closing) return;
|
| 393 |
closing = true;
|
|
@@ -678,7 +711,7 @@ export function createReaderBindings(readerContext) {
|
|
| 678 |
window.parent.postMessage({ type: "voice-reader-theme", theme }, location.origin);
|
| 679 |
});
|
| 680 |
window.addEventListener("storage", (event) => {
|
| 681 |
-
if (event.key === "theme"
|
| 682 |
});
|
| 683 |
window.addEventListener("voice-reader-capture-progress", event => {
|
| 684 |
if (!readerContext.isReaderOverlayFrame()) return;
|
|
@@ -708,9 +741,10 @@ export function createReaderBindings(readerContext) {
|
|
| 708 |
event.origin === location.origin &&
|
| 709 |
event.source === window.parent &&
|
| 710 |
event.data &&
|
| 711 |
-
event.data.type === "voice-reader-theme-state"
|
|
|
|
| 712 |
)
|
| 713 |
-
|
| 714 |
});
|
| 715 |
/** @type {HTMLButtonElement} */ (document.querySelector("#history"))
|
| 716 |
.addEventListener("click", (event) =>
|
|
|
|
| 377 |
readerContext.applyPageInversion();
|
| 378 |
}
|
| 379 |
|
| 380 |
+
/** @param {string | null} theme @param {boolean} [resume] */
|
| 381 |
+
function syncReaderTheme(theme, resume = false) {
|
| 382 |
+
const next = theme === "light" ? "light" : "dark";
|
| 383 |
+
if (next !== readerContext.readerTheme || (resume && document.documentElement.classList.contains("theme-transition"))) {
|
| 384 |
+
readerContext.applyReaderTheme(next, false, false);
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
/** @param {boolean} [resume] */
|
| 389 |
+
function syncStoredReaderTheme(resume = false) {
|
| 390 |
+
try { syncReaderTheme(localStorage.getItem("theme"), resume); } catch (_) {}
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function activeReaderTheme() {
|
| 394 |
+
// The Search shell also owns the first frame of embedded Readers when
|
| 395 |
+
// storage is unavailable or the preference changes during module loading.
|
| 396 |
+
try {
|
| 397 |
+
if (window.parent !== window) {
|
| 398 |
+
const theme = window.parent.document.documentElement.dataset.theme;
|
| 399 |
+
if (theme === "light" || theme === "dark") return theme;
|
| 400 |
+
}
|
| 401 |
+
} catch (_) {}
|
| 402 |
+
try { return localStorage.getItem("theme") === "light" ? "light" : "dark"; }
|
| 403 |
+
catch (_) { return readerContext.readerTheme; }
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
function restoreReaderThemeAndBindReturn() {
|
| 407 |
readerContext.readerThemeToggle.className = "theme-toggle";
|
| 408 |
|
| 409 |
+
readerContext.applyReaderTheme(activeReaderTheme(), false, false);
|
| 410 |
|
| 411 |
readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);
|
| 412 |
document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);
|
| 413 |
let closing = false;
|
| 414 |
+
window.addEventListener("pageshow", event => {
|
| 415 |
+
if (!event.persisted) return;
|
| 416 |
+
closing = false;
|
| 417 |
+
syncStoredReaderTheme(true);
|
| 418 |
+
});
|
| 419 |
// A parked speech iframe is shown again without a document navigation.
|
| 420 |
+
window.addEventListener("voice-reader-overlay-resume", () => {
|
| 421 |
+
closing = false;
|
| 422 |
+
syncReaderTheme(activeReaderTheme(), true);
|
| 423 |
+
});
|
| 424 |
/** @type {Element} */ (document.querySelector("#back")).addEventListener("click", async () => {
|
| 425 |
if (closing) return;
|
| 426 |
closing = true;
|
|
|
|
| 711 |
window.parent.postMessage({ type: "voice-reader-theme", theme }, location.origin);
|
| 712 |
});
|
| 713 |
window.addEventListener("storage", (event) => {
|
| 714 |
+
if (event.key === "theme" || event.key === null) syncStoredReaderTheme();
|
| 715 |
});
|
| 716 |
window.addEventListener("voice-reader-capture-progress", event => {
|
| 717 |
if (!readerContext.isReaderOverlayFrame()) return;
|
|
|
|
| 741 |
event.origin === location.origin &&
|
| 742 |
event.source === window.parent &&
|
| 743 |
event.data &&
|
| 744 |
+
event.data.type === "voice-reader-theme-state" &&
|
| 745 |
+
(event.data.theme === "light" || event.data.theme === "dark")
|
| 746 |
)
|
| 747 |
+
syncReaderTheme(event.data.theme);
|
| 748 |
});
|
| 749 |
/** @type {HTMLButtonElement} */ (document.querySelector("#history"))
|
| 750 |
.addEventListener("click", (event) =>
|
static/reader/ui/reader-ui.mjs
CHANGED
|
@@ -36,9 +36,14 @@ export function createReaderUi(readerContext) {
|
|
| 36 |
clearTimeout(readerContext.themeAnimationTimer);
|
| 37 |
document.documentElement.classList.add("theme-transition");
|
| 38 |
void document.documentElement.offsetWidth;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
readerContext.readerTheme = theme === "light" ? "light" : "dark";
|
| 41 |
document.documentElement.dataset.theme = readerContext.readerTheme;
|
|
|
|
| 42 |
readerContext.readerThemeToggle.innerHTML = readerContext.readerTheme === "dark" ? readerContext.THEME_MOON_ICON : readerContext.THEME_SUN_ICON;
|
| 43 |
if (animate) {
|
| 44 |
readerContext.readerThemeToggle.classList.remove("is-changing");
|
|
|
|
| 36 |
clearTimeout(readerContext.themeAnimationTimer);
|
| 37 |
document.documentElement.classList.add("theme-transition");
|
| 38 |
void document.documentElement.offsetWidth;
|
| 39 |
+
} else {
|
| 40 |
+
clearTimeout(readerContext.themeAnimationTimer);
|
| 41 |
+
document.documentElement.classList.remove("theme-transition");
|
| 42 |
+
readerContext.readerThemeToggle.classList.remove("is-changing");
|
| 43 |
}
|
| 44 |
readerContext.readerTheme = theme === "light" ? "light" : "dark";
|
| 45 |
document.documentElement.dataset.theme = readerContext.readerTheme;
|
| 46 |
+
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", readerContext.readerTheme === "light" ? "#f4f5f6" : "#111315");
|
| 47 |
readerContext.readerThemeToggle.innerHTML = readerContext.readerTheme === "dark" ? readerContext.THEME_MOON_ICON : readerContext.THEME_SUN_ICON;
|
| 48 |
if (animate) {
|
| 49 |
readerContext.readerThemeToggle.classList.remove("is-changing");
|
static/search/shell/presentation/view.js
CHANGED
|
@@ -37,6 +37,8 @@
|
|
| 37 |
/** @param {boolean} isDark */
|
| 38 |
function applyTheme(isDark) {
|
| 39 |
const el = elements();
|
|
|
|
|
|
|
| 40 |
el.themeBtn.setAttribute('aria-label', isDark ? '切换到浅色主题' : '切换到深色主题');
|
| 41 |
if (isDark) {
|
| 42 |
document.body.classList.remove("light");
|
|
|
|
| 37 |
/** @param {boolean} isDark */
|
| 38 |
function applyTheme(isDark) {
|
| 39 |
const el = elements();
|
| 40 |
+
document.documentElement.setAttribute("data-theme", isDark ? "dark" : "light");
|
| 41 |
+
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", isDark ? "#1a1c1e" : "#fdfbff");
|
| 42 |
el.themeBtn.setAttribute('aria-label', isDark ? '切换到浅色主题' : '切换到深色主题');
|
| 43 |
if (isDark) {
|
| 44 |
document.body.classList.remove("light");
|
static/style.css
CHANGED
|
@@ -67,7 +67,7 @@ body.reader-overlay-open {
|
|
| 67 |
width: 100%;
|
| 68 |
height: 100%;
|
| 69 |
border: 0;
|
| 70 |
-
background: #
|
| 71 |
}
|
| 72 |
|
| 73 |
.reader-overlay-pending { visibility: hidden; }
|
|
@@ -95,7 +95,8 @@ body.reader-overlay-open {
|
|
| 95 |
cursor: pointer;
|
| 96 |
}
|
| 97 |
|
| 98 |
-
|
|
|
|
| 99 |
--surface: #fdfbff;
|
| 100 |
--surface-variant: #f0eff4;
|
| 101 |
--surface-container: #f5f3f7;
|
|
@@ -116,6 +117,10 @@ body.light {
|
|
| 116 |
color-scheme: light;
|
| 117 |
}
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
*, *::before, *::after {
|
| 120 |
box-sizing: border-box;
|
| 121 |
margin: 0;
|
|
@@ -283,11 +288,11 @@ ul, li {
|
|
| 283 |
display: none;
|
| 284 |
}
|
| 285 |
|
| 286 |
-
|
| 287 |
display: none;
|
| 288 |
}
|
| 289 |
|
| 290 |
-
|
| 291 |
display: block;
|
| 292 |
}
|
| 293 |
|
|
@@ -689,7 +694,7 @@ body.light .header-logo-icon-light {
|
|
| 689 |
background: rgba(255, 255, 255, 0.04);
|
| 690 |
}
|
| 691 |
|
| 692 |
-
|
| 693 |
background: rgba(0, 0, 0, 0.04);
|
| 694 |
}
|
| 695 |
|
|
|
|
| 67 |
width: 100%;
|
| 68 |
height: 100%;
|
| 69 |
border: 0;
|
| 70 |
+
background: var(--reader-overlay-background, #111315);
|
| 71 |
}
|
| 72 |
|
| 73 |
.reader-overlay-pending { visibility: hidden; }
|
|
|
|
| 95 |
cursor: pointer;
|
| 96 |
}
|
| 97 |
|
| 98 |
+
:root[data-theme="light"] {
|
| 99 |
+
--reader-overlay-background: #f4f5f6;
|
| 100 |
--surface: #fdfbff;
|
| 101 |
--surface-variant: #f0eff4;
|
| 102 |
--surface-container: #f5f3f7;
|
|
|
|
| 117 |
color-scheme: light;
|
| 118 |
}
|
| 119 |
|
| 120 |
+
#theme-icon-light,
|
| 121 |
+
:root[data-theme="light"] #theme-icon-dark { display: none; }
|
| 122 |
+
:root[data-theme="light"] #theme-icon-light { display: inline; }
|
| 123 |
+
|
| 124 |
*, *::before, *::after {
|
| 125 |
box-sizing: border-box;
|
| 126 |
margin: 0;
|
|
|
|
| 288 |
display: none;
|
| 289 |
}
|
| 290 |
|
| 291 |
+
:root[data-theme="light"] .header-logo-icon-dark {
|
| 292 |
display: none;
|
| 293 |
}
|
| 294 |
|
| 295 |
+
:root[data-theme="light"] .header-logo-icon-light {
|
| 296 |
display: block;
|
| 297 |
}
|
| 298 |
|
|
|
|
| 694 |
background: rgba(255, 255, 255, 0.04);
|
| 695 |
}
|
| 696 |
|
| 697 |
+
:root[data-theme="light"] .left-sidebar.expanded-wide .browser-item:nth-child(even) {
|
| 698 |
background: rgba(0, 0, 0, 0.04);
|
| 699 |
}
|
| 700 |
|
tests/reader/browser/test_reader_accessibility_browser.py
CHANGED
|
@@ -38,6 +38,59 @@ class ReaderAccessibilityTests(unittest.TestCase):
|
|
| 38 |
self.page.locator('#history').press('Enter')
|
| 39 |
self.page.locator('#history').press('Enter')
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def test_compact_number_editors_hide_default_outline_only(self):
|
| 42 |
self.page.set_viewport_size({'width': 390, 'height': 844})
|
| 43 |
# Use the existing offline PDF engine and real toolbar controls.
|
|
|
|
| 38 |
self.page.locator('#history').press('Enter')
|
| 39 |
self.page.locator('#history').press('Enter')
|
| 40 |
|
| 41 |
+
def test_saved_theme_colors_both_shells_before_app_and_reader_scripts(self):
|
| 42 |
+
# Hold the main entry out of the test entirely: a post-init assertion
|
| 43 |
+
# would miss the dark frame while modules or IndexedDB are pending.
|
| 44 |
+
self.page.route('**/static/app.js', lambda route: route.abort())
|
| 45 |
+
self.page.route('**/static/reader.js', lambda route: route.abort())
|
| 46 |
+
search_url = self.origin + support.PREFIX + '/'
|
| 47 |
+
index = (support.ROOT / 'static/index.html').read_text()
|
| 48 |
+
self.page.route(search_url, lambda route: route.fulfill(content_type='text/html', body=index))
|
| 49 |
+
reader_url = self.origin + support.PREFIX + '/static/reader.html?ext=txt'
|
| 50 |
+
self.page.route(self.origin + '/theme-test-setup', lambda route: route.fulfill(body='setup'))
|
| 51 |
+
self.page.goto(self.origin + '/theme-test-setup')
|
| 52 |
+
self.page.evaluate("localStorage.setItem('theme', 'light')")
|
| 53 |
+
def colors():
|
| 54 |
+
return self.page.evaluate('''() => {
|
| 55 |
+
const root = getComputedStyle(document.documentElement);
|
| 56 |
+
const shell = document.querySelector('.reader-toolbar') || document.body;
|
| 57 |
+
return [root.colorScheme, root.backgroundColor, getComputedStyle(shell).backgroundColor,
|
| 58 |
+
document.querySelector('meta[name="theme-color"]').content];
|
| 59 |
+
}''')
|
| 60 |
+
light_search = ['light', 'rgb(253, 251, 255)', 'rgb(253, 251, 255)', '#fdfbff']
|
| 61 |
+
light_reader = ['light', 'rgb(244, 245, 246)', 'rgb(255, 255, 255)', '#f4f5f6']
|
| 62 |
+
cdp = self.context.new_cdp_session(self.page)
|
| 63 |
+
for width, agent in ((390, 'Mozilla/5.0 (Linux; Android 14) Chrome/145 Mobile'),
|
| 64 |
+
(1280, 'Mozilla/5.0 (X11; Linux x86_64) Chrome/145')):
|
| 65 |
+
cdp.send('Network.setUserAgentOverride', {'userAgent': agent})
|
| 66 |
+
self.page.set_viewport_size(dict(width=width, height=800))
|
| 67 |
+
self.page.goto(search_url)
|
| 68 |
+
self.assertEqual(colors(), light_search)
|
| 69 |
+
self.assertEqual(self.page.locator('html').evaluate("el => el.classList.contains('mobile-boot')"), width == 390)
|
| 70 |
+
self.page.goto(reader_url)
|
| 71 |
+
self.assertEqual(colors(), light_reader)
|
| 72 |
+
self.page.go_back()
|
| 73 |
+
self.assertEqual(colors(), light_search)
|
| 74 |
+
self.page.reload()
|
| 75 |
+
self.assertEqual(colors(), light_search)
|
| 76 |
+
self.page.evaluate("localStorage.setItem('theme', 'dark')")
|
| 77 |
+
self.page.reload()
|
| 78 |
+
self.assertEqual(colors(), ['dark', 'rgb(26, 28, 30)', 'rgb(26, 28, 30)', '#1a1c1e'])
|
| 79 |
+
self.page.goto(reader_url)
|
| 80 |
+
self.assertEqual(colors(), ['dark', 'rgb(17, 19, 21)', 'rgb(27, 30, 33)', '#111315'])
|
| 81 |
+
|
| 82 |
+
def test_reader_history_restore_applies_theme_without_transition(self):
|
| 83 |
+
self.open_book(open_panel=False)
|
| 84 |
+
state = self.page.evaluate('''() => {
|
| 85 |
+
const root = document.documentElement;
|
| 86 |
+
localStorage.setItem('theme', 'light');
|
| 87 |
+
root.classList.add('theme-transition');
|
| 88 |
+
window.dispatchEvent(new PageTransitionEvent('pageshow', {persisted: true}));
|
| 89 |
+
return [root.dataset.theme, root.classList.contains('theme-transition'),
|
| 90 |
+
document.querySelector('meta[name="theme-color"]').content, localStorage.getItem('theme')];
|
| 91 |
+
}''')
|
| 92 |
+
self.assertEqual(state, ['light', False, '#f4f5f6', 'light'])
|
| 93 |
+
|
| 94 |
def test_compact_number_editors_hide_default_outline_only(self):
|
| 95 |
self.page.set_viewport_size({'width': 390, 'height': 844})
|
| 96 |
# Use the existing offline PDF engine and real toolbar controls.
|
tests/reader/browser/test_reader_navigation_host.py
CHANGED
|
@@ -27,6 +27,30 @@ class ReaderNavigationHostTests(unittest.TestCase):
|
|
| 27 |
self.assertEqual(self.fixture.errors, [])
|
| 28 |
self.fixture.tearDown()
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def test_bundled_shell_starts_without_separate_dependency_scripts(self):
|
| 31 |
root = Path(__file__).resolve().parents[3]
|
| 32 |
shell = subprocess.check_output(['node', '--input-type=module', '-e', '''
|
|
@@ -760,8 +784,23 @@ process.stdout.write(stripBundledScripts(readFileSync('static/index.html','utf8'
|
|
| 760 |
self.assertEqual(self.page.url, search_url)
|
| 761 |
self.assertTrue(self.page.evaluate('!readerHost.overlay && readerNavigation.backgroundReader === __speechFrame'))
|
| 762 |
if reopen:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
bar.get_by_role('button', name='返回阅读').click()
|
| 764 |
self.assertTrue(self.page.evaluate('readerHost.overlay === __speechFrame && __speechFrame.contentDocument === __speechDocument'))
|
|
|
|
|
|
|
|
|
|
| 765 |
bar.get_by_role('button', name='停止朗读并关闭阅读器').click()
|
| 766 |
self.assertFalse(self.page.evaluate('__speechFrame.isConnected'))
|
| 767 |
|
|
|
|
| 27 |
self.assertEqual(self.fixture.errors, [])
|
| 28 |
self.fixture.tearDown()
|
| 29 |
|
| 30 |
+
def test_search_startup_uses_preference_changed_while_entry_is_loading(self):
|
| 31 |
+
pending = []
|
| 32 |
+
self.page.route('**/static/app.js', lambda route: pending.append(route))
|
| 33 |
+
self.page.reload(wait_until='commit')
|
| 34 |
+
self.page.wait_for_function("document.documentElement.dataset.theme === 'dark'")
|
| 35 |
+
other = self.fixture.context.new_page()
|
| 36 |
+
other.route(self.fixture.origin + '/theme-storage-test', lambda route: route.fulfill(body='test'))
|
| 37 |
+
other.goto(self.fixture.origin + '/theme-storage-test')
|
| 38 |
+
other.evaluate("localStorage.setItem('theme', 'light')")
|
| 39 |
+
other.close()
|
| 40 |
+
self.assertEqual(len(pending), 1)
|
| 41 |
+
pending.pop().continue_()
|
| 42 |
+
self.page.wait_for_function("typeof STATE !== 'undefined' && !STATE.isDark && document.documentElement.dataset.theme === 'light'")
|
| 43 |
+
|
| 44 |
+
def test_search_history_restore_resyncs_theme_without_ripple(self):
|
| 45 |
+
restored = self.page.evaluate('''() => {
|
| 46 |
+
localStorage.setItem('theme', 'light');
|
| 47 |
+
window.dispatchEvent(new PageTransitionEvent('pageshow', {persisted: true}));
|
| 48 |
+
return [STATE.isDark, getComputedStyle(document.documentElement).colorScheme,
|
| 49 |
+
document.querySelector('meta[name="theme-color"]').content,
|
| 50 |
+
!!document.querySelector('.theme-ripple')];
|
| 51 |
+
}''')
|
| 52 |
+
self.assertEqual(restored, [False, 'light', '#fdfbff', False])
|
| 53 |
+
|
| 54 |
def test_bundled_shell_starts_without_separate_dependency_scripts(self):
|
| 55 |
root = Path(__file__).resolve().parents[3]
|
| 56 |
shell = subprocess.check_output(['node', '--input-type=module', '-e', '''
|
|
|
|
| 784 |
self.assertEqual(self.page.url, search_url)
|
| 785 |
self.assertTrue(self.page.evaluate('!readerHost.overlay && readerNavigation.backgroundReader === __speechFrame'))
|
| 786 |
if reopen:
|
| 787 |
+
# Model a parked Reader that missed a preference update while
|
| 788 |
+
# hidden. Reopen must sync theme even before a frame is painted.
|
| 789 |
+
self.page.evaluate('''() => {
|
| 790 |
+
STATE.isDark = false;
|
| 791 |
+
applyTheme();
|
| 792 |
+
__speechDocument.documentElement.classList.add('theme-transition');
|
| 793 |
+
__speechFrame.contentWindow.addEventListener('voice-reader-overlay-resume', () => {
|
| 794 |
+
const root = __speechDocument.documentElement;
|
| 795 |
+
window.__resumedTheme = [root.dataset.theme, root.classList.contains('theme-transition'),
|
| 796 |
+
document.activeElement === __speechFrame];
|
| 797 |
+
}, {once: true});
|
| 798 |
+
}''')
|
| 799 |
bar.get_by_role('button', name='返回阅读').click()
|
| 800 |
self.assertTrue(self.page.evaluate('readerHost.overlay === __speechFrame && __speechFrame.contentDocument === __speechDocument'))
|
| 801 |
+
self.assertEqual(self.page.evaluate('__resumedTheme'), ['light', False, False])
|
| 802 |
+
self.assertEqual(self.page.locator('.reader-overlay').evaluate('el => getComputedStyle(el).backgroundColor'),
|
| 803 |
+
'rgb(244, 245, 246)')
|
| 804 |
bar.get_by_role('button', name='停止朗读并关闭阅读器').click()
|
| 805 |
self.assertFalse(self.page.evaluate('__speechFrame.isConnected'))
|
| 806 |
|
tests/search/ui/shell_contracts.mjs
CHANGED
|
@@ -42,7 +42,8 @@ function fixture() {
|
|
| 42 |
const leftControl = element('leftControl', DOM.leftSidebar), rightControl = element('rightControl', DOM.rightSidebar);
|
| 43 |
DOM.leftSidebar.controls = [leftControl]; DOM.rightSidebar.controls = [rightControl];
|
| 44 |
document.body = element('body'); document.documentElement = element('html');
|
| 45 |
-
|
|
|
|
| 46 |
document.createElement = () => element('ripple');
|
| 47 |
const c = vm.createContext({shell: null, DOM, document,
|
| 48 |
STATE: {isDark: true, isMobile: false, leftSidebarOpen: true, rightSidebarOpen: false},
|
|
@@ -63,7 +64,7 @@ function fixture() {
|
|
| 63 |
const single = app.match(new RegExp('^function ' + name + '\\([^\\n]*\\}\\s*$', 'm'));
|
| 64 |
assert.ok(single || match, name); vm.runInContext((single || match)[0], c);
|
| 65 |
}
|
| 66 |
-
return {c, events, nodes, frames, messages, document, DOM, main, mainControl, leftControl, rightControl, element};
|
| 67 |
}
|
| 68 |
|
| 69 |
test('shell modules are registered once in source, bundle, offline, resources and strict projects', async () => {
|
|
@@ -97,6 +98,8 @@ test('theme ripple, reader message, persistence and animation cleanup retain ord
|
|
| 97 |
f.c.toggleTheme();
|
| 98 |
assert.equal(f.c.STATE.isDark, false);
|
| 99 |
assert.equal(f.document.body.classes.has('light'), true);
|
|
|
|
|
|
|
| 100 |
assert.equal(f.DOM.themeIconDark.style.display, 'none');
|
| 101 |
assert.deepEqual(f.messages, [[{type: 'voice-reader-theme-state', theme: 'light'}, 'https://shell.test']]);
|
| 102 |
assert.deepEqual(f.events.slice(-3), [['reader', 'light'], ['preference', 'theme', 'light'], ['listen', 'animationend']]);
|
|
@@ -111,6 +114,8 @@ test('theme ripple, reader message, persistence and animation cleanup retain ord
|
|
| 111 |
f.c.toggleTheme(); assert.equal(f.c.STATE.isDark, true);
|
| 112 |
assert.equal(f.nodes[1].style.background, '#1a1c1e');
|
| 113 |
assert.equal(f.document.body.classes.has('light'), false);
|
|
|
|
|
|
|
| 114 |
});
|
| 115 |
|
| 116 |
test('mobile defaults apply before header, selection, scheduled scroll and preference write', () => {
|
|
|
|
| 42 |
const leftControl = element('leftControl', DOM.leftSidebar), rightControl = element('rightControl', DOM.rightSidebar);
|
| 43 |
DOM.leftSidebar.controls = [leftControl]; DOM.rightSidebar.controls = [rightControl];
|
| 44 |
document.body = element('body'); document.documentElement = element('html');
|
| 45 |
+
const themeColor = element('theme-color');
|
| 46 |
+
document.querySelector = selector => selector === 'meta[name="theme-color"]' ? themeColor : main;
|
| 47 |
document.createElement = () => element('ripple');
|
| 48 |
const c = vm.createContext({shell: null, DOM, document,
|
| 49 |
STATE: {isDark: true, isMobile: false, leftSidebarOpen: true, rightSidebarOpen: false},
|
|
|
|
| 64 |
const single = app.match(new RegExp('^function ' + name + '\\([^\\n]*\\}\\s*$', 'm'));
|
| 65 |
assert.ok(single || match, name); vm.runInContext((single || match)[0], c);
|
| 66 |
}
|
| 67 |
+
return {c, events, nodes, frames, messages, document, DOM, main, mainControl, leftControl, rightControl, element, themeColor};
|
| 68 |
}
|
| 69 |
|
| 70 |
test('shell modules are registered once in source, bundle, offline, resources and strict projects', async () => {
|
|
|
|
| 98 |
f.c.toggleTheme();
|
| 99 |
assert.equal(f.c.STATE.isDark, false);
|
| 100 |
assert.equal(f.document.body.classes.has('light'), true);
|
| 101 |
+
assert.equal(f.document.documentElement.attributes['data-theme'], 'light');
|
| 102 |
+
assert.equal(f.themeColor.attributes.content, '#fdfbff');
|
| 103 |
assert.equal(f.DOM.themeIconDark.style.display, 'none');
|
| 104 |
assert.deepEqual(f.messages, [[{type: 'voice-reader-theme-state', theme: 'light'}, 'https://shell.test']]);
|
| 105 |
assert.deepEqual(f.events.slice(-3), [['reader', 'light'], ['preference', 'theme', 'light'], ['listen', 'animationend']]);
|
|
|
|
| 114 |
f.c.toggleTheme(); assert.equal(f.c.STATE.isDark, true);
|
| 115 |
assert.equal(f.nodes[1].style.background, '#1a1c1e');
|
| 116 |
assert.equal(f.document.body.classes.has('light'), false);
|
| 117 |
+
assert.equal(f.document.documentElement.attributes['data-theme'], 'dark');
|
| 118 |
+
assert.equal(f.themeColor.attributes.content, '#1a1c1e');
|
| 119 |
});
|
| 120 |
|
| 121 |
test('mobile defaults apply before header, selection, scheduled scroll and preference write', () => {
|