Something went wrong. Try again.
A single hub to check all of my ATProto activity
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106import { RAIL_ANCHOR_PX } from "./config";import { MONTHS } from "./format";
const MIN_LABEL_GAP_PX = 13;
// Left-margin minimap: constant month ticks + year labels + a viewport thumb.// Jumps anchor on the month/year separators so a jump reveals the header.// Returns a teardown that detaches its listeners, so it can be rebuilt after the// timeline is re-rendered (e.g. when a filter changes which months exist).export function setupRail(): () => void { const noop = (): void => {}; const rail = document.querySelector<HTMLElement>("#rail"); const timeline = document.querySelector<HTMLElement>("#timeline"); if (!rail || !timeline) return noop; const ac = new AbortController(); const { signal } = ac;
const monthAnchor = new Map<string, HTMLElement>(); const yearAnchor = new Map<string, HTMLElement>(); ([...timeline.children] as HTMLElement[]).forEach((el) => { if (el.dataset.month) monthAnchor.set(el.dataset.month, el); else if (el.dataset.year) yearAnchor.set(el.dataset.year, el); }); rail.innerHTML = ""; if (!monthAnchor.size) return noop;
const scrollToEl = (el: HTMLElement): void => window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - RAIL_ANCHOR_PX, behavior: "smooth" });
const track = document.createElement("div"); track.className = "rail-track"; rail.appendChild(track); const thumb = document.createElement("div"); thumb.className = "rail-thumb"; rail.appendChild(thumb);
const monthMarks: { el: HTMLElement; tick: HTMLElement }[] = []; monthAnchor.forEach((el, ym) => { const [y, m] = ym.split("-").map(Number); const tick = document.createElement("button"); tick.className = "rail-tick"; tick.setAttribute("aria-label", `${MONTHS[m]} ${y}`); tick.innerHTML = `<span class="rail-tip">${MONTHS[m]}</span>`; // short month on hover tick.addEventListener("click", () => scrollToEl(el)); rail.appendChild(tick); monthMarks.push({ el, tick }); });
const yearMarks: { el: HTMLElement; label: HTMLElement }[] = []; yearAnchor.forEach((el, y) => { const label = document.createElement("button"); label.className = "rail-year"; label.textContent = `’${y.slice(2)}`; label.title = y; label.addEventListener("click", () => scrollToEl(el)); rail.appendChild(label); yearMarks.push({ el, label }); });
const docTop = (el: HTMLElement): number => el.getBoundingClientRect().top + window.scrollY; let docH = 1; let yearTops: { label: HTMLElement; top: number }[] = [];
const updateThumb = (): void => { thumb.style.top = `${(window.scrollY / docH) * 100}%`; thumb.style.height = `${Math.min(100, (window.innerHeight / docH) * 100)}%`; const y = window.scrollY + RAIL_ANCHOR_PX + 4; let active: { label: HTMLElement; top: number } | null = null; yearTops.forEach((m) => { if (m.top <= y) active = m; }); yearTops.forEach((m) => m.label.classList.toggle("active", m === active)); };
const measure = (): void => { docH = document.documentElement.scrollHeight; const railH = rail.clientHeight || 1; monthMarks.forEach(({ el, tick }) => { tick.style.top = `${(docTop(el) / docH) * 100}%`; }); // Position year labels; drop any that would collide with the last shown one // (sparse years stay reachable via their month ticks). let lastPx = -Infinity; yearMarks.forEach(({ el, label }) => { const frac = docTop(el) / docH; label.style.top = `${frac * 100}%`; const px = frac * railH; const show = px - lastPx >= MIN_LABEL_GAP_PX; label.style.display = show ? "" : "none"; if (show) lastPx = px; }); yearTops = yearMarks.map((m) => ({ label: m.label, top: docTop(m.el) })); // cache for scroll updateThumb(); };
track.addEventListener("click", (e) => { const rect = rail.getBoundingClientRect(); const frac = Math.min(1, Math.max(0, (e.clientY - rect.top) / rect.height)); window.scrollTo({ top: frac * docH - RAIL_ANCHOR_PX, behavior: "smooth" }); });
let ticking = false; window.addEventListener("scroll", () => { if (ticking) return; ticking = true; requestAnimationFrame(() => { updateThumb(); ticking = false; }); }, { passive: true, signal }); window.addEventListener("resize", measure, { signal }); window.addEventListener("load", measure, { signal }); // images shift offsets document.addEventListener("toggle", measure, { capture: true, signal }); measure(); return () => ac.abort();}