CoverageCheck / web /src /lib /architecture.ts
TBM99's picture
Deploy coverage-check 3559250
23d418f verified
Raw History Blame Contribute Delete
907 Bytes
// The Architecture page's scroll logic (the content is architecture.json; the layouts
// are the diagram components).
/** Which step is being read: the last one whose top has passed the reading line (a
* fraction of the scroll area's height from its top), so the step under the reader's
* eyes lights its boxes up (scrollytelling: the step crossing the middle is active).
* tops: each step's top relative to the scroll area, in order. -1 = none reached yet. */
export function activeStep(tops: number[], height: number, line = 0.45): number {
let active = -1
tops.forEach((top, i) => {
if (top <= height * line) active = i
})
return active
}
/** A box is lit when the active step names it; with no active step nothing is dimmed. */
export function boxState(id: string, lit: string[] | null): 'lit' | 'dim' | 'plain' {
if (!lit) return 'plain'
return lit.includes(id) ? 'lit' : 'dim'
}