Commit 28adf8f579

28adf8f579d94f6a7a45fbfd2a612be5128f091e

parent: a59323c465

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-31 13:07 UTC

commit

Layout: unified · split

docs/.vitepress/theme/components/BookmarksPanel.vue +184 −40
@@ -79,7 +79,9 @@ function flattenSidebarPaths(items: DefaultTheme.SidebarItem[]): string[] {
7979 return paths
8080}
8181
82const sidebarPathOrder = flattenSidebarPaths(Array.isArray(sidebar) ? sidebar : Object.values(sidebar).flat())
82const sidebarPathOrder = flattenSidebarPaths(
83 Array.isArray(sidebar) ? sidebar : Object.values(sidebar).flat()
84)
8385
8486function sidebarIndex(path: string): number {
8587 const exact = sidebarPathOrder.indexOf(path)
@@ -99,7 +101,10 @@ function getPageCard(path: string): HomeCard | null {
99101 let best: HomeCard | null = null
100102 let bestLen = 0
101103 for (const card of homeCards) {
102 if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) {
104 if (
105 (path === card.link || path.startsWith(card.link + '/')) &&
106 card.link.length > bestLen
107 ) {
103108 best = card
104109 bestLen = card.link.length
105110 }
@@ -108,8 +113,18 @@ function getPageCard(path: string): HomeCard | null {
108113}
109114
110115type PageGroup = { path: string; card: HomeCard | null; items: BookmarkItem[] }
111type TopLevelEntry = { type: 'page'; path: string; card: HomeCard | null; items: BookmarkItem[] }
112type FolderEntry = { type: 'folder'; section: string; parentCard: HomeCard | null; pages: PageGroup[] }
116type TopLevelEntry = {
117 type: 'page'
118 path: string
119 card: HomeCard | null
120 items: BookmarkItem[]
121}
122type FolderEntry = {
123 type: 'folder'
124 section: string
125 parentCard: HomeCard | null
126 pages: PageGroup[]
127}
113128type GroupEntry = TopLevelEntry | FolderEntry
114129
115130const grouped = computed((): GroupEntry[] => {
@@ -140,13 +155,27 @@ const grouped = computed((): GroupEntry[] => {
140155 // Build folder entries, sorted by parent card's sidebar position
141156 const folderEntries: FolderEntry[] = [...folderMap.entries()]
142157 .map(([section, paths]) => {
143 const parentCard = homeCards.find(c => c.title === section && !c.section) ?? null
158 const parentCard = homeCards.find(c =>
159 c.title === section && !c.section
160 ) ?? null
144161 const sortedPages = [...paths]
145162 .sort((a, b) => sidebarIndex(a) - sidebarIndex(b))
146 .map(path => ({ path, card: getPageCard(path), items: byPath.get(path)! }))
147 return { type: 'folder' as const, section, parentCard, pages: sortedPages }
163 .map(path => ({
164 path,
165 card: getPageCard(path),
166 items: byPath.get(path)!
167 }))
168 return {
169 type: 'folder' as const,
170 section,
171 parentCard,
172 pages: sortedPages
173 }
148174 })
149 .sort((a, b) => sidebarIndex(a.parentCard?.link ?? '') - sidebarIndex(b.parentCard?.link ?? ''))
175 .sort((a, b) =>
176 sidebarIndex(a.parentCard?.link ?? '') -
177 sidebarIndex(b.parentCard?.link ?? '')
178 )
150179
151180 // Merge top-level and folder entries in sidebar order
152181 const topEntries: TopLevelEntry[] = topPages.map(path => ({
@@ -157,8 +186,12 @@ const grouped = computed((): GroupEntry[] => {
157186 }))
158187
159188 return [...topEntries, ...folderEntries].sort((a, b) => {
160 const ai = a.type === 'page' ? sidebarIndex(a.path) : sidebarIndex(a.parentCard?.link ?? '')
161 const bi = b.type === 'page' ? sidebarIndex(b.path) : sidebarIndex(b.parentCard?.link ?? '')
189 const ai = a.type === 'page'
190 ? sidebarIndex(a.path)
191 : sidebarIndex(a.parentCard?.link ?? '')
192 const bi = b.type === 'page'
193 ? sidebarIndex(b.path)
194 : sidebarIndex(b.parentCard?.link ?? '')
162195 return ai - bi
163196 })
164197})
@@ -178,9 +211,21 @@ const grouped = computed((): GroupEntry[] => {
178211 </button>
179212
180213 <Transition name="bookmarks-panel">
181 <div v-if="isOpen" ref="panelRef" class="bookmarks-panel" :style="panelStyle" role="dialog" aria-label="Bookmarks">
214 <div
215 v-if="isOpen"
216 ref="panelRef"
217 class="bookmarks-panel"
218 :style="panelStyle"
219 role="dialog"
220 aria-label="Bookmarks"
221 >
182222 <div class="bookmarks-mobile-header">
183 <button type="button" class="bookmarks-mobile-back" aria-label="Back" @click="isOpen = false">
223 <button
224 type="button"
225 class="bookmarks-mobile-back"
226 aria-label="Back"
227 @click="isOpen = false"
228 >
184229 <ArrowLeft :size="18" :stroke-width="2" />
185230 </button>
186231 <span class="bookmarks-mobile-title">Bookmarks</span>
@@ -192,27 +237,81 @@ const grouped = computed((): GroupEntry[] => {
192237 >
193238 <div v-if="bookmarks.length === 0" class="bookmarks-empty">
194239 <span class="bookmarks-empty-kaomoji">(˶ᵔ ᵕ ᵔ˶)</span>
195 <p class="bookmarks-empty-hint bookmarks-empty-hint--desktop">Tip: Hover over any primary heading under <strong>On this page</strong> and click <Bookmark :size="13" :stroke-width="2" class="bookmarks-empty-inline-icon" /> to bookmark it.</p>
196 <p class="bookmarks-empty-hint bookmarks-empty-hint--mobile">Tip: Tap <strong>On this page</strong> and press <Bookmark :size="13" :stroke-width="2" class="bookmarks-empty-inline-icon" /> next to any primary heading to bookmark it.</p>
240 <p class="bookmarks-empty-hint bookmarks-empty-hint--desktop">
241 Tip: Hover over any primary heading under <strong>On this
242 page</strong> and click <Bookmark
243 :size="13"
244 :stroke-width="2"
245 class="bookmarks-empty-inline-icon"
246 /> to bookmark it.
247 </p>
248 <p class="bookmarks-empty-hint bookmarks-empty-hint--mobile">
249 Tip: Tap <strong>On this page</strong> and press <Bookmark
250 :size="13"
251 :stroke-width="2"
252 class="bookmarks-empty-inline-icon"
253 /> next to any primary heading to bookmark it.
254 </p>
197255 </div>
198256 <div v-else class="bookmarks-groups">
199 <template v-for="group in grouped" :key="group.type === 'page' ? group.path : group.section">
200
257 <template
258 v-for="group in grouped"
259 :key="group.type === 'page' ? group.path : group.section"
260 >
201261 <!-- Top-level page (no folder) -->
202262 <div v-if="group.type === 'page'" class="bookmarks-group">
203263 <h3 class="bookmarks-group-title">
204 <span v-if="group.card" :class="cardIconToClass(group.card.icon)" class="bookmarks-group-icon" />
205 <span v-else class="i-lucide:file-text bookmarks-group-icon" />
206 <span class="bookmarks-group-text">{{ group.card?.title ?? group.path }}</span>
264 <span
265 v-if="group.card"
266 :class="cardIconToClass(group.card.icon)"
267 class="bookmarks-group-icon"
268 />
269 <span
270 v-else
271 class="i-lucide:file-text bookmarks-group-icon"
272 />
273 <span class="bookmarks-group-text">{{
274 group.card?.title ?? group.path
275 }}</span>
207276 </h3>
208277 <ul class="bookmarks-list">
209 <li v-for="bm in group.items" :key="bm.anchor" class="bookmarks-item">
210 <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false">
211 <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" />
278 <li
279 v-for="bm in group.items"
280 :key="bm.anchor"
281 class="bookmarks-item"
282 >
283 <a
284 class="bookmarks-item-link"
285 :href="bm.path + '#' + bm.anchor"
286 @click="isOpen = false"
287 >
288 <Hash
289 :size="12"
290 :stroke-width="2"
291 class="bookmarks-item-icon"
292 />
212293 {{ bm.title }}
213294 </a>
214 <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)">
215 <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
295 <button
296 type="button"
297 class="bookmarks-item-remove"
298 :aria-label="`Remove bookmark for ${bm.title}`"
299 @click.stop="remove(bm.anchor, bm.path)"
300 >
301 <svg
302 xmlns="http://www.w3.org/2000/svg"
303 width="11"
304 height="11"
305 viewBox="0 0 24 24"
306 fill="none"
307 stroke="currentColor"
308 stroke-width="2.5"
309 stroke-linecap="round"
310 stroke-linejoin="round"
311 >
312 <path d="M18 6 6 18" />
313 <path d="m6 6 12 12" />
314 </svg>
216315 </button>
217316 </li>
218317 </ul>
@@ -221,31 +320,73 @@ const grouped = computed((): GroupEntry[] => {
221320 <!-- Folder group (e.g. Guides, Glossary) -->
222321 <div v-else class="bookmarks-group">
223322 <h3 class="bookmarks-group-title">
224 <span v-if="group.parentCard" :class="cardIconToClass(group.parentCard.icon)" class="bookmarks-group-icon" />
323 <span
324 v-if="group.parentCard"
325 :class="cardIconToClass(group.parentCard.icon)"
326 class="bookmarks-group-icon"
327 />
225328 <span v-else class="i-lucide:folder bookmarks-group-icon" />
226329 <span class="bookmarks-group-text">{{ group.section }}</span>
227330 </h3>
228 <div v-for="page in group.pages" :key="page.path" class="bookmarks-sub-group">
229 <h4 class="bookmarks-sub-title">{{ page.card?.title ?? page.path }}</h4>
331 <div
332 v-for="page in group.pages"
333 :key="page.path"
334 class="bookmarks-sub-group"
335 >
336 <h4 class="bookmarks-sub-title">
337 {{ page.card?.title ?? page.path }}
338 </h4>
230339 <ul class="bookmarks-list">
231 <li v-for="bm in page.items" :key="bm.anchor" class="bookmarks-item">
232 <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false">
233 <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" />
340 <li
341 v-for="bm in page.items"
342 :key="bm.anchor"
343 class="bookmarks-item"
344 >
345 <a
346 class="bookmarks-item-link"
347 :href="bm.path + '#' + bm.anchor"
348 @click="isOpen = false"
349 >
350 <Hash
351 :size="12"
352 :stroke-width="2"
353 class="bookmarks-item-icon"
354 />
234355 {{ bm.title }}
235356 </a>
236 <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)">
237 <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
357 <button
358 type="button"
359 class="bookmarks-item-remove"
360 :aria-label="`Remove bookmark for ${bm.title}`"
361 @click.stop="remove(bm.anchor, bm.path)"
362 >
363 <svg
364 xmlns="http://www.w3.org/2000/svg"
365 width="11"
366 height="11"
367 viewBox="0 0 24 24"
368 fill="none"
369 stroke="currentColor"
370 stroke-width="2.5"
371 stroke-linecap="round"
372 stroke-linejoin="round"
373 >
374 <path d="M18 6 6 18" />
375 <path d="m6 6 12 12" />
376 </svg>
238377 </button>
239378 </li>
240379 </ul>
241380 </div>
242381 </div>
243
244382 </template>
245383 </div>
246384 </div>
247385 <Transition name="bookmarks-fade">
248 <div v-if="showFade && bookmarks.length > 0" class="bookmarks-fade-overlay" />
386 <div
387 v-if="showFade && bookmarks.length > 0"
388 class="bookmarks-fade-overlay"
389 />
249390 </Transition>
250391 </div>
251392 </Transition>
@@ -270,13 +411,15 @@ const grouped = computed((): GroupEntry[] => {
270411 height: 100%;
271412 color: var(--vp-c-text-1);
272413 opacity: 0.55;
273 transition:
274 opacity 0.25s,
275 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
414 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
276415}
277416
278.bookmarks-btn:hover { opacity: 1; }
279.bookmarks-btn:active { transform: scale(0.94); }
417.bookmarks-btn:hover {
418 opacity: 1;
419}
420.bookmarks-btn:active {
421 transform: scale(0.94);
422}
280423
281424.bookmarks-panel {
282425 position: absolute;
@@ -481,7 +624,8 @@ const grouped = computed((): GroupEntry[] => {
481624.bookmarks-panel-enter-from,
482625.bookmarks-panel-leave-to {
483626 opacity: 0;
484 transform: translateX(var(--bookmarks-panel-shift, -50%)) scale(0.95) translateY(-4px);
627 transform: translateX(var(--bookmarks-panel-shift, -50%)) scale(0.95)
628 translateY(-4px);
485629}
486630
487631.bookmarks-fade-enter-active,
docs/.vitepress/theme/components/search/SearchRibbon.vue +207 −50
@@ -1,7 +1,18 @@
11<script setup lang="ts">
2import {
3 onClickOutside,
4 useElementBounding,
5 useEventListener
6} from '@vueuse/core'
27import { ChevronLeft, ChevronRight, Menu } from 'lucide-vue-next'
3import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue'
4import { onClickOutside, useEventListener } from '@vueuse/core'
8import {
9 computed,
10 nextTick,
11 onBeforeUnmount,
12 ref,
13 shallowRef,
14 watch
15} from 'vue'
516import { homeCards } from '../../../configs/constants'
617import type { HomeCard } from '../../../configs/constants'
718
@@ -34,7 +45,10 @@ function getPageCard(path: string): HomeCard | null {
3445 let best: HomeCard | null = null
3546 let bestLen = 0
3647 for (const card of homeCards) {
37 if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) {
48 if (
49 (path === card.link || path.startsWith(card.link + '/')) &&
50 card.link.length > bestLen
51 ) {
3852 best = card
3953 bestLen = card.link.length
4054 }
@@ -74,6 +88,26 @@ const emit = defineEmits<{
7488const showListMenu = ref(false)
7589const listMenuButtonRef = ref<HTMLElement>()
7690const listMenuRef = ref<HTMLElement>()
91const showListMenuFade = ref(true)
92const listMenuBounding = useElementBounding(listMenuRef)
93const ribbonBounding = useElementBounding(() =>
94 listMenuRef.value?.closest('.page-ribbon-list')
95)
96
97const listMenuFadeStyle = computed(() => ({
98 top: `${listMenuBounding.bottom.value - ribbonBounding.top.value - 56}px`,
99 left: `${listMenuBounding.left.value - ribbonBounding.left.value}px`,
100 width: `${listMenuBounding.width.value}px`
101}))
102
103const listMenuFadeReady = computed(() => listMenuBounding.width.value > 0)
104
105function onListMenuScroll() {
106 const el = listMenuRef.value
107 if (!el) return
108 const { scrollTop, scrollHeight, clientHeight } = el
109 showListMenuFade.value = scrollTop + clientHeight < scrollHeight - 4
110}
77111
78112// Tabs ribbon state
79113const ribbonTrack = shallowRef<HTMLElement>()
@@ -100,7 +134,7 @@ function onDragStart(e: MouseEvent) {
100134 // Don't drag if user clicked on a scroll arrow
101135 const target = e.target as HTMLElement
102136 if (target.closest('.page-ribbon-arrow')) return
103
137
104138 isDragging.value = true
105139 dragStartX = e.clientX
106140 dragStartScrollLeft = track.scrollLeft
@@ -115,13 +149,13 @@ function onDragMove(e: MouseEvent) {
115149 if (!isDragging.value) return
116150 const track = getRibbonTrack()
117151 if (!track) return
118
152
119153 const deltaX = e.clientX - dragStartX
120154 const threshold = 4
121155 if (!dragMoved && Math.abs(deltaX) > threshold) {
122156 dragMoved = true
123157 }
124
158
125159 if (dragMoved) {
126160 track.scrollLeft = dragStartScrollLeft - deltaX
127161 updateRibbonOverflow()
@@ -152,7 +186,10 @@ function onTrackWheel(e: WheelEvent) {
152186 if (!track) return
153187 const max = track.scrollWidth - track.clientWidth
154188 if (max <= 0) return
155 const newScroll = Math.max(0, Math.min(max, track.scrollLeft + e.deltaX + e.deltaY))
189 const newScroll = Math.max(
190 0,
191 Math.min(max, track.scrollLeft + e.deltaX + e.deltaY)
192 )
156193 if (newScroll !== track.scrollLeft) {
157194 e.preventDefault()
158195 track.scrollLeft = newScroll
@@ -189,9 +226,14 @@ function onTouchEnd() {
189226
190227function updateRibbonOverflow() {
191228 const track = getRibbonTrack()
192 if (!track) { ribbonCanScrollLeft.value = false; ribbonCanScrollRight.value = false; return }
229 if (!track) {
230 ribbonCanScrollLeft.value = false
231 ribbonCanScrollRight.value = false
232 return
233 }
193234 ribbonCanScrollLeft.value = track.scrollLeft > 2
194 ribbonCanScrollRight.value = track.scrollWidth - track.clientWidth - track.scrollLeft > 2
235 ribbonCanScrollRight.value =
236 track.scrollWidth - track.clientWidth - track.scrollLeft > 2
195237}
196238
197239function getRibbonTrack(): HTMLElement | null {
@@ -204,7 +246,9 @@ function scrollActivePagePillIntoView(direction = 0) {
204246 const track = getRibbonTrack()
205247 if (!track) return
206248 const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')]
207 const activeIndex = pills.findIndex((pill) => pill.classList.contains('active'))
249 const activeIndex = pills.findIndex((pill) =>
250 pill.classList.contains('active')
251 )
208252 const active = pills[activeIndex]
209253 if (!active) return
210254 const trackRect = track.getBoundingClientRect()
@@ -243,7 +287,11 @@ function scrollRibbon(direction: number) {
243287 const to = Math.max(0, Math.min(max, from + amount))
244288 if (to === from) return
245289 if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle)
246 if (!props.searchAnimationsEnabled) { track.scrollLeft = to; updateRibbonOverflow(); return }
290 if (!props.searchAnimationsEnabled) {
291 track.scrollLeft = to
292 updateRibbonOverflow()
293 return
294 }
247295
248296 const duration = 280
249297 const start = performance.now()
@@ -258,8 +306,23 @@ function scrollRibbon(direction: number) {
258306 ribbonAnimHandle = requestAnimationFrame(step)
259307}
260308
261watch(() => props.pageGroups, () => { nextTick(updateRibbonOverflow) })
262watch(() => props.urlPageGroups, () => { nextTick(updateRibbonOverflow) })
309watch(() => props.pageGroups, () => {
310 nextTick(() => {
311 updateRibbonOverflow()
312 onListMenuScroll()
313 })
314})
315watch(() => props.urlPageGroups, () => {
316 nextTick(() => {
317 updateRibbonOverflow()
318 onListMenuScroll()
319 })
320})
321watch(showListMenu, async (open) => {
322 if (!open) return
323 await nextTick()
324 onListMenuScroll()
325})
263326useEventListener('resize', updateRibbonOverflow)
264327
265328onBeforeUnmount(() => {
@@ -304,11 +367,15 @@ const groupedMenuEntries = computed((): MenuEntry[] => {
304367 // Build folder entries
305368 const folderEntries: FolderGroup[] = [...folderMap.entries()]
306369 .map(([section, pages]) => {
307 const parentCard = homeCards.find((c) => c.title === section && !c.section) ?? null
370 const parentCard = homeCards.find((c) =>
371 c.title === section && !c.section
372 ) ?? null
308373 return {
309374 section,
310375 parentCard,
311 iconClass: parentCard ? cardIconToClass(parentCard.icon) : 'i-lucide:folder',
376 iconClass: parentCard
377 ? cardIconToClass(parentCard.icon)
378 : 'i-lucide:folder',
312379 pages
313380 }
314381 })
@@ -338,12 +405,20 @@ const activePageData = computed(() => {
338405 const findInEntries = (key: string, fallbackCount: number) => {
339406 for (const entry of groupedMenuEntries.value) {
340407 if (entry.type === 'page' && entry.page.key === key) {
341 return { label: entry.page.label, iconClass: entry.page.iconClass, count: entry.page.count }
408 return {
409 label: entry.page.label,
410 iconClass: entry.page.iconClass,
411 count: entry.page.count
412 }
342413 }
343414 if (entry.type === 'folder') {
344415 const found = entry.folder.pages.find((p) => p.key === key)
345416 if (found) {
346 return { label: found.label, iconClass: entry.folder.iconClass, count: found.count }
417 return {
418 label: found.label,
419 iconClass: entry.folder.iconClass,
420 count: found.count
421 }
347422 }
348423 }
349424 }
@@ -352,17 +427,38 @@ const activePageData = computed(() => {
352427
353428 if (props.urlSearchMode) {
354429 if (props.urlActivePageFilter === null) {
355 return { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength }
430 return {
431 label: 'All',
432 iconClass: 'i-lucide:text-search',
433 count: props.urlMatchesLength
434 }
356435 }
357 const result = findInEntries(props.urlActivePageFilter, props.urlMatchesLength)
358 return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.urlMatchesLength }
436 const result = findInEntries(
437 props.urlActivePageFilter,
438 props.urlMatchesLength
439 )
440 return result ??
441 {
442 label: 'All',
443 iconClass: 'i-lucide:text-search',
444 count: props.urlMatchesLength
445 }
359446 }
360447
361448 if (props.activePageFilter === null) {
362 return { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength }
449 return {
450 label: 'All',
451 iconClass: 'i-lucide:text-search',
452 count: props.resultsLength
453 }
363454 }
364455 const result = findInEntries(props.activePageFilter, props.resultsLength)
365 return result ?? { label: 'All', iconClass: 'i-lucide:text-search', count: props.resultsLength }
456 return result ??
457 {
458 label: 'All',
459 iconClass: 'i-lucide:text-search',
460 count: props.resultsLength
461 }
366462})
367463
368464function toggleListMenu() {
@@ -384,7 +480,9 @@ const allPages = computed((): (string | null)[] => {
384480})
385481
386482const currentPageIndex = computed(() => {
387 const activeKey = props.urlSearchMode ? props.urlActivePageFilter : props.activePageFilter
483 const activeKey = props.urlSearchMode
484 ? props.urlActivePageFilter
485 : props.activePageFilter
388486 return allPages.value.indexOf(activeKey)
389487})
390488
@@ -451,40 +549,55 @@ function pageNav(delta: number) {
451549 v-if="showListMenu"
452550 ref="listMenuRef"
453551 class="page-ribbon-list-menu"
552 @scroll.passive="onListMenuScroll"
454553 >
455554 <!-- "All" item -->
456555 <button
457556 type="button"
458557 class="ribbon-menu-item all-item"
459 :class="{ active: urlSearchMode
460 ? urlActivePageFilter === null
461 : activePageFilter === null }"
558 :class="{
559 active: urlSearchMode
560 ? urlActivePageFilter === null
561 : activePageFilter === null
562 }"
462563 @click="urlSearchMode
463 ? setUrlPageFilter(null)
464 : setPageFilter(null)"
564 ? setUrlPageFilter(null)
565 : setPageFilter(null)"
465566 >
466567 <span class="i-lucide:text-search ribbon-menu-item-icon" />
467568 <span class="ribbon-menu-item-label">All</span>
468 <span class="ribbon-menu-item-count">{{ urlSearchMode ? urlMatchesLength : resultsLength }}</span>
569 <span class="ribbon-menu-item-count">{{
570 urlSearchMode ? urlMatchesLength : resultsLength
571 }}</span>
469572 </button>
470573
471574 <div class="ribbon-menu-divider" />
472575
473576 <!-- Grouped pages -->
474 <template v-for="entry in groupedMenuEntries" :key="entry.type === 'page' ? entry.page.key : entry.folder.section">
577 <template
578 v-for="entry in groupedMenuEntries"
579 :key="entry.type === 'page'
580 ? entry.page.key
581 : entry.folder.section"
582 >
475583 <!-- Top-level page -->
476584 <div v-if="entry.type === 'page'" class="ribbon-menu-group">
477585 <button
478586 type="button"
479587 class="ribbon-menu-item"
480 :class="{ active: urlSearchMode
481 ? urlActivePageFilter === entry.page.key
482 : activePageFilter === entry.page.key }"
588 :class="{
589 active: urlSearchMode
590 ? urlActivePageFilter === entry.page.key
591 : activePageFilter === entry.page.key
592 }"
483593 @click="urlSearchMode
484 ? setUrlPageFilter(entry.page.key)
485 : setPageFilter(entry.page.key)"
594 ? setUrlPageFilter(entry.page.key)
595 : setPageFilter(entry.page.key)"
486596 >
487 <span :class="entry.page.iconClass" class="ribbon-menu-item-icon" />
597 <span
598 :class="entry.page.iconClass"
599 class="ribbon-menu-item-icon"
600 />
488601 <span class="ribbon-menu-item-label">{{ entry.page.label }}</span>
489602 <span class="ribbon-menu-item-count">{{ entry.page.count }}</span>
490603 </button>
@@ -493,8 +606,13 @@ function pageNav(delta: number) {
493606 <!-- Folder group -->
494607 <div v-else class="ribbon-menu-group">
495608 <h4 class="ribbon-menu-group-title">
496 <span :class="entry.folder.iconClass" class="ribbon-menu-group-icon" />
497 <span class="ribbon-menu-group-text">{{ entry.folder.section }}</span>
609 <span
610 :class="entry.folder.iconClass"
611 class="ribbon-menu-group-icon"
612 />
613 <span class="ribbon-menu-group-text">{{
614 entry.folder.section
615 }}</span>
498616 </h4>
499617 <div class="ribbon-menu-sub-items">
500618 <button
@@ -502,12 +620,14 @@ function pageNav(delta: number) {
502620 :key="page.key"
503621 type="button"
504622 class="ribbon-menu-item"
505 :class="{ active: urlSearchMode
506 ? urlActivePageFilter === page.key
507 : activePageFilter === page.key }"
623 :class="{
624 active: urlSearchMode
625 ? urlActivePageFilter === page.key
626 : activePageFilter === page.key
627 }"
508628 @click="urlSearchMode
509 ? setUrlPageFilter(page.key)
510 : setPageFilter(page.key)"
629 ? setUrlPageFilter(page.key)
630 : setPageFilter(page.key)"
511631 >
512632 <span class="ribbon-menu-item-label">{{ page.label }}</span>
513633 <span class="ribbon-menu-item-count">{{ page.count }}</span>
@@ -517,6 +637,14 @@ function pageNav(delta: number) {
517637 </template>
518638 </div>
519639 </Transition>
640
641 <Transition name="ribbon-menu-fade">
642 <div
643 v-if="showListMenu && showListMenuFade && listMenuFadeReady"
644 class="page-ribbon-list-menu-fade"
645 :style="listMenuFadeStyle"
646 />
647 </Transition>
520648 </component>
521649
522650 <!-- Tabs ribbon style (original) -->
@@ -652,7 +780,7 @@ function pageNav(delta: number) {
652780}
653781
654782.page-ribbon::after {
655 content: '';
783 content: "";
656784 position: absolute;
657785 right: 0;
658786 bottom: 0;
@@ -681,14 +809,22 @@ function pageNav(delta: number) {
681809 left: 0;
682810 justify-content: flex-start;
683811 padding-left: 6px;
684 background: linear-gradient(to right, var(--vp-local-search-bg) 60%, transparent);
812 background: linear-gradient(
813 to right,
814 var(--vp-local-search-bg) 60%,
815 transparent
816 );
685817}
686818
687819.page-ribbon-arrow.right {
688820 right: 0;
689821 justify-content: flex-end;
690822 padding-right: 6px;
691 background: linear-gradient(to left, var(--vp-local-search-bg) 60%, transparent);
823 background: linear-gradient(
824 to left,
825 var(--vp-local-search-bg) 60%,
826 transparent
827 );
692828}
693829
694830.page-ribbon-arrow:hover {
@@ -728,7 +864,7 @@ function pageNav(delta: number) {
728864}
729865
730866.page-pill::after {
731 content: '';
867 content: "";
732868 position: absolute;
733869 z-index: 1;
734870 right: 8px;
@@ -842,9 +978,7 @@ function pageNav(delta: number) {
842978 opacity: 0.55;
843979 padding: 8px 4px;
844980 cursor: pointer;
845 transition:
846 opacity 0.25s,
847 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
981 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
848982 border-radius: 0;
849983 line-height: 1;
850984}
@@ -903,6 +1037,29 @@ html.effects-disabled .ribbon-menu-btn:active {
9031037 display: none;
9041038}
9051039
1040.page-ribbon-list-menu-fade {
1041 position: absolute;
1042 z-index: 51;
1043 height: 56px;
1044 pointer-events: none;
1045 background: linear-gradient(
1046 to bottom,
1047 transparent,
1048 var(--vp-c-bg-elv)
1049 );
1050 border-radius: 0 0 12px 12px;
1051}
1052
1053.ribbon-menu-fade-enter-active,
1054.ribbon-menu-fade-leave-active {
1055 transition: opacity 0.2s;
1056}
1057
1058.ribbon-menu-fade-enter-from,
1059.ribbon-menu-fade-leave-to {
1060 opacity: 0;
1061}
1062
9061063.ribbon-menu-divider {
9071064 height: 1px;
9081065 background: var(--vp-c-divider);
docs/.vitepress/theme/components/search/SearchSettings.vue +89 −10
@@ -35,17 +35,43 @@ const emit = defineEmits<{
3535
3636const settingsPopupRef = ref<HTMLDivElement>()
3737const settingsBounding = useElementBounding(() => props.settingsButtonRef)
38const settingsPopupBounding = useElementBounding(settingsPopupRef)
39const showFade = ref(true)
3840
39type HelpSection = 'search' | 'view' | 'ribbon' | 'preload' | 'highlight' | 'history'
41const settingsFadeStyle = computed(() => ({
42 top: `${settingsPopupBounding.bottom.value - 56}px`,
43 left: `${settingsPopupBounding.left.value}px`,
44 width: `${settingsPopupBounding.width.value}px`
45}))
46
47const settingsFadeReady = computed(() => settingsPopupBounding.width.value > 0)
48
49function onSettingsScroll() {
50 const el = settingsPopupRef.value
51 if (!el) return
52 const { scrollTop, scrollHeight, clientHeight } = el
53 showFade.value = scrollTop + clientHeight < scrollHeight - 4
54}
55
56type HelpSection =
57 | 'search'
58 | 'view'
59 | 'ribbon'
60 | 'preload'
61 | 'highlight'
62 | 'history'
4063const activeHelpSection = ref<HelpSection | null>(null)
4164const helpPopupEl = ref<HTMLDivElement>()
4265const helpPopupPos = ref({ top: -9999, left: -9999 })
4366
44watch(() => props.showSettingsPopup, (val) => {
67watch(() => props.showSettingsPopup, async (val) => {
4568 if (!val) {
4669 activeHelpSection.value = null
4770 helpPopupPos.value = { top: -9999, left: -9999 }
71 return
4872 }
73 await nextTick()
74 onSettingsScroll()
4975})
5076
5177const canHoverHelp = () =>
@@ -65,13 +91,16 @@ function positionHelpPopup(btn: HTMLElement) {
6591 const aboveTop = rect.top - popupH - margin
6692 const belowTop = rect.bottom + margin
6793 const top = aboveTop >= margin ? aboveTop : belowTop
68 const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin))
94 const left = Math.max(
95 margin,
96 Math.min((vw - popupW) / 2, vw - popupW - margin)
97 )
6998 helpPopupPos.value = { top, left }
7099 } else {
71100 const anchorLeft = menuRect ? menuRect.left : rect.left
72101 helpPopupPos.value = {
73102 left: Math.max(margin, anchorLeft - popupW - 16),
74 top: rect.top,
103 top: rect.top
75104 }
76105 }
77106 })
@@ -109,7 +138,7 @@ function onHelpLeave() {
109138
110139const settingsPopupStyle = computed(() => ({
111140 top: `${settingsBounding.bottom.value + 8}px`,
112 right: `calc(100vw - ${settingsBounding.right.value}px)`,
141 right: `calc(100vw - ${settingsBounding.right.value}px)`
113142}))
114143
115144const settingsBtnEl = computed(() => props.settingsButtonRef)
@@ -129,6 +158,7 @@ function setSearchMode(mode: string) {
129158 ref="settingsPopupRef"
130159 class="search-settings-popup"
131160 :style="settingsPopupStyle"
161 @scroll.passive="onSettingsScroll"
132162 @click="closeHelpSection"
133163 >
134164 <!-- Search Mode -->
@@ -415,6 +445,14 @@ function setSearchMode(mode: string) {
415445 </div>
416446 </Transition>
417447
448 <Transition name="settings-fade">
449 <div
450 v-if="showSettingsPopup && showFade && settingsFadeReady"
451 class="search-settings-fade-overlay"
452 :style="settingsFadeStyle"
453 />
454 </Transition>
455
418456 <!-- Help popups -->
419457 <Transition name="help-popup-fade">
420458 <div
@@ -452,8 +490,10 @@ function setSearchMode(mode: string) {
452490 <p class="sh-desc">Controls how search results are displayed.</p>
453491 <div class="sh-options">
454492 <div class="sh-option">
455 <strong><TextAlignStart :size="14" stroke-width="1.5" /> Detail</strong>
456 <span>Shows a content excerpt below each result. Uses more memory.</span>
493 <strong><TextAlignStart :size="14" stroke-width="1.5" />
494 Detail</strong>
495 <span>Shows a content excerpt below each result. Uses more
496 memory.</span>
457497 </div>
458498 <div class="sh-option">
459499 <strong><List :size="14" stroke-width="1.5" /> List</strong>
@@ -466,7 +506,10 @@ function setSearchMode(mode: string) {
466506 <Layers :size="16" stroke-width="1.75" class="sh-title-icon" />
467507 Excerpt Preload
468508 </h4>
469 <p class="sh-desc">Renders excerpts for upcoming result pages ahead of time in Detail view.</p>
509 <p class="sh-desc">
510 Renders excerpts for upcoming result pages ahead of time in Detail
511 view.
512 </p>
470513 <div class="sh-options">
471514 <div class="sh-option">
472515 <strong>All</strong>
@@ -474,7 +517,8 @@ function setSearchMode(mode: string) {
474517 </div>
475518 <div class="sh-option">
476519 <strong>Next</strong>
477 <span>Also prepares the next page so flipping forward is instant</span>
520 <span>Also prepares the next page so flipping forward is
521 instant</span>
478522 </div>
479523 <div class="sh-option">
480524 <strong>Off</strong>
@@ -521,7 +565,9 @@ function setSearchMode(mode: string) {
521565 <Clock :size="16" stroke-width="1.75" class="sh-title-icon" />
522566 Search History
523567 </h4>
524 <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p>
568 <p class="sh-desc">
569 Saves recent searches and shows them when the search bar is empty.
570 </p>
525571 </template>
526572 </div>
527573 </Transition>
@@ -543,6 +589,16 @@ function setSearchMode(mode: string) {
543589 display: flex;
544590 flex-direction: column;
545591 min-width: 196px;
592 max-height: min(320px, 60vh);
593 overflow-y: auto;
594 overflow-x: hidden;
595 overscroll-behavior: contain;
596 scrollbar-width: none;
597 -ms-overflow-style: none;
598}
599
600.search-settings-popup::-webkit-scrollbar {
601 display: none;
546602}
547603
548604.dark .search-settings-popup {
@@ -662,6 +718,29 @@ function setSearchMode(mode: string) {
662718 transform: scale(0.92) translateY(-4px);
663719}
664720
721.search-settings-fade-overlay {
722 position: fixed;
723 z-index: 200;
724 height: 56px;
725 pointer-events: none;
726 background: linear-gradient(
727 to bottom,
728 transparent,
729 var(--vp-c-bg-elv)
730 );
731 border-radius: 0 0 12px 12px;
732}
733
734.settings-fade-enter-active,
735.settings-fade-leave-active {
736 transition: opacity 0.2s;
737}
738
739.settings-fade-enter-from,
740.settings-fade-leave-to {
741 opacity: 0;
742}
743
665744.search-help-popup {
666745 position: fixed;
667746 z-index: 9999;