const ROOMS = [
{ key: "animals", title: "Animals", meta: "Animals & birds of prey", desc: "Raptors in a registered breeding-centre, and residents of Pairi Daiza." },
{ key: "sports", title: "Sports", meta: "Motorsport & wingsuit", desc: "A start-up built on the love of motorbikes, a Belgian motocross champion, and a wingsuit world record holder." },
{ key: "nature", title: "Nature", meta: "Landscape & portraiture", desc: "Quieter frames — people and places away from the race and the jump." },
];
// A room hangs as one flat run of frames, so it ignores the manifest's chapters.
function useRoomPieces(key) {
const data = window.useFolder("assets/gallery/" + key);
return data ? data.frames : null;
}
function TiltImg({ src, srcSet, alt, w, h }) {
// The tilt itself lives in Reveal.jsx, shared with the room cards.
const { ref, onMouseMove: onMove, onMouseLeave: onLeave, isMobile } = window.useTilt();
// Proportions from the manifest, so each frame holds its width before the
// photograph arrives. Without them the track grew as images loaded: frames
// shifted sideways under the reader, the progress bar lied, and End landed
// short of the end because the track was still getting wider.
const ratio = w && h ? `${w} / ${h}` : undefined;
return (
// Sized by height on a wide screen so frames hang on a common baseline. On a
// phone the room runs top to bottom, so each frame takes the full column and
// its own proportions decide its height.
);
}
// BlurIn is shared with the project pages — see Reveal.jsx. This file used to
// carry its own copy, which never actually ran.
const COUNT_WORDS = ["No", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"];
// One card per room, opening on a frame from the room itself. A gallery index
// with no photograph on it asks the visitor to pick a room on the strength of
// its title alone.
function RoomCard({ room, index, loaded }) {
const pieces = useRoomPieces(room.key);
const [hover, setHover] = React.useState(false);
// The same lean the hung frames in a room have — the card is a plate too.
const tilt = window.useTilt();
const first = pieces && pieces.length ? pieces[0] : null;
const cover = first ? first.src : null;
const count = pieces ? pieces.length : null;
return (
setHover(true)}
onMouseLeave={() => setHover(false)}
style={{
display: "flex", flexDirection: "column", textDecoration: "none", height: "100%",
opacity: loaded ? 1 : 0, transform: loaded ? "translateY(0)" : "translateY(20px)",
transition: `opacity 800ms cubic-bezier(.16,1,.3,1) ${260 + index * 110}ms, transform 800ms cubic-bezier(.16,1,.3,1) ${260 + index * 110}ms`,
}}
>
{/* The whole plate leans, not the picture inside it — a tilt applied to
the image alone would slide about under the crop. */}
);
}
// CSS scroll-behavior does not reach a scrollTo asked for in script, so the
// reduced-motion preference has to be read here too.
function scrollStyle() {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
}
function StepButton({ label, glyph, onClick, disabled }) {
const [hover, setHover] = React.useState(false);
// Ink at rest, brass on hover — the same move the menu tab makes, so every
// control on the site answers to the pointer the same way.
const fill = disabled ? "var(--paper-2)" : hover ? "var(--accent-brass)" : "var(--ink-1)";
return (
);
}
function Room({ room, roomIndex, nextRoom }) {
const isMobile = window.useIsMobile();
const loadedPieces = useRoomPieces(room.key);
const pieces = loadedPieces || [];
const trackRef = React.useRef(null);
const [progress, setProgress] = React.useState(0);
const [current, setCurrent] = React.useState(0);
// A hung room runs sideways, but a plain mouse has no sideways wheel and the
// keyboard none at all. This moves one frame at a time and drives the arrow
// buttons, the arrow keys and Home/End alike.
const step = React.useCallback((dir) => {
const el = trackRef.current;
if (!el) return;
const kids = [...el.children];
if (!kids.length) return;
const centre = el.scrollLeft + el.clientWidth / 2;
const middleOf = (k) => k.offsetLeft + k.offsetWidth / 2;
let nearest = 0;
let best = Infinity;
kids.forEach((k, i) => {
const d = Math.abs(middleOf(k) - centre);
if (d < best) { best = d; nearest = i; }
});
const target = kids[Math.min(kids.length - 1, Math.max(0, nearest + dir))];
el.scrollTo({ left: Math.max(0, middleOf(target) - el.clientWidth / 2), behavior: scrollStyle() });
}, []);
const jumpTo = React.useCallback((edge) => {
const el = trackRef.current;
if (!el) return;
el.scrollTo({ left: edge === "end" ? el.scrollWidth : 0, behavior: scrollStyle() });
}, []);
React.useEffect(() => {
if (isMobile) return; // the room reads top to bottom there, no stepping needed
const onKey = (e) => {
if (e.key === "ArrowRight") { e.preventDefault(); step(1); }
else if (e.key === "ArrowLeft") { e.preventDefault(); step(-1); }
else if (e.key === "Home") { e.preventDefault(); jumpTo("start"); }
else if (e.key === "End") { e.preventDefault(); jumpTo("end"); }
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [isMobile, step, jumpTo]);
// Which frame is actually in front of the reader, rather than how far along
// the scrollbar is. The track carries two extra children — the room's opening
// block and its closing block — so mapping raw progress onto the frame count
// ran a frame ahead: the picture said 02 while the counter said 03.
const currentFrame = React.useCallback(() => {
const el = trackRef.current;
if (!el) return 0;
const frames = [...el.children].slice(1, -1); // drop the opening and closing blocks
if (!frames.length) return 0;
const vertical = el.scrollHeight > el.clientHeight && el.scrollWidth <= el.clientWidth;
const centre = vertical
? el.scrollTop + el.clientHeight / 2
: el.scrollLeft + el.clientWidth / 2;
let nearest = 0;
let best = Infinity;
frames.forEach((f, i) => {
const middle = vertical ? f.offsetTop + f.offsetHeight / 2 : f.offsetLeft + f.offsetWidth / 2;
const d = Math.abs(middle - centre);
if (d < best) { best = d; nearest = i; }
});
return nearest;
}, []);
React.useEffect(() => {
const el = trackRef.current;
if (!el) return;
// A phone hangs the room top to bottom, so progress reads the vertical
// scroll there and the sideways wheel translation is not needed.
if (isMobile) {
el.scrollTop = 0;
const onScroll = () => {
const max = el.scrollHeight - el.clientHeight;
const p = max > 0 ? el.scrollTop / max : 0;
setProgress(p);
setCurrent(currentFrame());
};
el.addEventListener("scroll", onScroll, { passive: true });
return () => el.removeEventListener("scroll", onScroll);
}
el.scrollLeft = 0;
const onScroll = () => {
const max = el.scrollWidth - el.clientWidth;
const p = max > 0 ? el.scrollLeft / max : 0;
setProgress(p);
setCurrent(currentFrame());
};
el.addEventListener("scroll", onScroll, { passive: true });
const onWheel = (e) => {
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
const max = el.scrollWidth - el.clientWidth;
if (max <= 0) return;
e.preventDefault();
el.scrollLeft += e.deltaY;
};
el.addEventListener("wheel", onWheel, { passive: false });
return () => { el.removeEventListener("scroll", onScroll); el.removeEventListener("wheel", onWheel); };
}, [room.key, pieces.length, isMobile, currentFrame]);
return (
{/* A hung room reads left to right on a wide screen. On a phone that fights
the thumb, so the same room hangs top to bottom instead. */}
Room {String(roomIndex + 1).padStart(2, "0")}
{room.title}
{room.desc}
{isMobile ? "Scroll down" : "Scroll, or use ← →"}
{pieces.map((p, i) => (
{!isMobile && }
{/* Nothing under a frame that has nothing to say. Each used to carry
three lines — number, category and room name — so the room named
itself under all eighty-nine of its own photographs. The number
returns alongside the words once the manifest carries a caption;
the counter at the foot of the page says where you are meanwhile. */}
{p.caption && (
);
}
// The room comes from the address (#/gallery/animals), not from internal state,
// so a room can be linked to and the browser's back button steps out of it.
function GalleryPage({ roomKey }) {
const index = ROOMS.findIndex((r) => r.key === roomKey);
const [loaded, setLoaded] = React.useState(false);
React.useEffect(() => { const t = setTimeout(() => setLoaded(true), 60); return () => clearTimeout(t); }, []);
return (