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

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 (181) hide show
  1. package/dist/{0~7675.723d12b2.js → 0~7675.d236b058.js} +3 -3
  2. package/dist/{5485.9fc7f63d.js → 5485.7586c86a.js} +1 -1
  3. package/dist/{3521.9eb6b114.js → 7786.421b464f.js} +2 -2
  4. package/dist/9348.1beb3e25.js +11 -0
  5. package/dist/_private/react/render.js +1 -1
  6. package/dist/cli/index.js +2 -2
  7. package/dist/config/defineConfig.d.ts +40 -0
  8. package/dist/{cli/config → config}/loadConfigFile.js +2 -2
  9. package/dist/eject-theme/components/Callout/index.scss +6 -6
  10. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  11. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +21 -2
  12. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -0
  13. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -1
  14. package/dist/eject-theme/components/HomeHero/index.scss +8 -0
  15. package/dist/eject-theme/components/HomeHero/index.tsx +11 -2
  16. package/dist/eject-theme/components/Llms/LlmsContainer.scss +6 -0
  17. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +9 -0
  18. package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +57 -0
  19. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +94 -0
  20. package/dist/eject-theme/components/Llms/LlmsViewOptions.scss +98 -0
  21. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +259 -0
  22. package/dist/eject-theme/components/Llms/index.scss +42 -0
  23. package/dist/eject-theme/components/Llms/index.tsx +4 -0
  24. package/dist/eject-theme/components/Llms/useMdUrl.ts +14 -0
  25. package/dist/eject-theme/components/Nav/index.scss +3 -0
  26. package/dist/eject-theme/components/Nav/index.tsx +7 -2
  27. package/dist/eject-theme/components/{Nav/NavTitle.tsx → NavTitle/index.tsx} +15 -6
  28. package/dist/eject-theme/components/Overview/index.tsx +8 -62
  29. package/dist/eject-theme/components/OverviewGroup/index.tsx +46 -0
  30. package/dist/eject-theme/components/Steps/index.scss +1 -0
  31. package/dist/index.d.ts +2 -1
  32. package/dist/index.js +3 -4
  33. package/dist/node/PluginDriver.js +1 -1
  34. package/dist/node/auto-nav-sidebar/index.js +1 -1
  35. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  36. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  37. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  38. package/dist/node/constants.js +1 -1
  39. package/dist/node/eject.js +1 -0
  40. package/dist/node/initRsbuild.js +6 -6
  41. package/dist/node/last-updated/index.js +1 -1
  42. package/dist/node/mdx/{loader.7c249a26.js → loader.15e0b2d2.js} +0 -5
  43. package/dist/node/mdx/options.js +2 -2
  44. package/dist/node/mdx/processor.js +1 -1
  45. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  46. package/dist/node/mdx/rehypePlugins/headerAnchor.js +2 -3
  47. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  48. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -2
  49. package/dist/node/mdx/remarkPlugins/image.js +1 -3
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -2
  51. package/dist/node/mdx/remarkPlugins/toc.d.ts +4 -3
  52. package/dist/node/mdx/remarkPlugins/toc.js +14 -11
  53. package/dist/node/route/RoutePage.d.ts +3 -1
  54. package/dist/node/route/RoutePage.js +4 -0
  55. package/dist/node/route/RouteService.js +2 -2
  56. package/dist/node/route/extractPageData.d.ts +5 -0
  57. package/dist/node/route/extractPageData.js +88 -58
  58. package/dist/node/route/normalizeRoutePath.js +2 -2
  59. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  60. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +21 -0
  61. package/dist/node/runtimeModule/i18n.js +4 -3
  62. package/dist/node/runtimeModule/pageData/createPageData.js +9 -6
  63. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +20 -14
  64. package/dist/node/runtimeModule/siteData/createSiteData.js +2 -1
  65. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  66. package/dist/node/serve.js +1 -1
  67. package/dist/node/ssg/renderPage.js +1 -1
  68. package/dist/node/ssg/renderPageWorker.js +1 -1
  69. package/dist/node/ssg/renderPages.js +7 -3
  70. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  71. package/dist/node/ssg/ssgEnv.js +1 -1
  72. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  73. package/dist/node/ssg-md/llms/llmsTxt.js +12 -2
  74. package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
  75. package/dist/node/ssg-md/renderPage.js +1 -1
  76. package/dist/node/ssg-md/renderPages.js +1 -1
  77. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  78. package/dist/node/utils/createHash.js +1 -1
  79. package/dist/node/utils/flattenMdxContent.js +2 -3
  80. package/dist/node/utils/getPageKey.js +1 -1
  81. package/dist/node/utils/normalizePath.js +1 -1
  82. package/dist/node/utils/reactAlias.js +1 -1
  83. package/dist/runtime/Content.d.ts +4 -0
  84. package/dist/runtime/Content.js +18 -0
  85. package/dist/runtime/NoSSR.d.ts +3 -0
  86. package/dist/runtime/NoSSR.js +14 -0
  87. package/dist/runtime/getSidebarDataGroup.test.js +68 -0
  88. package/dist/runtime/hooks/useActiveMatcher.d.ts +1 -0
  89. package/dist/runtime/hooks/useActiveMatcher.js +14 -0
  90. package/dist/runtime/hooks/useDark.d.ts +7 -0
  91. package/dist/runtime/hooks/useDark.js +7 -0
  92. package/dist/runtime/hooks/useFrontmatter.d.ts +4 -0
  93. package/dist/runtime/hooks/useFrontmatter.js +9 -0
  94. package/dist/runtime/hooks/useI18n.d.ts +2 -0
  95. package/dist/runtime/hooks/useI18n.js +14 -0
  96. package/dist/runtime/hooks/useLang.d.ts +1 -0
  97. package/dist/runtime/hooks/useLang.js +6 -0
  98. package/dist/runtime/hooks/useLocaleSiteData.d.ts +18 -0
  99. package/dist/runtime/hooks/useLocaleSiteData.js +20 -0
  100. package/dist/runtime/hooks/useNav.d.ts +1 -0
  101. package/dist/runtime/hooks/useNav.js +12 -0
  102. package/dist/runtime/hooks/usePage.d.ts +10 -0
  103. package/dist/runtime/hooks/usePage.js +9 -0
  104. package/dist/runtime/hooks/usePageData.d.ts +5 -0
  105. package/dist/runtime/hooks/usePageData.js +16 -0
  106. package/dist/runtime/hooks/usePages.d.ts +4 -0
  107. package/dist/runtime/hooks/usePages.js +7 -0
  108. package/dist/runtime/hooks/useSidebar.d.ts +16 -0
  109. package/dist/runtime/hooks/useSidebar.js +67 -0
  110. package/dist/runtime/hooks/useSite.d.ts +4 -0
  111. package/dist/runtime/hooks/useSite.js +7 -0
  112. package/dist/runtime/hooks/useVersion.d.ts +1 -0
  113. package/dist/runtime/hooks/useVersion.js +6 -0
  114. package/dist/runtime/hooks/useWindowSize.d.ts +9 -0
  115. package/dist/runtime/hooks/useWindowSize.js +31 -0
  116. package/dist/runtime/hooks/useWindowSize.test.js +36 -0
  117. package/dist/runtime/index.d.ts +21 -0
  118. package/dist/runtime/index.js +22 -0
  119. package/dist/runtime/route.d.ts +36 -0
  120. package/dist/runtime/route.js +53 -0
  121. package/dist/runtime/route.test.js +154 -0
  122. package/dist/runtime/ssrMdServerEntry.js +1 -1
  123. package/dist/runtime/utils.d.ts +12 -0
  124. package/dist/runtime/utils.js +34 -0
  125. package/dist/runtime/utils.test.js +34 -0
  126. package/dist/theme/components/Callout/index.css +6 -6
  127. package/dist/theme/components/CodeBlock/index.js +1 -1
  128. package/dist/theme/components/DocContent/docComponents/title.js +25 -5
  129. package/dist/theme/components/FallbackHeading/index.js +4 -1
  130. package/dist/theme/components/HomeBackground/useNavTransparent.js +1 -1
  131. package/dist/theme/components/HomeHero/index.css +16 -10
  132. package/dist/theme/components/HomeHero/index.js +10 -3
  133. package/dist/theme/components/Llms/LlmsContainer.css +7 -0
  134. package/dist/theme/components/Llms/LlmsContainer.d.ts +5 -0
  135. package/dist/theme/components/Llms/LlmsContainer.js +9 -0
  136. package/dist/theme/components/Llms/LlmsCopyButton.css +57 -0
  137. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +20 -0
  138. package/dist/theme/components/Llms/LlmsCopyButton.js +73 -0
  139. package/dist/theme/components/Llms/LlmsCopyButton.js.LICENSE.txt +5 -0
  140. package/dist/theme/components/Llms/LlmsViewOptions.css +93 -0
  141. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +34 -0
  142. package/dist/theme/components/Llms/LlmsViewOptions.js +206 -0
  143. package/dist/theme/components/Llms/LlmsViewOptions.js.LICENSE.txt +5 -0
  144. package/dist/theme/components/Llms/index.css +32 -0
  145. package/dist/theme/components/Llms/index.d.ts +4 -0
  146. package/dist/theme/components/Llms/index.js +5 -0
  147. package/dist/theme/components/Llms/useMdUrl.d.ts +6 -0
  148. package/dist/theme/components/Llms/useMdUrl.js +15 -0
  149. package/dist/theme/components/Nav/index.css +1 -0
  150. package/dist/theme/components/Nav/index.js +1 -2
  151. package/dist/theme/components/{Nav/NavTitle.d.ts → NavTitle/index.d.ts} +1 -1
  152. package/dist/theme/components/{Nav/NavTitle.js → NavTitle/index.js} +11 -6
  153. package/dist/theme/components/Overview/index.js +11 -43
  154. package/dist/theme/components/OverviewGroup/index.js +33 -0
  155. package/dist/theme/components/PageTabs/index.css +1 -1
  156. package/dist/theme/components/Steps/index.css +1 -0
  157. package/dist/theme/components/Tabs/index.css +4 -4
  158. package/dist/theme/hooks/useDynamicToc.d.ts +2 -0
  159. package/dist/theme/hooks/useDynamicToc.js +3 -1
  160. package/dist/theme/index.d.ts +3 -1
  161. package/dist/theme/index.js +4 -2
  162. package/dist/theme/layout/Layout/index.js +1 -1
  163. package/dist/theme/logic/useScrollAfterNav.js +2 -2
  164. package/dist/theme/logic/useScrollReset.js +2 -2
  165. package/dist/theme/logic/{useAppearance.d.ts → useThemeState.d.ts} +4 -1
  166. package/dist/theme/logic/useThemeState.js +50 -0
  167. package/dist/theme/styles/scrollbar.css +14 -2
  168. package/package.json +18 -20
  169. package/static/MediumZoom.tsx +1 -1
  170. package/dist/4669.69cb6b18.js +0 -1
  171. package/dist/8813.4b28f4bb.js +0 -1
  172. package/dist/9643.2dff683e.js +0 -4
  173. package/dist/cli/config/index.d.ts +0 -2
  174. package/dist/runtime.72d450ac.js +0 -1
  175. package/dist/runtime.d.ts +0 -2
  176. package/dist/runtime.js +0 -3
  177. package/dist/theme/logic/useAppearance.js +0 -64
  178. /package/dist/{cli/config/index.js → config/defineConfig.js} +0 -0
  179. /package/dist/{cli/config → config}/loadConfigFile.d.ts +0 -0
  180. /package/dist/eject-theme/components/{Nav/NavTitle.scss → NavTitle/index.scss} +0 -0
  181. /package/dist/theme/components/{Nav/NavTitle.css → NavTitle/index.css} +0 -0
@@ -0,0 +1,7 @@
1
+ .rp-llms-container {
2
+ align-items: center;
3
+ gap: 8px;
4
+ margin-bottom: 20px;
5
+ display: flex;
6
+ }
7
+
@@ -0,0 +1,5 @@
1
+ import type React from 'react';
2
+ import './LlmsContainer.scss';
3
+ export interface LlmsContainerProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ }
5
+ export declare function LlmsContainer(props: LlmsContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "./LlmsContainer.css";
3
+ function LlmsContainer(props) {
4
+ return /*#__PURE__*/ jsx("div", {
5
+ ...props,
6
+ className: 'rp-not-doc rp-llms-container'
7
+ });
8
+ }
9
+ export { LlmsContainer };
@@ -0,0 +1,57 @@
1
+ .rp-llms-copy-button {
2
+ position: relative;
3
+ overflow: hidden;
4
+ }
5
+
6
+ .rp-llms-copy-button--loading.rp-llms-copy-button {
7
+ background: var(--rp-c-bg-mute);
8
+ opacity: .7;
9
+ cursor: wait;
10
+ }
11
+
12
+ .rp-llms-copy-button--success.rp-llms-copy-button {
13
+ color: var(--rp-c-green-1, #10b981);
14
+ border-color: var(--rp-c-green-1, #10b981);
15
+ background: var(--rp-c-bg-soft);
16
+ }
17
+
18
+ .rp-llms-copy-button--success .rp-llms-copy-button__icon-copy {
19
+ opacity: 0;
20
+ transform: translate(-50%, -50%)scale(.5);
21
+ }
22
+
23
+ .rp-llms-copy-button--success .rp-llms-copy-button__icon-success {
24
+ opacity: 1;
25
+ visibility: visible;
26
+ transform: translate(-50%, -50%)scale(1);
27
+ }
28
+
29
+ .rp-llms-copy-button__icon-wrapper {
30
+ width: 16px;
31
+ height: 16px;
32
+ position: relative;
33
+ }
34
+
35
+ .rp-llms-copy-button__icon-copy {
36
+ width: 16px;
37
+ height: 16px;
38
+ transition: all .2s;
39
+ position: absolute;
40
+ top: 50%;
41
+ left: 50%;
42
+ transform: translate(-50%, -50%)scale(1);
43
+ }
44
+
45
+ .rp-llms-copy-button__icon-success {
46
+ width: 16px;
47
+ height: 16px;
48
+ color: var(--rp-c-green-1, #10b981);
49
+ visibility: hidden;
50
+ opacity: 0;
51
+ transition: all .2s cubic-bezier(.18, .89, .32, 1.28);
52
+ position: absolute;
53
+ top: 50%;
54
+ left: 50%;
55
+ transform: translate(-50%, -50%)scale(.5);
56
+ }
57
+
@@ -0,0 +1,20 @@
1
+ import './index.scss';
2
+ import './LlmsCopyButton.scss';
3
+ export interface LlmsCopyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
4
+ /**
5
+ * Text by language, used with `useLang`.
6
+ * @default en: 'Copy Markdown', zh: '\u590d\u5236 Markdown'
7
+ */
8
+ textByLang?: Record<string, string>;
9
+ /**
10
+ * Priority is higher than textByLang
11
+ * @default ''
12
+ */
13
+ text?: string;
14
+ /**
15
+ * Overrides the default click handler.
16
+ * If provided, the default copy to clipboard functionality will not be executed.
17
+ */
18
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
19
+ }
20
+ export declare function LlmsCopyButton(props: LlmsCopyButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,73 @@
1
+ /*! For license information please see LlmsCopyButton.js.LICENSE.txt */
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useI18n } from "@rspress/core/runtime";
4
+ import { IconCopy, IconSuccess } from "@theme";
5
+ import { useCallback, useRef, useState } from "react";
6
+ import "./index.css";
7
+ import "./LlmsCopyButton.css";
8
+ import { useMdUrl } from "./useMdUrl.js";
9
+ /**
10
+ * Inspired from fumadocs docsite
11
+ * @from https://github.com/fuma-nama/fumadocs/blob/5723bbe58ef805a5421a780abf235a10b251be2f/apps/docs/app/docs/%5B...slug%5D/page.client.tsx#L11
12
+ * @license MIT
13
+ */ const cache = new Map();
14
+ function LlmsCopyButton(props) {
15
+ const { onClick, ...otherProps } = props;
16
+ const t = useI18n();
17
+ const { pathname } = useMdUrl();
18
+ const [isLoading, setLoading] = useState(false);
19
+ const [isFinished, setFinished] = useState(false);
20
+ const timer = useRef(null);
21
+ const handleClick = useCallback(async ()=>{
22
+ setLoading(true);
23
+ const url = pathname;
24
+ try {
25
+ const content = cache.get(url) ?? await fetch(url).then((res)=>res.text());
26
+ cache.set(url, content);
27
+ await navigator.clipboard.writeText(content);
28
+ } finally{
29
+ setLoading(false);
30
+ setFinished(true);
31
+ if (timer.current) {
32
+ clearTimeout(timer.current);
33
+ timer.current = null;
34
+ }
35
+ timer.current = window.setTimeout(()=>{
36
+ setFinished(false);
37
+ timer.current = null;
38
+ }, 500);
39
+ }
40
+ }, [
41
+ pathname
42
+ ]);
43
+ if (!pathname) return /*#__PURE__*/ jsx(Fragment, {});
44
+ return /*#__PURE__*/ jsxs("button", {
45
+ ...otherProps,
46
+ disabled: isLoading,
47
+ className: [
48
+ 'rp-not-doc',
49
+ 'rp-llms-button',
50
+ 'rp-llms-copy-button',
51
+ isLoading ? 'rp-llms-copy-button--loading' : '',
52
+ isFinished ? 'rp-llms-copy-button--success' : ''
53
+ ].filter(Boolean).join(' '),
54
+ onClick: onClick ?? handleClick,
55
+ children: [
56
+ /*#__PURE__*/ jsxs("div", {
57
+ className: "rp-llms-copy-button__icon-wrapper",
58
+ children: [
59
+ /*#__PURE__*/ jsx(IconSuccess, {
60
+ className: "rp-llms-copy-button__icon-success"
61
+ }),
62
+ /*#__PURE__*/ jsx(IconCopy, {
63
+ className: "rp-llms-copy-button__icon-copy"
64
+ })
65
+ ]
66
+ }),
67
+ /*#__PURE__*/ jsx("span", {
68
+ children: t('copyMarkdownText')
69
+ })
70
+ ]
71
+ });
72
+ }
73
+ export { LlmsCopyButton };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Inspired from fumadocs docsite
3
+ * @from https://github.com/fuma-nama/fumadocs/blob/5723bbe58ef805a5421a780abf235a10b251be2f/apps/docs/app/docs/%5B...slug%5D/page.client.tsx#L11
4
+ * @license MIT
5
+ */
@@ -0,0 +1,93 @@
1
+ .rp-llms-view-options__trigger {
2
+ position: relative;
3
+ }
4
+
5
+ .rp-llms-view-options__trigger--active {
6
+ background: var(--rp-c-bg-mute);
7
+ color: var(--rp-c-text-1);
8
+ border-color: var(--rp-c-divider);
9
+ }
10
+
11
+ .rp-llms-view-options__arrow {
12
+ transition: transform .2s;
13
+ }
14
+
15
+ .rp-llms-view-options__arrow--rotated {
16
+ transform: rotate(180deg);
17
+ }
18
+
19
+ .rp-llms-view-options__menu {
20
+ z-index: 100;
21
+ border: 1px solid var(--rp-c-divider-light);
22
+ background: var(--rp-c-bg);
23
+ width: max-content;
24
+ min-width: 220px;
25
+ color: var(--rp-c-text-1);
26
+ transform-origin: 0 0;
27
+ border-radius: 10px;
28
+ flex-direction: column;
29
+ align-items: flex-start;
30
+ padding: 6px;
31
+ animation: .2s cubic-bezier(.16, 1, .3, 1) dropdownIn;
32
+ display: flex;
33
+ position: absolute;
34
+ top: calc(100% + 6px);
35
+ left: 0;
36
+ box-shadow: 0 4px 20px -4px #00000026, 0 0 2px #0000000d;
37
+ }
38
+
39
+ @keyframes dropdownIn {
40
+ from {
41
+ opacity: 0;
42
+ transform: translateY(-8px)scale(.96);
43
+ }
44
+
45
+ to {
46
+ opacity: 1;
47
+ transform: translateY(0)scale(1);
48
+ }
49
+ }
50
+
51
+ .rp-llms-view-options__menu-item {
52
+ text-align: left;
53
+ cursor: pointer;
54
+ width: 100%;
55
+ color: var(--rp-c-text-2);
56
+ background: none;
57
+ border: none;
58
+ border-radius: 6px;
59
+ align-items: center;
60
+ gap: 10px;
61
+ padding: 8px 10px;
62
+ font-size: 14px;
63
+ font-weight: 500;
64
+ transition: background .2s, color .2s;
65
+ display: flex;
66
+ }
67
+
68
+ .rp-llms-view-options__menu-item:hover {
69
+ background: var(--rp-c-bg-mute);
70
+ color: var(--rp-c-text-1);
71
+ text-decoration: none;
72
+ }
73
+
74
+ .rp-llms-view-options__menu-item:active {
75
+ background: var(--rp-c-bg-soft);
76
+ }
77
+
78
+ .rp-llms-view-options__item-icon {
79
+ justify-content: center;
80
+ align-items: center;
81
+ width: 16px;
82
+ height: 16px;
83
+ font-size: 16px;
84
+ display: inline-flex;
85
+ }
86
+
87
+ .rp-llms-view-options__external-icon {
88
+ width: 16px;
89
+ height: 16px;
90
+ margin-left: auto;
91
+ font-size: 16px;
92
+ }
93
+
@@ -0,0 +1,34 @@
1
+ import type React from 'react';
2
+ import './index.scss';
3
+ import './LlmsViewOptions.scss';
4
+ type Option = {
5
+ title: string;
6
+ icon?: React.ReactNode;
7
+ onClick?: () => void;
8
+ } | {
9
+ title: string;
10
+ href: string;
11
+ icon?: React.ReactNode;
12
+ } | 'markdownLink' | 'chatgpt' | 'claude';
13
+ export interface LlmsViewOptionsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
14
+ /**
15
+ * Default options for the dropdown.
16
+ * @default ['markdownLink', 'chatgpt', 'claude']
17
+ * - 'chatgpt': Open in ChatGPT
18
+ * - 'claude': Open in Claude
19
+ */
20
+ options?: Option[];
21
+ /**
22
+ * Button text by language, used with `useLang`.
23
+ * @default en: 'Open', zh: '\u6253\u5f00'
24
+ */
25
+ textByLang?: Record<string, string>;
26
+ /**
27
+ * Button text.
28
+ * Priority is higher than textByLang
29
+ * @default ''
30
+ */
31
+ text?: string;
32
+ }
33
+ export declare function LlmsViewOptions({ options: propsOptions, }: LlmsViewOptionsProps): import("react/jsx-runtime").JSX.Element;
34
+ export {};
@@ -0,0 +1,206 @@
1
+ /*! For license information please see LlmsViewOptions.js.LICENSE.txt */
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useI18n, useSite } from "@rspress/core/runtime";
4
+ import { IconDown } from "@theme";
5
+ import { useEffect, useMemo, useRef, useState } from "react";
6
+ import "./index.css";
7
+ import "./LlmsViewOptions.css";
8
+ import { useMdUrl } from "./useMdUrl.js";
9
+ /**
10
+ * Inspired from fumadocs docsite
11
+ * @from https://github.com/fuma-nama/fumadocs/blob/5723bbe58ef805a5421a780abf235a10b251be2f/apps/docs/app/docs/%5B...slug%5D/page.client.tsx#L11
12
+ * @license MIT
13
+ */ const IconExternalLink = ()=>/*#__PURE__*/ jsxs("svg", {
14
+ xmlns: "http://www.w3.org/2000/svg",
15
+ width: "16",
16
+ height: "16",
17
+ viewBox: "0 0 16 16",
18
+ fill: "none",
19
+ children: [
20
+ /*#__PURE__*/ jsx("path", {
21
+ d: "M9.33301 2H13.9997V6.66667",
22
+ stroke: "currentColor",
23
+ strokeWidth: "1.33333",
24
+ strokeLinecap: "round",
25
+ strokeLinejoin: "round"
26
+ }),
27
+ /*#__PURE__*/ jsx("path", {
28
+ d: "M14 9.82457V13C14 13.5523 13.5523 14 13 14H3C2.44772 14 2 13.5523 2 13V3C2 2.44772 2.44772 2 3 2H6",
29
+ stroke: "currentColor",
30
+ strokeWidth: "1.33333",
31
+ strokeLinecap: "round",
32
+ strokeLinejoin: "round"
33
+ }),
34
+ /*#__PURE__*/ jsx("path", {
35
+ d: "M8.59961 7.39996L13.6996 2.29996",
36
+ stroke: "currentColor",
37
+ strokeWidth: "1.33333",
38
+ strokeLinecap: "round",
39
+ strokeLinejoin: "round"
40
+ })
41
+ ]
42
+ });
43
+ const DEFAULT_OPTIONS = [
44
+ 'markdownLink',
45
+ 'chatgpt',
46
+ 'claude'
47
+ ];
48
+ function LlmsViewOptions({ options: propsOptions }) {
49
+ const { site } = useSite();
50
+ const llmsUI = site?.themeConfig?.llmsUI;
51
+ const options = ('object' == typeof llmsUI ? llmsUI?.viewOptions : propsOptions) ?? DEFAULT_OPTIONS;
52
+ const [isOpen, setIsOpen] = useState(false);
53
+ const dropdownRef = useRef(null);
54
+ useEffect(()=>{
55
+ const handleClickOutside = (event)=>{
56
+ if (dropdownRef.current && event.target && !dropdownRef.current.contains(event.target)) setIsOpen(false);
57
+ };
58
+ document.addEventListener('mousedown', handleClickOutside);
59
+ return ()=>{
60
+ document.removeEventListener('mousedown', handleClickOutside);
61
+ };
62
+ }, []);
63
+ const toggleDropdown = ()=>{
64
+ setIsOpen(!isOpen);
65
+ };
66
+ const { pathname } = useMdUrl();
67
+ const t = useI18n();
68
+ const items = useMemo(()=>{
69
+ const fullMarkdownUrl = "u" > typeof window ? new URL(pathname, window.location.origin).toString() : 'loading';
70
+ const q = `Read ${fullMarkdownUrl}, I want to ask questions about it.`;
71
+ return {
72
+ markdownLink: {
73
+ title: t('copyMarkdownLinkText'),
74
+ icon: /*#__PURE__*/ jsx("svg", {
75
+ xmlns: "http://www.w3.org/2000/svg",
76
+ viewBox: "0 0 24 24",
77
+ width: "24",
78
+ height: "24",
79
+ children: /*#__PURE__*/ jsxs("g", {
80
+ fill: "none",
81
+ stroke: "currentColor",
82
+ strokeLinecap: "round",
83
+ strokeLinejoin: "round",
84
+ strokeWidth: "2",
85
+ children: [
86
+ /*#__PURE__*/ jsx("path", {
87
+ d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"
88
+ }),
89
+ /*#__PURE__*/ jsx("path", {
90
+ d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
91
+ })
92
+ ]
93
+ })
94
+ }),
95
+ onClick: ()=>{
96
+ navigator.clipboard.writeText(fullMarkdownUrl);
97
+ }
98
+ },
99
+ chatgpt: {
100
+ title: t('openInText', {
101
+ name: 'ChatGPT'
102
+ }),
103
+ href: `https://chatgpt.com/?${new URLSearchParams({
104
+ hints: 'search',
105
+ q
106
+ })}`,
107
+ icon: /*#__PURE__*/ jsxs("svg", {
108
+ role: "img",
109
+ viewBox: "0 0 24 24",
110
+ fill: "currentColor",
111
+ xmlns: "http://www.w3.org/2000/svg",
112
+ children: [
113
+ /*#__PURE__*/ jsx("title", {
114
+ children: "OpenAI"
115
+ }),
116
+ /*#__PURE__*/ jsx("path", {
117
+ d: "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"
118
+ }),
119
+ /*#__PURE__*/ jsx("path", {
120
+ d: "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"
121
+ })
122
+ ]
123
+ })
124
+ },
125
+ claude: {
126
+ title: t('openInText', {
127
+ name: 'Claude'
128
+ }),
129
+ href: `https://claude.ai/new?${new URLSearchParams({
130
+ q
131
+ })}`,
132
+ icon: /*#__PURE__*/ jsxs("svg", {
133
+ fill: "currentColor",
134
+ role: "img",
135
+ viewBox: "0 0 24 24",
136
+ xmlns: "http://www.w3.org/2000/svg",
137
+ children: [
138
+ /*#__PURE__*/ jsx("title", {
139
+ children: "Anthropic"
140
+ }),
141
+ /*#__PURE__*/ jsx("path", {
142
+ d: "M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"
143
+ })
144
+ ]
145
+ })
146
+ }
147
+ };
148
+ }, [
149
+ pathname,
150
+ t
151
+ ]);
152
+ return /*#__PURE__*/ jsx(Fragment, {
153
+ children: /*#__PURE__*/ jsxs("button", {
154
+ ref: dropdownRef,
155
+ onClick: toggleDropdown,
156
+ className: `rp-llms-button rp-llms-view-options__trigger ${isOpen ? 'rp-llms-view-options__trigger--active' : ''}`,
157
+ children: [
158
+ /*#__PURE__*/ jsx(IconDown, {
159
+ className: `rp-llms-view-options__arrow ${isOpen ? 'rp-llms-view-options__arrow--rotated' : ''}`
160
+ }),
161
+ isOpen && /*#__PURE__*/ jsx("div", {
162
+ className: "rp-llms-view-options__menu",
163
+ children: options.map((item)=>{
164
+ let displayItem = item;
165
+ if ('markdownLink' === item) displayItem = items.markdownLink;
166
+ else if ('chatgpt' === item) displayItem = items.chatgpt;
167
+ else if ('claude' === item) displayItem = items.claude;
168
+ if (displayItem.href) return /*#__PURE__*/ jsxs("a", {
169
+ className: "rp-llms-view-options__menu-item",
170
+ href: displayItem.href,
171
+ target: "_blank",
172
+ rel: "noopener noreferrer",
173
+ children: [
174
+ /*#__PURE__*/ jsx("span", {
175
+ className: "rp-llms-view-options__item-icon",
176
+ children: displayItem.icon
177
+ }),
178
+ /*#__PURE__*/ jsx("span", {
179
+ children: displayItem.title
180
+ }),
181
+ /*#__PURE__*/ jsx("span", {
182
+ className: "rp-llms-view-options__external-icon",
183
+ children: /*#__PURE__*/ jsx(IconExternalLink, {})
184
+ })
185
+ ]
186
+ }, displayItem.title);
187
+ return /*#__PURE__*/ jsxs("div", {
188
+ className: "rp-llms-view-options__menu-item",
189
+ onClick: displayItem.onClick,
190
+ children: [
191
+ /*#__PURE__*/ jsx("span", {
192
+ className: "rp-llms-view-options__item-icon",
193
+ children: displayItem.icon
194
+ }),
195
+ /*#__PURE__*/ jsx("span", {
196
+ children: displayItem.title
197
+ })
198
+ ]
199
+ }, displayItem.title);
200
+ })
201
+ })
202
+ ]
203
+ })
204
+ });
205
+ }
206
+ export { LlmsViewOptions };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Inspired from fumadocs docsite
3
+ * @from https://github.com/fuma-nama/fumadocs/blob/5723bbe58ef805a5421a780abf235a10b251be2f/apps/docs/app/docs/%5B...slug%5D/page.client.tsx#L11
4
+ * @license MIT
5
+ */
@@ -0,0 +1,32 @@
1
+ .rp-llms-button {
2
+ border: 1px solid var(--rp-c-divider-light);
3
+ background: var(--rp-c-bg);
4
+ height: 36px;
5
+ color: var(--rp-c-text-2);
6
+ user-select: none;
7
+ white-space: nowrap;
8
+ cursor: pointer;
9
+ border-radius: 8px;
10
+ justify-content: center;
11
+ align-items: center;
12
+ gap: 6px;
13
+ padding: 0 12px;
14
+ font-size: 14px;
15
+ font-weight: 500;
16
+ line-height: normal;
17
+ transition: background .2s, border-color .2s, color .2s, box-shadow .2s, transform .1s, opacity .2s;
18
+ display: inline-flex;
19
+ }
20
+
21
+ .rp-llms-button:hover {
22
+ background: var(--rp-c-bg-soft);
23
+ border-color: var(--rp-c-divider);
24
+ color: var(--rp-c-text-1);
25
+ box-shadow: 0 2px 6px #0000000a;
26
+ }
27
+
28
+ .rp-llms-button:active {
29
+ background: var(--rp-c-bg-soft);
30
+ box-shadow: none;
31
+ }
32
+
@@ -0,0 +1,4 @@
1
+ export { LlmsContainer, type LlmsContainerProps } from './LlmsContainer.js';
2
+ export { LlmsCopyButton, type LlmsCopyButtonProps } from './LlmsCopyButton.js';
3
+ export { LlmsViewOptions, type LlmsViewOptionsProps } from './LlmsViewOptions.js';
4
+ export { useMdUrl } from './useMdUrl.js';
@@ -0,0 +1,5 @@
1
+ import { LlmsContainer } from "./LlmsContainer.js";
2
+ import { LlmsCopyButton } from "./LlmsCopyButton.js";
3
+ import { LlmsViewOptions } from "./LlmsViewOptions.js";
4
+ import { useMdUrl } from "./useMdUrl.js";
5
+ export { LlmsContainer, LlmsCopyButton, LlmsViewOptions, useMdUrl };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @private
3
+ */
4
+ export declare function useMdUrl(): {
5
+ pathname: string;
6
+ };
@@ -0,0 +1,15 @@
1
+ import { routePathToMdPath, usePageData } from "@rspress/core/runtime";
2
+ import { useMemo } from "react";
3
+ function useMdUrl() {
4
+ const { page } = usePageData();
5
+ const mdPath = useMemo(()=>{
6
+ const pathname = routePathToMdPath(page.routePath);
7
+ return {
8
+ pathname
9
+ };
10
+ }, [
11
+ page.routePath
12
+ ]);
13
+ return mdPath;
14
+ }
15
+ export { useMdUrl };
@@ -11,6 +11,7 @@
11
11
  justify-content: space-between;
12
12
  align-items: center;
13
13
  width: 100%;
14
+ transition: background-color .2s ease-in-out, border-bottom .2s ease-in-out;
14
15
  display: flex;
15
16
  position: sticky;
16
17
  left: 0;
@@ -1,9 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useNav } from "@rspress/core/runtime";
3
- import { NavHamburger, Search, SocialLinks, SwitchAppearance } from "@theme";
3
+ import { NavHamburger, NavTitle, Search, SocialLinks, SwitchAppearance } from "@theme";
4
4
  import "./index.css";
5
5
  import { NavLangs, NavMenu, NavMenuDivider, NavVersions } from "./NavMenu.js";
6
- import { NavTitle } from "./NavTitle.js";
7
6
  function Nav(props) {
8
7
  const { beforeNavTitle, afterNavTitle, beforeNavMenu, afterNavMenu, navTitle } = props;
9
8
  const navList = useNav();
@@ -1,2 +1,2 @@
1
- import './NavTitle.scss';
1
+ import './index.scss';
2
2
  export declare const NavTitle: () => import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,18 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { addLeadingSlash, normalizeImagePath, useLocaleSiteData, useSite } from "@rspress/core/runtime";
2
+ import { addLeadingSlash, addTrailingSlash, normalizeImagePath, useLang, useSite } from "@rspress/core/runtime";
3
3
  import { Link } from "@theme";
4
4
  import { useMemo } from "react";
5
- import "./NavTitle.css";
5
+ import "./index.css";
6
6
  const NavTitle = ()=>{
7
7
  const { site } = useSite();
8
- const localeData = useLocaleSiteData();
9
- const { logo: rawLogo, logoText } = site;
10
- const title = (localeData.title ?? site.title) || 'Home';
8
+ const lang = useLang();
9
+ const themeConfig = site?.themeConfig ?? {};
10
+ const defaultLang = site.lang ?? '';
11
+ const locales = themeConfig?.locales;
12
+ const localeInfo = locales?.find((locale)=>locale.lang === lang);
13
+ const title = (localeInfo?.title ?? site.title) || 'Home';
14
+ const langRoutePrefix = lang === defaultLang ? '/' : addTrailingSlash(lang);
15
+ const { logo: rawLogo, logoText, logoHref } = site;
11
16
  const logo = useMemo(()=>{
12
17
  if (!rawLogo) return null;
13
18
  if ('string' == typeof rawLogo) return /*#__PURE__*/ jsx("img", {
@@ -38,7 +43,7 @@ const NavTitle = ()=>{
38
43
  return /*#__PURE__*/ jsx("div", {
39
44
  className: "rp-nav__title",
40
45
  children: /*#__PURE__*/ jsxs(Link, {
41
- href: addLeadingSlash(localeData.langRoutePrefix ?? '/'),
46
+ href: logoHref || addLeadingSlash(langRoutePrefix),
42
47
  className: "rp-nav__title__link",
43
48
  children: [
44
49
  logo && /*#__PURE__*/ jsx("div", {