Commit 9dfb2efd2c

9dfb2efd2ce2dc90448c745c9d0940dfd963c70a

parent: d1f964df31

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-02 16:13 UTC

Update Search.vue

Layout: unified · split

docs/.vitepress/theme/components/Search.vue +649 −57
@@ -37,8 +37,12 @@ import {
37 ArrowRight, 37 ArrowRight,
38 ChevronRight, 38 ChevronRight,
39 Delete, 39 Delete,
40 ExternalLink,
40 File, 41 File,
42 Globe,
41 Hash, 43 Hash,
44 LayoutList,
45 List,
42 Locate, 46 Locate,
43 LocateOff, 47 LocateOff,
44 TextAlignStart 48 TextAlignStart
@@ -136,13 +140,303 @@ const filterText = disableQueryPersistence.value
136 140
137const showDetailedList = useLocalStorage( 141const showDetailedList = useLocalStorage(
138 'vitepress:local-search-detailed-list', 142 'vitepress:local-search-detailed-list',
139 theme.value.search?.provider === 'local' && 143 false
140 theme.value.search.options?.detailedView === true
141) 144)
142 145
143const matchExact = useLocalStorage( 146// Three search modes: 'exact' | 'fuzzy' | 'url'
144 'vitepress:local-search-match-exact', 147const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>(
145 true // enabled by default 148 'vitepress:local-search-mode',
149 'exact'
150)
151
152// Cycle through modes on mobile (only active button is visible, tap it to advance)
153function cycleSearchMode() {
154 const modes = ['exact', 'fuzzy', 'url'] as const
155 const idx = modes.indexOf(searchMode.value)
156 searchMode.value = modes[(idx + 1) % modes.length]
157}
158
159// Keep matchExact and urlSearchMode as computed aliases
160const matchExact = computed(() => searchMode.value === 'exact')
161const urlSearchMode = computed(() => searchMode.value === 'url')
162
163interface PageLink {
164 href: string
165 linkText: string
166 pageId: string
167 anchor: string
168 titles: string[] // heading breadcrumb e.g. ["Manga", "Online"]
169}
170
171// allLinks is built lazily the first time URL mode is activated, then cached.
172// We store the result in a module-level variable so it survives across reactive
173// re-runs (searchIndex changes are rare; a full rebuild would remount every page).
174let allLinksCache: PageLink[] | null = null
175let allLinksBuildPromise: Promise<PageLink[]> | null = null
176
177async function buildAllLinks(index: any, vitePressData: any): Promise<PageLink[]> {
178 // Collect unique page-level doc ids (strip anchors)
179 const pageIds = new Set<string>()
180 const docIds = index._documentIds
181 if (docIds instanceof Map) {
182 for (const id of docIds.values()) pageIds.add(String(id).split('#')[0])
183 } else if (docIds && typeof docIds === 'object') {
184 for (const k of Object.keys(docIds)) pageIds.add(String((docIds as any)[k]).split('#')[0])
185 }
186
187 const collected: PageLink[] = []
188
189 for (const pageId of pageIds) {
190 try {
191 const file = pathToFile(pageId)
192 if (!file) continue
193 const mod = await import(/*@vite-ignore*/ file)
194 const comp = (mod as any).default ?? mod
195 if (!(comp?.render || comp?.setup)) continue
196
197 const app = createApp(comp)
198 app.config.warnHandler = () => {}
199 enhanceAppWithTabs(app)
200 app.provide(dataSymbol, vitePressData)
201 Object.defineProperties(app.config.globalProperties, {
202 $frontmatter: { get() { return vitePressData.frontmatter.value } },
203 $params: { get() { return vitePressData.page.value.params } }
204 })
205 const div = document.createElement('div')
206 const seenOnPage = new Set<string>()
207
208 // Collect links visible right now in the DOM
209 // heading stack: index = heading level - 1, value = heading text
210 const headingStack: string[] = []
211 const currentAnchor = { v: '' }
212
213 const scrapeLinks = () => {
214 const walker = document.createTreeWalker(div, NodeFilter.SHOW_ELEMENT)
215 let node: Element | null = div
216 while ((node = walker.nextNode() as Element | null)) {
217 const m = node.tagName.match(/^h([1-6])$/i)
218 if (m) {
219 const level = parseInt(m[1]) - 1
220 // Strip icon HTML, keep text only
221 const text = (node as HTMLElement).innerText?.trim()
222 ?? node.textContent?.trim() ?? ''
223 headingStack[level] = text
224 // Clear deeper levels
225 headingStack.length = level + 1
226 const ha = node.querySelector('a[href^="#"]')
227 if (ha) { const h = ha.getAttribute('href')!.slice(1); if (h) currentAnchor.v = h }
228 } else if (node.tagName === 'A') {
229 const href = node.getAttribute('href') ?? ''
230 if (/^https?:\/\//i.test(href)) {
231 const key = href + '\x00' + currentAnchor.v
232 if (!seenOnPage.has(key)) {
233 seenOnPage.add(key)
234 // titles = all heading levels above the link, filtering empty slots
235 const titles = headingStack.filter(Boolean)
236 collected.push({ href, linkText: node.textContent?.trim() ?? '', pageId, anchor: currentAnchor.v, titles })
237 }
238 }
239 }
240 }
241 }
242
243 try {
244 app.mount(div)
245 div.querySelectorAll('details').forEach((d) => { d.open = true })
246 div.querySelectorAll<HTMLElement>('[style*="display: none"],[style*="display:none"]')
247 .forEach((el) => { el.style.display = '' })
248
249 const raf = () => new Promise<void>(r => requestAnimationFrame(() => r()))
250 const tabGroups = div.querySelectorAll<HTMLElement>('.plugin-tabs')
251
252 if (tabGroups.length === 0) {
253 scrapeLinks()
254 } else {
255 // First pass: scrape non-tab content (anchors from headings outside tabs)
256 scrapeLinks()
257 // Then expose every tab panel
258 for (const tabGroup of Array.from(tabGroups)) {
259 const buttons = tabGroup.querySelectorAll<HTMLButtonElement>('.plugin-tabs--tab[role="tab"]')
260 for (const button of Array.from(buttons)) {
261 button.click()
262 await nextTick()
263 await raf()
264 scrapeLinks(anchor)
265 }
266 }
267 }
268 } finally {
269 try { app.unmount() } catch { /* ignore */ }
270 }
271 } catch { /* skip unrenderable pages */ }
272 }
273
274 // Sort by sidebar page order once so urlResults doesn't need to re-sort on every keypress
275 collected.sort((a, b) => {
276 const pa = pageMeta.get(a.pageId)?.order ?? Number.MAX_SAFE_INTEGER
277 const pb = pageMeta.get(b.pageId)?.order ?? Number.MAX_SAFE_INTEGER
278 return pa - pb
279 })
280 return collected
281}
282
283// Lazy ref — null until URL mode is first used
284const allLinks = shallowRef<PageLink[]>([])
285let allLinksIndexVersion: any = null // track which index version we built for
286
287async function ensureAllLinks() {
288 const index = searchIndex.value as any
289 if (!index) return
290 // Rebuild if the index changed (e.g. HMR)
291 if (allLinksCache && allLinksIndexVersion === index) {
292 allLinks.value = allLinksCache
293 return
294 }
295 if (allLinksBuildPromise) {
296 allLinks.value = await allLinksBuildPromise
297 return
298 }
299 allLinksBuildPromise = buildAllLinks(index, vitePressData)
300 const result = await allLinksBuildPromise
301 allLinksCache = result
302 allLinksIndexVersion = index
303 allLinksBuildPromise = null
304 allLinks.value = result
305}
306
307// Kick off link scraping the moment URL mode is activated (lazy, once)
308watch(urlSearchMode, (active) => { if (active) ensureAllLinks() }, { immediate: true })
309
310// If the search index changes (HMR rebuild), invalidate the link cache
311watch(searchIndex, () => {
312 allLinksCache = null
313 allLinksBuildPromise = null
314 allLinksIndexVersion = null
315 allLinks.value = []
316 if (urlSearchMode.value) ensureAllLinks()
317})
318
319interface UrlResult {
320 href: string
321 linkText: string
322 pageId: string
323 anchor: string
324 titles: string[]
325 highlighted: string
326 excerptHtml: string
327}
328
329const urlResults = computed((): UrlResult[] => {
330 if (!urlSearchMode.value || !filterText.value.trim()) return []
331 const query = filterText.value.trim().toLowerCase()
332 const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
333 const regex = new RegExp(`(${escaped})`, 'gi')
334 // allLinks is pre-sorted by page order — no sort needed here
335 return allLinks.value
336 .filter(({ href }) => href.toLowerCase().includes(query))
337 .map(({ href, linkText, pageId, anchor, titles }) => ({
338 href, linkText, pageId, anchor, titles,
339 highlighted: href.replace(regex, '<mark class="url-highlight">$1</mark>'),
340 excerptHtml: ''
341 }))
342})
343
344// URL mode page ribbon — mirrors the normal pageGroups/filteredResults logic
345const urlActivePageFilter = ref<string | null>(null)
346
347const urlPageGroups = computed(() => {
348 const map = new Map<string, { key: string; label: string; count: number }>()
349 for (const r of urlResults.value) {
350 const key = r.pageId
351 const existing = map.get(key)
352 if (existing) existing.count++
353 else map.set(key, { key, label: getPageLabel(key), count: 1 })
354 }
355 return [...map.values()].sort((a, b) => getPageOrder(a.key) - getPageOrder(b.key))
356})
357
358const filteredUrlResults = computed(() => {
359 const src = urlResultsWithExcerpts.value
360 if (!urlActivePageFilter.value) return src
361 return src.filter((r) => r.pageId === urlActivePageFilter.value)
362})
363
364// Reset URL filter when query changes or mode switches
365watch(urlResults, (r) => {
366 if (urlActivePageFilter.value && !urlPageGroups.value.some((g) => g.key === urlActivePageFilter.value)) {
367 urlActivePageFilter.value = null
368 }
369})
370
371watch(urlSearchMode, (active) => {
372 if (!active) urlActivePageFilter.value = null
373})
374
375function setUrlPageFilter(key: string | null) {
376 urlActivePageFilter.value = urlActivePageFilter.value === key ? null : key
377 selectedIndex.value = filteredUrlResults.value.length ? 1 : -1
378 nextTick(() => {
379 if (resultsEl.value) resultsEl.value.scrollTop = 0
380 scrollToSelectedResult()
381 // Sync currentTerms from the URL query so reapplyHighlights can highlight + center
382 if (filterText.value.trim()) {
383 currentTerms.value = new Set(
384 filterText.value.trim().toLowerCase().split(/\s+/).filter(Boolean)
385 )
386 }
387 reapplyHighlights()
388 })
389}
390
391// Reactive list used by the template — same as urlResults but with excerptHtml filled in
392const urlResultsWithExcerpts = shallowRef<UrlResult[]>([])
393
394watchDebounced(
395 () => [urlResults.value, showDetailedList.value, filterText.value] as const,
396 async ([results, detailed, query], _old, onCleanup) => {
397 let canceled = false
398 onCleanup(() => { canceled = true })
399
400 // Always sync the list immediately from the already-computed urlResults
401 urlResultsWithExcerpts.value = results.map(r => ({ ...r, excerptHtml: '' }))
402 if (!detailed || !results.length) return
403
404 // Build excerpts once per page (empty query = permanent cache, no re-render per keystroke)
405 const uniquePageIds = [...new Set(results.map(r => r.pageId))]
406 await Promise.all(uniquePageIds.map(pid => buildDocExcerpt(pid, '')))
407 if (canceled) return
408
409 // Fill in excerptHtml from cache keyed by pageId + ''
410 urlResultsWithExcerpts.value = results.map(r => {
411 const map = cache.get(`${r.pageId}\n`)
412 const html = map?.get(r.anchor)
413 ?? (r.anchor ? [...(map?.entries() ?? [])].find(([k]) => k.includes(r.anchor))?.[1] : undefined)
414 ?? map?.values().next().value
415 ?? ''
416 return { ...r, excerptHtml: html }
417 })
418 if (canceled) return
419
420 // Highlight query terms and center excerpts on the highlighted mark (like normal search)
421 if (query.trim()) {
422 currentTerms.value = new Set(
423 query.trim().toLowerCase().split(/\s+/).filter(Boolean)
424 )
425 }
426 await nextTick()
427 if (canceled) return
428 await new Promise<void>(resolve => {
429 mark.value?.unmark({
430 done: () => {
431 mark.value?.markRegExp(formMarkRegex(currentTerms.value), { done: () => resolve() })
432 }
433 })
434 })
435 if (canceled) return
436 await nextTick()
437 centerExcerptsUntilSettled()
438 },
439 { debounce: 80, immediate: true }
146) 440)
147 441
148const disableDetailedView = computed(() => { 442const disableDetailedView = computed(() => {
@@ -356,6 +650,10 @@ watch(pageGroups, () => {
356 nextTick(updateRibbonOverflow) 650 nextTick(updateRibbonOverflow)
357}) 651})
358 652
653watch(urlPageGroups, () => {
654 nextTick(updateRibbonOverflow)
655})
656
359useEventListener('resize', () => { 657useEventListener('resize', () => {
360 updateRibbonOverflow() 658 updateRibbonOverflow()
361}) 659})
@@ -443,8 +741,8 @@ function buildDocExcerpt(
443} 741}
444 742
445watchDebounced( 743watchDebounced(
446 () => [searchIndex.value, filterText.value, showDetailedList.value, matchExact.value] as const, 744 () => [searchIndex.value, filterText.value, showDetailedList.value, searchMode.value] as const,
447 async ([index, filterTextValue, showDetailedListValue, matchExactValue], old, onCleanup) => { 745 async ([index, filterTextValue, showDetailedListValue, mode], old, onCleanup) => {
448 if (old?.[0] !== index) { 746 if (old?.[0] !== index) {
449 // in case of hmr 747 // in case of hmr
450 cache.clear() 748 cache.clear()
@@ -457,11 +755,18 @@ watchDebounced(
457 755
458 if (!index) return 756 if (!index) return
459 757
758 // In URL search mode, skip normal text search
759 if (mode === 'url') {
760 results.value = []
761 enableNoResults.value = true
762 return
763 }
764
460 // Dynamic search options based on matchExact toggle 765 // Dynamic search options based on matchExact toggle
461 const dynamicSearchOptions = { 766 const dynamicSearchOptions = {
462 fuzzy: matchExactValue ? false : (0.3 as number | false), 767 fuzzy: mode === 'fuzzy' ? (0.3 as number | false) : false,
463 prefix: matchExactValue ? false : (term: string) => term.length > 3, 768 prefix: mode === 'fuzzy' ? (term: string) => term.length > 3 : false,
464 maxFuzzy: matchExactValue ? 0 : 1, 769 maxFuzzy: mode === 'fuzzy' ? 1 : 0,
465 boost: { title: 10, titles: 4, text: 1 }, 770 boost: { title: 10, titles: 4, text: 1 },
466 } 771 }
467 772
@@ -722,9 +1027,23 @@ function onSearchBarClick(event: PointerEvent) {
722const selectedIndex = ref(-1) 1027const selectedIndex = ref(-1)
723const disableMouseOver = ref(true) 1028const disableMouseOver = ref(true)
724 1029
1030// Active result list length (URL mode vs normal mode)
1031const activeResultsLength = computed(() =>
1032 urlSearchMode.value ? filteredUrlResults.value.length : filteredResults.value.length
1033)
1034
725watch(filteredResults, (r) => { 1035watch(filteredResults, (r) => {
726 selectedIndex.value = r.length ? 0 : -1 1036 if (!urlSearchMode.value) {
727 scrollToSelectedResult() 1037 selectedIndex.value = r.length ? 0 : -1
1038 scrollToSelectedResult()
1039 }
1040})
1041
1042watch(filteredUrlResults, (r) => {
1043 if (urlSearchMode.value) {
1044 selectedIndex.value = r.length ? 0 : -1
1045 scrollToSelectedResult()
1046 }
728}) 1047})
729 1048
730function scrollToSelectedResult() { 1049function scrollToSelectedResult() {
@@ -738,7 +1057,7 @@ onKeyStroke('ArrowUp', (event) => {
738 event.preventDefault() 1057 event.preventDefault()
739 selectedIndex.value-- 1058 selectedIndex.value--
740 if (selectedIndex.value < 0) { 1059 if (selectedIndex.value < 0) {
741 selectedIndex.value = filteredResults.value.length - 1 1060 selectedIndex.value = activeResultsLength.value - 1
742 } 1061 }
743 disableMouseOver.value = true 1062 disableMouseOver.value = true
744 scrollToSelectedResult() 1063 scrollToSelectedResult()
@@ -747,7 +1066,7 @@ onKeyStroke('ArrowUp', (event) => {
747onKeyStroke('ArrowDown', (event) => { 1066onKeyStroke('ArrowDown', (event) => {
748 event.preventDefault() 1067 event.preventDefault()
749 selectedIndex.value++ 1068 selectedIndex.value++
750 if (selectedIndex.value >= filteredResults.value.length + 1) { 1069 if (selectedIndex.value >= activeResultsLength.value + 1) {
751 selectedIndex.value = 0 1070 selectedIndex.value = 0
752 } 1071 }
753 disableMouseOver.value = true 1072 disableMouseOver.value = true
@@ -772,6 +1091,18 @@ onKeyStroke('Enter', (e) => {
772 return 1091 return
773 } 1092 }
774 1093
1094 // URL search mode: navigate to the page containing the link (like normal search)
1095 if (urlSearchMode.value) {
1096 const selectedUrl = filteredUrlResults.value[index]
1097 if (selectedUrl) {
1098 window.dispatchEvent(new CustomEvent('search-nav', { detail: { query: filterText.value } }))
1099 const dest = selectedUrl.anchor ? selectedUrl.pageId + '#' + selectedUrl.anchor : selectedUrl.pageId
1100 router.go(dest)
1101 showSearch.value = false
1102 }
1103 return
1104 }
1105
775 const selectedPackage = filteredResults.value[index] 1106 const selectedPackage = filteredResults.value[index]
776 if (e.target instanceof HTMLInputElement && !selectedPackage) { 1107 if (e.target instanceof HTMLInputElement && !selectedPackage) {
777 e.preventDefault() 1108 e.preventDefault()
@@ -950,27 +1281,55 @@ function onMouseMove(e: MouseEvent) {
950 type="search" 1281 type="search"
951 /> 1282 />
952 <div class="search-actions"> 1283 <div class="search-actions">
953 <button 1284 <div v-if="!disableDetailedView" class="view-group toolbar-group">
954 v-if="!disableDetailedView" 1285 <button
955 class="toggle-layout-button" 1286 type="button"
956 type="button" 1287 class="mode-btn"
957 :class="{ 'detailed-list': showDetailedList }" 1288 :class="{ 'mode-active': showDetailedList }"
958 :title="translate('modal.displayDetails')" 1289 title="Detail view (Consumes more RAM)"
959 @click="selectedIndex > -1 && 1290 @click="showDetailedList ? showDetailedList = false : showDetailedList = true"
960 (showDetailedList = !showDetailedList)" 1291 >
961 > 1292 <LayoutList :size="18" stroke-width="1.25" />
962 <TextAlignStart :size="19" stroke-width="1.25" /> 1293 </button>
963 </button> 1294 <button
964 <button 1295 type="button"
965 class="exact-match-button" 1296 class="mode-btn"
966 type="button" 1297 :class="{ 'mode-active': !showDetailedList }"
967 :class="{ 'exact-match-active': matchExact }" 1298 title="List view (Consumes less RAM)"
968 :title="translate('modal.exactMatchTitle')" 1299 @click="!showDetailedList ? showDetailedList = true : showDetailedList = false"
969 @click="matchExact = !matchExact" 1300 >
970 > 1301 <List :size="18" stroke-width="1.25" />
971 <Locate v-if="matchExact" :size="19" stroke-width="1.25" /> 1302 </button>
972 <LocateOff v-else :size="19" stroke-width="1.25" /> 1303 </div>
973 </button> 1304 <div class="search-mode-group toolbar-group">
1305 <button
1306 type="button"
1307 class="mode-btn"
1308 :class="{ 'mode-active': searchMode === 'exact' }"
1309 title="Exact search"
1310 @click="searchMode === 'exact' ? cycleSearchMode() : searchMode = 'exact'"
1311 >
1312 <Locate :size="18" stroke-width="1.25" />
1313 </button>
1314 <button
1315 type="button"
1316 class="mode-btn"
1317 :class="{ 'mode-active': searchMode === 'fuzzy' }"
1318 title="Fuzzy search"
1319 @click="searchMode === 'fuzzy' ? cycleSearchMode() : searchMode = 'fuzzy'"
1320 >
1321 <LocateOff :size="18" stroke-width="1.25" />
1322 </button>
1323 <button
1324 type="button"
1325 class="mode-btn"
1326 :class="{ 'mode-active': searchMode === 'url' }"
1327 title="URL search"
1328 @click="searchMode === 'url' ? cycleSearchMode() : searchMode = 'url'"
1329 >
1330 <Globe :size="18" stroke-width="1.25" />
1331 </button>
1332 </div>
974 <button 1333 <button
975 class="clear-button" 1334 class="clear-button"
976 type="reset" 1335 type="reset"
@@ -984,7 +1343,7 @@ function onMouseMove(e: MouseEvent) {
984 </form> 1343 </form>
985 1344
986 <div 1345 <div
987 v-if="pageGroups.length > 1" 1346 v-if="urlSearchMode ? urlPageGroups.length > 1 : pageGroups.length > 1"
988 class="page-ribbon" 1347 class="page-ribbon"
989 > 1348 >
990 <button 1349 <button
@@ -1001,26 +1360,52 @@ function onMouseMove(e: MouseEvent) {
1001 class="page-ribbon-track" 1360 class="page-ribbon-track"
1002 @scroll="updateRibbonOverflow" 1361 @scroll="updateRibbonOverflow"
1003 > 1362 >
1004 <button 1363 <!-- URL mode tabs -->
1005 type="button" 1364 <template v-if="urlSearchMode">
1006 class="page-pill" 1365 <button
1007 :class="{ active: activePageFilter === null }" 1366 type="button"
1008 @click="setPageFilter(null)" 1367 class="page-pill"
1009 > 1368 :class="{ active: urlActivePageFilter === null }"
1010 All 1369 @click="setUrlPageFilter(null)"
1011 <span class="page-pill-count">{{ results.length }}</span> 1370 >
1012 </button> 1371 All
1013 <button 1372 <span class="page-pill-count">{{ urlResults.length }}</span>
1014 v-for="group in pageGroups" 1373 </button>
1015 :key="group.key" 1374 <button
1016 type="button" 1375 v-for="group in urlPageGroups"
1017 class="page-pill" 1376 :key="group.key"
1018 :class="{ active: activePageFilter === group.key }" 1377 type="button"
1019 @click="setPageFilter(group.key)" 1378 class="page-pill"
1020 > 1379 :class="{ active: urlActivePageFilter === group.key }"
1021 <span class="page-pill-label">{{ group.label }}</span> 1380 @click="setUrlPageFilter(group.key)"
1022 <span class="page-pill-count">{{ group.count }}</span> 1381 >
1023 </button> 1382 <span class="page-pill-label">{{ group.label }}</span>
1383 <span class="page-pill-count">{{ group.count }}</span>
1384 </button>
1385 </template>
1386 <!-- Normal mode tabs -->
1387 <template v-else>
1388 <button
1389 type="button"
1390 class="page-pill"
1391 :class="{ active: activePageFilter === null }"
1392 @click="setPageFilter(null)"
1393 >
1394 All
1395 <span class="page-pill-count">{{ results.length }}</span>
1396 </button>
1397 <button
1398 v-for="group in pageGroups"
1399 :key="group.key"
1400 type="button"
1401 class="page-pill"
1402 :class="{ active: activePageFilter === group.key }"
1403 @click="setPageFilter(group.key)"
1404 >
1405 <span class="page-pill-label">{{ group.label }}</span>
1406 <span class="page-pill-count">{{ group.count }}</span>
1407 </button>
1408 </template>
1024 </div> 1409 </div>
1025 <button 1410 <button
1026 v-if="ribbonCanScrollRight" 1411 v-if="ribbonCanScrollRight"
@@ -1041,6 +1426,84 @@ function onMouseMove(e: MouseEvent) {
1041 class="results" 1426 class="results"
1042 @mousemove="onMouseMove" 1427 @mousemove="onMouseMove"
1043 > 1428 >
1429 <!-- URL search mode results -->
1430 <template v-if="urlSearchMode">
1431 <div
1432 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1433 v-if="!filterText || (filterText && !urlResults.length)"
1434 >
1435 <img
1436 class="h-40 object-contain object-center -translate-x-2"
1437 src="/asset/smolame.png"
1438 alt="Smol ame"
1439 />
1440 <h1 v-if="filterText && !urlResults.length">
1441 Couldn't find anything, try again?
1442 </h1>
1443 <h1 v-else>Looking for something?</h1>
1444 </div>
1445 <li
1446 v-for="(item, index) in filteredUrlResults"
1447 :key="item.href + item.pageId"
1448 class="result-layout"
1449 :id="'localsearch-item-' + (index + 1)"
1450 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1451 role="option"
1452 >
1453 <a
1454 :href="item.anchor ? item.pageId + '#' + item.anchor : item.pageId"
1455 class="result url-result"
1456 :class="{ selected: selectedIndex === index + 1 }"
1457 :aria-label="item.linkText || item.href"
1458 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1459 @focusin="selectedIndex = index + 1"
1460 @click="onResultClick"
1461 :data-index="index + 1"
1462 >
1463 <div class="url-result-content">
1464 <div>
1465 <div class="titles">
1466 <Hash v-if="item.titles.length > 0" stroke-width="1.25" :size="18" />
1467 <File v-else stroke-width="1.25" :size="18" />
1468 <span
1469 v-for="(t, ti) in item.titles"
1470 :key="ti"
1471 class="title"
1472 >
1473 <span class="text" v-html="t" />
1474 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
1475 </span>
1476 <span class="title main">
1477 <span class="text">{{ item.linkText || item.href }}</span>
1478 </span>
1479 </div>
1480 <div class="excerpt-wrapper" v-if="showDetailedList">
1481 <div class="excerpt" inert>
1482 <div v-if="item.excerptHtml" class="vp-doc" v-html="item.excerptHtml" />
1483 <div v-else class="url-excerpt-href" v-html="item.highlighted" />
1484 </div>
1485 <div class="excerpt-gradient-bottom" />
1486 <div class="excerpt-gradient-top" />
1487 </div>
1488 </div>
1489 <a
1490 :href="item.href"
1491 target="_blank"
1492 rel="noopener noreferrer"
1493 class="url-open-btn"
1494 :class="{ 'url-open-btn-selected': selectedIndex === index + 1 }"
1495 title="Open link"
1496 @click.stop
1497 >
1498 <ExternalLink :size="14" stroke-width="1.5" />
1499 </a>
1500 </div>
1501 </a>
1502 </li>
1503 </template>
1504
1505 <!-- Normal search results -->
1506 <template v-else>
1044 <div 1507 <div
1045 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90" 1508 class="flex flex-col justify-center items-center h-47.5 gap-2 font-medium text-sm text-gray-500 dark:text-gray-300 m-auto md:mt-10 md:mb-6 opacity-90"
1046 v-if="!filterText || (filterText && !filteredResults.length)" 1509 v-if="!filterText || (filterText && !filteredResults.length)"
@@ -1117,6 +1580,7 @@ function onMouseMove(e: MouseEvent) {
1117 </div> 1580 </div>
1118 </a> 1581 </a>
1119 </li> 1582 </li>
1583 </template>
1120 </ul> 1584 </ul>
1121 1585
1122 <div class="search-keyboard-shortcuts"> 1586 <div class="search-keyboard-shortcuts">
@@ -1332,7 +1796,7 @@ function onMouseMove(e: MouseEvent) {
1332 1796
1333@media (max-width: 767px) { 1797@media (max-width: 767px) {
1334 .page-ribbon { 1798 .page-ribbon {
1335 padding: 14px 0 4px; 1799 padding: 14px 12px 4px;
1336 } 1800 }
1337 1801
1338 .page-pill { 1802 .page-pill {
@@ -1591,4 +2055,132 @@ svg {
1591 background-color: rgba(var(--vp-c-brand-1), 0.1); 2055 background-color: rgba(var(--vp-c-brand-1), 0.1);
1592 border-radius: 4px; 2056 border-radius: 4px;
1593} 2057}
2058
2059.toolbar-group + .toolbar-group {
2060 margin-left: 6px;
2061}
2062
2063.search-mode-group,
2064.view-group {
2065 display: flex;
2066 align-items: center;
2067 border: 1px solid var(--vp-c-divider);
2068 border-radius: 5px;
2069 overflow: hidden;
2070}
2071
2072/* Mobile: hide inactive buttons in both groups — tap the active one to cycle */
2073@media (max-width: 767px) {
2074 .search-mode-group .mode-btn:not(.mode-active),
2075 .view-group .mode-btn:not(.mode-active) {
2076 display: none;
2077 }
2078
2079 .search-mode-group,
2080 .view-group {
2081 border-radius: 5px;
2082 }
2083
2084 /* Tapping the sole visible button cycles to the next option */
2085 .search-mode-group .mode-btn.mode-active,
2086 .view-group .mode-btn.mode-active {
2087 border-radius: 4px;
2088 }
2089}
2090
2091.mode-btn {
2092 display: flex;
2093 align-items: center;
2094 justify-content: center;
2095 padding: 5px 7px;
2096 color: var(--vp-c-text-2);
2097 background: transparent;
2098 border: none;
2099 cursor: pointer;
2100 transition: color 0.15s, background-color 0.15s;
2101 border-radius: 0;
2102}
2103
2104.mode-btn + .mode-btn {
2105 border-left: 1px solid var(--vp-c-divider);
2106}
2107
2108.mode-btn:hover {
2109 color: var(--vp-c-text-1);
2110 background: var(--vp-c-default-soft);
2111}
2112
2113.mode-btn.mode-active {
2114 color: var(--vp-c-brand-1);
2115 background: rgba(60, 120, 210, 0.10);
2116}
2117
2118.url-result-content {
2119 display: flex;
2120 align-items: center;
2121 width: 100%;
2122 gap: 8px;
2123}
2124
2125.url-result-content > div:first-child {
2126 flex: 1;
2127 min-width: 0;
2128}
2129
2130.url-open-btn {
2131 flex: none;
2132 display: flex;
2133 align-items: center;
2134 justify-content: center;
2135 width: 28px;
2136 height: 28px;
2137 border-radius: 6px;
2138 color: var(--vp-c-text-3);
2139 opacity: 0;
2140 transition: opacity 0.15s, color 0.15s, background 0.15s;
2141 margin-right: 4px;
2142}
2143
2144.result:hover .url-open-btn,
2145.result.selected .url-open-btn {
2146 opacity: 1;
2147}
2148
2149@media (max-width: 767px) {
2150 .url-open-btn {
2151 opacity: 1;
2152 }
2153}
2154
2155.url-open-btn:hover {
2156 color: var(--vp-c-brand-1);
2157 background: var(--vp-c-default-soft);
2158}
2159
2160.url-open-btn-selected {
2161 color: var(--vp-c-brand-1) !important;
2162}
2163
2164.url-excerpt {
2165 height: auto !important;
2166 max-height: none !important;
2167 overflow: visible !important;
2168}
2169
2170.url-excerpt-href {
2171 font-size: 0.78rem !important;
2172 font-family: var(--vp-font-family-mono, monospace);
2173 color: var(--vp-c-text-2);
2174 word-break: break-all;
2175 line-height: 1.5;
2176 padding: 2px 0;
2177}
2178
2179:deep(.url-highlight) {
2180 background-color: var(--vp-local-search-highlight-bg);
2181 color: var(--vp-local-search-highlight-text);
2182 border-radius: 2px;
2183 padding: 0 2px;
2184 font-style: normal;
2185}
1594</style>\ No newline at end of file 2186</style>\ No newline at end of file