From ca89a02c8947bda7660f1996614a7d012f060fdc Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 15 Nov 2026 21:46:08 -0500 Subject: [PATCH 1/3] Use the top sheet for the album badge and seek slider on every screen The badge and seek slider fold into the slide-down top sheet on tablets and desktop browsers too, not only on phones. The top sheet gets its own switch (, currently "all", published as html.top-sheet) separate from the phone layout's, which still governs the bottom sheet. In the sheet the badge is one line (slide count first, then the reindex button and album pulldown), the slider padding is trimmed, and a selected cluster colours only the slide count and cluster name rather than the whole badge. Co-Authored-By: Claude Opus 5.5 --- photomap/frontend/static/css/grid-view.css | 10 ++- .../frontend/static/css/mobile-sheets.css | 79 ++++++++++++------ .../static/javascript/metadata-drawer.js | 3 +- .../static/javascript/mobile-sheets.js | 80 +++++++++++++++---- .../static/javascript/score-display.js | 43 +++++++--- .../frontend/static/javascript/seek-slider.js | 4 +- photomap/frontend/templates/main.html | 7 ++ tests/frontend/metadata-drawer-sheet.test.js | 1 + tests/frontend/mobile-sheets.test.js | 64 ++++++++++++++- tests/frontend/score-display.test.js | 28 +++++++ tests/frontend/seek-slider-sheet.test.js | 3 +- 11 files changed, 264 insertions(+), 58 deletions(-) diff --git a/photomap/frontend/static/css/grid-view.css b/photomap/frontend/static/css/grid-view.css index 3aa19199..275d0947 100644 --- a/photomap/frontend/static/css/grid-view.css +++ b/photomap/frontend/static/css/grid-view.css @@ -8,14 +8,18 @@ height: calc(var(--visible-viewport-height, 100dvh) - var(--grid-top-reserve)); } -/* In the phone layout the badge is in the top sheet, which covers the grid - only by its handle unless the user pulls it open to seek. The bottom sheet +/* With the badge in the top sheet, the sheet covers the grid only by its + handle unless the user pulls it open to seek. */ +.top-sheet #gridViewSwiper { + --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); +} + +/* In the phone layout the bottom sheet is another matter: open, it is two rows of buttons tall, and Swiper divides the container's height between the grid rows, so the container has to stop above it. --bottom-sheet-height follows the sheet as it opens and closes (mobile-sheets.js), and grid-view.js re-counts the rows when it does. */ .mobile-sheets #gridViewSwiper { - --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); height: calc( var(--visible-viewport-height, 100dvh) - var(--grid-top-reserve) - var(--bottom-sheet-height, 0px) - 6px ); diff --git a/photomap/frontend/static/css/mobile-sheets.css b/photomap/frontend/static/css/mobile-sheets.css index f685e18a..54df7b50 100644 --- a/photomap/frontend/static/css/mobile-sheets.css +++ b/photomap/frontend/static/css/mobile-sheets.css @@ -7,7 +7,11 @@ holds the metadata drawer's contents below the panels: at the expanded stop only their title row shows, and its third, "details" stop opens them. - Everything here is keyed off html.mobile-sheets, set from the media query in + The top sheet has its own switch, html.top-sheet (main.html's + ), which is currently on everywhere: tablets + and desktop browsers get the top sheet too, but not the bottom one. + + Everything else here is keyed off html.mobile-sheets, set from the media query in main.html's , and the sheet states off html[data-top-sheet] / html[data-bottom-sheet]. This file loads after the panel and slider stylesheets, so at equal specificity its rules win. */ @@ -36,7 +40,8 @@ /* ----- Common to both sheets ----- */ -.mobile-sheets .mobile-sheet { +.mobile-sheets #panelStackContainer, +.top-sheet #topSheetContainer { position: fixed; left: 0; right: 0; @@ -51,15 +56,18 @@ pointer-events: auto; } -.mobile-sheets.sheets-ready .mobile-sheet { +.mobile-sheets.sheets-ready #panelStackContainer, +.top-sheet.sheets-ready #topSheetContainer { transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); } -.mobile-sheets.sheets-ready .mobile-sheet.sheet-dragging { +.mobile-sheets.sheets-ready #panelStackContainer.sheet-dragging, +.top-sheet.sheets-ready #topSheetContainer.sheet-dragging { transition: none; } -.mobile-sheets .sheet-handle { +.mobile-sheets #bottomSheetHandle, +.top-sheet #topSheetHandle { display: flex; align-items: center; justify-content: center; @@ -74,7 +82,8 @@ } /* The pill. */ -.mobile-sheets .sheet-handle::before { +.mobile-sheets #bottomSheetHandle::before, +.top-sheet #topSheetHandle::before { content: ""; width: 40px; height: 5px; @@ -82,14 +91,16 @@ background: var(--sheet-handle-color); } -.mobile-sheets .sheet-handle:focus-visible { +.mobile-sheets #bottomSheetHandle:focus-visible, +.top-sheet #topSheetHandle:focus-visible { outline: 2px solid #fff; outline-offset: -2px; } /* Hidden with the rest of the controls in fullscreen. (:is() keeps an unknown prefixed pseudo-class from dropping the rule; see seek-slider.css.) */ -html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) .mobile-sheet { +html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #panelStackContainer, +html.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { display: none !important; } @@ -321,7 +332,7 @@ html.mobile-sheets[data-bottom-sheet="expanded"] #panelStackContainer { /* ----- Top sheet: album badge and seek slider ----- */ -.mobile-sheets #topSheetContainer { +.top-sheet #topSheetContainer { top: 0; /* Under the semantic map (1000), as the badge always was, so the map's titlebar is not covered; above the photo and grid. */ @@ -329,60 +340,82 @@ html.mobile-sheets[data-bottom-sheet="expanded"] #panelStackContainer { display: flex; flex-direction: column; align-items: stretch; - padding: 6px 0 0; + padding: 4px 0 0; border-radius: 0 0 14px 14px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35); } -html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { +html.top-sheet[data-top-sheet="collapsed"] #topSheetContainer { transform: translateY(calc(-100% + var(--top-sheet-peek))); } /* The badge keeps its own pill (it carries the cluster colour) but sits in the - sheet instead of floating over the corner of the photo. */ -.mobile-sheets .fixed-score-display { + sheet instead of floating over the corner of the photo. Its two lines become + one, the slide counter ahead of the reindex button and album pulldown, to + keep the sheet short. */ +.top-sheet .fixed-score-display { position: static; align-self: flex-start; max-width: calc(100% - 16px); margin: 0 8px; box-shadow: none; order: 1; + flex-direction: row; + align-items: center; + gap: 8px; +} + +.top-sheet .album-badge-row { + flex: 0 1 auto; +} + +.top-sheet .fixed-score-display #scoreText { + order: -1; + flex: 0 1 auto; + padding: 2px 4px; + border-radius: 8px; +} + +/* A selected cluster colours the slide count and cluster name only + (score-display.js), as a pill of their own. */ +.top-sheet .fixed-score-display #scoreText.cluster-colored { + padding: 2px 8px; } /* The slider gets the full width of the sheet, under the badge. seek-slider.js leaves its left edge alone in this layout. Room is left at the sides for the end tick labels, which centre on the slider's ends, and below for the tick row, which hangs under the slider. */ -.mobile-sheets .score-slider-row { +.top-sheet .score-slider-row { position: static; left: auto; right: auto; order: 2; - margin: 10px 0 0; - padding: 0 32px 34px; + margin: 0; + padding: 0 32px 26px; transition: none; } -.mobile-sheets .slider-with-ticks-container { +.top-sheet .slider-with-ticks-container { min-width: 0; } /* Drag the thumb, not the sheet: make the slider a comfortable target. */ -.mobile-sheets .slide-seek-slider { +.top-sheet .slide-seek-slider { height: 28px; } /* No caption beside the slider, and no hover zone: the sheet opens and closes the slider here, and the zone, which hangs 20px below the slider row, would sit over the handle and swallow taps meant for it. */ -.mobile-sheets .context-label, -.mobile-sheets .slider-hover-zone { +.top-sheet .context-label, +.top-sheet .slider-hover-zone { display: none; } /* Ten date labels do not fit across a phone held upright; show every other. */ @media (max-width: 600px) { - .mobile-sheets .slider-tick:nth-child(even) .slider-tick-label { + .top-sheet .slider-tick:nth-child(even) .slider-tick-label { visibility: hidden; } } @@ -390,7 +423,7 @@ html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { /* The progress strip is what remains of the slider when the sheet is collapsed: it sits on the sheet's bottom edge, above the handle, and is part of the target that opens the sheet rather than a hover target of its own. */ -.mobile-sheets .slider-hover-strip { +.top-sheet .slider-hover-strip { position: static; order: 3; flex: 0 0 4px; @@ -399,7 +432,7 @@ html.mobile-sheets[data-top-sheet="collapsed"] #topSheetContainer { pointer-events: none; } -.mobile-sheets #topSheetHandle { +.top-sheet #topSheetHandle { order: 4; height: calc(var(--top-sheet-peek) - 4px); } diff --git a/photomap/frontend/static/javascript/metadata-drawer.js b/photomap/frontend/static/javascript/metadata-drawer.js index de26202d..9d3e8add 100644 --- a/photomap/frontend/static/javascript/metadata-drawer.js +++ b/photomap/frontend/static/javascript/metadata-drawer.js @@ -17,6 +17,7 @@ import { applyRefTarget } from "./invoke-ref-target.js"; import { closeSheetDetails, isMobileSheetsMode, + isTopSheetMode, setSheetState, SHEET_DETAILS, sheetState, @@ -642,7 +643,7 @@ function drawerRestingTop() { // In the phone layout the badge rides in the top sheet, and measuring it // mid-slide would catch the sheet part-way. Clear the sheet in the state it // is settling to instead; it reports a change whenever that moves. - if (isMobileSheetsMode()) { + if (isTopSheetMode()) { return Math.round(sheetVisibleHeight("top") + DRAWER_TOP_GAP); } const badge = document.getElementById("fixedScoreDisplay"); diff --git a/photomap/frontend/static/javascript/mobile-sheets.js b/photomap/frontend/static/javascript/mobile-sheets.js index cd853f29..281f8b66 100644 --- a/photomap/frontend/static/javascript/mobile-sheets.js +++ b/photomap/frontend/static/javascript/mobile-sheets.js @@ -20,6 +20,13 @@ // An inline script in main.html's sets all three before first paint; // this module keeps them current afterwards. // +// The top sheet has a switch of its own: the media query in +// and the `top-sheet` class on . It is +// currently "all", so the badge and slider sit in the top sheet on every +// screen, tablets and desktop browsers included, while the bottom sheet (and +// the details in it) is still for phones only. Wherever the phone layout is on +// the top sheet must be too: its rules lean on --top-sheet-peek. +// // Listeners learn about changes from a `mobileSheetChanged` window event, // detail { sheet: "top" | "bottom", state, expanded, mobile }, where state is // "collapsed", "expanded" or (bottom only) "details", and expanded is true for @@ -28,6 +35,8 @@ const FALLBACK_QUERY = "(max-width: 600px), (max-height: 500px) and (pointer: coarse)"; const MODE_CLASS = "mobile-sheets"; +const TOP_FALLBACK_QUERY = "all"; +const TOP_MODE_CLASS = "top-sheet"; const DRAGGING_CLASS = "sheet-dragging"; const BOTTOM_STATE_KEY = "bottomSheetState"; @@ -70,6 +79,22 @@ export function isMobileSheetsMode() { return document.documentElement.classList.contains(MODE_CLASS); } +/** The media query that puts the badge and slider in the top sheet. */ +export function topSheetQuery() { + const meta = document.querySelector('meta[name="top-sheet-query"]'); + return meta?.content || TOP_FALLBACK_QUERY; +} + +/** Are the badge and seek slider in the top sheet? */ +export function isTopSheetMode() { + return document.documentElement.classList.contains(TOP_MODE_CLASS); +} + +/** Is the named sheet's layout in effect? */ +function sheetModeActive(name) { + return name === "top" ? isTopSheetMode() : isMobileSheetsMode(); +} + // mobile-sheets.css hides both sheets while the page is fullscreen. function sheetsHiddenByFullscreen() { return Boolean(document.fullscreenElement || document.webkitFullscreenElement); @@ -148,6 +173,11 @@ class Sheet { this.onScrollerTouchMove = this.onScrollerTouchMove.bind(this); } + /** Is this sheet's layout in effect? */ + active() { + return sheetModeActive(this.name); + } + /** "collapsed", "expanded" or, for a sheet with details, "details". */ get state() { const value = document.documentElement.dataset[this.attribute]; @@ -184,7 +214,7 @@ class Sheet { * the details under their title row, which hang below the window there. */ detailsOffset() { - if (!this.details || !isMobileSheetsMode() || !this.details.slot.contains(this.details.banner)) { + if (!this.details || !this.active() || !this.details.slot.contains(this.details.banner)) { return 0; } const { slot } = this.details; @@ -221,7 +251,7 @@ class Sheet { * expanded height: what is under the sheet does not reflow as it opens. */ visibleHeight() { - if (!isMobileSheetsMode() || sheetsHiddenByFullscreen()) { + if (!this.active() || sheetsHiddenByFullscreen()) { return 0; } if (!this.expanded) { @@ -288,7 +318,8 @@ class Sheet { sheet: this.name, state, expanded: state !== SHEET_COLLAPSED, - mobile: isMobileSheetsMode(), + // Whether this sheet's layout is in effect. + mobile: this.active(), }, }) ); @@ -314,7 +345,7 @@ class Sheet { * slid out of view, and say on the handle which way it goes. */ syncAccessibility() { - const mobile = isMobileSheetsMode(); + const mobile = this.active(); const state = this.state; const hidden = mobile && state === SHEET_COLLAPSED; for (const child of this.element.children) { @@ -351,7 +382,7 @@ class Sheet { } onPointerDown(event) { - if (!isMobileSheetsMode() || !event.isPrimary) { + if (!this.active() || !event.isPrimary) { return; } if (event.pointerType === "mouse" && event.button !== 0) { @@ -547,7 +578,7 @@ class Sheet { } onClick(event) { - if (!isMobileSheetsMode()) { + if (!this.active()) { return; } const state = this.state; @@ -578,7 +609,7 @@ function publishSheetHeights() { const mobile = isMobileSheetsMode(); for (const sheet of Object.values(sheets)) { const property = `--${sheet.name}-sheet-height`; - if (mobile) { + if (sheet.active()) { root.style.setProperty(property, `${Math.round(sheet.visibleHeight())}px`); } else { root.style.removeProperty(property); @@ -624,7 +655,7 @@ export function sheetVisibleHeight(name) { * @param {"top"|"bottom"} name */ export function sheetPeekHeight(name) { - if (!isMobileSheetsMode()) { + if (!sheetModeActive(name)) { return 0; } return sheets[name]?.peekHeight() ?? 0; @@ -641,7 +672,7 @@ export function sheetState(name) { * for, when fullscreen ends. */ export function setSheetState(name, state) { - if (isMobileSheetsMode() && !sheetsHiddenByFullscreen()) { + if (sheetModeActive(name) && !sheetsHiddenByFullscreen()) { sheets[name]?.setState(state); } } @@ -659,6 +690,15 @@ export function setSheetExpanded(name, expanded) { setSheetState(name, expanded ? SHEET_EXPANDED : SHEET_COLLAPSED); } +/** Reset a sheet whose layout just switched on or off. */ +function resetSheetForMode(sheet) { + // A drag cannot survive the layout changing under it. + sheet.drag = null; + sheet.touchGate = null; + sheet.element.classList.remove(DRAGGING_CLASS); + sheet.element.style.transform = ""; +} + function applyMode(mobile) { const root = document.documentElement; const wasMobile = root.classList.contains(MODE_CLASS); @@ -666,12 +706,8 @@ function applyMode(mobile) { if (mobile === wasMobile) { return; } - // A drag cannot survive the layout changing under it. for (const sheet of Object.values(sheets)) { - sheet.drag = null; - sheet.touchGate = null; - sheet.element.classList.remove(DRAGGING_CLASS); - sheet.element.style.transform = ""; + resetSheetForMode(sheet); } placeDetails(mobile); // The slider row is only ever opened by the user; coming back into the @@ -686,6 +722,19 @@ function applyMode(mobile) { } } +function applyTopMode(topMode) { + const root = document.documentElement; + const was = root.classList.contains(TOP_MODE_CLASS); + root.classList.toggle(TOP_MODE_CLASS, topMode); + const sheet = sheets.top; + if (topMode === was || !sheet) { + return; + } + resetSheetForMode(sheet); + root.dataset.topSheet = SHEET_COLLAPSED; + sheet.setState(SHEET_COLLAPSED, { force: true }); +} + /** Find the sheets in the page and start following the media query. */ export function initializeMobileSheets() { const root = document.documentElement; @@ -724,12 +773,15 @@ export function initializeMobileSheets() { const query = window.matchMedia?.(mobileSheetsQuery()); const mobile = Boolean(query?.matches); root.classList.toggle(MODE_CLASS, mobile); + const topQuery = window.matchMedia?.(topSheetQuery()); + root.classList.toggle(TOP_MODE_CLASS, Boolean(topQuery?.matches)); placeDetails(mobile); for (const sheet of Object.values(sheets)) { sheet.syncAccessibility(); } publishSheetHeights(); query?.addEventListener?.("change", (event) => applyMode(event.matches)); + topQuery?.addEventListener?.("change", (event) => applyTopMode(event.matches)); // Heights change with rotation and with what the sheets hold (the panel // labels can be switched off; a search changes the badge). diff --git a/photomap/frontend/static/javascript/score-display.js b/photomap/frontend/static/javascript/score-display.js index 2b82b1a2..36bc34e2 100644 --- a/photomap/frontend/static/javascript/score-display.js +++ b/photomap/frontend/static/javascript/score-display.js @@ -1,6 +1,7 @@ // score-display.js // This file manages the score display functionality, showing and hiding the score overlay. import { getClusterLabelInfo, SHOW_CLUSTER_LABELS_IN_BADGES } from "./cluster-utils.js"; +import { isTopSheetMode } from "./mobile-sheets.js"; import { isColorLight } from "./utils.js"; // Utility function to check if a color is light // Star SVG icons for favorites display @@ -134,8 +135,7 @@ export class ScoreDisplay { this.scoreElement.style.display = "flex"; this.scoreElement.classList.add("visible"); this.scoreElement.classList.remove("hidden"); - this.scoreElement.style.backgroundColor = `rgba(0, 0, 0, ${this.opacity})`; // Default background color - this.scoreElement.style.color = "#fff"; // Default text color + this.applyColors(null); this.isVisible = true; this.dispatchContentChangedEvent(); } @@ -155,8 +155,7 @@ export class ScoreDisplay { this.scoreElement.style.display = "flex"; this.scoreElement.classList.add("visible"); this.scoreElement.classList.remove("hidden"); - this.scoreElement.style.backgroundColor = `rgba(0, 0, 0, ${this.opacity})`; // Default background color - this.scoreElement.style.color = "#fff"; // Default text color + this.applyColors(null); this.isVisible = true; this.dispatchContentChangedEvent(); } @@ -214,18 +213,42 @@ export class ScoreDisplay { this.isVisible = true; if (color) { - this.scoreElement.style.backgroundColor = color; this.scoreElement.style.opacity = this.opacity; - if (isColorLight(color)) { - this.scoreElement.style.color = "#000"; // Dark text for light background - } else { - this.scoreElement.style.color = "#fff"; // Light text for dark background - } + this.applyColors(color); } this.dispatchContentChangedEvent(); } } + /** + * Colour the badge for a cluster, or back to its default dark pill (null). + * With the badge in the top sheet the cluster colour goes on the slide + * count and cluster text alone (a pill of its own, mobile-sheets.css), and + * the album pulldown beside it stays on the badge's dark background. + * @param {string|null} clusterColor + */ + applyColors(clusterColor) { + const defaultBackground = `rgba(0, 0, 0, ${this.opacity})`; + const textColor = clusterColor && isColorLight(clusterColor) ? "#000" : "#fff"; + const inSheet = isTopSheetMode(); + const pill = inSheet ? this.scoreText : this.scoreElement; + if (inSheet) { + this.scoreElement.style.backgroundColor = defaultBackground; + this.scoreElement.style.color = "#fff"; + } else if (this.scoreText) { + this.scoreText.style.backgroundColor = ""; + this.scoreText.style.color = ""; + } + if (!pill) { + return; + } + pill.style.backgroundColor = clusterColor || (inSheet ? "" : defaultBackground); + pill.style.color = clusterColor ? textColor : inSheet ? "" : "#fff"; + if (this.scoreText) { + this.scoreText.classList.toggle("cluster-colored", inSheet && Boolean(clusterColor)); + } + } + hide() { this.scoreElement.classList.add("hidden"); this.scoreElement.classList.remove("visible"); diff --git a/photomap/frontend/static/javascript/seek-slider.js b/photomap/frontend/static/javascript/seek-slider.js index e17523cc..e68004bd 100644 --- a/photomap/frontend/static/javascript/seek-slider.js +++ b/photomap/frontend/static/javascript/seek-slider.js @@ -1,7 +1,7 @@ import { backStack } from "./back-stack.js"; import { bookmarkManager } from "./bookmarks.js"; import { scoreDisplay } from "./score-display.js"; -import { isMobileSheetsMode } from "./mobile-sheets.js"; +import { isTopSheetMode } from "./mobile-sheets.js"; import { getCurrentSlideIndex, slideState } from "./slide-state.js"; import { state } from "./state.js"; import { debounce } from "./utils.js"; @@ -143,7 +143,7 @@ class SeekSlider { } // In the phone layout the slider has its own full-width row under the // badge (mobile-sheets.css); an inline left would squeeze it back beside it. - if (isMobileSheetsMode()) { + if (isTopSheetMode()) { this.scoreSliderRow.style.left = ""; this.hoverStrip.style.left = ""; return; diff --git a/photomap/frontend/templates/main.html b/photomap/frontend/templates/main.html index a72e15d3..339ebad7 100644 --- a/photomap/frontend/templates/main.html +++ b/photomap/frontend/templates/main.html @@ -12,6 +12,9 @@ slider fold into sheets that slide in from the top and bottom edges (mobile-sheets.js). Narrow windows, and phones held sideways. --> + + @@ -22,6 +25,10 @@ if (meta && window.matchMedia && window.matchMedia(meta.content).matches) { root.classList.add("mobile-sheets"); } + var topMeta = document.querySelector('meta[name="top-sheet-query"]'); + if (window.matchMedia && window.matchMedia(topMeta ? topMeta.content : "all").matches) { + root.classList.add("top-sheet"); + } var bottom = "expanded"; try { if (localStorage.getItem("bottomSheetState") === "collapsed") { diff --git a/tests/frontend/metadata-drawer-sheet.test.js b/tests/frontend/metadata-drawer-sheet.test.js index d78ecdaa..0d159712 100644 --- a/tests/frontend/metadata-drawer-sheet.test.js +++ b/tests/frontend/metadata-drawer-sheet.test.js @@ -16,6 +16,7 @@ const closeSheetDetails = jest.fn(() => { jest.unstable_mockModule("../../photomap/frontend/static/javascript/mobile-sheets.js", () => ({ isMobileSheetsMode: () => mobile, + isTopSheetMode: () => mobile, setSheetState, closeSheetDetails, sheetState: () => bottomState, diff --git a/tests/frontend/mobile-sheets.test.js b/tests/frontend/mobile-sheets.test.js index 029ebcd5..65f50a9d 100644 --- a/tests/frontend/mobile-sheets.test.js +++ b/tests/frontend/mobile-sheets.test.js @@ -39,18 +39,25 @@ function drag(target, y0, y1, { steps = 10, duration = 400, release = true, kind } } +// The phone layout's query, and the top sheet's own ("all" when main.html's +// is absent, as it is here). +const TOP_QUERY = "all"; let queryListeners; +let topQueryListeners; let queryMatches; +let topQueryMatches; -function installMatchMedia(matches) { +function installMatchMedia(matches, topMatches = true) { queryMatches = matches; + topQueryMatches = topMatches; queryListeners = []; + topQueryListeners = []; window.matchMedia = jest.fn((query) => ({ media: query, get matches() { - return queryMatches; + return query === TOP_QUERY ? topQueryMatches : queryMatches; }, - addEventListener: (type, listener) => queryListeners.push(listener), + addEventListener: (type, listener) => (query === TOP_QUERY ? topQueryListeners : queryListeners).push(listener), removeEventListener: jest.fn(), })); } @@ -60,6 +67,11 @@ function flipQuery(matches) { queryListeners.forEach((listener) => listener({ matches })); } +function flipTopQuery(matches) { + topQueryMatches = matches; + topQueryListeners.forEach((listener) => listener({ matches })); +} + function buildDom() { document.body.innerHTML = `
@@ -126,6 +138,31 @@ describe("mobile-sheets.js", () => { expect(root.style.getPropertyValue("--bottom-sheet-height")).toBe(""); }); + it("keeps the top sheet outside the phone layout", () => { + installMatchMedia(false); + mod.initializeMobileSheets(); + expect(mod.isTopSheetMode()).toBe(true); + expect(mod.sheetVisibleHeight("top")).toBe(26); + expect(root.style.getPropertyValue("--top-sheet-height")).toBe("26px"); + expect(document.getElementById("fixedScoreDisplay").inert).toBe(true); + expect(events).toEqual( + expect.arrayContaining([ + { sheet: "top", state: "collapsed", expanded: false, mobile: true }, + { sheet: "bottom", state: "expanded", expanded: true, mobile: false }, + ]) + ); + }); + + it("leaves the badge and slider alone when the top-sheet query does not match", () => { + installMatchMedia(false, false); + mod.initializeMobileSheets(); + expect(mod.isTopSheetMode()).toBe(false); + expect(mod.sheetVisibleHeight("top")).toBe(0); + expect(document.getElementById("fixedScoreDisplay").inert).toBe(false); + document.getElementById("topSheetHandle").click(); + expect(root.dataset.topSheet).toBe("collapsed"); + }); + it("restores a bottom sheet the user had closed", () => { localStorage.setItem("bottomSheetState", "collapsed"); mod.initializeMobileSheets(); @@ -347,12 +384,31 @@ describe("mobile-sheets.js", () => { expect(mod.isMobileSheetsMode()).toBe(false); expect(events).toEqual( expect.arrayContaining([ - { sheet: "top", state: "collapsed", expanded: false, mobile: false }, + // The top sheet has its own switch, still on. + { sheet: "top", state: "collapsed", expanded: false, mobile: true }, { sheet: "bottom", state: "expanded", expanded: true, mobile: false }, ]) ); expect(root.style.getPropertyValue("--bottom-sheet-height")).toBe(""); + expect(root.style.getPropertyValue("--top-sheet-height")).toBe("26px"); + expect(document.getElementById("controlPanel").inert).toBe(false); + }); + + it("still opens the top sheet outside the phone layout", () => { + flipQuery(false); + document.getElementById("topSheetHandle").click(); + expect(root.dataset.topSheet).toBe("expanded"); + expect(events.at(-1)).toEqual({ sheet: "top", state: "expanded", expanded: true, mobile: true }); + }); + + it("closes and releases the top sheet when its own query stops matching", () => { + document.getElementById("topSheetHandle").click(); + flipTopQuery(false); + expect(mod.isTopSheetMode()).toBe(false); + expect(root.dataset.topSheet).toBe("collapsed"); + expect(events.at(-1)).toEqual({ sheet: "top", state: "collapsed", expanded: false, mobile: false }); expect(document.getElementById("fixedScoreDisplay").inert).toBe(false); + expect(root.style.getPropertyValue("--top-sheet-height")).toBe(""); }); it("comes back with the slider closed", () => { diff --git a/tests/frontend/score-display.test.js b/tests/frontend/score-display.test.js index 40ab90f3..28e3bdad 100644 --- a/tests/frontend/score-display.test.js +++ b/tests/frontend/score-display.test.js @@ -228,6 +228,34 @@ describe("score-display.js", () => { }); }); + describe("in the top sheet", () => { + beforeEach(() => document.documentElement.classList.add("top-sheet")); + afterEach(() => document.documentElement.classList.remove("top-sheet")); + + it("colours only the slide count and cluster, not the whole badge", () => { + scoreDisplayInstance.showCluster(3, "#ff5500", 0, 10); + const { scoreElement, scoreText } = scoreDisplayInstance; + expect(scoreText.style.backgroundColor).toBe("rgb(255, 85, 0)"); + expect(scoreText.classList.contains("cluster-colored")).toBe(true); + expect(scoreElement.style.backgroundColor).toBe("rgba(0, 0, 0, 0.85)"); + expect(scoreElement.style.color).toBe("rgb(255, 255, 255)"); + }); + + it("uses dark text on a light cluster colour", () => { + scoreDisplayInstance.showCluster(3, "#ffffcc", 0, 10); + expect(scoreDisplayInstance.scoreText.style.color).toBe("rgb(0, 0, 0)"); + }); + + it("drops the cluster pill when the badge goes back to a plain index", () => { + scoreDisplayInstance.showCluster(3, "#ff5500", 0, 10); + scoreDisplayInstance.showIndex(1, 10); + const { scoreText } = scoreDisplayInstance; + expect(scoreText.style.backgroundColor).toBe(""); + expect(scoreText.style.color).toBe(""); + expect(scoreText.classList.contains("cluster-colored")).toBe(false); + }); + }); + describe("hide", () => { beforeEach(() => { jest.useFakeTimers(); diff --git a/tests/frontend/seek-slider-sheet.test.js b/tests/frontend/seek-slider-sheet.test.js index 5c70b563..50e42bcc 100644 --- a/tests/frontend/seek-slider-sheet.test.js +++ b/tests/frontend/seek-slider-sheet.test.js @@ -25,6 +25,7 @@ jest.unstable_mockModule("../../photomap/frontend/static/javascript/utils.js", ( let mobile = true; jest.unstable_mockModule("../../photomap/frontend/static/javascript/mobile-sheets.js", () => ({ isMobileSheetsMode: () => mobile, + isTopSheetMode: () => mobile, })); const { seekSlider } = await import("../../photomap/frontend/static/javascript/seek-slider.js"); @@ -106,7 +107,7 @@ describe("seek slider pinned by the top sheet", () => { expect(document.getElementById("sliderHoverStrip").classList.contains("hidden")).toBe(false); }); - it("closes when the phone layout ends, and measures from the badge again", async () => { + it("closes when the top-sheet layout ends, and measures from the badge again", async () => { sheetChanged(true); await flush(); mobile = false; From d1f3e44ed5129f07ee93baccc9b088a94a03adc6 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 15 Nov 2026 21:52:31 -0500 Subject: [PATCH 2/3] Keep the top sheet reachable in desktop fullscreen and from the keyboard Review fixes: outside the phone layout the top sheet now stays in fullscreen (the slider was otherwise unreachable there, where the hover strip used to allow seeking), with the grid reserving its strip; the sheet handles stay in the tab order so a collapsed sheet's album pulldown can still be reached; and the badge recolours if the top-sheet mode changes under a shown cluster. Co-Authored-By: Claude Opus 5.5 --- photomap/frontend/static/css/grid-view.css | 6 +++++ .../frontend/static/css/mobile-sheets.css | 8 ++++--- photomap/frontend/static/javascript/events.js | 6 +++-- .../static/javascript/mobile-sheets.js | 20 +++++++++++----- .../static/javascript/score-display.js | 11 +++++++++ tests/frontend/mobile-sheets.test.js | 24 +++++++++++++++++++ tests/frontend/score-display.test.js | 10 ++++++++ 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/photomap/frontend/static/css/grid-view.css b/photomap/frontend/static/css/grid-view.css index 275d0947..8c277c51 100644 --- a/photomap/frontend/static/css/grid-view.css +++ b/photomap/frontend/static/css/grid-view.css @@ -37,6 +37,12 @@ html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { --grid-top-reserve: 0px; } +/* Except to the top sheet's strip, which stays in fullscreen outside the + phone layout (mobile-sheets.css). */ +html.top-sheet:not(.mobile-sheets):is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { + --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); +} + #swiperGridView { display: grid; grid-template-columns: repeat(auto-fill, minmax(256px, 1fr)); diff --git a/photomap/frontend/static/css/mobile-sheets.css b/photomap/frontend/static/css/mobile-sheets.css index 54df7b50..b0a845bc 100644 --- a/photomap/frontend/static/css/mobile-sheets.css +++ b/photomap/frontend/static/css/mobile-sheets.css @@ -97,10 +97,12 @@ outline-offset: -2px; } -/* Hidden with the rest of the controls in fullscreen. (:is() keeps an unknown - prefixed pseudo-class from dropping the rule; see seek-slider.css.) */ +/* Hidden with the rest of the controls in fullscreen. On larger screens the + top sheet stays, without the badge (seek-slider.css hides it), so the + slider can still be pulled down to seek. (:is() keeps an unknown prefixed + pseudo-class from dropping the rule; see seek-slider.css.) */ html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #panelStackContainer, -html.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { +html.mobile-sheets.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { display: none !important; } diff --git a/photomap/frontend/static/javascript/events.js b/photomap/frontend/static/javascript/events.js index 53a96ca0..5e46a0ab 100644 --- a/photomap/frontend/static/javascript/events.js +++ b/photomap/frontend/static/javascript/events.js @@ -214,8 +214,10 @@ window.addEventListener("slideshowStartRequested", async () => { }); function setupAccessibility() { - // Disable tabbing on buttons to prevent focus issues - document.querySelectorAll("button").forEach((btn) => (btn.tabIndex = -1)); + // Disable tabbing on buttons to prevent focus issues. The sheet handles stay + // tabbable: a collapsed top sheet makes the album pulldown inside it inert, + // and its handle is then the keyboard's only way to it. + document.querySelectorAll("button:not(.sheet-handle)").forEach((btn) => (btn.tabIndex = -1)); // Handle radio button accessibility document.querySelectorAll('input[type="radio"]').forEach((rb) => { diff --git a/photomap/frontend/static/javascript/mobile-sheets.js b/photomap/frontend/static/javascript/mobile-sheets.js index 281f8b66..98249ac2 100644 --- a/photomap/frontend/static/javascript/mobile-sheets.js +++ b/photomap/frontend/static/javascript/mobile-sheets.js @@ -95,9 +95,13 @@ function sheetModeActive(name) { return name === "top" ? isTopSheetMode() : isMobileSheetsMode(); } -// mobile-sheets.css hides both sheets while the page is fullscreen. -function sheetsHiddenByFullscreen() { - return Boolean(document.fullscreenElement || document.webkitFullscreenElement); +// mobile-sheets.css hides the bottom sheet while the page is fullscreen, and +// the top sheet too in the phone layout. On larger screens the top sheet stays +// (the badge in it is hidden), so the slider can still be reached to seek, as +// the hover strip always allowed there. +function sheetsHiddenByFullscreen(name) { + const fullscreen = Boolean(document.fullscreenElement || document.webkitFullscreenElement); + return fullscreen && (name === "bottom" || isMobileSheetsMode()); } function readStoredBottomState() { @@ -251,7 +255,7 @@ class Sheet { * expanded height: what is under the sheet does not reflow as it opens. */ visibleHeight() { - if (!this.active() || sheetsHiddenByFullscreen()) { + if (!this.active() || sheetsHiddenByFullscreen(this.name)) { return 0; } if (!this.expanded) { @@ -266,6 +270,10 @@ class Sheet { this.element.addEventListener("pointerup", this.onPointerUp); this.element.addEventListener("pointercancel", this.onPointerCancel); this.element.addEventListener("click", this.onClick); + // The handle is the keyboard's way in (events.js leaves it in the tab + // order, unlike other buttons), but a mouse press should not leave focus + // on it for the next Space or Enter to land there. + this.handle.addEventListener("mousedown", (event) => event.preventDefault()); if (this.details) { const scroller = this.details.banner; scroller.addEventListener("touchstart", this.onScrollerTouchStart, { passive: true }); @@ -672,7 +680,7 @@ export function sheetState(name) { * for, when fullscreen ends. */ export function setSheetState(name, state) { - if (sheetModeActive(name) && !sheetsHiddenByFullscreen()) { + if (sheetModeActive(name) && !sheetsHiddenByFullscreen(name)) { sheets[name]?.setState(state); } } @@ -680,7 +688,7 @@ export function setSheetState(name, state) { /** Close the bottom sheet's details, back to the stop they were opened from. */ export function closeSheetDetails() { const sheet = sheets.bottom; - if (sheet && sheet.state === SHEET_DETAILS && !sheetsHiddenByFullscreen()) { + if (sheet && sheet.state === SHEET_DETAILS && !sheetsHiddenByFullscreen("bottom")) { sheet.setState(sheet.stateBeforeDetails === SHEET_COLLAPSED ? SHEET_COLLAPSED : SHEET_EXPANDED); } } diff --git a/photomap/frontend/static/javascript/score-display.js b/photomap/frontend/static/javascript/score-display.js index 36bc34e2..56b0ebb4 100644 --- a/photomap/frontend/static/javascript/score-display.js +++ b/photomap/frontend/static/javascript/score-display.js @@ -23,6 +23,16 @@ export class ScoreDisplay { // in, so it cannot be re-rendered when the labels change underneath it; // these can. Null whenever the pill is showing something else. this.lastClusterArgs = null; + // The cluster colour the badge is showing, or null; see applyColors. + this.currentColor = null; + + // Which element carries the cluster colour depends on whether the badge + // is in the top sheet; recolour if that changes under a shown badge. + window.addEventListener("mobileSheetChanged", (event) => { + if (event.detail?.sheet === "top" && this.isVisible) { + this.applyColors(this.currentColor); + } + }); // Set up click listener for the star icon (deferred until DOM is ready) if (document.readyState === "loading") { @@ -228,6 +238,7 @@ export class ScoreDisplay { * @param {string|null} clusterColor */ applyColors(clusterColor) { + this.currentColor = clusterColor || null; const defaultBackground = `rgba(0, 0, 0, ${this.opacity})`; const textColor = clusterColor && isColorLight(clusterColor) ? "#000" : "#fff"; const inSheet = isTopSheetMode(); diff --git a/tests/frontend/mobile-sheets.test.js b/tests/frontend/mobile-sheets.test.js index 65f50a9d..d9aa542c 100644 --- a/tests/frontend/mobile-sheets.test.js +++ b/tests/frontend/mobile-sheets.test.js @@ -376,6 +376,30 @@ describe("mobile-sheets.js", () => { }); }); + describe("fullscreen", () => { + const enterFullscreen = () => + Object.defineProperty(document, "fullscreenElement", { configurable: true, get: () => root }); + afterEach(() => delete document.fullscreenElement); + + it("hides both sheets in the phone layout", () => { + mod.initializeMobileSheets(); + enterFullscreen(); + expect(mod.sheetVisibleHeight("top")).toBe(0); + expect(mod.sheetVisibleHeight("bottom")).toBe(0); + mod.setSheetState("top", "expanded"); + expect(root.dataset.topSheet).toBe("collapsed"); + }); + + it("keeps the top sheet on larger screens, so the slider can still seek", () => { + installMatchMedia(false); + mod.initializeMobileSheets(); + enterFullscreen(); + expect(mod.sheetVisibleHeight("top")).toBe(26); + mod.setSheetState("top", "expanded"); + expect(root.dataset.topSheet).toBe("expanded"); + }); + }); + describe("switching layouts", () => { beforeEach(() => mod.initializeMobileSheets()); diff --git a/tests/frontend/score-display.test.js b/tests/frontend/score-display.test.js index 28e3bdad..8f1594dc 100644 --- a/tests/frontend/score-display.test.js +++ b/tests/frontend/score-display.test.js @@ -246,6 +246,16 @@ describe("score-display.js", () => { expect(scoreDisplayInstance.scoreText.style.color).toBe("rgb(0, 0, 0)"); }); + it("moves the colour back onto the whole badge when the top sheet goes away", () => { + scoreDisplayInstance.showCluster(3, "#ff5500", 0, 10); + document.documentElement.classList.remove("top-sheet"); + window.dispatchEvent(new CustomEvent("mobileSheetChanged", { detail: { sheet: "top", mobile: false } })); + const { scoreElement, scoreText } = scoreDisplayInstance; + expect(scoreElement.style.backgroundColor).toBe("rgb(255, 85, 0)"); + expect(scoreText.style.backgroundColor).toBe(""); + expect(scoreText.classList.contains("cluster-colored")).toBe(false); + }); + it("drops the cluster pill when the badge goes back to a plain index", () => { scoreDisplayInstance.showCluster(3, "#ff5500", 0, 10); scoreDisplayInstance.showIndex(1, 10); From e2f6bc6151d488525d01c9d260832ddc9fa0ed71 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Mon, 16 Nov 2026 19:08:44 -0500 Subject: [PATCH 3/3] Hide the whole top sheet in fullscreen on every screen Handle and progress strip included; the grid gets the top row back. Co-Authored-By: Claude Opus 5.5 --- photomap/frontend/static/css/grid-view.css | 8 +------- photomap/frontend/static/css/mobile-sheets.css | 9 ++++----- .../frontend/static/javascript/mobile-sheets.js | 16 ++++++---------- tests/frontend/mobile-sheets.test.js | 6 +++--- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/photomap/frontend/static/css/grid-view.css b/photomap/frontend/static/css/grid-view.css index 8c277c51..0d66ad3e 100644 --- a/photomap/frontend/static/css/grid-view.css +++ b/photomap/frontend/static/css/grid-view.css @@ -32,17 +32,11 @@ html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { height: var(--visible-viewport-height, 100dvh); } -/* The badge is hidden in fullscreen (seek-slider.css), so give the row back. */ +/* The badge and the top sheet are hidden in fullscreen, so give the row back. */ :is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { --grid-top-reserve: 0px; } -/* Except to the top sheet's strip, which stays in fullscreen outside the - phone layout (mobile-sheets.css). */ -html.top-sheet:not(.mobile-sheets):is(:fullscreen, :-webkit-full-screen) #gridViewSwiper { - --grid-top-reserve: calc(var(--top-sheet-peek) + 6px); -} - #swiperGridView { display: grid; grid-template-columns: repeat(auto-fill, minmax(256px, 1fr)); diff --git a/photomap/frontend/static/css/mobile-sheets.css b/photomap/frontend/static/css/mobile-sheets.css index b0a845bc..bd743b88 100644 --- a/photomap/frontend/static/css/mobile-sheets.css +++ b/photomap/frontend/static/css/mobile-sheets.css @@ -97,12 +97,11 @@ outline-offset: -2px; } -/* Hidden with the rest of the controls in fullscreen. On larger screens the - top sheet stays, without the badge (seek-slider.css hides it), so the - slider can still be pulled down to seek. (:is() keeps an unknown prefixed - pseudo-class from dropping the rule; see seek-slider.css.) */ +/* Hidden with the rest of the controls in fullscreen, on every screen: the + whole top sheet goes, handle and progress strip included. (:is() keeps an + unknown prefixed pseudo-class from dropping the rule; see seek-slider.css.) */ html.mobile-sheets:is(:fullscreen, :-webkit-full-screen) #panelStackContainer, -html.mobile-sheets.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { +html.top-sheet:is(:fullscreen, :-webkit-full-screen) #topSheetContainer { display: none !important; } diff --git a/photomap/frontend/static/javascript/mobile-sheets.js b/photomap/frontend/static/javascript/mobile-sheets.js index 98249ac2..bc4c192f 100644 --- a/photomap/frontend/static/javascript/mobile-sheets.js +++ b/photomap/frontend/static/javascript/mobile-sheets.js @@ -95,13 +95,9 @@ function sheetModeActive(name) { return name === "top" ? isTopSheetMode() : isMobileSheetsMode(); } -// mobile-sheets.css hides the bottom sheet while the page is fullscreen, and -// the top sheet too in the phone layout. On larger screens the top sheet stays -// (the badge in it is hidden), so the slider can still be reached to seek, as -// the hover strip always allowed there. -function sheetsHiddenByFullscreen(name) { - const fullscreen = Boolean(document.fullscreenElement || document.webkitFullscreenElement); - return fullscreen && (name === "bottom" || isMobileSheetsMode()); +// mobile-sheets.css hides both sheets, whole, while the page is fullscreen. +function sheetsHiddenByFullscreen() { + return Boolean(document.fullscreenElement || document.webkitFullscreenElement); } function readStoredBottomState() { @@ -255,7 +251,7 @@ class Sheet { * expanded height: what is under the sheet does not reflow as it opens. */ visibleHeight() { - if (!this.active() || sheetsHiddenByFullscreen(this.name)) { + if (!this.active() || sheetsHiddenByFullscreen()) { return 0; } if (!this.expanded) { @@ -680,7 +676,7 @@ export function sheetState(name) { * for, when fullscreen ends. */ export function setSheetState(name, state) { - if (sheetModeActive(name) && !sheetsHiddenByFullscreen(name)) { + if (sheetModeActive(name) && !sheetsHiddenByFullscreen()) { sheets[name]?.setState(state); } } @@ -688,7 +684,7 @@ export function setSheetState(name, state) { /** Close the bottom sheet's details, back to the stop they were opened from. */ export function closeSheetDetails() { const sheet = sheets.bottom; - if (sheet && sheet.state === SHEET_DETAILS && !sheetsHiddenByFullscreen("bottom")) { + if (sheet && sheet.state === SHEET_DETAILS && !sheetsHiddenByFullscreen()) { sheet.setState(sheet.stateBeforeDetails === SHEET_COLLAPSED ? SHEET_COLLAPSED : SHEET_EXPANDED); } } diff --git a/tests/frontend/mobile-sheets.test.js b/tests/frontend/mobile-sheets.test.js index d9aa542c..6273cdb7 100644 --- a/tests/frontend/mobile-sheets.test.js +++ b/tests/frontend/mobile-sheets.test.js @@ -390,13 +390,13 @@ describe("mobile-sheets.js", () => { expect(root.dataset.topSheet).toBe("collapsed"); }); - it("keeps the top sheet on larger screens, so the slider can still seek", () => { + it("hides the top sheet on larger screens too", () => { installMatchMedia(false); mod.initializeMobileSheets(); enterFullscreen(); - expect(mod.sheetVisibleHeight("top")).toBe(26); + expect(mod.sheetVisibleHeight("top")).toBe(0); mod.setSheetState("top", "expanded"); - expect(root.dataset.topSheet).toBe("expanded"); + expect(root.dataset.topSheet).toBe("collapsed"); }); });