@rspress/core 2.0.0-rc.5 → 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 (116) hide show
  1. package/dist/{0~7675.4468968d.js → 0~7675.d236b058.js} +3 -3
  2. package/dist/{5485.b9ce9bdf.js → 5485.7586c86a.js} +1 -1
  3. package/dist/{5341.9eb6b114.js → 7786.421b464f.js} +2 -2
  4. package/dist/{1820.985588a0.js → 9348.1beb3e25.js} +6 -0
  5. package/dist/cli/index.js +2 -2
  6. package/dist/config/defineConfig.d.ts +40 -0
  7. package/dist/{cli/config → config}/loadConfigFile.js +2 -2
  8. package/dist/eject-theme/components/Callout/index.scss +6 -6
  9. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +21 -2
  10. package/dist/eject-theme/components/Llms/LlmsContainer.scss +6 -0
  11. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +9 -0
  12. package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +57 -0
  13. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +94 -0
  14. package/dist/eject-theme/components/Llms/LlmsViewOptions.scss +98 -0
  15. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +259 -0
  16. package/dist/eject-theme/components/Llms/index.scss +42 -0
  17. package/dist/eject-theme/components/Llms/index.tsx +4 -0
  18. package/dist/eject-theme/components/Llms/useMdUrl.ts +14 -0
  19. package/dist/eject-theme/components/Nav/index.scss +3 -0
  20. package/dist/eject-theme/components/Nav/index.tsx +7 -2
  21. package/dist/eject-theme/components/{Nav/NavTitle.tsx → NavTitle/index.tsx} +15 -6
  22. package/dist/index.d.ts +2 -1
  23. package/dist/index.js +3 -3
  24. package/dist/node/PluginDriver.js +1 -1
  25. package/dist/node/auto-nav-sidebar/index.js +1 -1
  26. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  27. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  28. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  29. package/dist/node/constants.js +1 -1
  30. package/dist/node/eject.js +1 -0
  31. package/dist/node/initRsbuild.js +5 -4
  32. package/dist/node/last-updated/index.js +1 -1
  33. package/dist/node/mdx/{loader.7c249a26.js → loader.15e0b2d2.js} +0 -5
  34. package/dist/node/mdx/options.js +2 -2
  35. package/dist/node/mdx/processor.js +1 -1
  36. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  37. package/dist/node/mdx/rehypePlugins/headerAnchor.js +2 -3
  38. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  39. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -2
  40. package/dist/node/mdx/remarkPlugins/image.js +1 -2
  41. package/dist/node/mdx/remarkPlugins/link.js +1 -2
  42. package/dist/node/mdx/remarkPlugins/toc.d.ts +4 -3
  43. package/dist/node/mdx/remarkPlugins/toc.js +14 -11
  44. package/dist/node/route/RoutePage.d.ts +3 -1
  45. package/dist/node/route/RoutePage.js +4 -0
  46. package/dist/node/route/RouteService.js +2 -2
  47. package/dist/node/route/extractPageData.d.ts +5 -0
  48. package/dist/node/route/extractPageData.js +88 -57
  49. package/dist/node/route/normalizeRoutePath.js +2 -2
  50. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  51. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +21 -0
  52. package/dist/node/runtimeModule/i18n.js +4 -3
  53. package/dist/node/runtimeModule/pageData/createPageData.js +9 -6
  54. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +20 -14
  55. package/dist/node/runtimeModule/siteData/createSiteData.js +2 -1
  56. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  57. package/dist/node/serve.js +1 -1
  58. package/dist/node/ssg/renderPage.js +1 -1
  59. package/dist/node/ssg/renderPageWorker.js +1 -1
  60. package/dist/node/ssg/renderPages.js +7 -3
  61. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  62. package/dist/node/ssg/ssgEnv.js +1 -1
  63. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  64. package/dist/node/ssg-md/llms/llmsTxt.js +12 -2
  65. package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
  66. package/dist/node/ssg-md/renderPage.js +1 -1
  67. package/dist/node/ssg-md/renderPages.js +1 -1
  68. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  69. package/dist/node/utils/createHash.js +1 -1
  70. package/dist/node/utils/flattenMdxContent.js +2 -2
  71. package/dist/node/utils/getPageKey.js +1 -1
  72. package/dist/node/utils/normalizePath.js +1 -1
  73. package/dist/node/utils/reactAlias.js +1 -1
  74. package/dist/runtime/hooks/useI18n.d.ts +1 -1
  75. package/dist/runtime/hooks/useI18n.js +2 -2
  76. package/dist/runtime/index.d.ts +1 -1
  77. package/dist/runtime/index.js +2 -2
  78. package/dist/runtime/utils.d.ts +2 -2
  79. package/dist/runtime/utils.js +2 -2
  80. package/dist/theme/components/Callout/index.css +6 -6
  81. package/dist/theme/components/DocContent/docComponents/title.js +25 -5
  82. package/dist/theme/components/HomeHero/index.css +10 -10
  83. package/dist/theme/components/Llms/LlmsContainer.css +7 -0
  84. package/dist/theme/components/Llms/LlmsContainer.d.ts +5 -0
  85. package/dist/theme/components/Llms/LlmsContainer.js +9 -0
  86. package/dist/theme/components/Llms/LlmsCopyButton.css +57 -0
  87. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +20 -0
  88. package/dist/theme/components/Llms/LlmsCopyButton.js +73 -0
  89. package/dist/theme/components/Llms/LlmsCopyButton.js.LICENSE.txt +5 -0
  90. package/dist/theme/components/Llms/LlmsViewOptions.css +93 -0
  91. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +34 -0
  92. package/dist/theme/components/Llms/LlmsViewOptions.js +206 -0
  93. package/dist/theme/components/Llms/LlmsViewOptions.js.LICENSE.txt +5 -0
  94. package/dist/theme/components/Llms/index.css +32 -0
  95. package/dist/theme/components/Llms/index.d.ts +4 -0
  96. package/dist/theme/components/Llms/index.js +5 -0
  97. package/dist/theme/components/Llms/useMdUrl.d.ts +6 -0
  98. package/dist/theme/components/Llms/useMdUrl.js +15 -0
  99. package/dist/theme/components/Nav/index.css +1 -0
  100. package/dist/theme/components/Nav/index.js +1 -2
  101. package/dist/theme/components/{Nav/NavTitle.d.ts → NavTitle/index.d.ts} +1 -1
  102. package/dist/theme/components/{Nav/NavTitle.js → NavTitle/index.js} +11 -6
  103. package/dist/theme/components/PageTabs/index.css +1 -1
  104. package/dist/theme/components/Tabs/index.css +4 -4
  105. package/dist/theme/hooks/useDynamicToc.d.ts +2 -0
  106. package/dist/theme/hooks/useDynamicToc.js +3 -1
  107. package/dist/theme/index.d.ts +2 -0
  108. package/dist/theme/index.js +3 -1
  109. package/dist/theme/layout/Layout/index.js +1 -1
  110. package/package.json +15 -16
  111. package/dist/8813.4b28f4bb.js +0 -1
  112. package/dist/cli/config/index.d.ts +0 -2
  113. /package/dist/{cli/config/index.js → config/defineConfig.js} +0 -0
  114. /package/dist/{cli/config → config}/loadConfigFile.d.ts +0 -0
  115. /package/dist/eject-theme/components/{Nav/NavTitle.scss → NavTitle/index.scss} +0 -0
  116. /package/dist/theme/components/{Nav/NavTitle.css → NavTitle/index.css} +0 -0
@@ -1,6 +1,6 @@
1
- import { node_fs, core_rspack } from "../../5341.9eb6b114.js";
1
+ import { node_fs, core_rspack } from "../../7786.421b464f.js";
2
2
  import { node_path, logger } from "../../6289.29817fb4.js";
3
- import { createProcessor, MDX_OR_MD_REGEXP } from "../../1820.985588a0.js";
3
+ import { createProcessor, MDX_OR_MD_REGEXP } from "../../9348.1beb3e25.js";
4
4
  import { createError } from "./error.js";
5
5
  import { importStatementRegex } from "../constants.js";
6
6
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../1820.985588a0.js";
1
+ import { removeLeadingSlash } from "../../9348.1beb3e25.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,4 +1,4 @@
1
- import { node_os } from "../../1820.985588a0.js";
1
+ import { node_os } from "../../9348.1beb3e25.js";
2
2
  import { node_path } from "../../6289.29817fb4.js";
3
3
  const isWindows = 'win32' === node_os.platform();
4
4
  function slash(p) {
@@ -1,5 +1,5 @@
1
1
  import { node_path, logger, picocolors } from "../../6289.29817fb4.js";
2
- import { core_rspack } from "../../5341.9eb6b114.js";
2
+ import { core_rspack } from "../../7786.421b464f.js";
3
3
  import { pathExists, readJson } from "./fs.js";
4
4
  import { PACKAGE_ROOT } from "../constants.js";
5
5
  import { hintReactVersion } from "../logger/hint.js";
@@ -1,2 +1,2 @@
1
1
  import type { I18nText } from '@rspress/shared';
2
- export declare function useI18n<T>(): (key: keyof (T & I18nText)) => string;
2
+ export declare function useI18n<T>(): (key: keyof (T & I18nText), params?: Record<string, string>) => string;
@@ -3,10 +3,10 @@ import virtual_i18n_text from "virtual-i18n-text";
3
3
  import { useLang } from "./useLang.js";
4
4
  function useI18n() {
5
5
  const lang = useLang();
6
- return useCallback((key)=>{
6
+ return useCallback((key, params)=>{
7
7
  const text = virtual_i18n_text[key]?.[lang];
8
8
  if ('string' != typeof text) throw new Error(`i18n key "${key}" not found for language "${lang}"`);
9
- return text;
9
+ return text.replace(/\{\{(\w+)\}\}/g, (_, p1)=>params?.[p1] ?? `${p1}`);
10
10
  }, [
11
11
  lang
12
12
  ]);
@@ -18,4 +18,4 @@ export { useVersion } from './hooks/useVersion.js';
18
18
  export { useWindowSize } from './hooks/useWindowSize.js';
19
19
  export { NoSSR } from './NoSSR.js';
20
20
  export { isActive, pathnameToRouteService, preloadLink } from './route.js';
21
- export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, } from './utils.js';
21
+ export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, } from './utils.js';
@@ -17,6 +17,6 @@ import { useVersion } from "./hooks/useVersion.js";
17
17
  import { useWindowSize } from "./hooks/useWindowSize.js";
18
18
  import { NoSSR } from "./NoSSR.js";
19
19
  import { isActive, pathnameToRouteService, preloadLink } from "./route.js";
20
- import { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase } from "./utils.js";
20
+ import { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase } from "./utils.js";
21
21
  export * from "react-router-dom";
22
- export { Content, Head, NoSSR, PageContext, ThemeContext, addLeadingSlash, cleanUrlByConfig, getSidebarDataGroup, isActive, isDataUrl, isEqualPath, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeHref, normalizeHrefInRuntime, normalizeImagePath, pathnameToRouteService, preloadLink, removeBase, removeTrailingSlash, routePathToMdPath, useActiveMatcher, useDark, useFrontmatter, useI18n, useLang, useLocaleSiteData, useNav, usePage, usePageData, usePages, useSidebar, useSidebarDynamic, useSite, useVersion, useWindowSize, withBase };
22
+ export { Content, Head, NoSSR, PageContext, ThemeContext, addLeadingSlash, addTrailingSlash, cleanUrlByConfig, getSidebarDataGroup, isActive, isDataUrl, isEqualPath, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeHref, normalizeHrefInRuntime, normalizeImagePath, pathnameToRouteService, preloadLink, removeBase, removeTrailingSlash, routePathToMdPath, useActiveMatcher, useDark, useFrontmatter, useI18n, useLang, useLocaleSiteData, useNav, usePage, usePageData, usePages, useSidebar, useSidebarDynamic, useSite, useVersion, useWindowSize, withBase };
@@ -1,4 +1,4 @@
1
- import { addLeadingSlash, isProduction, removeTrailingSlash } from '@rspress/shared';
1
+ import { addLeadingSlash, addTrailingSlash, isProduction, removeTrailingSlash } from '@rspress/shared';
2
2
  declare function withBase(url?: string): string;
3
3
  declare function removeBase(url: string): string;
4
4
  declare function isEqualPath(a: string, b: string): boolean;
@@ -9,4 +9,4 @@ declare function normalizeHrefInRuntime(link: string): string;
9
9
  declare function cleanUrlByConfig(link: string): string;
10
10
  declare function normalizeImagePath(imagePath: string): string;
11
11
  declare function routePathToMdPath(routePath: string): string;
12
- export { addLeadingSlash, removeTrailingSlash, isProduction, normalizeImagePath, cleanUrlByConfig, removeBase, withBase, isEqualPath, normalizeHrefInRuntime, routePathToMdPath, };
12
+ export { addLeadingSlash, addTrailingSlash, removeTrailingSlash, isProduction, normalizeImagePath, cleanUrlByConfig, removeBase, withBase, isEqualPath, normalizeHrefInRuntime, routePathToMdPath, };
@@ -1,4 +1,4 @@
1
- import { addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
1
+ import { addLeadingSlash, addTrailingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
2
2
  import virtual_site_data from "virtual-site-data";
3
3
  function utils_withBase(url = '/') {
4
4
  return withBase(url, virtual_site_data.base);
@@ -31,4 +31,4 @@ function routePathToMdPath(routePath) {
31
31
  function isAbsoluteUrl(path) {
32
32
  return isExternalUrl(path) || isDataUrl(path) || path.startsWith('//');
33
33
  }
34
- export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, utils_removeBase as removeBase, removeTrailingSlash, routePathToMdPath, utils_withBase as withBase };
34
+ export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, utils_removeBase as removeBase, removeTrailingSlash, routePathToMdPath, utils_withBase as withBase };
@@ -99,7 +99,7 @@
99
99
  background-color: var(--rp-container-note-text);
100
100
  }
101
101
 
102
- .rp-callout--note :not(pre, div) > code {
102
+ .rp-callout--note :not(pre) > code {
103
103
  color: var(--rp-container-note-text);
104
104
  background-color: var(--rp-container-note-code-bg);
105
105
  }
@@ -121,7 +121,7 @@
121
121
  background-color: var(--rp-container-tip-text);
122
122
  }
123
123
 
124
- .rp-callout--tip :not(pre, div) > code {
124
+ .rp-callout--tip :not(pre) > code {
125
125
  color: var(--rp-container-tip-text);
126
126
  background-color: var(--rp-container-tip-code-bg);
127
127
  }
@@ -143,7 +143,7 @@
143
143
  background-color: var(--rp-container-info-text);
144
144
  }
145
145
 
146
- .rp-callout--info :not(pre, div) > code {
146
+ .rp-callout--info :not(pre) > code {
147
147
  color: var(--rp-container-info-text);
148
148
  background-color: var(--rp-container-info-code-bg);
149
149
  }
@@ -165,7 +165,7 @@
165
165
  background-color: var(--rp-container-warning-text);
166
166
  }
167
167
 
168
- .rp-callout--warning :not(pre, div) > code {
168
+ .rp-callout--warning :not(pre) > code {
169
169
  color: var(--rp-container-warning-text);
170
170
  background-color: var(--rp-container-warning-code-bg);
171
171
  }
@@ -187,7 +187,7 @@
187
187
  background-color: var(--rp-container-danger-text);
188
188
  }
189
189
 
190
- .rp-callout--caution :not(pre, div) > code, .rp-callout--danger :not(pre, div) > code {
190
+ .rp-callout--caution :not(pre) > code, .rp-callout--danger :not(pre) > code {
191
191
  color: var(--rp-container-danger-text);
192
192
  background-color: var(--rp-container-danger-code-bg);
193
193
  }
@@ -209,7 +209,7 @@
209
209
  background-color: var(--rp-container-details-text);
210
210
  }
211
211
 
212
- .rp-callout--details :not(pre, div) > code {
212
+ .rp-callout--details :not(pre) > code {
213
213
  color: var(--rp-container-details-text);
214
214
  background-color: var(--rp-container-details-code-bg);
215
215
  }
@@ -1,10 +1,30 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useFrontmatter } from "@rspress/core/runtime";
3
+ import { LlmsContainer, LlmsCopyButton, LlmsViewOptions, Tag } from "@theme";
2
4
  import clsx from "clsx";
3
5
  const H1 = (props)=>{
4
- const { className, ...rest } = props;
5
- return /*#__PURE__*/ jsx("h1", {
6
- className: clsx('rp-toc-include', className),
7
- ...rest
6
+ const { className, children, ...rest } = props;
7
+ const { frontmatter: { tag } } = useFrontmatter();
8
+ return /*#__PURE__*/ jsxs(Fragment, {
9
+ children: [
10
+ /*#__PURE__*/ jsxs("h1", {
11
+ className: clsx('rp-toc-include', className),
12
+ ...rest,
13
+ children: [
14
+ children,
15
+ " ",
16
+ /*#__PURE__*/ jsx(Tag, {
17
+ tag: tag
18
+ })
19
+ ]
20
+ }),
21
+ process.env.ENABLE_LLMS_UI && /*#__PURE__*/ jsxs(LlmsContainer, {
22
+ children: [
23
+ /*#__PURE__*/ jsx(LlmsCopyButton, {}),
24
+ /*#__PURE__*/ jsx(LlmsViewOptions, {})
25
+ ]
26
+ })
27
+ ]
8
28
  });
9
29
  };
10
30
  const H2 = (props)=>{
@@ -65,6 +65,16 @@
65
65
  display: flex;
66
66
  }
67
67
 
68
+ .rp-home-hero__badge:before {
69
+ content: "";
70
+ background: var(--rp-home-hero-title-bg);
71
+ border-radius: 50%;
72
+ width: 8px;
73
+ height: 8px;
74
+ margin-right: 8px;
75
+ display: inline-block;
76
+ }
77
+
68
78
  .rp-home-hero__badge {
69
79
  background: var(--rp-c-bg-soft);
70
80
  border: 1px solid var(--rp-c-divider-light);
@@ -79,16 +89,6 @@
79
89
  display: inline-flex;
80
90
  }
81
91
 
82
- .rp-home-hero__badge:before {
83
- content: "";
84
- background: var(--rp-home-hero-title-bg);
85
- border-radius: 50%;
86
- width: 8px;
87
- height: 8px;
88
- margin-right: 8px;
89
- display: inline-block;
90
- }
91
-
92
92
  .rp-home-hero__badge:hover {
93
93
  background: var(--rp-c-bg-mute);
94
94
  cursor: pointer;
@@ -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 {};