function e(e,t){let n=`cannot ${e.method} ${e.action} ${t.status}'`,r=Error(n);return r.status=t.status,r.method=e.method,r.url=e.action,r}function t(e){let t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch{return t}}function n(n){let r=new XMLHttpRequest;n.onProgress&&r.upload&&(r.upload.onprogress=function(e){e.total>0&&(e.percent=e.loaded/e.total*100),n.onProgress(e)});let i=new FormData;n.data&&Object.keys(n.data).forEach(e=>{let t=n.data[e];if(Array.isArray(t)){t.forEach(t=>{i.append(`${e}[]`,t)});return}i.append(e,t)}),n.file instanceof Blob?i.append(n.filename,n.file,n.file.name):i.append(n.filename,n.file),r.onerror=function(e){n.onError(e)},r.onload=function(){return r.status<200||r.status>=300?n.onError(e(n,r),t(r)):n.onSuccess(t(r),r)},r.open(n.method,n.action,!0),n.withCredentials&&`withCredentials`in r&&(r.withCredentials=!0);let a=n.headers||{};return a[`X-Requested-With`]!==null&&r.setRequestHeader(`X-Requested-With`,`XMLHttpRequest`),Object.keys(a).forEach(e=>{a[e]!==null&&r.setRequestHeader(e,a[e])}),r.send(i),{abort(){r.abort()}}}export{n as default};