Commit 0274157c9b
Unsigned
Layout: unified · split
docs/.vitepress/theme/Layout.vue +96 −2
| @@ -15,7 +15,9 @@ import { usePreferredReducedMotion } from '@vueuse/core' | |||
| 15 | import { useData, useRoute } from 'vitepress' | 15 | import { useData, useRoute } from 'vitepress' |
| 16 | import type { DefaultTheme as Theme } from 'vitepress' | 16 | import type { DefaultTheme as Theme } from 'vitepress' |
| 17 | import DefaultTheme from 'vitepress/theme' | 17 | import DefaultTheme from 'vitepress/theme' |
| 18 | import { computed, onMounted, onUnmounted, ref } from 'vue' | 18 | import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue' |
| 19 | import { getSidebarGroups } from 'vitepress/dist/client/theme-default/support/sidebar' | ||
| 20 | import { computed, onMounted, onUnmounted, ref, watch } from 'vue' | ||
| 19 | import { sidebar } from '../configs/constants' | 21 | import { sidebar } from '../configs/constants' |
| 20 | import AnnouncementPill from './components/AnnouncementPill.vue' | 22 | import AnnouncementPill from './components/AnnouncementPill.vue' |
| 21 | import NotFoundComponent from './components/NotFound.vue' | 23 | import NotFoundComponent from './components/NotFound.vue' |
| @@ -28,8 +30,26 @@ import { TakodachiStorageKey } from './constants' | |||
| 28 | import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math' | 30 | import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math' |
| 29 | 31 | ||
| 30 | const route = useRoute() | 32 | const route = useRoute() |
| 33 | const { frontmatter, site, theme } = useData() | ||
| 31 | const { Layout } = DefaultTheme | 34 | const { Layout } = DefaultTheme |
| 32 | 35 | ||
| 36 | // Home sidebar menu | ||
| 37 | const isHome = computed(() => frontmatter.value.layout === 'home') | ||
| 38 | const homeSidebarOpen = ref(false) | ||
| 39 | const sidebarRef = ref<HTMLElement | null>(null) | ||
| 40 | const homeSidebarGroups = getSidebarGroups(sidebar as any) | ||
| 41 | const logoSrc = computed(() => | ||
| 42 | typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src | ||
| 43 | ) | ||
| 44 | |||
| 45 | watch(() => route.path, () => { | ||
| 46 | homeSidebarOpen.value = false | ||
| 47 | }) | ||
| 48 | |||
| 49 | function onSidebarEnter() { | ||
| 50 | sidebarRef.value?.focus() | ||
| 51 | } | ||
| 52 | |||
| 33 | interface BreadcrumbItem { | 53 | interface BreadcrumbItem { |
| 34 | text: string | 54 | text: string |
| 35 | link?: string | 55 | link?: string |
| @@ -153,6 +173,32 @@ const reloadTakodachi = () => { | |||
| 153 | onMounted(() => { | 173 | onMounted(() => { |
| 154 | if (import.meta.env.SSR) return | 174 | if (import.meta.env.SSR) return |
| 155 | 175 | ||
| 176 | // Arrow key scrolling + Escape close for desktop sidebar | ||
| 177 | useEventListener(document, 'keydown', (e: KeyboardEvent) => { | ||
| 178 | if (!homeSidebarOpen.value || !sidebarRef.value) return | ||
| 179 | if (e.key === 'Escape') { | ||
| 180 | homeSidebarOpen.value = false | ||
| 181 | return | ||
| 182 | } | ||
| 183 | if (e.key === 'ArrowDown') { | ||
| 184 | e.preventDefault() | ||
| 185 | sidebarRef.value.scrollBy({ top: 60, behavior: 'smooth' }) | ||
| 186 | } else if (e.key === 'ArrowUp') { | ||
| 187 | e.preventDefault() | ||
| 188 | sidebarRef.value.scrollBy({ top: -60, behavior: 'smooth' }) | ||
| 189 | } | ||
| 190 | }) | ||
| 191 | |||
| 192 | // Close home NavScreen on outside click | ||
| 193 | useEventListener(document, 'click', (e: Event) => { | ||
| 194 | if (!isHome.value) return | ||
| 195 | const screen = document.getElementById('VPNavScreen') | ||
| 196 | if (!screen) return | ||
| 197 | const hamburger = document.querySelector('.VPNavBarHamburger') | ||
| 198 | if (screen.contains(e.target as Node) || hamburger?.contains(e.target as Node)) return | ||
| 199 | requestAnimationFrame(() => (hamburger as HTMLElement)?.click()) | ||
| 200 | }) | ||
| 201 | |||
| 156 | // Storage changed in other documents. | 202 | // Storage changed in other documents. |
| 157 | useEventListener(window, 'storage', () => { | 203 | useEventListener(window, 'storage', () => { |
| 158 | reloadTakodachi() | 204 | reloadTakodachi() |
| @@ -185,6 +231,36 @@ onUnmounted(() => { | |||
| 185 | top: `${position.y}px` | 231 | top: `${position.y}px` |
| 186 | }" | 232 | }" |
| 187 | /> | 233 | /> |
| 234 | <!-- Home sidebar menu --> | ||
| 235 | <template v-if="isHome"> | ||
| 236 | <Transition name="home-fade"> | ||
| 237 | <div | ||
| 238 | v-if="homeSidebarOpen" | ||
| 239 | class="home-sidebar-backdrop" | ||
| 240 | @click="homeSidebarOpen = false" | ||
| 241 | /> | ||
| 242 | </Transition> | ||
| 243 | <Transition name="home-slide" @after-enter="onSidebarEnter"> | ||
| 244 | <aside | ||
| 245 | v-if="homeSidebarOpen" | ||
| 246 | ref="sidebarRef" | ||
| 247 | class="home-sidebar" | ||
| 248 | tabindex="-1" | ||
| 249 | @click.stop | ||
| 250 | > | ||
| 251 | <div class="home-sidebar-header"> | ||
| 252 | <a href="/" class="home-sidebar-logo"> | ||
| 253 | <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" /> | ||
| 254 | <span>{{ theme.siteTitle ?? site.title }}</span> | ||
| 255 | </a> | ||
| 256 | </div> | ||
| 257 | <nav id="VPSidebarNav" class="home-sidebar-nav"> | ||
| 258 | <VPSidebarGroup :items="homeSidebarGroups" /> | ||
| 259 | </nav> | ||
| 260 | <SidebarCard /> | ||
| 261 | </aside> | ||
| 262 | </Transition> | ||
| 263 | </template> | ||
| 188 | </template> | 264 | </template> |
| 189 | <template #doc-before> | 265 | <template #doc-before> |
| 190 | <!-- Breadcrumb Navigation --> | 266 | <!-- Breadcrumb Navigation --> |
| @@ -234,8 +310,26 @@ onUnmounted(() => { | |||
| 234 | <template #nav-bar-content-after> | 310 | <template #nav-bar-content-after> |
| 235 | <NolebaseEnhancedReadabilitiesMenu /> | 311 | <NolebaseEnhancedReadabilitiesMenu /> |
| 236 | </template> | 312 | </template> |
| 313 | <template #nav-screen-content-before> | ||
| 314 | <nav v-if="isHome" id="VPSidebarNavMobile" class="home-screen-nav"> | ||
| 315 | <VPSidebarGroup :items="homeSidebarGroups" /> | ||
| 316 | </nav> | ||
| 317 | </template> | ||
| 237 | <template #nav-screen-content-after> | 318 | <template #nav-screen-content-after> |
| 238 | <NolebaseEnhancedReadabilitiesScreenMenu /> | 319 | <NolebaseEnhancedReadabilitiesScreenMenu v-if="!isHome" /> |
| 320 | </template> | ||
| 321 | <template #nav-bar-title-before> | ||
| 322 | <span | ||
| 323 | v-if="isHome" | ||
| 324 | class="home-menu-btn" | ||
| 325 | role="button" | ||
| 326 | tabindex="0" | ||
| 327 | aria-label="Menu" | ||
| 328 | @click.prevent.stop="homeSidebarOpen = !homeSidebarOpen" | ||
| 329 | @keydown.enter.prevent.stop="homeSidebarOpen = !homeSidebarOpen" | ||
| 330 | > | ||
| 331 | <span class="vpi-align-left home-menu-icon" /> | ||
| 332 | </span> | ||
| 239 | </template> | 333 | </template> |
| 240 | </Layout> | 334 | </Layout> |
| 241 | </template> | 335 | </template> |
docs/.vitepress/theme/styles/style.scss +183 −1
| @@ -612,7 +612,8 @@ table tr:nth-child(odd) { | |||
| 612 | } | 612 | } |
| 613 | } | 613 | } |
| 614 | 614 | ||
| 615 | #VPSidebarNav > .group { | 615 | #VPSidebarNav > .group, |
| 616 | #VPSidebarNavMobile > .group { | ||
| 616 | @apply border-t-0 min-h-11 pt-2.25; | 617 | @apply border-t-0 min-h-11 pt-2.25; |
| 617 | 618 | ||
| 618 | & > .VPSidebarItem { | 619 | & > .VPSidebarItem { |
| @@ -1224,3 +1225,184 @@ table tr:nth-child(odd) { | |||
| 1224 | .VPNavBarSearch.search { | 1225 | .VPNavBarSearch.search { |
| 1225 | @apply ml-2 pl-0!; | 1226 | @apply ml-2 pl-0!; |
| 1226 | } | 1227 | } |
| 1228 | |||
| 1229 | %thin-scrollbar { | ||
| 1230 | scrollbar-width: thin; | ||
| 1231 | &::-webkit-scrollbar { width: 8px; } | ||
| 1232 | &::-webkit-scrollbar-track { background: transparent; } | ||
| 1233 | &::-webkit-scrollbar-thumb { border-radius: 4px; } | ||
| 1234 | } | ||
| 1235 | |||
| 1236 | %thin-scrollbar-narrow { | ||
| 1237 | scrollbar-width: thin; | ||
| 1238 | &::-webkit-scrollbar { width: 6px; } | ||
| 1239 | &::-webkit-scrollbar-track { background: transparent; } | ||
| 1240 | &::-webkit-scrollbar-thumb { border-radius: 3px; background-color: var(--vp-c-divider); } | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | /* Home sidebar menu button in navbar */ | ||
| 1244 | .home-menu-btn { | ||
| 1245 | display: none; | ||
| 1246 | align-items: center; | ||
| 1247 | justify-content: center; | ||
| 1248 | margin-right: 16px; | ||
| 1249 | color: var(--vp-c-text-2); | ||
| 1250 | cursor: pointer; | ||
| 1251 | transition: color 0.25s; | ||
| 1252 | |||
| 1253 | &:hover { | ||
| 1254 | color: var(--vp-c-text-1); | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | @media (min-width: 960px) { | ||
| 1258 | display: inline-flex; | ||
| 1259 | } | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | .home-menu-icon { | ||
| 1263 | font-size: 20px; | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | .home-sidebar-backdrop { | ||
| 1267 | position: fixed; | ||
| 1268 | inset: 0; | ||
| 1269 | z-index: var(--vp-z-index-backdrop, 100); | ||
| 1270 | background-color: rgba(0, 0, 0, 0.6); | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | /* Home desktop sidebar (left slideout) */ | ||
| 1274 | .home-sidebar { | ||
| 1275 | position: fixed; | ||
| 1276 | top: 0; | ||
| 1277 | bottom: 0; | ||
| 1278 | left: 0; | ||
| 1279 | z-index: calc(var(--vp-z-index-backdrop, 100) + 1); | ||
| 1280 | padding: 0 32px 96px; | ||
| 1281 | width: var(--vp-sidebar-width); | ||
| 1282 | max-width: calc(100vw - 64px); | ||
| 1283 | background-color: var(--vp-sidebar-bg-color); | ||
| 1284 | box-shadow: var(--vp-c-shadow-3); | ||
| 1285 | overflow-x: hidden; | ||
| 1286 | overflow-y: auto; | ||
| 1287 | overscroll-behavior: contain; | ||
| 1288 | @extend %thin-scrollbar; | ||
| 1289 | |||
| 1290 | .dark & { | ||
| 1291 | box-shadow: var(--vp-shadow-1); | ||
| 1292 | } | ||
| 1293 | } | ||
| 1294 | |||
| 1295 | .home-sidebar-header { | ||
| 1296 | position: sticky; | ||
| 1297 | top: 0; | ||
| 1298 | z-index: 1; | ||
| 1299 | height: var(--vp-nav-height); | ||
| 1300 | display: flex; | ||
| 1301 | align-items: center; | ||
| 1302 | background-color: var(--vp-sidebar-bg-color); | ||
| 1303 | border-bottom: 1px solid var(--vp-c-divider); | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | .home-sidebar-logo { | ||
| 1307 | display: flex; | ||
| 1308 | align-items: center; | ||
| 1309 | height: var(--vp-nav-height); | ||
| 1310 | font-size: 16px; | ||
| 1311 | font-weight: 600; | ||
| 1312 | color: var(--vp-c-text-1); | ||
| 1313 | text-decoration: none; | ||
| 1314 | } | ||
| 1315 | |||
| 1316 | .home-sidebar-logo-img { | ||
| 1317 | margin-right: 8px; | ||
| 1318 | height: var(--vp-nav-logo-height); | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | .home-sidebar-nav { | ||
| 1322 | padding-top: 10px; | ||
| 1323 | } | ||
| 1324 | |||
| 1325 | /* Desktop sidebar transitions */ | ||
| 1326 | .home-fade-enter-active, | ||
| 1327 | .home-fade-leave-active { | ||
| 1328 | transition: opacity 0.25s; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | .home-fade-enter-from, | ||
| 1332 | .home-fade-leave-to { | ||
| 1333 | opacity: 0; | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | .home-slide-enter-active { | ||
| 1337 | transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s; | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | .home-slide-leave-active { | ||
| 1341 | transition: transform 0.25s ease, opacity 0.5s; | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | .home-slide-enter-from, | ||
| 1345 | .home-slide-leave-to { | ||
| 1346 | transform: translateX(-100%); | ||
| 1347 | opacity: 0; | ||
| 1348 | } | ||
| 1349 | |||
| 1350 | /* Hide navbar border when home NavScreen is open */ | ||
| 1351 | .VPNavBar.home.screen-open { | ||
| 1352 | border-bottom: none !important; | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | /* Home NavScreen: restyle as left-aligned floating panel matching VPSidebar */ | ||
| 1356 | .VPNavScreen:has(.home-screen-nav) { | ||
| 1357 | @apply bg-white/85 dark:bg-neutral-800/85 | ||
| 1358 | border dark:border-neutral-700 border-neutral-200 | ||
| 1359 | rounded-3xl backdrop-blur shadow-lg; | ||
| 1360 | padding: 0 !important; | ||
| 1361 | left: 0.5rem !important; | ||
| 1362 | right: auto !important; | ||
| 1363 | top: 0.5rem !important; | ||
| 1364 | bottom: 0.5rem !important; | ||
| 1365 | width: calc(100vw - 64px) !important; | ||
| 1366 | max-width: 320px !important; | ||
| 1367 | overflow-x: hidden !important; | ||
| 1368 | @extend %thin-scrollbar-narrow; | ||
| 1369 | |||
| 1370 | & > * { | ||
| 1371 | max-width: 100% !important; | ||
| 1372 | padding: 16px 16px 0 !important; | ||
| 1373 | display: flex !important; | ||
| 1374 | flex-direction: column !important; | ||
| 1375 | min-height: 100%; | ||
| 1376 | } | ||
| 1377 | |||
| 1378 | .VPNavScreenAppearance { | ||
| 1379 | margin-top: 24px !important; | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | .VPNavScreenSocialLinks { | ||
| 1383 | margin-top: auto !important; | ||
| 1384 | padding: 16px 0 !important; | ||
| 1385 | display: flex; | ||
| 1386 | justify-content: center; | ||
| 1387 | } | ||
| 1388 | } | ||
| 1389 | |||
| 1390 | .home-screen-nav { | ||
| 1391 | padding-top: 8px; | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | /* Override NavScreen fade transition to slide-from-left on home */ | ||
| 1395 | .VPNavScreen:has(.home-screen-nav) { | ||
| 1396 | &.fade-enter-active, | ||
| 1397 | &.fade-leave-active { | ||
| 1398 | transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s !important; | ||
| 1399 | |||
| 1400 | .container { transform: none !important; } | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | &.fade-enter-from, | ||
| 1404 | &.fade-leave-to { | ||
| 1405 | transform: translateX(-100%) !important; | ||
| 1406 | opacity: 0 !important; | ||
| 1407 | } | ||
| 1408 | } | ||