fuma-content 1.1.4 → 1.1.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 (58) hide show
  1. package/dist/{async-cache-BVuJiIDT.d.ts → async-cache-Ca5oMQss.d.ts} +4 -2
  2. package/dist/async-cache-Ca5oMQss.d.ts.map +1 -0
  3. package/dist/{async-cache-DRmFaVGm.js → async-cache-Cce8lc9D.js} +4 -2
  4. package/dist/async-cache-Cce8lc9D.js.map +1 -0
  5. package/dist/{build-mdx-DgzggXIL.js → build-mdx-C210zpJN.js} +27 -50
  6. package/dist/build-mdx-C210zpJN.js.map +1 -0
  7. package/dist/{build-mdx-DRqbcE1d.d.ts → build-mdx-DhXGp7I9.d.ts} +27 -5
  8. package/dist/build-mdx-DhXGp7I9.d.ts.map +1 -0
  9. package/dist/{bun-Be5pgXW_.js → bun-DsjsbVrx.js} +2 -2
  10. package/dist/{bun-Be5pgXW_.js.map → bun-DsjsbVrx.js.map} +1 -1
  11. package/dist/collections/data.js +2 -2
  12. package/dist/collections/fs.js +1 -1
  13. package/dist/collections/json/loader-webpack.js +2 -2
  14. package/dist/collections/mdx/loader-webpack.js +2 -2
  15. package/dist/collections/mdx/react.d.ts +2 -1
  16. package/dist/collections/mdx/react.d.ts.map +1 -1
  17. package/dist/collections/mdx/react.js +1 -1
  18. package/dist/collections/mdx/runtime-browser.d.ts +2 -2
  19. package/dist/collections/mdx/runtime-browser.js +1 -1
  20. package/dist/collections/mdx/runtime-dynamic.d.ts +1 -1
  21. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
  22. package/dist/collections/mdx/runtime-dynamic.js +6 -4
  23. package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
  24. package/dist/collections/mdx/runtime.d.ts +1 -1
  25. package/dist/collections/mdx.d.ts +4 -11
  26. package/dist/collections/mdx.d.ts.map +1 -1
  27. package/dist/collections/mdx.js +12 -5
  28. package/dist/collections/mdx.js.map +1 -1
  29. package/dist/collections/obsidian.d.ts +4 -3
  30. package/dist/collections/obsidian.d.ts.map +1 -1
  31. package/dist/collections/obsidian.js +11 -7
  32. package/dist/collections/obsidian.js.map +1 -1
  33. package/dist/collections/yaml/loader-webpack.js +2 -2
  34. package/dist/dynamic.js +1 -1
  35. package/dist/{fuma-matter-B4gT09gM.js → fuma-matter-CCYGfgju.js} +1 -1
  36. package/dist/{fuma-matter-B4gT09gM.js.map → fuma-matter-CCYGfgju.js.map} +1 -1
  37. package/dist/{is-promise-like-DYHv0Yap.js → is-promise-like-pBUIbRFy.js} +1 -1
  38. package/dist/{is-promise-like-DYHv0Yap.js.map → is-promise-like-pBUIbRFy.js.map} +1 -1
  39. package/dist/{load-from-file-BhdBOcQT.js → load-from-file-B9ho46XM.js} +1 -1
  40. package/dist/{load-from-file-BhdBOcQT.js.map → load-from-file-B9ho46XM.js.map} +1 -1
  41. package/dist/{loader-BT4fwLTJ.js → loader-B3hZ0R4a.js} +6 -4
  42. package/dist/{loader-BT4fwLTJ.js.map → loader-B3hZ0R4a.js.map} +1 -1
  43. package/dist/{loader-UhlX4xbz.js → loader-BFfzKD3u.js} +1 -1
  44. package/dist/{loader-UhlX4xbz.js.map → loader-BFfzKD3u.js.map} +1 -1
  45. package/dist/{loader-BOYLUNfh.js → loader-C5w-u-h2.js} +2 -2
  46. package/dist/{loader-BOYLUNfh.js.map → loader-C5w-u-h2.js.map} +1 -1
  47. package/dist/{loader-Cb9kSSxT.js → loader-D2BD3e0R.js} +2 -2
  48. package/dist/{loader-Cb9kSSxT.js.map → loader-D2BD3e0R.js.map} +1 -1
  49. package/dist/next/index.js +1 -1
  50. package/dist/node/loader.js +1 -1
  51. package/dist/plugins/git.js +1 -1
  52. package/dist/plugins/loader/index.js +2 -2
  53. package/dist/vite/index.js +1 -1
  54. package/package.json +2 -2
  55. package/dist/async-cache-BVuJiIDT.d.ts.map +0 -1
  56. package/dist/async-cache-DRmFaVGm.js.map +0 -1
  57. package/dist/build-mdx-DRqbcE1d.d.ts.map +0 -1
  58. package/dist/build-mdx-DgzggXIL.js.map +0 -1
@@ -1,9 +1,11 @@
1
+ import { S as Awaitable } from "./core-FjA_Xoho.js";
2
+
1
3
  //#region src/utils/async-cache.d.ts
2
4
  interface AsyncCache<V> {
3
- cached: (key: string, fn: () => V | Promise<V>) => V | Promise<V>;
5
+ cached: (key: string, fn: () => Awaitable<V>) => V | PromiseLike<V>;
4
6
  $value: <T>() => AsyncCache<T>;
5
7
  invalidate: (key: string) => void;
6
8
  }
7
9
  //#endregion
8
10
  export { AsyncCache as t };
9
- //# sourceMappingURL=async-cache-BVuJiIDT.d.ts.map
11
+ //# sourceMappingURL=async-cache-Ca5oMQss.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-cache-Ca5oMQss.d.ts","names":[],"sources":["../src/utils/async-cache.ts"],"mappings":";;;UAGiB,UAAA;EACf,MAAA,GAAS,GAAA,UAAa,EAAA,QAAU,SAAA,CAAU,CAAA,MAAO,CAAA,GAAI,WAAA,CAAY,CAAA;EACjE,MAAA,WAAiB,UAAA,CAAW,CAAA;EAC5B,UAAA,GAAa,GAAA;AAAA"}
@@ -1,3 +1,5 @@
1
+ import { t as isPromiseLike } from "./is-promise-like-pBUIbRFy.js";
2
+
1
3
  //#region src/utils/async-cache.ts
2
4
  /**
3
5
  * cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.
@@ -8,7 +10,7 @@ function createCache(store = /* @__PURE__ */ new Map()) {
8
10
  let cached = store.get(key);
9
11
  if (cached) return cached;
10
12
  cached = fn();
11
- if (cached instanceof Promise) cached = cached.then((out) => {
13
+ if (isPromiseLike(cached)) cached = cached.then((out) => {
12
14
  if (store.has(key)) store.set(key, out);
13
15
  return out;
14
16
  });
@@ -26,4 +28,4 @@ function createCache(store = /* @__PURE__ */ new Map()) {
26
28
 
27
29
  //#endregion
28
30
  export { createCache as t };
29
- //# sourceMappingURL=async-cache-DRmFaVGm.js.map
31
+ //# sourceMappingURL=async-cache-Cce8lc9D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-cache-Cce8lc9D.js","names":[],"sources":["../src/utils/async-cache.ts"],"sourcesContent":["import { Awaitable } from \"@/types\";\nimport { isPromiseLike } from \"./is-promise-like\";\n\nexport interface AsyncCache<V> {\n cached: (key: string, fn: () => Awaitable<V>) => V | PromiseLike<V>;\n $value: <T>() => AsyncCache<T>;\n invalidate: (key: string) => void;\n}\n\n/**\n * cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.\n */\nexport function createCache<V>(store = new Map<string, V | PromiseLike<V>>()): AsyncCache<V> {\n return {\n cached(key, fn) {\n let cached = store.get(key);\n if (cached) return cached;\n\n cached = fn();\n if (isPromiseLike(cached)) {\n cached = cached.then((out) => {\n // replace with resolved if still exists\n if (store.has(key)) {\n store.set(key, out);\n }\n\n return out;\n });\n }\n store.set(key, cached);\n return cached;\n },\n invalidate(key) {\n store.delete(key);\n },\n $value<T>() {\n return this as unknown as AsyncCache<T>;\n },\n };\n}\n"],"mappings":";;;;;;AAYA,SAAgB,YAAe,wBAAQ,IAAI,KAAiC,EAAiB;AAC3F,QAAO;EACL,OAAO,KAAK,IAAI;GACd,IAAI,SAAS,MAAM,IAAI,IAAI;AAC3B,OAAI,OAAQ,QAAO;AAEnB,YAAS,IAAI;AACb,OAAI,cAAc,OAAO,CACvB,UAAS,OAAO,MAAM,QAAQ;AAE5B,QAAI,MAAM,IAAI,IAAI,CAChB,OAAM,IAAI,KAAK,IAAI;AAGrB,WAAO;KACP;AAEJ,SAAM,IAAI,KAAK,OAAO;AACtB,UAAO;;EAET,WAAW,KAAK;AACd,SAAM,OAAO,IAAI;;EAEnB,SAAY;AACV,UAAO;;EAEV"}
@@ -1,52 +1,16 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-CjeV3_4I.js";
2
- import { t as createCache } from "./async-cache-DRmFaVGm.js";
3
- import { t as fumaMatter } from "./fuma-matter-B4gT09gM.js";
2
+ import { t as createCache } from "./async-cache-Cce8lc9D.js";
3
+ import { t as fumaMatter } from "./fuma-matter-CCYGfgju.js";
4
4
  import * as fs$1 from "node:fs/promises";
5
5
  import * as path$1 from "node:path";
6
6
  import { visit } from "unist-util-visit";
7
7
  import { createProcessor } from "@mdx-js/mdx";
8
8
  import { VFile } from "vfile";
9
- import { unified } from "unified";
10
9
  import { toMarkdown } from "mdast-util-to-markdown";
11
10
  import { valueToEstree } from "estree-util-value-to-estree";
12
11
  import { removePosition } from "unist-util-remove-position";
13
12
  import { mdxToMarkdown } from "mdast-util-mdx";
14
13
 
15
- //#region src/collections/mdx/remark-unravel.ts
16
- function remarkMarkAndUnravel() {
17
- return (tree) => {
18
- visit(tree, (node, index, parent) => {
19
- let offset = -1;
20
- let all = true;
21
- let oneOrMore = false;
22
- if (parent && typeof index === "number" && node.type === "paragraph") {
23
- const children = node.children;
24
- while (++offset < children.length) {
25
- const child = children[offset];
26
- if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") oneOrMore = true;
27
- else if (child.type === "text" && child.value.trim().length === 0) {} else {
28
- all = false;
29
- break;
30
- }
31
- }
32
- if (all && oneOrMore) {
33
- offset = -1;
34
- const newChildren = [];
35
- while (++offset < children.length) {
36
- const child = children[offset];
37
- if (child.type === "mdxJsxTextElement") child.type = "mdxJsxFlowElement";
38
- if (child.type === "mdxTextExpression") child.type = "mdxFlowExpression";
39
- if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {} else newChildren.push(child);
40
- }
41
- parent.children.splice(index, 1, ...newChildren);
42
- return index;
43
- }
44
- }
45
- });
46
- };
47
- }
48
-
49
- //#endregion
50
14
  //#region src/utils/mdast/flatten.ts
51
15
  function flattenNode(node) {
52
16
  if ("children" in node) return node.children.map((child) => flattenNode(child)).join("");
@@ -177,9 +141,7 @@ function extractCodeRegion(content, regionName) {
177
141
  }
178
142
  throw new Error(`Region "${regionName}" not found`);
179
143
  }
180
- function remarkInclude({ preprocess = [] } = {}) {
181
- const TagName = "include";
182
- const preprocessor = unified().use(remarkMarkAndUnravel).use(preprocess);
144
+ function remarkInclude({ tagName = "include" } = {}) {
183
145
  const embedContent = async (targetPath, heading, params, parent) => {
184
146
  const { _getProcessor = () => this, _compiler } = parent.data;
185
147
  let content;
@@ -197,17 +159,24 @@ function remarkInclude({ preprocess = [] } = {}) {
197
159
  value: heading ? extractCodeRegion(content, heading) : content,
198
160
  data: {}
199
161
  };
200
- const parser = await _getProcessor(ext === ".mdx" ? "mdx" : "md");
162
+ const processor = await _getProcessor(ext === ".mdx" ? "mdx" : "md");
201
163
  const parsed = fumaMatter(content);
202
164
  const targetFile = new VFile({
203
165
  path: targetPath,
204
166
  value: parsed.content,
205
167
  data: {
206
168
  ...parent.data,
207
- frontmatter: parsed.data
169
+ frontmatter: parsed.data,
170
+ _in_include: true
208
171
  }
209
172
  });
210
- let mdast = await preprocessor.run(parser.parse(targetFile), targetFile);
173
+ let mdast;
174
+ try {
175
+ mdast = await processor.run(processor.parse(targetFile), targetFile);
176
+ } catch (e) {
177
+ if (e instanceof Terminated) mdast = e.value;
178
+ else throw e;
179
+ }
211
180
  if (heading) {
212
181
  const extracted = extractSection(mdast, heading);
213
182
  if (!extracted) throw new Error(`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.`);
@@ -220,7 +189,7 @@ function remarkInclude({ preprocess = [] } = {}) {
220
189
  const queue = [];
221
190
  visit(tree, ElementLikeTypes, (_node, _, parent) => {
222
191
  const node = _node;
223
- if (node.name !== TagName) return;
192
+ if (node.name !== tagName) return;
224
193
  const specifier = flattenNode(node);
225
194
  if (specifier.length === 0) return "skip";
226
195
  const attributes = parseElementAttributes(node);
@@ -234,9 +203,15 @@ function remarkInclude({ preprocess = [] } = {}) {
234
203
  await Promise.all(queue);
235
204
  }
236
205
  return async (tree, file) => {
206
+ if (file.data._in_include) throw new Terminated(tree);
237
207
  await update(tree, file);
238
208
  };
239
209
  }
210
+ var Terminated = class {
211
+ constructor(value) {
212
+ this.value = value;
213
+ }
214
+ };
240
215
 
241
216
  //#endregion
242
217
  //#region src/collections/mdx/remark-postprocess.ts
@@ -340,7 +315,7 @@ function getMdastExport(name, value) {
340
315
  //#endregion
341
316
  //#region src/collections/mdx/build-mdx.ts
342
317
  var build_mdx_exports = /* @__PURE__ */ __exportAll({ buildMDX: () => buildMDX });
343
- async function buildMDX(core, collection, { filePath, frontmatter, source, compiler, environment, isDevelopment }) {
318
+ async function buildMDX({ core, collection, filePath, frontmatter, source, compiler, environment, isDevelopment }) {
344
319
  const processorCache = createCache(core.cache).$value();
345
320
  function getProcessor(format) {
346
321
  const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
@@ -350,13 +325,15 @@ async function buildMDX(core, collection, { filePath, frontmatter, source, compi
350
325
  _format: format,
351
326
  ...collection?.postprocess
352
327
  };
353
- const remarkIncludeOptions = { preprocess: collection?.preprocess?.remarkPlugins };
354
328
  return createProcessor({
355
329
  outputFormat: "program",
356
330
  development: isDevelopment,
357
331
  ...mdxOptions,
358
- remarkPlugins: [
359
- [remarkInclude, remarkIncludeOptions],
332
+ remarkPlugins: typeof mdxOptions?.remarkPlugins === "function" ? mdxOptions.remarkPlugins({
333
+ remarkInclude,
334
+ remarkPostprocess: [remarkPostprocess, postprocessOptions]
335
+ }) : [
336
+ remarkInclude,
360
337
  ...mdxOptions?.remarkPlugins ?? [],
361
338
  [remarkPostprocess, postprocessOptions]
362
339
  ],
@@ -384,4 +361,4 @@ async function buildMDX(core, collection, { filePath, frontmatter, source, compi
384
361
 
385
362
  //#endregion
386
363
  export { build_mdx_exports as n, buildMDX as t };
387
- //# sourceMappingURL=build-mdx-DgzggXIL.js.map
364
+ //# sourceMappingURL=build-mdx-C210zpJN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-mdx-C210zpJN.js","names":["fs","path"],"sources":["../src/utils/mdast/flatten.ts","../src/collections/mdx/remark-include.ts","../src/collections/mdx/remark-postprocess.ts","../src/collections/mdx/build-mdx.ts"],"sourcesContent":["import type { RootContent } from \"mdast\";\n\nexport function flattenNode(node: RootContent): string {\n if (\"children\" in node) return node.children.map((child) => flattenNode(child)).join(\"\");\n\n if (\"value\" in node) return node.value;\n\n return \"\";\n}\n","import type { Processor, Transformer } from \"unified\";\nimport { visit } from \"unist-util-visit\";\nimport type { Code, Node, Root, RootContent } from \"mdast\";\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\nimport { fumaMatter } from \"@/collections/mdx/fuma-matter\";\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from \"mdast-util-mdx-jsx\";\nimport { VFile } from \"vfile\";\nimport type { Directives } from \"mdast-util-directive\";\nimport { flattenNode } from \"@/utils/mdast/flatten\";\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent[\"type\"][] = [\n \"mdxJsxFlowElement\",\n \"mdxJsxTextElement\",\n \"containerDirective\",\n \"textDirective\",\n \"leafDirective\",\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent[\"type\"]);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === \"mdxJsxAttribute\" &&\n (typeof attr.value === \"string\" || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf(\"#\");\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === \"heading\") {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return \"skip\";\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return \"skip\";\n }\n\n if (isElementLike(node) && node.name === \"section\") {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: \"root\",\n children: nodes,\n };\n}\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join(\"\\n\")\n : lines.map((l) => l.slice(minIndent)).join(\"\\n\");\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split(\"\\n\");\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === \"\") depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface RemarkIncludeOptions {\n tagName?: string;\n}\n\ndeclare module \"vfile\" {\n interface DataMap {\n /** [Fuma Content: remark-include] whether the content is getting parsed from a `<include />` */\n _in_include?: boolean;\n }\n}\n\nexport function remarkInclude(\n this: Processor,\n { tagName = \"include\" }: RemarkIncludeOptions = {},\n): Transformer<Root, Root> {\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = (await fs.readFile(targetPath)).toString();\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n if (params.lang || (ext !== \".md\" && ext !== \".mdx\")) {\n const lang = params.lang ?? ext.slice(1);\n\n return {\n type: \"code\",\n lang,\n meta: params.meta,\n value: heading ? extractCodeRegion(content, heading) : content,\n data: {},\n } satisfies Code;\n }\n\n const processor = (await _getProcessor(ext === \".mdx\" ? \"mdx\" : \"md\")) as unknown as Processor<\n Root,\n Root,\n Root\n >;\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n _in_include: true,\n },\n });\n\n let mdast: Root;\n try {\n mdast = await processor.run(processor.parse(targetFile), targetFile);\n } catch (e) {\n if (e instanceof Terminated) mdast = e.value;\n else throw e;\n }\n\n if (heading) {\n const extracted = extractSection(mdast, heading);\n if (!extracted)\n throw new Error(\n `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.`,\n );\n\n mdast = extracted;\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== tagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return \"skip\";\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve(\n \"cwd\" in attributes ? file.cwd : (file.dirname ?? \"\"),\n relativePath,\n );\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(parent && parent.type === \"paragraph\" ? parent : node, replace);\n }),\n );\n\n return \"skip\";\n });\n\n await Promise.all(queue);\n }\n return async (tree, file) => {\n if (file.data._in_include) throw new Terminated(tree);\n\n await update(tree, file);\n };\n}\n\nclass Terminated {\n constructor(readonly value: Root) {}\n}\n","import type { Processor, Transformer } from \"unified\";\nimport type { Heading, Root, RootContent } from \"mdast\";\nimport { visit } from \"unist-util-visit\";\nimport { toMarkdown } from \"mdast-util-to-markdown\";\nimport { valueToEstree } from \"estree-util-value-to-estree\";\nimport { removePosition } from \"unist-util-remove-position\";\nimport { flattenNode } from \"@/utils/mdast/flatten\";\nimport { mdxToMarkdown } from \"mdast-util-mdx\";\n\nexport interface LinkReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: \"md\" | \"mdx\";\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n processedMarkdown?:\n | boolean\n | {\n as?: string;\n /**\n * include heading IDs into the processed markdown.\n */\n headingIds?: boolean;\n };\n\n /**\n * extract link references, export via `_linkReferences`.\n */\n linkReferences?:\n | boolean\n | {\n as?: string;\n };\n\n /**\n * store MDAST and export via `_mdast`.\n */\n mdast?:\n | boolean\n | {\n as?: string;\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n _format,\n processedMarkdown = false,\n mdast = false,\n linkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, \"heading\", (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data[\"mdx-export\"] ??= [];\n file.data[\"mdx-export\"].push({\n name: \"frontmatter\",\n value: frontmatter,\n });\n\n if (linkReferences) {\n const { as = \"_linkReferences\" } = linkReferences === true ? {} : linkReferences;\n const urls: LinkReference[] = [];\n\n visit(tree, \"link\", (node) => {\n urls.push({\n href: node.url,\n });\n return \"skip\";\n });\n\n file.data[\"mdx-export\"].push({\n name: as,\n value: urls,\n });\n }\n\n if (processedMarkdown) {\n const { as = \"_markdown\", headingIds = true } =\n processedMarkdown === true ? {} : processedMarkdown;\n const extensions = this.data(\"toMarkdownExtensions\") ?? [];\n\n const markdown = toMarkdown(tree, {\n ...this.data(\"settings\"),\n extensions: _format === \"md\" ? [...extensions, mdxToMarkdown()] : extensions,\n handlers: {\n heading(node: Heading) {\n const id = node.data?.hProperties?.id;\n const content = flattenNode(node);\n return headingIds && id ? `${content} [#${id}]` : content;\n },\n },\n });\n\n file.data[\"mdx-export\"].push({\n name: as,\n value: markdown,\n });\n }\n\n if (mdast) {\n const { as = \"_mdast\", removePosition: shouldRemovePosition = false } =\n mdast === true ? {} : mdast;\n const stringified = JSON.stringify(\n shouldRemovePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data[\"mdx-export\"].push({\n name: as,\n value: stringified,\n });\n }\n\n for (const { name, value } of file.data[\"mdx-export\"]) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data[\"mdx-export\"] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: \"mdxjsEsm\",\n value: \"\",\n data: {\n estree: {\n type: \"Program\",\n sourceType: \"module\",\n body: [\n {\n type: \"ExportNamedDeclaration\",\n specifiers: [],\n attributes: [],\n source: null,\n declaration: {\n type: \"VariableDeclaration\",\n kind: \"let\",\n declarations: [\n {\n type: \"VariableDeclarator\",\n id: {\n type: \"Identifier\",\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor, type ProcessorOptions } from \"@mdx-js/mdx\";\nimport { VFile } from \"vfile\";\nimport { remarkInclude } from \"@/collections/mdx/remark-include\";\nimport { type PostprocessOptions, remarkPostprocess } from \"@/collections/mdx/remark-postprocess\";\nimport type { Core } from \"@/core\";\nimport { createCache } from \"@/utils/async-cache\";\nimport type { MDXContent } from \"mdx/types\";\nimport { MDXCollection } from \"../mdx\";\nimport type { Pluggable, PluggableList } from \"unified\";\nimport type { Awaitable } from \"@/types\";\n\ntype MDXProcessor = ReturnType<typeof createProcessor>;\n\ninterface MDXCompilerContext {\n addDependency: (file: string) => void;\n collection: MDXCollection | undefined;\n core: Core;\n}\n\ninterface BuildMDXOptions {\n core: Core;\n collection: MDXCollection | undefined;\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: \"bundler\" | \"runtime\";\n isDevelopment: boolean;\n compiler: MDXCompilerContext;\n}\n\nexport interface FumaContentProcessorOptions extends Omit<ProcessorOptions, \"remarkPlugins\"> {\n remarkPlugins?:\n | PluggableList\n | ((plugins: {\n remarkInclude: typeof remarkInclude;\n remarkPostprocess: Pluggable;\n }) => PluggableList)\n | null\n | undefined;\n}\n\nexport interface FumaContentDataMap {\n /**\n * [Fuma Content] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fuma Content] additional ESM exports to write\n */\n \"mdx-export\"?: { name: string; value: unknown }[];\n\n /**\n * [Fuma Content] The internal compiler info\n */\n _compiler?: MDXCompilerContext;\n\n /**\n * [Fuma Content] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: \"md\" | \"mdx\") => Awaitable<MDXProcessor>;\n}\n\ndeclare module \"vfile\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumaContentDataMap {}\n}\n\nexport interface CompiledMDX<Frontmatter = Record<string, unknown>> extends Record<\n string,\n unknown\n> {\n frontmatter: Frontmatter;\n default: MDXContent;\n}\n\nexport async function buildMDX({\n core,\n collection,\n filePath,\n frontmatter,\n source,\n compiler,\n environment,\n isDevelopment,\n}: BuildMDXOptions): Promise<VFile> {\n const processorCache = createCache(core.cache).$value<MDXProcessor>();\n\n function getProcessor(format: \"md\" | \"mdx\") {\n const key = `build-mdx:${collection?.name ?? \"global\"}:${format}`;\n\n return processorCache.cached(key, async () => {\n const mdxOptions = await collection?.getMDXOptions?.(environment);\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n return createProcessor({\n outputFormat: \"program\",\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins:\n typeof mdxOptions?.remarkPlugins === \"function\"\n ? mdxOptions.remarkPlugins({\n remarkInclude,\n remarkPostprocess: [remarkPostprocess, postprocessOptions],\n })\n : [\n remarkInclude,\n ...(mdxOptions?.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n });\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: core.getOptions().cwd,\n data: {\n frontmatter,\n _compiler: compiler,\n _getProcessor: getProcessor,\n },\n });\n\n if (collection && collection) {\n vfile = await collection.vfile.run(vfile, {\n collection,\n filePath,\n source,\n });\n }\n\n return (await getProcessor(filePath.endsWith(\".mdx\") ? \"mdx\" : \"md\")).process(vfile);\n}\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAgB,YAAY,MAA2B;AACrD,KAAI,cAAc,KAAM,QAAO,KAAK,SAAS,KAAK,UAAU,YAAY,MAAM,CAAC,CAAC,KAAK,GAAG;AAExF,KAAI,WAAW,KAAM,QAAO,KAAK;AAEjC,QAAO;;;;;ACST,MAAM,mBAAiD;CACrD;CACA;CACA;CACA;CACA;CACD;AAGD,SAAS,cAAc,MAAwC;AAC7D,QAAO,iBAAiB,SAAS,KAAK,KAAmC;;AAG3E,SAAS,uBACP,SAC2C;AAC3C,KAAI,MAAM,QAAQ,QAAQ,WAAW,EAAE;EACrC,MAAM,aAA4C,EAAE;AAEpD,OAAK,MAAM,QAAQ,QAAQ,WACzB,KACE,KAAK,SAAS,sBACb,OAAO,KAAK,UAAU,YAAY,KAAK,UAAU,MAElD,YAAW,KAAK,QAAQ,KAAK;AAIjC,SAAO;;AAGT,QAAO,QAAQ,cAAc,EAAE;;AAGjC,SAAS,eAAe,WAGtB;CACA,MAAM,MAAM,UAAU,YAAY,IAAI;AACtC,KAAI,QAAQ,GAAI,QAAO,EAAE,MAAM,WAAW;AAE1C,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O,YAAY,kBAAkB,aACjC,WAAW,cAAc;KACvB;KACA,mBAAmB,CAAC,mBAAmB,mBAAmB;KAC3D,CAAC,GACF;KACE;KACA,GAAI,YAAY,iBAAiB,EAAE;KACnC,CAAC,mBAAmB,mBAAmB;KACxC;IACP;IACD,CAAC;IACF;;CAGJ,IAAI,QAAQ,IAAI,MAAM;EACpB,OAAO;EACP,MAAM;EACN,KAAK,KAAK,YAAY,CAAC;EACvB,MAAM;GACJ;GACA,WAAW;GACX,eAAe;GAChB;EACF,CAAC;AAEF,KAAI,cAAc,WAChB,SAAQ,MAAM,WAAW,MAAM,IAAI,OAAO;EACxC;EACA;EACA;EACD,CAAC;AAGJ,SAAQ,MAAM,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,EAAE,QAAQ,MAAM"}
@@ -1,7 +1,9 @@
1
- import { t as Core } from "./core-FjA_Xoho.js";
1
+ import { S as Awaitable, t as Core } from "./core-FjA_Xoho.js";
2
2
  import { MDXCollection } from "./collections/mdx.js";
3
- import { createProcessor } from "@mdx-js/mdx";
3
+ import { ProcessorOptions, createProcessor } from "@mdx-js/mdx";
4
4
  import { VFile } from "vfile";
5
+ import { Pluggable, PluggableList, Processor, Transformer } from "unified";
6
+ import { Root } from "mdast";
5
7
  import { MDXContent } from "mdx/types";
6
8
 
7
9
  //#region src/collections/mdx/remark-postprocess.d.ts
@@ -39,6 +41,20 @@ interface PostprocessOptions {
39
41
  };
40
42
  }
41
43
  //#endregion
44
+ //#region src/collections/mdx/remark-include.d.ts
45
+ interface RemarkIncludeOptions {
46
+ tagName?: string;
47
+ }
48
+ declare module "vfile" {
49
+ interface DataMap {
50
+ /** [Fuma Content: remark-include] whether the content is getting parsed from a `<include />` */
51
+ _in_include?: boolean;
52
+ }
53
+ }
54
+ declare function remarkInclude(this: Processor, {
55
+ tagName
56
+ }?: RemarkIncludeOptions): Transformer<Root, Root>;
57
+ //#endregion
42
58
  //#region src/collections/mdx/build-mdx.d.ts
43
59
  type MDXProcessor = ReturnType<typeof createProcessor>;
44
60
  interface MDXCompilerContext {
@@ -46,6 +62,12 @@ interface MDXCompilerContext {
46
62
  collection: MDXCollection | undefined;
47
63
  core: Core;
48
64
  }
65
+ interface FumaContentProcessorOptions extends Omit<ProcessorOptions, "remarkPlugins"> {
66
+ remarkPlugins?: PluggableList | ((plugins: {
67
+ remarkInclude: typeof remarkInclude;
68
+ remarkPostprocess: Pluggable;
69
+ }) => PluggableList) | null | undefined;
70
+ }
49
71
  interface FumaContentDataMap {
50
72
  /**
51
73
  * [Fuma Content] raw frontmatter, you can modify it
@@ -65,7 +87,7 @@ interface FumaContentDataMap {
65
87
  /**
66
88
  * [Fuma Content] get internal processor, do not use this on user land.
67
89
  */
68
- _getProcessor?: (format: "md" | "mdx") => MDXProcessor | Promise<MDXProcessor>;
90
+ _getProcessor?: (format: "md" | "mdx") => Awaitable<MDXProcessor>;
69
91
  }
70
92
  declare module "vfile" {
71
93
  interface DataMap extends FumaContentDataMap {}
@@ -75,5 +97,5 @@ interface CompiledMDX<Frontmatter = Record<string, unknown>> extends Record<stri
75
97
  default: MDXContent;
76
98
  }
77
99
  //#endregion
78
- export { LinkReference as n, PostprocessOptions as r, CompiledMDX as t };
79
- //# sourceMappingURL=build-mdx-DRqbcE1d.d.ts.map
100
+ export { PostprocessOptions as i, FumaContentProcessorOptions as n, LinkReference as r, CompiledMDX as t };
101
+ //# sourceMappingURL=build-mdx-DhXGp7I9.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-mdx-DhXGp7I9.d.ts","names":[],"sources":["../src/collections/mdx/remark-postprocess.ts","../src/collections/mdx/remark-include.ts","../src/collections/mdx/build-mdx.ts"],"mappings":";;;;;;;;;UASiB,aAAA;EACf,IAAA;AAAA;AAAA,UAGe,kBAAA;EACf,OAAA;;;AALF;EAUE,aAAA;;;;EAKA,iBAAA;IAGM,EAAA;IAd2B;;;IAkB3B,UAAA;EAAA;EAJA;;;EAUN,cAAA;IAGM,EAAA;EAAA;EAUA;;;EAJN,KAAA;IAGM,EAAA;IACA,cAAA;EAAA;AAAA;;;UCuIS,oBAAA;EACf,OAAA;AAAA;AAAA;EAAA,UAIU,OAAA;IDrLkB;ICuL1B,WAAA;EAAA;AAAA;AAAA,iBAIY,aAAA,CACd,IAAA,EAAM,SAAA;EACJ;AAAA,IAAuB,oBAAA,GACxB,WAAA,CAAY,IAAA,EAAM,IAAA;;;KC5LhB,YAAA,GAAe,UAAA,QAAkB,eAAA;AAAA,UAE5B,kBAAA;EACR,aAAA,GAAgB,IAAA;EAChB,UAAA,EAAY,aAAA;EACZ,IAAA,EAAM,IAAA;AAAA;AAAA,UAkBS,2BAAA,SAAoC,IAAA,CAAK,gBAAA;EACxD,aAAA,GACI,aAAA,KACE,OAAA;IACA,aAAA,SAAsB,aAAA;IACtB,iBAAA,EAAmB,SAAA;EAAA,MACf,aAAA;AAAA;AAAA,UAKK,kBAAA;ED4IoB;;;ECxInC,WAAA,GAAc,MAAA;ED0If;;;ECrIC,YAAA;IAAiB,IAAA;IAAc,KAAA;EAAA;ED8IJ;;;ECzI3B,SAAA,GAAY,kBAAA;ED2Ia;;;ECtIzB,aAAA,IAAiB,MAAA,mBAAyB,SAAA,CAAU,YAAA;AAAA;AAAA;EAAA,UAK1C,OAAA,SAAgB,kBAAA;AAAA;AAAA,UAGX,WAAA,eAA0B,MAAA,2BAAiC,MAAA;EAI1E,WAAA,EAAa,WAAA;EACb,OAAA,EAAS,UAAA;AAAA"}
@@ -1,4 +1,4 @@
1
- import { t as isPromiseLike } from "./is-promise-like-DYHv0Yap.js";
1
+ import { t as isPromiseLike } from "./is-promise-like-pBUIbRFy.js";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { parse } from "node:querystring";
4
4
 
@@ -33,4 +33,4 @@ function toBun(test = /.+/, loader) {
33
33
 
34
34
  //#endregion
35
35
  export { toBun };
36
- //# sourceMappingURL=bun-Be5pgXW_.js.map
36
+ //# sourceMappingURL=bun-DsjsbVrx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun-Be5pgXW_.js","names":[],"sources":["../src/plugins/loader/bun.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { readFileSync } from \"node:fs\";\nimport type { LoaderInput, Loader, LoaderOutput } from \"@/plugins/loader\";\nimport { isPromiseLike } from \"@/utils/is-promise-like\";\n\nexport function toBun(test: RegExp = /.+/, loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? \"js\",\n };\n }\n\n return (build: Bun.PluginBuilder): void => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: test }, (args) => {\n const [filePath, query = \"\"] = args.path.split(\"?\", 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n addDependency() {},\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath).toString(), input);\n }\n\n const result = loader.load(input);\n if (isPromiseLike(result)) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,MAAM,OAAe,MAAM,QAAgB;CACzD,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ,OAAO,cAAc;GAC9B;;AAGH,SAAQ,UAAmC;AAEzC,QAAM,OAAO,EAAE,QAAQ,MAAM,GAAG,SAAS;GACvC,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAM,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,gBAAgB;IACjB;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,SAAS,CAAC,UAAU,EAAE,MAAM;GAGlE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,cAAc,OAAO,CACvB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
1
+ {"version":3,"file":"bun-DsjsbVrx.js","names":[],"sources":["../src/plugins/loader/bun.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { readFileSync } from \"node:fs\";\nimport type { LoaderInput, Loader, LoaderOutput } from \"@/plugins/loader\";\nimport { isPromiseLike } from \"@/utils/is-promise-like\";\n\nexport function toBun(test: RegExp = /.+/, loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? \"js\",\n };\n }\n\n return (build: Bun.PluginBuilder): void => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: test }, (args) => {\n const [filePath, query = \"\"] = args.path.split(\"?\", 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n addDependency() {},\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath).toString(), input);\n }\n\n const result = loader.load(input);\n if (isPromiseLike(result)) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,MAAM,OAAe,MAAM,QAAgB;CACzD,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ,OAAO,cAAc;GAC9B;;AAGH,SAAQ,UAAmC;AAEzC,QAAM,OAAO,EAAE,QAAQ,MAAM,GAAG,SAAS;GACvC,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAM,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,gBAAgB;IACjB;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,SAAS,CAAC,UAAU,EAAE,MAAM;GAGlE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,cAAc,OAAO,CACvB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
@@ -102,7 +102,7 @@ function yamlLoader() {
102
102
  };
103
103
  },
104
104
  async createLoader() {
105
- const { createYamlLoader } = await import("../loader-Cb9kSSxT.js").then((n) => n.n);
105
+ const { createYamlLoader } = await import("../loader-D2BD3e0R.js").then((n) => n.n);
106
106
  const core = this.core;
107
107
  return createYamlLoader({ getCore: () => core });
108
108
  }
@@ -147,7 +147,7 @@ function jsonLoader() {
147
147
  };
148
148
  },
149
149
  async createLoader(environment) {
150
- const { createJsonLoader } = await import("../loader-BOYLUNfh.js").then((n) => n.n);
150
+ const { createJsonLoader } = await import("../loader-C5w-u-h2.js").then((n) => n.n);
151
151
  const core = this.core;
152
152
  return createJsonLoader({ getCore: () => core }, environment === "vite" ? "json" : "js");
153
153
  }
@@ -1,5 +1,5 @@
1
1
  import { Collection } from "./index.js";
2
- import { t as createCache } from "../async-cache-DRmFaVGm.js";
2
+ import { t as createCache } from "../async-cache-Cce8lc9D.js";
3
3
  import path from "node:path";
4
4
  import picomatch from "picomatch";
5
5
 
@@ -1,7 +1,7 @@
1
1
  import "../../validation-C3kXuveD.js";
2
2
  import { createWebpackLoader } from "../../plugins/loader/webpack.js";
3
- import "../../loader-UhlX4xbz.js";
4
- import { t as createJsonLoader } from "../../loader-BOYLUNfh.js";
3
+ import "../../loader-BFfzKD3u.js";
4
+ import { t as createJsonLoader } from "../../loader-C5w-u-h2.js";
5
5
 
6
6
  //#region src/collections/json/loader-webpack.ts
7
7
  var loader_webpack_default = createWebpackLoader((core) => createJsonLoader(core, "json"));
@@ -1,7 +1,7 @@
1
1
  import "../../validation-C3kXuveD.js";
2
- import "../../fuma-matter-B4gT09gM.js";
2
+ import "../../fuma-matter-CCYGfgju.js";
3
3
  import { createWebpackLoader } from "../../plugins/loader/webpack.js";
4
- import { t as createMdxLoader } from "../../loader-BT4fwLTJ.js";
4
+ import { t as createMdxLoader } from "../../loader-B3hZ0R4a.js";
5
5
 
6
6
  //#region src/collections/mdx/loader-webpack.ts
7
7
  var loader_webpack_default = createWebpackLoader(createMdxLoader);
@@ -1,5 +1,6 @@
1
1
  import "../../core-FjA_Xoho.js";
2
- import { t as CompiledMDX } from "../../build-mdx-DRqbcE1d.js";
2
+ import { t as CompiledMDX } from "../../build-mdx-DhXGp7I9.js";
3
+ import "../../async-cache-Ca5oMQss.js";
3
4
  import { MDXStoreBrowserData } from "./runtime-browser.js";
4
5
  import { ReactNode } from "react";
5
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","names":[],"sources":["../../../src/collections/mdx/react.ts"],"mappings":";;;;;;;;;AAkBA;;iBAAgB,WAAA,uBAAA,CACd,KAAA,EAAO,mBAAA,CAAoB,WAAA,EAAa,QAAA,eACxC,QAAA,GAAW,IAAA,EAAM,WAAA,CAAY,WAAA,IAAe,QAAA,KAAa,SAAA,GACxD,SAAA"}
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../../../src/collections/mdx/react.ts"],"mappings":";;;;;;;;;;;AAkBA;iBAAgB,WAAA,uBAAA,CACd,KAAA,EAAO,mBAAA,CAAoB,WAAA,EAAa,QAAA,eACxC,QAAA,GAAW,IAAA,EAAM,WAAA,CAAY,WAAA,IAAe,QAAA,KAAa,SAAA,GACxD,SAAA"}
@@ -1,4 +1,4 @@
1
- import { t as isPromiseLike } from "../../is-promise-like-DYHv0Yap.js";
1
+ import { t as isPromiseLike } from "../../is-promise-like-pBUIbRFy.js";
2
2
  import { createElement, lazy } from "react";
3
3
 
4
4
  //#region src/collections/mdx/react.ts
@@ -1,8 +1,8 @@
1
1
  import { C as GetCollectionConfig, S as Awaitable } from "../../core-FjA_Xoho.js";
2
2
  import { MapCollectionStore } from "../runtime/store.js";
3
- import { t as CompiledMDX } from "../../build-mdx-DRqbcE1d.js";
3
+ import { t as CompiledMDX } from "../../build-mdx-DhXGp7I9.js";
4
4
  import { MDXCollection } from "../mdx.js";
5
- import { t as AsyncCache } from "../../async-cache-BVuJiIDT.js";
5
+ import { t as AsyncCache } from "../../async-cache-Ca5oMQss.js";
6
6
  import { WithGit } from "./runtime.js";
7
7
 
8
8
  //#region src/collections/mdx/runtime-browser.d.ts
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { t as createCache } from "../../async-cache-DRmFaVGm.js";
3
+ import { t as createCache } from "../../async-cache-Cce8lc9D.js";
4
4
  import { MapCollectionStore } from "../runtime/store.js";
5
5
 
6
6
  //#region src/collections/mdx/runtime-browser.ts
@@ -1,6 +1,6 @@
1
1
  import { C as GetCollectionConfig, n as CoreOptions } from "../../core-FjA_Xoho.js";
2
2
  import { FileCollectionStore } from "../runtime/file-store.js";
3
- import { t as CompiledMDX } from "../../build-mdx-DRqbcE1d.js";
3
+ import { t as CompiledMDX } from "../../build-mdx-DhXGp7I9.js";
4
4
  import { MDXCollection } from "../mdx.js";
5
5
  import { WithGit } from "./runtime.js";
6
6
  import { MDXContent } from "mdx/types";
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-dynamic.d.ts","names":[],"sources":["../../../src/collections/mdx/runtime-dynamic.ts"],"mappings":";;;;;;;;UAYiB,mBAAA;EACf,EAAA;EACA,WAAA,EAAa,WAAA;EACb,OAAA,QAAe,OAAA,CAAQ,WAAA,CAAY,WAAA,IAAe,QAAA;AAAA;AAAA,KAK/C,cAAA,gCACH,mBAAA,CAAoB,MAAA,EAAQ,IAAA,UAAc,aAAA,GACtC,mBAAA,CAAoB,MAAA,EAAQ,IAAA;AAAA,iBAGZ,eAAA,uCAAA,CACpB,MAAA,EAAQ,MAAA,EACR,WAAA,EAAa,WAAA,EACb,IAAA,EAAM,IAAA,EACN,IAAA,UACA,YAAA,EAAc,MAAA,mBACd,UAAA,YACC,OAAA,CAAQ,mBAAA,CAAoB,mBAAA,CAAoB,cAAA,CAAe,MAAA,EAAQ,IAAA,GAAO,QAAA;AAAA,KAoDrE,UAAA,GAAa,UAAA"}
1
+ {"version":3,"file":"runtime-dynamic.d.ts","names":[],"sources":["../../../src/collections/mdx/runtime-dynamic.ts"],"mappings":";;;;;;;;UAYiB,mBAAA;EACf,EAAA;EACA,WAAA,EAAa,WAAA;EACb,OAAA,QAAe,OAAA,CAAQ,WAAA,CAAY,WAAA,IAAe,QAAA;AAAA;AAAA,KAK/C,cAAA,gCACH,mBAAA,CAAoB,MAAA,EAAQ,IAAA,UAAc,aAAA,GACtC,mBAAA,CAAoB,MAAA,EAAQ,IAAA;AAAA,iBAGZ,eAAA,uCAAA,CACpB,MAAA,EAAQ,MAAA,EACR,WAAA,EAAa,WAAA,EACb,IAAA,EAAM,IAAA,EACN,IAAA,UACA,YAAA,EAAc,MAAA,mBACd,UAAA,YACC,OAAA,CAAQ,mBAAA,CAAoB,mBAAA,CAAoB,cAAA,CAAe,MAAA,EAAQ,IAAA,GAAO,QAAA;AAAA,KAsDrE,UAAA,GAAa,UAAA"}
@@ -1,10 +1,10 @@
1
1
  import { t as Core } from "../../core-BuUsOElL.js";
2
2
  import "../../validation-C3kXuveD.js";
3
- import { t as createCache } from "../../async-cache-DRmFaVGm.js";
3
+ import { t as createCache } from "../../async-cache-Cce8lc9D.js";
4
4
  import { MDXCollection } from "../mdx.js";
5
- import { t as fumaMatter } from "../../fuma-matter-B4gT09gM.js";
5
+ import { t as fumaMatter } from "../../fuma-matter-CCYGfgju.js";
6
6
  import { FileCollectionStore } from "../runtime/file-store.js";
7
- import { t as buildMDX } from "../../build-mdx-DgzggXIL.js";
7
+ import { t as buildMDX } from "../../build-mdx-C210zpJN.js";
8
8
  import fs from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import { pathToFileURL } from "node:url";
@@ -31,7 +31,9 @@ async function mdxStoreDynamic(config, coreOptions, name, base, _frontmatter, js
31
31
  const filePath = path.join(base, k);
32
32
  let content = (await fs.readFile(filePath)).toString();
33
33
  content = fumaMatter(content).content;
34
- const compiled = await buildMDX(core, collection, {
34
+ const compiled = await buildMDX({
35
+ core,
36
+ collection,
35
37
  filePath,
36
38
  source: content,
37
39
  frontmatter: v,
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-dynamic.js","names":[],"sources":["../../../src/collections/mdx/runtime-dynamic.ts"],"sourcesContent":["import { buildMDX, type CompiledMDX } from \"@/collections/mdx/build-mdx\";\nimport { pathToFileURL } from \"node:url\";\nimport { fumaMatter } from \"@/collections/mdx/fuma-matter\";\nimport fs from \"node:fs/promises\";\nimport { type CoreOptions, Core } from \"@/core\";\nimport type { MDXContent } from \"mdx/types\";\nimport { FileCollectionStore } from \"@/collections/runtime/file-store\";\nimport type { GetCollectionConfig } from \"@/types\";\nimport { MDXCollection } from \"@/collections/mdx\";\nimport path from \"node:path\";\nimport { createCache } from \"@/utils/async-cache\";\n\nexport interface MDXStoreDynamicData<Frontmatter, Attached = unknown> {\n id: string;\n frontmatter: Frontmatter;\n compile: () => Promise<CompiledMDX<Frontmatter> & Attached>;\n}\n\nlet corePromise: Promise<Core>;\n\ntype GetFrontmatter<Config, Name extends string> =\n GetCollectionConfig<Config, Name> extends MDXCollection\n ? GetCollectionConfig<Config, Name>[\"$inferFrontmatter\"]\n : never;\n\nexport async function mdxStoreDynamic<Config, Name extends string, Attached>(\n config: Config,\n coreOptions: CoreOptions,\n name: Name,\n base: string,\n _frontmatter: Record<string, unknown>,\n jsxRuntime: unknown,\n): Promise<FileCollectionStore<MDXStoreDynamicData<GetFrontmatter<Config, Name>, Attached>>> {\n corePromise ??= (async () => {\n const core = new Core(coreOptions);\n await core.init({\n config: config as Record<string, unknown>,\n });\n return core;\n })();\n const core = await corePromise;\n const frontmatter = _frontmatter as Record<string, GetFrontmatter<Config, Name>>;\n const collection = core.getCollection(name);\n if (!collection || !(collection instanceof MDXCollection))\n throw new Error(\"invalid collection name\");\n\n const merged: Record<string, MDXStoreDynamicData<GetFrontmatter<Config, Name>, Attached>> = {};\n const cache = createCache<CompiledMDX<GetFrontmatter<Config, Name>> & Attached>();\n\n for (const [k, v] of Object.entries(frontmatter)) {\n merged[k] = {\n id: k,\n frontmatter: v,\n async compile() {\n return cache.cached(k, async () => {\n const filePath = path.join(base, k);\n let content = (await fs.readFile(filePath)).toString();\n content = fumaMatter(content).content;\n\n const compiled = await buildMDX(core, collection, {\n filePath,\n source: content,\n frontmatter: v as unknown as Record<string, unknown>,\n isDevelopment: false,\n environment: \"runtime\",\n compiler: {\n collection,\n core,\n addDependency() {},\n },\n });\n\n return (await executeMdx(String(compiled.value), {\n baseUrl: pathToFileURL(filePath),\n jsxRuntime,\n })) as CompiledMDX<GetFrontmatter<Config, Name>> & Attached;\n });\n },\n };\n }\n\n return new FileCollectionStore(base, merged);\n}\n\nexport type MdxContent = MDXContent;\n\ninterface Options {\n scope?: Record<string, unknown>;\n baseUrl?: string | URL;\n jsxRuntime?: unknown;\n}\n\nconst AsyncFunction: new (...args: string[]) => (...args: unknown[]) => Promise<unknown> =\n Object.getPrototypeOf(executeMdx).constructor;\n\nasync function executeMdx(compiled: string, options: Options = {}) {\n const { opts: scopeOpts, ...scope } = options.scope ?? {};\n const fullScope = {\n opts: {\n ...(scopeOpts as object),\n ...(options.jsxRuntime as object),\n baseUrl: options.baseUrl,\n },\n ...scope,\n };\n\n const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);\n return (await hydrateFn.apply(hydrateFn, Object.values(fullScope))) as {\n default: MdxContent;\n };\n}\n\nexport type { WithGit } from \"./runtime\";\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAI;AAOJ,eAAsB,gBACpB,QACA,aACA,MACA,MACA,cACA,YAC2F;AAC3F,kBAAiB,YAAY;EAC3B,MAAM,OAAO,IAAI,KAAK,YAAY;AAClC,QAAM,KAAK,KAAK,EACN,QACT,CAAC;AACF,SAAO;KACL;CACJ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import { buildMDX, type CompiledMDX } from \"@/collections/mdx/build-mdx\";\nimport { pathToFileURL } from \"node:url\";\nimport { fumaMatter } from \"@/collections/mdx/fuma-matter\";\nimport fs from \"node:fs/promises\";\nimport { type CoreOptions, Core } from \"@/core\";\nimport type { MDXContent } from \"mdx/types\";\nimport { FileCollectionStore } from \"@/collections/runtime/file-store\";\nimport type { GetCollectionConfig } from \"@/types\";\nimport { MDXCollection } from \"@/collections/mdx\";\nimport path from \"node:path\";\nimport { createCache } from \"@/utils/async-cache\";\n\nexport interface MDXStoreDynamicData<Frontmatter, Attached = unknown> {\n id: string;\n frontmatter: Frontmatter;\n compile: () => Promise<CompiledMDX<Frontmatter> & Attached>;\n}\n\nlet corePromise: Promise<Core>;\n\ntype GetFrontmatter<Config, Name extends string> =\n GetCollectionConfig<Config, Name> extends MDXCollection\n ? GetCollectionConfig<Config, Name>[\"$inferFrontmatter\"]\n : never;\n\nexport async function mdxStoreDynamic<Config, Name extends string, Attached>(\n config: Config,\n coreOptions: CoreOptions,\n name: Name,\n base: string,\n _frontmatter: Record<string, unknown>,\n jsxRuntime: unknown,\n): Promise<FileCollectionStore<MDXStoreDynamicData<GetFrontmatter<Config, Name>, Attached>>> {\n corePromise ??= (async () => {\n const core = new Core(coreOptions);\n await core.init({\n config: config as Record<string, unknown>,\n });\n return core;\n })();\n const core = await corePromise;\n const frontmatter = _frontmatter as Record<string, GetFrontmatter<Config, Name>>;\n const collection = core.getCollection(name);\n if (!collection || !(collection instanceof MDXCollection))\n throw new Error(\"invalid collection name\");\n\n const merged: Record<string, MDXStoreDynamicData<GetFrontmatter<Config, Name>, Attached>> = {};\n const cache = createCache<CompiledMDX<GetFrontmatter<Config, Name>> & Attached>();\n\n for (const [k, v] of Object.entries(frontmatter)) {\n merged[k] = {\n id: k,\n frontmatter: v,\n async compile() {\n return cache.cached(k, async () => {\n const filePath = path.join(base, k);\n let content = (await fs.readFile(filePath)).toString();\n content = fumaMatter(content).content;\n\n const compiled = await buildMDX({\n core,\n collection,\n filePath,\n source: content,\n frontmatter: v as unknown as Record<string, unknown>,\n isDevelopment: false,\n environment: \"runtime\",\n compiler: {\n collection,\n core,\n addDependency() {},\n },\n });\n\n return (await executeMdx(String(compiled.value), {\n baseUrl: pathToFileURL(filePath),\n jsxRuntime,\n })) as CompiledMDX<GetFrontmatter<Config, Name>> & Attached;\n });\n },\n };\n }\n\n return new FileCollectionStore(base, merged);\n}\n\nexport type MdxContent = MDXContent;\n\ninterface Options {\n scope?: Record<string, unknown>;\n baseUrl?: string | URL;\n jsxRuntime?: unknown;\n}\n\nconst AsyncFunction: new (...args: string[]) => (...args: unknown[]) => Promise<unknown> =\n Object.getPrototypeOf(executeMdx).constructor;\n\nasync function executeMdx(compiled: string, options: Options = {}) {\n const { opts: scopeOpts, ...scope } = options.scope ?? {};\n const fullScope = {\n opts: {\n ...(scopeOpts as object),\n ...(options.jsxRuntime as object),\n baseUrl: options.baseUrl,\n },\n ...scope,\n };\n\n const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);\n return (await hydrateFn.apply(hydrateFn, Object.values(fullScope))) as {\n default: MdxContent;\n };\n}\n\nexport type { WithGit } from \"./runtime\";\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAI;AAOJ,eAAsB,gBACpB,QACA,aACA,MACA,MACA,cACA,YAC2F;AAC3F,kBAAiB,YAAY;EAC3B,MAAM,OAAO,IAAI,KAAK,YAAY;AAClC,QAAM,KAAK,KAAK,EACN,QACT,CAAC;AACF,SAAO;KACL;CACJ,MAAM,OAAO,MAAM;CACnB,MAAM,cAAc;CACpB,MAAM,aAAa,KAAK,cAAc,KAAK;AAC3C,KAAI,CAAC,cAAc,EAAE,sBAAsB,eACzC,OAAM,IAAI,MAAM,0BAA0B;CAE5C,MAAM,SAAsF,EAAE;CAC9F,MAAM,QAAQ,aAAmE;AAEjF,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,YAAY,CAC9C,QAAO,KAAK;EACV,IAAI;EACJ,aAAa;EACb,MAAM,UAAU;AACd,UAAO,MAAM,OAAO,GAAG,YAAY;IACjC,MAAM,WAAW,KAAK,KAAK,MAAM,EAAE;IACnC,IAAI,WAAW,MAAM,GAAG,SAAS,SAAS,EAAE,UAAU;AACtD,cAAU,WAAW,QAAQ,CAAC;IAE9B,MAAM,WAAW,MAAM,SAAS;KAC9B;KACA;KACA;KACA,QAAQ;KACR,aAAa;KACb,eAAe;KACf,aAAa;KACb,UAAU;MACR;MACA;MACA,gBAAgB;MACjB;KACF,CAAC;AAEF,WAAQ,MAAM,WAAW,OAAO,SAAS,MAAM,EAAE;KAC/C,SAAS,cAAc,SAAS;KAChC;KACD,CAAC;KACF;;EAEL;AAGH,QAAO,IAAI,oBAAoB,MAAM,OAAO;;AAW9C,MAAM,gBACJ,OAAO,eAAe,WAAW,CAAC;AAEpC,eAAe,WAAW,UAAkB,UAAmB,EAAE,EAAE;CACjE,MAAM,EAAE,MAAM,WAAW,GAAG,UAAU,QAAQ,SAAS,EAAE;CACzD,MAAM,YAAY;EAChB,MAAM;GACJ,GAAI;GACJ,GAAI,QAAQ;GACZ,SAAS,QAAQ;GAClB;EACD,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,cAAc,GAAG,OAAO,KAAK,UAAU,EAAE,SAAS;AACxE,QAAQ,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,UAAU,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { C as GetCollectionConfig } from "../../core-FjA_Xoho.js";
2
2
  import { FileCollectionStore } from "../runtime/file-store.js";
3
- import { t as CompiledMDX } from "../../build-mdx-DRqbcE1d.js";
3
+ import { t as CompiledMDX } from "../../build-mdx-DhXGp7I9.js";
4
4
  import { MDXCollection } from "../mdx.js";
5
5
  import { GitFileData } from "../../plugins/git.js";
6
6
 
@@ -1,10 +1,8 @@
1
1
  import { S as Awaitable, h as Pipe, m as AsyncPipe, p as CodeGenerator } from "../core-FjA_Xoho.js";
2
2
  import { Collection } from "./index.js";
3
3
  import { FileSystemCollection, FileSystemCollectionConfig } from "./fs.js";
4
- import { n as LinkReference, r as PostprocessOptions, t as CompiledMDX } from "../build-mdx-DRqbcE1d.js";
5
- import { ProcessorOptions } from "@mdx-js/mdx";
4
+ import { i as PostprocessOptions, n as FumaContentProcessorOptions, r as LinkReference, t as CompiledMDX } from "../build-mdx-DhXGp7I9.js";
6
5
  import { VFile } from "vfile";
7
- import { PluggableList } from "unified";
8
6
  import { StandardSchemaV1 } from "@standard-schema/spec";
9
7
 
10
8
  //#region src/collections/mdx.d.ts
@@ -13,17 +11,13 @@ interface CompilationContext {
13
11
  filePath: string;
14
12
  source: string;
15
13
  }
16
- interface MDXCollectionConfig<FrontmatterSchema extends StandardSchemaV1 | undefined> extends Omit<FileSystemCollectionConfig, "supportedFormats"> {
14
+ interface MDXCollectionConfig<FrontmatterSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined> extends Omit<FileSystemCollectionConfig, "supportedFormats"> {
17
15
  postprocess?: Partial<PostprocessOptions>;
18
- preprocess?: PreprocessOptions;
19
16
  frontmatter?: FrontmatterSchema;
20
- options?: (environment: "bundler" | "runtime") => Awaitable<ProcessorOptions>;
17
+ options?: FumaContentProcessorOptions | ((environment: "bundler" | "runtime") => Awaitable<FumaContentProcessorOptions>);
21
18
  lazy?: boolean;
22
19
  dynamic?: boolean;
23
20
  }
24
- interface PreprocessOptions {
25
- remarkPlugins?: PluggableList;
26
- }
27
21
  interface InitializerCode {
28
22
  fn: string;
29
23
  typeParams: [config: string, name: string, attached: string];
@@ -33,9 +27,8 @@ declare class MDXCollection<FrontmatterSchema extends StandardSchemaV1 | undefin
33
27
  #private;
34
28
  readonly dynamic: boolean;
35
29
  readonly lazy: boolean;
36
- readonly preprocess?: PreprocessOptions;
37
30
  readonly postprocess?: Partial<PostprocessOptions>;
38
- readonly getMDXOptions?: (environment: "bundler" | "runtime") => Awaitable<ProcessorOptions>;
31
+ getMDXOptions(environment: "bundler" | "runtime"): Promise<FumaContentProcessor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AAA,IAAkB,aAAA,CAAA,iBAAA"}
@@ -1,6 +1,7 @@
1
1
  import { n as pipe, t as asyncPipe } from "../pipe-CvCqOpXX.js";
2
2
  import { n as slash } from "../code-generator-CHcOrCeM.js";
3
3
  import { r as validate } from "../validation-C3kXuveD.js";
4
+ import { t as createCache } from "../async-cache-Cce8lc9D.js";
4
5
  import { loaderHook } from "../plugins/loader/index.js";
5
6
  import { FileSystemCollection } from "./fs.js";
6
7
  import { gitHook } from "../plugins/git.js";
@@ -18,9 +19,16 @@ function formatInitializer(code) {
18
19
  var MDXCollection = class extends FileSystemCollection {
19
20
  dynamic;
20
21
  lazy;
21
- preprocess;
22
22
  postprocess;
23
- getMDXOptions;
23
+ #mdxOptions;
24
+ #mdxOptionsCache;
25
+ async getMDXOptions(environment) {
26
+ const options = this.#mdxOptions;
27
+ if (!options) return {};
28
+ if (typeof options !== "function") return options;
29
+ this.#mdxOptionsCache ??= createCache();
30
+ return this.#mdxOptionsCache.cached(environment, () => options(environment));
31
+ }
24
32
  /**
25
33
  * Frontmatter schema
26
34
  */
@@ -45,8 +53,7 @@ var MDXCollection = class extends FileSystemCollection {
45
53
  supportedFormats: ["md", "mdx"]
46
54
  });
47
55
  this.postprocess = config.postprocess;
48
- this.preprocess = config.preprocess;
49
- this.getMDXOptions = config.options;
56
+ this.#mdxOptions = config.options;
50
57
  this.dynamic = config.dynamic ?? false;
51
58
  this.lazy = config.lazy ?? false;
52
59
  this.frontmatterSchema = config.frontmatter;
@@ -306,7 +313,7 @@ function mdxLoader() {
306
313
  };
307
314
  },
308
315
  async createLoader() {
309
- const { createMdxLoader } = await import("../loader-BT4fwLTJ.js").then((n) => n.n);
316
+ const { createMdxLoader } = await import("../loader-B3hZ0R4a.js").then((n) => n.n);
310
317
  return createMdxLoader({ getCore: () => this.core });
311
318
  }
312
319
  };