import{d as D,I as g,a4 as O,a5 as R,s as w,a6 as N,h as $,J as B,a7 as _,a8 as S,a9 as m,aa as A,ab as I,ac as V}from"./DnBXlrVC.js";import{h as v,f as L,a as U}from"./Y8sfbbmi.js";import{f as W}from"./CJ5NhiWv.js";const y="default",C=/^@|^v-on:/,x=/^:|^v-bind:/,q=/^v-model/,E=["select","textarea","input"],K=Object.fromEntries(["p","a","blockquote","code","pre","code","em","h1","h2","h3","h4","h5","h6","hr","img","ul","ol","li","strong","table","thead","tbody","td","th","tr","script"].map(t=>[t,`prose-${t}`])),nt=D({name:"MDCRenderer",props:{body:{type:Object,required:!0},data:{type:Object,default:()=>({})},class:{type:[String,Object],default:void 0},tag:{type:[String,Boolean],default:void 0},prose:{type:Boolean,default:void 0},components:{type:Object,default:()=>({})},unwrap:{type:[Boolean,String],default:!1}},async setup(t){const n=O()?.appContext?.app?.$nuxt,e=n?.$route||n?._route,{mdc:o}=n?.$config?.public||{},r={...o?.components?.prose&&t.prose!==!1?K:{},...o?.components?.map||{},...R(t.data?.mdc?.components||{}),...t.components},s=w(()=>{const a=(t.body?.children||[]).map(c=>c.tag||c.type).filter(c=>!v.includes(c));return Array.from(new Set(a)).sort().join(".")}),u=N({...t.data});$(()=>t.data,a=>{Object.assign(u,a)}),await M(t.body,{tags:r});function i(a,c){const p=a.split(".").length-1;return a.split(".").reduce((l,f,T)=>T==p&&l?(l[f]=c,l[f]):typeof l=="object"?l[f]:void 0,u)}return{tags:r,contentKey:s,route:e,runtimeData:u,updateRuntimeData:i}},render(t){const{tags:n,tag:e,body:o,data:r,contentKey:s,route:u,unwrap:i,runtimeData:a,updateRuntimeData:c}=t;if(!o)return null;const p={...r,tags:n,$route:u,runtimeData:a,updateRuntimeData:c},l=e!==!1?b(e||p.component?.name||p.component||"div"):void 0;return l?g(l,{...p.component?.props,class:t.class,...this.$attrs,key:s},{default:f}):f?.();function f(){return i?W(h(o,g,p,p).default(),typeof i=="string"?i.split(" "):["*"]):h(o,g,p,p).default()}}});function P(t,n,e,o={}){if(t.type==="text")return n(m,t.value);if(t.type==="comment")return n(A,null,t.value);const r=t.tag,s=j(t,e.tags);if(t.tag==="binding")return F(t,n,e,o);const u=b(s);typeof u=="object"&&(u.tag=r);const i=J(t,e);return n(u,i,h(t,n,e,{...o,...i}))}function F(t,n,e,o={}){const r={...e.runtimeData,...o,$document:e,$doc:e},s=/\.|\[(\d+)\]/,i=(t.props?.value.trim().split(s).filter(Boolean)).reduce((c,p)=>{if(c&&p in c)return typeof c[p]=="function"?c[p]():c[p]},r),a=t.props?.defaultValue;return n(m,i??a??"")}function h(t,n,e,o){const s=(t.children||[]).reduce((i,a)=>{if(!Y(a))return i[y].push(a),i;const c=X(a);return i[c]=i[c]||[],a.type==="element"&&i[c].push(...a.children||[]),i},{[y]:[]});return Object.entries(s).reduce((i,[a,c])=>(c.length&&(i[a]=()=>{const p=c.map(l=>P(l,n,e,o));return Z(p)}),i),{})}function J(t,n){const{tag:e="",props:o={}}=t;return Object.keys(o).reduce(function(r,s){if(s==="__ignoreMap")return r;const u=o[s];if(q.test(s))return z(s,u,r,n,{native:E.includes(e)});if(s==="v-bind")return G(s,u,r,n);if(C.test(s))return H(s,u,r,n);if(x.test(s))return Q(s,u,r,n);const{attribute:i}=L(U,s);return Array.isArray(u)&&u.every(a=>typeof a=="string")?(r[i]=u.join(" "),r):(r[i]=u,r)},{})}function z(t,n,e,o,{native:r}){const s=t.match(/^v-model:([^=]+)/)?.[1]||"modelValue",u=r?"value":s,i=r?"onInput":`onUpdate:${s}`;return e[u]=d(n,o.runtimeData),e[i]=a=>{o.updateRuntimeData(n,r?a.target?.value:a)},e}function G(t,n,e,o){const r=d(n,o);return e=Object.assign(e,r),e}function H(t,n,e,o){return t=t.replace(C,""),e.on=e.on||{},e.on[t]=()=>d(n,o),e}function Q(t,n,e,o){return t=t.replace(x,""),e[t]=d(n,o),e}const b=t=>{if(typeof t=="string"){if(v.includes(t))return t;const n=B(_(t),!1);return!t||n?.name==="AsyncComponentWrapper"||typeof n=="string"?n:"setup"in n?S(()=>new Promise(e=>e(n))):n}return t};function d(t,n){const e=t.split(".").reduce((o,r)=>typeof o=="object"?o[r]:void 0,n);return typeof e>"u"?V(t):e}function X(t){let n="";for(const e of Object.keys(t.props||{}))if(!(!e.startsWith("#")&&!e.startsWith("v-slot:"))){n=e.split(/[:#]/,2)[1];break}return n||y}function Y(t){return t.tag==="template"}function Z(t){const n=[];for(const e of t){const o=n[n.length-1];e.type===m&&o?.type===m?o.children=o.children+e.children:n.push(e)}return n}async function M(t,n){if(!t)return;const e=Array.from(new Set(o(t,n)));await Promise.all(e.map(async r=>{if(r?.render||r?.ssrRender||r?.__ssrInlineRender)return;const s=b(r);s?.__asyncLoader&&!s.__asyncResolved&&await s.__asyncLoader()}));function o(r,s){const u=r.tag;if(r.type==="text"||u==="binding"||r.type==="comment")return[];const i=j(r,s.tags),a=[];r.type!=="root"&&!v.includes(i)&&a.push(i);for(const c of r.children||[])a.push(...o(c,s));return a}}function j(t,n){const e=t.tag;return!e||typeof t.props?.__ignoreMap<"u"?e:n[e]||n[_(e)]||n[I(t.tag)]||e}export{nt as _};
