fix: make the reading viewport a script-driven scroll container so sticky and view timelines work

This commit is contained in:
2026-10-10 18:10:28 +03:00
parent 6c18228ed6
commit 71959f7541
3 changed files with 36 additions and 8 deletions

View File

@@ -99,8 +99,19 @@ const browserRuntime = (): NavigationRuntime => ({
pushHash: (hash) => window.history.pushState(window.history.state, "", hash),
replaceHash: (hash) =>
window.history.replaceState(window.history.state, "", hash),
scrollTarget: (target, behavior) =>
target.scrollIntoView({ behavior, block: "start" }),
scrollTarget: (target, behavior) => {
// Inside the live reading stage the document is the only real scroller;
// scrollIntoView would move the script-driven inner viewport instead.
if (target.closest('[data-reading-stage="live"]') === null) {
target.scrollIntoView({ behavior, block: "start" });
return;
}
const margin = parseFloat(getComputedStyle(target).scrollMarginTop) || 0;
window.scrollTo({
top: window.scrollY + target.getBoundingClientRect().top - margin,
behavior,
});
},
focusHeading: (target) => {
target
.querySelector<HTMLElement>('h1[tabindex="-1"], h2[tabindex="-1"]')