rspress-plugin-api-extractor 0.14.0 → 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 (37) hide show
  1. package/BuildEnv.js +0 -1
  2. package/build-program.js +4 -4
  3. package/build-stages.js +98 -281
  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 +1 -42
  8. package/layers/build-metrics.js +1 -2
  9. package/layers/config-resolution.js +3 -5
  10. package/layers/type-environment.js +1 -2
  11. package/llms-program.js +3 -3
  12. package/markdown/helpers.js +10 -176
  13. package/observability/sinks/console-sink.js +0 -1
  14. package/observability/sinks/metrics-sink.js +0 -2
  15. package/package.json +6 -5
  16. package/path-derivation.js +1 -29
  17. package/plugin.js +2 -1
  18. package/prettier-formatter.js +27 -59
  19. package/remark-with-api.js +3 -2
  20. package/schemas/config.js +1 -18
  21. package/schemas/observability.js +0 -2
  22. package/schemas/performance.js +0 -1
  23. package/services/TwoslashCacheService.js +1 -1
  24. package/twoslash-transformer.js +14 -2
  25. package/code-post-processor.js +0 -38
  26. package/llms-processing.js +0 -270
  27. package/markdown/page-generators/class-page.js +0 -363
  28. package/markdown/page-generators/enum-page.js +0 -152
  29. package/markdown/page-generators/function-page.js +0 -127
  30. package/markdown/page-generators/index-pages.js +0 -25
  31. package/markdown/page-generators/interface-page.js +0 -310
  32. package/markdown/page-generators/namespace-page.js +0 -277
  33. package/markdown/page-generators/type-alias-page.js +0 -110
  34. package/markdown/page-generators/variable-page.js +0 -110
  35. package/markdown/prose-linker.js +0 -22
  36. package/twoslash-cache.js +0 -174
  37. package/twoslash-patterns.js +0 -87
@@ -1,270 +0,0 @@
1
- //#region src/llms-processing.ts
2
- /** Pre-compiled regex for parsing llms.txt link lines. */
3
- const LLMS_TXT_LINE_RE = /^-\s+\[([^\]]+)\]\(([^)]+)\)(?::\s*(.+))?$/;
4
- /**
5
- * Parse a single line from llms.txt format.
6
- *
7
- * Recognizes the pattern: `- [title](url): description`
8
- * The description portion (`: description`) is optional.
9
- *
10
- * @param line - A single line from an llms.txt file
11
- * @returns Parsed entry or null for non-link lines (headers, empty lines, plain text)
12
- */
13
- function parseLlmsTxtLine(line) {
14
- const trimmed = line.trim();
15
- if (trimmed === "") return null;
16
- const match = LLMS_TXT_LINE_RE.exec(trimmed);
17
- if (!match) return null;
18
- const title = match[1];
19
- const url = match[2];
20
- const rawDescription = match[3];
21
- return {
22
- title,
23
- url,
24
- description: rawDescription ? rawDescription.trim() : void 0
25
- };
26
- }
27
- /**
28
- * Filter API page entries from global llms.txt content.
29
- *
30
- * Removes lines whose parsed URL is in the `apiRoutes` set.
31
- * Appends pointer lines for per-package llms files when `pointers` is non-empty.
32
- *
33
- * @param content - Full llms.txt content string
34
- * @param apiRoutes - Set of API route paths to remove
35
- * @param pointers - Per-package pointer entries to append
36
- * @returns Filtered llms.txt content
37
- */
38
- function filterLlmsTxt(content, apiRoutes, pointers) {
39
- const lines = content.split("\n");
40
- const filtered = [];
41
- for (const line of lines) {
42
- const entry = parseLlmsTxtLine(line);
43
- if (entry && apiRoutes.has(entry.url)) continue;
44
- filtered.push(line);
45
- }
46
- let result = filtered.join("\n");
47
- if (pointers.length > 0) {
48
- result += "\n\n";
49
- for (const pointer of pointers) result += `- For ${pointer.name} API docs, see [${pointer.name} llms.txt](${pointer.llmsTxtUrl})\n`;
50
- }
51
- return result;
52
- }
53
- /**
54
- * Generate a structured global llms.txt that groups pages by package scope.
55
- *
56
- * Output format:
57
- * ```
58
- * # {site title}
59
- *
60
- * ## Others
61
- * - [Blog Post](/blog/post.md)
62
- *
63
- * ## Packages
64
- *
65
- * ### {name} {version}
66
- * {description}
67
- * - [Guide Page](/pkg/guides/guide.md)
68
- * - [API Reference](/pkg/llms-api.txt)
69
- * ```
70
- *
71
- * @param content - Original RSPress-generated llms.txt content
72
- * @param apiRoutes - Set of API route paths to exclude as individual entries
73
- * @param packages - Package scope metadata
74
- * @returns Restructured llms.txt content
75
- */
76
- function generateStructuredLlmsTxt(content, apiRoutes, packages) {
77
- const lines = content.split("\n");
78
- let title = "";
79
- for (const line of lines) if (line.startsWith("# ")) {
80
- title = line;
81
- break;
82
- }
83
- const allEntries = [];
84
- for (const line of lines) {
85
- const entry = parseLlmsTxtLine(line);
86
- if (entry && !apiRoutes.has(entry.url)) allEntries.push(entry);
87
- }
88
- const packageEntries = /* @__PURE__ */ new Map();
89
- const others = [];
90
- for (const entry of allEntries) {
91
- let matched = false;
92
- for (const pkg of packages) {
93
- const base = pkg.packageRoute.endsWith("/") ? pkg.packageRoute : `${pkg.packageRoute}/`;
94
- if (entry.url.startsWith(base) || entry.url === pkg.packageRoute) {
95
- const existing = packageEntries.get(pkg.packageName) ?? [];
96
- existing.push(entry);
97
- packageEntries.set(pkg.packageName, existing);
98
- matched = true;
99
- break;
100
- }
101
- }
102
- if (!matched) others.push(entry);
103
- }
104
- const output = [];
105
- if (title) {
106
- output.push(title);
107
- output.push("");
108
- }
109
- if (others.length > 0) {
110
- output.push("## Others");
111
- output.push("");
112
- for (const entry of others) output.push(formatEntry(entry));
113
- output.push("");
114
- }
115
- const packagesWithEntries = packages;
116
- if (packagesWithEntries.length > 0) {
117
- output.push("## Packages");
118
- output.push("");
119
- for (const pkg of packagesWithEntries) {
120
- const versionSuffix = pkg.version ? ` ${pkg.version}` : "";
121
- output.push(`### ${pkg.name}${versionSuffix}`);
122
- output.push("");
123
- if (pkg.description) {
124
- output.push(pkg.description);
125
- output.push("");
126
- }
127
- const entries = packageEntries.get(pkg.packageName) ?? [];
128
- for (const entry of entries) output.push(formatEntry(entry));
129
- output.push(`- [API Reference](${pkg.llmsApiTxtUrl})`);
130
- output.push("");
131
- }
132
- }
133
- return output.join("\n");
134
- }
135
- /**
136
- * Parse llms-full.txt content into sections delimited by frontmatter blocks.
137
- *
138
- * Each section has the format:
139
- * ```
140
- * ---
141
- * url: /path/to/page
142
- * ---
143
- *
144
- * Content here...
145
- * ```
146
- */
147
- function parseSections(content) {
148
- if (content.trim() === "") return [];
149
- const sections = [];
150
- const frontmatterPattern = /^---\nurl:\s*(.+)\n---$/gm;
151
- let match = frontmatterPattern.exec(content);
152
- const boundaries = [];
153
- while (match !== null) {
154
- boundaries.push({
155
- url: match[1].trim(),
156
- start: match.index,
157
- fmEnd: match.index + match[0].length
158
- });
159
- match = frontmatterPattern.exec(content);
160
- }
161
- for (let i = 0; i < boundaries.length; i++) {
162
- const boundary = boundaries[i];
163
- const nextStart = i + 1 < boundaries.length ? boundaries[i + 1].start : content.length;
164
- const sectionContent = content.slice(boundary.start, nextStart);
165
- sections.push({
166
- url: boundary.url,
167
- raw: sectionContent.trimEnd()
168
- });
169
- }
170
- return sections;
171
- }
172
- /**
173
- * Filter API page content sections from global llms-full.txt.
174
- *
175
- * Sections are delimited by `---\nurl: {path}\n---` frontmatter blocks.
176
- * Removes entire sections whose URL matches a known API route.
177
- *
178
- * @param content - Full llms-full.txt content string
179
- * @param apiRoutes - Set of API route paths to remove
180
- * @returns Filtered llms-full.txt content
181
- */
182
- function filterLlmsFullTxt(content, apiRoutes) {
183
- if (content.trim() === "") return "";
184
- const kept = parseSections(content).filter((section) => !apiRoutes.has(section.url));
185
- if (kept.length === 0) return "";
186
- return kept.map((section) => section.raw).join("\n\n\n");
187
- }
188
- /**
189
- * Format a single llms.txt link entry.
190
- */
191
- function formatEntry(entry) {
192
- if (entry.description) return `- [${entry.title}](${entry.url}): ${entry.description}`;
193
- return `- [${entry.title}](${entry.url})`;
194
- }
195
- /**
196
- * Generate a per-package llms.txt index.
197
- *
198
- * Output format:
199
- * ```
200
- * # {name}
201
- *
202
- * ## Guides
203
- *
204
- * - [Guide Title](/path): Description
205
- *
206
- * ## API Reference
207
- *
208
- * - [ApiItem](/path): Description
209
- * ```
210
- *
211
- * Sections with no entries are omitted.
212
- *
213
- * @param input - Package name, guide pages, and API pages
214
- * @returns Generated llms.txt content
215
- */
216
- function generatePackageLlmsTxt(input) {
217
- const parts = [
218
- `# ${input.name}`,
219
- "",
220
- `> API documentation for the ${input.packageName} package`
221
- ];
222
- if (input.guidePages.length > 0) {
223
- parts.push("");
224
- parts.push("## Guides");
225
- parts.push("");
226
- for (const page of input.guidePages) parts.push(formatEntry(page));
227
- }
228
- if (input.apiPages.length > 0) {
229
- parts.push("");
230
- parts.push("## API Reference");
231
- parts.push("");
232
- for (const page of input.apiPages) parts.push(formatEntry(page));
233
- }
234
- parts.push("");
235
- return parts.join("\n");
236
- }
237
- /**
238
- * Concatenate page contents with frontmatter delimiters.
239
- *
240
- * Used for llms-full.txt, llms-docs.txt, and llms-api.txt generation
241
- * (pass different page sets for each).
242
- *
243
- * Output format:
244
- * ```
245
- * ---
246
- * url: /path/to/page
247
- * ---
248
- *
249
- * Content here...
250
- *
251
- *
252
- * ---
253
- * url: /path/to/next
254
- * ---
255
- *
256
- * More content...
257
- * ```
258
- *
259
- * @param pages - Array of page URLs and their markdown content
260
- * @returns Concatenated content with frontmatter delimiters
261
- */
262
- function generatePackageLlmsFullTxt(pages) {
263
- if (pages.length === 0) return "";
264
- const sections = [];
265
- for (const page of pages) sections.push(`---\nurl: ${page.url}\n---\n\n${page.content}`);
266
- return sections.join("\n\n\n");
267
- }
268
-
269
- //#endregion
270
- export { filterLlmsFullTxt, filterLlmsTxt, generatePackageLlmsFullTxt, generatePackageLlmsTxt, generateStructuredLlmsTxt, parseLlmsTxtLine };
@@ -1,363 +0,0 @@
1
- import { escapeMdxGenerics, formatExampleCode, generateAvailableFrom, generateFrontmatter, prepareExampleCode, prependHiddenImports, stripTwoslashDirectives } from "../helpers.js";
2
- import { linkProse } from "../prose-linker.js";
3
- import { ApiItems, Routes, Signature, Tsdoc, TypeReferenceExtractor } from "@tsdoctor/model";
4
-
5
- //#region src/markdown/page-generators/class-page.ts
6
- /**
7
- * Generates MDX documentation pages for TypeScript/JavaScript classes.
8
- *
9
- * This class transforms API Extractor class models into rich MDX documentation pages
10
- * with syntax-highlighted signatures, cross-linked type references, and interactive
11
- * features like copy-to-clipboard and line wrapping.
12
- *
13
- * **Page Structure:**
14
- * 1. Frontmatter with title, description, and Open Graph metadata
15
- * 2. Component imports (SourceCode, ParametersTable, ApiSignature, etc.)
16
- * 3. Page title (H1) and summary
17
- * 4. Optional deprecation warning and release tag badge
18
- * 5. Source code link toolbar
19
- * 6. Full class signature block showing all members
20
- * 7. Member sections: Constructors, Static Properties, Static Methods, Properties, Getters/Setters, Methods
21
- * 8. Examples section with Twoslash-enabled code blocks
22
- * 9. See Also references
23
- *
24
- * **Member Rendering:**
25
- * Each member is rendered with:
26
- * - An `ApiMember` component showing the signature in class context
27
- * - Optional `ParametersTable` for methods with parameters
28
- * - Return type documentation
29
- * - Cross-linked type references
30
- *
31
- * **Relationships:**
32
- * - Created and invoked by {@link ApiExtractorPlugin} during page generation
33
- * - Uses `Signature.format` from `@tsdoctor/model` for formatting type signatures
34
- * - Uses the `Tsdoc` / `ApiItems` modules from `@tsdoctor/model` for extracting documentation
35
- * - Uses the per-build prose linker (`linkProse`) for adding type reference links
36
- *
37
- * @example
38
- * ```ts
39
- * const generator = new ClassPageGenerator();
40
- * const { routePath, content } = await generator.generate(
41
- * apiClass,
42
- * "/api/my-package",
43
- * "my-package",
44
- * "Class",
45
- * "My Package",
46
- * sourceConfig,
47
- * true, // suppressExampleErrors
48
- * undefined, // llmsPlugin
49
- * "claude-binary-plugin", // apiScope
50
- * );
51
- * ```
52
- *
53
- * @see {@link InterfacePageGenerator} for interface documentation
54
- * @see {@link FunctionPageGenerator} for function documentation
55
- */
56
- var ClassPageGenerator = class {
57
- /**
58
- * Generate a markdown page for a class
59
- *
60
- * @param apiScope - API scope identifier for VFS lookup
61
- */
62
- async generate(apiClass, baseRoute, packageName, singularName, apiScope, apiName, sourceConfig, suppressExampleErrors, llmsPlugin, availableFrom, syntheticBase, memberAnchors) {
63
- const shouldSuppressErrors = suppressExampleErrors ?? true;
64
- const name = apiClass.displayName;
65
- const summary = Tsdoc.summary(apiClass) || "No description available.";
66
- const releaseTag = Tsdoc.releaseTag(apiClass);
67
- let content = generateFrontmatter(name, summary, singularName, apiName);
68
- content += `import { SourceCode } from "@rspress/core/theme";\n`;
69
- content += `import { ParametersTable } from "rspress-plugin-api-extractor/runtime";\n`;
70
- content += `import { ApiSignature, ApiMember, ApiExample } from "rspress-plugin-api-extractor/runtime";\n\n`;
71
- content += `# ${name}\n\n`;
72
- const deprecation = Tsdoc.deprecation(apiClass);
73
- if (deprecation) {
74
- const message = escapeMdxGenerics(linkProse(deprecation.message));
75
- content += `> ⚠️ **Deprecated:** ${message}\n\n`;
76
- }
77
- if (releaseTag !== "Public") content += `\`${releaseTag}\`\n\n`;
78
- content += `${summary}\n\n`;
79
- content += generateAvailableFrom(packageName, availableFrom);
80
- const sourceLink = ApiItems.sourceLink(apiClass, sourceConfig);
81
- if (sourceLink) {
82
- content += `<div className="api-docs-toolbar">\n`;
83
- content += ` <div className="api-docs-toolbar-left">\n`;
84
- content += ` <SourceCode href="${sourceLink}" />\n`;
85
- content += ` </div>\n`;
86
- if (llmsPlugin?.enabled) {
87
- content += ` <div className="api-docs-toolbar-right">\n`;
88
- content += ` </div>\n`;
89
- }
90
- content += `</div>\n\n`;
91
- }
92
- const skeleton = this.generateClassSkeletonWithTwoslash(apiClass, packageName);
93
- const displayCode = stripTwoslashDirectives(skeleton);
94
- content += `<ApiSignature code={${JSON.stringify(displayCode)}} source={${JSON.stringify(skeleton)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
95
- content += this.generateBaseClassSection(apiClass, syntheticBase, packageName, apiScope);
96
- const constructors = apiClass.members.filter((m) => m.kind === "Constructor");
97
- if (constructors.length > 0) {
98
- content += `## Constructors\n\n`;
99
- for (const ctor of constructors) {
100
- const ctorSummary = Tsdoc.summary(ctor);
101
- const ctorId = Routes.memberAnchor("constructor");
102
- const ctorItem = ctor;
103
- const params = Tsdoc.params(ctor);
104
- const hasParameters = params.length > 0;
105
- if (ctorItem.excerpt?.text) {
106
- const memberSignature = Signature.format(ctorItem.excerpt).trim();
107
- const skeletonWithContext = this.generateClassMemberWithContext(apiClass, ctor, packageName);
108
- const summaryMd = ctorSummary ? escapeMdxGenerics(linkProse(ctorSummary)) : void 0;
109
- content += `<ApiMember code={${JSON.stringify(memberSignature)}} source={${JSON.stringify(skeletonWithContext)}} apiScope={${JSON.stringify(apiScope)}} memberName="constructor"${summaryMd ? ` summary={${JSON.stringify(summaryMd)}}` : ""} id={${JSON.stringify(ctorId)}} hasParameters={${hasParameters}} />\n\n`;
110
- }
111
- if (hasParameters) content += `<ParametersTable parameters={${JSON.stringify(params.map((p) => ({
112
- name: p.name,
113
- type: p.type,
114
- description: linkProse(p.description)
115
- })))}} />\n\n`;
116
- }
117
- }
118
- const properties = apiClass.members.filter((m) => m.kind === "Property" || m.kind === "PropertySignature");
119
- const methods = apiClass.members.filter((m) => m.kind === "Method" || m.kind === "MethodSignature");
120
- const grouped = methods.length > 0 ? this.groupClassMembers(methods) : {
121
- staticMethods: [],
122
- instanceMethods: [],
123
- getters: []
124
- };
125
- const staticProperties = properties.filter((m) => {
126
- return m.isStatic === true;
127
- });
128
- const instanceProperties = properties.filter((m) => {
129
- const isStatic = m.isStatic === true;
130
- const isGetter = m.displayName.startsWith("get ") || m.displayName.startsWith("set ");
131
- return !isStatic && !isGetter;
132
- });
133
- const anchors = memberAnchors ?? ApiItems.memberAnchors(apiClass);
134
- const anchorFor = (member) => anchors.get(member.canonicalReference?.toString() ?? member.displayName) ?? Routes.memberAnchor(member.displayName);
135
- const renderProperties = async (title, propList) => {
136
- if (propList.length === 0) return;
137
- content += `## ${title}\n\n`;
138
- for (const prop of propList) {
139
- const propSummary = Tsdoc.summary(prop);
140
- const propId = anchorFor(prop);
141
- const propItem = prop;
142
- if (propItem.excerpt?.text) {
143
- const memberSignature = Signature.format(propItem.excerpt).trim();
144
- const skeletonWithContext = this.generateClassMemberWithContext(apiClass, prop, packageName);
145
- const summaryMd = propSummary ? escapeMdxGenerics(linkProse(propSummary)) : void 0;
146
- 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`;
147
- }
148
- }
149
- };
150
- const renderMethods = async (title, methodList) => {
151
- if (methodList.length === 0) return;
152
- content += `## ${title}\n\n`;
153
- for (const method of methodList) {
154
- const methodSummary = Tsdoc.summary(method);
155
- const methodId = anchorFor(method);
156
- const methodItem = method;
157
- const params = Tsdoc.params(method);
158
- const hasParameters = params.length > 0;
159
- if (methodItem.excerpt?.text) {
160
- const memberSignature = Signature.format(methodItem.excerpt).trim();
161
- const skeletonWithContext = this.generateClassMemberWithContext(apiClass, method, packageName);
162
- const summaryMd = methodSummary ? escapeMdxGenerics(linkProse(methodSummary)) : void 0;
163
- 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`;
164
- }
165
- if (hasParameters) content += `<ParametersTable parameters={${JSON.stringify(params.map((p) => ({
166
- name: p.name,
167
- type: p.type,
168
- description: linkProse(p.description)
169
- })))}} />\n\n`;
170
- const returns = Tsdoc.returns(method);
171
- if (returns) {
172
- const description = escapeMdxGenerics(linkProse(returns.description));
173
- content += `**Returns:** ${description}\n\n`;
174
- }
175
- }
176
- };
177
- await renderProperties("Static Properties", staticProperties);
178
- await renderMethods("Static Methods", grouped.staticMethods);
179
- await renderProperties("Properties", instanceProperties);
180
- await renderMethods("Getters & Setters", grouped.getters);
181
- await renderMethods("Methods", grouped.instanceMethods);
182
- const examples = Tsdoc.examples(apiClass);
183
- if (examples.length > 0) {
184
- content += `## Examples\n\n`;
185
- for (const example of examples) {
186
- const prepared = prepareExampleCode(example, name, packageName, shouldSuppressErrors);
187
- const formattedCode = await formatExampleCode(prepared.code, prepared.language, {
188
- api: packageName,
189
- blockType: "example"
190
- });
191
- if (prepared.isTypeScript) {
192
- const displayCode = stripTwoslashDirectives(formattedCode);
193
- content += `<ApiExample code={${JSON.stringify(displayCode)}} source={${JSON.stringify(formattedCode)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
194
- } else content += `\`\`\`${prepared.language}\n${formattedCode}\n\`\`\`\n\n`;
195
- }
196
- }
197
- const seeReferences = Tsdoc.seeReferences(apiClass);
198
- if (seeReferences.length > 0) {
199
- content += `## See Also\n\n`;
200
- for (const reference of seeReferences) {
201
- const refText = escapeMdxGenerics(linkProse(reference.text));
202
- content += `- ${refText}\n`;
203
- }
204
- content += `\n`;
205
- }
206
- return {
207
- routePath: `${baseRoute}/class/${name.toLowerCase()}`,
208
- content
209
- };
210
- }
211
- /**
212
- * Render the inline "Base Class" section for a synthetic base declaration
213
- * (an unexported item referenced by the class's extends clause, e.g. the
214
- * `Foo_base` variable TypeScript emits for `Schema.Class`-style patterns).
215
- *
216
- * The `## Base Class` heading slugs to `BASE_CLASS_ANCHOR` from
217
- * `@tsdoctor/model`'s `SyntheticBases`, which is where the cross-link
218
- * route for the base name points.
219
- */
220
- generateBaseClassSection(apiClass, syntheticBase, packageName, apiScope) {
221
- const baseDecl = syntheticBase;
222
- if (!baseDecl?.excerpt?.text) return "";
223
- let section = `## Base Class\n\n`;
224
- section += `\`${apiClass.displayName}\` extends \`${baseDecl.displayName}\`, a compiler-generated declaration that is not exported from \`${packageName}\`.\n\n`;
225
- const signature = Signature.format(baseDecl.excerpt).trim();
226
- let source = signature;
227
- const apiPackage = apiClass.getAssociatedPackage?.();
228
- if (apiPackage) {
229
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(baseDecl);
230
- source = prependHiddenImports(signature, imports);
231
- }
232
- const displayCode = stripTwoslashDirectives(source);
233
- section += `<ApiSignature code={${JSON.stringify(displayCode)}} source={${JSON.stringify(source)}} apiScope={${JSON.stringify(apiScope)}} />\n\n`;
234
- return section;
235
- }
236
- /**
237
- * Group class members by their type (static, instance, getters/setters)
238
- */
239
- groupClassMembers(members) {
240
- const staticMethods = [];
241
- const instanceMethods = [];
242
- const getters = [];
243
- for (const member of members) {
244
- const isGetter = member.kind === "Method" && (member.displayName.startsWith("get ") || member.displayName.startsWith("set "));
245
- const isStatic = member.isStatic === true;
246
- if (isGetter) getters.push(member);
247
- else if (isStatic) staticMethods.push(member);
248
- else instanceMethods.push(member);
249
- }
250
- return {
251
- staticMethods,
252
- instanceMethods,
253
- getters
254
- };
255
- }
256
- /**
257
- * Generate a class member signature with full class context
258
- * Includes hidden imports with cut directive for external type resolution
259
- * Uses the simplified approach: 3 lines (class opening, member, closing)
260
- */
261
- generateClassMemberWithContext(apiClass, targetMember, packageName) {
262
- const className = apiClass.displayName;
263
- const inheritance = ApiItems.inheritance(apiClass);
264
- let declaration = `class ${className}`;
265
- if (inheritance.extends && inheritance.extends.length > 0) declaration += ` extends ${inheritance.extends.join(", ")}`;
266
- if (inheritance.implements && inheritance.implements.length > 0) declaration += ` implements ${inheritance.implements.join(", ")}`;
267
- declaration += " {";
268
- const memberItem = targetMember;
269
- const memberSignature = memberItem.excerpt?.text ? Signature.format(memberItem.excerpt).trim() : "";
270
- const skeleton = `${declaration}\n${memberSignature}\n}`;
271
- const apiPackage = apiClass.getAssociatedPackage?.();
272
- if (apiPackage) {
273
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(targetMember);
274
- return prependHiddenImports(skeleton, imports);
275
- }
276
- return skeleton;
277
- }
278
- /**
279
- * Generate a class skeleton for signature blocks
280
- * Includes hidden imports with cut directive for external type resolution
281
- */
282
- generateClassSkeletonWithTwoslash(apiClass, packageName) {
283
- const skeleton = this.generateClassSkeleton(apiClass);
284
- const apiPackage = apiClass.getAssociatedPackage?.();
285
- if (apiPackage) {
286
- const imports = new TypeReferenceExtractor(apiPackage, packageName).extractImportsForApiItem(apiClass);
287
- return prependHiddenImports(skeleton, imports);
288
- }
289
- return skeleton;
290
- }
291
- /**
292
- * Generate a complete class skeleton showing all members
293
- */
294
- generateClassSkeleton(apiClass) {
295
- const lines = [];
296
- const className = apiClass.displayName;
297
- const inheritance = ApiItems.inheritance(apiClass);
298
- let declaration = `class ${className}`;
299
- if (inheritance.extends && inheritance.extends.length > 0) declaration += ` extends ${inheritance.extends.join(", ")}`;
300
- if (inheritance.implements && inheritance.implements.length > 0) declaration += ` implements ${inheritance.implements.join(", ")}`;
301
- declaration += " {";
302
- lines.push(declaration);
303
- const constructors = apiClass.members.filter((m) => m.kind === "Constructor");
304
- if (constructors.length > 0) for (const ctor of constructors) {
305
- const ctorItem = ctor;
306
- if (ctorItem.excerpt?.text) {
307
- const signature = Signature.format(ctorItem.excerpt).trim();
308
- lines.push(` ${signature}`);
309
- }
310
- }
311
- const methods = apiClass.members.filter((m) => m.kind === "Method" || m.kind === "MethodSignature");
312
- const grouped = this.groupClassMembers(methods);
313
- const properties = apiClass.members.filter((m) => m.kind === "Property" || m.kind === "PropertySignature");
314
- const staticProperties = properties.filter((m) => {
315
- return m.isStatic === true;
316
- });
317
- if (staticProperties.length > 0) for (const prop of staticProperties) {
318
- const propItem = prop;
319
- if (propItem.excerpt?.text) {
320
- const signature = Signature.format(propItem.excerpt).trim();
321
- lines.push(` ${signature}`);
322
- }
323
- }
324
- if (grouped.staticMethods.length > 0) for (const method of grouped.staticMethods) {
325
- const methodItem = method;
326
- if (methodItem.excerpt?.text) {
327
- const signature = Signature.format(methodItem.excerpt).trim();
328
- lines.push(` ${signature}`);
329
- }
330
- }
331
- const instanceProperties = properties.filter((m) => {
332
- const isStatic = m.isStatic === true;
333
- const isGetter = m.displayName.startsWith("get ") || m.displayName.startsWith("set ");
334
- return !isStatic && !isGetter;
335
- });
336
- if (instanceProperties.length > 0) for (const prop of instanceProperties) {
337
- const propItem = prop;
338
- if (propItem.excerpt?.text) {
339
- const signature = Signature.format(propItem.excerpt).trim();
340
- lines.push(` ${signature}`);
341
- }
342
- }
343
- if (grouped.getters.length > 0) for (const method of grouped.getters) {
344
- const methodItem = method;
345
- if (methodItem.excerpt?.text) {
346
- const signature = Signature.format(methodItem.excerpt).trim();
347
- lines.push(` ${signature}`);
348
- }
349
- }
350
- if (grouped.instanceMethods.length > 0) for (const method of grouped.instanceMethods) {
351
- const methodItem = method;
352
- if (methodItem.excerpt?.text) {
353
- const signature = Signature.format(methodItem.excerpt).trim();
354
- lines.push(` ${signature}`);
355
- }
356
- }
357
- lines.push("}");
358
- return lines.join("\n");
359
- }
360
- };
361
-
362
- //#endregion
363
- export { ClassPageGenerator };