@vuepress/theme-default 2.0.0-beta.6 → 2.0.0-beta.60
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/lib/client/components/AutoLink.vue +114 -0
- package/lib/client/components/DropdownTransition.vue +21 -0
- package/lib/client/components/Home.vue +15 -0
- package/lib/client/components/HomeContent.vue +5 -0
- package/lib/client/components/HomeFeatures.vue +23 -0
- package/lib/client/components/HomeFooter.vue +17 -0
- package/lib/client/components/HomeHero.vue +98 -0
- package/lib/client/components/Navbar.vue +75 -0
- package/lib/client/components/NavbarBrand.vue +55 -0
- package/lib/client/components/NavbarDropdown.vue +126 -0
- package/lib/{components/NavbarLinks.vue → client/components/NavbarItems.vue} +61 -50
- package/lib/{components → client/components}/Page.vue +9 -15
- package/lib/{components → client/components}/PageMeta.vue +51 -66
- package/lib/{components → client/components}/PageNav.vue +44 -57
- package/lib/client/components/Sidebar.vue +13 -0
- 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 +24 -0
- package/lib/client/components/global/Badge.vue +31 -0
- package/lib/client/components/global/CodeGroup.d.ts +4 -0
- package/lib/client/components/global/CodeGroup.js +106 -0
- package/lib/client/components/global/CodeGroupItem.vue +31 -0
- 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 +6 -0
- package/lib/client/composables/index.js +6 -0
- package/lib/client/composables/useDarkMode.d.ts +12 -0
- package/lib/client/composables/useDarkMode.js +57 -0
- package/lib/{composables → client/composables}/useNavLink.d.ts +6 -1
- package/lib/{composables → client/composables}/useNavLink.js +5 -2
- package/lib/{composables → client/composables}/useResolveRouteWithRedirect.d.ts +1 -1
- package/lib/{composables → client/composables}/useResolveRouteWithRedirect.js +2 -2
- package/lib/{composables → client/composables}/useScrollPromise.d.ts +0 -0
- package/lib/{composables → client/composables}/useScrollPromise.js +1 -1
- package/lib/client/composables/useSidebarItems.d.ts +36 -0
- package/lib/client/composables/useSidebarItems.js +118 -0
- package/lib/{composables → client/composables}/useThemeData.d.ts +2 -2
- package/lib/{composables → client/composables}/useThemeData.js +1 -1
- package/lib/client/config.d.ts +3 -0
- package/lib/client/config.js +44 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +3 -0
- package/lib/client/layouts/Layout.vue +134 -0
- package/lib/client/layouts/NotFound.vue +27 -0
- package/lib/{shim.d.ts → client/shim.d.ts} +0 -0
- package/lib/{styles/_wrapper.scss → client/styles/_mixins.scss} +7 -2
- package/lib/client/styles/_variables.scss +6 -0
- package/lib/{styles → client/styles}/arrow.scss +4 -6
- package/lib/client/styles/badge.scss +34 -0
- package/lib/{styles → client/styles}/code-group.scss +9 -2
- package/lib/{styles → client/styles}/code.scss +35 -49
- package/lib/client/styles/custom-container.scss +140 -0
- package/lib/{styles → client/styles}/home.scss +32 -24
- package/lib/{styles → client/styles}/index.scss +4 -4
- package/lib/client/styles/layout.scss +199 -0
- package/lib/{styles/dropdown.scss → client/styles/navbar-dropdown.scss} +36 -50
- package/lib/client/styles/navbar.scss +193 -0
- package/lib/client/styles/normalize.scss +200 -0
- package/lib/{styles → client/styles}/page.scss +24 -8
- package/lib/client/styles/sidebar.scss +134 -0
- package/lib/{styles → client/styles}/toc.scss +0 -0
- package/lib/client/styles/transitions.scss +22 -0
- package/lib/client/styles/vars-dark.scss +68 -0
- package/lib/client/styles/vars.scss +149 -0
- package/lib/client/utils/index.d.ts +3 -0
- package/lib/client/utils/index.js +3 -0
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
- package/lib/client/utils/isActiveSidebarItem.js +20 -0
- package/lib/{utils → client/utils}/resolveEditLink.d.ts +2 -2
- package/lib/{utils → client/utils}/resolveEditLink.js +15 -9
- package/lib/client/utils/resolveRepoType.d.ts +2 -0
- package/lib/{utils → client/utils}/resolveRepoType.js +3 -1
- package/lib/node/defaultTheme.d.ts +10 -0
- package/lib/node/defaultTheme.js +117 -0
- package/lib/node/index.d.ts +5 -5
- package/lib/node/index.js +5 -17
- package/lib/node/utils/assignDefaultLocaleOptions.d.ts +7 -0
- package/lib/node/{assignDefaultLocaleOptions.js → utils/assignDefaultLocaleOptions.js} +13 -13
- package/lib/node/utils/index.d.ts +2 -0
- package/lib/node/utils/index.js +2 -0
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +8 -0
- package/lib/node/utils/resolveContainerPluginOptions.js +17 -0
- package/lib/shared/index.d.ts +3 -0
- package/lib/shared/index.js +3 -0
- package/lib/shared/nav.d.ts +42 -0
- package/lib/shared/nav.js +1 -0
- package/lib/{types → shared}/options.d.ts +51 -13
- package/lib/shared/options.js +1 -0
- package/lib/{types → shared}/page.d.ts +15 -6
- package/lib/shared/page.js +1 -0
- package/package.json +49 -29
- package/templates/build.html +33 -0
- package/CHANGELOG.md +0 -376
- package/lib/clientAppEnhance.d.ts +0 -3
- package/lib/clientAppEnhance.js +0 -30
- package/lib/clientAppSetup.d.ts +0 -2
- package/lib/clientAppSetup.js +0 -11
- package/lib/components/DropdownLink.vue +0 -141
- package/lib/components/DropdownTransition.vue +0 -34
- package/lib/components/Home.vue +0 -133
- package/lib/components/NavLink.vue +0 -115
- package/lib/components/Navbar.vue +0 -114
- package/lib/components/Sidebar.vue +0 -38
- package/lib/components/SidebarChild.d.ts +0 -6
- package/lib/components/SidebarChild.js +0 -91
- package/lib/components/ToggleSidebarButton.vue +0 -27
- package/lib/components/global/Badge.vue +0 -37
- package/lib/components/global/CodeGroup.d.ts +0 -5
- package/lib/components/global/CodeGroup.js +0 -52
- package/lib/components/global/CodeGroupItem.vue +0 -25
- package/lib/components/global/OutboundLink.vue +0 -30
- package/lib/composables/index.d.ts +0 -5
- package/lib/composables/index.js +0 -5
- package/lib/composables/useSidebarItems.d.ts +0 -31
- package/lib/composables/useSidebarItems.js +0 -114
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -67
- package/lib/layouts/404.vue +0 -38
- package/lib/layouts/Layout.vue +0 -152
- package/lib/node/assignDefaultLocaleOptions.d.ts +0 -5
- package/lib/node/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
- package/lib/node/resolveActiveHeaderLinksPluginOptions.js +0 -16
- package/lib/node/resolveContainerPluginOptions.d.ts +0 -26
- package/lib/node/resolveContainerPluginOptions.js +0 -79
- package/lib/node/resolveGitPluginOptions.d.ts +0 -6
- package/lib/node/resolveGitPluginOptions.js +0 -22
- package/lib/node/resolveMediumZoomPluginOptions.d.ts +0 -6
- package/lib/node/resolveMediumZoomPluginOptions.js +0 -17
- package/lib/styles/_normalize.scss +0 -148
- package/lib/styles/_variables.scss +0 -34
- package/lib/styles/badge.scss +0 -33
- package/lib/styles/custom-container.scss +0 -78
- package/lib/styles/layout.scss +0 -194
- package/lib/styles/navbar.scss +0 -141
- package/lib/styles/plugins.scss +0 -18
- package/lib/styles/sidebar.scss +0 -152
- package/lib/styles/sr-only.scss +0 -12
- package/lib/styles/transitions.scss +0 -13
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -15
- package/lib/types/nav.d.ts +0 -44
- package/lib/types/nav.js +0 -2
- package/lib/types/options.js +0 -2
- package/lib/types/page.js +0 -2
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.js +0 -2
- package/lib/utils/resolveRepoType.d.ts +0 -2
|
@@ -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, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { defineComponent, h, onBeforeUpdate, ref } from 'vue';
|
|
2
|
+
export const CodeGroup = defineComponent({
|
|
3
|
+
name: 'CodeGroup',
|
|
4
|
+
setup(_, { slots }) {
|
|
5
|
+
// index of current active item
|
|
6
|
+
const activeIndex = ref(-1);
|
|
7
|
+
// refs of the tab buttons
|
|
8
|
+
const tabRefs = ref([]);
|
|
9
|
+
if (__VUEPRESS_DEV__) {
|
|
10
|
+
// after removing a code-group-item, we need to clear the ref
|
|
11
|
+
// of the removed item to avoid issues caused by HMR
|
|
12
|
+
onBeforeUpdate(() => {
|
|
13
|
+
tabRefs.value = [];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
// activate next tab
|
|
17
|
+
const activateNext = (i = activeIndex.value) => {
|
|
18
|
+
if (i < tabRefs.value.length - 1) {
|
|
19
|
+
activeIndex.value = i + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
activeIndex.value = 0;
|
|
23
|
+
}
|
|
24
|
+
tabRefs.value[activeIndex.value].focus();
|
|
25
|
+
};
|
|
26
|
+
// activate previous tab
|
|
27
|
+
const activatePrev = (i = activeIndex.value) => {
|
|
28
|
+
if (i > 0) {
|
|
29
|
+
activeIndex.value = i - 1;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
activeIndex.value = tabRefs.value.length - 1;
|
|
33
|
+
}
|
|
34
|
+
tabRefs.value[activeIndex.value].focus();
|
|
35
|
+
};
|
|
36
|
+
// handle keyboard event
|
|
37
|
+
const keyboardHandler = (event, i) => {
|
|
38
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
activeIndex.value = i;
|
|
41
|
+
}
|
|
42
|
+
else if (event.key === 'ArrowRight') {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
activateNext(i);
|
|
45
|
+
}
|
|
46
|
+
else if (event.key === 'ArrowLeft') {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
activatePrev(i);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return () => {
|
|
52
|
+
// NOTICE: here we put the `slots.default()` inside the render function to make
|
|
53
|
+
// the slots reactive, otherwise the slot content won't be changed once the
|
|
54
|
+
// `setup()` function of current component is called
|
|
55
|
+
// get children code-group-item
|
|
56
|
+
const items = (slots.default?.() || [])
|
|
57
|
+
.filter((vnode) => vnode.type.name === 'CodeGroupItem')
|
|
58
|
+
.map((vnode) => {
|
|
59
|
+
if (vnode.props === null) {
|
|
60
|
+
vnode.props = {};
|
|
61
|
+
}
|
|
62
|
+
return vnode;
|
|
63
|
+
});
|
|
64
|
+
// do not render anything if there is no code-group-item
|
|
65
|
+
if (items.length === 0) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
|
|
69
|
+
// if `activeIndex` is invalid
|
|
70
|
+
// find the index of the code-group-item with `active` props
|
|
71
|
+
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
72
|
+
// if there is no `active` props on code-group-item, set the first item active
|
|
73
|
+
if (activeIndex.value === -1) {
|
|
74
|
+
activeIndex.value = 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// set the active item
|
|
79
|
+
items.forEach((vnode, i) => {
|
|
80
|
+
vnode.props.active = i === activeIndex.value;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return h('div', { class: 'code-group' }, [
|
|
84
|
+
h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) => {
|
|
85
|
+
const isActive = i === activeIndex.value;
|
|
86
|
+
return h('li', { class: 'code-group__li' }, h('button', {
|
|
87
|
+
ref: (element) => {
|
|
88
|
+
if (element) {
|
|
89
|
+
tabRefs.value[i] = element;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
class: {
|
|
93
|
+
'code-group__nav-tab': true,
|
|
94
|
+
'code-group__nav-tab-active': isActive,
|
|
95
|
+
},
|
|
96
|
+
ariaPressed: isActive,
|
|
97
|
+
ariaExpanded: isActive,
|
|
98
|
+
onClick: () => (activeIndex.value = i),
|
|
99
|
+
onKeydown: (e) => keyboardHandler(e, i),
|
|
100
|
+
}, vnode.props.title));
|
|
101
|
+
}))),
|
|
102
|
+
items,
|
|
103
|
+
]);
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
name: 'CodeGroupItem',
|
|
6
|
+
})
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
defineProps({
|
|
11
|
+
title: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
active: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
required: false,
|
|
18
|
+
default: false,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<div
|
|
25
|
+
class="code-group-item"
|
|
26
|
+
:class="{ 'code-group-item__active': active }"
|
|
27
|
+
:aria-selected="active"
|
|
28
|
+
>
|
|
29
|
+
<slot />
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InjectionKey, WritableComputedRef } from 'vue';
|
|
2
|
+
export type DarkModeRef = WritableComputedRef<boolean>;
|
|
3
|
+
export declare const darkModeSymbol: InjectionKey<DarkModeRef>;
|
|
4
|
+
/**
|
|
5
|
+
* Inject dark mode global computed
|
|
6
|
+
*/
|
|
7
|
+
export declare const useDarkMode: () => DarkModeRef;
|
|
8
|
+
/**
|
|
9
|
+
* Create dark mode ref and provide as global computed in setup
|
|
10
|
+
*/
|
|
11
|
+
export declare const setupDarkMode: () => void;
|
|
12
|
+
export declare const updateHtmlDarkClass: (isDarkMode: DarkModeRef) => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { usePreferredDark, useStorage } from '@vueuse/core';
|
|
2
|
+
import { computed, inject, onMounted, onUnmounted, provide, watch } from 'vue';
|
|
3
|
+
import { useThemeLocaleData } from './useThemeData.js';
|
|
4
|
+
export const darkModeSymbol = Symbol(__VUEPRESS_DEV__ ? 'darkMode' : '');
|
|
5
|
+
/**
|
|
6
|
+
* Inject dark mode global computed
|
|
7
|
+
*/
|
|
8
|
+
export const useDarkMode = () => {
|
|
9
|
+
const isDarkMode = inject(darkModeSymbol);
|
|
10
|
+
if (!isDarkMode) {
|
|
11
|
+
throw new Error('useDarkMode() is called without provider.');
|
|
12
|
+
}
|
|
13
|
+
return isDarkMode;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create dark mode ref and provide as global computed in setup
|
|
17
|
+
*/
|
|
18
|
+
export const setupDarkMode = () => {
|
|
19
|
+
const themeLocale = useThemeLocaleData();
|
|
20
|
+
const isDarkPreferred = usePreferredDark();
|
|
21
|
+
const darkStorage = useStorage('vuepress-color-scheme', themeLocale.value.colorMode);
|
|
22
|
+
const isDarkMode = computed({
|
|
23
|
+
get() {
|
|
24
|
+
// disable color mode switching
|
|
25
|
+
if (!themeLocale.value.colorModeSwitch) {
|
|
26
|
+
return themeLocale.value.colorMode === 'dark';
|
|
27
|
+
}
|
|
28
|
+
// auto detected from prefers-color-scheme
|
|
29
|
+
if (darkStorage.value === 'auto') {
|
|
30
|
+
return isDarkPreferred.value;
|
|
31
|
+
}
|
|
32
|
+
// storage value
|
|
33
|
+
return darkStorage.value === 'dark';
|
|
34
|
+
},
|
|
35
|
+
set(val) {
|
|
36
|
+
if (val === isDarkPreferred.value) {
|
|
37
|
+
darkStorage.value = 'auto';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
darkStorage.value = val ? 'dark' : 'light';
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
provide(darkModeSymbol, isDarkMode);
|
|
45
|
+
updateHtmlDarkClass(isDarkMode);
|
|
46
|
+
};
|
|
47
|
+
export const updateHtmlDarkClass = (isDarkMode) => {
|
|
48
|
+
const update = (value = isDarkMode.value) => {
|
|
49
|
+
// set `class="dark"` on `<html>` element
|
|
50
|
+
const htmlEl = window?.document.querySelector('html');
|
|
51
|
+
htmlEl?.classList.toggle('dark', value);
|
|
52
|
+
};
|
|
53
|
+
onMounted(() => {
|
|
54
|
+
watch(isDarkMode, update, { immediate: true });
|
|
55
|
+
});
|
|
56
|
+
onUnmounted(() => update());
|
|
57
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
|
|
1
|
+
import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect.js';
|
|
2
2
|
/**
|
|
3
3
|
* Resolve NavLink props from string
|
|
4
4
|
*
|
|
@@ -7,7 +7,10 @@ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
|
|
|
7
7
|
* - Output: { text: 'Home', link: '/' }
|
|
8
8
|
*/
|
|
9
9
|
export const useNavLink = (item) => {
|
|
10
|
-
|
|
10
|
+
// the route path of vue-router is url-encoded, and we expect users are using
|
|
11
|
+
// non-url-encoded string in theme config, so we need to url-encode it first to
|
|
12
|
+
// resolve the route correctly
|
|
13
|
+
const resolved = useResolveRouteWithRedirect(encodeURI(item));
|
|
11
14
|
return {
|
|
12
15
|
text: resolved.meta.title || item,
|
|
13
16
|
link: resolved.name === '404' ? item : resolved.fullPath,
|
|
@@ -2,4 +2,4 @@ import type { Router } from 'vue-router';
|
|
|
2
2
|
/**
|
|
3
3
|
* Resolve a route with redirection
|
|
4
4
|
*/
|
|
5
|
-
export declare const useResolveRouteWithRedirect: (to: import("vue-router").RouteLocationRaw) => ReturnType<Router['resolve']>;
|
|
5
|
+
export declare const useResolveRouteWithRedirect: (to: import("vue-router").RouteLocationRaw, currentLocation?: import("vue-router").RouteLocationNormalizedLoaded | undefined) => ReturnType<Router['resolve']>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRouter } from 'vue-router';
|
|
2
1
|
import { isFunction, isString } from '@vuepress/shared';
|
|
2
|
+
import { useRouter } from 'vue-router';
|
|
3
3
|
/**
|
|
4
4
|
* Resolve a route with redirection
|
|
5
5
|
*/
|
|
@@ -7,7 +7,7 @@ export const useResolveRouteWithRedirect = (...args) => {
|
|
|
7
7
|
const router = useRouter();
|
|
8
8
|
const route = router.resolve(...args);
|
|
9
9
|
const lastMatched = route.matched[route.matched.length - 1];
|
|
10
|
-
if (!
|
|
10
|
+
if (!lastMatched?.redirect) {
|
|
11
11
|
return route;
|
|
12
12
|
}
|
|
13
13
|
const { redirect } = lastMatched;
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ const scrollPromise = {
|
|
|
6
6
|
promise = new Promise((resolve) => (promiseResolve = resolve));
|
|
7
7
|
},
|
|
8
8
|
resolve: () => {
|
|
9
|
-
promiseResolve
|
|
9
|
+
promiseResolve?.();
|
|
10
10
|
promise = null;
|
|
11
11
|
promiseResolve = null;
|
|
12
12
|
},
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { PageHeader } from '@vuepress/client';
|
|
2
|
+
import type { ComputedRef, InjectionKey } from 'vue';
|
|
3
|
+
import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
|
|
4
|
+
export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
|
|
5
|
+
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
6
|
+
/**
|
|
7
|
+
* Inject sidebar items global computed
|
|
8
|
+
*/
|
|
9
|
+
export declare const useSidebarItems: () => SidebarItemsRef;
|
|
10
|
+
/**
|
|
11
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
12
|
+
*/
|
|
13
|
+
export declare const setupSidebarItems: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve sidebar items global computed
|
|
16
|
+
*
|
|
17
|
+
* It should only be resolved and provided once
|
|
18
|
+
*/
|
|
19
|
+
export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
|
|
20
|
+
/**
|
|
21
|
+
* Util to transform page header to sidebar item
|
|
22
|
+
*/
|
|
23
|
+
export declare const headerToSidebarItem: (header: PageHeader, sidebarDepth: number) => ResolvedSidebarItem;
|
|
24
|
+
export declare const headersToSidebarItemChildren: (headers: PageHeader[], sidebarDepth: number) => ResolvedSidebarItem[];
|
|
25
|
+
/**
|
|
26
|
+
* Resolve sidebar items if the config is `auto`
|
|
27
|
+
*/
|
|
28
|
+
export declare const resolveAutoSidebarItems: (sidebarDepth: number) => ResolvedSidebarItem[];
|
|
29
|
+
/**
|
|
30
|
+
* Resolve sidebar items if the config is an array
|
|
31
|
+
*/
|
|
32
|
+
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
33
|
+
/**
|
|
34
|
+
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
35
|
+
*/
|
|
36
|
+
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { usePageData, usePageFrontmatter } from '@vuepress/client';
|
|
2
|
+
import { isArray, isPlainObject, isString, resolveLocalePath, } from '@vuepress/shared';
|
|
3
|
+
import { computed, inject, provide } from 'vue';
|
|
4
|
+
import { useRoute } from 'vue-router';
|
|
5
|
+
import { useNavLink } from './useNavLink.js';
|
|
6
|
+
import { useThemeLocaleData } from './useThemeData.js';
|
|
7
|
+
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
8
|
+
/**
|
|
9
|
+
* Inject sidebar items global computed
|
|
10
|
+
*/
|
|
11
|
+
export const useSidebarItems = () => {
|
|
12
|
+
const sidebarItems = inject(sidebarItemsSymbol);
|
|
13
|
+
if (!sidebarItems) {
|
|
14
|
+
throw new Error('useSidebarItems() is called without provider.');
|
|
15
|
+
}
|
|
16
|
+
return sidebarItems;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
20
|
+
*/
|
|
21
|
+
export const setupSidebarItems = () => {
|
|
22
|
+
const themeLocale = useThemeLocaleData();
|
|
23
|
+
const frontmatter = usePageFrontmatter();
|
|
24
|
+
const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value));
|
|
25
|
+
provide(sidebarItemsSymbol, sidebarItems);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve sidebar items global computed
|
|
29
|
+
*
|
|
30
|
+
* It should only be resolved and provided once
|
|
31
|
+
*/
|
|
32
|
+
export const resolveSidebarItems = (frontmatter, themeLocale) => {
|
|
33
|
+
// get sidebar config from frontmatter > theme data
|
|
34
|
+
const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
|
|
35
|
+
const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
|
|
36
|
+
// resolve sidebar items according to the config
|
|
37
|
+
if (frontmatter.home || sidebarConfig === false) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
if (sidebarConfig === 'auto') {
|
|
41
|
+
return resolveAutoSidebarItems(sidebarDepth);
|
|
42
|
+
}
|
|
43
|
+
if (isArray(sidebarConfig)) {
|
|
44
|
+
return resolveArraySidebarItems(sidebarConfig, sidebarDepth);
|
|
45
|
+
}
|
|
46
|
+
if (isPlainObject(sidebarConfig)) {
|
|
47
|
+
return resolveMultiSidebarItems(sidebarConfig, sidebarDepth);
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Util to transform page header to sidebar item
|
|
53
|
+
*/
|
|
54
|
+
export const headerToSidebarItem = (header, sidebarDepth) => ({
|
|
55
|
+
text: header.title,
|
|
56
|
+
link: header.link,
|
|
57
|
+
children: headersToSidebarItemChildren(header.children, sidebarDepth),
|
|
58
|
+
});
|
|
59
|
+
export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDepth > 0
|
|
60
|
+
? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
|
|
61
|
+
: [];
|
|
62
|
+
/**
|
|
63
|
+
* Resolve sidebar items if the config is `auto`
|
|
64
|
+
*/
|
|
65
|
+
export const resolveAutoSidebarItems = (sidebarDepth) => {
|
|
66
|
+
const page = usePageData();
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
text: page.value.title,
|
|
70
|
+
children: headersToSidebarItemChildren(page.value.headers, sidebarDepth),
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Resolve sidebar items if the config is an array
|
|
76
|
+
*/
|
|
77
|
+
export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
78
|
+
const route = useRoute();
|
|
79
|
+
const page = usePageData();
|
|
80
|
+
const handleChildItem = (item) => {
|
|
81
|
+
let childItem;
|
|
82
|
+
if (isString(item)) {
|
|
83
|
+
childItem = useNavLink(item);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
childItem = item;
|
|
87
|
+
}
|
|
88
|
+
if (childItem.children) {
|
|
89
|
+
return {
|
|
90
|
+
...childItem,
|
|
91
|
+
children: childItem.children.map((item) => handleChildItem(item)),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// if the sidebar item is current page and children is not set
|
|
95
|
+
// use headers of current page as children
|
|
96
|
+
if (childItem.link === route.path) {
|
|
97
|
+
// skip h1 header
|
|
98
|
+
const headers = page.value.headers[0]?.level === 1
|
|
99
|
+
? page.value.headers[0].children
|
|
100
|
+
: page.value.headers;
|
|
101
|
+
return {
|
|
102
|
+
...childItem,
|
|
103
|
+
children: headersToSidebarItemChildren(headers, sidebarDepth),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return childItem;
|
|
107
|
+
};
|
|
108
|
+
return sidebarConfig.map((item) => handleChildItem(item));
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
112
|
+
*/
|
|
113
|
+
export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
|
|
114
|
+
const route = useRoute();
|
|
115
|
+
const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
|
|
116
|
+
const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
|
|
117
|
+
return resolveArraySidebarItems(matchedSidebarConfig, sidebarDepth);
|
|
118
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/
|
|
2
|
-
import type { DefaultThemeData } from '
|
|
1
|
+
import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/client';
|
|
2
|
+
import type { DefaultThemeData } from '../../shared/index.js';
|
|
3
3
|
export declare const useThemeData: () => ThemeDataRef<DefaultThemeData>;
|
|
4
4
|
export declare const useThemeLocaleData: () => ThemeLocaleDataRef<DefaultThemeData>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/
|
|
1
|
+
import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/client';
|
|
2
2
|
export const useThemeData = () => _useThemeData();
|
|
3
3
|
export const useThemeLocaleData = () => _useThemeLocaleData();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineClientConfig } from '@vuepress/client';
|
|
2
|
+
import { h } from 'vue';
|
|
3
|
+
import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
|
|
4
|
+
import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
|
|
5
|
+
import Layout from './layouts/Layout.vue';
|
|
6
|
+
import NotFound from './layouts/NotFound.vue';
|
|
7
|
+
import './styles/index.scss';
|
|
8
|
+
export default defineClientConfig({
|
|
9
|
+
enhance({ app, router }) {
|
|
10
|
+
app.component('Badge', Badge);
|
|
11
|
+
app.component('CodeGroup', CodeGroup);
|
|
12
|
+
app.component('CodeGroupItem', CodeGroupItem);
|
|
13
|
+
// compat with @vuepress/plugin-external-link-icon
|
|
14
|
+
app.component('AutoLinkExternalIcon', () => {
|
|
15
|
+
const ExternalLinkIcon = app.component('ExternalLinkIcon');
|
|
16
|
+
if (ExternalLinkIcon) {
|
|
17
|
+
return h(ExternalLinkIcon);
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
});
|
|
21
|
+
// compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
|
|
22
|
+
app.component('NavbarSearch', () => {
|
|
23
|
+
const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
|
|
24
|
+
if (SearchComponent) {
|
|
25
|
+
return h(SearchComponent);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
});
|
|
29
|
+
// handle scrollBehavior with transition
|
|
30
|
+
const scrollBehavior = router.options.scrollBehavior;
|
|
31
|
+
router.options.scrollBehavior = async (...args) => {
|
|
32
|
+
await useScrollPromise().wait();
|
|
33
|
+
return scrollBehavior(...args);
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
setup() {
|
|
37
|
+
setupDarkMode();
|
|
38
|
+
setupSidebarItems();
|
|
39
|
+
},
|
|
40
|
+
layouts: {
|
|
41
|
+
Layout,
|
|
42
|
+
NotFound,
|
|
43
|
+
},
|
|
44
|
+
});
|