@vuepress/theme-default 2.0.0-beta.50-pre → 2.0.0-beta.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/lib/client/components/AutoLink.vue +114 -0
  2. package/lib/client/components/DropdownTransition.vue +21 -0
  3. package/lib/client/components/Home.vue +15 -0
  4. package/lib/client/components/HomeContent.vue +5 -0
  5. package/lib/client/components/HomeFeatures.vue +23 -0
  6. package/lib/client/components/HomeFooter.vue +17 -0
  7. package/lib/client/components/HomeHero.vue +97 -0
  8. package/lib/client/components/Navbar.vue +75 -0
  9. package/lib/client/components/NavbarBrand.vue +55 -0
  10. package/lib/client/components/NavbarDropdown.vue +126 -0
  11. package/lib/client/components/NavbarItems.vue +163 -0
  12. package/lib/client/components/Page.vue +24 -0
  13. package/lib/client/components/PageMeta.vue +124 -0
  14. package/lib/client/components/PageNav.vue +103 -0
  15. package/lib/client/components/Sidebar.vue +13 -0
  16. package/lib/client/components/SidebarItem.vue +87 -0
  17. package/lib/client/components/SidebarItems.vue +57 -0
  18. package/lib/client/components/ToggleColorModeButton.vue +57 -0
  19. package/lib/client/components/ToggleSidebarButton.vue +24 -0
  20. package/lib/client/components/global/Badge.vue +31 -0
  21. package/lib/client/components/global/CodeGroup.d.ts +4 -0
  22. package/lib/client/components/global/CodeGroup.js +106 -0
  23. package/lib/client/components/global/CodeGroupItem.vue +31 -0
  24. package/lib/client/components/global/index.d.ts +4 -0
  25. package/lib/client/components/global/index.js +4 -0
  26. package/lib/client/composables/index.d.ts +6 -0
  27. package/lib/client/composables/index.js +6 -0
  28. package/lib/client/composables/useDarkMode.d.ts +12 -0
  29. package/lib/client/composables/useDarkMode.js +57 -0
  30. package/lib/client/composables/useNavLink.d.ts +14 -0
  31. package/lib/client/composables/useNavLink.js +18 -0
  32. package/lib/client/composables/useResolveRouteWithRedirect.d.ts +5 -0
  33. package/lib/client/composables/useResolveRouteWithRedirect.js +24 -0
  34. package/lib/client/composables/useScrollPromise.d.ts +6 -0
  35. package/lib/client/composables/useScrollPromise.js +14 -0
  36. package/lib/client/composables/useSidebarItems.d.ts +36 -0
  37. package/lib/client/composables/useSidebarItems.js +118 -0
  38. package/lib/client/composables/useThemeData.d.ts +4 -0
  39. package/lib/client/composables/useThemeData.js +3 -0
  40. package/lib/client/config.d.ts +3 -0
  41. package/lib/client/config.js +44 -0
  42. package/lib/client/index.d.ts +3 -0
  43. package/lib/client/index.js +3 -0
  44. package/lib/client/layouts/Layout.vue +134 -0
  45. package/lib/client/layouts/NotFound.vue +27 -0
  46. package/lib/client/shim.d.ts +5 -0
  47. package/lib/client/styles/_mixins.scss +20 -0
  48. package/lib/client/styles/_variables.scss +11 -0
  49. package/lib/client/styles/arrow.scss +37 -0
  50. package/lib/client/styles/badge.scss +31 -0
  51. package/lib/client/styles/code-group.scss +69 -0
  52. package/lib/client/styles/code.scss +266 -0
  53. package/lib/client/styles/custom-container.scss +88 -0
  54. package/lib/client/styles/home.scss +168 -0
  55. package/lib/client/styles/index.scss +19 -0
  56. package/lib/client/styles/layout.scss +198 -0
  57. package/lib/client/styles/navbar-dropdown.scss +187 -0
  58. package/lib/client/styles/navbar.scss +177 -0
  59. package/lib/client/styles/normalize.scss +177 -0
  60. package/lib/client/styles/page.scss +83 -0
  61. package/lib/client/styles/sidebar.scss +134 -0
  62. package/lib/client/styles/toc.scss +5 -0
  63. package/lib/client/styles/transitions.scss +22 -0
  64. package/lib/client/styles/vars-dark.scss +46 -0
  65. package/lib/client/styles/vars.scss +133 -0
  66. package/lib/client/utils/index.d.ts +3 -0
  67. package/lib/client/utils/index.js +3 -0
  68. package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
  69. package/lib/client/utils/isActiveSidebarItem.js +20 -0
  70. package/lib/client/utils/resolveEditLink.d.ts +9 -0
  71. package/lib/client/utils/resolveEditLink.js +29 -0
  72. package/lib/client/utils/resolveRepoType.d.ts +2 -0
  73. package/lib/client/utils/resolveRepoType.js +12 -0
  74. package/lib/node/defaultTheme.d.ts +10 -0
  75. package/lib/node/defaultTheme.js +119 -0
  76. package/lib/node/index.d.ts +5 -0
  77. package/lib/node/index.js +5 -0
  78. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
  79. package/lib/node/utils/assignDefaultLocaleOptions.js +56 -0
  80. package/lib/node/utils/index.d.ts +2 -0
  81. package/lib/node/utils/index.js +2 -0
  82. package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
  83. package/lib/node/utils/resolveContainerPluginOptions.js +17 -0
  84. package/lib/shared/index.d.ts +3 -0
  85. package/lib/shared/index.js +3 -0
  86. package/lib/shared/nav.d.ts +43 -0
  87. package/lib/shared/nav.js +1 -0
  88. package/lib/shared/options.d.ts +243 -0
  89. package/lib/shared/options.js +1 -0
  90. package/lib/shared/page.d.ts +40 -0
  91. package/lib/shared/page.js +1 -0
  92. package/package.json +22 -20
  93. package/templates/build.html +33 -0
@@ -0,0 +1,163 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import NavbarDropdown from '@theme/NavbarDropdown.vue'
4
+ import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
5
+ import { isLinkHttp, isString } from '@vuepress/shared'
6
+ import { computed } from 'vue'
7
+ import type { ComputedRef } from 'vue'
8
+ import { useRouter } from 'vue-router'
9
+ import type {
10
+ NavbarGroup,
11
+ NavbarItem,
12
+ ResolvedNavbarItem,
13
+ } from '../../shared/index.js'
14
+ import { useNavLink, useThemeLocaleData } from '../composables/index.js'
15
+ import { resolveRepoType } from '../utils/index.js'
16
+
17
+ /**
18
+ * Get navbar config of select language dropdown
19
+ */
20
+ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
21
+ const router = useRouter()
22
+ const routeLocale = useRouteLocale()
23
+ const siteLocale = useSiteLocaleData()
24
+ const themeLocale = useThemeLocaleData()
25
+
26
+ return computed<ResolvedNavbarItem[]>(() => {
27
+ const localePaths = Object.keys(siteLocale.value.locales)
28
+ // do not display language selection dropdown if there is only one language
29
+ if (localePaths.length < 2) {
30
+ return []
31
+ }
32
+ const currentPath = router.currentRoute.value.path
33
+ const currentFullPath = router.currentRoute.value.fullPath
34
+ const currentHash = router.currentRoute.value.hash
35
+
36
+ const languageDropdown: ResolvedNavbarItem = {
37
+ text: themeLocale.value.selectLanguageText ?? 'unknown language',
38
+ ariaLabel:
39
+ themeLocale.value.selectLanguageAriaLabel ??
40
+ themeLocale.value.selectLanguageText ??
41
+ 'unknown language',
42
+ children: localePaths.map((targetLocalePath) => {
43
+ // target locale config of this language link
44
+ const targetSiteLocale =
45
+ siteLocale.value.locales?.[targetLocalePath] ?? {}
46
+ const targetThemeLocale =
47
+ themeLocale.value.locales?.[targetLocalePath] ?? {}
48
+ const targetLang = `${targetSiteLocale.lang}`
49
+
50
+ const text = targetThemeLocale.selectLanguageName ?? targetLang
51
+ let link
52
+
53
+ if (targetLang === siteLocale.value.lang) {
54
+ // if the target language is current language
55
+ // stay at current link
56
+ link = currentFullPath
57
+ } else {
58
+ // if the target language is not current language
59
+ // try to link to the corresponding page of current page
60
+ // or fallback to homepage
61
+ const targetLocalePage = currentPath.replace(
62
+ routeLocale.value,
63
+ targetLocalePath
64
+ )
65
+ if (
66
+ router.getRoutes().some((item) => item.path === targetLocalePage)
67
+ ) {
68
+ // try to keep current hash across languages
69
+ link = `${targetLocalePage}${currentHash}`
70
+ } else {
71
+ link = targetThemeLocale.home ?? targetLocalePath
72
+ }
73
+ }
74
+
75
+ return {
76
+ text,
77
+ link,
78
+ }
79
+ }),
80
+ }
81
+
82
+ return [languageDropdown]
83
+ })
84
+ }
85
+
86
+ /**
87
+ * Get navbar config of repository link
88
+ */
89
+ const useNavbarRepo = (): ComputedRef<ResolvedNavbarItem[]> => {
90
+ const themeLocale = useThemeLocaleData()
91
+
92
+ const repo = computed(() => themeLocale.value.repo)
93
+ const repoType = computed(() =>
94
+ repo.value ? resolveRepoType(repo.value) : null
95
+ )
96
+
97
+ const repoLink = computed(() => {
98
+ if (repo.value && !isLinkHttp(repo.value)) {
99
+ return `https://github.com/${repo.value}`
100
+ }
101
+
102
+ return repo.value
103
+ })
104
+
105
+ const repoLabel = computed(() => {
106
+ if (!repoLink.value) return null
107
+ if (themeLocale.value.repoLabel) return themeLocale.value.repoLabel
108
+ if (repoType.value === null) return 'Source'
109
+ return repoType.value
110
+ })
111
+
112
+ return computed(() => {
113
+ if (!repoLink.value || !repoLabel.value) {
114
+ return []
115
+ }
116
+
117
+ return [
118
+ {
119
+ text: repoLabel.value,
120
+ link: repoLink.value,
121
+ },
122
+ ]
123
+ })
124
+ }
125
+
126
+ const resolveNavbarItem = (
127
+ item: NavbarItem | NavbarGroup | string
128
+ ): ResolvedNavbarItem => {
129
+ if (isString(item)) {
130
+ return useNavLink(item)
131
+ }
132
+ if ((item as NavbarGroup).children) {
133
+ return {
134
+ ...item,
135
+ children: (item as NavbarGroup).children.map(resolveNavbarItem),
136
+ }
137
+ }
138
+ return item as ResolvedNavbarItem
139
+ }
140
+
141
+ const useNavbarConfig = (): ComputedRef<ResolvedNavbarItem[]> => {
142
+ const themeLocale = useThemeLocaleData()
143
+ return computed(() => (themeLocale.value.navbar || []).map(resolveNavbarItem))
144
+ }
145
+
146
+ const navbarConfig = useNavbarConfig()
147
+ const navbarSelectLanguage = useNavbarSelectLanguage()
148
+ const navbarRepo = useNavbarRepo()
149
+ const navbarLinks = computed(() => [
150
+ ...navbarConfig.value,
151
+ ...navbarSelectLanguage.value,
152
+ ...navbarRepo.value,
153
+ ])
154
+ </script>
155
+
156
+ <template>
157
+ <nav v-if="navbarLinks.length" class="navbar-items">
158
+ <div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
159
+ <NavbarDropdown v-if="item.children" :item="item" />
160
+ <AutoLink v-else :item="item" />
161
+ </div>
162
+ </nav>
163
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import PageMeta from '@theme/PageMeta.vue'
3
+ import PageNav from '@theme/PageNav.vue'
4
+ </script>
5
+
6
+ <template>
7
+ <main class="page">
8
+ <slot name="top" />
9
+
10
+ <div class="theme-default-content">
11
+ <slot name="content-top" />
12
+
13
+ <Content />
14
+
15
+ <slot name="content-bottom" />
16
+ </div>
17
+
18
+ <PageMeta />
19
+
20
+ <PageNav />
21
+
22
+ <slot name="bottom" />
23
+ </main>
24
+ </template>
@@ -0,0 +1,124 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import { usePageData, usePageFrontmatter } from '@vuepress/client'
4
+ import { computed } from 'vue'
5
+ import type { ComputedRef } from 'vue'
6
+ import type {
7
+ DefaultThemeNormalPageFrontmatter,
8
+ DefaultThemePageData,
9
+ NavLink,
10
+ } from '../../shared/index.js'
11
+ import { useThemeLocaleData } from '../composables/index.js'
12
+ import { resolveEditLink } from '../utils/index.js'
13
+
14
+ const useEditNavLink = (): ComputedRef<null | NavLink> => {
15
+ const themeLocale = useThemeLocaleData()
16
+ const page = usePageData<DefaultThemePageData>()
17
+ const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
18
+
19
+ return computed(() => {
20
+ const showEditLink =
21
+ frontmatter.value.editLink ?? themeLocale.value.editLink ?? true
22
+ if (!showEditLink) {
23
+ return null
24
+ }
25
+
26
+ const {
27
+ repo,
28
+ docsRepo = repo,
29
+ docsBranch = 'main',
30
+ docsDir = '',
31
+ editLinkText,
32
+ } = themeLocale.value
33
+
34
+ if (!docsRepo) return null
35
+
36
+ const editLink = resolveEditLink({
37
+ docsRepo,
38
+ docsBranch,
39
+ docsDir,
40
+ filePathRelative: page.value.filePathRelative,
41
+ editLinkPattern:
42
+ frontmatter.value.editLinkPattern ?? themeLocale.value.editLinkPattern,
43
+ })
44
+
45
+ if (!editLink) return null
46
+
47
+ return {
48
+ text: editLinkText ?? 'Edit this page',
49
+ link: editLink,
50
+ }
51
+ })
52
+ }
53
+
54
+ const useLastUpdated = (): ComputedRef<null | string> => {
55
+ const themeLocale = useThemeLocaleData()
56
+ const page = usePageData<DefaultThemePageData>()
57
+ const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
58
+
59
+ return computed(() => {
60
+ const showLastUpdated =
61
+ frontmatter.value.lastUpdated ?? themeLocale.value.lastUpdated ?? true
62
+
63
+ if (!showLastUpdated) return null
64
+
65
+ if (!page.value.git?.updatedTime) return null
66
+
67
+ const updatedDate = new Date(page.value.git?.updatedTime)
68
+
69
+ return updatedDate.toLocaleString()
70
+ })
71
+ }
72
+
73
+ const useContributors = (): ComputedRef<
74
+ null | Required<DefaultThemePageData['git']>['contributors']
75
+ > => {
76
+ const themeLocale = useThemeLocaleData()
77
+ const page = usePageData<DefaultThemePageData>()
78
+ const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
79
+
80
+ return computed(() => {
81
+ const showContributors =
82
+ frontmatter.value.contributors ?? themeLocale.value.contributors ?? true
83
+
84
+ if (!showContributors) return null
85
+
86
+ return page.value.git?.contributors ?? null
87
+ })
88
+ }
89
+
90
+ const themeLocale = useThemeLocaleData()
91
+ const editNavLink = useEditNavLink()
92
+ const lastUpdated = useLastUpdated()
93
+ const contributors = useContributors()
94
+ </script>
95
+
96
+ <template>
97
+ <footer class="page-meta">
98
+ <div v-if="editNavLink" class="meta-item edit-link">
99
+ <AutoLink class="meta-item-label" :item="editNavLink" />
100
+ </div>
101
+
102
+ <div v-if="lastUpdated" class="meta-item last-updated">
103
+ <span class="meta-item-label">{{ themeLocale.lastUpdatedText }}: </span>
104
+ <ClientOnly>
105
+ <span class="meta-item-info">{{ lastUpdated }}</span>
106
+ </ClientOnly>
107
+ </div>
108
+
109
+ <div
110
+ v-if="contributors && contributors.length"
111
+ class="meta-item contributors"
112
+ >
113
+ <span class="meta-item-label">{{ themeLocale.contributorsText }}: </span>
114
+ <span class="meta-item-info">
115
+ <template v-for="(contributor, index) in contributors" :key="index">
116
+ <span class="contributor" :title="`email: ${contributor.email}`">
117
+ {{ contributor.name }}
118
+ </span>
119
+ <template v-if="index !== contributors.length - 1">, </template>
120
+ </template>
121
+ </span>
122
+ </div>
123
+ </footer>
124
+ </template>
@@ -0,0 +1,103 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import { usePageFrontmatter } from '@vuepress/client'
4
+ import { isPlainObject, isString } from '@vuepress/shared'
5
+ import { computed } from 'vue'
6
+ import { useRoute } from 'vue-router'
7
+ import type {
8
+ DefaultThemeNormalPageFrontmatter,
9
+ NavLink,
10
+ ResolvedSidebarItem,
11
+ } from '../../shared/index.js'
12
+ import { useNavLink, useSidebarItems } from '../composables/index.js'
13
+
14
+ /**
15
+ * Resolve `prev` or `next` config from frontmatter
16
+ */
17
+ const resolveFromFrontmatterConfig = (
18
+ conf: unknown
19
+ ): null | false | NavLink => {
20
+ if (conf === false) {
21
+ return null
22
+ }
23
+
24
+ if (isString(conf)) {
25
+ return useNavLink(conf)
26
+ }
27
+
28
+ if (isPlainObject<NavLink>(conf)) {
29
+ return conf
30
+ }
31
+
32
+ return false
33
+ }
34
+
35
+ /**
36
+ * Resolve `prev` or `next` config from sidebar items
37
+ */
38
+ const resolveFromSidebarItems = (
39
+ sidebarItems: ResolvedSidebarItem[],
40
+ currentPath: string,
41
+ offset: number
42
+ ): null | NavLink => {
43
+ const index = sidebarItems.findIndex((item) => item.link === currentPath)
44
+ if (index !== -1) {
45
+ const targetItem = sidebarItems[index + offset]
46
+ if (!targetItem?.link) {
47
+ return null
48
+ }
49
+ return targetItem as NavLink
50
+ }
51
+
52
+ for (const item of sidebarItems) {
53
+ if (item.children) {
54
+ const childResult = resolveFromSidebarItems(
55
+ item.children,
56
+ currentPath,
57
+ offset
58
+ )
59
+ if (childResult) {
60
+ return childResult
61
+ }
62
+ }
63
+ }
64
+
65
+ return null
66
+ }
67
+
68
+ const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
69
+ const sidebarItems = useSidebarItems()
70
+ const route = useRoute()
71
+
72
+ const prevNavLink = computed(() => {
73
+ const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev)
74
+ if (prevConfig !== false) {
75
+ return prevConfig
76
+ }
77
+
78
+ return resolveFromSidebarItems(sidebarItems.value, route.path, -1)
79
+ })
80
+
81
+ const nextNavLink = computed(() => {
82
+ const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next)
83
+ if (nextConfig !== false) {
84
+ return nextConfig
85
+ }
86
+
87
+ return resolveFromSidebarItems(sidebarItems.value, route.path, 1)
88
+ })
89
+ </script>
90
+
91
+ <template>
92
+ <nav v-if="prevNavLink || nextNavLink" class="page-nav">
93
+ <p class="inner">
94
+ <span v-if="prevNavLink" class="prev">
95
+ <AutoLink :item="prevNavLink" />
96
+ </span>
97
+
98
+ <span v-if="nextNavLink" class="next">
99
+ <AutoLink :item="nextNavLink" />
100
+ </span>
101
+ </p>
102
+ </nav>
103
+ </template>
@@ -0,0 +1,13 @@
1
+ <script setup lang="ts">
2
+ import NavbarItems from '@theme/NavbarItems.vue'
3
+ import SidebarItems from '@theme/SidebarItems.vue'
4
+ </script>
5
+
6
+ <template>
7
+ <aside class="sidebar">
8
+ <NavbarItems />
9
+ <slot name="top" />
10
+ <SidebarItems />
11
+ <slot name="bottom" />
12
+ </aside>
13
+ </template>
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import AutoLink from '@theme/AutoLink.vue'
3
+ import DropdownTransition from '@theme/DropdownTransition.vue'
4
+ import { useToggle } from '@vueuse/core'
5
+ import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
6
+ import type { PropType } from 'vue'
7
+ import { useRoute, useRouter } from 'vue-router'
8
+ import type { ResolvedSidebarItem } from '../../shared/index.js'
9
+ import { isActiveSidebarItem } from '../utils/index.js'
10
+
11
+ const props = defineProps({
12
+ item: {
13
+ type: Object as PropType<ResolvedSidebarItem>,
14
+ required: true,
15
+ },
16
+ depth: {
17
+ type: Number,
18
+ required: false,
19
+ default: 0,
20
+ },
21
+ })
22
+
23
+ const { item, depth } = toRefs(props)
24
+ const route = useRoute()
25
+ const router = useRouter()
26
+
27
+ const isActive = computed(() => isActiveSidebarItem(item.value, route))
28
+ const itemClass = computed(() => ({
29
+ 'sidebar-item': true,
30
+ 'sidebar-heading': depth.value === 0,
31
+ 'active': isActive.value,
32
+ 'collapsible': item.value.collapsible,
33
+ }))
34
+
35
+ const isOpenDefault = computed(() =>
36
+ item.value.collapsible ? isActive.value : true
37
+ )
38
+ const [isOpen, toggleIsOpen] = useToggle(isOpenDefault.value)
39
+ const onClick = (e: Event): void => {
40
+ if (item.value.collapsible) {
41
+ e.preventDefault()
42
+ // toggle open status on click
43
+ toggleIsOpen()
44
+ }
45
+ }
46
+
47
+ // reset open status after navigation
48
+ const unregisterRouterHook = router.afterEach((to) => {
49
+ nextTick(() => {
50
+ isOpen.value = isOpenDefault.value
51
+ })
52
+ })
53
+ onBeforeUnmount(() => {
54
+ unregisterRouterHook()
55
+ })
56
+ </script>
57
+
58
+ <template>
59
+ <li>
60
+ <AutoLink v-if="item.link" :class="itemClass" :item="item" />
61
+ <p
62
+ v-else
63
+ tabindex="0"
64
+ :class="itemClass"
65
+ @click="onClick"
66
+ @keydown.enter="onClick"
67
+ >
68
+ {{ item.text }}
69
+ <span
70
+ v-if="item.collapsible"
71
+ class="arrow"
72
+ :class="isOpen ? 'down' : 'right'"
73
+ />
74
+ </p>
75
+
76
+ <DropdownTransition v-if="item.children?.length">
77
+ <ul v-show="isOpen" class="sidebar-item-children">
78
+ <SidebarItem
79
+ v-for="child in item.children"
80
+ :key="`${depth}${child.text}${child.link}`"
81
+ :item="child"
82
+ :depth="depth + 1"
83
+ />
84
+ </ul>
85
+ </DropdownTransition>
86
+ </li>
87
+ </template>
@@ -0,0 +1,57 @@
1
+ <script setup lang="ts">
2
+ import SidebarItem from '@theme/SidebarItem.vue'
3
+ import { onMounted, watch } from 'vue'
4
+ import { useRoute } from 'vue-router'
5
+ import { useSidebarItems } from '../composables/index.js'
6
+
7
+ const route = useRoute()
8
+ const sidebarItems = useSidebarItems()
9
+
10
+ onMounted(() => {
11
+ watch(
12
+ () => route.hash,
13
+ (hash) => {
14
+ // get the sidebar DOM
15
+ const sidebar = document.querySelector('.sidebar')
16
+ if (!sidebar) return
17
+
18
+ // get the active sidebar item DOM, whose href equals to the current route
19
+ const activeSidebarItem = document.querySelector(
20
+ `.sidebar a.sidebar-item[href="${route.path}${hash}"]`
21
+ )
22
+ if (!activeSidebarItem) return
23
+
24
+ // get the top and height of the sidebar
25
+ const { top: sidebarTop, height: sidebarHeight } =
26
+ sidebar.getBoundingClientRect()
27
+ // get the top and height of the active sidebar item
28
+ const { top: activeSidebarItemTop, height: activeSidebarItemHeight } =
29
+ activeSidebarItem.getBoundingClientRect()
30
+
31
+ // when the active sidebar item overflows the top edge of sidebar
32
+ if (activeSidebarItemTop < sidebarTop) {
33
+ // scroll to the top edge of sidebar
34
+ activeSidebarItem.scrollIntoView(true)
35
+ }
36
+ // when the active sidebar item overflows the bottom edge of sidebar
37
+ else if (
38
+ activeSidebarItemTop + activeSidebarItemHeight >
39
+ sidebarTop + sidebarHeight
40
+ ) {
41
+ // scroll to the bottom edge of sidebar
42
+ activeSidebarItem.scrollIntoView(false)
43
+ }
44
+ }
45
+ )
46
+ })
47
+ </script>
48
+
49
+ <template>
50
+ <ul v-if="sidebarItems.length" class="sidebar-items">
51
+ <SidebarItem
52
+ v-for="item in sidebarItems"
53
+ :key="`${item.text}${item.link}`"
54
+ :item="item"
55
+ />
56
+ </ul>
57
+ </template>
@@ -0,0 +1,57 @@
1
+ <script setup lang="ts">
2
+ import { useDarkMode, useThemeLocaleData } from '../composables/index.js'
3
+
4
+ const themeLocale = useThemeLocaleData()
5
+ const isDarkMode = useDarkMode()
6
+
7
+ const toggleColorMode = (): void => {
8
+ isDarkMode.value = !isDarkMode.value
9
+ }
10
+ </script>
11
+
12
+ <template>
13
+ <button
14
+ class="toggle-color-mode-button"
15
+ :title="themeLocale.toggleColorMode"
16
+ @click="toggleColorMode"
17
+ >
18
+ <svg
19
+ v-show="!isDarkMode"
20
+ class="icon"
21
+ focusable="false"
22
+ viewBox="0 0 32 32"
23
+ >
24
+ <path
25
+ d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z"
26
+ fill="currentColor"
27
+ />
28
+ <path
29
+ d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z"
30
+ fill="currentColor"
31
+ />
32
+ <path d="M2 15.005h5v2H2z" fill="currentColor" />
33
+ <path
34
+ d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z"
35
+ fill="currentColor"
36
+ />
37
+ <path d="M15 25.005h2v5h-2z" fill="currentColor" />
38
+ <path
39
+ d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z"
40
+ fill="currentColor"
41
+ />
42
+ <path d="M25 15.005h5v2h-5z" fill="currentColor" />
43
+ <path
44
+ d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z"
45
+ fill="currentColor"
46
+ />
47
+ <path d="M15 2.005h2v5h-2z" fill="currentColor" />
48
+ </svg>
49
+
50
+ <svg v-show="isDarkMode" class="icon" focusable="false" viewBox="0 0 32 32">
51
+ <path
52
+ d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z"
53
+ fill="currentColor"
54
+ />
55
+ </svg>
56
+ </button>
57
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import { useThemeLocaleData } from '../composables/index.js'
3
+
4
+ defineEmits(['toggle'])
5
+
6
+ const themeLocale = useThemeLocaleData()
7
+ </script>
8
+
9
+ <template>
10
+ <div
11
+ class="toggle-sidebar-button"
12
+ :title="themeLocale.toggleSidebar"
13
+ aria-expanded="false"
14
+ role="button"
15
+ tabindex="0"
16
+ @click="$emit('toggle')"
17
+ >
18
+ <div class="icon" aria-hidden="true">
19
+ <span></span>
20
+ <span></span>
21
+ <span></span>
22
+ </div>
23
+ </div>
24
+ </template>
@@ -0,0 +1,31 @@
1
+ <script setup lang="ts">
2
+ defineProps({
3
+ type: {
4
+ type: String,
5
+ required: false,
6
+ default: 'tip',
7
+ },
8
+ text: {
9
+ type: String,
10
+ required: false,
11
+ default: '',
12
+ },
13
+ vertical: {
14
+ type: String,
15
+ required: false,
16
+ default: undefined,
17
+ },
18
+ })
19
+ </script>
20
+
21
+ <template>
22
+ <span
23
+ class="badge"
24
+ :class="type"
25
+ :style="{
26
+ verticalAlign: vertical,
27
+ }"
28
+ >
29
+ <slot>{{ text }}</slot>
30
+ </span>
31
+ </template>
@@ -0,0 +1,4 @@
1
+ import type { VNode } from 'vue';
2
+ export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
3
+ [key: string]: any;
4
+ }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;