@apify/docusaurus-plugin-typedoc-api 3.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 (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -0
  3. package/assets/styles-8ad572ec.css +303 -0
  4. package/lib/components/AnchorLink.js +22 -0
  5. package/lib/components/AnchorLink.js.map +1 -0
  6. package/lib/components/ApiChangelog.js +28 -0
  7. package/lib/components/ApiChangelog.js.map +1 -0
  8. package/lib/components/ApiDataContext.js +16 -0
  9. package/lib/components/ApiDataContext.js.map +1 -0
  10. package/lib/components/ApiIndex.js +80 -0
  11. package/lib/components/ApiIndex.js.map +1 -0
  12. package/lib/components/ApiItem.js +86 -0
  13. package/lib/components/ApiItem.js.map +1 -0
  14. package/lib/components/ApiItemLayout.js +69 -0
  15. package/lib/components/ApiItemLayout.js.map +1 -0
  16. package/lib/components/ApiPage.js +69 -0
  17. package/lib/components/ApiPage.js.map +1 -0
  18. package/lib/components/Breadcrumb.js +38 -0
  19. package/lib/components/Breadcrumb.js.map +1 -0
  20. package/lib/components/Comment.js +56 -0
  21. package/lib/components/Comment.js.map +1 -0
  22. package/lib/components/CommentBadges.js +35 -0
  23. package/lib/components/CommentBadges.js.map +1 -0
  24. package/lib/components/DefaultValue.js +49 -0
  25. package/lib/components/DefaultValue.js.map +1 -0
  26. package/lib/components/Flags.js +27 -0
  27. package/lib/components/Flags.js.map +1 -0
  28. package/lib/components/Footer.js +18 -0
  29. package/lib/components/Footer.js.map +1 -0
  30. package/lib/components/Hierarchy.js +27 -0
  31. package/lib/components/Hierarchy.js.map +1 -0
  32. package/lib/components/Icon.js +27 -0
  33. package/lib/components/Icon.js.map +1 -0
  34. package/lib/components/Index.js +87 -0
  35. package/lib/components/Index.js.map +1 -0
  36. package/lib/components/Markdown.js +204 -0
  37. package/lib/components/Markdown.js.map +1 -0
  38. package/lib/components/Member.js +68 -0
  39. package/lib/components/Member.js.map +1 -0
  40. package/lib/components/MemberDeclaration.js +64 -0
  41. package/lib/components/MemberDeclaration.js.map +1 -0
  42. package/lib/components/MemberGetterSetter.js +61 -0
  43. package/lib/components/MemberGetterSetter.js.map +1 -0
  44. package/lib/components/MemberReference.js +38 -0
  45. package/lib/components/MemberReference.js.map +1 -0
  46. package/lib/components/MemberSignatureBody.js +91 -0
  47. package/lib/components/MemberSignatureBody.js.map +1 -0
  48. package/lib/components/MemberSignatureTitle.js +52 -0
  49. package/lib/components/MemberSignatureTitle.js.map +1 -0
  50. package/lib/components/MemberSignatures.js +61 -0
  51. package/lib/components/MemberSignatures.js.map +1 -0
  52. package/lib/components/MemberSources.js +33 -0
  53. package/lib/components/MemberSources.js.map +1 -0
  54. package/lib/components/Members.js +51 -0
  55. package/lib/components/Members.js.map +1 -0
  56. package/lib/components/MembersGroup.js +39 -0
  57. package/lib/components/MembersGroup.js.map +1 -0
  58. package/lib/components/Parameter.js +145 -0
  59. package/lib/components/Parameter.js.map +1 -0
  60. package/lib/components/Reflection.js +112 -0
  61. package/lib/components/Reflection.js.map +1 -0
  62. package/lib/components/SourceLink.js +37 -0
  63. package/lib/components/SourceLink.js.map +1 -0
  64. package/lib/components/Type.js +341 -0
  65. package/lib/components/Type.js.map +1 -0
  66. package/lib/components/TypeAndParent.js +27 -0
  67. package/lib/components/TypeAndParent.js.map +1 -0
  68. package/lib/components/TypeParameters.js +36 -0
  69. package/lib/components/TypeParameters.js.map +1 -0
  70. package/lib/components/TypeParametersGeneric.js +27 -0
  71. package/lib/components/TypeParametersGeneric.js.map +1 -0
  72. package/lib/components/VersionBanner.js +39 -0
  73. package/lib/components/VersionBanner.js.map +1 -0
  74. package/lib/hooks/useBreadcrumbs.js +9 -0
  75. package/lib/hooks/useBreadcrumbs.js.map +1 -0
  76. package/lib/hooks/useGitRefName.js +9 -0
  77. package/lib/hooks/useGitRefName.js.map +1 -0
  78. package/lib/hooks/useMinimalLayout.js +9 -0
  79. package/lib/hooks/useMinimalLayout.js.map +1 -0
  80. package/lib/hooks/useReflection.js +19 -0
  81. package/lib/hooks/useReflection.js.map +1 -0
  82. package/lib/hooks/useReflectionMap.js +9 -0
  83. package/lib/hooks/useReflectionMap.js.map +1 -0
  84. package/lib/index.js +320 -0
  85. package/lib/index.js.map +1 -0
  86. package/lib/markdownLoader.js +11 -0
  87. package/lib/markdownLoader.js.map +1 -0
  88. package/lib/plugin/data.js +332 -0
  89. package/lib/plugin/data.js.map +1 -0
  90. package/lib/plugin/sidebar.js +105 -0
  91. package/lib/plugin/sidebar.js.map +1 -0
  92. package/lib/plugin/structure/0.23.js +48 -0
  93. package/lib/plugin/structure/0.23.js.map +1 -0
  94. package/lib/plugin/url.js +49 -0
  95. package/lib/plugin/url.js.map +1 -0
  96. package/lib/plugin/version.js +83 -0
  97. package/lib/plugin/version.js.map +1 -0
  98. package/lib/types.js +2 -0
  99. package/lib/types.js.map +1 -0
  100. package/lib/utils/hierarchy.js +35 -0
  101. package/lib/utils/hierarchy.js.map +1 -0
  102. package/lib/utils/icons.js +124 -0
  103. package/lib/utils/icons.js.map +1 -0
  104. package/lib/utils/links.js +10 -0
  105. package/lib/utils/links.js.map +1 -0
  106. package/lib/utils/markdown.js +69 -0
  107. package/lib/utils/markdown.js.map +1 -0
  108. package/lib/utils/visibility.js +25 -0
  109. package/lib/utils/visibility.js.map +1 -0
  110. package/package.json +57 -0
  111. package/src/components/AnchorLink.tsx +14 -0
  112. package/src/components/ApiChangelog.tsx +26 -0
  113. package/src/components/ApiDataContext.ts +17 -0
  114. package/src/components/ApiIndex.tsx +109 -0
  115. package/src/components/ApiItem.tsx +110 -0
  116. package/src/components/ApiItemLayout.tsx +96 -0
  117. package/src/components/ApiPage.tsx +78 -0
  118. package/src/components/Breadcrumb.tsx +41 -0
  119. package/src/components/Comment.tsx +74 -0
  120. package/src/components/CommentBadges.tsx +40 -0
  121. package/src/components/DefaultValue.tsx +48 -0
  122. package/src/components/Flags.tsx +29 -0
  123. package/src/components/Footer.tsx +13 -0
  124. package/src/components/Hierarchy.tsx +27 -0
  125. package/src/components/Icon.tsx +20 -0
  126. package/src/components/Index.tsx +109 -0
  127. package/src/components/Markdown.tsx +241 -0
  128. package/src/components/Member.tsx +64 -0
  129. package/src/components/MemberDeclaration.tsx +67 -0
  130. package/src/components/MemberGetterSetter.tsx +69 -0
  131. package/src/components/MemberReference.tsx +43 -0
  132. package/src/components/MemberSignatureBody.tsx +121 -0
  133. package/src/components/MemberSignatureTitle.tsx +65 -0
  134. package/src/components/MemberSignatures.tsx +64 -0
  135. package/src/components/MemberSources.tsx +42 -0
  136. package/src/components/Members.tsx +62 -0
  137. package/src/components/MembersGroup.tsx +47 -0
  138. package/src/components/Parameter.tsx +165 -0
  139. package/src/components/README.md +9 -0
  140. package/src/components/Reflection.tsx +136 -0
  141. package/src/components/SourceLink.tsx +46 -0
  142. package/src/components/Type.tsx +377 -0
  143. package/src/components/TypeAndParent.tsx +26 -0
  144. package/src/components/TypeParameters.tsx +37 -0
  145. package/src/components/TypeParametersGeneric.tsx +25 -0
  146. package/src/components/VersionBanner.tsx +44 -0
  147. package/src/components/styles.css +303 -0
  148. package/src/hooks/useBreadcrumbs.ts +6 -0
  149. package/src/hooks/useGitRefName.ts +6 -0
  150. package/src/hooks/useMinimalLayout.ts +6 -0
  151. package/src/hooks/useReflection.ts +18 -0
  152. package/src/hooks/useReflectionMap.ts +7 -0
  153. package/src/index.ts +420 -0
  154. package/src/markdownLoader.ts +10 -0
  155. package/src/plugin/data.ts +389 -0
  156. package/src/plugin/sidebar.ts +139 -0
  157. package/src/plugin/structure/0.23.ts +58 -0
  158. package/src/plugin/url.ts +49 -0
  159. package/src/plugin/version.ts +118 -0
  160. package/src/types.ts +165 -0
  161. package/src/utils/hierarchy.ts +46 -0
  162. package/src/utils/icons.ts +103 -0
  163. package/src/utils/links.ts +10 -0
  164. package/src/utils/markdown.ts +82 -0
  165. package/src/utils/visibility.ts +31 -0
@@ -0,0 +1,118 @@
1
+ // BASED ON: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-content-docs/src/versions.ts
2
+
3
+ import path from 'path';
4
+ import type { PluginOptions as DocusaurusNativePluginOptions } from '@docusaurus/plugin-content-docs';
5
+ import {
6
+ CURRENT_VERSION_NAME,
7
+ filterVersions,
8
+ getDefaultVersionBanner,
9
+ readVersionNames,
10
+ VERSIONED_DOCS_DIR,
11
+ } from '@docusaurus/plugin-content-docs/server';
12
+ import type { LoadContext } from '@docusaurus/types';
13
+ import { DEFAULT_PLUGIN_ID, normalizeUrl } from '@docusaurus/utils';
14
+ import type { DocusaurusPluginTypeDocApiOptions, VersionMetadata } from '../types';
15
+
16
+ type PluginOptions = DocusaurusPluginTypeDocApiOptions;
17
+
18
+ export function getVersionedDocsDirPath(siteDir: string, pluginId: string): string {
19
+ return path.join(
20
+ siteDir,
21
+ pluginId === DEFAULT_PLUGIN_ID ? VERSIONED_DOCS_DIR : `${pluginId}_${VERSIONED_DOCS_DIR}`,
22
+ );
23
+ }
24
+
25
+ function getDefaultLastVersionName(versionNames: string[]): string {
26
+ if (versionNames.length === 1) {
27
+ return versionNames[0];
28
+ }
29
+
30
+ return versionNames.find((versionName) => versionName !== CURRENT_VERSION_NAME) ?? '';
31
+ }
32
+
33
+ function createVersionMetadata({
34
+ versionName,
35
+ versionNames,
36
+ lastVersionName,
37
+ context,
38
+ options,
39
+ }: {
40
+ versionName: string;
41
+ versionNames: string[];
42
+ lastVersionName: string;
43
+ context: LoadContext;
44
+ options: PluginOptions;
45
+ }): VersionMetadata {
46
+ const isLast = versionName === lastVersionName;
47
+ const versionOptions = options.versions[versionName] ?? {};
48
+ const versionLabel =
49
+ versionOptions.label ?? versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
50
+ let versionPathPart =
51
+ versionOptions.path ?? versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
52
+
53
+ if (isLast) {
54
+ versionPathPart = '';
55
+ }
56
+
57
+ const versionPath = normalizeUrl([
58
+ context.siteConfig.baseUrl,
59
+ options.routeBasePath ?? 'api',
60
+ versionPathPart,
61
+ ]);
62
+
63
+ return {
64
+ isLast: versionName === lastVersionName,
65
+ routePriority: versionPathPart === '' ? -1 : undefined,
66
+ versionBadge: versionOptions?.badge ?? versionNames.length !== 1,
67
+ versionBanner: getDefaultVersionBanner({
68
+ context,
69
+ lastVersionName,
70
+ // @ts-expect-error Ignore internal options
71
+ options,
72
+ versionName,
73
+ versionNames,
74
+ }),
75
+ versionClassName: versionOptions?.className ?? `api-version-${versionName}`,
76
+ versionLabel,
77
+ versionName,
78
+ versionPath,
79
+ };
80
+ }
81
+
82
+ export async function readVersionsMetadata(
83
+ context: LoadContext,
84
+ options: DocusaurusPluginTypeDocApiOptions,
85
+ ): Promise<VersionMetadata[]> {
86
+ // Docusaurus internals require *every* option, but the versioning
87
+ // does not actually use them. We are casting the types here to
88
+ // ignore all the missing properties.
89
+ const specialOptions = options as DocusaurusNativePluginOptions &
90
+ DocusaurusPluginTypeDocApiOptions;
91
+
92
+ const versionNamesUnfiltered = await readVersionNames(context.siteDir, {
93
+ ...specialOptions,
94
+ disableVersioning: options.disableVersioning ?? false,
95
+ id: options.id ?? 'default',
96
+ includeCurrentVersion: options.includeCurrentVersion ?? true,
97
+ });
98
+ const versionNames = filterVersions(versionNamesUnfiltered, {
99
+ ...specialOptions,
100
+ onlyIncludeVersions:
101
+ options.onlyIncludeVersions && options.onlyIncludeVersions.length > 0
102
+ ? options.onlyIncludeVersions
103
+ : undefined,
104
+ });
105
+ const lastVersionName = options.lastVersion
106
+ ? options.lastVersion
107
+ : getDefaultLastVersionName(versionNames);
108
+
109
+ return versionNames.map((versionName) =>
110
+ createVersionMetadata({
111
+ context,
112
+ lastVersionName,
113
+ options,
114
+ versionName,
115
+ versionNames,
116
+ }),
117
+ );
118
+ }
package/src/types.ts ADDED
@@ -0,0 +1,165 @@
1
+ import type { JSONOutput, TypeDocOptions } from 'typedoc';
2
+ import type {
3
+ PropSidebarItem,
4
+ VersionBanner,
5
+ VersionsOptions,
6
+ } from '@docusaurus/plugin-content-docs';
7
+
8
+ export type { VersionBanner };
9
+
10
+ export interface DocusaurusPluginTypeDocApiOptions
11
+ extends Omit<VersionsOptions, 'disableVersioning' | 'includeCurrentVersion'> {
12
+ banner?: string;
13
+ breadcrumbs?: boolean;
14
+ changelogName?: string;
15
+ changelogs?: boolean;
16
+ gitRefName?: string;
17
+ debug?: boolean;
18
+ exclude?: string[];
19
+ id?: string;
20
+ minimal?: boolean;
21
+ packageJsonName?: string;
22
+ packages: (PackageConfig | string)[];
23
+ pathToCurrentVersionTypedocJSON?: string;
24
+ projectRoot: string;
25
+ readmeName?: string;
26
+ readmes?: boolean;
27
+ removeScopes?: string[];
28
+ sortPackages?: (a: PackageReflectionGroup, d: PackageReflectionGroup) => number;
29
+ sortSidebar?: (a: string, d: string) => number;
30
+ tsconfigName?: string;
31
+ typedocOptions?: Partial<
32
+ Pick<
33
+ TypeDocOptions,
34
+ | 'commentStyle'
35
+ | 'disableSources'
36
+ | 'emit'
37
+ | 'excludeExternals'
38
+ | 'excludeInternal'
39
+ | 'excludeNotDocumented'
40
+ | 'excludePrivate'
41
+ | 'excludeProtected'
42
+ | 'excludeTags'
43
+ | 'externalPattern'
44
+ | 'logger'
45
+ | 'logLevel'
46
+ | 'sort'
47
+ | 'treatWarningsAsErrors'
48
+ | 'validation'
49
+ >
50
+ >;
51
+
52
+ // Versioning, based on Docusaurus
53
+ disableVersioning?: boolean;
54
+ includeCurrentVersion?: boolean;
55
+ routeBasePath?: string;
56
+ }
57
+
58
+ // CONFIG
59
+
60
+ export interface PackageEntryConfig {
61
+ label: string;
62
+ path: string;
63
+ }
64
+
65
+ export interface PackageConfig {
66
+ path: string; // Folder relative to project root
67
+ entry?: Record<string, PackageEntryConfig | string> | string;
68
+ slug?: string;
69
+ }
70
+
71
+ export interface ResolvedPackageConfig {
72
+ entryPoints: Record<string, PackageEntryConfig>;
73
+ packagePath: string;
74
+ packageSlug: string;
75
+ packageName: string;
76
+ packageVersion: string;
77
+ }
78
+
79
+ // VERSIONING
80
+
81
+ export interface VersionMetadata {
82
+ versionName: string; // 1.0.0
83
+ versionLabel: string; // Version 1.0.0
84
+ versionPath: string; // /baseUrl/api/1.0.0
85
+ versionBadge: boolean;
86
+ versionBanner: VersionBanner | null;
87
+ versionClassName: string;
88
+ isLast: boolean;
89
+ routePriority: number | undefined; // -1 for the latest
90
+ }
91
+
92
+ export interface LoadedVersion extends VersionMetadata {
93
+ // mainDocId: string;
94
+ packages: PackageReflectionGroup[];
95
+ sidebars: SidebarItem[];
96
+ }
97
+
98
+ export interface LoadedContent {
99
+ loadedVersions: LoadedVersion[];
100
+ }
101
+
102
+ // SIDEBAR / UI
103
+
104
+ export type SidebarItem = PropSidebarItem;
105
+
106
+ export interface ApiOptions {
107
+ banner: string;
108
+ breadcrumbs: boolean;
109
+ gitRefName: string;
110
+ minimal: boolean;
111
+ pluginId: string;
112
+ scopes: string[];
113
+ }
114
+
115
+ export interface TOCItem {
116
+ readonly value: string;
117
+ readonly id: string;
118
+ readonly level: number;
119
+ }
120
+
121
+ // REFLECTIONS
122
+
123
+ export interface PackageReflectionGroupEntry {
124
+ index: boolean;
125
+ label: string;
126
+ reflection: JSONOutput.ProjectReflection;
127
+ urlSlug: string;
128
+ }
129
+
130
+ export interface PackageReflectionGroup {
131
+ entryPoints: PackageReflectionGroupEntry[];
132
+ packageName: string;
133
+ packageVersion: string;
134
+ changelogPath?: string;
135
+ readmePath?: string;
136
+ }
137
+
138
+ export interface ApiMetadata {
139
+ id: number;
140
+ name: string;
141
+ permalink: string;
142
+ previousId?: number;
143
+ nextId?: number;
144
+ }
145
+
146
+ export type DeclarationReflectionMap = Record<number, JSONOutput.DeclarationReflection>;
147
+
148
+ declare module 'typedoc/dist/lib/serialization/schema' {
149
+ interface Reflection extends ApiMetadata {
150
+ // Not typed but used in the templates
151
+ declaration?: DeclarationReflection;
152
+ // Added by us for convenience
153
+ parentId?: number;
154
+ }
155
+
156
+ interface Type {
157
+ // Not typed but used in the templates
158
+ declaration?: DeclarationReflection;
159
+ }
160
+ }
161
+
162
+ declare global {
163
+ // eslint-disable-next-line no-var, vars-on-top
164
+ var typedocBuild: { count: number };
165
+ }
@@ -0,0 +1,46 @@
1
+ import type { JSONOutput } from 'typedoc';
2
+
3
+ export interface HierarchyNode {
4
+ types: JSONOutput.SomeType[];
5
+ next?: HierarchyNode;
6
+ isTarget?: boolean;
7
+ }
8
+
9
+ // The JSON output does not include hierarchy information, so we need to duplicate the logic!
10
+ // https://github.com/TypeStrong/typedoc/blob/master/src/lib/converter/plugins/TypePlugin.ts#L98
11
+ export function createHierarchy(reflection: JSONOutput.DeclarationReflection) {
12
+ let root!: HierarchyNode;
13
+ let hierarchy!: HierarchyNode;
14
+
15
+ function push(types: JSONOutput.SomeType[]) {
16
+ const level: HierarchyNode = { types };
17
+
18
+ if (hierarchy) {
19
+ hierarchy.next = level;
20
+ hierarchy = level;
21
+ } else {
22
+ root = level;
23
+ hierarchy = level;
24
+ }
25
+ }
26
+
27
+ if (reflection.extendedTypes) {
28
+ push(reflection.extendedTypes);
29
+ }
30
+
31
+ push([
32
+ {
33
+ id: reflection.id,
34
+ name: reflection.name,
35
+ type: 'reference',
36
+ },
37
+ ]);
38
+
39
+ hierarchy.isTarget = true;
40
+
41
+ if (reflection.extendedBy) {
42
+ push(reflection.extendedBy);
43
+ }
44
+
45
+ return root;
46
+ }
@@ -0,0 +1,103 @@
1
+ /* eslint-disable no-fallthrough */
2
+
3
+ import type { ReflectionKind } from 'typedoc';
4
+
5
+ // We have to map these manually instead of using the `ReflectionKind` enum,
6
+ // otherwise the `typedoc` package ends up in the bundle and crashes.
7
+ const KIND_ICONS: Record<ReflectionKind, string> = {
8
+ 1: 'project', // Project
9
+ 2: 'package', // Module
10
+ 4: 'symbol-namespace', // Namespace
11
+ 8: 'symbol-enum', // Enum
12
+ 16: 'symbol-enum-member', // EnumMember
13
+ 32: 'symbol-variable', // Variable
14
+ 64: 'symbol-function', // Function
15
+ 128: 'symbol-class', // Class
16
+ 256: 'symbol-interface', // Interface
17
+ 512: 'symbol-constructor', // Constructor
18
+ 1024: 'symbol-property', // Property
19
+ 2048: 'symbol-method', // Method
20
+ 4096: 'symbol-method', // CallSignature
21
+ 8192: 'bracket-dot', // IndexSignature
22
+ 16_384: 'symbol-method', // ConstructorSignature
23
+ 32_768: 'symbol-property', // Parameter
24
+ 65_536: 'symbol-key', // TypeLiteral
25
+ 131_072: 'symbol-type-parameter', // TypeParameter
26
+ 262_144: 'symbol-field', // Accessor
27
+ 524_288: 'symbol-field', // GetSignature
28
+ 1_048_576: 'symbol-field', // SetSignature
29
+ 2_097_152: 'bracket', // ObjectLiteral
30
+ 4_194_304: 'symbol-parameter', // TypeAlias
31
+ 8_388_608: 'references', // Reference
32
+ };
33
+
34
+ export function getKindIcon(kind: ReflectionKind, name: string): string {
35
+ let icon = KIND_ICONS[kind];
36
+
37
+ // Use event icon when property starts with "on"
38
+ if (kind === 1024 && name.match(/^on[A-Z]/)) {
39
+ icon = 'symbol-event';
40
+ }
41
+
42
+ return icon;
43
+ }
44
+
45
+ // eslint-disable-next-line complexity
46
+ export function getKindIconColor(kind: ReflectionKind): string {
47
+ switch (kind) {
48
+ // Function
49
+ case 64:
50
+ // Constructor
51
+ case 512:
52
+ // Method
53
+ case 2048:
54
+ // CallSignature
55
+ case 4096:
56
+ // ConstructorSignature
57
+ case 16_384:
58
+ // Accessor
59
+ case 262_144:
60
+ return 'var(--ifm-color-info)';
61
+
62
+ // EnumMember
63
+ case 16:
64
+ // Variable
65
+ case 32:
66
+ // Property
67
+ case 1024:
68
+ // GetSignature
69
+ case 524_288:
70
+ // SetSignature
71
+ case 1_048_576:
72
+ return 'var(--ifm-color-success)';
73
+
74
+ // Namespace
75
+ case 4:
76
+ // Class
77
+ case 128:
78
+ return 'var(--ifm-color-warning)';
79
+
80
+ // Enum
81
+ case 8:
82
+ // Interface
83
+ case 256:
84
+ // TypeAlias
85
+ case 4_194_304:
86
+ return 'var(--ifm-color-danger)';
87
+
88
+ default:
89
+ return 'inherit';
90
+ }
91
+ }
92
+
93
+ export function getKindIconHtml(kind: ReflectionKind, name: string): string {
94
+ const icon = getKindIcon(kind, name);
95
+
96
+ if (!icon) {
97
+ return '';
98
+ }
99
+
100
+ const color = getKindIconColor(kind);
101
+
102
+ return `<i class="codicon codicon-${icon}" style="color:${color};"></i>`;
103
+ }
@@ -0,0 +1,10 @@
1
+ export function removeScopes(text: string, scopes: string[]): string {
2
+ if (scopes.length === 0) {
3
+ return text;
4
+ }
5
+
6
+ return scopes.reduce(
7
+ (value, scope) => value.replace(new RegExp(`^(${scope}-|@${scope}/)`), ''),
8
+ text,
9
+ );
10
+ }
@@ -0,0 +1,82 @@
1
+ import type { PropVersionMetadata } from '@docusaurus/plugin-content-docs';
2
+ import type { DeclarationReflectionMap } from '../types';
3
+
4
+ function splitLinkText(text: string): { caption: string; target: string } {
5
+ let splitIndex = text.indexOf('|');
6
+
7
+ if (splitIndex === -1) {
8
+ splitIndex = text.search(/\s/);
9
+ }
10
+
11
+ if (splitIndex !== -1) {
12
+ return {
13
+ caption: text
14
+ .slice(splitIndex + 1)
15
+ .replace(/\n+/, ' ')
16
+ .trim(),
17
+ target: text.slice(0, Math.max(0, splitIndex)).trim(),
18
+ };
19
+ }
20
+
21
+ return {
22
+ caption: text,
23
+ target: text,
24
+ };
25
+ }
26
+
27
+ function findReflectionWithMatchingTarget(
28
+ reflections: DeclarationReflectionMap,
29
+ symbol: string,
30
+ member?: string,
31
+ ) {
32
+ return Object.values(reflections).find((ref) => {
33
+ if (ref.name !== symbol) {
34
+ return false;
35
+ }
36
+
37
+ return member ? ref.children?.some((child) => child.name === member) : true;
38
+ });
39
+ }
40
+
41
+ function replaceApiLinks(
42
+ reflections: DeclarationReflectionMap,
43
+ ): (match: string, tagName: string, content: string) => string {
44
+ return (match: string, tagName: string, content: string) => {
45
+ const { caption, target } = splitLinkText(content);
46
+ const [symbol, member] = target.split('.');
47
+ const reflection = findReflectionWithMatchingTarget(reflections, symbol, member);
48
+ const label = tagName === 'linkcode' ? `\`${caption}\`` : caption;
49
+
50
+ if (!reflection?.permalink) {
51
+ return label;
52
+ }
53
+
54
+ return `[${label}](${reflection.permalink}${member ? `#${member}` : ''})`;
55
+ };
56
+ }
57
+
58
+ function replaceDocLinks(
59
+ currentVersion: PropVersionMetadata,
60
+ ): (match: string, content: string) => string {
61
+ return (match: string, content: string) => {
62
+ const { caption, target } = splitLinkText(content);
63
+ const version = currentVersion.version === 'current' ? 'next' : currentVersion.version;
64
+
65
+ // TODO: Handle `routeBasePath`? Something else besides "docs"?
66
+ const url = currentVersion.isLast ? `/docs/${target}` : `/docs/${version}/${target}`;
67
+
68
+ return `[${caption}](${url})`;
69
+ };
70
+ }
71
+
72
+ // TypeDoc JSON output does not replace links, so we need to do this manually.
73
+ // @see https://github.com/TypeStrong/typedoc/blob/master/src/lib/output/plugins/MarkedLinksPlugin.ts
74
+ export function replaceLinkTokens(
75
+ markdown: string,
76
+ reflections: DeclarationReflectionMap,
77
+ currentVersion: PropVersionMetadata,
78
+ ) {
79
+ return markdown
80
+ .replace(/{@(link|linkcode|linkplain|apilink)\s+([^}]+?)}/gi, replaceApiLinks(reflections))
81
+ .replace(/{@doclink\s+([^}]+?)}/gi, replaceDocLinks(currentVersion));
82
+ }
@@ -0,0 +1,31 @@
1
+ import type { JSONOutput } from 'typedoc';
2
+ import type { DeclarationReflectionMap } from '../types';
3
+
4
+ // https://github.com/TypeStrong/typedoc/blob/master/src/lib/output/themes/DefaultTheme.ts#L264
5
+ export function hasOwnDocument(id: number, reflections: DeclarationReflectionMap): boolean {
6
+ const reflection = reflections[id];
7
+
8
+ return Boolean(reflection?.permalink && !reflection.permalink.includes('#'));
9
+ }
10
+
11
+ // https://github.com/TypeStrong/typedoc/blob/2103f347c9cba40fcaa1f67e36f7cea0bdea2f0f/src/lib/models/ReflectionCategory.ts#L44
12
+ export function allCategoryChildrenHaveOwnDocument(
13
+ category: JSONOutput.ReflectionCategory,
14
+ reflections: DeclarationReflectionMap,
15
+ ): boolean {
16
+ let onlyOwnDocuments = true;
17
+
18
+ category.children?.forEach((child) => {
19
+ onlyOwnDocuments &&= hasOwnDocument(child, reflections);
20
+ });
21
+
22
+ return onlyOwnDocuments;
23
+ }
24
+
25
+ // https://github.com/TypeStrong/typedoc/blob/2103f347c9cba40fcaa1f67e36f7cea0bdea2f0f/src/lib/models/ReflectionGroup.ts#L81
26
+ export function allGroupChildrenHaveOwnDocument(
27
+ group: JSONOutput.ReflectionGroup,
28
+ reflections: DeclarationReflectionMap,
29
+ ): boolean {
30
+ return Boolean(group.children?.every((child) => hasOwnDocument(child, reflections)));
31
+ }