fumadocs-mdx 13.0.8 → 14.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 (104) hide show
  1. package/dist/bin.cjs +924 -901
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +578 -471
  5. package/dist/bun/index.d.cts +3 -2
  6. package/dist/bun/index.d.ts +3 -2
  7. package/dist/bun/index.js +12 -12
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5UMZCWKV.js +17 -0
  10. package/dist/chunk-5YXP7JLN.js +138 -0
  11. package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
  12. package/dist/chunk-7L2KNF6B.js +180 -0
  13. package/dist/chunk-E5DJTSIM.js +86 -0
  14. package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
  15. package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
  16. package/dist/chunk-PKI7ZDA5.js +29 -0
  17. package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
  18. package/dist/{chunk-5FTSWCB4.js → chunk-SRSRFOVI.js} +8 -10
  19. package/dist/chunk-TYJDYTKH.js +85 -0
  20. package/dist/chunk-XHJCLBZ4.js +406 -0
  21. package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
  22. package/dist/config/index.cjs +79 -71
  23. package/dist/config/index.d.cts +2 -1
  24. package/dist/config/index.d.ts +2 -1
  25. package/dist/config/index.js +5 -5
  26. package/dist/index-BlVBvy-z.d.ts +8 -0
  27. package/dist/{core-DB7TdlyC.d.cts → index-D7JdSMpp.d.cts} +99 -61
  28. package/dist/{core-DB7TdlyC.d.ts → index-D7JdSMpp.d.ts} +99 -61
  29. package/dist/index-P2NNUkHn.d.cts +8 -0
  30. package/dist/index.d.cts +3 -74
  31. package/dist/index.d.ts +3 -74
  32. package/dist/load-from-file-I3ALLIVB.js +8 -0
  33. package/dist/next/index.cjs +698 -476
  34. package/dist/next/index.d.cts +11 -1
  35. package/dist/next/index.d.ts +11 -1
  36. package/dist/next/index.js +78 -281
  37. package/dist/node/loader.cjs +704 -602
  38. package/dist/node/loader.js +10 -11
  39. package/dist/plugins/index-file.cjs +471 -0
  40. package/dist/plugins/index-file.d.cts +29 -0
  41. package/dist/plugins/index-file.d.ts +29 -0
  42. package/dist/plugins/index-file.js +8 -0
  43. package/dist/plugins/json-schema.d.cts +3 -2
  44. package/dist/plugins/json-schema.d.ts +3 -2
  45. package/dist/plugins/last-modified.cjs +75 -0
  46. package/dist/plugins/last-modified.d.cts +27 -0
  47. package/dist/plugins/last-modified.d.ts +27 -0
  48. package/dist/plugins/last-modified.js +44 -0
  49. package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
  50. package/dist/runtime/browser.d.cts +50 -0
  51. package/dist/runtime/browser.d.ts +50 -0
  52. package/dist/runtime/browser.js +68 -0
  53. package/dist/runtime/dynamic.cjs +985 -0
  54. package/dist/runtime/dynamic.d.cts +27 -0
  55. package/dist/runtime/dynamic.d.ts +27 -0
  56. package/dist/runtime/dynamic.js +78 -0
  57. package/dist/runtime/server.cjs +173 -0
  58. package/dist/runtime/server.d.cts +161 -0
  59. package/dist/runtime/server.d.ts +161 -0
  60. package/dist/runtime/server.js +8 -0
  61. package/dist/vite/index.cjs +934 -638
  62. package/dist/vite/index.d.cts +12 -22
  63. package/dist/vite/index.d.ts +12 -22
  64. package/dist/vite/index.js +30 -221
  65. package/dist/webpack/mdx.cjs +613 -515
  66. package/dist/webpack/mdx.d.cts +9 -1
  67. package/dist/webpack/mdx.d.ts +9 -1
  68. package/dist/webpack/mdx.js +12 -17
  69. package/dist/webpack/meta.cjs +327 -233
  70. package/dist/webpack/meta.d.cts +9 -1
  71. package/dist/webpack/meta.d.ts +9 -1
  72. package/dist/webpack/meta.js +13 -15
  73. package/package.json +15 -32
  74. package/dist/build-mdx-BjXOmv0b.d.cts +0 -53
  75. package/dist/build-mdx-CY5UldCO.d.ts +0 -53
  76. package/dist/chunk-2AQRQXSO.js +0 -119
  77. package/dist/chunk-CXA4JO4Z.js +0 -45
  78. package/dist/chunk-DMJ6I4C3.js +0 -76
  79. package/dist/chunk-FSZMKRVH.js +0 -80
  80. package/dist/chunk-II3H5ZVZ.js +0 -77
  81. package/dist/chunk-KILFIBVW.js +0 -75
  82. package/dist/chunk-NVRDCY6Z.js +0 -30
  83. package/dist/chunk-VUEZTR2H.js +0 -26
  84. package/dist/index-D7s7kCc2.d.cts +0 -7
  85. package/dist/index-D7s7kCc2.d.ts +0 -7
  86. package/dist/load-from-file-AVYOFOI7.js +0 -7
  87. package/dist/preset-ZMP6U62C.js +0 -6
  88. package/dist/runtime/next/async.cjs +0 -760
  89. package/dist/runtime/next/async.d.cts +0 -19
  90. package/dist/runtime/next/async.d.ts +0 -19
  91. package/dist/runtime/next/async.js +0 -86
  92. package/dist/runtime/next/index.cjs +0 -136
  93. package/dist/runtime/next/index.d.cts +0 -33
  94. package/dist/runtime/next/index.d.ts +0 -33
  95. package/dist/runtime/next/index.js +0 -11
  96. package/dist/runtime/vite/browser.d.cts +0 -59
  97. package/dist/runtime/vite/browser.d.ts +0 -59
  98. package/dist/runtime/vite/browser.js +0 -11
  99. package/dist/runtime/vite/server.cjs +0 -243
  100. package/dist/runtime/vite/server.d.cts +0 -30
  101. package/dist/runtime/vite/server.d.ts +0 -30
  102. package/dist/runtime/vite/server.js +0 -111
  103. package/dist/types-Bnh9n7mj.d.cts +0 -45
  104. package/dist/types-ey1AZqrg.d.ts +0 -45
@@ -0,0 +1,406 @@
1
+ import {
2
+ readFileWithCache
3
+ } from "./chunk-PKI7ZDA5.js";
4
+ import {
5
+ fumaMatter
6
+ } from "./chunk-VWJKRQZR.js";
7
+
8
+ // src/plugins/index-file.ts
9
+ import path2 from "path";
10
+
11
+ // src/utils/codegen/index.ts
12
+ import path from "path";
13
+ import { glob } from "tinyglobby";
14
+ function createCodegen({
15
+ target = "default",
16
+ outDir = "",
17
+ jsExtension = false,
18
+ globCache = /* @__PURE__ */ new Map()
19
+ }) {
20
+ let eagerImportId = 0;
21
+ const banner = ["// @ts-nocheck"];
22
+ if (target === "vite") {
23
+ banner.push('/// <reference types="vite/client" />');
24
+ }
25
+ return {
26
+ options: {
27
+ target,
28
+ outDir
29
+ },
30
+ lines: [],
31
+ addImport(statement) {
32
+ this.lines.unshift(statement);
33
+ },
34
+ async pushAsync(insert) {
35
+ for (const line of await Promise.all(insert)) {
36
+ if (line === void 0) continue;
37
+ this.lines.push(line);
38
+ }
39
+ },
40
+ async generateGlobImport(patterns, options) {
41
+ if (target === "vite") {
42
+ return this.generateViteGlobImport(patterns, options);
43
+ }
44
+ return this.generateNodeGlobImport(patterns, options);
45
+ },
46
+ generateViteGlobImport(patterns, { base, ...rest }) {
47
+ patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
48
+ normalizeViteGlobPath
49
+ );
50
+ return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
51
+ {
52
+ base: normalizeViteGlobPath(path.relative(outDir, base)),
53
+ ...rest
54
+ },
55
+ null,
56
+ 2
57
+ )})`;
58
+ },
59
+ async generateNodeGlobImport(patterns, {
60
+ base,
61
+ eager = false,
62
+ query = {},
63
+ import: importName
64
+ }) {
65
+ const cacheKey = JSON.stringify({ patterns, base });
66
+ let files = globCache.get(cacheKey);
67
+ if (!files) {
68
+ files = glob(patterns, {
69
+ cwd: base
70
+ });
71
+ globCache.set(cacheKey, files);
72
+ }
73
+ let code = "{";
74
+ for (const item of await files) {
75
+ const fullPath = path.join(base, item);
76
+ const searchParams = new URLSearchParams();
77
+ for (const [k, v] of Object.entries(query)) {
78
+ searchParams.set(k, v);
79
+ }
80
+ const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
81
+ if (eager) {
82
+ const name = `__fd_glob_${eagerImportId++}`;
83
+ this.lines.unshift(
84
+ importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
85
+ );
86
+ code += `${JSON.stringify(item)}: ${name}, `;
87
+ } else {
88
+ let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
89
+ if (importName) {
90
+ line += `.then(mod => mod.${importName})`;
91
+ }
92
+ code += `${line}, `;
93
+ }
94
+ }
95
+ code += "}";
96
+ return code;
97
+ },
98
+ formatImportPath(file) {
99
+ const ext = path.extname(file);
100
+ let filename;
101
+ if (ext === ".ts" && jsExtension) {
102
+ filename = file.substring(0, file.length - ext.length) + ".js";
103
+ } else if (ext === ".ts") {
104
+ filename = file.substring(0, file.length - ext.length);
105
+ } else {
106
+ filename = file;
107
+ }
108
+ const importPath = slash(path.relative(outDir, filename));
109
+ return importPath.startsWith(".") ? importPath : `./${importPath}`;
110
+ },
111
+ toString() {
112
+ return [...banner, ...this.lines].join("\n");
113
+ }
114
+ };
115
+ }
116
+ function normalizeViteGlobPath(file) {
117
+ file = slash(file);
118
+ if (file.startsWith("./")) return file;
119
+ if (file.startsWith("/")) return `.${file}`;
120
+ return `./${file}`;
121
+ }
122
+ function slash(path3) {
123
+ const isExtendedLengthPath = path3.startsWith("\\\\?\\");
124
+ if (isExtendedLengthPath) {
125
+ return path3;
126
+ }
127
+ return path3.replaceAll("\\", "/");
128
+ }
129
+ function ident(code, tab = 1) {
130
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
131
+ }
132
+
133
+ // src/plugins/index-file.ts
134
+ import { glob as glob2 } from "tinyglobby";
135
+ import { createHash } from "crypto";
136
+ function indexFile(options = {}) {
137
+ const {
138
+ target = "default",
139
+ addJsExtension,
140
+ browser = true,
141
+ dynamic = true
142
+ } = options;
143
+ let config;
144
+ let dynamicCollections;
145
+ function isDynamic(collection) {
146
+ return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
147
+ }
148
+ return {
149
+ name: "index-file",
150
+ config(v) {
151
+ config = v;
152
+ dynamicCollections = config.collectionList.filter(isDynamic);
153
+ },
154
+ configureServer(server) {
155
+ if (!server.watcher) return;
156
+ server.watcher.on("all", async (event, file) => {
157
+ if (dynamicCollections.length === 0) {
158
+ if (target === "vite") return;
159
+ if (target === "default" && event === "change") return;
160
+ }
161
+ const updatedCollection = config.collectionList.find(
162
+ (collection) => collection.hasFile(file)
163
+ );
164
+ if (!updatedCollection) return;
165
+ if (!isDynamic(updatedCollection)) {
166
+ if (target === "vite") return;
167
+ if (target === "default" && event === "change") return;
168
+ }
169
+ await this.core.emitAndWrite({
170
+ filterPlugin: (plugin) => plugin.name === "index-file"
171
+ });
172
+ });
173
+ },
174
+ async emit() {
175
+ const globCache = /* @__PURE__ */ new Map();
176
+ const makeCodeGen = () => createCodegen({
177
+ target,
178
+ outDir: this.outDir,
179
+ jsExtension: addJsExtension,
180
+ globCache
181
+ });
182
+ async function toEmitEntry(path3, content) {
183
+ return {
184
+ path: path3,
185
+ content: await content
186
+ };
187
+ }
188
+ const out = [
189
+ toEmitEntry(
190
+ "server.ts",
191
+ generateServerIndexFile(makeCodeGen(), config, this.configPath)
192
+ )
193
+ ];
194
+ if (dynamic)
195
+ out.push(
196
+ toEmitEntry(
197
+ "dynamic.ts",
198
+ generateDynamicIndexFile(this.core, makeCodeGen())
199
+ )
200
+ );
201
+ if (browser)
202
+ out.push(
203
+ toEmitEntry(
204
+ "browser.ts",
205
+ generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
206
+ )
207
+ );
208
+ return await Promise.all(out);
209
+ }
210
+ };
211
+ }
212
+ async function generateServerIndexFile(codegen, config, configPath) {
213
+ codegen.lines.push(
214
+ `import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
215
+ `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
216
+ "",
217
+ `const create = fromConfig<typeof Config>();`
218
+ );
219
+ async function generateCollectionObject(collection) {
220
+ switch (collection.type) {
221
+ case "docs": {
222
+ if (collection.docs.dynamic) return;
223
+ if (collection.docs.async) {
224
+ const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
225
+ generateMetaCollectionGlob(codegen, collection.meta, true),
226
+ generateDocCollectionFrontmatterGlob(
227
+ codegen,
228
+ collection.docs,
229
+ true
230
+ ),
231
+ generateDocCollectionGlob(codegen, collection.docs)
232
+ ]);
233
+ return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
234
+ }
235
+ const [metaGlob, docGlob] = await Promise.all([
236
+ generateMetaCollectionGlob(codegen, collection.meta, true),
237
+ generateDocCollectionGlob(codegen, collection.docs, true)
238
+ ]);
239
+ return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
240
+ }
241
+ case "doc":
242
+ if (collection.dynamic) return;
243
+ if (collection.async) {
244
+ const [headGlob, bodyGlob] = await Promise.all([
245
+ generateDocCollectionFrontmatterGlob(codegen, collection, true),
246
+ generateDocCollectionGlob(codegen, collection)
247
+ ]);
248
+ return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
249
+ }
250
+ return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
251
+ codegen,
252
+ collection,
253
+ true
254
+ )})`;
255
+ case "meta":
256
+ return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
257
+ codegen,
258
+ collection,
259
+ true
260
+ )})`;
261
+ }
262
+ }
263
+ await codegen.pushAsync(
264
+ config.collectionList.map(async (collection) => {
265
+ const obj = await generateCollectionObject(collection);
266
+ if (!obj) return;
267
+ return `
268
+ export const ${collection.name} = ${obj};`;
269
+ })
270
+ );
271
+ return codegen.toString();
272
+ }
273
+ async function generateDynamicIndexFile(core, codegen) {
274
+ const { configPath } = core._options;
275
+ codegen.lines.push(
276
+ `import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
277
+ `import * as Config from '${codegen.formatImportPath(configPath)}';`,
278
+ "",
279
+ `const create = await fromConfigDynamic(Config);`
280
+ );
281
+ async function generateCollectionObjectEntry(collection, file) {
282
+ const fullPath = path2.join(collection.dir, file);
283
+ const content = await readFileWithCache(fullPath).catch(() => "");
284
+ const parsed = fumaMatter(content);
285
+ const data = await core.transformFrontmatter(
286
+ {
287
+ collection,
288
+ filePath: fullPath,
289
+ source: content
290
+ },
291
+ parsed.data
292
+ );
293
+ const hash = createHash("md5").update(content).digest("hex");
294
+ const infoStr = [
295
+ // make sure it's included in vercel/nft
296
+ `absolutePath: path.resolve(${JSON.stringify(fullPath)})`
297
+ ];
298
+ for (const [k, v] of Object.entries({
299
+ info: {
300
+ fullPath,
301
+ path: file
302
+ },
303
+ data,
304
+ hash
305
+ })) {
306
+ infoStr.push(`${k}: ${JSON.stringify(v)}`);
307
+ }
308
+ return `{ ${infoStr.join(", ")} }`;
309
+ }
310
+ async function generateCollectionObject(parent) {
311
+ let collection;
312
+ if (parent.type === "doc") collection = parent;
313
+ else if (parent.type === "docs") collection = parent.docs;
314
+ if (!collection || !collection.dynamic) return;
315
+ const files = await glob2(collection.patterns, {
316
+ cwd: collection.dir
317
+ });
318
+ const entries = await Promise.all(
319
+ files.map((file) => generateCollectionObjectEntry(collection, file))
320
+ );
321
+ switch (parent.type) {
322
+ case "docs": {
323
+ const metaGlob = await generateMetaCollectionGlob(
324
+ codegen,
325
+ parent.meta,
326
+ true
327
+ );
328
+ return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
329
+ }
330
+ case "doc":
331
+ return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
332
+ }
333
+ }
334
+ await codegen.pushAsync(
335
+ core.getConfig().collectionList.map(async (collection) => {
336
+ const obj = await generateCollectionObject(collection);
337
+ if (!obj) return;
338
+ return `
339
+ export const ${collection.name} = ${obj};`;
340
+ })
341
+ );
342
+ return codegen.toString();
343
+ }
344
+ async function generateBrowserIndexFile(codegen, config, configPath) {
345
+ codegen.lines.push(
346
+ `import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
347
+ `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
348
+ "",
349
+ `const create = fromConfig<typeof Config>();`
350
+ );
351
+ async function generateCollectionObject(collection) {
352
+ switch (collection.type) {
353
+ case "docs": {
354
+ if (collection.docs.dynamic) return;
355
+ return generateCollectionObject(collection.docs);
356
+ }
357
+ case "doc":
358
+ if (collection.dynamic) return;
359
+ return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
360
+ }
361
+ }
362
+ codegen.lines.push("const browserCollections = {");
363
+ await codegen.pushAsync(
364
+ config.collectionList.map(async (collection) => {
365
+ const obj = await generateCollectionObject(collection);
366
+ if (!obj) return;
367
+ return ident(`${collection.name}: ${obj},`);
368
+ })
369
+ );
370
+ codegen.lines.push("};", "export default browserCollections;");
371
+ return codegen.toString();
372
+ }
373
+ function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
374
+ return codegen.generateGlobImport(collection.patterns, {
375
+ query: {
376
+ collection: collection.name,
377
+ only: "frontmatter"
378
+ },
379
+ import: "frontmatter",
380
+ base: collection.dir,
381
+ eager
382
+ });
383
+ }
384
+ function generateDocCollectionGlob(codegen, collection, eager = false) {
385
+ return codegen.generateGlobImport(collection.patterns, {
386
+ query: {
387
+ collection: collection.name
388
+ },
389
+ base: collection.dir,
390
+ eager
391
+ });
392
+ }
393
+ function generateMetaCollectionGlob(codegen, collection, eager = false) {
394
+ return codegen.generateGlobImport(collection.patterns, {
395
+ query: {
396
+ collection: collection.name
397
+ },
398
+ import: "default",
399
+ base: collection.dir,
400
+ eager
401
+ });
402
+ }
403
+
404
+ export {
405
+ indexFile
406
+ };
@@ -1,3 +1,7 @@
1
+ import {
2
+ applyMdxPreset
3
+ } from "./chunk-E5DJTSIM.js";
4
+
1
5
  // src/config/build.ts
2
6
  import picomatch from "picomatch";
3
7
  var SupportedFormats = {
@@ -10,7 +14,10 @@ function buildCollection(name, config) {
10
14
  ...config,
11
15
  name,
12
16
  meta: buildPrimitiveCollection(name, config.meta),
13
- docs: buildPrimitiveCollection(name, config.docs)
17
+ docs: buildPrimitiveCollection(name, config.docs),
18
+ hasFile(filePath) {
19
+ return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
20
+ }
14
21
  };
15
22
  }
16
23
  return buildPrimitiveCollection(name, config);
@@ -64,11 +71,6 @@ function buildConfig(config) {
64
71
  `Unknown export "${k}", you can only export collections from source configuration file.`
65
72
  );
66
73
  }
67
- if (loaded.collections) {
68
- for (const [k, v] of Object.entries(loaded.collections)) {
69
- collections.set(k, buildCollection(k, v));
70
- }
71
- }
72
74
  const mdxOptionsCache = /* @__PURE__ */ new Map();
73
75
  return {
74
76
  global: loaded,
@@ -76,21 +78,22 @@ function buildConfig(config) {
76
78
  getCollection(name) {
77
79
  return collections.get(name);
78
80
  },
79
- async getDefaultMDXOptions(mode = "default") {
80
- const cached = mdxOptionsCache.get(mode);
81
+ getMDXOptions(collection, environment = "bundler") {
82
+ const key = collection ? `${environment}:${collection.name}` : environment;
83
+ const cached = mdxOptionsCache.get(key);
81
84
  if (cached) return cached;
82
- const input = this.global.mdxOptions;
83
- async function uncached() {
84
- const options = typeof input === "function" ? await input() : input;
85
- const { getDefaultMDXOptions } = await import("./preset-ZMP6U62C.js");
86
- if (options?.preset === "minimal") return options;
87
- return getDefaultMDXOptions({
88
- ...options,
89
- _withoutBundler: mode === "remote"
90
- });
85
+ let result;
86
+ if (collection?.mdxOptions) {
87
+ const optionsFn = collection.mdxOptions;
88
+ result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
89
+ } else {
90
+ result = (async () => {
91
+ const optionsFn = this.global.mdxOptions;
92
+ const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
93
+ return applyMdxPreset(options)(environment);
94
+ })();
91
95
  }
92
- const result = uncached();
93
- mdxOptionsCache.set(mode, result);
96
+ mdxOptionsCache.set(key, result);
94
97
  return result;
95
98
  }
96
99
  };
@@ -30,11 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/config/index.ts
31
31
  var config_exports = {};
32
32
  __export(config_exports, {
33
+ applyMdxPreset: () => applyMdxPreset,
33
34
  defineCollections: () => defineCollections,
34
35
  defineConfig: () => defineConfig,
35
36
  defineDocs: () => defineDocs,
36
37
  frontmatterSchema: () => frontmatterSchema,
37
- getDefaultMDXOptions: () => getDefaultMDXOptions,
38
38
  metaSchema: () => metaSchema,
39
39
  remarkInclude: () => remarkInclude
40
40
  });
@@ -86,8 +86,7 @@ function defineConfig(config = {}) {
86
86
  return config;
87
87
  }
88
88
 
89
- // src/loaders/mdx/preset.ts
90
- var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
89
+ // src/config/preset.ts
91
90
  function pluginOption(def, options = []) {
92
91
  const list = def(Array.isArray(options) ? options : []).filter(
93
92
  Boolean
@@ -97,69 +96,76 @@ function pluginOption(def, options = []) {
97
96
  }
98
97
  return list;
99
98
  }
100
- function getDefaultMDXOptions({
101
- valueToExport = [],
102
- rehypeCodeOptions,
103
- remarkImageOptions,
104
- remarkHeadingOptions,
105
- remarkStructureOptions,
106
- remarkCodeTabOptions,
107
- remarkNpmOptions,
108
- _withoutBundler = false,
109
- ...mdxOptions
110
- }) {
111
- const remarkPlugins = pluginOption(
112
- (v) => [
113
- plugins.remarkGfm,
114
- [
115
- plugins.remarkHeading,
116
- {
117
- generateToc: false,
118
- ...remarkHeadingOptions
119
- }
120
- ],
121
- remarkImageOptions !== false && [
122
- plugins.remarkImage,
123
- {
124
- ...remarkImageOptions,
125
- useImport: _withoutBundler ? false : remarkImageOptions?.useImport
126
- }
127
- ],
128
- "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
129
- plugins.remarkCodeTab,
130
- remarkCodeTabOptions
99
+ function applyMdxPreset(options = {}) {
100
+ return async (environment = "bundler") => {
101
+ if (options.preset === "minimal") return options;
102
+ const plugins = await import("fumadocs-core/mdx-plugins");
103
+ const {
104
+ valueToExport = [],
105
+ rehypeCodeOptions,
106
+ remarkImageOptions,
107
+ remarkHeadingOptions,
108
+ remarkStructureOptions,
109
+ remarkCodeTabOptions,
110
+ remarkNpmOptions,
111
+ ...mdxOptions
112
+ } = options;
113
+ const remarkPlugins = pluginOption(
114
+ (v) => [
115
+ plugins.remarkGfm,
116
+ [
117
+ plugins.remarkHeading,
118
+ {
119
+ generateToc: false,
120
+ ...remarkHeadingOptions
121
+ }
122
+ ],
123
+ remarkImageOptions !== false && [
124
+ plugins.remarkImage,
125
+ {
126
+ ...remarkImageOptions,
127
+ useImport: remarkImageOptions?.useImport ?? environment === "bundler"
128
+ }
129
+ ],
130
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
131
+ plugins.remarkCodeTab,
132
+ remarkCodeTabOptions
133
+ ],
134
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
135
+ ...v,
136
+ remarkStructureOptions !== false && [
137
+ plugins.remarkStructure,
138
+ remarkStructureOptions
139
+ ],
140
+ valueToExport.length > 0 && (() => {
141
+ return (_, file) => {
142
+ file.data["mdx-export"] ??= [];
143
+ for (const name of valueToExport) {
144
+ if (!(name in file.data)) continue;
145
+ file.data["mdx-export"].push({
146
+ name,
147
+ value: file.data[name]
148
+ });
149
+ }
150
+ };
151
+ })
131
152
  ],
132
- "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
133
- ...v,
134
- remarkStructureOptions !== false && [
135
- plugins.remarkStructure,
136
- remarkStructureOptions
153
+ mdxOptions.remarkPlugins
154
+ );
155
+ const rehypePlugins = pluginOption(
156
+ (v) => [
157
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
158
+ ...v,
159
+ plugins.rehypeToc
137
160
  ],
138
- () => {
139
- return (_, file) => {
140
- file.data["mdx-export"] ??= [];
141
- for (const name of valueToExport) {
142
- if (name in file.data)
143
- file.data["mdx-export"].push({ name, value: file.data[name] });
144
- }
145
- };
146
- }
147
- ],
148
- mdxOptions.remarkPlugins
149
- );
150
- const rehypePlugins = pluginOption(
151
- (v) => [
152
- rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
153
- ...v,
154
- plugins.rehypeToc
155
- ],
156
- mdxOptions.rehypePlugins
157
- );
158
- return {
159
- ...mdxOptions,
160
- outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
161
- remarkPlugins,
162
- rehypePlugins
161
+ mdxOptions.rehypePlugins
162
+ );
163
+ return {
164
+ ...mdxOptions,
165
+ outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
166
+ remarkPlugins,
167
+ rehypePlugins
168
+ };
163
169
  };
164
170
  }
165
171
 
@@ -232,6 +238,14 @@ function remarkMarkAndUnravel() {
232
238
  };
233
239
  }
234
240
 
241
+ // src/loaders/mdx/mdast-utils.ts
242
+ function flattenNode(node) {
243
+ if ("children" in node)
244
+ return node.children.map((child) => flattenNode(child)).join("");
245
+ if ("value" in node) return node.value;
246
+ return "";
247
+ }
248
+
235
249
  // src/loaders/mdx/remark-include.ts
236
250
  var ElementLikeTypes = [
237
251
  "mdxJsxFlowElement",
@@ -255,12 +269,6 @@ function parseElementAttributes(element) {
255
269
  }
256
270
  return element.attributes ?? {};
257
271
  }
258
- function flattenNode(node) {
259
- if ("children" in node)
260
- return node.children.map((child) => flattenNode(child)).join("");
261
- if ("value" in node) return node.value;
262
- return "";
263
- }
264
272
  function parseSpecifier(specifier) {
265
273
  const idx = specifier.lastIndexOf("#");
266
274
  if (idx === -1) return { file: specifier };
@@ -382,11 +390,11 @@ ${e instanceof Error ? e.message : String(e)}`,
382
390
  }
383
391
  // Annotate the CommonJS export names for ESM import in node:
384
392
  0 && (module.exports = {
393
+ applyMdxPreset,
385
394
  defineCollections,
386
395
  defineConfig,
387
396
  defineDocs,
388
397
  frontmatterSchema,
389
- getDefaultMDXOptions,
390
398
  metaSchema,
391
399
  remarkInclude
392
400
  });
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, D as DefaultMDXOptions, b as DocCollection, c as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, f as defineConfig, e as defineDocs, h as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../core-DB7TdlyC.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs, i as frontmatterSchema, m as metaSchema } from '../index-D7JdSMpp.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -6,6 +6,7 @@ import '@standard-schema/spec';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
+ import 'vfile';
9
10
 
10
11
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
11
12