fumadocs-mdx 14.0.1 → 14.0.3

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 (72) hide show
  1. package/dist/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
  2. package/dist/bun/index.d.ts +1 -1
  3. package/dist/bun/index.js +8 -8
  4. package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
  5. package/dist/{chunk-7UKSZSPY.js → chunk-DKA3EWZH.js} +6 -7
  6. package/dist/{chunk-BEBCWQC7.js → chunk-GB4W3YCZ.js} +1 -1
  7. package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
  8. package/dist/{chunk-MTTISKQJ.js → chunk-LPX7ZO66.js} +1 -1
  9. package/dist/{chunk-K6HCOGOX.js → chunk-OLL7FM7W.js} +2 -2
  10. package/dist/{chunk-IQGEFL2B.js → chunk-Q5OSGLJL.js} +1 -1
  11. package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
  12. package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
  13. package/dist/config/index.d.ts +1 -1
  14. package/dist/config/index.js +1 -1
  15. package/dist/{core-B9ZoS6sA.d.ts → core-C3QZSdEx.d.ts} +1 -1
  16. package/dist/{index-BD8Woo4m.d.cts → index-DG1I0CwF.d.ts} +2 -2
  17. package/dist/index.d.ts +1 -1
  18. package/dist/load-from-file-OZ5N7DXU.js +8 -0
  19. package/dist/next/index.cjs +10 -8
  20. package/dist/next/index.d.ts +1 -1
  21. package/dist/next/index.js +8 -8
  22. package/dist/node/loader.js +4 -4
  23. package/dist/plugins/index-file.d.ts +1 -1
  24. package/dist/plugins/index-file.js +2 -2
  25. package/dist/plugins/json-schema.d.ts +1 -1
  26. package/dist/plugins/last-modified.d.ts +5 -2
  27. package/dist/plugins/last-modified.js +10 -3
  28. package/dist/runtime/browser.d.ts +1 -1
  29. package/dist/runtime/dynamic.d.ts +1 -1
  30. package/dist/runtime/dynamic.js +5 -5
  31. package/dist/runtime/server.d.ts +1 -1
  32. package/dist/vite/index.d.ts +1 -1
  33. package/dist/vite/index.js +10 -10
  34. package/dist/webpack/mdx.d.ts +2 -2
  35. package/dist/webpack/mdx.js +6 -6
  36. package/dist/webpack/meta.d.ts +2 -2
  37. package/dist/webpack/meta.js +4 -4
  38. package/package.json +4 -6
  39. package/dist/bin.cjs +0 -1958
  40. package/dist/bin.d.cts +0 -1
  41. package/dist/bun/index.cjs +0 -1147
  42. package/dist/bun/index.d.cts +0 -25
  43. package/dist/config/index.cjs +0 -400
  44. package/dist/config/index.d.cts +0 -18
  45. package/dist/core-DTuP23zu.d.cts +0 -341
  46. package/dist/index-CNOvhtOn.d.ts +0 -8
  47. package/dist/index.cjs +0 -18
  48. package/dist/index.d.cts +0 -61
  49. package/dist/load-from-file-5HUQN36V.js +0 -8
  50. package/dist/next/index.d.cts +0 -33
  51. package/dist/node/loader.cjs +0 -1200
  52. package/dist/node/loader.d.cts +0 -5
  53. package/dist/plugins/index-file.cjs +0 -495
  54. package/dist/plugins/index-file.d.cts +0 -14
  55. package/dist/plugins/json-schema.cjs +0 -114
  56. package/dist/plugins/json-schema.d.cts +0 -31
  57. package/dist/plugins/last-modified.cjs +0 -110
  58. package/dist/plugins/last-modified.d.cts +0 -37
  59. package/dist/runtime/browser.cjs +0 -93
  60. package/dist/runtime/browser.d.cts +0 -53
  61. package/dist/runtime/dynamic.cjs +0 -1023
  62. package/dist/runtime/dynamic.d.cts +0 -27
  63. package/dist/runtime/server.cjs +0 -176
  64. package/dist/runtime/server.d.cts +0 -14
  65. package/dist/runtime/types.cjs +0 -18
  66. package/dist/runtime/types.d.cts +0 -61
  67. package/dist/vite/index.cjs +0 -1687
  68. package/dist/vite/index.d.cts +0 -44
  69. package/dist/webpack/mdx.cjs +0 -1124
  70. package/dist/webpack/mdx.d.cts +0 -20
  71. package/dist/webpack/meta.cjs +0 -684
  72. package/dist/webpack/meta.d.cts +0 -20
@@ -1,25 +0,0 @@
1
- import { BunPlugin } from 'bun';
2
- import { i as CoreOptions } from '../core-DTuP23zu.cjs';
3
- import '@mdx-js/mdx';
4
- import '@standard-schema/spec';
5
- import 'unified';
6
- import 'fumadocs-core/mdx-plugins';
7
- import 'zod';
8
- import 'chokidar';
9
- import 'vfile';
10
- import 'fumadocs-core/source';
11
- import '../runtime/types.cjs';
12
- import 'fumadocs-core/mdx-plugins/remark-structure';
13
- import 'fumadocs-core/toc';
14
- import 'mdast';
15
- import 'mdx/types';
16
-
17
- interface MdxPluginOptions extends Partial<CoreOptions> {
18
- /**
19
- * Skip meta file transformation step
20
- */
21
- disableMetaFile?: boolean;
22
- }
23
- declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
24
-
25
- export { type MdxPluginOptions, createMdxPlugin };
@@ -1,400 +0,0 @@
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/config/index.ts
31
- var config_exports = {};
32
- __export(config_exports, {
33
- applyMdxPreset: () => applyMdxPreset,
34
- defineCollections: () => defineCollections,
35
- defineConfig: () => defineConfig,
36
- defineDocs: () => defineDocs,
37
- frontmatterSchema: () => frontmatterSchema,
38
- metaSchema: () => metaSchema,
39
- remarkInclude: () => remarkInclude
40
- });
41
- module.exports = __toCommonJS(config_exports);
42
-
43
- // src/config/zod-4.ts
44
- var import_zod = require("zod");
45
- var metaSchema = import_zod.z.object({
46
- title: import_zod.z.string().optional(),
47
- pages: import_zod.z.array(import_zod.z.string()).optional(),
48
- description: import_zod.z.string().optional(),
49
- root: import_zod.z.boolean().optional(),
50
- defaultOpen: import_zod.z.boolean().optional(),
51
- icon: import_zod.z.string().optional()
52
- });
53
- var frontmatterSchema = import_zod.z.object({
54
- title: import_zod.z.string(),
55
- description: import_zod.z.string().optional(),
56
- icon: import_zod.z.string().optional(),
57
- full: import_zod.z.boolean().optional(),
58
- // Fumadocs OpenAPI generated
59
- _openapi: import_zod.z.looseObject({}).optional()
60
- });
61
-
62
- // src/config/define.ts
63
- function defineCollections(options) {
64
- return options;
65
- }
66
- function defineDocs(options) {
67
- const dir = options.dir ?? "content/docs";
68
- return {
69
- type: "docs",
70
- dir,
71
- docs: defineCollections({
72
- type: "doc",
73
- dir,
74
- schema: frontmatterSchema,
75
- ...options?.docs
76
- }),
77
- meta: defineCollections({
78
- type: "meta",
79
- dir,
80
- schema: metaSchema,
81
- ...options?.meta
82
- })
83
- };
84
- }
85
- function defineConfig(config = {}) {
86
- return config;
87
- }
88
-
89
- // src/config/preset.ts
90
- function pluginOption(def, options = []) {
91
- const list = def(Array.isArray(options) ? options : []).filter(
92
- Boolean
93
- );
94
- if (typeof options === "function") {
95
- return options(list);
96
- }
97
- return list;
98
- }
99
- function applyMdxPreset(options = {}) {
100
- return async (environment = "bundler") => {
101
- if (options.preset === "minimal") return options;
102
- const plugins = await import("fumadocs-core/mdx-plugins");
103
- const {
104
- valueToExport = [],
105
- rehypeCodeOptions,
106
- remarkImageOptions,
107
- remarkHeadingOptions,
108
- remarkStructureOptions,
109
- remarkCodeTabOptions,
110
- remarkNpmOptions,
111
- ...mdxOptions
112
- } = options;
113
- const remarkPlugins = pluginOption(
114
- (v) => [
115
- plugins.remarkGfm,
116
- [
117
- plugins.remarkHeading,
118
- {
119
- generateToc: false,
120
- ...remarkHeadingOptions
121
- }
122
- ],
123
- remarkImageOptions !== false && [
124
- plugins.remarkImage,
125
- {
126
- ...remarkImageOptions,
127
- useImport: remarkImageOptions?.useImport ?? environment === "bundler"
128
- }
129
- ],
130
- "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
131
- plugins.remarkCodeTab,
132
- remarkCodeTabOptions
133
- ],
134
- "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
135
- ...v,
136
- remarkStructureOptions !== false && [
137
- plugins.remarkStructure,
138
- remarkStructureOptions
139
- ],
140
- valueToExport.length > 0 && (() => {
141
- return (_, file) => {
142
- file.data["mdx-export"] ??= [];
143
- for (const name of valueToExport) {
144
- if (!(name in file.data)) continue;
145
- file.data["mdx-export"].push({
146
- name,
147
- value: file.data[name]
148
- });
149
- }
150
- };
151
- })
152
- ],
153
- mdxOptions.remarkPlugins
154
- );
155
- const rehypePlugins = pluginOption(
156
- (v) => [
157
- rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
158
- ...v,
159
- plugins.rehypeToc
160
- ],
161
- mdxOptions.rehypePlugins
162
- );
163
- return {
164
- ...mdxOptions,
165
- outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
166
- remarkPlugins,
167
- rehypePlugins
168
- };
169
- };
170
- }
171
-
172
- // src/loaders/mdx/remark-include.ts
173
- var import_unified = require("unified");
174
- var import_unist_util_visit2 = require("unist-util-visit");
175
- var path = __toESM(require("path"), 1);
176
- var fs = __toESM(require("fs/promises"), 1);
177
-
178
- // src/utils/fuma-matter.ts
179
- var import_js_yaml = require("js-yaml");
180
- var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
181
- function fumaMatter(input) {
182
- const output = { matter: "", data: {}, content: input };
183
- const match = regex.exec(input);
184
- if (!match) {
185
- return output;
186
- }
187
- output.matter = match[0];
188
- output.content = input.slice(match[0].length);
189
- const loaded = (0, import_js_yaml.load)(match[1]);
190
- output.data = loaded ?? {};
191
- return output;
192
- }
193
-
194
- // src/loaders/mdx/remark-include.ts
195
- var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
196
-
197
- // src/loaders/mdx/remark-unravel.ts
198
- var import_unist_util_visit = require("unist-util-visit");
199
- function remarkMarkAndUnravel() {
200
- return (tree) => {
201
- (0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
202
- let offset = -1;
203
- let all = true;
204
- let oneOrMore = false;
205
- if (parent && typeof index === "number" && node.type === "paragraph") {
206
- const children = node.children;
207
- while (++offset < children.length) {
208
- const child = children[offset];
209
- if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
210
- oneOrMore = true;
211
- } else if (child.type === "text" && child.value.trim().length === 0) {
212
- } else {
213
- all = false;
214
- break;
215
- }
216
- }
217
- if (all && oneOrMore) {
218
- offset = -1;
219
- const newChildren = [];
220
- while (++offset < children.length) {
221
- const child = children[offset];
222
- if (child.type === "mdxJsxTextElement") {
223
- child.type = "mdxJsxFlowElement";
224
- }
225
- if (child.type === "mdxTextExpression") {
226
- child.type = "mdxFlowExpression";
227
- }
228
- if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
229
- } else {
230
- newChildren.push(child);
231
- }
232
- }
233
- parent.children.splice(index, 1, ...newChildren);
234
- return index;
235
- }
236
- }
237
- });
238
- };
239
- }
240
-
241
- // src/loaders/mdx/mdast-utils.ts
242
- function flattenNode(node) {
243
- if ("children" in node)
244
- return node.children.map((child) => flattenNode(child)).join("");
245
- if ("value" in node) return node.value;
246
- return "";
247
- }
248
-
249
- // src/loaders/mdx/remark-include.ts
250
- var ElementLikeTypes = [
251
- "mdxJsxFlowElement",
252
- "mdxJsxTextElement",
253
- "containerDirective",
254
- "textDirective",
255
- "leafDirective"
256
- ];
257
- function isElementLike(node) {
258
- return ElementLikeTypes.includes(node.type);
259
- }
260
- function parseElementAttributes(element) {
261
- if (Array.isArray(element.attributes)) {
262
- const attributes = {};
263
- for (const attr of element.attributes) {
264
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
265
- attributes[attr.name] = attr.value;
266
- }
267
- }
268
- return attributes;
269
- }
270
- return element.attributes ?? {};
271
- }
272
- function parseSpecifier(specifier) {
273
- const idx = specifier.lastIndexOf("#");
274
- if (idx === -1) return { file: specifier };
275
- return {
276
- file: specifier.slice(0, idx),
277
- section: specifier.slice(idx + 1)
278
- };
279
- }
280
- function extractSection(root, section) {
281
- let nodes;
282
- let capturingHeadingContent = false;
283
- (0, import_unist_util_visit2.visit)(root, (node) => {
284
- if (node.type === "heading") {
285
- if (capturingHeadingContent) {
286
- return false;
287
- }
288
- if (node.data?.hProperties?.id === section) {
289
- capturingHeadingContent = true;
290
- nodes = [node];
291
- return "skip";
292
- }
293
- return;
294
- }
295
- if (capturingHeadingContent) {
296
- nodes?.push(node);
297
- return "skip";
298
- }
299
- if (isElementLike(node) && node.name === "section") {
300
- const attributes = parseElementAttributes(node);
301
- if (attributes.id === section) {
302
- nodes = node.children;
303
- return false;
304
- }
305
- }
306
- });
307
- if (nodes)
308
- return {
309
- type: "root",
310
- children: nodes
311
- };
312
- }
313
- function remarkInclude() {
314
- const TagName = "include";
315
- const embedContent = async (file, heading, params, data) => {
316
- let content;
317
- try {
318
- content = (await fs.readFile(file)).toString();
319
- } catch (e) {
320
- throw new Error(
321
- `failed to read file ${file}
322
- ${e instanceof Error ? e.message : String(e)}`,
323
- { cause: e }
324
- );
325
- }
326
- const ext = path.extname(file);
327
- data._compiler?.addDependency(file);
328
- if (params.lang || ext !== ".md" && ext !== ".mdx") {
329
- const lang = params.lang ?? ext.slice(1);
330
- return {
331
- type: "code",
332
- lang,
333
- meta: params.meta,
334
- value: content,
335
- data: {}
336
- };
337
- }
338
- const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
339
- const parsed = fumaMatter(content);
340
- let mdast = parser.parse({
341
- path: file,
342
- value: parsed.content,
343
- data: { frontmatter: parsed.data }
344
- });
345
- const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
346
- if (heading) {
347
- const extracted = extractSection(
348
- await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
349
- heading
350
- );
351
- if (!extracted)
352
- throw new Error(
353
- `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
354
- );
355
- mdast = extracted;
356
- } else {
357
- mdast = await baseProcessor.run(mdast);
358
- }
359
- await update(mdast, path.dirname(file), data);
360
- return mdast;
361
- };
362
- async function update(tree, directory, data) {
363
- const queue = [];
364
- (0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
365
- const node = _node;
366
- if (node.name !== TagName) return;
367
- const specifier = flattenNode(node);
368
- if (specifier.length === 0) return "skip";
369
- const attributes = parseElementAttributes(node);
370
- const { file: relativePath, section } = parseSpecifier(specifier);
371
- const file = path.resolve(
372
- "cwd" in attributes ? process.cwd() : directory,
373
- relativePath
374
- );
375
- queue.push(
376
- embedContent(file, section, attributes, data).then((replace) => {
377
- Object.assign(
378
- parent && parent.type === "paragraph" ? parent : node,
379
- replace
380
- );
381
- })
382
- );
383
- return "skip";
384
- });
385
- await Promise.all(queue);
386
- }
387
- return async (tree, file) => {
388
- await update(tree, path.dirname(file.path), file.data);
389
- };
390
- }
391
- // Annotate the CommonJS export names for ESM import in node:
392
- 0 && (module.exports = {
393
- applyMdxPreset,
394
- defineCollections,
395
- defineConfig,
396
- defineDocs,
397
- frontmatterSchema,
398
- metaSchema,
399
- remarkInclude
400
- });
@@ -1,18 +0,0 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, e as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, f as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, g as applyMdxPreset, d as defineCollections, c as defineConfig, b as defineDocs, h as frontmatterSchema, m as metaSchema } from '../core-DTuP23zu.cjs';
2
- import { Processor, Transformer } from 'unified';
3
- import { Root } from 'mdast';
4
- import '@mdx-js/mdx';
5
- import '@standard-schema/spec';
6
- import 'fumadocs-core/mdx-plugins';
7
- import 'zod';
8
- import 'chokidar';
9
- import 'vfile';
10
- import 'fumadocs-core/source';
11
- import '../runtime/types.cjs';
12
- import 'fumadocs-core/mdx-plugins/remark-structure';
13
- import 'fumadocs-core/toc';
14
- import 'mdx/types';
15
-
16
- declare function remarkInclude(this: Processor): Transformer<Root, Root>;
17
-
18
- export { remarkInclude };