A masonry photo grid that keeps the reading order (pure CSS, no measuring in the browser), an accessible lightbox on Chakra's Dialog with wrap-around browsing, keys, swipe and preloading, and a filter bar of toggle buttons. They work on generic gallery items, so other pages can use them. The swipe logic moves out of the hero into a shared hook; the hero behaves as before. The rules behind them live in pure helpers with property-based tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
804 B
TypeScript
25 lines
804 B
TypeScript
import { wrapIndex } from './wrapIndex';
|
|
|
|
// The positions around `index` whose large photos the lightbox loads ahead,
|
|
// nearest first and alternating next/previous (next, previous, next+1, …).
|
|
// The list wraps around, so in a short list each photo appears once and the
|
|
// current one never.
|
|
export function neighbourIndexes(
|
|
index: number,
|
|
count: number,
|
|
radius: number = 2,
|
|
): number[] {
|
|
const result: number[] = [];
|
|
for (let distance = 1; distance <= radius; distance++) {
|
|
for (const candidate of [
|
|
wrapIndex(index + distance, count),
|
|
wrapIndex(index - distance, count),
|
|
]) {
|
|
if (candidate !== index && !result.includes(candidate)) {
|
|
result.push(candidate);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|