@rspress/core 2.0.19 → 2.0.21
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.
- package/dist/{6305~0.js → 2711~0.js} +1 -1
- package/dist/5357~0.js +1 -1
- package/dist/8472~0.js +2 -2
- package/dist/864~0.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/config/loadConfigFile.js +2 -3
- package/dist/eject-theme/components/Banner/index.tsx +50 -9
- package/dist/eject-theme/components/Callout/index.scss +6 -1
- package/dist/eject-theme/components/CodeBlock/index.scss +2 -0
- package/dist/eject-theme/components/DocContent/doc.scss +2 -2
- package/dist/eject-theme/components/Link/getHref.test.ts +33 -0
- package/dist/eject-theme/components/Link/getHref.ts +60 -0
- package/dist/eject-theme/components/Link/index.tsx +7 -6
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +6 -51
- package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +1 -1
- package/dist/eject-theme/components/Llms/LlmsHint.tsx +10 -6
- package/dist/eject-theme/components/Nav/NavMenu.scss +16 -4
- package/dist/eject-theme/components/Nav/hooks.tsx +1 -2
- package/dist/eject-theme/components/Nav/index.scss +3 -1
- package/dist/eject-theme/components/Prompt/index.scss +2 -1
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +1 -1
- package/dist/eject-theme/components/SwitchAppearance/global.scss +18 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +4 -9
- package/dist/node/PluginDriver.js +1 -1
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +2 -3
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/constants.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +3 -3
- package/dist/node/last-updated/index.js +2 -2
- package/dist/node/mdx/options.js +2 -1
- package/dist/node/mdx/remarkPlugins/link.d.ts +2 -1
- package/dist/node/mdx/remarkPlugins/link.js +6 -5
- package/dist/node/route/RoutePage.d.ts +0 -1
- package/dist/node/route/RoutePage.js +4 -6
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +2 -3
- package/dist/node/runtimeModule/i18n.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/renderPages.js +2 -2
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +1 -1
- package/dist/node/ssg-md/renderPages.js +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +2 -2
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +1 -1
- package/dist/runtime/csrClientEntry.js +7 -2
- package/dist/runtime/route.d.ts +10 -0
- package/dist/runtime/route.js +13 -2
- package/dist/runtime/ssrClientEntry.js +2 -0
- package/dist/theme/components/Banner/index.js +53 -9
- package/dist/theme/components/Callout/index.css +6 -1
- package/dist/theme/components/CodeBlock/index.css +2 -0
- package/dist/theme/components/DocContent/doc.css +2 -2
- package/dist/theme/components/Link/getHref.d.ts +8 -0
- package/dist/theme/components/Link/getHref.js +33 -0
- package/dist/theme/components/Link/index.js +7 -6
- package/dist/theme/components/Link/useLinkNavigate.d.ts +0 -7
- package/dist/theme/components/Link/useLinkNavigate.js +7 -31
- package/dist/theme/components/Llms/LlmsHint.js +6 -2
- package/dist/theme/components/Nav/NavMenu.css +15 -7
- package/dist/theme/components/Nav/hooks.js +1 -2
- package/dist/theme/components/Nav/index.css +3 -1
- package/dist/theme/components/Prompt/index.css +2 -1
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +1 -1
- package/dist/theme/components/SwitchAppearance/global.css +10 -11
- package/dist/theme/components/SwitchAppearance/index.js +2 -8
- package/dist/theme/logic/applyThemeToDOM.d.ts +2 -0
- package/dist/theme/logic/applyThemeToDOM.js +17 -0
- package/dist/theme/logic/useThemeState.d.ts +1 -2
- package/dist/theme/logic/useThemeState.js +1 -7
- package/dist/theme/logic/utils.d.ts +4 -0
- package/dist/theme/logic/utils.js +23 -2
- package/dist/theme/styles/preflight.css +0 -2
- package/package.json +13 -13
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
.rp-doc :not(:where(.rp-not-doc, .rp-not-doc *)):where(a.rp-link):not(:where(.rp-header-anchor)):hover {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
text-underline-offset: 4px;
|
|
29
|
+
text-decoration: underline;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
.rp-doc :not(:where(.rp-not-doc, .rp-not-doc *)):where(a.rp-link):not(:where(.rp-header-anchor))[target="_blank"]:after {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cleanUrl, isExternalUrl } from "@rspress/shared";
|
|
2
|
+
import { cleanUrlByConfig, removeBase, withBase } from "../../../runtime/utils";
|
|
3
|
+
function isAbsoluteUrl(url) {
|
|
4
|
+
return url.startsWith('/');
|
|
5
|
+
}
|
|
6
|
+
function getLinkType(href) {
|
|
7
|
+
if (isExternalUrl(href)) return 'external';
|
|
8
|
+
if (href.startsWith('#')) return 'hashOnly';
|
|
9
|
+
if (!isAbsoluteUrl(href)) return 'relative';
|
|
10
|
+
return 'internal';
|
|
11
|
+
}
|
|
12
|
+
function getHref(href, currentUrl = "u" < typeof window ? void 0 : window.location.href) {
|
|
13
|
+
let withBaseHref;
|
|
14
|
+
const linkType = getLinkType(href);
|
|
15
|
+
if ('external' === linkType || 'hashOnly' === linkType) return {
|
|
16
|
+
linkType,
|
|
17
|
+
withBaseHref: href,
|
|
18
|
+
removeBaseHref: href,
|
|
19
|
+
routePath: cleanUrl(href)
|
|
20
|
+
};
|
|
21
|
+
if ('relative' === linkType && currentUrl) {
|
|
22
|
+
const url = new URL(href, currentUrl);
|
|
23
|
+
withBaseHref = `${url.pathname}${url.search}${url.hash}`;
|
|
24
|
+
} else withBaseHref = withBase(cleanUrlByConfig(href));
|
|
25
|
+
const removeBaseHref = removeBase(withBaseHref);
|
|
26
|
+
return {
|
|
27
|
+
withBaseHref,
|
|
28
|
+
removeBaseHref,
|
|
29
|
+
routePath: cleanUrl(removeBaseHref),
|
|
30
|
+
linkType
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { getHref };
|
|
@@ -4,13 +4,14 @@ import clsx from "clsx";
|
|
|
4
4
|
import nprogress from "nprogress";
|
|
5
5
|
import { forwardRef } from "react";
|
|
6
6
|
import "./index.css";
|
|
7
|
-
import { getHref
|
|
7
|
+
import { getHref } from "./getHref.js";
|
|
8
|
+
import { useLinkNavigate } from "./useLinkNavigate.js";
|
|
8
9
|
nprogress.configure({
|
|
9
10
|
showSpinner: false
|
|
10
11
|
});
|
|
11
12
|
const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
12
13
|
const { href = '/', children, className = '', onClick, onMouseEnter, startTransition, ...otherProps } = props;
|
|
13
|
-
const { linkType, removeBaseHref, withBaseHref } = getHref(href);
|
|
14
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
14
15
|
const navigate = useLinkNavigate({
|
|
15
16
|
startTransition
|
|
16
17
|
});
|
|
@@ -40,10 +41,10 @@ const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
40
41
|
className: clsx(className, 'rp-link'),
|
|
41
42
|
onMouseEnter: (event)=>{
|
|
42
43
|
onMouseEnter?.(event);
|
|
43
|
-
preloadLink(
|
|
44
|
+
preloadLink(routePath);
|
|
44
45
|
},
|
|
45
46
|
onTouchStart: ()=>{
|
|
46
|
-
preloadLink(
|
|
47
|
+
preloadLink(routePath);
|
|
47
48
|
},
|
|
48
49
|
onClick: (e)=>{
|
|
49
50
|
onClick?.(e);
|
|
@@ -60,10 +61,10 @@ const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
60
61
|
className: clsx(className, 'rp-link'),
|
|
61
62
|
onMouseEnter: (event)=>{
|
|
62
63
|
onMouseEnter?.(event);
|
|
63
|
-
preloadLink(
|
|
64
|
+
preloadLink(routePath);
|
|
64
65
|
},
|
|
65
66
|
onTouchStart: ()=>{
|
|
66
|
-
preloadLink(
|
|
67
|
+
preloadLink(routePath);
|
|
67
68
|
},
|
|
68
69
|
onClick: (e)=>{
|
|
69
70
|
onClick?.(e);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { type TransitionStartFunction } from 'react';
|
|
2
|
-
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
3
|
-
export declare function getHref(href: string): {
|
|
4
|
-
withBaseHref: string;
|
|
5
|
-
removeBaseHref: string;
|
|
6
|
-
linkType: LinkType;
|
|
7
|
-
};
|
|
8
2
|
/**
|
|
9
3
|
* For import { Link } from '@rspress/core/theme';
|
|
10
4
|
* useNavigate with preload logic
|
|
@@ -12,4 +6,3 @@ export declare function getHref(href: string): {
|
|
|
12
6
|
export declare function useLinkNavigate({ startTransition, }?: {
|
|
13
7
|
startTransition?: TransitionStartFunction;
|
|
14
8
|
}): (href: string) => Promise<void>;
|
|
15
|
-
export {};
|
|
@@ -1,34 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { initPageData, isActive, pathnameToRouteService, useLocation, useNavigate, useSite, warmPageData } from "@rspress/core/runtime";
|
|
2
2
|
import nprogress from "nprogress";
|
|
3
3
|
import { startTransition as external_react_startTransition, useCallback } from "react";
|
|
4
|
+
import { getHref } from "./getHref.js";
|
|
4
5
|
nprogress.configure({
|
|
5
6
|
showSpinner: false
|
|
6
7
|
});
|
|
7
|
-
function isAbsoluteUrl(url) {
|
|
8
|
-
return url.startsWith('/');
|
|
9
|
-
}
|
|
10
|
-
function getLinkType(href) {
|
|
11
|
-
if (isExternalUrl(href)) return 'external';
|
|
12
|
-
if (href.startsWith('#')) return 'hashOnly';
|
|
13
|
-
if (!isAbsoluteUrl(href)) return 'relative';
|
|
14
|
-
return 'internal';
|
|
15
|
-
}
|
|
16
|
-
function getHref(href) {
|
|
17
|
-
let withBaseHref;
|
|
18
|
-
const linkType = getLinkType(href);
|
|
19
|
-
if ('external' === linkType || 'hashOnly' === linkType) return {
|
|
20
|
-
linkType: linkType,
|
|
21
|
-
withBaseHref: href,
|
|
22
|
-
removeBaseHref: href
|
|
23
|
-
};
|
|
24
|
-
withBaseHref = 'relative' !== linkType || import.meta.env.SSR ? withBase(cleanUrlByConfig(href)) : new URL(href, window.location.href).pathname;
|
|
25
|
-
const removeBaseHref = removeBase(withBaseHref);
|
|
26
|
-
return {
|
|
27
|
-
withBaseHref,
|
|
28
|
-
removeBaseHref,
|
|
29
|
-
linkType
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
8
|
function useLinkNavigate({ startTransition = external_react_startTransition } = {
|
|
33
9
|
startTransition: external_react_startTransition
|
|
34
10
|
}) {
|
|
@@ -37,20 +13,20 @@ function useLinkNavigate({ startTransition = external_react_startTransition } =
|
|
|
37
13
|
const { site } = useSite();
|
|
38
14
|
const useTransitions = site?.route?.useTransitions;
|
|
39
15
|
return useCallback(async (href)=>{
|
|
40
|
-
const { linkType, removeBaseHref, withBaseHref } = getHref(href);
|
|
16
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
41
17
|
if ('external' === linkType || 'hashOnly' === linkType) return void window.location.assign(href);
|
|
42
18
|
const isTransitionable = !!(useTransitions && startTransition);
|
|
43
19
|
const preloadChunkThenNavigate = async ()=>{
|
|
44
20
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
45
21
|
if (!import.meta.env.SSR && !inCurrPage) {
|
|
46
|
-
const matchedRoute = pathnameToRouteService(
|
|
22
|
+
const matchedRoute = pathnameToRouteService(routePath);
|
|
47
23
|
if (!matchedRoute) return void window.location.assign(withBaseHref);
|
|
48
24
|
{
|
|
49
25
|
const timer = setTimeout(()=>{
|
|
50
26
|
nprogress.start();
|
|
51
27
|
}, 200);
|
|
52
|
-
const data = await initPageData(
|
|
53
|
-
warmPageData(
|
|
28
|
+
const data = await initPageData(routePath);
|
|
29
|
+
warmPageData(routePath, data);
|
|
54
30
|
clearTimeout(timer);
|
|
55
31
|
nprogress.done();
|
|
56
32
|
}
|
|
@@ -71,4 +47,4 @@ function useLinkNavigate({ startTransition = external_react_startTransition } =
|
|
|
71
47
|
startTransition
|
|
72
48
|
]);
|
|
73
49
|
}
|
|
74
|
-
export {
|
|
50
|
+
export { useLinkNavigate };
|
|
@@ -13,7 +13,8 @@ const visuallyHiddenStyle = {
|
|
|
13
13
|
border: 0
|
|
14
14
|
};
|
|
15
15
|
function createLlmsHintText({ llmsTxtUrl, llmsFullTxtUrl, pageMdUrl }) {
|
|
16
|
-
|
|
16
|
+
const text = `For AI agents: the complete documentation index is available at ${llmsTxtUrl}, the full documentation bundle is available at ${llmsFullTxtUrl}`;
|
|
17
|
+
return pageMdUrl ? `${text}, and this page is available as Markdown at ${pageMdUrl}.` : `${text}.`;
|
|
17
18
|
}
|
|
18
19
|
function LlmsHint() {
|
|
19
20
|
const { page } = usePage();
|
|
@@ -24,13 +25,16 @@ function LlmsHint() {
|
|
|
24
25
|
const langPrefix = page.lang === site.lang ? '' : `${page.lang}/`;
|
|
25
26
|
const llmsTxtUrl = withSiteOrigin(withBase(`/${versionPrefix}${langPrefix}llms.txt`));
|
|
26
27
|
const llmsFullTxtUrl = withSiteOrigin(withBase(`/${versionPrefix}${langPrefix}llms-full.txt`));
|
|
28
|
+
if (import.meta.env.SSG_MD) return `> ${createLlmsHintText({
|
|
29
|
+
llmsTxtUrl,
|
|
30
|
+
llmsFullTxtUrl
|
|
31
|
+
})}\n\n`;
|
|
27
32
|
const pageMdUrl = withSiteOrigin(routePathToMdPath(page.routePath));
|
|
28
33
|
const hintText = createLlmsHintText({
|
|
29
34
|
llmsTxtUrl,
|
|
30
35
|
llmsFullTxtUrl,
|
|
31
36
|
pageMdUrl
|
|
32
37
|
});
|
|
33
|
-
if (import.meta.env.SSG_MD) return `> ${hintText}\n\n`;
|
|
34
38
|
return /*#__PURE__*/ jsx("div", {
|
|
35
39
|
className: "rp-llms-hint",
|
|
36
40
|
style: visuallyHiddenStyle,
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
.rp-nav-menu {
|
|
2
|
+
--rp-nav-menu-item-gap: 32px;
|
|
2
3
|
align-items: center;
|
|
3
4
|
height: 100%;
|
|
4
5
|
list-style: none;
|
|
5
6
|
display: inline-flex;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
@media (width
|
|
9
|
+
@media (width <= 1279px) {
|
|
9
10
|
.rp-nav-menu {
|
|
10
|
-
gap:
|
|
11
|
+
--rp-nav-menu-item-gap: 24px;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
gap: 24px;
|
|
17
|
-
}
|
|
15
|
+
.rp-nav-menu--left {
|
|
16
|
+
margin: 0 0 0 24px;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
.rp-nav-menu__item {
|
|
@@ -27,11 +26,12 @@
|
|
|
27
26
|
|
|
28
27
|
.rp-nav-menu__item__container {
|
|
29
28
|
cursor: pointer;
|
|
29
|
+
height: 100%;
|
|
30
|
+
padding: 0 calc(var(--rp-nav-menu-item-gap)/2) 0 calc(var(--rp-nav-menu-item-gap)/2);
|
|
30
31
|
text-align: center;
|
|
31
32
|
justify-content: center;
|
|
32
33
|
align-items: center;
|
|
33
34
|
gap: 4px;
|
|
34
|
-
height: 100%;
|
|
35
35
|
font-size: 14px;
|
|
36
36
|
font-style: normal;
|
|
37
37
|
font-weight: 500;
|
|
@@ -39,6 +39,14 @@
|
|
|
39
39
|
display: flex;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
.rp-nav-menu__item:first-child > .rp-nav-menu__item__container {
|
|
43
|
+
padding-left: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.rp-nav-menu__item:last-child > .rp-nav-menu__item__container {
|
|
47
|
+
padding-right: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
.rp-nav-menu__item__icon {
|
|
43
51
|
justify-content: center;
|
|
44
52
|
align-items: center;
|
|
@@ -5,14 +5,13 @@ function replaceLang(rawUrl, lang, version, cleanUrls, isPageNotFound) {
|
|
|
5
5
|
url = normalizeHrefInRuntime(url);
|
|
6
6
|
let versionPart = '';
|
|
7
7
|
let langPart = '';
|
|
8
|
-
let purePathPart = '';
|
|
9
8
|
const parts = url.split('/').filter(Boolean);
|
|
10
9
|
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
|
11
10
|
if (lang.target !== lang.default) {
|
|
12
11
|
langPart = lang.target;
|
|
13
12
|
if (lang.current !== lang.default) parts.shift();
|
|
14
13
|
} else parts.shift();
|
|
15
|
-
purePathPart = parts.join('/') || '';
|
|
14
|
+
let purePathPart = parts.join('/') || '';
|
|
16
15
|
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
|
17
16
|
return addLeadingSlash([
|
|
18
17
|
versionPart,
|
|
@@ -11,7 +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
|
+
transition: background-color .2s ease-in-out, border-bottom-color .2s ease-in-out;
|
|
15
15
|
display: flex;
|
|
16
16
|
position: sticky;
|
|
17
17
|
left: 0;
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
.rp-nav__left {
|
|
28
|
+
align-items: center;
|
|
29
|
+
height: 100%;
|
|
28
30
|
display: flex;
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -302,7 +302,8 @@
|
|
|
302
302
|
|
|
303
303
|
.rp-prompt__custom-content a {
|
|
304
304
|
color: var(--rp-prompt-accent, var(--rp-c-brand-dark));
|
|
305
|
-
|
|
305
|
+
text-underline-offset: 4px;
|
|
306
|
+
text-decoration: underline;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
.rp-prompt__custom-content a > code, .rp-prompt__custom-content a:hover > code {
|
|
@@ -7,7 +7,7 @@ const cjkRegex = /[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]|[\u4E00-\u9FCC\u34
|
|
|
7
7
|
const cyrillicRegex = /[\u0400-\u04FF]/g;
|
|
8
8
|
function tokenize(str, regex) {
|
|
9
9
|
const words = [];
|
|
10
|
-
let m
|
|
10
|
+
let m;
|
|
11
11
|
do {
|
|
12
12
|
m = regex.exec(str);
|
|
13
13
|
if (m) words.push(m[0]);
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
::view-transition-old(root) {
|
|
1
|
+
::view-transition-old(root), ::view-transition-new(root) {
|
|
2
2
|
mix-blend-mode: normal;
|
|
3
3
|
animation: none;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
animation: none;
|
|
6
|
+
html.rp-theme-switching *, html.rp-theme-switching :before, html.rp-theme-switching :after {
|
|
7
|
+
transition: none !important;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
html.rp-theme-switching ::-webkit-scrollbar-thumb {
|
|
11
|
+
transition: none !important;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
.
|
|
16
|
-
|
|
14
|
+
html.rp-appearance-transition .rspress-doc {
|
|
15
|
+
view-transition-name: none !important;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
::view-transition-new(root) {
|
|
20
|
-
z-index:
|
|
18
|
+
::view-transition-old(root), .dark::view-transition-new(root) {
|
|
19
|
+
z-index: 1;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
.dark::view-transition-old(root) {
|
|
22
|
+
::view-transition-new(root), .dark::view-transition-old(root) {
|
|
24
23
|
z-index: 9999;
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -7,15 +7,9 @@ import "./index.css";
|
|
|
7
7
|
import { flushSync } from "react-dom";
|
|
8
8
|
const supportAppearanceTransition = ()=>'function' == typeof document?.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
9
9
|
const removeClipViewTransition = ()=>{
|
|
10
|
-
|
|
11
|
-
styleDom.innerHTML = `
|
|
12
|
-
.rspress-doc {
|
|
13
|
-
view-transition-name: none !important;
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
document.head.appendChild(styleDom);
|
|
10
|
+
document.documentElement.classList.add('rp-appearance-transition');
|
|
17
11
|
return ()=>{
|
|
18
|
-
document.
|
|
12
|
+
document.documentElement.classList.remove('rp-appearance-transition');
|
|
19
13
|
};
|
|
20
14
|
};
|
|
21
15
|
function SwitchAppearance({ onClick }) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const applyThemeToDOM = (theme)=>{
|
|
2
|
+
const root = document?.documentElement;
|
|
3
|
+
if (!root) return;
|
|
4
|
+
const isDark = 'dark' === theme;
|
|
5
|
+
const changed = root.classList.contains('dark') !== isDark;
|
|
6
|
+
root.classList.toggle('dark', isDark);
|
|
7
|
+
root.classList.toggle('rp-dark', isDark);
|
|
8
|
+
root.style.colorScheme = theme;
|
|
9
|
+
if (changed) {
|
|
10
|
+
root.classList.add('rp-theme-switching');
|
|
11
|
+
window.getComputedStyle(root).opacity;
|
|
12
|
+
requestAnimationFrame(()=>{
|
|
13
|
+
root.classList.remove('rp-theme-switching');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export { applyThemeToDOM };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type ThemeValue
|
|
1
|
+
import { type ThemeValue } from './applyThemeToDOM.js';
|
|
2
2
|
/**
|
|
3
3
|
* State provider for theme context.
|
|
4
4
|
* @internal
|
|
@@ -7,4 +7,3 @@ export declare function useThemeState(): readonly [
|
|
|
7
7
|
ThemeValue,
|
|
8
8
|
(value: ThemeValue) => void
|
|
9
9
|
];
|
|
10
|
-
export {};
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { useSite } from "@rspress/core/runtime";
|
|
2
2
|
import { getDefaultDarkModeValue, isDarkModeSwitchEnabled } from "@rspress/shared";
|
|
3
3
|
import { useCallback, useLayoutEffect } from "react";
|
|
4
|
+
import { applyThemeToDOM } from "./applyThemeToDOM.js";
|
|
4
5
|
import { useMediaQuery } from "./useMediaQuery.js";
|
|
5
6
|
import { useStorageValue } from "./useStorageValue.js";
|
|
6
7
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
7
8
|
const MEDIA_QUERY = '(prefers-color-scheme: dark)';
|
|
8
|
-
const applyThemeToDOM = (theme)=>{
|
|
9
|
-
if (!document?.documentElement) return;
|
|
10
|
-
const root = document.documentElement;
|
|
11
|
-
root.classList.toggle('dark', 'dark' === theme);
|
|
12
|
-
root.classList.toggle('rp-dark', 'dark' === theme);
|
|
13
|
-
root.style.colorScheme = theme;
|
|
14
|
-
};
|
|
15
9
|
function useSystemTheme() {
|
|
16
10
|
const prefersDark = useMediaQuery(MEDIA_QUERY);
|
|
17
11
|
const system = prefersDark ? 'dark' : 'light';
|
|
@@ -23,6 +23,10 @@ export declare function renderInlineMarkdown(text: string): {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
+
* Parse a header text to plain text, which can be used in attributes like `title`. Both the inline markdown syntax and
|
|
27
|
+
* the HTML are stripped, because a header is markdown when it comes from the remark toc plugin, and HTML when it is
|
|
28
|
+
* collected from the DOM by `useDynamicToc`, carrying the markup of the components rendered in the heading.
|
|
29
|
+
* @param mdx The header text to parse, either markdown or HTML.
|
|
26
30
|
* @internal
|
|
27
31
|
* @private
|
|
28
32
|
*/
|
|
@@ -20,11 +20,32 @@ const CODE_TEXT_PATTERN = /`(.*?)`/g;
|
|
|
20
20
|
const STRONG_TEXT_PATTERN = /\*{2}(?!\*)(.*?)\*{2}(?!\*)/g;
|
|
21
21
|
const EMPHASIS_TEXT_PATTERN = /\*(?!\*)(.*?)\*(?!\*)/g;
|
|
22
22
|
const DELETE_TEXT_PATTERN = /~{2}(.*?)~{2}/g;
|
|
23
|
+
const INLINE_CODE_PATTERN = /`[^`]+`/g;
|
|
24
|
+
const HTML_TAG_PATTERN = /<\/?[a-z][^>]*>/gi;
|
|
25
|
+
const HTML_ENTITY_PATTERN = /&(#\d+|#x[0-9a-f]+|[a-z][0-9a-z]*);/gi;
|
|
26
|
+
const NAMED_HTML_ENTITIES = {
|
|
27
|
+
amp: '&',
|
|
28
|
+
apos: "'",
|
|
29
|
+
gt: '>',
|
|
30
|
+
lt: '<',
|
|
31
|
+
nbsp: '\u00A0',
|
|
32
|
+
quot: '"'
|
|
33
|
+
};
|
|
34
|
+
function decodeHtmlEntities(text) {
|
|
35
|
+
return text.replace(HTML_ENTITY_PATTERN, (match, entity)=>{
|
|
36
|
+
if (!entity.startsWith('#')) return NAMED_HTML_ENTITIES[entity.toLowerCase()] ?? match;
|
|
37
|
+
const isHex = 'x' === entity[1] || 'X' === entity[1];
|
|
38
|
+
const codePoint = Number.parseInt(isHex ? entity.slice(2) : entity.slice(1), isHex ? 16 : 10);
|
|
39
|
+
const isScalarValue = codePoint <= 0x10ffff && !(codePoint >= 0xd800 && codePoint <= 0xdfff);
|
|
40
|
+
return isScalarValue ? String.fromCodePoint(codePoint) : match;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
23
43
|
function renderInlineMarkdown(text) {
|
|
24
|
-
const htmlText = text.replace(
|
|
44
|
+
const htmlText = text.replace(INLINE_CODE_PATTERN, (match)=>match.replace(/</g, '<')).replace(STRONG_TEXT_PATTERN, '<strong>$1</strong>').replace(EMPHASIS_TEXT_PATTERN, '<em>$1</em>').replace(DELETE_TEXT_PATTERN, '<del>$1</del>').replace(CODE_TEXT_PATTERN, '<code>$1</code>');
|
|
25
45
|
return renderHtmlOrText(htmlText);
|
|
26
46
|
}
|
|
27
47
|
function parseInlineMarkdownText(mdx) {
|
|
28
|
-
|
|
48
|
+
const plainText = mdx.replace(INLINE_CODE_PATTERN, (match)=>match.replace(/</g, '<')).replace(STRONG_TEXT_PATTERN, '$1').replace(EMPHASIS_TEXT_PATTERN, '$1').replace(DELETE_TEXT_PATTERN, '$1').replace(CODE_TEXT_PATTERN, '$1').replace(HTML_TAG_PATTERN, '');
|
|
49
|
+
return decodeHtmlEntities(plainText).trim();
|
|
29
50
|
}
|
|
30
51
|
export { parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown };
|
|
@@ -27,7 +27,6 @@ hr {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
abbr:where([title]) {
|
|
30
|
-
-webkit-text-decoration: underline dotted;
|
|
31
30
|
text-decoration: underline dotted;
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -38,7 +37,6 @@ h1, h2, h3, h4, h5, h6 {
|
|
|
38
37
|
|
|
39
38
|
a {
|
|
40
39
|
color: inherit;
|
|
41
|
-
-webkit-text-decoration: inherit;
|
|
42
40
|
text-decoration: inherit;
|
|
43
41
|
}
|
|
44
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@mdx-js/mdx": "^3.1.1",
|
|
62
62
|
"@mdx-js/react": "^3.1.1",
|
|
63
|
-
"@rsbuild/core": "^2.1.
|
|
63
|
+
"@rsbuild/core": "^2.1.13",
|
|
64
64
|
"@rsbuild/plugin-react": "~2.1.0",
|
|
65
65
|
"@shikijs/rehype": "^4.2.0",
|
|
66
66
|
"@types/mdast": "^4.0.4",
|
|
67
|
-
"@types/react": "^19.2.
|
|
68
|
-
"@unhead/react": "^2.1.
|
|
67
|
+
"@types/react": "^19.2.18",
|
|
68
|
+
"@unhead/react": "^2.1.17",
|
|
69
69
|
"body-scroll-lock": "4.0.0-beta.0",
|
|
70
70
|
"clsx": "2.1.1",
|
|
71
71
|
"copy-to-clipboard": "^3.3.3",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"react-dom": "^19.2.8",
|
|
81
81
|
"react-lazy-with-preload": "^2.2.1",
|
|
82
82
|
"react-render-to-markdown": "19.1.0",
|
|
83
|
-
"react-router-dom": "^7.18.
|
|
83
|
+
"react-router-dom": "^7.18.2",
|
|
84
84
|
"rehype-external-links": "^3.0.0",
|
|
85
85
|
"rehype-raw": "^7.0.0",
|
|
86
86
|
"remark-cjk-friendly": "^2.3.1",
|
|
@@ -95,27 +95,27 @@
|
|
|
95
95
|
"unist-util-visit": "^5.1.0",
|
|
96
96
|
"unist-util-visit-children": "^3.0.0",
|
|
97
97
|
"vfile": "^6.0.3",
|
|
98
|
-
"@rspress/shared": "2.0.
|
|
98
|
+
"@rspress/shared": "2.0.21"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@microsoft/api-extractor": "^7.
|
|
102
|
-
"@rsbuild/plugin-sass": "~
|
|
101
|
+
"@microsoft/api-extractor": "^7.59.0",
|
|
102
|
+
"@rsbuild/plugin-sass": "~2.0.1",
|
|
103
103
|
"@rsbuild/plugin-svgr": "^2.0.5",
|
|
104
|
-
"@rslib/core": "1.0.0-
|
|
104
|
+
"@rslib/core": "1.0.0-rc.0",
|
|
105
105
|
"@types/body-scroll-lock": "^3.1.2",
|
|
106
106
|
"@types/hast": "^3.0.5",
|
|
107
107
|
"@types/node": "^22.8.1",
|
|
108
108
|
"@types/nprogress": "^0.2.3",
|
|
109
|
-
"@types/react-dom": "^19.2.
|
|
110
|
-
"@types/web": "^0.0.
|
|
109
|
+
"@types/react-dom": "^19.2.4",
|
|
110
|
+
"@types/web": "^0.0.354",
|
|
111
111
|
"cac": "^7.0.0",
|
|
112
112
|
"execa": "8.0.1",
|
|
113
113
|
"mdast-util-directive": "^3.1.0",
|
|
114
114
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
115
|
-
"memfs": "^4.
|
|
115
|
+
"memfs": "^4.68.1",
|
|
116
116
|
"p-map": "^7.0.6",
|
|
117
117
|
"picocolors": "^1.1.1",
|
|
118
|
-
"postcss": "8.5.
|
|
118
|
+
"postcss": "8.5.26",
|
|
119
119
|
"remark-directive": "^4.0.0",
|
|
120
120
|
"rsbuild-plugin-publint": "^1.0.0",
|
|
121
121
|
"rsbuild-plugin-virtual-module": "0.4.5",
|