@rspress/core 2.0.0-rc.4 → 2.0.0-rc.5

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 (120) hide show
  1. package/dist/{0~7675.723d12b2.js → 0~7675.4468968d.js} +3 -3
  2. package/dist/{9643.2dff683e.js → 1820.985588a0.js} +1 -0
  3. package/dist/{5485.9fc7f63d.js → 5485.b9ce9bdf.js} +1 -1
  4. package/dist/_private/react/render.js +1 -1
  5. package/dist/cli/config/loadConfigFile.js +1 -1
  6. package/dist/cli/index.js +1 -1
  7. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  8. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -0
  9. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -1
  10. package/dist/eject-theme/components/HomeHero/index.scss +8 -0
  11. package/dist/eject-theme/components/HomeHero/index.tsx +11 -2
  12. package/dist/eject-theme/components/Overview/index.tsx +8 -62
  13. package/dist/eject-theme/components/OverviewGroup/index.tsx +46 -0
  14. package/dist/eject-theme/components/Steps/index.scss +1 -0
  15. package/dist/index.js +2 -3
  16. package/dist/node/PluginDriver.js +1 -1
  17. package/dist/node/auto-nav-sidebar/index.js +1 -1
  18. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  19. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  20. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  21. package/dist/node/constants.js +1 -1
  22. package/dist/node/initRsbuild.js +4 -5
  23. package/dist/node/last-updated/index.js +1 -1
  24. package/dist/node/mdx/options.js +1 -1
  25. package/dist/node/mdx/processor.js +1 -1
  26. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  27. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -1
  28. package/dist/node/mdx/remarkPlugins/image.js +1 -2
  29. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  30. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  31. package/dist/node/route/RouteService.js +2 -2
  32. package/dist/node/route/extractPageData.js +2 -3
  33. package/dist/node/route/normalizeRoutePath.js +2 -2
  34. package/dist/node/runtimeModule/i18n.js +1 -1
  35. package/dist/node/runtimeModule/pageData/createPageData.js +2 -2
  36. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  37. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  38. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  39. package/dist/node/serve.js +1 -1
  40. package/dist/node/ssg/renderPage.js +1 -1
  41. package/dist/node/ssg/renderPageWorker.js +1 -1
  42. package/dist/node/ssg/renderPages.js +2 -2
  43. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  44. package/dist/node/ssg/ssgEnv.js +1 -1
  45. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  46. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  47. package/dist/node/ssg-md/renderPage.js +1 -1
  48. package/dist/node/ssg-md/renderPages.js +1 -1
  49. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  50. package/dist/node/utils/createHash.js +1 -1
  51. package/dist/node/utils/flattenMdxContent.js +2 -3
  52. package/dist/node/utils/getPageKey.js +1 -1
  53. package/dist/node/utils/normalizePath.js +1 -1
  54. package/dist/node/utils/reactAlias.js +1 -1
  55. package/dist/runtime/Content.d.ts +4 -0
  56. package/dist/runtime/Content.js +18 -0
  57. package/dist/runtime/NoSSR.d.ts +3 -0
  58. package/dist/runtime/NoSSR.js +14 -0
  59. package/dist/runtime/getSidebarDataGroup.test.js +68 -0
  60. package/dist/runtime/hooks/useActiveMatcher.d.ts +1 -0
  61. package/dist/runtime/hooks/useActiveMatcher.js +14 -0
  62. package/dist/runtime/hooks/useDark.d.ts +7 -0
  63. package/dist/runtime/hooks/useDark.js +7 -0
  64. package/dist/runtime/hooks/useFrontmatter.d.ts +4 -0
  65. package/dist/runtime/hooks/useFrontmatter.js +9 -0
  66. package/dist/runtime/hooks/useI18n.d.ts +2 -0
  67. package/dist/runtime/hooks/useI18n.js +14 -0
  68. package/dist/runtime/hooks/useLang.d.ts +1 -0
  69. package/dist/runtime/hooks/useLang.js +6 -0
  70. package/dist/runtime/hooks/useLocaleSiteData.d.ts +18 -0
  71. package/dist/runtime/hooks/useLocaleSiteData.js +20 -0
  72. package/dist/runtime/hooks/useNav.d.ts +1 -0
  73. package/dist/runtime/hooks/useNav.js +12 -0
  74. package/dist/runtime/hooks/usePage.d.ts +10 -0
  75. package/dist/runtime/hooks/usePage.js +9 -0
  76. package/dist/runtime/hooks/usePageData.d.ts +5 -0
  77. package/dist/runtime/hooks/usePageData.js +16 -0
  78. package/dist/runtime/hooks/usePages.d.ts +4 -0
  79. package/dist/runtime/hooks/usePages.js +7 -0
  80. package/dist/runtime/hooks/useSidebar.d.ts +16 -0
  81. package/dist/runtime/hooks/useSidebar.js +67 -0
  82. package/dist/runtime/hooks/useSite.d.ts +4 -0
  83. package/dist/runtime/hooks/useSite.js +7 -0
  84. package/dist/runtime/hooks/useVersion.d.ts +1 -0
  85. package/dist/runtime/hooks/useVersion.js +6 -0
  86. package/dist/runtime/hooks/useWindowSize.d.ts +9 -0
  87. package/dist/runtime/hooks/useWindowSize.js +31 -0
  88. package/dist/runtime/hooks/useWindowSize.test.js +36 -0
  89. package/dist/runtime/index.d.ts +21 -0
  90. package/dist/runtime/index.js +22 -0
  91. package/dist/runtime/route.d.ts +36 -0
  92. package/dist/runtime/route.js +53 -0
  93. package/dist/runtime/route.test.js +154 -0
  94. package/dist/runtime/ssrMdServerEntry.js +1 -1
  95. package/dist/runtime/utils.d.ts +12 -0
  96. package/dist/runtime/utils.js +34 -0
  97. package/dist/runtime/utils.test.js +34 -0
  98. package/dist/theme/components/CodeBlock/index.js +1 -1
  99. package/dist/theme/components/FallbackHeading/index.js +4 -1
  100. package/dist/theme/components/HomeBackground/useNavTransparent.js +1 -1
  101. package/dist/theme/components/HomeHero/index.css +6 -0
  102. package/dist/theme/components/HomeHero/index.js +10 -3
  103. package/dist/theme/components/Overview/index.js +11 -43
  104. package/dist/theme/components/OverviewGroup/index.js +33 -0
  105. package/dist/theme/components/Steps/index.css +1 -0
  106. package/dist/theme/index.d.ts +1 -1
  107. package/dist/theme/index.js +1 -1
  108. package/dist/theme/logic/useScrollAfterNav.js +2 -2
  109. package/dist/theme/logic/useScrollReset.js +2 -2
  110. package/dist/theme/logic/{useAppearance.d.ts → useThemeState.d.ts} +4 -1
  111. package/dist/theme/logic/useThemeState.js +50 -0
  112. package/dist/theme/styles/scrollbar.css +14 -2
  113. package/package.json +9 -10
  114. package/static/MediumZoom.tsx +1 -1
  115. package/dist/4669.69cb6b18.js +0 -1
  116. package/dist/runtime.72d450ac.js +0 -1
  117. package/dist/runtime.d.ts +0 -2
  118. package/dist/runtime.js +0 -3
  119. package/dist/theme/logic/useAppearance.js +0 -64
  120. /package/dist/{3521.9eb6b114.js → 5341.9eb6b114.js} +0 -0
@@ -0,0 +1,53 @@
1
+ import { cleanUrl } from "@rspress/shared";
2
+ import { routes } from "virtual-routes";
3
+ function normalizeRoutePath(routePath) {
4
+ return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
5
+ }
6
+ function matchPath(pattern, pathname) {
7
+ const normalizedPattern = normalizeRoutePath(pattern);
8
+ const normalizedPathname = normalizeRoutePath(pathname);
9
+ const normalizedPatternWithSlash = normalizedPattern.endsWith('/') ? normalizedPattern : `${normalizedPattern}/`;
10
+ const normalizedPathnameWithSlash = normalizedPathname.endsWith('/') ? normalizedPathname : `${normalizedPathname}/`;
11
+ if (normalizedPatternWithSlash === normalizedPathnameWithSlash) return {
12
+ path: pattern
13
+ };
14
+ return null;
15
+ }
16
+ const sortedRoutes = [
17
+ ...routes
18
+ ].sort((a, b)=>{
19
+ const pathA = a.path || '';
20
+ const pathB = b.path || '';
21
+ return pathB.length - pathA.length;
22
+ });
23
+ function matchRoutes(_routes, pathname) {
24
+ for (const route of sortedRoutes){
25
+ const routePath = route.path || '';
26
+ const match = matchPath(routePath, pathname);
27
+ if (match) return [
28
+ {
29
+ route
30
+ }
31
+ ];
32
+ }
33
+ return null;
34
+ }
35
+ const cache = new Map();
36
+ function pathnameToRouteService(pathname) {
37
+ const normalizedPathname = normalizeRoutePath(pathname);
38
+ const cacheItem = cache.get(normalizedPathname);
39
+ if (cacheItem) return cacheItem;
40
+ const matched = matchRoutes(routes, normalizedPathname);
41
+ const route = matched?.[0]?.route;
42
+ if (route) cache.set(normalizedPathname, route);
43
+ return route;
44
+ }
45
+ function isActive(itemLink, currentPathname) {
46
+ const linkMatched = matchPath(itemLink, currentPathname);
47
+ return null !== linkMatched;
48
+ }
49
+ const preloadLink = (link)=>{
50
+ const route = pathnameToRouteService(link);
51
+ if (route) route.preload();
52
+ };
53
+ export { isActive, matchPath, pathnameToRouteService, preloadLink };
@@ -0,0 +1,154 @@
1
+ import { describe, expect, it, rs } from "@rstest/core";
2
+ import { isActive, matchPath, pathnameToRouteService } from "./route.js";
3
+ rs.mock('virtual-routes', ()=>{
4
+ const element = rs.fn();
5
+ const routes = [
6
+ {
7
+ path: '/api/config',
8
+ element,
9
+ filePath: 'api/config.mdx',
10
+ preload: async ()=>{},
11
+ lang: '',
12
+ version: ''
13
+ },
14
+ {
15
+ path: '/api/config/',
16
+ element,
17
+ filePath: 'api/config/index.mdx',
18
+ preload: async ()=>{},
19
+ lang: '',
20
+ version: ''
21
+ },
22
+ {
23
+ path: '/',
24
+ element,
25
+ filePath: 'index.mdx',
26
+ preload: async ()=>{},
27
+ lang: '',
28
+ version: ''
29
+ }
30
+ ];
31
+ return {
32
+ routes
33
+ };
34
+ });
35
+ describe('matchPath', ()=>{
36
+ it('should match exact paths', ()=>{
37
+ expect(matchPath('/api/config', '/api/config')).toEqual({
38
+ path: '/api/config'
39
+ });
40
+ expect(matchPath('/api/config/', '/api/config/')).toEqual({
41
+ path: '/api/config/'
42
+ });
43
+ });
44
+ it('should normalize trailing slashes', ()=>{
45
+ expect(matchPath('/api/config', '/api/config/')).toEqual({
46
+ path: '/api/config'
47
+ });
48
+ expect(matchPath('/api/config/', '/api/config')).toEqual({
49
+ path: '/api/config/'
50
+ });
51
+ expect(matchPath('/api/config/', '/api/config/index.html')).toEqual({
52
+ path: '/api/config/'
53
+ });
54
+ });
55
+ it('should return null for non-matching paths', ()=>{
56
+ expect(matchPath('/api/config', '/api/other')).toBeNull();
57
+ expect(matchPath('/api', '/api/config')).toBeNull();
58
+ expect(matchPath('/api', '/api/index.md')).toBeNull();
59
+ });
60
+ it('should handle case-insensitive matching', ()=>{
61
+ expect(matchPath('/api/config', '/API/CONFIG')).toEqual({
62
+ path: '/api/config'
63
+ });
64
+ expect(matchPath('/api/config', '/Api/Config')).toEqual({
65
+ path: '/api/config'
66
+ });
67
+ expect(matchPath('/api/config', '/api/CONFIG.html')).toEqual({
68
+ path: '/api/config'
69
+ });
70
+ expect(matchPath('/api/config/', '/API/CONFIG/')).toEqual({
71
+ path: '/api/config/'
72
+ });
73
+ expect(matchPath('/api/config/', '/API/CONFIG/index.html')).toEqual({
74
+ path: '/api/config/'
75
+ });
76
+ });
77
+ });
78
+ describe('isActive', ()=>{
79
+ it('should return true for matching normalized paths', ()=>{
80
+ expect(isActive('/api/config', '/api/config')).toBe(true);
81
+ expect(isActive('/api/config', '/api/config.html')).toBe(true);
82
+ expect(isActive('/api/config', '/api/config/')).toBe(true);
83
+ });
84
+ it('should return false for non-matching paths', ()=>{
85
+ expect(isActive('/api/config', '/api/other')).toBe(false);
86
+ });
87
+ it('should handle hash and search parameters correctly', ()=>{
88
+ expect(isActive('/api/config', '/api/config#hash')).toBe(true);
89
+ expect(isActive('/api/config', '/api/config?query=value')).toBe(true);
90
+ expect(isActive('/api/config', '/api/config.html#hash')).toBe(true);
91
+ expect(isActive('/api/config', '/api/config.html?query=value')).toBe(true);
92
+ expect(isActive('/api/config', '/api/config.html?query=value#hash')).toBe(true);
93
+ expect(isActive('/api/config#different', '/api/config#hash')).toBe(true);
94
+ });
95
+ it('should handle case-insensitive matching', ()=>{
96
+ expect(isActive('/api/config', '/API/CONFIG')).toBe(true);
97
+ expect(isActive('/api/config', '/Api/Config')).toBe(true);
98
+ expect(isActive('/api/config', '/api/CONFIG.html')).toBe(true);
99
+ expect(isActive('/api/config', '/API/CONFIG/')).toBe(true);
100
+ expect(isActive('/api/config', '/API/CONFIG/index.html')).toBe(true);
101
+ expect(isActive('/api/config', '/api/CONFIG#hash')).toBe(true);
102
+ expect(isActive('/api/config', '/API/config?query=value')).toBe(true);
103
+ });
104
+ });
105
+ describe('pathnameToRouteService', ()=>{
106
+ it('0. /api/config', ()=>{
107
+ const pathname = '/api/config';
108
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
109
+ });
110
+ it('1. /api/config.html', ()=>{
111
+ const pathname = '/api/config.html';
112
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
113
+ });
114
+ it('2. /api/config/', ()=>{
115
+ const pathname = '/api/config/';
116
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
117
+ });
118
+ it('3. /api/config/index', ()=>{
119
+ const pathname = '/api/config/index';
120
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
121
+ });
122
+ it('4. /api/config/index.html', ()=>{
123
+ const pathname = '/api/config/index.html';
124
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
125
+ });
126
+ it('5. /', ()=>{
127
+ expect(pathnameToRouteService('/index.html')?.path).toMatchInlineSnapshot('"/"');
128
+ expect(pathnameToRouteService('/index.md')?.path).toMatchInlineSnapshot("undefined");
129
+ });
130
+ it('6. /api/config.html#hash - should handle hash correctly', ()=>{
131
+ const pathname = '/api/config.html#hash';
132
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
133
+ });
134
+ it('7. /api/config.html?query=value - should handle query params correctly', ()=>{
135
+ const pathname = '/api/config.html?query=value';
136
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
137
+ });
138
+ it('8. /api/config.html?query=value#hash - should handle both query and hash', ()=>{
139
+ const pathname = '/api/config.html?query=value#hash';
140
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
141
+ });
142
+ it('9. /api/config#hash - should handle hash without .html', ()=>{
143
+ const pathname = '/api/config#hash';
144
+ expect(pathnameToRouteService(pathname)?.path).toMatchInlineSnapshot('"/api/config/"');
145
+ });
146
+ it('10. Case-insensitive route matching', ()=>{
147
+ expect(pathnameToRouteService('/API/CONFIG')?.path).toMatchInlineSnapshot('"/api/config/"');
148
+ expect(pathnameToRouteService('/Api/Config')?.path).toMatchInlineSnapshot('"/api/config/"');
149
+ expect(pathnameToRouteService('/API/CONFIG.html')?.path).toMatchInlineSnapshot('"/api/config/"');
150
+ expect(pathnameToRouteService('/API/CONFIG/')?.path).toMatchInlineSnapshot('"/api/config/"');
151
+ expect(pathnameToRouteService('/API/CONFIG/index.html')?.path).toMatchInlineSnapshot('"/api/config/"');
152
+ expect(pathnameToRouteService('/api/CONFIG#hash')?.path).toMatchInlineSnapshot('"/api/config/"');
153
+ });
154
+ });
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { renderToMarkdownString } from "@rspress/core/_private/react";
3
- import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/runtime";
3
+ import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/core/runtime";
4
4
  import { UnheadProvider } from "@unhead/react/server";
5
5
  import { StaticRouter } from "react-router-dom";
6
6
  import { App } from "./App.js";
@@ -0,0 +1,12 @@
1
+ import { addLeadingSlash, isProduction, removeTrailingSlash } from '@rspress/shared';
2
+ declare function withBase(url?: string): string;
3
+ declare function removeBase(url: string): string;
4
+ declare function isEqualPath(a: string, b: string): boolean;
5
+ declare function normalizeHrefInRuntime(link: string): string;
6
+ /**
7
+ * we do cleanUrls in runtime side
8
+ */
9
+ declare function cleanUrlByConfig(link: string): string;
10
+ declare function normalizeImagePath(imagePath: string): string;
11
+ declare function routePathToMdPath(routePath: string): string;
12
+ export { addLeadingSlash, removeTrailingSlash, isProduction, normalizeImagePath, cleanUrlByConfig, removeBase, withBase, isEqualPath, normalizeHrefInRuntime, routePathToMdPath, };
@@ -0,0 +1,34 @@
1
+ import { addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
2
+ import virtual_site_data from "virtual-site-data";
3
+ function utils_withBase(url = '/') {
4
+ return withBase(url, virtual_site_data.base);
5
+ }
6
+ function utils_removeBase(url) {
7
+ return removeBase(url, virtual_site_data.base);
8
+ }
9
+ function isEqualPath(a, b) {
10
+ return utils_removeBase(normalizeHref(removeHash(a), true)) === utils_removeBase(normalizeHref(removeHash(b), true));
11
+ }
12
+ function normalizeHrefInRuntime(link) {
13
+ const cleanUrls = Boolean(virtual_site_data?.route?.cleanUrls);
14
+ return normalizeHref(link, cleanUrls);
15
+ }
16
+ function cleanUrlByConfig(link) {
17
+ if (virtual_site_data?.route?.cleanUrls) return normalizeHref(link, true);
18
+ return link;
19
+ }
20
+ function normalizeImagePath(imagePath) {
21
+ if (isAbsoluteUrl(imagePath)) return imagePath;
22
+ if (!imagePath.startsWith('/')) return imagePath;
23
+ return utils_withBase(imagePath);
24
+ }
25
+ function routePathToMdPath(routePath) {
26
+ let url = routePath;
27
+ url = normalizeHref(url, false);
28
+ url = url.replace(/\.html(?=#|\?|$)/, '.md');
29
+ return utils_withBase(url);
30
+ }
31
+ function isAbsoluteUrl(path) {
32
+ return isExternalUrl(path) || isDataUrl(path) || path.startsWith('//');
33
+ }
34
+ export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, utils_removeBase as removeBase, removeTrailingSlash, routePathToMdPath, utils_withBase as withBase };
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it, rs } from "@rstest/core";
2
+ import { routePathToMdPath } from "./utils.js";
3
+ rs.mock('virtual-site-data', ()=>({
4
+ default: {
5
+ base: '/'
6
+ }
7
+ }));
8
+ describe('routePathToMdPath', ()=>{
9
+ it('should match snapshot for various paths', ()=>{
10
+ const cases = [
11
+ '/foo/bar.html',
12
+ '/foo/bar.html#hash',
13
+ '/foo/bar.html?q=1',
14
+ '/foo/bar.html?q=1#hash',
15
+ '/foo.html',
16
+ '/simple.html#my-heading',
17
+ '/query.html?foo=bar&baz=qux',
18
+ '/complex.html?id=123#section-2'
19
+ ];
20
+ const results = cases.map((path)=>routePathToMdPath(path));
21
+ expect(results).toMatchInlineSnapshot(`
22
+ [
23
+ "/foo/bar.md",
24
+ "/foo/bar.md#hash",
25
+ "/foo/bar.md?q=1",
26
+ "/foo/bar.md?q=1#hash",
27
+ "/foo.md",
28
+ "/simple.md#my-heading",
29
+ "/query.md?foo=bar&baz=qux",
30
+ "/complex.md?id=123#section-2",
31
+ ]
32
+ `);
33
+ });
34
+ });
@@ -18,7 +18,7 @@ function CodeBlock({ containerElementClassName, title, lang = 'txt', wrapCode: w
18
18
  className: clsx('rp-codeblock__content', codeWrap && 'rp-codeblock__content--code-wrap', lineNumbersProp && 'rp-codeblock__content--line-numbers'),
19
19
  children: [
20
20
  /*#__PURE__*/ jsx("div", {
21
- className: "rp-codeblock__content__scroll-container rp-scrollbar",
21
+ className: "rp-codeblock__content__scroll-container rp-scrollbar rp-scrollbar--always",
22
22
  ref: copyElementRef,
23
23
  children: children
24
24
  }),
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { getCustomMDXComponent, renderInlineMarkdown } from "@theme";
3
3
  import { slug } from "github-slugger";
4
4
  import { useMemo } from "react";
@@ -14,6 +14,9 @@ const getHeadingMap = ()=>{
14
14
  };
15
15
  };
16
16
  function FallbackHeading({ level, title }) {
17
+ if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
18
+ children: `${'#'.repeat(level)} ${title}\n\n`
19
+ });
17
20
  const titleSlug = title && slug(title.trim());
18
21
  const Element = useMemo(()=>{
19
22
  const headingMap = getHeadingMap();
@@ -29,7 +29,7 @@ const useNavTransparent = ()=>{
29
29
  topArrived
30
30
  ]);
31
31
  return /*#__PURE__*/ jsx("style", {
32
- children: "body:not(.notTopArrived) .rp-nav {background: transparent !important; border-bottom: none !important;}.rp-nav {background: color-mix(in srgb,var(--rp-c-bg) 60%,transparent);backdrop-filter: blur(25px);}"
32
+ children: "body:not(.notTopArrived) .rp-nav {background: transparent !important; border-bottom: 1px solid transparent !important;}.rp-nav {background: color-mix(in srgb,var(--rp-c-bg) 60%,transparent);backdrop-filter: blur(25px);}"
33
33
  });
34
34
  };
35
35
  export { useNavTransparent };
@@ -74,6 +74,8 @@
74
74
  padding: .5rem 1rem;
75
75
  font-size: .875rem;
76
76
  font-weight: 500;
77
+ text-decoration: none;
78
+ transition: background .2s, border-color .2s;
77
79
  display: inline-flex;
78
80
  }
79
81
 
@@ -92,6 +94,10 @@
92
94
  cursor: pointer;
93
95
  }
94
96
 
97
+ .rp-home-hero__badge:is(a):hover {
98
+ border-color: var(--rp-c-brand);
99
+ }
100
+
95
101
  .rp-home-hero__title {
96
102
  font-size: 4rem;
97
103
  font-weight: 600;
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { normalizeImagePath, useFrontmatter } from "@rspress/core/runtime";
3
- import { Button, renderHtmlOrText } from "@theme";
3
+ import { Button, Link, renderHtmlOrText } from "@theme";
4
4
  import "./index.css";
5
5
  import clsx from "clsx";
6
6
  const DEFAULT_HERO = {
@@ -31,10 +31,17 @@ function HomeHero({ beforeHeroActions, afterHeroActions }) {
31
31
  /*#__PURE__*/ jsxs("div", {
32
32
  className: "rp-home-hero__container",
33
33
  children: [
34
- hero.badge && /*#__PURE__*/ jsx("div", {
34
+ hero.badge && ('string' == typeof hero.badge ? /*#__PURE__*/ jsx("div", {
35
35
  className: "rp-home-hero__badge",
36
36
  children: hero.badge
37
- }),
37
+ }) : hero.badge.link ? /*#__PURE__*/ jsx(Link, {
38
+ href: hero.badge.link,
39
+ className: "rp-home-hero__badge",
40
+ children: hero.badge.text
41
+ }) : /*#__PURE__*/ jsx("div", {
42
+ className: "rp-home-hero__badge",
43
+ children: hero.badge.text
44
+ })),
38
45
  /*#__PURE__*/ jsxs("div", {
39
46
  className: "rp-home-hero__content",
40
47
  children: [
@@ -1,49 +1,10 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { isEqualPath, normalizeHref, useI18n, usePageData, useSidebar, withBase } from "@rspress/core/runtime";
2
+ import { isEqualPath, useI18n, usePageData, useSidebar } from "@rspress/core/runtime";
3
3
  import { FallbackHeading, OverviewGroup } from "@theme";
4
4
  import { useEffect, useMemo, useRef, useState } from "react";
5
5
  import { isSidebarDivider, isSidebarSectionHeader, isSidebarSingleFile } from "../Sidebar/utils.js";
6
6
  import "./index.css";
7
7
  import { findItemByRoutePath } from "./utils.js";
8
- function routePathToMdPath(routePath) {
9
- let url = routePath;
10
- url = normalizeHref(url, false);
11
- url = url.replace(/\.html$/, '.md');
12
- return withBase(url);
13
- }
14
- function OverviewMarkdown({ title, groups }) {
15
- const lines = [];
16
- lines.push(`# ${title}`);
17
- lines.push('');
18
- for (const group of groups){
19
- if (group.name) {
20
- lines.push(`## ${group.name}`);
21
- lines.push('');
22
- }
23
- for (const item of group.items){
24
- const itemTitle = item.link ? `[${item.text}](${routePathToMdPath(item.link)})` : `**${item.text}**`;
25
- lines.push(`### ${itemTitle}`);
26
- lines.push('');
27
- if (item.headers && item.headers.length > 0) {
28
- for (const header of item.headers){
29
- const headerLink = item.link ? `[${header.text}](${routePathToMdPath(item.link)}#${header.id})` : header.text;
30
- lines.push(`- ${headerLink}`);
31
- }
32
- lines.push('');
33
- }
34
- if (item.items && item.items.length > 0) {
35
- for (const subItem of item.items){
36
- const subItemLink = subItem.link ? `[${subItem.text}](${routePathToMdPath(subItem.link)})` : subItem.text;
37
- lines.push(`- ${subItemLink}`);
38
- }
39
- lines.push('');
40
- }
41
- }
42
- }
43
- return /*#__PURE__*/ jsx(Fragment, {
44
- children: lines.join('\n')
45
- });
46
- }
47
8
  const normalizeText = (s)=>s.toLowerCase().replace(/-/g, ' ');
48
9
  const matchesQuery = (text, query)=>normalizeText(text).includes(normalizeText(query));
49
10
  const OverviewSearchInput = ({ query, setQuery, searchRef })=>{
@@ -154,9 +115,16 @@ function Overview(props) {
154
115
  query
155
116
  ]);
156
117
  const overviewTitle = title || 'Overview';
157
- if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(OverviewMarkdown, {
158
- title: overviewTitle,
159
- groups: groups
118
+ if (process.env.__SSR_MD__) return /*#__PURE__*/ jsxs(Fragment, {
119
+ children: [
120
+ /*#__PURE__*/ jsx(FallbackHeading, {
121
+ level: 1,
122
+ title: overviewTitle
123
+ }),
124
+ groups.map((group)=>/*#__PURE__*/ jsx(OverviewGroup, {
125
+ group: group
126
+ }, group?.name))
127
+ ]
160
128
  });
161
129
  return /*#__PURE__*/ jsxs("div", {
162
130
  className: "rspress-doc rp-doc rspress-overview rp-overview",
@@ -1,9 +1,42 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { FallbackHeading, Link, SvgWrapper, renderInlineMarkdown } from "@theme";
3
3
  import "./index.css";
4
+ import { routePathToMdPath } from "@rspress/core/runtime";
4
5
  import { useMemo } from "react";
5
6
  import icons_plugin from "./icons/plugin.js";
7
+ function OverviewGroupMarkdown({ group }) {
8
+ const lines = [];
9
+ if (group.name) {
10
+ lines.push(`## ${group.name}`);
11
+ lines.push('');
12
+ }
13
+ for (const item of group.items){
14
+ const itemTitle = item.link ? `[${item.text}](${routePathToMdPath(item.link)})` : `**${item.text}**`;
15
+ lines.push(`### ${itemTitle}`);
16
+ lines.push('');
17
+ if (item.headers && item.headers.length > 0) {
18
+ for (const header of item.headers){
19
+ const headerLink = item.link ? `[${header.text}](${routePathToMdPath(item.link)}#${header.id})` : header.text;
20
+ lines.push(`- ${headerLink}`);
21
+ }
22
+ lines.push('');
23
+ }
24
+ if (item.items && item.items.length > 0) {
25
+ for (const subItem of item.items){
26
+ const subItemLink = subItem.link ? `[${subItem.text}](${routePathToMdPath(subItem.link)})` : subItem.text;
27
+ lines.push(`- ${subItemLink}`);
28
+ }
29
+ lines.push('');
30
+ }
31
+ }
32
+ return /*#__PURE__*/ jsx(Fragment, {
33
+ children: lines.join('\n')
34
+ });
35
+ }
6
36
  const OverviewGroup = ({ group })=>{
37
+ if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(OverviewGroupMarkdown, {
38
+ group: group
39
+ });
7
40
  const { itemsWithContent, itemsWithoutContent } = useMemo(()=>{
8
41
  const itemsWithContent = group.items.filter((item)=>item.headers && item.headers.length > 0 || item.items && item.items.length > 0);
9
42
  const itemsWithoutContent = group.items.filter((item)=>!(item.headers && item.headers.length > 0) && !(item.items && item.items.length > 0));
@@ -24,6 +24,7 @@
24
24
  align-items: center;
25
25
  font-size: 1.1rem;
26
26
  font-weight: 400;
27
+ line-height: 30px;
27
28
  display: flex;
28
29
  position: absolute;
29
30
  left: -41px;
@@ -53,7 +53,6 @@ export { HomeLayout, type HomeLayoutProps } from './layout/HomeLayout/index.js';
53
53
  export { Layout, type LayoutProps } from './layout/Layout/index.js';
54
54
  export { NotFoundLayout } from './layout/NotFountLayout/index.js';
55
55
  export { mergeRefs } from './logic/mergeRefs.js';
56
- export { useThemeState } from './logic/useAppearance.js';
57
56
  export { useFullTextSearch } from './logic/useFullTextSearch.js';
58
57
  export { usePrevNextPage } from './logic/usePrevNextPage.js';
59
58
  export { useRedirect4FirstVisit } from './logic/useRedirect4FirstVisit.js';
@@ -61,4 +60,5 @@ export { useScrollAfterNav } from './logic/useScrollAfterNav.js';
61
60
  export { useScrollReset } from './logic/useScrollReset.js';
62
61
  export { useSetup } from './logic/useSetup.js';
63
62
  export { useStorageValue } from './logic/useStorageValue.js';
63
+ export { useThemeState } from './logic/useThemeState.js';
64
64
  export { parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown, } from './logic/utils.js';
@@ -50,7 +50,6 @@ import { HomeLayout } from "./layout/HomeLayout/index.js";
50
50
  import { Layout } from "./layout/Layout/index.js";
51
51
  import { NotFoundLayout } from "./layout/NotFountLayout/index.js";
52
52
  import { mergeRefs } from "./logic/mergeRefs.js";
53
- import { useThemeState } from "./logic/useAppearance.js";
54
53
  import { useFullTextSearch } from "./logic/useFullTextSearch.js";
55
54
  import { usePrevNextPage } from "./logic/usePrevNextPage.js";
56
55
  import { useRedirect4FirstVisit } from "./logic/useRedirect4FirstVisit.js";
@@ -58,6 +57,7 @@ import { useScrollAfterNav } from "./logic/useScrollAfterNav.js";
58
57
  import { useScrollReset } from "./logic/useScrollReset.js";
59
58
  import { useSetup } from "./logic/useSetup.js";
60
59
  import { useStorageValue } from "./logic/useStorageValue.js";
60
+ import { useThemeState } from "./logic/useThemeState.js";
61
61
  import { parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown } from "./logic/utils.js";
62
62
  export * from "./icons.js";
63
63
  export { Badge, Banner, Button, Callout, CodeBlock, CodeBlockRuntime, CodeButtonGroup, DocContent, DocFooter, DocLayout, EditLink, FallbackHeading, HomeBackground, HomeFeature, HomeFooter, HomeHero, HomeLayout, HoverGroup, LastUpdated, Layout, Link, Nav, NavHamburger, NotFoundLayout, Outline, Overview, OverviewGroup, PackageManagerTabs, PageTab, PageTabs, PrevNextPage, ReadPercent, RenderType, Root, Search, SearchButton, SearchPanel, Sidebar, SidebarList, SocialLinks, SourceCode, Steps, SvgWrapper, SwitchAppearance, Tab, Tabs, Tag, Toc, getCustomMDXComponent, mergeRefs, parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown, useActiveAnchor, useCodeButtonGroup, useDynamicToc, useEditLink, useFullTextSearch, useHoverGroup, useLinkNavigate, usePrevNextPage, useRedirect4FirstVisit, useScrollAfterNav, useScrollReset, useSetup, useStorageValue, useThemeState, useWatchToc };
@@ -1,5 +1,5 @@
1
1
  import { useLocation } from "@rspress/core/runtime";
2
- import { useEffect } from "react";
2
+ import { useLayoutEffect } from "react";
3
3
  function parseCSSLength(value) {
4
4
  if (!value || 'auto' === value || 'none' === value) return 0;
5
5
  const numValue = Number.parseFloat(value);
@@ -20,7 +20,7 @@ function scrollToTarget(target) {
20
20
  }
21
21
  function useScrollAfterNav() {
22
22
  const location = useLocation();
23
- useEffect(()=>{
23
+ useLayoutEffect(()=>{
24
24
  const decodedHash = decodeURIComponent(window.location.hash);
25
25
  if (decodedHash.length > 0) {
26
26
  const target = document.getElementById(decodedHash.slice(1));
@@ -1,8 +1,8 @@
1
- import { useEffect } from "react";
1
+ import { useLayoutEffect } from "react";
2
2
  import { useLocation } from "react-router-dom";
3
3
  function useScrollReset() {
4
4
  const { pathname } = useLocation();
5
- useEffect(()=>{
5
+ useLayoutEffect(()=>{
6
6
  const decodedHash = decodeURIComponent(window.location.hash);
7
7
  if (0 === decodedHash.length) window.scrollTo(0, 0);
8
8
  }, [
@@ -4,10 +4,13 @@ declare global {
4
4
  RSPRESS_THEME?: string;
5
5
  }
6
6
  }
7
+ /** Resolved theme value used in the app */
7
8
  type ThemeValue = 'light' | 'dark';
9
+ /** Theme config value stored in localStorage */
8
10
  type ThemeConfigValue = ThemeValue | 'auto';
9
11
  /**
10
12
  * State provider for theme context.
13
+ * @internal
11
14
  */
12
- export declare const useThemeState: () => readonly [ThemeValue, (value: ThemeValue, storeValue?: ThemeConfigValue) => void];
15
+ export declare function useThemeState(): readonly [ThemeValue, (value: ThemeValue, storeValue?: ThemeConfigValue) => void];
13
16
  export {};
@@ -0,0 +1,50 @@
1
+ import { useSite } from "@rspress/core/runtime";
2
+ import { useCallback, useLayoutEffect, useMemo } from "react";
3
+ import { useMediaQuery } from "./useMediaQuery.js";
4
+ import { useStorageValue } from "./useStorageValue.js";
5
+ const APPEARANCE_KEY = 'rspress-theme-appearance';
6
+ const MEDIA_QUERY = '(prefers-color-scheme: dark)';
7
+ const applyThemeToDOM = (theme)=>{
8
+ if (!document || !document.documentElement) return;
9
+ const root = document.documentElement;
10
+ root.classList.toggle('dark', 'dark' === theme);
11
+ root.classList.toggle('rp-dark', 'dark' === theme);
12
+ root.style.colorScheme = theme;
13
+ };
14
+ function useThemeState() {
15
+ const { site } = useSite();
16
+ const disableDarkMode = false === site.themeConfig.darkMode;
17
+ const prefersDark = useMediaQuery(MEDIA_QUERY);
18
+ 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)=>{
31
+ if (disableDarkMode) return;
32
+ setStoredConfig(storeValue);
33
+ applyThemeToDOM(value);
34
+ }, [
35
+ disableDarkMode,
36
+ setStoredConfig
37
+ ]);
38
+ useLayoutEffect(()=>{
39
+ if (disableDarkMode) return;
40
+ applyThemeToDOM(resolvedTheme);
41
+ }, [
42
+ disableDarkMode,
43
+ resolvedTheme
44
+ ]);
45
+ return [
46
+ resolvedTheme,
47
+ setTheme
48
+ ];
49
+ }
50
+ export { useThemeState };