import{xn as e}from"./CaODJcyn.js";import{r as t}from"./aTmK00sy.js";var n=new Set([`og:image`,`og:image:url`,`og:image:secure_url`,`twitter:image`,`twitter:image:src`]),r=new Set([...n,`og:url`,`og:video`,`og:video:url`,`og:audio`,`og:audio:url`]),i=new Set([`icon`,`apple-touch-icon`,`apple-touch-icon-precomposed`]),a=/\.(?:png|jpe?g|gif|svg|ico|webp|avif)(?:\?.*)?$/i,o=6e4,s=new Map,c=e(new Map),l=e(new Set);function u(){c.value=new Map(c.value)}function d(){l.value=new Set(l.value)}function f(e){return c.value.has(e)}function p(e){let t=[];for(let n of e){let e=n.dedupeKey||void 0;if(n.tag===`meta`){let i=n.props?.property||n.props?.name||``;r.has(i)&&n.props?.content?.startsWith(`http`)&&t.push({url:n.props.content,tag:n.tag,identifier:i,tagDedupeKey:e})}(n.tag===`link`&&n.props?.href?.startsWith(`http`)||n.tag===`link`&&n.props?.href&&!n.props.href.startsWith(`http`)&&(i.has(n.props.rel||``)||a.test(n.props.href)))&&t.push({url:n.props.href,tag:n.tag,identifier:n.props.rel||`link`,tagDedupeKey:e}),n.tag===`script`&&n.props?.src?.startsWith(`http`)&&t.push({url:n.props.src,tag:n.tag,identifier:`src`,tagDedupeKey:e})}return t}async function m(e,r){if(typeof window>`u`)return`unknown`;let o=t(e);if(n.has(r)||i.has(r)||a.test(o))return new Promise(e=>{let t=new Image;t.onload=()=>e(`ok`),t.onerror=()=>e(`broken`),t.src=o});if(new URL(o).origin!==location.origin)return`unknown`;let s=await fetch(o,{method:`HEAD`});return s.status===404||s.status===410||s.status>=500?`broken`:`ok`}function h(e){let n=p(e).map(e=>({...e,target:t(e.url)})),r=new Set(n.map(e=>e.url)),i=new Set(n.map(e=>e.target));for(let e of s.keys())i.has(e)||s.delete(e);let a=!1;for(let e of c.value.keys())r.has(e)||(c.value.delete(e),a=!0);a&&u();let f=Date.now();for(let{url:e,target:t,tag:r,identifier:i,tagDedupeKey:a}of n)l.value.has(t)||f-(s.get(t)??0)(console.warn(`[unhead devtools] link check failed:`,e,t),`unknown`)).then(n=>{l.value.delete(t),d(),n===`broken`?(c.value.set(e,{url:e,tag:r,identifier:i,tagDedupeKey:a}),u()):c.value.has(e)&&(c.value.delete(e),u())}))}export{f as n,h as r,c as t};