Reveal content is visible in the HTML and only content below the viewport hides after hydration. Deferred photos get a noscript twin, and the first row of the portfolio loads eagerly per column count. Some old tests still expect the former behaviour; they are rewritten next, so this commit's test run is not fully green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
// 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;
|
|
}
|