fumadocs-mdx 12.0.2 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/bin.cjs +1033 -308
  2. package/dist/bin.js +4 -4
  3. package/dist/build-mdx-BHG-_uxo.d.cts +53 -0
  4. package/dist/build-mdx-CzrQDBRZ.d.ts +53 -0
  5. package/dist/bun/index.cjs +92 -28
  6. package/dist/bun/index.js +6 -7
  7. package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
  8. package/dist/chunk-4MAYA5QX.js +44 -0
  9. package/dist/{chunk-RMDXSZYE.js → chunk-CEA6MYJU.js} +13 -8
  10. package/dist/{chunk-IQAEAI4P.js → chunk-HI62EXSB.js} +63 -2
  11. package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
  12. package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
  13. package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
  14. package/dist/{chunk-AUOOMFAI.js → chunk-KILFIBVW.js} +4 -13
  15. package/dist/chunk-NVRDCY6Z.js +30 -0
  16. package/dist/{chunk-VXEBLM4X.js → chunk-XV5Z4BFL.js} +1 -1
  17. package/dist/config/index.cjs +56 -16
  18. package/dist/config/index.d.cts +2 -1
  19. package/dist/config/index.d.ts +2 -1
  20. package/dist/config/index.js +1 -1
  21. package/dist/{define-DJbJduHy.d.ts → define-BCNh3n4O.d.cts} +40 -16
  22. package/dist/{define-DJbJduHy.d.cts → define-bck_EB4t.d.ts} +40 -16
  23. package/dist/index.cjs +0 -109
  24. package/dist/index.d.cts +73 -12
  25. package/dist/index.d.ts +73 -12
  26. package/dist/index.js +0 -11
  27. package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
  28. package/dist/loader-mdx.cjs +153 -60
  29. package/dist/loader-mdx.d.cts +1 -0
  30. package/dist/loader-mdx.d.ts +1 -0
  31. package/dist/loader-mdx.js +23 -9
  32. package/dist/next/index.cjs +213 -181
  33. package/dist/next/index.d.cts +2 -11
  34. package/dist/next/index.d.ts +2 -11
  35. package/dist/next/index.js +145 -117
  36. package/dist/node/loader.cjs +128 -70
  37. package/dist/node/loader.js +14 -9
  38. package/dist/plugins/index.cjs +78 -0
  39. package/dist/plugins/index.d.cts +7 -0
  40. package/dist/plugins/index.d.ts +7 -0
  41. package/dist/plugins/index.js +6 -0
  42. package/dist/plugins/json-schema.cjs +61 -0
  43. package/dist/plugins/json-schema.d.cts +16 -0
  44. package/dist/plugins/json-schema.d.ts +16 -0
  45. package/dist/plugins/json-schema.js +40 -0
  46. package/dist/remark-postprocess-K233ZVBK.d.cts +22 -0
  47. package/dist/remark-postprocess-K233ZVBK.d.ts +22 -0
  48. package/dist/runtime/next/async.cjs +109 -71
  49. package/dist/runtime/next/async.d.cts +9 -6
  50. package/dist/runtime/next/async.d.ts +9 -6
  51. package/dist/runtime/next/async.js +9 -19
  52. package/dist/runtime/next/index.cjs +26 -15
  53. package/dist/runtime/next/index.d.cts +11 -8
  54. package/dist/runtime/next/index.d.ts +11 -8
  55. package/dist/runtime/next/index.js +2 -2
  56. package/dist/runtime/vite/browser.cjs +7 -3
  57. package/dist/runtime/vite/browser.d.cts +56 -7
  58. package/dist/runtime/vite/browser.d.ts +56 -7
  59. package/dist/runtime/vite/browser.js +2 -1
  60. package/dist/runtime/vite/server.cjs +46 -36
  61. package/dist/runtime/vite/server.d.cts +13 -10
  62. package/dist/runtime/vite/server.d.ts +13 -10
  63. package/dist/runtime/vite/server.js +14 -25
  64. package/dist/{types-Ci6BA1tA.d.ts → types-1cCFEzWt.d.ts} +3 -10
  65. package/dist/{types-CbLt05Gc.d.cts → types-D5NhXTJY.d.cts} +3 -10
  66. package/dist/vite/index.cjs +387 -220
  67. package/dist/vite/index.d.cts +29 -10
  68. package/dist/vite/index.d.ts +29 -10
  69. package/dist/vite/index.js +212 -33
  70. package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
  71. package/package.json +29 -16
  72. package/dist/browser-BupUnhpC.d.ts +0 -98
  73. package/dist/browser-R0x9IPaQ.d.cts +0 -98
  74. package/dist/chunk-ADR6R7HM.js +0 -29
  75. package/dist/chunk-XMFLD5J6.js +0 -30
  76. package/dist/chunk-ZLCSVXCD.js +0 -10
  77. package/dist/chunk-ZX7TM4AR.js +0 -127
  78. package/dist/postinstall-SCSXM4IM.js +0 -10
  79. package/dist/shared-Cnm1afPW.d.cts +0 -71
  80. package/dist/shared-DpXxElc1.d.ts +0 -71
@@ -0,0 +1,40 @@
1
+ // src/plugins/json-schema.ts
2
+ import { z } from "zod";
3
+ function jsonSchema() {
4
+ let config;
5
+ return {
6
+ config(v) {
7
+ config = v;
8
+ },
9
+ emit() {
10
+ const files = [];
11
+ function onSchema(name, schema) {
12
+ files.push({
13
+ path: `json-schema/${name}.json`,
14
+ content: JSON.stringify(
15
+ z.toJSONSchema(schema, {
16
+ io: "input",
17
+ unrepresentable: "any"
18
+ })
19
+ )
20
+ });
21
+ }
22
+ for (const [name, collection] of config.collections) {
23
+ if (collection.type === "docs") {
24
+ if (collection.meta.schema instanceof z.ZodType) {
25
+ onSchema(`${name}.meta`, collection.meta.schema);
26
+ }
27
+ if (collection.docs.schema instanceof z.ZodType) {
28
+ onSchema(`${name}.docs`, collection.docs.schema);
29
+ }
30
+ } else if (collection.schema instanceof z.ZodType) {
31
+ onSchema(name, collection.schema);
32
+ }
33
+ }
34
+ return files;
35
+ }
36
+ };
37
+ }
38
+ export {
39
+ jsonSchema as default
40
+ };
@@ -0,0 +1,22 @@
1
+ interface ExtractedReference {
2
+ href: string;
3
+ }
4
+ interface PostprocessOptions {
5
+ _format: 'md' | 'mdx';
6
+ /**
7
+ * Properties to export from `vfile.data`
8
+ */
9
+ valueToExport?: string[];
10
+ /**
11
+ * stringify MDAST and export via `_markdown`.
12
+ */
13
+ includeProcessedMarkdown?: boolean;
14
+ /**
15
+ * store MDAST and export via `_mdast`.
16
+ */
17
+ includeMDAST?: boolean | {
18
+ removePosition?: boolean;
19
+ };
20
+ }
21
+
22
+ export type { ExtractedReference as E, PostprocessOptions as P };
@@ -0,0 +1,22 @@
1
+ interface ExtractedReference {
2
+ href: string;
3
+ }
4
+ interface PostprocessOptions {
5
+ _format: 'md' | 'mdx';
6
+ /**
7
+ * Properties to export from `vfile.data`
8
+ */
9
+ valueToExport?: string[];
10
+ /**
11
+ * stringify MDAST and export via `_markdown`.
12
+ */
13
+ includeProcessedMarkdown?: boolean;
14
+ /**
15
+ * store MDAST and export via `_mdast`.
16
+ */
17
+ includeMDAST?: boolean | {
18
+ removePosition?: boolean;
19
+ };
20
+ }
21
+
22
+ export type { ExtractedReference as E, PostprocessOptions as P };
@@ -125,14 +125,31 @@ __export(async_exports, {
125
125
  });
126
126
  module.exports = __toCommonJS(async_exports);
127
127
 
128
- // src/runtime/next/index.ts
129
- var fs = __toESM(require("fs/promises"), 1);
130
-
131
128
  // src/runtime/shared.ts
132
- function missingProcessedMarkdown() {
133
- throw new Error(
134
- "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
135
- );
129
+ var import_promises = __toESM(require("fs/promises"), 1);
130
+ function createDocMethods(info, load2) {
131
+ return {
132
+ info,
133
+ async getText(type) {
134
+ if (type === "raw") {
135
+ return (await import_promises.default.readFile(info.fullPath)).toString();
136
+ }
137
+ const data = await load2();
138
+ if (typeof data._markdown !== "string")
139
+ throw new Error(
140
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
141
+ );
142
+ return data._markdown;
143
+ },
144
+ async getMDAST() {
145
+ const data = await load2();
146
+ if (!data._mdast)
147
+ throw new Error(
148
+ "getMDAST() requires `includeMDAST` to be enabled in your collection config."
149
+ );
150
+ return JSON.parse(data._mdast);
151
+ }
152
+ };
136
153
  }
137
154
 
138
155
  // src/runtime/next/index.ts
@@ -140,9 +157,7 @@ var _runtime = {
140
157
  doc(files) {
141
158
  return files.map((file) => {
142
159
  const data = file.data;
143
- const filePath = file.info.fullPath;
144
160
  return {
145
- info: file.info,
146
161
  _exports: data,
147
162
  body: data.default,
148
163
  lastModified: data.lastModified,
@@ -150,13 +165,7 @@ var _runtime = {
150
165
  structuredData: data.structuredData,
151
166
  extractedReferences: data.extractedReferences,
152
167
  ...data.frontmatter,
153
- async getText(type) {
154
- if (type === "raw") {
155
- return (await fs.readFile(filePath)).toString();
156
- }
157
- if (typeof data._markdown !== "string") missingProcessedMarkdown();
158
- return data._markdown;
159
- }
168
+ ...createDocMethods(file.info, () => Promise.resolve(data))
160
169
  };
161
170
  });
162
171
  },
@@ -182,7 +191,7 @@ var _runtime = {
182
191
  };
183
192
  function createMDXSource(docs, meta = []) {
184
193
  return {
185
- files: () => resolveFiles({
194
+ files: resolveFiles({
186
195
  docs,
187
196
  meta
188
197
  })
@@ -214,7 +223,7 @@ var import_mdx = require("@mdx-js/mdx");
214
223
 
215
224
  // src/loaders/mdx/remark-include.ts
216
225
  var import_unified = require("unified");
217
- var import_unist_util_visit = require("unist-util-visit");
226
+ var import_unist_util_visit2 = require("unist-util-visit");
218
227
  var path = __toESM(require("path"), 1);
219
228
  var fs2 = __toESM(require("fs/promises"), 1);
220
229
 
@@ -235,9 +244,53 @@ function fumaMatter(input) {
235
244
  }
236
245
 
237
246
  // src/loaders/mdx/remark-include.ts
238
- var import_remark_parse = __toESM(require("remark-parse"), 1);
239
- var import_remark_mdx = __toESM(require("remark-mdx"), 1);
240
247
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
248
+
249
+ // src/loaders/mdx/remark-unravel.ts
250
+ var import_unist_util_visit = require("unist-util-visit");
251
+ function remarkMarkAndUnravel() {
252
+ return (tree) => {
253
+ (0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
254
+ let offset = -1;
255
+ let all = true;
256
+ let oneOrMore = false;
257
+ if (parent && typeof index === "number" && node.type === "paragraph") {
258
+ const children = node.children;
259
+ while (++offset < children.length) {
260
+ const child = children[offset];
261
+ if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
262
+ oneOrMore = true;
263
+ } else if (child.type === "text" && child.value.trim().length === 0) {
264
+ } else {
265
+ all = false;
266
+ break;
267
+ }
268
+ }
269
+ if (all && oneOrMore) {
270
+ offset = -1;
271
+ const newChildren = [];
272
+ while (++offset < children.length) {
273
+ const child = children[offset];
274
+ if (child.type === "mdxJsxTextElement") {
275
+ child.type = "mdxJsxFlowElement";
276
+ }
277
+ if (child.type === "mdxTextExpression") {
278
+ child.type = "mdxFlowExpression";
279
+ }
280
+ if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
281
+ } else {
282
+ newChildren.push(child);
283
+ }
284
+ }
285
+ parent.children.splice(index, 1, ...newChildren);
286
+ return index;
287
+ }
288
+ }
289
+ });
290
+ };
291
+ }
292
+
293
+ // src/loaders/mdx/remark-include.ts
241
294
  var ElementLikeTypes = [
242
295
  "mdxJsxFlowElement",
243
296
  "mdxJsxTextElement",
@@ -277,7 +330,7 @@ function parseSpecifier(specifier) {
277
330
  function extractSection(root, section) {
278
331
  let nodes;
279
332
  let capturingHeadingContent = false;
280
- (0, import_unist_util_visit.visit)(root, (node) => {
333
+ (0, import_unist_util_visit2.visit)(root, (node) => {
281
334
  if (node.type === "heading") {
282
335
  if (capturingHeadingContent) {
283
336
  return false;
@@ -309,7 +362,7 @@ function extractSection(root, section) {
309
362
  }
310
363
  function remarkInclude() {
311
364
  const TagName = "include";
312
- async function embedContent(file, heading, params, data) {
365
+ const embedContent = async (file, heading, params, data) => {
313
366
  let content;
314
367
  try {
315
368
  content = (await fs2.readFile(file)).toString();
@@ -332,18 +385,17 @@ ${e instanceof Error ? e.message : String(e)}`,
332
385
  data: {}
333
386
  };
334
387
  }
335
- const parser = (data._getProcessor ?? getDefaultProcessor)(
336
- ext === ".mdx" ? "mdx" : "md"
337
- );
388
+ const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
338
389
  const parsed = fumaMatter(content);
339
390
  let mdast = parser.parse({
340
391
  path: file,
341
392
  value: parsed.content,
342
393
  data: { frontmatter: parsed.data }
343
394
  });
395
+ const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
344
396
  if (heading) {
345
397
  const extracted = extractSection(
346
- await (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading).run(mdast),
398
+ await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
347
399
  heading
348
400
  );
349
401
  if (!extracted)
@@ -351,13 +403,15 @@ ${e instanceof Error ? e.message : String(e)}`,
351
403
  `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
352
404
  );
353
405
  mdast = extracted;
406
+ } else {
407
+ mdast = await baseProcessor.run(mdast);
354
408
  }
355
409
  await update(mdast, path.dirname(file), data);
356
410
  return mdast;
357
- }
411
+ };
358
412
  async function update(tree, directory, data) {
359
413
  const queue = [];
360
- (0, import_unist_util_visit.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
414
+ (0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
361
415
  const node = _node;
362
416
  if (node.name !== TagName) return;
363
417
  const specifier = flattenNode(node);
@@ -384,24 +438,28 @@ ${e instanceof Error ? e.message : String(e)}`,
384
438
  await update(tree, path.dirname(file.path), file.data);
385
439
  };
386
440
  }
387
- function getDefaultProcessor(format) {
388
- const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
389
- if (format === "md") return mdProcessor;
390
- return mdProcessor.use(import_remark_mdx.default);
391
- }
392
441
 
393
442
  // src/loaders/mdx/remark-postprocess.ts
394
- var import_unist_util_visit2 = require("unist-util-visit");
443
+ var import_unist_util_visit3 = require("unist-util-visit");
395
444
  var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
396
445
  var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
446
+ var import_unist_util_remove_position = require("unist-util-remove-position");
447
+ var import_remark_mdx = __toESM(require("remark-mdx"), 1);
397
448
  function remarkPostprocess({
449
+ _format,
398
450
  includeProcessedMarkdown = false,
451
+ includeMDAST = false,
399
452
  valueToExport = []
400
- } = {}) {
453
+ }) {
454
+ let _stringifyProcessor;
455
+ const getStringifyProcessor = () => {
456
+ if (_format === "mdx") return this;
457
+ return _stringifyProcessor ??= this().use(import_remark_mdx.default).freeze();
458
+ };
401
459
  return (tree, file) => {
402
460
  let title;
403
461
  const urls = [];
404
- (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
462
+ (0, import_unist_util_visit3.visit)(tree, ["heading", "link"], (node) => {
405
463
  if (node.type === "heading" && node.depth === 1) {
406
464
  title = flattenNode2(node);
407
465
  }
@@ -417,12 +475,19 @@ function remarkPostprocess({
417
475
  }
418
476
  file.data.extractedReferences = urls;
419
477
  if (includeProcessedMarkdown) {
478
+ const processor = getStringifyProcessor();
420
479
  file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
421
- ...this.data("settings"),
480
+ ...processor.data("settings"),
422
481
  // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
423
- extensions: this.data("toMarkdownExtensions") || []
482
+ extensions: processor.data("toMarkdownExtensions") || []
424
483
  });
425
484
  }
485
+ if (includeMDAST) {
486
+ const options = includeMDAST === true ? {} : includeMDAST;
487
+ file.data._mdast = JSON.stringify(
488
+ options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
489
+ );
490
+ }
426
491
  for (const { name, value } of file.data["mdx-export"] ?? []) {
427
492
  tree.children.unshift(getMdastExport(name, value));
428
493
  }
@@ -490,6 +555,7 @@ async function buildMDX(cacheKey, source, options) {
490
555
  [
491
556
  remarkPostprocess,
492
557
  {
558
+ _format: format,
493
559
  ...options.postprocess,
494
560
  valueToExport: [
495
561
  ...options.postprocess?.valueToExport ?? [],
@@ -497,7 +563,8 @@ async function buildMDX(cacheKey, source, options) {
497
563
  "extractedReferences",
498
564
  "frontmatter",
499
565
  "lastModified",
500
- "_markdown"
566
+ "_markdown",
567
+ "_mdast"
501
568
  ]
502
569
  }
503
570
  ]
@@ -525,28 +592,7 @@ async function buildMDX(cacheKey, source, options) {
525
592
  // src/runtime/next/async.ts
526
593
  var import_client = require("@fumadocs/mdx-remote/client");
527
594
  var import_node_url = require("url");
528
-
529
- // src/next/map/file-cache.ts
530
- var import_lru_cache = require("lru-cache");
531
- var import_promises = __toESM(require("fs/promises"), 1);
532
- var import_node_path = __toESM(require("path"), 1);
533
- var map = new import_lru_cache.LRUCache({
534
- max: 100
535
- });
536
- function toFullPath(file) {
537
- if (import_node_path.default.isAbsolute(file)) {
538
- return import_node_path.default.relative(process.cwd(), file);
539
- }
540
- return file;
541
- }
542
- async function readFileWithCache(file) {
543
- const fullPath = toFullPath(file);
544
- const cached = map.get(fullPath);
545
- if (cached) return cached;
546
- const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
547
- map.set(fullPath, read);
548
- return read;
549
- }
595
+ var import_promises2 = __toESM(require("fs/promises"), 1);
550
596
 
551
597
  // src/config/build.ts
552
598
  function buildConfig(config) {
@@ -616,7 +662,7 @@ var _runtimeAsync = {
616
662
  async function compileAndLoad() {
617
663
  if (cachedResult) return cachedResult;
618
664
  const mdxOptions = await initMdxOptions;
619
- const raw = await readFileWithCache(info.fullPath);
665
+ const raw = (await import_promises2.default.readFile(info.fullPath)).toString();
620
666
  const { content } = fumaMatter(raw);
621
667
  const compiled = await buildMDX(collectionName, content, {
622
668
  ...mdxOptions,
@@ -635,15 +681,7 @@ var _runtimeAsync = {
635
681
  }
636
682
  return {
637
683
  ...data,
638
- info,
639
- async getText(type) {
640
- if (type === "raw") {
641
- return readFileWithCache(info.fullPath);
642
- }
643
- const out = await compileAndLoad();
644
- if (typeof out._markdown !== "string") missingProcessedMarkdown();
645
- return out._markdown;
646
- },
684
+ ...createDocMethods(info, () => compileAndLoad()),
647
685
  async load() {
648
686
  const out = await compileAndLoad();
649
687
  return {
@@ -1,15 +1,18 @@
1
- import { L as LoadedConfig, R as RuntimeAsync } from '../../types-CbLt05Gc.cjs';
1
+ import { c as RuntimeAsync } from '../../types-D5NhXTJY.cjs';
2
+ import { L as LoadedConfig } from '../../define-BCNh3n4O.cjs';
2
3
  import '@standard-schema/spec';
3
4
  import 'fumadocs-core/source';
4
- import '../../define-DJbJduHy.cjs';
5
+ import '../../index.cjs';
5
6
  import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/toc';
8
+ import 'mdx/types';
9
+ import '../../remark-postprocess-K233ZVBK.cjs';
10
+ import 'mdast';
11
+ import '../../build-mdx-BHG-_uxo.cjs';
6
12
  import '@mdx-js/mdx';
13
+ import 'react';
7
14
  import 'unified';
8
15
  import 'zod';
9
- import '../../shared-Cnm1afPW.cjs';
10
- import 'fumadocs-core/server';
11
- import 'react';
12
- import 'mdx/types';
13
16
 
14
17
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
15
18
 
@@ -1,15 +1,18 @@
1
- import { L as LoadedConfig, R as RuntimeAsync } from '../../types-Ci6BA1tA.js';
1
+ import { c as RuntimeAsync } from '../../types-1cCFEzWt.js';
2
+ import { L as LoadedConfig } from '../../define-bck_EB4t.js';
2
3
  import '@standard-schema/spec';
3
4
  import 'fumadocs-core/source';
4
- import '../../define-DJbJduHy.js';
5
+ import '../../index.js';
5
6
  import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/toc';
8
+ import 'mdx/types';
9
+ import '../../remark-postprocess-K233ZVBK.js';
10
+ import 'mdast';
11
+ import '../../build-mdx-CzrQDBRZ.js';
6
12
  import '@mdx-js/mdx';
13
+ import 'react';
7
14
  import 'unified';
8
15
  import 'zod';
9
- import '../../shared-DpXxElc1.js';
10
- import 'fumadocs-core/server';
11
- import 'react';
12
- import 'mdx/types';
13
16
 
14
17
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
15
18
 
@@ -1,20 +1,17 @@
1
1
  import {
2
2
  _runtime,
3
3
  createMDXSource
4
- } from "../../chunk-AUOOMFAI.js";
4
+ } from "../../chunk-KILFIBVW.js";
5
5
  import {
6
- missingProcessedMarkdown
7
- } from "../../chunk-ZLCSVXCD.js";
6
+ createDocMethods
7
+ } from "../../chunk-NVRDCY6Z.js";
8
8
  import {
9
- readFileWithCache
10
- } from "../../chunk-ADR6R7HM.js";
9
+ buildMDX
10
+ } from "../../chunk-3J3WL7WN.js";
11
+ import "../../chunk-K5ZLPEIQ.js";
11
12
  import {
12
13
  buildConfig
13
14
  } from "../../chunk-U4MQ44TS.js";
14
- import {
15
- buildMDX
16
- } from "../../chunk-QAUWMR5D.js";
17
- import "../../chunk-LMG6UWCL.js";
18
15
  import {
19
16
  fumaMatter
20
17
  } from "../../chunk-VWJKRQZR.js";
@@ -22,6 +19,7 @@ import {
22
19
  // src/runtime/next/async.ts
23
20
  import { executeMdx } from "@fumadocs/mdx-remote/client";
24
21
  import { pathToFileURL } from "url";
22
+ import fs from "fs/promises";
25
23
  function getDocCollection(config, collection) {
26
24
  const col = config.collections.get(collection);
27
25
  if (col?.type === "doc" && col.mdxOptions) return col;
@@ -39,7 +37,7 @@ var _runtimeAsync = {
39
37
  async function compileAndLoad() {
40
38
  if (cachedResult) return cachedResult;
41
39
  const mdxOptions = await initMdxOptions;
42
- const raw = await readFileWithCache(info.fullPath);
40
+ const raw = (await fs.readFile(info.fullPath)).toString();
43
41
  const { content } = fumaMatter(raw);
44
42
  const compiled = await buildMDX(collectionName, content, {
45
43
  ...mdxOptions,
@@ -58,15 +56,7 @@ var _runtimeAsync = {
58
56
  }
59
57
  return {
60
58
  ...data,
61
- info,
62
- async getText(type) {
63
- if (type === "raw") {
64
- return readFileWithCache(info.fullPath);
65
- }
66
- const out = await compileAndLoad();
67
- if (typeof out._markdown !== "string") missingProcessedMarkdown();
68
- return out._markdown;
69
- },
59
+ ...createDocMethods(info, () => compileAndLoad()),
70
60
  async load() {
71
61
  const out = await compileAndLoad();
72
62
  return {
@@ -35,13 +35,32 @@ __export(next_exports, {
35
35
  resolveFiles: () => resolveFiles
36
36
  });
37
37
  module.exports = __toCommonJS(next_exports);
38
- var fs = __toESM(require("fs/promises"), 1);
39
38
 
40
39
  // src/runtime/shared.ts
41
- function missingProcessedMarkdown() {
42
- throw new Error(
43
- "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
44
- );
40
+ var import_promises = __toESM(require("fs/promises"), 1);
41
+ function createDocMethods(info, load) {
42
+ return {
43
+ info,
44
+ async getText(type) {
45
+ if (type === "raw") {
46
+ return (await import_promises.default.readFile(info.fullPath)).toString();
47
+ }
48
+ const data = await load();
49
+ if (typeof data._markdown !== "string")
50
+ throw new Error(
51
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
52
+ );
53
+ return data._markdown;
54
+ },
55
+ async getMDAST() {
56
+ const data = await load();
57
+ if (!data._mdast)
58
+ throw new Error(
59
+ "getMDAST() requires `includeMDAST` to be enabled in your collection config."
60
+ );
61
+ return JSON.parse(data._mdast);
62
+ }
63
+ };
45
64
  }
46
65
 
47
66
  // src/runtime/next/index.ts
@@ -49,9 +68,7 @@ var _runtime = {
49
68
  doc(files) {
50
69
  return files.map((file) => {
51
70
  const data = file.data;
52
- const filePath = file.info.fullPath;
53
71
  return {
54
- info: file.info,
55
72
  _exports: data,
56
73
  body: data.default,
57
74
  lastModified: data.lastModified,
@@ -59,13 +76,7 @@ var _runtime = {
59
76
  structuredData: data.structuredData,
60
77
  extractedReferences: data.extractedReferences,
61
78
  ...data.frontmatter,
62
- async getText(type) {
63
- if (type === "raw") {
64
- return (await fs.readFile(filePath)).toString();
65
- }
66
- if (typeof data._markdown !== "string") missingProcessedMarkdown();
67
- return data._markdown;
68
- }
79
+ ...createDocMethods(file.info, () => Promise.resolve(data))
69
80
  };
70
81
  });
71
82
  },
@@ -91,7 +102,7 @@ var _runtime = {
91
102
  };
92
103
  function createMDXSource(docs, meta = []) {
93
104
  return {
94
- files: () => resolveFiles({
105
+ files: resolveFiles({
95
106
  docs,
96
107
  meta
97
108
  })
@@ -1,16 +1,19 @@
1
- import { F as FileInfo } from '../../shared-Cnm1afPW.cjs';
2
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
3
- import { a as Runtime } from '../../types-CbLt05Gc.cjs';
4
- export { c as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, R as RuntimeAsync, b as RuntimeFile } from '../../types-CbLt05Gc.cjs';
5
- import '../../define-DJbJduHy.cjs';
6
- import 'fumadocs-core/mdx-plugins';
7
- import 'fumadocs-core/server';
8
- import 'react';
9
- import 'mdx/types';
2
+ import { R as Runtime } from '../../types-D5NhXTJY.cjs';
3
+ export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-D5NhXTJY.cjs';
4
+ import { FileInfo } from '../../index.cjs';
10
5
  import '@standard-schema/spec';
6
+ import '../../define-BCNh3n4O.cjs';
7
+ import 'fumadocs-core/mdx-plugins';
11
8
  import '@mdx-js/mdx';
12
9
  import 'unified';
13
10
  import 'zod';
11
+ import '../../remark-postprocess-K233ZVBK.cjs';
12
+ import 'fumadocs-core/toc';
13
+ import 'mdx/types';
14
+ import 'mdast';
15
+ import '../../build-mdx-BHG-_uxo.cjs';
16
+ import 'react';
14
17
 
15
18
  declare const _runtime: Runtime;
16
19
  interface AnyCollectionEntry {
@@ -1,16 +1,19 @@
1
- import { F as FileInfo } from '../../shared-DpXxElc1.js';
2
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
3
- import { a as Runtime } from '../../types-Ci6BA1tA.js';
4
- export { c as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, R as RuntimeAsync, b as RuntimeFile } from '../../types-Ci6BA1tA.js';
5
- import '../../define-DJbJduHy.js';
6
- import 'fumadocs-core/mdx-plugins';
7
- import 'fumadocs-core/server';
8
- import 'react';
9
- import 'mdx/types';
2
+ import { R as Runtime } from '../../types-1cCFEzWt.js';
3
+ export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-1cCFEzWt.js';
4
+ import { FileInfo } from '../../index.js';
10
5
  import '@standard-schema/spec';
6
+ import '../../define-bck_EB4t.js';
7
+ import 'fumadocs-core/mdx-plugins';
11
8
  import '@mdx-js/mdx';
12
9
  import 'unified';
13
10
  import 'zod';
11
+ import '../../remark-postprocess-K233ZVBK.js';
12
+ import 'fumadocs-core/toc';
13
+ import 'mdx/types';
14
+ import 'mdast';
15
+ import '../../build-mdx-CzrQDBRZ.js';
16
+ import 'react';
14
17
 
15
18
  declare const _runtime: Runtime;
16
19
  interface AnyCollectionEntry {
@@ -2,8 +2,8 @@ import {
2
2
  _runtime,
3
3
  createMDXSource,
4
4
  resolveFiles
5
- } from "../../chunk-AUOOMFAI.js";
6
- import "../../chunk-ZLCSVXCD.js";
5
+ } from "../../chunk-KILFIBVW.js";
6
+ import "../../chunk-NVRDCY6Z.js";
7
7
  export {
8
8
  _runtime,
9
9
  createMDXSource,