refactor(hud): share the warning line and trim the summary helpers

One provenanceLine() builds STATE | text | LAYERS for the HUD and
get_hud_caption. hasWord is one lookaround regex, capAtWord one grapheme
pass. Feed-state helpers are imported from layerSnapshot.js directly, and the
kept-whole sanitizer cases are one table.
This commit is contained in:
German Khokhlov committed 2026-11-03 14:45:32 +04:00
1 parent ab8691383b
commit 03c168d7c9
6 files changed
+93 -117

No files matched your search

+15 -15
View File
@@ -35,12 +35,15 @@ import {
hasWord,
hudSummaryHasEnglish,
hudSummaryIsLatin,
hudSummaryMatchesProvenance,
hudSummaryLayerContext,
hudTelemetryProvenance,
isHudSummaryUnconfigured,
provenanceTag,
} from './hudSummaryResponse.js';
import {
hudSummaryMatchesProvenance,
provenanceLine,
provenanceTag,
} from './data/layerSnapshot.js';
import {
applyHudUiTheme,
DEFAULT_HUD_LAYOUT,
@@ -119,20 +122,17 @@ const FEED_STATE_LABELS = Object.freeze({
unavailable: msg('UNAVAILABLE'),
});
/**
* A summary line with its translated warning:
* `UNAVAILABLE | <text> | LIVE AIS VESSELS`. The state leads so a narrow
* readout never clips it; the layer names trail so they never push out the text.
*/
/** A summary line with its warning in the active language. */
function withProvenance(text, provenance) {
if (!provenance) return text;
const state = FEED_STATE_LABELS[provenance.state]
? t(FEED_STATE_LABELS[provenance.state])
: provenance.state.toUpperCase();
const layers = provenance.names
.map((name) => localizeLayerName(name).toUpperCase())
.join('/');
return [state, text, layers].filter(Boolean).join(' | ');
return provenanceLine(
text,
provenance,
(state) =>
FEED_STATE_LABELS[state]
? t(FEED_STATE_LABELS[state])
: state.toUpperCase(),
(name) => localizeLayerName(name).toUpperCase(),
);
}
/**