function e(e){return new Promise((t,n,r)=>{(r=new XMLHttpRequest).open("GET",e,r.withCredentials=!0),r.onload=()=>{200===r.status?t():n()},r.send()})}function t(t){return window.fetch?fetch(t,{credentials:"include"}):e(t)}const n=(r=document.createElement("link")).relList&&r.relList.supports&&r.relList.supports("prefetch")?function(e){return new Promise((t,n,r)=>{(r=document.createElement("link")).rel="prefetch",r.href=e,r.onload=t,r.onerror=n,document.head.appendChild(r)})}:e;var r;const o=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout(function(){e({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-t))}})},1)},i=new Set;function c(e){if(e||(e={}),!window.IntersectionObserver)return;const[t,n]=function(e){e=e||1;var t=[],n=0;function r(){n0&&(t.shift()(),n++)}return[function(e){t.push(e)>1||r()},function(){n--,r()}]}(e.throttle||1/0),r=e.limit||1/0,c=e.origins||[location.hostname],a=e.ignores||[],u=e.delay||0,f=[],l=e.timeoutFn||o,h="function"==typeof e.hrefFn&&e.hrefFn,d=new IntersectionObserver(o=>{o.forEach(o=>{if(o.isIntersecting)f.push((o=o.target).href),((e,t)=>{t?setTimeout(e,t):e()})(()=>{-1!==f.indexOf(o.href)&&(d.unobserve(o),i.size{s(h?h(o):o.href,e.priority).then(n).catch(t=>{n(),e.onError&&e.onError(t)})}))},u);else{const e=f.indexOf((o=o.target).href);e>-1&&f.splice(e)}})});return l(()=>{(e.el||document).querySelectorAll("a").forEach(e=>{c.length&&!c.includes(e.hostname)||function e(t,n){return Array.isArray(n)?n.some(n=>e(t,n)):(n.test||n).call(n,t.href,t)}(e,a)||d.observe(e)})},{timeout:e.timeout||2e3}),function(){i.clear(),d.disconnect()}}function s(e,r,o){if(o=navigator.connection){if(o.saveData)return Promise.reject(new Error("Cannot prefetch, Save-Data is enabled"));if(/2g/.test(o.effectiveType))return Promise.reject(new Error("Cannot prefetch, network conditions are poor"))}return Promise.all([].concat(e).map(e=>{if(!i.has(e))return i.add(e),(r?t:n)(new URL(e,location.href).toString())}))}export{c as listen,s as prefetch};