1// Mark the contents entry for the section being read: the last one in the2// top half of the screen. The page works without it.3(() => {4 const links = new Map([...document.querySelectorAll('.toc a[href^="#"]')].map((a) => [a.getAttribute('href').slice(1), a]));5 if (!links.size || !('IntersectionObserver' in window)) return;6 const seen = new Set();7 const mark = () => {8 const id = [...links.keys()].filter((k) => seen.has(k)).pop();9 for (const [k, a] of links) {10 if (k === id) a.setAttribute('aria-current', 'true');11 else a.removeAttribute('aria-current');12 }13 };14 const io = new IntersectionObserver((entries) => {15 for (const e of entries) e.isIntersecting ? seen.add(e.target.id) : seen.delete(e.target.id);16 mark();17 }, { rootMargin: '0px 0px -55% 0px' });18 for (const id of links.keys()) {19 const el = document.getElementById(id);20 if (el) io.observe(el);21 }22})();