Commit e240c1a830

e240c1a830a32ec7ee4244aabf56ec8396ea79ee

parent: bb0a5808b3

Unsigned

TubaApollo <86665265+TubaApollo@users.noreply.github.com> · 2026-04-10 15:24 UTC

feat: add icon hover tooltips and smooth rAF arrow-key scrolling

Layout: unified · split

docs/.vitepress/configs/markdown/emoji.ts +36 −10
@@ -7,6 +7,7 @@
7 */ 7 */
8import type { IconifyJSON } from '@iconify-json/octicon' 8import type { IconifyJSON } from '@iconify-json/octicon'
9import type { MarkdownRenderer } from 'vitepress' 9import type { MarkdownRenderer } from 'vitepress'
10import { iconTooltips } from './tooltip'
10 11
11// Icons that need to be used should be imported here 12// Icons that need to be used should be imported here
12import { icons as akar } from '@iconify-json/akar-icons' 13import { icons as akar } from '@iconify-json/akar-icons'
@@ -133,6 +134,31 @@ const aliases: Record<string, string> = {
133 hs: 'mdi-hulu' 134 hs: 'mdi-hulu'
134} 135}
135 136
137// Tooltip labels for icon aliases (desktop hover)
138const aliasLabels: Record<string, string> = {
139 s: 'Favorite', src: 'Source Code', cs: 'Closed Source',
140 e: 'Extension / Plugin', prx: 'Proxies', ero: 'R18',
141 acc: 'Needs account', help: 'Help / Docs', more: 'Related',
142 and: 'Android', ios: 'iOS / iPadOS', app: 'MacOS',
143 win: 'Windows', lin: 'Linux', bsd: 'BSD',
144 cmd: 'CLI / TUI', ff: 'Firefox', cr: 'Chromium', web: 'Web',
145 strm: 'Stream', ddl: 'Online / DDL', mag: 'Torrent / p2p',
146 lcl: 'Local file', batch: 'Batch Download',
147 sp: 'Single Page Mode', dp: 'Double Page Mode', ls: 'Long-Strip Mode',
148 paid: 'Paid', sub: 'Subscription', free: 'Has free content',
149 coin: 'Coin / Point', fm: 'Freemium',
150 d: 'Discord', f: '4chan', x: 'Twitter', tg: 'Telegram',
151 mal: 'MyAnimeList', al: 'AniList', k: 'Kitsu', simkl: 'Simkl',
152 sgd: 'Google Drive', sm: 'MEGA', smf: 'MediaFire', host: 'Other Host',
153 fjp: 'Japan', fkr: 'Korea', fcn: 'China',
154 js: 'JavaScript', css: 'CSS', py: 'Python', dock: 'Docker',
155 n: 'Nightly build', alt: 'Alternative', rss: 'RSS Feed', tf: 'Testflight',
156 yes: 'Yes / Available', no: 'No / Unavailable',
157 global: 'Global', cc: 'Subtitles / CC', hs: 'Hardsubs',
158 up: 'More Info', ms: 'Feedback',
159 sync: 'Sync', ie: 'Import / Export'
160}
161
136// Custom icons using UnoCSS inline collection 162// Custom icons using UnoCSS inline collection
137const customIconAliases: Record<string, string> = { 163const customIconAliases: Record<string, string> = {
138 'custom-circle': 'inline-circle' 164 'custom-circle': 'inline-circle'
@@ -163,26 +189,26 @@ export { aliases, defs }
163export function emojiRender(md: MarkdownRenderer) { 189export function emojiRender(md: MarkdownRenderer) {
164 md.renderer.rules.emoji = (tokens, idx) => { 190 md.renderer.rules.emoji = (tokens, idx) => {
165 const markup = tokens[idx].markup 191 const markup = tokens[idx].markup
192 const label = aliasLabels[markup] || iconTooltips[markup]
193
194 const tip = label?.replace(/"/g, '&quot;')
195 const wrap = (cls: string) => tip
196 ? `<span class="icon-tip" data-tip="${tip}" tabindex="-1"><span class="${cls}"></span></span>`
197 : `<span class="${cls}"></span>`
166 198
167 // Check for custom icon aliases first 199 // Check for custom icon aliases first
168 if (customIconAliases[markup]) { 200 if (customIconAliases[markup]) return wrap(`i-${customIconAliases[markup]}`)
169 return `<span class="i-${customIconAliases[markup]}"></span>`
170 }
171 201
172 // Check for aliases 202 // Check for aliases
173 if (aliases[markup]) { 203 if (aliases[markup]) return wrap(`i-${aliases[markup]}`)
174 return `<span class="i-${aliases[markup]}"></span>`
175 }
176 204
177 // Check for prefixed icons 205 // Check for prefixed icons
178 for (const emoji of emojis) { 206 for (const emoji of emojis) {
179 if (markup.startsWith(emoji.prefix!)) { 207 if (markup.startsWith(emoji.prefix!)) return wrap(`i-${markup}`)
180 return `<span class="i-${markup}"></span>`
181 }
182 } 208 }
183 209
184 // Default to twemoji 210 // Default to twemoji
185 return `<span class="i-twemoji-${markup}"></span>` 211 return wrap(`i-twemoji-${markup}`)
186 } 212 }
187} 213}
188 214
docs/.vitepress/configs/markdown/tooltip.ts added +10
@@ -0,0 +1,10 @@
1/**
2 * Tooltip labels for icons without shortcode aliases.
3 * Format: 'iconpack-id': 'Description'
4 *
5 * These are merged with alias labels from emoji.ts
6 * to provide hover tooltips on all icons.
7 */
8export const iconTooltips: Record<string, string> = {
9 'mingcute-server-fill': 'Self-uploaded (Own storage or video host)'
10}
docs/.vitepress/theme/Layout.vue +26 −1
@@ -186,6 +186,21 @@ onMounted(() => {
186 } 186 }
187 }) 187 })
188 188
189 const pxPerFrame = 18
190 let scrollDirection = 0
191 let scrollRaf = 0
192
193 function tickScroll() {
194 if (!scrollDirection) return
195 activeScrollTarget.scrollBy({ top: scrollDirection * pxPerFrame })
196 scrollRaf = requestAnimationFrame(tickScroll)
197 }
198
199 function stopScroll() {
200 scrollDirection = 0
201 cancelAnimationFrame(scrollRaf)
202 }
203
189 useEventListener(document, 'keydown', (e: KeyboardEvent) => { 204 useEventListener(document, 'keydown', (e: KeyboardEvent) => {
190 if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp' && e.key !== 'Escape') return 205 if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp' && e.key !== 'Escape') return
191 206
@@ -195,9 +210,19 @@ onMounted(() => {
195 } 210 }
196 211
197 e.preventDefault() 212 e.preventDefault()
198 activeScrollTarget.scrollBy({ top: e.key === 'ArrowDown' ? 60 : -60, behavior: 'smooth' }) 213 const dir = e.key === 'ArrowDown' ? 1 : -1
214 if (scrollDirection === dir) return
215 scrollDirection = dir
216 cancelAnimationFrame(scrollRaf)
217 scrollRaf = requestAnimationFrame(tickScroll)
199 }) 218 })
200 219
220 useEventListener(document, 'keyup', (e: KeyboardEvent) => {
221 if (e.key === 'ArrowDown' || e.key === 'ArrowUp') stopScroll()
222 })
223
224 onUnmounted(stopScroll)
225
201 // Close home NavScreen on outside click 226 // Close home NavScreen on outside click
202 useEventListener(document, 'click', (e: Event) => { 227 useEventListener(document, 'click', (e: Event) => {
203 if (!isHome.value) return 228 if (!isHome.value) return
docs/.vitepress/theme/styles/style.scss +33
@@ -1406,3 +1406,36 @@ table tr:nth-child(odd) {
1406 opacity: 0 !important; 1406 opacity: 0 !important;
1407 } 1407 }
1408} 1408}
1409
1410/* Icon tooltips (hover on desktop, tap on mobile) */
1411.icon-tip {
1412 position: relative;
1413 display: inline-block;
1414 vertical-align: middle;
1415 cursor: help;
1416
1417 &::after {
1418 content: attr(data-tip);
1419 position: absolute;
1420 bottom: calc(100% + 6px);
1421 left: 50%;
1422 transform: translateX(-50%);
1423 padding: 4px 8px;
1424 border-radius: 6px;
1425 background: var(--vp-c-bg-elv);
1426 color: var(--vp-c-text-1);
1427 font-size: 12px;
1428 line-height: 1.4;
1429 white-space: nowrap;
1430 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
1431 pointer-events: none;
1432 opacity: 0;
1433 transition: opacity 0.15s;
1434 z-index: 10;
1435 }
1436
1437 &:hover::after,
1438 &:focus::after {
1439 opacity: 1;
1440 }
1441}