vitepress 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (122) hide show
  1. package/client.d.ts +2 -0
  2. package/dist/client/app/components/ClientOnly.js +10 -10
  3. package/dist/client/app/components/Content.js +17 -11
  4. package/dist/client/app/composables/copyCode.js +68 -0
  5. package/dist/client/app/composables/head.js +51 -85
  6. package/dist/client/app/composables/preFetch.js +94 -94
  7. package/dist/client/app/data.js +44 -45
  8. package/dist/client/app/devtools.js +28 -28
  9. package/dist/client/app/index.js +97 -90
  10. package/dist/client/app/router.js +207 -202
  11. package/dist/client/app/ssr.js +8 -0
  12. package/dist/client/app/theme.js +1 -1
  13. package/dist/client/app/utils.js +47 -46
  14. package/dist/client/index.d.ts +42 -107
  15. package/dist/client/index.js +9 -9
  16. package/dist/client/shared.js +109 -95
  17. package/dist/client/theme-default/Layout.vue +21 -4
  18. package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +18 -51
  19. package/dist/client/theme-default/components/VPButton.vue +5 -4
  20. package/dist/client/theme-default/components/VPCarbonAds.vue +1 -1
  21. package/dist/client/theme-default/components/VPContent.vue +4 -4
  22. package/dist/client/theme-default/components/VPDoc.vue +19 -33
  23. package/dist/client/theme-default/components/VPDocAside.vue +2 -2
  24. package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +1 -1
  25. package/dist/client/theme-default/components/VPDocAsideOutline.vue +23 -55
  26. package/dist/client/theme-default/components/VPDocAsideOutlineItem.vue +51 -0
  27. package/dist/client/theme-default/components/VPDocAsideSponsors.vue +3 -18
  28. package/dist/client/theme-default/components/VPDocFooter.vue +15 -9
  29. package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +4 -4
  30. package/dist/client/theme-default/components/VPFlyout.vue +10 -2
  31. package/dist/client/theme-default/components/VPFooter.vue +3 -3
  32. package/dist/client/theme-default/components/VPHero.vue +11 -12
  33. package/dist/client/theme-default/components/VPImage.vue +39 -0
  34. package/dist/client/theme-default/components/VPLink.vue +4 -3
  35. package/dist/client/theme-default/components/VPLocalNav.vue +1 -1
  36. package/dist/client/theme-default/components/VPMenu.vue +8 -0
  37. package/dist/client/theme-default/components/VPMenuLink.vue +1 -1
  38. package/dist/client/theme-default/components/VPNav.vue +13 -4
  39. package/dist/client/theme-default/components/VPNavBar.vue +13 -3
  40. package/dist/client/theme-default/components/VPNavBarExtra.vue +4 -1
  41. package/dist/client/theme-default/components/VPNavBarHamburger.vue +10 -10
  42. package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +17 -2
  43. package/dist/client/theme-default/components/VPNavBarMenuLink.vue +2 -2
  44. package/dist/client/theme-default/components/VPNavBarSearch.vue +23 -6
  45. package/dist/client/theme-default/components/VPNavBarTitle.vue +6 -3
  46. package/dist/client/theme-default/components/VPNavScreen.vue +3 -0
  47. package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +1 -1
  48. package/dist/client/theme-default/components/VPSidebar.vue +2 -3
  49. package/dist/client/theme-default/components/VPSidebarGroup.vue +19 -3
  50. package/dist/client/theme-default/components/VPSidebarLink.vue +27 -10
  51. package/dist/client/theme-default/components/VPSkipLink.vue +3 -3
  52. package/dist/client/theme-default/components/VPSocialLink.vue +13 -27
  53. package/dist/client/theme-default/components/VPSocialLinks.vue +1 -1
  54. package/dist/client/theme-default/components/VPSponsors.vue +9 -15
  55. package/dist/client/theme-default/components/VPSponsorsGrid.vue +24 -6
  56. package/dist/client/theme-default/components/VPSwitchAppearance.vue +28 -1
  57. package/dist/client/theme-default/components/VPTeamMembers.vue +55 -0
  58. package/dist/client/theme-default/components/VPTeamMembersItem.vue +215 -0
  59. package/dist/client/theme-default/components/VPTeamPage.vue +53 -0
  60. package/dist/client/theme-default/components/VPTeamPageSection.vue +77 -0
  61. package/dist/client/theme-default/components/VPTeamPageTitle.vue +63 -0
  62. package/dist/client/theme-default/composables/aside.js +17 -17
  63. package/dist/client/theme-default/composables/edit-link.js +11 -11
  64. package/dist/client/theme-default/composables/flyout.js +40 -40
  65. package/dist/client/theme-default/composables/nav.js +53 -51
  66. package/dist/client/theme-default/composables/outline.js +141 -122
  67. package/dist/client/theme-default/composables/prev-next.js +22 -18
  68. package/dist/client/theme-default/composables/sidebar.js +63 -57
  69. package/dist/client/theme-default/composables/sponsor-grid.js +94 -94
  70. package/dist/client/theme-default/fonts/inter-cyrillic-ext.woff2 +0 -0
  71. package/dist/client/theme-default/fonts/inter-cyrillic.woff2 +0 -0
  72. package/dist/client/theme-default/fonts/inter-greek-ext.woff2 +0 -0
  73. package/dist/client/theme-default/fonts/inter-greek.woff2 +0 -0
  74. package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
  75. package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
  76. package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
  77. package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
  78. package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
  79. package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
  80. package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
  81. package/dist/client/theme-default/fonts/inter-latin-ext.woff2 +0 -0
  82. package/dist/client/theme-default/fonts/inter-latin.woff2 +0 -0
  83. package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
  84. package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
  85. package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
  86. package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
  87. package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
  88. package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
  89. package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
  90. package/dist/client/theme-default/fonts/inter-vietnamese.woff2 +0 -0
  91. package/dist/client/theme-default/index.js +23 -19
  92. package/dist/client/theme-default/styles/base.css +15 -6
  93. package/dist/client/theme-default/styles/components/vp-doc.css +46 -64
  94. package/dist/client/theme-default/styles/components/vp-sponsor.css +40 -15
  95. package/dist/client/theme-default/styles/fonts.css +185 -35
  96. package/dist/client/theme-default/styles/lib-override/nprogress.css +12 -0
  97. package/dist/client/theme-default/styles/vars.css +11 -9
  98. package/dist/client/theme-default/support/sidebar.js +37 -29
  99. package/dist/client/theme-default/support/socialIcons.js +11 -0
  100. package/dist/client/theme-default/support/utils.js +63 -62
  101. package/dist/node/cli.js +26 -15
  102. package/dist/node/index.d.ts +1755 -268
  103. package/dist/node/index.js +5 -5
  104. package/dist/node/{serve-42a92e2f.js → serve-585d953a.js} +37119 -45149
  105. package/dist/node-cjs/cli.cjs +26 -15
  106. package/dist/node-cjs/index.cjs +5 -5
  107. package/dist/node-cjs/{serve-507b373b.cjs → serve-8687ced9.cjs} +37127 -45157
  108. package/package.json +81 -58
  109. package/theme.d.ts +10 -5
  110. package/types/default-theme.d.ts +60 -5
  111. package/types/index.d.ts +3 -2
  112. package/types/shared.d.ts +31 -1
  113. package/dist/client/theme-default/components/icons/VPIconDiscord.vue +0 -5
  114. package/dist/client/theme-default/components/icons/VPIconFacebook.vue +0 -5
  115. package/dist/client/theme-default/components/icons/VPIconGitHub.vue +0 -5
  116. package/dist/client/theme-default/components/icons/VPIconInstagram.vue +0 -5
  117. package/dist/client/theme-default/components/icons/VPIconLinkedIn.vue +0 -5
  118. package/dist/client/theme-default/components/icons/VPIconSlack.vue +0 -5
  119. package/dist/client/theme-default/components/icons/VPIconTwitter.vue +0 -5
  120. package/dist/client/theme-default/components/icons/VPIconYouTube.vue +0 -5
  121. package/dist/client/theme-default/composables/copy-code.js +0 -33
  122. package/dist/client/theme-default/config.js +0 -1
package/client.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  // re-export vite client types. with strict installers like pnpm, user won't
2
2
  // be able to reference vite/client in project root.
3
3
  /// <reference types="vite/client" />
4
+
5
+ export * from './dist/client/index.js'
@@ -1,10 +1,10 @@
1
- import { defineComponent, ref, onMounted } from 'vue';
2
- export const ClientOnly = defineComponent({
3
- setup(_, { slots }) {
4
- const show = ref(false);
5
- onMounted(() => {
6
- show.value = true;
7
- });
8
- return () => (show.value && slots.default ? slots.default() : null);
9
- }
10
- });
1
+ import { defineComponent, ref, onMounted } from 'vue';
2
+ export const ClientOnly = defineComponent({
3
+ setup(_, { slots }) {
4
+ const show = ref(false);
5
+ onMounted(() => {
6
+ show.value = true;
7
+ });
8
+ return () => (show.value && slots.default ? slots.default() : null);
9
+ }
10
+ });
@@ -1,11 +1,17 @@
1
- import { defineComponent, h } from 'vue';
2
- import { useRoute } from '../router';
3
- export const Content = defineComponent({
4
- name: 'VitePressContent',
5
- setup() {
6
- const route = useRoute();
7
- return () => h('div', { style: { position: 'relative' } }, [
8
- route.component ? h(route.component) : null
9
- ]);
10
- }
11
- });
1
+ import { defineComponent, h, onUpdated } from 'vue';
2
+ import { useRoute } from '../router.js';
3
+ export const Content = defineComponent({
4
+ name: 'VitePressContent',
5
+ props: {
6
+ onContentUpdated: Function
7
+ },
8
+ setup(props) {
9
+ const route = useRoute();
10
+ onUpdated(() => {
11
+ props.onContentUpdated?.();
12
+ });
13
+ return () => h('div', { style: { position: 'relative' } }, [
14
+ route.component ? h(route.component) : null
15
+ ]);
16
+ }
17
+ });
@@ -0,0 +1,68 @@
1
+ import { inBrowser } from '../utils.js';
2
+ export function useCopyCode() {
3
+ if (inBrowser) {
4
+ const timeoutIdMap = new Map();
5
+ window.addEventListener('click', (e) => {
6
+ const el = e.target;
7
+ if (el.matches('div[class*="language-"] > button.copy')) {
8
+ const parent = el.parentElement;
9
+ const sibling = el.nextElementSibling
10
+ ?.nextElementSibling;
11
+ if (!parent || !sibling) {
12
+ return;
13
+ }
14
+ const isShell = /language-(shellscript|shell|bash|sh|zsh)/.test(parent.classList.toString());
15
+ let { innerText: text = '' } = sibling;
16
+ if (isShell) {
17
+ text = text.replace(/^ *(\$|>) /gm, '');
18
+ }
19
+ copyToClipboard(text).then(() => {
20
+ el.classList.add('copied');
21
+ clearTimeout(timeoutIdMap.get(el));
22
+ const timeoutId = setTimeout(() => {
23
+ el.classList.remove('copied');
24
+ el.blur();
25
+ timeoutIdMap.delete(el);
26
+ }, 2000);
27
+ timeoutIdMap.set(el, timeoutId);
28
+ });
29
+ }
30
+ });
31
+ }
32
+ }
33
+ async function copyToClipboard(text) {
34
+ try {
35
+ return navigator.clipboard.writeText(text);
36
+ }
37
+ catch {
38
+ const element = document.createElement('textarea');
39
+ const previouslyFocusedElement = document.activeElement;
40
+ element.value = text;
41
+ // Prevent keyboard from showing on mobile
42
+ element.setAttribute('readonly', '');
43
+ element.style.contain = 'strict';
44
+ element.style.position = 'absolute';
45
+ element.style.left = '-9999px';
46
+ element.style.fontSize = '12pt'; // Prevent zooming on iOS
47
+ const selection = document.getSelection();
48
+ const originalRange = selection
49
+ ? selection.rangeCount > 0 && selection.getRangeAt(0)
50
+ : null;
51
+ document.body.appendChild(element);
52
+ element.select();
53
+ // Explicit selection workaround for iOS
54
+ element.selectionStart = 0;
55
+ element.selectionEnd = text.length;
56
+ document.execCommand('copy');
57
+ document.body.removeChild(element);
58
+ if (originalRange) {
59
+ selection.removeAllRanges(); // originalRange can't be truthy when selection is falsy
60
+ selection.addRange(originalRange);
61
+ }
62
+ // Get the focus back on the previously focused element, if any
63
+ if (previouslyFocusedElement) {
64
+ ;
65
+ previouslyFocusedElement.focus();
66
+ }
67
+ }
68
+ }
@@ -1,85 +1,51 @@
1
- import { watchEffect } from 'vue';
2
- import { createTitle } from '../../shared';
3
- export function useUpdateHead(route, siteDataByRouteRef) {
4
- let managedHeadTags = [];
5
- let isFirstUpdate = true;
6
- const updateHeadTags = (newTags) => {
7
- if (import.meta.env.PROD && isFirstUpdate) {
8
- // in production, the initial meta tags are already pre-rendered so we
9
- // skip the first update.
10
- isFirstUpdate = false;
11
- return;
12
- }
13
- const newEls = [];
14
- const commonLength = Math.min(managedHeadTags.length, newTags.length);
15
- for (let i = 0; i < commonLength; i++) {
16
- let el = managedHeadTags[i];
17
- const [tag, attrs, innerHTML = ''] = newTags[i];
18
- if (el.tagName.toLocaleLowerCase() === tag) {
19
- for (const key in attrs) {
20
- if (el.getAttribute(key) !== attrs[key]) {
21
- el.setAttribute(key, attrs[key]);
22
- }
23
- }
24
- for (let i = 0; i < el.attributes.length; i++) {
25
- const name = el.attributes[i].name;
26
- if (!(name in attrs)) {
27
- el.removeAttribute(name);
28
- }
29
- }
30
- if (el.innerHTML !== innerHTML) {
31
- el.innerHTML = innerHTML;
32
- }
33
- }
34
- else {
35
- document.head.removeChild(el);
36
- el = createHeadElement(newTags[i]);
37
- document.head.append(el);
38
- }
39
- newEls.push(el);
40
- }
41
- managedHeadTags
42
- .slice(commonLength)
43
- .forEach((el) => document.head.removeChild(el));
44
- newTags.slice(commonLength).forEach((headConfig) => {
45
- const el = createHeadElement(headConfig);
46
- document.head.appendChild(el);
47
- newEls.push(el);
48
- });
49
- managedHeadTags = newEls;
50
- };
51
- watchEffect(() => {
52
- const pageData = route.data;
53
- const siteData = siteDataByRouteRef.value;
54
- const pageDescription = pageData && pageData.description;
55
- const frontmatterHead = pageData && pageData.frontmatter.head;
56
- // update title and description
57
- document.title = createTitle(siteData, pageData);
58
- document
59
- .querySelector(`meta[name=description]`)
60
- .setAttribute('content', pageDescription || siteData.description);
61
- updateHeadTags([
62
- // site head can only change during dev
63
- ...(import.meta.env.DEV ? siteData.head : []),
64
- ...(frontmatterHead ? filterOutHeadDescription(frontmatterHead) : [])
65
- ]);
66
- });
67
- }
68
- function createHeadElement([tag, attrs, innerHTML]) {
69
- const el = document.createElement(tag);
70
- for (const key in attrs) {
71
- el.setAttribute(key, attrs[key]);
72
- }
73
- if (innerHTML) {
74
- el.innerHTML = innerHTML;
75
- }
76
- return el;
77
- }
78
- function isMetaDescription(headConfig) {
79
- return (headConfig[0] === 'meta' &&
80
- headConfig[1] &&
81
- headConfig[1].name === 'description');
82
- }
83
- function filterOutHeadDescription(head) {
84
- return head.filter((h) => !isMetaDescription(h));
85
- }
1
+ import { watchEffect } from 'vue';
2
+ import { createTitle, mergeHead } from '../../shared.js';
3
+ export function useUpdateHead(route, siteDataByRouteRef) {
4
+ let managedHeadTags = [];
5
+ let isFirstUpdate = true;
6
+ const updateHeadTags = (newTags) => {
7
+ if (import.meta.env.PROD && isFirstUpdate) {
8
+ // in production, the initial meta tags are already pre-rendered so we
9
+ // skip the first update.
10
+ isFirstUpdate = false;
11
+ return;
12
+ }
13
+ managedHeadTags.forEach((el) => document.head.removeChild(el));
14
+ managedHeadTags = [];
15
+ newTags.forEach((headConfig) => {
16
+ const el = createHeadElement(headConfig);
17
+ document.head.appendChild(el);
18
+ managedHeadTags.push(el);
19
+ });
20
+ };
21
+ watchEffect(() => {
22
+ const pageData = route.data;
23
+ const siteData = siteDataByRouteRef.value;
24
+ const pageDescription = pageData && pageData.description;
25
+ const frontmatterHead = (pageData && pageData.frontmatter.head) || [];
26
+ // update title and description
27
+ document.title = createTitle(siteData, pageData);
28
+ document
29
+ .querySelector(`meta[name=description]`)
30
+ .setAttribute('content', pageDescription || siteData.description);
31
+ updateHeadTags(mergeHead(siteData.head, filterOutHeadDescription(frontmatterHead)));
32
+ });
33
+ }
34
+ function createHeadElement([tag, attrs, innerHTML]) {
35
+ const el = document.createElement(tag);
36
+ for (const key in attrs) {
37
+ el.setAttribute(key, attrs[key]);
38
+ }
39
+ if (innerHTML) {
40
+ el.innerHTML = innerHTML;
41
+ }
42
+ return el;
43
+ }
44
+ function isMetaDescription(headConfig) {
45
+ return (headConfig[0] === 'meta' &&
46
+ headConfig[1] &&
47
+ headConfig[1].name === 'description');
48
+ }
49
+ function filterOutHeadDescription(head) {
50
+ return head.filter((h) => !isMetaDescription(h));
51
+ }
@@ -1,94 +1,94 @@
1
- // Customized pre-fetch for page chunks based on
2
- // https://github.com/GoogleChromeLabs/quicklink
3
- import { useRoute } from '../router';
4
- import { onMounted, onUnmounted, watch } from 'vue';
5
- import { inBrowser, pathToFile } from '../utils';
6
- const hasFetched = new Set();
7
- const createLink = () => document.createElement('link');
8
- const viaDOM = (url) => {
9
- const link = createLink();
10
- link.rel = `prefetch`;
11
- link.href = url;
12
- document.head.appendChild(link);
13
- };
14
- const viaXHR = (url) => {
15
- const req = new XMLHttpRequest();
16
- req.open('GET', url, (req.withCredentials = true));
17
- req.send();
18
- };
19
- let link;
20
- const doFetch = inBrowser &&
21
- (link = createLink()) &&
22
- link.relList &&
23
- link.relList.supports &&
24
- link.relList.supports('prefetch')
25
- ? viaDOM
26
- : viaXHR;
27
- export function usePrefetch() {
28
- if (!inBrowser) {
29
- return;
30
- }
31
- if (!window.IntersectionObserver) {
32
- return;
33
- }
34
- let conn;
35
- if ((conn = navigator.connection) &&
36
- (conn.saveData || /2g/.test(conn.effectiveType))) {
37
- // Don't prefetch if using 2G or if Save-Data is enabled.
38
- return;
39
- }
40
- const rIC = window.requestIdleCallback || setTimeout;
41
- let observer = null;
42
- const observeLinks = () => {
43
- if (observer) {
44
- observer.disconnect();
45
- }
46
- observer = new IntersectionObserver((entries) => {
47
- entries.forEach((entry) => {
48
- if (entry.isIntersecting) {
49
- const link = entry.target;
50
- observer.unobserve(link);
51
- const { pathname } = link;
52
- if (!hasFetched.has(pathname)) {
53
- hasFetched.add(pathname);
54
- const pageChunkPath = pathToFile(pathname);
55
- doFetch(pageChunkPath);
56
- }
57
- }
58
- });
59
- });
60
- rIC(() => {
61
- document.querySelectorAll('#app a').forEach((link) => {
62
- const { target, hostname, pathname } = link;
63
- const extMatch = pathname.match(/\.\w+$/);
64
- if (extMatch && extMatch[0] !== '.html') {
65
- return;
66
- }
67
- if (
68
- // only prefetch same tab navigation, since a new tab will load
69
- // the lean js chunk instead.
70
- target !== `_blank` &&
71
- // only prefetch inbound links
72
- hostname === location.hostname) {
73
- if (pathname !== location.pathname) {
74
- observer.observe(link);
75
- }
76
- else {
77
- // No need to prefetch chunk for the current page, but also mark
78
- // it as already fetched. This is because the initial page uses its
79
- // lean chunk, and if we don't mark it, navigation to another page
80
- // with a link back to the first page will fetch its full chunk
81
- // which isn't needed.
82
- hasFetched.add(pathname);
83
- }
84
- }
85
- });
86
- });
87
- };
88
- onMounted(observeLinks);
89
- const route = useRoute();
90
- watch(() => route.path, observeLinks);
91
- onUnmounted(() => {
92
- observer && observer.disconnect();
93
- });
94
- }
1
+ // Customized pre-fetch for page chunks based on
2
+ // https://github.com/GoogleChromeLabs/quicklink
3
+ import { useRoute } from '../router.js';
4
+ import { onMounted, onUnmounted, watch } from 'vue';
5
+ import { inBrowser, pathToFile } from '../utils.js';
6
+ const hasFetched = new Set();
7
+ const createLink = () => document.createElement('link');
8
+ const viaDOM = (url) => {
9
+ const link = createLink();
10
+ link.rel = `prefetch`;
11
+ link.href = url;
12
+ document.head.appendChild(link);
13
+ };
14
+ const viaXHR = (url) => {
15
+ const req = new XMLHttpRequest();
16
+ req.open('GET', url, (req.withCredentials = true));
17
+ req.send();
18
+ };
19
+ let link;
20
+ const doFetch = inBrowser &&
21
+ (link = createLink()) &&
22
+ link.relList &&
23
+ link.relList.supports &&
24
+ link.relList.supports('prefetch')
25
+ ? viaDOM
26
+ : viaXHR;
27
+ export function usePrefetch() {
28
+ if (!inBrowser) {
29
+ return;
30
+ }
31
+ if (!window.IntersectionObserver) {
32
+ return;
33
+ }
34
+ let conn;
35
+ if ((conn = navigator.connection) &&
36
+ (conn.saveData || /2g/.test(conn.effectiveType))) {
37
+ // Don't prefetch if using 2G or if Save-Data is enabled.
38
+ return;
39
+ }
40
+ const rIC = window.requestIdleCallback || setTimeout;
41
+ let observer = null;
42
+ const observeLinks = () => {
43
+ if (observer) {
44
+ observer.disconnect();
45
+ }
46
+ observer = new IntersectionObserver((entries) => {
47
+ entries.forEach((entry) => {
48
+ if (entry.isIntersecting) {
49
+ const link = entry.target;
50
+ observer.unobserve(link);
51
+ const { pathname } = link;
52
+ if (!hasFetched.has(pathname)) {
53
+ hasFetched.add(pathname);
54
+ const pageChunkPath = pathToFile(pathname);
55
+ doFetch(pageChunkPath);
56
+ }
57
+ }
58
+ });
59
+ });
60
+ rIC(() => {
61
+ document.querySelectorAll('#app a').forEach((link) => {
62
+ const { target, hostname, pathname } = link;
63
+ const extMatch = pathname.match(/\.\w+$/);
64
+ if (extMatch && extMatch[0] !== '.html') {
65
+ return;
66
+ }
67
+ if (
68
+ // only prefetch same tab navigation, since a new tab will load
69
+ // the lean js chunk instead.
70
+ target !== `_blank` &&
71
+ // only prefetch inbound links
72
+ hostname === location.hostname) {
73
+ if (pathname !== location.pathname) {
74
+ observer.observe(link);
75
+ }
76
+ else {
77
+ // No need to prefetch chunk for the current page, but also mark
78
+ // it as already fetched. This is because the initial page uses its
79
+ // lean chunk, and if we don't mark it, navigation to another page
80
+ // with a link back to the first page will fetch its full chunk
81
+ // which isn't needed.
82
+ hasFetched.add(pathname);
83
+ }
84
+ }
85
+ });
86
+ });
87
+ };
88
+ onMounted(observeLinks);
89
+ const route = useRoute();
90
+ watch(() => route.path, observeLinks);
91
+ onUnmounted(() => {
92
+ observer && observer.disconnect();
93
+ });
94
+ }
@@ -1,45 +1,44 @@
1
- import { shallowRef, readonly, computed, inject } from 'vue';
2
- import serializedSiteData from '@siteData';
3
- import { resolveSiteDataByRoute, createTitle } from '../shared';
4
- import { withBase } from './utils';
5
- export const dataSymbol = Symbol();
6
- export const siteDataRef = shallowRef(parse(serializedSiteData));
7
- function parse(data) {
8
- const parsed = JSON.parse(data);
9
- return (import.meta.env.DEV ? readonly(parsed) : parsed);
10
- }
11
- // hmr
12
- if (import.meta.hot) {
13
- import.meta.hot.accept('/@siteData', (m) => {
14
- siteDataRef.value = parse(m.default);
15
- });
16
- }
17
- // per-app data
18
- export function initData(route) {
19
- const site = computed(() => resolveSiteDataByRoute(siteDataRef.value, route.path));
20
- return {
21
- site,
22
- theme: computed(() => site.value.themeConfig),
23
- page: computed(() => route.data),
24
- frontmatter: computed(() => route.data.frontmatter),
25
- lang: computed(() => site.value.lang),
26
- localePath: computed(() => {
27
- const { langs, lang } = site.value;
28
- const path = Object.keys(langs).find((langPath) => langs[langPath].lang === lang);
29
- return withBase(path || '/');
30
- }),
31
- title: computed(() => {
32
- return createTitle(site.value, route.data);
33
- }),
34
- description: computed(() => {
35
- return route.data.description || site.value.description;
36
- })
37
- };
38
- }
39
- export function useData() {
40
- const data = inject(dataSymbol);
41
- if (!data) {
42
- throw new Error('vitepress data not properly injected in app');
43
- }
44
- return data;
45
- }
1
+ import { shallowRef, readonly, computed, inject } from 'vue';
2
+ import siteData from '@siteData';
3
+ import { resolveSiteDataByRoute, createTitle } from '../shared.js';
4
+ import { withBase } from './utils.js';
5
+ export const dataSymbol = Symbol();
6
+ // site data is a singleton
7
+ export const siteDataRef = shallowRef((import.meta.env.PROD ? siteData : readonly(siteData)));
8
+ // hmr
9
+ if (import.meta.hot) {
10
+ import.meta.hot.accept('/@siteData', (m) => {
11
+ if (m) {
12
+ siteDataRef.value = m.default;
13
+ }
14
+ });
15
+ }
16
+ // per-app data
17
+ export function initData(route) {
18
+ const site = computed(() => resolveSiteDataByRoute(siteDataRef.value, route.path));
19
+ return {
20
+ site,
21
+ theme: computed(() => site.value.themeConfig),
22
+ page: computed(() => route.data),
23
+ frontmatter: computed(() => route.data.frontmatter),
24
+ lang: computed(() => site.value.lang),
25
+ localePath: computed(() => {
26
+ const { langs, lang } = site.value;
27
+ const path = Object.keys(langs).find((langPath) => langs[langPath].lang === lang);
28
+ return withBase(path || '/');
29
+ }),
30
+ title: computed(() => {
31
+ return createTitle(site.value, route.data);
32
+ }),
33
+ description: computed(() => {
34
+ return route.data.description || site.value.description;
35
+ })
36
+ };
37
+ }
38
+ export function useData() {
39
+ const data = inject(dataSymbol);
40
+ if (!data) {
41
+ throw new Error('vitepress data not properly injected in app');
42
+ }
43
+ return data;
44
+ }
@@ -1,28 +1,28 @@
1
- import { setupDevtoolsPlugin } from '@vue/devtools-api';
2
- const COMPONENT_STATE_TYPE = 'VitePress';
3
- export const setupDevtools = (app, router, data) => {
4
- setupDevtoolsPlugin({
5
- // fix recursive reference
6
- app: app,
7
- id: 'org.vuejs.vitepress',
8
- label: 'VitePress',
9
- packageName: 'vitepress',
10
- homepage: 'https://vitepress.vuejs.org',
11
- componentStateTypes: [COMPONENT_STATE_TYPE]
12
- }, (api) => {
13
- api.on.inspectComponent((payload) => {
14
- payload.instanceData.state.push({
15
- type: COMPONENT_STATE_TYPE,
16
- key: 'route',
17
- value: router.route,
18
- editable: false
19
- });
20
- payload.instanceData.state.push({
21
- type: COMPONENT_STATE_TYPE,
22
- key: 'data',
23
- value: data,
24
- editable: false
25
- });
26
- });
27
- });
28
- };
1
+ import { setupDevtoolsPlugin } from '@vue/devtools-api';
2
+ const COMPONENT_STATE_TYPE = 'VitePress';
3
+ export const setupDevtools = (app, router, data) => {
4
+ setupDevtoolsPlugin({
5
+ // fix recursive reference
6
+ app: app,
7
+ id: 'org.vuejs.vitepress',
8
+ label: 'VitePress',
9
+ packageName: 'vitepress',
10
+ homepage: 'https://vitepress.vuejs.org',
11
+ componentStateTypes: [COMPONENT_STATE_TYPE]
12
+ }, (api) => {
13
+ api.on.inspectComponent((payload) => {
14
+ payload.instanceData.state.push({
15
+ type: COMPONENT_STATE_TYPE,
16
+ key: 'route',
17
+ value: router.route,
18
+ editable: false
19
+ });
20
+ payload.instanceData.state.push({
21
+ type: COMPONENT_STATE_TYPE,
22
+ key: 'data',
23
+ value: data,
24
+ editable: false
25
+ });
26
+ });
27
+ });
28
+ };