(index, { emit = false, force = false } = {})
| 991 | }; |
| 992 | |
| 993 | const setActiveIndex = async (index, { emit = false, force = false } = {}) => { |
| 994 | if (!Number.isFinite(index)) return null; |
| 995 | const safeIndex = Math.round(index); |
| 996 | if (safeIndex < 0 || safeIndex >= timelineSnapshots.length) return null; |
| 997 | if (!force && state.activeIndex === safeIndex) return timelineSnapshots[safeIndex]; |
| 998 | if (state.loading && !force) return null; |
| 999 | |
| 1000 | state.activeIndex = safeIndex; |
| 1001 | slider.value = String(safeIndex); |
| 1002 | |
| 1003 | const snapshot = timelineSnapshots[safeIndex]; |
| 1004 | summary.textContent = snapshot.label; |
| 1005 | label.textContent = formatSnapshotDescription(snapshot); |
| 1006 | |
| 1007 | const metricsText = formatTimelineMetrics(snapshot.metrics); |
| 1008 | metricsElement.textContent = metricsText || ""; |
| 1009 | metricsElement.classList.toggle("timeline-metrics--empty", metricsText.length === 0); |
| 1010 | |
| 1011 | if (emit) { |
| 1012 | await applySnapshotChange(snapshot, safeIndex); |
| 1013 | } |
| 1014 | |
| 1015 | return snapshot; |
| 1016 | }; |
| 1017 | |
| 1018 | slider.addEventListener("input", (event) => { |
| 1019 | const nextIndex = Number(event.target.value); |
no test coverage detected