import S from"node:path";import{normalizeRouteSlug as v}from"../../../../utils/path/normalize-route-slug.js";import{reporter as a}from"../../../tools/notifiers/reporter.js";import{getNodeAttribute as m}from"../../../../markdoc/helpers/get-node-attribute.js";import{FileNotFoundError as u,resolveAssetPath as w,resolveSrcSet as h}from"../../../utils/index.js";import{MdResolveError as $}from"./md-resolve-error.js";import{getLinkOriginalAttrName as A}from"./utils.js";async function B(e,o,s,{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 w(t,c.fs,{fromFileRelativePath:s,contentDir:n,outdir:l});e.attributes.attrs[o]=r}catch(r){if(r instanceof u)throw new $(`File ${t} does not exist`,{rawLink:t,link:t});await a.panicOnBuild(`Cannot resolve %rp: ${r.message}`,t)}}if(o==="srcSet")try{const r=await h(i,c.fs,{fromFileRelativePath:s,contentDir:n,outdir:l});e.attributes.attrs[o]=r}catch(r){r instanceof u?await a.panicOnBuildContentError(`Cannot resolve 'srcSet' attribute: ${i}: ${r.message}`):await a.panicOnBuild(`Cannot resolve 'srcSet' attribute: ${i}: ${r.message}`)}}}export{B as resolveHtmlSourceAttribute};
