Skip to content

Commit a811757

Browse files
committed
chore: remove sidebar outline and improve ux
1 parent a6ae722 commit a811757

3 files changed

Lines changed: 40 additions & 191 deletions

File tree

app/components/ReadmeToc.vue

Lines changed: 0 additions & 147 deletions
This file was deleted.

app/composables/useActiveTocItem.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,40 +124,49 @@ export function useActiveTocItem(toc: Ref<TocItem[]>) {
124124
behavior: 'smooth',
125125
})
126126

127-
// Monitor scroll until it settles, THEN update URL hash
128-
let lastScrollY = window.scrollY
129-
let stableFrames = 0
130-
let rafId: number | null = null
131-
const STABLE_THRESHOLD = 5 // Number of frames with no movement to consider settled
132-
133-
const checkScrollSettled = () => {
134-
const currentScrollY = window.scrollY
135-
136-
if (Math.abs(currentScrollY - lastScrollY) < 1) {
137-
stableFrames++
138-
if (stableFrames >= STABLE_THRESHOLD) {
139-
// Scroll has settled - NOW update URL hash (won't trigger native scroll)
140-
history.replaceState(null, '', `#${id}`)
141-
setupObserver()
142-
scrollCleanup = null
143-
return
127+
const handleScrollEnd = () => {
128+
history.replaceState(null, '', `#${id}`)
129+
setupObserver()
130+
scrollCleanup = null
131+
}
132+
133+
// Check for scrollend support (Chrome 114+, Firefox 109+, Safari 18+)
134+
const supportsScrollEnd = 'onscrollend' in window
135+
136+
if (supportsScrollEnd) {
137+
window.addEventListener('scrollend', handleScrollEnd, { once: true })
138+
scrollCleanup = () => window.removeEventListener('scrollend', handleScrollEnd)
139+
} else {
140+
// Fallback: use RAF polling for older browsers
141+
let lastScrollY = window.scrollY
142+
let stableFrames = 0
143+
let rafId: number | null = null
144+
const STABLE_THRESHOLD = 5 // Number of frames with no movement to consider settled
145+
146+
const checkScrollSettled = () => {
147+
const currentScrollY = window.scrollY
148+
149+
if (Math.abs(currentScrollY - lastScrollY) < 1) {
150+
stableFrames++
151+
if (stableFrames >= STABLE_THRESHOLD) {
152+
handleScrollEnd()
153+
return
154+
}
155+
} else {
156+
stableFrames = 0
144157
}
145-
} else {
146-
stableFrames = 0
158+
159+
lastScrollY = currentScrollY
160+
rafId = requestAnimationFrame(checkScrollSettled)
147161
}
148162

149-
lastScrollY = currentScrollY
150163
rafId = requestAnimationFrame(checkScrollSettled)
151-
}
152164

153-
// Start monitoring
154-
rafId = requestAnimationFrame(checkScrollSettled)
155-
156-
// Store cleanup function
157-
scrollCleanup = () => {
158-
if (rafId !== null) {
159-
cancelAnimationFrame(rafId)
160-
rafId = null
165+
scrollCleanup = () => {
166+
if (rafId !== null) {
167+
cancelAnimationFrame(rafId)
168+
rafId = null
169+
}
161170
}
162171
}
163172

@@ -169,7 +178,7 @@ export function useActiveTocItem(toc: Ref<TocItem[]>) {
169178
history.replaceState(null, '', `#${id}`)
170179
setupObserver()
171180
}
172-
}, 1500)
181+
}, 1000)
173182
}
174183

175184
// Set up observer when TOC changes

app/pages/[...package].vue

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,12 @@ function handleClick(event: MouseEvent) {
940940
/>
941941
</a>
942942
</h2>
943-
<!-- Mobile TOC dropdown (shown only on smaller screens) -->
944943
<ClientOnly>
945944
<ReadmeTocDropdown
946-
v-if="readmeData?.toc?.length"
945+
v-if="readmeData?.toc && readmeData.toc.length > 1"
947946
:toc="readmeData.toc"
948947
:active-id="activeTocId"
949948
:scroll-to-heading="scrollToHeading"
950-
class="xl:hidden"
951949
/>
952950
</ClientOnly>
953951
</div>
@@ -1013,17 +1011,6 @@ function handleClick(event: MouseEvent) {
10131011
:links="readmeData.playgroundLinks"
10141012
/>
10151013

1016-
<!-- Table of Contents (desktop only - hidden on lg and below) -->
1017-
<ClientOnly>
1018-
<ReadmeToc
1019-
v-if="readmeData?.toc?.length"
1020-
:toc="readmeData.toc"
1021-
:active-id="activeTocId"
1022-
:scroll-to-heading="scrollToHeading"
1023-
class="hidden xl:block"
1024-
/>
1025-
</ClientOnly>
1026-
10271014
<section
10281015
id="compatibility"
10291016
v-if="

0 commit comments

Comments
 (0)