@rspress/core 2.0.10 → 2.0.11

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 (90) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/3323.js +8 -0
  3. package/dist/{2240.js → 6162.js} +1 -4
  4. package/dist/8006.js +1 -1
  5. package/dist/8857.js +1 -1
  6. package/dist/common-Qw-RoVFD.js +25 -0
  7. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -2
  8. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +1 -2
  9. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +1 -2
  10. package/dist/eject-theme/components/Prompt/icons.tsx +1 -1
  11. package/dist/eject-theme/components/Prompt/index.scss +325 -380
  12. package/dist/eject-theme/components/Search/logic/search.ts +10 -5
  13. package/dist/eject-theme/components/Search/logic/util.test.ts +20 -1
  14. package/dist/eject-theme/components/Search/logic/util.ts +4 -1
  15. package/dist/entry/process.d.ts +1 -0
  16. package/dist/entry/process.js +65 -0
  17. package/dist/entry/utils.d.ts +7 -0
  18. package/dist/entry/utils.js +2 -0
  19. package/dist/entry/worker.d.ts +1 -0
  20. package/dist/entry/worker.js +74 -0
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +1 -0
  23. package/dist/node/PluginDriver.js +1 -1
  24. package/dist/node/auto-nav-sidebar/index.js +1 -1
  25. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  26. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  27. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  28. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  29. package/dist/node/index.d.ts +1 -0
  30. package/dist/node/initRsbuild.js +1 -1
  31. package/dist/node/mdx/options.js +2 -1
  32. package/dist/node/mdx/processor.js +1 -1
  33. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  34. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  35. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  36. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +1 -1
  37. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  38. package/dist/node/mdx/remarkPlugins/fileCodeBlock.d.ts +1 -0
  39. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +9 -4
  40. package/dist/node/mdx/remarkPlugins/image.js +1 -1
  41. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  42. package/dist/node/route/RoutePage.js +1 -1
  43. package/dist/node/route/RouteService.js +1 -1
  44. package/dist/node/route/extractPageData.js +1 -1
  45. package/dist/node/route/normalizeRoutePath.js +1 -1
  46. package/dist/node/runtimeModule/i18n.js +1 -1
  47. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  48. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  49. package/dist/node/runtimeModule/searchHooks.js +1 -1
  50. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  51. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  52. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  53. package/dist/node/serve.js +1 -1
  54. package/dist/node/ssg/renderPages.js +2 -2
  55. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  56. package/dist/node/ssg/ssgEnv.js +1 -1
  57. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  58. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  59. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  60. package/dist/node/ssg-md/renderPage.js +1 -1
  61. package/dist/node/ssg-md/renderPages.js +1 -1
  62. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  63. package/dist/node/utils/checkLanguageParity.js +1 -1
  64. package/dist/node/utils/createHash.js +1 -1
  65. package/dist/node/utils/flattenMdxContent.js +1 -1
  66. package/dist/node/utils/getPageKey.js +1 -1
  67. package/dist/node/utils/reactAlias.js +1 -1
  68. package/dist/runtime/BrowserOnly.d.ts +7 -0
  69. package/dist/runtime/BrowserOnly.js +40 -0
  70. package/dist/runtime/BrowserOnly.test.d.ts +1 -0
  71. package/dist/runtime/index.d.ts +1 -0
  72. package/dist/runtime/index.js +1 -0
  73. package/dist/theme/components/Prompt/icons.js +1 -1
  74. package/dist/theme/components/Prompt/index.css +11 -37
  75. package/dist/theme/components/Search/logic/search.js +5 -3
  76. package/dist/theme/components/Search/logic/util.js +2 -1
  77. package/dist/theme/layout/DocLayout/index.css +4 -0
  78. package/dist/theme/layout/DocLayout/index.js +3 -2
  79. package/dist/theme/logic/useThemeState.d.ts +5 -10
  80. package/dist/theme/logic/useThemeState.js +15 -20
  81. package/dist/utils-B--2TaWv.js +34 -0
  82. package/dist/utils-De75vAgL.js +7 -0
  83. package/package.json +12 -12
  84. package/dist/3425.js +0 -6
  85. package/dist/runtime/getSidebarDataGroup.test.js +0 -68
  86. package/dist/runtime/hooks/useWindowSize.test.js +0 -36
  87. package/dist/runtime/route.test.js +0 -154
  88. package/dist/runtime/utils.test.js +0 -34
  89. package/dist/theme/components/Search/logic/util.test.js +0 -51
  90. /package/dist/{2287.js → 5810.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { writeFile, mkdir, rm, join, isDebugMode } from "../../2287.js";
1
+ import { writeFile, mkdir, rm, join, isDebugMode } from "../../5810.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 "../../2287.js";
1
+ import { node_path, logger, promises } from "../../5810.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 "../../2287.js";
1
+ import { createHash as external_node_crypto_createHash } from "../../5810.js";
2
2
  function createHash(str) {
3
3
  return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, 8);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../2287.js";
1
+ import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../5810.js";
2
2
  import { createError } from "./error.js";
3
3
  import { importStatementRegex } from "../constants.js";
4
4
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../2287.js";
1
+ import { removeLeadingSlash } from "../../5810.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
2
  import "../../8006.js";
3
- import { node_path, core_rspack, logger } from "../../2287.js";
3
+ import { node_path, core_rspack, logger } from "../../5810.js";
4
4
  import { pathExists, readJson } from "./fs.js";
5
5
  import { PACKAGE_ROOT } from "../constants.js";
6
6
  import { hintReactVersion } from "../logger/hint.js";
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface BrowserOnlyProps {
3
+ children: () => ReactNode | Promise<ReactNode>;
4
+ fallback?: ReactNode;
5
+ }
6
+ export declare function BrowserOnly(props: BrowserOnlyProps): ReactNode;
7
+ export default BrowserOnly;
@@ -0,0 +1,40 @@
1
+ import { useEffect, useState } from "react";
2
+ function BrowserOnly(props) {
3
+ const { children, fallback = null } = props;
4
+ const [state, setState] = useState({
5
+ status: 'pending',
6
+ children
7
+ });
8
+ useEffect(()=>{
9
+ let isMounted = true;
10
+ setState({
11
+ status: 'pending',
12
+ children
13
+ });
14
+ Promise.resolve().then(()=>children()).then((content)=>{
15
+ if (isMounted) setState({
16
+ status: 'resolved',
17
+ children,
18
+ content
19
+ });
20
+ }, (error)=>{
21
+ if (isMounted) setState({
22
+ status: 'rejected',
23
+ children,
24
+ error
25
+ });
26
+ });
27
+ return ()=>{
28
+ isMounted = false;
29
+ };
30
+ }, [
31
+ children
32
+ ]);
33
+ if (state.children !== children) return fallback;
34
+ if ('rejected' === state.status) throw state.error;
35
+ if ('resolved' === state.status) return state.content;
36
+ return fallback;
37
+ }
38
+ const runtime_BrowserOnly = BrowserOnly;
39
+ export default runtime_BrowserOnly;
40
+ export { BrowserOnly };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref, } from '@rspress/shared';
2
2
  export { Head, useHead } from '@unhead/react';
3
3
  export * from 'react-router-dom';
4
+ export { BrowserOnly, type BrowserOnlyProps } from './BrowserOnly.js';
4
5
  export { Content } from './Content.js';
5
6
  export { useActiveMatcher } from './hooks/useActiveMatcher.js';
6
7
  export { ThemeContext, useDark } from './hooks/useDark.js';
@@ -1,6 +1,7 @@
1
1
  export * from "react-router-dom";
2
2
  export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
3
3
  export { Head, useHead } from "@unhead/react";
4
+ export { BrowserOnly } from "./BrowserOnly.js";
4
5
  export { Content } from "./Content.js";
5
6
  export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
6
7
  export { ThemeContext, useDark } from "./hooks/useDark.js";
@@ -36,7 +36,7 @@ const AGENT_ICONS = [
36
36
  },
37
37
  {
38
38
  name: 'Cursor',
39
- color: '#434343',
39
+ color: '#737373',
40
40
  svg: /*#__PURE__*/ jsx("svg", {
41
41
  "aria-hidden": "true",
42
42
  viewBox: "0 0 24 24",
@@ -37,7 +37,7 @@
37
37
  .rp-prompt__panel {
38
38
  border-radius: calc(var(--rp-radius) + 5px);
39
39
  color: var(--rp-c-text-1);
40
- background: linear-gradient(180deg, color-mix(in srgb, var(--rp-c-bg) 92%, transparent), color-mix(in srgb, var(--rp-c-bg-soft) 96%, transparent));
40
+ background: color-mix(in srgb, var(--rp-c-bg) 92%, transparent);
41
41
  backdrop-filter: blur(12px);
42
42
  padding: 1rem;
43
43
  position: relative;
@@ -47,9 +47,6 @@
47
47
  content: "";
48
48
  pointer-events: none;
49
49
  border-radius: inherit;
50
- background-image: linear-gradient(90deg, color-mix(in srgb, var(--rp-c-divider-light) 35%, transparent) 1px, transparent 1px),linear-gradient(180deg, color-mix(in srgb, var(--rp-c-divider-light) 28%, transparent) 1px, transparent 1px);
51
- opacity: .28;
52
- background-size: 20px 20px;
53
50
  position: absolute;
54
51
  inset: 0;
55
52
  mask-image: linear-gradient(#0000008c, #0000);
@@ -92,6 +89,10 @@
92
89
  display: inline-flex;
93
90
  }
94
91
 
92
+ .rp-prompt__meta--copied {
93
+ background: color-mix(in srgb, var(--rp-prompt-accent, var(--rp-c-brand-light)) 16%, var(--rp-c-bg));
94
+ }
95
+
95
96
  .rp-prompt__eyebrow {
96
97
  letter-spacing: .08em;
97
98
  text-transform: uppercase;
@@ -145,10 +146,6 @@
145
146
  line-height: 1.65;
146
147
  }
147
148
 
148
- .rp-prompt__meta--copied {
149
- background: color-mix(in srgb, var(--rp-prompt-accent, var(--rp-c-brand-light)) 16%, var(--rp-c-bg));
150
- }
151
-
152
149
  .rp-prompt__ripple {
153
150
  background: color-mix(in srgb, var(--rp-prompt-accent, var(--rp-c-brand-light)) 40%, transparent);
154
151
  pointer-events: none;
@@ -163,13 +160,6 @@
163
160
  transform: scale(0);
164
161
  }
165
162
 
166
- @keyframes rp-prompt-ripple {
167
- to {
168
- opacity: 0;
169
- transform: scale(5);
170
- }
171
- }
172
-
173
163
  .rp-prompt__action-icon {
174
164
  flex: none;
175
165
  width: .875rem;
@@ -267,22 +257,11 @@
267
257
  border-radius: calc(var(--rp-radius) - 2px);
268
258
  font-family: var(--rp-font-family-mono);
269
259
  color: var(--rp-c-text-1);
270
- background: linear-gradient(180deg, color-mix(in srgb, var(--rp-c-bg-soft) 88%, transparent), color-mix(in srgb, var(--rp-c-bg) 94%, transparent));
260
+ background: color-mix(in srgb, var(--rp-c-bg) 94%, transparent);
271
261
  padding: 1rem 1.125rem;
272
262
  font-size: .92rem;
273
263
  line-height: 1.8;
274
264
  position: relative;
275
- box-shadow: inset 0 1px #ffffff73;
276
- }
277
-
278
- .rp-prompt__content-body:before {
279
- content: "";
280
- pointer-events: none;
281
- border-radius: inherit;
282
- border: 1px solid #ffffff73;
283
- position: absolute;
284
- inset: 0;
285
- mask-image: linear-gradient(160deg, #000000d9, #0000 55%);
286
265
  }
287
266
 
288
267
  .rp-prompt__content-body > :first-child {
@@ -338,15 +317,10 @@
338
317
  margin-bottom: 0;
339
318
  }
340
319
 
341
- html.rp-dark .rp-prompt__meta {
342
- background: color-mix(in srgb, var(--rp-prompt-accent, var(--rp-c-brand)) 12%, var(--rp-c-bg));
343
- }
344
-
345
- html.rp-dark .rp-prompt__eyebrow {
346
- color: color-mix(in srgb, var(--rp-prompt-accent, #dbeafe) 92%, white);
347
- }
348
-
349
- html.rp-dark .rp-prompt__content-body {
350
- box-shadow: inset 0 1px #ffffff1a;
320
+ @keyframes rp-prompt-ripple {
321
+ to {
322
+ opacity: 0;
323
+ transform: scale(5);
324
+ }
351
325
  }
352
326
 
@@ -150,10 +150,11 @@ class PageSearcher {
150
150
  const currentHeader = getCurrentHeader(queryIndex);
151
151
  let statementStartIndex = content.slice(0, queryIndex).lastIndexOf('\n');
152
152
  statementStartIndex = -1 === statementStartIndex ? 0 : statementStartIndex;
153
- const statementEndIndex = content.indexOf('\n\n', queryIndex + query.length);
153
+ let statementEndIndex = content.indexOf('\n\n', queryIndex + query.length);
154
+ statementEndIndex = -1 === statementEndIndex ? content.length : statementEndIndex;
154
155
  let statement = content.slice(statementStartIndex, statementEndIndex);
155
- if (statement.length > THRESHOLD_CONTENT_LENGTH) statement = this.#normalizeStatement(statement, query);
156
- const highlightIndex = normalizeTextCase(statement).indexOf(query);
156
+ statement = this.#normalizeStatement(statement, query);
157
+ const highlightIndex = normalizeTextCase(statement).indexOf(normalizeTextCase(query));
157
158
  const highlightInfoList = [
158
159
  {
159
160
  start: highlightIndex,
@@ -176,6 +177,7 @@ class PageSearcher {
176
177
  }
177
178
  }
178
179
  #normalizeStatement(statement, query) {
180
+ if (statement.length <= THRESHOLD_CONTENT_LENGTH) return statement;
179
181
  const queryIndex = normalizeTextCase(statement).indexOf(normalizeTextCase(query));
180
182
  const maxPrefixOrSuffix = Math.floor((THRESHOLD_CONTENT_LENGTH - query.length) / 2);
181
183
  let prefix = statement.slice(0, queryIndex);
@@ -1,4 +1,5 @@
1
1
  const MAX_TITLE_LENGTH = 20;
2
+ const jRegex = /[\u3040-\u309f\u30a0-\u30ff\u31f0-\u31ff]/u;
2
3
  const kRegex = /[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]/u;
3
4
  const cyrillicRegex = /[\u0400-\u04FF]/u;
4
5
  function backTrackHeaders(rawHeaders, index) {
@@ -30,7 +31,7 @@ function normalizeTextCase(text) {
30
31
  const textNormalized = text.toString().toLowerCase().normalize('NFD');
31
32
  if (cyrillicRegex.test(String(text))) return textNormalized.normalize('NFC');
32
33
  const resultWithoutAccents = textNormalized.replace(/[\u0300-\u036f]/g, '');
33
- if (kRegex.test(String(text))) return resultWithoutAccents.normalize('NFC');
34
+ if (jRegex.test(String(text)) || kRegex.test(String(text))) return resultWithoutAccents.normalize('NFC');
34
35
  return resultWithoutAccents;
35
36
  }
36
37
  function removeDomain(url) {
@@ -23,6 +23,10 @@
23
23
  }
24
24
  }
25
25
 
26
+ :root:has(.rp-doc-layout__container--no-menu) {
27
+ --rp-sidebar-menu-height: 0px;
28
+ }
29
+
26
30
  .rp-doc-layout__container {
27
31
  flex-direction: row;
28
32
  justify-content: flex-start;
@@ -13,6 +13,7 @@ function DocLayout(props) {
13
13
  const showSidebarPlaceholder = false === sidebar || 'placeholder' === sidebar;
14
14
  const isLegacyPlaceholder = 'placeholder' === sidebar;
15
15
  const { outline: showOutline = true, footer: showDocFooter = true, pageType } = frontmatter;
16
+ const showSidebarMenu = showSidebar || !isOverviewPage && showOutline;
16
17
  if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
17
18
  children: isOverviewPage ? /*#__PURE__*/ jsx(Overview, {
18
19
  content: /*#__PURE__*/ jsx(DocContent, {
@@ -28,13 +29,13 @@ function DocLayout(props) {
28
29
  const { rspressDocRef } = useWatchToc();
29
30
  return /*#__PURE__*/ jsxs(Fragment, {
30
31
  children: [
31
- /*#__PURE__*/ jsx("div", {
32
+ showSidebarMenu && /*#__PURE__*/ jsx("div", {
32
33
  className: "rp-doc-layout__menu",
33
34
  children: sidebarMenu
34
35
  }),
35
36
  beforeDoc,
36
37
  /*#__PURE__*/ jsxs("div", {
37
- className: "rp-doc-layout__container",
38
+ className: clsx('rp-doc-layout__container', !showSidebarMenu && 'rp-doc-layout__container--no-menu'),
38
39
  children: [
39
40
  showSidebar ? /*#__PURE__*/ jsxs("aside", {
40
41
  className: clsx('rp-doc-layout__sidebar', isSidebarOpen && 'rp-doc-layout__sidebar--open', 'rp-scrollbar'),
@@ -1,16 +1,11 @@
1
- declare global {
2
- interface Window {
3
- MODERN_THEME?: string;
4
- RSPRESS_THEME?: string;
5
- }
6
- }
7
1
  /** Resolved theme value used in the app */
8
- type ThemeValue = 'light' | 'dark';
2
+ export type ThemeValue = 'light' | 'dark';
9
3
  /** Theme config value stored in localStorage */
10
- type ThemeConfigValue = ThemeValue | 'auto';
4
+ export type ThemeConfigValue = ThemeValue | 'auto';
5
+ export declare const getStoredThemeConfig: (theme: ThemeValue, prefersDark: boolean) => ThemeConfigValue;
6
+ export declare const getResolvedTheme: (config: ThemeConfigValue, prefersDark: boolean) => ThemeValue;
11
7
  /**
12
8
  * State provider for theme context.
13
9
  * @internal
14
10
  */
15
- export declare function useThemeState(): readonly [ThemeValue, (value: ThemeValue, storeValue?: ThemeConfigValue) => void];
16
- export {};
11
+ export declare function useThemeState(): readonly [ThemeValue, (value: ThemeValue) => void];
@@ -1,9 +1,15 @@
1
1
  import { useSite } from "@rspress/core/runtime";
2
- import { useCallback, useLayoutEffect, useMemo } from "react";
2
+ import { useCallback, useLayoutEffect } from "react";
3
3
  import { useMediaQuery } from "./useMediaQuery.js";
4
4
  import { useStorageValue } from "./useStorageValue.js";
5
5
  const APPEARANCE_KEY = 'rspress-theme-appearance';
6
6
  const MEDIA_QUERY = '(prefers-color-scheme: dark)';
7
+ const getSystemTheme = (prefersDark)=>prefersDark ? 'dark' : 'light';
8
+ const getStoredThemeConfig = (theme, prefersDark)=>{
9
+ const systemTheme = getSystemTheme(prefersDark);
10
+ return theme === systemTheme ? 'auto' : theme;
11
+ };
12
+ const getResolvedTheme = (config, prefersDark)=>'auto' === config ? getSystemTheme(prefersDark) : config;
7
13
  const applyThemeToDOM = (theme)=>{
8
14
  if (!document?.documentElement) return;
9
15
  const root = document.documentElement;
@@ -16,35 +22,24 @@ function useThemeState() {
16
22
  const disableDarkMode = false === site.themeConfig.darkMode;
17
23
  const prefersDark = useMediaQuery(MEDIA_QUERY);
18
24
  const [storedConfig, setStoredConfig] = useStorageValue(APPEARANCE_KEY, 'auto');
19
- const resolvedTheme = useMemo(()=>{
20
- if ("u" < typeof window) return 'light';
21
- if (disableDarkMode) return 'light';
22
- const defaultTheme = window.RSPRESS_THEME;
23
- if (defaultTheme) return 'dark' === defaultTheme ? 'dark' : 'light';
24
- return 'auto' === storedConfig ? prefersDark ? 'dark' : 'light' : storedConfig;
25
- }, [
26
- disableDarkMode,
27
- prefersDark,
28
- storedConfig
29
- ]);
30
- const setTheme = useCallback((value, storeValue = value)=>{
25
+ const theme = disableDarkMode ? 'light' : getResolvedTheme(storedConfig, prefersDark);
26
+ const setTheme = useCallback((value)=>{
31
27
  if (disableDarkMode) return;
32
- setStoredConfig(storeValue);
28
+ setStoredConfig(getStoredThemeConfig(value, prefersDark));
33
29
  applyThemeToDOM(value);
34
30
  }, [
35
31
  disableDarkMode,
32
+ prefersDark,
36
33
  setStoredConfig
37
34
  ]);
38
35
  useLayoutEffect(()=>{
39
- if (disableDarkMode) return;
40
- applyThemeToDOM(resolvedTheme);
36
+ applyThemeToDOM(theme);
41
37
  }, [
42
- disableDarkMode,
43
- resolvedTheme
38
+ theme
44
39
  ]);
45
40
  return [
46
- resolvedTheme,
41
+ theme,
47
42
  setTheme
48
43
  ];
49
44
  }
50
- export { useThemeState };
45
+ export { getResolvedTheme, getStoredThemeConfig, useThemeState };
@@ -0,0 +1,34 @@
1
+ import { pathToFileURL } from "node:url";
2
+ let importESMCached;
3
+ function getImportESM() {
4
+ if (void 0 === importESMCached) importESMCached = new Function("specifier", "return import(specifier)");
5
+ return importESMCached;
6
+ }
7
+ const handlerCache = new Map();
8
+ async function getHandler(filename, name) {
9
+ let handler = handlerCache.get(`${filename}/${name}`);
10
+ if (void 0 !== handler) return handler;
11
+ try {
12
+ const handlerModule = await import(filename);
13
+ handler = "function" != typeof handlerModule.default && handlerModule.default || handlerModule;
14
+ if ("function" != typeof handler) handler = await handler[name];
15
+ } catch {}
16
+ if ("function" != typeof handler) {
17
+ handler = await getImportESM()(pathToFileURL(filename).href);
18
+ if ("function" != typeof handler) handler = await handler[name];
19
+ }
20
+ if ("function" != typeof handler) return null;
21
+ if (handlerCache.size > 1e3) {
22
+ const [handler$1] = handlerCache;
23
+ const key = handler$1[0];
24
+ handlerCache.delete(key);
25
+ }
26
+ handlerCache.set(`${filename}/${name}`, handler);
27
+ return handler;
28
+ }
29
+ function throwInNextTick(error) {
30
+ process.nextTick(()=>{
31
+ throw error;
32
+ });
33
+ }
34
+ export { getHandler, throwInNextTick };
@@ -0,0 +1,7 @@
1
+ function stdout() {
2
+ return console._stdout || process.stdout || void 0;
3
+ }
4
+ function stderr() {
5
+ return console._stderr || process.stderr || void 0;
6
+ }
7
+ export { stderr, stdout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -60,11 +60,11 @@
60
60
  "dependencies": {
61
61
  "@mdx-js/mdx": "^3.1.1",
62
62
  "@mdx-js/react": "^3.1.1",
63
- "@rsbuild/core": "^2.0.2",
63
+ "@rsbuild/core": "^2.0.5",
64
64
  "@rsbuild/plugin-react": "~2.0.0",
65
65
  "@shikijs/rehype": "^4.0.2",
66
66
  "@types/unist": "^3.0.3",
67
- "@unhead/react": "^2.1.13",
67
+ "@unhead/react": "^2.1.15",
68
68
  "body-scroll-lock": "4.0.0-beta.0",
69
69
  "clsx": "2.1.1",
70
70
  "copy-to-clipboard": "^3.3.3",
@@ -75,12 +75,12 @@
75
75
  "mdast-util-mdxjs-esm": "^2.0.1",
76
76
  "medium-zoom": "1.1.0",
77
77
  "nprogress": "^0.2.0",
78
- "react": "^19.2.5",
79
- "react-dom": "^19.2.5",
78
+ "react": "^19.2.6",
79
+ "react-dom": "^19.2.6",
80
80
  "react-lazy-with-preload": "^2.2.1",
81
81
  "react-reconciler": "0.33.0",
82
82
  "react-render-to-markdown": "19.0.1",
83
- "react-router-dom": "^7.13.2",
83
+ "react-router-dom": "^7.15.0",
84
84
  "rehype-external-links": "^3.0.0",
85
85
  "rehype-raw": "^7.0.0",
86
86
  "remark-cjk-friendly": "^2.0.1",
@@ -95,13 +95,13 @@
95
95
  "unist-util-remove": "^4.0.0",
96
96
  "unist-util-visit": "^5.1.0",
97
97
  "unist-util-visit-children": "^3.0.0",
98
- "@rspress/shared": "2.0.10"
98
+ "@rspress/shared": "2.0.11"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@microsoft/api-extractor": "^7.57.7",
102
- "@rsbuild/plugin-sass": "~1.5.1",
103
- "@rsbuild/plugin-svgr": "^2.0.1",
104
- "@rslib/core": "0.21.3",
102
+ "@rsbuild/plugin-sass": "~1.5.2",
103
+ "@rsbuild/plugin-svgr": "^2.0.2",
104
+ "@rslib/core": "0.21.4",
105
105
  "@types/body-scroll-lock": "^3.1.2",
106
106
  "@types/hast": "^3.0.4",
107
107
  "@types/mdast": "^4.0.4",
@@ -110,7 +110,7 @@
110
110
  "@types/react": "^19.2.14",
111
111
  "@types/react-dom": "^19.2.3",
112
112
  "@types/react-reconciler": "^0.33.0",
113
- "@types/web": "^0.0.347",
113
+ "@types/web": "^0.0.349",
114
114
  "cac": "^7.0.0",
115
115
  "chokidar": "^3.6.0",
116
116
  "execa": "8.0.1",
@@ -119,7 +119,7 @@
119
119
  "memfs": "^4.57.2",
120
120
  "p-map": "^7.0.4",
121
121
  "picocolors": "^1.1.1",
122
- "postcss": "8.5.12",
122
+ "postcss": "8.5.14",
123
123
  "remark-directive": "^4.0.0",
124
124
  "rsbuild-plugin-publint": "^0.3.4",
125
125
  "rsbuild-plugin-virtual-module": "0.4.2",
package/dist/3425.js DELETED
@@ -1,6 +0,0 @@
1
- export { readFile } from "node:fs/promises";
2
- export { default as node_path } from "node:path";
3
- export { cwd } from "node:process";
4
- export { logger } from "@rspress/shared/logger";
5
- export { visit } from "unist-util-visit";
6
- export { addLeadingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
@@ -1,68 +0,0 @@
1
- import { describe, expect, it, rs } from "@rstest/core";
2
- import { getSidebarDataGroup } from "./hooks/useSidebar.js";
3
- import { isActive } from "./route.js";
4
- rs.mock('virtual-i18n-text', ()=>({
5
- default: {}
6
- }));
7
- rs.mock('virtual-site-data', ()=>({
8
- default: {
9
- base: '/'
10
- }
11
- }));
12
- rs.mock('virtual-routes', ()=>({
13
- routes: []
14
- }));
15
- describe('getSidebarDataGroup', ()=>{
16
- it('when using "/"', async ()=>{
17
- expect(getSidebarDataGroup({
18
- '/': [],
19
- '/guide': [
20
- {
21
- text: 'Getting Started',
22
- link: '/guide/getting-started'
23
- }
24
- ]
25
- }, '/guide/getting-started')).toMatchInlineSnapshot(`
26
- [
27
- {
28
- "link": "/guide/getting-started",
29
- "text": "Getting Started",
30
- },
31
- ]
32
- `);
33
- });
34
- it('when using api-extractor', async ()=>{
35
- expect(getSidebarDataGroup({
36
- '/api/react': [
37
- {
38
- link: '/api/react.use',
39
- text: 'react.use'
40
- }
41
- ]
42
- }, '/api/react.use.html')).toMatchInlineSnapshot(`
43
- [
44
- {
45
- "link": "/api/react.use",
46
- "text": "react.use",
47
- },
48
- ]
49
- `);
50
- });
51
- });
52
- describe('isActive', ()=>{
53
- it('pass cases', ()=>{
54
- const routes = [
55
- '/api/config',
56
- '/api/config.html',
57
- '/api/config/',
58
- '/api/config/index',
59
- '/api/config/index.html'
60
- ];
61
- for (const route of routes)for (const route2 of routes)expect(isActive(route, route2)).toBeTruthy();
62
- });
63
- it('failed cases', ()=>{
64
- expect(isActive('/api/config', '/api/config2')).toBeFalsy();
65
- expect(isActive('/api/config', '/api/config/config2')).toBeFalsy();
66
- expect(isActive('/api/config/index', '/api/config/config2')).toBeFalsy();
67
- });
68
- });
@@ -1,36 +0,0 @@
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
- describe('useWindowSize', ()=>{
5
- it('should have debounce implementation with RESIZE_DEBOUNCE_MS constant', ()=>{
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
- expect(fileContent).toContain('const RESIZE_DEBOUNCE_MS = 150');
9
- expect(fileContent).toContain('setTimeout');
10
- expect(fileContent).toContain('RESIZE_DEBOUNCE_MS');
11
- });
12
- it('should clear timeout with conditional check', ()=>{
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
- expect(fileContent).toContain('if (timeoutId) clearTimeout(timeoutId)');
16
- expect(fileContent).not.toContain('clearTimeout(timeoutId!)');
17
- });
18
- it('should register and cleanup resize event listener', ()=>{
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
- expect(fileContent).toContain("addEventListener('resize'");
22
- expect(fileContent).toContain("removeEventListener('resize'");
23
- });
24
- it('should set initial size immediately', ()=>{
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
- const setStateMatch = fileContent.match(/setSize\(\{[^}]+\}\)/g);
28
- expect(setStateMatch).toBeTruthy();
29
- expect(setStateMatch?.length).toBeGreaterThanOrEqual(2);
30
- });
31
- it('should export useWindowSize function', async ()=>{
32
- const module = await import("./useWindowSize.js");
33
- expect(module.useWindowSize).toBeDefined();
34
- expect(typeof module.useWindowSize).toBe('function');
35
- });
36
- });