@rspress/core 2.0.0-beta.3 → 2.0.0-beta.31

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.
@@ -0,0 +1,193 @@
1
+ import { workerData } from "node:worker_threads";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import { logger as logger_logger } from "@rspress/shared/logger";
4
+ import { createHead, transformHtmlTemplate } from "@unhead/react/server";
5
+ import picocolors_0 from "picocolors";
6
+ import "node:fs/promises";
7
+ import node_path from "node:path";
8
+ import { APPEARANCE_KEY, RSPRESS_TEMP_DIR } from "@rspress/shared";
9
+ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
10
+ return new Promise((resolve_, reject_)=>{
11
+ if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
12
+ if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
13
+ if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === 1 / 0)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
14
+ const result = [];
15
+ const errors = [];
16
+ const skippedIndexesMap = new Map();
17
+ let isRejected = false;
18
+ let isResolved = false;
19
+ let isIterableDone = false;
20
+ let resolvingCount = 0;
21
+ let currentIndex = 0;
22
+ const iterator = void 0 === iterable[Symbol.iterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
23
+ const signalListener = ()=>{
24
+ reject(signal.reason);
25
+ };
26
+ const cleanup = ()=>{
27
+ signal?.removeEventListener('abort', signalListener);
28
+ };
29
+ const resolve = (value)=>{
30
+ resolve_(value);
31
+ cleanup();
32
+ };
33
+ const reject = (reason)=>{
34
+ isRejected = true;
35
+ isResolved = true;
36
+ reject_(reason);
37
+ cleanup();
38
+ };
39
+ if (signal) {
40
+ if (signal.aborted) reject(signal.reason);
41
+ signal.addEventListener('abort', signalListener, {
42
+ once: true
43
+ });
44
+ }
45
+ const next = async ()=>{
46
+ if (isResolved) return;
47
+ const nextItem = await iterator.next();
48
+ const index = currentIndex;
49
+ currentIndex++;
50
+ if (nextItem.done) {
51
+ isIterableDone = true;
52
+ if (0 === resolvingCount && !isResolved) {
53
+ if (!stopOnError && errors.length > 0) return void reject(new AggregateError(errors));
54
+ isResolved = true;
55
+ if (0 === skippedIndexesMap.size) return void resolve(result);
56
+ const pureResult = [];
57
+ for (const [index, value] of result.entries())if (skippedIndexesMap.get(index) !== pMapSkip) pureResult.push(value);
58
+ resolve(pureResult);
59
+ }
60
+ return;
61
+ }
62
+ resolvingCount++;
63
+ (async ()=>{
64
+ try {
65
+ const element = await nextItem.value;
66
+ if (isResolved) return;
67
+ const value = await mapper(element, index);
68
+ if (value === pMapSkip) skippedIndexesMap.set(index, value);
69
+ result[index] = value;
70
+ resolvingCount--;
71
+ await next();
72
+ } catch (error) {
73
+ if (stopOnError) reject(error);
74
+ else {
75
+ errors.push(error);
76
+ resolvingCount--;
77
+ try {
78
+ await next();
79
+ } catch (error) {
80
+ reject(error);
81
+ }
82
+ }
83
+ }
84
+ })();
85
+ };
86
+ (async ()=>{
87
+ for(let index = 0; index < concurrency; index++){
88
+ try {
89
+ await next();
90
+ } catch (error) {
91
+ reject(error);
92
+ break;
93
+ }
94
+ if (isIterableDone || isRejected) break;
95
+ }
96
+ })();
97
+ });
98
+ }
99
+ const pMapSkip = Symbol('skip');
100
+ function hintSSGFailed() {
101
+ logger_logger.info(`[Rspress v2] \`ssg: true\` requires the source code to support SSR. If the code is not compatible to SSR, the build process will fail. You can try:
102
+ 1. Fix code to make it SSR-compatible.
103
+ 2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
104
+ }
105
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.31"}');
106
+ const RSPRESS_VERSION = package_namespaceObject.rE;
107
+ `{
108
+ const saved = localStorage.getItem('${APPEARANCE_KEY}')
109
+ const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
110
+ const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
111
+ document.documentElement.classList.toggle('dark', isDark)
112
+ document.documentElement.classList.toggle('rp-dark', isDark)
113
+ document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
114
+ }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
115
+ const dirname = node_path.dirname(fileURLToPath(new URL(import.meta.url)));
116
+ const PACKAGE_ROOT = node_path.join(dirname, '..');
117
+ node_path.join(PACKAGE_ROOT, 'index.html');
118
+ node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
119
+ node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
120
+ node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
121
+ const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
122
+ const HEAD_MARKER = '<!--<?- HEAD ?>-->';
123
+ const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
124
+ node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
125
+ async function renderConfigHead(head, route) {
126
+ if (!isRouteMeta(route)) return '';
127
+ if (!head || 0 === head.length) return '';
128
+ return head.map((head)=>{
129
+ if ('string' == typeof head) return head;
130
+ if ('function' == typeof head) {
131
+ const resultHead = head(route);
132
+ if (!resultHead) return '';
133
+ if ('string' == typeof resultHead) return resultHead;
134
+ return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
135
+ }
136
+ return `<${head[0]} ${renderAttrs(head[1])}>`;
137
+ }).join('');
138
+ }
139
+ async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '') {
140
+ const replacedHtmlTemplate = htmlTemplate.replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
141
+ await renderConfigHead(head, route)
142
+ ].join(''));
143
+ return replacedHtmlTemplate;
144
+ }
145
+ function renderAttrs(attrs) {
146
+ return Object.entries(attrs).map(([key, value])=>{
147
+ if ('boolean' == typeof value) return key;
148
+ if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
149
+ throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
150
+ }).join('');
151
+ }
152
+ function isRouteMeta(route) {
153
+ return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
154
+ }
155
+ async function renderPage(route, htmlTemplate, configHead, ssrBundlePath) {
156
+ let render;
157
+ try {
158
+ const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
159
+ render = await ssrExports.render;
160
+ } catch (e) {
161
+ if (e instanceof Error) {
162
+ logger_logger.error(`Failed to load SSG bundle: ${picocolors_0.yellow(ssrBundlePath)}: ${e.message}`);
163
+ logger_logger.debug(e);
164
+ hintSSGFailed();
165
+ }
166
+ throw e;
167
+ }
168
+ const head = createHead();
169
+ const { routePath } = route;
170
+ let appHtml = '';
171
+ if (render) try {
172
+ ({ appHtml } = await render(routePath, head));
173
+ } catch (e) {
174
+ if (e instanceof Error) {
175
+ logger_logger.error(`Page "${picocolors_0.yellow(routePath)}" SSG rendering failed.\n ${picocolors_0.gray(e.toString())}`);
176
+ throw e;
177
+ }
178
+ }
179
+ const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml);
180
+ const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
181
+ return html;
182
+ }
183
+ const params = workerData?.[1]?.params;
184
+ if (!params) throw new Error('SSG Worker Thread workerData params missing');
185
+ const { htmlTemplate: renderPageWorker_htmlTemplate, head: renderPageWorker_head, ssrBundlePath: renderPageWorker_ssrBundlePath } = params;
186
+ const exportWorkerGlueFn = async ({ routes })=>pMap(routes, async (route)=>{
187
+ const html = await renderPage(route, renderPageWorker_htmlTemplate, renderPageWorker_head, renderPageWorker_ssrBundlePath);
188
+ return html;
189
+ }, {
190
+ concurrency: 10
191
+ });
192
+ const renderPageWorker = exportWorkerGlueFn;
193
+ export { renderPageWorker as default };
@@ -1,4 +1 @@
1
- import 'virtual-global-styles';
2
- export declare function App({ helmetContext }: {
3
- helmetContext?: object;
4
- }): import("react/jsx-runtime").JSX.Element;
1
+ export declare function App(): import("react/jsx-runtime").JSX.Element;
@@ -1,18 +1,16 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__dr_pogodin_react_helmet_ecf718aa__ from "@dr.pogodin/react-helmet";
3
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
4
- import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
5
- import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
6
- import * as __WEBPACK_EXTERNAL_MODULE_virtual_global_components_43dbb356__ from "virtual-global-components";
7
- import "virtual-global-styles";
8
- import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
9
- function App({ helmetContext }) {
10
- const { setData: setPageData, data } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext);
11
- const { pathname, search } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
12
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { PageContext, useLocation } from "@rspress/runtime";
3
+ import { Layout } from "@theme";
4
+ import react, { useContext, useLayoutEffect } from "react";
5
+ import virtual_global_components from "virtual-global-components";
6
+ import { initPageData } from "./initPageData.js";
7
+ function App() {
8
+ const { setData: setPageData, data } = useContext(PageContext);
9
+ const { pathname, search } = useLocation();
10
+ useLayoutEffect(()=>{
13
11
  async function refetchData() {
14
12
  try {
15
- const pageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pathname);
13
+ const pageData = await initPageData(pathname);
16
14
  setPageData?.(pageData);
17
15
  } catch (e) {
18
16
  console.log(e);
@@ -23,24 +21,23 @@ function App({ helmetContext }) {
23
21
  pathname,
24
22
  setPageData
25
23
  ]);
26
- if (!data) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
27
- const frontmatter = data.page.frontmatter || {};
24
+ if (!data) return /*#__PURE__*/ jsx(Fragment, {});
25
+ const frontmatter = data.frontmatter || {};
28
26
  const GLOBAL_COMPONENTS_KEY = 'globalUIComponents';
29
27
  const query = new URLSearchParams(search);
30
28
  const hideGlobalUIComponents = false === frontmatter[GLOBAL_COMPONENTS_KEY] || "0" === query.get(GLOBAL_COMPONENTS_KEY);
31
- return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__dr_pogodin_react_helmet_ecf718aa__.HelmetProvider, {
32
- context: helmetContext,
29
+ return /*#__PURE__*/ jsxs(Fragment, {
33
30
  children: [
34
- /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Layout, {}),
35
- !hideGlobalUIComponents && __WEBPACK_EXTERNAL_MODULE_virtual_global_components_43dbb356__["default"].map((componentInfo, index)=>{
31
+ /*#__PURE__*/ jsx(Layout, {}),
32
+ !hideGlobalUIComponents && virtual_global_components.map((componentInfo, index)=>{
36
33
  if (Array.isArray(componentInfo)) {
37
34
  const [component, props] = componentInfo;
38
- return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(component, {
35
+ return /*#__PURE__*/ react.createElement(component, {
39
36
  key: index,
40
37
  ...props
41
38
  });
42
39
  }
43
- return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(componentInfo, {
40
+ return /*#__PURE__*/ react.createElement(componentInfo, {
44
41
  key: index
45
42
  });
46
43
  })
@@ -1,4 +1,4 @@
1
- import type { PageData } from '@rspress/shared';
1
+ import type { Page } from './initPageData';
2
2
  export declare function ClientApp({ initialPageData, }: {
3
- initialPageData?: PageData;
3
+ initialPageData?: Page;
4
4
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,29 +1,39 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
3
- import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
4
- import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
5
- import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { BrowserRouter, PageContext, ThemeContext, removeTrailingSlash, withBase } from "@rspress/runtime";
3
+ import { useThemeState } from "@theme";
4
+ import { UnheadProvider, createHead } from "@unhead/react/client";
5
+ import { useMemo, useState } from "react";
6
+ import { App } from "./App.js";
7
+ const head = createHead();
6
8
  function ClientApp({ initialPageData = null }) {
7
- const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
8
- const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
9
- return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
10
- value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
9
+ const [data, setData] = useState(initialPageData);
10
+ const [theme, setTheme] = useThemeState();
11
+ return /*#__PURE__*/ jsx(ThemeContext.Provider, {
12
+ value: useMemo(()=>({
11
13
  theme,
12
14
  setTheme
13
15
  }), [
14
16
  theme,
15
17
  setTheme
16
18
  ]),
17
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext.Provider, {
18
- value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
19
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
20
+ value: useMemo(()=>({
19
21
  data,
20
22
  setData
21
23
  }), [
22
24
  data,
23
25
  setData
24
26
  ]),
25
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.BrowserRouter, {
26
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.App, {})
27
+ children: /*#__PURE__*/ jsx(BrowserRouter, {
28
+ future: {
29
+ v7_relativeSplatPath: true,
30
+ v7_startTransition: true
31
+ },
32
+ basename: removeTrailingSlash(withBase('/')),
33
+ children: /*#__PURE__*/ jsx(UnheadProvider, {
34
+ head: head,
35
+ children: /*#__PURE__*/ jsx(App, {})
36
+ })
27
37
  })
28
38
  })
29
39
  });
@@ -1,13 +1,5 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
3
- async function renderInBrowser() {
4
- const container = document.getElementById('root');
5
- if (process.env.__REACT_GTE_18__) {
6
- const { createRoot } = await import("react-dom/client");
7
- createRoot(container).render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}));
8
- } else {
9
- const ReactDOM = await import("react-dom");
10
- ReactDOM.render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}), container);
11
- }
12
- }
13
- renderInBrowser();
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createRoot } from "react-dom/client";
3
+ import { ClientApp } from "./ClientApp.js";
4
+ const container = document.getElementById('root');
5
+ createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {}));
@@ -1,3 +1,3 @@
1
- import { type PageData } from '@rspress/shared';
2
- import 'virtual-global-styles';
3
- export declare function initPageData(routePath: string): Promise<PageData>;
1
+ import { type PageDataLegacy } from '@rspress/shared';
2
+ export type Page = PageDataLegacy['page'];
3
+ export declare function initPageData(routePath: string): Promise<Page>;
@@ -1,57 +1,51 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
3
- import "virtual-global-styles";
4
- import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
1
+ import { isEqualPath, pathnameToRouteService } from "@rspress/runtime";
2
+ import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
3
+ import { pageData } from "virtual-page-data";
4
+ import virtual_site_data from "virtual-site-data";
5
5
  async function initPageData(routePath) {
6
- const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
6
+ const matchedRoute = pathnameToRouteService(routePath);
7
7
  if (matchedRoute) {
8
8
  const mod = await matchedRoute.preload();
9
- const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
9
+ const pagePath = cleanUrl(matchedRoute.filePath);
10
10
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
11
- const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path)));
11
+ const extractPageInfo = pageData.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
12
12
  const encodedPagePath = encodeURIComponent(pagePath);
13
13
  const meta = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
14
- const { toc = [], title = '', frontmatter = {}, ...rest } = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
14
+ const { toc = [], title = '', frontmatter = {}, ...rest } = MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
15
15
  return {
16
- siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
17
- page: {
18
- ...rest,
19
- pagePath,
20
- ...extractPageInfo,
21
- pageType: frontmatter?.pageType || 'doc',
22
- title,
23
- frontmatter,
24
- toc
25
- }
16
+ ...rest,
17
+ pagePath,
18
+ ...extractPageInfo,
19
+ pageType: frontmatter?.pageType || 'doc',
20
+ title,
21
+ frontmatter,
22
+ toc
26
23
  };
27
24
  }
28
- let lang = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang || '';
29
- let version = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion?.default || '';
30
- if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang && 'undefined' != typeof window) {
31
- const path = location.pathname.replace(__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].base, '').split('/').slice(0, 2);
32
- if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.length) {
33
- const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.find(({ lang })=>path.includes(lang));
25
+ let lang = virtual_site_data.lang || '';
26
+ let version = virtual_site_data.multiVersion?.default || '';
27
+ if (virtual_site_data.lang && 'undefined' != typeof window) {
28
+ const path = window.location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
29
+ if (virtual_site_data.locales.length) {
30
+ const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
34
31
  if (result) lang = result.lang;
35
32
  }
36
- if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions) {
37
- const result = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion.versions.find((version)=>path.includes(version));
33
+ if (virtual_site_data.multiVersion.versions) {
34
+ const result = virtual_site_data.multiVersion.versions.find((version)=>path.includes(version));
38
35
  if (result) version = result;
39
36
  }
40
37
  }
41
38
  return {
42
- siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
43
- page: {
44
- pagePath: '',
45
- pageType: '404',
46
- routePath: '/404',
47
- lang,
48
- frontmatter: {},
49
- title: '404',
50
- toc: [],
51
- version,
52
- _filepath: '',
53
- _relativePath: ''
54
- }
39
+ pagePath: '',
40
+ pageType: '404',
41
+ routePath: '/404',
42
+ lang,
43
+ frontmatter: {},
44
+ title: '404',
45
+ toc: [],
46
+ version,
47
+ _filepath: '',
48
+ _relativePath: ''
55
49
  };
56
50
  }
57
51
  export { initPageData };
@@ -1,19 +1,20 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
3
- import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { removeBase } from "@rspress/runtime";
3
+ import { startTransition } from "react";
4
+ import { hydrateRoot } from "react-dom/client";
5
+ import { ClientApp } from "./ClientApp.js";
6
+ import { initPageData } from "./initPageData.js";
4
7
  async function renderInBrowser() {
5
8
  const container = document.getElementById('root');
6
- const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(window.location.pathname);
7
- if (process.env.__REACT_GTE_18__) {
8
- const { hydrateRoot } = await import("react-dom/client");
9
- hydrateRoot(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
9
+ const initialPageData = await initPageData(removeBase(window.location.pathname));
10
+ startTransition(()=>{
11
+ hydrateRoot(container, /*#__PURE__*/ jsx(ClientApp, {
10
12
  initialPageData: initialPageData
11
- }));
12
- } else {
13
- const ReactDOM = await import("react-dom");
14
- ReactDOM.hydrate(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
15
- initialPageData: initialPageData
16
- }), container);
17
- }
13
+ }), {
14
+ onRecoverableError (error, errorInfo) {
15
+ if (error instanceof Error) console.warn('hydrateRoot recoverable error:', error, errorInfo);
16
+ }
17
+ });
18
+ });
18
19
  }
19
20
  renderInBrowser();
@@ -1,6 +1,5 @@
1
- import type { PageData } from '@rspress/shared';
2
- export declare function render(pagePath: string, helmetContext: object): Promise<{
1
+ import { type Unhead } from '@unhead/react/server';
2
+ export declare function render(routePath: string, head: Unhead): Promise<{
3
3
  appHtml: string;
4
- pageData: PageData;
5
4
  }>;
6
- export { routes } from 'virtual-routes-ssr';
5
+ export { routes } from 'virtual-routes';
@@ -1,33 +1,55 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
3
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_server_673c713a__ from "@rspress/runtime/server";
4
- import * as __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__ from "react-dom/server";
5
- import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
6
- import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
7
- import * as __WEBPACK_EXTERNAL_MODULE_virtual_routes_ssr_f802e6e5__ from "virtual-routes-ssr";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { PassThrough } from "node:stream";
3
+ import { text as consumers_text } from "node:stream/consumers";
4
+ import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/runtime";
5
+ import { StaticRouter } from "@rspress/runtime/server";
6
+ import { UnheadProvider } from "@unhead/react/server";
7
+ import { renderToPipeableStream } from "react-dom/server";
8
+ import { App } from "./App.js";
9
+ import { initPageData } from "./initPageData.js";
10
+ import { routes } from "virtual-routes";
8
11
  const DEFAULT_THEME = 'light';
9
- async function render(pagePath, helmetContext) {
10
- const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pagePath);
11
- const appHtml = (0, __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__.renderToString)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
12
+ async function preloadRoute(pathname) {
13
+ const route = pathnameToRouteService(pathname);
14
+ await route?.preload();
15
+ }
16
+ function renderToHtml(app) {
17
+ return new Promise((resolve, reject)=>{
18
+ const passThrough = new PassThrough();
19
+ const { pipe } = renderToPipeableStream(app, {
20
+ onError (error) {
21
+ reject(error);
22
+ },
23
+ onAllReady () {
24
+ pipe(passThrough);
25
+ consumers_text(passThrough).then(resolve, reject);
26
+ }
27
+ });
28
+ });
29
+ }
30
+ async function render(routePath, head) {
31
+ const initialPageData = await initPageData(routePath);
32
+ await preloadRoute(routePath);
33
+ const appHtml = await renderToHtml(/*#__PURE__*/ jsx(ThemeContext.Provider, {
12
34
  value: {
13
35
  theme: DEFAULT_THEME
14
36
  },
15
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext.Provider, {
37
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
16
38
  value: {
17
39
  data: initialPageData
18
40
  },
19
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_server_673c713a__.StaticRouter, {
20
- location: pagePath,
21
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.App, {
22
- helmetContext: helmetContext
41
+ children: /*#__PURE__*/ jsx(StaticRouter, {
42
+ location: withBase(routePath),
43
+ basename: removeTrailingSlash(withBase('/')),
44
+ children: /*#__PURE__*/ jsx(UnheadProvider, {
45
+ value: head,
46
+ children: /*#__PURE__*/ jsx(App, {})
23
47
  })
24
48
  })
25
49
  })
26
50
  }));
27
51
  return {
28
- appHtml,
29
- pageData: initialPageData
52
+ appHtml
30
53
  };
31
54
  }
32
- var __webpack_exports__routes = __WEBPACK_EXTERNAL_MODULE_virtual_routes_ssr_f802e6e5__.routes;
33
- export { render, __webpack_exports__routes as routes };
55
+ export { render, routes };
@@ -0,0 +1,11 @@
1
+ import { isExternalUrl } from '@rspress/shared';
2
+ import { normalizeHref } from '@rspress/shared';
3
+
4
+ export { isExternalUrl }
5
+
6
+ export { normalizeHref }
7
+
8
+
9
+ export * from "@rspress/runtime";
10
+
11
+ export { }
@@ -0,0 +1,3 @@
1
+ import { isExternalUrl, normalizeHref } from "@rspress/shared";
2
+ export * from "@rspress/runtime";
3
+ export { isExternalUrl, normalizeHref };
@@ -0,0 +1,38 @@
1
+ import type { ShikiTransformer } from 'shiki';
2
+
3
+ declare interface ITransformerLineNumberOptions {
4
+ classActivePre?: string;
5
+ classActiveLine?: string;
6
+ }
7
+
8
+ export declare const SHIKI_TRANSFORMER_ADD_TITLE = "shiki-transformer:add-title";
9
+
10
+ export declare const SHIKI_TRANSFORMER_LINE_NUMBER = "shiki-transformer:line-number";
11
+
12
+ export declare const SHIKI_TRANSFORMER_META_HIGHLIGHT = "shiki-transformer:compatible-meta-highlight";
13
+
14
+ export declare function transformerAddTitle(): ShikiTransformer;
15
+
16
+ /**
17
+ * Allow using `{1,3-5}` in the code snippet meta to mark highlighted lines.
18
+ * @deprecated This is a workaround when migrating to Rspress 2.0, you should migrate to `import { transformerNotationHighlight } from '@shikijs/transformers'` instead.
19
+ */
20
+ export declare function transformerCompatibleMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer;
21
+
22
+ export declare function transformerLineNumber(options?: ITransformerLineNumberOptions): ShikiTransformer;
23
+
24
+ declare interface TransformerMetaHighlightOptions {
25
+ /**
26
+ * Class for highlighted lines
27
+ *
28
+ * @default 'highlighted'
29
+ */
30
+ classActiveLine?: string;
31
+ /**
32
+ *
33
+ * @default 'has-highlighted'
34
+ */
35
+ classActivePre?: string;
36
+ }
37
+
38
+ export { }