fumadocs-mdx 14.2.2 → 14.2.4

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 (116) hide show
  1. package/dist/adapter-DG-viEbG.js +144 -0
  2. package/dist/adapter-DG-viEbG.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -12
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-BTTNEFmV.js +100 -0
  7. package/dist/build-BTTNEFmV.js.map +1 -0
  8. package/dist/build-mdx-10MrLupc.d.ts +53 -0
  9. package/dist/build-mdx-10MrLupc.d.ts.map +1 -0
  10. package/dist/build-mdx-BVeBo4jT.js +153 -0
  11. package/dist/build-mdx-BVeBo4jT.js.map +1 -0
  12. package/dist/build-mdx-ChjP7zAn.js +5 -0
  13. package/dist/bun/index.d.ts +10 -21
  14. package/dist/bun/index.d.ts.map +1 -0
  15. package/dist/bun/index.js +30 -49
  16. package/dist/bun/index.js.map +1 -0
  17. package/dist/codegen-DleOVLNr.js +101 -0
  18. package/dist/codegen-DleOVLNr.js.map +1 -0
  19. package/dist/config/index.d.ts +2 -18
  20. package/dist/config/index.js +50 -53
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/core-DG43f_AU.d.ts +364 -0
  23. package/dist/core-DG43f_AU.d.ts.map +1 -0
  24. package/dist/core-DjldE3H9.js +212 -0
  25. package/dist/core-DjldE3H9.js.map +1 -0
  26. package/dist/fuma-matter-CHgJa_-B.js +27 -0
  27. package/dist/fuma-matter-CHgJa_-B.js.map +1 -0
  28. package/dist/index-Bc_4I1HE.d.ts +12 -0
  29. package/dist/index-Bc_4I1HE.d.ts.map +1 -0
  30. package/dist/index-file-D9HsrWU_.js +264 -0
  31. package/dist/index-file-D9HsrWU_.js.map +1 -0
  32. package/dist/index.d.ts +3 -61
  33. package/dist/index.js +1 -0
  34. package/dist/load-from-file-B7Rswy9i.js +5 -0
  35. package/dist/load-from-file-Doc98oEB.js +38 -0
  36. package/dist/load-from-file-Doc98oEB.js.map +1 -0
  37. package/dist/loaders-BVwYfelL.js +7 -0
  38. package/dist/loaders-BVwYfelL.js.map +1 -0
  39. package/dist/mdx-DMZ9tsAa.js +91 -0
  40. package/dist/mdx-DMZ9tsAa.js.map +1 -0
  41. package/dist/meta-DyieTM4Z.js +81 -0
  42. package/dist/meta-DyieTM4Z.js.map +1 -0
  43. package/dist/next/index.cjs +863 -1076
  44. package/dist/next/index.d.ts +17 -28
  45. package/dist/next/index.d.ts.map +1 -0
  46. package/dist/next/index.js +141 -170
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/node/loader.d.ts +4 -2
  49. package/dist/node/loader.d.ts.map +1 -0
  50. package/dist/node/loader.js +26 -38
  51. package/dist/node/loader.js.map +1 -0
  52. package/dist/plugins/index-file.d.ts +2 -14
  53. package/dist/plugins/index-file.js +5 -8
  54. package/dist/plugins/json-schema.d.ts +14 -23
  55. package/dist/plugins/json-schema.d.ts.map +1 -0
  56. package/dist/plugins/json-schema.js +70 -78
  57. package/dist/plugins/json-schema.js.map +1 -0
  58. package/dist/plugins/last-modified.d.ts +21 -32
  59. package/dist/plugins/last-modified.d.ts.map +1 -0
  60. package/dist/plugins/last-modified.js +70 -78
  61. package/dist/plugins/last-modified.js.map +1 -0
  62. package/dist/preset-gmDZnBcg.js +61 -0
  63. package/dist/preset-gmDZnBcg.js.map +1 -0
  64. package/dist/remark-include-D3G3mAnv.js +247 -0
  65. package/dist/remark-include-D3G3mAnv.js.map +1 -0
  66. package/dist/runtime/browser.d.ts +32 -41
  67. package/dist/runtime/browser.d.ts.map +1 -0
  68. package/dist/runtime/browser.js +56 -63
  69. package/dist/runtime/browser.js.map +1 -0
  70. package/dist/runtime/dynamic.d.ts +13 -21
  71. package/dist/runtime/dynamic.d.ts.map +1 -0
  72. package/dist/runtime/dynamic.js +64 -76
  73. package/dist/runtime/dynamic.js.map +1 -0
  74. package/dist/runtime/server.d.ts +2 -14
  75. package/dist/runtime/server.js +111 -8
  76. package/dist/runtime/server.js.map +1 -0
  77. package/dist/runtime/types.d.ts +2 -61
  78. package/dist/runtime/types.js +1 -0
  79. package/dist/types-B6myALSk.d.ts +63 -0
  80. package/dist/types-B6myALSk.d.ts.map +1 -0
  81. package/dist/vite/index.d.ts +28 -39
  82. package/dist/vite/index.d.ts.map +1 -0
  83. package/dist/vite/index.js +79 -122
  84. package/dist/vite/index.js.map +1 -0
  85. package/dist/webpack/mdx.d.ts +6 -3
  86. package/dist/webpack/mdx.d.ts.map +1 -0
  87. package/dist/webpack/mdx.js +21 -34
  88. package/dist/webpack/mdx.js.map +1 -0
  89. package/dist/webpack/meta.d.ts +6 -3
  90. package/dist/webpack/meta.d.ts.map +1 -0
  91. package/dist/webpack/meta.js +23 -37
  92. package/dist/webpack/meta.js.map +1 -0
  93. package/dist/webpack--VSEE6Zp.js +15 -0
  94. package/dist/webpack--VSEE6Zp.js.map +1 -0
  95. package/loader-mdx.cjs +1 -3
  96. package/loader-meta.cjs +1 -3
  97. package/package.json +38 -38
  98. package/dist/build-mdx-5XLFMP5P.js +0 -8
  99. package/dist/chunk-257RZJEQ.js +0 -17
  100. package/dist/chunk-2PY3JUIC.js +0 -126
  101. package/dist/chunk-4EUH5CD2.js +0 -173
  102. package/dist/chunk-4JSFLXXT.js +0 -8
  103. package/dist/chunk-5OBUOALK.js +0 -141
  104. package/dist/chunk-DTFUANSF.js +0 -40
  105. package/dist/chunk-KWSETXYC.js +0 -274
  106. package/dist/chunk-OLD35ARB.js +0 -116
  107. package/dist/chunk-S7KOJHHO.js +0 -89
  108. package/dist/chunk-STLEUNK7.js +0 -335
  109. package/dist/chunk-USQZ5OLE.js +0 -116
  110. package/dist/chunk-VWJKRQZR.js +0 -19
  111. package/dist/chunk-WFDF56IJ.js +0 -290
  112. package/dist/chunk-WSQ23PNV.js +0 -179
  113. package/dist/chunk-ZAYZWFWP.js +0 -89
  114. package/dist/core-X5ggQtBM.d.ts +0 -350
  115. package/dist/index-BqkSNsGO.d.ts +0 -8
  116. package/dist/load-from-file-FHW724YY.js +0 -8
@@ -0,0 +1,144 @@
1
+ import { r as ValidationError } from "./core-DjldE3H9.js";
2
+ import { readFileSync } from "node:fs";
3
+ import fs from "node:fs/promises";
4
+ import { fileURLToPath } from "node:url";
5
+ import { parse } from "node:querystring";
6
+
7
+ //#region src/loaders/config.ts
8
+ function createStandaloneConfigLoader({ core, buildConfig, mode }) {
9
+ let prev;
10
+ async function getConfigHash() {
11
+ if (mode === "production") return "static";
12
+ return (await fs.stat(core.getOptions().configPath).catch(() => {
13
+ throw new Error("Cannot find config file");
14
+ })).mtime.getTime().toString();
15
+ }
16
+ return { async getCore() {
17
+ const hash = await getConfigHash();
18
+ if (!prev || hash !== prev.hash) prev = {
19
+ hash,
20
+ init: (async () => {
21
+ const { loadConfig } = await import("./load-from-file-B7Rswy9i.js");
22
+ await core.init({ config: loadConfig(core, buildConfig) });
23
+ })()
24
+ };
25
+ await prev.init;
26
+ return core;
27
+ } };
28
+ }
29
+ /**
30
+ * create config loader from initialized core
31
+ */
32
+ function createIntegratedConfigLoader(core) {
33
+ return { async getCore() {
34
+ return core;
35
+ } };
36
+ }
37
+
38
+ //#endregion
39
+ //#region src/loaders/adapter.ts
40
+ function toNode(loader) {
41
+ return async (url, _context, nextLoad) => {
42
+ if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
43
+ const parsedUrl = new URL(url);
44
+ const filePath = fileURLToPath(parsedUrl);
45
+ const result = await loader.load({
46
+ filePath,
47
+ query: Object.fromEntries(parsedUrl.searchParams.entries()),
48
+ async getSource() {
49
+ return (await fs.readFile(filePath)).toString();
50
+ },
51
+ development: false,
52
+ compiler: { addDependency() {} }
53
+ });
54
+ if (result) return {
55
+ source: result.code,
56
+ format: "module",
57
+ shortCircuit: true
58
+ };
59
+ }
60
+ return nextLoad(url);
61
+ };
62
+ }
63
+ function toVite(loader) {
64
+ return {
65
+ filter(id) {
66
+ return !loader.test || loader.test.test(id);
67
+ },
68
+ async transform(value, id) {
69
+ const [file, query = ""] = id.split("?", 2);
70
+ const result = await loader.load({
71
+ filePath: file,
72
+ query: parse(query),
73
+ getSource() {
74
+ return value;
75
+ },
76
+ development: this.environment.mode === "dev",
77
+ compiler: { addDependency: (file$1) => {
78
+ this.addWatchFile(file$1);
79
+ } }
80
+ });
81
+ if (result === null) return null;
82
+ return {
83
+ code: result.code,
84
+ map: result.map,
85
+ moduleType: result.moduleType
86
+ };
87
+ }
88
+ };
89
+ }
90
+ /**
91
+ * need to handle the `test` regex in Webpack config instead.
92
+ */
93
+ function toWebpack(loader) {
94
+ return async function(source, callback) {
95
+ try {
96
+ const result = await loader.load({
97
+ filePath: this.resourcePath,
98
+ query: parse(this.resourceQuery.slice(1)),
99
+ getSource() {
100
+ return source;
101
+ },
102
+ development: this.mode === "development",
103
+ compiler: this
104
+ });
105
+ if (result === null) callback(void 0, source);
106
+ else callback(void 0, result.code, result.map);
107
+ } catch (error) {
108
+ if (error instanceof ValidationError) return callback(new Error(await error.toStringFormatted()));
109
+ if (!(error instanceof Error)) throw error;
110
+ callback(error);
111
+ }
112
+ };
113
+ }
114
+ function toBun(loader) {
115
+ function toResult(output) {
116
+ if (!output) return;
117
+ return {
118
+ contents: output.code,
119
+ loader: output.moduleType ?? "js"
120
+ };
121
+ }
122
+ return (build) => {
123
+ build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {
124
+ const [filePath, query = ""] = args.path.split("?", 2);
125
+ const input = {
126
+ async getSource() {
127
+ return Bun.file(filePath).text();
128
+ },
129
+ query: parse(query),
130
+ filePath,
131
+ development: false,
132
+ compiler: { addDependency() {} }
133
+ };
134
+ if (loader.bun?.load) return loader.bun.load(readFileSync(filePath).toString(), input);
135
+ const result = loader.load(input);
136
+ if (result instanceof Promise) return result.then(toResult);
137
+ return toResult(result);
138
+ });
139
+ };
140
+ }
141
+
142
+ //#endregion
143
+ export { createIntegratedConfigLoader as a, toWebpack as i, toNode as n, createStandaloneConfigLoader as o, toVite as r, toBun as t };
144
+ //# sourceMappingURL=adapter-DG-viEbG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-DG-viEbG.js","names":["prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined","file","input: LoaderInput"],"sources":["../src/loaders/config.ts","../src/loaders/adapter.ts"],"sourcesContent":["import type { Core } from '@/core';\nimport fs from 'node:fs/promises';\n\nexport interface ConfigLoader {\n getCore(): Promise<Core>;\n}\n\nexport function createStandaloneConfigLoader({\n core,\n buildConfig,\n mode,\n}: {\n /**\n * core (not initialized)\n */\n core: Core;\n buildConfig: boolean;\n /**\n * In dev mode, the config file is dynamically re-loaded when it's updated.\n */\n mode: 'dev' | 'production';\n}): ConfigLoader {\n let prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined;\n\n async function getConfigHash(): Promise<string> {\n if (mode === 'production') return 'static';\n\n const stats = await fs.stat(core.getOptions().configPath).catch(() => {\n throw new Error('Cannot find config file');\n });\n\n return stats.mtime.getTime().toString();\n }\n\n return {\n async getCore() {\n const hash = await getConfigHash();\n if (!prev || hash !== prev.hash) {\n prev = {\n hash,\n init: (async () => {\n const { loadConfig } = await import('../config/load-from-file');\n\n await core.init({\n config: loadConfig(core, buildConfig),\n });\n })(),\n };\n }\n\n await prev.init;\n return core;\n },\n };\n}\n\n/**\n * create config loader from initialized core\n */\nexport function createIntegratedConfigLoader(core: Core): ConfigLoader {\n return {\n async getCore() {\n return core;\n },\n };\n}\n","import type { CompilerOptions } from '@/loaders/mdx/build-mdx';\nimport type { LoadFnOutput, LoadHook } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport type { SourceMap, TransformPluginContext } from 'rollup';\nimport type { TransformResult } from 'vite';\nimport { parse } from 'node:querystring';\nimport { ValidationError } from '@/utils/validation';\nimport type { LoaderContext } from 'webpack';\nimport { readFileSync } from 'node:fs';\n\nexport interface LoaderInput {\n development: boolean;\n compiler: CompilerOptions;\n\n filePath: string;\n query: Record<string, string | string[] | undefined>;\n getSource: () => string | Promise<string>;\n}\n\nexport interface LoaderOutput {\n code: string;\n map?: unknown;\n\n /**\n * Only supported in Vite 8.\n *\n * Explicitly define the transformed module type, for unsupported environments, you need to consider the differences between each bundler.\n */\n moduleType?: 'js' | 'json';\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface Loader {\n /**\n * Filter file paths, the input can be either a file URL or file path.\n *\n * Must take resource query into consideration.\n */\n test?: RegExp;\n\n /**\n * Transform input into JavaScript.\n *\n * Returns:\n * - `LoaderOutput`: JavaScript code & source map.\n * - `null`: skip the loader. Fallback to default behaviour if possible, otherwise the adapter will try workarounds.\n */\n load: (input: LoaderInput) => Awaitable<LoaderOutput | null>;\n\n bun?: {\n /**\n * 1. Bun doesn't allow `null` in loaders.\n * 2. Bun requires sync result to support dynamic require().\n */\n load?: (source: string, input: LoaderInput) => Awaitable<Bun.OnLoadResult>;\n };\n}\n\nexport function toNode(loader: Loader): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (url.startsWith('file:///') && (!loader.test || loader.test.test(url))) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await loader.load({\n filePath,\n query: Object.fromEntries(parsedUrl.searchParams.entries()),\n async getSource() {\n return (await fs.readFile(filePath)).toString();\n },\n development: false,\n compiler: {\n addDependency() {},\n },\n });\n\n if (result) {\n return {\n source: result.code,\n format: 'module',\n shortCircuit: true,\n };\n }\n }\n\n return nextLoad(url);\n };\n}\n\nexport interface ViteLoader {\n filter: (id: string) => boolean;\n\n transform: (\n this: TransformPluginContext,\n value: string,\n id: string,\n ) => Promise<TransformResult | null>;\n}\n\nexport function toVite(loader: Loader): ViteLoader {\n return {\n filter(id) {\n return !loader.test || loader.test.test(id);\n },\n async transform(value, id) {\n const [file, query = ''] = id.split('?', 2);\n\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === 'dev',\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n moduleType: result.moduleType,\n };\n },\n };\n}\n\nexport type WebpackLoader = (\n this: LoaderContext<unknown>,\n source: string,\n callback: LoaderContext<unknown>['callback'],\n) => Promise<void>;\n\n/**\n * need to handle the `test` regex in Webpack config instead.\n */\nexport function toWebpack(loader: Loader): WebpackLoader {\n return async function (source, callback) {\n try {\n const result = await loader.load({\n filePath: this.resourcePath,\n query: parse(this.resourceQuery.slice(1)),\n getSource() {\n return source;\n },\n development: this.mode === 'development',\n compiler: this,\n });\n\n if (result === null) {\n callback(undefined, source);\n } else {\n callback(undefined, result.code, result.map as string);\n }\n } catch (error) {\n if (error instanceof ValidationError) {\n return callback(new Error(await error.toStringFormatted()));\n }\n\n if (!(error instanceof Error)) throw error;\n callback(error);\n }\n };\n}\n\nexport function toBun(loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? 'js',\n };\n }\n\n return (build: Bun.PluginBuilder) => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {\n const [filePath, query = ''] = args.path.split('?', 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n compiler: {\n addDependency() {},\n },\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath).toString(), input);\n }\n\n const result = loader.load(input);\n if (result instanceof Promise) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,6BAA6B,EAC3C,MACA,aACA,QAWe;CACf,IAAIA;CAOJ,eAAe,gBAAiC;AAC9C,MAAI,SAAS,aAAc,QAAO;AAMlC,UAJc,MAAM,GAAG,KAAK,KAAK,YAAY,CAAC,WAAW,CA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OAAO,IAAI,KAAK,aAAa,SAAS,CAAC,UAAU,EAAE,MAAM;GAGlE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,kBAAkB,QACpB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
package/dist/bin.d.ts CHANGED
@@ -1 +1 @@
1
- #!/usr/bin/env node
1
+ export { };
package/dist/bin.js CHANGED
@@ -1,16 +1,25 @@
1
1
  #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
2
3
 
3
- // src/bin.ts
4
- import { existsSync } from "fs";
4
+ //#region src/bin.ts
5
5
  async function start() {
6
- const [configPath, outDir] = process.argv.slice(2);
7
- const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.mts") || existsSync("next.config.ts");
8
- if (isNext) {
9
- const { postInstall } = await import("./next/index.js");
10
- await postInstall({ configPath, outDir });
11
- } else {
12
- const { postInstall } = await import("./vite/index.js");
13
- await postInstall({ configPath, outDir });
14
- }
6
+ const [configPath, outDir] = process.argv.slice(2);
7
+ if (existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.mts") || existsSync("next.config.ts")) {
8
+ const { postInstall } = await import("./next/index.js");
9
+ await postInstall({
10
+ configPath,
11
+ outDir
12
+ });
13
+ } else {
14
+ const { postInstall } = await import("./vite/index.js");
15
+ await postInstall({
16
+ configPath,
17
+ outDir
18
+ });
19
+ }
15
20
  }
16
- void start();
21
+ start();
22
+
23
+ //#endregion
24
+ export { };
25
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { existsSync } from 'node:fs';\n\nasync function start() {\n const [configPath, outDir] = process.argv.slice(2);\n const isNext =\n existsSync('next.config.js') ||\n existsSync('next.config.mjs') ||\n existsSync('next.config.mts') ||\n existsSync('next.config.ts');\n\n if (isNext) {\n const { postInstall } = await import('./next');\n await postInstall({ configPath, outDir });\n } else {\n const { postInstall } = await import('./vite');\n await postInstall({ configPath, outDir });\n }\n}\n\nvoid start();\n"],"mappings":";;;;AAIA,eAAe,QAAQ;CACrB,MAAM,CAAC,YAAY,UAAU,QAAQ,KAAK,MAAM,EAAE;AAOlD,KALE,WAAW,iBAAiB,IAC5B,WAAW,kBAAkB,IAC7B,WAAW,kBAAkB,IAC7B,WAAW,iBAAiB,EAElB;EACV,MAAM,EAAE,gBAAgB,MAAM,OAAO;AACrC,QAAM,YAAY;GAAE;GAAY;GAAQ,CAAC;QACpC;EACL,MAAM,EAAE,gBAAgB,MAAM,OAAO;AACrC,QAAM,YAAY;GAAE;GAAY;GAAQ,CAAC;;;AAIxC,OAAO"}
@@ -0,0 +1,100 @@
1
+ import { t as applyMdxPreset } from "./preset-gmDZnBcg.js";
2
+ import path from "node:path";
3
+ import picomatch from "picomatch";
4
+
5
+ //#region src/config/build.ts
6
+ const SupportedFormats = {
7
+ doc: ["mdx", "md"],
8
+ meta: ["json", "yaml"]
9
+ };
10
+ function buildCollection(name, collection, cwd) {
11
+ if (collection.type === "docs") return {
12
+ ...collection,
13
+ type: "docs",
14
+ get dir() {
15
+ return this.docs.dir;
16
+ },
17
+ name,
18
+ meta: buildCollection(name, collection.meta, cwd),
19
+ docs: buildCollection(name, collection.docs, cwd),
20
+ hasFile(filePath) {
21
+ return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
22
+ },
23
+ isFileSupported(filePath) {
24
+ return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
25
+ },
26
+ cwd
27
+ };
28
+ return {
29
+ ...collection,
30
+ ...buildPrimitiveCollection(name, collection, cwd)
31
+ };
32
+ }
33
+ function buildPrimitiveCollection(name, config, cwd) {
34
+ const supportedFormats = SupportedFormats[config.type];
35
+ const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
36
+ let matcher;
37
+ return {
38
+ dir: path.resolve(cwd, config.dir),
39
+ cwd,
40
+ name,
41
+ patterns,
42
+ isFileSupported(filePath) {
43
+ return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
44
+ },
45
+ hasFile(filePath) {
46
+ if (!this.isFileSupported(filePath)) return false;
47
+ const relativePath = path.relative(this.dir, filePath);
48
+ if (relativePath.startsWith(`..${path.sep}`)) return false;
49
+ return (matcher ??= picomatch(patterns))(relativePath);
50
+ }
51
+ };
52
+ }
53
+ function buildConfig(config, cwd = process.cwd()) {
54
+ const collections = /* @__PURE__ */ new Map();
55
+ const loaded = {};
56
+ for (const [k, v] of Object.entries(config)) {
57
+ if (!v) continue;
58
+ if (typeof v === "object" && "type" in v) {
59
+ if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
60
+ collections.set(k, buildCollection(k, v, cwd));
61
+ continue;
62
+ }
63
+ }
64
+ if (k === "default" && v) {
65
+ Object.assign(loaded, v);
66
+ continue;
67
+ }
68
+ throw new Error(`Unknown export "${k}", you can only export collections from source configuration file.`);
69
+ }
70
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
71
+ return {
72
+ global: loaded,
73
+ collections,
74
+ workspaces: Object.fromEntries(Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
75
+ return [key, {
76
+ dir: value.dir,
77
+ config: buildConfig(value.config, path.resolve(cwd, value.dir))
78
+ }];
79
+ })),
80
+ getMDXOptions(collection, environment = "bundler") {
81
+ const key = collection ? `${environment}:${collection.name}` : environment;
82
+ const cached = mdxOptionsCache.get(key);
83
+ if (cached) return cached;
84
+ let result;
85
+ if (collection?.mdxOptions) {
86
+ const optionsFn = collection.mdxOptions;
87
+ result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
88
+ } else result = (async () => {
89
+ const optionsFn = this.global.mdxOptions;
90
+ return applyMdxPreset(typeof optionsFn === "function" ? await optionsFn() : optionsFn)(environment);
91
+ })();
92
+ mdxOptionsCache.set(key, result);
93
+ return result;
94
+ }
95
+ };
96
+ }
97
+
98
+ //#endregion
99
+ export { buildConfig as t };
100
+ //# sourceMappingURL=build-BTTNEFmV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-BTTNEFmV.js","names":["matcher: picomatch.Matcher","loaded: GlobalConfig","result: ProcessorOptions | Promise<ProcessorOptions>"],"sources":["../src/config/build.ts"],"sourcesContent":["import type { ProcessorOptions } from '@mdx-js/mdx';\nimport type {\n AnyCollection,\n DocCollection,\n DocsCollection,\n GlobalConfig,\n MetaCollection,\n} from '@/config/define';\nimport picomatch from 'picomatch';\nimport { applyMdxPreset } from '@/config/preset';\nimport path from 'node:path';\n\nexport type BuildEnvironment = 'bundler' | 'runtime';\n\nexport interface LoadedConfig {\n collections: Map<string, CollectionItem>;\n global: GlobalConfig;\n getMDXOptions(\n collection?: DocCollectionItem,\n environment?: BuildEnvironment,\n ): ProcessorOptions | Promise<ProcessorOptions>;\n workspaces: Record<\n string,\n {\n dir: string;\n config: LoadedConfig;\n }\n >;\n}\n\nexport type CollectionItem = MetaCollectionItem | DocCollectionItem | DocsCollectionItem;\n\ninterface PrimitiveCollectionItem {\n name: string;\n cwd: string;\n /**\n * content directory (absolute)\n */\n dir: string;\n hasFile: (filePath: string) => boolean;\n isFileSupported: (filePath: string) => boolean;\n patterns: string[];\n}\n\nexport type MetaCollectionItem = PrimitiveCollectionItem & Omit<MetaCollection, 'files' | 'dir'>;\nexport type DocCollectionItem = PrimitiveCollectionItem & Omit<DocCollection, 'files' | 'dir'>;\n\nexport interface DocsCollectionItem\n extends Omit<DocsCollection, 'dir' | 'meta' | 'docs'>, Omit<PrimitiveCollectionItem, 'patterns'> {\n meta: MetaCollectionItem;\n docs: DocCollectionItem;\n}\n\nconst SupportedFormats = {\n doc: ['mdx', 'md'],\n meta: ['json', 'yaml'],\n};\n\nexport function buildCollection(\n name: string,\n collection: AnyCollection,\n cwd: string,\n): CollectionItem {\n if (collection.type === 'docs') {\n return {\n ...collection,\n type: 'docs',\n get dir() {\n return this.docs.dir;\n },\n name,\n meta: buildCollection(name, collection.meta, cwd) as MetaCollectionItem,\n docs: buildCollection(name, collection.docs, cwd) as DocCollectionItem,\n hasFile(filePath) {\n return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);\n },\n isFileSupported(filePath) {\n return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);\n },\n cwd,\n };\n }\n\n return {\n ...collection,\n ...buildPrimitiveCollection(name, collection, cwd),\n };\n}\n\nfunction buildPrimitiveCollection(\n name: string,\n config: DocCollection | MetaCollection,\n cwd: string,\n): PrimitiveCollectionItem {\n const supportedFormats = SupportedFormats[config.type];\n const patterns = config.files ?? [`**/*.{${supportedFormats.join(',')}}`];\n let matcher: picomatch.Matcher;\n\n return {\n dir: path.resolve(cwd, config.dir),\n cwd,\n name,\n patterns,\n isFileSupported(filePath) {\n return supportedFormats.some((format) => filePath.endsWith(`.${format}`));\n },\n hasFile(filePath) {\n if (!this.isFileSupported(filePath)) return false;\n\n const relativePath = path.relative(this.dir, filePath);\n if (relativePath.startsWith(`..${path.sep}`)) return false;\n\n return (matcher ??= picomatch(patterns))(relativePath);\n },\n };\n}\n\nexport function buildConfig(config: Record<string, unknown>, cwd = process.cwd()): LoadedConfig {\n const collections = new Map<string, CollectionItem>();\n const loaded: GlobalConfig = {};\n\n for (const [k, v] of Object.entries(config)) {\n if (!v) {\n continue;\n }\n\n if (typeof v === 'object' && 'type' in v) {\n if (v.type === 'docs' || v.type === 'doc' || v.type === 'meta') {\n collections.set(k, buildCollection(k, v as AnyCollection, cwd));\n continue;\n }\n }\n\n if (k === 'default' && v) {\n Object.assign(loaded, v);\n continue;\n }\n\n throw new Error(\n `Unknown export \"${k}\", you can only export collections from source configuration file.`,\n );\n }\n\n const mdxOptionsCache = new Map<string, ProcessorOptions | Promise<ProcessorOptions>>();\n return {\n global: loaded,\n collections,\n workspaces: Object.fromEntries(\n Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {\n return [\n key,\n {\n dir: value.dir,\n config: buildConfig(value.config, path.resolve(cwd, value.dir)),\n },\n ];\n }),\n ),\n getMDXOptions(collection, environment = 'bundler') {\n const key = collection ? `${environment}:${collection.name}` : environment;\n const cached = mdxOptionsCache.get(key);\n if (cached) return cached;\n let result: ProcessorOptions | Promise<ProcessorOptions>;\n\n if (collection?.mdxOptions) {\n const optionsFn = collection.mdxOptions;\n result = typeof optionsFn === 'function' ? optionsFn(environment) : optionsFn;\n } else {\n result = (async () => {\n const optionsFn = this.global.mdxOptions;\n const options = typeof optionsFn === 'function' ? await optionsFn() : optionsFn;\n\n return applyMdxPreset(options)(environment);\n })();\n }\n\n mdxOptionsCache.set(key, result);\n return result;\n },\n };\n}\n"],"mappings":";;;;;AAqDA,MAAM,mBAAmB;CACvB,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,QAAQ,OAAO;CACvB;AAED,SAAgB,gBACd,MACA,YACA,KACgB;AAChB,KAAI,WAAW,SAAS,OACtB,QAAO;EACL,GAAG;EACH,MAAM;EACN,IAAI,MAAM;AACR,UAAO,KAAK,KAAK;;EAEnB;EACA,MAAM,gBAAgB,MAAM,WAAW,MAAM,IAAI;EACjD,MAAM,gBAAgB,MAAM,WAAW,MAAM,IAAI;EACjD,QAAQ,UAAU;AAChB,UAAO,KAAK,KAAK,QAAQ,SAAS,IAAI,KAAK,KAAK,QAAQ,SAAS;;EAEnE,gBAAgB,UAAU;AACxB,UAAO,KAAK,KAAK,gBAAgB,SAAS,IAAI,KAAK,KAAK,gBAAgB,SAAS;;EAEnF;EACD;AAGH,QAAO;EACL,GAAG;EACH,GAAG,yBAAyB,MAAM,YAAY,IAAI;EACnD;;AAGH,SAAS,yBACP,MACA,QACA,KACyB;CACzB,MAAM,mBAAmB,iBAAiB,OAAO;CACjD,MAAM,WAAW,OAAO,SAAS,CAAC,SAAS,iBAAiB,KAAK,IAAI,CAAC,GAAG;CACzE,IAAIA;AAEJ,QAAO;EACL,KAAK,KAAK,QAAQ,KAAK,OAAO,IAAI;EAClC;EACA;EACA;EACA,gBAAgB,UAAU;AACxB,UAAO,iBAAiB,M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,MAAM,YAAY,WAAW;AAC7B,aAAS,OAAO,cAAc,aAAa,UAAU,YAAY,GAAG;SAEpE,WAAU,YAAY;IACpB,MAAM,YAAY,KAAK,OAAO;AAG9B,WAAO,eAFS,OAAO,cAAc,aAAa,MAAM,WAAW,GAAG,UAExC,CAAC,YAAY;OACzC;AAGN,mBAAgB,IAAI,KAAK,OAAO;AAChC,UAAO;;EAEV"}
@@ -0,0 +1,53 @@
1
+ import { StructuredData } from "fumadocs-core/mdx-plugins";
2
+ import { VFile } from "vfile";
3
+ import { FC } from "react";
4
+ import { createProcessor } from "@mdx-js/mdx";
5
+ import { TOCItemType } from "fumadocs-core/toc";
6
+ import { MDXProps } from "mdx/types";
7
+
8
+ //#region src/loaders/mdx/build-mdx.d.ts
9
+ type Processor = ReturnType<typeof createProcessor>;
10
+ interface CompilerOptions {
11
+ addDependency: (file: string) => void;
12
+ }
13
+ interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
14
+ frontmatter: Frontmatter;
15
+ structuredData: StructuredData;
16
+ toc: TOCItemType[];
17
+ default: FC<MDXProps>;
18
+ /**
19
+ * Enable from `postprocess` option.
20
+ */
21
+ _markdown?: string;
22
+ /**
23
+ * Enable from `postprocess` option.
24
+ */
25
+ _mdast?: string;
26
+ }
27
+ interface FumadocsDataMap {
28
+ /**
29
+ * [Fumadocs MDX] raw frontmatter, you can modify it
30
+ */
31
+ frontmatter?: Record<string, unknown>;
32
+ /**
33
+ * [Fumadocs MDX] additional ESM exports to write
34
+ */
35
+ 'mdx-export'?: {
36
+ name: string;
37
+ value: unknown;
38
+ }[];
39
+ /**
40
+ * [Fumadocs MDX] The compiler object from loader
41
+ */
42
+ _compiler?: CompilerOptions;
43
+ /**
44
+ * [Fumadocs MDX] get internal processor, do not use this on user land.
45
+ */
46
+ _getProcessor?: (format: 'md' | 'mdx') => Processor;
47
+ }
48
+ declare module 'vfile' {
49
+ interface DataMap extends FumadocsDataMap {}
50
+ }
51
+ //#endregion
52
+ export { CompiledMDXProperties as t };
53
+ //# sourceMappingURL=build-mdx-10MrLupc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-mdx-10MrLupc.d.ts","names":[],"sources":["../src/loaders/mdx/build-mdx.ts"],"sourcesContent":[],"mappings":";;;;;;;;AASwD,KAEnD,SAAA,GAAY,UAAH,CAAqB,OAAA,eAAlB,CAAA;AAiDH,UAlCG,eAAA,CAkCH;EAK8B,aAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAAA,IAAA;;AAC3C,UApCgB,qBAoChB,CAAA,cApCoD,MAoCpD,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA;EAAA,WAAA,EAnCc,WAmCd;gBAI2B,EAtCV,cAsCyB;EAAA,GAAA,EArCpC,WAqCoC,EAAA;EAAA,OAAA,EApChC,EAoCgC,CApC7B,QAoC6B,CAAA;;;;;;;;;;UAxB1B,eAAA;;;;gBAID;;;;;;;;;;;cAUF;;;;4CAK8B;;;4BAKhB"}
@@ -0,0 +1,153 @@
1
+ import { n as flattenNode, t as remarkInclude } from "./remark-include-D3G3mAnv.js";
2
+ import { visit } from "unist-util-visit";
3
+ import { VFile } from "vfile";
4
+ import { createProcessor } from "@mdx-js/mdx";
5
+ import { toMarkdown } from "mdast-util-to-markdown";
6
+ import { valueToEstree } from "estree-util-value-to-estree";
7
+ import { removePosition } from "unist-util-remove-position";
8
+ import remarkMdx from "remark-mdx";
9
+
10
+ //#region src/loaders/mdx/remark-postprocess.ts
11
+ /**
12
+ * - collect references
13
+ * - write frontmatter (auto-title & description)
14
+ */
15
+ function remarkPostprocess({ _format, includeProcessedMarkdown = false, includeMDAST = false, extractLinkReferences = false, valueToExport = [] }) {
16
+ let _stringifyProcessor;
17
+ const getStringifyProcessor = () => {
18
+ return _stringifyProcessor ??= _format === "mdx" ? this : this().use(remarkMdx).freeze();
19
+ };
20
+ return (tree, file) => {
21
+ const frontmatter = file.data.frontmatter ??= {};
22
+ if (!frontmatter.title) visit(tree, "heading", (node) => {
23
+ if (node.depth === 1) {
24
+ frontmatter.title = flattenNode(node);
25
+ return false;
26
+ }
27
+ });
28
+ file.data["mdx-export"] ??= [];
29
+ file.data["mdx-export"].push({
30
+ name: "frontmatter",
31
+ value: frontmatter
32
+ });
33
+ if (extractLinkReferences) {
34
+ const urls = [];
35
+ visit(tree, "link", (node) => {
36
+ urls.push({ href: node.url });
37
+ return "skip";
38
+ });
39
+ file.data["mdx-export"].push({
40
+ name: "extractedReferences",
41
+ value: urls
42
+ });
43
+ }
44
+ if (includeProcessedMarkdown) {
45
+ const processor = getStringifyProcessor();
46
+ const markdown = toMarkdown(tree, {
47
+ ...processor.data("settings"),
48
+ extensions: processor.data("toMarkdownExtensions") || []
49
+ });
50
+ file.data["mdx-export"].push({
51
+ name: "_markdown",
52
+ value: markdown
53
+ });
54
+ }
55
+ if (includeMDAST) {
56
+ const options = includeMDAST === true ? {} : includeMDAST;
57
+ const mdast = JSON.stringify(options.removePosition ? removePosition(structuredClone(tree)) : tree);
58
+ file.data["mdx-export"].push({
59
+ name: "_mdast",
60
+ value: mdast
61
+ });
62
+ }
63
+ for (const { name, value } of file.data["mdx-export"]) tree.children.unshift(getMdastExport(name, value));
64
+ file.data["mdx-export"] = [];
65
+ for (const name of valueToExport) {
66
+ if (!(name in file.data)) continue;
67
+ tree.children.unshift(getMdastExport(name, file.data[name]));
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins
73
+ *
74
+ * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node
75
+ */
76
+ function getMdastExport(name, value) {
77
+ return {
78
+ type: "mdxjsEsm",
79
+ value: "",
80
+ data: { estree: {
81
+ type: "Program",
82
+ sourceType: "module",
83
+ body: [{
84
+ type: "ExportNamedDeclaration",
85
+ attributes: [],
86
+ specifiers: [],
87
+ source: null,
88
+ declaration: {
89
+ type: "VariableDeclaration",
90
+ kind: "let",
91
+ declarations: [{
92
+ type: "VariableDeclarator",
93
+ id: {
94
+ type: "Identifier",
95
+ name
96
+ },
97
+ init: valueToEstree(value)
98
+ }]
99
+ }
100
+ }]
101
+ } }
102
+ };
103
+ }
104
+
105
+ //#endregion
106
+ //#region src/loaders/mdx/build-mdx.ts
107
+ async function buildMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment }) {
108
+ const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);
109
+ function getProcessor(format) {
110
+ const cache = core.cache;
111
+ const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
112
+ let processor = cache.get(key);
113
+ if (!processor) {
114
+ const postprocessOptions = {
115
+ _format: format,
116
+ ...collection?.postprocess
117
+ };
118
+ processor = createProcessor({
119
+ outputFormat: "program",
120
+ development: isDevelopment,
121
+ ...mdxOptions,
122
+ remarkPlugins: [
123
+ remarkInclude,
124
+ ...mdxOptions.remarkPlugins ?? [],
125
+ [remarkPostprocess, postprocessOptions]
126
+ ],
127
+ format
128
+ });
129
+ cache.set(key, processor);
130
+ }
131
+ return processor;
132
+ }
133
+ let vfile = new VFile({
134
+ value: source,
135
+ path: filePath,
136
+ cwd: collection?.cwd,
137
+ data: {
138
+ frontmatter,
139
+ _compiler,
140
+ _getProcessor: getProcessor
141
+ }
142
+ });
143
+ if (collection) vfile = await core.transformVFile({
144
+ collection,
145
+ filePath,
146
+ source
147
+ }, vfile);
148
+ return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
149
+ }
150
+
151
+ //#endregion
152
+ export { buildMDX as t };
153
+ //# sourceMappingURL=build-mdx-BVeBo4jT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-mdx-BVeBo4jT.js","names":["_stringifyProcessor: Processor | undefined","urls: ExtractedReference[]","postprocessOptions: PostprocessOptions"],"sources":["../src/loaders/mdx/remark-postprocess.ts","../src/loaders/mdx/build-mdx.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport { toMarkdown } from 'mdast-util-to-markdown';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { removePosition } from 'unist-util-remove-position';\nimport remarkMdx from 'remark-mdx';\nimport { flattenNode } from './mdast-utils';\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: 'md' | 'mdx';\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n _format,\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n let _stringifyProcessor: Processor | undefined;\n const getStringifyProcessor = () => {\n return (_stringifyProcessor ??=\n _format === 'mdx'\n ? this\n : // force Markdown processor to stringify MDX nodes\n this().use(remarkMdx).freeze());\n };\n\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, 'heading', (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data['mdx-export'] ??= [];\n file.data['mdx-export'].push({\n name: 'frontmatter',\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, 'link', (node) => {\n urls.push({\n href: node.url,\n });\n return 'skip';\n });\n\n file.data['mdx-export'].push({\n name: 'extractedReferences',\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const processor = getStringifyProcessor();\n const markdown = toMarkdown(tree, {\n ...processor.data('settings'),\n // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js\n extensions: processor.data('toMarkdownExtensions') || [],\n });\n\n file.data['mdx-export'].push({\n name: '_markdown',\n value: markdown,\n });\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data['mdx-export'].push({\n name: '_mdast',\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data['mdx-export']) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data['mdx-export'] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor } from '@mdx-js/mdx';\nimport { VFile } from 'vfile';\nimport { remarkInclude } from '@/loaders/mdx/remark-include';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { FC } from 'react';\nimport type { MDXProps } from 'mdx/types';\nimport { type PostprocessOptions, remarkPostprocess } from '@/loaders/mdx/remark-postprocess';\nimport type { Core } from '@/core';\nimport type { DocCollectionItem } from '@/config/build';\n\ntype Processor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: 'bundler' | 'runtime';\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface CompilerOptions {\n addDependency: (file: string) => void;\n}\n\nexport interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {\n frontmatter: Frontmatter;\n structuredData: StructuredData;\n toc: TOCItemType[];\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport interface FumadocsDataMap {\n /**\n * [Fumadocs MDX] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fumadocs MDX] additional ESM exports to write\n */\n 'mdx-export'?: { name: string; value: unknown }[];\n\n /**\n * [Fumadocs MDX] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fumadocs MDX] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: 'md' | 'mdx') => Processor;\n}\n\ndeclare module 'vfile' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumadocsDataMap {}\n}\n\nexport async function buildMDX(\n core: Core,\n collection: DocCollectionItem | undefined,\n { filePath, frontmatter, source, _compiler, environment, isDevelopment }: BuildMDXOptions,\n): Promise<VFile> {\n const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);\n\n function getProcessor(format: 'md' | 'mdx') {\n const cache = core.cache as Map<string, Processor>;\n const key = `build-mdx:${collection?.name ?? 'global'}:${format}`;\n let processor = cache.get(key);\n\n if (!processor) {\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n processor = createProcessor({\n outputFormat: 'program',\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n remarkInclude,\n ...(mdxOptions.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n\n cache.set(key, processor);\n }\n\n return processor;\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: collection?.cwd,\n data: { frontmatter, _compiler, _getProcessor: getProcessor },\n });\n\n if (collection) {\n vfile = await core.transformVFile({ collection, filePath, source }, vfile);\n }\n\n return getProcessor(filePath.endsWith('.mdx') ? 'mdx' : 'md').process(vfile);\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,SAAgB,kBAEd,EACE,SACA,2BAA2B,OAC3B,eAAe,OACf,wBAAwB,OACxB,gBAAgB,EAAE,IAEK;CACzB,IAAIA;CACJ,MAAM,8BAA8B;AAClC,SAAQ,wBACN,YAAY,QACR,OAEA,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ;;AAGtC,SAAQ,MAAM,SAAS;EACrB,MAAM,cAAe,KAAK,KAAK,gBAAgB,EAAE;AACjD,MAAI,CAAC,YAAY,MACf,OAAM,MAAM,YAAY,SAAS;AAC/B,OAAI,KAAK,UAAU,GAAG;AACpB,gBAAY,QAAQ,YAAY,KAAK;AACrC,WAAO;;IAET;AAGJ,OAAK,KAAK,kBAAkB,EAAE;AAC9B,OAAK,KAAK,cAAc,KAAK;GAC3B,MAAM;GACN,OAAO;GACR,CAAC;AAEF,MAAI,uBAAuB;GACzB,MAAMC,OAA6B,EAAE;AAErC,SAAM,MAAM,SAAS,SAAS;AAC5B,SAAK,KAAK,EACR,MAAM,KAAK,KACZ,CAAC;AACF,WAAO;KACP;AAEF,QAAK,KAAK,cAAc,KAAK;IAC3B,MAAM;IACN,OAAO;IACR,CAAC;;AAGJ,MAAI,0BAA0B;GAC5B,MAAM,YAAY,uBAAuB;GACzC,MAAM,WAAW,WAAW,MAAM;IAChC,GAAG,UAAU,KAAK,WAAW;IAE7B,YAAY,UAAU,KAAK,uBAAuB,IAAI,EAAE;IACzD,CAAC;AAEF,QAAK,KAAK,cAAc,KAAK;IAC3B,MAAM;IACN,OAAO;IACR,CAAC;;AAGJ,MAAI,cAAc;GAChB,MAAM,UAAU,iBAAiB,OAAO,EAAE,GAAG;GAC7C,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,mBAAmB,mBAAmB;KACxC;IACD;IACD,CAAC;AAEF,SAAM,IAAI,KAAK,UAAU;;AAG3B,SAAO;;CAGT,IAAI,QAAQ,IAAI,MAAM;EACpB,OAAO;EACP,MAAM;EACN,KAAK,YAAY;EACjB,MAAM;GAAE;GAAa;GAAW,eAAe;GAAc;EAC9D,CAAC;AAEF,KAAI,WACF,SAAQ,MAAM,KAAK,eAAe;EAAE;EAAY;EAAU;EAAQ,EAAE,MAAM;AAG5E,QAAO,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,CAAC,QAAQ,MAAM"}
@@ -0,0 +1,5 @@
1
+ import "./fuma-matter-CHgJa_-B.js";
2
+ import "./remark-include-D3G3mAnv.js";
3
+ import { t as buildMDX } from "./build-mdx-BVeBo4jT.js";
4
+
5
+ export { buildMDX };
@@ -1,25 +1,14 @@
1
- import { BunPlugin } from 'bun';
2
- import { C as CoreOptions } from '../core-X5ggQtBM.js';
3
- import '@mdx-js/mdx';
4
- import '@standard-schema/spec';
5
- import 'unified';
6
- import 'fumadocs-core/mdx-plugins';
7
- import 'fumadocs-core/source/schema';
8
- import 'chokidar';
9
- import 'vfile';
10
- import 'fumadocs-core/source';
11
- import '../runtime/types.js';
12
- import 'fumadocs-core/mdx-plugins/remark-structure';
13
- import 'fumadocs-core/toc';
14
- import 'mdast';
15
- import 'mdx/types';
1
+ import { r as CoreOptions } from "../core-DG43f_AU.js";
2
+ import { BunPlugin } from "bun";
16
3
 
4
+ //#region src/bun/index.d.ts
17
5
  interface MdxPluginOptions extends Partial<CoreOptions> {
18
- /**
19
- * Skip meta file transformation step
20
- */
21
- disableMetaFile?: boolean;
6
+ /**
7
+ * Skip meta file transformation step
8
+ */
9
+ disableMetaFile?: boolean;
22
10
  }
23
11
  declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
24
-
25
- export { type MdxPluginOptions, createMdxPlugin };
12
+ //#endregion
13
+ export { MdxPluginOptions, createMdxPlugin };
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/bun/index.ts"],"sourcesContent":[],"mappings":";;;;UASiB,gBAAA,SAAyB,QAAQ;;AAAlD;AAOA;;;iBAAgB,eAAA,WAAyB,mBAAwB"}