@vuepress/theme-default 2.0.0-beta.9 → 2.0.0-rc.1
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.
- package/LICENSE +1 -1
- package/lib/client/components/AutoLink.vue +113 -0
- package/lib/client/components/DropdownTransition.vue +15 -24
- package/lib/client/components/Home.vue +12 -130
- package/lib/client/components/HomeContent.vue +5 -0
- package/lib/client/components/HomeFeatures.vue +22 -0
- package/lib/client/components/HomeFooter.vue +17 -0
- package/lib/client/components/HomeHero.vue +97 -0
- package/lib/client/components/Navbar.vue +60 -95
- package/lib/client/components/NavbarBrand.vue +55 -0
- package/lib/client/components/NavbarDropdown.vue +126 -0
- package/lib/client/components/{NavbarLinks.vue → NavbarItems.vue} +81 -61
- package/lib/client/components/Page.vue +16 -15
- package/lib/client/components/PageMeta.vue +51 -66
- package/lib/client/components/PageNav.vue +61 -64
- package/lib/client/components/Sidebar.vue +12 -32
- package/lib/client/components/SidebarItem.vue +87 -0
- package/lib/client/components/SidebarItems.vue +57 -0
- package/lib/client/components/ToggleColorModeButton.vue +57 -0
- package/lib/client/components/ToggleSidebarButton.vue +21 -24
- package/lib/client/components/global/Badge.vue +24 -26
- package/lib/client/components/global/CodeGroup.d.ts +5 -4
- package/lib/client/components/global/CodeGroup.js +85 -17
- package/lib/client/components/global/CodeGroupItem.vue +22 -20
- package/lib/client/components/global/index.d.ts +4 -0
- package/lib/client/components/global/index.js +4 -0
- package/lib/client/composables/index.d.ts +5 -5
- package/lib/client/composables/index.js +5 -5
- package/lib/client/composables/useDarkMode.d.ts +12 -0
- package/lib/client/composables/useDarkMode.js +57 -0
- package/lib/client/composables/useScrollPromise.js +1 -1
- package/lib/client/composables/useSidebarItems.d.ts +14 -8
- package/lib/client/composables/useSidebarItems.js +49 -48
- package/lib/client/composables/useThemeData.d.ts +2 -2
- package/lib/client/composables/useThemeData.js +1 -1
- package/lib/client/composables/useUpdateDeviceStatus.d.ts +7 -0
- package/lib/client/composables/useUpdateDeviceStatus.js +25 -0
- package/lib/client/config.d.ts +4 -0
- package/lib/client/config.js +44 -0
- package/lib/client/index.d.ts +3 -4
- package/lib/client/index.js +3 -2
- package/lib/client/layouts/Layout.vue +133 -136
- package/lib/client/layouts/NotFound.vue +27 -0
- package/lib/client/shim.d.ts +5 -0
- package/lib/client/styles/{_wrapper.scss → _mixins.scss} +7 -2
- package/lib/client/styles/_variables.module.scss +5 -0
- package/lib/client/styles/_variables.scss +0 -34
- package/lib/client/styles/arrow.scss +4 -6
- package/lib/client/styles/badge.scss +14 -11
- package/lib/client/styles/code-group.scss +10 -10
- package/lib/client/styles/code.scss +33 -46
- package/lib/client/styles/custom-container.scss +82 -18
- package/lib/client/styles/home.scss +32 -24
- package/lib/client/styles/index.scss +4 -4
- package/lib/client/styles/layout.scss +82 -73
- package/lib/client/styles/{dropdown.scss → navbar-dropdown.scss} +36 -50
- package/lib/client/styles/navbar.scss +106 -50
- package/lib/client/styles/normalize.scss +199 -0
- package/lib/client/styles/page.scss +24 -8
- package/lib/client/styles/sidebar.scss +69 -87
- package/lib/client/styles/transitions.scss +13 -4
- package/lib/client/styles/vars-dark.scss +68 -0
- package/lib/client/styles/vars.scss +155 -0
- package/lib/client/utils/getNavLink.d.ts +15 -0
- package/lib/client/utils/getNavLink.js +18 -0
- package/lib/client/utils/getResolveRouteWithRedirect.d.ts +5 -0
- package/lib/client/{composables/useResolveRouteWithRedirect.js → utils/getResolveRouteWithRedirect.js} +4 -6
- package/lib/client/utils/index.d.ts +5 -2
- package/lib/client/utils/index.js +5 -2
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
- package/lib/client/utils/isActiveSidebarItem.js +20 -0
- package/lib/client/utils/resolveEditLink.d.ts +2 -2
- package/lib/client/utils/resolveEditLink.js +15 -9
- package/lib/client/utils/resolveRepoType.d.ts +1 -1
- package/lib/client/utils/resolveRepoType.js +4 -2
- package/lib/node/defaultTheme.d.ts +4 -4
- package/lib/node/defaultTheme.js +111 -48
- package/lib/node/index.d.ts +4 -4
- package/lib/node/index.js +5 -17
- package/lib/node/utils/assignDefaultLocaleOptions.d.ts +4 -2
- package/lib/node/utils/assignDefaultLocaleOptions.js +13 -13
- package/lib/node/utils/index.d.ts +2 -5
- package/lib/node/utils/index.js +2 -17
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +2 -20
- package/lib/node/utils/resolveContainerPluginOptions.js +4 -66
- package/lib/shared/index.d.ts +3 -3
- package/lib/shared/index.js +3 -15
- package/lib/shared/nav.d.ts +16 -18
- package/lib/shared/nav.js +1 -2
- package/lib/shared/options.d.ts +51 -6
- package/lib/shared/options.js +1 -2
- package/lib/shared/page.d.ts +15 -6
- package/lib/shared/page.js +1 -2
- package/package.json +43 -25
- package/templates/build.html +34 -0
- package/CHANGELOG.md +0 -419
- package/lib/client/clientAppEnhance.d.ts +0 -3
- package/lib/client/clientAppEnhance.js +0 -28
- package/lib/client/clientAppSetup.d.ts +0 -2
- package/lib/client/clientAppSetup.js +0 -11
- package/lib/client/components/DropdownLink.vue +0 -141
- package/lib/client/components/NavLink.vue +0 -115
- package/lib/client/components/SidebarChild.d.ts +0 -6
- package/lib/client/components/SidebarChild.js +0 -91
- package/lib/client/components/global/OutboundLink.vue +0 -30
- package/lib/client/composables/useNavLink.d.ts +0 -9
- package/lib/client/composables/useNavLink.js +0 -15
- package/lib/client/composables/useResolveRouteWithRedirect.d.ts +0 -5
- package/lib/client/layouts/404.vue +0 -38
- package/lib/client/styles/_normalize.scss +0 -148
- package/lib/client/styles/plugins.scss +0 -18
- package/lib/client/styles/sr-only.scss +0 -12
- package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.js +0 -16
- package/lib/node/utils/resolveGitPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveGitPluginOptions.js +0 -22
- package/lib/node/utils/resolveMediumZoomPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveMediumZoomPluginOptions.js +0 -17
|
@@ -1,43 +1,34 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
</template>
|
|
16
|
-
|
|
17
|
-
<script lang="ts">
|
|
18
|
-
import { computed, defineComponent } from 'vue'
|
|
19
|
-
import { useRoute } from 'vue-router'
|
|
20
|
-
import { usePageFrontmatter } from '@vuepress/client'
|
|
21
|
-
import { isPlainObject, isString } from '@vuepress/shared'
|
|
22
|
-
import type { NavLink as NavLinkType, ResolvedSidebarItem } from '../../shared'
|
|
23
|
-
import { useNavLink, useSidebarItems } from '../composables'
|
|
24
|
-
import NavLink from './NavLink.vue'
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
+
import { computed } from 'vue'
|
|
4
|
+
import type { Router } from 'vue-router'
|
|
5
|
+
import { useRoute, useRouter } from 'vue-router'
|
|
6
|
+
import { usePageFrontmatter } from 'vuepress/client'
|
|
7
|
+
import { isPlainObject, isString } from 'vuepress/shared'
|
|
8
|
+
import type {
|
|
9
|
+
DefaultThemeNormalPageFrontmatter,
|
|
10
|
+
NavLink,
|
|
11
|
+
ResolvedSidebarItem,
|
|
12
|
+
} from '../../shared/index.js'
|
|
13
|
+
import { useSidebarItems } from '../composables/index.js'
|
|
14
|
+
import { getNavLink } from '../utils/index.js'
|
|
25
15
|
|
|
26
16
|
/**
|
|
27
17
|
* Resolve `prev` or `next` config from frontmatter
|
|
28
18
|
*/
|
|
29
19
|
const resolveFromFrontmatterConfig = (
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
router: Router,
|
|
21
|
+
conf: unknown,
|
|
22
|
+
): null | false | NavLink => {
|
|
32
23
|
if (conf === false) {
|
|
33
24
|
return null
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
if (isString(conf)) {
|
|
37
|
-
return
|
|
28
|
+
return getNavLink(router, conf)
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
if (isPlainObject<
|
|
31
|
+
if (isPlainObject<NavLink>(conf)) {
|
|
41
32
|
return conf
|
|
42
33
|
}
|
|
43
34
|
|
|
@@ -50,15 +41,15 @@ const resolveFromFrontmatterConfig = (
|
|
|
50
41
|
const resolveFromSidebarItems = (
|
|
51
42
|
sidebarItems: ResolvedSidebarItem[],
|
|
52
43
|
currentPath: string,
|
|
53
|
-
offset: number
|
|
54
|
-
): null |
|
|
44
|
+
offset: number,
|
|
45
|
+
): null | NavLink => {
|
|
55
46
|
const index = sidebarItems.findIndex((item) => item.link === currentPath)
|
|
56
47
|
if (index !== -1) {
|
|
57
48
|
const targetItem = sidebarItems[index + offset]
|
|
58
49
|
if (!targetItem?.link) {
|
|
59
50
|
return null
|
|
60
51
|
}
|
|
61
|
-
return targetItem as
|
|
52
|
+
return targetItem as NavLink
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
for (const item of sidebarItems) {
|
|
@@ -66,7 +57,7 @@ const resolveFromSidebarItems = (
|
|
|
66
57
|
const childResult = resolveFromSidebarItems(
|
|
67
58
|
item.children,
|
|
68
59
|
currentPath,
|
|
69
|
-
offset
|
|
60
|
+
offset,
|
|
70
61
|
)
|
|
71
62
|
if (childResult) {
|
|
72
63
|
return childResult
|
|
@@ -77,40 +68,46 @@ const resolveFromSidebarItems = (
|
|
|
77
68
|
return null
|
|
78
69
|
}
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev)
|
|
94
|
-
if (prevConfig !== false) {
|
|
95
|
-
return prevConfig
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return resolveFromSidebarItems(sidebarItems.value, route.path, -1)
|
|
99
|
-
})
|
|
71
|
+
const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
|
|
72
|
+
const sidebarItems = useSidebarItems()
|
|
73
|
+
const route = useRoute()
|
|
74
|
+
const router = useRouter()
|
|
75
|
+
|
|
76
|
+
const prevNavLink = computed(() => {
|
|
77
|
+
const prevConfig = resolveFromFrontmatterConfig(
|
|
78
|
+
router,
|
|
79
|
+
frontmatter.value.prev,
|
|
80
|
+
)
|
|
81
|
+
if (prevConfig !== false) {
|
|
82
|
+
return prevConfig
|
|
83
|
+
}
|
|
100
84
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (nextConfig !== false) {
|
|
104
|
-
return nextConfig
|
|
105
|
-
}
|
|
85
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, -1)
|
|
86
|
+
})
|
|
106
87
|
|
|
107
|
-
|
|
108
|
-
|
|
88
|
+
const nextNavLink = computed(() => {
|
|
89
|
+
const nextConfig = resolveFromFrontmatterConfig(
|
|
90
|
+
router,
|
|
91
|
+
frontmatter.value.next,
|
|
92
|
+
)
|
|
93
|
+
if (nextConfig !== false) {
|
|
94
|
+
return nextConfig
|
|
95
|
+
}
|
|
109
96
|
|
|
110
|
-
|
|
111
|
-
prevNavLink,
|
|
112
|
-
nextNavLink,
|
|
113
|
-
}
|
|
114
|
-
},
|
|
97
|
+
return resolveFromSidebarItems(sidebarItems.value, route.path, 1)
|
|
115
98
|
})
|
|
116
99
|
</script>
|
|
100
|
+
|
|
101
|
+
<template>
|
|
102
|
+
<nav v-if="prevNavLink || nextNavLink" class="page-nav">
|
|
103
|
+
<p class="inner">
|
|
104
|
+
<span v-if="prevNavLink" class="prev">
|
|
105
|
+
<AutoLink :item="prevNavLink" />
|
|
106
|
+
</span>
|
|
107
|
+
|
|
108
|
+
<span v-if="nextNavLink" class="next">
|
|
109
|
+
<AutoLink :item="nextNavLink" />
|
|
110
|
+
</span>
|
|
111
|
+
</p>
|
|
112
|
+
</nav>
|
|
113
|
+
</template>
|
|
@@ -1,38 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import NavbarItems from '@theme/NavbarItems.vue'
|
|
3
|
+
import SidebarItems from '@theme/SidebarItems.vue'
|
|
4
|
+
|
|
5
|
+
defineSlots<{
|
|
6
|
+
top?: (props: Record<never, never>) => any
|
|
7
|
+
bottom?: (props: Record<never, never>) => any
|
|
8
|
+
}>()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
1
11
|
<template>
|
|
2
12
|
<aside class="sidebar">
|
|
3
|
-
<
|
|
4
|
-
|
|
13
|
+
<NavbarItems />
|
|
5
14
|
<slot name="top" />
|
|
6
|
-
|
|
7
|
-
<ul class="sidebar-links">
|
|
8
|
-
<template v-for="item in sidebarItems" :key="item.link || item.text">
|
|
9
|
-
<SidebarChild :item="item" />
|
|
10
|
-
</template>
|
|
11
|
-
</ul>
|
|
12
|
-
|
|
15
|
+
<SidebarItems />
|
|
13
16
|
<slot name="bottom" />
|
|
14
17
|
</aside>
|
|
15
18
|
</template>
|
|
16
|
-
|
|
17
|
-
<script lang="ts">
|
|
18
|
-
import { defineComponent } from 'vue'
|
|
19
|
-
import { useSidebarItems } from '../composables'
|
|
20
|
-
import NavbarLinks from './NavbarLinks.vue'
|
|
21
|
-
import { SidebarChild } from './SidebarChild'
|
|
22
|
-
|
|
23
|
-
export default defineComponent({
|
|
24
|
-
name: 'Sidebar',
|
|
25
|
-
|
|
26
|
-
components: {
|
|
27
|
-
NavbarLinks,
|
|
28
|
-
SidebarChild,
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
setup() {
|
|
32
|
-
const sidebarItems = useSidebarItems()
|
|
33
|
-
return {
|
|
34
|
-
sidebarItems,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
</script>
|
|
@@ -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>
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
<svg
|
|
4
|
-
class="icon"
|
|
5
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
-
aria-hidden="true"
|
|
7
|
-
role="img"
|
|
8
|
-
viewBox="0 0 448 512"
|
|
9
|
-
>
|
|
10
|
-
<path
|
|
11
|
-
fill="currentColor"
|
|
12
|
-
d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"
|
|
13
|
-
class=""
|
|
14
|
-
/>
|
|
15
|
-
</svg>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script lang="ts">
|
|
20
|
-
import { defineComponent } from 'vue'
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useThemeLocaleData } from '../composables/index.js'
|
|
21
3
|
|
|
22
|
-
|
|
23
|
-
name: 'ToggleSidebarButton',
|
|
4
|
+
defineEmits<(e: 'toggle') => void>()
|
|
24
5
|
|
|
25
|
-
|
|
26
|
-
})
|
|
6
|
+
const themeLocale = useThemeLocaleData()
|
|
27
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>
|
|
@@ -1,3 +1,27 @@
|
|
|
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
|
+
|
|
20
|
+
defineSlots<{
|
|
21
|
+
default?: () => any
|
|
22
|
+
}>()
|
|
23
|
+
</script>
|
|
24
|
+
|
|
1
25
|
<template>
|
|
2
26
|
<span
|
|
3
27
|
class="badge"
|
|
@@ -9,29 +33,3 @@
|
|
|
9
33
|
<slot>{{ text }}</slot>
|
|
10
34
|
</span>
|
|
11
35
|
</template>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
import { defineComponent } from 'vue'
|
|
15
|
-
|
|
16
|
-
export default defineComponent({
|
|
17
|
-
name: 'Badge',
|
|
18
|
-
|
|
19
|
-
props: {
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
required: false,
|
|
23
|
-
default: 'tip',
|
|
24
|
-
},
|
|
25
|
-
text: {
|
|
26
|
-
type: String,
|
|
27
|
-
required: false,
|
|
28
|
-
default: '',
|
|
29
|
-
},
|
|
30
|
-
vertical: {
|
|
31
|
-
type: String,
|
|
32
|
-
required: false,
|
|
33
|
-
default: undefined,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
</script>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { VNode } from 'vue';
|
|
2
|
-
declare const
|
|
1
|
+
import type { SlotsType, VNode } from 'vue';
|
|
2
|
+
export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
3
3
|
[key: string]: any;
|
|
4
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin,
|
|
5
|
-
|
|
4
|
+
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, SlotsType<{
|
|
5
|
+
default: () => VNode[];
|
|
6
|
+
}>>;
|
|
@@ -1,16 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useStorage } from '@vueuse/core';
|
|
2
|
+
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
export const CodeGroup = defineComponent({
|
|
3
4
|
name: 'CodeGroup',
|
|
5
|
+
slots: Object,
|
|
4
6
|
setup(_, { slots }) {
|
|
7
|
+
// refs of the tab buttons
|
|
8
|
+
const tabRefs = ref([]);
|
|
9
|
+
if (__VUEPRESS_DEV__) {
|
|
10
|
+
// in dev mode, we need to clear the tabs ref to avoid HMR issues
|
|
11
|
+
// after removing a code-group-item
|
|
12
|
+
onBeforeUpdate(() => {
|
|
13
|
+
tabRefs.value = [];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
5
16
|
// index of current active item
|
|
6
17
|
const activeIndex = ref(-1);
|
|
18
|
+
const codeGroupStorage = useStorage('vuepress-code-group', {});
|
|
19
|
+
const codeGroupKey = computed(() => tabRefs.value.map((tab) => tab.innerText).join(','));
|
|
20
|
+
onMounted(() => {
|
|
21
|
+
watch(() => codeGroupStorage.value[codeGroupKey.value], (val = -1) => {
|
|
22
|
+
if (activeIndex.value !== val) {
|
|
23
|
+
activeIndex.value = val;
|
|
24
|
+
}
|
|
25
|
+
}, { immediate: true });
|
|
26
|
+
watch(activeIndex, (val) => {
|
|
27
|
+
if (codeGroupStorage.value[codeGroupKey.value] !== val) {
|
|
28
|
+
codeGroupStorage.value[codeGroupKey.value] = val;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
// activate next tab
|
|
33
|
+
const activateNext = (i = activeIndex.value) => {
|
|
34
|
+
if (i < tabRefs.value.length - 1) {
|
|
35
|
+
activeIndex.value = i + 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
activeIndex.value = 0;
|
|
39
|
+
}
|
|
40
|
+
tabRefs.value[activeIndex.value].focus();
|
|
41
|
+
};
|
|
42
|
+
// activate previous tab
|
|
43
|
+
const activatePrev = (i = activeIndex.value) => {
|
|
44
|
+
if (i > 0) {
|
|
45
|
+
activeIndex.value = i - 1;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
activeIndex.value = tabRefs.value.length - 1;
|
|
49
|
+
}
|
|
50
|
+
tabRefs.value[activeIndex.value].focus();
|
|
51
|
+
};
|
|
52
|
+
// handle keyboard event
|
|
53
|
+
const keyboardHandler = (event, i) => {
|
|
54
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
activeIndex.value = i;
|
|
57
|
+
}
|
|
58
|
+
else if (event.key === 'ArrowRight') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
activateNext(i);
|
|
61
|
+
}
|
|
62
|
+
else if (event.key === 'ArrowLeft') {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
activatePrev(i);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
7
67
|
return () => {
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
// `setup()` function of current component is called
|
|
11
|
-
var _a;
|
|
12
|
-
// get children code-group-item
|
|
13
|
-
const items = (((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || [])
|
|
68
|
+
// get children code-group-item from default slots
|
|
69
|
+
const items = (slots.default?.() || [])
|
|
14
70
|
.filter((vnode) => vnode.type.name === 'CodeGroupItem')
|
|
15
71
|
.map((vnode) => {
|
|
16
72
|
if (vnode.props === null) {
|
|
@@ -22,8 +78,8 @@ export default defineComponent({
|
|
|
22
78
|
if (items.length === 0) {
|
|
23
79
|
return null;
|
|
24
80
|
}
|
|
25
|
-
if
|
|
26
|
-
|
|
81
|
+
// if activeIndex is invalid
|
|
82
|
+
if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
|
|
27
83
|
// find the index of the code-group-item with `active` props
|
|
28
84
|
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
29
85
|
// if there is no `active` props on code-group-item, set the first item active
|
|
@@ -31,20 +87,32 @@ export default defineComponent({
|
|
|
31
87
|
activeIndex.value = 0;
|
|
32
88
|
}
|
|
33
89
|
}
|
|
90
|
+
// if activeIndex is valid
|
|
34
91
|
else {
|
|
35
|
-
// re-render triggered by modifying `activeIndex` ref
|
|
36
92
|
// set the active item
|
|
37
93
|
items.forEach((vnode, i) => {
|
|
38
94
|
vnode.props.active = i === activeIndex.value;
|
|
39
95
|
});
|
|
40
96
|
}
|
|
41
97
|
return h('div', { class: 'code-group' }, [
|
|
42
|
-
h('div', { class: 'code-group__nav'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
:
|
|
46
|
-
|
|
47
|
-
|
|
98
|
+
h('div', { class: 'code-group__nav', role: 'tablist' }, items.map((vnode, i) => {
|
|
99
|
+
const isActive = i === activeIndex.value;
|
|
100
|
+
return h('button', {
|
|
101
|
+
ref: (element) => {
|
|
102
|
+
if (element) {
|
|
103
|
+
tabRefs.value[i] = element;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
class: {
|
|
107
|
+
'code-group__nav-tab': true,
|
|
108
|
+
'code-group__nav-tab-active': isActive,
|
|
109
|
+
},
|
|
110
|
+
role: 'tab',
|
|
111
|
+
ariaSelected: isActive,
|
|
112
|
+
onClick: () => (activeIndex.value = i),
|
|
113
|
+
onKeydown: (e) => keyboardHandler(e, i),
|
|
114
|
+
}, vnode.props.title);
|
|
115
|
+
})),
|
|
48
116
|
items,
|
|
49
117
|
]);
|
|
50
118
|
};
|