@docubook/core 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cn as e, formatDate as t, formatDate2 as n, parseDate as r, stringToDate as i, toIsoDateOnly as a } from "./utils.js";
|
|
2
|
-
import { t as o } from "./serialize-
|
|
2
|
+
import { t as o } from "./serialize-JlIIwThu.js";
|
|
3
3
|
import { compileSync as s } from "@mdx-js/mdx";
|
|
4
4
|
import { visit as c } from "unist-util-visit";
|
|
5
5
|
import l from "remark-gfm";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../serialize-
|
|
1
|
+
import { t as e } from "../serialize-JlIIwThu.js";
|
|
2
2
|
export { e as serialize };
|
|
@@ -74,7 +74,7 @@ function p(e = {}, t = !1, n = !0, r = "function-body", i = "mdx") {
|
|
|
74
74
|
format: i,
|
|
75
75
|
outputFormat: r,
|
|
76
76
|
providerImportSource: t ? void 0 : "@mdx-js/react",
|
|
77
|
-
development: process.env.NODE_ENV !== "production"
|
|
77
|
+
development: r !== "program" && process.env.NODE_ENV !== "production"
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
async function m(r, { scope: i = {}, mdxOptions: a = {}, parseFrontmatter: s = !1, blockJS: c = !0, outputFormat: l = "function-body", format: u = "mdx" } = {}, d = !1) {
|
|
@@ -95,4 +95,4 @@ async function m(r, { scope: i = {}, mdxOptions: a = {}, parseFrontmatter: s = !
|
|
|
95
95
|
//#endregion
|
|
96
96
|
export { m as t };
|
|
97
97
|
|
|
98
|
-
//# sourceMappingURL=serialize-
|
|
98
|
+
//# sourceMappingURL=serialize-JlIIwThu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-DEuXE4Xm.js","names":[],"sources":["../src/mdx-compiler/format-mdx-error.ts","../src/mdx-compiler/plugins/remove-imports-exports.ts","../src/mdx-compiler/plugins/remove-javascript-expressions.ts","../src/mdx-compiler/plugins/remove-dangerous-javascript-expressions.ts","../src/mdx-compiler/serialize.ts"],"sourcesContent":["// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\n/**\n * Wraps raw MDX compilation errors with a clear message prefix.\n */\nexport function createFormattedMDXError(error: any, _source: string): Error {\n return new Error(`[mdx] error compiling MDX:\\n${error?.message ?? error}`);\n}\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { remove } from \"unist-util-remove\";\nimport type { Node } from \"unist\";\n\n/** remark plugin: strips all `mdxjsEsm` nodes (import/export statements). */\nexport function removeImportsExportsPlugin() {\n return (tree: Node) => remove(tree, \"mdxjsEsm\");\n}\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { visit, SKIP } from \"unist-util-visit\";\nimport type { Node } from \"unist\";\n\n/**\n * remark plugin: removes JS expression nodes ({variable}, {func()}) from MDX.\n * Preserves JSX (<Component />) and plain markdown.\n */\nexport const removeJavaScriptExpressions = () => {\n return (tree: Node) => {\n visit(tree, (node: Node, index: number | undefined, parent: Node | undefined) => {\n if (node.type === \"mdxFlowExpression\" || node.type === \"mdxTextExpression\") {\n if (parent && typeof index === \"number\") {\n (parent as any).children.splice(index, 1);\n return [SKIP, index] as const;\n }\n }\n\n if (node.type === \"mdxJsxFlowElement\" || node.type === \"mdxJsxTextElement\") {\n const el = node as any;\n if (el.attributes) {\n el.attributes = el.attributes.filter((attr: any) => {\n if (attr.type === \"mdxJsxAttribute\") {\n return (\n attr.value === null ||\n typeof attr.value === \"string\" ||\n (attr.value && attr.value.type !== \"mdxJsxAttributeValueExpression\")\n );\n }\n return attr.type !== \"mdxJsxExpressionAttribute\";\n });\n }\n }\n });\n };\n};\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport type { Node } from \"unist\";\n\nconst BLOCKED_GLOBALS = [\n // Code execution\n \"eval\",\n \"Function\",\n \"AsyncFunction\",\n \"GeneratorFunction\",\n // Module system\n \"require\",\n \"module\",\n \"exports\",\n \"__dirname\",\n \"__filename\",\n // Runtime\n \"process\",\n \"global\",\n \"globalThis\",\n \"Reflect\",\n // File system / network\n \"child_process\",\n \"fs\",\n \"net\",\n \"http\",\n \"https\",\n \"vm\",\n \"worker_threads\",\n // Browser-like (available in Node/Deno)\n \"fetch\",\n \"setTimeout\",\n \"setInterval\",\n \"setImmediate\",\n \"queueMicrotask\",\n \"XMLHttpRequest\",\n];\n\nconst BLOCKED_PROPERTIES = [\n \"constructor\",\n \"prototype\",\n \"__proto__\",\n \"eval\",\n \"Reflect\",\n \"Function\",\n \"AsyncFunction\",\n \"GeneratorFunction\",\n \"require\",\n];\n\nfunction walk(node: any, blockedGlobals: string[], blockedProperties: string[]) {\n if (!node || typeof node !== \"object\") return;\n\n if (node.type === \"Identifier\" && blockedGlobals.includes(node.name)) {\n const parent = node.parent;\n const isProperty =\n parent?.type === \"MemberExpression\" && parent.property === node && !parent.computed;\n const isParam = parent?.type === \"FunctionDeclaration\" || parent?.type === \"FunctionExpression\";\n if (!isProperty && !isParam) {\n throw new Error(`Security: Access to '${node.name}' is not allowed`);\n }\n }\n\n // Block direct calls to blocked globals: eval(), Function(), fetch(), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"Identifier\" &&\n blockedGlobals.includes(node.callee.name)\n ) {\n throw new Error(`Security: ${node.callee.name}() calls are not allowed`);\n }\n\n // Block dynamic import(): import(\"node:fs\")\n if (node.type === \"ImportExpression\") {\n throw new Error(\"Security: Dynamic import() is not allowed\");\n }\n\n // Block tagged template literals on blocked globals: eval`...`\n if (\n node.type === \"TaggedTemplateExpression\" &&\n node.tag?.type === \"Identifier\" &&\n blockedGlobals.includes(node.tag.name)\n ) {\n throw new Error(`Security: ${node.tag.name}\\`...\\` tagged template is not allowed`);\n }\n\n // Block computed MemberExpression calls on any object identifier\n // Catches: Object[\"constructor\"](...), Object[\"con\"+\"structor\"](...), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.computed\n ) {\n throw new Error(\"Security: Function calls via computed property access are not allowed\");\n }\n\n // Block non-computed property access to dangerous properties:\n // obj.constructor, obj.prototype, obj.__proto__\n if (node.type === \"MemberExpression\" && !node.computed) {\n const prop = node.property;\n if (prop?.type === \"Identifier\" && blockedProperties.includes(prop.name)) {\n throw new Error(`Security: .${prop.name} access is not allowed`);\n }\n }\n\n // Block new expressions: new Function(...)\n if (\n node.type === \"NewExpression\" &&\n node.callee?.type === \"Identifier\" &&\n blockedGlobals.includes(node.callee.name)\n ) {\n throw new Error(`Security: new ${node.callee.name}() is not allowed`);\n }\n\n for (const key in node) {\n if (key === \"parent\" || key === \"position\") continue;\n const value = node[key];\n if (Array.isArray(value)) {\n value.forEach((child: any) => {\n if (child && typeof child === \"object\") walk(child, blockedGlobals, blockedProperties);\n });\n } else if (value && typeof value === \"object\") {\n walk(value, blockedGlobals, blockedProperties);\n }\n }\n}\n\nexport const CreateRemoveDangerousCallsPlugin = (\n blockedGlobals?: string[],\n blockedProperties?: string[]\n) => {\n return () => (tree: Node) => {\n walk(tree, blockedGlobals ?? BLOCKED_GLOBALS, blockedProperties ?? BLOCKED_PROPERTIES);\n return tree;\n };\n};\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { compile } from \"@mdx-js/mdx\";\nimport { VFile } from \"vfile\";\nimport { matter } from \"vfile-matter\";\nimport { createFormattedMDXError } from \"./format-mdx-error.js\";\nimport { removeImportsExportsPlugin } from \"./plugins/remove-imports-exports.js\";\nimport { removeJavaScriptExpressions } from \"./plugins/remove-javascript-expressions.js\";\nimport { CreateRemoveDangerousCallsPlugin } from \"./plugins/remove-dangerous-javascript-expressions.js\";\nimport type { Pluggable } from \"unified\";\n\n/** @internal — re-exported from unified. */\ntype RemarkPlugins = Pluggable[];\ntype RehypePlugins = Pluggable[];\n\nexport type { MDXRemoteSerializeResult } from \"./types\";\n\nexport type SerializeOptions = {\n scope?: Record<string, unknown>;\n mdxOptions?: {\n remarkPlugins?: RemarkPlugins;\n rehypePlugins?: RehypePlugins;\n };\n parseFrontmatter?: boolean;\n /**\n * MDX compile output shape.\n * - `\"function-body\"` (default): JS function body string for `<MDXRemote>`.\n * - `\"program\"`: full ESM module source (imports + `export default MDXContent`)\n * for static bundling / hydration without `new Function`.\n * @default \"function-body\"\n */\n outputFormat?: \"function-body\" | \"program\";\n /**\n * MDX input format.\n * - `\"mdx\"` (default): JSX tags are parsed and resolve via the components map.\n * - `\"md\"`: plain markdown — authored JSX tags are NOT parsed (dropped,\n * content kept as text). Markdown directives (`:::`/`::`/`::::`) still\n * work; this is the v2 authoring contract (no JSX tags).\n * @default \"mdx\"\n */\n format?: \"mdx\" | \"md\";\n /**\n * Strip JavaScript expressions from MDX (default: true).\n * When true, removes all `{expression}` and JSX attribute expression nodes\n * before compilation. When false, expressions are preserved but a\n * security sanitizer audits the AST for dangerous patterns.\n * @default true\n */\n blockJS?: boolean;\n};\n\nexport type SerializeResult = {\n compiledSource: string;\n frontmatter: Record<string, unknown>;\n scope: Record<string, unknown>;\n};\n\nfunction getCompileOptions(\n mdxOptions: SerializeOptions[\"mdxOptions\"] = {},\n rsc = false,\n blockJS = true,\n outputFormat: NonNullable<SerializeOptions[\"outputFormat\"]> = \"function-body\",\n format: NonNullable<SerializeOptions[\"format\"]> = \"mdx\"\n) {\n const remarkPlugins = [\n ...(mdxOptions?.remarkPlugins ?? []),\n removeImportsExportsPlugin,\n ...(blockJS ? [removeJavaScriptExpressions] : []),\n // Defense-in-depth: audit remaining AST for dangerous patterns.\n CreateRemoveDangerousCallsPlugin(),\n ];\n\n return {\n ...mdxOptions,\n remarkPlugins,\n rehypePlugins: mdxOptions?.rehypePlugins ?? [],\n format,\n outputFormat,\n providerImportSource: rsc ? undefined : \"@mdx-js/react\",\n development: process.env.NODE_ENV !== \"production\",\n };\n}\n\n/**\n * Compile raw MDX string into a serialized result that can be rendered.\n */\nexport async function serialize(\n source: string,\n {\n scope = {},\n mdxOptions = {},\n parseFrontmatter = false,\n blockJS = true,\n outputFormat = \"function-body\",\n format = \"mdx\",\n }: SerializeOptions = {},\n rsc = false\n): Promise<SerializeResult> {\n const vfile = new VFile(source);\n\n if (parseFrontmatter) {\n matter(vfile, { strip: true });\n }\n\n let compiledSource: string;\n try {\n compiledSource = String(\n await compile(vfile, getCompileOptions(mdxOptions, rsc, blockJS, outputFormat, format))\n );\n } catch (error: any) {\n throw createFormattedMDXError(error, String(vfile));\n }\n\n return {\n compiledSource,\n frontmatter: (vfile.data.matter ?? {}) as Record<string, unknown>,\n scope,\n };\n}\n"],"mappings":";;;;;;AAIA,SAAgB,EAAwB,GAAY,GAAwB;CAC1E,OAAO,gBAAI,MAAM,+BAA+B,GAAO,WAAW,GAAO;AAC3E;;;ACDA,SAAgB,IAA6B;CAC3C,QAAQ,MAAe,EAAO,GAAM,UAAU;AAChD;;;ACCA,IAAa,WACH,MAAe;CACrB,EAAM,IAAO,GAAY,GAA2B,MAA6B;EAC/E,KAAI,EAAK,SAAS,uBAAuB,EAAK,SAAS,wBACjD,KAAU,OAAO,KAAU,UAE7B,OADA,EAAgB,SAAS,OAAO,GAAO,CAAC,GACjC,CAAC,GAAM,CAAK;EAIvB,IAAI,EAAK,SAAS,uBAAuB,EAAK,SAAS,qBAAqB;GAC1E,IAAM,IAAK;GACX,AACE,EAAG,eAAa,EAAG,WAAW,QAAQ,MAChC,EAAK,SAAS,oBAEd,EAAK,UAAU,QACf,OAAO,EAAK,SAAU,YACrB,EAAK,SAAS,EAAK,MAAM,SAAS,mCAGhC,EAAK,SAAS,2BACtB;EAEL;CACF,CAAC;AACH,GC/BI,IAAkB,iRAgCxB,GAEM,IAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,EAAK,GAAW,GAA0B,GAA6B;CAC1E,OAAC,KAAQ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EAAK,GAAO,GAAgB,CAAiB;GACvF,CAAC,IACQ,KAAS,OAAO,KAAU,YACnC,EAAK,GAAO,GAAgB,CAAiB;EAEjD;CA/DA;AAgEF;AAEA,IAAa,KACX,GACA,aAEc,OACZ,EAAK,GAAM,KAAkB,GAAiB,KAAqB,CAAkB,GAC9E;;;AC5EX,SAAS,EACP,IAA6C,CAAC,GAC9C,IAAM,IACN,IAAU,IACV,IAA8D,iBAC9D,IAAkD,OAClD;CACA,IAAM,IAAgB;EACpB,GAAI,GAAY,iBAAiB,CAAC;EAClC;EACA,GAAI,IAAU,CAAC,CAA2B,IAAI,CAAC;EAE/C,EAAiC;CACnC;CAEA,OAAO;EACL,GAAG;EACH;EACA,eAAe,GAAY,iBAAiB,CAAC;EAC7C;EACA;EACA,sBAAsB,IAAM,KAAA,IAAY;EACxC,aAAA,QAAA,IAAA,aAAsC;CACxC;AACF;AAKA,eAAsB,EACpB,GACA,EACE,WAAQ,CAAC,GACT,gBAAa,CAAC,GACd,sBAAmB,IACnB,aAAU,IACV,kBAAe,iBACf,YAAS,UACW,CAAC,GACvB,IAAM,IACoB;CAC1B,IAAM,IAAQ,IAAI,EAAM,CAAM;CAE9B,AAAI,KACF,EAAO,GAAO,EAAE,OAAO,GAAK,CAAC;CAG/B,IAAI;CACJ,IAAI;EACF,IAAiB,OACf,MAAM,EAAQ,GAAO,EAAkB,GAAY,GAAK,GAAS,GAAc,CAAM,CAAC,CACxF;CACF,SAAS,GAAY;EACnB,MAAM,EAAwB,GAAO,OAAO,CAAK,CAAC;CACpD;CAEA,OAAO;EACL;EACA,aAAc,EAAM,KAAK,UAAU,CAAC;EACpC;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"serialize-JlIIwThu.js","names":[],"sources":["../src/mdx-compiler/format-mdx-error.ts","../src/mdx-compiler/plugins/remove-imports-exports.ts","../src/mdx-compiler/plugins/remove-javascript-expressions.ts","../src/mdx-compiler/plugins/remove-dangerous-javascript-expressions.ts","../src/mdx-compiler/serialize.ts"],"sourcesContent":["// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\n/**\n * Wraps raw MDX compilation errors with a clear message prefix.\n */\nexport function createFormattedMDXError(error: any, _source: string): Error {\n return new Error(`[mdx] error compiling MDX:\\n${error?.message ?? error}`);\n}\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { remove } from \"unist-util-remove\";\nimport type { Node } from \"unist\";\n\n/** remark plugin: strips all `mdxjsEsm` nodes (import/export statements). */\nexport function removeImportsExportsPlugin() {\n return (tree: Node) => remove(tree, \"mdxjsEsm\");\n}\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { visit, SKIP } from \"unist-util-visit\";\nimport type { Node } from \"unist\";\n\n/**\n * remark plugin: removes JS expression nodes ({variable}, {func()}) from MDX.\n * Preserves JSX (<Component />) and plain markdown.\n */\nexport const removeJavaScriptExpressions = () => {\n return (tree: Node) => {\n visit(tree, (node: Node, index: number | undefined, parent: Node | undefined) => {\n if (node.type === \"mdxFlowExpression\" || node.type === \"mdxTextExpression\") {\n if (parent && typeof index === \"number\") {\n (parent as any).children.splice(index, 1);\n return [SKIP, index] as const;\n }\n }\n\n if (node.type === \"mdxJsxFlowElement\" || node.type === \"mdxJsxTextElement\") {\n const el = node as any;\n if (el.attributes) {\n el.attributes = el.attributes.filter((attr: any) => {\n if (attr.type === \"mdxJsxAttribute\") {\n return (\n attr.value === null ||\n typeof attr.value === \"string\" ||\n (attr.value && attr.value.type !== \"mdxJsxAttributeValueExpression\")\n );\n }\n return attr.type !== \"mdxJsxExpressionAttribute\";\n });\n }\n }\n });\n };\n};\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport type { Node } from \"unist\";\n\nconst BLOCKED_GLOBALS = [\n // Code execution\n \"eval\",\n \"Function\",\n \"AsyncFunction\",\n \"GeneratorFunction\",\n // Module system\n \"require\",\n \"module\",\n \"exports\",\n \"__dirname\",\n \"__filename\",\n // Runtime\n \"process\",\n \"global\",\n \"globalThis\",\n \"Reflect\",\n // File system / network\n \"child_process\",\n \"fs\",\n \"net\",\n \"http\",\n \"https\",\n \"vm\",\n \"worker_threads\",\n // Browser-like (available in Node/Deno)\n \"fetch\",\n \"setTimeout\",\n \"setInterval\",\n \"setImmediate\",\n \"queueMicrotask\",\n \"XMLHttpRequest\",\n];\n\nconst BLOCKED_PROPERTIES = [\n \"constructor\",\n \"prototype\",\n \"__proto__\",\n \"eval\",\n \"Reflect\",\n \"Function\",\n \"AsyncFunction\",\n \"GeneratorFunction\",\n \"require\",\n];\n\nfunction walk(node: any, blockedGlobals: string[], blockedProperties: string[]) {\n if (!node || typeof node !== \"object\") return;\n\n if (node.type === \"Identifier\" && blockedGlobals.includes(node.name)) {\n const parent = node.parent;\n const isProperty =\n parent?.type === \"MemberExpression\" && parent.property === node && !parent.computed;\n const isParam = parent?.type === \"FunctionDeclaration\" || parent?.type === \"FunctionExpression\";\n if (!isProperty && !isParam) {\n throw new Error(`Security: Access to '${node.name}' is not allowed`);\n }\n }\n\n // Block direct calls to blocked globals: eval(), Function(), fetch(), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"Identifier\" &&\n blockedGlobals.includes(node.callee.name)\n ) {\n throw new Error(`Security: ${node.callee.name}() calls are not allowed`);\n }\n\n // Block dynamic import(): import(\"node:fs\")\n if (node.type === \"ImportExpression\") {\n throw new Error(\"Security: Dynamic import() is not allowed\");\n }\n\n // Block tagged template literals on blocked globals: eval`...`\n if (\n node.type === \"TaggedTemplateExpression\" &&\n node.tag?.type === \"Identifier\" &&\n blockedGlobals.includes(node.tag.name)\n ) {\n throw new Error(`Security: ${node.tag.name}\\`...\\` tagged template is not allowed`);\n }\n\n // Block computed MemberExpression calls on any object identifier\n // Catches: Object[\"constructor\"](...), Object[\"con\"+\"structor\"](...), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.computed\n ) {\n throw new Error(\"Security: Function calls via computed property access are not allowed\");\n }\n\n // Block non-computed property access to dangerous properties:\n // obj.constructor, obj.prototype, obj.__proto__\n if (node.type === \"MemberExpression\" && !node.computed) {\n const prop = node.property;\n if (prop?.type === \"Identifier\" && blockedProperties.includes(prop.name)) {\n throw new Error(`Security: .${prop.name} access is not allowed`);\n }\n }\n\n // Block new expressions: new Function(...)\n if (\n node.type === \"NewExpression\" &&\n node.callee?.type === \"Identifier\" &&\n blockedGlobals.includes(node.callee.name)\n ) {\n throw new Error(`Security: new ${node.callee.name}() is not allowed`);\n }\n\n for (const key in node) {\n if (key === \"parent\" || key === \"position\") continue;\n const value = node[key];\n if (Array.isArray(value)) {\n value.forEach((child: any) => {\n if (child && typeof child === \"object\") walk(child, blockedGlobals, blockedProperties);\n });\n } else if (value && typeof value === \"object\") {\n walk(value, blockedGlobals, blockedProperties);\n }\n }\n}\n\nexport const CreateRemoveDangerousCallsPlugin = (\n blockedGlobals?: string[],\n blockedProperties?: string[]\n) => {\n return () => (tree: Node) => {\n walk(tree, blockedGlobals ?? BLOCKED_GLOBALS, blockedProperties ?? BLOCKED_PROPERTIES);\n return tree;\n };\n};\n","// MPL-2.0 — derived from next-mdx-remote (IBM). See LICENSE-MPL-2.0.\nimport { compile } from \"@mdx-js/mdx\";\nimport { VFile } from \"vfile\";\nimport { matter } from \"vfile-matter\";\nimport { createFormattedMDXError } from \"./format-mdx-error.js\";\nimport { removeImportsExportsPlugin } from \"./plugins/remove-imports-exports.js\";\nimport { removeJavaScriptExpressions } from \"./plugins/remove-javascript-expressions.js\";\nimport { CreateRemoveDangerousCallsPlugin } from \"./plugins/remove-dangerous-javascript-expressions.js\";\nimport type { Pluggable } from \"unified\";\n\n/** @internal — re-exported from unified. */\ntype RemarkPlugins = Pluggable[];\ntype RehypePlugins = Pluggable[];\n\nexport type { MDXRemoteSerializeResult } from \"./types\";\n\nexport type SerializeOptions = {\n scope?: Record<string, unknown>;\n mdxOptions?: {\n remarkPlugins?: RemarkPlugins;\n rehypePlugins?: RehypePlugins;\n };\n parseFrontmatter?: boolean;\n /**\n * MDX compile output shape.\n * - `\"function-body\"` (default): JS function body string for `<MDXRemote>`.\n * - `\"program\"`: full ESM module source (imports + `export default MDXContent`)\n * for static bundling / hydration without `new Function`.\n * @default \"function-body\"\n */\n outputFormat?: \"function-body\" | \"program\";\n /**\n * MDX input format.\n * - `\"mdx\"` (default): JSX tags are parsed and resolve via the components map.\n * - `\"md\"`: plain markdown — authored JSX tags are NOT parsed (dropped,\n * content kept as text). Markdown directives (`:::`/`::`/`::::`) still\n * work; this is the v2 authoring contract (no JSX tags).\n * @default \"mdx\"\n */\n format?: \"mdx\" | \"md\";\n /**\n * Strip JavaScript expressions from MDX (default: true).\n * When true, removes all `{expression}` and JSX attribute expression nodes\n * before compilation. When false, expressions are preserved but a\n * security sanitizer audits the AST for dangerous patterns.\n * @default true\n */\n blockJS?: boolean;\n};\n\nexport type SerializeResult = {\n compiledSource: string;\n frontmatter: Record<string, unknown>;\n scope: Record<string, unknown>;\n};\n\nfunction getCompileOptions(\n mdxOptions: SerializeOptions[\"mdxOptions\"] = {},\n rsc = false,\n blockJS = true,\n outputFormat: NonNullable<SerializeOptions[\"outputFormat\"]> = \"function-body\",\n format: NonNullable<SerializeOptions[\"format\"]> = \"mdx\"\n) {\n const remarkPlugins = [\n ...(mdxOptions?.remarkPlugins ?? []),\n removeImportsExportsPlugin,\n ...(blockJS ? [removeJavaScriptExpressions] : []),\n // Defense-in-depth: audit remaining AST for dangerous patterns.\n CreateRemoveDangerousCallsPlugin(),\n ];\n\n return {\n ...mdxOptions,\n remarkPlugins,\n rehypePlugins: mdxOptions?.rehypePlugins ?? [],\n format,\n outputFormat,\n providerImportSource: rsc ? undefined : \"@mdx-js/react\",\n // Program output is bundled for the browser and must always use the\n // production JSX runtime. Deploy builds can run under Bun, Node, or Deno,\n // and dev JSX makes virtual MDX modules fragile in Vite/Rolldown.\n development: outputFormat !== \"program\" && process.env.NODE_ENV !== \"production\",\n };\n}\n\n/**\n * Compile raw MDX string into a serialized result that can be rendered.\n */\nexport async function serialize(\n source: string,\n {\n scope = {},\n mdxOptions = {},\n parseFrontmatter = false,\n blockJS = true,\n outputFormat = \"function-body\",\n format = \"mdx\",\n }: SerializeOptions = {},\n rsc = false\n): Promise<SerializeResult> {\n const vfile = new VFile(source);\n\n if (parseFrontmatter) {\n matter(vfile, { strip: true });\n }\n\n let compiledSource: string;\n try {\n compiledSource = String(\n await compile(vfile, getCompileOptions(mdxOptions, rsc, blockJS, outputFormat, format))\n );\n } catch (error: any) {\n throw createFormattedMDXError(error, String(vfile));\n }\n\n return {\n compiledSource,\n frontmatter: (vfile.data.matter ?? {}) as Record<string, unknown>,\n scope,\n };\n}\n"],"mappings":";;;;;;AAIA,SAAgB,EAAwB,GAAY,GAAwB;CAC1E,OAAO,gBAAI,MAAM,+BAA+B,GAAO,WAAW,GAAO;AAC3E;;;ACDA,SAAgB,IAA6B;CAC3C,QAAQ,MAAe,EAAO,GAAM,UAAU;AAChD;;;ACCA,IAAa,WACH,MAAe;CACrB,EAAM,IAAO,GAAY,GAA2B,MAA6B;EAC/E,KAAI,EAAK,SAAS,uBAAuB,EAAK,SAAS,wBACjD,KAAU,OAAO,KAAU,UAE7B,OADA,EAAgB,SAAS,OAAO,GAAO,CAAC,GACjC,CAAC,GAAM,CAAK;EAIvB,IAAI,EAAK,SAAS,uBAAuB,EAAK,SAAS,qBAAqB;GAC1E,IAAM,IAAK;GACX,AACE,EAAG,eAAa,EAAG,WAAW,QAAQ,MAChC,EAAK,SAAS,oBAEd,EAAK,UAAU,QACf,OAAO,EAAK,SAAU,YACrB,EAAK,SAAS,EAAK,MAAM,SAAS,mCAGhC,EAAK,SAAS,2BACtB;EAEL;CACF,CAAC;AACH,GC/BI,IAAkB,iRAgCxB,GAEM,IAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,EAAK,GAAW,GAA0B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