vitepress 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (286) hide show
  1. package/README.md +34 -2
  2. package/THIRD-PARTY-NOTICES.md +1736 -0
  3. package/bin/vitepress.js +14 -0
  4. package/client.d.ts +9 -0
  5. package/dist/client/app/components/ClientOnly.d.ts +5 -0
  6. package/dist/client/app/components/ClientOnly.js +11 -10
  7. package/dist/client/app/components/Content.d.ts +17 -0
  8. package/dist/client/app/components/Content.js +25 -22
  9. package/dist/client/app/composables/codeGroups.d.ts +3 -0
  10. package/dist/client/app/composables/codeGroups.js +36 -39
  11. package/dist/client/app/composables/copyCode.d.ts +3 -0
  12. package/dist/client/app/composables/copyCode.js +59 -70
  13. package/dist/client/app/composables/head.d.ts +5 -0
  14. package/dist/client/app/composables/head.js +56 -74
  15. package/dist/client/app/composables/icon.d.ts +12 -0
  16. package/dist/client/app/composables/icon.js +56 -0
  17. package/dist/client/app/composables/preFetch.d.ts +3 -0
  18. package/dist/client/app/composables/preFetch.js +64 -96
  19. package/dist/client/app/data.d.ts +9 -0
  20. package/dist/client/app/data.js +34 -59
  21. package/dist/client/app/devtools.d.ts +7 -0
  22. package/dist/client/app/devtools.js +29 -28
  23. package/dist/client/app/index.d.ts +11 -0
  24. package/dist/client/app/index.js +106 -131
  25. package/dist/client/app/router.d.ts +49 -0
  26. package/dist/client/app/router.js +198 -239
  27. package/dist/client/app/ssr.d.ts +4 -0
  28. package/dist/client/app/ssr.js +14 -9
  29. package/dist/client/app/theme.d.ts +24 -0
  30. package/dist/client/app/theme.js +0 -1
  31. package/dist/client/app/utils.d.ts +35 -0
  32. package/dist/client/app/utils.js +77 -110
  33. package/dist/client/index.d.ts +21 -137
  34. package/dist/client/index.js +8 -9
  35. package/dist/client/shared.d.ts +88 -0
  36. package/dist/client/shared.js +265 -141
  37. package/dist/client/theme-default/Layout.d.vue.ts +79 -0
  38. package/dist/client/theme-default/Layout.vue +33 -36
  39. package/dist/client/theme-default/NotFound.d.vue.ts +3 -0
  40. package/dist/client/theme-default/NotFound.vue +33 -35
  41. package/dist/client/theme-default/components/VPAlgoliaSearchBox.d.vue.ts +11 -0
  42. package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +202 -70
  43. package/dist/client/theme-default/components/VPBackdrop.d.vue.ts +6 -0
  44. package/dist/client/theme-default/components/VPBackdrop.vue +8 -12
  45. package/dist/client/theme-default/components/VPBadge.d.vue.ts +19 -0
  46. package/dist/client/theme-default/components/VPBadge.vue +49 -26
  47. package/dist/client/theme-default/components/VPButton.d.vue.ts +25 -0
  48. package/dist/client/theme-default/components/VPButton.vue +53 -36
  49. package/dist/client/theme-default/components/VPCarbonAds.d.vue.ts +7 -0
  50. package/dist/client/theme-default/components/VPCarbonAds.vue +51 -52
  51. package/dist/client/theme-default/components/VPContent.d.vue.ts +59 -0
  52. package/dist/client/theme-default/components/VPContent.vue +27 -26
  53. package/dist/client/theme-default/components/VPDoc.d.vue.ts +33 -0
  54. package/dist/client/theme-default/components/VPDoc.vue +52 -48
  55. package/dist/client/theme-default/components/VPDocAside.d.vue.ts +23 -0
  56. package/dist/client/theme-default/components/VPDocAside.vue +7 -8
  57. package/dist/client/theme-default/components/VPDocAsideCarbonAds.d.vue.ts +7 -0
  58. package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +7 -11
  59. package/dist/client/theme-default/components/VPDocAsideOutline.d.vue.ts +3 -0
  60. package/dist/client/theme-default/components/VPDocAsideOutline.vue +22 -38
  61. package/dist/client/theme-default/components/VPDocAsideSponsors.d.vue.ts +10 -0
  62. package/dist/client/theme-default/components/VPDocAsideSponsors.vue +17 -11
  63. package/dist/client/theme-default/components/VPDocFooter.d.vue.ts +13 -0
  64. package/dist/client/theme-default/components/VPDocFooter.vue +38 -45
  65. package/dist/client/theme-default/components/VPDocFooterLastUpdated.d.vue.ts +3 -0
  66. package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +30 -29
  67. package/dist/client/theme-default/components/VPDocOutlineItem.d.vue.ts +8 -0
  68. package/dist/client/theme-default/components/VPDocOutlineItem.vue +20 -19
  69. package/dist/client/theme-default/components/VPFeature.d.vue.ts +13 -0
  70. package/dist/client/theme-default/components/VPFeature.vue +62 -36
  71. package/dist/client/theme-default/components/VPFeatures.d.vue.ts +16 -0
  72. package/dist/client/theme-default/components/VPFeatures.vue +35 -48
  73. package/dist/client/theme-default/components/VPFlyout.d.vue.ts +26 -0
  74. package/dist/client/theme-default/components/VPFlyout.vue +111 -47
  75. package/dist/client/theme-default/components/VPFooter.d.vue.ts +3 -0
  76. package/dist/client/theme-default/components/VPFooter.vue +22 -15
  77. package/dist/client/theme-default/components/VPHero.d.vue.ts +38 -0
  78. package/dist/client/theme-default/components/VPHero.vue +109 -99
  79. package/dist/client/theme-default/components/VPHome.d.vue.ts +31 -0
  80. package/dist/client/theme-default/components/VPHome.vue +15 -15
  81. package/dist/client/theme-default/components/VPHomeContent.d.vue.ts +13 -0
  82. package/dist/client/theme-default/components/VPHomeContent.vue +9 -27
  83. package/dist/client/theme-default/components/VPHomeFeatures.d.vue.ts +3 -0
  84. package/dist/client/theme-default/components/VPHomeFeatures.vue +4 -5
  85. package/dist/client/theme-default/components/VPHomeHero.d.vue.ts +23 -0
  86. package/dist/client/theme-default/components/VPHomeHero.vue +5 -5
  87. package/dist/client/theme-default/components/VPHomeSponsors.d.vue.ts +21 -0
  88. package/dist/client/theme-default/components/VPHomeSponsors.vue +42 -43
  89. package/dist/client/theme-default/components/VPIcon.d.vue.ts +8 -0
  90. package/dist/client/theme-default/components/VPIcon.vue +29 -0
  91. package/dist/client/theme-default/components/VPImage.d.vue.ts +8 -0
  92. package/dist/client/theme-default/components/VPImage.vue +20 -14
  93. package/dist/client/theme-default/components/VPLink.d.vue.ts +23 -0
  94. package/dist/client/theme-default/components/VPLink.vue +42 -23
  95. package/dist/client/theme-default/components/VPLocalNav.d.vue.ts +10 -0
  96. package/dist/client/theme-default/components/VPLocalNav.vue +69 -86
  97. package/dist/client/theme-default/components/VPLocalNavOutlineDropdown.d.vue.ts +8 -0
  98. package/dist/client/theme-default/components/VPLocalNavOutlineDropdown.vue +98 -96
  99. package/dist/client/theme-default/components/VPLocalSearchBox.d.vue.ts +7 -0
  100. package/dist/client/theme-default/components/VPLocalSearchBox.vue +391 -454
  101. package/dist/client/theme-default/components/VPMenu.d.vue.ts +23 -0
  102. package/dist/client/theme-default/components/VPMenu.vue +19 -31
  103. package/dist/client/theme-default/components/VPMenuGroup.d.vue.ts +22 -0
  104. package/dist/client/theme-default/components/VPMenuGroup.vue +72 -18
  105. package/dist/client/theme-default/components/VPMenuLink.d.vue.ts +22 -0
  106. package/dist/client/theme-default/components/VPMenuLink.vue +65 -31
  107. package/dist/client/theme-default/components/VPNav.d.vue.ts +23 -0
  108. package/dist/client/theme-default/components/VPNav.vue +18 -24
  109. package/dist/client/theme-default/components/VPNavAppearance.d.vue.ts +9 -0
  110. package/dist/client/theme-default/components/VPNavAppearance.vue +88 -0
  111. package/dist/client/theme-default/components/VPNavBar.d.vue.ts +26 -0
  112. package/dist/client/theme-default/components/VPNavBar.vue +170 -142
  113. package/dist/client/theme-default/components/VPNavBarAskAiButton.d.vue.ts +3 -0
  114. package/dist/client/theme-default/components/VPNavBarAskAiButton.vue +31 -0
  115. package/dist/client/theme-default/components/VPNavBarExtra.d.vue.ts +3 -0
  116. package/dist/client/theme-default/components/VPNavBarExtra.vue +51 -73
  117. package/dist/client/theme-default/components/VPNavBarHamburger.d.vue.ts +10 -0
  118. package/dist/client/theme-default/components/VPNavBarHamburger.vue +38 -28
  119. package/dist/client/theme-default/components/VPNavBarSearch.d.vue.ts +3 -0
  120. package/dist/client/theme-default/components/VPNavBarSearch.vue +129 -160
  121. package/dist/client/theme-default/components/VPNavBarSearchButton.d.vue.ts +6 -0
  122. package/dist/client/theme-default/components/VPNavBarSearchButton.vue +48 -182
  123. package/dist/client/theme-default/components/VPNavBarTitle.d.vue.ts +15 -0
  124. package/dist/client/theme-default/components/VPNavBarTitle.vue +39 -38
  125. package/dist/client/theme-default/components/VPNavMenu.d.vue.ts +6 -0
  126. package/dist/client/theme-default/components/VPNavMenu.vue +76 -0
  127. package/dist/client/theme-default/components/VPNavMenuGroup.d.vue.ts +11 -0
  128. package/dist/client/theme-default/components/VPNavMenuGroup.vue +140 -0
  129. package/dist/client/theme-default/components/VPNavMenuLink.d.vue.ts +8 -0
  130. package/dist/client/theme-default/components/VPNavMenuLink.vue +69 -0
  131. package/dist/client/theme-default/components/VPNavScreen.d.vue.ts +18 -0
  132. package/dist/client/theme-default/components/VPNavScreen.vue +36 -34
  133. package/dist/client/theme-default/components/VPNavSocialLinks.d.vue.ts +6 -0
  134. package/dist/client/theme-default/components/VPNavSocialLinks.vue +36 -0
  135. package/dist/client/theme-default/components/VPNavTranslations.d.vue.ts +9 -0
  136. package/dist/client/theme-default/components/VPNavTranslations.vue +170 -0
  137. package/dist/client/theme-default/components/VPPage.d.vue.ts +15 -0
  138. package/dist/client/theme-default/components/VPSidebar.d.vue.ts +18 -0
  139. package/dist/client/theme-default/components/VPSidebar.vue +40 -53
  140. package/dist/client/theme-default/components/VPSidebarGroup.d.vue.ts +7 -0
  141. package/dist/client/theme-default/components/VPSidebarGroup.vue +24 -29
  142. package/dist/client/theme-default/components/VPSidebarItem.d.vue.ts +8 -0
  143. package/dist/client/theme-default/components/VPSidebarItem.vue +60 -93
  144. package/dist/client/theme-default/components/VPSkipLink.d.vue.ts +6 -0
  145. package/dist/client/theme-default/components/VPSkipLink.vue +23 -42
  146. package/dist/client/theme-default/components/VPSocialLink.d.vue.ts +11 -0
  147. package/dist/client/theme-default/components/VPSocialLink.vue +42 -49
  148. package/dist/client/theme-default/components/VPSocialLinks.d.vue.ts +10 -0
  149. package/dist/client/theme-default/components/VPSocialLinks.vue +26 -16
  150. package/dist/client/theme-default/components/VPSponsors.d.vue.ts +18 -0
  151. package/dist/client/theme-default/components/VPSponsors.vue +34 -33
  152. package/dist/client/theme-default/components/VPSponsorsGrid.d.vue.ts +15 -0
  153. package/dist/client/theme-default/components/VPSponsorsGrid.vue +23 -26
  154. package/dist/client/theme-default/components/VPSwitch.d.vue.ts +13 -0
  155. package/dist/client/theme-default/components/VPSwitch.vue +12 -13
  156. package/dist/client/theme-default/components/VPSwitchAppearance.d.vue.ts +3 -0
  157. package/dist/client/theme-default/components/VPSwitchAppearance.vue +16 -21
  158. package/dist/client/theme-default/components/VPTeamMembers.d.vue.ts +10 -0
  159. package/dist/client/theme-default/components/VPTeamMembers.vue +59 -32
  160. package/dist/client/theme-default/components/VPTeamMembersItem.d.vue.ts +10 -0
  161. package/dist/client/theme-default/components/VPTeamMembersItem.vue +62 -58
  162. package/dist/client/theme-default/components/VPTeamPage.d.vue.ts +13 -0
  163. package/dist/client/theme-default/components/VPTeamPage.vue +14 -14
  164. package/dist/client/theme-default/components/VPTeamPageSection.d.vue.ts +17 -0
  165. package/dist/client/theme-default/components/VPTeamPageSection.vue +20 -19
  166. package/dist/client/theme-default/components/VPTeamPageTitle.d.vue.ts +15 -0
  167. package/dist/client/theme-default/components/VPTeamPageTitle.vue +22 -22
  168. package/dist/client/theme-default/composables/data.d.ts +5 -0
  169. package/dist/client/theme-default/composables/data.js +5 -2
  170. package/dist/client/theme-default/composables/edit-link.d.ts +6 -0
  171. package/dist/client/theme-default/composables/edit-link.js +17 -15
  172. package/dist/client/theme-default/composables/flyout.d.ts +10 -0
  173. package/dist/client/theme-default/composables/flyout.js +33 -32
  174. package/dist/client/theme-default/composables/langs.d.ts +44 -0
  175. package/dist/client/theme-default/composables/langs.js +48 -24
  176. package/dist/client/theme-default/composables/layout.d.ts +13 -0
  177. package/dist/client/theme-default/composables/layout.js +68 -0
  178. package/dist/client/theme-default/composables/nav-overflow.d.ts +54 -0
  179. package/dist/client/theme-default/composables/nav-overflow.js +179 -0
  180. package/dist/client/theme-default/composables/nav.d.ts +25 -0
  181. package/dist/client/theme-default/composables/nav.js +58 -29
  182. package/dist/client/theme-default/composables/outline.d.ts +8 -0
  183. package/dist/client/theme-default/composables/outline.js +144 -166
  184. package/dist/client/theme-default/composables/prev-next.d.ts +16 -0
  185. package/dist/client/theme-default/composables/prev-next.js +34 -56
  186. package/dist/client/theme-default/composables/scroll-lock.d.ts +4 -0
  187. package/dist/client/theme-default/composables/scroll-lock.js +95 -0
  188. package/dist/client/theme-default/composables/sidebar.d.ts +25 -0
  189. package/dist/client/theme-default/composables/sidebar.js +96 -133
  190. package/dist/client/theme-default/composables/sponsor-grid.d.ts +10 -0
  191. package/dist/client/theme-default/composables/sponsor-grid.js +69 -76
  192. package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
  193. package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
  194. package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
  195. package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
  196. package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
  197. package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
  198. package/dist/client/theme-default/fonts/inter-italic-symbols.woff2 +0 -0
  199. package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
  200. package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
  201. package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
  202. package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
  203. package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
  204. package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
  205. package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
  206. package/dist/client/theme-default/fonts/inter-roman-symbols.woff2 +0 -0
  207. package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
  208. package/dist/client/theme-default/index.d.ts +3 -0
  209. package/dist/client/theme-default/index.js +4 -3
  210. package/dist/client/theme-default/styles/base.css +279 -211
  211. package/dist/client/theme-default/styles/components/custom-block.css +12 -7
  212. package/dist/client/theme-default/styles/components/vp-code-group.css +13 -16
  213. package/dist/client/theme-default/styles/components/vp-code.css +10 -2
  214. package/dist/client/theme-default/styles/components/vp-doc.css +188 -142
  215. package/dist/client/theme-default/styles/components/vp-sponsor.css +48 -37
  216. package/dist/client/theme-default/styles/docsearch.css +138 -0
  217. package/dist/client/theme-default/styles/fonts.css +216 -55
  218. package/dist/client/theme-default/styles/icons.css +42 -22
  219. package/dist/client/theme-default/styles/vars.css +111 -46
  220. package/dist/client/theme-default/support/docsearch.d.ts +57 -0
  221. package/dist/client/theme-default/support/docsearch.js +145 -0
  222. package/dist/client/theme-default/support/local-search.d.ts +9 -0
  223. package/dist/client/theme-default/support/local-search.js +31 -0
  224. package/dist/client/theme-default/support/lru.d.ts +11 -0
  225. package/dist/client/theme-default/support/lru.js +30 -33
  226. package/dist/client/theme-default/support/reactivity.d.ts +4 -0
  227. package/dist/client/theme-default/support/reactivity.js +10 -0
  228. package/dist/client/theme-default/support/sidebar.d.ts +27 -0
  229. package/dist/client/theme-default/support/sidebar.js +69 -80
  230. package/dist/client/theme-default/support/translation.d.ts +6 -0
  231. package/dist/client/theme-default/support/translation.js +33 -47
  232. package/dist/client/theme-default/support/utils.d.ts +7 -0
  233. package/dist/client/theme-default/support/utils.js +39 -30
  234. package/dist/client/theme-default/without-fonts.d.ts +25 -0
  235. package/dist/client/theme-default/without-fonts.js +37 -36
  236. package/dist/node/chunk-BjrVv9r8.js +28627 -0
  237. package/dist/node/cli.d.ts +1 -0
  238. package/dist/node/cli.js +160 -423
  239. package/dist/node/index.d.ts +1761 -2476
  240. package/dist/node/index.js +1 -121
  241. package/dist/web-types.json +75 -0
  242. package/package.json +89 -98
  243. package/template/.vitepress/config.js +3 -1
  244. package/template/.vitepress/theme/style.css +3 -11
  245. package/theme.d.ts +30 -23
  246. package/types/default-theme.d.ts +109 -113
  247. package/types/docsearch.d.ts +61 -142
  248. package/types/shared.d.ts +469 -50
  249. package/dist/client/theme-default/components/VPNavBarAppearance.vue +0 -32
  250. package/dist/client/theme-default/components/VPNavBarMenu.vue +0 -40
  251. package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +0 -42
  252. package/dist/client/theme-default/components/VPNavBarMenuLink.vue +0 -53
  253. package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +0 -27
  254. package/dist/client/theme-default/components/VPNavBarTranslations.vue +0 -47
  255. package/dist/client/theme-default/components/VPNavScreenAppearance.vue +0 -40
  256. package/dist/client/theme-default/components/VPNavScreenMenu.vue +0 -26
  257. package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +0 -112
  258. package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +0 -40
  259. package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +0 -34
  260. package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +0 -43
  261. package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +0 -14
  262. package/dist/client/theme-default/components/VPNavScreenTranslations.vue +0 -73
  263. package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +0 -8
  264. package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +0 -8
  265. package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +0 -8
  266. package/dist/client/theme-default/components/icons/VPIconArrowLeft.vue +0 -7
  267. package/dist/client/theme-default/components/icons/VPIconArrowRight.vue +0 -7
  268. package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +0 -5
  269. package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +0 -5
  270. package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +0 -5
  271. package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +0 -5
  272. package/dist/client/theme-default/components/icons/VPIconEdit.vue +0 -6
  273. package/dist/client/theme-default/components/icons/VPIconHeart.vue +0 -5
  274. package/dist/client/theme-default/components/icons/VPIconLanguages.vue +0 -9
  275. package/dist/client/theme-default/components/icons/VPIconMinus.vue +0 -5
  276. package/dist/client/theme-default/components/icons/VPIconMinusSquare.vue +0 -6
  277. package/dist/client/theme-default/components/icons/VPIconMoon.vue +0 -5
  278. package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +0 -7
  279. package/dist/client/theme-default/components/icons/VPIconPlus.vue +0 -5
  280. package/dist/client/theme-default/components/icons/VPIconPlusSquare.vue +0 -6
  281. package/dist/client/theme-default/components/icons/VPIconSun.vue +0 -13
  282. package/dist/client/theme-default/composables/aside.js +0 -17
  283. package/dist/client/theme-default/composables/local-nav.js +0 -18
  284. package/dist/node/chunk-C-d2RJOW.js +0 -470
  285. package/dist/node/chunk-CxQfvv8o.js +0 -49065
  286. package/dist/node/worker_shikiResolveLang.js +0 -13
@@ -1,252 +1,211 @@
1
- import { inject, markRaw, nextTick, reactive, readonly } from 'vue';
2
- import { notFoundPageData, treatAsHtml } from '../shared';
3
- import { siteDataRef } from './data';
4
- import { getScrollOffset, inBrowser, withBase } from './utils';
5
- export const RouterSymbol = Symbol();
6
- // we are just using URL to parse the pathname and hash - the base doesn't
7
- // matter and is only passed to support same-host hrefs.
8
- const fakeHost = 'http://a.com';
1
+ import { inBrowser, notFoundPageData, treatAsHtml } from "../shared.js";
2
+ import { siteDataRef } from "./data.js";
3
+ import { runtimeBase, withBase } from "./utils.js";
4
+ import { inject, markRaw, nextTick, reactive, readonly } from "vue";
5
+ //#region src/client/app/router.ts
6
+ const RouterSymbol = Symbol();
7
+ const fakeHost = "http://a.com";
9
8
  const getDefaultRoute = () => ({
10
- path: '/',
11
- hash: '',
12
- query: '',
13
- component: null,
14
- data: notFoundPageData
9
+ path: "/",
10
+ hash: "",
11
+ query: "",
12
+ component: null,
13
+ data: notFoundPageData
15
14
  });
16
- export function createRouter(loadPageModule, fallbackComponent) {
17
- const route = reactive(getDefaultRoute());
18
- const router = {
19
- route,
20
- async go(href, options) {
21
- href = normalizeHref(href);
22
- if ((await router.onBeforeRouteChange?.(href)) === false)
23
- return;
24
- if (!inBrowser || (await changeRoute(href, options)))
25
- await loadPage(href);
26
- syncRouteQueryAndHash();
27
- await router.onAfterRouteChange?.(href);
28
- }
29
- };
30
- let latestPendingPath = null;
31
- async function loadPage(href, scrollPosition = 0, isRetry = false) {
32
- if ((await router.onBeforePageLoad?.(href)) === false)
33
- return;
34
- const targetLoc = new URL(href, fakeHost);
35
- const pendingPath = (latestPendingPath = targetLoc.pathname);
36
- try {
37
- let page = await loadPageModule(pendingPath);
38
- if (!page)
39
- throw new Error(`Page not found: ${pendingPath}`);
40
- if (latestPendingPath === pendingPath) {
41
- latestPendingPath = null;
42
- const { default: comp, __pageData } = page;
43
- if (!comp)
44
- throw new Error(`Invalid route component: ${comp}`);
45
- await router.onAfterPageLoad?.(href);
46
- route.path = inBrowser ? pendingPath : withBase(pendingPath);
47
- route.component = markRaw(comp);
48
- route.data = import.meta.env.PROD
49
- ? markRaw(__pageData)
50
- : readonly(__pageData);
51
- syncRouteQueryAndHash(targetLoc);
52
- if (inBrowser) {
53
- nextTick(() => {
54
- let actualPathname = siteDataRef.value.base +
55
- __pageData.relativePath.replace(/(?:(^|\/)index)?\.md$/, '$1');
56
- if (!siteDataRef.value.cleanUrls && !actualPathname.endsWith('/')) {
57
- actualPathname += '.html';
58
- }
59
- if (actualPathname !== targetLoc.pathname) {
60
- targetLoc.pathname = actualPathname;
61
- href = actualPathname + targetLoc.search + targetLoc.hash;
62
- history.replaceState({}, '', href);
63
- }
64
- return scrollTo(targetLoc.hash, false, scrollPosition);
65
- });
66
- }
67
- }
68
- }
69
- catch (err) {
70
- if (!/fetch|Page not found/.test(err.message) &&
71
- !/^\/404(\.html|\/)?$/.test(href)) {
72
- console.error(err);
73
- }
74
- // retry on fetch fail: the page to hash map may have been invalidated
75
- // because a new deploy happened while the page is open. Try to fetch
76
- // the updated pageToHash map and fetch again.
77
- if (!isRetry) {
78
- try {
79
- const res = await fetch(siteDataRef.value.base + 'hashmap.json');
80
- window.__VP_HASH_MAP__ = await res.json();
81
- await loadPage(href, scrollPosition, true);
82
- return;
83
- }
84
- catch (e) { }
85
- }
86
- if (latestPendingPath === pendingPath) {
87
- latestPendingPath = null;
88
- route.path = inBrowser ? pendingPath : withBase(pendingPath);
89
- route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
90
- const relativePath = inBrowser
91
- ? pendingPath
92
- .replace(/(^|\/)$/, '$1index')
93
- .replace(/(\.html)?$/, '.md')
94
- .replace(/^\//, '')
95
- : '404.md';
96
- route.data = { ...notFoundPageData, relativePath };
97
- syncRouteQueryAndHash(targetLoc);
98
- }
99
- }
100
- }
101
- function syncRouteQueryAndHash(loc = inBrowser
102
- ? location
103
- : { search: '', hash: '' }) {
104
- route.query = loc.search;
105
- route.hash = decodeURIComponent(loc.hash);
106
- }
107
- if (inBrowser) {
108
- if (history.state === null)
109
- history.replaceState({}, '');
110
- window.addEventListener('click', (e) => {
111
- if (e.defaultPrevented ||
112
- !(e.target instanceof Element) ||
113
- e.target.closest('button') || // temporary fix for docsearch action buttons
114
- e.button !== 0 ||
115
- e.ctrlKey ||
116
- e.shiftKey ||
117
- e.altKey ||
118
- e.metaKey) {
119
- return;
120
- }
121
- const link = e.target.closest('a');
122
- if (!link ||
123
- link.closest('.vp-raw') ||
124
- link.hasAttribute('download') ||
125
- link.hasAttribute('target')) {
126
- return;
127
- }
128
- const linkHref = link.getAttribute('href') ??
129
- (link instanceof SVGAElement ? link.getAttribute('xlink:href') : null);
130
- if (linkHref == null)
131
- return;
132
- const { href, origin, pathname } = new URL(linkHref, link.baseURI);
133
- const currentLoc = new URL(location.href); // copy to keep old data
134
- // only intercept inbound html links
135
- if (origin === currentLoc.origin && treatAsHtml(pathname)) {
136
- e.preventDefault();
137
- router.go(href, {
138
- // use smooth scroll when clicking on header anchor links
139
- smoothScroll: link.classList.contains('header-anchor')
140
- });
141
- }
142
- }, { capture: true });
143
- window.addEventListener('popstate', async (e) => {
144
- if (e.state === null)
145
- return;
146
- const href = normalizeHref(location.href);
147
- await loadPage(href, (e.state && e.state.scrollPosition) || 0);
148
- syncRouteQueryAndHash();
149
- await router.onAfterRouteChange?.(href);
150
- });
151
- window.addEventListener('hashchange', (e) => {
152
- e.preventDefault();
153
- syncRouteQueryAndHash();
154
- });
155
- }
156
- handleHMR(route);
157
- return router;
15
+ function createRouter(loadPageModule, fallbackComponent) {
16
+ const route = reactive(getDefaultRoute());
17
+ const router = {
18
+ route,
19
+ async go(href, options) {
20
+ const { hash } = new URL(href, fakeHost);
21
+ const hasTextFragment = inBrowser && document.fragmentDirective && hash.includes(":~:");
22
+ href = normalizeHref(href);
23
+ if (await router.onBeforeRouteChange?.(href) === false) return;
24
+ if (!inBrowser || await changeRoute(href, {
25
+ ...options,
26
+ hasTextFragment
27
+ })) await loadPage(href, { initialLoad: !!options?.initialLoad });
28
+ if (hasTextFragment) location.hash = hash;
29
+ syncRouteQueryAndHash();
30
+ await router.onAfterRouteChange?.(href);
31
+ }
32
+ };
33
+ let latestPendingPath = null;
34
+ async function loadPage(href, { scrollPosition = 0, isRetry = false, initialLoad = false } = {}) {
35
+ if (await router.onBeforePageLoad?.(href) === false) return;
36
+ const targetLoc = new URL(href, fakeHost);
37
+ const pendingPath = latestPendingPath = targetLoc.pathname;
38
+ try {
39
+ let page = await loadPageModule(pendingPath);
40
+ if (!page) throw new Error(`Page not found: ${pendingPath}`);
41
+ if (latestPendingPath === pendingPath) {
42
+ latestPendingPath = null;
43
+ const { default: comp, __pageData } = page;
44
+ if (!comp) throw new Error(`Invalid route component: ${comp}`);
45
+ await router.onAfterPageLoad?.(href);
46
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
47
+ route.component = markRaw(comp);
48
+ route.data = import.meta.env.PROD ? markRaw(__pageData) : readonly(__pageData);
49
+ syncRouteQueryAndHash(targetLoc);
50
+ if (inBrowser) nextTick(() => {
51
+ let actualPathname = runtimeBase() + __pageData.relativePath.replace(/(?:(^|\/)index)?\.md$/, "$1");
52
+ if (!siteDataRef.value.cleanUrls && !actualPathname.endsWith("/")) actualPathname += ".html";
53
+ if (actualPathname !== targetLoc.pathname) {
54
+ targetLoc.pathname = actualPathname;
55
+ href = actualPathname + targetLoc.search + targetLoc.hash;
56
+ history.replaceState({}, "", href);
57
+ }
58
+ if (!initialLoad) scrollTo(targetLoc.hash, scrollPosition);
59
+ });
60
+ }
61
+ } catch (err) {
62
+ if (!/fetch|Page not found/.test(err.message) && !/^\/404(\.html|\/)?$/.test(href)) console.error(err);
63
+ if (!isRetry) try {
64
+ const res = await fetch(runtimeBase() + "hashmap.json");
65
+ window.__VP_HASH_MAP__ = await res.json();
66
+ await loadPage(href, {
67
+ scrollPosition,
68
+ isRetry: true,
69
+ initialLoad
70
+ });
71
+ return;
72
+ } catch (e) {}
73
+ if (latestPendingPath === pendingPath) {
74
+ latestPendingPath = null;
75
+ route.path = inBrowser ? pendingPath : withBase(pendingPath);
76
+ route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
77
+ const relativePath = inBrowser ? route.path.replace(/(^|\/)$/, "$1index").replace(/(\.html)?$/, ".md").slice(runtimeBase().length) : "404.md";
78
+ route.data = {
79
+ ...notFoundPageData,
80
+ relativePath
81
+ };
82
+ syncRouteQueryAndHash(targetLoc);
83
+ }
84
+ }
85
+ }
86
+ function syncRouteQueryAndHash(loc = inBrowser ? location : {
87
+ search: "",
88
+ hash: ""
89
+ }) {
90
+ route.query = loc.search;
91
+ route.hash = decodeURIComponent(loc.hash);
92
+ }
93
+ if (inBrowser) {
94
+ if (history.state === null) history.replaceState({}, "");
95
+ window.addEventListener("click", (e) => {
96
+ if (e.defaultPrevented || !(e.target instanceof Element) || e.target.closest("button") || e.button !== 0 || e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
97
+ const link = e.target.closest("a");
98
+ const url = link && getRoutableLinkUrl(link);
99
+ if (url) {
100
+ e.preventDefault();
101
+ router.go(url.href);
102
+ }
103
+ }, { capture: true });
104
+ window.addEventListener("popstate", async (e) => {
105
+ if (e.state === null) return;
106
+ const href = normalizeHref(location.href);
107
+ await loadPage(href, { scrollPosition: e.state.scrollPosition || 0 });
108
+ syncRouteQueryAndHash();
109
+ await router.onAfterRouteChange?.(href);
110
+ });
111
+ window.addEventListener("hashchange", (e) => {
112
+ e.preventDefault();
113
+ syncRouteQueryAndHash();
114
+ });
115
+ }
116
+ handleHMR(route);
117
+ return router;
158
118
  }
159
- export function useRouter() {
160
- const router = inject(RouterSymbol);
161
- if (!router)
162
- throw new Error('useRouter() is called without provider.');
163
- return router;
119
+ function useRouter() {
120
+ const router = inject(RouterSymbol);
121
+ if (!router) throw new Error("useRouter() is called without provider.");
122
+ return router;
164
123
  }
165
- export function useRoute() {
166
- return useRouter().route;
124
+ function useRoute() {
125
+ return useRouter().route;
167
126
  }
168
- export function scrollTo(hash, smooth = false, scrollPosition = 0) {
169
- if (!hash || scrollPosition) {
170
- window.scrollTo(0, scrollPosition);
171
- return;
172
- }
173
- let target = null;
174
- try {
175
- target = document.getElementById(decodeURIComponent(hash).slice(1));
176
- }
177
- catch (e) {
178
- console.warn(e);
179
- }
180
- if (target) {
181
- const targetPadding = parseInt(window.getComputedStyle(target).paddingTop, 10);
182
- const targetTop = window.scrollY +
183
- target.getBoundingClientRect().top -
184
- getScrollOffset() +
185
- targetPadding;
186
- function scrollToTarget() {
187
- // only smooth scroll if distance is smaller than screen height.
188
- if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight)
189
- window.scrollTo(0, targetTop);
190
- else
191
- window.scrollTo({ left: 0, top: targetTop, behavior: 'smooth' });
192
- }
193
- requestAnimationFrame(scrollToTarget);
194
- }
127
+ function scrollTo(hash, scrollPosition = 0) {
128
+ if (!hash || scrollPosition) {
129
+ window.scrollTo(0, scrollPosition);
130
+ return;
131
+ }
132
+ let target = null;
133
+ try {
134
+ target = document.getElementById(decodeURIComponent(hash).slice(1));
135
+ } catch (e) {
136
+ console.warn(e);
137
+ }
138
+ if (!target) return;
139
+ const scrollToTarget = () => {
140
+ target.scrollIntoView({ block: "start" });
141
+ target.focus({ preventScroll: true });
142
+ if (document.activeElement === target) return;
143
+ if (target.hasAttribute("tabindex")) return;
144
+ const restoreTabindex = () => {
145
+ target.removeAttribute("tabindex");
146
+ target.removeEventListener("blur", restoreTabindex);
147
+ };
148
+ target.setAttribute("tabindex", "-1");
149
+ target.addEventListener("blur", restoreTabindex);
150
+ target.focus({ preventScroll: true });
151
+ if (document.activeElement !== target) restoreTabindex();
152
+ };
153
+ requestAnimationFrame(scrollToTarget);
154
+ }
155
+ /**
156
+ * Resolves the URL of a link the router handles on the client side, or `null`
157
+ * if it's left to the browser (explicit `target`, `download`, `.vp-raw`,
158
+ * other origins, non-html files).
159
+ */
160
+ function getRoutableLinkUrl(link) {
161
+ if (link.closest(".vp-raw") || link.hasAttribute("download") || link.hasAttribute("target")) return null;
162
+ const href = link.getAttribute("href") ?? (link instanceof SVGAElement ? link.getAttribute("xlink:href") : null);
163
+ if (href == null) return null;
164
+ const url = new URL(href, link.baseURI);
165
+ return url.origin === location.origin && treatAsHtml(url.pathname) ? url : null;
195
166
  }
196
167
  function handleHMR(route) {
197
- // update route.data on HMR updates of active page
198
- if (import.meta.hot) {
199
- // hot reload pageData
200
- import.meta.hot.on('vitepress:pageData', (payload) => {
201
- if (shouldHotReload(payload))
202
- route.data = payload.pageData;
203
- });
204
- }
168
+ if (import.meta.hot) import.meta.hot.on("vitepress:pageData", (payload) => {
169
+ if (shouldHotReload(payload)) route.data = payload.pageData;
170
+ });
205
171
  }
206
172
  function shouldHotReload(payload) {
207
- const payloadPath = payload.path.replace(/(?:(^|\/)index)?\.md$/, '$1');
208
- const locationPath = location.pathname
209
- .replace(/(?:(^|\/)index)?\.html$/, '')
210
- .slice(siteDataRef.value.base.length - 1);
211
- return payloadPath === locationPath;
173
+ return payload.path.replace(/(?:(^|\/)index)?\.md$/, "$1") === location.pathname.replace(/(?:(^|\/)index)?\.html$/, "").slice(runtimeBase().length - 1);
212
174
  }
213
175
  function normalizeHref(href) {
214
- const url = new URL(href, fakeHost);
215
- url.pathname = url.pathname.replace(/(^|\/)index(\.html)?$/, '$1');
216
- // ensure correct deep link so page refresh lands on correct files.
217
- if (siteDataRef.value.cleanUrls) {
218
- url.pathname = url.pathname.replace(/\.html$/, '');
219
- }
220
- else if (!url.pathname.endsWith('/') && !url.pathname.endsWith('.html')) {
221
- url.pathname += '.html';
222
- }
223
- return url.pathname + url.search + url.hash;
176
+ const url = new URL(href, fakeHost);
177
+ url.pathname = url.pathname.replace(/(^|\/)index(\.html)?$/, "$1");
178
+ if (siteDataRef.value.cleanUrls) url.pathname = url.pathname.replace(/\.html$/, "");
179
+ else if (!url.pathname.endsWith("/") && !url.pathname.endsWith(".html")) url.pathname += ".html";
180
+ return url.pathname + url.search + url.hash.split(":~:")[0];
224
181
  }
225
- async function changeRoute(href, { smoothScroll = false, initialLoad = false } = {}) {
226
- const loc = normalizeHref(location.href);
227
- const { pathname, hash } = new URL(href, fakeHost);
228
- const currentLoc = new URL(loc, fakeHost);
229
- if (href === loc) {
230
- if (!initialLoad) {
231
- scrollTo(hash, smoothScroll);
232
- return false;
233
- }
234
- }
235
- else {
236
- // save scroll position before changing URL
237
- history.replaceState({ scrollPosition: window.scrollY }, '');
238
- history.pushState({}, '', href);
239
- if (pathname === currentLoc.pathname) {
240
- // scroll between hash anchors on the same page, avoid duplicate entries
241
- if (hash !== currentLoc.hash) {
242
- window.dispatchEvent(new HashChangeEvent('hashchange', {
243
- oldURL: currentLoc.href,
244
- newURL: href
245
- }));
246
- scrollTo(hash, smoothScroll);
247
- }
248
- return false;
249
- }
250
- }
251
- return true;
182
+ async function changeRoute(href, { initialLoad = false, replace = false, hasTextFragment = false } = {}) {
183
+ const loc = normalizeHref(location.href);
184
+ const nextUrl = new URL(href, location.origin);
185
+ const currentUrl = new URL(loc, location.origin);
186
+ if (href === loc) {
187
+ if (!initialLoad) {
188
+ if (!hasTextFragment) scrollTo(nextUrl.hash);
189
+ return false;
190
+ }
191
+ } else {
192
+ if (replace) history.replaceState({}, "", href);
193
+ else {
194
+ history.replaceState({ scrollPosition: window.scrollY }, "");
195
+ history.pushState({}, "", href);
196
+ }
197
+ if (nextUrl.pathname === currentUrl.pathname) {
198
+ if (nextUrl.hash !== currentUrl.hash) {
199
+ window.dispatchEvent(new HashChangeEvent("hashchange", {
200
+ oldURL: currentUrl.href,
201
+ newURL: nextUrl.href
202
+ }));
203
+ if (!hasTextFragment) scrollTo(nextUrl.hash);
204
+ }
205
+ return false;
206
+ }
207
+ }
208
+ return true;
252
209
  }
210
+ //#endregion
211
+ export { RouterSymbol, createRouter, getRoutableLinkUrl, scrollTo, useRoute, useRouter };
@@ -0,0 +1,4 @@
1
+ import { SSGContext } from "../shared.js";
2
+ //#region src/client/app/ssr.d.ts
3
+ export declare function render(path: string): Promise<SSGContext>;
4
+ //#endregion
@@ -1,10 +1,15 @@
1
- // entry for SSR
2
- import { renderToString } from 'vue/server-renderer';
3
- import { createApp } from './index';
4
- export async function render(path) {
5
- const { app, router } = await createApp();
6
- await router.go(path);
7
- const ctx = { content: '', vpSocialIcons: new Set() };
8
- ctx.content = await renderToString(app, ctx);
9
- return ctx;
1
+ import { createApp } from "./index.js";
2
+ import { renderToString } from "vue/server-renderer";
3
+ //#region src/client/app/ssr.ts
4
+ async function render(path) {
5
+ const { app, router } = await createApp();
6
+ await router.go(path);
7
+ const ctx = {
8
+ content: "",
9
+ vpIcons: /* @__PURE__ */ new Set()
10
+ };
11
+ ctx.content = await renderToString(app, ctx);
12
+ return ctx;
10
13
  }
14
+ //#endregion
15
+ export { render };
@@ -0,0 +1,24 @@
1
+ import { Awaitable, SiteData } from "../shared.js";
2
+ import { Router } from "./router.js";
3
+ import { App, Component, Ref } from "vue";
4
+ //#region src/client/app/theme.d.ts
5
+ export interface EnhanceAppContext {
6
+ app: App;
7
+ router: Router;
8
+ siteData: Ref<SiteData>;
9
+ }
10
+ export interface Theme {
11
+ Layout?: Component;
12
+ enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>;
13
+ extends?: Theme;
14
+ /**
15
+ * Runs inside the root component's `setup()` (during SSR too). With
16
+ * `extends`, setups run base-first, like `enhanceApp`.
17
+ */
18
+ setup?: () => void;
19
+ /**
20
+ * @deprecated Render not found page by checking `useData().page.value.isNotFound` in Layout instead.
21
+ */
22
+ NotFound?: Component;
23
+ }
24
+ //#endregion
@@ -1 +0,0 @@
1
- export {};
@@ -0,0 +1,35 @@
1
+ import { Awaitable, escapeHtml, inBrowser, joinPath } from "../shared.js";
2
+ import { AsyncComponentLoader, SetupContext } from "vue";
3
+ //#region src/client/app/utils.d.ts
4
+ /**
5
+ * Runtime base path used by the app.
6
+ *
7
+ * Usually this is the configured site base.
8
+ *
9
+ * For a relative base (`'./'`), the mount point is unknown at build time, so:
10
+ * - SSR: uses `RELATIVE_BASE_SENTINEL` (for per-page URL relativization)
11
+ * - dev browser: uses `'/'` (dev server always mounts at root)
12
+ * - prod browser: resolves from the page's `__VP_SITE_ROOT__`
13
+ */
14
+ export declare function runtimeBase(): string;
15
+ /**
16
+ * Prepend base to internal (non-relative) urls
17
+ */
18
+ export declare function withBase(path: string): string;
19
+ /**
20
+ * Converts a url path to the corresponding js chunk filename.
21
+ */
22
+ export declare function pathToFile(path: string): string | null;
23
+ export declare let contentUpdatedCallbacks: (() => any)[];
24
+ /**
25
+ * Register callback that is called every time the markdown content is updated
26
+ * in the DOM.
27
+ */
28
+ export declare function onContentUpdated(fn: () => any): void;
29
+ export declare function defineClientComponent(loader: AsyncComponentLoader, args?: any[], cb?: () => Awaitable<void>): {
30
+ setup(_: unknown, { slots }: SetupContext): () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
31
+ [key: string]: any;
32
+ }> | null;
33
+ };
34
+ //#endregion
35
+ export { escapeHtml as _escapeHtml, inBrowser, joinPath };