@rspress/core 2.0.9 → 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 (119) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/3323.js +8 -0
  3. package/dist/{740.js → 5810.js} +127 -139
  4. package/dist/{2240.js → 6162.js} +1 -4
  5. package/dist/8006.js +1 -1
  6. package/dist/8857.js +2 -3
  7. package/dist/cli/index.js +7 -4
  8. package/dist/common-Qw-RoVFD.js +25 -0
  9. package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +17 -21
  10. package/dist/eject-theme/components/DocContent/doc.scss +14 -41
  11. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -2
  12. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +14 -8
  13. package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +13 -5
  14. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +8 -5
  15. package/dist/eject-theme/components/Outline/index.scss +1 -1
  16. package/dist/eject-theme/components/Prompt/icons.tsx +80 -0
  17. package/dist/eject-theme/components/Prompt/index.scss +423 -0
  18. package/dist/eject-theme/components/Prompt/index.tsx +335 -0
  19. package/dist/eject-theme/components/Search/logic/search.ts +10 -5
  20. package/dist/eject-theme/components/Search/logic/util.test.ts +20 -1
  21. package/dist/eject-theme/components/Search/logic/util.ts +4 -1
  22. package/dist/eject-theme/components/SidebarMenu/index.tsx +5 -1
  23. package/dist/entry/process.d.ts +1 -0
  24. package/dist/entry/process.js +65 -0
  25. package/dist/entry/utils.d.ts +7 -0
  26. package/dist/entry/utils.js +2 -0
  27. package/dist/entry/worker.d.ts +1 -0
  28. package/dist/entry/worker.js +74 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +1 -0
  31. package/dist/node/PluginDriver.js +1 -1
  32. package/dist/node/auto-nav-sidebar/index.js +1 -1
  33. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  34. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  35. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  36. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  37. package/dist/node/eject.js +1 -0
  38. package/dist/node/index.d.ts +1 -0
  39. package/dist/node/initRsbuild.js +1 -1
  40. package/dist/node/mdx/options.js +2 -1
  41. package/dist/node/mdx/processor.js +1 -1
  42. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  43. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  44. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  45. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +1 -1
  46. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  47. package/dist/node/mdx/remarkPlugins/fileCodeBlock.d.ts +1 -0
  48. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +9 -4
  49. package/dist/node/mdx/remarkPlugins/image.js +1 -1
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  51. package/dist/node/route/RoutePage.js +1 -1
  52. package/dist/node/route/RouteService.js +1 -1
  53. package/dist/node/route/extractPageData.js +1 -1
  54. package/dist/node/route/normalizeRoutePath.js +1 -1
  55. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
  56. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
  57. package/dist/node/runtimeModule/i18n.js +1 -1
  58. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  59. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  60. package/dist/node/runtimeModule/searchHooks.js +1 -1
  61. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  62. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  63. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  64. package/dist/node/serve.js +1 -1
  65. package/dist/node/ssg/renderPages.js +2 -2
  66. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  67. package/dist/node/ssg/ssgEnv.js +1 -1
  68. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  69. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  70. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  71. package/dist/node/ssg-md/renderPage.js +1 -1
  72. package/dist/node/ssg-md/renderPages.js +1 -1
  73. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  74. package/dist/node/utils/checkLanguageParity.js +1 -1
  75. package/dist/node/utils/createHash.js +1 -1
  76. package/dist/node/utils/flattenMdxContent.js +1 -1
  77. package/dist/node/utils/getPageKey.js +1 -1
  78. package/dist/node/utils/reactAlias.js +1 -1
  79. package/dist/runtime/BrowserOnly.d.ts +7 -0
  80. package/dist/runtime/BrowserOnly.js +40 -0
  81. package/dist/runtime/BrowserOnly.test.d.ts +1 -0
  82. package/dist/runtime/index.d.ts +1 -0
  83. package/dist/runtime/index.js +1 -0
  84. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +14 -12
  85. package/dist/theme/components/DocContent/doc.css +13 -21
  86. package/dist/theme/components/Llms/LlmsCopyButton.js +5 -6
  87. package/dist/theme/components/Llms/LlmsCopyRow.js +5 -5
  88. package/dist/theme/components/Llms/LlmsViewOptions.js +1 -3
  89. package/dist/theme/components/Outline/index.css +1 -1
  90. package/dist/theme/components/Prompt/icons.d.ts +10 -0
  91. package/dist/theme/components/Prompt/icons.js +64 -0
  92. package/dist/theme/components/Prompt/index.css +326 -0
  93. package/dist/theme/components/Prompt/index.d.ts +33 -0
  94. package/dist/theme/components/Prompt/index.js +262 -0
  95. package/dist/theme/components/Search/logic/search.js +5 -3
  96. package/dist/theme/components/Search/logic/util.js +2 -1
  97. package/dist/theme/components/SidebarMenu/index.js +2 -1
  98. package/dist/theme/index.d.ts +3 -0
  99. package/dist/theme/index.js +3 -0
  100. package/dist/theme/layout/DocLayout/index.css +9 -1
  101. package/dist/theme/layout/DocLayout/index.js +11 -6
  102. package/dist/theme/logic/copyToClipboard.d.ts +1 -0
  103. package/dist/theme/{components/Llms/copy.js → logic/copyToClipboard.js} +4 -3
  104. package/dist/theme/logic/getCopyableText.d.ts +5 -0
  105. package/dist/theme/logic/getCopyableText.js +52 -0
  106. package/dist/theme/logic/useThemeState.d.ts +5 -10
  107. package/dist/theme/logic/useThemeState.js +15 -20
  108. package/dist/theme/styles/vars/base-vars.css +4 -4
  109. package/dist/utils-B--2TaWv.js +34 -0
  110. package/dist/utils-De75vAgL.js +7 -0
  111. package/package.json +16 -16
  112. package/dist/3425.js +0 -6
  113. package/dist/eject-theme/components/Llms/copy.ts +0 -12
  114. package/dist/runtime/getSidebarDataGroup.test.js +0 -68
  115. package/dist/runtime/hooks/useWindowSize.test.js +0 -36
  116. package/dist/runtime/route.test.js +0 -154
  117. package/dist/runtime/utils.test.js +0 -34
  118. package/dist/theme/components/Llms/copy.d.ts +0 -1
  119. package/dist/theme/components/Search/logic/util.test.js +0 -51
@@ -0,0 +1,262 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useI18n } from "@rspress/core/runtime";
3
+ import { IconArrowDown, IconCopy, IconSuccess, SvgWrapper, copyToClipboard, renderInlineMarkdown } from "@rspress/core/theme";
4
+ import clsx from "clsx";
5
+ import { useCallback, useEffect, useId, useRef, useState } from "react";
6
+ import { AGENT_ICONS } from "./icons.js";
7
+ import "./index.css";
8
+ const ROTATE_INTERVAL = 3500;
9
+ const FADE_DURATION = 400;
10
+ function RotatingIcon({ index, fading }) {
11
+ return /*#__PURE__*/ jsx("span", {
12
+ className: clsx('rp-prompt__icon', fading && 'rp-prompt__icon--fade-out'),
13
+ title: AGENT_ICONS[index].name,
14
+ children: AGENT_ICONS[index].svg
15
+ });
16
+ }
17
+ function useRotatingIcon() {
18
+ const [iconIndex, setIconIndex] = useState(0);
19
+ const [fading, setFading] = useState(false);
20
+ const rotateTimeoutRef = useRef(null);
21
+ useEffect(()=>{
22
+ const timer = setInterval(()=>{
23
+ setFading(true);
24
+ rotateTimeoutRef.current = setTimeout(()=>{
25
+ setIconIndex((prev)=>(prev + 1) % AGENT_ICONS.length);
26
+ setFading(false);
27
+ rotateTimeoutRef.current = null;
28
+ }, FADE_DURATION);
29
+ }, ROTATE_INTERVAL);
30
+ return ()=>{
31
+ clearInterval(timer);
32
+ if (rotateTimeoutRef.current) clearTimeout(rotateTimeoutRef.current);
33
+ };
34
+ }, []);
35
+ return {
36
+ fading,
37
+ iconIndex
38
+ };
39
+ }
40
+ function CustomPrompt({ children, className, defaultCollapsed: _defaultCollapsed, description: _description, eyebrow = 'For your Agent', prompt: _prompt, style, title: _title, ...props }) {
41
+ const { fading, iconIndex } = useRotatingIcon();
42
+ return /*#__PURE__*/ jsxs("div", {
43
+ ...props,
44
+ className: clsx('rp-prompt', 'rp-prompt--custom', className),
45
+ style: {
46
+ '--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
47
+ ...style
48
+ },
49
+ children: [
50
+ /*#__PURE__*/ jsx("div", {
51
+ className: "rp-prompt__backdrop"
52
+ }),
53
+ /*#__PURE__*/ jsxs("div", {
54
+ className: "rp-prompt__panel",
55
+ children: [
56
+ /*#__PURE__*/ jsx("div", {
57
+ className: "rp-prompt__meta",
58
+ children: /*#__PURE__*/ jsxs("span", {
59
+ className: "rp-prompt__eyebrow",
60
+ children: [
61
+ /*#__PURE__*/ jsx(RotatingIcon, {
62
+ index: iconIndex,
63
+ fading: fading
64
+ }),
65
+ eyebrow
66
+ ]
67
+ })
68
+ }),
69
+ /*#__PURE__*/ jsx("div", {
70
+ className: "rp-prompt__custom-content",
71
+ children: children
72
+ })
73
+ ]
74
+ })
75
+ ]
76
+ });
77
+ }
78
+ function CopyablePrompt({ className, defaultCollapsed = true, description, eyebrow = 'For your Agent', onClick, prompt, style, title = 'Agent Prompt', ...props }) {
79
+ const t = useI18n();
80
+ const contentId = useId();
81
+ const [collapsed, setCollapsed] = useState(defaultCollapsed);
82
+ const [copied, setCopied] = useState(false);
83
+ const { fading, iconIndex } = useRotatingIcon();
84
+ const [ripples, setRipples] = useState([]);
85
+ const cardRef = useRef(null);
86
+ const copyTimerRef = useRef(null);
87
+ const rippleTimersRef = useRef(new Set());
88
+ useEffect(()=>()=>{
89
+ copyTimerRef.current && clearTimeout(copyTimerRef.current);
90
+ rippleTimersRef.current.forEach(clearTimeout);
91
+ rippleTimersRef.current.clear();
92
+ }, []);
93
+ const handleCopy = useCallback(async ()=>{
94
+ if (!prompt) return;
95
+ const isCopied = await copyToClipboard(prompt);
96
+ if (!isCopied) return;
97
+ setCopied(true);
98
+ if (copyTimerRef.current) clearTimeout(copyTimerRef.current);
99
+ copyTimerRef.current = setTimeout(()=>{
100
+ setCopied(false);
101
+ copyTimerRef.current = null;
102
+ }, 2000);
103
+ }, [
104
+ prompt
105
+ ]);
106
+ const handleCardActivate = useCallback((e)=>{
107
+ onClick?.(e);
108
+ if (e.defaultPrevented) return;
109
+ if (window.getSelection()?.toString()) return;
110
+ const target = e.target;
111
+ if (target.closest('a, button, .rp-prompt__action-copy, .rp-prompt__action-toggle')) return;
112
+ const rect = cardRef.current?.getBoundingClientRect();
113
+ if (!rect) return;
114
+ const id = Date.now() + Math.random();
115
+ setRipples((prev)=>[
116
+ ...prev,
117
+ {
118
+ id,
119
+ x: e.clientX - rect.left,
120
+ y: e.clientY - rect.top
121
+ }
122
+ ]);
123
+ const timer = setTimeout(()=>{
124
+ setRipples((prev)=>prev.filter((r)=>r.id !== id));
125
+ rippleTimersRef.current.delete(timer);
126
+ }, 600);
127
+ rippleTimersRef.current.add(timer);
128
+ handleCopy();
129
+ }, [
130
+ handleCopy,
131
+ onClick
132
+ ]);
133
+ return /*#__PURE__*/ jsxs("div", {
134
+ ...props,
135
+ ref: cardRef,
136
+ className: clsx('rp-prompt', className),
137
+ style: {
138
+ '--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
139
+ ...style
140
+ },
141
+ onClick: handleCardActivate,
142
+ children: [
143
+ /*#__PURE__*/ jsx("div", {
144
+ className: "rp-prompt__backdrop"
145
+ }),
146
+ ripples.map((r)=>/*#__PURE__*/ jsx("span", {
147
+ className: "rp-prompt__ripple",
148
+ style: {
149
+ left: r.x,
150
+ top: r.y
151
+ }
152
+ }, r.id)),
153
+ /*#__PURE__*/ jsxs("div", {
154
+ className: "rp-prompt__panel",
155
+ children: [
156
+ /*#__PURE__*/ jsxs("div", {
157
+ className: "rp-prompt__header",
158
+ children: [
159
+ /*#__PURE__*/ jsx("div", {
160
+ className: clsx('rp-prompt__meta', copied && 'rp-prompt__meta--copied'),
161
+ children: /*#__PURE__*/ jsxs("span", {
162
+ className: "rp-prompt__eyebrow",
163
+ children: [
164
+ /*#__PURE__*/ jsx(RotatingIcon, {
165
+ index: iconIndex,
166
+ fading: fading
167
+ }),
168
+ eyebrow
169
+ ]
170
+ })
171
+ }),
172
+ /*#__PURE__*/ jsxs("div", {
173
+ className: "rp-prompt__header-row",
174
+ children: [
175
+ /*#__PURE__*/ jsxs("div", {
176
+ className: "rp-prompt__header-left",
177
+ children: [
178
+ /*#__PURE__*/ jsx("div", {
179
+ className: "rp-prompt__title-with-icon",
180
+ children: /*#__PURE__*/ jsx("div", {
181
+ className: "rp-prompt__title",
182
+ children: title
183
+ })
184
+ }),
185
+ description ? /*#__PURE__*/ jsx("p", {
186
+ className: "rp-prompt__description",
187
+ ...renderInlineMarkdown(description)
188
+ }) : null
189
+ ]
190
+ }),
191
+ /*#__PURE__*/ jsxs("div", {
192
+ className: "rp-prompt__header-actions",
193
+ children: [
194
+ /*#__PURE__*/ jsxs("button", {
195
+ type: "button",
196
+ className: clsx('rp-prompt__action-copy', copied && 'rp-prompt__action-copy--copied'),
197
+ onClick: (e)=>{
198
+ e.stopPropagation();
199
+ handleCopy();
200
+ },
201
+ title: t('promptCopyText'),
202
+ children: [
203
+ /*#__PURE__*/ jsx(SvgWrapper, {
204
+ icon: copied ? IconSuccess : IconCopy,
205
+ className: "rp-prompt__action-icon"
206
+ }),
207
+ /*#__PURE__*/ jsx("span", {
208
+ children: copied ? t('promptCopiedText') : t('promptCopyText')
209
+ })
210
+ ]
211
+ }),
212
+ /*#__PURE__*/ jsx("button", {
213
+ type: "button",
214
+ className: "rp-prompt__action-toggle",
215
+ onClick: (e)=>{
216
+ e.stopPropagation();
217
+ setCollapsed((value)=>!value);
218
+ },
219
+ "aria-controls": contentId,
220
+ "aria-expanded": !collapsed,
221
+ title: collapsed ? t('promptExpandText') : t('promptCollapseText'),
222
+ children: /*#__PURE__*/ jsx(SvgWrapper, {
223
+ icon: IconArrowDown,
224
+ className: clsx('rp-prompt__action-toggle-icon', !collapsed && 'rp-prompt__action-toggle-icon--expanded')
225
+ })
226
+ })
227
+ ]
228
+ })
229
+ ]
230
+ })
231
+ ]
232
+ }),
233
+ /*#__PURE__*/ jsx("div", {
234
+ id: contentId,
235
+ className: clsx('rp-prompt__content', collapsed && 'rp-prompt__content--collapsed'),
236
+ "aria-hidden": collapsed,
237
+ children: /*#__PURE__*/ jsx("div", {
238
+ className: "rp-prompt__content-inner",
239
+ children: /*#__PURE__*/ jsx("div", {
240
+ className: "rp-prompt__content-body",
241
+ style: {
242
+ whiteSpace: 'pre-wrap'
243
+ },
244
+ children: prompt
245
+ })
246
+ })
247
+ })
248
+ ]
249
+ })
250
+ ]
251
+ });
252
+ }
253
+ function Prompt({ custom = false, ...props }) {
254
+ return custom ? /*#__PURE__*/ jsx(CustomPrompt, {
255
+ ...props
256
+ }) : /*#__PURE__*/ jsx(CopyablePrompt, {
257
+ ...props
258
+ });
259
+ }
260
+ var components_Prompt = Prompt;
261
+ export default components_Prompt;
262
+ export { Prompt };
@@ -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) {
@@ -10,7 +10,8 @@ const SidebarMenu = /*#__PURE__*/ forwardRef(({ isSidebarOpen, onIsSidebarOpenCh
10
10
  const { pathname, hash } = useLocation();
11
11
  const headers = useDynamicToc();
12
12
  const { scrolledHeader } = useActiveAnchor(headers);
13
- const { frontmatter: { sidebar: showSidebar = true, outline: showOutline = true } } = useFrontmatter();
13
+ const { frontmatter: { sidebar: sidebarConfig = true, outline: showOutline = true } } = useFrontmatter();
14
+ const showSidebar = true === sidebarConfig;
14
15
  function openSidebar() {
15
16
  onIsSidebarOpenChange(true);
16
17
  }
@@ -33,6 +33,7 @@ export { type Group, type GroupItem, OverviewGroup, } from './components/Overvie
33
33
  export { type PackageManagerTabProps, PackageManagerTabs, } from './components/PackageManagerTabs/index.js';
34
34
  export { PageTab, type PageTabProps, PageTabs, type PageTabsProps, } from './components/PageTabs/index.js';
35
35
  export { PrevNextPage } from './components/PrevNextPage/index.js';
36
+ export { Prompt, type PromptProps } from './components/Prompt/index.js';
36
37
  export { ReadPercent } from './components/ReadPercent/index.js';
37
38
  export { useReadPercent } from './components/ReadPercent/useReadPercent.js';
38
39
  export { Root, type RootProps } from './components/Root/index.js';
@@ -57,6 +58,8 @@ export { DocLayout, type DocLayoutProps } from './layout/DocLayout/index.js';
57
58
  export { HomeLayout, type HomeLayoutProps } from './layout/HomeLayout/index.js';
58
59
  export { Layout, type LayoutProps } from './layout/Layout/index.js';
59
60
  export { NotFoundLayout } from './layout/NotFountLayout/index.js';
61
+ export { copyToClipboard } from './logic/copyToClipboard.js';
62
+ export { getCopyableText } from './logic/getCopyableText.js';
60
63
  export { mergeRefs } from './logic/mergeRefs.js';
61
64
  export { useFullTextSearch } from './logic/useFullTextSearch.js';
62
65
  export { usePrevNextPage } from './logic/usePrevNextPage.js';
@@ -33,6 +33,7 @@ export { OverviewGroup } from "./components/OverviewGroup/index.js";
33
33
  export { PackageManagerTabs } from "./components/PackageManagerTabs/index.js";
34
34
  export { PageTab, PageTabs } from "./components/PageTabs/index.js";
35
35
  export { PrevNextPage } from "./components/PrevNextPage/index.js";
36
+ export { Prompt } from "./components/Prompt/index.js";
36
37
  export { ReadPercent } from "./components/ReadPercent/index.js";
37
38
  export { useReadPercent } from "./components/ReadPercent/useReadPercent.js";
38
39
  export { Root } from "./components/Root/index.js";
@@ -55,6 +56,8 @@ export { DocLayout } from "./layout/DocLayout/index.js";
55
56
  export { HomeLayout } from "./layout/HomeLayout/index.js";
56
57
  export { Layout } from "./layout/Layout/index.js";
57
58
  export { NotFoundLayout } from "./layout/NotFountLayout/index.js";
59
+ export { copyToClipboard } from "./logic/copyToClipboard.js";
60
+ export { getCopyableText } from "./logic/getCopyableText.js";
58
61
  export { mergeRefs } from "./logic/mergeRefs.js";
59
62
  export { useFullTextSearch } from "./logic/useFullTextSearch.js";
60
63
  export { usePrevNextPage } from "./logic/usePrevNextPage.js";
@@ -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;
@@ -115,10 +119,14 @@
115
119
  }
116
120
 
117
121
  .rp-doc-layout__sidebar-placeholder {
118
- width: var(--rp-sidebar-width);
122
+ width: 12vw;
119
123
  margin-left: var(--rp-sidebar-margin-left);
120
124
  }
121
125
 
126
+ .rp-doc-layout__sidebar-placeholder--legacy {
127
+ width: var(--rp-sidebar-width);
128
+ }
129
+
122
130
  .rp-doc-layout__outline {
123
131
  margin-right: var(--rp-outline-margin-right);
124
132
  padding-bottom: var(--rp-content-padding-y);
@@ -8,7 +8,12 @@ function DocLayout(props) {
8
8
  const { beforeDocFooter, afterDocFooter, beforeDoc, afterDoc, beforeDocContent, afterDocContent, beforeOutline, afterOutline, beforeSidebar, afterSidebar, components } = props;
9
9
  const { frontmatter } = useFrontmatter();
10
10
  const isOverviewPage = frontmatter?.overview ?? false;
11
- const { sidebar: showSidebar = true, outline: showOutline = true, footer: showDocFooter = true, pageType } = frontmatter;
11
+ const sidebar = frontmatter?.sidebar ?? true;
12
+ const showSidebar = true === sidebar;
13
+ const showSidebarPlaceholder = false === sidebar || 'placeholder' === sidebar;
14
+ const isLegacyPlaceholder = 'placeholder' === sidebar;
15
+ const { outline: showOutline = true, footer: showDocFooter = true, pageType } = frontmatter;
16
+ const showSidebarMenu = showSidebar || !isOverviewPage && showOutline;
12
17
  if (process.env.__SSR_MD__) return /*#__PURE__*/ jsx(Fragment, {
13
18
  children: isOverviewPage ? /*#__PURE__*/ jsx(Overview, {
14
19
  content: /*#__PURE__*/ jsx(DocContent, {
@@ -24,13 +29,13 @@ function DocLayout(props) {
24
29
  const { rspressDocRef } = useWatchToc();
25
30
  return /*#__PURE__*/ jsxs(Fragment, {
26
31
  children: [
27
- /*#__PURE__*/ jsx("div", {
32
+ showSidebarMenu && /*#__PURE__*/ jsx("div", {
28
33
  className: "rp-doc-layout__menu",
29
34
  children: sidebarMenu
30
35
  }),
31
36
  beforeDoc,
32
37
  /*#__PURE__*/ jsxs("div", {
33
- className: "rp-doc-layout__container",
38
+ className: clsx('rp-doc-layout__container', !showSidebarMenu && 'rp-doc-layout__container--no-menu'),
34
39
  children: [
35
40
  showSidebar ? /*#__PURE__*/ jsxs("aside", {
36
41
  className: clsx('rp-doc-layout__sidebar', isSidebarOpen && 'rp-doc-layout__sidebar--open', 'rp-scrollbar'),
@@ -40,12 +45,12 @@ function DocLayout(props) {
40
45
  /*#__PURE__*/ jsx(Sidebar, {}),
41
46
  afterSidebar
42
47
  ]
43
- }) : /*#__PURE__*/ jsx("aside", {
44
- className: "rp-doc-layout__sidebar-placeholder",
48
+ }) : showSidebarPlaceholder ? /*#__PURE__*/ jsx("aside", {
49
+ className: clsx('rp-doc-layout__sidebar-placeholder', isLegacyPlaceholder && 'rp-doc-layout__sidebar-placeholder--legacy'),
45
50
  style: isDocWide ? {
46
51
  width: '0'
47
52
  } : {}
48
- }),
53
+ }) : null,
49
54
  isOverviewPage ? /*#__PURE__*/ jsx(Fragment, {
50
55
  children: /*#__PURE__*/ jsxs("main", {
51
56
  className: "rp-doc-layout__overview",
@@ -0,0 +1 @@
1
+ export declare function copyToClipboard(text: string): Promise<boolean>;
@@ -1,9 +1,10 @@
1
1
  import copy_to_clipboard from "copy-to-clipboard";
2
2
  async function copyToClipboard(text) {
3
- if (navigator.clipboard?.writeText) try {
3
+ if ("u" > typeof navigator && navigator.clipboard?.writeText) try {
4
4
  await navigator.clipboard.writeText(text);
5
- return;
5
+ return true;
6
6
  } catch {}
7
- copy_to_clipboard(text);
7
+ if ("u" < typeof document) return false;
8
+ return copy_to_clipboard(text);
8
9
  }
9
10
  export { copyToClipboard };
@@ -0,0 +1,5 @@
1
+ export interface GetCopyableTextOptions {
2
+ ignoreClasses?: string[];
3
+ ignoreSelectors?: string[];
4
+ }
5
+ export declare function getCopyableText(element: HTMLElement | null, options?: GetCopyableTextOptions): string;
@@ -0,0 +1,52 @@
1
+ function getCopyableText(element, options = {}) {
2
+ if (!element) return '';
3
+ const { ignoreClasses = [], ignoreSelectors = [] } = options;
4
+ const nodeFilter = element.ownerDocument.defaultView?.NodeFilter ?? NodeFilter;
5
+ const walk = element.ownerDocument.createTreeWalker(element, nodeFilter.SHOW_TEXT);
6
+ let text = '';
7
+ let node = walk.nextNode();
8
+ const markdownState = {
9
+ seenNodes: new WeakSet()
10
+ };
11
+ let previousBlock = null;
12
+ while(node){
13
+ const parentElement = node.parentElement;
14
+ const shouldIgnore = !parentElement || ignoreClasses.some((className)=>parentElement.classList.contains(className)) || ignoreSelectors.some((selector)=>parentElement.closest(selector));
15
+ if (!shouldIgnore) {
16
+ const currentBlock = getBlockElement(parentElement, element);
17
+ if ((node.previousSibling?.nodeName === 'BR' || parentElement.previousSibling?.nodeName === 'BR') && !text.endsWith('\n')) text += '\n';
18
+ if (currentBlock && previousBlock && currentBlock !== previousBlock && !text.endsWith('\n')) text += '\n';
19
+ text += toMarkdown(parentElement, markdownState);
20
+ text += node.nodeValue ?? '';
21
+ previousBlock = currentBlock;
22
+ }
23
+ node = walk.nextNode();
24
+ }
25
+ return text;
26
+ }
27
+ function getBlockElement(element, rootElement) {
28
+ const blockElement = element.closest('li, p, div, pre, blockquote');
29
+ if (!blockElement) return null;
30
+ return rootElement.contains(blockElement) ? blockElement : null;
31
+ }
32
+ function toMarkdown(node, state) {
33
+ if (node.nodeType !== Node.ELEMENT_NODE) return '';
34
+ const element = node;
35
+ const listItem = element.closest('li');
36
+ if (listItem && !state.seenNodes.has(listItem)) {
37
+ state.seenNodes.add(listItem);
38
+ return toMarkdownListItem(listItem);
39
+ }
40
+ return '';
41
+ }
42
+ function toMarkdownListItem(listItem) {
43
+ const list = listItem.parentElement;
44
+ if (!list) return '- ';
45
+ if ('OL' === list.tagName) {
46
+ const listItems = Array.from(list.children).filter((child)=>'LI' === child.tagName);
47
+ const index = listItems.indexOf(listItem);
48
+ return `${index + 1}. `;
49
+ }
50
+ return '- ';
51
+ }
52
+ export { getCopyableText };
@@ -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 };
@@ -11,8 +11,8 @@
11
11
  --rp-c-text-3: #3c3c3c54;
12
12
  --rp-c-text-4: #3c3c3c2e;
13
13
  --rp-c-text-code: #476582;
14
- --rp-c-text-code-bg: #99a1b314;
15
- --rp-c-text-code-border: #0000000d;
14
+ --rp-c-text-code-bg: #99a1b30f;
15
+ --rp-c-text-code-border: #00000009;
16
16
  --rp-c-link: var(--rp-c-brand-dark);
17
17
  }
18
18
 
@@ -29,8 +29,8 @@
29
29
  --rp-c-text-3: #ebebeb61;
30
30
  --rp-c-text-4: #ebebeb2e;
31
31
  --rp-c-text-code: #c9def1;
32
- --rp-c-text-code-bg: #ffffff14;
33
- --rp-c-text-code-border: #ffffff0d;
32
+ --rp-c-text-code-bg: #ffffff0f;
33
+ --rp-c-text-code-border: #ffffff0a;
34
34
  --rp-c-link: var(--rp-c-brand-light);
35
35
  }
36
36
 
@@ -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 };