@vuepress/theme-default 2.0.0-rc.10 → 2.0.0-rc.101
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/VPAutoLink.vue +32 -0
- package/lib/client/components/VPDarkIcon.vue +8 -0
- package/lib/client/components/VPDropdownTransition.vue +43 -0
- package/lib/client/components/VPEditIcon.vue +12 -0
- package/lib/client/components/VPFadeSlideYTransition.vue +23 -0
- package/lib/client/components/VPHome.vue +37 -0
- package/lib/client/components/VPHomeFeatures.vue +65 -0
- package/lib/client/components/VPHomeFooter.vue +30 -0
- package/lib/client/components/VPHomeHero.vue +186 -0
- package/lib/client/components/VPLightIcon.vue +28 -0
- package/lib/client/components/VPNavbar.vue +138 -0
- package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +39 -15
- package/lib/client/components/VPNavbarDropdown.vue +330 -0
- package/lib/client/components/VPNavbarItems.vue +111 -0
- package/lib/client/components/VPPage.vue +69 -0
- package/lib/client/components/VPPageMeta.vue +139 -0
- package/lib/client/components/VPPageNav.vue +123 -0
- package/lib/client/components/VPSidebar.vue +120 -0
- package/lib/client/components/VPSidebarItem.vue +189 -0
- package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +27 -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 +7 -1
- package/lib/client/composables/index.js +7 -1
- package/lib/client/composables/useDarkMode.d.ts +0 -1
- package/lib/client/composables/useDarkMode.js +19 -16
- package/lib/client/composables/useData.d.ts +8 -0
- package/lib/client/composables/useData.js +7 -0
- package/lib/client/composables/useEditLink.d.ts +3 -0
- package/lib/client/composables/useEditLink.js +28 -0
- package/lib/client/composables/useHeaders.d.ts +9 -0
- package/lib/client/composables/useHeaders.js +38 -0
- package/lib/client/composables/useNavbarConfig.d.ts +3 -0
- package/lib/client/composables/useNavbarConfig.js +29 -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 +55 -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 +90 -0
- package/lib/client/composables/useScrollPromise.js +3 -1
- package/lib/client/composables/useSidebarItems.d.ts +21 -20
- package/lib/client/composables/useSidebarItems.js +96 -85
- 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 +8 -23
- package/lib/client/index.d.ts +1 -0
- package/lib/client/layouts/Layout.vue +128 -56
- package/lib/client/layouts/NotFound.vue +24 -10
- 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 +24 -22
- package/lib/client/styles/code-group.scss +34 -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 +5 -197
- 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 +54 -139
- package/lib/client/typings.d.ts +13 -0
- package/lib/client/typings.js +1 -0
- package/lib/client/utils/index.d.ts +2 -1
- package/lib/client/utils/index.js +2 -1
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -3
- package/lib/client/utils/isActiveSidebarItem.js +1 -1
- package/lib/client/utils/resolveAutoLink.d.ts +9 -0
- package/lib/client/utils/{getNavLink.js → resolveAutoLink.js} +3 -3
- package/lib/client/utils/resolveEditLink.d.ts +3 -3
- package/lib/client/utils/resolveEditLink.js +3 -3
- 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 +57 -64
- package/lib/node/index.d.ts +1 -3
- package/lib/node/index.js +0 -3
- package/lib/node/typings.d.ts +59 -0
- package/lib/node/typings.js +1 -0
- package/lib/node/utils/assignDefaultLocaleOptions.js +3 -8
- 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 -66
- 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 +29 -27
- package/templates/build.html +16 -10
- 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/HomeFooter.vue +0 -17
- package/lib/client/components/HomeHero.vue +0 -97
- package/lib/client/components/Navbar.vue +0 -79
- package/lib/client/components/NavbarDropdown.vue +0 -126
- package/lib/client/components/NavbarItems.vue +0 -194
- 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/composables/useThemeData.d.ts +0 -4
- package/lib/client/composables/useThemeData.js +0 -3
- 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 -9
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +0 -8
- package/lib/node/utils/resolveContainerPluginOptions.js +0 -17
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
2
|
import type { PageData, PageHeader } from 'vuepress/client';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
3
|
+
import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
|
|
4
|
+
import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* Util to transform page header to sidebar item
|
|
8
7
|
*/
|
|
9
|
-
export declare const
|
|
8
|
+
export declare const resolveSidebarPageHeader: (header: PageHeader) => SidebarHeaderItem;
|
|
9
|
+
export declare const resolveSidebarPageHeaders: (headers?: PageHeader[]) => SidebarHeaderItem[];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
12
12
|
*/
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const resolveSidebarHeadingItem: (page: PageData, headers: PageHeader[]) => SidebarItem[];
|
|
14
14
|
/**
|
|
15
|
-
* Resolve sidebar items
|
|
16
|
-
*
|
|
17
|
-
* It should only be resolved and provided once
|
|
15
|
+
* Resolve sidebar items if the config is an array
|
|
18
16
|
*/
|
|
19
|
-
export declare const
|
|
17
|
+
export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptions, headers: PageHeader[], path: string, prefix?: string) => SidebarItem[];
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
19
|
+
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
22
20
|
*/
|
|
23
|
-
export declare const
|
|
24
|
-
export
|
|
21
|
+
export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, page: PageData, headers: PageHeader[], path: string) => SidebarItem[];
|
|
22
|
+
export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
|
|
23
|
+
export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Inject sidebar items global computed
|
|
27
26
|
*/
|
|
28
|
-
export declare const
|
|
27
|
+
export declare const useSidebarItems: () => SidebarItemsRef;
|
|
29
28
|
/**
|
|
30
|
-
* Resolve sidebar items
|
|
29
|
+
* Resolve sidebar items global computed
|
|
30
|
+
*
|
|
31
|
+
* It should only be resolved and provided once
|
|
31
32
|
*/
|
|
32
|
-
export declare const
|
|
33
|
+
export declare const resolveSidebarItems: (sidebarConfig: SidebarOptions | false, page: PageData, path: string, routeLocale: string, headers: PageHeader[]) => SidebarItem[];
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
35
36
|
*/
|
|
36
|
-
export declare const
|
|
37
|
+
export declare const setupSidebarItems: () => void;
|
|
@@ -1,117 +1,128 @@
|
|
|
1
|
+
import { resolveAutoLink } from '@theme/resolveAutoLink';
|
|
2
|
+
import { resolvePrefix } from '@theme/resolvePrefix';
|
|
3
|
+
import { useData } from '@theme/useData';
|
|
4
|
+
import { useHeaders } from '@theme/useHeaders';
|
|
5
|
+
import { isLinkRelative, keys, startsWith } from '@vuepress/helper/client';
|
|
1
6
|
import { computed, inject, provide } from 'vue';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
|
|
5
|
-
import { getNavLink } from '../utils/index.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 page = usePageData();
|
|
25
|
-
const route = useRoute();
|
|
26
|
-
const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, route.path));
|
|
27
|
-
provide(sidebarItemsSymbol, sidebarItems);
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Resolve sidebar items global computed
|
|
31
|
-
*
|
|
32
|
-
* It should only be resolved and provided once
|
|
33
|
-
*/
|
|
34
|
-
export const resolveSidebarItems = (frontmatter, themeLocale, page, path) => {
|
|
35
|
-
// get sidebar config from frontmatter > theme data
|
|
36
|
-
const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
|
|
37
|
-
const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
|
|
38
|
-
// resolve sidebar items according to the config
|
|
39
|
-
if (frontmatter.home || sidebarConfig === false) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
if (sidebarConfig === 'auto') {
|
|
43
|
-
return resolveAutoSidebarItems(page, sidebarDepth);
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(sidebarConfig)) {
|
|
46
|
-
return resolveArraySidebarItems(page, path, sidebarConfig, sidebarDepth);
|
|
47
|
-
}
|
|
48
|
-
if (isPlainObject(sidebarConfig)) {
|
|
49
|
-
return resolveMultiSidebarItems(page, path, sidebarConfig, sidebarDepth);
|
|
50
|
-
}
|
|
51
|
-
return [];
|
|
52
|
-
};
|
|
7
|
+
import { useRoutePath } from 'vuepress/client';
|
|
8
|
+
import { isPlainObject, isString } from 'vuepress/shared';
|
|
53
9
|
/**
|
|
54
10
|
* Util to transform page header to sidebar item
|
|
55
11
|
*/
|
|
56
|
-
export const
|
|
12
|
+
export const resolveSidebarPageHeader = (header) => ({
|
|
57
13
|
text: header.title,
|
|
58
14
|
link: header.link,
|
|
59
|
-
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
+
children: resolveSidebarPageHeaders(header.children),
|
|
60
17
|
});
|
|
61
|
-
export const
|
|
62
|
-
? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
|
|
63
|
-
: [];
|
|
18
|
+
export const resolveSidebarPageHeaders = (headers) => headers ? headers.map((header) => resolveSidebarPageHeader(header)) : [];
|
|
64
19
|
/**
|
|
65
|
-
* Resolve sidebar items if the config is `
|
|
20
|
+
* Resolve current page and its header to sidebar items if the config is `heading`
|
|
66
21
|
*/
|
|
67
|
-
export const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
];
|
|
74
|
-
};
|
|
22
|
+
export const resolveSidebarHeadingItem = (page, headers) => [
|
|
23
|
+
{
|
|
24
|
+
text: page.title,
|
|
25
|
+
children: resolveSidebarPageHeaders(headers),
|
|
26
|
+
},
|
|
27
|
+
];
|
|
75
28
|
/**
|
|
76
29
|
* Resolve sidebar items if the config is an array
|
|
77
30
|
*/
|
|
78
|
-
export const resolveArraySidebarItems = (
|
|
79
|
-
const handleChildItem = (item) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
31
|
+
export const resolveArraySidebarItems = (sidebarConfig, headers, path, prefix = '') => {
|
|
32
|
+
const handleChildItem = (item, pathPrefix) => {
|
|
33
|
+
const childItem = isString(item)
|
|
34
|
+
? resolveAutoLink(resolvePrefix(pathPrefix, item))
|
|
35
|
+
: isString(item.link)
|
|
36
|
+
? {
|
|
37
|
+
...item,
|
|
38
|
+
link: isLinkRelative(item.link)
|
|
39
|
+
? resolveAutoLink(resolvePrefix(pathPrefix, item.link)).link
|
|
40
|
+
: item.link,
|
|
41
|
+
}
|
|
42
|
+
: item;
|
|
43
|
+
if ('children' in childItem) {
|
|
88
44
|
return {
|
|
89
45
|
...childItem,
|
|
90
|
-
children: childItem.children.map((
|
|
46
|
+
children: childItem.children.map((child) => handleChildItem(child, resolvePrefix(pathPrefix, childItem.prefix))),
|
|
91
47
|
};
|
|
92
48
|
}
|
|
93
49
|
// if the sidebar item is current page and children is not set
|
|
94
50
|
// use headers of current page as children
|
|
95
51
|
if (childItem.link === path) {
|
|
96
52
|
// skip h1 header
|
|
97
|
-
const
|
|
53
|
+
const currentHeaders = headers[0]?.level === 1 ? headers[0].children : headers;
|
|
98
54
|
return {
|
|
99
55
|
...childItem,
|
|
100
|
-
children:
|
|
56
|
+
children: resolveSidebarPageHeaders(currentHeaders),
|
|
101
57
|
};
|
|
102
58
|
}
|
|
103
59
|
return childItem;
|
|
104
60
|
};
|
|
105
|
-
return sidebarConfig.map((item) => handleChildItem(item));
|
|
61
|
+
return sidebarConfig.map((item) => handleChildItem(item, prefix));
|
|
106
62
|
};
|
|
107
63
|
/**
|
|
108
64
|
* Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
|
|
109
65
|
*/
|
|
110
|
-
export const resolveMultiSidebarItems = (
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
66
|
+
export const resolveMultiSidebarItems = (sidebarConfig, page, headers, path) => {
|
|
67
|
+
const sidebarRoutes = keys(sidebarConfig).sort((x, y) => y.length - x.length);
|
|
68
|
+
// Find matching config
|
|
69
|
+
for (const base of sidebarRoutes)
|
|
70
|
+
if (startsWith(decodeURI(path), base)) {
|
|
71
|
+
const matched = sidebarConfig[base];
|
|
72
|
+
return matched
|
|
73
|
+
? matched === 'heading'
|
|
74
|
+
? resolveSidebarHeadingItem(page, headers)
|
|
75
|
+
: resolveArraySidebarItems(matched, headers, path, base)
|
|
76
|
+
: [];
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.warn(`${decodeURI(path)} is missing sidebar config.`);
|
|
80
|
+
return [];
|
|
81
|
+
};
|
|
82
|
+
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
83
|
+
/**
|
|
84
|
+
* Inject sidebar items global computed
|
|
85
|
+
*/
|
|
86
|
+
export const useSidebarItems = () => {
|
|
87
|
+
const sidebarItems = inject(sidebarItemsSymbol);
|
|
88
|
+
if (!sidebarItems) {
|
|
89
|
+
throw new Error('useSidebarItems() is called without provider.');
|
|
90
|
+
}
|
|
91
|
+
return sidebarItems;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Resolve sidebar items global computed
|
|
95
|
+
*
|
|
96
|
+
* It should only be resolved and provided once
|
|
97
|
+
*/
|
|
98
|
+
export const resolveSidebarItems = (sidebarConfig, page, path, routeLocale, headers) => {
|
|
99
|
+
// resolve sidebar items according to the config
|
|
100
|
+
if (sidebarConfig === false) {
|
|
101
|
+
return [];
|
|
115
102
|
}
|
|
116
|
-
|
|
103
|
+
if (sidebarConfig === 'heading') {
|
|
104
|
+
return resolveSidebarHeadingItem(page, headers);
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(sidebarConfig)) {
|
|
107
|
+
return resolveArraySidebarItems(sidebarConfig, headers, path, routeLocale);
|
|
108
|
+
}
|
|
109
|
+
if (isPlainObject(sidebarConfig)) {
|
|
110
|
+
return resolveMultiSidebarItems(sidebarConfig, page, headers, path);
|
|
111
|
+
}
|
|
112
|
+
return [];
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Create sidebar items ref and provide as global computed in setup
|
|
116
|
+
*/
|
|
117
|
+
export const setupSidebarItems = () => {
|
|
118
|
+
const { frontmatter, page, routeLocale, themeLocale } = useData();
|
|
119
|
+
const headers = useHeaders();
|
|
120
|
+
const routePath = useRoutePath();
|
|
121
|
+
const sidebarConfig = computed(() => frontmatter.value.home
|
|
122
|
+
? false
|
|
123
|
+
: (frontmatter.value.sidebar ??
|
|
124
|
+
themeLocale.value.sidebar ??
|
|
125
|
+
'heading'));
|
|
126
|
+
const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, page.value, routePath.value, routeLocale.value, headers.value));
|
|
127
|
+
provide(sidebarItemsSymbol, sidebarItems);
|
|
117
128
|
};
|
|
@@ -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
|
+
});
|
|
24
|
+
useEventListener('resize', () => {
|
|
25
|
+
callback(width);
|
|
26
|
+
});
|
|
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,19 @@
|
|
|
1
|
+
import { setupDarkMode } from '@theme/useDarkMode';
|
|
2
|
+
import { setupHeaders } from '@theme/useHeaders';
|
|
3
|
+
import { useScrollPromise } from '@theme/useScrollPromise';
|
|
4
|
+
import { setupSidebarItems } from '@theme/useSidebarItems';
|
|
1
5
|
import { hasGlobalComponent } from '@vuepress/helper/client';
|
|
2
|
-
import { h } from 'vue';
|
|
3
6
|
import { defineClientConfig } from 'vuepress/client';
|
|
4
|
-
import { Badge
|
|
5
|
-
import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
|
|
7
|
+
import { Badge } from './components/global/index.js';
|
|
6
8
|
import Layout from './layouts/Layout.vue';
|
|
7
9
|
import NotFound from './layouts/NotFound.vue';
|
|
10
|
+
import '@vuepress/helper/colors.css';
|
|
11
|
+
import '@vuepress/helper/normalize.css';
|
|
8
12
|
import './styles/index.scss';
|
|
9
13
|
export default defineClientConfig({
|
|
10
14
|
enhance({ app, router }) {
|
|
11
15
|
if (!hasGlobalComponent('Badge'))
|
|
12
16
|
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
17
|
// handle scrollBehavior with transition
|
|
34
18
|
const scrollBehavior = router.options.scrollBehavior;
|
|
35
19
|
router.options.scrollBehavior = async (...args) => {
|
|
@@ -39,6 +23,7 @@ export default defineClientConfig({
|
|
|
39
23
|
},
|
|
40
24
|
setup() {
|
|
41
25
|
setupDarkMode();
|
|
26
|
+
setupHeaders();
|
|
42
27
|
setupSidebarItems();
|
|
43
28
|
},
|
|
44
29
|
layouts: {
|
package/lib/client/index.d.ts
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
useThemeLocaleData,
|
|
14
|
-
} from '../composables/index.js'
|
|
2
|
+
import VPFadeSlideYTransition from '@theme/VPFadeSlideYTransition.vue'
|
|
3
|
+
import VPHome from '@theme/VPHome.vue'
|
|
4
|
+
import VPNavbar from '@theme/VPNavbar.vue'
|
|
5
|
+
import VPPage from '@theme/VPPage.vue'
|
|
6
|
+
import VPSidebar from '@theme/VPSidebar.vue'
|
|
7
|
+
import { useData } from '@theme/useData'
|
|
8
|
+
import { useScrollPromise } from '@theme/useScrollPromise'
|
|
9
|
+
import { useSidebarItems } from '@theme/useSidebarItems'
|
|
10
|
+
import type { VNode } from 'vue'
|
|
11
|
+
import { computed, ref } from 'vue'
|
|
12
|
+
import { onContentUpdated } from 'vuepress/client'
|
|
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
|
-
const page =
|
|
31
|
-
const frontmatter = usePageFrontmatter<DefaultThemePageFrontmatter>()
|
|
32
|
-
const themeLocale = useThemeLocaleData()
|
|
30
|
+
const { frontmatter, page, themeLocale } = useData()
|
|
33
31
|
|
|
34
32
|
// navbar
|
|
35
33
|
const shouldShowNavbar = computed(
|
|
36
|
-
() =>
|
|
37
|
-
frontmatter.value.navbar !== false && themeLocale.value.navbar !== false,
|
|
34
|
+
() => frontmatter.value.navbar ?? themeLocale.value.navbar ?? true,
|
|
38
35
|
)
|
|
39
36
|
|
|
40
37
|
// sidebar
|
|
@@ -44,11 +41,11 @@ const toggleSidebar = (to?: boolean): void => {
|
|
|
44
41
|
isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
|
|
45
42
|
}
|
|
46
43
|
const touchStart = { x: 0, y: 0 }
|
|
47
|
-
const onTouchStart = (e): void => {
|
|
44
|
+
const onTouchStart = (e: TouchEvent): void => {
|
|
48
45
|
touchStart.x = e.changedTouches[0].clientX
|
|
49
46
|
touchStart.y = e.changedTouches[0].clientY
|
|
50
47
|
}
|
|
51
|
-
const onTouchEnd = (e): void => {
|
|
48
|
+
const onTouchEnd = (e: TouchEvent): void => {
|
|
52
49
|
const dx = e.changedTouches[0].clientX - touchStart.x
|
|
53
50
|
const dy = e.changedTouches[0].clientY - touchStart.y
|
|
54
51
|
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
|
|
@@ -60,26 +57,28 @@ const onTouchEnd = (e): void => {
|
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
|
|
60
|
+
// external-link-icon
|
|
61
|
+
const enableExternalLinkIcon = computed(
|
|
62
|
+
() =>
|
|
63
|
+
frontmatter.value.externalLinkIcon ??
|
|
64
|
+
themeLocale.value.externalLinkIcon ??
|
|
65
|
+
true,
|
|
66
|
+
)
|
|
67
|
+
|
|
63
68
|
// classes
|
|
64
69
|
const containerClass = computed(() => [
|
|
65
70
|
{
|
|
66
71
|
'no-navbar': !shouldShowNavbar.value,
|
|
67
72
|
'no-sidebar': !sidebarItems.value.length,
|
|
68
73
|
'sidebar-open': isSidebarOpen.value,
|
|
74
|
+
'external-link-icon': enableExternalLinkIcon.value,
|
|
69
75
|
},
|
|
70
76
|
frontmatter.value.pageClass,
|
|
71
77
|
])
|
|
72
78
|
|
|
73
|
-
// close sidebar
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const router = useRouter()
|
|
77
|
-
unregisterRouterHook = router.afterEach(() => {
|
|
78
|
-
toggleSidebar(false)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
onUnmounted(() => {
|
|
82
|
-
unregisterRouterHook()
|
|
79
|
+
// close sidebar when content changes
|
|
80
|
+
onContentUpdated(() => {
|
|
81
|
+
toggleSidebar(false)
|
|
83
82
|
})
|
|
84
83
|
|
|
85
84
|
// handle scrollBehavior with transition
|
|
@@ -90,46 +89,43 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
90
89
|
|
|
91
90
|
<template>
|
|
92
91
|
<div
|
|
93
|
-
class="theme-container"
|
|
92
|
+
class="vp-theme-container"
|
|
94
93
|
:class="containerClass"
|
|
94
|
+
vp-container
|
|
95
95
|
@touchstart="onTouchStart"
|
|
96
96
|
@touchend="onTouchEnd"
|
|
97
97
|
>
|
|
98
98
|
<slot name="navbar">
|
|
99
|
-
<
|
|
99
|
+
<VPNavbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar">
|
|
100
100
|
<template #before>
|
|
101
101
|
<slot name="navbar-before" />
|
|
102
102
|
</template>
|
|
103
103
|
<template #after>
|
|
104
104
|
<slot name="navbar-after" />
|
|
105
105
|
</template>
|
|
106
|
-
</
|
|
106
|
+
</VPNavbar>
|
|
107
107
|
</slot>
|
|
108
108
|
|
|
109
|
-
<div class="sidebar-mask" @click="toggleSidebar(false)" />
|
|
109
|
+
<div class="vp-sidebar-mask" @click="toggleSidebar(false)" />
|
|
110
110
|
|
|
111
111
|
<slot name="sidebar">
|
|
112
|
-
<
|
|
112
|
+
<VPSidebar>
|
|
113
113
|
<template #top>
|
|
114
114
|
<slot name="sidebar-top" />
|
|
115
115
|
</template>
|
|
116
116
|
<template #bottom>
|
|
117
117
|
<slot name="sidebar-bottom" />
|
|
118
118
|
</template>
|
|
119
|
-
</
|
|
119
|
+
</VPSidebar>
|
|
120
120
|
</slot>
|
|
121
121
|
|
|
122
122
|
<slot name="page">
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
<Transition
|
|
126
|
-
v-else
|
|
127
|
-
name="fade-slide-y"
|
|
128
|
-
mode="out-in"
|
|
123
|
+
<VPFadeSlideYTransition
|
|
129
124
|
@before-enter="onBeforeEnter"
|
|
130
125
|
@before-leave="onBeforeLeave"
|
|
131
126
|
>
|
|
132
|
-
<
|
|
127
|
+
<VPHome v-if="frontmatter.home" />
|
|
128
|
+
<VPPage v-else :key="page.path">
|
|
133
129
|
<template #top>
|
|
134
130
|
<slot name="page-top" />
|
|
135
131
|
</template>
|
|
@@ -142,8 +138,84 @@ const onBeforeLeave = scrollPromise.pending
|
|
|
142
138
|
<template #bottom>
|
|
143
139
|
<slot name="page-bottom" />
|
|
144
140
|
</template>
|
|
145
|
-
</
|
|
146
|
-
</
|
|
141
|
+
</VPPage>
|
|
142
|
+
</VPFadeSlideYTransition>
|
|
147
143
|
</slot>
|
|
148
144
|
</div>
|
|
149
145
|
</template>
|
|
146
|
+
|
|
147
|
+
<style lang="scss">
|
|
148
|
+
@use '../styles/variables' as *;
|
|
149
|
+
|
|
150
|
+
.vp-sidebar-mask {
|
|
151
|
+
position: fixed;
|
|
152
|
+
top: 0;
|
|
153
|
+
left: 0;
|
|
154
|
+
z-index: 9;
|
|
155
|
+
|
|
156
|
+
display: none;
|
|
157
|
+
|
|
158
|
+
width: 100vw;
|
|
159
|
+
height: 100vh;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.vp-theme-container {
|
|
163
|
+
// navbar is disabled
|
|
164
|
+
&.no-navbar {
|
|
165
|
+
.vp-sidebar {
|
|
166
|
+
top: 0;
|
|
167
|
+
|
|
168
|
+
@media (max-width: $MQMobile) {
|
|
169
|
+
padding-top: 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.vp-page {
|
|
174
|
+
padding-top: 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// adjust heading margin and padding;
|
|
178
|
+
[vp-content] {
|
|
179
|
+
h1,
|
|
180
|
+
h2,
|
|
181
|
+
h3,
|
|
182
|
+
h4,
|
|
183
|
+
h5,
|
|
184
|
+
h6 {
|
|
185
|
+
margin-top: 1.5rem;
|
|
186
|
+
padding-top: 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
&.no-sidebar {
|
|
192
|
+
// hide sidebar
|
|
193
|
+
.vp-sidebar {
|
|
194
|
+
display: none;
|
|
195
|
+
|
|
196
|
+
// show sidebar on mobile because it has navbar links
|
|
197
|
+
@media (max-width: $MQMobile) {
|
|
198
|
+
display: block;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.vp-page {
|
|
203
|
+
padding-inline-start: 0;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
&.sidebar-open {
|
|
208
|
+
@media (max-width: $MQMobile) {
|
|
209
|
+
// show sidebar
|
|
210
|
+
.vp-sidebar {
|
|
211
|
+
transform: translateX(0);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// show sidebar mask
|
|
215
|
+
.vp-sidebar-mask {
|
|
216
|
+
display: block;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
</style>
|