@rspress/core 0.1.1 → 0.2.0
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/index.js +57 -24
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -0
- package/dist/loader.js +5 -24
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +1 -0
- package/dist/runtime/Content.js +7 -2
- package/dist/runtime/hooks.d.ts +7 -0
- package/dist/runtime/hooks.js +23 -1
- package/dist/theme/bundle.css +39 -1
- package/dist/theme/bundle.d.ts +6 -1
- package/dist/theme/bundle.js +119 -69
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +7 -7
- package/src/runtime/App.tsx +1 -0
- package/src/runtime/Content.tsx +11 -2
- package/src/runtime/hooks.ts +47 -1
- package/src/theme-default/components/Nav/index.tsx +19 -5
- package/src/theme-default/index.ts +2 -0
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +8 -23
- package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
- package/src/theme-default/logic/index.ts +1 -0
- package/src/theme-default/logic/usePathUtils.ts +72 -0
package/dist/runtime/App.js
CHANGED
package/dist/runtime/Content.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import { Suspense } from "react";
|
|
3
3
|
import { matchRoutes, useLocation } from "react-router-dom";
|
|
4
4
|
import { normalizeRoutePath } from "./utils";
|
|
5
|
+
import { usePageData, useViewTransition } from "./hooks";
|
|
5
6
|
const { routes } = process.env.__SSR__ ? require("virtual-routes-ssr") : require("virtual-routes");
|
|
6
7
|
export const Content = ({ fallback = /* @__PURE__ */ _jsx(_Fragment, {}) }) => {
|
|
7
8
|
const { pathname } = useLocation();
|
|
@@ -10,11 +11,15 @@ export const Content = ({ fallback = /* @__PURE__ */ _jsx(_Fragment, {}) }) => {
|
|
|
10
11
|
return /* @__PURE__ */ _jsx("div", {});
|
|
11
12
|
}
|
|
12
13
|
const routesElement = matched[0].route.element;
|
|
14
|
+
let element = routesElement;
|
|
15
|
+
if (usePageData().siteData.themeConfig.enableContentAnimation) {
|
|
16
|
+
element = useViewTransition(routesElement);
|
|
17
|
+
}
|
|
13
18
|
if (!process.env.__IS_REACT_18__ && process.env.__SSR__) {
|
|
14
|
-
return
|
|
19
|
+
return element;
|
|
15
20
|
}
|
|
16
21
|
return /* @__PURE__ */ _jsx(Suspense, {
|
|
17
22
|
fallback,
|
|
18
|
-
children:
|
|
23
|
+
children: element
|
|
19
24
|
});
|
|
20
25
|
};
|
package/dist/runtime/hooks.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare const DataContext: import("react").Context<IDataContext>;
|
|
|
17
17
|
export declare const ThemeContext: import("react").Context<IThemeContext>;
|
|
18
18
|
export declare function usePageData(): PageData;
|
|
19
19
|
export declare function useLang(): string;
|
|
20
|
+
export declare function useVersion(): string;
|
|
20
21
|
export declare function useDark(): boolean;
|
|
21
22
|
export declare function useI18n<T = Record<string, Record<string, string>>>(): (key: keyof T) => any;
|
|
23
|
+
declare global {
|
|
24
|
+
interface Document {
|
|
25
|
+
startViewTransition: (callback: () => void) => void;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export declare function useViewTransition(dom: any): any;
|
|
22
29
|
export {};
|
package/dist/runtime/hooks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createContext, useContext } from "react";
|
|
1
|
+
import { createContext, useContext, useLayoutEffect, useState } from "react";
|
|
2
2
|
import i18nTextData from "virtual-i18n-text";
|
|
3
|
+
import { flushSync } from "react-dom";
|
|
3
4
|
export const DataContext = createContext({});
|
|
4
5
|
export const ThemeContext = createContext({});
|
|
5
6
|
export function usePageData() {
|
|
@@ -10,6 +11,10 @@ export function useLang() {
|
|
|
10
11
|
const ctx = useContext(DataContext);
|
|
11
12
|
return ctx.data.page.lang || "";
|
|
12
13
|
}
|
|
14
|
+
export function useVersion() {
|
|
15
|
+
const ctx = useContext(DataContext);
|
|
16
|
+
return ctx.data.page.version || "";
|
|
17
|
+
}
|
|
13
18
|
export function useDark() {
|
|
14
19
|
const ctx = useContext(ThemeContext);
|
|
15
20
|
return ctx.theme === "dark";
|
|
@@ -18,3 +23,20 @@ export function useI18n() {
|
|
|
18
23
|
const lang = useLang();
|
|
19
24
|
return (key) => i18nTextData[key][lang];
|
|
20
25
|
}
|
|
26
|
+
export function useViewTransition(dom) {
|
|
27
|
+
const [element, setElement] = useState(dom);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (document.startViewTransition) {
|
|
30
|
+
document.startViewTransition(() => {
|
|
31
|
+
flushSync(() => {
|
|
32
|
+
setElement(dom);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
setElement(dom);
|
|
37
|
+
}
|
|
38
|
+
}, [
|
|
39
|
+
dom
|
|
40
|
+
]);
|
|
41
|
+
return element;
|
|
42
|
+
}
|
package/dist/theme/bundle.css
CHANGED
|
@@ -1795,7 +1795,7 @@ button:focus-visible {
|
|
|
1795
1795
|
}
|
|
1796
1796
|
}
|
|
1797
1797
|
|
|
1798
|
-
/* src/theme-default/layout/DocLayout/index.module.scss?css_virtual&hash=
|
|
1798
|
+
/* src/theme-default/layout/DocLayout/index.module.scss?css_virtual&hash=25669c7207a2c741ceb395341c44f545 */
|
|
1799
1799
|
.aside-container_feeda {
|
|
1800
1800
|
position: sticky;
|
|
1801
1801
|
display: none;
|
|
@@ -1810,6 +1810,44 @@ button:focus-visible {
|
|
|
1810
1810
|
.aside-container_feeda::-webkit-scrollbar {
|
|
1811
1811
|
display: none;
|
|
1812
1812
|
}
|
|
1813
|
+
.rspress-doc {
|
|
1814
|
+
min-height: 60vh;
|
|
1815
|
+
view-transition-name: flip;
|
|
1816
|
+
}
|
|
1817
|
+
* {
|
|
1818
|
+
view-transition-name: none;
|
|
1819
|
+
}
|
|
1820
|
+
@keyframes fade-out_feeda {
|
|
1821
|
+
from {
|
|
1822
|
+
opacity: 1;
|
|
1823
|
+
}
|
|
1824
|
+
to {
|
|
1825
|
+
opacity: 0;
|
|
1826
|
+
transform: translateY(20px);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
@keyframes fade-in_feeda {
|
|
1830
|
+
from {
|
|
1831
|
+
opacity: 0;
|
|
1832
|
+
transform: translateY(20px);
|
|
1833
|
+
}
|
|
1834
|
+
to {
|
|
1835
|
+
opacity: 1;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
::view-transition-old(flip),
|
|
1839
|
+
::view-transition-new(flip) {
|
|
1840
|
+
animation-time: 250ms;
|
|
1841
|
+
}
|
|
1842
|
+
::view-transition-old(flip) {
|
|
1843
|
+
animation-name: fade-out_feeda;
|
|
1844
|
+
transition-timing-function: cubic-bezier(0, 0, 0.58, 1);
|
|
1845
|
+
}
|
|
1846
|
+
::view-transition-new(flip) {
|
|
1847
|
+
animation-name: fade-in_feeda;
|
|
1848
|
+
animation-delay: 180ms;
|
|
1849
|
+
transition-timing-function: cubic-bezier(0.42, 0, 1, 1);
|
|
1850
|
+
}
|
|
1813
1851
|
@media (max-width: 960px) {
|
|
1814
1852
|
.docLayout_feeda {
|
|
1815
1853
|
position: relative;
|
package/dist/theme/bundle.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ type LayoutProps = {
|
|
|
29
29
|
top?: react__default.ReactNode;
|
|
30
30
|
bottom?: react__default.ReactNode;
|
|
31
31
|
} & DocLayoutProps & HomeLayoutProps & NavProps;
|
|
32
|
+
declare const Layout: react__default.FC<LayoutProps>;
|
|
32
33
|
|
|
33
34
|
declare function NotFoundLayout(): JSX.Element;
|
|
34
35
|
|
|
@@ -54,6 +55,10 @@ declare function scrollToTarget(target: HTMLElement, isSmooth: boolean): void;
|
|
|
54
55
|
declare function bindingAsideScroll(): () => void;
|
|
55
56
|
declare function setup(): void;
|
|
56
57
|
|
|
58
|
+
declare function usePathUtils(): {
|
|
59
|
+
normalizeLinkHref: (rawHref: string) => string;
|
|
60
|
+
};
|
|
61
|
+
|
|
57
62
|
declare function isActive(currentPath: string, targetLink?: string, strict?: boolean): boolean;
|
|
58
63
|
declare function isExternalHref(href: string): boolean;
|
|
59
64
|
declare function getLogoUrl(rawLogo: string | {
|
|
@@ -164,4 +169,4 @@ declare const _default: {
|
|
|
164
169
|
setup: typeof setup;
|
|
165
170
|
};
|
|
166
171
|
|
|
167
|
-
export { Button, HomeFooter, Link, Nav, PackageManagerTabs, Search, SearchPanel, Tab, Tabs, Toc, bindingAsideScroll, _default as default, getCustomMDXComponent, getLogoUrl, isActive, isExternalHref, isMobileDevice, scrollToTarget, setup, useEditLink, useLocaleSiteData, usePrevNextPage, useSidebarData };
|
|
172
|
+
export { Button, HomeFooter, HomeLayout, Layout, Link, Nav, NotFoundLayout, PackageManagerTabs, Search, SearchPanel, Tab, Tabs, Toc, bindingAsideScroll, _default as default, getCustomMDXComponent, getLogoUrl, isActive, isExternalHref, isMobileDevice, scrollToTarget, setup, useEditLink, useLocaleSiteData, usePathUtils, usePrevNextPage, useSidebarData };
|