@rspress/core 2.0.20 → 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/8472~0.js +1 -1
- 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/Nav/NavMenu.scss +16 -4
- 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/SwitchAppearance/global.scss +18 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +4 -9
- 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/Nav/NavMenu.css +15 -7
- package/dist/theme/components/Nav/index.css +3 -1
- package/dist/theme/components/Prompt/index.css +2 -1
- package/dist/theme/components/SwitchAppearance/global.css +12 -0
- 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/package.json +2 -2
package/dist/8472~0.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { IconClose, Link, mergeRefs, SvgWrapper } from '@rspress/core/theme';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { forwardRef, type ReactNode, useEffect, useState } from 'react';
|
|
3
|
+
import { forwardRef, type ReactNode, useEffect, useId, useState } from 'react';
|
|
4
4
|
import './index.scss';
|
|
5
5
|
|
|
6
|
+
const inlineStorageScript = `(function () {
|
|
7
|
+
var script = document.currentScript;
|
|
8
|
+
if (!script) return;
|
|
9
|
+
try {
|
|
10
|
+
var storage = window[script.dataset.rpBannerStorage];
|
|
11
|
+
var storageKey = script.dataset.rpBannerStorageKey;
|
|
12
|
+
var hiddenClass = script.dataset.rpBannerHiddenClass;
|
|
13
|
+
if (storage && storageKey && hiddenClass && storage.getItem(storageKey)) {
|
|
14
|
+
document.documentElement.classList.add(hiddenClass);
|
|
15
|
+
}
|
|
16
|
+
} catch (e) {}
|
|
17
|
+
})();`;
|
|
18
|
+
|
|
6
19
|
export type BannerProps = {
|
|
7
20
|
/**
|
|
8
21
|
* @default true
|
|
@@ -71,6 +84,7 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
71
84
|
storage?: 'localStorage' | 'sessionStorage' | false;
|
|
72
85
|
customChildren?: ReactNode;
|
|
73
86
|
};
|
|
87
|
+
const isCustom = 'customChildren' in props;
|
|
74
88
|
|
|
75
89
|
const [height, setHeight] = useState(36);
|
|
76
90
|
const ref = mergeRefs(forwardedRef, element => {
|
|
@@ -79,14 +93,27 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
79
93
|
}
|
|
80
94
|
});
|
|
81
95
|
const [disable, setDisable] = useState(false);
|
|
96
|
+
const bannerId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
97
|
+
const bannerClass = `rp-banner-${bannerId}`;
|
|
98
|
+
const hiddenClass = `${bannerClass}-hidden`;
|
|
82
99
|
|
|
83
|
-
// TODO: support SSR
|
|
84
100
|
useEffect(() => {
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
let isDisabled = false;
|
|
102
|
+
if (!isCustom && typeof window !== 'undefined' && storage && storageKey) {
|
|
103
|
+
try {
|
|
104
|
+
isDisabled = Boolean(window[storage].getItem(storageKey));
|
|
105
|
+
} catch {
|
|
106
|
+
isDisabled = false;
|
|
107
|
+
}
|
|
87
108
|
}
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
|
|
110
|
+
document.documentElement.classList.toggle(hiddenClass, isDisabled);
|
|
111
|
+
setDisable(isDisabled);
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
document.documentElement.classList.remove(hiddenClass);
|
|
115
|
+
};
|
|
116
|
+
}, [hiddenClass, isCustom, storage, storageKey]);
|
|
90
117
|
|
|
91
118
|
if (!display || disable) {
|
|
92
119
|
return null;
|
|
@@ -94,7 +121,17 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
94
121
|
|
|
95
122
|
return (
|
|
96
123
|
<>
|
|
97
|
-
|
|
124
|
+
{!isCustom && storage && storageKey ? (
|
|
125
|
+
<script
|
|
126
|
+
data-rp-banner-hidden-class={hiddenClass}
|
|
127
|
+
data-rp-banner-storage={storage}
|
|
128
|
+
data-rp-banner-storage-key={storageKey}
|
|
129
|
+
suppressHydrationWarning
|
|
130
|
+
dangerouslySetInnerHTML={{ __html: inlineStorageScript }}
|
|
131
|
+
/>
|
|
132
|
+
) : null}
|
|
133
|
+
<style>{`:root {--rp-banner-height: ${height}px;} :root.${hiddenClass} {--rp-banner-height: 0px;} :root.${hiddenClass} .${bannerClass} {display: none;}`}</style>
|
|
134
|
+
<div className={clsx('rp-banner', bannerClass, className)} ref={ref}>
|
|
98
135
|
{customChildren ?? (
|
|
99
136
|
<>
|
|
100
137
|
<Link
|
|
@@ -107,9 +144,14 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
107
144
|
<SvgWrapper
|
|
108
145
|
icon={IconClose}
|
|
109
146
|
onClick={() => {
|
|
147
|
+
document.documentElement.classList.add(hiddenClass);
|
|
110
148
|
setDisable(true);
|
|
111
149
|
if (storage) {
|
|
112
|
-
|
|
150
|
+
try {
|
|
151
|
+
window[storage].setItem(storageKey, 'true');
|
|
152
|
+
} catch {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
113
155
|
}
|
|
114
156
|
}}
|
|
115
157
|
className="rp-banner__close"
|
|
@@ -117,7 +159,6 @@ export const Banner = forwardRef<HTMLDivElement, BannerProps>(
|
|
|
117
159
|
</>
|
|
118
160
|
)}
|
|
119
161
|
</div>
|
|
120
|
-
<style>{`:root {--rp-banner-height: ${height}px;}`}</style>
|
|
121
162
|
</>
|
|
122
163
|
);
|
|
123
164
|
},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { getHref } from './getHref';
|
|
3
|
+
|
|
4
|
+
rs.mock('virtual-site-data', () => ({
|
|
5
|
+
default: {
|
|
6
|
+
base: '/docs/',
|
|
7
|
+
route: {
|
|
8
|
+
cleanUrls: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe('getHref', () => {
|
|
14
|
+
it('preserves search and hash for an internal link with a base', () => {
|
|
15
|
+
expect(getHref('/guide?tab=api#install')).toEqual({
|
|
16
|
+
linkType: 'internal',
|
|
17
|
+
withBaseHref: '/docs/guide?tab=api#install',
|
|
18
|
+
removeBaseHref: '/guide?tab=api#install',
|
|
19
|
+
routePath: '/guide',
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('preserves search and hash when resolving a relative link', () => {
|
|
24
|
+
expect(
|
|
25
|
+
getHref('./guide?tab=api#install', 'https://example.com/docs/source'),
|
|
26
|
+
).toEqual({
|
|
27
|
+
linkType: 'relative',
|
|
28
|
+
withBaseHref: '/docs/guide?tab=api#install',
|
|
29
|
+
removeBaseHref: '/guide?tab=api#install',
|
|
30
|
+
routePath: '/guide',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { cleanUrl, isExternalUrl } from '@rspress/shared';
|
|
2
|
+
import { cleanUrlByConfig, removeBase, withBase } from '../../../runtime/utils';
|
|
3
|
+
|
|
4
|
+
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
5
|
+
|
|
6
|
+
function isAbsoluteUrl(url: string): boolean {
|
|
7
|
+
return url.startsWith('/');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getLinkType(href: string): LinkType {
|
|
11
|
+
if (isExternalUrl(href)) {
|
|
12
|
+
return 'external';
|
|
13
|
+
}
|
|
14
|
+
if (href.startsWith('#')) {
|
|
15
|
+
return 'hashOnly';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!isAbsoluteUrl(href)) {
|
|
19
|
+
return 'relative';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return 'internal';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getHref(
|
|
26
|
+
href: string,
|
|
27
|
+
currentUrl = typeof window === 'undefined' ? undefined : window.location.href,
|
|
28
|
+
): {
|
|
29
|
+
withBaseHref: string;
|
|
30
|
+
removeBaseHref: string;
|
|
31
|
+
routePath: string;
|
|
32
|
+
linkType: LinkType;
|
|
33
|
+
} {
|
|
34
|
+
let withBaseHref;
|
|
35
|
+
const linkType = getLinkType(href);
|
|
36
|
+
|
|
37
|
+
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
38
|
+
return {
|
|
39
|
+
linkType,
|
|
40
|
+
withBaseHref: href,
|
|
41
|
+
removeBaseHref: href,
|
|
42
|
+
routePath: cleanUrl(href),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (linkType === 'relative' && currentUrl) {
|
|
47
|
+
const url = new URL(href, currentUrl);
|
|
48
|
+
withBaseHref = `${url.pathname}${url.search}${url.hash}`;
|
|
49
|
+
} else {
|
|
50
|
+
withBaseHref = withBase(cleanUrlByConfig(href));
|
|
51
|
+
}
|
|
52
|
+
const removeBaseHref = removeBase(withBaseHref);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
withBaseHref,
|
|
56
|
+
removeBaseHref,
|
|
57
|
+
routePath: cleanUrl(removeBaseHref),
|
|
58
|
+
linkType,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -5,7 +5,8 @@ import type React from 'react';
|
|
|
5
5
|
import type { ComponentProps, TransitionStartFunction } from 'react';
|
|
6
6
|
import { forwardRef } from 'react';
|
|
7
7
|
import './index.scss';
|
|
8
|
-
import { getHref
|
|
8
|
+
import { getHref } from './getHref';
|
|
9
|
+
import { useLinkNavigate } from './useLinkNavigate';
|
|
9
10
|
|
|
10
11
|
export interface LinkProps extends ComponentProps<'a'> {
|
|
11
12
|
href?: string;
|
|
@@ -55,7 +56,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
55
56
|
...otherProps
|
|
56
57
|
} = props;
|
|
57
58
|
|
|
58
|
-
const { linkType, removeBaseHref, withBaseHref } = getHref(href);
|
|
59
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
59
60
|
const navigate = useLinkNavigate({ startTransition });
|
|
60
61
|
|
|
61
62
|
if (linkType === 'external') {
|
|
@@ -98,10 +99,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
98
99
|
className={clsx(className, 'rp-link')}
|
|
99
100
|
onMouseEnter={event => {
|
|
100
101
|
onMouseEnter?.(event);
|
|
101
|
-
preloadLink(
|
|
102
|
+
preloadLink(routePath);
|
|
102
103
|
}}
|
|
103
104
|
onTouchStart={() => {
|
|
104
|
-
preloadLink(
|
|
105
|
+
preloadLink(routePath);
|
|
105
106
|
}}
|
|
106
107
|
onClick={e => {
|
|
107
108
|
onClick?.(e);
|
|
@@ -135,10 +136,10 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
|
|
|
135
136
|
className={clsx(className, 'rp-link')}
|
|
136
137
|
onMouseEnter={event => {
|
|
137
138
|
onMouseEnter?.(event);
|
|
138
|
-
preloadLink(
|
|
139
|
+
preloadLink(routePath);
|
|
139
140
|
}}
|
|
140
141
|
onTouchStart={() => {
|
|
141
|
-
preloadLink(
|
|
142
|
+
preloadLink(routePath);
|
|
142
143
|
}}
|
|
143
144
|
onClick={e => {
|
|
144
145
|
onClick?.(e);
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
cleanUrlByConfig,
|
|
3
2
|
initPageData,
|
|
4
3
|
isActive,
|
|
5
|
-
isExternalUrl,
|
|
6
4
|
pathnameToRouteService,
|
|
7
|
-
removeBase,
|
|
8
5
|
useLocation,
|
|
9
6
|
useNavigate as useNavigateInner,
|
|
10
7
|
useSite,
|
|
11
8
|
warmPageData,
|
|
12
|
-
withBase,
|
|
13
9
|
} from '@rspress/core/runtime';
|
|
14
10
|
import nprogress from 'nprogress';
|
|
15
11
|
import {
|
|
@@ -17,52 +13,10 @@ import {
|
|
|
17
13
|
type TransitionStartFunction,
|
|
18
14
|
useCallback,
|
|
19
15
|
} from 'react';
|
|
16
|
+
import { getHref } from './getHref';
|
|
20
17
|
|
|
21
18
|
nprogress.configure({ showSpinner: false });
|
|
22
19
|
|
|
23
|
-
function isAbsoluteUrl(url: string): boolean {
|
|
24
|
-
return url.startsWith('/');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type LinkType = 'external' | 'hashOnly' | 'relative' | 'internal';
|
|
28
|
-
|
|
29
|
-
function getLinkType(href: string): LinkType {
|
|
30
|
-
if (isExternalUrl(href)) {
|
|
31
|
-
return 'external';
|
|
32
|
-
}
|
|
33
|
-
if (href.startsWith('#')) {
|
|
34
|
-
return 'hashOnly';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!isAbsoluteUrl(href)) {
|
|
38
|
-
return 'relative';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return 'internal';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getHref(href: string): {
|
|
45
|
-
withBaseHref: string;
|
|
46
|
-
removeBaseHref: string;
|
|
47
|
-
linkType: LinkType;
|
|
48
|
-
} {
|
|
49
|
-
let withBaseHref;
|
|
50
|
-
const linkType = getLinkType(href);
|
|
51
|
-
|
|
52
|
-
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
53
|
-
return { linkType: linkType, withBaseHref: href, removeBaseHref: href };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (linkType === 'relative' && !import.meta.env.SSR) {
|
|
57
|
-
withBaseHref = new URL(href, window.location.href).pathname;
|
|
58
|
-
} else {
|
|
59
|
-
withBaseHref = withBase(cleanUrlByConfig(href));
|
|
60
|
-
}
|
|
61
|
-
const removeBaseHref = removeBase(withBaseHref);
|
|
62
|
-
|
|
63
|
-
return { withBaseHref, removeBaseHref, linkType };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
20
|
/**
|
|
67
21
|
* For import { Link } from '@rspress/core/theme';
|
|
68
22
|
* useNavigate with preload logic
|
|
@@ -81,7 +35,8 @@ export function useLinkNavigate(
|
|
|
81
35
|
|
|
82
36
|
return useCallback(
|
|
83
37
|
async (href: string) => {
|
|
84
|
-
const { linkType, removeBaseHref, withBaseHref } =
|
|
38
|
+
const { linkType, removeBaseHref, routePath, withBaseHref } =
|
|
39
|
+
getHref(href);
|
|
85
40
|
if (linkType === 'external' || linkType === 'hashOnly') {
|
|
86
41
|
window.location.assign(href);
|
|
87
42
|
return;
|
|
@@ -92,13 +47,13 @@ export function useLinkNavigate(
|
|
|
92
47
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
93
48
|
|
|
94
49
|
if (!import.meta.env.SSR && !inCurrPage) {
|
|
95
|
-
const matchedRoute = pathnameToRouteService(
|
|
50
|
+
const matchedRoute = pathnameToRouteService(routePath);
|
|
96
51
|
if (matchedRoute) {
|
|
97
52
|
const timer = setTimeout(() => {
|
|
98
53
|
nprogress.start();
|
|
99
54
|
}, 200);
|
|
100
|
-
const data = await initPageData(
|
|
101
|
-
warmPageData(
|
|
55
|
+
const data = await initPageData(routePath);
|
|
56
|
+
warmPageData(routePath, data);
|
|
102
57
|
clearTimeout(timer);
|
|
103
58
|
nprogress.done();
|
|
104
59
|
} else {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
.rp-nav-menu {
|
|
2
|
+
--rp-nav-menu-item-gap: 32px;
|
|
3
|
+
|
|
2
4
|
display: inline-flex;
|
|
3
5
|
align-items: center;
|
|
4
6
|
height: 100%;
|
|
5
7
|
list-style: none;
|
|
6
8
|
|
|
7
|
-
@media (
|
|
8
|
-
gap:
|
|
9
|
+
@media (max-width: 1279px) {
|
|
10
|
+
--rp-nav-menu-item-gap: 24px;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
&--left {
|
|
14
|
+
margin: 0 0 0 24px;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
&__item {
|
|
@@ -26,6 +28,8 @@
|
|
|
26
28
|
align-items: center;
|
|
27
29
|
height: 100%;
|
|
28
30
|
gap: 4px;
|
|
31
|
+
padding: 0 calc(var(--rp-nav-menu-item-gap) / 2) 0
|
|
32
|
+
calc(var(--rp-nav-menu-item-gap) / 2);
|
|
29
33
|
|
|
30
34
|
// text
|
|
31
35
|
text-align: center;
|
|
@@ -35,6 +39,14 @@
|
|
|
35
39
|
line-height: 22px;
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
&:first-child > .rp-nav-menu__item__container {
|
|
43
|
+
padding-left: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&:last-child > .rp-nav-menu__item__container {
|
|
47
|
+
padding-right: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
&__icon {
|
|
39
51
|
display: flex;
|
|
40
52
|
justify-content: center;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
.rp-nav {
|
|
2
2
|
transition:
|
|
3
3
|
background-color 0.2s ease-in-out,
|
|
4
|
-
border-bottom 0.2s ease-in-out;
|
|
4
|
+
border-bottom-color 0.2s ease-in-out;
|
|
5
5
|
display: flex;
|
|
6
6
|
height: var(--rp-nav-height);
|
|
7
7
|
flex-shrink: 0;
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
|
|
40
40
|
&__left {
|
|
41
41
|
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
height: 100%;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
&__title {
|
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
mix-blend-mode: normal;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
/* Toggled by applyThemeToDOM for one frame while the theme class flips, so
|
|
8
|
+
every themed surface switches in sync instead of fading at its own pace.
|
|
9
|
+
A static rule toggled via a root class (rather than an injected <style>)
|
|
10
|
+
stays compatible with strict CSP. */
|
|
11
|
+
html.rp-theme-switching *,
|
|
12
|
+
html.rp-theme-switching *::before,
|
|
13
|
+
html.rp-theme-switching *::after,
|
|
14
|
+
html.rp-theme-switching *::-webkit-scrollbar-thumb {
|
|
15
|
+
transition: none !important;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Toggled by SwitchAppearance while the appearance view transition runs; the
|
|
19
|
+
'flip' and 'root' view-transition names conflict otherwise, see
|
|
20
|
+
https://github.com/web-infra-dev/rspress/pull/1272 */
|
|
21
|
+
html.rp-appearance-transition .rspress-doc {
|
|
22
|
+
view-transition-name: none !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
7
25
|
::view-transition-old(root),
|
|
8
26
|
.dark::view-transition-new(root) {
|
|
9
27
|
z-index: 1;
|
|
@@ -12,17 +12,12 @@ const supportAppearanceTransition = () => {
|
|
|
12
12
|
);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
//
|
|
15
|
+
// Toggles the `html.rp-appearance-transition` rule in global.scss — see the
|
|
16
|
+
// comment there and https://github.com/web-infra-dev/rspress/pull/1272
|
|
16
17
|
const removeClipViewTransition = () => {
|
|
17
|
-
|
|
18
|
-
styleDom.innerHTML = `
|
|
19
|
-
.rspress-doc {
|
|
20
|
-
view-transition-name: none !important;
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
document.head.appendChild(styleDom);
|
|
18
|
+
document.documentElement.classList.add('rp-appearance-transition');
|
|
24
19
|
return () => {
|
|
25
|
-
document.
|
|
20
|
+
document.documentElement.classList.remove('rp-appearance-transition');
|
|
26
21
|
};
|
|
27
22
|
};
|
|
28
23
|
|
|
@@ -1,24 +1,66 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { IconClose, Link, SvgWrapper, mergeRefs } from "@rspress/core/theme";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { forwardRef, useEffect, useState } from "react";
|
|
4
|
+
import { forwardRef, useEffect, useId, useState } from "react";
|
|
5
5
|
import "./index.css";
|
|
6
|
+
const inlineStorageScript = `(function () {
|
|
7
|
+
var script = document.currentScript;
|
|
8
|
+
if (!script) return;
|
|
9
|
+
try {
|
|
10
|
+
var storage = window[script.dataset.rpBannerStorage];
|
|
11
|
+
var storageKey = script.dataset.rpBannerStorageKey;
|
|
12
|
+
var hiddenClass = script.dataset.rpBannerHiddenClass;
|
|
13
|
+
if (storage && storageKey && hiddenClass && storage.getItem(storageKey)) {
|
|
14
|
+
document.documentElement.classList.add(hiddenClass);
|
|
15
|
+
}
|
|
16
|
+
} catch (e) {}
|
|
17
|
+
})();`;
|
|
6
18
|
const Banner = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
|
|
7
19
|
const { href, message, display = true, className, storageKey = 'rp-banner-closed', storage = 'localStorage', customChildren } = props;
|
|
20
|
+
const isCustom = 'customChildren' in props;
|
|
8
21
|
const [height, setHeight] = useState(36);
|
|
9
22
|
const ref = mergeRefs(forwardedRef, (element)=>{
|
|
10
23
|
if (element?.offsetHeight) setHeight(element?.offsetHeight);
|
|
11
24
|
});
|
|
12
25
|
const [disable, setDisable] = useState(false);
|
|
26
|
+
const bannerId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
27
|
+
const bannerClass = `rp-banner-${bannerId}`;
|
|
28
|
+
const hiddenClass = `${bannerClass}-hidden`;
|
|
13
29
|
useEffect(()=>{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
let isDisabled = false;
|
|
31
|
+
if (!isCustom && "u" > typeof window && storage && storageKey) try {
|
|
32
|
+
isDisabled = Boolean(window[storage].getItem(storageKey));
|
|
33
|
+
} catch {
|
|
34
|
+
isDisabled = false;
|
|
35
|
+
}
|
|
36
|
+
document.documentElement.classList.toggle(hiddenClass, isDisabled);
|
|
37
|
+
setDisable(isDisabled);
|
|
38
|
+
return ()=>{
|
|
39
|
+
document.documentElement.classList.remove(hiddenClass);
|
|
40
|
+
};
|
|
41
|
+
}, [
|
|
42
|
+
hiddenClass,
|
|
43
|
+
isCustom,
|
|
44
|
+
storage,
|
|
45
|
+
storageKey
|
|
46
|
+
]);
|
|
17
47
|
if (!display || disable) return null;
|
|
18
48
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
19
49
|
children: [
|
|
50
|
+
!isCustom && storage && storageKey ? /*#__PURE__*/ jsx("script", {
|
|
51
|
+
"data-rp-banner-hidden-class": hiddenClass,
|
|
52
|
+
"data-rp-banner-storage": storage,
|
|
53
|
+
"data-rp-banner-storage-key": storageKey,
|
|
54
|
+
suppressHydrationWarning: true,
|
|
55
|
+
dangerouslySetInnerHTML: {
|
|
56
|
+
__html: inlineStorageScript
|
|
57
|
+
}
|
|
58
|
+
}) : null,
|
|
59
|
+
/*#__PURE__*/ jsx("style", {
|
|
60
|
+
children: `:root {--rp-banner-height: ${height}px;} :root.${hiddenClass} {--rp-banner-height: 0px;} :root.${hiddenClass} .${bannerClass} {display: none;}`
|
|
61
|
+
}),
|
|
20
62
|
/*#__PURE__*/ jsx("div", {
|
|
21
|
-
className: clsx('rp-banner', className),
|
|
63
|
+
className: clsx('rp-banner', bannerClass, className),
|
|
22
64
|
ref: ref,
|
|
23
65
|
children: customChildren ?? /*#__PURE__*/ jsxs(Fragment, {
|
|
24
66
|
children: [
|
|
@@ -31,16 +73,18 @@ const Banner = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
|
|
|
31
73
|
/*#__PURE__*/ jsx(SvgWrapper, {
|
|
32
74
|
icon: IconClose,
|
|
33
75
|
onClick: ()=>{
|
|
76
|
+
document.documentElement.classList.add(hiddenClass);
|
|
34
77
|
setDisable(true);
|
|
35
|
-
if (storage)
|
|
78
|
+
if (storage) try {
|
|
79
|
+
window[storage].setItem(storageKey, 'true');
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
36
83
|
},
|
|
37
84
|
className: "rp-banner__close"
|
|
38
85
|
})
|
|
39
86
|
]
|
|
40
87
|
})
|
|
41
|
-
}),
|
|
42
|
-
/*#__PURE__*/ jsx("style", {
|
|
43
|
-
children: `:root {--rp-banner-height: ${height}px;}`
|
|
44
88
|
})
|
|
45
89
|
]
|
|
46
90
|
});
|
|
@@ -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 };
|
|
@@ -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;
|
|
@@ -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 {
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
animation: none;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
html.rp-theme-switching *, html.rp-theme-switching :before, html.rp-theme-switching :after {
|
|
7
|
+
transition: none !important;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
html.rp-theme-switching ::-webkit-scrollbar-thumb {
|
|
11
|
+
transition: none !important;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
html.rp-appearance-transition .rspress-doc {
|
|
15
|
+
view-transition-name: none !important;
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
::view-transition-old(root), .dark::view-transition-new(root) {
|
|
7
19
|
z-index: 1;
|
|
8
20
|
}
|
|
@@ -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';
|
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": {
|
|
@@ -95,7 +95,7 @@
|
|
|
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
101
|
"@microsoft/api-extractor": "^7.59.0",
|