@rspress/core 2.0.6 → 2.0.8

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 (183) hide show
  1. package/dist/0~execa.js +25 -34
  2. package/dist/{675.js → 7319.js} +17 -0
  3. package/dist/7397.js +1 -1
  4. package/dist/8311.js +1 -1
  5. package/dist/eject-theme/components/Banner/index.tsx +1 -1
  6. package/dist/eject-theme/components/Button/index.tsx +1 -1
  7. package/dist/eject-theme/components/CodeBlock/index.scss +58 -1
  8. package/dist/eject-theme/components/CodeBlock/index.tsx +85 -7
  9. package/dist/eject-theme/components/CodeBlockRuntime/index.tsx +12 -2
  10. package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -1
  11. package/dist/eject-theme/components/CodeButtonGroup/index.tsx +15 -15
  12. package/dist/eject-theme/components/DocContent/docComponents/a.tsx +1 -1
  13. package/dist/eject-theme/components/DocContent/docComponents/pre.tsx +5 -1
  14. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +6 -1
  15. package/dist/eject-theme/components/DocContent/index.tsx +1 -1
  16. package/dist/eject-theme/components/DocFooter/index.tsx +1 -1
  17. package/dist/eject-theme/components/EditLink/index.tsx +1 -1
  18. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -1
  19. package/dist/eject-theme/components/HomeFeature/index.tsx +5 -1
  20. package/dist/eject-theme/components/HomeFooter/index.tsx +1 -1
  21. package/dist/eject-theme/components/HomeHero/index.tsx +1 -1
  22. package/dist/eject-theme/components/HoverGroup/index.tsx +4 -1
  23. package/dist/eject-theme/components/Link/useLinkNavigate.ts +1 -1
  24. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +1 -1
  25. package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +1 -1
  26. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +1 -1
  27. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +1 -1
  28. package/dist/eject-theme/components/Nav/NavMenu.tsx +9 -2
  29. package/dist/eject-theme/components/Nav/index.tsx +1 -1
  30. package/dist/eject-theme/components/NavHamburger/index.tsx +6 -1
  31. package/dist/eject-theme/components/NavScreen/NavScreenAppearance.tsx +1 -1
  32. package/dist/eject-theme/components/NavScreen/NavScreenLangs.tsx +1 -1
  33. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +5 -1
  34. package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +1 -1
  35. package/dist/eject-theme/components/NavScreen/NavScreenVersions.tsx +1 -1
  36. package/dist/eject-theme/components/NavScreen/index.tsx +1 -1
  37. package/dist/eject-theme/components/NavTitle/index.tsx +1 -1
  38. package/dist/eject-theme/components/Outline/ScrollToTop.tsx +5 -1
  39. package/dist/eject-theme/components/Outline/index.tsx +1 -1
  40. package/dist/eject-theme/components/Overview/index.tsx +1 -1
  41. package/dist/eject-theme/components/OverviewGroup/index.tsx +2 -2
  42. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +1 -1
  43. package/dist/eject-theme/components/PrevNextPage/index.tsx +1 -1
  44. package/dist/eject-theme/components/Root/index.tsx +1 -1
  45. package/dist/eject-theme/components/Search/NoSearchResult.tsx +1 -1
  46. package/dist/eject-theme/components/Search/SearchButton.tsx +1 -1
  47. package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -1
  48. package/dist/eject-theme/components/Search/SuggestItem.tsx +1 -1
  49. package/dist/eject-theme/components/Search/index.tsx +1 -1
  50. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +5 -1
  51. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -1
  52. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.tsx +1 -1
  53. package/dist/eject-theme/components/SidebarMenu/index.tsx +1 -1
  54. package/dist/eject-theme/components/SocialLinks/index.tsx +1 -1
  55. package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
  56. package/dist/eject-theme/components/SvgWrapper/index.tsx +1 -1
  57. package/dist/eject-theme/components/SwitchAppearance/index.tsx +1 -1
  58. package/dist/eject-theme/components/Tabs/index.tsx +1 -1
  59. package/dist/eject-theme/components/Tag/index.tsx +1 -1
  60. package/dist/eject-theme/components/Toc/TocItem.tsx +5 -1
  61. package/dist/eject-theme/components/Toc/index.tsx +1 -1
  62. package/dist/node/PluginDriver.js +2 -2
  63. package/dist/node/auto-nav-sidebar/index.js +2 -2
  64. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  65. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  66. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  67. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  68. package/dist/node/eject.js +3 -1
  69. package/dist/node/initRsbuild.js +1 -1
  70. package/dist/node/mdx/options.js +2 -2
  71. package/dist/node/mdx/rehypePlugins/headerAnchor.js +2 -1
  72. package/dist/node/mdx/rehypePlugins/shiki.d.ts +4 -1
  73. package/dist/node/mdx/rehypePlugins/shiki.js +5 -2
  74. package/dist/node/mdx/rehypePlugins/transformers/add-fold.d.ts +12 -0
  75. package/dist/node/mdx/rehypePlugins/transformers/add-fold.js +55 -0
  76. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +1 -0
  77. package/dist/node/mdx/rehypePlugins/transformers/index.js +6 -5
  78. package/dist/node/mdx/remarkPlugins/containerSyntax.js +7 -1
  79. package/dist/node/route/RoutePage.js +1 -1
  80. package/dist/node/route/RouteService.js +1 -1
  81. package/dist/node/route/extractPageData.js +3 -2
  82. package/dist/node/route/normalizeRoutePath.js +1 -1
  83. package/dist/node/runtimeModule/i18n.js +2 -2
  84. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  85. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  86. package/dist/node/runtimeModule/searchHooks.js +1 -1
  87. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  88. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  89. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  90. package/dist/node/serve.js +1 -1
  91. package/dist/node/ssg/renderPages.js +1 -1
  92. package/dist/node/ssg/rsbuildPluginSSG.js +20 -7
  93. package/dist/node/ssg/ssgEnv.js +1 -1
  94. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  95. package/dist/node/ssg-md/llms/llmsTxt.js +3 -2
  96. package/dist/node/ssg-md/renderPage.js +1 -1
  97. package/dist/node/ssg-md/renderPages.js +1 -1
  98. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  99. package/dist/node/utils/checkLanguageParity.js +1 -1
  100. package/dist/node/utils/createHash.js +1 -1
  101. package/dist/node/utils/flattenMdxContent.js +3 -2
  102. package/dist/node/utils/getPageKey.js +1 -1
  103. package/dist/node/utils/normalizePath.js +2 -1
  104. package/dist/node/utils/reactAlias.js +1 -1
  105. package/dist/runtime/hooks/useWindowSize.test.js +10 -10
  106. package/dist/shiki-transformers.js +1 -0
  107. package/dist/theme/components/Banner/index.js +1 -1
  108. package/dist/theme/components/Button/index.js +1 -1
  109. package/dist/theme/components/CodeBlock/index.css +53 -1
  110. package/dist/theme/components/CodeBlock/index.d.ts +8 -3
  111. package/dist/theme/components/CodeBlock/index.js +56 -6
  112. package/dist/theme/components/CodeBlockRuntime/index.d.ts +2 -2
  113. package/dist/theme/components/CodeBlockRuntime/index.js +10 -2
  114. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.css +2 -2
  115. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +1 -1
  116. package/dist/theme/components/CodeButtonGroup/index.css +2 -2
  117. package/dist/theme/components/CodeButtonGroup/index.d.ts +6 -6
  118. package/dist/theme/components/CodeButtonGroup/index.js +10 -10
  119. package/dist/theme/components/DocContent/docComponents/a.js +1 -1
  120. package/dist/theme/components/DocContent/docComponents/pre.d.ts +2 -2
  121. package/dist/theme/components/DocContent/docComponents/pre.js +4 -2
  122. package/dist/theme/components/DocContent/docComponents/title.js +1 -1
  123. package/dist/theme/components/DocContent/index.js +1 -1
  124. package/dist/theme/components/DocFooter/index.js +1 -1
  125. package/dist/theme/components/EditLink/index.js +1 -1
  126. package/dist/theme/components/FallbackHeading/index.js +1 -1
  127. package/dist/theme/components/HomeFeature/index.js +1 -1
  128. package/dist/theme/components/HomeFooter/index.js +1 -1
  129. package/dist/theme/components/HomeHero/index.js +1 -1
  130. package/dist/theme/components/HoverGroup/index.js +4 -1
  131. package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
  132. package/dist/theme/components/Llms/LlmsCopyButton.css +4 -4
  133. package/dist/theme/components/Llms/LlmsCopyButton.js +1 -1
  134. package/dist/theme/components/Llms/LlmsCopyRow.js +1 -1
  135. package/dist/theme/components/Llms/LlmsOpenRow.js +1 -1
  136. package/dist/theme/components/Llms/LlmsViewOptions.css +2 -2
  137. package/dist/theme/components/Llms/LlmsViewOptions.js +1 -1
  138. package/dist/theme/components/Nav/NavMenu.d.ts +1 -1
  139. package/dist/theme/components/Nav/NavMenu.js +2 -1
  140. package/dist/theme/components/Nav/index.js +1 -1
  141. package/dist/theme/components/NavHamburger/index.js +1 -1
  142. package/dist/theme/components/NavScreen/NavScreenAppearance.js +1 -1
  143. package/dist/theme/components/NavScreen/NavScreenLangs.js +1 -1
  144. package/dist/theme/components/NavScreen/NavScreenMenuItem.d.ts +2 -1
  145. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +4 -2
  146. package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +1 -1
  147. package/dist/theme/components/NavScreen/NavScreenVersions.js +1 -1
  148. package/dist/theme/components/NavScreen/index.js +1 -1
  149. package/dist/theme/components/NavTitle/index.js +1 -1
  150. package/dist/theme/components/Outline/ScrollToTop.js +1 -1
  151. package/dist/theme/components/Outline/index.js +1 -1
  152. package/dist/theme/components/Overview/index.d.ts +1 -1
  153. package/dist/theme/components/Overview/index.js +1 -1
  154. package/dist/theme/components/OverviewGroup/index.js +1 -1
  155. package/dist/theme/components/PackageManagerTabs/index.js +1 -1
  156. package/dist/theme/components/PrevNextPage/index.js +1 -1
  157. package/dist/theme/components/Root/index.d.ts +1 -1
  158. package/dist/theme/components/Search/NoSearchResult.js +1 -1
  159. package/dist/theme/components/Search/SearchButton.js +1 -1
  160. package/dist/theme/components/Search/SearchPanel.js +1 -1
  161. package/dist/theme/components/Search/SuggestItem.js +1 -1
  162. package/dist/theme/components/Search/index.js +1 -1
  163. package/dist/theme/components/Sidebar/SidebarGroup.js +1 -1
  164. package/dist/theme/components/Sidebar/SidebarItem.js +1 -1
  165. package/dist/theme/components/Sidebar/SidebarSectionHeader.js +1 -1
  166. package/dist/theme/components/SidebarMenu/index.js +1 -1
  167. package/dist/theme/components/SocialLinks/index.js +1 -1
  168. package/dist/theme/components/SourceCode/index.js +1 -1
  169. package/dist/theme/components/SvgWrapper/index.js +1 -1
  170. package/dist/theme/components/SwitchAppearance/index.js +1 -1
  171. package/dist/theme/components/Tabs/index.js +1 -1
  172. package/dist/theme/components/Tag/index.js +1 -1
  173. package/dist/theme/components/Toc/TocItem.js +1 -1
  174. package/dist/theme/components/Toc/index.js +1 -1
  175. package/dist/theme/layout/DocLayout/index.js +1 -1
  176. package/dist/theme/layout/HomeLayout/index.js +1 -1
  177. package/dist/theme/layout/Layout/index.d.ts +2 -2
  178. package/dist/theme/layout/Layout/index.js +2 -2
  179. package/dist/theme/layout/NotFountLayout/index.js +1 -1
  180. package/dist/theme/styles/base.css +1 -1
  181. package/nav-json-schema.json +3 -0
  182. package/package.json +12 -12
  183. /package/dist/{rslib-runtime.js → 0~rslib-runtime.js} +0 -0
package/dist/0~execa.js CHANGED
@@ -1,17 +1,14 @@
1
- import * as __rspack_external_child_process from "child_process";
2
- import * as __rspack_external_fs from "fs";
3
- import * as __rspack_external_path from "path";
4
- import * as __rspack_external_stream from "stream";
5
- import { __webpack_require__ } from "./rslib-runtime.js";
6
1
  import { Buffer } from "node:buffer";
7
2
  import node_path from "node:path";
8
3
  import node_child_process, { ChildProcess } from "node:child_process";
9
4
  import node_process from "node:process";
10
- import node_url from "node:url";
5
+ import { fileURLToPath } from "node:url";
11
6
  import node_os, { constants } from "node:os";
12
7
  import { createReadStream, createWriteStream, readFileSync } from "node:fs";
13
8
  import { setTimeout as promises_setTimeout } from "node:timers/promises";
14
9
  import { debuglog } from "node:util";
10
+ import { __webpack_require__ } from "./0~rslib-runtime.js";
11
+ import "./7319.js";
15
12
  __webpack_require__.add({
16
13
  "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module, __unused_rspack_exports, __webpack_require__) {
17
14
  const cp = __webpack_require__("child_process");
@@ -442,18 +439,6 @@ __webpack_require__.add({
442
439
  };
443
440
  module.exports = which;
444
441
  which.sync = whichSync;
445
- },
446
- child_process (module) {
447
- module.exports = __rspack_external_child_process;
448
- },
449
- fs (module) {
450
- module.exports = __rspack_external_fs;
451
- },
452
- path (module) {
453
- module.exports = __rspack_external_path;
454
- },
455
- stream (module) {
456
- module.exports = __rspack_external_stream;
457
442
  }
458
443
  });
459
444
  function stripFinalNewline(input) {
@@ -468,34 +453,40 @@ function pathKey(options = {}) {
468
453
  if ('win32' !== platform) return 'PATH';
469
454
  return Object.keys(env).reverse().find((key)=>'PATH' === key.toUpperCase()) || 'Path';
470
455
  }
471
- function npmRunPath(options = {}) {
472
- const { cwd = node_process.cwd(), path: path_ = node_process.env[pathKey()], execPath = node_process.execPath } = options;
473
- let previous;
474
- const cwdString = cwd instanceof URL ? node_url.fileURLToPath(cwd) : cwd;
475
- let cwdPath = node_path.resolve(cwdString);
456
+ const npmRunPath = ({ cwd = node_process.cwd(), path: pathOption = node_process.env[pathKey()], preferLocal = true, execPath = node_process.execPath, addExecPath = true } = {})=>{
457
+ const cwdString = cwd instanceof URL ? fileURLToPath(cwd) : cwd;
458
+ const cwdPath = node_path.resolve(cwdString);
476
459
  const result = [];
460
+ if (preferLocal) applyPreferLocal(result, cwdPath);
461
+ if (addExecPath) applyExecPath(result, execPath, cwdPath);
462
+ return [
463
+ ...result,
464
+ pathOption
465
+ ].join(node_path.delimiter);
466
+ };
467
+ const applyPreferLocal = (result, cwdPath)=>{
468
+ let previous;
477
469
  while(previous !== cwdPath){
478
470
  result.push(node_path.join(cwdPath, 'node_modules/.bin'));
479
471
  previous = cwdPath;
480
472
  cwdPath = node_path.resolve(cwdPath, '..');
481
473
  }
482
- result.push(node_path.resolve(cwdString, execPath, '..'));
483
- return [
484
- ...result,
485
- path_
486
- ].join(node_path.delimiter);
487
- }
488
- function npmRunPathEnv({ env = node_process.env, ...options } = {}) {
474
+ };
475
+ const applyExecPath = (result, execPath, cwdPath)=>{
476
+ const execPathString = execPath instanceof URL ? fileURLToPath(execPath) : execPath;
477
+ result.push(node_path.resolve(cwdPath, execPathString, '..'));
478
+ };
479
+ const npmRunPathEnv = ({ env = node_process.env, ...options } = {})=>{
489
480
  env = {
490
481
  ...env
491
482
  };
492
- const path = pathKey({
483
+ const pathName = pathKey({
493
484
  env
494
485
  });
495
- options.path = env[path];
496
- env[path] = npmRunPath(options);
486
+ options.path = env[pathName];
487
+ env[pathName] = npmRunPath(options);
497
488
  return env;
498
- }
489
+ };
499
490
  const copyProperty = (to, from, property, ignoreNonConfigurable)=>{
500
491
  if ('length' === property || 'prototype' === property) return;
501
492
  if ('arguments' === property || 'caller' === property) return;
@@ -1,4 +1,21 @@
1
1
  import node_path, { extname, join, relative } from "node:path";
2
+ import { __webpack_require__ } from "./0~rslib-runtime.js";
3
+ import { createRequire as __rspack_createRequire } from "node:module";
4
+ const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
5
+ __webpack_require__.add({
6
+ child_process (module) {
7
+ module.exports = __rspack_createRequire_require("child_process");
8
+ },
9
+ fs (module) {
10
+ module.exports = __rspack_createRequire_require("fs");
11
+ },
12
+ path (module) {
13
+ module.exports = __rspack_createRequire_require("path");
14
+ },
15
+ stream (module) {
16
+ module.exports = __rspack_createRequire_require("stream");
17
+ }
18
+ });
2
19
  const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
3
20
  const pluginVirtualModule = (pluginOptions = {})=>({
4
21
  name: PLUGIN_VIRTUAL_MODULE_NAME,
package/dist/7397.js CHANGED
@@ -13,6 +13,6 @@ export { unified } from "unified";
13
13
  export { visit } from "unist-util-visit";
14
14
  export { default as github_slugger } from "github-slugger";
15
15
  export { headingRank } from "hast-util-heading-rank";
16
- export { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
16
+ export { transformerAddFold, transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
17
17
  export { createCssVariablesTheme } from "shiki";
18
18
  export { isExternalUrl } from "@rspress/shared";
package/dist/8311.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.0.6"
2
+ rE: "2.0.8"
3
3
  };
4
4
  async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
5
5
  return new Promise((resolve_, reject_)=>{
@@ -1,4 +1,4 @@
1
- import { IconClose, Link, mergeRefs, SvgWrapper } from '@theme';
1
+ import { IconClose, Link, mergeRefs, SvgWrapper } from '@rspress/core/theme';
2
2
  import clsx from 'clsx';
3
3
  import { forwardRef, type ReactNode, useEffect, useState } from 'react';
4
4
  import './index.scss';
@@ -1,4 +1,4 @@
1
- import { Link } from '@theme';
1
+ import { Link } from '@rspress/core/theme';
2
2
  import clsx from 'clsx';
3
3
  import React, { type JSX } from 'react';
4
4
  import './index.scss';
@@ -65,7 +65,7 @@
65
65
  line-height: 1.7;
66
66
  }
67
67
 
68
- &--code-wrap code {
68
+ &--wrap-code code {
69
69
  white-space: pre-wrap !important;
70
70
  word-break: break-all !important;
71
71
  }
@@ -87,4 +87,61 @@
87
87
  width: 3ch;
88
88
  }
89
89
  }
90
+
91
+ &--scroll {
92
+ overflow-y: auto;
93
+ }
94
+
95
+ &--fold {
96
+ overflow: hidden;
97
+ position: relative;
98
+
99
+ &::after {
100
+ content: '';
101
+ position: absolute;
102
+ bottom: 0;
103
+ left: 0;
104
+ right: 0;
105
+ height: 48px;
106
+ background: linear-gradient(
107
+ to bottom,
108
+ transparent,
109
+ var(--rp-code-block-bg)
110
+ );
111
+ pointer-events: none;
112
+ z-index: 2;
113
+ }
114
+ }
115
+ }
116
+
117
+ .rp-codeblock__fold-btn {
118
+ display: flex;
119
+ align-items: center;
120
+ justify-content: center;
121
+ width: 100%;
122
+ padding: 4px 0;
123
+ border: none;
124
+ background-color: var(--rp-code-block-bg);
125
+ color: var(--rp-c-text-3);
126
+ cursor: pointer;
127
+ transition:
128
+ color 0.2s ease,
129
+ background-color 0.2s ease;
130
+ user-select: none;
131
+ border-radius: 0 0 var(--rp-radius) var(--rp-radius);
132
+
133
+ &:hover {
134
+ color: var(--rp-c-text-1);
135
+ background-color: var(--rp-code-title-bg);
136
+ }
137
+
138
+ &__icon {
139
+ width: 18px;
140
+ height: 18px;
141
+ transition: transform 0.3s ease;
142
+ }
143
+
144
+ &--expanded &__icon {
145
+ transform: rotate(180deg);
146
+ }
90
147
  }
@@ -1,11 +1,16 @@
1
1
  import {
2
2
  CodeButtonGroup,
3
3
  type CodeButtonGroupProps,
4
+ IconArrowDown,
5
+ SvgWrapper,
4
6
  useCodeButtonGroup,
5
- } from '@theme';
7
+ } from '@rspress/core/theme';
6
8
  import clsx from 'clsx';
9
+ import { useCallback, useEffect, useRef, useState } from 'react';
7
10
  import './index.scss';
8
11
 
12
+ const DEFAULT_FOLD_HEIGHT = 300;
13
+
9
14
  export type CodeBlockProps = {
10
15
  title?: string;
11
16
  lang?: string;
@@ -17,10 +22,15 @@ export type CodeBlockProps = {
17
22
  * @default false
18
23
  */
19
24
  lineNumbers?: boolean;
25
+ /**
26
+ * @default false
27
+ */
28
+ fold?: boolean;
29
+ height?: number;
20
30
  containerElementClassName?: string;
21
31
  codeButtonGroupProps?: Omit<
22
32
  CodeButtonGroupProps,
23
- 'preElementRef' | 'codeWrap' | 'toggleCodeWrap'
33
+ 'preElementRef' | 'wrapCode' | 'toggleWrapCode'
24
34
  >;
25
35
  children?: React.ReactNode;
26
36
  };
@@ -66,6 +76,8 @@ export function CodeBlock({
66
76
  lang = 'txt',
67
77
  wrapCode: wrapCodeProp = false,
68
78
  lineNumbers: lineNumbersProp = false,
79
+ fold = false,
80
+ height,
69
81
  codeButtonGroupProps,
70
82
  children,
71
83
  }: CodeBlockProps) {
@@ -73,8 +85,46 @@ export function CodeBlock({
73
85
  return <>{children}</>;
74
86
  }
75
87
 
76
- const { codeWrap, toggleCodeWrap, copyElementRef } =
77
- useCodeButtonGroup(wrapCodeProp);
88
+ const {
89
+ wrapCode: wrapCodeState,
90
+ toggleWrapCode,
91
+ copyElementRef,
92
+ } = useCodeButtonGroup(wrapCodeProp);
93
+ const [expanded, setExpanded] = useState(false);
94
+ const [needFold, setNeedFold] = useState(false);
95
+ const hasScroll = !fold && height !== undefined;
96
+ const codeBlockRef = useRef<HTMLDivElement>(null);
97
+ const contentRef = useRef<HTMLDivElement>(null);
98
+
99
+ useEffect(() => {
100
+ if (!fold || !contentRef.current) {
101
+ setNeedFold(false);
102
+ return;
103
+ }
104
+ const foldHeight = height ?? DEFAULT_FOLD_HEIGHT;
105
+ const realHeight = contentRef.current.scrollHeight;
106
+ setNeedFold(realHeight > foldHeight);
107
+ }, [fold, height]);
108
+
109
+ const handleFoldToggle = useCallback(() => {
110
+ if (expanded) {
111
+ setExpanded(false);
112
+ requestAnimationFrame(() => {
113
+ if (codeBlockRef.current) {
114
+ const rect = codeBlockRef.current.getBoundingClientRect();
115
+ if (rect.top < 0) {
116
+ window.scrollBy({
117
+ top: rect.top - 16,
118
+ behavior: 'smooth',
119
+ });
120
+ }
121
+ }
122
+ });
123
+ } else {
124
+ setExpanded(true);
125
+ }
126
+ }, [expanded]);
127
+
78
128
  return (
79
129
  <div
80
130
  className={clsx(
@@ -82,14 +132,25 @@ export function CodeBlock({
82
132
  `language-${lang}`,
83
133
  containerElementClassName,
84
134
  )}
135
+ ref={codeBlockRef}
85
136
  >
86
137
  {title && <div className="rp-codeblock__title">{title}</div>}
87
138
  <div
88
139
  className={clsx(
89
140
  'rp-codeblock__content',
90
- codeWrap && 'rp-codeblock__content--code-wrap',
141
+ wrapCodeState && 'rp-codeblock__content--wrap-code',
91
142
  lineNumbersProp && 'rp-codeblock__content--line-numbers',
143
+ needFold && !expanded && 'rp-codeblock__content--fold',
144
+ hasScroll && 'rp-codeblock__content--scroll',
92
145
  )}
146
+ style={
147
+ needFold && !expanded
148
+ ? { maxHeight: `${height ?? DEFAULT_FOLD_HEIGHT}px` }
149
+ : hasScroll
150
+ ? { maxHeight: `${height}px` }
151
+ : undefined
152
+ }
153
+ ref={contentRef}
93
154
  >
94
155
  <div
95
156
  className="rp-codeblock__content__scroll-container rp-scrollbar rp-scrollbar--always"
@@ -100,10 +161,27 @@ export function CodeBlock({
100
161
  <CodeButtonGroup
101
162
  {...codeButtonGroupProps}
102
163
  copyElementRef={copyElementRef}
103
- codeWrap={codeWrap}
104
- toggleCodeWrap={toggleCodeWrap}
164
+ wrapCode={wrapCodeState}
165
+ toggleWrapCode={toggleWrapCode}
105
166
  />
106
167
  </div>
168
+ {needFold && (
169
+ <button
170
+ type="button"
171
+ className={clsx(
172
+ 'rp-codeblock__fold-btn',
173
+ expanded && 'rp-codeblock__fold-btn--expanded',
174
+ )}
175
+ onClick={handleFoldToggle}
176
+ aria-label={expanded ? 'Collapse code' : 'Expand code'}
177
+ aria-expanded={expanded}
178
+ >
179
+ <SvgWrapper
180
+ icon={IconArrowDown}
181
+ className="rp-codeblock__fold-btn__icon"
182
+ />
183
+ </button>
184
+ )}
107
185
  </div>
108
186
  );
109
187
  }
@@ -1,5 +1,5 @@
1
- import type { CodeBlockProps } from '@theme';
2
- import { getCustomMDXComponent } from '@theme';
1
+ import type { CodeBlockProps } from '@rspress/core/theme';
2
+ import { getCustomMDXComponent } from '@rspress/core/theme';
3
3
  import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
4
4
  import {
5
5
  Fragment,
@@ -56,6 +56,8 @@ export function CodeBlockRuntime({
56
56
  onRendered,
57
57
  wrapCode,
58
58
  lineNumbers,
59
+ fold,
60
+ height,
59
61
  }: CodeBlockRuntimeProps) {
60
62
  // getCustomMDXComponent is stable for theme rendering
61
63
  const mdxComponents = useMemo(() => getCustomMDXComponent(), []);
@@ -67,6 +69,8 @@ export function CodeBlockRuntime({
67
69
  lang={lang}
68
70
  wrapCode={wrapCode}
69
71
  lineNumbers={lineNumbers}
72
+ fold={fold}
73
+ height={height}
70
74
  containerElementClassName={containerElementClassName}
71
75
  codeButtonGroupProps={codeButtonGroupProps}
72
76
  className="shiki css-variables"
@@ -79,6 +83,8 @@ export function CodeBlockRuntime({
79
83
  lang,
80
84
  wrapCode,
81
85
  lineNumbers,
86
+ fold,
87
+ height,
82
88
  containerElementClassName,
83
89
  codeButtonGroupProps,
84
90
  code,
@@ -115,6 +121,8 @@ export function CodeBlockRuntime({
115
121
  codeButtonGroupProps={codeButtonGroupProps}
116
122
  wrapCode={wrapCode}
117
123
  lineNumbers={lineNumbers}
124
+ fold={fold}
125
+ height={height}
118
126
  {...props}
119
127
  />
120
128
  ),
@@ -132,6 +140,8 @@ export function CodeBlockRuntime({
132
140
  containerElementClassName,
133
141
  lang,
134
142
  lineNumbers,
143
+ fold,
144
+ height,
135
145
  shikiOptions,
136
146
  title,
137
147
  wrapCode,
@@ -1,4 +1,4 @@
1
- import { IconCopy, IconSuccess, SvgWrapper } from '@theme';
1
+ import { IconCopy, IconSuccess, SvgWrapper } from '@rspress/core/theme';
2
2
  import copy from 'copy-to-clipboard';
3
3
  import { useRef } from 'react';
4
4
  import './CopyCodeButton.scss';
@@ -1,5 +1,5 @@
1
1
  import { useSite } from '@rspress/core/runtime';
2
- import { IconWrap, IconWrapped, SvgWrapper } from '@theme';
2
+ import { IconWrap, IconWrapped, SvgWrapper } from '@rspress/core/theme';
3
3
  import clsx from 'clsx';
4
4
  import { useRef, useState } from 'react';
5
5
  import './index.scss';
@@ -7,12 +7,12 @@ import { CopyCodeButton } from './CopyCodeButton';
7
7
 
8
8
  export interface CodeButtonGroupProps {
9
9
  copyElementRef: React.RefObject<HTMLDivElement | null>;
10
- codeWrap: boolean;
11
- toggleCodeWrap: () => void;
10
+ wrapCode: boolean;
11
+ toggleWrapCode: () => void;
12
12
  /**
13
13
  * @default true
14
14
  */
15
- showCodeWrapButton?: boolean;
15
+ showWrapCodeButton?: boolean;
16
16
  /**
17
17
  * @default true
18
18
  */
@@ -22,38 +22,38 @@ export interface CodeButtonGroupProps {
22
22
  export const useCodeButtonGroup = (initialWrapCode?: boolean) => {
23
23
  const { site } = useSite();
24
24
  const { defaultWrapCode } = site.markdown;
25
- const [codeWrap, setCodeWrap] = useState(initialWrapCode ?? defaultWrapCode);
25
+ const [wrapCode, setWrapCode] = useState(initialWrapCode ?? defaultWrapCode);
26
26
  const copyElementRef = useRef<HTMLDivElement>(null);
27
27
 
28
- const toggleCodeWrap = () => {
29
- setCodeWrap(!codeWrap);
28
+ const toggleWrapCode = () => {
29
+ setWrapCode(!wrapCode);
30
30
  };
31
31
 
32
32
  return {
33
33
  copyElementRef,
34
- codeWrap,
35
- toggleCodeWrap,
34
+ wrapCode,
35
+ toggleWrapCode,
36
36
  };
37
37
  };
38
38
 
39
39
  export function CodeButtonGroup({
40
- codeWrap,
41
- toggleCodeWrap,
40
+ wrapCode,
41
+ toggleWrapCode,
42
42
  copyElementRef,
43
- showCodeWrapButton = true,
43
+ showWrapCodeButton = true,
44
44
  showCopyButton = true,
45
45
  }: CodeButtonGroupProps) {
46
46
  return (
47
47
  <>
48
48
  <div className="rp-code-button-group">
49
- {showCodeWrapButton && (
49
+ {showWrapCodeButton && (
50
50
  <button
51
51
  className={clsx(
52
52
  'rp-code-button-group__button',
53
53
  'rp-code-wrap-button',
54
- codeWrap && 'rp-code-wrap-button--wrapped',
54
+ wrapCode && 'rp-code-wrap-button--wrapped',
55
55
  )}
56
- onClick={() => toggleCodeWrap()}
56
+ onClick={() => toggleWrapCode()}
57
57
  title="Toggle code wrap"
58
58
  >
59
59
  <SvgWrapper
@@ -1,4 +1,4 @@
1
- import { Link } from '@theme';
1
+ import { Link } from '@rspress/core/theme';
2
2
  import type { ComponentProps } from 'react';
3
3
 
4
4
  export const A = (props: ComponentProps<'a'>) => {
@@ -1,4 +1,4 @@
1
- import { CodeBlock, type CodeBlockProps } from '@theme';
1
+ import { CodeBlock, type CodeBlockProps } from '@rspress/core/theme';
2
2
 
3
3
  export type ShikiPreProps = CodeBlockProps &
4
4
  React.HTMLAttributes<HTMLPreElement>;
@@ -8,6 +8,8 @@ export function ShikiPre({
8
8
  lang,
9
9
  wrapCode,
10
10
  lineNumbers,
11
+ fold,
12
+ height,
11
13
  containerElementClassName,
12
14
  codeButtonGroupProps,
13
15
  ...otherProps
@@ -18,6 +20,8 @@ export function ShikiPre({
18
20
  lang={lang}
19
21
  wrapCode={wrapCode}
20
22
  lineNumbers={lineNumbers}
23
+ fold={fold}
24
+ height={height}
21
25
  containerElementClassName={containerElementClassName}
22
26
  codeButtonGroupProps={codeButtonGroupProps}
23
27
  >
@@ -1,5 +1,10 @@
1
1
  import { useFrontmatter, useSite } from '@rspress/core/runtime';
2
- import { LlmsContainer, LlmsCopyButton, LlmsViewOptions, Tag } from '@theme';
2
+ import {
3
+ LlmsContainer,
4
+ LlmsCopyButton,
5
+ LlmsViewOptions,
6
+ Tag,
7
+ } from '@rspress/core/theme';
3
8
  import clsx from 'clsx';
4
9
  import type React from 'react';
5
10
 
@@ -5,7 +5,7 @@ import {
5
5
  FallbackHeading,
6
6
  getCustomMDXComponent,
7
7
  useScrollAfterNav,
8
- } from '@theme';
8
+ } from '@rspress/core/theme';
9
9
  import './doc.scss';
10
10
 
11
11
  function FallbackTitle() {
@@ -1,4 +1,4 @@
1
- import { EditLink, LastUpdated, PrevNextPage } from '@theme';
1
+ import { EditLink, LastUpdated, PrevNextPage } from '@rspress/core/theme';
2
2
  import './index.scss';
3
3
 
4
4
  export function DocFooter() {
@@ -1,4 +1,4 @@
1
- import { IconEdit, Link, SvgWrapper } from '@theme';
1
+ import { IconEdit, Link, SvgWrapper } from '@rspress/core/theme';
2
2
  import './index.scss';
3
3
  import { useEditLink } from './useEditLink';
4
4
 
@@ -1,4 +1,7 @@
1
- import { getCustomMDXComponent, renderInlineMarkdown } from '@theme';
1
+ import {
2
+ getCustomMDXComponent,
3
+ renderInlineMarkdown,
4
+ } from '@rspress/core/theme';
2
5
  import { slug } from 'github-slugger';
3
6
  import { useMemo } from 'react';
4
7
 
@@ -1,6 +1,10 @@
1
1
  import type { Feature } from '@rspress/core';
2
2
  import { useFrontmatter } from '@rspress/core/runtime';
3
- import { renderHtmlOrText, SvgWrapper, useLinkNavigate } from '@theme';
3
+ import {
4
+ renderHtmlOrText,
5
+ SvgWrapper,
6
+ useLinkNavigate,
7
+ } from '@rspress/core/theme';
4
8
  import type { JSX } from 'react';
5
9
  import './index.scss';
6
10
  import { useCardAnimation } from './useCardAnimation';
@@ -1,5 +1,5 @@
1
1
  import { useSite } from '@rspress/core/runtime';
2
- import { renderHtmlOrText } from '@theme';
2
+ import { renderHtmlOrText } from '@rspress/core/theme';
3
3
  import './index.scss';
4
4
 
5
5
  export function HomeFooter() {
@@ -1,6 +1,6 @@
1
1
  import type { FrontMatterMeta } from '@rspress/core';
2
2
  import { normalizeImagePath, useFrontmatter } from '@rspress/core/runtime';
3
- import { Button, Link, renderHtmlOrText } from '@theme';
3
+ import { Button, Link, renderHtmlOrText } from '@rspress/core/theme';
4
4
 
5
5
  import './index.scss';
6
6
  import clsx from 'clsx';
@@ -1,6 +1,6 @@
1
1
  import type { NavItemWithChildren } from '@rspress/core';
2
2
  import { matchNavbar, useLocation } from '@rspress/core/runtime';
3
- import { Link, Tag } from '@theme';
3
+ import { Link, Tag } from '@rspress/core/theme';
4
4
  import cls from 'clsx';
5
5
 
6
6
  import './index.scss';
@@ -44,6 +44,7 @@ function HoverGroupItem({
44
44
  >
45
45
  <Link
46
46
  href={item.link}
47
+ download={'download' in item ? item.download : undefined}
47
48
  aria-label={item.text}
48
49
  className="rp-hover-group__item__link"
49
50
  lang={item.lang}
@@ -69,6 +70,7 @@ function HoverGroupItem({
69
70
 
70
71
  if ('link' in item) {
71
72
  const { text, link, lang, rel } = item;
73
+ const download = 'download' in item ? item.download : undefined;
72
74
  const isActiveItem = activeMatcher
73
75
  ? activeMatcher(item)
74
76
  : matchNavbar(item, pathname);
@@ -85,6 +87,7 @@ function HoverGroupItem({
85
87
  {link ? (
86
88
  <Link
87
89
  href={link}
90
+ download={download}
88
91
  aria-label={text}
89
92
  className="rp-hover-group__item__link"
90
93
  lang={lang}
@@ -61,7 +61,7 @@ export function getHref(href: string): {
61
61
  }
62
62
 
63
63
  /**
64
- * For import { Link } from '@theme';
64
+ * For import { Link } from '@rspress/core/theme';
65
65
  * useNavigate with preload logic
66
66
  */
67
67
  export function useLinkNavigate(
@@ -4,7 +4,7 @@
4
4
  * @license MIT
5
5
  */
6
6
  import { useI18n } from '@rspress/core/runtime';
7
- import { IconCopy, IconSuccess } from '@theme';
7
+ import { IconCopy, IconSuccess } from '@rspress/core/theme';
8
8
  import { useCallback, useRef, useState } from 'react';
9
9
  import { SvgWrapper } from '../SvgWrapper';
10
10
  import './index.scss';
@@ -1,5 +1,5 @@
1
1
  import { useI18n } from '@rspress/core/runtime';
2
- import { IconCopy, IconSuccess, SvgWrapper } from '@theme';
2
+ import { IconCopy, IconSuccess, SvgWrapper } from '@rspress/core/theme';
3
3
  import { useCallback, useRef, useState } from 'react';
4
4
  import { copyToClipboard } from './copy';
5
5
  import { useMdUrl } from './useMdUrl';