@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,49 @@
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 { createContext, useContext } from 'react';
8
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ import useRouteContext from '@docusaurus/useRouteContext';
10
+ import { ReactContextError } from './reactUtils';
11
+ export const TitleFormatterFnDefault = ({ title, siteTitle, titleDelimiter, }) => {
12
+ const trimmedTitle = title?.trim();
13
+ if (!trimmedTitle || trimmedTitle === siteTitle) {
14
+ return siteTitle;
15
+ }
16
+ return `${trimmedTitle} ${titleDelimiter} ${siteTitle}`;
17
+ };
18
+ const TitleFormatterContext = createContext(null);
19
+ export function TitleFormatterProvider({ formatter, children, }) {
20
+ return (<TitleFormatterContext value={formatter}>{children}</TitleFormatterContext>);
21
+ }
22
+ function useTitleFormatterContext() {
23
+ const value = useContext(TitleFormatterContext);
24
+ if (value === null) {
25
+ throw new ReactContextError('TitleFormatterProvider');
26
+ }
27
+ return value;
28
+ }
29
+ /**
30
+ * Returns a function to format the page title
31
+ */
32
+ export function useTitleFormatter() {
33
+ const formatter = useTitleFormatterContext();
34
+ const { siteConfig } = useDocusaurusContext();
35
+ const { title: siteTitle, titleDelimiter } = siteConfig;
36
+ // Unfortunately we can only call this hook here, not in the provider
37
+ // Route context can't be accessed in any provider applied above the router
38
+ const { plugin } = useRouteContext();
39
+ return {
40
+ format: (title) => formatter({
41
+ title,
42
+ siteTitle,
43
+ titleDelimiter,
44
+ plugin,
45
+ defaultFormatter: TitleFormatterFnDefault,
46
+ }),
47
+ };
48
+ }
49
+ //# sourceMappingURL=titleFormatterUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"titleFormatterUtils.js","sourceRoot":"","sources":["../../src/utils/titleFormatterUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AAEhD,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AA6C/C,MAAM,CAAC,MAAM,uBAAuB,GAAqB,CAAC,EACxD,KAAK,EACL,SAAS,EACT,cAAc,GACf,EAAU,EAAE;IACX,MAAM,YAAY,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IACnC,IAAI,CAAC,YAAY,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,YAAY,IAAI,cAAc,IAAI,SAAS,EAAE,CAAC;AAC1D,CAAC,CAAC;AAOF,MAAM,qBAAqB,GAAG,aAAa,CACzC,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,QAAQ,GAIT;IACC,OAAO,CACL,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC,CAC5E,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,KAAK,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAChD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,SAAS,GAAG,wBAAwB,EAAE,CAAC;IAC7C,MAAM,EAAC,UAAU,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAC5C,MAAM,EAAC,KAAK,EAAE,SAAS,EAAE,cAAc,EAAC,GAAG,UAAU,CAAC;IAEtD,qEAAqE;IACrE,2EAA2E;IAC3E,MAAM,EAAC,MAAM,EAAC,GAAG,eAAe,EAAE,CAAC;IAEnC,OAAO;QACL,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,KAAK;YACL,SAAS;YACT,cAAc;YACd,MAAM;YACN,gBAAgB,EAAE,uBAAuB;SAC1C,CAAC;KACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
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 { TOCItem } from '@docusaurus/mdx-loader';
8
+ export type TOCTreeNode = {
9
+ readonly value: string;
10
+ readonly id: string;
11
+ readonly level: number;
12
+ readonly children: readonly TOCTreeNode[];
13
+ };
14
+ /**
15
+ * Takes a flat TOC list (from the MDX loader) and treeifies it into what the
16
+ * TOC components expect. Memoized for performance.
17
+ */
18
+ export declare function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[];
19
+ /**
20
+ * Takes a flat TOC list (from the MDX loader) and treeifies it into what the
21
+ * TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
22
+ * Memoized for performance.
23
+ *
24
+ * **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
25
+ * because we have to filter the TOC after it has been treeified. This is mostly
26
+ * to ensure that weird TOC structures preserve their semantics. For example, an
27
+ * h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
28
+ * min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
29
+ * the two headings and they are not parent-children)
30
+ */
31
+ export declare function useFilteredAndTreeifiedTOC({ toc, minHeadingLevel, maxHeadingLevel, }: {
32
+ toc: readonly TOCItem[];
33
+ minHeadingLevel: number;
34
+ maxHeadingLevel: number;
35
+ }): readonly TOCTreeNode[];
36
+ //# sourceMappingURL=tocUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tocUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,wBAAwB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;CAC3C,CAAC;AAuCF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,SAAS,WAAW,EAAE,CAEtE;AAiCD;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAChB,EAAE;IACD,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,SAAS,WAAW,EAAE,CAKzB"}
@@ -0,0 +1,84 @@
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 { useMemo } from 'react';
8
+ function treeifyTOC(flatTOC) {
9
+ const headings = flatTOC.map((heading) => ({
10
+ ...heading,
11
+ parentIndex: -1,
12
+ children: [],
13
+ }));
14
+ // Keep track of which previous index would be the current heading's direct
15
+ // parent. Each entry <i> is the last index of the `headings` array at heading
16
+ // level <i>. We will modify these indices as we iterate through all headings.
17
+ // e.g. if an ### H3 was last seen at index 2, then prevIndexForLevel[3] === 2
18
+ // indices 0 and 1 will remain unused.
19
+ const prevIndexForLevel = Array(7).fill(-1);
20
+ headings.forEach((curr, currIndex) => {
21
+ // Take the last seen index for each ancestor level. the highest index will
22
+ // be the direct ancestor of the current heading.
23
+ const ancestorLevelIndexes = prevIndexForLevel.slice(2, curr.level);
24
+ curr.parentIndex = Math.max(...ancestorLevelIndexes);
25
+ // Mark that curr.level was last seen at the current index.
26
+ prevIndexForLevel[curr.level] = currIndex;
27
+ });
28
+ const rootNodes = [];
29
+ // For a given parentIndex, add each Node into that parent's `children` array
30
+ headings.forEach((heading) => {
31
+ const { parentIndex, ...rest } = heading;
32
+ if (parentIndex >= 0) {
33
+ headings[parentIndex].children.push(rest);
34
+ }
35
+ else {
36
+ rootNodes.push(rest);
37
+ }
38
+ });
39
+ return rootNodes;
40
+ }
41
+ /**
42
+ * Takes a flat TOC list (from the MDX loader) and treeifies it into what the
43
+ * TOC components expect. Memoized for performance.
44
+ */
45
+ export function useTreeifiedTOC(toc) {
46
+ return useMemo(() => treeifyTOC(toc), [toc]);
47
+ }
48
+ function filterTOC({ toc, minHeadingLevel, maxHeadingLevel, }) {
49
+ function isValid(item) {
50
+ return item.level >= minHeadingLevel && item.level <= maxHeadingLevel;
51
+ }
52
+ return toc.flatMap((item) => {
53
+ const filteredChildren = filterTOC({
54
+ toc: item.children,
55
+ minHeadingLevel,
56
+ maxHeadingLevel,
57
+ });
58
+ if (isValid(item)) {
59
+ return [
60
+ {
61
+ ...item,
62
+ children: filteredChildren,
63
+ },
64
+ ];
65
+ }
66
+ return filteredChildren;
67
+ });
68
+ }
69
+ /**
70
+ * Takes a flat TOC list (from the MDX loader) and treeifies it into what the
71
+ * TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
72
+ * Memoized for performance.
73
+ *
74
+ * **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
75
+ * because we have to filter the TOC after it has been treeified. This is mostly
76
+ * to ensure that weird TOC structures preserve their semantics. For example, an
77
+ * h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
78
+ * min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
79
+ * the two headings and they are not parent-children)
80
+ */
81
+ export function useFilteredAndTreeifiedTOC({ toc, minHeadingLevel, maxHeadingLevel, }) {
82
+ return useMemo(() => filterTOC({ toc: treeifyTOC(toc), minHeadingLevel, maxHeadingLevel }), [toc, minHeadingLevel, maxHeadingLevel]);
83
+ }
84
+ //# sourceMappingURL=tocUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tocUtils.js","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAU9B,SAAS,UAAU,CAAC,OAA2B;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACzC,GAAG,OAAO;QACV,WAAW,EAAE,CAAC,CAAC;QACf,QAAQ,EAAE,EAAmB;KAC9B,CAAC,CAAC,CAAC;IAEJ,2EAA2E;IAC3E,8EAA8E;IAC9E,8EAA8E;IAC9E,8EAA8E;IAC9E,sCAAsC;IACtC,MAAM,iBAAiB,GAAG,KAAK,CAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;QACnC,2EAA2E;QAC3E,iDAAiD;QACjD,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC;QACrD,2DAA2D;QAC3D,iBAAiB,CAAC,IAAI,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CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAKhB;IACC,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,EACzE,CAAC,GAAG,EAAE,eAAe,EAAE,eAAe,CAAC,CACxC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
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
+ * Permits to obtain the url of the current page in another locale, useful to
9
+ * generate hreflang meta headers etc...
10
+ *
11
+ * @see https://developers.google.com/search/docs/advanced/crawling/localized-versions
12
+ */
13
+ export declare function useAlternatePageUtils(): {
14
+ /**
15
+ * Everything (pathname, base URL, etc.) is read from the context. Just tell
16
+ * it which locale to link to and it will give you the alternate link for the
17
+ * current page.
18
+ */
19
+ createUrl: ({
20
+ /** The locale name to link to. */
21
+ locale,
22
+ /**
23
+ * For hreflang SEO headers, we need it to be fully qualified (full
24
+ * protocol/domain/path...); but for locale dropdowns, using a pathname is
25
+ * good enough.
26
+ */
27
+ fullyQualified, }: {
28
+ locale: string;
29
+ fullyQualified: boolean;
30
+ }) => string;
31
+ };
32
+ //# sourceMappingURL=useAlternatePageUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI;IACvC;;;;OAIG;IACH,SAAS,EAAE,CAAC;IACV,kCAAkC;IAClC,MAAM;IACN;;;;OAIG;IACH,cAAc,GACf,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,OAAO,CAAC;KACzB,KAAK,MAAM,CAAC;CACd,CA0CA"}
@@ -0,0 +1,42 @@
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8
+ import { useLocation } from '@docusaurus/router';
9
+ import { applyTrailingSlash } from '@docusaurus/utils-common';
10
+ /**
11
+ * Permits to obtain the url of the current page in another locale, useful to
12
+ * generate hreflang meta headers etc...
13
+ *
14
+ * @see https://developers.google.com/search/docs/advanced/crawling/localized-versions
15
+ */
16
+ export function useAlternatePageUtils() {
17
+ const { siteConfig: { baseUrl, trailingSlash }, i18n: { localeConfigs }, } = useDocusaurusContext();
18
+ // TODO using useLocation().pathname is not a super idea
19
+ // See https://github.com/facebook/docusaurus/issues/9170
20
+ const { pathname } = useLocation();
21
+ const canonicalPathname = applyTrailingSlash(pathname, {
22
+ trailingSlash,
23
+ baseUrl,
24
+ });
25
+ // Canonical pathname, without the baseUrl of the current locale
26
+ const pathnameSuffix = canonicalPathname.replace(baseUrl, '');
27
+ function getLocaleConfig(locale) {
28
+ const localeConfig = localeConfigs[locale];
29
+ if (!localeConfig) {
30
+ throw new Error(`Unexpected Docusaurus bug, no locale config found for locale=${locale}`);
31
+ }
32
+ return localeConfig;
33
+ }
34
+ function createUrl({ locale, fullyQualified, }) {
35
+ const localeConfig = getLocaleConfig(locale);
36
+ const newUrl = `${fullyQualified ? localeConfig.url : ''}`;
37
+ const newBaseUrl = localeConfig.baseUrl;
38
+ return `${newUrl}${newBaseUrl}${pathnameSuffix}`;
39
+ }
40
+ return { createUrl };
41
+ }
42
+ //# sourceMappingURL=useAlternatePageUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAlternatePageUtils.js","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;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13 @@
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
+ * Get the pathname of current route, without the optional site baseUrl.
9
+ * - `/docs/myDoc` => `/docs/myDoc`
10
+ * - `/baseUrl/docs/myDoc` => `/docs/myDoc`
11
+ */
12
+ export declare function useLocalPathname(): string;
13
+ //# sourceMappingURL=useLocalPathname.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalPathname.d.ts","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC"}
@@ -0,0 +1,19 @@
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 { useLocation } from '@docusaurus/router';
8
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ /**
10
+ * Get the pathname of current route, without the optional site baseUrl.
11
+ * - `/docs/myDoc` => `/docs/myDoc`
12
+ * - `/baseUrl/docs/myDoc` => `/docs/myDoc`
13
+ */
14
+ export function useLocalPathname() {
15
+ const { siteConfig: { baseUrl }, } = useDocusaurusContext();
16
+ const { pathname } = useLocation();
17
+ return pathname.replace(baseUrl, '/');
18
+ }
19
+ //# sourceMappingURL=useLocalPathname.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalPathname.js","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAC,GACtB,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IACjC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,17 @@
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 { Location } from 'history';
8
+ /**
9
+ * Fires an effect when the location changes (which includes hash, query, etc.).
10
+ * Importantly, doesn't fire when there's no previous location: see
11
+ * https://github.com/facebook/docusaurus/pull/6696
12
+ */
13
+ export declare function useLocationChange(onLocationChange: (locationChangeEvent: {
14
+ location: Location;
15
+ previousLocation: Location | undefined;
16
+ }) => void): void;
17
+ //# sourceMappingURL=useLocationChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocationChange.d.ts","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEtC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,gBAAgB,EAAE,CAAC,mBAAmB,EAAE;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC;CACxC,KAAK,IAAI,GACT,IAAI,CAkBN"}
@@ -0,0 +1,31 @@
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 { useEffect } from 'react';
8
+ import { useLocation } from '@docusaurus/router';
9
+ import { useEvent, usePrevious } from './reactUtils';
10
+ /**
11
+ * Fires an effect when the location changes (which includes hash, query, etc.).
12
+ * Importantly, doesn't fire when there's no previous location: see
13
+ * https://github.com/facebook/docusaurus/pull/6696
14
+ */
15
+ export function useLocationChange(onLocationChange) {
16
+ const location = useLocation();
17
+ const previousLocation = usePrevious(location);
18
+ const onLocationChangeDynamic = useEvent(onLocationChange);
19
+ useEffect(() => {
20
+ if (!previousLocation) {
21
+ return;
22
+ }
23
+ if (location !== previousLocation) {
24
+ onLocationChangeDynamic({
25
+ location,
26
+ previousLocation,
27
+ });
28
+ }
29
+ }, [onLocationChangeDynamic, location, previousLocation]);
30
+ }
31
+ //# sourceMappingURL=useLocationChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocationChange.js","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAGnD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAGU;IAEV,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,uBAAuB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE3D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,IAAI,QAAQ,KAAK,gBAAgB,EAAE,CAAC;YAClC,uBAAuB,CAAC;gBACtB,QAAQ;gBACR,gBAAgB;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,uBAAuB,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,21 @@
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
+ * Reads the current locale and returns an interface very similar to
9
+ * `Intl.PluralRules`.
10
+ */
11
+ export declare function usePluralForm(): {
12
+ /**
13
+ * Give it a `count` and it will select the relevant message from
14
+ * `pluralMessages`. `pluralMessages` should be separated by `|`, and in the
15
+ * order of "zero", "one", "two", "few", "many", "other". The actual selection
16
+ * is done by `Intl.PluralRules`, which tells us all plurals the locale has
17
+ * and which plural we should use for `count`.
18
+ */
19
+ selectMessage: (count: number, pluralMessages: string) => string;
20
+ };
21
+ //# sourceMappingURL=usePluralForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0GH;;;GAGG;AACH,wBAAgB,aAAa,IAAI;IAC/B;;;;;;OAMG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE,CAMA"}
@@ -0,0 +1,93 @@
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 { useMemo } from 'react';
8
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ // We want to ensurer a stable plural form order in all cases
10
+ // It is more convenient and natural to handle "small values" first
11
+ // See https://x.com/sebastienlorber/status/1366820663261077510
12
+ const OrderedPluralForms = [
13
+ 'zero',
14
+ 'one',
15
+ 'two',
16
+ 'few',
17
+ 'many',
18
+ 'other',
19
+ ];
20
+ function sortPluralForms(pluralForms) {
21
+ return OrderedPluralForms.filter((pf) => pluralForms.includes(pf));
22
+ }
23
+ // Hardcoded english/fallback implementation
24
+ const EnglishPluralForms = {
25
+ locale: 'en',
26
+ pluralForms: sortPluralForms(['one', 'other']),
27
+ select: (count) => (count === 1 ? 'one' : 'other'),
28
+ };
29
+ function createLocalePluralForms(locale) {
30
+ const pluralRules = new Intl.PluralRules(locale);
31
+ return {
32
+ locale,
33
+ pluralForms: sortPluralForms(pluralRules.resolvedOptions().pluralCategories),
34
+ select: (count) => pluralRules.select(count),
35
+ };
36
+ }
37
+ /**
38
+ * Poor man's `PluralSelector` implementation, using an English fallback. We
39
+ * want a lightweight, future-proof and good-enough solution. We don't want a
40
+ * perfect and heavy solution.
41
+ *
42
+ * Docusaurus classic theme has only 2 deeply nested labels requiring complex
43
+ * plural rules. We don't want to use `Intl` + `PluralRules` polyfills + full
44
+ * ICU syntax (react-intl) just for that.
45
+ *
46
+ * Notes:
47
+ * - 2021: 92+% Browsers support `Intl.PluralRules`, and support will increase
48
+ * in the future
49
+ * - NodeJS >= 13 has full ICU support by default
50
+ * - In case of "mismatch" between SSR and Browser ICU support, React keeps
51
+ * working!
52
+ */
53
+ function useLocalePluralForms() {
54
+ const { i18n: { currentLocale }, } = useDocusaurusContext();
55
+ return useMemo(() => {
56
+ try {
57
+ return createLocalePluralForms(currentLocale);
58
+ }
59
+ catch (err) {
60
+ console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
61
+ Docusaurus will fallback to the default (English) implementation.
62
+ Error: ${err.message}
63
+ `);
64
+ return EnglishPluralForms;
65
+ }
66
+ }, [currentLocale]);
67
+ }
68
+ function selectPluralMessage(pluralMessages, count, localePluralForms) {
69
+ const separator = '|';
70
+ const parts = pluralMessages.split(separator);
71
+ if (parts.length === 1) {
72
+ return parts[0];
73
+ }
74
+ if (parts.length > localePluralForms.pluralForms.length) {
75
+ console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms.join(',')}), but the message contains ${parts.length}: ${pluralMessages}`);
76
+ }
77
+ const pluralForm = localePluralForms.select(count);
78
+ const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
79
+ // In case of not enough plural form messages, we take the last one (other)
80
+ // instead of returning undefined
81
+ return parts[Math.min(pluralFormIndex, parts.length - 1)];
82
+ }
83
+ /**
84
+ * Reads the current locale and returns an interface very similar to
85
+ * `Intl.PluralRules`.
86
+ */
87
+ export function usePluralForm() {
88
+ const localePluralForm = useLocalePluralForms();
89
+ return {
90
+ selectMessage: (count, pluralMessages) => selectPluralMessage(pluralMessages, count, localePluralForm),
91
+ };
92
+ }
93
+ //# sourceMappingURL=usePluralForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePluralForm.js","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,6DAA6D;AAC7D,mEAAmE;AACnE,+DAA+D;AAC/D,MAAM,kBAAkB,GAA0B;IAChD,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,OAAO;CACR,CAAC;AACF,SAAS,eAAe,CACtB,WAAkC;IAElC,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC;AAQD,4CAA4C;AAC5C,MAAM,kBAAkB,GAAsB;IAC5C,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,eAAe,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC;AAEF,SAAS,uBAAuB,CAAC,MAAc;IAC7C,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;QACL,MAAM;QACN,WAAW,EAAE,eAAe,CAC1B,WAAW,CAAC,eA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AAC;IACnD,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1E,2EAA2E;IAC3E,iCAAiC;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAE,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAU3B,MAAM,gBAAgB,GAAG,oBAAoB,EAAE,CAAC;IAChD,OAAO;QACL,aAAa,EAAE,CAAC,KAAa,EAAE,cAAsB,EAAU,EAAE,CAC/D,mBAAmB,CAAC,cAAc,EAAE,KAAK,EAAE,gBAAgB,CAAC;KAC/D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,120 @@
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';
10
+ import type { ColorMode } from '../contexts/colorMode';
11
+ type DocsVersionPersistence = 'localStorage' | 'none';
12
+ export type NavbarItem = {
13
+ type?: string;
14
+ items?: NavbarItem[];
15
+ label?: string;
16
+ position?: 'left' | 'right';
17
+ } & {
18
+ [key: string]: unknown;
19
+ };
20
+ type BaseLogo = {
21
+ alt?: string;
22
+ src: string;
23
+ srcDark?: string;
24
+ href?: string;
25
+ width?: string | number;
26
+ height?: string | number;
27
+ target?: string;
28
+ style?: object;
29
+ className?: string;
30
+ };
31
+ export type NavbarLogo = BaseLogo;
32
+ export type Navbar = {
33
+ style?: 'dark' | 'primary';
34
+ hideOnScroll: boolean;
35
+ title?: string;
36
+ items: NavbarItem[];
37
+ logo?: NavbarLogo;
38
+ };
39
+ export type ColorModeConfig = {
40
+ defaultMode: ColorMode;
41
+ disableSwitch: boolean;
42
+ respectPrefersColorScheme: boolean;
43
+ };
44
+ type AnnouncementBarConfig = {
45
+ id: string;
46
+ content: string;
47
+ backgroundColor: string;
48
+ textColor: string;
49
+ isCloseable: boolean;
50
+ };
51
+ type PrismConfig = {
52
+ theme: PrismTheme;
53
+ darkTheme?: PrismTheme;
54
+ defaultLanguage?: string;
55
+ additionalLanguages: string[];
56
+ magicComments: MagicCommentConfig[];
57
+ };
58
+ export type FooterLinkItem = {
59
+ label?: string;
60
+ className?: string;
61
+ to?: string;
62
+ href?: string;
63
+ html?: string;
64
+ prependBaseUrlToHref?: string;
65
+ } & {
66
+ [key: string]: unknown;
67
+ };
68
+ export type FooterColumnItem = {
69
+ title: string | null;
70
+ className?: string;
71
+ items: FooterLinkItem[];
72
+ };
73
+ export type FooterLogo = BaseLogo;
74
+ type FooterBase = {
75
+ style: 'light' | 'dark';
76
+ logo?: FooterLogo;
77
+ copyright?: string;
78
+ };
79
+ export type MultiColumnFooter = FooterBase & {
80
+ links: FooterColumnItem[];
81
+ };
82
+ export type SimpleFooter = FooterBase & {
83
+ links: FooterLinkItem[];
84
+ };
85
+ export type Footer = MultiColumnFooter | SimpleFooter;
86
+ type TableOfContents = {
87
+ minHeadingLevel: number;
88
+ maxHeadingLevel: number;
89
+ };
90
+ export type ThemeConfig = {
91
+ docs: {
92
+ versionPersistence: DocsVersionPersistence;
93
+ sidebar: {
94
+ hideable: boolean;
95
+ autoCollapseCategories: boolean;
96
+ };
97
+ };
98
+ blog: {
99
+ sidebar: {
100
+ groupByYear: boolean;
101
+ };
102
+ };
103
+ navbar: Navbar;
104
+ colorMode: ColorModeConfig;
105
+ announcementBar?: AnnouncementBarConfig;
106
+ prism: PrismConfig;
107
+ footer?: Footer;
108
+ image?: string;
109
+ metadata: {
110
+ [key: string]: string;
111
+ }[];
112
+ tableOfContents: TableOfContents;
113
+ };
114
+ export type UserThemeConfig = DeepPartial<ThemeConfig>;
115
+ /**
116
+ * A convenient/more semantic way to get theme config from context.
117
+ */
118
+ export declare function useThemeConfig(): ThemeConfig;
119
+ export {};
120
+ //# sourceMappingURL=useThemeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAErD,KAAK,sBAAsB,GAAG,cAAc,GAAG,MAAM,CAAC;AAGtD,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAE7B,KAAK,QAAQ,GAAG;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;AAGlC,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAA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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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8
+ /**
9
+ * A convenient/more semantic way to get theme config from context.
10
+ */
11
+ export function useThemeConfig() {
12
+ return useDocusaurusContext().siteConfig.themeConfig;
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;AAsIpE;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,oBAAoB,EAAE,CAAC,UAAU,CAAC,WAA0B,CAAC;AACtE,CAAC"}