@hanzo/docs-mdx 14.1.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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +16 -0
  4. package/dist/build-mdx-LN7FEKIP.js +8 -0
  5. package/dist/build-mdx-RXJZQXGA.js +8 -0
  6. package/dist/bun/index.d.ts +25 -0
  7. package/dist/bun/index.js +52 -0
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5OBUOALK.js +141 -0
  10. package/dist/chunk-72JS4QVZ.js +17 -0
  11. package/dist/chunk-7I4W7XGI.js +179 -0
  12. package/dist/chunk-7W73RILB.js +173 -0
  13. package/dist/chunk-A3YIGE7S.js +334 -0
  14. package/dist/chunk-AOTZP2TV.js +152 -0
  15. package/dist/chunk-AXJB5MGS.js +173 -0
  16. package/dist/chunk-DMIIE3XZ.js +179 -0
  17. package/dist/chunk-DTFUANSF.js +40 -0
  18. package/dist/chunk-JWZR25CW.js +116 -0
  19. package/dist/chunk-K7N6GD4M.js +17 -0
  20. package/dist/chunk-LXB7WYAF.js +334 -0
  21. package/dist/chunk-MYAVS2LD.js +116 -0
  22. package/dist/chunk-OLD35ARB.js +116 -0
  23. package/dist/chunk-PW2AZGGD.js +125 -0
  24. package/dist/chunk-RGBNABKS.js +334 -0
  25. package/dist/chunk-RPUM7REY.js +40 -0
  26. package/dist/chunk-RR2X6AE6.js +274 -0
  27. package/dist/chunk-S7KOJHHO.js +89 -0
  28. package/dist/chunk-STUCUTJQ.js +334 -0
  29. package/dist/chunk-T6G5VOED.js +116 -0
  30. package/dist/chunk-U5YPLCO5.js +89 -0
  31. package/dist/chunk-UB55AMXC.js +274 -0
  32. package/dist/chunk-VITVHHR6.js +334 -0
  33. package/dist/chunk-VKSHE52K.js +274 -0
  34. package/dist/chunk-VWJKRQZR.js +19 -0
  35. package/dist/chunk-WAAWFNDX.js +179 -0
  36. package/dist/chunk-WGXYJGSZ.js +141 -0
  37. package/dist/chunk-WLJ6EKOZ.js +17 -0
  38. package/dist/chunk-WMYYALAS.js +334 -0
  39. package/dist/chunk-Y7ISNZ7X.js +216 -0
  40. package/dist/chunk-YKRCQ42E.js +216 -0
  41. package/dist/chunk-ZAYZWFWP.js +89 -0
  42. package/dist/config/index.d.ts +18 -0
  43. package/dist/config/index.js +63 -0
  44. package/dist/core-BQcKaqmC.d.ts +350 -0
  45. package/dist/core-BhWOtait.d.ts +350 -0
  46. package/dist/core-CV8uFMUa.d.ts +350 -0
  47. package/dist/core-DAQ64Hkq.d.ts +350 -0
  48. package/dist/core-DZtRjhds.d.ts +350 -0
  49. package/dist/core-De5K4ixv.d.ts +350 -0
  50. package/dist/core-X5ggQtBM.d.ts +350 -0
  51. package/dist/index-BqkSNsGO.d.ts +8 -0
  52. package/dist/index.d.ts +61 -0
  53. package/dist/index.js +0 -0
  54. package/dist/load-from-file-FHW724YY.js +8 -0
  55. package/dist/load-from-file-S5CQ4H6T.js +8 -0
  56. package/dist/next/index.cjs +1165 -0
  57. package/dist/next/index.d.ts +33 -0
  58. package/dist/next/index.js +181 -0
  59. package/dist/node/loader.d.ts +5 -0
  60. package/dist/node/loader.js +41 -0
  61. package/dist/plugins/index-file.d.ts +14 -0
  62. package/dist/plugins/index-file.js +8 -0
  63. package/dist/plugins/json-schema.d.ts +31 -0
  64. package/dist/plugins/json-schema.js +80 -0
  65. package/dist/plugins/last-modified.d.ts +40 -0
  66. package/dist/plugins/last-modified.js +89 -0
  67. package/dist/runtime/browser.d.ts +53 -0
  68. package/dist/runtime/browser.js +67 -0
  69. package/dist/runtime/dynamic.d.ts +27 -0
  70. package/dist/runtime/dynamic.js +79 -0
  71. package/dist/runtime/server.d.ts +14 -0
  72. package/dist/runtime/server.js +8 -0
  73. package/dist/runtime/types.d.ts +61 -0
  74. package/dist/runtime/types.js +0 -0
  75. package/dist/vite/index.d.ts +44 -0
  76. package/dist/vite/index.js +122 -0
  77. package/dist/webpack/mdx.d.ts +6 -0
  78. package/dist/webpack/mdx.js +37 -0
  79. package/dist/webpack/meta.d.ts +6 -0
  80. package/dist/webpack/meta.js +40 -0
  81. package/loader-mdx.cjs +7 -0
  82. package/loader-meta.cjs +7 -0
  83. package/package.json +137 -0
@@ -0,0 +1,33 @@
1
+ import { NextConfig } from 'next';
2
+ import { I as IndexFilePluginOptions } from '../core-BhWOtait.js';
3
+ import '@mdx-js/mdx';
4
+ import '@standard-schema/spec';
5
+ import 'unified';
6
+ import '@hanzo/docs-core/mdx-plugins';
7
+ import '@hanzo/docs-core/source/schema';
8
+ import 'chokidar';
9
+ import 'vfile';
10
+ import '@hanzo/docs-core/source';
11
+ import '../runtime/types.js';
12
+ import '@hanzo/docs-core/mdx-plugins/remark-structure';
13
+ import '@hanzo/docs-core/toc';
14
+ import 'mdast';
15
+ import 'mdx/types';
16
+
17
+ interface CreateMDXOptions {
18
+ /**
19
+ * Path to source configuration file
20
+ */
21
+ configPath?: string;
22
+ /**
23
+ * Directory for output files
24
+ *
25
+ * @defaultValue '.source'
26
+ */
27
+ outDir?: string;
28
+ index?: IndexFilePluginOptions | false;
29
+ }
30
+ declare function createMDX(createOptions?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
31
+ declare function postInstall(options: CreateMDXOptions): Promise<void>;
32
+
33
+ export { type CreateMDXOptions, createMDX, postInstall };
@@ -0,0 +1,181 @@
1
+ import {
2
+ loadConfig
3
+ } from "../chunk-RPUM7REY.js";
4
+ import {
5
+ indexFile
6
+ } from "../chunk-A3YIGE7S.js";
7
+ import {
8
+ mdxLoaderGlob,
9
+ metaLoaderGlob
10
+ } from "../chunk-4JSFLXXT.js";
11
+ import "../chunk-MYAVS2LD.js";
12
+ import "../chunk-U5YPLCO5.js";
13
+ import {
14
+ _Defaults,
15
+ createCore
16
+ } from "../chunk-RR2X6AE6.js";
17
+ import "../chunk-PW2AZGGD.js";
18
+ import "../chunk-VWJKRQZR.js";
19
+
20
+ // src/next/index.ts
21
+ import * as path from "path";
22
+ var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
23
+ function createMDX(createOptions = {}) {
24
+ const core = createNextCore(applyDefaults(createOptions));
25
+ const isDev = process.env.NODE_ENV === "development";
26
+ if (process.env._FUMADOCS_MDX !== "1") {
27
+ process.env._FUMADOCS_MDX = "1";
28
+ void init(isDev, core);
29
+ }
30
+ return (nextConfig = {}) => {
31
+ const { configPath, outDir } = core.getOptions();
32
+ const loaderOptions = {
33
+ configPath,
34
+ outDir,
35
+ absoluteCompiledConfigPath: path.resolve(core.getCompiledConfigPath()),
36
+ isDev
37
+ };
38
+ const turbopack = {
39
+ ...nextConfig.turbopack,
40
+ rules: {
41
+ ...nextConfig.turbopack?.rules,
42
+ "*.{md,mdx}": {
43
+ loaders: [
44
+ {
45
+ loader: "@hanzo/docs-mdx/loader-mdx",
46
+ options: loaderOptions
47
+ }
48
+ ],
49
+ as: "*.js"
50
+ },
51
+ "*.json": {
52
+ loaders: [
53
+ {
54
+ loader: "@hanzo/docs-mdx/loader-meta",
55
+ options: loaderOptions
56
+ }
57
+ ],
58
+ as: "*.json"
59
+ },
60
+ "*.yaml": {
61
+ loaders: [
62
+ {
63
+ loader: "@hanzo/docs-mdx/loader-meta",
64
+ options: loaderOptions
65
+ }
66
+ ],
67
+ as: "*.js"
68
+ }
69
+ }
70
+ };
71
+ return {
72
+ ...nextConfig,
73
+ turbopack,
74
+ pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
75
+ webpack: (config, options) => {
76
+ config.resolve ||= {};
77
+ config.module ||= {};
78
+ config.module.rules ||= [];
79
+ config.module.rules.push(
80
+ {
81
+ test: mdxLoaderGlob,
82
+ use: [
83
+ options.defaultLoaders.babel,
84
+ {
85
+ loader: "@hanzo/docs-mdx/loader-mdx",
86
+ options: loaderOptions
87
+ }
88
+ ]
89
+ },
90
+ {
91
+ test: metaLoaderGlob,
92
+ enforce: "pre",
93
+ use: [
94
+ {
95
+ loader: "@hanzo/docs-mdx/loader-meta",
96
+ options: loaderOptions
97
+ }
98
+ ]
99
+ }
100
+ );
101
+ config.plugins ||= [];
102
+ return nextConfig.webpack?.(config, options) ?? config;
103
+ }
104
+ };
105
+ };
106
+ }
107
+ async function init(dev, core) {
108
+ async function initOrReload() {
109
+ await core.init({
110
+ config: loadConfig(core, true)
111
+ });
112
+ await core.emit({ write: true });
113
+ }
114
+ async function devServer() {
115
+ const { FSWatcher } = await import("chokidar");
116
+ const { configPath, outDir } = core.getOptions();
117
+ const watcher = new FSWatcher({
118
+ ignoreInitial: true,
119
+ persistent: true,
120
+ ignored: [outDir]
121
+ });
122
+ watcher.add(configPath);
123
+ for (const collection of core.getCollections()) {
124
+ watcher.add(collection.dir);
125
+ }
126
+ for (const workspace of core.getWorkspaces().values()) {
127
+ for (const collection of workspace.getCollections()) {
128
+ watcher.add(collection.dir);
129
+ }
130
+ }
131
+ watcher.on("ready", () => {
132
+ console.log("[MDX] started dev server");
133
+ });
134
+ const absoluteConfigPath = path.resolve(configPath);
135
+ watcher.on("all", async (_event, file) => {
136
+ if (path.resolve(file) === absoluteConfigPath) {
137
+ watcher.removeAllListeners();
138
+ await watcher.close();
139
+ await initOrReload();
140
+ console.log("[MDX] restarting dev server");
141
+ await devServer();
142
+ }
143
+ });
144
+ process.on("exit", () => {
145
+ if (watcher.closed) return;
146
+ console.log("[MDX] closing dev server");
147
+ void watcher.close();
148
+ });
149
+ await core.initServer({ watcher });
150
+ }
151
+ await initOrReload();
152
+ if (dev) {
153
+ await devServer();
154
+ }
155
+ }
156
+ async function postInstall(options) {
157
+ const core = createNextCore(applyDefaults(options));
158
+ await core.init({
159
+ config: loadConfig(core, true)
160
+ });
161
+ await core.emit({ write: true });
162
+ }
163
+ function applyDefaults(options) {
164
+ return {
165
+ index: {},
166
+ outDir: options.outDir ?? _Defaults.outDir,
167
+ configPath: options.configPath ?? _Defaults.configPath
168
+ };
169
+ }
170
+ function createNextCore(options) {
171
+ return createCore({
172
+ environment: "next",
173
+ outDir: options.outDir,
174
+ configPath: options.configPath,
175
+ plugins: [options.index && indexFile(options.index)]
176
+ });
177
+ }
178
+ export {
179
+ createMDX,
180
+ postInstall
181
+ };
@@ -0,0 +1,5 @@
1
+ import { LoadHook } from 'node:module';
2
+
3
+ declare const load: LoadHook;
4
+
5
+ export { load };
@@ -0,0 +1,41 @@
1
+ import {
2
+ createMdxLoader
3
+ } from "../chunk-JWZR25CW.js";
4
+ import {
5
+ createMetaLoader
6
+ } from "../chunk-ZAYZWFWP.js";
7
+ import {
8
+ createStandaloneConfigLoader,
9
+ toNode
10
+ } from "../chunk-DMIIE3XZ.js";
11
+ import "../chunk-4JSFLXXT.js";
12
+ import {
13
+ _Defaults,
14
+ createCore
15
+ } from "../chunk-RR2X6AE6.js";
16
+ import "../chunk-PW2AZGGD.js";
17
+ import "../chunk-VWJKRQZR.js";
18
+
19
+ // src/node/loader.ts
20
+ var core = createCore({
21
+ environment: "node",
22
+ configPath: _Defaults.configPath,
23
+ outDir: _Defaults.outDir
24
+ });
25
+ var configLoader = createStandaloneConfigLoader({
26
+ core,
27
+ buildConfig: true,
28
+ mode: "production"
29
+ });
30
+ var mdxLoader = toNode(createMdxLoader(configLoader));
31
+ var metaLoader = toNode(createMetaLoader(configLoader));
32
+ var load = (url, context, nextLoad) => {
33
+ return mdxLoader(
34
+ url,
35
+ context,
36
+ (v, ctx) => metaLoader(v, { ...context, ...ctx }, nextLoad)
37
+ );
38
+ };
39
+ export {
40
+ load
41
+ };
@@ -0,0 +1,14 @@
1
+ export { H as IndexFilePlugin, I as IndexFilePluginOptions, F as default } from '../core-BhWOtait.js';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import '@hanzo/docs-core/mdx-plugins';
6
+ import '@hanzo/docs-core/source/schema';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+ import '@hanzo/docs-core/source';
10
+ import '../runtime/types.js';
11
+ import '@hanzo/docs-core/mdx-plugins/remark-structure';
12
+ import '@hanzo/docs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
@@ -0,0 +1,8 @@
1
+ import {
2
+ indexFile
3
+ } from "../chunk-A3YIGE7S.js";
4
+ import "../chunk-PW2AZGGD.js";
5
+ import "../chunk-VWJKRQZR.js";
6
+ export {
7
+ indexFile as default
8
+ };
@@ -0,0 +1,31 @@
1
+ import { k as Plugin } from '../core-BhWOtait.js';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import '@hanzo/docs-core/mdx-plugins';
6
+ import '@hanzo/docs-core/source/schema';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+ import '@hanzo/docs-core/source';
10
+ import '../runtime/types.js';
11
+ import '@hanzo/docs-core/mdx-plugins/remark-structure';
12
+ import '@hanzo/docs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
15
+
16
+ interface JSONSchemaOptions {
17
+ /**
18
+ * insert `$schema` field to JSON files on creation.
19
+ *
20
+ * @defaultValue false
21
+ */
22
+ insert?: boolean;
23
+ }
24
+ /**
25
+ * Generate JSON schemas locally for collection schemas
26
+ *
27
+ * note: **it only works with Zod**
28
+ */
29
+ declare function jsonSchema({ insert, }?: JSONSchemaOptions): Plugin;
30
+
31
+ export { type JSONSchemaOptions, jsonSchema as default };
@@ -0,0 +1,80 @@
1
+ // src/plugins/json-schema.ts
2
+ import { z } from "zod";
3
+ import fs from "fs/promises";
4
+ import path from "path";
5
+ function jsonSchema({
6
+ insert = false
7
+ } = {}) {
8
+ function getSchemaPath(name) {
9
+ return `json-schema/${name}.json`;
10
+ }
11
+ return {
12
+ configureServer(server) {
13
+ const { outDir } = this.core.getOptions();
14
+ if (!server.watcher || !insert) return;
15
+ server.watcher.on("add", async (file) => {
16
+ let parent;
17
+ let match;
18
+ for (const collection of this.core.getCollections()) {
19
+ if (collection.type === "meta" && collection.hasFile(file)) {
20
+ match = collection;
21
+ break;
22
+ }
23
+ if (collection.type === "docs" && collection.meta.hasFile(file)) {
24
+ parent = collection;
25
+ match = collection.meta;
26
+ break;
27
+ }
28
+ }
29
+ if (!match) return;
30
+ let obj;
31
+ try {
32
+ const content = (await fs.readFile(file)).toString();
33
+ obj = content.length > 0 ? JSON.parse(content) : {};
34
+ } catch {
35
+ return;
36
+ }
37
+ if ("$schema" in obj) return;
38
+ const schemaPath = path.join(
39
+ outDir,
40
+ getSchemaPath(parent ? `${parent.name}.meta` : match.name)
41
+ );
42
+ const updated = {
43
+ $schema: path.relative(path.dirname(file), schemaPath),
44
+ ...obj
45
+ };
46
+ await fs.writeFile(file, JSON.stringify(updated, null, 2));
47
+ });
48
+ },
49
+ emit() {
50
+ const files = [];
51
+ function onSchema(name, schema) {
52
+ files.push({
53
+ path: getSchemaPath(name),
54
+ content: JSON.stringify(
55
+ z.toJSONSchema(schema, {
56
+ io: "input",
57
+ unrepresentable: "any"
58
+ })
59
+ )
60
+ });
61
+ }
62
+ for (const collection of this.core.getCollections()) {
63
+ if (collection.type === "docs") {
64
+ if (collection.meta.schema instanceof z.ZodType) {
65
+ onSchema(`${collection.name}.meta`, collection.meta.schema);
66
+ }
67
+ if (collection.docs.schema instanceof z.ZodType) {
68
+ onSchema(`${collection.name}.docs`, collection.docs.schema);
69
+ }
70
+ } else if (collection.schema instanceof z.ZodType) {
71
+ onSchema(collection.name, collection.schema);
72
+ }
73
+ }
74
+ return files;
75
+ }
76
+ };
77
+ }
78
+ export {
79
+ jsonSchema as default
80
+ };
@@ -0,0 +1,40 @@
1
+ import { k as Plugin } from '../core-BhWOtait.js';
2
+ import '@mdx-js/mdx';
3
+ import '@standard-schema/spec';
4
+ import 'unified';
5
+ import '@hanzo/docs-core/mdx-plugins';
6
+ import '@hanzo/docs-core/source/schema';
7
+ import 'chokidar';
8
+ import 'vfile';
9
+ import '@hanzo/docs-core/source';
10
+ import '../runtime/types.js';
11
+ import '@hanzo/docs-core/mdx-plugins/remark-structure';
12
+ import '@hanzo/docs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
15
+
16
+ type VersionControlFn = (filePath: string) => Promise<Date | null | undefined>;
17
+ interface LastModifiedPluginOptions {
18
+ /**
19
+ * Version control to obtain the last modified time.
20
+ *
21
+ * - `git`: Requires `git` to be installed.
22
+ *
23
+ * If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`.
24
+ *
25
+ * - A function: return the last modified time for given file path.
26
+ *
27
+ * @defaultValue 'git'
28
+ */
29
+ versionControl?: 'git' | VersionControlFn;
30
+ /**
31
+ * Filter the collections to include by names
32
+ */
33
+ filter?: (collection: string) => boolean;
34
+ }
35
+ /**
36
+ * Injects `lastModified` property to page exports.
37
+ */
38
+ declare function lastModified(options?: LastModifiedPluginOptions): Plugin;
39
+
40
+ export { type LastModifiedPluginOptions, lastModified as default };
@@ -0,0 +1,89 @@
1
+ import {
2
+ ident
3
+ } from "../chunk-PW2AZGGD.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
+ let fn;
19
+ return {
20
+ name: "last-modified",
21
+ "index-file": {
22
+ generateTypeConfig() {
23
+ const lines = [];
24
+ lines.push("{");
25
+ lines.push(" DocData: {");
26
+ for (const collection of this.core.getCollections()) {
27
+ if (filter(collection.name)) {
28
+ lines.push(ident(`${collection.name}: ${ExtendTypes},`, 2));
29
+ }
30
+ }
31
+ lines.push(" }");
32
+ lines.push("}");
33
+ return lines.join("\n");
34
+ },
35
+ serverOptions(options2) {
36
+ options2.doc ??= {};
37
+ options2.doc.passthroughs ??= [];
38
+ options2.doc.passthroughs.push("lastModified");
39
+ }
40
+ },
41
+ config() {
42
+ const { workspace } = this.core.getOptions();
43
+ const cwd = workspace ? path.resolve(workspace.dir) : process.cwd();
44
+ switch (versionControl) {
45
+ case "git":
46
+ fn = (v) => getGitTimestamp(v, cwd);
47
+ break;
48
+ default:
49
+ fn = versionControl;
50
+ }
51
+ },
52
+ doc: {
53
+ async vfile(file) {
54
+ if (!filter(this.collection.name)) return;
55
+ const timestamp = await fn(this.filePath);
56
+ if (timestamp) {
57
+ file.data["mdx-export"] ??= [];
58
+ file.data["mdx-export"].push({
59
+ name: "lastModified",
60
+ value: timestamp
61
+ });
62
+ }
63
+ }
64
+ }
65
+ };
66
+ }
67
+ async function getGitTimestamp(file, cwd) {
68
+ const cached = cache.get(file);
69
+ if (cached) return cached;
70
+ const timePromise = (async () => {
71
+ const out = await x(
72
+ "git",
73
+ ["log", "-1", '--pretty="%ai"', path.relative(cwd, file)],
74
+ {
75
+ nodeOptions: {
76
+ cwd
77
+ }
78
+ }
79
+ );
80
+ if (out.exitCode !== 0) return null;
81
+ const date = new Date(out.stdout);
82
+ return isNaN(date.getTime()) ? null : date;
83
+ })();
84
+ cache.set(file, timePromise);
85
+ return timePromise;
86
+ }
87
+ export {
88
+ lastModified as default
89
+ };
@@ -0,0 +1,53 @@
1
+ import { ReactNode, FC } from 'react';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import { D as DocCollection, b as DocsCollection } from '../core-BhWOtait.js';
4
+ import { CompiledMDXProperties } from '../index.js';
5
+ import { InternalTypeConfig } from './types.js';
6
+ import '@mdx-js/mdx';
7
+ import 'unified';
8
+ import '@hanzo/docs-core/mdx-plugins';
9
+ import '@hanzo/docs-core/source/schema';
10
+ import 'chokidar';
11
+ import 'vfile';
12
+ import '@hanzo/docs-core/source';
13
+ import '@hanzo/docs-core/toc';
14
+ import 'mdx/types';
15
+ import '@hanzo/docs-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
+ };
@@ -0,0 +1,27 @@
1
+ import * as _hanzo_docs_core_source from '@hanzo/docs-core/source';
2
+ import { C as CoreOptions, S as ServerOptions, D as DocCollection, b as DocsCollection, i as AsyncDocCollectionEntry, j as AsyncDocsCollectionEntry } from '../core-BhWOtait.js';
3
+ import * as _standard_schema_spec from '@standard-schema/spec';
4
+ import { FileInfo, InternalTypeConfig } from './types.js';
5
+ import '@mdx-js/mdx';
6
+ import 'unified';
7
+ import '@hanzo/docs-core/mdx-plugins';
8
+ import '@hanzo/docs-core/source/schema';
9
+ import 'chokidar';
10
+ import 'vfile';
11
+ import '@hanzo/docs-core/mdx-plugins/remark-structure';
12
+ import '@hanzo/docs-core/toc';
13
+ import 'mdast';
14
+ import 'mdx/types';
15
+
16
+ interface LazyEntry<Data = unknown> {
17
+ info: FileInfo;
18
+ data: Data;
19
+ hash?: string;
20
+ }
21
+ type CreateDynamic<Config, TC extends InternalTypeConfig = InternalTypeConfig> = ReturnType<typeof dynamic<Config, TC>>;
22
+ declare function dynamic<Config, TC extends InternalTypeConfig>(configExports: Config, coreOptions: CoreOptions, serverOptions?: ServerOptions): Promise<{
23
+ doc<Name extends keyof Config & string>(name: Name, base: string, entries: LazyEntry<unknown>[]): Promise<Config[Name] extends DocCollection<infer Schema extends _standard_schema_spec.StandardSchemaV1<unknown, unknown>> | DocsCollection<infer Schema extends _standard_schema_spec.StandardSchemaV1<unknown, unknown>, _standard_schema_spec.StandardSchemaV1<unknown, unknown>> ? AsyncDocCollectionEntry<Name, _standard_schema_spec.StandardSchemaV1.InferOutput<Schema>, TC>[] : never>;
24
+ docs<Name extends keyof Config & string>(name: Name, base: string, meta: Record<string, unknown>, entries: LazyEntry<unknown>[]): Promise<Config[Name] extends DocsCollection<infer Page extends _standard_schema_spec.StandardSchemaV1<unknown, unknown>, infer Meta extends _standard_schema_spec.StandardSchemaV1<unknown, unknown>> ? _standard_schema_spec.StandardSchemaV1.InferOutput<Page> extends _hanzo_docs_core_source.PageData ? _standard_schema_spec.StandardSchemaV1.InferOutput<Meta> extends _hanzo_docs_core_source.MetaData ? AsyncDocsCollectionEntry<Name, _standard_schema_spec.StandardSchemaV1.InferOutput<Page>, _standard_schema_spec.StandardSchemaV1.InferOutput<Meta>, TC> : never : never : never>;
25
+ }>;
26
+
27
+ export { type CreateDynamic, type LazyEntry, dynamic };