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 [ + '
', + '