(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 h=(p,w,_)=>(le(p,w,"read from private field"),_?_.call(p):w.get(p)),N=(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,_)},D=(p,w,_,Y)=>(le(p,w,"write to private field"),Y?Y.call(p,_):w.set(p,_),_);var G,B,J,q,Q,W,L,X,Z,H,K,k,I,R;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,d=new Uint8Array(u);g!==a;){for(var A=f[g],T=0,b=u-1;(A!==0||T>>0,d[b]=A%c>>>0,A=A/c>>>0;if(A!==0)throw new Error("Non-zero carry");o=T,g++}for(var n=u-o;n!==u&&d[n]===0;)n++;for(var E=$.repeat(s);n>>0,u=new Uint8Array(a);f[s];){var d=e[f.charCodeAt(s)];if(d===255)return;for(var A=0,T=a-1;(d!==0||A>>0,u[T]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");g=A,s++}for(var b=a-g;b!==a&&u[b]===0;)b++;for(var n=new Uint8Array(o+(a-b)),E=o;b!==a;)n[E++]=u[b++];return n}function v(f){var s=M(f);if(s)return s;throw new Error("Non-base"+c+" character")}return{encode:F,decodeUnsafe:M,decode:v}}var Y=_;const ce=w(Y);var ne={};(function(t){(function(e){e([],function(){var r=-1,i=-2,l=-3,y=-4,c=-5,$=function(s,o){o=o||{};var g=o.verbose||!1;g&&console.log("Normalize the JSON Object"),s=typeof s=="string"?this.JSON.parse(s):s,g&&console.log("Creating a empty dictionary");var a={strings:[],integers:[],floats:[]};g&&console.log("Creating the AST");var u=function b(n){g&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(n));var E=typeof n;if(n===null)return{type:"null",index:l};if(typeof n>"u")return{type:"undefined",index:c};if(n instanceof Array){var U=["@"];for(var S in n)n.hasOwnProperty(S)&&U.push(b(n[S]));return U}if(E==="object"){var U=["$"];for(var j in n)n.hasOwnProperty(j)&&(U.push(b(j)),U.push(b(n[j])));return U}if(n==="")return{type:"empty",index:y};if(E==="string"){var C=f.call(a.strings,n);return C==-1&&(a.strings.push(z(n)),C=a.strings.length-1),{type:"strings",index:C}}if(E==="number"&&n%1===0){var C=f.call(a.integers,n);return C==-1&&(a.integers.push(M(n)),C=a.integers.length-1),{type:"integers",index:C}}if(E==="number"){var C=f.call(a.floats,n);return C==-1&&(a.floats.push(n),C=a.floats.length-1),{type:"floats",index:C}}if(E==="boolean")return{type:"boolean",index:n?r:i};throw new Error("Unexpected argument of type "+typeof n)}(s),d=a.strings.length,A=a.integers.length;a.floats.length,g&&console.log("Parsing the dictionary");var T=a.strings.join("|");return T+="^"+a.integers.join("|"),T+="^"+a.floats.join("|"),g&&console.log("Parsing the structure"),T+="^"+function b(n){if(g&&console.log("Calling a recursiveParser with "+this.JSON.stringify(n)),n instanceof Array){var E=n.shift();for(var U in n)n.hasOwnProperty(U)&&(E+=b(n[U])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var S=n.type,j=n.index;if(S==="strings")return M(j);if(S==="integers")return M(d+j);if(S==="floats")return M(d+A+j);if(S==="boolean")return n.index;if(S==="null")return l;if(S==="undefined")return c;if(S==="empty")return y;throw new TypeError("The item is alien!")}(u),g&&console.log("Ending parser"),o.debug?{dictionary:a,ast:u,packed:T}:T},V=function(s,o){o=o||{};var g=s.split("^");o.verbose&&console.log("Building dictionary");var a=[],u=g[0];if(u!==""){u=u.split("|"),o.verbose&&console.log("Parse the strings dictionary");for(var d=0,A=u.length;dh(this,Q).call(this,r),ownKeys:()=>Object.keys(h(this,q).getPrototypeOf()||{}),getPrototypeOf:()=>h(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:h(this,q).getPrototypeOf()})});N(this,Q,e=>e==="$toast"?h(this,L):e==="msg"?h(this,W):e==="then"||e==="resp"?(D(this,J,!0),D(this,B,e==="resp"),h(this,X)):e==="catch"?h(this,Z):e==="IS_ECHO_MSG"?h(this,J):Reflect.get(this,e));N(this,W,(e=i=>i,r=!1)=>(h(this,L).call(this),D(this,B,r),Promise.resolve(e==null?void 0:e(h(this,q).getPrototypeOf()))));N(this,L,()=>{h(this,J)&&(D(this,J,!1),ue.onToast(this.code,this.message))});N(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(h(this,q).getPrototypeOf())):Promise.reject(h(this,G)));N(this,Z,e=>Promise.resolve(e(h(this,G))));return this.code=e,this.message=r,this.data=i,this.url=l,this.res=y,D(this,G,new Proxy(this,h(this,q)))}}G=new WeakMap,B=new WeakMap,J=new WeakMap,q=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,r,i="/",l="")=>new ee(t,e,r,i,l);var se=["utf8","utf-8","unicode-1-1-utf-8"];function ge(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 l=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 l=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),y=new Array(l.length);for(let c=0;c{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请求方法主体"})){N(this,H,void 0);N(this,K,void 0);N(this,k,void 0);N(this,I,{"#":new Map,$:new Map});N(this,R,new Map);P(this,"request",({url:e="/",method:r="GET",...i},l=!1)=>{var M;const y=r.toUpperCase(),c=ae(JSON.stringify([e,y,i])),$=(M=e==null?void 0:e.includes)!=null&&M.call(e,"/_/")?"#":"$",{promise:V,resolve:z,reject:F}=Promise.withResolvers();return h(this,I)[$].has(c)?(console.log("缓存命中",e),z(h(this,I)[$].get(c))):h(this,R).has(c)?h(this,R).get(c).push([z,F]):h(this,R).set(c,[[z,F]]),h(this,R).get(c).length===1&&h(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=>(($=="#"||l&&y==="GET")&&h(this,I)[$].set(c,v),v)).then(v=>h(this,R).get(c).forEach(([f,s])=>f(v))).catch(v=>(h(this,I)[$].delete(c),h(this,R).get(c).forEach(([f,s])=>s(v instanceof ee?v:te(-1,v,null,e))))).finally(()=>setTimeout(()=>{h(this,R).delete(c)})),new Proxy(V,{get:(v,f)=>(...s)=>v.then(o=>te(...o)[f](...s)).catch(o=>{if(!o instanceof ee)throw o;return typeof o[f]=="function"?o[f](...s):o[f]})})});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&&h(this,I)["#"].clear(),h(this,I).$.clear()});P(this,"decode",(e="",r={})=>{if(e===void 0||e===""||e===null)return r;try{const i=h(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,l)=>l===void 0?null:l);return h(this,K).encode(fe(ie.pack(r)))});D(this,k,e),D(this,H,i),D(this,K,ce(r))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,I=new WeakMap,R=new WeakMap;const ue=re;re.onUnhandledRejection=t=>{var e,r,i,l,y,c;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=(l=t.reason)==null?void 0:l.$toast)==null||y.call(l),(c=t==null?void 0:t.preventDefault)==null||c.call(t))},re.onToast=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),p.default=ue,p.signature=ae,p.str2uint8array=fe,p.trim=we,p.uint8array2str=he,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});