@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,91 @@
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, useLayoutEffect, useMemo, useRef, } from 'react';
8
+ /**
9
+ * Temporary userland implementation until an official hook is implemented
10
+ * See RFC: https://github.com/reactjs/rfcs/pull/220
11
+ *
12
+ * Permits to transform an unstable callback (like an arrow function provided as
13
+ * props) to a "stable" callback that is safe to use in a `useEffect` dependency
14
+ * array. Useful to avoid React stale closure problems + avoid useless effect
15
+ * re-executions.
16
+ *
17
+ * This generally works but has some potential drawbacks, such as
18
+ * https://github.com/facebook/react/issues/16956#issuecomment-536636418
19
+ */
20
+ export function useEvent(callback) {
21
+ const ref = useRef(callback);
22
+ useLayoutEffect(() => {
23
+ ref.current = callback;
24
+ }, [callback]);
25
+ // @ts-expect-error: TS is right that this callback may be a supertype of T,
26
+ // but good enough for our use
27
+ return useCallback((...args) => ref.current(...args), []);
28
+ }
29
+ /**
30
+ * Gets `value` from the last render.
31
+ */
32
+ export function usePrevious(value) {
33
+ const ref = useRef(undefined);
34
+ useLayoutEffect(() => {
35
+ ref.current = value;
36
+ });
37
+ // TODO need to fix this React Compiler lint error
38
+ // probably requires changing the API though
39
+ // eslint-disable-next-line react-hooks/refs
40
+ return ref.current;
41
+ }
42
+ /**
43
+ * This error is thrown when a context is consumed outside its provider. Allows
44
+ * reusing a generic error message format and reduces bundle size. The hook's
45
+ * name will be extracted from its stack, so only the provider's name is needed.
46
+ */
47
+ export class ReactContextError extends Error {
48
+ constructor(providerName, additionalInfo) {
49
+ super();
50
+ this.name = 'ReactContextError';
51
+ this.message = `Hook ${this.stack?.split('\n')[1]?.match(/at (?:\w+\.)?(?<name>\w+)/)?.groups
52
+ .name ?? ''} is called outside the <${providerName}>. ${additionalInfo ?? ''}`;
53
+ }
54
+ }
55
+ /**
56
+ * Shallow-memoize an object. This means the returned object will be the same as
57
+ * the previous render if the property keys and values did not change. This
58
+ * works for simple cases: when property values are primitives or stable
59
+ * objects.
60
+ *
61
+ * @param obj
62
+ */
63
+ export function useShallowMemoObject(obj) {
64
+ const deps = Object.entries(obj);
65
+ // Sort by keys to make it order-insensitive
66
+ deps.sort((a, b) => a[0].localeCompare(b[0]));
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps,react-hooks/use-memo
68
+ return useMemo(() => obj, deps.flat());
69
+ }
70
+ /**
71
+ * Creates a single React provider from an array of existing providers
72
+ * assuming providers only take "children" as props.
73
+ *
74
+ * Prevents the annoying React element nesting
75
+ * Example here: https://getfrontend.tips/compose-multiple-react-providers/
76
+ *
77
+ * The order matters:
78
+ * - The first provider is at the top of the tree.
79
+ * - The last provider is the most nested one
80
+ *
81
+ * @param providers array of providers to compose
82
+ */
83
+ export function composeProviders(providers) {
84
+ // Creates a single React component: it's cheaper to compose JSX elements
85
+ return function ComposedProvider({ children }) {
86
+ return (<>
87
+ {providers.reduceRight((element, CurrentProvider) => (<CurrentProvider>{element}</CurrentProvider>), children)}
88
+ </>);
89
+ };
90
+ }
91
+ //# sourceMappingURL=reactUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactUtils.js","sourceRoot":"","sources":["../../src/utils/reactUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,eAAe,EACf,OAAO,EACP,MAAM,GAGP,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAW;IAEX,MAAM,GAAG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C,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,4EAA4E;IAC5E,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAID;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA2B;IAC1D,yEAAyE;IACzE,OAAO,SAAS,gBAAgB,CAAC,EAAC,QAAQ,EAAwB;QAChE,OAAO,CACL,EACE;QAAA,CAAC,SAAS,CAAC,WAAW,CACpB,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,CAAC,CAC5B,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAC7C,EACD,QAAQ,CACT,CACH;MAAA,GAAG,CACJ,CAAC;IACJ,CAAC,CAAC;AACJ,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
+ * Matches a string regex (as provided from the config) against a target in a
9
+ * null-safe fashion, case insensitive and global.
10
+ */
11
+ export declare function isRegexpStringMatch(regexAsString?: string, valueToTest?: string): boolean;
12
+ //# sourceMappingURL=regexpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,CAAC,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAST"}
@@ -0,0 +1,18 @@
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
+ * Matches a string regex (as provided from the config) against a target in a
9
+ * null-safe fashion, case insensitive and global.
10
+ */
11
+ export function isRegexpStringMatch(regexAsString, valueToTest) {
12
+ if (typeof regexAsString === 'undefined' ||
13
+ typeof valueToTest === 'undefined') {
14
+ return false;
15
+ }
16
+ return new RegExp(regexAsString, 'gi').test(valueToTest);
17
+ }
18
+ //# sourceMappingURL=regexpUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexpUtils.js","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,aAAsB,EACtB,WAAoB;IAEpB,IACE,OAAO,aAAa,KAAK,WAAW;QACpC,OAAO,WAAW,KAAK,WAAW,EAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,26 @@
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 { RouteConfig } from 'react-router-config';
8
+ /**
9
+ * Compare the 2 paths, case insensitive and ignoring trailing slash
10
+ */
11
+ export declare function isSamePath(path1: string | undefined, path2: string | undefined): boolean;
12
+ /**
13
+ * Note that sites don't always have a homepage in practice, so we can't assume
14
+ * that linking to '/' is always safe.
15
+ * @see https://github.com/facebook/docusaurus/pull/6517#issuecomment-1048709116
16
+ */
17
+ export declare function findHomePageRoute({ baseUrl, routes: initialRoutes, }: {
18
+ routes: RouteConfig[];
19
+ baseUrl: string;
20
+ }): RouteConfig | undefined;
21
+ /**
22
+ * Fetches the route that points to "/". Use this instead of the naive "/",
23
+ * because the homepage may not exist.
24
+ */
25
+ export declare function useHomePageRoute(): RouteConfig | undefined;
26
+ //# sourceMappingURL=routesUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EAAE,aAAa,GACtB,EAAE;IACD,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,WAAW,GAAG,SAAS,CAwB1B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,GAAG,SAAS,CAM1D"}
@@ -0,0 +1,54 @@
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 generatedRoutes from '@generated/routes';
9
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
+ /**
11
+ * Compare the 2 paths, case insensitive and ignoring trailing slash
12
+ */
13
+ export function isSamePath(path1, path2) {
14
+ const normalize = (pathname) => (!pathname || pathname.endsWith('/')
15
+ ? pathname
16
+ : `${pathname}/`)?.toLowerCase();
17
+ return normalize(path1) === normalize(path2);
18
+ }
19
+ /**
20
+ * Note that sites don't always have a homepage in practice, so we can't assume
21
+ * that linking to '/' is always safe.
22
+ * @see https://github.com/facebook/docusaurus/pull/6517#issuecomment-1048709116
23
+ */
24
+ export function findHomePageRoute({ baseUrl, routes: initialRoutes, }) {
25
+ function isHomePageRoute(route) {
26
+ return route.path === baseUrl && route.exact === true;
27
+ }
28
+ function isHomeParentRoute(route) {
29
+ return route.path === baseUrl && !route.exact;
30
+ }
31
+ function doFindHomePageRoute(routes) {
32
+ if (routes.length === 0) {
33
+ return undefined;
34
+ }
35
+ const homePage = routes.find(isHomePageRoute);
36
+ if (homePage) {
37
+ return homePage;
38
+ }
39
+ const indexSubRoutes = routes
40
+ .filter(isHomeParentRoute)
41
+ .flatMap((route) => route.routes ?? []);
42
+ return doFindHomePageRoute(indexSubRoutes);
43
+ }
44
+ return doFindHomePageRoute(initialRoutes);
45
+ }
46
+ /**
47
+ * Fetches the route that points to "/". Use this instead of the naive "/",
48
+ * because the homepage may not exist.
49
+ */
50
+ export function useHomePageRoute() {
51
+ const { baseUrl } = useDocusaurusContext().siteConfig;
52
+ return useMemo(() => findHomePageRoute({ routes: generatedRoutes, baseUrl }), [baseUrl]);
53
+ }
54
+ //# sourceMappingURL=routesUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routesUtils.js","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAGpE;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,KAAyB,EACzB,KAAyB;IAEzB,MAAM,SAAS,GAAG,CAAC,QAA4B,EAAE,EAAE,CACjD,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAClC,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,GAAG,QAAQ,GAAG,CACjB,EAAE,WAAW,EAAE,CAAC;IACnB,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EAAE,aAAa,GAItB;IACC,SAAS,eAAe,CAAC,KAAkB;QACzC,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC;IACxD,CAAC;IAED,SAAS,iBAAiB,CAAC,KAAkB;QAC3C,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChD,CAAC;IAED,SAAS,mBAAmB,CAAC,MAAqB;QAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,cAAc,GAAG,MAAM;aAC1B,MAAM,CAAC,iBAAiB,CAAC;aACzB,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,mBAAmB,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAC,OAAO,EAAC,GAAG,oBAAoB,EAAE,CAAC,UAAU,CAAC;IACpD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,iBAAiB,CAAC,EAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAC,CAAC,EAC3D,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,83 @@
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 React, { type ReactNode } from 'react';
8
+ type ScrollController = {
9
+ /** A boolean ref tracking whether scroll events are enabled. */
10
+ scrollEventsEnabledRef: React.RefObject<boolean>;
11
+ /** Enable scroll events in `useScrollPosition`. */
12
+ enableScrollEvents: () => void;
13
+ /** Disable scroll events in `useScrollPosition`. */
14
+ disableScrollEvents: () => void;
15
+ };
16
+ export declare function ScrollControllerProvider({ children, }: {
17
+ children: ReactNode;
18
+ }): ReactNode;
19
+ /**
20
+ * We need a way to update the scroll position while ignoring scroll events
21
+ * so as not to toggle Navbar/BackToTop visibility.
22
+ *
23
+ * This API permits to temporarily disable/ignore scroll events. Motivated by
24
+ * https://github.com/facebook/docusaurus/pull/5618
25
+ */
26
+ export declare function useScrollController(): ScrollController;
27
+ type ScrollPosition = {
28
+ scrollX: number;
29
+ scrollY: number;
30
+ };
31
+ /**
32
+ * This hook fires an effect when the scroll position changes. The effect will
33
+ * be provided with the before/after scroll positions. Note that the effect may
34
+ * not be always run: if scrolling is disabled through `useScrollController`, it
35
+ * will be a no-op.
36
+ *
37
+ * @see {@link useScrollController}
38
+ */
39
+ export declare function useScrollPosition(effect: (position: ScrollPosition, lastPosition: ScrollPosition | null) => void, deps?: unknown[]): void;
40
+ /**
41
+ * This hook permits to "block" the scroll position of a DOM element.
42
+ * The idea is that we should be able to update DOM content above this element
43
+ * but the screen position of this element should not change.
44
+ *
45
+ * Feature motivated by the Tabs groups: clicking on a tab may affect tabs of
46
+ * the same group upper in the tree, yet to avoid a bad UX, the clicked tab must
47
+ * remain under the user mouse.
48
+ *
49
+ * @see https://github.com/facebook/docusaurus/pull/5618
50
+ */
51
+ export declare function useScrollPositionBlocker(): {
52
+ /**
53
+ * Takes an element, and keeps its screen position no matter what's getting
54
+ * rendered above it, until the next render.
55
+ */
56
+ blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
57
+ };
58
+ type CancelScrollTop = () => void;
59
+ /**
60
+ * A "smart polyfill" of `window.scrollTo({ top, behavior: "smooth" })`.
61
+ * This currently always uses a polyfilled implementation unless
62
+ * `scroll-behavior: smooth` has been set in CSS, because native support
63
+ * detection for scroll behavior seems unreliable.
64
+ *
65
+ * This hook does not do anything by itself: it returns a start and a stop
66
+ * handle. You can execute either handle at any time.
67
+ */
68
+ export declare function useSmoothScrollTo(): {
69
+ /**
70
+ * Start the scroll.
71
+ *
72
+ * @param top The final scroll top position.
73
+ */
74
+ startScroll: (top: number) => void;
75
+ /**
76
+ * A cancel function, because the non-native smooth scroll-top
77
+ * implementation must be interrupted if user scrolls down. If there's no
78
+ * existing animation or the scroll is using native behavior, this is a no-op.
79
+ */
80
+ cancelScroll: CancelScrollTop;
81
+ };
82
+ export {};
83
+ //# sourceMappingURL=scrollUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollUtils.d.ts","sourceRoot":"","sources":["../../src/utils/scrollUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,KAAK,gBAAgB,GAAG;IACtB,gEAAgE;IAChE,sBAAsB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjD,mDAAmD;IACnD,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,oDAAoD;IACpD,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AAuBF,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,SAAS,CAGZ;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAMtD;AAED,KAAK,cAAc,GAAG;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC;AAUzD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,CACN,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,cAAc,GAAG,IAAI,KAChC,IAAI,EACT,IAAI,GAAE,OAAO,EAAO,GACnB,IAAI,CA0BN;AA6CD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,IAAI;IAC1C;;;OAGG;IACH,yCAAyC,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,CAAC;CACtE,CA2CA;AAED,KAAK,eAAe,GAAG,MAAM,IAAI,CAAC;AA6BlC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI;IACnC;;;;OAIG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,YAAY,EAAE,eAAe,CAAC;CAC/B,CAoBA"}
@@ -0,0 +1,201 @@
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 React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, } from 'react';
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
+ import useIsBrowser from '@docusaurus/useIsBrowser';
10
+ import { useEvent, ReactContextError } from './reactUtils';
11
+ function useScrollControllerContextValue() {
12
+ const scrollEventsEnabledRef = useRef(true);
13
+ return useMemo(() => ({
14
+ scrollEventsEnabledRef,
15
+ enableScrollEvents: () => {
16
+ scrollEventsEnabledRef.current = true;
17
+ },
18
+ disableScrollEvents: () => {
19
+ scrollEventsEnabledRef.current = false;
20
+ },
21
+ }), []);
22
+ }
23
+ const ScrollMonitorContext = React.createContext(undefined);
24
+ export function ScrollControllerProvider({ children, }) {
25
+ const value = useScrollControllerContextValue();
26
+ return <ScrollMonitorContext value={value}>{children}</ScrollMonitorContext>;
27
+ }
28
+ /**
29
+ * We need a way to update the scroll position while ignoring scroll events
30
+ * so as not to toggle Navbar/BackToTop visibility.
31
+ *
32
+ * This API permits to temporarily disable/ignore scroll events. Motivated by
33
+ * https://github.com/facebook/docusaurus/pull/5618
34
+ */
35
+ export function useScrollController() {
36
+ const context = useContext(ScrollMonitorContext);
37
+ if (context == null) {
38
+ throw new ReactContextError('ScrollControllerProvider');
39
+ }
40
+ return context;
41
+ }
42
+ const getScrollPosition = () => ExecutionEnvironment.canUseDOM
43
+ ? {
44
+ scrollX: window.pageXOffset,
45
+ scrollY: window.pageYOffset,
46
+ }
47
+ : null;
48
+ /**
49
+ * This hook fires an effect when the scroll position changes. The effect will
50
+ * be provided with the before/after scroll positions. Note that the effect may
51
+ * not be always run: if scrolling is disabled through `useScrollController`, it
52
+ * will be a no-op.
53
+ *
54
+ * @see {@link useScrollController}
55
+ */
56
+ export function useScrollPosition(effect, deps = []) {
57
+ const { scrollEventsEnabledRef } = useScrollController();
58
+ const lastPositionRef = useRef(getScrollPosition());
59
+ const dynamicEffect = useEvent(effect);
60
+ useEffect(() => {
61
+ const handleScroll = () => {
62
+ if (!scrollEventsEnabledRef.current) {
63
+ return;
64
+ }
65
+ const currentPosition = getScrollPosition();
66
+ dynamicEffect(currentPosition, lastPositionRef.current);
67
+ lastPositionRef.current = currentPosition;
68
+ };
69
+ const opts = {
70
+ passive: true,
71
+ };
72
+ handleScroll();
73
+ window.addEventListener('scroll', handleScroll, opts);
74
+ return () => window.removeEventListener('scroll', handleScroll, opts);
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ }, [dynamicEffect, scrollEventsEnabledRef, ...deps]);
77
+ }
78
+ function useScrollPositionSaver() {
79
+ const lastElementRef = useRef({
80
+ elem: null,
81
+ top: 0,
82
+ });
83
+ const save = useCallback((elem) => {
84
+ lastElementRef.current = {
85
+ elem,
86
+ top: elem.getBoundingClientRect().top,
87
+ };
88
+ }, []);
89
+ const restore = useCallback(() => {
90
+ const { current: { elem, top }, } = lastElementRef;
91
+ if (!elem) {
92
+ return { restored: false };
93
+ }
94
+ const newTop = elem.getBoundingClientRect().top;
95
+ const heightDiff = newTop - top;
96
+ if (heightDiff) {
97
+ window.scrollBy({ left: 0, top: heightDiff });
98
+ }
99
+ lastElementRef.current = { elem: null, top: 0 };
100
+ return { restored: heightDiff !== 0 };
101
+ }, []);
102
+ return useMemo(() => ({ save, restore }), [restore, save]);
103
+ }
104
+ /**
105
+ * This hook permits to "block" the scroll position of a DOM element.
106
+ * The idea is that we should be able to update DOM content above this element
107
+ * but the screen position of this element should not change.
108
+ *
109
+ * Feature motivated by the Tabs groups: clicking on a tab may affect tabs of
110
+ * the same group upper in the tree, yet to avoid a bad UX, the clicked tab must
111
+ * remain under the user mouse.
112
+ *
113
+ * @see https://github.com/facebook/docusaurus/pull/5618
114
+ */
115
+ export function useScrollPositionBlocker() {
116
+ const scrollController = useScrollController();
117
+ const scrollPositionSaver = useScrollPositionSaver();
118
+ const nextLayoutEffectCallbackRef = useRef(undefined);
119
+ const blockElementScrollPositionUntilNextRender = useCallback((el) => {
120
+ scrollPositionSaver.save(el);
121
+ scrollController.disableScrollEvents();
122
+ nextLayoutEffectCallbackRef.current = () => {
123
+ const { restored } = scrollPositionSaver.restore();
124
+ nextLayoutEffectCallbackRef.current = undefined;
125
+ // Restoring the former scroll position will trigger a scroll event. We
126
+ // need to wait for next scroll event to happen before enabling the
127
+ // scrollController events again.
128
+ if (restored) {
129
+ const handleScrollRestoreEvent = () => {
130
+ scrollController.enableScrollEvents();
131
+ window.removeEventListener('scroll', handleScrollRestoreEvent);
132
+ };
133
+ window.addEventListener('scroll', handleScrollRestoreEvent);
134
+ }
135
+ else {
136
+ scrollController.enableScrollEvents();
137
+ }
138
+ };
139
+ }, [scrollController, scrollPositionSaver]);
140
+ useLayoutEffect(() => {
141
+ // Queuing permits to restore scroll position after all useLayoutEffect
142
+ // have run, and yet preserve the sync nature of the scroll restoration
143
+ // See https://github.com/facebook/docusaurus/issues/8625
144
+ queueMicrotask(() => nextLayoutEffectCallbackRef.current?.());
145
+ });
146
+ return {
147
+ blockElementScrollPositionUntilNextRender,
148
+ };
149
+ }
150
+ function smoothScrollNative(top) {
151
+ window.scrollTo({ top, behavior: 'smooth' });
152
+ return () => {
153
+ // Nothing to cancel, it's natively cancelled if user tries to scroll down
154
+ };
155
+ }
156
+ function smoothScrollPolyfill(top) {
157
+ let raf = null;
158
+ const isUpScroll = document.documentElement.scrollTop > top;
159
+ function rafRecursion() {
160
+ const currentScroll = document.documentElement.scrollTop;
161
+ if ((isUpScroll && currentScroll > top) ||
162
+ (!isUpScroll && currentScroll < top)) {
163
+ raf = requestAnimationFrame(rafRecursion);
164
+ window.scrollTo(0, Math.floor((currentScroll - top) * 0.85) + top);
165
+ }
166
+ }
167
+ rafRecursion();
168
+ // Break the recursion. Prevents the user from "fighting" against that
169
+ // recursion producing a weird UX
170
+ return () => raf && cancelAnimationFrame(raf);
171
+ }
172
+ /**
173
+ * A "smart polyfill" of `window.scrollTo({ top, behavior: "smooth" })`.
174
+ * This currently always uses a polyfilled implementation unless
175
+ * `scroll-behavior: smooth` has been set in CSS, because native support
176
+ * detection for scroll behavior seems unreliable.
177
+ *
178
+ * This hook does not do anything by itself: it returns a start and a stop
179
+ * handle. You can execute either handle at any time.
180
+ */
181
+ export function useSmoothScrollTo() {
182
+ const cancelRef = useRef(null);
183
+ const isBrowser = useIsBrowser();
184
+ // Not all have support for smooth scrolling (particularly Safari mobile iOS)
185
+ // TODO proper detection is currently unreliable!
186
+ // see https://github.com/wessberg/scroll-behavior-polyfill/issues/16
187
+ // For now, we only use native scroll behavior if smooth is already set,
188
+ // because otherwise the polyfill produces a weird UX when both CSS and JS try
189
+ // to scroll a page, and they cancel each other.
190
+ const supportsNativeSmoothScrolling = isBrowser &&
191
+ getComputedStyle(document.documentElement).scrollBehavior === 'smooth';
192
+ return {
193
+ startScroll: (top) => {
194
+ cancelRef.current = supportsNativeSmoothScrolling
195
+ ? smoothScrollNative(top)
196
+ : smoothScrollPolyfill(top);
197
+ },
198
+ cancelScroll: () => cancelRef.current?.(),
199
+ };
200
+ }
201
+ //# sourceMappingURL=scrollUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollUtils.js","sourceRoot":"","sources":["../../src/utils/scrollUtils.ts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,EAAE;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
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 const DEFAULT_SEARCH_TAG = "default";
8
+ //# sourceMappingURL=searchUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchUtils.d.ts","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,YAAY,CAAC"}
@@ -0,0 +1,8 @@
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 const DEFAULT_SEARCH_TAG = 'default';
8
+ //# sourceMappingURL=searchUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchUtils.js","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC"}
@@ -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 { type ComponentProps, type ReactNode } from 'react';
8
+ /**
9
+ * The id of the element that should become focused on a page
10
+ * that does not have a <main> html tag.
11
+ * Focusing the Docusaurus Layout children is a reasonable fallback.
12
+ *
13
+ * __ prefix allows search crawlers (Algolia/DocSearch) to ignore anchors
14
+ * https://github.com/facebook/docusaurus/issues/8883#issuecomment-1516328368
15
+ */
16
+ export declare const SkipToContentFallbackId = "__docusaurus_skipToContent_fallback";
17
+ type SkipToContentLinkProps = Omit<ComponentProps<'a'>, 'href' | 'onClick'>;
18
+ export declare function SkipToContentLink(props: SkipToContentLinkProps): ReactNode;
19
+ export {};
20
+ //# sourceMappingURL=skipToContentUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipToContentUtils.d.ts","sourceRoot":"","sources":["../../src/utils/skipToContentUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAK/E;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,wCAAwC,CAAC;AAiE7E,KAAK,sBAAsB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,CAmB1E"}
@@ -0,0 +1,75 @@
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 { translate } from '@docusaurus/Translate';
10
+ import { useLocationChange } from './useLocationChange';
11
+ /**
12
+ * The id of the element that should become focused on a page
13
+ * that does not have a <main> html tag.
14
+ * Focusing the Docusaurus Layout children is a reasonable fallback.
15
+ *
16
+ * __ prefix allows search crawlers (Algolia/DocSearch) to ignore anchors
17
+ * https://github.com/facebook/docusaurus/issues/8883#issuecomment-1516328368
18
+ */
19
+ export const SkipToContentFallbackId = '__docusaurus_skipToContent_fallback';
20
+ /**
21
+ * Returns the skip to content element to focus when the link is clicked.
22
+ */
23
+ function getSkipToContentTarget() {
24
+ return (
25
+ // Try to focus the <main> in priority
26
+ // Note: this will only work if JS is enabled
27
+ // See https://github.com/facebook/docusaurus/issues/6411#issuecomment-1284136069
28
+ document.querySelector('main:first-of-type') ??
29
+ // Then try to focus the fallback element (usually the Layout children)
30
+ document.getElementById(SkipToContentFallbackId));
31
+ }
32
+ function programmaticFocus(el) {
33
+ el.setAttribute('tabindex', '-1');
34
+ el.focus();
35
+ el.removeAttribute('tabindex');
36
+ }
37
+ /** This hook wires the logic for a skip-to-content link. */
38
+ function useSkipToContent() {
39
+ const containerRef = useRef(null);
40
+ const { action } = useHistory();
41
+ const onClick = useCallback((e) => {
42
+ e.preventDefault();
43
+ const targetElement = getSkipToContentTarget();
44
+ if (targetElement) {
45
+ programmaticFocus(targetElement);
46
+ }
47
+ }, []);
48
+ // "Reset" focus when navigating.
49
+ // See https://github.com/facebook/docusaurus/pull/8204#issuecomment-1276547558
50
+ useLocationChange(({ location }) => {
51
+ if (containerRef.current && !location.hash && action === 'PUSH') {
52
+ programmaticFocus(containerRef.current);
53
+ }
54
+ });
55
+ return { containerRef, onClick };
56
+ }
57
+ const DefaultSkipToContentLabel = translate({
58
+ id: 'theme.common.skipToMainContent',
59
+ description: 'The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation',
60
+ message: 'Skip to main content',
61
+ });
62
+ export function SkipToContentLink(props) {
63
+ const linkLabel = props.children ?? DefaultSkipToContentLabel;
64
+ const { containerRef, onClick } = useSkipToContent();
65
+ return (<div ref={containerRef} role="region" aria-label={DefaultSkipToContentLabel}>
66
+ {/* eslint-disable-next-line @docusaurus/no-html-links */}
67
+ <a {...props}
68
+ // Note this is a fallback href in case JS is disabled
69
+ // It has limitations, see https://github.com/facebook/docusaurus/issues/6411#issuecomment-1284136069
70
+ href={`#${SkipToContentFallbackId}`} onClick={onClick}>
71
+ {linkLabel}
72
+ </a>
73
+ </div>);
74
+ }
75
+ //# sourceMappingURL=skipToContentUtils.js.map