Adds the shared gallery building blocks

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>
This commit is contained in:
2026-10-25 23:22:43 +01:00
co-authored by Claude Opus 5.5
parent e013f1436b
commit 18bf0311ef
38 changed files with 2392 additions and 43 deletions
+56
View File
@@ -0,0 +1,56 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { neighbourIndexes } from './neighbourIndexes';
import { wrapIndex } from './wrapIndex';
// A list position together with the list length it belongs to
const position = fc.integer({ min: 1, max: 30 }).chain((count) =>
fc.record({
count: fc.constant(count),
index: fc.integer({ min: 0, max: count - 1 }),
radius: fc.integer({ min: 0, max: 4 }),
}),
);
describe('neighbourIndexes', () => {
it('lists the two photos on each side, nearest first', () => {
expect(neighbourIndexes(5, 10)).toEqual([6, 4, 7, 3]);
expect(neighbourIndexes(0, 10)).toEqual([1, 9, 2, 8]);
});
it('lists each photo once in a short list', () => {
expect(neighbourIndexes(0, 1)).toEqual([]);
expect(neighbourIndexes(0, 2)).toEqual([1]);
expect(neighbourIndexes(1, 3)).toEqual([2, 0]);
});
it('never repeats a photo or includes the current one (invariant)', () => {
fc.assert(
fc.property(position, ({ index, count, radius }) => {
const result = neighbourIndexes(index, count, radius);
expect(new Set(result).size).toBe(result.length);
expect(result).not.toContain(index);
for (const i of result) {
expect(i).toBeGreaterThanOrEqual(0);
expect(i).toBeLessThan(count);
}
expect(result).toHaveLength(Math.min(2 * radius, count - 1));
}),
);
});
it('matches all positions within the radius (oracle)', () => {
fc.assert(
fc.property(position, ({ index, count, radius }) => {
const expected = new Set<number>();
for (let d = -radius; d <= radius; d++) {
expected.add(wrapIndex(index + d, count));
}
expected.delete(index);
expect(new Set(neighbourIndexes(index, count, radius))).toEqual(
expected,
);
}),
);
});
});