vitepress 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/client/app/data.js +13 -3
  2. package/dist/client/app/router.js +16 -13
  3. package/dist/client/index.d.ts +4 -0
  4. package/dist/client/theme-default/components/VPLocalNavOutlineDropdown.vue +1 -1
  5. package/dist/client/theme-default/composables/langs.js +2 -3
  6. package/dist/client/theme-default/composables/sidebar.js +2 -3
  7. package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
  8. package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
  9. package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
  10. package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
  11. package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
  12. package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
  13. package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
  14. package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
  15. package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
  16. package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
  17. package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
  18. package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
  19. package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
  20. package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
  21. package/dist/client/theme-default/styles/fonts.css +64 -72
  22. package/dist/client/theme-default/styles/vars.css +7 -6
  23. package/dist/node/cli.js +1 -1
  24. package/dist/node/index.d.ts +311 -317
  25. package/dist/node/index.js +2 -2
  26. package/dist/node/{serve-CEVH7KNu.js → serve-BOsNJwDZ.js} +194 -91
  27. package/package.json +63 -63
  28. package/types/default-theme.d.ts +2 -2
  29. package/dist/client/theme-default/composables/hash.js +0 -9
@@ -1,7 +1,7 @@
1
1
  import siteData from '@siteData';
2
2
  import { useDark } from '@vueuse/core';
3
- import { computed, inject, readonly, ref, shallowRef } from 'vue';
4
- import { APPEARANCE_KEY, createTitle, resolveSiteDataByRoute } from '../shared';
3
+ import { computed, inject, readonly, ref, shallowRef, watch } from 'vue';
4
+ import { APPEARANCE_KEY, createTitle, inBrowser, resolveSiteDataByRoute } from '../shared';
5
5
  export const dataSymbol = Symbol();
6
6
  // site data is a singleton
7
7
  export const siteDataRef = shallowRef((import.meta.env.PROD ? siteData : readonly(siteData)));
@@ -26,6 +26,15 @@ export function initData(route) {
26
26
  ...(typeof appearance === 'object' ? appearance : {})
27
27
  })
28
28
  : ref(false);
29
+ const hashRef = ref(inBrowser ? location.hash : '');
30
+ if (inBrowser) {
31
+ window.addEventListener('hashchange', () => {
32
+ hashRef.value = location.hash;
33
+ });
34
+ }
35
+ watch(() => route.data, () => {
36
+ hashRef.value = inBrowser ? location.hash : '';
37
+ });
29
38
  return {
30
39
  site,
31
40
  theme: computed(() => site.value.themeConfig),
@@ -37,7 +46,8 @@ export function initData(route) {
37
46
  localeIndex: computed(() => site.value.localeIndex || 'root'),
38
47
  title: computed(() => createTitle(site.value, route.data)),
39
48
  description: computed(() => route.data.description || site.value.description),
40
- isDark
49
+ isDark,
50
+ hash: computed(() => hashRef.value)
41
51
  };
42
52
  }
43
53
  export function useData() {
@@ -21,16 +21,10 @@ export function createRouter(loadPageModule, fallbackComponent) {
21
21
  href = normalizeHref(href);
22
22
  if ((await router.onBeforeRouteChange?.(href)) === false)
23
23
  return;
24
- if (inBrowser) {
25
- const currentUrl = new URL(location.href);
26
- if (href !== normalizeHref(currentUrl.href)) {
27
- // save scroll position before changing url
28
- history.replaceState({ scrollPosition: window.scrollY }, document.title);
29
- history.pushState(null, '', href);
30
- if (new URL(href, fakeHost).hash !== currentUrl.hash) {
31
- window.dispatchEvent(new Event('hashchange'));
32
- }
33
- }
24
+ if (inBrowser && href !== normalizeHref(location.href)) {
25
+ // save scroll position before changing url
26
+ history.replaceState({ scrollPosition: window.scrollY }, '');
27
+ history.pushState({}, '', href);
34
28
  }
35
29
  await loadPage(href);
36
30
  await router.onAfterRouteChanged?.(href);
@@ -67,7 +61,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
67
61
  if (actualPathname !== targetLoc.pathname) {
68
62
  targetLoc.pathname = actualPathname;
69
63
  href = actualPathname + targetLoc.search + targetLoc.hash;
70
- history.replaceState(null, '', href);
64
+ history.replaceState({}, '', href);
71
65
  }
72
66
  if (targetLoc.hash && !scrollPosition) {
73
67
  let target = null;
@@ -113,6 +107,9 @@ export function createRouter(loadPageModule, fallbackComponent) {
113
107
  }
114
108
  }
115
109
  if (inBrowser) {
110
+ if (history.state === null) {
111
+ history.replaceState({}, '');
112
+ }
116
113
  window.addEventListener('click', (e) => {
117
114
  // temporary fix for docsearch action buttons
118
115
  const button = e.target.closest('button');
@@ -141,9 +138,12 @@ export function createRouter(loadPageModule, fallbackComponent) {
141
138
  // scroll between hash anchors in the same page
142
139
  // avoid duplicate history entries when the hash is same
143
140
  if (hash !== currentUrl.hash) {
144
- history.pushState(null, '', href);
141
+ history.pushState({}, '', href);
145
142
  // still emit the event so we can listen to it in themes
146
- window.dispatchEvent(new Event('hashchange'));
143
+ window.dispatchEvent(new HashChangeEvent('hashchange', {
144
+ oldURL: currentUrl.href,
145
+ newURL: href
146
+ }));
147
147
  }
148
148
  if (hash) {
149
149
  // use smooth scroll when clicking on header anchor links
@@ -160,6 +160,9 @@ export function createRouter(loadPageModule, fallbackComponent) {
160
160
  }
161
161
  }, { capture: true });
162
162
  window.addEventListener('popstate', async (e) => {
163
+ if (e.state === null) {
164
+ return;
165
+ }
163
166
  await loadPage(normalizeHref(location.href), (e.state && e.state.scrollPosition) || 0);
164
167
  router.onAfterRouteChanged?.(location.href);
165
168
  });
@@ -64,6 +64,10 @@ interface VitePressData<T = any> {
64
64
  dir: Ref<string>;
65
65
  localeIndex: Ref<string>;
66
66
  isDark: Ref<boolean>;
67
+ /**
68
+ * Current location hash
69
+ */
70
+ hash: Ref<string>;
67
71
  }
68
72
  declare function useData<T = any>(): VitePressData<T>;
69
73
 
@@ -59,7 +59,7 @@ function scrollToTop() {
59
59
  ref="main"
60
60
  >
61
61
  <button @click="toggle" :class="{ open }" v-if="headers.length > 0">
62
- {{ resolveTitle(theme) }}
62
+ <span class="menu-text">{{ resolveTitle(theme) }}</span>
63
63
  <span class="vpi-chevron-right icon" />
64
64
  </button>
65
65
  <button @click="scrollToTop" v-else>
@@ -1,9 +1,8 @@
1
1
  import { computed } from 'vue';
2
2
  import { ensureStartingSlash } from '../support/utils';
3
3
  import { useData } from './data';
4
- import { hashRef } from './hash';
5
4
  export function useLangs({ removeCurrent = true, correspondingLink = false } = {}) {
6
- const { site, localeIndex, page, theme } = useData();
5
+ const { site, localeIndex, page, theme, hash } = useData();
7
6
  const currentLang = computed(() => ({
8
7
  label: site.value.locales[localeIndex.value]?.label,
9
8
  link: site.value.locales[localeIndex.value]?.link ||
@@ -13,7 +12,7 @@ export function useLangs({ removeCurrent = true, correspondingLink = false } = {
13
12
  ? []
14
13
  : {
15
14
  text: value.label,
16
- link: normalizeLink(value.link || (key === 'root' ? '/' : `/${key}/`), theme.value.i18nRouting !== false && correspondingLink, page.value.relativePath.slice(currentLang.value.link.length - 1), !site.value.cleanUrls) + hashRef.value
15
+ link: normalizeLink(value.link || (key === 'root' ? '/' : `/${key}/`), theme.value.i18nRouting !== false && correspondingLink, page.value.relativePath.slice(currentLang.value.link.length - 1), !site.value.cleanUrls) + hash.value
17
16
  }));
18
17
  return { localeLinks, currentLang };
19
18
  }
@@ -3,7 +3,6 @@ import { computed, onMounted, onUnmounted, ref, watch, watchEffect, watchPostEff
3
3
  import { isActive } from '../../shared';
4
4
  import { hasActiveLink as containsActiveLink, getSidebar, getSidebarGroups } from '../support/sidebar';
5
5
  import { useData } from './data';
6
- import { hashRef } from './hash';
7
6
  export function useSidebar() {
8
7
  const { frontmatter, page, theme } = useData();
9
8
  const is960 = useMediaQuery('(min-width: 960px)');
@@ -88,7 +87,7 @@ export function useCloseSidebarOnEscape(isOpen, close) {
88
87
  }
89
88
  }
90
89
  export function useSidebarControl(item) {
91
- const { page } = useData();
90
+ const { page, hash } = useData();
92
91
  const collapsed = ref(false);
93
92
  const collapsible = computed(() => {
94
93
  return item.value.collapsed != null;
@@ -100,7 +99,7 @@ export function useSidebarControl(item) {
100
99
  const updateIsActiveLink = () => {
101
100
  isActiveLink.value = isActive(page.value.relativePath, item.value.link);
102
101
  };
103
- watch([page, item, hashRef], updateIsActiveLink);
102
+ watch([page, item, hash], updateIsActiveLink);
104
103
  onMounted(updateIsActiveLink);
105
104
  const hasActiveLink = computed(() => {
106
105
  if (isActiveLink.value) {
@@ -7,153 +7,143 @@ html body {
7
7
  /* webfont-marker-end */
8
8
 
9
9
  @font-face {
10
- font-family: 'Inter var';
11
- font-weight: 100 900;
12
- font-display: swap;
10
+ font-family: Inter;
13
11
  font-style: normal;
14
- font-named-instance: 'Regular';
15
- src: url('../fonts/inter-roman-cyrillic.woff2') format('woff2');
16
- unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
17
- }
18
-
19
- @font-face {
20
- font-family: 'Inter var';
21
12
  font-weight: 100 900;
22
13
  font-display: swap;
23
- font-style: normal;
24
- font-named-instance: 'Regular';
25
14
  src: url('../fonts/inter-roman-cyrillic-ext.woff2') format('woff2');
26
15
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F,
27
16
  U+FE2E-FE2F;
28
17
  }
29
18
 
30
19
  @font-face {
31
- font-family: 'Inter var';
20
+ font-family: Inter;
21
+ font-style: normal;
32
22
  font-weight: 100 900;
33
23
  font-display: swap;
34
- font-style: normal;
35
- font-named-instance: 'Regular';
36
- src: url('../fonts/inter-roman-greek.woff2') format('woff2');
37
- unicode-range: U+0370-03FF;
24
+ src: url('../fonts/inter-roman-cyrillic.woff2') format('woff2');
25
+ unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
38
26
  }
39
27
 
40
28
  @font-face {
41
- font-family: 'Inter var';
29
+ font-family: Inter;
30
+ font-style: normal;
42
31
  font-weight: 100 900;
43
32
  font-display: swap;
44
- font-style: normal;
45
- font-named-instance: 'Regular';
46
33
  src: url('../fonts/inter-roman-greek-ext.woff2') format('woff2');
47
34
  unicode-range: U+1F00-1FFF;
48
35
  }
49
36
 
50
37
  @font-face {
51
- font-family: 'Inter var';
38
+ font-family: Inter;
39
+ font-style: normal;
52
40
  font-weight: 100 900;
53
41
  font-display: swap;
54
- font-style: normal;
55
- font-named-instance: 'Regular';
56
- src: url('../fonts/inter-roman-latin.woff2') format('woff2');
57
- unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
58
- U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
59
- U+FEFF, U+FFFD;
42
+ src: url('../fonts/inter-roman-greek.woff2') format('woff2');
43
+ unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1,
44
+ U+03A3-03FF;
60
45
  }
61
46
 
62
47
  @font-face {
63
- font-family: 'Inter var';
48
+ font-family: Inter;
49
+ font-style: normal;
64
50
  font-weight: 100 900;
65
51
  font-display: swap;
66
- font-style: normal;
67
- font-named-instance: 'Regular';
68
- src: url('../fonts/inter-roman-latin-ext.woff2') format('woff2');
69
- unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
70
- U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
52
+ src: url('../fonts/inter-roman-vietnamese.woff2') format('woff2');
53
+ unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
54
+ U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329,
55
+ U+1EA0-1EF9, U+20AB;
71
56
  }
72
57
 
73
58
  @font-face {
74
- font-family: 'Inter var';
59
+ font-family: Inter;
60
+ font-style: normal;
75
61
  font-weight: 100 900;
76
62
  font-display: swap;
77
- font-style: normal;
78
- font-named-instance: 'Regular';
79
- src: url('../fonts/inter-roman-vietnamese.woff2') format('woff2');
80
- unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
81
- U+01AF-01B0, U+1EA0-1EF9, U+20AB;
63
+ src: url('../fonts/inter-roman-latin-ext.woff2') format('woff2');
64
+ unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
65
+ U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
82
66
  }
83
67
 
84
68
  @font-face {
85
- font-family: 'Inter var';
69
+ font-family: Inter;
70
+ font-style: normal;
86
71
  font-weight: 100 900;
87
72
  font-display: swap;
88
- font-style: italic;
89
- font-named-instance: 'Italic';
90
- src: url('../fonts/inter-italic-cyrillic.woff2') format('woff2');
91
- unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
73
+ src: url('../fonts/inter-roman-latin.woff2') format('woff2');
74
+ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
75
+ U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
76
+ U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
92
77
  }
93
78
 
94
79
  @font-face {
95
- font-family: 'Inter var';
80
+ font-family: Inter;
81
+ font-style: italic;
96
82
  font-weight: 100 900;
97
83
  font-display: swap;
98
- font-style: italic;
99
- font-named-instance: 'Italic';
100
84
  src: url('../fonts/inter-italic-cyrillic-ext.woff2') format('woff2');
101
85
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F,
102
86
  U+FE2E-FE2F;
103
87
  }
104
88
 
105
89
  @font-face {
106
- font-family: 'Inter var';
90
+ font-family: Inter;
91
+ font-style: italic;
107
92
  font-weight: 100 900;
108
93
  font-display: swap;
109
- font-style: italic;
110
- font-named-instance: 'Italic';
111
- src: url('../fonts/inter-italic-greek.woff2') format('woff2');
112
- unicode-range: U+0370-03FF;
94
+ src: url('../fonts/inter-italic-cyrillic.woff2') format('woff2');
95
+ unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
113
96
  }
114
97
 
115
98
  @font-face {
116
- font-family: 'Inter var';
99
+ font-family: Inter;
100
+ font-style: italic;
117
101
  font-weight: 100 900;
118
102
  font-display: swap;
119
- font-style: italic;
120
- font-named-instance: 'Italic';
121
103
  src: url('../fonts/inter-italic-greek-ext.woff2') format('woff2');
122
104
  unicode-range: U+1F00-1FFF;
123
105
  }
124
106
 
125
107
  @font-face {
126
- font-family: 'Inter var';
108
+ font-family: Inter;
109
+ font-style: italic;
127
110
  font-weight: 100 900;
128
111
  font-display: swap;
129
- font-style: italic;
130
- font-named-instance: 'Italic';
131
- src: url('../fonts/inter-italic-latin.woff2') format('woff2');
132
- unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
133
- U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
134
- U+FEFF, U+FFFD;
112
+ src: url('../fonts/inter-italic-greek.woff2') format('woff2');
113
+ unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1,
114
+ U+03A3-03FF;
135
115
  }
136
116
 
137
117
  @font-face {
138
- font-family: 'Inter var';
118
+ font-family: Inter;
119
+ font-style: italic;
139
120
  font-weight: 100 900;
140
121
  font-display: swap;
122
+ src: url('../fonts/inter-italic-vietnamese.woff2') format('woff2');
123
+ unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
124
+ U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329,
125
+ U+1EA0-1EF9, U+20AB;
126
+ }
127
+
128
+ @font-face {
129
+ font-family: Inter;
141
130
  font-style: italic;
142
- font-named-instance: 'Italic';
131
+ font-weight: 100 900;
132
+ font-display: swap;
143
133
  src: url('../fonts/inter-italic-latin-ext.woff2') format('woff2');
144
- unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
145
- U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
134
+ unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
135
+ U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
146
136
  }
147
137
 
148
138
  @font-face {
149
- font-family: 'Inter var';
139
+ font-family: Inter;
140
+ font-style: italic;
150
141
  font-weight: 100 900;
151
142
  font-display: swap;
152
- font-style: italic;
153
- font-named-instance: 'Italic';
154
- src: url('../fonts/inter-italic-vietnamese.woff2') format('woff2');
155
- unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
156
- U+01AF-01B0, U+1EA0-1EF9, U+20AB;
143
+ src: url('../fonts/inter-italic-latin.woff2') format('woff2');
144
+ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
145
+ U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
146
+ U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
157
147
  }
158
148
 
159
149
  /* Chinese quotes rendering fix. 中英文弯引号共享 Unicode 码位,确保引号使用中文字体渲染 */
@@ -163,3 +153,5 @@ html body {
163
153
  local('Source Han Sans SC');
164
154
  unicode-range: U+2018, U+2019, U+201C, U+201D; /* 分别是 ‘’“” */
165
155
  }
156
+
157
+ /* Generate the subsetted fonts using: `pyftsubset <file>.woff2 --unicodes="<range>" --output-file="inter-<style>-<subset>.woff2" --flavor=woff2` */
@@ -261,12 +261,13 @@
261
261
  * -------------------------------------------------------------------------- */
262
262
 
263
263
  :root {
264
- --vp-font-family-base: 'Chinese Quotes', 'Inter var', 'Inter', ui-sans-serif,
265
- system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
266
- 'Helvetica Neue', Helvetica, Arial, 'Noto Sans', sans-serif,
267
- 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
268
- --vp-font-family-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco,
269
- Consolas, 'Liberation Mono', 'Courier New', monospace;
264
+ --vp-font-family-base: 'Chinese Quotes', Inter, ui-sans-serif, system-ui,
265
+ sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
266
+ 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
267
+ 'Noto Color Emoji';
268
+ --vp-font-family-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
269
+ 'Liberation Mono', 'Courier New', monospace;
270
+ font-optical-sizing: auto;
270
271
  }
271
272
 
272
273
  /**
package/dist/node/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as getDefaultExportFromCjs, q as c, t as clearCache, n as init, b as build, o as serve, v as version, p as createServer } from './serve-CEVH7KNu.js';
1
+ import { a as getDefaultExportFromCjs, q as c, t as clearCache, n as init, b as build, o as serve, v as version, p as createServer } from './serve-BOsNJwDZ.js';
2
2
  import { createLogger } from 'vite';
3
3
  import 'path';
4
4
  import 'url';