Commit b7af4889c5
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/NavBarSearch.vue +1 −1
| @@ -5,7 +5,7 @@ import { defineAsyncComponent, onMounted, onUnmounted } from 'vue' | |||
| 5 | import { searchOpen as showSearch } from '../searchState' | 5 | import { searchOpen as showSearch } from '../searchState' |
| 6 | import VPNavBarSearchButton from './NavBarSearchButton.vue' | 6 | import VPNavBarSearchButton from './NavBarSearchButton.vue' |
| 7 | 7 | ||
| 8 | const VPLocalSearchBox = defineAsyncComponent(() => import('./Search.vue')) | 8 | const VPLocalSearchBox = defineAsyncComponent(() => import('./search/Search.vue')) |
| 9 | 9 | ||
| 10 | onMounted(() => { | 10 | onMounted(() => { |
| 11 | const handleSearchHotKey = (event: KeyboardEvent) => { | 11 | const handleSearchHotKey = (event: KeyboardEvent) => { |
docs/.vitepress/theme/components/Search.vue deleted −4035
| @@ -1,4035 +0,0 @@ | |||
| 1 | <script lang="ts" setup> | ||
| 2 | import type { SearchResult } from 'minisearch' | ||
| 3 | import { dataSymbol, type DefaultTheme, inBrowser, useRouter } from 'vitepress' | ||
| 4 | import { | ||
| 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 | ||
| 18 | import { pathToFile } from 'vitepress/dist/client/app/utils' | ||
| 19 | // @ts-ignore | ||
| 20 | import { escapeRegExp } from 'vitepress/dist/client/shared' | ||
| 21 | |||
| 22 | import { | ||
| 23 | computedAsync, | ||
| 24 | onClickOutside, | ||
| 25 | onKeyStroke, | ||
| 26 | useElementBounding, | ||
| 27 | useEventListener, | ||
| 28 | useScrollLock, | ||
| 29 | useSessionStorage, | ||
| 30 | watchDebounced | ||
| 31 | } from '@vueuse/core' | ||
| 32 | import { useFocusTrap } from '@vueuse/integrations/useFocusTrap' | ||
| 33 | import { AnimatePresence, motion } from 'motion-v' | ||
| 34 | |||
| 35 | // @ts-ignore | ||
| 36 | import localSearchIndex from '@localSearchIndex' | ||
| 37 | |||
| 38 | import { | ||
| 39 | ArrowLeft, | ||
| 40 | ArrowLeftToLine, | ||
| 41 | ArrowRight, | ||
| 42 | ArrowRightToLine, | ||
| 43 | ChevronRight, | ||
| 44 | Clock, | ||
| 45 | File, | ||
| 46 | Globe, | ||
| 47 | Highlighter, | ||
| 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' | ||
| 59 | import Mark from 'mark.js/dist/mark.es6.js' | ||
| 60 | import { sidebar } from '../../configs/constants' | ||
| 61 | import type { PageLink } from '../../plugins/urlSearchPlugin' | ||
| 62 | import { LRUCache } from '../composables/search/lru-cache' | ||
| 63 | import { createSearchTranslate } from '../composables/search/translation' | ||
| 64 | import { useData } from '../composables/search/use-data' | ||
| 65 | import { useEffects } from '../composables/useEffects' | ||
| 66 | import { applyFavicons, useFavicons } from '../composables/useFavicons' | ||
| 67 | import { registerGlobalComponents } from '../globalComponents' | ||
| 68 | import { | ||
| 69 | excerptPreload, | ||
| 70 | saveHistoryEnabled, | ||
| 71 | searchHistory, | ||
| 72 | searchMode, | ||
| 73 | searchResultHighlightMode, | ||
| 74 | showDetailedList, | ||
| 75 | type SearchHistoryEntry, | ||
| 76 | type SearchSortMode | ||
| 77 | } from '../searchState' | ||
| 78 | import { enhanceAppWithTabs } from './tabs' | ||
| 79 | |||
| 80 | export interface FooterTranslations { | ||
| 81 | selectText?: string | ||
| 82 | selectKeyAriaLabel?: string | ||
| 83 | navigateText?: string | ||
| 84 | navigateUpKeyAriaLabel?: string | ||
| 85 | navigateDownKeyAriaLabel?: string | ||
| 86 | switchTabsText?: string | ||
| 87 | switchTabsKeyAriaLabel?: string | ||
| 88 | switchPagesText?: string | ||
| 89 | switchPagesKeyAriaLabel?: string | ||
| 90 | closeText?: string | ||
| 91 | closeKeyAriaLabel?: string | ||
| 92 | } | ||
| 93 | |||
| 94 | export interface ModalTranslations { | ||
| 95 | displayDetails?: string | ||
| 96 | resetButtonTitle?: string | ||
| 97 | backButtonTitle?: string | ||
| 98 | noResultsText?: string | ||
| 99 | footer?: FooterTranslations | ||
| 100 | } | ||
| 101 | |||
| 102 | const showSearch = defineModel<boolean>() | ||
| 103 | |||
| 104 | const el = shallowRef<HTMLElement>() | ||
| 105 | const resultsEl = shallowRef<HTMLElement>() | ||
| 106 | |||
| 107 | /* Search */ | ||
| 108 | interface Result { | ||
| 109 | tabs?: string[] | ||
| 110 | title: string | ||
| 111 | titles: string[] | ||
| 112 | text?: string | ||
| 113 | } | ||
| 114 | |||
| 115 | const searchIndexData = shallowRef(localSearchIndex) | ||
| 116 | const searchIndexVersion = ref(0) | ||
| 117 | |||
| 118 | // @ts-ignore | ||
| 119 | if (import.meta.hot) { | ||
| 120 | // @ts-ignore | ||
| 121 | import.meta.hot.accept('@localSearchIndex', (m) => { | ||
| 122 | if (m) { | ||
| 123 | searchIndexData.value = m.default | ||
| 124 | searchIndexVersion.value++ | ||
| 125 | } | ||
| 126 | }) | ||
| 127 | } | ||
| 128 | |||
| 129 | const vitePressData = useData() | ||
| 130 | const { activate } = useFocusTrap(el, { | ||
| 131 | immediate: true, | ||
| 132 | allowOutsideClick: true, | ||
| 133 | clickOutsideDeactivates: true, | ||
| 134 | escapeDeactivates: true, | ||
| 135 | returnFocusOnDeactivate: false, | ||
| 136 | initialFocus: () => { | ||
| 137 | return searchInput.value | ||
| 138 | } | ||
| 139 | }) | ||
| 140 | const { localeIndex, theme } = vitePressData | ||
| 141 | |||
| 142 | const disableQueryPersistence = computed(() => { | ||
| 143 | return ( | ||
| 144 | theme.value.search?.provider === 'local' && | ||
| 145 | theme.value.search.options?.disableQueryPersistence === true | ||
| 146 | ) | ||
| 147 | }) | ||
| 148 | |||
| 149 | const filterText = disableQueryPersistence.value | ||
| 150 | ? ref('') | ||
| 151 | : useSessionStorage('vitepress:local-search-filter', '') | ||
| 152 | |||
| 153 | const { effectsEnabled: searchAnimationsEnabled } = useEffects() | ||
| 154 | const { faviconsEnabled } = useFavicons() | ||
| 155 | const showKeyboardShortcuts = computed(() => !filterText.value) | ||
| 156 | |||
| 157 | const SearchMotionDiv = motion.div | ||
| 158 | const SearchMotionForm = motion.form | ||
| 159 | const SearchMotionLi = motion.li | ||
| 160 | const searchMotionDiv = computed(() => | ||
| 161 | searchAnimationsEnabled.value ? SearchMotionDiv : 'div' | ||
| 162 | ) | ||
| 163 | const searchMotionForm = computed(() => | ||
| 164 | searchAnimationsEnabled.value ? SearchMotionForm : 'form' | ||
| 165 | ) | ||
| 166 | const searchMotionLi = computed(() => | ||
| 167 | searchAnimationsEnabled.value ? SearchMotionLi : 'li' | ||
| 168 | ) | ||
| 169 | const searchMotionEase = [0.16, 1, 0.3, 1] | ||
| 170 | |||
| 171 | const backdropMotion = computed(() => | ||
| 172 | searchAnimationsEnabled.value | ||
| 173 | ? { | ||
| 174 | initial: { opacity: 0 }, | ||
| 175 | animate: { opacity: 1 }, | ||
| 176 | exit: { opacity: 0 }, | ||
| 177 | transition: { duration: 0.55, ease: searchMotionEase } | ||
| 178 | } | ||
| 179 | : {} | ||
| 180 | ) | ||
| 181 | |||
| 182 | const shellMotion = computed(() => | ||
| 183 | searchAnimationsEnabled.value | ||
| 184 | ? { | ||
| 185 | layout: 'size', | ||
| 186 | initial: { opacity: 0, scale: 0.9375 }, | ||
| 187 | animate: { opacity: 1, scale: 1 }, | ||
| 188 | exit: { opacity: 0, scale: 0.9375 }, | ||
| 189 | transition: { duration: 0.55, ease: searchMotionEase } | ||
| 190 | } | ||
| 191 | : {} | ||
| 192 | ) | ||
| 193 | |||
| 194 | const formMotion = computed(() => | ||
| 195 | searchAnimationsEnabled.value ? { layout: 'position' } : {} | ||
| 196 | ) | ||
| 197 | |||
| 198 | const ribbonMotion = computed(() => | ||
| 199 | searchAnimationsEnabled.value | ||
| 200 | ? { | ||
| 201 | layout: 'position', | ||
| 202 | initial: { opacity: 0, height: 0 }, | ||
| 203 | animate: { opacity: 1, height: 'auto' }, | ||
| 204 | exit: { opacity: 0, height: 0 }, | ||
| 205 | transition: { duration: 0.4, ease: searchMotionEase } | ||
| 206 | } | ||
| 207 | : {} | ||
| 208 | ) | ||
| 209 | |||
| 210 | const emptyStateMotion = computed(() => | ||
| 211 | searchAnimationsEnabled.value | ||
| 212 | ? { | ||
| 213 | initial: { opacity: 0 }, | ||
| 214 | animate: { | ||
| 215 | opacity: 1, | ||
| 216 | transition: { delay: 0.1 } | ||
| 217 | }, | ||
| 218 | exit: { | ||
| 219 | opacity: 0, | ||
| 220 | height: 0, | ||
| 221 | transition: { duration: 0.2 } | ||
| 222 | }, | ||
| 223 | transition: { duration: 0.7, ease: searchMotionEase } | ||
| 224 | } | ||
| 225 | : {} | ||
| 226 | ) | ||
| 227 | |||
| 228 | function resultMotion(index: number) { | ||
| 229 | if (!searchAnimationsEnabled.value) return {} | ||
| 230 | return { | ||
| 231 | layout: true, | ||
| 232 | initial: { opacity: 0, scale: 0.9375 }, | ||
| 233 | animate: { opacity: 1, scale: 1 }, | ||
| 234 | exit: { | ||
| 235 | opacity: 0, | ||
| 236 | scale: 0.9375, | ||
| 237 | height: 0, | ||
| 238 | transition: { duration: 0.25 } | ||
| 239 | }, | ||
| 240 | transition: { | ||
| 241 | duration: 0.55, | ||
| 242 | ease: searchMotionEase, | ||
| 243 | delay: index * 0.02 | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 248 | const excerptMotion = computed(() => | ||
| 249 | searchAnimationsEnabled.value | ||
| 250 | ? { | ||
| 251 | layout: true, | ||
| 252 | initial: { height: 0 }, | ||
| 253 | animate: { height: '84px' }, | ||
| 254 | exit: { height: 0 }, | ||
| 255 | transition: { duration: 0.4, ease: searchMotionEase } | ||
| 256 | } | ||
| 257 | : {} | ||
| 258 | ) | ||
| 259 | |||
| 260 | const footerMotion = computed(() => | ||
| 261 | searchAnimationsEnabled.value ? { layout: true } : {} | ||
| 262 | ) | ||
| 263 | |||
| 264 | const urlFilterDebounced = ref(filterText.value) | ||
| 265 | let urlDebounceTimer: ReturnType<typeof setTimeout> | undefined | ||
| 266 | watch(filterText, (v) => { | ||
| 267 | clearTimeout(urlDebounceTimer) | ||
| 268 | if (!v) { | ||
| 269 | urlFilterDebounced.value = '' // instant clear, no trailing-edge delay | ||
| 270 | return | ||
| 271 | } | ||
| 272 | urlDebounceTimer = setTimeout(() => { | ||
| 273 | urlFilterDebounced.value = v | ||
| 274 | }, 60) | ||
| 275 | }) | ||
| 276 | onBeforeUnmount(() => clearTimeout(urlDebounceTimer)) | ||
| 277 | |||
| 278 | // Cycle through modes on mobile (only active button is visible, tap it to advance) | ||
| 279 | function cycleSearchMode() { | ||
| 280 | const modes = ['exact', 'fuzzy', 'url'] as const | ||
| 281 | const idx = modes.indexOf(searchMode.value) | ||
| 282 | searchMode.value = modes[(idx + 1) % modes.length] | ||
| 283 | } | ||
| 284 | |||
| 285 | // Keep matchExact and urlSearchMode as computed aliases | ||
| 286 | const matchExact = computed(() => searchMode.value === 'exact') | ||
| 287 | const urlSearchMode = computed(() => searchMode.value === 'url') | ||
| 288 | |||
| 289 | const showHistory = computed( | ||
| 290 | () => !filterText.value && searchHistory.value.length > 0 | ||
| 291 | ) | ||
| 292 | |||
| 293 | function saveToHistory( | ||
| 294 | query: string, | ||
| 295 | mode: SearchSortMode, | ||
| 296 | path?: string[], | ||
| 297 | href?: string, | ||
| 298 | resultText?: string | ||
| 299 | ) { | ||
| 300 | const trimmed = query.trim() | ||
| 301 | if (!trimmed || !saveHistoryEnabled.value) return | ||
| 302 | const pathKey = (path ?? []).join('\n') | ||
| 303 | searchHistory.value = [ | ||
| 304 | { query: trimmed, mode, path, href, resultText }, | ||
| 305 | ...searchHistory.value.filter( | ||
| 306 | (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey) | ||
| 307 | ) | ||
| 308 | ] | ||
| 309 | } | ||
| 310 | |||
| 311 | function removeFromHistory(index: number) { | ||
| 312 | searchHistory.value = searchHistory.value.filter((_, i) => i !== index) | ||
| 313 | } | ||
| 314 | |||
| 315 | function applyHistory(entry: SearchHistoryEntry) { | ||
| 316 | if (entry.href) { | ||
| 317 | window.dispatchEvent( | ||
| 318 | new CustomEvent('search-nav', { | ||
| 319 | detail: { query: entry.query, resultText: entry.resultText } | ||
| 320 | }) | ||
| 321 | ) | ||
| 322 | router.go(entry.href) | ||
| 323 | showSearch.value = false | ||
| 324 | return | ||
| 325 | } | ||
| 326 | searchMode.value = entry.mode | ||
| 327 | filterText.value = entry.query | ||
| 328 | nextTick(() => focusSearchInput(false)) | ||
| 329 | } | ||
| 330 | |||
| 331 | // Mobile settings popup | ||
| 332 | const showSettingsPopup = ref(false) | ||
| 333 | const settingsButtonRef = ref<HTMLButtonElement>() | ||
| 334 | const settingsPopupRef = ref<HTMLDivElement>() | ||
| 335 | const settingsBounding = useElementBounding(settingsButtonRef) | ||
| 336 | type HelpSection = | ||
| 337 | | 'search' | ||
| 338 | | 'view' | ||
| 339 | | 'preload' | ||
| 340 | | 'highlight' | ||
| 341 | | 'history' | ||
| 342 | const activeHelpSection = ref<HelpSection | null>(null) | ||
| 343 | const helpPopupEl = ref<HTMLDivElement>() | ||
| 344 | const helpPopupPos = ref({ top: -9999, left: -9999 }) | ||
| 345 | |||
| 346 | watch(showSettingsPopup, (val) => { | ||
| 347 | if (!val) { | ||
| 348 | activeHelpSection.value = null | ||
| 349 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 350 | } | ||
| 351 | }) | ||
| 352 | |||
| 353 | const canHoverHelp = () => | ||
| 354 | typeof window !== 'undefined' && window.matchMedia('(hover: hover)').matches | ||
| 355 | |||
| 356 | function positionHelpPopup(btn: HTMLElement) { | ||
| 357 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 358 | const rect = btn.getBoundingClientRect() | ||
| 359 | // Anchor to the menu's left edge so the popup sits beside it, not over it. | ||
| 360 | const menuRect = settingsPopupRef.value?.getBoundingClientRect() | ||
| 361 | nextTick(() => { | ||
| 362 | const popupW = helpPopupEl.value?.offsetWidth || 260 | ||
| 363 | const popupH = helpPopupEl.value?.offsetHeight || 200 | ||
| 364 | const vw = window.innerWidth | ||
| 365 | const margin = 8 | ||
| 366 | const isMobile = vw < 768 | ||
| 367 | if (isMobile) { | ||
| 368 | const aboveTop = rect.top - popupH - margin | ||
| 369 | const belowTop = rect.bottom + margin | ||
| 370 | const top = aboveTop >= margin ? aboveTop : belowTop | ||
| 371 | const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin)) | ||
| 372 | helpPopupPos.value = { top, left } | ||
| 373 | } else { | ||
| 374 | const anchorLeft = menuRect ? menuRect.left : rect.left | ||
| 375 | helpPopupPos.value = { | ||
| 376 | left: Math.max(margin, anchorLeft - popupW - 16), | ||
| 377 | top: rect.top, | ||
| 378 | } | ||
| 379 | } | ||
| 380 | }) | ||
| 381 | } | ||
| 382 | |||
| 383 | function closeHelpSection() { | ||
| 384 | activeHelpSection.value = null | ||
| 385 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 386 | } | ||
| 387 | |||
| 388 | function toggleHelpSection(section: HelpSection, e: MouseEvent) { | ||
| 389 | // Hover devices open/close via mouseenter/leave; touch devices toggle on tap. | ||
| 390 | if (canHoverHelp()) { | ||
| 391 | activeHelpSection.value = section | ||
| 392 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 393 | return | ||
| 394 | } | ||
| 395 | if (activeHelpSection.value === section) { | ||
| 396 | closeHelpSection() | ||
| 397 | return | ||
| 398 | } | ||
| 399 | activeHelpSection.value = section | ||
| 400 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 401 | } | ||
| 402 | |||
| 403 | function onHelpEnter(section: HelpSection, e: MouseEvent) { | ||
| 404 | if (!canHoverHelp()) return | ||
| 405 | activeHelpSection.value = section | ||
| 406 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 407 | } | ||
| 408 | |||
| 409 | function onHelpLeave() { | ||
| 410 | if (!canHoverHelp()) return | ||
| 411 | closeHelpSection() | ||
| 412 | } | ||
| 413 | |||
| 414 | const settingsPopupStyle = computed(() => ({ | ||
| 415 | top: `${settingsBounding.bottom.value + 8}px`, | ||
| 416 | right: `calc(100vw - ${settingsBounding.right.value}px)`, | ||
| 417 | })) | ||
| 418 | |||
| 419 | onClickOutside(settingsPopupRef, () => { | ||
| 420 | showSettingsPopup.value = false | ||
| 421 | }, { ignore: [settingsButtonRef] }) | ||
| 422 | |||
| 423 | interface PageGroupCount { | ||
| 424 | key: string | ||
| 425 | count: number | ||
| 426 | } | ||
| 427 | |||
| 428 | const urlMatches = shallowRef<PageLink[]>([]) | ||
| 429 | const urlPageGroupCounts = shallowRef<PageGroupCount[]>([]) | ||
| 430 | |||
| 431 | interface UrlResult { | ||
| 432 | tabs?: string[] | ||
| 433 | href: string | ||
| 434 | linkText: string | ||
| 435 | pageId: string | ||
| 436 | anchor: string | ||
| 437 | titles: string[] | ||
| 438 | highlighted: string | ||
| 439 | } | ||
| 440 | |||
| 441 | const URL_PAGE_SIZE = 25 | ||
| 442 | |||
| 443 | // 1-indexed current page within the URL results. | ||
| 444 | const urlPage = ref(1) | ||
| 445 | |||
| 446 | // Full URL match set returned by the search worker. | ||
| 447 | // Used for accurate page-group counts in the ribbon and for pagination. | ||
| 448 | |||
| 449 | // URL mode page ribbon — mirrors the normal pageGroups/filteredResults logic | ||
| 450 | const urlActivePageFilter = ref<string | null>(null) | ||
| 451 | |||
| 452 | const urlPageGroups = computed(() => | ||
| 453 | urlPageGroupCounts.value | ||
| 454 | .map((group) => ({ | ||
| 455 | key: group.key, | ||
| 456 | label: getPageLabel(group.key), | ||
| 457 | count: group.count | ||
| 458 | })) | ||
| 459 | .sort((a, b) => getPageOrder(a.key) - getPageOrder(b.key)) | ||
| 460 | ) | ||
| 461 | |||
| 462 | // Full match set honoring the active ribbon page filter (uncapped). | ||
| 463 | const urlFilteredMatches = computed((): PageLink[] => { | ||
| 464 | if (!urlActivePageFilter.value) return urlMatches.value | ||
| 465 | return urlMatches.value.filter((l) => l.pageId === urlActivePageFilter.value) | ||
| 466 | }) | ||
| 467 | |||
| 468 | // Total number of result pages (Google-style paging through urlFilteredMatches). | ||
| 469 | const urlTotalPages = computed(() => | ||
| 470 | Math.max(1, Math.ceil(urlFilteredMatches.value.length / URL_PAGE_SIZE)) | ||
| 471 | ) | ||
| 472 | |||
| 473 | // Clamp the current page whenever the result set shrinks. | ||
| 474 | const urlCurrentPage = computed(() => | ||
| 475 | Math.min(urlPage.value, urlTotalPages.value) | ||
| 476 | ) | ||
| 477 | |||
| 478 | // The rows actually rendered: the current page's slice of the filtered matches. | ||
| 479 | const filteredUrlResults = computed((): UrlResult[] => { | ||
| 480 | const matches = urlFilteredMatches.value | ||
| 481 | const start = (urlCurrentPage.value - 1) * URL_PAGE_SIZE | ||
| 482 | const end = start + URL_PAGE_SIZE | ||
| 483 | const out: UrlResult[] = [] | ||
| 484 | const query = urlFilterDebounced.value.trim() | ||
| 485 | for (let i = start; i < end && i < matches.length; i++) { | ||
| 486 | const link = matches[i] | ||
| 487 | out.push({ | ||
| 488 | href: link.href, | ||
| 489 | linkText: link.linkText, | ||
| 490 | pageId: link.pageId, | ||
| 491 | anchor: link.anchor, | ||
| 492 | titles: link.titles, | ||
| 493 | tabs: link.tabs, | ||
| 494 | highlighted: highlightUrl(link.href, query) | ||
| 495 | }) | ||
| 496 | } | ||
| 497 | return out | ||
| 498 | }) | ||
| 499 | |||
| 500 | function escapeHtml(value: string) { | ||
| 501 | return value | ||
| 502 | .replace(/&/g, '&') | ||
| 503 | .replace(/</g, '<') | ||
| 504 | .replace(/>/g, '>') | ||
| 505 | .replace(/"/g, '"') | ||
| 506 | .replace(/'/g, ''') | ||
| 507 | } | ||
| 508 | |||
| 509 | function highlightUrl(url: string, query: string) { | ||
| 510 | const needle = query.trim() | ||
| 511 | if (!needle) return escapeHtml(url) | ||
| 512 | |||
| 513 | const lowerUrl = url.toLowerCase() | ||
| 514 | const lowerNeedle = needle.toLowerCase() | ||
| 515 | let out = '' | ||
| 516 | let cursor = 0 | ||
| 517 | let index = lowerUrl.indexOf(lowerNeedle) | ||
| 518 | |||
| 519 | while (index !== -1) { | ||
| 520 | out += escapeHtml(url.slice(cursor, index)) | ||
| 521 | out += `<mark class="url-highlight">${ | ||
| 522 | escapeHtml(url.slice(index, index + needle.length)) | ||
| 523 | }</mark>` | ||
| 524 | cursor = index + needle.length | ||
| 525 | index = lowerUrl.indexOf(lowerNeedle, cursor) | ||
| 526 | } | ||
| 527 | |||
| 528 | return out + escapeHtml(url.slice(cursor)) | ||
| 529 | } | ||
| 530 | |||
| 531 | // Compact page-number list with ellipses, e.g. [1, '…', 4, 5, 6, '…', 12]. | ||
| 532 | const urlPageList = computed<(number | '…')[]>(() => { | ||
| 533 | const total = urlTotalPages.value | ||
| 534 | const current = urlCurrentPage.value | ||
| 535 | if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1) | ||
| 536 | const pages: (number | '…')[] = [1] | ||
| 537 | const left = Math.max(2, current - 1) | ||
| 538 | const right = Math.min(total - 1, current + 1) | ||
| 539 | if (left > 2) pages.push('…') | ||
| 540 | for (let p = left; p <= right; p++) pages.push(p) | ||
| 541 | if (right < total - 1) pages.push('…') | ||
| 542 | pages.push(total) | ||
| 543 | return pages | ||
| 544 | }) | ||
| 545 | |||
| 546 | function goToUrlPage(p: number) { | ||
| 547 | const target = Math.min(Math.max(1, p), urlTotalPages.value) | ||
| 548 | if (target === urlCurrentPage.value) return | ||
| 549 | urlPage.value = target | ||
| 550 | selectedIndex.value = filteredUrlResults.value.length ? 1 : -1 | ||
| 551 | nextTick(() => { | ||
| 552 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 553 | scrollToSelectedResult() | ||
| 554 | }) | ||
| 555 | } | ||
| 556 | |||
| 557 | // Reset to page 1 whenever the query changes or the page filter changes. | ||
| 558 | watch([urlFilterDebounced, urlActivePageFilter], () => { | ||
| 559 | urlPage.value = 1 | ||
| 560 | }) | ||
| 561 | |||
| 562 | // Reset URL ribbon filter if the active page disappears from the groups. | ||
| 563 | watch(urlMatches, () => { | ||
| 564 | if ( | ||
| 565 | urlActivePageFilter.value && | ||
| 566 | !urlPageGroups.value.some((g) => g.key === urlActivePageFilter.value) | ||
| 567 | ) { | ||
| 568 | urlActivePageFilter.value = null | ||
| 569 | } | ||
| 570 | }) | ||
| 571 | |||
| 572 | watch(urlSearchMode, (active) => { | ||
| 573 | if (!active) { | ||
| 574 | urlActivePageFilter.value = null | ||
| 575 | urlPage.value = 1 | ||
| 576 | } | ||
| 577 | }) | ||
| 578 | |||
| 579 | function setUrlPageFilter(key: string | null) { | ||
| 580 | urlActivePageFilter.value = urlActivePageFilter.value === key ? null : key | ||
| 581 | urlPage.value = 1 | ||
| 582 | selectedIndex.value = filteredUrlResults.value.length ? 1 : -1 | ||
| 583 | nextTick(() => { | ||
| 584 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 585 | scrollToSelectedResult() | ||
| 586 | }) | ||
| 587 | } | ||
| 588 | |||
| 589 | const disableDetailedView = computed(() => { | ||
| 590 | return ( | ||
| 591 | theme.value.search?.provider === 'local' && | ||
| 592 | theme.value.search.options?.detailedView === false | ||
| 593 | ) | ||
| 594 | }) | ||
| 595 | |||
| 596 | const buttonText = computed(() => { | ||
| 597 | const options = theme.value.search?.options | ||
| 598 | |||
| 599 | return ( | ||
| 600 | options?.locales?.[localeIndex.value]?.translations?.button?.buttonText || | ||
| 601 | options?.translations?.button?.buttonText || | ||
| 602 | 'Search' | ||
| 603 | ) | ||
| 604 | }) | ||
| 605 | |||
| 606 | watchEffect(() => { | ||
| 607 | if (disableDetailedView.value) { | ||
| 608 | showDetailedList.value = false | ||
| 609 | } | ||
| 610 | }) | ||
| 611 | |||
| 612 | const results: Ref<(SearchResult & Result)[]> = shallowRef([]) | ||
| 613 | |||
| 614 | const currentTerms = shallowRef(new Set<string>()) | ||
| 615 | |||
| 616 | const enableNoResults = ref(false) | ||
| 617 | const textSearchLoading = ref(false) | ||
| 618 | const urlSearchLoading = ref(false) | ||
| 619 | const searchLoading = computed(() => | ||
| 620 | urlSearchMode.value ? urlSearchLoading.value : textSearchLoading.value | ||
| 621 | ) | ||
| 622 | const pageMeta = (() => { | ||
| 623 | const map = new Map<string, { label: string; order: number }>() | ||
| 624 | let order = 0 | ||
| 625 | const stripIcon = (text: string) => | ||
| 626 | text | ||
| 627 | .replace(/<[^>]*>/g, '') | ||
| 628 | .replace(/\s+/g, ' ') | ||
| 629 | .trim() | ||
| 630 | const walk = (items: DefaultTheme.SidebarItem[]) => { | ||
| 631 | for (const item of items) { | ||
| 632 | if (item.link) { | ||
| 633 | const key = item.link.replace(/\/$/, '') | ||
| 634 | if (!map.has(key)) { | ||
| 635 | map.set(key, { label: stripIcon(item.text ?? key), order: order++ }) | ||
| 636 | } | ||
| 637 | } | ||
| 638 | if (item.items) walk(item.items) | ||
| 639 | } | ||
| 640 | } | ||
| 641 | walk(sidebar as DefaultTheme.SidebarItem[]) | ||
| 642 | return map | ||
| 643 | })() | ||
| 644 | |||
| 645 | interface TextSearchWorkerPayload { | ||
| 646 | results: (SearchResult & Result)[] | ||
| 647 | terms: string[] | ||
| 648 | } | ||
| 649 | |||
| 650 | interface UrlSearchWorkerPayload { | ||
| 651 | matches: PageLink[] | ||
| 652 | pageGroups: PageGroupCount[] | ||
| 653 | } | ||
| 654 | |||
| 655 | interface LoadIndexWorkerRequest { | ||
| 656 | type: 'load-index' | ||
| 657 | localeIndex: string | ||
| 658 | indexJson: unknown | ||
| 659 | indexVersion: number | ||
| 660 | config: ReturnType<typeof getMiniSearchWorkerConfig> | ||
| 661 | } | ||
| 662 | |||
| 663 | interface TextSearchWorkerRequest { | ||
| 664 | type: 'text-search' | ||
| 665 | query: string | ||
| 666 | mode: SearchSortMode | ||
| 667 | pageOrderEntries: [string, number][] | ||
| 668 | } | ||
| 669 | |||
| 670 | interface UrlSearchWorkerRequest { | ||
| 671 | type: 'url-search' | ||
| 672 | query: string | ||
| 673 | pageOrderEntries: [string, number][] | ||
| 674 | } | ||
| 675 | |||
| 676 | interface PreloadMetadataWorkerRequest { | ||
| 677 | type: 'preload-metadata' | ||
| 678 | pageOrderEntries: [string, number][] | ||
| 679 | } | ||
| 680 | |||
| 681 | type SearchWorkerRequest = | ||
| 682 | | LoadIndexWorkerRequest | ||
| 683 | | TextSearchWorkerRequest | ||
| 684 | | UrlSearchWorkerRequest | ||
| 685 | | PreloadMetadataWorkerRequest | ||
| 686 | |||
| 687 | const activePageFilter = ref<string | null>(null) | ||
| 688 | const searchWorkerReady = ref(false) | ||
| 689 | const searchWorkerConfigKey = computed(() => | ||
| 690 | JSON.stringify(getMiniSearchWorkerConfig()) | ||
| 691 | ) | ||
| 692 | let searchWorker: Worker | undefined | ||
| 693 | let searchWorkerRequestId = 0 | ||
| 694 | let loadedWorkerIndexKey = '' | ||
| 695 | let preloadedSearchDataKey = '' | ||
| 696 | let preloadSearchDataRequest: | ||
| 697 | | { key: string; promise: Promise<void> } | ||
| 698 | | undefined | ||
| 699 | const searchWorkerRequests = new Map< | ||
| 700 | number, | ||
| 701 | { | ||
| 702 | resolve: (value: unknown) => void | ||
| 703 | reject: (reason?: unknown) => void | ||
| 704 | } | ||
| 705 | >() | ||
| 706 | |||
| 707 | function getPageOrderEntries(): [string, number][] { | ||
| 708 | return [...pageMeta.entries()].map(([key, meta]) => [key, meta.order]) | ||
| 709 | } | ||
| 710 | |||
| 711 | async function preloadSearchData( | ||
| 712 | localeIndexValue: string, | ||
| 713 | indexVersion: number, | ||
| 714 | configKey: string | ||
| 715 | ) { | ||
| 716 | const workerIndexKey = `${localeIndexValue}\n${indexVersion}\n${configKey}` | ||
| 717 | if (preloadedSearchDataKey === workerIndexKey) return | ||
| 718 | if (preloadSearchDataRequest?.key === workerIndexKey) { | ||
| 719 | await preloadSearchDataRequest.promise | ||
| 720 | return | ||
| 721 | } | ||
| 722 | |||
| 723 | const promise = (async () => { | ||
| 724 | if (loadedWorkerIndexKey !== workerIndexKey) { | ||
| 725 | const indexJson = (await searchIndexData.value[localeIndexValue]?.()) | ||
| 726 | ?.default | ||
| 727 | await postSearchWorker<void>({ | ||
| 728 | type: 'load-index', | ||
| 729 | localeIndex: localeIndexValue, | ||
| 730 | indexJson, | ||
| 731 | indexVersion, | ||
| 732 | config: getMiniSearchWorkerConfig() | ||
| 733 | }) | ||
| 734 | loadedWorkerIndexKey = workerIndexKey | ||
| 735 | } | ||
| 736 | |||
| 737 | await postSearchWorker<void>({ | ||
| 738 | type: 'preload-metadata', | ||
| 739 | pageOrderEntries: getPageOrderEntries() | ||
| 740 | }) | ||
| 741 | preloadedSearchDataKey = workerIndexKey | ||
| 742 | })() | ||
| 743 | |||
| 744 | preloadSearchDataRequest = { key: workerIndexKey, promise } | ||
| 745 | try { | ||
| 746 | await promise | ||
| 747 | } finally { | ||
| 748 | if (preloadSearchDataRequest?.promise === promise) { | ||
| 749 | preloadSearchDataRequest = undefined | ||
| 750 | } | ||
| 751 | } | ||
| 752 | } | ||
| 753 | |||
| 754 | function stripNonCloneable(value: unknown): unknown { | ||
| 755 | if (typeof value === 'function' || typeof value === 'symbol') return undefined | ||
| 756 | if (!value || typeof value !== 'object') return value | ||
| 757 | if (Array.isArray(value)) { | ||
| 758 | return value | ||
| 759 | .map((item) => stripNonCloneable(item)) | ||
| 760 | .filter((item) => item !== undefined) | ||
| 761 | } | ||
| 762 | |||
| 763 | const out: Record<string, unknown> = {} | ||
| 764 | for (const [key, nestedValue] of Object.entries(value)) { | ||
| 765 | const cloneable = stripNonCloneable(nestedValue) | ||
| 766 | if (cloneable !== undefined) out[key] = cloneable | ||
| 767 | } | ||
| 768 | return out | ||
| 769 | } | ||
| 770 | |||
| 771 | function getMiniSearchWorkerConfig() { | ||
| 772 | const miniSearch = theme.value.search?.provider === 'local' | ||
| 773 | ? theme.value.search.options?.miniSearch | ||
| 774 | : undefined | ||
| 775 | const rawSearchOptions = miniSearch?.searchOptions as | ||
| 776 | | Record<string, unknown> | ||
| 777 | | undefined | ||
| 778 | |||
| 779 | return { | ||
| 780 | options: stripNonCloneable(miniSearch?.options) as | ||
| 781 | | Record<string, unknown> | ||
| 782 | | undefined, | ||
| 783 | searchOptions: stripNonCloneable(rawSearchOptions) as | ||
| 784 | | Record<string, unknown> | ||
| 785 | | undefined, | ||
| 786 | useDefaultBoostDocument: | ||
| 787 | typeof rawSearchOptions?.boostDocument === 'function' | ||
| 788 | } | ||
| 789 | } | ||
| 790 | |||
| 791 | function ensureSearchWorker() { | ||
| 792 | if (!inBrowser || searchWorker) return searchWorker | ||
| 793 | |||
| 794 | try { | ||
| 795 | searchWorker = new Worker( | ||
| 796 | new URL('../workers/searchWorker.ts', import.meta.url), | ||
| 797 | { | ||
| 798 | type: 'module' | ||
| 799 | } | ||
| 800 | ) | ||
| 801 | } catch (error) { | ||
| 802 | console.error('[search] failed to start search worker', error) | ||
| 803 | return | ||
| 804 | } | ||
| 805 | |||
| 806 | searchWorker.onmessage = (event: MessageEvent) => { | ||
| 807 | const data = event.data as { | ||
| 808 | id: number | ||
| 809 | type: string | ||
| 810 | payload?: unknown | ||
| 811 | error?: string | ||
| 812 | } | ||
| 813 | const request = searchWorkerRequests.get(data.id) | ||
| 814 | if (!request) return | ||
| 815 | |||
| 816 | searchWorkerRequests.delete(data.id) | ||
| 817 | if (data.type.endsWith(':error')) { | ||
| 818 | request.reject(new Error(data.error ?? 'Search worker failed')) | ||
| 819 | } else { | ||
| 820 | request.resolve(data.payload) | ||
| 821 | } | ||
| 822 | } | ||
| 823 | searchWorker.onerror = (event) => { | ||
| 824 | console.error('[search] search worker error', event) | ||
| 825 | } | ||
| 826 | searchWorkerReady.value = true | ||
| 827 | return searchWorker | ||
| 828 | } | ||
| 829 | |||
| 830 | function postSearchWorker<T>(message: SearchWorkerRequest) { | ||
| 831 | const worker = ensureSearchWorker() | ||
| 832 | if (!worker) return Promise.reject(new Error('Search worker is unavailable')) | ||
| 833 | |||
| 834 | const id = ++searchWorkerRequestId | ||
| 835 | return new Promise<T>((resolve, reject) => { | ||
| 836 | searchWorkerRequests.set(id, { | ||
| 837 | resolve: (value) => resolve(value as T), | ||
| 838 | reject | ||
| 839 | }) | ||
| 840 | worker.postMessage({ ...message, id }) | ||
| 841 | }) | ||
| 842 | } | ||
| 843 | |||
| 844 | onMounted(() => { | ||
| 845 | ensureSearchWorker() | ||
| 846 | }) | ||
| 847 | |||
| 848 | onBeforeUnmount(() => { | ||
| 849 | searchWorker?.terminate() | ||
| 850 | searchWorker = undefined | ||
| 851 | loadedWorkerIndexKey = '' | ||
| 852 | preloadedSearchDataKey = '' | ||
| 853 | preloadSearchDataRequest = undefined | ||
| 854 | searchWorkerReady.value = false | ||
| 855 | for (const request of searchWorkerRequests.values()) { | ||
| 856 | request.reject(new Error('Search worker was terminated')) | ||
| 857 | } | ||
| 858 | searchWorkerRequests.clear() | ||
| 859 | }) | ||
| 860 | |||
| 861 | watch( | ||
| 862 | () => | ||
| 863 | [ | ||
| 864 | searchWorkerReady.value, | ||
| 865 | showSearch.value, | ||
| 866 | localeIndex.value, | ||
| 867 | searchIndexVersion.value, | ||
| 868 | searchWorkerConfigKey.value | ||
| 869 | ] as const, | ||
| 870 | async ([ready, isOpen, localeIndexValue, indexVersion, configKey]) => { | ||
| 871 | if (!ready || !isOpen) return | ||
| 872 | |||
| 873 | try { | ||
| 874 | await preloadSearchData(localeIndexValue, indexVersion, configKey) | ||
| 875 | } catch (error) { | ||
| 876 | console.error('[search] search data preload failed', error) | ||
| 877 | } | ||
| 878 | }, | ||
| 879 | { immediate: true } | ||
| 880 | ) | ||
| 881 | |||
| 882 | watch( | ||
| 883 | () => | ||
| 884 | [ | ||
| 885 | searchWorkerReady.value, | ||
| 886 | showSearch.value, | ||
| 887 | urlSearchMode.value, | ||
| 888 | urlFilterDebounced.value | ||
| 889 | ] as const, | ||
| 890 | async ([ready, isOpen, active, query], _old, onCleanup) => { | ||
| 891 | let canceled = false | ||
| 892 | onCleanup(() => { | ||
| 893 | canceled = true | ||
| 894 | }) | ||
| 895 | |||
| 896 | if (!active || !isOpen || !query.trim()) { | ||
| 897 | urlMatches.value = [] | ||
| 898 | urlPageGroupCounts.value = [] | ||
| 899 | urlSearchLoading.value = false | ||
| 900 | return | ||
| 901 | } | ||
| 902 | if (!ready) { | ||
| 903 | urlSearchLoading.value = false | ||
| 904 | return | ||
| 905 | } | ||
| 906 | |||
| 907 | urlSearchLoading.value = true | ||
| 908 | try { | ||
| 909 | const payload = await postSearchWorker<UrlSearchWorkerPayload>({ | ||
| 910 | type: 'url-search', | ||
| 911 | query, | ||
| 912 | pageOrderEntries: getPageOrderEntries() | ||
| 913 | }) | ||
| 914 | if (canceled) return | ||
| 915 | urlMatches.value = payload.matches | ||
| 916 | urlPageGroupCounts.value = payload.pageGroups | ||
| 917 | urlSearchLoading.value = false | ||
| 918 | } catch (error) { | ||
| 919 | if (!canceled) { | ||
| 920 | console.error('[search] URL search worker request failed', error) | ||
| 921 | urlMatches.value = [] | ||
| 922 | urlPageGroupCounts.value = [] | ||
| 923 | urlSearchLoading.value = false | ||
| 924 | } | ||
| 925 | } | ||
| 926 | }, | ||
| 927 | { immediate: true } | ||
| 928 | ) | ||
| 929 | |||
| 930 | function getPageKey(id: string) { | ||
| 931 | return getDocId(id).replace(/\/$/, '') | ||
| 932 | } | ||
| 933 | |||
| 934 | function getDocId(id: string) { | ||
| 935 | const hashIndex = id.indexOf('#') | ||
| 936 | return hashIndex === -1 ? id : id.slice(0, hashIndex) | ||
| 937 | } | ||
| 938 | |||
| 939 | function getDocAnchor(id: string) { | ||
| 940 | const hashIndex = id.indexOf('#') | ||
| 941 | return hashIndex === -1 ? '' : id.slice(hashIndex + 1) | ||
| 942 | } | ||
| 943 | |||
| 944 | function getPageLabel(key: string) { | ||
| 945 | return pageMeta.get(key)?.label ?? key.replace(/^\//, '') | ||
| 946 | } | ||
| 947 | |||
| 948 | function getPageOrder(key: string) { | ||
| 949 | return pageMeta.get(key)?.order ?? Number.MAX_SAFE_INTEGER | ||
| 950 | } | ||
| 951 | |||
| 952 | const pageGroups = computed(() => { | ||
| 953 | const map = new Map<string, { key: string; label: string; count: number }>() | ||
| 954 | for (const r of results.value) { | ||
| 955 | const key = getPageKey(r.id) | ||
| 956 | const existing = map.get(key) | ||
| 957 | if (existing) existing.count++ | ||
| 958 | else map.set(key, { key, label: getPageLabel(key), count: 1 }) | ||
| 959 | } | ||
| 960 | return [...map.values()].sort( | ||
| 961 | (a, b) => getPageOrder(a.key) - getPageOrder(b.key) | ||
| 962 | ) | ||
| 963 | }) | ||
| 964 | |||
| 965 | const filteredResults = computed(() => { | ||
| 966 | if (!activePageFilter.value) return results.value | ||
| 967 | return results.value.filter( | ||
| 968 | (r) => getPageKey(r.id) === activePageFilter.value | ||
| 969 | ) | ||
| 970 | }) | ||
| 971 | |||
| 972 | // --- Normal-mode (exact/fuzzy) pagination --------------------------------- | ||
| 973 | // Mirrors the URL-mode pager. filteredResults stays the full filtered set; | ||
| 974 | // pagedResults is the current page slice that actually renders. | ||
| 975 | const NORMAL_PAGE_SIZE = URL_PAGE_SIZE | ||
| 976 | |||
| 977 | const normalPage = ref(1) | ||
| 978 | |||
| 979 | const normalTotalPages = computed(() => | ||
| 980 | Math.max(1, Math.ceil(filteredResults.value.length / NORMAL_PAGE_SIZE)) | ||
| 981 | ) | ||
| 982 | |||
| 983 | const normalCurrentPage = computed(() => | ||
| 984 | Math.min(normalPage.value, normalTotalPages.value) | ||
| 985 | ) | ||
| 986 | |||
| 987 | const pagedResults = computed(() => { | ||
| 988 | const start = (normalCurrentPage.value - 1) * NORMAL_PAGE_SIZE | ||
| 989 | return filteredResults.value.slice(start, start + NORMAL_PAGE_SIZE) | ||
| 990 | }) | ||
| 991 | |||
| 992 | const normalPageList = computed<(number | '…')[]>(() => { | ||
| 993 | const total = normalTotalPages.value | ||
| 994 | const current = normalCurrentPage.value | ||
| 995 | if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1) | ||
| 996 | const pages: (number | '…')[] = [1] | ||
| 997 | const left = Math.max(2, current - 1) | ||
| 998 | const right = Math.min(total - 1, current + 1) | ||
| 999 | if (left > 2) pages.push('…') | ||
| 1000 | for (let p = left; p <= right; p++) pages.push(p) | ||
| 1001 | if (right < total - 1) pages.push('…') | ||
| 1002 | pages.push(total) | ||
| 1003 | return pages | ||
| 1004 | }) | ||
| 1005 | |||
| 1006 | function goToNormalPage(p: number) { | ||
| 1007 | const target = Math.min(Math.max(1, p), normalTotalPages.value) | ||
| 1008 | if (target === normalCurrentPage.value) return | ||
| 1009 | normalPage.value = target | ||
| 1010 | selectedIndex.value = pagedResults.value.length ? 1 : -1 | ||
| 1011 | nextTick(() => { | ||
| 1012 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 1013 | scrollToSelectedResult() | ||
| 1014 | reapplyHighlights() | ||
| 1015 | void buildVisibleExcerpts() | ||
| 1016 | }) | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | // --------------------------------------------------------------------------- | ||
| 1020 | |||
| 1021 | function setPageFilter(key: string | null) { | ||
| 1022 | activePageFilter.value = activePageFilter.value === key ? null : key | ||
| 1023 | normalPage.value = 1 | ||
| 1024 | selectedIndex.value = filteredResults.value.length ? 1 : -1 | ||
| 1025 | nextTick(() => { | ||
| 1026 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 1027 | scrollToSelectedResult() | ||
| 1028 | reapplyHighlights() | ||
| 1029 | void buildVisibleExcerpts() | ||
| 1030 | }) | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | async function reapplyHighlights() { | ||
| 1034 | if (!showDetailedList.value || !currentTerms.value.size) { | ||
| 1035 | centerExcerptsUntilSettled() | ||
| 1036 | return | ||
| 1037 | } | ||
| 1038 | await new Promise<void>((resolve) => { | ||
| 1039 | mark.value?.unmark({ | ||
| 1040 | done: () => { | ||
| 1041 | mark.value?.markRegExp(formMarkRegex(currentTerms.value), { | ||
| 1042 | done: () => resolve() | ||
| 1043 | }) | ||
| 1044 | } | ||
| 1045 | }) | ||
| 1046 | }) | ||
| 1047 | await nextTick() | ||
| 1048 | centerExcerptsUntilSettled() | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | const toRows = (list: (SearchResult & Result)[]) => | ||
| 1052 | list.map((r) => { | ||
| 1053 | const map = cache.get(getDocId(r.id)) | ||
| 1054 | return { ...r, text: map?.get(getDocAnchor(r.id)) ?? '' } | ||
| 1055 | }) | ||
| 1056 | |||
| 1057 | let excerptBuildToken = 0 | ||
| 1058 | |||
| 1059 | function visiblePageDocs(pageOffset: number): string[] { | ||
| 1060 | const start = (normalCurrentPage.value - 1 + pageOffset) * NORMAL_PAGE_SIZE | ||
| 1061 | if (start < 0) return [] | ||
| 1062 | const list = filteredResults.value | ||
| 1063 | const docs: string[] = [] | ||
| 1064 | const seen = new Set<string>() | ||
| 1065 | for (let i = start; i < start + NORMAL_PAGE_SIZE && i < list.length; i++) { | ||
| 1066 | const docId = getDocId(String(list[i].id)) | ||
| 1067 | if (!seen.has(docId)) { | ||
| 1068 | seen.add(docId) | ||
| 1069 | docs.push(docId) | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | return docs | ||
| 1073 | } | ||
| 1074 | |||
| 1075 | // Builds excerpts for the visible pagination page, then prefetches the next. | ||
| 1076 | async function buildVisibleExcerpts() { | ||
| 1077 | const token = ++excerptBuildToken | ||
| 1078 | if (!showDetailedList.value || urlSearchMode.value) return | ||
| 1079 | |||
| 1080 | let builtAny = false | ||
| 1081 | let sliceStart = performance.now() | ||
| 1082 | |||
| 1083 | const refreshRows = async () => { | ||
| 1084 | const keepSelected = selectedIndex.value | ||
| 1085 | results.value = toRows(results.value) | ||
| 1086 | await nextTick() | ||
| 1087 | if (token !== excerptBuildToken) return false | ||
| 1088 | selectedIndex.value = keepSelected | ||
| 1089 | return true | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | const buildAll = async (docIds: string[], progressive = false) => { | ||
| 1093 | for (const docId of docIds) { | ||
| 1094 | if (cache.get(docId)) continue | ||
| 1095 | await buildDocExcerpt(docId) | ||
| 1096 | if (token !== excerptBuildToken) return false | ||
| 1097 | builtAny = true | ||
| 1098 | if (performance.now() - sliceStart > 40) { | ||
| 1099 | if (progressive && !(await refreshRows())) return false | ||
| 1100 | await nextFrame() | ||
| 1101 | if (token !== excerptBuildToken) return false | ||
| 1102 | sliceStart = performance.now() | ||
| 1103 | } | ||
| 1104 | } | ||
| 1105 | return true | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | if (!(await buildAll(visiblePageDocs(0), true))) return | ||
| 1109 | |||
| 1110 | const rowsStale = pagedResults.value.some((r) => { | ||
| 1111 | if (r.text) return false | ||
| 1112 | const map = cache.get(getDocId(String(r.id))) | ||
| 1113 | return Boolean(map?.get(getDocAnchor(String(r.id)))) | ||
| 1114 | }) | ||
| 1115 | |||
| 1116 | if (builtAny || rowsStale) { | ||
| 1117 | if (!(await refreshRows())) return | ||
| 1118 | await reapplyHighlights() | ||
| 1119 | if (token !== excerptBuildToken) return | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | if (excerptPreload.value === 'next') { | ||
| 1123 | await buildAll(visiblePageDocs(1)) | ||
| 1124 | } else if (excerptPreload.value === 'all') { | ||
| 1125 | const seen = new Set<string>() | ||
| 1126 | const docs: string[] = [] | ||
| 1127 | for (const r of results.value) { | ||
| 1128 | const docId = getDocId(String(r.id)) | ||
| 1129 | if (!seen.has(docId)) { | ||
| 1130 | seen.add(docId) | ||
| 1131 | docs.push(docId) | ||
| 1132 | } | ||
| 1133 | } | ||
| 1134 | await buildAll(docs) | ||
| 1135 | } | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | watch(excerptPreload, () => { | ||
| 1139 | void buildVisibleExcerpts() | ||
| 1140 | }) | ||
| 1141 | |||
| 1142 | watch(results, () => { | ||
| 1143 | if ( | ||
| 1144 | activePageFilter.value && | ||
| 1145 | !pageGroups.value.some((g) => g.key === activePageFilter.value) | ||
| 1146 | ) { | ||
| 1147 | activePageFilter.value = null | ||
| 1148 | } | ||
| 1149 | }) | ||
| 1150 | |||
| 1151 | watch(filterText, () => { | ||
| 1152 | enableNoResults.value = false | ||
| 1153 | }) | ||
| 1154 | |||
| 1155 | const ribbonTrack = shallowRef<HTMLElement>() | ||
| 1156 | const ribbonCanScrollLeft = ref(false) | ||
| 1157 | const ribbonCanScrollRight = ref(false) | ||
| 1158 | |||
| 1159 | function getRibbonTrack(): HTMLElement | null { | ||
| 1160 | return ( | ||
| 1161 | ribbonTrack.value ?? | ||
| 1162 | (el.value?.querySelector('.page-ribbon-track') as HTMLElement | null) | ||
| 1163 | ) | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | function updateRibbonOverflow() { | ||
| 1167 | const track = getRibbonTrack() | ||
| 1168 | if (!track) { | ||
| 1169 | ribbonCanScrollLeft.value = false | ||
| 1170 | ribbonCanScrollRight.value = false | ||
| 1171 | return | ||
| 1172 | } | ||
| 1173 | ribbonCanScrollLeft.value = track.scrollLeft > 2 | ||
| 1174 | ribbonCanScrollRight.value = | ||
| 1175 | track.scrollWidth - track.clientWidth - track.scrollLeft > 2 | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | function scrollActivePagePillIntoView(direction = 0) { | ||
| 1179 | nextTick(() => { | ||
| 1180 | const track = getRibbonTrack() | ||
| 1181 | if (!track) return | ||
| 1182 | |||
| 1183 | const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')] | ||
| 1184 | const activeIndex = pills.findIndex((pill) => | ||
| 1185 | pill.classList.contains('active') | ||
| 1186 | ) | ||
| 1187 | const active = pills[activeIndex] | ||
| 1188 | if (!active) return | ||
| 1189 | |||
| 1190 | const trackRect = track.getBoundingClientRect() | ||
| 1191 | const activeRect = active.getBoundingClientRect() | ||
| 1192 | const gap = 8 | ||
| 1193 | let nextScrollLeft = track.scrollLeft | ||
| 1194 | |||
| 1195 | if (activeRect.left < trackRect.left) { | ||
| 1196 | nextScrollLeft += activeRect.left - trackRect.left - gap | ||
| 1197 | } else if (activeRect.right > trackRect.right) { | ||
| 1198 | nextScrollLeft += activeRect.right - trackRect.right + gap | ||
| 1199 | } | ||
| 1200 | |||
| 1201 | const peek = pills[activeIndex + Math.sign(direction)] | ||
| 1202 | if (peek) { | ||
| 1203 | const peekRect = peek.getBoundingClientRect() | ||
| 1204 | if (direction > 0 && peekRect.right > trackRect.right) { | ||
| 1205 | nextScrollLeft += peekRect.right - trackRect.right + gap | ||
| 1206 | } else if (direction < 0 && peekRect.left < trackRect.left) { | ||
| 1207 | nextScrollLeft += peekRect.left - trackRect.left - gap | ||
| 1208 | } | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | const max = track.scrollWidth - track.clientWidth | ||
| 1212 | track.scrollTo({ | ||
| 1213 | left: Math.max(0, Math.min(max, nextScrollLeft)), | ||
| 1214 | behavior: searchAnimationsEnabled.value ? 'smooth' : 'auto' | ||
| 1215 | }) | ||
| 1216 | updateRibbonOverflow() | ||
| 1217 | }) | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | let ribbonAnimHandle = 0 | ||
| 1221 | |||
| 1222 | function scrollRibbon(direction: number) { | ||
| 1223 | const track = getRibbonTrack() | ||
| 1224 | if (!track) return | ||
| 1225 | const max = track.scrollWidth - track.clientWidth | ||
| 1226 | const amount = track.clientWidth * 0.7 * direction | ||
| 1227 | const from = track.scrollLeft | ||
| 1228 | const to = Math.max(0, Math.min(max, from + amount)) | ||
| 1229 | if (to === from) return | ||
| 1230 | |||
| 1231 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) | ||
| 1232 | |||
| 1233 | if (!searchAnimationsEnabled.value) { | ||
| 1234 | track.scrollLeft = to | ||
| 1235 | updateRibbonOverflow() | ||
| 1236 | return | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | const duration = 280 | ||
| 1240 | const start = performance.now() | ||
| 1241 | const ease = (t: number) => 1 - Math.pow(1 - t, 3) | ||
| 1242 | |||
| 1243 | const step = (now: number) => { | ||
| 1244 | const t = Math.min(1, (now - start) / duration) | ||
| 1245 | track.scrollLeft = from + (to - from) * ease(t) | ||
| 1246 | updateRibbonOverflow() | ||
| 1247 | if (t < 1) { | ||
| 1248 | ribbonAnimHandle = requestAnimationFrame(step) | ||
| 1249 | } else { | ||
| 1250 | ribbonAnimHandle = 0 | ||
| 1251 | } | ||
| 1252 | } | ||
| 1253 | ribbonAnimHandle = requestAnimationFrame(step) | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | watch(pageGroups, () => { | ||
| 1257 | nextTick(updateRibbonOverflow) | ||
| 1258 | }) | ||
| 1259 | |||
| 1260 | watch(urlPageGroups, () => { | ||
| 1261 | nextTick(updateRibbonOverflow) | ||
| 1262 | }) | ||
| 1263 | |||
| 1264 | useEventListener('resize', () => { | ||
| 1265 | updateRibbonOverflow() | ||
| 1266 | }) | ||
| 1267 | |||
| 1268 | const mark = computedAsync(async () => { | ||
| 1269 | if (!resultsEl.value) return | ||
| 1270 | return markRaw(new Mark(resultsEl.value)) | ||
| 1271 | }, null) | ||
| 1272 | |||
| 1273 | const cache = new LRUCache<string, Map<string, string>>(120) | ||
| 1274 | |||
| 1275 | const inFlightExcerpts = new Map<string, Promise<void>>() | ||
| 1276 | |||
| 1277 | function buildDocExcerpt(docId: string): Promise<void> { | ||
| 1278 | if (cache.get(docId)) return Promise.resolve() | ||
| 1279 | const pending = inFlightExcerpts.get(docId) | ||
| 1280 | if (pending) return pending | ||
| 1281 | |||
| 1282 | const job = (async () => { | ||
| 1283 | const { mod } = await fetchExcerpt(docId) | ||
| 1284 | if (cache.get(docId)) return | ||
| 1285 | |||
| 1286 | const comp = (mod as any).default ?? mod | ||
| 1287 | if (!(comp?.render || comp?.setup)) return // nothing renderable; don't cache | ||
| 1288 | |||
| 1289 | const map = new Map<string, string>() | ||
| 1290 | const app = createApp(comp) | ||
| 1291 | app.config.warnHandler = () => {} | ||
| 1292 | enhanceAppWithTabs(app, { renderAll: true }) | ||
| 1293 | registerGlobalComponents(app) | ||
| 1294 | app.provide(dataSymbol, vitePressData) | ||
| 1295 | Object.defineProperties(app.config.globalProperties, { | ||
| 1296 | $frontmatter: { | ||
| 1297 | get() { | ||
| 1298 | return vitePressData.frontmatter.value | ||
| 1299 | } | ||
| 1300 | }, | ||
| 1301 | $params: { | ||
| 1302 | get() { | ||
| 1303 | return vitePressData.page.value.params | ||
| 1304 | } | ||
| 1305 | } | ||
| 1306 | }) | ||
| 1307 | const div = document.createElement('div') | ||
| 1308 | try { | ||
| 1309 | // force lazy images so the detached render doesn't download them | ||
| 1310 | const originalCreateElement = document.createElement | ||
| 1311 | document.createElement = function ( | ||
| 1312 | this: Document, | ||
| 1313 | ...args: Parameters<Document['createElement']> | ||
| 1314 | ) { | ||
| 1315 | const el = originalCreateElement.apply(this, args) | ||
| 1316 | if (el instanceof HTMLImageElement) { | ||
| 1317 | el.loading = 'lazy' | ||
| 1318 | el.decoding = 'async' | ||
| 1319 | } | ||
| 1320 | return el | ||
| 1321 | } as typeof document.createElement | ||
| 1322 | try { | ||
| 1323 | app.mount(div) | ||
| 1324 | } finally { | ||
| 1325 | document.createElement = originalCreateElement | ||
| 1326 | } | ||
| 1327 | const headings = div.querySelectorAll('h1, h2, h3, h4, h5, h6') | ||
| 1328 | headings.forEach((heading) => { | ||
| 1329 | const href = heading.querySelector('a')?.getAttribute('href') | ||
| 1330 | const anchor = href?.startsWith('#') && href.slice(1) | ||
| 1331 | if (!anchor) return | ||
| 1332 | let html = '' | ||
| 1333 | let node = heading as Element | ||
| 1334 | while ( | ||
| 1335 | (node = node.nextElementSibling!) && | ||
| 1336 | !/^h[1-6]$/i.test(node.tagName) | ||
| 1337 | ) { | ||
| 1338 | html += (node as HTMLElement).outerHTML | ||
| 1339 | } | ||
| 1340 | map.set(anchor, html) | ||
| 1341 | }) | ||
| 1342 | } catch (e) { | ||
| 1343 | console.error('[search] excerpt render failed for', docId, e) | ||
| 1344 | } finally { | ||
| 1345 | try { | ||
| 1346 | app.unmount() | ||
| 1347 | } catch { | ||
| 1348 | /* ignore */ | ||
| 1349 | } | ||
| 1350 | } | ||
| 1351 | cache.set(docId, map) | ||
| 1352 | })() | ||
| 1353 | |||
| 1354 | inFlightExcerpts.set(docId, job) | ||
| 1355 | job.finally(() => { | ||
| 1356 | if (inFlightExcerpts.get(docId) === job) inFlightExcerpts.delete(docId) | ||
| 1357 | }) | ||
| 1358 | return job | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | watchDebounced( | ||
| 1362 | () => | ||
| 1363 | [ | ||
| 1364 | searchWorkerReady.value, | ||
| 1365 | showSearch.value, | ||
| 1366 | localeIndex.value, | ||
| 1367 | searchIndexVersion.value, | ||
| 1368 | searchWorkerConfigKey.value, | ||
| 1369 | filterText.value, | ||
| 1370 | showDetailedList.value, | ||
| 1371 | searchMode.value | ||
| 1372 | ] as const, | ||
| 1373 | async ( | ||
| 1374 | [ | ||
| 1375 | ready, | ||
| 1376 | isOpen, | ||
| 1377 | localeIndexValue, | ||
| 1378 | indexVersion, | ||
| 1379 | configKey, | ||
| 1380 | filterTextValue, | ||
| 1381 | showDetailedListValue, | ||
| 1382 | mode | ||
| 1383 | ], | ||
| 1384 | old, | ||
| 1385 | onCleanup | ||
| 1386 | ) => { | ||
| 1387 | if ( | ||
| 1388 | old?.[2] !== localeIndexValue || | ||
| 1389 | old?.[3] !== indexVersion || | ||
| 1390 | old?.[4] !== configKey | ||
| 1391 | ) { | ||
| 1392 | // Locale/config changes rebuild the worker index, so cached excerpts may no | ||
| 1393 | // longer match the active result set. | ||
| 1394 | cache.clear() | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | let canceled = false | ||
| 1398 | onCleanup(() => { | ||
| 1399 | canceled = true | ||
| 1400 | }) | ||
| 1401 | |||
| 1402 | excerptBuildToken++ | ||
| 1403 | |||
| 1404 | if (!ready || !isOpen) { | ||
| 1405 | textSearchLoading.value = false | ||
| 1406 | return | ||
| 1407 | } | ||
| 1408 | |||
| 1409 | // In URL search mode, skip normal text search | ||
| 1410 | if (mode === 'url') { | ||
| 1411 | results.value = [] | ||
| 1412 | currentTerms.value = new Set() | ||
| 1413 | enableNoResults.value = Boolean(filterTextValue.trim()) | ||
| 1414 | textSearchLoading.value = false | ||
| 1415 | return | ||
| 1416 | } | ||
| 1417 | |||
| 1418 | const searchQuery = filterTextValue.trim() | ||
| 1419 | textSearchLoading.value = Boolean(searchQuery) | ||
| 1420 | |||
| 1421 | try { | ||
| 1422 | await preloadSearchData(localeIndexValue, indexVersion, configKey) | ||
| 1423 | if (canceled) return | ||
| 1424 | } catch (error) { | ||
| 1425 | if (!canceled) { | ||
| 1426 | console.error('[search] text search index preload failed', error) | ||
| 1427 | results.value = [] | ||
| 1428 | currentTerms.value = new Set() | ||
| 1429 | enableNoResults.value = Boolean(searchQuery) | ||
| 1430 | textSearchLoading.value = false | ||
| 1431 | } | ||
| 1432 | return | ||
| 1433 | } | ||
| 1434 | |||
| 1435 | if (!searchQuery) { | ||
| 1436 | results.value = [] | ||
| 1437 | currentTerms.value = new Set() | ||
| 1438 | enableNoResults.value = false | ||
| 1439 | textSearchLoading.value = false | ||
| 1440 | return | ||
| 1441 | } | ||
| 1442 | |||
| 1443 | let workerPayload: TextSearchWorkerPayload | ||
| 1444 | try { | ||
| 1445 | workerPayload = await postSearchWorker<TextSearchWorkerPayload>({ | ||
| 1446 | type: 'text-search', | ||
| 1447 | query: searchQuery, | ||
| 1448 | mode, | ||
| 1449 | pageOrderEntries: getPageOrderEntries() | ||
| 1450 | }) | ||
| 1451 | } catch (error) { | ||
| 1452 | if (!canceled) { | ||
| 1453 | console.error('[search] text search worker request failed', error) | ||
| 1454 | results.value = [] | ||
| 1455 | currentTerms.value = new Set() | ||
| 1456 | enableNoResults.value = true | ||
| 1457 | textSearchLoading.value = false | ||
| 1458 | } | ||
| 1459 | return | ||
| 1460 | } | ||
| 1461 | if (canceled) return | ||
| 1462 | |||
| 1463 | const _result = workerPayload.results | ||
| 1464 | const terms = new Set(workerPayload.terms) | ||
| 1465 | currentTerms.value = terms | ||
| 1466 | enableNoResults.value = true | ||
| 1467 | |||
| 1468 | if (!_result.length) { | ||
| 1469 | results.value = [] | ||
| 1470 | textSearchLoading.value = false | ||
| 1471 | return | ||
| 1472 | } | ||
| 1473 | |||
| 1474 | const highlight = () => | ||
| 1475 | new Promise<void>((resolve) => { | ||
| 1476 | if (!terms.size || !mark.value) { | ||
| 1477 | resolve() | ||
| 1478 | return | ||
| 1479 | } | ||
| 1480 | mark.value.unmark({ | ||
| 1481 | done: () => { | ||
| 1482 | mark.value?.markRegExp(formMarkRegex(terms), { | ||
| 1483 | done: () => resolve() | ||
| 1484 | }) | ||
| 1485 | } | ||
| 1486 | }) | ||
| 1487 | }) | ||
| 1488 | |||
| 1489 | normalPage.value = 1 | ||
| 1490 | |||
| 1491 | // Show results immediately; excerpts fill in below once built | ||
| 1492 | results.value = toRows(_result) | ||
| 1493 | |||
| 1494 | await nextTick() | ||
| 1495 | if (canceled) return | ||
| 1496 | await highlight() | ||
| 1497 | await nextTick() | ||
| 1498 | await nextFrame() | ||
| 1499 | if (canceled) return | ||
| 1500 | |||
| 1501 | if (resultsEl.value) { | ||
| 1502 | resultsEl.value.scrollTop = 0 | ||
| 1503 | } | ||
| 1504 | centerExcerptsUntilSettled() | ||
| 1505 | |||
| 1506 | if (showDetailedListValue) { | ||
| 1507 | await buildVisibleExcerpts() | ||
| 1508 | if (canceled) return | ||
| 1509 | } | ||
| 1510 | textSearchLoading.value = false | ||
| 1511 | }, | ||
| 1512 | { debounce: 80, immediate: true } | ||
| 1513 | ) | ||
| 1514 | |||
| 1515 | function centerExcerpts() { | ||
| 1516 | const excerpts = el.value?.querySelectorAll('.result .excerpt') ?? [] | ||
| 1517 | for (let i = 0; i < excerpts.length; i++) { | ||
| 1518 | const excerptElement = excerpts[i] as HTMLElement | ||
| 1519 | |||
| 1520 | const markNode = excerptElement.querySelector( | ||
| 1521 | 'mark[data-markjs="true"]' | ||
| 1522 | ) as HTMLElement | null | ||
| 1523 | if (!markNode) continue | ||
| 1524 | |||
| 1525 | const viewportHeight = excerptElement.clientHeight || 84 | ||
| 1526 | |||
| 1527 | let offset = 0 | ||
| 1528 | let node: HTMLElement | null = markNode | ||
| 1529 | while (node && node !== excerptElement) { | ||
| 1530 | offset += node.offsetTop | ||
| 1531 | node = node.offsetParent as HTMLElement | null | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | const targetScrollTop = offset - viewportHeight / 2 + | ||
| 1535 | markNode.offsetHeight / 2 | ||
| 1536 | excerptElement.scrollTop = Math.max(0, targetScrollTop) | ||
| 1537 | } | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | let centerHandle = 0 | ||
| 1541 | |||
| 1542 | function centerExcerptsUntilSettled( | ||
| 1543 | duration = searchAnimationsEnabled.value ? 450 : 0 | ||
| 1544 | ) { | ||
| 1545 | if (centerHandle) cancelAnimationFrame(centerHandle) | ||
| 1546 | |||
| 1547 | if (duration <= 0) { | ||
| 1548 | centerHandle = requestAnimationFrame(() => { | ||
| 1549 | centerExcerpts() | ||
| 1550 | centerHandle = 0 | ||
| 1551 | }) | ||
| 1552 | return | ||
| 1553 | } | ||
| 1554 | |||
| 1555 | const start = performance.now() | ||
| 1556 | const tick = () => { | ||
| 1557 | centerExcerpts() | ||
| 1558 | if (performance.now() - start < duration) { | ||
| 1559 | centerHandle = requestAnimationFrame(tick) | ||
| 1560 | } else { | ||
| 1561 | centerHandle = 0 | ||
| 1562 | } | ||
| 1563 | } | ||
| 1564 | centerHandle = requestAnimationFrame(tick) | ||
| 1565 | } | ||
| 1566 | |||
| 1567 | onBeforeUnmount(() => { | ||
| 1568 | if (centerHandle) cancelAnimationFrame(centerHandle) | ||
| 1569 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) | ||
| 1570 | }) | ||
| 1571 | |||
| 1572 | const excerptCache = new LRUCache<string, unknown>(24) | ||
| 1573 | |||
| 1574 | async function fetchExcerpt(id: string) { | ||
| 1575 | const docId = getDocId(id) | ||
| 1576 | |||
| 1577 | const cached = excerptCache.get(docId) | ||
| 1578 | if (cached) return { id, mod: cached } | ||
| 1579 | |||
| 1580 | const file = pathToFile(docId) | ||
| 1581 | try { | ||
| 1582 | if (!file) throw new Error(`Cannot find file for id: ${id}`) | ||
| 1583 | const mod = await import(/*@vite-ignore*/ file) | ||
| 1584 | |||
| 1585 | excerptCache.set(docId, mod) | ||
| 1586 | |||
| 1587 | return { id, mod } | ||
| 1588 | } catch (e) { | ||
| 1589 | console.error(e) | ||
| 1590 | return { id, mod: {} } | ||
| 1591 | } | ||
| 1592 | } | ||
| 1593 | |||
| 1594 | const nextFrame = () => | ||
| 1595 | new Promise<void>((resolve) => requestAnimationFrame(() => resolve())) | ||
| 1596 | |||
| 1597 | function hasExcerptPreview(html?: string) { | ||
| 1598 | if (!html) return false | ||
| 1599 | for (let i = 0; i < html.length; i++) { | ||
| 1600 | const ch = html[i] | ||
| 1601 | if (ch === '<') { | ||
| 1602 | const close = html.indexOf('>', i + 1) | ||
| 1603 | if (close === -1) return false | ||
| 1604 | i = close | ||
| 1605 | continue | ||
| 1606 | } | ||
| 1607 | if (ch === '&') { | ||
| 1608 | const entity = html.slice(i, i + 6).toLowerCase() | ||
| 1609 | if (entity === ' ' || entity === ' ') { | ||
| 1610 | i += 5 | ||
| 1611 | continue | ||
| 1612 | } | ||
| 1613 | return true | ||
| 1614 | } | ||
| 1615 | if (!/\s/.test(ch)) return true | ||
| 1616 | } | ||
| 1617 | return false | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | /* Search input focus */ | ||
| 1621 | |||
| 1622 | const searchInput = ref<HTMLInputElement>() | ||
| 1623 | const disableReset = computed(() => { | ||
| 1624 | return filterText.value?.length <= 0 | ||
| 1625 | }) | ||
| 1626 | function focusSearchInput(select = true) { | ||
| 1627 | searchInput.value?.focus() | ||
| 1628 | select && searchInput.value?.select() | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | onMounted(() => { | ||
| 1632 | focusSearchInput() | ||
| 1633 | }) | ||
| 1634 | |||
| 1635 | function onSearchBarClick(event: PointerEvent) { | ||
| 1636 | if (event.pointerType === 'mouse') { | ||
| 1637 | focusSearchInput() | ||
| 1638 | } | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | /* Search keyboard selection */ | ||
| 1642 | |||
| 1643 | const selectedIndex = ref(-1) | ||
| 1644 | const disableMouseOver = ref(true) | ||
| 1645 | |||
| 1646 | // Active result list length (URL mode vs normal mode) — current page only | ||
| 1647 | const activeResultsLength = computed(() => | ||
| 1648 | urlSearchMode.value | ||
| 1649 | ? filteredUrlResults.value.length | ||
| 1650 | : pagedResults.value.length | ||
| 1651 | ) | ||
| 1652 | |||
| 1653 | watch(pagedResults, (r) => { | ||
| 1654 | if (!urlSearchMode.value) { | ||
| 1655 | selectedIndex.value = r.length ? 0 : -1 | ||
| 1656 | scrollToSelectedResult() | ||
| 1657 | } | ||
| 1658 | }) | ||
| 1659 | |||
| 1660 | watch(filteredUrlResults, (r) => { | ||
| 1661 | if (urlSearchMode.value) { | ||
| 1662 | selectedIndex.value = r.length ? 0 : -1 | ||
| 1663 | scrollToSelectedResult() | ||
| 1664 | } | ||
| 1665 | }) | ||
| 1666 | |||
| 1667 | watch([pagedResults, filteredUrlResults, faviconsEnabled], () => { | ||
| 1668 | if (!faviconsEnabled.value) return | ||
| 1669 | nextTick(() => { if (resultsEl.value) applyFavicons(resultsEl.value) }) | ||
| 1670 | }) | ||
| 1671 | |||
| 1672 | function scrollToSelectedResult() { | ||
| 1673 | nextTick(() => { | ||
| 1674 | const selectedEl = document.querySelector('.result.selected') | ||
| 1675 | selectedEl?.scrollIntoView({ block: 'nearest' }) | ||
| 1676 | }) | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | function goToSearchPageDelta(delta: number) { | ||
| 1680 | if (urlSearchMode.value) { | ||
| 1681 | const target = urlCurrentPage.value + delta | ||
| 1682 | if (target < 1 || target > urlTotalPages.value) return false | ||
| 1683 | goToUrlPage(target) | ||
| 1684 | return true | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | const target = normalCurrentPage.value + delta | ||
| 1688 | if (target < 1 || target > normalTotalPages.value) return false | ||
| 1689 | goToNormalPage(target) | ||
| 1690 | return true | ||
| 1691 | } | ||
| 1692 | |||
| 1693 | function cyclePageTab(delta: number) { | ||
| 1694 | if (urlSearchMode.value) { | ||
| 1695 | if (urlPageGroups.value.length <= 1) return false | ||
| 1696 | const keys = [null, ...urlPageGroups.value.map((group) => group.key)] | ||
| 1697 | const current = keys.indexOf(urlActivePageFilter.value) | ||
| 1698 | const next = (current + delta + keys.length) % keys.length | ||
| 1699 | setUrlPageFilter(keys[next]) | ||
| 1700 | scrollActivePagePillIntoView(delta) | ||
| 1701 | return true | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | if (pageGroups.value.length <= 1) return false | ||
| 1705 | const keys = [null, ...pageGroups.value.map((group) => group.key)] | ||
| 1706 | const current = keys.indexOf(activePageFilter.value) | ||
| 1707 | const next = (current + delta + keys.length) % keys.length | ||
| 1708 | setPageFilter(keys[next]) | ||
| 1709 | scrollActivePagePillIntoView(delta) | ||
| 1710 | return true | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | onKeyStroke('ArrowUp', (event) => { | ||
| 1714 | event.preventDefault() | ||
| 1715 | selectedIndex.value-- | ||
| 1716 | if (selectedIndex.value < 0) { | ||
| 1717 | selectedIndex.value = activeResultsLength.value - 1 | ||
| 1718 | } | ||
| 1719 | disableMouseOver.value = true | ||
| 1720 | scrollToSelectedResult() | ||
| 1721 | }) | ||
| 1722 | |||
| 1723 | onKeyStroke('ArrowDown', (event) => { | ||
| 1724 | event.preventDefault() | ||
| 1725 | selectedIndex.value++ | ||
| 1726 | if (selectedIndex.value >= activeResultsLength.value + 1) { | ||
| 1727 | selectedIndex.value = 0 | ||
| 1728 | } | ||
| 1729 | disableMouseOver.value = true | ||
| 1730 | scrollToSelectedResult() | ||
| 1731 | }) | ||
| 1732 | |||
| 1733 | onKeyStroke('ArrowLeft', (event) => { | ||
| 1734 | if (!goToSearchPageDelta(-1)) return | ||
| 1735 | event.preventDefault() | ||
| 1736 | disableMouseOver.value = true | ||
| 1737 | }) | ||
| 1738 | |||
| 1739 | onKeyStroke('ArrowRight', (event) => { | ||
| 1740 | if (!goToSearchPageDelta(1)) return | ||
| 1741 | event.preventDefault() | ||
| 1742 | disableMouseOver.value = true | ||
| 1743 | }) | ||
| 1744 | |||
| 1745 | onKeyStroke('Tab', (event) => { | ||
| 1746 | if (!showSearch.value) return | ||
| 1747 | if (!cyclePageTab(event.shiftKey ? -1 : 1)) return | ||
| 1748 | event.preventDefault() | ||
| 1749 | disableMouseOver.value = true | ||
| 1750 | }) | ||
| 1751 | |||
| 1752 | const router = useRouter() | ||
| 1753 | |||
| 1754 | function buildResultHref(pageId: string, tabs?: string[], anchor = '') { | ||
| 1755 | const params: string[] = [] | ||
| 1756 | if (tabs?.length) { | ||
| 1757 | params.push(`t=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`) | ||
| 1758 | } | ||
| 1759 | |||
| 1760 | let hash = '' | ||
| 1761 | if (anchor.startsWith('collapsible-')) { | ||
| 1762 | const collapsible = anchor.slice('collapsible-'.length) | ||
| 1763 | if (collapsible) params.push(`c=${encodeURIComponent(collapsible)}`) | ||
| 1764 | } else { | ||
| 1765 | const lastTab = tabs?.length ? tabs[tabs.length - 1] : '' | ||
| 1766 | const isRedundantTabHeading = Boolean(anchor) && anchor === `tab-${lastTab}` | ||
| 1767 | if (anchor && !isRedundantTabHeading) { | ||
| 1768 | hash = `#${encodeURIComponent(anchor)}` | ||
| 1769 | } | ||
| 1770 | } | ||
| 1771 | |||
| 1772 | const query = params.length ? `?${params.join('&')}` : '' | ||
| 1773 | return `${pageId}${query}${hash}` | ||
| 1774 | } | ||
| 1775 | |||
| 1776 | function getSearchResultHref(item: SearchResult & Result) { | ||
| 1777 | const id = String(item.id) | ||
| 1778 | const hashIndex = id.indexOf('#') | ||
| 1779 | if (hashIndex < 0) return buildResultHref(id, item.tabs) | ||
| 1780 | |||
| 1781 | return buildResultHref( | ||
| 1782 | id.slice(0, hashIndex), | ||
| 1783 | item.tabs, | ||
| 1784 | id.slice(hashIndex + 1) | ||
| 1785 | ) | ||
| 1786 | } | ||
| 1787 | |||
| 1788 | function navigateToUrlResult(item: UrlResult) { | ||
| 1789 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(item.pageId), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean), buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText) | ||
| 1790 | window.dispatchEvent( | ||
| 1791 | new CustomEvent('search-nav', { | ||
| 1792 | detail: { query: filterText.value, resultText: item.linkText } | ||
| 1793 | }) | ||
| 1794 | ) | ||
| 1795 | router.go(buildResultHref(item.pageId, item.tabs, item.anchor)) | ||
| 1796 | showSearch.value = false | ||
| 1797 | } | ||
| 1798 | |||
| 1799 | onKeyStroke('Enter', (e) => { | ||
| 1800 | if (e.isComposing) return | ||
| 1801 | |||
| 1802 | if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') { | ||
| 1803 | return | ||
| 1804 | } | ||
| 1805 | |||
| 1806 | const index = selectedIndex.value - 1 | ||
| 1807 | |||
| 1808 | if (index === -1) { | ||
| 1809 | // @ts-ignore | ||
| 1810 | window.toggleAI({ value: filterText.value }) | ||
| 1811 | showSearch.value = false | ||
| 1812 | return | ||
| 1813 | } | ||
| 1814 | |||
| 1815 | // URL search mode: navigate to the page containing the link (like normal search) | ||
| 1816 | if (urlSearchMode.value) { | ||
| 1817 | const selectedUrl = filteredUrlResults.value[index] | ||
| 1818 | if (selectedUrl) { | ||
| 1819 | navigateToUrlResult(selectedUrl) | ||
| 1820 | } | ||
| 1821 | return | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | const selectedPackage = pagedResults.value[index] | ||
| 1825 | if (e.target instanceof HTMLInputElement && !selectedPackage) { | ||
| 1826 | e.preventDefault() | ||
| 1827 | return | ||
| 1828 | } | ||
| 1829 | |||
| 1830 | if (selectedPackage) { | ||
| 1831 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(selectedPackage.id))), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(selectedPackage), selectedPackage.title) | ||
| 1832 | window.dispatchEvent( | ||
| 1833 | new CustomEvent('search-nav', { | ||
| 1834 | detail: { query: filterText.value, resultText: selectedPackage.title } | ||
| 1835 | }) | ||
| 1836 | ) | ||
| 1837 | router.go(getSearchResultHref(selectedPackage)) | ||
| 1838 | showSearch.value = false | ||
| 1839 | } | ||
| 1840 | }) | ||
| 1841 | |||
| 1842 | function onResultClick(item: SearchResult & Result) { | ||
| 1843 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(item.id))), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(item), item.title) | ||
| 1844 | window.dispatchEvent( | ||
| 1845 | new CustomEvent('search-nav', { | ||
| 1846 | detail: { query: filterText.value, resultText: item.title } | ||
| 1847 | }) | ||
| 1848 | ) | ||
| 1849 | showSearch.value = false | ||
| 1850 | } | ||
| 1851 | |||
| 1852 | onKeyStroke('Escape', () => { | ||
| 1853 | if (showSettingsPopup.value) { | ||
| 1854 | showSettingsPopup.value = false | ||
| 1855 | return | ||
| 1856 | } | ||
| 1857 | showSearch.value = false | ||
| 1858 | }) | ||
| 1859 | |||
| 1860 | // Translations | ||
| 1861 | const defaultTranslations = { | ||
| 1862 | modal: { | ||
| 1863 | displayDetails: 'Display detailed list', | ||
| 1864 | exactMatchTitle: 'Exact search', | ||
| 1865 | resetButtonTitle: 'Reset search', | ||
| 1866 | backButtonTitle: 'Close search', | ||
| 1867 | noResultsText: 'No results for', | ||
| 1868 | footer: { | ||
| 1869 | selectText: 'select', | ||
| 1870 | selectKeyAriaLabel: 'enter', | ||
| 1871 | navigateText: 'navigate', | ||
| 1872 | navigateUpKeyAriaLabel: 'up arrow', | ||
| 1873 | navigateDownKeyAriaLabel: 'down arrow', | ||
| 1874 | switchTabsText: 'switch tabs', | ||
| 1875 | switchTabsKeyAriaLabel: 'shift tab and tab', | ||
| 1876 | switchPagesText: 'switch pages', | ||
| 1877 | switchPagesKeyAriaLabel: 'left and right arrow', | ||
| 1878 | closeText: 'close', | ||
| 1879 | closeKeyAriaLabel: 'escape' | ||
| 1880 | } | ||
| 1881 | } | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | const translate = createSearchTranslate(defaultTranslations) | ||
| 1885 | |||
| 1886 | // Back | ||
| 1887 | |||
| 1888 | onMounted(() => { | ||
| 1889 | // Prevents going to previous site | ||
| 1890 | window.history.pushState(null, '', null) | ||
| 1891 | }) | ||
| 1892 | |||
| 1893 | useEventListener('popstate', (event) => { | ||
| 1894 | event.preventDefault() | ||
| 1895 | showSearch.value = false | ||
| 1896 | }) | ||
| 1897 | |||
| 1898 | /** Lock body */ | ||
| 1899 | const isLocked = useScrollLock(inBrowser ? document.body : null) | ||
| 1900 | |||
| 1901 | watch( | ||
| 1902 | () => showSearch.value, | ||
| 1903 | (val) => { | ||
| 1904 | if (!val) { | ||
| 1905 | isLocked.value = false | ||
| 1906 | return | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | nextTick(() => { | ||
| 1910 | isLocked.value = true | ||
| 1911 | nextTick().then(() => { | ||
| 1912 | activate() | ||
| 1913 | updateRibbonOverflow() | ||
| 1914 | }) | ||
| 1915 | }) | ||
| 1916 | } | ||
| 1917 | ) | ||
| 1918 | |||
| 1919 | function formMarkRegex(terms: Set<string>) { | ||
| 1920 | return new RegExp( | ||
| 1921 | [...terms] | ||
| 1922 | .sort((a, b) => b.length - a.length) | ||
| 1923 | .map((term) => `(${escapeRegExp(term)})`) | ||
| 1924 | .join('|'), | ||
| 1925 | 'gi' | ||
| 1926 | ) | ||
| 1927 | } | ||
| 1928 | |||
| 1929 | function decodeHtml(html: string): string { | ||
| 1930 | const txt = document.createElement('textarea') | ||
| 1931 | txt.innerHTML = html | ||
| 1932 | return txt.value | ||
| 1933 | } | ||
| 1934 | |||
| 1935 | function toHistoryPathHtml(html: string): string { | ||
| 1936 | const stripped = decodeHtml(html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim()) | ||
| 1937 | if (stripped) return escapeHtml(stripped) | ||
| 1938 | return html.trim() | ||
| 1939 | } | ||
| 1940 | |||
| 1941 | function resetSearch() { | ||
| 1942 | filterText.value = '' | ||
| 1943 | nextTick().then(() => focusSearchInput(false)) | ||
| 1944 | } | ||
| 1945 | |||
| 1946 | function onMouseMove(e: MouseEvent) { | ||
| 1947 | if (!disableMouseOver.value) return | ||
| 1948 | const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result') | ||
| 1949 | const index = Number.parseInt(el?.dataset.index!) | ||
| 1950 | if (index >= 0 && index !== selectedIndex.value) { | ||
| 1951 | selectedIndex.value = index | ||
| 1952 | } | ||
| 1953 | disableMouseOver.value = false | ||
| 1954 | } | ||
| 1955 | </script> | ||
| 1956 | |||
| 1957 | <template> | ||
| 1958 | <Teleport to="body"> | ||
| 1959 | <div | ||
| 1960 | ref="el" | ||
| 1961 | role="button" | ||
| 1962 | :aria-owns="results?.length ? 'localsearch-list' : undefined" | ||
| 1963 | aria-expanded="true" | ||
| 1964 | aria-haspopup="listbox" | ||
| 1965 | aria-labelledby="localsearch-label" | ||
| 1966 | class="VPLocalSearchBox" | ||
| 1967 | :class="{ 'pointer-events-none': !showSearch }" | ||
| 1968 | > | ||
| 1969 | <AnimatePresence> | ||
| 1970 | <component | ||
| 1971 | :is="searchMotionDiv" | ||
| 1972 | v-if="showSearch" | ||
| 1973 | class="backdrop" | ||
| 1974 | @click="showSearch = false" | ||
| 1975 | v-bind="backdropMotion" | ||
| 1976 | /> | ||
| 1977 | </AnimatePresence> | ||
| 1978 | |||
| 1979 | <AnimatePresence> | ||
| 1980 | <component | ||
| 1981 | :is="searchMotionDiv" | ||
| 1982 | v-if="showSearch" | ||
| 1983 | class="shell" | ||
| 1984 | v-bind="shellMotion" | ||
| 1985 | > | ||
| 1986 | <component | ||
| 1987 | :is="searchMotionForm" | ||
| 1988 | class="search-bar" | ||
| 1989 | v-bind="formMotion" | ||
| 1990 | @pointerup="onSearchBarClick($event)" | ||
| 1991 | @submit.prevent="" | ||
| 1992 | > | ||
| 1993 | <label | ||
| 1994 | :title="buttonText" | ||
| 1995 | id="localsearch-label" | ||
| 1996 | for="localsearch-input" | ||
| 1997 | > | ||
| 1998 | <span | ||
| 1999 | aria-hidden="true" | ||
| 2000 | class="vpi-search search-icon local-search-icon" | ||
| 2001 | /> | ||
| 2002 | </label> | ||
| 2003 | <div class="search-actions before"> | ||
| 2004 | <button | ||
| 2005 | class="back-button" | ||
| 2006 | :title="translate('modal.backButtonTitle')" | ||
| 2007 | @click="showSearch = false" | ||
| 2008 | > | ||
| 2009 | <span class="vpi-arrow-left local-search-icon" /> | ||
| 2010 | </button> | ||
| 2011 | </div> | ||
| 2012 | <input | ||
| 2013 | ref="searchInput" | ||
| 2014 | v-model="filterText" | ||
| 2015 | :aria-activedescendant="selectedIndex > -1 | ||
| 2016 | ? 'localsearch-item-' + selectedIndex | ||
| 2017 | : undefined" | ||
| 2018 | aria-autocomplete="both" | ||
| 2019 | :aria-controls="results?.length ? 'localsearch-list' : undefined" | ||
| 2020 | aria-labelledby="localsearch-label" | ||
| 2021 | autocapitalize="off" | ||
| 2022 | autocomplete="off" | ||
| 2023 | autocorrect="off" | ||
| 2024 | class="search-input" | ||
| 2025 | id="localsearch-input" | ||
| 2026 | enterkeyhint="go" | ||
| 2027 | maxlength="64" | ||
| 2028 | :placeholder="buttonText" | ||
| 2029 | spellcheck="false" | ||
| 2030 | type="search" | ||
| 2031 | /> | ||
| 2032 | <div class="search-actions"> | ||
| 2033 | <button | ||
| 2034 | v-if="searchLoading" | ||
| 2035 | class="search-loading-button" | ||
| 2036 | type="button" | ||
| 2037 | > | ||
| 2038 | <img | ||
| 2039 | class="search-loading-bubba" | ||
| 2040 | src="/bubba.webp" | ||
| 2041 | alt="Bubba loading" | ||
| 2042 | /> | ||
| 2043 | </button> | ||
| 2044 | <div | ||
| 2045 | v-if="!disableDetailedView && searchMode !== 'url'" | ||
| 2046 | class="view-group toolbar-group" | ||
| 2047 | > | ||
| 2048 | <button | ||
| 2049 | type="button" | ||
| 2050 | class="mode-btn" | ||
| 2051 | :class="{ 'mode-active': showDetailedList }" | ||
| 2052 | title="Detail view (Consumes more RAM)" | ||
| 2053 | @click="showDetailedList | ||
| 2054 | ? showDetailedList = false | ||
| 2055 | : showDetailedList = true" | ||
| 2056 | > | ||
| 2057 | <TextAlignStart :size="18" stroke-width="2" /> | ||
| 2058 | </button> | ||
| 2059 | <button | ||
| 2060 | type="button" | ||
| 2061 | class="mode-btn" | ||
| 2062 | :class="{ 'mode-active': !showDetailedList }" | ||
| 2063 | title="List view (Consumes less RAM)" | ||
| 2064 | @click="!showDetailedList | ||
| 2065 | ? showDetailedList = true | ||
| 2066 | : showDetailedList = false" | ||
| 2067 | > | ||
| 2068 | <List :size="18" stroke-width="2" /> | ||
| 2069 | </button> | ||
| 2070 | </div> | ||
| 2071 | <div class="search-mode-group toolbar-group"> | ||
| 2072 | <button | ||
| 2073 | type="button" | ||
| 2074 | class="mode-btn" | ||
| 2075 | :class="{ 'mode-active': searchMode === 'exact' }" | ||
| 2076 | title="Exact search" | ||
| 2077 | @click="searchMode === 'exact' | ||
| 2078 | ? cycleSearchMode() | ||
| 2079 | : searchMode = 'exact'" | ||
| 2080 | > | ||
| 2081 | <Regex :size="18" stroke-width="2" /> | ||
| 2082 | </button> | ||
| 2083 | <button | ||
| 2084 | type="button" | ||
| 2085 | class="mode-btn" | ||
| 2086 | :class="{ 'mode-active': searchMode === 'fuzzy' }" | ||
| 2087 | title="Fuzzy search" | ||
| 2088 | @click="searchMode === 'fuzzy' | ||
| 2089 | ? cycleSearchMode() | ||
| 2090 | : searchMode = 'fuzzy'" | ||
| 2091 | > | ||
| 2092 | <LocateOff :size="18" stroke-width="2" /> | ||
| 2093 | </button> | ||
| 2094 | <button | ||
| 2095 | type="button" | ||
| 2096 | class="mode-btn" | ||
| 2097 | :class="{ 'mode-active': searchMode === 'url' }" | ||
| 2098 | title="URL search" | ||
| 2099 | @click="searchMode === 'url' | ||
| 2100 | ? cycleSearchMode() | ||
| 2101 | : searchMode = 'url'" | ||
| 2102 | > | ||
| 2103 | <Globe :size="18" stroke-width="2" /> | ||
| 2104 | </button> | ||
| 2105 | </div> | ||
| 2106 | <button | ||
| 2107 | ref="settingsButtonRef" | ||
| 2108 | type="button" | ||
| 2109 | class="mode-btn settings-toggle-btn" | ||
| 2110 | :class="{ 'mode-active': showSettingsPopup }" | ||
| 2111 | title="Search settings" | ||
| 2112 | @click.stop="showSettingsPopup = !showSettingsPopup" | ||
| 2113 | > | ||
| 2114 | <Settings :size="18" stroke-width="2" /> | ||
| 2115 | </button> | ||
| 2116 | <button | ||
| 2117 | class="clear-button" | ||
| 2118 | type="reset" | ||
| 2119 | :disabled="disableReset" | ||
| 2120 | :title="translate('modal.resetButtonTitle')" | ||
| 2121 | @click="resetSearch" | ||
| 2122 | > | ||
| 2123 | <X :size="18" stroke-width="2" /> | ||
| 2124 | </button> | ||
| 2125 | </div> | ||
| 2126 | </component> | ||
| 2127 | |||
| 2128 | <AnimatePresence> | ||
| 2129 | <component | ||
| 2130 | :is="searchMotionDiv" | ||
| 2131 | v-if="urlSearchMode | ||
| 2132 | ? urlPageGroups.length > 1 | ||
| 2133 | : pageGroups.length > 1" | ||
| 2134 | class="page-ribbon" | ||
| 2135 | :class="{ | ||
| 2136 | 'can-scroll-left': ribbonCanScrollLeft, | ||
| 2137 | 'can-scroll-right': ribbonCanScrollRight | ||
| 2138 | }" | ||
| 2139 | v-bind="ribbonMotion" | ||
| 2140 | > | ||
| 2141 | <button | ||
| 2142 | v-if="ribbonCanScrollLeft" | ||
| 2143 | type="button" | ||
| 2144 | class="page-ribbon-arrow left" | ||
| 2145 | aria-label="Scroll filters left" | ||
| 2146 | @click="scrollRibbon(-1)" | ||
| 2147 | > | ||
| 2148 | <ChevronRight :size="18" stroke-width="1.75" /> | ||
| 2149 | </button> | ||
| 2150 | <div | ||
| 2151 | ref="ribbonTrack" | ||
| 2152 | class="page-ribbon-track" | ||
| 2153 | @scroll="updateRibbonOverflow" | ||
| 2154 | > | ||
| 2155 | <!-- URL mode tabs --> | ||
| 2156 | <template v-if="urlSearchMode"> | ||
| 2157 | <button | ||
| 2158 | type="button" | ||
| 2159 | class="page-pill" | ||
| 2160 | :class="{ | ||
| 2161 | active: urlActivePageFilter === null | ||
| 2162 | }" | ||
| 2163 | @click="setUrlPageFilter(null)" | ||
| 2164 | > | ||
| 2165 | All | ||
| 2166 | <span class="page-pill-count">{{ urlMatches.length }}</span> | ||
| 2167 | </button> | ||
| 2168 | <button | ||
| 2169 | v-for="group in urlPageGroups" | ||
| 2170 | :key="group.key" | ||
| 2171 | type="button" | ||
| 2172 | class="page-pill" | ||
| 2173 | :class="{ | ||
| 2174 | active: | ||
| 2175 | urlActivePageFilter === group.key | ||
| 2176 | }" | ||
| 2177 | @click="setUrlPageFilter(group.key)" | ||
| 2178 | > | ||
| 2179 | <span class="page-pill-label">{{ group.label }}</span> | ||
| 2180 | <span class="page-pill-count">{{ group.count }}</span> | ||
| 2181 | </button> | ||
| 2182 | </template> | ||
| 2183 | <!-- Normal mode tabs --> | ||
| 2184 | <template v-else> | ||
| 2185 | <button | ||
| 2186 | type="button" | ||
| 2187 | class="page-pill" | ||
| 2188 | :class="{ active: activePageFilter === null }" | ||
| 2189 | @click="setPageFilter(null)" | ||
| 2190 | > | ||
| 2191 | All | ||
| 2192 | <span class="page-pill-count">{{ results.length }}</span> | ||
| 2193 | </button> | ||
| 2194 | <button | ||
| 2195 | v-for="group in pageGroups" | ||
| 2196 | :key="group.key" | ||
| 2197 | type="button" | ||
| 2198 | class="page-pill" | ||
| 2199 | :class="{ | ||
| 2200 | active: activePageFilter === group.key | ||
| 2201 | }" | ||
| 2202 | @click="setPageFilter(group.key)" | ||
| 2203 | > | ||
| 2204 | <span class="page-pill-label">{{ group.label }}</span> | ||
| 2205 | <span class="page-pill-count">{{ group.count }}</span> | ||
| 2206 | </button> | ||
| 2207 | </template> | ||
| 2208 | </div> | ||
| 2209 | <button | ||
| 2210 | v-if="ribbonCanScrollRight" | ||
| 2211 | type="button" | ||
| 2212 | class="page-ribbon-arrow right" | ||
| 2213 | aria-label="Scroll filters right" | ||
| 2214 | @click="scrollRibbon(1)" | ||
| 2215 | > | ||
| 2216 | <ChevronRight :size="18" stroke-width="1.75" /> | ||
| 2217 | </button> | ||
| 2218 | </component> | ||
| 2219 | </AnimatePresence> | ||
| 2220 | |||
| 2221 | <ul | ||
| 2222 | ref="resultsEl" | ||
| 2223 | :id="results?.length ? 'localsearch-list' : undefined" | ||
| 2224 | :role="results?.length ? 'listbox' : undefined" | ||
| 2225 | :aria-labelledby="results?.length ? 'localsearch-label' : undefined" | ||
| 2226 | class="results" | ||
| 2227 | @mousemove="onMouseMove" | ||
| 2228 | > | ||
| 2229 | <!-- Empty state (shared) --> | ||
| 2230 | <AnimatePresence> | ||
| 2231 | <component | ||
| 2232 | :is="searchMotionDiv" | ||
| 2233 | v-if="!showHistory && (urlSearchMode | ||
| 2234 | ? (!filterText || !urlMatches.length) | ||
| 2235 | : (!filterText || !filteredResults.length))" | ||
| 2236 | 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" | ||
| 2237 | v-bind="emptyStateMotion" | ||
| 2238 | > | ||
| 2239 | <img | ||
| 2240 | class="h-40 object-contain object-center" | ||
| 2241 | src="/asset/smolame.png" | ||
| 2242 | alt="Smol ame" | ||
| 2243 | /> | ||
| 2244 | <h1 v-if="filterText">Couldn't find anything, try again?</h1> | ||
| 2245 | <h1 v-else>Looking for something?</h1> | ||
| 2246 | </component> | ||
| 2247 | </AnimatePresence> | ||
| 2248 | |||
| 2249 | <!-- Search history --> | ||
| 2250 | <AnimatePresence> | ||
| 2251 | <component | ||
| 2252 | :is="searchMotionDiv" | ||
| 2253 | v-if="showHistory" | ||
| 2254 | class="history-list" | ||
| 2255 | v-bind="emptyStateMotion" | ||
| 2256 | > | ||
| 2257 | <div class="history-header"> | ||
| 2258 | <span>Recent searches</span> | ||
| 2259 | <button | ||
| 2260 | class="history-clear-all" | ||
| 2261 | title="Clear all history" | ||
| 2262 | @click.stop="searchHistory = []" | ||
| 2263 | > | ||
| 2264 | <X :size="16" stroke-width="2" /> | ||
| 2265 | </button> | ||
| 2266 | </div> | ||
| 2267 | <ul class="history-items"> | ||
| 2268 | <li | ||
| 2269 | v-for="(entry, index) in searchHistory" | ||
| 2270 | :key="index" | ||
| 2271 | class="history-item" | ||
| 2272 | @click="applyHistory(entry)" | ||
| 2273 | > | ||
| 2274 | <div class="history-main"> | ||
| 2275 | <span class="history-query">{{ entry.query }}</span> | ||
| 2276 | <template v-if="entry.path?.length"> | ||
| 2277 | <ArrowRight :size="13" stroke-width="1.5" class="history-arrow" /> | ||
| 2278 | <template v-for="(seg, si) in entry.path" :key="si"> | ||
| 2279 | <span | ||
| 2280 | class="history-path-seg" | ||
| 2281 | :class="{ | ||
| 2282 | 'history-path-end': si === entry.path.length - 1, | ||
| 2283 | 'history-path-only': entry.path.length === 1 | ||
| 2284 | }" | ||
| 2285 | v-html="seg" | ||
| 2286 | /> | ||
| 2287 | <span v-if="si < entry.path.length - 1" class="history-path-sep">›</span> | ||
| 2288 | </template> | ||
| 2289 | </template> | ||
| 2290 | </div> | ||
| 2291 | <component | ||
| 2292 | :is="entry.mode === 'exact' ? Regex : entry.mode === 'fuzzy' ? LocateOff : Globe" | ||
| 2293 | :size="14" | ||
| 2294 | stroke-width="2" | ||
| 2295 | class="history-mode-icon" | ||
| 2296 | /> | ||
| 2297 | <button | ||
| 2298 | class="history-remove" | ||
| 2299 | :title="'Remove \'' + entry.query + '\' from history'" | ||
| 2300 | @click.stop="removeFromHistory(index)" | ||
| 2301 | > | ||
| 2302 | <X :size="16" stroke-width="2" /> | ||
| 2303 | </button> | ||
| 2304 | </li> | ||
| 2305 | </ul> | ||
| 2306 | </component> | ||
| 2307 | </AnimatePresence> | ||
| 2308 | |||
| 2309 | <!-- URL search results --> | ||
| 2310 | <template v-if="urlSearchMode"> | ||
| 2311 | <AnimatePresence> | ||
| 2312 | <component | ||
| 2313 | :is="searchMotionLi" | ||
| 2314 | v-for="(item, index) in filteredUrlResults" | ||
| 2315 | :key="'url-' + urlCurrentPage + '-' + | ||
| 2316 | item.pageId + '-' + | ||
| 2317 | item.anchor + '-' + index" | ||
| 2318 | class="result-layout" | ||
| 2319 | :id="'localsearch-item-' + (index + 1)" | ||
| 2320 | :aria-selected="selectedIndex === index + 1 | ||
| 2321 | ? 'true' | ||
| 2322 | : 'false'" | ||
| 2323 | role="option" | ||
| 2324 | v-bind="resultMotion(index)" | ||
| 2325 | > | ||
| 2326 | <div | ||
| 2327 | class="result url-result-card" | ||
| 2328 | :class="{ | ||
| 2329 | selected: selectedIndex === index + 1 | ||
| 2330 | }" | ||
| 2331 | :aria-label="item.href" | ||
| 2332 | role="button" | ||
| 2333 | @mouseenter="!disableMouseOver && | ||
| 2334 | (selectedIndex = index + 1)" | ||
| 2335 | @focusin="selectedIndex = index + 1" | ||
| 2336 | @click="navigateToUrlResult(item)" | ||
| 2337 | :data-index="index + 1" | ||
| 2338 | > | ||
| 2339 | <div class="url-result-body"> | ||
| 2340 | <div class="url-path"> | ||
| 2341 | <Hash | ||
| 2342 | v-if="item.anchor || | ||
| 2343 | item.titles.length > 0" | ||
| 2344 | stroke-width="2" | ||
| 2345 | :size="18" | ||
| 2346 | /> | ||
| 2347 | <File v-else stroke-width="2" :size="18" /> | ||
| 2348 | <span | ||
| 2349 | v-for="(t, ti) in item.titles" | ||
| 2350 | :key="ti" | ||
| 2351 | class="url-path-segment" | ||
| 2352 | > | ||
| 2353 | <span class="text" v-html="t" /> | ||
| 2354 | <ArrowRight | ||
| 2355 | stroke-width="2" | ||
| 2356 | :size="18" | ||
| 2357 | class="mx-0.5" | ||
| 2358 | /> | ||
| 2359 | </span> | ||
| 2360 | <span | ||
| 2361 | v-if="item.linkText" | ||
| 2362 | class="url-path-current" | ||
| 2363 | v-html="item.linkText" | ||
| 2364 | /> | ||
| 2365 | </div> | ||
| 2366 | <a | ||
| 2367 | :href="item.href" | ||
| 2368 | target="_blank" | ||
| 2369 | rel="noopener noreferrer" | ||
| 2370 | class="url-link" | ||
| 2371 | :title="item.href" | ||
| 2372 | @click.stop | ||
| 2373 | v-html="item.highlighted" | ||
| 2374 | > | ||
| 2375 | </a> | ||
| 2376 | </div> | ||
| 2377 | </div> | ||
| 2378 | </component> | ||
| 2379 | </AnimatePresence> | ||
| 2380 | </template> | ||
| 2381 | |||
| 2382 | <!-- Normal search results --> | ||
| 2383 | <template v-else> | ||
| 2384 | <AnimatePresence> | ||
| 2385 | <component | ||
| 2386 | :is="searchMotionLi" | ||
| 2387 | v-for="(p, index) in pagedResults" | ||
| 2388 | :key="'normal-' + normalCurrentPage + '-' + p.id" | ||
| 2389 | class="result-layout" | ||
| 2390 | :id="'localsearch-item-' + (index + 1)" | ||
| 2391 | :aria-selected="selectedIndex === index + 1 | ||
| 2392 | ? 'true' | ||
| 2393 | : 'false'" | ||
| 2394 | role="option" | ||
| 2395 | v-bind="resultMotion(index)" | ||
| 2396 | > | ||
| 2397 | <a | ||
| 2398 | :href="getSearchResultHref(p)" | ||
| 2399 | class="result" | ||
| 2400 | :class="{ | ||
| 2401 | selected: selectedIndex === index + 1 | ||
| 2402 | }" | ||
| 2403 | :aria-label="[...p.titles, p.title].join(' > ')" | ||
| 2404 | @mouseenter="!disableMouseOver && | ||
| 2405 | (selectedIndex = index + 1)" | ||
| 2406 | @focusin="selectedIndex = index + 1" | ||
| 2407 | @click="onResultClick(p)" | ||
| 2408 | :data-index="index + 1" | ||
| 2409 | > | ||
| 2410 | <div> | ||
| 2411 | <div class="titles"> | ||
| 2412 | <Hash | ||
| 2413 | v-if="getDocAnchor(p.id) || | ||
| 2414 | p.titles.length > 0" | ||
| 2415 | stroke-width="2" | ||
| 2416 | :size="18" | ||
| 2417 | /> | ||
| 2418 | <File v-else stroke-width="2" :size="18" /> | ||
| 2419 | <span | ||
| 2420 | v-for="(t, index) in p.titles" | ||
| 2421 | :key="index" | ||
| 2422 | class="title" | ||
| 2423 | > | ||
| 2424 | <span class="text" v-html="t" /> | ||
| 2425 | <ArrowRight | ||
| 2426 | stroke-width="2" | ||
| 2427 | :size="18" | ||
| 2428 | class="mx-0.5" | ||
| 2429 | /> | ||
| 2430 | </span> | ||
| 2431 | <span class="title main"> | ||
| 2432 | <span class="text" v-html="p.title" /> | ||
| 2433 | </span> | ||
| 2434 | </div> | ||
| 2435 | |||
| 2436 | <div | ||
| 2437 | v-if="showDetailedList && | ||
| 2438 | hasExcerptPreview(p.text)" | ||
| 2439 | class="excerpt-wrapper" | ||
| 2440 | > | ||
| 2441 | <component | ||
| 2442 | :is="searchMotionDiv" | ||
| 2443 | class="excerpt" | ||
| 2444 | inert | ||
| 2445 | v-bind="excerptMotion" | ||
| 2446 | > | ||
| 2447 | <div class="vp-doc" v-html="p.text" /> | ||
| 2448 | </component> | ||
| 2449 | <div class="excerpt-gradient-bottom" /> | ||
| 2450 | <div class="excerpt-gradient-top" /> | ||
| 2451 | </div> | ||
| 2452 | </div> | ||
| 2453 | </a> | ||
| 2454 | </component> | ||
| 2455 | </AnimatePresence> | ||
| 2456 | </template> | ||
| 2457 | </ul> | ||
| 2458 | |||
| 2459 | <!-- Bottom section: pagination (when needed). Always rendered so the | ||
| 2460 | shell's rounded bottom edge stays consistent. --> | ||
| 2461 | <nav | ||
| 2462 | class="url-pagination" | ||
| 2463 | aria-label="Search result pages" | ||
| 2464 | > | ||
| 2465 | <div | ||
| 2466 | v-if="(urlSearchMode | ||
| 2467 | ? urlTotalPages | ||
| 2468 | : normalTotalPages) > 1" | ||
| 2469 | class="url-pagination-segment" | ||
| 2470 | > | ||
| 2471 | <button | ||
| 2472 | type="button" | ||
| 2473 | class="url-page-btn url-page-nav" | ||
| 2474 | :disabled="(urlSearchMode | ||
| 2475 | ? urlCurrentPage | ||
| 2476 | : normalCurrentPage) <= 1" | ||
| 2477 | aria-label="Previous page" | ||
| 2478 | @click="urlSearchMode | ||
| 2479 | ? goToUrlPage(urlCurrentPage - 1) | ||
| 2480 | : goToNormalPage(normalCurrentPage - 1)" | ||
| 2481 | > | ||
| 2482 | <ChevronRight | ||
| 2483 | :size="14" | ||
| 2484 | stroke-width="2" | ||
| 2485 | style="transform: rotate(180deg)" | ||
| 2486 | /> | ||
| 2487 | </button> | ||
| 2488 | |||
| 2489 | <template | ||
| 2490 | v-for="(p, pi) in urlSearchMode ? urlPageList : normalPageList" | ||
| 2491 | :key="pi" | ||
| 2492 | > | ||
| 2493 | <span v-if="p === '…'" class="url-page-ellipsis">…</span> | ||
| 2494 | <button | ||
| 2495 | v-else | ||
| 2496 | type="button" | ||
| 2497 | class="url-page-btn" | ||
| 2498 | :class="{ | ||
| 2499 | active: p === (urlSearchMode | ||
| 2500 | ? urlCurrentPage | ||
| 2501 | : normalCurrentPage) | ||
| 2502 | }" | ||
| 2503 | :aria-current="p === (urlSearchMode | ||
| 2504 | ? urlCurrentPage | ||
| 2505 | : normalCurrentPage) | ||
| 2506 | ? 'page' | ||
| 2507 | : undefined" | ||
| 2508 | @click="urlSearchMode | ||
| 2509 | ? goToUrlPage(p as number) | ||
| 2510 | : goToNormalPage(p as number)" | ||
| 2511 | > | ||
| 2512 | {{ p }} | ||
| 2513 | </button> | ||
| 2514 | </template> | ||
| 2515 | |||
| 2516 | <button | ||
| 2517 | type="button" | ||
| 2518 | class="url-page-btn url-page-nav" | ||
| 2519 | :disabled="(urlSearchMode | ||
| 2520 | ? urlCurrentPage | ||
| 2521 | : normalCurrentPage) >= | ||
| 2522 | (urlSearchMode | ||
| 2523 | ? urlTotalPages | ||
| 2524 | : normalTotalPages)" | ||
| 2525 | aria-label="Next page" | ||
| 2526 | @click="urlSearchMode | ||
| 2527 | ? goToUrlPage(urlCurrentPage + 1) | ||
| 2528 | : goToNormalPage(normalCurrentPage + 1)" | ||
| 2529 | > | ||
| 2530 | <ChevronRight :size="14" stroke-width="2" /> | ||
| 2531 | </button> | ||
| 2532 | </div> | ||
| 2533 | </nav> | ||
| 2534 | |||
| 2535 | <component | ||
| 2536 | :is="searchMotionDiv" | ||
| 2537 | v-if="showKeyboardShortcuts" | ||
| 2538 | class="search-keyboard-shortcuts" | ||
| 2539 | v-bind="footerMotion" | ||
| 2540 | > | ||
| 2541 | <span> | ||
| 2542 | <kbd | ||
| 2543 | :aria-label="translate( | ||
| 2544 | 'modal.footer.navigateUpKeyAriaLabel' | ||
| 2545 | )" | ||
| 2546 | > | ||
| 2547 | <span class="vpi-arrow-up navigate-icon" /> | ||
| 2548 | </kbd> | ||
| 2549 | <kbd | ||
| 2550 | :aria-label="translate( | ||
| 2551 | 'modal.footer.navigateDownKeyAriaLabel' | ||
| 2552 | )" | ||
| 2553 | > | ||
| 2554 | <span class="vpi-arrow-down navigate-icon" /> | ||
| 2555 | </kbd> | ||
| 2556 | {{ translate('modal.footer.navigateText') }} | ||
| 2557 | </span> | ||
| 2558 | <span> | ||
| 2559 | <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')"> | ||
| 2560 | <ArrowLeftToLine class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 2561 | </kbd> | ||
| 2562 | <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')"> | ||
| 2563 | <ArrowRightToLine class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 2564 | </kbd> | ||
| 2565 | {{ translate('modal.footer.switchTabsText') }} | ||
| 2566 | </span> | ||
| 2567 | <span> | ||
| 2568 | <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')"> | ||
| 2569 | <ArrowLeft class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 2570 | </kbd> | ||
| 2571 | <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')"> | ||
| 2572 | <ArrowRight class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 2573 | </kbd> | ||
| 2574 | {{ translate('modal.footer.switchPagesText') }} | ||
| 2575 | </span> | ||
| 2576 | <span> | ||
| 2577 | <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')"> | ||
| 2578 | <span class="vpi-corner-down-left navigate-icon" /> | ||
| 2579 | </kbd> | ||
| 2580 | {{ translate('modal.footer.selectText') }} | ||
| 2581 | </span> | ||
| 2582 | <span> | ||
| 2583 | <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')"> | ||
| 2584 | esc | ||
| 2585 | </kbd> | ||
| 2586 | {{ translate('modal.footer.closeText') }} | ||
| 2587 | </span> | ||
| 2588 | </component> | ||
| 2589 | <Teleport to="body"> | ||
| 2590 | <Transition name="settings-popup"> | ||
| 2591 | <div | ||
| 2592 | v-if="showSettingsPopup" | ||
| 2593 | ref="settingsPopupRef" | ||
| 2594 | class="search-settings-popup" | ||
| 2595 | :style="settingsPopupStyle" | ||
| 2596 | @click="activeHelpSection = null" | ||
| 2597 | > | ||
| 2598 | <div class="settings-section"> | ||
| 2599 | <div class="settings-section-header"> | ||
| 2600 | <div class="settings-section-label"> | ||
| 2601 | <Search :size="14" stroke-width="1.75" /> | ||
| 2602 | Search | ||
| 2603 | </div> | ||
| 2604 | <button | ||
| 2605 | type="button" | ||
| 2606 | class="settings-help-btn" | ||
| 2607 | :class="{ active: activeHelpSection === 'search' }" | ||
| 2608 | aria-label="Search mode help" | ||
| 2609 | @click.stop="toggleHelpSection('search', $event)" | ||
| 2610 | @mouseenter="onHelpEnter('search', $event)" | ||
| 2611 | @mouseleave="onHelpLeave" | ||
| 2612 | > | ||
| 2613 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 2614 | </button> | ||
| 2615 | </div> | ||
| 2616 | <div | ||
| 2617 | class="settings-options" | ||
| 2618 | :class="{ 'is-highlighted': activeHelpSection === 'search' }" | ||
| 2619 | > | ||
| 2620 | <button | ||
| 2621 | type="button" | ||
| 2622 | class="settings-option" | ||
| 2623 | :class="{ active: searchMode === 'exact' }" | ||
| 2624 | @click="searchMode = 'exact'" | ||
| 2625 | > | ||
| 2626 | <span>Exact</span> | ||
| 2627 | </button> | ||
| 2628 | <button | ||
| 2629 | type="button" | ||
| 2630 | class="settings-option" | ||
| 2631 | :class="{ active: searchMode === 'fuzzy' }" | ||
| 2632 | @click="searchMode = 'fuzzy'" | ||
| 2633 | > | ||
| 2634 | <span>Fuzzy</span> | ||
| 2635 | </button> | ||
| 2636 | <button | ||
| 2637 | type="button" | ||
| 2638 | class="settings-option" | ||
| 2639 | :class="{ active: searchMode === 'url' }" | ||
| 2640 | @click="searchMode = 'url'" | ||
| 2641 | > | ||
| 2642 | <span>URL</span> | ||
| 2643 | </button> | ||
| 2644 | </div> | ||
| 2645 | </div> | ||
| 2646 | <div | ||
| 2647 | v-if="!disableDetailedView && searchMode !== 'url'" | ||
| 2648 | class="settings-section" | ||
| 2649 | > | ||
| 2650 | <div class="settings-section-header"> | ||
| 2651 | <div class="settings-section-label"> | ||
| 2652 | <LayoutList :size="14" stroke-width="1.75" /> | ||
| 2653 | View | ||
| 2654 | </div> | ||
| 2655 | <button | ||
| 2656 | type="button" | ||
| 2657 | class="settings-help-btn" | ||
| 2658 | :class="{ active: activeHelpSection === 'view' }" | ||
| 2659 | aria-label="Result view help" | ||
| 2660 | @click.stop="toggleHelpSection('view', $event)" | ||
| 2661 | @mouseenter="onHelpEnter('view', $event)" | ||
| 2662 | @mouseleave="onHelpLeave" | ||
| 2663 | > | ||
| 2664 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 2665 | </button> | ||
| 2666 | </div> | ||
| 2667 | <div | ||
| 2668 | class="settings-options" | ||
| 2669 | :class="{ 'is-highlighted': activeHelpSection === 'view' }" | ||
| 2670 | > | ||
| 2671 | <button | ||
| 2672 | type="button" | ||
| 2673 | class="settings-option" | ||
| 2674 | :class="{ active: showDetailedList }" | ||
| 2675 | @click="showDetailedList = true" | ||
| 2676 | > | ||
| 2677 | <span>Detail</span> | ||
| 2678 | </button> | ||
| 2679 | <button | ||
| 2680 | type="button" | ||
| 2681 | class="settings-option" | ||
| 2682 | :class="{ active: !showDetailedList }" | ||
| 2683 | @click="showDetailedList = false" | ||
| 2684 | > | ||
| 2685 | <span>List</span> | ||
| 2686 | </button> | ||
| 2687 | </div> | ||
| 2688 | </div> | ||
| 2689 | <div | ||
| 2690 | v-if="!disableDetailedView && searchMode !== 'url' && | ||
| 2691 | showDetailedList" | ||
| 2692 | class="settings-section" | ||
| 2693 | > | ||
| 2694 | <div class="settings-section-header"> | ||
| 2695 | <div class="settings-section-label"> | ||
| 2696 | <Layers :size="14" stroke-width="1.75" /> | ||
| 2697 | Preload | ||
| 2698 | </div> | ||
| 2699 | <button | ||
| 2700 | type="button" | ||
| 2701 | class="settings-help-btn" | ||
| 2702 | :class="{ active: activeHelpSection === 'preload' }" | ||
| 2703 | aria-label="Excerpt preload help" | ||
| 2704 | @click.stop="toggleHelpSection('preload', $event)" | ||
| 2705 | @mouseenter="onHelpEnter('preload', $event)" | ||
| 2706 | @mouseleave="onHelpLeave" | ||
| 2707 | > | ||
| 2708 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 2709 | </button> | ||
| 2710 | </div> | ||
| 2711 | <div | ||
| 2712 | class="settings-options" | ||
| 2713 | :class="{ 'is-highlighted': activeHelpSection === 'preload' }" | ||
| 2714 | > | ||
| 2715 | <button | ||
| 2716 | type="button" | ||
| 2717 | class="settings-option" | ||
| 2718 | :class="{ active: excerptPreload === 'all' }" | ||
| 2719 | @click="excerptPreload = 'all'" | ||
| 2720 | > | ||
| 2721 | <span>All</span> | ||
| 2722 | </button> | ||
| 2723 | <button | ||
| 2724 | type="button" | ||
| 2725 | class="settings-option" | ||
| 2726 | :class="{ active: excerptPreload === 'next' }" | ||
| 2727 | @click="excerptPreload = 'next'" | ||
| 2728 | > | ||
| 2729 | <span>Next</span> | ||
| 2730 | </button> | ||
| 2731 | <button | ||
| 2732 | type="button" | ||
| 2733 | class="settings-option" | ||
| 2734 | :class="{ active: excerptPreload === 'off' }" | ||
| 2735 | @click="excerptPreload = 'off'" | ||
| 2736 | > | ||
| 2737 | <span>Off</span> | ||
| 2738 | </button> | ||
| 2739 | </div> | ||
| 2740 | </div> | ||
| 2741 | <div class="settings-section"> | ||
| 2742 | <div class="settings-section-header"> | ||
| 2743 | <div class="settings-section-label"> | ||
| 2744 | <Highlighter :size="14" stroke-width="1.75" /> | ||
| 2745 | Highlight | ||
| 2746 | </div> | ||
| 2747 | <button | ||
| 2748 | type="button" | ||
| 2749 | class="settings-help-btn" | ||
| 2750 | :class="{ active: activeHelpSection === 'highlight' }" | ||
| 2751 | aria-label="Search result highlight help" | ||
| 2752 | @click.stop="toggleHelpSection('highlight', $event)" | ||
| 2753 | @mouseenter="onHelpEnter('highlight', $event)" | ||
| 2754 | @mouseleave="onHelpLeave" | ||
| 2755 | > | ||
| 2756 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 2757 | </button> | ||
| 2758 | </div> | ||
| 2759 | <div | ||
| 2760 | class="settings-options" | ||
| 2761 | :class="{ 'is-highlighted': activeHelpSection === 'highlight' }" | ||
| 2762 | > | ||
| 2763 | <button | ||
| 2764 | type="button" | ||
| 2765 | class="settings-option" | ||
| 2766 | :class="{ active: searchResultHighlightMode === 'soft' }" | ||
| 2767 | @click="searchResultHighlightMode = 'soft'" | ||
| 2768 | > | ||
| 2769 | <span>Soft</span> | ||
| 2770 | </button> | ||
| 2771 | <button | ||
| 2772 | type="button" | ||
| 2773 | class="settings-option" | ||
| 2774 | :class="{ active: searchResultHighlightMode === 'solid' }" | ||
| 2775 | @click="searchResultHighlightMode = 'solid'" | ||
| 2776 | > | ||
| 2777 | <span>Solid</span> | ||
| 2778 | </button> | ||
| 2779 | <button | ||
| 2780 | type="button" | ||
| 2781 | class="settings-option" | ||
| 2782 | :class="{ active: searchResultHighlightMode === 'off' }" | ||
| 2783 | @click="searchResultHighlightMode = 'off'" | ||
| 2784 | > | ||
| 2785 | <span>Off</span> | ||
| 2786 | </button> | ||
| 2787 | </div> | ||
| 2788 | </div> | ||
| 2789 | <div class="settings-section"> | ||
| 2790 | <div class="settings-section-header"> | ||
| 2791 | <div class="settings-section-label"> | ||
| 2792 | <Clock :size="14" stroke-width="1.75" /> | ||
| 2793 | History | ||
| 2794 | </div> | ||
| 2795 | <button | ||
| 2796 | type="button" | ||
| 2797 | class="settings-help-btn" | ||
| 2798 | :class="{ active: activeHelpSection === 'history' }" | ||
| 2799 | aria-label="Search history help" | ||
| 2800 | @click.stop="toggleHelpSection('history', $event)" | ||
| 2801 | @mouseenter="onHelpEnter('history', $event)" | ||
| 2802 | @mouseleave="onHelpLeave" | ||
| 2803 | > | ||
| 2804 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 2805 | </button> | ||
| 2806 | </div> | ||
| 2807 | <div | ||
| 2808 | class="settings-options" | ||
| 2809 | :class="{ 'is-highlighted': activeHelpSection === 'history' }" | ||
| 2810 | > | ||
| 2811 | <button | ||
| 2812 | type="button" | ||
| 2813 | class="settings-option" | ||
| 2814 | :class="{ active: saveHistoryEnabled }" | ||
| 2815 | @click="saveHistoryEnabled = true" | ||
| 2816 | > | ||
| 2817 | <span>On</span> | ||
| 2818 | </button> | ||
| 2819 | <button | ||
| 2820 | type="button" | ||
| 2821 | class="settings-option" | ||
| 2822 | :class="{ active: !saveHistoryEnabled }" | ||
| 2823 | @click="saveHistoryEnabled = false" | ||
| 2824 | > | ||
| 2825 | <span>Off</span> | ||
| 2826 | </button> | ||
| 2827 | </div> | ||
| 2828 | </div> | ||
| 2829 | </div> | ||
| 2830 | </Transition> | ||
| 2831 | <Transition name="help-popup-fade"> | ||
| 2832 | <div | ||
| 2833 | v-if="activeHelpSection && showSettingsPopup" | ||
| 2834 | ref="helpPopupEl" | ||
| 2835 | class="search-help-popup" | ||
| 2836 | :style="{ top: helpPopupPos.top + 'px', left: helpPopupPos.left + 'px' }" | ||
| 2837 | > | ||
| 2838 | <template v-if="activeHelpSection === 'search'"> | ||
| 2839 | <h4 class="sh-title"> | ||
| 2840 | <Search :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 2841 | Search Mode | ||
| 2842 | </h4> | ||
| 2843 | <p class="sh-desc">Choose how queries are matched against content.</p> | ||
| 2844 | <div class="sh-options"> | ||
| 2845 | <div class="sh-option"> | ||
| 2846 | <strong> | ||
| 2847 | <Regex :size="14" stroke-width="1.5" /> | ||
| 2848 | Exact | ||
| 2849 | </strong> | ||
| 2850 | <span>Matches the exact phrase you type</span> | ||
| 2851 | </div> | ||
| 2852 | <div class="sh-option"> | ||
| 2853 | <strong> | ||
| 2854 | <LocateOff :size="14" stroke-width="1.5" /> | ||
| 2855 | Fuzzy | ||
| 2856 | </strong> | ||
| 2857 | <span>Approximate matching that tolerates typos</span> | ||
| 2858 | </div> | ||
| 2859 | <div class="sh-option"> | ||
| 2860 | <strong> | ||
| 2861 | <Globe :size="14" stroke-width="1.5" /> | ||
| 2862 | URL | ||
| 2863 | </strong> | ||
| 2864 | <span>Searches through hyperlinks</span> | ||
| 2865 | </div> | ||
| 2866 | </div> | ||
| 2867 | </template> | ||
| 2868 | <template v-else-if="activeHelpSection === 'view'"> | ||
| 2869 | <h4 class="sh-title"> | ||
| 2870 | <LayoutList :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 2871 | Result View | ||
| 2872 | </h4> | ||
| 2873 | <p class="sh-desc">Controls how search results are displayed.</p> | ||
| 2874 | <div class="sh-options"> | ||
| 2875 | <div class="sh-option"> | ||
| 2876 | <strong> | ||
| 2877 | <TextAlignStart :size="14" stroke-width="1.5" /> | ||
| 2878 | Detail | ||
| 2879 | </strong> | ||
| 2880 | <span>Shows a content excerpt below each result. Uses more memory.</span> | ||
| 2881 | </div> | ||
| 2882 | <div class="sh-option"> | ||
| 2883 | <strong> | ||
| 2884 | <List :size="14" stroke-width="1.5" /> | ||
| 2885 | List | ||
| 2886 | </strong> | ||
| 2887 | <span>Compact list of titles only. Uses less memory.</span> | ||
| 2888 | </div> | ||
| 2889 | </div> | ||
| 2890 | </template> | ||
| 2891 | <template v-else-if="activeHelpSection === 'preload'"> | ||
| 2892 | <h4 class="sh-title"> | ||
| 2893 | <Layers :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 2894 | Excerpt Preload | ||
| 2895 | </h4> | ||
| 2896 | <p class="sh-desc">Renders excerpts for upcoming result pages ahead of time in Detail view.</p> | ||
| 2897 | <div class="sh-options"> | ||
| 2898 | <div class="sh-option"> | ||
| 2899 | <strong>All</strong> | ||
| 2900 | <span>Prepares every result page. Uses more memory.</span> | ||
| 2901 | </div> | ||
| 2902 | <div class="sh-option"> | ||
| 2903 | <strong>Next</strong> | ||
| 2904 | <span>Also prepares the next page so flipping forward is instant</span> | ||
| 2905 | </div> | ||
| 2906 | <div class="sh-option"> | ||
| 2907 | <strong>Off</strong> | ||
| 2908 | <span>Only the visible page. Uses the least memory.</span> | ||
| 2909 | </div> | ||
| 2910 | </div> | ||
| 2911 | </template> | ||
| 2912 | <template v-else-if="activeHelpSection === 'highlight'"> | ||
| 2913 | <h4 class="sh-title"> | ||
| 2914 | <Highlighter :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 2915 | Search Result Highlight | ||
| 2916 | </h4> | ||
| 2917 | <p class="sh-desc"> | ||
| 2918 | Highlights the exact result you open. | ||
| 2919 | </p> | ||
| 2920 | <div class="sh-options"> | ||
| 2921 | <div class="sh-option"> | ||
| 2922 | <strong>Soft</strong> | ||
| 2923 | <span>Soft accent background with a solid border.</span> | ||
| 2924 | </div> | ||
| 2925 | <div class="sh-option"> | ||
| 2926 | <strong>Solid</strong> | ||
| 2927 | <span>Solid accent fill with no border.</span> | ||
| 2928 | </div> | ||
| 2929 | </div> | ||
| 2930 | </template> | ||
| 2931 | <template v-else-if="activeHelpSection === 'history'"> | ||
| 2932 | <h4 class="sh-title"> | ||
| 2933 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 2934 | Search History | ||
| 2935 | </h4> | ||
| 2936 | <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p> | ||
| 2937 | </template> | ||
| 2938 | </div> | ||
| 2939 | </Transition> | ||
| 2940 | </Teleport> | ||
| 2941 | </component> | ||
| 2942 | </AnimatePresence> | ||
| 2943 | |||
| 2944 | <button v-if="!showSearch" /> | ||
| 2945 | </div> | ||
| 2946 | </Teleport> | ||
| 2947 | </template> | ||
| 2948 | |||
| 2949 | <style scoped> | ||
| 2950 | .VPLocalSearchBox { | ||
| 2951 | position: fixed; | ||
| 2952 | z-index: 100; | ||
| 2953 | inset: 0; | ||
| 2954 | display: flex; | ||
| 2955 | align-items: flex-start; | ||
| 2956 | } | ||
| 2957 | |||
| 2958 | @media (max-width: 767px) { | ||
| 2959 | .VPLocalSearchBox { | ||
| 2960 | align-items: stretch; | ||
| 2961 | } | ||
| 2962 | } | ||
| 2963 | |||
| 2964 | .backdrop { | ||
| 2965 | position: absolute; | ||
| 2966 | inset: 0; | ||
| 2967 | background: var(--vp-backdrop-bg-color); | ||
| 2968 | } | ||
| 2969 | |||
| 2970 | .shell { | ||
| 2971 | position: relative; | ||
| 2972 | box-sizing: border-box; | ||
| 2973 | padding: 12px 12px 8px; | ||
| 2974 | margin: 64px auto; | ||
| 2975 | display: flex; | ||
| 2976 | flex-direction: column; | ||
| 2977 | gap: 16px; | ||
| 2978 | background: var(--vp-local-search-bg); | ||
| 2979 | width: min(100vw - 60px, 700px); | ||
| 2980 | height: 100%; | ||
| 2981 | max-height: min(100vh - 128px, 680px); | ||
| 2982 | border-radius: 6px; | ||
| 2983 | } | ||
| 2984 | |||
| 2985 | @media (max-width: 767px) { | ||
| 2986 | .shell { | ||
| 2987 | margin: 0; | ||
| 2988 | width: 100vw; | ||
| 2989 | height: 100vh; | ||
| 2990 | height: 100dvh; | ||
| 2991 | max-height: none; | ||
| 2992 | border-radius: 0; | ||
| 2993 | overflow: hidden; | ||
| 2994 | gap: 8px; | ||
| 2995 | } | ||
| 2996 | } | ||
| 2997 | |||
| 2998 | .search-bar { | ||
| 2999 | flex: 0 0 auto !important; | ||
| 3000 | min-height: 44px !important; | ||
| 3001 | border: 1px solid var(--vp-c-divider); | ||
| 3002 | border-radius: 4px; | ||
| 3003 | display: flex; | ||
| 3004 | align-items: center; | ||
| 3005 | padding: 0 12px; | ||
| 3006 | cursor: text; | ||
| 3007 | } | ||
| 3008 | |||
| 3009 | @media (max-width: 767px) { | ||
| 3010 | .search-bar { | ||
| 3011 | padding: 0 8px; | ||
| 3012 | min-height: 40px !important; | ||
| 3013 | } | ||
| 3014 | } | ||
| 3015 | |||
| 3016 | .search-bar:focus-within { | ||
| 3017 | border-color: var(--vp-c-brand-1); | ||
| 3018 | } | ||
| 3019 | |||
| 3020 | .page-ribbon { | ||
| 3021 | display: flex; | ||
| 3022 | align-items: center; | ||
| 3023 | padding: 12px 0 4px; | ||
| 3024 | padding-inline: calc(var(--spacing) * 3); | ||
| 3025 | position: relative; | ||
| 3026 | min-width: 0; | ||
| 3027 | flex: none; | ||
| 3028 | overflow: hidden; | ||
| 3029 | transition: padding-inline 0.15s; | ||
| 3030 | } | ||
| 3031 | |||
| 3032 | .page-ribbon.can-scroll-left { | ||
| 3033 | padding-left: 42px; | ||
| 3034 | } | ||
| 3035 | |||
| 3036 | .page-ribbon.can-scroll-right { | ||
| 3037 | padding-right: 42px; | ||
| 3038 | } | ||
| 3039 | |||
| 3040 | .page-ribbon-track { | ||
| 3041 | display: flex; | ||
| 3042 | flex-wrap: nowrap; | ||
| 3043 | gap: 8px; | ||
| 3044 | min-width: 0; | ||
| 3045 | flex: 1; | ||
| 3046 | overflow-x: auto; | ||
| 3047 | overflow-y: hidden; | ||
| 3048 | scrollbar-width: none; | ||
| 3049 | -ms-overflow-style: none; | ||
| 3050 | overscroll-behavior-x: contain; | ||
| 3051 | } | ||
| 3052 | |||
| 3053 | .page-ribbon-track::-webkit-scrollbar { | ||
| 3054 | display: none; | ||
| 3055 | width: 0; | ||
| 3056 | height: 0; | ||
| 3057 | } | ||
| 3058 | |||
| 3059 | .page-ribbon-arrow { | ||
| 3060 | position: absolute; | ||
| 3061 | top: 12px; | ||
| 3062 | bottom: 4px; | ||
| 3063 | z-index: 2; | ||
| 3064 | display: inline-flex; | ||
| 3065 | align-items: center; | ||
| 3066 | justify-content: center; | ||
| 3067 | width: 48px; | ||
| 3068 | border: none; | ||
| 3069 | background: transparent; | ||
| 3070 | color: var(--vp-c-text-2); | ||
| 3071 | cursor: pointer; | ||
| 3072 | transition: color 0.15s; | ||
| 3073 | } | ||
| 3074 | |||
| 3075 | .page-ribbon-arrow:hover { | ||
| 3076 | color: var(--vp-c-text-1); | ||
| 3077 | } | ||
| 3078 | |||
| 3079 | .page-ribbon-arrow.right { | ||
| 3080 | right: 0; | ||
| 3081 | justify-content: flex-end; | ||
| 3082 | padding-right: 6px; | ||
| 3083 | } | ||
| 3084 | |||
| 3085 | .page-ribbon-arrow.left { | ||
| 3086 | left: 0; | ||
| 3087 | justify-content: flex-start; | ||
| 3088 | padding-left: 6px; | ||
| 3089 | } | ||
| 3090 | |||
| 3091 | .page-ribbon-arrow.left svg { | ||
| 3092 | transform: rotate(180deg); | ||
| 3093 | } | ||
| 3094 | |||
| 3095 | .page-pill { | ||
| 3096 | flex: none; | ||
| 3097 | display: inline-flex; | ||
| 3098 | align-items: center; | ||
| 3099 | gap: 6px; | ||
| 3100 | padding: 6px 10px; | ||
| 3101 | font-size: 0.8rem; | ||
| 3102 | line-height: 1.2; | ||
| 3103 | white-space: nowrap; | ||
| 3104 | border-radius: 8px; | ||
| 3105 | border: 1.5px solid var(--vp-c-divider); | ||
| 3106 | background: var(--vp-c-bg-soft); | ||
| 3107 | color: var(--vp-c-text-2); | ||
| 3108 | cursor: pointer; | ||
| 3109 | transition: color 0.15s, border-color 0.15s, background-color 0.15s; | ||
| 3110 | } | ||
| 3111 | |||
| 3112 | .page-pill:hover { | ||
| 3113 | color: var(--vp-c-text-1); | ||
| 3114 | border-color: var(--vp-c-brand-1); | ||
| 3115 | } | ||
| 3116 | |||
| 3117 | .page-pill.active { | ||
| 3118 | color: var(--vp-c-brand-1); | ||
| 3119 | border: 1.5px solid var(--vp-c-brand-1); | ||
| 3120 | background: color-mix(in srgb, var(--vp-c-brand-1) 12%, transparent); | ||
| 3121 | box-shadow: none; | ||
| 3122 | } | ||
| 3123 | |||
| 3124 | .page-pill-label { | ||
| 3125 | max-width: 180px; | ||
| 3126 | overflow: hidden; | ||
| 3127 | text-overflow: ellipsis; | ||
| 3128 | } | ||
| 3129 | |||
| 3130 | .page-pill-count { | ||
| 3131 | font-variant-numeric: tabular-nums; | ||
| 3132 | font-size: 0.7rem; | ||
| 3133 | padding: 1px 6px; | ||
| 3134 | border-radius: 4px; | ||
| 3135 | background: rgba(128, 128, 128, 0.15); | ||
| 3136 | color: inherit; | ||
| 3137 | } | ||
| 3138 | |||
| 3139 | .page-pill.active .page-pill-count { | ||
| 3140 | background: color-mix(in srgb, var(--vp-c-brand-1) 18%, transparent); | ||
| 3141 | } | ||
| 3142 | |||
| 3143 | @media (max-width: 767px) { | ||
| 3144 | .page-ribbon { | ||
| 3145 | padding: 14px 12px 4px; | ||
| 3146 | } | ||
| 3147 | |||
| 3148 | .page-pill { | ||
| 3149 | padding: 7px 14px; | ||
| 3150 | font-size: 0.82rem; | ||
| 3151 | background: var(--vp-c-bg-elv, var(--vp-c-bg-soft)); | ||
| 3152 | border-color: var(--vp-c-divider); | ||
| 3153 | color: var(--vp-c-text-1); | ||
| 3154 | } | ||
| 3155 | } | ||
| 3156 | |||
| 3157 | .local-search-icon { | ||
| 3158 | display: block; | ||
| 3159 | font-size: 18px; | ||
| 3160 | } | ||
| 3161 | |||
| 3162 | .navigate-icon { | ||
| 3163 | display: block; | ||
| 3164 | font-size: 14px; | ||
| 3165 | } | ||
| 3166 | |||
| 3167 | .search-icon { | ||
| 3168 | margin: 8px; | ||
| 3169 | } | ||
| 3170 | |||
| 3171 | @media (max-width: 767px) { | ||
| 3172 | .search-icon { | ||
| 3173 | display: none; | ||
| 3174 | } | ||
| 3175 | } | ||
| 3176 | |||
| 3177 | .search-input { | ||
| 3178 | flex: 1 1 auto; | ||
| 3179 | min-width: 0; | ||
| 3180 | padding: 6px 12px; | ||
| 3181 | font-size: inherit; | ||
| 3182 | width: 100%; | ||
| 3183 | } | ||
| 3184 | |||
| 3185 | .search-input::-webkit-search-cancel-button { | ||
| 3186 | display: none; | ||
| 3187 | } | ||
| 3188 | |||
| 3189 | @media (max-width: 767px) { | ||
| 3190 | .search-input { | ||
| 3191 | padding: 6px 4px; | ||
| 3192 | } | ||
| 3193 | } | ||
| 3194 | |||
| 3195 | .search-actions { | ||
| 3196 | flex: 0 0 auto; | ||
| 3197 | display: flex; | ||
| 3198 | align-items: center; | ||
| 3199 | gap: 4px; | ||
| 3200 | } | ||
| 3201 | |||
| 3202 | .search-loading-button { | ||
| 3203 | display: inline-flex; | ||
| 3204 | align-items: center; | ||
| 3205 | justify-content: center; | ||
| 3206 | padding: 0 !important; | ||
| 3207 | margin-inline-end: 6px; | ||
| 3208 | border: 0; | ||
| 3209 | background: transparent; | ||
| 3210 | cursor: pointer; | ||
| 3211 | } | ||
| 3212 | |||
| 3213 | .search-loading-bubba { | ||
| 3214 | width: 32px; | ||
| 3215 | height: 28px; | ||
| 3216 | object-fit: contain; | ||
| 3217 | image-rendering: pixelated; | ||
| 3218 | user-select: none; | ||
| 3219 | } | ||
| 3220 | |||
| 3221 | @media (any-pointer: coarse) { | ||
| 3222 | .search-actions { | ||
| 3223 | gap: 8px; | ||
| 3224 | } | ||
| 3225 | } | ||
| 3226 | |||
| 3227 | @media (min-width: 769px) { | ||
| 3228 | .search-actions.before { | ||
| 3229 | display: none; | ||
| 3230 | } | ||
| 3231 | } | ||
| 3232 | |||
| 3233 | .search-actions button { | ||
| 3234 | padding: 8px; | ||
| 3235 | } | ||
| 3236 | |||
| 3237 | .search-actions button:not([disabled]):hover, | ||
| 3238 | .toggle-layout-button.detailed-list { | ||
| 3239 | color: var(--vp-c-brand-1); | ||
| 3240 | } | ||
| 3241 | |||
| 3242 | .search-actions button.clear-button:disabled { | ||
| 3243 | opacity: 0.37; | ||
| 3244 | } | ||
| 3245 | |||
| 3246 | .search-keyboard-shortcuts { | ||
| 3247 | font-size: 0.8rem; | ||
| 3248 | opacity: 75%; | ||
| 3249 | display: flex; | ||
| 3250 | flex-wrap: wrap; | ||
| 3251 | gap: 16px; | ||
| 3252 | line-height: 14px; | ||
| 3253 | } | ||
| 3254 | |||
| 3255 | .search-keyboard-shortcuts span { | ||
| 3256 | display: flex; | ||
| 3257 | align-items: center; | ||
| 3258 | gap: 4px; | ||
| 3259 | } | ||
| 3260 | |||
| 3261 | @media (max-width: 767px) { | ||
| 3262 | .search-keyboard-shortcuts { | ||
| 3263 | display: none; | ||
| 3264 | } | ||
| 3265 | } | ||
| 3266 | |||
| 3267 | .search-keyboard-shortcuts kbd { | ||
| 3268 | background: rgba(128, 128, 128, 0.1); | ||
| 3269 | border-radius: 4px; | ||
| 3270 | padding: 3px 6px; | ||
| 3271 | min-width: 24px; | ||
| 3272 | display: inline-block; | ||
| 3273 | text-align: center; | ||
| 3274 | vertical-align: middle; | ||
| 3275 | border: 1px solid rgba(128, 128, 128, 0.15); | ||
| 3276 | box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1); | ||
| 3277 | } | ||
| 3278 | |||
| 3279 | .results { | ||
| 3280 | display: flex; | ||
| 3281 | flex-direction: column; | ||
| 3282 | gap: 6px; | ||
| 3283 | flex: 1 1 auto; | ||
| 3284 | min-height: 0 !important; | ||
| 3285 | overflow-x: hidden; | ||
| 3286 | overflow-y: auto; | ||
| 3287 | overscroll-behavior: contain; | ||
| 3288 | } | ||
| 3289 | |||
| 3290 | .result-layout { | ||
| 3291 | will-change: transform, opacity, height; | ||
| 3292 | } | ||
| 3293 | |||
| 3294 | .result { | ||
| 3295 | display: flex; | ||
| 3296 | align-items: center; | ||
| 3297 | gap: 8px; | ||
| 3298 | border-radius: 4px; | ||
| 3299 | transition: none; | ||
| 3300 | line-height: 1rem; | ||
| 3301 | border: solid 2px var(--vp-local-search-result-border); | ||
| 3302 | outline: none; | ||
| 3303 | } | ||
| 3304 | |||
| 3305 | .result > div { | ||
| 3306 | margin: 12px; | ||
| 3307 | width: 100%; | ||
| 3308 | overflow: hidden; | ||
| 3309 | } | ||
| 3310 | |||
| 3311 | @media (max-width: 767px) { | ||
| 3312 | .result > div { | ||
| 3313 | margin: 8px; | ||
| 3314 | } | ||
| 3315 | } | ||
| 3316 | |||
| 3317 | .titles { | ||
| 3318 | display: flex; | ||
| 3319 | flex-wrap: wrap; | ||
| 3320 | gap: 4px; | ||
| 3321 | position: relative; | ||
| 3322 | z-index: 1001; | ||
| 3323 | padding: 2px 0; | ||
| 3324 | align-items: center; | ||
| 3325 | } | ||
| 3326 | |||
| 3327 | .url-result-card { | ||
| 3328 | cursor: pointer; | ||
| 3329 | } | ||
| 3330 | |||
| 3331 | .url-result-body { | ||
| 3332 | display: flex; | ||
| 3333 | flex-direction: column; | ||
| 3334 | gap: 6px; | ||
| 3335 | } | ||
| 3336 | |||
| 3337 | .url-path { | ||
| 3338 | display: flex; | ||
| 3339 | align-items: center; | ||
| 3340 | flex-wrap: wrap; | ||
| 3341 | gap: 4px; | ||
| 3342 | color: var(--vp-c-text-3); | ||
| 3343 | font-size: 0.78rem; | ||
| 3344 | line-height: 1.2; | ||
| 3345 | } | ||
| 3346 | |||
| 3347 | .url-path > svg, | ||
| 3348 | .url-path-segment svg { | ||
| 3349 | flex-shrink: 0; | ||
| 3350 | width: 1em; | ||
| 3351 | height: 1em; | ||
| 3352 | margin-top: -1px; | ||
| 3353 | opacity: 0.55; | ||
| 3354 | } | ||
| 3355 | |||
| 3356 | .url-path > svg { | ||
| 3357 | margin-top: -2px; | ||
| 3358 | } | ||
| 3359 | |||
| 3360 | .url-path-segment { | ||
| 3361 | display: flex; | ||
| 3362 | align-items: center; | ||
| 3363 | min-width: 0; | ||
| 3364 | } | ||
| 3365 | |||
| 3366 | .url-path-current { | ||
| 3367 | display: inline-flex; | ||
| 3368 | align-items: center; | ||
| 3369 | color: var(--vp-c-text-2); | ||
| 3370 | } | ||
| 3371 | |||
| 3372 | .url-path :deep(.icon-tip) { | ||
| 3373 | display: inline-flex; | ||
| 3374 | align-items: center; | ||
| 3375 | line-height: 1; | ||
| 3376 | vertical-align: middle; | ||
| 3377 | } | ||
| 3378 | |||
| 3379 | .url-path :deep(.icon-tip > span) { | ||
| 3380 | width: 1em; | ||
| 3381 | height: 1em; | ||
| 3382 | min-width: 1em; | ||
| 3383 | } | ||
| 3384 | |||
| 3385 | .url-link { | ||
| 3386 | align-self: flex-start; | ||
| 3387 | max-width: 100%; | ||
| 3388 | color: var(--vp-c-text-1); | ||
| 3389 | font-size: 0.95rem; | ||
| 3390 | font-weight: 500; | ||
| 3391 | line-height: 1.35; | ||
| 3392 | overflow-wrap: anywhere; | ||
| 3393 | word-break: break-word; | ||
| 3394 | } | ||
| 3395 | |||
| 3396 | .url-link:hover { | ||
| 3397 | color: var(--vp-c-brand-1); | ||
| 3398 | text-decoration: underline; | ||
| 3399 | text-underline-offset: 2px; | ||
| 3400 | } | ||
| 3401 | |||
| 3402 | .result.selected .url-link { | ||
| 3403 | color: var(--vp-c-brand-1); | ||
| 3404 | } | ||
| 3405 | |||
| 3406 | .titles > svg { | ||
| 3407 | flex-shrink: 0; | ||
| 3408 | align-self: center; | ||
| 3409 | } | ||
| 3410 | |||
| 3411 | .title { | ||
| 3412 | display: flex; | ||
| 3413 | align-items: center; | ||
| 3414 | gap: 4px; | ||
| 3415 | } | ||
| 3416 | |||
| 3417 | .title.main { | ||
| 3418 | font-weight: 500; | ||
| 3419 | } | ||
| 3420 | |||
| 3421 | .title-icon { | ||
| 3422 | opacity: 1; | ||
| 3423 | font-weight: 500; | ||
| 3424 | } | ||
| 3425 | |||
| 3426 | .title svg { | ||
| 3427 | opacity: 0.5; | ||
| 3428 | } | ||
| 3429 | |||
| 3430 | .result.selected { | ||
| 3431 | --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg); | ||
| 3432 | border-color: var(--vp-local-search-result-selected-border); | ||
| 3433 | } | ||
| 3434 | |||
| 3435 | .excerpt-wrapper { | ||
| 3436 | position: relative; | ||
| 3437 | } | ||
| 3438 | |||
| 3439 | .excerpt { | ||
| 3440 | opacity: 50%; | ||
| 3441 | pointer-events: none; | ||
| 3442 | height: 84px; | ||
| 3443 | max-height: 84px; | ||
| 3444 | overflow: hidden; | ||
| 3445 | position: relative; | ||
| 3446 | margin-top: 4px; | ||
| 3447 | contain: layout paint; | ||
| 3448 | } | ||
| 3449 | |||
| 3450 | .result.selected .excerpt { | ||
| 3451 | opacity: 1; | ||
| 3452 | } | ||
| 3453 | |||
| 3454 | .excerpt :deep(*) { | ||
| 3455 | font-size: 0.8rem !important; | ||
| 3456 | line-height: 130% !important; | ||
| 3457 | } | ||
| 3458 | |||
| 3459 | .titles :deep(mark), | ||
| 3460 | .excerpt :deep(mark) { | ||
| 3461 | background-color: var(--vp-local-search-highlight-bg); | ||
| 3462 | color: var(--vp-local-search-highlight-text); | ||
| 3463 | border-radius: 2px; | ||
| 3464 | padding: 0 2px; | ||
| 3465 | } | ||
| 3466 | |||
| 3467 | .excerpt :deep(.vp-code-group) .tabs { | ||
| 3468 | display: none; | ||
| 3469 | } | ||
| 3470 | |||
| 3471 | .excerpt :deep(.vp-code-group) div[class*="language-"] { | ||
| 3472 | border-radius: 8px !important; | ||
| 3473 | } | ||
| 3474 | |||
| 3475 | .excerpt > .vp-doc > *:first-child { | ||
| 3476 | margin-top: 6px !important; | ||
| 3477 | } | ||
| 3478 | |||
| 3479 | .excerpt-gradient-bottom { | ||
| 3480 | position: absolute; | ||
| 3481 | bottom: -1px; | ||
| 3482 | left: 0; | ||
| 3483 | width: 100%; | ||
| 3484 | height: 8px; | ||
| 3485 | background: linear-gradient(transparent, var(--vp-local-search-result-bg)); | ||
| 3486 | z-index: 1000; | ||
| 3487 | } | ||
| 3488 | |||
| 3489 | .excerpt-gradient-top { | ||
| 3490 | position: absolute; | ||
| 3491 | top: -1px; | ||
| 3492 | left: 0; | ||
| 3493 | width: 100%; | ||
| 3494 | height: 8px; | ||
| 3495 | background: linear-gradient(var(--vp-local-search-result-bg), transparent); | ||
| 3496 | z-index: 1000; | ||
| 3497 | } | ||
| 3498 | |||
| 3499 | .result.selected .titles, | ||
| 3500 | .result.selected .title-icon { | ||
| 3501 | color: var(--vp-c-brand-1) !important; | ||
| 3502 | } | ||
| 3503 | |||
| 3504 | .no-results { | ||
| 3505 | font-size: 0.9rem; | ||
| 3506 | text-align: center; | ||
| 3507 | padding: 12px; | ||
| 3508 | } | ||
| 3509 | |||
| 3510 | svg { | ||
| 3511 | flex: none; | ||
| 3512 | } | ||
| 3513 | |||
| 3514 | .exact-match-button.exact-match-active { | ||
| 3515 | color: var(--vp-c-brand-1); | ||
| 3516 | background-color: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 3517 | border-radius: 4px; | ||
| 3518 | } | ||
| 3519 | |||
| 3520 | .toolbar-group + .toolbar-group { | ||
| 3521 | margin-left: 6px; | ||
| 3522 | } | ||
| 3523 | |||
| 3524 | .search-mode-group, | ||
| 3525 | .view-group { | ||
| 3526 | display: none; | ||
| 3527 | } | ||
| 3528 | |||
| 3529 | .mode-btn { | ||
| 3530 | display: flex; | ||
| 3531 | align-items: center; | ||
| 3532 | justify-content: center; | ||
| 3533 | padding: 5px 7px; | ||
| 3534 | color: var(--vp-c-text-2); | ||
| 3535 | background: transparent; | ||
| 3536 | border: none; | ||
| 3537 | cursor: pointer; | ||
| 3538 | transition: color 0.15s, background-color 0.15s; | ||
| 3539 | border-radius: 0; | ||
| 3540 | } | ||
| 3541 | |||
| 3542 | .mode-btn + .mode-btn { | ||
| 3543 | border-left: 1px solid var(--vp-c-divider); | ||
| 3544 | } | ||
| 3545 | |||
| 3546 | .mode-btn:hover { | ||
| 3547 | color: var(--vp-c-text-1); | ||
| 3548 | background: var(--vp-c-default-soft); | ||
| 3549 | } | ||
| 3550 | |||
| 3551 | .mode-btn.mode-active { | ||
| 3552 | color: var(--vp-c-brand-1); | ||
| 3553 | background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 3554 | } | ||
| 3555 | |||
| 3556 | :deep(.url-highlight) { | ||
| 3557 | background-color: var(--vp-local-search-highlight-bg); | ||
| 3558 | color: var(--vp-local-search-highlight-text); | ||
| 3559 | border-radius: 2px; | ||
| 3560 | padding: 0 2px; | ||
| 3561 | font-style: normal; | ||
| 3562 | } | ||
| 3563 | |||
| 3564 | /* Bottom-strip pagination. The <nav> is always rendered (empty when only one | ||
| 3565 | page) but collapses to zero height in that case so the shell's bottom | ||
| 3566 | rounded edge sits flush against the results. */ | ||
| 3567 | .url-pagination { | ||
| 3568 | display: flex; | ||
| 3569 | align-items: center; | ||
| 3570 | justify-content: center; | ||
| 3571 | flex: 0 0 auto !important; | ||
| 3572 | } | ||
| 3573 | |||
| 3574 | .url-pagination:has(.url-pagination-segment) { | ||
| 3575 | padding-top: 8px; | ||
| 3576 | } | ||
| 3577 | |||
| 3578 | .url-pagination-segment { | ||
| 3579 | display: flex; | ||
| 3580 | align-items: center; | ||
| 3581 | border: 1px solid var(--vp-c-divider); | ||
| 3582 | border-radius: 5px; | ||
| 3583 | overflow: hidden; | ||
| 3584 | background: transparent; | ||
| 3585 | } | ||
| 3586 | |||
| 3587 | .url-page-btn { | ||
| 3588 | display: flex; | ||
| 3589 | align-items: center; | ||
| 3590 | justify-content: center; | ||
| 3591 | min-width: 32px; | ||
| 3592 | height: 28px; | ||
| 3593 | padding: 0 8px; | ||
| 3594 | border: none; | ||
| 3595 | background: transparent; | ||
| 3596 | color: var(--vp-c-text-2); | ||
| 3597 | font-size: 0.82rem; | ||
| 3598 | cursor: pointer; | ||
| 3599 | transition: color 0.15s, background-color 0.15s; | ||
| 3600 | border-radius: 0; | ||
| 3601 | } | ||
| 3602 | |||
| 3603 | .url-page-btn + .url-page-btn, | ||
| 3604 | .url-page-ellipsis + .url-page-btn, | ||
| 3605 | .url-page-btn + .url-page-ellipsis { | ||
| 3606 | border-left: 1px solid var(--vp-c-divider); | ||
| 3607 | } | ||
| 3608 | |||
| 3609 | .url-page-btn:hover:not(:disabled):not(.active) { | ||
| 3610 | color: var(--vp-c-text-1); | ||
| 3611 | background: var(--vp-c-default-soft); | ||
| 3612 | } | ||
| 3613 | |||
| 3614 | .url-page-btn.active { | ||
| 3615 | color: var(--vp-c-brand-1); | ||
| 3616 | background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 3617 | font-weight: 500; | ||
| 3618 | cursor: default; | ||
| 3619 | } | ||
| 3620 | |||
| 3621 | .url-page-btn:disabled { | ||
| 3622 | opacity: 0.25; | ||
| 3623 | cursor: not-allowed; | ||
| 3624 | background: transparent; | ||
| 3625 | } | ||
| 3626 | |||
| 3627 | .url-page-nav { | ||
| 3628 | padding: 0 6px; | ||
| 3629 | } | ||
| 3630 | |||
| 3631 | .url-page-ellipsis { | ||
| 3632 | display: flex; | ||
| 3633 | align-items: center; | ||
| 3634 | justify-content: center; | ||
| 3635 | min-width: 28px; | ||
| 3636 | height: 28px; | ||
| 3637 | color: var(--vp-c-text-3); | ||
| 3638 | font-size: 0.8rem; | ||
| 3639 | user-select: none; | ||
| 3640 | background: transparent; | ||
| 3641 | } | ||
| 3642 | |||
| 3643 | /* Settings gear + clear (X) buttons — nav-bar style */ | ||
| 3644 | .search-actions .settings-toggle-btn, | ||
| 3645 | .search-actions .clear-button { | ||
| 3646 | display: flex; | ||
| 3647 | border: none; | ||
| 3648 | border-radius: 0; | ||
| 3649 | background: transparent; | ||
| 3650 | color: var(--vp-c-text-1); | ||
| 3651 | opacity: 0.55; | ||
| 3652 | padding: 8px 4px; | ||
| 3653 | transition: | ||
| 3654 | opacity 0.25s, | ||
| 3655 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 3656 | } | ||
| 3657 | |||
| 3658 | .search-actions button.settings-toggle-btn:not([disabled]):hover, | ||
| 3659 | .search-actions button.clear-button:not([disabled]):hover, | ||
| 3660 | .settings-toggle-btn.mode-active { | ||
| 3661 | color: var(--vp-c-text-1); | ||
| 3662 | opacity: 1; | ||
| 3663 | background: transparent; | ||
| 3664 | } | ||
| 3665 | |||
| 3666 | .settings-toggle-btn:active, | ||
| 3667 | .clear-button:not([disabled]):active { | ||
| 3668 | transform: scale(0.94); | ||
| 3669 | } | ||
| 3670 | |||
| 3671 | /* Respect the "effects off" preference */ | ||
| 3672 | html.effects-disabled .settings-toggle-btn, | ||
| 3673 | html.effects-disabled .clear-button { | ||
| 3674 | transition: none; | ||
| 3675 | } | ||
| 3676 | |||
| 3677 | html.effects-disabled .settings-toggle-btn:active, | ||
| 3678 | html.effects-disabled .clear-button:active { | ||
| 3679 | transform: none; | ||
| 3680 | } | ||
| 3681 | |||
| 3682 | /* Settings popup card */ | ||
| 3683 | .search-settings-popup { | ||
| 3684 | --seg-track: var(--wk-c-menu-bg); | ||
| 3685 | --seg-pill-bg: var(--vp-c-bg); | ||
| 3686 | --seg-pill-text: var(--vp-c-text-1); | ||
| 3687 | --seg-pill-shadow: 0 2px 4px 0 #bababa8c; | ||
| 3688 | position: fixed; | ||
| 3689 | z-index: 200; | ||
| 3690 | background: var(--vp-c-bg-elv); | ||
| 3691 | border: 1px solid var(--vp-c-divider); | ||
| 3692 | border-radius: 12px; | ||
| 3693 | padding: 12px; | ||
| 3694 | box-shadow: var(--vp-shadow-3); | ||
| 3695 | display: flex; | ||
| 3696 | flex-direction: column; | ||
| 3697 | min-width: 196px; | ||
| 3698 | } | ||
| 3699 | |||
| 3700 | .dark .search-settings-popup { | ||
| 3701 | --seg-track: var(--wk-c-menu-bg); | ||
| 3702 | --seg-pill-bg: var(--vp-c-text-1); | ||
| 3703 | --seg-pill-text: var(--vp-c-bg-elv); | ||
| 3704 | --seg-pill-shadow: 0 2px 4px 0 #535353db; | ||
| 3705 | } | ||
| 3706 | |||
| 3707 | .settings-section { | ||
| 3708 | display: flex; | ||
| 3709 | flex-direction: column; | ||
| 3710 | gap: 0; | ||
| 3711 | } | ||
| 3712 | |||
| 3713 | .settings-section + .settings-section { | ||
| 3714 | border-top: 1px solid var(--vp-c-divider); | ||
| 3715 | margin-top: 8px; | ||
| 3716 | padding-top: 8px; | ||
| 3717 | } | ||
| 3718 | |||
| 3719 | .settings-section-header { | ||
| 3720 | display: flex; | ||
| 3721 | align-items: center; | ||
| 3722 | justify-content: space-between; | ||
| 3723 | margin-bottom: 6px; | ||
| 3724 | } | ||
| 3725 | |||
| 3726 | .settings-section-label { | ||
| 3727 | display: flex; | ||
| 3728 | align-items: center; | ||
| 3729 | gap: 6px; | ||
| 3730 | font-size: 14px; | ||
| 3731 | font-weight: 500; | ||
| 3732 | color: var(--vp-c-text-1); | ||
| 3733 | } | ||
| 3734 | |||
| 3735 | .settings-help-btn { | ||
| 3736 | display: flex; | ||
| 3737 | align-items: center; | ||
| 3738 | justify-content: center; | ||
| 3739 | padding: 3px; | ||
| 3740 | background: transparent; | ||
| 3741 | border: none; | ||
| 3742 | cursor: pointer; | ||
| 3743 | color: var(--vp-c-text-3); | ||
| 3744 | opacity: 0.5; | ||
| 3745 | transition: opacity 0.15s, color 0.15s; | ||
| 3746 | border-radius: 3px; | ||
| 3747 | line-height: 1; | ||
| 3748 | } | ||
| 3749 | |||
| 3750 | .settings-help-btn:hover, | ||
| 3751 | .settings-help-btn.active { | ||
| 3752 | opacity: 1; | ||
| 3753 | color: var(--vp-c-text-1); | ||
| 3754 | } | ||
| 3755 | |||
| 3756 | .settings-help-icon { | ||
| 3757 | display: block; | ||
| 3758 | width: 16px; | ||
| 3759 | height: 16px; | ||
| 3760 | } | ||
| 3761 | |||
| 3762 | /* Help popup */ | ||
| 3763 | .search-help-popup { | ||
| 3764 | position: fixed; | ||
| 3765 | z-index: 9999; | ||
| 3766 | width: 280px; | ||
| 3767 | background: var(--vp-c-bg-elv); | ||
| 3768 | border: 1px solid var(--vp-c-divider); | ||
| 3769 | border-radius: 12px; | ||
| 3770 | padding: 16px; | ||
| 3771 | box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); | ||
| 3772 | pointer-events: none; | ||
| 3773 | } | ||
| 3774 | |||
| 3775 | .help-popup-fade-enter-active, | ||
| 3776 | .help-popup-fade-leave-active { | ||
| 3777 | transition: opacity 0.15s ease; | ||
| 3778 | } | ||
| 3779 | |||
| 3780 | .help-popup-fade-enter-from, | ||
| 3781 | .help-popup-fade-leave-to { | ||
| 3782 | opacity: 0; | ||
| 3783 | } | ||
| 3784 | |||
| 3785 | .sh-title { | ||
| 3786 | display: flex; | ||
| 3787 | align-items: center; | ||
| 3788 | gap: 6px; | ||
| 3789 | font-size: 1rem; | ||
| 3790 | font-weight: 600; | ||
| 3791 | color: var(--vp-c-text-1); | ||
| 3792 | margin: 0 0 4px; | ||
| 3793 | } | ||
| 3794 | |||
| 3795 | .sh-title-icon { | ||
| 3796 | flex-shrink: 0; | ||
| 3797 | opacity: 0.8; | ||
| 3798 | width: 16px; | ||
| 3799 | height: 16px; | ||
| 3800 | } | ||
| 3801 | |||
| 3802 | .sh-desc { | ||
| 3803 | font-size: 0.875rem; | ||
| 3804 | color: var(--vp-c-text-2); | ||
| 3805 | margin: 0 0 6px; | ||
| 3806 | line-height: 1.5; | ||
| 3807 | } | ||
| 3808 | |||
| 3809 | .sh-options { | ||
| 3810 | display: flex; | ||
| 3811 | flex-direction: column; | ||
| 3812 | gap: 5px; | ||
| 3813 | } | ||
| 3814 | |||
| 3815 | .sh-option { | ||
| 3816 | display: flex; | ||
| 3817 | flex-direction: column; | ||
| 3818 | gap: 4px; | ||
| 3819 | background: var(--wk-c-menu-bg); | ||
| 3820 | border-radius: 12px; | ||
| 3821 | padding: 10px 12px; | ||
| 3822 | } | ||
| 3823 | |||
| 3824 | .dark .sh-option { | ||
| 3825 | background: var(--wk-c-menu-bg); | ||
| 3826 | } | ||
| 3827 | |||
| 3828 | .sh-option strong { | ||
| 3829 | display: flex; | ||
| 3830 | align-items: center; | ||
| 3831 | gap: 4px; | ||
| 3832 | font-size: 0.875rem; | ||
| 3833 | font-weight: 600; | ||
| 3834 | color: var(--vp-c-text-1); | ||
| 3835 | } | ||
| 3836 | |||
| 3837 | .sh-option span { | ||
| 3838 | font-size: 0.875rem; | ||
| 3839 | color: var(--vp-c-text-2); | ||
| 3840 | line-height: 1.4; | ||
| 3841 | } | ||
| 3842 | |||
| 3843 | .settings-options { | ||
| 3844 | display: flex; | ||
| 3845 | gap: 4px; | ||
| 3846 | background: var(--seg-track); | ||
| 3847 | border-radius: 8px; | ||
| 3848 | padding: 4px; | ||
| 3849 | outline: 2px dashed transparent; | ||
| 3850 | outline-offset: 4px; | ||
| 3851 | transition: outline-color 0.2s ease; | ||
| 3852 | } | ||
| 3853 | |||
| 3854 | .settings-options.is-highlighted { | ||
| 3855 | outline-color: var(--vp-c-brand-1); | ||
| 3856 | } | ||
| 3857 | |||
| 3858 | .settings-option { | ||
| 3859 | display: flex; | ||
| 3860 | align-items: center; | ||
| 3861 | justify-content: center; | ||
| 3862 | gap: 5px; | ||
| 3863 | padding: 5px 6px; | ||
| 3864 | background: transparent; | ||
| 3865 | border: none; | ||
| 3866 | border-radius: 6px; | ||
| 3867 | cursor: pointer; | ||
| 3868 | color: var(--vp-c-text-1); | ||
| 3869 | font-size: 14px; | ||
| 3870 | font-weight: 500; | ||
| 3871 | transition: background-color 0.15s, color 0.15s, box-shadow 0.15s; | ||
| 3872 | flex: 1; | ||
| 3873 | } | ||
| 3874 | |||
| 3875 | .settings-option:hover, | ||
| 3876 | .settings-option.active { | ||
| 3877 | color: var(--seg-pill-text); | ||
| 3878 | background: var(--seg-pill-bg); | ||
| 3879 | box-shadow: var(--seg-pill-shadow); | ||
| 3880 | } | ||
| 3881 | |||
| 3882 | .settings-option.active { | ||
| 3883 | font-weight: 700; | ||
| 3884 | } | ||
| 3885 | |||
| 3886 | .settings-popup-enter-active, | ||
| 3887 | .settings-popup-leave-active { | ||
| 3888 | transition: opacity 0.15s ease, transform 0.15s ease; | ||
| 3889 | transform-origin: top right; | ||
| 3890 | } | ||
| 3891 | |||
| 3892 | .settings-popup-enter-from, | ||
| 3893 | .settings-popup-leave-to { | ||
| 3894 | opacity: 0; | ||
| 3895 | transform: scale(0.92) translateY(-4px); | ||
| 3896 | } | ||
| 3897 | |||
| 3898 | .history-list { | ||
| 3899 | display: flex; | ||
| 3900 | flex-direction: column; | ||
| 3901 | width: 100%; | ||
| 3902 | padding: 4px 0; | ||
| 3903 | } | ||
| 3904 | |||
| 3905 | .history-header { | ||
| 3906 | font-size: 0.7rem; | ||
| 3907 | font-weight: 600; | ||
| 3908 | text-transform: uppercase; | ||
| 3909 | letter-spacing: 0.06em; | ||
| 3910 | color: var(--vp-c-text-3); | ||
| 3911 | padding: 4px 12px 8px; | ||
| 3912 | display: flex; | ||
| 3913 | align-items: center; | ||
| 3914 | justify-content: space-between; | ||
| 3915 | } | ||
| 3916 | |||
| 3917 | .history-clear-all { | ||
| 3918 | display: flex; | ||
| 3919 | align-items: center; | ||
| 3920 | justify-content: center; | ||
| 3921 | flex-shrink: 0; | ||
| 3922 | padding: 0; | ||
| 3923 | border: none; | ||
| 3924 | background: transparent; | ||
| 3925 | color: var(--vp-c-text-3); | ||
| 3926 | cursor: pointer; | ||
| 3927 | opacity: 0.7; | ||
| 3928 | transition: color 0.15s; | ||
| 3929 | } | ||
| 3930 | |||
| 3931 | .history-clear-all:hover { | ||
| 3932 | color: var(--vp-c-text-1); | ||
| 3933 | opacity: 1; | ||
| 3934 | } | ||
| 3935 | |||
| 3936 | .history-items { | ||
| 3937 | display: flex; | ||
| 3938 | flex-direction: column; | ||
| 3939 | list-style: none; | ||
| 3940 | margin: 0; | ||
| 3941 | padding: 0; | ||
| 3942 | } | ||
| 3943 | |||
| 3944 | .history-item { | ||
| 3945 | display: flex; | ||
| 3946 | align-items: center; | ||
| 3947 | gap: 8px; | ||
| 3948 | padding: 8px 12px; | ||
| 3949 | cursor: pointer; | ||
| 3950 | border-radius: 4px; | ||
| 3951 | transition: background-color 0.15s; | ||
| 3952 | } | ||
| 3953 | |||
| 3954 | .history-item:hover { | ||
| 3955 | background: var(--vp-c-default-soft); | ||
| 3956 | } | ||
| 3957 | |||
| 3958 | .history-main { | ||
| 3959 | flex: 1; | ||
| 3960 | min-width: 0; | ||
| 3961 | display: flex; | ||
| 3962 | align-items: center; | ||
| 3963 | gap: 6px; | ||
| 3964 | overflow: hidden; | ||
| 3965 | } | ||
| 3966 | |||
| 3967 | .history-query { | ||
| 3968 | flex-shrink: 0; | ||
| 3969 | font-size: 0.9rem; | ||
| 3970 | color: var(--vp-c-text-1); | ||
| 3971 | white-space: nowrap; | ||
| 3972 | } | ||
| 3973 | |||
| 3974 | .history-arrow { | ||
| 3975 | flex-shrink: 0; | ||
| 3976 | opacity: 0.5; | ||
| 3977 | color: var(--vp-c-text-3); | ||
| 3978 | } | ||
| 3979 | |||
| 3980 | .history-path-seg { | ||
| 3981 | min-width: 0; | ||
| 3982 | overflow: hidden; | ||
| 3983 | text-overflow: ellipsis; | ||
| 3984 | white-space: nowrap; | ||
| 3985 | font-size: 0.78rem; | ||
| 3986 | font-weight: 500; | ||
| 3987 | color: var(--vp-c-text-3); | ||
| 3988 | } | ||
| 3989 | |||
| 3990 | .history-path-sep { | ||
| 3991 | flex-shrink: 0; | ||
| 3992 | font-size: 0.78rem; | ||
| 3993 | color: var(--vp-c-text-3); | ||
| 3994 | } | ||
| 3995 | |||
| 3996 | .history-path-end { | ||
| 3997 | flex-shrink: 0; | ||
| 3998 | white-space: nowrap; | ||
| 3999 | font-size: 0.78rem; | ||
| 4000 | font-weight: 500; | ||
| 4001 | color: var(--vp-c-text-3); | ||
| 4002 | } | ||
| 4003 | |||
| 4004 | .history-path-only { | ||
| 4005 | flex-shrink: 1; | ||
| 4006 | min-width: 0; | ||
| 4007 | overflow: hidden; | ||
| 4008 | text-overflow: ellipsis; | ||
| 4009 | } | ||
| 4010 | |||
| 4011 | .history-mode-icon { | ||
| 4012 | flex-shrink: 0; | ||
| 4013 | color: var(--vp-c-text-3); | ||
| 4014 | opacity: 0.7; | ||
| 4015 | } | ||
| 4016 | |||
| 4017 | .history-remove { | ||
| 4018 | display: flex; | ||
| 4019 | align-items: center; | ||
| 4020 | justify-content: center; | ||
| 4021 | flex-shrink: 0; | ||
| 4022 | padding: 0; | ||
| 4023 | border: none; | ||
| 4024 | background: transparent; | ||
| 4025 | color: var(--vp-c-text-3); | ||
| 4026 | cursor: pointer; | ||
| 4027 | opacity: 0.7; | ||
| 4028 | transition: color 0.15s; | ||
| 4029 | } | ||
| 4030 | |||
| 4031 | .history-remove:hover { | ||
| 4032 | color: var(--vp-c-text-1); | ||
| 4033 | opacity: 1; | ||
| 4034 | } | ||
| 4035 | </style>\ No newline at end of file | ||
docs/.vitepress/theme/components/search/Search.vue added +1741
| @@ -0,0 +1,1741 @@ | |||
| 1 | <script lang="ts" setup> | ||
| 2 | import type { SearchResult } from 'minisearch' | ||
| 3 | import { dataSymbol, type DefaultTheme, inBrowser, useRouter } from 'vitepress' | ||
| 4 | import { | ||
| 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 | ||
| 18 | import { pathToFile } from 'vitepress/dist/client/app/utils' | ||
| 19 | |||
| 20 | import { | ||
| 21 | computedAsync, | ||
| 22 | onKeyStroke, | ||
| 23 | useEventListener, | ||
| 24 | useScrollLock, | ||
| 25 | useSessionStorage, | ||
| 26 | watchDebounced | ||
| 27 | } from '@vueuse/core' | ||
| 28 | import { useFocusTrap } from '@vueuse/integrations/useFocusTrap' | ||
| 29 | import { AnimatePresence } from 'motion-v' | ||
| 30 | |||
| 31 | // @ts-ignore | ||
| 32 | import localSearchIndex from '@localSearchIndex' | ||
| 33 | |||
| 34 | import { | ||
| 35 | File, | ||
| 36 | Hash, | ||
| 37 | ArrowRight | ||
| 38 | } from 'lucide-vue-next' | ||
| 39 | |||
| 40 | import Mark from 'mark.js/dist/mark.es6.js' | ||
| 41 | import { sidebar } from '../../../configs/constants' | ||
| 42 | import type { PageLink } from '../../plugins/urlSearchPlugin' | ||
| 43 | import { LRUCache } from '../../composables/search/lru-cache' | ||
| 44 | import { createSearchTranslate } from '../../composables/search/translation' | ||
| 45 | import { useData } from '../../composables/search/use-data' | ||
| 46 | import { useEffects } from '../../composables/useEffects' | ||
| 47 | import { applyFavicons, useFavicons } from '../../composables/useFavicons' | ||
| 48 | import { registerGlobalComponents } from '../../globalComponents' | ||
| 49 | import { | ||
| 50 | excerptPreload, | ||
| 51 | saveHistoryEnabled, | ||
| 52 | searchHistory, | ||
| 53 | searchMode, | ||
| 54 | searchResultHighlightMode, | ||
| 55 | showDetailedList, | ||
| 56 | type SearchHistoryEntry, | ||
| 57 | type SearchSortMode | ||
| 58 | } from '../../searchState' | ||
| 59 | import { enhanceAppWithTabs } from '../tabs' | ||
| 60 | |||
| 61 | import type { | ||
| 62 | FooterTranslations, | ||
| 63 | ModalTranslations, | ||
| 64 | Result, | ||
| 65 | PageGroupCount, | ||
| 66 | UrlResult, | ||
| 67 | TextSearchWorkerPayload, | ||
| 68 | UrlSearchWorkerPayload, | ||
| 69 | SearchWorkerRequest | ||
| 70 | } from './types' | ||
| 71 | |||
| 72 | import { | ||
| 73 | escapeHtml, | ||
| 74 | highlightUrl, | ||
| 75 | formMarkRegex, | ||
| 76 | toHistoryPathHtml, | ||
| 77 | hasExcerptPreview, | ||
| 78 | getPageKey, | ||
| 79 | getDocId, | ||
| 80 | getDocAnchor, | ||
| 81 | getPageLabel, | ||
| 82 | getPageOrder, | ||
| 83 | buildResultHref, | ||
| 84 | getSearchResultHref, | ||
| 85 | cycleSearchMode, | ||
| 86 | stripNonCloneable, | ||
| 87 | getPageOrderEntries, | ||
| 88 | nextFrame | ||
| 89 | } from './utils' | ||
| 90 | |||
| 91 | import { useSearchMotion } from './SearchMotion' | ||
| 92 | |||
| 93 | import SearchBar from './SearchBar.vue' | ||
| 94 | import SearchRibbon from './SearchRibbon.vue' | ||
| 95 | import SearchPagination from './SearchPagination.vue' | ||
| 96 | import SearchKeyboardShortcuts from './SearchKeyboardShortcuts.vue' | ||
| 97 | import SearchEmptyState from './SearchEmptyState.vue' | ||
| 98 | import SearchHistory from './SearchHistory.vue' | ||
| 99 | import SearchSettings from './SearchSettings.vue' | ||
| 100 | |||
| 101 | const showSearch = defineModel<boolean>() | ||
| 102 | |||
| 103 | const el = shallowRef<HTMLElement>() | ||
| 104 | const resultsEl = shallowRef<HTMLElement>() | ||
| 105 | const searchBarRef = ref<InstanceType<typeof SearchBar>>() | ||
| 106 | const ribbonRef = ref<InstanceType<typeof SearchRibbon>>() | ||
| 107 | |||
| 108 | /* Refs exposed by SearchBar */ | ||
| 109 | const searchInput = computed(() => searchBarRef.value?.searchInput as HTMLInputElement | undefined) | ||
| 110 | const settingsButtonRef = computed(() => searchBarRef.value?.settingsButtonRef as HTMLButtonElement | undefined) | ||
| 111 | |||
| 112 | /* Search */ | ||
| 113 | const searchIndexData = shallowRef(localSearchIndex) | ||
| 114 | const searchIndexVersion = ref(0) | ||
| 115 | |||
| 116 | // @ts-ignore | ||
| 117 | if (import.meta.hot) { | ||
| 118 | // @ts-ignore | ||
| 119 | import.meta.hot.accept('@localSearchIndex', (m) => { | ||
| 120 | if (m) { | ||
| 121 | searchIndexData.value = m.default | ||
| 122 | searchIndexVersion.value++ | ||
| 123 | } | ||
| 124 | }) | ||
| 125 | } | ||
| 126 | |||
| 127 | const vitePressData = useData() | ||
| 128 | const { activate } = useFocusTrap(el, { | ||
| 129 | immediate: true, | ||
| 130 | allowOutsideClick: true, | ||
| 131 | clickOutsideDeactivates: true, | ||
| 132 | escapeDeactivates: true, | ||
| 133 | returnFocusOnDeactivate: false, | ||
| 134 | initialFocus: () => searchInput.value | ||
| 135 | }) | ||
| 136 | const { localeIndex, theme } = vitePressData | ||
| 137 | |||
| 138 | const disableQueryPersistence = computed(() => { | ||
| 139 | return ( | ||
| 140 | theme.value.search?.provider === 'local' && | ||
| 141 | theme.value.search.options?.disableQueryPersistence === true | ||
| 142 | ) | ||
| 143 | }) | ||
| 144 | |||
| 145 | const filterText = disableQueryPersistence.value | ||
| 146 | ? ref('') | ||
| 147 | : useSessionStorage('vitepress:local-search-filter', '') | ||
| 148 | |||
| 149 | const { effectsEnabled: searchAnimationsEnabled } = useEffects() | ||
| 150 | const { faviconsEnabled } = useFavicons() | ||
| 151 | const showKeyboardShortcuts = computed(() => !filterText.value) | ||
| 152 | |||
| 153 | // Motion config | ||
| 154 | const { | ||
| 155 | searchMotionDiv, | ||
| 156 | searchMotionForm, | ||
| 157 | searchMotionLi, | ||
| 158 | backdropMotion, | ||
| 159 | shellMotion, | ||
| 160 | formMotion, | ||
| 161 | ribbonMotion, | ||
| 162 | emptyStateMotion, | ||
| 163 | resultMotion, | ||
| 164 | excerptMotion, | ||
| 165 | footerMotion | ||
| 166 | } = useSearchMotion(searchAnimationsEnabled) | ||
| 167 | |||
| 168 | const urlFilterDebounced = ref(filterText.value) | ||
| 169 | let urlDebounceTimer: ReturnType<typeof setTimeout> | undefined | ||
| 170 | watch(filterText, (v) => { | ||
| 171 | clearTimeout(urlDebounceTimer) | ||
| 172 | if (!v) { | ||
| 173 | urlFilterDebounced.value = '' | ||
| 174 | return | ||
| 175 | } | ||
| 176 | urlDebounceTimer = setTimeout(() => { | ||
| 177 | urlFilterDebounced.value = v | ||
| 178 | }, 60) | ||
| 179 | }) | ||
| 180 | onBeforeUnmount(() => clearTimeout(urlDebounceTimer)) | ||
| 181 | |||
| 182 | const matchExact = computed(() => searchMode.value === 'exact') | ||
| 183 | const urlSearchMode = computed(() => searchMode.value === 'url') | ||
| 184 | |||
| 185 | const showHistory = computed( | ||
| 186 | () => !filterText.value && searchHistory.value.length > 0 | ||
| 187 | ) | ||
| 188 | |||
| 189 | function saveToHistory( | ||
| 190 | query: string, | ||
| 191 | mode: SearchSortMode, | ||
| 192 | path?: string[], | ||
| 193 | href?: string, | ||
| 194 | resultText?: string | ||
| 195 | ) { | ||
| 196 | const trimmed = query.trim() | ||
| 197 | if (!trimmed || !saveHistoryEnabled.value) return | ||
| 198 | const pathKey = (path ?? []).join('\n') | ||
| 199 | searchHistory.value = [ | ||
| 200 | { query: trimmed, mode, path, href, resultText }, | ||
| 201 | ...searchHistory.value.filter( | ||
| 202 | (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey) | ||
| 203 | ) | ||
| 204 | ] | ||
| 205 | } | ||
| 206 | |||
| 207 | function removeFromHistory(index: number) { | ||
| 208 | searchHistory.value = searchHistory.value.filter((_, i) => i !== index) | ||
| 209 | } | ||
| 210 | |||
| 211 | function applyHistory(entry: SearchHistoryEntry) { | ||
| 212 | if (entry.href) { | ||
| 213 | window.dispatchEvent( | ||
| 214 | new CustomEvent('search-nav', { | ||
| 215 | detail: { query: entry.query, resultText: entry.resultText } | ||
| 216 | }) | ||
| 217 | ) | ||
| 218 | router.go(entry.href) | ||
| 219 | showSearch.value = false | ||
| 220 | return | ||
| 221 | } | ||
| 222 | searchMode.value = entry.mode | ||
| 223 | filterText.value = entry.query | ||
| 224 | nextTick(() => focusSearchInput(false)) | ||
| 225 | } | ||
| 226 | |||
| 227 | // Settings popup | ||
| 228 | const showSettingsPopup = ref(false) | ||
| 229 | |||
| 230 | // Page groups & URL search state | ||
| 231 | interface PageGroupCount { key: string; count: number } | ||
| 232 | |||
| 233 | const urlMatches = shallowRef<PageLink[]>([]) | ||
| 234 | const urlPageGroupCounts = shallowRef<PageGroupCount[]>([]) | ||
| 235 | |||
| 236 | const URL_PAGE_SIZE = 25 | ||
| 237 | const urlPage = ref(1) | ||
| 238 | const urlActivePageFilter = ref<string | null>(null) | ||
| 239 | |||
| 240 | const urlPageGroups = computed(() => | ||
| 241 | urlPageGroupCounts.value | ||
| 242 | .map((group) => ({ | ||
| 243 | key: group.key, | ||
| 244 | label: getPageLabel(group.key, pageMeta), | ||
| 245 | count: group.count | ||
| 246 | })) | ||
| 247 | .sort((a, b) => getPageOrder(a.key, pageMeta) - getPageOrder(b.key, pageMeta)) | ||
| 248 | ) | ||
| 249 | |||
| 250 | const urlFilteredMatches = computed((): PageLink[] => { | ||
| 251 | if (!urlActivePageFilter.value) return urlMatches.value | ||
| 252 | return urlMatches.value.filter((l) => l.pageId === urlActivePageFilter.value) | ||
| 253 | }) | ||
| 254 | |||
| 255 | const urlTotalPages = computed(() => | ||
| 256 | Math.max(1, Math.ceil(urlFilteredMatches.value.length / URL_PAGE_SIZE)) | ||
| 257 | ) | ||
| 258 | |||
| 259 | const urlCurrentPage = computed(() => | ||
| 260 | Math.min(urlPage.value, urlTotalPages.value) | ||
| 261 | ) | ||
| 262 | |||
| 263 | const filteredUrlResults = computed((): UrlResult[] => { | ||
| 264 | const matches = urlFilteredMatches.value | ||
| 265 | const start = (urlCurrentPage.value - 1) * URL_PAGE_SIZE | ||
| 266 | const end = start + URL_PAGE_SIZE | ||
| 267 | const out: UrlResult[] = [] | ||
| 268 | const query = urlFilterDebounced.value.trim() | ||
| 269 | for (let i = start; i < end && i < matches.length; i++) { | ||
| 270 | const link = matches[i] | ||
| 271 | out.push({ | ||
| 272 | href: link.href, | ||
| 273 | linkText: link.linkText, | ||
| 274 | pageId: link.pageId, | ||
| 275 | anchor: link.anchor, | ||
| 276 | titles: link.titles, | ||
| 277 | tabs: link.tabs, | ||
| 278 | highlighted: highlightUrl(link.href, query) | ||
| 279 | }) | ||
| 280 | } | ||
| 281 | return out | ||
| 282 | }) | ||
| 283 | |||
| 284 | const urlPageList = computed<(number | '…')[]>(() => { | ||
| 285 | const total = urlTotalPages.value | ||
| 286 | const current = urlCurrentPage.value | ||
| 287 | if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1) | ||
| 288 | const pages: (number | '…')[] = [1] | ||
| 289 | const left = Math.max(2, current - 1) | ||
| 290 | const right = Math.min(total - 1, current + 1) | ||
| 291 | if (left > 2) pages.push('…') | ||
| 292 | for (let p = left; p <= right; p++) pages.push(p) | ||
| 293 | if (right < total - 1) pages.push('…') | ||
| 294 | pages.push(total) | ||
| 295 | return pages | ||
| 296 | }) | ||
| 297 | |||
| 298 | function goToUrlPage(p: number) { | ||
| 299 | const target = Math.min(Math.max(1, p), urlTotalPages.value) | ||
| 300 | if (target === urlCurrentPage.value) return | ||
| 301 | urlPage.value = target | ||
| 302 | selectedIndex.value = filteredUrlResults.value.length ? 1 : -1 | ||
| 303 | nextTick(() => { | ||
| 304 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 305 | scrollToSelectedResult() | ||
| 306 | }) | ||
| 307 | } | ||
| 308 | |||
| 309 | watch([urlFilterDebounced, urlActivePageFilter], () => { urlPage.value = 1 }) | ||
| 310 | |||
| 311 | watch(urlMatches, () => { | ||
| 312 | if ( | ||
| 313 | urlActivePageFilter.value && | ||
| 314 | !urlPageGroups.value.some((g) => g.key === urlActivePageFilter.value) | ||
| 315 | ) { | ||
| 316 | urlActivePageFilter.value = null | ||
| 317 | } | ||
| 318 | }) | ||
| 319 | |||
| 320 | watch(urlSearchMode, (active) => { | ||
| 321 | if (!active) { | ||
| 322 | urlActivePageFilter.value = null | ||
| 323 | urlPage.value = 1 | ||
| 324 | } | ||
| 325 | }) | ||
| 326 | |||
| 327 | function setUrlPageFilter(key: string | null) { | ||
| 328 | urlActivePageFilter.value = urlActivePageFilter.value === key ? null : key | ||
| 329 | urlPage.value = 1 | ||
| 330 | selectedIndex.value = filteredUrlResults.value.length ? 1 : -1 | ||
| 331 | nextTick(() => { | ||
| 332 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 333 | scrollToSelectedResult() | ||
| 334 | }) | ||
| 335 | } | ||
| 336 | |||
| 337 | const disableDetailedView = computed(() => { | ||
| 338 | return ( | ||
| 339 | theme.value.search?.provider === 'local' && | ||
| 340 | theme.value.search.options?.detailedView === false | ||
| 341 | ) | ||
| 342 | }) | ||
| 343 | |||
| 344 | const buttonText = computed(() => { | ||
| 345 | const options = theme.value.search?.options | ||
| 346 | return ( | ||
| 347 | options?.locales?.[localeIndex.value]?.translations?.button?.buttonText || | ||
| 348 | options?.translations?.button?.buttonText || | ||
| 349 | 'Search' | ||
| 350 | ) | ||
| 351 | }) | ||
| 352 | |||
| 353 | watchEffect(() => { | ||
| 354 | if (disableDetailedView.value) { | ||
| 355 | showDetailedList.value = false | ||
| 356 | } | ||
| 357 | }) | ||
| 358 | |||
| 359 | const results: Ref<(SearchResult & Result)[]> = shallowRef([]) | ||
| 360 | const currentTerms = shallowRef(new Set<string>()) | ||
| 361 | const enableNoResults = ref(false) | ||
| 362 | const textSearchLoading = ref(false) | ||
| 363 | const urlSearchLoading = ref(false) | ||
| 364 | const searchLoading = computed(() => | ||
| 365 | urlSearchMode.value ? urlSearchLoading.value : textSearchLoading.value | ||
| 366 | ) | ||
| 367 | |||
| 368 | const pageMeta = (() => { | ||
| 369 | const map = new Map<string, { label: string; order: number }>() | ||
| 370 | let order = 0 | ||
| 371 | const stripIcon = (text: string) => | ||
| 372 | text.replace(/<[^>]*>/g, '').replace(/\s+/g, ' ').trim() | ||
| 373 | const walk = (items: DefaultTheme.SidebarItem[]) => { | ||
| 374 | for (const item of items) { | ||
| 375 | if (item.link) { | ||
| 376 | const key = item.link.replace(/\/$/, '') | ||
| 377 | if (!map.has(key)) { | ||
| 378 | map.set(key, { label: stripIcon(item.text ?? key), order: order++ }) | ||
| 379 | } | ||
| 380 | } | ||
| 381 | if (item.items) walk(item.items) | ||
| 382 | } | ||
| 383 | } | ||
| 384 | walk(sidebar as DefaultTheme.SidebarItem[]) | ||
| 385 | return map | ||
| 386 | })() | ||
| 387 | |||
| 388 | const activePageFilter = ref<string | null>(null) | ||
| 389 | const searchWorkerReady = ref(false) | ||
| 390 | const searchWorkerConfigKey = computed(() => | ||
| 391 | JSON.stringify(getMiniSearchWorkerConfig()) | ||
| 392 | ) | ||
| 393 | |||
| 394 | let searchWorker: Worker | undefined | ||
| 395 | let searchWorkerRequestId = 0 | ||
| 396 | let loadedWorkerIndexKey = '' | ||
| 397 | let preloadedSearchDataKey = '' | ||
| 398 | let preloadSearchDataRequest: { key: string; promise: Promise<void> } | undefined | ||
| 399 | const searchWorkerRequests = new Map< | ||
| 400 | number, | ||
| 401 | { resolve: (value: unknown) => void; reject: (reason?: unknown) => void } | ||
| 402 | >() | ||
| 403 | |||
| 404 | function getMiniSearchWorkerConfig() { | ||
| 405 | const miniSearch = theme.value.search?.provider === 'local' | ||
| 406 | ? theme.value.search.options?.miniSearch | ||
| 407 | : undefined | ||
| 408 | const rawSearchOptions = miniSearch?.searchOptions as Record<string, unknown> | undefined | ||
| 409 | return { | ||
| 410 | options: stripNonCloneable(miniSearch?.options) as Record<string, unknown> | undefined, | ||
| 411 | searchOptions: stripNonCloneable(rawSearchOptions) as Record<string, unknown> | undefined, | ||
| 412 | useDefaultBoostDocument: typeof rawSearchOptions?.boostDocument === 'function' | ||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | async function preloadSearchData( | ||
| 417 | localeIndexValue: string, | ||
| 418 | indexVersion: number, | ||
| 419 | configKey: string | ||
| 420 | ) { | ||
| 421 | const workerIndexKey = `${localeIndexValue}\n${indexVersion}\n${configKey}` | ||
| 422 | if (preloadedSearchDataKey === workerIndexKey) return | ||
| 423 | if (preloadSearchDataRequest?.key === workerIndexKey) { | ||
| 424 | await preloadSearchDataRequest.promise | ||
| 425 | return | ||
| 426 | } | ||
| 427 | |||
| 428 | const promise = (async () => { | ||
| 429 | if (loadedWorkerIndexKey !== workerIndexKey) { | ||
| 430 | const indexJson = (await searchIndexData.value[localeIndexValue]?.())?.default | ||
| 431 | await postSearchWorker<void>({ | ||
| 432 | type: 'load-index', | ||
| 433 | localeIndex: localeIndexValue, | ||
| 434 | indexJson, | ||
| 435 | indexVersion, | ||
| 436 | config: getMiniSearchWorkerConfig() | ||
| 437 | }) | ||
| 438 | loadedWorkerIndexKey = workerIndexKey | ||
| 439 | } | ||
| 440 | |||
| 441 | await postSearchWorker<void>({ | ||
| 442 | type: 'preload-metadata', | ||
| 443 | pageOrderEntries: getPageOrderEntries(pageMeta) | ||
| 444 | }) | ||
| 445 | preloadedSearchDataKey = workerIndexKey | ||
| 446 | })() | ||
| 447 | |||
| 448 | preloadSearchDataRequest = { key: workerIndexKey, promise } | ||
| 449 | try { | ||
| 450 | await promise | ||
| 451 | } finally { | ||
| 452 | if (preloadSearchDataRequest?.promise === promise) { | ||
| 453 | preloadSearchDataRequest = undefined | ||
| 454 | } | ||
| 455 | } | ||
| 456 | } | ||
| 457 | |||
| 458 | function ensureSearchWorker() { | ||
| 459 | if (!inBrowser || searchWorker) return searchWorker | ||
| 460 | |||
| 461 | try { | ||
| 462 | searchWorker = new Worker( | ||
| 463 | new URL('../../workers/searchWorker.ts', import.meta.url), | ||
| 464 | { type: 'module' } | ||
| 465 | ) | ||
| 466 | } catch (error) { | ||
| 467 | console.error('[search] failed to start search worker', error) | ||
| 468 | return | ||
| 469 | } | ||
| 470 | |||
| 471 | searchWorker.onmessage = (event: MessageEvent) => { | ||
| 472 | const data = event.data as { id: number; type: string; payload?: unknown; error?: string } | ||
| 473 | const request = searchWorkerRequests.get(data.id) | ||
| 474 | if (!request) return | ||
| 475 | searchWorkerRequests.delete(data.id) | ||
| 476 | if (data.type.endsWith(':error')) { | ||
| 477 | request.reject(new Error(data.error ?? 'Search worker failed')) | ||
| 478 | } else { | ||
| 479 | request.resolve(data.payload) | ||
| 480 | } | ||
| 481 | } | ||
| 482 | searchWorker.onerror = (event) => { | ||
| 483 | console.error('[search] search worker error', event) | ||
| 484 | } | ||
| 485 | searchWorkerReady.value = true | ||
| 486 | return searchWorker | ||
| 487 | } | ||
| 488 | |||
| 489 | function postSearchWorker<T>(message: SearchWorkerRequest) { | ||
| 490 | const worker = ensureSearchWorker() | ||
| 491 | if (!worker) return Promise.reject(new Error('Search worker is unavailable')) | ||
| 492 | |||
| 493 | const id = ++searchWorkerRequestId | ||
| 494 | return new Promise<T>((resolve, reject) => { | ||
| 495 | searchWorkerRequests.set(id, { resolve: (value) => resolve(value as T), reject }) | ||
| 496 | worker.postMessage({ ...message, id }) | ||
| 497 | }) | ||
| 498 | } | ||
| 499 | |||
| 500 | onMounted(() => { ensureSearchWorker() }) | ||
| 501 | |||
| 502 | onBeforeUnmount(() => { | ||
| 503 | searchWorker?.terminate() | ||
| 504 | searchWorker = undefined | ||
| 505 | loadedWorkerIndexKey = '' | ||
| 506 | preloadedSearchDataKey = '' | ||
| 507 | preloadSearchDataRequest = undefined | ||
| 508 | searchWorkerReady.value = false | ||
| 509 | for (const request of searchWorkerRequests.values()) { | ||
| 510 | request.reject(new Error('Search worker was terminated')) | ||
| 511 | } | ||
| 512 | searchWorkerRequests.clear() | ||
| 513 | }) | ||
| 514 | |||
| 515 | // Watch: preload search data when search opens | ||
| 516 | watch( | ||
| 517 | () => [searchWorkerReady.value, showSearch.value, localeIndex.value, searchIndexVersion.value, searchWorkerConfigKey.value] as const, | ||
| 518 | async ([ready, isOpen, localeIndexValue, indexVersion, configKey]) => { | ||
| 519 | if (!ready || !isOpen) return | ||
| 520 | try { | ||
| 521 | await preloadSearchData(localeIndexValue, indexVersion, configKey) | ||
| 522 | } catch (error) { | ||
| 523 | console.error('[search] search data preload failed', error) | ||
| 524 | } | ||
| 525 | }, | ||
| 526 | { immediate: true } | ||
| 527 | ) | ||
| 528 | |||
| 529 | // Watch: URL search | ||
| 530 | watch( | ||
| 531 | () => [searchWorkerReady.value, showSearch.value, urlSearchMode.value, urlFilterDebounced.value] as const, | ||
| 532 | async ([ready, isOpen, active, query], _old, onCleanup) => { | ||
| 533 | let canceled = false | ||
| 534 | onCleanup(() => { canceled = true }) | ||
| 535 | if (!active || !isOpen || !query.trim()) { | ||
| 536 | urlMatches.value = [] | ||
| 537 | urlPageGroupCounts.value = [] | ||
| 538 | urlSearchLoading.value = false | ||
| 539 | return | ||
| 540 | } | ||
| 541 | if (!ready) { urlSearchLoading.value = false; return } | ||
| 542 | urlSearchLoading.value = true | ||
| 543 | try { | ||
| 544 | const payload = await postSearchWorker<UrlSearchWorkerPayload>({ | ||
| 545 | type: 'url-search', | ||
| 546 | query, | ||
| 547 | pageOrderEntries: getPageOrderEntries(pageMeta) | ||
| 548 | }) | ||
| 549 | if (canceled) return | ||
| 550 | urlMatches.value = payload.matches | ||
| 551 | urlPageGroupCounts.value = payload.pageGroups | ||
| 552 | urlSearchLoading.value = false | ||
| 553 | } catch (error) { | ||
| 554 | if (!canceled) { | ||
| 555 | console.error('[search] URL search worker request failed', error) | ||
| 556 | urlMatches.value = [] | ||
| 557 | urlPageGroupCounts.value = [] | ||
| 558 | urlSearchLoading.value = false | ||
| 559 | } | ||
| 560 | } | ||
| 561 | }, | ||
| 562 | { immediate: true } | ||
| 563 | ) | ||
| 564 | |||
| 565 | // Page groups computed | ||
| 566 | const pageGroups = computed(() => { | ||
| 567 | const map = new Map<string, { key: string; label: string; count: number }>() | ||
| 568 | for (const r of results.value) { | ||
| 569 | const key = getPageKey(r.id) | ||
| 570 | const existing = map.get(key) | ||
| 571 | if (existing) existing.count++ | ||
| 572 | else map.set(key, { key, label: getPageLabel(key, pageMeta), count: 1 }) | ||
| 573 | } | ||
| 574 | return [...map.values()].sort( | ||
| 575 | (a, b) => getPageOrder(a.key, pageMeta) - getPageOrder(b.key, pageMeta) | ||
| 576 | ) | ||
| 577 | }) | ||
| 578 | |||
| 579 | const filteredResults = computed(() => { | ||
| 580 | if (!activePageFilter.value) return results.value | ||
| 581 | return results.value.filter((r) => getPageKey(r.id) === activePageFilter.value) | ||
| 582 | }) | ||
| 583 | |||
| 584 | // Normal pagination | ||
| 585 | const NORMAL_PAGE_SIZE = URL_PAGE_SIZE | ||
| 586 | const normalPage = ref(1) | ||
| 587 | const normalTotalPages = computed(() => | ||
| 588 | Math.max(1, Math.ceil(filteredResults.value.length / NORMAL_PAGE_SIZE)) | ||
| 589 | ) | ||
| 590 | const normalCurrentPage = computed(() => | ||
| 591 | Math.min(normalPage.value, normalTotalPages.value) | ||
| 592 | ) | ||
| 593 | |||
| 594 | const pagedResults = computed(() => { | ||
| 595 | const start = (normalCurrentPage.value - 1) * NORMAL_PAGE_SIZE | ||
| 596 | return filteredResults.value.slice(start, start + NORMAL_PAGE_SIZE) | ||
| 597 | }) | ||
| 598 | |||
| 599 | const normalPageList = computed<(number | '…')[]>(() => { | ||
| 600 | const total = normalTotalPages.value | ||
| 601 | const current = normalCurrentPage.value | ||
| 602 | if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1) | ||
| 603 | const pages: (number | '…')[] = [1] | ||
| 604 | const left = Math.max(2, current - 1) | ||
| 605 | const right = Math.min(total - 1, current + 1) | ||
| 606 | if (left > 2) pages.push('…') | ||
| 607 | for (let p = left; p <= right; p++) pages.push(p) | ||
| 608 | if (right < total - 1) pages.push('…') | ||
| 609 | pages.push(total) | ||
| 610 | return pages | ||
| 611 | }) | ||
| 612 | |||
| 613 | function goToNormalPage(p: number) { | ||
| 614 | const target = Math.min(Math.max(1, p), normalTotalPages.value) | ||
| 615 | if (target === normalCurrentPage.value) return | ||
| 616 | normalPage.value = target | ||
| 617 | selectedIndex.value = pagedResults.value.length ? 1 : -1 | ||
| 618 | nextTick(() => { | ||
| 619 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 620 | scrollToSelectedResult() | ||
| 621 | reapplyHighlights() | ||
| 622 | void buildVisibleExcerpts() | ||
| 623 | }) | ||
| 624 | } | ||
| 625 | |||
| 626 | function setPageFilter(key: string | null) { | ||
| 627 | activePageFilter.value = activePageFilter.value === key ? null : key | ||
| 628 | normalPage.value = 1 | ||
| 629 | selectedIndex.value = filteredResults.value.length ? 1 : -1 | ||
| 630 | nextTick(() => { | ||
| 631 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 632 | scrollToSelectedResult() | ||
| 633 | reapplyHighlights() | ||
| 634 | void buildVisibleExcerpts() | ||
| 635 | }) | ||
| 636 | } | ||
| 637 | |||
| 638 | // Mark.js & excerpts | ||
| 639 | const mark = computedAsync(async () => { | ||
| 640 | if (!resultsEl.value) return | ||
| 641 | return markRaw(new Mark(resultsEl.value)) | ||
| 642 | }, null) | ||
| 643 | |||
| 644 | const cache = new LRUCache<string, Map<string, string>>(120) | ||
| 645 | const inFlightExcerpts = new Map<string, Promise<void>>() | ||
| 646 | const excerptCache = new LRUCache<string, unknown>(24) | ||
| 647 | |||
| 648 | async function reapplyHighlights() { | ||
| 649 | if (!showDetailedList.value || !currentTerms.value.size) { | ||
| 650 | centerExcerptsUntilSettled() | ||
| 651 | return | ||
| 652 | } | ||
| 653 | await new Promise<void>((resolve) => { | ||
| 654 | mark.value?.unmark({ | ||
| 655 | done: () => { | ||
| 656 | mark.value?.markRegExp(formMarkRegex(currentTerms.value), { | ||
| 657 | done: () => resolve() | ||
| 658 | }) | ||
| 659 | } | ||
| 660 | }) | ||
| 661 | }) | ||
| 662 | await nextTick() | ||
| 663 | centerExcerptsUntilSettled() | ||
| 664 | } | ||
| 665 | |||
| 666 | const toRows = (list: (SearchResult & Result)[]) => | ||
| 667 | list.map((r) => { | ||
| 668 | const map = cache.get(getDocId(r.id)) | ||
| 669 | return { ...r, text: map?.get(getDocAnchor(r.id)) ?? '' } | ||
| 670 | }) | ||
| 671 | |||
| 672 | let excerptBuildToken = 0 | ||
| 673 | |||
| 674 | function visiblePageDocs(pageOffset: number): string[] { | ||
| 675 | const start = (normalCurrentPage.value - 1 + pageOffset) * NORMAL_PAGE_SIZE | ||
| 676 | if (start < 0) return [] | ||
| 677 | const list = filteredResults.value | ||
| 678 | const docs: string[] = [] | ||
| 679 | const seen = new Set<string>() | ||
| 680 | for (let i = start; i < start + NORMAL_PAGE_SIZE && i < list.length; i++) { | ||
| 681 | const docId = getDocId(String(list[i].id)) | ||
| 682 | if (!seen.has(docId)) { | ||
| 683 | seen.add(docId) | ||
| 684 | docs.push(docId) | ||
| 685 | } | ||
| 686 | } | ||
| 687 | return docs | ||
| 688 | } | ||
| 689 | |||
| 690 | async function buildVisibleExcerpts() { | ||
| 691 | const token = ++excerptBuildToken | ||
| 692 | if (!showDetailedList.value || urlSearchMode.value) return | ||
| 693 | |||
| 694 | let builtAny = false | ||
| 695 | let sliceStart = performance.now() | ||
| 696 | |||
| 697 | const refreshRows = async () => { | ||
| 698 | const keepSelected = selectedIndex.value | ||
| 699 | results.value = toRows(results.value) | ||
| 700 | await nextTick() | ||
| 701 | if (token !== excerptBuildToken) return false | ||
| 702 | selectedIndex.value = keepSelected | ||
| 703 | return true | ||
| 704 | } | ||
| 705 | |||
| 706 | const buildAll = async (docIds: string[], progressive = false) => { | ||
| 707 | for (const docId of docIds) { | ||
| 708 | if (cache.get(docId)) continue | ||
| 709 | await buildDocExcerpt(docId) | ||
| 710 | if (token !== excerptBuildToken) return false | ||
| 711 | builtAny = true | ||
| 712 | if (performance.now() - sliceStart > 40) { | ||
| 713 | if (progressive && !(await refreshRows())) return false | ||
| 714 | await nextFrame() | ||
| 715 | if (token !== excerptBuildToken) return false | ||
| 716 | sliceStart = performance.now() | ||
| 717 | } | ||
| 718 | } | ||
| 719 | return true | ||
| 720 | } | ||
| 721 | |||
| 722 | if (!(await buildAll(visiblePageDocs(0), true))) return | ||
| 723 | |||
| 724 | const rowsStale = pagedResults.value.some((r) => { | ||
| 725 | if (r.text) return false | ||
| 726 | const map = cache.get(getDocId(String(r.id))) | ||
| 727 | return Boolean(map?.get(getDocAnchor(String(r.id)))) | ||
| 728 | }) | ||
| 729 | |||
| 730 | if (builtAny || rowsStale) { | ||
| 731 | if (!(await refreshRows())) return | ||
| 732 | await reapplyHighlights() | ||
| 733 | if (token !== excerptBuildToken) return | ||
| 734 | } | ||
| 735 | |||
| 736 | if (excerptPreload.value === 'next') { | ||
| 737 | await buildAll(visiblePageDocs(1)) | ||
| 738 | } else if (excerptPreload.value === 'all') { | ||
| 739 | const seen = new Set<string>() | ||
| 740 | const docs: string[] = [] | ||
| 741 | for (const r of results.value) { | ||
| 742 | const docId = getDocId(String(r.id)) | ||
| 743 | if (!seen.has(docId)) { | ||
| 744 | seen.add(docId) | ||
| 745 | docs.push(docId) | ||
| 746 | } | ||
| 747 | } | ||
| 748 | await buildAll(docs) | ||
| 749 | } | ||
| 750 | } | ||
| 751 | |||
| 752 | function buildDocExcerpt(docId: string): Promise<void> { | ||
| 753 | if (cache.get(docId)) return Promise.resolve() | ||
| 754 | const pending = inFlightExcerpts.get(docId) | ||
| 755 | if (pending) return pending | ||
| 756 | |||
| 757 | const job = (async () => { | ||
| 758 | const { mod } = await fetchExcerpt(docId) | ||
| 759 | if (cache.get(docId)) return | ||
| 760 | const comp = (mod as any).default ?? mod | ||
| 761 | if (!(comp?.render || comp?.setup)) return | ||
| 762 | |||
| 763 | const map = new Map<string, string>() | ||
| 764 | const app = createApp(comp) | ||
| 765 | app.config.warnHandler = () => {} | ||
| 766 | enhanceAppWithTabs(app, { renderAll: true }) | ||
| 767 | registerGlobalComponents(app) | ||
| 768 | app.provide(dataSymbol, vitePressData) | ||
| 769 | Object.defineProperties(app.config.globalProperties, { | ||
| 770 | $frontmatter: { get() { return vitePressData.frontmatter.value } }, | ||
| 771 | $params: { get() { return vitePressData.page.value.params } } | ||
| 772 | }) | ||
| 773 | const div = document.createElement('div') | ||
| 774 | try { | ||
| 775 | const originalCreateElement = document.createElement | ||
| 776 | document.createElement = function (this: Document, ...args: Parameters<Document['createElement']>) { | ||
| 777 | const el = originalCreateElement.apply(this, args) | ||
| 778 | if (el instanceof HTMLImageElement) { el.loading = 'lazy'; el.decoding = 'async' } | ||
| 779 | return el | ||
| 780 | } as typeof document.createElement | ||
| 781 | try { app.mount(div) } finally { document.createElement = originalCreateElement } | ||
| 782 | const headings = div.querySelectorAll('h1, h2, h3, h4, h5, h6') | ||
| 783 | headings.forEach((heading) => { | ||
| 784 | const href = heading.querySelector('a')?.getAttribute('href') | ||
| 785 | const anchor = href?.startsWith('#') && href.slice(1) | ||
| 786 | if (!anchor) return | ||
| 787 | let html = '' | ||
| 788 | let node = heading as Element | ||
| 789 | while ((node = node.nextElementSibling!) && !/^h[1-6]$/i.test(node.tagName)) { | ||
| 790 | html += (node as HTMLElement).outerHTML | ||
| 791 | } | ||
| 792 | map.set(anchor, html) | ||
| 793 | }) | ||
| 794 | } catch (e) { | ||
| 795 | console.error('[search] excerpt render failed for', docId, e) | ||
| 796 | } finally { | ||
| 797 | try { app.unmount() } catch { /* ignore */ } | ||
| 798 | } | ||
| 799 | cache.set(docId, map) | ||
| 800 | })() | ||
| 801 | |||
| 802 | inFlightExcerpts.set(docId, job) | ||
| 803 | job.finally(() => { | ||
| 804 | if (inFlightExcerpts.get(docId) === job) inFlightExcerpts.delete(docId) | ||
| 805 | }) | ||
| 806 | return job | ||
| 807 | } | ||
| 808 | |||
| 809 | async function fetchExcerpt(id: string) { | ||
| 810 | const docId = getDocId(id) | ||
| 811 | const cached = excerptCache.get(docId) | ||
| 812 | if (cached) return { id, mod: cached } | ||
| 813 | const file = pathToFile(docId) | ||
| 814 | try { | ||
| 815 | if (!file) throw new Error(`Cannot find file for id: ${id}`) | ||
| 816 | const mod = await import(/*@vite-ignore*/ file) | ||
| 817 | excerptCache.set(docId, mod) | ||
| 818 | return { id, mod } | ||
| 819 | } catch (e) { | ||
| 820 | console.error(e) | ||
| 821 | return { id, mod: {} } | ||
| 822 | } | ||
| 823 | } | ||
| 824 | |||
| 825 | watch(excerptPreload, () => { void buildVisibleExcerpts() }) | ||
| 826 | |||
| 827 | watch(results, () => { | ||
| 828 | if ( | ||
| 829 | activePageFilter.value && | ||
| 830 | !pageGroups.value.some((g) => g.key === activePageFilter.value) | ||
| 831 | ) { | ||
| 832 | activePageFilter.value = null | ||
| 833 | } | ||
| 834 | }) | ||
| 835 | |||
| 836 | watch(filterText, () => { enableNoResults.value = false }) | ||
| 837 | |||
| 838 | // Debounced text search | ||
| 839 | watchDebounced( | ||
| 840 | () => [searchWorkerReady.value, showSearch.value, localeIndex.value, searchIndexVersion.value, searchWorkerConfigKey.value, filterText.value, showDetailedList.value, searchMode.value] as const, | ||
| 841 | async ([ready, isOpen, localeIndexValue, indexVersion, configKey, filterTextValue, showDetailedListValue, mode], old, onCleanup) => { | ||
| 842 | if (old?.[2] !== localeIndexValue || old?.[3] !== indexVersion || old?.[4] !== configKey) { | ||
| 843 | cache.clear() | ||
| 844 | } | ||
| 845 | let canceled = false | ||
| 846 | onCleanup(() => { canceled = true }) | ||
| 847 | excerptBuildToken++ | ||
| 848 | if (!ready || !isOpen) { textSearchLoading.value = false; return } | ||
| 849 | |||
| 850 | if (mode === 'url') { | ||
| 851 | results.value = [] | ||
| 852 | currentTerms.value = new Set() | ||
| 853 | enableNoResults.value = Boolean(filterTextValue.trim()) | ||
| 854 | textSearchLoading.value = false | ||
| 855 | return | ||
| 856 | } | ||
| 857 | |||
| 858 | const searchQuery = filterTextValue.trim() | ||
| 859 | textSearchLoading.value = Boolean(searchQuery) | ||
| 860 | try { | ||
| 861 | await preloadSearchData(localeIndexValue, indexVersion, configKey) | ||
| 862 | if (canceled) return | ||
| 863 | } catch (error) { | ||
| 864 | if (!canceled) { | ||
| 865 | console.error('[search] text search index preload failed', error) | ||
| 866 | results.value = []; currentTerms.value = new Set() | ||
| 867 | enableNoResults.value = Boolean(searchQuery); textSearchLoading.value = false | ||
| 868 | } | ||
| 869 | return | ||
| 870 | } | ||
| 871 | if (!searchQuery) { | ||
| 872 | results.value = []; currentTerms.value = new Set() | ||
| 873 | enableNoResults.value = false; textSearchLoading.value = false | ||
| 874 | return | ||
| 875 | } | ||
| 876 | |||
| 877 | let workerPayload: TextSearchWorkerPayload | ||
| 878 | try { | ||
| 879 | workerPayload = await postSearchWorker<TextSearchWorkerPayload>({ | ||
| 880 | type: 'text-search', | ||
| 881 | query: searchQuery, | ||
| 882 | mode, | ||
| 883 | pageOrderEntries: getPageOrderEntries(pageMeta) | ||
| 884 | }) | ||
| 885 | } catch (error) { | ||
| 886 | if (!canceled) { | ||
| 887 | console.error('[search] text search worker request failed', error) | ||
| 888 | results.value = []; currentTerms.value = new Set() | ||
| 889 | enableNoResults.value = true; textSearchLoading.value = false | ||
| 890 | } | ||
| 891 | return | ||
| 892 | } | ||
| 893 | if (canceled) return | ||
| 894 | |||
| 895 | const _result = workerPayload.results | ||
| 896 | const terms = new Set(workerPayload.terms) | ||
| 897 | currentTerms.value = terms | ||
| 898 | enableNoResults.value = true | ||
| 899 | if (!_result.length) { results.value = []; textSearchLoading.value = false; return } | ||
| 900 | |||
| 901 | const highlight = () => | ||
| 902 | new Promise<void>((resolve) => { | ||
| 903 | if (!terms.size || !mark.value) { resolve(); return } | ||
| 904 | mark.value.unmark({ | ||
| 905 | done: () => { | ||
| 906 | mark.value?.markRegExp(formMarkRegex(terms), { done: () => resolve() }) | ||
| 907 | } | ||
| 908 | }) | ||
| 909 | }) | ||
| 910 | |||
| 911 | normalPage.value = 1 | ||
| 912 | results.value = toRows(_result) | ||
| 913 | await nextTick() | ||
| 914 | if (canceled) return | ||
| 915 | await highlight() | ||
| 916 | await nextTick() | ||
| 917 | await nextFrame() | ||
| 918 | if (canceled) return | ||
| 919 | if (resultsEl.value) resultsEl.value.scrollTop = 0 | ||
| 920 | centerExcerptsUntilSettled() | ||
| 921 | if (showDetailedListValue) { | ||
| 922 | await buildVisibleExcerpts() | ||
| 923 | if (canceled) return | ||
| 924 | } | ||
| 925 | textSearchLoading.value = false | ||
| 926 | }, | ||
| 927 | { debounce: 80, immediate: true } | ||
| 928 | ) | ||
| 929 | |||
| 930 | // Excerpt centering | ||
| 931 | function centerExcerpts() { | ||
| 932 | const excerpts = el.value?.querySelectorAll('.result .excerpt') ?? [] | ||
| 933 | for (let i = 0; i < excerpts.length; i++) { | ||
| 934 | const excerptElement = excerpts[i] as HTMLElement | ||
| 935 | const markNode = excerptElement.querySelector('mark[data-markjs="true"]') as HTMLElement | null | ||
| 936 | if (!markNode) continue | ||
| 937 | const viewportHeight = excerptElement.clientHeight || 84 | ||
| 938 | let offset = 0 | ||
| 939 | let node: HTMLElement | null = markNode | ||
| 940 | while (node && node !== excerptElement) { | ||
| 941 | offset += node.offsetTop | ||
| 942 | node = node.offsetParent as HTMLElement | null | ||
| 943 | } | ||
| 944 | const targetScrollTop = offset - viewportHeight / 2 + markNode.offsetHeight / 2 | ||
| 945 | excerptElement.scrollTop = Math.max(0, targetScrollTop) | ||
| 946 | } | ||
| 947 | } | ||
| 948 | |||
| 949 | let centerHandle = 0 | ||
| 950 | |||
| 951 | function centerExcerptsUntilSettled(duration = searchAnimationsEnabled.value ? 450 : 0) { | ||
| 952 | if (centerHandle) cancelAnimationFrame(centerHandle) | ||
| 953 | if (duration <= 0) { | ||
| 954 | centerHandle = requestAnimationFrame(() => { centerExcerpts(); centerHandle = 0 }) | ||
| 955 | return | ||
| 956 | } | ||
| 957 | const start = performance.now() | ||
| 958 | const tick = () => { | ||
| 959 | centerExcerpts() | ||
| 960 | if (performance.now() - start < duration) { | ||
| 961 | centerHandle = requestAnimationFrame(tick) | ||
| 962 | } else { centerHandle = 0 } | ||
| 963 | } | ||
| 964 | centerHandle = requestAnimationFrame(tick) | ||
| 965 | } | ||
| 966 | |||
| 967 | onBeforeUnmount(() => { | ||
| 968 | if (centerHandle) cancelAnimationFrame(centerHandle) | ||
| 969 | }) | ||
| 970 | |||
| 971 | // Search input | ||
| 972 | const disableReset = computed(() => filterText.value?.length <= 0) | ||
| 973 | |||
| 974 | function focusSearchInput(select = true) { | ||
| 975 | searchInput.value?.focus() | ||
| 976 | select && searchInput.value?.select() | ||
| 977 | } | ||
| 978 | |||
| 979 | onMounted(() => { focusSearchInput() }) | ||
| 980 | |||
| 981 | function onSearchBarClick(event: PointerEvent) { | ||
| 982 | if (event.pointerType === 'mouse') focusSearchInput() | ||
| 983 | } | ||
| 984 | |||
| 985 | // Keyboard navigation | ||
| 986 | const selectedIndex = ref(-1) | ||
| 987 | const disableMouseOver = ref(true) | ||
| 988 | |||
| 989 | const activeResultsLength = computed(() => | ||
| 990 | urlSearchMode.value ? filteredUrlResults.value.length : pagedResults.value.length | ||
| 991 | ) | ||
| 992 | |||
| 993 | watch(pagedResults, (r) => { | ||
| 994 | if (!urlSearchMode.value) { selectedIndex.value = r.length ? 0 : -1; scrollToSelectedResult() } | ||
| 995 | }) | ||
| 996 | |||
| 997 | watch(filteredUrlResults, (r) => { | ||
| 998 | if (urlSearchMode.value) { selectedIndex.value = r.length ? 0 : -1; scrollToSelectedResult() } | ||
| 999 | }) | ||
| 1000 | |||
| 1001 | watch([pagedResults, filteredUrlResults, faviconsEnabled], () => { | ||
| 1002 | if (!faviconsEnabled.value) return | ||
| 1003 | nextTick(() => { if (resultsEl.value) applyFavicons(resultsEl.value) }) | ||
| 1004 | }) | ||
| 1005 | |||
| 1006 | function scrollToSelectedResult() { | ||
| 1007 | nextTick(() => { | ||
| 1008 | const selectedEl = document.querySelector('.result.selected') | ||
| 1009 | selectedEl?.scrollIntoView({ block: 'nearest' }) | ||
| 1010 | }) | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | function goToSearchPageDelta(delta: number) { | ||
| 1014 | if (urlSearchMode.value) { | ||
| 1015 | const target = urlCurrentPage.value + delta | ||
| 1016 | if (target < 1 || target > urlTotalPages.value) return false | ||
| 1017 | goToUrlPage(target) | ||
| 1018 | return true | ||
| 1019 | } | ||
| 1020 | const target = normalCurrentPage.value + delta | ||
| 1021 | if (target < 1 || target > normalTotalPages.value) return false | ||
| 1022 | goToNormalPage(target) | ||
| 1023 | return true | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | function cyclePageTab(delta: number) { | ||
| 1027 | if (urlSearchMode.value) { | ||
| 1028 | if (urlPageGroups.value.length <= 1) return false | ||
| 1029 | const keys = [null, ...urlPageGroups.value.map((group) => group.key)] | ||
| 1030 | const current = keys.indexOf(urlActivePageFilter.value) | ||
| 1031 | const next = (current + delta + keys.length) % keys.length | ||
| 1032 | setUrlPageFilter(keys[next]) | ||
| 1033 | ribbonRef.value?.scrollActivePagePillIntoView(delta) | ||
| 1034 | return true | ||
| 1035 | } | ||
| 1036 | if (pageGroups.value.length <= 1) return false | ||
| 1037 | const keys = [null, ...pageGroups.value.map((group) => group.key)] | ||
| 1038 | const current = keys.indexOf(activePageFilter.value) | ||
| 1039 | const next = (current + delta + keys.length) % keys.length | ||
| 1040 | setPageFilter(keys[next]) | ||
| 1041 | ribbonRef.value?.scrollActivePagePillIntoView(delta) | ||
| 1042 | return true | ||
| 1043 | } | ||
| 1044 | |||
| 1045 | onKeyStroke('ArrowUp', (event) => { | ||
| 1046 | event.preventDefault() | ||
| 1047 | selectedIndex.value-- | ||
| 1048 | if (selectedIndex.value < 0) selectedIndex.value = activeResultsLength.value - 1 | ||
| 1049 | disableMouseOver.value = true | ||
| 1050 | scrollToSelectedResult() | ||
| 1051 | }) | ||
| 1052 | |||
| 1053 | onKeyStroke('ArrowDown', (event) => { | ||
| 1054 | event.preventDefault() | ||
| 1055 | selectedIndex.value++ | ||
| 1056 | if (selectedIndex.value >= activeResultsLength.value + 1) selectedIndex.value = 0 | ||
| 1057 | disableMouseOver.value = true | ||
| 1058 | scrollToSelectedResult() | ||
| 1059 | }) | ||
| 1060 | |||
| 1061 | onKeyStroke('ArrowLeft', (event) => { | ||
| 1062 | if (!goToSearchPageDelta(-1)) return | ||
| 1063 | event.preventDefault() | ||
| 1064 | disableMouseOver.value = true | ||
| 1065 | }) | ||
| 1066 | |||
| 1067 | onKeyStroke('ArrowRight', (event) => { | ||
| 1068 | if (!goToSearchPageDelta(1)) return | ||
| 1069 | event.preventDefault() | ||
| 1070 | disableMouseOver.value = true | ||
| 1071 | }) | ||
| 1072 | |||
| 1073 | onKeyStroke('Tab', (event) => { | ||
| 1074 | if (!showSearch.value) return | ||
| 1075 | if (!cyclePageTab(event.shiftKey ? -1 : 1)) return | ||
| 1076 | event.preventDefault() | ||
| 1077 | disableMouseOver.value = true | ||
| 1078 | }) | ||
| 1079 | |||
| 1080 | const router = useRouter() | ||
| 1081 | |||
| 1082 | function navigateToUrlResult(item: UrlResult) { | ||
| 1083 | saveToHistory( | ||
| 1084 | filterText.value, searchMode.value, | ||
| 1085 | [getPageLabel(item.pageId, pageMeta), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean), | ||
| 1086 | buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText | ||
| 1087 | ) | ||
| 1088 | window.dispatchEvent( | ||
| 1089 | new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: item.linkText } }) | ||
| 1090 | ) | ||
| 1091 | router.go(buildResultHref(item.pageId, item.tabs, item.anchor)) | ||
| 1092 | showSearch.value = false | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | onKeyStroke('Enter', (e) => { | ||
| 1096 | if (e.isComposing) return | ||
| 1097 | if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') return | ||
| 1098 | |||
| 1099 | const index = selectedIndex.value - 1 | ||
| 1100 | if (index === -1) { | ||
| 1101 | // @ts-ignore | ||
| 1102 | window.toggleAI({ value: filterText.value }) | ||
| 1103 | showSearch.value = false | ||
| 1104 | return | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | if (urlSearchMode.value) { | ||
| 1108 | const selectedUrl = filteredUrlResults.value[index] | ||
| 1109 | if (selectedUrl) navigateToUrlResult(selectedUrl) | ||
| 1110 | return | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | const selectedPackage = pagedResults.value[index] | ||
| 1114 | if (e.target instanceof HTMLInputElement && !selectedPackage) { e.preventDefault(); return } | ||
| 1115 | if (selectedPackage) { | ||
| 1116 | saveToHistory( | ||
| 1117 | filterText.value, searchMode.value, | ||
| 1118 | [getPageLabel(getPageKey(String(selectedPackage.id)), pageMeta), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean), | ||
| 1119 | getSearchResultHref(selectedPackage), selectedPackage.title | ||
| 1120 | ) | ||
| 1121 | window.dispatchEvent( | ||
| 1122 | new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: selectedPackage.title } }) | ||
| 1123 | ) | ||
| 1124 | router.go(getSearchResultHref(selectedPackage)) | ||
| 1125 | showSearch.value = false | ||
| 1126 | } | ||
| 1127 | }) | ||
| 1128 | |||
| 1129 | function onResultClick(item: SearchResult & Result) { | ||
| 1130 | saveToHistory( | ||
| 1131 | filterText.value, searchMode.value, | ||
| 1132 | [getPageLabel(getPageKey(String(item.id)), pageMeta), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean), | ||
| 1133 | getSearchResultHref(item), item.title | ||
| 1134 | ) | ||
| 1135 | window.dispatchEvent( | ||
| 1136 | new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: item.title } }) | ||
| 1137 | ) | ||
| 1138 | showSearch.value = false | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | onKeyStroke('Escape', () => { | ||
| 1142 | if (showSettingsPopup.value) { showSettingsPopup.value = false; return } | ||
| 1143 | showSearch.value = false | ||
| 1144 | }) | ||
| 1145 | |||
| 1146 | // Translations | ||
| 1147 | const defaultTranslations: { modal: ModalTranslations } = { | ||
| 1148 | modal: { | ||
| 1149 | displayDetails: 'Display detailed list', | ||
| 1150 | exactMatchTitle: 'Exact search', | ||
| 1151 | resetButtonTitle: 'Reset search', | ||
| 1152 | backButtonTitle: 'Close search', | ||
| 1153 | noResultsText: 'No results for', | ||
| 1154 | footer: { | ||
| 1155 | selectText: 'select', | ||
| 1156 | selectKeyAriaLabel: 'enter', | ||
| 1157 | navigateText: 'navigate', | ||
| 1158 | navigateUpKeyAriaLabel: 'up arrow', | ||
| 1159 | navigateDownKeyAriaLabel: 'down arrow', | ||
| 1160 | switchTabsText: 'switch tabs', | ||
| 1161 | switchTabsKeyAriaLabel: 'shift tab and tab', | ||
| 1162 | switchPagesText: 'switch pages', | ||
| 1163 | switchPagesKeyAriaLabel: 'left and right arrow', | ||
| 1164 | closeText: 'close', | ||
| 1165 | closeKeyAriaLabel: 'escape' | ||
| 1166 | } | ||
| 1167 | } | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | const translate = createSearchTranslate(defaultTranslations) | ||
| 1171 | |||
| 1172 | // Back | ||
| 1173 | onMounted(() => { window.history.pushState(null, '', null) }) | ||
| 1174 | useEventListener('popstate', (event) => { event.preventDefault(); showSearch.value = false }) | ||
| 1175 | |||
| 1176 | // Lock body | ||
| 1177 | const isLocked = useScrollLock(inBrowser ? document.body : null) | ||
| 1178 | |||
| 1179 | watch(() => showSearch.value, (val) => { | ||
| 1180 | if (!val) { isLocked.value = false; return } | ||
| 1181 | nextTick(() => { | ||
| 1182 | isLocked.value = true | ||
| 1183 | nextTick().then(() => { activate() }) | ||
| 1184 | }) | ||
| 1185 | }) | ||
| 1186 | |||
| 1187 | function resetSearch() { | ||
| 1188 | filterText.value = '' | ||
| 1189 | nextTick().then(() => focusSearchInput(false)) | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | function onMouseMove(e: MouseEvent) { | ||
| 1193 | if (!disableMouseOver.value) return | ||
| 1194 | const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result') | ||
| 1195 | const index = Number.parseInt(el?.dataset.index!) | ||
| 1196 | if (index >= 0 && index !== selectedIndex.value) selectedIndex.value = index | ||
| 1197 | disableMouseOver.value = false | ||
| 1198 | } | ||
| 1199 | </script> | ||
| 1200 | |||
| 1201 | <template> | ||
| 1202 | <Teleport to="body"> | ||
| 1203 | <div | ||
| 1204 | ref="el" | ||
| 1205 | role="button" | ||
| 1206 | :aria-owns="results?.length ? 'localsearch-list' : undefined" | ||
| 1207 | aria-expanded="true" | ||
| 1208 | aria-haspopup="listbox" | ||
| 1209 | aria-labelledby="localsearch-label" | ||
| 1210 | class="VPLocalSearchBox" | ||
| 1211 | :class="{ 'pointer-events-none': !showSearch }" | ||
| 1212 | > | ||
| 1213 | <AnimatePresence> | ||
| 1214 | <component | ||
| 1215 | :is="searchMotionDiv" | ||
| 1216 | v-if="showSearch" | ||
| 1217 | class="backdrop" | ||
| 1218 | @click="showSearch = false" | ||
| 1219 | v-bind="backdropMotion" | ||
| 1220 | /> | ||
| 1221 | </AnimatePresence> | ||
| 1222 | |||
| 1223 | <AnimatePresence> | ||
| 1224 | <component | ||
| 1225 | :is="searchMotionDiv" | ||
| 1226 | v-if="showSearch" | ||
| 1227 | class="shell" | ||
| 1228 | v-bind="shellMotion" | ||
| 1229 | > | ||
| 1230 | <!-- Search Bar --> | ||
| 1231 | <SearchBar | ||
| 1232 | ref="searchBarRef" | ||
| 1233 | :filter-text="filterText" | ||
| 1234 | :search-loading="searchLoading" | ||
| 1235 | :disable-detailed-view="disableDetailedView" | ||
| 1236 | :show-settings-popup="showSettingsPopup" | ||
| 1237 | :button-text="buttonText" | ||
| 1238 | :disable-reset="disableReset" | ||
| 1239 | :search-motion-form="searchMotionForm" | ||
| 1240 | :form-motion="formMotion" | ||
| 1241 | :translate="translate" | ||
| 1242 | @update:filter-text="filterText = $event" | ||
| 1243 | @cycle-search-mode="cycleSearchMode(searchMode)" | ||
| 1244 | @reset-search="resetSearch" | ||
| 1245 | @search-bar-click="onSearchBarClick" | ||
| 1246 | @toggle-settings="showSettingsPopup = !showSettingsPopup" | ||
| 1247 | @close="showSearch = false" | ||
| 1248 | /> | ||
| 1249 | |||
| 1250 | <!-- Page Ribbon --> | ||
| 1251 | <AnimatePresence> | ||
| 1252 | <SearchRibbon | ||
| 1253 | ref="ribbonRef" | ||
| 1254 | :search-motion-div="searchMotionDiv" | ||
| 1255 | :ribbon-motion="ribbonMotion" | ||
| 1256 | :search-animations-enabled="searchAnimationsEnabled" | ||
| 1257 | :url-search-mode="urlSearchMode" | ||
| 1258 | :url-page-groups="urlPageGroups" | ||
| 1259 | :url-active-page-filter="urlActivePageFilter" | ||
| 1260 | :url-matches-length="urlMatches.length" | ||
| 1261 | :page-groups="pageGroups" | ||
| 1262 | :active-page-filter="activePageFilter" | ||
| 1263 | :results-length="results.length" | ||
| 1264 | @select-url-page="setUrlPageFilter" | ||
| 1265 | @select-page="setPageFilter" | ||
| 1266 | /> | ||
| 1267 | </AnimatePresence> | ||
| 1268 | |||
| 1269 | <ul | ||
| 1270 | ref="resultsEl" | ||
| 1271 | :id="results?.length ? 'localsearch-list' : undefined" | ||
| 1272 | :role="results?.length ? 'listbox' : undefined" | ||
| 1273 | :aria-labelledby="results?.length ? 'localsearch-label' : undefined" | ||
| 1274 | class="results" | ||
| 1275 | @mousemove="onMouseMove" | ||
| 1276 | > | ||
| 1277 | <!-- Empty state --> | ||
| 1278 | <AnimatePresence> | ||
| 1279 | <SearchEmptyState | ||
| 1280 | v-if="!showHistory && (urlSearchMode | ||
| 1281 | ? (!filterText || !urlMatches.length) | ||
| 1282 | : (!filterText || !filteredResults.length))" | ||
| 1283 | :filter-text="filterText" | ||
| 1284 | :search-motion-div="searchMotionDiv" | ||
| 1285 | :empty-state-motion="emptyStateMotion" | ||
| 1286 | /> | ||
| 1287 | </AnimatePresence> | ||
| 1288 | |||
| 1289 | <!-- Search history --> | ||
| 1290 | <AnimatePresence> | ||
| 1291 | <SearchHistory | ||
| 1292 | :search-motion-div="searchMotionDiv" | ||
| 1293 | :empty-state-motion="emptyStateMotion" | ||
| 1294 | :filter-text="filterText" | ||
| 1295 | @apply-history="applyHistory" | ||
| 1296 | @remove-from-history="removeFromHistory" | ||
| 1297 | /> | ||
| 1298 | </AnimatePresence> | ||
| 1299 | |||
| 1300 | <!-- URL search results --> | ||
| 1301 | <template v-if="urlSearchMode"> | ||
| 1302 | <AnimatePresence> | ||
| 1303 | <component | ||
| 1304 | :is="searchMotionLi" | ||
| 1305 | v-for="(item, index) in filteredUrlResults" | ||
| 1306 | :key="'url-' + urlCurrentPage + '-' + | ||
| 1307 | item.pageId + '-' + | ||
| 1308 | item.anchor + '-' + index" | ||
| 1309 | class="result-layout" | ||
| 1310 | :id="'localsearch-item-' + (index + 1)" | ||
| 1311 | :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'" | ||
| 1312 | role="option" | ||
| 1313 | v-bind="resultMotion(index)" | ||
| 1314 | > | ||
| 1315 | <div | ||
| 1316 | class="result url-result-card" | ||
| 1317 | :class="{ selected: selectedIndex === index + 1 }" | ||
| 1318 | :aria-label="item.href" | ||
| 1319 | role="button" | ||
| 1320 | @mouseenter="!disableMouseOver && (selectedIndex = index + 1)" | ||
| 1321 | @focusin="selectedIndex = index + 1" | ||
| 1322 | @click="navigateToUrlResult(item)" | ||
| 1323 | :data-index="index + 1" | ||
| 1324 | > | ||
| 1325 | <div class="url-result-body"> | ||
| 1326 | <div class="url-path"> | ||
| 1327 | <Hash | ||
| 1328 | v-if="item.anchor || item.titles.length > 0" | ||
| 1329 | stroke-width="2" | ||
| 1330 | :size="18" | ||
| 1331 | /> | ||
| 1332 | <File v-else stroke-width="2" :size="18" /> | ||
| 1333 | <span v-for="(t, ti) in item.titles" :key="ti" class="url-path-segment"> | ||
| 1334 | <span class="text" v-html="t" /> | ||
| 1335 | <ArrowRight stroke-width="2" :size="18" class="mx-0.5" /> | ||
| 1336 | </span> | ||
| 1337 | <span v-if="item.linkText" class="url-path-current" v-html="item.linkText" /> | ||
| 1338 | </div> | ||
| 1339 | <a | ||
| 1340 | :href="item.href" | ||
| 1341 | target="_blank" | ||
| 1342 | rel="noopener noreferrer" | ||
| 1343 | class="url-link" | ||
| 1344 | :title="item.href" | ||
| 1345 | @click.stop | ||
| 1346 | v-html="item.highlighted" | ||
| 1347 | /> | ||
| 1348 | </div> | ||
| 1349 | </div> | ||
| 1350 | </component> | ||
| 1351 | </AnimatePresence> | ||
| 1352 | </template> | ||
| 1353 | |||
| 1354 | <!-- Normal search results --> | ||
| 1355 | <template v-else> | ||
| 1356 | <AnimatePresence> | ||
| 1357 | <component | ||
| 1358 | :is="searchMotionLi" | ||
| 1359 | v-for="(p, index) in pagedResults" | ||
| 1360 | :key="'normal-' + normalCurrentPage + '-' + p.id" | ||
| 1361 | class="result-layout" | ||
| 1362 | :id="'localsearch-item-' + (index + 1)" | ||
| 1363 | :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'" | ||
| 1364 | role="option" | ||
| 1365 | v-bind="resultMotion(index)" | ||
| 1366 | > | ||
| 1367 | <a | ||
| 1368 | :href="getSearchResultHref(p)" | ||
| 1369 | class="result" | ||
| 1370 | :class="{ selected: selectedIndex === index + 1 }" | ||
| 1371 | :aria-label="[...p.titles, p.title].join(' > ')" | ||
| 1372 | @mouseenter="!disableMouseOver && (selectedIndex = index + 1)" | ||
| 1373 | @focusin="selectedIndex = index + 1" | ||
| 1374 | @click="onResultClick(p)" | ||
| 1375 | :data-index="index + 1" | ||
| 1376 | > | ||
| 1377 | <div> | ||
| 1378 | <div class="titles"> | ||
| 1379 | <Hash | ||
| 1380 | v-if="getDocAnchor(p.id) || p.titles.length > 0" | ||
| 1381 | stroke-width="2" | ||
| 1382 | :size="18" | ||
| 1383 | /> | ||
| 1384 | <File v-else stroke-width="2" :size="18" /> | ||
| 1385 | <span v-for="(t, index) in p.titles" :key="index" class="title"> | ||
| 1386 | <span class="text" v-html="t" /> | ||
| 1387 | <ArrowRight stroke-width="2" :size="18" class="mx-0.5" /> | ||
| 1388 | </span> | ||
| 1389 | <span class="title main"> | ||
| 1390 | <span class="text" v-html="p.title" /> | ||
| 1391 | </span> | ||
| 1392 | </div> | ||
| 1393 | <div | ||
| 1394 | v-if="showDetailedList && hasExcerptPreview(p.text)" | ||
| 1395 | class="excerpt-wrapper" | ||
| 1396 | > | ||
| 1397 | <component | ||
| 1398 | :is="searchMotionDiv" | ||
| 1399 | class="excerpt" | ||
| 1400 | inert | ||
| 1401 | v-bind="excerptMotion" | ||
| 1402 | > | ||
| 1403 | <div class="vp-doc" v-html="p.text" /> | ||
| 1404 | </component> | ||
| 1405 | <div class="excerpt-gradient-bottom" /> | ||
| 1406 | <div class="excerpt-gradient-top" /> | ||
| 1407 | </div> | ||
| 1408 | </div> | ||
| 1409 | </a> | ||
| 1410 | </component> | ||
| 1411 | </AnimatePresence> | ||
| 1412 | </template> | ||
| 1413 | </ul> | ||
| 1414 | |||
| 1415 | <!-- Pagination --> | ||
| 1416 | <SearchPagination | ||
| 1417 | :url-search-mode="urlSearchMode" | ||
| 1418 | :url-total-pages="urlTotalPages" | ||
| 1419 | :url-current-page="urlCurrentPage" | ||
| 1420 | :url-page-list="urlPageList" | ||
| 1421 | :normal-total-pages="normalTotalPages" | ||
| 1422 | :normal-current-page="normalCurrentPage" | ||
| 1423 | :normal-page-list="normalPageList" | ||
| 1424 | @go-to-url-page="goToUrlPage" | ||
| 1425 | @go-to-normal-page="goToNormalPage" | ||
| 1426 | /> | ||
| 1427 | |||
| 1428 | <!-- Keyboard Shortcuts --> | ||
| 1429 | <SearchKeyboardShortcuts | ||
| 1430 | v-if="showKeyboardShortcuts" | ||
| 1431 | :search-motion-div="searchMotionDiv" | ||
| 1432 | :footer-motion="footerMotion" | ||
| 1433 | :translate="translate" | ||
| 1434 | /> | ||
| 1435 | </component> | ||
| 1436 | </AnimatePresence> | ||
| 1437 | |||
| 1438 | <!-- Search Settings popup (teleported to body) --> | ||
| 1439 | <SearchSettings | ||
| 1440 | v-if="showSearch" | ||
| 1441 | v-model:show-settings-popup="showSettingsPopup" | ||
| 1442 | :settings-button-ref="settingsButtonRef" | ||
| 1443 | /> | ||
| 1444 | |||
| 1445 | <button v-if="!showSearch" /> | ||
| 1446 | </div> | ||
| 1447 | </Teleport> | ||
| 1448 | </template> | ||
| 1449 | |||
| 1450 | <style> | ||
| 1451 | .VPLocalSearchBox { | ||
| 1452 | position: fixed; | ||
| 1453 | z-index: 100; | ||
| 1454 | inset: 0; | ||
| 1455 | display: flex; | ||
| 1456 | align-items: flex-start; | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | @media (max-width: 767px) { | ||
| 1460 | .VPLocalSearchBox { | ||
| 1461 | align-items: stretch; | ||
| 1462 | } | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | .backdrop { | ||
| 1466 | position: absolute; | ||
| 1467 | inset: 0; | ||
| 1468 | background: var(--vp-backdrop-bg-color); | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | .shell { | ||
| 1472 | position: relative; | ||
| 1473 | box-sizing: border-box; | ||
| 1474 | padding: 12px 12px 8px; | ||
| 1475 | margin: 64px auto; | ||
| 1476 | display: flex; | ||
| 1477 | flex-direction: column; | ||
| 1478 | gap: 16px; | ||
| 1479 | background: var(--vp-local-search-bg); | ||
| 1480 | width: min(100vw - 60px, 700px); | ||
| 1481 | height: 100%; | ||
| 1482 | max-height: min(100vh - 128px, 680px); | ||
| 1483 | border-radius: 6px; | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | @media (max-width: 767px) { | ||
| 1487 | .shell { | ||
| 1488 | margin: 0; | ||
| 1489 | width: 100vw; | ||
| 1490 | height: 100vh; | ||
| 1491 | height: 100dvh; | ||
| 1492 | max-height: none; | ||
| 1493 | border-radius: 0; | ||
| 1494 | overflow: hidden; | ||
| 1495 | gap: 8px; | ||
| 1496 | } | ||
| 1497 | } | ||
| 1498 | |||
| 1499 | .results { | ||
| 1500 | display: flex; | ||
| 1501 | flex-direction: column; | ||
| 1502 | gap: 6px; | ||
| 1503 | flex: 1 1 auto; | ||
| 1504 | min-height: 0 !important; | ||
| 1505 | overflow-x: hidden; | ||
| 1506 | overflow-y: auto; | ||
| 1507 | overscroll-behavior: contain; | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | .result-layout { | ||
| 1511 | will-change: transform, opacity, height; | ||
| 1512 | } | ||
| 1513 | |||
| 1514 | .result { | ||
| 1515 | display: flex; | ||
| 1516 | align-items: center; | ||
| 1517 | gap: 8px; | ||
| 1518 | border-radius: 4px; | ||
| 1519 | transition: none; | ||
| 1520 | line-height: 1rem; | ||
| 1521 | border: solid 2px var(--vp-local-search-result-border); | ||
| 1522 | outline: none; | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | .result > div { | ||
| 1526 | margin: 12px; | ||
| 1527 | width: 100%; | ||
| 1528 | overflow: hidden; | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | @media (max-width: 767px) { | ||
| 1532 | .result > div { | ||
| 1533 | margin: 8px; | ||
| 1534 | } | ||
| 1535 | } | ||
| 1536 | |||
| 1537 | .result.selected { | ||
| 1538 | --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg); | ||
| 1539 | border-color: var(--vp-local-search-result-selected-border); | ||
| 1540 | } | ||
| 1541 | |||
| 1542 | .titles { | ||
| 1543 | display: flex; | ||
| 1544 | flex-wrap: wrap; | ||
| 1545 | gap: 4px; | ||
| 1546 | position: relative; | ||
| 1547 | z-index: 1001; | ||
| 1548 | padding: 2px 0; | ||
| 1549 | align-items: center; | ||
| 1550 | } | ||
| 1551 | |||
| 1552 | .title { | ||
| 1553 | display: flex; | ||
| 1554 | align-items: center; | ||
| 1555 | gap: 4px; | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | .title.main { | ||
| 1559 | font-weight: 500; | ||
| 1560 | } | ||
| 1561 | |||
| 1562 | .title-icon { | ||
| 1563 | opacity: 1; | ||
| 1564 | font-weight: 500; | ||
| 1565 | } | ||
| 1566 | |||
| 1567 | .title svg { | ||
| 1568 | opacity: 0.5; | ||
| 1569 | } | ||
| 1570 | |||
| 1571 | .titles > svg { | ||
| 1572 | flex-shrink: 0; | ||
| 1573 | align-self: center; | ||
| 1574 | } | ||
| 1575 | |||
| 1576 | .titles mark, | ||
| 1577 | .excerpt mark { | ||
| 1578 | background-color: var(--vp-local-search-highlight-bg); | ||
| 1579 | color: var(--vp-local-search-highlight-text); | ||
| 1580 | border-radius: 2px; | ||
| 1581 | padding: 0 2px; | ||
| 1582 | } | ||
| 1583 | |||
| 1584 | .url-highlight { | ||
| 1585 | background-color: var(--vp-local-search-highlight-bg); | ||
| 1586 | color: var(--vp-local-search-highlight-text); | ||
| 1587 | border-radius: 2px; | ||
| 1588 | padding: 0 2px; | ||
| 1589 | font-style: normal; | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | .excerpt-wrapper { | ||
| 1593 | position: relative; | ||
| 1594 | } | ||
| 1595 | |||
| 1596 | .excerpt { | ||
| 1597 | opacity: 50%; | ||
| 1598 | pointer-events: none; | ||
| 1599 | height: 84px; | ||
| 1600 | max-height: 84px; | ||
| 1601 | overflow: hidden; | ||
| 1602 | position: relative; | ||
| 1603 | margin-top: 4px; | ||
| 1604 | contain: layout paint; | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | .result.selected .excerpt { | ||
| 1608 | opacity: 1; | ||
| 1609 | } | ||
| 1610 | |||
| 1611 | .excerpt * { | ||
| 1612 | font-size: 0.8rem !important; | ||
| 1613 | line-height: 130% !important; | ||
| 1614 | } | ||
| 1615 | |||
| 1616 | .excerpt .vp-code-group .tabs { | ||
| 1617 | display: none; | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | .excerpt .vp-code-group div[class*="language-"] { | ||
| 1621 | border-radius: 8px !important; | ||
| 1622 | } | ||
| 1623 | |||
| 1624 | .excerpt > .vp-doc > *:first-child { | ||
| 1625 | margin-top: 6px !important; | ||
| 1626 | } | ||
| 1627 | |||
| 1628 | .excerpt-gradient-bottom { | ||
| 1629 | position: absolute; | ||
| 1630 | bottom: -1px; | ||
| 1631 | left: 0; | ||
| 1632 | width: 100%; | ||
| 1633 | height: 8px; | ||
| 1634 | background: linear-gradient(transparent, var(--vp-local-search-result-bg)); | ||
| 1635 | z-index: 1000; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | .excerpt-gradient-top { | ||
| 1639 | position: absolute; | ||
| 1640 | top: -1px; | ||
| 1641 | left: 0; | ||
| 1642 | width: 100%; | ||
| 1643 | height: 8px; | ||
| 1644 | background: linear-gradient(var(--vp-local-search-result-bg), transparent); | ||
| 1645 | z-index: 1000; | ||
| 1646 | } | ||
| 1647 | |||
| 1648 | .result.selected .titles, | ||
| 1649 | .result.selected .title-icon { | ||
| 1650 | color: var(--vp-c-brand-1) !important; | ||
| 1651 | } | ||
| 1652 | |||
| 1653 | .result.selected .url-link { | ||
| 1654 | color: var(--vp-c-brand-1); | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | .no-results { | ||
| 1658 | font-size: 0.9rem; | ||
| 1659 | text-align: center; | ||
| 1660 | padding: 12px; | ||
| 1661 | } | ||
| 1662 | |||
| 1663 | svg { | ||
| 1664 | flex: none; | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | .url-result-card { | ||
| 1668 | cursor: pointer; | ||
| 1669 | } | ||
| 1670 | |||
| 1671 | .url-result-body { | ||
| 1672 | display: flex; | ||
| 1673 | flex-direction: column; | ||
| 1674 | gap: 6px; | ||
| 1675 | } | ||
| 1676 | |||
| 1677 | .url-path { | ||
| 1678 | display: flex; | ||
| 1679 | align-items: center; | ||
| 1680 | flex-wrap: wrap; | ||
| 1681 | gap: 4px; | ||
| 1682 | color: var(--vp-c-text-3); | ||
| 1683 | font-size: 0.78rem; | ||
| 1684 | line-height: 1.2; | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | .url-path > svg, | ||
| 1688 | .url-path-segment svg { | ||
| 1689 | flex-shrink: 0; | ||
| 1690 | width: 1em; | ||
| 1691 | height: 1em; | ||
| 1692 | margin-top: -1px; | ||
| 1693 | opacity: 0.55; | ||
| 1694 | } | ||
| 1695 | |||
| 1696 | .url-path > svg { | ||
| 1697 | margin-top: -2px; | ||
| 1698 | } | ||
| 1699 | |||
| 1700 | .url-path-segment { | ||
| 1701 | display: flex; | ||
| 1702 | align-items: center; | ||
| 1703 | min-width: 0; | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | .url-path-current { | ||
| 1707 | display: inline-flex; | ||
| 1708 | align-items: center; | ||
| 1709 | color: var(--vp-c-text-2); | ||
| 1710 | } | ||
| 1711 | |||
| 1712 | .url-path .icon-tip { | ||
| 1713 | display: inline-flex; | ||
| 1714 | align-items: center; | ||
| 1715 | line-height: 1; | ||
| 1716 | vertical-align: middle; | ||
| 1717 | } | ||
| 1718 | |||
| 1719 | .url-path .icon-tip > span { | ||
| 1720 | width: 1em; | ||
| 1721 | height: 1em; | ||
| 1722 | min-width: 1em; | ||
| 1723 | } | ||
| 1724 | |||
| 1725 | .url-link { | ||
| 1726 | align-self: flex-start; | ||
| 1727 | max-width: 100%; | ||
| 1728 | color: var(--vp-c-text-1); | ||
| 1729 | font-size: 0.95rem; | ||
| 1730 | font-weight: 500; | ||
| 1731 | line-height: 1.35; | ||
| 1732 | overflow-wrap: anywhere; | ||
| 1733 | word-break: break-word; | ||
| 1734 | } | ||
| 1735 | |||
| 1736 | .url-link:hover { | ||
| 1737 | color: var(--vp-c-brand-1); | ||
| 1738 | text-decoration: underline; | ||
| 1739 | text-underline-offset: 2px; | ||
| 1740 | } | ||
| 1741 | </style> | ||
docs/.vitepress/theme/components/search/SearchBar.vue added +410
| @@ -0,0 +1,410 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { | ||
| 3 | Globe, | ||
| 4 | List, | ||
| 5 | LocateOff, | ||
| 6 | Regex, | ||
| 7 | Settings, | ||
| 8 | TextAlignStart, | ||
| 9 | X | ||
| 10 | } from 'lucide-vue-next' | ||
| 11 | import { ref } from 'vue' | ||
| 12 | import { searchMode, showDetailedList } from '../../searchState' | ||
| 13 | import type { SearchSortMode } from '../../searchState' | ||
| 14 | |||
| 15 | defineProps<{ | ||
| 16 | filterText: string | ||
| 17 | searchLoading: boolean | ||
| 18 | disableDetailedView: boolean | ||
| 19 | showSettingsPopup: boolean | ||
| 20 | buttonText: string | ||
| 21 | disableReset: boolean | ||
| 22 | searchMotionForm: string | object | ||
| 23 | formMotion: Record<string, unknown> | ||
| 24 | translate: (key: string) => string | ||
| 25 | }>() | ||
| 26 | |||
| 27 | const emit = defineEmits<{ | ||
| 28 | 'update:filterText': [value: string] | ||
| 29 | cycleSearchMode: [] | ||
| 30 | resetSearch: [] | ||
| 31 | searchBarClick: [event: PointerEvent] | ||
| 32 | toggleSettings: [] | ||
| 33 | close: [] | ||
| 34 | }>() | ||
| 35 | |||
| 36 | const searchInput = ref<HTMLInputElement>() | ||
| 37 | const settingsButtonRef = ref<HTMLButtonElement>() | ||
| 38 | |||
| 39 | defineExpose({ searchInput, settingsButtonRef }) | ||
| 40 | |||
| 41 | function onViewDetailClick() { | ||
| 42 | showDetailedList.value = true | ||
| 43 | } | ||
| 44 | |||
| 45 | function onViewListClick() { | ||
| 46 | showDetailedList.value = false | ||
| 47 | } | ||
| 48 | |||
| 49 | function onExactClick() { | ||
| 50 | if (searchMode.value === 'exact') emit('cycleSearchMode') | ||
| 51 | else searchMode.value = 'exact' as SearchSortMode | ||
| 52 | } | ||
| 53 | |||
| 54 | function onFuzzyClick() { | ||
| 55 | if (searchMode.value === 'fuzzy') emit('cycleSearchMode') | ||
| 56 | else searchMode.value = 'fuzzy' as SearchSortMode | ||
| 57 | } | ||
| 58 | |||
| 59 | function onUrlClick() { | ||
| 60 | if (searchMode.value === 'url') emit('cycleSearchMode') | ||
| 61 | else searchMode.value = 'url' as SearchSortMode | ||
| 62 | } | ||
| 63 | </script> | ||
| 64 | |||
| 65 | <template> | ||
| 66 | <component | ||
| 67 | :is="searchMotionForm" | ||
| 68 | class="search-bar" | ||
| 69 | v-bind="formMotion" | ||
| 70 | @pointerup="emit('searchBarClick', $event)" | ||
| 71 | @submit.prevent="" | ||
| 72 | > | ||
| 73 | <label | ||
| 74 | :title="buttonText" | ||
| 75 | id="localsearch-label" | ||
| 76 | for="localsearch-input" | ||
| 77 | > | ||
| 78 | <span | ||
| 79 | aria-hidden="true" | ||
| 80 | class="vpi-search search-icon local-search-icon" | ||
| 81 | /> | ||
| 82 | </label> | ||
| 83 | <div class="search-actions before"> | ||
| 84 | <button | ||
| 85 | class="back-button" | ||
| 86 | :title="translate('modal.backButtonTitle')" | ||
| 87 | @click="emit('close')" | ||
| 88 | > | ||
| 89 | <span class="vpi-arrow-left local-search-icon" /> | ||
| 90 | </button> | ||
| 91 | </div> | ||
| 92 | <input | ||
| 93 | ref="searchInput" | ||
| 94 | :value="filterText" | ||
| 95 | @input="emit('update:filterText', ($event.target as HTMLInputElement).value)" | ||
| 96 | aria-autocomplete="both" | ||
| 97 | aria-labelledby="localsearch-label" | ||
| 98 | autocapitalize="off" | ||
| 99 | autocomplete="off" | ||
| 100 | autocorrect="off" | ||
| 101 | class="search-input" | ||
| 102 | id="localsearch-input" | ||
| 103 | enterkeyhint="go" | ||
| 104 | maxlength="64" | ||
| 105 | :placeholder="buttonText" | ||
| 106 | spellcheck="false" | ||
| 107 | type="search" | ||
| 108 | /> | ||
| 109 | <div class="search-actions"> | ||
| 110 | <button | ||
| 111 | v-if="searchLoading" | ||
| 112 | class="search-loading-button" | ||
| 113 | type="button" | ||
| 114 | > | ||
| 115 | <img | ||
| 116 | class="search-loading-bubba" | ||
| 117 | src="/bubba.webp" | ||
| 118 | alt="Bubba loading" | ||
| 119 | /> | ||
| 120 | </button> | ||
| 121 | <div | ||
| 122 | v-if="!disableDetailedView && searchMode !== 'url'" | ||
| 123 | class="view-group toolbar-group" | ||
| 124 | > | ||
| 125 | <button | ||
| 126 | type="button" | ||
| 127 | class="mode-btn" | ||
| 128 | :class="{ 'mode-active': showDetailedList }" | ||
| 129 | title="Detail view (Consumes more RAM)" | ||
| 130 | @click="onViewDetailClick" | ||
| 131 | > | ||
| 132 | <TextAlignStart :size="18" stroke-width="2" /> | ||
| 133 | </button> | ||
| 134 | <button | ||
| 135 | type="button" | ||
| 136 | class="mode-btn" | ||
| 137 | :class="{ 'mode-active': !showDetailedList }" | ||
| 138 | title="List view (Consumes less RAM)" | ||
| 139 | @click="onViewListClick" | ||
| 140 | > | ||
| 141 | <List :size="18" stroke-width="2" /> | ||
| 142 | </button> | ||
| 143 | </div> | ||
| 144 | <div class="search-mode-group toolbar-group"> | ||
| 145 | <button | ||
| 146 | type="button" | ||
| 147 | class="mode-btn" | ||
| 148 | :class="{ 'mode-active': searchMode === 'exact' }" | ||
| 149 | title="Exact search" | ||
| 150 | @click="onExactClick" | ||
| 151 | > | ||
| 152 | <Regex :size="18" stroke-width="2" /> | ||
| 153 | </button> | ||
| 154 | <button | ||
| 155 | type="button" | ||
| 156 | class="mode-btn" | ||
| 157 | :class="{ 'mode-active': searchMode === 'fuzzy' }" | ||
| 158 | title="Fuzzy search" | ||
| 159 | @click="onFuzzyClick" | ||
| 160 | > | ||
| 161 | <LocateOff :size="18" stroke-width="2" /> | ||
| 162 | </button> | ||
| 163 | <button | ||
| 164 | type="button" | ||
| 165 | class="mode-btn" | ||
| 166 | :class="{ 'mode-active': searchMode === 'url' }" | ||
| 167 | title="URL search" | ||
| 168 | @click="onUrlClick" | ||
| 169 | > | ||
| 170 | <Globe :size="18" stroke-width="2" /> | ||
| 171 | </button> | ||
| 172 | </div> | ||
| 173 | <button | ||
| 174 | ref="settingsButtonRef" | ||
| 175 | type="button" | ||
| 176 | class="mode-btn settings-toggle-btn" | ||
| 177 | :class="{ 'mode-active': showSettingsPopup }" | ||
| 178 | title="Search settings" | ||
| 179 | @click.stop="emit('toggleSettings')" | ||
| 180 | > | ||
| 181 | <Settings :size="18" stroke-width="2" /> | ||
| 182 | </button> | ||
| 183 | <button | ||
| 184 | class="clear-button" | ||
| 185 | type="reset" | ||
| 186 | :disabled="disableReset" | ||
| 187 | :title="translate('modal.resetButtonTitle')" | ||
| 188 | @click="emit('resetSearch')" | ||
| 189 | > | ||
| 190 | <X :size="18" stroke-width="2" /> | ||
| 191 | </button> | ||
| 192 | </div> | ||
| 193 | </component> | ||
| 194 | </template> | ||
| 195 | |||
| 196 | <style> | ||
| 197 | .search-bar { | ||
| 198 | flex: 0 0 auto !important; | ||
| 199 | min-height: 44px !important; | ||
| 200 | border: 1px solid var(--vp-c-divider); | ||
| 201 | border-radius: 4px; | ||
| 202 | display: flex; | ||
| 203 | align-items: center; | ||
| 204 | padding: 0 12px; | ||
| 205 | cursor: text; | ||
| 206 | } | ||
| 207 | |||
| 208 | @media (max-width: 767px) { | ||
| 209 | .search-bar { | ||
| 210 | padding: 0 8px; | ||
| 211 | min-height: 40px !important; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | .search-bar:focus-within { | ||
| 216 | border-color: var(--vp-c-brand-1); | ||
| 217 | } | ||
| 218 | |||
| 219 | .local-search-icon { | ||
| 220 | display: block; | ||
| 221 | font-size: 18px; | ||
| 222 | } | ||
| 223 | |||
| 224 | .search-icon { | ||
| 225 | margin: 8px; | ||
| 226 | } | ||
| 227 | |||
| 228 | @media (max-width: 767px) { | ||
| 229 | .search-icon { | ||
| 230 | display: none; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | .search-input { | ||
| 235 | flex: 1 1 auto; | ||
| 236 | min-width: 0; | ||
| 237 | padding: 6px 12px; | ||
| 238 | font-size: inherit; | ||
| 239 | width: 100%; | ||
| 240 | } | ||
| 241 | |||
| 242 | .search-input::-webkit-search-cancel-button { | ||
| 243 | display: none; | ||
| 244 | } | ||
| 245 | |||
| 246 | @media (max-width: 767px) { | ||
| 247 | .search-input { | ||
| 248 | padding: 6px 4px; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | .search-actions { | ||
| 253 | flex: 0 0 auto; | ||
| 254 | display: flex; | ||
| 255 | align-items: center; | ||
| 256 | gap: 4px; | ||
| 257 | } | ||
| 258 | |||
| 259 | .search-loading-button { | ||
| 260 | display: inline-flex; | ||
| 261 | align-items: center; | ||
| 262 | justify-content: center; | ||
| 263 | padding: 0 !important; | ||
| 264 | margin-inline-end: 6px; | ||
| 265 | border: 0; | ||
| 266 | background: transparent; | ||
| 267 | cursor: pointer; | ||
| 268 | } | ||
| 269 | |||
| 270 | .search-loading-bubba { | ||
| 271 | width: 32px; | ||
| 272 | height: 28px; | ||
| 273 | object-fit: contain; | ||
| 274 | image-rendering: pixelated; | ||
| 275 | user-select: none; | ||
| 276 | } | ||
| 277 | |||
| 278 | @media (any-pointer: coarse) { | ||
| 279 | .search-actions { | ||
| 280 | gap: 8px; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | @media (min-width: 769px) { | ||
| 285 | .search-actions.before { | ||
| 286 | display: none; | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | .search-actions button { | ||
| 291 | padding: 8px; | ||
| 292 | } | ||
| 293 | |||
| 294 | .search-actions button:not([disabled]):hover, | ||
| 295 | .toggle-layout-button.detailed-list { | ||
| 296 | color: var(--vp-c-brand-1); | ||
| 297 | } | ||
| 298 | |||
| 299 | .search-actions button.clear-button:disabled { | ||
| 300 | opacity: 0.37; | ||
| 301 | } | ||
| 302 | |||
| 303 | .toolbar-group + .toolbar-group { | ||
| 304 | margin-left: 6px; | ||
| 305 | } | ||
| 306 | |||
| 307 | .search-mode-group, | ||
| 308 | .view-group { | ||
| 309 | display: none; | ||
| 310 | } | ||
| 311 | |||
| 312 | .mode-btn { | ||
| 313 | display: flex; | ||
| 314 | align-items: center; | ||
| 315 | justify-content: center; | ||
| 316 | padding: 5px 7px; | ||
| 317 | color: var(--vp-c-text-2); | ||
| 318 | background: transparent; | ||
| 319 | border: none; | ||
| 320 | cursor: pointer; | ||
| 321 | transition: color 0.15s, background-color 0.15s; | ||
| 322 | border-radius: 0; | ||
| 323 | } | ||
| 324 | |||
| 325 | .mode-btn + .mode-btn { | ||
| 326 | border-left: 1px solid var(--vp-c-divider); | ||
| 327 | } | ||
| 328 | |||
| 329 | .mode-btn:hover { | ||
| 330 | color: var(--vp-c-text-1); | ||
| 331 | background: var(--vp-c-default-soft); | ||
| 332 | } | ||
| 333 | |||
| 334 | .mode-btn.mode-active { | ||
| 335 | color: var(--vp-c-brand-1); | ||
| 336 | background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 337 | } | ||
| 338 | |||
| 339 | .exact-match-button.exact-match-active { | ||
| 340 | color: var(--vp-c-brand-1); | ||
| 341 | background-color: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 342 | border-radius: 4px; | ||
| 343 | } | ||
| 344 | |||
| 345 | .search-actions .settings-toggle-btn, | ||
| 346 | .search-actions .clear-button { | ||
| 347 | display: flex; | ||
| 348 | border: none; | ||
| 349 | border-radius: 0; | ||
| 350 | background: transparent; | ||
| 351 | color: var(--vp-c-text-1); | ||
| 352 | opacity: 0.55; | ||
| 353 | padding: 8px 4px; | ||
| 354 | transition: | ||
| 355 | opacity 0.25s, | ||
| 356 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 357 | } | ||
| 358 | |||
| 359 | .search-actions button.settings-toggle-btn:not([disabled]):hover, | ||
| 360 | .search-actions button.clear-button:not([disabled]):hover, | ||
| 361 | .settings-toggle-btn.mode-active { | ||
| 362 | color: var(--vp-c-text-1); | ||
| 363 | opacity: 1; | ||
| 364 | background: transparent; | ||
| 365 | } | ||
| 366 | |||
| 367 | .settings-toggle-btn:active, | ||
| 368 | .clear-button:not([disabled]):active { | ||
| 369 | transform: scale(0.94); | ||
| 370 | } | ||
| 371 | |||
| 372 | html.effects-disabled .settings-toggle-btn, | ||
| 373 | html.effects-disabled .clear-button { | ||
| 374 | transition: none; | ||
| 375 | } | ||
| 376 | |||
| 377 | html.effects-disabled .settings-toggle-btn:active, | ||
| 378 | html.effects-disabled .clear-button:active { | ||
| 379 | transform: none; | ||
| 380 | } | ||
| 381 | |||
| 382 | @media (max-width: 767px) { | ||
| 383 | .search-actions.before { | ||
| 384 | display: flex; | ||
| 385 | } | ||
| 386 | |||
| 387 | label[for="localsearch-input"] { | ||
| 388 | display: none; | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | .back-button { | ||
| 393 | display: none; | ||
| 394 | align-items: center; | ||
| 395 | justify-content: center; | ||
| 396 | padding: 0; | ||
| 397 | border: none; | ||
| 398 | background: transparent; | ||
| 399 | color: var(--vp-c-text-1); | ||
| 400 | cursor: pointer; | ||
| 401 | width: 24px; | ||
| 402 | height: 24px; | ||
| 403 | } | ||
| 404 | |||
| 405 | @media (max-width: 767px) { | ||
| 406 | .back-button { | ||
| 407 | display: flex; | ||
| 408 | } | ||
| 409 | } | ||
| 410 | </style> | ||
docs/.vitepress/theme/components/search/SearchEmptyState.vue added +23
| @@ -0,0 +1,23 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | defineProps<{ | ||
| 3 | filterText: string | ||
| 4 | searchMotionDiv: string | object | ||
| 5 | emptyStateMotion: Record<string, unknown> | ||
| 6 | }>() | ||
| 7 | </script> | ||
| 8 | |||
| 9 | <template> | ||
| 10 | <component | ||
| 11 | :is="searchMotionDiv" | ||
| 12 | 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" | ||
| 13 | v-bind="emptyStateMotion" | ||
| 14 | > | ||
| 15 | <img | ||
| 16 | class="h-40 object-contain object-center" | ||
| 17 | src="/asset/smolame.png" | ||
| 18 | alt="Smol ame" | ||
| 19 | /> | ||
| 20 | <h1 v-if="filterText">Couldn't find anything, try again?</h1> | ||
| 21 | <h1 v-else>Looking for something?</h1> | ||
| 22 | </component> | ||
| 23 | </template> | ||
docs/.vitepress/theme/components/search/SearchHistory.vue added +215
| @@ -0,0 +1,215 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { ArrowRight, Globe, LocateOff, Regex, X } from 'lucide-vue-next' | ||
| 3 | import { searchHistory, type SearchHistoryEntry } from '../../searchState' | ||
| 4 | import type { SearchSortMode } from '../../searchState' | ||
| 5 | |||
| 6 | defineProps<{ | ||
| 7 | searchMotionDiv: string | object | ||
| 8 | emptyStateMotion: Record<string, unknown> | ||
| 9 | filterText: string | ||
| 10 | }>() | ||
| 11 | |||
| 12 | const emit = defineEmits<{ | ||
| 13 | applyHistory: [entry: SearchHistoryEntry] | ||
| 14 | removeFromHistory: [index: number] | ||
| 15 | }>() | ||
| 16 | </script> | ||
| 17 | |||
| 18 | <template> | ||
| 19 | <component | ||
| 20 | :is="searchMotionDiv" | ||
| 21 | v-if="!filterText && searchHistory.length > 0" | ||
| 22 | class="history-list" | ||
| 23 | v-bind="emptyStateMotion" | ||
| 24 | > | ||
| 25 | <div class="history-header"> | ||
| 26 | <span>Recent searches</span> | ||
| 27 | <button | ||
| 28 | class="history-clear-all" | ||
| 29 | title="Clear all history" | ||
| 30 | @click.stop="searchHistory = []" | ||
| 31 | > | ||
| 32 | <X :size="16" stroke-width="2" /> | ||
| 33 | </button> | ||
| 34 | </div> | ||
| 35 | <ul class="history-items"> | ||
| 36 | <li | ||
| 37 | v-for="(entry, index) in searchHistory" | ||
| 38 | :key="index" | ||
| 39 | class="history-item" | ||
| 40 | @click="emit('applyHistory', entry)" | ||
| 41 | > | ||
| 42 | <div class="history-main"> | ||
| 43 | <span class="history-query">{{ entry.query }}</span> | ||
| 44 | <template v-if="entry.path?.length"> | ||
| 45 | <ArrowRight :size="13" stroke-width="1.5" class="history-arrow" /> | ||
| 46 | <template v-for="(seg, si) in entry.path" :key="si"> | ||
| 47 | <span | ||
| 48 | class="history-path-seg" | ||
| 49 | :class="{ | ||
| 50 | 'history-path-end': si === entry.path.length - 1, | ||
| 51 | 'history-path-only': entry.path.length === 1 | ||
| 52 | }" | ||
| 53 | v-html="seg" | ||
| 54 | /> | ||
| 55 | <span v-if="si < entry.path.length - 1" class="history-path-sep">›</span> | ||
| 56 | </template> | ||
| 57 | </template> | ||
| 58 | </div> | ||
| 59 | <component | ||
| 60 | :is="entry.mode === 'exact' ? Regex : entry.mode === 'fuzzy' ? LocateOff : Globe" | ||
| 61 | :size="14" | ||
| 62 | stroke-width="2" | ||
| 63 | class="history-mode-icon" | ||
| 64 | /> | ||
| 65 | <button | ||
| 66 | class="history-remove" | ||
| 67 | :title="`Remove '${entry.query}' from history`" | ||
| 68 | @click.stop="emit('removeFromHistory', index)" | ||
| 69 | > | ||
| 70 | <X :size="16" stroke-width="2" /> | ||
| 71 | </button> | ||
| 72 | </li> | ||
| 73 | </ul> | ||
| 74 | </component> | ||
| 75 | </template> | ||
| 76 | |||
| 77 | <style> | ||
| 78 | .history-list { | ||
| 79 | display: flex; | ||
| 80 | flex-direction: column; | ||
| 81 | width: 100%; | ||
| 82 | padding: 4px 0; | ||
| 83 | } | ||
| 84 | |||
| 85 | .history-header { | ||
| 86 | font-size: 0.7rem; | ||
| 87 | font-weight: 600; | ||
| 88 | text-transform: uppercase; | ||
| 89 | letter-spacing: 0.06em; | ||
| 90 | color: var(--vp-c-text-3); | ||
| 91 | padding: 4px 12px 8px; | ||
| 92 | display: flex; | ||
| 93 | align-items: center; | ||
| 94 | justify-content: space-between; | ||
| 95 | } | ||
| 96 | |||
| 97 | .history-clear-all { | ||
| 98 | display: flex; | ||
| 99 | align-items: center; | ||
| 100 | justify-content: center; | ||
| 101 | flex-shrink: 0; | ||
| 102 | padding: 0; | ||
| 103 | border: none; | ||
| 104 | background: transparent; | ||
| 105 | color: var(--vp-c-text-3); | ||
| 106 | cursor: pointer; | ||
| 107 | opacity: 0.7; | ||
| 108 | transition: color 0.15s; | ||
| 109 | } | ||
| 110 | |||
| 111 | .history-clear-all:hover { | ||
| 112 | color: var(--vp-c-text-1); | ||
| 113 | opacity: 1; | ||
| 114 | } | ||
| 115 | |||
| 116 | .history-items { | ||
| 117 | display: flex; | ||
| 118 | flex-direction: column; | ||
| 119 | list-style: none; | ||
| 120 | margin: 0; | ||
| 121 | padding: 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | .history-item { | ||
| 125 | display: flex; | ||
| 126 | align-items: center; | ||
| 127 | gap: 8px; | ||
| 128 | padding: 8px 12px; | ||
| 129 | cursor: pointer; | ||
| 130 | border-radius: 4px; | ||
| 131 | transition: background-color 0.15s; | ||
| 132 | } | ||
| 133 | |||
| 134 | .history-item:hover { | ||
| 135 | background: var(--vp-c-default-soft); | ||
| 136 | } | ||
| 137 | |||
| 138 | .history-main { | ||
| 139 | flex: 1; | ||
| 140 | min-width: 0; | ||
| 141 | display: flex; | ||
| 142 | align-items: center; | ||
| 143 | gap: 6px; | ||
| 144 | overflow: hidden; | ||
| 145 | } | ||
| 146 | |||
| 147 | .history-query { | ||
| 148 | flex-shrink: 0; | ||
| 149 | font-size: 0.9rem; | ||
| 150 | color: var(--vp-c-text-1); | ||
| 151 | white-space: nowrap; | ||
| 152 | } | ||
| 153 | |||
| 154 | .history-arrow { | ||
| 155 | flex-shrink: 0; | ||
| 156 | opacity: 0.5; | ||
| 157 | color: var(--vp-c-text-3); | ||
| 158 | } | ||
| 159 | |||
| 160 | .history-path-seg { | ||
| 161 | min-width: 0; | ||
| 162 | overflow: hidden; | ||
| 163 | text-overflow: ellipsis; | ||
| 164 | white-space: nowrap; | ||
| 165 | font-size: 0.78rem; | ||
| 166 | font-weight: 500; | ||
| 167 | color: var(--vp-c-text-3); | ||
| 168 | } | ||
| 169 | |||
| 170 | .history-path-sep { | ||
| 171 | flex-shrink: 0; | ||
| 172 | font-size: 0.78rem; | ||
| 173 | color: var(--vp-c-text-3); | ||
| 174 | } | ||
| 175 | |||
| 176 | .history-path-end { | ||
| 177 | flex-shrink: 0; | ||
| 178 | white-space: nowrap; | ||
| 179 | font-size: 0.78rem; | ||
| 180 | font-weight: 500; | ||
| 181 | color: var(--vp-c-text-3); | ||
| 182 | } | ||
| 183 | |||
| 184 | .history-path-only { | ||
| 185 | flex-shrink: 1; | ||
| 186 | min-width: 0; | ||
| 187 | overflow: hidden; | ||
| 188 | text-overflow: ellipsis; | ||
| 189 | } | ||
| 190 | |||
| 191 | .history-mode-icon { | ||
| 192 | flex-shrink: 0; | ||
| 193 | color: var(--vp-c-text-3); | ||
| 194 | opacity: 0.7; | ||
| 195 | } | ||
| 196 | |||
| 197 | .history-remove { | ||
| 198 | display: flex; | ||
| 199 | align-items: center; | ||
| 200 | justify-content: center; | ||
| 201 | flex-shrink: 0; | ||
| 202 | padding: 0; | ||
| 203 | border: none; | ||
| 204 | background: transparent; | ||
| 205 | color: var(--vp-c-text-3); | ||
| 206 | cursor: pointer; | ||
| 207 | opacity: 0.7; | ||
| 208 | transition: color 0.15s; | ||
| 209 | } | ||
| 210 | |||
| 211 | .history-remove:hover { | ||
| 212 | color: var(--vp-c-text-1); | ||
| 213 | opacity: 1; | ||
| 214 | } | ||
| 215 | </style> | ||
docs/.vitepress/theme/components/search/SearchKeyboardShortcuts.vue added +113
| @@ -0,0 +1,113 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { ArrowLeft, ArrowLeftToLine, ArrowRight, ArrowRightToLine } from 'lucide-vue-next' | ||
| 3 | import type { FooterTranslations } from './types' | ||
| 4 | |||
| 5 | defineProps<{ | ||
| 6 | searchMotionDiv: string | object | ||
| 7 | footerMotion: Record<string, unknown> | ||
| 8 | translate: (key: string) => string | ||
| 9 | }>() | ||
| 10 | |||
| 11 | defineOptions({ inheritAttrs: false }) | ||
| 12 | </script> | ||
| 13 | |||
| 14 | <template> | ||
| 15 | <component | ||
| 16 | :is="searchMotionDiv" | ||
| 17 | class="search-keyboard-shortcuts" | ||
| 18 | v-bind="footerMotion" | ||
| 19 | > | ||
| 20 | <span> | ||
| 21 | <kbd | ||
| 22 | :aria-label="translate( | ||
| 23 | 'modal.footer.navigateUpKeyAriaLabel' | ||
| 24 | )" | ||
| 25 | > | ||
| 26 | <span class="vpi-arrow-up navigate-icon" /> | ||
| 27 | </kbd> | ||
| 28 | <kbd | ||
| 29 | :aria-label="translate( | ||
| 30 | 'modal.footer.navigateDownKeyAriaLabel' | ||
| 31 | )" | ||
| 32 | > | ||
| 33 | <span class="vpi-arrow-down navigate-icon" /> | ||
| 34 | </kbd> | ||
| 35 | {{ translate('modal.footer.navigateText') }} | ||
| 36 | </span> | ||
| 37 | <span> | ||
| 38 | <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')"> | ||
| 39 | <ArrowLeftToLine class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 40 | </kbd> | ||
| 41 | <kbd :aria-label="translate('modal.footer.switchTabsKeyAriaLabel')"> | ||
| 42 | <ArrowRightToLine class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 43 | </kbd> | ||
| 44 | {{ translate('modal.footer.switchTabsText') }} | ||
| 45 | </span> | ||
| 46 | <span> | ||
| 47 | <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')"> | ||
| 48 | <ArrowLeft class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 49 | </kbd> | ||
| 50 | <kbd :aria-label="translate('modal.footer.switchPagesKeyAriaLabel')"> | ||
| 51 | <ArrowRight class="navigate-icon" :size="14" stroke-width="2" /> | ||
| 52 | </kbd> | ||
| 53 | {{ translate('modal.footer.switchPagesText') }} | ||
| 54 | </span> | ||
| 55 | <span> | ||
| 56 | <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')"> | ||
| 57 | <span class="vpi-corner-down-left navigate-icon" /> | ||
| 58 | </kbd> | ||
| 59 | {{ translate('modal.footer.selectText') }} | ||
| 60 | </span> | ||
| 61 | <span> | ||
| 62 | <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')"> | ||
| 63 | esc | ||
| 64 | </kbd> | ||
| 65 | {{ translate('modal.footer.closeText') }} | ||
| 66 | </span> | ||
| 67 | </component> | ||
| 68 | </template> | ||
| 69 | |||
| 70 | <style> | ||
| 71 | .search-keyboard-shortcuts { | ||
| 72 | display: flex; | ||
| 73 | flex-wrap: wrap; | ||
| 74 | gap: 16px; | ||
| 75 | justify-content: center; | ||
| 76 | padding: 8px 12px; | ||
| 77 | font-size: 0.75rem; | ||
| 78 | color: var(--vp-c-text-2); | ||
| 79 | user-select: none; | ||
| 80 | flex-shrink: 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | @media (max-width: 767px) { | ||
| 84 | .search-keyboard-shortcuts { | ||
| 85 | display: none; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | .search-keyboard-shortcuts span { | ||
| 90 | display: flex; | ||
| 91 | align-items: center; | ||
| 92 | gap: 4px; | ||
| 93 | } | ||
| 94 | |||
| 95 | .search-keyboard-shortcuts kbd { | ||
| 96 | display: inline-flex; | ||
| 97 | align-items: center; | ||
| 98 | justify-content: center; | ||
| 99 | padding: 2px 6px; | ||
| 100 | border: 1px solid var(--vp-c-divider); | ||
| 101 | border-radius: 4px; | ||
| 102 | background: var(--vp-c-bg-soft); | ||
| 103 | font-size: 0.7rem; | ||
| 104 | font-family: inherit; | ||
| 105 | color: var(--vp-c-text-2); | ||
| 106 | line-height: 1; | ||
| 107 | min-width: 20px; | ||
| 108 | } | ||
| 109 | |||
| 110 | .navigate-icon { | ||
| 111 | flex: none; | ||
| 112 | } | ||
| 113 | </style> | ||
docs/.vitepress/theme/components/search/SearchMotion.ts added +126
| @@ -0,0 +1,126 @@ | |||
| 1 | import { computed, type ComputedRef } from 'vue' | ||
| 2 | import { motion } from 'motion-v' | ||
| 3 | |||
| 4 | export const SearchMotionDiv = motion.div | ||
| 5 | export const SearchMotionForm = motion.form | ||
| 6 | export const SearchMotionLi = motion.li | ||
| 7 | export const searchMotionEase = [0.16, 1, 0.3, 1] | ||
| 8 | |||
| 9 | export function useSearchMotion(animationsEnabled: ComputedRef<boolean>) { | ||
| 10 | const searchMotionDiv = computed(() => | ||
| 11 | animationsEnabled.value ? SearchMotionDiv : 'div' | ||
| 12 | ) | ||
| 13 | const searchMotionForm = computed(() => | ||
| 14 | animationsEnabled.value ? SearchMotionForm : 'form' | ||
| 15 | ) | ||
| 16 | const searchMotionLi = computed(() => | ||
| 17 | animationsEnabled.value ? SearchMotionLi : 'li' | ||
| 18 | ) | ||
| 19 | |||
| 20 | const backdropMotion = computed(() => | ||
| 21 | animationsEnabled.value | ||
| 22 | ? { | ||
| 23 | initial: { opacity: 0 }, | ||
| 24 | animate: { opacity: 1 }, | ||
| 25 | exit: { opacity: 0 }, | ||
| 26 | transition: { duration: 0.55, ease: searchMotionEase } | ||
| 27 | } | ||
| 28 | : {} | ||
| 29 | ) | ||
| 30 | |||
| 31 | const shellMotion = computed(() => | ||
| 32 | animationsEnabled.value | ||
| 33 | ? { | ||
| 34 | layout: 'size', | ||
| 35 | initial: { opacity: 0, scale: 0.9375 }, | ||
| 36 | animate: { opacity: 1, scale: 1 }, | ||
| 37 | exit: { opacity: 0, scale: 0.9375 }, | ||
| 38 | transition: { duration: 0.55, ease: searchMotionEase } | ||
| 39 | } | ||
| 40 | : {} | ||
| 41 | ) | ||
| 42 | |||
| 43 | const formMotion = computed(() => | ||
| 44 | animationsEnabled.value ? { layout: 'position' } : {} | ||
| 45 | ) | ||
| 46 | |||
| 47 | const ribbonMotion = computed(() => | ||
| 48 | animationsEnabled.value | ||
| 49 | ? { | ||
| 50 | layout: 'position', | ||
| 51 | initial: { opacity: 0, height: 0 }, | ||
| 52 | animate: { opacity: 1, height: 'auto' }, | ||
| 53 | exit: { opacity: 0, height: 0 }, | ||
| 54 | transition: { duration: 0.4, ease: searchMotionEase } | ||
| 55 | } | ||
| 56 | : {} | ||
| 57 | ) | ||
| 58 | |||
| 59 | const emptyStateMotion = computed(() => | ||
| 60 | animationsEnabled.value | ||
| 61 | ? { | ||
| 62 | initial: { opacity: 0 }, | ||
| 63 | animate: { | ||
| 64 | opacity: 1, | ||
| 65 | transition: { delay: 0.1 } | ||
| 66 | }, | ||
| 67 | exit: { | ||
| 68 | opacity: 0, | ||
| 69 | height: 0, | ||
| 70 | transition: { duration: 0.2 } | ||
| 71 | }, | ||
| 72 | transition: { duration: 0.7, ease: searchMotionEase } | ||
| 73 | } | ||
| 74 | : {} | ||
| 75 | ) | ||
| 76 | |||
| 77 | function resultMotion(index: number) { | ||
| 78 | if (!animationsEnabled.value) return {} | ||
| 79 | return { | ||
| 80 | layout: true, | ||
| 81 | initial: { opacity: 0, scale: 0.9375 }, | ||
| 82 | animate: { opacity: 1, scale: 1 }, | ||
| 83 | exit: { | ||
| 84 | opacity: 0, | ||
| 85 | scale: 0.9375, | ||
| 86 | height: 0, | ||
| 87 | transition: { duration: 0.25 } | ||
| 88 | }, | ||
| 89 | transition: { | ||
| 90 | duration: 0.55, | ||
| 91 | ease: searchMotionEase, | ||
| 92 | delay: index * 0.02 | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | const excerptMotion = computed(() => | ||
| 98 | animationsEnabled.value | ||
| 99 | ? { | ||
| 100 | layout: true, | ||
| 101 | initial: { height: 0 }, | ||
| 102 | animate: { height: '84px' }, | ||
| 103 | exit: { height: 0 }, | ||
| 104 | transition: { duration: 0.4, ease: searchMotionEase } | ||
| 105 | } | ||
| 106 | : {} | ||
| 107 | ) | ||
| 108 | |||
| 109 | const footerMotion = computed(() => | ||
| 110 | animationsEnabled.value ? { layout: true } : {} | ||
| 111 | ) | ||
| 112 | |||
| 113 | return { | ||
| 114 | searchMotionDiv, | ||
| 115 | searchMotionForm, | ||
| 116 | searchMotionLi, | ||
| 117 | backdropMotion, | ||
| 118 | shellMotion, | ||
| 119 | formMotion, | ||
| 120 | ribbonMotion, | ||
| 121 | emptyStateMotion, | ||
| 122 | resultMotion, | ||
| 123 | excerptMotion, | ||
| 124 | footerMotion | ||
| 125 | } | ||
| 126 | } | ||
docs/.vitepress/theme/components/search/SearchPagination.vue added +172
| @@ -0,0 +1,172 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { ChevronRight } from 'lucide-vue-next' | ||
| 3 | |||
| 4 | defineProps<{ | ||
| 5 | urlSearchMode: boolean | ||
| 6 | urlTotalPages: number | ||
| 7 | urlCurrentPage: number | ||
| 8 | urlPageList: (number | '…')[] | ||
| 9 | normalTotalPages: number | ||
| 10 | normalCurrentPage: number | ||
| 11 | normalPageList: (number | '…')[] | ||
| 12 | }>() | ||
| 13 | |||
| 14 | const emit = defineEmits<{ | ||
| 15 | goToUrlPage: [page: number] | ||
| 16 | goToNormalPage: [page: number] | ||
| 17 | }>() | ||
| 18 | </script> | ||
| 19 | |||
| 20 | <template> | ||
| 21 | <nav | ||
| 22 | class="url-pagination" | ||
| 23 | aria-label="Search result pages" | ||
| 24 | > | ||
| 25 | <div | ||
| 26 | v-if="(urlSearchMode | ||
| 27 | ? urlTotalPages | ||
| 28 | : normalTotalPages) > 1" | ||
| 29 | class="url-pagination-segment" | ||
| 30 | > | ||
| 31 | <button | ||
| 32 | type="button" | ||
| 33 | class="url-page-btn url-page-nav" | ||
| 34 | :disabled="(urlSearchMode | ||
| 35 | ? urlCurrentPage | ||
| 36 | : normalCurrentPage) <= 1" | ||
| 37 | aria-label="Previous page" | ||
| 38 | @click="urlSearchMode | ||
| 39 | ? emit('goToUrlPage', urlCurrentPage - 1) | ||
| 40 | : emit('goToNormalPage', normalCurrentPage - 1)" | ||
| 41 | > | ||
| 42 | <ChevronRight | ||
| 43 | :size="14" | ||
| 44 | stroke-width="2" | ||
| 45 | style="transform: rotate(180deg)" | ||
| 46 | /> | ||
| 47 | </button> | ||
| 48 | |||
| 49 | <template | ||
| 50 | v-for="(p, pi) in urlSearchMode ? urlPageList : normalPageList" | ||
| 51 | :key="pi" | ||
| 52 | > | ||
| 53 | <span v-if="p === '…'" class="url-page-ellipsis">…</span> | ||
| 54 | <button | ||
| 55 | v-else | ||
| 56 | type="button" | ||
| 57 | class="url-page-btn" | ||
| 58 | :class="{ | ||
| 59 | active: p === (urlSearchMode | ||
| 60 | ? urlCurrentPage | ||
| 61 | : normalCurrentPage) | ||
| 62 | }" | ||
| 63 | :aria-current="p === (urlSearchMode | ||
| 64 | ? urlCurrentPage | ||
| 65 | : normalCurrentPage) | ||
| 66 | ? 'page' | ||
| 67 | : undefined" | ||
| 68 | @click="urlSearchMode | ||
| 69 | ? emit('goToUrlPage', p as number) | ||
| 70 | : emit('goToNormalPage', p as number)" | ||
| 71 | > | ||
| 72 | {{ p }} | ||
| 73 | </button> | ||
| 74 | </template> | ||
| 75 | |||
| 76 | <button | ||
| 77 | type="button" | ||
| 78 | class="url-page-btn url-page-nav" | ||
| 79 | :disabled="(urlSearchMode | ||
| 80 | ? urlCurrentPage | ||
| 81 | : normalCurrentPage) >= | ||
| 82 | (urlSearchMode | ||
| 83 | ? urlTotalPages | ||
| 84 | : normalTotalPages)" | ||
| 85 | aria-label="Next page" | ||
| 86 | @click="urlSearchMode | ||
| 87 | ? emit('goToUrlPage', urlCurrentPage + 1) | ||
| 88 | : emit('goToNormalPage', normalCurrentPage + 1)" | ||
| 89 | > | ||
| 90 | <ChevronRight :size="14" stroke-width="2" /> | ||
| 91 | </button> | ||
| 92 | </div> | ||
| 93 | </nav> | ||
| 94 | </template> | ||
| 95 | |||
| 96 | <style> | ||
| 97 | .url-pagination { | ||
| 98 | display: flex; | ||
| 99 | align-items: center; | ||
| 100 | justify-content: center; | ||
| 101 | flex: 0 0 auto !important; | ||
| 102 | } | ||
| 103 | |||
| 104 | .url-pagination:has(.url-pagination-segment) { | ||
| 105 | padding-top: 8px; | ||
| 106 | } | ||
| 107 | |||
| 108 | .url-pagination-segment { | ||
| 109 | display: flex; | ||
| 110 | align-items: center; | ||
| 111 | border: 1px solid var(--vp-c-divider); | ||
| 112 | border-radius: 5px; | ||
| 113 | overflow: hidden; | ||
| 114 | background: transparent; | ||
| 115 | } | ||
| 116 | |||
| 117 | .url-page-btn { | ||
| 118 | display: flex; | ||
| 119 | align-items: center; | ||
| 120 | justify-content: center; | ||
| 121 | min-width: 32px; | ||
| 122 | height: 28px; | ||
| 123 | padding: 0 8px; | ||
| 124 | border: none; | ||
| 125 | background: transparent; | ||
| 126 | color: var(--vp-c-text-2); | ||
| 127 | font-size: 0.82rem; | ||
| 128 | cursor: pointer; | ||
| 129 | transition: color 0.15s, background-color 0.15s; | ||
| 130 | border-radius: 0; | ||
| 131 | } | ||
| 132 | |||
| 133 | .url-page-btn + .url-page-btn, | ||
| 134 | .url-page-ellipsis + .url-page-btn, | ||
| 135 | .url-page-btn + .url-page-ellipsis { | ||
| 136 | border-left: 1px solid var(--vp-c-divider); | ||
| 137 | } | ||
| 138 | |||
| 139 | .url-page-btn:hover:not(:disabled):not(.active) { | ||
| 140 | color: var(--vp-c-text-1); | ||
| 141 | background: var(--vp-c-default-soft); | ||
| 142 | } | ||
| 143 | |||
| 144 | .url-page-btn.active { | ||
| 145 | color: var(--vp-c-brand-1); | ||
| 146 | background: color-mix(in srgb, var(--vp-c-brand-1) 10%, transparent); | ||
| 147 | font-weight: 500; | ||
| 148 | cursor: default; | ||
| 149 | } | ||
| 150 | |||
| 151 | .url-page-btn:disabled { | ||
| 152 | opacity: 0.25; | ||
| 153 | cursor: not-allowed; | ||
| 154 | background: transparent; | ||
| 155 | } | ||
| 156 | |||
| 157 | .url-page-nav { | ||
| 158 | padding: 0 6px; | ||
| 159 | } | ||
| 160 | |||
| 161 | .url-page-ellipsis { | ||
| 162 | display: flex; | ||
| 163 | align-items: center; | ||
| 164 | justify-content: center; | ||
| 165 | min-width: 28px; | ||
| 166 | height: 28px; | ||
| 167 | color: var(--vp-c-text-3); | ||
| 168 | font-size: 0.8rem; | ||
| 169 | user-select: none; | ||
| 170 | background: transparent; | ||
| 171 | } | ||
| 172 | </style> | ||
docs/.vitepress/theme/components/search/SearchRibbon.vue added +346
| @@ -0,0 +1,346 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { ChevronRight } from 'lucide-vue-next' | ||
| 3 | import { nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' | ||
| 4 | import { useEventListener } from '@vueuse/core' | ||
| 5 | |||
| 6 | interface PageGroup { | ||
| 7 | key: string | ||
| 8 | label: string | ||
| 9 | count: number | ||
| 10 | } | ||
| 11 | |||
| 12 | const props = defineProps<{ | ||
| 13 | searchMotionDiv: string | object | ||
| 14 | ribbonMotion: Record<string, unknown> | ||
| 15 | searchAnimationsEnabled: boolean | ||
| 16 | urlSearchMode: boolean | ||
| 17 | urlPageGroups: PageGroup[] | ||
| 18 | urlActivePageFilter: string | null | ||
| 19 | urlMatchesLength: number | ||
| 20 | pageGroups: PageGroup[] | ||
| 21 | activePageFilter: string | null | ||
| 22 | resultsLength: number | ||
| 23 | }>() | ||
| 24 | |||
| 25 | const emit = defineEmits<{ | ||
| 26 | selectUrlPage: [key: string | null] | ||
| 27 | selectPage: [key: string | null] | ||
| 28 | }>() | ||
| 29 | |||
| 30 | const ribbonTrack = shallowRef<HTMLElement>() | ||
| 31 | const ribbonCanScrollLeft = ref(false) | ||
| 32 | const ribbonCanScrollRight = ref(false) | ||
| 33 | let ribbonAnimHandle = 0 | ||
| 34 | |||
| 35 | function updateRibbonOverflow() { | ||
| 36 | const track = getRibbonTrack() | ||
| 37 | if (!track) { ribbonCanScrollLeft.value = false; ribbonCanScrollRight.value = false; return } | ||
| 38 | ribbonCanScrollLeft.value = track.scrollLeft > 2 | ||
| 39 | ribbonCanScrollRight.value = track.scrollWidth - track.clientWidth - track.scrollLeft > 2 | ||
| 40 | } | ||
| 41 | |||
| 42 | function getRibbonTrack(): HTMLElement | null { | ||
| 43 | return ribbonTrack.value ?? null | ||
| 44 | } | ||
| 45 | |||
| 46 | function scrollActivePagePillIntoView(direction = 0) { | ||
| 47 | nextTick(() => { | ||
| 48 | const track = getRibbonTrack() | ||
| 49 | if (!track) return | ||
| 50 | const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')] | ||
| 51 | const activeIndex = pills.findIndex((pill) => pill.classList.contains('active')) | ||
| 52 | const active = pills[activeIndex] | ||
| 53 | if (!active) return | ||
| 54 | const trackRect = track.getBoundingClientRect() | ||
| 55 | const activeRect = active.getBoundingClientRect() | ||
| 56 | const gap = 8 | ||
| 57 | let nextScrollLeft = track.scrollLeft | ||
| 58 | if (activeRect.left < trackRect.left) { | ||
| 59 | nextScrollLeft += activeRect.left - trackRect.left - gap | ||
| 60 | } else if (activeRect.right > trackRect.right) { | ||
| 61 | nextScrollLeft += activeRect.right - trackRect.right + gap | ||
| 62 | } | ||
| 63 | const peek = pills[activeIndex + Math.sign(direction)] | ||
| 64 | if (peek) { | ||
| 65 | const peekRect = peek.getBoundingClientRect() | ||
| 66 | if (direction > 0 && peekRect.right > trackRect.right) { | ||
| 67 | nextScrollLeft += peekRect.right - trackRect.right + gap | ||
| 68 | } else if (direction < 0 && peekRect.left < trackRect.left) { | ||
| 69 | nextScrollLeft += peekRect.left - trackRect.left - gap | ||
| 70 | } | ||
| 71 | } | ||
| 72 | const max = track.scrollWidth - track.clientWidth | ||
| 73 | track.scrollTo({ | ||
| 74 | left: Math.max(0, Math.min(max, nextScrollLeft)), | ||
| 75 | behavior: props.searchAnimationsEnabled ? 'smooth' : 'auto' | ||
| 76 | }) | ||
| 77 | updateRibbonOverflow() | ||
| 78 | }) | ||
| 79 | } | ||
| 80 | |||
| 81 | function scrollRibbon(direction: number) { | ||
| 82 | const track = getRibbonTrack() | ||
| 83 | if (!track) return | ||
| 84 | const max = track.scrollWidth - track.clientWidth | ||
| 85 | const amount = track.clientWidth * 0.7 * direction | ||
| 86 | const from = track.scrollLeft | ||
| 87 | const to = Math.max(0, Math.min(max, from + amount)) | ||
| 88 | if (to === from) return | ||
| 89 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) | ||
| 90 | if (!props.searchAnimationsEnabled) { track.scrollLeft = to; updateRibbonOverflow(); return } | ||
| 91 | |||
| 92 | const duration = 280 | ||
| 93 | const start = performance.now() | ||
| 94 | const ease = (t: number) => 1 - Math.pow(1 - t, 3) | ||
| 95 | const step = (now: number) => { | ||
| 96 | const t = Math.min(1, (now - start) / duration) | ||
| 97 | track.scrollLeft = from + (to - from) * ease(t) | ||
| 98 | updateRibbonOverflow() | ||
| 99 | if (t < 1) ribbonAnimHandle = requestAnimationFrame(step) | ||
| 100 | else ribbonAnimHandle = 0 | ||
| 101 | } | ||
| 102 | ribbonAnimHandle = requestAnimationFrame(step) | ||
| 103 | } | ||
| 104 | |||
| 105 | watch(() => props.pageGroups, () => { nextTick(updateRibbonOverflow) }) | ||
| 106 | watch(() => props.urlPageGroups, () => { nextTick(updateRibbonOverflow) }) | ||
| 107 | useEventListener('resize', updateRibbonOverflow) | ||
| 108 | |||
| 109 | onBeforeUnmount(() => { | ||
| 110 | if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle) | ||
| 111 | }) | ||
| 112 | |||
| 113 | defineExpose({ scrollActivePagePillIntoView }) | ||
| 114 | |||
| 115 | function setUrlPageFilter(key: string | null) { | ||
| 116 | emit('selectUrlPage', key) | ||
| 117 | nextTick(updateRibbonOverflow) | ||
| 118 | } | ||
| 119 | |||
| 120 | function setPageFilter(key: string | null) { | ||
| 121 | emit('selectPage', key) | ||
| 122 | nextTick(updateRibbonOverflow) | ||
| 123 | } | ||
| 124 | </script> | ||
| 125 | |||
| 126 | <template> | ||
| 127 | <component | ||
| 128 | :is="searchMotionDiv" | ||
| 129 | v-if="urlSearchMode | ||
| 130 | ? urlPageGroups.length > 1 | ||
| 131 | : pageGroups.length > 1" | ||
| 132 | class="page-ribbon" | ||
| 133 | :class="{ | ||
| 134 | 'can-scroll-left': ribbonCanScrollLeft, | ||
| 135 | 'can-scroll-right': ribbonCanScrollRight | ||
| 136 | }" | ||
| 137 | v-bind="ribbonMotion" | ||
| 138 | > | ||
| 139 | <button | ||
| 140 | v-if="ribbonCanScrollLeft" | ||
| 141 | type="button" | ||
| 142 | class="page-ribbon-arrow left" | ||
| 143 | aria-label="Scroll filters left" | ||
| 144 | @click="scrollRibbon(-1)" | ||
| 145 | > | ||
| 146 | <ChevronRight :size="18" stroke-width="1.75" /> | ||
| 147 | </button> | ||
| 148 | <div | ||
| 149 | ref="ribbonTrack" | ||
| 150 | class="page-ribbon-track" | ||
| 151 | @scroll="updateRibbonOverflow" | ||
| 152 | > | ||
| 153 | <!-- URL mode tabs --> | ||
| 154 | <template v-if="urlSearchMode"> | ||
| 155 | <button | ||
| 156 | type="button" | ||
| 157 | class="page-pill" | ||
| 158 | :class="{ active: urlActivePageFilter === null }" | ||
| 159 | @click="setUrlPageFilter(null)" | ||
| 160 | > | ||
| 161 | All | ||
| 162 | <span class="page-pill-count">{{ urlMatchesLength }}</span> | ||
| 163 | </button> | ||
| 164 | <button | ||
| 165 | v-for="group in urlPageGroups" | ||
| 166 | :key="group.key" | ||
| 167 | type="button" | ||
| 168 | class="page-pill" | ||
| 169 | :class="{ active: urlActivePageFilter === group.key }" | ||
| 170 | @click="setUrlPageFilter(group.key)" | ||
| 171 | > | ||
| 172 | <span class="page-pill-label">{{ group.label }}</span> | ||
| 173 | <span class="page-pill-count">{{ group.count }}</span> | ||
| 174 | </button> | ||
| 175 | </template> | ||
| 176 | <!-- Normal mode tabs --> | ||
| 177 | <template v-else> | ||
| 178 | <button | ||
| 179 | type="button" | ||
| 180 | class="page-pill" | ||
| 181 | :class="{ active: activePageFilter === null }" | ||
| 182 | @click="setPageFilter(null)" | ||
| 183 | > | ||
| 184 | All | ||
| 185 | <span class="page-pill-count">{{ resultsLength }}</span> | ||
| 186 | </button> | ||
| 187 | <button | ||
| 188 | v-for="group in pageGroups" | ||
| 189 | :key="group.key" | ||
| 190 | type="button" | ||
| 191 | class="page-pill" | ||
| 192 | :class="{ active: activePageFilter === group.key }" | ||
| 193 | @click="setPageFilter(group.key)" | ||
| 194 | > | ||
| 195 | <span class="page-pill-label">{{ group.label }}</span> | ||
| 196 | <span class="page-pill-count">{{ group.count }}</span> | ||
| 197 | </button> | ||
| 198 | </template> | ||
| 199 | </div> | ||
| 200 | <button | ||
| 201 | v-if="ribbonCanScrollRight" | ||
| 202 | type="button" | ||
| 203 | class="page-ribbon-arrow right" | ||
| 204 | aria-label="Scroll filters right" | ||
| 205 | @click="scrollRibbon(1)" | ||
| 206 | > | ||
| 207 | <ChevronRight :size="18" stroke-width="1.75" /> | ||
| 208 | </button> | ||
| 209 | </component> | ||
| 210 | </template> | ||
| 211 | |||
| 212 | <style> | ||
| 213 | .page-ribbon { | ||
| 214 | display: flex; | ||
| 215 | align-items: center; | ||
| 216 | padding: 12px 0 4px; | ||
| 217 | padding-inline: calc(var(--spacing) * 3); | ||
| 218 | position: relative; | ||
| 219 | min-width: 0; | ||
| 220 | flex: none; | ||
| 221 | overflow: hidden; | ||
| 222 | transition: padding-inline 0.15s; | ||
| 223 | } | ||
| 224 | |||
| 225 | .page-ribbon.can-scroll-left { | ||
| 226 | padding-left: 42px; | ||
| 227 | } | ||
| 228 | |||
| 229 | .page-ribbon.can-scroll-right { | ||
| 230 | padding-right: 42px; | ||
| 231 | } | ||
| 232 | |||
| 233 | .page-ribbon-track { | ||
| 234 | display: flex; | ||
| 235 | flex-wrap: nowrap; | ||
| 236 | gap: 8px; | ||
| 237 | min-width: 0; | ||
| 238 | flex: 1; | ||
| 239 | overflow-x: auto; | ||
| 240 | overflow-y: hidden; | ||
| 241 | scrollbar-width: none; | ||
| 242 | -ms-overflow-style: none; | ||
| 243 | overscroll-behavior-x: contain; | ||
| 244 | } | ||
| 245 | |||
| 246 | .page-ribbon-track::-webkit-scrollbar { | ||
| 247 | display: none; | ||
| 248 | width: 0; | ||
| 249 | height: 0; | ||
| 250 | } | ||
| 251 | |||
| 252 | .page-ribbon-arrow { | ||
| 253 | position: absolute; | ||
| 254 | top: 12px; | ||
| 255 | bottom: 4px; | ||
| 256 | z-index: 2; | ||
| 257 | display: inline-flex; | ||
| 258 | align-items: center; | ||
| 259 | justify-content: center; | ||
| 260 | width: 48px; | ||
| 261 | border: none; | ||
| 262 | background: transparent; | ||
| 263 | color: var(--vp-c-text-2); | ||
| 264 | cursor: pointer; | ||
| 265 | transition: color 0.15s; | ||
| 266 | } | ||
| 267 | |||
| 268 | .page-ribbon-arrow:hover { | ||
| 269 | color: var(--vp-c-text-1); | ||
| 270 | } | ||
| 271 | |||
| 272 | .page-ribbon-arrow.right { | ||
| 273 | right: 0; | ||
| 274 | justify-content: flex-end; | ||
| 275 | padding-right: 6px; | ||
| 276 | } | ||
| 277 | |||
| 278 | .page-ribbon-arrow.left { | ||
| 279 | left: 0; | ||
| 280 | justify-content: flex-start; | ||
| 281 | padding-left: 6px; | ||
| 282 | } | ||
| 283 | |||
| 284 | .page-ribbon-arrow.left svg { | ||
| 285 | transform: rotate(180deg); | ||
| 286 | } | ||
| 287 | |||
| 288 | .page-pill { | ||
| 289 | flex: none; | ||
| 290 | display: inline-flex; | ||
| 291 | align-items: center; | ||
| 292 | gap: 6px; | ||
| 293 | padding: 6px 10px; | ||
| 294 | font-size: 0.8rem; | ||
| 295 | line-height: 1.2; | ||
| 296 | white-space: nowrap; | ||
| 297 | border-radius: 8px; | ||
| 298 | border: 1.5px solid var(--vp-c-divider); | ||
| 299 | background: var(--vp-c-bg-soft); | ||
| 300 | color: var(--vp-c-text-2); | ||
| 301 | cursor: pointer; | ||
| 302 | transition: color 0.15s, border-color 0.15s, background-color 0.15s; | ||
| 303 | } | ||
| 304 | |||
| 305 | .page-pill:hover { | ||
| 306 | color: var(--vp-c-text-1); | ||
| 307 | border-color: var(--vp-c-brand-1); | ||
| 308 | } | ||
| 309 | |||
| 310 | .page-pill.active { | ||
| 311 | color: var(--vp-c-brand-1); | ||
| 312 | border: 1.5px solid var(--vp-c-brand-1); | ||
| 313 | background: color-mix(in srgb, var(--vp-c-brand-1) 12%, transparent); | ||
| 314 | box-shadow: none; | ||
| 315 | } | ||
| 316 | |||
| 317 | .page-pill-label { | ||
| 318 | max-width: 180px; | ||
| 319 | overflow: hidden; | ||
| 320 | text-overflow: ellipsis; | ||
| 321 | } | ||
| 322 | |||
| 323 | .page-pill-count { | ||
| 324 | font-variant-numeric: tabular-nums; | ||
| 325 | font-size: 0.7rem; | ||
| 326 | padding: 1px 6px; | ||
| 327 | border-radius: 4px; | ||
| 328 | background: rgba(128, 128, 128, 0.15); | ||
| 329 | color: inherit; | ||
| 330 | } | ||
| 331 | |||
| 332 | .page-pill.active .page-pill-count { | ||
| 333 | background: color-mix(in srgb, var(--vp-c-brand-1) 18%, transparent); | ||
| 334 | } | ||
| 335 | |||
| 336 | @media (max-width: 767px) { | ||
| 337 | .page-ribbon { | ||
| 338 | padding: 14px 12px 4px; | ||
| 339 | } | ||
| 340 | |||
| 341 | .page-pill { | ||
| 342 | padding: 4px 8px; | ||
| 343 | font-size: 0.75rem; | ||
| 344 | } | ||
| 345 | } | ||
| 346 | </style> | ||
docs/.vitepress/theme/components/search/SearchSettings.vue added +694
| @@ -0,0 +1,694 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { onClickOutside, useElementBounding } from '@vueuse/core' | ||
| 3 | import { | ||
| 4 | Clock, | ||
| 5 | Globe, | ||
| 6 | Highlighter, | ||
| 7 | Layers, | ||
| 8 | LayoutList, | ||
| 9 | List, | ||
| 10 | LocateOff, | ||
| 11 | Regex, | ||
| 12 | Search, | ||
| 13 | TextAlignStart | ||
| 14 | } from 'lucide-vue-next' | ||
| 15 | import { computed, nextTick, ref, watch } from 'vue' | ||
| 16 | import { | ||
| 17 | excerptPreload, | ||
| 18 | saveHistoryEnabled, | ||
| 19 | searchMode, | ||
| 20 | searchResultHighlightMode, | ||
| 21 | showDetailedList | ||
| 22 | } from '../../searchState' | ||
| 23 | import type { SearchSortMode } from '../../searchState' | ||
| 24 | |||
| 25 | const props = defineProps<{ | ||
| 26 | showSettingsPopup: boolean | ||
| 27 | settingsButtonRef: HTMLElement | undefined | ||
| 28 | }>() | ||
| 29 | |||
| 30 | const emit = defineEmits<{ | ||
| 31 | 'update:showSettingsPopup': [value: boolean] | ||
| 32 | }>() | ||
| 33 | |||
| 34 | const settingsPopupRef = ref<HTMLDivElement>() | ||
| 35 | const settingsBounding = useElementBounding(() => props.settingsButtonRef) | ||
| 36 | |||
| 37 | type HelpSection = 'search' | 'view' | 'preload' | 'highlight' | 'history' | ||
| 38 | const activeHelpSection = ref<HelpSection | null>(null) | ||
| 39 | const helpPopupEl = ref<HTMLDivElement>() | ||
| 40 | const helpPopupPos = ref({ top: -9999, left: -9999 }) | ||
| 41 | |||
| 42 | watch(() => props.showSettingsPopup, (val) => { | ||
| 43 | if (!val) { | ||
| 44 | activeHelpSection.value = null | ||
| 45 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 46 | } | ||
| 47 | }) | ||
| 48 | |||
| 49 | const canHoverHelp = () => | ||
| 50 | typeof window !== 'undefined' && window.matchMedia('(hover: hover)').matches | ||
| 51 | |||
| 52 | function positionHelpPopup(btn: HTMLElement) { | ||
| 53 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 54 | const rect = btn.getBoundingClientRect() | ||
| 55 | const menuRect = settingsPopupRef.value?.getBoundingClientRect() | ||
| 56 | nextTick(() => { | ||
| 57 | const popupW = helpPopupEl.value?.offsetWidth || 260 | ||
| 58 | const popupH = helpPopupEl.value?.offsetHeight || 200 | ||
| 59 | const vw = window.innerWidth | ||
| 60 | const margin = 8 | ||
| 61 | const isMobile = vw < 768 | ||
| 62 | if (isMobile) { | ||
| 63 | const aboveTop = rect.top - popupH - margin | ||
| 64 | const belowTop = rect.bottom + margin | ||
| 65 | const top = aboveTop >= margin ? aboveTop : belowTop | ||
| 66 | const left = Math.max(margin, Math.min((vw - popupW) / 2, vw - popupW - margin)) | ||
| 67 | helpPopupPos.value = { top, left } | ||
| 68 | } else { | ||
| 69 | const anchorLeft = menuRect ? menuRect.left : rect.left | ||
| 70 | helpPopupPos.value = { | ||
| 71 | left: Math.max(margin, anchorLeft - popupW - 16), | ||
| 72 | top: rect.top, | ||
| 73 | } | ||
| 74 | } | ||
| 75 | }) | ||
| 76 | } | ||
| 77 | |||
| 78 | function closeHelpSection() { | ||
| 79 | activeHelpSection.value = null | ||
| 80 | helpPopupPos.value = { top: -9999, left: -9999 } | ||
| 81 | } | ||
| 82 | |||
| 83 | function toggleHelpSection(section: HelpSection, e: MouseEvent) { | ||
| 84 | if (canHoverHelp()) { | ||
| 85 | activeHelpSection.value = section | ||
| 86 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 87 | return | ||
| 88 | } | ||
| 89 | if (activeHelpSection.value === section) { | ||
| 90 | closeHelpSection() | ||
| 91 | return | ||
| 92 | } | ||
| 93 | activeHelpSection.value = section | ||
| 94 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 95 | } | ||
| 96 | |||
| 97 | function onHelpEnter(section: HelpSection, e: MouseEvent) { | ||
| 98 | if (!canHoverHelp()) return | ||
| 99 | activeHelpSection.value = section | ||
| 100 | positionHelpPopup(e.currentTarget as HTMLElement) | ||
| 101 | } | ||
| 102 | |||
| 103 | function onHelpLeave() { | ||
| 104 | if (!canHoverHelp()) return | ||
| 105 | closeHelpSection() | ||
| 106 | } | ||
| 107 | |||
| 108 | const settingsPopupStyle = computed(() => ({ | ||
| 109 | top: `${settingsBounding.bottom.value + 8}px`, | ||
| 110 | right: `calc(100vw - ${settingsBounding.right.value}px)`, | ||
| 111 | })) | ||
| 112 | |||
| 113 | onClickOutside(settingsPopupRef, () => { | ||
| 114 | emit('update:showSettingsPopup', false) | ||
| 115 | }, { ignore: [props.settingsButtonRef] }) | ||
| 116 | |||
| 117 | function setSearchMode(mode: string) { | ||
| 118 | searchMode.value = mode as SearchSortMode | ||
| 119 | } | ||
| 120 | </script> | ||
| 121 | |||
| 122 | <template> | ||
| 123 | <Transition name="settings-popup"> | ||
| 124 | <div | ||
| 125 | v-if="showSettingsPopup" | ||
| 126 | ref="settingsPopupRef" | ||
| 127 | class="search-settings-popup" | ||
| 128 | :style="settingsPopupStyle" | ||
| 129 | @click="closeHelpSection" | ||
| 130 | > | ||
| 131 | <!-- Search Mode --> | ||
| 132 | <div class="settings-section"> | ||
| 133 | <div class="settings-section-header"> | ||
| 134 | <div class="settings-section-label"> | ||
| 135 | <Search :size="14" stroke-width="1.75" /> | ||
| 136 | Search | ||
| 137 | </div> | ||
| 138 | <button | ||
| 139 | type="button" | ||
| 140 | class="settings-help-btn" | ||
| 141 | :class="{ active: activeHelpSection === 'search' }" | ||
| 142 | aria-label="Search mode help" | ||
| 143 | @click.stop="toggleHelpSection('search', $event)" | ||
| 144 | @mouseenter="onHelpEnter('search', $event)" | ||
| 145 | @mouseleave="onHelpLeave" | ||
| 146 | > | ||
| 147 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 148 | </button> | ||
| 149 | </div> | ||
| 150 | <div | ||
| 151 | class="settings-options" | ||
| 152 | :class="{ 'is-highlighted': activeHelpSection === 'search' }" | ||
| 153 | > | ||
| 154 | <button | ||
| 155 | type="button" | ||
| 156 | class="settings-option" | ||
| 157 | :class="{ active: searchMode === 'exact' }" | ||
| 158 | @click="setSearchMode('exact')" | ||
| 159 | > | ||
| 160 | <span>Exact</span> | ||
| 161 | </button> | ||
| 162 | <button | ||
| 163 | type="button" | ||
| 164 | class="settings-option" | ||
| 165 | :class="{ active: searchMode === 'fuzzy' }" | ||
| 166 | @click="setSearchMode('fuzzy')" | ||
| 167 | > | ||
| 168 | <span>Fuzzy</span> | ||
| 169 | </button> | ||
| 170 | <button | ||
| 171 | type="button" | ||
| 172 | class="settings-option" | ||
| 173 | :class="{ active: searchMode === 'url' }" | ||
| 174 | @click="setSearchMode('url')" | ||
| 175 | > | ||
| 176 | <span>URL</span> | ||
| 177 | </button> | ||
| 178 | </div> | ||
| 179 | </div> | ||
| 180 | |||
| 181 | <!-- View --> | ||
| 182 | <div | ||
| 183 | v-if="searchMode !== 'url'" | ||
| 184 | class="settings-section" | ||
| 185 | > | ||
| 186 | <div class="settings-section-header"> | ||
| 187 | <div class="settings-section-label"> | ||
| 188 | <LayoutList :size="14" stroke-width="1.75" /> | ||
| 189 | View | ||
| 190 | </div> | ||
| 191 | <button | ||
| 192 | type="button" | ||
| 193 | class="settings-help-btn" | ||
| 194 | :class="{ active: activeHelpSection === 'view' }" | ||
| 195 | aria-label="Result view help" | ||
| 196 | @click.stop="toggleHelpSection('view', $event)" | ||
| 197 | @mouseenter="onHelpEnter('view', $event)" | ||
| 198 | @mouseleave="onHelpLeave" | ||
| 199 | > | ||
| 200 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 201 | </button> | ||
| 202 | </div> | ||
| 203 | <div | ||
| 204 | class="settings-options" | ||
| 205 | :class="{ 'is-highlighted': activeHelpSection === 'view' }" | ||
| 206 | > | ||
| 207 | <button | ||
| 208 | type="button" | ||
| 209 | class="settings-option" | ||
| 210 | :class="{ active: showDetailedList }" | ||
| 211 | @click="showDetailedList = true" | ||
| 212 | > | ||
| 213 | <span>Detail</span> | ||
| 214 | </button> | ||
| 215 | <button | ||
| 216 | type="button" | ||
| 217 | class="settings-option" | ||
| 218 | :class="{ active: !showDetailedList }" | ||
| 219 | @click="showDetailedList = false" | ||
| 220 | > | ||
| 221 | <span>List</span> | ||
| 222 | </button> | ||
| 223 | </div> | ||
| 224 | </div> | ||
| 225 | |||
| 226 | <!-- Preload --> | ||
| 227 | <div | ||
| 228 | v-if="searchMode !== 'url' && showDetailedList" | ||
| 229 | class="settings-section" | ||
| 230 | > | ||
| 231 | <div class="settings-section-header"> | ||
| 232 | <div class="settings-section-label"> | ||
| 233 | <Layers :size="14" stroke-width="1.75" /> | ||
| 234 | Preload | ||
| 235 | </div> | ||
| 236 | <button | ||
| 237 | type="button" | ||
| 238 | class="settings-help-btn" | ||
| 239 | :class="{ active: activeHelpSection === 'preload' }" | ||
| 240 | aria-label="Excerpt preload help" | ||
| 241 | @click.stop="toggleHelpSection('preload', $event)" | ||
| 242 | @mouseenter="onHelpEnter('preload', $event)" | ||
| 243 | @mouseleave="onHelpLeave" | ||
| 244 | > | ||
| 245 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 246 | </button> | ||
| 247 | </div> | ||
| 248 | <div | ||
| 249 | class="settings-options" | ||
| 250 | :class="{ 'is-highlighted': activeHelpSection === 'preload' }" | ||
| 251 | > | ||
| 252 | <button | ||
| 253 | type="button" | ||
| 254 | class="settings-option" | ||
| 255 | :class="{ active: excerptPreload === 'all' }" | ||
| 256 | @click="excerptPreload = 'all'" | ||
| 257 | > | ||
| 258 | <span>All</span> | ||
| 259 | </button> | ||
| 260 | <button | ||
| 261 | type="button" | ||
| 262 | class="settings-option" | ||
| 263 | :class="{ active: excerptPreload === 'next' }" | ||
| 264 | @click="excerptPreload = 'next'" | ||
| 265 | > | ||
| 266 | <span>Next</span> | ||
| 267 | </button> | ||
| 268 | <button | ||
| 269 | type="button" | ||
| 270 | class="settings-option" | ||
| 271 | :class="{ active: excerptPreload === 'off' }" | ||
| 272 | @click="excerptPreload = 'off'" | ||
| 273 | > | ||
| 274 | <span>Off</span> | ||
| 275 | </button> | ||
| 276 | </div> | ||
| 277 | </div> | ||
| 278 | |||
| 279 | <!-- Highlight --> | ||
| 280 | <div class="settings-section"> | ||
| 281 | <div class="settings-section-header"> | ||
| 282 | <div class="settings-section-label"> | ||
| 283 | <Highlighter :size="14" stroke-width="1.75" /> | ||
| 284 | Highlight | ||
| 285 | </div> | ||
| 286 | <button | ||
| 287 | type="button" | ||
| 288 | class="settings-help-btn" | ||
| 289 | :class="{ active: activeHelpSection === 'highlight' }" | ||
| 290 | aria-label="Search result highlight help" | ||
| 291 | @click.stop="toggleHelpSection('highlight', $event)" | ||
| 292 | @mouseenter="onHelpEnter('highlight', $event)" | ||
| 293 | @mouseleave="onHelpLeave" | ||
| 294 | > | ||
| 295 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 296 | </button> | ||
| 297 | </div> | ||
| 298 | <div | ||
| 299 | class="settings-options" | ||
| 300 | :class="{ 'is-highlighted': activeHelpSection === 'highlight' }" | ||
| 301 | > | ||
| 302 | <button | ||
| 303 | type="button" | ||
| 304 | class="settings-option" | ||
| 305 | :class="{ active: searchResultHighlightMode === 'soft' }" | ||
| 306 | @click="searchResultHighlightMode = 'soft'" | ||
| 307 | > | ||
| 308 | <span>Soft</span> | ||
| 309 | </button> | ||
| 310 | <button | ||
| 311 | type="button" | ||
| 312 | class="settings-option" | ||
| 313 | :class="{ active: searchResultHighlightMode === 'solid' }" | ||
| 314 | @click="searchResultHighlightMode = 'solid'" | ||
| 315 | > | ||
| 316 | <span>Solid</span> | ||
| 317 | </button> | ||
| 318 | <button | ||
| 319 | type="button" | ||
| 320 | class="settings-option" | ||
| 321 | :class="{ active: searchResultHighlightMode === 'off' }" | ||
| 322 | @click="searchResultHighlightMode = 'off'" | ||
| 323 | > | ||
| 324 | <span>Off</span> | ||
| 325 | </button> | ||
| 326 | </div> | ||
| 327 | </div> | ||
| 328 | |||
| 329 | <!-- History --> | ||
| 330 | <div class="settings-section"> | ||
| 331 | <div class="settings-section-header"> | ||
| 332 | <div class="settings-section-label"> | ||
| 333 | <Clock :size="14" stroke-width="1.75" /> | ||
| 334 | History | ||
| 335 | </div> | ||
| 336 | <button | ||
| 337 | type="button" | ||
| 338 | class="settings-help-btn" | ||
| 339 | :class="{ active: activeHelpSection === 'history' }" | ||
| 340 | aria-label="Search history help" | ||
| 341 | @click.stop="toggleHelpSection('history', $event)" | ||
| 342 | @mouseenter="onHelpEnter('history', $event)" | ||
| 343 | @mouseleave="onHelpLeave" | ||
| 344 | > | ||
| 345 | <span class="i-carbon:help-filled settings-help-icon" /> | ||
| 346 | </button> | ||
| 347 | </div> | ||
| 348 | <div | ||
| 349 | class="settings-options" | ||
| 350 | :class="{ 'is-highlighted': activeHelpSection === 'history' }" | ||
| 351 | > | ||
| 352 | <button | ||
| 353 | type="button" | ||
| 354 | class="settings-option" | ||
| 355 | :class="{ active: saveHistoryEnabled }" | ||
| 356 | @click="saveHistoryEnabled = true" | ||
| 357 | > | ||
| 358 | <span>On</span> | ||
| 359 | </button> | ||
| 360 | <button | ||
| 361 | type="button" | ||
| 362 | class="settings-option" | ||
| 363 | :class="{ active: !saveHistoryEnabled }" | ||
| 364 | @click="saveHistoryEnabled = false" | ||
| 365 | > | ||
| 366 | <span>Off</span> | ||
| 367 | </button> | ||
| 368 | </div> | ||
| 369 | </div> | ||
| 370 | </div> | ||
| 371 | </Transition> | ||
| 372 | |||
| 373 | <!-- Help popups --> | ||
| 374 | <Transition name="help-popup-fade"> | ||
| 375 | <div | ||
| 376 | v-if="activeHelpSection && showSettingsPopup" | ||
| 377 | ref="helpPopupEl" | ||
| 378 | class="search-help-popup" | ||
| 379 | :style="{ top: helpPopupPos.top + 'px', left: helpPopupPos.left + 'px' }" | ||
| 380 | > | ||
| 381 | <template v-if="activeHelpSection === 'search'"> | ||
| 382 | <h4 class="sh-title"> | ||
| 383 | <Search :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 384 | Search Mode | ||
| 385 | </h4> | ||
| 386 | <p class="sh-desc">Choose how queries are matched against content.</p> | ||
| 387 | <div class="sh-options"> | ||
| 388 | <div class="sh-option"> | ||
| 389 | <strong><Regex :size="14" stroke-width="1.5" /> Exact</strong> | ||
| 390 | <span>Matches the exact phrase you type</span> | ||
| 391 | </div> | ||
| 392 | <div class="sh-option"> | ||
| 393 | <strong><LocateOff :size="14" stroke-width="1.5" /> Fuzzy</strong> | ||
| 394 | <span>Approximate matching that tolerates typos</span> | ||
| 395 | </div> | ||
| 396 | <div class="sh-option"> | ||
| 397 | <strong><Globe :size="14" stroke-width="1.5" /> URL</strong> | ||
| 398 | <span>Searches through hyperlinks</span> | ||
| 399 | </div> | ||
| 400 | </div> | ||
| 401 | </template> | ||
| 402 | <template v-else-if="activeHelpSection === 'view'"> | ||
| 403 | <h4 class="sh-title"> | ||
| 404 | <LayoutList :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 405 | Result View | ||
| 406 | </h4> | ||
| 407 | <p class="sh-desc">Controls how search results are displayed.</p> | ||
| 408 | <div class="sh-options"> | ||
| 409 | <div class="sh-option"> | ||
| 410 | <strong><TextAlignStart :size="14" stroke-width="1.5" /> Detail</strong> | ||
| 411 | <span>Shows a content excerpt below each result. Uses more memory.</span> | ||
| 412 | </div> | ||
| 413 | <div class="sh-option"> | ||
| 414 | <strong><List :size="14" stroke-width="1.5" /> List</strong> | ||
| 415 | <span>Compact list of titles only. Uses less memory.</span> | ||
| 416 | </div> | ||
| 417 | </div> | ||
| 418 | </template> | ||
| 419 | <template v-else-if="activeHelpSection === 'preload'"> | ||
| 420 | <h4 class="sh-title"> | ||
| 421 | <Layers :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 422 | Excerpt Preload | ||
| 423 | </h4> | ||
| 424 | <p class="sh-desc">Renders excerpts for upcoming result pages ahead of time in Detail view.</p> | ||
| 425 | <div class="sh-options"> | ||
| 426 | <div class="sh-option"> | ||
| 427 | <strong>All</strong> | ||
| 428 | <span>Prepares every result page. Uses more memory.</span> | ||
| 429 | </div> | ||
| 430 | <div class="sh-option"> | ||
| 431 | <strong>Next</strong> | ||
| 432 | <span>Also prepares the next page so flipping forward is instant</span> | ||
| 433 | </div> | ||
| 434 | <div class="sh-option"> | ||
| 435 | <strong>Off</strong> | ||
| 436 | <span>Only the visible page. Uses the least memory.</span> | ||
| 437 | </div> | ||
| 438 | </div> | ||
| 439 | </template> | ||
| 440 | <template v-else-if="activeHelpSection === 'highlight'"> | ||
| 441 | <h4 class="sh-title"> | ||
| 442 | <Highlighter :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 443 | Search Result Highlight | ||
| 444 | </h4> | ||
| 445 | <p class="sh-desc">Highlights the exact result you open.</p> | ||
| 446 | <div class="sh-options"> | ||
| 447 | <div class="sh-option"> | ||
| 448 | <strong>Soft</strong> | ||
| 449 | <span>Soft accent background with a solid border.</span> | ||
| 450 | </div> | ||
| 451 | <div class="sh-option"> | ||
| 452 | <strong>Solid</strong> | ||
| 453 | <span>Solid accent fill with no border.</span> | ||
| 454 | </div> | ||
| 455 | </div> | ||
| 456 | </template> | ||
| 457 | <template v-else-if="activeHelpSection === 'history'"> | ||
| 458 | <h4 class="sh-title"> | ||
| 459 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> | ||
| 460 | Search History | ||
| 461 | </h4> | ||
| 462 | <p class="sh-desc">Saves recent searches and shows them when the search bar is empty.</p> | ||
| 463 | </template> | ||
| 464 | </div> | ||
| 465 | </Transition> | ||
| 466 | </template> | ||
| 467 | |||
| 468 | <style> | ||
| 469 | .search-settings-popup { | ||
| 470 | --seg-track: var(--wk-c-menu-bg); | ||
| 471 | --seg-pill-bg: var(--vp-c-bg); | ||
| 472 | --seg-pill-text: var(--vp-c-text-1); | ||
| 473 | --seg-pill-shadow: 0 2px 4px 0 #bababa8c; | ||
| 474 | position: fixed; | ||
| 475 | z-index: 200; | ||
| 476 | background: var(--vp-c-bg-elv); | ||
| 477 | border: 1px solid var(--vp-c-divider); | ||
| 478 | border-radius: 12px; | ||
| 479 | padding: 12px; | ||
| 480 | box-shadow: var(--vp-shadow-3); | ||
| 481 | display: flex; | ||
| 482 | flex-direction: column; | ||
| 483 | min-width: 196px; | ||
| 484 | } | ||
| 485 | |||
| 486 | .dark .search-settings-popup { | ||
| 487 | --seg-track: var(--wk-c-menu-bg); | ||
| 488 | --seg-pill-bg: var(--vp-c-text-1); | ||
| 489 | --seg-pill-text: var(--vp-c-bg-elv); | ||
| 490 | --seg-pill-shadow: 0 2px 4px 0 #535353db; | ||
| 491 | } | ||
| 492 | |||
| 493 | .settings-section { | ||
| 494 | display: flex; | ||
| 495 | flex-direction: column; | ||
| 496 | gap: 0; | ||
| 497 | } | ||
| 498 | |||
| 499 | .settings-section + .settings-section { | ||
| 500 | border-top: 1px solid var(--vp-c-divider); | ||
| 501 | margin-top: 8px; | ||
| 502 | padding-top: 8px; | ||
| 503 | } | ||
| 504 | |||
| 505 | .settings-section-header { | ||
| 506 | display: flex; | ||
| 507 | align-items: center; | ||
| 508 | justify-content: space-between; | ||
| 509 | margin-bottom: 6px; | ||
| 510 | } | ||
| 511 | |||
| 512 | .settings-section-label { | ||
| 513 | display: flex; | ||
| 514 | align-items: center; | ||
| 515 | gap: 6px; | ||
| 516 | font-size: 14px; | ||
| 517 | font-weight: 500; | ||
| 518 | color: var(--vp-c-text-1); | ||
| 519 | } | ||
| 520 | |||
| 521 | .settings-help-btn { | ||
| 522 | display: flex; | ||
| 523 | align-items: center; | ||
| 524 | justify-content: center; | ||
| 525 | padding: 3px; | ||
| 526 | background: transparent; | ||
| 527 | border: none; | ||
| 528 | cursor: pointer; | ||
| 529 | color: var(--vp-c-text-3); | ||
| 530 | opacity: 0.5; | ||
| 531 | transition: opacity 0.15s, color 0.15s; | ||
| 532 | border-radius: 3px; | ||
| 533 | line-height: 1; | ||
| 534 | } | ||
| 535 | |||
| 536 | .settings-help-btn:hover, | ||
| 537 | .settings-help-btn.active { | ||
| 538 | opacity: 1; | ||
| 539 | color: var(--vp-c-text-1); | ||
| 540 | } | ||
| 541 | |||
| 542 | .settings-help-icon { | ||
| 543 | display: block; | ||
| 544 | width: 16px; | ||
| 545 | height: 16px; | ||
| 546 | } | ||
| 547 | |||
| 548 | .settings-options { | ||
| 549 | display: flex; | ||
| 550 | gap: 4px; | ||
| 551 | background: var(--seg-track); | ||
| 552 | border-radius: 8px; | ||
| 553 | padding: 4px; | ||
| 554 | outline: 2px dashed transparent; | ||
| 555 | outline-offset: 4px; | ||
| 556 | transition: outline-color 0.2s ease; | ||
| 557 | } | ||
| 558 | |||
| 559 | .settings-options.is-highlighted { | ||
| 560 | outline-color: var(--vp-c-brand-1); | ||
| 561 | } | ||
| 562 | |||
| 563 | .settings-option { | ||
| 564 | display: flex; | ||
| 565 | align-items: center; | ||
| 566 | justify-content: center; | ||
| 567 | gap: 5px; | ||
| 568 | padding: 5px 6px; | ||
| 569 | background: transparent; | ||
| 570 | border: none; | ||
| 571 | border-radius: 6px; | ||
| 572 | cursor: pointer; | ||
| 573 | color: var(--vp-c-text-1); | ||
| 574 | font-size: 14px; | ||
| 575 | font-weight: 500; | ||
| 576 | transition: background-color 0.15s, color 0.15s, box-shadow 0.15s; | ||
| 577 | flex: 1; | ||
| 578 | } | ||
| 579 | |||
| 580 | .settings-option:hover, | ||
| 581 | .settings-option.active { | ||
| 582 | color: var(--seg-pill-text); | ||
| 583 | background: var(--seg-pill-bg); | ||
| 584 | box-shadow: var(--seg-pill-shadow); | ||
| 585 | } | ||
| 586 | |||
| 587 | .settings-option.active { | ||
| 588 | font-weight: 700; | ||
| 589 | } | ||
| 590 | |||
| 591 | .settings-popup-enter-active, | ||
| 592 | .settings-popup-leave-active { | ||
| 593 | transition: opacity 0.15s ease, transform 0.15s ease; | ||
| 594 | transform-origin: top right; | ||
| 595 | } | ||
| 596 | |||
| 597 | .settings-popup-enter-from, | ||
| 598 | .settings-popup-leave-to { | ||
| 599 | opacity: 0; | ||
| 600 | transform: scale(0.92) translateY(-4px); | ||
| 601 | } | ||
| 602 | |||
| 603 | .search-help-popup { | ||
| 604 | position: fixed; | ||
| 605 | z-index: 9999; | ||
| 606 | width: 280px; | ||
| 607 | background: var(--vp-c-bg-elv); | ||
| 608 | border: 1px solid var(--vp-c-divider); | ||
| 609 | border-radius: 12px; | ||
| 610 | padding: 16px; | ||
| 611 | box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); | ||
| 612 | pointer-events: none; | ||
| 613 | } | ||
| 614 | |||
| 615 | .help-popup-fade-enter-active, | ||
| 616 | .help-popup-fade-leave-active { | ||
| 617 | transition: opacity 0.15s ease; | ||
| 618 | } | ||
| 619 | |||
| 620 | .help-popup-fade-enter-from, | ||
| 621 | .help-popup-fade-leave-to { | ||
| 622 | opacity: 0; | ||
| 623 | } | ||
| 624 | |||
| 625 | .sh-title { | ||
| 626 | display: flex; | ||
| 627 | align-items: center; | ||
| 628 | gap: 6px; | ||
| 629 | font-size: 1rem; | ||
| 630 | font-weight: 600; | ||
| 631 | color: var(--vp-c-text-1); | ||
| 632 | margin: 0 0 4px; | ||
| 633 | } | ||
| 634 | |||
| 635 | .sh-title-icon { | ||
| 636 | flex-shrink: 0; | ||
| 637 | opacity: 0.8; | ||
| 638 | width: 16px; | ||
| 639 | height: 16px; | ||
| 640 | } | ||
| 641 | |||
| 642 | .sh-desc { | ||
| 643 | font-size: 0.875rem; | ||
| 644 | color: var(--vp-c-text-2); | ||
| 645 | margin: 0 0 6px; | ||
| 646 | line-height: 1.5; | ||
| 647 | } | ||
| 648 | |||
| 649 | .sh-options { | ||
| 650 | display: flex; | ||
| 651 | flex-direction: column; | ||
| 652 | gap: 5px; | ||
| 653 | } | ||
| 654 | |||
| 655 | .sh-option { | ||
| 656 | display: flex; | ||
| 657 | flex-direction: column; | ||
| 658 | gap: 4px; | ||
| 659 | background: var(--wk-c-menu-bg); | ||
| 660 | border-radius: 12px; | ||
| 661 | padding: 10px 12px; | ||
| 662 | } | ||
| 663 | |||
| 664 | .dark .sh-option { | ||
| 665 | background: var(--wk-c-menu-bg); | ||
| 666 | } | ||
| 667 | |||
| 668 | .sh-option strong { | ||
| 669 | display: flex; | ||
| 670 | align-items: center; | ||
| 671 | gap: 4px; | ||
| 672 | font-size: 0.875rem; | ||
| 673 | font-weight: 600; | ||
| 674 | color: var(--vp-c-text-1); | ||
| 675 | } | ||
| 676 | |||
| 677 | .sh-option span { | ||
| 678 | font-size: 0.875rem; | ||
| 679 | color: var(--vp-c-text-2); | ||
| 680 | line-height: 1.4; | ||
| 681 | } | ||
| 682 | |||
| 683 | @media (max-width: 767px) { | ||
| 684 | .search-settings-popup { | ||
| 685 | display: none; | ||
| 686 | } | ||
| 687 | |||
| 688 | .search-help-popup { | ||
| 689 | position: fixed !important; | ||
| 690 | width: calc(100vw - 16px); | ||
| 691 | max-width: 300px; | ||
| 692 | } | ||
| 693 | } | ||
| 694 | </style> | ||
docs/.vitepress/theme/components/search/index.ts added +3
| @@ -0,0 +1,3 @@ | |||
| 1 | import Search from './Search.vue' | ||
| 2 | |||
| 3 | export default Search | ||
docs/.vitepress/theme/components/search/types.ts added +98
| @@ -0,0 +1,98 @@ | |||
| 1 | import type { SearchResult } from 'minisearch' | ||
| 2 | import type { PageLink } from '../../plugins/urlSearchPlugin' | ||
| 3 | import type { SearchSortMode } from '../../searchState' | ||
| 4 | |||
| 5 | export interface FooterTranslations { | ||
| 6 | selectText?: string | ||
| 7 | selectKeyAriaLabel?: string | ||
| 8 | navigateText?: string | ||
| 9 | navigateUpKeyAriaLabel?: string | ||
| 10 | navigateDownKeyAriaLabel?: string | ||
| 11 | switchTabsText?: string | ||
| 12 | switchTabsKeyAriaLabel?: string | ||
| 13 | switchPagesText?: string | ||
| 14 | switchPagesKeyAriaLabel?: string | ||
| 15 | closeText?: string | ||
| 16 | closeKeyAriaLabel?: string | ||
| 17 | } | ||
| 18 | |||
| 19 | export interface ModalTranslations { | ||
| 20 | displayDetails?: string | ||
| 21 | exactMatchTitle?: string | ||
| 22 | resetButtonTitle?: string | ||
| 23 | backButtonTitle?: string | ||
| 24 | noResultsText?: string | ||
| 25 | footer?: FooterTranslations | ||
| 26 | } | ||
| 27 | |||
| 28 | export interface Result { | ||
| 29 | tabs?: string[] | ||
| 30 | title: string | ||
| 31 | titles: string[] | ||
| 32 | text?: string | ||
| 33 | } | ||
| 34 | |||
| 35 | export interface PageGroupCount { | ||
| 36 | key: string | ||
| 37 | count: number | ||
| 38 | } | ||
| 39 | |||
| 40 | export interface UrlResult { | ||
| 41 | tabs?: string[] | ||
| 42 | href: string | ||
| 43 | linkText: string | ||
| 44 | pageId: string | ||
| 45 | anchor: string | ||
| 46 | titles: string[] | ||
| 47 | highlighted: string | ||
| 48 | } | ||
| 49 | |||
| 50 | export interface TextSearchWorkerPayload { | ||
| 51 | results: (SearchResult & Result)[] | ||
| 52 | terms: string[] | ||
| 53 | } | ||
| 54 | |||
| 55 | export interface UrlSearchWorkerPayload { | ||
| 56 | matches: PageLink[] | ||
| 57 | pageGroups: PageGroupCount[] | ||
| 58 | } | ||
| 59 | |||
| 60 | export interface LoadIndexWorkerRequest { | ||
| 61 | type: 'load-index' | ||
| 62 | localeIndex: string | ||
| 63 | indexJson: unknown | ||
| 64 | indexVersion: number | ||
| 65 | config: ReturnType<typeof getMiniSearchWorkerConfigShape> | ||
| 66 | } | ||
| 67 | |||
| 68 | export interface TextSearchWorkerRequest { | ||
| 69 | type: 'text-search' | ||
| 70 | query: string | ||
| 71 | mode: SearchSortMode | ||
| 72 | pageOrderEntries: [string, number][] | ||
| 73 | } | ||
| 74 | |||
| 75 | export interface UrlSearchWorkerRequest { | ||
| 76 | type: 'url-search' | ||
| 77 | query: string | ||
| 78 | pageOrderEntries: [string, number][] | ||
| 79 | } | ||
| 80 | |||
| 81 | export interface PreloadMetadataWorkerRequest { | ||
| 82 | type: 'preload-metadata' | ||
| 83 | pageOrderEntries: [string, number][] | ||
| 84 | } | ||
| 85 | |||
| 86 | export type SearchWorkerRequest = | ||
| 87 | | LoadIndexWorkerRequest | ||
| 88 | | TextSearchWorkerRequest | ||
| 89 | | UrlSearchWorkerRequest | ||
| 90 | | PreloadMetadataWorkerRequest | ||
| 91 | |||
| 92 | export function getMiniSearchWorkerConfigShape() { | ||
| 93 | return { | ||
| 94 | options: {} as Record<string, unknown> | undefined, | ||
| 95 | searchOptions: {} as Record<string, unknown> | undefined, | ||
| 96 | useDefaultBoostDocument: false as boolean | ||
| 97 | } | ||
| 98 | } | ||
docs/.vitepress/theme/components/search/utils.ts added +168
| @@ -0,0 +1,168 @@ | |||
| 1 | import type { SearchResult } from 'minisearch' | ||
| 2 | import type { SearchSortMode } from '../../searchState' | ||
| 3 | import type { Result, UrlResult } from './types' | ||
| 4 | |||
| 5 | // @ts-ignore | ||
| 6 | import { escapeRegExp } from 'vitepress/dist/client/shared' | ||
| 7 | |||
| 8 | export function escapeHtml(value: string) { | ||
| 9 | return value | ||
| 10 | .replace(/&/g, '&') | ||
| 11 | .replace(/</g, '<') | ||
| 12 | .replace(/>/g, '>') | ||
| 13 | .replace(/\"/g, '"') | ||
| 14 | .replace(/'/g, ''') | ||
| 15 | } | ||
| 16 | |||
| 17 | export function highlightUrl(url: string, query: string) { | ||
| 18 | const needle = query.trim() | ||
| 19 | if (!needle) return escapeHtml(url) | ||
| 20 | |||
| 21 | const lowerUrl = url.toLowerCase() | ||
| 22 | const lowerNeedle = needle.toLowerCase() | ||
| 23 | let out = '' | ||
| 24 | let cursor = 0 | ||
| 25 | let index = lowerUrl.indexOf(lowerNeedle) | ||
| 26 | |||
| 27 | while (index !== -1) { | ||
| 28 | out += escapeHtml(url.slice(cursor, index)) | ||
| 29 | out += `<mark class="url-highlight">${ | ||
| 30 | escapeHtml(url.slice(index, index + needle.length)) | ||
| 31 | }</mark>` | ||
| 32 | cursor = index + needle.length | ||
| 33 | index = lowerUrl.indexOf(lowerNeedle, cursor) | ||
| 34 | } | ||
| 35 | |||
| 36 | return out + escapeHtml(url.slice(cursor)) | ||
| 37 | } | ||
| 38 | |||
| 39 | export function formMarkRegex(terms: Set<string>) { | ||
| 40 | return new RegExp( | ||
| 41 | [...terms] | ||
| 42 | .sort((a, b) => b.length - a.length) | ||
| 43 | .map((term) => `(${escapeRegExp(term)})`) | ||
| 44 | .join('|'), | ||
| 45 | 'gi' | ||
| 46 | ) | ||
| 47 | } | ||
| 48 | |||
| 49 | export function decodeHtml(html: string): string { | ||
| 50 | const txt = document.createElement('textarea') | ||
| 51 | txt.innerHTML = html | ||
| 52 | return txt.value | ||
| 53 | } | ||
| 54 | |||
| 55 | export function toHistoryPathHtml(html: string): string { | ||
| 56 | const stripped = decodeHtml(html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim()) | ||
| 57 | if (stripped) return escapeHtml(stripped) | ||
| 58 | return html.trim() | ||
| 59 | } | ||
| 60 | |||
| 61 | export function hasExcerptPreview(html?: string) { | ||
| 62 | if (!html) return false | ||
| 63 | for (let i = 0; i < html.length; i++) { | ||
| 64 | const ch = html[i] | ||
| 65 | if (ch === '<') { | ||
| 66 | const close = html.indexOf('>', i + 1) | ||
| 67 | if (close === -1) return false | ||
| 68 | i = close | ||
| 69 | continue | ||
| 70 | } | ||
| 71 | if (ch === '&') { | ||
| 72 | const entity = html.slice(i, i + 6).toLowerCase() | ||
| 73 | if (entity === ' ' || entity === ' ') { | ||
| 74 | i += 5 | ||
| 75 | continue | ||
| 76 | } | ||
| 77 | return true | ||
| 78 | } | ||
| 79 | if (!/\s/.test(ch)) return true | ||
| 80 | } | ||
| 81 | return false | ||
| 82 | } | ||
| 83 | |||
| 84 | export function getPageKey(id: string) { | ||
| 85 | return getDocId(id).replace(/\/$/, '') | ||
| 86 | } | ||
| 87 | |||
| 88 | export function getDocId(id: string) { | ||
| 89 | const hashIndex = id.indexOf('#') | ||
| 90 | return hashIndex === -1 ? id : id.slice(0, hashIndex) | ||
| 91 | } | ||
| 92 | |||
| 93 | export function getDocAnchor(id: string) { | ||
| 94 | const hashIndex = id.indexOf('#') | ||
| 95 | return hashIndex === -1 ? '' : id.slice(hashIndex + 1) | ||
| 96 | } | ||
| 97 | |||
| 98 | export function getPageLabel(key: string, pageMeta: Map<string, { label: string; order: number }>) { | ||
| 99 | return pageMeta.get(key)?.label ?? key.replace(/^\//, '') | ||
| 100 | } | ||
| 101 | |||
| 102 | export function getPageOrder(key: string, pageMeta: Map<string, { label: string; order: number }>) { | ||
| 103 | return pageMeta.get(key)?.order ?? Number.MAX_SAFE_INTEGER | ||
| 104 | } | ||
| 105 | |||
| 106 | export function buildResultHref(pageId: string, tabs?: string[], anchor = '') { | ||
| 107 | const params: string[] = [] | ||
| 108 | if (tabs?.length) { | ||
| 109 | params.push(`t=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`) | ||
| 110 | } | ||
| 111 | |||
| 112 | let hash = '' | ||
| 113 | if (anchor.startsWith('collapsible-')) { | ||
| 114 | const collapsible = anchor.slice('collapsible-'.length) | ||
| 115 | if (collapsible) params.push(`c=${encodeURIComponent(collapsible)}`) | ||
| 116 | } else { | ||
| 117 | const lastTab = tabs?.length ? tabs[tabs.length - 1] : '' | ||
| 118 | const isRedundantTabHeading = Boolean(anchor) && anchor === `tab-${lastTab}` | ||
| 119 | if (anchor && !isRedundantTabHeading) { | ||
| 120 | hash = `#${encodeURIComponent(anchor)}` | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | const query = params.length ? `?${params.join('&')}` : '' | ||
| 125 | return `${pageId}${query}${hash}` | ||
| 126 | } | ||
| 127 | |||
| 128 | export function getSearchResultHref(item: SearchResult & Result) { | ||
| 129 | const id = String(item.id) | ||
| 130 | const hashIndex = id.indexOf('#') | ||
| 131 | if (hashIndex < 0) return buildResultHref(id, item.tabs) | ||
| 132 | |||
| 133 | return buildResultHref( | ||
| 134 | id.slice(0, hashIndex), | ||
| 135 | item.tabs, | ||
| 136 | id.slice(hashIndex + 1) | ||
| 137 | ) | ||
| 138 | } | ||
| 139 | |||
| 140 | export function cycleSearchMode(searchMode: { value: SearchSortMode }) { | ||
| 141 | const modes = ['exact', 'fuzzy', 'url'] as const | ||
| 142 | const idx = modes.indexOf(searchMode.value as 'exact' | 'fuzzy' | 'url') | ||
| 143 | searchMode.value = modes[(idx + 1) % modes.length] as SearchSortMode | ||
| 144 | } | ||
| 145 | |||
| 146 | export function stripNonCloneable(value: unknown): unknown { | ||
| 147 | if (typeof value === 'function' || typeof value === 'symbol') return undefined | ||
| 148 | if (!value || typeof value !== 'object') return value | ||
| 149 | if (Array.isArray(value)) { | ||
| 150 | return value | ||
| 151 | .map((item) => stripNonCloneable(item)) | ||
| 152 | .filter((item) => item !== undefined) | ||
| 153 | } | ||
| 154 | |||
| 155 | const out: Record<string, unknown> = {} | ||
| 156 | for (const [key, nestedValue] of Object.entries(value)) { | ||
| 157 | const cloneable = stripNonCloneable(nestedValue) | ||
| 158 | if (cloneable !== undefined) out[key] = cloneable | ||
| 159 | } | ||
| 160 | return out | ||
| 161 | } | ||
| 162 | |||
| 163 | export function getPageOrderEntries(pageMeta: Map<string, { label: string; order: number }>): [string, number][] { | ||
| 164 | return [...pageMeta.entries()].map(([key, meta]) => [key, meta.order]) | ||
| 165 | } | ||
| 166 | |||
| 167 | export const nextFrame = () => | ||
| 168 | new Promise<void>((resolve) => requestAnimationFrame(() => resolve())) | ||