var j=class extends Error{constructor(i,c){super(i.statusText),this.code=i.status,this.response=i,this.body=c}},v=i=>{function c(r){if(typeof r!="object"||r===null)return!1;let t=r;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(r)===t}return function(t,w){const{beforeRequest:d,customParser:u,...a}={...w};a.headers&&Object.keys(a.headers).forEach(o=>{const e=o.toLowerCase();e!==o&&(a.headers[e]=a.headers[o],delete a.headers[o])}),d==null||d(t,a);let{timeout:h=5e3,json:x,text:O,blob:p,buffer:g,headers:b={},...f}=a;f.method&&f.method.toUpperCase(),c(f.body)&&(b["content-type"]="application/json;charset=UTF-8",f.body=JSON.stringify(f.body)),f.headers=b;function m(o){let e=p?"blob":g?"arrayBuffer":x?"json":O?"text":void 0;if(e===void 0){const[s]=(o.headers.get("content-type")||"").split(";"),[l,n]=s.split("/");l==="application"?n==="json"?e="json":n==="octet-stream"?e=p?"blob":"arrayBuffer":e="text":e="text"}return o[e]().then(s=>({r:o,body:s}))}return new Promise((o,e)=>{let s;h>0&&(s=setTimeout(()=>{s=void 0,l.abort(),e(new Error(`fetch ${t} timeout for ${h}ms.`))},h));const l=i(t,f);l.then(n=>(s&&clearTimeout(s),u?u(n,m):m(n))).then(({r:n,body:y})=>{if(!n.ok){e(new j(n,y));return}o(y)}).catch(e)})}},P=v((i,c)=>{const r=new window.AbortController,t=window.fetch(i,{...c,signal:r.signal});return t.abort=()=>r.abort(),t}),E=P;export{E as i};
