var oe = Object.defineProperty; var ie = (r, e, t) => e in r ? oe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var P = (r, e, t) => (ie(r, typeof e != "symbol" ? e + "" : e, t), t), k = (r, e, t) => { if (!e.has(r)) throw TypeError("Cannot " + t); }; var u = (r, e, t) => (k(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => { if (e.has(r)) throw TypeError("Cannot add the same private member more than once"); e instanceof WeakSet ? e.add(r) : e.set(r, t); }, M = (r, e, t, s) => (k(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t); function re(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } function ae(r) { if (r.length >= 255) throw new TypeError("Alphabet too long"); for (var e = new Uint8Array(256), t = 0; t < e.length; t++) e[t] = 255; for (var s = 0; s < r.length; s++) { var l = r.charAt(s), v = l.charCodeAt(0); if (e[v] !== 255) throw new TypeError(l + " is ambiguous"); e[v] = s; } var g = r.length, N = r.charAt(0), B = Math.log(g) / Math.log(256), I = Math.log(256) / Math.log(g); function q(n) { if (n instanceof Uint8Array || (ArrayBuffer.isView(n) ? n = new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : Array.isArray(n) && (n = Uint8Array.from(n))), !(n instanceof Uint8Array)) throw new TypeError("Expected Uint8Array"); if (n.length === 0) return ""; for (var o = 0, f = 0, i = 0, h = n.length; i !== h && n[i] === 0; ) i++, o++; for (var c = (h - i) * I + 1 >>> 0, d = new Uint8Array(c); i !== h; ) { for (var O = n[i], b = 0, p = c - 1; (O !== 0 || b < f) && p !== -1; p--, b++) O += 256 * d[p] >>> 0, d[p] = O % g >>> 0, O = O / g >>> 0; if (O !== 0) throw new Error("Non-zero carry"); f = b, i++; } for (var a = c - f; a !== c && d[a] === 0; ) a++; for (var w = N.repeat(o); a < c; ++a) w += r.charAt(d[a]); return w; } function U(n) { if (typeof n != "string") throw new TypeError("Expected String"); if (n.length === 0) return new Uint8Array(); for (var o = 0, f = 0, i = 0; n[o] === N; ) f++, o++; for (var h = (n.length - o) * B + 1 >>> 0, c = new Uint8Array(h); n[o]; ) { var d = e[n.charCodeAt(o)]; if (d === 255) return; for (var O = 0, b = h - 1; (d !== 0 || O < i) && b !== -1; b--, O++) d += g * c[b] >>> 0, c[b] = d % 256 >>> 0, d = d / 256 >>> 0; if (d !== 0) throw new Error("Non-zero carry"); i = O, o++; } for (var p = h - i; p !== h && c[p] === 0; ) p++; for (var a = new Uint8Array(f + (h - p)), w = f; p !== h; ) a[w++] = c[p++]; return a; } function j(n) { var o = U(n); if (o) return o; throw new Error("Non-base" + g + " character"); } return { encode: q, decodeUnsafe: U, decode: j }; } var fe = ae; const he = /* @__PURE__ */ re(fe); var te = {}; (function(r) { (function(e) { e([], function() { var t = -1, s = -2, l = -3, v = -4, g = -5, N = function(o, f) { f = f || {}; var i = f.verbose || !1; i && console.log("Normalize the JSON Object"), o = typeof o == "string" ? this.JSON.parse(o) : o, i && console.log("Creating a empty dictionary"); var h = { strings: [], integers: [], floats: [] }; i && console.log("Creating the AST"); var c = function p(a) { i && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(a)); var w = typeof a; if (a === null) return { type: "null", index: l }; if (typeof a > "u") return { type: "undefined", index: g }; if (a instanceof Array) { var S = ["@"]; for (var E in a) a.hasOwnProperty(E) && S.push(p(a[E])); return S; } if (w === "object") { var S = ["$"]; for (var x in a) a.hasOwnProperty(x) && (S.push(p(x)), S.push(p(a[x]))); return S; } if (a === "") return { type: "empty", index: v }; if (w === "string") { var T = n.call(h.strings, a); return T == -1 && (h.strings.push(I(a)), T = h.strings.length - 1), { type: "strings", index: T }; } if (w === "number" && a % 1 === 0) { var T = n.call(h.integers, a); return T == -1 && (h.integers.push(U(a)), T = h.integers.length - 1), { type: "integers", index: T }; } if (w === "number") { var T = n.call(h.floats, a); return T == -1 && (h.floats.push(a), T = h.floats.length - 1), { type: "floats", index: T }; } if (w === "boolean") return { type: "boolean", index: a ? t : s }; throw new Error("Unexpected argument of type " + typeof a); }(o), d = h.strings.length, O = h.integers.length; h.floats.length, i && console.log("Parsing the dictionary"); var b = h.strings.join("|"); return b += "^" + h.integers.join("|"), b += "^" + h.floats.join("|"), i && console.log("Parsing the structure"), b += "^" + function p(a) { if (i && console.log("Calling a recursiveParser with " + this.JSON.stringify(a)), a instanceof Array) { var w = a.shift(); for (var S in a) a.hasOwnProperty(S) && (w += p(a[S]) + "|"); return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]"; } var E = a.type, x = a.index; if (E === "strings") return U(x); if (E === "integers") return U(d + x); if (E === "floats") return U(d + O + x); if (E === "boolean") return a.index; if (E === "null") return l; if (E === "undefined") return g; if (E === "empty") return v; throw new TypeError("The item is alien!"); }(c), i && console.log("Ending parser"), f.debug ? { dictionary: h, ast: c, packed: b } : b; }, B = function(o, f) { f = f || {}; var i = o.split("^"); f.verbose && console.log("Building dictionary"); var h = [], c = i[0]; if (c !== "") { c = c.split("|"), f.verbose && console.log("Parse the strings dictionary"); for (var d = 0, O = c.length; d < O; d++) h.push(q(c[d])); } if (c = i[1], c !== "") { c = c.split("|"), f.verbose && console.log("Parse the integers dictionary"); for (var d = 0, O = c.length; d < O; d++) h.push(j(c[d])); } if (c = i[2], c !== "") { c = c.split("|"), f.verbose && console.log("Parse the floats dictionary"); for (var d = 0, O = c.length; d < O; d++) h.push(parseFloat(c[d])); } c = null, f.verbose && console.log("Tokenizing the structure"); for (var b = "", p = [], a = i[3].length, d = 0; d < a; d++) { var w = i[3].charAt(d); w === "|" || w === "$" || w === "@" || w === "]" ? (b && (p.push(j(b)), b = ""), w !== "|" && p.push(w)) : b += w; } var S = p.length, E = 0; return f.verbose && console.log("Starting recursive parser"), function x() { var T = p[E++]; if (f.verbose && console.log("Reading collection type " + (T === "$" ? "object" : "Array")), T === "@") { for (var y = []; E < S; E++) { var C = p[E]; if (f.verbose && console.log("Read " + C + " symbol"), C === "]") return y; if (C === "@" || C === "$") y.push(x()); else switch (C) { case t: y.push(!0); break; case s: y.push(!1); break; case l: y.push(null); break; case g: y.push(void 0); break; case v: y.push(""); break; default: y.push(h[C]); } } return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; } if (T === "$") { for (var y = {}; E < S; E++) { var _ = p[E]; if (_ === "]") return y; _ === v ? _ = "" : _ = h[_]; var C = p[++E]; if (C === "@" || C === "$") y[_] = x(); else switch (C) { case t: y[_] = !0; break; case s: y[_] = !1; break; case l: y[_] = null; break; case g: y[_] = void 0; break; case v: y[_] = ""; break; default: y[_] = h[C]; } } return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; } throw new TypeError("Bad token " + T + " isn't a type"); }(); }, I = function(o) { return typeof o != "string" ? o : o.replace(/[\+ \|\^\%]/g, function(f) { return { " ": "+", "+": "%2B", "|": "%7C", "^": "%5E", "%": "%25" }[f]; }); }, q = function(o) { return typeof o != "string" ? o : o.replace(/\+|%2B|%7C|%5E|%25/g, function(f) { return { "+": " ", "%2B": "+", "%7C": "|", "%5E": "^", "%25": "%" }[f]; }); }, U = function(o) { return Number.prototype.toString.call(o, 36).toUpperCase(); }, j = function(o) { return parseInt(o, 36); }, n = Array.prototype.indexOf || function(o, f) { for (var i = f || 0, h = this.length; i < h; i++) if (this[i] === o) return i; return -1; }; return { JSON, pack: N, unpack: B }; }); })(function(e, t) { var s = t(); for (var l in s) r[l] = s[l]; }); })(te); const ee = /* @__PURE__ */ re(te); var J, z, D, $, L, H, K, V, Y; class X { constructor(e, t, s, l, v) { P(this, "code", 0); P(this, "message", "操作成功"); P(this, "data", null); P(this, "url", ""); P(this, "res", ""); // static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined } A(this, J, null); // 判断返回 Response 对象, 还是 Response 中的 data A(this, z, !0); // 判罚是否已经给出错误提示 A(this, D, !0); A(this, $, { get: (e, t) => u(this, L).call(this, t), ownKeys: () => Object.keys(u(this, $).getPrototypeOf() || {}), getPrototypeOf: () => u(this, z) ? this : this.data, getOwnPropertyDescriptor: () => ({ configurable: !0, enumerable: !0, writable: !0, value: u(this, $).getPrototypeOf() }) }); A(this, L, (e) => e === "$echoMsg" ? u(this, K) : e === "msg" ? u(this, H) : e === "then" || e === "resp" ? (M(this, D, !0), M(this, z, e === "resp"), u(this, V)) : e === "catch" ? u(this, Y) : e === "IS_ECHO_MSG" ? u(this, D) : Reflect.get(this, e)); A(this, H, (e = (s) => s, t = !1) => (u(this, K).call(this), M(this, z, t), Promise.resolve(e == null ? void 0 : e(u(this, $).getPrototypeOf())))); A(this, K, () => { u(this, D) && (M(this, D, !1), we.onMsg(this.code, this.message)); }); A(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(u(this, $).getPrototypeOf())) : Promise.reject(u(this, J))); A(this, Y, (e) => Promise.resolve(e(u(this, J)))); return this.code = e, this.message = t, this.data = s, this.url = l, this.res = v, M(this, J, new Proxy(this, u(this, $))); } } J = new WeakMap(), z = new WeakMap(), D = new WeakMap(), $ = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); const W = (r, e, t, s = "/", l = "") => new X(r, e, t, s, l); var ne = [ "utf8", "utf-8", "unicode-1-1-utf-8" ]; function le(r) { if (ne.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)), s = new Uint8Array(t.length); const l = t.split(""); for (let v = 0; v < l.length; v++) s[v] = l[v].charCodeAt(0); return s; }; } function ue(r) { if (ne.indexOf(r) < 0 && typeof r < "u" && r != null) throw new RangeError("Invalid encoding type. Only utf-8 is supported"); this.encoding = "utf-8", this.decode = function(e, t) { if (typeof e > "u") return ""; var s = typeof t < "u" && s in t ? t.stream : !1; if (typeof s != "boolean") throw new TypeError("stream option must be boolean"); if (ArrayBuffer.isView(e)) { var l = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), v = new Array(l.length); for (let g = 0; g < l.length; g++) v[g] = String.fromCharCode(l[g]); return decodeURIComponent(escape(v.join(""))); } else throw new TypeError("passed argument must be an array buffer view"); }; } var se = { TextEncoder: le, TextDecoder: ue }; const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (r) => { let e = 5381; for (let t = 0; t < r.length; t++) e = e * 33 ^ r.charCodeAt(t); return (e >>> 0).toString(16); }, be = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => ce.encode(r || ""), pe = (r) => ge.decode(new DataView(r), {}); Promise.withResolvers || (Promise.withResolvers = function() { let r, e; return { promise: new Promise((s, l) => { r = s, e = l; }), resolve: r, reject: e }; }); var F, G, Q, m, R; class Z { constructor(e, t, s = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { A(this, F, void 0); A(this, G, void 0); A(this, Q, void 0); A(this, m, { "#": /* @__PURE__ */ new Map(), // 系统缓存 $: /* @__PURE__ */ new Map() // 普通缓存 }); A(this, R, /* @__PURE__ */ new Map()); P(this, "request", ({ url: e = "/", method: t = "GET", ...s }, l = !1) => { var U, j; const v = t.toUpperCase(), g = de(JSON.stringify([e, v, s])), N = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: B, resolve: I, reject: q } = Promise.withResolvers(); return u(this, m)[N].has(g) ? (console.log("缓存命中", e), I(u(this, m)[N].get(g))) : (u(this, R).has(g) ? u(this, R).get(g).push([I, q]) : u(this, R).set(g, [[I, q]]), (j = u(this, R).get(g)) != null && j.some((n) => n) && u(this, F).call(this, { url: e, method: v, ...s }).then((n) => { if (![0, 1].includes(n.code)) throw W(n.code, n.msg, n.data, e, n == null ? void 0 : n.res); return [n.code, n.msg, n.data, e, n == null ? void 0 : n.res]; }).then((n) => ((N == "#" || l && v === "GET") && u(this, m)[N].set(g, n), n)).then((n) => { var o; return (o = u(this, R).get(g)) == null ? void 0 : o.forEach((f, i, h) => { f && f[0](n), delete h[i]; }); }).catch((n) => { var o; u(this, m)[N].delete(g), (o = u(this, R).get(g)) == null || o.forEach((f, i, h) => { f && f[1](n instanceof X ? n : W(-1, n, null, e)), delete h[i]; }); }).finally(() => u(this, R).delete(g))), new Proxy(B, { get: (n, o) => (...f) => n.then((i) => W(...i)[o](...f)).catch((i) => { if (!i instanceof X) throw i; return typeof i[o] == "function" ? i[o](...f) : i[o]; }) }); }); P(this, "get", (e, t = {}) => this.request({ url: e, method: "GET", params: t })); P(this, "post", (e, t = {}, s = {}) => this.request({ url: e, method: "POST", data: t, params: s })); P(this, "put", (e, t = {}, s = {}) => this.request({ url: e, method: "PUT", data: t, params: s })); P(this, "del", (e, t = {}, s = {}) => this.request({ url: e, method: "DELETE", data: t, params: s })); P(this, "download", (e, t) => { }); P(this, "cache", (e, t = {}) => this.request({ url: e, method: "GET", params: t }, !0)); P(this, "list", (e, t = {}) => this.get(`/api/${e}/${this.encode(t)}`)); P(this, "getAppInfo", () => { }); P(this, "refreshCache", (e = !1) => { e && u(this, m)["#"].clear(), u(this, m).$.clear(); }); P(this, "decode", (e = "", t = {}) => { if (e === void 0 || e === "" || e === null) return t; try { const s = u(this, G).decode(e).buffer; return ee.unpack(pe(s)); } catch { return console.warn("core.decode", e), t; } }); P(this, "encode", (e = {}) => { const t = JSON.stringify(e, (s, l) => l === void 0 ? null : l); return u(this, G).encode(ve(ee.pack(t))); }); M(this, Q, e), M(this, F, s), M(this, G, he(t)); } } F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), R = new WeakMap(); const we = Z; Z.onUnhandledRejection = (r) => { var e, t, s, l, v, g; 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)) : (s = r.reason) != null && s.IS_ECHO_MSG && ((v = (l = r.reason) == null ? void 0 : l.$echoMsg) == null || v.call(l), (g = r == null ? void 0 : r.preventDefault) == null || g.call(r)); }; Z.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e); export { we as default, de as signature, ve as str2uint8array, be as trim, pe as uint8array2str };