From c69a421678d5e7a34f40c57f0b5b183568a75df4 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 18:08:29 -0800 Subject: [PATCH 1/4] Keep the HUD corners, the dock and a wrapped credit line apart at every width The credit line now wraps at every width instead of running under the corner row, and right to left it takes the bottom right at every width. A small watcher keeps its height in --credit-line-height, so the coordinates (and, right to left, the Tactical readout) stay 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 bottom corners, so the coordinates and the readout sit above the dock instead of under it. Outside the Omnibar layout, the coordinate rule meant for 981 to 1199px no longer overrides the two-row dock's placement at 980px and below. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 17 ++++-- scripts/format-scope.json | 2 + scripts/package-boundaries.json | 1 + src/app/scene.js | 3 + src/creditAttribution.test.mjs | 91 ++++++++++++++++++++++------ src/ui/creditLineHeight.js | 41 +++++++++++++ src/ui/creditLineHeight.test.mjs | 79 ++++++++++++++++++++++++ src/ui/hudSonarStyle.test.mjs | 15 +++-- src/ui/styles/command-dock-trays.css | 48 ++++++++------- src/ui/styles/omnibar-dock.css | 51 +++++++++++++--- 10 files changed, 288 insertions(+), 60 deletions(-) create mode 100644 src/ui/creditLineHeight.js create mode 100644 src/ui/creditLineHeight.test.mjs 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']) From 40e2998466e9ffafa242a5c5a6eae308b9e69a4c Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 18:27:26 -0800 Subject: [PATCH 2/4] Carry Sonar with the Minimal HUD layout in links and scene shots A link or scene shot made in Minimal with Sonar on played back with Sonar off, and turned off the viewer's own. Tactical with Sonar keeps the `cyber` layout code, which older readers understand; Minimal with Sonar now carries an explicit mark beside its layout: flag bit 5 (`hudSonar`, default off) of a compact link, `hs=1` in the long form, and `hud.sonar: true` in a scene shot. A restore turns Sonar on when the state names Cyber or carries the mark, so a state made before it restores exactly as it did. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 8 ++- docs/SCENE-DOCUMENT.md | 6 +- docs/SHARE-LINK-FORMAT.md | 6 +- src/director/document.js | 2 +- src/director/document.test.mjs | 27 +++++++ src/scenes/project.js | 3 + src/share/legacyShareState.js | 1 + src/share/legacyShareState.test.mjs | 18 +++++ src/share/viewCodec.js | 3 + src/share/viewCodec.test.mjs | 28 +++++++- src/sharelink.celestial.test.mjs | 31 ++++++++ src/sharelink.js | 9 +++ src/ui/hudSonarStyle.test.mjs | 108 ++++++++++++++++++++++++---- src/ui/visualSettings.js | 44 +++++++++--- 14 files changed, 266 insertions(+), 28 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index c70f50c8b1..9e3c37ab9b 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1136,8 +1136,12 @@ opt-in visual style over Tactical or Minimal: Display > HUD > Sonar is OFF by default, and ON reveals the Rings, Range, Power, Opacity and Sector sliders. Share links, scenes and saved views that name Cyber keep its enum code and open in Tactical with Sonar on. Links and scene shots record Tactical with -Sonar on under that same code, and a restored state that names another layout -turns Sonar off; Minimal has no such code, so its Sonar is not carried. +Sonar on under that same code, so older builds still read it. Minimal with +Sonar on is recorded as Minimal plus an explicit Sonar mark: flag bit 5 +(`hudSonar`) of a compact link, `hs=1` in the long form, and `hud.sonar: true` +in a scene shot. A restored state turns Sonar on when it names Cyber or carries +that mark, and off otherwise, so a link or shot made before the mark restores +as it always did. An explicit Sonar toggle or validated voice setting takes visual restore authority, so a delayed share-link restore cannot undo the newer choice. Choosing Reset Visual keeps the HUD layout and the Sonar setting. diff --git a/docs/SCENE-DOCUMENT.md b/docs/SCENE-DOCUMENT.md index 6d4077d959..5670e11068 100644 --- a/docs/SCENE-DOCUMENT.md +++ b/docs/SCENE-DOCUMENT.md @@ -54,8 +54,12 @@ fallback for zero; holds may be zero. Visual fields are `style`, `mapStack`, `styleParams`, `bloom`, `sharpen`, `hud`, and `detection`, and `scope`. Bloom has `enabled`, `intensity`, `version`; sharpen has `enabled`, -`intensity`; HUD has `visible`, `variant`; detection has `mode`, `density`, +`intensity`; HUD has `visible`, `variant` and an optional `sonar`; detection has `mode`, `density`, `allocation`, `fadePct` and `outsideOpacityPct`. Scope has `enabled`, `featherPct`. +HUD `sonar: true` is Sonar on beside a layout that cannot say it (Minimal); it +is written only then, so Tactical with Sonar stays the variant `cyber` and a +shot without Sonar has no `sonar`. A shot without it opens with Sonar on only +when its variant is `cyber`. The latter settings were written by Update Shot but previously lost during normalization; they now survive import and capture. Version-1/2 bloom without an explicit scale version uses the original inverted diff --git a/docs/SHARE-LINK-FORMAT.md b/docs/SHARE-LINK-FORMAT.md index 888c3a91e3..41e1b81abd 100644 --- a/docs/SHARE-LINK-FORMAT.md +++ b/docs/SHARE-LINK-FORMAT.md @@ -176,7 +176,11 @@ Opacity slider (the long form's `sco`). It is written only below 100, so a link made before it, which opens at full opacity, keeps its code. Flag bits (field 9): 0 `bloom`, 1 `sharpen`, 2 `hudVisible`, 3 -`celestialRing` (each defaulting by style), 4 `scopeEnabled` (default on). +`celestialRing` (each defaulting by style), 4 `scopeEnabled` (default on), 5 +`hudSonar` (default off). `hudSonar` is Sonar on beside a HUD layout whose code +cannot say so, Minimal (the long form's `hs=1`); Tactical with Sonar stays the +`cyber` layout code alone. A link made before the bit has it off, and opens +with Sonar on only when it names `cyber`, as before. ### Style defaults diff --git a/src/director/document.js b/src/director/document.js index 2ab0e6ec32..a682605a00 100644 --- a/src/director/document.js +++ b/src/director/document.js @@ -36,7 +36,7 @@ function visual(value, path, legacy) { const specs = { bloom: { enabled: 'boolean', intensity: [-100, 10000], version: [1, 100] }, sharpen: { enabled: 'boolean', intensity: [0, 100] }, - hud: { visible: 'boolean', variant: 'string' }, + hud: { visible: 'boolean', variant: 'string', sonar: 'boolean' }, detection: { mode: 'string', density: [0, 100], diff --git a/src/director/document.test.mjs b/src/director/document.test.mjs index 0a73f98edb..4e7e1112a5 100644 --- a/src/director/document.test.mjs +++ b/src/director/document.test.mjs @@ -168,3 +168,30 @@ test('captured scope and extended detection edits survive migration', () => { project.scenes[0].shots[0].visual.detection, ); }); + +test('a shot keeps Sonar beside its HUD layout; one without it reads as before', () => { + const project = fixture(); + const shot = project.scenes[0].shots[0]; + shot.visual = { hud: { visible: true, variant: 'minimal', sonar: true } }; + const read = (p) => + normalizeProject(parseSceneDocument(JSON.stringify(p))).scenes[0].shots[0] + .visual.hud; + assert.deepEqual(read(project), { + visible: true, + variant: 'minimal', + sonar: true, + }); + // Older shots name no Sonar: the layout alone, Cyber included, as before. + for (const variant of ['minimal', 'cyber']) { + shot.visual = { hud: { visible: true, variant } }; + assert.deepEqual(read(project), { visible: true, variant }); + } + // Off is the meaning of an absent field, so it is not kept. + shot.visual = { hud: { variant: 'minimal', sonar: false } }; + assert.equal(Object.hasOwn(read(project), 'sonar'), false); + shot.visual = { hud: { variant: 'minimal', sonar: 'on' } }; + assert.throws( + () => validateSceneDocument(project), + /\$\.scenes\[0\]\.shots\[0\]\.visual\.hud\.sonar/, + ); +}); diff --git a/src/scenes/project.js b/src/scenes/project.js index 95397183c7..b4cdf33571 100644 --- a/src/scenes/project.js +++ b/src/scenes/project.js @@ -287,6 +287,9 @@ export function normalizeShot( hud: { visible: typeof hud.visible === 'boolean' ? hud.visible : true, variant: typeof hud.variant === 'string' ? hud.variant : 'tactical', + // Sonar on beside a layout whose code cannot say so; absent is off + // unless the variant names the retired Cyber layout. + ...(hud.sonar === true ? { sonar: true } : {}), }, detection: { ...(typeof detection.allocation === 'string' diff --git a/src/share/legacyShareState.js b/src/share/legacyShareState.js index e941faeee8..98fae4a75f 100644 --- a/src/share/legacyShareState.js +++ b/src/share/legacyShareState.js @@ -34,6 +34,7 @@ export const LEGACY_SHARE_STATE_KEYS = Object.freeze([ 'bloomVersion', 'sharpenIntensity', 'hudVariant', + 'hudSonar', 'hudVisible', 'detectionMode', 'detectionDensity', diff --git a/src/share/legacyShareState.test.mjs b/src/share/legacyShareState.test.mjs index 7f3bac84ab..a511ca1f7d 100644 --- a/src/share/legacyShareState.test.mjs +++ b/src/share/legacyShareState.test.mjs @@ -146,6 +146,23 @@ test('links from earlier long-form versions keep their historical meaning', () = assert.equal(off.layerState.options.flights.models3d, false); }); +test('Sonar beside the Minimal layout survives the compact form; older links do not name it', () => { + const { parsed, state } = assertLegacyRoundTrip( + 'v=2&lat=10&lon=20&hud=minimal&hs=1', + ); + assert.equal(parsed.hudSonar, true); + assert.equal(state.hudVariant, 'minimal'); + assert.equal(state.hudSonar, true); + // Links made before `hs`: Minimal carries no Sonar, Cyber carries it in + // its own code. + for (const hud of ['minimal', 'cyber']) { + const old = assertLegacyRoundTrip(`v=2&lat=10&lon=20&hud=${hud}`); + assert.equal(old.parsed.hudSonar, false); + assert.equal(old.state.hudVariant, hud); + assert.equal(old.state.hudSonar, false); + } +}); + test('a tracking selection becomes a thing view and back', () => { const flights = assertLegacyRoundTrip('v=2&lat=1&lon=2&l=f&lo=f.t.a1b2c3'); assert.deepEqual(flights.state.view.entity, { @@ -232,6 +249,7 @@ function generatedLegacyHash(random) { bloomVersion: pick(random, [1, 2]), sharpenIntensity: int(0, 100), hudVariant: pick(random, HUD_LAYOUTS), + hudSonar: random() < 0.5, hudVisible: random() < 0.5, detectionMode: pick(random, ['OFF', 'SPARSE', 'BALANCED', 'DENSE']), detectionDensity: density, diff --git a/src/share/viewCodec.js b/src/share/viewCodec.js index 518156fb67..9a5015964d 100644 --- a/src/share/viewCodec.js +++ b/src/share/viewCodec.js @@ -255,6 +255,9 @@ export const SHARE_VIEW_FLAGS = freezeAll([ { bit: 2, key: 'hudVisible', default: BY_STYLE }, { bit: 3, key: 'celestialRing', default: BY_STYLE }, { bit: 4, key: 'scopeEnabled', default: true }, + // Sonar on beside a HUD layout whose code cannot say so (Minimal). Tactical + // with Sonar stays the `cyber` layout code alone. + { bit: 5, key: 'hudSonar', default: false }, ]); /** diff --git a/src/share/viewCodec.test.mjs b/src/share/viewCodec.test.mjs index aafa5083b2..1a2c87e0c0 100644 --- a/src/share/viewCodec.test.mjs +++ b/src/share/viewCodec.test.mjs @@ -348,6 +348,7 @@ test('every registered field round-trips at once', () => { bloomVersion: 1, sharpenIntensity: 65, hudVariant: 'operator', + hudSonar: true, hudVisible: false, detectionMode: 'SPARSE', detectionDensity: 100, @@ -449,6 +450,28 @@ test('links made with a retired HUD layout still decode to its name', () => { } }); +test('Sonar beside the Minimal layout is flag bit 5; links made before it keep their meaning', () => { + const minimal = { ...createDefaultShareViewState(), hudVariant: 'minimal' }; + const plain = encodeShareView(minimal); + // Off is the default, so a view without Sonar costs nothing for it. + assert.equal(encodeShareView({ ...minimal, hudSonar: false }), plain); + const withSonar = assertRoundTrip({ ...minimal, hudSonar: true }); + assert.notEqual(withSonar, plain); + const decoded = decodeOk(withSonar).state; + assert.equal(decoded.hudVariant, 'minimal'); + assert.equal(decoded.hudSonar, true); + assert.equal(decodeOk(plain).state.hudSonar, false); + // Tactical with Sonar is still the Cyber code alone. + const cyber = { ...createDefaultShareViewState(), hudVariant: 'cyber' }; + assert.equal(decodeOk(encodeShareView(cyber)).state.hudSonar, false); + // A link made before the bit (thermal, Cyber, Scope off) decodes as it did: + // Cyber without the bit, which the app opens as Tactical with Sonar on. + const before = decodeOk('ARD-7j4YuxMguBcoUEgQcAOAAQPIASPQAWGa').state; + assert.equal(before.hudVariant, 'cyber'); + assert.equal(before.hudSonar, false); + assert.equal(encodeShareView(before), 'ARD-7j4YuxMguBcoUEgQcAOAAQPIASPQAWGa'); +}); + test('defaults travel as frozen meanings that match today’s app defaults', () => { const defaults = createDefaultShareViewState(); // When an app default moves, these tests should be updated to document the @@ -535,6 +558,7 @@ test('the field registry is well formed and permanent', () => { [2, 'hudVisible', BY_STYLE], [3, 'celestialRing', BY_STYLE], [4, 'scopeEnabled', true], + [5, 'hudSonar', false], ], ); // The style-applied defaults are frozen meanings too. If the app's style @@ -921,7 +945,7 @@ test('unknown fields inside a thing view, codes and bits are skipped too', () => thing.textField(20, 'cockpit'); // a future thing field const writer = new WireWriter(); writer.bytes.push(1); - writer.sintField(2, 100000).uintField(9, 0b100001); // flag bit 5 unknown + writer.sintField(2, 100000).uintField(9, 0b1000001); // flag bit 6 unknown writer.bytesField( 10, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], @@ -944,7 +968,7 @@ test('unknown fields inside a thing view, codes and bits are skipped too', () => result.unknownFields.map((u) => [u.scope, u.field ?? u.code]), [ ['enum:style', 99], - ['flags', 32], + ['flags', 64], ['layer', 160], ['panel', 12], ['thing', 20], diff --git a/src/sharelink.celestial.test.mjs b/src/sharelink.celestial.test.mjs index 6e2cd935c0..aa679c105e 100644 --- a/src/sharelink.celestial.test.mjs +++ b/src/sharelink.celestial.test.mjs @@ -158,6 +158,37 @@ test('share-link serialization emits the current celestial state', () => { assert.equal(new URLSearchParams(window.location.hash.slice(1)).get('cr'), '1'); }); +test('Sonar beside the HUD layout rides as hs only when on, and through the compact link', async () => { + // Links made before `hs` name no Sonar. + assert.equal(makeManager('#v=2&lat=10&lon=20&hud=minimal').parseInitialHash().hudSonar, false); + assert.equal(makeManager('#v=2&lat=10&lon=20&hud=minimal&hs=1').parseInitialHash().hudSonar, true); + + const manager = makeManager(); + manager.onToggleChange(false, false, { hudVariant: 'minimal', hudSonar: false }); + assert.equal(manager._buildHashParams().has('hs'), false, 'off writes nothing'); + assert.equal(sharedState(manager.buildLink()).hudSonar, false); + manager.onToggleChange(false, false, { hudVariant: 'minimal', hudSonar: true }); + assert.equal(manager._buildHashParams().get('hs'), '1'); + const shared = sharedState(manager.buildLink()); + assert.equal(shared.hudVariant, 'minimal'); + assert.equal(shared.hudSonar, true); + // Tactical with Sonar is written as the Cyber layout code alone. + manager.onToggleChange(false, false, { hudVariant: 'cyber', hudSonar: false }); + assert.equal(manager._buildHashParams().get('hud'), 'cyber'); + assert.equal(manager._buildHashParams().has('hs'), false); + assert.equal(sharedState(manager.buildLink()).hudVariant, 'cyber'); + clearTimeout(manager._debounceTimer); + + // The restore hands it to the visual settings beside the layout. + const opened = makeManager('#v=2&lat=40&lon=-74&hud=minimal&hs=1'); + let restored = null; + opened._onRestore = (state) => { restored = state; }; + opened._isNavigationCurrent = () => false; + await opened.applyState(opened.parseInitialHash(), { navigationToken: 1 }); + assert.equal(restored.hudVariant, 'minimal'); + assert.equal(restored.hudSonar, true); +}); + test('generated links are v2 and include deterministic layers, options, style params, and panels', () => { const manager = makeManager(); const layers = createDefaultLayerState(); diff --git a/src/sharelink.js b/src/sharelink.js index 063a2792b2..1ddfeeb326 100644 --- a/src/sharelink.js +++ b/src/sharelink.js @@ -94,6 +94,8 @@ export class ShareLinkManager { this._bloomVersion = BLOOM_SCALE_VERSION; this._sharpenIntensity = 49; this._hudVariant = 'tactical'; + // Sonar on beside a layout whose code cannot say so (Minimal); `hs`. + this._hudSonar = false; this._hudVisible = false; this._detectionMode = 'OFF'; this._detectionDensity = 50; @@ -260,6 +262,9 @@ export class ShareLinkManager { bloomVersion: parseOr(params.get('bv'), 1), sharpenIntensity: parseOr(params.get('si'), 49), hudVariant: params.get('hud') || 'tactical', + // Absent in links made before it, which restore Sonar from `hud=cyber` + // alone. + hudSonar: params.get('hs') === '1', hudVisible: params.get('hv') === '1', detectionMode: restoredDetection.enabled ? restoredDetection.profile @@ -477,6 +482,7 @@ export class ShareLinkManager { bloomVersion: visualCurrent ? state.bloomVersion : undefined, sharpenIntensity: visualCurrent ? state.sharpenIntensity : undefined, hudVariant: visualCurrent ? state.hudVariant : undefined, + hudSonar: visualCurrent ? state.hudSonar : undefined, hudVisible: visualCurrent ? state.hudVisible : undefined, detectionMode: visualCurrent ? state.detectionMode : undefined, detectionDensity: visualCurrent ? state.detectionDensity : undefined, @@ -627,6 +633,7 @@ export class ShareLinkManager { this._sharpenIntensity = extras.sharpenIntensity; if (typeof extras.hudVariant === 'string') this._hudVariant = extras.hudVariant; + if (typeof extras.hudSonar === 'boolean') this._hudSonar = extras.hudSonar; if (typeof extras.hudVisible === 'boolean') this._hudVisible = extras.hudVisible; if (typeof extras.detectionMode === 'string') @@ -786,6 +793,8 @@ export class ShareLinkManager { params.set('bv', Math.round(this._bloomVersion).toString()); params.set('si', Math.round(this._sharpenIntensity).toString()); params.set('hud', this._hudVariant); + // Only written when on, so a link without Sonar keeps its old form. + if (this._hudSonar) params.set('hs', '1'); params.set('hv', this._hudVisible ? '1' : '0'); params.set('dm', this._detectionMode); params.set('dd', Math.round(this._detectionDensity).toString()); diff --git a/src/ui/hudSonarStyle.test.mjs b/src/ui/hudSonarStyle.test.mjs index 08816d8a9d..391eefa55b 100644 --- a/src/ui/hudSonarStyle.test.mjs +++ b/src/ui/hudSonarStyle.test.mjs @@ -28,6 +28,13 @@ import { setCyberSonarControls } from './cyberSonarControls.js'; import { createPinia } from 'pinia'; import { useDisplayStore } from './stores/display.js'; import { VisualSettings } from './visualSettings.js'; +import { normalizeShot } from '../scenes/project.js'; +import { + SCENE_DOCUMENT_VERSION, + validateSceneDocument, +} from '../director/document.js'; +import { decodeShareView, encodeShareView } from '../share/viewCodec.js'; +import { toLegacyShareState } from '../share/legacyShareState.js'; import { STYLES } from './visualPresets.js'; const read = (relative) => @@ -140,9 +147,10 @@ test('a share link, scene or saved view naming Cyber opens Tactical with Sonar o assert.equal(isCyberSonarEnabled(root), true); }); -test('links and scene shots record Tactical with Sonar as the Cyber code, and only that', (t) => { - const { owner, root } = styleOwner(t, 'tactical'); - Object.assign(owner.services, { +/** A styleOwner that can also read its share state and scene shot. */ +function sharingOwner(t, initialVariant) { + const fixture = styleOwner(t, initialVariant); + Object.assign(fixture.owner.services, { getDetectionTuning: () => ({ allocationStrategy: 'ELASTIC' }), getDetectionMode: () => 'OFF', isScopeMaskEnabled: () => true, @@ -150,18 +158,94 @@ test('links and scene shots record Tactical with Sonar as the Cyber code, and on getScopeMaskOpacity: () => 1, getScopeTerminusOverride: () => null, }); - owner.readCelestialRing = () => null; - const shared = () => owner._readShareState().options.hudVariant; - assert.equal(shared(), 'tactical'); + fixture.owner.readCelestialRing = () => null; + return fixture; +} + +test('links and scene shots record Tactical with Sonar as the Cyber code, and only that', (t) => { + const { owner, root } = sharingOwner(t, 'tactical'); + const shared = () => { + const { hudVariant, hudSonar } = owner._readShareState().options; + return [hudVariant, hudSonar]; + }; + const shot = () => owner.getVisualState().hud; + assert.deepEqual(shared(), ['tactical', false]); + assert.deepEqual(shot(), { visible: true, variant: 'tactical' }); owner._setCyberSonarEnabled(true); - assert.equal(shared(), 'cyber'); - // Minimal has no code that carries Sonar; it stays local. + // Tactical with Sonar is the Cyber code alone, as older readers expect. + assert.deepEqual(shared(), ['cyber', false]); + assert.deepEqual(shot(), { visible: true, variant: 'cyber' }); + // Minimal has no such code, so Sonar is carried beside it. owner._setHudVariant('minimal'); - assert.equal(shared(), 'minimal'); - owner._setHudVariant('tactical'); - assert.equal(shared(), 'cyber'); + assert.deepEqual(shared(), ['minimal', true]); + assert.deepEqual(shot(), { visible: true, variant: 'minimal', sonar: true }); owner._setCyberSonarEnabled(false); - assert.equal(shared(), 'tactical'); + assert.deepEqual(shared(), ['minimal', false]); + assert.deepEqual(shot(), { visible: true, variant: 'minimal' }); + owner._setHudVariant('tactical'); + assert.deepEqual(shared(), ['tactical', false]); + assert.equal(isCyberSonarEnabled(root), false); +}); + +test('Minimal with Sonar round-trips through a compact link and a scene shot', async (t) => { + const { owner, hud, root } = sharingOwner(t, 'minimal'); + owner._setCyberSonarEnabled(true); + const options = owner._readShareState().options; + const shot = normalizeShot( + JSON.parse(JSON.stringify({ visual: owner.getVisualState() })), + ); + validateSceneDocument({ + version: SCENE_DOCUMENT_VERSION, + scenes: [{ id: 'scene', title: 'Scene', shots: [shot] }], + }); + const code = encodeShareView({ + hudVariant: options.hudVariant, + hudSonar: options.hudSonar, + }); + const link = decodeShareView(code, { nowMs: Date.now() }).state; + + // The viewer is elsewhere: Tactical, Sonar off. + owner._setHudVariant('tactical'); + owner._setCyberSonarEnabled(false); + // The HUD fields of the parsed link (the fixture drives no detection). + const { hudVariant, hudSonar } = toLegacyShareState(link); + assert.deepEqual([hudVariant, hudSonar], ['minimal', true]); + await owner.restoreShareState({ hudVariant, hudSonar }); + assert.equal(hud.getVariant(), 'minimal'); + assert.equal(isCyberSonarEnabled(root), true); + + owner._setHudVariant('tactical'); + owner._setCyberSonarEnabled(false); + // The saved shot's HUD, as the editor normalized and validated it. + assert.deepEqual(shot.visual.hud, { + visible: true, + variant: 'minimal', + sonar: true, + }); + await owner.applyVisualState({ hud: shot.visual.hud }); + assert.equal(hud.getVariant(), 'minimal'); + assert.equal(isCyberSonarEnabled(root), true); +}); + +test('a link or scene shot that does not mention Sonar restores as before', async (t) => { + const { owner, hud, root } = sharingOwner(t, 'minimal'); + // Made before Sonar was carried: Minimal turns the viewer's Sonar off... + setCyberSonarEnabled(true, root); + await owner.restoreShareState({ hudVariant: 'minimal' }); + assert.equal(isCyberSonarEnabled(root), false); + setCyberSonarEnabled(true, root); + await owner.applyVisualState({ hud: { variant: 'minimal' } }); + assert.equal(isCyberSonarEnabled(root), false); + // ...and Cyber still opens Tactical with Sonar on. + await owner.restoreShareState({ hudVariant: 'cyber', hudSonar: false }); + assert.equal(hud.getVariant(), 'tactical'); + assert.equal(isCyberSonarEnabled(root), true); + owner._setCyberSonarEnabled(false); + await owner.applyVisualState({ hud: { variant: 'cyber' } }); + assert.equal(isCyberSonarEnabled(root), true); + // Sonar beside a layout counts only in a restore, not a layout choice. + owner._setCyberSonarEnabled(false); + owner._setHudVariant('minimal', { sonar: true }); assert.equal(isCyberSonarEnabled(root), false); }); diff --git a/src/ui/visualSettings.js b/src/ui/visualSettings.js index e9ad998d50..1e2efbf6c0 100644 --- a/src/ui/visualSettings.js +++ b/src/ui/visualSettings.js @@ -73,6 +73,7 @@ export class VisualSettings { bloomVersion, sharpenIntensity, hudVariant, + hudSonar, hudVisible, detectionMode, detectionDensity, @@ -122,7 +123,8 @@ export class VisualSettings { this._setSharpenIntensity(sharpenIntensity, { syncShare: false }); if (typeof bloom === 'boolean') this._setBloomEnabled(bloom); if (typeof sharpen === 'boolean') this._setSharpenEnabled(sharpen); - if (hudVariant) this._setHudVariant(hudVariant, { restore: true }); + if (hudVariant) + this._setHudVariant(hudVariant, { restore: true, sonar: hudSonar }); if (typeof hudVisible === 'boolean') { this.hud.setMode(hudVisible ? 'on' : 'off'); this._updateHudButtonState(); @@ -719,15 +721,21 @@ export class VisualSettings { /** * @param {string} variantName Layout, or the removed `cyber` layout. - * @param {{restore?: boolean}} [options] A share link, scene or saved view - * is authoritative for Sonar too: it is on only when the state names - * Cyber. Other callers leave Sonar as the viewer set it. + * @param {{restore?: boolean, sonar?: boolean}} [options] A share link, + * scene or saved view is authoritative for Sonar too: it is on only when + * the state names Cyber or says `sonar: true`, so a state that does not + * mention Sonar turns it off unless it names Cyber. Other callers leave + * Sonar as the viewer set it. */ - _setHudVariant(variantName, { restore = false } = {}) { + _setHudVariant( + variantName, + { restore = false, sonar: sonarOn = false } = {}, + ) { if (!variantName) return; // Cyber was removed; its sonar became a visual style. A state that names // Cyber opens in Tactical with Sonar on. - const sonar = isLegacySonarHudLayout(variantName); + const sonar = + isLegacySonarHudLayout(variantName) || (restore && sonarOn === true); if (sonar || (restore && isCyberSonarEnabled())) this._setCyberSonarEnabled(sonar); this.hud.setVariant(variantName); @@ -761,8 +769,8 @@ export class VisualSettings { /** * The HUD layout a share link or scene shot records. Tactical with Sonar on - * is written as the retired Cyber code, which restores exactly that; Minimal - * has no such code, so its Sonar stays local. + * is written as the retired Cyber code, which restores exactly that and + * which older readers understand too. */ _sharedHudVariant() { const variant = this.hud.getVariant(); @@ -771,6 +779,17 @@ export class VisualSettings { : variant; } + /** + * Whether a share link or scene shot records Sonar on beside its layout: + * only when the layout code does not already say so (Minimal with Sonar), + * so a state with Tactical and Sonar stays the Cyber code alone. + */ + _sharedHudSonar() { + return ( + isCyberSonarEnabled() && !isLegacySonarHudLayout(this._sharedHudVariant()) + ); + } + _setCyberSonarSetting(name, value) { const settings = readCyberSonarSettings(); if (!Object.hasOwn(settings, name)) return settings; @@ -919,6 +938,7 @@ export class VisualSettings { bloomVersion: BLOOM_SCALE_VERSION, sharpenIntensity: this._sharpenPct, hudVariant: this._sharedHudVariant(), + hudSonar: this._sharedHudSonar(), hudVisible: this.hud.visible, detectionMode: detection.mode, detectionDensity: detection.densityPct, @@ -1237,6 +1257,9 @@ export class VisualSettings { hud: { visible: this.hud.visible, variant: this._sharedHudVariant(), + // Written only when on beside a layout that cannot say it, so a shot + // without Sonar or with Tactical and Sonar reads in older builds. + ...(this._sharedHudSonar() ? { sonar: true } : {}), }, detection: { mode: getDetectionMode(), @@ -1284,7 +1307,10 @@ export class VisualSettings { const hudState = state.hud || {}; if (hudState.variant) { - this._setHudVariant(hudState.variant, { restore: true }); + this._setHudVariant(hudState.variant, { + restore: true, + sonar: hudState.sonar, + }); } if (typeof hudState.visible === 'boolean') { this.hud.setMode(hudState.visible ? 'on' : 'off'); From c49cf5168eb14642a75836a75c3686347db11067 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 18:28:06 -0800 Subject: [PATCH 3/4] Add the changelog entry for #1833 Co-authored-by: Manjunath Paparaju --- changelog.d/1833-hud-credits-sonar-links.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1833-hud-credits-sonar-links.md diff --git a/changelog.d/1833-hud-credits-sonar-links.md b/changelog.d/1833-hud-credits-sonar-links.md new file mode 100644 index 0000000000..c81dbc0590 --- /dev/null +++ b/changelog.d/1833-hud-credits-sonar-links.md @@ -0,0 +1,4 @@ +- Keep the HUD's bottom corners, the Omnibar dock and the corner row clear of + the map credits at every desktop width, also right to left and when the + credits wrap onto several lines; and carry Sonar with the Minimal HUD layout + in share links and scene shots (manjunath22466, samehkhamis, #1833). From 71f40c9655fe5447279fb8d3e451174486cb5f78 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 18:56:00 -0800 Subject: [PATCH 4/4] Keep phone and clean-view credits as they were, and lift narrow corners over the World Timeline The Cesium credit box's width cap and right-to-left placement apply from 1200px as before, and in the Omnibar layout at every width, so the phone shell, clean view, recording and scene playback keep their own layout. Narrower than 1120px the coordinates and the Tactical readout sit above the World Timeline while it shows. The scene format notes that a build from before `sonar` refuses a project that has it. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 4 +- docs/SCENE-DOCUMENT.md | 4 +- src/ui/hudSonarStyle.test.mjs | 38 ++++++++++++++++--- src/ui/styles/command-dock-trays.css | 56 ++++++++++++++++++++-------- src/ui/styles/omnibar-dock.css | 7 ++++ 5 files changed, 87 insertions(+), 22 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 9e3c37ab9b..721350646a 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1192,7 +1192,9 @@ 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 dock, and above the World Timeline while it shows. Outside that layout +Cesium's credit box wraps from 1200px, as before; the phone shell, clean +view, recording and scene playback lay the line out themselves. 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. diff --git a/docs/SCENE-DOCUMENT.md b/docs/SCENE-DOCUMENT.md index 5670e11068..948062c8e0 100644 --- a/docs/SCENE-DOCUMENT.md +++ b/docs/SCENE-DOCUMENT.md @@ -59,7 +59,9 @@ Visual fields are `style`, `mapStack`, `styleParams`, `bloom`, `sharpen`, `hud`, HUD `sonar: true` is Sonar on beside a layout that cannot say it (Minimal); it is written only then, so Tactical with Sonar stays the variant `cyber` and a shot without Sonar has no `sonar`. A shot without it opens with Sonar on only -when its variant is `cyber`. +when its variant is `cyber`. A build from before `sonar` refuses a project +that has it, as it refuses any field it does not know; every other project +still opens there. The latter settings were written by Update Shot but previously lost during normalization; they now survive import and capture. Version-1/2 bloom without an explicit scale version uses the original inverted diff --git a/src/ui/hudSonarStyle.test.mjs b/src/ui/hudSonarStyle.test.mjs index 391eefa55b..0892e07480 100644 --- a/src/ui/hudSonarStyle.test.mjs +++ b/src/ui/hudSonarStyle.test.mjs @@ -542,10 +542,14 @@ 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;/, ); - // 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;/, + // From 1200px, and in the Omnibar layout at every width: a long line + // wraps rather than running under the corner row. + const box = trayWide.match( + /\n\s*#cesium-credits \.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - ([\d.]+)rem\);\s*white-space: normal;/, + ); + assert.match( + trays, + /:has\(#command-dock > #gev-voice-control\)\s*\)\s*#cesium-credits\s*\.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - 26rem\);/, ); return anchor && box && [null, anchor[1], box[1]]; })(), @@ -576,9 +580,16 @@ test('the desktop bottom row: credits on the Power Up baseline, the dock lifted, trayWide, /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;/, ); + // Its box hangs from the anchor's right edge there, and in the Omnibar + // layout at every width; never in clean view or recording, where the + // anchor stays on the left. + assert.match( + trayWide, + /body:not\(\.context-docked\):not\(\.ui-clean-view\):not\(\.recording-mode\)\s*#cesium-credits\s*\.cesium-widget-credits \{\s*right: 0;\s*left: auto;/, + ); assert.match( trays, - /html\[dir='rtl'\] #cesium-credits \.cesium-widget-credits \{\s*right: 0;\s*left: auto;/, + /html\[dir='rtl'\]\s*body:not\(\.mobile-shell\)[^{]*:not\(\.recording-mode\):not\(\.context-docked\)[^{]*#cesium-credits\s*\.cesium-widget-credits \{\s*right: 0;\s*left: auto;/, ); // There the readout clears the row under it, however many lines it wraps // onto (--credit-line-height). @@ -757,3 +768,20 @@ test('shared panel hooks affect only opted-in rail surfaces without overriding d /body:is\(\.ui-clean-view, \.recording-mode\)[^{]+\{[^}]*visibility: hidden !important;[^}]*pointer-events: none !important;/, ); }); + +test('narrow Omnibar corners clear the World Timeline over the dock', () => { + const css = read('./styles/omnibar-dock.css'); + const timeline = css.match( + /#world-timeline \{\s*bottom: calc\(var\(--omnibar-dock-bottom\) \+ (\d+)px\);/, + ); + const height = read('./styles/world-timeline.css').match( + /#world-timeline \{[^}]*\n {2}height: (\d+)px;/, + ); + const corners = css.match( + /&:has\(#world-timeline\) \{\s*--omnibar-coordinates-bottom: max\(\s*calc\(var\(--omnibar-dock-bottom\) \+ (\d+)px \+ (\d+)px \+ (\d+)px\)/, + ); + assert.ok(timeline && height && corners); + assert.equal(Number(corners[1]), Number(timeline[1])); + assert.equal(Number(corners[2]), Number(height[1])); + assert.ok(Number(corners[3]) >= 6); +}); diff --git a/src/ui/styles/command-dock-trays.css b/src/ui/styles/command-dock-trays.css index c547cc448c..850f7f4e12 100644 --- a/src/ui/styles/command-dock-trays.css +++ b/src/ui/styles/command-dock-trays.css @@ -501,16 +501,13 @@ 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). 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)); - } + (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)); } @media (max-width: 1199px) { @@ -532,21 +529,42 @@ body:not(.ui-clean-view):not(.recording-mode):has( } /* 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 { + #cesium-credits anchor, so the cap and the wrapping go on that box: from + 1200px, and in the Omnibar layout at every width, whose attribution row + shares the bottom edge with the corner row (omnibar-dock.css). */ +body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not( + .ui-clean-view + ):not(.recording-mode):where( + :has(#gev-omnibar):has(#command-dock > #gev-voice-control) + ) + #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 to left that layout puts the row at the bottom right at every + width, so the box hangs from the anchor's right edge. */ +html[dir='rtl'] + body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not( + .ui-clean-view + ):not(.recording-mode):not(.context-docked):where( + :has(#gev-omnibar):has(#command-dock > #gev-voice-control) + ) + #cesium-credits + .cesium-widget-credits { right: 0; left: auto; } @media (min-width: 1200px) { + #cesium-credits .cesium-widget-credits { + width: max-content; + max-width: calc(100vw - 1.5rem - 26rem); + white-space: normal; + } + /* 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). */ @@ -564,6 +582,14 @@ html[dir='rtl'] #cesium-credits .cesium-widget-credits { 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 e60d5b5d4d..e9faafcdb2 100644 --- a/src/ui/styles/omnibar-dock.css +++ b/src/ui/styles/omnibar-dock.css @@ -368,6 +368,13 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not( calc(var(--omnibar-dock-bottom) + 56px + 10px), var(--omnibar-credits-clear) ); + /* And above the World Timeline (42px tall) over the dock. */ + &:has(#world-timeline) { + --omnibar-coordinates-bottom: max( + calc(var(--omnibar-dock-bottom) + 66px + 42px + 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']