docs/.vitepress/theme/components/Search.vue
3650 lines · 98183 bytes
1<script lang="ts" setup>
2import type { SearchResult } from 'minisearch'
3import { dataSymbol, type DefaultTheme, inBrowser, useRouter } from 'vitepress'
4import {
5 computed,
6 createApp,
7 markRaw,
8 nextTick,
9 onBeforeUnmount,
10 onMounted,
11 type Ref,
12 ref,
13 shallowRef,
14 watch,
15 watchEffect
16} from 'vue'
17// @ts-ignore
18import { pathToFile } from 'vitepress/dist/client/app/utils'
19// @ts-ignore
20import { escapeRegExp } from 'vitepress/dist/client/shared'
21
22import {
23 computedAsync,
24 onClickOutside,
25 onKeyStroke,
26 useElementBounding,
27 useEventListener,
28 useLocalStorage,
29 useScrollLock,
30 useSessionStorage,
31 useStorage,
32 watchDebounced
33} from '@vueuse/core'
34import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
35import { AnimatePresence, motion } from 'motion-v'
36
37// @ts-ignore
38import localSearchIndex from '@localSearchIndex'
39
40import {
41 ArrowLeft,
42 ArrowLeftToLine,
43 ArrowRight,
44 ArrowRightToLine,
45 ChevronRight,
46 Clock,
47 File,
48 Globe,
49 Hash,
50 LayoutList,
51 List,
52 LocateOff,
53 Regex,
54 Search,
55 Settings2,
56 TextAlignStart,
57 X
58} from 'lucide-vue-next'
59import Mark from 'mark.js/dist/mark.es6.js'
60import { sidebar } from '../../configs/constants'
61import type { PageLink } from '../../plugins/urlSearchPlugin'
62import { LRUCache } from '../composables/search/lru-cache'
63import { createSearchTranslate } from '../composables/search/translation'
64import { useData } from '../composables/search/use-data'
65import { LowEndDeviceModeStorageKey } from '../constants'
66import { enhanceAppWithTabs } from './tabs'
67
68export interface FooterTranslations {
69 selectText?: string
70 selectKeyAriaLabel?: string
71 navigateText?: string
72 navigateUpKeyAriaLabel?: string
73 navigateDownKeyAriaLabel?: string
74 switchTabsText?: string
75 switchTabsKeyAriaLabel?: string
76 switchPagesText?: string
77 switchPagesKeyAriaLabel?: string
78 closeText?: string
79 closeKeyAriaLabel?: string
80}
81
82export interface ModalTranslations {
83 displayDetails?: string
84 resetButtonTitle?: string
85 backButtonTitle?: string
86 noResultsText?: string
87 footer?: FooterTranslations
88}
89
90const showSearch = defineModel<boolean>()
91
92const el = shallowRef<HTMLElement>()
93const resultsEl = shallowRef<HTMLElement>()
94
95/* Search */
96interface Result {
97 tabs?: string[]
98 title: string
99 titles: string[]
100 text?: string
101}
102
103const searchIndexData = shallowRef(localSearchIndex)
104const searchIndexVersion = ref(0)
105
106// @ts-ignore
107if (import.meta.hot) {
108 // @ts-ignore
109 import.meta.hot.accept('@localSearchIndex', (m) => {
110 if (m) {
111 searchIndexData.value = m.default
112 searchIndexVersion.value++
113 }
114 })
115}
116
117const vitePressData = useData()
118const { activate } = useFocusTrap(el, {
119 immediate: true,
120 allowOutsideClick: true,
121 clickOutsideDeactivates: true,
122 escapeDeactivates: true,
123 returnFocusOnDeactivate: false,
124 initialFocus: () => {
125 return searchInput.value
126 }
127})
128const { localeIndex, theme } = vitePressData
129
130const disableQueryPersistence = computed(() => {
131 return (
132 theme.value.search?.provider === 'local' &&
133 theme.value.search.options?.disableQueryPersistence === true
134 )
135})
136
137const filterText = disableQueryPersistence.value
138 ? ref('')
139 : useSessionStorage('vitepress:local-search-filter', '')
140
141const lowEndDeviceMode = useStorage(LowEndDeviceModeStorageKey, 'off')
142const searchAnimationsEnabled = computed(() => lowEndDeviceMode.value !== 'on')
143const showKeyboardShortcuts = computed(() => !filterText.value)
144
145const SearchMotionDiv = motion.div
146const SearchMotionForm = motion.form
147const SearchMotionLi = motion.li
148const searchMotionDiv = computed(() =>
149 searchAnimationsEnabled.value ? SearchMotionDiv : 'div'
150)
151const searchMotionForm = computed(() =>
152 searchAnimationsEnabled.value ? SearchMotionForm : 'form'
153)
154const searchMotionLi = computed(() =>
155 searchAnimationsEnabled.value ? SearchMotionLi : 'li'
156)
157const searchMotionEase = [0.16, 1, 0.3, 1]
158
159const backdropMotion = computed(() =>
160 searchAnimationsEnabled.value
161 ? {
162 initial: { opacity: 0 },
163 animate: { opacity: 1 },
164 exit: { opacity: 0 },
165 transition: { duration: 0.55, ease: searchMotionEase }
166 }
167 : {}
168)
169
170const shellMotion = computed(() =>
171 searchAnimationsEnabled.value
172 ? {
173 layout: 'size',
174 initial: { opacity: 0, scale: 0.9375 },
175 animate: { opacity: 1, scale: 1 },
176 exit: { opacity: 0, scale: 0.9375 },
177 transition: { duration: 0.55, ease: searchMotionEase }
178 }
179 : {}
180)
181
182const formMotion = computed(() =>
183 searchAnimationsEnabled.value ? { layout: 'position' } : {}
184)
185
186const ribbonMotion = computed(() =>
187 searchAnimationsEnabled.value
188 ? {
189 layout: 'position',
190 initial: { opacity: 0, height: 0 },
191 animate: { opacity: 1, height: 'auto' },
192 exit: { opacity: 0, height: 0 },
193 transition: { duration: 0.4, ease: searchMotionEase }
194 }
195 : {}
196)
197
198const emptyStateMotion = computed(() =>
199 searchAnimationsEnabled.value
200 ? {
201 initial: { opacity: 0 },
202 animate: {
203 opacity: 1,
204 transition: { delay: 0.1 }
205 },
206 exit: {
207 opacity: 0,
208 height: 0,
209 transition: { duration: 0.2 }
210 },
211 transition: { duration: 0.7, ease: searchMotionEase }
212 }
213 : {}
214)
215
216function resultMotion(index: number) {
217 if (!searchAnimationsEnabled.value) return {}
218 return {
219 layout: true,
220 initial: { opacity: 0, scale: 0.9375 },
221 animate: { opacity: 1, scale: 1 },
222 exit: {
223 opacity: 0,
224 scale: 0.9375,
225 height: 0,
226 transition: { duration: 0.25 }
227 },
228 transition: {
229 duration: 0.55,
230 ease: searchMotionEase,
231 delay: index * 0.02
232 }
233 }
234}
235
236const excerptMotion = computed(() =>
237 searchAnimationsEnabled.value
238 ? {
239 layout: true,
240 initial: { height: 0 },
241 animate: { height: '84px' },
242 exit: { height: 0 },
243 transition: { duration: 0.4, ease: searchMotionEase }
244 }
245 : {}
246)
247
248const footerMotion = computed(() =>
249 searchAnimationsEnabled.value ? { layout: true } : {}
250)
251
252const urlFilterDebounced = ref(filterText.value)
253let urlDebounceTimer: ReturnType<typeof setTimeout> | undefined
254watch(filterText, (v) => {
255 clearTimeout(urlDebounceTimer)
256 if (!v) {
257 urlFilterDebounced.value = '' // instant clear, no trailing-edge delay
258 return
259 }
260 urlDebounceTimer = setTimeout(() => {
261 urlFilterDebounced.value = v
262 }, 60)
263})
264onBeforeUnmount(() => clearTimeout(urlDebounceTimer))
265
266const showDetailedList = useLocalStorage(
267 'vitepress:local-search-detailed-list',
268 false
269)
270
271// Three search modes: 'exact' | 'fuzzy' | 'url'
272const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>(
273 'vitepress:local-search-mode',
274 'exact'
275)
276
277// Cycle through modes on mobile (only active button is visible, tap it to advance)
278function cycleSearchMode() {
279 const modes = ['exact', 'fuzzy', 'url'] as const
280 const idx = modes.indexOf(searchMode.value)
281 searchMode.value = modes[(idx + 1) % modes.length]
282}
283
284// Keep matchExact and urlSearchMode as computed aliases
285const matchExact = computed(() => searchMode.value === 'exact')
286const urlSearchMode = computed(() => searchMode.value === 'url')
287
288// Search history
289interface SearchHistoryEntry {
290 query: string
291 mode: SearchMode
292 path?: string[]
293 href?: string
294}
295
296const saveHistoryEnabled = useLocalStorage('vitepress:local-search-save-history', false)
297
298const searchHistory = useLocalStorage<SearchHistoryEntry[]>(
299 'vitepress:local-search-history',
300 []
301)
302
303const showHistory = computed(
304 () => !filterText.value && searchHistory.value.length > 0
305)
306
307function saveToHistory(query: string, mode: SearchMode, path?: string[], href?: string) {
308 const trimmed = query.trim()
309 if (!trimmed || !saveHistoryEnabled.value) return
310 const pathKey = (path ?? []).join('\n')
311 searchHistory.value = [
312 { query: trimmed, mode, path, href },
313 ...searchHistory.value.filter(
314 (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey)
315 )
316 ]
317}
318
319function removeFromHistory(index: number) {
320 searchHistory.value = searchHistory.value.filter((_, i) => i !== index)
321}
322
323function applyHistory(entry: SearchHistoryEntry) {
324 if (entry.href) {
325 window.dispatchEvent(
326 new CustomEvent('search-nav', { detail: { query: entry.query } })
327 )
328 router.go(entry.href)
329 showSearch.value = false
330 return
331 }
332 searchMode.value = entry.mode
333 filterText.value = entry.query
334 nextTick(() => focusSearchInput(false))
335}
336
337// Mobile settings popup
338const showSettingsPopup = ref(false)
339const settingsButtonRef = ref<HTMLButtonElement>()
340const settingsPopupRef = ref<HTMLDivElement>()
341const settingsBounding = useElementBounding(settingsButtonRef)
342type HelpSection = 'search' | 'view' | 'history'
343const activeHelpSection = ref<HelpSection | null>(null)
344const helpPopupEl = ref<HTMLDivElement>()
345const helpPopupPos = ref({ top: -9999, left: -9999 })
346
347watch(showSettingsPopup, (val) => {
348 if (!val) {
349 activeHelpSection.value = null
350 helpPopupPos.value = { top: -9999, left: -9999 }
351 }
352})
353
354function toggleHelpSection(section: HelpSection, e: MouseEvent) {
355 if (activeHelpSection.value === section) {
356 activeHelpSection.value = null
357 helpPopupPos.value = { top: -9999, left: -9999 }
358 return
359 }
360 activeHelpSection.value = section
361 helpPopupPos.value = { top: -9999, left: -9999 }
362 const btn = e.currentTarget as HTMLElement
363 const rect = btn.getBoundingClientRect()
364 nextTick(() => {
365 const popupW = helpPopupEl.value?.offsetWidth || 260
366 const popupH = helpPopupEl.value?.offsetHeight || 200
367 const vw = window.innerWidth
368 const margin = 8
369 const isMobile = vw < 768
370 if (isMobile) {
371 const aboveTop = rect.top - popupH - margin
372 const belowTop = rect.bottom + margin
373 const top = aboveTop >= margin ? aboveTop : belowTop
374 const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin))
375 helpPopupPos.value = { top, left }
376 } else {
377 helpPopupPos.value = {
378 left: Math.max(margin, rect.left - popupW - 16),
379 top: rect.top,
380 }
381 }
382 })
383}
384
385const settingsPopupStyle = computed(() => ({
386 top: `${settingsBounding.bottom.value + 8}px`,
387 right: `calc(100vw - ${settingsBounding.right.value}px)`,
388}))
389
390onClickOutside(settingsPopupRef, () => {
391 showSettingsPopup.value = false
392}, { ignore: [settingsButtonRef] })
393
394interface PageGroupCount {
395 key: string
396 count: number
397}
398
399const urlMatches = shallowRef<PageLink[]>([])
400const urlPageGroupCounts = shallowRef<PageGroupCount[]>([])
401
402interface UrlResult {
403 tabs?: string[]
404 href: string
405 linkText: string
406 pageId: string
407 anchor: string
408 titles: string[]
409 highlighted: string
410}
411
412const URL_PAGE_SIZE = 25
413
414// 1-indexed current page within the URL results.
415const urlPage = ref(1)
416
417// Full URL match set returned by the search worker.
418// Used for accurate page-group counts in the ribbon and for pagination.
419
420// URL mode page ribbon — mirrors the normal pageGroups/filteredResults logic
421const urlActivePageFilter = ref<string | null>(null)
422
423const urlPageGroups = computed(() =>
424 urlPageGroupCounts.value
425 .map((group) => ({
426 key: group.key,
427 label: getPageLabel(group.key),
428 count: group.count
429 }))
430 .sort((a, b) => getPageOrder(a.key) - getPageOrder(b.key))
431)
432
433// Full match set honoring the active ribbon page filter (uncapped).
434const urlFilteredMatches = computed((): PageLink[] => {
435 if (!urlActivePageFilter.value) return urlMatches.value
436 return urlMatches.value.filter((l) => l.pageId === urlActivePageFilter.value)
437})
438
439// Total number of result pages (Google-style paging through urlFilteredMatches).
440const urlTotalPages = computed(() =>
441 Math.max(1, Math.ceil(urlFilteredMatches.value.length / URL_PAGE_SIZE))
442)
443
444// Clamp the current page whenever the result set shrinks.
445const urlCurrentPage = computed(() =>
446 Math.min(urlPage.value, urlTotalPages.value)
447)
448
449// The rows actually rendered: the current page's slice of the filtered matches.
450const filteredUrlResults = computed((): UrlResult[] => {
451 const matches = urlFilteredMatches.value
452 const start = (urlCurrentPage.value - 1) * URL_PAGE_SIZE
453 const end = start + URL_PAGE_SIZE
454 const out: UrlResult[] = []
455 const query = urlFilterDebounced.value.trim()
456 for (let i = start; i < end && i < matches.length; i++) {
457 const link = matches[i]
458 out.push({
459 href: link.href,
460 linkText: link.linkText,
461 pageId: link.pageId,
462 anchor: link.anchor,
463 titles: link.titles,
464 tabs: link.tabs,
465 highlighted: highlightUrl(link.href, query)
466 })
467 }
468 return out
469})
470
471function escapeHtml(value: string) {
472 return value
473 .replace(/&/g, '&')
474 .replace(/</g, '<')
475 .replace(/>/g, '>')
476 .replace(/"/g, '"')
477 .replace(/'/g, ''')
478}
479
480function highlightUrl(url: string, query: string) {
481 const needle = query.trim()
482 if (!needle) return escapeHtml(url)
483
484 const lowerUrl = url.toLowerCase()
485 const lowerNeedle = needle.toLowerCase()
486 let out = ''
487 let cursor = 0
488 let index = lowerUrl.indexOf(lowerNeedle)
489
490 while (index !== -1) {
491 out += escapeHtml(url.slice(cursor, index))
492 out += `<mark class="url-highlight">${
493 escapeHtml(url.slice(index, index + needle.length))
494 }</mark>`
495 cursor = index + needle.length
496 index = lowerUrl.indexOf(lowerNeedle, cursor)
497 }
498
499 return out + escapeHtml(url.slice(cursor))
500}
501
502// Compact page-number list with ellipses, e.g. [1, '…', 4, 5, 6, '…', 12].
503const urlPageList = computed<(number | '…')[]>(() => {
504 const total = urlTotalPages.value
505 const current = urlCurrentPage.value
506 if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1)
507 const pages: (number | '…')[] = [1]
508 const left = Math.max(2, current - 1)
509 const right = Math.min(total - 1, current + 1)
510 if (left > 2) pages.push('…')
511 for (let p = left; p <= right; p++) pages.push(p)
512 if (right < total - 1) pages.push('…')
513 pages.push(total)
514 return pages
515})
516
517function goToUrlPage(p: number) {
518 const target = Math.min(Math.max(1, p), urlTotalPages.value)
519 if (target === urlCurrentPage.value) return
520 urlPage.value = target
521 selectedIndex.value = filteredUrlResults.value.length ? 1 : -1
522 nextTick(() => {
523 if (resultsEl.value) resultsEl.value.scrollTop = 0
524 scrollToSelectedResult()
525 })
526}
527
528// Reset to page 1 whenever the query changes or the page filter changes.
529watch([urlFilterDebounced, urlActivePageFilter], () => {
530 urlPage.value = 1
531})
532
533// Reset URL ribbon filter if the active page disappears from the groups.
534watch(urlMatches, () => {
535 if (
536 urlActivePageFilter.value &&
537 !urlPageGroups.value.some((g) => g.key === urlActivePageFilter.value)
538 ) {
539 urlActivePageFilter.value = null
540 }
541})
542
543watch(urlSearchMode, (active) => {
544 if (!active) {
545 urlActivePageFilter.value = null
546 urlPage.value = 1
547 }
548})
549
550function setUrlPageFilter(key: string | null) {
551 urlActivePageFilter.value = urlActivePageFilter.value === key ? null : key
552 urlPage.value = 1
553 selectedIndex.value = filteredUrlResults.value.length ? 1 : -1
554 nextTick(() => {
555 if (resultsEl.value) resultsEl.value.scrollTop = 0
556 scrollToSelectedResult()
557 })
558}
559
560const disableDetailedView = computed(() => {
561 return (
562 theme.value.search?.provider === 'local' &&
563 theme.value.search.options?.detailedView === false
564 )
565})
566
567const buttonText = computed(() => {
568 const options = theme.value.search?.options
569
570 return (
571 options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
572 options?.translations?.button?.buttonText ||
573 'Search'
574 )
575})
576
577watchEffect(() => {
578 if (disableDetailedView.value) {
579 showDetailedList.value = false
580 }
581})
582
583const results: Ref<(SearchResult & Result)[]> = shallowRef([])
584
585const currentTerms = shallowRef(new Set<string>())
586
587const enableNoResults = ref(false)
588const textSearchLoading = ref(false)
589const urlSearchLoading = ref(false)
590const searchLoading = computed(() =>
591 urlSearchMode.value ? urlSearchLoading.value : textSearchLoading.value
592)
593const pageMeta = (() => {
594 const map = new Map<string, { label: string; order: number }>()
595 let order = 0
596 const stripIcon = (text: string) =>
597 text
598 .replace(/<[^>]*>/g, '')
599 .replace(/\s+/g, ' ')
600 .trim()
601 const walk = (items: DefaultTheme.SidebarItem[]) => {
602 for (const item of items) {
603 if (item.link) {
604 const key = item.link.replace(/\/$/, '')
605 if (!map.has(key)) {
606 map.set(key, { label: stripIcon(item.text ?? key), order: order++ })
607 }
608 }
609 if (item.items) walk(item.items)
610 }
611 }
612 walk(sidebar as DefaultTheme.SidebarItem[])
613 return map
614})()
615
616type SearchMode = 'exact' | 'fuzzy' | 'url'
617
618interface TextSearchWorkerPayload {
619 results: (SearchResult & Result)[]
620 terms: string[]
621}
622
623interface UrlSearchWorkerPayload {
624 matches: PageLink[]
625 pageGroups: PageGroupCount[]
626}
627
628interface LoadIndexWorkerRequest {
629 type: 'load-index'
630 localeIndex: string
631 indexJson: unknown
632 indexVersion: number
633 config: ReturnType<typeof getMiniSearchWorkerConfig>
634}
635
636interface TextSearchWorkerRequest {
637 type: 'text-search'
638 query: string
639 mode: SearchMode
640 pageOrderEntries: [string, number][]
641}
642
643interface UrlSearchWorkerRequest {
644 type: 'url-search'
645 query: string
646 pageOrderEntries: [string, number][]
647}
648
649type SearchWorkerRequest =
650 | LoadIndexWorkerRequest
651 | TextSearchWorkerRequest
652 | UrlSearchWorkerRequest
653
654const activePageFilter = ref<string | null>(null)
655const searchWorkerReady = ref(false)
656const searchWorkerConfigKey = computed(() =>
657 JSON.stringify(getMiniSearchWorkerConfig())
658)
659let searchWorker: Worker | undefined
660let searchWorkerRequestId = 0
661let loadedWorkerIndexKey = ''
662const searchWorkerRequests = new Map<
663 number,
664 {
665 resolve: (value: unknown) => void
666 reject: (reason?: unknown) => void
667 }
668>()
669
670function getPageOrderEntries(): [string, number][] {
671 return [...pageMeta.entries()].map(([key, meta]) => [key, meta.order])
672}
673
674function stripNonCloneable(value: unknown): unknown {
675 if (typeof value === 'function' || typeof value === 'symbol') return undefined
676 if (!value || typeof value !== 'object') return value
677 if (Array.isArray(value)) {
678 return value
679 .map((item) => stripNonCloneable(item))
680 .filter((item) => item !== undefined)
681 }
682
683 const out: Record<string, unknown> = {}
684 for (const [key, nestedValue] of Object.entries(value)) {
685 const cloneable = stripNonCloneable(nestedValue)
686 if (cloneable !== undefined) out[key] = cloneable
687 }
688 return out
689}
690
691function getMiniSearchWorkerConfig() {
692 const miniSearch = theme.value.search?.provider === 'local'
693 ? theme.value.search.options?.miniSearch
694 : undefined
695 const rawSearchOptions = miniSearch?.searchOptions as
696 | Record<string, unknown>
697 | undefined
698
699 return {
700 options: stripNonCloneable(miniSearch?.options) as
701 | Record<string, unknown>
702 | undefined,
703 searchOptions: stripNonCloneable(rawSearchOptions) as
704 | Record<string, unknown>
705 | undefined,
706 useDefaultBoostDocument:
707 typeof rawSearchOptions?.boostDocument === 'function'
708 }
709}
710
711function ensureSearchWorker() {
712 if (!inBrowser || searchWorker) return searchWorker
713
714 try {
715 searchWorker = new Worker(
716 new URL('../workers/searchWorker.ts', import.meta.url),
717 {
718 type: 'module'
719 }
720 )
721 } catch (error) {
722 console.error('[search] failed to start search worker', error)
723 return
724 }
725
726 searchWorker.onmessage = (event: MessageEvent) => {
727 const data = event.data as {
728 id: number
729 type: string
730 payload?: unknown
731 error?: string
732 }
733 const request = searchWorkerRequests.get(data.id)
734 if (!request) return
735
736 searchWorkerRequests.delete(data.id)
737 if (data.type.endsWith(':error')) {
738 request.reject(new Error(data.error ?? 'Search worker failed'))
739 } else {
740 request.resolve(data.payload)
741 }
742 }
743 searchWorker.onerror = (event) => {
744 console.error('[search] search worker error', event)
745 }
746 searchWorkerReady.value = true
747 return searchWorker
748}
749
750function postSearchWorker<T>(message: SearchWorkerRequest) {
751 const worker = ensureSearchWorker()
752 if (!worker) return Promise.reject(new Error('Search worker is unavailable'))
753
754 const id = ++searchWorkerRequestId
755 return new Promise<T>((resolve, reject) => {
756 searchWorkerRequests.set(id, {
757 resolve: (value) => resolve(value as T),
758 reject
759 })
760 worker.postMessage({ ...message, id })
761 })
762}
763
764onMounted(() => {
765 ensureSearchWorker()
766})
767
768onBeforeUnmount(() => {
769 searchWorker?.terminate()
770 searchWorker = undefined
771 loadedWorkerIndexKey = ''
772 searchWorkerReady.value = false
773 for (const request of searchWorkerRequests.values()) {
774 request.reject(new Error('Search worker was terminated'))
775 }
776 searchWorkerRequests.clear()
777})
778
779watch(
780 () =>
781 [
782 searchWorkerReady.value,
783 showSearch.value,
784 urlSearchMode.value,
785 urlFilterDebounced.value
786 ] as const,
787 async ([ready, isOpen, active, query], _old, onCleanup) => {
788 let canceled = false
789 onCleanup(() => {
790 canceled = true
791 })
792
793 if (!active || !isOpen || !query.trim()) {
794 urlMatches.value = []
795 urlPageGroupCounts.value = []
796 urlSearchLoading.value = false
797 return
798 }
799 if (!ready) {
800 urlSearchLoading.value = false
801 return
802 }
803
804 urlSearchLoading.value = true
805 try {
806 const payload = await postSearchWorker<UrlSearchWorkerPayload>({
807 type: 'url-search',
808 query,
809 pageOrderEntries: getPageOrderEntries()
810 })
811 if (canceled) return
812 urlMatches.value = payload.matches
813 urlPageGroupCounts.value = payload.pageGroups
814 urlSearchLoading.value = false
815 } catch (error) {
816 if (!canceled) {
817 console.error('[search] URL search worker request failed', error)
818 urlMatches.value = []
819 urlPageGroupCounts.value = []
820 urlSearchLoading.value = false
821 }
822 }
823 },
824 { immediate: true }
825)
826
827function getPageKey(id: string) {
828 return getDocId(id).replace(/\/$/, '')
829}
830
831function getDocId(id: string) {
832 const hashIndex = id.indexOf('#')
833 return hashIndex === -1 ? id : id.slice(0, hashIndex)
834}
835
836function getDocAnchor(id: string) {
837 const hashIndex = id.indexOf('#')
838 return hashIndex === -1 ? '' : id.slice(hashIndex + 1)
839}
840
841function getPageLabel(key: string) {
842 return pageMeta.get(key)?.label ?? key.replace(/^\//, '')
843}
844
845function getPageOrder(key: string) {
846 return pageMeta.get(key)?.order ?? Number.MAX_SAFE_INTEGER
847}
848
849const pageGroups = computed(() => {
850 const map = new Map<string, { key: string; label: string; count: number }>()
851 for (const r of results.value) {
852 const key = getPageKey(r.id)
853 const existing = map.get(key)
854 if (existing) existing.count++
855 else map.set(key, { key, label: getPageLabel(key), count: 1 })
856 }
857 return [...map.values()].sort(
858 (a, b) => getPageOrder(a.key) - getPageOrder(b.key)
859 )
860})
861
862const filteredResults = computed(() => {
863 if (!activePageFilter.value) return results.value
864 return results.value.filter(
865 (r) => getPageKey(r.id) === activePageFilter.value
866 )
867})
868
869// --- Normal-mode (exact/fuzzy) pagination ---------------------------------
870// Mirrors the URL-mode pager. filteredResults stays the full filtered set;
871// pagedResults is the current page slice that actually renders.
872const NORMAL_PAGE_SIZE = URL_PAGE_SIZE
873
874const normalPage = ref(1)
875
876const normalTotalPages = computed(() =>
877 Math.max(1, Math.ceil(filteredResults.value.length / NORMAL_PAGE_SIZE))
878)
879
880const normalCurrentPage = computed(() =>
881 Math.min(normalPage.value, normalTotalPages.value)
882)
883
884const pagedResults = computed(() => {
885 const start = (normalCurrentPage.value - 1) * NORMAL_PAGE_SIZE
886 return filteredResults.value.slice(start, start + NORMAL_PAGE_SIZE)
887})
888
889const normalPageList = computed<(number | '…')[]>(() => {
890 const total = normalTotalPages.value
891 const current = normalCurrentPage.value
892 if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1)
893 const pages: (number | '…')[] = [1]
894 const left = Math.max(2, current - 1)
895 const right = Math.min(total - 1, current + 1)
896 if (left > 2) pages.push('…')
897 for (let p = left; p <= right; p++) pages.push(p)
898 if (right < total - 1) pages.push('…')
899 pages.push(total)
900 return pages
901})
902
903function goToNormalPage(p: number) {
904 const target = Math.min(Math.max(1, p), normalTotalPages.value)
905 if (target === normalCurrentPage.value) return
906 normalPage.value = target
907 selectedIndex.value = pagedResults.value.length ? 1 : -1
908 nextTick(() => {
909 if (resultsEl.value) resultsEl.value.scrollTop = 0
910 scrollToSelectedResult()
911 reapplyHighlights()
912 })
913}
914
915// Reset to page 1 when the query changes (results replaced) or filter changes.
916watch([results, activePageFilter], () => {
917 normalPage.value = 1
918})
919// ---------------------------------------------------------------------------
920
921function setPageFilter(key: string | null) {
922 activePageFilter.value = activePageFilter.value === key ? null : key
923 selectedIndex.value = filteredResults.value.length ? 1 : -1
924 nextTick(() => {
925 if (resultsEl.value) resultsEl.value.scrollTop = 0
926 scrollToSelectedResult()
927 reapplyHighlights()
928 })
929}
930
931async function reapplyHighlights() {
932 if (!showDetailedList.value || !currentTerms.value.size) {
933 centerExcerptsUntilSettled()
934 return
935 }
936 await new Promise<void>((resolve) => {
937 mark.value?.unmark({
938 done: () => {
939 mark.value?.markRegExp(formMarkRegex(currentTerms.value), {
940 done: () => resolve()
941 })
942 }
943 })
944 })
945 await nextTick()
946 centerExcerptsUntilSettled()
947}
948
949watch(results, () => {
950 if (
951 activePageFilter.value &&
952 !pageGroups.value.some((g) => g.key === activePageFilter.value)
953 ) {
954 activePageFilter.value = null
955 }
956})
957
958watch(filterText, () => {
959 enableNoResults.value = false
960})
961
962const ribbonTrack = shallowRef<HTMLElement>()
963const ribbonCanScrollLeft = ref(false)
964const ribbonCanScrollRight = ref(false)
965
966function getRibbonTrack(): HTMLElement | null {
967 return (
968 ribbonTrack.value ??
969 (el.value?.querySelector('.page-ribbon-track') as HTMLElement | null)
970 )
971}
972
973function updateRibbonOverflow() {
974 const track = getRibbonTrack()
975 if (!track) {
976 ribbonCanScrollLeft.value = false
977 ribbonCanScrollRight.value = false
978 return
979 }
980 ribbonCanScrollLeft.value = track.scrollLeft > 2
981 ribbonCanScrollRight.value =
982 track.scrollWidth - track.clientWidth - track.scrollLeft > 2
983}
984
985function scrollActivePagePillIntoView(direction = 0) {
986 nextTick(() => {
987 const track = getRibbonTrack()
988 if (!track) return
989
990 const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')]
991 const activeIndex = pills.findIndex((pill) =>
992 pill.classList.contains('active')
993 )
994 const active = pills[activeIndex]
995 if (!active) return
996
997 const trackRect = track.getBoundingClientRect()
998 const activeRect = active.getBoundingClientRect()
999 const gap = 8
1000 let nextScrollLeft = track.scrollLeft
1001
1002 if (activeRect.left < trackRect.left) {
1003 nextScrollLeft += activeRect.left - trackRect.left - gap
1004 } else if (activeRect.right > trackRect.right) {
1005 nextScrollLeft += activeRect.right - trackRect.right + gap
1006 }
1007
1008 const peek = pills[activeIndex + Math.sign(direction)]
1009 if (peek) {
1010 const peekRect = peek.getBoundingClientRect()
1011 if (direction > 0 && peekRect.right > trackRect.right) {
1012 nextScrollLeft += peekRect.right - trackRect.right + gap
1013 } else if (direction < 0 && peekRect.left < trackRect.left) {
1014 nextScrollLeft += peekRect.left - trackRect.left - gap
1015 }
1016 }
1017
1018 const max = track.scrollWidth - track.clientWidth
1019 track.scrollTo({
1020 left: Math.max(0, Math.min(max, nextScrollLeft)),
1021 behavior: searchAnimationsEnabled.value ? 'smooth' : 'auto'
1022 })
1023 updateRibbonOverflow()
1024 })
1025}
1026
1027let ribbonAnimHandle = 0
1028
1029function scrollRibbon(direction: number) {
1030 const track = getRibbonTrack()
1031 if (!track) return
1032 const max = track.scrollWidth - track.clientWidth
1033 const amount = track.clientWidth * 0.7 * direction
1034 const from = track.scrollLeft
1035 const to = Math.max(0, Math.min(max, from + amount))
1036 if (to === from) return
1037
1038 if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle)
1039
1040 if (!searchAnimationsEnabled.value) {
1041 track.scrollLeft = to
1042 updateRibbonOverflow()
1043 return
1044 }
1045
1046 const duration = 280
1047 const start = performance.now()
1048 const ease = (t: number) => 1 - Math.pow(1 - t, 3)
1049
1050 const step = (now: number) => {
1051 const t = Math.min(1, (now - start) / duration)
1052 track.scrollLeft = from + (to - from) * ease(t)
1053 updateRibbonOverflow()
1054 if (t < 1) {
1055 ribbonAnimHandle = requestAnimationFrame(step)
1056 } else {
1057 ribbonAnimHandle = 0
1058 }
1059 }
1060 ribbonAnimHandle = requestAnimationFrame(step)
1061}
1062
1063watch(pageGroups, () => {
1064 nextTick(updateRibbonOverflow)
1065})
1066
1067watch(urlPageGroups, () => {
1068 nextTick(updateRibbonOverflow)
1069})
1070
1071useEventListener('resize', () => {
1072 updateRibbonOverflow()
1073})
1074
1075const mark = computedAsync(async () => {
1076 if (!resultsEl.value) return
1077 return markRaw(new Mark(resultsEl.value))
1078}, null)
1079
1080const cache = new LRUCache<string, Map<string, string>>(120)
1081
1082const inFlightExcerpts = new Map<string, Promise<void>>()
1083
1084const EAGER_EXCERPTS = 15
1085
1086function buildDocExcerpt(
1087 docId: string,
1088 filterTextValue: string
1089): Promise<void> {
1090 const cacheId = `${docId}\n${filterTextValue}`
1091 if (cache.get(cacheId)) return Promise.resolve()
1092 const pending = inFlightExcerpts.get(cacheId)
1093 if (pending) return pending
1094
1095 const job = (async () => {
1096 const { mod } = await fetchExcerpt(docId)
1097 if (cache.get(cacheId)) return
1098
1099 const comp = (mod as any).default ?? mod
1100 if (!(comp?.render || comp?.setup)) return // nothing renderable; don't cache
1101
1102 const map = new Map<string, string>()
1103 const app = createApp(comp)
1104 app.config.warnHandler = () => {}
1105 enhanceAppWithTabs(app, { renderAll: true })
1106 app.provide(dataSymbol, vitePressData)
1107 Object.defineProperties(app.config.globalProperties, {
1108 $frontmatter: {
1109 get() {
1110 return vitePressData.frontmatter.value
1111 }
1112 },
1113 $params: {
1114 get() {
1115 return vitePressData.page.value.params
1116 }
1117 }
1118 })
1119 const div = document.createElement('div')
1120 try {
1121 app.mount(div)
1122 const headings = div.querySelectorAll('h1, h2, h3, h4, h5, h6')
1123 headings.forEach((heading) => {
1124 const href = heading.querySelector('a')?.getAttribute('href')
1125 const anchor = href?.startsWith('#') && href.slice(1)
1126 if (!anchor) return
1127 let html = ''
1128 let node = heading as Element
1129 while (
1130 (node = node.nextElementSibling!) &&
1131 !/^h[1-6]$/i.test(node.tagName)
1132 ) {
1133 html += (node as HTMLElement).outerHTML
1134 }
1135 map.set(anchor, html)
1136 })
1137 } catch (e) {
1138 console.error('[search] excerpt render failed for', docId, e)
1139 } finally {
1140 try {
1141 app.unmount()
1142 } catch {
1143 /* ignore */
1144 }
1145 }
1146 cache.set(cacheId, map)
1147 })()
1148
1149 inFlightExcerpts.set(cacheId, job)
1150 job.finally(() => {
1151 if (inFlightExcerpts.get(cacheId) === job) inFlightExcerpts.delete(cacheId)
1152 })
1153 return job
1154}
1155
1156watchDebounced(
1157 () =>
1158 [
1159 searchWorkerReady.value,
1160 showSearch.value,
1161 localeIndex.value,
1162 searchIndexVersion.value,
1163 searchWorkerConfigKey.value,
1164 filterText.value,
1165 showDetailedList.value,
1166 searchMode.value
1167 ] as const,
1168 async (
1169 [
1170 ready,
1171 isOpen,
1172 localeIndexValue,
1173 indexVersion,
1174 configKey,
1175 filterTextValue,
1176 showDetailedListValue,
1177 mode
1178 ],
1179 old,
1180 onCleanup
1181 ) => {
1182 if (
1183 old?.[2] !== localeIndexValue ||
1184 old?.[3] !== indexVersion ||
1185 old?.[4] !== configKey
1186 ) {
1187 // Locale/config changes rebuild the worker index, so cached excerpts may no
1188 // longer match the active result set.
1189 cache.clear()
1190 }
1191
1192 let canceled = false
1193 onCleanup(() => {
1194 canceled = true
1195 })
1196
1197 if (!ready || !isOpen) {
1198 textSearchLoading.value = false
1199 return
1200 }
1201
1202 // In URL search mode, skip normal text search
1203 if (mode === 'url') {
1204 results.value = []
1205 currentTerms.value = new Set()
1206 enableNoResults.value = Boolean(filterTextValue.trim())
1207 textSearchLoading.value = false
1208 return
1209 }
1210
1211 const searchQuery = filterTextValue.trim()
1212 if (!searchQuery) {
1213 results.value = []
1214 currentTerms.value = new Set()
1215 enableNoResults.value = false
1216 textSearchLoading.value = false
1217 return
1218 }
1219
1220 textSearchLoading.value = true
1221 let workerPayload: TextSearchWorkerPayload
1222 try {
1223 const workerIndexKey =
1224 `${localeIndexValue}\n${indexVersion}\n${configKey}`
1225 if (loadedWorkerIndexKey !== workerIndexKey) {
1226 const indexJson = (await searchIndexData.value[localeIndexValue]?.())
1227 ?.default
1228 if (canceled) return
1229 await postSearchWorker<void>({
1230 type: 'load-index',
1231 localeIndex: localeIndexValue,
1232 indexJson,
1233 indexVersion,
1234 config: getMiniSearchWorkerConfig()
1235 })
1236 if (canceled) return
1237 loadedWorkerIndexKey = workerIndexKey
1238 }
1239
1240 workerPayload = await postSearchWorker<TextSearchWorkerPayload>({
1241 type: 'text-search',
1242 query: searchQuery,
1243 mode,
1244 pageOrderEntries: getPageOrderEntries()
1245 })
1246 } catch (error) {
1247 if (!canceled) {
1248 console.error('[search] text search worker request failed', error)
1249 results.value = []
1250 currentTerms.value = new Set()
1251 enableNoResults.value = true
1252 textSearchLoading.value = false
1253 }
1254 return
1255 }
1256 if (canceled) return
1257
1258 const _result = workerPayload.results
1259 const terms = new Set(workerPayload.terms)
1260 currentTerms.value = terms
1261 enableNoResults.value = true
1262
1263 if (!_result.length) {
1264 results.value = []
1265 textSearchLoading.value = false
1266 return
1267 }
1268
1269 const toRows = (list: (SearchResult & Result)[]) =>
1270 list.map((r) => {
1271 const id = getDocId(r.id)
1272 const anchor = getDocAnchor(r.id)
1273 const map = cache.get(`${id}\n${searchQuery}`)
1274 return { ...r, text: map?.get(anchor) ?? '' }
1275 })
1276
1277 const highlight = () =>
1278 new Promise<void>((resolve) => {
1279 if (!terms.size || !mark.value) {
1280 resolve()
1281 return
1282 }
1283 mark.value.unmark({
1284 done: () => {
1285 mark.value?.markRegExp(formMarkRegex(terms), {
1286 done: () => resolve()
1287 })
1288 }
1289 })
1290 })
1291
1292 const docOrderList: string[] = []
1293 const seenDocs = new Set<string>()
1294 for (const r of _result) {
1295 const docId = getDocId(r.id)
1296 if (!seenDocs.has(docId)) {
1297 seenDocs.add(docId)
1298 docOrderList.push(docId)
1299 }
1300 }
1301
1302 // Show results immediately (excerpts may be empty on first detail-view switch;
1303 // they fill in below once built)
1304 results.value = toRows(_result)
1305
1306 if (showDetailedListValue) {
1307 const eagerDocs = new Set<string>()
1308 for (const r of _result.slice(0, EAGER_EXCERPTS)) {
1309 eagerDocs.add(getDocId(r.id))
1310 }
1311 await Promise.all(
1312 [...eagerDocs].map((docId) => buildDocExcerpt(docId, searchQuery))
1313 )
1314 if (canceled) return
1315 }
1316
1317 results.value = toRows(_result)
1318
1319 await nextTick()
1320 if (canceled) return
1321 await highlight()
1322 await nextTick()
1323 await nextFrame()
1324 if (canceled) return
1325
1326 if (resultsEl.value) {
1327 resultsEl.value.scrollTop = 0
1328 }
1329 centerExcerptsUntilSettled()
1330
1331 if (showDetailedListValue) {
1332 const built = new Set<string>()
1333 for (const r of _result.slice(0, EAGER_EXCERPTS)) {
1334 built.add(getDocId(r.id))
1335 }
1336 const remaining = docOrderList.filter((d) => !built.has(d))
1337 if (remaining.length) {
1338 for (const docId of remaining) {
1339 await buildDocExcerpt(docId, searchQuery)
1340 if (canceled) return
1341 await nextFrame()
1342 if (canceled) return
1343 }
1344 results.value = toRows(_result)
1345 await nextTick()
1346 if (canceled) return
1347 await highlight()
1348 await nextTick()
1349 await nextFrame()
1350 if (canceled) return
1351 centerExcerptsUntilSettled()
1352 }
1353 }
1354 textSearchLoading.value = false
1355 },
1356 { debounce: 80, immediate: true }
1357)
1358
1359function centerExcerpts() {
1360 const excerpts = el.value?.querySelectorAll('.result .excerpt') ?? []
1361 for (let i = 0; i < excerpts.length; i++) {
1362 const excerptElement = excerpts[i] as HTMLElement
1363
1364 const markNode = excerptElement.querySelector(
1365 'mark[data-markjs="true"]'
1366 ) as HTMLElement | null
1367 if (!markNode) continue
1368
1369 const viewportHeight =
1370 Number.parseFloat(getComputedStyle(excerptElement).maxHeight) || 84
1371
1372 let offset = 0
1373 let node: HTMLElement | null = markNode
1374 while (node && node !== excerptElement) {
1375 offset += node.offsetTop
1376 node = node.offsetParent as HTMLElement | null
1377 }
1378
1379 const targetScrollTop = offset - viewportHeight / 2 +
1380 markNode.offsetHeight / 2
1381 excerptElement.scrollTop = Math.max(0, targetScrollTop)
1382 }
1383}
1384
1385let centerHandle = 0
1386
1387function centerExcerptsUntilSettled(
1388 duration = searchAnimationsEnabled.value ? 450 : 0
1389) {
1390 if (centerHandle) cancelAnimationFrame(centerHandle)
1391
1392 if (duration <= 0) {
1393 centerHandle = requestAnimationFrame(() => {
1394 centerExcerpts()
1395 centerHandle = 0
1396 })
1397 return
1398 }
1399
1400 const start = performance.now()
1401 const tick = () => {
1402 centerExcerpts()
1403 if (performance.now() - start < duration) {
1404 centerHandle = requestAnimationFrame(tick)
1405 } else {
1406 centerHandle = 0
1407 }
1408 }
1409 centerHandle = requestAnimationFrame(tick)
1410}
1411
1412onBeforeUnmount(() => {
1413 if (centerHandle) cancelAnimationFrame(centerHandle)
1414 if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle)
1415})
1416
1417const excerptCache = new LRUCache<string, unknown>(24)
1418
1419async function fetchExcerpt(id: string) {
1420 const docId = getDocId(id)
1421
1422 const cached = excerptCache.get(docId)
1423 if (cached) return { id, mod: cached }
1424
1425 const file = pathToFile(docId)
1426 try {
1427 if (!file) throw new Error(`Cannot find file for id: ${id}`)
1428 const mod = await import(/*@vite-ignore*/ file)
1429
1430 excerptCache.set(docId, mod)
1431
1432 return { id, mod }
1433 } catch (e) {
1434 console.error(e)
1435 return { id, mod: {} }
1436 }
1437}
1438
1439const nextFrame = () =>
1440 new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
1441
1442function hasExcerptPreview(html?: string) {
1443 if (!html) return false
1444 return Boolean(
1445 html
1446 .replace(/<[^>]*>/g, ' ')
1447 .replace(/ | /gi, ' ')
1448 .replace(/\s+/g, ' ')
1449 .trim()
1450 )
1451}
1452
1453/* Search input focus */
1454
1455const searchInput = ref<HTMLInputElement>()
1456const disableReset = computed(() => {
1457 return filterText.value?.length <= 0
1458})
1459function focusSearchInput(select = true) {
1460 searchInput.value?.focus()
1461 select && searchInput.value?.select()
1462}
1463
1464onMounted(() => {
1465 focusSearchInput()
1466})
1467
1468function onSearchBarClick(event: PointerEvent) {
1469 if (event.pointerType === 'mouse') {
1470 focusSearchInput()
1471 }
1472}
1473
1474/* Search keyboard selection */
1475
1476const selectedIndex = ref(-1)
1477const disableMouseOver = ref(true)
1478
1479// Active result list length (URL mode vs normal mode) — current page only
1480const activeResultsLength = computed(() =>
1481 urlSearchMode.value
1482 ? filteredUrlResults.value.length
1483 : pagedResults.value.length
1484)
1485
1486watch(pagedResults, (r) => {
1487 if (!urlSearchMode.value) {
1488 selectedIndex.value = r.length ? 0 : -1
1489 scrollToSelectedResult()
1490 }
1491})
1492
1493watch(filteredUrlResults, (r) => {
1494 if (urlSearchMode.value) {
1495 selectedIndex.value = r.length ? 0 : -1
1496 scrollToSelectedResult()
1497 }
1498})
1499
1500function scrollToSelectedResult() {
1501 nextTick(() => {
1502 const selectedEl = document.querySelector('.result.selected')
1503 selectedEl?.scrollIntoView({ block: 'nearest' })
1504 })
1505}
1506
1507function goToSearchPageDelta(delta: number) {
1508 if (urlSearchMode.value) {
1509 const target = urlCurrentPage.value + delta
1510 if (target < 1 || target > urlTotalPages.value) return false
1511 goToUrlPage(target)
1512 return true
1513 }
1514
1515 const target = normalCurrentPage.value + delta
1516 if (target < 1 || target > normalTotalPages.value) return false
1517 goToNormalPage(target)
1518 return true
1519}
1520
1521function cyclePageTab(delta: number) {
1522 if (urlSearchMode.value) {
1523 if (urlPageGroups.value.length <= 1) return false
1524 const keys = [null, ...urlPageGroups.value.map((group) => group.key)]
1525 const current = keys.indexOf(urlActivePageFilter.value)
1526 const next = (current + delta + keys.length) % keys.length
1527 setUrlPageFilter(keys[next])
1528 scrollActivePagePillIntoView(delta)
1529 return true
1530 }
1531
1532 if (pageGroups.value.length <= 1) return false
1533 const keys = [null, ...pageGroups.value.map((group) => group.key)]
1534 const current = keys.indexOf(activePageFilter.value)
1535 const next = (current + delta + keys.length) % keys.length
1536 setPageFilter(keys[next])
1537 scrollActivePagePillIntoView(delta)
1538 return true
1539}
1540
1541onKeyStroke('ArrowUp', (event) => {
1542 event.preventDefault()
1543 selectedIndex.value--
1544 if (selectedIndex.value < 0) {
1545 selectedIndex.value = activeResultsLength.value - 1
1546 }
1547 disableMouseOver.value = true
1548 scrollToSelectedResult()
1549})
1550
1551onKeyStroke('ArrowDown', (event) => {
1552 event.preventDefault()
1553 selectedIndex.value++
1554 if (selectedIndex.value >= activeResultsLength.value + 1) {
1555 selectedIndex.value = 0
1556 }
1557 disableMouseOver.value = true
1558 scrollToSelectedResult()
1559})
1560
1561onKeyStroke('ArrowLeft', (event) => {
1562 if (!goToSearchPageDelta(-1)) return
1563 event.preventDefault()
1564 disableMouseOver.value = true
1565})
1566
1567onKeyStroke('ArrowRight', (event) => {
1568 if (!goToSearchPageDelta(1)) return
1569 event.preventDefault()
1570 disableMouseOver.value = true
1571})
1572
1573onKeyStroke('Tab', (event) => {
1574 if (!showSearch.value) return
1575 if (!cyclePageTab(event.shiftKey ? -1 : 1)) return
1576 event.preventDefault()
1577 disableMouseOver.value = true
1578})
1579
1580const router = useRouter()
1581
1582function buildResultHref(pageId: string, tabs?: string[], anchor = '') {
1583 const params: string[] = []
1584 if (tabs?.length) {
1585 params.push(`t=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`)
1586 }
1587
1588 let hash = ''
1589 if (anchor.startsWith('collapsible-')) {
1590 const collapsible = anchor.slice('collapsible-'.length)
1591 if (collapsible) params.push(`c=${encodeURIComponent(collapsible)}`)
1592 } else {
1593 const lastTab = tabs?.length ? tabs[tabs.length - 1] : ''
1594 const isRedundantTabHeading = Boolean(anchor) && anchor === `tab-${lastTab}`
1595 if (anchor && !isRedundantTabHeading) {
1596 hash = `#${encodeURIComponent(anchor)}`
1597 }
1598 }
1599
1600 const query = params.length ? `?${params.join('&')}` : ''
1601 return `${pageId}${query}${hash}`
1602}
1603
1604function getSearchResultHref(item: SearchResult & Result) {
1605 const id = String(item.id)
1606 const hashIndex = id.indexOf('#')
1607 if (hashIndex < 0) return buildResultHref(id, item.tabs)
1608
1609 return buildResultHref(
1610 id.slice(0, hashIndex),
1611 item.tabs,
1612 id.slice(hashIndex + 1)
1613 )
1614}
1615
1616function navigateToUrlResult(item: UrlResult) {
1617 saveToHistory(filterText.value, searchMode.value, [getPageLabel(item.pageId), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean), buildResultHref(item.pageId, item.tabs, item.anchor))
1618 window.dispatchEvent(
1619 new CustomEvent('search-nav', { detail: { query: filterText.value } })
1620 )
1621 router.go(buildResultHref(item.pageId, item.tabs, item.anchor))
1622 showSearch.value = false
1623}
1624
1625onKeyStroke('Enter', (e) => {
1626 if (e.isComposing) return
1627
1628 if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') {
1629 return
1630 }
1631
1632 const index = selectedIndex.value - 1
1633
1634 if (index === -1) {
1635 // @ts-ignore
1636 window.toggleAI({ value: filterText.value })
1637 showSearch.value = false
1638 return
1639 }
1640
1641 // URL search mode: navigate to the page containing the link (like normal search)
1642 if (urlSearchMode.value) {
1643 const selectedUrl = filteredUrlResults.value[index]
1644 if (selectedUrl) {
1645 navigateToUrlResult(selectedUrl)
1646 }
1647 return
1648 }
1649
1650 const selectedPackage = pagedResults.value[index]
1651 if (e.target instanceof HTMLInputElement && !selectedPackage) {
1652 e.preventDefault()
1653 return
1654 }
1655
1656 if (selectedPackage) {
1657 saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(selectedPackage.id))), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(selectedPackage))
1658 window.dispatchEvent(
1659 new CustomEvent('search-nav', {
1660 detail: { query: filterText.value }
1661 })
1662 )
1663 router.go(getSearchResultHref(selectedPackage))
1664 showSearch.value = false
1665 }
1666})
1667
1668function onResultClick(item: SearchResult & Result) {
1669 saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(item.id))), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(item))
1670 window.dispatchEvent(
1671 new CustomEvent('search-nav', {
1672 detail: { query: filterText.value }
1673 })
1674 )
1675 showSearch.value = false
1676}
1677
1678onKeyStroke('Escape', () => {
1679 if (showSettingsPopup.value) {
1680 showSettingsPopup.value = false
1681 return
1682 }
1683 showSearch.value = false
1684})
1685
1686// Translations
1687const defaultTranslations = {
1688 modal: {
1689 displayDetails: 'Display detailed list',
1690 exactMatchTitle: 'Exact search',
1691 resetButtonTitle: 'Reset search',
1692 backButtonTitle: 'Close search',
1693 noResultsText: 'No results for',
1694 footer: {
1695 selectText: 'select',
1696 selectKeyAriaLabel: 'enter',
1697 navigateText: 'navigate',
1698 navigateUpKeyAriaLabel: 'up arrow',
1699 navigateDownKeyAriaLabel: 'down arrow',
1700 switchTabsText: 'switch tabs',
1701 switchTabsKeyAriaLabel: 'shift tab and tab',
1702 switchPagesText: 'switch pages',
1703 switchPagesKeyAriaLabel: 'left and right arrow',
1704 closeText: 'close',
1705 closeKeyAriaLabel: 'escape'
1706 }
1707 }
1708}
1709
1710const translate = createSearchTranslate(defaultTranslations)
1711
1712// Back
1713
1714onMounted(() => {
1715 // Prevents going to previous site
1716 window.history.pushState(null, '', null)
1717})
1718
1719useEventListener('popstate', (event) => {
1720 event.preventDefault()
1721 showSearch.value = false
1722})
1723
1724/** Lock body */
1725const isLocked = useScrollLock(inBrowser ? document.body : null)
1726
1727watch(
1728 () => showSearch.value,
1729 (val) => {
1730 if (!val) {
1731 isLocked.value = false
1732 return
1733 }
1734
1735 nextTick(() => {
1736 isLocked.value = true
1737 nextTick().then(() => {
1738 activate()
1739 updateRibbonOverflow()
1740 })
1741 })
1742 }
1743)
1744
1745function formMarkRegex(terms: Set<string>) {
1746 return new RegExp(
1747 [...terms]
1748 .sort((a, b) => b.length - a.length)
1749 .map((term) => `(${escapeRegExp(term)})`)
1750 .join('|'),
1751 'gi'
1752 )
1753}
1754
1755function decodeHtml(html: string): string {
1756 const txt = document.createElement('textarea')
1757 txt.innerHTML = html
1758 return txt.value
1759}
1760
1761function toHistoryPathHtml(html: string): string {
1762 const stripped = decodeHtml(html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim())
1763 if (stripped) return escapeHtml(stripped)
1764 return html.trim()
1765}
1766
1767function resetSearch() {
1768 filterText.value = ''
1769 nextTick().then(() => focusSearchInput(false))
1770}
1771
1772function onMouseMove(e: MouseEvent) {
1773 if (!disableMouseOver.value) return
1774 const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result')
1775 const index = Number.parseInt(el?.dataset.index!)
1776 if (index >= 0 && index !== selectedIndex.value) {
1777 selectedIndex.value = index
1778 }
1779 disableMouseOver.value = false
1780}
1781</script>
1782
1783<template>
1784 <Teleport to="body">
1785 <div
1786 ref="el"
1787 role="button"
1788 :aria-owns="results?.length ? 'localsearch-list' : undefined"
1789 aria-expanded="true"
1790 aria-haspopup="listbox"
1791 aria-labelledby="localsearch-label"
1792 class="VPLocalSearchBox"
1793 :class="{ 'pointer-events-none': !showSearch }"
1794 >
1795 <AnimatePresence>
1796 <component
1797 :is="searchMotionDiv"
1798 v-if="showSearch"
1799 class="backdrop"
1800 @click="showSearch = false"
1801 v-bind="backdropMotion"
1802 />
1803 </AnimatePresence>
1804
1805 <AnimatePresence>
1806 <component
1807 :is="searchMotionDiv"
1808 v-if="showSearch"
1809 class="shell"
1810 v-bind="shellMotion"
1811 >
1812 <component
1813 :is="searchMotionForm"
1814 class="search-bar"
1815 v-bind="formMotion"
1816 @pointerup="onSearchBarClick($event)"
1817 @submit.prevent=""
1818 >
1819 <label
1820 :title="buttonText"
1821 id="localsearch-label"
1822 for="localsearch-input"
1823 >
1824 <span
1825 aria-hidden="true"
1826 class="vpi-search search-icon local-search-icon"
1827 />
1828 </label>
1829 <div class="search-actions before">
1830 <button
1831 class="back-button"
1832 :title="translate('modal.backButtonTitle')"
1833 @click="showSearch = false"
1834 >
1835 <span class="vpi-arrow-left local-search-icon" />
1836 </button>
1837 </div>
1838 <input
1839 ref="searchInput"
1840 v-model="filterText"
1841 :aria-activedescendant="selectedIndex > -1
1842 ? 'localsearch-item-' + selectedIndex
1843 : undefined"
1844 aria-autocomplete="both"
1845 :aria-controls="results?.length ? 'localsearch-list' : undefined"
1846 aria-labelledby="localsearch-label"
1847 autocapitalize="off"
1848 autocomplete="off"
1849 autocorrect="off"
1850 class="search-input"
1851 id="localsearch-input"
1852 enterkeyhint="go"
1853 maxlength="64"
1854 :placeholder="buttonText"
1855 spellcheck="false"
1856 type="search"
1857 />
1858 <div class="search-actions">
1859 <button
1860 v-if="searchLoading"
1861 class="search-loading-button"
1862 type="button"
1863 >
1864 <img
1865 class="search-loading-bubba"
1866 src="/bubba.webp"
1867 alt="Bubba loading"
1868 />
1869 </button>
1870 <div
1871 v-if="!disableDetailedView && searchMode !== 'url'"
1872 class="view-group toolbar-group"
1873 >
1874 <button
1875 type="button"
1876 class="mode-btn"
1877 :class="{ 'mode-active': showDetailedList }"
1878 title="Detail view (Consumes more RAM)"
1879 @click="showDetailedList
1880 ? showDetailedList = false
1881 : showDetailedList = true"
1882 >
1883 <TextAlignStart :size="18" stroke-width="1.25" />
1884 </button>
1885 <button
1886 type="button"
1887 class="mode-btn"
1888 :class="{ 'mode-active': !showDetailedList }"
1889 title="List view (Consumes less RAM)"
1890 @click="!showDetailedList
1891 ? showDetailedList = true
1892 : showDetailedList = false"
1893 >
1894 <List :size="18" stroke-width="1.25" />
1895 </button>
1896 </div>
1897 <div class="search-mode-group toolbar-group">
1898 <button
1899 type="button"
1900 class="mode-btn"
1901 :class="{ 'mode-active': searchMode === 'exact' }"
1902 title="Exact search"
1903 @click="searchMode === 'exact'
1904 ? cycleSearchMode()
1905 : searchMode = 'exact'"
1906 >
1907 <Regex :size="18" stroke-width="1.25" />
1908 </button>
1909 <button
1910 type="button"
1911 class="mode-btn"
1912 :class="{ 'mode-active': searchMode === 'fuzzy' }"
1913 title="Fuzzy search"
1914 @click="searchMode === 'fuzzy'
1915 ? cycleSearchMode()
1916 : searchMode = 'fuzzy'"
1917 >
1918 <LocateOff :size="18" stroke-width="1.25" />
1919 </button>
1920 <button
1921 type="button"
1922 class="mode-btn"
1923 :class="{ 'mode-active': searchMode === 'url' }"
1924 title="URL search"
1925 @click="searchMode === 'url'
1926 ? cycleSearchMode()
1927 : searchMode = 'url'"
1928 >
1929 <Globe :size="18" stroke-width="1.25" />
1930 </button>
1931 </div>
1932 <button
1933 ref="settingsButtonRef"
1934 type="button"
1935 class="mode-btn settings-toggle-btn"
1936 :class="{ 'mode-active': showSettingsPopup }"
1937 title="Search settings"
1938 @click.stop="showSettingsPopup = !showSettingsPopup"
1939 >
1940 <Settings2 :size="18" stroke-width="1.25" />
1941 </button>
1942 <button
1943 class="clear-button"
1944 type="reset"
1945 :disabled="disableReset"
1946 :title="translate('modal.resetButtonTitle')"
1947 @click="resetSearch"
1948 >
1949 <X :size="19" stroke-width="1.25" />
1950 </button>
1951 </div>
1952 </component>
1953
1954 <AnimatePresence>
1955 <component
1956 :is="searchMotionDiv"
1957 v-if="urlSearchMode
1958 ? urlPageGroups.length > 1
1959 : pageGroups.length > 1"
1960 class="page-ribbon"
1961 :class="{
1962 'can-scroll-left': ribbonCanScrollLeft,
1963 'can-scroll-right': ribbonCanScrollRight
1964 }"
1965 v-bind="ribbonMotion"
1966 >
1967 <button
1968 v-if="ribbonCanScrollLeft"
1969 type="button"
1970 class="page-ribbon-arrow left"
1971 aria-label="Scroll filters left"
1972 @click="scrollRibbon(-1)"
1973 >
1974 <ChevronRight :size="18" stroke-width="1.75" />
1975 </button>
1976 <div
1977 ref="ribbonTrack"
1978 class="page-ribbon-track"
1979 @scroll="updateRibbonOverflow"
1980 >
1981 <!-- URL mode tabs -->
1982 <template v-if="urlSearchMode">
1983 <button
1984 type="button"
1985 class="page-pill"
1986 :class="{
1987 active: urlActivePageFilter === null
1988 }"
1989 @click="setUrlPageFilter(null)"
1990 >
1991 All
1992 <span class="page-pill-count">{{ urlMatches.length }}</span>
1993 </button>
1994 <button
1995 v-for="group in urlPageGroups"
1996 :key="group.key"
1997 type="button"
1998 class="page-pill"
1999 :class="{
2000 active:
2001 urlActivePageFilter === group.key
2002 }"
2003 @click="setUrlPageFilter(group.key)"
2004 >
2005 <span class="page-pill-label">{{ group.label }}</span>
2006 <span class="page-pill-count">{{ group.count }}</span>
2007 </button>
2008 </template>
2009 <!-- Normal mode tabs -->
2010 <template v-else>
2011 <button
2012 type="button"
2013 class="page-pill"
2014 :class="{ active: activePageFilter === null }"
2015 @click="setPageFilter(null)"
2016 >
2017 All
2018 <span class="page-pill-count">{{ results.length }}</span>
2019 </button>
2020 <button
2021 v-for="group in pageGroups"
2022 :key="group.key"
2023 type="button"
2024 class="page-pill"
2025 :class="{
2026 active: activePageFilter === group.key
2027 }"
2028 @click="setPageFilter(group.key)"
2029 >
2030 <span class="page-pill-label">{{ group.label }}</span>
2031 <span class="page-pill-count">{{ group.count }}</span>
2032 </button>
2033 </template>
2034 </div>
2035 <button
2036 v-if="ribbonCanScrollRight"
2037 type="button"
2038 class="page-ribbon-arrow right"
2039 aria-label="Scroll filters right"
2040 @click="scrollRibbon(1)"
2041 >
2042 <ChevronRight :size="18" stroke-width="1.75" />
2043 </button>
2044 </component>
2045 </AnimatePresence>
2046
2047 <ul
2048 ref="resultsEl"
2049 :id="results?.length ? 'localsearch-list' : undefined"
2050 :role="results?.length ? 'listbox' : undefined"
2051 :aria-labelledby="results?.length ? 'localsearch-label' : undefined"
2052 class="results"
2053 @mousemove="onMouseMove"
2054 >
2055 <!-- Empty state (shared) -->
2056 <AnimatePresence>
2057 <component
2058 :is="searchMotionDiv"
2059 v-if="!showHistory && (urlSearchMode
2060 ? (!filterText || !urlMatches.length)
2061 : (!filterText || !filteredResults.length))"
2062 class="flex flex-1 flex-col justify-center items-center w-full min-h-full gap-2 font-medium text-sm text-center text-gray-500 dark:text-gray-300 m-auto opacity-90"
2063 v-bind="emptyStateMotion"
2064 >
2065 <img
2066 class="h-40 object-contain object-center"
2067 src="/asset/smolame.png"
2068 alt="Smol ame"
2069 />
2070 <h1 v-if="filterText">Couldn't find anything, try again?</h1>
2071 <h1 v-else>Looking for something?</h1>
2072 </component>
2073 </AnimatePresence>
2074
2075 <!-- Search history -->
2076 <AnimatePresence>
2077 <component
2078 :is="searchMotionDiv"
2079 v-if="showHistory"
2080 class="history-list"
2081 v-bind="emptyStateMotion"
2082 >
2083 <div class="history-header">
2084 <span>Recent searches</span>
2085 <button
2086 class="history-clear-all"
2087 title="Clear all history"
2088 @click.stop="searchHistory = []"
2089 >
2090 <X :size="16" stroke-width="1.25" />
2091 </button>
2092 </div>
2093 <ul class="history-items">
2094 <li
2095 v-for="(entry, index) in searchHistory"
2096 :key="index"
2097 class="history-item"
2098 @click="applyHistory(entry)"
2099 >
2100 <div class="history-main">
2101 <span class="history-query">{{ entry.query }}</span>
2102 <template v-if="entry.path?.length">
2103 <ArrowRight :size="13" stroke-width="1.5" class="history-arrow" />
2104 <template v-for="(seg, si) in entry.path" :key="si">
2105 <span
2106 class="history-path-seg"
2107 :class="{
2108 'history-path-end': si === entry.path.length - 1,
2109 'history-path-only': entry.path.length === 1
2110 }"
2111 v-html="seg"
2112 />
2113 <span v-if="si < entry.path.length - 1" class="history-path-sep">›</span>
2114 </template>
2115 </template>
2116 </div>
2117 <component
2118 :is="entry.mode === 'exact' ? Regex : entry.mode === 'fuzzy' ? LocateOff : Globe"
2119 :size="14"
2120 stroke-width="1.25"
2121 class="history-mode-icon"
2122 />
2123 <button
2124 class="history-remove"
2125 :title="'Remove \'' + entry.query + '\' from history'"
2126 @click.stop="removeFromHistory(index)"
2127 >
2128 <X :size="16" stroke-width="1.25" />
2129 </button>
2130 </li>
2131 </ul>
2132 </component>
2133 </AnimatePresence>
2134
2135 <!-- URL search results -->
2136 <template v-if="urlSearchMode">
2137 <AnimatePresence>
2138 <component
2139 :is="searchMotionLi"
2140 v-for="(item, index) in filteredUrlResults"
2141 :key="'url-' + urlCurrentPage + '-' +
2142 item.pageId + '-' +
2143 item.anchor + '-' + index"
2144 class="result-layout"
2145 :id="'localsearch-item-' + (index + 1)"
2146 :aria-selected="selectedIndex === index + 1
2147 ? 'true'
2148 : 'false'"
2149 role="option"
2150 v-bind="resultMotion(index)"
2151 >
2152 <div
2153 class="result url-result-card"
2154 :class="{
2155 selected: selectedIndex === index + 1
2156 }"
2157 :aria-label="item.href"
2158 role="button"
2159 @mouseenter="!disableMouseOver &&
2160 (selectedIndex = index + 1)"
2161 @focusin="selectedIndex = index + 1"
2162 @click="navigateToUrlResult(item)"
2163 :data-index="index + 1"
2164 >
2165 <div class="url-result-body">
2166 <div class="url-path">
2167 <Hash
2168 v-if="item.anchor ||
2169 item.titles.length > 0"
2170 stroke-width="1.25"
2171 :size="18"
2172 />
2173 <File v-else stroke-width="1.25" :size="18" />
2174 <span
2175 v-for="(t, ti) in item.titles"
2176 :key="ti"
2177 class="url-path-segment"
2178 >
2179 <span class="text" v-html="t" />
2180 <ArrowRight
2181 stroke-width="1.25"
2182 :size="18"
2183 class="mx-0.5"
2184 />
2185 </span>
2186 <span
2187 v-if="item.linkText"
2188 class="url-path-current"
2189 v-html="item.linkText"
2190 />
2191 </div>
2192 <a
2193 :href="item.href"
2194 target="_blank"
2195 rel="noopener noreferrer"
2196 class="url-link"
2197 :title="item.href"
2198 @click.stop
2199 v-html="item.highlighted"
2200 >
2201 </a>
2202 </div>
2203 </div>
2204 </component>
2205 </AnimatePresence>
2206 </template>
2207
2208 <!-- Normal search results -->
2209 <template v-else>
2210 <AnimatePresence>
2211 <component
2212 :is="searchMotionLi"
2213 v-for="(p, index) in pagedResults"
2214 :key="'normal-' + normalCurrentPage + '-' + p.id"
2215 class="result-layout"
2216 :id="'localsearch-item-' + (index + 1)"
2217 :aria-selected="selectedIndex === index + 1
2218 ? 'true'
2219 : 'false'"
2220 role="option"
2221 v-bind="resultMotion(index)"
2222 >
2223 <a
2224 :href="getSearchResultHref(p)"
2225 class="result"
2226 :class="{
2227 selected: selectedIndex === index + 1
2228 }"
2229 :aria-label="[...p.titles, p.title].join(' > ')"
2230 @mouseenter="!disableMouseOver &&
2231 (selectedIndex = index + 1)"
2232 @focusin="selectedIndex = index + 1"
2233 @click="onResultClick(p)"
2234 :data-index="index + 1"
2235 >
2236 <div>
2237 <div class="titles">
2238 <Hash
2239 v-if="getDocAnchor(p.id) ||
2240 p.titles.length > 0"
2241 stroke-width="1.25"
2242 :size="18"
2243 />
2244 <File v-else stroke-width="1.25" :size="18" />
2245 <span
2246 v-for="(t, index) in p.titles"
2247 :key="index"
2248 class="title"
2249 >
2250 <span class="text" v-html="t" />
2251 <ArrowRight
2252 stroke-width="1.25"
2253 :size="18"
2254 class="mx-0.5"
2255 />
2256 </span>
2257 <span class="title main">
2258 <span class="text" v-html="p.title" />
2259 </span>
2260 </div>
2261
2262 <div
2263 v-if="showDetailedList &&
2264 hasExcerptPreview(p.text)"
2265 class="excerpt-wrapper"
2266 >
2267 <component
2268 :is="searchMotionDiv"
2269 class="excerpt"
2270 inert
2271 v-bind="excerptMotion"
2272 >
2273 <div class="vp-doc" v-html="p.text" />
2274 </component>
2275 <div class="excerpt-gradient-bottom" />
2276 <div class="excerpt-gradient-top" />
2277 </div>
2278 </div>
2279 </a>
2280 </component>
2281 </AnimatePresence>
2282 </template>
2283 </ul>
2284
2285 <!-- Bottom section: pagination (when needed). Always rendered so the
2286 shell's rounded bottom edge stays consistent. -->
2287 <nav
2288 class="url-pagination"
2289 aria-label="Search result pages"
2290 >
2291 <div
2292 v-if="(urlSearchMode
2293 ? urlTotalPages
2294 : normalTotalPages) > 1"
2295 class="url-pagination-segment"
2296 >
2297 <button
2298 type="button"
2299 class="url-page-btn url-page-nav"
2300 :disabled="(urlSearchMode
2301 ? urlCurrentPage
2302 : normalCurrentPage) <= 1"
2303 aria-label="Previous page"
2304 @click="urlSearchMode
2305 ? goToUrlPage(urlCurrentPage - 1)
2306 : goToNormalPage(normalCurrentPage - 1)"
2307 >
2308 <ChevronRight
2309 :size="14"
2310 stroke-width="2"
2311 style="transform: rotate(180deg)"
2312 />
2313 </button>
2314
2315 <template
2316 v-for="(p, pi) in urlSearchMode ? urlPageList : normalPageList"
2317 :key="pi"
2318 >
2319 <span v-if="p === '…'" class="url-page-ellipsis">…</span>
2320 <button
2321 v-else
2322 type="button"
2323 class="url-page-btn"
2324 :class="{
2325 active: p === (urlSearchMode
2326 ? urlCurrentPage
2327 : normalCurrentPage)
2328 }"
2329 :aria-current="p === (urlSearchMode
2330 ? urlCurrentPage
2331 : normalCurrentPage)
2332 ? 'page'
2333 : undefined"
2334 @click="urlSearchMode
2335 ? goToUrlPage(p as number)
2336 : goToNormalPage(p as number)"
2337 >
2338 {{ p }}
2339 </button>
2340 </template>
2341
2342 <button
2343 type="button"
2344 class="url-page-btn url-page-nav"
2345 :disabled="(urlSearchMode
2346 ? urlCurrentPage
2347 : normalCurrentPage) >=
2348 (urlSearchMode
2349 ? urlTotalPages
2350 : normalTotalPages)"
2351 aria-label="Next page"
2352 @click="urlSearchMode
2353 ? goToUrlPage(urlCurrentPage + 1)
2354 : goToNormalPage(normalCurrentPage + 1)"
2355 >
2356 <ChevronRight :size="14" stroke-width="2" />
2357 </button>
2358 </div>
2359 </nav>
2360
2361 <component
2362 :is="searchMotionDiv"
2363 v-if="showKeyboardShortcuts"
2364 class="search-keyboard-shortcuts"
2365 v-bind="footerMotion"
2366 >
2367 <span>
2368 <kbd
2369 :aria-label="translate(
2370 'modal.footer.navigateUpKeyAriaLabel'
2371 )"
2372 >
2373 <span class="vpi-arrow-up navigate-icon" />
2374 </kbd>
2375 <kbd
2376 :aria-label="translate(
2377 'modal.footer.navigateDownKeyAriaLabel'
2378 )"
2379 >
2380 <span class="vpi-arrow-down navigate-icon" />
2381 </kbd>
2382 {{ translate('modal.footer.navigateText') }}
2383 </span>
2384 <span>
2385 <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')">
2386 <ArrowLeftToLine class="navigate-icon" :size="14" stroke-width="2" />
2387 </kbd>
2388 <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')">
2389 <ArrowRightToLine class="navigate-icon" :size="14" stroke-width="2" />
2390 </kbd>
2391 {{ translate('modal.footer.switchTabsText') }}
2392 </span>
2393 <span>
2394 <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')">
2395 <ArrowLeft class="navigate-icon" :size="14" stroke-width="2" />
2396 </kbd>
2397 <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')">
2398 <ArrowRight class="navigate-icon" :size="14" stroke-width="2" />
2399 </kbd>
2400 {{ translate('modal.footer.switchPagesText') }}
2401 </span>
2402 <span>
2403 <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')">
2404 <span class="vpi-corner-down-left navigate-icon" />
2405 </kbd>
2406 {{ translate('modal.footer.selectText') }}
2407 </span>
2408 <span>
2409 <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')">
2410 esc
2411 </kbd>
2412 {{ translate('modal.footer.closeText') }}
2413 </span>
2414 </component>
2415 <Teleport to="body">
2416 <Transition name="settings-popup">
2417 <div
2418 v-if="showSettingsPopup"
2419 ref="settingsPopupRef"
2420 class="search-settings-popup"
2421 :style="settingsPopupStyle"
2422 @click="activeHelpSection = null"
2423 >
2424 <div class="settings-section">
2425 <div class="settings-section-header">
2426 <div class="settings-section-label">
2427 <Search :size="14" stroke-width="1.75" />
2428 Search
2429 </div>
2430 <button
2431 type="button"
2432 class="settings-help-btn"
2433 :class="{ active: activeHelpSection === 'search' }"
2434 aria-label="Search mode help"
2435 @click.stop="toggleHelpSection('search', $event)"
2436 >
2437 <span class="i-carbon:help-filled settings-help-icon" />
2438 </button>
2439 </div>
2440 <div class="settings-options">
2441 <button
2442 type="button"
2443 class="settings-option"
2444 :class="{ active: searchMode === 'exact' }"
2445 @click="searchMode = 'exact'"
2446 >
2447 <span>Exact</span>
2448 </button>
2449 <button
2450 type="button"
2451 class="settings-option"
2452 :class="{ active: searchMode === 'fuzzy' }"
2453 @click="searchMode = 'fuzzy'"
2454 >
2455 <span>Fuzzy</span>
2456 </button>
2457 <button
2458 type="button"
2459 class="settings-option"
2460 :class="{ active: searchMode === 'url' }"
2461 @click="searchMode = 'url'"
2462 >
2463 <span>URL</span>
2464 </button>
2465 </div>
2466 </div>
2467 <div
2468 v-if="!disableDetailedView && searchMode !== 'url'"
2469 class="settings-section"
2470 >
2471 <div class="settings-section-header">
2472 <div class="settings-section-label">
2473 <LayoutList :size="14" stroke-width="1.75" />
2474 View
2475 </div>
2476 <button
2477 type="button"
2478 class="settings-help-btn"
2479 :class="{ active: activeHelpSection === 'view' }"
2480 aria-label="Result view help"
2481 @click.stop="toggleHelpSection('view', $event)"
2482 >
2483 <span class="i-carbon:help-filled settings-help-icon" />
2484 </button>
2485 </div>
2486 <div class="settings-options">
2487 <button
2488 type="button"
2489 class="settings-option"
2490 :class="{ active: showDetailedList }"
2491 @click="showDetailedList = true"
2492 >
2493 <span>Detail</span>
2494 </button>
2495 <button
2496 type="button"
2497 class="settings-option"
2498 :class="{ active: !showDetailedList }"
2499 @click="showDetailedList = false"
2500 >
2501 <span>List</span>
2502 </button>
2503 </div>
2504 </div>
2505 <div class="settings-section">
2506 <div class="settings-section-header">
2507 <div class="settings-section-label">
2508 <Clock :size="14" stroke-width="1.75" />
2509 History
2510 </div>
2511 <button
2512 type="button"
2513 class="settings-help-btn"
2514 :class="{ active: activeHelpSection === 'history' }"
2515 aria-label="Search history help"
2516 @click.stop="toggleHelpSection('history', $event)"
2517 >
2518 <span class="i-carbon:help-filled settings-help-icon" />
2519 </button>
2520 </div>
2521 <div class="settings-options">
2522 <button
2523 type="button"
2524 class="settings-option"
2525 :class="{ active: saveHistoryEnabled }"
2526 @click="saveHistoryEnabled = true"
2527 >
2528 <span>On</span>
2529 </button>
2530 <button
2531 type="button"
2532 class="settings-option"
2533 :class="{ active: !saveHistoryEnabled }"
2534 @click="saveHistoryEnabled = false"
2535 >
2536 <span>Off</span>
2537 </button>
2538 </div>
2539 </div>
2540 </div>
2541 </Transition>
2542 <Transition name="help-popup-fade">
2543 <div
2544 v-if="activeHelpSection && showSettingsPopup"
2545 ref="helpPopupEl"
2546 class="search-help-popup"
2547 :style="{ top: helpPopupPos.top + 'px', left: helpPopupPos.left + 'px' }"
2548 >
2549 <template v-if="activeHelpSection === 'search'">
2550 <h4 class="sh-title">
2551 <Search :size="16" stroke-width="1.75" class="sh-title-icon" />
2552 Search Mode
2553 </h4>
2554 <p class="sh-desc">Choose how queries are matched against content.</p>
2555 <div class="sh-options">
2556 <div class="sh-option">
2557 <strong>
2558 <Regex :size="14" stroke-width="1.5" />
2559 Exact
2560 </strong>
2561 <span>Matches the exact phrase you type</span>
2562 </div>
2563 <div class="sh-option">
2564 <strong>
2565 <LocateOff :size="14" stroke-width="1.5" />
2566 Fuzzy
2567 </strong>
2568 <span>Approximate matching that tolerates typos</span>
2569 </div>
2570 <div class="sh-option">
2571 <strong>
2572 <Globe :size="14" stroke-width="1.5" />
2573 URL
2574 </strong>
2575 <span>Searches through hyperlinks</span>
2576 </div>
2577 </div>
2578 </template>
2579 <template v-else-if="activeHelpSection === 'view'">
2580 <h4 class="sh-title">
2581 <LayoutList :size="16" stroke-width="1.75" class="sh-title-icon" />
2582 Result View
2583 </h4>
2584 <p class="sh-desc">Controls how search results are displayed.</p>
2585 <div class="sh-options">
2586 <div class="sh-option">
2587 <strong>
2588 <TextAlignStart :size="14" stroke-width="1.5" />
2589 Detail
2590 </strong>
2591 <span>Shows a content excerpt below each result. Uses more memory.</span>
2592 </div>
2593 <div class="sh-option">
2594 <strong>
2595 <List :size="14" stroke-width="1.5" />
2596 List
2597 </strong>
2598 <span>Compact list of titles only. Uses less memory.</span>
2599 </div>
2600 </div>
2601 </template>
2602 <template v-else-if="activeHelpSection === 'history'">
2603 <h4 class="sh-title">
2604 <Clock :size="16" stroke-width="1.75" class="sh-title-icon" />
2605 Search History
2606 </h4>
2607 <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p>
2608 </template>
2609 </div>
2610 </Transition>
2611 </Teleport>
2612 </component>
2613 </AnimatePresence>
2614
2615 <button v-if="!showSearch" />
2616 </div>
2617 </Teleport>
2618</template>
2619
2620<style scoped>
2621.VPLocalSearchBox {
2622 position: fixed;
2623 z-index: 100;
2624 inset: 0;
2625 display: flex;
2626 align-items: flex-start;
2627}
2628
2629@media (max-width: 767px) {
2630 .VPLocalSearchBox {
2631 align-items: stretch;
2632 }
2633}
2634
2635.backdrop {
2636 position: absolute;
2637 inset: 0;
2638 background: var(--vp-backdrop-bg-color);
2639}
2640
2641.shell {
2642 position: relative;
2643 box-sizing: border-box;
2644 padding: 12px 12px 8px;
2645 margin: 64px auto;
2646 display: flex;
2647 flex-direction: column;
2648 gap: 16px;
2649 background: var(--vp-local-search-bg);
2650 width: min(100vw - 60px, 700px);
2651 height: 100%;
2652 max-height: min(100vh - 128px, 680px);
2653 border-radius: 6px;
2654}
2655
2656@media (max-width: 767px) {
2657 .shell {
2658 margin: 0;
2659 width: 100vw;
2660 height: 100vh;
2661 height: 100dvh;
2662 max-height: none;
2663 border-radius: 0;
2664 overflow: hidden;
2665 gap: 8px;
2666 }
2667}
2668
2669.search-bar {
2670 flex: 0 0 auto !important;
2671 min-height: 44px !important;
2672 border: 1px solid var(--vp-c-divider);
2673 border-radius: 4px;
2674 display: flex;
2675 align-items: center;
2676 padding: 0 12px;
2677 cursor: text;
2678}
2679
2680@media (max-width: 767px) {
2681 .search-bar {
2682 padding: 0 8px;
2683 min-height: 40px !important;
2684 }
2685}
2686
2687.search-bar:focus-within {
2688 border-color: var(--vp-c-brand-1);
2689}
2690
2691.page-ribbon {
2692 display: flex;
2693 align-items: center;
2694 padding: 12px 0 4px;
2695 padding-inline: calc(var(--spacing) * 3);
2696 position: relative;
2697 min-width: 0;
2698 flex: none;
2699 overflow: hidden;
2700 transition: padding-inline 0.15s;
2701}
2702
2703.page-ribbon.can-scroll-left {
2704 padding-left: 42px;
2705}
2706
2707.page-ribbon.can-scroll-right {
2708 padding-right: 42px;
2709}
2710
2711.page-ribbon-track {
2712 display: flex;
2713 flex-wrap: nowrap;
2714 gap: 8px;
2715 min-width: 0;
2716 flex: 1;
2717 overflow-x: auto;
2718 overflow-y: hidden;
2719 scrollbar-width: none;
2720 -ms-overflow-style: none;
2721 overscroll-behavior-x: contain;
2722}
2723
2724.page-ribbon-track::-webkit-scrollbar {
2725 display: none;
2726 width: 0;
2727 height: 0;
2728}
2729
2730.page-ribbon-arrow {
2731 position: absolute;
2732 top: 12px;
2733 bottom: 4px;
2734 z-index: 2;
2735 display: inline-flex;
2736 align-items: center;
2737 justify-content: center;
2738 width: 48px;
2739 border: none;
2740 background: transparent;
2741 color: var(--vp-c-text-2);
2742 cursor: pointer;
2743 transition: color 0.15s;
2744}
2745
2746.page-ribbon-arrow:hover {
2747 color: var(--vp-c-text-1);
2748}
2749
2750.page-ribbon-arrow.right {
2751 right: 0;
2752 justify-content: flex-end;
2753 padding-right: 6px;
2754}
2755
2756.page-ribbon-arrow.left {
2757 left: 0;
2758 justify-content: flex-start;
2759 padding-left: 6px;
2760}
2761
2762.page-ribbon-arrow.left svg {
2763 transform: rotate(180deg);
2764}
2765
2766.page-pill {
2767 flex: none;
2768 display: inline-flex;
2769 align-items: center;
2770 gap: 6px;
2771 padding: 6px 10px;
2772 font-size: 0.8rem;
2773 line-height: 1.2;
2774 white-space: nowrap;
2775 border-radius: 8px;
2776 border: 1.5px solid var(--vp-c-divider);
2777 background: var(--vp-c-bg-soft);
2778 color: var(--vp-c-text-2);
2779 cursor: pointer;
2780 transition: color 0.15s, border-color 0.15s, background-color 0.15s;
2781}
2782
2783.page-pill:hover {
2784 color: var(--vp-c-text-1);
2785 border-color: var(--vp-c-brand-1);
2786}
2787
2788.page-pill.active {
2789 color: var(--vp-c-brand-1);
2790 border: 1.5px solid var(--vp-c-brand-1);
2791 background: color-mix(in srgb, var(--vp-c-brand-1) 12%, transparent);
2792 box-shadow: none;
2793}
2794
2795.page-pill-label {
2796 max-width: 180px;
2797 overflow: hidden;
2798 text-overflow: ellipsis;
2799}
2800
2801.page-pill-count {
2802 font-variant-numeric: tabular-nums;
2803 font-size: 0.7rem;
2804 padding: 1px 6px;
2805 border-radius: 4px;
2806 background: rgba(128, 128, 128, 0.15);
2807 color: inherit;
2808}
2809
2810.page-pill.active .page-pill-count {
2811 background: color-mix(in srgb, var(--vp-c-brand-1) 18%, transparent);
2812}
2813
2814@media (max-width: 767px) {
2815 .page-ribbon {
2816 padding: 14px 12px 4px;
2817 }
2818
2819 .page-pill {
2820 padding: 7px 14px;
2821 font-size: 0.82rem;
2822 background: var(--vp-c-bg-elv, var(--vp-c-bg-soft));
2823 border-color: var(--vp-c-divider);
2824 color: var(--vp-c-text-1);
2825 }
2826}
2827
2828.local-search-icon {
2829 display: block;
2830 font-size: 18px;
2831}
2832
2833.navigate-icon {
2834 display: block;
2835 font-size: 14px;
2836}
2837
2838.search-icon {
2839 margin: 8px;
2840}
2841
2842@media (max-width: 767px) {
2843 .search-icon {
2844 display: none;
2845 }
2846}
2847
2848.search-input {
2849 flex: 1 1 auto;
2850 min-width: 0;
2851 padding: 6px 12px;
2852 font-size: inherit;
2853 width: 100%;
2854}
2855
2856.search-input::-webkit-search-cancel-button {
2857 display: none;
2858}
2859
2860@media (max-width: 767px) {
2861 .search-input {
2862 padding: 6px 4px;
2863 }
2864}
2865
2866.search-actions {
2867 flex: 0 0 auto;
2868 display: flex;
2869 align-items: center;
2870 gap: 4px;
2871}
2872
2873.search-loading-button {
2874 display: inline-flex;
2875 align-items: center;
2876 justify-content: center;
2877 padding: 0 !important;
2878 margin-inline-end: 6px;
2879 border: 0;
2880 background: transparent;
2881 cursor: pointer;
2882}
2883
2884.search-loading-bubba {
2885 width: 32px;
2886 height: 28px;
2887 object-fit: contain;
2888 image-rendering: pixelated;
2889 user-select: none;
2890}
2891
2892@media (any-pointer: coarse) {
2893 .search-actions {
2894 gap: 8px;
2895 }
2896}
2897
2898@media (min-width: 769px) {
2899 .search-actions.before {
2900 display: none;
2901 }
2902}
2903
2904.search-actions button {
2905 padding: 8px;
2906}
2907
2908.search-actions button:not([disabled]):hover,
2909.toggle-layout-button.detailed-list {
2910 color: var(--vp-c-brand-1);
2911}
2912
2913.search-actions button.clear-button:disabled {
2914 opacity: 0.37;
2915}
2916
2917.search-keyboard-shortcuts {
2918 font-size: 0.8rem;
2919 opacity: 75%;
2920 display: flex;
2921 flex-wrap: wrap;
2922 gap: 16px;
2923 line-height: 14px;
2924}
2925
2926.search-keyboard-shortcuts span {
2927 display: flex;
2928 align-items: center;
2929 gap: 4px;
2930}
2931
2932@media (max-width: 767px) {
2933 .search-keyboard-shortcuts {
2934 display: none;
2935 }
2936}
2937
2938.search-keyboard-shortcuts kbd {
2939 background: rgba(128, 128, 128, 0.1);
2940 border-radius: 4px;
2941 padding: 3px 6px;
2942 min-width: 24px;
2943 display: inline-block;
2944 text-align: center;
2945 vertical-align: middle;
2946 border: 1px solid rgba(128, 128, 128, 0.15);
2947 box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
2948}
2949
2950.results {
2951 display: flex;
2952 flex-direction: column;
2953 gap: 6px;
2954 flex: 1 1 auto;
2955 min-height: 0 !important;
2956 overflow-x: hidden;
2957 overflow-y: auto;
2958 overscroll-behavior: contain;
2959}
2960
2961.result-layout {
2962 will-change: transform, opacity, height;
2963}
2964
2965.result {
2966 display: flex;
2967 align-items: center;
2968 gap: 8px;
2969 border-radius: 4px;
2970 transition: none;
2971 line-height: 1rem;
2972 border: solid 2px var(--vp-local-search-result-border);
2973 outline: none;
2974}
2975
2976.result > div {
2977 margin: 12px;
2978 width: 100%;
2979 overflow: hidden;
2980}
2981
2982@media (max-width: 767px) {
2983 .result > div {
2984 margin: 8px;
2985 }
2986}
2987
2988.titles {
2989 display: flex;
2990 flex-wrap: wrap;
2991 gap: 4px;
2992 position: relative;
2993 z-index: 1001;
2994 padding: 2px 0;
2995 align-items: center;
2996}
2997
2998.url-result-card {
2999 cursor: pointer;
3000}
3001
3002.url-result-body {
3003 display: flex;
3004 flex-direction: column;
3005 gap: 6px;
3006}
3007
3008.url-path {
3009 display: flex;
3010 align-items: center;
3011 flex-wrap: wrap;
3012 gap: 4px;
3013 color: var(--vp-c-text-3);
3014 font-size: 0.78rem;
3015 line-height: 1.2;
3016}
3017
3018.url-path > svg,
3019.url-path-segment svg {
3020 flex-shrink: 0;
3021 width: 1em;
3022 height: 1em;
3023 margin-top: -1px;
3024 opacity: 0.55;
3025}
3026
3027.url-path > svg {
3028 margin-top: -2px;
3029}
3030
3031.url-path-segment {
3032 display: flex;
3033 align-items: center;
3034 min-width: 0;
3035}
3036
3037.url-path-current {
3038 display: inline-flex;
3039 align-items: center;
3040 color: var(--vp-c-text-2);
3041}
3042
3043.url-path :deep(.icon-tip) {
3044 display: inline-flex;
3045 align-items: center;
3046 line-height: 1;
3047 vertical-align: middle;
3048}
3049
3050.url-path :deep(.icon-tip > span) {
3051 width: 1em;
3052 height: 1em;
3053 min-width: 1em;
3054}
3055
3056.url-link {
3057 align-self: flex-start;
3058 max-width: 100%;
3059 color: var(--vp-c-text-1);
3060 font-size: 0.95rem;
3061 font-weight: 500;
3062 line-height: 1.35;
3063 overflow-wrap: anywhere;
3064 word-break: break-word;
3065}
3066
3067.url-link:hover {
3068 color: var(--vp-c-brand-1);
3069 text-decoration: underline;
3070 text-underline-offset: 2px;
3071}
3072
3073.result.selected .url-link {
3074 color: var(--vp-c-brand-1);
3075}
3076
3077.titles > svg {
3078 flex-shrink: 0;
3079 align-self: center;
3080}
3081
3082.title {
3083 display: flex;
3084 align-items: center;
3085 gap: 4px;
3086}
3087
3088.title.main {
3089 font-weight: 500;
3090}
3091
3092.title-icon {
3093 opacity: 1;
3094 font-weight: 500;
3095}
3096
3097.title svg {
3098 opacity: 0.5;
3099}
3100
3101.result.selected {
3102 --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg);
3103 border-color: var(--vp-local-search-result-selected-border);
3104}
3105
3106.excerpt-wrapper {
3107 position: relative;
3108}
3109
3110.excerpt {
3111 opacity: 50%;
3112 pointer-events: none;
3113 height: 84px;
3114 max-height: 84px;
3115 overflow: hidden;
3116 position: relative;
3117 margin-top: 4px;
3118}
3119
3120.result.selected .excerpt {
3121 opacity: 1;
3122}
3123
3124.excerpt :deep(*) {
3125 font-size: 0.8rem !important;
3126 line-height: 130% !important;
3127}
3128
3129.titles :deep(mark),
3130.excerpt :deep(mark) {
3131 background-color: var(--vp-local-search-highlight-bg);
3132 color: var(--vp-local-search-highlight-text);
3133 border-radius: 2px;
3134 padding: 0 2px;
3135}
3136
3137.excerpt :deep(.vp-code-group) .tabs {
3138 display: none;
3139}
3140
3141.excerpt :deep(.vp-code-group) div[class*="language-"] {
3142 border-radius: 8px !important;
3143}
3144
3145.excerpt > .vp-doc > *:first-child {
3146 margin-top: 6px !important;
3147}
3148
3149.excerpt-gradient-bottom {
3150 position: absolute;
3151 bottom: -1px;
3152 left: 0;
3153 width: 100%;
3154 height: 8px;
3155 background: linear-gradient(transparent, var(--vp-local-search-result-bg));
3156 z-index: 1000;
3157}
3158
3159.excerpt-gradient-top {
3160 position: absolute;
3161 top: -1px;
3162 left: 0;
3163 width: 100%;
3164 height: 8px;
3165 background: linear-gradient(var(--vp-local-search-result-bg), transparent);
3166 z-index: 1000;
3167}
3168
3169.result.selected .titles,
3170.result.selected .title-icon {
3171 color: var(--vp-c-brand-1) !important;
3172}
3173
3174.no-results {
3175 font-size: 0.9rem;
3176 text-align: center;
3177 padding: 12px;
3178}
3179
3180svg {
3181 flex: none;
3182}
3183
3184.exact-match-button.exact-match-active {
3185 color: var(--vp-c-brand-1);
3186 background-color: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent);
3187 border-radius: 4px;
3188}
3189
3190.toolbar-group + .toolbar-group {
3191 margin-left: 6px;
3192}
3193
3194.search-mode-group,
3195.view-group {
3196 display: none;
3197}
3198
3199.mode-btn {
3200 display: flex;
3201 align-items: center;
3202 justify-content: center;
3203 padding: 5px 7px;
3204 color: var(--vp-c-text-2);
3205 background: transparent;
3206 border: none;
3207 cursor: pointer;
3208 transition: color 0.15s, background-color 0.15s;
3209 border-radius: 0;
3210}
3211
3212.mode-btn + .mode-btn {
3213 border-left: 1px solid var(--vp-c-divider);
3214}
3215
3216.mode-btn:hover {
3217 color: var(--vp-c-text-1);
3218 background: var(--vp-c-default-soft);
3219}
3220
3221.mode-btn.mode-active {
3222 color: var(--vp-c-brand-1);
3223 background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent);
3224}
3225
3226:deep(.url-highlight) {
3227 background-color: var(--vp-local-search-highlight-bg);
3228 color: var(--vp-local-search-highlight-text);
3229 border-radius: 2px;
3230 padding: 0 2px;
3231 font-style: normal;
3232}
3233
3234/* Bottom-strip pagination. The <nav> is always rendered (empty when only one
3235 page) but collapses to zero height in that case so the shell's bottom
3236 rounded edge sits flush against the results. */
3237.url-pagination {
3238 display: flex;
3239 align-items: center;
3240 justify-content: center;
3241 flex: 0 0 auto !important;
3242}
3243
3244.url-pagination:has(.url-pagination-segment) {
3245 padding-top: 8px;
3246}
3247
3248.url-pagination-segment {
3249 display: flex;
3250 align-items: center;
3251 border: 1px solid var(--vp-c-divider);
3252 border-radius: 5px;
3253 overflow: hidden;
3254 background: transparent;
3255}
3256
3257.url-page-btn {
3258 display: flex;
3259 align-items: center;
3260 justify-content: center;
3261 min-width: 32px;
3262 height: 28px;
3263 padding: 0 8px;
3264 border: none;
3265 background: transparent;
3266 color: var(--vp-c-text-2);
3267 font-size: 0.82rem;
3268 cursor: pointer;
3269 transition: color 0.15s, background-color 0.15s;
3270 border-radius: 0;
3271}
3272
3273.url-page-btn + .url-page-btn,
3274.url-page-ellipsis + .url-page-btn,
3275.url-page-btn + .url-page-ellipsis {
3276 border-left: 1px solid var(--vp-c-divider);
3277}
3278
3279.url-page-btn:hover:not(:disabled):not(.active) {
3280 color: var(--vp-c-text-1);
3281 background: var(--vp-c-default-soft);
3282}
3283
3284.url-page-btn.active {
3285 color: var(--vp-c-brand-1);
3286 background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent);
3287 font-weight: 500;
3288 cursor: default;
3289}
3290
3291.url-page-btn:disabled {
3292 opacity: 0.25;
3293 cursor: not-allowed;
3294 background: transparent;
3295}
3296
3297.url-page-nav {
3298 padding: 0 6px;
3299}
3300
3301.url-page-ellipsis {
3302 display: flex;
3303 align-items: center;
3304 justify-content: center;
3305 min-width: 28px;
3306 height: 28px;
3307 color: var(--vp-c-text-3);
3308 font-size: 0.8rem;
3309 user-select: none;
3310 background: transparent;
3311}
3312
3313/* Settings toggle button — always visible */
3314.settings-toggle-btn {
3315 display: flex;
3316 border: none;
3317 border-radius: 5px;
3318 color: var(--vp-c-text-1);
3319 padding: 8px;
3320}
3321
3322/* Settings popup card */
3323.search-settings-popup {
3324 position: fixed;
3325 z-index: 200;
3326 background: var(--vp-c-bg);
3327 border: 1px solid var(--vp-c-divider);
3328 border-radius: 10px;
3329 padding: 10px;
3330 box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
3331 display: flex;
3332 flex-direction: column;
3333 min-width: 196px;
3334}
3335
3336.settings-section {
3337 display: flex;
3338 flex-direction: column;
3339 gap: 0;
3340}
3341
3342.settings-section + .settings-section {
3343 border-top: 1px solid var(--vp-c-divider);
3344 margin-top: 8px;
3345 padding-top: 8px;
3346}
3347
3348.settings-section-header {
3349 display: flex;
3350 align-items: center;
3351 justify-content: space-between;
3352 margin-bottom: 6px;
3353}
3354
3355.settings-section-label {
3356 display: flex;
3357 align-items: center;
3358 gap: 6px;
3359 font-size: 14px;
3360 font-weight: 500;
3361 color: var(--vp-c-text-1);
3362}
3363
3364.settings-help-btn {
3365 display: flex;
3366 align-items: center;
3367 justify-content: center;
3368 padding: 3px;
3369 background: transparent;
3370 border: none;
3371 cursor: pointer;
3372 color: var(--vp-c-text-3);
3373 opacity: 0.5;
3374 transition: opacity 0.15s, color 0.15s;
3375 border-radius: 3px;
3376 line-height: 1;
3377}
3378
3379.settings-help-btn:hover,
3380.settings-help-btn.active {
3381 opacity: 1;
3382 color: var(--vp-c-text-1);
3383}
3384
3385.settings-help-icon {
3386 display: block;
3387 width: 14px;
3388 height: 14px;
3389}
3390
3391/* Help popup */
3392.search-help-popup {
3393 position: fixed;
3394 z-index: 9999;
3395 width: 280px;
3396 background: var(--vp-c-bg-elv);
3397 border: 1px solid var(--vp-c-divider);
3398 border-radius: 12px;
3399 padding: 16px;
3400 box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
3401 pointer-events: none;
3402}
3403
3404.help-popup-fade-enter-active,
3405.help-popup-fade-leave-active {
3406 transition: opacity 0.15s ease;
3407}
3408
3409.help-popup-fade-enter-from,
3410.help-popup-fade-leave-to {
3411 opacity: 0;
3412}
3413
3414.sh-title {
3415 display: flex;
3416 align-items: center;
3417 gap: 6px;
3418 font-size: 1rem;
3419 font-weight: 600;
3420 color: var(--vp-c-text-1);
3421 margin: 0 0 4px;
3422}
3423
3424.sh-title-icon {
3425 flex-shrink: 0;
3426 opacity: 0.8;
3427 width: 16px;
3428 height: 16px;
3429}
3430
3431.sh-desc {
3432 font-size: 0.875rem;
3433 color: var(--vp-c-text-2);
3434 margin: 0 0 6px;
3435 line-height: 1.5;
3436}
3437
3438.sh-options {
3439 display: flex;
3440 flex-direction: column;
3441 gap: 5px;
3442}
3443
3444.sh-option {
3445 display: flex;
3446 flex-direction: column;
3447 gap: 4px;
3448 background: var(--vp-c-bg-soft);
3449 border-radius: 12px;
3450 padding: 10px 12px;
3451}
3452
3453.sh-option strong {
3454 display: flex;
3455 align-items: center;
3456 gap: 4px;
3457 font-size: 0.875rem;
3458 font-weight: 600;
3459 color: var(--vp-c-text-1);
3460}
3461
3462.sh-option span {
3463 font-size: 0.875rem;
3464 color: var(--vp-c-text-2);
3465 line-height: 1.4;
3466}
3467
3468.settings-options {
3469 display: flex;
3470 gap: 4px;
3471}
3472
3473.settings-option {
3474 display: flex;
3475 align-items: center;
3476 justify-content: center;
3477 gap: 5px;
3478 padding: 5px 6px;
3479 background: transparent;
3480 border: none;
3481 border-radius: 5px;
3482 cursor: pointer;
3483 color: var(--vp-c-text-2);
3484 font-size: 14px;
3485 font-weight: 500;
3486 transition: background-color 0.15s, color 0.15s;
3487 flex: 1;
3488}
3489
3490.settings-option:hover {
3491 color: var(--vp-c-text-1);
3492 background: var(--vp-c-bg-soft);
3493}
3494
3495.settings-option.active {
3496 color: var(--vp-c-brand-1);
3497 background: var(--vp-c-brand-soft);
3498 font-weight: 600;
3499}
3500
3501.settings-popup-enter-active,
3502.settings-popup-leave-active {
3503 transition: opacity 0.15s ease, transform 0.15s ease;
3504 transform-origin: top right;
3505}
3506
3507.settings-popup-enter-from,
3508.settings-popup-leave-to {
3509 opacity: 0;
3510 transform: scale(0.92) translateY(-4px);
3511}
3512
3513.history-list {
3514 display: flex;
3515 flex-direction: column;
3516 width: 100%;
3517 padding: 4px 0;
3518}
3519
3520.history-header {
3521 font-size: 0.7rem;
3522 font-weight: 600;
3523 text-transform: uppercase;
3524 letter-spacing: 0.06em;
3525 color: var(--vp-c-text-3);
3526 padding: 4px 12px 8px;
3527 display: flex;
3528 align-items: center;
3529 justify-content: space-between;
3530}
3531
3532.history-clear-all {
3533 display: flex;
3534 align-items: center;
3535 justify-content: center;
3536 flex-shrink: 0;
3537 padding: 0;
3538 border: none;
3539 background: transparent;
3540 color: var(--vp-c-text-3);
3541 cursor: pointer;
3542 opacity: 0.7;
3543 transition: color 0.15s;
3544}
3545
3546.history-clear-all:hover {
3547 color: var(--vp-c-text-1);
3548 opacity: 1;
3549}
3550
3551.history-items {
3552 display: flex;
3553 flex-direction: column;
3554 list-style: none;
3555 margin: 0;
3556 padding: 0;
3557}
3558
3559.history-item {
3560 display: flex;
3561 align-items: center;
3562 gap: 8px;
3563 padding: 8px 12px;
3564 cursor: pointer;
3565 border-radius: 4px;
3566 transition: background-color 0.15s;
3567}
3568
3569.history-item:hover {
3570 background: var(--vp-c-default-soft);
3571}
3572
3573.history-main {
3574 flex: 1;
3575 min-width: 0;
3576 display: flex;
3577 align-items: center;
3578 gap: 6px;
3579 overflow: hidden;
3580}
3581
3582.history-query {
3583 flex-shrink: 0;
3584 font-size: 0.9rem;
3585 color: var(--vp-c-text-1);
3586 white-space: nowrap;
3587}
3588
3589.history-arrow {
3590 flex-shrink: 0;
3591 opacity: 0.5;
3592 color: var(--vp-c-text-3);
3593}
3594
3595.history-path-seg {
3596 min-width: 0;
3597 overflow: hidden;
3598 text-overflow: ellipsis;
3599 white-space: nowrap;
3600 font-size: 0.78rem;
3601 font-weight: 500;
3602 color: var(--vp-c-text-3);
3603}
3604
3605.history-path-sep {
3606 flex-shrink: 0;
3607 font-size: 0.78rem;
3608 color: var(--vp-c-text-3);
3609}
3610
3611.history-path-end {
3612 flex-shrink: 0;
3613 white-space: nowrap;
3614 font-size: 0.78rem;
3615 font-weight: 500;
3616 color: var(--vp-c-text-3);
3617}
3618
3619.history-path-only {
3620 flex-shrink: 1;
3621 min-width: 0;
3622 overflow: hidden;
3623 text-overflow: ellipsis;
3624}
3625
3626.history-mode-icon {
3627 flex-shrink: 0;
3628 color: var(--vp-c-text-3);
3629 opacity: 0.7;
3630}
3631
3632.history-remove {
3633 display: flex;
3634 align-items: center;
3635 justify-content: center;
3636 flex-shrink: 0;
3637 padding: 0;
3638 border: none;
3639 background: transparent;
3640 color: var(--vp-c-text-3);
3641 cursor: pointer;
3642 opacity: 0.7;
3643 transition: color 0.15s;
3644}
3645
3646.history-remove:hover {
3647 color: var(--vp-c-text-1);
3648 opacity: 1;
3649}
3650</style>