Commit 6c128353a9

6c128353a9ab22a86a955527b7758071928d55e2

parent: 957cbded40

Unsigned

taskylizard <75871323+taskylizard@users.noreply.github.com> · 2026-06-04 12:56 UTC

fix search stuff

Layout: unified · split

docs/.vitepress/configs/markdown/emoji.ts +52 −33
@@ -11,22 +11,22 @@ import { iconTooltips } from './tooltip'
1111
1212// Icons that need to be used should be imported here
1313import { icons as akar } from '@iconify-json/akar-icons'
14import { icons as bi } from '@iconify-json/bi'
1415import { icons as ic } from '@iconify-json/ic'
1516import { icons as iconoir } from '@iconify-json/iconoir'
1617import { icons as logos } from '@iconify-json/logos'
1718import { icons as lucide } from '@iconify-json/lucide'
19import { icons as map } from '@iconify-json/map'
1820import { icons as materials } from '@iconify-json/material-symbols'
1921import { icons as mdi } from '@iconify-json/mdi'
2022import { icons as mingcute } from '@iconify-json/mingcute'
2123import { icons as octicon } from '@iconify-json/octicon'
2224import { icons as simple } from '@iconify-json/simple-icons'
23import { icons as twemoji } from '@iconify-json/twemoji'
24import { icons as uil } from '@iconify-json/uil'
25import { icons as map } from '@iconify-json/map'
26import { icons as bi } from '@iconify-json/bi'
2725import { icons as sl } from '@iconify-json/streamline-logos'
28import { icons as su } from '@iconify-json/streamline-ultimate'
2926import { icons as ss } from '@iconify-json/streamline-sharp'
27import { icons as su } from '@iconify-json/streamline-ultimate'
28import { icons as twemoji } from '@iconify-json/twemoji'
29import { icons as uil } from '@iconify-json/uil'
3030
3131// 1. Install emoji pack with `pnpm add -D @iconify-json/<icon>`
3232// 2. Import them like I did above
@@ -56,7 +56,6 @@ const emojis: { pack: IconifyJSON; prefix?: string }[] = [
5656// Add aliases here: [icon, label?]
5757// Label is optional — omit for icons that don't need a tooltip.
5858const aliasDefs: Record<string, [string, string?]> = {
59
6059 // Operating System
6160 and: ['simple-icons-android', 'Android'],
6261 ios: ['simple-icons-apple', 'iOS / iPadOS'],
@@ -84,10 +83,13 @@ const aliasDefs: Record<string, [string, string?]> = {
8483 cs: ['mdi-package-variant-closed-remove', 'Closed Source'],
8584
8685 // Network Type
87 ddl: ['material-symbols-cloud-download-outline-rounded', 'Direct / HTTP(S) Download'],
86 ddl: [
87 'material-symbols-cloud-download-outline-rounded',
88 'Direct / HTTP(S) Download'
89 ],
8890 mag: ['lucide-magnet', 'Torrent / Magnet Download'],
8991 usnt: ['material-symbols-newspaper-rounded', 'Usenet / NZB download'],
90
92
9193 // Device
9294 erdr: ['material-symbols-chrome-reader-mode-outline-rounded', 'E-reader'],
9395
@@ -104,12 +106,15 @@ const aliasDefs: Record<string, [string, string?]> = {
104106 sup: ['mingcute-server-fill', 'Self-uploaded (Own storage or video host)'],
105107 scrpr: ['mingcute-shovel-fill', 'Scraper (Pulling from other host sites)'],
106108 tv: ['material-symbols-tv-gen-outline-rounded', 'Native TV support'],
107 cast: ['material-symbols-cast-outline','TV casting support'],
108 dlna: ['mdi-dlna','DLNA support'],
109 cast: ['material-symbols-cast-outline', 'TV casting support'],
110 dlna: ['mdi-dlna', 'DLNA support'],
109111
110112 up: ['material-symbols-upload', 'User / scanlator upload'],
111113 ms: ['material-symbols-file-copy-rounded', 'Multiple chapter sources'],
112 ps: ['material-symbols-file-copy-outline-rounded', 'Unlabeled / Poorly labeled / Partial multi-source'],
114 ps: [
115 'material-symbols-file-copy-outline-rounded',
116 'Unlabeled / Poorly labeled / Partial multi-source'
117 ],
113118 ss: ['material-symbols-file-copy-off-rounded', 'Single source'],
114119 sp: ['lucide-file', 'Single Page Mode'],
115120 dp: ['lucide-book-open', 'Dual Page Mode'],
@@ -120,7 +125,7 @@ const aliasDefs: Record<string, [string, string?]> = {
120125 mal: ['simple-icons-myanimelist', 'MyAnimeList'],
121126 al: ['simple-icons-anilist', 'AniList'],
122127 k: ['simple-icons-kitsu', 'Kitsu'],
123 shiki: ['simple-icons-shikimori','Shikimori'],
128 shiki: ['simple-icons-shikimori', 'Shikimori'],
124129 simkl: ['simple-icons-simkl', 'Simkl'],
125130 tmdb: ['simple-icons-themoviedatabase', 'TMDB'],
126131 lstfm: ['simple-icons-lastdotfm', 'Lastfm'],
@@ -137,8 +142,8 @@ const aliasDefs: Record<string, [string, string?]> = {
137142 steam: ['simple-icons-steam', 'Steam'],
138143 gog: ['mdi-gog', 'GOG'],
139144 iarch: ['simple-icons-internetarchive', 'Internet Archive'],
140 apple: ['simple-icons-apple','Apple product'],
141 wikip: ['simple-icons-wikipedia','WikiPedia'],
145 apple: ['simple-icons-apple', 'Apple product'],
146 wikip: ['simple-icons-wikipedia', 'WikiPedia'],
142147
143148 // Price
144149 paid: ['streamline-ultimate-cash-payment-bills-bold', "Good ol' money"],
@@ -184,14 +189,12 @@ const aliasDefs: Record<string, [string, string?]> = {
184189 cvie: ['twemoji-flag-vietnam', 'Vietnam'],
185190 cbr: ['twemoji-flag-brazil', 'Brazil'],
186191
187
188192 // Storage
189193 sgd: ['simple-icons-googledrive', 'Google Drive'],
190194 sm: ['simple-icons-mega', 'MEGA'],
191195 smf: ['simple-icons-mediafire', 'MediaFire'],
192196 host: ['mdi-snail', 'Rate-limited / Paywalled Host'],
193197
194
195198 // General
196199 s: ['twemoji-glowing-star', 'Favorite'],
197200 e: ['mdi-puzzle', 'Extension'],
@@ -204,9 +207,9 @@ const aliasDefs: Record<string, [string, string?]> = {
204207 prx: ['material-symbols-directions-alt', 'Proxies / Mirrors'],
205208 tf: ['mdi-airplane', 'Testflight'],
206209 more: ['mdi-arrow-right-bold', 'Related'],
207 prev: ['mdi-arrow-right-thick','Related to Prior URL'],
210 prev: ['mdi-arrow-right-thick', 'Related to Prior URL'],
208211 help: ['material-symbols-help', 'Help / Docs'],
209 ded: ['twemoji-headstone','Inactive / Retired'],
212 ded: ['twemoji-headstone', 'Inactive / Retired'],
210213 strm: ['material-symbols-play-circle-outline', 'Stream'],
211214 lcl: ['iconoir-floppy-disk', 'Local file'],
212215 batch: ['material-symbols-package-2-outline', 'Batch Download'],
@@ -250,29 +253,45 @@ for (const [alias, fullName] of Object.entries(aliases)) {
250253
251254export { aliases, defs }
252255
253export function emojiRender(md: MarkdownRenderer) {
254 md.renderer.rules.emoji = (tokens, idx) => {
255 const markup = tokens[idx].markup
256 const label = aliasLabels[markup] || iconTooltips[markup]
256export function renderEmojiMarkup(markup: string) {
257 const label = aliasLabels[markup] || iconTooltips[markup]
257258
258 const tip = label?.replace(/"/g, '&quot;')
259 const wrap = (cls: string) => tip
259 const tip = label?.replace(/"/g, '&quot;')
260 const wrap = (cls: string) =>
261 tip
260262 ? `<span class="icon-tip" data-tip="${tip}" tabindex="-1"><span class="${cls}"></span></span>`
261263 : `<span class="${cls}"></span>`
262264
263 // Check for custom icon aliases first
264 if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
265 // Check for custom icon aliases first
266 if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
267
268 // Check for aliases
269 if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
270
271 // Check for prefixed icons
272 for (const emoji of emojis) {
273 if (emoji.prefix && markup.startsWith(emoji.prefix)) {
274 return wrap(`i-${markup}`)
275 }
276 }
265277
266 // Check for aliases
267 if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
278 // Default to twemoji
279 return wrap(`i-twemoji-${markup}`)
280}
268281
269 // Check for prefixed icons
270 for (const emoji of emojis) {
271 if (markup.startsWith(emoji.prefix!)) return wrap(`i-${markup}`)
282export function renderEmojiShortcodes(value: string) {
283 return value.replace(/:([A-Za-z0-9_+-]+):/g, (match, markup) => {
284 if (defs[markup] === undefined || defs[markup] === 'INVALID_ALIAS') {
285 return match
272286 }
287 return renderEmojiMarkup(markup)
288 })
289}
273290
274 // Default to twemoji
275 return wrap(`i-twemoji-${markup}`)
291export function emojiRender(md: MarkdownRenderer) {
292 md.renderer.rules.emoji = (tokens, idx) => {
293 const markup = tokens[idx].markup
294 return renderEmojiMarkup(markup)
276295 }
277296}
278297
docs/.vitepress/plugins/urlSearchPlugin.ts +87 −23
@@ -1,5 +1,6 @@
11import { writeFileSync } from 'node:fs'
22import { join } from 'node:path'
3import { renderEmojiShortcodes } from '../configs/markdown/emoji'
34
45export interface PageLink {
56 href: string
@@ -13,28 +14,88 @@ function extractLinksFromMarkdown(src: string, pageId: string): PageLink[] {
1314 const results: PageLink[] = []
1415 const seen = new Set<string>()
1516 const headingStack: string[] = []
17 const slugCounts = new Map<string, number>()
18 const collapsibleStack: {
19 anchor: string
20 headings: string[]
21 }[] = []
1622 let currentAnchor = ''
1723
1824 // Strip frontmatter
1925 const body = src.startsWith('---')
2026 ? src.replace(/^---[\s\S]*?---\n?/, '')
2127 : src
28 const lines = body.split('\n')
29
30 const slugify = (value: string) =>
31 value
32 .replace(/\{[^}]*\}\s*$/, '')
33 .replace(/<[^>]*>/g, '')
34 .replace(/`([^`]+)`/g, '$1')
35 .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
36 .replace(/[*_~]/g, '')
37 .trim()
38 .toLowerCase()
39 .replace(/[^\w\s-]/g, '')
40 .replace(/\s+/g, '-')
41 .replace(/-+/g, '-')
42 .replace(/^-|-$/g, '')
43
44 const getAnchor = (text: string) => {
45 const slug = slugify(text)
46 const count = slugCounts.get(slug) ?? 0
47 slugCounts.set(slug, count + 1)
48 return count === 0 ? slug : `${slug}-${count}`
49 }
50
51 const setHeading = (level: number, text: string) => {
52 headingStack[level] = text
53 headingStack.length = level + 1
54 currentAnchor = getAnchor(text)
55 }
56
57 for (let i = 0; i < lines.length; i++) {
58 const line = lines[i]
59
60 const collapsibleMatch = line.match(
61 /^\s*<Collapsible\b(?=[^>]*\btitle=(['"])(.*?)\1)[^>]*>\s*$/i
62 )
63 if (collapsibleMatch) {
64 collapsibleStack.push({
65 anchor: currentAnchor,
66 headings: [...headingStack]
67 })
68
69 let nextLine = i + 1
70 while (nextLine < lines.length && lines[nextLine].trim() === '') {
71 nextLine++
72 }
73
74 // The markdown renderer injects a searchable H3 for collapsibles that
75 // don't already start with a heading. Mirror that anchor so URL search
76 // can deep-link into and auto-open those collapsibles.
77 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) {
78 setHeading(2, collapsibleMatch[2].trim())
79 }
80 continue
81 }
82
83 if (/^\s*<\/Collapsible>\s*$/i.test(line)) {
84 const previous = collapsibleStack.pop()
85 if (previous) {
86 currentAnchor = previous.anchor
87 headingStack.length = 0
88 headingStack.push(...previous.headings)
89 }
90 continue
91 }
2292
23 for (const line of body.split('\n')) {
2493 // Heading: ## Title or === Title (setext-style ignored, ATX only)
2594 const headingMatch = line.match(/^(#{1,6})\s+(.+)/)
2695 if (headingMatch) {
2796 const level = headingMatch[1].length - 1
2897 const text = headingMatch[2].trim()
29 headingStack[level] = text
30 headingStack.length = level + 1
31 // Derive anchor the same way VitePress does: lowercase, spaces→hyphens, strip non-word
32 currentAnchor = text
33 .toLowerCase()
34 .replace(/[^\w\s-]/g, '')
35 .replace(/\s+/g, '-')
36 .replace(/-+/g, '-')
37 .replace(/^-|-$/g, '')
98 setHeading(level, text)
3899 continue
39100 }
40101
@@ -42,7 +103,7 @@ function extractLinksFromMarkdown(src: string, pageId: string): PageLink[] {
42103 const linkRE = /\[([^\]]*)\]\((https?:\/\/[^)]+)\)/g
43104 let m: RegExpExecArray | null
44105 while ((m = linkRE.exec(line)) !== null) {
45 const linkText = m[1].trim()
106 const linkText = renderEmojiShortcodes(m[1].trim())
46107 const href = m[2].trim()
47108 const key = href + '\x00' + currentAnchor
48109 if (seen.has(key)) continue
@@ -100,17 +161,20 @@ export function urlSearchDevPlugin() {
100161 return {
101162 name: 'url-search-dev',
102163 configureServer(server: any) {
103 server.middlewares.use('/url-search-index.json', (_req: any, res: any) => {
104 const seen = new Set<string>()
105 const deduped = collected.filter((l) => {
106 const key = l.href + '\x00' + l.pageId + '\x00' + l.anchor
107 if (seen.has(key)) return false
108 seen.add(key)
109 return true
110 })
111 res.setHeader('Content-Type', 'application/json')
112 res.end(JSON.stringify(deduped))
113 })
164 server.middlewares.use(
165 '/url-search-index.json',
166 (_req: any, res: any) => {
167 const seen = new Set<string>()
168 const deduped = collected.filter((l) => {
169 const key = l.href + '\x00' + l.pageId + '\x00' + l.anchor
170 if (seen.has(key)) return false
171 seen.add(key)
172 return true
173 })
174 res.setHeader('Content-Type', 'application/json')
175 res.end(JSON.stringify(deduped))
176 }
177 )
114178 }
115179 }
116}
\ No newline at end of file
180}
docs/.vitepress/theme/components/Search.vue +900 −457
@@ -1,6 +1,6 @@
11<script lang="ts" setup>
22import MiniSearch, { type SearchResult } from 'minisearch'
3import { type DefaultTheme, dataSymbol, inBrowser, useRouter } from 'vitepress'
3import { dataSymbol, type DefaultTheme, inBrowser, useRouter } from 'vitepress'
44import {
55 computed,
66 createApp,
@@ -26,9 +26,11 @@ import {
2626 useLocalStorage,
2727 useScrollLock,
2828 useSessionStorage,
29 useStorage,
2930 watchDebounced
3031} from '@vueuse/core'
3132import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
33import { AnimatePresence, motion } from 'motion-v'
3234
3335// @ts-ignore
3436import localSearchIndex from '@localSearchIndex'
@@ -37,23 +39,22 @@ import {
3739 ArrowRight,
3840 ChevronRight,
3941 Delete,
40 ExternalLink,
4142 File,
4243 Globe,
4344 Hash,
44 LayoutList,
4545 List,
46 Locate,
4746 LocateOff,
47 Regex,
4848 TextAlignStart
4949} from 'lucide-vue-next'
5050import Mark from 'mark.js/dist/mark.es6.js'
5151import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
52import { LRUCache } from '../composables/search/lru-cache'
52import { sidebar } from '../../configs/constants'
5353import type { PageLink } from '../../plugins/urlSearchPlugin'
54import { LRUCache } from '../composables/search/lru-cache'
5455import { createSearchTranslate } from '../composables/search/translation'
5556import { useData } from '../composables/search/use-data'
56import { sidebar } from '../../configs/constants'
57import { LowEndDeviceModeStorageKey } from '../constants'
5758
5859export interface FooterTranslations {
5960 selectText?: string
@@ -139,6 +140,117 @@ const filterText = disableQueryPersistence.value
139140 ? ref('')
140141 : useSessionStorage('vitepress:local-search-filter', '')
141142
143const lowEndDeviceMode = useStorage(LowEndDeviceModeStorageKey, 'off')
144const searchAnimationsEnabled = computed(() => lowEndDeviceMode.value !== 'on')
145const showKeyboardShortcuts = computed(() => !filterText.value)
146
147const SearchMotionDiv = motion.div
148const SearchMotionForm = motion.form
149const SearchMotionLi = motion.li
150const searchMotionDiv = computed(() =>
151 searchAnimationsEnabled.value ? SearchMotionDiv : 'div'
152)
153const searchMotionForm = computed(() =>
154 searchAnimationsEnabled.value ? SearchMotionForm : 'form'
155)
156const searchMotionLi = computed(() =>
157 searchAnimationsEnabled.value ? SearchMotionLi : 'li'
158)
159const searchMotionEase = [0.16, 1, 0.3, 1]
160
161const backdropMotion = computed(() =>
162 searchAnimationsEnabled.value
163 ? {
164 initial: { opacity: 0 },
165 animate: { opacity: 1 },
166 exit: { opacity: 0 },
167 transition: { duration: 0.55, ease: searchMotionEase }
168 }
169 : {}
170)
171
172const shellMotion = computed(() =>
173 searchAnimationsEnabled.value
174 ? {
175 layout: 'size',
176 initial: { opacity: 0, scale: 0.9375 },
177 animate: { opacity: 1, scale: 1 },
178 exit: { opacity: 0, scale: 0.9375 },
179 transition: { duration: 0.55, ease: searchMotionEase }
180 }
181 : {}
182)
183
184const formMotion = computed(() =>
185 searchAnimationsEnabled.value ? { layout: 'position' } : {}
186)
187
188const ribbonMotion = computed(() =>
189 searchAnimationsEnabled.value
190 ? {
191 layout: 'position',
192 initial: { opacity: 0, height: 0 },
193 animate: { opacity: 1, height: 'auto' },
194 exit: { opacity: 0, height: 0 },
195 transition: { duration: 0.4, ease: searchMotionEase }
196 }
197 : {}
198)
199
200const emptyStateMotion = computed(() =>
201 searchAnimationsEnabled.value
202 ? {
203 initial: { opacity: 0 },
204 animate: {
205 opacity: 1,
206 transition: { delay: 0.1 }
207 },
208 exit: {
209 opacity: 0,
210 height: 0,
211 transition: { duration: 0.2 }
212 },
213 transition: { duration: 0.7, ease: searchMotionEase }
214 }
215 : {}
216)
217
218function resultMotion(index: number) {
219 if (!searchAnimationsEnabled.value) return {}
220 return {
221 layout: true,
222 initial: { opacity: 0, scale: 0.9375 },
223 animate: { opacity: 1, scale: 1 },
224 exit: {
225 opacity: 0,
226 scale: 0.9375,
227 height: 0,
228 transition: { duration: 0.25 }
229 },
230 transition: {
231 duration: 0.55,
232 ease: searchMotionEase,
233 delay: index * 0.02
234 }
235 }
236}
237
238const excerptMotion = computed(() =>
239 searchAnimationsEnabled.value
240 ? {
241 layout: true,
242 initial: { height: 0 },
243 animate: { height: '84px' },
244 exit: { height: 0 },
245 transition: { duration: 0.4, ease: searchMotionEase }
246 }
247 : {}
248)
249
250const footerMotion = computed(() =>
251 searchAnimationsEnabled.value ? { layout: true } : {}
252)
253
142254const urlFilterDebounced = ref(filterText.value)
143255let urlDebounceTimer: ReturnType<typeof setTimeout> | undefined
144256watch(filterText, (v) => {
@@ -180,7 +292,10 @@ let allLinksFetchPromise: Promise<void> | null = null
180292
181293async function ensureAllLinks() {
182294 if (allLinks.value.length > 0) return
183 if (allLinksFetchPromise) { await allLinksFetchPromise; return }
295 if (allLinksFetchPromise) {
296 await allLinksFetchPromise
297 return
298 }
184299 allLinksFetchPromise = fetch('/url-search-index.json')
185300 .then((r) => r.json())
186301 .then((data: PageLink[]) => {
@@ -191,12 +306,18 @@ async function ensureAllLinks() {
191306 })
192307 allLinks.value = data
193308 })
194 .catch(() => { allLinks.value = [] })
195 .finally(() => { allLinksFetchPromise = null })
309 .catch(() => {
310 allLinks.value = []
311 })
312 .finally(() => {
313 allLinksFetchPromise = null
314 })
196315 await allLinksFetchPromise
197316}
198317
199watch(urlSearchMode, (active) => { if (active) ensureAllLinks() }, { immediate: true })
318watch(urlSearchMode, (active) => {
319 if (active) ensureAllLinks()
320}, { immediate: true })
200321
201322interface UrlResult {
202323 href: string
@@ -236,7 +357,9 @@ const urlPageGroups = computed(() => {
236357 if (existing) existing.count++
237358 else map.set(key, { key, label: getPageLabel(key), count: 1 })
238359 }
239 return [...map.values()].sort((a, b) => getPageOrder(a.key) - getPageOrder(b.key))
360 return [...map.values()].sort((a, b) =>
361 getPageOrder(a.key) - getPageOrder(b.key)
362 )
240363})
241364
242365// Full match set honoring the active ribbon page filter (uncapped).
@@ -261,6 +384,7 @@ const filteredUrlResults = computed((): UrlResult[] => {
261384 const start = (urlCurrentPage.value - 1) * URL_PAGE_SIZE
262385 const end = start + URL_PAGE_SIZE
263386 const out: UrlResult[] = []
387 const query = urlFilterDebounced.value.trim()
264388 for (let i = start; i < end && i < matches.length; i++) {
265389 const link = matches[i]
266390 out.push({
@@ -269,12 +393,43 @@ const filteredUrlResults = computed((): UrlResult[] => {
269393 pageId: link.pageId,
270394 anchor: link.anchor,
271395 titles: link.titles,
272 highlighted: link.href // not currently rendered; kept for type compat
396 highlighted: highlightUrl(link.href, query)
273397 })
274398 }
275399 return out
276400})
277401
402function escapeHtml(value: string) {
403 return value
404 .replace(/&/g, '&amp;')
405 .replace(/</g, '&lt;')
406 .replace(/>/g, '&gt;')
407 .replace(/"/g, '&quot;')
408 .replace(/'/g, '&#39;')
409}
410
411function highlightUrl(url: string, query: string) {
412 const needle = query.trim()
413 if (!needle) return escapeHtml(url)
414
415 const lowerUrl = url.toLowerCase()
416 const lowerNeedle = needle.toLowerCase()
417 let out = ''
418 let cursor = 0
419 let index = lowerUrl.indexOf(lowerNeedle)
420
421 while (index !== -1) {
422 out += escapeHtml(url.slice(cursor, index))
423 out += `<mark class="url-highlight">${
424 escapeHtml(url.slice(index, index + needle.length))
425 }</mark>`
426 cursor = index + needle.length
427 index = lowerUrl.indexOf(lowerNeedle, cursor)
428 }
429
430 return out + escapeHtml(url.slice(cursor))
431}
432
278433// Compact page-number list with ellipses, e.g. [1, '…', 4, 5, 6, '…', 12].
279434const urlPageList = computed<(number | '…')[]>(() => {
280435 const total = urlTotalPages.value
@@ -333,7 +488,6 @@ function setUrlPageFilter(key: string | null) {
333488 })
334489}
335490
336
337491const disableDetailedView = computed(() => {
338492 return (
339493 theme.value.search?.provider === 'local' &&
@@ -548,7 +702,7 @@ const ribbonCanScrollRight = ref(false)
548702function getRibbonTrack(): HTMLElement | null {
549703 return (
550704 ribbonTrack.value ??
551 (el.value?.querySelector('.page-ribbon-track') as HTMLElement | null)
705 (el.value?.querySelector('.page-ribbon-track') as HTMLElement | null)
552706 )
553707}
554708
@@ -564,6 +718,48 @@ function updateRibbonOverflow() {
564718 track.scrollWidth - track.clientWidth - track.scrollLeft > 2
565719}
566720
721function scrollActivePagePillIntoView(direction = 0) {
722 nextTick(() => {
723 const track = getRibbonTrack()
724 if (!track) return
725
726 const pills = [...track.querySelectorAll<HTMLElement>('.page-pill')]
727 const activeIndex = pills.findIndex((pill) =>
728 pill.classList.contains('active')
729 )
730 const active = pills[activeIndex]
731 if (!active) return
732
733 const trackRect = track.getBoundingClientRect()
734 const activeRect = active.getBoundingClientRect()
735 const gap = 8
736 let nextScrollLeft = track.scrollLeft
737
738 if (activeRect.left < trackRect.left) {
739 nextScrollLeft += activeRect.left - trackRect.left - gap
740 } else if (activeRect.right > trackRect.right) {
741 nextScrollLeft += activeRect.right - trackRect.right + gap
742 }
743
744 const peek = pills[activeIndex + Math.sign(direction)]
745 if (peek) {
746 const peekRect = peek.getBoundingClientRect()
747 if (direction > 0 && peekRect.right > trackRect.right) {
748 nextScrollLeft += peekRect.right - trackRect.right + gap
749 } else if (direction < 0 && peekRect.left < trackRect.left) {
750 nextScrollLeft += peekRect.left - trackRect.left - gap
751 }
752 }
753
754 const max = track.scrollWidth - track.clientWidth
755 track.scrollTo({
756 left: Math.max(0, Math.min(max, nextScrollLeft)),
757 behavior: searchAnimationsEnabled.value ? 'smooth' : 'auto'
758 })
759 updateRibbonOverflow()
760 })
761}
762
567763let ribbonAnimHandle = 0
568764
569765function scrollRibbon(direction: number) {
@@ -576,6 +772,13 @@ function scrollRibbon(direction: number) {
576772 if (to === from) return
577773
578774 if (ribbonAnimHandle) cancelAnimationFrame(ribbonAnimHandle)
775
776 if (!searchAnimationsEnabled.value) {
777 track.scrollLeft = to
778 updateRibbonOverflow()
779 return
780 }
781
579782 const duration = 280
580783 const start = performance.now()
581784 const ease = (t: number) => 1 - Math.pow(1 - t, 3)
@@ -688,8 +891,18 @@ function buildDocExcerpt(
688891}
689892
690893watchDebounced(
691 () => [searchIndex.value, filterText.value, showDetailedList.value, searchMode.value] as const,
692 async ([index, filterTextValue, showDetailedListValue, mode], old, onCleanup) => {
894 () =>
895 [
896 searchIndex.value,
897 filterText.value,
898 showDetailedList.value,
899 searchMode.value
900 ] as const,
901 async (
902 [index, filterTextValue, showDetailedListValue, mode],
903 old,
904 onCleanup
905 ) => {
693906 if (old?.[0] !== index) {
694907 // in case of hmr
695908 cache.clear()
@@ -714,11 +927,14 @@ watchDebounced(
714927 fuzzy: mode === 'fuzzy' ? (0.3 as number | false) : false,
715928 prefix: mode === 'fuzzy' ? (term: string) => term.length > 3 : false,
716929 maxFuzzy: mode === 'fuzzy' ? 1 : 0,
717 boost: { title: 10, titles: 4, text: 1 },
930 boost: { title: 10, titles: 4, text: 1 }
718931 }
719932
720933 // Search
721 const ranked = index.search(filterTextValue, dynamicSearchOptions) as (SearchResult & Result)[]
934 const ranked = index.search(
935 filterTextValue,
936 dynamicSearchOptions
937 ) as (SearchResult & Result)[]
722938
723939 const top = ranked.slice(0, 50)
724940 const seen = new Set(top.map((r) => r.id))
@@ -748,8 +964,8 @@ watchDebounced(
748964 return { ...r, text: map?.get(anchor) ?? '' }
749965 })
750966 .sort((a, b) => {
751 const pageDiff =
752 getPageOrder(getPageKey(a.id)) - getPageOrder(getPageKey(b.id))
967 const pageDiff = getPageOrder(getPageKey(a.id)) -
968 getPageOrder(getPageKey(b.id))
753969 if (pageDiff !== 0) return pageDiff
754970 return getDocOrder(a.id) - getDocOrder(b.id)
755971 })
@@ -855,21 +1071,37 @@ function centerExcerpts() {
8551071 node = node.offsetParent as HTMLElement | null
8561072 }
8571073
858 const targetScrollTop = offset - viewportHeight / 2 + markNode.offsetHeight / 2
1074 const targetScrollTop = offset - viewportHeight / 2 +
1075 markNode.offsetHeight / 2
8591076 excerptElement.scrollTop = Math.max(0, targetScrollTop)
8601077 }
8611078}
8621079
8631080let centerHandle = 0
8641081
865function centerExcerptsUntilSettled() {
866 // No layout animations to wait on anymore — a single pass after the
867 // DOM has painted is enough.
1082function centerExcerptsUntilSettled(
1083 duration = searchAnimationsEnabled.value ? 450 : 0
1084) {
8681085 if (centerHandle) cancelAnimationFrame(centerHandle)
869 centerHandle = requestAnimationFrame(() => {
1086
1087 if (duration <= 0) {
1088 centerHandle = requestAnimationFrame(() => {
1089 centerExcerpts()
1090 centerHandle = 0
1091 })
1092 return
1093 }
1094
1095 const start = performance.now()
1096 const tick = () => {
8701097 centerExcerpts()
871 centerHandle = 0
872 })
1098 if (performance.now() - start < duration) {
1099 centerHandle = requestAnimationFrame(tick)
1100 } else {
1101 centerHandle = 0
1102 }
1103 }
1104 centerHandle = requestAnimationFrame(tick)
8731105}
8741106
8751107onBeforeUnmount(() => {
@@ -980,7 +1212,9 @@ const disableMouseOver = ref(true)
9801212
9811213// Active result list length (URL mode vs normal mode) — current page only
9821214const activeResultsLength = computed(() =>
983 urlSearchMode.value ? filteredUrlResults.value.length : pagedResults.value.length
1215 urlSearchMode.value
1216 ? filteredUrlResults.value.length
1217 : pagedResults.value.length
9841218)
9851219
9861220watch(pagedResults, (r) => {
@@ -1004,6 +1238,40 @@ function scrollToSelectedResult() {
10041238 })
10051239}
10061240
1241function goToSearchPageDelta(delta: number) {
1242 if (urlSearchMode.value) {
1243 const target = urlCurrentPage.value + delta
1244 if (target < 1 || target > urlTotalPages.value) return false
1245 goToUrlPage(target)
1246 return true
1247 }
1248
1249 const target = normalCurrentPage.value + delta
1250 if (target < 1 || target > normalTotalPages.value) return false
1251 goToNormalPage(target)
1252 return true
1253}
1254
1255function cyclePageTab(delta: number) {
1256 if (urlSearchMode.value) {
1257 if (urlPageGroups.value.length <= 1) return false
1258 const keys = [null, ...urlPageGroups.value.map((group) => group.key)]
1259 const current = keys.indexOf(urlActivePageFilter.value)
1260 const next = (current + delta + keys.length) % keys.length
1261 setUrlPageFilter(keys[next])
1262 scrollActivePagePillIntoView(delta)
1263 return true
1264 }
1265
1266 if (pageGroups.value.length <= 1) return false
1267 const keys = [null, ...pageGroups.value.map((group) => group.key)]
1268 const current = keys.indexOf(activePageFilter.value)
1269 const next = (current + delta + keys.length) % keys.length
1270 setPageFilter(keys[next])
1271 scrollActivePagePillIntoView(delta)
1272 return true
1273}
1274
10071275onKeyStroke('ArrowUp', (event) => {
10081276 event.preventDefault()
10091277 selectedIndex.value--
@@ -1024,8 +1292,36 @@ onKeyStroke('ArrowDown', (event) => {
10241292 scrollToSelectedResult()
10251293})
10261294
1295onKeyStroke('ArrowLeft', (event) => {
1296 if (!goToSearchPageDelta(-1)) return
1297 event.preventDefault()
1298 disableMouseOver.value = true
1299})
1300
1301onKeyStroke('ArrowRight', (event) => {
1302 if (!goToSearchPageDelta(1)) return
1303 event.preventDefault()
1304 disableMouseOver.value = true
1305})
1306
1307onKeyStroke('Tab', (event) => {
1308 if (!showSearch.value) return
1309 if (!cyclePageTab(event.shiftKey ? -1 : 1)) return
1310 event.preventDefault()
1311 disableMouseOver.value = true
1312})
1313
10271314const router = useRouter()
10281315
1316function navigateToUrlResult(item: UrlResult) {
1317 window.dispatchEvent(
1318 new CustomEvent('search-nav', { detail: { query: filterText.value } })
1319 )
1320 const dest = item.anchor ? item.pageId + '#' + item.anchor : item.pageId
1321 router.go(dest)
1322 showSearch.value = false
1323}
1324
10291325onKeyStroke('Enter', (e) => {
10301326 if (e.isComposing) return
10311327
@@ -1046,10 +1342,7 @@ onKeyStroke('Enter', (e) => {
10461342 if (urlSearchMode.value) {
10471343 const selectedUrl = filteredUrlResults.value[index]
10481344 if (selectedUrl) {
1049 window.dispatchEvent(new CustomEvent('search-nav', { detail: { query: filterText.value } }))
1050 const dest = selectedUrl.anchor ? selectedUrl.pageId + '#' + selectedUrl.anchor : selectedUrl.pageId
1051 router.go(dest)
1052 showSearch.value = false
1345 navigateToUrlResult(selectedUrl)
10531346 }
10541347 return
10551348 }
@@ -1177,406 +1470,524 @@ function onMouseMove(e: MouseEvent) {
11771470 class="VPLocalSearchBox"
11781471 :class="{ 'pointer-events-none': !showSearch }"
11791472 >
1180 <div
1181 v-if="showSearch"
1182 class="backdrop"
1183 @click="showSearch = false"
1184 />
1185
1186 <div
1187 v-if="showSearch"
1188 class="shell"
1189 >
1190 <form
1191 class="search-bar"
1192 @pointerup="onSearchBarClick($event)"
1193 @submit.prevent=""
1473 <AnimatePresence>
1474 <component
1475 :is="searchMotionDiv"
1476 v-if="showSearch"
1477 class="backdrop"
1478 @click="showSearch = false"
1479 v-bind="backdropMotion"
1480 />
1481 </AnimatePresence>
1482
1483 <AnimatePresence>
1484 <component
1485 :is="searchMotionDiv"
1486 v-if="showSearch"
1487 class="shell"
1488 v-bind="shellMotion"
11941489 >
1195 <label
1196 :title="buttonText"
1197 id="localsearch-label"
1198 for="localsearch-input"
1490 <component
1491 :is="searchMotionForm"
1492 class="search-bar"
1493 v-bind="formMotion"
1494 @pointerup="onSearchBarClick($event)"
1495 @submit.prevent=""
11991496 >
1200 <span
1201 aria-hidden="true"
1202 class="vpi-search search-icon local-search-icon"
1203 />
1204 </label>
1205 <div class="search-actions before">
1206 <button
1207 class="back-button"
1208 :title="translate('modal.backButtonTitle')"
1209 @click="showSearch = false"
1497 <label
1498 :title="buttonText"
1499 id="localsearch-label"
1500 for="localsearch-input"
12101501 >
1211 <span class="vpi-arrow-left local-search-icon" />
1212 </button>
1213 </div>
1214 <input
1215 ref="searchInput"
1216 v-model="filterText"
1217 :aria-activedescendant="selectedIndex > -1
1218 ? 'localsearch-item-' + selectedIndex
1219 : undefined"
1220 aria-autocomplete="both"
1221 :aria-controls="results?.length ? 'localsearch-list' : undefined"
1222 aria-labelledby="localsearch-label"
1223 autocapitalize="off"
1224 autocomplete="off"
1225 autocorrect="off"
1226 class="search-input"
1227 id="localsearch-input"
1228 enterkeyhint="go"
1229 maxlength="64"
1230 :placeholder="buttonText"
1231 spellcheck="false"
1232 type="search"
1233 />
1234 <div class="search-actions">
1235 <div v-if="!disableDetailedView && searchMode !== 'url'" class="view-group toolbar-group">
1502 <span
1503 aria-hidden="true"
1504 class="vpi-search search-icon local-search-icon"
1505 />
1506 </label>
1507 <div class="search-actions before">
12361508 <button
1237 type="button"
1238 class="mode-btn"
1239 :class="{ 'mode-active': showDetailedList }"
1240 title="Detail view (Consumes more RAM)"
1241 @click="showDetailedList ? showDetailedList = false : showDetailedList = true"
1509 class="back-button"
1510 :title="translate('modal.backButtonTitle')"
1511 @click="showSearch = false"
12421512 >
1243 <LayoutList :size="18" stroke-width="1.25" />
1244 </button>
1245 <button
1246 type="button"
1247 class="mode-btn"
1248 :class="{ 'mode-active': !showDetailedList }"
1249 title="List view (Consumes less RAM)"
1250 @click="!showDetailedList ? showDetailedList = true : showDetailedList = false"
1251 >
1252 <List :size="18" stroke-width="1.25" />
1513 <span class="vpi-arrow-left local-search-icon" />
12531514 </button>
12541515 </div>
1255 <div class="search-mode-group toolbar-group">
1256 <button
1257 type="button"
1258 class="mode-btn"
1259 :class="{ 'mode-active': searchMode === 'exact' }"
1260 title="Exact search"
1261 @click="searchMode === 'exact' ? cycleSearchMode() : searchMode = 'exact'"
1516 <input
1517 ref="searchInput"
1518 v-model="filterText"
1519 :aria-activedescendant="selectedIndex > -1
1520 ? 'localsearch-item-' + selectedIndex
1521 : undefined"
1522 aria-autocomplete="both"
1523 :aria-controls="results?.length ? 'localsearch-list' : undefined"
1524 aria-labelledby="localsearch-label"
1525 autocapitalize="off"
1526 autocomplete="off"
1527 autocorrect="off"
1528 class="search-input"
1529 id="localsearch-input"
1530 enterkeyhint="go"
1531 maxlength="64"
1532 :placeholder="buttonText"
1533 spellcheck="false"
1534 type="search"
1535 />
1536 <div class="search-actions">
1537 <div
1538 v-if="!disableDetailedView && searchMode !== 'url'"
1539 class="view-group toolbar-group"
12621540 >
1263 <Locate :size="18" stroke-width="1.25" />
1264 </button>
1541 <button
1542 type="button"
1543 class="mode-btn"
1544 :class="{ 'mode-active': showDetailedList }"
1545 title="Detail view (Consumes more RAM)"
1546 @click="showDetailedList
1547 ? showDetailedList = false
1548 : showDetailedList = true"
1549 >
1550 <TextAlignStart :size="18" stroke-width="1.25" />
1551 </button>
1552 <button
1553 type="button"
1554 class="mode-btn"
1555 :class="{ 'mode-active': !showDetailedList }"
1556 title="List view (Consumes less RAM)"
1557 @click="!showDetailedList
1558 ? showDetailedList = true
1559 : showDetailedList = false"
1560 >
1561 <List :size="18" stroke-width="1.25" />
1562 </button>
1563 </div>
1564 <div class="search-mode-group toolbar-group">
1565 <button
1566 type="button"
1567 class="mode-btn"
1568 :class="{ 'mode-active': searchMode === 'exact' }"
1569 title="Exact search"
1570 @click="searchMode === 'exact'
1571 ? cycleSearchMode()
1572 : searchMode = 'exact'"
1573 >
1574 <Regex :size="18" stroke-width="1.25" />
1575 </button>
1576 <button
1577 type="button"
1578 class="mode-btn"
1579 :class="{ 'mode-active': searchMode === 'fuzzy' }"
1580 title="Fuzzy search"
1581 @click="searchMode === 'fuzzy'
1582 ? cycleSearchMode()
1583 : searchMode = 'fuzzy'"
1584 >
1585 <LocateOff :size="18" stroke-width="1.25" />
1586 </button>
1587 <button
1588 type="button"
1589 class="mode-btn"
1590 :class="{ 'mode-active': searchMode === 'url' }"
1591 title="URL search"
1592 @click="searchMode === 'url'
1593 ? cycleSearchMode()
1594 : searchMode = 'url'"
1595 >
1596 <Globe :size="18" stroke-width="1.25" />
1597 </button>
1598 </div>
12651599 <button
1266 type="button"
1267 class="mode-btn"
1268 :class="{ 'mode-active': searchMode === 'fuzzy' }"
1269 title="Fuzzy search"
1270 @click="searchMode === 'fuzzy' ? cycleSearchMode() : searchMode = 'fuzzy'"
1600 class="clear-button"
1601 type="reset"
1602 :disabled="disableReset"
1603 :title="translate('modal.resetButtonTitle')"
1604 @click="resetSearch"
12711605 >
1272 <LocateOff :size="18" stroke-width="1.25" />
1273 </button>
1274 <button
1275 type="button"
1276 class="mode-btn"
1277 :class="{ 'mode-active': searchMode === 'url' }"
1278 title="URL search"
1279 @click="searchMode === 'url' ? cycleSearchMode() : searchMode = 'url'"
1280 >
1281 <Globe :size="18" stroke-width="1.25" />
1606 <Delete :size="19" stroke-width="1.25" />
12821607 </button>
12831608 </div>
1284 <button
1285 class="clear-button"
1286 type="reset"
1287 :disabled="disableReset"
1288 :title="translate('modal.resetButtonTitle')"
1289 @click="resetSearch"
1609 </component>
1610
1611 <AnimatePresence>
1612 <component
1613 :is="searchMotionDiv"
1614 v-if="urlSearchMode
1615 ? urlPageGroups.length > 1
1616 : pageGroups.length > 1"
1617 class="page-ribbon"
1618 :class="{
1619 'can-scroll-left': ribbonCanScrollLeft,
1620 'can-scroll-right': ribbonCanScrollRight
1621 }"
1622 v-bind="ribbonMotion"
12901623 >
1291 <Delete :size="19" stroke-width="1.25" />
1292 </button>
1293 </div>
1294 </form>
1295
1296 <div
1297 v-if="urlSearchMode ? urlPageGroups.length > 1 : pageGroups.length > 1"
1298 class="page-ribbon"
1299 >
1300 <button
1301 v-if="ribbonCanScrollLeft"
1302 type="button"
1303 class="page-ribbon-arrow left"
1304 aria-label="Scroll filters left"
1305 @click="scrollRibbon(-1)"
1306 >
1307 <ChevronRight :size="18" stroke-width="1.75" />
1308 </button>
1309 <div
1310 ref="ribbonTrack"
1311 class="page-ribbon-track"
1312 @scroll="updateRibbonOverflow"
1313 >
1314 <!-- URL mode tabs -->
1315 <template v-if="urlSearchMode">
1316 <button
1317 type="button"
1318 class="page-pill"
1319 :class="{ active: urlActivePageFilter === null }"
1320 @click="setUrlPageFilter(null)"
1321 >
1322 All
1323 <span class="page-pill-count">{{ urlMatches.length }}</span>
1324 </button>
13251624 <button
1326 v-for="group in urlPageGroups"
1327 :key="group.key"
1625 v-if="ribbonCanScrollLeft"
13281626 type="button"
1329 class="page-pill"
1330 :class="{ active: urlActivePageFilter === group.key }"
1331 @click="setUrlPageFilter(group.key)"
1627 class="page-ribbon-arrow left"
1628 aria-label="Scroll filters left"
1629 @click="scrollRibbon(-1)"
13321630 >
1333 <span class="page-pill-label">{{ group.label }}</span>
1334 <span class="page-pill-count">{{ group.count }}</span>
1631 <ChevronRight :size="18" stroke-width="1.75" />
13351632 </button>
1336 </template>
1337 <!-- Normal mode tabs -->
1338 <template v-else>
1339 <button
1340 type="button"
1341 class="page-pill"
1342 :class="{ active: activePageFilter === null }"
1343 @click="setPageFilter(null)"
1633 <div
1634 ref="ribbonTrack"
1635 class="page-ribbon-track"
1636 @scroll="updateRibbonOverflow"
13441637 >
1345 All
1346 <span class="page-pill-count">{{ results.length }}</span>
1347 </button>
1638 <!-- URL mode tabs -->
1639 <template v-if="urlSearchMode">
1640 <button
1641 type="button"
1642 class="page-pill"
1643 :class="{
1644 active: urlActivePageFilter === null
1645 }"
1646 @click="setUrlPageFilter(null)"
1647 >
1648 All
1649 <span class="page-pill-count">{{ urlMatches.length }}</span>
1650 </button>
1651 <button
1652 v-for="group in urlPageGroups"
1653 :key="group.key"
1654 type="button"
1655 class="page-pill"
1656 :class="{
1657 active:
1658 urlActivePageFilter === group.key
1659 }"
1660 @click="setUrlPageFilter(group.key)"
1661 >
1662 <span class="page-pill-label">{{ group.label }}</span>
1663 <span class="page-pill-count">{{ group.count }}</span>
1664 </button>
1665 </template>
1666 <!-- Normal mode tabs -->
1667 <template v-else>
1668 <button
1669 type="button"
1670 class="page-pill"
1671 :class="{ active: activePageFilter === null }"
1672 @click="setPageFilter(null)"
1673 >
1674 All
1675 <span class="page-pill-count">{{ results.length }}</span>
1676 </button>
1677 <button
1678 v-for="group in pageGroups"
1679 :key="group.key"
1680 type="button"
1681 class="page-pill"
1682 :class="{
1683 active: activePageFilter === group.key
1684 }"
1685 @click="setPageFilter(group.key)"
1686 >
1687 <span class="page-pill-label">{{ group.label }}</span>
1688 <span class="page-pill-count">{{ group.count }}</span>
1689 </button>
1690 </template>
1691 </div>
13481692 <button
1349 v-for="group in pageGroups"
1350 :key="group.key"
1693 v-if="ribbonCanScrollRight"
13511694 type="button"
1352 class="page-pill"
1353 :class="{ active: activePageFilter === group.key }"
1354 @click="setPageFilter(group.key)"
1695 class="page-ribbon-arrow right"
1696 aria-label="Scroll filters right"
1697 @click="scrollRibbon(1)"
13551698 >
1356 <span class="page-pill-label">{{ group.label }}</span>
1357 <span class="page-pill-count">{{ group.count }}</span>
1699 <ChevronRight :size="18" stroke-width="1.75" />
13581700 </button>
1359 </template>
1360 </div>
1361 <button
1362 v-if="ribbonCanScrollRight"
1363 type="button"
1364 class="page-ribbon-arrow right"
1365 aria-label="Scroll filters right"
1366 @click="scrollRibbon(1)"
1701 </component>
1702 </AnimatePresence>
1703
1704 <ul
1705 ref="resultsEl"
1706 :id="results?.length ? 'localsearch-list' : undefined"
1707 :role="results?.length ? 'listbox' : undefined"
1708 :aria-labelledby="results?.length ? 'localsearch-label' : undefined"
1709 class="results"
1710 @mousemove="onMouseMove"
13671711 >
1368 <ChevronRight :size="18" stroke-width="1.75" />
1369 </button>
1370 </div>
1371
1372 <ul
1373 ref="resultsEl"
1374 :id="results?.length ? 'localsearch-list' : undefined"
1375 :role="results?.length ? 'listbox' : undefined"
1376 :aria-labelledby="results?.length ? 'localsearch-label' : undefined"
1377 class="results"
1378 @mousemove="onMouseMove"
1379 >
1380 <!-- Empty state (shared) -->
1381 <div
1382 v-if="urlSearchMode
1383 ? (!filterText || !urlMatches.length)
1384 : (!filterText || !filteredResults.length)"
1385 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"
1386 >
1387 <img
1388 class="h-40 object-contain object-center -translate-x-2"
1389 src="/asset/smolame.png"
1390 alt="Smol ame"
1391 />
1392 <h1 v-if="filterText">Couldn't find anything, try again?</h1>
1393 <h1 v-else>Looking for something?</h1>
1394 </div>
1395
1396 <!-- URL search results -->
1397 <template v-if="urlSearchMode">
1398 <li
1399 v-for="(item, index) in filteredUrlResults"
1400 :key="'url-' + urlCurrentPage + '-' + item.pageId + '-' + item.anchor + '-' + index"
1401 class="result-layout"
1402 :id="'localsearch-item-' + (index + 1)"
1403 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1404 role="option"
1405 >
1406 <a
1407 :href="item.anchor ? item.pageId + '#' + item.anchor : item.pageId"
1408 class="result"
1409 :class="{ selected: selectedIndex === index + 1 }"
1410 :aria-label="item.linkText || item.href"
1411 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1412 @focusin="selectedIndex = index + 1"
1413 @click="onResultClick"
1414 :data-index="index + 1"
1712 <!-- Empty state (shared) -->
1713 <AnimatePresence>
1714 <component
1715 :is="searchMotionDiv"
1716 v-if="urlSearchMode
1717 ? (!filterText || !urlMatches.length)
1718 : (!filterText || !filteredResults.length)"
1719 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"
1720 v-bind="emptyStateMotion"
14151721 >
1416 <div class="url-result-body">
1417 <div class="titles url-titles">
1418 <Hash v-if="item.titles.length > 0" stroke-width="1.25" :size="18" />
1419 <File v-else stroke-width="1.25" :size="18" />
1420 <span
1421 v-for="(t, ti) in item.titles"
1422 :key="ti"
1423 class="title"
1424 >
1425 <span class="text" v-html="t" />
1426 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
1427 </span>
1428 <span class="title main">
1429 <span class="text">{{ item.linkText || item.href }}</span>
1430 </span>
1431 </div>
1432 <a
1433 :href="item.href"
1434 target="_blank"
1435 rel="noopener noreferrer"
1436 class="url-open-btn"
1437 :class="{ 'url-open-btn-selected': selectedIndex === index + 1 }"
1438 title="Open link"
1439 @click.stop
1722 <img
1723 class="h-40 object-contain object-center"
1724 src="/asset/smolame.png"
1725 alt="Smol ame"
1726 />
1727 <h1 v-if="filterText">Couldn't find anything, try again?</h1>
1728 <h1 v-else>Looking for something?</h1>
1729 </component>
1730 </AnimatePresence>
1731
1732 <!-- URL search results -->
1733 <template v-if="urlSearchMode">
1734 <AnimatePresence>
1735 <component
1736 :is="searchMotionLi"
1737 v-for="(item, index) in filteredUrlResults"
1738 :key="'url-' + urlCurrentPage + '-' +
1739 item.pageId + '-' +
1740 item.anchor + '-' + index"
1741 class="result-layout"
1742 :id="'localsearch-item-' + (index + 1)"
1743 :aria-selected="selectedIndex === index + 1
1744 ? 'true'
1745 : 'false'"
1746 role="option"
1747 v-bind="resultMotion(index)"
1748 >
1749 <div
1750 class="result url-result-card"
1751 :class="{
1752 selected: selectedIndex === index + 1
1753 }"
1754 :aria-label="item.href"
1755 role="button"
1756 @mouseenter="!disableMouseOver &&
1757 (selectedIndex = index + 1)"
1758 @focusin="selectedIndex = index + 1"
1759 @click="navigateToUrlResult(item)"
1760 :data-index="index + 1"
14401761 >
1441 <ExternalLink :size="14" stroke-width="1.5" />
1442 </a>
1443 </div>
1444 </a>
1445 </li>
1446 </template>
1447
1448 <!-- Normal search results -->
1449 <template v-else>
1450 <li
1451 v-for="(p, index) in pagedResults"
1452 :key="'normal-' + normalCurrentPage + '-' + p.id"
1453 class="result-layout"
1454 :id="'localsearch-item-' + (index + 1)"
1455 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1456 role="option"
1457 >
1458 <a
1459 :href="p.id"
1460 class="result"
1461 :class="{ selected: selectedIndex === index + 1 }"
1462 :aria-label="[...p.titles, p.title].join(' > ')"
1463 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1464 @focusin="selectedIndex = index + 1"
1465 @click="onResultClick"
1466 :data-index="index + 1"
1467 >
1468 <div>
1469 <div class="titles">
1470 <Hash v-if="p.titles.length > 0" stroke-width="1.25" :size="18" />
1471 <File v-else stroke-width="1.25" :size="18" />
1472 <span
1473 v-for="(t, index) in p.titles"
1474 :key="index"
1475 class="title"
1476 >
1477 <span class="text" v-html="t" />
1478 <ArrowRight stroke-width="1.25" :size="18" class="mx-0.5" />
1479 </span>
1480 <span class="title main">
1481 <span class="text" v-html="p.title" />
1482 </span>
1762 <div class="url-result-body">
1763 <div class="url-path">
1764 <Hash
1765 v-if="item.titles.length > 0"
1766 stroke-width="1.25"
1767 :size="18"
1768 />
1769 <File v-else stroke-width="1.25" :size="18" />
1770 <span
1771 v-for="(t, ti) in item.titles"
1772 :key="ti"
1773 class="url-path-segment"
1774 >
1775 <span class="text" v-html="t" />
1776 <ArrowRight
1777 stroke-width="1.25"
1778 :size="18"
1779 class="mx-0.5"
1780 />
1781 </span>
1782 <span
1783 v-if="item.linkText"
1784 class="url-path-current"
1785 v-html="item.linkText"
1786 />
1787 </div>
1788 <a
1789 :href="item.href"
1790 target="_blank"
1791 rel="noopener noreferrer"
1792 class="url-link"
1793 :title="item.href"
1794 @click.stop
1795 v-html="item.highlighted"
1796 >
1797 </a>
1798 </div>
14831799 </div>
1800 </component>
1801 </AnimatePresence>
1802 </template>
14841803
1485 <div v-if="showDetailedList" class="excerpt-wrapper">
1486 <div v-if="p.text" class="excerpt" inert>
1487 <div class="vp-doc" v-html="p.text" />
1804 <!-- Normal search results -->
1805 <template v-else>
1806 <AnimatePresence>
1807 <component
1808 :is="searchMotionLi"
1809 v-for="(p, index) in pagedResults"
1810 :key="'normal-' + normalCurrentPage + '-' + p.id"
1811 class="result-layout"
1812 :id="'localsearch-item-' + (index + 1)"
1813 :aria-selected="selectedIndex === index + 1
1814 ? 'true'
1815 : 'false'"
1816 role="option"
1817 v-bind="resultMotion(index)"
1818 >
1819 <a
1820 :href="p.id"
1821 class="result"
1822 :class="{
1823 selected: selectedIndex === index + 1
1824 }"
1825 :aria-label="[...p.titles, p.title].join(' > ')"
1826 @mouseenter="!disableMouseOver &&
1827 (selectedIndex = index + 1)"
1828 @focusin="selectedIndex = index + 1"
1829 @click="onResultClick"
1830 :data-index="index + 1"
1831 >
1832 <div>
1833 <div class="titles">
1834 <Hash
1835 v-if="p.titles.length > 0"
1836 stroke-width="1.25"
1837 :size="18"
1838 />
1839 <File v-else stroke-width="1.25" :size="18" />
1840 <span
1841 v-for="(t, index) in p.titles"
1842 :key="index"
1843 class="title"
1844 >
1845 <span class="text" v-html="t" />
1846 <ArrowRight
1847 stroke-width="1.25"
1848 :size="18"
1849 class="mx-0.5"
1850 />
1851 </span>
1852 <span class="title main">
1853 <span class="text" v-html="p.title" />
1854 </span>
1855 </div>
1856
1857 <div v-if="showDetailedList" class="excerpt-wrapper">
1858 <component
1859 :is="searchMotionDiv"
1860 v-if="p.text"
1861 class="excerpt"
1862 inert
1863 v-bind="excerptMotion"
1864 >
1865 <div class="vp-doc" v-html="p.text" />
1866 </component>
1867 <div class="excerpt-gradient-bottom" />
1868 <div class="excerpt-gradient-top" />
1869 </div>
14881870 </div>
1489 <div class="excerpt-gradient-bottom" />
1490 <div class="excerpt-gradient-top" />
1491 </div>
1492 </div>
1493 </a>
1494 </li>
1495 </template>
1496 </ul>
1497
1498 <!-- Pagination controls (Fixed structural segment block style wrapper) -->
1499 <nav
1500 v-if="(urlSearchMode ? urlTotalPages : normalTotalPages) > 1"
1501 class="url-pagination"
1502 aria-label="Search result pages"
1503 >
1504 <div class="url-pagination-segment">
1505 <button
1506 type="button"
1507 class="url-page-btn url-page-nav"
1508 :disabled="(urlSearchMode ? urlCurrentPage : normalCurrentPage) <= 1"
1509 aria-label="Previous page"
1510 @click="urlSearchMode
1511 ? goToUrlPage(urlCurrentPage - 1)
1512 : goToNormalPage(normalCurrentPage - 1)"
1513 >
1514 <ChevronRight :size="14" stroke-width="2" style="transform: rotate(180deg)" />
1515 </button>
1871 </a>
1872 </component>
1873 </AnimatePresence>
1874 </template>
1875 </ul>
15161876
1517 <template
1518 v-for="(p, pi) in (urlSearchMode ? urlPageList : normalPageList)"
1519 :key="pi"
1877 <!-- Bottom section: pagination (when needed). Always rendered so the
1878 shell's rounded bottom edge stays consistent. -->
1879 <nav
1880 class="url-pagination"
1881 aria-label="Search result pages"
1882 >
1883 <div
1884 v-if="(urlSearchMode
1885 ? urlTotalPages
1886 : normalTotalPages) > 1"
1887 class="url-pagination-segment"
15201888 >
1521 <span v-if="p === '…'" class="url-page-ellipsis">…</span>
15221889 <button
1523 v-else
15241890 type="button"
1525 class="url-page-btn"
1526 :class="{ active: p === (urlSearchMode ? urlCurrentPage : normalCurrentPage) }"
1527 :aria-current="p === (urlSearchMode ? urlCurrentPage : normalCurrentPage) ? 'page' : undefined"
1528 @click="urlSearchMode ? goToUrlPage(p as number) : goToNormalPage(p as number)"
1891 class="url-page-btn url-page-nav"
1892 :disabled="(urlSearchMode
1893 ? urlCurrentPage
1894 : normalCurrentPage) <= 1"
1895 aria-label="Previous page"
1896 @click="urlSearchMode
1897 ? goToUrlPage(urlCurrentPage - 1)
1898 : goToNormalPage(normalCurrentPage - 1)"
15291899 >
1530 {{ p }}
1900 <ChevronRight
1901 :size="14"
1902 stroke-width="2"
1903 style="transform: rotate(180deg)"
1904 />
15311905 </button>
1532 </template>
15331906
1534 <button
1535 type="button"
1536 class="url-page-btn url-page-nav"
1537 :disabled="(urlSearchMode ? urlCurrentPage : normalCurrentPage) >= (urlSearchMode ? urlTotalPages : normalTotalPages)"
1538 aria-label="Next page"
1539 @click="urlSearchMode
1907 <template
1908 v-for="(p, pi) in urlSearchMode ? urlPageList : normalPageList"
1909 :key="pi"
1910 >
1911 <span v-if="p === '…'" class="url-page-ellipsis">…</span>
1912 <button
1913 v-else
1914 type="button"
1915 class="url-page-btn"
1916 :class="{
1917 active: p === (urlSearchMode
1918 ? urlCurrentPage
1919 : normalCurrentPage)
1920 }"
1921 :aria-current="p === (urlSearchMode
1922 ? urlCurrentPage
1923 : normalCurrentPage)
1924 ? 'page'
1925 : undefined"
1926 @click="urlSearchMode
1927 ? goToUrlPage(p as number)
1928 : goToNormalPage(p as number)"
1929 >
1930 {{ p }}
1931 </button>
1932 </template>
1933
1934 <button
1935 type="button"
1936 class="url-page-btn url-page-nav"
1937 :disabled="(urlSearchMode
1938 ? urlCurrentPage
1939 : normalCurrentPage) >=
1940 (urlSearchMode
1941 ? urlTotalPages
1942 : normalTotalPages)"
1943 aria-label="Next page"
1944 @click="urlSearchMode
15401945 ? goToUrlPage(urlCurrentPage + 1)
15411946 : goToNormalPage(normalCurrentPage + 1)"
1542 >
1543 <ChevronRight :size="14" stroke-width="2" />
1544 </button>
1545 </div>
1546 </nav>
1547
1548 <div class="search-keyboard-shortcuts">
1549 <span>
1550 <kbd
1551 :aria-label="translate(
1552 'modal.footer.navigateUpKeyAriaLabel'
1553 )"
1554 >
1555 <span class="vpi-arrow-up navigate-icon" />
1556 </kbd>
1557 <kbd
1558 :aria-label="translate(
1559 'modal.footer.navigateDownKeyAriaLabel'
1560 )"
1561 >
1562 <span class="vpi-arrow-down navigate-icon" />
1563 </kbd>
1564 {{ translate('modal.footer.navigateText') }}
1565 </span>
1566 <span>
1567 <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')">
1568 <span class="vpi-corner-down-left navigate-icon" />
1569 </kbd>
1570 {{ translate('modal.footer.selectText') }}
1571 </span>
1572 <span>
1573 <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')">
1574 esc
1575 </kbd>
1576 {{ translate('modal.footer.closeText') }}
1577 </span>
1578 </div>
1579 </div>
1947 >
1948 <ChevronRight :size="14" stroke-width="2" />
1949 </button>
1950 </div>
1951 </nav>
1952
1953 <component
1954 :is="searchMotionDiv"
1955 v-if="showKeyboardShortcuts"
1956 class="search-keyboard-shortcuts"
1957 v-bind="footerMotion"
1958 >
1959 <span>
1960 <kbd
1961 :aria-label="translate(
1962 'modal.footer.navigateUpKeyAriaLabel'
1963 )"
1964 >
1965 <span class="vpi-arrow-up navigate-icon" />
1966 </kbd>
1967 <kbd
1968 :aria-label="translate(
1969 'modal.footer.navigateDownKeyAriaLabel'
1970 )"
1971 >
1972 <span class="vpi-arrow-down navigate-icon" />
1973 </kbd>
1974 {{ translate('modal.footer.navigateText') }}
1975 </span>
1976 <span>
1977 <kbd :aria-label="translate('modal.footer.selectKeyAriaLabel')">
1978 <span class="vpi-corner-down-left navigate-icon" />
1979 </kbd>
1980 {{ translate('modal.footer.selectText') }}
1981 </span>
1982 <span>
1983 <kbd :aria-label="translate('modal.footer.closeKeyAriaLabel')">
1984 esc
1985 </kbd>
1986 {{ translate('modal.footer.closeText') }}
1987 </span>
1988 </component>
1989 </component>
1990 </AnimatePresence>
15801991
15811992 <button v-if="!showSearch" />
15821993 </div>
@@ -1607,7 +2018,7 @@ function onMouseMove(e: MouseEvent) {
16072018.shell {
16082019 position: relative;
16092020 box-sizing: border-box;
1610 padding: 12px;
2021 padding: 12px 12px 8px;
16112022 margin: 64px auto;
16122023 display: flex;
16132024 flex-direction: column;
@@ -1663,6 +2074,15 @@ function onMouseMove(e: MouseEvent) {
16632074 min-width: 0;
16642075 flex: none;
16652076 overflow: hidden;
2077 transition: padding-inline 0.15s;
2078}
2079
2080.page-ribbon.can-scroll-left {
2081 padding-left: 42px;
2082}
2083
2084.page-ribbon.can-scroll-right {
2085 padding-right: 42px;
16662086}
16672087
16682088.page-ribbon-track {
@@ -1706,14 +2126,12 @@ function onMouseMove(e: MouseEvent) {
17062126
17072127.page-ribbon-arrow.right {
17082128 right: 0;
1709 background: linear-gradient(to right, transparent, var(--vp-local-search-bg, var(--vp-c-bg-soft)) 70%);
17102129 justify-content: flex-end;
17112130 padding-right: 6px;
17122131}
17132132
17142133.page-ribbon-arrow.left {
17152134 left: 0;
1716 background: linear-gradient(to left, transparent, var(--vp-local-search-bg, var(--vp-c-bg-soft)) 70%);
17172135 justify-content: flex-start;
17182136 padding-left: 6px;
17192137}
@@ -1894,6 +2312,10 @@ function onMouseMove(e: MouseEvent) {
18942312 overscroll-behavior: contain;
18952313}
18962314
2315.result-layout {
2316 will-change: transform, opacity, height;
2317}
2318
18972319.result {
18982320 display: flex;
18992321 align-items: center;
@@ -1927,15 +2349,83 @@ function onMouseMove(e: MouseEvent) {
19272349 align-items: center;
19282350}
19292351
1930/* URL-mode card: breadcrumb text wraps freely, open-link button is pinned
1931 to the top-right corner so it never detaches when the title wraps. */
2352.url-result-card {
2353 cursor: pointer;
2354}
2355
19322356.url-result-body {
1933 position: relative;
1934 padding-right: 28px;
2357 display: flex;
2358 flex-direction: column;
2359 gap: 6px;
19352360}
19362361
1937.url-titles {
1938 z-index: auto;
2362.url-path {
2363 display: flex;
2364 align-items: center;
2365 flex-wrap: wrap;
2366 gap: 4px;
2367 color: var(--vp-c-text-3);
2368 font-size: 0.78rem;
2369 line-height: 1.2;
2370}
2371
2372.url-path > svg,
2373.url-path-segment svg {
2374 flex-shrink: 0;
2375 width: 1em;
2376 height: 1em;
2377 margin-top: -1px;
2378 opacity: 0.55;
2379}
2380
2381.url-path > svg {
2382 margin-top: -2px;
2383}
2384
2385.url-path-segment {
2386 display: flex;
2387 align-items: center;
2388 min-width: 0;
2389}
2390
2391.url-path-current {
2392 display: inline-flex;
2393 align-items: center;
2394 color: var(--vp-c-text-2);
2395}
2396
2397.url-path :deep(.icon-tip) {
2398 display: inline-flex;
2399 align-items: center;
2400 line-height: 1;
2401 vertical-align: middle;
2402}
2403
2404.url-path :deep(.icon-tip > span) {
2405 width: 1em;
2406 height: 1em;
2407 min-width: 1em;
2408}
2409
2410.url-link {
2411 align-self: flex-start;
2412 max-width: 100%;
2413 color: var(--vp-c-text-1);
2414 font-size: 0.95rem;
2415 font-weight: 500;
2416 line-height: 1.35;
2417 overflow-wrap: anywhere;
2418 word-break: break-word;
2419}
2420
2421.url-link:hover {
2422 color: var(--vp-c-brand-1);
2423 text-decoration: underline;
2424 text-underline-offset: 2px;
2425}
2426
2427.result.selected .url-link {
2428 color: var(--vp-c-brand-1);
19392429}
19402430
19412431.titles > svg {
@@ -1962,15 +2452,6 @@ function onMouseMove(e: MouseEvent) {
19622452 opacity: 0.5;
19632453}
19642454
1965.url-titles .title.main {
1966 min-width: 0;
1967}
1968
1969.url-titles .title.main .text {
1970 overflow-wrap: anywhere;
1971 word-break: break-word;
1972}
1973
19742455.result.selected {
19752456 --vp-local-search-result-bg: var(--vp-local-search-result-selected-bg);
19762457 border-color: var(--vp-local-search-result-selected-border);
@@ -2119,42 +2600,6 @@ svg {
21192600 background: rgba(60, 120, 210, 0.10);
21202601}
21212602
2122.url-open-btn {
2123 position: absolute;
2124 top: 0;
2125 right: 0;
2126 flex: none;
2127 display: flex;
2128 align-items: center;
2129 justify-content: center;
2130 width: 24px;
2131 height: 24px;
2132 border-radius: 4px;
2133 color: var(--vp-c-text-3);
2134 opacity: 0;
2135 transition: opacity 0.15s, color 0.15s, background 0.15s;
2136}
2137
2138.result:hover .url-open-btn,
2139.result.selected .url-open-btn {
2140 opacity: 1;
2141}
2142
2143@media (max-width: 767px) {
2144 .url-open-btn {
2145 opacity: 1;
2146 }
2147}
2148
2149.url-open-btn:hover {
2150 color: var(--vp-c-brand-1);
2151 background: var(--vp-c-default-soft);
2152}
2153
2154.url-open-btn-selected {
2155 color: var(--vp-c-brand-1) !important;
2156}
2157
21582603:deep(.url-highlight) {
21592604 background-color: var(--vp-local-search-highlight-bg);
21602605 color: var(--vp-local-search-highlight-text);
@@ -2163,20 +2608,18 @@ svg {
21632608 font-style: normal;
21642609}
21652610
2166/* Redesigned Unified Mode Switching Segmented Style Pagination Controls */
2611/* Bottom-strip pagination. The <nav> is always rendered (empty when only one
2612 page) but collapses to zero height in that case so the shell's bottom
2613 rounded edge sits flush against the results. */
21672614.url-pagination {
21682615 display: flex;
21692616 align-items: center;
21702617 justify-content: center;
21712618 flex: 0 0 auto !important;
2172 padding: 10px 8px;
2173 border-top: 1px solid var(--vp-c-divider);
21742619}
21752620
2176@media (max-width: 767px) {
2177 .url-pagination {
2178 padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
2179 }
2621.url-pagination:has(.url-pagination-segment) {
2622 padding-top: 8px;
21802623}
21812624
21822625.url-pagination-segment {
@@ -2243,4 +2686,4 @@ svg {
22432686 user-select: none;
22442687 background: transparent;
22452688}
2246</style>
\ No newline at end of file
2689</style>
docs/.vitepress/theme/styles/style.scss +12 −11
@@ -415,8 +415,8 @@ main figure figcaption {
415415}
416416
417417.vp-doc h1 {
418 margin-top: 0.5rem;
419 margin-bottom: 0.5rem;
418 margin-top: 0.5rem;
419 margin-bottom: 0.5rem;
420420}
421421
422422.vp-doc h2 {
@@ -429,8 +429,8 @@ main figure figcaption {
429429}
430430
431431.vp-doc h4 {
432 margin-top: 1rem;
433 margin-bottom: 1rem;
432 margin-top: 1rem;
433 margin-bottom: 1rem;
434434}
435435
436436/* Make the page half the width for class `sandbox` */
@@ -996,12 +996,6 @@ table tr:nth-child(odd) {
996996 @apply hidden;
997997 }
998998
999 &::after {
1000 @apply fixed hidden md:block left-0 bottom-11 w-full h-0.25
1001 bg-neutral-400/25 dark:bg-neutral-600/65;
1002 content: "";
1003 }
1004
1005999 & > li {
10061000 @apply z-10 scroll-pt-2;
10071001
@@ -1430,6 +1424,13 @@ html.reduce-blur-effects {
14301424 animation: none !important;
14311425 }
14321426
1427 .VPLocalSearchBox,
1428 .VPLocalSearchBox * {
1429 animation: none !important;
1430 scroll-behavior: auto !important;
1431 transition-duration: 0s !important;
1432 }
1433
14331434 .VPLocalNav > .container > .menu,
14341435 .VPLocalNav > .container > .VPLocalNavOutlineDropdown > button,
14351436 .VPLocalNav > .container > .VPLocalNavOutlineDropdown > .items,
@@ -1676,4 +1677,4 @@ html.reduce-blur-effects {
16761677
16771678.vp-doc .custom-block.title-only {
16781679 padding-bottom: 16px;
1679}
\ No newline at end of file
1680}