@vuepress/client 2.0.0-beta.9 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -0
  3. package/dist/app.d.ts +7 -0
  4. package/dist/app.js +353 -0
  5. package/dist/chunk-PEQEPZ75.js +339 -0
  6. package/dist/createVueAppFunction-YNGNKfE3.d.ts +9 -0
  7. package/dist/index.d.ts +283 -0
  8. package/dist/index.js +64 -0
  9. package/dist/setupDevtools-X4YFRK4B.js +89 -0
  10. package/package.json +52 -17
  11. package/templates/build.html +16 -0
  12. package/templates/{index.dev.html → dev.html} +2 -0
  13. package/types.d.ts +6 -3
  14. package/CHANGELOG.md +0 -229
  15. package/lib/app.d.ts +0 -18
  16. package/lib/app.js +0 -139
  17. package/lib/client.d.ts +0 -1
  18. package/lib/client.js +0 -14
  19. package/lib/components/Content.d.ts +0 -7
  20. package/lib/components/Content.js +0 -34
  21. package/lib/components/OutboundLink.css +0 -7
  22. package/lib/components/OutboundLink.d.ts +0 -3
  23. package/lib/components/OutboundLink.js +0 -24
  24. package/lib/components/Vuepress.d.ts +0 -5
  25. package/lib/components/Vuepress.js +0 -33
  26. package/lib/components/index.d.ts +0 -3
  27. package/lib/components/index.js +0 -3
  28. package/lib/index.d.ts +0 -7
  29. package/lib/index.js +0 -5
  30. package/lib/injections/index.d.ts +0 -10
  31. package/lib/injections/index.js +0 -10
  32. package/lib/injections/pageData.d.ts +0 -7
  33. package/lib/injections/pageData.js +0 -32
  34. package/lib/injections/pageFrontmatter.d.ts +0 -7
  35. package/lib/injections/pageFrontmatter.js +0 -10
  36. package/lib/injections/pageHead.d.ts +0 -15
  37. package/lib/injections/pageHead.js +0 -33
  38. package/lib/injections/pageHeadTitle.d.ts +0 -11
  39. package/lib/injections/pageHeadTitle.js +0 -13
  40. package/lib/injections/pageLang.d.ts +0 -13
  41. package/lib/injections/pageLang.js +0 -16
  42. package/lib/injections/pagesData.d.ts +0 -6
  43. package/lib/injections/pagesData.js +0 -6
  44. package/lib/injections/routeLocale.d.ts +0 -10
  45. package/lib/injections/routeLocale.js +0 -14
  46. package/lib/injections/siteData.d.ts +0 -6
  47. package/lib/injections/siteData.js +0 -10
  48. package/lib/injections/siteLocaleData.d.ts +0 -12
  49. package/lib/injections/siteLocaleData.js +0 -17
  50. package/lib/injections/updateHead.d.ts +0 -15
  51. package/lib/injections/updateHead.js +0 -100
  52. package/lib/server.d.ts +0 -8
  53. package/lib/server.js +0 -10
  54. package/lib/types/clientAppEnhance.d.ts +0 -8
  55. package/lib/types/clientAppEnhance.js +0 -1
  56. package/lib/types/clientAppSetup.d.ts +0 -1
  57. package/lib/types/clientAppSetup.js +0 -1
  58. package/lib/types/index.d.ts +0 -7
  59. package/lib/types/index.js +0 -2
  60. package/lib/types/internal/clientAppEnhances.d.ts +0 -5
  61. package/lib/types/internal/clientAppRootComponents.d.ts +0 -5
  62. package/lib/types/internal/clientAppSetups.d.ts +0 -5
  63. package/lib/types/internal/layoutComponents.d.ts +0 -5
  64. package/lib/types/internal/pagesComponent.d.ts +0 -5
  65. package/lib/types/internal/pagesData.d.ts +0 -5
  66. package/lib/types/internal/pagesRoutes.d.ts +0 -5
  67. package/lib/types/internal/siteData.d.ts +0 -5
  68. package/lib/utils/defineClientAppEnhance.d.ts +0 -2
  69. package/lib/utils/defineClientAppEnhance.js +0 -1
  70. package/lib/utils/defineClientAppSetup.d.ts +0 -2
  71. package/lib/utils/defineClientAppSetup.js +0 -1
  72. package/lib/utils/index.d.ts +0 -3
  73. package/lib/utils/index.js +0 -3
  74. package/lib/utils/withBase.d.ts +0 -4
  75. package/lib/utils/withBase.js +0 -11
  76. package/templates/index.ssr.html +0 -12
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-present, Yuxi (Evan) You
3
+ Copyright (c) 2018-present, VuePress Community
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @vuepress/client
2
+
3
+ [![npm](https://badgen.net/npm/v/@vuepress/client/next)](https://www.npmjs.com/package/@vuepress/client)
4
+ [![license](https://badgen.net/github/license/vuepress/core)](https://github.com/vuepress/core/blob/main/LICENSE)
5
+
6
+ ## Documentation
7
+
8
+ https://v2.vuepress.vuejs.org
9
+
10
+ ## License
11
+
12
+ [MIT](https://github.com/vuepress/core/blob/main/LICENSE)
package/dist/app.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { C as CreateVueAppFunction } from './createVueAppFunction-YNGNKfE3.js';
2
+ import 'vue';
3
+ import 'vue-router';
4
+
5
+ declare const createVueApp: CreateVueAppFunction;
6
+
7
+ export { createVueApp };
package/dist/app.js ADDED
@@ -0,0 +1,353 @@
1
+ import {
2
+ ClientOnly,
3
+ Content,
4
+ layoutsSymbol,
5
+ pageDataSymbol,
6
+ pageFrontmatterSymbol,
7
+ pageHeadSymbol,
8
+ pageHeadTitleSymbol,
9
+ pageLangSymbol,
10
+ pageLayoutSymbol,
11
+ pagesData,
12
+ resolvers,
13
+ routeLocaleSymbol,
14
+ siteData,
15
+ siteLocaleDataSymbol,
16
+ updateHeadSymbol,
17
+ usePageHead,
18
+ usePageLang,
19
+ usePageLayout,
20
+ withBase
21
+ } from "./chunk-PEQEPZ75.js";
22
+
23
+ // src/app.ts
24
+ import { clientConfigs } from "@internal/clientConfigs";
25
+ import { createApp, createSSRApp, h as h2 } from "vue";
26
+ import { RouterView } from "vue-router";
27
+
28
+ // src/router.ts
29
+ import { pagesComponents } from "@internal/pagesComponents";
30
+ import { removeEndingSlash } from "@vuepress/shared";
31
+ import {
32
+ createMemoryHistory,
33
+ createRouter,
34
+ createWebHistory,
35
+ START_LOCATION
36
+ } from "vue-router";
37
+
38
+ // src/routes.ts
39
+ import { pagesRoutes } from "@internal/pagesRoutes";
40
+
41
+ // src/components/Vuepress.ts
42
+ import { defineComponent, h } from "vue";
43
+ var Vuepress = defineComponent({
44
+ name: "Vuepress",
45
+ setup() {
46
+ const layout = usePageLayout();
47
+ return () => h(layout.value);
48
+ }
49
+ });
50
+
51
+ // src/routes.ts
52
+ var createRoutes = () => pagesRoutes.reduce(
53
+ (result, [name, path, meta, redirects]) => {
54
+ result.push(
55
+ {
56
+ name,
57
+ path,
58
+ component: Vuepress,
59
+ meta
60
+ },
61
+ {
62
+ path: path.endsWith("/") ? (
63
+ // redirect from `/index.html` to `/`
64
+ path + "index.html"
65
+ ) : (
66
+ // redirect from `/foo` to `/foo.html`
67
+ path.substring(0, path.length - 5)
68
+ ),
69
+ redirect: path
70
+ },
71
+ ...redirects.map((item) => ({
72
+ path: item === ":md" ? (
73
+ // redirect from `/foo.md` to `/foo.html`
74
+ path.substring(0, path.length - 5) + ".md"
75
+ ) : item,
76
+ redirect: path
77
+ }))
78
+ );
79
+ return result;
80
+ },
81
+ [
82
+ {
83
+ name: "404",
84
+ path: "/:catchAll(.*)",
85
+ component: Vuepress
86
+ }
87
+ ]
88
+ );
89
+
90
+ // src/router.ts
91
+ var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
92
+ var createVueRouter = () => {
93
+ const router = createRouter({
94
+ // it might be an issue of vue-router that have to remove the ending slash
95
+ history: historyCreator(removeEndingSlash(__VUEPRESS_BASE__)),
96
+ routes: createRoutes(),
97
+ scrollBehavior: (to, from, savedPosition) => {
98
+ if (savedPosition)
99
+ return savedPosition;
100
+ if (to.hash)
101
+ return { el: to.hash };
102
+ return { top: 0 };
103
+ }
104
+ });
105
+ router.beforeResolve(async (to, from) => {
106
+ if (to.path !== from.path || from === START_LOCATION) {
107
+ ;
108
+ [to.meta._data] = await Promise.all([
109
+ resolvers.resolvePageData(to.name),
110
+ pagesComponents[to.name]?.__asyncLoader()
111
+ ]);
112
+ }
113
+ });
114
+ return router;
115
+ };
116
+
117
+ // src/setupGlobalComponents.ts
118
+ var setupGlobalComponents = (app) => {
119
+ app.component("ClientOnly", ClientOnly);
120
+ app.component("Content", Content);
121
+ };
122
+
123
+ // src/setupGlobalComputed.ts
124
+ import { computedWithControl } from "@vueuse/core";
125
+ import { computed } from "vue";
126
+ var setupGlobalComputed = (app, router, clientConfigs2) => {
127
+ const routePath = computed(() => router.currentRoute.value.path);
128
+ const pageData = computedWithControl(
129
+ routePath,
130
+ () => router.currentRoute.value.meta._data
131
+ );
132
+ if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
133
+ __VUE_HMR_RUNTIME__.updatePageData = (data) => {
134
+ pagesData.value[data.key] = () => Promise.resolve(data);
135
+ if (data.key === router.currentRoute.value.meta._data?.key) {
136
+ router.currentRoute.value.meta._data = data;
137
+ pageData.trigger();
138
+ }
139
+ };
140
+ }
141
+ const layouts = computed(() => resolvers.resolveLayouts(clientConfigs2));
142
+ const routeLocale = computed(
143
+ () => resolvers.resolveRouteLocale(siteData.value.locales, routePath.value)
144
+ );
145
+ const siteLocaleData = computed(
146
+ () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
147
+ );
148
+ const pageFrontmatter = computed(
149
+ () => resolvers.resolvePageFrontmatter(pageData.value)
150
+ );
151
+ const pageHeadTitle = computed(
152
+ () => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
153
+ );
154
+ const pageHead = computed(
155
+ () => resolvers.resolvePageHead(
156
+ pageHeadTitle.value,
157
+ pageFrontmatter.value,
158
+ siteLocaleData.value
159
+ )
160
+ );
161
+ const pageLang = computed(
162
+ () => resolvers.resolvePageLang(pageData.value, siteLocaleData.value)
163
+ );
164
+ const pageLayout = computed(
165
+ () => resolvers.resolvePageLayout(pageData.value, layouts.value)
166
+ );
167
+ app.provide(layoutsSymbol, layouts);
168
+ app.provide(pageDataSymbol, pageData);
169
+ app.provide(pageFrontmatterSymbol, pageFrontmatter);
170
+ app.provide(pageHeadTitleSymbol, pageHeadTitle);
171
+ app.provide(pageHeadSymbol, pageHead);
172
+ app.provide(pageLangSymbol, pageLang);
173
+ app.provide(pageLayoutSymbol, pageLayout);
174
+ app.provide(routeLocaleSymbol, routeLocale);
175
+ app.provide(siteLocaleDataSymbol, siteLocaleData);
176
+ Object.defineProperties(app.config.globalProperties, {
177
+ $frontmatter: { get: () => pageFrontmatter.value },
178
+ $head: { get: () => pageHead.value },
179
+ $headTitle: { get: () => pageHeadTitle.value },
180
+ $lang: { get: () => pageLang.value },
181
+ $page: { get: () => pageData.value },
182
+ $routeLocale: { get: () => routeLocale.value },
183
+ $site: { get: () => siteData.value },
184
+ $siteLocale: { get: () => siteLocaleData.value },
185
+ $withBase: { get: () => withBase }
186
+ });
187
+ return {
188
+ layouts,
189
+ pageData,
190
+ pageFrontmatter,
191
+ pageHead,
192
+ pageHeadTitle,
193
+ pageLang,
194
+ pageLayout,
195
+ routeLocale,
196
+ siteData,
197
+ siteLocaleData
198
+ };
199
+ };
200
+
201
+ // src/setupUpdateHead.ts
202
+ import { isPlainObject, isString } from "@vuepress/shared";
203
+ import { onMounted, provide, useSSRContext, watch } from "vue";
204
+ var setupUpdateHead = () => {
205
+ const head = usePageHead();
206
+ const lang = usePageLang();
207
+ if (__VUEPRESS_SSR__) {
208
+ const ssrContext = useSSRContext();
209
+ if (ssrContext) {
210
+ ssrContext.head = head.value;
211
+ ssrContext.lang = lang.value;
212
+ }
213
+ return;
214
+ }
215
+ let managedHeadElements = [];
216
+ const takeOverHeadElements = () => {
217
+ head.value.forEach((item) => {
218
+ const headElement = queryHeadElement(item);
219
+ if (headElement) {
220
+ managedHeadElements.push(headElement);
221
+ }
222
+ });
223
+ };
224
+ const generateHeadElements = () => {
225
+ const result = [];
226
+ head.value.forEach((item) => {
227
+ const headElement = createHeadElement(item);
228
+ if (headElement) {
229
+ result.push(headElement);
230
+ }
231
+ });
232
+ return result;
233
+ };
234
+ const updateHead = () => {
235
+ document.documentElement.lang = lang.value;
236
+ const newHeadElements = generateHeadElements();
237
+ managedHeadElements.forEach((oldEl, oldIndex) => {
238
+ const matchedIndex = newHeadElements.findIndex(
239
+ (newEl) => oldEl.isEqualNode(newEl)
240
+ );
241
+ if (matchedIndex === -1) {
242
+ oldEl.remove();
243
+ delete managedHeadElements[oldIndex];
244
+ } else {
245
+ newHeadElements.splice(matchedIndex, 1);
246
+ }
247
+ });
248
+ newHeadElements.forEach((el) => document.head.appendChild(el));
249
+ managedHeadElements = [
250
+ // filter out empty deleted items
251
+ ...managedHeadElements.filter((item) => !!item),
252
+ ...newHeadElements
253
+ ];
254
+ };
255
+ provide(updateHeadSymbol, updateHead);
256
+ onMounted(() => {
257
+ if (!__VUEPRESS_DEV__) {
258
+ takeOverHeadElements();
259
+ }
260
+ watch(head, updateHead, { immediate: __VUEPRESS_DEV__ });
261
+ });
262
+ };
263
+ var queryHeadElement = ([
264
+ tagName,
265
+ attrs,
266
+ content = ""
267
+ ]) => {
268
+ const attrsSelector = Object.entries(attrs).map(([key, value]) => {
269
+ if (isString(value)) {
270
+ return `[${key}=${JSON.stringify(value)}]`;
271
+ }
272
+ if (value === true) {
273
+ return `[${key}]`;
274
+ }
275
+ return "";
276
+ }).join("");
277
+ const selector = `head > ${tagName}${attrsSelector}`;
278
+ const headElements = Array.from(
279
+ document.querySelectorAll(selector)
280
+ );
281
+ const matchedHeadElement = headElements.find(
282
+ (item) => item.innerText === content
283
+ );
284
+ return matchedHeadElement || null;
285
+ };
286
+ var createHeadElement = ([
287
+ tagName,
288
+ attrs,
289
+ content
290
+ ]) => {
291
+ if (!isString(tagName)) {
292
+ return null;
293
+ }
294
+ const headElement = document.createElement(tagName);
295
+ if (isPlainObject(attrs)) {
296
+ Object.entries(attrs).forEach(([key, value]) => {
297
+ if (isString(value)) {
298
+ headElement.setAttribute(key, value);
299
+ } else if (value === true) {
300
+ headElement.setAttribute(key, "");
301
+ }
302
+ });
303
+ }
304
+ if (isString(content)) {
305
+ headElement.appendChild(document.createTextNode(content));
306
+ }
307
+ return headElement;
308
+ };
309
+
310
+ // src/app.ts
311
+ var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
312
+ var createVueApp = async () => {
313
+ const app = appCreator({
314
+ name: "VuepressApp",
315
+ setup() {
316
+ setupUpdateHead();
317
+ for (const clientConfig of clientConfigs) {
318
+ clientConfig.setup?.();
319
+ }
320
+ return () => [
321
+ h2(RouterView),
322
+ ...clientConfigs.flatMap(
323
+ ({ rootComponents = [] }) => rootComponents.map((component) => h2(component))
324
+ )
325
+ ];
326
+ }
327
+ });
328
+ const router = createVueRouter();
329
+ setupGlobalComponents(app);
330
+ const globalComputed = setupGlobalComputed(app, router, clientConfigs);
331
+ if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
332
+ const { setupDevtools } = await import("./setupDevtools-X4YFRK4B.js");
333
+ setupDevtools(app, globalComputed);
334
+ }
335
+ for (const clientConfig of clientConfigs) {
336
+ await clientConfig.enhance?.({ app, router, siteData });
337
+ }
338
+ app.use(router);
339
+ return {
340
+ app,
341
+ router
342
+ };
343
+ };
344
+ if (!__VUEPRESS_SSR__) {
345
+ createVueApp().then(({ app, router }) => {
346
+ router.isReady().then(() => {
347
+ app.mount("#app");
348
+ });
349
+ });
350
+ }
351
+ export {
352
+ createVueApp
353
+ };