@vuepress/client 2.0.0-beta.5 → 2.0.0-beta.50

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 (72) hide show
  1. package/dist/app.js +286 -0
  2. package/dist/chunk-V3MKNX2O.js +264 -0
  3. package/dist/index.d.ts +260 -0
  4. package/dist/index.js +60 -0
  5. package/dist/setupDevtools-EXVHPMXB.js +88 -0
  6. package/package.json +48 -16
  7. package/templates/{index.ssr.html → build.html} +3 -0
  8. package/templates/{index.dev.html → dev.html} +2 -0
  9. package/types.d.ts +6 -0
  10. package/CHANGELOG.md +0 -187
  11. package/lib/app.d.ts +0 -18
  12. package/lib/app.js +0 -132
  13. package/lib/client.d.ts +0 -1
  14. package/lib/client.js +0 -14
  15. package/lib/components/Content.d.ts +0 -7
  16. package/lib/components/Content.js +0 -34
  17. package/lib/components/OutboundLink.css +0 -7
  18. package/lib/components/OutboundLink.d.ts +0 -3
  19. package/lib/components/OutboundLink.js +0 -24
  20. package/lib/components/Vuepress.d.ts +0 -5
  21. package/lib/components/Vuepress.js +0 -33
  22. package/lib/components/index.d.ts +0 -3
  23. package/lib/components/index.js +0 -3
  24. package/lib/constants.d.ts +0 -4
  25. package/lib/index.d.ts +0 -7
  26. package/lib/index.js +0 -5
  27. package/lib/injections/index.d.ts +0 -10
  28. package/lib/injections/index.js +0 -10
  29. package/lib/injections/pageData.d.ts +0 -7
  30. package/lib/injections/pageData.js +0 -31
  31. package/lib/injections/pageFrontmatter.d.ts +0 -7
  32. package/lib/injections/pageFrontmatter.js +0 -10
  33. package/lib/injections/pageHead.d.ts +0 -15
  34. package/lib/injections/pageHead.js +0 -33
  35. package/lib/injections/pageHeadTitle.d.ts +0 -11
  36. package/lib/injections/pageHeadTitle.js +0 -13
  37. package/lib/injections/pageLang.d.ts +0 -13
  38. package/lib/injections/pageLang.js +0 -16
  39. package/lib/injections/pagesData.d.ts +0 -6
  40. package/lib/injections/pagesData.js +0 -6
  41. package/lib/injections/routeLocale.d.ts +0 -10
  42. package/lib/injections/routeLocale.js +0 -14
  43. package/lib/injections/siteData.d.ts +0 -6
  44. package/lib/injections/siteData.js +0 -10
  45. package/lib/injections/siteLocaleData.d.ts +0 -12
  46. package/lib/injections/siteLocaleData.js +0 -17
  47. package/lib/injections/updateHead.d.ts +0 -15
  48. package/lib/injections/updateHead.js +0 -100
  49. package/lib/server.d.ts +0 -8
  50. package/lib/server.js +0 -10
  51. package/lib/types/clientAppEnhance.d.ts +0 -8
  52. package/lib/types/clientAppEnhance.js +0 -1
  53. package/lib/types/clientAppSetup.d.ts +0 -1
  54. package/lib/types/clientAppSetup.js +0 -1
  55. package/lib/types/index.d.ts +0 -7
  56. package/lib/types/index.js +0 -2
  57. package/lib/types/internal/clientAppEnhances.d.ts +0 -5
  58. package/lib/types/internal/clientAppRootComponents.d.ts +0 -5
  59. package/lib/types/internal/clientAppSetups.d.ts +0 -5
  60. package/lib/types/internal/layoutComponents.d.ts +0 -5
  61. package/lib/types/internal/pagesComponent.d.ts +0 -5
  62. package/lib/types/internal/pagesData.d.ts +0 -5
  63. package/lib/types/internal/pagesRoutes.d.ts +0 -5
  64. package/lib/types/internal/siteData.d.ts +0 -5
  65. package/lib/utils/defineClientAppEnhance.d.ts +0 -2
  66. package/lib/utils/defineClientAppEnhance.js +0 -1
  67. package/lib/utils/defineClientAppSetup.d.ts +0 -2
  68. package/lib/utils/defineClientAppSetup.js +0 -1
  69. package/lib/utils/index.d.ts +0 -3
  70. package/lib/utils/index.js +0 -3
  71. package/lib/utils/withBase.d.ts +0 -4
  72. package/lib/utils/withBase.js +0 -11
package/dist/app.js ADDED
@@ -0,0 +1,286 @@
1
+ import {
2
+ ClientOnly,
3
+ Content,
4
+ Vuepress,
5
+ pageData,
6
+ pageFrontmatterSymbol,
7
+ pageHeadSymbol,
8
+ pageHeadTitleSymbol,
9
+ pageLangSymbol,
10
+ resolvers,
11
+ routeLocaleSymbol,
12
+ siteData,
13
+ siteLocaleDataSymbol,
14
+ updateHeadSymbol,
15
+ usePageHead,
16
+ usePageLang,
17
+ withBase
18
+ } from "./chunk-V3MKNX2O.js";
19
+
20
+ // src/app.ts
21
+ import { clientConfigs } from "@internal/clientConfigs";
22
+ import { createApp, createSSRApp, h } from "vue";
23
+ import { RouterView } from "vue-router";
24
+
25
+ // src/router.ts
26
+ import { pagesComponents } from "@internal/pagesComponents";
27
+ import { removeEndingSlash } from "@vuepress/shared";
28
+ import {
29
+ createMemoryHistory,
30
+ createRouter,
31
+ createWebHistory,
32
+ START_LOCATION
33
+ } from "vue-router";
34
+
35
+ // src/routes.ts
36
+ import { pagesRoutes } from "@internal/pagesRoutes";
37
+ var createRoutes = () => pagesRoutes.reduce(
38
+ (result, [name, path, meta, redirects]) => {
39
+ result.push(
40
+ {
41
+ name,
42
+ path,
43
+ component: Vuepress,
44
+ meta
45
+ },
46
+ ...redirects.map((item) => ({
47
+ path: item,
48
+ redirect: path
49
+ }))
50
+ );
51
+ return result;
52
+ },
53
+ [
54
+ {
55
+ name: "404",
56
+ path: "/:catchAll(.*)",
57
+ component: Vuepress
58
+ }
59
+ ]
60
+ );
61
+
62
+ // src/router.ts
63
+ var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
64
+ var createVueRouter = () => {
65
+ const router = createRouter({
66
+ history: historyCreator(removeEndingSlash(siteData.value.base)),
67
+ routes: createRoutes(),
68
+ scrollBehavior: (to, from, savedPosition) => {
69
+ if (savedPosition)
70
+ return savedPosition;
71
+ if (to.hash)
72
+ return { el: to.hash };
73
+ return { top: 0 };
74
+ }
75
+ });
76
+ router.beforeResolve(async (to, from) => {
77
+ if (to.path !== from.path || from === START_LOCATION) {
78
+ ;
79
+ [pageData.value] = await Promise.all([
80
+ resolvers.resolvePageData(to.name),
81
+ pagesComponents[to.name]?.__asyncLoader()
82
+ ]);
83
+ }
84
+ });
85
+ return router;
86
+ };
87
+
88
+ // src/setupGlobalComponents.ts
89
+ var setupGlobalComponents = (app) => {
90
+ app.component("ClientOnly", ClientOnly);
91
+ app.component("Content", Content);
92
+ };
93
+
94
+ // src/setupGlobalComputed.ts
95
+ import { computed } from "vue";
96
+ var setupGlobalComputed = (app, router) => {
97
+ const routeLocale = computed(
98
+ () => resolvers.resolveRouteLocale(
99
+ siteData.value.locales,
100
+ router.currentRoute.value.path
101
+ )
102
+ );
103
+ const siteLocaleData = computed(
104
+ () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
105
+ );
106
+ const pageFrontmatter = computed(
107
+ () => resolvers.resolvePageFrontmatter(pageData.value)
108
+ );
109
+ const pageHeadTitle = computed(
110
+ () => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
111
+ );
112
+ const pageHead = computed(
113
+ () => resolvers.resolvePageHead(
114
+ pageHeadTitle.value,
115
+ pageFrontmatter.value,
116
+ siteLocaleData.value
117
+ )
118
+ );
119
+ const pageLang = computed(() => resolvers.resolvePageLang(pageData.value));
120
+ app.provide(routeLocaleSymbol, routeLocale);
121
+ app.provide(siteLocaleDataSymbol, siteLocaleData);
122
+ app.provide(pageFrontmatterSymbol, pageFrontmatter);
123
+ app.provide(pageHeadTitleSymbol, pageHeadTitle);
124
+ app.provide(pageHeadSymbol, pageHead);
125
+ app.provide(pageLangSymbol, pageLang);
126
+ Object.defineProperties(app.config.globalProperties, {
127
+ $frontmatter: { get: () => pageFrontmatter.value },
128
+ $head: { get: () => pageHead.value },
129
+ $headTitle: { get: () => pageHeadTitle.value },
130
+ $lang: { get: () => pageLang.value },
131
+ $page: { get: () => pageData.value },
132
+ $routeLocale: { get: () => routeLocale.value },
133
+ $site: { get: () => siteData.value },
134
+ $siteLocale: { get: () => siteLocaleData.value },
135
+ $withBase: { get: () => withBase }
136
+ });
137
+ return {
138
+ pageData,
139
+ pageFrontmatter,
140
+ pageHead,
141
+ pageHeadTitle,
142
+ pageLang,
143
+ routeLocale,
144
+ siteData,
145
+ siteLocaleData
146
+ };
147
+ };
148
+
149
+ // src/setupUpdateHead.ts
150
+ import { isPlainObject, isString } from "@vuepress/shared";
151
+ import { onMounted, provide, ref, useSSRContext, watch } from "vue";
152
+ import { useRoute } from "vue-router";
153
+ var setupUpdateHead = () => {
154
+ const route = useRoute();
155
+ const head = usePageHead();
156
+ const lang = usePageLang();
157
+ if (__VUEPRESS_SSR__) {
158
+ const ssrContext = useSSRContext();
159
+ if (ssrContext) {
160
+ ssrContext.head = head.value;
161
+ ssrContext.lang = lang.value;
162
+ }
163
+ return;
164
+ }
165
+ const headTags = ref([]);
166
+ const loadHead = () => {
167
+ head.value.forEach((item) => {
168
+ const tag = queryHeadTag(item);
169
+ if (tag) {
170
+ headTags.value.push(tag);
171
+ }
172
+ });
173
+ };
174
+ const updateHead = () => {
175
+ document.documentElement.lang = lang.value;
176
+ headTags.value.forEach((item) => {
177
+ if (item.parentNode === document.head) {
178
+ document.head.removeChild(item);
179
+ }
180
+ });
181
+ headTags.value.splice(0, headTags.value.length);
182
+ head.value.forEach((item) => {
183
+ const tag = createHeadTag(item);
184
+ if (tag !== null) {
185
+ document.head.appendChild(tag);
186
+ headTags.value.push(tag);
187
+ }
188
+ });
189
+ };
190
+ provide(updateHeadSymbol, updateHead);
191
+ onMounted(() => {
192
+ loadHead();
193
+ updateHead();
194
+ watch(
195
+ () => __VUEPRESS_DEV__ ? head.value : route.path,
196
+ () => updateHead()
197
+ );
198
+ });
199
+ };
200
+ var queryHeadTag = ([
201
+ tagName,
202
+ attrs,
203
+ content = ""
204
+ ]) => {
205
+ const attrsSelector = Object.entries(attrs).map(([key, value]) => {
206
+ if (isString(value)) {
207
+ return `[${key}="${value}"]`;
208
+ }
209
+ if (value === true) {
210
+ return `[${key}]`;
211
+ }
212
+ return "";
213
+ }).join("");
214
+ const selector = `head > ${tagName}${attrsSelector}`;
215
+ const tags = Array.from(document.querySelectorAll(selector));
216
+ const matchedTag = tags.find((item) => item.innerText === content);
217
+ return matchedTag || null;
218
+ };
219
+ var createHeadTag = ([
220
+ tagName,
221
+ attrs,
222
+ content
223
+ ]) => {
224
+ if (!isString(tagName)) {
225
+ return null;
226
+ }
227
+ const tag = document.createElement(tagName);
228
+ if (isPlainObject(attrs)) {
229
+ Object.entries(attrs).forEach(([key, value]) => {
230
+ if (isString(value)) {
231
+ tag.setAttribute(key, value);
232
+ } else if (value === true) {
233
+ tag.setAttribute(key, "");
234
+ }
235
+ });
236
+ }
237
+ if (isString(content)) {
238
+ tag.appendChild(document.createTextNode(content));
239
+ }
240
+ return tag;
241
+ };
242
+
243
+ // src/app.ts
244
+ var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
245
+ var createVueApp = async () => {
246
+ const app = appCreator({
247
+ name: "VuepressApp",
248
+ setup() {
249
+ setupUpdateHead();
250
+ for (const clientConfig of clientConfigs) {
251
+ clientConfig.setup?.();
252
+ }
253
+ return () => [
254
+ h(RouterView),
255
+ ...clientConfigs.flatMap(
256
+ ({ rootComponents = [] }) => rootComponents.map((component) => h(component))
257
+ )
258
+ ];
259
+ }
260
+ });
261
+ const router = createVueRouter();
262
+ setupGlobalComponents(app);
263
+ const globalComputed = setupGlobalComputed(app, router);
264
+ if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
265
+ const { setupDevtools } = await import("./setupDevtools-EXVHPMXB.js");
266
+ setupDevtools(app, globalComputed);
267
+ }
268
+ for (const clientConfig of clientConfigs) {
269
+ await clientConfig.enhance?.({ app, router, siteData });
270
+ }
271
+ app.use(router);
272
+ return {
273
+ app,
274
+ router
275
+ };
276
+ };
277
+ if (!__VUEPRESS_SSR__) {
278
+ createVueApp().then(({ app, router }) => {
279
+ router.isReady().then(() => {
280
+ app.mount("#app");
281
+ });
282
+ });
283
+ }
284
+ export {
285
+ createVueApp
286
+ };
@@ -0,0 +1,264 @@
1
+ // src/composables/pagesData.ts
2
+ import { pagesData as pagesDataRaw } from "@internal/pagesData";
3
+ import { ref } from "vue";
4
+ var pagesData = ref(pagesDataRaw);
5
+ var usePagesData = () => pagesData;
6
+
7
+ // src/composables/pageData.ts
8
+ import { readonly, ref as ref2 } from "vue";
9
+ var pageDataEmpty = readonly({
10
+ key: "",
11
+ path: "",
12
+ title: "",
13
+ lang: "",
14
+ frontmatter: {},
15
+ excerpt: "",
16
+ headers: []
17
+ });
18
+ var pageData = ref2(pageDataEmpty);
19
+ var usePageData = () => pageData;
20
+ if (import.meta.webpackHot || import.meta.hot) {
21
+ __VUE_HMR_RUNTIME__.updatePageData = (data) => {
22
+ pagesData.value[data.key] = () => Promise.resolve(data);
23
+ if (data.key === pageData.value.key) {
24
+ pageData.value = data;
25
+ }
26
+ };
27
+ }
28
+
29
+ // src/composables/pageFrontmatter.ts
30
+ import { inject } from "vue";
31
+ var pageFrontmatterSymbol = Symbol(
32
+ __VUEPRESS_DEV__ ? "pageFrontmatter" : ""
33
+ );
34
+ var usePageFrontmatter = () => {
35
+ const pageFrontmatter = inject(pageFrontmatterSymbol);
36
+ if (!pageFrontmatter) {
37
+ throw new Error("usePageFrontmatter() is called without provider.");
38
+ }
39
+ return pageFrontmatter;
40
+ };
41
+
42
+ // src/composables/pageHead.ts
43
+ import { inject as inject2 } from "vue";
44
+ var pageHeadSymbol = Symbol(
45
+ __VUEPRESS_DEV__ ? "pageHead" : ""
46
+ );
47
+ var usePageHead = () => {
48
+ const pageHead = inject2(pageHeadSymbol);
49
+ if (!pageHead) {
50
+ throw new Error("usePageHead() is called without provider.");
51
+ }
52
+ return pageHead;
53
+ };
54
+
55
+ // src/composables/pageHeadTitle.ts
56
+ import { inject as inject3 } from "vue";
57
+ var pageHeadTitleSymbol = Symbol(
58
+ __VUEPRESS_DEV__ ? "pageHeadTitle" : ""
59
+ );
60
+ var usePageHeadTitle = () => {
61
+ const pageHeadTitle = inject3(pageHeadTitleSymbol);
62
+ if (!pageHeadTitle) {
63
+ throw new Error("usePageHeadTitle() is called without provider.");
64
+ }
65
+ return pageHeadTitle;
66
+ };
67
+
68
+ // src/composables/pageLang.ts
69
+ import { inject as inject4 } from "vue";
70
+ var pageLangSymbol = Symbol(
71
+ __VUEPRESS_DEV__ ? "pageLang" : ""
72
+ );
73
+ var usePageLang = () => {
74
+ const pageLang = inject4(pageLangSymbol);
75
+ if (!pageLang) {
76
+ throw new Error("usePageLang() is called without provider.");
77
+ }
78
+ return pageLang;
79
+ };
80
+
81
+ // src/composables/routeLocale.ts
82
+ import { inject as inject5 } from "vue";
83
+ var routeLocaleSymbol = Symbol(
84
+ __VUEPRESS_DEV__ ? "routeLocale" : ""
85
+ );
86
+ var useRouteLocale = () => {
87
+ const routeLocale = inject5(routeLocaleSymbol);
88
+ if (!routeLocale) {
89
+ throw new Error("useRouteLocale() is called without provider.");
90
+ }
91
+ return routeLocale;
92
+ };
93
+
94
+ // src/composables/siteData.ts
95
+ import { siteData as siteDataRaw } from "@internal/siteData";
96
+ import { ref as ref3 } from "vue";
97
+ var siteData = ref3(siteDataRaw);
98
+ var useSiteData = () => siteData;
99
+ if (import.meta.webpackHot || import.meta.hot) {
100
+ __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
101
+ siteData.value = data;
102
+ };
103
+ }
104
+
105
+ // src/composables/siteLocaleData.ts
106
+ import { inject as inject6 } from "vue";
107
+ var siteLocaleDataSymbol = Symbol(
108
+ __VUEPRESS_DEV__ ? "siteLocaleData" : ""
109
+ );
110
+ var useSiteLocaleData = () => {
111
+ const siteLocaleData = inject6(siteLocaleDataSymbol);
112
+ if (!siteLocaleData) {
113
+ throw new Error("useSiteLocaleData() is called without provider.");
114
+ }
115
+ return siteLocaleData;
116
+ };
117
+
118
+ // src/composables/updateHead.ts
119
+ import { inject as inject7 } from "vue";
120
+ var updateHeadSymbol = Symbol(
121
+ __VUEPRESS_DEV__ ? "updateHead" : ""
122
+ );
123
+ var useUpdateHead = () => {
124
+ const updateHead = inject7(updateHeadSymbol);
125
+ if (!updateHead) {
126
+ throw new Error("useUpdateHead() is called without provider.");
127
+ }
128
+ return updateHead;
129
+ };
130
+
131
+ // src/resolvers.ts
132
+ import {
133
+ dedupeHead,
134
+ isArray,
135
+ isString,
136
+ resolveLocalePath
137
+ } from "@vuepress/shared";
138
+ import { reactive } from "vue";
139
+ var resolvers = reactive({
140
+ resolvePageData: async (pageKey) => {
141
+ const pageDataResolver = pagesData.value[pageKey];
142
+ const pageData2 = await pageDataResolver?.();
143
+ return pageData2 ?? pageDataEmpty;
144
+ },
145
+ resolvePageFrontmatter: (pageData2) => pageData2.frontmatter,
146
+ resolvePageHead: (headTitle, frontmatter, siteLocale) => {
147
+ const description = isString(frontmatter.description) ? frontmatter.description : siteLocale.description;
148
+ const head = [
149
+ ...isArray(frontmatter.head) ? frontmatter.head : [],
150
+ ...siteLocale.head,
151
+ ["title", {}, headTitle],
152
+ ["meta", { name: "description", content: description }]
153
+ ];
154
+ return dedupeHead(head);
155
+ },
156
+ resolvePageHeadTitle: (page, siteLocale) => `${page.title ? `${page.title} | ` : ``}${siteLocale.title}`,
157
+ resolvePageLang: (pageData2) => pageData2.lang || "en",
158
+ resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
159
+ resolveSiteLocaleData: (site, routeLocale) => ({
160
+ ...site,
161
+ ...site.locales[routeLocale]
162
+ })
163
+ });
164
+
165
+ // src/components/ClientOnly.ts
166
+ import { defineComponent, onMounted, ref as ref4 } from "vue";
167
+ var ClientOnly = defineComponent({
168
+ name: "ClientOnly",
169
+ setup(_, ctx) {
170
+ const isMounted = ref4(false);
171
+ onMounted(() => {
172
+ isMounted.value = true;
173
+ });
174
+ return () => isMounted.value ? ctx.slots.default?.() : null;
175
+ }
176
+ });
177
+
178
+ // src/components/Content.ts
179
+ import { pagesComponents } from "@internal/pagesComponents";
180
+ import { computed, defineComponent as defineComponent2, h } from "vue";
181
+ var Content = defineComponent2({
182
+ name: "Content",
183
+ props: {
184
+ pageKey: {
185
+ type: String,
186
+ required: false,
187
+ default: ""
188
+ }
189
+ },
190
+ setup(props) {
191
+ const page = usePageData();
192
+ const pageComponent = computed(
193
+ () => pagesComponents[props.pageKey || page.value.key]
194
+ );
195
+ return () => pageComponent.value ? h(pageComponent.value) : h(
196
+ "div",
197
+ __VUEPRESS_DEV__ ? "Page does not exist. This is a fallback content." : "404 Not Found"
198
+ );
199
+ }
200
+ });
201
+
202
+ // src/components/Vuepress.ts
203
+ import { layoutComponents } from "@internal/layoutComponents";
204
+ import { isString as isString2 } from "@vuepress/shared";
205
+ import { computed as computed2, defineComponent as defineComponent3, h as h2, resolveComponent } from "vue";
206
+ var Vuepress = defineComponent3({
207
+ name: "Vuepress",
208
+ setup() {
209
+ const page = usePageData();
210
+ const layoutComponent = computed2(() => {
211
+ let layoutName;
212
+ if (page.value.path) {
213
+ const frontmatterLayout = page.value.frontmatter.layout;
214
+ if (isString2(frontmatterLayout)) {
215
+ layoutName = frontmatterLayout;
216
+ } else {
217
+ layoutName = "Layout";
218
+ }
219
+ } else {
220
+ layoutName = "404";
221
+ }
222
+ return layoutComponents[layoutName] || resolveComponent(layoutName, false);
223
+ });
224
+ return () => h2(layoutComponent.value);
225
+ }
226
+ });
227
+
228
+ // src/withBase.ts
229
+ import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
230
+ var withBase = (url) => {
231
+ if (isLinkHttp(url))
232
+ return url;
233
+ const base = useSiteData().value.base;
234
+ return `${base}${removeLeadingSlash(url)}`;
235
+ };
236
+
237
+ export {
238
+ pagesData,
239
+ usePagesData,
240
+ pageDataEmpty,
241
+ pageData,
242
+ usePageData,
243
+ pageFrontmatterSymbol,
244
+ usePageFrontmatter,
245
+ pageHeadSymbol,
246
+ usePageHead,
247
+ pageHeadTitleSymbol,
248
+ usePageHeadTitle,
249
+ pageLangSymbol,
250
+ usePageLang,
251
+ routeLocaleSymbol,
252
+ useRouteLocale,
253
+ siteData,
254
+ useSiteData,
255
+ siteLocaleDataSymbol,
256
+ useSiteLocaleData,
257
+ updateHeadSymbol,
258
+ useUpdateHead,
259
+ resolvers,
260
+ ClientOnly,
261
+ Content,
262
+ Vuepress,
263
+ withBase
264
+ };