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