fumadocs-mdx 13.0.7 → 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 +927 -904
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +592 -481
  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-ETIN2W7C.js → chunk-SRSRFOVI.js} +22 -19
  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-HkAVGq_a.d.cts → index-D7JdSMpp.d.cts} +99 -61
  28. package/dist/{core-HkAVGq_a.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 +705 -603
  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 +935 -639
  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 +614 -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 +328 -234
  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-BnJhW5O1.d.cts +0 -53
  75. package/dist/build-mdx-DNzfRRlY.d.ts +0 -53
  76. package/dist/chunk-2AQRQXSO.js +0 -119
  77. package/dist/chunk-4757L6ST.js +0 -77
  78. package/dist/chunk-CXA4JO4Z.js +0 -45
  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-By6wKOnT.d.cts +0 -45
  104. package/dist/types-DgD5Omj2.d.ts +0 -45
@@ -1,11 +1,12 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { h as CoreOptions } from '../core-HkAVGq_a.cjs';
2
+ import { C as CoreOptions } from '../index-D7JdSMpp.cjs';
3
3
  import '@mdx-js/mdx';
4
4
  import '@standard-schema/spec';
5
- import 'fumadocs-core/mdx-plugins';
6
5
  import 'unified';
6
+ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
+ import 'vfile';
9
10
 
10
11
  interface MdxPluginOptions extends Partial<CoreOptions> {
11
12
  /**
@@ -1,11 +1,12 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { h as CoreOptions } from '../core-HkAVGq_a.js';
2
+ import { C as CoreOptions } from '../index-D7JdSMpp.js';
3
3
  import '@mdx-js/mdx';
4
4
  import '@standard-schema/spec';
5
- import 'fumadocs-core/mdx-plugins';
6
5
  import 'unified';
6
+ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
+ import 'vfile';
9
10
 
10
11
  interface MdxPluginOptions extends Partial<CoreOptions> {
11
12
  /**
package/dist/bun/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  buildConfig
3
- } from "../chunk-2HXTGJBI.js";
3
+ } from "../chunk-ZY6UZ7NH.js";
4
+ import "../chunk-E5DJTSIM.js";
4
5
  import {
5
6
  createMdxLoader
6
- } from "../chunk-2E2JCOSO.js";
7
+ } from "../chunk-6NISOLQ6.js";
7
8
  import {
8
9
  createMetaLoader
9
- } from "../chunk-4757L6ST.js";
10
+ } from "../chunk-TYJDYTKH.js";
10
11
  import {
11
12
  createIntegratedConfigLoader,
12
13
  toBun
13
- } from "../chunk-ETIN2W7C.js";
14
- import "../chunk-3J3WL7WN.js";
15
- import "../chunk-K5ZLPEIQ.js";
16
- import "../chunk-VUEZTR2H.js";
14
+ } from "../chunk-SRSRFOVI.js";
15
+ import "../chunk-4JSFLXXT.js";
17
16
  import {
18
- createCore,
19
- findConfigFile
20
- } from "../chunk-2AQRQXSO.js";
17
+ _Defaults,
18
+ createCore
19
+ } from "../chunk-7L2KNF6B.js";
20
+ import "../chunk-PKI7ZDA5.js";
21
21
  import "../chunk-VWJKRQZR.js";
22
22
 
23
23
  // src/bun/index.ts
@@ -25,8 +25,8 @@ import { pathToFileURL } from "url";
25
25
  function createMdxPlugin(options = {}) {
26
26
  const {
27
27
  environment = "bun",
28
- outDir = ".source",
29
- configPath = findConfigFile(),
28
+ outDir = _Defaults.outDir,
29
+ configPath = _Defaults.configPath,
30
30
  disableMetaFile = false
31
31
  } = options;
32
32
  return {
@@ -0,0 +1,8 @@
1
+ // src/loaders/index.ts
2
+ var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
3
+ var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
4
+
5
+ export {
6
+ metaLoaderGlob,
7
+ mdxLoaderGlob
8
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ createCore
3
+ } from "./chunk-7L2KNF6B.js";
4
+
5
+ // src/webpack/index.ts
6
+ var core;
7
+ function getCore(options) {
8
+ return core ??= createCore({
9
+ environment: "webpack",
10
+ outDir: options.outDir,
11
+ configPath: options.configPath
12
+ });
13
+ }
14
+
15
+ export {
16
+ getCore
17
+ };
@@ -0,0 +1,138 @@
1
+ // src/runtime/server.ts
2
+ import * as path from "path";
3
+ function fromConfig() {
4
+ function fileInfo(file, base) {
5
+ if (file.startsWith("./")) {
6
+ file = file.slice(2);
7
+ }
8
+ return {
9
+ path: file,
10
+ fullPath: path.join(base, file)
11
+ };
12
+ }
13
+ function mapDocData(entry) {
14
+ return {
15
+ body: entry.default,
16
+ toc: entry.toc,
17
+ extractedReferences: entry.extractedReferences,
18
+ structuredData: entry.structuredData,
19
+ lastModified: entry.lastModified,
20
+ _exports: entry
21
+ };
22
+ }
23
+ return {
24
+ async doc(_name, base, glob) {
25
+ const out = await Promise.all(
26
+ Object.entries(glob).map(async ([k, v]) => {
27
+ const data = typeof v === "function" ? await v() : v;
28
+ return {
29
+ ...mapDocData(data),
30
+ ...data.frontmatter,
31
+ ...createDocMethods(fileInfo(k, base), () => data)
32
+ };
33
+ })
34
+ );
35
+ return out;
36
+ },
37
+ async docLazy(_name, base, head, body) {
38
+ const out = await Promise.all(
39
+ Object.entries(head).map(async ([k, v]) => {
40
+ const data = typeof v === "function" ? await v() : v;
41
+ const content = body[k];
42
+ return {
43
+ ...data,
44
+ ...createDocMethods(fileInfo(k, base), content),
45
+ async load() {
46
+ return mapDocData(await content());
47
+ }
48
+ };
49
+ })
50
+ );
51
+ return out;
52
+ },
53
+ async meta(_name, base, glob) {
54
+ const out = await Promise.all(
55
+ Object.entries(glob).map(async ([k, v]) => {
56
+ const data = typeof v === "function" ? await v() : v;
57
+ return {
58
+ info: fileInfo(k, base),
59
+ ...data
60
+ };
61
+ })
62
+ );
63
+ return out;
64
+ },
65
+ async docs(name, base, metaGlob, docGlob) {
66
+ const entry = {
67
+ docs: await this.doc(name, base, docGlob),
68
+ meta: await this.meta(name, base, metaGlob),
69
+ toFumadocsSource() {
70
+ return toFumadocsSource(this.docs, this.meta);
71
+ }
72
+ };
73
+ return entry;
74
+ },
75
+ async docsLazy(name, base, metaGlob, docHeadGlob, docBodyGlob) {
76
+ const entry = {
77
+ docs: await this.docLazy(name, base, docHeadGlob, docBodyGlob),
78
+ meta: await this.meta(name, base, metaGlob),
79
+ toFumadocsSource() {
80
+ return toFumadocsSource(this.docs, this.meta);
81
+ }
82
+ };
83
+ return entry;
84
+ }
85
+ };
86
+ }
87
+ function toFumadocsSource(pages, metas) {
88
+ const files = [];
89
+ for (const entry of pages) {
90
+ files.push({
91
+ type: "page",
92
+ path: entry.info.path,
93
+ absolutePath: entry.info.fullPath,
94
+ data: entry
95
+ });
96
+ }
97
+ for (const entry of metas) {
98
+ files.push({
99
+ type: "meta",
100
+ path: entry.info.path,
101
+ absolutePath: entry.info.fullPath,
102
+ data: entry
103
+ });
104
+ }
105
+ return {
106
+ files
107
+ };
108
+ }
109
+ function createDocMethods(info, load) {
110
+ return {
111
+ info,
112
+ async getText(type) {
113
+ if (type === "raw") {
114
+ const fs = await import("fs/promises");
115
+ return (await fs.readFile(info.fullPath)).toString();
116
+ }
117
+ const data = await load();
118
+ if (typeof data._markdown !== "string")
119
+ throw new Error(
120
+ "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
121
+ );
122
+ return data._markdown;
123
+ },
124
+ async getMDAST() {
125
+ const data = await load();
126
+ if (!data._mdast)
127
+ throw new Error(
128
+ "getMDAST() requires `includeMDAST` to be enabled in your collection config."
129
+ );
130
+ return JSON.parse(data._mdast);
131
+ }
132
+ };
133
+ }
134
+
135
+ export {
136
+ fromConfig,
137
+ toFumadocsSource
138
+ };
@@ -1,13 +1,6 @@
1
1
  import {
2
- buildMDX
3
- } from "./chunk-3J3WL7WN.js";
4
- import {
5
- getGitTimestamp
6
- } from "./chunk-VUEZTR2H.js";
7
- import {
8
- mdxLoaderGlob,
9
- validate
10
- } from "./chunk-2AQRQXSO.js";
2
+ mdxLoaderGlob
3
+ } from "./chunk-4JSFLXXT.js";
11
4
  import {
12
5
  fumaMatter
13
6
  } from "./chunk-VWJKRQZR.js";
@@ -36,10 +29,10 @@ function createMdxLoader(configLoader) {
36
29
  compiler,
37
30
  filePath
38
31
  }) {
32
+ const config = await configLoader.getConfig();
39
33
  const value = await getSource();
40
34
  const matter = fumaMatter(value);
41
35
  const parsed = querySchema.parse(query);
42
- const config = await configLoader.getConfig();
43
36
  let after;
44
37
  if (!isDevelopment && config.global.experimentalBuildCache) {
45
38
  const cacheDir = config.global.experimentalBuildCache;
@@ -67,15 +60,10 @@ function createMdxLoader(configLoader) {
67
60
  docCollection = collection.docs;
68
61
  break;
69
62
  }
70
- if (docCollection?.schema) {
71
- matter.data = await validate(
72
- docCollection.schema,
73
- matter.data,
74
- {
75
- source: value,
76
- path: filePath
77
- },
78
- `invalid frontmatter in ${filePath}`
63
+ if (docCollection) {
64
+ matter.data = await configLoader.core.transformFrontmatter(
65
+ { collection: docCollection, filePath, source: value },
66
+ matter.data
79
67
  );
80
68
  }
81
69
  if (parsed.only === "frontmatter") {
@@ -84,24 +72,16 @@ function createMdxLoader(configLoader) {
84
72
  map: null
85
73
  };
86
74
  }
87
- const data = {};
88
- if (config.global.lastModifiedTime === "git") {
89
- data.lastModified = (await getGitTimestamp(filePath))?.getTime();
90
- }
91
75
  const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
92
- const compiled = await buildMDX(
93
- `${getConfigHash(config)}:${parsed.collection ?? "global"}`,
94
- "\n".repeat(lineOffset) + matter.content,
95
- {
96
- development: isDevelopment,
97
- ...docCollection?.mdxOptions ?? await config.getDefaultMDXOptions(),
98
- postprocess: docCollection?.postprocess,
99
- data,
100
- filePath,
101
- frontmatter: matter.data,
102
- _compiler: compiler
103
- }
104
- );
76
+ const { buildMDX } = await import("./build-mdx-6UAK5FF5.js");
77
+ const compiled = await buildMDX(configLoader.core, docCollection, {
78
+ isDevelopment,
79
+ source: "\n".repeat(lineOffset) + matter.content,
80
+ filePath,
81
+ frontmatter: matter.data,
82
+ _compiler: compiler,
83
+ environment: "bundler"
84
+ });
105
85
  const out = {
106
86
  code: String(compiled.value),
107
87
  map: compiled.map
@@ -111,14 +91,6 @@ function createMdxLoader(configLoader) {
111
91
  }
112
92
  };
113
93
  }
114
- var hashes = /* @__PURE__ */ new WeakMap();
115
- function getConfigHash(config) {
116
- let hash = hashes.get(config);
117
- if (hash) return hash;
118
- hash = Date.now().toString();
119
- hashes.set(config, hash);
120
- return hash;
121
- }
122
94
  function generateCacheHash(input) {
123
95
  return createHash("md5").update(input).digest("hex");
124
96
  }
@@ -0,0 +1,180 @@
1
+ import {
2
+ removeFileCache
3
+ } from "./chunk-PKI7ZDA5.js";
4
+
5
+ // src/utils/validation.ts
6
+ var ValidationError = class extends Error {
7
+ constructor(message, issues) {
8
+ super(
9
+ `${message}:
10
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
11
+ );
12
+ this.title = message;
13
+ this.issues = issues;
14
+ }
15
+ async toStringFormatted() {
16
+ const picocolors = await import("picocolors");
17
+ return [
18
+ picocolors.bold(`[MDX] ${this.title}:`),
19
+ ...this.issues.map(
20
+ (issue) => picocolors.redBright(
21
+ `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
22
+ )
23
+ )
24
+ ].join("\n");
25
+ }
26
+ };
27
+ async function validate(schema, data, context, errorMessage) {
28
+ if (typeof schema === "function" && !("~standard" in schema)) {
29
+ schema = schema(context);
30
+ }
31
+ if ("~standard" in schema) {
32
+ const result = await schema["~standard"].validate(
33
+ data
34
+ );
35
+ if (result.issues) {
36
+ throw new ValidationError(errorMessage, result.issues);
37
+ }
38
+ return result.value;
39
+ }
40
+ return data;
41
+ }
42
+
43
+ // src/core.ts
44
+ import path from "path";
45
+ import fs from "fs/promises";
46
+ var _Defaults = {
47
+ configPath: "source.config.ts",
48
+ outDir: ".source"
49
+ };
50
+ async function getPlugins(pluginOptions) {
51
+ const plugins = [];
52
+ for await (const option of pluginOptions) {
53
+ if (!option) continue;
54
+ if (Array.isArray(option)) plugins.push(...await getPlugins(option));
55
+ else plugins.push(option);
56
+ }
57
+ return plugins;
58
+ }
59
+ function createCore(options, defaultPlugins = []) {
60
+ let config;
61
+ let plugins;
62
+ async function transformMetadata({
63
+ collection,
64
+ filePath,
65
+ source
66
+ }, data) {
67
+ if (collection.schema) {
68
+ data = await validate(
69
+ collection.schema,
70
+ data,
71
+ { path: filePath, source },
72
+ collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
73
+ );
74
+ }
75
+ return data;
76
+ }
77
+ const core = {
78
+ _options: options,
79
+ /**
80
+ * Convenient cache store, reset when config changes
81
+ */
82
+ cache: /* @__PURE__ */ new Map(),
83
+ async init({ config: newConfig }) {
84
+ config = await newConfig;
85
+ this.cache.clear();
86
+ plugins = await getPlugins([
87
+ ...defaultPlugins,
88
+ ...config.global.plugins ?? []
89
+ ]);
90
+ for (const plugin of plugins) {
91
+ const out = await plugin.config?.call(pluginContext, config);
92
+ if (out) config = out;
93
+ }
94
+ return this;
95
+ },
96
+ getConfig() {
97
+ return config;
98
+ },
99
+ /**
100
+ * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
101
+ */
102
+ getCompiledConfigPath() {
103
+ return path.join(options.outDir, "source.config.mjs");
104
+ },
105
+ async initServer(server) {
106
+ server.watcher?.on("all", async (event, file) => {
107
+ if (event === "change") removeFileCache(file);
108
+ });
109
+ for (const plugin of plugins) {
110
+ await plugin.configureServer?.call(pluginContext, server);
111
+ }
112
+ },
113
+ async emit({ filterPlugin = () => true } = {}) {
114
+ return (await Promise.all(
115
+ plugins.map((plugin) => {
116
+ if (!filterPlugin(plugin) || !plugin.emit) return [];
117
+ return plugin.emit.call(pluginContext);
118
+ })
119
+ )).flat();
120
+ },
121
+ async emitAndWrite(emitOptions) {
122
+ const start = performance.now();
123
+ const out = await this.emit(emitOptions);
124
+ await Promise.all(
125
+ out.map(async (entry) => {
126
+ const file = path.join(options.outDir, entry.path);
127
+ await fs.mkdir(path.dirname(file), { recursive: true });
128
+ await fs.writeFile(file, entry.content);
129
+ })
130
+ );
131
+ console.log(`[MDX] generated files in ${performance.now() - start}ms`);
132
+ },
133
+ async transformMeta(options2, data) {
134
+ const ctx = {
135
+ ...pluginContext,
136
+ ...options2
137
+ };
138
+ data = await transformMetadata(options2, data);
139
+ for (const plugin of plugins) {
140
+ if (plugin.meta?.transform)
141
+ data = await plugin.meta.transform.call(ctx, data) ?? data;
142
+ }
143
+ return data;
144
+ },
145
+ async transformFrontmatter(options2, data) {
146
+ const ctx = {
147
+ ...pluginContext,
148
+ ...options2
149
+ };
150
+ data = await transformMetadata(options2, data);
151
+ for (const plugin of plugins) {
152
+ if (plugin.doc?.frontmatter)
153
+ data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
154
+ }
155
+ return data;
156
+ },
157
+ async transformVFile(options2, file) {
158
+ const ctx = {
159
+ ...pluginContext,
160
+ ...options2
161
+ };
162
+ for (const plugin of plugins) {
163
+ if (plugin.doc?.vfile)
164
+ file = await plugin.doc.vfile.call(ctx, file) ?? file;
165
+ }
166
+ return file;
167
+ }
168
+ };
169
+ const pluginContext = {
170
+ core,
171
+ ...options
172
+ };
173
+ return core;
174
+ }
175
+
176
+ export {
177
+ ValidationError,
178
+ _Defaults,
179
+ createCore
180
+ };
@@ -0,0 +1,86 @@
1
+ // src/config/preset.ts
2
+ function pluginOption(def, options = []) {
3
+ const list = def(Array.isArray(options) ? options : []).filter(
4
+ Boolean
5
+ );
6
+ if (typeof options === "function") {
7
+ return options(list);
8
+ }
9
+ return list;
10
+ }
11
+ function applyMdxPreset(options = {}) {
12
+ return async (environment = "bundler") => {
13
+ if (options.preset === "minimal") return options;
14
+ const plugins = await import("fumadocs-core/mdx-plugins");
15
+ const {
16
+ valueToExport = [],
17
+ rehypeCodeOptions,
18
+ remarkImageOptions,
19
+ remarkHeadingOptions,
20
+ remarkStructureOptions,
21
+ remarkCodeTabOptions,
22
+ remarkNpmOptions,
23
+ ...mdxOptions
24
+ } = options;
25
+ const remarkPlugins = pluginOption(
26
+ (v) => [
27
+ plugins.remarkGfm,
28
+ [
29
+ plugins.remarkHeading,
30
+ {
31
+ generateToc: false,
32
+ ...remarkHeadingOptions
33
+ }
34
+ ],
35
+ remarkImageOptions !== false && [
36
+ plugins.remarkImage,
37
+ {
38
+ ...remarkImageOptions,
39
+ useImport: remarkImageOptions?.useImport ?? environment === "bundler"
40
+ }
41
+ ],
42
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
43
+ plugins.remarkCodeTab,
44
+ remarkCodeTabOptions
45
+ ],
46
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
47
+ ...v,
48
+ remarkStructureOptions !== false && [
49
+ plugins.remarkStructure,
50
+ remarkStructureOptions
51
+ ],
52
+ valueToExport.length > 0 && (() => {
53
+ return (_, file) => {
54
+ file.data["mdx-export"] ??= [];
55
+ for (const name of valueToExport) {
56
+ if (!(name in file.data)) continue;
57
+ file.data["mdx-export"].push({
58
+ name,
59
+ value: file.data[name]
60
+ });
61
+ }
62
+ };
63
+ })
64
+ ],
65
+ mdxOptions.remarkPlugins
66
+ );
67
+ const rehypePlugins = pluginOption(
68
+ (v) => [
69
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
70
+ ...v,
71
+ plugins.rehypeToc
72
+ ],
73
+ mdxOptions.rehypePlugins
74
+ );
75
+ return {
76
+ ...mdxOptions,
77
+ outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
78
+ remarkPlugins,
79
+ rehypePlugins
80
+ };
81
+ };
82
+ }
83
+
84
+ export {
85
+ applyMdxPreset
86
+ };
@@ -53,6 +53,14 @@ function remarkMarkAndUnravel() {
53
53
  };
54
54
  }
55
55
 
56
+ // src/loaders/mdx/mdast-utils.ts
57
+ function flattenNode(node) {
58
+ if ("children" in node)
59
+ return node.children.map((child) => flattenNode(child)).join("");
60
+ if ("value" in node) return node.value;
61
+ return "";
62
+ }
63
+
56
64
  // src/loaders/mdx/remark-include.ts
57
65
  var ElementLikeTypes = [
58
66
  "mdxJsxFlowElement",
@@ -76,12 +84,6 @@ function parseElementAttributes(element) {
76
84
  }
77
85
  return element.attributes ?? {};
78
86
  }
79
- function flattenNode(node) {
80
- if ("children" in node)
81
- return node.children.map((child) => flattenNode(child)).join("");
82
- if ("value" in node) return node.value;
83
- return "";
84
- }
85
87
  function parseSpecifier(specifier) {
86
88
  const idx = specifier.lastIndexOf("#");
87
89
  if (idx === -1) return { file: specifier };
@@ -203,5 +205,6 @@ ${e instanceof Error ? e.message : String(e)}`,
203
205
  }
204
206
 
205
207
  export {
208
+ flattenNode,
206
209
  remarkInclude
207
210
  };
@@ -1,16 +1,15 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-2HXTGJBI.js";
3
+ } from "./chunk-ZY6UZ7NH.js";
4
4
 
5
5
  // src/config/load-from-file.ts
6
- import * as path from "path";
7
6
  import { pathToFileURL } from "url";
8
- async function compileConfig(configPath, outDir) {
7
+ async function compileConfig(core) {
9
8
  const { build } = await import("esbuild");
10
9
  const transformed = await build({
11
- entryPoints: [{ in: configPath, out: "source.config" }],
10
+ entryPoints: [{ in: core._options.configPath, out: "source.config" }],
12
11
  bundle: true,
13
- outdir: outDir,
12
+ outdir: core._options.outDir,
14
13
  target: "node20",
15
14
  write: true,
16
15
  platform: "node",
@@ -25,9 +24,9 @@ async function compileConfig(configPath, outDir) {
25
24
  throw new Error("failed to compile configuration file");
26
25
  }
27
26
  }
28
- async function loadConfig(configPath, outDir, build = false) {
29
- if (build) await compileConfig(configPath, outDir);
30
- const url = pathToFileURL(path.resolve(outDir, "source.config.mjs"));
27
+ async function loadConfig(core, build = false) {
28
+ if (build) await compileConfig(core);
29
+ const url = pathToFileURL(core.getCompiledConfigPath());
31
30
  url.searchParams.set("hash", Date.now().toString());
32
31
  const config = import(url.href).then(
33
32
  (loaded) => buildConfig(loaded)