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.timeoutFn||o,f=e.prefetchChunks,l=t=>{s(t,e.priority).then(n).catch(t=>{n(),e.onError&&e.onError(t)})},h=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&(h.unobserve(e=e.target),i.size{f?f(e,l):l(e.href)}))})});return u(()=>{(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)||h.observe(e)})},{timeout:e.timeout||2e3}),function(){i.clear(),h.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};