fumadocs-mdx 11.6.0 → 13.0.1

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 (93) hide show
  1. package/dist/bin.cjs +1728 -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/build-mdx-CCNr86q6.d.ts +53 -0
  6. package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
  7. package/dist/bun/index.cjs +857 -0
  8. package/dist/bun/index.d.cts +13 -0
  9. package/dist/bun/index.d.ts +13 -0
  10. package/dist/bun/index.js +62 -0
  11. package/dist/chunk-3J3WL7WN.js +160 -0
  12. package/dist/chunk-CXA4JO4Z.js +45 -0
  13. package/dist/chunk-EELYB2XC.js +207 -0
  14. package/dist/chunk-FSZMKRVH.js +80 -0
  15. package/dist/chunk-II3H5ZVZ.js +77 -0
  16. package/dist/chunk-JVZFH6ND.js +40 -0
  17. package/dist/chunk-K5ZLPEIQ.js +207 -0
  18. package/dist/{chunk-VFALQK6O.js → chunk-KILFIBVW.js} +21 -12
  19. package/dist/chunk-NVRDCY6Z.js +30 -0
  20. package/dist/chunk-U4MQ44TS.js +53 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-XQ5O7IPO.js +128 -0
  23. package/dist/chunk-XZY2AWJI.js +81 -0
  24. package/dist/chunk-YVCR6FUH.js +82 -0
  25. package/dist/config/index.cjs +232 -128
  26. package/dist/config/index.d.cts +4 -6
  27. package/dist/config/index.d.ts +4 -6
  28. package/dist/config/index.js +26 -19
  29. package/dist/core-B6j6Fxse.d.cts +218 -0
  30. package/dist/core-B6j6Fxse.d.ts +218 -0
  31. package/dist/index.cjs +0 -76
  32. package/dist/index.d.cts +73 -20
  33. package/dist/index.d.ts +73 -20
  34. package/dist/index.js +0 -10
  35. package/dist/load-MNG3CLET.js +7 -0
  36. package/dist/next/index.cjs +567 -314
  37. package/dist/next/index.d.cts +9 -12
  38. package/dist/next/index.d.ts +9 -12
  39. package/dist/next/index.js +238 -211
  40. package/dist/node/loader.cjs +922 -0
  41. package/dist/node/loader.d.cts +5 -0
  42. package/dist/node/loader.d.ts +5 -0
  43. package/dist/node/loader.js +33 -0
  44. package/dist/plugins/json-schema.cjs +162 -0
  45. package/dist/plugins/json-schema.d.cts +24 -0
  46. package/dist/plugins/json-schema.d.ts +24 -0
  47. package/dist/plugins/json-schema.js +78 -0
  48. package/dist/{mdx-options-CAU273O3.js → preset-ZMP6U62C.js} +1 -1
  49. package/dist/runtime/next/async.cjs +715 -0
  50. package/dist/runtime/next/async.d.cts +21 -0
  51. package/dist/runtime/next/async.d.ts +21 -0
  52. package/dist/runtime/next/async.js +89 -0
  53. package/dist/runtime/next/index.cjs +136 -0
  54. package/dist/runtime/next/index.d.cts +33 -0
  55. package/dist/runtime/next/index.d.ts +33 -0
  56. package/dist/runtime/next/index.js +11 -0
  57. package/dist/runtime/vite/browser.cjs +107 -0
  58. package/dist/runtime/vite/browser.d.cts +59 -0
  59. package/dist/runtime/vite/browser.d.ts +59 -0
  60. package/dist/runtime/vite/browser.js +11 -0
  61. package/dist/runtime/vite/server.cjs +243 -0
  62. package/dist/runtime/vite/server.d.cts +30 -0
  63. package/dist/runtime/vite/server.d.ts +30 -0
  64. package/dist/runtime/vite/server.js +111 -0
  65. package/dist/types-AGzTfBmf.d.ts +45 -0
  66. package/dist/types-DKGMoay5.d.cts +45 -0
  67. package/dist/vite/index.cjs +1185 -0
  68. package/dist/vite/index.d.cts +45 -0
  69. package/dist/vite/index.d.ts +45 -0
  70. package/dist/vite/index.js +297 -0
  71. package/dist/webpack/index.cjs +957 -0
  72. package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +3 -6
  73. package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +3 -6
  74. package/dist/webpack/index.js +44 -0
  75. package/loader-mdx.cjs +1 -1
  76. package/package.json +86 -29
  77. package/bin.js +0 -5
  78. package/dist/chunk-2ZOW45YZ.js +0 -63
  79. package/dist/chunk-DRVUBK5B.js +0 -39
  80. package/dist/chunk-HFLDWPJA.js +0 -62
  81. package/dist/chunk-IOENRFUX.js +0 -112
  82. package/dist/chunk-MK7EXW7O.js +0 -75
  83. package/dist/define-BaW0PQDJ.d.cts +0 -201
  84. package/dist/define-BaW0PQDJ.d.ts +0 -201
  85. package/dist/loader-mdx.cjs +0 -527
  86. package/dist/loader-mdx.js +0 -162
  87. package/dist/runtime/async.cjs +0 -269
  88. package/dist/runtime/async.d.cts +0 -18
  89. package/dist/runtime/async.d.ts +0 -18
  90. package/dist/runtime/async.js +0 -73
  91. package/dist/types-BNrQHCj5.d.cts +0 -100
  92. package/dist/types-DEduCvIT.d.ts +0 -100
  93. package/dist/watcher-IAZDSTU7.js +0 -24
@@ -0,0 +1,13 @@
1
+ import { BunPlugin } from 'bun';
2
+ import { C as CoreOptions } from '../core-B6j6Fxse.cjs';
3
+ import '@standard-schema/spec';
4
+ import 'fumadocs-core/mdx-plugins';
5
+ import '@mdx-js/mdx';
6
+ import 'unified';
7
+ import 'zod';
8
+ import 'chokidar';
9
+
10
+ type MdxPluginOptions = Partial<CoreOptions>;
11
+ declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
12
+
13
+ export { type MdxPluginOptions, createMdxPlugin };
@@ -0,0 +1,13 @@
1
+ import { BunPlugin } from 'bun';
2
+ import { C as CoreOptions } from '../core-B6j6Fxse.js';
3
+ import '@standard-schema/spec';
4
+ import 'fumadocs-core/mdx-plugins';
5
+ import '@mdx-js/mdx';
6
+ import 'unified';
7
+ import 'zod';
8
+ import 'chokidar';
9
+
10
+ type MdxPluginOptions = Partial<CoreOptions>;
11
+ declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
12
+
13
+ export { type MdxPluginOptions, createMdxPlugin };
@@ -0,0 +1,62 @@
1
+ import {
2
+ buildConfig
3
+ } from "../chunk-U4MQ44TS.js";
4
+ import {
5
+ createMdxLoader
6
+ } from "../chunk-XQ5O7IPO.js";
7
+ import "../chunk-3J3WL7WN.js";
8
+ import "../chunk-K5ZLPEIQ.js";
9
+ import {
10
+ createCore,
11
+ findConfigFile
12
+ } from "../chunk-EELYB2XC.js";
13
+ import "../chunk-VWJKRQZR.js";
14
+
15
+ // src/bun/index.ts
16
+ import { parse } from "querystring";
17
+ import { pathToFileURL } from "url";
18
+ function createMdxPlugin(options = {}) {
19
+ const {
20
+ environment = "bun",
21
+ outDir = ".source",
22
+ configPath = findConfigFile()
23
+ } = options;
24
+ async function getMdxLoader() {
25
+ const importPath = pathToFileURL(configPath).href;
26
+ const core = await createCore({
27
+ environment,
28
+ outDir,
29
+ configPath
30
+ }).init({
31
+ config: buildConfig(await import(importPath))
32
+ });
33
+ return createMdxLoader(core.creatConfigLoader());
34
+ }
35
+ return {
36
+ name: "bun-plugin-fumadocs-mdx",
37
+ setup(build) {
38
+ const mdxLoader = getMdxLoader();
39
+ build.onLoad({ filter: /\.mdx(\?.+?)?$/ }, async (args) => {
40
+ const [filePath, query] = args.path.split("?", 2);
41
+ const content = await Bun.file(filePath).text();
42
+ const result = await (await mdxLoader)({
43
+ source: content,
44
+ query: parse(query),
45
+ filePath,
46
+ development: false,
47
+ compiler: {
48
+ addDependency() {
49
+ }
50
+ }
51
+ });
52
+ return {
53
+ contents: result.code,
54
+ loader: "js"
55
+ };
56
+ });
57
+ }
58
+ };
59
+ }
60
+ export {
61
+ createMdxPlugin
62
+ };
@@ -0,0 +1,160 @@
1
+ import {
2
+ remarkInclude
3
+ } from "./chunk-K5ZLPEIQ.js";
4
+
5
+ // src/loaders/mdx/build-mdx.ts
6
+ import { createProcessor } from "@mdx-js/mdx";
7
+
8
+ // src/loaders/mdx/remark-postprocess.ts
9
+ import { visit } from "unist-util-visit";
10
+ import { toMarkdown } from "mdast-util-to-markdown";
11
+ import { valueToEstree } from "estree-util-value-to-estree";
12
+ import { removePosition } from "unist-util-remove-position";
13
+ import remarkMdx from "remark-mdx";
14
+ function remarkPostprocess({
15
+ _format,
16
+ includeProcessedMarkdown = false,
17
+ includeMDAST = false,
18
+ valueToExport = []
19
+ }) {
20
+ let _stringifyProcessor;
21
+ const getStringifyProcessor = () => {
22
+ if (_format === "mdx") return this;
23
+ return _stringifyProcessor ??= this().use(remarkMdx).freeze();
24
+ };
25
+ return (tree, file) => {
26
+ let title;
27
+ const urls = [];
28
+ visit(tree, ["heading", "link"], (node) => {
29
+ if (node.type === "heading" && node.depth === 1) {
30
+ title = flattenNode(node);
31
+ }
32
+ if (node.type !== "link") return;
33
+ urls.push({
34
+ href: node.url
35
+ });
36
+ return "skip";
37
+ });
38
+ if (title) {
39
+ file.data.frontmatter ??= {};
40
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
41
+ }
42
+ file.data.extractedReferences = urls;
43
+ if (includeProcessedMarkdown) {
44
+ const processor = getStringifyProcessor();
45
+ file.data._markdown = toMarkdown(tree, {
46
+ ...processor.data("settings"),
47
+ // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
48
+ extensions: processor.data("toMarkdownExtensions") || []
49
+ });
50
+ }
51
+ if (includeMDAST) {
52
+ const options = includeMDAST === true ? {} : includeMDAST;
53
+ file.data._mdast = JSON.stringify(
54
+ options.removePosition ? removePosition(structuredClone(tree)) : tree
55
+ );
56
+ }
57
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
58
+ tree.children.unshift(getMdastExport(name, value));
59
+ }
60
+ for (const name of valueToExport) {
61
+ if (!(name in file.data)) continue;
62
+ tree.children.unshift(getMdastExport(name, file.data[name]));
63
+ }
64
+ };
65
+ }
66
+ function getMdastExport(name, value) {
67
+ return {
68
+ type: "mdxjsEsm",
69
+ value: "",
70
+ data: {
71
+ estree: {
72
+ type: "Program",
73
+ sourceType: "module",
74
+ body: [
75
+ {
76
+ type: "ExportNamedDeclaration",
77
+ attributes: [],
78
+ specifiers: [],
79
+ source: null,
80
+ declaration: {
81
+ type: "VariableDeclaration",
82
+ kind: "let",
83
+ declarations: [
84
+ {
85
+ type: "VariableDeclarator",
86
+ id: {
87
+ type: "Identifier",
88
+ name
89
+ },
90
+ init: valueToEstree(value)
91
+ }
92
+ ]
93
+ }
94
+ }
95
+ ]
96
+ }
97
+ }
98
+ };
99
+ }
100
+ function flattenNode(node) {
101
+ if ("children" in node)
102
+ return node.children.map((child) => flattenNode(child)).join("");
103
+ if ("value" in node) return node.value;
104
+ return "";
105
+ }
106
+
107
+ // src/loaders/mdx/build-mdx.ts
108
+ var cache = /* @__PURE__ */ new Map();
109
+ async function buildMDX(cacheKey, source, options) {
110
+ const { filePath, frontmatter, data, _compiler, ...rest } = options;
111
+ function getProcessor(format) {
112
+ const key = `${cacheKey}:${format}`;
113
+ let processor = cache.get(key);
114
+ if (!processor) {
115
+ processor = createProcessor({
116
+ outputFormat: "program",
117
+ ...rest,
118
+ remarkPlugins: [
119
+ remarkInclude,
120
+ ...rest.remarkPlugins ?? [],
121
+ [
122
+ remarkPostprocess,
123
+ {
124
+ _format: format,
125
+ ...options.postprocess,
126
+ valueToExport: [
127
+ ...options.postprocess?.valueToExport ?? [],
128
+ "structuredData",
129
+ "extractedReferences",
130
+ "frontmatter",
131
+ "lastModified",
132
+ "_markdown",
133
+ "_mdast"
134
+ ]
135
+ }
136
+ ]
137
+ ],
138
+ format
139
+ });
140
+ cache.set(key, processor);
141
+ }
142
+ return processor;
143
+ }
144
+ return getProcessor(
145
+ options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
146
+ ).process({
147
+ value: source,
148
+ path: filePath,
149
+ data: {
150
+ ...data,
151
+ frontmatter,
152
+ _compiler,
153
+ _getProcessor: getProcessor
154
+ }
155
+ });
156
+ }
157
+
158
+ export {
159
+ buildMDX
160
+ };
@@ -0,0 +1,45 @@
1
+ // src/utils/import-formatter.ts
2
+ import path from "path";
3
+ function getImportCode(info) {
4
+ const specifier = JSON.stringify(info.specifier);
5
+ if (info.type === "default") return `import ${info.name} from ${specifier}`;
6
+ if (info.type === "namespace")
7
+ return `import * as ${info.name} from ${specifier}`;
8
+ if (info.type === "named") {
9
+ const names = info.names.map(
10
+ (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
11
+ );
12
+ return `import { ${names.join(", ")} } from ${specifier}`;
13
+ }
14
+ return `import ${specifier}`;
15
+ }
16
+ function toImportPath(file, config) {
17
+ const ext = path.extname(file);
18
+ let filename;
19
+ if (ext === ".ts" && config.jsExtension) {
20
+ filename = file.substring(0, file.length - ext.length) + ".js";
21
+ } else if (ext === ".ts") {
22
+ filename = file.substring(0, file.length - ext.length);
23
+ } else {
24
+ filename = file;
25
+ }
26
+ let importPath;
27
+ if ("relativeTo" in config) {
28
+ importPath = path.relative(config.relativeTo, filename);
29
+ if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
30
+ importPath = `./${importPath}`;
31
+ }
32
+ } else {
33
+ importPath = path.resolve(filename);
34
+ }
35
+ return importPath.replaceAll(path.sep, "/");
36
+ }
37
+ function ident(code, tab = 1) {
38
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
39
+ }
40
+
41
+ export {
42
+ getImportCode,
43
+ toImportPath,
44
+ ident
45
+ };
@@ -0,0 +1,207 @@
1
+ // src/loaders/config/index.ts
2
+ import path from "path";
3
+ import fs from "fs/promises";
4
+ function findConfigFile() {
5
+ return path.resolve("source.config.ts");
6
+ }
7
+ function staticConfig({
8
+ core,
9
+ buildConfig
10
+ }) {
11
+ let cached;
12
+ async function newConfig() {
13
+ const { loadConfig } = await import("./load-MNG3CLET.js");
14
+ await core.init({
15
+ config: loadConfig(
16
+ core._options.configPath,
17
+ core._options.outDir,
18
+ buildConfig
19
+ )
20
+ });
21
+ return core.getConfig();
22
+ }
23
+ return {
24
+ async getConfig() {
25
+ return cached ??= newConfig();
26
+ }
27
+ };
28
+ }
29
+ function dynamicConfig({
30
+ core,
31
+ buildConfig
32
+ }) {
33
+ let loaded;
34
+ async function getConfigHash() {
35
+ const stats = await fs.stat(core._options.configPath).catch(() => void 0);
36
+ if (stats) {
37
+ return stats.mtime.getTime().toString();
38
+ }
39
+ throw new Error("Cannot find config file");
40
+ }
41
+ async function newConfig() {
42
+ const { loadConfig } = await import("./load-MNG3CLET.js");
43
+ await core.init({
44
+ config: loadConfig(
45
+ core._options.configPath,
46
+ core._options.outDir,
47
+ buildConfig
48
+ )
49
+ });
50
+ return core.getConfig();
51
+ }
52
+ return {
53
+ async getConfig() {
54
+ const hash = await getConfigHash();
55
+ if (loaded && loaded.hash === hash) return loaded.config;
56
+ loaded = {
57
+ hash,
58
+ config: newConfig()
59
+ };
60
+ return loaded.config;
61
+ }
62
+ };
63
+ }
64
+
65
+ // src/utils/validation.ts
66
+ import picocolors from "picocolors";
67
+ var ValidationError = class extends Error {
68
+ constructor(message, issues) {
69
+ super(
70
+ `${message}:
71
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
72
+ );
73
+ this.title = message;
74
+ this.issues = issues;
75
+ }
76
+ toStringFormatted() {
77
+ return [
78
+ picocolors.bold(`[MDX] ${this.title}:`),
79
+ ...this.issues.map(
80
+ (issue) => picocolors.redBright(
81
+ `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
82
+ )
83
+ )
84
+ ].join("\n");
85
+ }
86
+ };
87
+ async function validate(schema, data, context, errorMessage) {
88
+ if (typeof schema === "function" && !("~standard" in schema)) {
89
+ schema = schema(context);
90
+ }
91
+ if ("~standard" in schema) {
92
+ const result = await schema["~standard"].validate(
93
+ data
94
+ );
95
+ if (result.issues) {
96
+ throw new ValidationError(errorMessage, result.issues);
97
+ }
98
+ return result.value;
99
+ }
100
+ return data;
101
+ }
102
+
103
+ // src/core.ts
104
+ import path2 from "path";
105
+ import fs2 from "fs/promises";
106
+ function createCore(options, defaultPlugins = []) {
107
+ let config;
108
+ let plugins;
109
+ return {
110
+ _options: options,
111
+ getPluginContext() {
112
+ return {
113
+ core: this,
114
+ ...options
115
+ };
116
+ },
117
+ /**
118
+ * Convenient cache store, reset when config changes
119
+ */
120
+ cache: /* @__PURE__ */ new Map(),
121
+ async init({ config: newConfig }) {
122
+ config = await newConfig;
123
+ this.cache.clear();
124
+ plugins = [];
125
+ for await (const option of [
126
+ ...defaultPlugins,
127
+ ...config.global.plugins ?? []
128
+ ]) {
129
+ if (!option) continue;
130
+ if (Array.isArray(option)) plugins.push(...option);
131
+ else plugins.push(option);
132
+ }
133
+ for (const plugin of plugins) {
134
+ const out = await plugin.config?.call(this.getPluginContext(), config);
135
+ if (out) config = out;
136
+ }
137
+ return this;
138
+ },
139
+ getConfig() {
140
+ return config;
141
+ },
142
+ creatConfigLoader() {
143
+ return {
144
+ getConfig() {
145
+ return config;
146
+ }
147
+ };
148
+ },
149
+ async initServer(server) {
150
+ for (const plugin of plugins) {
151
+ await plugin.configureServer?.call(this.getPluginContext(), server);
152
+ }
153
+ },
154
+ async emitAndWrite({
155
+ filterPlugin = () => true
156
+ } = {}) {
157
+ const start = performance.now();
158
+ const out = await Promise.all(
159
+ plugins.map((plugin) => {
160
+ if (!filterPlugin(plugin) || !plugin.emit) return [];
161
+ return plugin.emit.call(this.getPluginContext());
162
+ })
163
+ );
164
+ await Promise.all(
165
+ out.flat().map(async (entry) => {
166
+ const file = path2.join(options.outDir, entry.path);
167
+ await fs2.mkdir(path2.dirname(file), { recursive: true });
168
+ await fs2.writeFile(file, entry.content);
169
+ })
170
+ );
171
+ console.log(`[MDX] generated files in ${performance.now() - start}ms`);
172
+ }
173
+ };
174
+ }
175
+
176
+ // src/utils/git-timestamp.ts
177
+ import path3 from "path";
178
+ import { x } from "tinyexec";
179
+ var cache = /* @__PURE__ */ new Map();
180
+ async function getGitTimestamp(file) {
181
+ const cached = cache.get(file);
182
+ if (cached) return cached;
183
+ try {
184
+ const out = await x(
185
+ "git",
186
+ ["log", "-1", '--pretty="%ai"', path3.relative(process.cwd(), file)],
187
+ {
188
+ throwOnError: true
189
+ }
190
+ );
191
+ const time = new Date(out.stdout);
192
+ cache.set(file, time);
193
+ return time;
194
+ } catch {
195
+ return;
196
+ }
197
+ }
198
+
199
+ export {
200
+ findConfigFile,
201
+ staticConfig,
202
+ dynamicConfig,
203
+ ValidationError,
204
+ validate,
205
+ getGitTimestamp,
206
+ createCore
207
+ };
@@ -0,0 +1,80 @@
1
+ // src/loaders/mdx/preset.ts
2
+ import * as plugins from "fumadocs-core/mdx-plugins";
3
+ function pluginOption(def, options = []) {
4
+ const list = def(Array.isArray(options) ? options : []).filter(
5
+ Boolean
6
+ );
7
+ if (typeof options === "function") {
8
+ return options(list);
9
+ }
10
+ return list;
11
+ }
12
+ function getDefaultMDXOptions({
13
+ valueToExport = [],
14
+ rehypeCodeOptions,
15
+ remarkImageOptions,
16
+ remarkHeadingOptions,
17
+ remarkStructureOptions,
18
+ remarkCodeTabOptions,
19
+ remarkNpmOptions,
20
+ _withoutBundler = false,
21
+ ...mdxOptions
22
+ }) {
23
+ const remarkPlugins = pluginOption(
24
+ (v) => [
25
+ plugins.remarkGfm,
26
+ [
27
+ plugins.remarkHeading,
28
+ {
29
+ generateToc: false,
30
+ ...remarkHeadingOptions
31
+ }
32
+ ],
33
+ remarkImageOptions !== false && [
34
+ plugins.remarkImage,
35
+ {
36
+ ...remarkImageOptions,
37
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
38
+ }
39
+ ],
40
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
41
+ plugins.remarkCodeTab,
42
+ remarkCodeTabOptions
43
+ ],
44
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
45
+ ...v,
46
+ remarkStructureOptions !== false && [
47
+ plugins.remarkStructure,
48
+ remarkStructureOptions
49
+ ],
50
+ () => {
51
+ return (_, file) => {
52
+ file.data["mdx-export"] ??= [];
53
+ for (const name of valueToExport) {
54
+ if (name in file.data)
55
+ file.data["mdx-export"].push({ name, value: file.data[name] });
56
+ }
57
+ };
58
+ }
59
+ ],
60
+ mdxOptions.remarkPlugins
61
+ );
62
+ const rehypePlugins = pluginOption(
63
+ (v) => [
64
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
65
+ ...v,
66
+ plugins.rehypeToc
67
+ ],
68
+ mdxOptions.rehypePlugins
69
+ );
70
+ return {
71
+ ...mdxOptions,
72
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
73
+ remarkPlugins,
74
+ rehypePlugins
75
+ };
76
+ }
77
+
78
+ export {
79
+ getDefaultMDXOptions
80
+ };
@@ -0,0 +1,77 @@
1
+ // src/runtime/vite/base.ts
2
+ import { createElement, lazy } from "react";
3
+ function fromConfigBase() {
4
+ function normalize(entries, base) {
5
+ const out = {};
6
+ for (const k in entries) {
7
+ const mappedK = k.startsWith("./") ? k.slice(2) : k;
8
+ if (base) Object.assign(entries[k], { base });
9
+ out[mappedK] = entries[k];
10
+ }
11
+ return out;
12
+ }
13
+ return {
14
+ doc(_, base, glob) {
15
+ return normalize(glob, base);
16
+ },
17
+ meta(_, base, glob) {
18
+ return normalize(glob, base);
19
+ },
20
+ docLazy(_, base, head, body) {
21
+ return {
22
+ base,
23
+ head: normalize(head),
24
+ body: normalize(body)
25
+ };
26
+ }
27
+ };
28
+ }
29
+ var loaderStore = /* @__PURE__ */ new Map();
30
+ function createClientLoader(files, options) {
31
+ const { id = "", component } = options;
32
+ let renderer;
33
+ const store = loaderStore.get(id) ?? {
34
+ preloaded: /* @__PURE__ */ new Map()
35
+ };
36
+ loaderStore.set(id, store);
37
+ function getRenderer() {
38
+ if (renderer) return renderer;
39
+ renderer = {};
40
+ for (const k in files) {
41
+ const OnDemand = lazy(async () => {
42
+ const loaded = await files[k]();
43
+ return { default: (props) => component(loaded, props) };
44
+ });
45
+ renderer[k] = (props) => {
46
+ const cached = store.preloaded.get(k);
47
+ if (!cached) return createElement(OnDemand, props);
48
+ return component(cached, props);
49
+ };
50
+ }
51
+ return renderer;
52
+ }
53
+ return {
54
+ async preload(path) {
55
+ const loaded = await files[path]();
56
+ store.preloaded.set(path, loaded);
57
+ return loaded;
58
+ },
59
+ getRenderer,
60
+ getComponent(path) {
61
+ return getRenderer()[path];
62
+ },
63
+ useContent(path, props) {
64
+ const Comp = this.getComponent(path);
65
+ return createElement(Comp, props);
66
+ }
67
+ };
68
+ }
69
+ function toClientRenderer(files, component) {
70
+ return createClientLoader(files, { component }).getRenderer();
71
+ }
72
+
73
+ export {
74
+ fromConfigBase,
75
+ createClientLoader,
76
+ toClientRenderer
77
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ buildConfig
3
+ } from "./chunk-U4MQ44TS.js";
4
+
5
+ // src/loaders/config/load.ts
6
+ import * as path from "path";
7
+ import { pathToFileURL } from "url";
8
+ async function compileConfig(configPath, outDir) {
9
+ const { build } = await import("esbuild");
10
+ const transformed = await build({
11
+ entryPoints: [{ in: configPath, out: "source.config" }],
12
+ bundle: true,
13
+ outdir: outDir,
14
+ target: "node20",
15
+ write: true,
16
+ platform: "node",
17
+ format: "esm",
18
+ packages: "external",
19
+ outExtension: {
20
+ ".js": ".mjs"
21
+ },
22
+ allowOverwrite: true
23
+ });
24
+ if (transformed.errors.length > 0) {
25
+ throw new Error("failed to compile configuration file");
26
+ }
27
+ }
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"));
31
+ url.searchParams.set("hash", Date.now().toString());
32
+ const config = import(url.href).then(
33
+ (loaded) => buildConfig(loaded)
34
+ );
35
+ return await config;
36
+ }
37
+
38
+ export {
39
+ loadConfig
40
+ };