(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c["ff-request"]={}))})(this,function(c){"use strict";var Se=Object.defineProperty;var xe=(c,d,b)=>d in c?Se(c,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[d]=b;var w=(c,d,b)=>(xe(c,typeof d!="symbol"?d+"":d,b),b),de=(c,d,b)=>{if(!d.has(c))throw TypeError("Cannot "+b)};var o=(c,d,b)=>(de(c,d,"read from private field"),b?b.call(c):d.get(c)),P=(c,d,b)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,b)},N=(c,d,b,H)=>(de(c,d,"write to private field"),H?H.call(c,b):d.set(c,b),b);var G,J,D,j,X,Z,L,k,ee,z,V,Y,K,te,$,I;function d(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var b={};(function(r){(function(e){e([],function(){var t=-1,n=-2,s=-3,l=-4,u=-5,M=function(f,i){i=i||{};var p=i.verbose||!1;p&&console.log("Normalize the JSON Object"),f=typeof f=="string"?this.JSON.parse(f):f,p&&console.log("Creating a empty dictionary");var g={strings:[],integers:[],floats:[]};p&&console.log("Creating the AST");var v=function _(a){p&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(a));var E=typeof a;if(a===null)return{type:"null",index:s};if(typeof a>"u")return{type:"undefined",index:u};if(a instanceof Array){var C=["@"];for(var T in a)a.hasOwnProperty(T)&&C.push(_(a[T]));return C}if(E==="object"){var C=["$"];for(var F in a)a.hasOwnProperty(F)&&(C.push(_(F)),C.push(_(a[F])));return C}if(a==="")return{type:"empty",index:l};if(E==="string"){var S=x.call(g.strings,a);return S==-1&&(g.strings.push(Q(a)),S=g.strings.length-1),{type:"strings",index:S}}if(E==="number"&&a%1===0){var S=x.call(g.integers,a);return S==-1&&(g.integers.push(B(a)),S=g.integers.length-1),{type:"integers",index:S}}if(E==="number"){var S=x.call(g.floats,a);return S==-1&&(g.floats.push(a),S=g.floats.length-1),{type:"floats",index:S}}if(E==="boolean")return{type:"boolean",index:a?t:n};throw new Error("Unexpected argument of type "+typeof a)}(f),O=g.strings.length,q=g.integers.length;g.floats.length,p&&console.log("Parsing the dictionary");var U=g.strings.join("|");return U+="^"+g.integers.join("|"),U+="^"+g.floats.join("|"),p&&console.log("Parsing the structure"),U+="^"+function _(a){if(p&&console.log("Calling a recursiveParser with "+this.JSON.stringify(a)),a instanceof Array){var E=a.shift();for(var C in a)a.hasOwnProperty(C)&&(E+=_(a[C])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var T=a.type,F=a.index;if(T==="strings")return B(F);if(T==="integers")return B(O+F);if(T==="floats")return B(O+q+F);if(T==="boolean")return a.index;if(T==="null")return s;if(T==="undefined")return u;if(T==="empty")return l;throw new TypeError("The item is alien!")}(v),p&&console.log("Ending parser"),i.debug?{dictionary:g,ast:v,packed:U}:U},R=function(f,i){i=i||{};var p=f.split("^");i.verbose&&console.log("Building dictionary");var g=[],v=p[0];if(v!==""){v=v.split("|"),i.verbose&&console.log("Parse the strings dictionary");for(var O=0,q=v.length;Oo(this,X).call(this,t),ownKeys:()=>Object.keys(o(this,j).getPrototypeOf()||{}),getPrototypeOf:()=>o(this,J)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:o(this,j).getPrototypeOf()})});P(this,X,e=>e==="$echoMsg"?o(this,L):e==="msg"?o(this,Z):e==="then"||e==="resp"?(N(this,D,!0),N(this,J,e==="resp"),o(this,k)):e==="catch"?o(this,ee):e==="IS_ECHO_MSG"?o(this,D):Reflect.get(this,e));P(this,Z,(e=n=>n,t=!1)=>(o(this,L).call(this),N(this,J,t),Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf()))));P(this,L,()=>{o(this,D)&&(N(this,D,!1),he.onMsg(this.code,this.message))});P(this,k,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf())):Promise.reject(o(this,G)));P(this,ee,e=>Promise.resolve(e(o(this,G))));return this.code=e,this.message=t,this.data=n,this.url=s,this.res=l,N(this,G,new Proxy(this,o(this,j)))}}G=new WeakMap,J=new WeakMap,D=new WeakMap,j=new WeakMap,X=new WeakMap,Z=new WeakMap,L=new WeakMap,k=new WeakMap,ee=new WeakMap;const se=(r,e,t,n="/",s="")=>new ne(r,e,t,n,s);var oe=["utf8","utf-8","unicode-1-1-utf-8"];function ge(r){if(oe.indexOf(r)<0&&typeof r<"u"&&r!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);const s=t.split("");for(let l=0;l"u")return"";var n=typeof t<"u"&&n in t?t.stream:!1;if(typeof n!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),l=new Array(s.length);for(let u=0;u{let e=5381;for(let t=0;t>>0).toString(16)},le=(r,e)=>r.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),ue=r=>ve.encode(r||""),we=r=>ye.decode(new DataView(r),{}),be=62,W=30,fe=31,Ee=63;class Te{constructor(e){w(this,"encodeTable",[]);w(this,"decodeMap",new Uint8Array(256).fill(255));if(e.length!==be)throw new Error("Encoding alphabet must be 62 characters long");if(e.includes(` `)||e.includes("\r"))throw new Error("Encoding alphabet contains newline character");this.encodeTable=e.split(""),this.decodeMap=new Uint8Array(256).fill(255);for(let t=0;t>3;e===0&&(t-=1,e=8);let n=this.src[t]>>8-e;return e<6&&t>0&&(n|=this.src[t-1]<0;){let n=6,s=this.get6bits();(s&W)===W&&((this.pos>6||s>fe)&&(n=5),s&=fe),t.push(o(this,z).encodeTable[s].charCodeAt(0)),this.pos-=n}return t}}z=new WeakMap;class Pe{constructor(e){P(this,V,null);N(this,V,e)}decode(e){const t=new Uint8Array(Math.ceil(e.length*6/8)+1);let n=t.length,s=0,l=0;for(let u=0;u=8&&(n--,t[n]=l&255,s%=8,l>>=8)}return s>0&&(n--,t[n]=l&255),t.slice(n)}}V=new WeakMap,Promise.withResolvers||(Promise.withResolvers=function(){let r,e;return{promise:new Promise((n,s)=>{r=n,e=s}),resolve:r,reject:e}});class ie{constructor(e,t,n=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){P(this,Y,void 0);P(this,K,void 0);P(this,te,void 0);P(this,$,{"#":new Map,$:new Map});P(this,I,new Map);w(this,"request",({url:e="/",method:t="GET",...n},s=!1)=>{var B;e=le(e,"/");const l=t.toUpperCase(),u=ce(JSON.stringify([e,l,n])),M=(B=e==null?void 0:e.includes)!=null&&B.call(e,"/_/")?"#":"$",{promise:R,resolve:Q,reject:re}=Promise.withResolvers();return o(this,$)[M].has(u)?(console.log("cache",e),Q(o(this,$)[M].get(u))):o(this,I).has(u)?o(this,I).get(u).push([Q,re]):(o(this,I).set(u,[[Q,re]]),o(this,Y).call(this,{url:e,method:l,...n}).then(h=>{if(![0,1].includes(h.code))throw se(h.code,h.msg,h.data,e,h==null?void 0:h.res);return[h.code,h.msg,h.data,e,h==null?void 0:h.res]}).then(h=>((M=="#"||l=="GET")&&o(this,$)[M].set(u,h),M!="#"&&l=="GET"&&!s&&setTimeout(()=>{o(this,$)[M].delete(u)},300),h)).then(h=>{var x;return(x=o(this,I).get(u))==null?void 0:x.forEach((f,i,p)=>{f&&f[0](h),delete p[i]})}).catch(h=>{var x;o(this,$)[M].delete(u),(x=o(this,I).get(u))==null||x.forEach((f,i,p)=>{f&&f[1](h instanceof ne?h:se(-1,h,null,e)),delete p[i]})}).finally(()=>o(this,I).delete(u))),new Proxy(R,{get:(h,x)=>(...f)=>h.then(i=>se(...i)[x](...f)).catch(i=>{if(!i instanceof ne)throw i;return typeof i[x]=="function"?i[x](...f):i[x]})})});w(this,"get",(e,t={})=>this.request({url:e,method:"GET",params:t}));w(this,"post",(e,t={},n={})=>this.request({url:e,method:"POST",data:t,params:n}));w(this,"put",(e,t={},n={})=>this.request({url:e,method:"PUT",data:t,params:n}));w(this,"del",(e,t={},n={})=>this.request({url:e,method:"DELETE",data:t,params:n}));w(this,"download",(e,t)=>{});w(this,"cache",(e,t={})=>this.request({url:e,method:"GET",params:t},!0));w(this,"list",(e,t={})=>this.get(`/api/${e}/${this.encode(t)}`));w(this,"getAppInfo",()=>{});w(this,"refreshCache",(e=!1)=>{e&&o(this,$)["#"].clear(),o(this,$).$.clear()});w(this,"decode",(e="",t={})=>{if(e===void 0||e===""||e===null)return t;try{const n=o(this,K).decode(e);return H.unpack(n)}catch{return console.warn("core.decode",e),t}});w(this,"encode",(e={})=>{const t=JSON.stringify(e,(n,s)=>s===void 0?null:s);return o(this,K).encode(H.pack(t))});N(this,te,e),N(this,Y,n),N(this,K,new Te(t))}}Y=new WeakMap,K=new WeakMap,te=new WeakMap,$=new WeakMap,I=new WeakMap;const he=ie;ie.onUnhandledRejection=r=>{var e,t,n,s,l,u;r!=null&&r.IS_ECHO_MSG?((e=r==null?void 0:r.$echoMsg)==null||e.call(r),(t=r==null?void 0:r.preventDefault)==null||t.call(r)):(n=r.reason)!=null&&n.IS_ECHO_MSG&&((l=(s=r.reason)==null?void 0:s.$echoMsg)==null||l.call(s),(u=r==null?void 0:r.preventDefault)==null||u.call(r))},ie.onMsg=(r,e)=>[0,1].includes(r)?console.log(e):console.warn(e),c.default=he,c.signature=ce,c.str2uint8array=ue,c.trim=le,c.uint8array2str=we,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});