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

1035e8f3ad2a4829161829f320a5e02c4693f05c
wotaku/docs/.vitepress/theme/components/Search.vue

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