feat(overlay): flash the row on a new time, ticking pit clock and split badges (1.88.0)
This commit is contained in:
1 parent
ee290a4ab8
commit
f5b77d5589
11 files changed
+304
-6
No files matched your search
@@ -3,6 +3,7 @@ import { getSyncStatus } from "./sync_status.js";
|
||||
import { installListSorting } from "./list_sorting.js";
|
||||
import { escapeHtml } from "./html_escape.js";
|
||||
import { getOverlayModeLabel, buildOverlayPanels, renderOverlaySidePanel, renderOverlayLeaderboard, renderTeamOverlay, renderObsOverlay } from "./overlays.js";
|
||||
import { refreshLiveMarkNodes } from "./overlay_live_marks.js";
|
||||
|
||||
import { renderSettings, openSettingsTab } from "./settings.js";
|
||||
import { buildRaceDayQueue, buildRaceDayPreflight, getRaceDriverIds, shouldOfferFinals } from "./race_day_logic.js";
|
||||
@@ -811,6 +812,7 @@ const refreshOverlayDynamics = () => {
|
||||
node.textContent = clock;
|
||||
});
|
||||
|
||||
refreshLiveMarkNodes(document);
|
||||
const rowsByKey = new Map(buildLeaderboard(active).map((row) => [String(row.key), row]));
|
||||
document.querySelectorAll("[data-overlay-competitor]").forEach((node) => {
|
||||
const row = rowsByKey.get(String(node.dataset.overlayCompetitor || ""));
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Live marks on overlay rows: a short flash when a driver gets a new time, a ticking pit
|
||||
// clock while in the pits (then the stop time for a few seconds), and a new split for a few
|
||||
// seconds. Everything runs on this computer's clock from the moment the overlay saw the
|
||||
// change - the decoder's clock may differ, and a page just opened must not flash every row.
|
||||
|
||||
export const PASSING_FLASH_MS = 700;
|
||||
export const PIT_DONE_SHOW_MS = 5000;
|
||||
export const SPLIT_SHOW_MS = 4000;
|
||||
const MAX_PIT_FALLBACK_MS = 15 * 60 * 1000;
|
||||
|
||||
export function createOverlayLiveMarks({ now = () => Date.now() } = {}) {
|
||||
const seen = new Map();
|
||||
|
||||
// Call with the rows about to be drawn; returns the marks for each row key.
|
||||
function observe(rows) {
|
||||
const at = now();
|
||||
const marks = new Map();
|
||||
(Array.isArray(rows) ? rows : []).forEach((row) => {
|
||||
const key = String(row?.key ?? "");
|
||||
if (!key) return;
|
||||
const lastTimestamp = Number(row.lastTimestamp || 0);
|
||||
const splitTimestamp = Number(row.lastSplitTimestamp || 0);
|
||||
const pitActive = Boolean(row.pitActive);
|
||||
const pitStops = Number(row.pitStops || 0);
|
||||
const previous = seen.get(key);
|
||||
const entry = previous || { passingAt: 0, splitAt: 0, pitStartAt: 0, pitDoneAt: 0 };
|
||||
if (!previous) {
|
||||
// First sight: no flash, but a car already in the pits gets a clock from its entry time.
|
||||
if (pitActive) {
|
||||
const sinceEntry = at - Number(row.pitEnteredAt || 0);
|
||||
entry.pitStartAt = sinceEntry > 0 && sinceEntry < MAX_PIT_FALLBACK_MS ? at - sinceEntry : at;
|
||||
}
|
||||
} else {
|
||||
if (lastTimestamp && lastTimestamp !== previous.lastTimestamp) entry.passingAt = at;
|
||||
if (splitTimestamp && splitTimestamp !== previous.splitTimestamp) entry.splitAt = at;
|
||||
if (pitActive && !previous.pitActive) entry.pitStartAt = at;
|
||||
if (!pitActive && previous.pitActive && pitStops > previous.pitStops) entry.pitDoneAt = at;
|
||||
if (!pitActive) entry.pitStartAt = 0;
|
||||
}
|
||||
Object.assign(entry, { lastTimestamp, splitTimestamp, pitActive, pitStops });
|
||||
seen.set(key, entry);
|
||||
|
||||
const passingAgeMs = entry.passingAt ? at - entry.passingAt : Infinity;
|
||||
const splitAgeMs = entry.splitAt ? at - entry.splitAt : Infinity;
|
||||
const pitDoneAgeMs = entry.pitDoneAt ? at - entry.pitDoneAt : Infinity;
|
||||
marks.set(key, {
|
||||
passingAgeMs: passingAgeMs < PASSING_FLASH_MS ? passingAgeMs : null,
|
||||
pit: pitActive
|
||||
? { active: true, startAt: entry.pitStartAt }
|
||||
: pitDoneAgeMs < PIT_DONE_SHOW_MS && Number(row.lastPitStopMs) > 0
|
||||
? { active: false, stopMs: Number(row.lastPitStopMs), hideAt: entry.pitDoneAt + PIT_DONE_SHOW_MS }
|
||||
: null,
|
||||
split: splitAgeMs < SPLIT_SHOW_MS && Number(row.lastSplitMs) > 0
|
||||
? { ms: Number(row.lastSplitMs), deltaMs: Number.isFinite(row.lastSplitDeltaMs) ? row.lastSplitDeltaMs : null, hideAt: entry.splitAt + SPLIT_SHOW_MS }
|
||||
: null,
|
||||
});
|
||||
});
|
||||
return marks;
|
||||
}
|
||||
|
||||
return { observe, reset: () => seen.clear() };
|
||||
}
|
||||
|
||||
// "0:12.4" - the running pit clock.
|
||||
export function formatPitClock(ms) {
|
||||
const tenths = Math.max(0, Math.floor(Number(ms || 0) / 100));
|
||||
const seconds = Math.floor(tenths / 10);
|
||||
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}.${tenths % 10}`;
|
||||
}
|
||||
|
||||
const FUEL_ICON = '<svg class="overlay-fuel-icon" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M4 3h9a1 1 0 0 1 1 1v8h1a2 2 0 0 1 2 2v3a1 1 0 0 0 2 0V9.4l-2.7-2.7 1.4-1.4 3 3c.2.2.3.5.3.7V17a3 3 0 0 1-6 0v-3h-1v6h1v2H2v-2h1V4a1 1 0 0 1 1-1Zm1 2v5h7V5H5Z"/></svg>';
|
||||
|
||||
// Row class + style for the passing flash. A negative delay lets a re-render pick the
|
||||
// animation up where it was instead of starting it over.
|
||||
export function passingFlashAttrs(mark) {
|
||||
if (!mark || mark.passingAgeMs == null) return { className: "", style: "" };
|
||||
return { className: " is-passing", style: ` style="--pass-delay:-${Math.round(mark.passingAgeMs)}ms"` };
|
||||
}
|
||||
|
||||
// Pit badge and split chip shown next to the driver's time.
|
||||
export function renderLiveMarkBadges(mark, { formatLap, escapeHtml, nowMs = Date.now(), labels = {} }) {
|
||||
if (!mark) return "";
|
||||
const parts = [];
|
||||
if (mark.pit?.active) {
|
||||
parts.push(`<span class="overlay-pit-badge is-active" title="${escapeHtml(labels.pit || "")}" data-pit-clock="${Math.round(mark.pit.startAt)}">${FUEL_ICON}<b>${formatPitClock(nowMs - mark.pit.startAt)}</b></span>`);
|
||||
} else if (mark.pit) {
|
||||
parts.push(`<span class="overlay-pit-badge is-done" title="${escapeHtml(labels.pit || "")}" data-live-hide-at="${Math.round(mark.pit.hideAt)}">${FUEL_ICON}<b>${escapeHtml(formatLap(mark.pit.stopMs))}</b></span>`);
|
||||
}
|
||||
if (mark.split) {
|
||||
const delta = mark.split.deltaMs == null ? "" : ` <i class="${mark.split.deltaMs <= 0 ? "is-faster" : "is-slower"}">${mark.split.deltaMs <= 0 ? "−" : "+"}${(Math.abs(mark.split.deltaMs) / 1000).toFixed(3)}</i>`;
|
||||
parts.push(`<span class="overlay-split-chip" title="${escapeHtml(labels.split || "")}" data-live-hide-at="${Math.round(mark.split.hideAt)}">S ${escapeHtml(formatLap(mark.split.ms))}${delta}</span>`);
|
||||
}
|
||||
return parts.length ? `<span class="overlay-live-marks">${parts.join("")}</span>` : "";
|
||||
}
|
||||
|
||||
// Called by the overlay's 250 ms tick: run the pit clocks and drop marks whose time is up,
|
||||
// without redrawing the rows.
|
||||
export function refreshLiveMarkNodes(root, nowMs = Date.now()) {
|
||||
root.querySelectorAll("[data-pit-clock]").forEach((node) => {
|
||||
const label = node.querySelector("b");
|
||||
if (label) label.textContent = formatPitClock(nowMs - Number(node.dataset.pitClock || nowMs));
|
||||
});
|
||||
root.querySelectorAll("[data-live-hide-at]").forEach((node) => {
|
||||
if (nowMs >= Number(node.dataset.liveHideAt || 0)) node.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// The overlay page's shared instance.
|
||||
export const overlayLiveMarks = createOverlayLiveMarks();
|
||||
+15
-3
@@ -1,5 +1,6 @@
|
||||
import { sortValuesAttribute } from "./list_sorting.js";
|
||||
import { escapeHtml as escapeHtmlLocal } from "./html_escape.js";
|
||||
import { overlayLiveMarks, passingFlashAttrs, renderLiveMarkBadges } from "./overlay_live_marks.js";
|
||||
export function getOverlayModeLabel(mode, { t }) {
|
||||
return t(`overlay.mode_${String(mode || "leaderboard").toLowerCase()}`);
|
||||
}
|
||||
@@ -69,6 +70,8 @@ export function renderOverlayLeaderboard(rows, { t, escapeHtml, formatTeamActive
|
||||
// More than 12 cars (a busy Open Practice): compact rows so all of them fit on a TV that
|
||||
// can't scroll - no per-cell labels (the header names the columns), sub-line or prediction bar.
|
||||
const compact = rows.length > 12;
|
||||
const liveMarks = overlayLiveMarks.observe(rows);
|
||||
const markLabels = { pit: t("table.pit"), split: t("table.split") };
|
||||
return `
|
||||
<div class="overlay-race-list ${compact ? "overlay-race-list-compact" : ""}"${sortAttrs}>
|
||||
${rows
|
||||
@@ -76,13 +79,15 @@ export function renderOverlayLeaderboard(rows, { t, escapeHtml, formatTeamActive
|
||||
const posClass = idx === 0 ? "pos-1" : idx === 1 ? "pos-2" : idx === 2 ? "pos-3" : "";
|
||||
const rowSortAttr = sortable ? ` data-sort-values="${sortValuesAttribute([idx + 1, row.displayName || row.driverName, row.laps ?? 0, row.resultDisplay, row.gapDisplay || row.gapAhead || null, row.gapAhead || null, row.lapDelta || null, row.bestLapMs || null])}"` : "";
|
||||
const linkAttrs = driverLinks && row.driverId && !row.teamId ? ` data-training-driver="${escapeHtml(row.driverId)}" title="${escapeHtml(t("overlay.open_training_stats"))}"` : "";
|
||||
const mark = liveMarks.get(String(row.key ?? ""));
|
||||
const flash = passingFlashAttrs(mark);
|
||||
return `
|
||||
<article class="overlay-race-row ${idx === 0 ? "overlay-race-row-leader" : ""} ${row.invalidPending ? "overlay-race-row-invalid" : ""} ${linkAttrs ? "is-linked" : ""}"${rowSortAttr}${linkAttrs} data-overlay-competitor="${escapeHtml(row.key)}">
|
||||
<article class="overlay-race-row ${idx === 0 ? "overlay-race-row-leader" : ""} ${row.invalidPending ? "overlay-race-row-invalid" : ""} ${linkAttrs ? "is-linked" : ""}${flash.className}"${flash.style}${rowSortAttr}${linkAttrs} data-overlay-competitor="${escapeHtml(row.key)}">
|
||||
<div class="overlay-race-pos">
|
||||
<span class="pos-pill ${posClass}">${idx + 1}</span>
|
||||
</div>
|
||||
<div class="overlay-race-driver">
|
||||
<strong>${escapeHtml(row.displayName || row.driverName)}${row.personalTimeUp ? ` <span class="pill pill-green">🏁 ${t("timing.personal_time_up")}</span>` : ""}${row.suspectPending ? ` <span class="suspect-flag" title="${escapeHtml(t("suspect.flag_title"))}">⚠</span>` : ""}</strong>
|
||||
<strong>${escapeHtml(row.displayName || row.driverName)}${row.personalTimeUp ? ` <span class="pill pill-green">🏁 ${t("timing.personal_time_up")}</span>` : ""}${row.suspectPending ? ` <span class="suspect-flag" title="${escapeHtml(t("suspect.flag_title"))}">⚠</span>` : ""}${renderLiveMarkBadges(mark, { formatLap, escapeHtml, labels: markLabels })}</strong>
|
||||
${row.heatCarName ? `<span class="overlay-heat-car">🚗 ${escapeHtml(row.heatCarName)}</span>` : `<span>${escapeHtml(row.teamId ? `${t("overlay.active_member")}: ${formatTeamActiveMemberLabel(row)}` : row.subLabel || row.transponder || "-")}</span>`}
|
||||
${row.lastSplitMs || row.pitActive || row.pitStops ? `<span class="overlay-decoder-meta">${row.lastSplitMs ? `${t("table.split")}: ${formatLap(row.lastSplitMs)}` : ""}${row.lastSplitMs && (row.pitActive || row.pitStops) ? " • " : ""}${row.pitActive ? t("timing.pit_active") : row.pitStops ? `${t("table.pit")}: ${row.pitStops} / ${formatLap(row.totalPitMs)}` : ""}</span>` : ""}
|
||||
${row.invalidPending ? `<span class="overlay-invalid-note">${escapeHtml(row.invalidLabel)}${row.invalidLapMs ? ` • ${formatLap(row.invalidLapMs)}` : ""}</span>` : ""}
|
||||
@@ -219,11 +224,14 @@ function renderObsBroadcast({ active, compactRows, startOrder, showStartGrid, fa
|
||||
// With laps in their own column the result's "14/" prefix only repeats them.
|
||||
const timeOnly = (value) => (obsConfig.showLaps ? String(value || "").replace(/^\d+\//, "") : String(value || ""));
|
||||
const podium = (place) => (place <= 3 ? ` is-p${place}` : "");
|
||||
const liveMarks = showStartGrid ? null : overlayLiveMarks.observe(compactRows);
|
||||
const rows = showStartGrid
|
||||
? getSessionGridEntries(active).slice(0, obsConfig.rows).map((entry, idx) => `
|
||||
<div class="obs-tv-row${podium(idx + 1)}">${cell("pos", entry.slot)}${cell("name", escapeHtml(entry.name))}</div>`)
|
||||
: compactRows.map((row, idx) => {
|
||||
const start = startOrder.indexOf(row.driverId) + 1;
|
||||
const mark = liveMarks?.get(String(row.key ?? ""));
|
||||
const badges = renderLiveMarkBadges(mark, { formatLap, escapeHtml, labels: { pit: t("table.pit"), split: t("table.split") } });
|
||||
const values = {
|
||||
pos: idx + 1,
|
||||
start: start ? `<span class="obs-tv-slash">/</span>${start}` : "",
|
||||
@@ -234,7 +242,11 @@ function renderObsBroadcast({ active, compactRows, startOrder, showStartGrid, fa
|
||||
best: Number.isFinite(row.bestLapMs) ? escapeHtml(formatLap(row.bestLapMs)) : "-",
|
||||
gap: escapeHtml(idx === 0 ? "" : row.gapDisplay || row.gapAhead || ""),
|
||||
};
|
||||
return `<div class="obs-tv-row${podium(idx + 1)}${row.driverId === fastestRow?.driverId ? " is-fastest" : ""}">${columns.map(([key]) => cell(key, values[key])).join("")}</div>`;
|
||||
// Pit clock and split at the end of the name column, the one flexible column - in
|
||||
// the time columns they would push every other column out of line.
|
||||
if (badges) values.name = `<span class="obs-tv-name-text">${values.name}</span>${badges}`;
|
||||
const flash = passingFlashAttrs(mark);
|
||||
return `<div class="obs-tv-row${podium(idx + 1)}${row.driverId === fastestRow?.driverId ? " is-fastest" : ""}${flash.className}"${flash.style}>${columns.map(([key]) => cell(key, values[key])).join("")}</div>`;
|
||||
});
|
||||
const eventName = String(getEventName(active.eventId) || "").trim();
|
||||
return `
|
||||
|
||||
@@ -4992,3 +4992,40 @@ tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60,
|
||||
.stint-lap.is-excluded { opacity: 0.55; }
|
||||
.stint-laps-empty { color: var(--muted); }
|
||||
.stint-laps-title { margin: 12px 0 2px; }
|
||||
|
||||
/* Overlay live marks (src/overlay_live_marks.js): flash on a new time, pit clock, split. */
|
||||
.overlay-race-row.is-passing, .obs-tv-row.is-passing { animation: overlay-pass 700ms ease-out var(--pass-delay, 0ms) both; }
|
||||
@keyframes overlay-pass {
|
||||
0% { box-shadow: inset 4px 0 0 #ffe066, inset 0 0 0 999px rgb(255 224 102 / 34%); }
|
||||
100% { box-shadow: inset 4px 0 0 transparent, inset 0 0 0 999px transparent; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.overlay-race-row.is-passing, .obs-tv-row.is-passing { animation: none; box-shadow: inset 4px 0 0 #ffe066; }
|
||||
}
|
||||
.overlay-live-marks { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; vertical-align: middle; }
|
||||
.overlay-race-driver .overlay-live-marks { margin-left: 8px; }
|
||||
/* The driver cell styles its spans as tiny grey labels; the marks keep their own look. */
|
||||
.overlay-race-driver .overlay-live-marks span { font-size: 0.72rem; letter-spacing: 0; text-transform: none; }
|
||||
.overlay-race-driver .overlay-pit-badge { color: #2a1a00; }
|
||||
.overlay-race-driver .overlay-pit-badge.is-done { color: #ffd28a; }
|
||||
.overlay-race-driver .overlay-split-chip { color: #bfe8ff; }
|
||||
body[data-theme="light"] .overlay-race-driver .overlay-split-chip { color: #075985; }
|
||||
body[data-theme="light"] .overlay-race-driver .overlay-pit-badge.is-done { color: #7a4a00; }
|
||||
.overlay-pit-badge, .overlay-split-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 6px; border-radius: 999px; font-size: 0.78em; font-weight: 800; line-height: 1.4; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.overlay-pit-badge { background: #f5a623; color: #2a1a00; }
|
||||
.overlay-pit-badge.is-active { animation: overlay-pit-pulse 1s ease-in-out infinite; }
|
||||
.overlay-pit-badge.is-done { background: color-mix(in srgb, #f5a623 30%, transparent); color: #ffd28a; }
|
||||
.overlay-fuel-icon { width: 1.05em; height: 1.05em; flex: none; }
|
||||
@keyframes overlay-pit-pulse { 50% { background: #ffc65c; } }
|
||||
.overlay-split-chip { background: rgb(14 165 233 / 22%); color: #bfe8ff; }
|
||||
.overlay-split-chip i { font-style: normal; }
|
||||
.overlay-split-chip .is-faster { color: #4ade80; }
|
||||
.overlay-split-chip .is-slower { color: #f87171; }
|
||||
/* Hung outside the tower's left edge, over the video: it covers no name and the tower
|
||||
(sized to its content) never changes width. */
|
||||
.obs-tv-row:has(.overlay-live-marks) { position: relative; overflow: visible; }
|
||||
.obs-tv-name:has(.overlay-live-marks) { overflow: visible; }
|
||||
.obs-tv-cell .overlay-live-marks { position: absolute; top: 50%; right: calc(100% + 0.35em); transform: translateY(-50%); flex-wrap: nowrap; margin: 0; font-size: 0.85em; text-transform: none; filter: drop-shadow(0 0.1em 0.3em rgb(0 0 0 / 60%)); }
|
||||
.obs-tv-cell .overlay-split-chip { background: #0b4a6b; }
|
||||
body[data-theme="light"] .overlay-split-chip { color: #075985; }
|
||||
body[data-theme="light"] .overlay-pit-badge.is-done { color: #7a4a00; }
|
||||
Reference in new issue
Block a user