// The reader's cite thread labels (components/ui/cite-thread.tsx ReaderThread): // 0:00 at the left, the cite under its notch, the length at the right -- and // the cite's label never on top of an end's (P4b: "0:000:03" in a bench's // reader). An end label gives way when the cite sits close to it; otherwise // the cite's label is held clear of it, measured in `ch` (the labels are mono). // // Pure: `node --test` runs it. /** * @param {{ pct: number, citeChars: number, startChars: number, endChars: number }} o * pct: the cite's place, 0..100; the *Chars: each label's length * @returns {{ showStart: boolean, showEnd: boolean, citeLeft: string }} */ export function threadLabels({ pct, citeChars, startChars, endChars }) { const showStart = pct >= 12; const showEnd = pct <= 80; const gap = 1; const lo = showStart ? `${startChars + gap}ch` : "0px"; const hi = showEnd ? `calc(100% - ${endChars + gap + citeChars}ch)` : `calc(100% - ${citeChars}ch)`; return { showStart, showEnd, citeLeft: `clamp(${lo}, calc(${pct}% - ${citeChars / 2}ch), ${hi})` }; }