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,5 +1,13 @@
1
1
  import { LoaderContext } from 'webpack';
2
- import { W as WebpackLoaderOptions } from '../index-D7s7kCc2.cjs';
2
+ import { W as WebpackLoaderOptions } from '../index-P2NNUkHn.cjs';
3
+ import '../index-D7JdSMpp.cjs';
4
+ import '@mdx-js/mdx';
5
+ import '@standard-schema/spec';
6
+ import 'unified';
7
+ import 'fumadocs-core/mdx-plugins';
8
+ import 'zod';
9
+ import 'chokidar';
10
+ import 'vfile';
3
11
 
4
12
  declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string, callback: LoaderContext<WebpackLoaderOptions>['callback']): Promise<void>;
5
13
 
@@ -1,5 +1,13 @@
1
1
  import { LoaderContext } from 'webpack';
2
- import { W as WebpackLoaderOptions } from '../index-D7s7kCc2.js';
2
+ import { W as WebpackLoaderOptions } from '../index-BlVBvy-z.js';
3
+ import '../index-D7JdSMpp.js';
4
+ import '@mdx-js/mdx';
5
+ import '@standard-schema/spec';
6
+ import 'unified';
7
+ import 'fumadocs-core/mdx-plugins';
8
+ import 'zod';
9
+ import 'chokidar';
10
+ import 'vfile';
3
11
 
4
12
  declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string, callback: LoaderContext<WebpackLoaderOptions>['callback']): Promise<void>;
5
13
 
@@ -1,36 +1,34 @@
1
+ import {
2
+ getCore
3
+ } from "../chunk-5UMZCWKV.js";
1
4
  import {
2
5
  createMetaLoader
3
- } from "../chunk-4757L6ST.js";
6
+ } from "../chunk-TYJDYTKH.js";
4
7
  import {
5
8
  createStandaloneConfigLoader,
6
9
  toWebpack
7
- } from "../chunk-ETIN2W7C.js";
8
- import {
9
- createCore
10
- } from "../chunk-2AQRQXSO.js";
10
+ } from "../chunk-SRSRFOVI.js";
11
+ import "../chunk-4JSFLXXT.js";
12
+ import "../chunk-7L2KNF6B.js";
13
+ import "../chunk-PKI7ZDA5.js";
11
14
 
12
15
  // src/webpack/meta.ts
13
16
  var instance;
14
17
  async function loader(source, callback) {
15
- const { isDev, outDir, configPath } = this.getOptions();
18
+ const options = this.getOptions();
16
19
  this.cacheable(true);
17
- this.addDependency(configPath);
20
+ this.addDependency(options.compiledConfigPath);
18
21
  if (!instance) {
19
- const core = createCore({
20
- environment: "webpack",
21
- outDir,
22
- configPath
23
- });
24
22
  instance = toWebpack(
25
23
  createMetaLoader(
26
24
  createStandaloneConfigLoader({
27
- core,
25
+ core: getCore(options),
28
26
  buildConfig: false,
29
- mode: isDev ? "dev" : "production"
27
+ mode: options.isDev ? "dev" : "production"
30
28
  }),
31
29
  {
32
30
  json: "json",
33
- yaml: "yaml"
31
+ yaml: "js"
34
32
  }
35
33
  )
36
34
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "13.0.7",
3
+ "version": "14.0.0",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -33,26 +33,9 @@
33
33
  "import": "./dist/index.js",
34
34
  "types": "./dist/index.d.ts"
35
35
  },
36
- "./runtime/next": {
37
- "import": "./dist/runtime/next/index.js",
38
- "types": "./dist/runtime/next/index.d.ts"
39
- },
40
- "./runtime/async": {
41
- "import": "./dist/runtime/next/async.js",
42
- "types": "./dist/runtime/next/async.d.ts"
43
- },
44
- "./runtime/vite": {
45
- "browser": "./dist/runtime/vite/browser.js",
46
- "import": "./dist/runtime/vite/server.js",
47
- "types": "./dist/runtime/vite/server.d.ts"
48
- },
49
- "./runtime/vite.server": {
50
- "import": "./dist/runtime/vite/server.js",
51
- "types": "./dist/runtime/vite/server.d.ts"
52
- },
53
- "./runtime/vite.browser": {
54
- "import": "./dist/runtime/vite/browser.js",
55
- "types": "./dist/runtime/vite/browser.d.ts"
36
+ "./runtime/*": {
37
+ "import": "./dist/runtime/*.js",
38
+ "types": "./dist/runtime/*.d.ts"
56
39
  },
57
40
  "./node/loader": {
58
41
  "import": "./dist/node/loader.js",
@@ -79,9 +62,9 @@
79
62
  "@mdx-js/mdx": "^3.1.1",
80
63
  "@standard-schema/spec": "^1.0.0",
81
64
  "chokidar": "^4.0.3",
82
- "esbuild": "^0.25.12",
65
+ "esbuild": "^0.27.0",
83
66
  "estree-util-value-to-estree": "^3.5.0",
84
- "js-yaml": "^4.1.0",
67
+ "js-yaml": "^4.1.1",
85
68
  "lru-cache": "^11.2.2",
86
69
  "mdast-util-to-markdown": "^2.1.2",
87
70
  "picocolors": "^1.1.1",
@@ -92,31 +75,31 @@
92
75
  "unified": "^11.0.5",
93
76
  "unist-util-remove-position": "^5.0.0",
94
77
  "unist-util-visit": "^5.0.0",
78
+ "vfile": "^6.0.3",
95
79
  "zod": "^4.1.12"
96
80
  },
97
81
  "devDependencies": {
98
- "@types/bun": "^1.3.1",
82
+ "@types/bun": "^1.3.2",
99
83
  "@types/js-yaml": "^4.0.9",
100
84
  "@types/mdast": "^4.0.4",
101
85
  "@types/mdx": "^2.0.13",
102
- "@types/node": "^24.10.0",
86
+ "@types/node": "^24.10.1",
103
87
  "@types/picomatch": "^4.0.2",
104
- "@types/react": "^19.2.2",
105
- "astro": "^5.15.3",
88
+ "@types/react": "^19.2.5",
89
+ "astro": "^5.15.8",
106
90
  "mdast-util-directive": "^3.1.0",
107
91
  "mdast-util-mdx-jsx": "^3.2.0",
108
- "next": "16.0.1",
92
+ "next": "16.0.3",
109
93
  "react": "^19.2.0",
110
94
  "remark": "^15.0.1",
111
95
  "remark-directive": "^4.0.0",
112
96
  "remark-stringify": "^11.0.0",
113
- "rollup": "^4.52.5",
114
- "vfile": "^6.0.3",
115
- "vite": "^7.2.0",
97
+ "rollup": "^4.53.2",
98
+ "vite": "^7.2.2",
116
99
  "webpack": "^5.102.1",
117
100
  "@fumadocs/mdx-remote": "1.4.3",
118
101
  "eslint-config-custom": "0.0.0",
119
- "fumadocs-core": "16.0.10",
102
+ "fumadocs-core": "16.0.12",
120
103
  "tsconfig": "0.0.0"
121
104
  },
122
105
  "peerDependencies": {
@@ -1,53 +0,0 @@
1
- import { createProcessor } from '@mdx-js/mdx';
2
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
3
- import { TOCItemType } from 'fumadocs-core/toc';
4
- import { FC } from 'react';
5
- import { MDXProps } from 'mdx/types';
6
- import { E as ExtractedReference } from './core-HkAVGq_a.cjs';
7
-
8
- type Processor = ReturnType<typeof createProcessor>;
9
- interface CompilerOptions {
10
- addDependency: (file: string) => void;
11
- }
12
- interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
13
- frontmatter: Frontmatter;
14
- structuredData: StructuredData;
15
- toc: TOCItemType[];
16
- default: FC<MDXProps>;
17
- /**
18
- * Only available when `lastModifiedTime` is enabled on MDX loader
19
- */
20
- lastModified?: Date;
21
- extractedReferences?: ExtractedReference[];
22
- _markdown?: string;
23
- _mdast?: string;
24
- }
25
- interface FumadocsDataMap {
26
- /**
27
- * [Fumadocs MDX] raw frontmatter, you can modify it
28
- */
29
- frontmatter?: Record<string, unknown>;
30
- /**
31
- * [Fumadocs MDX] additional ESM exports to write
32
- */
33
- 'mdx-export'?: {
34
- name: string;
35
- value: unknown;
36
- }[];
37
- extractedReferences: ExtractedReference[];
38
- /**
39
- * [Fumadocs MDX] The compiler object from loader
40
- */
41
- _compiler?: CompilerOptions;
42
- _getProcessor?: (format: 'md' | 'mdx') => Processor;
43
- /**
44
- * [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
45
- */
46
- _markdown?: string;
47
- }
48
- declare module 'vfile' {
49
- interface DataMap extends FumadocsDataMap {
50
- }
51
- }
52
-
53
- export type { CompiledMDXProperties as C };
@@ -1,53 +0,0 @@
1
- import { createProcessor } from '@mdx-js/mdx';
2
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
3
- import { TOCItemType } from 'fumadocs-core/toc';
4
- import { FC } from 'react';
5
- import { MDXProps } from 'mdx/types';
6
- import { E as ExtractedReference } from './core-HkAVGq_a.js';
7
-
8
- type Processor = ReturnType<typeof createProcessor>;
9
- interface CompilerOptions {
10
- addDependency: (file: string) => void;
11
- }
12
- interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
13
- frontmatter: Frontmatter;
14
- structuredData: StructuredData;
15
- toc: TOCItemType[];
16
- default: FC<MDXProps>;
17
- /**
18
- * Only available when `lastModifiedTime` is enabled on MDX loader
19
- */
20
- lastModified?: Date;
21
- extractedReferences?: ExtractedReference[];
22
- _markdown?: string;
23
- _mdast?: string;
24
- }
25
- interface FumadocsDataMap {
26
- /**
27
- * [Fumadocs MDX] raw frontmatter, you can modify it
28
- */
29
- frontmatter?: Record<string, unknown>;
30
- /**
31
- * [Fumadocs MDX] additional ESM exports to write
32
- */
33
- 'mdx-export'?: {
34
- name: string;
35
- value: unknown;
36
- }[];
37
- extractedReferences: ExtractedReference[];
38
- /**
39
- * [Fumadocs MDX] The compiler object from loader
40
- */
41
- _compiler?: CompilerOptions;
42
- _getProcessor?: (format: 'md' | 'mdx') => Processor;
43
- /**
44
- * [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
45
- */
46
- _markdown?: string;
47
- }
48
- declare module 'vfile' {
49
- interface DataMap extends FumadocsDataMap {
50
- }
51
- }
52
-
53
- export type { CompiledMDXProperties as C };
@@ -1,119 +0,0 @@
1
- // src/utils/validation.ts
2
- import picocolors from "picocolors";
3
- var ValidationError = class extends Error {
4
- constructor(message, issues) {
5
- super(
6
- `${message}:
7
- ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
8
- );
9
- this.title = message;
10
- this.issues = issues;
11
- }
12
- toStringFormatted() {
13
- return [
14
- picocolors.bold(`[MDX] ${this.title}:`),
15
- ...this.issues.map(
16
- (issue) => picocolors.redBright(
17
- `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
18
- )
19
- )
20
- ].join("\n");
21
- }
22
- };
23
- async function validate(schema, data, context, errorMessage) {
24
- if (typeof schema === "function" && !("~standard" in schema)) {
25
- schema = schema(context);
26
- }
27
- if ("~standard" in schema) {
28
- const result = await schema["~standard"].validate(
29
- data
30
- );
31
- if (result.issues) {
32
- throw new ValidationError(errorMessage, result.issues);
33
- }
34
- return result.value;
35
- }
36
- return data;
37
- }
38
-
39
- // src/core.ts
40
- import path from "path";
41
- import fs from "fs/promises";
42
- function findConfigFile() {
43
- return path.resolve("source.config.ts");
44
- }
45
- function createCore(options, defaultPlugins = []) {
46
- let config;
47
- let plugins;
48
- return {
49
- _options: options,
50
- getPluginContext() {
51
- return {
52
- core: this,
53
- ...options
54
- };
55
- },
56
- /**
57
- * Convenient cache store, reset when config changes
58
- */
59
- cache: /* @__PURE__ */ new Map(),
60
- async init({ config: newConfig }) {
61
- config = await newConfig;
62
- this.cache.clear();
63
- plugins = [];
64
- for await (const option of [
65
- ...defaultPlugins,
66
- ...config.global.plugins ?? []
67
- ]) {
68
- if (!option) continue;
69
- if (Array.isArray(option)) plugins.push(...option);
70
- else plugins.push(option);
71
- }
72
- for (const plugin of plugins) {
73
- const out = await plugin.config?.call(this.getPluginContext(), config);
74
- if (out) config = out;
75
- }
76
- return this;
77
- },
78
- getConfig() {
79
- return config;
80
- },
81
- async initServer(server) {
82
- for (const plugin of plugins) {
83
- await plugin.configureServer?.call(this.getPluginContext(), server);
84
- }
85
- },
86
- async emitAndWrite({
87
- filterPlugin = () => true
88
- } = {}) {
89
- const start = performance.now();
90
- const out = await Promise.all(
91
- plugins.map((plugin) => {
92
- if (!filterPlugin(plugin) || !plugin.emit) return [];
93
- return plugin.emit.call(this.getPluginContext());
94
- })
95
- );
96
- await Promise.all(
97
- out.flat().map(async (entry) => {
98
- const file = path.join(options.outDir, entry.path);
99
- await fs.mkdir(path.dirname(file), { recursive: true });
100
- await fs.writeFile(file, entry.content);
101
- })
102
- );
103
- console.log(`[MDX] generated files in ${performance.now() - start}ms`);
104
- }
105
- };
106
- }
107
-
108
- // src/loaders/index.ts
109
- var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
110
- var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
111
-
112
- export {
113
- ValidationError,
114
- validate,
115
- findConfigFile,
116
- createCore,
117
- metaLoaderGlob,
118
- mdxLoaderGlob
119
- };
@@ -1,77 +0,0 @@
1
- import {
2
- metaLoaderGlob,
3
- validate
4
- } from "./chunk-2AQRQXSO.js";
5
-
6
- // src/loaders/meta.ts
7
- import { dump, load } from "js-yaml";
8
- import { z } from "zod";
9
- var querySchema = z.object({
10
- collection: z.string().optional()
11
- }).loose();
12
- function createMetaLoader(configLoader, resolve = {}) {
13
- const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
14
- function stringifyOutput(isJson, data) {
15
- if (isJson) {
16
- return resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`;
17
- } else {
18
- return resolveYaml === "yaml" ? dump(data) : `export default ${JSON.stringify(data)}`;
19
- }
20
- }
21
- return {
22
- test: metaLoaderGlob,
23
- async load({ filePath, query, getSource }) {
24
- const parsed = querySchema.parse(query);
25
- const collection = parsed.collection ? (await configLoader.getConfig()).getCollection(parsed.collection) : void 0;
26
- if (!collection) return null;
27
- const isJson = filePath.endsWith(".json");
28
- const source = await getSource();
29
- let data;
30
- try {
31
- data = isJson ? JSON.parse(source) : load(source);
32
- } catch (e) {
33
- throw new Error(`invalid data in ${filePath}`, { cause: e });
34
- }
35
- let schema;
36
- switch (collection?.type) {
37
- case "meta":
38
- schema = collection.schema;
39
- break;
40
- case "docs":
41
- schema = collection.meta.schema;
42
- break;
43
- }
44
- if (schema) {
45
- data = await validate(
46
- schema,
47
- data,
48
- { path: filePath, source },
49
- `invalid data in ${filePath}`
50
- );
51
- }
52
- return {
53
- code: stringifyOutput(isJson, data)
54
- };
55
- },
56
- bun: {
57
- async fallback({ getSource, filePath }) {
58
- const source = await getSource();
59
- const isJson = filePath.endsWith(".json");
60
- let data;
61
- try {
62
- data = isJson ? JSON.parse(source) : load(source);
63
- } catch (e) {
64
- throw new Error(`invalid data in ${filePath}`, { cause: e });
65
- }
66
- return {
67
- loader: "object",
68
- exports: data
69
- };
70
- }
71
- }
72
- };
73
- }
74
-
75
- export {
76
- createMetaLoader
77
- };
@@ -1,45 +0,0 @@
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
- };
@@ -1,80 +0,0 @@
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
- };
@@ -1,77 +0,0 @@
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
- };