import u from"@markdoc/markdoc";import{isTag as b}from"./markdoc/helpers/guards/is-tag.js";import{slugger as g}from"../../utils/index.js";import{getMarkdocOptions as l}from"./markdoc/markdoc-options.js";import{visit as h,getHeadingData as k}from"./markdoc/plugins/utils.js";import{renderMermaid as v}from"./markdoc/plugins/render-mermaid.js";import{deepStringify as M}from"./markdoc/utils/deep-stringify.js";import{stringifyTagChildrenObjects as w}from"./utils/stringify-tag-children-objects.js";async function _(d,e,p){const c=await l(p),t=[],a=[],i=M(e.variables?.pageProps),{headers:y,...f}=e.variables||{};g.reset();const s=u.transform(d,{...c,...e,variables:{...f,pageProps:i}});let o=0;h(s,r=>{if(b(r)){switch(r.name){case"Heading":r.attributes.__idx=o,o++;const n=k(r);n&&t.push(n);break;case"Mermaid":a.push({tag:r,source:r.attributes.diagramSource});break}w(r)}});const m=await v(a.map(r=>r.source));for(let r=0;r<m.length;r++)a[r].tag.attributes.diagramHtml=m[r];return{headings:t,renderableAst:s,pageProps:i}}export{_ as transformMdAst};
