@rspress/core 2.1.0 → 2.1.2

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 (41) hide show
  1. package/dist/b~0.js +1 -0
  2. package/dist/eject-theme/components/CodeBlockRuntime/index.tsx +2 -0
  3. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +14 -3
  4. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +18 -2
  5. package/dist/eject-theme/components/Prompt/index.scss +8 -0
  6. package/dist/eject-theme/components/Search/useSearchPanel.ts +85 -81
  7. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +10 -7
  8. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
  9. package/dist/eject-theme/components/SwitchAppearance/global.scss +26 -0
  10. package/dist/eject-theme/components/SwitchAppearance/index.tsx +46 -35
  11. package/dist/node/mdx/rehypePlugins/shiki.js +2 -2
  12. package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.d.ts +1 -1
  13. package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.d.ts +463 -0
  14. package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.js +497 -34
  15. package/dist/shiki-transformers.d.ts +4 -0
  16. package/dist/shiki-transformers.js +18 -0
  17. package/dist/theme/assets/markdown.js +22 -0
  18. package/dist/theme/components/CodeBlockRuntime/index.js +3 -1
  19. package/dist/theme/components/Llms/LlmsOpenRow.js +11 -2
  20. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +4 -2
  21. package/dist/theme/components/Llms/LlmsViewOptions.js +14 -2
  22. package/dist/theme/components/Prompt/index.css +12 -0
  23. package/dist/theme/components/Search/useSearchPanel.js +66 -65
  24. package/dist/theme/components/Sidebar/SidebarItem.css +9 -11
  25. package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
  26. package/dist/theme/components/SwitchAppearance/global.css +22 -0
  27. package/dist/theme/components/SwitchAppearance/index.js +35 -27
  28. package/dist/theme/hooks/useWebMcpNavigation.d.ts +1 -1
  29. package/dist/theme/hooks/useWebMcpPageList.d.ts +1 -1
  30. package/dist/theme/hooks/useWebMcpPageReading.d.ts +1 -1
  31. package/dist/theme/hooks/useWebMcpPageReading.js +2 -2
  32. package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +1 -1
  33. package/dist/theme/icons.d.ts +5 -0
  34. package/dist/theme/icons.js +3 -1
  35. package/dist/theme/logic/useStorageValue.d.ts +2 -1
  36. package/dist/theme/logic/useStorageValue.js +50 -34
  37. package/dist/theme/styles/shiki.css +8 -0
  38. package/dist/theme/webMcp/tools.js +1 -1
  39. package/dist/tx~0.js +1 -1
  40. package/dist/y~0.js +1 -1
  41. package/package.json +6 -5
@@ -1 +1,5 @@
1
+ import type { ShikiTransformer } from 'shiki';
2
+ export * from '@shikijs/transformers';
1
3
  export * from './node/mdx/rehypePlugins/transformers/index.js';
4
+ /** @internal */
5
+ export declare function getShikiTransformers(transformers?: ShikiTransformer[]): ShikiTransformer[];
@@ -1,7 +1,25 @@
1
+ import { transformerNotationDiff, transformerNotationWordHighlight, transformerNotationFocus, transformerNotationErrorLevel, transformerRemoveNotationEscape, transformerNotationHighlight } from "./b~0.js";
1
2
  import "./node/mdx/rehypePlugins/transformers/index.js";
3
+ export * from "@shikijs/transformers";
4
+ function getShikiTransformers(transformers = []) {
5
+ const customNames = new Set(transformers.map((transformer)=>transformer.name));
6
+ const defaults = [
7
+ transformerNotationHighlight(),
8
+ transformerNotationWordHighlight(),
9
+ transformerNotationDiff(),
10
+ transformerNotationFocus(),
11
+ transformerNotationErrorLevel(),
12
+ transformerRemoveNotationEscape()
13
+ ];
14
+ return [
15
+ ...transformers,
16
+ ...defaults.filter((transformer)=>!customNames.has(transformer.name))
17
+ ];
18
+ }
2
19
  export { SHIKI_TRANSFORMER_ADD_FOLD, transformerAddFold } from "./node/mdx/rehypePlugins/transformers/add-fold.js";
3
20
  export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from "./node/mdx/rehypePlugins/transformers/add-lang.js";
4
21
  export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers } from "./node/mdx/rehypePlugins/transformers/add-line-numbers.js";
5
22
  export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from "./node/mdx/rehypePlugins/transformers/add-title.js";
6
23
  export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode } from "./node/mdx/rehypePlugins/transformers/add-wrap-code.js";
7
24
  export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight } from "./node/mdx/rehypePlugins/transformers/meta-highlight.js";
25
+ export { getShikiTransformers };
@@ -0,0 +1,22 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "react";
3
+ const SvgMarkdown = (props)=>/*#__PURE__*/ jsxs("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ width: 24,
6
+ height: 24,
7
+ fill: "currentColor",
8
+ viewBox: "0 0 208 128",
9
+ ...props,
10
+ children: [
11
+ /*#__PURE__*/ jsx("path", {
12
+ fillRule: "evenodd",
13
+ d: "M15 10a5 5 0 0 0-5 5v98a5 5 0 0 0 5 5h178a5 5 0 0 0 5-5V15a5 5 0 0 0-5-5zM0 15C0 6.716 6.716 0 15 0h178c8.284 0 15 6.716 15 15v98c0 8.284-6.716 15-15 15H15c-8.284 0-15-6.716-15-15z",
14
+ clipRule: "evenodd"
15
+ }),
16
+ /*#__PURE__*/ jsx("path", {
17
+ d: "M30 98V30h20l20 25 20-25h20v68H90V59L70 84 50 59v39zm125 0-30-33h20V30h20v35h20z"
18
+ })
19
+ ]
20
+ });
21
+ var markdown = SvgMarkdown;
22
+ export default markdown;
@@ -1,4 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { getShikiTransformers } from "@rspress/core/shiki-transformers";
2
3
  import { getCustomMDXComponent } from "@rspress/core/theme";
3
4
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
4
5
  import { Fragment, useEffect, useMemo, useRef, useState } from "react";
@@ -51,7 +52,8 @@ function CodeBlockRuntime({ lang, title, code, shikiOptions, codeButtonGroupProp
51
52
  const hast = await codeToHast(code, {
52
53
  lang,
53
54
  theme: cssVariablesTheme,
54
- ...shikiOptions
55
+ ...shikiOptions,
56
+ transformers: getShikiTransformers(shikiOptions?.transformers)
55
57
  });
56
58
  if (codeRef.current.length !== code.length) return;
57
59
  const reactNode = toJsxRuntime(hast, {
@@ -1,12 +1,13 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useI18n, useSite } from "@rspress/core/runtime";
3
- import { IconAnthropic, IconExternalLink, IconLink, IconOpenAI, IconOpenInChat, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
3
+ import { IconAnthropic, IconExternalLink, IconLink, IconMarkdown, IconOpenAI, IconOpenInChat, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
4
4
  import { useEffect, useMemo, useRef, useState } from "react";
5
5
  import "./LlmsOpenRow.css";
6
6
  import "./LlmsViewOptions.css";
7
7
  import { useMdUrl } from "./useMdUrl.js";
8
8
  const DEFAULT_OPTIONS = [
9
9
  'markdownLink',
10
+ 'viewMarkdown',
10
11
  'chatgpt',
11
12
  'claude'
12
13
  ];
@@ -41,6 +42,13 @@ function LlmsOpenRow() {
41
42
  copyToClipboard(fullMarkdownUrl);
42
43
  }
43
44
  },
45
+ viewMarkdown: {
46
+ title: t('viewMarkdownText'),
47
+ href: pathname,
48
+ icon: /*#__PURE__*/ jsx(SvgWrapper, {
49
+ icon: IconMarkdown
50
+ })
51
+ },
44
52
  chatgpt: {
45
53
  title: t('openInText', {
46
54
  name: 'ChatGPT'
@@ -66,6 +74,7 @@ function LlmsOpenRow() {
66
74
  }
67
75
  }), [
68
76
  fullMarkdownUrl,
77
+ pathname,
69
78
  t,
70
79
  q
71
80
  ]);
@@ -80,7 +89,7 @@ function LlmsOpenRow() {
80
89
  children: [
81
90
  /*#__PURE__*/ jsxs("button", {
82
91
  className: "rp-outline__action-row",
83
- onClick: ()=>setIsOpen(!isOpen),
92
+ onClick: ()=>setIsOpen((prevOpen)=>!prevOpen),
84
93
  children: [
85
94
  /*#__PURE__*/ jsx(SvgWrapper, {
86
95
  icon: IconOpenInChat
@@ -9,11 +9,13 @@ export type LlmsViewOptionsItem = {
9
9
  title: string;
10
10
  href: string;
11
11
  icon?: React.ReactNode;
12
- } | 'markdownLink' | 'chatgpt' | 'claude';
12
+ } | 'markdownLink' | 'viewMarkdown' | 'chatgpt' | 'claude';
13
13
  export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
14
14
  /**
15
15
  * Default options for the dropdown.
16
- * @default ['markdownLink', 'chatgpt', 'claude']
16
+ * @default ['markdownLink', 'viewMarkdown', 'chatgpt', 'claude']
17
+ * - 'markdownLink': Copy Markdown link
18
+ * - 'viewMarkdown': View as Markdown
17
19
  * - 'chatgpt': Open in ChatGPT
18
20
  * - 'claude': Open in Claude
19
21
  *
@@ -1,7 +1,7 @@
1
1
  /*! LICENSE: LlmsViewOptions.js.LICENSE.txt */
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useI18n, useSite } from "@rspress/core/runtime";
4
- import { IconAnthropic, IconDown, IconExternalLink, IconLink, IconOpenAI, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
4
+ import { IconAnthropic, IconDown, IconExternalLink, IconLink, IconMarkdown, IconOpenAI, SvgWrapper, copyToClipboard } from "@rspress/core/theme";
5
5
  import { useEffect, useMemo, useRef, useState } from "react";
6
6
  import "./index.css";
7
7
  import "./LlmsViewOptions.css";
@@ -12,6 +12,7 @@ import { useMdUrl } from "./useMdUrl.js";
12
12
  * @license MIT
13
13
  */ const DEFAULT_OPTIONS = [
14
14
  'markdownLink',
15
+ 'viewMarkdown',
15
16
  'chatgpt',
16
17
  'claude'
17
18
  ];
@@ -32,7 +33,7 @@ function LlmsViewOptions({ options: propsOptions }) {
32
33
  };
33
34
  }, []);
34
35
  const toggleDropdown = ()=>{
35
- setIsOpen(!isOpen);
36
+ setIsOpen((prevOpen)=>!prevOpen);
36
37
  };
37
38
  const { pathname } = useMdUrl();
38
39
  const t = useI18n();
@@ -49,6 +50,13 @@ function LlmsViewOptions({ options: propsOptions }) {
49
50
  copyToClipboard(fullMarkdownUrl);
50
51
  }
51
52
  },
53
+ viewMarkdown: {
54
+ title: t('viewMarkdownText'),
55
+ href: pathname,
56
+ icon: /*#__PURE__*/ jsx(SvgWrapper, {
57
+ icon: IconMarkdown
58
+ })
59
+ },
52
60
  chatgpt: {
53
61
  title: t('openInText', {
54
62
  name: 'ChatGPT'
@@ -79,6 +87,7 @@ function LlmsViewOptions({ options: propsOptions }) {
79
87
  ]);
80
88
  const renderableItems = useMemo(()=>options.map((option)=>{
81
89
  if ('markdownLink' === option) return items.markdownLink;
90
+ if ('viewMarkdown' === option) return items.viewMarkdown;
82
91
  if ('chatgpt' === option) return items.chatgpt;
83
92
  if ('claude' === option) return items.claude;
84
93
  if ('object' == typeof option && 'title' in option && 'string' == typeof option.title && ('href' in option || 'onClick' in option)) return option;
@@ -92,6 +101,9 @@ function LlmsViewOptions({ options: propsOptions }) {
92
101
  children: /*#__PURE__*/ jsxs("button", {
93
102
  ref: dropdownRef,
94
103
  onClick: toggleDropdown,
104
+ "aria-label": "View options",
105
+ "aria-expanded": isOpen,
106
+ "aria-haspopup": "true",
95
107
  className: `rp-llms-button rp-llms-view-options__trigger ${isOpen ? 'rp-llms-view-options__trigger--active' : ''}`,
96
108
  children: [
97
109
  /*#__PURE__*/ jsx(SvgWrapper, {
@@ -65,6 +65,12 @@
65
65
  display: flex;
66
66
  }
67
67
 
68
+ @media (width <= 768px) {
69
+ .rp-prompt__header-row {
70
+ flex-direction: column;
71
+ }
72
+ }
73
+
68
74
  .rp-prompt__header-left {
69
75
  flex-direction: column;
70
76
  gap: .375rem;
@@ -132,6 +138,12 @@
132
138
  display: flex;
133
139
  }
134
140
 
141
+ @media (width <= 768px) {
142
+ .rp-prompt__header-actions {
143
+ align-self: flex-end;
144
+ }
145
+ }
146
+
135
147
  .rp-prompt__title {
136
148
  color: var(--rp-c-text-0);
137
149
  font-size: 1.125rem;
@@ -1,15 +1,10 @@
1
1
  import { usePageData, useSearchHooks, useWebMcp } from "@rspress/core/runtime";
2
2
  import { debounce } from "@rspress/shared/lodash-es";
3
- import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
4
  import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
5
5
  import { PageSearcher } from "./logic/search.js";
6
6
  import { RenderType } from "./logic/types.js";
7
7
  import { defineTool, queryField, toWebMcpSearchResults } from "../../webMcp/tools.js";
8
- const useDebounce = (cb)=>{
9
- const cbRef = useRef(cb);
10
- cbRef.current = cb;
11
- return useCallback(debounce((...args)=>cbRef.current(...args), 150), []);
12
- };
13
8
  function useSearchPanel({ focused, searchInputRef }) {
14
9
  const { siteData, page: { lang, version } } = usePageData();
15
10
  const userSearchHooks = useSearchHooks();
@@ -27,8 +22,9 @@ function useSearchPanel({ focused, searchInputRef }) {
27
22
  const initializationRef = useRef(void 0);
28
23
  const searchEnabled = false !== search;
29
24
  const searchOptions = false === search ? {} : search;
30
- const versionedSearch = searchEnabled && (search?.versioned ?? true);
31
- const searchIndexURL = searchEnabled ? getSearchIndexURL(lang, versionedSearch ? version : '') : void 0;
25
+ const isSearchVersioned = searchEnabled && (search?.versioned ?? true);
26
+ const searchVersion = isSearchVersioned ? version : '';
27
+ const searchIndexURL = searchEnabled ? getSearchIndexURL(lang, searchVersion) : void 0;
32
28
  const DEFAULT_RESULT = [
33
29
  {
34
30
  group: siteTitle,
@@ -38,7 +34,7 @@ function useSearchPanel({ focused, searchInputRef }) {
38
34
  ];
39
35
  const createSearcher = ()=>{
40
36
  const previous = pageSearcherConfigRef.current;
41
- if (pageSearcherRef.current && previous?.currentLang === lang && (!versionedSearch || previous.currentVersion === version) && pageSearcherURLRef.current === searchIndexURL) return pageSearcherRef.current;
37
+ if (pageSearcherRef.current && previous?.currentLang === lang && (!isSearchVersioned || previous.currentVersion === version) && pageSearcherURLRef.current === searchIndexURL) return pageSearcherRef.current;
42
38
  const pageSearcherConfig = {
43
39
  currentLang: lang,
44
40
  currentVersion: version
@@ -99,89 +95,94 @@ function useSearchPanel({ focused, searchInputRef }) {
99
95
  ], async (args)=>toWebMcpSearchResults(await searchDocs(args.query, args.limit ?? 10))),
100
96
  enabled: searchEnabled && Boolean(searchIndexURL || userSearchHooks.onSearch)
101
97
  });
98
+ const requestIdRef = useRef(0);
99
+ const scheduleQuery = useMemo(()=>debounce((run)=>run(), 150), []);
100
+ const invalidateQuery = useCallback(()=>{
101
+ requestIdRef.current++;
102
+ scheduleQuery.cancel();
103
+ }, [
104
+ scheduleQuery
105
+ ]);
106
+ useLayoutEffect(()=>invalidateQuery, [
107
+ focused,
108
+ searchEnabled,
109
+ lang,
110
+ searchVersion,
111
+ searchIndexURL,
112
+ invalidateQuery
113
+ ]);
114
+ useLayoutEffect(()=>{
115
+ pageSearcherRef.current = null;
116
+ setInitStatus('initial');
117
+ setSearchError(void 0);
118
+ }, [
119
+ searchEnabled,
120
+ lang,
121
+ searchVersion,
122
+ searchIndexURL
123
+ ]);
102
124
  const initSearch = async ()=>{
103
- if ('initial' !== initStatus) return;
104
125
  const searcher = createSearcher();
126
+ if ('initial' !== initStatus && initializationRef.current?.searcher === searcher) return;
105
127
  setSearchError(void 0);
106
128
  setInitStatus('initing');
107
129
  try {
108
130
  await initializeSearcher(searcher);
131
+ if (pageSearcherRef.current === searcher) setInitStatus('inited');
109
132
  } catch (error) {
110
- if (pageSearcherRef.current !== searcher) return;
111
- setSearchError(error instanceof Error ? error.message : String(error));
112
- setInitStatus('error');
113
- setIsSearching(false);
114
- return;
115
- }
116
- if (pageSearcherRef.current !== searcher) return;
117
- setInitStatus('inited');
118
- const currentQuery = searchInputRef.current?.value;
119
- if (currentQuery) {
120
- const matched = await searcher.match(currentQuery);
121
- if (pageSearcherRef.current !== searcher || searchInputRef.current?.value !== currentQuery) return;
122
- setSearchResult(matched || DEFAULT_RESULT);
123
- setIsSearching(false);
133
+ if (pageSearcherRef.current === searcher) {
134
+ setSearchError(error instanceof Error ? error.message : String(error));
135
+ setInitStatus('error');
136
+ }
124
137
  }
125
138
  };
126
- useEffect(()=>{
127
- if (!searchEnabled) return;
128
- if (focused) {
129
- setSearchResult(DEFAULT_RESULT);
130
- initSearch();
131
- } else setQuery('');
132
- }, [
133
- focused,
134
- searchEnabled
135
- ]);
136
- useEffect(()=>{
137
- if (!searchEnabled) return;
138
- const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
139
- const isLangChanged = lang !== currentLang;
140
- const isVersionChanged = versionedSearch && version !== currentVersion;
141
- const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
142
- if (isLangChanged || isVersionChanged || isIndexChanged) {
143
- setInitStatus('initial');
144
- setSearchError(void 0);
145
- setIsSearching(false);
146
- pageSearcherRef.current = null;
147
- }
148
- }, [
149
- lang,
150
- version,
151
- versionedSearch,
152
- searchEnabled,
153
- searchIndexURL
154
- ]);
155
- const handleQueryChangedImpl = async (value)=>{
156
- const newQuery = value;
157
- setQuery(newQuery);
158
- if (!newQuery) return void setIsSearching(false);
139
+ const runQuery = async (value, requestId)=>{
140
+ const isCurrent = ()=>requestId === requestIdRef.current && searchInputRef.current?.value === value;
141
+ if (!isCurrent()) return;
142
+ setQuery(value);
159
143
  try {
160
144
  const result = await searchDocs(value);
161
- if (searchInputRef.current?.value === newQuery) {
145
+ if (isCurrent()) {
162
146
  setSearchError(void 0);
163
147
  setInitStatus('inited');
164
148
  setCurrentSuggestionIndex(0);
165
- setSearchResult(result || DEFAULT_RESULT);
149
+ setSearchResult(result);
166
150
  setIsSearching(false);
167
151
  }
168
152
  } catch (error) {
169
- if (searchInputRef.current?.value === newQuery) {
153
+ if (isCurrent()) {
170
154
  setSearchError(error instanceof Error ? error.message : String(error));
171
155
  setInitStatus('error');
172
156
  setIsSearching(false);
173
157
  }
174
158
  }
175
159
  };
176
- const handleQueryChange = useDebounce(handleQueryChangedImpl);
177
- const handleQueryInput = (value)=>{
178
- setIsSearching(Boolean(value));
179
- handleQueryChange(value);
180
- };
181
160
  const clearQuery = ()=>{
161
+ invalidateQuery();
182
162
  setQuery('');
183
163
  setIsSearching(false);
184
164
  };
165
+ const handleQueryInput = (value)=>{
166
+ if (!value) return void clearQuery();
167
+ const requestId = ++requestIdRef.current;
168
+ setIsSearching(true);
169
+ scheduleQuery(()=>{
170
+ runQuery(value, requestId);
171
+ });
172
+ };
173
+ useEffect(()=>{
174
+ if (!focused || !searchEnabled) return void clearQuery();
175
+ setSearchResult(DEFAULT_RESULT);
176
+ const value = searchInputRef.current?.value;
177
+ if (value) handleQueryInput(value);
178
+ else initSearch();
179
+ }, [
180
+ focused,
181
+ searchEnabled,
182
+ lang,
183
+ searchVersion,
184
+ searchIndexURL
185
+ ]);
185
186
  return {
186
187
  searchEnabled,
187
188
  clearQuery,
@@ -32,15 +32,14 @@
32
32
  display: inline-block;
33
33
  }
34
34
 
35
- .rp-sidebar-item--active {
35
+ .rp-sidebar-item--active, .rp-sidebar-item--active:hover {
36
36
  color: var(--rp-c-link);
37
37
  background-color: var(--rp-c-brand-tint);
38
- font-weight: 600;
39
38
  }
40
39
 
41
- .rp-sidebar-item--active:hover {
42
- color: var(--rp-c-link);
43
- background-color: var(--rp-c-brand-tint);
40
+ .rp-sidebar-item:focus-visible {
41
+ outline: 2px solid var(--rp-c-brand);
42
+ outline-offset: -2px;
44
43
  }
45
44
 
46
45
  .rp-sidebar-item--group-item:before {
@@ -48,20 +47,19 @@
48
47
  background-color: var(--rp-c-divider-light);
49
48
  width: 1px;
50
49
  position: absolute;
51
- top: 0;
50
+ top: -2px;
52
51
  bottom: 0;
53
- left: 12px;
52
+ left: -7px;
54
53
  }
55
54
 
56
55
  .rp-sidebar-item--group-item.rp-sidebar-item--active .rp-sidebar-item__left:before {
57
56
  content: "";
58
57
  background-color: var(--rp-c-brand);
59
58
  width: 1px;
60
- height: calc(50% - 4px);
61
59
  position: absolute;
62
- top: calc(25% + 2px);
63
- bottom: 0;
64
- left: 12px;
60
+ top: 8px;
61
+ bottom: 8px;
62
+ left: -7px;
65
63
  }
66
64
 
67
65
  .rp-sidebar-item__left {
@@ -57,7 +57,7 @@ function SidebarItemRaw({ active, text, icon, tag, link, context, className, lef
57
57
  'rp-sidebar-item--pending': isPending
58
58
  }, className),
59
59
  style: {
60
- paddingLeft: 0 === depth ? '12px' : `calc(12px * ${depth} + 12px)`
60
+ marginLeft: 24 * depth
61
61
  },
62
62
  'data-depth': depth,
63
63
  ...context ? {
@@ -72,7 +72,7 @@ function SidebarItemRaw({ active, text, icon, tag, link, context, className, lef
72
72
  'rp-sidebar-item--active': active
73
73
  }, className),
74
74
  style: {
75
- paddingLeft: 0 === depth ? '12px' : `calc(12px * ${depth} + 12px)`
75
+ marginLeft: 24 * depth
76
76
  },
77
77
  'data-depth': depth,
78
78
  ...context ? {
@@ -23,3 +23,25 @@ html.rp-appearance-transition .rspress-doc {
23
23
  z-index: 9999;
24
24
  }
25
25
 
26
+ html.rp-appearance-transition::view-transition-old(root), html.rp-appearance-transition::view-transition-new(root) {
27
+ will-change: contents;
28
+ }
29
+
30
+ html.rp-appearance-transition:not(.dark)::view-transition-new(root) {
31
+ animation: .4s ease-in both rp-appearance;
32
+ }
33
+
34
+ html.rp-appearance-transition.dark::view-transition-old(root) {
35
+ animation: .4s ease-in reverse both rp-appearance;
36
+ }
37
+
38
+ @keyframes rp-appearance {
39
+ from {
40
+ clip-path: var(--rp-vt-clip-start);
41
+ }
42
+
43
+ to {
44
+ clip-path: var(--rp-vt-clip-end);
45
+ }
46
+ }
47
+
@@ -7,50 +7,58 @@ import "./index.css";
7
7
  import { flushSync } from "react-dom";
8
8
  import { getClipPath } from "./getClipPath.js";
9
9
  const supportAppearanceTransition = ()=>'function' == typeof document?.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
10
- const removeClipViewTransition = ()=>{
11
- document.documentElement.classList.add('rp-appearance-transition');
12
- return ()=>{
13
- document.documentElement.classList.remove('rp-appearance-transition');
14
- };
15
- };
10
+ let isAppearanceTransitioning = false;
16
11
  function SwitchAppearance({ onClick }) {
17
12
  const { theme, setTheme = ()=>{} } = useContext(ThemeContext);
18
13
  const { site } = useSite();
19
14
  const handleClick = (event)=>{
15
+ if (isAppearanceTransitioning) return;
20
16
  const supported = supportAppearanceTransition();
21
17
  const enabled = site?.themeConfig?.enableAppearanceAnimation;
22
18
  const nextTheme = 'dark' === theme ? 'light' : 'dark';
23
- const isDark = 'dark' === nextTheme;
24
19
  if (supported && enabled) {
20
+ isAppearanceTransitioning = true;
25
21
  const x = event.clientX;
26
22
  const y = event.clientY;
27
- const dispose = removeClipViewTransition();
28
- const transition = document.startViewTransition(async ()=>{
29
- flushSync(()=>{
30
- setTheme(nextTheme);
31
- onClick?.();
32
- });
33
- });
34
23
  const clipPath = getClipPath({
35
24
  height: innerHeight,
36
25
  width: innerWidth,
37
26
  x,
38
27
  y
39
28
  });
40
- transition.ready.then(()=>{
41
- document.documentElement.animate({
42
- clipPath: isDark ? [
43
- ...clipPath
44
- ].reverse() : clipPath
45
- }, {
46
- duration: 400,
47
- easing: 'ease-in',
48
- fill: 'both',
49
- pseudoElement: isDark ? '::view-transition-old(root)' : '::view-transition-new(root)',
50
- id: ''
29
+ const root = document.documentElement;
30
+ root.style.setProperty('--rp-vt-clip-start', clipPath[0]);
31
+ root.style.setProperty('--rp-vt-clip-end', clipPath[1]);
32
+ root.classList.add('rp-appearance-transition');
33
+ const cleanup = ()=>{
34
+ root.classList.remove('rp-appearance-transition');
35
+ root.style.removeProperty('--rp-vt-clip-start');
36
+ root.style.removeProperty('--rp-vt-clip-end');
37
+ isAppearanceTransitioning = false;
38
+ };
39
+ let updated = false;
40
+ const updateTheme = ()=>{
41
+ updated = true;
42
+ flushSync(()=>{
43
+ setTheme(nextTheme);
44
+ onClick?.();
51
45
  });
52
- });
53
- transition.finished.then(dispose, dispose);
46
+ };
47
+ try {
48
+ const transition = document.startViewTransition(async ()=>{
49
+ updateTheme();
50
+ });
51
+ transition.updateCallbackDone.catch(()=>{
52
+ transition.skipTransition();
53
+ });
54
+ transition.ready.catch(()=>{
55
+ transition.skipTransition();
56
+ });
57
+ transition.finished.then(cleanup, cleanup);
58
+ } catch {
59
+ cleanup();
60
+ if (!updated) updateTheme();
61
+ }
54
62
  } else {
55
63
  setTheme(nextTheme);
56
64
  onClick?.();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_navigate` for known internal routes. Waits for committed
2
+ * Registers `navigate` for known internal routes. Waits for committed
3
3
  * page context before returning metadata, section routes, and adjacent pages.
4
4
  * @unstable
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_list_pages` for filtered, paginated page discovery,
2
+ * Registers `list_pages` for filtered, paginated page discovery,
3
3
  * defaulting to the active language and version without requiring search.
4
4
  * @unstable
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_get_page` and `rspress_get_current_page` to read page
2
+ * Registers `get_page` and `get_current_page` to read page
3
3
  * metadata and generated SSG-MD without navigating. The app registers these
4
4
  * tools when Markdown generation is enabled, independently of the theme UI.
5
5
  * @unstable
@@ -4,7 +4,7 @@ function useWebMcpPageReading() {
4
4
  const { page } = usePage();
5
5
  const { site } = useSite();
6
6
  const { pages } = usePages();
7
- useWebMcp(defineTool('get_page', 'Read metadata and generated Markdown for a known documentation route without navigating. Paths are relative to the site base.', {
7
+ useWebMcp(defineTool('get_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the documentation page specified by routePath, without navigating. Paths are relative to the site base.', {
8
8
  routePath: routePathField
9
9
  }, [
10
10
  'routePath'
@@ -18,6 +18,6 @@ function useWebMcpPageReading() {
18
18
  if (!targetPage) throw new TypeError(`Unknown internal route: ${path}`);
19
19
  return readPage(targetPage, site.base, signal);
20
20
  }));
21
- useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the current documentation page.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
21
+ useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the documentation page currently open in the browser.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
22
22
  }
23
23
  export { useWebMcpPageReading };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_get_site_info` to expose site metadata, locales, versions,
2
+ * Registers `get_site_info` to expose site metadata, locales, versions,
3
3
  * navigation, and the active sidebar from the current page context.
4
4
  * @unstable
5
5
  */
@@ -20,6 +20,11 @@ export declare const IconHeader: Icon;
20
20
  export declare const IconJsdelivr: Icon;
21
21
  export declare const IconJump: Icon;
22
22
  export declare const IconLoading: Icon;
23
+ /**
24
+ * Markdown Mark by Dustin Curtis, dedicated to the public domain.
25
+ * @see https://github.com/dcurtis/markdown-mark
26
+ */
27
+ export declare const IconMarkdown: Icon;
23
28
  export declare const IconMenu: Icon;
24
29
  export declare const IconMoon: Icon;
25
30
  export declare const IconNpm: Icon;