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

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

3970 lines · 108319 bytes

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