@rspress/core 2.0.21 → 2.0.23
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/bin/rspress.js +3 -1
- package/dist/{2711~0.js → a~0.js} +90 -70
- package/dist/{8472~0.js → b~0.js} +19 -14
- package/dist/cli/index.js +12 -13
- package/dist/config/loadConfigFile.d.ts +3 -4
- package/dist/config/loadConfigFile.js +13 -17
- package/dist/{7748~0.js → d~0.js} +0 -2
- package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +8 -0
- package/dist/eject-theme/components/Llms/LlmsHint.tsx +11 -3
- package/dist/eject-theme/components/Nav/NavMenu.scss +4 -0
- package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
- package/dist/eject-theme/components/Nav/index.tsx +30 -4
- package/dist/eject-theme/components/NavHamburger/index.tsx +11 -3
- package/dist/eject-theme/components/NavList/context.ts +3 -0
- package/dist/eject-theme/components/NavList/index.tsx +24 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.test.tsx +59 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenu.tsx +43 -2
- package/dist/eject-theme/components/NavScreen/index.scss +0 -6
- package/dist/eject-theme/components/NavScreen/index.tsx +20 -3
- package/dist/eject-theme/components/ReadPercent/useReadPercent.ts +1 -1
- package/dist/eject-theme/components/Search/SearchButton.scss +1 -0
- package/dist/eject-theme/components/Search/SearchPanel.scss +51 -12
- package/dist/eject-theme/components/Search/SearchPanel.tsx +62 -216
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +39 -17
- package/dist/eject-theme/components/Search/useSearchPanel.ts +217 -0
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
- package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
- package/dist/eject-theme/components/Steps/index.scss +1 -1
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.test.ts +15 -0
- package/dist/eject-theme/components/SwitchAppearance/getClipPath.ts +26 -0
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +22 -26
- package/dist/eject-theme/components/Tabs/index.tsx +14 -14
- package/dist/index.js +1 -1
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +5 -9
- 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 +6 -6
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/build.d.ts +3 -2
- package/dist/node/build.js +9 -3
- package/dist/node/constants.js +1 -1
- package/dist/node/dev.d.ts +4 -4
- package/dist/node/dev.js +8 -6
- package/dist/node/eject.js +5 -5
- package/dist/node/initRsbuild.d.ts +2 -3
- package/dist/node/initRsbuild.js +9 -7
- package/dist/node/last-updated/index.js +2 -2
- package/dist/node/logger/hint.js +4 -4
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +3 -3
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +6 -5
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +5 -5
- package/dist/node/mdx/remarkPlugins/image.js +5 -5
- package/dist/node/mdx/remarkPlugins/link.js +5 -5
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/medium-zoom/index.js +1 -1
- package/dist/node/route/RoutePage.js +6 -4
- package/dist/node/route/RouteService.js +3 -3
- package/dist/node/route/extractPageData.js +20 -7
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/i18n.js +5 -5
- 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.d.ts +3 -3
- package/dist/node/serve.js +10 -4
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +4 -3
- package/dist/node/ssg/renderPage.js +5 -5
- package/dist/node/ssg/renderPageWorker.js +2 -2
- package/dist/node/ssg/renderPages.js +6 -6
- 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/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -5
- package/dist/node/ssg-md/renderPages.js +6 -6
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +5 -7
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/error.js +4 -4
- package/dist/node/utils/flattenMdxContent.js +2 -2
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/index.d.ts +1 -1
- package/dist/node/utils/reactAlias.js +5 -5
- package/dist/node/utils/slash.d.ts +1 -0
- package/dist/node/utils/slash.js +4 -0
- package/dist/{864~0.js → n~0.js} +42 -41
- package/dist/rslib-runtime~0.js +27 -35
- package/dist/runtime/App.js +3 -2
- package/dist/runtime/hooks/createExternalStore.d.ts +4 -0
- package/dist/runtime/hooks/createExternalStore.js +20 -0
- package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
- package/dist/runtime/hooks/useGlobalComponents.js +10 -0
- package/dist/runtime/hooks/useI18n.js +5 -3
- package/dist/runtime/hooks/useI18nText.d.ts +1 -0
- package/dist/runtime/hooks/useI18nText.js +10 -0
- package/dist/runtime/hooks/usePages.d.ts +2 -0
- package/dist/runtime/hooks/usePages.js +12 -3
- package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
- package/dist/runtime/hooks/useSearchHooks.js +14 -0
- package/dist/runtime/hooks/useSite.d.ts +1 -0
- package/dist/runtime/hooks/useSite.js +9 -2
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.js +5 -1
- package/dist/runtime/initPageData.js +10 -10
- package/dist/runtime/route.js +5 -5
- package/dist/runtime/utils.js +6 -6
- package/dist/theme/components/Link/useLinkNavigate.js +1 -1
- package/dist/theme/components/Llms/LlmsHint.js +23 -6
- package/dist/theme/components/Nav/NavMenu.css +4 -0
- package/dist/theme/components/Nav/NavMenu.d.ts +4 -2
- package/dist/theme/components/Nav/NavMenu.js +17 -9
- package/dist/theme/components/Nav/index.d.ts +7 -1
- package/dist/theme/components/Nav/index.js +13 -4
- package/dist/theme/components/NavHamburger/index.d.ts +2 -1
- package/dist/theme/components/NavHamburger/index.js +8 -2
- package/dist/theme/components/NavList/context.d.ts +1 -0
- package/dist/theme/components/NavList/context.js +3 -0
- package/dist/theme/components/NavList/index.d.ts +6 -0
- package/dist/theme/components/NavList/index.js +17 -0
- package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +3 -2
- package/dist/theme/components/NavScreen/NavScreenMenu.js +42 -6
- package/dist/theme/components/NavScreen/index.css +0 -10
- package/dist/theme/components/NavScreen/index.d.ts +2 -1
- package/dist/theme/components/NavScreen/index.js +11 -3
- package/dist/theme/components/PackageManagerTabs/index.js +2 -2
- package/dist/theme/components/ReadPercent/useReadPercent.js +1 -0
- package/dist/theme/components/Search/SearchButton.css +1 -0
- package/dist/theme/components/Search/SearchPanel.css +47 -9
- package/dist/theme/components/Search/SearchPanel.js +104 -210
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +24 -14
- package/dist/theme/components/Search/logic/search.js +1 -1
- package/dist/theme/components/Search/useSearchPanel.d.ts +23 -0
- package/dist/theme/components/Search/useSearchPanel.js +155 -0
- package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
- package/dist/theme/components/SourceCode/index.js +1 -1
- package/dist/theme/components/Steps/index.css +3 -3
- package/dist/theme/components/SwitchAppearance/getClipPath.d.ts +8 -0
- package/dist/theme/components/SwitchAppearance/getClipPath.js +13 -0
- package/dist/theme/components/SwitchAppearance/index.js +9 -7
- package/dist/theme/components/Tabs/index.js +4 -4
- package/dist/theme/components/Tag/index.js +2 -2
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/layout/DocLayout/index.js +2 -2
- package/dist/theme/layout/Layout/index.js +12 -4
- package/dist/theme/logic/useFullTextSearch.js +6 -1
- package/dist/theme/logic/utils.d.ts +0 -2
- package/dist/theme/logic/utils.js +56 -6
- package/dist/theme/styles/vars/shiki-vars.css +1 -1
- package/dist/tinypool~0.js +5 -3
- package/dist/{4538~0.js → t~0.js} +2 -2
- package/package.json +15 -16
- package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +0 -29
- package/dist/node/utils/normalizePath.d.ts +0 -3
- package/dist/node/utils/normalizePath.js +0 -10
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +0 -2
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +0 -30
- package/dist/theme/logic/useHandler.d.ts +0 -6
- package/dist/theme/logic/useHandler.js +0 -7
- /package/dist/{9857~0.js → 4~0.js} +0 -0
- /package/dist/{8016~0.js → i~0.js} +0 -0
- /package/dist/{5357~0.js → r~0.js} +0 -0
- /package/dist/{102~0.js → t2~0.js} +0 -0
- /package/dist/{9940~0.js → tx~0.js} +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { usePageData, useSearchHooks } from '@rspress/core/runtime';
|
|
2
|
+
import type { LocalSearchOptions } from '@rspress/core';
|
|
3
|
+
import { debounce } from '@rspress/shared/lodash-es';
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type RefObject,
|
|
10
|
+
} from 'react';
|
|
11
|
+
|
|
12
|
+
import { getSearchIndexURL } from './logic/providers/LocalProvider';
|
|
13
|
+
import { PageSearcher } from './logic/search';
|
|
14
|
+
import type {
|
|
15
|
+
CustomMatchResult,
|
|
16
|
+
DefaultMatchResult,
|
|
17
|
+
MatchResult,
|
|
18
|
+
PageSearcherConfig,
|
|
19
|
+
} from './logic/types';
|
|
20
|
+
import { RenderType } from './logic/types';
|
|
21
|
+
|
|
22
|
+
const useDebounce = <T extends (...args: any[]) => any>(cb: T) => {
|
|
23
|
+
const cbRef = useRef(cb);
|
|
24
|
+
cbRef.current = cb;
|
|
25
|
+
return useCallback(
|
|
26
|
+
debounce(
|
|
27
|
+
((...args: Parameters<T>): ReturnType<T> => cbRef.current(...args)) as T,
|
|
28
|
+
150,
|
|
29
|
+
),
|
|
30
|
+
[],
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function useSearchPanel({
|
|
35
|
+
focused,
|
|
36
|
+
searchInputRef,
|
|
37
|
+
}: {
|
|
38
|
+
focused: boolean;
|
|
39
|
+
searchInputRef: RefObject<HTMLInputElement | null>;
|
|
40
|
+
}) {
|
|
41
|
+
const {
|
|
42
|
+
siteData,
|
|
43
|
+
page: { lang, version },
|
|
44
|
+
} = usePageData();
|
|
45
|
+
const userSearchHooks = useSearchHooks();
|
|
46
|
+
const { search, title: siteTitle } = siteData;
|
|
47
|
+
const [query, setQuery] = useState('');
|
|
48
|
+
const [searchResult, setSearchResult] = useState<MatchResult>([]);
|
|
49
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
50
|
+
const [resultTabIndex, setResultTabIndex] = useState(0);
|
|
51
|
+
const [currentSuggestionIndex, setCurrentSuggestionIndex] = useState(0);
|
|
52
|
+
const [initStatus, setInitStatus] = useState<
|
|
53
|
+
'initial' | 'initing' | 'inited' | 'error'
|
|
54
|
+
>('initial');
|
|
55
|
+
const [searchError, setSearchError] = useState<string>();
|
|
56
|
+
const pageSearcherRef = useRef<PageSearcher | null>(null);
|
|
57
|
+
const pageSearcherConfigRef = useRef<PageSearcherConfig | null>(null);
|
|
58
|
+
const searchEnabled = search !== false;
|
|
59
|
+
const searchOptions: LocalSearchOptions = search === false ? {} : search;
|
|
60
|
+
const versionedSearch = searchEnabled && (search?.versioned ?? true);
|
|
61
|
+
const searchIndexURL = searchEnabled
|
|
62
|
+
? getSearchIndexURL(lang, versionedSearch ? version : '')
|
|
63
|
+
: undefined;
|
|
64
|
+
const DEFAULT_RESULT = [
|
|
65
|
+
{ group: siteTitle, result: [], renderType: RenderType.Default },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const createSearcher = () => {
|
|
69
|
+
if (pageSearcherRef.current) {
|
|
70
|
+
return pageSearcherRef.current;
|
|
71
|
+
}
|
|
72
|
+
const pageSearcherConfig = { currentLang: lang, currentVersion: version };
|
|
73
|
+
const pageSearcher = new PageSearcher({
|
|
74
|
+
indexName: siteTitle,
|
|
75
|
+
...searchOptions,
|
|
76
|
+
...pageSearcherConfig,
|
|
77
|
+
});
|
|
78
|
+
pageSearcherRef.current = pageSearcher;
|
|
79
|
+
pageSearcherConfigRef.current = pageSearcherConfig;
|
|
80
|
+
return pageSearcher;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const initSearch = async () => {
|
|
84
|
+
if (initStatus !== 'initial') {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const searcher = createSearcher();
|
|
88
|
+
setSearchError(undefined);
|
|
89
|
+
setInitStatus('initing');
|
|
90
|
+
try {
|
|
91
|
+
await searcher.init();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (pageSearcherRef.current !== searcher) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
setSearchError(error instanceof Error ? error.message : String(error));
|
|
97
|
+
setInitStatus('error');
|
|
98
|
+
setIsSearching(false);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (pageSearcherRef.current !== searcher) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setInitStatus('inited');
|
|
105
|
+
const currentQuery = searchInputRef.current?.value;
|
|
106
|
+
if (currentQuery) {
|
|
107
|
+
const matched = await searcher.match(currentQuery);
|
|
108
|
+
if (
|
|
109
|
+
pageSearcherRef.current !== searcher ||
|
|
110
|
+
searchInputRef.current?.value !== currentQuery
|
|
111
|
+
) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
setSearchResult(matched || DEFAULT_RESULT);
|
|
115
|
+
setIsSearching(false);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!searchEnabled) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (focused) {
|
|
124
|
+
setSearchResult(DEFAULT_RESULT);
|
|
125
|
+
initSearch();
|
|
126
|
+
} else {
|
|
127
|
+
setQuery('');
|
|
128
|
+
}
|
|
129
|
+
}, [focused, searchEnabled]);
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!searchEnabled) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
136
|
+
const isLangChanged = lang !== currentLang;
|
|
137
|
+
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
138
|
+
if (isLangChanged || isVersionChanged) {
|
|
139
|
+
setInitStatus('initial');
|
|
140
|
+
setSearchError(undefined);
|
|
141
|
+
setIsSearching(false);
|
|
142
|
+
pageSearcherRef.current = null;
|
|
143
|
+
createSearcher()
|
|
144
|
+
.fetchSearchIndex()
|
|
145
|
+
.catch(() => {});
|
|
146
|
+
}
|
|
147
|
+
}, [lang, version, versionedSearch, searchEnabled]);
|
|
148
|
+
|
|
149
|
+
const handleQueryChangedImpl = async (value: string) => {
|
|
150
|
+
let newQuery = value;
|
|
151
|
+
setQuery(newQuery);
|
|
152
|
+
if (!newQuery) {
|
|
153
|
+
setIsSearching(false);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const result: MatchResult = [];
|
|
157
|
+
if (userSearchHooks.beforeSearch) {
|
|
158
|
+
const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
|
|
159
|
+
if (transformedQuery) newQuery = transformedQuery;
|
|
160
|
+
}
|
|
161
|
+
const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
|
|
162
|
+
if (defaultSearchResult) result.push(...defaultSearchResult);
|
|
163
|
+
if (userSearchHooks.onSearch) {
|
|
164
|
+
const customSearchResult = await userSearchHooks.onSearch(
|
|
165
|
+
newQuery,
|
|
166
|
+
result as DefaultMatchResult[],
|
|
167
|
+
);
|
|
168
|
+
if (customSearchResult) {
|
|
169
|
+
result.push(
|
|
170
|
+
...customSearchResult.map(
|
|
171
|
+
item =>
|
|
172
|
+
({ renderType: RenderType.Custom, ...item }) as CustomMatchResult,
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (userSearchHooks.afterSearch) {
|
|
178
|
+
await userSearchHooks.afterSearch(newQuery, result);
|
|
179
|
+
}
|
|
180
|
+
if (searchInputRef.current?.value === newQuery) {
|
|
181
|
+
setCurrentSuggestionIndex(0);
|
|
182
|
+
setSearchResult(result || DEFAULT_RESULT);
|
|
183
|
+
setIsSearching(false);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
188
|
+
const handleQueryInput = (value: string) => {
|
|
189
|
+
setIsSearching(Boolean(value));
|
|
190
|
+
handleQueryChange(value);
|
|
191
|
+
};
|
|
192
|
+
const clearQuery = () => {
|
|
193
|
+
setQuery('');
|
|
194
|
+
setIsSearching(false);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
searchEnabled,
|
|
199
|
+
clearQuery,
|
|
200
|
+
currentRenderType:
|
|
201
|
+
searchResult[resultTabIndex]?.renderType ?? RenderType.Default,
|
|
202
|
+
currentSuggestions:
|
|
203
|
+
(searchResult[resultTabIndex]?.result as DefaultMatchResult['result']) ??
|
|
204
|
+
[],
|
|
205
|
+
handleQueryInput,
|
|
206
|
+
initStatus,
|
|
207
|
+
isSearching,
|
|
208
|
+
resultTabIndex,
|
|
209
|
+
searchError,
|
|
210
|
+
searchIndexURL,
|
|
211
|
+
searchResult,
|
|
212
|
+
query,
|
|
213
|
+
currentSuggestionIndex,
|
|
214
|
+
setCurrentSuggestionIndex,
|
|
215
|
+
setResultTabIndex,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SocialLink as ISocialLink } from '@rspress/core';
|
|
2
|
-
import
|
|
2
|
+
import { socialLinks } from '@rspress/core/runtime';
|
|
3
3
|
import './index.scss';
|
|
4
4
|
import { GithubStars } from './GithubStars';
|
|
5
5
|
import { useHoverGroup } from '../HoverGroup/useHoverGroup';
|
|
@@ -18,7 +18,7 @@ export const SocialLink = (props: SocialLinkProps) => {
|
|
|
18
18
|
|
|
19
19
|
let IconComp: React.ReactElement = <></>;
|
|
20
20
|
if (icon) {
|
|
21
|
-
const html = typeof icon === 'string' ?
|
|
21
|
+
const html = typeof icon === 'string' ? socialLinks[icon] : icon.svg;
|
|
22
22
|
IconComp = (
|
|
23
23
|
<div
|
|
24
24
|
className="rp-social-links__icon"
|
|
@@ -11,7 +11,7 @@ export function SourceCode(props: SourceCodeProps) {
|
|
|
11
11
|
const { href, platform = 'github' } = props;
|
|
12
12
|
const t = useI18n();
|
|
13
13
|
return (
|
|
14
|
-
<div className="rp-not-doc rp-source-code">
|
|
14
|
+
<div className="rp-not-doc rp-source-code rp-toc-exclude">
|
|
15
15
|
<a href={href} target="_blank" className="rp-source-code__link">
|
|
16
16
|
<span className="rp-source-code__icon">
|
|
17
17
|
{
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, it } from '@rstest/core';
|
|
2
|
+
import { getClipPath } from './getClipPath';
|
|
3
|
+
|
|
4
|
+
describe('getClipPath', () => {
|
|
5
|
+
it('uses percentages relative to the view transition snapshot', () => {
|
|
6
|
+
expect(
|
|
7
|
+
getClipPath({
|
|
8
|
+
height: 600,
|
|
9
|
+
width: 800,
|
|
10
|
+
x: 800,
|
|
11
|
+
y: 0,
|
|
12
|
+
}),
|
|
13
|
+
).toEqual(['circle(0% at 100% 0%)', 'circle(160% at 100% 0%)']);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type ClipPathOptions = {
|
|
2
|
+
height: number;
|
|
3
|
+
width: number;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const roundPercentage = (value: number) => Math.round(value * 1e6) / 1e6;
|
|
9
|
+
|
|
10
|
+
export const getClipPath = ({ height, width, x, y }: ClipPathOptions) => {
|
|
11
|
+
const endRadius = Math.hypot(
|
|
12
|
+
Math.max(x, width - x + 200),
|
|
13
|
+
Math.max(y, height - y + 200),
|
|
14
|
+
);
|
|
15
|
+
const normalizedDiagonal = Math.hypot(width, height) / Math.SQRT2;
|
|
16
|
+
const xPercentage = roundPercentage((x / width) * 100);
|
|
17
|
+
const yPercentage = roundPercentage((y / height) * 100);
|
|
18
|
+
const endRadiusPercentage = roundPercentage(
|
|
19
|
+
(endRadius / normalizedDiagonal) * 100,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return [
|
|
23
|
+
`circle(0% at ${xPercentage}% ${yPercentage}%)`,
|
|
24
|
+
`circle(${endRadiusPercentage}% at ${xPercentage}% ${yPercentage}%)`,
|
|
25
|
+
];
|
|
26
|
+
};
|
|
@@ -4,6 +4,7 @@ import { type MouseEvent, useContext } from 'react';
|
|
|
4
4
|
import './global.scss';
|
|
5
5
|
import './index.scss';
|
|
6
6
|
import { flushSync } from 'react-dom';
|
|
7
|
+
import { getClipPath } from './getClipPath';
|
|
7
8
|
|
|
8
9
|
const supportAppearanceTransition = () => {
|
|
9
10
|
return (
|
|
@@ -36,11 +37,6 @@ export function SwitchAppearance({ onClick }: { onClick?: () => void }) {
|
|
|
36
37
|
const x = event.clientX;
|
|
37
38
|
const y = event.clientY;
|
|
38
39
|
|
|
39
|
-
const endRadius = Math.hypot(
|
|
40
|
-
Math.max(x, innerWidth - x + 200),
|
|
41
|
-
Math.max(y, innerHeight - y + 200),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
40
|
const dispose = removeClipViewTransition();
|
|
45
41
|
const transition = document.startViewTransition(async () => {
|
|
46
42
|
flushSync(() => {
|
|
@@ -49,30 +45,30 @@ export function SwitchAppearance({ onClick }: { onClick?: () => void }) {
|
|
|
49
45
|
});
|
|
50
46
|
});
|
|
51
47
|
|
|
52
|
-
const clipPath =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const clipPath = getClipPath({
|
|
49
|
+
height: innerHeight,
|
|
50
|
+
width: innerWidth,
|
|
51
|
+
x,
|
|
52
|
+
y,
|
|
53
|
+
});
|
|
56
54
|
transition.ready.then(() => {
|
|
57
|
-
document.documentElement
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
document.documentElement.animate(
|
|
56
|
+
{
|
|
57
|
+
clipPath: isDark ? [...clipPath].reverse() : clipPath,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
duration: 400,
|
|
61
|
+
easing: 'ease-in',
|
|
62
|
+
fill: 'both',
|
|
63
|
+
pseudoElement: isDark
|
|
64
|
+
? '::view-transition-old(root)'
|
|
65
|
+
: '::view-transition-new(root)',
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.finished.then(() => {
|
|
73
|
-
dispose();
|
|
74
|
-
});
|
|
67
|
+
id: '',
|
|
68
|
+
},
|
|
69
|
+
);
|
|
75
70
|
});
|
|
71
|
+
transition.finished.then(dispose, dispose);
|
|
76
72
|
} else {
|
|
77
73
|
setTheme(nextTheme);
|
|
78
74
|
onClick?.();
|
|
@@ -116,6 +116,20 @@ export const Tabs = forwardRef(
|
|
|
116
116
|
return getTabValuesFromChildren(children, values);
|
|
117
117
|
}, [children, values]);
|
|
118
118
|
|
|
119
|
+
const defaultValueIndex =
|
|
120
|
+
defaultValue !== undefined
|
|
121
|
+
? tabValues.findIndex(item => item.value === defaultValue)
|
|
122
|
+
: -1;
|
|
123
|
+
const initialActiveIndex =
|
|
124
|
+
defaultValueIndex === -1 ? (defaultIndex ?? 0) : defaultValueIndex;
|
|
125
|
+
|
|
126
|
+
const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
|
|
127
|
+
|
|
128
|
+
const [storageIndex, setStorageIndex] = useStorageValue<string>(
|
|
129
|
+
`${groupIdPrefix}${groupId}`,
|
|
130
|
+
initialActiveIndex.toString(),
|
|
131
|
+
);
|
|
132
|
+
|
|
119
133
|
if (import.meta.env.SSG_MD) {
|
|
120
134
|
return (
|
|
121
135
|
<>
|
|
@@ -132,20 +146,6 @@ export const Tabs = forwardRef(
|
|
|
132
146
|
);
|
|
133
147
|
}
|
|
134
148
|
|
|
135
|
-
const defaultValueIndex =
|
|
136
|
-
defaultValue !== undefined
|
|
137
|
-
? tabValues.findIndex(item => item.value === defaultValue)
|
|
138
|
-
: -1;
|
|
139
|
-
const initialActiveIndex =
|
|
140
|
-
defaultValueIndex === -1 ? (defaultIndex ?? 0) : defaultValueIndex;
|
|
141
|
-
|
|
142
|
-
const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
|
|
143
|
-
|
|
144
|
-
const [storageIndex, setStorageIndex] = useStorageValue<string>(
|
|
145
|
-
`${groupIdPrefix}${groupId}`,
|
|
146
|
-
initialActiveIndex.toString(),
|
|
147
|
-
);
|
|
148
|
-
|
|
149
149
|
const currentIndex: number = groupId ? Number(storageIndex) : activeIndex;
|
|
150
150
|
|
|
151
151
|
return (
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { PluginDriver } from "./node/PluginDriver.js";
|
|
2
|
-
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase, withSiteOrigin } from "./
|
|
2
|
+
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase, withSiteOrigin } from "./t2~0.js";
|
|
3
3
|
export { RouteService } from "./node/route/RouteService.js";
|
|
4
4
|
export { build } from "./node/build.js";
|
|
5
5
|
export { defineConfig } from "./config/defineConfig.js";
|
|
@@ -4,9 +4,9 @@ type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages
|
|
|
4
4
|
export declare class PluginDriver {
|
|
5
5
|
#private;
|
|
6
6
|
haveNavSidebarConfig: boolean;
|
|
7
|
+
static create(config: UserConfig, isProd: boolean): Promise<PluginDriver>;
|
|
7
8
|
static create(config: UserConfig, configFilePath: string, isProd: boolean): Promise<PluginDriver>;
|
|
8
9
|
private constructor();
|
|
9
|
-
getConfigFilePath(): string;
|
|
10
10
|
init(): Promise<void>;
|
|
11
11
|
addPlugin(plugin: RspressPlugin): void;
|
|
12
12
|
getPlugins(): RspressPlugin[];
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { addTrailingSlash, node_path, addLeadingSlash } from "../
|
|
1
|
+
import { addTrailingSlash, node_path, addLeadingSlash } from "../a~0.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
|
|
4
4
|
class PluginDriver {
|
|
5
5
|
#config;
|
|
6
|
-
#configFilePath;
|
|
7
6
|
#plugins;
|
|
8
7
|
#isProd;
|
|
9
8
|
haveNavSidebarConfig = false;
|
|
10
|
-
static async create(config,
|
|
11
|
-
|
|
9
|
+
static async create(config, configFilePathOrIsProd, isProd = false) {
|
|
10
|
+
if ('boolean' == typeof configFilePathOrIsProd) isProd = configFilePathOrIsProd;
|
|
11
|
+
const pluginDriver = new PluginDriver(config, isProd);
|
|
12
12
|
await pluginDriver.init();
|
|
13
13
|
return pluginDriver;
|
|
14
14
|
}
|
|
15
|
-
constructor(config,
|
|
15
|
+
constructor(config, isProd){
|
|
16
16
|
this.#config = config;
|
|
17
|
-
this.#configFilePath = configFilePath;
|
|
18
17
|
this.#isProd = isProd;
|
|
19
18
|
this.#plugins = [];
|
|
20
19
|
}
|
|
21
|
-
getConfigFilePath() {
|
|
22
|
-
return this.#configFilePath;
|
|
23
|
-
}
|
|
24
20
|
async init() {
|
|
25
21
|
this.clearPlugins();
|
|
26
22
|
const config = this.#config;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../
|
|
1
|
+
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../a~0.js";
|
|
2
2
|
import { processLocales, combineWalkResult } from "./locales.js";
|
|
3
3
|
import { walk } from "./walk.js";
|
|
4
4
|
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../../
|
|
3
|
-
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../
|
|
1
|
+
import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
|
|
2
|
+
import "../../t~0.js";
|
|
3
|
+
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../a~0.js";
|
|
4
4
|
import { createError } from "../utils/error.js";
|
|
5
5
|
import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
|
|
6
6
|
import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
|
|
7
7
|
import { RouteService } from "../route/RouteService.js";
|
|
8
|
-
const picocolors =
|
|
9
|
-
var picocolors_default = /*#__PURE__*/
|
|
8
|
+
const picocolors = rspackRequire("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
9
|
+
var picocolors_default = /*#__PURE__*/ compatGetDefaultExport(picocolors);
|
|
10
10
|
const AUTO_NAV_SIDEBAR_ERROR_PREFIX = '[auto-nav-sidebar] ';
|
|
11
11
|
function getFileKey(realPath, docsDir) {
|
|
12
12
|
return realPath ? slash(external_node_path_relative(docsDir, realPath).replace(extname(realPath), '')) : '';
|
|
@@ -168,7 +168,7 @@ async function metaDirItemToSidebarItem(metaItem, workDir, docsDir, extensions,
|
|
|
168
168
|
context: metaJsonContext,
|
|
169
169
|
_fileKey: getFileKey(dirAbsolutePath, docsDir)
|
|
170
170
|
};
|
|
171
|
-
{
|
|
171
|
+
else {
|
|
172
172
|
const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions, mdFileSet);
|
|
173
173
|
if (!indexFile) return {
|
|
174
174
|
text: label || name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../
|
|
1
|
+
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../a~0.js";
|
|
2
2
|
import { createError } from "../utils/error.js";
|
|
3
3
|
async function pathExists(path) {
|
|
4
4
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isExternalUrl, node_path, promises } from "../../
|
|
1
|
+
import { isExternalUrl, node_path, promises } from "../../a~0.js";
|
|
2
2
|
import { pathExists } from "../utils/fs.js";
|
|
3
3
|
import { readJson } from "./utils.js";
|
|
4
4
|
import { addRoutePrefix } from "../route/RoutePage.js";
|
package/dist/node/build.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { LoadConfigResult } from '@rsbuild/core';
|
|
1
2
|
import type { UserConfig } from '@rspress/shared';
|
|
2
3
|
interface BuildOptions {
|
|
3
4
|
docDirectory: string;
|
|
4
|
-
config: UserConfig
|
|
5
|
-
configFilePath
|
|
5
|
+
config: UserConfig | LoadConfigResult<UserConfig>;
|
|
6
|
+
configFilePath?: string;
|
|
6
7
|
}
|
|
7
8
|
export declare function build(options: BuildOptions): Promise<void>;
|
|
8
9
|
export {};
|
package/dist/node/build.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeConfigResult } from "../config/loadConfigFile.js";
|
|
1
2
|
import { PluginDriver } from "./PluginDriver.js";
|
|
2
3
|
import { RouteService } from "./route/RouteService.js";
|
|
3
4
|
import { modifyConfigWithAutoNavSide } from "./auto-nav-sidebar/index.js";
|
|
@@ -5,8 +6,10 @@ import { initRsbuild } from "./initRsbuild.js";
|
|
|
5
6
|
import { checkLanguageParity } from "./utils/checkLanguageParity.js";
|
|
6
7
|
import { hintSSGFalse } from "./logger/hint.js";
|
|
7
8
|
async function build(options) {
|
|
8
|
-
const { docDirectory
|
|
9
|
-
const
|
|
9
|
+
const { docDirectory } = options;
|
|
10
|
+
const configResult = normalizeConfigResult(options.config, options.configFilePath);
|
|
11
|
+
const { content: config } = configResult;
|
|
12
|
+
const pluginDriver = await PluginDriver.create(configResult.content, true);
|
|
10
13
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
11
14
|
const enableSSG = Boolean((modifiedConfig.ssg || modifiedConfig.llms) ?? true);
|
|
12
15
|
const additionalPages = await pluginDriver.addPages();
|
|
@@ -20,7 +23,10 @@ async function build(options) {
|
|
|
20
23
|
await modifyConfigWithAutoNavSide(modifiedConfig);
|
|
21
24
|
try {
|
|
22
25
|
await pluginDriver.beforeBuild();
|
|
23
|
-
const rsbuild = await initRsbuild(docDirectory,
|
|
26
|
+
const rsbuild = await initRsbuild(docDirectory, {
|
|
27
|
+
...configResult,
|
|
28
|
+
content: modifiedConfig
|
|
29
|
+
}, pluginDriver, routeService, enableSSG);
|
|
24
30
|
await rsbuild.build();
|
|
25
31
|
} finally{
|
|
26
32
|
await checkLanguageParity(config);
|
package/dist/node/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../
|
|
1
|
+
import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../b~0.js";
|
|
2
2
|
const constants_require = createRequire(import.meta.url);
|
|
3
3
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
4
4
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
package/dist/node/dev.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { RestartFn, RsbuildConfig } from '@rsbuild/core';
|
|
1
|
+
import type { LoadConfigResult, RestartFn, RsbuildConfig } from '@rsbuild/core';
|
|
2
2
|
import type { UserConfig } from '@rspress/shared';
|
|
3
3
|
interface ServerInstance {
|
|
4
4
|
close: () => Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
interface DevOptions {
|
|
7
|
-
appDirectory
|
|
7
|
+
appDirectory?: string;
|
|
8
8
|
docDirectory: string;
|
|
9
|
-
config: UserConfig
|
|
10
|
-
configFilePath
|
|
9
|
+
config: UserConfig | LoadConfigResult<UserConfig>;
|
|
10
|
+
configFilePath?: string;
|
|
11
11
|
extraBuilderConfig?: RsbuildConfig;
|
|
12
12
|
restart?: RestartFn;
|
|
13
13
|
}
|
package/dist/node/dev.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { normalizeConfigResult } from "../config/loadConfigFile.js";
|
|
1
2
|
import { PluginDriver } from "./PluginDriver.js";
|
|
2
3
|
import { RouteService } from "./route/RouteService.js";
|
|
3
4
|
import { initRsbuild } from "./initRsbuild.js";
|
|
4
5
|
import { checkLanguageParity } from "./utils/checkLanguageParity.js";
|
|
5
6
|
async function dev(options) {
|
|
6
|
-
const { docDirectory,
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const pluginDriver = await PluginDriver.create(config, configFilePath, isProd);
|
|
7
|
+
const { docDirectory, extraBuilderConfig, restart } = options;
|
|
8
|
+
const configResult = normalizeConfigResult(options.config, options.configFilePath);
|
|
9
|
+
const pluginDriver = await PluginDriver.create(configResult.content, false);
|
|
10
10
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
11
11
|
try {
|
|
12
12
|
const additionalPages = await pluginDriver.addPages();
|
|
@@ -18,8 +18,10 @@ async function dev(options) {
|
|
|
18
18
|
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
19
19
|
await pluginDriver.routeServiceGenerated(routeService);
|
|
20
20
|
await pluginDriver.beforeBuild();
|
|
21
|
-
const rsbuild = await initRsbuild(docDirectory,
|
|
22
|
-
|
|
21
|
+
const rsbuild = await initRsbuild(docDirectory, {
|
|
22
|
+
...configResult,
|
|
23
|
+
content: modifiedConfig
|
|
24
|
+
}, pluginDriver, routeService, false, {
|
|
23
25
|
extraRsbuildConfig: extraBuilderConfig,
|
|
24
26
|
restart
|
|
25
27
|
});
|
package/dist/node/eject.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
3
|
-
import { node_path, logger, promises } from "../
|
|
1
|
+
import { rspackRequire, compatGetDefaultExport } from "../rslib-runtime~0.js";
|
|
2
|
+
import "../t~0.js";
|
|
3
|
+
import { node_path, logger, promises } from "../a~0.js";
|
|
4
4
|
import { EJECTED_THEME } from "./constants.js";
|
|
5
|
-
const picocolors =
|
|
6
|
-
var picocolors_default = /*#__PURE__*/
|
|
5
|
+
const picocolors = rspackRequire("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
6
|
+
var picocolors_default = /*#__PURE__*/ compatGetDefaultExport(picocolors);
|
|
7
7
|
let _themeComponentsPathOverride;
|
|
8
8
|
function getThemeComponentsPath() {
|
|
9
9
|
if (_themeComponentsPathOverride) return _themeComponentsPathOverride;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { RestartFn, RsbuildConfig, RsbuildInstance } from '@rsbuild/core';
|
|
1
|
+
import type { LoadConfigResult, RestartFn, RsbuildConfig, RsbuildInstance } from '@rsbuild/core';
|
|
2
2
|
import { type UserConfig } from '@rspress/shared';
|
|
3
3
|
import type { PluginDriver } from './PluginDriver.js';
|
|
4
4
|
import type { RouteService } from './route/RouteService.js';
|
|
5
|
-
export declare function initRsbuild(rootDir: string,
|
|
6
|
-
configFileMeta?: RsbuildConfig['_privateMeta'];
|
|
5
|
+
export declare function initRsbuild(rootDir: string, configResult: LoadConfigResult<UserConfig>, pluginDriver: PluginDriver, routeService: RouteService, enableSSG: boolean, options?: {
|
|
7
6
|
extraRsbuildConfig?: RsbuildConfig;
|
|
8
7
|
restart?: RestartFn;
|
|
9
8
|
}): Promise<RsbuildInstance>;
|