// The phases of a Reveal. `settled` is what the server and the hydrating // render show: visible, nothing to animate. After hydration only an element // wholly below the viewport becomes `hidden`, and it becomes `revealed` once // it scrolls into view (BR-RVL-09). export type RevealPhase = 'settled' | 'hidden' | 'revealed'; export type RevealEvent = 'belowViewport' | 'inView' | 'intersected'; // An element whose top edge is at or below the bottom edge of the viewport was // not painted from the HTML, so it may be hidden without a flash. Anything // else, also an element above the viewport or one taller than it, stays. export function startsHidden(top: number, viewportHeight: number): boolean { return top >= viewportHeight; } // One way only: settled stays settled, hidden becomes revealed, revealed // stays. Applying an event twice (StrictMode runs effects twice) gives the // same phase as once. export function nextRevealPhase( phase: RevealPhase, event: RevealEvent, ): RevealPhase { if (phase === 'settled' && event === 'belowViewport') return 'hidden'; if (phase === 'hidden' && event === 'intersected') return 'revealed'; return phase; }