@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,40 @@
1
+ import {
2
+ buildConfig
3
+ } from "./chunk-MYAVS2LD.js";
4
+
5
+ // src/config/load-from-file.ts
6
+ import { pathToFileURL } from "url";
7
+ async function compileConfig(core) {
8
+ const { build } = await import("esbuild");
9
+ const { configPath, outDir } = core.getOptions();
10
+ const transformed = await build({
11
+ entryPoints: [{ in: configPath, out: "source.config" }],
12
+ bundle: true,
13
+ outdir: outDir,
14
+ target: "node20",
15
+ write: true,
16
+ platform: "node",
17
+ format: "esm",
18
+ packages: "external",
19
+ outExtension: {
20
+ ".js": ".mjs"
21
+ },
22
+ allowOverwrite: true
23
+ });
24
+ if (transformed.errors.length > 0) {
25
+ throw new Error("failed to compile configuration file");
26
+ }
27
+ }
28
+ async function loadConfig(core, build = false) {
29
+ if (build) await compileConfig(core);
30
+ const url = pathToFileURL(core.getCompiledConfigPath());
31
+ url.searchParams.set("hash", Date.now().toString());
32
+ const config = import(url.href).then(
33
+ (loaded) => buildConfig(loaded)
34
+ );
35
+ return await config;
36
+ }
37
+
38
+ export {
39
+ loadConfig
40
+ };
@@ -0,0 +1,274 @@
1
+ import {
2
+ ident
3
+ } from "./chunk-PW2AZGGD.js";
4
+
5
+ // src/utils/validation.ts
6
+ var ValidationError = class extends Error {
7
+ constructor(message, issues) {
8
+ super(
9
+ `${message}:
10
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
11
+ );
12
+ this.title = message;
13
+ this.issues = issues;
14
+ }
15
+ async toStringFormatted() {
16
+ const picocolorsModule = await import("picocolors");
17
+ const picocolors = picocolorsModule.default ?? picocolorsModule;
18
+ return [
19
+ picocolors.bold(`[MDX] ${this.title}:`),
20
+ ...this.issues.map(
21
+ (issue) => picocolors.redBright(
22
+ `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
23
+ )
24
+ )
25
+ ].join("\n");
26
+ }
27
+ };
28
+ async function validate(schema, data, context, errorMessage) {
29
+ if (typeof schema === "function" && !("~standard" in schema)) {
30
+ schema = schema(context);
31
+ }
32
+ if ("~standard" in schema) {
33
+ const result = await schema["~standard"].validate(
34
+ data
35
+ );
36
+ if (result.issues) {
37
+ throw new ValidationError(errorMessage, result.issues);
38
+ }
39
+ return result.value;
40
+ }
41
+ return data;
42
+ }
43
+
44
+ // src/core.ts
45
+ import path from "path";
46
+ import fs from "fs/promises";
47
+ var _Defaults = {
48
+ configPath: "source.config.ts",
49
+ outDir: ".docs"
50
+ };
51
+ async function getPlugins(pluginOptions) {
52
+ const plugins = [];
53
+ for await (const option of pluginOptions) {
54
+ if (!option) continue;
55
+ if (Array.isArray(option)) plugins.push(...await getPlugins(option));
56
+ else plugins.push(option);
57
+ }
58
+ return plugins;
59
+ }
60
+ function createCore(options) {
61
+ let config;
62
+ let plugins;
63
+ const workspaces = /* @__PURE__ */ new Map();
64
+ async function transformMetadata({
65
+ collection,
66
+ filePath,
67
+ source
68
+ }, data) {
69
+ if (collection.schema) {
70
+ data = await validate(
71
+ collection.schema,
72
+ data,
73
+ { path: filePath, source },
74
+ collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
75
+ );
76
+ }
77
+ return data;
78
+ }
79
+ return {
80
+ /**
81
+ * Convenient cache store, reset when config changes
82
+ */
83
+ cache: /* @__PURE__ */ new Map(),
84
+ async init({ config: newConfig }) {
85
+ config = await newConfig;
86
+ this.cache.clear();
87
+ workspaces.clear();
88
+ plugins = await getPlugins([
89
+ postprocessPlugin(),
90
+ options.plugins,
91
+ config.global.plugins
92
+ ]);
93
+ for (const plugin of plugins) {
94
+ const out = await plugin.config?.call(this.getPluginContext(), config);
95
+ if (out) config = out;
96
+ }
97
+ if (!options.workspace) {
98
+ await Promise.all(
99
+ Object.entries(config.workspaces).map(async ([name, workspace]) => {
100
+ const core = createCore({
101
+ ...options,
102
+ outDir: path.join(options.outDir, name),
103
+ workspace: {
104
+ name,
105
+ parent: this,
106
+ dir: workspace.dir
107
+ }
108
+ });
109
+ await core.init({ config: workspace.config });
110
+ workspaces.set(name, core);
111
+ })
112
+ );
113
+ }
114
+ },
115
+ getWorkspaces() {
116
+ return workspaces;
117
+ },
118
+ getOptions() {
119
+ return options;
120
+ },
121
+ getConfig() {
122
+ return config;
123
+ },
124
+ /**
125
+ * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
126
+ */
127
+ getCompiledConfigPath() {
128
+ return path.join(options.outDir, "source.config.mjs");
129
+ },
130
+ getPlugins() {
131
+ return plugins;
132
+ },
133
+ getCollections() {
134
+ return Array.from(config.collections.values());
135
+ },
136
+ getCollection(name) {
137
+ return config.collections.get(name);
138
+ },
139
+ getPluginContext() {
140
+ return {
141
+ core: this
142
+ };
143
+ },
144
+ async initServer(server) {
145
+ const ctx = this.getPluginContext();
146
+ for (const plugin of plugins) {
147
+ await plugin.configureServer?.call(ctx, server);
148
+ }
149
+ for (const workspace of workspaces.values()) {
150
+ await workspace.initServer(server);
151
+ }
152
+ },
153
+ async emit(emitOptions = {}) {
154
+ const { filterPlugin, filterWorkspace, write = false } = emitOptions;
155
+ const start = performance.now();
156
+ const ctx = this.getPluginContext();
157
+ const added = /* @__PURE__ */ new Set();
158
+ const out = {
159
+ entries: [],
160
+ workspaces: {}
161
+ };
162
+ for (const li of await Promise.all(
163
+ plugins.map((plugin) => {
164
+ if (filterPlugin && !filterPlugin(plugin) || !plugin.emit) return;
165
+ return plugin.emit.call(ctx);
166
+ })
167
+ )) {
168
+ if (!li) continue;
169
+ for (const item of li) {
170
+ if (added.has(item.path)) continue;
171
+ out.entries.push(item);
172
+ added.add(item.path);
173
+ }
174
+ }
175
+ if (write) {
176
+ await Promise.all(
177
+ out.entries.map(async (entry) => {
178
+ const file = path.join(options.outDir, entry.path);
179
+ await fs.mkdir(path.dirname(file), { recursive: true });
180
+ await fs.writeFile(file, entry.content);
181
+ })
182
+ );
183
+ console.log(
184
+ options.workspace ? `[MDX: ${options.workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
185
+ );
186
+ }
187
+ for (const [name, workspace] of workspaces) {
188
+ if (filterWorkspace && !filterWorkspace(name)) continue;
189
+ out.workspaces[name] = (await workspace.emit(emitOptions)).entries;
190
+ }
191
+ return out;
192
+ },
193
+ async transformMeta(options2, data) {
194
+ const ctx = {
195
+ ...this.getPluginContext(),
196
+ ...options2
197
+ };
198
+ data = await transformMetadata(options2, data);
199
+ for (const plugin of plugins) {
200
+ if (plugin.meta?.transform)
201
+ data = await plugin.meta.transform.call(ctx, data) ?? data;
202
+ }
203
+ return data;
204
+ },
205
+ async transformFrontmatter(options2, data) {
206
+ const ctx = {
207
+ ...this.getPluginContext(),
208
+ ...options2
209
+ };
210
+ data = await transformMetadata(options2, data);
211
+ for (const plugin of plugins) {
212
+ if (plugin.doc?.frontmatter)
213
+ data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
214
+ }
215
+ return data;
216
+ },
217
+ async transformVFile(options2, file) {
218
+ const ctx = {
219
+ ...this.getPluginContext(),
220
+ ...options2
221
+ };
222
+ for (const plugin of plugins) {
223
+ if (plugin.doc?.vfile)
224
+ file = await plugin.doc.vfile.call(ctx, file) ?? file;
225
+ }
226
+ return file;
227
+ }
228
+ };
229
+ }
230
+ function postprocessPlugin() {
231
+ const LinkReferenceTypes = `{
232
+ /**
233
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
234
+ */
235
+ extractedReferences: import("@hanzo/docs-mdx").ExtractedReference[];
236
+ }`;
237
+ return {
238
+ "index-file": {
239
+ generateTypeConfig() {
240
+ const lines = [];
241
+ lines.push("{");
242
+ lines.push(" DocData: {");
243
+ for (const collection of this.core.getCollections()) {
244
+ let postprocessOptions;
245
+ switch (collection.type) {
246
+ case "doc":
247
+ postprocessOptions = collection.postprocess;
248
+ break;
249
+ case "docs":
250
+ postprocessOptions = collection.docs.postprocess;
251
+ break;
252
+ }
253
+ if (postprocessOptions?.extractLinkReferences) {
254
+ lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
255
+ }
256
+ }
257
+ lines.push(" }");
258
+ lines.push("}");
259
+ return lines.join("\n");
260
+ },
261
+ serverOptions(options) {
262
+ options.doc ??= {};
263
+ options.doc.passthroughs ??= [];
264
+ options.doc.passthroughs.push("extractedReferences");
265
+ }
266
+ }
267
+ };
268
+ }
269
+
270
+ export {
271
+ ValidationError,
272
+ _Defaults,
273
+ createCore
274
+ };
@@ -0,0 +1,89 @@
1
+ // src/config/preset.ts
2
+ function pluginOption(def, options = []) {
3
+ const list = def(Array.isArray(options) ? options : []).filter(
4
+ Boolean
5
+ );
6
+ if (typeof options === "function") {
7
+ return options(list);
8
+ }
9
+ return list;
10
+ }
11
+ function applyMdxPreset(options = {}) {
12
+ return async (environment = "bundler") => {
13
+ if (options.preset === "minimal") return options;
14
+ const plugins = await import("fumadocs-core/mdx-plugins");
15
+ const {
16
+ valueToExport = [],
17
+ rehypeCodeOptions,
18
+ remarkImageOptions,
19
+ remarkHeadingOptions,
20
+ remarkStructureOptions,
21
+ remarkCodeTabOptions,
22
+ remarkNpmOptions,
23
+ ...mdxOptions
24
+ } = options;
25
+ const remarkPlugins = pluginOption(
26
+ (v) => [
27
+ plugins.remarkGfm,
28
+ [
29
+ plugins.remarkHeading,
30
+ {
31
+ generateToc: false,
32
+ ...remarkHeadingOptions
33
+ }
34
+ ],
35
+ remarkImageOptions !== false && [
36
+ plugins.remarkImage,
37
+ {
38
+ ...remarkImageOptions,
39
+ useImport: remarkImageOptions?.useImport ?? environment === "bundler"
40
+ }
41
+ ],
42
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
43
+ plugins.remarkCodeTab,
44
+ remarkCodeTabOptions
45
+ ],
46
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
47
+ ...v,
48
+ remarkStructureOptions !== false && [
49
+ plugins.remarkStructure,
50
+ {
51
+ exportAs: "structuredData",
52
+ ...remarkStructureOptions
53
+ }
54
+ ],
55
+ valueToExport.length > 0 && (() => {
56
+ return (_, file) => {
57
+ file.data["mdx-export"] ??= [];
58
+ for (const name of valueToExport) {
59
+ if (!(name in file.data)) continue;
60
+ file.data["mdx-export"].push({
61
+ name,
62
+ value: file.data[name]
63
+ });
64
+ }
65
+ };
66
+ })
67
+ ],
68
+ mdxOptions.remarkPlugins
69
+ );
70
+ const rehypePlugins = pluginOption(
71
+ (v) => [
72
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
73
+ ...v,
74
+ plugins.rehypeToc
75
+ ],
76
+ mdxOptions.rehypePlugins
77
+ );
78
+ return {
79
+ ...mdxOptions,
80
+ outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
81
+ remarkPlugins,
82
+ rehypePlugins
83
+ };
84
+ };
85
+ }
86
+
87
+ export {
88
+ applyMdxPreset
89
+ };