Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: Years, Months and All Photos in the Library, as on a Mac

Yashwanth Kamireddi86702e201d77
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index d2849de..240e822 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -180,6 +180,8 @@ export const api = {
/** Photos by id, in the order asked; any gone are left out. */
photosGet: (ids: string[]) => invoke<Photo[]>("photos_get", { ids }),
photosCounts: () => invoke<[PhotoView, number][]>("photos_counts"),
+ /** The library's months, newest first, each with its count and key photos (Years and Months). */
+ photosMonths: () => invoke<PhotoMonth[]>("photos_months"),
/** The albums the person made, each with how many photos it holds. */
/** Each album, how many it shows, and its cover — the first photo it shows. */
photosAlbums: () => invoke<[PhotoAlbum, number, string | null][]>("photos_albums"),
@@ -834,6 +836,19 @@ export type PhotoIndex = {
first: number | null;
last: number | null;
};
+/** One month of the library as Years and Months show it (quince-core photos::PhotoMonth). */
+export type PhotoMonth = {
+ year: number;
+ /** 1–12. */
+ month: number;
+ count: number;
+ videos: number;
+ /** The photo that stands for it: a favourite if it has one, else the still nearest its middle. */
+ key: string;
+ keyFavorite: boolean;
+ /** Up to three more, spread through it, newest first. */
+ more: string[];
+};
export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "panoramas" | "portrait" | "recents" | "hidden" | "rated" | "recentlyDeleted";
export type Photo = {
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index f72cd8a..0f9077c 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -17,6 +17,7 @@ import {
PHOTO_UPLOAD,
type Photo,
type PhotoAlbum,
+ type PhotoMonth,
type PhotoOrder,
type PhotoSource,
type PhotoView,
@@ -44,6 +45,7 @@ import { AdjustDate } from "./photos/AdjustDate";
import { useReveal } from "../lib/reveal";
import { Picker } from "../components/Picker";
import { PAGE, PhotoList, PhotoStore } from "./photos/list";
+import { Periods, monthName, type Level, type Place } from "./photos/Periods";
import { same } from "../lib/same";
/** The sidebar, in Photos' order, each with the symbol Photos gives it. */
@@ -66,6 +68,10 @@ const UTILITIES: typeof VIEWS = [
{ key: "recentlyDeleted", label: "Recently Deleted", Icon: Trash2 },
];
+/** The Library's three levels, as Photos names them in its toolbar. */
+const LEVELS: [Level, string][] = [["years", "Years"], ["months", "Months"], ["all", "All Photos"]];
+const LEVEL_KEY = "quince.photos.level";
+
/** How many across at each step of the zoom, as Photos steps it. */
const ACROSS = [10, 7, 5, 3];
@@ -799,6 +805,15 @@ export function PhotosView() {
const [error, setError] = useState<string | null>(null);
useErrorToast(error, () => setError(null));
const [zoom, setZoom] = useState(1);
+ // The Library's level — Years, Months or All Photos — kept on this machine, as Photos keeps it.
+ const [level, setLevel] = useState<Level>(() => {
+ try {
+ const kept = window.localStorage.getItem(LEVEL_KEY);
+ return kept === "years" || kept === "months" ? kept : "all";
+ } catch {
+ return "all";
+ }
+ });
// Squares that fill each cell, or each photo whole in its own shape — icloud.com's toggle,
// kept on this machine.
const [fit, setFit] = useState(() => {
@@ -1979,6 +1994,16 @@ export function PhotosView() {
// after Photos is chosen there — never the page's text.
const selectAll = ctrl && e.key.toLowerCase() === "a";
if (!selectAll && !t?.closest?.(".px") && t !== document.body) return;
+ // Ctrl+[ — and Escape, with nothing selected — step out a level, as Photos' Back does:
+ // All Photos to Months, Months to Years.
+ if (periodsHere && level !== "years" && !e.altKey && !e.shiftKey && !chosen.size
+ && ((ctrl && (e.key === "[" || e.code === "BracketLeft")) || (!ctrl && e.key === "Escape"))) {
+ e.preventDefault();
+ goLevel(level === "all" ? "months" : "years");
+ return;
+ }
+ // Years or Months showing: the grid behind them takes no keys.
+ if (away) return;
if (ctrl && e.key.toLowerCase() === "a") {
setChosen(new Set(list));
} else if (ctrl && !e.shiftKey && !e.altKey && e.key.toLowerCase() === "c" && selected.length && place !== "recentlyDeleted") {
@@ -2608,14 +2633,14 @@ export function PhotosView() {
return { label: m.month, year: d.getFullYear(), month: d.getMonth(), cover: { id: m.items[0].id } };
});
}, [months, drawn]); // eslint-disable-line react-hooks/exhaustive-deps
- const goToMonth = (label: string) => {
+ const goToMonth = (label: string, instant = false) => {
const el = scroller.current;
const at = el?.querySelector<HTMLElement>(`.px-month[data-month="${CSS.escape(label)}"]`);
// Measured against the scroller itself: offsetTop counts from whatever positioned box
// happens to hold the month, which is not always the scroller.
if (el && at) {
const top = at.getBoundingClientRect().top - el.getBoundingClientRect().top + el.scrollTop - 4;
- el.scrollTo({ top, behavior: still() ? "auto" : "smooth" });
+ el.scrollTo({ top, behavior: instant || still() ? "auto" : "smooth" });
}
};
const scroller = useRef<HTMLDivElement | null>(null);
@@ -2643,6 +2668,87 @@ export function PhotosView() {
}, 120);
}, [album]);
useEffect(() => setHere(null), [view, album]);
+
+ /*
+ * Years, Months and All Photos, as Photos on a Mac steps through its Library: only the
+ * Library has them (every other view, an album and a search are their own grid). Years and
+ * Months are drawn in place of the grid, which stays as it was beneath them — built and kept
+ * current by every sync, its scroll put back — so coming back to All Photos is instant and
+ * finds it where it was.
+ */
+ const periodsHere = drawn.view === "library" && !drawn.album && !drawn.query;
+ const away = periodsHere && level !== "all";
+ const awayRef = useRef(away);
+ awayRef.current = away;
+ // The library's months, with their counts and key photos, asked of the library whenever Years
+ // or Months is shown and again whenever the library changes under them.
+ const [periodMonths, setPeriodMonths] = useState<PhotoMonth[] | null>(null);
+ useEffect(() => {
+ if (!away) return undefined;
+ let mine = true;
+ api.photosMonths().then(
+ (m) => mine && setPeriodMonths((was) => (same(was, m) ? was : m)),
+ (e) => mine && setError(messageOf(e)),
+ );
+ return () => {
+ mine = false;
+ };
+ }, [away, photos]);
+ /** Where a level just shown lands: the place carried from the last one (a new object each time). */
+ const [landAt, setLandAt] = useState<Place | null>(null);
+ /** The place at the top of Years or Months now (kept by them). */
+ const periodAt = useRef<Place | null>(null);
+ /** All Photos as it was left: its scroll, and the month at its top. */
+ const leftAll = useRef<{ top: number; place: Place | null } | null>(null);
+ /** All Photos about to be shown, and the place to show it at. */
+ const toAll = useRef<Place | null | undefined>(undefined);
+ /** The month at the top of All Photos. */
+ const gridPlace = (): Place | null => {
+ const label = here ?? months[0]?.month;
+ const g = months.find((m) => m.month === label && m.items.length);
+ if (!g || !photos) return null;
+ const d = new Date(photos.keys[g.items[0].index] * 1000);
+ return { year: d.getFullYear(), month: d.getMonth() + 1 };
+ };
+ const goLevel = (next: Level, to?: Place | null) => {
+ if (next === level) return;
+ const from = level === "all" ? gridPlace() : periodAt.current;
+ const place = to === undefined ? from : to;
+ if (level === "all") {
+ leftAll.current = { top: scroller.current?.scrollTop ?? 0, place: from };
+ // Nothing stays chosen out of sight, for a key to act on.
+ setChosen(new Set());
+ anchor.current = null;
+ }
+ setJumping(null);
+ if (next === "all") toAll.current = place;
+ else setLandAt(place ? { year: place.year, month: next === "months" ? place.month : undefined } : null);
+ setLevel(next);
+ try {
+ window.localStorage.setItem(LEVEL_KEY, next);
+ } catch {
+ // For this run only.
+ }
+ };
+ // All Photos shown again: at the month chosen, or exactly where it was left when that is the
+ // same month, or a year it was in (Escape and back again), before its first frame is painted.
+ useLayoutEffect(() => {
+ const to = toAll.current;
+ toAll.current = undefined;
+ const el = scroller.current;
+ if (level !== "all" || to === undefined || !el) return;
+ const left = leftAll.current;
+ if (left && (!to || (left.place?.year === to.year && (to.month === undefined || left.place.month === to.month)))) {
+ el.scrollTop = left.top;
+ return;
+ }
+ if (!to) return;
+ // A year alone: its first month as the grid shows them.
+ const label = to.month
+ ? monthName(to.year, to.month)
+ : months.find((m) => m.month && photos && new Date(photos.keys[m.items[0].index] * 1000).getFullYear() === to.year)?.month;
+ if (label) goToMonth(label, true);
+ }, [level]); // eslint-disable-line react-hooks/exhaustive-deps
// Info closes with the photo: the next photo opens plain, as he expects it to.
useEffect(() => {
if (open === null) setInfo(false);
@@ -2656,7 +2762,7 @@ export function PhotosView() {
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (!live.current) return;
- if (!(e.ctrlKey || e.metaKey) || e.altKey || viewer.current) return;
+ if (!(e.ctrlKey || e.metaKey) || e.altKey || viewer.current || awayRef.current) return;
if (e.key === "=" || e.key === "+") acts.current.zoomBy(1);
else if (e.key === "-") acts.current.zoomBy(-1);
else return;
@@ -3193,12 +3299,21 @@ export function PhotosView() {
</span>
</>
)
- : (here ?? span) || undefined
+ : (away ? span : (here ?? span)) || undefined
}
>
{title}
</PaneTitle>
<div className="px-tools">
+ {periodsHere && (
+ <div className="segmented toolbar-group px-levels" role="group" aria-label="Library">
+ {LEVELS.map(([key, label]) => (
+ <button key={key} className="segment" aria-pressed={level === key} onClick={() => goLevel(key)}>
+ {label}
+ </button>
+ ))}
+ </div>
+ )}
{place === "recentlyDeleted" && !inAlbum && photos && photos.length > 0 && (
// Recently Deleted's own toolbar, in Photos' words: Recover and Delete for what is
// selected, Delete All when nothing is.
@@ -3219,7 +3334,7 @@ export function PhotosView() {
)}
</div>
)}
- <div className="toolbar-group">
+ {!away && <div className="toolbar-group">
<button
className="tool px-cap is-glyph-state"
aria-label={fit ? "Show Square Photos" : "Show Whole Photos"}
@@ -3229,7 +3344,7 @@ export function PhotosView() {
>
{fit ? <Square size={15} strokeWidth={1.9} aria-hidden="true" /> : <RectangleHorizontal size={16} strokeWidth={1.9} aria-hidden="true" />}
</button>
- </div>
+ </div>}
{sort && (
<div className="toolbar-group">
<button
@@ -3255,7 +3370,7 @@ export function PhotosView() {
</button>
</div>
)}
- {monthCovers.length > 1 && (
+ {monthCovers.length > 1 && !away && (
<div className="toolbar-group">
<button
className="tool px-cap"
@@ -3270,14 +3385,14 @@ export function PhotosView() {
</div>
)}
{jumping && <JumpTo months={monthCovers} at={jumping} current={here ?? monthCovers[0]?.label ?? null} onPick={goToMonth} onClose={() => setJumping(null)} />}
- <div className="toolbar-group" role="group" aria-label="Zoom">
+ {!away && <div className="toolbar-group" role="group" aria-label="Zoom">
<button className="tool px-cap" aria-label="Zoom Out" title="Zoom Out (Ctrl −)" disabled={zoom === 0} onClick={() => zoomBy(-1)}>
<Minus size={15} strokeWidth={2.2} aria-hidden="true" />
</button>
<button className="tool px-cap" aria-label="Zoom In" title="Zoom In (Ctrl +)" disabled={zoom === ACROSS.length - 1} onClick={() => zoomBy(1)}>
<Plus size={15} strokeWidth={2.2} aria-hidden="true" />
</button>
- </div>
+ </div>}
<div className="toolbar-group">
<button className="tool px-cap px-add" onClick={() => void choose()} title="Add photos and videos" aria-label="Add Photos">
<ImagePlus size={16} strokeWidth={1.9} aria-hidden="true" />
@@ -3350,7 +3465,7 @@ export function PhotosView() {
return;
}
if (!(e.target as HTMLElement).closest(".px-tile")) setChosen(new Set());
- }} data-fit={fit || undefined} style={{ "--across": across } as React.CSSProperties}>
+ }} data-fit={fit || undefined} data-away={away || undefined} style={{ "--across": across } as React.CSSProperties}>
{waiting && (
<div className="px-month" aria-busy="true">
<h2 className="px-month-title px-month-title-ph" aria-hidden="true">&nbsp;</h2>
@@ -3384,6 +3499,17 @@ export function PhotosView() {
{tally && <p className="px-tally">{tally}</p>}
<div className="px-sweep" ref={sweepBox} aria-hidden="true" hidden />
</div>
+ {away && periodMonths && (
+ <Periods
+ level={level as "years" | "months"}
+ months={periodMonths}
+ oldest={sort?.oldest ?? false}
+ land={landAt}
+ at={periodAt}
+ onYear={(year) => goLevel("months", { year })}
+ onMonth={(year, month) => goLevel("all", { year, month })}
+ />
+ )}
{shown && (
<div
diff --git a/src/screens/photos/Periods.tsx b/src/screens/photos/Periods.tsx
new file mode 100644
index 0000000..977718c
--- /dev/null
+++ b/src/screens/photos/Periods.tsx
@@ -0,0 +1,245 @@
+/**
+ * The library by Years and by Months, as Photos on a Mac steps out of All Photos: a large tile a
+ * year, then a tile a month, each with the photo that stands for it (chosen by the library, see
+ * quince-core photo_months). A year opens its months; a month opens All Photos at that month.
+ *
+ * However large the library, these are a few hundred tiles at most, every one the same shape: laid
+ * out from the width alone, so a jump to any one lands exactly, and only the rows near the screen
+ * are made, their pictures fetched.
+ */
+import { useLayoutEffect, useMemo, useRef, useState, type MutableRefObject } from "react";
+import { fitSrc, type PhotoMonth } from "../../lib/ipc";
+
+export type Level = "years" | "months" | "all";
+/** A place in the library carried from one level to the next: a year, or a month of it (1–12). */
+export type Place = { year: number; month?: number };
+
+/** "October 2026": the grid's own words for a month (PhotosView's monthOf), so the two agree. */
+export const monthName = (year: number, month: number) =>
+ new Date(year, month - 1, 15).toLocaleDateString(undefined, { month: "long", year: "numeric" });
+
+/** "212 Photos, 4 Videos", as the foot of the library counts. */
+const tally = (count: number, videos: number) => {
+ const part = (n: number, one: string) => `${n.toLocaleString()} ${n === 1 ? one : `${one}s`}`;
+ const stills = count - videos;
+ return [stills && part(stills, "Photo"), videos && part(videos, "Video")].filter(Boolean).join(", ");
+};
+
+type Year = { year: number; count: number; videos: number; key: string };
+
+/**
+ * Each year's count and its key photo: the favourite standing for its busiest month that has one,
+ * or else the key of its busiest month — the photo most likely to say what that year was.
+ */
+function yearsOf(months: PhotoMonth[]): Year[] {
+ const out = new Map<number, Year & { best: PhotoMonth }>();
+ for (const m of months) {
+ const y = out.get(m.year);
+ if (!y) {
+ out.set(m.year, { year: m.year, count: m.count, videos: m.videos, key: m.key, best: m });
+ continue;
+ }
+ y.count += m.count;
+ y.videos += m.videos;
+ const better = m.keyFavorite !== y.best.keyFavorite ? m.keyFavorite : m.count > y.best.count;
+ if (better) {
+ y.best = m;
+ y.key = m.key;
+ }
+ }
+ return [...out.values()].map(({ best: _best, ...y }) => y);
+}
+
+/** Each level's tiles: the narrowest a column may be, the gap between, and their shape. */
+const LAYOUT = {
+ years: { min: 360, gap: 16, ratio: 3 / 2 },
+ months: { min: 232, gap: 12, ratio: 4 / 3 },
+};
+/** The room the floating bar takes at the top of the scroller (its scroll padding). */
+const topRoom = (el: HTMLElement) => parseFloat(getComputedStyle(el).scrollPaddingTop) || 0;
+
+/** The longer side each picture is made at, in device pixels: thumbnails, never originals. */
+const YEAR_PX = 1024;
+const MONTH_PX = 512;
+const SMALL_PX = 256;
+
+export function Periods({
+ level,
+ months,
+ oldest,
+ land,
+ at,
+ onYear,
+ onMonth,
+}: {
+ level: "years" | "months";
+ /** Newest first, as the library gives them. */
+ months: PhotoMonth[];
+ /** The library is sorted oldest first: so are its years and months. */
+ oldest: boolean;
+ /** Where to land as this level is shown (the place carried from the last one). */
+ land: Place | null;
+ /** The place at the top of the view now, kept current for a step to another level. */
+ at: MutableRefObject<Place | null>;
+ onYear: (year: number) => void;
+ onMonth: (year: number, month: number) => void;
+}) {
+ const box = useRef<HTMLDivElement | null>(null);
+ const years = useMemo(() => (level === "years" ? yearsOf(months) : []), [level, months]);
+ const tiles = useMemo(() => {
+ const list =
+ level === "years"
+ ? years.map((y) => ({ id: `${y.year}`, year: y.year, month: undefined as number | undefined, key: y.key, more: [] as string[], title: `${y.year}`, sub: tally(y.count, y.videos) }))
+ : months.map((m) => ({ id: `${m.year}-${m.month}`, year: m.year, month: m.month as number | undefined, key: m.key, more: m.more, title: monthName(m.year, m.month), sub: tally(m.count, m.videos) }));
+ return oldest ? list.reverse() : list;
+ }, [level, years, months, oldest]);
+
+ /*
+ * Laid out here, not by the engine: every tile is the same shape, so its column, its row and
+ * where it lies follow from the width alone, and only the rows near the screen are made. Left to
+ * the engine (content-visibility and lazy pictures), WebKit made and fetched every tile at once —
+ * 2.5 s on twenty years of months — and a tile off screen guessed at its height until drawn, so
+ * a jump to a month landed a row out.
+ */
+ const shape = LAYOUT[level];
+ const [width, setWidth] = useState(0);
+ const [top, setTop] = useState(0);
+ const [height, setHeight] = useState(800);
+ useLayoutEffect(() => {
+ const el = box.current;
+ if (!el) return undefined;
+ const measure = () => {
+ const pad = parseFloat(getComputedStyle(el).paddingLeft) + parseFloat(getComputedStyle(el).paddingRight);
+ if (el.clientWidth) setWidth(el.clientWidth - pad);
+ setHeight(el.clientHeight);
+ };
+ measure();
+ const watch = new ResizeObserver(measure);
+ watch.observe(el);
+ return () => watch.disconnect();
+ }, []);
+ const across = Math.max(1, Math.floor((width + shape.gap) / (shape.min + shape.gap)));
+ const tileW = (width - (across - 1) * shape.gap) / across;
+ const rowH = tileW / shape.ratio + shape.gap;
+ const rows = Math.ceil(tiles.length / across);
+ /** Where the row of tile `i` lies in the scroller: at its top, under the bar. */
+ const rowTop = (i: number) => Math.floor(i / across) * rowH;
+ // The rows on screen and a screen either side.
+ const first = rowH > 0 ? Math.max(0, Math.floor(top / rowH) - Math.ceil(height / rowH)) : 0;
+ const last = rowH > 0 ? Math.min(rows, Math.ceil((top + height) / rowH) + Math.ceil(height / rowH)) : 0;
+
+ // The tile that takes Tab: the one landed on, then the one the arrows or a click moved to.
+ const [current, setCurrent] = useState(0);
+ const landing = land ? tiles.findIndex((t) => t.year === land.year && (land.month === undefined || level === "years" || t.month === land.month)) : -1;
+ // A year landed on in Months: its first month in the order shown.
+ const target = landing >= 0 ? landing : land ? tiles.findIndex((t) => t.year === land.year) : -1;
+
+ const where = (i: number): Place | null => (tiles[i] ? { year: tiles[i].year, month: tiles[i].month } : null);
+ /** A tile focused once it is made (it may be in a row not made yet). */
+ const focusing = useRef<number | null>(null);
+ const scrollTo = (y: number) => {
+ const el = box.current;
+ if (!el) return;
+ el.scrollTop = y;
+ // The rows there are made in this same frame, not a scroll event later.
+ setTop(el.scrollTop);
+ };
+
+ // Landed on before the first frame: the tile's row at the top under the bar, and the tile
+ // focused, so the keys go on from it. At the top when there is nowhere to land.
+ useLayoutEffect(() => {
+ if (!width) return;
+ const i = Math.max(0, target);
+ setCurrent(i);
+ at.current = where(i);
+ scrollTo(target < 0 ? 0 : rowTop(i));
+ if (target >= 0) focusing.current = i;
+ // Only on arriving at a level (and once it has a width): a sync leaves it be.
+ }, [level, land, width > 0]); // eslint-disable-line react-hooks/exhaustive-deps
+ useLayoutEffect(() => {
+ const i = focusing.current;
+ if (i === null) return;
+ const tile = box.current?.querySelector<HTMLElement>(`[data-period="${CSS.escape(tiles[i]?.id ?? "")}"]`);
+ if (!tile) return;
+ focusing.current = null;
+ tile.focus({ preventScroll: true });
+ });
+
+ // The rows to make follow the scroll at once; and the place, for a step to another level.
+ const onScroll = () => {
+ const el = box.current;
+ if (!el) return;
+ setTop(el.scrollTop);
+ if (rowH <= 0) return;
+ // The tile the keys rest on while its row is on screen; else the first of the top row.
+ const y = rowTop(current);
+ const seen = y > el.scrollTop - rowH / 2 && y < el.scrollTop + el.clientHeight - topRoom(el) - rowH / 2;
+ at.current = where(seen ? current : Math.min(tiles.length - 1, Math.round(el.scrollTop / rowH) * across));
+ };
+
+ // The arrows move between tiles as laid out, as Photos' do; Home and End go to either end.
+ const onKeyDown = (e: React.KeyboardEvent) => {
+ const el = box.current;
+ if (!el || e.altKey || e.ctrlKey || e.metaKey) return;
+ const from = Math.min(current, tiles.length - 1);
+ const step: Record<string, number> = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -across, ArrowDown: across };
+ let to: number;
+ if (e.key in step) to = from + step[e.key];
+ else if (e.key === "Home") to = 0;
+ else if (e.key === "End") to = tiles.length - 1;
+ else return;
+ e.preventDefault();
+ // Down from a row with none under it: the last tile, as a short last row is reached.
+ if (e.key === "ArrowDown" && to >= tiles.length && Math.floor(from / across) < Math.floor((tiles.length - 1) / across)) to = tiles.length - 1;
+ if (to < 0 || to >= tiles.length) return;
+ setCurrent(to);
+ at.current = where(to);
+ // Brought into view as little as it takes, as the grid's arrows do.
+ const y = rowTop(to);
+ if (y < el.scrollTop) scrollTo(y);
+ else if (y + rowH - shape.gap > el.scrollTop + el.clientHeight - topRoom(el)) scrollTo(y + rowH - shape.gap - el.clientHeight + topRoom(el));
+ focusing.current = to;
+ };
+
+ const dpr = window.devicePixelRatio || 1;
+ const big = Math.min(level === "years" ? YEAR_PX : MONTH_PX, Math.round((level === "years" ? 560 : 320) * dpr));
+ return (
+ <div ref={box} className="px-periods" data-level={level} onScroll={onScroll} onKeyDown={onKeyDown}>
+ <div
+ className="px-periods-grid"
+ role="group"
+ aria-label={level === "years" ? "Years" : "Months"}
+ data-count={tiles.length}
+ style={{ "--across": across, "--gap": `${shape.gap}px`, height: Math.max(0, rows * rowH - shape.gap), paddingTop: first * rowH } as React.CSSProperties}
+ >
+ {tiles.slice(first * across, last * across).map((t, k) => {
+ const i = first * across + k;
+ return (
+ <button
+ key={t.id}
+ className="px-period"
+ data-period={t.id}
+ data-mosaic={t.more.length >= 2 ? t.more.length : undefined}
+ aria-label={`${t.title}, ${t.sub}`}
+ // The tab stop is the current tile, or the first made when it is scrolled away.
+ tabIndex={i === current || ((current < first * across || current >= last * across) && k === 0) ? 0 : -1}
+ onFocus={() => {
+ if (current !== i) setCurrent(i);
+ at.current = where(i);
+ }}
+ onClick={() => (t.month === undefined ? onYear(t.year) : onMonth(t.year, t.month))}
+ >
+ <img className="px-period-key" src={fitSrc(t.key, big)} alt="" decoding="async" draggable={false} />
+ {t.more.length >= 2 &&
+ t.more.map((id) => <img key={id} src={fitSrc(id, SMALL_PX * Math.min(2, dpr))} alt="" decoding="async" draggable={false} />)}
+ <span className="px-period-words" aria-hidden="true">
+ <strong>{t.title}</strong>
+ <span>{t.sub}</span>
+ </span>
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ );
+}
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 8379b61..cb91166 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -1019,3 +1019,80 @@ img[data-failed] { content: url("data:image/gif;base64,R0lGODlhAQABAAAAACw="); }
z-index: 1;
justify-content: center;
}
+
+/* ---- Years and Months: the Library a tile a year, or a tile a month, over the grid ---------- */
+/* The grid stays beneath, built and kept current, but out of the page's layout (see PhotosView's
+ levels): only hidden, it went on being laid out under Years and Months, and their scroll lost
+ frames of 100–250 ms to it on fifty thousand photos. */
+.px-scroll[data-away] { display: none; }
+.px-periods {
+ position: absolute;
+ inset: 0;
+ z-index: 1;
+ overflow-y: auto;
+ /* As the grid's: room for the header floating over it, and a tile reached by a key lands
+ below it. */
+ padding: calc(var(--bar, 68px) + 12px) 16px 24px;
+ scroll-padding-top: calc(var(--bar, 68px) + 8px);
+ contain: strict;
+ overflow-anchor: none;
+}
+.px-periods::-webkit-scrollbar-track { margin-top: calc(var(--bar, 68px) + 4px); }
+/* Its columns, gap and height worked out by Periods from the width (only the rows near the screen
+ are made; the padding stands for the rows above them). */
+.px-periods-grid {
+ display: grid;
+ box-sizing: border-box;
+ align-content: start;
+ gap: var(--gap, 12px);
+ grid-template-columns: repeat(var(--across, 4), minmax(0, 1fr));
+}
+/* A tile is exactly the shape its column makes it, whatever is in it. */
+.px-period {
+ position: relative;
+ display: grid;
+ grid-template: 1fr / 1fr;
+ gap: 2px;
+ aspect-ratio: 4 / 3;
+ padding: 0;
+ border: 0;
+ border-radius: var(--r-plateau);
+ overflow: hidden;
+ background: color-mix(in srgb, var(--text) 7%, transparent);
+ color: #fff;
+ font: inherit;
+ text-align: left;
+ cursor: default;
+}
+.px-periods[data-level="years"] .px-period { aspect-ratio: 3 / 2; }
+/* A month's key photo large, with a few more from it in a column beside, as Photos gathers one. */
+.px-period[data-mosaic] { grid-template-columns: 2fr 1fr; }
+.px-period[data-mosaic="2"] { grid-template-rows: 1fr 1fr; }
+.px-period[data-mosaic="3"] { grid-template-rows: 1fr 1fr 1fr; }
+.px-period[data-mosaic] .px-period-key { grid-row: 1 / -1; }
+.px-period img {
+ display: block;
+ width: 100%;
+ height: 100%;
+ min-height: 0;
+ object-fit: cover;
+ background: color-mix(in srgb, var(--text) 7%, transparent);
+}
+/* Its name over the top of the photo, white on a soft shade, as Photos writes it. */
+.px-period-words {
+ position: absolute;
+ inset: 0 0 auto 0;
+ display: flex;
+ flex-direction: column;
+ gap: 1px;
+ padding: 12px 14px 28px;
+ background: linear-gradient(rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.18) 60%, transparent);
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
+ pointer-events: none;
+}
+.px-period-words strong { font-size: var(--t-17, 17px); font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
+.px-period-words span { font-size: var(--t-12, 12px); font-weight: 500; opacity: 0.9; font-variant-numeric: tabular-nums; }
+.px-periods[data-level="years"] .px-period-words { padding: 16px 18px 40px; }
+.px-periods[data-level="years"] .px-period-words strong { font-size: 30px; letter-spacing: -0.02em; }
+.px-period:hover img { filter: brightness(1.06); }
+.px-period:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }