@rspress/core 0.0.13 → 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.
Files changed (39) hide show
  1. package/dist/index.js +90 -50
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +3 -0
  4. package/dist/loader.js +28 -72
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.d.ts +8 -0
  7. package/dist/runtime/App.js +1 -0
  8. package/dist/runtime/Content.d.ts +6 -0
  9. package/dist/runtime/Content.js +7 -2
  10. package/dist/runtime/NoSSR.d.ts +4 -0
  11. package/dist/runtime/clientEntry.d.ts +1 -0
  12. package/dist/runtime/hooks.d.ts +29 -0
  13. package/dist/runtime/hooks.js +23 -1
  14. package/dist/runtime/index.d.ts +6 -0
  15. package/dist/runtime/ssrEntry.d.ts +6 -0
  16. package/dist/runtime/tsconfig.json +9 -0
  17. package/dist/runtime/utils.d.ts +6 -0
  18. package/dist/theme/bundle.css +94 -53
  19. package/dist/theme/bundle.d.ts +12 -1
  20. package/dist/theme/bundle.js +527 -489
  21. package/dist/theme/bundle.js.map +1 -1
  22. package/package.json +14 -14
  23. package/src/runtime/App.tsx +1 -0
  24. package/src/runtime/Content.tsx +11 -2
  25. package/src/runtime/global.d.ts +49 -0
  26. package/src/runtime/hooks.ts +47 -1
  27. package/src/runtime/tsconfig.json +9 -0
  28. package/src/theme-default/components/LocalSideBar/{index.module.scss → index.scss} +6 -5
  29. package/src/theme-default/components/LocalSideBar/index.tsx +4 -4
  30. package/src/theme-default/components/Nav/index.tsx +19 -5
  31. package/src/theme-default/components/Search/SearchPanel.tsx +339 -0
  32. package/src/theme-default/components/Search/index.tsx +6 -326
  33. package/src/theme-default/index.ts +3 -1
  34. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +8 -23
  35. package/src/theme-default/layout/DocLayout/index.module.scss +52 -3
  36. package/src/theme-default/layout/DocLayout/index.tsx +9 -7
  37. package/src/theme-default/logic/index.ts +1 -0
  38. package/src/theme-default/logic/useAppearance.ts +0 -1
  39. package/src/theme-default/logic/usePathUtils.ts +72 -0
@@ -0,0 +1,8 @@
1
+ import { PageData } from '@rspress/shared';
2
+ import 'virtual-global-styles';
3
+ export declare function initPageData(routePath: string): Promise<PageData>;
4
+ export declare function App({
5
+ helmetContext
6
+ }: {
7
+ helmetContext?: object;
8
+ }): JSX.Element;
@@ -59,6 +59,7 @@ export async function initPageData(routePath) {
59
59
  frontmatter: {},
60
60
  title: "404",
61
61
  toc: [],
62
+ version: "",
62
63
  _filepath: "",
63
64
  _relativePath: ""
64
65
  }
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ export declare const Content: ({
3
+ fallback
4
+ }: {
5
+ fallback?: ReactNode;
6
+ }) => any;
@@ -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 routesElement;
19
+ return element;
15
20
  }
16
21
  return /* @__PURE__ */ _jsx(Suspense, {
17
22
  fallback,
18
- children: routesElement
23
+ children: element
19
24
  });
20
25
  };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function NoSSR(props: {
3
+ children: React.ReactNode;
4
+ }): JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function renderInBrowser(): Promise<void>;
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ import { PageData } from '@rspress/shared';
3
+ declare global {
4
+ interface Window {
5
+ __MODERN_PAGE_DATA__: any;
6
+ }
7
+ }
8
+ interface IDataContext {
9
+ data: PageData;
10
+ setData?: (data: PageData) => void;
11
+ }
12
+ interface IThemeContext {
13
+ theme: 'light' | 'dark';
14
+ setTheme?: (theme: 'light' | 'dark') => void;
15
+ }
16
+ export declare const DataContext: import("react").Context<IDataContext>;
17
+ export declare const ThemeContext: import("react").Context<IThemeContext>;
18
+ export declare function usePageData(): PageData;
19
+ export declare function useLang(): string;
20
+ export declare function useVersion(): string;
21
+ export declare function useDark(): boolean;
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;
29
+ export {};
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ export * from './hooks';
2
+ export * from './Content';
3
+ export { normalizeHref, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from './utils';
4
+ export { useLocation, useNavigate } from 'react-router-dom';
5
+ export { Helmet } from 'react-helmet-async';
6
+ export { NoSSR } from './NoSSR';
@@ -0,0 +1,6 @@
1
+ import { PageData } from '@rspress/shared';
2
+ export declare function render(pagePath: string, helmetContext: object): Promise<{
3
+ appHtml: string;
4
+ pageData: PageData;
5
+ }>;
6
+ export { routes } from 'virtual-routes-ssr';
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": ".",
4
+ "baseUrl": ".",
5
+ "skipLibCheck": true,
6
+ "jsx": "react-jsx"
7
+ },
8
+ "include": ["./**/*"]
9
+ }
@@ -0,0 +1,6 @@
1
+ import { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeHref } from '@rspress/shared';
2
+ export declare function normalizeRoutePath(routePath: string): string;
3
+ export declare function withBase(url?: string): string;
4
+ export declare function removeBase(url: string): string;
5
+ export declare function isEqualPath(a: string, b: string): boolean;
6
+ export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeHref };
@@ -1623,8 +1623,8 @@ button:focus-visible {
1623
1623
  background-color: var(--rp-c-bg-mute);
1624
1624
  }
1625
1625
 
1626
- /* src/theme-default/components/LocalSideBar/index.module.scss?css_virtual&hash=8ee65aa6fc817c893cd6d70fa6feed70 */
1627
- .localNav_dce60 {
1626
+ /* src/theme-default/components/LocalSideBar/index.scss */
1627
+ .rspress-sidebar-menu {
1628
1628
  position: sticky;
1629
1629
  top: 0;
1630
1630
  left: 0;
@@ -1638,22 +1638,22 @@ button:focus-visible {
1638
1638
  background-color: var(--rp-c-bg);
1639
1639
  padding-left: 10px;
1640
1640
  }
1641
- .localNav_dce60 .menu_dce60 {
1641
+ .rspress-sidebar-menu > button {
1642
1642
  padding: 12px;
1643
1643
  transition: color 0.5s;
1644
1644
  }
1645
- .localNav_dce60 .menu_dce60:hover {
1645
+ .rspress-sidebar-menu > button:hover {
1646
1646
  color: var(--rp-c-text-3);
1647
1647
  }
1648
1648
  @media (min-width: 960px) {
1649
- .localNav_dce60 {
1649
+ .rspress-sidebar-menu {
1650
1650
  display: none;
1651
1651
  }
1652
- .backDrop_dce60 {
1652
+ .rspress-sidebar-back-drop {
1653
1653
  display: none;
1654
1654
  }
1655
1655
  }
1656
- .backDrop_dce60 {
1656
+ .rspress-sidebar-back-drop {
1657
1657
  position: fixed;
1658
1658
  top: 0;
1659
1659
  right: 0;
@@ -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=fc1722758dddfc71c5344b874e8f6553 */
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;
@@ -1828,7 +1866,8 @@ button:focus-visible {
1828
1866
  width: calc(100% - var(--rp-sidebar-width));
1829
1867
  padding: 48px 48px 72px 0;
1830
1868
  }
1831
- .content_feeda .rspress-doc {
1869
+ .content_feeda .rspress-doc,
1870
+ .content_feeda .rspress-doc-footer {
1832
1871
  width: 100%;
1833
1872
  }
1834
1873
  .aside-container_feeda {
@@ -1843,7 +1882,8 @@ button:focus-visible {
1843
1882
  .content_feeda {
1844
1883
  padding: 48px 0 72px 0;
1845
1884
  }
1846
- .content_feeda .rspress-doc {
1885
+ .content_feeda .rspress-doc,
1886
+ .content_feeda .rspress-doc-footer {
1847
1887
  padding: 0 48px;
1848
1888
  box-sizing: content-box;
1849
1889
  width: calc(100vw - var(--rp-aside-width) - var(--rp-sidebar-width));
@@ -1854,7 +1894,8 @@ button:focus-visible {
1854
1894
  width: 100%;
1855
1895
  margin-left: 0;
1856
1896
  }
1857
- .content_feeda .rspress-doc {
1897
+ .content_feeda .rspress-doc,
1898
+ .content_feeda .rspress-doc-footer {
1858
1899
  box-sizing: content-box;
1859
1900
  width: calc(100vw - var(--rp-sidebar-width) - var(--rp-aside-width));
1860
1901
  padding: 0 max(48px, (100vw - var(--rp-sidebar-width) - var(--rp-aside-width) - 960px) / 2);
@@ -2297,48 +2338,6 @@ button:focus-visible {
2297
2338
  transform: translateX(4px);
2298
2339
  }
2299
2340
 
2300
- /* src/theme-default/components/Tabs/index.module.scss?css_virtual&hash=8fca224caa73cde9adc275a3199ef4ac */
2301
- .container_7e0fb {
2302
- background-color: var(--rp-code-block-bg);
2303
- contain: content;
2304
- border-radius: 16px;
2305
- }
2306
- .container_7e0fb div[class*=language-] {
2307
- margin: 6px 0;
2308
- }
2309
- .container_7e0fb div[class*=language-] code {
2310
- background-color: var(--rp-c-bg);
2311
- }
2312
- .tab-list_7e0fb {
2313
- padding-left: 8px;
2314
- padding-top: 4px;
2315
- display: flex;
2316
- min-width: 100%;
2317
- background-color: var(--rp-code-title-bg);
2318
- }
2319
- .tab_7e0fb {
2320
- color: var(--rp-c-text-2);
2321
- border-bottom: 1px solid transparent;
2322
- box-sizing: border-box;
2323
- margin-right: 10px;
2324
- padding: 6px 12px;
2325
- margin-bottom: -1px;
2326
- user-select: none;
2327
- transition: all 0.2s ease-in-out;
2328
- cursor: pointer;
2329
- }
2330
- .tab_7e0fb:last-child {
2331
- margin-right: 0;
2332
- }
2333
- .not-selected_7e0fb:hover {
2334
- color: var(--rp-c-text-1);
2335
- border-color: var(--rp-c-gray);
2336
- }
2337
- .selected_7e0fb {
2338
- color: var(--rp-c-brand-dark);
2339
- border-color: var(--rp-c-brand-dark);
2340
- }
2341
-
2342
2341
  /* src/theme-default/components/Search/index.module.scss?css_virtual&hash=19f728cc293dbb1f87fb5f4deca962a4 */
2343
2342
  .mask_f619e {
2344
2343
  position: fixed;
@@ -2551,6 +2550,48 @@ button:focus-visible {
2551
2550
  }
2552
2551
  }
2553
2552
 
2553
+ /* src/theme-default/components/Tabs/index.module.scss?css_virtual&hash=8fca224caa73cde9adc275a3199ef4ac */
2554
+ .container_7e0fb {
2555
+ background-color: var(--rp-code-block-bg);
2556
+ contain: content;
2557
+ border-radius: 16px;
2558
+ }
2559
+ .container_7e0fb div[class*=language-] {
2560
+ margin: 6px 0;
2561
+ }
2562
+ .container_7e0fb div[class*=language-] code {
2563
+ background-color: var(--rp-c-bg);
2564
+ }
2565
+ .tab-list_7e0fb {
2566
+ padding-left: 8px;
2567
+ padding-top: 4px;
2568
+ display: flex;
2569
+ min-width: 100%;
2570
+ background-color: var(--rp-code-title-bg);
2571
+ }
2572
+ .tab_7e0fb {
2573
+ color: var(--rp-c-text-2);
2574
+ border-bottom: 1px solid transparent;
2575
+ box-sizing: border-box;
2576
+ margin-right: 10px;
2577
+ padding: 6px 12px;
2578
+ margin-bottom: -1px;
2579
+ user-select: none;
2580
+ transition: all 0.2s ease-in-out;
2581
+ cursor: pointer;
2582
+ }
2583
+ .tab_7e0fb:last-child {
2584
+ margin-right: 0;
2585
+ }
2586
+ .not-selected_7e0fb:hover {
2587
+ color: var(--rp-c-text-1);
2588
+ border-color: var(--rp-c-gray);
2589
+ }
2590
+ .selected_7e0fb {
2591
+ color: var(--rp-c-brand-dark);
2592
+ border-color: var(--rp-c-brand-dark);
2593
+ }
2594
+
2554
2595
  /* src/theme-default/components/Toc/index.css */
2555
2596
  .toc-link {
2556
2597
  padding-bottom: 1px;
@@ -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 | {
@@ -62,6 +67,12 @@ declare function getLogoUrl(rawLogo: string | {
62
67
  }, theme: 'dark' | 'light'): string;
63
68
  declare function isMobileDevice(): boolean;
64
69
 
70
+ interface SearchPanelProps {
71
+ focused: boolean;
72
+ setFocused: (focused: boolean) => void;
73
+ }
74
+ declare function SearchPanel({ focused, setFocused }: SearchPanelProps): JSX.Element;
75
+
65
76
  declare function Search(): JSX.Element;
66
77
 
67
78
  type TabItem = {
@@ -158,4 +169,4 @@ declare const _default: {
158
169
  setup: typeof setup;
159
170
  };
160
171
 
161
- export { Button, HomeFooter, Link, Nav, PackageManagerTabs, Search, 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 };