vitepress 1.3.4 → 1.4.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.
@@ -1,4 +1,4 @@
1
- import { defineComponent, h } from 'vue';
1
+ import { defineComponent, h, watch } from 'vue';
2
2
  import { useData, useRoute } from 'vitepress';
3
3
  import { contentUpdatedCallbacks } from '../utils';
4
4
  const runCbs = () => contentUpdatedCallbacks.forEach((fn) => fn());
@@ -9,7 +9,8 @@ export const Content = defineComponent({
9
9
  },
10
10
  setup(props) {
11
11
  const route = useRoute();
12
- const { site } = useData();
12
+ const { frontmatter, site } = useData();
13
+ watch(frontmatter, runCbs, { deep: true, flush: 'post' });
13
14
  return () => h(props.as, site.value.contentProps ?? { style: { position: 'relative' } }, [
14
15
  route.component
15
16
  ? h(route.component, {
@@ -64,7 +64,7 @@ function createHeadElement([tag, attrs, innerHTML]) {
64
64
  if (innerHTML) {
65
65
  el.innerHTML = innerHTML;
66
66
  }
67
- if (tag === 'script' && !attrs.async) {
67
+ if (tag === 'script' && attrs.async == null) {
68
68
  // async is true by default for dynamically created scripts
69
69
  ;
70
70
  el.async = false;
@@ -1,5 +1,5 @@
1
1
  import siteData from '@siteData';
2
- import { useDark } from '@vueuse/core';
2
+ import { useDark, usePreferredDark } from '@vueuse/core';
3
3
  import { computed, inject, readonly, ref, shallowRef, watch } from 'vue';
4
4
  import { APPEARANCE_KEY, createTitle, inBrowser, resolveSiteDataByRoute } from '../shared';
5
5
  export const dataSymbol = Symbol();
@@ -19,13 +19,15 @@ export function initData(route) {
19
19
  const appearance = site.value.appearance; // fine with reactivity being lost here, config change triggers a restart
20
20
  const isDark = appearance === 'force-dark'
21
21
  ? ref(true)
22
- : appearance
23
- ? useDark({
24
- storageKey: APPEARANCE_KEY,
25
- initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'),
26
- ...(typeof appearance === 'object' ? appearance : {})
27
- })
28
- : ref(false);
22
+ : appearance === 'force-auto'
23
+ ? usePreferredDark()
24
+ : appearance
25
+ ? useDark({
26
+ storageKey: APPEARANCE_KEY,
27
+ initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'),
28
+ ...(typeof appearance === 'object' ? appearance : {})
29
+ })
30
+ : ref(false);
29
31
  const hashRef = ref(inBrowser ? location.hash : '');
30
32
  if (inBrowser) {
31
33
  window.addEventListener('hashchange', () => {
@@ -46,6 +46,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
46
46
  if (!comp) {
47
47
  throw new Error(`Invalid route component: ${comp}`);
48
48
  }
49
+ await router.onAfterPageLoad?.(href);
49
50
  route.path = inBrowser ? pendingPath : withBase(pendingPath);
50
51
  route.component = markRaw(comp);
51
52
  route.data = import.meta.env.PROD
@@ -32,6 +32,10 @@ interface Router {
32
32
  * updated). Return `false` to cancel the navigation.
33
33
  */
34
34
  onBeforePageLoad?: (to: string) => Awaitable<void | boolean>;
35
+ /**
36
+ * Called after the page component is loaded (before the page component is updated).
37
+ */
38
+ onAfterPageLoad?: (to: string) => Awaitable<void>;
35
39
  /**
36
40
  * Called after the route changes.
37
41
  */
@@ -110,20 +114,20 @@ declare function defineClientComponent(loader: AsyncComponentLoader, args?: any[
110
114
  };
111
115
  declare function getScrollOffset(): number;
112
116
 
113
- declare const Content: vue.DefineComponent<{
117
+ declare const Content: vue.DefineComponent<vue.ExtractPropTypes<{
114
118
  as: {
115
119
  type: (ObjectConstructor | StringConstructor)[];
116
120
  default: string;
117
121
  };
118
- }, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
122
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
119
123
  [key: string]: any;
120
- }>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
124
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
121
125
  as: {
122
126
  type: (ObjectConstructor | StringConstructor)[];
123
127
  default: string;
124
128
  };
125
- }>>, {
129
+ }>> & Readonly<{}>, {
126
130
  as: string | Record<string, any>;
127
- }, {}>;
131
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
128
132
 
129
133
  export { Content, type EnhanceAppContext, type Route, type Router, type Theme, type VitePressData, escapeHtml as _escapeHtml, dataSymbol, defineClientComponent, getScrollOffset, inBrowser, onContentUpdated, useData, useRoute, useRouter, withBase };
@@ -22,7 +22,7 @@ const isExternal = computed(
22
22
  )
23
23
 
24
24
  const component = computed(() => {
25
- return props.tag || props.href ? 'a' : 'button'
25
+ return props.tag || (props.href ? 'a' : 'button')
26
26
  })
27
27
  </script>
28
28
 
@@ -78,6 +78,12 @@ function onBlur() {
78
78
  color: var(--vp-c-brand-2);
79
79
  }
80
80
 
81
+ .button[aria-expanded="false"] + .menu {
82
+ opacity: 0;
83
+ visibility: hidden;
84
+ transform: translateY(0);
85
+ }
86
+
81
87
  .VPFlyout:hover .menu,
82
88
  .button[aria-expanded="true"] + .menu {
83
89
  opacity: 1;
@@ -85,12 +91,6 @@ function onBlur() {
85
91
  transform: translateY(0);
86
92
  }
87
93
 
88
- .button[aria-expanded="false"] + .menu {
89
- opacity: 0;
90
- visibility: hidden;
91
- transform: translateY(0);
92
- }
93
-
94
94
  .button {
95
95
  display: flex;
96
96
  align-items: center;
@@ -440,10 +440,20 @@ function formMarkRegex(terms: Set<string>) {
440
440
  <input
441
441
  ref="searchInput"
442
442
  v-model="filterText"
443
- :placeholder="buttonText"
444
- id="localsearch-input"
443
+ :aria-activedescendant="selectedIndex > -1 ? ('localsearch-item-' + selectedIndex) : undefined"
444
+ aria-autocomplete="both"
445
+ :aria-controls="results?.length ? 'localsearch-list' : undefined"
445
446
  aria-labelledby="localsearch-label"
447
+ autocapitalize="off"
448
+ autocomplete="off"
449
+ autocorrect="off"
446
450
  class="search-input"
451
+ id="localsearch-input"
452
+ enterkeyhint="go"
453
+ maxlength="64"
454
+ :placeholder="buttonText"
455
+ spellcheck="false"
456
+ type="search"
447
457
  />
448
458
  <div class="search-actions">
449
459
  <button
@@ -482,8 +492,9 @@ function formMarkRegex(terms: Set<string>) {
482
492
  <li
483
493
  v-for="(p, index) in results"
484
494
  :key="p.id"
485
- role="option"
495
+ :id="'localsearch-item-' + index"
486
496
  :aria-selected="selectedIndex === index ? 'true' : 'false'"
497
+ role="option"
487
498
  >
488
499
  <a
489
500
  :href="p.id"
@@ -14,12 +14,19 @@ const { page } = useData()
14
14
  <template>
15
15
  <div class="VPMenuLink">
16
16
  <VPLink
17
- :class="{ active: isActive(page.relativePath, item.activeMatch || item.link, !!item.activeMatch) }"
17
+ :class="{
18
+ active: isActive(
19
+ page.relativePath,
20
+ item.activeMatch || item.link,
21
+ !!item.activeMatch
22
+ )
23
+ }"
18
24
  :href="item.link"
19
25
  :target="item.target"
20
26
  :rel="item.rel"
27
+ :no-icon="item.noIcon"
21
28
  >
22
- {{ item.text }}
29
+ <span v-html="item.text"></span>
23
30
  </VPLink>
24
31
  </div>
25
32
  </template>
@@ -40,7 +47,9 @@ const { page } = useData()
40
47
  font-weight: 500;
41
48
  color: var(--vp-c-text-1);
42
49
  white-space: nowrap;
43
- transition: background-color 0.25s, color 0.25s;
50
+ transition:
51
+ background-color 0.25s,
52
+ color 0.25s;
44
53
  }
45
54
 
46
55
  .link:hover {
@@ -22,9 +22,9 @@ const { page } = useData()
22
22
  )
23
23
  }"
24
24
  :href="item.link"
25
- :noIcon="item.noIcon"
26
25
  :target="item.target"
27
26
  :rel="item.rel"
27
+ :no-icon="item.noIcon"
28
28
  tabindex="0"
29
29
  >
30
30
  <span v-html="item.text"></span>
@@ -16,9 +16,10 @@ const closeScreen = inject('close-screen') as () => void
16
16
  :href="item.link"
17
17
  :target="item.target"
18
18
  :rel="item.rel"
19
+ :no-icon="item.noIcon"
19
20
  @click="closeScreen"
20
21
  >
21
- {{ item.text }}
22
+ <span v-html="item.text"></span>
22
23
  </VPLink>
23
24
  </template>
24
25
 
@@ -16,9 +16,11 @@ const closeScreen = inject('close-screen') as () => void
16
16
  :href="item.link"
17
17
  :target="item.target"
18
18
  :rel="item.rel"
19
+ :no-icon="item.noIcon"
19
20
  @click="closeScreen"
20
- v-html="item.text"
21
- />
21
+ >
22
+ <span v-html="item.text"></span>
23
+ </VPLink>
22
24
  </template>
23
25
 
24
26
  <style scoped>
@@ -30,7 +32,9 @@ const closeScreen = inject('close-screen') as () => void
30
32
  font-size: 14px;
31
33
  font-weight: 500;
32
34
  color: var(--vp-c-text-1);
33
- transition: border-color 0.25s, color 0.25s;
35
+ transition:
36
+ border-color 0.25s,
37
+ color 0.25s;
34
38
  }
35
39
 
36
40
  .VPNavScreenMenuLink:hover {
@@ -56,32 +56,7 @@ export function resolveHeaders(headers, range) {
56
56
  : levelsRange === 'deep'
57
57
  ? [2, 6]
58
58
  : levelsRange;
59
- headers = headers.filter((h) => h.level >= high && h.level <= low);
60
- // clear previous caches
61
- resolvedHeaders.length = 0;
62
- // update global header list for active link rendering
63
- for (const { element, link } of headers) {
64
- resolvedHeaders.push({ element, link });
65
- }
66
- const ret = [];
67
- outer: for (let i = 0; i < headers.length; i++) {
68
- const cur = headers[i];
69
- if (i === 0) {
70
- ret.push(cur);
71
- }
72
- else {
73
- for (let j = i - 1; j >= 0; j--) {
74
- const prev = headers[j];
75
- if (prev.level < cur.level) {
76
- ;
77
- (prev.children || (prev.children = [])).push(cur);
78
- continue outer;
79
- }
80
- }
81
- ret.push(cur);
82
- }
83
- }
84
- return ret;
59
+ return buildTree(headers, high, low);
85
60
  }
86
61
  export function useActiveAnchor(container, marker) {
87
62
  const { isAsideEnabled } = useAside();
@@ -176,3 +151,30 @@ function getAbsoluteTop(element) {
176
151
  }
177
152
  return offsetTop;
178
153
  }
154
+ function buildTree(data, min, max) {
155
+ resolvedHeaders.length = 0;
156
+ const result = [];
157
+ const stack = [];
158
+ data.forEach((item) => {
159
+ const node = { ...item, children: [] };
160
+ let parent = stack[stack.length - 1];
161
+ while (parent && parent.level >= node.level) {
162
+ stack.pop();
163
+ parent = stack[stack.length - 1];
164
+ }
165
+ if (node.element.classList.contains('ignore-header') ||
166
+ (parent && 'shouldIgnore' in parent)) {
167
+ stack.push({ level: node.level, shouldIgnore: true });
168
+ return;
169
+ }
170
+ if (node.level > max || node.level < min)
171
+ return;
172
+ resolvedHeaders.push({ element: node.element, link: node.link });
173
+ if (parent)
174
+ parent.children.push(node);
175
+ else
176
+ result.push(node);
177
+ stack.push(node);
178
+ });
179
+ return result;
180
+ }
@@ -1,9 +1,5 @@
1
1
  /* webfont-marker-begin */
2
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
3
-
4
- html body {
5
- font-synthesis: style;
6
- }
2
+ @import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
7
3
  /* webfont-marker-end */
8
4
 
9
5
  @font-face {
@@ -16,7 +16,10 @@ export { default as VPHomeContent } from './components/VPHomeContent.vue';
16
16
  export { default as VPHomeHero } from './components/VPHomeHero.vue';
17
17
  export { default as VPHomeFeatures } from './components/VPHomeFeatures.vue';
18
18
  export { default as VPHomeSponsors } from './components/VPHomeSponsors.vue';
19
+ export { default as VPLink } from './components/VPLink.vue';
19
20
  export { default as VPDocAsideSponsors } from './components/VPDocAsideSponsors.vue';
21
+ export { default as VPSocialLink } from './components/VPSocialLink.vue';
22
+ export { default as VPSocialLinks } from './components/VPSocialLinks.vue';
20
23
  export { default as VPSponsors } from './components/VPSponsors.vue';
21
24
  export { default as VPTeamPage } from './components/VPTeamPage.vue';
22
25
  export { default as VPTeamPageTitle } from './components/VPTeamPageTitle.vue';