@azerion/bunosaurus-theme-common 0.0.0-stage → 4.0.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 (261) hide show
  1. package/README.md +2 -2
  2. package/lib/components/Collapsible/index.d.ts +59 -0
  3. package/lib/components/Collapsible/index.d.ts.map +1 -0
  4. package/lib/components/Collapsible/index.js +145 -0
  5. package/lib/components/Collapsible/index.js.map +1 -0
  6. package/lib/components/Details/index.d.ts +20 -0
  7. package/lib/components/Details/index.d.ts.map +1 -0
  8. package/lib/components/Details/index.js +86 -0
  9. package/lib/components/Details/index.js.map +1 -0
  10. package/lib/components/Details/styles.module.css +66 -0
  11. package/lib/components/ThemedComponent/index.d.ts +31 -0
  12. package/lib/components/ThemedComponent/index.d.ts.map +1 -0
  13. package/lib/components/ThemedComponent/index.js +47 -0
  14. package/lib/components/ThemedComponent/index.js.map +1 -0
  15. package/lib/components/ThemedComponent/styles.module.css +26 -0
  16. package/lib/contexts/announcementBar.d.ts +21 -0
  17. package/lib/contexts/announcementBar.d.ts.map +1 -0
  18. package/lib/contexts/announcementBar.js +72 -0
  19. package/lib/contexts/announcementBar.js.map +1 -0
  20. package/lib/contexts/colorMode.d.ts +23 -0
  21. package/lib/contexts/colorMode.d.ts.map +1 -0
  22. package/lib/contexts/colorMode.js +163 -0
  23. package/lib/contexts/colorMode.js.map +1 -0
  24. package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
  25. package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
  26. package/lib/contexts/navbarMobileSidebar.js +65 -0
  27. package/lib/contexts/navbarMobileSidebar.js.map +1 -0
  28. package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
  29. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
  30. package/lib/contexts/navbarSecondaryMenu/content.js +50 -0
  31. package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
  32. package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
  33. package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
  34. package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
  35. package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
  36. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  37. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  38. package/lib/hooks/useBackToTopButton.js +50 -0
  39. package/lib/hooks/useBackToTopButton.js.map +1 -0
  40. package/lib/hooks/useCodeWordWrap.d.ts +15 -0
  41. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  42. package/lib/hooks/useCodeWordWrap.js +67 -0
  43. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  44. package/lib/hooks/useHideableNavbar.d.ts +17 -0
  45. package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
  46. package/lib/hooks/useHideableNavbar.js +65 -0
  47. package/lib/hooks/useHideableNavbar.js.map +1 -0
  48. package/lib/hooks/useLockBodyScroll.d.ts +12 -0
  49. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
  50. package/lib/hooks/useLockBodyScroll.js +20 -0
  51. package/lib/hooks/useLockBodyScroll.js.map +1 -0
  52. package/lib/hooks/useMutationObserver.d.ts +4 -0
  53. package/lib/hooks/useMutationObserver.d.ts.map +1 -0
  54. package/lib/hooks/useMutationObserver.js +29 -0
  55. package/lib/hooks/useMutationObserver.js.map +1 -0
  56. package/lib/hooks/usePrismTheme.d.ts +13 -0
  57. package/lib/hooks/usePrismTheme.d.ts.map +1 -0
  58. package/lib/hooks/usePrismTheme.js +21 -0
  59. package/lib/hooks/usePrismTheme.js.map +1 -0
  60. package/lib/hooks/useTOCHighlight.d.ts +25 -0
  61. package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
  62. package/lib/hooks/useTOCHighlight.js +130 -0
  63. package/lib/hooks/useTOCHighlight.js.map +1 -0
  64. package/lib/hooks/useWindowSize.d.ts +27 -0
  65. package/lib/hooks/useWindowSize.d.ts.map +1 -0
  66. package/lib/hooks/useWindowSize.js +49 -0
  67. package/lib/hooks/useWindowSize.js.map +1 -0
  68. package/lib/index.d.ts +30 -0
  69. package/lib/index.d.ts.map +1 -0
  70. package/lib/index.js +37 -0
  71. package/lib/index.js.map +1 -0
  72. package/lib/internal.d.ts +35 -0
  73. package/lib/internal.d.ts.map +1 -0
  74. package/lib/internal.js +45 -0
  75. package/lib/internal.js.map +1 -0
  76. package/lib/translations/blogTranslations.d.ts +20 -0
  77. package/lib/translations/blogTranslations.d.ts.map +1 -0
  78. package/lib/translations/blogTranslations.js +52 -0
  79. package/lib/translations/blogTranslations.js.map +1 -0
  80. package/lib/translations/contentVisibilityTranslations.d.ts +12 -0
  81. package/lib/translations/contentVisibilityTranslations.d.ts.map +1 -0
  82. package/lib/translations/contentVisibilityTranslations.js +30 -0
  83. package/lib/translations/contentVisibilityTranslations.js.map +1 -0
  84. package/lib/translations/docsTranslations.d.ts +8 -0
  85. package/lib/translations/docsTranslations.d.ts.map +1 -0
  86. package/lib/translations/docsTranslations.js +17 -0
  87. package/lib/translations/docsTranslations.js.map +1 -0
  88. package/lib/utils/IntlUtils.d.ts +2 -0
  89. package/lib/utils/IntlUtils.d.ts.map +1 -0
  90. package/lib/utils/IntlUtils.js +20 -0
  91. package/lib/utils/IntlUtils.js.map +1 -0
  92. package/lib/utils/ThemeClassNames.d.ts +99 -0
  93. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  94. package/lib/utils/ThemeClassNames.js +107 -0
  95. package/lib/utils/ThemeClassNames.js.map +1 -0
  96. package/lib/utils/accessibilityUtils.d.ts +8 -0
  97. package/lib/utils/accessibilityUtils.d.ts.map +1 -0
  98. package/lib/utils/accessibilityUtils.js +10 -0
  99. package/lib/utils/accessibilityUtils.js.map +1 -0
  100. package/lib/utils/admonitionUtils.d.ts +12 -0
  101. package/lib/utils/admonitionUtils.d.ts.map +1 -0
  102. package/lib/utils/admonitionUtils.js +32 -0
  103. package/lib/utils/admonitionUtils.js.map +1 -0
  104. package/lib/utils/anchorUtils.d.ts +16 -0
  105. package/lib/utils/anchorUtils.d.ts.map +1 -0
  106. package/lib/utils/anchorUtils.js +26 -0
  107. package/lib/utils/anchorUtils.js.map +1 -0
  108. package/lib/utils/anchorUtils.module.css +14 -0
  109. package/lib/utils/codeBlockUtils.d.ts +101 -0
  110. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  111. package/lib/utils/codeBlockUtils.js +310 -0
  112. package/lib/utils/codeBlockUtils.js.map +1 -0
  113. package/lib/utils/emojiUtils.d.ts +20 -0
  114. package/lib/utils/emojiUtils.d.ts.map +1 -0
  115. package/lib/utils/emojiUtils.js +32 -0
  116. package/lib/utils/emojiUtils.js.map +1 -0
  117. package/lib/utils/errorBoundaryUtils.d.ts +31 -0
  118. package/lib/utils/errorBoundaryUtils.d.ts.map +1 -0
  119. package/lib/utils/errorBoundaryUtils.js +48 -0
  120. package/lib/utils/errorBoundaryUtils.js.map +1 -0
  121. package/lib/utils/errorBoundaryUtils.module.css +16 -0
  122. package/lib/utils/footerUtils.d.ts +13 -0
  123. package/lib/utils/footerUtils.d.ts.map +1 -0
  124. package/lib/utils/footerUtils.js +14 -0
  125. package/lib/utils/footerUtils.js.map +1 -0
  126. package/lib/utils/historyUtils.d.ts +39 -0
  127. package/lib/utils/historyUtils.d.ts.map +1 -0
  128. package/lib/utils/historyUtils.js +148 -0
  129. package/lib/utils/historyUtils.js.map +1 -0
  130. package/lib/utils/jsUtils.d.ts +24 -0
  131. package/lib/utils/jsUtils.d.ts.map +1 -0
  132. package/lib/utils/jsUtils.js +43 -0
  133. package/lib/utils/jsUtils.js.map +1 -0
  134. package/lib/utils/metadataUtils.d.ts +38 -0
  135. package/lib/utils/metadataUtils.d.ts.map +1 -0
  136. package/lib/utils/metadataUtils.js +87 -0
  137. package/lib/utils/metadataUtils.js.map +1 -0
  138. package/lib/utils/navbarUtils.d.ts +21 -0
  139. package/lib/utils/navbarUtils.d.ts.map +1 -0
  140. package/lib/utils/navbarUtils.js +35 -0
  141. package/lib/utils/navbarUtils.js.map +1 -0
  142. package/lib/utils/reactUtils.d.ts +60 -0
  143. package/lib/utils/reactUtils.d.ts.map +1 -0
  144. package/lib/utils/reactUtils.js +91 -0
  145. package/lib/utils/reactUtils.js.map +1 -0
  146. package/lib/utils/regexpUtils.d.ts +12 -0
  147. package/lib/utils/regexpUtils.d.ts.map +1 -0
  148. package/lib/utils/regexpUtils.js +18 -0
  149. package/lib/utils/regexpUtils.js.map +1 -0
  150. package/lib/utils/routesUtils.d.ts +26 -0
  151. package/lib/utils/routesUtils.d.ts.map +1 -0
  152. package/lib/utils/routesUtils.js +54 -0
  153. package/lib/utils/routesUtils.js.map +1 -0
  154. package/lib/utils/scrollUtils.d.ts +83 -0
  155. package/lib/utils/scrollUtils.d.ts.map +1 -0
  156. package/lib/utils/scrollUtils.js +201 -0
  157. package/lib/utils/scrollUtils.js.map +1 -0
  158. package/lib/utils/searchUtils.d.ts +8 -0
  159. package/lib/utils/searchUtils.d.ts.map +1 -0
  160. package/lib/utils/searchUtils.js +8 -0
  161. package/lib/utils/searchUtils.js.map +1 -0
  162. package/lib/utils/skipToContentUtils.d.ts +20 -0
  163. package/lib/utils/skipToContentUtils.d.ts.map +1 -0
  164. package/lib/utils/skipToContentUtils.js +75 -0
  165. package/lib/utils/skipToContentUtils.js.map +1 -0
  166. package/lib/utils/storageUtils.d.ts +36 -0
  167. package/lib/utils/storageUtils.d.ts.map +1 -0
  168. package/lib/utils/storageUtils.js +193 -0
  169. package/lib/utils/storageUtils.js.map +1 -0
  170. package/lib/utils/tabsUtils.d.ts +55 -0
  171. package/lib/utils/tabsUtils.d.ts.map +1 -0
  172. package/lib/utils/tabsUtils.js +179 -0
  173. package/lib/utils/tabsUtils.js.map +1 -0
  174. package/lib/utils/tagsUtils.d.ts +20 -0
  175. package/lib/utils/tagsUtils.d.ts.map +1 -0
  176. package/lib/utils/tagsUtils.js +41 -0
  177. package/lib/utils/tagsUtils.js.map +1 -0
  178. package/lib/utils/titleFormatterUtils.d.ts +59 -0
  179. package/lib/utils/titleFormatterUtils.d.ts.map +1 -0
  180. package/lib/utils/titleFormatterUtils.js +49 -0
  181. package/lib/utils/titleFormatterUtils.js.map +1 -0
  182. package/lib/utils/tocUtils.d.ts +36 -0
  183. package/lib/utils/tocUtils.d.ts.map +1 -0
  184. package/lib/utils/tocUtils.js +84 -0
  185. package/lib/utils/tocUtils.js.map +1 -0
  186. package/lib/utils/useAlternatePageUtils.d.ts +32 -0
  187. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  188. package/lib/utils/useAlternatePageUtils.js +42 -0
  189. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  190. package/lib/utils/useLocalPathname.d.ts +13 -0
  191. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  192. package/lib/utils/useLocalPathname.js +19 -0
  193. package/lib/utils/useLocalPathname.js.map +1 -0
  194. package/lib/utils/useLocationChange.d.ts +17 -0
  195. package/lib/utils/useLocationChange.d.ts.map +1 -0
  196. package/lib/utils/useLocationChange.js +31 -0
  197. package/lib/utils/useLocationChange.js.map +1 -0
  198. package/lib/utils/usePluralForm.d.ts +21 -0
  199. package/lib/utils/usePluralForm.d.ts.map +1 -0
  200. package/lib/utils/usePluralForm.js +93 -0
  201. package/lib/utils/usePluralForm.js.map +1 -0
  202. package/lib/utils/useThemeConfig.d.ts +120 -0
  203. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  204. package/lib/utils/useThemeConfig.js +14 -0
  205. package/lib/utils/useThemeConfig.js.map +1 -0
  206. package/package.json +58 -4
  207. package/src/components/Collapsible/index.tsx +250 -0
  208. package/src/components/Details/index.tsx +130 -0
  209. package/src/components/Details/styles.module.css +66 -0
  210. package/src/components/ThemedComponent/index.tsx +75 -0
  211. package/src/components/ThemedComponent/styles.module.css +26 -0
  212. package/src/contexts/announcementBar.tsx +117 -0
  213. package/src/contexts/colorMode.tsx +257 -0
  214. package/src/contexts/navbarMobileSidebar.tsx +119 -0
  215. package/src/contexts/navbarSecondaryMenu/content.tsx +100 -0
  216. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  217. package/src/hooks/useBackToTopButton.ts +73 -0
  218. package/src/hooks/useCodeWordWrap.ts +107 -0
  219. package/src/hooks/useHideableNavbar.ts +81 -0
  220. package/src/hooks/useLockBodyScroll.ts +21 -0
  221. package/src/hooks/useMutationObserver.ts +38 -0
  222. package/src/hooks/usePrismTheme.ts +24 -0
  223. package/src/hooks/useTOCHighlight.ts +189 -0
  224. package/src/hooks/useWindowSize.ts +67 -0
  225. package/src/index.ts +112 -0
  226. package/src/internal.ts +107 -0
  227. package/src/translations/blogTranslations.tsx +89 -0
  228. package/src/translations/contentVisibilityTranslations.tsx +51 -0
  229. package/src/translations/docsTranslations.tsx +28 -0
  230. package/src/types.d.ts +8 -0
  231. package/src/utils/IntlUtils.ts +27 -0
  232. package/src/utils/ThemeClassNames.ts +119 -0
  233. package/src/utils/accessibilityUtils.ts +10 -0
  234. package/src/utils/admonitionUtils.tsx +44 -0
  235. package/src/utils/anchorUtils.module.css +14 -0
  236. package/src/utils/anchorUtils.ts +31 -0
  237. package/src/utils/codeBlockUtils.tsx +494 -0
  238. package/src/utils/emojiUtils.ts +40 -0
  239. package/src/utils/errorBoundaryUtils.module.css +16 -0
  240. package/src/utils/errorBoundaryUtils.tsx +71 -0
  241. package/src/utils/footerUtils.ts +18 -0
  242. package/src/utils/historyUtils.ts +199 -0
  243. package/src/utils/jsUtils.ts +54 -0
  244. package/src/utils/metadataUtils.tsx +145 -0
  245. package/src/utils/navbarUtils.tsx +45 -0
  246. package/src/utils/reactUtils.tsx +120 -0
  247. package/src/utils/regexpUtils.ts +24 -0
  248. package/src/utils/routesUtils.ts +75 -0
  249. package/src/utils/scrollUtils.tsx +303 -0
  250. package/src/utils/searchUtils.ts +8 -0
  251. package/src/utils/skipToContentUtils.tsx +108 -0
  252. package/src/utils/storageUtils.ts +260 -0
  253. package/src/utils/tabsUtils.tsx +307 -0
  254. package/src/utils/tagsUtils.tsx +61 -0
  255. package/src/utils/titleFormatterUtils.tsx +120 -0
  256. package/src/utils/tocUtils.ts +119 -0
  257. package/src/utils/useAlternatePageUtils.ts +80 -0
  258. package/src/utils/useLocalPathname.ts +22 -0
  259. package/src/utils/useLocationChange.ts +41 -0
  260. package/src/utils/usePluralForm.ts +131 -0
  261. package/src/utils/useThemeConfig.ts +147 -0
@@ -0,0 +1,41 @@
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 {useEffect} from 'react';
9
+ import {useLocation} from '@docusaurus/router';
10
+ import {useEvent, usePrevious} from './reactUtils';
11
+ import type {Location} from 'history';
12
+
13
+ /**
14
+ * Fires an effect when the location changes (which includes hash, query, etc.).
15
+ * Importantly, doesn't fire when there's no previous location: see
16
+ * https://github.com/facebook/docusaurus/pull/6696
17
+ */
18
+ export function useLocationChange(
19
+ onLocationChange: (locationChangeEvent: {
20
+ location: Location;
21
+ previousLocation: Location | undefined;
22
+ }) => void,
23
+ ): void {
24
+ const location = useLocation();
25
+ const previousLocation = usePrevious(location);
26
+
27
+ const onLocationChangeDynamic = useEvent(onLocationChange);
28
+
29
+ useEffect(() => {
30
+ if (!previousLocation) {
31
+ return;
32
+ }
33
+
34
+ if (location !== previousLocation) {
35
+ onLocationChangeDynamic({
36
+ location,
37
+ previousLocation,
38
+ });
39
+ }
40
+ }, [onLocationChangeDynamic, location, previousLocation]);
41
+ }
@@ -0,0 +1,131 @@
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 {useMemo} from 'react';
9
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
+
11
+ // We want to ensurer a stable plural form order in all cases
12
+ // It is more convenient and natural to handle "small values" first
13
+ // See https://x.com/sebastienlorber/status/1366820663261077510
14
+ const OrderedPluralForms: Intl.LDMLPluralRule[] = [
15
+ 'zero',
16
+ 'one',
17
+ 'two',
18
+ 'few',
19
+ 'many',
20
+ 'other',
21
+ ];
22
+ function sortPluralForms(
23
+ pluralForms: Intl.LDMLPluralRule[],
24
+ ): Intl.LDMLPluralRule[] {
25
+ return OrderedPluralForms.filter((pf) => pluralForms.includes(pf));
26
+ }
27
+
28
+ type LocalePluralForms = {
29
+ locale: string;
30
+ pluralForms: Intl.LDMLPluralRule[];
31
+ select: (count: number) => Intl.LDMLPluralRule;
32
+ };
33
+
34
+ // Hardcoded english/fallback implementation
35
+ const EnglishPluralForms: LocalePluralForms = {
36
+ locale: 'en',
37
+ pluralForms: sortPluralForms(['one', 'other']),
38
+ select: (count) => (count === 1 ? 'one' : 'other'),
39
+ };
40
+
41
+ function createLocalePluralForms(locale: string): LocalePluralForms {
42
+ const pluralRules = new Intl.PluralRules(locale);
43
+ return {
44
+ locale,
45
+ pluralForms: sortPluralForms(
46
+ pluralRules.resolvedOptions().pluralCategories,
47
+ ),
48
+ select: (count) => pluralRules.select(count),
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Poor man's `PluralSelector` implementation, using an English fallback. We
54
+ * want a lightweight, future-proof and good-enough solution. We don't want a
55
+ * perfect and heavy solution.
56
+ *
57
+ * Docusaurus classic theme has only 2 deeply nested labels requiring complex
58
+ * plural rules. We don't want to use `Intl` + `PluralRules` polyfills + full
59
+ * ICU syntax (react-intl) just for that.
60
+ *
61
+ * Notes:
62
+ * - 2021: 92+% Browsers support `Intl.PluralRules`, and support will increase
63
+ * in the future
64
+ * - NodeJS >= 13 has full ICU support by default
65
+ * - In case of "mismatch" between SSR and Browser ICU support, React keeps
66
+ * working!
67
+ */
68
+ function useLocalePluralForms(): LocalePluralForms {
69
+ const {
70
+ i18n: {currentLocale},
71
+ } = useDocusaurusContext();
72
+ return useMemo(() => {
73
+ try {
74
+ return createLocalePluralForms(currentLocale);
75
+ } catch (err) {
76
+ console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
77
+ Docusaurus will fallback to the default (English) implementation.
78
+ Error: ${(err as Error).message}
79
+ `);
80
+ return EnglishPluralForms;
81
+ }
82
+ }, [currentLocale]);
83
+ }
84
+
85
+ function selectPluralMessage(
86
+ pluralMessages: string,
87
+ count: number,
88
+ localePluralForms: LocalePluralForms,
89
+ ): string {
90
+ const separator = '|';
91
+ const parts = pluralMessages.split(separator);
92
+
93
+ if (parts.length === 1) {
94
+ return parts[0]!;
95
+ }
96
+ if (parts.length > localePluralForms.pluralForms.length) {
97
+ console.error(
98
+ `For locale=${localePluralForms.locale}, a maximum of ${
99
+ localePluralForms.pluralForms.length
100
+ } plural forms are expected (${localePluralForms.pluralForms.join(
101
+ ',',
102
+ )}), but the message contains ${parts.length}: ${pluralMessages}`,
103
+ );
104
+ }
105
+ const pluralForm = localePluralForms.select(count);
106
+ const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
107
+ // In case of not enough plural form messages, we take the last one (other)
108
+ // instead of returning undefined
109
+ return parts[Math.min(pluralFormIndex, parts.length - 1)]!;
110
+ }
111
+
112
+ /**
113
+ * Reads the current locale and returns an interface very similar to
114
+ * `Intl.PluralRules`.
115
+ */
116
+ export function usePluralForm(): {
117
+ /**
118
+ * Give it a `count` and it will select the relevant message from
119
+ * `pluralMessages`. `pluralMessages` should be separated by `|`, and in the
120
+ * order of "zero", "one", "two", "few", "many", "other". The actual selection
121
+ * is done by `Intl.PluralRules`, which tells us all plurals the locale has
122
+ * and which plural we should use for `count`.
123
+ */
124
+ selectMessage: (count: number, pluralMessages: string) => string;
125
+ } {
126
+ const localePluralForm = useLocalePluralForms();
127
+ return {
128
+ selectMessage: (count: number, pluralMessages: string): string =>
129
+ selectPluralMessage(pluralMessages, count, localePluralForm),
130
+ };
131
+ }
@@ -0,0 +1,147 @@
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ import type {PrismTheme} from 'prism-react-renderer';
10
+ import type {DeepPartial} from 'utility-types';
11
+ import type {MagicCommentConfig} from './codeBlockUtils';
12
+ import type {ColorMode} from '../contexts/colorMode';
13
+
14
+ type DocsVersionPersistence = 'localStorage' | 'none';
15
+
16
+ // TODO improve types, use unions
17
+ export type NavbarItem = {
18
+ type?: string;
19
+ items?: NavbarItem[];
20
+ label?: string;
21
+ position?: 'left' | 'right';
22
+ } & {[key: string]: unknown};
23
+
24
+ type BaseLogo = {
25
+ alt?: string;
26
+ src: string;
27
+ srcDark?: string;
28
+ href?: string;
29
+ width?: string | number;
30
+ height?: string | number;
31
+ target?: string;
32
+ style?: object;
33
+ className?: string;
34
+ };
35
+
36
+ export type NavbarLogo = BaseLogo;
37
+
38
+ // TODO improve
39
+ export type Navbar = {
40
+ style?: 'dark' | 'primary';
41
+ hideOnScroll: boolean;
42
+ title?: string;
43
+ items: NavbarItem[];
44
+ logo?: NavbarLogo;
45
+ };
46
+
47
+ export type ColorModeConfig = {
48
+ defaultMode: ColorMode;
49
+ disableSwitch: boolean;
50
+ respectPrefersColorScheme: boolean;
51
+ };
52
+
53
+ type AnnouncementBarConfig = {
54
+ id: string;
55
+ content: string;
56
+ backgroundColor: string;
57
+ textColor: string;
58
+ isCloseable: boolean;
59
+ };
60
+
61
+ type PrismConfig = {
62
+ theme: PrismTheme;
63
+ darkTheme?: PrismTheme;
64
+ defaultLanguage?: string;
65
+ additionalLanguages: string[];
66
+ magicComments: MagicCommentConfig[];
67
+ };
68
+
69
+ export type FooterLinkItem = {
70
+ label?: string;
71
+ className?: string;
72
+ to?: string;
73
+ href?: string;
74
+ html?: string;
75
+ prependBaseUrlToHref?: string;
76
+ } & {[key: string]: unknown};
77
+
78
+ export type FooterColumnItem = {
79
+ title: string | null;
80
+ className?: string;
81
+ items: FooterLinkItem[];
82
+ };
83
+
84
+ export type FooterLogo = BaseLogo;
85
+
86
+ type FooterBase = {
87
+ style: 'light' | 'dark';
88
+ logo?: FooterLogo;
89
+ copyright?: string;
90
+ };
91
+
92
+ export type MultiColumnFooter = FooterBase & {
93
+ links: FooterColumnItem[];
94
+ };
95
+
96
+ export type SimpleFooter = FooterBase & {
97
+ links: FooterLinkItem[];
98
+ };
99
+
100
+ export type Footer = MultiColumnFooter | SimpleFooter;
101
+
102
+ type TableOfContents = {
103
+ minHeadingLevel: number;
104
+ maxHeadingLevel: number;
105
+ };
106
+
107
+ // TODO Docusaurus v4: use interface + declaration merging to enhance
108
+ // Theme config after validation/normalization
109
+ export type ThemeConfig = {
110
+ docs: {
111
+ versionPersistence: DocsVersionPersistence;
112
+ sidebar: {
113
+ hideable: boolean;
114
+ autoCollapseCategories: boolean;
115
+ };
116
+ };
117
+
118
+ blog: {
119
+ sidebar: {
120
+ groupByYear: boolean;
121
+ };
122
+ };
123
+
124
+ // TODO we should complete this theme config type over time
125
+ // and share it across all themes
126
+ // and use it in the Joi validation schema?
127
+
128
+ // TODO temporary types
129
+ navbar: Navbar;
130
+ colorMode: ColorModeConfig;
131
+ announcementBar?: AnnouncementBarConfig;
132
+ prism: PrismConfig;
133
+ footer?: Footer;
134
+ image?: string;
135
+ metadata: {[key: string]: string}[];
136
+ tableOfContents: TableOfContents;
137
+ };
138
+
139
+ // User-provided theme config, unnormalized
140
+ export type UserThemeConfig = DeepPartial<ThemeConfig>;
141
+
142
+ /**
143
+ * A convenient/more semantic way to get theme config from context.
144
+ */
145
+ export function useThemeConfig(): ThemeConfig {
146
+ return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
147
+ }