rspress-plugin-api-extractor 0.13.3 → 0.15.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 (44) hide show
  1. package/BuildEnv.js +0 -1
  2. package/build-program.js +5 -5
  3. package/build-stages.js +98 -282
  4. package/config-helpers.js +1 -1
  5. package/emit/mdx.js +311 -0
  6. package/emit/meta.js +62 -0
  7. package/index.d.ts +6 -70
  8. package/layers/build-metrics.js +1 -2
  9. package/layers/config-resolution.js +5 -8
  10. package/layers/type-environment.js +5 -4
  11. package/llms-program.js +3 -3
  12. package/markdown/helpers.js +10 -177
  13. package/observability/sinks/console-sink.js +1 -3
  14. package/observability/sinks/metrics-sink.js +0 -2
  15. package/package.json +9 -7
  16. package/path-derivation.js +1 -29
  17. package/plugin.js +3 -10
  18. package/prettier-formatter.js +27 -59
  19. package/remark-with-api.js +3 -2
  20. package/schemas/config.js +3 -29
  21. package/schemas/observability.js +8 -23
  22. package/schemas/performance.js +1 -7
  23. package/services/TwoslashCacheService.js +18 -14
  24. package/services/TypeRegistryService.js +4 -4
  25. package/shiki-transformer.js +12 -51
  26. package/twoslash-transformer.js +16 -49
  27. package/api-extracted-package.js +0 -471
  28. package/code-post-processor.js +0 -38
  29. package/frontmatter.js +0 -176
  30. package/llms-processing.js +0 -270
  31. package/markdown/page-generators/class-page.js +0 -364
  32. package/markdown/page-generators/enum-page.js +0 -152
  33. package/markdown/page-generators/function-page.js +0 -128
  34. package/markdown/page-generators/index-pages.js +0 -25
  35. package/markdown/page-generators/interface-page.js +0 -311
  36. package/markdown/page-generators/namespace-page.js +0 -278
  37. package/markdown/page-generators/type-alias-page.js +0 -111
  38. package/markdown/page-generators/variable-page.js +0 -111
  39. package/markdown/prose-linker.js +0 -22
  40. package/tsconfig-parser.js +0 -115
  41. package/twoslash-cache.js +0 -174
  42. package/twoslash-patterns.js +0 -87
  43. package/type-reference-extractor.js +0 -199
  44. package/typescript-config.js +0 -170
@@ -1,152 +0,0 @@
1
- import { escapeMdxGenerics, formatExampleCode, generateAvailableFrom, generateFrontmatter, prepareExampleCode, stripTwoslashDirectives } from "../helpers.js";
2
- import { linkProse } from "../prose-linker.js";
3
- import { ApiItems, Tsdoc } from "@tsdoctor/model";
4
-
5
- //#region src/markdown/page-generators/enum-page.ts
6
- /**
7
- * Generates MDX documentation pages for TypeScript enums.
8
- *
9
- * This class transforms API Extractor enum models into rich MDX documentation
10
- * pages with syntax-highlighted signatures, member tables, and cross-linked
11
- * type references.
12
- *
13
- * **Page Structure:**
14
- * 1. Frontmatter with title, description, and Open Graph metadata
15
- * 2. Component imports
16
- * 3. Page title (H1) and summary
17
- * 4. Optional deprecation warning and release tag badge
18
- * 5. Source code link toolbar
19
- * 6. Enum signature block
20
- * 7. Members table (Name, Value, Description)
21
- * 8. Examples section with Twoslash-enabled code blocks
22
- * 9. See Also references
23
- *
24
- * **Relationships:**
25
- * - Created and invoked by {@link ApiExtractorPlugin} during page generation
26
- * - Uses `Signature.format` from `@tsdoctor/model` for formatting type signatures
27
- * - Uses the `Tsdoc` / `ApiItems` modules from `@tsdoctor/model` for extracting documentation
28
- * - Uses the per-build prose linker (`linkProse`) for adding type reference links
29
- *
30
- * @see {@link TypeAliasPageGenerator} for type alias documentation
31
- * @see {@link VariablePageGenerator} for variable/constant documentation
32
- */
33
- var EnumPageGenerator = class {
34
- /**
35
- * Generate a markdown page for an enum
36
- *
37
- * @param apiScope - API scope identifier for VFS lookup
38
- */
39
- async generate(apiEnum, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
40
- const shouldSuppressErrors = suppressExampleErrors ?? true;
41
- const name = apiEnum.displayName;
42
- const summary = Tsdoc.summary(apiEnum) || "No description available.";
43
- const releaseTag = Tsdoc.releaseTag(apiEnum);
44
- let content = generateFrontmatter(name, summary, singularName, apiName);
45
- content += `import { SourceCode } from "@rspress/core/theme";\n`;
46
- content += `import { EnumMembersTable } from "rspress-plugin-api-extractor/runtime";\n`;
47
- content += `import { ApiSignature, ApiExample } from "rspress-plugin-api-extractor/runtime";\n\n`;
48
- content += `# ${name}\n\n`;
49
- const deprecation = Tsdoc.deprecation(apiEnum);
50
- if (deprecation) {
51
- const message = escapeMdxGenerics(linkProse(deprecation.message));
52
- content += `> ⚠️ **Deprecated:** ${message}\n\n`;
53
- }
54
- if (releaseTag !== "Public") content += `\`${releaseTag}\`\n\n`;
55
- content += `${summary}\n\n`;
56
- content += generateAvailableFrom(packageName, availableFrom);
57
- const sourceLink = ApiItems.sourceLink(apiEnum, sourceConfig);
58
- if (sourceLink) {
59
- content += `<div className="api-docs-toolbar">\n`;
60
- content += ` <div className="api-docs-toolbar-left">\n`;
61
- content += ` <SourceCode href="${sourceLink}" />\n`;
62
- content += ` </div>\n`;
63
- if (llmsPlugin?.enabled) {
64
- content += ` <div className="api-docs-toolbar-right">\n`;
65
- content += ` </div>\n`;
66
- }
67
- content += `</div>\n\n`;
68
- }
69
- const skeleton = this.generateEnumSkeleton(apiEnum);
70
- const hasMembers = apiEnum.members.length > 0;
71
- if (skeleton) {
72
- const displayCode = stripTwoslashDirectives(skeleton);
73
- const signatureNewlines = hasMembers ? "\n" : "\n\n";
74
- content += `<ApiSignature code={${JSON.stringify(displayCode)}} source={${JSON.stringify(skeleton)}} apiScope={${JSON.stringify(apiScope)}} hasMembers={${hasMembers}} />${signatureNewlines}`;
75
- }
76
- if (hasMembers) {
77
- const membersData = apiEnum.members.map((member) => {
78
- const memberItem = member;
79
- const memberSummary = Tsdoc.summary(member) || "";
80
- let value;
81
- if (memberItem.excerpt?.text) {
82
- const excerptText = memberItem.excerpt.text.trim();
83
- const equalsIndex = excerptText.indexOf("=");
84
- if (equalsIndex !== -1) value = excerptText.substring(equalsIndex + 1).trim().replace(/,\s*$/, "");
85
- }
86
- return {
87
- name: member.displayName,
88
- value,
89
- description: linkProse(memberSummary)
90
- };
91
- });
92
- content += `<EnumMembersTable members={${JSON.stringify(membersData)}} />\n\n`;
93
- }
94
- const examples = Tsdoc.examples(apiEnum);
95
- if (examples.length > 0) {
96
- content += `## Examples\n\n`;
97
- for (const example of examples) {
98
- const prepared = prepareExampleCode(example, name, packageName, shouldSuppressErrors);
99
- const formattedCode = await formatExampleCode(prepared.code, prepared.language, {
100
- api: packageName,
101
- blockType: "example"
102
- });
103
- if (prepared.isTypeScript) {
104
- const displayCode = stripTwoslashDirectives(formattedCode);
105
- content += `<ApiExample code={${JSON.stringify(displayCode)}} source={${JSON.stringify(formattedCode)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
106
- } else content += `\`\`\`${prepared.language}\n${formattedCode}\n\`\`\`\n\n`;
107
- }
108
- }
109
- const seeReferences = Tsdoc.seeReferences(apiEnum);
110
- if (seeReferences.length > 0) {
111
- content += `## See Also\n\n`;
112
- for (const reference of seeReferences) {
113
- const refText = escapeMdxGenerics(linkProse(reference.text));
114
- content += `- ${refText}\n`;
115
- }
116
- content += `\n`;
117
- }
118
- return {
119
- routePath: `${baseRoute}/enum/${name.toLowerCase()}`,
120
- content
121
- };
122
- }
123
- /**
124
- * Generate a complete enum skeleton showing all members
125
- */
126
- generateEnumSkeleton(apiEnum) {
127
- const lines = [];
128
- const enumName = apiEnum.displayName;
129
- lines.push(`enum ${enumName} {`);
130
- const members = apiEnum.members;
131
- for (let i = 0; i < members.length; i++) {
132
- const member = members[i];
133
- const memberItem = member;
134
- let memberLine = ` ${member.displayName}`;
135
- if (memberItem.excerpt?.text) {
136
- const excerptText = memberItem.excerpt.text.trim();
137
- const equalsIndex = excerptText.indexOf("=");
138
- if (equalsIndex !== -1) {
139
- const value = excerptText.substring(equalsIndex + 1).trim().replace(/,\s*$/, "");
140
- memberLine += ` = ${value}`;
141
- }
142
- }
143
- if (i < members.length - 1) memberLine += ",";
144
- lines.push(memberLine);
145
- }
146
- lines.push("}");
147
- return lines.join("\n");
148
- }
149
- };
150
-
151
- //#endregion
152
- export { EnumPageGenerator };
@@ -1,128 +0,0 @@
1
- import { TypeReferenceExtractor } from "../../type-reference-extractor.js";
2
- import { escapeMdxGenerics, formatExampleCode, generateAvailableFrom, generateFrontmatter, prepareExampleCode, prependHiddenImports, stripTwoslashDirectives } from "../helpers.js";
3
- import { linkProse } from "../prose-linker.js";
4
- import { ApiItems, Signature, Tsdoc } from "@tsdoctor/model";
5
-
6
- //#region src/markdown/page-generators/function-page.ts
7
- /**
8
- * Generates MDX documentation pages for TypeScript/JavaScript functions.
9
- *
10
- * This class transforms API Extractor function models into rich MDX documentation
11
- * pages with syntax-highlighted signatures and cross-linked type references.
12
- *
13
- * **Page Structure:**
14
- * 1. Frontmatter with title, description, and Open Graph metadata
15
- * 2. Component imports
16
- * 3. Page title (H1) and summary
17
- * 4. Optional deprecation warning and release tag badge
18
- * 5. Source code link toolbar
19
- * 6. Function signature block
20
- * 7. Parameters documentation
21
- * 8. Returns documentation
22
- * 9. Examples section with Twoslash-enabled code blocks
23
- * 10. See Also references
24
- *
25
- * **Relationships:**
26
- * - Created and invoked by {@link ApiExtractorPlugin} during page generation
27
- * - Uses `Signature.format` from `@tsdoctor/model` for formatting type signatures
28
- * - Uses the `Tsdoc` / `ApiItems` modules from `@tsdoctor/model` for extracting documentation
29
- * - Uses the per-build prose linker (`linkProse`) for adding type reference links
30
- *
31
- * @see {@link ClassPageGenerator} for class documentation
32
- * @see {@link TypeAliasPageGenerator} for type alias documentation
33
- */
34
- var FunctionPageGenerator = class {
35
- /**
36
- * Generate a markdown page for a function
37
- *
38
- * @param apiScope - API scope identifier for VFS lookup
39
- */
40
- async generate(apiFunction, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
41
- const shouldSuppressErrors = suppressExampleErrors ?? true;
42
- const name = apiFunction.displayName;
43
- const summary = Tsdoc.summary(apiFunction) || "No description available.";
44
- const releaseTag = Tsdoc.releaseTag(apiFunction);
45
- let content = generateFrontmatter(name, summary, singularName, apiName);
46
- content += `import { SourceCode } from "@rspress/core/theme";\n`;
47
- content += `import { ParametersTable } from "rspress-plugin-api-extractor/runtime";\n`;
48
- content += `import { ApiSignature, ApiExample } from "rspress-plugin-api-extractor/runtime";\n\n`;
49
- content += `# ${name}\n\n`;
50
- const deprecation = Tsdoc.deprecation(apiFunction);
51
- if (deprecation) {
52
- const message = escapeMdxGenerics(linkProse(deprecation.message));
53
- content += `> ⚠️ **Deprecated:** ${message}\n\n`;
54
- }
55
- if (releaseTag !== "Public") content += `\`${releaseTag}\`\n\n`;
56
- content += `${summary}\n\n`;
57
- content += generateAvailableFrom(packageName, availableFrom);
58
- const sourceLink = ApiItems.sourceLink(apiFunction, sourceConfig);
59
- if (sourceLink) {
60
- content += `<div className="api-docs-toolbar">\n`;
61
- content += ` <div className="api-docs-toolbar-left">\n`;
62
- content += ` <SourceCode href="${sourceLink}" />\n`;
63
- content += ` </div>\n`;
64
- if (llmsPlugin?.enabled) {
65
- content += ` <div className="api-docs-toolbar-right">\n`;
66
- content += ` </div>\n`;
67
- }
68
- content += `</div>\n\n`;
69
- }
70
- const params = Tsdoc.params(apiFunction);
71
- const hasParameters = params.length > 0;
72
- if (apiFunction.excerpt.text) {
73
- const signature = Signature.format(apiFunction.excerpt).trim();
74
- let signatureWithImports = signature;
75
- const apiPackage = apiFunction.getAssociatedPackage?.();
76
- if (apiPackage) {
77
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(apiFunction);
78
- signatureWithImports = prependHiddenImports(signature, imports);
79
- }
80
- const displayCode = stripTwoslashDirectives(signatureWithImports);
81
- content += `<ApiSignature code={${JSON.stringify(displayCode)}} source={${JSON.stringify(signatureWithImports)}} apiScope={${JSON.stringify(apiScope)}} hasParameters={${hasParameters}} />\n\n`;
82
- }
83
- if (hasParameters) {
84
- const parametersData = params.map((param) => ({
85
- name: param.name,
86
- type: param.type,
87
- description: escapeMdxGenerics(linkProse(param.description))
88
- }));
89
- content += `<ParametersTable parameters={${JSON.stringify(parametersData)}} />\n\n`;
90
- }
91
- const returns = Tsdoc.returns(apiFunction);
92
- if (returns) {
93
- const description = escapeMdxGenerics(linkProse(returns.description));
94
- content += `## Returns\n\n${description}\n\n`;
95
- }
96
- const examples = Tsdoc.examples(apiFunction);
97
- if (examples.length > 0) {
98
- content += `## Examples\n\n`;
99
- for (const example of examples) {
100
- const prepared = prepareExampleCode(example, name, packageName, shouldSuppressErrors);
101
- const formattedCode = await formatExampleCode(prepared.code, prepared.language, {
102
- api: packageName,
103
- blockType: "example"
104
- });
105
- if (prepared.isTypeScript) {
106
- const displayCode = stripTwoslashDirectives(formattedCode);
107
- content += `<ApiExample code={${JSON.stringify(displayCode)}} source={${JSON.stringify(formattedCode)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
108
- } else content += `\`\`\`${prepared.language}\n${formattedCode}\n\`\`\`\n\n`;
109
- }
110
- }
111
- const seeReferences = Tsdoc.seeReferences(apiFunction);
112
- if (seeReferences.length > 0) {
113
- content += `## See Also\n\n`;
114
- for (const reference of seeReferences) {
115
- const refText = escapeMdxGenerics(linkProse(reference.text));
116
- content += `- ${refText}\n`;
117
- }
118
- content += `\n`;
119
- }
120
- return {
121
- routePath: `${baseRoute}/function/${name.toLowerCase()}`,
122
- content
123
- };
124
- }
125
- };
126
-
127
- //#endregion
128
- export { FunctionPageGenerator };
@@ -1,25 +0,0 @@
1
- import { emitFrontmatterBlock } from "../../frontmatter.js";
2
-
3
- //#region src/markdown/page-generators/index-pages.ts
4
- /**
5
- * Generator for main API index page with only frontmatter (no content)
6
- */
7
- var MainIndexPageGenerator = class {
8
- /**
9
- * Generate the main API index page
10
- */
11
- generate(packageName, baseRoute, _categoryCounts) {
12
- const content = emitFrontmatterBlock({
13
- title: "API Reference",
14
- description: `Auto-generated API documentation for ${packageName}`,
15
- overview: true
16
- });
17
- return {
18
- routePath: `${baseRoute}/index`,
19
- content
20
- };
21
- }
22
- };
23
-
24
- //#endregion
25
- export { MainIndexPageGenerator };
@@ -1,311 +0,0 @@
1
- import { TypeReferenceExtractor } from "../../type-reference-extractor.js";
2
- import { escapeMdxGenerics, formatExampleCode, generateAvailableFrom, generateFrontmatter, prepareExampleCode, prependHiddenImports, stripTwoslashDirectives } from "../helpers.js";
3
- import { linkProse } from "../prose-linker.js";
4
- import { ApiItems, Routes, Signature, Tsdoc } from "@tsdoctor/model";
5
-
6
- //#region src/markdown/page-generators/interface-page.ts
7
- /**
8
- * Generates MDX documentation pages for TypeScript interfaces.
9
- *
10
- * This class transforms API Extractor interface models into rich MDX documentation
11
- * pages with syntax-highlighted signatures, cross-linked type references, and
12
- * interactive features.
13
- *
14
- * **Page Structure:**
15
- * 1. Frontmatter with title, description, and Open Graph metadata
16
- * 2. Component imports (SourceCode, ParametersTable, ApiSignature, etc.)
17
- * 3. Page title (H1) and summary
18
- * 4. Optional deprecation warning and release tag badge
19
- * 5. Source code link toolbar
20
- * 6. Full interface signature block showing all members
21
- * 7. Member sections: Call Signatures, Construct Signatures, Index Signatures, Properties, Methods
22
- * 8. Examples section with Twoslash-enabled code blocks
23
- * 9. See Also references
24
- *
25
- * **Interface-Specific Features:**
26
- * - Handles type parameters (generics) in interface declarations
27
- * - Supports call signatures for callable interfaces
28
- * - Supports construct signatures for constructable interfaces
29
- * - Supports index signatures for dictionary-like interfaces
30
- * - Handles extends clauses for interface inheritance
31
- *
32
- * **Relationships:**
33
- * - Created and invoked by {@link ApiExtractorPlugin} during page generation
34
- * - Uses `Signature.format` from `@tsdoctor/model` for formatting type signatures
35
- * - Uses the `Tsdoc` / `ApiItems` modules from `@tsdoctor/model` for extracting documentation
36
- * - Uses the per-build prose linker (`linkProse`) for adding type reference links
37
- *
38
- * @example
39
- * ```ts
40
- * const generator = new InterfacePageGenerator();
41
- * const { routePath, content } = await generator.generate(
42
- * apiInterface,
43
- * "/api/my-package",
44
- * "my-package",
45
- * "Interface",
46
- * "My Package",
47
- * sourceConfig,
48
- * true, // suppressExampleErrors
49
- * undefined, // llmsPlugin
50
- * "claude-binary-plugin", // apiScope
51
- * );
52
- * ```
53
- *
54
- * @see {@link ClassPageGenerator} for class documentation
55
- * @see {@link TypeAliasPageGenerator} for type alias documentation
56
- */
57
- var InterfacePageGenerator = class {
58
- /**
59
- * Generate a markdown page for an interface
60
- *
61
- * @param apiScope - API scope identifier for VFS lookup
62
- */
63
- async generate(apiInterface, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom) {
64
- const shouldSuppressErrors = suppressExampleErrors ?? true;
65
- const name = apiInterface.displayName;
66
- const summary = Tsdoc.summary(apiInterface) || "No description available.";
67
- const releaseTag = Tsdoc.releaseTag(apiInterface);
68
- let content = generateFrontmatter(name, summary, singularName, apiName);
69
- content += `import { SourceCode } from "@rspress/core/theme";\n`;
70
- content += `import { ParametersTable } from "rspress-plugin-api-extractor/runtime";\n`;
71
- content += `import { ApiSignature, ApiMember, ApiExample } from "rspress-plugin-api-extractor/runtime";\n\n`;
72
- content += `# ${name}\n\n`;
73
- const deprecation = Tsdoc.deprecation(apiInterface);
74
- if (deprecation) {
75
- const message = escapeMdxGenerics(linkProse(deprecation.message));
76
- content += `> ⚠️ **Deprecated:** ${message}\n\n`;
77
- }
78
- if (releaseTag !== "Public") content += `\`${releaseTag}\`\n\n`;
79
- content += `${summary}\n\n`;
80
- content += generateAvailableFrom(packageName, availableFrom);
81
- const sourceLink = ApiItems.sourceLink(apiInterface, sourceConfig);
82
- if (sourceLink) {
83
- content += `<div className="api-docs-toolbar">\n`;
84
- content += ` <div className="api-docs-toolbar-left">\n`;
85
- content += ` <SourceCode href="${sourceLink}" />\n`;
86
- content += ` </div>\n`;
87
- if (llmsPlugin?.enabled) {
88
- content += ` <div className="api-docs-toolbar-right">\n`;
89
- content += ` </div>\n`;
90
- }
91
- content += `</div>\n\n`;
92
- }
93
- const skeleton = this.generateInterfaceSkeletonWithTwoslash(apiInterface, packageName);
94
- const displayCode = stripTwoslashDirectives(skeleton);
95
- content += `<ApiSignature code={${JSON.stringify(displayCode)}} source={${JSON.stringify(skeleton)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
96
- const callSignatures = apiInterface.members.filter((m) => m.kind === "CallSignature");
97
- if (callSignatures.length > 0) {
98
- content += `## Call Signatures\n\n`;
99
- for (const callSig of callSignatures) {
100
- const callSigSummary = Tsdoc.summary(callSig);
101
- const callSigId = Routes.memberAnchor("call-signature");
102
- const callSigItem = callSig;
103
- if (callSigItem.excerpt?.text) {
104
- const memberSignature = Signature.format(callSigItem.excerpt).trim();
105
- const skeletonWithContext = this.generateInterfaceMemberWithContext(apiInterface, callSig, packageName);
106
- const summaryMd = callSigSummary ? escapeMdxGenerics(linkProse(callSigSummary)) : void 0;
107
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName="Call Signature"${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(callSigId)}} />\n\n`;
108
- }
109
- }
110
- }
111
- const constructSignatures = apiInterface.members.filter((m) => m.kind === "ConstructSignature");
112
- if (constructSignatures.length > 0) {
113
- content += `## Construct Signatures\n\n`;
114
- for (const constructSig of constructSignatures) {
115
- const constructSigSummary = Tsdoc.summary(constructSig);
116
- const constructSigId = Routes.memberAnchor("construct-signature");
117
- const constructSigItem = constructSig;
118
- if (constructSigItem.excerpt?.text) {
119
- const memberSignature = Signature.format(constructSigItem.excerpt).trim();
120
- const skeletonWithContext = this.generateInterfaceMemberWithContext(apiInterface, constructSig, packageName);
121
- const summaryMd = constructSigSummary ? escapeMdxGenerics(linkProse(constructSigSummary)) : void 0;
122
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName="Construct Signature"${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(constructSigId)}} />\n\n`;
123
- }
124
- }
125
- }
126
- const indexSignatures = apiInterface.members.filter((m) => m.kind === "IndexSignature");
127
- if (indexSignatures.length > 0) {
128
- content += `## Index Signature\n\n`;
129
- for (const indexSig of indexSignatures) {
130
- const indexSigSummary = Tsdoc.summary(indexSig);
131
- const indexSigId = Routes.memberAnchor("index-signature");
132
- const indexSigItem = indexSig;
133
- if (indexSigItem.excerpt?.text) {
134
- const memberSignature = Signature.format(indexSigItem.excerpt).trim();
135
- const skeletonWithContext = this.generateInterfaceMemberWithContext(apiInterface, indexSig, packageName);
136
- const summaryMd = indexSigSummary ? escapeMdxGenerics(linkProse(indexSigSummary)) : void 0;
137
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName="Index Signature"${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(indexSigId)}} />\n\n`;
138
- }
139
- }
140
- }
141
- const properties = apiInterface.members.filter((m) => m.kind === "PropertySignature");
142
- if (properties.length > 0) {
143
- content += `## Properties\n\n`;
144
- for (const prop of properties) {
145
- const propSummary = Tsdoc.summary(prop);
146
- const propId = Routes.memberAnchor(prop.displayName);
147
- const propItem = prop;
148
- if (propItem.excerpt?.text) {
149
- const memberSignature = Signature.format(propItem.excerpt).trim();
150
- const skeletonWithContext = this.generateInterfaceMemberWithContext(apiInterface, prop, packageName);
151
- const summaryMd = propSummary ? escapeMdxGenerics(linkProse(propSummary)) : void 0;
152
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName={${JSON.stringify(prop.displayName)}}${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(propId)}} />\n\n`;
153
- }
154
- }
155
- }
156
- const methods = apiInterface.members.filter((m) => m.kind === "MethodSignature");
157
- if (methods.length > 0) {
158
- content += `## Methods\n\n`;
159
- for (const method of methods) {
160
- const methodSummary = Tsdoc.summary(method);
161
- const methodId = Routes.memberAnchor(method.displayName);
162
- const methodItem = method;
163
- if (methodItem.excerpt?.text) {
164
- const memberSignature = Signature.format(methodItem.excerpt).trim();
165
- const skeletonWithContext = this.generateInterfaceMemberWithContext(apiInterface, method, packageName);
166
- const hasParameters = Tsdoc.params(method).length > 0;
167
- const summaryMd = methodSummary ? escapeMdxGenerics(linkProse(methodSummary)) : void 0;
168
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName={${JSON.stringify(method.displayName)}}${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(methodId)}} hasParameters={${hasParameters}} />\n\n`;
169
- }
170
- const params = Tsdoc.params(method);
171
- if (params.length > 0) content += `<ParametersTable parameters={${JSON.stringify(params.map((p) => ({
172
- name: p.name,
173
- type: p.type,
174
- description: linkProse(p.description)
175
- })))}} />\n\n`;
176
- const returns = Tsdoc.returns(method);
177
- if (returns) {
178
- const description = escapeMdxGenerics(linkProse(returns.description));
179
- content += `**Returns:** ${description}\n\n`;
180
- }
181
- }
182
- }
183
- const examples = Tsdoc.examples(apiInterface);
184
- if (examples.length > 0) {
185
- content += `## Examples\n\n`;
186
- for (const example of examples) {
187
- const prepared = prepareExampleCode(example, name, packageName, shouldSuppressErrors);
188
- const formattedCode = await formatExampleCode(prepared.code, prepared.language, {
189
- api: packageName,
190
- blockType: "example"
191
- });
192
- if (prepared.isTypeScript) {
193
- const displayCode = stripTwoslashDirectives(formattedCode);
194
- content += `<ApiExample code={${JSON.stringify(displayCode)}} source={${JSON.stringify(formattedCode)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
195
- } else content += `\`\`\`${prepared.language}\n${formattedCode}\n\`\`\`\n\n`;
196
- }
197
- }
198
- const seeReferences = Tsdoc.seeReferences(apiInterface);
199
- if (seeReferences.length > 0) {
200
- content += `## See Also\n\n`;
201
- for (const reference of seeReferences) {
202
- const refText = escapeMdxGenerics(linkProse(reference.text));
203
- content += `- ${refText}\n`;
204
- }
205
- content += `\n`;
206
- }
207
- return {
208
- routePath: `${baseRoute}/interface/${name.toLowerCase()}`,
209
- content
210
- };
211
- }
212
- /**
213
- * Generate an interface member signature with full interface context
214
- * Includes hidden imports with cut directive for external type resolution
215
- * Uses the simplified approach: 3 lines (interface opening, member, closing)
216
- */
217
- generateInterfaceMemberWithContext(apiInterface, targetMember, packageName) {
218
- const interfaceName = apiInterface.displayName;
219
- const inheritance = ApiItems.inheritance(apiInterface);
220
- let declaration = `interface ${interfaceName}`;
221
- if (apiInterface.typeParameters && apiInterface.typeParameters.length > 0) {
222
- const typeParams = apiInterface.typeParameters.map((tp) => tp.name).join(", ");
223
- declaration += `<${typeParams}>`;
224
- }
225
- if (inheritance.extends && inheritance.extends.length > 0) declaration += ` extends ${inheritance.extends.join(", ")}`;
226
- declaration += " {";
227
- const memberItem = targetMember;
228
- const memberSignature = memberItem.excerpt?.text ? Signature.format(memberItem.excerpt).trim() : "";
229
- const skeleton = `${declaration}\n${memberSignature}\n}`;
230
- const apiPackage = apiInterface.getAssociatedPackage?.();
231
- if (apiPackage) {
232
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(targetMember);
233
- return prependHiddenImports(skeleton, imports);
234
- }
235
- return skeleton;
236
- }
237
- /**
238
- * Generate an interface skeleton for signature blocks
239
- * Includes hidden imports with cut directive for external type resolution
240
- */
241
- generateInterfaceSkeletonWithTwoslash(apiInterface, packageName) {
242
- const skeleton = this.generateInterfaceSkeleton(apiInterface);
243
- const apiPackage = apiInterface.getAssociatedPackage?.();
244
- if (apiPackage) {
245
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(apiInterface);
246
- return prependHiddenImports(skeleton, imports);
247
- }
248
- return skeleton;
249
- }
250
- /**
251
- * Generate a complete interface skeleton showing all members
252
- */
253
- generateInterfaceSkeleton(apiInterface) {
254
- const lines = [];
255
- const interfaceName = apiInterface.displayName;
256
- const inheritance = ApiItems.inheritance(apiInterface);
257
- let declaration = `interface ${interfaceName}`;
258
- if (apiInterface.typeParameters && apiInterface.typeParameters.length > 0) {
259
- const typeParams = apiInterface.typeParameters.map((tp) => tp.name).join(", ");
260
- declaration += `<${typeParams}>`;
261
- }
262
- if (inheritance.extends && inheritance.extends.length > 0) declaration += ` extends ${inheritance.extends.join(", ")}`;
263
- declaration += " {";
264
- lines.push(declaration);
265
- const callSignatures = apiInterface.members.filter((m) => m.kind === "CallSignature");
266
- if (callSignatures.length > 0) for (const callSig of callSignatures) {
267
- const callSigItem = callSig;
268
- if (callSigItem.excerpt?.text) {
269
- const signature = Signature.format(callSigItem.excerpt).trim();
270
- lines.push(` ${signature}`);
271
- }
272
- }
273
- const constructSignatures = apiInterface.members.filter((m) => m.kind === "ConstructSignature");
274
- if (constructSignatures.length > 0) for (const constructSig of constructSignatures) {
275
- const constructSigItem = constructSig;
276
- if (constructSigItem.excerpt?.text) {
277
- const signature = Signature.format(constructSigItem.excerpt).trim();
278
- lines.push(` ${signature}`);
279
- }
280
- }
281
- const indexSignatures = apiInterface.members.filter((m) => m.kind === "IndexSignature");
282
- if (indexSignatures.length > 0) for (const indexSig of indexSignatures) {
283
- const indexSigItem = indexSig;
284
- if (indexSigItem.excerpt?.text) {
285
- const signature = Signature.format(indexSigItem.excerpt).trim();
286
- lines.push(` ${signature}`);
287
- }
288
- }
289
- const properties = apiInterface.members.filter((m) => m.kind === "PropertySignature");
290
- if (properties.length > 0) for (const prop of properties) {
291
- const propItem = prop;
292
- if (propItem.excerpt?.text) {
293
- const signature = Signature.format(propItem.excerpt).trim();
294
- lines.push(` ${signature}`);
295
- }
296
- }
297
- const methods = apiInterface.members.filter((m) => m.kind === "MethodSignature");
298
- if (methods.length > 0) for (const method of methods) {
299
- const methodItem = method;
300
- if (methodItem.excerpt?.text) {
301
- const signature = Signature.format(methodItem.excerpt).trim();
302
- lines.push(` ${signature}`);
303
- }
304
- }
305
- lines.push("}");
306
- return lines.join("\n");
307
- }
308
- };
309
-
310
- //#endregion
311
- export { InterfacePageGenerator };