@rspress/core 2.0.21 → 2.0.23

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 (179) hide show
  1. package/bin/rspress.js +3 -1
  2. package/dist/{2711~0.js → a~0.js} +90 -70
  3. package/dist/{8472~0.js → b~0.js} +19 -14
  4. package/dist/cli/index.js +12 -13
  5. package/dist/config/loadConfigFile.d.ts +3 -4
  6. package/dist/config/loadConfigFile.js +13 -17
  7. package/dist/{7748~0.js → d~0.js} +0 -2
  8. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +8 -0
  9. package/dist/eject-theme/components/Llms/LlmsHint.tsx +11 -3
  10. package/dist/eject-theme/components/Nav/NavMenu.scss +4 -0
  11. package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
  12. package/dist/eject-theme/components/Nav/index.tsx +30 -4
  13. package/dist/eject-theme/components/NavHamburger/index.tsx +11 -3
  14. package/dist/eject-theme/components/NavList/context.ts +3 -0
  15. package/dist/eject-theme/components/NavList/index.tsx +24 -0
  16. package/dist/eject-theme/components/NavScreen/NavScreenMenu.test.tsx +59 -0
  17. package/dist/eject-theme/components/NavScreen/NavScreenMenu.tsx +43 -2
  18. package/dist/eject-theme/components/NavScreen/index.scss +0 -6
  19. package/dist/eject-theme/components/NavScreen/index.tsx +20 -3
  20. package/dist/eject-theme/components/ReadPercent/useReadPercent.ts +1 -1
  21. package/dist/eject-theme/components/Search/SearchButton.scss +1 -0
  22. package/dist/eject-theme/components/Search/SearchPanel.scss +51 -12
  23. package/dist/eject-theme/components/Search/SearchPanel.tsx +62 -216
  24. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +39 -17
  25. package/dist/eject-theme/components/Search/useSearchPanel.ts +217 -0
  26. package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
  27. package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
  28. package/dist/eject-theme/components/Steps/index.scss +1 -1
  29. package/dist/eject-theme/components/SwitchAppearance/getClipPath.test.ts +15 -0
  30. package/dist/eject-theme/components/SwitchAppearance/getClipPath.ts +26 -0
  31. package/dist/eject-theme/components/SwitchAppearance/index.tsx +22 -26
  32. package/dist/eject-theme/components/Tabs/index.tsx +14 -14
  33. package/dist/index.js +1 -1
  34. package/dist/node/PluginDriver.d.ts +1 -1
  35. package/dist/node/PluginDriver.js +5 -9
  36. package/dist/node/auto-nav-sidebar/index.js +1 -1
  37. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  38. package/dist/node/auto-nav-sidebar/normalize.js +6 -6
  39. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  40. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  41. package/dist/node/build.d.ts +3 -2
  42. package/dist/node/build.js +9 -3
  43. package/dist/node/constants.js +1 -1
  44. package/dist/node/dev.d.ts +4 -4
  45. package/dist/node/dev.js +8 -6
  46. package/dist/node/eject.js +5 -5
  47. package/dist/node/initRsbuild.d.ts +2 -3
  48. package/dist/node/initRsbuild.js +9 -7
  49. package/dist/node/last-updated/index.js +2 -2
  50. package/dist/node/logger/hint.js +4 -4
  51. package/dist/node/mdx/options.js +1 -1
  52. package/dist/node/mdx/processor.js +3 -3
  53. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  54. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  55. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  56. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  57. package/dist/node/mdx/remarkPlugins/containerSyntax.js +6 -5
  58. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +5 -5
  59. package/dist/node/mdx/remarkPlugins/image.js +5 -5
  60. package/dist/node/mdx/remarkPlugins/link.js +5 -5
  61. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  62. package/dist/node/medium-zoom/index.js +1 -1
  63. package/dist/node/route/RoutePage.js +6 -4
  64. package/dist/node/route/RouteService.js +3 -3
  65. package/dist/node/route/extractPageData.js +20 -7
  66. package/dist/node/route/normalizeRoutePath.js +1 -1
  67. package/dist/node/runtimeModule/i18n.js +5 -5
  68. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  69. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  70. package/dist/node/runtimeModule/searchHooks.js +1 -1
  71. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  72. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  73. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  74. package/dist/node/serve.d.ts +3 -3
  75. package/dist/node/serve.js +10 -4
  76. package/dist/node/ssg/alternateLinks.js +1 -1
  77. package/dist/node/ssg/htmlFile.js +1 -1
  78. package/dist/node/ssg/renderHtmlTemplate.js +4 -3
  79. package/dist/node/ssg/renderPage.js +5 -5
  80. package/dist/node/ssg/renderPageWorker.js +2 -2
  81. package/dist/node/ssg/renderPages.js +6 -6
  82. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  83. package/dist/node/ssg/ssgEnv.js +1 -1
  84. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  85. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  86. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  87. package/dist/node/ssg-md/renderPage.js +5 -5
  88. package/dist/node/ssg-md/renderPages.js +6 -6
  89. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  90. package/dist/node/utils/checkLanguageParity.js +5 -7
  91. package/dist/node/utils/createHash.js +1 -1
  92. package/dist/node/utils/error.js +4 -4
  93. package/dist/node/utils/flattenMdxContent.js +2 -2
  94. package/dist/node/utils/fs.js +1 -1
  95. package/dist/node/utils/getPageKey.js +1 -1
  96. package/dist/node/utils/index.d.ts +1 -1
  97. package/dist/node/utils/reactAlias.js +5 -5
  98. package/dist/node/utils/slash.d.ts +1 -0
  99. package/dist/node/utils/slash.js +4 -0
  100. package/dist/{864~0.js → n~0.js} +42 -41
  101. package/dist/rslib-runtime~0.js +27 -35
  102. package/dist/runtime/App.js +3 -2
  103. package/dist/runtime/hooks/createExternalStore.d.ts +4 -0
  104. package/dist/runtime/hooks/createExternalStore.js +20 -0
  105. package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
  106. package/dist/runtime/hooks/useGlobalComponents.js +10 -0
  107. package/dist/runtime/hooks/useI18n.js +5 -3
  108. package/dist/runtime/hooks/useI18nText.d.ts +1 -0
  109. package/dist/runtime/hooks/useI18nText.js +10 -0
  110. package/dist/runtime/hooks/usePages.d.ts +2 -0
  111. package/dist/runtime/hooks/usePages.js +12 -3
  112. package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
  113. package/dist/runtime/hooks/useSearchHooks.js +14 -0
  114. package/dist/runtime/hooks/useSite.d.ts +1 -0
  115. package/dist/runtime/hooks/useSite.js +9 -2
  116. package/dist/runtime/index.d.ts +3 -1
  117. package/dist/runtime/index.js +5 -1
  118. package/dist/runtime/initPageData.js +10 -10
  119. package/dist/runtime/route.js +5 -5
  120. package/dist/runtime/utils.js +6 -6
  121. package/dist/theme/components/Link/useLinkNavigate.js +1 -1
  122. package/dist/theme/components/Llms/LlmsHint.js +23 -6
  123. package/dist/theme/components/Nav/NavMenu.css +4 -0
  124. package/dist/theme/components/Nav/NavMenu.d.ts +4 -2
  125. package/dist/theme/components/Nav/NavMenu.js +17 -9
  126. package/dist/theme/components/Nav/index.d.ts +7 -1
  127. package/dist/theme/components/Nav/index.js +13 -4
  128. package/dist/theme/components/NavHamburger/index.d.ts +2 -1
  129. package/dist/theme/components/NavHamburger/index.js +8 -2
  130. package/dist/theme/components/NavList/context.d.ts +1 -0
  131. package/dist/theme/components/NavList/context.js +3 -0
  132. package/dist/theme/components/NavList/index.d.ts +6 -0
  133. package/dist/theme/components/NavList/index.js +17 -0
  134. package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +3 -2
  135. package/dist/theme/components/NavScreen/NavScreenMenu.js +42 -6
  136. package/dist/theme/components/NavScreen/index.css +0 -10
  137. package/dist/theme/components/NavScreen/index.d.ts +2 -1
  138. package/dist/theme/components/NavScreen/index.js +11 -3
  139. package/dist/theme/components/PackageManagerTabs/index.js +2 -2
  140. package/dist/theme/components/ReadPercent/useReadPercent.js +1 -0
  141. package/dist/theme/components/Search/SearchButton.css +1 -0
  142. package/dist/theme/components/Search/SearchPanel.css +47 -9
  143. package/dist/theme/components/Search/SearchPanel.js +104 -210
  144. package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
  145. package/dist/theme/components/Search/logic/providers/LocalProvider.js +24 -14
  146. package/dist/theme/components/Search/logic/search.js +1 -1
  147. package/dist/theme/components/Search/useSearchPanel.d.ts +23 -0
  148. package/dist/theme/components/Search/useSearchPanel.js +155 -0
  149. package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
  150. package/dist/theme/components/SourceCode/index.js +1 -1
  151. package/dist/theme/components/Steps/index.css +3 -3
  152. package/dist/theme/components/SwitchAppearance/getClipPath.d.ts +8 -0
  153. package/dist/theme/components/SwitchAppearance/getClipPath.js +13 -0
  154. package/dist/theme/components/SwitchAppearance/index.js +9 -7
  155. package/dist/theme/components/Tabs/index.js +4 -4
  156. package/dist/theme/components/Tag/index.js +2 -2
  157. package/dist/theme/index.d.ts +1 -0
  158. package/dist/theme/index.js +1 -0
  159. package/dist/theme/layout/DocLayout/index.js +2 -2
  160. package/dist/theme/layout/Layout/index.js +12 -4
  161. package/dist/theme/logic/useFullTextSearch.js +6 -1
  162. package/dist/theme/logic/utils.d.ts +0 -2
  163. package/dist/theme/logic/utils.js +56 -6
  164. package/dist/theme/styles/vars/shiki-vars.css +1 -1
  165. package/dist/tinypool~0.js +5 -3
  166. package/dist/{4538~0.js → t~0.js} +2 -2
  167. package/package.json +15 -16
  168. package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +0 -29
  169. package/dist/node/utils/normalizePath.d.ts +0 -3
  170. package/dist/node/utils/normalizePath.js +0 -10
  171. package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +0 -2
  172. package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +0 -30
  173. package/dist/theme/logic/useHandler.d.ts +0 -6
  174. package/dist/theme/logic/useHandler.js +0 -7
  175. /package/dist/{9857~0.js → 4~0.js} +0 -0
  176. /package/dist/{8016~0.js → i~0.js} +0 -0
  177. /package/dist/{5357~0.js → r~0.js} +0 -0
  178. /package/dist/{102~0.js → t2~0.js} +0 -0
  179. /package/dist/{9940~0.js → tx~0.js} +0 -0
@@ -0,0 +1,155 @@
1
+ import { usePageData, useSearchHooks } from "@rspress/core/runtime";
2
+ import { debounce } from "@rspress/shared/lodash-es";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
5
+ import { PageSearcher } from "./logic/search.js";
6
+ import { RenderType } from "./logic/types.js";
7
+ const useDebounce = (cb)=>{
8
+ const cbRef = useRef(cb);
9
+ cbRef.current = cb;
10
+ return useCallback(debounce((...args)=>cbRef.current(...args), 150), []);
11
+ };
12
+ function useSearchPanel({ focused, searchInputRef }) {
13
+ const { siteData, page: { lang, version } } = usePageData();
14
+ const userSearchHooks = useSearchHooks();
15
+ const { search, title: siteTitle } = siteData;
16
+ const [query, setQuery] = useState('');
17
+ const [searchResult, setSearchResult] = useState([]);
18
+ const [isSearching, setIsSearching] = useState(false);
19
+ const [resultTabIndex, setResultTabIndex] = useState(0);
20
+ const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
21
+ const [initStatus, setInitStatus] = useState('initial');
22
+ const [searchError, setSearchError] = useState();
23
+ const pageSearcherRef = useRef(null);
24
+ const pageSearcherConfigRef = useRef(null);
25
+ const searchEnabled = false !== search;
26
+ const searchOptions = false === search ? {} : search;
27
+ const versionedSearch = searchEnabled && (search?.versioned ?? true);
28
+ const searchIndexURL = searchEnabled ? getSearchIndexURL(lang, versionedSearch ? version : '') : void 0;
29
+ const DEFAULT_RESULT = [
30
+ {
31
+ group: siteTitle,
32
+ result: [],
33
+ renderType: RenderType.Default
34
+ }
35
+ ];
36
+ const createSearcher = ()=>{
37
+ if (pageSearcherRef.current) return pageSearcherRef.current;
38
+ const pageSearcherConfig = {
39
+ currentLang: lang,
40
+ currentVersion: version
41
+ };
42
+ const pageSearcher = new PageSearcher({
43
+ indexName: siteTitle,
44
+ ...searchOptions,
45
+ ...pageSearcherConfig
46
+ });
47
+ pageSearcherRef.current = pageSearcher;
48
+ pageSearcherConfigRef.current = pageSearcherConfig;
49
+ return pageSearcher;
50
+ };
51
+ const initSearch = async ()=>{
52
+ if ('initial' !== initStatus) return;
53
+ const searcher = createSearcher();
54
+ setSearchError(void 0);
55
+ setInitStatus('initing');
56
+ try {
57
+ await searcher.init();
58
+ } catch (error) {
59
+ if (pageSearcherRef.current !== searcher) return;
60
+ setSearchError(error instanceof Error ? error.message : String(error));
61
+ setInitStatus('error');
62
+ setIsSearching(false);
63
+ return;
64
+ }
65
+ if (pageSearcherRef.current !== searcher) return;
66
+ setInitStatus('inited');
67
+ const currentQuery = searchInputRef.current?.value;
68
+ if (currentQuery) {
69
+ const matched = await searcher.match(currentQuery);
70
+ if (pageSearcherRef.current !== searcher || searchInputRef.current?.value !== currentQuery) return;
71
+ setSearchResult(matched || DEFAULT_RESULT);
72
+ setIsSearching(false);
73
+ }
74
+ };
75
+ useEffect(()=>{
76
+ if (!searchEnabled) return;
77
+ if (focused) {
78
+ setSearchResult(DEFAULT_RESULT);
79
+ initSearch();
80
+ } else setQuery('');
81
+ }, [
82
+ focused,
83
+ searchEnabled
84
+ ]);
85
+ useEffect(()=>{
86
+ if (!searchEnabled) return;
87
+ const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
88
+ const isLangChanged = lang !== currentLang;
89
+ const isVersionChanged = versionedSearch && version !== currentVersion;
90
+ if (isLangChanged || isVersionChanged) {
91
+ setInitStatus('initial');
92
+ setSearchError(void 0);
93
+ setIsSearching(false);
94
+ pageSearcherRef.current = null;
95
+ createSearcher().fetchSearchIndex().catch(()=>{});
96
+ }
97
+ }, [
98
+ lang,
99
+ version,
100
+ versionedSearch,
101
+ searchEnabled
102
+ ]);
103
+ const handleQueryChangedImpl = async (value)=>{
104
+ let newQuery = value;
105
+ setQuery(newQuery);
106
+ if (!newQuery) return void setIsSearching(false);
107
+ const result = [];
108
+ if (userSearchHooks.beforeSearch) {
109
+ const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
110
+ if (transformedQuery) newQuery = transformedQuery;
111
+ }
112
+ const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
113
+ if (defaultSearchResult) result.push(...defaultSearchResult);
114
+ if (userSearchHooks.onSearch) {
115
+ const customSearchResult = await userSearchHooks.onSearch(newQuery, result);
116
+ if (customSearchResult) result.push(...customSearchResult.map((item)=>({
117
+ renderType: RenderType.Custom,
118
+ ...item
119
+ })));
120
+ }
121
+ if (userSearchHooks.afterSearch) await userSearchHooks.afterSearch(newQuery, result);
122
+ if (searchInputRef.current?.value === newQuery) {
123
+ setCurrentSuggestionIndex(0);
124
+ setSearchResult(result || DEFAULT_RESULT);
125
+ setIsSearching(false);
126
+ }
127
+ };
128
+ const handleQueryChange = useDebounce(handleQueryChangedImpl);
129
+ const handleQueryInput = (value)=>{
130
+ setIsSearching(Boolean(value));
131
+ handleQueryChange(value);
132
+ };
133
+ const clearQuery = ()=>{
134
+ setQuery('');
135
+ setIsSearching(false);
136
+ };
137
+ return {
138
+ searchEnabled,
139
+ clearQuery,
140
+ currentRenderType: searchResult[resultTabIndex]?.renderType ?? RenderType.Default,
141
+ currentSuggestions: searchResult[resultTabIndex]?.result ?? [],
142
+ handleQueryInput,
143
+ initStatus,
144
+ isSearching,
145
+ resultTabIndex,
146
+ searchError,
147
+ searchIndexURL,
148
+ searchResult,
149
+ query,
150
+ currentSuggestionIndex,
151
+ setCurrentSuggestionIndex,
152
+ setResultTabIndex
153
+ };
154
+ }
155
+ export { useSearchPanel };
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import virtual_social_links from "virtual-social-links";
2
+ import { socialLinks } from "@rspress/core/runtime";
3
3
  import "./index.css";
4
4
  import { GithubStars } from "./GithubStars.js";
5
5
  import { useHoverGroup } from "../HoverGroup/useHoverGroup.js";
@@ -8,7 +8,7 @@ const SocialLink = (props)=>{
8
8
  const { icon, mode = 'link', content } = link;
9
9
  let IconComp = /*#__PURE__*/ jsx(Fragment, {});
10
10
  if (icon) {
11
- const html = 'string' == typeof icon ? virtual_social_links[icon] : icon.svg;
11
+ const html = 'string' == typeof icon ? socialLinks[icon] : icon.svg;
12
12
  IconComp = /*#__PURE__*/ jsx("div", {
13
13
  className: "rp-social-links__icon",
14
14
  dangerouslySetInnerHTML: {
@@ -6,7 +6,7 @@ function SourceCode(props) {
6
6
  const { href, platform = 'github' } = props;
7
7
  const t = useI18n();
8
8
  return /*#__PURE__*/ jsx("div", {
9
- className: "rp-not-doc rp-source-code",
9
+ className: "rp-not-doc rp-source-code rp-toc-exclude",
10
10
  children: /*#__PURE__*/ jsxs("a", {
11
11
  href: href,
12
12
  target: "_blank",
@@ -12,14 +12,14 @@
12
12
  margin-left: 1rem;
13
13
  }
14
14
 
15
- .rp-steps h3 {
15
+ .rp-steps > :is(h2, h3, h4, h5, h6) {
16
16
  counter-increment: step;
17
17
  min-height: var(--rp-steps-size);
18
18
  margin-top: 0;
19
19
  position: relative;
20
20
  }
21
21
 
22
- .rp-steps h3:before {
22
+ .rp-steps > :is(h2, h3, h4, h5, h6):before {
23
23
  content: counter(step);
24
24
  top: calc(var(--rp-steps-size)/2 + var(--rp-steps-offset-y));
25
25
  left: calc(-1*var(--rp-steps-gap));
@@ -40,7 +40,7 @@
40
40
  transform: translate(-50%, -50%);
41
41
  }
42
42
 
43
- .rp-steps h3 .rp-header-anchor {
43
+ .rp-steps > :is(h2, h3, h4, h5, h6) .rp-header-anchor {
44
44
  top: calc(var(--rp-steps-size)/2 + var(--rp-steps-offset-y));
45
45
  left: calc(-1*var(--rp-steps-gap) - var(--rp-steps-size)/2);
46
46
  position: absolute;
@@ -0,0 +1,8 @@
1
+ type ClipPathOptions = {
2
+ height: number;
3
+ width: number;
4
+ x: number;
5
+ y: number;
6
+ };
7
+ export declare const getClipPath: ({ height, width, x, y }: ClipPathOptions) => string[];
8
+ export {};
@@ -0,0 +1,13 @@
1
+ const roundPercentage = (value)=>Math.round(1e6 * value) / 1e6;
2
+ const getClipPath = ({ height, width, x, y })=>{
3
+ const endRadius = Math.hypot(Math.max(x, width - x + 200), Math.max(y, height - y + 200));
4
+ const normalizedDiagonal = Math.hypot(width, height) / Math.SQRT2;
5
+ const xPercentage = roundPercentage(x / width * 100);
6
+ const yPercentage = roundPercentage(y / height * 100);
7
+ const endRadiusPercentage = roundPercentage(endRadius / normalizedDiagonal * 100);
8
+ return [
9
+ `circle(0% at ${xPercentage}% ${yPercentage}%)`,
10
+ `circle(${endRadiusPercentage}% at ${xPercentage}% ${yPercentage}%)`
11
+ ];
12
+ };
13
+ export { getClipPath };
@@ -5,6 +5,7 @@ import { useContext } from "react";
5
5
  import "./global.css";
6
6
  import "./index.css";
7
7
  import { flushSync } from "react-dom";
8
+ import { getClipPath } from "./getClipPath.js";
8
9
  const supportAppearanceTransition = ()=>'function' == typeof document?.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
9
10
  const removeClipViewTransition = ()=>{
10
11
  document.documentElement.classList.add('rp-appearance-transition');
@@ -23,7 +24,6 @@ function SwitchAppearance({ onClick }) {
23
24
  if (supported && enabled) {
24
25
  const x = event.clientX;
25
26
  const y = event.clientY;
26
- const endRadius = Math.hypot(Math.max(x, innerWidth - x + 200), Math.max(y, innerHeight - y + 200));
27
27
  const dispose = removeClipViewTransition();
28
28
  const transition = document.startViewTransition(async ()=>{
29
29
  flushSync(()=>{
@@ -31,10 +31,12 @@ function SwitchAppearance({ onClick }) {
31
31
  onClick?.();
32
32
  });
33
33
  });
34
- const clipPath = [
35
- `circle(0px at ${x}px ${y}px)`,
36
- `circle(${endRadius}px at ${x}px ${y}px)`
37
- ];
34
+ const clipPath = getClipPath({
35
+ height: innerHeight,
36
+ width: innerWidth,
37
+ x,
38
+ y
39
+ });
38
40
  transition.ready.then(()=>{
39
41
  document.documentElement.animate({
40
42
  clipPath: isDark ? [
@@ -43,12 +45,12 @@ function SwitchAppearance({ onClick }) {
43
45
  }, {
44
46
  duration: 400,
45
47
  easing: 'ease-in',
48
+ fill: 'both',
46
49
  pseudoElement: isDark ? '::view-transition-old(root)' : '::view-transition-new(root)',
47
50
  id: ''
48
- }).finished.then(()=>{
49
- dispose();
50
51
  });
51
52
  });
53
+ transition.finished.then(dispose, dispose);
52
54
  } else {
53
55
  setTheme(nextTheme);
54
56
  onClick?.();
@@ -32,6 +32,10 @@ const Tabs = /*#__PURE__*/ forwardRef((props, ref)=>{
32
32
  children,
33
33
  values
34
34
  ]);
35
+ const defaultValueIndex = void 0 !== defaultValue ? tabValues.findIndex((item)=>item.value === defaultValue) : -1;
36
+ const initialActiveIndex = -1 === defaultValueIndex ? defaultIndex ?? 0 : defaultValueIndex;
37
+ const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
38
+ const [storageIndex, setStorageIndex] = useStorageValue(`${groupIdPrefix}${groupId}`, initialActiveIndex.toString());
35
39
  if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
36
40
  children: tabValues.map(({ label, content })=>/*#__PURE__*/ jsxs(Fragment, {
37
41
  children: [
@@ -41,10 +45,6 @@ const Tabs = /*#__PURE__*/ forwardRef((props, ref)=>{
41
45
  ]
42
46
  }))
43
47
  });
44
- const defaultValueIndex = void 0 !== defaultValue ? tabValues.findIndex((item)=>item.value === defaultValue) : -1;
45
- const initialActiveIndex = -1 === defaultValueIndex ? defaultIndex ?? 0 : defaultValueIndex;
46
- const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
47
- const [storageIndex, setStorageIndex] = useStorageValue(`${groupIdPrefix}${groupId}`, initialActiveIndex.toString());
48
48
  const currentIndex = groupId ? Number(storageIndex) : activeIndex;
49
49
  return /*#__PURE__*/ jsxs("div", {
50
50
  className: clsx('rp-tabs', className),
@@ -62,7 +62,7 @@ const Tag_Tag = ({ tag })=>{
62
62
  })
63
63
  ]
64
64
  });
65
- if ('deprecated' === normalizedTag) return /*#__PURE__*/ jsxs(Badge, {
65
+ else if ('deprecated' === normalizedTag) return /*#__PURE__*/ jsxs(Badge, {
66
66
  type: "danger",
67
67
  children: [
68
68
  /*#__PURE__*/ jsx(SvgWrapper, {
@@ -73,7 +73,7 @@ const Tag_Tag = ({ tag })=>{
73
73
  })
74
74
  ]
75
75
  });
76
- if ('new' === normalizedTag) return /*#__PURE__*/ jsx(Badge, {
76
+ else if ('new' === normalizedTag) return /*#__PURE__*/ jsx(Badge, {
77
77
  text: "new",
78
78
  type: "tip"
79
79
  });
@@ -25,6 +25,7 @@ export { LlmsContainer, type LlmsContainerProps, LlmsCopyButton, type LlmsCopyBu
25
25
  export { LlmsCopyRow } from './components/Llms/LlmsCopyRow.js';
26
26
  export { LlmsOpenRow } from './components/Llms/LlmsOpenRow.js';
27
27
  export { Nav, type NavProps } from './components/Nav/index.js';
28
+ export { NavList, type NavListProps } from './components/NavList/index.js';
28
29
  export { NavHamburger } from './components/NavHamburger/index.js';
29
30
  export { NavTitle } from './components/NavTitle/index.js';
30
31
  export { Outline } from './components/Outline/index.js';
@@ -25,6 +25,7 @@ export { LlmsContainer, LlmsCopyButton, LlmsHint, LlmsViewOptions, useMdUrl } fr
25
25
  export { LlmsCopyRow } from "./components/Llms/LlmsCopyRow.js";
26
26
  export { LlmsOpenRow } from "./components/Llms/LlmsOpenRow.js";
27
27
  export { Nav } from "./components/Nav/index.js";
28
+ export { NavList } from "./components/NavList/index.js";
28
29
  export { NavHamburger } from "./components/NavHamburger/index.js";
29
30
  export { NavTitle } from "./components/NavTitle/index.js";
30
31
  export { Outline } from "./components/Outline/index.js";
@@ -7,6 +7,8 @@ import "./index.css";
7
7
  function DocLayout(props) {
8
8
  const { beforeDocFooter, afterDocFooter, beforeDoc, afterDoc, beforeDocContent, afterDocContent, beforeOutline, afterOutline, beforeSidebar, afterSidebar, components } = props;
9
9
  const { frontmatter } = useFrontmatter();
10
+ const { isOutlineOpen, isSidebarOpen, sidebarMenu, asideLayoutRef, sidebarLayoutRef } = useSidebarMenu(beforeOutline, afterOutline);
11
+ const { rspressDocRef } = useWatchToc();
10
12
  const isOverviewPage = frontmatter?.overview ?? false;
11
13
  const sidebar = frontmatter?.sidebar ?? true;
12
14
  const showSidebar = true === sidebar;
@@ -25,8 +27,6 @@ function DocLayout(props) {
25
27
  })
26
28
  });
27
29
  const isDocWide = 'doc-wide' === pageType;
28
- const { isOutlineOpen, isSidebarOpen, sidebarMenu, asideLayoutRef, sidebarLayoutRef } = useSidebarMenu(beforeOutline, afterOutline);
29
- const { rspressDocRef } = useWatchToc();
30
30
  return /*#__PURE__*/ jsxs(Fragment, {
31
31
  children: [
32
32
  showSidebarMenu && /*#__PURE__*/ jsx("div", {
@@ -58,8 +58,13 @@ const HeadTags = /*#__PURE__*/ memo((props)=>{
58
58
  children: frontmatterTags ?? null
59
59
  });
60
60
  });
61
+ const ClientEffects = ()=>{
62
+ useSetup();
63
+ useScrollReset();
64
+ return null;
65
+ };
61
66
  function Layout(props) {
62
- const { top, bottom, beforeDocFooter, afterDocFooter, beforeDoc, afterDoc, beforeDocContent, afterDocContent, beforeSidebar, afterSidebar, beforeOutline, afterOutline, beforeNavTitle, afterNavTitle, navTitle, beforeNav, afterNav, beforeHero, afterHero, beforeFeatures, afterFeatures, beforeNavMenu, afterNavMenu, components, HomeLayout = theme_HomeLayout, NotFoundLayout = theme_NotFoundLayout } = props;
67
+ const { top, bottom, beforeDocFooter, afterDocFooter, beforeDoc, afterDoc, beforeDocContent, afterDocContent, beforeSidebar, afterSidebar, beforeOutline, afterOutline, beforeNavTitle, afterNavTitle, navTitle, beforeNav, afterNav, beforeHero, afterHero, beforeFeatures, afterFeatures, beforeLeftNavItems, afterLeftNavItems, beforeRightNavItems, afterRightNavItems, beforeNavMenu, afterNavMenu, components, HomeLayout = theme_HomeLayout, NotFoundLayout = theme_NotFoundLayout } = props;
63
68
  const docProps = {
64
69
  beforeDocFooter,
65
70
  afterDocFooter,
@@ -84,6 +89,7 @@ function Layout(props) {
84
89
  const { frontmatter } = useFrontmatter();
85
90
  const { pageType, lang: currentLang, title: articleTitle } = page;
86
91
  const localesData = useLocaleSiteData();
92
+ const { navbar: showNavbar = true } = frontmatter;
87
93
  let title = frontmatter.title ?? articleTitle;
88
94
  const mainTitle = site.title || localesData.title || '';
89
95
  title = title && ('doc' === pageType || 'doc-wide' === pageType) ? concatTitle(title, frontmatter.titleSuffix || mainTitle) : 'home' === pageType ? concatTitle(mainTitle, frontmatter.titleSuffix) : '404' === pageType ? concatTitle('404', mainTitle) : mainTitle;
@@ -114,11 +120,9 @@ function Layout(props) {
114
120
  if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
115
121
  children: getContentLayout()
116
122
  });
117
- useSetup();
118
- useScrollReset();
119
- const { frontmatter: { navbar: showNavbar = true } } = useFrontmatter();
120
123
  return /*#__PURE__*/ jsxs(Fragment, {
121
124
  children: [
125
+ /*#__PURE__*/ jsx(ClientEffects, {}),
122
126
  /*#__PURE__*/ jsx(HeadTags, {
123
127
  lang: currentLang,
124
128
  title: title,
@@ -133,6 +137,10 @@ function Layout(props) {
133
137
  beforeNavTitle: beforeNavTitle,
134
138
  afterNavTitle: afterNavTitle,
135
139
  navTitle: navTitle,
140
+ beforeLeftNavItems: beforeLeftNavItems,
141
+ afterLeftNavItems: afterLeftNavItems,
142
+ beforeRightNavItems: beforeRightNavItems,
143
+ afterRightNavItems: afterRightNavItems,
136
144
  beforeNavMenu: beforeNavMenu,
137
145
  afterNavMenu: afterNavMenu
138
146
  }),
@@ -15,7 +15,12 @@ function useFullTextSearch() {
15
15
  currentVersion: page.version
16
16
  });
17
17
  searchRef.current = searcher;
18
- await searcher.init();
18
+ try {
19
+ await searcher.init();
20
+ } catch (error) {
21
+ console.error('[Rspress] Failed to initialize full-text search:', error);
22
+ return;
23
+ }
19
24
  setInitialized(true);
20
25
  }
21
26
  }
@@ -16,8 +16,6 @@ export declare function renderHtmlOrText(str?: string | number | null): {
16
16
  * @private
17
17
  */
18
18
  export declare function renderInlineMarkdown(text: string): {
19
- children: string | null;
20
- } | {
21
19
  dangerouslySetInnerHTML: {
22
20
  __html: string;
23
21
  };
@@ -16,12 +16,11 @@ function renderHtmlOrText(str) {
16
16
  children: str.replace(/\\</g, '<').replace(/\\>/g, '>').replace(/&lt;/g, '<').replace(/&gt;/g, '>')
17
17
  };
18
18
  }
19
- const CODE_TEXT_PATTERN = /`(.*?)`/g;
20
19
  const STRONG_TEXT_PATTERN = /\*{2}(?!\*)(.*?)\*{2}(?!\*)/g;
21
20
  const EMPHASIS_TEXT_PATTERN = /\*(?!\*)(.*?)\*(?!\*)/g;
22
21
  const DELETE_TEXT_PATTERN = /~{2}(.*?)~{2}/g;
23
- const INLINE_CODE_PATTERN = /`[^`]+`/g;
24
22
  const HTML_TAG_PATTERN = /<\/?[a-z][^>]*>/gi;
23
+ const HTML_VOID_ELEMENT_PATTERN = /<(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)(?=[\s/>])[^>]*>/gi;
25
24
  const HTML_ENTITY_PATTERN = /&(#\d+|#x[0-9a-f]+|[a-z][0-9a-z]*);/gi;
26
25
  const NAMED_HTML_ENTITIES = {
27
26
  amp: '&',
@@ -40,12 +39,63 @@ function decodeHtmlEntities(text) {
40
39
  return isScalarValue ? String.fromCodePoint(codePoint) : match;
41
40
  });
42
41
  }
42
+ function escapeHtml(text) {
43
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
44
+ }
45
+ function protectInlineMarkdown(text) {
46
+ let marker = '\u0000';
47
+ while(text.includes(marker))marker += '\u0000';
48
+ const fragments = [];
49
+ const protect = (value, html = escapeHtml(value))=>{
50
+ const index = fragments.push({
51
+ text: value,
52
+ html
53
+ }) - 1;
54
+ return `${marker}${index}${marker}`;
55
+ };
56
+ const pattern = /\\([!-/:-@[-`{-~])|`+|<code\b[^>]*>[\s\S]*?<\/code>|&(#\d+|#x[0-9a-f]+|[a-z][0-9a-z]*);/gi;
57
+ const backticks = /`+/g;
58
+ let result = '';
59
+ let offset = 0;
60
+ let match;
61
+ while(match = pattern.exec(text)){
62
+ result += text.slice(offset, match.index);
63
+ if (match[1]) result += protect(match[1]);
64
+ else if (match[0].startsWith('&')) result += protect(decodeHtmlEntities(match[0]), match[0]);
65
+ else if (match[0].startsWith('<')) result += protect(decodeHtmlEntities(match[0].replace(HTML_TAG_PATTERN, '')), match[0]);
66
+ else {
67
+ backticks.lastIndex = pattern.lastIndex;
68
+ let closing;
69
+ while(closing = backticks.exec(text))if (closing[0].length === match[0].length) break;
70
+ if (closing) {
71
+ let value = text.slice(pattern.lastIndex, closing.index).replace(/\r\n?|\n/g, ' ');
72
+ if (value.startsWith(' ') && value.endsWith(' ') && /[^ ]/.test(value)) value = value.slice(1, -1);
73
+ result += protect(value, `<code>${escapeHtml(value)}</code>`);
74
+ pattern.lastIndex = closing.index + closing[0].length;
75
+ } else result += protect(match[0]);
76
+ }
77
+ offset = pattern.lastIndex;
78
+ }
79
+ result += text.slice(offset);
80
+ return {
81
+ text: result,
82
+ restore: (value, format)=>value.replace(new RegExp(`${marker}(\\d+)${marker}`, 'g'), (_, index)=>fragments[Number(index)][format])
83
+ };
84
+ }
43
85
  function renderInlineMarkdown(text) {
44
- const htmlText = text.replace(INLINE_CODE_PATTERN, (match)=>match.replace(/</g, '&lt;')).replace(STRONG_TEXT_PATTERN, '<strong>$1</strong>').replace(EMPHASIS_TEXT_PATTERN, '<em>$1</em>').replace(DELETE_TEXT_PATTERN, '<del>$1</del>').replace(CODE_TEXT_PATTERN, '<code>$1</code>');
45
- return renderHtmlOrText(htmlText);
86
+ const protectedText = protectInlineMarkdown(text);
87
+ const source = renderHtmlOrText(protectedText.text);
88
+ const htmlText = ('children' in source ? escapeHtml(source.children ?? '') : source.dangerouslySetInnerHTML.__html).replace(STRONG_TEXT_PATTERN, '<strong>$1</strong>').replace(EMPHASIS_TEXT_PATTERN, '<em>$1</em>').replace(DELETE_TEXT_PATTERN, '<del>$1</del>');
89
+ return {
90
+ dangerouslySetInnerHTML: {
91
+ __html: protectedText.restore(htmlText, 'html')
92
+ }
93
+ };
46
94
  }
47
95
  function parseInlineMarkdownText(mdx) {
48
- const plainText = mdx.replace(INLINE_CODE_PATTERN, (match)=>match.replace(/</g, '&lt;')).replace(STRONG_TEXT_PATTERN, '$1').replace(EMPHASIS_TEXT_PATTERN, '$1').replace(DELETE_TEXT_PATTERN, '$1').replace(CODE_TEXT_PATTERN, '$1').replace(HTML_TAG_PATTERN, '');
49
- return decodeHtmlEntities(plainText).trim();
96
+ const protectedText = protectInlineMarkdown(mdx);
97
+ const source = renderHtmlOrText(protectedText.text.replace(HTML_VOID_ELEMENT_PATTERN, ''));
98
+ const plainText = ('children' in source ? source.children ?? '' : source.dangerouslySetInnerHTML.__html.replace(HTML_TAG_PATTERN, '')).replace(STRONG_TEXT_PATTERN, '$1').replace(EMPHASIS_TEXT_PATTERN, '$1').replace(DELETE_TEXT_PATTERN, '$1');
99
+ return protectedText.restore(decodeHtmlEntities(plainText), 'text').trim();
50
100
  }
51
101
  export { parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown };
@@ -2,7 +2,7 @@
2
2
  --shiki-foreground: inherit;
3
3
  --shiki-background: transparent;
4
4
  --shiki-token-constant: #1976d2;
5
- --shiki-token-string: #31a94d;
5
+ --shiki-token-string: #032f62;
6
6
  --shiki-token-comment: #b6b4b4;
7
7
  --shiki-token-keyword: #cf2727;
8
8
  --shiki-token-parameter: #f59403;
@@ -678,8 +678,10 @@ var ThreadPool = class {
678
678
  const totalCapacity = this.options.maxQueue + this.pendingCapacity();
679
679
  if (this.taskQueue.size >= totalCapacity) if (0 === this.options.maxQueue) return Promise.reject(Errors.NoTaskQueueAvailable());
680
680
  else return Promise.reject(Errors.TaskQueueAtLimit());
681
- if (this.workers.size < this.options.maxThreads) this._addNewWorker();
682
- this.taskQueue.push(taskInfo);
681
+ else {
682
+ if (this.workers.size < this.options.maxThreads) this._addNewWorker();
683
+ this.taskQueue.push(taskInfo);
684
+ }
683
685
  return ret;
684
686
  }
685
687
  let workerInfo = this.workers.findAvailable();
@@ -691,7 +693,7 @@ var ThreadPool = class {
691
693
  }
692
694
  if (null === workerInfo) {
693
695
  if (this.options.maxQueue <= 0 && !waitingForNewWorker) return Promise.reject(Errors.NoTaskQueueAvailable());
694
- this.taskQueue.push(taskInfo);
696
+ else this.taskQueue.push(taskInfo);
695
697
  return ret;
696
698
  }
697
699
  const now = performance.now();
@@ -1,5 +1,5 @@
1
- import { __webpack_require__ } from "./rslib-runtime~0.js";
2
- __webpack_require__.add({
1
+ import { moduleFactories } from "./rslib-runtime~0.js";
2
+ moduleFactories.add({
3
3
  "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (module) {
4
4
  let p = process || {}, argv = p.argv || [], env = p.env || {};
5
5
  let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || "win32" === p.platform || (p.stdout || {}).isTTY && "dumb" !== env.TERM || !!env.CI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.21",
3
+ "version": "2.0.23",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -60,8 +60,9 @@
60
60
  "dependencies": {
61
61
  "@mdx-js/mdx": "^3.1.1",
62
62
  "@mdx-js/react": "^3.1.1",
63
- "@rsbuild/core": "^2.1.13",
63
+ "@rsbuild/core": "^2.2.10",
64
64
  "@rsbuild/plugin-react": "~2.1.0",
65
+ "@rspress/shared": "2.0.23",
65
66
  "@shikijs/rehype": "^4.2.0",
66
67
  "@types/mdast": "^4.0.4",
67
68
  "@types/react": "^19.2.18",
@@ -80,7 +81,7 @@
80
81
  "react-dom": "^19.2.8",
81
82
  "react-lazy-with-preload": "^2.2.1",
82
83
  "react-render-to-markdown": "19.1.0",
83
- "react-router-dom": "^7.18.2",
84
+ "react-router-dom": "^7.18.4",
84
85
  "rehype-external-links": "^3.0.0",
85
86
  "rehype-raw": "^7.0.0",
86
87
  "remark-cjk-friendly": "^2.3.1",
@@ -94,36 +95,34 @@
94
95
  "unified": "^11.0.5",
95
96
  "unist-util-visit": "^5.1.0",
96
97
  "unist-util-visit-children": "^3.0.0",
97
- "vfile": "^6.0.3",
98
- "@rspress/shared": "2.0.21"
98
+ "vfile": "^6.0.3"
99
99
  },
100
100
  "devDependencies": {
101
- "@microsoft/api-extractor": "^7.59.0",
101
+ "@microsoft/api-extractor": "^7.59.2",
102
102
  "@rsbuild/plugin-sass": "~2.0.1",
103
103
  "@rsbuild/plugin-svgr": "^2.0.5",
104
- "@rslib/core": "1.0.0-rc.0",
104
+ "@rspress/config": "1.0.0",
105
105
  "@types/body-scroll-lock": "^3.1.2",
106
106
  "@types/hast": "^3.0.5",
107
107
  "@types/node": "^22.8.1",
108
108
  "@types/nprogress": "^0.2.3",
109
- "@types/react-dom": "^19.2.4",
110
- "@types/web": "^0.0.354",
109
+ "@types/react-dom": "^19.2.7",
110
+ "@types/web": "^0.0.357",
111
111
  "cac": "^7.0.0",
112
112
  "execa": "8.0.1",
113
113
  "mdast-util-directive": "^3.1.0",
114
114
  "mdast-util-mdx-expression": "^2.0.1",
115
- "memfs": "^4.68.1",
116
- "p-map": "^7.0.6",
115
+ "memfs": "^4.78.1",
116
+ "p-map": "^7.0.8",
117
117
  "picocolors": "^1.1.1",
118
- "postcss": "8.5.26",
118
+ "postcss": "8.5.28",
119
119
  "remark-directive": "^4.0.0",
120
120
  "rsbuild-plugin-publint": "^1.0.0",
121
121
  "rsbuild-plugin-virtual-module": "0.4.5",
122
122
  "tinyglobby": "^0.2.17",
123
123
  "tinypool": "^1.1.1",
124
124
  "ts-json-schema-generator": "^2.9.0",
125
- "typescript": "^6.0.3",
126
- "@rspress/config": "1.0.0"
125
+ "typescript": "^6.0.3"
127
126
  },
128
127
  "engines": {
129
128
  "node": "^20.19.0 || >=22.12.0"
@@ -133,8 +132,8 @@
133
132
  "registry": "https://registry.npmjs.org/"
134
133
  },
135
134
  "scripts": {
136
- "build": "node ./scripts/generateJsonSchema.mjs && rslib build",
137
- "dev": "rslib build -w",
135
+ "build": "node ./scripts/generateJsonSchema.mjs && rs lib",
136
+ "dev": "rs lib -w",
138
137
  "reset": "rimraf ./**/node_modules"
139
138
  }
140
139
  }