@hanzo/docs-core 16.2.5

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 (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/algolia-IZEDLPHE.js +58 -0
  4. package/dist/breadcrumb.d.ts +46 -0
  5. package/dist/breadcrumb.js +81 -0
  6. package/dist/chunk-5PMI7QDD.js +220 -0
  7. package/dist/chunk-ADBHPKXG.js +78 -0
  8. package/dist/chunk-APKPSBSB.js +74 -0
  9. package/dist/chunk-CH7YHH7V.js +222 -0
  10. package/dist/chunk-EFVXL2PP.js +144 -0
  11. package/dist/chunk-EMWGTXSW.js +19 -0
  12. package/dist/chunk-FAEPKD7U.js +20 -0
  13. package/dist/chunk-FUUVPEA5.js +29 -0
  14. package/dist/chunk-GINBKBVQ.js +12 -0
  15. package/dist/chunk-GLRQBLGN.js +59 -0
  16. package/dist/chunk-JUF4WZ6G.js +117 -0
  17. package/dist/chunk-K4WNLOVQ.js +75 -0
  18. package/dist/chunk-L4JKQWCM.js +131 -0
  19. package/dist/chunk-MA6O2UUE.js +50 -0
  20. package/dist/chunk-ONG4RVCR.js +8 -0
  21. package/dist/chunk-OTD7MV33.js +53 -0
  22. package/dist/chunk-PFNP6PEB.js +11 -0
  23. package/dist/chunk-QJRXMG4S.js +275 -0
  24. package/dist/chunk-SH7BNTG7.js +38 -0
  25. package/dist/chunk-TWIDBWFG.js +84 -0
  26. package/dist/chunk-U67V476Y.js +35 -0
  27. package/dist/chunk-VLSDGCJE.js +47 -0
  28. package/dist/chunk-W6WTLKRA.js +73 -0
  29. package/dist/chunk-X2HFD5QJ.js +275 -0
  30. package/dist/chunk-XJ6ZQNEX.js +91 -0
  31. package/dist/chunk-XN2LKXFZ.js +101 -0
  32. package/dist/chunk-XOFXGHS4.js +93 -0
  33. package/dist/chunk-XZSI7AHE.js +67 -0
  34. package/dist/chunk-YVVDKJ2H.js +34 -0
  35. package/dist/chunk-ZMWYLUDP.js +21 -0
  36. package/dist/content/github.d.ts +40 -0
  37. package/dist/content/github.js +44 -0
  38. package/dist/content/index.d.ts +16 -0
  39. package/dist/content/index.js +30 -0
  40. package/dist/content/mdx/preset-bundler.d.ts +31 -0
  41. package/dist/content/mdx/preset-bundler.js +72 -0
  42. package/dist/content/mdx/preset-runtime.d.ts +31 -0
  43. package/dist/content/mdx/preset-runtime.js +71 -0
  44. package/dist/content/toc.d.ts +21 -0
  45. package/dist/content/toc.js +22 -0
  46. package/dist/definitions-pJ7PybYY.d.ts +60 -0
  47. package/dist/dynamic-link.d.ts +12 -0
  48. package/dist/dynamic-link.js +32 -0
  49. package/dist/fetch-IBTWQCJR.js +22 -0
  50. package/dist/framework/index.d.ts +41 -0
  51. package/dist/framework/index.js +18 -0
  52. package/dist/framework/next.d.ts +12 -0
  53. package/dist/framework/next.js +31 -0
  54. package/dist/framework/react-router.d.ts +12 -0
  55. package/dist/framework/react-router.js +59 -0
  56. package/dist/framework/tanstack.d.ts +15 -0
  57. package/dist/framework/tanstack.js +72 -0
  58. package/dist/framework/waku.d.ts +12 -0
  59. package/dist/framework/waku.js +63 -0
  60. package/dist/highlight/client.d.ts +15 -0
  61. package/dist/highlight/client.js +18 -0
  62. package/dist/highlight/index.d.ts +30 -0
  63. package/dist/highlight/index.js +13 -0
  64. package/dist/i18n/index.d.ts +39 -0
  65. package/dist/i18n/index.js +9 -0
  66. package/dist/i18n/middleware.d.ts +34 -0
  67. package/dist/i18n/middleware.js +76 -0
  68. package/dist/link.d.ts +18 -0
  69. package/dist/link.js +9 -0
  70. package/dist/loader-BvlPPJX0.d.ts +321 -0
  71. package/dist/mdx-plugins/codeblock-utils.d.ts +29 -0
  72. package/dist/mdx-plugins/codeblock-utils.js +9 -0
  73. package/dist/mdx-plugins/index.d.ts +20 -0
  74. package/dist/mdx-plugins/index.js +73 -0
  75. package/dist/mdx-plugins/rehype-code.d.ts +55 -0
  76. package/dist/mdx-plugins/rehype-code.js +15 -0
  77. package/dist/mdx-plugins/rehype-toc.d.ts +14 -0
  78. package/dist/mdx-plugins/rehype-toc.js +7 -0
  79. package/dist/mdx-plugins/remark-admonition.d.ts +20 -0
  80. package/dist/mdx-plugins/remark-admonition.js +8 -0
  81. package/dist/mdx-plugins/remark-code-tab.d.ts +30 -0
  82. package/dist/mdx-plugins/remark-code-tab.js +8 -0
  83. package/dist/mdx-plugins/remark-directive-admonition.d.ts +27 -0
  84. package/dist/mdx-plugins/remark-directive-admonition.js +7 -0
  85. package/dist/mdx-plugins/remark-gfm.d.ts +1 -0
  86. package/dist/mdx-plugins/remark-gfm.js +7 -0
  87. package/dist/mdx-plugins/remark-heading.d.ts +31 -0
  88. package/dist/mdx-plugins/remark-heading.js +8 -0
  89. package/dist/mdx-plugins/remark-image.d.ts +57 -0
  90. package/dist/mdx-plugins/remark-image.js +7 -0
  91. package/dist/mdx-plugins/remark-mdx-files.d.ts +40 -0
  92. package/dist/mdx-plugins/remark-mdx-files.js +7 -0
  93. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -0
  94. package/dist/mdx-plugins/remark-mdx-mermaid.js +7 -0
  95. package/dist/mdx-plugins/remark-npm.d.ts +31 -0
  96. package/dist/mdx-plugins/remark-npm.js +8 -0
  97. package/dist/mdx-plugins/remark-steps.d.ts +23 -0
  98. package/dist/mdx-plugins/remark-steps.js +7 -0
  99. package/dist/mdx-plugins/remark-structure.d.ts +71 -0
  100. package/dist/mdx-plugins/remark-structure.js +12 -0
  101. package/dist/mixedbread-RAHDVXGJ.js +118 -0
  102. package/dist/negotiation/index.d.ts +19 -0
  103. package/dist/negotiation/index.js +11 -0
  104. package/dist/orama-cloud-UZAPMPFV.js +93 -0
  105. package/dist/page-tree/index.d.ts +33 -0
  106. package/dist/page-tree/index.js +17 -0
  107. package/dist/search/algolia.d.ts +69 -0
  108. package/dist/search/algolia.js +71 -0
  109. package/dist/search/client.d.ts +140 -0
  110. package/dist/search/client.js +99 -0
  111. package/dist/search/index.d.ts +26 -0
  112. package/dist/search/index.js +7 -0
  113. package/dist/search/orama-cloud.d.ts +79 -0
  114. package/dist/search/orama-cloud.js +60 -0
  115. package/dist/search/server.d.ts +136 -0
  116. package/dist/search/server.js +400 -0
  117. package/dist/source/client/index.d.ts +16 -0
  118. package/dist/source/client/index.js +41 -0
  119. package/dist/source/index.d.ts +42 -0
  120. package/dist/source/index.js +776 -0
  121. package/dist/source/plugins/lucide-icons.d.ts +14 -0
  122. package/dist/source/plugins/lucide-icons.js +23 -0
  123. package/dist/source/schema.d.ts +26 -0
  124. package/dist/source/schema.js +25 -0
  125. package/dist/static-A2YJ5TXV.js +62 -0
  126. package/dist/toc.d.ts +43 -0
  127. package/dist/toc.js +151 -0
  128. package/dist/util-bZU2QeJ2.d.ts +6 -0
  129. package/dist/utils/use-effect-event.d.ts +9 -0
  130. package/dist/utils/use-effect-event.js +16 -0
  131. package/dist/utils/use-media-query.d.ts +3 -0
  132. package/dist/utils/use-media-query.js +23 -0
  133. package/dist/utils/use-on-change.d.ts +8 -0
  134. package/dist/utils/use-on-change.js +7 -0
  135. package/package.json +222 -0
@@ -0,0 +1,776 @@
1
+ import {
2
+ iconPlugin
3
+ } from "../chunk-FAEPKD7U.js";
4
+ import {
5
+ basename,
6
+ dirname,
7
+ extname,
8
+ joinPath,
9
+ path_exports,
10
+ slash,
11
+ splitPath
12
+ } from "../chunk-XZSI7AHE.js";
13
+ import {
14
+ normalizeUrl
15
+ } from "../chunk-PFNP6PEB.js";
16
+ import {
17
+ visit
18
+ } from "../chunk-L4JKQWCM.js";
19
+ import "../chunk-U67V476Y.js";
20
+
21
+ // src/source/source.ts
22
+ function multiple(sources) {
23
+ const out = { files: [] };
24
+ for (const [type, source2] of Object.entries(sources)) {
25
+ for (const file of source2.files) {
26
+ out.files.push({
27
+ ...file,
28
+ data: {
29
+ ...file.data,
30
+ type
31
+ }
32
+ });
33
+ }
34
+ }
35
+ return out;
36
+ }
37
+ function source(config) {
38
+ return {
39
+ files: [...config.pages, ...config.metas]
40
+ };
41
+ }
42
+ function update(source2) {
43
+ return {
44
+ files(fn) {
45
+ source2.files = fn(source2.files);
46
+ return this;
47
+ },
48
+ page(fn) {
49
+ for (let i = 0; i < source2.files.length; i++) {
50
+ const file = source2.files[i];
51
+ if (file.type === "page") source2.files[i] = fn(file);
52
+ }
53
+ return this;
54
+ },
55
+ meta(fn) {
56
+ for (let i = 0; i < source2.files.length; i++) {
57
+ const file = source2.files[i];
58
+ if (file.type === "meta") source2.files[i] = fn(file);
59
+ }
60
+ return this;
61
+ },
62
+ build() {
63
+ return source2;
64
+ }
65
+ };
66
+ }
67
+
68
+ // src/source/storage/file-system.ts
69
+ var FileSystem = class {
70
+ constructor(inherit) {
71
+ this.files = /* @__PURE__ */ new Map();
72
+ this.folders = /* @__PURE__ */ new Map();
73
+ if (inherit) {
74
+ for (const [k, v] of inherit.folders) {
75
+ this.folders.set(k, v);
76
+ }
77
+ for (const [k, v] of inherit.files) {
78
+ this.files.set(k, v);
79
+ }
80
+ } else {
81
+ this.folders.set("", []);
82
+ }
83
+ }
84
+ read(path) {
85
+ return this.files.get(path);
86
+ }
87
+ /**
88
+ * get the direct children of folder (in virtual file path)
89
+ */
90
+ readDir(path) {
91
+ return this.folders.get(path);
92
+ }
93
+ write(path, file) {
94
+ if (!this.files.has(path)) {
95
+ const dir = dirname(path);
96
+ this.makeDir(dir);
97
+ this.readDir(dir)?.push(path);
98
+ }
99
+ this.files.set(path, file);
100
+ }
101
+ /**
102
+ * Delete files at specified path.
103
+ *
104
+ * @param path - the target path.
105
+ * @param [recursive=false] - if set to `true`, it will also delete directories.
106
+ */
107
+ delete(path, recursive = false) {
108
+ if (this.files.delete(path)) return true;
109
+ if (recursive) {
110
+ const folder = this.folders.get(path);
111
+ if (!folder) return false;
112
+ this.folders.delete(path);
113
+ for (const child of folder) {
114
+ this.delete(child);
115
+ }
116
+ return true;
117
+ }
118
+ return false;
119
+ }
120
+ getFiles() {
121
+ return Array.from(this.files.keys());
122
+ }
123
+ makeDir(path) {
124
+ const segments = splitPath(path);
125
+ for (let i = 0; i < segments.length; i++) {
126
+ const segment = segments.slice(0, i + 1).join("/");
127
+ if (this.folders.has(segment)) continue;
128
+ this.folders.set(segment, []);
129
+ this.folders.get(dirname(segment)).push(segment);
130
+ }
131
+ }
132
+ };
133
+
134
+ // src/source/storage/content.ts
135
+ function isLocaleValid(locale) {
136
+ return locale.length > 0 && !/\d+/.test(locale);
137
+ }
138
+ var parsers = {
139
+ dir(path) {
140
+ const [locale, ...segs] = path.split("/");
141
+ if (locale && segs.length > 0 && isLocaleValid(locale))
142
+ return [segs.join("/"), locale];
143
+ return [path];
144
+ },
145
+ dot(path) {
146
+ const dir = dirname(path);
147
+ const base = basename(path);
148
+ const parts = base.split(".");
149
+ if (parts.length < 3) return [path];
150
+ const [locale] = parts.splice(parts.length - 2, 1);
151
+ if (!isLocaleValid(locale)) return [path];
152
+ return [joinPath(dir, parts.join(".")), locale];
153
+ },
154
+ none(path) {
155
+ return [path];
156
+ }
157
+ };
158
+ function buildContentStorage(loaderConfig, defaultLanguage) {
159
+ const {
160
+ source: source2,
161
+ plugins = [],
162
+ i18n = {
163
+ defaultLanguage,
164
+ parser: "none",
165
+ languages: [defaultLanguage]
166
+ }
167
+ } = loaderConfig;
168
+ const parser = parsers[i18n.parser ?? "dot"];
169
+ const storages = {};
170
+ const normalized = /* @__PURE__ */ new Map();
171
+ for (const inputFile of source2.files) {
172
+ let file;
173
+ if (inputFile.type === "page") {
174
+ file = {
175
+ format: "page",
176
+ path: normalizePath(inputFile.path),
177
+ // will be generated by the slugs plugin if unspecified
178
+ slugs: inputFile.slugs,
179
+ data: inputFile.data,
180
+ absolutePath: inputFile.absolutePath
181
+ };
182
+ } else {
183
+ file = {
184
+ format: "meta",
185
+ path: normalizePath(inputFile.path),
186
+ absolutePath: inputFile.absolutePath,
187
+ data: inputFile.data
188
+ };
189
+ }
190
+ const [pathWithoutLocale, locale = i18n.defaultLanguage] = parser(
191
+ file.path
192
+ );
193
+ const list = normalized.get(locale) ?? [];
194
+ list.push({
195
+ pathWithoutLocale,
196
+ file
197
+ });
198
+ normalized.set(locale, list);
199
+ }
200
+ const fallbackLang = i18n.fallbackLanguage !== null ? i18n.fallbackLanguage ?? i18n.defaultLanguage : null;
201
+ function scan(lang) {
202
+ if (storages[lang]) return;
203
+ let storage;
204
+ if (fallbackLang && fallbackLang !== lang) {
205
+ scan(fallbackLang);
206
+ storage = new FileSystem(storages[fallbackLang]);
207
+ } else {
208
+ storage = new FileSystem();
209
+ }
210
+ for (const { pathWithoutLocale, file } of normalized.get(lang) ?? []) {
211
+ storage.write(pathWithoutLocale, file);
212
+ }
213
+ const context = {
214
+ storage
215
+ };
216
+ for (const plugin of plugins) {
217
+ plugin.transformStorage?.(context);
218
+ }
219
+ storages[lang] = storage;
220
+ }
221
+ for (const lang of i18n.languages) scan(lang);
222
+ return storages;
223
+ }
224
+ function normalizePath(path) {
225
+ const segments = splitPath(slash(path));
226
+ if (segments[0] === "." || segments[0] === "..")
227
+ throw new Error("It must not start with './' or '../'");
228
+ return segments.join("/");
229
+ }
230
+
231
+ // src/source/page-tree/transformer-fallback.ts
232
+ function transformerFallback() {
233
+ const addedFiles = /* @__PURE__ */ new Set();
234
+ return {
235
+ root(root) {
236
+ const isolatedStorage = new FileSystem();
237
+ for (const file of this.storage.getFiles()) {
238
+ if (addedFiles.has(file)) continue;
239
+ const content = this.storage.read(file);
240
+ if (content) isolatedStorage.write(file, content);
241
+ }
242
+ if (isolatedStorage.getFiles().length === 0) return root;
243
+ root.fallback = this.builder.build(isolatedStorage, {
244
+ ...this.options,
245
+ id: `fallback-${root.$id ?? ""}`,
246
+ generateFallback: false
247
+ });
248
+ addedFiles.clear();
249
+ return root;
250
+ },
251
+ file(node, file) {
252
+ if (file) addedFiles.add(file);
253
+ return node;
254
+ },
255
+ folder(node, _dir, metaPath) {
256
+ if (metaPath) addedFiles.add(metaPath);
257
+ return node;
258
+ }
259
+ };
260
+ }
261
+
262
+ // src/source/page-tree/builder.ts
263
+ var group = /^\((?<name>.+)\)$/;
264
+ var link = /^(?<external>external:)?(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
265
+ var separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---|^---$/;
266
+ var rest = "...";
267
+ var restReversed = "z...a";
268
+ var extractPrefix = "...";
269
+ var excludePrefix = "!";
270
+ function createPageTreeBuilder(loaderConfig) {
271
+ const { plugins = [], url, pageTree: defaultOptions = {} } = loaderConfig;
272
+ return {
273
+ build(storage, options = defaultOptions) {
274
+ const key = "";
275
+ return this.buildI18n({ [key]: storage }, options)[key];
276
+ },
277
+ buildI18n(storages, options = defaultOptions) {
278
+ let nextId = 0;
279
+ const out = {};
280
+ const transformers = [];
281
+ if (options.transformers) {
282
+ transformers.push(...options.transformers);
283
+ }
284
+ for (const plugin of plugins) {
285
+ if (plugin.transformPageTree)
286
+ transformers.push(plugin.transformPageTree);
287
+ }
288
+ if (options.generateFallback ?? true) {
289
+ transformers.push(transformerFallback());
290
+ }
291
+ for (const [locale, storage] of Object.entries(storages)) {
292
+ let rootId = locale.length === 0 ? "root" : locale;
293
+ if (options.id) rootId = `${options.id}-${rootId}`;
294
+ out[locale] = createPageTreeBuilderUtils({
295
+ rootId,
296
+ transformers,
297
+ builder: this,
298
+ options,
299
+ getUrl: url,
300
+ locale,
301
+ storage,
302
+ storages,
303
+ generateNodeId() {
304
+ return "_" + nextId++;
305
+ }
306
+ }).root();
307
+ }
308
+ return out;
309
+ }
310
+ };
311
+ }
312
+ function createFlattenPathResolver(storage) {
313
+ const map = /* @__PURE__ */ new Map();
314
+ const files = storage.getFiles();
315
+ for (const file of files) {
316
+ const content = storage.read(file);
317
+ const flattenPath = file.substring(0, file.length - extname(file).length);
318
+ map.set(flattenPath + "." + content.format, file);
319
+ }
320
+ return (name, format) => {
321
+ return map.get(name + "." + format) ?? name;
322
+ };
323
+ }
324
+ function createPageTreeBuilderUtils(ctx) {
325
+ const resolveFlattenPath = createFlattenPathResolver(ctx.storage);
326
+ const visitedPaths = /* @__PURE__ */ new Set();
327
+ function nextNodeId(localId = ctx.generateNodeId()) {
328
+ return `${ctx.rootId}:${localId}`;
329
+ }
330
+ return {
331
+ buildPaths(paths, reversed = false) {
332
+ const items = [];
333
+ const folders = [];
334
+ const sortedPaths = paths.sort(
335
+ (a, b) => a.localeCompare(b) * (reversed ? -1 : 1)
336
+ );
337
+ for (const path of sortedPaths) {
338
+ const fileNode = this.file(path);
339
+ if (fileNode) {
340
+ if (basename(path, extname(path)) === "index")
341
+ items.unshift(fileNode);
342
+ else items.push(fileNode);
343
+ continue;
344
+ }
345
+ const dirNode = this.folder(path, false);
346
+ if (dirNode) folders.push(dirNode);
347
+ }
348
+ items.push(...folders);
349
+ return items;
350
+ },
351
+ resolveFolderItem(folderPath, item) {
352
+ if (item === rest || item === restReversed) return item;
353
+ let match = separator.exec(item);
354
+ if (match?.groups) {
355
+ let node = {
356
+ $id: nextNodeId(),
357
+ type: "separator",
358
+ icon: match.groups.icon,
359
+ name: match.groups.name
360
+ };
361
+ for (const transformer of ctx.transformers) {
362
+ if (!transformer.separator) continue;
363
+ node = transformer.separator.call(ctx, node);
364
+ }
365
+ return [node];
366
+ }
367
+ match = link.exec(item);
368
+ if (match?.groups) {
369
+ const { icon, url, name, external } = match.groups;
370
+ let node = {
371
+ $id: nextNodeId(),
372
+ type: "page",
373
+ icon,
374
+ name,
375
+ url,
376
+ external: external ? true : void 0
377
+ };
378
+ for (const transformer of ctx.transformers) {
379
+ if (!transformer.file) continue;
380
+ node = transformer.file.call(ctx, node);
381
+ }
382
+ return [node];
383
+ }
384
+ const isExcept = item.startsWith(excludePrefix);
385
+ const isExtract = !isExcept && item.startsWith(extractPrefix);
386
+ let filename = item;
387
+ if (isExcept) {
388
+ filename = item.slice(excludePrefix.length);
389
+ } else if (isExtract) {
390
+ filename = item.slice(extractPrefix.length);
391
+ }
392
+ const path = resolveFlattenPath(joinPath(folderPath, filename), "page");
393
+ if (isExcept) {
394
+ visitedPaths.add(path);
395
+ return [];
396
+ }
397
+ const dirNode = this.folder(path, false);
398
+ if (dirNode) {
399
+ return isExtract ? dirNode.children : [dirNode];
400
+ }
401
+ const fileNode = this.file(path);
402
+ return fileNode ? [fileNode] : [];
403
+ },
404
+ folder(folderPath, isGlobalRoot) {
405
+ const { storage, options, transformers } = ctx;
406
+ const files = storage.readDir(folderPath);
407
+ if (!files) return;
408
+ const metaPath = resolveFlattenPath(joinPath(folderPath, "meta"), "meta");
409
+ const indexPath = resolveFlattenPath(
410
+ joinPath(folderPath, "index"),
411
+ "page"
412
+ );
413
+ let meta = storage.read(metaPath);
414
+ if (meta && meta.format !== "meta") meta = void 0;
415
+ const metadata = meta?.data ?? {};
416
+ const { root = isGlobalRoot, pages } = metadata;
417
+ let index;
418
+ let children;
419
+ if (pages) {
420
+ const resolved = pages.flatMap((item) => this.resolveFolderItem(folderPath, item));
421
+ if (!root && !visitedPaths.has(indexPath)) {
422
+ index = this.file(indexPath);
423
+ }
424
+ for (let i = 0; i < resolved.length; i++) {
425
+ const item = resolved[i];
426
+ if (item !== rest && item !== restReversed) continue;
427
+ const items = this.buildPaths(
428
+ files.filter((file) => !visitedPaths.has(file)),
429
+ item === restReversed
430
+ );
431
+ resolved.splice(i, 1, ...items);
432
+ break;
433
+ }
434
+ children = resolved;
435
+ } else {
436
+ if (!root && !visitedPaths.has(indexPath)) {
437
+ index = this.file(indexPath);
438
+ }
439
+ children = this.buildPaths(
440
+ files.filter((file) => !visitedPaths.has(file))
441
+ );
442
+ }
443
+ let node = {
444
+ type: "folder",
445
+ name: metadata.title ?? index?.name ?? (() => {
446
+ const folderName = basename(folderPath);
447
+ return pathToName(group.exec(folderName)?.[1] ?? folderName);
448
+ })(),
449
+ icon: metadata.icon,
450
+ root: metadata.root,
451
+ defaultOpen: metadata.defaultOpen,
452
+ description: metadata.description,
453
+ collapsible: metadata.collapsible,
454
+ index,
455
+ children,
456
+ $id: nextNodeId(folderPath),
457
+ $ref: !options.noRef && meta ? {
458
+ metaFile: metaPath
459
+ } : void 0
460
+ };
461
+ visitedPaths.add(folderPath);
462
+ for (const transformer of transformers) {
463
+ if (!transformer.folder) continue;
464
+ node = transformer.folder.call(ctx, node, folderPath, metaPath);
465
+ }
466
+ return node;
467
+ },
468
+ file(path) {
469
+ const { options, getUrl, storage, locale, transformers } = ctx;
470
+ const page = storage.read(path);
471
+ if (page?.format !== "page") return;
472
+ const { title, description, icon } = page.data;
473
+ let item = {
474
+ $id: nextNodeId(path),
475
+ type: "page",
476
+ name: title ?? pathToName(basename(path, extname(path))),
477
+ description,
478
+ icon,
479
+ url: getUrl(page.slugs, locale),
480
+ $ref: !options.noRef ? {
481
+ file: path
482
+ } : void 0
483
+ };
484
+ visitedPaths.add(path);
485
+ for (const transformer of transformers) {
486
+ if (!transformer.file) continue;
487
+ item = transformer.file.call(ctx, item, path);
488
+ }
489
+ return item;
490
+ },
491
+ root() {
492
+ const folder = this.folder("", true);
493
+ let root = {
494
+ $id: ctx.rootId,
495
+ name: folder.name || "Docs",
496
+ children: folder.children
497
+ };
498
+ for (const transformer of ctx.transformers) {
499
+ if (!transformer.root) continue;
500
+ root = transformer.root.call(ctx, root);
501
+ }
502
+ return root;
503
+ }
504
+ };
505
+ }
506
+ function pathToName(name) {
507
+ const result = [];
508
+ for (const c of name) {
509
+ if (result.length === 0) result.push(c.toLocaleUpperCase());
510
+ else if (c === "-") result.push(" ");
511
+ else result.push(c);
512
+ }
513
+ return result.join("");
514
+ }
515
+
516
+ // src/source/plugins/index.ts
517
+ var priorityMap = {
518
+ pre: 1,
519
+ default: 0,
520
+ post: -1
521
+ };
522
+ function buildPlugins(plugins, sort = true) {
523
+ const flatten = [];
524
+ for (const plugin of plugins) {
525
+ if (Array.isArray(plugin)) flatten.push(...buildPlugins(plugin, false));
526
+ else if (plugin) flatten.push(plugin);
527
+ }
528
+ if (sort)
529
+ return flatten.sort(
530
+ (a, b) => priorityMap[b.enforce ?? "default"] - priorityMap[a.enforce ?? "default"]
531
+ );
532
+ return flatten;
533
+ }
534
+
535
+ // src/source/plugins/slugs.ts
536
+ function slugsPlugin(slugsFn) {
537
+ function isIndex(file) {
538
+ return basename(file, extname(file)) === "index";
539
+ }
540
+ return {
541
+ name: "fumadocs:slugs",
542
+ transformStorage({ storage }) {
543
+ const indexFiles = /* @__PURE__ */ new Set();
544
+ const taken = /* @__PURE__ */ new Set();
545
+ const autoIndex = slugsFn === void 0;
546
+ for (const path of storage.getFiles()) {
547
+ const file = storage.read(path);
548
+ if (!file || file.format !== "page" || file.slugs) continue;
549
+ if (isIndex(path) && autoIndex) {
550
+ indexFiles.add(path);
551
+ continue;
552
+ }
553
+ file.slugs = slugsFn ? slugsFn({ path }) : getSlugs(path);
554
+ const key = file.slugs.join("/");
555
+ if (taken.has(key)) throw new Error("Duplicated slugs");
556
+ taken.add(key);
557
+ }
558
+ for (const path of indexFiles) {
559
+ const file = storage.read(path);
560
+ if (file?.format !== "page") continue;
561
+ file.slugs = getSlugs(path);
562
+ if (taken.has(file.slugs.join("/"))) file.slugs.push("index");
563
+ }
564
+ }
565
+ };
566
+ }
567
+ var GroupRegex = /^\(.+\)$/;
568
+ function getSlugs(file) {
569
+ const dir = dirname(file);
570
+ const name = basename(file, extname(file));
571
+ const slugs = [];
572
+ for (const seg of dir.split("/")) {
573
+ if (seg.length > 0 && !GroupRegex.test(seg)) slugs.push(encodeURI(seg));
574
+ }
575
+ if (GroupRegex.test(name))
576
+ throw new Error(`Cannot use folder group in file names: ${file}`);
577
+ if (name !== "index") {
578
+ slugs.push(encodeURI(name));
579
+ }
580
+ return slugs;
581
+ }
582
+
583
+ // src/source/loader.ts
584
+ function indexPages(storages, { url }) {
585
+ const result = {
586
+ // (locale.slugs -> page)
587
+ pages: /* @__PURE__ */ new Map(),
588
+ // (locale.path -> page)
589
+ pathToMeta: /* @__PURE__ */ new Map(),
590
+ // (locale.path -> meta)
591
+ pathToPage: /* @__PURE__ */ new Map()
592
+ };
593
+ for (const [lang, storage] of Object.entries(storages)) {
594
+ for (const filePath of storage.getFiles()) {
595
+ const item = storage.read(filePath);
596
+ const path = `${lang}.${filePath}`;
597
+ if (item.format === "meta") {
598
+ result.pathToMeta.set(path, {
599
+ path: item.path,
600
+ absolutePath: item.absolutePath,
601
+ data: item.data
602
+ });
603
+ continue;
604
+ }
605
+ const page = {
606
+ absolutePath: item.absolutePath,
607
+ path: item.path,
608
+ url: url(item.slugs, lang),
609
+ slugs: item.slugs,
610
+ data: item.data,
611
+ locale: lang
612
+ };
613
+ result.pathToPage.set(path, page);
614
+ result.pages.set(`${lang}.${page.slugs.join("/")}`, page);
615
+ }
616
+ }
617
+ return result;
618
+ }
619
+ function createGetUrl(baseUrl, i18n) {
620
+ const baseSlugs = baseUrl.split("/");
621
+ return (slugs, locale) => {
622
+ const hideLocale = i18n?.hideLocale ?? "never";
623
+ let urlLocale;
624
+ if (hideLocale === "never") {
625
+ urlLocale = locale;
626
+ } else if (hideLocale === "default-locale" && locale !== i18n?.defaultLanguage) {
627
+ urlLocale = locale;
628
+ }
629
+ const paths = [...baseSlugs, ...slugs];
630
+ if (urlLocale) paths.unshift(urlLocale);
631
+ return `/${paths.filter((v) => v.length > 0).join("/")}`;
632
+ };
633
+ }
634
+ function loader(...args) {
635
+ const loaderConfig = args.length === 2 ? resolveConfig(args[0], args[1]) : resolveConfig(args[0].source, args[0]);
636
+ const { i18n } = loaderConfig;
637
+ const defaultLanguage = i18n?.defaultLanguage ?? "";
638
+ const storages = buildContentStorage(loaderConfig, defaultLanguage);
639
+ const walker = indexPages(storages, loaderConfig);
640
+ const builder = createPageTreeBuilder(loaderConfig);
641
+ let pageTrees;
642
+ function getPageTrees() {
643
+ return pageTrees ??= builder.buildI18n(storages);
644
+ }
645
+ return {
646
+ _i18n: i18n,
647
+ get pageTree() {
648
+ const trees = getPageTrees();
649
+ return i18n ? trees : trees[defaultLanguage];
650
+ },
651
+ set pageTree(v) {
652
+ if (i18n) {
653
+ pageTrees = v;
654
+ } else {
655
+ pageTrees ??= {};
656
+ pageTrees[defaultLanguage] = v;
657
+ }
658
+ },
659
+ getPageByHref(href, { dir = "", language = defaultLanguage } = {}) {
660
+ const [value, hash] = href.split("#", 2);
661
+ let target;
662
+ if (value.startsWith(".") && (value.endsWith(".md") || value.endsWith(".mdx"))) {
663
+ const path = joinPath(dir, value);
664
+ target = walker.pathToPage.get(`${language}.${path}`);
665
+ } else {
666
+ target = this.getPages(language).find((item) => item.url === value);
667
+ }
668
+ if (target)
669
+ return {
670
+ page: target,
671
+ hash
672
+ };
673
+ },
674
+ getPages(language) {
675
+ const pages = [];
676
+ for (const [key, value] of walker.pages.entries()) {
677
+ if (language === void 0 || key.startsWith(`${language}.`)) {
678
+ pages.push(value);
679
+ }
680
+ }
681
+ return pages;
682
+ },
683
+ getLanguages() {
684
+ const list = [];
685
+ if (!i18n) return list;
686
+ for (const language of i18n.languages) {
687
+ list.push({
688
+ language,
689
+ pages: this.getPages(language)
690
+ });
691
+ }
692
+ return list;
693
+ },
694
+ // the slugs plugin generates encoded slugs by default.
695
+ // we can assume page slugs are always URI encoded.
696
+ getPage(slugs = [], language = defaultLanguage) {
697
+ let page = walker.pages.get(`${language}.${slugs.join("/")}`);
698
+ if (page) return page;
699
+ page = walker.pages.get(`${language}.${slugs.map(decodeURI).join("/")}`);
700
+ if (page) return page;
701
+ },
702
+ getNodeMeta(node, language = defaultLanguage) {
703
+ const ref = node.$ref?.metaFile;
704
+ if (!ref) return;
705
+ return walker.pathToMeta.get(`${language}.${ref}`);
706
+ },
707
+ getNodePage(node, language = defaultLanguage) {
708
+ const ref = node.$ref?.file;
709
+ if (!ref) return;
710
+ return walker.pathToPage.get(`${language}.${ref}`);
711
+ },
712
+ getPageTree(locale = defaultLanguage) {
713
+ const trees = getPageTrees();
714
+ return trees[locale] ?? trees[defaultLanguage];
715
+ },
716
+ // @ts-expect-error -- ignore this
717
+ generateParams(slug, lang) {
718
+ if (i18n) {
719
+ return this.getLanguages().flatMap(
720
+ (entry) => entry.pages.map((page) => ({
721
+ [slug ?? "slug"]: page.slugs,
722
+ [lang ?? "lang"]: entry.language
723
+ }))
724
+ );
725
+ }
726
+ return this.getPages().map((page) => ({
727
+ [slug ?? "slug"]: page.slugs
728
+ }));
729
+ },
730
+ async serializePageTree(tree) {
731
+ const { renderToString } = await import("react-dom/server.edge");
732
+ return visit(tree, (node) => {
733
+ node = { ...node };
734
+ if ("icon" in node && node.icon) {
735
+ node.icon = renderToString(node.icon);
736
+ }
737
+ if (node.name) {
738
+ node.name = renderToString(node.name);
739
+ }
740
+ if ("children" in node) {
741
+ node.children = [...node.children];
742
+ }
743
+ return node;
744
+ });
745
+ }
746
+ };
747
+ }
748
+ function resolveConfig(source2, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
749
+ let config = {
750
+ ...base,
751
+ url: url ? (...args) => normalizeUrl(url(...args)) : createGetUrl(baseUrl, base.i18n),
752
+ source: source2,
753
+ plugins: buildPlugins([
754
+ slugsPlugin(slugs),
755
+ icon && iconPlugin(icon),
756
+ ...typeof plugins === "function" ? plugins({
757
+ typedPlugin: (plugin) => plugin
758
+ }) : plugins
759
+ ])
760
+ };
761
+ for (const plugin of config.plugins ?? []) {
762
+ const result = plugin.config?.(config);
763
+ if (result) config = result;
764
+ }
765
+ return config;
766
+ }
767
+ export {
768
+ FileSystem,
769
+ path_exports as PathUtils,
770
+ createGetUrl,
771
+ getSlugs,
772
+ loader,
773
+ multiple,
774
+ source,
775
+ update
776
+ };