import{b as x}from"./chunk-NATZLJV5.js";import{f as c}from"./chunk-4IDNTCH7.js";var O=e=>c(null,null,function*(){return new Promise((t,s)=>{let n=new FileReader;n.onload=()=>{let o=n.result,a=o.substr(o.indexOf(",")+1);t(a)},n.onerror=o=>s(o),n.readAsDataURL(e)})}),f=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),b=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);var w=(e,t,s={})=>{let n=f(e),o=f(t),a=`; expires=${(s.expires||"").replace("expires=","")}`,r=(s.path||"/").replace("path=","");document.cookie=`${n}=${o||""}${a}; path=${r}`},k=()=>{let e=[],t={};if(!document.cookie)return e;let s=document.cookie.split(";")||[];for(let o of s){let[a,r]=o.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");a=b(a).trim(),r=b(r).trim(),t[a]=r}let n=Object.entries(t);for(let[o,a]of n)e.push({key:o,value:a});return e},j=e=>{let t=k();for(let s of t)if(s.key===e)return s;return{key:e,value:""}},R=e=>{document.cookie=`${e}=; Max-Age=0`},m=()=>{let e=document.cookie.split(";")||[];for(let t of e)document.cookie=t.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)};var U=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(o=>o.toLocaleLowerCase()).reduce((o,a,r)=>(o[a]=e[t[r]],o),{})},D=(e,t=!0)=>e?Object.entries(e).reduce((n,o)=>{let[a,r]=o,i,d;return Array.isArray(r)?(d="",r.forEach(l=>{i=t?encodeURIComponent(l):l,d+=`${a}=${i}&`}),d.slice(0,-1)):(i=t?encodeURIComponent(r):r,d=`${a}=${i}`),`${n}&${d}`},"").substr(1):null,g=(e,t={})=>{let s=Object.assign({method:e.method||"GET",headers:e.headers},t),o=U(e.headers)["content-type"]||"";if(typeof e.data=="string")s.body=e.data;else if(o.includes("application/x-www-form-urlencoded")){let a=new URLSearchParams;for(let[r,i]of Object.entries(e.data||{}))a.set(r,i);s.body=a.toString()}else if(o.includes("multipart/form-data")){let a=new FormData;if(e.data instanceof FormData)e.data.forEach((i,d)=>{a.append(d,i)});else for(let i of Object.keys(e.data))a.append(i,e.data[i]);s.body=a;let r=new Headers(s.headers);r.delete("content-type"),s.headers=r}else(o.includes("application/json")||typeof e.data=="object")&&(s.body=JSON.stringify(e.data));return s},u=e=>c(null,null,function*(){let t=g(e,e.webFetchExtra),s=D(e.params,e.shouldEncodeUrlParams),n=s?`${e.url}?${s}`:e.url,o=yield fetch(n,t),a=o.headers.get("content-type")||"",{responseType:r="text"}=o.ok?e:{};a.includes("application/json")&&(r="json");let i;switch(r){case"arraybuffer":case"blob":let l=yield o.blob();i=yield O(l);break;case"json":i=yield o.json();break;case"document":case"text":default:i=yield o.text()}let d={};return o.headers.forEach((l,h)=>{d[h]=l}),{data:i,headers:d,status:o.status,url:o.url}}),q=e=>c(null,null,function*(){return u(Object.assign(Object.assign({},e),{method:"GET"}))}),$=e=>c(null,null,function*(){return u(Object.assign(Object.assign({},e),{method:"POST"}))}),v=e=>c(null,null,function*(){return u(Object.assign(Object.assign({},e),{method:"PUT"}))}),A=e=>c(null,null,function*(){return u(Object.assign(Object.assign({},e),{method:"PATCH"}))}),E=e=>c(null,null,function*(){return u(Object.assign(Object.assign({},e),{method:"DELETE"}))});var I=class extends x{constructor(){super(),this.request=t=>c(this,null,function*(){return u(t)}),this.get=t=>c(this,null,function*(){return q(t)}),this.post=t=>c(this,null,function*(){return $(t)}),this.put=t=>c(this,null,function*(){return v(t)}),this.patch=t=>c(this,null,function*(){return A(t)}),this.del=t=>c(this,null,function*(){return E(t)}),this.getCookiesMap=t=>c(this,null,function*(){let s=k(),n={};for(let o of s)n[o.key]=o.value;return n}),this.getCookies=t=>c(this,null,function*(){let{url:s}=t;return{cookies:k()}}),this.setCookie=t=>c(this,null,function*(){let{key:s,value:n,expires:o="",path:a=""}=t;w(s,n,{expires:o,path:a})}),this.getCookie=t=>c(this,null,function*(){return j(t.key)}),this.deleteCookie=t=>c(this,null,function*(){return R(t.key)}),this.clearCookies=t=>c(this,null,function*(){return m()}),this.clearAllCookies=()=>c(this,null,function*(){return m()}),this.uploadFile=t=>c(this,null,function*(){let s=new FormData;s.append(t.name,t.blob||"undefined");let n=Object.assign(Object.assign({},t),{body:s,method:"POST"});return this.post(n)}),this.downloadFile=t=>c(this,null,function*(){let s=g(t,t.webFetchExtra),n=yield fetch(t.url,s),o;if(!t?.progress)o=yield n.blob();else if(!n?.body)o=new Blob;else{let a=n.body.getReader(),r=0,i=[],d=n.headers.get("content-type"),l=parseInt(n.headers.get("content-length")||"0",10);for(;;){let{done:p,value:y}=yield a.read();if(p)break;i.push(y),r+=y?.length||0;let P={type:"DOWNLOAD",url:t.url,bytes:r,contentLength:l};this.notifyListeners("progress",P)}let h=new Uint8Array(r),C=0;for(let p of i)typeof p>"u"||(h.set(p,C),C+=p.length);o=new Blob([h.buffer],{type:d||void 0})}return{blob:o}})}};export{I as HttpWeb};
