@docusaurus/theme-common 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.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/Details.d.ts +14 -0
- package/lib/components/Collapsible/index.d.ts +64 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +150 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +17 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +76 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +62 -0
- package/lib/contexts/announcementBar.d.ts +22 -0
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +30 -31
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/contexts/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.js +28 -0
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +31 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +130 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
- package/lib/contexts/tabGroupChoice.d.ts +21 -0
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/contexts/tabGroupChoice.js +49 -0
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/{utils/usePrevious.d.ts → hooks/styles.css} +4 -1
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +41 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +17 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +60 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +39 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +12 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +20 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +13 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +21 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +25 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +43 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/hooks/useTOCHighlight.js +130 -0
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +28 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +59 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +38 -10
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +38 -9
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +47 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +45 -4
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +63 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +159 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +91 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +217 -1
- package/lib/utils/docsUtils.js.map +1 -0
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +11 -1
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +9 -5
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +17 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +38 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +70 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +36 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +42 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +64 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +12 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +18 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +26 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +54 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +83 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +200 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +13 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +37 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +15 -7
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +55 -22
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +18 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +36 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +36 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +84 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +21 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +9 -4
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +13 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +19 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +9 -6
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +17 -11
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +12 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +36 -37
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +56 -25
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +4 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +28 -13
- package/src/components/Collapsible/index.tsx +263 -0
- package/src/components/Details/index.tsx +109 -0
- package/src/components/Details/styles.module.css +62 -0
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +43 -39
- package/src/contexts/colorMode.tsx +198 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +251 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/contexts/tabGroupChoice.tsx +85 -0
- package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +75 -0
- package/src/hooks/useKeyboardNavigation.ts +45 -0
- package/src/hooks/useLockBodyScroll.ts +21 -0
- package/src/hooks/usePrismTheme.ts +24 -0
- package/src/hooks/useSearchPage.ts +79 -0
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/hooks/useTOCHighlight.ts +189 -0
- package/src/hooks/useWindowSize.ts +72 -0
- package/src/index.ts +130 -19
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +51 -5
- package/src/utils/codeBlockUtils.ts +241 -2
- package/src/utils/docsUtils.tsx +334 -0
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +9 -5
- package/src/utils/historyUtils.ts +45 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +76 -0
- package/src/utils/regexpUtils.ts +24 -0
- package/src/utils/routesUtils.ts +75 -0
- package/src/utils/scrollUtils.tsx +304 -0
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +56 -23
- package/src/utils/tagsUtils.ts +50 -0
- package/src/utils/tocUtils.ts +119 -0
- package/src/utils/useAlternatePageUtils.ts +19 -6
- package/src/utils/useLocalPathname.ts +22 -0
- package/src/utils/useLocationChange.ts +24 -20
- package/src/utils/usePluralForm.ts +50 -38
- package/src/utils/useThemeConfig.ts +55 -27
- package/lib/.tsbuildinfo +0 -1
- package/lib/utils/announcementBarUtils.d.ts +0 -17
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/pathUtils.js +0 -13
- package/lib/utils/usePrevious.js +0 -14
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
- package/src/utils/docsUtils.ts +0 -11
- package/src/utils/pathUtils.ts +0 -17
- package/src/utils/usePrevious.ts +0 -18
- package/tsconfig.json +0 -10
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { PrismTheme } from 'prism-react-renderer';
|
|
8
|
+
import type { DeepPartial } from 'utility-types';
|
|
9
|
+
import type { MagicCommentConfig } from './codeBlockUtils';
|
|
3
10
|
export declare type DocsVersionPersistence = 'localStorage' | 'none';
|
|
4
11
|
export declare type NavbarItem = {
|
|
5
12
|
type?: string | undefined;
|
|
6
13
|
items?: NavbarItem[];
|
|
7
14
|
label?: string;
|
|
8
15
|
position?: 'left' | 'right';
|
|
16
|
+
} & {
|
|
17
|
+
[key: string]: unknown;
|
|
9
18
|
};
|
|
10
19
|
export declare type NavbarLogo = {
|
|
11
20
|
src: string;
|
|
12
21
|
srcDark?: string;
|
|
22
|
+
width?: string | number;
|
|
23
|
+
height?: string | number;
|
|
13
24
|
href?: string;
|
|
14
25
|
target?: string;
|
|
15
26
|
alt?: string;
|
|
16
27
|
};
|
|
17
28
|
export declare type Navbar = {
|
|
18
|
-
style
|
|
29
|
+
style?: 'dark' | 'primary';
|
|
19
30
|
hideOnScroll: boolean;
|
|
20
31
|
title?: string;
|
|
21
32
|
items: NavbarItem[];
|
|
@@ -25,12 +36,6 @@ export declare type ColorModeConfig = {
|
|
|
25
36
|
defaultMode: 'light' | 'dark';
|
|
26
37
|
disableSwitch: boolean;
|
|
27
38
|
respectPrefersColorScheme: boolean;
|
|
28
|
-
switchConfig: {
|
|
29
|
-
darkIcon: string;
|
|
30
|
-
darkIconStyle: CSSProperties;
|
|
31
|
-
lightIcon: string;
|
|
32
|
-
lightIconStyle: CSSProperties;
|
|
33
|
-
};
|
|
34
39
|
};
|
|
35
40
|
export declare type AnnouncementBarConfig = {
|
|
36
41
|
id: string;
|
|
@@ -40,10 +45,11 @@ export declare type AnnouncementBarConfig = {
|
|
|
40
45
|
isCloseable: boolean;
|
|
41
46
|
};
|
|
42
47
|
export declare type PrismConfig = {
|
|
43
|
-
theme
|
|
48
|
+
theme: PrismTheme;
|
|
44
49
|
darkTheme?: PrismTheme;
|
|
45
50
|
defaultLanguage?: string;
|
|
46
|
-
additionalLanguages
|
|
51
|
+
additionalLanguages: string[];
|
|
52
|
+
magicComments: MagicCommentConfig[];
|
|
47
53
|
};
|
|
48
54
|
export declare type FooterLinkItem = {
|
|
49
55
|
label?: string;
|
|
@@ -51,33 +57,58 @@ export declare type FooterLinkItem = {
|
|
|
51
57
|
href?: string;
|
|
52
58
|
html?: string;
|
|
53
59
|
prependBaseUrlToHref?: string;
|
|
60
|
+
} & {
|
|
61
|
+
[key: string]: unknown;
|
|
54
62
|
};
|
|
55
|
-
export declare type
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
export declare type FooterLogo = {
|
|
64
|
+
alt?: string;
|
|
65
|
+
src: string;
|
|
66
|
+
srcDark?: string;
|
|
67
|
+
width?: string | number;
|
|
68
|
+
height?: string | number;
|
|
69
|
+
href?: string;
|
|
58
70
|
};
|
|
59
|
-
export declare type
|
|
71
|
+
export declare type FooterBase = {
|
|
60
72
|
style: 'light' | 'dark';
|
|
61
|
-
logo?:
|
|
62
|
-
alt?: string;
|
|
63
|
-
src?: string;
|
|
64
|
-
srcDark?: string;
|
|
65
|
-
href?: string;
|
|
66
|
-
};
|
|
73
|
+
logo?: FooterLogo;
|
|
67
74
|
copyright?: string;
|
|
68
|
-
|
|
75
|
+
};
|
|
76
|
+
export declare type MultiColumnFooter = FooterBase & {
|
|
77
|
+
links: {
|
|
78
|
+
title: string | null;
|
|
79
|
+
items: FooterLinkItem[];
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
export declare type SimpleFooter = FooterBase & {
|
|
83
|
+
links: FooterLinkItem[];
|
|
84
|
+
};
|
|
85
|
+
export declare type Footer = MultiColumnFooter | SimpleFooter;
|
|
86
|
+
export declare type TableOfContents = {
|
|
87
|
+
minHeadingLevel: number;
|
|
88
|
+
maxHeadingLevel: number;
|
|
69
89
|
};
|
|
70
90
|
export declare type ThemeConfig = {
|
|
71
91
|
docs: {
|
|
72
92
|
versionPersistence: DocsVersionPersistence;
|
|
93
|
+
sidebar: {
|
|
94
|
+
hideable: boolean;
|
|
95
|
+
autoCollapseCategories: boolean;
|
|
96
|
+
};
|
|
73
97
|
};
|
|
74
98
|
navbar: Navbar;
|
|
75
99
|
colorMode: ColorModeConfig;
|
|
76
100
|
announcementBar?: AnnouncementBarConfig;
|
|
77
101
|
prism: PrismConfig;
|
|
78
102
|
footer?: Footer;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
image?: string;
|
|
104
|
+
metadata: {
|
|
105
|
+
[key: string]: string;
|
|
106
|
+
}[];
|
|
107
|
+
tableOfContents: TableOfContents;
|
|
82
108
|
};
|
|
109
|
+
export declare type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
110
|
+
/**
|
|
111
|
+
* A convenient/more semantic way to get theme config from context.
|
|
112
|
+
*/
|
|
83
113
|
export declare function useThemeConfig(): ThemeConfig;
|
|
114
|
+
//# sourceMappingURL=useThemeConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"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"}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
+
/**
|
|
9
|
+
* A convenient/more semantic way to get theme config from context.
|
|
10
|
+
*/
|
|
8
11
|
export function useThemeConfig() {
|
|
9
12
|
return useDocusaurusContext().siteConfig.themeConfig;
|
|
10
13
|
}
|
|
14
|
+
//# sourceMappingURL=useThemeConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemeConfig.js","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AA6HpE;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,oBAAoB,EAAE,CAAC,UAAU,CAAC,WAA0B,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"lib/components/Details/*",
|
|
9
|
+
"*.css"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./lib/index.js",
|
|
13
|
+
"./Details": "./lib/components/Details/index.js"
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"watch": "
|
|
16
|
+
"build": "tsc && node ../../admin/scripts/copyUntypedFiles.js",
|
|
17
|
+
"watch": "run-p -c copy:watch build:watch",
|
|
18
|
+
"build:watch": "tsc --watch",
|
|
19
|
+
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
10
20
|
},
|
|
11
21
|
"publishConfig": {
|
|
12
22
|
"access": "public"
|
|
@@ -18,23 +28,28 @@
|
|
|
18
28
|
},
|
|
19
29
|
"license": "MIT",
|
|
20
30
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"@docusaurus/plugin-content-blog": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/plugin-content-docs": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/plugin-content-pages": "2.0.0-beta.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
31
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
32
|
+
"@docusaurus/plugin-content-blog": "2.0.0-beta.21",
|
|
33
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.21",
|
|
34
|
+
"@docusaurus/plugin-content-pages": "2.0.0-beta.21",
|
|
35
|
+
"clsx": "^1.1.1",
|
|
36
|
+
"parse-numeric-range": "^1.3.0",
|
|
37
|
+
"prism-react-renderer": "^1.3.3",
|
|
38
|
+
"tslib": "^2.4.0",
|
|
39
|
+
"utility-types": "^3.10.0"
|
|
27
40
|
},
|
|
28
41
|
"devDependencies": {
|
|
29
|
-
"@docusaurus/
|
|
42
|
+
"@docusaurus/core": "2.0.0-beta.21",
|
|
43
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
44
|
+
"fs-extra": "^10.1.0",
|
|
45
|
+
"lodash": "^4.17.21"
|
|
30
46
|
},
|
|
31
47
|
"peerDependencies": {
|
|
32
|
-
"prism-react-renderer": "^1.2.1",
|
|
33
48
|
"react": "^16.8.4 || ^17.0.0",
|
|
34
49
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
35
50
|
},
|
|
36
51
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
52
|
+
"node": ">=16.14"
|
|
38
53
|
},
|
|
39
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
|
|
40
55
|
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, {
|
|
9
|
+
useState,
|
|
10
|
+
useEffect,
|
|
11
|
+
useRef,
|
|
12
|
+
useCallback,
|
|
13
|
+
useLayoutEffect,
|
|
14
|
+
type RefObject,
|
|
15
|
+
type Dispatch,
|
|
16
|
+
type SetStateAction,
|
|
17
|
+
type ReactNode,
|
|
18
|
+
} from 'react';
|
|
19
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
20
|
+
|
|
21
|
+
const DefaultAnimationEasing = 'ease-in-out';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This hook is a very thin wrapper around a `useState`.
|
|
25
|
+
*/
|
|
26
|
+
export function useCollapsible({
|
|
27
|
+
initialState,
|
|
28
|
+
}: {
|
|
29
|
+
/** The initial state. Will be non-collapsed by default. */
|
|
30
|
+
initialState?: boolean | (() => boolean);
|
|
31
|
+
}): {
|
|
32
|
+
collapsed: boolean;
|
|
33
|
+
setCollapsed: Dispatch<SetStateAction<boolean>>;
|
|
34
|
+
toggleCollapsed: () => void;
|
|
35
|
+
} {
|
|
36
|
+
const [collapsed, setCollapsed] = useState(initialState ?? false);
|
|
37
|
+
|
|
38
|
+
const toggleCollapsed = useCallback(() => {
|
|
39
|
+
setCollapsed((expanded) => !expanded);
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
collapsed,
|
|
44
|
+
setCollapsed,
|
|
45
|
+
toggleCollapsed,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const CollapsedStyles = {
|
|
50
|
+
display: 'none',
|
|
51
|
+
overflow: 'hidden',
|
|
52
|
+
height: '0px',
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
const ExpandedStyles = {
|
|
56
|
+
display: 'block',
|
|
57
|
+
overflow: 'visible',
|
|
58
|
+
height: 'auto',
|
|
59
|
+
} as const;
|
|
60
|
+
|
|
61
|
+
function applyCollapsedStyle(el: HTMLElement, collapsed: boolean) {
|
|
62
|
+
const collapsedStyles = collapsed ? CollapsedStyles : ExpandedStyles;
|
|
63
|
+
el.style.display = collapsedStyles.display;
|
|
64
|
+
el.style.overflow = collapsedStyles.overflow;
|
|
65
|
+
el.style.height = collapsedStyles.height;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
Lex111: Dynamic transition duration is used in Material design, this technique
|
|
70
|
+
is good for a large number of items.
|
|
71
|
+
https://material.io/archive/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
|
|
72
|
+
https://github.com/mui-org/material-ui/blob/e724d98eba018e55e1a684236a2037e24bcf050c/packages/material-ui/src/styles/createTransitions.js#L40-L43
|
|
73
|
+
*/
|
|
74
|
+
function getAutoHeightDuration(height: number) {
|
|
75
|
+
const constant = height / 36;
|
|
76
|
+
return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type CollapsibleAnimationConfig = {
|
|
80
|
+
duration?: number;
|
|
81
|
+
easing?: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function useCollapseAnimation({
|
|
85
|
+
collapsibleRef,
|
|
86
|
+
collapsed,
|
|
87
|
+
animation,
|
|
88
|
+
}: {
|
|
89
|
+
collapsibleRef: RefObject<HTMLElement>;
|
|
90
|
+
collapsed: boolean;
|
|
91
|
+
animation?: CollapsibleAnimationConfig;
|
|
92
|
+
}) {
|
|
93
|
+
const mounted = useRef(false);
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const el = collapsibleRef.current!;
|
|
97
|
+
|
|
98
|
+
function getTransitionStyles() {
|
|
99
|
+
const height = el.scrollHeight;
|
|
100
|
+
const duration = animation?.duration ?? getAutoHeightDuration(height);
|
|
101
|
+
const easing = animation?.easing ?? DefaultAnimationEasing;
|
|
102
|
+
return {
|
|
103
|
+
transition: `height ${duration}ms ${easing}`,
|
|
104
|
+
height: `${height}px`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function applyTransitionStyles() {
|
|
109
|
+
const transitionStyles = getTransitionStyles();
|
|
110
|
+
el.style.transition = transitionStyles.transition;
|
|
111
|
+
el.style.height = transitionStyles.height;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// On mount, we just apply styles, no animated transition
|
|
115
|
+
if (!mounted.current) {
|
|
116
|
+
applyCollapsedStyle(el, collapsed);
|
|
117
|
+
mounted.current = true;
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
el.style.willChange = 'height';
|
|
122
|
+
|
|
123
|
+
function startAnimation() {
|
|
124
|
+
const animationFrame = requestAnimationFrame(() => {
|
|
125
|
+
// When collapsing
|
|
126
|
+
if (collapsed) {
|
|
127
|
+
applyTransitionStyles();
|
|
128
|
+
|
|
129
|
+
requestAnimationFrame(() => {
|
|
130
|
+
el.style.height = CollapsedStyles.height;
|
|
131
|
+
el.style.overflow = CollapsedStyles.overflow;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// When expanding
|
|
135
|
+
else {
|
|
136
|
+
el.style.display = 'block';
|
|
137
|
+
requestAnimationFrame(() => {
|
|
138
|
+
applyTransitionStyles();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return () => cancelAnimationFrame(animationFrame);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return startAnimation();
|
|
147
|
+
}, [collapsibleRef, collapsed, animation]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type CollapsibleElementType = React.ElementType<
|
|
151
|
+
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Prevent hydration layout shift before animations are handled imperatively
|
|
156
|
+
* with JS
|
|
157
|
+
*/
|
|
158
|
+
function getSSRStyle(collapsed: boolean) {
|
|
159
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
return collapsed ? CollapsedStyles : ExpandedStyles;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type CollapsibleBaseProps = {
|
|
166
|
+
/** The actual DOM element to be used in the markup. */
|
|
167
|
+
as?: CollapsibleElementType;
|
|
168
|
+
/** Initial collapsed state. */
|
|
169
|
+
collapsed: boolean;
|
|
170
|
+
children: ReactNode;
|
|
171
|
+
/** Configuration of animation, like `duration` and `easing` */
|
|
172
|
+
animation?: CollapsibleAnimationConfig;
|
|
173
|
+
/**
|
|
174
|
+
* A callback fired when the collapse transition animation ends. Receives
|
|
175
|
+
* the **new** collapsed state: e.g. when
|
|
176
|
+
* expanding, `collapsed` will be `false`. You can use this for some "cleanup"
|
|
177
|
+
* like applying new styles when the container is fully expanded.
|
|
178
|
+
*/
|
|
179
|
+
onCollapseTransitionEnd?: (collapsed: boolean) => void;
|
|
180
|
+
/** Class name for the underlying DOM element. */
|
|
181
|
+
className?: string;
|
|
182
|
+
/**
|
|
183
|
+
* This is mostly useful for details/summary component where ssrStyle is not
|
|
184
|
+
* needed (as details are hidden natively) and can mess up with the browser's
|
|
185
|
+
* native behavior when JS fails to load or is disabled
|
|
186
|
+
*/
|
|
187
|
+
disableSSRStyle?: boolean;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
function CollapsibleBase({
|
|
191
|
+
as: As = 'div',
|
|
192
|
+
collapsed,
|
|
193
|
+
children,
|
|
194
|
+
animation,
|
|
195
|
+
onCollapseTransitionEnd,
|
|
196
|
+
className,
|
|
197
|
+
disableSSRStyle,
|
|
198
|
+
}: CollapsibleBaseProps) {
|
|
199
|
+
const collapsibleRef = useRef<HTMLElement>(null);
|
|
200
|
+
|
|
201
|
+
useCollapseAnimation({collapsibleRef, collapsed, animation});
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<As
|
|
205
|
+
// @ts-expect-error: the "too complicated type" is produced from
|
|
206
|
+
// "CollapsibleElementType" being a huge union
|
|
207
|
+
ref={collapsibleRef as RefObject<never>} // Refs are contravariant, which is not expressible in TS
|
|
208
|
+
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
|
209
|
+
onTransitionEnd={(e: React.TransitionEvent) => {
|
|
210
|
+
if (e.propertyName !== 'height') {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
applyCollapsedStyle(collapsibleRef.current!, collapsed);
|
|
215
|
+
onCollapseTransitionEnd?.(collapsed);
|
|
216
|
+
}}
|
|
217
|
+
className={className}>
|
|
218
|
+
{children}
|
|
219
|
+
</As>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
224
|
+
const [mounted, setMounted] = useState(!collapsed);
|
|
225
|
+
// Updated in effect so that first expansion transition can work
|
|
226
|
+
const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
|
|
227
|
+
|
|
228
|
+
useLayoutEffect(() => {
|
|
229
|
+
if (!collapsed) {
|
|
230
|
+
setMounted(true);
|
|
231
|
+
}
|
|
232
|
+
}, [collapsed]);
|
|
233
|
+
|
|
234
|
+
useLayoutEffect(() => {
|
|
235
|
+
if (mounted) {
|
|
236
|
+
setLazyCollapsed(collapsed);
|
|
237
|
+
}
|
|
238
|
+
}, [mounted, collapsed]);
|
|
239
|
+
|
|
240
|
+
return mounted ? (
|
|
241
|
+
<CollapsibleBase {...props} collapsed={lazyCollapsed} />
|
|
242
|
+
) : null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
type CollapsibleProps = CollapsibleBaseProps & {
|
|
246
|
+
/**
|
|
247
|
+
* Delay rendering of the content till first expansion. Marked as required to
|
|
248
|
+
* force us to think if content should be server-rendered or not. This has
|
|
249
|
+
* perf impact since it reduces html file sizes, but could undermine SEO.
|
|
250
|
+
* @see https://github.com/facebook/docusaurus/issues/4753
|
|
251
|
+
*/
|
|
252
|
+
lazy: boolean;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A headless component providing smooth and uniform collapsing behavior. The
|
|
257
|
+
* component will be invisible (zero height) when collapsed. Doesn't provide
|
|
258
|
+
* interactivity by itself: collapse state is toggled through props.
|
|
259
|
+
*/
|
|
260
|
+
export function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
|
|
261
|
+
const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
|
|
262
|
+
return <Comp {...props} />;
|
|
263
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, {
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
type ComponentProps,
|
|
12
|
+
type ReactElement,
|
|
13
|
+
} from 'react';
|
|
14
|
+
import clsx from 'clsx';
|
|
15
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
16
|
+
import {useCollapsible, Collapsible} from '../Collapsible';
|
|
17
|
+
import styles from './styles.module.css';
|
|
18
|
+
|
|
19
|
+
function isInSummary(node: HTMLElement | null): boolean {
|
|
20
|
+
if (!node) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return node.tagName === 'SUMMARY' || isInSummary(node.parentElement);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean {
|
|
27
|
+
if (!node) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return node === parent || hasParent(node.parentElement, parent);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type DetailsProps = {
|
|
34
|
+
/** Summary is provided as props, including the wrapping `<summary>` tag */
|
|
35
|
+
summary?: ReactElement;
|
|
36
|
+
} & ComponentProps<'details'>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A mostly un-styled `<details>` element with smooth collapsing. Provides some
|
|
40
|
+
* very lightweight styles, but you should bring your UI.
|
|
41
|
+
*/
|
|
42
|
+
export function Details({
|
|
43
|
+
summary,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}: DetailsProps): JSX.Element {
|
|
47
|
+
const isBrowser = useIsBrowser();
|
|
48
|
+
const detailsRef = useRef<HTMLDetailsElement>(null);
|
|
49
|
+
|
|
50
|
+
const {collapsed, setCollapsed} = useCollapsible({
|
|
51
|
+
initialState: !props.open,
|
|
52
|
+
});
|
|
53
|
+
// Use a separate state for the actual details prop, because it must be set
|
|
54
|
+
// only after animation completes, otherwise close animations won't work
|
|
55
|
+
const [open, setOpen] = useState(props.open);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
|
59
|
+
<details
|
|
60
|
+
{...props}
|
|
61
|
+
ref={detailsRef}
|
|
62
|
+
open={open}
|
|
63
|
+
data-collapsed={collapsed}
|
|
64
|
+
className={clsx(
|
|
65
|
+
styles.details,
|
|
66
|
+
isBrowser && styles.isBrowser,
|
|
67
|
+
props.className,
|
|
68
|
+
)}
|
|
69
|
+
onMouseDown={(e) => {
|
|
70
|
+
const target = e.target as HTMLElement;
|
|
71
|
+
// Prevent a double-click to highlight summary text
|
|
72
|
+
if (isInSummary(target) && e.detail > 1) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
onClick={(e) => {
|
|
77
|
+
e.stopPropagation(); // For isolation of multiple nested details/summary
|
|
78
|
+
const target = e.target as HTMLElement;
|
|
79
|
+
const shouldToggle =
|
|
80
|
+
isInSummary(target) && hasParent(target, detailsRef.current!);
|
|
81
|
+
if (!shouldToggle) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
if (collapsed) {
|
|
86
|
+
setCollapsed(false);
|
|
87
|
+
setOpen(true);
|
|
88
|
+
} else {
|
|
89
|
+
setCollapsed(true);
|
|
90
|
+
// Don't do this, it breaks close animation!
|
|
91
|
+
// setOpen(false);
|
|
92
|
+
}
|
|
93
|
+
}}>
|
|
94
|
+
{/* eslint-disable-next-line @docusaurus/no-untranslated-text */}
|
|
95
|
+
{summary ?? <summary>Details</summary>}
|
|
96
|
+
|
|
97
|
+
<Collapsible
|
|
98
|
+
lazy={false} // Content might matter for SEO in this case
|
|
99
|
+
collapsed={collapsed}
|
|
100
|
+
disableSSRStyle // Allows component to work fine even with JS disabled!
|
|
101
|
+
onCollapseTransitionEnd={(newCollapsed) => {
|
|
102
|
+
setCollapsed(newCollapsed);
|
|
103
|
+
setOpen(!newCollapsed);
|
|
104
|
+
}}>
|
|
105
|
+
<div className={styles.collapsibleContent}>{children}</div>
|
|
106
|
+
</Collapsible>
|
|
107
|
+
</details>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
CSS variables, meant to be overridden by final theme
|
|
10
|
+
*/
|
|
11
|
+
.details {
|
|
12
|
+
--docusaurus-details-summary-arrow-size: 0.38rem;
|
|
13
|
+
--docusaurus-details-transition: transform 200ms ease;
|
|
14
|
+
--docusaurus-details-decoration-color: grey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.details > summary {
|
|
18
|
+
position: relative;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
list-style: none;
|
|
21
|
+
padding-left: 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* TODO: deprecation, need to remove this after Safari will support `::marker` */
|
|
25
|
+
.details > summary::-webkit-details-marker {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.details > summary::before {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 0.45rem;
|
|
32
|
+
left: 0;
|
|
33
|
+
|
|
34
|
+
/* CSS-only Arrow */
|
|
35
|
+
content: '';
|
|
36
|
+
border-width: var(--docusaurus-details-summary-arrow-size);
|
|
37
|
+
border-style: solid;
|
|
38
|
+
border-color: transparent transparent transparent
|
|
39
|
+
var(--docusaurus-details-decoration-color);
|
|
40
|
+
|
|
41
|
+
/* Arrow rotation anim */
|
|
42
|
+
transform: rotate(0deg);
|
|
43
|
+
transition: var(--docusaurus-details-transition);
|
|
44
|
+
transform-origin: calc(var(--docusaurus-details-summary-arrow-size) / 2) 50%;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* When JS disabled/failed to load: we use the open property for arrow animation: */
|
|
48
|
+
.details[open]:not(.isBrowser) > summary::before,
|
|
49
|
+
/* When JS works: we use the data-attribute for arrow animation */
|
|
50
|
+
.details[data-collapsed='false'].isBrowser > summary::before {
|
|
51
|
+
transform: rotate(90deg);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.collapsibleContent {
|
|
55
|
+
margin-top: 1rem;
|
|
56
|
+
border-top: 1px solid var(--docusaurus-details-decoration-color);
|
|
57
|
+
padding-top: 1rem;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.collapsibleContent > *:last-child {
|
|
61
|
+
margin-bottom: 0;
|
|
62
|
+
}
|