Show the renderer's credits in the application's own line

- On a renderer whose plugin does not show its credits in a display of
  its own (the ownCreditDisplay hook; Cesium's does), the application
  shows what the credits port lists at the bottom left (#gev-credits):
  inline credits on the line, the rest, the layers' data credits among
  them, in the Data attribution list it opens. The button and list are
  keyboard operable; Escape closes the list and returns focus. Text is set
  as text; links and logos keep only safe schemes.
- The panel, Cockpit and overlay layouts keep clear of it as of Cesium's.
- The stub boot check fails when the credits line is not shown or its list
  is empty; it keeps its report when the run stops early, counts only the
  dev server's providers and other origins as feeds, and a failed default
  renderer load is retried without dropping a newer one.
This commit is contained in:
Sameh Khamis committed 2026-11-10 18:29:47 -08:00
1 parent 691cb0cd79
commit 16c7034c28
15 files changed
+411 -18

No files matched your search

+1
View File
@@ -99,6 +99,7 @@ export function syncContextLayout() {
let safeBottom = window.innerHeight - 24;
for (const selector of [
'#cesium-credits',
'#gev-credits',
'#command-dock',
'#view-switcher',
]) {
+150
View File
@@ -0,0 +1,150 @@
/**
* @module ui/creditsView
* @description The attribution line, in the application's own DOM, for a
* renderer that does not draw its own credit display: what the renderer's
* credits port lists (its own credits, each base layer's, the layers' data
* credits). Inline credits are shown on the line at the bottom left; the
* rest are in the "Data attribution" list it opens. A credit is plain data
* (`src/render/contract/credits.d.ts`): its text is set as text, and a link
* or logo is kept only for a safe scheme.
*/
import { findCredits } from '../render/rendererOf.js';
import { LINK_SCHEMES, LOGO_SCHEMES, safeUrl } from '../render/creditMarkup.js';
import { onLocaleChange, t } from '../i18n/index.js';
const PANEL_ID = 'gev-credits-panel';
/** The credits once each, in order: the same text and link are one. */
function distinct(list) {
const seen = new Set();
return list.filter((credit) => {
const key = `${credit?.text ?? ''}\u0000${credit?.href ?? ''}`;
if (!credit?.text || seen.has(key)) return false;
seen.add(key);
return true;
});
}
/** One credit as DOM: its logo, then its text, linked when it has a link. */
function creditElement(doc, credit) {
const href = credit.href ? safeUrl(credit.href, LINK_SCHEMES) : null;
const element = doc.createElement(href ? 'a' : 'span');
element.className = 'gev-credit';
if (href) {
element.href = href;
element.target = '_blank';
element.rel = 'noopener';
}
const logo = credit.logoUrl ? safeUrl(credit.logoUrl, LOGO_SCHEMES) : null;
if (logo) {
const image = doc.createElement('img');
image.className = 'gev-credit-logo';
image.src = logo;
image.alt = credit.text;
element.append(image);
} else element.textContent = credit.text;
return element;
}
/**
* Show `viewer`'s renderer credits at the bottom left of `root`'s page.
* @param {object} viewer The scene object, bound to its renderer.
* @param {{root?: HTMLElement}} [options] Where the line goes (the body).
* @returns {() => void} Removes it.
*/
export function mountCreditsView(viewer, { root = document.body } = {}) {
const credits = findCredits(viewer);
if (!credits || !root) return () => {};
const doc = root.ownerDocument;
const bar = doc.createElement('div');
bar.id = 'gev-credits';
bar.className = 'gev-credits';
const line = doc.createElement('span');
line.className = 'gev-credits-line';
const expand = doc.createElement('button');
expand.type = 'button';
expand.className = 'gev-credits-expand';
expand.setAttribute('aria-haspopup', 'dialog');
expand.setAttribute('aria-controls', PANEL_ID);
expand.setAttribute('aria-expanded', 'false');
const panel = doc.createElement('div');
panel.id = PANEL_ID;
panel.className = 'gev-credits-panel';
panel.setAttribute('role', 'dialog');
panel.hidden = true;
const header = doc.createElement('div');
header.className = 'gev-credits-header';
const title = doc.createElement('span');
title.className = 'gev-credits-title';
title.id = `${PANEL_ID}-title`;
panel.setAttribute('aria-labelledby', title.id);
const close = doc.createElement('button');
close.type = 'button';
close.className = 'gev-credits-close';
close.textContent = '×';
header.append(title, close);
const list = doc.createElement('ul');
list.className = 'gev-credits-list';
panel.append(header, list);
bar.append(line, expand);
root.append(bar, panel);
const label = () => {
expand.textContent = t('Data attribution');
title.textContent = t('Data provided by:');
close.setAttribute('aria-label', t('Close data attribution'));
};
const setOpen = (open, { focus = false } = {}) => {
panel.hidden = !open;
expand.setAttribute('aria-expanded', String(open));
if (open) close.focus();
else if (focus) expand.focus();
};
const render = (all) => {
const shown = distinct(Array.isArray(all) ? all : []);
const inline = shown.filter((credit) => credit.inline);
const listed = shown.filter((credit) => !credit.inline);
line.replaceChildren();
inline.forEach((credit, i) => {
if (i) line.append(doc.createTextNode(' · '));
line.append(creditElement(doc, credit));
});
if (inline.length && listed.length) line.append(doc.createTextNode(' · '));
list.replaceChildren(
...listed.map((credit) => {
const item = doc.createElement('li');
item.append(creditElement(doc, credit));
return item;
}),
);
expand.hidden = listed.length === 0;
if (expand.hidden && !panel.hidden) setOpen(false);
};
const onExpand = () => setOpen(panel.hidden);
const onClose = () => setOpen(false, { focus: true });
const onKey = (event) => {
if (event.key !== 'Escape' || panel.hidden) return;
event.preventDefault();
setOpen(false, { focus: true });
};
expand.addEventListener('click', onExpand);
close.addEventListener('click', onClose);
panel.addEventListener('keydown', onKey);
label();
render(credits.list());
const offChange = credits.on('change', render);
const offLocale = onLocaleChange(label);
return () => {
offChange();
offLocale();
expand.removeEventListener('click', onExpand);
close.removeEventListener('click', onClose);
panel.removeEventListener('keydown', onKey);
bar.remove();
panel.remove();
};
}
+66
View File
@@ -0,0 +1,66 @@
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { mountCreditsView } from './creditsView.js';
import { bindRenderer } from '../render/rendererOf.js';
import { createStubRenderer } from '../render/stub/index.js';
function scene() {
document.body.replaceChildren();
const renderer = createStubRenderer();
const viewer = {};
bindRenderer(viewer, renderer);
return { viewer, renderer };
}
test("the renderer's credits show on the line, and the rest in the list it opens", () => {
const { viewer, renderer } = scene();
renderer.credits.addStatic({
text: 'Google',
href: 'https://maps.google.com',
inline: true,
});
const off = mountCreditsView(viewer);
const line = document.querySelector('#gev-credits .gev-credits-line');
assert.equal(line.textContent, 'Google');
assert.equal(line.querySelector('a').href, 'https://maps.google.com/');
const expand = document.querySelector('.gev-credits-expand');
assert.equal(expand.hidden, true, 'nothing to list yet');
const remove = renderer.credits.addStatic({ text: 'Wildlife: iNaturalist' });
renderer.credits.addStatic({ text: 'Wildlife: iNaturalist' });
renderer.credits.addStatic({ text: 'OSM', href: 'javascript:alert(1)' });
assert.equal(expand.hidden, false);
assert.equal(expand.textContent, 'Data attribution');
const panel = document.getElementById('gev-credits-panel');
assert.equal(panel.hidden, true);
expand.click();
assert.equal(panel.hidden, false);
assert.equal(expand.getAttribute('aria-expanded'), 'true');
const items = [...panel.querySelectorAll('li')].map((li) => li.textContent);
assert.deepEqual(items, ['Wildlife: iNaturalist', 'OSM'], 'once each');
assert.equal(panel.querySelector('li:last-child a'), null, 'unsafe link');
panel.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }),
);
assert.equal(panel.hidden, true);
assert.equal(document.activeElement, expand, 'focus goes back');
remove();
assert.equal(
[...panel.querySelectorAll('li')].length,
2,
'a duplicate still credits it',
);
off();
assert.equal(document.getElementById('gev-credits'), null);
assert.equal(document.getElementById('gev-credits-panel'), null);
});
test('a viewer with no renderer shows no credits line', () => {
document.body.replaceChildren();
const off = mountCreditsView({});
assert.equal(document.getElementById('gev-credits'), null);
off();
});
+9 -6
View File
@@ -27,6 +27,7 @@ const LEFT_STACK_OBSTACLE_SELECTOR = [
'#cockpit-context',
'#cesium-credits .cesium-credit-logoContainer',
'#cesium-credits .cesium-credit-textContainer',
'#gev-credits',
'#location-bar',
'#control-panel',
'#gev-voice-control',
@@ -58,6 +59,7 @@ const RIGHT_STACK_OBSTACLE_SELECTOR = [
'#cockpit-signal-stream',
'#cesium-credits .cesium-credit-logoContainer',
'#cesium-credits .cesium-credit-textContainer',
'#gev-credits',
'#command-dock',
'#gev-voice-control',
'#world-timeline',
@@ -342,12 +344,13 @@ export class PanelLayoutController {
attributeFilter: ['class', 'data-variant'],
});
}
const credits = document.getElementById('cesium-credits');
if (credits) {
this._leftStackMutationObserver.observe(credits, {
subtree: true,
childList: true,
});
for (const id of ['cesium-credits', 'gev-credits']) {
const credits = document.getElementById(id);
if (credits)
this._leftStackMutationObserver.observe(credits, {
subtree: true,
childList: true,
});
}
}
+91
View File
@@ -332,6 +332,97 @@ body.cockpit-mode #cockpit-cloud-effects.active {
color: rgba(232, 234, 237, 0.7);
}
/* The application's own attribution line (src/ui/creditsView.js), for a
renderer without a credit display of its own: the same place and look. */
#gev-credits {
position: fixed;
bottom: 36px;
left: 36px;
z-index: 90;
max-width: 90vw;
white-space: nowrap;
pointer-events: auto;
font-family: var(--font-mono);
font-size: 10px;
color: rgba(232, 234, 237, 0.55);
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
#gev-credits a,
#gev-credits .gev-credits-expand {
color: rgba(232, 234, 237, 0.7);
}
#gev-credits .gev-credit-logo {
height: 14px;
vertical-align: middle;
}
#gev-credits .gev-credits-expand {
padding: 0;
border: 0;
background: none;
font: inherit;
text-decoration: underline;
cursor: pointer;
}
.gev-credits-panel {
position: fixed;
bottom: 60px;
left: 36px;
z-index: 200;
display: flex;
flex-direction: column;
width: 470px;
max-width: calc(100vw - 2rem);
max-height: min(70dvh, 36rem);
overflow: hidden;
border: 1px solid rgba(232, 234, 237, 0.2);
border-radius: 6px;
background: rgba(16, 18, 22, 0.94);
color: rgba(232, 234, 237, 0.85);
font-family: var(--font-mono);
font-size: 12px;
}
.gev-credits-panel[hidden] {
display: none;
}
.gev-credits-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 14px 4px 20px;
}
.gev-credits-close {
border: 0;
background: none;
color: inherit;
font-size: 18px;
cursor: pointer;
}
.gev-credits-list {
flex: 1;
min-height: 0;
margin: 0;
padding: 4px 20px 14px 40px;
overflow-y: auto;
overscroll-behavior: contain;
line-height: 1.35;
}
.gev-credits-list > li {
padding-bottom: 5px;
overflow-wrap: anywhere;
}
.gev-credits-list a {
color: rgba(232, 234, 237, 0.85);
}
@media (max-width: 575px) {
.gev-credits-panel {
inset: 0;
width: 100%;
max-width: none;
max-height: 100dvh;
border-radius: 0;
}
}
/* Cesium's stock attribution lightbox grows with every registered data source.
Keep the title and close affordance fixed while the complete, unabridged
credit list wraps and scrolls inside a compact panel. */