diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 48d461d764..c70f50c8b1 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1181,12 +1181,17 @@ corners, so it keeps to the bottom edge, the attribution row sits above it and the coordinates clear the row's logo line. In the desktop Omnibar layout the Omnibar's own rules (`src/ui/styles/omnibar-dock.css`) place the dock, the World Timeline, the credits and the coordinates; its Tactical bottom-right -readout also keeps 8px above the Power Up row. The left rail treats the -centered World Timeline and voice control as obstacles only where they reach a -laid-out panel, not the stack's transparent gutter. Known limit, unchanged -from main: below 1200px with the World Timeline showing, the Tactical -bottom-right readout does not rise with the bar and can touch the dock, and a -credit line longer than the screen does not wrap. +readout also keeps 8px above the Power Up row. There the credit line wraps at +every width, right to left it takes the bottom right at every width, and +`src/ui/creditLineHeight.js` keeps its height in `--credit-line-height`: the +coordinates (and, right to left, the Tactical readout) stay 6px above it +however many lines it wraps onto, and the dock and World Timeline rise when +it is taller than their usual clearance. Narrower than 1120px the dock leaves +no room between the corners, so the coordinates and the readout sit above +the dock. Cesium's credit box wraps at every width outside that layout too. +The left rail treats the centered World Timeline and voice control as +obstacles only where they reach a laid-out panel, not the stack's +transparent gutter. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/scripts/format-scope.json b/scripts/format-scope.json index a755bb8064..4cc86bda7c 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1564,6 +1564,8 @@ "dev/stub-app/main.js", "scripts/qa-stub-boot.mjs", "src/ui/creditsView.js", + "src/ui/creditLineHeight.js", + "src/ui/creditLineHeight.test.mjs", "src/ui/creditsView.test.mjs", "src/cockpitSubjectProviders.js", "src/cockpitSubjectProviders.test.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index dffb890a48..2289a8318d 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -5477,6 +5477,7 @@ "src/render/applicationHooks.js", "src/maps/globeEngine.js", "src/render/cesium/viewers.js", + "src/ui/creditLineHeight.js", "src/ui/creditsView.js", "src/data/planespottersPhoto.js", "src/maps/keylessTerrain.js", diff --git a/src/app/scene.js b/src/app/scene.js index 63012fb663..9945fb2bbd 100644 --- a/src/app/scene.js +++ b/src/app/scene.js @@ -1,6 +1,7 @@ import { createApplicationOperations } from './operations.js'; import { registerDataCredits } from '../data/dataCredits.js'; import { mountCreditsView } from '../ui/creditsView.js'; +import { trackCreditLineHeight } from '../ui/creditLineHeight.js'; import { MapStackController } from '../mapStackController.js'; import { mapEngineFor } from '../maps/engine.js'; import { initLogoGaze } from '../logoGaze.js'; @@ -173,6 +174,8 @@ export async function createApplicationScene({ // The credits, in the application's own line, unless the renderer shows // them in a display of its own. if (!hooks.ownCreditDisplay) defer(mountCreditsView(viewer)); + // The HUD corners above the line clear it when it wraps. + defer(trackCreditLineHeight(document)); loaderStatus.textContent = googleApiKey || googleTokens || cesiumToken ? t('Loading Google 3D Tiles...') diff --git a/src/creditAttribution.test.mjs b/src/creditAttribution.test.mjs index 879f58d64e..958578689d 100644 --- a/src/creditAttribution.test.mjs +++ b/src/creditAttribution.test.mjs @@ -439,12 +439,21 @@ function resolve(candidates, prop, width, label) { /** Evaluate a length. Anything the model cannot resolve exactly fails loudly. */ function toPx(value, viewportHeight, where) { const trimmed = value.trim(); + // The larger of its lengths, each resolved the same way. + if (/^max\(.*\)$/.test(trimmed)) + return Math.max( + ...splitTopLevel(trimmed.slice(4, -1), ',').map((part) => + toPx(part, viewportHeight, where), + ), + ); const inner = /^calc\(/.test(trimmed) ? trimmed.slice(5, -1) : trimmed; - assert.doesNotMatch( - inner, - /\bcalc\(/, - `nested calc() in ${where}: "${value}"`, - ); + // A calc() is a whole term of its own, resolved below; nowhere else. + for (const term of splitTopLevel(inner, '+')) + assert.doesNotMatch( + term.trim().replace(/^calc\(.*\)$/, ''), + /\bcalc\(/, + `nested calc() in ${where}: "${value}"`, + ); assert.doesNotMatch( inner, /\b(min|max|clamp|env|attr|round|mod)\(/, @@ -465,6 +474,18 @@ function toPx(value, viewportHeight, where) { const term = raw.trim(); if (!term) continue; if (term === '100%') continue; // the tray's own panel height, added separately + // A calc() of its own, as a term ("calc(var(--omnibar-credits-clear) + + // 2px)" once substituted). + if (/^calc\(.*\)$/.test(term)) { + total += toPx(term, viewportHeight, where); + continue; + } + // The credit line's own height (src/ui/creditLineHeight.js), at the + // height this pin models it at. + if (/^var\(--credit-line-height\b/.test(term)) { + total += CREDIT_HEIGHT_PX; + continue; + } if (term.startsWith('var(')) { const name = term.slice(4, term.lastIndexOf(')')).split(',')[0].trim(); assert.ok( @@ -859,16 +880,28 @@ function omnibarVar(name) { const decls = RULES.filter((rule) => rule.parts.includes(OMNIBAR_SCOPE)) .flatMap((rule) => rule.decls) .filter((decl) => decl.prop === name); - assert.equal(decls.length, 1, `${name} is declared once in the Omnibar scope`); + assert.equal( + decls.length, + 1, + `${name} is declared once in the Omnibar scope`, + ); return decls[0].value; } /** A length in the Omnibar layout, with its scope's own custom properties. */ function omnibarPx(value, viewportHeight, where) { - const substituted = value.replace( - /var\((--omnibar-[\w-]+)\)/g, - (_, name) => omnibarVar(name), - ); + // The scope's properties may name each other ("--omnibar-dock-bottom" + // clears "--omnibar-credits-clear"): substitute until none is left. + let substituted = value; + for (let pass = 0; /var\(--omnibar-/.test(substituted); pass += 1) { + assert.ok( + pass < 8, + `Omnibar properties name each other in a loop: ${value}`, + ); + substituted = substituted.replace(/var\((--omnibar-[\w-]+)\)/g, (_, name) => + omnibarVar(name), + ); + } return toPx(substituted, viewportHeight, where); } @@ -893,7 +926,11 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' width, 'Omnibar dock', ); - assert.equal(dock.part, OMNIBAR.dock, `the Omnibar owns the dock at ${width}px`); + assert.equal( + dock.part, + OMNIBAR.dock, + `the Omnibar owns the dock at ${width}px`, + ); // Its top and height too: a legacy top or height winning here would // move or stretch the dock the clearance below is measured from. for (const [prop, value] of [ @@ -906,8 +943,16 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' width, `Omnibar dock ${prop}`, ); - assert.equal(own.part, OMNIBAR.dock, `the Omnibar owns the dock ${prop} at ${width}px`); - assert.equal(own.decl.value, value, `Omnibar dock ${prop} at ${width}px`); + assert.equal( + own.part, + OMNIBAR.dock, + `the Omnibar owns the dock ${prop} at ${width}px`, + ); + assert.equal( + own.decl.value, + value, + `Omnibar dock ${prop} at ${width}px`, + ); } const credit = resolve( [ @@ -923,7 +968,11 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' credit.part.startsWith(OMNIBAR_SCOPE), `the Omnibar owns the credit row at ${width}px`, ); - const dockBottom = omnibarPx(dock.decl.value, height, 'Omnibar dock bottom'); + const dockBottom = omnibarPx( + dock.decl.value, + height, + 'Omnibar dock bottom', + ); const creditTop = omnibarPx(credit.decl.value, height, 'Omnibar credit bottom') + CREDIT_HEIGHT_PX; @@ -938,7 +987,10 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' // and no rule elsewhere forces them back. const trays = RULES.find((rule) => rule.parts.includes(OMNIBAR.trays)); assert.ok(trays, 'the Omnibar layout hides the legacy trays'); - assert.equal(trays.decls.find((decl) => decl.prop === 'display')?.value, 'none'); + assert.equal( + trays.decls.find((decl) => decl.prop === 'display')?.value, + 'none', + ); for (const rule of RULES) { for (const part of rule.parts) { if (!/#(location-bar|control-panel)$/.test(lastCompound(part))) continue; @@ -951,8 +1003,13 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' // The minimal-HUD rail cap only shortens the rail, which is anchored at // its top, so it can only add room above the credit. const rail = RULES.find((rule) => rule.parts.includes(OMNIBAR.minimalRail)); - const cap = rail.decls.find((decl) => decl.prop === '--omnibar-minimal-rail-height'); - assert.match(cap?.value || '', /^min\(\s*var\(--right-stack-max-height, 70vh\),/); + const cap = rail.decls.find( + (decl) => decl.prop === '--omnibar-minimal-rail-height', + ); + assert.match( + cap?.value || '', + /^min\(\s*var\(--right-stack-max-height, 70vh\),/, + ); assert.equal( rail.decls.find((decl) => decl.prop === 'max-height')?.value, 'var(--omnibar-minimal-rail-height)', diff --git a/src/ui/creditLineHeight.js b/src/ui/creditLineHeight.js new file mode 100644 index 0000000000..700f6c8789 --- /dev/null +++ b/src/ui/creditLineHeight.js @@ -0,0 +1,41 @@ +/** + * @module ui/creditLineHeight + * @description Keeps `--credit-line-height` on the page's root at the + * height of the attribution line at the bottom of the screen, so what sits + * above it (the HUD's bottom corners) clears it when it wraps onto more + * lines. The line is the application's own (`#gev-credits`) or the one a + * renderer draws inside `#cesium-credits`. + */ + +const LINES = ['#gev-credits', '#cesium-credits .cesium-widget-credits']; + +/** + * Follow the attribution line's height in `--credit-line-height`. + * @param {Document} [doc] + * @returns {() => void} Stops following it and clears the property. + */ +export function trackCreditLineHeight(doc = globalThis.document) { + const Observer = doc?.defaultView?.ResizeObserver; + if (!doc?.documentElement || typeof Observer !== 'function') return () => {}; + const root = doc.documentElement; + const lines = LINES.map((selector) => doc.querySelector(selector)).filter( + Boolean, + ); + if (!lines.length) return () => {}; + const update = () => { + const height = Math.max( + 0, + ...lines.map((line) => line.getBoundingClientRect().height), + ); + if (height > 0) + root.style.setProperty('--credit-line-height', `${Math.ceil(height)}px`); + else root.style.removeProperty('--credit-line-height'); + }; + const observer = new Observer(update); + for (const line of lines) observer.observe(line); + update(); + return () => { + observer.disconnect(); + root.style.removeProperty('--credit-line-height'); + }; +} diff --git a/src/ui/creditLineHeight.test.mjs b/src/ui/creditLineHeight.test.mjs new file mode 100644 index 0000000000..6b3def9ba8 --- /dev/null +++ b/src/ui/creditLineHeight.test.mjs @@ -0,0 +1,79 @@ +import '../testSupport/registerDom.mjs'; +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { trackCreditLineHeight } from './creditLineHeight.js'; + +/** A ResizeObserver the test drives, with each line's height set by hand. */ +function fakeResizing() { + const observers = []; + const window = document.defaultView; + const original = window.ResizeObserver; + window.ResizeObserver = class { + constructor(callback) { + this.callback = callback; + this.targets = new Set(); + observers.push(this); + } + observe(target) { + this.targets.add(target); + } + disconnect() { + this.targets.clear(); + } + }; + return { + resize(element, height) { + element.getBoundingClientRect = () => ({ height }); + for (const observer of observers) + if (observer.targets.has(element)) observer.callback([]); + }, + restore() { + window.ResizeObserver = original; + }, + }; +} + +test("the credit line's height follows it as it wraps, for either renderer's line", () => { + const resizing = fakeResizing(); + try { + for (const markup of [ + '
', + '
', + ]) { + document.body.innerHTML = markup; + const line = document.querySelector( + '#gev-credits, #cesium-credits .cesium-widget-credits', + ); + line.getBoundingClientRect = () => ({ height: 28 }); + const stop = trackCreditLineHeight(document); + const root = document.documentElement.style; + assert.equal(root.getPropertyValue('--credit-line-height'), '28px'); + resizing.resize(line, 66.4); + assert.equal(root.getPropertyValue('--credit-line-height'), '67px'); + // Hidden, it holds no room. + resizing.resize(line, 0); + assert.equal(root.getPropertyValue('--credit-line-height'), ''); + resizing.resize(line, 28); + stop(); + assert.equal(root.getPropertyValue('--credit-line-height'), ''); + } + } finally { + resizing.restore(); + document.body.replaceChildren(); + } +}); + +test('without a credit line nothing is followed', () => { + const resizing = fakeResizing(); + try { + document.body.replaceChildren(); + const stop = trackCreditLineHeight(document); + assert.equal( + document.documentElement.style.getPropertyValue('--credit-line-height'), + '', + ); + stop(); + } finally { + resizing.restore(); + } +}); diff --git a/src/ui/hudSonarStyle.test.mjs b/src/ui/hudSonarStyle.test.mjs index 75c7aaa6f9..08816d8a9d 100644 --- a/src/ui/hudSonarStyle.test.mjs +++ b/src/ui/hudSonarStyle.test.mjs @@ -458,8 +458,10 @@ test('the desktop bottom row: credits on the Power Up baseline, the dock lifted, const anchor = trays.match( /#cesium-credits \{\s*right: auto;\s*bottom: ([\d.]+)rem;\s*left: 1\.5rem;/, ); - const box = trayWide.match( - /\n #cesium-credits \.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - ([\d.]+)rem\);\s*white-space: normal;/, + // At every width: a long line wraps rather than running under the + // corner row. + const box = trays.match( + /\n#cesium-credits \.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - ([\d.]+)rem\);\s*white-space: normal;/, ); return anchor && box && [null, anchor[1], box[1]]; })(), @@ -491,13 +493,14 @@ test('the desktop bottom row: credits on the Power Up baseline, the dock lifted, /html\[dir='rtl'\]\s*body:not\(\.context-docked\):not\(\.ui-clean-view\):not\(\.recording-mode\)\s*:is\(#cesium-credits, #gev-credits\),\s*html\[dir='rtl'\]\s*body:not\(\.context-docked\):not\(\.ui-clean-view\):not\(\.recording-mode\):has\(\s*#intel-hud\[data-variant='minimal'\]\.active\s*\)\s*:is\(#cesium-credits, #gev-credits\) \{\s*right: 1\.5rem;\s*left: auto;/, ); assert.match( - trayWide, - /#cesium-credits\s*\.cesium-widget-credits \{\s*right: 0;\s*left: auto;/, + trays, + /html\[dir='rtl'\] #cesium-credits \.cesium-widget-credits \{\s*right: 0;\s*left: auto;/, ); - // There the readout clears two lines of the row under it. + // There the readout clears the row under it, however many lines it wraps + // onto (--credit-line-height). assert.match( read('./styles/omnibar-dock.css'), - /html\[dir='rtl'\] \*\)\s*#intel-hud\[data-variant='tactical'\]\s*\.hud-bottom-right \{\s*bottom: calc\(3\.375rem \+ 1\.5rem\);/, + /html\[dir='rtl'\] \*\):not\(\.context-docked\)\s*#intel-hud\[data-variant='tactical'\]\s*\.hud-bottom-right \{\s*bottom: max\(3\.375rem, var\(--omnibar-credits-clear\)\);/, ); const locale = read('./styles/locale-picker.css'); assert.match(locale, /#corner-actions \{[^}]*inset-inline-end: 0\.9rem;/); diff --git a/src/ui/styles/command-dock-trays.css b/src/ui/styles/command-dock-trays.css index eb20f444ad..c547cc448c 100644 --- a/src/ui/styles/command-dock-trays.css +++ b/src/ui/styles/command-dock-trays.css @@ -501,13 +501,16 @@ body:not(.ui-clean-view):not(.recording-mode):has( /* The coordinate readout shares the bottom-left corner with the attribution row below 1200px: it sits clear of the row's 28px logo line, with a 6px gap - (from 1200px, rail-split.css). */ -#intel-hud:is([data-variant='tactical'], [data-variant='minimal']) - .hud-bottom-left, -:root[data-scope-mask='off'] - #intel-hud[data-variant='minimal'] - .hud-bottom-left { - bottom: calc(2vh + 7.125rem + var(--world-timeline-lift, 0px)); + (from 1200px, rail-split.css). At 980px and below the dock is two rows + tall and command-dock.css places it. */ +@media (min-width: 981px) { + #intel-hud:is([data-variant='tactical'], [data-variant='minimal']) + .hud-bottom-left, + :root[data-scope-mask='off'] + #intel-hud[data-variant='minimal'] + .hud-bottom-left { + bottom: calc(2vh + 7.125rem + var(--world-timeline-lift, 0px)); + } } @media (max-width: 1199px) { @@ -528,15 +531,22 @@ body:not(.ui-clean-view):not(.recording-mode):has( } } -@media (min-width: 1200px) { - /* Cesium draws the line in an absolutely placed box inside the empty - #cesium-credits anchor, so the cap and the wrapping go on that box. */ - #cesium-credits .cesium-widget-credits { - width: max-content; - max-width: calc(100vw - 1.5rem - 26rem); - white-space: normal; - } +/* Cesium draws the line in an absolutely placed box inside the empty + #cesium-credits anchor, so the cap and the wrapping go on that box, at + every width: a long line wraps rather than running under the corner row. + Right to left it hangs from the anchor's right edge. */ +#cesium-credits .cesium-widget-credits { + width: max-content; + max-width: calc(100vw - 1.5rem - 26rem); + white-space: normal; +} +html[dir='rtl'] #cesium-credits .cesium-widget-credits { + right: 0; + left: auto; +} + +@media (min-width: 1200px) { /* Right to left, the corner row sits at the bottom left (locale-picker.css), so the attribution row takes the bottom right. Expanded Context places it itself (context-dock.css). */ @@ -554,14 +564,6 @@ body:not(.ui-clean-view):not(.recording-mode):has( left: auto; text-align: right; } - - html[dir='rtl'] - body:not(.context-docked):not(.ui-clean-view):not(.recording-mode) - #cesium-credits - .cesium-widget-credits { - right: 0; - left: auto; - } } @media (max-width: 900px) { diff --git a/src/ui/styles/omnibar-dock.css b/src/ui/styles/omnibar-dock.css index 480227e014..e60d5b5d4d 100644 --- a/src/ui/styles/omnibar-dock.css +++ b/src/ui/styles/omnibar-dock.css @@ -5,8 +5,13 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not( :has(#gev-omnibar):has(#command-dock > #gev-voice-control) ) { --omnibar-dock-width: clamp(400px, 32vw, 460px); - --omnibar-dock-bottom: 74px; - --omnibar-coordinates-bottom: 4.25rem; + /* Clear of the attribution line under it, however many lines it wraps + onto (--credit-line-height, src/ui/creditLineHeight.js). */ + --omnibar-credits-clear: calc(1rem + var(--credit-line-height, 28px) + 6px); + /* The dock, and the World Timeline and narrow corners placed from it, + rise over a line wrapped taller than its usual one or two lines. */ + --omnibar-dock-bottom: max(74px, calc(var(--omnibar-credits-clear) + 2px)); + --omnibar-coordinates-bottom: max(4.25rem, var(--omnibar-credits-clear)); --world-timeline-lift: 0px; #intel-hud:is([data-variant='tactical'], [data-variant='minimal']) @@ -320,24 +325,54 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not( display: none; } - /* Align the plain credits with Power Up. */ + /* Align the plain credits with Power Up. The line wraps at every width + rather than running under the corner row (Power Up and the language + picker), whose side it stays clear of. */ :is(#cesium-credits, #gev-credits), &:has(#intel-hud[data-variant='minimal'].active) :is(#cesium-credits, #gev-credits) { bottom: 1rem; } + #gev-credits { + width: max-content !important; + max-width: calc(100vw - 1.5rem - 26rem); + white-space: normal; + } + /* Right to left the corner row is at the bottom left, so the line takes + the bottom right at every width. Expanded Context places it itself. */ + &:where(html[dir='rtl'] *):not(.context-docked) { + :is(#cesium-credits, #gev-credits), + &:has(#intel-hud[data-variant='minimal'].active) + :is(#cesium-credits, #gev-credits) { + right: 1.5rem; + left: auto; + text-align: right; + } + } /* 8px above the bottom-right corner row (Power Up and the language picker: 32px tall, 14px up), as outside the Omnibar layout. */ #intel-hud[data-variant='tactical'] .hud-bottom-right { bottom: 3.375rem; } - /* Right to left the attribution row takes the bottom right: the readout - clears two lines of it (rail-split.css). */ - @media (min-width: 1200px) { - &:where(html[dir='rtl'] *) + /* Right to left the attribution line is under the readout, which clears + it however many lines it wraps onto. */ + &:where(html[dir='rtl'] *):not(.context-docked) + #intel-hud[data-variant='tactical'] + .hud-bottom-right { + bottom: max(3.375rem, var(--omnibar-credits-clear)); + } + /* Narrower than the two corners and the dock between them, the corners + rise above the dock. */ + @media (max-width: 1119px) { + --omnibar-coordinates-bottom: max( + calc(var(--omnibar-dock-bottom) + 56px + 10px), + var(--omnibar-credits-clear) + ); + #intel-hud[data-variant='tactical'] .hud-bottom-right, + &:where(html[dir='rtl'] *):not(.context-docked) #intel-hud[data-variant='tactical'] .hud-bottom-right { - bottom: calc(3.375rem + 1.5rem); + bottom: var(--omnibar-coordinates-bottom); } } #intel-hud:is([data-variant='tactical'], [data-variant='minimal'])