Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ Keep these true:
and in the code.
- Opening something, a reference in place included, pushes one history entry that holds the
paper's pixel, the pin, the tab and the map's camera. Following and pointing never push.
- A statement opened by a click stays until Unpin, Escape, Back or a new click. Scrolling never
lets it go.
- A statement opened by a click stays until Unpin, Escape, Back, a new click, or until the
reader scrolls on to another statement. Nobody should have to click for the Lean and the
graph to follow the reading.
graph to follow the reading.
- The address names the statement carrying the highlighter, and the counter reads the same.
- Failing to find a quote or a name stops the build.
- `web/src/map/` is copied from lean-exposition. Keep it close to that source so fixes
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ the handle between the graph and the Lean to share the pane; both are
remembered. Closing the proof pane lasts for that visit.
As you scroll, the proof pane follows the linked passage you are reading: the
Lean shows its declaration, and the graph shows that declaration with what it
uses. Choosing another card or result holds the graph there until you choose
**Follow the paper again**. Click a statement or diagram
uses, with no click needed. A statement you open by clicking it stays until you
read on to another statement. Above the Lean, the graph takes only the room its
drawing needs. Click a statement or diagram
card to see its Lean code. Use **Back**
to return to the diagram without losing your place, or the **Graph / Lean**
toggle to choose what stays beside the paper.
Expand Down
40 changes: 30 additions & 10 deletions tests/journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def graph_follows(page: Page, url: str, shots: Path | None) -> None:
head = lambda: page.eval_on_selector_all(".nearmap__card.is-head .nearmap__title", "els => els.map(e => e.textContent)")
check(page.locator(".proof__graph").bounding_box()["height"] > 150 and lean_open(page),
"a fresh visit opens with the graph above the Lean")
check(page.locator(".claims--many select").count() == 1, "many results share one line with a menu")
check(page.locator(".claims--many select").count() == 0, "many results have no menu to operate")
seen = set()
for _ in range(8):
page.mouse.move(400, 500)
Expand All @@ -197,16 +197,36 @@ def graph_follows(page: Page, url: str, shots: Path | None) -> None:
if "Following" in caption(page) and heads:
check(any(title in caption(page) for title in heads), f"the graph shows the statement being read: {heads[0]}")
check(len(seen) >= 4, f"the graph changed {len(seen)} times as the paper scrolled")
page.get_by_role("button", name="Next result").click()
page.wait_for_timeout(300)
# A statement opened by its address is held; reading on lets it go without a click.
page.goto(f"{url}#/pcp-exposition/@pcp-expository-opening", wait_until="load")
page.locator(".nearmap__card.is-head").first.wait_for()
wait_until(page, lambda: "Pinned" in caption(page), "a statement opened by its address is held open")
wait_until(page, lambda: top(page) < 1200, "the paper has arrived at that statement")
page.wait_for_timeout(600)
held = head()
check(page.locator(".graph__paused").count() == 1, "choosing a result holds the graph there")
page.mouse.move(400, 500)
page.mouse.wheel(0, -4000)
page.wait_for_timeout(900)
check(head() == held, "a held graph stays put while the paper scrolls")
page.get_by_role("button", name="Follow the paper again").click()
wait_until(page, lambda: head() != held and page.locator(".graph__paused").count() == 0, "following again returns to the statement being read")
let_go = False
for _ in range(8):
page.mouse.move(400, 500)
page.mouse.wheel(0, 1100)
page.wait_for_timeout(700)
if "Following" in caption(page) and head() != held:
let_go = True
break
check(let_go, "reading on lets go of it: the Lean and the graph follow the scroll")
check(page.locator(".graph__paused").count() == 0, "and nothing asks to be clicked first")
# Whole file and back: the step's Lean is in view again.
page.locator(".proof").get_by_role("button", name="Whole file", exact=True).click()
page.wait_for_timeout(700)
page.locator(".proof").get_by_role("button", name="This step", exact=True).click()
page.wait_for_timeout(600)
check(page.evaluate("""() => {
const body = document.querySelector('.leaf__body'), line = body.querySelector('.decl .source__line');
if (!line) return false;
const r = line.getBoundingClientRect(), b = body.getBoundingClientRect();
return r.top >= b.top - 2 && r.bottom <= b.bottom + 2;
}"""), "back from the whole file, the step's Lean is in view")
page.goto(f"{url}#/pcp-exposition", wait_until="load")
page.locator(".papersplit").wait_for()
shot(page, shots, "05-graph-follows")
width = lambda: page.locator(".left").bounding_box()["width"]
start = width()
Expand Down
16 changes: 7 additions & 9 deletions web/src/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,14 @@ a.source__ref:hover { color: var(--lit); text-decoration: underline solid; }
.proof:has(.graph--near) .proof__key { display: none; }
@media (prefers-reduced-motion: no-preference) { .nearmap__card, .nearmap__line { transition: opacity 120ms; } }

/* Many results: one line names the result on show, with a menu and a step either way. */
.claims--many { flex-wrap: nowrap; align-items: center; gap: 6px; padding: 5px 12px 5px 16px; border-bottom: 1px solid var(--rule); }
.claims__pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
/* Many results: one quiet line says which of the paper's results is on show. */
.claims--many { margin: 0; display: flex; flex-wrap: nowrap; align-items: baseline; gap: 10px; padding: 7px 16px 6px; border-bottom: 1px solid var(--rule); color: var(--ink); }
.claims__count { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.claims__pick select { flex: 1; min-width: 0; min-height: 28px; padding: 0 28px 0 8px; font: inherit; font-weight: 600; color: var(--ink); text-overflow: ellipsis; background-color: var(--sheet); border: 1px solid var(--rule-control); border-radius: var(--radius-s); cursor: pointer; }
.claims__pick select:hover { border-color: var(--ink-3); }
.claims--many .claims__step { flex: none; min-width: 28px; padding: 0; font-size: var(--fs-base); line-height: 1; color: var(--ink); border: 1px solid var(--rule-control); }
.claims--many .claims__step:hover:not(:disabled) { border-color: var(--ink-3); }
.claims--many .claims__step:disabled { color: var(--ink-3); opacity: 0.5; cursor: default; }
.claims__pick select:focus-visible, .claims__step:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.claims--many b { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.graph__usedby .graph__more { color: var(--ink-2); }
/* Above the Lean, the graph is as tall as its drawing needs, never more than its share. */
.proof:not([data-side]) .proof__panes.is-both > .proof__graph { flex: 0 0 auto; height: min(calc(var(--share) * 100%), var(--graph-want, 100%)); }
.proof:not([data-side]) .proof__panes.is-both > .proof__lean { flex: 1 1 0; }
/* The drawing changes with the statement being read: a short dissolve says it is a new drawing. */
@media (prefers-reduced-motion: no-preference) {
.nearmap__world { animation: nearmap-arrive 180ms cubic-bezier(0.16, 1, 0.3, 1) backwards; }
Expand Down
13 changes: 12 additions & 1 deletion web/src/paper/PaperPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,18 @@ export function PaperPage({ edition }: { edition: Edition }) {
else letGo(layoutRef.current.lean);
}, [closeSheet, letGo, setMode, wide]);

const onFollow = useCallback<Follow>((id, zone, above) => {
const lineId = useRef<string | null>(null);
const onFollow = useCallback<Follow>((id, zone, above, byReader) => {
// Reading on lets go of a statement held open: once the reader has scrolled to another
// statement, the Lean and the graph follow the reading line again.
const cur = entryRef.current;
if (byReader && cur.pin && cur.tab === "step" && id && id !== lineId.current && id !== cur.pin.passage) {
const unpinned = { ...cur, pin: null, lean: layoutRef.current.lean, opened: null };
entryRef.current = unpinned;
setEntry(unpinned);
setMapStays(false);
}
lineId.current = id;
setLine({ id, zone, above });
if (above) lastPassage.current = above;
const at = id ?? above;
Expand Down
2 changes: 1 addition & 1 deletion web/src/paper/ReadingPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const ReadingPane = forwardRef<PaperHandle, Props>(function ReadingPane(p

const followSoon = useCallback((id: string | null, kind: Zone, above: string | null) => {
window.clearTimeout(followTimer.current);
followTimer.current = window.setTimeout(() => latest.current.onFollow(id, kind, above), FOLLOW_MS);
followTimer.current = window.setTimeout(() => latest.current.onFollow(id, kind, above, userMoved.current), FOLLOW_MS);
}, []);

/** What the reading line shows now. */
Expand Down
3 changes: 2 additions & 1 deletion web/src/paper/reading-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const READING_LINE = 0.34;
export const FOLLOW_MS = 200;

/** What the left page is called on when a statement settles. */
export type Follow = (id: string | null, zone: Zone, above: string | null) => void;
/** `byReader`: the reader scrolled here; a jump the page made itself does not count. */
export type Follow = (id: string | null, zone: Zone, above: string | null, byReader?: boolean) => void;

/** How long a pointer rests before the right page previews. */
export const DWELL_MS = 150;
Expand Down
2 changes: 2 additions & 0 deletions web/src/paper/reading.css
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ dialog.plot p { margin: 8px 0 0; font-family: var(--font-sans); font-size: var(-
/* Author Markdown tables: the original cells remain one semantic table. */
.sheet__text table {
display: block;
/* As wide as its cells, centred on the text column; a table wider than the page scrolls. */
width: fit-content;
max-width: 100%;
overflow-x: auto;
border-collapse: collapse;
Expand Down
12 changes: 9 additions & 3 deletions web/src/proof/LeanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,20 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start
// pane; a step come back to keeps its place.
const shownOpen = useRef(false);
const arriving = useRef(true);
const tabWas = useRef(tab);
useLayoutEffect(() => {
const el = body.current;
if (!el || !open) {
shownOpen.current = false;
return;
}
// The whole file and the index scroll this same page. Coming back to the step, place
// it afresh: their scroll position means nothing here.
const back = tab === "step" && tabWas.current !== "step";
tabWas.current = tab;
if (tab !== "step") return;
const was = shownKey.current;
if (was === step.key && shownOpen.current) return;
if (was === step.key && shownOpen.current && !back) return;
if (was !== step.key && shownOpen.current) tops.current.set(was, el.scrollTop);
shownKey.current = step.key;
shownOpen.current = true;
Expand All @@ -103,7 +109,7 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start
return;
}
}
const kept = tops.current.get(step.key);
const kept = back ? undefined : tops.current.get(step.key);
if (kept !== undefined) {
el.scrollTop = kept;
return;
Expand All @@ -129,7 +135,7 @@ export const LeanPage = memo(function LeanPage({ ref, edition, step, open, start
if (target > 0 && target < top) target = fits(0) ? 0 : top;
el.scrollTop = Math.max(0, target);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open, step]);
}, [open, step, tab]);

return (
<section className="leaf" aria-label="Lean">
Expand Down
45 changes: 27 additions & 18 deletions web/src/proof/MapPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const BAND = 340;
const MAP_LIMIT = 16;
/** More results than this, and the switch between them is one line with a menu. */
const MANY_CLAIMS = 4;
/** How many users of a card are named before "and N more". */
const USERS_SHOWN = 3;
const LIST_BELOW = 440;
/** Neighbourhood tiles are wider, and each is as tall as its title needs, up to four lines. */
const NEAR_W = 140;
Expand Down Expand Up @@ -179,6 +181,9 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
};
}, [big, edition.slug]);
const graph = useMemo(() => (near ? neighbourhood(edition, fullGraph, centre, goal, files) : fullGraph), [near, edition, fullGraph, centre, goal, files]);
// A much-used definition has dozens of users: name a few, with the rest one press away.
const [allUsers, setAllUsers] = useState(false);
useEffect(() => setAllUsers(false), [centre]);
const usedBy = useMemo(() => (near && centre !== goal ? (edition.declarations.find((d) => d.id === centre)?.used_by ?? []) : []), [near, centre, goal, edition]);
// What the pointer or focus is on, for the "via" line under the controls.
const [hovered, setHovered] = useState<string | null>(null);
Expand Down Expand Up @@ -217,9 +222,14 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
useEffect(() => {
if (selected) show(selected);
}, [selected, show]);
// A card the reader chose in the graph stays in view only until they read on: the next
// statement to reach the reading line takes the graph back. No button is needed.
const [held, setHeld] = useState<string | null>(null);
useEffect(() => {
if (!selected && followed && !paused) show(followed);
}, [selected, followed, paused, show]);
if (selected || !followed || followed === held) return;
setHeld(null);
show(followed);
}, [selected, followed, held, show]);
const litIds = useMemo(() => (lit.length ? new Set(lit) : null), [lit]);
const litKey = lit.join("|");
const litRef = useRef(lit);
Expand Down Expand Up @@ -286,8 +296,8 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
const browse = useCallback((id: string) => {
if (claims.some((c) => c.id === id)) setGoal(id);
setCentre(id);
if (litRef.current.length) setPause(true);
}, [claims, setPause]);
setHeld(litRef.current.find((x) => edition.declarations.some((d) => d.id === x)) ?? "");
}, [claims, edition]);

const restoring = useRef(false);
useImperativeHandle(ref, (): MapPaneHandle => ({
Expand Down Expand Up @@ -439,7 +449,7 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
<section ref={section} className={`graph${big ? " graph--quiet" : ""}${near ? " graph--near" : ""}`} aria-label="Graph of the Lean proof">
{paused && (
<p className="graph__paused" role="status">
The graph stays where you put it.
Paused while you move the graph.
<button type="button" onClick={() => setPause(false)}>Follow the paper again</button>
</p>
)}
Expand All @@ -450,17 +460,11 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
))}
</div>
)}
{claims.length > MANY_CLAIMS && (
<div className="claims claims--many" role="group" aria-label="Which result's proof to show">
<button type="button" className="claims__step" aria-label="Previous result" disabled={claimAt <= 0} onClick={() => browse(claims[claimAt - 1].id)}>‹</button>
<label className="claims__pick">
<span className="claims__count">Result {claimAt + 1} of {claims.length}</span>
<select value={claim?.id} onChange={(event) => browse(event.target.value)}>
{claims.map((c, i) => <option key={c.id} value={c.id}>{i + 1}. {c.title}</option>)}
</select>
</label>
<button type="button" className="claims__step" aria-label="Next result" disabled={claimAt >= claims.length - 1} onClick={() => browse(claims[claimAt + 1].id)}>›</button>
</div>
{claims.length > MANY_CLAIMS && (!near || centre === goal) && (
<p className="claims claims--many">
<span className="claims__count">Result {claimAt + 1} of {claims.length}</span>
<b>{claim?.title}</b>
</p>
)}
{types.length > 0 && (
<div className="vocab" aria-label="Types the proof is written in">
Expand All @@ -482,11 +486,16 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
{whole ? "Show one card and what it uses" : "Whole map"}
</button>
)}
{near && !narrow && centre !== goal && <button type="button" onClick={() => browse(goal)}>Back to {claims.length > 1 ? "the result" : "the main result"}</button>}
{near && !narrow && centre !== goal && claims.length <= MANY_CLAIMS && <button type="button" onClick={() => browse(goal)}>Back to {claims.length > 1 ? "the result" : "the main result"}</button>}
{near && !narrow && centre !== goal && <button type="button" onClick={() => onSelect(centre)}>Open its Lean</button>}
{near && !narrow && usedBy.length > 0 && (
<span className="graph__usedby">Used by{" "}
{usedBy.map((id) => <button key={id} type="button" onClick={() => browse(id)}>{edition.declarations.find((d) => d.id === id)?.plain ?? id}</button>)}
{(allUsers ? usedBy : usedBy.slice(0, USERS_SHOWN)).map((id) => <button key={id} type="button" onClick={() => browse(id)}>{edition.declarations.find((d) => d.id === id)?.plain ?? id}</button>)}
{usedBy.length > USERS_SHOWN && (
<button type="button" className="graph__more" aria-expanded={allUsers} onClick={() => setAllUsers((v) => !v)}>
{allUsers ? "show fewer" : `and ${usedBy.length - USERS_SHOWN} more`}
</button>
)}
</span>
)}
{whole && big && !narrow && <span className="graph__hint">Point at a card to see its lines.</span>}
Expand Down
21 changes: 19 additions & 2 deletions web/src/proof/NearMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ export function NearMap({ graph, heads, plate, kicker = "Main result", alone, li
return { placed, lines, height: y + 12, crossings, behind, kinds, edges, bands };
}, [graph, heads, plate, width]);

// Above the Lean, the graph takes only the room its drawing needs, up to the share the
// reader has given it: a card with two uses leaves the rest of the page to its Lean.
const tail = useRef<HTMLParagraphElement>(null);
useLayoutEffect(() => {
const el = frame.current;
const pane = el?.closest<HTMLElement>(".proof__graph");
const panes = el?.closest<HTMLElement>(".proof__panes");
if (!el || !pane || !panes || !drawing) return;
const above = el.getBoundingClientRect().top - pane.getBoundingClientRect().top;
panes.style.setProperty("--graph-want", `${Math.ceil(above + drawing.height + (tail.current?.offsetHeight ?? 0) + 14)}px`);
}, [drawing, alone]);
useEffect(() => {
const panes = frame.current?.closest<HTMLElement>(".proof__panes");
return () => {
panes?.style.removeProperty("--graph-want");
};
}, []);
// Shrink to fit the pane with the one-line key under the drawing; past MIN_SCALE it scrolls.
const KEY_H = 34;
const fit = drawing && paneH ? Math.max(MIN_SCALE, Math.min(1, (paneH - KEY_H) / drawing.height)) : 1;
Expand Down Expand Up @@ -370,9 +387,9 @@ export function NearMap({ graph, heads, plate, kicker = "Main result", alone, li
</div>
</div>
)}
{drawing && drawing.edges.length === 0 && alone && <p className="nearmap__alone">{alone}</p>}
{drawing && drawing.edges.length === 0 && alone && <p className="nearmap__alone" ref={tail}>{alone}</p>}
{drawing && drawing.edges.length > 0 && (
<p className="nearmap__key">
<p className="nearmap__key" ref={tail}>
<span>
{drawing.kinds.size > 1
? "Lines run down to what a card uses; dashed: its statement only."
Expand Down
2 changes: 1 addition & 1 deletion web/src/proof/ProofPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const KEY = "proof-reader-pane-3";
/** Narrower than this, the graph sits above the Lean; from here they stand side by side. */
const SIDE_BY_SIDE = 1040;
/** What the graph has before the reader pulls the handle: the statement's place in the proof, above or beside its Lean. */
const OPENING = { share: 0.4, sideShare: 0.46 };
const OPENING = { share: 0.6, sideShare: 0.46 };
const MAX = 0.78;
/** A pull shorter than this leaves the Lean the whole page. */
const SHUT = 0.08;
Expand Down