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