@vuepress/theme-default 2.0.0-rc.6 → 2.0.0-rc.61
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/VPDarkIcon.vue +8 -0
- package/lib/client/components/VPDropdownTransition.vue +36 -0
- package/lib/client/components/VPEditIcon.vue +12 -0
- package/lib/client/components/VPHome.vue +38 -0
- package/lib/client/components/VPHomeFeatures.vue +66 -0
- package/lib/client/components/{HomeFooter.vue → VPHomeFooter.vue} +17 -2
- package/lib/client/components/{HomeHero.vue → VPHomeHero.vue} +113 -19
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +134 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +40 -7
- package/lib/client/components/VPNavbarDropdown.vue +334 -0
- package/lib/client/components/VPNavbarItems.vue +111 -0
- package/lib/client/components/VPPage.vue +72 -0
- package/lib/client/components/VPPageMeta.vue +134 -0
- package/lib/client/components/VPPageNav.vue +118 -0
- package/lib/client/components/VPSidebar.vue +113 -0
- package/lib/client/components/VPSidebarItem.vue +174 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +32 -7
- package/lib/client/components/VPToggleColorModeButton.vue +55 -0
- package/lib/client/components/VPToggleSidebarButton.vue +92 -0
- package/lib/client/components/global/Badge.vue +84 -18
- package/lib/client/components/global/index.d.ts +1 -3
- package/lib/client/components/global/index.js +1 -3
- package/lib/client/composables/index.d.ts +8 -0
- package/lib/client/composables/index.js +8 -0
- package/lib/client/composables/useContributors.d.ts +3 -0
- package/lib/client/composables/useContributors.js +14 -0
- package/lib/client/composables/useDarkMode.d.ts +0 -1
- package/lib/client/composables/useDarkMode.js +16 -13
- package/lib/client/composables/useEditLink.d.ts +3 -0
- package/lib/client/composables/useEditLink.js +31 -0
- package/lib/client/composables/useLastUpdated.d.ts +2 -0
- package/lib/client/composables/useLastUpdated.js +17 -0
- package/lib/client/composables/useNavbarConfig.d.ts +3 -0
- package/lib/client/composables/useNavbarConfig.js +27 -0
- package/lib/client/composables/useNavbarRepo.d.ts +6 -0
- package/lib/client/composables/useNavbarRepo.js +38 -0
- package/lib/client/composables/useNavbarSelectLanguage.d.ts +6 -0
- package/lib/client/composables/useNavbarSelectLanguage.js +59 -0
- package/lib/client/composables/useNavigate.d.ts +1 -0
- package/lib/client/composables/useNavigate.js +22 -0
- package/lib/client/composables/useRelatedLinks.d.ts +8 -0
- package/lib/client/composables/useRelatedLinks.js +91 -0
- package/lib/client/composables/useScrollPromise.js +3 -1
- package/lib/client/composables/useSidebarItems.d.ts +28 -23
- package/lib/client/composables/useSidebarItems.js +120 -84
- package/lib/client/composables/useUpdateDeviceStatus.d.ts +1 -1
- package/lib/client/composables/useUpdateDeviceStatus.js +10 -5
- package/lib/client/config.d.ts +3 -2
- package/lib/client/config.js +6 -23
- package/lib/client/index.d.ts +2 -1
- package/lib/client/index.js +0 -1
- package/lib/client/layouts/Layout.vue +139 -34
- package/lib/client/layouts/NotFound.vue +17 -5
- package/lib/client/shim.d.ts +6 -5
- package/lib/client/styles/_mixins.scss +4 -4
- package/lib/client/styles/_variables.module.scss +1 -1
- package/lib/client/styles/_variables.scss +2 -1
- package/lib/client/styles/arrow.scss +18 -24
- package/lib/client/styles/code-group.scss +35 -30
- package/lib/client/styles/content/code.scss +23 -0
- package/lib/client/styles/content/index.scss +3 -0
- package/lib/client/styles/content/normalize.scss +39 -0
- package/lib/client/styles/{toc.scss → content/toc.scss} +1 -1
- package/lib/client/styles/external-link-icon.scss +36 -0
- package/lib/client/styles/index.scss +3 -13
- package/lib/client/styles/layout.scss +3 -199
- package/lib/client/styles/normalize.scss +1 -194
- package/lib/client/styles/plugins.scss +28 -0
- package/lib/client/styles/vars-dark.scss +20 -58
- package/lib/client/styles/vars.scss +53 -129
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/getAutoLink.d.ts +9 -0
- package/lib/client/utils/getAutoLink.js +17 -0
- package/lib/client/utils/index.d.ts +3 -2
- package/lib/client/utils/index.js +3 -2
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -3
- package/lib/client/utils/isActiveSidebarItem.js +3 -3
- package/lib/client/utils/isLinkInternal.d.ts +1 -0
- package/lib/client/utils/isLinkInternal.js +2 -0
- package/lib/client/utils/resolveEditLink.d.ts +1 -1
- package/lib/client/utils/resolvePrefix.d.ts +1 -0
- package/lib/client/utils/resolvePrefix.js +4 -0
- package/lib/client/utils/resolveRepoType.d.ts +1 -1
- package/lib/client/utils/resolveRepoType.js +4 -4
- package/lib/node/defaultTheme.d.ts +2 -1
- package/lib/node/defaultTheme.js +40 -49
- package/lib/node/index.d.ts +2 -3
- package/lib/node/index.js +0 -3
- package/lib/node/typings.d.ts +58 -0
- package/lib/node/typings.js +1 -0
- package/lib/node/utils/assignDefaultLocaleOptions.js +3 -7
- package/lib/node/utils/index.d.ts +1 -1
- package/lib/node/utils/index.js +1 -1
- package/lib/node/utils/resolveMarkdownHintLocales.d.ts +9 -0
- package/lib/node/utils/resolveMarkdownHintLocales.js +19 -0
- package/lib/shared/index.d.ts +5 -3
- package/lib/shared/index.js +1 -3
- package/lib/shared/nav.d.ts +19 -30
- package/lib/shared/navbar.d.ts +21 -0
- package/lib/shared/navbar.js +1 -0
- package/lib/shared/options.d.ts +36 -65
- package/lib/shared/page.d.ts +9 -6
- package/lib/shared/sidebar.d.ts +26 -0
- package/lib/shared/sidebar.js +1 -0
- package/package.json +30 -28
- package/templates/build.html +14 -8
- package/lib/client/components/AutoLink.vue +0 -113
- package/lib/client/components/DropdownTransition.vue +0 -25
- package/lib/client/components/Home.vue +0 -15
- package/lib/client/components/HomeContent.vue +0 -5
- package/lib/client/components/HomeFeatures.vue +0 -22
- package/lib/client/components/Navbar.vue +0 -79
- package/lib/client/components/NavbarDropdown.vue +0 -126
- package/lib/client/components/NavbarItems.vue +0 -199
- package/lib/client/components/Page.vue +0 -31
- package/lib/client/components/PageMeta.vue +0 -124
- package/lib/client/components/PageNav.vue +0 -122
- package/lib/client/components/Sidebar.vue +0 -18
- package/lib/client/components/SidebarItem.vue +0 -87
- package/lib/client/components/ToggleColorModeButton.vue +0 -57
- package/lib/client/components/ToggleSidebarButton.vue +0 -24
- package/lib/client/components/global/CodeGroup.d.ts +0 -6
- package/lib/client/components/global/CodeGroup.js +0 -120
- package/lib/client/components/global/CodeGroupItem.vue +0 -27
- package/lib/client/styles/badge.scss +0 -36
- package/lib/client/styles/code.scss +0 -263
- package/lib/client/styles/custom-container.scss +0 -142
- package/lib/client/styles/home.scss +0 -168
- package/lib/client/styles/navbar-dropdown.scss +0 -183
- package/lib/client/styles/navbar.scss +0 -197
- package/lib/client/styles/page.scss +0 -87
- package/lib/client/styles/sidebar.scss +0 -134
- package/lib/client/styles/transitions.scss +0 -22
- package/lib/client/utils/getNavLink.d.ts +0 -15
- package/lib/client/utils/getNavLink.js +0 -18
- package/lib/client/utils/getResolveRouteWithRedirect.d.ts +0 -5
- package/lib/client/utils/getResolveRouteWithRedirect.js +0 -22
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +0 -8
- package/lib/node/utils/resolveContainerPluginOptions.js +0 -17
|
@@ -1,118 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
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 = () => {
|
|
1
|
+
import { useThemeLocaleData } from '@theme/useThemeData';
|
|
2
|
+
import { getHeaders, keys, startsWith } from '@vuepress/helper/client';
|
|
3
|
+
import { computed, inject, onMounted, provide, ref, watch } from 'vue';
|
|
4
|
+
import { usePageData, usePageFrontmatter, useRoute, useRouteLocale, useRouter, } from 'vuepress/client';
|
|
5
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
6
|
+
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js';
|
|
7
|
+
export const headersRef = ref([]);
|
|
8
|
+
export const setupHeaders = () => {
|
|
9
|
+
const router = useRouter();
|
|
22
10
|
const themeLocale = useThemeLocaleData();
|
|
23
11
|
const frontmatter = usePageFrontmatter();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
if (sidebarConfig === 'auto') {
|
|
44
|
-
return resolveAutoSidebarItems(page, sidebarDepth);
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(sidebarConfig)) {
|
|
47
|
-
return resolveArraySidebarItems(page, router, path, sidebarConfig, sidebarDepth);
|
|
48
|
-
}
|
|
49
|
-
if (isPlainObject(sidebarConfig)) {
|
|
50
|
-
return resolveMultiSidebarItems(page, router, path, sidebarConfig, sidebarDepth);
|
|
51
|
-
}
|
|
52
|
-
return [];
|
|
12
|
+
const levels = computed(() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2);
|
|
13
|
+
router.beforeEach((to, from) => {
|
|
14
|
+
if (to.path !== from.path) {
|
|
15
|
+
headersRef.value = [];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const updateHeaders = () => {
|
|
19
|
+
if (levels.value <= 0) {
|
|
20
|
+
headersRef.value = [];
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
headersRef.value = getHeaders({
|
|
24
|
+
levels: [2, levels.value + 1],
|
|
25
|
+
ignore: ['.vp-badge'],
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
watch(levels, updateHeaders);
|
|
29
|
+
onMounted(updateHeaders);
|
|
53
30
|
};
|
|
31
|
+
export const useHeaders = () => headersRef;
|
|
54
32
|
/**
|
|
55
33
|
* Util to transform page header to sidebar item
|
|
56
34
|
*/
|
|
57
|
-
export const
|
|
35
|
+
export const resolveSidebarHeaderItem = (header) => ({
|
|
58
36
|
text: header.title,
|
|
59
37
|
link: header.link,
|
|
60
|
-
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
39
|
+
children: resolveSidebarHeaderItems(header.children),
|
|
61
40
|
});
|
|
62
|
-
export const
|
|
63
|
-
? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
|
|
64
|
-
: [];
|
|
41
|
+
export const resolveSidebarHeaderItems = (headers) => headers ? headers.map((header) => resolveSidebarHeaderItem(header)) : [];
|
|
65
42
|
/**
|
|
66
|
-
* Resolve sidebar items if the config is `
|
|
43
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
67
44
|
*/
|
|
68
|
-
export const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
];
|
|
75
|
-
};
|
|
45
|
+
export const resolveSidebarHeadingItem = (page, headers) => [
|
|
46
|
+
{
|
|
47
|
+
text: page.title,
|
|
48
|
+
children: resolveSidebarHeaderItems(headers),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
76
51
|
/**
|
|
77
52
|
* Resolve sidebar items if the config is an array
|
|
78
53
|
*/
|
|
79
|
-
export const resolveArraySidebarItems = (
|
|
80
|
-
const handleChildItem = (item) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
export const resolveArraySidebarItems = (sidebarConfig, headers, path, prefix = '') => {
|
|
55
|
+
const handleChildItem = (item, pathPrefix) => {
|
|
56
|
+
const childItem = isString(item)
|
|
57
|
+
? getAutoLink(resolvePrefix(pathPrefix, item))
|
|
58
|
+
: isString(item.link)
|
|
59
|
+
? {
|
|
60
|
+
...item,
|
|
61
|
+
link: isLinkInternal(item.link)
|
|
62
|
+
? getAutoLink(resolvePrefix(pathPrefix, item.link)).link
|
|
63
|
+
: item.link,
|
|
64
|
+
}
|
|
65
|
+
: item;
|
|
66
|
+
if ('children' in childItem) {
|
|
89
67
|
return {
|
|
90
68
|
...childItem,
|
|
91
|
-
children: childItem.children.map((
|
|
69
|
+
children: childItem.children.map((child) => handleChildItem(child, resolvePrefix(pathPrefix, childItem.prefix))),
|
|
92
70
|
};
|
|
93
71
|
}
|
|
94
72
|
// if the sidebar item is current page and children is not set
|
|
95
73
|
// use headers of current page as children
|
|
96
74
|
if (childItem.link === path) {
|
|
97
75
|
// skip h1 header
|
|
98
|
-
const
|
|
76
|
+
const currentHeaders = headers[0]?.level === 1 ? headers[0].children : headers;
|
|
99
77
|
return {
|
|
100
78
|
...childItem,
|
|
101
|
-
children:
|
|
79
|
+
children: resolveSidebarHeaderItems(currentHeaders),
|
|
102
80
|
};
|
|
103
81
|
}
|
|
104
82
|
return childItem;
|
|
105
83
|
};
|
|
106
|
-
return sidebarConfig.map((item) => handleChildItem(item));
|
|
84
|
+
return sidebarConfig.map((item) => handleChildItem(item, prefix));
|
|
107
85
|
};
|
|
108
86
|
/**
|
|
109
87
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
110
88
|
*/
|
|
111
|
-
export const resolveMultiSidebarItems = (page,
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
89
|
+
export const resolveMultiSidebarItems = (sidebarConfig, page, headers, path) => {
|
|
90
|
+
const sidebarRoutes = keys(sidebarConfig).sort((x, y) => y.length - x.length);
|
|
91
|
+
// Find matching config
|
|
92
|
+
for (const base of sidebarRoutes)
|
|
93
|
+
if (startsWith(decodeURI(path), base)) {
|
|
94
|
+
const matched = sidebarConfig[base];
|
|
95
|
+
return matched
|
|
96
|
+
? matched === 'heading'
|
|
97
|
+
? resolveSidebarHeadingItem(page, headers)
|
|
98
|
+
: resolveArraySidebarItems(matched, headers, path, base)
|
|
99
|
+
: [];
|
|
100
|
+
}
|
|
101
|
+
// eslint-disable-next-line no-console
|
|
102
|
+
console.warn(`${decodeURI(path)} is missing sidebar config.`);
|
|
103
|
+
return [];
|
|
104
|
+
};
|
|
105
|
+
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
106
|
+
/**
|
|
107
|
+
* Inject sidebar items global computed
|
|
108
|
+
*/
|
|
109
|
+
export const useSidebarItems = () => {
|
|
110
|
+
const sidebarItems = inject(sidebarItemsSymbol);
|
|
111
|
+
if (!sidebarItems) {
|
|
112
|
+
throw new Error('useSidebarItems() is called without provider.');
|
|
116
113
|
}
|
|
117
|
-
return
|
|
114
|
+
return sidebarItems;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Resolve sidebar items global computed
|
|
118
|
+
*
|
|
119
|
+
* It should only be resolved and provided once
|
|
120
|
+
*/
|
|
121
|
+
export const resolveSidebarItems = (sidebarConfig, page, path, routeLocale, headers) => {
|
|
122
|
+
// resolve sidebar items according to the config
|
|
123
|
+
if (sidebarConfig === false) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
if (sidebarConfig === 'heading') {
|
|
127
|
+
return resolveSidebarHeadingItem(page, headers);
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(sidebarConfig)) {
|
|
130
|
+
return resolveArraySidebarItems(sidebarConfig, headers, path, routeLocale);
|
|
131
|
+
}
|
|
132
|
+
if (isPlainObject(sidebarConfig)) {
|
|
133
|
+
return resolveMultiSidebarItems(sidebarConfig, page, headers, path);
|
|
134
|
+
}
|
|
135
|
+
return [];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
139
|
+
*/
|
|
140
|
+
export const setupSidebarItems = () => {
|
|
141
|
+
const themeLocale = useThemeLocaleData();
|
|
142
|
+
const frontmatter = usePageFrontmatter();
|
|
143
|
+
const page = usePageData();
|
|
144
|
+
const route = useRoute();
|
|
145
|
+
const routeLocale = useRouteLocale();
|
|
146
|
+
const headers = useHeaders();
|
|
147
|
+
const sidebarConfig = computed(() => frontmatter.value.home
|
|
148
|
+
? false
|
|
149
|
+
: (frontmatter.value.sidebar ??
|
|
150
|
+
themeLocale.value.sidebar ??
|
|
151
|
+
'heading'));
|
|
152
|
+
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, page.value, route.path, routeLocale.value, headers.value));
|
|
153
|
+
provide(sidebarItemsSymbol, sidebarItems);
|
|
118
154
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { useEventListener } from '@vueuse/core';
|
|
1
2
|
import { onMounted } from 'vue';
|
|
2
|
-
import
|
|
3
|
+
import cssVariables from '../styles/_variables.module.scss';
|
|
3
4
|
export var DeviceType;
|
|
4
5
|
(function (DeviceType) {
|
|
5
|
-
DeviceType["
|
|
6
|
+
DeviceType["Mobile"] = "mobile";
|
|
6
7
|
})(DeviceType || (DeviceType = {}));
|
|
7
8
|
const DeviceTypeMap = {
|
|
8
|
-
[DeviceType.
|
|
9
|
+
[DeviceType.Mobile]: Number.parseInt(cssVariables.mobile.replace('px', ''), 10),
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* add listener to detect screen though device type
|
|
@@ -17,9 +18,13 @@ export const useUpdateDeviceStatus = (deviceType, callback) => {
|
|
|
17
18
|
throw new Error('device width must be a integer');
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
21
|
+
useEventListener('orientationchange', () => {
|
|
22
|
+
callback(width);
|
|
23
|
+
}, false);
|
|
24
|
+
useEventListener('resize', () => {
|
|
25
|
+
callback(width);
|
|
26
|
+
}, false);
|
|
20
27
|
onMounted(() => {
|
|
21
28
|
callback(width);
|
|
22
|
-
window.addEventListener('resize', () => callback(width), false);
|
|
23
|
-
window.addEventListener('orientationchange', () => callback(width), false);
|
|
24
29
|
});
|
|
25
30
|
};
|
package/lib/client/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@vuepress/helper/colors.css';
|
|
2
|
+
import '@vuepress/helper/normalize.css';
|
|
2
3
|
import './styles/index.scss';
|
|
3
|
-
declare const _default: ClientConfig;
|
|
4
|
+
declare const _default: import("vuepress/client").ClientConfig;
|
|
4
5
|
export default _default;
|
package/lib/client/config.js
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
|
+
import { setupDarkMode } from '@theme/useDarkMode';
|
|
2
|
+
import { useScrollPromise } from '@theme/useScrollPromise';
|
|
3
|
+
import { setupSidebarItems } from '@theme/useSidebarItems';
|
|
1
4
|
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
2
|
-
import { h } from 'vue';
|
|
3
5
|
import { defineClientConfig } from 'vuepress/client';
|
|
4
|
-
import { Badge
|
|
5
|
-
import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
|
|
6
|
+
import { Badge } from './components/global/index.js';
|
|
6
7
|
import Layout from './layouts/Layout.vue';
|
|
7
8
|
import NotFound from './layouts/NotFound.vue';
|
|
9
|
+
import '@vuepress/helper/colors.css';
|
|
10
|
+
import '@vuepress/helper/normalize.css';
|
|
8
11
|
import './styles/index.scss';
|
|
9
12
|
export default defineClientConfig({
|
|
10
13
|
enhance({ app, router }) {
|
|
11
14
|
if (!hasGlobalComponent('Badge'))
|
|
12
15
|
app.component('Badge', Badge);
|
|
13
|
-
if (!hasGlobalComponent('CodeGroup'))
|
|
14
|
-
app.component('CodeGroup', CodeGroup);
|
|
15
|
-
if (!hasGlobalComponent('CodeGroupItem'))
|
|
16
|
-
app.component('CodeGroupItem', CodeGroupItem);
|
|
17
|
-
// compat with @vuepress/plugin-external-link-icon
|
|
18
|
-
app.component('AutoLinkExternalIcon', () => {
|
|
19
|
-
const ExternalLinkIcon = app.component('ExternalLinkIcon');
|
|
20
|
-
if (ExternalLinkIcon) {
|
|
21
|
-
return h(ExternalLinkIcon);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
});
|
|
25
|
-
// compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
|
|
26
|
-
app.component('NavbarSearch', () => {
|
|
27
|
-
const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
|
|
28
|
-
if (SearchComponent) {
|
|
29
|
-
return h(SearchComponent);
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
16
|
// handle scrollBehavior with transition
|
|
34
17
|
const scrollBehavior = router.options.scrollBehavior;
|
|
35
18
|
router.options.scrollBehavior = async (...args) => {
|
package/lib/client/index.d.ts
CHANGED
package/lib/client/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import VPHome from '@theme/VPHome.vue'
|
|
3
|
+
import VPNavbar from '@theme/VPNavbar.vue'
|
|
4
|
+
import VPPage from '@theme/VPPage.vue'
|
|
5
|
+
import VPSidebar from '@theme/VPSidebar.vue'
|
|
6
|
+
import { useScrollPromise } from '@theme/useScrollPromise'
|
|
7
|
+
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
8
|
+
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
9
|
+
import type { VNode } from 'vue'
|
|
6
10
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
7
|
-
import { useRouter } from '
|
|
8
|
-
import { usePageData, usePageFrontmatter } from 'vuepress/client'
|
|
11
|
+
import { usePageData, usePageFrontmatter, useRouter } from 'vuepress/client'
|
|
9
12
|
import type { DefaultThemePageFrontmatter } from '../../shared/index.js'
|
|
10
|
-
import {
|
|
11
|
-
useScrollPromise,
|
|
12
|
-
useSidebarItems,
|
|
13
|
-
useThemeLocaleData,
|
|
14
|
-
} from '../composables/index.js'
|
|
15
13
|
|
|
16
14
|
defineSlots<{
|
|
17
|
-
'navbar'?: (props: Record<never, never>) =>
|
|
18
|
-
'navbar-before'?: (props: Record<never, never>) =>
|
|
19
|
-
'navbar-after'?: (props: Record<never, never>) =>
|
|
20
|
-
'sidebar'?: (props: Record<never, never>) =>
|
|
21
|
-
'sidebar-top'?: (props: Record<never, never>) =>
|
|
22
|
-
'sidebar-bottom'?: (props: Record<never, never>) =>
|
|
23
|
-
'page'?: (props: Record<never, never>) =>
|
|
24
|
-
'page-top'?: (props: Record<never, never>) =>
|
|
25
|
-
'page-bottom'?: (props: Record<never, never>) =>
|
|
26
|
-
'page-content-top'?: (props: Record<never, never>) =>
|
|
27
|
-
'page-content-bottom'?: (
|
|
15
|
+
'navbar'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
16
|
+
'navbar-before'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
17
|
+
'navbar-after'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
18
|
+
'sidebar'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
19
|
+
'sidebar-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
20
|
+
'sidebar-bottom'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
21
|
+
'page'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
22
|
+
'page-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
23
|
+
'page-bottom'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
24
|
+
'page-content-top'?: (props: Record<never, never>) => VNode | VNode[] | null
|
|
25
|
+
'page-content-bottom'?: (
|
|
26
|
+
props: Record<never, never>,
|
|
27
|
+
) => VNode | VNode[] | null
|
|
28
28
|
}>()
|
|
29
29
|
|
|
30
30
|
const page = usePageData()
|
|
@@ -44,11 +44,11 @@ const toggleSidebar = (to?: boolean): void => {
|
|
|
44
44
|
isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
|
|
45
45
|
}
|
|
46
46
|
const touchStart = { x: 0, y: 0 }
|
|
47
|
-
const onTouchStart = (e): void => {
|
|
47
|
+
const onTouchStart = (e: TouchEvent): void => {
|
|
48
48
|
touchStart.x = e.changedTouches[0].clientX
|
|
49
49
|
touchStart.y = e.changedTouches[0].clientY
|
|
50
50
|
}
|
|
51
|
-
const onTouchEnd = (e): void => {
|
|
51
|
+
const onTouchEnd = (e: TouchEvent): void => {
|
|
52
52
|
const dx = e.changedTouches[0].clientX - touchStart.x
|
|
53
53
|
const dy = e.changedTouches[0].clientY - touchStart.y
|
|
54
54
|
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
|
|
@@ -60,18 +60,27 @@ const onTouchEnd = (e): void => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// external-link-icon
|
|
64
|
+
const enableExternalLinkIcon = computed(
|
|
65
|
+
() =>
|
|
66
|
+
frontmatter.value.externalLinkIcon ??
|
|
67
|
+
themeLocale.value.externalLinkIcon ??
|
|
68
|
+
true,
|
|
69
|
+
)
|
|
70
|
+
|
|
63
71
|
// classes
|
|
64
72
|
const containerClass = computed(() => [
|
|
65
73
|
{
|
|
66
74
|
'no-navbar': !shouldShowNavbar.value,
|
|
67
75
|
'no-sidebar': !sidebarItems.value.length,
|
|
68
76
|
'sidebar-open': isSidebarOpen.value,
|
|
77
|
+
'external-link-icon': enableExternalLinkIcon.value,
|
|
69
78
|
},
|
|
70
79
|
frontmatter.value.pageClass,
|
|
71
80
|
])
|
|
72
81
|
|
|
73
82
|
// close sidebar after navigation
|
|
74
|
-
let unregisterRouterHook
|
|
83
|
+
let unregisterRouterHook: () => void
|
|
75
84
|
onMounted(() => {
|
|
76
85
|
const router = useRouter()
|
|
77
86
|
unregisterRouterHook = router.afterEach(() => {
|
|
@@ -90,37 +99,38 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
90
99
|
|
|
91
100
|
<template>
|
|
92
101
|
<div
|
|
93
|
-
class="theme-container"
|
|
102
|
+
class="vp-theme-container"
|
|
94
103
|
:class="containerClass"
|
|
104
|
+
vp-container
|
|
95
105
|
@touchstart="onTouchStart"
|
|
96
106
|
@touchend="onTouchEnd"
|
|
97
107
|
>
|
|
98
108
|
<slot name="navbar">
|
|
99
|
-
<
|
|
109
|
+
<VPNavbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar">
|
|
100
110
|
<template #before>
|
|
101
111
|
<slot name="navbar-before" />
|
|
102
112
|
</template>
|
|
103
113
|
<template #after>
|
|
104
114
|
<slot name="navbar-after" />
|
|
105
115
|
</template>
|
|
106
|
-
</
|
|
116
|
+
</VPNavbar>
|
|
107
117
|
</slot>
|
|
108
118
|
|
|
109
|
-
<div class="sidebar-mask" @click="toggleSidebar(false)" />
|
|
119
|
+
<div class="vp-sidebar-mask" @click="toggleSidebar(false)" />
|
|
110
120
|
|
|
111
121
|
<slot name="sidebar">
|
|
112
|
-
<
|
|
122
|
+
<VPSidebar>
|
|
113
123
|
<template #top>
|
|
114
124
|
<slot name="sidebar-top" />
|
|
115
125
|
</template>
|
|
116
126
|
<template #bottom>
|
|
117
127
|
<slot name="sidebar-bottom" />
|
|
118
128
|
</template>
|
|
119
|
-
</
|
|
129
|
+
</VPSidebar>
|
|
120
130
|
</slot>
|
|
121
131
|
|
|
122
132
|
<slot name="page">
|
|
123
|
-
<
|
|
133
|
+
<VPHome v-if="frontmatter.home" />
|
|
124
134
|
|
|
125
135
|
<Transition
|
|
126
136
|
v-else
|
|
@@ -129,7 +139,7 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
129
139
|
@before-enter="onBeforeEnter"
|
|
130
140
|
@before-leave="onBeforeLeave"
|
|
131
141
|
>
|
|
132
|
-
<
|
|
142
|
+
<VPPage :key="page.path">
|
|
133
143
|
<template #top>
|
|
134
144
|
<slot name="page-top" />
|
|
135
145
|
</template>
|
|
@@ -142,8 +152,103 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
142
152
|
<template #bottom>
|
|
143
153
|
<slot name="page-bottom" />
|
|
144
154
|
</template>
|
|
145
|
-
</
|
|
155
|
+
</VPPage>
|
|
146
156
|
</Transition>
|
|
147
157
|
</slot>
|
|
148
158
|
</div>
|
|
149
159
|
</template>
|
|
160
|
+
|
|
161
|
+
<style lang="scss">
|
|
162
|
+
@use '../styles/variables' as *;
|
|
163
|
+
|
|
164
|
+
.vp-sidebar-mask {
|
|
165
|
+
position: fixed;
|
|
166
|
+
top: 0;
|
|
167
|
+
left: 0;
|
|
168
|
+
z-index: 9;
|
|
169
|
+
|
|
170
|
+
display: none;
|
|
171
|
+
|
|
172
|
+
width: 100vw;
|
|
173
|
+
height: 100vh;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.vp-theme-container {
|
|
177
|
+
// navbar is disabled
|
|
178
|
+
&.no-navbar {
|
|
179
|
+
.vp-sidebar {
|
|
180
|
+
top: 0;
|
|
181
|
+
|
|
182
|
+
@media (max-width: $MQMobile) {
|
|
183
|
+
padding-top: 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.vp-page {
|
|
188
|
+
padding-top: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// adjust heading margin and padding;
|
|
192
|
+
.theme-default-content {
|
|
193
|
+
h1,
|
|
194
|
+
h2,
|
|
195
|
+
h3,
|
|
196
|
+
h4,
|
|
197
|
+
h5,
|
|
198
|
+
h6 {
|
|
199
|
+
margin-top: 1.5rem;
|
|
200
|
+
padding-top: 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&.no-sidebar {
|
|
206
|
+
// hide sidebar
|
|
207
|
+
.vp-sidebar {
|
|
208
|
+
display: none;
|
|
209
|
+
|
|
210
|
+
// show sidebar on mobile because it has navbar links
|
|
211
|
+
@media (max-width: $MQMobile) {
|
|
212
|
+
display: block;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.vp-page {
|
|
217
|
+
padding-left: 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&.sidebar-open {
|
|
222
|
+
@media (max-width: $MQMobile) {
|
|
223
|
+
// show sidebar
|
|
224
|
+
.vp-sidebar {
|
|
225
|
+
transform: translateX(0);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// show sidebar mask
|
|
229
|
+
.vp-sidebar-mask {
|
|
230
|
+
display: block;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* fade-slide-y transition
|
|
238
|
+
*/
|
|
239
|
+
.fade-slide-y {
|
|
240
|
+
&-enter-active {
|
|
241
|
+
transition: all 0.2s ease;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
&-leave-active {
|
|
245
|
+
transition: all 0.2s cubic-bezier(1, 0.5, 0.8, 1);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
&-enter-from,
|
|
249
|
+
&-leave-to {
|
|
250
|
+
opacity: 0;
|
|
251
|
+
transform: translateY(10px);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
</style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useThemeLocaleData } from '@theme/useThemeData'
|
|
3
|
+
import { RouteLink, useRouteLocale } from 'vuepress/client'
|
|
4
4
|
|
|
5
5
|
const routeLocale = useRouteLocale()
|
|
6
6
|
const themeLocale = useThemeLocaleData()
|
|
@@ -13,15 +13,27 @@ const homeText = themeLocale.value.backToHome ?? 'Back to home'
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<template>
|
|
16
|
-
<div class="theme-container">
|
|
16
|
+
<div class="vp-theme-container" vp-container>
|
|
17
17
|
<main class="page">
|
|
18
|
-
<div class="theme-default-content">
|
|
18
|
+
<div class="theme-default-content" vp-content>
|
|
19
19
|
<h1>404</h1>
|
|
20
20
|
|
|
21
21
|
<blockquote>{{ getMsg() }}</blockquote>
|
|
22
22
|
|
|
23
|
-
<
|
|
23
|
+
<RouteLink :to="homeLink">{{ homeText }}</RouteLink>
|
|
24
24
|
</div>
|
|
25
25
|
</main>
|
|
26
26
|
</div>
|
|
27
27
|
</template>
|
|
28
|
+
|
|
29
|
+
<style scoped lang="scss">
|
|
30
|
+
.vp-theme-container {
|
|
31
|
+
max-width: 740px;
|
|
32
|
+
margin: 0 auto;
|
|
33
|
+
padding: 2rem 2.5rem;
|
|
34
|
+
|
|
35
|
+
@media (max-width: 959px) {
|
|
36
|
+
padding: 2rem;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
</style>
|
package/lib/client/shim.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
declare module '*.vue' {
|
|
2
2
|
import type { ComponentOptions } from 'vue'
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
const component: ComponentOptions
|
|
5
|
+
export default component
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
declare module '
|
|
8
|
-
const
|
|
9
|
-
export default
|
|
8
|
+
declare module '*/styles/_variables.module.scss' {
|
|
9
|
+
const cSSVariables: Record<string, string>
|
|
10
|
+
export default cSSVariables
|
|
10
11
|
}
|