import S from"node:path";import{getNodeAttribute as m}from"../../../../shared/markdoc.js";import{normalizeRouteSlug as v}from"../../../../shared/utils.js";import{FileNotFoundError as u,resolveAssetPath as h,resolveSrcSet as $}from"../../../utils/index.js";import{MdResolveError as w}from"./md-resolve-error.js";import{getLinkOriginalAttrName as A}from"./utils.js";import{reporter as s}from"../../../utils/reporter/reporter.js";async function B(e,o,a,{actions:{contentDir:n,outdir:l,getRouteBySlug:p},context:c}){const i=m(e,"attrs")?.[o],g=m(e,"name");if(!i)return;const f=A(o),t=e[f]||i;if(!(g==="iframe"&&p(v(t)))){if(e[f]=t,o==="src"){if(!S.extname(t))return;try{const r=await h(t,c.fs,{fromFileRelativePath:a,contentDir:n,outdir:l});e.attributes.attrs[o]=r}catch(r){if(r instanceof u)throw new w(`File ${t} does not exist`,{rawLink:t,link:t});s.panicOnBuild(`Cannot resolve %rp: ${r.message}`,t)}}if(o==="srcSet")try{const r=await $(i,c.fs,{fromFileRelativePath:a,contentDir:n,outdir:l});e.attributes.attrs[o]=r}catch(r){r instanceof u?s.panicOnBuildContentError(`Cannot resolve 'srcSet' attribute: ${i}: ${r.message}`):s.panicOnBuild(`Cannot resolve 'srcSet' attribute: ${i}: ${r.message}`)}}}export{B as resolveHtmlSourceAttribute};
