@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,216 @@
1
+ import {
2
+ fumaMatter
3
+ } from "./chunk-VWJKRQZR.js";
4
+
5
+ // src/loaders/mdx/remark-include.ts
6
+ import { unified } from "unified";
7
+ import { visit as visit2 } from "unist-util-visit";
8
+ import * as path from "path";
9
+ import * as fs from "fs/promises";
10
+ import { remarkHeading } from "@hanzo/docs-core/mdx-plugins";
11
+ import { VFile } from "vfile";
12
+
13
+ // src/loaders/mdx/remark-unravel.ts
14
+ import { visit } from "unist-util-visit";
15
+ function remarkMarkAndUnravel() {
16
+ return (tree) => {
17
+ visit(tree, function(node, index, parent) {
18
+ let offset = -1;
19
+ let all = true;
20
+ let oneOrMore = false;
21
+ if (parent && typeof index === "number" && node.type === "paragraph") {
22
+ const children = node.children;
23
+ while (++offset < children.length) {
24
+ const child = children[offset];
25
+ if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
26
+ oneOrMore = true;
27
+ } else if (child.type === "text" && child.value.trim().length === 0) {
28
+ } else {
29
+ all = false;
30
+ break;
31
+ }
32
+ }
33
+ if (all && oneOrMore) {
34
+ offset = -1;
35
+ const newChildren = [];
36
+ while (++offset < children.length) {
37
+ const child = children[offset];
38
+ if (child.type === "mdxJsxTextElement") {
39
+ child.type = "mdxJsxFlowElement";
40
+ }
41
+ if (child.type === "mdxTextExpression") {
42
+ child.type = "mdxFlowExpression";
43
+ }
44
+ if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
45
+ } else {
46
+ newChildren.push(child);
47
+ }
48
+ }
49
+ parent.children.splice(index, 1, ...newChildren);
50
+ return index;
51
+ }
52
+ }
53
+ });
54
+ };
55
+ }
56
+
57
+ // src/loaders/mdx/mdast-utils.ts
58
+ function flattenNode(node) {
59
+ if ("children" in node)
60
+ return node.children.map((child) => flattenNode(child)).join("");
61
+ if ("value" in node) return node.value;
62
+ return "";
63
+ }
64
+
65
+ // src/loaders/mdx/remark-include.ts
66
+ var ElementLikeTypes = [
67
+ "mdxJsxFlowElement",
68
+ "mdxJsxTextElement",
69
+ "containerDirective",
70
+ "textDirective",
71
+ "leafDirective"
72
+ ];
73
+ function isElementLike(node) {
74
+ return ElementLikeTypes.includes(node.type);
75
+ }
76
+ function parseElementAttributes(element) {
77
+ if (Array.isArray(element.attributes)) {
78
+ const attributes = {};
79
+ for (const attr of element.attributes) {
80
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
81
+ attributes[attr.name] = attr.value;
82
+ }
83
+ }
84
+ return attributes;
85
+ }
86
+ return element.attributes ?? {};
87
+ }
88
+ function parseSpecifier(specifier) {
89
+ const idx = specifier.lastIndexOf("#");
90
+ if (idx === -1) return { file: specifier };
91
+ return {
92
+ file: specifier.slice(0, idx),
93
+ section: specifier.slice(idx + 1)
94
+ };
95
+ }
96
+ function extractSection(root, section) {
97
+ let nodes;
98
+ let capturingHeadingContent = false;
99
+ visit2(root, (node) => {
100
+ if (node.type === "heading") {
101
+ if (capturingHeadingContent) {
102
+ return false;
103
+ }
104
+ if (node.data?.hProperties?.id === section) {
105
+ capturingHeadingContent = true;
106
+ nodes = [node];
107
+ return "skip";
108
+ }
109
+ return;
110
+ }
111
+ if (capturingHeadingContent) {
112
+ nodes?.push(node);
113
+ return "skip";
114
+ }
115
+ if (isElementLike(node) && node.name === "section") {
116
+ const attributes = parseElementAttributes(node);
117
+ if (attributes.id === section) {
118
+ nodes = node.children;
119
+ return false;
120
+ }
121
+ }
122
+ });
123
+ if (nodes)
124
+ return {
125
+ type: "root",
126
+ children: nodes
127
+ };
128
+ }
129
+ function remarkInclude() {
130
+ const TagName = "include";
131
+ const embedContent = async (targetPath, heading, params, parent) => {
132
+ const { _getProcessor = () => this, _compiler } = parent.data;
133
+ let content;
134
+ try {
135
+ content = (await fs.readFile(targetPath)).toString();
136
+ } catch (e) {
137
+ throw new Error(
138
+ `failed to read file ${targetPath}
139
+ ${e instanceof Error ? e.message : String(e)}`,
140
+ { cause: e }
141
+ );
142
+ }
143
+ const ext = path.extname(targetPath);
144
+ _compiler?.addDependency(targetPath);
145
+ if (params.lang || ext !== ".md" && ext !== ".mdx") {
146
+ const lang = params.lang ?? ext.slice(1);
147
+ return {
148
+ type: "code",
149
+ lang,
150
+ meta: params.meta,
151
+ value: content,
152
+ data: {}
153
+ };
154
+ }
155
+ const parser = _getProcessor(ext === ".mdx" ? "mdx" : "md");
156
+ const parsed = fumaMatter(content);
157
+ const targetFile = new VFile({
158
+ path: targetPath,
159
+ value: parsed.content,
160
+ data: {
161
+ ...parent.data,
162
+ frontmatter: parsed.data
163
+ }
164
+ });
165
+ let mdast = parser.parse(targetFile);
166
+ const baseProcessor = unified().use(remarkMarkAndUnravel);
167
+ if (heading) {
168
+ const extracted = extractSection(
169
+ await baseProcessor.use(remarkHeading).run(mdast),
170
+ heading
171
+ );
172
+ if (!extracted)
173
+ throw new Error(
174
+ `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
175
+ );
176
+ mdast = extracted;
177
+ } else {
178
+ mdast = await baseProcessor.run(mdast);
179
+ }
180
+ await update(mdast, targetFile);
181
+ return mdast;
182
+ };
183
+ async function update(tree, file) {
184
+ const queue = [];
185
+ visit2(tree, ElementLikeTypes, (_node, _, parent) => {
186
+ const node = _node;
187
+ if (node.name !== TagName) return;
188
+ const specifier = flattenNode(node);
189
+ if (specifier.length === 0) return "skip";
190
+ const attributes = parseElementAttributes(node);
191
+ const { file: relativePath, section } = parseSpecifier(specifier);
192
+ const targetPath = path.resolve(
193
+ "cwd" in attributes ? file.cwd : file.dirname,
194
+ relativePath
195
+ );
196
+ queue.push(
197
+ embedContent(targetPath, section, attributes, file).then((replace) => {
198
+ Object.assign(
199
+ parent && parent.type === "paragraph" ? parent : node,
200
+ replace
201
+ );
202
+ })
203
+ );
204
+ return "skip";
205
+ });
206
+ await Promise.all(queue);
207
+ }
208
+ return async (tree, file) => {
209
+ await update(tree, file);
210
+ };
211
+ }
212
+
213
+ export {
214
+ flattenNode,
215
+ remarkInclude
216
+ };
@@ -0,0 +1,89 @@
1
+ import {
2
+ metaLoaderGlob
3
+ } from "./chunk-4JSFLXXT.js";
4
+
5
+ // src/loaders/meta.ts
6
+ import { dump, load } from "js-yaml";
7
+ import { z } from "zod";
8
+ var querySchema = z.object({
9
+ collection: z.string().optional(),
10
+ workspace: z.string().optional()
11
+ }).loose();
12
+ function createMetaLoader({ getCore }, resolve = {}) {
13
+ const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
14
+ function parse(filePath, source) {
15
+ try {
16
+ if (filePath.endsWith(".json")) return JSON.parse(source);
17
+ if (filePath.endsWith(".yaml")) return load(source);
18
+ } catch (e) {
19
+ throw new Error(`invalid data in ${filePath}`, { cause: e });
20
+ }
21
+ throw new Error("Unknown file type " + filePath);
22
+ }
23
+ function onMeta(source, { filePath, query }) {
24
+ const parsed = querySchema.safeParse(query);
25
+ if (!parsed.success || !parsed.data.collection) return null;
26
+ const { collection: collectionName, workspace } = parsed.data;
27
+ return async () => {
28
+ let core = await getCore();
29
+ if (workspace) {
30
+ core = core.getWorkspaces().get(workspace) ?? core;
31
+ }
32
+ const collection = core.getCollection(collectionName);
33
+ let metaCollection;
34
+ switch (collection?.type) {
35
+ case "meta":
36
+ metaCollection = collection;
37
+ break;
38
+ case "docs":
39
+ metaCollection = collection.meta;
40
+ break;
41
+ }
42
+ const data = parse(filePath, source);
43
+ if (!metaCollection) return data;
44
+ return core.transformMeta(
45
+ {
46
+ collection: metaCollection,
47
+ filePath,
48
+ source
49
+ },
50
+ data
51
+ );
52
+ };
53
+ }
54
+ return {
55
+ test: metaLoaderGlob,
56
+ async load(input) {
57
+ const result = onMeta(await input.getSource(), input);
58
+ if (result === null) return null;
59
+ const data = await result();
60
+ if (input.filePath.endsWith(".json")) {
61
+ return {
62
+ code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
63
+ };
64
+ } else {
65
+ return {
66
+ code: resolveYaml === "yaml" ? dump(data) : `export default ${JSON.stringify(data)}`
67
+ };
68
+ }
69
+ },
70
+ bun: {
71
+ load(source, input) {
72
+ const result = onMeta(source, input);
73
+ if (result === null)
74
+ return {
75
+ loader: "object",
76
+ exports: parse(input.filePath, source)
77
+ };
78
+ return result().then((data) => ({
79
+ loader: "object",
80
+ exports: { default: data }
81
+ }));
82
+ }
83
+ }
84
+ };
85
+ }
86
+
87
+ export {
88
+ createMetaLoader
89
+ };
@@ -0,0 +1,18 @@
1
+ export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs } from '../core-BhWOtait.js';
2
+ import { Processor, Transformer } from 'unified';
3
+ import { Root } from 'mdast';
4
+ export { pageSchema as frontmatterSchema, metaSchema } from '@hanzo/docs-core/source/schema';
5
+ import '@mdx-js/mdx';
6
+ import '@standard-schema/spec';
7
+ import '@hanzo/docs-core/mdx-plugins';
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 'mdx/types';
15
+
16
+ declare function remarkInclude(this: Processor): Transformer<Root, Root>;
17
+
18
+ export { remarkInclude };
@@ -0,0 +1,63 @@
1
+ import {
2
+ remarkInclude
3
+ } from "../chunk-YKRCQ42E.js";
4
+ import {
5
+ applyMdxPreset
6
+ } from "../chunk-U5YPLCO5.js";
7
+ import "../chunk-VWJKRQZR.js";
8
+
9
+ // ../core/dist/source/schema.js
10
+ import { z } from "zod";
11
+ var metaSchema = z.object({
12
+ title: z.string().optional(),
13
+ pages: z.array(z.string()).optional(),
14
+ description: z.string().optional(),
15
+ root: z.boolean().optional(),
16
+ defaultOpen: z.boolean().optional(),
17
+ collapsible: z.boolean().optional(),
18
+ icon: z.string().optional()
19
+ });
20
+ var pageSchema = z.object({
21
+ title: z.string(),
22
+ description: z.string().optional(),
23
+ icon: z.string().optional(),
24
+ full: z.boolean().optional(),
25
+ // Fumadocs OpenAPI generated
26
+ _openapi: z.looseObject({}).optional()
27
+ });
28
+
29
+ // src/config/define.ts
30
+ function defineCollections(options) {
31
+ return options;
32
+ }
33
+ function defineDocs(options) {
34
+ const dir = options.dir ?? "content/docs";
35
+ return {
36
+ type: "docs",
37
+ dir,
38
+ docs: defineCollections({
39
+ type: "doc",
40
+ dir,
41
+ schema: pageSchema,
42
+ ...options?.docs
43
+ }),
44
+ meta: defineCollections({
45
+ type: "meta",
46
+ dir,
47
+ schema: metaSchema,
48
+ ...options?.meta
49
+ })
50
+ };
51
+ }
52
+ function defineConfig(config = {}) {
53
+ return config;
54
+ }
55
+ export {
56
+ applyMdxPreset,
57
+ defineCollections,
58
+ defineConfig,
59
+ defineDocs,
60
+ pageSchema as frontmatterSchema,
61
+ metaSchema,
62
+ remarkInclude
63
+ };