Commit 319fe54de3
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +72
| @@ -27,6 +27,7 @@ import { | |||
| 27 | watchEffect | 27 | watchEffect |
| 28 | } from 'vue' | 28 | } from 'vue' |
| 29 | import { sidebar } from '../configs/constants' | 29 | import { sidebar } from '../configs/constants' |
| 30 | import { useBookmarks, BOOKMARK_CHANGE_EVENT } from './composables/useBookmarks' | ||
| 30 | import AnnouncementPill from './components/AnnouncementPill.vue' | 31 | import AnnouncementPill from './components/AnnouncementPill.vue' |
| 31 | import SiteFooter from './components/SiteFooter.vue' | 32 | import SiteFooter from './components/SiteFooter.vue' |
| 32 | import NotFoundComponent from './components/NotFound.vue' | 33 | import NotFoundComponent from './components/NotFound.vue' |
| @@ -38,6 +39,7 @@ import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math' | |||
| 38 | 39 | ||
| 39 | const route = useRoute() | 40 | const route = useRoute() |
| 40 | const { frontmatter, isDark, site, theme } = useData() | 41 | const { frontmatter, isDark, site, theme } = useData() |
| 42 | const { isBookmarked, toggle: bookmarkToggle } = useBookmarks() | ||
| 41 | const { Layout } = DefaultTheme | 43 | const { Layout } = DefaultTheme |
| 42 | 44 | ||
| 43 | // Home sidebar menu | 45 | // Home sidebar menu |
| @@ -613,14 +615,79 @@ const setupOutlineFollow = () => { | |||
| 613 | followActiveOutlineLink() | 615 | followActiveOutlineLink() |
| 614 | } | 616 | } |
| 615 | 617 | ||
| 618 | const BOOKMARK_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/></svg>` | ||
| 619 | |||
| 620 | function syncTocBookmarkStates() { | ||
| 621 | const path = route.path | ||
| 622 | document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn => { | ||
| 623 | const anchor = btn.dataset.anchor ?? '' | ||
| 624 | btn.classList.toggle('is-bookmarked', isBookmarked(anchor, path)) | ||
| 625 | }) | ||
| 626 | } | ||
| 627 | |||
| 628 | function addBookmarkBtnToLi(li: HTMLElement, path: string) { | ||
| 629 | if (li.querySelector('.toc-bookmark-btn')) return | ||
| 630 | |||
| 631 | const link = li.querySelector<HTMLAnchorElement>(':scope > .outline-link') | ||
| 632 | if (!link) return | ||
| 633 | |||
| 634 | const hrefAttr = link.getAttribute('href') ?? '' | ||
| 635 | const anchor = hrefAttr.startsWith('#') ? hrefAttr.slice(1) : hrefAttr | ||
| 636 | const title = link.textContent?.trim() ?? '' | ||
| 637 | if (!anchor || !title) return | ||
| 638 | |||
| 639 | const btn = document.createElement('button') | ||
| 640 | btn.className = 'toc-bookmark-btn' | ||
| 641 | btn.setAttribute('aria-label', `Bookmark "${title}"`) | ||
| 642 | btn.dataset.anchor = anchor | ||
| 643 | btn.innerHTML = BOOKMARK_SVG | ||
| 644 | |||
| 645 | if (isBookmarked(anchor, path)) btn.classList.add('is-bookmarked') | ||
| 646 | |||
| 647 | btn.addEventListener('click', (e) => { | ||
| 648 | e.preventDefault() | ||
| 649 | e.stopPropagation() | ||
| 650 | bookmarkToggle({ anchor, title, path }) | ||
| 651 | btn.classList.toggle('is-bookmarked', isBookmarked(anchor, path)) | ||
| 652 | }) | ||
| 653 | |||
| 654 | li.appendChild(btn) | ||
| 655 | } | ||
| 656 | |||
| 657 | let tocMutationObserver: MutationObserver | null = null | ||
| 658 | let tocRaf = 0 | ||
| 659 | |||
| 660 | function scanTocItems(path: string) { | ||
| 661 | // Desktop sidebar — VPDocOutlineItem is called with :root="true" | ||
| 662 | document.querySelectorAll<HTMLElement>('.VPDocOutlineItem.root > li').forEach(li => addBookmarkBtnToLi(li, path)) | ||
| 663 | // Mobile dropdown — VPDocOutlineItem is called without root prop, so the ul gets class "nested" | ||
| 664 | document.querySelectorAll<HTMLElement>('.VPLocalNavOutlineDropdown .outline > .VPDocOutlineItem > li').forEach(li => addBookmarkBtnToLi(li, path)) | ||
| 665 | } | ||
| 666 | |||
| 667 | function setupTocBookmarks() { | ||
| 668 | const path = route.path | ||
| 669 | document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn => btn.remove()) | ||
| 670 | scanTocItems(path) | ||
| 671 | |||
| 672 | // Mobile dropdown items are v-if rendered on open — watch for them being added | ||
| 673 | tocMutationObserver?.disconnect() | ||
| 674 | tocMutationObserver = new MutationObserver(() => { | ||
| 675 | cancelAnimationFrame(tocRaf) | ||
| 676 | tocRaf = requestAnimationFrame(() => scanTocItems(route.path)) | ||
| 677 | }) | ||
| 678 | tocMutationObserver.observe(document.body, { childList: true, subtree: true }) | ||
| 679 | } | ||
| 680 | |||
| 616 | onMounted(tryOpenAnchoredContent) | 681 | onMounted(tryOpenAnchoredContent) |
| 617 | onMounted(rewriteAnchorLinksDeferred) | 682 | onMounted(rewriteAnchorLinksDeferred) |
| 618 | onMounted(() => nextTick(setupOutlineFollow)) | 683 | onMounted(() => nextTick(setupOutlineFollow)) |
| 684 | onMounted(() => nextTick(setupTocBookmarks)) | ||
| 619 | watch(() => route.data, () => { | 685 | watch(() => route.data, () => { |
| 620 | void tryOpenAnchoredContent() | 686 | void tryOpenAnchoredContent() |
| 621 | rewriteAnchorLinksDeferred() | 687 | rewriteAnchorLinksDeferred() |
| 622 | nextTick(setupOutlineFollow) | 688 | nextTick(setupOutlineFollow) |
| 623 | nextTick(setupManualCopyButtons) | 689 | nextTick(setupManualCopyButtons) |
| 690 | nextTick(setupTocBookmarks) | ||
| 624 | }, { flush: 'post' }) | 691 | }, { flush: 'post' }) |
| 625 | watch(() => route.query, () => { | 692 | watch(() => route.query, () => { |
| 626 | void tryOpenAnchoredContent() | 693 | void tryOpenAnchoredContent() |
| @@ -984,6 +1051,8 @@ watch( | |||
| 984 | onMounted(() => { | 1051 | onMounted(() => { |
| 985 | if (import.meta.env.SSR) return | 1052 | if (import.meta.env.SSR) return |
| 986 | 1053 | ||
| 1054 | window.addEventListener(BOOKMARK_CHANGE_EVENT, syncTocBookmarkStates) | ||
| 1055 | |||
| 987 | initTitleOnly() | 1056 | initTitleOnly() |
| 988 | nextTick(setupManualCopyButtons) | 1057 | nextTick(setupManualCopyButtons) |
| 989 | 1058 | ||
| @@ -1190,8 +1259,11 @@ onMounted(() => { | |||
| 1190 | onUnmounted(() => { | 1259 | onUnmounted(() => { |
| 1191 | outlineFollowObserver?.disconnect() | 1260 | outlineFollowObserver?.disconnect() |
| 1192 | copyButtonObserver?.disconnect() | 1261 | copyButtonObserver?.disconnect() |
| 1262 | tocMutationObserver?.disconnect() | ||
| 1193 | cancelAnimationFrame(outlineFollowRaf) | 1263 | cancelAnimationFrame(outlineFollowRaf) |
| 1264 | cancelAnimationFrame(tocRaf) | ||
| 1194 | takodachiDisable.value && takodachiDisable.value() | 1265 | takodachiDisable.value && takodachiDisable.value() |
| 1266 | window.removeEventListener(BOOKMARK_CHANGE_EVENT, syncTocBookmarkStates) | ||
| 1195 | }) | 1267 | }) |
| 1196 | </script> | 1268 | </script> |
| 1197 | 1269 | ||
docs/.vitepress/theme/components/BookmarksPanel.vue added +509
| @@ -0,0 +1,509 @@ | |||
| 1 | <script setup lang="ts"> | ||
| 2 | import { onClickOutside } from '@vueuse/core' | ||
| 3 | import { Bookmark, BookMarked, Hash, X } from 'lucide-vue-next' | ||
| 4 | import { computed, ref } from 'vue' | ||
| 5 | import type { DefaultTheme } from 'vitepress/theme' | ||
| 6 | import type { HomeCard } from '../../configs/constants' | ||
| 7 | import { homeCards, sidebar } from '../../configs/constants' | ||
| 8 | import type { Bookmark as BookmarkItem } from '../composables/useBookmarks' | ||
| 9 | import { useBookmarks } from '../composables/useBookmarks' | ||
| 10 | |||
| 11 | const ICON_SIZE = 18 | ||
| 12 | const ICON_STROKE = 2 | ||
| 13 | |||
| 14 | const { bookmarks, remove } = useBookmarks() | ||
| 15 | const isOpen = ref(false) | ||
| 16 | const wrapperRef = ref<HTMLElement>() | ||
| 17 | const scrollRef = ref<HTMLElement>() | ||
| 18 | const showFade = ref(true) | ||
| 19 | |||
| 20 | onClickOutside(wrapperRef, () => { | ||
| 21 | isOpen.value = false | ||
| 22 | }) | ||
| 23 | |||
| 24 | function onScroll() { | ||
| 25 | if (!scrollRef.value) return | ||
| 26 | const { scrollTop, scrollHeight, clientHeight } = scrollRef.value | ||
| 27 | showFade.value = scrollTop + clientHeight < scrollHeight - 4 | ||
| 28 | } | ||
| 29 | |||
| 30 | function flattenSidebarPaths(items: DefaultTheme.SidebarItem[]): string[] { | ||
| 31 | const paths: string[] = [] | ||
| 32 | for (const item of items) { | ||
| 33 | if (item.link) paths.push(item.link) | ||
| 34 | if (item.items) paths.push(...flattenSidebarPaths(item.items)) | ||
| 35 | } | ||
| 36 | return paths | ||
| 37 | } | ||
| 38 | |||
| 39 | const sidebarPathOrder = flattenSidebarPaths(Array.isArray(sidebar) ? sidebar : Object.values(sidebar).flat()) | ||
| 40 | |||
| 41 | function sidebarIndex(path: string): number { | ||
| 42 | const exact = sidebarPathOrder.indexOf(path) | ||
| 43 | return exact !== -1 ? exact : Infinity | ||
| 44 | } | ||
| 45 | |||
| 46 | function cardIconToClass(icon: string): string { | ||
| 47 | const m = icon.match(/^:(.+):$/) | ||
| 48 | if (!m) return 'i-lucide:file-text' | ||
| 49 | const name = m[1] | ||
| 50 | const dash = name.indexOf('-') | ||
| 51 | if (dash === -1) return 'i-lucide:file-text' | ||
| 52 | return `i-${name.slice(0, dash)}:${name.slice(dash + 1)}` | ||
| 53 | } | ||
| 54 | |||
| 55 | function getPageCard(path: string): HomeCard | null { | ||
| 56 | let best: HomeCard | null = null | ||
| 57 | let bestLen = 0 | ||
| 58 | for (const card of homeCards) { | ||
| 59 | if ((path === card.link || path.startsWith(card.link + '/')) && card.link.length > bestLen) { | ||
| 60 | best = card | ||
| 61 | bestLen = card.link.length | ||
| 62 | } | ||
| 63 | } | ||
| 64 | return best | ||
| 65 | } | ||
| 66 | |||
| 67 | type PageGroup = { path: string; card: HomeCard | null; items: BookmarkItem[] } | ||
| 68 | type TopLevelEntry = { type: 'page'; path: string; card: HomeCard | null; items: BookmarkItem[] } | ||
| 69 | type FolderEntry = { type: 'folder'; section: string; parentCard: HomeCard | null; pages: PageGroup[] } | ||
| 70 | type GroupEntry = TopLevelEntry | FolderEntry | ||
| 71 | |||
| 72 | const grouped = computed((): GroupEntry[] => { | ||
| 73 | // Collect bookmarks by path | ||
| 74 | const byPath = new Map<string, BookmarkItem[]>() | ||
| 75 | for (const bm of bookmarks.value) { | ||
| 76 | if (!byPath.has(bm.path)) byPath.set(bm.path, []) | ||
| 77 | byPath.get(bm.path)!.push(bm) | ||
| 78 | } | ||
| 79 | |||
| 80 | // Separate into top-level pages and folder sub-pages (those with a section field) | ||
| 81 | const topPages: string[] = [] | ||
| 82 | const folderMap = new Map<string, string[]>() // section → paths | ||
| 83 | |||
| 84 | for (const path of byPath.keys()) { | ||
| 85 | const card = getPageCard(path) | ||
| 86 | if (card?.section) { | ||
| 87 | if (!folderMap.has(card.section)) folderMap.set(card.section, []) | ||
| 88 | folderMap.get(card.section)!.push(path) | ||
| 89 | } else { | ||
| 90 | topPages.push(path) | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | // Sort top-level pages by exact sidebar position | ||
| 95 | topPages.sort((a, b) => sidebarIndex(a) - sidebarIndex(b)) | ||
| 96 | |||
| 97 | // Build folder entries, sorted by parent card's sidebar position | ||
| 98 | const folderEntries: FolderEntry[] = [...folderMap.entries()] | ||
| 99 | .map(([section, paths]) => { | ||
| 100 | const parentCard = homeCards.find(c => c.title === section && !c.section) ?? null | ||
| 101 | const sortedPages = [...paths] | ||
| 102 | .sort((a, b) => sidebarIndex(a) - sidebarIndex(b)) | ||
| 103 | .map(path => ({ path, card: getPageCard(path), items: byPath.get(path)! })) | ||
| 104 | return { type: 'folder' as const, section, parentCard, pages: sortedPages } | ||
| 105 | }) | ||
| 106 | .sort((a, b) => sidebarIndex(a.parentCard?.link ?? '') - sidebarIndex(b.parentCard?.link ?? '')) | ||
| 107 | |||
| 108 | // Merge top-level and folder entries in sidebar order | ||
| 109 | const topEntries: TopLevelEntry[] = topPages.map(path => ({ | ||
| 110 | type: 'page' as const, | ||
| 111 | path, | ||
| 112 | card: getPageCard(path), | ||
| 113 | items: byPath.get(path)! | ||
| 114 | })) | ||
| 115 | |||
| 116 | return [...topEntries, ...folderEntries].sort((a, b) => { | ||
| 117 | const ai = a.type === 'page' ? sidebarIndex(a.path) : sidebarIndex(a.parentCard?.link ?? '') | ||
| 118 | const bi = b.type === 'page' ? sidebarIndex(b.path) : sidebarIndex(b.parentCard?.link ?? '') | ||
| 119 | return ai - bi | ||
| 120 | }) | ||
| 121 | }) | ||
| 122 | </script> | ||
| 123 | |||
| 124 | <template> | ||
| 125 | <div ref="wrapperRef" class="bookmarks-wrapper"> | ||
| 126 | <button | ||
| 127 | type="button" | ||
| 128 | class="bookmarks-btn" | ||
| 129 | aria-label="Bookmarks" | ||
| 130 | :aria-expanded="isOpen" | ||
| 131 | @click="isOpen = !isOpen" | ||
| 132 | > | ||
| 133 | <Bookmark :size="ICON_SIZE" :stroke-width="ICON_STROKE" /> | ||
| 134 | </button> | ||
| 135 | |||
| 136 | <Transition name="bookmarks-panel"> | ||
| 137 | <div v-if="isOpen" class="bookmarks-panel" role="dialog" aria-label="Bookmarks"> | ||
| 138 | <div class="bookmarks-mobile-header"> | ||
| 139 | <span class="bookmarks-mobile-title">Bookmarks</span> | ||
| 140 | <button type="button" class="bookmarks-mobile-close" aria-label="Close" @click="isOpen = false"> | ||
| 141 | <X :size="18" :stroke-width="2" /> | ||
| 142 | </button> | ||
| 143 | </div> | ||
| 144 | <div | ||
| 145 | ref="scrollRef" | ||
| 146 | class="bookmarks-scroll" | ||
| 147 | @scroll.passive="onScroll" | ||
| 148 | > | ||
| 149 | <div v-if="bookmarks.length === 0" class="bookmarks-empty"> | ||
| 150 | <BookMarked :size="128" :stroke-width="1" class="bookmarks-empty-icon" /> | ||
| 151 | <p class="bookmarks-empty-hint">Click the bookmark icon next to any heading in the table of contents to save it here.</p> | ||
| 152 | </div> | ||
| 153 | <div v-else class="bookmarks-groups"> | ||
| 154 | <template v-for="group in grouped" :key="group.type === 'page' ? group.path : group.section"> | ||
| 155 | |||
| 156 | <!-- Top-level page (no folder) --> | ||
| 157 | <div v-if="group.type === 'page'" class="bookmarks-group"> | ||
| 158 | <h3 class="bookmarks-group-title"> | ||
| 159 | <span v-if="group.card" :class="cardIconToClass(group.card.icon)" class="bookmarks-group-icon" /> | ||
| 160 | <span v-else class="i-lucide:file-text bookmarks-group-icon" /> | ||
| 161 | <span class="bookmarks-group-text">{{ group.card?.title ?? group.path }}</span> | ||
| 162 | </h3> | ||
| 163 | <ul class="bookmarks-list"> | ||
| 164 | <li v-for="bm in group.items" :key="bm.anchor" class="bookmarks-item"> | ||
| 165 | <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false"> | ||
| 166 | <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" /> | ||
| 167 | {{ bm.title }} | ||
| 168 | </a> | ||
| 169 | <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)"> | ||
| 170 | <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg> | ||
| 171 | </button> | ||
| 172 | </li> | ||
| 173 | </ul> | ||
| 174 | </div> | ||
| 175 | |||
| 176 | <!-- Folder group (e.g. Guides, Glossary) --> | ||
| 177 | <div v-else class="bookmarks-group"> | ||
| 178 | <h3 class="bookmarks-group-title"> | ||
| 179 | <span v-if="group.parentCard" :class="cardIconToClass(group.parentCard.icon)" class="bookmarks-group-icon" /> | ||
| 180 | <span v-else class="i-lucide:folder bookmarks-group-icon" /> | ||
| 181 | <span class="bookmarks-group-text">{{ group.section }}</span> | ||
| 182 | </h3> | ||
| 183 | <div v-for="page in group.pages" :key="page.path" class="bookmarks-sub-group"> | ||
| 184 | <h4 class="bookmarks-sub-title">{{ page.card?.title ?? page.path }}</h4> | ||
| 185 | <ul class="bookmarks-list"> | ||
| 186 | <li v-for="bm in page.items" :key="bm.anchor" class="bookmarks-item"> | ||
| 187 | <a class="bookmarks-item-link" :href="bm.path + '#' + bm.anchor" @click="isOpen = false"> | ||
| 188 | <Hash :size="12" :stroke-width="2" class="bookmarks-item-icon" /> | ||
| 189 | {{ bm.title }} | ||
| 190 | </a> | ||
| 191 | <button type="button" class="bookmarks-item-remove" :aria-label="`Remove bookmark for ${bm.title}`" @click.stop="remove(bm.anchor, bm.path)"> | ||
| 192 | <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg> | ||
| 193 | </button> | ||
| 194 | </li> | ||
| 195 | </ul> | ||
| 196 | </div> | ||
| 197 | </div> | ||
| 198 | |||
| 199 | </template> | ||
| 200 | </div> | ||
| 201 | </div> | ||
| 202 | <Transition name="bookmarks-fade"> | ||
| 203 | <div v-if="showFade && bookmarks.length > 0" class="bookmarks-fade-overlay" /> | ||
| 204 | </Transition> | ||
| 205 | </div> | ||
| 206 | </Transition> | ||
| 207 | </div> | ||
| 208 | </template> | ||
| 209 | |||
| 210 | <style scoped> | ||
| 211 | .bookmarks-wrapper { | ||
| 212 | position: relative; | ||
| 213 | width: 100%; | ||
| 214 | height: 100%; | ||
| 215 | display: flex; | ||
| 216 | align-items: center; | ||
| 217 | justify-content: center; | ||
| 218 | } | ||
| 219 | |||
| 220 | .bookmarks-btn { | ||
| 221 | display: flex; | ||
| 222 | align-items: center; | ||
| 223 | justify-content: center; | ||
| 224 | width: 100%; | ||
| 225 | height: 100%; | ||
| 226 | color: var(--vp-c-text-1); | ||
| 227 | opacity: 0.55; | ||
| 228 | transition: | ||
| 229 | opacity 0.25s, | ||
| 230 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 231 | } | ||
| 232 | |||
| 233 | .bookmarks-btn:hover { opacity: 1; } | ||
| 234 | .bookmarks-btn:active { transform: scale(0.94); } | ||
| 235 | |||
| 236 | .bookmarks-panel { | ||
| 237 | position: absolute; | ||
| 238 | top: calc(var(--vp-nav-height) / 2 + 20px); | ||
| 239 | right: 0; | ||
| 240 | z-index: 100; | ||
| 241 | width: 282px; | ||
| 242 | background-color: var(--vp-c-bg-elv); | ||
| 243 | border: 1px solid var(--vp-c-divider); | ||
| 244 | border-radius: 12px; | ||
| 245 | box-shadow: var(--vp-shadow-3); | ||
| 246 | transition: background-color 0.5s; | ||
| 247 | transform-origin: top right; | ||
| 248 | overflow: hidden; | ||
| 249 | } | ||
| 250 | |||
| 251 | .bookmarks-scroll { | ||
| 252 | height: 400px; | ||
| 253 | overflow-y: auto; | ||
| 254 | overflow-x: hidden; | ||
| 255 | overscroll-behavior: contain; | ||
| 256 | padding: 20px; | ||
| 257 | scrollbar-width: none; | ||
| 258 | -ms-overflow-style: none; | ||
| 259 | } | ||
| 260 | |||
| 261 | .bookmarks-scroll::-webkit-scrollbar { | ||
| 262 | display: none; | ||
| 263 | } | ||
| 264 | |||
| 265 | .bookmarks-fade-overlay { | ||
| 266 | position: absolute; | ||
| 267 | bottom: 0; | ||
| 268 | left: 0; | ||
| 269 | right: 0; | ||
| 270 | height: 56px; | ||
| 271 | pointer-events: none; | ||
| 272 | background: linear-gradient( | ||
| 273 | to bottom, | ||
| 274 | transparent, | ||
| 275 | var(--vp-c-bg-elv) | ||
| 276 | ); | ||
| 277 | border-radius: 0 0 12px 12px; | ||
| 278 | } | ||
| 279 | |||
| 280 | .bookmarks-empty { | ||
| 281 | display: flex; | ||
| 282 | flex-direction: column; | ||
| 283 | align-items: center; | ||
| 284 | justify-content: center; | ||
| 285 | min-height: 360px; | ||
| 286 | gap: 10px; | ||
| 287 | text-align: center; | ||
| 288 | overflow: hidden; | ||
| 289 | } | ||
| 290 | |||
| 291 | .bookmarks-empty-icon { | ||
| 292 | color: var(--vp-c-text-3); | ||
| 293 | flex: none; | ||
| 294 | } | ||
| 295 | |||
| 296 | .bookmarks-empty-hint { | ||
| 297 | font-size: 13px; | ||
| 298 | color: var(--vp-c-text-2); | ||
| 299 | line-height: 1.6; | ||
| 300 | margin: 0; | ||
| 301 | white-space: normal; | ||
| 302 | overflow-wrap: break-word; | ||
| 303 | word-break: break-word; | ||
| 304 | } | ||
| 305 | |||
| 306 | .bookmarks-groups { | ||
| 307 | display: flex; | ||
| 308 | flex-direction: column; | ||
| 309 | gap: 8px; | ||
| 310 | } | ||
| 311 | |||
| 312 | .bookmarks-sub-group { | ||
| 313 | margin-top: 4px; | ||
| 314 | } | ||
| 315 | |||
| 316 | .bookmarks-sub-title { | ||
| 317 | font-size: 11px; | ||
| 318 | font-weight: 600; | ||
| 319 | letter-spacing: 0; | ||
| 320 | color: var(--vp-c-text-3); | ||
| 321 | margin: 6px 0 2px; | ||
| 322 | padding: 0 6px 4px; | ||
| 323 | user-select: none; | ||
| 324 | border-bottom: 1px solid #525252; | ||
| 325 | } | ||
| 326 | |||
| 327 | .bookmarks-group-title { | ||
| 328 | display: flex; | ||
| 329 | align-items: center; | ||
| 330 | gap: 6px; | ||
| 331 | font-size: 16px; | ||
| 332 | font-weight: 500; | ||
| 333 | color: var(--vp-c-text-1); | ||
| 334 | margin: 0 0 2px; | ||
| 335 | padding: 2px 0; | ||
| 336 | user-select: none; | ||
| 337 | min-width: 0; | ||
| 338 | } | ||
| 339 | |||
| 340 | .bookmarks-group-icon { | ||
| 341 | font-size: 16px; | ||
| 342 | color: var(--vp-c-text-1); | ||
| 343 | flex: none; | ||
| 344 | } | ||
| 345 | |||
| 346 | .bookmarks-group-text { | ||
| 347 | flex: 1; | ||
| 348 | min-width: 0; | ||
| 349 | overflow: hidden; | ||
| 350 | white-space: nowrap; | ||
| 351 | text-overflow: ellipsis; | ||
| 352 | } | ||
| 353 | |||
| 354 | .bookmarks-list { | ||
| 355 | list-style: none; | ||
| 356 | padding: 0; | ||
| 357 | margin: 0; | ||
| 358 | } | ||
| 359 | |||
| 360 | .bookmarks-item { | ||
| 361 | display: flex; | ||
| 362 | align-items: center; | ||
| 363 | border-radius: 6px; | ||
| 364 | transition: background-color 0.15s; | ||
| 365 | } | ||
| 366 | |||
| 367 | .bookmarks-item:hover { | ||
| 368 | background: var(--vp-c-default-soft); | ||
| 369 | } | ||
| 370 | |||
| 371 | .bookmarks-item-link { | ||
| 372 | display: flex; | ||
| 373 | align-items: center; | ||
| 374 | gap: 5px; | ||
| 375 | flex: 1; | ||
| 376 | padding: 4px 6px; | ||
| 377 | font-size: 13px; | ||
| 378 | color: var(--vp-c-text-2); | ||
| 379 | text-decoration: none; | ||
| 380 | white-space: nowrap; | ||
| 381 | overflow: hidden; | ||
| 382 | text-overflow: ellipsis; | ||
| 383 | transition: color 0.15s; | ||
| 384 | min-width: 0; | ||
| 385 | } | ||
| 386 | |||
| 387 | .bookmarks-item-link:hover { | ||
| 388 | color: var(--vp-c-brand-1); | ||
| 389 | } | ||
| 390 | |||
| 391 | .bookmarks-item-icon { | ||
| 392 | flex: none; | ||
| 393 | color: var(--vp-c-text-3); | ||
| 394 | } | ||
| 395 | |||
| 396 | .bookmarks-item-remove { | ||
| 397 | flex: none; | ||
| 398 | display: flex; | ||
| 399 | align-items: center; | ||
| 400 | justify-content: center; | ||
| 401 | width: 20px; | ||
| 402 | height: 20px; | ||
| 403 | margin-right: 4px; | ||
| 404 | border: none; | ||
| 405 | background: transparent; | ||
| 406 | color: var(--vp-c-text-3); | ||
| 407 | cursor: pointer; | ||
| 408 | transition: color 0.15s; | ||
| 409 | } | ||
| 410 | |||
| 411 | .bookmarks-item-remove:hover { | ||
| 412 | color: var(--vp-c-text-1); | ||
| 413 | } | ||
| 414 | |||
| 415 | .bookmarks-panel-enter-active, | ||
| 416 | .bookmarks-panel-leave-active { | ||
| 417 | transition: opacity 0.15s, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1); | ||
| 418 | } | ||
| 419 | |||
| 420 | .bookmarks-panel-enter-from, | ||
| 421 | .bookmarks-panel-leave-to { | ||
| 422 | opacity: 0; | ||
| 423 | transform: scale(0.95) translateY(-4px); | ||
| 424 | } | ||
| 425 | |||
| 426 | .bookmarks-fade-enter-active, | ||
| 427 | .bookmarks-fade-leave-active { | ||
| 428 | transition: opacity 0.2s; | ||
| 429 | } | ||
| 430 | |||
| 431 | .bookmarks-fade-enter-from, | ||
| 432 | .bookmarks-fade-leave-to { | ||
| 433 | opacity: 0; | ||
| 434 | } | ||
| 435 | |||
| 436 | .bookmarks-mobile-header { | ||
| 437 | display: none; | ||
| 438 | } | ||
| 439 | |||
| 440 | @media (max-width: 767px) { | ||
| 441 | .bookmarks-panel { | ||
| 442 | position: fixed; | ||
| 443 | top: 0; | ||
| 444 | left: 0; | ||
| 445 | right: 0; | ||
| 446 | bottom: 0; | ||
| 447 | width: 100%; | ||
| 448 | height: 100%; | ||
| 449 | border-radius: 0; | ||
| 450 | border: none; | ||
| 451 | z-index: 9999; | ||
| 452 | transform-origin: center top; | ||
| 453 | display: flex; | ||
| 454 | flex-direction: column; | ||
| 455 | } | ||
| 456 | |||
| 457 | .bookmarks-scroll { | ||
| 458 | flex: 1; | ||
| 459 | height: auto; | ||
| 460 | min-height: 0; | ||
| 461 | } | ||
| 462 | |||
| 463 | .bookmarks-empty { | ||
| 464 | min-height: 0; | ||
| 465 | flex: 1; | ||
| 466 | } | ||
| 467 | |||
| 468 | .bookmarks-mobile-header { | ||
| 469 | display: flex; | ||
| 470 | align-items: center; | ||
| 471 | justify-content: space-between; | ||
| 472 | height: 56px; | ||
| 473 | flex-shrink: 0; | ||
| 474 | padding: 0 20px; | ||
| 475 | border-bottom: 1px solid var(--vp-c-divider); | ||
| 476 | } | ||
| 477 | |||
| 478 | .bookmarks-mobile-title { | ||
| 479 | font-size: 16px; | ||
| 480 | font-weight: 600; | ||
| 481 | color: var(--vp-c-text-1); | ||
| 482 | } | ||
| 483 | |||
| 484 | .bookmarks-mobile-close { | ||
| 485 | display: flex; | ||
| 486 | align-items: center; | ||
| 487 | justify-content: center; | ||
| 488 | width: 32px; | ||
| 489 | height: 32px; | ||
| 490 | border-radius: 8px; | ||
| 491 | border: none; | ||
| 492 | background: transparent; | ||
| 493 | color: var(--vp-c-text-2); | ||
| 494 | cursor: pointer; | ||
| 495 | transition: background-color 0.15s, color 0.15s; | ||
| 496 | } | ||
| 497 | |||
| 498 | .bookmarks-mobile-close:hover { | ||
| 499 | background: var(--vp-c-default-soft); | ||
| 500 | color: var(--vp-c-text-1); | ||
| 501 | } | ||
| 502 | |||
| 503 | .bookmarks-panel-enter-from, | ||
| 504 | .bookmarks-panel-leave-to { | ||
| 505 | opacity: 0; | ||
| 506 | transform: translateY(8px); | ||
| 507 | } | ||
| 508 | } | ||
| 509 | </style> | ||
docs/.vitepress/theme/components/NavActions.vue +30 −2
| @@ -8,6 +8,7 @@ import { inject } from 'vue' | |||
| 8 | import { navActions } from '../navActions' | 8 | import { navActions } from '../navActions' |
| 9 | import { openSearch } from '../searchState' | 9 | import { openSearch } from '../searchState' |
| 10 | import NolebaseEnhancedReadabilitiesMenu from './settings/Menu.vue' | 10 | import NolebaseEnhancedReadabilitiesMenu from './settings/Menu.vue' |
| 11 | import BookmarksPanel from './BookmarksPanel.vue' | ||
| 11 | 12 | ||
| 12 | const ICON_SIZE = 18 | 13 | const ICON_SIZE = 18 |
| 13 | const ICON_STROKE = 2 | 14 | const ICON_STROKE = 2 |
| @@ -19,6 +20,10 @@ const toggleAppearance = inject<() => void>('toggle-appearance', () => { | |||
| 19 | </script> | 20 | </script> |
| 20 | 21 | ||
| 21 | <template> | 22 | <template> |
| 23 | <div class="nav-actions-container"> | ||
| 24 | <div class="nav-bookmark-mobile"> | ||
| 25 | <BookmarksPanel /> | ||
| 26 | </div> | ||
| 22 | <div class="nav-actions" role="group" aria-label="Site actions"> | 27 | <div class="nav-actions" role="group" aria-label="Site actions"> |
| 23 | <template v-for="(action, i) in navActions" :key="i"> | 28 | <template v-for="(action, i) in navActions" :key="i"> |
| 24 | <div class="nav-action" :class="`nav-action--${action.type}`"> | 29 | <div class="nav-action" :class="`nav-action--${action.type}`"> |
| @@ -53,12 +58,33 @@ const toggleAppearance = inject<() => void>('toggle-appearance', () => { | |||
| 53 | /> | 58 | /> |
| 54 | 59 | ||
| 55 | <NolebaseEnhancedReadabilitiesMenu v-else-if="action.type === 'settings'" /> | 60 | <NolebaseEnhancedReadabilitiesMenu v-else-if="action.type === 'settings'" /> |
| 61 | <BookmarksPanel v-else-if="action.type === 'bookmarks'" /> | ||
| 56 | </div> | 62 | </div> |
| 57 | </template> | 63 | </template> |
| 58 | </div> | 64 | </div> |
| 65 | </div> | ||
| 59 | </template> | 66 | </template> |
| 60 | 67 | ||
| 61 | <style scoped> | 68 | <style scoped> |
| 69 | .nav-actions-container { | ||
| 70 | display: flex; | ||
| 71 | align-items: center; | ||
| 72 | } | ||
| 73 | |||
| 74 | .nav-bookmark-mobile { | ||
| 75 | display: flex; | ||
| 76 | align-items: center; | ||
| 77 | justify-content: center; | ||
| 78 | width: 36px; | ||
| 79 | height: var(--vp-nav-height); | ||
| 80 | } | ||
| 81 | |||
| 82 | @media (min-width: 768px) { | ||
| 83 | .nav-bookmark-mobile { | ||
| 84 | display: none; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 62 | .nav-actions { | 88 | .nav-actions { |
| 63 | display: none; | 89 | display: none; |
| 64 | align-items: center; | 90 | align-items: center; |
| @@ -137,14 +163,16 @@ const toggleAppearance = inject<() => void>('toggle-appearance', () => { | |||
| 137 | 163 | ||
| 138 | .nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button) { | 164 | .nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button) { |
| 139 | width: 100% !important; | 165 | width: 100% !important; |
| 140 | height: auto !important; | 166 | height: 100% !important; |
| 141 | padding: 0 !important; | 167 | padding: 0 !important; |
| 142 | display: flex !important; | 168 | display: flex !important; |
| 143 | justify-content: center !important; | 169 | justify-content: center !important; |
| 144 | align-items: center !important; | 170 | align-items: center !important; |
| 145 | color: var(--vp-c-text-1); | 171 | color: var(--vp-c-text-1); |
| 146 | opacity: 0.55; | 172 | opacity: 0.55; |
| 147 | transition: opacity 0.25s; | 173 | transition: |
| 174 | opacity 0.25s, | ||
| 175 | transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important; | ||
| 148 | } | 176 | } |
| 149 | .nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout:hover .button) { | 177 | .nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout:hover .button) { |
| 150 | opacity: 1; | 178 | opacity: 1; |
docs/.vitepress/theme/composables/useBookmarks.ts added +64
| @@ -0,0 +1,64 @@ | |||
| 1 | import { ref, watch } from 'vue' | ||
| 2 | |||
| 3 | export interface Bookmark { | ||
| 4 | title: string | ||
| 5 | anchor: string | ||
| 6 | path: string | ||
| 7 | } | ||
| 8 | |||
| 9 | const STORAGE_KEY = 'wotaku-bookmarks' | ||
| 10 | export const BOOKMARK_CHANGE_EVENT = 'wotaku-bookmarks-changed' | ||
| 11 | |||
| 12 | const bookmarks = ref<Bookmark[]>([]) | ||
| 13 | let initialized = false | ||
| 14 | |||
| 15 | function loadFromStorage(): Bookmark[] { | ||
| 16 | try { | ||
| 17 | return JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]') | ||
| 18 | } catch { | ||
| 19 | return [] | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | function saveToStorage(): void { | ||
| 24 | localStorage.setItem(STORAGE_KEY, JSON.stringify(bookmarks.value)) | ||
| 25 | } | ||
| 26 | |||
| 27 | if (typeof window !== 'undefined') { | ||
| 28 | watch(bookmarks, () => { | ||
| 29 | window.dispatchEvent(new CustomEvent(BOOKMARK_CHANGE_EVENT)) | ||
| 30 | }, { deep: true, flush: 'post' }) | ||
| 31 | } | ||
| 32 | |||
| 33 | export function useBookmarks() { | ||
| 34 | if (!initialized && typeof window !== 'undefined') { | ||
| 35 | initialized = true | ||
| 36 | bookmarks.value = loadFromStorage() | ||
| 37 | } | ||
| 38 | |||
| 39 | function isBookmarked(anchor: string, path: string): boolean { | ||
| 40 | return bookmarks.value.some(b => b.anchor === anchor && b.path === path) | ||
| 41 | } | ||
| 42 | |||
| 43 | function toggle(bookmark: Bookmark): void { | ||
| 44 | const idx = bookmarks.value.findIndex( | ||
| 45 | b => b.anchor === bookmark.anchor && b.path === bookmark.path | ||
| 46 | ) | ||
| 47 | if (idx >= 0) { | ||
| 48 | bookmarks.value.splice(idx, 1) | ||
| 49 | } else { | ||
| 50 | bookmarks.value.push(bookmark) | ||
| 51 | } | ||
| 52 | saveToStorage() | ||
| 53 | } | ||
| 54 | |||
| 55 | function remove(anchor: string, path: string): void { | ||
| 56 | const idx = bookmarks.value.findIndex(b => b.anchor === anchor && b.path === path) | ||
| 57 | if (idx >= 0) { | ||
| 58 | bookmarks.value.splice(idx, 1) | ||
| 59 | saveToStorage() | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | return { bookmarks, isBookmarked, toggle, remove } | ||
| 64 | } | ||
docs/.vitepress/theme/navActions.ts +6
| @@ -16,6 +16,10 @@ export interface NavSettingsAction extends NavActionBase { | |||
| 16 | type: 'settings' | 16 | type: 'settings' |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | export interface NavBookmarksAction extends NavActionBase { | ||
| 20 | type: 'bookmarks' | ||
| 21 | } | ||
| 22 | |||
| 19 | export interface NavLinkAction extends NavActionBase { | 23 | export interface NavLinkAction extends NavActionBase { |
| 20 | type: 'link' | 24 | type: 'link' |
| 21 | icon: string | 25 | icon: string |
| @@ -27,6 +31,7 @@ export type NavAction = | |||
| 27 | | NavSearchAction | 31 | | NavSearchAction |
| 28 | | NavAppearanceAction | 32 | | NavAppearanceAction |
| 29 | | NavSettingsAction | 33 | | NavSettingsAction |
| 34 | | NavBookmarksAction | ||
| 30 | | NavLinkAction | 35 | | NavLinkAction |
| 31 | 36 | ||
| 32 | export const navActions: NavAction[] = [ | 37 | export const navActions: NavAction[] = [ |
| @@ -44,5 +49,6 @@ export const navActions: NavAction[] = [ | |||
| 44 | link: 'https://discord.gg/vShRGx8ZBC', | 49 | link: 'https://discord.gg/vShRGx8ZBC', |
| 45 | label: 'Discord' | 50 | label: 'Discord' |
| 46 | }, | 51 | }, |
| 52 | { type: 'bookmarks' }, | ||
| 47 | { type: 'settings' } | 53 | { type: 'settings' } |
| 48 | ] | 54 | ] |
docs/.vitepress/theme/styles/style.scss +90
| @@ -1209,7 +1209,15 @@ table tr:nth-child(odd) { | |||
| 1209 | } | 1209 | } |
| 1210 | 1210 | ||
| 1211 | .VPDocOutlineItem.root > li { | 1211 | .VPDocOutlineItem.root > li { |
| 1212 | position: relative; | ||
| 1213 | |||
| 1214 | &:hover .toc-bookmark-btn, | ||
| 1215 | & .toc-bookmark-btn.is-bookmarked { | ||
| 1216 | opacity: 1; | ||
| 1217 | } | ||
| 1218 | |||
| 1212 | & > .outline-link { | 1219 | & > .outline-link { |
| 1220 | padding-right: 20px; | ||
| 1213 | @apply text-neutral-600/80 dark:text-neutral-300/80 transition-all | 1221 | @apply text-neutral-600/80 dark:text-neutral-300/80 transition-all |
| 1214 | dark:hover:text-neutral-300 dark:focus:text-neutral-300; | 1222 | dark:hover:text-neutral-300 dark:focus:text-neutral-300; |
| 1215 | 1223 | ||
| @@ -1242,12 +1250,94 @@ table tr:nth-child(odd) { | |||
| 1242 | } | 1250 | } |
| 1243 | } | 1251 | } |
| 1244 | 1252 | ||
| 1253 | .toc-bookmark-btn { | ||
| 1254 | position: absolute; | ||
| 1255 | right: 2px; | ||
| 1256 | top: 0; | ||
| 1257 | height: 32px; | ||
| 1258 | display: flex; | ||
| 1259 | align-items: center; | ||
| 1260 | justify-content: center; | ||
| 1261 | width: 16px; | ||
| 1262 | padding: 0; | ||
| 1263 | opacity: 0; | ||
| 1264 | border: none; | ||
| 1265 | background: transparent; | ||
| 1266 | cursor: pointer; | ||
| 1267 | color: var(--vp-c-text-2); | ||
| 1268 | line-height: 0; | ||
| 1269 | transition: opacity 0.2s, color 0.15s; | ||
| 1270 | |||
| 1271 | &.is-bookmarked { | ||
| 1272 | color: var(--vp-c-brand-1); | ||
| 1273 | |||
| 1274 | svg path { | ||
| 1275 | fill: currentColor; | ||
| 1276 | } | ||
| 1277 | } | ||
| 1278 | |||
| 1279 | &:hover { | ||
| 1280 | color: var(--vp-c-brand-1); | ||
| 1281 | } | ||
| 1282 | } | ||
| 1283 | |||
| 1245 | & > .VPDocOutlineItem { | 1284 | & > .VPDocOutlineItem { |
| 1246 | --uno: "border-l-2! border-neutral-100 dark:border-neutral-600 pl-4"; | 1285 | --uno: "border-l-2! border-neutral-100 dark:border-neutral-600 pl-4"; |
| 1247 | } | 1286 | } |
| 1248 | } | 1287 | } |
| 1249 | } | 1288 | } |
| 1250 | 1289 | ||
| 1290 | .VPLocalNavOutlineDropdown .outline > .VPDocOutlineItem > li { | ||
| 1291 | position: relative; | ||
| 1292 | |||
| 1293 | & > .outline-link { | ||
| 1294 | padding-right: 28px !important; | ||
| 1295 | overflow: hidden !important; | ||
| 1296 | text-overflow: ellipsis !important; | ||
| 1297 | white-space: nowrap !important; | ||
| 1298 | } | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | .VPLocalNavOutlineDropdown .outline { | ||
| 1302 | |||
| 1303 | .toc-bookmark-btn { | ||
| 1304 | position: absolute; | ||
| 1305 | right: 4px; | ||
| 1306 | top: 0; | ||
| 1307 | height: 32px; | ||
| 1308 | display: flex; | ||
| 1309 | align-items: center; | ||
| 1310 | justify-content: center; | ||
| 1311 | width: 16px; | ||
| 1312 | padding: 0; | ||
| 1313 | opacity: 1; | ||
| 1314 | border: none; | ||
| 1315 | background: transparent; | ||
| 1316 | cursor: pointer; | ||
| 1317 | color: var(--vp-c-text-3); | ||
| 1318 | line-height: 0; | ||
| 1319 | transition: color 0.15s; | ||
| 1320 | |||
| 1321 | &.is-bookmarked { | ||
| 1322 | color: var(--vp-c-brand-1); | ||
| 1323 | |||
| 1324 | svg path { | ||
| 1325 | fill: currentColor; | ||
| 1326 | } | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | &:hover { | ||
| 1330 | color: var(--vp-c-brand-1); | ||
| 1331 | } | ||
| 1332 | } | ||
| 1333 | } | ||
| 1334 | |||
| 1335 | @media (hover: none) { | ||
| 1336 | .VPDocAside .toc-bookmark-btn { | ||
| 1337 | opacity: 1; | ||
| 1338 | } | ||
| 1339 | } | ||
| 1340 | |||
| 1251 | .aside-container { | 1341 | .aside-container { |
| 1252 | padding-top: calc( | 1342 | padding-top: calc( |
| 1253 | var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + | 1343 | var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + |