fumadocs-mdx 13.0.8 → 14.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 (111) hide show
  1. package/dist/bin.cjs +985 -893
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +613 -471
  5. package/dist/bun/index.d.cts +9 -2
  6. package/dist/bun/index.d.ts +9 -2
  7. package/dist/bun/index.js +15 -14
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5OBUOALK.js +141 -0
  10. package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
  11. package/dist/chunk-7UKSZSPY.js +331 -0
  12. package/dist/chunk-BEBCWQC7.js +224 -0
  13. package/dist/chunk-E5DJTSIM.js +86 -0
  14. package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
  15. package/dist/chunk-IQGEFL2B.js +17 -0
  16. package/dist/{chunk-5FTSWCB4.js → chunk-K6HCOGOX.js} +9 -11
  17. package/dist/{chunk-QXHN25N3.js → chunk-MTTISKQJ.js} +6 -6
  18. package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
  19. package/dist/chunk-TYJDYTKH.js +85 -0
  20. package/dist/chunk-WBIHDYMN.js +126 -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 +7 -1
  24. package/dist/config/index.d.ts +7 -1
  25. package/dist/config/index.js +5 -5
  26. package/dist/core-B9ZoS6sA.d.ts +341 -0
  27. package/dist/core-DTuP23zu.d.cts +341 -0
  28. package/dist/index-BD8Woo4m.d.cts +8 -0
  29. package/dist/index-CNOvhtOn.d.ts +8 -0
  30. package/dist/index.d.cts +38 -56
  31. package/dist/index.d.ts +38 -56
  32. package/dist/load-from-file-5HUQN36V.js +8 -0
  33. package/dist/next/index.cjs +763 -473
  34. package/dist/next/index.d.cts +16 -1
  35. package/dist/next/index.d.ts +16 -1
  36. package/dist/next/index.js +80 -281
  37. package/dist/node/loader.cjs +764 -627
  38. package/dist/node/loader.js +10 -11
  39. package/dist/plugins/index-file.cjs +495 -0
  40. package/dist/plugins/index-file.d.cts +14 -0
  41. package/dist/plugins/index-file.d.ts +14 -0
  42. package/dist/plugins/index-file.js +8 -0
  43. package/dist/plugins/json-schema.d.cts +9 -2
  44. package/dist/plugins/json-schema.d.ts +9 -2
  45. package/dist/plugins/last-modified.cjs +110 -0
  46. package/dist/plugins/last-modified.d.cts +37 -0
  47. package/dist/plugins/last-modified.d.ts +37 -0
  48. package/dist/plugins/last-modified.js +74 -0
  49. package/dist/runtime/browser.cjs +93 -0
  50. package/dist/runtime/browser.d.cts +53 -0
  51. package/dist/runtime/browser.d.ts +53 -0
  52. package/dist/runtime/browser.js +67 -0
  53. package/dist/runtime/dynamic.cjs +1023 -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 +79 -0
  57. package/dist/runtime/server.cjs +176 -0
  58. package/dist/runtime/server.d.cts +14 -0
  59. package/dist/runtime/server.d.ts +14 -0
  60. package/dist/runtime/server.js +8 -0
  61. package/dist/runtime/types.cjs +18 -0
  62. package/dist/runtime/types.d.cts +61 -0
  63. package/dist/runtime/types.d.ts +61 -0
  64. package/dist/runtime/types.js +0 -0
  65. package/dist/vite/index.cjs +984 -621
  66. package/dist/vite/index.d.cts +17 -22
  67. package/dist/vite/index.d.ts +17 -22
  68. package/dist/vite/index.js +32 -222
  69. package/dist/webpack/mdx.cjs +647 -514
  70. package/dist/webpack/mdx.d.cts +15 -1
  71. package/dist/webpack/mdx.d.ts +15 -1
  72. package/dist/webpack/mdx.js +12 -17
  73. package/dist/webpack/meta.cjs +360 -231
  74. package/dist/webpack/meta.d.cts +15 -1
  75. package/dist/webpack/meta.d.ts +15 -1
  76. package/dist/webpack/meta.js +13 -15
  77. package/package.json +15 -32
  78. package/dist/build-mdx-BjXOmv0b.d.cts +0 -53
  79. package/dist/build-mdx-CY5UldCO.d.ts +0 -53
  80. package/dist/chunk-2AQRQXSO.js +0 -119
  81. package/dist/chunk-CXA4JO4Z.js +0 -45
  82. package/dist/chunk-DMJ6I4C3.js +0 -76
  83. package/dist/chunk-FSZMKRVH.js +0 -80
  84. package/dist/chunk-II3H5ZVZ.js +0 -77
  85. package/dist/chunk-KILFIBVW.js +0 -75
  86. package/dist/chunk-NVRDCY6Z.js +0 -30
  87. package/dist/chunk-VUEZTR2H.js +0 -26
  88. package/dist/core-DB7TdlyC.d.cts +0 -234
  89. package/dist/core-DB7TdlyC.d.ts +0 -234
  90. package/dist/index-D7s7kCc2.d.cts +0 -7
  91. package/dist/index-D7s7kCc2.d.ts +0 -7
  92. package/dist/load-from-file-AVYOFOI7.js +0 -7
  93. package/dist/preset-ZMP6U62C.js +0 -6
  94. package/dist/runtime/next/async.cjs +0 -760
  95. package/dist/runtime/next/async.d.cts +0 -19
  96. package/dist/runtime/next/async.d.ts +0 -19
  97. package/dist/runtime/next/async.js +0 -86
  98. package/dist/runtime/next/index.cjs +0 -136
  99. package/dist/runtime/next/index.d.cts +0 -33
  100. package/dist/runtime/next/index.d.ts +0 -33
  101. package/dist/runtime/next/index.js +0 -11
  102. package/dist/runtime/vite/browser.cjs +0 -107
  103. package/dist/runtime/vite/browser.d.cts +0 -59
  104. package/dist/runtime/vite/browser.d.ts +0 -59
  105. package/dist/runtime/vite/browser.js +0 -11
  106. package/dist/runtime/vite/server.cjs +0 -243
  107. package/dist/runtime/vite/server.d.cts +0 -30
  108. package/dist/runtime/vite/server.d.ts +0 -30
  109. package/dist/runtime/vite/server.js +0 -111
  110. package/dist/types-Bnh9n7mj.d.cts +0 -45
  111. package/dist/types-ey1AZqrg.d.ts +0 -45
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/plugins/last-modified.ts
31
+ var last_modified_exports = {};
32
+ __export(last_modified_exports, {
33
+ default: () => lastModified
34
+ });
35
+ module.exports = __toCommonJS(last_modified_exports);
36
+ var import_node_path2 = __toESM(require("path"), 1);
37
+ var import_tinyexec = require("tinyexec");
38
+
39
+ // src/utils/codegen.ts
40
+ var import_node_path = __toESM(require("path"), 1);
41
+ var import_tinyglobby = require("tinyglobby");
42
+ function ident(code, tab = 1) {
43
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
44
+ }
45
+
46
+ // src/plugins/last-modified.ts
47
+ var cache = /* @__PURE__ */ new Map();
48
+ var ExtendTypes = `{
49
+ /**
50
+ * Last modified date of document file, obtained from version control.
51
+ *
52
+ */
53
+ lastModified?: Date;
54
+ }`;
55
+ function lastModified(options = {}) {
56
+ const { versionControl = "git", filter = () => true } = options;
57
+ return {
58
+ name: "last-modified",
59
+ "index-file": {
60
+ generateTypeConfig() {
61
+ const lines = [];
62
+ lines.push("{");
63
+ lines.push(" DocData: {");
64
+ for (const collection of this.core.getConfig().collectionList) {
65
+ if (filter(collection.name)) {
66
+ lines.push(ident(`${collection.name}: ${ExtendTypes},`, 2));
67
+ }
68
+ }
69
+ lines.push(" }");
70
+ lines.push("}");
71
+ return lines.join("\n");
72
+ },
73
+ serverOptions(options2) {
74
+ options2.doc ??= {};
75
+ options2.doc.passthroughs ??= [];
76
+ options2.doc.passthroughs.push("lastModified");
77
+ }
78
+ },
79
+ doc: {
80
+ async vfile(file) {
81
+ if (!filter(this.collection.name)) return;
82
+ if (versionControl === "git") {
83
+ const timestamp = await getGitTimestamp(this.filePath);
84
+ if (timestamp === void 0) return;
85
+ file.data["mdx-export"] ??= [];
86
+ file.data["mdx-export"].push({
87
+ name: "lastModified",
88
+ value: timestamp
89
+ });
90
+ }
91
+ }
92
+ }
93
+ };
94
+ }
95
+ async function getGitTimestamp(file) {
96
+ const cached = cache.get(file);
97
+ if (cached) return cached;
98
+ const timePromise = (async () => {
99
+ const out = await (0, import_tinyexec.x)(
100
+ "git",
101
+ ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
102
+ {
103
+ throwOnError: true
104
+ }
105
+ );
106
+ return new Date(out.stdout);
107
+ })();
108
+ cache.set(file, timePromise);
109
+ return timePromise.catch(() => void 0);
110
+ }
@@ -0,0 +1,37 @@
1
+ import { j as Plugin } from '../core-DTuP23zu.cjs';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import 'fumadocs-core/mdx-plugins';
6
+ import 'zod';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+ import 'fumadocs-core/source';
10
+ import '../runtime/types.cjs';
11
+ import 'fumadocs-core/mdx-plugins/remark-structure';
12
+ import 'fumadocs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
15
+
16
+ interface LastModifiedPluginOptions {
17
+ /**
18
+ * Version control to obtain the last modified time.
19
+ *
20
+ * - `git`: Requires `git` to be installed.
21
+ *
22
+ * If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`.
23
+ *
24
+ * @defaultValue 'git'
25
+ */
26
+ versionControl?: 'git';
27
+ /**
28
+ * Filter the collections to include by names
29
+ */
30
+ filter?: (collection: string) => boolean;
31
+ }
32
+ /**
33
+ * Injects `lastModified` property to page exports.
34
+ */
35
+ declare function lastModified(options?: LastModifiedPluginOptions): Plugin;
36
+
37
+ export { type LastModifiedPluginOptions, lastModified as default };
@@ -0,0 +1,37 @@
1
+ import { j as Plugin } from '../core-B9ZoS6sA.js';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import 'fumadocs-core/mdx-plugins';
6
+ import 'zod';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+ import 'fumadocs-core/source';
10
+ import '../runtime/types.js';
11
+ import 'fumadocs-core/mdx-plugins/remark-structure';
12
+ import 'fumadocs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
15
+
16
+ interface LastModifiedPluginOptions {
17
+ /**
18
+ * Version control to obtain the last modified time.
19
+ *
20
+ * - `git`: Requires `git` to be installed.
21
+ *
22
+ * If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`.
23
+ *
24
+ * @defaultValue 'git'
25
+ */
26
+ versionControl?: 'git';
27
+ /**
28
+ * Filter the collections to include by names
29
+ */
30
+ filter?: (collection: string) => boolean;
31
+ }
32
+ /**
33
+ * Injects `lastModified` property to page exports.
34
+ */
35
+ declare function lastModified(options?: LastModifiedPluginOptions): Plugin;
36
+
37
+ export { type LastModifiedPluginOptions, lastModified as default };
@@ -0,0 +1,74 @@
1
+ import {
2
+ ident
3
+ } from "../chunk-WBIHDYMN.js";
4
+
5
+ // src/plugins/last-modified.ts
6
+ import path from "path";
7
+ import { x } from "tinyexec";
8
+ var cache = /* @__PURE__ */ new Map();
9
+ var ExtendTypes = `{
10
+ /**
11
+ * Last modified date of document file, obtained from version control.
12
+ *
13
+ */
14
+ lastModified?: Date;
15
+ }`;
16
+ function lastModified(options = {}) {
17
+ const { versionControl = "git", filter = () => true } = options;
18
+ return {
19
+ name: "last-modified",
20
+ "index-file": {
21
+ generateTypeConfig() {
22
+ const lines = [];
23
+ lines.push("{");
24
+ lines.push(" DocData: {");
25
+ for (const collection of this.core.getConfig().collectionList) {
26
+ if (filter(collection.name)) {
27
+ lines.push(ident(`${collection.name}: ${ExtendTypes},`, 2));
28
+ }
29
+ }
30
+ lines.push(" }");
31
+ lines.push("}");
32
+ return lines.join("\n");
33
+ },
34
+ serverOptions(options2) {
35
+ options2.doc ??= {};
36
+ options2.doc.passthroughs ??= [];
37
+ options2.doc.passthroughs.push("lastModified");
38
+ }
39
+ },
40
+ doc: {
41
+ async vfile(file) {
42
+ if (!filter(this.collection.name)) return;
43
+ if (versionControl === "git") {
44
+ const timestamp = await getGitTimestamp(this.filePath);
45
+ if (timestamp === void 0) return;
46
+ file.data["mdx-export"] ??= [];
47
+ file.data["mdx-export"].push({
48
+ name: "lastModified",
49
+ value: timestamp
50
+ });
51
+ }
52
+ }
53
+ }
54
+ };
55
+ }
56
+ async function getGitTimestamp(file) {
57
+ const cached = cache.get(file);
58
+ if (cached) return cached;
59
+ const timePromise = (async () => {
60
+ const out = await x(
61
+ "git",
62
+ ["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
63
+ {
64
+ throwOnError: true
65
+ }
66
+ );
67
+ return new Date(out.stdout);
68
+ })();
69
+ cache.set(file, timePromise);
70
+ return timePromise.catch(() => void 0);
71
+ }
72
+ export {
73
+ lastModified as default
74
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/runtime/browser.ts
21
+ var browser_exports = {};
22
+ __export(browser_exports, {
23
+ browser: () => browser,
24
+ createClientLoader: () => createClientLoader
25
+ });
26
+ module.exports = __toCommonJS(browser_exports);
27
+ var import_react = require("react");
28
+ function browser() {
29
+ return {
30
+ doc(_name, glob) {
31
+ const out = {
32
+ raw: glob,
33
+ createClientLoader({ id = _name, ...options }) {
34
+ return createClientLoader(this.raw, { id, ...options });
35
+ }
36
+ };
37
+ return out;
38
+ }
39
+ };
40
+ }
41
+ var loaderStore = /* @__PURE__ */ new Map();
42
+ function createClientLoader(globEntries, options) {
43
+ const { id = "", component } = options;
44
+ const renderers = {};
45
+ const loaders = /* @__PURE__ */ new Map();
46
+ const store = loaderStore.get(id) ?? {
47
+ preloaded: /* @__PURE__ */ new Map()
48
+ };
49
+ loaderStore.set(id, store);
50
+ for (const k in globEntries) {
51
+ loaders.set(k.startsWith("./") ? k.slice(2) : k, globEntries[k]);
52
+ }
53
+ function getLoader(path) {
54
+ const loader = loaders.get(path);
55
+ if (!loader)
56
+ throw new Error(
57
+ `[createClientLoader] ${path} does not exist in available entries`
58
+ );
59
+ return loader;
60
+ }
61
+ function getRenderer(path) {
62
+ if (path in renderers) return renderers[path];
63
+ const OnDemand = (0, import_react.lazy)(async () => {
64
+ const loaded = await getLoader(path)();
65
+ return { default: (props) => component(loaded, props) };
66
+ });
67
+ renderers[path] = (props) => {
68
+ const cached = store.preloaded.get(path);
69
+ if (!cached) return (0, import_react.createElement)(OnDemand, props);
70
+ return component(cached, props);
71
+ };
72
+ return renderers[path];
73
+ }
74
+ return {
75
+ async preload(path) {
76
+ const loaded = await getLoader(path)();
77
+ store.preloaded.set(path, loaded);
78
+ return loaded;
79
+ },
80
+ getComponent(path) {
81
+ return getRenderer(path);
82
+ },
83
+ useContent(path, props) {
84
+ const Comp = this.getComponent(path);
85
+ return (0, import_react.createElement)(Comp, props);
86
+ }
87
+ };
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ browser,
92
+ createClientLoader
93
+ });
@@ -0,0 +1,53 @@
1
+ import { ReactNode, FC } from 'react';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import { D as DocCollection, a as DocsCollection } from '../core-DTuP23zu.cjs';
4
+ import { CompiledMDXProperties } from '../index.cjs';
5
+ import { InternalTypeConfig } from './types.cjs';
6
+ import '@mdx-js/mdx';
7
+ import 'unified';
8
+ import 'fumadocs-core/mdx-plugins';
9
+ import 'zod';
10
+ import 'chokidar';
11
+ import 'vfile';
12
+ import 'fumadocs-core/source';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdx/types';
15
+ import 'fumadocs-core/mdx-plugins/remark-structure';
16
+ import 'mdast';
17
+
18
+ type CompiledMDXFile<Name extends string, Frontmatter, TC extends InternalTypeConfig> = CompiledMDXProperties<Frontmatter> & TC['DocData'][Name] & Record<string, unknown>;
19
+ interface ClientLoaderOptions<Doc, Props> {
20
+ /**
21
+ * Loader ID (usually your collection name)
22
+ *
23
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
24
+ *
25
+ * We use loader ID to share cache between multiple instances of client loader.
26
+ *
27
+ * @defaultValue ''
28
+ */
29
+ id?: string;
30
+ component: (loaded: Doc, props: Props) => ReactNode;
31
+ }
32
+ interface ClientLoader<Doc, Props> {
33
+ preload: (path: string) => Promise<Doc>;
34
+ /**
35
+ * Get a component that renders content with `React.lazy`.
36
+ */
37
+ getComponent: (path: string) => FC<Props>;
38
+ /**
39
+ * Get react nodes that renders content with `React.lazy`.
40
+ */
41
+ useContent: (path: string, props: Props) => ReactNode;
42
+ }
43
+ type BrowserCreate<Config, TC extends InternalTypeConfig> = ReturnType<typeof browser<Config, TC>>;
44
+ interface DocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> {
45
+ raw: Record<string, () => Promise<CompiledMDXFile<Name, Frontmatter, TC>>>;
46
+ createClientLoader: <Props extends object>(options: ClientLoaderOptions<CompiledMDXFile<Name, Frontmatter, TC>, Props>) => ClientLoader<CompiledMDXFile<Name, Frontmatter, TC>, Props>;
47
+ }
48
+ declare function browser<Config, TC extends InternalTypeConfig>(): {
49
+ doc<Name extends keyof Config & string>(_name: Name, glob: Record<string, () => Promise<unknown>>): Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC> : never;
50
+ };
51
+ declare function createClientLoader<Doc = CompiledMDXProperties, Props extends object = object>(globEntries: Record<string, () => Promise<Doc>>, options: ClientLoaderOptions<Doc, Props>): ClientLoader<Doc, Props>;
52
+
53
+ export { type BrowserCreate, type ClientLoader, type ClientLoaderOptions, type DocCollectionEntry, browser, createClientLoader };
@@ -0,0 +1,53 @@
1
+ import { ReactNode, FC } from 'react';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import { D as DocCollection, a as DocsCollection } from '../core-B9ZoS6sA.js';
4
+ import { CompiledMDXProperties } from '../index.js';
5
+ import { InternalTypeConfig } from './types.js';
6
+ import '@mdx-js/mdx';
7
+ import 'unified';
8
+ import 'fumadocs-core/mdx-plugins';
9
+ import 'zod';
10
+ import 'chokidar';
11
+ import 'vfile';
12
+ import 'fumadocs-core/source';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdx/types';
15
+ import 'fumadocs-core/mdx-plugins/remark-structure';
16
+ import 'mdast';
17
+
18
+ type CompiledMDXFile<Name extends string, Frontmatter, TC extends InternalTypeConfig> = CompiledMDXProperties<Frontmatter> & TC['DocData'][Name] & Record<string, unknown>;
19
+ interface ClientLoaderOptions<Doc, Props> {
20
+ /**
21
+ * Loader ID (usually your collection name)
22
+ *
23
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
24
+ *
25
+ * We use loader ID to share cache between multiple instances of client loader.
26
+ *
27
+ * @defaultValue ''
28
+ */
29
+ id?: string;
30
+ component: (loaded: Doc, props: Props) => ReactNode;
31
+ }
32
+ interface ClientLoader<Doc, Props> {
33
+ preload: (path: string) => Promise<Doc>;
34
+ /**
35
+ * Get a component that renders content with `React.lazy`.
36
+ */
37
+ getComponent: (path: string) => FC<Props>;
38
+ /**
39
+ * Get react nodes that renders content with `React.lazy`.
40
+ */
41
+ useContent: (path: string, props: Props) => ReactNode;
42
+ }
43
+ type BrowserCreate<Config, TC extends InternalTypeConfig> = ReturnType<typeof browser<Config, TC>>;
44
+ interface DocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> {
45
+ raw: Record<string, () => Promise<CompiledMDXFile<Name, Frontmatter, TC>>>;
46
+ createClientLoader: <Props extends object>(options: ClientLoaderOptions<CompiledMDXFile<Name, Frontmatter, TC>, Props>) => ClientLoader<CompiledMDXFile<Name, Frontmatter, TC>, Props>;
47
+ }
48
+ declare function browser<Config, TC extends InternalTypeConfig>(): {
49
+ doc<Name extends keyof Config & string>(_name: Name, glob: Record<string, () => Promise<unknown>>): Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC> : never;
50
+ };
51
+ declare function createClientLoader<Doc = CompiledMDXProperties, Props extends object = object>(globEntries: Record<string, () => Promise<Doc>>, options: ClientLoaderOptions<Doc, Props>): ClientLoader<Doc, Props>;
52
+
53
+ export { type BrowserCreate, type ClientLoader, type ClientLoaderOptions, type DocCollectionEntry, browser, createClientLoader };
@@ -0,0 +1,67 @@
1
+ // src/runtime/browser.ts
2
+ import { lazy, createElement } from "react";
3
+ function browser() {
4
+ return {
5
+ doc(_name, glob) {
6
+ const out = {
7
+ raw: glob,
8
+ createClientLoader({ id = _name, ...options }) {
9
+ return createClientLoader(this.raw, { id, ...options });
10
+ }
11
+ };
12
+ return out;
13
+ }
14
+ };
15
+ }
16
+ var loaderStore = /* @__PURE__ */ new Map();
17
+ function createClientLoader(globEntries, options) {
18
+ const { id = "", component } = options;
19
+ const renderers = {};
20
+ const loaders = /* @__PURE__ */ new Map();
21
+ const store = loaderStore.get(id) ?? {
22
+ preloaded: /* @__PURE__ */ new Map()
23
+ };
24
+ loaderStore.set(id, store);
25
+ for (const k in globEntries) {
26
+ loaders.set(k.startsWith("./") ? k.slice(2) : k, globEntries[k]);
27
+ }
28
+ function getLoader(path) {
29
+ const loader = loaders.get(path);
30
+ if (!loader)
31
+ throw new Error(
32
+ `[createClientLoader] ${path} does not exist in available entries`
33
+ );
34
+ return loader;
35
+ }
36
+ function getRenderer(path) {
37
+ if (path in renderers) return renderers[path];
38
+ const OnDemand = lazy(async () => {
39
+ const loaded = await getLoader(path)();
40
+ return { default: (props) => component(loaded, props) };
41
+ });
42
+ renderers[path] = (props) => {
43
+ const cached = store.preloaded.get(path);
44
+ if (!cached) return createElement(OnDemand, props);
45
+ return component(cached, props);
46
+ };
47
+ return renderers[path];
48
+ }
49
+ return {
50
+ async preload(path) {
51
+ const loaded = await getLoader(path)();
52
+ store.preloaded.set(path, loaded);
53
+ return loaded;
54
+ },
55
+ getComponent(path) {
56
+ return getRenderer(path);
57
+ },
58
+ useContent(path, props) {
59
+ const Comp = this.getComponent(path);
60
+ return createElement(Comp, props);
61
+ }
62
+ };
63
+ }
64
+ export {
65
+ browser,
66
+ createClientLoader
67
+ };