docs/.vitepress/theme/components/Search.vue
1143 lines · 28329 bytes
1<script lang="ts" setup>
2import MiniSearch, { type SearchResult } from 'minisearch'
3import { dataSymbol, 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 onKeyStroke,
25 useEventListener,
26 useLocalStorage,
27 useScrollLock,
28 useSessionStorage,
29 watchDebounced
30} from '@vueuse/core'
31import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
32import { AnimatePresence, motion } from 'motion-v'
33
34// @ts-ignore
35import localSearchIndex from '@localSearchIndex'
36
37import {
38 ArrowRight,
39 Delete,
40 File,
41 Hash,
42 Regex,
43 TextAlignStart
44} from 'lucide-vue-next'
45import Mark from 'mark.js/dist/mark.es6.js'
46import { LRUCache } from '../composables/search/lru-cache'
47import { createSearchTranslate } from '../composables/search/translation'
48import { useData } from '../composables/search/use-data'
49
50export interface FooterTranslations {
51 selectText?: string
52 selectKeyAriaLabel?: string
53 navigateText?: string
54 navigateUpKeyAriaLabel?: string
55 navigateDownKeyAriaLabel?: string
56 closeText?: string
57 closeKeyAriaLabel?: string
58}
59
60export interface ModalTranslations {
61 displayDetails?: string
62 resetButtonTitle?: string
63 backButtonTitle?: string
64 noResultsText?: string
65 footer?: FooterTranslations
66}
67
68const showSearch = defineModel<boolean>()
69
70const el = shallowRef<HTMLElement>()
71const resultsEl = shallowRef<HTMLElement>()
72
73/* Search */
74const searchIndexData = shallowRef(localSearchIndex)
75
76// @ts-ignore
77if (import.meta.hot) {
78 // @ts-ignore
79 import.meta.hot.accept('@localSearchIndex', (m) => {
80 if (m) {
81 searchIndexData.value = m.default
82 }
83 })
84}
85
86interface Result {
87 title: string
88 titles: string[]
89 text?: string
90}
91
92const vitePressData = useData()
93const { activate } = useFocusTrap(el, {
94 immediate: true,
95 allowOutsideClick: true,
96 clickOutsideDeactivates: true,
97 escapeDeactivates: true,
98 returnFocusOnDeactivate: false,
99 initialFocus: () => {
100 return searchInput.value
101 }
102})
103const { localeIndex, theme } = vitePressData
104const searchIndex = computedAsync(async () =>
105 markRaw(
106 MiniSearch.loadJSON<Result>(
107 (await searchIndexData.value[localeIndex.value]?.())?.default,
108 {
109 fields: ['title', 'titles', 'text'],
110 storeFields: ['title', 'titles'],
111 searchOptions: {
112 // Conditional fuzzy search based on matchExact value
113 fuzzy: matchExact.value ? false : 0.07,
114 // Conditional prefix search based on matchExact value
115 prefix: matchExact.value ? false : (term) => term.length > 3,
116 // Disable max fuzzy if match exact is enabled
117 maxFuzzy: matchExact.value ? 0 : 1,
118 boost: { title: 4, text: 2, titles: 1 },
119 ...(theme.value.search?.provider === 'local' &&
120 theme.value.search.options?.miniSearch?.searchOptions)
121 },
122 ...(theme.value.search?.provider === 'local' &&
123 theme.value.search.options?.miniSearch?.options)
124 }
125 )
126 )
127)
128
129const disableQueryPersistence = computed(() => {
130 return (
131 theme.value.search?.provider === 'local' &&
132 theme.value.search.options?.disableQueryPersistence === true
133 )
134})
135
136const filterText = disableQueryPersistence.value
137 ? ref('')
138 : useSessionStorage('vitepress:local-search-filter', '')
139
140const showDetailedList = useLocalStorage(
141 'vitepress:local-search-detailed-list',
142 theme.value.search?.provider === 'local' &&
143 theme.value.search.options?.detailedView === true
144)
145
146const matchExact = useLocalStorage(
147 'vitepress:local-search-match-exact',
148 false // disabled by default
149)
150
151const disableDetailedView = computed(() => {
152 return (
153 theme.value.search?.provider === 'local' &&
154 theme.value.search.options?.detailedView === false
155 )
156})
157
158const buttonText = computed(() => {
159 const options = theme.value.search?.options
160
161 return (
162 options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
163 options?.translations?.button?.buttonText ||
164 'Search'
165 )
166})
167
168watchEffect(() => {
169 if (disableDetailedView.value) {
170 showDetailedList.value = false
171 }
172})
173
174const results: Ref<(SearchResult & Result)[]> = shallowRef([])
175
176const enableNoResults = ref(false)
177
178watch(filterText, () => {
179 enableNoResults.value = false
180})
181
182const mark = computedAsync(async () => {
183 if (!resultsEl.value) return
184 return markRaw(new Mark(resultsEl.value))
185}, null)
186
187const cache = new LRUCache<string, Map<string, string>>(16) // 16 files
188
189watchDebounced(
190 () => [searchIndex.value, filterText.value, showDetailedList.value] as const,
191 async ([index, filterTextValue, showDetailedListValue], old, onCleanup) => {
192 if (old?.[0] !== index) {
193 // in case of hmr
194 cache.clear()
195 }
196
197 let canceled = false
198 onCleanup(() => {
199 canceled = true
200 })
201
202 if (!index) return
203
204 // Search
205 const _result = index
206 .search(filterTextValue)
207 .slice(0, 16) as (SearchResult & Result)[]
208 enableNoResults.value = true
209
210 if (!_result) {
211 results.value = []
212 return
213 }
214
215 // Highlighting
216 const mods = showDetailedListValue
217 ? await Promise.all(results.value.map((r) => fetchExcerpt(r.id)))
218 : []
219 if (canceled) return
220 for (const { id, mod } of mods) {
221 const mapId = id.slice(0, id.indexOf('#'))
222 let map = cache.get(mapId)
223 if (map) continue
224 map = new Map()
225 cache.set(mapId, map)
226 const comp = mod.default ?? mod
227 if (comp?.render || comp?.setup) {
228 const app = createApp(comp)
229 // Silence warnings about missing components
230 app.config.warnHandler = () => {}
231 app.provide(dataSymbol, vitePressData)
232 Object.defineProperties(app.config.globalProperties, {
233 $frontmatter: {
234 get() {
235 return vitePressData.frontmatter.value
236 }
237 },
238 $params: {
239 get() {
240 return vitePressData.page.value.params
241 }
242 }
243 })
244 const div = document.createElement('div')
245 app.mount(div)
246 const headings = div.querySelectorAll('h1, h2, h3, h4, h5, h6')
247 headings.forEach((el) => {
248 const href = el.querySelector('a')?.getAttribute('href')
249 const anchor = href?.startsWith('#') && href.slice(1)
250 if (!anchor) return
251 let html = ''
252 while (
253 (el = el.nextElementSibling!) &&
254 !/^h[1-6]$/i.test(el.tagName)
255 ) {
256 html += el.outerHTML
257 }
258 map!.set(anchor, html)
259 })
260 app.unmount()
261 }
262 if (canceled) return
263 }
264
265 const terms = new Set<string>()
266
267 results.value = _result.map((r) => {
268 const [id, anchor] = r.id.split('#')
269 const map = cache.get(id)
270 const text = map?.get(anchor) ?? ''
271 for (const term in r.match) {
272 terms.add(term)
273 }
274 return { ...r, text }
275 })
276
277 await nextTick()
278 if (canceled) return
279
280 await new Promise((r) => {
281 mark.value?.unmark({
282 done: () => {
283 mark.value?.markRegExp(formMarkRegex(terms), { done: r })
284 }
285 })
286 })
287
288 const excerpts = el.value?.querySelectorAll('.result .excerpt') ?? []
289 const scrollMutations: { element: HTMLElement; scrollTop: number }[] = []
290 for (let i = 0; i < excerpts.length; i++) {
291 const excerptElement = excerpts[i] as HTMLElement
292
293 const markNode = excerptElement.querySelector('mark[data-markjs="true"]') as HTMLElement | null
294 if (markNode) {
295 const markRect = markNode.getBoundingClientRect()
296 const excerptRect = excerptElement.getBoundingClientRect()
297
298 const relativeTop = (markRect.top - excerptRect.top) + excerptElement.scrollTop
299 const targetScrollTop = relativeTop - (excerptElement.clientHeight / 2) + (markRect.height / 2)
300
301 scrollMutations.push({
302 element: excerptElement,
303 scrollTop: targetScrollTop
304 })
305 }
306 }
307 for (let i = 0; i < scrollMutations.length; i++) {
308 scrollMutations[i].element.scrollTop = scrollMutations[i].scrollTop
309 }
310 if (resultsEl.value) {
311 resultsEl.value.scrollTop = 0
312 }
313 },
314 { debounce: 180, immediate: true }
315)
316
317const excerptCache = new LRUCache<string, unknown>(60) // 60 excerpts
318
319async function fetchExcerpt(id: string) {
320 const cache = excerptCache.get(id)
321 if (cache) return { id, mod: cache }
322
323 const file = pathToFile(id.slice(0, id.indexOf('#')))
324 try {
325 if (!file) throw new Error(`Cannot find file for id: ${id}`)
326 const mod = await import(/*@vite-ignore*/ file)
327
328 excerptCache.set(id, mod)
329
330 return { id, mod }
331 } catch (e) {
332 console.error(e)
333 return { id, mod: {} }
334 }
335}
336
337/* Search input focus */
338
339const searchInput = ref<HTMLInputElement>()
340const disableReset = computed(() => {
341 return filterText.value?.length <= 0
342})
343function focusSearchInput(select = true) {
344 searchInput.value?.focus()
345 select && searchInput.value?.select()
346}
347
348onMounted(() => {
349 focusSearchInput()
350})
351
352function onSearchBarClick(event: PointerEvent) {
353 if (event.pointerType === 'mouse') {
354 focusSearchInput()
355 }
356}
357
358/* Search keyboard selection */
359
360const selectedIndex = ref(-1)
361const disableMouseOver = ref(true)
362
363watch(results, (r) => {
364 selectedIndex.value = r.length ? 0 : -1
365 scrollToSelectedResult()
366})
367
368function scrollToSelectedResult() {
369 nextTick(() => {
370 const selectedEl = document.querySelector('.result.selected')
371 selectedEl?.scrollIntoView({ block: 'nearest' })
372 })
373}
374
375onKeyStroke('ArrowUp', (event) => {
376 event.preventDefault()
377 selectedIndex.value--
378 if (selectedIndex.value < 0) {
379 selectedIndex.value = results.value.length - 1
380 }
381 disableMouseOver.value = true
382 scrollToSelectedResult()
383})
384
385onKeyStroke('ArrowDown', (event) => {
386 event.preventDefault()
387 selectedIndex.value++
388 if (selectedIndex.value >= results.value.length + 1) {
389 selectedIndex.value = 0
390 }
391 disableMouseOver.value = true
392 scrollToSelectedResult()
393})
394
395const router = useRouter()
396
397onKeyStroke('Enter', (e) => {
398 if (e.isComposing) return
399
400 if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') {
401 return
402 }
403
404 const index = selectedIndex.value - 1
405
406 if (index === -1) {
407 // @ts-ignore
408 window.toggleAI({ value: filterText.value })
409 showSearch.value = false
410 return
411 }
412
413 const selectedPackage = results.value[index]
414 if (e.target instanceof HTMLInputElement && !selectedPackage) {
415 e.preventDefault()
416 return
417 }
418
419 if (selectedPackage) {
420 window.dispatchEvent(new CustomEvent('search-nav'))
421 router.go(selectedPackage.id)
422 showSearch.value = false
423 }
424})
425
426function onResultClick() {
427 window.dispatchEvent(new CustomEvent('search-nav'))
428 showSearch.value = false
429}
430
431onKeyStroke('Escape', () => {
432 showSearch.value = false
433})
434
435// Translations
436const defaultTranslations = {
437 modal: {
438 displayDetails: 'Display detailed list',
439 exactMatchTitle: 'Match exact phrases',
440 resetButtonTitle: 'Reset search',
441 backButtonTitle: 'Close search',
442 noResultsText: 'No results for',
443 footer: {
444 selectText: 'to select',
445 selectKeyAriaLabel: 'enter',
446 navigateText: 'to navigate',
447 navigateUpKeyAriaLabel: 'up arrow',
448 navigateDownKeyAriaLabel: 'down arrow',
449 closeText: 'to close',
450 closeKeyAriaLabel: 'escape'
451 }
452 }
453}
454
455const translate = createSearchTranslate(defaultTranslations)
456
457// Back
458
459onMounted(() => {
460 // Prevents going to previous site
461 window.history.pushState(null, '', null)
462})
463
464useEventListener('popstate', (event) => {
465 event.preventDefault()
466 showSearch.value = false
467})
468
469/** Lock body */
470const isLocked = useScrollLock(inBrowser ? document.body : null)
471
472watch(
473 () => showSearch.value,
474 (val) => {
475 if (!val) {
476 isLocked.value = false
477 return
478 }
479
480 nextTick(() => {
481 isLocked.value = true
482 nextTick().then(() => activate())
483 })
484 }
485)
486
487function formMarkRegex(terms: Set<string>) {
488 return new RegExp(
489 [...terms]
490 .sort((a, b) => b.length - a.length)
491 .map((term) => `(${escapeRegExp(term)})`)
492 .join('|'),
493 'gi'
494 )
495}
496
497function resetSearch() {
498 filterText.value = ''
499 nextTick().then(() => focusSearchInput(false))
500}
501
502function onMouseMove(e: MouseEvent) {
503 if (!disableMouseOver.value) return
504 const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result')
505 const index = Number.parseInt(el?.dataset.index!)
506 if (index >= 0 && index !== selectedIndex.value) {
507 selectedIndex.value = index
508 }
509 disableMouseOver.value = false
510}
511</script>
512
513<template>
514 <Teleport to="body">
515 <div
516 ref="el"
517 role="button"
518 :aria-owns="results?.length ? 'localsearch-list' : undefined"
519 aria-expanded="true"
520 aria-haspopup="listbox"
521 aria-labelledby="localsearch-label"
522 class="VPLocalSearchBox"
523 :class="{ 'pointer-events-none': !showSearch }"
524 >
525 <AnimatePresence>
526 <motion.div
527 v-if="showSearch"
528 class="backdrop"
529 @click="showSearch = false"
530 :initial="{
531 opacity: 0
532 }"
533 :animate="{
534 opacity: 1
535 }"
536 :exit="{
537 opacity: 0
538 }"
539 :transition="{
540 duration: 0.55,
541 ease: [0.16, 1, 0.3, 1]
542 }"
543 />
544 </AnimatePresence>
545
546 <AnimatePresence>
547 <motion.div
548 v-if="showSearch"
549 layout="size"
550 class="shell"
551 :initial="{
552 opacity: 0,
553 scale: 0.9375
554 }"
555 :animate="{
556 opacity: 1,
557 scale: 1
558 }"
559 :exit="{
560 opacity: 0,
561 scale: 0.9375
562 }"
563 :transition="{
564 duration: 0.55,
565 ease: [0.16, 1, 0.3, 1]
566 }"
567 >
568 <motion.form
569 layout="position"
570 class="search-bar"
571 @pointerup="onSearchBarClick($event)"
572 @submit.prevent=""
573 >
574 <label
575 :title="buttonText"
576 id="localsearch-label"
577 for="localsearch-input"
578 >
579 <span
580 aria-hidden="true"
581 class="vpi-search search-icon local-search-icon"
582 />
583 </label>
584 <div class="search-actions before">
585 <button
586 class="back-button"
587 :title="translate('modal.backButtonTitle')"
588 @click="showSearch = false"
589 >
590 <span class="vpi-arrow-left local-search-icon" />
591 </button>
592 </div>
593 <input
594 ref="searchInput"
595 v-model="filterText"
596 :aria-activedescendant="selectedIndex > -1
597 ? 'localsearch-item-' + selectedIndex
598 : undefined"
599 aria-autocomplete="both"
600 :aria-controls="results?.length ? 'localsearch-list' : undefined"
601 aria-labelledby="localsearch-label"
602 autocapitalize="off"
603 autocomplete="off"
604 autocorrect="off"
605 class="search-input"
606 id="localsearch-input"
607 enterkeyhint="go"
608 maxlength="64"
609 :placeholder="buttonText"
610 spellcheck="false"
611 type="search"
612 />
613 <div class="search-actions">
614 <button
615 v-if="!disableDetailedView"
616 class="toggle-layout-button"
617 type="button"
618 :class="{ 'detailed-list': showDetailedList }"
619 :title="translate('modal.displayDetails')"
620 @click="selectedIndex > -1 &&
621 (showDetailedList = !showDetailedList)"
622 >
623 <TextAlignStart :size="19" stroke-width="1.25" />
624 </button>
625 <button
626 class="exact-match-button"
627 type="button"
628 :class="{ 'exact-match-active': matchExact }"
629 :title="translate('modal.exactMatchTitle')"
630 @click="matchExact = !matchExact"
631 >
632 <Regex :size="19" stroke-width="1.25" />
633 </button>
634 <button
635 class="clear-button"
636 type="reset"
637 :disabled="disableReset"
638 :title="translate('modal.resetButtonTitle')"
639 @click="resetSearch"
640 >
641 <Delete :size="19" stroke-width="1.25" />
642 </button>
643 </div>
644 </motion.form>
645
646 <ul
647 ref="resultsEl"
648 :id="results?.length ? 'localsearch-list' : undefined"
649 :role="results?.length ? 'listbox' : undefined"
650 :aria-labelledby="results?.length ? 'localsearch-label' : undefined"
651 class="results"
652 @mousemove="onMouseMove"
653 >
654 <AnimatePresence>
655 <motion.div
656 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
657 v-if="!filterText || (filterText && !results.length)"
658 :initial="{
659 opacity: 0
660 }"
661 :animate="{
662 opacity: 1,
663 transition: {
664 delay: 0.1
665 }
666 }"
667 :exit="{
668 opacity: 0,
669 height: 0,
670 transition: {
671 duration: 0.2
672 }
673 }"
674 :transition="{
675 duration: 0.7,
676 ease: [0.16, 1, 0.3, 1]
677 }"
678 >
679 <img
680 class="h-40 object-contain object-center -translate-x-2"
681 src="/asset/smolame.png"
682 alt="Smol ame"
683 />
684 <h1 v-if="filterText && !results.length">
685 Couldn't find anything, try again?
686 </h1>
687 <h1 v-else>Looking for something?</h1>
688 </motion.div>
689 </AnimatePresence>
690
691 <AnimatePresence>
692 <motion.li
693 v-for="(p, index) in results"
694 :key="p.id"
695 layout
696 class="result-layout"
697 :id="'localsearch-item-' + (index + 1)"
698 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
699 role="option"
700 :initial="{
701 opacity: 0,
702 scale: 0.9375
703 }"
704 :animate="{
705 opacity: 1,
706 scale: 1
707 }"
708 :exit="{
709 opacity: 0,
710 scale: 0.9375,
711 height: 0,
712 transition: {
713 duration: 0.25
714 }
715 }"
716 :transition="{
717 duration: 0.55,
718 ease: [0.16, 1, 0.3, 1],
719 delay: index * 0.02
720 }"
721 >
722 <a
723 :href="p.id"
724 class="result"
725 :class="{
726 selected: selectedIndex === index + 1
727 }"
728 :aria-label="[...p.titles, p.title].join(' > ')"
729 @mouseenter="!disableMouseOver &&
730 (selectedIndex = index + 1)"
731 @focusin="selectedIndex = index + 1"
732 @click="onResultClick"
733 :data-index="index + 1"
734 >
735 <div>
736 <div class="titles">
737 <Hash
738 v-if="p.titles.length > 0"
739 stroke-width="1.25"
740 :size="18"
741 />
742 <File v-else stroke-width="1.25" :size="18" />
743
744 <span
745 v-for="(t, index) in p.titles"
746 :key="index"
747 class="title"
748 >
749 <span class="text" v-html="t" />
750 <ArrowRight
751 stroke-width="1.25"
752 :size="18"
753 class="mx-0.5"
754 />
755 </span>
756 <span class="title main">
757 <span class="text" v-html="p.title" />
758 </span>
759 </div>
760
761 <div v-if="showDetailedList" class="excerpt-wrapper">
762 <motion.div
763 v-if="p.text"
764 layout
765 class="excerpt"
766 inert
767 :initial="{
768 height: 0
769 }"
770 :animate="{
771 height: '84px'
772 }"
773 :exit="{
774 height: 0
775 }"
776 :transition="{
777 duration: 0.4,
778 ease: [0.16, 1, 0.3, 1]
779 }"
780 >
781 <div class="vp-doc" v-html="p.text" />
782 </motion.div>
783 <div class="excerpt-gradient-bottom" />
784 <div class="excerpt-gradient-top" />
785 </div>
786 </div>
787 </a>
788 </motion.li>
789 </AnimatePresence>
790 </ul>
791
792 <motion.div layout class="search-keyboard-shortcuts">
793 <span>
794 <kbd
795 :aria-label="translate(
796 'modal.footer.navigateUpKeyAriaLabel'
797 )"
798 >
799 <span class="vpi-arrow-up navigate-icon" />
800 </kbd>
801 <kbd
802 :aria-label="translate(
803 'modal.footer.navigateDownKeyAriaLabel'
804 )"
805 >
806 <span class="vpi-arrow-down navigate-icon" />
807 </kbd>
808 {{ translate('modal.footer.navigateText') }}
809 </span>
810 <span>
811 <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')">
812 <span class="vpi-corner-down-left navigate-icon" />
813 </kbd>
814 {{ translate('modal.footer.selectText') }}
815 </span>
816 <span>
817 <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')">
818 esc
819 </kbd>
820 {{ translate('modal.footer.closeText') }}
821 </span>
822 </motion.div>
823 </motion.div>
824 </AnimatePresence>
825
826 <button v-if="!showSearch" />
827 </div>
828 </Teleport>
829</template>
830
831<style scoped>
832.VPLocalSearchBox {
833 position: fixed;
834 z-index: 100;
835 inset: 0;
836 display: flex;
837}
838
839.backdrop {
840 position: absolute;
841 inset: 0;
842 background: var(--vp-backdrop-bg-color);
843 transition: opacity 0.5s;
844 will-change: opacity;
845}
846
847.shell {
848 position: relative;
849 padding: 12px;
850 margin: 64px auto;
851 display: flex;
852 flex-direction: column;
853 gap: 16px;
854 background: var(--vp-local-search-bg);
855 width: min(100vw - 60px, 900px);
856 height: min-content;
857 max-height: min(100vh - 128px, 900px);
858 border-radius: 6px;
859 will-change: transform, opacity, height;
860}
861
862@media (max-width: 767px) {
863 .shell {
864 margin: 0;
865 width: 100vw;
866 height: 100vh;
867 max-height: none;
868 border-radius: 0;
869 }
870}
871
872.search-bar {
873 border: 1px solid var(--vp-c-divider);
874 border-radius: 4px;
875 display: flex;
876 align-items: center;
877 padding: 0 12px;
878 cursor: text;
879 will-change: height;
880}
881
882@media (max-width: 767px) {
883 .search-bar {
884 padding: 0 8px;
885 }
886}
887
888.search-bar:focus-within {
889 border-color: var(--vp-c-brand-1);
890}
891
892.local-search-icon {
893 display: block;
894 font-size: 18px;
895}
896
897.navigate-icon {
898 display: block;
899 font-size: 14px;
900}
901
902.search-icon {
903 margin: 8px;
904}
905
906@media (max-width: 767px) {
907 .search-icon {
908 display: none;
909 }
910}
911
912.search-input {
913 padding: 6px 12px;
914 font-size: inherit;
915 width: 100%;
916}
917
918.search-input::-webkit-search-cancel-button {
919 display: none;
920}
921
922@media (max-width: 767px) {
923 .search-input {
924 padding: 6px 4px;
925 }
926}
927
928.search-actions {
929 display: flex;
930 gap: 4px;
931}
932
933@media (any-pointer: coarse) {
934 .search-actions {
935 gap: 8px;
936 }
937}
938
939@media (min-width: 769px) {
940 .search-actions.before {
941 display: none;
942 }
943}
944
945.search-actions button {
946 padding: 8px;
947}
948
949.search-actions button:not([disabled]):hover,
950.toggle-layout-button.detailed-list {
951 color: var(--vp-c-brand-1);
952}
953
954.search-actions button.clear-button:disabled {
955 opacity: 0.37;
956}
957
958.search-keyboard-shortcuts {
959 font-size: 0.8rem;
960 opacity: 75%;
961 display: flex;
962 flex-wrap: wrap;
963 gap: 16px;
964 line-height: 14px;
965}
966
967.search-keyboard-shortcuts span {
968 display: flex;
969 align-items: center;
970 gap: 4px;
971}
972
973@media (max-width: 767px) {
974 .search-keyboard-shortcuts {
975 display: none;
976 }
977}
978
979.search-keyboard-shortcuts kbd {
980 background: rgba(128, 128, 128, 0.1);
981 border-radius: 4px;
982 padding: 3px 6px;
983 min-width: 24px;
984 display: inline-block;
985 text-align: center;
986 vertical-align: middle;
987 border: 1px solid rgba(128, 128, 128, 0.15);
988 box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
989}
990
991.results {
992 display: flex;
993 flex-direction: column;
994 gap: 6px;
995 overflow-x: hidden;
996 overflow-y: auto;
997 overscroll-behavior: contain;
998}
999
1000.result-layout {
1001 will-change: transform, opacity, height;
1002}
1003
1004.result {
1005 display: flex;
1006 align-items: center;
1007 gap: 8px;
1008 border-radius: 4px;
1009 transition: none;
1010 line-height: 1rem;
1011 border: solid 2px var(--vp-local-search-result-border);
1012 outline: none;
1013}
1014
1015.result > div {
1016 margin: 12px;
1017 width: 100%;
1018 overflow: hidden;
1019}
1020
1021@media (max-width: 767px) {
1022 .result > div {
1023 margin: 8px;
1024 }
1025}
1026
1027.titles {
1028 display: flex;
1029 flex-wrap: wrap;
1030 gap: 4px;
1031 position: relative;
1032 z-index: 1001;
1033 padding: 2px 0;
1034}
1035
1036.title {
1037 display: flex;
1038 align-items: center;
1039 gap: 4px;
1040}
1041
1042.title.main {
1043 font-weight: 500;
1044}
1045
1046.title-icon {
1047 opacity: 1;
1048 font-weight: 500;
1049}
1050
1051.title svg {
1052 opacity: 0.5;
1053}
1054
1055.result.selected {
1056 --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg);
1057 border-color: var(--vp-local-search-result-selected-border);
1058}
1059
1060.excerpt-wrapper {
1061 position: relative;
1062}
1063
1064.excerpt {
1065 opacity: 50%;
1066 pointer-events: none;
1067 max-height: 84px;
1068 overflow: hidden;
1069 position: relative;
1070 margin-top: 4px;
1071 will-change: height;
1072}
1073
1074.result.selected .excerpt {
1075 opacity: 1;
1076}
1077
1078.excerpt :deep(*) {
1079 font-size: 0.8rem !important;
1080 line-height: 130% !important;
1081}
1082
1083.titles :deep(mark),
1084.excerpt :deep(mark) {
1085 background-color: var(--vp-local-search-highlight-bg);
1086 color: var(--vp-local-search-highlight-text);
1087 border-radius: 2px;
1088 padding: 0 2px;
1089}
1090
1091.excerpt :deep(.vp-code-group) .tabs {
1092 display: none;
1093}
1094
1095.excerpt :deep(.vp-code-group) div[class*="language-"] {
1096 border-radius: 8px !important;
1097}
1098
1099.excerpt > .vp-doc > *:first-child {
1100 margin-top: 6px !important;
1101}
1102
1103.excerpt-gradient-bottom {
1104 position: absolute;
1105 bottom: -1px;
1106 left: 0;
1107 width: 100%;
1108 height: 8px;
1109 background: linear-gradient(transparent, var(--vp-local-search-result-bg));
1110 z-index: 1000;
1111}
1112
1113.excerpt-gradient-top {
1114 position: absolute;
1115 top: -1px;
1116 left: 0;
1117 width: 100%;
1118 height: 8px;
1119 background: linear-gradient(var(--vp-local-search-result-bg), transparent);
1120 z-index: 1000;
1121}
1122
1123.result.selected .titles,
1124.result.selected .title-icon {
1125 color: var(--vp-c-brand-1) !important;
1126}
1127
1128.no-results {
1129 font-size: 0.9rem;
1130 text-align: center;
1131 padding: 12px;
1132}
1133
1134svg {
1135 flex: none;
1136}
1137
1138.exact-match-button.exact-match-active {
1139 color: var(--vp-c-brand-1);
1140 background-color: rgba(var(--vp-c-brand-1), 0.1);
1141 border-radius: 4px;
1142}
1143</style>