const c="https://www.google.com/s2/favicons?domain_url=",h="https://www.google.com/s2/favicons?sz=32&domain_url=",w=t=>new Promise((o,e)=>{const n=new Image;n.onload=()=>{const{naturalWidth:r,naturalHeight:i}=n;o({width:r,height:i})},n.onerror=()=>{e(new Error("There was some problem with the image."))},n.src=t}),g=t=>new Promise((o,e)=>{const r=new Image;let i;r.onload=()=>{clearTimeout(i),o("success")},r.onerror=()=>{clearTimeout(i),e(new Error("error"))},r.src=t,i=setTimeout(function(){r.src="//!!!!/test.jpg",e(new Error("timeout"))},5e3)}),s=async t=>{try{const o=await w(h+t);return(o==null?void 0:o.width)>16&&(o==null?void 0:o.height)>16}catch{return!1}},a=t=>{let o;try{o=new URL(t)}catch{return!1}return o.protocol==="http:"||o.protocol==="https:"},m=t=>t.match(/\.(jpeg|jpg|png|svg)$/)!=null,f=t=>new Promise((o,e)=>{t&&a(t)&&(m(t)&&g(t).then(n=>{n&&o(t)},n=>{o(void 0)}),s(t).then(n=>{n&&o(`${c}${t}`),o(void 0)}))}),p=(t,o)=>new Promise((e,n)=>{if(t&&a(t))m(t)?g(t).then(r=>{r&&e(t)},r=>{e(void 0)}):s(t).then(r=>{r&&e(`${c}${t}`),e(void 0)},r=>{e(void 0)});else if(o&&a(o)){const r=new URL(o);s(r.origin).then(i=>{i&&e(`${c}${r.origin}`)},i=>{e(void 0)})}else e(void 0)});export{p as a,f as g};
