@docusaurus/theme-common 2.0.0-beta.fc64c12e4 → 2.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 (274) hide show
  1. package/lib/components/Collapsible/index.d.ts +35 -6
  2. package/lib/components/Collapsible/index.d.ts.map +1 -0
  3. package/lib/components/Collapsible/index.js +33 -30
  4. package/lib/components/Collapsible/index.js.map +1 -0
  5. package/lib/components/Details/index.d.ts +8 -3
  6. package/lib/components/Details/index.d.ts.map +1 -0
  7. package/lib/components/Details/index.js +31 -19
  8. package/lib/components/Details/index.js.map +1 -0
  9. package/lib/components/Details/styles.module.css +14 -11
  10. package/lib/contexts/announcementBar.d.ts +22 -0
  11. package/lib/contexts/announcementBar.d.ts.map +1 -0
  12. package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +30 -31
  13. package/lib/contexts/announcementBar.js.map +1 -0
  14. package/lib/contexts/blogPost.d.ts +33 -0
  15. package/lib/contexts/blogPost.d.ts.map +1 -0
  16. package/lib/contexts/blogPost.js +46 -0
  17. package/lib/contexts/blogPost.js.map +1 -0
  18. package/lib/contexts/colorMode.d.ts +27 -0
  19. package/lib/contexts/colorMode.d.ts.map +1 -0
  20. package/lib/contexts/colorMode.js +132 -0
  21. package/lib/contexts/colorMode.js.map +1 -0
  22. package/lib/contexts/doc.d.ts +30 -0
  23. package/lib/contexts/doc.d.ts.map +1 -0
  24. package/lib/contexts/doc.js +48 -0
  25. package/lib/contexts/doc.js.map +1 -0
  26. package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
  27. package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
  28. package/lib/contexts/docSidebarItemsExpandedState.js +28 -0
  29. package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
  30. package/lib/contexts/docsPreferredVersion.d.ts +30 -0
  31. package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
  32. package/lib/contexts/docsPreferredVersion.js +130 -0
  33. package/lib/contexts/docsPreferredVersion.js.map +1 -0
  34. package/lib/contexts/docsSidebar.d.ts +26 -0
  35. package/lib/contexts/docsSidebar.d.ts.map +1 -0
  36. package/lib/contexts/docsSidebar.js +30 -0
  37. package/lib/contexts/docsSidebar.js.map +1 -0
  38. package/lib/contexts/docsVersion.d.ts +20 -0
  39. package/lib/contexts/docsVersion.d.ts.map +1 -0
  40. package/lib/contexts/docsVersion.js +26 -0
  41. package/lib/contexts/docsVersion.js.map +1 -0
  42. package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
  43. package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
  44. package/lib/contexts/navbarMobileSidebar.js +56 -0
  45. package/lib/contexts/navbarMobileSidebar.js.map +1 -0
  46. package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
  47. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
  48. package/lib/contexts/navbarSecondaryMenu/content.js +50 -0
  49. package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
  50. package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
  51. package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
  52. package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
  53. package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
  54. package/lib/contexts/tabGroupChoice.d.ts +21 -0
  55. package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
  56. package/lib/contexts/tabGroupChoice.js +49 -0
  57. package/lib/contexts/tabGroupChoice.js.map +1 -0
  58. package/lib/{utils/usePrevious.d.ts → hooks/styles.css} +4 -1
  59. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  60. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  61. package/lib/hooks/useBackToTopButton.js +50 -0
  62. package/lib/hooks/useBackToTopButton.js.map +1 -0
  63. package/lib/hooks/useCodeWordWrap.d.ts +14 -0
  64. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  65. package/lib/hooks/useCodeWordWrap.js +67 -0
  66. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  67. package/lib/hooks/useHideableNavbar.d.ts +17 -0
  68. package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
  69. package/lib/hooks/useHideableNavbar.js +60 -0
  70. package/lib/hooks/useHideableNavbar.js.map +1 -0
  71. package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
  72. package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
  73. package/lib/hooks/useKeyboardNavigation.js +39 -0
  74. package/lib/hooks/useKeyboardNavigation.js.map +1 -0
  75. package/lib/hooks/useLockBodyScroll.d.ts +12 -0
  76. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
  77. package/lib/hooks/useLockBodyScroll.js +20 -0
  78. package/lib/hooks/useLockBodyScroll.js.map +1 -0
  79. package/lib/hooks/useMutationObserver.d.ts +4 -0
  80. package/lib/hooks/useMutationObserver.d.ts.map +1 -0
  81. package/lib/hooks/useMutationObserver.js +29 -0
  82. package/lib/hooks/useMutationObserver.js.map +1 -0
  83. package/lib/hooks/usePrismTheme.d.ts +13 -0
  84. package/lib/hooks/usePrismTheme.d.ts.map +1 -0
  85. package/lib/hooks/usePrismTheme.js +21 -0
  86. package/lib/hooks/usePrismTheme.js.map +1 -0
  87. package/lib/hooks/useSearchPage.d.ts +25 -0
  88. package/lib/hooks/useSearchPage.d.ts.map +1 -0
  89. package/lib/hooks/useSearchPage.js +43 -0
  90. package/lib/hooks/useSearchPage.js.map +1 -0
  91. package/lib/hooks/useSkipToContent.d.ts +25 -0
  92. package/lib/hooks/useSkipToContent.d.ts.map +1 -0
  93. package/lib/hooks/useSkipToContent.js +35 -0
  94. package/lib/hooks/useSkipToContent.js.map +1 -0
  95. package/lib/hooks/useTOCHighlight.d.ts +25 -0
  96. package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
  97. package/lib/hooks/useTOCHighlight.js +130 -0
  98. package/lib/hooks/useTOCHighlight.js.map +1 -0
  99. package/lib/hooks/useWindowSize.d.ts +28 -0
  100. package/lib/hooks/useWindowSize.d.ts.map +1 -0
  101. package/lib/hooks/useWindowSize.js +59 -0
  102. package/lib/hooks/useWindowSize.js.map +1 -0
  103. package/lib/index.d.ts +15 -19
  104. package/lib/index.d.ts.map +1 -0
  105. package/lib/index.js +22 -15
  106. package/lib/index.js.map +1 -0
  107. package/lib/internal.d.ts +41 -0
  108. package/lib/internal.d.ts.map +1 -0
  109. package/lib/internal.js +52 -0
  110. package/lib/internal.js.map +1 -0
  111. package/lib/utils/ThemeClassNames.d.ts +49 -12
  112. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  113. package/lib/utils/ThemeClassNames.js +47 -4
  114. package/lib/utils/ThemeClassNames.js.map +1 -0
  115. package/lib/utils/codeBlockUtils.d.ts +63 -0
  116. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  117. package/lib/utils/codeBlockUtils.js +159 -3
  118. package/lib/utils/codeBlockUtils.js.map +1 -0
  119. package/lib/utils/docsUtils.d.ts +91 -0
  120. package/lib/utils/docsUtils.d.ts.map +1 -0
  121. package/lib/utils/docsUtils.js +217 -1
  122. package/lib/utils/docsUtils.js.map +1 -0
  123. package/lib/utils/footerUtils.d.ts +13 -0
  124. package/lib/utils/footerUtils.d.ts.map +1 -0
  125. package/lib/utils/footerUtils.js +14 -0
  126. package/lib/utils/footerUtils.js.map +1 -0
  127. package/lib/utils/generalUtils.d.ts +11 -1
  128. package/lib/utils/generalUtils.d.ts.map +1 -0
  129. package/lib/utils/generalUtils.js +9 -5
  130. package/lib/utils/generalUtils.js.map +1 -0
  131. package/lib/utils/historyUtils.d.ts +17 -0
  132. package/lib/utils/historyUtils.d.ts.map +1 -0
  133. package/lib/utils/historyUtils.js +38 -0
  134. package/lib/utils/historyUtils.js.map +1 -0
  135. package/lib/utils/jsUtils.d.ts +23 -0
  136. package/lib/utils/jsUtils.d.ts.map +1 -0
  137. package/lib/utils/jsUtils.js +29 -0
  138. package/lib/utils/jsUtils.js.map +1 -0
  139. package/lib/utils/metadataUtils.d.ts +38 -0
  140. package/lib/utils/metadataUtils.d.ts.map +1 -0
  141. package/lib/utils/metadataUtils.js +70 -0
  142. package/lib/utils/metadataUtils.js.map +1 -0
  143. package/lib/utils/navbarUtils.d.ts +21 -0
  144. package/lib/utils/navbarUtils.d.ts.map +1 -0
  145. package/lib/utils/navbarUtils.js +36 -0
  146. package/lib/utils/navbarUtils.js.map +1 -0
  147. package/lib/utils/reactUtils.d.ts +69 -0
  148. package/lib/utils/reactUtils.d.ts.map +1 -0
  149. package/lib/utils/reactUtils.js +98 -0
  150. package/lib/utils/reactUtils.js.map +1 -0
  151. package/lib/utils/regexpUtils.d.ts +12 -0
  152. package/lib/utils/regexpUtils.d.ts.map +1 -0
  153. package/lib/utils/regexpUtils.js +18 -0
  154. package/lib/utils/regexpUtils.js.map +1 -0
  155. package/lib/utils/routesUtils.d.ts +26 -0
  156. package/lib/utils/routesUtils.d.ts.map +1 -0
  157. package/lib/utils/routesUtils.js +54 -0
  158. package/lib/utils/routesUtils.js.map +1 -0
  159. package/lib/utils/scrollUtils.d.ts +83 -0
  160. package/lib/utils/scrollUtils.d.ts.map +1 -0
  161. package/lib/utils/scrollUtils.js +200 -0
  162. package/lib/utils/scrollUtils.js.map +1 -0
  163. package/lib/utils/searchUtils.d.ts +13 -0
  164. package/lib/utils/searchUtils.d.ts.map +1 -0
  165. package/lib/utils/searchUtils.js +37 -0
  166. package/lib/utils/searchUtils.js.map +1 -0
  167. package/lib/utils/storageUtils.d.ts +15 -7
  168. package/lib/utils/storageUtils.d.ts.map +1 -0
  169. package/lib/utils/storageUtils.js +55 -22
  170. package/lib/utils/storageUtils.js.map +1 -0
  171. package/lib/utils/tagsUtils.d.ts +18 -0
  172. package/lib/utils/tagsUtils.d.ts.map +1 -0
  173. package/lib/utils/tagsUtils.js +36 -0
  174. package/lib/utils/tagsUtils.js.map +1 -0
  175. package/lib/utils/tocUtils.d.ts +36 -0
  176. package/lib/utils/tocUtils.d.ts.map +1 -0
  177. package/lib/utils/tocUtils.js +84 -0
  178. package/lib/utils/tocUtils.js.map +1 -0
  179. package/lib/utils/useAlternatePageUtils.d.ts +21 -1
  180. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  181. package/lib/utils/useAlternatePageUtils.js +9 -4
  182. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  183. package/lib/utils/useLocalPathname.d.ts +6 -0
  184. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  185. package/lib/utils/useLocalPathname.js +7 -4
  186. package/lib/utils/useLocalPathname.js.map +1 -0
  187. package/lib/utils/useLocationChange.d.ts +9 -6
  188. package/lib/utils/useLocationChange.d.ts.map +1 -0
  189. package/lib/utils/useLocationChange.js +17 -11
  190. package/lib/utils/useLocationChange.js.map +1 -0
  191. package/lib/utils/usePluralForm.d.ts +12 -0
  192. package/lib/utils/usePluralForm.d.ts.map +1 -0
  193. package/lib/utils/usePluralForm.js +36 -37
  194. package/lib/utils/usePluralForm.js.map +1 -0
  195. package/lib/utils/useThemeConfig.d.ts +56 -29
  196. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  197. package/lib/utils/useThemeConfig.js +4 -0
  198. package/lib/utils/useThemeConfig.js.map +1 -0
  199. package/package.json +35 -15
  200. package/src/components/Collapsible/index.tsx +57 -48
  201. package/src/components/Details/index.tsx +27 -12
  202. package/src/components/Details/styles.module.css +14 -11
  203. package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +43 -39
  204. package/src/contexts/blogPost.tsx +80 -0
  205. package/src/contexts/colorMode.tsx +198 -0
  206. package/src/contexts/doc.tsx +71 -0
  207. package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
  208. package/src/contexts/docsPreferredVersion.tsx +251 -0
  209. package/src/contexts/docsSidebar.tsx +50 -0
  210. package/src/contexts/docsVersion.tsx +36 -0
  211. package/src/contexts/navbarMobileSidebar.tsx +99 -0
  212. package/src/contexts/navbarSecondaryMenu/content.tsx +100 -0
  213. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  214. package/src/contexts/tabGroupChoice.tsx +85 -0
  215. package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
  216. package/src/hooks/useBackToTopButton.ts +73 -0
  217. package/src/hooks/useCodeWordWrap.ts +105 -0
  218. package/src/hooks/useHideableNavbar.ts +75 -0
  219. package/src/hooks/useKeyboardNavigation.ts +45 -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/useSearchPage.ts +79 -0
  224. package/src/hooks/useSkipToContent.ts +58 -0
  225. package/src/hooks/useTOCHighlight.ts +189 -0
  226. package/src/hooks/useWindowSize.ts +72 -0
  227. package/src/index.ts +49 -42
  228. package/src/internal.ts +122 -0
  229. package/src/types.d.ts +0 -2
  230. package/src/utils/ThemeClassNames.ts +54 -5
  231. package/src/utils/codeBlockUtils.ts +241 -2
  232. package/src/utils/docsUtils.tsx +334 -0
  233. package/src/utils/footerUtils.ts +18 -0
  234. package/src/utils/generalUtils.ts +9 -5
  235. package/src/utils/historyUtils.ts +45 -0
  236. package/src/utils/jsUtils.ts +36 -0
  237. package/src/utils/metadataUtils.tsx +115 -0
  238. package/src/utils/navbarUtils.tsx +45 -0
  239. package/src/utils/reactUtils.tsx +129 -0
  240. package/src/utils/regexpUtils.ts +24 -0
  241. package/src/utils/routesUtils.ts +75 -0
  242. package/src/utils/scrollUtils.tsx +304 -0
  243. package/src/utils/searchUtils.ts +51 -0
  244. package/src/utils/storageUtils.ts +56 -23
  245. package/src/utils/tagsUtils.ts +50 -0
  246. package/src/utils/tocUtils.ts +119 -0
  247. package/src/utils/useAlternatePageUtils.ts +19 -6
  248. package/src/utils/useLocalPathname.ts +6 -4
  249. package/src/utils/useLocationChange.ts +24 -20
  250. package/src/utils/usePluralForm.ts +50 -38
  251. package/src/utils/useThemeConfig.ts +55 -31
  252. package/copyUntypedFiles.js +0 -20
  253. package/lib/.tsbuildinfo +0 -1
  254. package/lib/utils/announcementBarUtils.d.ts +0 -17
  255. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
  256. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
  257. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
  258. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
  259. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
  260. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
  261. package/lib/utils/mobileSecondaryMenu.d.ts +0 -20
  262. package/lib/utils/mobileSecondaryMenu.js +0 -50
  263. package/lib/utils/pathUtils.js +0 -13
  264. package/lib/utils/usePrevious.js +0 -14
  265. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  266. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  267. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
  268. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
  269. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
  270. package/src/utils/docsUtils.ts +0 -11
  271. package/src/utils/mobileSecondaryMenu.tsx +0 -115
  272. package/src/utils/pathUtils.ts +0 -17
  273. package/src/utils/usePrevious.ts +0 -18
  274. package/tsconfig.json +0 -10
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKeyboardNavigation.d.ts","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAqB5C"}
@@ -0,0 +1,39 @@
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 './styles.css';
9
+ export const keyboardFocusedClassName = 'navigation-with-keyboard';
10
+ /**
11
+ * Side-effect that adds the `keyboardFocusedClassName` to the body element when
12
+ * the keyboard has been pressed, or removes it when the mouse is clicked.
13
+ *
14
+ * The presence of this class name signals that the user may be using keyboard
15
+ * for navigation, and the theme **must** add focus outline when this class name
16
+ * is present. (And optionally not if it's absent, for design purposes)
17
+ *
18
+ * Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
19
+ */
20
+ export function useKeyboardNavigation() {
21
+ useEffect(() => {
22
+ function handleOutlineStyles(e) {
23
+ if (e.type === 'keydown' && e.key === 'Tab') {
24
+ document.body.classList.add(keyboardFocusedClassName);
25
+ }
26
+ if (e.type === 'mousedown') {
27
+ document.body.classList.remove(keyboardFocusedClassName);
28
+ }
29
+ }
30
+ document.addEventListener('keydown', handleOutlineStyles);
31
+ document.addEventListener('mousedown', handleOutlineStyles);
32
+ return () => {
33
+ document.body.classList.remove(keyboardFocusedClassName);
34
+ document.removeEventListener('keydown', handleOutlineStyles);
35
+ document.removeEventListener('mousedown', handleOutlineStyles);
36
+ };
37
+ }, []);
38
+ }
39
+ //# sourceMappingURL=useKeyboardNavigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKeyboardNavigation.js","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,mBAAmB,CAAC,CAA6B;YACxD,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAK,CAAmB,CAAC,GAAG,KAAK,KAAK,EAAE;gBAC9D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;aACvD;YAED,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC1B,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;aAC1D;QACH,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAC1D,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAE5D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;YAC7D,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QACjE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
@@ -0,0 +1,12 @@
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
+ * Side-effect that locks the document body's scroll throughout the lifetime of
9
+ * the containing component. e.g. when the mobile sidebar is expanded.
10
+ */
11
+ export declare function useLockBodyScroll(lock?: boolean): void;
12
+ //# sourceMappingURL=useLockBodyScroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLockBodyScroll.d.ts","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,OAAc,GAAG,IAAI,CAO5D"}
@@ -0,0 +1,20 @@
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
+ /**
9
+ * Side-effect that locks the document body's scroll throughout the lifetime of
10
+ * the containing component. e.g. when the mobile sidebar is expanded.
11
+ */
12
+ export function useLockBodyScroll(lock = true) {
13
+ useEffect(() => {
14
+ document.body.style.overflow = lock ? 'hidden' : 'visible';
15
+ return () => {
16
+ document.body.style.overflow = 'visible';
17
+ };
18
+ }, [lock]);
19
+ }
20
+ //# sourceMappingURL=useLockBodyScroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,IAAI;IACpD,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare type Options = MutationObserverInit;
2
+ export declare function useMutationObserver(target: Element | undefined | null, callback: MutationCallback, options?: Options): void;
3
+ export {};
4
+ //# sourceMappingURL=useMutationObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMutationObserver.d.ts","sourceRoot":"","sources":["../../src/hooks/useMutationObserver.ts"],"names":[],"mappings":"AASA,aAAK,OAAO,GAAG,oBAAoB,CAAC;AASpC,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,EAClC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,OAAwB,GAChC,IAAI,CAeN"}
@@ -0,0 +1,29 @@
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 { useEvent, useShallowMemoObject } from '../utils/reactUtils';
9
+ const DefaultOptions = {
10
+ attributes: true,
11
+ characterData: true,
12
+ childList: true,
13
+ subtree: true,
14
+ };
15
+ export function useMutationObserver(target, callback, options = DefaultOptions) {
16
+ const stableCallback = useEvent(callback);
17
+ // MutationObserver options are not nested much
18
+ // so this should be to memo options in 99%
19
+ // TODO handle options.attributeFilter array
20
+ const stableOptions = useShallowMemoObject(options);
21
+ useEffect(() => {
22
+ const observer = new MutationObserver(stableCallback);
23
+ if (target) {
24
+ observer.observe(target, stableOptions);
25
+ }
26
+ return () => observer.disconnect();
27
+ }, [target, stableCallback, stableOptions]);
28
+ }
29
+ //# sourceMappingURL=useMutationObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMutationObserver.js","sourceRoot":"","sources":["../../src/hooks/useMutationObserver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,QAAQ,EAAE,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAInE,MAAM,cAAc,GAAY;IAC9B,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,MAAM,UAAU,mBAAmB,CACjC,MAAkC,EAClC,QAA0B,EAC1B,UAAmB,cAAc;IAEjC,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE1C,+CAA+C;IAC/C,2CAA2C;IAC3C,4CAA4C;IAC5C,MAAM,aAAa,GAAY,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,cAAc,CAAC,CAAC;QACtD,IAAI,MAAM,EAAE;YACV,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;SACzC;QACD,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,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
+ import type { PrismTheme } from 'prism-react-renderer';
8
+ /**
9
+ * Returns a color-mode-dependent Prism theme: whatever the user specified in
10
+ * the config. Falls back to `palenight`.
11
+ */
12
+ export declare function usePrismTheme(): PrismTheme;
13
+ //# sourceMappingURL=usePrismTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrismTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAQ1C"}
@@ -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
+ import { useColorMode } from '../contexts/colorMode';
8
+ import { useThemeConfig } from '../utils/useThemeConfig';
9
+ /**
10
+ * Returns a color-mode-dependent Prism theme: whatever the user specified in
11
+ * the config. Falls back to `palenight`.
12
+ */
13
+ export function usePrismTheme() {
14
+ const { prism } = useThemeConfig();
15
+ const { colorMode } = useColorMode();
16
+ const lightModeTheme = prism.theme;
17
+ const darkModeTheme = prism.darkTheme || lightModeTheme;
18
+ const prismTheme = colorMode === 'dark' ? darkModeTheme : lightModeTheme;
19
+ return prismTheme;
20
+ }
21
+ //# sourceMappingURL=usePrismTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrismTheme.js","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAGvD;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAC,KAAK,EAAC,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,YAAY,EAAE,CAAC;IACnC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC;IACnC,MAAM,aAAa,GAAG,KAAK,CAAC,SAAS,IAAI,cAAc,CAAC;IACxD,MAAM,UAAU,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC;IAEzE,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,25 @@
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
+ /** Some utility functions around search queries. */
8
+ export declare function useSearchPage(): {
9
+ /**
10
+ * Works hand-in-hand with `setSearchQuery`; whatever the user has inputted
11
+ * into the search box.
12
+ */
13
+ searchQuery: string;
14
+ /**
15
+ * Set a new search query. In addition to updating `searchQuery`, this handle
16
+ * also mutates the location and appends the query.
17
+ */
18
+ setSearchQuery: (newSearchQuery: string) => void;
19
+ /**
20
+ * Given a query, this handle generates the corresponding search page link,
21
+ * with base URL prepended.
22
+ */
23
+ generateSearchPageLink: (targetSearchQuery: string) => string;
24
+ };
25
+ //# sourceMappingURL=useSearchPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSearchPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,oDAAoD;AACpD,wBAAgB,aAAa,IAAI;IAC/B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,sBAAsB,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/D,CAgDA"}
@@ -0,0 +1,43 @@
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 { useCallback, useEffect, useState } from 'react';
8
+ import { useHistory } from '@docusaurus/router';
9
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
+ const SEARCH_PARAM_QUERY = 'q';
11
+ /** Some utility functions around search queries. */
12
+ export function useSearchPage() {
13
+ const history = useHistory();
14
+ const { siteConfig: { baseUrl }, } = useDocusaurusContext();
15
+ const [searchQuery, setSearchQueryState] = useState('');
16
+ // Init search query just after React hydration
17
+ useEffect(() => {
18
+ const searchQueryStringValue = new URLSearchParams(window.location.search).get(SEARCH_PARAM_QUERY) ?? '';
19
+ setSearchQueryState(searchQueryStringValue);
20
+ }, []);
21
+ const setSearchQuery = useCallback((newSearchQuery) => {
22
+ const searchParams = new URLSearchParams(window.location.search);
23
+ if (newSearchQuery) {
24
+ searchParams.set(SEARCH_PARAM_QUERY, newSearchQuery);
25
+ }
26
+ else {
27
+ searchParams.delete(SEARCH_PARAM_QUERY);
28
+ }
29
+ history.replace({
30
+ search: searchParams.toString(),
31
+ });
32
+ setSearchQueryState(newSearchQuery);
33
+ }, [history]);
34
+ const generateSearchPageLink = useCallback((targetSearchQuery) =>
35
+ // Refer to https://github.com/facebook/docusaurus/pull/2838
36
+ `${baseUrl}search?${SEARCH_PARAM_QUERY}=${encodeURIComponent(targetSearchQuery)}`, [baseUrl]);
37
+ return {
38
+ searchQuery,
39
+ setSearchQuery,
40
+ generateSearchPageLink,
41
+ };
42
+ }
43
+ //# sourceMappingURL=useSearchPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSearchPage.js","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,oDAAoD;AACpD,MAAM,UAAU,aAAa;IAiB3B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAC,GACtB,GAAG,oBAAoB,EAAE,CAAC;IAE3B,MAAM,CAAC,WAAW,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAExD,+CAA+C;IAC/C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,sBAAsB,GAC1B,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAE5E,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IAC9C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,cAAc,GAAG,WAAW,CAChC,CAAC,cAAsB,EAAE,EAAE;QACzB,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEjE,IAAI,cAAc,EAAE;YAClB,YAAY,CAAC,GAAG,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;SACtD;aAAM;YACL,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SACzC;QAED,OAAO,CAAC,OAAO,CAAC;YACd,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;SAChC,CAAC,CAAC;QACH,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,MAAM,sBAAsB,GAAG,WAAW,CACxC,CAAC,iBAAyB,EAAE,EAAE;IAC5B,4DAA4D;IAC5D,GAAG,OAAO,UAAU,kBAAkB,IAAI,kBAAkB,CAC1D,iBAAiB,CAClB,EAAE,EACL,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO;QACL,WAAW;QACX,cAAc;QACd,sBAAsB;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
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 React from 'react';
8
+ /** This hook wires the logic for a skip-to-content link. */
9
+ export declare function useSkipToContent(): {
10
+ /**
11
+ * The ref to the container. On page transition, the container will be focused
12
+ * so that keyboard navigators can instantly interact with the link and jump
13
+ * to content. **Note:** the type is `RefObject<HTMLDivElement>` only because
14
+ * the typing for refs don't reflect that the `ref` prop is contravariant, so
15
+ * using `HTMLElement` causes type-checking to fail. You can plug the ref into
16
+ * any HTML element, as long as it can be focused.
17
+ */
18
+ containerRef: React.RefObject<HTMLDivElement>;
19
+ /**
20
+ * Callback fired when the skip to content link has been interacted with. It
21
+ * will programmatically focus the main content.
22
+ */
23
+ handleSkip: (e: React.MouseEvent<HTMLAnchorElement>) => void;
24
+ };
25
+ //# sourceMappingURL=useSkipToContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSkipToContent.d.ts","sourceRoot":"","sources":["../../src/hooks/useSkipToContent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAY/B,4DAA4D;AAC5D,wBAAgB,gBAAgB,IAAI;IAClC;;;;;;;OAOG;IACH,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C;;;OAGG;IACH,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;CAC9D,CAsBA"}
@@ -0,0 +1,35 @@
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 { useCallback, useRef } from 'react';
8
+ import { useHistory } from '@docusaurus/router';
9
+ import { useLocationChange } from '../utils/useLocationChange';
10
+ import { ThemeClassNames } from '../utils/ThemeClassNames';
11
+ function programmaticFocus(el) {
12
+ el.setAttribute('tabindex', '-1');
13
+ el.focus();
14
+ el.removeAttribute('tabindex');
15
+ }
16
+ /** This hook wires the logic for a skip-to-content link. */
17
+ export function useSkipToContent() {
18
+ const containerRef = useRef(null);
19
+ const { action } = useHistory();
20
+ const handleSkip = useCallback((e) => {
21
+ e.preventDefault();
22
+ const targetElement = document.querySelector('main:first-of-type') ??
23
+ document.querySelector(`.${ThemeClassNames.wrapper.main}`);
24
+ if (targetElement) {
25
+ programmaticFocus(targetElement);
26
+ }
27
+ }, []);
28
+ useLocationChange(({ location }) => {
29
+ if (containerRef.current && !location.hash && action === 'PUSH') {
30
+ programmaticFocus(containerRef.current);
31
+ }
32
+ });
33
+ return { containerRef, handleSkip };
34
+ }
35
+ //# sourceMappingURL=useSkipToContent.js.map
@@ -0,0 +1 @@
1
+ {"version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AC;IAEH,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,25 @@
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
+ export declare type TOCHighlightConfig = {
8
+ /** A class name that all TOC links share. */
9
+ linkClassName: string;
10
+ /** The class name applied to the active (highlighted) link. */
11
+ linkActiveClassName: string;
12
+ /**
13
+ * The minimum heading level that the TOC includes. Only headings that are in
14
+ * this range will be eligible as "active heading".
15
+ */
16
+ minHeadingLevel: number;
17
+ /** @see {@link TOCHighlightConfig.minHeadingLevel} */
18
+ maxHeadingLevel: number;
19
+ };
20
+ /**
21
+ * Side-effect that applies the active class name to the TOC heading that the
22
+ * user is currently viewing. Disabled when `config` is undefined.
23
+ */
24
+ export declare function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
25
+ //# sourceMappingURL=useTOCHighlight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/hooks/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6GH,oBAAY,kBAAkB,GAAG;IAC/B,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAwD5E"}
@@ -0,0 +1,130 @@
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, useRef } from 'react';
8
+ import { useThemeConfig } from '../utils/useThemeConfig';
9
+ // TODO make the hardcoded theme-classic classnames configurable (or add them
10
+ // to ThemeClassNames?)
11
+ /**
12
+ * If the anchor has no height and is just a "marker" in the DOM; we'll use the
13
+ * parent (normally the link text) rect boundaries instead
14
+ */
15
+ function getVisibleBoundingClientRect(element) {
16
+ const rect = element.getBoundingClientRect();
17
+ const hasNoHeight = rect.top === rect.bottom;
18
+ if (hasNoHeight) {
19
+ return getVisibleBoundingClientRect(element.parentNode);
20
+ }
21
+ return rect;
22
+ }
23
+ /**
24
+ * Considering we divide viewport into 2 zones of each 50vh, this returns true
25
+ * if an element is in the first zone (i.e., appear in viewport, near the top)
26
+ */
27
+ function isInViewportTopHalf(boundingRect) {
28
+ return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
29
+ }
30
+ function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
31
+ const selectors = [];
32
+ for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
33
+ selectors.push(`h${i}.anchor`);
34
+ }
35
+ return Array.from(document.querySelectorAll(selectors.join()));
36
+ }
37
+ function getActiveAnchor(anchors, { anchorTopOffset, }) {
38
+ // Naming is hard: The "nextVisibleAnchor" is the first anchor that appear
39
+ // under the viewport top boundary. It does not mean this anchor is visible
40
+ // yet, but if user continues scrolling down, it will be the first to become
41
+ // visible
42
+ const nextVisibleAnchor = anchors.find((anchor) => {
43
+ const boundingRect = getVisibleBoundingClientRect(anchor);
44
+ return boundingRect.top >= anchorTopOffset;
45
+ });
46
+ if (nextVisibleAnchor) {
47
+ const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
48
+ // If anchor is in the top half of the viewport: it is the one we consider
49
+ // "active" (unless it's too close to the top and and soon to be scrolled
50
+ // outside viewport)
51
+ if (isInViewportTopHalf(boundingRect)) {
52
+ return nextVisibleAnchor;
53
+ }
54
+ // If anchor is in the bottom half of the viewport, or under the viewport,
55
+ // we consider the active anchor is the previous one. This is because the
56
+ // main text appearing in the user screen mostly belong to the previous
57
+ // anchor. Returns null for the first anchor, see
58
+ // https://github.com/facebook/docusaurus/issues/5318
59
+ return anchors[anchors.indexOf(nextVisibleAnchor) - 1] ?? null;
60
+ }
61
+ // No anchor under viewport top (i.e. we are at the bottom of the page),
62
+ // highlight the last anchor found
63
+ return anchors[anchors.length - 1] ?? null;
64
+ }
65
+ function getLinkAnchorValue(link) {
66
+ return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
67
+ }
68
+ function getLinks(linkClassName) {
69
+ return Array.from(document.getElementsByClassName(linkClassName));
70
+ }
71
+ function getNavbarHeight() {
72
+ // Not ideal to obtain actual height this way
73
+ // Using TS ! (not ?) because otherwise a bad selector would be un-noticed
74
+ return document.querySelector('.navbar').clientHeight;
75
+ }
76
+ function useAnchorTopOffsetRef() {
77
+ const anchorTopOffsetRef = useRef(0);
78
+ const { navbar: { hideOnScroll }, } = useThemeConfig();
79
+ useEffect(() => {
80
+ anchorTopOffsetRef.current = hideOnScroll ? 0 : getNavbarHeight();
81
+ }, [hideOnScroll]);
82
+ return anchorTopOffsetRef;
83
+ }
84
+ /**
85
+ * Side-effect that applies the active class name to the TOC heading that the
86
+ * user is currently viewing. Disabled when `config` is undefined.
87
+ */
88
+ export function useTOCHighlight(config) {
89
+ const lastActiveLinkRef = useRef(undefined);
90
+ const anchorTopOffsetRef = useAnchorTopOffsetRef();
91
+ useEffect(() => {
92
+ if (!config) {
93
+ // No-op, highlighting is disabled
94
+ return () => { };
95
+ }
96
+ const { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, } = config;
97
+ function updateLinkActiveClass(link, active) {
98
+ if (active) {
99
+ if (lastActiveLinkRef.current && lastActiveLinkRef.current !== link) {
100
+ lastActiveLinkRef.current.classList.remove(linkActiveClassName);
101
+ }
102
+ link.classList.add(linkActiveClassName);
103
+ lastActiveLinkRef.current = link;
104
+ // link.scrollIntoView({block: 'nearest'});
105
+ }
106
+ else {
107
+ link.classList.remove(linkActiveClassName);
108
+ }
109
+ }
110
+ function updateActiveLink() {
111
+ const links = getLinks(linkClassName);
112
+ const anchors = getAnchors({ minHeadingLevel, maxHeadingLevel });
113
+ const activeAnchor = getActiveAnchor(anchors, {
114
+ anchorTopOffset: anchorTopOffsetRef.current,
115
+ });
116
+ const activeLink = links.find((link) => activeAnchor && activeAnchor.id === getLinkAnchorValue(link));
117
+ links.forEach((link) => {
118
+ updateLinkActiveClass(link, link === activeLink);
119
+ });
120
+ }
121
+ document.addEventListener('scroll', updateActiveLink);
122
+ document.addEventListener('resize', updateActiveLink);
123
+ updateActiveLink();
124
+ return () => {
125
+ document.removeEventListener('scroll', updateActiveLink);
126
+ document.removeEventListener('resize', updateActiveLink);
127
+ };
128
+ }, [config, anchorTopOffsetRef]);
129
+ }
130
+ //# sourceMappingURL=useTOCHighlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/hooks/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD,6EAA6E;AAC7E,uBAAuB;AAEvB;;;GAGG;AACH,SAAS,4BAA4B,CAAC,OAAoB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,4BAA4B,CAAC,OAAO,CAAC,UAAyB,CAAC,CAAC;KACxE;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,YAAqB;IAChD,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC;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BAAgB,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,28 @@
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
+ declare const windowSizes: {
8
+ readonly desktop: "desktop";
9
+ readonly mobile: "mobile";
10
+ readonly ssr: "ssr";
11
+ };
12
+ declare type WindowSize = keyof typeof windowSizes;
13
+ /**
14
+ * Gets the current window size as an enum value. We don't want it to return the
15
+ * actual width value, so that it only re-renders once a breakpoint is crossed.
16
+ *
17
+ * It may return `"ssr"`, which is very important to handle hydration FOUC or
18
+ * layout shifts. You have to handle it explicitly upfront. On the server, you
19
+ * may need to render BOTH the mobile/desktop elements (and hide one of them
20
+ * with mediaquery). We don't return `undefined` on purpose, to make it more
21
+ * explicit.
22
+ *
23
+ * In development mode, this hook will still return `"ssr"` for one second, to
24
+ * catch potential layout shifts, similar to strict mode calling effects twice.
25
+ */
26
+ export declare function useWindowSize(): WindowSize;
27
+ export {};
28
+ //# sourceMappingURL=useWindowSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,QAAA,MAAM,WAAW;;;;CAIP,CAAC;AAEX,aAAK,UAAU,GAAG,MAAM,OAAO,WAAW,CAAC;AAe3C;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,IAAI,UAAU,CA0B1C"}
@@ -0,0 +1,59 @@
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, useState } from 'react';
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
+ const windowSizes = {
10
+ desktop: 'desktop',
11
+ mobile: 'mobile',
12
+ ssr: 'ssr',
13
+ };
14
+ const DesktopThresholdWidth = 996;
15
+ function getWindowSize() {
16
+ if (!ExecutionEnvironment.canUseDOM) {
17
+ return windowSizes.ssr;
18
+ }
19
+ return window.innerWidth > DesktopThresholdWidth
20
+ ? windowSizes.desktop
21
+ : windowSizes.mobile;
22
+ }
23
+ const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
24
+ /**
25
+ * Gets the current window size as an enum value. We don't want it to return the
26
+ * actual width value, so that it only re-renders once a breakpoint is crossed.
27
+ *
28
+ * It may return `"ssr"`, which is very important to handle hydration FOUC or
29
+ * layout shifts. You have to handle it explicitly upfront. On the server, you
30
+ * may need to render BOTH the mobile/desktop elements (and hide one of them
31
+ * with mediaquery). We don't return `undefined` on purpose, to make it more
32
+ * explicit.
33
+ *
34
+ * In development mode, this hook will still return `"ssr"` for one second, to
35
+ * catch potential layout shifts, similar to strict mode calling effects twice.
36
+ */
37
+ export function useWindowSize() {
38
+ const [windowSize, setWindowSize] = useState(() => {
39
+ if (DevSimulateSSR) {
40
+ return 'ssr';
41
+ }
42
+ return getWindowSize();
43
+ });
44
+ useEffect(() => {
45
+ function updateWindowSize() {
46
+ setWindowSize(getWindowSize());
47
+ }
48
+ const timeout = DevSimulateSSR
49
+ ? window.setTimeout(updateWindowSize, 1000)
50
+ : undefined;
51
+ window.addEventListener('resize', updateWindowSize);
52
+ return () => {
53
+ window.removeEventListener('resize', updateWindowSize);
54
+ clearTimeout(timeout);
55
+ };
56
+ }, []);
57
+ return windowSize;
58
+ }
59
+ //# sourceMappingURL=useWindowSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowSize.js","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE1C,OAAO,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