@vuepress/theme-default 2.0.0-beta.41 → 2.0.0-beta.44

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.
@@ -52,9 +52,8 @@ export default defineComponent({
52
52
  // NOTICE: here we put the `slots.default()` inside the render function to make
53
53
  // the slots reactive, otherwise the slot content won't be changed once the
54
54
  // `setup()` function of current component is called
55
- var _a;
56
55
  // get children code-group-item
57
- const items = (((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || [])
56
+ const items = (slots.default?.() || [])
58
57
  .filter((vnode) => vnode.type.name === 'CodeGroupItem')
59
58
  .map((vnode) => {
60
59
  if (vnode.props === null) {
@@ -47,8 +47,8 @@ export const setupDarkMode = () => {
47
47
  export const updateHtmlDarkClass = (isDarkMode) => {
48
48
  const update = (value = isDarkMode.value) => {
49
49
  // set `class="dark"` on `<html>` element
50
- const htmlEl = window === null || window === void 0 ? void 0 : window.document.querySelector('html');
51
- htmlEl === null || htmlEl === void 0 ? void 0 : htmlEl.classList.toggle('dark', value);
50
+ const htmlEl = window?.document.querySelector('html');
51
+ htmlEl?.classList.toggle('dark', value);
52
52
  };
53
53
  onMounted(() => {
54
54
  watch(isDarkMode, update, { immediate: true });
@@ -7,7 +7,10 @@ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
7
7
  * - Output: { text: 'Home', link: '/' }
8
8
  */
9
9
  export const useNavLink = (item) => {
10
- const resolved = useResolveRouteWithRedirect(item);
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,
@@ -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 (!(lastMatched === null || lastMatched === void 0 ? void 0 : lastMatched.redirect)) {
10
+ if (!lastMatched?.redirect) {
11
11
  return route;
12
12
  }
13
13
  const { redirect } = lastMatched;
@@ -6,7 +6,7 @@ const scrollPromise = {
6
6
  promise = new Promise((resolve) => (promiseResolve = resolve));
7
7
  },
8
8
  resolve: () => {
9
- promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve();
9
+ promiseResolve?.();
10
10
  promise = null;
11
11
  promiseResolve = null;
12
12
  },
@@ -29,10 +29,9 @@ export const setupSidebarItems = () => {
29
29
  * It should only be resolved and provided once
30
30
  */
31
31
  export const resolveSidebarItems = (frontmatter, themeLocale) => {
32
- var _a, _b, _c, _d;
33
32
  // get sidebar config from frontmatter > theme data
34
- const sidebarConfig = (_b = (_a = frontmatter.sidebar) !== null && _a !== void 0 ? _a : themeLocale.sidebar) !== null && _b !== void 0 ? _b : 'auto';
35
- const sidebarDepth = (_d = (_c = frontmatter.sidebarDepth) !== null && _c !== void 0 ? _c : themeLocale.sidebarDepth) !== null && _d !== void 0 ? _d : 2;
33
+ const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
34
+ const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
36
35
  // resolve sidebar items according to the config
37
36
  if (frontmatter.home || sidebarConfig === false) {
38
37
  return [];
@@ -78,7 +77,6 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
78
77
  const route = useRoute();
79
78
  const page = usePageData();
80
79
  const handleChildItem = (item) => {
81
- var _a;
82
80
  let childItem;
83
81
  if (isString(item)) {
84
82
  childItem = useNavLink(item);
@@ -96,7 +94,7 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
96
94
  // use headers of current page as children
97
95
  if (childItem.link === route.path) {
98
96
  // skip h1 header
99
- const headers = ((_a = page.value.headers[0]) === null || _a === void 0 ? void 0 : _a.level) === 1
97
+ const headers = page.value.headers[0]?.level === 1
100
98
  ? page.value.headers[0].children
101
99
  : page.value.headers;
102
100
  return {
@@ -112,9 +110,8 @@ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
112
110
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
113
111
  */
114
112
  export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
115
- var _a;
116
113
  const route = useRoute();
117
114
  const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
118
- const matchedSidebarConfig = (_a = sidebarConfig[sidebarPath]) !== null && _a !== void 0 ? _a : [];
115
+ const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
119
116
  return resolveArraySidebarItems(matchedSidebarConfig, sidebarDepth);
120
117
  };
@@ -0,0 +1,3 @@
1
+ import './styles/index.scss';
2
+ declare const _default: import("@vuepress/client").ClientConfig;
3
+ export default _default;
@@ -0,0 +1,40 @@
1
+ import { defineClientConfig } from '@vuepress/client';
2
+ import { h } from 'vue';
3
+ import Badge from './components/global/Badge.vue';
4
+ import CodeGroup from './components/global/CodeGroup';
5
+ import CodeGroupItem from './components/global/CodeGroupItem.vue';
6
+ import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables';
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
+ });
@@ -218,17 +218,19 @@ div[class*='language-'] {
218
218
  color: var(--code-ln-color);
219
219
  padding-top: 1.25rem;
220
220
  line-height: 1.4;
221
-
222
- br {
223
- user-select: none;
224
- }
221
+ counter-reset: line-number;
225
222
 
226
223
  .line-number {
227
224
  position: relative;
228
225
  z-index: 3;
229
226
  user-select: none;
230
- font-size: 0.85em;
231
- line-height: 0;
227
+ height: 1.4em;
228
+
229
+ &::before {
230
+ counter-increment: line-number;
231
+ content: counter(line-number);
232
+ font-size: 0.85em;
233
+ }
232
234
  }
233
235
  }
234
236
 
@@ -10,11 +10,15 @@ html.dark {
10
10
  color-scheme: dark;
11
11
  }
12
12
 
13
+ html {
14
+ font-size: 16px;
15
+ }
16
+
13
17
  body {
14
18
  font-family: var(--font-family);
15
19
  -webkit-font-smoothing: antialiased;
16
20
  -moz-osx-font-smoothing: grayscale;
17
- font-size: 16px;
21
+ font-size: 1rem;
18
22
  color: var(--c-text);
19
23
  }
20
24
 
@@ -14,7 +14,6 @@ const plugin_theme_data_1 = require("@vuepress/plugin-theme-data");
14
14
  const utils_1 = require("@vuepress/utils");
15
15
  const utils_2 = require("./utils");
16
16
  const defaultTheme = ({ themePlugins = {}, ...localeOptions } = {}) => {
17
- var _a, _b, _c, _d, _e, _f;
18
17
  (0, utils_2.assignDefaultLocaleOptions)(localeOptions);
19
18
  return {
20
19
  name: '@vuepress/theme-default',
@@ -28,8 +27,7 @@ const defaultTheme = ({ themePlugins = {}, ...localeOptions } = {}) => {
28
27
  `@theme/${file}`,
29
28
  utils_1.path.resolve(__dirname, '../client/components', file),
30
29
  ])),
31
- clientAppEnhanceFiles: utils_1.path.resolve(__dirname, '../client/clientAppEnhance.js'),
32
- clientAppSetupFiles: utils_1.path.resolve(__dirname, '../client/clientAppSetup.js'),
30
+ clientConfigFile: utils_1.path.resolve(__dirname, '../client/config.js'),
33
31
  extendsPage: (page) => {
34
32
  // save relative file path into page data to generate edit link
35
33
  page.data.filePathRelative = page.filePathRelative;
@@ -49,30 +47,30 @@ const defaultTheme = ({ themePlugins = {}, ...localeOptions } = {}) => {
49
47
  // @vuepress/plugin-back-to-top
50
48
  themePlugins.backToTop !== false ? (0, plugin_back_to_top_1.backToTopPlugin)() : [],
51
49
  // @vuepress/plugin-container
52
- ((_a = themePlugins.container) === null || _a === void 0 ? void 0 : _a.tip) !== false
50
+ themePlugins.container?.tip !== false
53
51
  ? (0, plugin_container_1.containerPlugin)((0, utils_2.resolveContainerPluginOptions)(localeOptions, 'tip'))
54
52
  : [],
55
- ((_b = themePlugins.container) === null || _b === void 0 ? void 0 : _b.warning) !== false
53
+ themePlugins.container?.warning !== false
56
54
  ? (0, plugin_container_1.containerPlugin)((0, utils_2.resolveContainerPluginOptions)(localeOptions, 'warning'))
57
55
  : [],
58
- ((_c = themePlugins.container) === null || _c === void 0 ? void 0 : _c.danger) !== false
56
+ themePlugins.container?.danger !== false
59
57
  ? (0, plugin_container_1.containerPlugin)((0, utils_2.resolveContainerPluginOptions)(localeOptions, 'danger'))
60
58
  : [],
61
- ((_d = themePlugins.container) === null || _d === void 0 ? void 0 : _d.details) !== false
59
+ themePlugins.container?.details !== false
62
60
  ? (0, plugin_container_1.containerPlugin)({
63
61
  type: 'details',
64
62
  before: (info) => `<details class="custom-container details">${info ? `<summary>${info}</summary>` : ''}\n`,
65
63
  after: () => '</details>\n',
66
64
  })
67
65
  : [],
68
- ((_e = themePlugins.container) === null || _e === void 0 ? void 0 : _e.codeGroup) !== false
66
+ themePlugins.container?.codeGroup !== false
69
67
  ? (0, plugin_container_1.containerPlugin)({
70
68
  type: 'code-group',
71
69
  before: () => `<CodeGroup>\n`,
72
70
  after: () => '</CodeGroup>\n',
73
71
  })
74
72
  : [],
75
- ((_f = themePlugins.container) === null || _f === void 0 ? void 0 : _f.codeGroupItem) !== false
73
+ themePlugins.container?.codeGroupItem !== false
76
74
  ? (0, plugin_container_1.containerPlugin)({
77
75
  type: 'code-group-item',
78
76
  before: (info) => `<CodeGroupItem title="${info}">\n`,
@@ -83,9 +81,8 @@ const defaultTheme = ({ themePlugins = {}, ...localeOptions } = {}) => {
83
81
  themePlugins.externalLinkIcon !== false
84
82
  ? (0, plugin_external_link_icon_1.externalLinkIconPlugin)({
85
83
  locales: Object.entries(localeOptions.locales || {}).reduce((result, [key, value]) => {
86
- var _a;
87
84
  result[key] = {
88
- openInNewWindow: (_a = value.openInNewWindow) !== null && _a !== void 0 ? _a : localeOptions.openInNewWindow,
85
+ openInNewWindow: value.openInNewWindow ?? localeOptions.openInNewWindow,
89
86
  };
90
87
  return result;
91
88
  }, {}),
@@ -8,9 +8,8 @@ exports.resolveContainerPluginOptions = void 0;
8
8
  */
9
9
  const resolveContainerPluginOptions = (localeOptions, type) => {
10
10
  const locales = Object.entries(localeOptions.locales || {}).reduce((result, [key, value]) => {
11
- var _a;
12
11
  result[key] = {
13
- defaultInfo: (_a = value === null || value === void 0 ? void 0 : value[type]) !== null && _a !== void 0 ? _a : localeOptions[type],
12
+ defaultInfo: value?.[type] ?? localeOptions[type],
14
13
  };
15
14
  return result;
16
15
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-beta.41",
3
+ "version": "2.0.0-beta.44",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -25,24 +25,24 @@
25
25
  "templates"
26
26
  ],
27
27
  "dependencies": {
28
- "@vuepress/client": "2.0.0-beta.41",
29
- "@vuepress/core": "2.0.0-beta.41",
30
- "@vuepress/plugin-active-header-links": "2.0.0-beta.41",
31
- "@vuepress/plugin-back-to-top": "2.0.0-beta.41",
32
- "@vuepress/plugin-container": "2.0.0-beta.41",
33
- "@vuepress/plugin-external-link-icon": "2.0.0-beta.41",
34
- "@vuepress/plugin-git": "2.0.0-beta.41",
35
- "@vuepress/plugin-medium-zoom": "2.0.0-beta.41",
36
- "@vuepress/plugin-nprogress": "2.0.0-beta.41",
37
- "@vuepress/plugin-palette": "2.0.0-beta.41",
38
- "@vuepress/plugin-prismjs": "2.0.0-beta.41",
39
- "@vuepress/plugin-theme-data": "2.0.0-beta.41",
40
- "@vuepress/shared": "2.0.0-beta.41",
41
- "@vuepress/utils": "2.0.0-beta.41",
42
- "@vueuse/core": "^8.2.1",
43
- "sass": "^1.49.10",
28
+ "@vuepress/client": "2.0.0-beta.44",
29
+ "@vuepress/core": "2.0.0-beta.44",
30
+ "@vuepress/plugin-active-header-links": "2.0.0-beta.44",
31
+ "@vuepress/plugin-back-to-top": "2.0.0-beta.44",
32
+ "@vuepress/plugin-container": "2.0.0-beta.44",
33
+ "@vuepress/plugin-external-link-icon": "2.0.0-beta.44",
34
+ "@vuepress/plugin-git": "2.0.0-beta.44",
35
+ "@vuepress/plugin-medium-zoom": "2.0.0-beta.44",
36
+ "@vuepress/plugin-nprogress": "2.0.0-beta.44",
37
+ "@vuepress/plugin-palette": "2.0.0-beta.44",
38
+ "@vuepress/plugin-prismjs": "2.0.0-beta.44",
39
+ "@vuepress/plugin-theme-data": "2.0.0-beta.44",
40
+ "@vuepress/shared": "2.0.0-beta.44",
41
+ "@vuepress/utils": "2.0.0-beta.44",
42
+ "@vueuse/core": "^8.4.2",
43
+ "sass": "^1.51.0",
44
44
  "vue": "^3.2.33",
45
- "vue-router": "^4.0.14"
45
+ "vue-router": "^4.0.15"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "sass-loader": "^12.6.0"
@@ -1,3 +0,0 @@
1
- import './styles/index.scss';
2
- declare const _default: import("@vuepress/client").ClientAppEnhance;
3
- export default _default;
@@ -1,34 +0,0 @@
1
- import { defineClientAppEnhance } from '@vuepress/client';
2
- import { h } from 'vue';
3
- import Badge from './components/global/Badge.vue';
4
- import CodeGroup from './components/global/CodeGroup';
5
- import CodeGroupItem from './components/global/CodeGroupItem.vue';
6
- import { useScrollPromise } from './composables';
7
- import './styles/index.scss';
8
- export default defineClientAppEnhance(({ app, router }) => {
9
- app.component('Badge', Badge);
10
- app.component('CodeGroup', CodeGroup);
11
- app.component('CodeGroupItem', CodeGroupItem);
12
- // compat with @vuepress/plugin-external-link-icon
13
- app.component('AutoLinkExternalIcon', () => {
14
- const ExternalLinkIcon = app.component('ExternalLinkIcon');
15
- if (ExternalLinkIcon) {
16
- return h(ExternalLinkIcon);
17
- }
18
- return null;
19
- });
20
- // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
21
- app.component('NavbarSearch', () => {
22
- const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
23
- if (SearchComponent) {
24
- return h(SearchComponent);
25
- }
26
- return null;
27
- });
28
- // handle scrollBehavior with transition
29
- const scrollBehavior = router.options.scrollBehavior;
30
- router.options.scrollBehavior = async (...args) => {
31
- await useScrollPromise().wait();
32
- return scrollBehavior(...args);
33
- };
34
- });
@@ -1,2 +0,0 @@
1
- declare const _default: import("@vuepress/client").ClientAppSetup;
2
- export default _default;
@@ -1,6 +0,0 @@
1
- import { defineClientAppSetup } from '@vuepress/client';
2
- import { setupDarkMode, setupSidebarItems } from './composables';
3
- export default defineClientAppSetup(() => {
4
- setupDarkMode();
5
- setupSidebarItems();
6
- });