@docusaurus/theme-common 2.0.0-beta.1decd6f80 → 2.0.0-beta.20

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 (250) hide show
  1. package/Details.d.ts +14 -0
  2. package/lib/components/Collapsible/index.d.ts +64 -0
  3. package/lib/components/Collapsible/index.d.ts.map +1 -0
  4. package/lib/components/Collapsible/index.js +152 -0
  5. package/lib/components/Collapsible/index.js.map +1 -0
  6. package/lib/components/Details/index.d.ts +17 -0
  7. package/lib/components/Details/index.d.ts.map +1 -0
  8. package/lib/components/Details/index.js +71 -0
  9. package/lib/components/Details/index.js.map +1 -0
  10. package/lib/components/Details/styles.module.css +62 -0
  11. package/lib/contexts/announcementBar.d.ts +22 -0
  12. package/lib/contexts/announcementBar.d.ts.map +1 -0
  13. package/lib/contexts/announcementBar.js +72 -0
  14. package/lib/contexts/announcementBar.js.map +1 -0
  15. package/lib/contexts/colorMode.d.ts +27 -0
  16. package/lib/contexts/colorMode.d.ts.map +1 -0
  17. package/lib/contexts/colorMode.js +132 -0
  18. package/lib/contexts/colorMode.js.map +1 -0
  19. package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
  20. package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
  21. package/lib/contexts/docSidebarItemsExpandedState.js +28 -0
  22. package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
  23. package/lib/contexts/docsPreferredVersion.d.ts +31 -0
  24. package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
  25. package/lib/contexts/docsPreferredVersion.js +128 -0
  26. package/lib/contexts/docsPreferredVersion.js.map +1 -0
  27. package/lib/contexts/docsSidebar.d.ts +26 -0
  28. package/lib/contexts/docsSidebar.d.ts.map +1 -0
  29. package/lib/contexts/docsSidebar.js +30 -0
  30. package/lib/contexts/docsSidebar.js.map +1 -0
  31. package/lib/contexts/docsVersion.d.ts +20 -0
  32. package/lib/contexts/docsVersion.d.ts.map +1 -0
  33. package/lib/contexts/docsVersion.js +26 -0
  34. package/lib/contexts/docsVersion.js.map +1 -0
  35. package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
  36. package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
  37. package/lib/contexts/navbarMobileSidebar.js +56 -0
  38. package/lib/contexts/navbarMobileSidebar.js.map +1 -0
  39. package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
  40. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
  41. package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
  42. package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
  43. package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
  44. package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
  45. package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
  46. package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
  47. package/lib/contexts/tabGroupChoice.d.ts +21 -0
  48. package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
  49. package/lib/contexts/tabGroupChoice.js +49 -0
  50. package/lib/contexts/tabGroupChoice.js.map +1 -0
  51. package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
  52. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  53. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  54. package/lib/hooks/useBackToTopButton.js +50 -0
  55. package/lib/hooks/useBackToTopButton.js.map +1 -0
  56. package/lib/hooks/useCodeWordWrap.d.ts +14 -0
  57. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  58. package/lib/hooks/useCodeWordWrap.js +41 -0
  59. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  60. package/lib/hooks/useHideableNavbar.d.ts +17 -0
  61. package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
  62. package/lib/hooks/useHideableNavbar.js +60 -0
  63. package/lib/hooks/useHideableNavbar.js.map +1 -0
  64. package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
  65. package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
  66. package/lib/hooks/useKeyboardNavigation.js +39 -0
  67. package/lib/hooks/useKeyboardNavigation.js.map +1 -0
  68. package/lib/hooks/useLockBodyScroll.d.ts +12 -0
  69. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
  70. package/lib/hooks/useLockBodyScroll.js +20 -0
  71. package/lib/hooks/useLockBodyScroll.js.map +1 -0
  72. package/lib/hooks/usePrismTheme.d.ts +13 -0
  73. package/lib/hooks/usePrismTheme.d.ts.map +1 -0
  74. package/lib/hooks/usePrismTheme.js +21 -0
  75. package/lib/hooks/usePrismTheme.js.map +1 -0
  76. package/lib/hooks/useSearchPage.d.ts +25 -0
  77. package/lib/hooks/useSearchPage.d.ts.map +1 -0
  78. package/lib/hooks/useSearchPage.js +43 -0
  79. package/lib/hooks/useSearchPage.js.map +1 -0
  80. package/lib/hooks/useSkipToContent.d.ts +25 -0
  81. package/lib/hooks/useSkipToContent.d.ts.map +1 -0
  82. package/lib/hooks/useSkipToContent.js +35 -0
  83. package/lib/hooks/useSkipToContent.js.map +1 -0
  84. package/lib/hooks/useTOCHighlight.d.ts +25 -0
  85. package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
  86. package/lib/hooks/useTOCHighlight.js +130 -0
  87. package/lib/hooks/useTOCHighlight.js.map +1 -0
  88. package/lib/hooks/useWindowSize.d.ts +28 -0
  89. package/lib/hooks/useWindowSize.d.ts.map +1 -0
  90. package/lib/hooks/useWindowSize.js +59 -0
  91. package/lib/hooks/useWindowSize.js.map +1 -0
  92. package/lib/index.d.ts +39 -9
  93. package/lib/index.d.ts.map +1 -0
  94. package/lib/index.js +39 -8
  95. package/lib/index.js.map +1 -0
  96. package/lib/utils/ThemeClassNames.d.ts +47 -12
  97. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  98. package/lib/utils/ThemeClassNames.js +45 -4
  99. package/lib/utils/ThemeClassNames.js.map +1 -0
  100. package/lib/utils/codeBlockUtils.d.ts +63 -0
  101. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  102. package/lib/utils/codeBlockUtils.js +157 -3
  103. package/lib/utils/codeBlockUtils.js.map +1 -0
  104. package/lib/utils/docsUtils.d.ts +91 -0
  105. package/lib/utils/docsUtils.d.ts.map +1 -0
  106. package/lib/utils/docsUtils.js +217 -1
  107. package/lib/utils/docsUtils.js.map +1 -0
  108. package/lib/utils/footerUtils.d.ts +13 -0
  109. package/lib/utils/footerUtils.d.ts.map +1 -0
  110. package/lib/utils/footerUtils.js +14 -0
  111. package/lib/utils/footerUtils.js.map +1 -0
  112. package/lib/utils/generalUtils.d.ts +11 -1
  113. package/lib/utils/generalUtils.d.ts.map +1 -0
  114. package/lib/utils/generalUtils.js +9 -5
  115. package/lib/utils/generalUtils.js.map +1 -0
  116. package/lib/utils/historyUtils.d.ts +17 -0
  117. package/lib/utils/historyUtils.d.ts.map +1 -0
  118. package/lib/utils/historyUtils.js +38 -0
  119. package/lib/utils/historyUtils.js.map +1 -0
  120. package/lib/utils/jsUtils.d.ts +23 -0
  121. package/lib/utils/jsUtils.d.ts.map +1 -0
  122. package/lib/utils/jsUtils.js +29 -0
  123. package/lib/utils/jsUtils.js.map +1 -0
  124. package/lib/utils/metadataUtils.d.ts +38 -0
  125. package/lib/utils/metadataUtils.d.ts.map +1 -0
  126. package/lib/utils/metadataUtils.js +61 -0
  127. package/lib/utils/metadataUtils.js.map +1 -0
  128. package/lib/utils/navbarUtils.d.ts +21 -0
  129. package/lib/utils/navbarUtils.d.ts.map +1 -0
  130. package/lib/utils/navbarUtils.js +32 -0
  131. package/lib/utils/navbarUtils.js.map +1 -0
  132. package/lib/utils/reactUtils.d.ts +42 -0
  133. package/lib/utils/reactUtils.d.ts.map +1 -0
  134. package/lib/utils/reactUtils.js +64 -0
  135. package/lib/utils/reactUtils.js.map +1 -0
  136. package/lib/utils/regexpUtils.d.ts +12 -0
  137. package/lib/utils/regexpUtils.d.ts.map +1 -0
  138. package/lib/utils/regexpUtils.js +18 -0
  139. package/lib/utils/regexpUtils.js.map +1 -0
  140. package/lib/utils/routesUtils.d.ts +26 -0
  141. package/lib/utils/routesUtils.d.ts.map +1 -0
  142. package/lib/utils/routesUtils.js +54 -0
  143. package/lib/utils/routesUtils.js.map +1 -0
  144. package/lib/utils/scrollUtils.d.ts +83 -0
  145. package/lib/utils/scrollUtils.d.ts.map +1 -0
  146. package/lib/utils/scrollUtils.js +200 -0
  147. package/lib/utils/scrollUtils.js.map +1 -0
  148. package/lib/utils/searchUtils.d.ts +13 -0
  149. package/lib/utils/searchUtils.d.ts.map +1 -0
  150. package/lib/utils/searchUtils.js +37 -0
  151. package/lib/utils/searchUtils.js.map +1 -0
  152. package/lib/utils/storageUtils.d.ts +15 -7
  153. package/lib/utils/storageUtils.d.ts.map +1 -0
  154. package/lib/utils/storageUtils.js +58 -25
  155. package/lib/utils/storageUtils.js.map +1 -0
  156. package/lib/utils/tagsUtils.d.ts +18 -0
  157. package/lib/utils/tagsUtils.d.ts.map +1 -0
  158. package/lib/utils/tagsUtils.js +36 -0
  159. package/lib/utils/tagsUtils.js.map +1 -0
  160. package/lib/utils/tocUtils.d.ts +36 -0
  161. package/lib/utils/tocUtils.d.ts.map +1 -0
  162. package/lib/utils/tocUtils.js +84 -0
  163. package/lib/utils/tocUtils.js.map +1 -0
  164. package/lib/utils/useAlternatePageUtils.d.ts +21 -1
  165. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  166. package/lib/utils/useAlternatePageUtils.js +9 -4
  167. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  168. package/lib/utils/useLocalPathname.d.ts +13 -0
  169. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  170. package/lib/utils/useLocalPathname.js +19 -0
  171. package/lib/utils/useLocalPathname.js.map +1 -0
  172. package/lib/utils/useLocationChange.d.ts +17 -0
  173. package/lib/utils/useLocationChange.d.ts.map +1 -0
  174. package/lib/utils/useLocationChange.js +31 -0
  175. package/lib/utils/useLocationChange.js.map +1 -0
  176. package/lib/utils/usePluralForm.d.ts +12 -0
  177. package/lib/utils/usePluralForm.d.ts.map +1 -0
  178. package/lib/utils/usePluralForm.js +36 -37
  179. package/lib/utils/usePluralForm.js.map +1 -0
  180. package/lib/utils/useThemeConfig.d.ts +55 -23
  181. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  182. package/lib/utils/useThemeConfig.js +4 -0
  183. package/lib/utils/useThemeConfig.js.map +1 -0
  184. package/package.json +26 -13
  185. package/src/components/Collapsible/index.tsx +265 -0
  186. package/src/components/Details/index.tsx +109 -0
  187. package/src/components/Details/styles.module.css +62 -0
  188. package/src/contexts/announcementBar.tsx +119 -0
  189. package/src/contexts/colorMode.tsx +199 -0
  190. package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
  191. package/src/contexts/docsPreferredVersion.tsx +253 -0
  192. package/src/contexts/docsSidebar.tsx +50 -0
  193. package/src/contexts/docsVersion.tsx +36 -0
  194. package/src/contexts/navbarMobileSidebar.tsx +99 -0
  195. package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
  196. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  197. package/src/contexts/tabGroupChoice.tsx +85 -0
  198. package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
  199. package/src/hooks/useBackToTopButton.ts +73 -0
  200. package/src/hooks/useCodeWordWrap.ts +56 -0
  201. package/src/hooks/useHideableNavbar.ts +75 -0
  202. package/src/hooks/useKeyboardNavigation.ts +45 -0
  203. package/src/hooks/useLockBodyScroll.ts +21 -0
  204. package/src/hooks/usePrismTheme.ts +24 -0
  205. package/src/hooks/useSearchPage.ts +79 -0
  206. package/src/hooks/useSkipToContent.ts +58 -0
  207. package/src/hooks/useTOCHighlight.ts +192 -0
  208. package/src/hooks/useWindowSize.ts +72 -0
  209. package/src/index.ts +136 -18
  210. package/src/types.d.ts +0 -2
  211. package/src/utils/ThemeClassNames.ts +51 -5
  212. package/src/utils/codeBlockUtils.ts +239 -2
  213. package/src/utils/docsUtils.tsx +334 -0
  214. package/src/utils/footerUtils.ts +18 -0
  215. package/src/utils/generalUtils.ts +9 -5
  216. package/src/utils/historyUtils.ts +45 -0
  217. package/src/utils/jsUtils.ts +36 -0
  218. package/src/utils/metadataUtils.tsx +115 -0
  219. package/src/utils/navbarUtils.tsx +45 -0
  220. package/src/utils/reactUtils.tsx +76 -0
  221. package/src/utils/regexpUtils.ts +24 -0
  222. package/src/utils/routesUtils.ts +75 -0
  223. package/src/utils/scrollUtils.tsx +308 -0
  224. package/src/utils/searchUtils.ts +51 -0
  225. package/src/utils/storageUtils.ts +59 -26
  226. package/src/utils/tagsUtils.ts +50 -0
  227. package/src/utils/tocUtils.ts +119 -0
  228. package/src/utils/useAlternatePageUtils.ts +28 -7
  229. package/src/utils/useLocalPathname.ts +22 -0
  230. package/src/utils/useLocationChange.ts +41 -0
  231. package/src/utils/usePluralForm.ts +49 -39
  232. package/src/utils/useThemeConfig.ts +54 -25
  233. package/lib/.tsbuildinfo +0 -4115
  234. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
  235. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
  236. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
  237. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
  238. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
  239. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
  240. package/lib/utils/pathUtils.js +0 -13
  241. package/lib/utils/useChangeRoute.js +0 -18
  242. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  243. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  244. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
  245. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
  246. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
  247. package/src/utils/docsUtils.ts +0 -11
  248. package/src/utils/pathUtils.ts +0 -17
  249. package/src/utils/useChangeRoute.ts +0 -21
  250. package/tsconfig.json +0 -10
@@ -4,19 +4,54 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ /**
8
+ * These class names are used to style page layouts in Docusaurus, meant to be
9
+ * targeted by user-provided custom CSS selectors.
10
+ */
7
11
  export declare const ThemeClassNames: {
8
- page: {
9
- blogListPage: string;
10
- blogPostPage: string;
11
- blogTagsListPage: string;
12
- blogTagsPostPage: string;
13
- docPage: string;
14
- mdxPage: string;
12
+ readonly page: {
13
+ readonly blogListPage: "blog-list-page";
14
+ readonly blogPostPage: "blog-post-page";
15
+ readonly blogTagsListPage: "blog-tags-list-page";
16
+ readonly blogTagPostListPage: "blog-tags-post-list-page";
17
+ readonly docsDocPage: "docs-doc-page";
18
+ readonly docsTagsListPage: "docs-tags-list-page";
19
+ readonly docsTagDocListPage: "docs-tags-doc-list-page";
20
+ readonly mdxPage: "mdx-page";
21
+ };
22
+ readonly wrapper: {
23
+ readonly main: "main-wrapper";
24
+ readonly blogPages: "blog-wrapper";
25
+ readonly docsPages: "docs-wrapper";
26
+ readonly mdxPages: "mdx-wrapper";
27
+ };
28
+ /**
29
+ * Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
30
+ */
31
+ readonly common: {
32
+ readonly editThisPage: "theme-edit-this-page";
33
+ readonly lastUpdated: "theme-last-updated";
34
+ readonly backToTopButton: "theme-back-to-top-button";
35
+ readonly codeBlock: "theme-code-block";
15
36
  };
16
- wrapper: {
17
- main: string;
18
- blogPages: string;
19
- docPages: string;
20
- mdxPages: string;
37
+ readonly layout: {};
38
+ readonly docs: {
39
+ readonly docVersionBanner: "theme-doc-version-banner";
40
+ readonly docVersionBadge: "theme-doc-version-badge";
41
+ readonly docBreadcrumbs: "theme-doc-breadcrumbs";
42
+ readonly docMarkdown: "theme-doc-markdown";
43
+ readonly docTocMobile: "theme-doc-toc-mobile";
44
+ readonly docTocDesktop: "theme-doc-toc-desktop";
45
+ readonly docFooter: "theme-doc-footer";
46
+ readonly docFooterTagsRow: "theme-doc-footer-tags-row";
47
+ readonly docFooterEditMetaRow: "theme-doc-footer-edit-meta-row";
48
+ readonly docSidebarContainer: "theme-doc-sidebar-container";
49
+ readonly docSidebarMenu: "theme-doc-sidebar-menu";
50
+ readonly docSidebarItemCategory: "theme-doc-sidebar-item-category";
51
+ readonly docSidebarItemLink: "theme-doc-sidebar-item-link";
52
+ readonly docSidebarItemCategoryLevel: (level: number) => `theme-doc-sidebar-item-category-level-${number}`;
53
+ readonly docSidebarItemLinkLevel: (level: number) => `theme-doc-sidebar-item-link-level-${number}`;
21
54
  };
55
+ readonly blog: {};
22
56
  };
57
+ //# sourceMappingURL=ThemeClassNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeClassNames.d.ts","sourceRoot":"","sources":["../../src/utils/ThemeClassNames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;IAoB1B;;OAEG;;;;;;;;;;;;;;;;;;;;;;sDAwBoC,MAAM;kDAEV,MAAM;;;CAOjC,CAAC"}
@@ -4,20 +4,61 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- // These class names are used to style page layouts in Docusaurus
7
+ // Please do not modify the classnames! This is a breaking change, and annoying
8
+ // for users!
9
+ /**
10
+ * These class names are used to style page layouts in Docusaurus, meant to be
11
+ * targeted by user-provided custom CSS selectors.
12
+ */
8
13
  export const ThemeClassNames = {
9
14
  page: {
10
15
  blogListPage: 'blog-list-page',
11
16
  blogPostPage: 'blog-post-page',
12
17
  blogTagsListPage: 'blog-tags-list-page',
13
- blogTagsPostPage: 'blog-tags-post-page',
14
- docPage: 'doc-page',
18
+ blogTagPostListPage: 'blog-tags-post-list-page',
19
+ docsDocPage: 'docs-doc-page',
20
+ docsTagsListPage: 'docs-tags-list-page',
21
+ docsTagDocListPage: 'docs-tags-doc-list-page',
15
22
  mdxPage: 'mdx-page',
16
23
  },
17
24
  wrapper: {
18
25
  main: 'main-wrapper',
19
26
  blogPages: 'blog-wrapper',
20
- docPages: 'docs-wrapper',
27
+ docsPages: 'docs-wrapper',
21
28
  mdxPages: 'mdx-wrapper',
22
29
  },
30
+ /**
31
+ * Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
32
+ */
33
+ common: {
34
+ editThisPage: 'theme-edit-this-page',
35
+ lastUpdated: 'theme-last-updated',
36
+ backToTopButton: 'theme-back-to-top-button',
37
+ codeBlock: 'theme-code-block',
38
+ },
39
+ layout: {
40
+ // TODO add other stable classNames here
41
+ },
42
+ docs: {
43
+ docVersionBanner: 'theme-doc-version-banner',
44
+ docVersionBadge: 'theme-doc-version-badge',
45
+ docBreadcrumbs: 'theme-doc-breadcrumbs',
46
+ docMarkdown: 'theme-doc-markdown',
47
+ docTocMobile: 'theme-doc-toc-mobile',
48
+ docTocDesktop: 'theme-doc-toc-desktop',
49
+ docFooter: 'theme-doc-footer',
50
+ docFooterTagsRow: 'theme-doc-footer-tags-row',
51
+ docFooterEditMetaRow: 'theme-doc-footer-edit-meta-row',
52
+ docSidebarContainer: 'theme-doc-sidebar-container',
53
+ docSidebarMenu: 'theme-doc-sidebar-menu',
54
+ docSidebarItemCategory: 'theme-doc-sidebar-item-category',
55
+ docSidebarItemLink: 'theme-doc-sidebar-item-link',
56
+ docSidebarItemCategoryLevel: (level) => `theme-doc-sidebar-item-category-level-${level}`,
57
+ docSidebarItemLinkLevel: (level) => `theme-doc-sidebar-item-link-level-${level}`,
58
+ // TODO add other stable classNames here
59
+ },
60
+ blog: {
61
+ // TODO add other stable classNames here
62
+ },
23
63
  };
64
+ //# sourceMappingURL=ThemeClassNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeClassNames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C;KACzC;IACD,IAAI,EAAE;IACJ,wCAAwC;KACzC;CACO,CAAC"}
@@ -4,4 +4,67 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ import type { PrismTheme } from 'prism-react-renderer';
8
+ import type { CSSProperties } from 'react';
9
+ export declare type MagicCommentConfig = {
10
+ className: string;
11
+ line?: string;
12
+ block?: {
13
+ start: string;
14
+ end: string;
15
+ };
16
+ };
7
17
  export declare function parseCodeBlockTitle(metastring?: string): string;
18
+ export declare function containsLineNumbers(metastring?: string): boolean;
19
+ /**
20
+ * Gets the language name from the class name (set by MDX).
21
+ * e.g. `"language-javascript"` => `"javascript"`.
22
+ * Returns undefined if there is no language class name.
23
+ */
24
+ export declare function parseLanguage(className: string): string | undefined;
25
+ /**
26
+ * Parses the code content, strips away any magic comments, and returns the
27
+ * clean content and the highlighted lines marked by the comments or metastring.
28
+ *
29
+ * If the metastring contains a range, the `content` will be returned as-is
30
+ * without any parsing. The returned `lineClassNames` will be a map from that
31
+ * number range to the first magic comment config entry (which _should_ be for
32
+ * line highlight directives.)
33
+ *
34
+ * @param content The raw code with magic comments. Trailing newline will be
35
+ * trimmed upfront.
36
+ * @param options Options for parsing behavior.
37
+ */
38
+ export declare function parseLines(content: string, options: {
39
+ /**
40
+ * The full metastring, as received from MDX. Line ranges declared here
41
+ * start at 1.
42
+ */
43
+ metastring: string | undefined;
44
+ /**
45
+ * Language of the code block, used to determine which kinds of magic
46
+ * comment styles to enable.
47
+ */
48
+ language: string | undefined;
49
+ /**
50
+ * Magic comment types that we should try to parse. Each entry would
51
+ * correspond to one class name to apply to each line.
52
+ */
53
+ magicComments: MagicCommentConfig[];
54
+ }): {
55
+ /**
56
+ * The highlighted lines, 0-indexed. e.g. `{ 0: ["highlight", "sample"] }`
57
+ * means the 1st line should have `highlight` and `sample` as class names.
58
+ */
59
+ lineClassNames: {
60
+ [lineIndex: number]: string[];
61
+ };
62
+ /**
63
+ * If there's number range declared in the metastring, the code block is
64
+ * returned as-is (no parsing); otherwise, this is the clean code with all
65
+ * magic comments stripped away.
66
+ */
67
+ code: string;
68
+ };
69
+ export declare function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties;
70
+ //# sourceMappingURL=codeBlockUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeBlockUtils.d.ts","sourceRoot":"","sources":["../../src/utils/codeBlockUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAgBzC,oBAAY,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAC;CACtC,CAAC;AAiEF,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKnE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IACP;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B;;;OAGG;IACH,aAAa,EAAE,kBAAkB,EAAE,CAAC;CACrC,GACA;IACD;;;OAGG;IACH,cAAc,EAAE;QAAC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAC,CAAC;IAChD;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CA0EA;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa,CAc1E"}
@@ -4,8 +4,162 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- const codeBlockTitleRegex = /title=(["'])(.*?)\1/;
7
+ import rangeParser from 'parse-numeric-range';
8
+ const codeBlockTitleRegex = /title=(?<quote>["'])(?<title>.*?)\1/;
9
+ const metastringLinesRangeRegex = /\{(?<range>[\d,-]+)\}/;
10
+ // Supported types of highlight comments
11
+ const commentPatterns = {
12
+ js: { start: '\\/\\/', end: '' },
13
+ jsBlock: { start: '\\/\\*', end: '\\*\\/' },
14
+ jsx: { start: '\\{\\s*\\/\\*', end: '\\*\\/\\s*\\}' },
15
+ bash: { start: '#', end: '' },
16
+ html: { start: '<!--', end: '-->' },
17
+ };
18
+ function getCommentPattern(languages, magicCommentDirectives) {
19
+ // To be more reliable, the opening and closing comment must match
20
+ const commentPattern = languages
21
+ .map((lang) => {
22
+ const { start, end } = commentPatterns[lang];
23
+ return `(?:${start}\\s*(${magicCommentDirectives
24
+ .flatMap((d) => [d.line, d.block?.start, d.block?.end].filter(Boolean))
25
+ .join('|')})\\s*${end})`;
26
+ })
27
+ .join('|');
28
+ // White space is allowed, but otherwise it should be on it's own line
29
+ return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
30
+ }
31
+ /**
32
+ * Select comment styles based on language
33
+ */
34
+ function getAllMagicCommentDirectiveStyles(lang, magicCommentDirectives) {
35
+ switch (lang) {
36
+ case 'js':
37
+ case 'javascript':
38
+ case 'ts':
39
+ case 'typescript':
40
+ return getCommentPattern(['js', 'jsBlock'], magicCommentDirectives);
41
+ case 'jsx':
42
+ case 'tsx':
43
+ return getCommentPattern(['js', 'jsBlock', 'jsx'], magicCommentDirectives);
44
+ case 'html':
45
+ return getCommentPattern(['js', 'jsBlock', 'html'], magicCommentDirectives);
46
+ case 'python':
47
+ case 'py':
48
+ case 'bash':
49
+ return getCommentPattern(['bash'], magicCommentDirectives);
50
+ case 'markdown':
51
+ case 'md':
52
+ // Text uses HTML, front matter uses bash
53
+ return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives);
54
+ default:
55
+ // All comment types
56
+ return getCommentPattern(Object.keys(commentPatterns), magicCommentDirectives);
57
+ }
58
+ }
8
59
  export function parseCodeBlockTitle(metastring) {
9
- var _a, _b;
10
- return (_b = (_a = metastring === null || metastring === void 0 ? void 0 : metastring.match(codeBlockTitleRegex)) === null || _a === void 0 ? void 0 : _a[2]) !== null && _b !== void 0 ? _b : '';
60
+ return metastring?.match(codeBlockTitleRegex)?.groups.title ?? '';
61
+ }
62
+ export function containsLineNumbers(metastring) {
63
+ return metastring?.includes('showLineNumbers') || false;
64
+ }
65
+ /**
66
+ * Gets the language name from the class name (set by MDX).
67
+ * e.g. `"language-javascript"` => `"javascript"`.
68
+ * Returns undefined if there is no language class name.
69
+ */
70
+ export function parseLanguage(className) {
71
+ const languageClassName = className
72
+ .split(' ')
73
+ .find((str) => str.startsWith('language-'));
74
+ return languageClassName?.replace(/language-/, '');
75
+ }
76
+ /**
77
+ * Parses the code content, strips away any magic comments, and returns the
78
+ * clean content and the highlighted lines marked by the comments or metastring.
79
+ *
80
+ * If the metastring contains a range, the `content` will be returned as-is
81
+ * without any parsing. The returned `lineClassNames` will be a map from that
82
+ * number range to the first magic comment config entry (which _should_ be for
83
+ * line highlight directives.)
84
+ *
85
+ * @param content The raw code with magic comments. Trailing newline will be
86
+ * trimmed upfront.
87
+ * @param options Options for parsing behavior.
88
+ */
89
+ export function parseLines(content, options) {
90
+ let code = content.replace(/\n$/, '');
91
+ const { language, magicComments, metastring } = options;
92
+ // Highlighted lines specified in props: don't parse the content
93
+ if (metastring && metastringLinesRangeRegex.test(metastring)) {
94
+ const linesRange = metastring.match(metastringLinesRangeRegex).groups
95
+ .range;
96
+ if (magicComments.length === 0) {
97
+ throw new Error(`A highlight range has been given in code block's metastring (\`\`\` ${metastring}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`);
98
+ }
99
+ const metastringRangeClassName = magicComments[0].className;
100
+ const lines = rangeParser(linesRange)
101
+ .filter((n) => n > 0)
102
+ .map((n) => [n - 1, [metastringRangeClassName]]);
103
+ return { lineClassNames: Object.fromEntries(lines), code };
104
+ }
105
+ if (language === undefined) {
106
+ return { lineClassNames: {}, code };
107
+ }
108
+ const directiveRegex = getAllMagicCommentDirectiveStyles(language, magicComments);
109
+ // Go through line by line
110
+ const lines = code.split('\n');
111
+ const blocks = Object.fromEntries(magicComments.map((d) => [d.className, { start: 0, range: '' }]));
112
+ const lineToClassName = Object.fromEntries(magicComments
113
+ .filter((d) => d.line)
114
+ .map(({ className, line }) => [line, className]));
115
+ const blockStartToClassName = Object.fromEntries(magicComments
116
+ .filter((d) => d.block)
117
+ .map(({ className, block }) => [block.start, className]));
118
+ const blockEndToClassName = Object.fromEntries(magicComments
119
+ .filter((d) => d.block)
120
+ .map(({ className, block }) => [block.end, className]));
121
+ for (let lineNumber = 0; lineNumber < lines.length;) {
122
+ const line = lines[lineNumber];
123
+ const match = line.match(directiveRegex);
124
+ if (!match) {
125
+ // Lines without directives are unchanged
126
+ lineNumber += 1;
127
+ continue;
128
+ }
129
+ const directive = match.slice(1).find((item) => item !== undefined);
130
+ if (lineToClassName[directive]) {
131
+ blocks[lineToClassName[directive]].range += `${lineNumber},`;
132
+ }
133
+ else if (blockStartToClassName[directive]) {
134
+ blocks[blockStartToClassName[directive]].start = lineNumber;
135
+ }
136
+ else if (blockEndToClassName[directive]) {
137
+ blocks[blockEndToClassName[directive]].range += `${blocks[blockEndToClassName[directive]].start}-${lineNumber - 1},`;
138
+ }
139
+ lines.splice(lineNumber, 1);
140
+ }
141
+ code = lines.join('\n');
142
+ const lineClassNames = {};
143
+ Object.entries(blocks).forEach(([className, { range }]) => {
144
+ rangeParser(range).forEach((l) => {
145
+ lineClassNames[l] ?? (lineClassNames[l] = []);
146
+ lineClassNames[l].push(className);
147
+ });
148
+ });
149
+ return { lineClassNames, code };
150
+ }
151
+ export function getPrismCssVariables(prismTheme) {
152
+ const mapping = {
153
+ color: '--prism-color',
154
+ backgroundColor: '--prism-background-color',
155
+ };
156
+ const properties = {};
157
+ Object.entries(prismTheme.plain).forEach(([key, value]) => {
158
+ const varName = mapping[key];
159
+ if (varName && typeof value === 'string') {
160
+ properties[varName] = value;
161
+ }
162
+ });
163
+ return properties;
11
164
  }
165
+ //# sourceMappingURL=codeBlockUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeBlockUtils.js","sourceRoot":"","sources":["../../src/utils/codeBlockUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAI9C,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAClE,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAE1D,wCAAwC;AACxC,MAAM,eAAe,GAAG;IACtB,EAAE,EAAE,EAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAC;IAC9B,OAAO,EAAE,EAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAC;IACzC,GAAG,EAAE,EAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe,EAAC;IACnD,IAAI,EAAE,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAC;IAC3B,IAAI,EAAE,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAC;CAClC,CAAC;AAUF,SAAS,iBAAiB,CACxB,SAAwB,EACxB,sBAA4C;IAE5C,kEAAkE;IAClE,MAAM,cAAc,GAAG,SAAS;SAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,EAAC,KAAK,EAAE,GAAG,EAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO,MA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AAC,GAAG,CAAC;SACvB;QACD,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;KAC7B;IACD,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,MAAM,cAAc,GAAoC,EAAE,CAAC;IAC3D,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,EAAC,KAAK,EAAC,CAAC,EAAE,EAAE;QACtD,WAAW,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC/B,cAAc,CAAC,CAAC,MAAhB,cAAc,CAAC,CAAC,IAAM,EAAE,EAAC;YACzB,cAAc,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAsB;IACzD,MAAM,OAAO,GAAgD;QAC3D,KAAK,EAAE,eAAe;QACtB,eAAe,EAAE,0BAA0B;KAC5C,CAAC;IAEF,MAAM,UAAU,GAA4B,EAAE,CAAC;IAC/C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACxD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACxC,UAAU,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;SAC7B;IACH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -4,4 +4,95 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ /// <reference types="react" />
8
+ import { type GlobalVersion, type GlobalSidebar, type GlobalDoc } from '@docusaurus/plugin-content-docs/client';
9
+ import type { PropSidebar, PropSidebarItem, PropSidebarItemCategory, PropVersionDoc, PropSidebarBreadcrumbsItem } from '@docusaurus/plugin-content-docs';
10
+ import type { Props as DocPageProps } from '@theme/DocPage';
7
11
  export declare const isDocsPluginEnabled: boolean;
12
+ /**
13
+ * A null-safe way to access a doc's data by ID in the active version.
14
+ */
15
+ export declare function useDocById(id: string): PropVersionDoc;
16
+ /**
17
+ * A null-safe way to access a doc's data by ID in the active version.
18
+ */
19
+ export declare function useDocById(id: string | undefined): PropVersionDoc | undefined;
20
+ /**
21
+ * Pure function, similar to `Array#find`, but works on the sidebar tree.
22
+ */
23
+ export declare function findSidebarCategory(sidebar: PropSidebar, predicate: (category: PropSidebarItemCategory) => boolean): PropSidebarItemCategory | undefined;
24
+ /**
25
+ * Best effort to assign a link to a sidebar category. If the category doesn't
26
+ * have a link itself, we link to the first sub item with a link.
27
+ */
28
+ export declare function findFirstCategoryLink(item: PropSidebarItemCategory): string | undefined;
29
+ /**
30
+ * Gets the category associated with the current location. Should only be used
31
+ * on category index pages.
32
+ */
33
+ export declare function useCurrentSidebarCategory(): PropSidebarItemCategory;
34
+ /**
35
+ * Checks if a sidebar item should be active, based on the active path.
36
+ */
37
+ export declare function isActiveSidebarItem(item: PropSidebarItem, activePath: string): boolean;
38
+ /**
39
+ * Gets the breadcrumbs of the current doc page, based on its sidebar location.
40
+ * Returns `null` if there's no sidebar or breadcrumbs are disabled.
41
+ */
42
+ export declare function useSidebarBreadcrumbs(): PropSidebarBreadcrumbsItem[] | null;
43
+ /**
44
+ * "Version candidates" are mostly useful for the layout components, which must
45
+ * be able to work on all pages. For example, if a user has `{ type: "doc",
46
+ * docId: "intro" }` as a navbar item, which version does that refer to? We
47
+ * believe that it could refer to at most three version candidates:
48
+ *
49
+ * 1. The **active version**, the one that the user is currently browsing. See
50
+ * {@link useActiveDocContext}.
51
+ * 2. The **preferred version**, the one that the user last visited. See
52
+ * {@link useDocsPreferredVersion}.
53
+ * 3. The **latest version**, the "default". See {@link useLatestVersion}.
54
+ *
55
+ * @param docsPluginId The plugin ID to get versions from.
56
+ * @returns An array of 1~3 versions with priorities defined above, guaranteed
57
+ * to be unique and non-sparse. Will be memoized, hence stable for deps array.
58
+ */
59
+ export declare function useDocsVersionCandidates(docsPluginId?: string): [GlobalVersion, ...GlobalVersion[]];
60
+ /**
61
+ * The layout components, like navbar items, must be able to work on all pages,
62
+ * even on non-doc ones where there's no version context, so a sidebar ID could
63
+ * be ambiguous. This hook would always return a sidebar to be linked to. See
64
+ * also {@link useDocsVersionCandidates} for how this selection is done.
65
+ *
66
+ * @throws This hook throws if a sidebar with said ID is not found.
67
+ */
68
+ export declare function useLayoutDocsSidebar(sidebarId: string, docsPluginId?: string): GlobalSidebar;
69
+ /**
70
+ * The layout components, like navbar items, must be able to work on all pages,
71
+ * even on non-doc ones where there's no version context, so a doc ID could be
72
+ * ambiguous. This hook would always return a doc to be linked to. See also
73
+ * {@link useDocsVersionCandidates} for how this selection is done.
74
+ *
75
+ * @throws This hook throws if a doc with said ID is not found.
76
+ */
77
+ export declare function useLayoutDoc(docId: string, docsPluginId?: string): GlobalDoc | null;
78
+ /**
79
+ * The docs plugin creates nested routes, with the top-level route providing the
80
+ * version metadata, and the subroutes creating individual doc pages. This hook
81
+ * will match the current location against all known sub-routes.
82
+ *
83
+ * @param props The props received by `@theme/DocPage`
84
+ * @returns The data of the relevant document at the current location, or `null`
85
+ * if no document associated with the current location can be found.
86
+ */
87
+ export declare function useDocRouteMetadata({ route, versionMetadata, }: DocPageProps): null | {
88
+ /** The element that should be rendered at the current location. */
89
+ docElement: JSX.Element;
90
+ /**
91
+ * The name of the sidebar associated with the current doc. `sidebarName` and
92
+ * `sidebarItems` correspond to the value of {@link useDocsSidebar}.
93
+ */
94
+ sidebarName: string | undefined;
95
+ /** The items of the sidebar associated with the current doc. */
96
+ sidebarItems: PropSidebar | undefined;
97
+ };
98
+ //# sourceMappingURL=docsUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/docsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAGH,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAC,KAAK,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAU1D,eAAO,MAAM,mBAAmB,EAAE,OAA0B,CAAC;AAE7D;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,CAAC;AACvD;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC;AAa/E;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,CAAC,QAAQ,EAAE,uBAAuB,KAAK,OAAO,GACxD,uBAAuB,GAAG,SAAS,CAarC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,uBAAuB,GAC5B,MAAM,GAAG,SAAS,CAiBpB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,uBAAuB,CAenE;AASD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAaT;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,EAAE,GAAG,IAAI,CA6B3E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,CAAC,EAAE,MAAM,GACpB,CAAC,aAAa,EAAE,GAA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