fumadocs-core 15.2.8 → 16.3.2

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 (145) hide show
  1. package/README.md +1 -1
  2. package/dist/algolia-IZEDLPHE.js +58 -0
  3. package/dist/breadcrumb.d.ts +7 -5
  4. package/dist/breadcrumb.js +46 -52
  5. package/dist/chunk-5PMI7QDD.js +220 -0
  6. package/dist/chunk-ADBHPKXG.js +78 -0
  7. package/dist/chunk-APKPSBSB.js +74 -0
  8. package/dist/chunk-CH7YHH7V.js +222 -0
  9. package/dist/chunk-EFVXL2PP.js +144 -0
  10. package/dist/{chunk-ORHEEQVY.js → chunk-EMWGTXSW.js} +0 -7
  11. package/dist/chunk-FAEPKD7U.js +20 -0
  12. package/dist/chunk-FUUVPEA5.js +29 -0
  13. package/dist/chunk-GINBKBVQ.js +12 -0
  14. package/dist/chunk-GLRQBLGN.js +59 -0
  15. package/dist/chunk-JUF4WZ6G.js +117 -0
  16. package/dist/chunk-K4WNLOVQ.js +75 -0
  17. package/dist/chunk-L4JKQWCM.js +131 -0
  18. package/dist/{chunk-Y2774T3B.js → chunk-MA6O2UUE.js} +10 -18
  19. package/dist/chunk-ONG4RVCR.js +8 -0
  20. package/dist/chunk-OTD7MV33.js +53 -0
  21. package/dist/chunk-PFNP6PEB.js +11 -0
  22. package/dist/chunk-QJRXMG4S.js +275 -0
  23. package/dist/{chunk-NNKVN7WA.js → chunk-SH7BNTG7.js} +7 -4
  24. package/dist/chunk-TWIDBWFG.js +84 -0
  25. package/dist/chunk-U67V476Y.js +35 -0
  26. package/dist/chunk-VLSDGCJE.js +47 -0
  27. package/dist/chunk-W6WTLKRA.js +73 -0
  28. package/dist/chunk-XJ6ZQNEX.js +91 -0
  29. package/dist/{chunk-BUCUQ3WX.js → chunk-XN2LKXFZ.js} +39 -34
  30. package/dist/{chunk-WFUH5VBX.js → chunk-XOFXGHS4.js} +26 -10
  31. package/dist/chunk-XZSI7AHE.js +67 -0
  32. package/dist/chunk-YVVDKJ2H.js +34 -0
  33. package/dist/chunk-ZMWYLUDP.js +21 -0
  34. package/dist/content/github.d.ts +40 -0
  35. package/dist/content/github.js +44 -0
  36. package/dist/content/index.d.ts +16 -0
  37. package/dist/content/index.js +30 -0
  38. package/dist/content/mdx/preset-bundler.d.ts +31 -0
  39. package/dist/content/mdx/preset-bundler.js +72 -0
  40. package/dist/content/mdx/preset-runtime.d.ts +31 -0
  41. package/dist/content/mdx/preset-runtime.js +71 -0
  42. package/dist/{get-toc-Cr2URuiP.d.ts → content/toc.d.ts} +6 -10
  43. package/dist/content/toc.js +22 -0
  44. package/dist/definitions-pJ7PybYY.d.ts +60 -0
  45. package/dist/dynamic-link.js +3 -3
  46. package/dist/fetch-IBTWQCJR.js +22 -0
  47. package/dist/framework/index.d.ts +2 -9
  48. package/dist/framework/index.js +2 -4
  49. package/dist/framework/next.d.ts +5 -1
  50. package/dist/framework/next.js +9 -5
  51. package/dist/framework/react-router.d.ts +5 -1
  52. package/dist/framework/react-router.js +16 -4
  53. package/dist/framework/tanstack.d.ts +5 -1
  54. package/dist/framework/tanstack.js +33 -8
  55. package/dist/framework/waku.d.ts +12 -0
  56. package/dist/framework/waku.js +63 -0
  57. package/dist/highlight/client.d.ts +8 -5
  58. package/dist/highlight/client.js +9 -93
  59. package/dist/highlight/index.d.ts +20 -5
  60. package/dist/highlight/index.js +10 -6
  61. package/dist/i18n/index.d.ts +35 -8
  62. package/dist/i18n/index.js +5 -69
  63. package/dist/i18n/middleware.d.ts +34 -0
  64. package/dist/i18n/middleware.js +76 -0
  65. package/dist/link.js +3 -3
  66. package/dist/loader-_E2HOdV0.d.ts +333 -0
  67. package/dist/mdx-plugins/codeblock-utils.d.ts +29 -0
  68. package/dist/mdx-plugins/codeblock-utils.js +9 -0
  69. package/dist/mdx-plugins/index.d.ts +18 -134
  70. package/dist/mdx-plugins/index.js +51 -914
  71. package/dist/mdx-plugins/rehype-code.d.ts +55 -0
  72. package/dist/mdx-plugins/rehype-code.js +15 -0
  73. package/dist/mdx-plugins/rehype-toc.d.ts +14 -0
  74. package/dist/mdx-plugins/rehype-toc.js +7 -0
  75. package/dist/mdx-plugins/remark-admonition.d.ts +20 -0
  76. package/dist/mdx-plugins/remark-admonition.js +8 -0
  77. package/dist/mdx-plugins/remark-code-tab.d.ts +30 -0
  78. package/dist/mdx-plugins/remark-code-tab.js +8 -0
  79. package/dist/mdx-plugins/remark-directive-admonition.d.ts +27 -0
  80. package/dist/mdx-plugins/remark-directive-admonition.js +7 -0
  81. package/dist/mdx-plugins/remark-gfm.d.ts +1 -0
  82. package/dist/mdx-plugins/remark-gfm.js +7 -0
  83. package/dist/{remark-heading-BPCoYwjn.d.ts → mdx-plugins/remark-heading.d.ts} +1 -1
  84. package/dist/mdx-plugins/remark-heading.js +8 -0
  85. package/dist/mdx-plugins/remark-image.d.ts +57 -0
  86. package/dist/mdx-plugins/remark-image.js +7 -0
  87. package/dist/mdx-plugins/remark-mdx-files.d.ts +40 -0
  88. package/dist/mdx-plugins/remark-mdx-files.js +7 -0
  89. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -0
  90. package/dist/mdx-plugins/remark-mdx-mermaid.js +7 -0
  91. package/dist/mdx-plugins/remark-npm.d.ts +31 -0
  92. package/dist/mdx-plugins/remark-npm.js +8 -0
  93. package/dist/mdx-plugins/remark-steps.d.ts +23 -0
  94. package/dist/mdx-plugins/remark-steps.js +7 -0
  95. package/dist/mdx-plugins/remark-structure.d.ts +71 -0
  96. package/dist/mdx-plugins/remark-structure.js +12 -0
  97. package/dist/mixedbread-2ZQZ32QK.js +117 -0
  98. package/dist/negotiation/index.d.ts +19 -0
  99. package/dist/negotiation/index.js +11 -0
  100. package/dist/{orama-cloud-USLSOSXS.js → orama-cloud-UZAPMPFV.js} +36 -27
  101. package/dist/page-tree/index.d.ts +33 -0
  102. package/dist/page-tree/index.js +17 -0
  103. package/dist/search/algolia.d.ts +9 -7
  104. package/dist/search/algolia.js +31 -17
  105. package/dist/search/client.d.ts +89 -18
  106. package/dist/search/client.js +72 -50
  107. package/dist/search/index.d.ts +26 -0
  108. package/dist/search/index.js +7 -0
  109. package/dist/search/orama-cloud.d.ts +8 -5
  110. package/dist/search/orama-cloud.js +18 -10
  111. package/dist/search/server.d.ts +33 -25
  112. package/dist/search/server.js +109 -47
  113. package/dist/source/client/index.d.ts +16 -0
  114. package/dist/source/client/index.js +41 -0
  115. package/dist/source/index.d.ts +33 -254
  116. package/dist/source/index.js +662 -429
  117. package/dist/source/plugins/lucide-icons.d.ts +14 -0
  118. package/dist/source/plugins/lucide-icons.js +23 -0
  119. package/dist/source/schema.d.ts +26 -0
  120. package/dist/source/schema.js +25 -0
  121. package/dist/static-A2YJ5TXV.js +62 -0
  122. package/dist/toc.d.ts +14 -11
  123. package/dist/toc.js +99 -77
  124. package/dist/util-bZU2QeJ2.d.ts +6 -0
  125. package/dist/utils/use-effect-event.d.ts +4 -3
  126. package/dist/utils/use-effect-event.js +9 -6
  127. package/dist/utils/use-media-query.d.ts +3 -0
  128. package/dist/utils/use-media-query.js +23 -0
  129. package/dist/utils/use-on-change.js +2 -2
  130. package/package.json +107 -40
  131. package/dist/algolia-NTWLS6J3.js +0 -49
  132. package/dist/chunk-FVY6EZ3N.js +0 -94
  133. package/dist/chunk-KAOEMCTI.js +0 -17
  134. package/dist/chunk-MLKGABMK.js +0 -9
  135. package/dist/chunk-XMCPKVJQ.js +0 -34
  136. package/dist/config-inq6kP6y.d.ts +0 -26
  137. package/dist/fetch-W5EHIBOE.js +0 -21
  138. package/dist/page-tree-BG3wP0gU.d.ts +0 -57
  139. package/dist/remark-structure-FIjTA11P.d.ts +0 -48
  140. package/dist/server/index.d.ts +0 -117
  141. package/dist/server/index.js +0 -202
  142. package/dist/sidebar.d.ts +0 -33
  143. package/dist/sidebar.js +0 -89
  144. package/dist/static-VESU2S64.js +0 -61
  145. package/dist/types-Ch8gnVgO.d.ts +0 -8
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The core library for Fumadocs.
4
4
 
5
- 📘 Learn More: [Documentation](https://fumadocs.vercel.app)
5
+ 📘 Learn More: [Documentation](https://fumadocs.dev)
@@ -0,0 +1,58 @@
1
+ import {
2
+ createContentHighlighter
3
+ } from "./chunk-OTD7MV33.js";
4
+ import "./chunk-U67V476Y.js";
5
+
6
+ // src/search/client/algolia.ts
7
+ function groupResults(hits) {
8
+ const grouped = [];
9
+ const scannedUrls = /* @__PURE__ */ new Set();
10
+ for (const hit of hits) {
11
+ if (!scannedUrls.has(hit.url)) {
12
+ scannedUrls.add(hit.url);
13
+ grouped.push({
14
+ id: hit.url,
15
+ type: "page",
16
+ breadcrumbs: hit.breadcrumbs,
17
+ url: hit.url,
18
+ content: hit.title
19
+ });
20
+ }
21
+ grouped.push({
22
+ id: hit.objectID,
23
+ type: hit.content === hit.section ? "heading" : "text",
24
+ url: hit.section_id ? `${hit.url}#${hit.section_id}` : hit.url,
25
+ content: hit.content
26
+ });
27
+ }
28
+ return grouped;
29
+ }
30
+ async function searchDocs(query, { indexName, onSearch, client, locale, tag }) {
31
+ if (query.trim().length === 0) return [];
32
+ const result = onSearch ? await onSearch(query, tag, locale) : await client.searchForHits({
33
+ requests: [
34
+ {
35
+ type: "default",
36
+ indexName,
37
+ query,
38
+ distinct: 5,
39
+ hitsPerPage: 10,
40
+ filters: tag ? `tag:${tag}` : void 0
41
+ }
42
+ ]
43
+ });
44
+ const highlighter = createContentHighlighter(query);
45
+ return groupResults(result.results[0].hits).flatMap((hit) => {
46
+ if (hit.type === "page") {
47
+ return {
48
+ ...hit,
49
+ contentWithHighlights: hit.contentWithHighlights ?? highlighter.highlight(hit.content)
50
+ };
51
+ }
52
+ return [];
53
+ });
54
+ }
55
+ export {
56
+ groupResults,
57
+ searchDocs
58
+ };
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { R as Root, N as Node } from './page-tree-BG3wP0gU.js';
2
+ import { R as Root, N as Node } from './definitions-pJ7PybYY.js';
3
3
 
4
4
  interface BreadcrumbItem {
5
5
  name: ReactNode;
@@ -7,18 +7,20 @@ interface BreadcrumbItem {
7
7
  }
8
8
  interface BreadcrumbOptions {
9
9
  /**
10
- * Include the root itself in the breadcrumb items array.
11
- * Specify the url by passing an object instead
10
+ * Include the root folders in the breadcrumb items array.
12
11
  *
13
12
  * @defaultValue false
14
13
  */
15
14
  includeRoot?: boolean | {
15
+ /**
16
+ * Specify the url of root
17
+ */
16
18
  url: string;
17
19
  };
18
20
  /**
19
21
  * Include the page itself in the breadcrumb items array
20
22
  *
21
- * @defaultValue true
23
+ * @defaultValue false
22
24
  */
23
25
  includePage?: boolean;
24
26
  /**
@@ -37,7 +39,7 @@ declare function getBreadcrumbItemsFromPath(tree: Root, path: Node[], options: B
37
39
  * - When the page doesn't exist, return null
38
40
  *
39
41
  * @returns The path to the target node from root
40
- * @internal
42
+ * @internal Don't use this on your own
41
43
  */
42
44
  declare function searchPath(nodes: Node[], url: string): Node[] | null;
43
45
 
@@ -1,4 +1,10 @@
1
- import "./chunk-MLKGABMK.js";
1
+ import {
2
+ normalizeUrl
3
+ } from "./chunk-PFNP6PEB.js";
4
+ import {
5
+ findPath
6
+ } from "./chunk-L4JKQWCM.js";
7
+ import "./chunk-U67V476Y.js";
2
8
 
3
9
  // src/breadcrumb.tsx
4
10
  import { useMemo } from "react";
@@ -16,33 +22,42 @@ function getBreadcrumbItems(url, tree, options = {}) {
16
22
  );
17
23
  }
18
24
  function getBreadcrumbItemsFromPath(tree, path, options) {
19
- const { includePage = true, includeSeparator = false, includeRoot } = options;
25
+ const {
26
+ includePage = false,
27
+ includeSeparator = false,
28
+ includeRoot = false
29
+ } = options;
20
30
  let items = [];
21
- path.forEach((item, i) => {
22
- if (item.type === "separator" && includeSeparator) {
23
- items.push({
24
- name: item.name
25
- });
31
+ for (let i = 0; i < path.length; i++) {
32
+ const item = path[i];
33
+ switch (item.type) {
34
+ case "page":
35
+ if (includePage)
36
+ items.push({
37
+ name: item.name,
38
+ url: item.url
39
+ });
40
+ break;
41
+ case "folder":
42
+ if (item.root && !includeRoot) {
43
+ items = [];
44
+ break;
45
+ }
46
+ if (i === path.length - 1 || item.index !== path[i + 1]) {
47
+ items.push({
48
+ name: item.name,
49
+ url: item.index?.url
50
+ });
51
+ }
52
+ break;
53
+ case "separator":
54
+ if (item.name && includeSeparator)
55
+ items.push({
56
+ name: item.name
57
+ });
58
+ break;
26
59
  }
27
- if (item.type === "folder") {
28
- const next = path.at(i + 1);
29
- if (next && item.index === next) return;
30
- if (item.root) {
31
- items = [];
32
- return;
33
- }
34
- items.push({
35
- name: item.name,
36
- url: item.index?.url
37
- });
38
- }
39
- if (item.type === "page" && includePage) {
40
- items.push({
41
- name: item.name,
42
- url: item.url
43
- });
44
- }
45
- });
60
+ }
46
61
  if (includeRoot) {
47
62
  items.unshift({
48
63
  name: tree.name,
@@ -52,32 +67,11 @@ function getBreadcrumbItemsFromPath(tree, path, options) {
52
67
  return items;
53
68
  }
54
69
  function searchPath(nodes, url) {
55
- if (url.endsWith("/")) url = url.slice(0, -1);
56
- let separator;
57
- for (const node of nodes) {
58
- if (node.type === "separator") separator = node;
59
- if (node.type === "folder") {
60
- if (node.index?.url === url) {
61
- const items2 = [];
62
- if (separator) items2.push(separator);
63
- items2.push(node, node.index);
64
- return items2;
65
- }
66
- const items = searchPath(node.children, url);
67
- if (items) {
68
- items.unshift(node);
69
- if (separator) items.unshift(separator);
70
- return items;
71
- }
72
- }
73
- if (node.type === "page" && node.url === url) {
74
- const items = [];
75
- if (separator) items.push(separator);
76
- items.push(node);
77
- return items;
78
- }
79
- }
80
- return null;
70
+ const normalizedUrl = normalizeUrl(url);
71
+ return findPath(
72
+ nodes,
73
+ (node) => node.type === "page" && node.url === normalizedUrl
74
+ );
81
75
  }
82
76
  export {
83
77
  getBreadcrumbItems,
@@ -0,0 +1,220 @@
1
+ // src/mdx-plugins/remark-image.ts
2
+ import * as path from "path";
3
+ import { visit } from "unist-util-visit";
4
+ import { fileURLToPath } from "url";
5
+ var VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
6
+ var EXTERNAL_URL_REGEX = /^https?:\/\//;
7
+ function remarkImage({
8
+ placeholder = "blur",
9
+ external = true,
10
+ useImport = true,
11
+ onError = "error",
12
+ publicDir = path.join(process.cwd(), "public")
13
+ } = {}) {
14
+ return async (tree, file) => {
15
+ const importsToInject = [];
16
+ const promises = [];
17
+ async function onImage(src, node) {
18
+ const attributes = [
19
+ {
20
+ type: "mdxJsxAttribute",
21
+ name: "alt",
22
+ value: node.alt ?? "image"
23
+ }
24
+ ];
25
+ if (node.title) {
26
+ attributes.push({
27
+ type: "mdxJsxAttribute",
28
+ name: "title",
29
+ value: node.title
30
+ });
31
+ }
32
+ if (src.type === "file" && useImport) {
33
+ const variableName = `__img${importsToInject.length}`;
34
+ const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));
35
+ if (!file.dirname) {
36
+ throw new Error(
37
+ "When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler."
38
+ );
39
+ }
40
+ importsToInject.push({
41
+ variableName,
42
+ importPath: getImportPath(src.file, file.dirname)
43
+ });
44
+ attributes.push({
45
+ type: "mdxJsxAttribute",
46
+ name: "src",
47
+ value: {
48
+ type: "mdxJsxAttributeValueExpression",
49
+ value: variableName,
50
+ data: {
51
+ estree: {
52
+ body: [
53
+ {
54
+ type: "ExpressionStatement",
55
+ expression: { type: "Identifier", name: variableName }
56
+ }
57
+ ],
58
+ type: "Program",
59
+ sourceType: "script"
60
+ }
61
+ }
62
+ }
63
+ });
64
+ const out = {
65
+ children: [],
66
+ type: "mdxJsxFlowElement",
67
+ name: "img",
68
+ attributes
69
+ };
70
+ if (hasBlur) {
71
+ out.attributes.push({
72
+ type: "mdxJsxAttribute",
73
+ name: "placeholder",
74
+ value: "blur"
75
+ });
76
+ }
77
+ return out;
78
+ }
79
+ const size = await getImageSize(src, external).catch((e) => {
80
+ throw new Error(
81
+ `[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,
82
+ {
83
+ cause: e
84
+ }
85
+ );
86
+ });
87
+ if (!size) return;
88
+ attributes.push(
89
+ {
90
+ type: "mdxJsxAttribute",
91
+ name: "src",
92
+ // `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it
93
+ value: src.type === "url" ? src.url.toString() : node.url
94
+ },
95
+ {
96
+ type: "mdxJsxAttribute",
97
+ name: "width",
98
+ value: size.width.toString()
99
+ },
100
+ {
101
+ type: "mdxJsxAttribute",
102
+ name: "height",
103
+ value: size.height.toString()
104
+ }
105
+ );
106
+ return {
107
+ type: "mdxJsxFlowElement",
108
+ name: "img",
109
+ attributes,
110
+ children: []
111
+ };
112
+ }
113
+ visit(tree, "image", (node) => {
114
+ const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);
115
+ if (!src) return;
116
+ const task = onImage(src, node).catch((e) => {
117
+ if (onError === "ignore" || node.url.endsWith(".svg")) {
118
+ return;
119
+ }
120
+ if (onError === "hide") {
121
+ return {
122
+ type: "mdxJsxFlowElement",
123
+ name: null,
124
+ attributes: [],
125
+ children: []
126
+ };
127
+ }
128
+ if (onError === "error") throw e;
129
+ onError(e);
130
+ }).then((res) => {
131
+ if (res) Object.assign(node, res);
132
+ });
133
+ promises.push(task);
134
+ });
135
+ await Promise.all(promises);
136
+ if (importsToInject.length === 0) return;
137
+ const imports = importsToInject.map(
138
+ ({ variableName, importPath }) => ({
139
+ type: "mdxjsEsm",
140
+ data: {
141
+ estree: {
142
+ body: [
143
+ {
144
+ type: "ImportDeclaration",
145
+ source: { type: "Literal", value: importPath },
146
+ specifiers: [
147
+ {
148
+ type: "ImportDefaultSpecifier",
149
+ local: { type: "Identifier", name: variableName }
150
+ }
151
+ ]
152
+ }
153
+ ]
154
+ }
155
+ }
156
+ })
157
+ );
158
+ tree.children.unshift(...imports);
159
+ };
160
+ }
161
+ function getImportPath(file, dir) {
162
+ const relative2 = path.relative(dir, file).replaceAll(path.sep, "/");
163
+ return relative2.startsWith("../") ? relative2 : `./${relative2}`;
164
+ }
165
+ function parseSrc(src, publicDir, dir) {
166
+ if (src.startsWith("file:///"))
167
+ return { type: "file", file: fileURLToPath(src) };
168
+ if (EXTERNAL_URL_REGEX.test(src)) {
169
+ return {
170
+ type: "url",
171
+ url: new URL(src)
172
+ };
173
+ }
174
+ if (src.startsWith("/")) {
175
+ if (EXTERNAL_URL_REGEX.test(publicDir)) {
176
+ const url = new URL(publicDir);
177
+ const segs = [...url.pathname.split("/"), ...src.split("/")].filter(
178
+ (v) => v.length > 0
179
+ );
180
+ url.pathname = `/${segs.join("/")}`;
181
+ return { type: "url", url };
182
+ }
183
+ return {
184
+ type: "file",
185
+ file: path.join(publicDir, src)
186
+ };
187
+ }
188
+ if (!dir) {
189
+ console.warn(
190
+ `[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`
191
+ );
192
+ return;
193
+ }
194
+ return {
195
+ type: "file",
196
+ file: path.join(dir, src)
197
+ };
198
+ }
199
+ async function getImageSize(src, onExternal) {
200
+ if (src.type === "file") {
201
+ const { imageSizeFromFile } = await import("image-size/fromFile");
202
+ return imageSizeFromFile(src.file);
203
+ }
204
+ if (onExternal === false) return;
205
+ const { timeout } = typeof onExternal === "object" ? onExternal : {};
206
+ const res = await fetch(src.url, {
207
+ signal: typeof timeout === "number" ? AbortSignal.timeout(timeout) : void 0
208
+ });
209
+ if (!res.ok) {
210
+ throw new Error(
211
+ `[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`
212
+ );
213
+ }
214
+ const { imageSize } = await import("image-size");
215
+ return imageSize(new Uint8Array(await res.arrayBuffer()));
216
+ }
217
+
218
+ export {
219
+ remarkImage
220
+ };
@@ -0,0 +1,78 @@
1
+ // src/mdx-plugins/remark-mdx-files.ts
2
+ import { visit } from "unist-util-visit";
3
+ function parseFileTree(code) {
4
+ const lines = code.split(/\r?\n/);
5
+ const stack = /* @__PURE__ */ new Map();
6
+ for (const line of lines) {
7
+ let depth = 0;
8
+ let name = line;
9
+ let match;
10
+ while (match = /(?:├──|│|└──)\s*/.exec(name)) {
11
+ name = name.slice(match[0].length);
12
+ depth++;
13
+ }
14
+ if (!name) continue;
15
+ const node = name.endsWith("/") ? { type: "folder", name, children: [], depth } : { type: "file", name, depth };
16
+ let parent;
17
+ for (let i = depth - 1; i >= 0 && !parent; i--) {
18
+ parent = stack.get(i);
19
+ }
20
+ stack.set(depth, node);
21
+ if (!parent) continue;
22
+ if (parent.type === "file") {
23
+ Object.assign(parent, {
24
+ type: "folder",
25
+ children: []
26
+ });
27
+ }
28
+ parent.children.push(node);
29
+ }
30
+ return stack.get(0);
31
+ }
32
+ function defaultToMDX(node, depth = 0) {
33
+ if (depth === 0) {
34
+ return {
35
+ type: "mdxJsxFlowElement",
36
+ name: "Files",
37
+ attributes: [],
38
+ children: [defaultToMDX(node, depth + 1)]
39
+ };
40
+ }
41
+ const attributes = [
42
+ { type: "mdxJsxAttribute", name: "name", value: node.name }
43
+ ];
44
+ if (node.type === "file") {
45
+ return {
46
+ type: "mdxJsxFlowElement",
47
+ attributes,
48
+ children: [],
49
+ name: "File"
50
+ };
51
+ }
52
+ attributes.push({
53
+ type: "mdxJsxAttribute",
54
+ name: "defaultOpen",
55
+ value: null
56
+ });
57
+ return {
58
+ type: "mdxJsxFlowElement",
59
+ attributes,
60
+ name: "Folder",
61
+ children: node.children.map((item) => defaultToMDX(item, depth + 1))
62
+ };
63
+ }
64
+ function remarkMdxFiles(options = {}) {
65
+ const { lang = "files", toMdx = defaultToMDX } = options;
66
+ return (tree) => {
67
+ visit(tree, "code", (node) => {
68
+ if (node.lang !== lang || !node.value) return;
69
+ const fileTree = parseFileTree(node.value);
70
+ if (!fileTree) return;
71
+ Object.assign(node, toMdx(fileTree));
72
+ });
73
+ };
74
+ }
75
+
76
+ export {
77
+ remarkMdxFiles
78
+ };
@@ -0,0 +1,74 @@
1
+ // src/mdx-plugins/remark-directive-admonition.ts
2
+ import { visit } from "unist-util-visit";
3
+ function remarkDirectiveAdmonition({
4
+ tags: {
5
+ CalloutContainer = "CalloutContainer",
6
+ CalloutTitle = "CalloutTitle",
7
+ CalloutDescription = "CalloutDescription"
8
+ } = {},
9
+ types = {
10
+ note: "info",
11
+ tip: "info",
12
+ info: "info",
13
+ warn: "warning",
14
+ warning: "warning",
15
+ danger: "error",
16
+ success: "success"
17
+ }
18
+ } = {}) {
19
+ return (tree) => {
20
+ visit(tree, "containerDirective", (node) => {
21
+ if (!(node.name in types)) return;
22
+ const attributes = [
23
+ {
24
+ type: "mdxJsxAttribute",
25
+ name: "type",
26
+ value: types[node.name]
27
+ }
28
+ ];
29
+ for (const [k, v] of Object.entries(node.attributes ?? {})) {
30
+ attributes.push({
31
+ type: "mdxJsxAttribute",
32
+ name: k,
33
+ value: v
34
+ });
35
+ }
36
+ const titleNodes = [];
37
+ const descriptionNodes = [];
38
+ for (const item of node.children) {
39
+ if (item.type === "paragraph" && item.data?.directiveLabel) {
40
+ titleNodes.push(...item.children);
41
+ } else {
42
+ descriptionNodes.push(item);
43
+ }
44
+ }
45
+ const children = [];
46
+ if (titleNodes.length > 0) {
47
+ children.push({
48
+ type: "mdxJsxFlowElement",
49
+ name: CalloutTitle,
50
+ attributes: [],
51
+ children: titleNodes
52
+ });
53
+ }
54
+ if (descriptionNodes.length > 0) {
55
+ children.push({
56
+ type: "mdxJsxFlowElement",
57
+ name: CalloutDescription,
58
+ attributes: [],
59
+ children: descriptionNodes
60
+ });
61
+ }
62
+ Object.assign(node, {
63
+ type: "mdxJsxFlowElement",
64
+ attributes,
65
+ name: CalloutContainer,
66
+ children
67
+ });
68
+ });
69
+ };
70
+ }
71
+
72
+ export {
73
+ remarkDirectiveAdmonition
74
+ };