fumadocs-typescript 5.0.1 → 5.1.1
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.
- package/dist/base-Dvhn4vZx.d.ts +1 -2
- package/dist/index.d.ts +12 -6
- package/dist/index.js +144 -197
- package/dist/parse-tags-B09hzgIX.js +68 -0
- package/dist/ui/index.d.ts +14 -11
- package/dist/ui/index.js +31 -66
- package/package.json +10 -10
- package/dist/base-Dvhn4vZx.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/objectSpread2-BbbttTvx.js +0 -203
- package/dist/objectSpread2-BbbttTvx.js.map +0 -1
- package/dist/ui/index.d.ts.map +0 -1
- package/dist/ui/index.js.map +0 -1
package/dist/base-Dvhn4vZx.d.ts
CHANGED
|
@@ -111,5 +111,4 @@ declare function createGenerator(config?: GeneratorOptions | Project): {
|
|
|
111
111
|
generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
|
|
112
112
|
};
|
|
113
113
|
//#endregion
|
|
114
|
-
export { GeneratorOptions as a, Cache as c, createProject as d, Generator as i, BaseTypeTableProps as l, GenerateOptions as n, RawTag as o, GeneratedDoc as r, createGenerator as s, DocEntry as t, GenerateTypeTableOptions as u };
|
|
115
|
-
//# sourceMappingURL=base-Dvhn4vZx.d.ts.map
|
|
114
|
+
export { GeneratorOptions as a, Cache as c, createProject as d, Generator as i, BaseTypeTableProps as l, GenerateOptions as n, RawTag as o, GeneratedDoc as r, createGenerator as s, DocEntry as t, GenerateTypeTableOptions as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { a as GeneratorOptions, c as Cache, d as createProject, i as Generator, l as BaseTypeTableProps, n as GenerateOptions, o as RawTag, r as GeneratedDoc, s as createGenerator, t as DocEntry, u as GenerateTypeTableOptions } from "./base-Dvhn4vZx.js";
|
|
2
|
+
import { ResolvedShikiConfig } from "fumadocs-core/highlight/config";
|
|
2
3
|
import { Nodes } from "hast";
|
|
3
4
|
import { Root } from "mdast";
|
|
4
5
|
import { Transformer } from "unified";
|
|
5
6
|
|
|
6
7
|
//#region src/markdown.d.ts
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
interface MarkdownRenderer {
|
|
9
|
+
renderTypeToHast: (type: string) => Nodes | Promise<Nodes>;
|
|
10
|
+
renderMarkdownToHast: (md: string) => Nodes | Promise<Nodes>;
|
|
11
|
+
}
|
|
9
12
|
//#endregion
|
|
10
13
|
//#region src/lib/remark-auto-type-table.d.ts
|
|
11
14
|
interface RemarkAutoTypeTableOptions {
|
|
@@ -17,8 +20,12 @@ interface RemarkAutoTypeTableOptions {
|
|
|
17
20
|
* @defaultValue 'TypeTable'
|
|
18
21
|
*/
|
|
19
22
|
outputName?: string;
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* config for Shiki when using default `renderMarkdown` & `renderType`.
|
|
25
|
+
*/
|
|
26
|
+
shiki?: ResolvedShikiConfig;
|
|
27
|
+
renderMarkdown?: MarkdownRenderer['renderMarkdownToHast'];
|
|
28
|
+
renderType?: MarkdownRenderer['renderTypeToHast'];
|
|
22
29
|
/**
|
|
23
30
|
* Customise type table generation
|
|
24
31
|
*/
|
|
@@ -42,5 +49,4 @@ declare function remarkAutoTypeTable(config?: RemarkAutoTypeTableOptions): Trans
|
|
|
42
49
|
//#region src/cache/fs-cache.d.ts
|
|
43
50
|
declare function createFileSystemGeneratorCache(dir: string): Cache;
|
|
44
51
|
//#endregion
|
|
45
|
-
export { Cache, DocEntry, GenerateOptions, GeneratedDoc, Generator, GeneratorOptions, RawTag, RemarkAutoTypeTableOptions, TypeTableProps, createFileSystemGeneratorCache, createGenerator, createProject, remarkAutoTypeTable
|
|
46
|
-
//# sourceMappingURL=index.d.ts.map
|
|
52
|
+
export { Cache, DocEntry, GenerateOptions, GeneratedDoc, Generator, GeneratorOptions, type MarkdownRenderer, RawTag, RemarkAutoTypeTableOptions, TypeTableProps, createFileSystemGeneratorCache, createGenerator, createProject, remarkAutoTypeTable };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as markdownRenderer, t as parseTags } from "./parse-tags-B09hzgIX.js";
|
|
2
2
|
import * as ts$1 from "ts-morph";
|
|
3
3
|
import { Project, ts } from "ts-morph";
|
|
4
4
|
import * as fs$1 from "node:fs/promises";
|
|
@@ -11,40 +11,30 @@ import { createHash } from "node:crypto";
|
|
|
11
11
|
|
|
12
12
|
//#region src/create-project.ts
|
|
13
13
|
function createProject(options = {}) {
|
|
14
|
-
var _options$tsconfigPath;
|
|
15
14
|
return new Project({
|
|
16
|
-
tsConfigFilePath:
|
|
15
|
+
tsConfigFilePath: options.tsconfigPath ?? "./tsconfig.json",
|
|
17
16
|
skipAddingFilesFromTsConfig: true
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/lib/type-table.ts
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
const output = yield gen.generateDocumentation({
|
|
41
|
-
path: file !== null && file !== void 0 ? file : "temp.ts",
|
|
42
|
-
content
|
|
43
|
-
}, typeName, options);
|
|
44
|
-
if (name && output.length === 0) throw new Error(`${name} in ${file !== null && file !== void 0 ? file : "empty file"} doesn't exist`);
|
|
45
|
-
return output;
|
|
46
|
-
});
|
|
47
|
-
return _getTypeTableOutput.apply(this, arguments);
|
|
22
|
+
async function getTypeTableOutput(gen, { name, type, ...props }, options) {
|
|
23
|
+
const file = props.path && options?.basePath ? join(options.basePath, props.path) : props.path;
|
|
24
|
+
let typeName = name;
|
|
25
|
+
let content = "";
|
|
26
|
+
if (file) content = (await fs$1.readFile(file)).toString();
|
|
27
|
+
if (type && type.split("\n").length > 1) content += `\n${type}`;
|
|
28
|
+
else if (type) {
|
|
29
|
+
typeName ??= "$Fumadocs";
|
|
30
|
+
content += `\nexport type ${typeName} = ${type}`;
|
|
31
|
+
}
|
|
32
|
+
const output = await gen.generateDocumentation({
|
|
33
|
+
path: file ?? "temp.ts",
|
|
34
|
+
content
|
|
35
|
+
}, typeName, options);
|
|
36
|
+
if (name && output.length === 0) throw new Error(`${name} in ${file ?? "empty file"} doesn't exist`);
|
|
37
|
+
return output;
|
|
48
38
|
}
|
|
49
39
|
|
|
50
40
|
//#endregion
|
|
@@ -93,33 +83,29 @@ function dedupe(arr) {
|
|
|
93
83
|
//#region src/lib/base.ts
|
|
94
84
|
function createGenerator(config) {
|
|
95
85
|
const options = config instanceof Project ? { project: config } : config;
|
|
96
|
-
const cache =
|
|
86
|
+
const cache = options?.cache ? options.cache : null;
|
|
97
87
|
let instance;
|
|
98
88
|
function getProject() {
|
|
99
|
-
|
|
100
|
-
(_instance = instance) !== null && _instance !== void 0 || (instance = (_options$project = options === null || options === void 0 ? void 0 : options.project) !== null && _options$project !== void 0 ? _options$project : createProject(options));
|
|
89
|
+
instance ??= options?.project ?? createProject(options);
|
|
101
90
|
return instance;
|
|
102
91
|
}
|
|
103
92
|
return {
|
|
104
|
-
generateDocumentation(file, name, options$1) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
cache === null || cache === void 0 || cache.write(cacheKey, out);
|
|
121
|
-
return out;
|
|
122
|
-
})();
|
|
93
|
+
async generateDocumentation(file, name, options$1) {
|
|
94
|
+
const content = file.content ?? (await fs.readFile(path.resolve(file.path))).toString();
|
|
95
|
+
const cacheKey = `${file.path}:${name}:${content}`;
|
|
96
|
+
if (cache) {
|
|
97
|
+
const cached = await cache.read(cacheKey);
|
|
98
|
+
if (cached) return cached;
|
|
99
|
+
}
|
|
100
|
+
const sourceFile = getProject().createSourceFile(file.path, content, { overwrite: true });
|
|
101
|
+
const out = [];
|
|
102
|
+
for (const [k, d] of sourceFile.getExportedDeclarations()) {
|
|
103
|
+
if (name && name !== k) continue;
|
|
104
|
+
if (d.length > 1) console.warn(`export ${k} should not have more than one type declaration.`);
|
|
105
|
+
out.push(generate(getProject(), k, d[0], options$1));
|
|
106
|
+
}
|
|
107
|
+
cache?.write(cacheKey, out);
|
|
108
|
+
return out;
|
|
123
109
|
},
|
|
124
110
|
generateTypeTable(props, options$1) {
|
|
125
111
|
return getTypeTableOutput(this, props, options$1);
|
|
@@ -127,14 +113,13 @@ function createGenerator(config) {
|
|
|
127
113
|
};
|
|
128
114
|
}
|
|
129
115
|
function generate(program, name, declaration, { allowInternal = false, transform } = {}) {
|
|
130
|
-
var _declaration$getSymbo;
|
|
131
116
|
const entryContext = {
|
|
132
117
|
transform,
|
|
133
118
|
program,
|
|
134
119
|
type: declaration.getType(),
|
|
135
120
|
declaration
|
|
136
121
|
};
|
|
137
|
-
const comment =
|
|
122
|
+
const comment = declaration.getSymbol()?.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject);
|
|
138
123
|
return {
|
|
139
124
|
name,
|
|
140
125
|
description: comment ? ts.displayPartsToString(comment) : "",
|
|
@@ -154,14 +139,12 @@ function getDocEntry(prop, context) {
|
|
|
154
139
|
let simplifiedType = getSimpleForm(subType, program.getTypeChecker(), isOptional, context.declaration);
|
|
155
140
|
for (const tag of tags) {
|
|
156
141
|
if (tag.name === "fumadocsType") {
|
|
157
|
-
|
|
158
|
-
const match = (_exec = new RegExp("`(?<name>.+)`$", "").exec(tag.text)) === null || _exec === void 0 ? void 0 : _exec[1];
|
|
142
|
+
const match = /`(?<name>.+)`$/.exec(tag.text)?.[1];
|
|
159
143
|
if (match) type = match;
|
|
160
144
|
continue;
|
|
161
145
|
}
|
|
162
146
|
if (tag.name === "remarks") {
|
|
163
|
-
|
|
164
|
-
const match = (_exec2 = new RegExp("^`(?<name>.+)`", "").exec(tag.text)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
|
|
147
|
+
const match = /^`(?<name>.+)`/.exec(tag.text)?.[1];
|
|
165
148
|
if (match) simplifiedType = match;
|
|
166
149
|
}
|
|
167
150
|
}
|
|
@@ -174,7 +157,7 @@ function getDocEntry(prop, context) {
|
|
|
174
157
|
required: !isOptional,
|
|
175
158
|
deprecated: tags.some((tag) => tag.name === "deprecated")
|
|
176
159
|
};
|
|
177
|
-
transform
|
|
160
|
+
transform?.call(context, entry, subType, prop);
|
|
178
161
|
return entry;
|
|
179
162
|
}
|
|
180
163
|
|
|
@@ -209,60 +192,35 @@ function objectBuilder() {
|
|
|
209
192
|
}
|
|
210
193
|
};
|
|
211
194
|
}
|
|
212
|
-
function buildTypeProp(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
function _onParam() {
|
|
242
|
-
_onParam = _asyncToGenerator(function* (param) {
|
|
243
|
-
const node = objectBuilder();
|
|
244
|
-
node.addExpressionNode("name", valueToEstree(param.name));
|
|
245
|
-
if (param.description) node.addJsxProperty("description", yield renderMarkdown(param.description));
|
|
246
|
-
return node.build();
|
|
247
|
-
});
|
|
248
|
-
return _onParam.apply(this, arguments);
|
|
249
|
-
}
|
|
250
|
-
const prop = objectBuilder();
|
|
251
|
-
const output = yield Promise.all(entries.map(function() {
|
|
252
|
-
var _ref = _asyncToGenerator(function* (entry) {
|
|
253
|
-
return {
|
|
254
|
-
name: entry.name,
|
|
255
|
-
node: yield onItem(entry)
|
|
256
|
-
};
|
|
257
|
-
});
|
|
258
|
-
return function(_x3) {
|
|
259
|
-
return _ref.apply(this, arguments);
|
|
260
|
-
};
|
|
261
|
-
}()));
|
|
262
|
-
for (const node of output) prop.addExpressionNode(node.name, node.node);
|
|
263
|
-
return prop.build();
|
|
264
|
-
});
|
|
265
|
-
return _buildTypeProp.apply(this, arguments);
|
|
195
|
+
async function buildTypeProp(entries, renderer) {
|
|
196
|
+
async function onItem(entry) {
|
|
197
|
+
const node = objectBuilder();
|
|
198
|
+
const tags = parseTags(entry.tags);
|
|
199
|
+
node.addJsxProperty("type", await renderer.renderTypeToHast(entry.simplifiedType));
|
|
200
|
+
node.addJsxProperty("typeDescription", await renderer.renderTypeToHast(entry.type));
|
|
201
|
+
node.addExpressionNode("required", valueToEstree(entry.required));
|
|
202
|
+
if (tags.default) node.addJsxProperty("default", await renderer.renderTypeToHast(tags.default));
|
|
203
|
+
if (tags.returns) node.addJsxProperty("returns", await renderer.renderMarkdownToHast(tags.returns));
|
|
204
|
+
if (tags.params) node.addExpressionNode("parameters", {
|
|
205
|
+
type: "ArrayExpression",
|
|
206
|
+
elements: await Promise.all(tags.params.map(onParam))
|
|
207
|
+
});
|
|
208
|
+
if (entry.description) node.addJsxProperty("description", await renderer.renderMarkdownToHast(entry.description));
|
|
209
|
+
return node.build();
|
|
210
|
+
}
|
|
211
|
+
async function onParam(param) {
|
|
212
|
+
const node = objectBuilder();
|
|
213
|
+
node.addExpressionNode("name", valueToEstree(param.name));
|
|
214
|
+
if (param.description) node.addJsxProperty("description", await renderer.renderMarkdownToHast(param.description));
|
|
215
|
+
return node.build();
|
|
216
|
+
}
|
|
217
|
+
const prop = objectBuilder();
|
|
218
|
+
const output = await Promise.all(entries.map(async (entry) => ({
|
|
219
|
+
name: entry.name,
|
|
220
|
+
node: await onItem(entry)
|
|
221
|
+
})));
|
|
222
|
+
for (const node of output) prop.addExpressionNode(node.name, node.node);
|
|
223
|
+
return prop.build();
|
|
266
224
|
}
|
|
267
225
|
/**
|
|
268
226
|
* Compile `auto-type-table` into Fumadocs UI compatible TypeTable
|
|
@@ -270,78 +228,72 @@ function _buildTypeProp() {
|
|
|
270
228
|
* MDX is required to use this plugin.
|
|
271
229
|
*/
|
|
272
230
|
function remarkAutoTypeTable(config = {}) {
|
|
273
|
-
const { name = "auto-type-table", outputName = "TypeTable", options: generateOptions = {}, remarkStringify = true, generator = createGenerator() } = config;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
};
|
|
314
|
-
}());
|
|
315
|
-
Object.assign(node, {
|
|
316
|
-
type: "root",
|
|
317
|
-
attributes: [],
|
|
318
|
-
children: yield Promise.all(rendered)
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
return _run.apply(this, arguments);
|
|
322
|
-
}
|
|
323
|
-
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
324
|
-
if (node.name !== name) return;
|
|
325
|
-
const props = {};
|
|
326
|
-
const onError = (message, cause) => {
|
|
327
|
-
const location = node.position ? `${file.path}:${node.position.start.line}:${node.position.start.column}` : file.path;
|
|
328
|
-
throw new Error(`${location} from <auto-type-table>: ${message}`, { cause });
|
|
231
|
+
const { name = "auto-type-table", outputName = "TypeTable", options: generateOptions = {}, remarkStringify = true, generator = createGenerator(), renderMarkdown, renderType, shiki } = config;
|
|
232
|
+
let renderer;
|
|
233
|
+
if (renderMarkdown && renderType) renderer = {
|
|
234
|
+
renderMarkdownToHast: renderMarkdown,
|
|
235
|
+
renderTypeToHast: renderType
|
|
236
|
+
};
|
|
237
|
+
else {
|
|
238
|
+
renderer = markdownRenderer(shiki);
|
|
239
|
+
if (renderMarkdown) renderer.renderMarkdownToHast = renderMarkdown;
|
|
240
|
+
if (renderType) renderer.renderTypeToHast = renderType;
|
|
241
|
+
}
|
|
242
|
+
return async (tree, file) => {
|
|
243
|
+
const queue = [];
|
|
244
|
+
async function run(node, props) {
|
|
245
|
+
let basePath = props.cwd ? file.cwd : generateOptions.basePath;
|
|
246
|
+
if (file.dirname) basePath ??= file.dirname;
|
|
247
|
+
const rendered = (await generator.generateTypeTable(props, {
|
|
248
|
+
...generateOptions,
|
|
249
|
+
basePath
|
|
250
|
+
})).map(async (doc) => {
|
|
251
|
+
return {
|
|
252
|
+
type: "mdxJsxFlowElement",
|
|
253
|
+
name: outputName,
|
|
254
|
+
attributes: [{
|
|
255
|
+
type: "mdxJsxAttribute",
|
|
256
|
+
name: "type",
|
|
257
|
+
value: {
|
|
258
|
+
type: "mdxJsxAttributeValueExpression",
|
|
259
|
+
value: remarkStringify ? JSON.stringify(doc, null, 2) : "",
|
|
260
|
+
data: { estree: {
|
|
261
|
+
type: "Program",
|
|
262
|
+
sourceType: "module",
|
|
263
|
+
body: [{
|
|
264
|
+
type: "ExpressionStatement",
|
|
265
|
+
expression: await buildTypeProp(doc.entries, renderer)
|
|
266
|
+
}]
|
|
267
|
+
} }
|
|
268
|
+
}
|
|
269
|
+
}],
|
|
270
|
+
children: []
|
|
329
271
|
};
|
|
330
|
-
for (const attr of node.attributes) if (attr.type !== "mdxJsxAttribute") onError("only named attributes are allowed.");
|
|
331
|
-
else if (typeof attr.value === "string") props[attr.name] = attr.value;
|
|
332
|
-
else if (attr.value === null) props[attr.name] = true;
|
|
333
|
-
else onError("only string & boolean attributes are allowed.");
|
|
334
|
-
queue.push(run(node, props).catch((err) => {
|
|
335
|
-
onError("failed to generate type table", err);
|
|
336
|
-
}));
|
|
337
|
-
return "skip";
|
|
338
272
|
});
|
|
339
|
-
|
|
273
|
+
Object.assign(node, {
|
|
274
|
+
type: "root",
|
|
275
|
+
attributes: [],
|
|
276
|
+
children: await Promise.all(rendered)
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
280
|
+
if (node.name !== name) return;
|
|
281
|
+
const props = {};
|
|
282
|
+
const onError = (message, cause) => {
|
|
283
|
+
const location = node.position ? `${file.path}:${node.position.start.line}:${node.position.start.column}` : file.path;
|
|
284
|
+
throw new Error(`${location} from <auto-type-table>: ${message}`, { cause });
|
|
285
|
+
};
|
|
286
|
+
for (const attr of node.attributes) if (attr.type !== "mdxJsxAttribute") onError("only named attributes are allowed.");
|
|
287
|
+
else if (typeof attr.value === "string") props[attr.name] = attr.value;
|
|
288
|
+
else if (attr.value === null) props[attr.name] = true;
|
|
289
|
+
else onError("only string & boolean attributes are allowed.");
|
|
290
|
+
queue.push(run(node, props).catch((err) => {
|
|
291
|
+
onError("failed to generate type table", err);
|
|
292
|
+
}));
|
|
293
|
+
return "skip";
|
|
340
294
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
};
|
|
344
|
-
}();
|
|
295
|
+
await Promise.all(queue);
|
|
296
|
+
};
|
|
345
297
|
}
|
|
346
298
|
|
|
347
299
|
//#endregion
|
|
@@ -350,26 +302,21 @@ function createFileSystemGeneratorCache(dir) {
|
|
|
350
302
|
dir = path.resolve(dir);
|
|
351
303
|
const initDirPromise = fs.mkdir(dir, { recursive: true }).catch(() => {});
|
|
352
304
|
return {
|
|
353
|
-
write(input, data) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
yield fs.writeFile(path.join(dir, `${hash}.json`), JSON.stringify(data));
|
|
358
|
-
})();
|
|
305
|
+
async write(input, data) {
|
|
306
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
307
|
+
await initDirPromise;
|
|
308
|
+
await fs.writeFile(path.join(dir, `${hash}.json`), JSON.stringify(data));
|
|
359
309
|
},
|
|
360
|
-
read(input) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
})();
|
|
310
|
+
async read(input) {
|
|
311
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
312
|
+
try {
|
|
313
|
+
return JSON.parse((await fs.readFile(path.join(dir, `${hash}.json`))).toString());
|
|
314
|
+
} catch {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
369
317
|
}
|
|
370
318
|
};
|
|
371
319
|
}
|
|
372
320
|
|
|
373
321
|
//#endregion
|
|
374
|
-
export { createFileSystemGeneratorCache, createGenerator, createProject, remarkAutoTypeTable
|
|
375
|
-
//# sourceMappingURL=index.js.map
|
|
322
|
+
export { createFileSystemGeneratorCache, createGenerator, createProject, remarkAutoTypeTable };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { remark } from "remark";
|
|
2
|
+
import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
|
|
3
|
+
import { createRehypeCode } from "fumadocs-core/mdx-plugins/rehype-code.core";
|
|
4
|
+
import remarkRehype from "remark-rehype";
|
|
5
|
+
import { highlightHast } from "fumadocs-core/highlight/core";
|
|
6
|
+
import { configDefault } from "fumadocs-core/highlight";
|
|
7
|
+
|
|
8
|
+
//#region src/markdown.ts
|
|
9
|
+
function markdownRenderer(shiki = configDefault) {
|
|
10
|
+
const processor = remark().use(remarkGfm).use(remarkRehype).use(createRehypeCode(shiki), {
|
|
11
|
+
lazy: true,
|
|
12
|
+
langs: ["ts", "tsx"],
|
|
13
|
+
transformers: [],
|
|
14
|
+
parseMetaString: void 0
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
async renderTypeToHast(type) {
|
|
18
|
+
return {
|
|
19
|
+
type: "element",
|
|
20
|
+
tagName: "span",
|
|
21
|
+
properties: { class: "shiki" },
|
|
22
|
+
children: [{
|
|
23
|
+
type: "element",
|
|
24
|
+
tagName: "code",
|
|
25
|
+
properties: {},
|
|
26
|
+
children: (await highlightHast(type, {
|
|
27
|
+
config: shiki,
|
|
28
|
+
lang: "ts",
|
|
29
|
+
structure: "inline"
|
|
30
|
+
})).children
|
|
31
|
+
}]
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
renderMarkdownToHast(md) {
|
|
35
|
+
md = md.replace(/{@link (?<link>[^}]*)}/g, "$1");
|
|
36
|
+
return processor.run(processor.parse(md));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/lib/parse-tags.ts
|
|
43
|
+
/**
|
|
44
|
+
* Parse tags, only returns recognized fields.
|
|
45
|
+
*/
|
|
46
|
+
function parseTags(tags) {
|
|
47
|
+
const typed = {};
|
|
48
|
+
for (const { name: key, text } of tags) {
|
|
49
|
+
if (key === "default" || key === "defaultValue") {
|
|
50
|
+
typed.default = text;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (key === "param") {
|
|
54
|
+
const [param, description] = text.split("-", 2);
|
|
55
|
+
typed.params ??= [];
|
|
56
|
+
typed.params.push({
|
|
57
|
+
name: param.trim(),
|
|
58
|
+
description: description.trim()
|
|
59
|
+
});
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (key === "returns") typed.returns = text;
|
|
63
|
+
}
|
|
64
|
+
return typed;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { markdownRenderer as n, parseTags as t };
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { i as Generator, l as BaseTypeTableProps, u as GenerateTypeTableOptions } from "../base-Dvhn4vZx.js";
|
|
2
2
|
import * as runtime from "react/jsx-runtime";
|
|
3
3
|
import "server-only";
|
|
4
|
+
import { ResolvedShikiConfig } from "fumadocs-core/highlight/config";
|
|
4
5
|
import { ReactNode } from "react";
|
|
5
6
|
|
|
6
7
|
//#region src/ui/auto-type-table.d.ts
|
|
7
|
-
|
|
8
|
+
interface JSXMarkdownRenderer {
|
|
9
|
+
renderMarkdown: (md: string) => Promise<ReactNode>;
|
|
10
|
+
renderType: (type: string) => Promise<ReactNode>;
|
|
11
|
+
}
|
|
12
|
+
interface AutoTypeTableProps extends BaseTypeTableProps, Partial<JSXMarkdownRenderer> {
|
|
13
|
+
generator: Generator;
|
|
14
|
+
/** Shiki configuration when using default `renderMarkdown` & `renderType` */
|
|
15
|
+
shiki?: ResolvedShikiConfig;
|
|
16
|
+
options?: GenerateTypeTableOptions;
|
|
17
|
+
}
|
|
8
18
|
declare function AutoTypeTable({
|
|
9
19
|
generator,
|
|
10
20
|
options,
|
|
11
21
|
renderType,
|
|
12
22
|
renderMarkdown,
|
|
23
|
+
shiki,
|
|
13
24
|
...props
|
|
14
|
-
}: AutoTypeTableProps
|
|
15
|
-
generator: Generator;
|
|
16
|
-
renderMarkdown?: typeof renderMarkdownDefault;
|
|
17
|
-
renderType?: typeof renderTypeDefault;
|
|
18
|
-
options?: GenerateTypeTableOptions;
|
|
19
|
-
}): Promise<Promise<runtime.JSX.Element>[]>;
|
|
20
|
-
declare function renderTypeDefault(type: string): Promise<ReactNode>;
|
|
21
|
-
declare function renderMarkdownDefault(md: string): Promise<ReactNode>;
|
|
25
|
+
}: AutoTypeTableProps): Promise<Promise<runtime.JSX.Element>[]>;
|
|
22
26
|
//#endregion
|
|
23
|
-
export { AutoTypeTable, AutoTypeTableProps };
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
|
27
|
+
export { AutoTypeTable, AutoTypeTableProps };
|
package/dist/ui/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as markdownRenderer, t as parseTags } from "../parse-tags-B09hzgIX.js";
|
|
2
2
|
import { TypeTable } from "fumadocs-ui/components/type-table";
|
|
3
3
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
4
4
|
import * as runtime from "react/jsx-runtime";
|
|
@@ -7,80 +7,45 @@ import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
|
7
7
|
import "server-only";
|
|
8
8
|
|
|
9
9
|
//#region src/ui/auto-type-table.tsx
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var _ref3 = _asyncToGenerator(function* (item) {
|
|
24
|
-
const entries = item.entries.map(function() {
|
|
25
|
-
var _ref2 = _asyncToGenerator(function* (entry) {
|
|
26
|
-
var _tags$params;
|
|
27
|
-
const tags = parseTags(entry.tags);
|
|
28
|
-
const paramNodes = [];
|
|
29
|
-
for (const param of (_tags$params = tags.params) !== null && _tags$params !== void 0 ? _tags$params : []) paramNodes.push({
|
|
30
|
-
name: param.name,
|
|
31
|
-
description: param.description ? yield renderMarkdown(param.description) : void 0
|
|
32
|
-
});
|
|
33
|
-
return [entry.name, {
|
|
34
|
-
type: yield renderType(entry.simplifiedType),
|
|
35
|
-
typeDescription: yield renderType(entry.type),
|
|
36
|
-
description: yield renderMarkdown(entry.description),
|
|
37
|
-
default: tags.default ? yield renderType(tags.default) : void 0,
|
|
38
|
-
parameters: paramNodes,
|
|
39
|
-
required: entry.required,
|
|
40
|
-
deprecated: entry.deprecated,
|
|
41
|
-
returns: tags.returns ? yield renderMarkdown(tags.returns) : void 0
|
|
42
|
-
}];
|
|
43
|
-
});
|
|
44
|
-
return function(_x) {
|
|
45
|
-
return _ref2.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
}());
|
|
48
|
-
return /* @__PURE__ */ jsx(TypeTable, { type: Object.fromEntries(yield Promise.all(entries)) }, item.name);
|
|
10
|
+
async function AutoTypeTable({ generator, options = {}, renderType, renderMarkdown, shiki, ...props }) {
|
|
11
|
+
if (!renderType || !renderMarkdown) {
|
|
12
|
+
const renderer = markdownRenderer(shiki);
|
|
13
|
+
renderType ??= async (v) => toJsx(await renderer.renderTypeToHast(v));
|
|
14
|
+
renderMarkdown ??= async (v) => toJsx(await renderer.renderMarkdownToHast(v));
|
|
15
|
+
}
|
|
16
|
+
return (await generator.generateTypeTable(props, options)).map(async (item) => {
|
|
17
|
+
const entries = item.entries.map(async (entry) => {
|
|
18
|
+
const tags = parseTags(entry.tags);
|
|
19
|
+
const paramNodes = [];
|
|
20
|
+
for (const param of tags.params ?? []) paramNodes.push({
|
|
21
|
+
name: param.name,
|
|
22
|
+
description: param.description ? await renderMarkdown(param.description) : void 0
|
|
49
23
|
});
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
return [entry.name, {
|
|
25
|
+
type: await renderType(entry.simplifiedType),
|
|
26
|
+
typeDescription: await renderType(entry.type),
|
|
27
|
+
description: await renderMarkdown(entry.description),
|
|
28
|
+
default: tags.default ? await renderType(tags.default) : void 0,
|
|
29
|
+
parameters: paramNodes,
|
|
30
|
+
required: entry.required,
|
|
31
|
+
deprecated: entry.deprecated,
|
|
32
|
+
returns: tags.returns ? await renderMarkdown(tags.returns) : void 0
|
|
33
|
+
}];
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ jsx(TypeTable, { type: Object.fromEntries(await Promise.all(entries)) }, item.name);
|
|
54
36
|
});
|
|
55
|
-
return _AutoTypeTable.apply(this, arguments);
|
|
56
37
|
}
|
|
57
38
|
function toJsx(hast) {
|
|
58
39
|
return toJsxRuntime(hast, {
|
|
59
40
|
Fragment: runtime.Fragment,
|
|
60
41
|
jsx: runtime.jsx,
|
|
61
42
|
jsxs: runtime.jsxs,
|
|
62
|
-
components:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return _renderTypeDefault.apply(this, arguments);
|
|
67
|
-
}
|
|
68
|
-
function _renderTypeDefault() {
|
|
69
|
-
_renderTypeDefault = _asyncToGenerator(function* (type) {
|
|
70
|
-
return toJsx(yield renderTypeToHast(type));
|
|
71
|
-
});
|
|
72
|
-
return _renderTypeDefault.apply(this, arguments);
|
|
73
|
-
}
|
|
74
|
-
function renderMarkdownDefault(_x5) {
|
|
75
|
-
return _renderMarkdownDefault.apply(this, arguments);
|
|
76
|
-
}
|
|
77
|
-
function _renderMarkdownDefault() {
|
|
78
|
-
_renderMarkdownDefault = _asyncToGenerator(function* (md) {
|
|
79
|
-
return toJsx(yield renderMarkdownToHast(md));
|
|
43
|
+
components: {
|
|
44
|
+
...defaultMdxComponents,
|
|
45
|
+
img: void 0
|
|
46
|
+
}
|
|
80
47
|
});
|
|
81
|
-
return _renderMarkdownDefault.apply(this, arguments);
|
|
82
48
|
}
|
|
83
49
|
|
|
84
50
|
//#endregion
|
|
85
|
-
export { AutoTypeTable };
|
|
86
|
-
//# sourceMappingURL=index.js.map
|
|
51
|
+
export { AutoTypeTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -38,28 +38,28 @@
|
|
|
38
38
|
"remark-rehype": "^11.1.2",
|
|
39
39
|
"tinyglobby": "^0.2.15",
|
|
40
40
|
"ts-morph": "^27.0.2",
|
|
41
|
-
"
|
|
41
|
+
"unified": "^11.0.5",
|
|
42
|
+
"unist-util-visit": "^5.1.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@mdx-js/mdx": "^3.1.1",
|
|
45
46
|
"@types/estree": "^1.0.8",
|
|
46
47
|
"@types/hast": "^3.0.4",
|
|
47
48
|
"@types/mdast": "^4.0.4",
|
|
48
|
-
"@types/node": "
|
|
49
|
-
"@types/react": "^19.2.
|
|
49
|
+
"@types/node": "25.1.0",
|
|
50
|
+
"@types/react": "^19.2.10",
|
|
50
51
|
"@types/react-dom": "^19.2.3",
|
|
51
|
-
"tsdown": "^0.
|
|
52
|
+
"tsdown": "^0.19.0",
|
|
52
53
|
"typescript": "^5.9.3",
|
|
53
|
-
"unified": "^11.0.5",
|
|
54
54
|
"eslint-config-custom": "0.0.0",
|
|
55
|
-
"fumadocs-core": "16.
|
|
56
|
-
"fumadocs-ui": "16.
|
|
55
|
+
"fumadocs-core": "16.5.0",
|
|
56
|
+
"fumadocs-ui": "16.5.0",
|
|
57
57
|
"tsconfig": "0.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@types/react": "*",
|
|
61
|
-
"fumadocs-core": "^
|
|
62
|
-
"fumadocs-ui": "^
|
|
61
|
+
"fumadocs-core": "^16.5.0",
|
|
62
|
+
"fumadocs-ui": "^16.5.0",
|
|
63
63
|
"react": "*",
|
|
64
64
|
"typescript": "*"
|
|
65
65
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-Dvhn4vZx.d.ts","names":[],"sources":["../src/create-project.ts","../src/lib/type-table.ts","../src/cache/index.ts","../src/lib/base.ts"],"sourcesContent":[],"mappings":";;;UAEiB,gBAAA;;EAAA,YAAA,CAAA,EAAA,MAAgB;EAOjB;;;iBAAA,aAAA,WAAuB,mBAAwB;;;UCL9C,kBAAA;;ADFjB;AAOA;;;;ACLA;EAmCiB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fs-cache.ts"],"sourcesContent":[],"mappings":";;;;;;iBAuBsB,gBAAA,gBAAgC,QAAQ;iBA8BxC,oBAAA,cAAkC,QAAQ;;;UCiD/C,0BAAA;ED/EK;AA8BtB;;;;ACiDA;;EAYsB,UAAA,CAAA,EAAA,MAAA;EAKV,cAAA,CAAA,EAAA,OANc,oBAMd;EAOE,UAAA,CAAA,EAAA,OAZQ,gBAYR;EAAS;AAGvB;AASA;EACU,OAAA,CAAA,EApBE,wBAoBF;EACK;;;EAAD,eAAA,CAAA,EAAA,OAAA;cAdA;;UAGG,cAAA,SAAuB;EC5HxB,GAAA,CAAA,EAAA,IAAA;;;;;;;iBDqIA,mBAAA,UACN,6BACP,YAAY,MAAM;;;iBCvIL,8BAAA,eAA6C"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs","types: string[]","ts","dedupe","out: T[]","instance: Project | undefined","out: GeneratedDoc[]","options","entryContext: EntryContext","entry: DocEntry","out: ObjectExpression","queue: Promise<void>[]","props: Record<string, string | true>"],"sources":["../src/create-project.ts","../src/lib/type-table.ts","../src/lib/get-simple-form.ts","../src/lib/base.ts","../src/lib/remark-auto-type-table.ts","../src/cache/fs-cache.ts"],"sourcesContent":["import { Project } from 'ts-morph';\n\nexport interface TypescriptConfig {\n files?: string[];\n tsconfigPath?: string;\n /** A root directory to resolve relative path entries in the config file to. e.g. outDir */\n basePath?: string;\n}\n\nexport function createProject(options: TypescriptConfig = {}): Project {\n return new Project({\n tsConfigFilePath: options.tsconfigPath ?? './tsconfig.json',\n skipAddingFilesFromTsConfig: true,\n });\n}\n","import * as fs from 'node:fs/promises';\nimport { type GenerateOptions, type Generator } from '@/lib/base';\nimport { join } from 'node:path';\n\nexport interface BaseTypeTableProps {\n /**\n * The path to source TypeScript file.\n */\n path?: string;\n\n /**\n * Exported type name to generate from.\n */\n name?: string;\n\n /**\n * Set the type to generate from.\n *\n * When used with `name`, it generates the type with `name` as export name.\n *\n * ```ts\n * export const myName = MyType;\n * ```\n *\n * When `type` contains multiple lines, `export const` is not added.\n * You need to export it manually, and specify the type name with `name`.\n *\n * ```tsx\n * <AutoTypeTable\n * path=\"./file.ts\"\n * type={`import { ReactNode } from \"react\"\n * export const MyName = ReactNode`}\n * name=\"MyName\"\n * />\n * ```\n */\n type?: string;\n}\n\nexport interface GenerateTypeTableOptions extends GenerateOptions {\n /**\n * base path to resolve `path` prop\n */\n basePath?: string;\n}\n\nexport async function getTypeTableOutput(\n gen: Generator,\n { name, type, ...props }: BaseTypeTableProps,\n options?: GenerateTypeTableOptions,\n) {\n const file = props.path && options?.basePath ? join(options.basePath, props.path) : props.path;\n let typeName = name;\n let content = '';\n\n if (file) {\n content = (await fs.readFile(file)).toString();\n }\n\n if (type && type.split('\\n').length > 1) {\n content += `\\n${type}`;\n } else if (type) {\n typeName ??= '$Fumadocs';\n content += `\\nexport type ${typeName} = ${type}`;\n }\n\n const output = await gen.generateDocumentation(\n { path: file ?? 'temp.ts', content },\n typeName,\n options,\n );\n\n if (name && output.length === 0)\n throw new Error(`${name} in ${file ?? 'empty file'} doesn't exist`);\n\n return output;\n}\n","import * as ts from 'ts-morph';\n\nexport function getSimpleForm(\n type: ts.Type,\n checker: ts.TypeChecker,\n noUndefined = false,\n location?: ts.Node,\n): string {\n if (type.isUndefined() && noUndefined) return '';\n\n const alias = type.getAliasSymbol();\n if (alias) {\n const args = type.getAliasTypeArguments();\n if (args.length === 0) return alias.getName();\n\n return `${alias.getName()}<${args.map((arg) => getSimpleForm(arg, checker)).join(', ')}>`;\n }\n\n if (type.isUnion()) {\n const types: string[] = [];\n for (const t of type.getUnionTypes()) {\n const str = getSimpleForm(t, checker, noUndefined);\n if (str.length > 0 && str !== 'never') types.unshift(str);\n }\n\n return types.length > 0\n ? // boolean | null will become true | false | null, need to ensure it's still returned as boolean\n dedupe(types).join(' | ').replace('true | false', 'boolean')\n : 'never';\n }\n\n if (type.isIntersection()) {\n const types: string[] = [];\n for (const t of type.getIntersectionTypes()) {\n const str = getSimpleForm(t, checker, noUndefined);\n if (str.length > 0 && str !== 'never') types.unshift(str);\n }\n\n return dedupe(types).join(' & ');\n }\n\n if (type.isTuple()) {\n const elements = type\n .getTupleElements()\n .map((t) => getSimpleForm(t, checker))\n .join(', ');\n\n return `[${elements}]`;\n }\n\n if (type.isArray() || type.isReadonlyArray()) {\n return 'array';\n }\n\n if (type.getCallSignatures().length > 0) {\n return 'function';\n }\n\n if (type.isClassOrInterface() || type.isObject()) {\n return 'object';\n }\n\n return type.getText(location, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);\n}\n\nfunction dedupe<T>(arr: T[]): T[] {\n const dedupe = new Set<T>();\n const out: T[] = [];\n\n for (const item of arr) {\n if (!dedupe.has(item)) {\n out.push(item);\n dedupe.add(item);\n }\n }\n\n return out;\n}\n","import {\n type ExportedDeclarations,\n Project,\n type Symbol as TsSymbol,\n ts,\n type Type,\n} from 'ts-morph';\nimport { createProject, type TypescriptConfig } from '@/create-project';\nimport fs from 'node:fs/promises';\nimport {\n type BaseTypeTableProps,\n type GenerateTypeTableOptions,\n getTypeTableOutput,\n} from '@/lib/type-table';\nimport path from 'node:path';\nimport { getSimpleForm } from '@/lib/get-simple-form';\nimport type { Cache } from '@/cache';\n\nexport interface GeneratedDoc {\n name: string;\n description: string;\n entries: DocEntry[];\n}\n\nexport interface DocEntry {\n name: string;\n description: string;\n type: string;\n simplifiedType: string;\n\n tags: RawTag[];\n required: boolean;\n deprecated: boolean;\n}\n\nexport interface RawTag {\n name: string;\n text: string;\n}\n\ninterface EntryContext {\n program: Project;\n transform?: Transformer;\n type: Type;\n declaration: ExportedDeclarations;\n}\n\ntype Transformer = (\n this: EntryContext,\n entry: DocEntry,\n propertyType: Type,\n propertySymbol: TsSymbol,\n) => void;\n\nexport interface GenerateOptions {\n /**\n * Allow fields with `@internal` tag\n *\n * @defaultValue false\n */\n allowInternal?: boolean;\n\n /**\n * Modify output property entry\n */\n transform?: Transformer;\n}\n\nexport type Generator = ReturnType<typeof createGenerator>;\n\nexport interface GeneratorOptions extends TypescriptConfig {\n /**\n * cache results, note that some options are not marked as dependency.\n *\n * @defaultValue false\n */\n cache?: Cache | false;\n\n project?: Project;\n}\n\nexport function createGenerator(config?: GeneratorOptions | Project) {\n const options =\n config instanceof Project\n ? {\n project: config,\n }\n : config;\n const cache = options?.cache ? options.cache : null;\n let instance: Project | undefined;\n\n function getProject() {\n instance ??= options?.project ?? createProject(options);\n return instance;\n }\n\n return {\n async generateDocumentation(\n file: {\n path: string;\n content?: string;\n },\n name: string | undefined,\n options?: GenerateOptions,\n ) {\n const content = file.content ?? (await fs.readFile(path.resolve(file.path))).toString();\n const cacheKey = `${file.path}:${name}:${content}`;\n if (cache) {\n const cached = (await cache.read(cacheKey)) as GeneratedDoc[] | undefined;\n if (cached) return cached;\n }\n const sourceFile = getProject().createSourceFile(file.path, content, {\n overwrite: true,\n });\n const out: GeneratedDoc[] = [];\n\n for (const [k, d] of sourceFile.getExportedDeclarations()) {\n if (name && name !== k) continue;\n\n if (d.length > 1)\n console.warn(`export ${k} should not have more than one type declaration.`);\n\n out.push(generate(getProject(), k, d[0], options));\n }\n\n void cache?.write(cacheKey, out);\n return out;\n },\n generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions) {\n return getTypeTableOutput(this, props, options);\n },\n };\n}\n\nfunction generate(\n program: Project,\n name: string,\n declaration: ExportedDeclarations,\n { allowInternal = false, transform }: GenerateOptions = {},\n): GeneratedDoc {\n const entryContext: EntryContext = {\n transform,\n program,\n type: declaration.getType(),\n declaration,\n };\n\n const comment = declaration\n .getSymbol()\n ?.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject);\n\n return {\n name,\n description: comment ? ts.displayPartsToString(comment) : '',\n entries: declaration\n .getType()\n .getProperties()\n .map((prop) => getDocEntry(prop, entryContext))\n .filter((entry) => entry && (allowInternal || !('internal' in entry.tags))) as DocEntry[],\n };\n}\n\nfunction getDocEntry(prop: TsSymbol, context: EntryContext): DocEntry | undefined {\n const { transform, program } = context;\n if (context.type.isClass() && prop.getName().startsWith('#')) {\n return;\n }\n\n const subType = prop.getTypeAtLocation(context.declaration);\n const isOptional = prop.isOptional();\n const tags = prop.getJsDocTags().map(\n (tag) =>\n ({\n name: tag.getName(),\n text: ts.displayPartsToString(tag.getText()),\n }) satisfies RawTag,\n );\n\n let type = subType.getText(\n context.declaration,\n ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation,\n );\n let simplifiedType = getSimpleForm(\n subType,\n program.getTypeChecker(),\n isOptional,\n context.declaration,\n );\n\n for (const tag of tags) {\n // replace full type with @fumadocsType\n if (tag.name === 'fumadocsType') {\n const match = /`(?<name>.+)`$/.exec(tag.text)?.[1];\n if (match) type = match;\n continue;\n }\n\n // replace simplified type with @remarks\n if (tag.name === 'remarks') {\n const match = /^`(?<name>.+)`/.exec(tag.text)?.[1];\n if (match) simplifiedType = match;\n }\n }\n\n const entry: DocEntry = {\n name: prop.getName(),\n description: ts.displayPartsToString(\n prop.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject),\n ),\n tags,\n type,\n simplifiedType,\n required: !isOptional,\n deprecated: tags.some((tag) => tag.name === 'deprecated'),\n };\n\n transform?.call(context, entry, subType, prop);\n\n return entry;\n}\n","import type { Root } from 'mdast';\nimport type { Nodes } from 'hast';\nimport type { Transformer } from 'unified';\nimport type { Expression, ExpressionStatement, ObjectExpression, Program } from 'estree';\nimport { createGenerator, type DocEntry, type Generator } from '@/lib/base';\nimport { renderMarkdownToHast, renderTypeToHast } from '@/markdown';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { visit } from 'unist-util-visit';\nimport { type BaseTypeTableProps, type GenerateTypeTableOptions } from '@/lib/type-table';\nimport { toEstree } from 'hast-util-to-estree';\nimport { type ParameterTag, parseTags } from '@/lib/parse-tags';\n\nfunction objectBuilder() {\n const out: ObjectExpression = {\n type: 'ObjectExpression',\n properties: [],\n };\n\n return {\n addExpressionNode(key: string, expression: Expression) {\n out.properties.push({\n type: 'Property',\n method: false,\n shorthand: false,\n computed: false,\n key: {\n type: 'Identifier',\n name: key,\n },\n kind: 'init',\n value: expression,\n });\n },\n addJsxProperty(key: string, hast: Nodes) {\n const estree = toEstree(hast, {\n elementAttributeNameCase: 'react',\n }).body[0] as ExpressionStatement;\n\n this.addExpressionNode(key, estree.expression);\n },\n build() {\n return out;\n },\n };\n}\n\nasync function buildTypeProp(\n entries: DocEntry[],\n {\n renderMarkdown = renderMarkdownToHast,\n renderType = renderTypeToHast,\n }: RemarkAutoTypeTableOptions,\n): Promise<ObjectExpression> {\n async function onItem(entry: DocEntry) {\n const node = objectBuilder();\n const tags = parseTags(entry.tags);\n node.addJsxProperty('type', await renderType(entry.simplifiedType));\n node.addJsxProperty('typeDescription', await renderType(entry.type));\n node.addExpressionNode('required', valueToEstree(entry.required));\n\n if (tags.default) node.addJsxProperty('default', await renderType(tags.default));\n\n if (tags.returns) node.addJsxProperty('returns', await renderMarkdown(tags.returns));\n\n if (tags.params) {\n node.addExpressionNode('parameters', {\n type: 'ArrayExpression',\n elements: await Promise.all(tags.params.map(onParam)),\n });\n }\n\n if (entry.description) {\n node.addJsxProperty('description', await renderMarkdown(entry.description));\n }\n\n return node.build();\n }\n\n async function onParam(param: ParameterTag) {\n const node = objectBuilder();\n node.addExpressionNode('name', valueToEstree(param.name));\n if (param.description)\n node.addJsxProperty('description', await renderMarkdown(param.description));\n\n return node.build();\n }\n\n const prop = objectBuilder();\n const output = await Promise.all(\n entries.map(async (entry) => ({\n name: entry.name,\n node: await onItem(entry),\n })),\n );\n\n for (const node of output) {\n prop.addExpressionNode(node.name, node.node);\n }\n\n return prop.build();\n}\n\nexport interface RemarkAutoTypeTableOptions {\n /**\n * @defaultValue 'auto-type-table'\n */\n name?: string;\n\n /**\n * @defaultValue 'TypeTable'\n */\n outputName?: string;\n\n renderMarkdown?: typeof renderMarkdownToHast;\n renderType?: typeof renderTypeToHast;\n\n /**\n * Customise type table generation\n */\n options?: GenerateTypeTableOptions;\n\n /**\n * generate required `value` property for `remark-stringify`\n */\n remarkStringify?: boolean;\n\n generator?: Generator;\n}\n\nexport interface TypeTableProps extends BaseTypeTableProps {\n cwd?: true;\n}\n\n/**\n * Compile `auto-type-table` into Fumadocs UI compatible TypeTable\n *\n * MDX is required to use this plugin.\n */\nexport function remarkAutoTypeTable(\n config: RemarkAutoTypeTableOptions = {},\n): Transformer<Root, Root> {\n const {\n name = 'auto-type-table',\n outputName = 'TypeTable',\n options: generateOptions = {},\n remarkStringify = true,\n generator = createGenerator(),\n } = config;\n\n return async (tree, file) => {\n const queue: Promise<void>[] = [];\n async function run(node: object, props: TypeTableProps) {\n let basePath = props.cwd ? file.cwd : generateOptions.basePath;\n if (file.dirname) {\n basePath ??= file.dirname;\n }\n\n const output = await generator.generateTypeTable(props, {\n ...generateOptions,\n basePath,\n });\n\n const rendered = output.map(async (doc) => {\n return {\n type: 'mdxJsxFlowElement',\n name: outputName,\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'type',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: remarkStringify ? JSON.stringify(doc, null, 2) : '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExpressionStatement',\n expression: await buildTypeProp(doc.entries, config),\n },\n ],\n } satisfies Program,\n },\n },\n },\n ],\n children: [],\n };\n });\n\n Object.assign(node, {\n type: 'root',\n attributes: [],\n children: await Promise.all(rendered),\n } as Root);\n }\n\n visit(tree, 'mdxJsxFlowElement', (node) => {\n if (node.name !== name) return;\n const props: Record<string, string | true> = {};\n const onError = (message: string, cause?: Error) => {\n const location = node.position\n ? `${file.path}:${node.position.start.line}:${node.position.start.column}`\n : file.path;\n throw new Error(`${location} from <auto-type-table>: ${message}`, {\n cause,\n });\n };\n\n for (const attr of node.attributes) {\n if (attr.type !== 'mdxJsxAttribute') {\n onError('only named attributes are allowed.');\n } else if (typeof attr.value === 'string') {\n props[attr.name] = attr.value;\n } else if (attr.value === null) {\n props[attr.name] = true;\n } else {\n onError('only string & boolean attributes are allowed.');\n }\n }\n\n queue.push(\n run(node, props).catch((err) => {\n onError('failed to generate type table', err);\n }),\n );\n return 'skip';\n });\n\n await Promise.all(queue);\n };\n}\n","import fs from 'node:fs/promises';\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport type { Cache } from '@/cache/index';\n\nexport function createFileSystemGeneratorCache(dir: string): Cache {\n // call `path.resolve` so Vercel NFT will include the cache directory in production.\n dir = path.resolve(dir);\n const initDirPromise = fs.mkdir(dir, { recursive: true }).catch(() => {\n // it fails on Vercel as of 2025 12 May, we can skip it\n });\n\n return {\n async write(input, data) {\n const hash = createHash('SHA256').update(input).digest('hex').slice(0, 12);\n\n await initDirPromise;\n await fs.writeFile(path.join(dir, `${hash}.json`), JSON.stringify(data));\n },\n async read(input) {\n const hash = createHash('SHA256').update(input).digest('hex').slice(0, 12);\n\n try {\n return JSON.parse((await fs.readFile(path.join(dir, `${hash}.json`))).toString());\n } catch {\n return;\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,UAA4B,EAAE,EAAW;;AACrE,QAAO,IAAI,QAAQ;EACjB,2CAAkB,QAAQ,qFAAgB;EAC1C,6BAA6B;EAC9B,CAAC;;;;;mBCmCA,QAAM;AAFV,SAAsB,mBACpB,IACA,KACA;;;;oDAFA,KACA,MACA,SACA;MAFA,EAAE,MAAM,eAAS;EAGjB,MAAM,OAAO,MAAM,2DAAQ,QAAS,YAAW,KAAK,QAAQ,UAAU,MAAM,KAAK,GAAG,MAAM;EAC1F,IAAI,WAAW;EACf,IAAI,UAAU;AAEd,MAAI,KACF,kBAAiBA,KAAG,SAAS,KAAK,EAAE,UAAU;AAGhD,MAAI,QAAQ,KAAK,MAAM,KAAK,CAAC,SAAS,EACpC,YAAW,KAAK;WACP,MAAM;;AACf,0EAAa;AACb,cAAW,iB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AM,OAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;AAE1E,UAAM;AACN,UAAM,GAAG,UAAU,KAAK,KAAK,KAAK,GAAG,KAAK,OAAO,EAAE,KAAK,UAAU,KAAK,CAAC;;;EAE1E,AAAM,KAAK;yCAAO;IAChB,MAAM,OAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;AAE1E,QAAI;AACF,YAAO,KAAK,aAAa,GAAG,SAAS,KAAK,KAAK,KAAK,GAAG,KAAK,OAAO,CAAC,EAAE,UAAU,CAAC;sBAC3E;AACN;;;;EAGL"}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { remark } from "remark";
|
|
2
|
-
import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
|
|
3
|
-
import { rehypeCode } from "fumadocs-core/mdx-plugins/rehype-code";
|
|
4
|
-
import remarkRehype from "remark-rehype";
|
|
5
|
-
import { getHighlighter } from "fumadocs-core/highlight";
|
|
6
|
-
|
|
7
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutPropertiesLoose.js
|
|
8
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
9
|
-
if (null == r) return {};
|
|
10
|
-
var t = {};
|
|
11
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
12
|
-
if (e.includes(n)) continue;
|
|
13
|
-
t[n] = r[n];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectWithoutProperties.js
|
|
20
|
-
function _objectWithoutProperties(e, t) {
|
|
21
|
-
if (null == e) return {};
|
|
22
|
-
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
23
|
-
if (Object.getOwnPropertySymbols) {
|
|
24
|
-
var s = Object.getOwnPropertySymbols(e);
|
|
25
|
-
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
26
|
-
}
|
|
27
|
-
return i;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/asyncToGenerator.js
|
|
32
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
33
|
-
try {
|
|
34
|
-
var i = n[a](c), u = i.value;
|
|
35
|
-
} catch (n$1) {
|
|
36
|
-
e(n$1);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
40
|
-
}
|
|
41
|
-
function _asyncToGenerator(n) {
|
|
42
|
-
return function() {
|
|
43
|
-
var t = this, e = arguments;
|
|
44
|
-
return new Promise(function(r, o) {
|
|
45
|
-
var a = n.apply(t, e);
|
|
46
|
-
function _next(n$1) {
|
|
47
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
|
|
48
|
-
}
|
|
49
|
-
function _throw(n$1) {
|
|
50
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
|
|
51
|
-
}
|
|
52
|
-
_next(void 0);
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/markdown.ts
|
|
59
|
-
const shikiOptions = {
|
|
60
|
-
lazy: true,
|
|
61
|
-
langs: ["ts", "tsx"],
|
|
62
|
-
transformers: [],
|
|
63
|
-
parseMetaString: void 0,
|
|
64
|
-
themes: {
|
|
65
|
-
light: "github-light",
|
|
66
|
-
dark: "github-dark"
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);
|
|
70
|
-
function renderTypeToHast(_x) {
|
|
71
|
-
return _renderTypeToHast.apply(this, arguments);
|
|
72
|
-
}
|
|
73
|
-
function _renderTypeToHast() {
|
|
74
|
-
_renderTypeToHast = _asyncToGenerator(function* (type) {
|
|
75
|
-
return {
|
|
76
|
-
type: "element",
|
|
77
|
-
tagName: "span",
|
|
78
|
-
properties: { class: "shiki" },
|
|
79
|
-
children: [{
|
|
80
|
-
type: "element",
|
|
81
|
-
tagName: "code",
|
|
82
|
-
properties: {},
|
|
83
|
-
children: (yield getHighlighter("js", {
|
|
84
|
-
langs: ["ts"],
|
|
85
|
-
themes: Object.values(shikiOptions.themes)
|
|
86
|
-
})).codeToHast(type, {
|
|
87
|
-
lang: "ts",
|
|
88
|
-
structure: "inline",
|
|
89
|
-
themes: shikiOptions.themes,
|
|
90
|
-
defaultColor: false
|
|
91
|
-
}).children
|
|
92
|
-
}]
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
return _renderTypeToHast.apply(this, arguments);
|
|
96
|
-
}
|
|
97
|
-
function renderMarkdownToHast(_x2) {
|
|
98
|
-
return _renderMarkdownToHast.apply(this, arguments);
|
|
99
|
-
}
|
|
100
|
-
function _renderMarkdownToHast() {
|
|
101
|
-
_renderMarkdownToHast = _asyncToGenerator(function* (md) {
|
|
102
|
-
md = md.replace(new RegExp("{@link (?<link>[^}]*)}", "g"), "$1");
|
|
103
|
-
return processor.run(processor.parse(md));
|
|
104
|
-
});
|
|
105
|
-
return _renderMarkdownToHast.apply(this, arguments);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/lib/parse-tags.ts
|
|
110
|
-
/**
|
|
111
|
-
* Parse tags, only returns recognized fields.
|
|
112
|
-
*/
|
|
113
|
-
function parseTags(tags) {
|
|
114
|
-
const typed = {};
|
|
115
|
-
for (const { name: key, text } of tags) {
|
|
116
|
-
if (key === "default" || key === "defaultValue") {
|
|
117
|
-
typed.default = text;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (key === "param") {
|
|
121
|
-
var _typed$params;
|
|
122
|
-
const [param, description] = text.split("-", 2);
|
|
123
|
-
(_typed$params = typed.params) !== null && _typed$params !== void 0 || (typed.params = []);
|
|
124
|
-
typed.params.push({
|
|
125
|
-
name: param.trim(),
|
|
126
|
-
description: description.trim()
|
|
127
|
-
});
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (key === "returns") typed.returns = text;
|
|
131
|
-
}
|
|
132
|
-
return typed;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
137
|
-
function _typeof(o) {
|
|
138
|
-
"@babel/helpers - typeof";
|
|
139
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
140
|
-
return typeof o$1;
|
|
141
|
-
} : function(o$1) {
|
|
142
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
143
|
-
}, _typeof(o);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
148
|
-
function toPrimitive(t, r) {
|
|
149
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
150
|
-
var e = t[Symbol.toPrimitive];
|
|
151
|
-
if (void 0 !== e) {
|
|
152
|
-
var i = e.call(t, r || "default");
|
|
153
|
-
if ("object" != _typeof(i)) return i;
|
|
154
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
155
|
-
}
|
|
156
|
-
return ("string" === r ? String : Number)(t);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
161
|
-
function toPropertyKey(t) {
|
|
162
|
-
var i = toPrimitive(t, "string");
|
|
163
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
168
|
-
function _defineProperty(e, r, t) {
|
|
169
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
170
|
-
value: t,
|
|
171
|
-
enumerable: !0,
|
|
172
|
-
configurable: !0,
|
|
173
|
-
writable: !0
|
|
174
|
-
}) : e[r] = t, e;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
179
|
-
function ownKeys(e, r) {
|
|
180
|
-
var t = Object.keys(e);
|
|
181
|
-
if (Object.getOwnPropertySymbols) {
|
|
182
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
183
|
-
r && (o = o.filter(function(r$1) {
|
|
184
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
185
|
-
})), t.push.apply(t, o);
|
|
186
|
-
}
|
|
187
|
-
return t;
|
|
188
|
-
}
|
|
189
|
-
function _objectSpread2(e) {
|
|
190
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
191
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
192
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
193
|
-
_defineProperty(e, r$1, t[r$1]);
|
|
194
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
195
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
return e;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
//#endregion
|
|
202
|
-
export { _asyncToGenerator as a, renderTypeToHast as i, parseTags as n, _objectWithoutProperties as o, renderMarkdownToHast as r, _objectSpread2 as t };
|
|
203
|
-
//# sourceMappingURL=objectSpread2-BbbttTvx.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"objectSpread2-BbbttTvx.js","names":["typed: TypedTags"],"sources":["../src/markdown.ts","../src/lib/parse-tags.ts"],"sourcesContent":["import type { ElementContent, Nodes } from 'hast';\nimport { remark } from 'remark';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport { rehypeCode, type RehypeCodeOptions } from 'fumadocs-core/mdx-plugins/rehype-code';\nimport remarkRehype from 'remark-rehype';\nimport { getHighlighter } from 'fumadocs-core/highlight';\n\nconst shikiOptions = {\n lazy: true,\n langs: ['ts', 'tsx'],\n\n // disable default transformers & meta parser\n transformers: [],\n parseMetaString: undefined,\n\n themes: {\n light: 'github-light',\n dark: 'github-dark',\n },\n} satisfies RehypeCodeOptions;\n\nconst processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);\n\nexport async function renderTypeToHast(type: string): Promise<Nodes> {\n const highlighter = await getHighlighter('js', {\n langs: ['ts'],\n themes: Object.values(shikiOptions.themes),\n });\n\n const nodes = highlighter.codeToHast(type, {\n lang: 'ts',\n structure: 'inline',\n themes: shikiOptions.themes,\n defaultColor: false,\n });\n\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n class: 'shiki',\n },\n children: [\n {\n type: 'element',\n tagName: 'code',\n properties: {},\n children: nodes.children as ElementContent[],\n },\n ],\n };\n}\n\nexport async function renderMarkdownToHast(md: string): Promise<Nodes> {\n md = md.replace(/{@link (?<link>[^}]*)}/g, '$1'); // replace jsdoc links\n\n return processor.run(processor.parse(md));\n}\n","import { RawTag } from '@/lib/base';\n\nexport interface ParameterTag {\n name: string;\n description?: string;\n}\n\nexport interface TypedTags {\n default?: string;\n params?: ParameterTag[];\n returns?: string;\n}\n\n/**\n * Parse tags, only returns recognized fields.\n */\nexport function parseTags(tags: RawTag[]): TypedTags {\n const typed: TypedTags = {};\n\n for (const { name: key, text } of tags) {\n if (key === 'default' || key === 'defaultValue') {\n typed.default = text;\n continue;\n }\n\n if (key === 'param') {\n const [param, description] = text.split('-', 2);\n\n typed.params ??= [];\n typed.params.push({\n name: param.trim(),\n description: description.trim(),\n });\n continue;\n }\n\n if (key === 'returns') {\n typed.returns = text;\n }\n }\n\n return typed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,eAAe;CACnB,MAAM;CACN,OAAO,CAAC,MAAM,MAAM;CAGpB,cAAc,EAAE;CAChB,iBAAiB;CAEjB,QAAQ;EACN,OAAO;EACP,MAAM;EACP;CACF;AAED,MAAM,YAAY,QAAQ,CAAC,IAAI,UAAU,CAAC,IAAI,aAAa,CAAC,IAAI,YAAY,aAAa;AAEzF,SAAsB,iBAAiB;;;;wDAA8B;AAanE,SAAO;GACL,MAAM;GACN,SAAS;GACT,YAAY,EACV,OAAO,SACR;GACD,UAAU,CACR;IACE,MAAM;IACN,SAAS;IACT,YAAY,EAAE;IACd,iBAvBoB,eAAe,MAAM;KAC7C,OAAO,CAAC,KAAK;KACb,QAAQ,OAAO,OAAO,aAAa,OAAO;KAC3C,CAAC,EAEwB,WAAW,MAAM;KACzC,MAAM;KACN,WAAW;KACX,QAAQ,aAAa;KACrB,cAAc;KACf,CAAC,CAaoB;IACjB,CACF;GACF;;;;AAGH,SAAsB,qBAAqB;;;;0DAA4B;AACrE,OAAK,GAAG,QAAQ,yCAAyB,EAAE,KAAK;AAEhD,SAAO,UAAU,IAAI,UAAU,MAAM,GAAG,CAAC;;;;;;;;;;ACxC3C,SAAgB,UAAU,MAA2B;CACnD,MAAMA,QAAmB,EAAE;AAE3B,MAAK,MAAM,EAAE,MAAM,KAAK,UAAU,MAAM;AACtC,MAAI,QAAQ,aAAa,QAAQ,gBAAgB;AAC/C,SAAM,UAAU;AAChB;;AAGF,MAAI,QAAQ,SAAS;;GACnB,MAAM,CAAC,OAAO,eAAe,KAAK,MAAM,KAAK,EAAE;AAE/C,0BAAM,iDAAN,MAAM,SAAW,EAAE;AACnB,SAAM,OAAO,KAAK;IAChB,MAAM,MAAM,MAAM;IAClB,aAAa,YAAY,MAAM;IAChC,CAAC;AACF;;AAGF,MAAI,QAAQ,UACV,OAAM,UAAU;;AAIpB,QAAO"}
|
package/dist/ui/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/ui/auto-type-table.tsx"],"sourcesContent":[],"mappings":";;;;;;KAYY,kBAAA,GAAqB;AAArB,iBAEU,aAAA,CAFW;EAAA,SAAA;EAAA,OAAkB;EAAA,UAAA;EAAA,cAAA;EAAA,GAAA;CAAA,EAQhD,kBARgD,GAAA;EAE7B,SAAA,EAOT,SAPsB;EACjC,cAAA,CAAA,EAAA,OAQwB,qBARxB;EACA,UAAA,CAAA,EAAA,OAQoB,iBARpB;EACA,OAAA,CAAA,EAQU,wBARV;CACA,CAAA,EAQD,OARC,CAQD,OARC,CAQD,OAAA,CAAA,GAAA,CAAA,OARC,CAAA,EAAA,CAAA;iBAmDa,iBAAA,CAjDZ,IAAA,EAAA,MAAA,CAAA,EAiD6C,OAjD7C,CAiDqD,SAjDrD,CAAA;iBAqDY,qBAAA,CApDF,EAAA,EAAA,MAAA,CAAA,EAoDqC,OApDrC,CAoD6C,SApD7C,CAAA"}
|
package/dist/ui/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["paramNodes: ParameterNode[]"],"sources":["../../src/ui/auto-type-table.tsx"],"sourcesContent":["import { type ParameterNode, type TypeNode, TypeTable } from 'fumadocs-ui/components/type-table';\nimport { type Jsx, toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as runtime from 'react/jsx-runtime';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { renderMarkdownToHast, renderTypeToHast } from '@/markdown';\nimport 'server-only';\nimport type { ReactNode } from 'react';\nimport { type BaseTypeTableProps, type GenerateTypeTableOptions } from '@/lib/type-table';\nimport { type Generator } from '@/lib/base';\nimport type { Nodes } from 'hast';\nimport { parseTags } from '@/lib/parse-tags';\n\nexport type AutoTypeTableProps = BaseTypeTableProps;\n\nexport async function AutoTypeTable({\n generator,\n options = {},\n renderType = renderTypeDefault,\n renderMarkdown = renderMarkdownDefault,\n ...props\n}: AutoTypeTableProps & {\n generator: Generator;\n\n renderMarkdown?: typeof renderMarkdownDefault;\n renderType?: typeof renderTypeDefault;\n options?: GenerateTypeTableOptions;\n}) {\n const output = await generator.generateTypeTable(props, options);\n\n return output.map(async (item) => {\n const entries = item.entries.map(async (entry) => {\n const tags = parseTags(entry.tags);\n const paramNodes: ParameterNode[] = [];\n\n for (const param of tags.params ?? []) {\n paramNodes.push({\n name: param.name,\n description: param.description ? await renderMarkdown(param.description) : undefined,\n });\n }\n\n return [\n entry.name,\n {\n type: await renderType(entry.simplifiedType),\n typeDescription: await renderType(entry.type),\n description: await renderMarkdown(entry.description),\n default: tags.default ? await renderType(tags.default) : undefined,\n parameters: paramNodes,\n required: entry.required,\n deprecated: entry.deprecated,\n returns: tags.returns ? await renderMarkdown(tags.returns) : undefined,\n } as TypeNode,\n ];\n });\n\n return <TypeTable key={item.name} type={Object.fromEntries(await Promise.all(entries))} />;\n });\n}\n\nfunction toJsx(hast: Nodes) {\n return toJsxRuntime(hast, {\n Fragment: runtime.Fragment,\n jsx: runtime.jsx as Jsx,\n jsxs: runtime.jsxs as Jsx,\n components: { ...defaultMdxComponents, img: undefined },\n });\n}\n\nasync function renderTypeDefault(type: string): Promise<ReactNode> {\n return toJsx(await renderTypeToHast(type));\n}\n\nasync function renderMarkdownDefault(md: string): Promise<ReactNode> {\n return toJsx(await renderMarkdownToHast(md));\n}\n"],"mappings":";;;;;;;;;;CAeE;CACA;CACA;CACA;;AAJF,SAAsB,cAAc;;;;qDAYjC;MAZiC,EAClC,WACA,UAAU,EAAE,EACZ,aAAa,mBACb,iBAAiB,gCACd;AAUH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