/** * docs.ts — scroll-spy sidebar for all Muse developer docs pages. * * Observes .devdocs-section[id] elements and marks the matching * .devdocs-nav-link--sub link active as sections scroll into view. * * Registered for every docs-* page key in app.ts. */ function initScrollSpy(): void { const links = document.querySelectorAll('.devdocs-nav-link--sub'); if (!links.length) return; const observer = new IntersectionObserver( (entries) => { entries.forEach((e) => { if (e.isIntersecting) { links.forEach((l) => l.classList.remove('devdocs-nav-link--active')); const target = document.querySelector( `.devdocs-nav-link--sub[href="#${e.target.id}"]` ); if (target) target.classList.add('devdocs-nav-link--active'); } }); }, { rootMargin: '-20% 0px -70% 0px' } ); document.querySelectorAll('.devdocs-section[id]').forEach((s) => observer.observe(s)); } export function initDocs(): void { initScrollSpy(); }