docs/.vitepress/theme/Layout.vue

78ea9fc554970c86ce26acb3978ead8147153dad
wotaku/docs/.vitepress/theme/Layout.vue
Duck updated822be9529 4 months ago

1395 lines · 42135 bytes

   1<!--
   2  All Rights Reserved
   3
   4  Copyright (c) 2025 taskylizard
   5
   6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
   7-->
   8<script setup lang="ts">
   9import {
  10  customStorageEventName,
  11  useEventListener,
  12  useStorage
  13} from '@vueuse/core'
  14import { usePreferredReducedMotion } from '@vueuse/core'
  15import { useData, useRoute } from 'vitepress'
  16import type { DefaultTheme as Theme } from 'vitepress'
  17import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue'
  18import { getSidebarGroups } from 'vitepress/dist/client/theme-default/support/sidebar'
  19import DefaultTheme from 'vitepress/theme'
  20import {
  21  computed,
  22  nextTick,
  23  onMounted,
  24  onUnmounted,
  25  ref,
  26  watch,
  27  watchEffect
  28} from 'vue'
  29import { sidebar } from '../configs/constants'
  30import { useBookmarks, BOOKMARK_CHANGE_EVENT } from './composables/useBookmarks'
  31import AnnouncementPill from './components/AnnouncementPill.vue'
  32import SiteFooter from './components/SiteFooter.vue'
  33import NotFoundComponent from './components/NotFound.vue'
  34import { NolebaseEnhancedReadabilitiesScreenMenu } from './components/settings'
  35import NavActions from './components/NavActions.vue'
  36import SidebarCard from './components/SidebarCard.vue'
  37import { AccentColorStorageKey, TakodachiStorageKey } from './constants'
  38import { useEffects } from './composables/useEffects'
  39import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math'
  40
  41const route = useRoute()
  42const { frontmatter, isDark, site, theme } = useData()
  43const { isBookmarked, toggle: bookmarkToggle } = useBookmarks()
  44const { Layout } = DefaultTheme
  45
  46// Home sidebar menu
  47const isHome = computed(() => frontmatter.value.layout === 'home')
  48const homeSidebarOpen = ref(false)
  49const sidebarRef = ref<HTMLElement | null>(null)
  50const homeSidebarGroups = getSidebarGroups(sidebar as any)
  51const logoSrc = computed(() =>
  52  typeof theme.value.logo === 'string'
  53    ? theme.value.logo
  54    : theme.value.logo?.src
  55)
  56
  57watch(() => route.path, () => {
  58  homeSidebarOpen.value = false
  59})
  60
  61let searchNavigated = false
  62let searchQuery = ''
  63
  64if (!import.meta.env.SSR) {
  65  useEventListener(window, 'search-nav', (event) => {
  66    searchNavigated = true
  67    searchQuery = event instanceof CustomEvent &&
  68        typeof event.detail?.query === 'string'
  69      ? event.detail.query
  70      : ''
  71  })
  72}
  73
  74const nextFrame = () =>
  75  new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
  76
  77const getSearchTerms = (query: string) =>
  78  query
  79    .toLowerCase()
  80    .split(/\s+/)
  81    .map((term) => term.trim())
  82    .filter(Boolean)
  83
  84const getTargetByHash = (hash: string) => {
  85  const ids = [hash]
  86  try {
  87    const decoded = decodeURIComponent(hash)
  88    if (decoded !== hash) ids.unshift(decoded)
  89  } catch {
  90    /* keep the raw hash */
  91  }
  92
  93  for (const id of ids) {
  94    const target = document.getElementById(id)
  95    if (target) return target
  96  }
  97}
  98
  99const getScrollTargetForAnchor = (target: HTMLElement) => {
 100  if (target.classList.contains('tab-search-heading')) {
 101    return target.closest<HTMLElement>('.plugin-tabs') ?? target
 102  }
 103
 104  return target
 105}
 106
 107const TAB_QUERY_PARAM = 't'
 108const COLLAPSIBLE_QUERY_PARAM = 'c'
 109
 110const getRequestedAnchorPath = (param: string) => {
 111  const value = new URLSearchParams(window.location.search).get(param)
 112  return value
 113    ?.split(',')
 114    .map((anchor) => anchor.trim())
 115    .filter(Boolean) ?? []
 116}
 117
 118const getRequestedTabPath = () => getRequestedAnchorPath(TAB_QUERY_PARAM)
 119const getRequestedCollapsiblePath = () =>
 120  getRequestedAnchorPath(COLLAPSIBLE_QUERY_PARAM)
 121
 122const encodeAnchorList = (anchors: string[]) =>
 123  anchors.map((anchor) => encodeURIComponent(anchor)).join(',')
 124
 125const buildUrl = (
 126  options: { tabs?: string[]; collapsibles?: string[]; hash?: string } = {}
 127) => {
 128  const params = new URLSearchParams(window.location.search)
 129  const currentTabs = params.get(TAB_QUERY_PARAM)
 130  const currentCollapsibles = params.get(COLLAPSIBLE_QUERY_PARAM)
 131  params.delete(TAB_QUERY_PARAM)
 132  params.delete(COLLAPSIBLE_QUERY_PARAM)
 133
 134  const tabs = options.tabs ??
 135    (currentTabs ? currentTabs.split(',').filter(Boolean) : [])
 136  const collapsibles = options.collapsibles ??
 137    (currentCollapsibles ? currentCollapsibles.split(',').filter(Boolean) : [])
 138
 139  const queryParts = [
 140    params.toString(),
 141    tabs.length ? `${TAB_QUERY_PARAM}=${encodeAnchorList(tabs)}` : '',
 142    collapsibles.length
 143      ? `${COLLAPSIBLE_QUERY_PARAM}=${encodeAnchorList(collapsibles)}`
 144      : ''
 145  ].filter(Boolean)
 146
 147  const hash = options.hash ?? ''
 148  return `${window.location.pathname}${
 149    queryParts.length ? `?${queryParts.join('&')}` : ''
 150  }${hash ? `#${encodeURIComponent(hash)}` : ''}`
 151}
 152
 153const buildUrlWithTabs = (tabs: string[], hash = '') => buildUrl({ tabs, hash })
 154
 155const getSelectedTabAnchor = (tabs: HTMLElement) =>
 156  tabs.querySelector<HTMLButtonElement>(
 157    '.plugin-tabs--tab[aria-selected="true"][data-tab-anchor]'
 158  )?.dataset.tabAnchor
 159
 160const getPanelForTabButton = (button: HTMLButtonElement) => {
 161  const panelId = button.getAttribute('aria-controls')
 162  return panelId ? document.getElementById(panelId) : undefined
 163}
 164
 165const getTabPathForGroup = (tabs: HTMLElement) => {
 166  const groups: HTMLElement[] = []
 167  let currentTabs: HTMLElement | null = tabs
 168
 169  while (currentTabs) {
 170    groups.unshift(currentTabs)
 171    const parentPanel = currentTabs.parentElement?.closest<HTMLElement>(
 172      '.plugin-tabs--content[data-tab-anchor]'
 173    )
 174    currentTabs = parentPanel?.closest<HTMLElement>('.plugin-tabs') ?? null
 175  }
 176
 177  return groups
 178    .map((group) => getSelectedTabAnchor(group))
 179    .filter((tab): tab is string => Boolean(tab))
 180}
 181
 182const updateQueryForSelectedTab = async (tabs: HTMLElement) => {
 183  await nextTick()
 184  await nextFrame()
 185
 186  const tabPath = getTabPathForGroup(tabs)
 187  if (!tabPath.length) return
 188
 189  const collapsibles = getOpenCollapsiblePath(tabs)
 190
 191  const nextUrl = buildUrl({ tabs: tabPath, collapsibles })
 192  const currentUrl =
 193    `${window.location.pathname}${window.location.search}${window.location.hash}`
 194  if (nextUrl === currentUrl) return
 195
 196  window.history.pushState(null, '', nextUrl)
 197  rewriteAnchorLinks()
 198}
 199
 200const queueTabQueryUpdateForSelection = (target: EventTarget | null) => {
 201  if (!(target instanceof HTMLElement)) return
 202
 203  const button = target.closest<HTMLButtonElement>(
 204    '.plugin-tabs--tab[role="tab"]'
 205  )
 206  const tabs = button?.closest<HTMLElement>('.plugin-tabs')
 207  if (tabs) void updateQueryForSelectedTab(tabs)
 208}
 209
 210const COLLAPSIBLE_SELECTOR = 'details[data-collapsible-anchor]'
 211
 212const getOpenCollapsiblePath = (details: HTMLElement) => {
 213  const path: string[] = []
 214  let el: HTMLElement | null = details
 215
 216  while (el) {
 217    const current: HTMLElement | null = el.closest(COLLAPSIBLE_SELECTOR)
 218    if (!current) break
 219
 220    if ((current as HTMLDetailsElement).open) {
 221      const anchor = current.dataset.collapsibleAnchor
 222      if (anchor) path.unshift(anchor)
 223    }
 224
 225    el = current.parentElement
 226  }
 227
 228  return path
 229}
 230
 231const getEnclosingTabPath = (el: HTMLElement) => {
 232  const panel = el.closest<HTMLElement>(
 233    '.plugin-tabs--content[data-tab-anchor]'
 234  )
 235  const tabs = panel?.closest<HTMLElement>('.plugin-tabs')
 236  return tabs ? getTabPathForGroup(tabs) : []
 237}
 238
 239const updateQueryForCollapsible = async (details: HTMLElement) => {
 240  await nextTick()
 241  await nextFrame()
 242
 243  const collapsiblePath = getOpenCollapsiblePath(details)
 244  const tabPath = getEnclosingTabPath(details)
 245
 246  const nextUrl = buildUrl({
 247    tabs: tabPath.length ? tabPath : undefined,
 248    collapsibles: collapsiblePath
 249  })
 250  const currentUrl =
 251    `${window.location.pathname}${window.location.search}${window.location.hash}`
 252  if (nextUrl === currentUrl) return
 253
 254  window.history.pushState(null, '', nextUrl)
 255  rewriteAnchorLinks()
 256}
 257
 258const queueCollapsibleQueryUpdate = (target: EventTarget | null) => {
 259  if (!(target instanceof HTMLElement)) return
 260
 261  const summary = target.closest<HTMLElement>('summary')
 262  const details = summary?.parentElement
 263  if (details instanceof HTMLElement && details.matches(COLLAPSIBLE_SELECTOR)) {
 264    void updateQueryForCollapsible(details)
 265  }
 266}
 267
 268const selectCollapsiblesByPath = async (collapsiblePath: string[]) => {
 269  let root: ParentNode = document
 270  let opened: HTMLElement | undefined
 271
 272  for (const anchor of collapsiblePath) {
 273    const details = root.querySelector<HTMLDetailsElement>(
 274      `details[data-collapsible-anchor="${CSS.escape(anchor)}"]`
 275    )
 276    if (!details) return opened
 277
 278    opened = details
 279    if (!details.open) {
 280      details.open = true
 281      await nextTick()
 282      await nextFrame()
 283    }
 284
 285    root = details
 286  }
 287
 288  return opened
 289}
 290
 291const TAB_LINK_MARKER = 'tab-'
 292
 293const rewriteAnchorLinks = () => {
 294  const origin = window.location.origin
 295  const pathname = window.location.pathname
 296
 297  document
 298    .querySelectorAll<HTMLAnchorElement>('.VPDoc .vp-doc a[href]')
 299    .forEach((link) => {
 300      // Accept either the original `#…` form or a previously-rewritten absolute URL.
 301      const raw = link.getAttribute('href') ?? ''
 302      let fragment: string | null = null
 303      if (raw.startsWith('#') && raw.length > 1) {
 304        fragment = raw.slice(1)
 305      } else if (raw.startsWith(origin + pathname + '#')) {
 306        fragment = raw.slice((origin + pathname + '#').length)
 307      } else if (raw.startsWith(origin + pathname + '?')) {
 308        // Already rewritten as a tab link — re-derive the tab name and re-stamp.
 309        const qs = raw.slice((origin + pathname + '?').length).split('#')[0]
 310        const tabName = new URLSearchParams(qs).get(TAB_QUERY_PARAM)
 311        if (tabName) {
 312          const href = `${origin}${pathname}?${TAB_QUERY_PARAM}=${
 313            encodeURIComponent(tabName)
 314          }`
 315          if (link.getAttribute('href') !== href) {
 316            link.setAttribute('href', href)
 317          }
 318        }
 319        return
 320      } else {
 321        return
 322      }
 323
 324      const isTabLink = fragment.startsWith(TAB_LINK_MARKER)
 325      const name = (isTabLink
 326        ? fragment.slice(TAB_LINK_MARKER.length)
 327        : fragment).trim()
 328      if (!name) return
 329
 330      // Use absolute URLs so the browser's Copy Link has nothing to merge with
 331      // the current ?tabs= query.
 332      const href = isTabLink
 333        ? `${origin}${pathname}?${TAB_QUERY_PARAM}=${encodeURIComponent(name)}`
 334        : `${origin}${pathname}#${name}`
 335
 336      if (link.getAttribute('href') !== href) link.setAttribute('href', href)
 337    })
 338}
 339
 340const selectTabsByPath = async (tabPath: string[]) => {
 341  let root: ParentNode = document
 342  let selectedTabs: HTMLElement | undefined
 343
 344  for (const anchor of tabPath) {
 345    const button = root.querySelector<HTMLButtonElement>(
 346      `.plugin-tabs--tab[role="tab"][data-tab-anchor="${CSS.escape(anchor)}"]`
 347    )
 348    if (!button) return selectedTabs
 349
 350    const tabs = button.closest<HTMLElement>('.plugin-tabs')
 351    if (!tabs) return selectedTabs
 352
 353    selectedTabs = tabs
 354    if (button.getAttribute('aria-selected') !== 'true') {
 355      button.click()
 356      await nextTick()
 357      await nextFrame()
 358    }
 359
 360    root = getPanelForTabButton(button) ?? tabs
 361  }
 362
 363  return selectedTabs
 364}
 365
 366const selectLegacyTabHash = async (hash: string) => {
 367  const button = document.querySelector<HTMLButtonElement>(
 368    `.plugin-tabs--tab[role="tab"][data-tab-anchor="${CSS.escape(hash)}"]`
 369  )
 370  if (!button) return
 371
 372  if (button.getAttribute('aria-selected') !== 'true') {
 373    button.click()
 374    await nextTick()
 375    await nextFrame()
 376  }
 377
 378  const tabs = button.closest<HTMLElement>('.plugin-tabs')
 379  if (tabs) {
 380    window.history.replaceState(null, '', buildUrlWithTabs([hash]))
 381  }
 382  return tabs
 383}
 384
 385const getSelectedTabScrollTarget = (tabs: HTMLElement) => {
 386  const selectedTab = tabs.querySelector<HTMLButtonElement>(
 387    '.plugin-tabs--tab[aria-selected="true"]'
 388  )
 389  return selectedTab ? getPanelForTabButton(selectedTab) ?? tabs : tabs
 390}
 391
 392const scrollToElement = (target: HTMLElement, smooth = true) => {
 393  requestAnimationFrame(() => {
 394    requestAnimationFrame(() => {
 395      const navBar = document.querySelector<HTMLElement>('.VPNavBar')
 396      const navOffset = navBar ? navBar.offsetHeight : 0
 397      window.scrollTo({
 398        top: target.getBoundingClientRect().top + window.scrollY - navOffset,
 399        behavior: smooth &&
 400            !window.matchMedia('(prefers-reduced-motion: reduce)').matches
 401          ? 'smooth'
 402          : 'auto'
 403      })
 404      target.setAttribute('tabindex', '-1')
 405      target.focus({ preventScroll: true })
 406    })
 407  })
 408}
 409
 410const openCollapsibles = async (target: HTMLElement) => {
 411  const activeTarget = target
 412  let scrollTarget = getScrollTargetForAnchor(activeTarget)
 413  let el: HTMLElement | null = activeTarget
 414
 415  while ((el = el.closest('details'))) {
 416    el.open = true
 417    scrollTarget = el
 418    el = el.parentElement
 419  }
 420
 421  const tagName = activeTarget.tagName
 422  if (tagName.length === 2 && tagName[0] === 'H') {
 423    const level = +tagName[1]
 424    if (level >= 1 && level <= 6) {
 425      const terms = getSearchTerms(searchQuery)
 426      const detailsContainsTerms = (d: HTMLElement) => {
 427        if (!terms.length) return false
 428        const text = (d.textContent ?? '').toLowerCase()
 429        return terms.every((term) => text.includes(term))
 430      }
 431
 432      let sibling = activeTarget.nextElementSibling
 433
 434      while (sibling) {
 435        const siblingTag = sibling.tagName
 436        if (
 437          siblingTag.length === 2 && siblingTag[0] === 'H' &&
 438          +siblingTag[1] <= level
 439        ) break
 440
 441        if (siblingTag === 'DETAILS') {
 442          if (detailsContainsTerms(sibling as HTMLElement)) {
 443            ;(sibling as HTMLDetailsElement).open = true
 444            if (scrollTarget === activeTarget) {
 445              scrollTarget = sibling as HTMLElement
 446            }
 447          }
 448        }
 449
 450        const nested = sibling.getElementsByTagName('details')
 451        for (let i = 0, len = nested.length; i < len; i++) {
 452          if (detailsContainsTerms(nested[i])) {
 453            nested[i].open = true
 454            if (scrollTarget === activeTarget) scrollTarget = nested[i]
 455          }
 456        }
 457
 458        sibling = sibling.nextElementSibling
 459      }
 460    }
 461  }
 462
 463  await nextTick()
 464  await nextFrame()
 465
 466  scrollToElement(scrollTarget)
 467}
 468
 469const resetSearchNavigation = () => {
 470  searchNavigated = false
 471  searchQuery = ''
 472}
 473
 474const tryOpenAnchoredContent = async () => {
 475  await nextTick()
 476  await nextFrame()
 477
 478  const requestedTabs = getRequestedTabPath()
 479  const selectedTabs = requestedTabs.length
 480    ? await selectTabsByPath(requestedTabs)
 481    : undefined
 482  const requestedCollapsibles = getRequestedCollapsiblePath()
 483  const openedCollapsible = requestedCollapsibles.length
 484    ? await selectCollapsiblesByPath(requestedCollapsibles)
 485    : undefined
 486  const hash = window.location.hash.slice(1)
 487
 488  if (!hash) {
 489    resetSearchNavigation()
 490    if (openedCollapsible) {
 491      scrollToElement(openedCollapsible, false)
 492    } else if (selectedTabs) {
 493      scrollToElement(getSelectedTabScrollTarget(selectedTabs), false)
 494    }
 495    return
 496  }
 497
 498  let target = getTargetByHash(hash)
 499
 500  if (!target && !requestedTabs.length) {
 501    const legacyTabs = await selectLegacyTabHash(hash)
 502    if (legacyTabs) {
 503      resetSearchNavigation()
 504      scrollToElement(getSelectedTabScrollTarget(legacyTabs), false)
 505      return
 506    }
 507  }
 508
 509  if (!target) {
 510    if (searchNavigated) resetSearchNavigation()
 511    return
 512  }
 513
 514  if (searchNavigated) {
 515    await openCollapsibles(target)
 516    const collapsiblePath = getOpenCollapsiblePath(target)
 517    if (collapsiblePath.length) {
 518      const tabPath = getEnclosingTabPath(target)
 519      window.history.replaceState(
 520        null,
 521        '',
 522        buildUrl({
 523          tabs: tabPath.length ? tabPath : undefined,
 524          collapsibles: collapsiblePath
 525        })
 526      )
 527      rewriteAnchorLinks()
 528    }
 529    resetSearchNavigation()
 530    return
 531  }
 532
 533  const isTabRelatedTarget = target.classList.contains('tab-search-heading') ||
 534    Boolean(target.closest('.plugin-tabs'))
 535
 536  if (
 537    !isTabRelatedTarget &&
 538    new URLSearchParams(window.location.search).has(TAB_QUERY_PARAM)
 539  ) {
 540    window.history.replaceState(null, '', buildUrlWithTabs([], hash))
 541    scrollToElement(getScrollTargetForAnchor(target), false)
 542    return
 543  }
 544
 545  if (target.classList.contains('tab-search-heading')) {
 546    const tabs = target.closest<HTMLElement>('.plugin-tabs')
 547    if (tabs) {
 548      window.history.replaceState(
 549        null,
 550        '',
 551        buildUrlWithTabs(getTabPathForGroup(tabs))
 552      )
 553    }
 554  }
 555
 556  if (
 557    selectedTabs ||
 558    target.classList.contains('tab-search-heading')
 559  ) {
 560    scrollToElement(getScrollTargetForAnchor(target), false)
 561  }
 562}
 563
 564const rewriteAnchorLinksDeferred = () => nextTick(() => rewriteAnchorLinks())
 565
 566let outlineFollowObserver: MutationObserver | null = null
 567let outlineFollowRaf = 0
 568
 569const followActiveOutlineLink = () => {
 570  cancelAnimationFrame(outlineFollowRaf)
 571
 572  outlineFollowRaf = requestAnimationFrame(() => {
 573    const activeLink = document.querySelector<HTMLElement>(
 574      '.VPDocAsideOutline a.outline-link.active'
 575    )
 576    const scroller = activeLink?.closest<HTMLElement>('.aside-container')
 577    if (!activeLink || !scroller) return
 578
 579    const linkRect = activeLink.getBoundingClientRect()
 580    const scrollerRect = scroller.getBoundingClientRect()
 581    const margin = 32
 582
 583    if (linkRect.top < scrollerRect.top + margin) {
 584      scroller.scrollTop += linkRect.top - scrollerRect.top - margin
 585    } else if (linkRect.bottom > scrollerRect.bottom - margin) {
 586      scroller.scrollTop += linkRect.bottom - scrollerRect.bottom + margin
 587    }
 588  })
 589}
 590
 591const setupOutlineFollow = () => {
 592  outlineFollowObserver?.disconnect()
 593  outlineFollowObserver = null
 594
 595  const outline = document.querySelector('.VPDocAsideOutline')
 596  if (!outline) return
 597
 598  outlineFollowObserver = new MutationObserver((mutations) => {
 599    if (
 600      mutations.some((mutation) =>
 601        mutation.type === 'childList' ||
 602        (mutation.target instanceof HTMLElement &&
 603          mutation.target.matches('a.outline-link'))
 604      )
 605    ) {
 606      followActiveOutlineLink()
 607    }
 608  })
 609
 610  outlineFollowObserver.observe(outline, {
 611    attributes: true,
 612    attributeFilter: ['class'],
 613    childList: true,
 614    subtree: true
 615  })
 616  followActiveOutlineLink()
 617}
 618
 619const 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>`
 620
 621function syncTocBookmarkStates() {
 622  const path = route.path
 623  document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn => {
 624    const anchor = btn.dataset.anchor ?? ''
 625    btn.classList.toggle('is-bookmarked', isBookmarked(anchor, path))
 626  })
 627}
 628
 629function addBookmarkBtnToLi(li: HTMLElement, path: string) {
 630  if (li.querySelector('.toc-bookmark-btn')) return
 631
 632  const link = li.querySelector<HTMLAnchorElement>(':scope > .outline-link')
 633  if (!link) return
 634
 635  const hrefAttr = link.getAttribute('href') ?? ''
 636  const anchor = hrefAttr.startsWith('#') ? hrefAttr.slice(1) : hrefAttr
 637  const title = link.textContent?.trim() ?? ''
 638  if (!anchor || !title) return
 639
 640  const btn = document.createElement('button')
 641  btn.className = 'toc-bookmark-btn'
 642  btn.setAttribute('aria-label', `Bookmark "${title}"`)
 643  btn.dataset.anchor = anchor
 644  btn.innerHTML = BOOKMARK_SVG
 645
 646  if (isBookmarked(anchor, path)) btn.classList.add('is-bookmarked')
 647
 648  btn.addEventListener('click', (e) => {
 649    e.preventDefault()
 650    e.stopPropagation()
 651    bookmarkToggle({ anchor, title, path })
 652    btn.classList.toggle('is-bookmarked', isBookmarked(anchor, path))
 653  })
 654
 655  li.appendChild(btn)
 656}
 657
 658let tocMutationObserver: MutationObserver | null = null
 659let tocRaf = 0
 660
 661function scanTocItems(path: string) {
 662  // Desktop sidebar — VPDocOutlineItem is called with :root="true"
 663  document.querySelectorAll<HTMLElement>('.VPDocOutlineItem.root > li').forEach(li => addBookmarkBtnToLi(li, path))
 664  // Mobile dropdown — VPDocOutlineItem is called without root prop, so the ul gets class "nested"
 665  document.querySelectorAll<HTMLElement>('.VPLocalNavOutlineDropdown .outline > .VPDocOutlineItem > li').forEach(li => addBookmarkBtnToLi(li, path))
 666}
 667
 668function setupTocBookmarks() {
 669  const path = route.path
 670  document.querySelectorAll<HTMLElement>('.toc-bookmark-btn').forEach(btn => btn.remove())
 671  scanTocItems(path)
 672
 673  // Mobile dropdown items are v-if rendered on open — watch for them being added
 674  tocMutationObserver?.disconnect()
 675  tocMutationObserver = new MutationObserver(() => {
 676    cancelAnimationFrame(tocRaf)
 677    tocRaf = requestAnimationFrame(() => scanTocItems(route.path))
 678  })
 679  tocMutationObserver.observe(document.body, { childList: true, subtree: true })
 680}
 681
 682onMounted(tryOpenAnchoredContent)
 683onMounted(rewriteAnchorLinksDeferred)
 684onMounted(() => nextTick(setupOutlineFollow))
 685onMounted(() => nextTick(setupTocBookmarks))
 686watch(() => route.data, () => {
 687  void tryOpenAnchoredContent()
 688  rewriteAnchorLinksDeferred()
 689  nextTick(setupOutlineFollow)
 690  nextTick(setupManualCopyButtons)
 691  nextTick(setupTocBookmarks)
 692}, { flush: 'post' })
 693watch(() => route.query, () => {
 694  void tryOpenAnchoredContent()
 695  rewriteAnchorLinksDeferred()
 696}, { flush: 'post' })
 697watch(() => route.hash, tryOpenAnchoredContent, { flush: 'post' })
 698
 699function onSidebarEnter() {
 700  sidebarRef.value?.focus()
 701}
 702
 703interface BreadcrumbItem {
 704  text: string
 705  link?: string
 706}
 707
 708const buildBreadcrumbs = (
 709  items: Theme.SidebarItem[],
 710  currentPath: string
 711): BreadcrumbItem[] => {
 712  for (const item of items) {
 713    // Check if this item matches the current path
 714    if (item.link === currentPath) {
 715      return [
 716        {
 717          text: item.text!.replace('mr-2 block w-4 h-4 bg-cover', '').trim(),
 718          link: item.link
 719        }
 720      ]
 721    }
 722
 723    // Check nested items
 724    if (item.items) {
 725      const nestedBreadcrumbs = buildBreadcrumbs(item.items, currentPath)
 726      if (nestedBreadcrumbs.length > 0) {
 727        return [
 728          {
 729            text: item.text!.replace('mr-2 block w-4 h-4 bg-cover', '').trim(),
 730            link: item.link
 731          },
 732          ...nestedBreadcrumbs
 733        ]
 734      }
 735    }
 736  }
 737  return []
 738}
 739
 740const breadcrumbs = computed(() => {
 741  const currentPath = route.path
 742  // @ts-expect-error
 743  return buildBreadcrumbs(sidebar, currentPath)
 744})
 745
 746// Respect user's reduced motion preferences
 747const prefs = usePreferredReducedMotion()
 748const { effectsEnabled } = useEffects()
 749
 750watchEffect(() => {
 751  if (import.meta.env.SSR) return
 752
 753  // Effects are off by default; the class strips blur/transitions/scaling.
 754  document.documentElement.classList.toggle(
 755    'effects-disabled',
 756    !effectsEnabled.value
 757  )
 758})
 759
 760type ShadeMap = Record<string, string>
 761type PaletteEntry = ShadeMap | { dark: ShadeMap; light: ShadeMap }
 762
 763const accentPalettes: Record<string, PaletteEntry> = {
 764  ayanami: {
 765    400: 'oklch(0.722 0.105 247.48)',
 766    500: 'oklch(0.626 0.098 247.46)',
 767    600: 'oklch(0.523 0.081 246.86)',
 768    700: 'oklch(0.43 0.066 246.75)',
 769    800: 'oklch(0.335 0.052 246.76)',
 770  },
 771  asuka: {
 772    400: 'oklch(0.740 0.210 32)',
 773    500: 'oklch(0.650 0.240 30)',
 774    600: 'oklch(0.555 0.238 28)',
 775    700: 'oklch(0.455 0.205 26)',
 776    800: 'oklch(0.370 0.165 24)',
 777  },
 778  irys: {
 779    400: 'oklch(0.716 0.188 5.18)',
 780    500: 'oklch(0.659 0.237 8.99)',
 781    600: 'oklch(0.584 0.229 10.32)',
 782    700: 'oklch(0.538 0.213 9.67)',
 783    800: 'oklch(0.475 0.187 5.94)',
 784  },
 785  inanis: {
 786    400: 'oklch(0.762 0.073 302.02)',
 787    500: 'oklch(0.663 0.102 301.22)',
 788    600: 'oklch(0.580 0.119 301.34)',
 789    700: 'oklch(0.508 0.114 301.00)',
 790    800: 'oklch(0.452 0.094 302.20)',
 791  },
 792  baelz: {
 793    400: 'oklch(0.720 0.215 22.00)',
 794    500: 'oklch(0.640 0.255 22.00)',
 795    600: 'oklch(0.555 0.268 22.00)',
 796    700: 'oklch(0.472 0.248 22.00)',
 797    800: 'oklch(0.395 0.208 22.00)',
 798  },
 799  amelia: {
 800    400: 'oklch(0.800 0.085 75.49)',
 801    500: 'oklch(0.710 0.090 72.47)',
 802    600: 'oklch(0.594 0.085 69.07)',
 803    700: 'oklch(0.496 0.078 72.12)',
 804    800: 'oklch(0.391 0.062 68.86)',
 805  },
 806  suisei: {
 807    400: 'oklch(0.827 0.096 224.60)',
 808    500: 'oklch(0.740 0.119 230.91)',
 809    600: 'oklch(0.645 0.127 236.29)',
 810    700: 'oklch(0.548 0.120 241.26)',
 811    800: 'oklch(0.451 0.106 244.63)',
 812  },
 813  miku: {
 814    400: 'oklch(0.788 0.133 184.43)',
 815    500: 'oklch(0.711 0.123 185.28)',
 816    600: 'oklch(0.607 0.104 187.31)',
 817    700: 'oklch(0.515 0.086 189.60)',
 818    800: 'oklch(0.441 0.071 190.95)',
 819  },
 820  fubuki: {
 821    dark: {
 822      400: 'oklch(0.88 0 0)',
 823      500: 'oklch(0.78 0 0)',
 824      600: 'oklch(0.68 0 0)',
 825      700: 'oklch(0.58 0 0)',
 826      800: 'oklch(0.48 0 0)',
 827    },
 828    light: {
 829      400: 'oklch(0.52 0 0)',
 830      500: 'oklch(0.42 0 0)',
 831      600: 'oklch(0.32 0 0)',
 832      700: 'oklch(0.22 0 0)',
 833      800: 'oklch(0.12 0 0)',
 834    },
 835  },
 836}
 837
 838const accentColor = useStorage(AccentColorStorageKey, 'ayanami')
 839
 840watchEffect(() => {
 841  if (import.meta.env.SSR) return
 842  const palette = accentPalettes[accentColor.value] ?? accentPalettes.ayanami
 843  const shades = 'dark' in palette
 844    ? (isDark.value ? palette.dark : palette.light)
 845    : palette
 846  const el = document.documentElement
 847  if (isDark.value) {
 848    el.style.setProperty('--vp-c-brand-1', shades['400'])
 849    el.style.setProperty('--vp-c-brand-2', shades['500'])
 850    el.style.setProperty('--vp-c-brand-3', shades['700'])
 851    el.style.setProperty('--vp-c-brand-soft', `color-mix(in srgb, ${shades['500']} 20%, transparent)`)
 852    el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['500']} 15%, transparent)`)
 853  } else {
 854    el.style.setProperty('--vp-c-brand-1', shades['500'])
 855    el.style.setProperty('--vp-c-brand-2', shades['600'])
 856    el.style.setProperty('--vp-c-brand-3', shades['800'])
 857    el.style.setProperty('--vp-c-brand-soft', `color-mix(in srgb, ${shades['400']} 40%, transparent)`)
 858    el.style.setProperty('--vp-c-sidebar-active', `color-mix(in srgb, ${shades['800']} 15%, transparent)`)
 859  }
 860})
 861
 862const speed = 2
 863const snapThreshold = 5 // px
 864
 865const takodachiRef = ref<HTMLImageElement | null>(null)
 866let mousePos: Vec2D | null = null
 867let target: Vec2D | null = null
 868let offset: Vec2D = [0, 0]
 869
 870const position = ref({
 871  x: 0,
 872  y: 0
 873})
 874
 875const updateMousePos = (e: MouseEvent | TouchEvent) => {
 876  if (e instanceof MouseEvent) {
 877    mousePos = [e.clientX, e.clientY]
 878  } else {
 879    mousePos = [e.touches[0].clientX, e.touches[0].clientY]
 880  }
 881}
 882
 883const takodachiDisable = ref<(() => void) | null>(null)
 884const takodachiToggledOn = useStorage(TakodachiStorageKey, false)
 885
 886const reloadTakodachi = () => {
 887  takodachiDisable.value?.()
 888
 889  if (prefs.value === 'reduce') return
 890  const saved = takodachiToggledOn
 891  if (saved.value === false) return
 892
 893  window.addEventListener('mousemove', updateMousePos)
 894  window.addEventListener('touchstart', updateMousePos)
 895
 896  const chaser = takodachiRef!.value
 897  if (chaser) {
 898    offset = v2smul([chaser.clientWidth, chaser.clientHeight], 0.5)
 899    setTimeout(() => {
 900      chaser.classList.remove('opacity-0')
 901    }, 1000)
 902  }
 903
 904  const intervalId = setInterval(() => {
 905    if (!mousePos) return
 906
 907    const currentPos: Vec2D = [
 908      position.value.x + offset[0],
 909      position.value.y + offset[1]
 910    ]
 911
 912    target = target ?? currentPos
 913
 914    const diff = v2sub(mousePos, currentPos)
 915
 916    target = v2mag(diff) < snapThreshold
 917      ? mousePos
 918      : v2add(target, v2smul(v2norm(diff), speed))
 919
 920    const finalVec = v2sub(target, offset)
 921
 922    position.value = { x: finalVec[0], y: finalVec[1] }
 923  }, 10)
 924
 925  takodachiDisable.value = () => {
 926    chaser?.classList.add('opacity-0')
 927
 928    window.removeEventListener('mousemove', updateMousePos)
 929    window.removeEventListener('touchstart', updateMousePos)
 930    clearInterval(intervalId)
 931
 932    takodachiDisable.value = null
 933  }
 934}
 935
 936function initTitleOnly() {
 937  document.querySelectorAll('.custom-block').forEach(block => {
 938    const children = [...block.children]
 939    const hasOnlyTitle = children.every(el =>
 940      el.classList.contains('custom-block-title')
 941    )
 942    if (hasOnlyTitle) block.classList.add('title-only')
 943  })
 944}
 945
 946function initCopyButtonsInRoot(root: ParentNode) {
 947  root.querySelectorAll<HTMLTableElement>('table').forEach(table => {
 948    const headers = table.querySelectorAll<HTMLTableCellElement>('thead th')
 949    let manualColIndex = -1
 950    headers.forEach((th, i) => {
 951      if (th.textContent?.trim() === 'Manual') manualColIndex = i
 952    })
 953    if (manualColIndex === -1) return
 954
 955    // Track how many more rows each column is occupied by a rowspan from above
 956    const colOccupied: number[] = []
 957
 958    table.querySelectorAll<HTMLTableRowElement>('tbody tr').forEach(row => {
 959      const cells = Array.from(row.querySelectorAll('td'))
 960      let cellIdx = 0
 961      let col = 0
 962      let manualCell: HTMLTableCellElement | null = null
 963
 964      while (col <= manualColIndex) {
 965        // Column occupied by a rowspan from a previous row — skip it
 966        if ((colOccupied[col] ?? 0) > 0) {
 967          colOccupied[col]--
 968          col++
 969          continue
 970        }
 971
 972        if (cellIdx >= cells.length) break
 973        const cell = cells[cellIdx++]
 974        const colspan = cell.colSpan || 1
 975        const rowspan = cell.rowSpan || 1
 976
 977        // Register future occupation for rowspan > 1
 978        if (rowspan > 1) {
 979          for (let c = col; c < col + colspan; c++) {
 980            colOccupied[c] = (colOccupied[c] ?? 0) + (rowspan - 1)
 981          }
 982        }
 983
 984        if (col <= manualColIndex && col + colspan > manualColIndex) {
 985          manualCell = cell
 986        }
 987
 988        col += colspan
 989      }
 990
 991      if (!manualCell || manualCell.querySelector('.manual-copy-btn')) return
 992
 993      const link = manualCell.querySelector<HTMLAnchorElement>('a[href]')
 994      if (!link) return
 995      const url = link.getAttribute('href')!
 996
 997      const btn = document.createElement('button')
 998      btn.className = 'manual-copy-btn'
 999      btn.title = 'Copy URL'
1000      const icon = document.createElement('span')
1001      icon.className = 'i-lucide:copy'
1002      btn.appendChild(icon)
1003
1004      btn.addEventListener('click', async (e) => {
1005        e.preventDefault()
1006        try {
1007          await navigator.clipboard.writeText(url)
1008          icon.className = 'i-lucide:check'
1009          btn.classList.add('copied')
1010          setTimeout(() => {
1011            icon.className = 'i-lucide:copy'
1012            btn.classList.remove('copied')
1013          }, 2000)
1014        } catch {}
1015      })
1016
1017      manualCell.classList.add('has-manual-copy')
1018      manualCell.appendChild(btn)
1019    })
1020  })
1021}
1022
1023let copyButtonObserver: MutationObserver | null = null
1024
1025function setupManualCopyButtons() {
1026  initCopyButtonsInRoot(document)
1027
1028  copyButtonObserver?.disconnect()
1029  copyButtonObserver = new MutationObserver((mutations) => {
1030    for (const mutation of mutations) {
1031      for (const node of mutation.addedNodes) {
1032        if (!(node instanceof HTMLElement)) continue
1033        if (node.classList.contains('plugin-tabs--content')) {
1034          initCopyButtonsInRoot(node)
1035        } else {
1036          node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach(
1037            panel => initCopyButtonsInRoot(panel)
1038          )
1039        }
1040      }
1041    }
1042  })
1043  copyButtonObserver.observe(document.body, { childList: true, subtree: true })
1044}
1045
1046watch(
1047  () => route.path,
1048  () => nextTick(() => { initTitleOnly(); setupManualCopyButtons() }),
1049  { flush: 'post' }
1050)
1051
1052onMounted(() => {
1053  if (import.meta.env.SSR) return
1054
1055  window.addEventListener(BOOKMARK_CHANGE_EVENT, syncTocBookmarkStates)
1056
1057  initTitleOnly()
1058  nextTick(setupManualCopyButtons)
1059
1060  // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping
1061  const tooltipEl = document.createElement('div')
1062  tooltipEl.className = 'icon-tip-popup'
1063  document.body.appendChild(tooltipEl)
1064
1065  const showTooltip = (e: MouseEvent) => {
1066    const target = (e.target as HTMLElement).closest('.icon-tip') as
1067      | HTMLElement
1068      | null
1069    if (!target) return
1070    const tip = target.dataset.tip
1071    if (!tip) return
1072
1073    tooltipEl.textContent = tip
1074    tooltipEl.classList.add('visible')
1075
1076    const rect = target.getBoundingClientRect()
1077    const tipWidth = tooltipEl.offsetWidth
1078    const tipHeight = tooltipEl.offsetHeight
1079    let left = rect.left + rect.width / 2 - tipWidth / 2
1080    left = Math.max(8, Math.min(left, window.innerWidth - tipWidth - 8))
1081    const top = rect.top - tipHeight - 6
1082
1083    tooltipEl.style.left = `${left}px`
1084    tooltipEl.style.top = `${top}px`
1085  }
1086
1087  const hideTooltip = () => {
1088    tooltipEl.classList.remove('visible')
1089  }
1090
1091  document.addEventListener('mouseover', showTooltip)
1092  document.addEventListener('mouseout', hideTooltip)
1093  document.addEventListener('scroll', hideTooltip, true)
1094
1095  const onCaptureClick = (e: MouseEvent) => {
1096    if (!e.isTrusted) return
1097    const link = (e.target as HTMLElement).closest<HTMLAnchorElement>('a[href]')
1098    if (!link) return
1099    const raw = link.getAttribute('href') ?? ''
1100
1101    // ── Tab link: #tab-name or already-rewritten /path?tabs=name ──────────
1102    const tabFromHash = raw.startsWith('#' + TAB_LINK_MARKER)
1103      ? raw.slice(1 + TAB_LINK_MARKER.length)
1104      : null
1105    let tabFromQuery: string | null = null
1106    if (
1107      !e.defaultPrevented &&
1108      !tabFromHash &&
1109      raw.includes(`?${TAB_QUERY_PARAM}=`) &&
1110      !raw.includes('#')
1111    ) {
1112      try {
1113        const url = new URL(raw, window.location.href)
1114        const samePage = url.origin === window.location.origin &&
1115          url.pathname === window.location.pathname
1116        tabFromQuery = samePage
1117          ? url.searchParams.get(TAB_QUERY_PARAM)
1118          : null
1119      } catch {
1120        tabFromQuery = null
1121      }
1122    }
1123    const tabName = tabFromHash ?? tabFromQuery
1124
1125    if (tabName) {
1126      e.preventDefault()
1127      e.stopImmediatePropagation()
1128      window.history.pushState(null, '', buildUrlWithTabs([tabName]))
1129      rewriteAnchorLinks()
1130      void (async () => {
1131        const tabs = await selectTabsByPath([tabName])
1132        if (tabs) scrollToElement(getSelectedTabScrollTarget(tabs), false)
1133      })()
1134      return
1135    }
1136
1137    // ── Plain heading link: #name or already-rewritten /path#name ─────────
1138    // Only intercept when ?tabs= is present — otherwise let the router handle normally.
1139    if (!new URLSearchParams(window.location.search).has(TAB_QUERY_PARAM)) {
1140      return
1141    }
1142
1143    let hash: string | null = null
1144    if (raw.startsWith('#') && raw.length > 1) {
1145      hash = raw.slice(1)
1146    } else if (raw.startsWith(window.location.pathname + '#')) {
1147      hash = raw.slice(window.location.pathname.length + 1)
1148    }
1149    if (!hash) return
1150
1151    e.preventDefault()
1152    e.stopImmediatePropagation()
1153    window.history.pushState(null, '', `${window.location.pathname}#${hash}`)
1154    rewriteAnchorLinks()
1155    void tryOpenAnchoredContent()
1156  }
1157
1158  document.addEventListener('click', onCaptureClick, { capture: true })
1159
1160  useEventListener(document, 'click', (e: MouseEvent) => {
1161    if (!e.isTrusted) return
1162    queueTabQueryUpdateForSelection(e.target)
1163    queueCollapsibleQueryUpdate(e.target)
1164  })
1165
1166  useEventListener(document, 'keydown', (e: KeyboardEvent) => {
1167    if (!e.isTrusted || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')) {
1168      return
1169    }
1170
1171    queueTabQueryUpdateForSelection(e.target)
1172  })
1173
1174  onUnmounted(() => {
1175    document.removeEventListener('click', onCaptureClick, { capture: true })
1176    document.removeEventListener('mouseover', showTooltip)
1177    document.removeEventListener('mouseout', hideTooltip)
1178    document.removeEventListener('scroll', hideTooltip, true)
1179    tooltipEl.remove()
1180  })
1181
1182  // Arrow key scrolling + Escape close for sidebars and content
1183  let activeScrollTarget: HTMLElement | Window = window
1184
1185  useEventListener(document, 'pointerdown', (e: PointerEvent) => {
1186    const el = e.target as HTMLElement
1187    if (homeSidebarOpen.value && sidebarRef.value?.contains(el)) {
1188      activeScrollTarget = sidebarRef.value
1189    } else if (el.closest('.VPSidebar')) {
1190      activeScrollTarget = el.closest('.VPSidebar') as HTMLElement
1191    } else {
1192      activeScrollTarget = window
1193    }
1194  })
1195
1196  const pxPerFrame = 18
1197  let scrollDirection = 0
1198  let scrollRaf = 0
1199
1200  function tickScroll() {
1201    if (!scrollDirection) return
1202    activeScrollTarget.scrollBy({ top: scrollDirection * pxPerFrame })
1203    scrollRaf = requestAnimationFrame(tickScroll)
1204  }
1205
1206  function stopScroll() {
1207    scrollDirection = 0
1208    cancelAnimationFrame(scrollRaf)
1209  }
1210
1211  useEventListener(document, 'keydown', (e: KeyboardEvent) => {
1212    if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp' && e.key !== 'Escape') {
1213      return
1214    }
1215
1216    if (e.key === 'Escape') {
1217      if (homeSidebarOpen.value) homeSidebarOpen.value = false
1218      return
1219    }
1220
1221    e.preventDefault()
1222    const dir = e.key === 'ArrowDown' ? 1 : -1
1223    if (scrollDirection === dir) return
1224    scrollDirection = dir
1225    cancelAnimationFrame(scrollRaf)
1226    scrollRaf = requestAnimationFrame(tickScroll)
1227  })
1228
1229  useEventListener(document, 'keyup', (e: KeyboardEvent) => {
1230    if (e.key === 'ArrowDown' || e.key === 'ArrowUp') stopScroll()
1231  })
1232
1233  onUnmounted(stopScroll)
1234
1235  // Close home NavScreen on outside click
1236  useEventListener(document, 'click', (e: Event) => {
1237    if (!isHome.value) return
1238    const screen = document.getElementById('VPNavScreen')
1239    if (!screen) return
1240    const hamburger = document.querySelector('.VPNavBarHamburger')
1241    if (
1242      screen.contains(e.target as Node) || hamburger?.contains(e.target as Node)
1243    ) return
1244    requestAnimationFrame(() => (hamburger as HTMLElement)?.click())
1245  })
1246
1247  // Storage changed in other documents.
1248  useEventListener(window, 'storage', () => {
1249    reloadTakodachi()
1250  })
1251
1252  // Storage changed in the same document.
1253  useEventListener(window, customStorageEventName, () => {
1254    reloadTakodachi()
1255  })
1256
1257  reloadTakodachi()
1258})
1259
1260onUnmounted(() => {
1261  outlineFollowObserver?.disconnect()
1262  copyButtonObserver?.disconnect()
1263  tocMutationObserver?.disconnect()
1264  cancelAnimationFrame(outlineFollowRaf)
1265  cancelAnimationFrame(tocRaf)
1266  takodachiDisable.value && takodachiDisable.value()
1267  window.removeEventListener(BOOKMARK_CHANGE_EVENT, syncTocBookmarkStates)
1268})
1269</script>
1270
1271<template>
1272  <Layout>
1273    <template #layout-top>
1274      <img
1275        id="takodachi"
1276        ref="takodachiRef"
1277        src="/takodachi.webp"
1278        alt="Takodachi"
1279        class="pointer-events-none fixed absolute z-[9999] h-10 w-10 opacity-0 transition-opacity duration-500"
1280        :style="{
1281          left: `${position.x}px`,
1282          top: `${position.y}px`
1283        }"
1284      />
1285      <!-- Home sidebar menu -->
1286      <template v-if="isHome">
1287        <Transition name="home-fade">
1288          <div
1289            v-if="homeSidebarOpen"
1290            class="home-sidebar-backdrop"
1291            @click="homeSidebarOpen = false"
1292          />
1293        </Transition>
1294        <Transition name="home-slide" @after-enter="onSidebarEnter">
1295          <aside
1296            v-if="homeSidebarOpen"
1297            ref="sidebarRef"
1298            class="home-sidebar"
1299            tabindex="-1"
1300            @click.stop
1301          >
1302            <div class="home-sidebar-header">
1303              <a href="/" class="home-sidebar-logo">
1304                <img
1305                  v-if="logoSrc"
1306                  :src="logoSrc"
1307                  class="home-sidebar-logo-img"
1308                  alt="Logo"
1309                />
1310                <span>{{ theme.siteTitle ?? site.title }}</span>
1311              </a>
1312            </div>
1313            <nav id="VPSidebarNav" class="home-sidebar-nav">
1314              <VPSidebarGroup :items="homeSidebarGroups" />
1315              <SidebarCard />
1316            </nav>
1317          </aside>
1318        </Transition>
1319      </template>
1320    </template>
1321    <template #doc-before>
1322      <!-- Breadcrumb Navigation -->
1323      <nav
1324        v-if="breadcrumbs.length > 0"
1325        class="breadcrumb mb-6 text-sm text-text-2"
1326        aria-label="Breadcrumb"
1327      >
1328        <ol class="flex flex-wrap items-center gap-2">
1329          <li>
1330            <a href="/" class="hover:text-primary transition-colors">
1331              <span class="i-lucide:home"></span>
1332            </a>
1333          </li>
1334          <li
1335            v-for="(crumb, index) in breadcrumbs"
1336            :key="crumb.link || index"
1337            class="flex items-center gap-2"
1338          >
1339            <span
1340              class="i-lucide:chevron-right text-text-3 flex-shrink-0"
1341            ></span>
1342            <span
1343              v-if="index === breadcrumbs.length - 1"
1344              v-html="crumb.text"
1345              class="font-medium text-text-1 break-words"
1346            ></span>
1347            <a
1348              v-else
1349              :href="crumb.link"
1350              v-html="crumb.text"
1351              class="hover:text-primary transition-colors break-words"
1352            ></a>
1353          </li>
1354        </ol>
1355      </nav>
1356    </template>
1357    <template #not-found>
1358      <NotFoundComponent />
1359    </template>
1360    <template #sidebar-nav-after>
1361      <SidebarCard />
1362    </template>
1363    <template #home-hero-info-before>
1364      <AnnouncementPill />
1365    </template>
1366    <template #nav-bar-content-after>
1367      <NavActions />
1368    </template>
1369    <template #nav-screen-content-before>
1370      <nav v-if="isHome" id="VPSidebarNavMobile" class="home-screen-nav">
1371        <VPSidebarGroup :items="homeSidebarGroups" />
1372      </nav>
1373    </template>
1374    <template #nav-screen-content-after>
1375      <NolebaseEnhancedReadabilitiesScreenMenu />
1376    </template>
1377    <template #layout-bottom>
1378      <SiteFooter />
1379    </template>
1380
1381    <template #nav-bar-title-before>
1382      <span
1383        v-if="isHome"
1384        class="home-menu-btn"
1385        role="button"
1386        tabindex="0"
1387        aria-label="Menu"
1388        @click.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
1389        @keydown.enter.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
1390      >
1391        <span class="vpi-align-left home-menu-icon" />
1392      </span>
1393    </template>
1394  </Layout>
1395</template>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form