fumadocs-mdx 12.0.3 → 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-OMAMTKDE.js → chunk-KILFIBVW.js} +3 -12
  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 +108 -70
  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 +25 -14
  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 +40 -34
  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 +8 -23
  64. package/dist/{types-TeHjsmja.d.ts → types-1cCFEzWt.d.ts} +3 -10
  65. package/dist/{types-BRx1QsIJ.d.cts → types-D5NhXTJY.d.cts} +3 -10
  66. package/dist/vite/index.cjs +386 -224
  67. package/dist/vite/index.d.cts +23 -10
  68. package/dist/vite/index.d.ts +23 -10
  69. package/dist/vite/index.js +211 -37
  70. package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
  71. package/package.json +28 -15
  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-CfiiRctw.d.ts +0 -70
  80. package/dist/shared-fFqiuWJC.d.cts +0 -70
@@ -3,10 +3,8 @@ import {
3
3
  } from "./chunk-U4MQ44TS.js";
4
4
 
5
5
  // src/loaders/config/load.ts
6
- import * as fs from "fs/promises";
7
6
  import * as path from "path";
8
7
  import { pathToFileURL } from "url";
9
- var cache = null;
10
8
  async function compileConfig(configPath, outDir) {
11
9
  const { build } = await import("esbuild");
12
10
  const transformed = await build({
@@ -27,30 +25,16 @@ async function compileConfig(configPath, outDir) {
27
25
  throw new Error("failed to compile configuration file");
28
26
  }
29
27
  }
30
- async function loadConfig(configPath, outDir, hash, build = false) {
31
- if (cache && cache.hash === hash) {
32
- return await cache.config;
33
- }
28
+ async function loadConfig(configPath, outDir, build = false) {
34
29
  if (build) await compileConfig(configPath, outDir);
35
30
  const url = pathToFileURL(path.resolve(outDir, "source.config.mjs"));
36
- const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
37
- return buildConfig(
38
- // every call to `loadConfig` will cause the previous cache to be ignored
39
- loaded
40
- );
41
- });
42
- if (hash) cache = { config, hash };
31
+ url.searchParams.set("hash", Date.now().toString());
32
+ const config = import(url.href).then(
33
+ (loaded) => buildConfig(loaded)
34
+ );
43
35
  return await config;
44
36
  }
45
- async function getConfigHash(configPath) {
46
- const stats = await fs.stat(configPath).catch(() => void 0);
47
- if (stats) {
48
- return stats.mtime.getTime().toString();
49
- }
50
- throw new Error("Cannot find config file");
51
- }
52
37
 
53
38
  export {
54
- loadConfig,
55
- getConfigHash
39
+ loadConfig
56
40
  };
@@ -4,12 +4,56 @@ import {
4
4
 
5
5
  // src/loaders/mdx/remark-include.ts
6
6
  import { unified } from "unified";
7
- import { visit } from "unist-util-visit";
7
+ import { visit as visit2 } from "unist-util-visit";
8
8
  import * as path from "path";
9
9
  import * as fs from "fs/promises";
10
- import remarkParse from "remark-parse";
11
- import remarkMdx from "remark-mdx";
12
10
  import { remarkHeading } from "fumadocs-core/mdx-plugins";
11
+
12
+ // src/loaders/mdx/remark-unravel.ts
13
+ import { visit } from "unist-util-visit";
14
+ function remarkMarkAndUnravel() {
15
+ return (tree) => {
16
+ visit(tree, function(node, index, parent) {
17
+ let offset = -1;
18
+ let all = true;
19
+ let oneOrMore = false;
20
+ if (parent && typeof index === "number" && node.type === "paragraph") {
21
+ const children = node.children;
22
+ while (++offset < children.length) {
23
+ const child = children[offset];
24
+ if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
25
+ oneOrMore = true;
26
+ } else if (child.type === "text" && child.value.trim().length === 0) {
27
+ } else {
28
+ all = false;
29
+ break;
30
+ }
31
+ }
32
+ if (all && oneOrMore) {
33
+ offset = -1;
34
+ const newChildren = [];
35
+ while (++offset < children.length) {
36
+ const child = children[offset];
37
+ if (child.type === "mdxJsxTextElement") {
38
+ child.type = "mdxJsxFlowElement";
39
+ }
40
+ if (child.type === "mdxTextExpression") {
41
+ child.type = "mdxFlowExpression";
42
+ }
43
+ if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
44
+ } else {
45
+ newChildren.push(child);
46
+ }
47
+ }
48
+ parent.children.splice(index, 1, ...newChildren);
49
+ return index;
50
+ }
51
+ }
52
+ });
53
+ };
54
+ }
55
+
56
+ // src/loaders/mdx/remark-include.ts
13
57
  var ElementLikeTypes = [
14
58
  "mdxJsxFlowElement",
15
59
  "mdxJsxTextElement",
@@ -49,7 +93,7 @@ function parseSpecifier(specifier) {
49
93
  function extractSection(root, section) {
50
94
  let nodes;
51
95
  let capturingHeadingContent = false;
52
- visit(root, (node) => {
96
+ visit2(root, (node) => {
53
97
  if (node.type === "heading") {
54
98
  if (capturingHeadingContent) {
55
99
  return false;
@@ -81,7 +125,7 @@ function extractSection(root, section) {
81
125
  }
82
126
  function remarkInclude() {
83
127
  const TagName = "include";
84
- async function embedContent(file, heading, params, data) {
128
+ const embedContent = async (file, heading, params, data) => {
85
129
  let content;
86
130
  try {
87
131
  content = (await fs.readFile(file)).toString();
@@ -104,18 +148,17 @@ ${e instanceof Error ? e.message : String(e)}`,
104
148
  data: {}
105
149
  };
106
150
  }
107
- const parser = (data._getProcessor ?? getDefaultProcessor)(
108
- ext === ".mdx" ? "mdx" : "md"
109
- );
151
+ const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
110
152
  const parsed = fumaMatter(content);
111
153
  let mdast = parser.parse({
112
154
  path: file,
113
155
  value: parsed.content,
114
156
  data: { frontmatter: parsed.data }
115
157
  });
158
+ const baseProcessor = unified().use(remarkMarkAndUnravel);
116
159
  if (heading) {
117
160
  const extracted = extractSection(
118
- await unified().use(remarkHeading).run(mdast),
161
+ await baseProcessor.use(remarkHeading).run(mdast),
119
162
  heading
120
163
  );
121
164
  if (!extracted)
@@ -123,13 +166,15 @@ ${e instanceof Error ? e.message : String(e)}`,
123
166
  `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.`
124
167
  );
125
168
  mdast = extracted;
169
+ } else {
170
+ mdast = await baseProcessor.run(mdast);
126
171
  }
127
172
  await update(mdast, path.dirname(file), data);
128
173
  return mdast;
129
- }
174
+ };
130
175
  async function update(tree, directory, data) {
131
176
  const queue = [];
132
- visit(tree, ElementLikeTypes, (_node, _, parent) => {
177
+ visit2(tree, ElementLikeTypes, (_node, _, parent) => {
133
178
  const node = _node;
134
179
  if (node.name !== TagName) return;
135
180
  const specifier = flattenNode(node);
@@ -156,11 +201,6 @@ ${e instanceof Error ? e.message : String(e)}`,
156
201
  await update(tree, path.dirname(file.path), file.data);
157
202
  };
158
203
  }
159
- function getDefaultProcessor(format) {
160
- const mdProcessor = unified().use(remarkParse);
161
- if (format === "md") return mdProcessor;
162
- return mdProcessor.use(remarkMdx);
163
- }
164
204
 
165
205
  export {
166
206
  remarkInclude
@@ -1,16 +1,13 @@
1
1
  import {
2
- missingProcessedMarkdown
3
- } from "./chunk-ZLCSVXCD.js";
2
+ createDocMethods
3
+ } from "./chunk-NVRDCY6Z.js";
4
4
 
5
5
  // src/runtime/next/index.ts
6
- import * as fs from "fs/promises";
7
6
  var _runtime = {
8
7
  doc(files) {
9
8
  return files.map((file) => {
10
9
  const data = file.data;
11
- const filePath = file.info.fullPath;
12
10
  return {
13
- info: file.info,
14
11
  _exports: data,
15
12
  body: data.default,
16
13
  lastModified: data.lastModified,
@@ -18,13 +15,7 @@ var _runtime = {
18
15
  structuredData: data.structuredData,
19
16
  extractedReferences: data.extractedReferences,
20
17
  ...data.frontmatter,
21
- async getText(type) {
22
- if (type === "raw") {
23
- return (await fs.readFile(filePath)).toString();
24
- }
25
- if (typeof data._markdown !== "string") missingProcessedMarkdown();
26
- return data._markdown;
27
- }
18
+ ...createDocMethods(file.info, () => Promise.resolve(data))
28
19
  };
29
20
  });
30
21
  },
@@ -0,0 +1,30 @@
1
+ // src/runtime/shared.ts
2
+ import fs from "fs/promises";
3
+ function createDocMethods(info, load) {
4
+ return {
5
+ info,
6
+ async getText(type) {
7
+ if (type === "raw") {
8
+ return (await fs.readFile(info.fullPath)).toString();
9
+ }
10
+ const data = await load();
11
+ if (typeof data._markdown !== "string")
12
+ throw new Error(
13
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
14
+ );
15
+ return data._markdown;
16
+ },
17
+ async getMDAST() {
18
+ const data = await load();
19
+ if (!data._mdast)
20
+ throw new Error(
21
+ "getMDAST() requires `includeMDAST` to be enabled in your collection config."
22
+ );
23
+ return JSON.parse(data._mdast);
24
+ }
25
+ };
26
+ }
27
+
28
+ export {
29
+ createDocMethods
30
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-IQAEAI4P.js";
3
+ } from "./chunk-HI62EXSB.js";
4
4
 
5
5
  // src/loaders/adapter.ts
6
6
  import { fileURLToPath } from "url";
@@ -165,7 +165,7 @@ function getDefaultMDXOptions({
165
165
 
166
166
  // src/loaders/mdx/remark-include.ts
167
167
  var import_unified = require("unified");
168
- var import_unist_util_visit = require("unist-util-visit");
168
+ var import_unist_util_visit2 = require("unist-util-visit");
169
169
  var path = __toESM(require("path"), 1);
170
170
  var fs = __toESM(require("fs/promises"), 1);
171
171
 
@@ -186,9 +186,53 @@ function fumaMatter(input) {
186
186
  }
187
187
 
188
188
  // src/loaders/mdx/remark-include.ts
189
- var import_remark_parse = __toESM(require("remark-parse"), 1);
190
- var import_remark_mdx = __toESM(require("remark-mdx"), 1);
191
189
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
190
+
191
+ // src/loaders/mdx/remark-unravel.ts
192
+ var import_unist_util_visit = require("unist-util-visit");
193
+ function remarkMarkAndUnravel() {
194
+ return (tree) => {
195
+ (0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
196
+ let offset = -1;
197
+ let all = true;
198
+ let oneOrMore = false;
199
+ if (parent && typeof index === "number" && node.type === "paragraph") {
200
+ const children = node.children;
201
+ while (++offset < children.length) {
202
+ const child = children[offset];
203
+ if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
204
+ oneOrMore = true;
205
+ } else if (child.type === "text" && child.value.trim().length === 0) {
206
+ } else {
207
+ all = false;
208
+ break;
209
+ }
210
+ }
211
+ if (all && oneOrMore) {
212
+ offset = -1;
213
+ const newChildren = [];
214
+ while (++offset < children.length) {
215
+ const child = children[offset];
216
+ if (child.type === "mdxJsxTextElement") {
217
+ child.type = "mdxJsxFlowElement";
218
+ }
219
+ if (child.type === "mdxTextExpression") {
220
+ child.type = "mdxFlowExpression";
221
+ }
222
+ if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
223
+ } else {
224
+ newChildren.push(child);
225
+ }
226
+ }
227
+ parent.children.splice(index, 1, ...newChildren);
228
+ return index;
229
+ }
230
+ }
231
+ });
232
+ };
233
+ }
234
+
235
+ // src/loaders/mdx/remark-include.ts
192
236
  var ElementLikeTypes = [
193
237
  "mdxJsxFlowElement",
194
238
  "mdxJsxTextElement",
@@ -228,7 +272,7 @@ function parseSpecifier(specifier) {
228
272
  function extractSection(root, section) {
229
273
  let nodes;
230
274
  let capturingHeadingContent = false;
231
- (0, import_unist_util_visit.visit)(root, (node) => {
275
+ (0, import_unist_util_visit2.visit)(root, (node) => {
232
276
  if (node.type === "heading") {
233
277
  if (capturingHeadingContent) {
234
278
  return false;
@@ -260,7 +304,7 @@ function extractSection(root, section) {
260
304
  }
261
305
  function remarkInclude() {
262
306
  const TagName = "include";
263
- async function embedContent(file, heading, params, data) {
307
+ const embedContent = async (file, heading, params, data) => {
264
308
  let content;
265
309
  try {
266
310
  content = (await fs.readFile(file)).toString();
@@ -283,18 +327,17 @@ ${e instanceof Error ? e.message : String(e)}`,
283
327
  data: {}
284
328
  };
285
329
  }
286
- const parser = (data._getProcessor ?? getDefaultProcessor)(
287
- ext === ".mdx" ? "mdx" : "md"
288
- );
330
+ const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
289
331
  const parsed = fumaMatter(content);
290
332
  let mdast = parser.parse({
291
333
  path: file,
292
334
  value: parsed.content,
293
335
  data: { frontmatter: parsed.data }
294
336
  });
337
+ const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
295
338
  if (heading) {
296
339
  const extracted = extractSection(
297
- await (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading).run(mdast),
340
+ await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
298
341
  heading
299
342
  );
300
343
  if (!extracted)
@@ -302,13 +345,15 @@ ${e instanceof Error ? e.message : String(e)}`,
302
345
  `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.`
303
346
  );
304
347
  mdast = extracted;
348
+ } else {
349
+ mdast = await baseProcessor.run(mdast);
305
350
  }
306
351
  await update(mdast, path.dirname(file), data);
307
352
  return mdast;
308
- }
353
+ };
309
354
  async function update(tree, directory, data) {
310
355
  const queue = [];
311
- (0, import_unist_util_visit.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
356
+ (0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
312
357
  const node = _node;
313
358
  if (node.name !== TagName) return;
314
359
  const specifier = flattenNode(node);
@@ -335,11 +380,6 @@ ${e instanceof Error ? e.message : String(e)}`,
335
380
  await update(tree, path.dirname(file.path), file.data);
336
381
  };
337
382
  }
338
- function getDefaultProcessor(format) {
339
- const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
340
- if (format === "md") return mdProcessor;
341
- return mdProcessor.use(import_remark_mdx.default);
342
- }
343
383
  // Annotate the CommonJS export names for ESM import in node:
344
384
  0 && (module.exports = {
345
385
  defineCollections,
@@ -1,6 +1,7 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DJbJduHy.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-BCNh3n4O.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
+ export { P as PostprocessOptions } from '../remark-postprocess-K233ZVBK.cjs';
4
5
  import '@standard-schema/spec';
5
6
  import 'fumadocs-core/mdx-plugins';
6
7
  import '@mdx-js/mdx';
@@ -1,6 +1,7 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DJbJduHy.js';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-bck_EB4t.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
+ export { P as PostprocessOptions } from '../remark-postprocess-K233ZVBK.js';
4
5
  import '@standard-schema/spec';
5
6
  import 'fumadocs-core/mdx-plugins';
6
7
  import '@mdx-js/mdx';
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-FSZMKRVH.js";
4
4
  import {
5
5
  remarkInclude
6
- } from "../chunk-LMG6UWCL.js";
6
+ } from "../chunk-K5ZLPEIQ.js";
7
7
  import "../chunk-VWJKRQZR.js";
8
8
 
9
9
  // src/config/zod-4.ts
@@ -3,20 +3,7 @@ import * as plugins from 'fumadocs-core/mdx-plugins';
3
3
  import { ProcessorOptions } from '@mdx-js/mdx';
4
4
  import { Pluggable } from 'unified';
5
5
  import { z } from 'zod';
6
-
7
- interface ExtractedReference {
8
- href: string;
9
- }
10
- interface PostprocessOptions {
11
- /**
12
- * Properties to export from `vfile.data`
13
- */
14
- valueToExport?: string[];
15
- /**
16
- * stringify MDAST and export via `_markdown`.
17
- */
18
- includeProcessedMarkdown?: boolean;
19
- }
6
+ import { P as PostprocessOptions } from './remark-postprocess-K233ZVBK.cjs';
20
7
 
21
8
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
22
9
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -52,6 +39,42 @@ declare const frontmatterSchema: z.ZodObject<{
52
39
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
53
40
  }, z.core.$strip>;
54
41
 
42
+ interface LoadedConfig {
43
+ collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
44
+ global: GlobalConfig;
45
+ getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
46
+ }
47
+
48
+ type Awaitable<T> = T | Promise<T>;
49
+ interface EmitEntry {
50
+ /**
51
+ * path relative to output directory
52
+ */
53
+ path: string;
54
+ content: string;
55
+ }
56
+ interface PluginContext {
57
+ environment: 'next' | 'vite';
58
+ configPath: string;
59
+ outDir: string;
60
+ }
61
+ interface Plugin {
62
+ /**
63
+ * on config loaded
64
+ */
65
+ config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;
66
+ /**
67
+ * Generate files (e.g. types, index file, or JSON schemas)
68
+ */
69
+ emit?: (this: PluginContext) => EmitEntry[] | Promise<EmitEntry[]>;
70
+ }
71
+ type PluginOption = Awaitable<Plugin | Plugin[] | false>;
72
+ declare function createPluginHandler(context: PluginContext, defaultPlugins?: PluginOption[]): {
73
+ init(config: LoadedConfig): Promise<LoadedConfig>;
74
+ emit(): Promise<EmitEntry[]>;
75
+ emitAndWrite(): Promise<void>;
76
+ };
77
+
55
78
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
56
79
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
57
80
  interface BaseCollection {
@@ -75,7 +98,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
75
98
  }
76
99
  interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
77
100
  type: 'doc';
78
- postprocess?: PostprocessOptions;
101
+ postprocess?: Partial<PostprocessOptions>;
79
102
  mdxOptions?: ProcessorOptions;
80
103
  /**
81
104
  * Load files with async
@@ -98,6 +121,7 @@ type GlobalConfigMDXOptions = ({
98
121
  preset: 'minimal';
99
122
  } & ProcessorOptions);
100
123
  interface GlobalConfig {
124
+ plugins?: PluginOption[];
101
125
  /**
102
126
  * Configure global MDX options
103
127
  */
@@ -128,4 +152,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
128
152
  }): DocsCollection<DocSchema, MetaSchema, Async>;
129
153
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
130
154
 
131
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type MetaCollection as M, type PostprocessOptions as P, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
155
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type EmitEntry as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type Plugin as P, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, type PluginContext as h, type PluginOption as i, createPluginHandler as j, metaSchema as m };
@@ -3,20 +3,7 @@ import * as plugins from 'fumadocs-core/mdx-plugins';
3
3
  import { ProcessorOptions } from '@mdx-js/mdx';
4
4
  import { Pluggable } from 'unified';
5
5
  import { z } from 'zod';
6
-
7
- interface ExtractedReference {
8
- href: string;
9
- }
10
- interface PostprocessOptions {
11
- /**
12
- * Properties to export from `vfile.data`
13
- */
14
- valueToExport?: string[];
15
- /**
16
- * stringify MDAST and export via `_markdown`.
17
- */
18
- includeProcessedMarkdown?: boolean;
19
- }
6
+ import { P as PostprocessOptions } from './remark-postprocess-K233ZVBK.js';
20
7
 
21
8
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
22
9
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -52,6 +39,42 @@ declare const frontmatterSchema: z.ZodObject<{
52
39
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
53
40
  }, z.core.$strip>;
54
41
 
42
+ interface LoadedConfig {
43
+ collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
44
+ global: GlobalConfig;
45
+ getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
46
+ }
47
+
48
+ type Awaitable<T> = T | Promise<T>;
49
+ interface EmitEntry {
50
+ /**
51
+ * path relative to output directory
52
+ */
53
+ path: string;
54
+ content: string;
55
+ }
56
+ interface PluginContext {
57
+ environment: 'next' | 'vite';
58
+ configPath: string;
59
+ outDir: string;
60
+ }
61
+ interface Plugin {
62
+ /**
63
+ * on config loaded
64
+ */
65
+ config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;
66
+ /**
67
+ * Generate files (e.g. types, index file, or JSON schemas)
68
+ */
69
+ emit?: (this: PluginContext) => EmitEntry[] | Promise<EmitEntry[]>;
70
+ }
71
+ type PluginOption = Awaitable<Plugin | Plugin[] | false>;
72
+ declare function createPluginHandler(context: PluginContext, defaultPlugins?: PluginOption[]): {
73
+ init(config: LoadedConfig): Promise<LoadedConfig>;
74
+ emit(): Promise<EmitEntry[]>;
75
+ emitAndWrite(): Promise<void>;
76
+ };
77
+
55
78
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
56
79
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
57
80
  interface BaseCollection {
@@ -75,7 +98,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
75
98
  }
76
99
  interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
77
100
  type: 'doc';
78
- postprocess?: PostprocessOptions;
101
+ postprocess?: Partial<PostprocessOptions>;
79
102
  mdxOptions?: ProcessorOptions;
80
103
  /**
81
104
  * Load files with async
@@ -98,6 +121,7 @@ type GlobalConfigMDXOptions = ({
98
121
  preset: 'minimal';
99
122
  } & ProcessorOptions);
100
123
  interface GlobalConfig {
124
+ plugins?: PluginOption[];
101
125
  /**
102
126
  * Configure global MDX options
103
127
  */
@@ -128,4 +152,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
128
152
  }): DocsCollection<DocSchema, MetaSchema, Async>;
129
153
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
130
154
 
131
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type MetaCollection as M, type PostprocessOptions as P, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
155
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type EmitEntry as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type Plugin as P, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, type PluginContext as h, type PluginOption as i, createPluginHandler as j, metaSchema as m };