vomebook commited on
Commit
de6eb19
·
1 Parent(s): 8180541

Layer shell appearance and sidebar focus coordination

Browse files
config/types/jsconfig.check.json CHANGED
@@ -97,6 +97,9 @@
97
  "../../typings/search-restoration.d.ts",
98
  "../../typings/search-results.d.ts",
99
  "../../typings/search-discovery.d.ts",
 
 
 
100
  "../../typings/search-history-ambient.d.ts",
101
  "../../static/search/history/infrastructure/store.js",
102
  "../../static/search/history/application/controller.js",
 
97
  "../../typings/search-restoration.d.ts",
98
  "../../typings/search-results.d.ts",
99
  "../../typings/search-discovery.d.ts",
100
+ "../../typings/search-shell.d.ts",
101
+ "../../static/search/shell/presentation/view.js",
102
+ "../../static/search/shell/application/controller.js",
103
  "../../typings/search-history-ambient.d.ts",
104
  "../../static/search/history/infrastructure/store.js",
105
  "../../static/search/history/application/controller.js",
config/types/jsconfig.search-exact.json CHANGED
@@ -20,6 +20,9 @@
20
  "../../typings/search-restoration.d.ts",
21
  "../../typings/search-results.d.ts",
22
  "../../typings/search-discovery.d.ts",
 
 
 
23
  "../../typings/search-history-ambient.d.ts",
24
  "../../static/search/history/infrastructure/store.js",
25
  "../../static/search/history/application/controller.js",
 
20
  "../../typings/search-restoration.d.ts",
21
  "../../typings/search-results.d.ts",
22
  "../../typings/search-discovery.d.ts",
23
+ "../../typings/search-shell.d.ts",
24
+ "../../static/search/shell/presentation/view.js",
25
+ "../../static/search/shell/application/controller.js",
26
  "../../typings/search-history-ambient.d.ts",
27
  "../../static/search/history/infrastructure/store.js",
28
  "../../static/search/history/application/controller.js",
config/types/jsconfig.strict.json CHANGED
@@ -73,6 +73,9 @@
73
  "../../typings/search-restoration.d.ts",
74
  "../../typings/search-results.d.ts",
75
  "../../typings/search-discovery.d.ts",
 
 
 
76
  "../../typings/search-history-ambient.d.ts",
77
  "../../static/search/history/infrastructure/store.js",
78
  "../../static/search/history/application/controller.js",
 
73
  "../../typings/search-restoration.d.ts",
74
  "../../typings/search-results.d.ts",
75
  "../../typings/search-discovery.d.ts",
76
+ "../../typings/search-shell.d.ts",
77
+ "../../static/search/shell/presentation/view.js",
78
+ "../../static/search/shell/application/controller.js",
79
  "../../typings/search-history-ambient.d.ts",
80
  "../../static/search/history/infrastructure/store.js",
81
  "../../static/search/history/application/controller.js",
eslint.config.mjs CHANGED
@@ -20,7 +20,7 @@ export default [
20
  globals: { ...globals.browser, ...globals.serviceworker, ...globals.worker,
21
  module: "readonly", require: "readonly",
22
  ...Object.fromEntries(["VoiceOfMLReaderSecurity", "VoiceOfMLReader", "VoiceOfMLReaderResources",
23
- "VoiceOfMLReaderStore", "VoiceOfMLReaderChapters", "VoiceOfMLReaderVirtual", "VoiceOfMLReaderNavigation", "VoiceOfMLReaderHost", "VoiceOfMLReaderReturn",
24
  "VoiceOfMLDownloadController", "VoiceOfMLDownloadBatch", "VoiceOfMLDownloadQueue", "VoiceOfMLSearchSession", "VoiceOfMLPositionPolicy", "VoiceOfMLPositionStorage", "VoiceOfMLSearchPositions", "VoiceOfMLPositionRestoration", "VoiceOfMLResultRows", "VoiceOfMLResultInteractions", "VoiceOfMLRandomDiscovery", "VoiceOfMLSearchHistoryStore", "VoiceOfMLSearchHistory", "VoiceOfMLQuotation", "VoiceOfMLSnapshotPolicy", "VoiceOfMLResultSnapshots", "VoiceOfMLSearchWindowPage", "VoiceOfMLReaderRequests", "VoiceOfMLReaderRuntime",
25
  "VoiceOfMLReaderAdapters", "VoiceOfMLReaderScroll", "VoiceOfMLSearchSidebarRender", "DOMPurify", "marked"]
26
  .map(name => [name, "readonly"])) }
 
20
  globals: { ...globals.browser, ...globals.serviceworker, ...globals.worker,
21
  module: "readonly", require: "readonly",
22
  ...Object.fromEntries(["VoiceOfMLReaderSecurity", "VoiceOfMLReader", "VoiceOfMLReaderResources",
23
+ "VoiceOfMLShell", "VoiceOfMLShellView", "VoiceOfMLReaderStore", "VoiceOfMLReaderChapters", "VoiceOfMLReaderVirtual", "VoiceOfMLReaderNavigation", "VoiceOfMLReaderHost", "VoiceOfMLReaderReturn",
24
  "VoiceOfMLDownloadController", "VoiceOfMLDownloadBatch", "VoiceOfMLDownloadQueue", "VoiceOfMLSearchSession", "VoiceOfMLPositionPolicy", "VoiceOfMLPositionStorage", "VoiceOfMLSearchPositions", "VoiceOfMLPositionRestoration", "VoiceOfMLResultRows", "VoiceOfMLResultInteractions", "VoiceOfMLRandomDiscovery", "VoiceOfMLSearchHistoryStore", "VoiceOfMLSearchHistory", "VoiceOfMLQuotation", "VoiceOfMLSnapshotPolicy", "VoiceOfMLResultSnapshots", "VoiceOfMLSearchWindowPage", "VoiceOfMLReaderRequests", "VoiceOfMLReaderRuntime",
25
  "VoiceOfMLReaderAdapters", "VoiceOfMLReaderScroll", "VoiceOfMLSearchSidebarRender", "DOMPurify", "marked"]
26
  .map(name => [name, "readonly"])) }
scripts/build/check_reader_release.mjs CHANGED
@@ -282,6 +282,7 @@ function crossCheck(githubRoot, hfRoot) {
282
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
283
  "search/results/presentation/row.js", "search/results/application/interactions.js",
284
  "search/discovery/application/random.js",
 
285
  "search/history/infrastructure/store.js",
286
  "search/history/application/controller.js",
287
  "search/ambient/application/quotation.js",
 
282
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
283
  "search/results/presentation/row.js", "search/results/application/interactions.js",
284
  "search/discovery/application/random.js",
285
+ "search/shell/presentation/view.js", "search/shell/application/controller.js",
286
  "search/history/infrastructure/store.js",
287
  "search/history/application/controller.js",
288
  "search/ambient/application/quotation.js",
scripts/build/compose_app.mjs CHANGED
@@ -10,6 +10,7 @@ export const APP_DEPENDENCIES = Object.freeze([
10
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
11
  "search/results/presentation/row.js", "search/results/application/interactions.js",
12
  "search/discovery/application/random.js",
 
13
  "search/history/infrastructure/store.js",
14
  "search/history/application/controller.js",
15
  "search/ambient/application/quotation.js",
 
10
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
11
  "search/results/presentation/row.js", "search/results/application/interactions.js",
12
  "search/discovery/application/random.js",
13
+ "search/shell/presentation/view.js", "search/shell/application/controller.js",
14
  "search/history/infrastructure/store.js",
15
  "search/history/application/controller.js",
16
  "search/ambient/application/quotation.js",
static/app.js CHANGED
@@ -2068,18 +2068,8 @@ function returnFromSidebar() {
2068
  navigateSidebarParent();
2069
  }
2070
 
2071
- function closeLeftSidebar() {
2072
- STATE.leftSidebarOpen = false;
2073
- setSidebarExpanded(false);
2074
- updateSidebarVisibility();
2075
- syncStateToURL(true);
2076
- }
2077
-
2078
- function closeRightSidebar() {
2079
- STATE.rightSidebarOpen = false;
2080
- updateSidebarVisibility();
2081
- syncStateToURL(true);
2082
- }
2083
  const ROUTER = {
2084
  parse() {
2085
  const path = window.location.pathname.replace(/\/+$/, "");
@@ -3683,104 +3673,38 @@ function setupQuickScroll() {
3683
  document.addEventListener("visibilitychange", () => { if (document.hidden) cancelQuickScroll(); });
3684
  }
3685
 
3686
- function toggleTheme() {
3687
- const btn = DOM.themeBtn;
3688
- const rect = btn.getBoundingClientRect();
3689
- const ripple = document.createElement("div");
3690
- ripple.className = "theme-ripple";
3691
- ripple.style.left = (rect.left + rect.width / 2) + "px";
3692
- ripple.style.top = (rect.top + rect.height / 2) + "px";
3693
- ripple.style.background = STATE.isDark ? "#fff" : "#1a1c1e";
3694
- document.body.appendChild(ripple);
3695
- document.body.classList.add("theme-transitioning");
3696
- STATE.isDark = !STATE.isDark;
3697
- applyTheme();
3698
- writeSearchPreference("theme", STATE.isDark ? "dark" : "light");
3699
- ripple.addEventListener("animationend", () => {
3700
- ripple.remove();
3701
- document.body.classList.remove("theme-transitioning");
3702
- });
3703
- }
3704
-
3705
- function applyTheme() {
3706
- DOM.themeBtn.setAttribute('aria-label', STATE.isDark ? '切换到浅色主题' : '切换到深色主题');
3707
- if (STATE.isDark) { document.body.classList.remove("light"); DOM.themeIconLight.style.display = "none"; DOM.themeIconDark.style.display = ""; }
3708
- else { document.body.classList.add("light"); DOM.themeIconLight.style.display = ""; DOM.themeIconDark.style.display = "none"; }
3709
- if (readerHost.overlay && readerHost.overlay.contentWindow) readerHost.overlay.contentWindow.postMessage({ type: "voice-reader-theme-state", theme: STATE.isDark ? "dark" : "light" }, location.origin);
3710
- }
3711
-
3712
- function toggleMobile() { STATE.isMobile = !STATE.isMobile; applyMobileMode(); writeSearchPreference("mobileMode", STATE.isMobile ? "mobile" : "desktop"); }
3713
-
3714
- function applyMobileMode() {
3715
- DOM.mobileToggleBtn.setAttribute('aria-label', STATE.isMobile ? '切换到电脑版' : '切换到手机版');
3716
- if (STATE.isMobile) {
3717
- document.body.classList.add("mobile"); document.body.classList.remove("force-desktop");
3718
- DOM.mobileIconPhone.style.display = ""; DOM.mobileIconDesktop.style.display = "none";
3719
- STATE.leftSidebarOpen = false; STATE.rightSidebarOpen = false;
3720
- } else {
3721
- document.body.classList.remove("mobile"); document.body.classList.add("force-desktop");
3722
- DOM.mobileIconPhone.style.display = "none"; DOM.mobileIconDesktop.style.display = "";
3723
- STATE.leftSidebarOpen = true; STATE.rightSidebarOpen = false;
3724
- }
3725
- updateSidebarVisibility();
3726
- document.documentElement.classList.remove("mobile-boot");
3727
- updateSidebarHeader();
3728
- updateSelectionUI();
3729
- requestAnimationFrame(updateScrollTrack);
3730
  }
3731
-
 
 
 
3732
  function autoDetectMobile() { return window.innerWidth <= 768; }
3733
-
3734
- function focusSearchSidebar(sidebar) {
3735
- const control = Array.from(sidebar.querySelectorAll('button,a[href],input,select,[tabindex="0"]'))
3736
- .find(node => !node.disabled && node.getClientRects().length && !node.closest('[hidden],[inert]'));
3737
- (control || sidebar).focus({ preventScroll: true });
3738
- }
3739
-
3740
- function toggleLeftSidebar(event) {
3741
- if (STATE.leftSidebarOpen) {
3742
- closeLeftSidebar();
3743
- return;
3744
- }
3745
- STATE.leftSidebarOpen = true;
3746
- if (STATE.isMobile && STATE.leftSidebarOpen && STATE.rightSidebarOpen) STATE.rightSidebarOpen = false;
3747
- updateSidebarVisibility();
3748
- updateSidebarHeader();
3749
- syncStateToURL(true);
3750
- if (event?.detail === 0 || event?.type === 'keydown') focusSearchSidebar(DOM.leftSidebar);
3751
- }
3752
-
3753
- function toggleRightSidebar(event) {
3754
- if (STATE.rightSidebarOpen) return closeRightSidebar();
3755
- STATE.rightSidebarOpen = true;
3756
- if (STATE.rightSidebarOpen && STATE.leftSidebarOpen && STATE.isMobile) STATE.leftSidebarOpen = false;
3757
- updateSidebarVisibility();
3758
- syncStateToURL(true);
3759
- if (event?.detail === 0 || event?.type === 'keydown') focusSearchSidebar(DOM.rightSidebar);
3760
- }
3761
-
3762
- function updateSidebarVisibility() {
3763
- const main = /** @type {HTMLElement} */ (document.querySelector('#main-content'));
3764
- const covered = STATE.isMobile && (STATE.leftSidebarOpen || STATE.rightSidebarOpen);
3765
- const focusCovered = covered && main.contains(document.activeElement);
3766
- main.inert = covered;
3767
- for (const [sidebar, button, open] of [[DOM.leftSidebar, DOM.hamburgerBtn, STATE.leftSidebarOpen],
3768
- [DOM.rightSidebar, DOM.settingsBtn, STATE.rightSidebarOpen]]) {
3769
- const restoreFocus = !open && sidebar.contains(document.activeElement);
3770
- sidebar.inert = !open;
3771
- button.setAttribute('aria-expanded', String(open));
3772
- button.setAttribute('aria-label', sidebar === DOM.leftSidebar ? (open ? '关闭仓库导航' : '打开仓库导航') :
3773
- (open ? '关闭搜索过滤' : '打开搜索过滤'));
3774
- if (restoreFocus) button.focus({ preventScroll: true });
3775
- }
3776
- DOM.leftSidebar.classList.toggle("collapsed", !STATE.leftSidebarOpen);
3777
- DOM.leftSidebar.classList.toggle("open", STATE.leftSidebarOpen);
3778
- DOM.rightSidebar.classList.toggle("collapsed", !STATE.rightSidebarOpen);
3779
- DOM.rightSidebar.classList.toggle("open", STATE.rightSidebarOpen);
3780
- DOM.overlay.style.display = "";
3781
- DOM.overlay.classList.toggle("open", STATE.isMobile && (STATE.leftSidebarOpen || STATE.rightSidebarOpen));
3782
- if (focusCovered) focusSearchSidebar(STATE.rightSidebarOpen ? DOM.rightSidebar : DOM.leftSidebar);
3783
- }
3784
  let keyboardResultIndex = -1;
3785
 
3786
  function focusKeyboardResult(index) {
 
2068
  navigateSidebarParent();
2069
  }
2070
 
2071
+ function closeLeftSidebar() { getShell().closeLeftSidebar(); }
2072
+ function closeRightSidebar() { getShell().closeRightSidebar(); }
 
 
 
 
 
 
 
 
 
 
2073
  const ROUTER = {
2074
  parse() {
2075
  const path = window.location.pathname.replace(/\/+$/, "");
 
3673
  document.addEventListener("visibilitychange", () => { if (document.hidden) cancelQuickScroll(); });
3674
  }
3675
 
3676
+ let shell = null;
3677
+ function getShell() {
3678
+ return shell || (shell = VoiceOfMLShell.create({
3679
+ readState: () => ({ isDark: STATE.isDark, isMobile: STATE.isMobile,
3680
+ leftSidebarOpen: STATE.leftSidebarOpen, rightSidebarOpen: STATE.rightSidebarOpen }),
3681
+ setDark: value => { STATE.isDark = value; },
3682
+ setMobile: value => { STATE.isMobile = value; },
3683
+ setSidebars: (left, right) => { STATE.leftSidebarOpen = left; STATE.rightSidebarOpen = right; },
3684
+ writePreference: writeSearchPreference,
3685
+ notifyReaderTheme: isDark => {
3686
+ if (readerHost.overlay && readerHost.overlay.contentWindow) readerHost.overlay.contentWindow.postMessage({ type: "voice-reader-theme-state", theme: isDark ? "dark" : "light" }, location.origin);
3687
+ },
3688
+ updateSidebarHeader, updateSelectionUI,
3689
+ scheduleScrollTrack: () => requestAnimationFrame(updateScrollTrack),
3690
+ syncURL: () => syncStateToURL(true),
3691
+ collapseLeftSidebar: () => setSidebarExpanded(false),
3692
+ view: VoiceOfMLShellView.create(() => ({ themeBtn: DOM.themeBtn, themeIconLight: DOM.themeIconLight,
3693
+ themeIconDark: DOM.themeIconDark, mobileToggleBtn: DOM.mobileToggleBtn,
3694
+ mobileIconPhone: DOM.mobileIconPhone, mobileIconDesktop: DOM.mobileIconDesktop,
3695
+ leftSidebar: DOM.leftSidebar, rightSidebar: DOM.rightSidebar, hamburgerBtn: DOM.hamburgerBtn,
3696
+ settingsBtn: DOM.settingsBtn, overlay: DOM.overlay }), false)
3697
+ }));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3698
  }
3699
+ function toggleTheme() { getShell().toggleTheme(); }
3700
+ function applyTheme() { getShell().applyTheme(); }
3701
+ function toggleMobile() { getShell().toggleMobile(); }
3702
+ function applyMobileMode() { getShell().applyMobileMode(); }
3703
  function autoDetectMobile() { return window.innerWidth <= 768; }
3704
+ function focusSearchSidebar(sidebar) { VoiceOfMLShellView.focusSearchSidebar(sidebar); }
3705
+ function toggleLeftSidebar(event) { getShell().toggleLeftSidebar(event); }
3706
+ function toggleRightSidebar(event) { getShell().toggleRightSidebar(event); }
3707
+ function updateSidebarVisibility() { getShell().updateSidebarVisibility(); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3708
  let keyboardResultIndex = -1;
3709
 
3710
  function focusKeyboardResult(index) {
static/index.html CHANGED
@@ -347,6 +347,8 @@ if ("serviceWorker" in navigator) {
347
  <script src="/static/search/results/presentation/row.js"></script>
348
  <script src="/static/search/results/application/interactions.js"></script>
349
  <script src="/static/search/discovery/application/random.js"></script>
 
 
350
  <script src="/static/search/history/infrastructure/store.js"></script>
351
  <script src="/static/search/history/application/controller.js"></script>
352
  <script src="/static/search/ambient/application/quotation.js"></script>
 
347
  <script src="/static/search/results/presentation/row.js"></script>
348
  <script src="/static/search/results/application/interactions.js"></script>
349
  <script src="/static/search/discovery/application/random.js"></script>
350
+ <script src="/static/search/shell/presentation/view.js"></script>
351
+ <script src="/static/search/shell/application/controller.js"></script>
352
  <script src="/static/search/history/infrastructure/store.js"></script>
353
  <script src="/static/search/history/application/controller.js"></script>
354
  <script src="/static/search/ambient/application/quotation.js"></script>
static/reader-resources.js CHANGED
@@ -131,6 +131,7 @@
131
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
132
  "search/results/presentation/row.js", "search/results/application/interactions.js",
133
  "search/discovery/application/random.js",
 
134
  "search/history/infrastructure/store.js",
135
  "search/history/application/controller.js",
136
  "search/ambient/application/quotation.js",
 
131
  "search/positions/domain/policy.js", "search/positions/infrastructure/indexed-db.js", "search/positions/application/persistence.js", "search/positions/application/restoration.js",
132
  "search/results/presentation/row.js", "search/results/application/interactions.js",
133
  "search/discovery/application/random.js",
134
+ "search/shell/presentation/view.js", "search/shell/application/controller.js",
135
  "search/history/infrastructure/store.js",
136
  "search/history/application/controller.js",
137
  "search/ambient/application/quotation.js",
static/search/shell/application/controller.js ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Shell transitions use a bounded state snapshot; the app owns preferences and routing.
2
+ (function () {
3
+ /** @param {VoiceOfMLShellDependencies} deps */
4
+ function create(deps) {
5
+ const view = deps.view;
6
+
7
+ function applyTheme() {
8
+ const { isDark } = deps.readState();
9
+ view.applyTheme(isDark);
10
+ deps.notifyReaderTheme(isDark);
11
+ }
12
+
13
+ function toggleTheme() {
14
+ const ripple = view.startThemeTransition(deps.readState().isDark);
15
+ deps.setDark(!deps.readState().isDark);
16
+ applyTheme();
17
+ deps.writePreference("theme", deps.readState().isDark ? "dark" : "light");
18
+ view.finishThemeTransition(ripple);
19
+ }
20
+
21
+ function updateSidebarVisibility() { view.updateSidebarVisibility(deps.readState()); }
22
+
23
+ function applyMobileMode() {
24
+ const { isMobile } = deps.readState();
25
+ view.applyMobileMode(isMobile);
26
+ deps.setSidebars(!isMobile, false);
27
+ updateSidebarVisibility();
28
+ view.finishMobileMode();
29
+ deps.updateSidebarHeader();
30
+ deps.updateSelectionUI();
31
+ deps.scheduleScrollTrack();
32
+ }
33
+
34
+ function toggleMobile() {
35
+ deps.setMobile(!deps.readState().isMobile);
36
+ applyMobileMode();
37
+ deps.writePreference("mobileMode", deps.readState().isMobile ? "mobile" : "desktop");
38
+ }
39
+
40
+ function closeLeftSidebar() {
41
+ deps.setSidebars(false, deps.readState().rightSidebarOpen);
42
+ if (deps.collapseLeftSidebar) deps.collapseLeftSidebar();
43
+ else view.collapseLeftSidebar();
44
+ updateSidebarVisibility();
45
+ deps.syncURL();
46
+ }
47
+
48
+ function closeRightSidebar() {
49
+ deps.setSidebars(deps.readState().leftSidebarOpen, false);
50
+ updateSidebarVisibility();
51
+ deps.syncURL();
52
+ }
53
+
54
+ /** @param {VoiceOfMLShellEvent} [event] */
55
+ function toggleLeftSidebar(event) {
56
+ const state = deps.readState();
57
+ if (state.leftSidebarOpen) return closeLeftSidebar();
58
+ deps.setSidebars(true, state.isMobile ? false : state.rightSidebarOpen);
59
+ updateSidebarVisibility();
60
+ deps.updateSidebarHeader();
61
+ deps.syncURL();
62
+ if (event?.detail === 0 || event?.type === 'keydown') view.focusSidebar('left');
63
+ }
64
+
65
+ /** @param {VoiceOfMLShellEvent} [event] */
66
+ function toggleRightSidebar(event) {
67
+ const state = deps.readState();
68
+ if (state.rightSidebarOpen) return closeRightSidebar();
69
+ deps.setSidebars(state.isMobile ? false : state.leftSidebarOpen, true);
70
+ updateSidebarVisibility();
71
+ deps.syncURL();
72
+ if (event?.detail === 0 || event?.type === 'keydown') view.focusSidebar('right');
73
+ }
74
+
75
+ return { toggleTheme, applyTheme, toggleMobile, applyMobileMode, toggleLeftSidebar,
76
+ toggleRightSidebar, closeLeftSidebar, closeRightSidebar, updateSidebarVisibility };
77
+ }
78
+ globalThis.VoiceOfMLShell = { create };
79
+ })();
static/search/shell/presentation/view.js ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Theme, mobile chrome and sidebar accessibility share one bounded element set.
2
+ (function () {
3
+ /** @param {HTMLElement} sidebar */
4
+ function focusSearchSidebar(sidebar) {
5
+ const control = Array.from(sidebar.querySelectorAll('button,a[href],input,select,[tabindex="0"]'))
6
+ .find(node => !(/** @type {HTMLButtonElement} */ (node)).disabled && node.getClientRects().length && !node.closest('[hidden],[inert]'));
7
+ (/** @type {HTMLElement} */ (control) || sidebar).focus({ preventScroll: true });
8
+ }
9
+
10
+ /** @param {() => VoiceOfMLShellElements} elements @param {boolean} zeroRippleMargins */
11
+ function create(elements, zeroRippleMargins) {
12
+ /** @param {boolean} isDark */
13
+ function startThemeTransition(isDark) {
14
+ const rect = elements().themeBtn.getBoundingClientRect();
15
+ const ripple = document.createElement("div");
16
+ ripple.className = "theme-ripple";
17
+ ripple.style.left = (rect.left + rect.width / 2) + "px";
18
+ ripple.style.top = (rect.top + rect.height / 2) + "px";
19
+ ripple.style.background = isDark ? "#fff" : "#1a1c1e";
20
+ if (zeroRippleMargins) {
21
+ ripple.style.marginLeft = "-0px";
22
+ ripple.style.marginTop = "-0px";
23
+ }
24
+ document.body.appendChild(ripple);
25
+ document.body.classList.add("theme-transitioning");
26
+ return ripple;
27
+ }
28
+
29
+ /** @param {HTMLElement} ripple */
30
+ function finishThemeTransition(ripple) {
31
+ ripple.addEventListener("animationend", () => {
32
+ ripple.remove();
33
+ document.body.classList.remove("theme-transitioning");
34
+ });
35
+ }
36
+
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");
43
+ el.themeIconLight.style.display = "none";
44
+ el.themeIconDark.style.display = "";
45
+ } else {
46
+ document.body.classList.add("light");
47
+ el.themeIconLight.style.display = "";
48
+ el.themeIconDark.style.display = "none";
49
+ }
50
+ }
51
+
52
+ /** @param {boolean} isMobile */
53
+ function applyMobileMode(isMobile) {
54
+ const el = elements();
55
+ el.mobileToggleBtn.setAttribute('aria-label', isMobile ? '切换到电脑版' : '切换到手机版');
56
+ if (isMobile) {
57
+ document.body.classList.add("mobile");
58
+ document.body.classList.remove("force-desktop");
59
+ el.mobileIconPhone.style.display = "";
60
+ el.mobileIconDesktop.style.display = "none";
61
+ } else {
62
+ document.body.classList.remove("mobile");
63
+ document.body.classList.add("force-desktop");
64
+ el.mobileIconPhone.style.display = "none";
65
+ el.mobileIconDesktop.style.display = "";
66
+ }
67
+ }
68
+
69
+ function finishMobileMode() { document.documentElement.classList.remove("mobile-boot"); }
70
+ function collapseLeftSidebar() { elements().leftSidebar.classList.remove("expanded-wide"); }
71
+ /** @param {'left' | 'right'} side */
72
+ function focusSidebar(side) { focusSearchSidebar(side === 'left' ? elements().leftSidebar : elements().rightSidebar); }
73
+
74
+ /** @param {VoiceOfMLShellState} state */
75
+ function updateSidebarVisibility(state) {
76
+ const el = elements();
77
+ const main = /** @type {HTMLElement} */ (document.querySelector('#main-content'));
78
+ const covered = state.isMobile && (state.leftSidebarOpen || state.rightSidebarOpen);
79
+ const focusCovered = covered && main.contains(document.activeElement);
80
+ main.inert = covered;
81
+ /** @type {Array<[HTMLElement, HTMLElement, boolean]>} */
82
+ const sidebars = [[el.leftSidebar, el.hamburgerBtn, state.leftSidebarOpen],
83
+ [el.rightSidebar, el.settingsBtn, state.rightSidebarOpen]];
84
+ for (const [sidebar, button, open] of sidebars) {
85
+ const restoreFocus = !open && sidebar.contains(document.activeElement);
86
+ sidebar.inert = !open;
87
+ button.setAttribute('aria-expanded', String(open));
88
+ button.setAttribute('aria-label', sidebar === el.leftSidebar ? (open ? '关闭仓库导航' : '打开仓库导航') :
89
+ (open ? '关闭搜索过滤' : '打开搜索过滤'));
90
+ if (restoreFocus) button.focus({ preventScroll: true });
91
+ }
92
+ el.leftSidebar.classList.toggle("collapsed", !state.leftSidebarOpen);
93
+ el.leftSidebar.classList.toggle("open", state.leftSidebarOpen);
94
+ el.rightSidebar.classList.toggle("collapsed", !state.rightSidebarOpen);
95
+ el.rightSidebar.classList.toggle("open", state.rightSidebarOpen);
96
+ el.overlay.style.display = "";
97
+ el.overlay.classList.toggle("open", state.isMobile && (state.leftSidebarOpen || state.rightSidebarOpen));
98
+ if (focusCovered) focusSearchSidebar(state.rightSidebarOpen ? el.rightSidebar : el.leftSidebar);
99
+ }
100
+
101
+ return { startThemeTransition, finishThemeTransition, applyTheme, applyMobileMode, finishMobileMode,
102
+ collapseLeftSidebar, focusSidebar, updateSidebarVisibility };
103
+ }
104
+ globalThis.VoiceOfMLShellView = { create, focusSearchSidebar };
105
+ })();
static/sw.js CHANGED
@@ -103,6 +103,8 @@ const PRECACHE_URLS = [
103
  "/static/search/results/presentation/row.js",
104
  "/static/search/results/application/interactions.js",
105
  "/static/search/discovery/application/random.js",
 
 
106
  "/static/search/history/infrastructure/store.js",
107
  "/static/search/history/application/controller.js",
108
  "/static/search/ambient/application/quotation.js",
 
103
  "/static/search/results/presentation/row.js",
104
  "/static/search/results/application/interactions.js",
105
  "/static/search/discovery/application/random.js",
106
+ "/static/search/shell/presentation/view.js",
107
+ "/static/search/shell/application/controller.js",
108
  "/static/search/history/infrastructure/store.js",
109
  "/static/search/history/application/controller.js",
110
  "/static/search/ambient/application/quotation.js",
tests/gates/test_static_contract.py CHANGED
@@ -188,6 +188,7 @@ class StaticFrontendContractTests(unittest.TestCase):
188
  cls.result_rows = (ROOT / "static/search/results/presentation/row.js").read_text(encoding="utf-8")
189
  cls.result_interactions = (ROOT / "static/search/results/application/interactions.js").read_text(encoding="utf-8")
190
  cls.random_discovery = (ROOT / "static/search/discovery/application/random.js").read_text(encoding="utf-8")
 
191
  cls.css = (ROOT / "static/style.css").read_text(encoding="utf-8")
192
  cls.sw = (ROOT / "static/sw.js").read_text(encoding="utf-8")
193
 
@@ -669,7 +670,11 @@ console.log('Chapter adapter contract passed; 5 negative controls rejected');
669
  def test_mobile_shell_hides_sidebars_before_application_startup(self):
670
  self.assertIn('document.documentElement.classList.add("mobile-boot")', self.html)
671
  self.assertIn('html.mobile-boot .left-sidebar', self.css)
672
- self.assertIn('document.documentElement.classList.remove("mobile-boot")', self.js)
 
 
 
 
673
 
674
  def test_js_has_warm_connection_keepalive(self):
675
  for value in ('function warmConnection', '/api/ping', 'keepalivePending', 'KEEPALIVE_INTERVAL_MS', 'KEEPALIVE_MIN_GAP_MS', 'document.hidden || !navigator.onLine', 'warmConnection(true)'):
 
188
  cls.result_rows = (ROOT / "static/search/results/presentation/row.js").read_text(encoding="utf-8")
189
  cls.result_interactions = (ROOT / "static/search/results/application/interactions.js").read_text(encoding="utf-8")
190
  cls.random_discovery = (ROOT / "static/search/discovery/application/random.js").read_text(encoding="utf-8")
191
+ cls.shell_view = (ROOT / "static/search/shell/presentation/view.js").read_text(encoding="utf-8")
192
  cls.css = (ROOT / "static/style.css").read_text(encoding="utf-8")
193
  cls.sw = (ROOT / "static/sw.js").read_text(encoding="utf-8")
194
 
 
670
  def test_mobile_shell_hides_sidebars_before_application_startup(self):
671
  self.assertIn('document.documentElement.classList.add("mobile-boot")', self.html)
672
  self.assertIn('html.mobile-boot .left-sidebar', self.css)
673
+ self.assertIn('document.documentElement.classList.remove("mobile-boot")', self.shell_view)
674
+ self.assertIn('function applyMobileMode() { getShell().applyMobileMode(); }', self.js)
675
+ self.assertIn('view: VoiceOfMLShellView.create(', self.js)
676
+ shell_controller = (ROOT / "static/search/shell/application/controller.js").read_text(encoding="utf-8")
677
+ self.assertRegex(shell_controller, r'updateSidebarVisibility\(\);\s*view\.finishMobileMode\(\);\s*deps\.updateSidebarHeader\(\);\s*deps\.updateSelectionUI\(\);\s*deps\.scheduleScrollTrack\(\);')
678
 
679
  def test_js_has_warm_connection_keepalive(self):
680
  for value in ('function warmConnection', '/api/ping', 'keepalivePending', 'KEEPALIVE_INTERVAL_MS', 'KEEPALIVE_MIN_GAP_MS', 'document.hidden || !navigator.onLine', 'warmConnection(true)'):
tests/search/ui/shell_contracts.mjs ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import vm from 'node:vm';
4
+ import test from 'node:test';
5
+ import {createRequire} from 'node:module';
6
+ import {APP_DEPENDENCIES, stripBundledScripts} from '../../../scripts/build/compose_app.mjs';
7
+
8
+ const names = ['search/shell/presentation/view.js', 'search/shell/application/controller.js'];
9
+ const app = fs.readFileSync('static/app.js', 'utf8');
10
+ const space = fs.existsSync('pyrightconfig.json');
11
+ const functions = ['getShell', 'toggleTheme', 'applyTheme', 'toggleMobile', 'applyMobileMode',
12
+ 'focusSearchSidebar', 'toggleLeftSidebar', 'toggleRightSidebar', 'closeLeftSidebar',
13
+ 'closeRightSidebar', 'updateSidebarVisibility'];
14
+
15
+ function fixture() {
16
+ const events = [], nodes = [], frames = [], messages = [];
17
+ const document = {activeElement: null};
18
+ function element(name, parent = null) {
19
+ const classes = new Set(), attributes = {}, listeners = {};
20
+ const node = {name, parent, classes, attributes, listeners, disabled: false, hidden: false, inert: false,
21
+ style: {}, controls: [],
22
+ classList: {add: value => classes.add(value), remove: value => classes.delete(value),
23
+ toggle(value, on) { if (on) classes.add(value); else classes.delete(value); }},
24
+ setAttribute(key, value) { attributes[key] = value; events.push([name, key, value]); },
25
+ contains(other) { return !!other && (other === node || node.contains(other.parent)); },
26
+ focus(options) { assert.equal(options.preventScroll, true); document.activeElement = node; events.push(['focus', name]); },
27
+ querySelectorAll() { return node.controls; },
28
+ getClientRects() { return node.hidden ? [] : [{}]; },
29
+ closest() { for (let el = node; el; el = el.parent) if (el.hidden || el.inert) return el; return null; },
30
+ getBoundingClientRect() { return {left: 10, top: 20, width: 40, height: 60}; },
31
+ appendChild(child) { child.parent = node; nodes.push(child); events.push(['append', child.className]); },
32
+ addEventListener(type, fn) { listeners[type] = fn; events.push(['listen', type]); },
33
+ remove() { node.removed = true; }
34
+ };
35
+ return node;
36
+ }
37
+ const DOM = Object.fromEntries(['themeBtn', 'themeIconLight', 'themeIconDark', 'mobileToggleBtn',
38
+ 'mobileIconPhone', 'mobileIconDesktop', 'leftSidebar', 'rightSidebar', 'hamburgerBtn', 'settingsBtn', 'overlay']
39
+ .map(name => [name, element(name)]));
40
+ const main = element('main'), mainControl = element('mainControl', main);
41
+ const leftControl = element('leftControl', DOM.leftSidebar), rightControl = element('rightControl', DOM.rightSidebar);
42
+ DOM.leftSidebar.controls = [leftControl]; DOM.rightSidebar.controls = [rightControl];
43
+ document.body = element('body'); document.documentElement = element('html');
44
+ document.querySelector = selector => { assert.equal(selector, '#main-content'); return main; };
45
+ document.createElement = () => element('ripple');
46
+ const c = vm.createContext({shell: null, DOM, document,
47
+ STATE: {isDark: true, isMobile: false, leftSidebarOpen: true, rightSidebarOpen: false},
48
+ readerHost: {overlay: {contentWindow: {postMessage(message, origin) {
49
+ messages.push(JSON.parse(JSON.stringify([message, origin]))); events.push(['reader', message.theme]);
50
+ }}}}, location: {origin: 'https://shell.test'},
51
+ writeSearchPreference: (...args) => events.push(['preference', ...args]),
52
+ syncStateToURL: (...args) => events.push(['url', ...args]),
53
+ updateSidebarHeader: () => events.push(['header']), updateSelectionUI: () => events.push(['selection']),
54
+ updateScrollTrack: () => events.push(['scroll']),
55
+ requestAnimationFrame: fn => { frames.push(fn); events.push(['frame']); },
56
+ setSidebarExpanded: value => { DOM.leftSidebar.classList.toggle('expanded-wide', value); events.push(['header']); }
57
+ });
58
+ for (const name of names) vm.runInContext(fs.readFileSync('static/' + name, 'utf8'), c);
59
+ for (const name of functions) {
60
+ const match = app.match(new RegExp('^function ' + name + '\\([^]*?^}', 'm'));
61
+ // Single-line forwarding functions must not consume the following function.
62
+ const single = app.match(new RegExp('^function ' + name + '\\([^\\n]*\\}\\s*$', 'm'));
63
+ assert.ok(single || match, name); vm.runInContext((single || match)[0], c);
64
+ }
65
+ return {c, events, nodes, frames, messages, document, DOM, main, mainControl, leftControl, rightControl, element};
66
+ }
67
+
68
+ test('shell modules are registered once in source, bundle, offline, resources and strict projects', () => {
69
+ const html = fs.readFileSync('static/index.html', 'utf8');
70
+ const resources = createRequire(import.meta.url)('../../../static/reader-resources.js');
71
+ for (const name of names) {
72
+ assert.equal(APP_DEPENDENCIES.filter(item => item === name).length, 1);
73
+ assert.equal(html.split(name).length - 1, 1);
74
+ assert.ok(html.indexOf(name) < html.lastIndexOf('app.js'));
75
+ assert.ok(!stripBundledScripts(html).includes(name));
76
+ for (const project of ['github', 'hf']) assert.equal(resources.buildFiles(project).filter(item => item === name).length, 1);
77
+ assert.equal(fs.readFileSync('static/sw.js', 'utf8').split('/static/' + name).length - 1, 1);
78
+ for (const project of ['check', 'strict', 'search-exact']) {
79
+ const files = JSON.parse(fs.readFileSync(`config/types/jsconfig.${project}.json`, 'utf8')).files;
80
+ assert.ok(files.includes('../../static/' + name));
81
+ assert.ok(files.includes('../../typings/search-shell.d.ts'));
82
+ }
83
+ assert.doesNotMatch(fs.readFileSync('static/' + name, 'utf8'), /\bSTATE\b|\bDOM\b|\bVSCROLL\b|syncStateToURL|localStorage/);
84
+ }
85
+ });
86
+
87
+ test('theme ripple, reader message, persistence and animation cleanup retain ordering', () => {
88
+ const f = fixture();
89
+ f.c.toggleTheme();
90
+ assert.equal(f.c.STATE.isDark, false);
91
+ assert.equal(f.document.body.classes.has('light'), true);
92
+ assert.equal(f.DOM.themeIconDark.style.display, 'none');
93
+ assert.deepEqual(f.messages, [[{type: 'voice-reader-theme-state', theme: 'light'}, 'https://shell.test']]);
94
+ assert.deepEqual(f.events.slice(-3), [['reader', 'light'], ['preference', 'theme', 'light'], ['listen', 'animationend']]);
95
+ const ripple = f.nodes[0];
96
+ assert.equal(ripple.style.left, '30px'); assert.equal(ripple.style.top, '50px');
97
+ assert.equal(ripple.style.background, '#fff');
98
+ assert.equal(ripple.style.marginLeft, space ? undefined : '-0px');
99
+ ripple.listeners.animationend();
100
+ assert.equal(ripple.removed, true); assert.equal(f.document.body.classes.has('theme-transitioning'), false);
101
+ f.c.readerHost.overlay = null; f.events.length = 0; f.c.applyTheme();
102
+ assert.ok(!f.events.some(event => event[0] === 'preference'));
103
+ f.c.toggleTheme(); assert.equal(f.c.STATE.isDark, true);
104
+ assert.equal(f.nodes[1].style.background, '#1a1c1e');
105
+ assert.equal(f.document.body.classes.has('light'), false);
106
+ });
107
+
108
+ test('mobile defaults apply before header, selection, scheduled scroll and preference write', () => {
109
+ const f = fixture(); f.document.documentElement.classes.add('mobile-boot');
110
+ f.c.STATE.rightSidebarOpen = true; f.c.toggleMobile();
111
+ assert.equal(f.c.STATE.isMobile, true);
112
+ assert.equal(f.c.STATE.leftSidebarOpen, false); assert.equal(f.c.STATE.rightSidebarOpen, false);
113
+ assert.equal(f.document.body.classes.has('mobile'), true);
114
+ assert.equal(f.document.documentElement.classes.has('mobile-boot'), false);
115
+ assert.deepEqual(f.events.slice(-4), [['header'], ['selection'], ['frame'], ['preference', 'mobileMode', 'mobile']]);
116
+ assert.equal(f.frames[0], f.c.updateScrollTrack);
117
+ assert.ok(!f.events.some(event => event[0] === 'scroll' || event[0] === 'url'));
118
+ f.c.toggleMobile();
119
+ assert.equal(f.c.STATE.leftSidebarOpen, true); assert.equal(f.c.STATE.rightSidebarOpen, false);
120
+ assert.equal(f.document.body.classes.has('force-desktop'), true);
121
+ f.events.length = 0; f.c.applyMobileMode();
122
+ assert.ok(!f.events.some(event => event[0] === 'preference'));
123
+ });
124
+
125
+ test('sidebar event detail and keyboard rules focus only after URL sync, preserving site route mode', () => {
126
+ for (const side of ['Left', 'Right']) for (const event of [undefined, {detail: 1}, {detail: 0}, {type: 'keydown'}]) {
127
+ const f = fixture(); f.c.STATE.leftSidebarOpen = false;
128
+ f.c['toggle' + side + 'Sidebar'](event);
129
+ const keyboard = event?.detail === 0 || event?.type === 'keydown';
130
+ const tail = [...(side === 'Left' ? [['header']] : []), ['url', ...(space ? [true] : [])],
131
+ ...(keyboard ? [['focus', side === 'Left' ? 'leftControl' : 'rightControl']] : [])];
132
+ assert.deepEqual(f.events.slice(-tail.length), tail);
133
+ assert.equal(f.document.activeElement, keyboard ? (side === 'Left' ? f.leftControl : f.rightControl) : null);
134
+ }
135
+ });
136
+
137
+ test('mobile coverage, mutually exclusive sidebars, inert, ARIA and focus restoration stay synchronized', () => {
138
+ const f = fixture(); f.c.STATE.isMobile = true; f.c.applyMobileMode();
139
+ f.document.activeElement = f.mainControl; f.c.toggleLeftSidebar({detail: 1});
140
+ assert.equal(f.main.inert, true); assert.equal(f.document.activeElement, f.leftControl);
141
+ assert.equal(f.DOM.leftSidebar.inert, false); assert.equal(f.DOM.rightSidebar.inert, true);
142
+ assert.equal(f.DOM.hamburgerBtn.attributes['aria-expanded'], 'true');
143
+ assert.equal(f.DOM.hamburgerBtn.attributes['aria-label'], '关闭仓库导航');
144
+ assert.equal(f.DOM.overlay.classes.has('open'), true);
145
+ f.c.toggleRightSidebar({detail: 0});
146
+ assert.equal(f.c.STATE.leftSidebarOpen, false); assert.equal(f.document.activeElement, f.rightControl);
147
+ assert.equal(f.DOM.leftSidebar.inert, true); assert.equal(f.DOM.settingsBtn.attributes['aria-expanded'], 'true');
148
+ f.c.closeRightSidebar();
149
+ assert.equal(f.document.activeElement, f.DOM.settingsBtn); assert.equal(f.main.inert, false);
150
+ assert.equal(f.DOM.overlay.classes.has('open'), false);
151
+ assert.equal(f.DOM.settingsBtn.attributes['aria-label'], '打开搜索过滤');
152
+ f.c.toggleLeftSidebar({type: 'keydown'}); f.DOM.leftSidebar.classes.add('expanded-wide');
153
+ f.events.length = 0; f.c.toggleLeftSidebar();
154
+ assert.equal(f.DOM.leftSidebar.classes.has('expanded-wide'), false);
155
+ assert.equal(f.document.activeElement, f.DOM.hamburgerBtn);
156
+ assert.deepEqual(f.events.at(-1), ['url', ...(space ? [true] : [])]);
157
+ assert.equal(f.events.filter(event => event[0] === 'header').length, space ? 1 : 0);
158
+ if (space) assert.deepEqual(f.events[0], ['header']);
159
+ });
160
+
161
+ test('sidebar focus skips disabled, invisible and hidden or inert controls and falls back to the sidebar', () => {
162
+ const f = fixture(), sidebar = f.DOM.leftSidebar;
163
+ const disabled = f.element('disabled', sidebar); disabled.disabled = true;
164
+ const invisible = f.element('invisible', sidebar); invisible.hidden = true;
165
+ const inertParent = f.element('inertParent', sidebar); inertParent.inert = true;
166
+ const inert = f.element('inert', inertParent);
167
+ sidebar.controls = [disabled, invisible, inert, f.leftControl];
168
+ f.c.focusSearchSidebar(sidebar); assert.equal(f.document.activeElement, f.leftControl);
169
+ sidebar.controls.pop(); f.c.focusSearchSidebar(sidebar); assert.equal(f.document.activeElement, sidebar);
170
+ });
tests/search/ui/test_sidebar_directory.mjs CHANGED
@@ -1,6 +1,7 @@
1
  import './result_interactions_contracts.mjs';
2
  import './random_discovery_contracts.mjs';
3
  import './history_quotation_contracts.mjs';
 
4
  import assert from 'node:assert/strict';
5
  import fs from 'node:fs';
6
  import vm from 'node:vm';
 
1
  import './result_interactions_contracts.mjs';
2
  import './random_discovery_contracts.mjs';
3
  import './history_quotation_contracts.mjs';
4
+ import './shell_contracts.mjs';
5
  import assert from 'node:assert/strict';
6
  import fs from 'node:fs';
7
  import vm from 'node:vm';
tests/support/classic_search_modules.js CHANGED
@@ -9,6 +9,7 @@ const MODULES = ["static/search/execution/domain/policy.js", "static/search/exec
9
  "static/search/positions/domain/policy.js", "static/search/positions/infrastructure/indexed-db.js", "static/search/positions/application/persistence.js", "static/search/positions/application/restoration.js",
10
  "static/search/results/presentation/row.js", "static/search/results/application/interactions.js",
11
  "static/search/discovery/application/random.js",
 
12
  "static/search/history/infrastructure/store.js", "static/search/history/application/controller.js",
13
  "static/search/ambient/application/quotation.js",
14
  "static/search/results/snapshots/domain/copy-budget.js", "static/search/results/snapshots/application/store.js",
 
9
  "static/search/positions/domain/policy.js", "static/search/positions/infrastructure/indexed-db.js", "static/search/positions/application/persistence.js", "static/search/positions/application/restoration.js",
10
  "static/search/results/presentation/row.js", "static/search/results/application/interactions.js",
11
  "static/search/discovery/application/random.js",
12
+ "static/search/shell/presentation/view.js", "static/search/shell/application/controller.js",
13
  "static/search/history/infrastructure/store.js", "static/search/history/application/controller.js",
14
  "static/search/ambient/application/quotation.js",
15
  "static/search/results/snapshots/domain/copy-budget.js", "static/search/results/snapshots/application/store.js",
typings/search-shell.d.ts ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ interface VoiceOfMLShellState {
2
+ isDark: boolean; isMobile: boolean; leftSidebarOpen: boolean; rightSidebarOpen: boolean;
3
+ }
4
+ interface VoiceOfMLShellEvent { detail?: number; type?: string }
5
+ interface VoiceOfMLShellElements {
6
+ themeBtn: HTMLElement; themeIconLight: HTMLElement; themeIconDark: HTMLElement;
7
+ mobileToggleBtn: HTMLElement; mobileIconPhone: HTMLElement; mobileIconDesktop: HTMLElement;
8
+ leftSidebar: HTMLElement; rightSidebar: HTMLElement; hamburgerBtn: HTMLElement;
9
+ settingsBtn: HTMLElement; overlay: HTMLElement;
10
+ }
11
+ interface VoiceOfMLShellViewInstance {
12
+ startThemeTransition(isDark: boolean): HTMLElement;
13
+ finishThemeTransition(ripple: HTMLElement): void;
14
+ applyTheme(isDark: boolean): void;
15
+ applyMobileMode(isMobile: boolean): void;
16
+ finishMobileMode(): void;
17
+ collapseLeftSidebar(): void;
18
+ focusSidebar(side: 'left' | 'right'): void;
19
+ updateSidebarVisibility(state: VoiceOfMLShellState): void;
20
+ }
21
+ interface VoiceOfMLShellDependencies {
22
+ view: VoiceOfMLShellViewInstance;
23
+ readState(): VoiceOfMLShellState;
24
+ setDark(value: boolean): void;
25
+ setMobile(value: boolean): void;
26
+ setSidebars(left: boolean, right: boolean): void;
27
+ writePreference(key: 'theme' | 'mobileMode', value: string): void;
28
+ notifyReaderTheme(isDark: boolean): void;
29
+ updateSidebarHeader(): void;
30
+ updateSelectionUI(): void;
31
+ scheduleScrollTrack(): void;
32
+ syncURL(): void;
33
+ collapseLeftSidebar?(): void;
34
+ }
35
+ declare var VoiceOfMLShellView: {
36
+ create(elements: () => VoiceOfMLShellElements, zeroRippleMargins: boolean): VoiceOfMLShellViewInstance;
37
+ focusSearchSidebar(sidebar: HTMLElement): void;
38
+ };
39
+ declare var VoiceOfMLShell: { create(deps: VoiceOfMLShellDependencies): {
40
+ toggleTheme(): void; applyTheme(): void; toggleMobile(): void; applyMobileMode(): void;
41
+ toggleLeftSidebar(event?: VoiceOfMLShellEvent): void;
42
+ toggleRightSidebar(event?: VoiceOfMLShellEvent): void;
43
+ closeLeftSidebar(): void; closeRightSidebar(): void; updateSidebarVisibility(): void;
44
+ }};