@rspress/core 2.0.7 → 2.0.9

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 (107) hide show
  1. package/dist/0~execa.js +32 -41
  2. package/dist/0~rslib-runtime.js +38 -0
  3. package/dist/0~tinypool.js +828 -0
  4. package/dist/{8311.js → 1688.js} +1 -7
  5. package/dist/{7397.js → 2240.js} +4 -2
  6. package/dist/{1361.js → 3294.js} +1 -1
  7. package/dist/{1965.js → 3425.js} +0 -1
  8. package/dist/740.js +2470 -0
  9. package/dist/8006.js +77 -0
  10. package/dist/8857.js +4827 -0
  11. package/dist/8857.js.LICENSE.txt +41 -0
  12. package/dist/cli/index.js +7 -3
  13. package/dist/config/loadConfigFile.js +1 -1
  14. package/dist/eject-theme/components/CodeBlock/index.scss +4 -0
  15. package/dist/eject-theme/components/CodeBlock/index.tsx +14 -6
  16. package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.scss +1 -1
  17. package/dist/eject-theme/components/CodeButtonGroup/index.scss +1 -1
  18. package/dist/eject-theme/components/DocContent/doc.scss +2 -0
  19. package/dist/eject-theme/components/FallbackHeading/index.tsx +1 -1
  20. package/dist/eject-theme/components/Link/useLinkNavigate.ts +4 -1
  21. package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +3 -3
  22. package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -1
  23. package/dist/eject-theme/components/Steps/index.scss +32 -13
  24. package/dist/node/PluginDriver.js +2 -2
  25. package/dist/node/auto-nav-sidebar/index.js +2 -2
  26. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  27. package/dist/node/auto-nav-sidebar/normalize.js +9 -5
  28. package/dist/node/auto-nav-sidebar/utils.js +8 -2
  29. package/dist/node/auto-nav-sidebar/walk.js +2 -8
  30. package/dist/node/constants.js +1 -1
  31. package/dist/node/eject.js +14 -8
  32. package/dist/node/initRsbuild.js +6 -6
  33. package/dist/node/logger/hint.js +9 -6
  34. package/dist/node/mdx/options.js +15 -4
  35. package/dist/node/mdx/processor.js +1 -1
  36. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  37. package/dist/node/mdx/rehypePlugins/headerAnchor.js +3 -2
  38. package/dist/node/mdx/rehypePlugins/shiki.d.ts +4 -1
  39. package/dist/node/mdx/rehypePlugins/shiki.js +5 -3
  40. package/dist/node/mdx/rehypePlugins/transformers/add-fold.d.ts +7 -1
  41. package/dist/node/mdx/rehypePlugins/transformers/add-fold.js +23 -6
  42. package/dist/node/mdx/rehypePlugins/transformers/index.js +6 -6
  43. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  44. package/dist/node/mdx/remarkPlugins/containerSyntax.js +7 -1
  45. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +6 -2
  46. package/dist/node/mdx/remarkPlugins/image.d.ts +7 -2
  47. package/dist/node/mdx/remarkPlugins/image.js +51 -2
  48. package/dist/node/mdx/remarkPlugins/link.js +7 -3
  49. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  50. package/dist/node/route/RoutePage.js +1 -1
  51. package/dist/node/route/RouteService.js +1 -1
  52. package/dist/node/route/extractPageData.js +77 -27
  53. package/dist/node/route/normalizeRoutePath.js +1 -1
  54. package/dist/node/runtimeModule/i18n.js +10 -6
  55. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  56. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  57. package/dist/node/runtimeModule/searchHooks.js +1 -1
  58. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  59. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  60. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  61. package/dist/node/serve.js +1 -1
  62. package/dist/node/ssg/renderPage.js +8 -4
  63. package/dist/node/ssg/renderPageWorker.js +1 -1
  64. package/dist/node/ssg/renderPages.js +9 -5
  65. package/dist/node/ssg/rsbuildPluginSSG.js +20 -7
  66. package/dist/node/ssg/ssgEnv.js +1 -1
  67. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  68. package/dist/node/ssg-md/llms/llmsTxt.js +3 -2
  69. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  70. package/dist/node/ssg-md/renderPage.js +8 -4
  71. package/dist/node/ssg-md/renderPages.js +7 -3
  72. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  73. package/dist/node/utils/checkLanguageParity.js +1 -1
  74. package/dist/node/utils/createHash.js +1 -1
  75. package/dist/node/utils/error.js +5 -2
  76. package/dist/node/utils/flattenMdxContent.js +3 -2
  77. package/dist/node/utils/fs.js +1 -1
  78. package/dist/node/utils/getPageKey.js +1 -1
  79. package/dist/node/utils/normalizePath.js +3 -2
  80. package/dist/node/utils/reactAlias.js +7 -3
  81. package/dist/runtime/App.js +4 -1
  82. package/dist/runtime/hooks/useWindowSize.test.js +10 -10
  83. package/dist/runtime/index.d.ts +2 -1
  84. package/dist/runtime/index.js +2 -1
  85. package/dist/runtime/initPageData.d.ts +3 -0
  86. package/dist/runtime/initPageData.js +37 -2
  87. package/dist/runtime/ssrClientEntry.js +4 -2
  88. package/dist/theme/assets/success.js +1 -1
  89. package/dist/theme/assets/wrapped.js +1 -1
  90. package/dist/theme/components/CodeBlock/index.css +4 -0
  91. package/dist/theme/components/CodeBlock/index.d.ts +0 -3
  92. package/dist/theme/components/CodeBlock/index.js +8 -3
  93. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.css +3 -3
  94. package/dist/theme/components/CodeButtonGroup/index.css +3 -3
  95. package/dist/theme/components/DocContent/doc.css +1 -0
  96. package/dist/theme/components/FallbackHeading/index.js +1 -1
  97. package/dist/theme/components/Link/useLinkNavigate.js +3 -2
  98. package/dist/theme/components/Llms/LlmsCopyButton.css +9 -9
  99. package/dist/theme/components/Llms/LlmsViewOptions.css +2 -2
  100. package/dist/theme/components/Search/SearchPanel.js +1 -1
  101. package/dist/theme/components/Steps/index.css +23 -12
  102. package/dist/theme/logic/useThemeState.js +1 -1
  103. package/package.json +14 -17
  104. package/dist/4454.js +0 -8
  105. package/dist/4524.js +0 -71
  106. package/dist/8885.js +0 -4
  107. package/dist/rslib-runtime.js +0 -18
@@ -1,4 +1,4 @@
1
- import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../4524.js";
1
+ import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../740.js";
2
2
  import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  const rsbuildPluginSSG = ({ routeService, config })=>({
@@ -7,7 +7,19 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
7
7
  api.onBeforeBuild(()=>{
8
8
  let htmlTemplate = '';
9
9
  let hasError = false;
10
+ const missingIndexHtmlMessage = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
10
11
  const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
12
+ let settled = false;
13
+ const resolveOnce = ()=>{
14
+ if (settled) return;
15
+ settled = true;
16
+ resolve();
17
+ };
18
+ const rejectOnce = ()=>{
19
+ if (settled) return;
20
+ settled = true;
21
+ reject(new Error(missingIndexHtmlMessage));
22
+ };
11
23
  api.processAssets({
12
24
  stage: 'report',
13
25
  environments: [
@@ -16,20 +28,20 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
16
28
  }, ({ assets, compilation })=>{
17
29
  if (compilation.errors.length > 0) {
18
30
  hasError = true;
31
+ resolveOnce();
19
32
  return;
20
33
  }
21
34
  for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
22
35
  htmlTemplate = assetSource.source().toString();
23
36
  compilation.deleteAsset(assetName);
24
- resolve();
25
- break;
37
+ resolveOnce();
38
+ return;
26
39
  }
27
- reject();
40
+ rejectOnce();
28
41
  });
29
42
  }).catch(()=>{
30
- const message = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
31
- logger.error(message);
32
- const error = new Error(message);
43
+ logger.error(missingIndexHtmlMessage);
44
+ const error = new Error(missingIndexHtmlMessage);
33
45
  throw error;
34
46
  });
35
47
  api.processAssets({
@@ -60,6 +72,7 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
60
72
  }
61
73
  }));
62
74
  await indexHtmlEmittedInWeb;
75
+ if (hasError) return;
63
76
  await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset);
64
77
  if (!isDebugMode()) await rm(ssgFolderPath, {
65
78
  recursive: true
@@ -1,5 +1,5 @@
1
1
  /*! LICENSE: ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../4524.js";
2
+ import { node_os } from "../../740.js";
3
3
  /**
4
4
  * these codes are copied from
5
5
  * @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
@@ -1,4 +1,4 @@
1
- import { matchPath, getSidebarDataGroup } from "../../../4524.js";
1
+ import { matchPath, getSidebarDataGroup } from "../../../740.js";
2
2
  import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
3
3
  async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
4
4
  const base = config.base ?? '/';
@@ -1,4 +1,4 @@
1
- import { normalizeHref, logger, withBase } from "../../../4524.js";
1
+ import { normalizeHref, logger, withBase } from "../../../740.js";
2
2
  import { extractInfoFromFrontmatterWithAbsolutePath } from "../../auto-nav-sidebar/utils.js";
3
3
  function routePathToMdPath(routePath, base) {
4
4
  let url = routePath;
@@ -75,4 +75,5 @@ url: ${routePathToMdPath(routePath, base)}
75
75
  }
76
76
  return lines.join('\n');
77
77
  }
78
- export { generateLlmsFullTxt, generateLlmsTxt };
78
+ var llmsTxt_routePathToMdPath = void 0;
79
+ export { generateLlmsFullTxt, generateLlmsTxt, llmsTxt_routePathToMdPath as routePathToMdPath };
@@ -1,4 +1,4 @@
1
- import { unified, visit, remark_gfm, remark_mdx, remark_stringify } from "../../7397.js";
1
+ import { unified, visit, remark_gfm, remark_mdx, remark_stringify } from "../../2240.js";
2
2
  function remarkSplitMdx(options = {}) {
3
3
  return (tree)=>{
4
4
  const newChildren = [];
@@ -1,5 +1,9 @@
1
- import { createHead, logger, pathToFileURL, picocolors } from "../../4524.js";
1
+ import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
+ import "../../8006.js";
3
+ import { createHead, pathToFileURL, logger } from "../../740.js";
2
4
  import { hintSSGFailed } from "../logger/hint.js";
5
+ const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
+ var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
3
7
  async function renderPage(route, ssrBundlePath) {
4
8
  let render;
5
9
  try {
@@ -8,7 +12,7 @@ async function renderPage(route, ssrBundlePath) {
8
12
  render = ssrExports.render;
9
13
  } catch (e) {
10
14
  if (e instanceof Error) {
11
- logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
15
+ logger.error(`Failed to load SSG bundle: ${picocolors_default().yellow(ssrBundlePath)}: ${e.message}`);
12
16
  logger.debug(e);
13
17
  hintSSGFailed();
14
18
  }
@@ -21,8 +25,8 @@ async function renderPage(route, ssrBundlePath) {
21
25
  ({ appMd } = await render(routePath, head));
22
26
  } catch (e) {
23
27
  if (e instanceof Error) {
24
- logger.error(`Page "${picocolors.yellow(routePath)}" SSG-MD rendering failed.
25
- ${absolutePath ? picocolors.gray(` File: ${absolutePath}\n`) : ''} ${picocolors.gray(e.toString())}`);
28
+ logger.error(`Page "${picocolors_default().yellow(routePath)}" SSG-MD rendering failed.
29
+ ${absolutePath ? picocolors_default().gray(` File: ${absolutePath}\n`) : ''} ${picocolors_default().gray(e.toString())}`);
26
30
  throw e;
27
31
  }
28
32
  }
@@ -1,7 +1,11 @@
1
- import { logger, picocolors } from "../../4524.js";
2
- import { pMap } from "../../8311.js";
1
+ import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
+ import "../../8006.js";
3
+ import { logger } from "../../740.js";
4
+ import { pMap } from "../../1688.js";
3
5
  import { renderPage } from "./renderPage.js";
4
6
  import { SSGConcurrency } from "../ssg/ssgEnv.js";
7
+ const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
8
+ var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
5
9
  const routePage2MdFilename = (routePath)=>{
6
10
  let fileName = routePath;
7
11
  fileName = fileName.endsWith('/') ? `${routePath}index.md` : `${routePath}.md`;
@@ -21,7 +25,7 @@ async function renderPages(routeService, ssrBundlePath, emitAsset) {
21
25
  concurrency: SSGConcurrency()
22
26
  });
23
27
  const totalTime = Date.now() - startTime;
24
- logger.success(`Markdown rendered in ${picocolors.yellow(totalTime)} ms.`);
28
+ logger.success(`Markdown rendered in ${picocolors_default().yellow(totalTime)} ms.`);
25
29
  return result;
26
30
  }
27
31
  export { renderPages };
@@ -1,4 +1,4 @@
1
- import { writeFile, mkdir, rm, join, isDebugMode } from "../../4524.js";
1
+ import { writeFile, mkdir, rm, join, isDebugMode } from "../../740.js";
2
2
  import { NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  import { emitLlmsTxt } from "./llms/emitLlmsTxt.js";
@@ -1,4 +1,4 @@
1
- import { node_path, logger, promises } from "../../4524.js";
1
+ import { node_path, logger, promises } from "../../740.js";
2
2
  import { createError } from "./error.js";
3
3
  function normalizePath(filePath) {
4
4
  return filePath.split(node_path.sep).join('/');
@@ -1,4 +1,4 @@
1
- import { createHash as external_node_crypto_createHash } from "../../4524.js";
1
+ import { createHash as external_node_crypto_createHash } from "../../740.js";
2
2
  function createHash(str) {
3
3
  return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, 8);
4
4
  }
@@ -1,9 +1,12 @@
1
- import { picocolors } from "../../8885.js";
1
+ import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
+ import "../../8006.js";
3
+ const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
4
+ var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
2
5
  function createError(message, maxStackLines = 5) {
3
6
  const error = new Error(message);
4
7
  if (error.stack) {
5
8
  const lines = error.stack.split('\n');
6
- if (lines.length > maxStackLines + 1) error.stack = `${lines.slice(0, maxStackLines + 1).map((line)=>picocolors.gray(line)).join('\n')}\n ${picocolors.gray('... (truncated)')}`;
9
+ if (lines.length > maxStackLines + 1) error.stack = `${lines.slice(0, maxStackLines + 1).map((line)=>picocolors_default().gray(line)).join('\n')}\n ${picocolors_default().gray('... (truncated)')}`;
7
10
  }
8
11
  return error;
9
12
  }
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../4524.js";
1
+ import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../740.js";
2
2
  import { createError } from "./error.js";
3
3
  import { importStatementRegex } from "../constants.js";
4
4
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -68,4 +68,5 @@ async function flattenMdxContent(content, basePath, alias) {
68
68
  deps
69
69
  };
70
70
  }
71
- export { flattenMdxContent };
71
+ var flattenMdxContent_resolveDepPath = void 0;
72
+ export { flattenMdxContent, flattenMdxContent_resolveDepPath as resolveDepPath };
@@ -1,4 +1,4 @@
1
- import { promises } from "../../8885.js";
1
+ import { promises } from "../../8006.js";
2
2
  async function pathExists(path) {
3
3
  try {
4
4
  await promises.access(path);
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../4524.js";
1
+ import { removeLeadingSlash } from "../../740.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,4 +1,4 @@
1
- import { node_os, node_path } from "../../1361.js";
1
+ import { node_os, node_path } from "../../3294.js";
2
2
  const isWindows = 'win32' === node_os.platform();
3
3
  function slash(p) {
4
4
  return p.replace(/\\/g, '/');
@@ -6,4 +6,5 @@ function slash(p) {
6
6
  function normalizePath(id) {
7
7
  return node_path.posix.normalize(isWindows ? slash(id) : id);
8
8
  }
9
- export { normalizePath, slash };
9
+ var normalizePath_isWindows = void 0;
10
+ export { normalizePath, normalizePath_isWindows as isWindows, slash };
@@ -1,7 +1,11 @@
1
- import { node_path, core_rspack, logger, picocolors } from "../../4524.js";
1
+ import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
+ import "../../8006.js";
3
+ import { node_path, core_rspack, logger } from "../../740.js";
2
4
  import { pathExists, readJson } from "./fs.js";
3
5
  import { PACKAGE_ROOT } from "../constants.js";
4
6
  import { hintReactVersion } from "../logger/hint.js";
7
+ const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
8
+ var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
5
9
  const Resolver = core_rspack.experiments.resolver.ResolverFactory;
6
10
  async function detectPackageMajorVersion(name) {
7
11
  const cwd = process.cwd();
@@ -77,7 +81,7 @@ async function resolveReactAlias(isSSR) {
77
81
  alias[lib] = resolved.path;
78
82
  } catch (e) {
79
83
  if (e instanceof Error) {
80
- logger.warn(`${lib} not found: \n ${picocolors.gray(e.toString())}`);
84
+ logger.warn(`${lib} not found: \n ${picocolors_default().gray(e.toString())}`);
81
85
  hintReactVersion();
82
86
  }
83
87
  }
@@ -88,7 +92,7 @@ async function resolveReactRenderToMarkdownAlias() {
88
92
  const hasInstalled = await detectPackageMajorVersion('react-render-to-markdown');
89
93
  if (!hasInstalled) {
90
94
  const reactMajorVersion = await detectPackageMajorVersion('react');
91
- if (reactMajorVersion && reactMajorVersion < 19) logger.warn(`You are using React ${reactMajorVersion} with \`llms: true\`. Please install \`react-render-to-markdown\` to ensure compatibility.\n\nAdd the following to your ${picocolors.greenBright('package.json')}:\n\n` + picocolors.greenBright(` "dependencies": {\n "react": "^18.3.1",\n "react-dom": "^18.3.1",\n "react-render-to-markdown": "^18.3.1"\n }\n`));
95
+ if (reactMajorVersion && reactMajorVersion < 19) logger.warn(`You are using React ${reactMajorVersion} with \`llms: true\`. Please install \`react-render-to-markdown\` to ensure compatibility.\n\nAdd the following to your ${picocolors_default().greenBright('package.json')}:\n\n` + picocolors_default().greenBright(` "dependencies": {\n "react": "^18.3.1",\n "react-dom": "^18.3.1",\n "react-render-to-markdown": "^18.3.1"\n }\n`));
92
96
  return {};
93
97
  }
94
98
  const alias = {};
@@ -3,14 +3,17 @@ import { PageContext, useLocation } from "@rspress/core/runtime";
3
3
  import { Layout, Root } from "@theme";
4
4
  import react, { useContext, useLayoutEffect } from "react";
5
5
  import virtual_global_components from "virtual-global-components";
6
- import { initPageData } from "./initPageData.js";
6
+ import { consumeCachedPageData, initPageData, setCurrentPageData } from "./initPageData.js";
7
7
  function App() {
8
8
  const { setData: setPageData, data } = useContext(PageContext);
9
9
  const { pathname, search } = useLocation();
10
10
  useLayoutEffect(()=>{
11
+ const cached = consumeCachedPageData(pathname);
12
+ if (cached) return void setPageData?.(cached);
11
13
  async function refetchData() {
12
14
  try {
13
15
  const pageData = await initPageData(pathname);
16
+ setCurrentPageData(pathname, pageData);
14
17
  setPageData?.(pageData);
15
18
  } catch (e) {
16
19
  console.log(e);
@@ -1,29 +1,29 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
1
  import { describe, expect, it } from "@rstest/core";
2
+ import * as __rspack_external_node_fs_5ea92f0c from "node:fs";
3
+ import * as __rspack_external_node_path_c5b9b54f from "node:path";
4
4
  describe('useWindowSize', ()=>{
5
5
  it('should have debounce implementation with RESIZE_DEBOUNCE_MS constant', ()=>{
6
- const filePath = join(__dirname, 'useWindowSize.ts');
7
- const fileContent = readFileSync(filePath, 'utf-8');
6
+ const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
7
+ const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
8
8
  expect(fileContent).toContain('const RESIZE_DEBOUNCE_MS = 150');
9
9
  expect(fileContent).toContain('setTimeout');
10
10
  expect(fileContent).toContain('RESIZE_DEBOUNCE_MS');
11
11
  });
12
12
  it('should clear timeout with conditional check', ()=>{
13
- const filePath = join(__dirname, 'useWindowSize.ts');
14
- const fileContent = readFileSync(filePath, 'utf-8');
13
+ const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
14
+ const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
15
15
  expect(fileContent).toContain('if (timeoutId) clearTimeout(timeoutId)');
16
16
  expect(fileContent).not.toContain('clearTimeout(timeoutId!)');
17
17
  });
18
18
  it('should register and cleanup resize event listener', ()=>{
19
- const filePath = join(__dirname, 'useWindowSize.ts');
20
- const fileContent = readFileSync(filePath, 'utf-8');
19
+ const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
20
+ const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
21
21
  expect(fileContent).toContain("addEventListener('resize'");
22
22
  expect(fileContent).toContain("removeEventListener('resize'");
23
23
  });
24
24
  it('should set initial size immediately', ()=>{
25
- const filePath = join(__dirname, 'useWindowSize.ts');
26
- const fileContent = readFileSync(filePath, 'utf-8');
25
+ const filePath = __rspack_external_node_path_c5b9b54f.join(__dirname, 'useWindowSize.ts');
26
+ const fileContent = __rspack_external_node_fs_5ea92f0c.readFileSync(filePath, 'utf-8');
27
27
  const setStateMatch = fileContent.match(/setSize\(\{[^}]+\}\)/g);
28
28
  expect(setStateMatch).toBeTruthy();
29
29
  expect(setStateMatch?.length).toBeGreaterThanOrEqual(2);
@@ -1,5 +1,5 @@
1
1
  export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref, } from '@rspress/shared';
2
- export { Head } from '@unhead/react';
2
+ export { Head, useHead } from '@unhead/react';
3
3
  export * from 'react-router-dom';
4
4
  export { Content } from './Content.js';
5
5
  export { useActiveMatcher } from './hooks/useActiveMatcher.js';
@@ -16,6 +16,7 @@ export { getSidebarDataGroup, useSidebar, useSidebarDynamic, } from './hooks/use
16
16
  export { useSite } from './hooks/useSite.js';
17
17
  export { useVersion } from './hooks/useVersion.js';
18
18
  export { useWindowSize } from './hooks/useWindowSize.js';
19
+ export { initPageData, warmPageData } from './initPageData.js';
19
20
  export { NoSSR } from './NoSSR.js';
20
21
  export { isActive, pathnameToRouteService, preloadLink } from './route.js';
21
22
  export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, } from './utils.js';
@@ -1,6 +1,6 @@
1
1
  export * from "react-router-dom";
2
2
  export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
3
- export { Head } from "@unhead/react";
3
+ export { Head, useHead } from "@unhead/react";
4
4
  export { Content } from "./Content.js";
5
5
  export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
6
6
  export { ThemeContext, useDark } from "./hooks/useDark.js";
@@ -16,6 +16,7 @@ export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useS
16
16
  export { useSite } from "./hooks/useSite.js";
17
17
  export { useVersion } from "./hooks/useVersion.js";
18
18
  export { useWindowSize } from "./hooks/useWindowSize.js";
19
+ export { initPageData, warmPageData } from "./initPageData.js";
19
20
  export { NoSSR } from "./NoSSR.js";
20
21
  export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
21
22
  export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase } from "./utils.js";
@@ -1,3 +1,6 @@
1
1
  import { type PageDataLegacy } from '@rspress/shared';
2
2
  export type Page = PageDataLegacy['page'];
3
+ export declare function warmPageData(routePath: string, data: Page): void;
4
+ export declare function consumeCachedPageData(routePath: string): Page | undefined;
5
+ export declare function setCurrentPageData(routePath: string, data: Page): void;
3
6
  export declare function initPageData(routePath: string): Promise<Page>;
@@ -1,7 +1,42 @@
1
- import { isEqualPath, pathnameToRouteService } from "@rspress/core/runtime";
2
1
  import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
3
2
  import { pageData } from "virtual-page-data";
4
3
  import virtual_site_data from "virtual-site-data";
4
+ import { pathnameToRouteService } from "./route.js";
5
+ import { isEqualPath } from "./utils.js";
6
+ const slots = [
7
+ void 0,
8
+ void 0,
9
+ void 0
10
+ ];
11
+ function warmPageData(routePath, data) {
12
+ slots[0] = {
13
+ routePath,
14
+ data
15
+ };
16
+ }
17
+ function consumeCachedPageData(routePath) {
18
+ if (slots[0]?.routePath === routePath) {
19
+ const data = slots[0].data;
20
+ slots[2] = slots[1];
21
+ slots[1] = slots[0];
22
+ slots[0] = void 0;
23
+ return data;
24
+ }
25
+ if (slots[2]?.routePath === routePath) {
26
+ const data = slots[2].data;
27
+ slots[0] = slots[1];
28
+ slots[1] = slots[2];
29
+ slots[2] = void 0;
30
+ return data;
31
+ }
32
+ }
33
+ function setCurrentPageData(routePath, data) {
34
+ slots[2] = slots[1];
35
+ slots[1] = {
36
+ routePath,
37
+ data
38
+ };
39
+ }
5
40
  async function initPageData(routePath) {
6
41
  const matchedRoute = pathnameToRouteService(routePath);
7
42
  if (matchedRoute) {
@@ -48,4 +83,4 @@ async function initPageData(routePath) {
48
83
  _relativePath: ''
49
84
  };
50
85
  }
51
- export { initPageData };
86
+ export { consumeCachedPageData, initPageData, setCurrentPageData, warmPageData };
@@ -3,10 +3,12 @@ import { removeBase } from "@rspress/core/runtime";
3
3
  import { startTransition } from "react";
4
4
  import { hydrateRoot } from "react-dom/client";
5
5
  import { ClientApp } from "./ClientApp.js";
6
- import { initPageData } from "./initPageData.js";
6
+ import { initPageData, setCurrentPageData } from "./initPageData.js";
7
7
  async function renderInBrowser() {
8
8
  const container = document.getElementById('__rspress_root');
9
- const initialPageData = await initPageData(removeBase(window.location.pathname));
9
+ const pathname = removeBase(window.location.pathname);
10
+ const initialPageData = await initPageData(pathname);
11
+ setCurrentPageData(pathname, initialPageData);
10
12
  startTransition(()=>{
11
13
  hydrateRoot(container, /*#__PURE__*/ jsx(ClientApp, {
12
14
  initialPageData: initialPageData
@@ -7,7 +7,7 @@ const SvgSuccess = (props)=>/*#__PURE__*/ jsx("svg", {
7
7
  viewBox: "0 0 24 24",
8
8
  ...props,
9
9
  children: /*#__PURE__*/ jsx("path", {
10
- fill: "#49cd37",
10
+ fill: "currentColor",
11
11
  d: "m9.55 18-5.7-5.7 1.425-1.425L9.55 15.15l9.175-9.175L20.15 7.4z"
12
12
  })
13
13
  });
@@ -7,7 +7,7 @@ const SvgWrapped = (props)=>/*#__PURE__*/ jsx("svg", {
7
7
  viewBox: "0 0 24 24",
8
8
  ...props,
9
9
  children: /*#__PURE__*/ jsx("path", {
10
- fill: "#22a041",
10
+ fill: "currentColor",
11
11
  d: "M21 5H3v2h18zM3 19h7v-2H3zm0-6h15c1 0 2 .43 2 2s-1 2-2 2h-2v-2l-4 3 4 3v-2h2c2.95 0 4-1.27 4-4 0-2.72-1-4-4-4H3z"
12
12
  })
13
13
  });
@@ -82,6 +82,10 @@
82
82
  width: 3ch;
83
83
  }
84
84
 
85
+ .rp-codeblock__content--scroll {
86
+ overflow-y: auto;
87
+ }
88
+
85
89
  .rp-codeblock__content--fold {
86
90
  position: relative;
87
91
  overflow: hidden;
@@ -15,9 +15,6 @@ export type CodeBlockProps = {
15
15
  * @default false
16
16
  */
17
17
  fold?: boolean;
18
- /**
19
- * @default 300
20
- */
21
18
  height?: number;
22
19
  containerElementClassName?: string;
23
20
  codeButtonGroupProps?: Omit<CodeButtonGroupProps, 'preElementRef' | 'wrapCode' | 'toggleWrapCode'>;
@@ -3,19 +3,22 @@ import { CodeButtonGroup, IconArrowDown, SvgWrapper, useCodeButtonGroup } from "
3
3
  import clsx from "clsx";
4
4
  import { useCallback, useEffect, useRef, useState } from "react";
5
5
  import "./index.css";
6
- function CodeBlock({ containerElementClassName, title, lang = 'txt', wrapCode: wrapCodeProp = false, lineNumbers: lineNumbersProp = false, fold = false, height = 300, codeButtonGroupProps, children }) {
6
+ const DEFAULT_FOLD_HEIGHT = 300;
7
+ function CodeBlock({ containerElementClassName, title, lang = 'txt', wrapCode: wrapCodeProp = false, lineNumbers: lineNumbersProp = false, fold = false, height, codeButtonGroupProps, children }) {
7
8
  if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
8
9
  children: children
9
10
  });
10
11
  const { wrapCode: wrapCodeState, toggleWrapCode, copyElementRef } = useCodeButtonGroup(wrapCodeProp);
11
12
  const [expanded, setExpanded] = useState(false);
12
13
  const [needFold, setNeedFold] = useState(false);
14
+ const hasScroll = !fold && void 0 !== height;
13
15
  const codeBlockRef = useRef(null);
14
16
  const contentRef = useRef(null);
15
17
  useEffect(()=>{
16
18
  if (!fold || !contentRef.current) return void setNeedFold(false);
19
+ const foldHeight = height ?? DEFAULT_FOLD_HEIGHT;
17
20
  const realHeight = contentRef.current.scrollHeight;
18
- setNeedFold(realHeight > height);
21
+ setNeedFold(realHeight > foldHeight);
19
22
  }, [
20
23
  fold,
21
24
  height
@@ -45,8 +48,10 @@ function CodeBlock({ containerElementClassName, title, lang = 'txt', wrapCode: w
45
48
  children: title
46
49
  }),
47
50
  /*#__PURE__*/ jsxs("div", {
48
- className: clsx('rp-codeblock__content', wrapCodeState && 'rp-codeblock__content--wrap-code', lineNumbersProp && 'rp-codeblock__content--line-numbers', needFold && !expanded && 'rp-codeblock__content--fold'),
51
+ className: clsx('rp-codeblock__content', wrapCodeState && 'rp-codeblock__content--wrap-code', lineNumbersProp && 'rp-codeblock__content--line-numbers', needFold && !expanded && 'rp-codeblock__content--fold', hasScroll && 'rp-codeblock__content--scroll'),
49
52
  style: needFold && !expanded ? {
53
+ maxHeight: `${height ?? DEFAULT_FOLD_HEIGHT}px`
54
+ } : hasScroll ? {
50
55
  maxHeight: `${height}px`
51
56
  } : void 0,
52
57
  ref: contentRef,
@@ -4,11 +4,11 @@
4
4
 
5
5
  .rp-code-copy-button__icon--success {
6
6
  opacity: 0;
7
- color: #00d600;
7
+ color: #10b981;
8
8
  position: absolute;
9
9
  top: 50%;
10
10
  left: 50%;
11
- transform: translate(-50%, -50%)scale(0);
11
+ transform: translate(-50%, -50%) scale(0);
12
12
  }
13
13
 
14
14
  .rp-code-copy-button--copied .rp-code-copy-button__icon--copy {
@@ -19,6 +19,6 @@
19
19
  .rp-code-copy-button--copied .rp-code-copy-button__icon--success {
20
20
  opacity: 1;
21
21
  transition-delay: 75ms;
22
- transform: translate(-50%, -50%)scale(1);
22
+ transform: translate(-50%, -50%) scale(1);
23
23
  }
24
24
 
@@ -45,11 +45,11 @@
45
45
 
46
46
  .rp-code-button-group__icon--wrapped {
47
47
  opacity: 0;
48
- color: #00d600;
48
+ color: #10b981;
49
49
  position: absolute;
50
50
  top: 50%;
51
51
  left: 50%;
52
- transform: translate(-50%, -50%)scale(0);
52
+ transform: translate(-50%, -50%) scale(0);
53
53
  }
54
54
 
55
55
  .rp-code-wrap-button--wrapped .rp-code-button-group__icon--wrap {
@@ -60,6 +60,6 @@
60
60
  .rp-code-wrap-button--wrapped .rp-code-button-group__icon--wrapped {
61
61
  opacity: 1;
62
62
  transition-delay: 75ms;
63
- transform: translate(-50%, -50%)scale(1);
63
+ transform: translate(-50%, -50%) scale(1);
64
64
  }
65
65
 
@@ -54,6 +54,7 @@
54
54
  opacity: 0;
55
55
  font-weight: 500;
56
56
  font-size: inherit;
57
+ border-bottom: 1px solid #0000;
57
58
  margin-left: -.8em;
58
59
  transition: color .25s, opacity .25s;
59
60
  }
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { getCustomMDXComponent, renderInlineMarkdown } from "@rspress/core/theme";
3
- import { slug } from "github-slugger";
3
+ import { slug } from "@rspress/shared/github-slugger";
4
4
  import { useMemo } from "react";
5
5
  const getHeadingMap = ()=>{
6
6
  const { h1, h2, h3, h4, h5, h6 } = getCustomMDXComponent();
@@ -1,4 +1,4 @@
1
- import { cleanUrlByConfig, isActive, isExternalUrl, pathnameToRouteService, removeBase, useLocation, useNavigate, withBase } from "@rspress/core/runtime";
1
+ import { cleanUrlByConfig, initPageData, isActive, isExternalUrl, pathnameToRouteService, removeBase, useLocation, useNavigate, warmPageData, withBase } from "@rspress/core/runtime";
2
2
  import nprogress from "nprogress";
3
3
  import { startTransition as external_react_startTransition, useCallback } from "react";
4
4
  nprogress.configure({
@@ -46,7 +46,8 @@ function useLinkNavigate({ startTransition } = {
46
46
  const timer = setTimeout(()=>{
47
47
  nprogress.start();
48
48
  }, 200);
49
- await matchedRoute.preload();
49
+ const data = await initPageData(removeBaseHref);
50
+ warmPageData(removeBaseHref, data);
50
51
  clearTimeout(timer);
51
52
  nprogress.done();
52
53
  }