fumadocs-mdx 11.10.0 → 12.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 (71) hide show
  1. package/dist/bin.cjs +953 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  6. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  7. package/dist/bun/index.cjs +129 -109
  8. package/dist/bun/index.js +9 -6
  9. package/dist/chunk-3M4SHY6K.js +80 -0
  10. package/dist/chunk-6Y5JDZHD.js +65 -0
  11. package/dist/{chunk-NUDEC6C5.js → chunk-AUOOMFAI.js} +28 -22
  12. package/dist/chunk-IQAEAI4P.js +66 -0
  13. package/dist/{chunk-5XJM5RPV.js → chunk-KGUBBRL6.js} +13 -13
  14. package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
  15. package/dist/chunk-POXTQZ4D.js +60 -0
  16. package/dist/chunk-SWNOXPYJ.js +142 -0
  17. package/dist/{chunk-COQ4VMK2.js → chunk-TLD6JMT6.js} +28 -61
  18. package/dist/{chunk-NVX3U5YE.js → chunk-VXEBLM4X.js} +2 -2
  19. package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
  20. package/dist/chunk-ZLCSVXCD.js +10 -0
  21. package/dist/config/index.cjs +18 -97
  22. package/dist/config/index.d.cts +1 -1
  23. package/dist/config/index.d.ts +1 -1
  24. package/dist/config/index.js +48 -9
  25. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.cts} +18 -3
  26. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.ts} +18 -3
  27. package/dist/loader-mdx.cjs +127 -139
  28. package/dist/loader-mdx.js +7 -6
  29. package/dist/next/index.cjs +44 -269
  30. package/dist/next/index.js +30 -46
  31. package/dist/node/loader.cjs +131 -143
  32. package/dist/node/loader.js +7 -6
  33. package/dist/postinstall-U7VROOY7.js +9 -0
  34. package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
  35. package/dist/runtime/{async.cjs → next/async.cjs} +202 -154
  36. package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
  37. package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
  38. package/dist/runtime/next/async.js +92 -0
  39. package/dist/{index.cjs → runtime/next/index.cjs} +35 -26
  40. package/dist/runtime/next/index.d.cts +30 -0
  41. package/dist/runtime/next/index.d.ts +30 -0
  42. package/dist/{index.js → runtime/next/index.js} +2 -1
  43. package/dist/runtime/vite/browser.d.cts +2 -3
  44. package/dist/runtime/vite/browser.d.ts +2 -3
  45. package/dist/runtime/vite/server.cjs +67 -21
  46. package/dist/runtime/vite/server.d.cts +14 -28
  47. package/dist/runtime/vite/server.d.ts +14 -28
  48. package/dist/runtime/vite/server.js +61 -21
  49. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  50. package/dist/shared-CqgMnt9h.d.cts +70 -0
  51. package/dist/{types-DN9KrG7R.d.ts → types-DLIAvrgC.d.ts} +6 -32
  52. package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
  53. package/dist/vite/index.cjs +201 -123
  54. package/dist/vite/index.d.cts +4 -1
  55. package/dist/vite/index.d.ts +4 -1
  56. package/dist/vite/index.js +13 -9
  57. package/package.json +11 -17
  58. package/bin.js +0 -5
  59. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  60. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  61. package/dist/chunk-2HKRTQYP.js +0 -154
  62. package/dist/chunk-GBMFGEC7.js +0 -57
  63. package/dist/chunk-QQWCBFFE.js +0 -40
  64. package/dist/chunk-SMSNZ6N5.js +0 -155
  65. package/dist/config/zod-3.cjs +0 -422
  66. package/dist/config/zod-3.d.cts +0 -53
  67. package/dist/config/zod-3.d.ts +0 -53
  68. package/dist/config/zod-3.js +0 -40
  69. package/dist/index.d.cts +0 -26
  70. package/dist/index.d.ts +0 -26
  71. package/dist/runtime/async.js +0 -72
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/mdx-plugins/remark-postprocess.ts
34
- function remarkPostprocess({
35
- injectExports
36
- }) {
37
- return (tree, file) => {
38
- let title;
39
- const urls = [];
40
- (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
41
- if (node.type === "heading" && node.depth === 1) {
42
- title = flattenNode2(node);
43
- }
44
- if (node.type !== "link") return;
45
- urls.push({
46
- href: node.url
47
- });
48
- return "skip";
49
- });
50
- if (title) {
51
- file.data.frontmatter ??= {};
52
- if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
53
- }
54
- file.data.extractedReferences = urls;
55
- for (const name of injectExports) {
56
- if (!(name in file.data)) continue;
57
- tree.children.unshift(getMdastExport(name, file.data[name]));
58
- }
59
- };
60
- }
61
- function flattenNode2(node) {
62
- if ("children" in node)
63
- return node.children.map((child) => flattenNode2(child)).join("");
64
- if ("value" in node) return node.value;
65
- return "";
66
- }
67
- function getMdastExport(name, value) {
68
- return {
69
- type: "mdxjsEsm",
70
- value: "",
71
- data: {
72
- estree: {
73
- type: "Program",
74
- sourceType: "module",
75
- body: [
76
- {
77
- type: "ExportNamedDeclaration",
78
- attributes: [],
79
- specifiers: [],
80
- source: null,
81
- declaration: {
82
- type: "VariableDeclaration",
83
- kind: "let",
84
- declarations: [
85
- {
86
- type: "VariableDeclarator",
87
- id: {
88
- type: "Identifier",
89
- name
90
- },
91
- init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
92
- }
93
- ]
94
- }
95
- }
96
- ]
97
- }
98
- }
99
- };
100
- }
101
- var import_unist_util_visit2, import_estree_util_value_to_estree;
102
- var init_remark_postprocess = __esm({
103
- "src/mdx-plugins/remark-postprocess.ts"() {
104
- "use strict";
105
- import_unist_util_visit2 = require("unist-util-visit");
106
- import_estree_util_value_to_estree = require("estree-util-value-to-estree");
107
- }
108
- });
109
-
110
- // src/utils/mdx-options.ts
111
- var mdx_options_exports = {};
112
- __export(mdx_options_exports, {
33
+ // src/mdx/preset.ts
34
+ var preset_exports = {};
35
+ __export(preset_exports, {
113
36
  getDefaultMDXOptions: () => getDefaultMDXOptions
114
37
  });
115
38
  function pluginOption(def, options = []) {
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
132
55
  _withoutBundler = false,
133
56
  ...mdxOptions
134
57
  }) {
135
- const mdxExports = [
136
- "structuredData",
137
- "extractedReferences",
138
- "frontmatter",
139
- "lastModified",
140
- ...valueToExport
141
- ];
142
58
  const remarkPlugins = pluginOption(
143
59
  (v) => [
144
60
  plugins.remarkGfm,
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
166
82
  plugins.remarkStructure,
167
83
  remarkStructureOptions
168
84
  ],
169
- [
170
- remarkPostprocess,
171
- { injectExports: mdxExports }
172
- ]
85
+ () => {
86
+ return (_, file) => {
87
+ file.data["mdx-export"] ??= [];
88
+ for (const name of valueToExport) {
89
+ if (name in file.data)
90
+ file.data["mdx-export"].push({ name, value: file.data[name] });
91
+ }
92
+ };
93
+ }
173
94
  ],
174
95
  mdxOptions.remarkPlugins
175
96
  );
@@ -189,15 +110,14 @@ function getDefaultMDXOptions({
189
110
  };
190
111
  }
191
112
  var plugins;
192
- var init_mdx_options = __esm({
193
- "src/utils/mdx-options.ts"() {
113
+ var init_preset = __esm({
114
+ "src/mdx/preset.ts"() {
194
115
  "use strict";
195
116
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
196
- init_remark_postprocess();
197
117
  }
198
118
  });
199
119
 
200
- // src/runtime/async.ts
120
+ // src/runtime/next/async.ts
201
121
  var async_exports = {};
202
122
  __export(async_exports, {
203
123
  _runtimeAsync: () => _runtimeAsync,
@@ -205,26 +125,37 @@ __export(async_exports, {
205
125
  });
206
126
  module.exports = __toCommonJS(async_exports);
207
127
 
208
- // src/runtime/index.ts
209
- var import_node_fs = __toESM(require("fs"), 1);
210
- var cache = /* @__PURE__ */ new Map();
128
+ // src/runtime/next/index.ts
129
+ var fs = __toESM(require("fs/promises"), 1);
130
+
131
+ // src/runtime/shared.ts
132
+ function missingProcessedMarkdown() {
133
+ throw new Error(
134
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
135
+ );
136
+ }
137
+
138
+ // src/runtime/next/index.ts
211
139
  var _runtime = {
212
140
  doc(files) {
213
141
  return files.map((file) => {
214
- const { default: body, frontmatter, ...exports2 } = file.data;
142
+ const data = file.data;
143
+ const filePath = file.info.fullPath;
215
144
  return {
216
- body,
217
- ...exports2,
218
- ...frontmatter,
219
- _file: file.info,
220
- _exports: file.data,
221
- get content() {
222
- const path2 = this._file.absolutePath;
223
- const cached = cache.get(path2);
224
- if (cached) return cached;
225
- const content = import_node_fs.default.readFileSync(path2).toString();
226
- cache.set(path2, content);
227
- return content;
145
+ info: file.info,
146
+ _exports: data,
147
+ body: data.default,
148
+ lastModified: data.lastModified,
149
+ toc: data.toc,
150
+ structuredData: data.structuredData,
151
+ extractedReferences: data.extractedReferences,
152
+ ...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;
228
159
  }
229
160
  };
230
161
  });
@@ -232,8 +163,8 @@ var _runtime = {
232
163
  meta(files) {
233
164
  return files.map((file) => {
234
165
  return {
235
- ...file.data,
236
- _file: file.info
166
+ info: file.info,
167
+ ...file.data
237
168
  };
238
169
  });
239
170
  },
@@ -262,26 +193,26 @@ function resolveFiles({ docs, meta }) {
262
193
  for (const entry of docs) {
263
194
  outputs.push({
264
195
  type: "page",
265
- absolutePath: entry._file.absolutePath,
266
- path: entry._file.path,
196
+ absolutePath: entry.info.fullPath,
197
+ path: entry.info.path,
267
198
  data: entry
268
199
  });
269
200
  }
270
201
  for (const entry of meta) {
271
202
  outputs.push({
272
203
  type: "meta",
273
- absolutePath: entry._file.absolutePath,
274
- path: entry._file.path,
204
+ absolutePath: entry.info.fullPath,
205
+ path: entry.info.path,
275
206
  data: entry
276
207
  });
277
208
  }
278
209
  return outputs;
279
210
  }
280
211
 
281
- // src/utils/build-mdx.ts
212
+ // src/mdx/build-mdx.ts
282
213
  var import_mdx = require("@mdx-js/mdx");
283
214
 
284
- // src/mdx-plugins/remark-include.ts
215
+ // src/mdx/remark-include.ts
285
216
  var import_unified = require("unified");
286
217
  var import_unist_util_visit = require("unist-util-visit");
287
218
  var path = __toESM(require("path"), 1);
@@ -303,7 +234,7 @@ function fumaMatter(input) {
303
234
  return output;
304
235
  }
305
236
 
306
- // src/mdx-plugins/remark-include.ts
237
+ // src/mdx/remark-include.ts
307
238
  var import_remark_parse = __toESM(require("remark-parse"), 1);
308
239
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
309
240
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
@@ -431,21 +362,121 @@ function getDefaultProcessor(format) {
431
362
  return mdProcessor.use(import_remark_mdx.default);
432
363
  }
433
364
 
434
- // src/utils/build-mdx.ts
435
- var cache2 = /* @__PURE__ */ new Map();
365
+ // src/mdx/remark-postprocess.ts
366
+ var import_unist_util_visit2 = require("unist-util-visit");
367
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
368
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
369
+ function remarkPostprocess({
370
+ includeProcessedMarkdown = false,
371
+ valueToExport = []
372
+ } = {}) {
373
+ return (tree, file) => {
374
+ let title;
375
+ const urls = [];
376
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
377
+ if (node.type === "heading" && node.depth === 1) {
378
+ title = flattenNode2(node);
379
+ }
380
+ if (node.type !== "link") return;
381
+ urls.push({
382
+ href: node.url
383
+ });
384
+ return "skip";
385
+ });
386
+ if (title) {
387
+ file.data.frontmatter ??= {};
388
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
389
+ }
390
+ file.data.extractedReferences = urls;
391
+ if (includeProcessedMarkdown) {
392
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
393
+ ...this.data("settings"),
394
+ // @ts-expect-error - from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
395
+ extensions: this.data("toMarkdownExtensions") || []
396
+ });
397
+ }
398
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
399
+ tree.children.unshift(getMdastExport(name, value));
400
+ }
401
+ for (const name of valueToExport) {
402
+ if (!(name in file.data)) continue;
403
+ tree.children.unshift(getMdastExport(name, file.data[name]));
404
+ }
405
+ };
406
+ }
407
+ function getMdastExport(name, value) {
408
+ return {
409
+ type: "mdxjsEsm",
410
+ value: "",
411
+ data: {
412
+ estree: {
413
+ type: "Program",
414
+ sourceType: "module",
415
+ body: [
416
+ {
417
+ type: "ExportNamedDeclaration",
418
+ attributes: [],
419
+ specifiers: [],
420
+ source: null,
421
+ declaration: {
422
+ type: "VariableDeclaration",
423
+ kind: "let",
424
+ declarations: [
425
+ {
426
+ type: "VariableDeclarator",
427
+ id: {
428
+ type: "Identifier",
429
+ name
430
+ },
431
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
432
+ }
433
+ ]
434
+ }
435
+ }
436
+ ]
437
+ }
438
+ }
439
+ };
440
+ }
441
+ function flattenNode2(node) {
442
+ if ("children" in node)
443
+ return node.children.map((child) => flattenNode2(child)).join("");
444
+ if ("value" in node) return node.value;
445
+ return "";
446
+ }
447
+
448
+ // src/mdx/build-mdx.ts
449
+ var cache = /* @__PURE__ */ new Map();
436
450
  async function buildMDX(cacheKey, source, options) {
437
451
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
438
452
  function getProcessor(format) {
439
453
  const key = `${cacheKey}:${format}`;
440
- let processor = cache2.get(key);
454
+ let processor = cache.get(key);
441
455
  if (!processor) {
442
456
  processor = (0, import_mdx.createProcessor)({
443
457
  outputFormat: "program",
444
458
  ...rest,
445
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
459
+ remarkPlugins: [
460
+ remarkInclude,
461
+ ...rest.remarkPlugins ?? [],
462
+ [
463
+ remarkPostprocess,
464
+ {
465
+ ...options.postprocess,
466
+ valueToExport: [
467
+ ...options.postprocess?.valueToExport ?? [],
468
+ "structuredData",
469
+ "extractedReferences",
470
+ "frontmatter",
471
+ "lastModified",
472
+ "_markdown"
473
+ ]
474
+ }
475
+ ]
476
+ ],
446
477
  format
447
478
  });
448
- cache2.set(key, processor);
479
+ cache.set(key, processor);
449
480
  }
450
481
  return processor;
451
482
  }
@@ -463,7 +494,7 @@ async function buildMDX(cacheKey, source, options) {
463
494
  });
464
495
  }
465
496
 
466
- // src/runtime/async.ts
497
+ // src/runtime/next/async.ts
467
498
  var import_client = require("@fumadocs/mdx-remote/client");
468
499
  var import_node_url = require("url");
469
500
 
@@ -503,7 +534,7 @@ function buildConfig(config) {
503
534
  const input = this.global.mdxOptions;
504
535
  async function uncached() {
505
536
  const options = typeof input === "function" ? await input() : input;
506
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
537
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
507
538
  if (options?.preset === "minimal") return options;
508
539
  return getDefaultMDXOptions2({
509
540
  ...options,
@@ -517,42 +548,59 @@ function buildConfig(config) {
517
548
  };
518
549
  }
519
550
 
520
- // src/runtime/async.ts
521
- async function getOptions(config, collection) {
551
+ // src/runtime/next/async.ts
552
+ function getDocCollection(config, collection) {
522
553
  const col = config.collections.get(collection);
523
- if (col?.type === "doc" && col.mdxOptions) return col.mdxOptions;
524
- if (col?.type === "docs" && col.docs.mdxOptions) return col.docs.mdxOptions;
525
- return config.getDefaultMDXOptions("remote");
554
+ if (col?.type === "doc" && col.mdxOptions) return col;
555
+ if (col?.type === "docs" && col.docs.mdxOptions) return col.docs;
556
+ }
557
+ async function getOptions(config, collection) {
558
+ return collection?.mdxOptions ?? await config.getDefaultMDXOptions("remote");
526
559
  }
527
560
  var _runtimeAsync = {
528
- doc(files, collection, config) {
561
+ doc(files, collectionName, config) {
562
+ const collection = getDocCollection(config, collectionName);
529
563
  const initMdxOptions = getOptions(config, collection);
530
- return files.map(({ info: file, data, content, lastModified }) => {
564
+ return files.map(({ info, data, content, lastModified }) => {
565
+ let cachedResult;
566
+ async function compileAndLoad() {
567
+ if (cachedResult) return cachedResult;
568
+ const mdxOptions = await initMdxOptions;
569
+ const compiled = await buildMDX(collectionName, content.body, {
570
+ ...mdxOptions,
571
+ development: false,
572
+ frontmatter: data,
573
+ postprocess: collection?.postprocess,
574
+ data: {
575
+ lastModified
576
+ },
577
+ filePath: info.fullPath
578
+ });
579
+ const result = await (0, import_client.executeMdx)(String(compiled.value), {
580
+ baseUrl: (0, import_node_url.pathToFileURL)(info.fullPath)
581
+ });
582
+ return cachedResult = result;
583
+ }
531
584
  return {
532
585
  ...data,
533
- _file: file,
534
- get content() {
535
- return `${content.matter}${content.body}`;
586
+ info,
587
+ async getText(type) {
588
+ if (type === "raw") {
589
+ return `${content.matter}${content.body}`;
590
+ }
591
+ const out = await compileAndLoad();
592
+ if (typeof out._markdown !== "string") missingProcessedMarkdown();
593
+ return out._markdown;
536
594
  },
537
595
  async load() {
538
- const mdxOptions = await initMdxOptions;
539
- const out = await buildMDX(collection, content.body, {
540
- ...mdxOptions,
541
- development: false,
542
- frontmatter: data,
543
- data: {
544
- lastModified
545
- },
546
- filePath: file.absolutePath
547
- });
548
- const { default: body, ...rest } = await (0, import_client.executeMdx)(String(out), {
549
- baseUrl: (0, import_node_url.pathToFileURL)(file.absolutePath)
550
- });
596
+ const out = await compileAndLoad();
551
597
  return {
552
- structuredData: out.data.structuredData,
553
- body,
554
- ...rest,
555
- lastModified
598
+ _exports: out,
599
+ body: out.default,
600
+ lastModified,
601
+ toc: out.toc,
602
+ extractedReferences: out.extractedReferences,
603
+ structuredData: out.structuredData
556
604
  };
557
605
  }
558
606
  };
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DT83Ijs6.cjs';
1
+ import { L as LoadedConfig, c as RuntimeAsync } from '../../types-Dl8HLbm5.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-BH4bnHQl.cjs';
4
+ import '../../define--6HQ1ehX.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../build-mdx-DnC1jKvn.cjs';
9
+ import '../../shared-CqgMnt9h.cjs';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DN9KrG7R.js';
1
+ import { L as LoadedConfig, c as RuntimeAsync } from '../../types-DLIAvrgC.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-BH4bnHQl.js';
4
+ import '../../define--6HQ1ehX.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../build-mdx-DnC1jKvn.js';
9
+ import '../../shared-0QIuV0XZ.js';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -0,0 +1,92 @@
1
+ import {
2
+ _runtime,
3
+ createMDXSource
4
+ } from "../../chunk-AUOOMFAI.js";
5
+ import {
6
+ missingProcessedMarkdown
7
+ } from "../../chunk-ZLCSVXCD.js";
8
+ import {
9
+ buildMDX
10
+ } from "../../chunk-SWNOXPYJ.js";
11
+ import "../../chunk-KTDVTBMH.js";
12
+ import {
13
+ buildConfig
14
+ } from "../../chunk-YC25YEBF.js";
15
+ import "../../chunk-VWJKRQZR.js";
16
+
17
+ // src/runtime/next/async.ts
18
+ import { executeMdx } from "@fumadocs/mdx-remote/client";
19
+ import { pathToFileURL } from "url";
20
+ function getDocCollection(config, collection) {
21
+ const col = config.collections.get(collection);
22
+ if (col?.type === "doc" && col.mdxOptions) return col;
23
+ if (col?.type === "docs" && col.docs.mdxOptions) return col.docs;
24
+ }
25
+ async function getOptions(config, collection) {
26
+ return collection?.mdxOptions ?? await config.getDefaultMDXOptions("remote");
27
+ }
28
+ var _runtimeAsync = {
29
+ doc(files, collectionName, config) {
30
+ const collection = getDocCollection(config, collectionName);
31
+ const initMdxOptions = getOptions(config, collection);
32
+ return files.map(({ info, data, content, lastModified }) => {
33
+ let cachedResult;
34
+ async function compileAndLoad() {
35
+ if (cachedResult) return cachedResult;
36
+ const mdxOptions = await initMdxOptions;
37
+ const compiled = await buildMDX(collectionName, content.body, {
38
+ ...mdxOptions,
39
+ development: false,
40
+ frontmatter: data,
41
+ postprocess: collection?.postprocess,
42
+ data: {
43
+ lastModified
44
+ },
45
+ filePath: info.fullPath
46
+ });
47
+ const result = await executeMdx(String(compiled.value), {
48
+ baseUrl: pathToFileURL(info.fullPath)
49
+ });
50
+ return cachedResult = result;
51
+ }
52
+ return {
53
+ ...data,
54
+ info,
55
+ async getText(type) {
56
+ if (type === "raw") {
57
+ return `${content.matter}${content.body}`;
58
+ }
59
+ const out = await compileAndLoad();
60
+ if (typeof out._markdown !== "string") missingProcessedMarkdown();
61
+ return out._markdown;
62
+ },
63
+ async load() {
64
+ const out = await compileAndLoad();
65
+ return {
66
+ _exports: out,
67
+ body: out.default,
68
+ lastModified,
69
+ toc: out.toc,
70
+ extractedReferences: out.extractedReferences,
71
+ structuredData: out.structuredData
72
+ };
73
+ }
74
+ };
75
+ });
76
+ },
77
+ docs(docs, metas, collection, config) {
78
+ const parsedDocs = this.doc(docs, collection, config);
79
+ const parsedMetas = _runtime.meta(metas);
80
+ return {
81
+ docs: parsedDocs,
82
+ meta: parsedMetas,
83
+ toFumadocsSource() {
84
+ return createMDXSource(parsedDocs, parsedMetas);
85
+ }
86
+ };
87
+ }
88
+ };
89
+ export {
90
+ _runtimeAsync,
91
+ buildConfig
92
+ };