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
@@ -64,11 +64,7 @@ function defineCollections(options) {
64
64
  return options;
65
65
  }
66
66
  function defineDocs(options) {
67
- if (!options)
68
- console.warn(
69
- "[`source.config.ts`] Deprecated: please pass options to `defineDocs()` and specify a `dir`."
70
- );
71
- const dir = options?.dir ?? "content/docs";
67
+ const dir = options.dir ?? "content/docs";
72
68
  return {
73
69
  type: "docs",
74
70
  dir,
@@ -90,81 +86,8 @@ function defineConfig(config = {}) {
90
86
  return config;
91
87
  }
92
88
 
93
- // src/utils/mdx-options.ts
89
+ // src/mdx/preset.ts
94
90
  var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
95
-
96
- // src/mdx-plugins/remark-postprocess.ts
97
- var import_unist_util_visit = require("unist-util-visit");
98
- var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
99
- function remarkPostprocess({
100
- injectExports
101
- }) {
102
- return (tree, file) => {
103
- let title;
104
- const urls = [];
105
- (0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
106
- if (node.type === "heading" && node.depth === 1) {
107
- title = flattenNode(node);
108
- }
109
- if (node.type !== "link") return;
110
- urls.push({
111
- href: node.url
112
- });
113
- return "skip";
114
- });
115
- if (title) {
116
- file.data.frontmatter ??= {};
117
- if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
118
- }
119
- file.data.extractedReferences = urls;
120
- for (const name of injectExports) {
121
- if (!(name in file.data)) continue;
122
- tree.children.unshift(getMdastExport(name, file.data[name]));
123
- }
124
- };
125
- }
126
- function flattenNode(node) {
127
- if ("children" in node)
128
- return node.children.map((child) => flattenNode(child)).join("");
129
- if ("value" in node) return node.value;
130
- return "";
131
- }
132
- function getMdastExport(name, value) {
133
- return {
134
- type: "mdxjsEsm",
135
- value: "",
136
- data: {
137
- estree: {
138
- type: "Program",
139
- sourceType: "module",
140
- body: [
141
- {
142
- type: "ExportNamedDeclaration",
143
- attributes: [],
144
- specifiers: [],
145
- source: null,
146
- declaration: {
147
- type: "VariableDeclaration",
148
- kind: "let",
149
- declarations: [
150
- {
151
- type: "VariableDeclarator",
152
- id: {
153
- type: "Identifier",
154
- name
155
- },
156
- init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
157
- }
158
- ]
159
- }
160
- }
161
- ]
162
- }
163
- }
164
- };
165
- }
166
-
167
- // src/utils/mdx-options.ts
168
91
  function pluginOption(def, options = []) {
169
92
  const list = def(Array.isArray(options) ? options : []).filter(
170
93
  Boolean
@@ -185,13 +108,6 @@ function getDefaultMDXOptions({
185
108
  _withoutBundler = false,
186
109
  ...mdxOptions
187
110
  }) {
188
- const mdxExports = [
189
- "structuredData",
190
- "extractedReferences",
191
- "frontmatter",
192
- "lastModified",
193
- ...valueToExport
194
- ];
195
111
  const remarkPlugins = pluginOption(
196
112
  (v) => [
197
113
  plugins.remarkGfm,
@@ -219,10 +135,15 @@ function getDefaultMDXOptions({
219
135
  plugins.remarkStructure,
220
136
  remarkStructureOptions
221
137
  ],
222
- [
223
- remarkPostprocess,
224
- { injectExports: mdxExports }
225
- ]
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
+ }
226
147
  ],
227
148
  mdxOptions.remarkPlugins
228
149
  );
@@ -242,9 +163,9 @@ function getDefaultMDXOptions({
242
163
  };
243
164
  }
244
165
 
245
- // src/mdx-plugins/remark-include.ts
166
+ // src/mdx/remark-include.ts
246
167
  var import_unified = require("unified");
247
- var import_unist_util_visit2 = require("unist-util-visit");
168
+ var import_unist_util_visit = require("unist-util-visit");
248
169
  var path = __toESM(require("path"), 1);
249
170
  var fs = __toESM(require("fs/promises"), 1);
250
171
 
@@ -264,14 +185,14 @@ function fumaMatter(input) {
264
185
  return output;
265
186
  }
266
187
 
267
- // src/mdx-plugins/remark-include.ts
188
+ // src/mdx/remark-include.ts
268
189
  var import_remark_parse = __toESM(require("remark-parse"), 1);
269
190
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
270
191
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
271
192
  var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
272
- function flattenNode2(node) {
193
+ function flattenNode(node) {
273
194
  if ("children" in node)
274
- return node.children.map((child) => flattenNode2(child)).join("");
195
+ return node.children.map((child) => flattenNode(child)).join("");
275
196
  if ("value" in node) return node.value;
276
197
  return "";
277
198
  }
@@ -350,14 +271,14 @@ ${e instanceof Error ? e.message : String(e)}`,
350
271
  }
351
272
  async function update(tree, directory, data) {
352
273
  const queue = [];
353
- (0, import_unist_util_visit2.visit)(
274
+ (0, import_unist_util_visit.visit)(
354
275
  tree,
355
276
  ["mdxJsxFlowElement", "mdxJsxTextElement"],
356
277
  (_node, _, parent) => {
357
278
  const node = _node;
358
279
  if (node.name !== TagName) return;
359
280
  const params = {};
360
- const specifier = flattenNode2(node);
281
+ const specifier = flattenNode(node);
361
282
  if (specifier.length === 0) return "skip";
362
283
  for (const attr of node.attributes) {
363
284
  if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
@@ -1,4 +1,4 @@
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-BH4bnHQl.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--6HQ1ehX.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@standard-schema/spec';
@@ -1,4 +1,4 @@
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-BH4bnHQl.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--6HQ1ehX.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@standard-schema/spec';
@@ -1,17 +1,56 @@
1
- import {
2
- defineCollections,
3
- defineConfig,
4
- defineDocs,
5
- frontmatterSchema,
6
- metaSchema
7
- } from "../chunk-GBMFGEC7.js";
8
1
  import {
9
2
  getDefaultMDXOptions
10
- } from "../chunk-SMSNZ6N5.js";
3
+ } from "../chunk-3M4SHY6K.js";
11
4
  import {
12
5
  remarkInclude
13
- } from "../chunk-SVTXMVLQ.js";
6
+ } from "../chunk-KTDVTBMH.js";
14
7
  import "../chunk-VWJKRQZR.js";
8
+
9
+ // src/config/zod-4.ts
10
+ import { z } from "zod";
11
+ var metaSchema = z.object({
12
+ title: z.string().optional(),
13
+ pages: z.array(z.string()).optional(),
14
+ description: z.string().optional(),
15
+ root: z.boolean().optional(),
16
+ defaultOpen: z.boolean().optional(),
17
+ icon: z.string().optional()
18
+ });
19
+ var frontmatterSchema = z.object({
20
+ title: z.string(),
21
+ description: z.string().optional(),
22
+ icon: z.string().optional(),
23
+ full: z.boolean().optional(),
24
+ // Fumadocs OpenAPI generated
25
+ _openapi: z.looseObject({}).optional()
26
+ });
27
+
28
+ // src/config/define.ts
29
+ function defineCollections(options) {
30
+ return options;
31
+ }
32
+ function defineDocs(options) {
33
+ const dir = options.dir ?? "content/docs";
34
+ return {
35
+ type: "docs",
36
+ dir,
37
+ docs: defineCollections({
38
+ type: "doc",
39
+ dir,
40
+ schema: frontmatterSchema,
41
+ ...options?.docs
42
+ }),
43
+ meta: defineCollections({
44
+ type: "meta",
45
+ dir,
46
+ schema: metaSchema,
47
+ ...options?.meta
48
+ })
49
+ };
50
+ }
51
+ function defineConfig(config = {}) {
52
+ return config;
53
+ }
15
54
  export {
16
55
  defineCollections,
17
56
  defineConfig,
@@ -38,6 +38,20 @@ declare const frontmatterSchema: z.ZodObject<{
38
38
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
39
39
  }, z.core.$strip>;
40
40
 
41
+ interface ExtractedReference {
42
+ href: string;
43
+ }
44
+ interface PostprocessOptions {
45
+ /**
46
+ * Properties to export from `vfile.data`
47
+ */
48
+ valueToExport?: string[];
49
+ /**
50
+ * stringify MDAST and export via `_markdown`.
51
+ */
52
+ includeProcessedMarkdown?: boolean;
53
+ }
54
+
41
55
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
42
56
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
43
57
  interface BaseCollection {
@@ -61,6 +75,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
61
75
  }
62
76
  interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
63
77
  type: 'doc';
78
+ postprocess?: PostprocessOptions;
64
79
  mdxOptions?: ProcessorOptions;
65
80
  /**
66
81
  * Load files with async
@@ -101,9 +116,9 @@ interface GlobalConfig {
101
116
  }
102
117
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
103
118
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
104
- declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options?: {
119
+ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options: {
105
120
  /**
106
- * The directory to scan files
121
+ * The content directory to scan files
107
122
  *
108
123
  * @defaultValue 'content/docs'
109
124
  */
@@ -113,4 +128,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
113
128
  }): DocsCollection<DocSchema, MetaSchema, Async>;
114
129
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
115
130
 
116
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, 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 };
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 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 };
@@ -38,6 +38,20 @@ declare const frontmatterSchema: z.ZodObject<{
38
38
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
39
39
  }, z.core.$strip>;
40
40
 
41
+ interface ExtractedReference {
42
+ href: string;
43
+ }
44
+ interface PostprocessOptions {
45
+ /**
46
+ * Properties to export from `vfile.data`
47
+ */
48
+ valueToExport?: string[];
49
+ /**
50
+ * stringify MDAST and export via `_markdown`.
51
+ */
52
+ includeProcessedMarkdown?: boolean;
53
+ }
54
+
41
55
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
42
56
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
43
57
  interface BaseCollection {
@@ -61,6 +75,7 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
61
75
  }
62
76
  interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
63
77
  type: 'doc';
78
+ postprocess?: PostprocessOptions;
64
79
  mdxOptions?: ProcessorOptions;
65
80
  /**
66
81
  * Load files with async
@@ -101,9 +116,9 @@ interface GlobalConfig {
101
116
  }
102
117
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
103
118
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
104
- declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options?: {
119
+ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options: {
105
120
  /**
106
- * The directory to scan files
121
+ * The content directory to scan files
107
122
  *
108
123
  * @defaultValue 'content/docs'
109
124
  */
@@ -113,4 +128,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
113
128
  }): DocsCollection<DocSchema, MetaSchema, Async>;
114
129
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
115
130
 
116
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, 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 };
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 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 };