import { useEffect, useRef } from 'react' import { CHAPTERS, SCREENS, adjacentScreens, chapterDomId, screenLabel, type LabelInput } from '../../utils/matrixStory' /** * The slim story bar under the site header: the five chapter phrases as links, the one in view marked with `aria-current`, * and a thin progress line along its bottom edge. Under the current chapter, one small dot per screen (no numbers; each * has the screen's plain name as its accessible name). On a phone only the current phrase and the progress line show; the * Continue and Back controls do the paging there. It is a `nav` of real links. `pos` is the DOM id in view. */ export default function SectionBand({ pos, onJump, rootRef, reduced, labels, selection, onTop, onChange, }: { pos: string onJump: (domId: string) => void /** The element whose height the progress line measures (the sections wrapper). */ rootRef: React.RefObject reduced: boolean labels: LabelInput /** The measure and the place in view, in words, for the "change" link. */ selection: { measure: string; place: string } /** Back to the very top of the page and the main menu. */ onTop: () => void /** Back to the heading's blanks so the reader can change the measure. */ onChange: () => void }) { const bar = useRef(null) useEffect(() => { let raf = 0 const update = () => { raf = 0 const root = rootRef.current if (!root || !bar.current) return const r = root.getBoundingClientRect() const span = r.height - window.innerHeight * 0.6 const p = span > 0 ? Math.min(1, Math.max(0, -r.top / span)) : 0 bar.current.style.transform = `scaleX(${p.toFixed(4)})` } const onScroll = () => { if (!raf) raf = requestAnimationFrame(update) } update() window.addEventListener('scroll', onScroll, { passive: true }) window.addEventListener('resize', onScroll) return () => { window.removeEventListener('scroll', onScroll) window.removeEventListener('resize', onScroll) if (raf) cancelAnimationFrame(raf) } }, [rootRef, reduced]) const here = adjacentScreens(pos) const screen = SCREENS[Math.max(0, here.index)]! const chapter = CHAPTERS.find((c) => c.id === screen.chapter) ?? CHAPTERS[0]! return ( ) }