import{F as e,L as t,Vt as n,ft as r,ot as i,v as a,z as o}from"./xY0c-UfG.js";import"./xihTtKlq.js";import{a as s,n as c,o as l,r as u}from"./BVQQTlFf2.js";var d=o(`<span class="location-pill svelte-bjfjvn"> </span>`);function f(o,s){var c=d(),l=r(c,!0);n(c),i(()=>{a(c,`title`,s.title??s.label),e(l,s.label)}),t(o,c)}function p(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}async function m(e,t){let n=c({title:t.title});try{let r=await fetch(e,{signal:n.signal});if(!r.ok){let e=`Download failed (HTTP ${r.status})`;try{let t=await r.json();typeof t?.error==`string`&&t.error&&(e=t.error)}catch{}n.fail(e);return}let i=t.filename||s(r.headers.get(`content-disposition`))||t.fallbackFilename||l(e),a=Number(r.headers.get(`content-length`))||0,o;if(r.body&&typeof r.body.getReader==`function`){let e=r.body.getReader(),t=[],i=0;for(;;){let{done:r,value:o}=await e.read();if(r)break;o&&(t.push(o),i+=o.length,n.setFraction(u(i,a)))}o=new Blob(t,{type:r.headers.get(`content-type`)||`application/octet-stream`})}else o=await r.blob();p(o,i),n.succeed(t.doneMessage??`Downloaded`)}catch(e){if(e instanceof DOMException&&e.name===`AbortError`){n.finishCancelled(`Download cancelled`);return}n.fail(e?.message??`Download failed`)}}export{f as n,m as t};