docs/.vitepress/theme/components/Search.vue

1ab1d19dff5fdd6756cf7c8bfdfe1d1e144bbc76
wotaku/docs/.vitepress/theme/components/Search.vue history · blame · raw

995 lines · 25535 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    resultsEl.value?.scrollTo(0, 0)
298  },
299  { debounce: 180, immediate: true }
300)
301
302const excerptCache = new LRUCache<string, unknown>(60) // 60 excerpts
303
304async function fetchExcerpt(id: string) {
305  const cache = excerptCache.get(id)
306  if (cache) return { id, mod: cache }
307
308  const file = pathToFile(id.slice(0, id.indexOf('#')))
309  try {
310    if (!file) throw new Error(`Cannot find file for id: ${id}`)
311    const mod = await import(/*@vite-ignore*/ file)
312
313    excerptCache.set(id, mod)
314
315    return { id, mod }
316  } catch (e) {
317    console.error(e)
318    return { id, mod: {} }
319  }
320}
321
322/* Search input focus */
323
324const searchInput = ref<HTMLInputElement>()
325const disableReset = computed(() => {
326  return filterText.value?.length <= 0
327})
328function focusSearchInput(select = true) {
329  searchInput.value?.focus()
330  select && searchInput.value?.select()
331}
332
333onMounted(() => {
334  focusSearchInput()
335})
336
337function onSearchBarClick(event: PointerEvent) {
338  if (event.pointerType === 'mouse') {
339    focusSearchInput()
340  }
341}
342
343/* Search keyboard selection */
344
345const selectedIndex = ref(-1)
346const disableMouseOver = ref(true)
347
348watch(results, (r) => {
349  selectedIndex.value = r.length ? 0 : -1
350  scrollToSelectedResult()
351})
352
353function scrollToSelectedResult() {
354  nextTick(() => {
355    const selectedEl = document.querySelector('.result.selected')
356    selectedEl?.scrollIntoView({ block: 'nearest' })
357  })
358}
359
360onKeyStroke('ArrowUp', (event) => {
361  event.preventDefault()
362  selectedIndex.value--
363  if (selectedIndex.value < 0) {
364    selectedIndex.value = results.value.length - 1
365  }
366  disableMouseOver.value = true
367  scrollToSelectedResult()
368})
369
370onKeyStroke('ArrowDown', (event) => {
371  event.preventDefault()
372  selectedIndex.value++
373  if (selectedIndex.value >= results.value.length + 1) {
374    selectedIndex.value = 0
375  }
376  disableMouseOver.value = true
377  scrollToSelectedResult()
378})
379
380const router = useRouter()
381
382onKeyStroke('Enter', (e) => {
383  if (e.isComposing) return
384
385  if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') {
386    return
387  }
388
389  const index = selectedIndex.value - 1
390
391  if (index === -1) {
392    // @ts-ignore
393    window.toggleAI({ value: filterText.value })
394    showSearch.value = false
395    return
396  }
397
398  const selectedPackage = results.value[index]
399  if (e.target instanceof HTMLInputElement && !selectedPackage) {
400    e.preventDefault()
401    return
402  }
403
404  if (selectedPackage) {
405    router.go(selectedPackage.id)
406    showSearch.value = false
407  }
408})
409
410onKeyStroke('Escape', () => {
411  showSearch.value = false
412})
413
414// Translations
415const defaultTranslations = {
416  modal: {
417    displayDetails: 'Display detailed list',
418    exactMatchTitle: 'Match exact phrases',
419    resetButtonTitle: 'Reset search',
420    backButtonTitle: 'Close search',
421    noResultsText: 'No results for',
422    footer: {
423      selectText: 'to select',
424      selectKeyAriaLabel: 'enter',
425      navigateText: 'to navigate',
426      navigateUpKeyAriaLabel: 'up arrow',
427      navigateDownKeyAriaLabel: 'down arrow',
428      closeText: 'to close',
429      closeKeyAriaLabel: 'escape'
430    }
431  }
432}
433
434const translate = createSearchTranslate(defaultTranslations)
435
436// Back
437
438onMounted(() => {
439  // Prevents going to previous site
440  window.history.pushState(null, '', null)
441})
442
443useEventListener('popstate', (event) => {
444  event.preventDefault()
445  showSearch.value = false
446})
447
448/** Lock body */
449const isLocked = useScrollLock(inBrowser ? document.body : null)
450
451watch(
452  () => showSearch.value,
453  (val) => {
454    if (!val) {
455      isLocked.value = false
456      return
457    }
458
459    nextTick(() => {
460      isLocked.value = true
461      nextTick().then(() => activate())
462    })
463  }
464)
465
466function formMarkRegex(terms: Set<string>) {
467  return new RegExp(
468    [...terms]
469      .sort((a, b) => b.length - a.length)
470      .map((term) => `(${escapeRegExp(term)})`)
471      .join('|'),
472    'gi'
473  )
474}
475
476function resetSearch() {
477  filterText.value = ''
478  nextTick().then(() => focusSearchInput(false))
479}
480
481function onMouseMove(e: MouseEvent) {
482  if (!disableMouseOver.value) return
483  const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result')
484  const index = Number.parseInt(el?.dataset.index!)
485  if (index >= 0 && index !== selectedIndex.value) {
486    selectedIndex.value = index
487  }
488  disableMouseOver.value = false
489}
490</script>
491
492<template>
493  <Teleport to="body">
494    <div ref="el" role="button" :aria-owns="results?.length ? 'localsearch-list' : undefined" aria-expanded="true"
495      aria-haspopup="listbox" aria-labelledby="localsearch-label" class="VPLocalSearchBox"
496      :class="{ 'pointer-events-none': !showSearch }">
497      <AnimatePresence>
498        <motion.div v-if="showSearch" class="backdrop" @click="showSearch = false" :initial="{
499          opacity: 0
500        }" :animate="{
501            opacity: 1
502          }" :exit="{
503            opacity: 0
504          }" :transition="{
505            duration: 0.55,
506            ease: [0.16, 1, 0.3, 1]
507          }" />
508      </AnimatePresence>
509
510      <AnimatePresence>
511        <motion.div v-if="showSearch" layout="size" class="shell" :initial="{
512          opacity: 0,
513          scale: 0.9375
514        }" :animate="{
515            opacity: 1,
516            scale: 1
517          }" :exit="{
518            opacity: 0,
519            scale: 0.9375
520          }" :transition="{
521            duration: 0.55,
522            ease: [0.16, 1, 0.3, 1]
523          }">
524          <motion.form layout="position" class="search-bar" @pointerup="onSearchBarClick($event)" @submit.prevent="">
525            <label :title="buttonText" id="localsearch-label" for="localsearch-input">
526              <span aria-hidden="true" class="vpi-search search-icon local-search-icon" />
527            </label>
528            <div class="search-actions before">
529              <button class="back-button" :title="translate('modal.backButtonTitle')" @click="showSearch = false">
530                <span class="vpi-arrow-left local-search-icon" />
531              </button>
532            </div>
533            <input ref="searchInput" v-model="filterText" :aria-activedescendant="selectedIndex > -1
534                ? 'localsearch-item-' + selectedIndex
535                : undefined
536              " aria-autocomplete="both" :aria-controls="results?.length ? 'localsearch-list' : undefined"
537              aria-labelledby="localsearch-label" autocapitalize="off" autocomplete="off" autocorrect="off"
538              class="search-input" id="localsearch-input" enterkeyhint="go" maxlength="64" :placeholder="buttonText"
539              spellcheck="false" type="search" />
540            <div class="search-actions">
541              <button v-if="!disableDetailedView" class="toggle-layout-button" type="button"
542                :class="{ 'detailed-list': showDetailedList }" :title="translate('modal.displayDetails')" @click="
543                  selectedIndex > -1 && (showDetailedList = !showDetailedList)
544                  ">
545                <TextAlignStart :size="19" stroke-width="1.25" />
546              </button>
547              <button class="exact-match-button" type="button" :class="{ 'exact-match-active': matchExact }"
548                :title="translate('modal.exactMatchTitle')" @click="matchExact = !matchExact">
549                <Regex :size="19" stroke-width="1.25" />
550              </button>
551              <button class="clear-button" type="reset" :disabled="disableReset"
552                :title="translate('modal.resetButtonTitle')" @click="resetSearch">
553                <Delete :size="19" stroke-width="1.25" />
554              </button>
555            </div>
556          </motion.form>
557
558          <ul ref="resultsEl" :id="results?.length ? 'localsearch-list' : undefined"
559            :role="results?.length ? 'listbox' : undefined"
560            :aria-labelledby="results?.length ? 'localsearch-label' : undefined" class="results"
561            @mousemove="onMouseMove">
562            <AnimatePresence>
563              <motion.div
564                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"
565                v-if="!filterText || (filterText && !results.length)" :initial="{
566                  opacity: 0
567                }" :animate="{
568                  opacity: 1,
569                  transition: {
570                    delay: 0.1
571                  }
572                }" :exit="{
573                  opacity: 0,
574                  height: 0,
575                  transition: {
576                    duration: 0.2
577                  }
578                }" :transition="{
579                  duration: 0.7,
580                  ease: [0.16, 1, 0.3, 1]
581                }">
582                <img class="h-40 object-contain object-center -translate-x-2" src="/asset/smolame.png" alt="Smol ame" />
583                <h1 v-if="filterText && !results.length">
584                  Couldn't find anything, try again?
585                </h1>
586                <h1 v-else>Looking for something?</h1>
587              </motion.div>
588            </AnimatePresence>
589
590            <AnimatePresence>
591              <motion.li v-for="(p, index) in results" :key="p.id" layout class="result-layout"
592                :id="'localsearch-item-' + (index + 1)" :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
593                role="option" :initial="{
594                  opacity: 0,
595                  scale: 0.9375
596                }" :animate="{
597                  opacity: 1,
598                  scale: 1
599                }" :exit="{
600                  opacity: 0,
601                  scale: 0.9375,
602                  height: 0,
603                  transition: {
604                    duration: 0.25
605                  }
606                }" :transition="{
607                  duration: 0.55,
608                  ease: [0.16, 1, 0.3, 1],
609                  delay: index * 0.02
610                }">
611                <a :href="p.id" class="result" :class="{
612                  selected: selectedIndex === index + 1
613                }" :aria-label="[...p.titles, p.title].join(' > ')"
614                  @mouseenter="!disableMouseOver && (selectedIndex = index + 1)" @focusin="selectedIndex = index + 1"
615                  @click="showSearch = false" :data-index="index + 1">
616                  <div>
617                    <div class="titles">
618                      <Hash v-if="p.titles.length > 0" stroke-width="1.25" :size="18" />
619                      <File v-else stroke-width="1.25" :size="18" />
620
621                      <span v-for="(t, index) in p.titles" :key="index" class="title">
622                        <span class="text" v-html="t" />
623                        <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
624                      </span>
625                      <span class="title main">
626                        <span class="text" v-html="p.title" />
627                      </span>
628                    </div>
629
630                    <div v-if="showDetailedList" class="excerpt-wrapper">
631                      <motion.div v-if="p.text" layout class="excerpt" inert :initial="{
632                        height: 0
633                      }" :animate="{
634                          height: '84px'
635                        }" :exit="{
636                          height: 0
637                        }" :transition="{
638                          duration: 0.4,
639                          ease: [0.16, 1, 0.3, 1]
640                        }">
641                        <div class="vp-doc" v-html="p.text" />
642                      </motion.div>
643                      <div class="excerpt-gradient-bottom" />
644                      <div class="excerpt-gradient-top" />
645                    </div>
646                  </div>
647                </a>
648              </motion.li>
649            </AnimatePresence>
650          </ul>
651
652          <motion.div layout class="search-keyboard-shortcuts">
653            <span>
654              <kbd :aria-label="translate('modal.footer.navigateUpKeyAriaLabel')">
655                <span class="vpi-arrow-up navigate-icon" />
656              </kbd>
657              <kbd :aria-label="translate('modal.footer.navigateDownKeyAriaLabel')">
658                <span class="vpi-arrow-down navigate-icon" />
659              </kbd>
660              {{ translate('modal.footer.navigateText') }}
661            </span>
662            <span>
663              <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')">
664                <span class="vpi-corner-down-left navigate-icon" />
665              </kbd>
666              {{ translate('modal.footer.selectText') }}
667            </span>
668            <span>
669              <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')">
670                esc
671              </kbd>
672              {{ translate('modal.footer.closeText') }}
673            </span>
674          </motion.div>
675        </motion.div>
676      </AnimatePresence>
677
678      <button v-if="!showSearch" />
679    </div>
680  </Teleport>
681</template>
682
683<style scoped>
684.VPLocalSearchBox {
685  position: fixed;
686  z-index: 100;
687  inset: 0;
688  display: flex;
689}
690
691.backdrop {
692  position: absolute;
693  inset: 0;
694  background: var(--vp-backdrop-bg-color);
695  transition: opacity 0.5s;
696  will-change: opacity;
697}
698
699.shell {
700  position: relative;
701  padding: 12px;
702  margin: 64px auto;
703  display: flex;
704  flex-direction: column;
705  gap: 16px;
706  background: var(--vp-local-search-bg);
707  width: min(100vw - 60px, 900px);
708  height: min-content;
709  max-height: min(100vh - 128px, 900px);
710  border-radius: 6px;
711  will-change: transform, opacity, height;
712}
713
714@media (max-width: 767px) {
715  .shell {
716    margin: 0;
717    width: 100vw;
718    height: 100vh;
719    max-height: none;
720    border-radius: 0;
721  }
722}
723
724.search-bar {
725  border: 1px solid var(--vp-c-divider);
726  border-radius: 4px;
727  display: flex;
728  align-items: center;
729  padding: 0 12px;
730  cursor: text;
731  will-change: height;
732}
733
734@media (max-width: 767px) {
735  .search-bar {
736    padding: 0 8px;
737  }
738}
739
740.search-bar:focus-within {
741  border-color: var(--vp-c-brand-1);
742}
743
744.local-search-icon {
745  display: block;
746  font-size: 18px;
747}
748
749.navigate-icon {
750  display: block;
751  font-size: 14px;
752}
753
754.search-icon {
755  margin: 8px;
756}
757
758@media (max-width: 767px) {
759  .search-icon {
760    display: none;
761  }
762}
763
764.search-input {
765  padding: 6px 12px;
766  font-size: inherit;
767  width: 100%;
768}
769
770.search-input::-webkit-search-cancel-button {
771  display: none;
772}
773
774@media (max-width: 767px) {
775  .search-input {
776    padding: 6px 4px;
777  }
778}
779
780.search-actions {
781  display: flex;
782  gap: 4px;
783}
784
785@media (any-pointer: coarse) {
786  .search-actions {
787    gap: 8px;
788  }
789}
790
791@media (min-width: 769px) {
792  .search-actions.before {
793    display: none;
794  }
795}
796
797.search-actions button {
798  padding: 8px;
799}
800
801.search-actions button:not([disabled]):hover,
802.toggle-layout-button.detailed-list {
803  color: var(--vp-c-brand-1);
804}
805
806.search-actions button.clear-button:disabled {
807  opacity: 0.37;
808}
809
810.search-keyboard-shortcuts {
811  font-size: 0.8rem;
812  opacity: 75%;
813  display: flex;
814  flex-wrap: wrap;
815  gap: 16px;
816  line-height: 14px;
817}
818
819.search-keyboard-shortcuts span {
820  display: flex;
821  align-items: center;
822  gap: 4px;
823}
824
825@media (max-width: 767px) {
826  .search-keyboard-shortcuts {
827    display: none;
828  }
829}
830
831.search-keyboard-shortcuts kbd {
832  background: rgba(128, 128, 128, 0.1);
833  border-radius: 4px;
834  padding: 3px 6px;
835  min-width: 24px;
836  display: inline-block;
837  text-align: center;
838  vertical-align: middle;
839  border: 1px solid rgba(128, 128, 128, 0.15);
840  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
841}
842
843.results {
844  display: flex;
845  flex-direction: column;
846  gap: 6px;
847  overflow-x: hidden;
848  overflow-y: auto;
849  overscroll-behavior: contain;
850}
851
852.result-layout {
853  will-change: transform, opacity, height;
854}
855
856.result {
857  display: flex;
858  align-items: center;
859  gap: 8px;
860  border-radius: 4px;
861  transition: none;
862  line-height: 1rem;
863  border: solid 2px var(--vp-local-search-result-border);
864  outline: none;
865}
866
867.result>div {
868  margin: 12px;
869  width: 100%;
870  overflow: hidden;
871}
872
873@media (max-width: 767px) {
874  .result>div {
875    margin: 8px;
876  }
877}
878
879.titles {
880  display: flex;
881  flex-wrap: wrap;
882  gap: 4px;
883  position: relative;
884  z-index: 1001;
885  padding: 2px 0;
886}
887
888.title {
889  display: flex;
890  align-items: center;
891  gap: 4px;
892}
893
894.title.main {
895  font-weight: 500;
896}
897
898.title-icon {
899  opacity: 1;
900  font-weight: 500;
901}
902
903.title svg {
904  opacity: 0.5;
905}
906
907.result.selected {
908  --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg);
909  border-color: var(--vp-local-search-result-selected-border);
910}
911
912.excerpt-wrapper {
913  position: relative;
914}
915
916.excerpt {
917  opacity: 50%;
918  pointer-events: none;
919  max-height: 84px;
920  overflow: hidden;
921  position: relative;
922  margin-top: 4px;
923  will-change: height;
924}
925
926.result.selected .excerpt {
927  opacity: 1;
928}
929
930.excerpt :deep(*) {
931  font-size: 0.8rem !important;
932  line-height: 130% !important;
933}
934
935.titles :deep(mark),
936.excerpt :deep(mark) {
937  background-color: var(--vp-local-search-highlight-bg);
938  color: var(--vp-local-search-highlight-text);
939  border-radius: 2px;
940  padding: 0 2px;
941}
942
943.excerpt :deep(.vp-code-group) .tabs {
944  display: none;
945}
946
947.excerpt :deep(.vp-code-group) div[class*='language-'] {
948  border-radius: 8px !important;
949}
950
951.excerpt>.vp-doc>*:first-child {
952  margin-top: 6px !important;
953}
954
955.excerpt-gradient-bottom {
956  position: absolute;
957  bottom: -1px;
958  left: 0;
959  width: 100%;
960  height: 8px;
961  background: linear-gradient(transparent, var(--vp-local-search-result-bg));
962  z-index: 1000;
963}
964
965.excerpt-gradient-top {
966  position: absolute;
967  top: -1px;
968  left: 0;
969  width: 100%;
970  height: 8px;
971  background: linear-gradient(var(--vp-local-search-result-bg), transparent);
972  z-index: 1000;
973}
974
975.result.selected .titles,
976.result.selected .title-icon {
977  color: var(--vp-c-brand-1) !important;
978}
979
980.no-results {
981  font-size: 0.9rem;
982  text-align: center;
983  padding: 12px;
984}
985
986svg {
987  flex: none;
988}
989
990.exact-match-button.exact-match-active {
991  color: var(--vp-c-brand-1);
992  background-color: rgba(var(--vp-c-brand-1), 0.1);
993  border-radius: 4px;
994}
995</style>