// The section jump strip (SectionJump.astro): marks the section being read// and keeps its link in view inside the strip's own sideways scroll.exportfunction initSectionJump():void {
const nav =document.querySelector<HTMLElement>('[data-sec-jump]');
if (!nav || nav.dataset.bound ||!('IntersectionObserver'inwindow)) return;
nav.dataset.bound ='1';
const track = nav.querySelector<HTMLElement>('.sec-jump__track');
const links = [...nav.querySelectorAll<HTMLAnchorElement>('a[data-sf-jump]')];
const byId =newMap(links.map((l) => [decodeURIComponent(l.hash.slice(1)), l]));
const mark = (id:string):void => {
const link = byId.get(id);
if (!link || link.getAttribute('aria-current') ==='true') return;
links.forEach((l) => l.removeAttribute('aria-current'));
link.setAttribute('aria-current', 'true');
// Scroll the strip, never the page: `scrollIntoView` would move both.if (track) {
const left = link.offsetLeft - track.offsetLeft;
const right = left + link.offsetWidth;
if (left < track.scrollLeft) track.scrollLeft = left;
elseif (right > track.scrollLeft + track.clientWidth) track.scrollLeft = right - track.clientWidth;
}
};
// A band just under the masthead and strip: whichever section crosses it// is the one being read.const observer =newwindow.IntersectionObserver(
(entries) => entries.forEach((e) => { if (e.isIntersecting) mark((e.target as HTMLElement).id); }),
{ rootMargin:'-130px 0px -72% 0px', threshold:0 },
);
byId.forEach((_, id) => {
const section =document.getElementById(id);
if (section) observer.observe(section);
});
document.addEventListener('astro:before-swap', () => observer.disconnect(), { once:true });
}