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

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

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