"use strict";const D=require("./index.cjs263.js"),s=require("./index.cjs226.js"),f=require("./index.cjs237.js"),U=require("./index.cjs335.js"),v=require("./index.cjs336.js"),k=require("./index.cjs240.js"),p=require("./index.cjs333.js"),H=require("./index.cjs334.js"),K=require("./index.cjs331.js"),R=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",O=R&&typeof ReadableStream=="function",z=R&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),_=(e,...t)=>{try{return!!e(...t)}catch{return!1}},j=O&&_(()=>{let e=!1;const t=new Request(D.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),A=64*1024,T=O&&_(()=>s.isReadableStream(new Response("").body)),w={stream:T&&(e=>e.body)};R&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!w[t]&&(w[t]=s.isFunction(e[t])?r=>r[t]():(r,c)=>{throw new f(`Response type '${t}' is not supported`,f.ERR_NOT_SUPPORT,c)})})})(new Response);const I=async e=>{if(e==null)return 0;if(s.isBlob(e))return e.size;if(s.isSpecCompliantForm(e))return(await new Request(D.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(s.isArrayBufferView(e)||s.isArrayBuffer(e))return e.byteLength;if(s.isURLSearchParams(e)&&(e=e+""),s.isString(e))return(await z(e)).byteLength},J=async(e,t)=>{const r=s.toFiniteNumber(e.getContentLength());return r??I(t)},V=R&&(async e=>{let{url:t,method:r,data:c,signal:B,cancelToken:x,timeout:F,onDownloadProgress:y,onUploadProgress:E,responseType:o,headers:S,withCredentials:h="same-origin",fetchOptions:b}=H(e);o=o?(o+"").toLowerCase():"text";let m=U([B,x&&x.toAbortSignal()],F),d;const u=m&&m.unsubscribe&&(()=>{m.unsubscribe()});let C;try{if(E&&j&&r!=="get"&&r!=="head"&&(C=await J(S,c))!==0){let i=new Request(t,{method:"POST",body:c,duplex:"half"}),l;if(s.isFormData(c)&&(l=i.headers.get("content-type"))&&S.setContentType(l),i.body){const[q,g]=p.progressEventDecorator(C,p.progressEventReducer(p.asyncDecorator(E)));c=v.trackStream(i.body,A,q,g)}}s.isString(h)||(h=h?"include":"omit");const n="credentials"in Request.prototype;d=new Request(t,{...b,signal:m,method:r.toUpperCase(),headers:S.normalize().toJSON(),body:c,duplex:"half",credentials:n?h:void 0});let a=await fetch(d,b);const L=T&&(o==="stream"||o==="response");if(T&&(y||L&&u)){const i={};["status","statusText","headers"].forEach(P=>{i[P]=a[P]});const l=s.toFiniteNumber(a.headers.get("content-length")),[q,g]=y&&p.progressEventDecorator(l,p.progressEventReducer(p.asyncDecorator(y),!0))||[];a=new Response(v.trackStream(a.body,A,q,()=>{g&&g(),u&&u()}),i)}o=o||"text";let N=await w[s.findKey(w,o)||"text"](a,e);return!L&&u&&u(),await new Promise((i,l)=>{K(i,l,{data:N,headers:k.from(a.headers),status:a.status,statusText:a.statusText,config:e,request:d})})}catch(n){throw u&&u(),n&&n.name==="TypeError"&&/Load failed|fetch/i.test(n.message)?Object.assign(new f("Network Error",f.ERR_NETWORK,e,d),{cause:n.cause||n}):f.from(n,n&&n.code,e,d)}});module.exports=V;
//# sourceMappingURL=index.cjs267.js.map
