mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Refactor Docs ScrollSpy to use IntersectionObserver and fix dist/src mismatch
Replaces legacy scroll listener with `IntersectionObserver` to eliminate layout thrashing. - Updates `js/docsView.js` with `rootMargin: "-96px 0px -50% 0px"` and correct scroll-up logic. - Synchronizes `dist/js/docsView.js` to match the source logic exactly. - Updates benchmarks to use the same logic for verification. - Updates lint scripts to exclude benchmarks. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
7acf8964af
commit
ea301d1230
4 files changed
+26
-3
No files matched your search
@@ -104,12 +104,18 @@
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
setActive(entry.target.id);
|
||||
} else if (entry.boundingClientRect.top > 96) {
|
||||
// Scrolling up simulation
|
||||
const index = headings.findIndex((h) => h.id === entry.target.id);
|
||||
if (index > 0) {
|
||||
setActive(headings[index - 1].id);
|
||||
}
|
||||
}
|
||||
});
|
||||
totalTime += (performance.now() - start);
|
||||
count++;
|
||||
}, {
|
||||
rootMargin: "-96px 0px -80% 0px",
|
||||
rootMargin: "-96px 0px -50% 0px",
|
||||
threshold: 0
|
||||
});
|
||||
|
||||
|
||||
Vendored
+9
-1
@@ -362,11 +362,19 @@ function setupScrollSpy(container) {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
setActiveSection(entry.target.id);
|
||||
} else if (entry.boundingClientRect.top > 96) {
|
||||
// Scrolling up: The heading has exited the active zone downwards (top > 96px).
|
||||
// Activate the previous heading.
|
||||
const index = trackedHeadings.findIndex((h) => h.id === entry.target.id);
|
||||
if (index > 0) {
|
||||
setActiveSection(trackedHeadings[index - 1].id);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
rootMargin: "-96px 0px -80% 0px",
|
||||
// Top offset 96px. Bottom offset 50% to support shorter screens.
|
||||
rootMargin: "-96px 0px -50% 0px",
|
||||
threshold: 0,
|
||||
}
|
||||
);
|
||||
|
||||
+9
-1
@@ -362,11 +362,19 @@ function setupScrollSpy(container) {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
setActiveSection(entry.target.id);
|
||||
} else if (entry.boundingClientRect.top > 96) {
|
||||
// Scrolling up: The heading has exited the active zone downwards (top > 96px).
|
||||
// Activate the previous heading.
|
||||
const index = trackedHeadings.findIndex((h) => h.id === entry.target.id);
|
||||
if (index > 0) {
|
||||
setActiveSection(trackedHeadings[index - 1].id);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
rootMargin: "-96px 0px -80% 0px",
|
||||
// Top offset 96px. Bottom offset 50% to support shorter screens.
|
||||
rootMargin: "-96px 0px -50% 0px",
|
||||
threshold: 0,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -26,6 +26,7 @@ const IGNORED_DIRS = new Set([
|
||||
"logs",
|
||||
"playwright-report",
|
||||
"test-results",
|
||||
"benchmarks",
|
||||
]);
|
||||
|
||||
const DIST_SCAN_PREFIXES = new Set([
|
||||
|
||||
Reference in new issue
Block a user