@inpageedit/core 0.14.1 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/{BasePlugin-YOi2_vUo.js → BasePlugin-DD7l-5Xw.js} +2 -2
- package/dist/{BasePlugin-YOi2_vUo.js.map → BasePlugin-DD7l-5Xw.js.map} +1 -1
- package/dist/{PluginPrefSync-jTNlRQE-.js → PluginPrefSync-CbFuuC19.js} +3 -3
- package/dist/{PluginPrefSync-jTNlRQE-.js.map → PluginPrefSync-CbFuuC19.js.map} +1 -1
- package/dist/{PluginStoreApp-CGNxKXAN.js → PluginStoreApp-qiSVtnBy.js} +2 -2
- package/dist/{PluginStoreApp-CGNxKXAN.js.map → PluginStoreApp-qiSVtnBy.js.map} +1 -1
- package/dist/Preferences-C10tZMl1.js +2701 -0
- package/dist/Preferences-C10tZMl1.js.map +1 -0
- package/dist/{index-3NZkG2a3.js → index-BXNyXvre.js} +3 -3
- package/dist/{index-3NZkG2a3.js.map → index-BXNyXvre.js.map} +1 -1
- package/dist/{index-Bb0FiU2c.js → index-BanevHQ2.js} +21 -17
- package/dist/index-BanevHQ2.js.map +1 -0
- package/dist/index-BjDTD66_.js +491 -0
- package/dist/index-BjDTD66_.js.map +1 -0
- package/dist/{index-D97lUU3h.js → index-BpQ6VGMz.js} +55 -55
- package/dist/index-BpQ6VGMz.js.map +1 -0
- package/dist/{index-D-fW3ESK.js → index-CnR6CqkM.js} +2 -2
- package/dist/{index-D-fW3ESK.js.map → index-CnR6CqkM.js.map} +1 -1
- package/dist/{index-DELHsLHS.js → index-DKCZDN-Q.js} +4 -4
- package/dist/{index-DELHsLHS.js.map → index-DKCZDN-Q.js.map} +1 -1
- package/dist/{index-BBNseJXG.js → index-DVOc6fB6.js} +3 -3
- package/dist/{index-BBNseJXG.js.map → index-DVOc6fB6.js.map} +1 -1
- package/dist/{index-D6zFqL2u.js → index-De25v1_Q.js} +3 -3
- package/dist/{index-D6zFqL2u.js.map → index-De25v1_Q.js.map} +1 -1
- package/dist/{index-BrYKe18j.js → index-DensW9qt.js} +3 -3
- package/dist/{index-BrYKe18j.js.map → index-DensW9qt.js.map} +1 -1
- package/dist/{index-DTHY5rAO.js → index-DrIf5j8O.js} +156 -127
- package/dist/index-DrIf5j8O.js.map +1 -0
- package/dist/index-MgXERLzL.js +3090 -0
- package/dist/index-MgXERLzL.js.map +1 -0
- package/dist/{index-DmLoihN1.js → index-WfXtYVMt.js} +134 -131
- package/dist/index-WfXtYVMt.js.map +1 -0
- package/dist/index.d.ts +38 -6
- package/dist/index.js +5 -5
- package/dist/models/index.js +7 -503
- package/dist/models/index.js.map +1 -1
- package/dist/plugins/index.js +10 -10
- package/dist/services/index.js +1 -1
- package/lib/index.umd.js +11 -11
- package/lib/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/dist/Preferences-BF2fcXrn.js +0 -1539
- package/dist/Preferences-BF2fcXrn.js.map +0 -1
- package/dist/index-Bb0FiU2c.js.map +0 -1
- package/dist/index-BgkZW91u.js +0 -4245
- package/dist/index-BgkZW91u.js.map +0 -1
- package/dist/index-D97lUU3h.js.map +0 -1
- package/dist/index-DTHY5rAO.js.map +0 -1
- package/dist/index-DmLoihN1.js.map +0 -1
|
@@ -0,0 +1,2701 @@
|
|
|
1
|
+
const He = () => {
|
|
2
|
+
let e, t;
|
|
3
|
+
return { promise: new Promise((n, s) => {
|
|
4
|
+
e = n, t = s;
|
|
5
|
+
}), resolve: e, reject: t };
|
|
6
|
+
};
|
|
7
|
+
Promise.withResolvers || (Promise.withResolvers = He);
|
|
8
|
+
var Fe = Object.defineProperty, x = (e, t) => Fe(e, "name", { value: t, configurable: !0 });
|
|
9
|
+
function We() {
|
|
10
|
+
}
|
|
11
|
+
x(We, "noop");
|
|
12
|
+
function j(e) {
|
|
13
|
+
return e == null;
|
|
14
|
+
}
|
|
15
|
+
x(j, "isNullable");
|
|
16
|
+
function Ke(e) {
|
|
17
|
+
return !j(e);
|
|
18
|
+
}
|
|
19
|
+
x(Ke, "isNonNullable");
|
|
20
|
+
function te(e) {
|
|
21
|
+
return e && typeof e == "object" && !Array.isArray(e);
|
|
22
|
+
}
|
|
23
|
+
x(te, "isPlainObject");
|
|
24
|
+
function Ae(e, t) {
|
|
25
|
+
return Object.fromEntries(Object.entries(e).filter(([r, n]) => t(r, n)));
|
|
26
|
+
}
|
|
27
|
+
x(Ae, "filterKeys");
|
|
28
|
+
function q(e, t) {
|
|
29
|
+
return Object.fromEntries(Object.entries(e).map(([r, n]) => [r, t(n, r)]));
|
|
30
|
+
}
|
|
31
|
+
x(q, "mapValues");
|
|
32
|
+
function ve(e, t, r) {
|
|
33
|
+
if (!t) return { ...e };
|
|
34
|
+
const n = {};
|
|
35
|
+
for (const s of t)
|
|
36
|
+
(r || e[s] !== void 0) && (n[s] = e[s]);
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
x(ve, "pick");
|
|
40
|
+
function ze(e, t) {
|
|
41
|
+
if (!t) return { ...e };
|
|
42
|
+
const r = { ...e };
|
|
43
|
+
for (const n of t)
|
|
44
|
+
Reflect.deleteProperty(r, n);
|
|
45
|
+
return r;
|
|
46
|
+
}
|
|
47
|
+
x(ze, "omit");
|
|
48
|
+
function P(e, t, r) {
|
|
49
|
+
return Object.defineProperty(e, t, { writable: !0, value: r, enumerable: !1 });
|
|
50
|
+
}
|
|
51
|
+
x(P, "defineProperty");
|
|
52
|
+
function Ye(e, t) {
|
|
53
|
+
return t.every((r) => e.includes(r));
|
|
54
|
+
}
|
|
55
|
+
x(Ye, "contain");
|
|
56
|
+
function Ge(e, t) {
|
|
57
|
+
return e.filter((r) => t.includes(r));
|
|
58
|
+
}
|
|
59
|
+
x(Ge, "intersection");
|
|
60
|
+
function Je(e, t) {
|
|
61
|
+
return e.filter((r) => !t.includes(r));
|
|
62
|
+
}
|
|
63
|
+
x(Je, "difference");
|
|
64
|
+
function Ve(e, t) {
|
|
65
|
+
return Array.from(/* @__PURE__ */ new Set([...e, ...t]));
|
|
66
|
+
}
|
|
67
|
+
x(Ve, "union");
|
|
68
|
+
function Qe(e) {
|
|
69
|
+
return [...new Set(e)];
|
|
70
|
+
}
|
|
71
|
+
x(Qe, "deduplicate");
|
|
72
|
+
function M(e, t) {
|
|
73
|
+
const r = e?.indexOf(t);
|
|
74
|
+
return r >= 0 ? (e.splice(r, 1), !0) : !1;
|
|
75
|
+
}
|
|
76
|
+
x(M, "remove");
|
|
77
|
+
function Xe(e) {
|
|
78
|
+
return Array.isArray(e) ? e : j(e) ? [] : [e];
|
|
79
|
+
}
|
|
80
|
+
x(Xe, "makeArray");
|
|
81
|
+
function F(e, t) {
|
|
82
|
+
return arguments.length === 1 ? (r) => F(e, r) : e in globalThis && t instanceof globalThis[e] || Object.prototype.toString.call(t).slice(8, -1) === e;
|
|
83
|
+
}
|
|
84
|
+
x(F, "is");
|
|
85
|
+
function Z(e) {
|
|
86
|
+
return F("ArrayBuffer", e) || F("SharedArrayBuffer", e);
|
|
87
|
+
}
|
|
88
|
+
x(Z, "isArrayBufferLike");
|
|
89
|
+
function _e(e) {
|
|
90
|
+
return Z(e) || ArrayBuffer.isView(e);
|
|
91
|
+
}
|
|
92
|
+
x(_e, "isArrayBufferSource");
|
|
93
|
+
var N;
|
|
94
|
+
((e) => {
|
|
95
|
+
e.is = Z, e.isSource = _e;
|
|
96
|
+
function t(o) {
|
|
97
|
+
return ArrayBuffer.isView(o) ? o.buffer.slice(o.byteOffset, o.byteOffset + o.byteLength) : o;
|
|
98
|
+
}
|
|
99
|
+
e.fromSource = t, x(t, "fromSource");
|
|
100
|
+
function r(o) {
|
|
101
|
+
if (typeof Buffer < "u")
|
|
102
|
+
return Buffer.from(o).toString("base64");
|
|
103
|
+
let u = "";
|
|
104
|
+
const l = new Uint8Array(o);
|
|
105
|
+
for (let h = 0; h < l.byteLength; h++)
|
|
106
|
+
u += String.fromCharCode(l[h]);
|
|
107
|
+
return btoa(u);
|
|
108
|
+
}
|
|
109
|
+
e.toBase64 = r, x(r, "toBase64");
|
|
110
|
+
function n(o) {
|
|
111
|
+
return typeof Buffer < "u" ? t(Buffer.from(o, "base64")) : Uint8Array.from(atob(o), (u) => u.charCodeAt(0));
|
|
112
|
+
}
|
|
113
|
+
e.fromBase64 = n, x(n, "fromBase64");
|
|
114
|
+
function s(o) {
|
|
115
|
+
return typeof Buffer < "u" ? Buffer.from(o).toString("hex") : Array.from(new Uint8Array(o), (u) => u.toString(16).padStart(2, "0")).join("");
|
|
116
|
+
}
|
|
117
|
+
e.toHex = s, x(s, "toHex");
|
|
118
|
+
function i(o) {
|
|
119
|
+
if (typeof Buffer < "u") return t(Buffer.from(o, "hex"));
|
|
120
|
+
const u = o.length % 2 === 0 ? o : o.slice(0, o.length - 1), l = [];
|
|
121
|
+
for (let h = 0; h < u.length; h += 2)
|
|
122
|
+
l.push(parseInt(`${u[h]}${u[h + 1]}`, 16));
|
|
123
|
+
return Uint8Array.from(l).buffer;
|
|
124
|
+
}
|
|
125
|
+
e.fromHex = i, x(i, "fromHex");
|
|
126
|
+
})(N || (N = {}));
|
|
127
|
+
N.fromBase64;
|
|
128
|
+
N.toBase64;
|
|
129
|
+
N.fromHex;
|
|
130
|
+
N.toHex;
|
|
131
|
+
function ne(e, t = /* @__PURE__ */ new Map()) {
|
|
132
|
+
if (!e || typeof e != "object") return e;
|
|
133
|
+
if (F("Date", e)) return new Date(e.valueOf());
|
|
134
|
+
if (F("RegExp", e)) return new RegExp(e.source, e.flags);
|
|
135
|
+
if (Z(e)) return e.slice(0);
|
|
136
|
+
if (ArrayBuffer.isView(e)) return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
137
|
+
const r = t.get(e);
|
|
138
|
+
if (r) return r;
|
|
139
|
+
if (Array.isArray(e)) {
|
|
140
|
+
const s = [];
|
|
141
|
+
return t.set(e, s), e.forEach((i, o) => {
|
|
142
|
+
s[o] = Reflect.apply(ne, null, [i, t]);
|
|
143
|
+
}), s;
|
|
144
|
+
}
|
|
145
|
+
const n = Object.create(Object.getPrototypeOf(e));
|
|
146
|
+
t.set(e, n);
|
|
147
|
+
for (const s of Reflect.ownKeys(e)) {
|
|
148
|
+
const i = { ...Reflect.getOwnPropertyDescriptor(e, s) };
|
|
149
|
+
"value" in i && (i.value = Reflect.apply(ne, null, [i.value, t])), Reflect.defineProperty(n, s, i);
|
|
150
|
+
}
|
|
151
|
+
return n;
|
|
152
|
+
}
|
|
153
|
+
x(ne, "clone");
|
|
154
|
+
function K(e, t, r) {
|
|
155
|
+
if (e === t || !r && j(e) && j(t)) return !0;
|
|
156
|
+
if (typeof e != typeof t || typeof e != "object" || !e || !t) return !1;
|
|
157
|
+
function n(s, i) {
|
|
158
|
+
return s(e) ? s(t) ? i(e, t) : !1 : s(t) ? !1 : void 0;
|
|
159
|
+
}
|
|
160
|
+
return x(n, "check"), n(Array.isArray, (s, i) => s.length === i.length && s.every((o, u) => K(o, i[u]))) ?? n(F("Date"), (s, i) => s.valueOf() === i.valueOf()) ?? n(F("RegExp"), (s, i) => s.source === i.source && s.flags === i.flags) ?? n(Z, (s, i) => {
|
|
161
|
+
if (s.byteLength !== i.byteLength) return !1;
|
|
162
|
+
const o = new Uint8Array(s), u = new Uint8Array(i);
|
|
163
|
+
for (let l = 0; l < o.length; l++)
|
|
164
|
+
if (o[l] !== u[l]) return !1;
|
|
165
|
+
return !0;
|
|
166
|
+
}) ?? Object.keys({ ...e, ...t }).every((s) => K(e[s], t[s], r));
|
|
167
|
+
}
|
|
168
|
+
x(K, "deepEqual");
|
|
169
|
+
function Ze(e) {
|
|
170
|
+
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
171
|
+
}
|
|
172
|
+
x(Ze, "capitalize");
|
|
173
|
+
function et(e) {
|
|
174
|
+
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
175
|
+
}
|
|
176
|
+
x(et, "uncapitalize");
|
|
177
|
+
function tt(e) {
|
|
178
|
+
return e.replace(/[_-][a-z]/g, (t) => t.slice(1).toUpperCase());
|
|
179
|
+
}
|
|
180
|
+
x(tt, "camelCase");
|
|
181
|
+
function de(e, t, r) {
|
|
182
|
+
const n = [];
|
|
183
|
+
let s = 0;
|
|
184
|
+
for (let i = 0; i < e.length; i++) {
|
|
185
|
+
const o = e.charCodeAt(i);
|
|
186
|
+
if (o >= 65 && o <= 90) {
|
|
187
|
+
if (s === 1) {
|
|
188
|
+
const u = e.charCodeAt(i + 1);
|
|
189
|
+
u >= 97 && u <= 122 && n.push(r), n.push(o + 32);
|
|
190
|
+
} else
|
|
191
|
+
s !== 0 && n.push(r), n.push(o + 32);
|
|
192
|
+
s = 1;
|
|
193
|
+
} else o >= 97 && o <= 122 ? (n.push(o), s = 2) : t.includes(o) ? (s !== 0 && n.push(r), s = 0) : n.push(o);
|
|
194
|
+
}
|
|
195
|
+
return String.fromCharCode(...n);
|
|
196
|
+
}
|
|
197
|
+
x(de, "tokenize");
|
|
198
|
+
function rt(e) {
|
|
199
|
+
return de(e, [45, 95], 45);
|
|
200
|
+
}
|
|
201
|
+
x(rt, "paramCase");
|
|
202
|
+
function nt(e) {
|
|
203
|
+
return de(e, [45, 95], 95);
|
|
204
|
+
}
|
|
205
|
+
x(nt, "snakeCase");
|
|
206
|
+
function it(e) {
|
|
207
|
+
return typeof e != "string" ? `[${e.toString()}]` : /^[a-z_$][\w$]*$/i.test(e) ? `.${e}` : `[${JSON.stringify(e)}]`;
|
|
208
|
+
}
|
|
209
|
+
x(it, "formatProperty");
|
|
210
|
+
function je(e) {
|
|
211
|
+
return e.replace(/\/$/, "");
|
|
212
|
+
}
|
|
213
|
+
x(je, "trimSlash");
|
|
214
|
+
function st(e) {
|
|
215
|
+
return e.startsWith("/") || (e = "/" + e), je(e);
|
|
216
|
+
}
|
|
217
|
+
x(st, "sanitize");
|
|
218
|
+
var Oe;
|
|
219
|
+
((e) => {
|
|
220
|
+
e.millisecond = 1, e.second = 1e3, e.minute = e.second * 60, e.hour = e.minute * 60, e.day = e.hour * 24, e.week = e.day * 7;
|
|
221
|
+
let t = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
222
|
+
function r(g) {
|
|
223
|
+
t = g;
|
|
224
|
+
}
|
|
225
|
+
e.setTimezoneOffset = r, x(r, "setTimezoneOffset");
|
|
226
|
+
function n() {
|
|
227
|
+
return t;
|
|
228
|
+
}
|
|
229
|
+
e.getTimezoneOffset = n, x(n, "getTimezoneOffset");
|
|
230
|
+
function s(g = /* @__PURE__ */ new Date(), w) {
|
|
231
|
+
return typeof g == "number" && (g = new Date(g)), w === void 0 && (w = t), Math.floor((g.valueOf() / e.minute - w) / 1440);
|
|
232
|
+
}
|
|
233
|
+
e.getDateNumber = s, x(s, "getDateNumber");
|
|
234
|
+
function i(g, w) {
|
|
235
|
+
const _ = new Date(g * e.day);
|
|
236
|
+
return w === void 0 && (w = t), new Date(+_ + w * e.minute);
|
|
237
|
+
}
|
|
238
|
+
e.fromDateNumber = i, x(i, "fromDateNumber");
|
|
239
|
+
const o = /\d+(?:\.\d+)?/.source, u = new RegExp(`^${[
|
|
240
|
+
"w(?:eek(?:s)?)?",
|
|
241
|
+
"d(?:ay(?:s)?)?",
|
|
242
|
+
"h(?:our(?:s)?)?",
|
|
243
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
244
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
245
|
+
].map((g) => `(${o}${g})?`).join("")}$`);
|
|
246
|
+
function l(g) {
|
|
247
|
+
const w = u.exec(g);
|
|
248
|
+
return w ? (parseFloat(w[1]) * e.week || 0) + (parseFloat(w[2]) * e.day || 0) + (parseFloat(w[3]) * e.hour || 0) + (parseFloat(w[4]) * e.minute || 0) + (parseFloat(w[5]) * e.second || 0) : 0;
|
|
249
|
+
}
|
|
250
|
+
e.parseTime = l, x(l, "parseTime");
|
|
251
|
+
function h(g) {
|
|
252
|
+
const w = l(g);
|
|
253
|
+
return w ? g = Date.now() + w : /^\d{1,2}(:\d{1,2}){1,2}$/.test(g) ? g = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${g}` : /^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(g) && (g = `${(/* @__PURE__ */ new Date()).getFullYear()}-${g}`), g ? new Date(g) : /* @__PURE__ */ new Date();
|
|
254
|
+
}
|
|
255
|
+
e.parseDate = h, x(h, "parseDate");
|
|
256
|
+
function d(g) {
|
|
257
|
+
const w = Math.abs(g);
|
|
258
|
+
return w >= e.day - e.hour / 2 ? Math.round(g / e.day) + "d" : w >= e.hour - e.minute / 2 ? Math.round(g / e.hour) + "h" : w >= e.minute - e.second / 2 ? Math.round(g / e.minute) + "m" : w >= e.second ? Math.round(g / e.second) + "s" : g + "ms";
|
|
259
|
+
}
|
|
260
|
+
e.format = d, x(d, "format");
|
|
261
|
+
function R(g, w = 2) {
|
|
262
|
+
return g.toString().padStart(w, "0");
|
|
263
|
+
}
|
|
264
|
+
e.toDigits = R, x(R, "toDigits");
|
|
265
|
+
function b(g, w = /* @__PURE__ */ new Date()) {
|
|
266
|
+
return g.replace("yyyy", w.getFullYear().toString()).replace("yy", w.getFullYear().toString().slice(2)).replace("MM", R(w.getMonth() + 1)).replace("dd", R(w.getDate())).replace("hh", R(w.getHours())).replace("mm", R(w.getMinutes())).replace("ss", R(w.getSeconds())).replace("SSS", R(w.getMilliseconds(), 3));
|
|
267
|
+
}
|
|
268
|
+
e.template = b, x(b, "template");
|
|
269
|
+
})(Oe || (Oe = {}));
|
|
270
|
+
var ot = Object.defineProperty, k = (e, t) => ot(e, "name", { value: t, configurable: !0 }), m = {
|
|
271
|
+
// internal symbols
|
|
272
|
+
shadow: Symbol.for("cordis.shadow"),
|
|
273
|
+
receiver: Symbol.for("cordis.receiver"),
|
|
274
|
+
original: Symbol.for("cordis.original"),
|
|
275
|
+
// context symbols
|
|
276
|
+
store: Symbol.for("cordis.store"),
|
|
277
|
+
events: Symbol.for("cordis.events"),
|
|
278
|
+
static: Symbol.for("cordis.static"),
|
|
279
|
+
filter: Symbol.for("cordis.filter"),
|
|
280
|
+
expose: Symbol.for("cordis.expose"),
|
|
281
|
+
isolate: Symbol.for("cordis.isolate"),
|
|
282
|
+
internal: Symbol.for("cordis.internal"),
|
|
283
|
+
intercept: Symbol.for("cordis.intercept"),
|
|
284
|
+
// service symbols
|
|
285
|
+
setup: Symbol.for("cordis.setup"),
|
|
286
|
+
invoke: Symbol.for("cordis.invoke"),
|
|
287
|
+
extend: Symbol.for("cordis.extend"),
|
|
288
|
+
tracker: Symbol.for("cordis.tracker"),
|
|
289
|
+
provide: Symbol.for("cordis.provide"),
|
|
290
|
+
immediate: Symbol.for("cordis.immediate")
|
|
291
|
+
}, ct = function* () {
|
|
292
|
+
}.constructor, Re = async function* () {
|
|
293
|
+
}.constructor;
|
|
294
|
+
function ye(e) {
|
|
295
|
+
return !(!e.prototype || e instanceof ct || Re !== Function && e instanceof Re);
|
|
296
|
+
}
|
|
297
|
+
k(ye, "isConstructor");
|
|
298
|
+
function ee(e, t) {
|
|
299
|
+
const r = e.Config || e.schema;
|
|
300
|
+
return r && e.schema !== !1 && (t = r(t)), t ?? {};
|
|
301
|
+
}
|
|
302
|
+
k(ee, "resolveConfig");
|
|
303
|
+
function Le(e) {
|
|
304
|
+
return [Map, Set, Date, Promise].some((t) => e instanceof t);
|
|
305
|
+
}
|
|
306
|
+
k(Le, "isUnproxyable");
|
|
307
|
+
function ge(e, t) {
|
|
308
|
+
if (e === Object.prototype) return t;
|
|
309
|
+
const r = Object.create(ge(Object.getPrototypeOf(e), t));
|
|
310
|
+
for (const n of Reflect.ownKeys(e))
|
|
311
|
+
Object.defineProperty(r, n, Object.getOwnPropertyDescriptor(e, n));
|
|
312
|
+
return r;
|
|
313
|
+
}
|
|
314
|
+
k(ge, "joinPrototype");
|
|
315
|
+
function me(e) {
|
|
316
|
+
return e && (typeof e == "object" || typeof e == "function");
|
|
317
|
+
}
|
|
318
|
+
k(me, "isObject");
|
|
319
|
+
function B(e, t, r) {
|
|
320
|
+
if (!me(t)) return t;
|
|
321
|
+
if (Object.hasOwn(t, m.shadow))
|
|
322
|
+
return Object.getPrototypeOf(t);
|
|
323
|
+
const n = t[m.tracker];
|
|
324
|
+
return n ? ae(e, t, n, r) : t;
|
|
325
|
+
}
|
|
326
|
+
k(B, "getTraceable");
|
|
327
|
+
function X(e, t) {
|
|
328
|
+
return t ? new Proxy(e, {
|
|
329
|
+
get: /* @__PURE__ */ k((r, n, s) => n in t && n !== "constructor" ? Reflect.get(t, n, s) : Reflect.get(r, n, s), "get"),
|
|
330
|
+
set: /* @__PURE__ */ k((r, n, s, i) => n in t && n !== "constructor" ? Reflect.set(t, n, s, i) : Reflect.set(r, n, s, i), "set")
|
|
331
|
+
}) : e;
|
|
332
|
+
}
|
|
333
|
+
k(X, "withProps");
|
|
334
|
+
function ie(e, t, r) {
|
|
335
|
+
return X(e, Object.defineProperty(/* @__PURE__ */ Object.create(null), t, {
|
|
336
|
+
value: r,
|
|
337
|
+
writable: !1
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
k(ie, "withProp");
|
|
341
|
+
function fe(e, t, r, n) {
|
|
342
|
+
if (!r) return n;
|
|
343
|
+
const s = Reflect.getOwnPropertyDescriptor(t, r)?.value;
|
|
344
|
+
return s ? ie(n, r, e.extend({ [m.shadow]: s })) : n;
|
|
345
|
+
}
|
|
346
|
+
k(fe, "createShadow");
|
|
347
|
+
function Te(e, t, r, n) {
|
|
348
|
+
return new Proxy(t, {
|
|
349
|
+
apply: /* @__PURE__ */ k((s, i, o) => (i === r && (i = n), o = o.map((u) => typeof u != "function" || u[m.original] ? u : new Proxy(u, {
|
|
350
|
+
get: /* @__PURE__ */ k((l, h, d) => {
|
|
351
|
+
if (h === m.original) return l;
|
|
352
|
+
const R = Reflect.get(l, h, d);
|
|
353
|
+
return h === "toString" && R === Function.prototype.toString ? function(...b) {
|
|
354
|
+
return Reflect.apply(R, this === d ? l : this, b);
|
|
355
|
+
} : R;
|
|
356
|
+
}, "get"),
|
|
357
|
+
apply: /* @__PURE__ */ k((l, h, d) => Reflect.apply(l, B(e, h), d.map((R) => B(e, R))), "apply"),
|
|
358
|
+
construct: /* @__PURE__ */ k((l, h, d) => Reflect.construct(l, h.map((R) => B(e, R)), d), "construct")
|
|
359
|
+
})), B(e, Reflect.apply(s, i, o))), "apply")
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
k(Te, "createShadowMethod");
|
|
363
|
+
function ae(e, t, r, n) {
|
|
364
|
+
e[m.shadow] && (e = Object.getPrototypeOf(e));
|
|
365
|
+
const s = new Proxy(t, {
|
|
366
|
+
get: /* @__PURE__ */ k((i, o, u) => {
|
|
367
|
+
if (o === m.original) return i;
|
|
368
|
+
if (o === r.property) return e;
|
|
369
|
+
if (typeof o == "symbol")
|
|
370
|
+
return Reflect.get(i, o, u);
|
|
371
|
+
if (r.associate && e[m.internal][`${r.associate}.${o}`])
|
|
372
|
+
return Reflect.get(e, `${r.associate}.${o}`, ie(e, m.receiver, u));
|
|
373
|
+
const l = fe(e, i, r.property, u), h = Reflect.get(i, o, l), d = h?.[m.tracker];
|
|
374
|
+
return d ? ae(e, h, d) : !n && typeof h == "function" ? Te(e, h, u, l) : h;
|
|
375
|
+
}, "get"),
|
|
376
|
+
set: /* @__PURE__ */ k((i, o, u, l) => {
|
|
377
|
+
if (o === m.original || o === r.property) return !1;
|
|
378
|
+
if (typeof o == "symbol")
|
|
379
|
+
return Reflect.set(i, o, u, l);
|
|
380
|
+
if (r.associate && e[m.internal][`${r.associate}.${o}`])
|
|
381
|
+
return Reflect.set(e, `${r.associate}.${o}`, u, ie(e, m.receiver, l));
|
|
382
|
+
const h = fe(e, i, r.property, l);
|
|
383
|
+
return Reflect.set(i, o, u, h);
|
|
384
|
+
}, "set"),
|
|
385
|
+
apply: /* @__PURE__ */ k((i, o, u) => be(s, i, o, u), "apply")
|
|
386
|
+
});
|
|
387
|
+
return s;
|
|
388
|
+
}
|
|
389
|
+
k(ae, "createTraceable");
|
|
390
|
+
function be(e, t, r, n) {
|
|
391
|
+
return t[m.invoke] ? t[m.invoke].apply(e, n) : Reflect.apply(t, r, n);
|
|
392
|
+
}
|
|
393
|
+
k(be, "applyTraceable");
|
|
394
|
+
function ue(e, t, r) {
|
|
395
|
+
const n = /* @__PURE__ */ k(function(...s) {
|
|
396
|
+
const i = ae(n.ctx, n, r);
|
|
397
|
+
return be(i, n, this, s);
|
|
398
|
+
}, "self");
|
|
399
|
+
return P(n, "name", e), Object.setPrototypeOf(n, t);
|
|
400
|
+
}
|
|
401
|
+
k(ue, "createCallable");
|
|
402
|
+
var at = class z {
|
|
403
|
+
constructor(t) {
|
|
404
|
+
this.ctx = t, P(this, m.tracker, {
|
|
405
|
+
associate: "reflect",
|
|
406
|
+
property: "ctx"
|
|
407
|
+
}), this._mixin("reflect", ["get", "set", "provide", "accessor", "mixin", "alias"]), this._mixin("scope", ["config", "runtime", "effect", "collect", "accept", "decline"]), this._mixin("registry", ["using", "inject", "plugin"]), this._mixin("lifecycle", ["on", "once", "parallel", "emit", "serial", "bail", "start", "stop"]);
|
|
408
|
+
}
|
|
409
|
+
static {
|
|
410
|
+
k(this, "ReflectService");
|
|
411
|
+
}
|
|
412
|
+
static resolveInject(t, r) {
|
|
413
|
+
let n = t[m.internal][r];
|
|
414
|
+
for (; n?.type === "alias"; )
|
|
415
|
+
r = n.name, n = t[m.internal][r];
|
|
416
|
+
return [r, n];
|
|
417
|
+
}
|
|
418
|
+
static checkInject(t, r, n) {
|
|
419
|
+
if (t = t[m.shadow] ?? t, ["prototype", "then", "registry", "lifecycle"].includes(r) || r[0] === "$" || r[0] === "_" || !t.runtime.plugin || t.bail(t, "internal/inject", r)) return;
|
|
420
|
+
const s = n.stack.split(`
|
|
421
|
+
`);
|
|
422
|
+
s.splice(1, 1), n.stack = s.join(`
|
|
423
|
+
`), t.emit(t, "internal/warning", n);
|
|
424
|
+
}
|
|
425
|
+
static handler = {
|
|
426
|
+
get: /* @__PURE__ */ k((t, r, n) => {
|
|
427
|
+
if (typeof r != "string") return Reflect.get(t, r, n);
|
|
428
|
+
if (Reflect.has(t, r))
|
|
429
|
+
return B(n, Reflect.get(t, r, n), !0);
|
|
430
|
+
const [s, i] = z.resolveInject(t, r), o = new Error(`property ${s} is not registered, declare it as \`inject\` to suppress this warning`);
|
|
431
|
+
return i ? i.type === "accessor" ? i.get.call(n, n[m.receiver]) : (i.builtin || z.checkInject(n, s, o), n.reflect.get(s)) : (z.checkInject(n, s, o), Reflect.get(t, s, n));
|
|
432
|
+
}, "get"),
|
|
433
|
+
set: /* @__PURE__ */ k((t, r, n, s) => {
|
|
434
|
+
if (typeof r != "string") return Reflect.set(t, r, n, s);
|
|
435
|
+
const [i, o] = z.resolveInject(t, r);
|
|
436
|
+
return o ? o.type === "accessor" ? o.set ? o.set.call(s, n, s[m.receiver]) : !1 : (s.reflect.set(i, n), !0) : Reflect.set(t, i, n, s);
|
|
437
|
+
}, "set"),
|
|
438
|
+
has: /* @__PURE__ */ k((t, r) => {
|
|
439
|
+
if (typeof r != "string") return Reflect.has(t, r);
|
|
440
|
+
if (Reflect.has(t, r)) return !0;
|
|
441
|
+
const [, n] = z.resolveInject(t, r);
|
|
442
|
+
return !!n;
|
|
443
|
+
}, "has")
|
|
444
|
+
};
|
|
445
|
+
get(t) {
|
|
446
|
+
if (this.ctx[m.internal][t]?.type !== "service") return;
|
|
447
|
+
const n = this.ctx[m.isolate][t], s = this.ctx[m.store][n]?.value;
|
|
448
|
+
return B(this.ctx, s);
|
|
449
|
+
}
|
|
450
|
+
set(t, r) {
|
|
451
|
+
this.provide(t);
|
|
452
|
+
const n = this.ctx[m.isolate][t], s = this.ctx[m.store][n]?.value;
|
|
453
|
+
r ??= void 0;
|
|
454
|
+
let i = /* @__PURE__ */ k(() => {
|
|
455
|
+
}, "dispose");
|
|
456
|
+
if (s === r) return i;
|
|
457
|
+
if (!j(r) && !j(s))
|
|
458
|
+
throw new Error(`service ${t} has been registered`);
|
|
459
|
+
const o = this.ctx;
|
|
460
|
+
j(r) || (i = o.effect(() => () => {
|
|
461
|
+
o.set(t, void 0);
|
|
462
|
+
})), Le(r) && o.emit(o, "internal/warning", new Error(`service ${t} is an unproxyable object, which may lead to unexpected behavior`));
|
|
463
|
+
const u = Object.create(o);
|
|
464
|
+
return u[m.filter] = (l) => o[m.isolate][t] === l[m.isolate][t], o.emit(u, "internal/before-service", t, r), o[m.store][n] = { value: r, source: o }, o.emit(u, "internal/service", t, s), i;
|
|
465
|
+
}
|
|
466
|
+
provide(t, r, n) {
|
|
467
|
+
const s = this.ctx.root[m.internal];
|
|
468
|
+
if (t in s) return;
|
|
469
|
+
const i = Symbol(t);
|
|
470
|
+
s[t] = { type: "service", builtin: n }, this.ctx.root[m.isolate][t] = i, me(r) && (this.ctx[m.store][i] = { value: r, source: null }, P(r, m.tracker, {
|
|
471
|
+
associate: t,
|
|
472
|
+
property: "ctx"
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
_accessor(t, r) {
|
|
476
|
+
const n = this.ctx.root[m.internal];
|
|
477
|
+
return t in n ? () => {
|
|
478
|
+
} : (n[t] = { type: "accessor", ...r }, () => delete this.ctx.root[m.isolate][t]);
|
|
479
|
+
}
|
|
480
|
+
accessor(t, r) {
|
|
481
|
+
this.ctx.scope.effect(() => this._accessor(t, r));
|
|
482
|
+
}
|
|
483
|
+
alias(t, r) {
|
|
484
|
+
const n = this.ctx.root[m.internal];
|
|
485
|
+
if (!(t in n))
|
|
486
|
+
for (const s of r)
|
|
487
|
+
n[s] ||= { type: "alias", name: t };
|
|
488
|
+
}
|
|
489
|
+
_mixin(t, r) {
|
|
490
|
+
const n = Array.isArray(r) ? r.map((o) => [o, o]) : Object.entries(r), s = typeof t == "string" ? (o) => o[t] : () => t, i = n.map(([o, u]) => this._accessor(u, {
|
|
491
|
+
get(l) {
|
|
492
|
+
const h = s(this);
|
|
493
|
+
if (j(h)) return h;
|
|
494
|
+
const d = l ? X(l, h) : h, R = Reflect.get(h, o, d);
|
|
495
|
+
return typeof R != "function" ? R : R.bind(d ?? h);
|
|
496
|
+
},
|
|
497
|
+
set(l, h) {
|
|
498
|
+
const d = s(this), R = h ? X(h, d) : d;
|
|
499
|
+
return Reflect.set(d, o, l, R);
|
|
500
|
+
}
|
|
501
|
+
}));
|
|
502
|
+
return () => i.forEach((o) => o());
|
|
503
|
+
}
|
|
504
|
+
mixin(t, r) {
|
|
505
|
+
this.ctx.scope.effect(() => this._mixin(t, r));
|
|
506
|
+
}
|
|
507
|
+
trace(t) {
|
|
508
|
+
return B(this.ctx, t);
|
|
509
|
+
}
|
|
510
|
+
bind(t) {
|
|
511
|
+
return new Proxy(t, {
|
|
512
|
+
apply: /* @__PURE__ */ k((r, n, s) => r.apply(this.trace(n), s.map((i) => this.trace(i))), "apply")
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}, le = at;
|
|
516
|
+
function he(e) {
|
|
517
|
+
return e !== null && e !== !1 && e !== void 0;
|
|
518
|
+
}
|
|
519
|
+
k(he, "isBailed");
|
|
520
|
+
var ft = class {
|
|
521
|
+
constructor(e) {
|
|
522
|
+
this.ctx = e, P(this, m.tracker, {
|
|
523
|
+
associate: "lifecycle",
|
|
524
|
+
property: "ctx"
|
|
525
|
+
}), P(this.on("internal/listener", function(r, n, s) {
|
|
526
|
+
const i = s.prepend ? "unshift" : "push";
|
|
527
|
+
if (r === "ready")
|
|
528
|
+
return this.lifecycle.isActive ? (this.scope.ensure(async () => n()), () => !1) : void 0;
|
|
529
|
+
if (r === "dispose")
|
|
530
|
+
return this.scope.disposables[i](n), P(n, "name", "event <dispose>"), () => M(this.scope.disposables, n);
|
|
531
|
+
if (r === "fork")
|
|
532
|
+
return this.scope.runtime.forkables[i](n), this.scope.collect("event <fork>", () => M(this.scope.runtime.forkables, n));
|
|
533
|
+
}), I.static, e.scope);
|
|
534
|
+
for (const r of ["info", "error", "warning"])
|
|
535
|
+
P(this.on(`internal/${r}`, (n, ...s) => {
|
|
536
|
+
this._hooks[`internal/${r}`].length > 1;
|
|
537
|
+
}), I.static, e.scope);
|
|
538
|
+
P(this.on("internal/before-service", function(r) {
|
|
539
|
+
for (const n of this.registry.values()) {
|
|
540
|
+
if (!n.inject[r]?.required) continue;
|
|
541
|
+
const s = n.isReusable ? n.children : [n];
|
|
542
|
+
for (const i of s)
|
|
543
|
+
this[m.filter](i.ctx) && (i.updateStatus(), i.reset());
|
|
544
|
+
}
|
|
545
|
+
}, { global: !0 }), I.static, e.scope), P(this.on("internal/service", function(r) {
|
|
546
|
+
for (const n of this.registry.values()) {
|
|
547
|
+
if (!n.inject[r]?.required) continue;
|
|
548
|
+
const s = n.isReusable ? n.children : [n];
|
|
549
|
+
for (const i of s)
|
|
550
|
+
this[m.filter](i.ctx) && i.start();
|
|
551
|
+
}
|
|
552
|
+
}, { global: !0 }), I.static, e.scope);
|
|
553
|
+
const t = /* @__PURE__ */ k((r, n) => {
|
|
554
|
+
if (!r.runtime.plugin) return !1;
|
|
555
|
+
for (const s in r.runtime.inject)
|
|
556
|
+
if (n === le.resolveInject(r.ctx, s)[0]) return !0;
|
|
557
|
+
return t(r.parent.scope, n);
|
|
558
|
+
}, "checkInject");
|
|
559
|
+
P(this.on("internal/inject", function(r) {
|
|
560
|
+
return t(this.scope, r);
|
|
561
|
+
}, { global: !0 }), I.static, e.scope);
|
|
562
|
+
}
|
|
563
|
+
static {
|
|
564
|
+
k(this, "Lifecycle");
|
|
565
|
+
}
|
|
566
|
+
isActive = !1;
|
|
567
|
+
_tasks = /* @__PURE__ */ new Set();
|
|
568
|
+
_hooks = {};
|
|
569
|
+
async flush() {
|
|
570
|
+
for (; this._tasks.size; )
|
|
571
|
+
await Promise.all(Array.from(this._tasks));
|
|
572
|
+
}
|
|
573
|
+
filterHooks(e, t) {
|
|
574
|
+
return t = B(this.ctx, t), e.slice().filter((r) => {
|
|
575
|
+
const n = t?.[I.filter];
|
|
576
|
+
return r.global || !n || n.call(t, r.ctx);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
*dispatch(e, t) {
|
|
580
|
+
const r = typeof t[0] == "object" || typeof t[0] == "function" ? t.shift() : null, n = t.shift();
|
|
581
|
+
n !== "internal/event" && this.emit("internal/event", e, n, t, r);
|
|
582
|
+
for (const s of this.filterHooks(this._hooks[n] || [], r))
|
|
583
|
+
yield s.callback.apply(r, t);
|
|
584
|
+
}
|
|
585
|
+
async parallel(...e) {
|
|
586
|
+
await Promise.all(this.dispatch("emit", e));
|
|
587
|
+
}
|
|
588
|
+
emit(...e) {
|
|
589
|
+
Array.from(this.dispatch("emit", e));
|
|
590
|
+
}
|
|
591
|
+
async serial(...e) {
|
|
592
|
+
for await (const t of this.dispatch("serial", e))
|
|
593
|
+
if (he(t)) return t;
|
|
594
|
+
}
|
|
595
|
+
bail(...e) {
|
|
596
|
+
for (const t of this.dispatch("bail", e))
|
|
597
|
+
if (he(t)) return t;
|
|
598
|
+
}
|
|
599
|
+
register(e, t, r, n) {
|
|
600
|
+
const s = n.prepend ? "unshift" : "push";
|
|
601
|
+
return t[s]({ ctx: this.ctx, callback: r, ...n }), this.ctx.state.collect(e, () => this.unregister(t, r));
|
|
602
|
+
}
|
|
603
|
+
unregister(e, t) {
|
|
604
|
+
const r = e.findIndex((n) => n.callback === t);
|
|
605
|
+
if (r >= 0)
|
|
606
|
+
return e.splice(r, 1), !0;
|
|
607
|
+
}
|
|
608
|
+
on(e, t, r) {
|
|
609
|
+
typeof r != "object" && (r = { prepend: r }), this.ctx.scope.assertActive(), t = this.ctx.reflect.bind(t);
|
|
610
|
+
const n = this.bail(this.ctx, "internal/listener", e, t, r);
|
|
611
|
+
if (n) return n;
|
|
612
|
+
const s = this._hooks[e] ||= [], i = typeof e == "string" ? `event <${e}>` : "event (Symbol)";
|
|
613
|
+
return this.register(i, s, t, r);
|
|
614
|
+
}
|
|
615
|
+
once(e, t, r) {
|
|
616
|
+
const n = this.on(e, function(...s) {
|
|
617
|
+
return n(), t.apply(this, s);
|
|
618
|
+
}, r);
|
|
619
|
+
return n;
|
|
620
|
+
}
|
|
621
|
+
async start() {
|
|
622
|
+
this.isActive = !0;
|
|
623
|
+
const e = this._hooks.ready || [];
|
|
624
|
+
for (; e.length; ) {
|
|
625
|
+
const { ctx: t, callback: r } = e.shift();
|
|
626
|
+
t.scope.ensure(async () => r());
|
|
627
|
+
}
|
|
628
|
+
await this.flush();
|
|
629
|
+
}
|
|
630
|
+
async stop() {
|
|
631
|
+
this.isActive = !1, this.ctx.scope.reset();
|
|
632
|
+
}
|
|
633
|
+
}, ut = ft, lt = /* @__PURE__ */ ((e) => (e[e.PENDING = 0] = "PENDING", e[e.LOADING = 1] = "LOADING", e[e.ACTIVE = 2] = "ACTIVE", e[e.FAILED = 3] = "FAILED", e[e.DISPOSED = 4] = "DISPOSED", e))(lt || {}), pe = class Pe extends Error {
|
|
634
|
+
constructor(t, r) {
|
|
635
|
+
super(r ?? Pe.Code[t]), this.code = t;
|
|
636
|
+
}
|
|
637
|
+
static {
|
|
638
|
+
k(this, "CordisError");
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
((e) => {
|
|
642
|
+
e.Code = {
|
|
643
|
+
INACTIVE_EFFECT: "cannot create effect on inactive context"
|
|
644
|
+
};
|
|
645
|
+
})(pe || (pe = {}));
|
|
646
|
+
var $e = class {
|
|
647
|
+
constructor(e, t) {
|
|
648
|
+
this.parent = e, this.config = t, this.uid = e.registry ? e.registry.counter : 0, this.ctx = this.context = e.extend({ scope: this }), this.proxy = new Proxy({}, {
|
|
649
|
+
get: /* @__PURE__ */ k((r, n) => Reflect.get(this.config, n), "get")
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
static {
|
|
653
|
+
k(this, "EffectScope");
|
|
654
|
+
}
|
|
655
|
+
uid;
|
|
656
|
+
ctx;
|
|
657
|
+
disposables = [];
|
|
658
|
+
error;
|
|
659
|
+
status = 0;
|
|
660
|
+
isActive = !1;
|
|
661
|
+
// Same as `this.ctx`, but with a more specific type.
|
|
662
|
+
context;
|
|
663
|
+
proxy;
|
|
664
|
+
acceptors = [];
|
|
665
|
+
tasks = /* @__PURE__ */ new Set();
|
|
666
|
+
hasError = !1;
|
|
667
|
+
get _config() {
|
|
668
|
+
return this.runtime.isReactive ? this.proxy : this.config;
|
|
669
|
+
}
|
|
670
|
+
assertActive() {
|
|
671
|
+
if (!(this.uid !== null || this.isActive))
|
|
672
|
+
throw new pe("INACTIVE_EFFECT");
|
|
673
|
+
}
|
|
674
|
+
effect(e, t) {
|
|
675
|
+
this.assertActive();
|
|
676
|
+
const r = ye(e) ? new e(this.ctx, t) : e(this.ctx, t);
|
|
677
|
+
let n = !1;
|
|
678
|
+
const s = typeof r == "function" ? r : r.dispose.bind(r), i = /* @__PURE__ */ k((...o) => {
|
|
679
|
+
if (!n)
|
|
680
|
+
return n = !0, M(this.disposables, i), s(...o);
|
|
681
|
+
}, "wrapped");
|
|
682
|
+
return this.disposables.push(i), typeof r == "function" ? i : (r.dispose = i, r);
|
|
683
|
+
}
|
|
684
|
+
collect(e, t) {
|
|
685
|
+
const r = P(() => (M(this.disposables, r), t()), "name", e);
|
|
686
|
+
return this.disposables.push(r), r;
|
|
687
|
+
}
|
|
688
|
+
restart() {
|
|
689
|
+
this.reset(), this.error = null, this.hasError = !1, this.status = 0, this.start();
|
|
690
|
+
}
|
|
691
|
+
_getStatus() {
|
|
692
|
+
return this.uid === null ? 4 : this.hasError ? 3 : this.tasks.size ? 1 : this.ready ? 2 : 0;
|
|
693
|
+
}
|
|
694
|
+
updateStatus(e) {
|
|
695
|
+
const t = this.status;
|
|
696
|
+
e?.(), this.status = this._getStatus(), t !== this.status && this.context.emit("internal/status", this, t);
|
|
697
|
+
}
|
|
698
|
+
ensure(e) {
|
|
699
|
+
const t = e().catch((r) => {
|
|
700
|
+
this.context.emit(this.ctx, "internal/error", r), this.cancel(r);
|
|
701
|
+
}).finally(() => {
|
|
702
|
+
this.updateStatus(() => this.tasks.delete(t)), this.context.events._tasks.delete(t);
|
|
703
|
+
});
|
|
704
|
+
this.updateStatus(() => this.tasks.add(t)), this.context.events._tasks.add(t);
|
|
705
|
+
}
|
|
706
|
+
cancel(e) {
|
|
707
|
+
this.error = e, this.updateStatus(() => this.hasError = !0), this.reset();
|
|
708
|
+
}
|
|
709
|
+
get ready() {
|
|
710
|
+
return Object.entries(this.runtime.inject).every(([e, t]) => !t.required || !j(this.ctx.get(e)));
|
|
711
|
+
}
|
|
712
|
+
reset() {
|
|
713
|
+
this.isActive = !1, this.disposables = this.disposables.splice(0).filter((e) => {
|
|
714
|
+
if (this.uid !== null && e[I.static] === this) return !0;
|
|
715
|
+
(async () => e())().catch((t) => {
|
|
716
|
+
this.context.emit(this.ctx, "internal/error", t);
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
init(e) {
|
|
721
|
+
this.config ? this.start() : this.cancel(e);
|
|
722
|
+
}
|
|
723
|
+
start() {
|
|
724
|
+
if (!this.ready || this.isActive || this.uid === null) return !0;
|
|
725
|
+
this.isActive = !0, this.updateStatus(() => this.hasError = !1);
|
|
726
|
+
}
|
|
727
|
+
accept(...e) {
|
|
728
|
+
const r = { keys: Array.isArray(e[0]) ? e.shift() : null, callback: e[0], ...e[1] };
|
|
729
|
+
return this.effect(() => (this.acceptors.push(r), r.immediate && r.callback?.(this.config), () => M(this.acceptors, r)));
|
|
730
|
+
}
|
|
731
|
+
decline(e) {
|
|
732
|
+
return this.accept(e, () => !0);
|
|
733
|
+
}
|
|
734
|
+
checkUpdate(e, t) {
|
|
735
|
+
if (t || !this.config) return [!0, !0];
|
|
736
|
+
if (t === !1) return [!1, !1];
|
|
737
|
+
const r = /* @__PURE__ */ Object.create(null), n = /* @__PURE__ */ k((l) => {
|
|
738
|
+
const h = r[l] ??= !K(this.config[l], e[l]);
|
|
739
|
+
return i ||= h, h;
|
|
740
|
+
}, "checkPropertyUpdate"), s = /* @__PURE__ */ new Set();
|
|
741
|
+
let i = !1, o = !1, u = this.runtime.isReactive || null;
|
|
742
|
+
for (const { keys: l, callback: h, passive: d } of this.acceptors) {
|
|
743
|
+
if (!l)
|
|
744
|
+
u ||= !d;
|
|
745
|
+
else if (d)
|
|
746
|
+
l?.forEach((b) => s.add(b));
|
|
747
|
+
else {
|
|
748
|
+
let b = !1;
|
|
749
|
+
for (const g of l)
|
|
750
|
+
b ||= n(g);
|
|
751
|
+
if (!b) continue;
|
|
752
|
+
}
|
|
753
|
+
h?.(e) && (o = !0);
|
|
754
|
+
}
|
|
755
|
+
for (const l in { ...this.config, ...e })
|
|
756
|
+
if (u !== !1 && !(l in r) && !s.has(l)) {
|
|
757
|
+
const h = n(l);
|
|
758
|
+
u === null && (o ||= h);
|
|
759
|
+
}
|
|
760
|
+
return [i, o];
|
|
761
|
+
}
|
|
762
|
+
}, ht = class extends $e {
|
|
763
|
+
constructor(e, t, r, n) {
|
|
764
|
+
super(e, r), this.runtime = t, this.dispose = P(e.scope.collect(`fork <${e.runtime.name}>`, () => {
|
|
765
|
+
this.uid = null, this.reset(), this.context.emit("internal/fork", this);
|
|
766
|
+
const s = M(t.disposables, this.dispose);
|
|
767
|
+
return M(t.children, this) && !t.children.length && e.registry.delete(t.plugin), s;
|
|
768
|
+
}), I.static, t), t.children.push(this), t.disposables.push(this.dispose), this.context.emit("internal/fork", this), this.init(n);
|
|
769
|
+
}
|
|
770
|
+
static {
|
|
771
|
+
k(this, "ForkScope");
|
|
772
|
+
}
|
|
773
|
+
dispose;
|
|
774
|
+
start() {
|
|
775
|
+
if (super.start()) return !0;
|
|
776
|
+
for (const e of this.runtime.forkables)
|
|
777
|
+
this.ensure(async () => e(this.context, this._config));
|
|
778
|
+
}
|
|
779
|
+
update(e, t) {
|
|
780
|
+
const r = this.config, n = this.runtime.isForkable ? this : this.runtime;
|
|
781
|
+
if (n.config !== r) return;
|
|
782
|
+
let s;
|
|
783
|
+
try {
|
|
784
|
+
s = ee(this.runtime.plugin, e);
|
|
785
|
+
} catch (u) {
|
|
786
|
+
return this.context.emit("internal/error", u), this.cancel(u);
|
|
787
|
+
}
|
|
788
|
+
const [i, o] = n.checkUpdate(s, t);
|
|
789
|
+
this.context.emit("internal/before-update", this, e), this.config = s, n.config = s, i && this.context.emit("internal/update", this, r), o && n.restart();
|
|
790
|
+
}
|
|
791
|
+
}, Se = class extends $e {
|
|
792
|
+
constructor(e, t, r, n) {
|
|
793
|
+
super(e, r), this.plugin = t, t ? (this.setup(), this.init(n)) : (this.name = "root", this.isActive = !0);
|
|
794
|
+
}
|
|
795
|
+
static {
|
|
796
|
+
k(this, "MainScope");
|
|
797
|
+
}
|
|
798
|
+
value;
|
|
799
|
+
runtime = this;
|
|
800
|
+
schema;
|
|
801
|
+
name;
|
|
802
|
+
inject = /* @__PURE__ */ Object.create(null);
|
|
803
|
+
forkables = [];
|
|
804
|
+
children = [];
|
|
805
|
+
isReusable = !1;
|
|
806
|
+
isReactive = !1;
|
|
807
|
+
get isForkable() {
|
|
808
|
+
return this.forkables.length > 0;
|
|
809
|
+
}
|
|
810
|
+
fork(e, t, r) {
|
|
811
|
+
return new ht(e, this, t, r);
|
|
812
|
+
}
|
|
813
|
+
dispose() {
|
|
814
|
+
return this.uid = null, this.reset(), this.context.emit("internal/runtime", this), !0;
|
|
815
|
+
}
|
|
816
|
+
setup() {
|
|
817
|
+
const { name: e } = this.plugin;
|
|
818
|
+
e && e !== "apply" && (this.name = e), this.schema = this.plugin.Config || this.plugin.schema, this.inject = se.resolve(this.plugin.using || this.plugin.inject), this.isReusable = this.plugin.reusable, this.isReactive = this.plugin.reactive, this.context.emit("internal/runtime", this), this.isReusable && this.forkables.push(this.apply);
|
|
819
|
+
}
|
|
820
|
+
apply = /* @__PURE__ */ k((e, t) => {
|
|
821
|
+
if (typeof this.plugin != "function")
|
|
822
|
+
return this.plugin.apply(e, t);
|
|
823
|
+
if (ye(this.plugin)) {
|
|
824
|
+
const r = new this.plugin(e, t), n = r[I.expose];
|
|
825
|
+
return n && e.set(n, r), r.fork && this.forkables.push(r.fork.bind(r)), r;
|
|
826
|
+
} else
|
|
827
|
+
return this.plugin(e, t);
|
|
828
|
+
}, "apply");
|
|
829
|
+
reset() {
|
|
830
|
+
super.reset();
|
|
831
|
+
for (const e of this.children)
|
|
832
|
+
e.reset();
|
|
833
|
+
}
|
|
834
|
+
start() {
|
|
835
|
+
if (super.start()) return !0;
|
|
836
|
+
!this.isReusable && this.plugin && this.ensure(async () => this.value = this.apply(this.ctx, this._config));
|
|
837
|
+
for (const e of this.children)
|
|
838
|
+
e.start();
|
|
839
|
+
}
|
|
840
|
+
update(e, t) {
|
|
841
|
+
if (this.isForkable) {
|
|
842
|
+
const u = new Error(`attempting to update forkable plugin "${this.plugin.name}", which may lead to unexpected behavior`);
|
|
843
|
+
this.context.emit(this.ctx, "internal/warning", u);
|
|
844
|
+
}
|
|
845
|
+
const r = this.config;
|
|
846
|
+
let n;
|
|
847
|
+
try {
|
|
848
|
+
n = ee(this.runtime.plugin || this.context.constructor, e);
|
|
849
|
+
} catch (u) {
|
|
850
|
+
return this.context.emit("internal/error", u), this.cancel(u);
|
|
851
|
+
}
|
|
852
|
+
const [s, i] = this.checkUpdate(n, t), o = this.children.find((u) => u.config === r);
|
|
853
|
+
this.config = n, o && (this.context.emit("internal/before-update", o, e), o.config = n, s && this.context.emit("internal/update", o, r)), i && this.restart();
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
function De(e) {
|
|
857
|
+
return e && typeof e == "object" && typeof e.apply == "function";
|
|
858
|
+
}
|
|
859
|
+
k(De, "isApplicable");
|
|
860
|
+
function se(e) {
|
|
861
|
+
return function(t, r) {
|
|
862
|
+
if (r.kind === "class")
|
|
863
|
+
t.inject = e;
|
|
864
|
+
else if (r.kind === "method")
|
|
865
|
+
r.addInitializer(function() {
|
|
866
|
+
const n = this[m.tracker]?.property;
|
|
867
|
+
if (!n) throw new Error("missing context tracker");
|
|
868
|
+
this[n].inject(e, (s) => {
|
|
869
|
+
t.call(X(this, { [n]: s }));
|
|
870
|
+
});
|
|
871
|
+
});
|
|
872
|
+
else
|
|
873
|
+
throw new Error("@Inject can only be used on class or class methods");
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
k(se, "Inject");
|
|
877
|
+
((e) => {
|
|
878
|
+
function t(r) {
|
|
879
|
+
if (!r) return {};
|
|
880
|
+
if (Array.isArray(r))
|
|
881
|
+
return Object.fromEntries(r.map((o) => [o, { required: !0 }]));
|
|
882
|
+
const { required: n, optional: s, ...i } = r;
|
|
883
|
+
return Array.isArray(n) && Object.assign(i, Object.fromEntries(n.map((o) => [o, { required: !0 }]))), Array.isArray(s) && Object.assign(i, Object.fromEntries(s.map((o) => [o, { required: !1 }]))), i;
|
|
884
|
+
}
|
|
885
|
+
e.resolve = t, k(t, "resolve");
|
|
886
|
+
})(se || (se = {}));
|
|
887
|
+
var pt = class {
|
|
888
|
+
constructor(e, t) {
|
|
889
|
+
this.ctx = e, P(this, m.tracker, {
|
|
890
|
+
associate: "registry",
|
|
891
|
+
property: "ctx"
|
|
892
|
+
}), this.context = e;
|
|
893
|
+
const r = new Se(e, null, t);
|
|
894
|
+
e.scope = r, r.ctx = e, this.set(null, r);
|
|
895
|
+
}
|
|
896
|
+
static {
|
|
897
|
+
k(this, "Registry");
|
|
898
|
+
}
|
|
899
|
+
_counter = 0;
|
|
900
|
+
_internal = /* @__PURE__ */ new Map();
|
|
901
|
+
context;
|
|
902
|
+
get counter() {
|
|
903
|
+
return ++this._counter;
|
|
904
|
+
}
|
|
905
|
+
get size() {
|
|
906
|
+
return this._internal.size;
|
|
907
|
+
}
|
|
908
|
+
resolve(e, t = !1) {
|
|
909
|
+
if (e === null || typeof e == "function") return e;
|
|
910
|
+
if (De(e)) return e.apply;
|
|
911
|
+
if (t) throw new Error('invalid plugin, expect function or object with an "apply" method, received ' + typeof e);
|
|
912
|
+
}
|
|
913
|
+
get(e) {
|
|
914
|
+
const t = this.resolve(e);
|
|
915
|
+
return t && this._internal.get(t);
|
|
916
|
+
}
|
|
917
|
+
has(e) {
|
|
918
|
+
const t = this.resolve(e);
|
|
919
|
+
return !!t && this._internal.has(t);
|
|
920
|
+
}
|
|
921
|
+
set(e, t) {
|
|
922
|
+
const r = this.resolve(e);
|
|
923
|
+
this._internal.set(r, t);
|
|
924
|
+
}
|
|
925
|
+
delete(e) {
|
|
926
|
+
const t = this.resolve(e), r = t && this._internal.get(t);
|
|
927
|
+
if (r)
|
|
928
|
+
return this._internal.delete(t), r.dispose(), r;
|
|
929
|
+
}
|
|
930
|
+
keys() {
|
|
931
|
+
return this._internal.keys();
|
|
932
|
+
}
|
|
933
|
+
values() {
|
|
934
|
+
return this._internal.values();
|
|
935
|
+
}
|
|
936
|
+
entries() {
|
|
937
|
+
return this._internal.entries();
|
|
938
|
+
}
|
|
939
|
+
forEach(e) {
|
|
940
|
+
return this._internal.forEach(e);
|
|
941
|
+
}
|
|
942
|
+
using(e, t) {
|
|
943
|
+
return this.inject(e, t);
|
|
944
|
+
}
|
|
945
|
+
inject(e, t) {
|
|
946
|
+
return this.plugin({ inject: e, apply: t, name: t.name });
|
|
947
|
+
}
|
|
948
|
+
plugin(e, t, r) {
|
|
949
|
+
if (this.resolve(e, !0), this.ctx.scope.assertActive(), !r)
|
|
950
|
+
try {
|
|
951
|
+
t = ee(e, t);
|
|
952
|
+
} catch (s) {
|
|
953
|
+
this.context.emit(this.ctx, "internal/error", s), r = s, t = null;
|
|
954
|
+
}
|
|
955
|
+
let n = this.get(e);
|
|
956
|
+
return n ? (n.isForkable || this.context.emit(this.ctx, "internal/warning", new Error(`duplicate plugin detected: ${e.name}`)), n.fork(this.ctx, t, r)) : (n = new Se(this.ctx, e, t, r), this.set(e, n), n.fork(this.ctx, t, r));
|
|
957
|
+
}
|
|
958
|
+
}, dt = pt, I = class Y {
|
|
959
|
+
static {
|
|
960
|
+
k(this, "Context");
|
|
961
|
+
}
|
|
962
|
+
static store = m.store;
|
|
963
|
+
static events = m.events;
|
|
964
|
+
static static = m.static;
|
|
965
|
+
static filter = m.filter;
|
|
966
|
+
static expose = m.expose;
|
|
967
|
+
static isolate = m.isolate;
|
|
968
|
+
static internal = m.internal;
|
|
969
|
+
static intercept = m.intercept;
|
|
970
|
+
static origin = "ctx";
|
|
971
|
+
static current = "ctx";
|
|
972
|
+
static is(t) {
|
|
973
|
+
return !!t?.[Y.is];
|
|
974
|
+
}
|
|
975
|
+
static {
|
|
976
|
+
Y.is[Symbol.toPrimitive] = () => Symbol.for("cordis.is"), Y.prototype[Y.is] = !0;
|
|
977
|
+
}
|
|
978
|
+
/** @deprecated use `Service.traceable` instead */
|
|
979
|
+
static associate(t, r) {
|
|
980
|
+
return t;
|
|
981
|
+
}
|
|
982
|
+
constructor(t) {
|
|
983
|
+
t = ee(this.constructor, t), this[m.store] = /* @__PURE__ */ Object.create(null), this[m.isolate] = /* @__PURE__ */ Object.create(null), this[m.internal] = /* @__PURE__ */ Object.create(null), this[m.intercept] = /* @__PURE__ */ Object.create(null);
|
|
984
|
+
const r = new Proxy(this, le.handler);
|
|
985
|
+
r.root = r, r.reflect = new le(r), r.registry = new dt(r, t), r.lifecycle = new ut(r);
|
|
986
|
+
const n = /* @__PURE__ */ k((s) => {
|
|
987
|
+
if (s) {
|
|
988
|
+
n(Object.getPrototypeOf(s));
|
|
989
|
+
for (const i of Object.getOwnPropertyNames(s)) {
|
|
990
|
+
const o = s[i].prototype?.constructor;
|
|
991
|
+
o && (r[s[i].key] = new o(r, t), P(r[s[i].key], "ctx", r));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}, "attach");
|
|
995
|
+
return n(this[m.internal]), r;
|
|
996
|
+
}
|
|
997
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
998
|
+
return `Context <${this.name}>`;
|
|
999
|
+
}
|
|
1000
|
+
get name() {
|
|
1001
|
+
let t = this.runtime;
|
|
1002
|
+
for (; t && !t.name; )
|
|
1003
|
+
t = t.parent.runtime;
|
|
1004
|
+
return t?.name;
|
|
1005
|
+
}
|
|
1006
|
+
get events() {
|
|
1007
|
+
return this.lifecycle;
|
|
1008
|
+
}
|
|
1009
|
+
/** @deprecated */
|
|
1010
|
+
get state() {
|
|
1011
|
+
return this.scope;
|
|
1012
|
+
}
|
|
1013
|
+
extend(t = {}) {
|
|
1014
|
+
const r = Reflect.getOwnPropertyDescriptor(this, m.shadow)?.value, n = Object.assign(Object.create(B(this, this)), t);
|
|
1015
|
+
return r ? Object.assign(Object.create(n), { [m.shadow]: r }) : n;
|
|
1016
|
+
}
|
|
1017
|
+
isolate(t, r) {
|
|
1018
|
+
const n = Object.create(this[m.isolate]);
|
|
1019
|
+
return n[t] = r ?? Symbol(t), this.extend({ [m.isolate]: n });
|
|
1020
|
+
}
|
|
1021
|
+
intercept(t, r) {
|
|
1022
|
+
const n = Object.create(this[m.intercept]);
|
|
1023
|
+
return n[t] = r, this.extend({ [m.intercept]: n });
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
I.prototype[I.internal] = /* @__PURE__ */ Object.create(null);
|
|
1027
|
+
var Tt = class Ce {
|
|
1028
|
+
static {
|
|
1029
|
+
k(this, "Service");
|
|
1030
|
+
}
|
|
1031
|
+
static setup = m.setup;
|
|
1032
|
+
static invoke = m.invoke;
|
|
1033
|
+
static extend = m.extend;
|
|
1034
|
+
static tracker = m.tracker;
|
|
1035
|
+
static provide = m.provide;
|
|
1036
|
+
static immediate = m.immediate;
|
|
1037
|
+
start() {
|
|
1038
|
+
}
|
|
1039
|
+
stop() {
|
|
1040
|
+
}
|
|
1041
|
+
ctx;
|
|
1042
|
+
name;
|
|
1043
|
+
config;
|
|
1044
|
+
constructor(...t) {
|
|
1045
|
+
let r, n, s, i;
|
|
1046
|
+
I.is(t[0]) ? (r = t[0], typeof t[1] == "string" ? (n = t[1], s = t[2]) : i = t[1]) : i = t[0], n ??= this.constructor[m.provide], s ??= this.constructor[m.immediate];
|
|
1047
|
+
let o = this;
|
|
1048
|
+
const u = {
|
|
1049
|
+
associate: n,
|
|
1050
|
+
property: "ctx"
|
|
1051
|
+
};
|
|
1052
|
+
return o[m.invoke] && (o = ue(n, ge(Object.getPrototypeOf(this), Function.prototype), u)), r ? o.ctx = r : o[m.setup](), o.name = n, o.config = i, P(o, m.tracker, u), o.ctx.provide(n), o.ctx.runtime.name = n, s && (r ? o[m.expose] = n : o.ctx.set(n, o)), o.ctx.on("ready", async () => {
|
|
1053
|
+
await Promise.resolve(), await o.start(), s || o.ctx.set(n, o);
|
|
1054
|
+
}), o.ctx.on("dispose", () => o.stop()), o;
|
|
1055
|
+
}
|
|
1056
|
+
[m.filter](t) {
|
|
1057
|
+
return t[m.isolate][this.name] === this.ctx[m.isolate][this.name];
|
|
1058
|
+
}
|
|
1059
|
+
[m.setup]() {
|
|
1060
|
+
this.ctx = new I();
|
|
1061
|
+
}
|
|
1062
|
+
[m.extend](t) {
|
|
1063
|
+
let r;
|
|
1064
|
+
return this[Ce.invoke] ? r = ue(this.name, this, this[m.tracker]) : r = Object.create(this), Object.assign(r, t);
|
|
1065
|
+
}
|
|
1066
|
+
static [Symbol.hasInstance](t) {
|
|
1067
|
+
let r = t.constructor;
|
|
1068
|
+
for (; r; ) {
|
|
1069
|
+
if (r = r.prototype?.constructor, r === this) return !0;
|
|
1070
|
+
r = Object.getPrototypeOf(r);
|
|
1071
|
+
}
|
|
1072
|
+
return !1;
|
|
1073
|
+
}
|
|
1074
|
+
}, yt = Object.defineProperty, gt = Object.getOwnPropertyNames, E = (e, t) => yt(e, "name", { value: t, configurable: !0 }), mt = (e, t) => function() {
|
|
1075
|
+
return t || (0, e[gt(e)[0]])((t = { exports: {} }).exports, t), t.exports;
|
|
1076
|
+
}, bt = mt({
|
|
1077
|
+
"src/index.ts"(e, t) {
|
|
1078
|
+
var r = Symbol.for("schemastery"), n = Symbol.for("ValidationError");
|
|
1079
|
+
globalThis.__schemastery_index__ ??= 0;
|
|
1080
|
+
var s = class extends TypeError {
|
|
1081
|
+
constructor(a, c) {
|
|
1082
|
+
let f = "$";
|
|
1083
|
+
for (const p of c.path || [])
|
|
1084
|
+
typeof p == "string" ? f += "." + p : typeof p == "number" ? f += "[" + p + "]" : typeof p == "symbol" && (f += `[Symbol(${p.toString()})]`);
|
|
1085
|
+
f.startsWith(".") && (f = f.slice(1)), super((f === "$" ? "" : `${f} `) + a), this.options = c;
|
|
1086
|
+
}
|
|
1087
|
+
static {
|
|
1088
|
+
E(this, "ValidationError");
|
|
1089
|
+
}
|
|
1090
|
+
name = "ValidationError";
|
|
1091
|
+
static is(a) {
|
|
1092
|
+
return !!a?.[n];
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
Object.defineProperty(s.prototype, n, {
|
|
1096
|
+
value: !0
|
|
1097
|
+
});
|
|
1098
|
+
var i = /* @__PURE__ */ E(function(a) {
|
|
1099
|
+
const c = /* @__PURE__ */ E(function(f, p = {}) {
|
|
1100
|
+
return i.resolve(f, c, p)[0];
|
|
1101
|
+
}, "schema");
|
|
1102
|
+
if (a.refs) {
|
|
1103
|
+
const f = q(a.refs, (y) => new i(y)), p = /* @__PURE__ */ E((y) => f[y], "getRef");
|
|
1104
|
+
for (const y in f) {
|
|
1105
|
+
const O = f[y];
|
|
1106
|
+
O.sKey = p(O.sKey), O.inner = p(O.inner), O.list = O.list && O.list.map(p), O.dict = O.dict && q(O.dict, p);
|
|
1107
|
+
}
|
|
1108
|
+
return f[a.uid];
|
|
1109
|
+
}
|
|
1110
|
+
if (Object.assign(c, a), typeof c.callback == "string")
|
|
1111
|
+
try {
|
|
1112
|
+
c.callback = new Function("return " + c.callback)();
|
|
1113
|
+
} catch {
|
|
1114
|
+
}
|
|
1115
|
+
return Object.defineProperty(c, "uid", { value: globalThis.__schemastery_index__++ }), Object.setPrototypeOf(c, i.prototype), c.meta ||= {}, c.toString = c.toString.bind(c), c;
|
|
1116
|
+
}, "Schema");
|
|
1117
|
+
i.prototype = Object.create(Function.prototype), i.prototype[r] = !0, i.ValidationError = s;
|
|
1118
|
+
var o;
|
|
1119
|
+
i.prototype.toJSON = /* @__PURE__ */ E(function() {
|
|
1120
|
+
if (o)
|
|
1121
|
+
return o[this.uid] ??= JSON.parse(JSON.stringify({ ...this })), this.uid;
|
|
1122
|
+
o = { [this.uid]: { ...this } }, o[this.uid] = JSON.parse(JSON.stringify({ ...this }));
|
|
1123
|
+
const c = { uid: this.uid, refs: o };
|
|
1124
|
+
return o = void 0, c;
|
|
1125
|
+
}, "toJSON"), i.prototype.set = /* @__PURE__ */ E(function(c, f) {
|
|
1126
|
+
return this.dict[c] = f, this;
|
|
1127
|
+
}, "set"), i.prototype.push = /* @__PURE__ */ E(function(c) {
|
|
1128
|
+
return this.list.push(c), this;
|
|
1129
|
+
}, "push");
|
|
1130
|
+
function u(a, c) {
|
|
1131
|
+
const f = typeof a == "string" ? { "": a } : { ...a };
|
|
1132
|
+
for (const p in c) {
|
|
1133
|
+
const y = c[p];
|
|
1134
|
+
y?.$description || y?.$desc ? f[p] = y.$description || y.$desc : typeof y == "string" && (f[p] = y);
|
|
1135
|
+
}
|
|
1136
|
+
return f;
|
|
1137
|
+
}
|
|
1138
|
+
E(u, "mergeDesc");
|
|
1139
|
+
function l(a) {
|
|
1140
|
+
return a?.$value ?? a?.$inner;
|
|
1141
|
+
}
|
|
1142
|
+
E(l, "getInner");
|
|
1143
|
+
function h(a) {
|
|
1144
|
+
return Ae(a ?? {}, (c) => !c.startsWith("$"));
|
|
1145
|
+
}
|
|
1146
|
+
E(h, "extractKeys"), i.prototype.i18n = /* @__PURE__ */ E(function(c) {
|
|
1147
|
+
const f = i(this), p = u(f.meta.description, c);
|
|
1148
|
+
return Object.keys(p).length && (f.meta.description = p), f.dict && (f.dict = q(f.dict, (y, O) => y.i18n(q(c, (S) => l(S)?.[O] ?? S?.[O])))), f.list && (f.list = f.list.map((y, O) => y.i18n(q(c, (S = {}) => Array.isArray(l(S)) ? l(S)[O] : Array.isArray(S) ? S[O] : h(S))))), f.inner && (f.inner = f.inner.i18n(q(c, (y) => l(y) ? l(y) : h(y)))), f.sKey && (f.sKey = f.sKey.i18n(q(c, (y) => y?.$key))), f;
|
|
1149
|
+
}, "i18n"), i.prototype.extra = /* @__PURE__ */ E(function(c, f) {
|
|
1150
|
+
const p = i(this);
|
|
1151
|
+
return p.meta = { ...p.meta, [c]: f }, p;
|
|
1152
|
+
}, "extra");
|
|
1153
|
+
for (const a of ["required", "disabled", "collapse", "hidden", "loose"])
|
|
1154
|
+
Object.assign(i.prototype, {
|
|
1155
|
+
[a](c = !0) {
|
|
1156
|
+
const f = i(this);
|
|
1157
|
+
return f.meta = { ...f.meta, [a]: c }, f;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
i.prototype.deprecated = /* @__PURE__ */ E(function() {
|
|
1161
|
+
const c = i(this);
|
|
1162
|
+
return c.meta.badges ||= [], c.meta.badges.push({ text: "deprecated", type: "danger" }), c;
|
|
1163
|
+
}, "deprecated"), i.prototype.experimental = /* @__PURE__ */ E(function() {
|
|
1164
|
+
const c = i(this);
|
|
1165
|
+
return c.meta.badges ||= [], c.meta.badges.push({ text: "experimental", type: "warning" }), c;
|
|
1166
|
+
}, "experimental"), i.prototype.pattern = /* @__PURE__ */ E(function(c) {
|
|
1167
|
+
const f = i(this), p = ve(c, ["source", "flags"]);
|
|
1168
|
+
return f.meta = { ...f.meta, pattern: p }, f;
|
|
1169
|
+
}, "pattern"), i.prototype.simplify = /* @__PURE__ */ E(function(c) {
|
|
1170
|
+
if (K(c, this.meta.default, this.type === "dict")) return null;
|
|
1171
|
+
if (j(c)) return c;
|
|
1172
|
+
if (this.type === "object" || this.type === "dict") {
|
|
1173
|
+
const f = {};
|
|
1174
|
+
for (const p in c) {
|
|
1175
|
+
const O = (this.type === "object" ? this.dict[p] : this.inner)?.simplify(c[p]);
|
|
1176
|
+
(this.type === "dict" || !j(O)) && (f[p] = O);
|
|
1177
|
+
}
|
|
1178
|
+
return K(f, this.meta.default, this.type === "dict") ? null : f;
|
|
1179
|
+
} else if (this.type === "array" || this.type === "tuple") {
|
|
1180
|
+
const f = [];
|
|
1181
|
+
return c.forEach((p, y) => {
|
|
1182
|
+
const O = this.type === "array" ? this.inner : this.list[y], S = O ? O.simplify(p) : p;
|
|
1183
|
+
f.push(S);
|
|
1184
|
+
}), f;
|
|
1185
|
+
} else if (this.type === "intersect") {
|
|
1186
|
+
const f = {};
|
|
1187
|
+
for (const p of this.list)
|
|
1188
|
+
Object.assign(f, p.simplify(c));
|
|
1189
|
+
return f;
|
|
1190
|
+
} else if (this.type === "union")
|
|
1191
|
+
for (const f of this.list)
|
|
1192
|
+
try {
|
|
1193
|
+
return i.resolve(c, f, {}), f.simplify(c);
|
|
1194
|
+
} catch {
|
|
1195
|
+
}
|
|
1196
|
+
return c;
|
|
1197
|
+
}, "simplify"), i.prototype.toString = /* @__PURE__ */ E(function(c) {
|
|
1198
|
+
return $[this.type]?.(this, c) ?? `Schema<${this.type}>`;
|
|
1199
|
+
}, "toString"), i.prototype.role = /* @__PURE__ */ E(function(a, c) {
|
|
1200
|
+
const f = i(this);
|
|
1201
|
+
return f.meta = { ...f.meta, role: a, extra: c }, f;
|
|
1202
|
+
}, "role");
|
|
1203
|
+
for (const a of ["default", "link", "comment", "description", "max", "min", "step"])
|
|
1204
|
+
Object.assign(i.prototype, {
|
|
1205
|
+
[a](c) {
|
|
1206
|
+
const f = i(this);
|
|
1207
|
+
return f.meta = { ...f.meta, [a]: c }, f;
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
var d = {};
|
|
1211
|
+
i.extend = /* @__PURE__ */ E(function(c, f) {
|
|
1212
|
+
d[c] = f;
|
|
1213
|
+
}, "extend"), i.resolve = /* @__PURE__ */ E(function(c, f, p = {}, y = !1) {
|
|
1214
|
+
if (!f) return [c];
|
|
1215
|
+
if (p.ignore?.(c, f)) return [c];
|
|
1216
|
+
if (j(c) && f.type !== "lazy") {
|
|
1217
|
+
if (f.meta.required) throw new s("missing required value", p);
|
|
1218
|
+
let S = f, A = f.meta.default;
|
|
1219
|
+
for (; S?.type === "intersect" && j(A); )
|
|
1220
|
+
S = S.list[0], A = S?.meta.default;
|
|
1221
|
+
if (j(A)) return [c];
|
|
1222
|
+
c = ne(A);
|
|
1223
|
+
}
|
|
1224
|
+
const O = d[f.type];
|
|
1225
|
+
if (!O) throw new s(`unsupported type "${f.type}"`, p);
|
|
1226
|
+
try {
|
|
1227
|
+
return O(c, f, p, y);
|
|
1228
|
+
} catch (S) {
|
|
1229
|
+
if (!f.meta.loose) throw S;
|
|
1230
|
+
return [f.meta.default];
|
|
1231
|
+
}
|
|
1232
|
+
}, "resolve"), i.from = /* @__PURE__ */ E(function(c) {
|
|
1233
|
+
if (j(c))
|
|
1234
|
+
return i.any();
|
|
1235
|
+
if (["string", "number", "boolean"].includes(typeof c))
|
|
1236
|
+
return i.const(c).required();
|
|
1237
|
+
if (c[r])
|
|
1238
|
+
return c;
|
|
1239
|
+
if (typeof c == "function")
|
|
1240
|
+
switch (c) {
|
|
1241
|
+
case String:
|
|
1242
|
+
return i.string().required();
|
|
1243
|
+
case Number:
|
|
1244
|
+
return i.number().required();
|
|
1245
|
+
case Boolean:
|
|
1246
|
+
return i.boolean().required();
|
|
1247
|
+
case Function:
|
|
1248
|
+
return i.function().required();
|
|
1249
|
+
default:
|
|
1250
|
+
return i.is(c).required();
|
|
1251
|
+
}
|
|
1252
|
+
else
|
|
1253
|
+
throw new TypeError(`cannot infer schema from ${c}`);
|
|
1254
|
+
}, "from"), i.lazy = /* @__PURE__ */ E(function(c) {
|
|
1255
|
+
const f = /* @__PURE__ */ E(() => (p.inner[r] || (p.inner = p.builder(), p.inner.meta = { ...p.meta, ...p.inner.meta }), p.inner.toJSON()), "toJSON"), p = new i({ type: "lazy", builder: c, inner: { toJSON: f } });
|
|
1256
|
+
return p;
|
|
1257
|
+
}, "lazy"), i.natural = /* @__PURE__ */ E(function() {
|
|
1258
|
+
return i.number().step(1).min(0);
|
|
1259
|
+
}, "natural"), i.percent = /* @__PURE__ */ E(function() {
|
|
1260
|
+
return i.number().step(0.01).min(0).max(1).role("slider");
|
|
1261
|
+
}, "percent"), i.date = /* @__PURE__ */ E(function() {
|
|
1262
|
+
return i.union([
|
|
1263
|
+
i.is(Date),
|
|
1264
|
+
i.transform(i.string().role("datetime"), (c, f) => {
|
|
1265
|
+
const p = new Date(c);
|
|
1266
|
+
if (isNaN(+p)) throw new s(`invalid date "${c}"`, f);
|
|
1267
|
+
return p;
|
|
1268
|
+
}, !0)
|
|
1269
|
+
]);
|
|
1270
|
+
}, "date"), i.regExp = /* @__PURE__ */ E(function(c = "") {
|
|
1271
|
+
return i.union([
|
|
1272
|
+
i.is(RegExp),
|
|
1273
|
+
i.transform(i.string().role("regexp", { flag: c }), (f, p) => {
|
|
1274
|
+
try {
|
|
1275
|
+
return new RegExp(f, c);
|
|
1276
|
+
} catch (y) {
|
|
1277
|
+
throw new s(y.message, p);
|
|
1278
|
+
}
|
|
1279
|
+
}, !0)
|
|
1280
|
+
]);
|
|
1281
|
+
}, "regExp"), i.arrayBuffer = /* @__PURE__ */ E(function(c) {
|
|
1282
|
+
return i.union([
|
|
1283
|
+
i.is(ArrayBuffer),
|
|
1284
|
+
i.is(SharedArrayBuffer),
|
|
1285
|
+
i.transform(i.any(), (f, p) => {
|
|
1286
|
+
if (N.isSource(f)) return N.fromSource(f);
|
|
1287
|
+
throw new s(`expected ArrayBufferSource but got ${f}`, p);
|
|
1288
|
+
}, !0),
|
|
1289
|
+
...c ? [i.transform(i.string(), (f, p) => {
|
|
1290
|
+
try {
|
|
1291
|
+
return c === "base64" ? N.fromBase64(f) : N.fromHex(f);
|
|
1292
|
+
} catch (y) {
|
|
1293
|
+
throw new s(y.message, p);
|
|
1294
|
+
}
|
|
1295
|
+
}, !0)] : []
|
|
1296
|
+
]);
|
|
1297
|
+
}, "arrayBuffer"), i.extend("lazy", (a, c, f, p) => (c.inner[r] || (c.inner = c.builder(), c.inner.meta = { ...c.meta, ...c.inner.meta }), i.resolve(a, c.inner, f, p))), i.extend("any", (a) => [a]), i.extend("never", (a, c, f) => {
|
|
1298
|
+
throw new s(`expected nullable but got ${a}`, f);
|
|
1299
|
+
}), i.extend("const", (a, { value: c }, f) => {
|
|
1300
|
+
if (K(a, c)) return [c];
|
|
1301
|
+
throw new s(`expected ${c} but got ${a}`, f);
|
|
1302
|
+
});
|
|
1303
|
+
function R(a, c, f, p, y = !1) {
|
|
1304
|
+
const { max: O = 1 / 0, min: S = -1 / 0 } = c;
|
|
1305
|
+
if (a > O) throw new s(`expected ${f} <= ${O} but got ${a}`, p);
|
|
1306
|
+
if (a < S && !y) throw new s(`expected ${f} >= ${S} but got ${a}`, p);
|
|
1307
|
+
}
|
|
1308
|
+
E(R, "checkWithinRange"), i.extend("string", (a, { meta: c }, f) => {
|
|
1309
|
+
if (typeof a != "string") throw new s(`expected string but got ${a}`, f);
|
|
1310
|
+
if (c.pattern) {
|
|
1311
|
+
const p = new RegExp(c.pattern.source, c.pattern.flags);
|
|
1312
|
+
if (!p.test(a)) throw new s(`expect string to match regexp ${p}`, f);
|
|
1313
|
+
}
|
|
1314
|
+
return R(a.length, c, "string length", f), [a];
|
|
1315
|
+
});
|
|
1316
|
+
function b(a, c) {
|
|
1317
|
+
const f = a.toString();
|
|
1318
|
+
if (f.includes("e")) return a * Math.pow(10, c);
|
|
1319
|
+
const p = f.indexOf(".");
|
|
1320
|
+
if (p === -1) return a * Math.pow(10, c);
|
|
1321
|
+
const y = f.slice(p + 1), O = f.slice(0, p);
|
|
1322
|
+
return y.length <= c ? +(O + y.padEnd(c, "0")) : +(O + y.slice(0, c) + "." + y.slice(c));
|
|
1323
|
+
}
|
|
1324
|
+
E(b, "decimalShift");
|
|
1325
|
+
function g(a, c, f) {
|
|
1326
|
+
if (f = Math.abs(f), !/^\d+\.\d+$/.test(f.toString()))
|
|
1327
|
+
return (a - c) % f === 0;
|
|
1328
|
+
const p = f.toString().indexOf("."), y = f.toString().slice(p + 1).length;
|
|
1329
|
+
return Math.abs(b(a, y) - b(c, y)) % b(f, y) === 0;
|
|
1330
|
+
}
|
|
1331
|
+
E(g, "isMultipleOf"), i.extend("number", (a, { meta: c }, f) => {
|
|
1332
|
+
if (typeof a != "number") throw new s(`expected number but got ${a}`, f);
|
|
1333
|
+
R(a, c, "number", f);
|
|
1334
|
+
const { step: p } = c;
|
|
1335
|
+
if (p && !g(a, c.min ?? 0, p))
|
|
1336
|
+
throw new s(`expected number multiple of ${p} but got ${a}`, f);
|
|
1337
|
+
return [a];
|
|
1338
|
+
}), i.extend("boolean", (a, c, f) => {
|
|
1339
|
+
if (typeof a == "boolean") return [a];
|
|
1340
|
+
throw new s(`expected boolean but got ${a}`, f);
|
|
1341
|
+
}), i.extend("bitset", (a, { bits: c, meta: f }, p) => {
|
|
1342
|
+
let y = 0, O = [];
|
|
1343
|
+
if (typeof a == "number") {
|
|
1344
|
+
y = a;
|
|
1345
|
+
for (const S in c)
|
|
1346
|
+
a & c[S] && O.push(S);
|
|
1347
|
+
} else if (Array.isArray(a)) {
|
|
1348
|
+
O = a;
|
|
1349
|
+
for (const S of O) {
|
|
1350
|
+
if (typeof S != "string") throw new s(`expected string but got ${S}`, p);
|
|
1351
|
+
S in c && (y |= c[S]);
|
|
1352
|
+
}
|
|
1353
|
+
} else
|
|
1354
|
+
throw new s(`expected number or array but got ${a}`, p);
|
|
1355
|
+
return y === f.default ? [y] : [y, O];
|
|
1356
|
+
}), i.extend("function", (a, c, f) => {
|
|
1357
|
+
if (typeof a == "function") return [a];
|
|
1358
|
+
throw new s(`expected function but got ${a}`, f);
|
|
1359
|
+
}), i.extend("is", (a, { constructor: c }, f) => {
|
|
1360
|
+
if (typeof c == "function") {
|
|
1361
|
+
if (a instanceof c) return [a];
|
|
1362
|
+
throw new s(`expected ${c.name} but got ${a}`, f);
|
|
1363
|
+
} else {
|
|
1364
|
+
if (j(a))
|
|
1365
|
+
throw new s(`expected ${c} but got ${a}`, f);
|
|
1366
|
+
let p = Object.getPrototypeOf(a);
|
|
1367
|
+
for (; p; ) {
|
|
1368
|
+
if (p.constructor?.name === c) return [a];
|
|
1369
|
+
p = Object.getPrototypeOf(p);
|
|
1370
|
+
}
|
|
1371
|
+
throw new s(`expected ${c} but got ${a}`, f);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
function w(a, c, f, p) {
|
|
1375
|
+
try {
|
|
1376
|
+
const [y, O] = i.resolve(a[c], f, {
|
|
1377
|
+
...p,
|
|
1378
|
+
path: [...p.path || [], c]
|
|
1379
|
+
});
|
|
1380
|
+
return O !== void 0 && (a[c] = O), y;
|
|
1381
|
+
} catch (y) {
|
|
1382
|
+
if (!p?.autofix) throw y;
|
|
1383
|
+
return delete a[c], f.meta.default;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
E(w, "property"), i.extend("array", (a, { inner: c, meta: f }, p) => {
|
|
1387
|
+
if (!Array.isArray(a)) throw new s(`expected array but got ${a}`, p);
|
|
1388
|
+
return R(a.length, f, "array length", p, !j(c.meta.default)), [a.map((y, O) => w(a, O, c, p))];
|
|
1389
|
+
}), i.extend("dict", (a, { inner: c, sKey: f }, p, y) => {
|
|
1390
|
+
if (!te(a)) throw new s(`expected object but got ${a}`, p);
|
|
1391
|
+
const O = {};
|
|
1392
|
+
for (const S in a) {
|
|
1393
|
+
let A;
|
|
1394
|
+
try {
|
|
1395
|
+
A = i.resolve(S, f, p)[0];
|
|
1396
|
+
} catch (Me) {
|
|
1397
|
+
if (y) continue;
|
|
1398
|
+
throw Me;
|
|
1399
|
+
}
|
|
1400
|
+
O[A] = w(a, S, c, p), a[A] = a[S], S !== A && delete a[S];
|
|
1401
|
+
}
|
|
1402
|
+
return [O];
|
|
1403
|
+
}), i.extend("tuple", (a, { list: c }, f, p) => {
|
|
1404
|
+
if (!Array.isArray(a)) throw new s(`expected array but got ${a}`, f);
|
|
1405
|
+
const y = c.map((O, S) => w(a, S, O, f));
|
|
1406
|
+
return p ? [y] : (y.push(...a.slice(c.length)), [y]);
|
|
1407
|
+
});
|
|
1408
|
+
function _(a, c) {
|
|
1409
|
+
for (const f in c)
|
|
1410
|
+
f in a || (a[f] = c[f]);
|
|
1411
|
+
}
|
|
1412
|
+
E(_, "merge"), i.extend("object", (a, { dict: c }, f, p) => {
|
|
1413
|
+
if (!te(a)) throw new s(`expected object but got ${a}`, f);
|
|
1414
|
+
const y = {};
|
|
1415
|
+
for (const O in c) {
|
|
1416
|
+
const S = w(a, O, c[O], f);
|
|
1417
|
+
(!j(S) || O in a) && (y[O] = S);
|
|
1418
|
+
}
|
|
1419
|
+
return p || _(y, a), [y];
|
|
1420
|
+
}), i.extend("union", (a, { list: c, toString: f }, p, y) => {
|
|
1421
|
+
for (const O of c)
|
|
1422
|
+
try {
|
|
1423
|
+
return i.resolve(a, O, p, y);
|
|
1424
|
+
} catch {
|
|
1425
|
+
}
|
|
1426
|
+
throw new s(`expected ${f()} but got ${JSON.stringify(a)}`, p);
|
|
1427
|
+
}), i.extend("intersect", (a, { list: c, toString: f }, p, y) => {
|
|
1428
|
+
if (!c.length) return [a];
|
|
1429
|
+
let O;
|
|
1430
|
+
for (const S of c) {
|
|
1431
|
+
const A = i.resolve(a, S, p, !0)[0];
|
|
1432
|
+
if (!j(A))
|
|
1433
|
+
if (j(O))
|
|
1434
|
+
O = A;
|
|
1435
|
+
else {
|
|
1436
|
+
if (typeof O != typeof A)
|
|
1437
|
+
throw new s(`expected ${f()} but got ${JSON.stringify(a)}`, p);
|
|
1438
|
+
if (typeof A == "object")
|
|
1439
|
+
_(O ??= {}, A);
|
|
1440
|
+
else if (O !== A)
|
|
1441
|
+
throw new s(`expected ${f()} but got ${JSON.stringify(a)}`, p);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return !y && te(a) && _(O, a), [O];
|
|
1445
|
+
}), i.extend("transform", (a, { inner: c, callback: f, preserve: p }, y) => {
|
|
1446
|
+
const [O, S = a] = i.resolve(a, c, y, !0);
|
|
1447
|
+
return p ? [f(O)] : [f(O), f(S)];
|
|
1448
|
+
});
|
|
1449
|
+
var $ = {};
|
|
1450
|
+
function v(a, c, f) {
|
|
1451
|
+
$[a] = f, Object.assign(i, {
|
|
1452
|
+
[a](...p) {
|
|
1453
|
+
const y = new i({ type: a });
|
|
1454
|
+
return c.forEach((O, S) => {
|
|
1455
|
+
switch (O) {
|
|
1456
|
+
case "sKey":
|
|
1457
|
+
y.sKey = p[S] ?? i.string();
|
|
1458
|
+
break;
|
|
1459
|
+
case "inner":
|
|
1460
|
+
y.inner = i.from(p[S]);
|
|
1461
|
+
break;
|
|
1462
|
+
case "list":
|
|
1463
|
+
y.list = p[S].map(i.from);
|
|
1464
|
+
break;
|
|
1465
|
+
case "dict":
|
|
1466
|
+
y.dict = q(p[S], i.from);
|
|
1467
|
+
break;
|
|
1468
|
+
case "bits": {
|
|
1469
|
+
y.bits = {};
|
|
1470
|
+
for (const A in p[S])
|
|
1471
|
+
typeof p[S][A] == "number" && (y.bits[A] = p[S][A]);
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
case "callback": {
|
|
1475
|
+
const A = y.callback = p[S];
|
|
1476
|
+
A.toJSON ||= () => A.toString();
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
case "constructor": {
|
|
1480
|
+
const A = y.constructor = p[S];
|
|
1481
|
+
typeof A == "function" && (A.toJSON ||= () => A.name);
|
|
1482
|
+
break;
|
|
1483
|
+
}
|
|
1484
|
+
default:
|
|
1485
|
+
y[O] = p[S];
|
|
1486
|
+
}
|
|
1487
|
+
}), a === "object" || a === "dict" ? y.meta.default = {} : a === "array" || a === "tuple" ? y.meta.default = [] : a === "bitset" && (y.meta.default = 0), y;
|
|
1488
|
+
}
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
E(v, "defineMethod"), v("is", ["constructor"], ({ constructor: a }) => typeof a == "function" ? a.name : a), v("any", [], () => "any"), v("never", [], () => "never"), v("const", ["value"], ({ value: a }) => typeof a == "string" ? JSON.stringify(a) : a), v("string", [], () => "string"), v("number", [], () => "number"), v("boolean", [], () => "boolean"), v("bitset", ["bits"], () => "bitset"), v("function", [], () => "function"), v("array", ["inner"], ({ inner: a }) => `${a.toString(!0)}[]`), v("dict", ["inner", "sKey"], ({ inner: a, sKey: c }) => `{ [key: ${c.toString()}]: ${a.toString()} }`), v("tuple", ["list"], ({ list: a }) => `[${a.map((c) => c.toString()).join(", ")}]`), v("object", ["dict"], ({ dict: a }) => Object.keys(a).length === 0 ? "{}" : `{ ${Object.entries(a).map(([c, f]) => `${c}${f.meta.required ? "" : "?"}: ${f.toString()}`).join(", ")} }`), v("union", ["list"], ({ list: a }, c) => {
|
|
1492
|
+
const f = a.map(({ toString: p }) => p()).join(" | ");
|
|
1493
|
+
return c ? `(${f})` : f;
|
|
1494
|
+
}), v("intersect", ["list"], ({ list: a }) => `${a.map((c) => c.toString(!0)).join(" & ")}`), v("transform", ["inner", "callback", "preserve"], ({ inner: a }, c) => a.toString(c)), t.exports = i;
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
const Pt = bt();
|
|
1498
|
+
var C = /* @__PURE__ */ ((e) => (e.BODY_USED = "BODY_USED", e.NO_BODY_READER = "NO_BODY_READER", e.TIMEOUT = "TIMEOUT", e.NETWORK_ERROR = "NETWORK_ERROR", e.BODY_NOT_ALLOWED = "BODY_NOT_ALLOWED", e.HOOK_CONTEXT_CHANGED = "HOOK_CONTEXT_CHANGED", e.ABORTED_BY_HOOK = "ABORTED_BY_HOOK", e.INVALID_HOOK_CALLBACK = "INVALID_HOOK_CALLBACK", e.UNEXPECTED_HOOK_RETURN = "UNEXPECTED_HOOK_RETURN", e))(C || {});
|
|
1499
|
+
class T extends Error {
|
|
1500
|
+
constructor(t, r, n, s) {
|
|
1501
|
+
super(r, s), this.code = t, this.context = n;
|
|
1502
|
+
}
|
|
1503
|
+
name = "FexiosError";
|
|
1504
|
+
static is(t) {
|
|
1505
|
+
return t?.constructor === T;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
class we extends T {
|
|
1509
|
+
constructor(t, r, n) {
|
|
1510
|
+
super(r.statusText, t, void 0, n), this.response = r;
|
|
1511
|
+
}
|
|
1512
|
+
name = "FexiosResponseError";
|
|
1513
|
+
static is(t) {
|
|
1514
|
+
return t?.constructor === we;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
function wt(e, t = 2048) {
|
|
1518
|
+
if (!(e instanceof Uint8Array))
|
|
1519
|
+
throw new TypeError("Input must be a Uint8Array");
|
|
1520
|
+
if (e.length === 0)
|
|
1521
|
+
return !0;
|
|
1522
|
+
const r = Math.min(
|
|
1523
|
+
Math.max(e.length, 256),
|
|
1524
|
+
t
|
|
1525
|
+
), n = e.slice(0, r);
|
|
1526
|
+
if (Ot(n))
|
|
1527
|
+
return !1;
|
|
1528
|
+
const s = Rt(n);
|
|
1529
|
+
if (s.nullByteRatio > 0.05 || s.highByteRatio > 0.95)
|
|
1530
|
+
return !1;
|
|
1531
|
+
const i = ["utf-8", "utf-16le", "utf-16be", "iso-8859-1"];
|
|
1532
|
+
let o = -1, u = !1;
|
|
1533
|
+
for (const l of i)
|
|
1534
|
+
try {
|
|
1535
|
+
const h = new TextDecoder(l, { fatal: !0 }).decode(n), d = St(h);
|
|
1536
|
+
d > o && (o = d, u = d > 0.7);
|
|
1537
|
+
} catch {
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
return u;
|
|
1541
|
+
}
|
|
1542
|
+
function Ot(e) {
|
|
1543
|
+
if (e.length < 4) return !1;
|
|
1544
|
+
const t = [
|
|
1545
|
+
[137, 80, 78, 71],
|
|
1546
|
+
// PNG
|
|
1547
|
+
[255, 216, 255],
|
|
1548
|
+
// JPEG
|
|
1549
|
+
[71, 73, 70],
|
|
1550
|
+
// GIF
|
|
1551
|
+
[37, 80, 68, 70],
|
|
1552
|
+
// PDF
|
|
1553
|
+
[80, 75, 3, 4],
|
|
1554
|
+
// ZIP/Office documents
|
|
1555
|
+
[80, 75, 5, 6],
|
|
1556
|
+
// ZIP empty archive
|
|
1557
|
+
[80, 75, 7, 8],
|
|
1558
|
+
// ZIP spanned archive
|
|
1559
|
+
[127, 69, 76, 70],
|
|
1560
|
+
// ELF executable
|
|
1561
|
+
[77, 90],
|
|
1562
|
+
// Windows executable
|
|
1563
|
+
[202, 254, 186, 190],
|
|
1564
|
+
// Java class file
|
|
1565
|
+
[0, 0, 1, 0],
|
|
1566
|
+
// ICO
|
|
1567
|
+
[82, 73, 70, 70]
|
|
1568
|
+
// RIFF (AVI, WAV, etc.)
|
|
1569
|
+
];
|
|
1570
|
+
for (const r of t)
|
|
1571
|
+
if (e.length >= r.length) {
|
|
1572
|
+
let n = !0;
|
|
1573
|
+
for (let s = 0; s < r.length; s++)
|
|
1574
|
+
if (e[s] !== r[s]) {
|
|
1575
|
+
n = !1;
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
if (n) return !0;
|
|
1579
|
+
}
|
|
1580
|
+
return !1;
|
|
1581
|
+
}
|
|
1582
|
+
function Rt(e) {
|
|
1583
|
+
let t = 0, r = 0, n = 0;
|
|
1584
|
+
for (const s of e)
|
|
1585
|
+
s === 0 && t++, s > 127 && r++, (s < 32 && s !== 9 && s !== 10 && s !== 13 || s === 127) && n++;
|
|
1586
|
+
return {
|
|
1587
|
+
nullByteRatio: t / e.length,
|
|
1588
|
+
highByteRatio: r / e.length,
|
|
1589
|
+
controlCharRatio: n / e.length
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
function St(e) {
|
|
1593
|
+
if (e.length === 0) return 1;
|
|
1594
|
+
let t = 1, r = 0;
|
|
1595
|
+
for (let s = 0; s < e.length; s++) {
|
|
1596
|
+
const i = e[s].charCodeAt(0);
|
|
1597
|
+
i >= 32 && i <= 126 || i === 9 || i === 10 || i === 13 || i === 32 ? r++ : i > 127 && i < 65534 ? !kt(i) && !xt(i) && r++ : t -= 0.1;
|
|
1598
|
+
}
|
|
1599
|
+
const n = r / e.length;
|
|
1600
|
+
return t *= n, Et(e) && (t *= 1.1), Math.max(0, Math.min(1, t));
|
|
1601
|
+
}
|
|
1602
|
+
function kt(e) {
|
|
1603
|
+
return e >= 0 && e <= 31 || e >= 127 && e <= 159;
|
|
1604
|
+
}
|
|
1605
|
+
function xt(e) {
|
|
1606
|
+
return e >= 57344 && e <= 63743 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109;
|
|
1607
|
+
}
|
|
1608
|
+
function Et(e) {
|
|
1609
|
+
return [
|
|
1610
|
+
/\b\w+\b/,
|
|
1611
|
+
// Words
|
|
1612
|
+
/[.!?]+\s/,
|
|
1613
|
+
// Sentence endings
|
|
1614
|
+
/\s+/,
|
|
1615
|
+
// Whitespace
|
|
1616
|
+
/[a-zA-Z]{3,}/,
|
|
1617
|
+
// English words
|
|
1618
|
+
/[\u4e00-\u9fa5]+/,
|
|
1619
|
+
// Chinese characters
|
|
1620
|
+
/\d+/
|
|
1621
|
+
// Numbers
|
|
1622
|
+
].some((t) => t.test(e));
|
|
1623
|
+
}
|
|
1624
|
+
function U(e) {
|
|
1625
|
+
if (typeof e != "object" || e === null || Object.prototype.toString.call(e) !== "[object Object]")
|
|
1626
|
+
return !1;
|
|
1627
|
+
const t = Object.getPrototypeOf(e);
|
|
1628
|
+
return t === Object.prototype || t === null;
|
|
1629
|
+
}
|
|
1630
|
+
const re = (e, ...t) => {
|
|
1631
|
+
const r = (s) => {
|
|
1632
|
+
if (Array.isArray(s)) return s.slice();
|
|
1633
|
+
if (U(s)) {
|
|
1634
|
+
const i = {};
|
|
1635
|
+
for (const o of Reflect.ownKeys(s)) i[o] = r(s[o]);
|
|
1636
|
+
return i;
|
|
1637
|
+
}
|
|
1638
|
+
return s;
|
|
1639
|
+
}, n = r(e);
|
|
1640
|
+
for (const s of t)
|
|
1641
|
+
if (s != null)
|
|
1642
|
+
for (const i of Reflect.ownKeys(s)) {
|
|
1643
|
+
const o = s[i];
|
|
1644
|
+
if (typeof o > "u") continue;
|
|
1645
|
+
const u = n[i];
|
|
1646
|
+
U(u) && U(o) ? n[i] = re(u, o) : n[i] = r(o);
|
|
1647
|
+
}
|
|
1648
|
+
return n;
|
|
1649
|
+
};
|
|
1650
|
+
class G {
|
|
1651
|
+
constructor(t, r, n) {
|
|
1652
|
+
this.rawResponse = t, this.data = r, this.ok = t.ok, this.status = t.status, this.statusText = t.statusText, this.headers = t.headers, Object.entries(n || {}).forEach(([s, i]) => {
|
|
1653
|
+
this[s] = i;
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
ok;
|
|
1657
|
+
status;
|
|
1658
|
+
statusText;
|
|
1659
|
+
headers;
|
|
1660
|
+
}
|
|
1661
|
+
async function ke(e, t, r) {
|
|
1662
|
+
if (e.bodyUsed)
|
|
1663
|
+
throw new T(
|
|
1664
|
+
C.BODY_USED,
|
|
1665
|
+
"Response body has already been used or locked"
|
|
1666
|
+
);
|
|
1667
|
+
const n = e.headers.get("content-type") || "", s = Number(e.headers.get("content-length")) || 0, i = (u, l) => l === "json" || u.startsWith("application/json"), o = (u, l, h) => h === "blob" || u.startsWith("image/") && !u.startsWith("image/svg") || u.startsWith("video/") || u.startsWith("audio/") || !wt(l);
|
|
1668
|
+
if ((e.status === 101 || e.status === 426 || e.headers.get("upgrade")) && typeof globalThis.WebSocket < "u") {
|
|
1669
|
+
const u = new WebSocket(e.url);
|
|
1670
|
+
return await new Promise((l, h) => {
|
|
1671
|
+
u.onopen = l, u.onerror = h;
|
|
1672
|
+
}), new G(e, u, {
|
|
1673
|
+
ok: !0,
|
|
1674
|
+
status: 101,
|
|
1675
|
+
statusText: "Switching Protocols"
|
|
1676
|
+
});
|
|
1677
|
+
} else if (n.startsWith("text/event-stream") && !["text", "json"].includes(t || "") && typeof globalThis.EventSource < "u") {
|
|
1678
|
+
const u = new EventSource(e.url);
|
|
1679
|
+
return await new Promise((l, h) => {
|
|
1680
|
+
u.onopen = l, u.onerror = h;
|
|
1681
|
+
}), new G(e, u);
|
|
1682
|
+
} else {
|
|
1683
|
+
if (t === "stream")
|
|
1684
|
+
return new G(
|
|
1685
|
+
e,
|
|
1686
|
+
e.body
|
|
1687
|
+
);
|
|
1688
|
+
{
|
|
1689
|
+
const u = e.clone().body?.getReader();
|
|
1690
|
+
if (!u)
|
|
1691
|
+
throw new T(
|
|
1692
|
+
C.NO_BODY_READER,
|
|
1693
|
+
"Failed to get ReadableStream from response body"
|
|
1694
|
+
);
|
|
1695
|
+
let l = new Uint8Array();
|
|
1696
|
+
for (; ; ) {
|
|
1697
|
+
const { done: d, value: R } = await u.read();
|
|
1698
|
+
if (d) break;
|
|
1699
|
+
if (R && (l = new Uint8Array([...l, ...R]), r && s > 0)) {
|
|
1700
|
+
const b = Math.min(l.length / s, 1);
|
|
1701
|
+
r(b, l);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
const h = new G(e, void 0);
|
|
1705
|
+
if (t === "arrayBuffer")
|
|
1706
|
+
return h.data = l.buffer, h;
|
|
1707
|
+
if (i(n, t))
|
|
1708
|
+
try {
|
|
1709
|
+
const d = new TextDecoder().decode(l);
|
|
1710
|
+
h.data = JSON.parse(d);
|
|
1711
|
+
} catch {
|
|
1712
|
+
}
|
|
1713
|
+
if (typeof h.data != "string" && o(n, l, t) ? h.data = new Blob([l], {
|
|
1714
|
+
type: e.headers.get("content-type") || void 0
|
|
1715
|
+
}) : h.data = new TextDecoder().decode(l), typeof h.data == "string" && t !== "text") {
|
|
1716
|
+
const d = h.data.trim(), R = d[0], b = d[d.length - 1];
|
|
1717
|
+
if (R === "{" && b === "}" || R === "[" && b === "]")
|
|
1718
|
+
try {
|
|
1719
|
+
h.data = JSON.parse(h.data);
|
|
1720
|
+
} catch {
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
if (typeof h.data > "u" && (h.data = l.length > 0 ? l : void 0), h.ok)
|
|
1724
|
+
return h;
|
|
1725
|
+
throw new we(
|
|
1726
|
+
`Request failed with status code ${e.status}`,
|
|
1727
|
+
h
|
|
1728
|
+
);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
var oe;
|
|
1733
|
+
((e) => {
|
|
1734
|
+
e.makeSearchParams = (s) => {
|
|
1735
|
+
if (!s)
|
|
1736
|
+
return new URLSearchParams();
|
|
1737
|
+
if (s instanceof URLSearchParams)
|
|
1738
|
+
return s;
|
|
1739
|
+
if (typeof s != "object" || s?.constructor !== Object)
|
|
1740
|
+
throw new TypeError("only plain object is supported");
|
|
1741
|
+
const i = new URLSearchParams(), o = (h, d) => {
|
|
1742
|
+
d != null && i.append(h, d);
|
|
1743
|
+
}, u = (h, d) => {
|
|
1744
|
+
d != null && i.set(h, d);
|
|
1745
|
+
}, l = (h, d) => {
|
|
1746
|
+
if (d != null) {
|
|
1747
|
+
if (Array.isArray(d)) {
|
|
1748
|
+
for (const R of d) o(h, R?.toString());
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
if (typeof d == "object" && d.constructor === Object) {
|
|
1752
|
+
for (const [R, b] of Object.entries(d)) {
|
|
1753
|
+
if (b == null) continue;
|
|
1754
|
+
const g = R.endsWith("[]"), w = g ? R.slice(0, -2) : R, _ = `${h}[${w}]`;
|
|
1755
|
+
if (g) {
|
|
1756
|
+
const $ = `${_}[]`;
|
|
1757
|
+
if (Array.isArray(b))
|
|
1758
|
+
for (const v of b) o($, v?.toString());
|
|
1759
|
+
else typeof b == "object" && b !== null && b.constructor === Object ? l(`${_}[]`, b) : o($, b?.toString());
|
|
1760
|
+
} else if (Array.isArray(b))
|
|
1761
|
+
for (const $ of b) o(_, $?.toString());
|
|
1762
|
+
else typeof b == "object" && b !== null && b.constructor === Object ? l(_, b) : u(_, b?.toString());
|
|
1763
|
+
}
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
u(h, d?.toString());
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
for (const [h, d] of Object.entries(s))
|
|
1770
|
+
l(h, d);
|
|
1771
|
+
return i;
|
|
1772
|
+
}, e.makeQueryString = (s) => (0, e.makeSearchParams)(s).toString(), e.makeURL = (s, i, o, u) => {
|
|
1773
|
+
const l = typeof window < "u" && window.location?.origin || "http://localhost", h = typeof s == "string" ? new URL(s, u ?? l) : new URL(s), d = (0, e.toQueryRecord)(h.searchParams), R = (0, e.mergeQueries)(d, i || {}), b = (0, e.makeSearchParams)(R);
|
|
1774
|
+
return h.search = b.toString(), h.hash = o || "", h;
|
|
1775
|
+
}, e.toQueryRecord = (s) => {
|
|
1776
|
+
typeof s == "string" && (s = (0, e.fromString)(s));
|
|
1777
|
+
const i = {}, o = (l) => {
|
|
1778
|
+
if (!l.includes("[")) return { path: [l], forceArray: !1 };
|
|
1779
|
+
const h = [l.slice(0, l.indexOf("["))], d = /\[([^\]]*)\]/g;
|
|
1780
|
+
let R, b = !1, g = !1;
|
|
1781
|
+
for (; R = d.exec(l); )
|
|
1782
|
+
R[1] === "" ? (b = !0, g = !0) : (h.push(R[1]), g = !1);
|
|
1783
|
+
return b && g && (h[h.length - 1] = h[h.length - 1] + "[]"), { path: h, forceArray: b };
|
|
1784
|
+
}, u = (l, h, d, R) => {
|
|
1785
|
+
let b = l;
|
|
1786
|
+
for (let g = 0; g < h.length; g++) {
|
|
1787
|
+
const w = h[g];
|
|
1788
|
+
g === h.length - 1 ? R ? b[w] === void 0 ? b[w] = [d] : Array.isArray(b[w]) ? b[w].push(d) : b[w] = [b[w], d] : b[w] === void 0 ? b[w] = d : Array.isArray(b[w]) ? b[w].push(d) : b[w] = [b[w], d] : ((b[w] === void 0 || typeof b[w] != "object" || Array.isArray(b[w])) && (b[w] = {}), b = b[w]);
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
for (const [l, h] of s.entries()) {
|
|
1792
|
+
const { path: d, forceArray: R } = o(String(l));
|
|
1793
|
+
u(i, d, h?.toString(), R);
|
|
1794
|
+
}
|
|
1795
|
+
return i;
|
|
1796
|
+
}, e.fromString = (s) => {
|
|
1797
|
+
const i = s.trim();
|
|
1798
|
+
if (!i) return new URLSearchParams();
|
|
1799
|
+
if (i.startsWith("?")) return new URLSearchParams(i.slice(1));
|
|
1800
|
+
const o = i.indexOf("?");
|
|
1801
|
+
if (o >= 0) {
|
|
1802
|
+
const u = i.indexOf("#", o + 1), l = i.slice(o + 1, u >= 0 ? u : void 0);
|
|
1803
|
+
return new URLSearchParams(l);
|
|
1804
|
+
}
|
|
1805
|
+
return new URLSearchParams(i);
|
|
1806
|
+
}, e.mergeQueries = (s, ...i) => {
|
|
1807
|
+
const o = t(r(s));
|
|
1808
|
+
for (const u of i)
|
|
1809
|
+
u != null && n(o, r(u));
|
|
1810
|
+
return o;
|
|
1811
|
+
};
|
|
1812
|
+
function t(s) {
|
|
1813
|
+
if (Array.isArray(s)) return s.map(t);
|
|
1814
|
+
if (U(s)) {
|
|
1815
|
+
const i = {};
|
|
1816
|
+
for (const [o, u] of Object.entries(s)) i[o] = t(u);
|
|
1817
|
+
return i;
|
|
1818
|
+
}
|
|
1819
|
+
if (s instanceof Map) {
|
|
1820
|
+
const i = {};
|
|
1821
|
+
for (const [o, u] of s.entries()) i[o] = t(u);
|
|
1822
|
+
return i;
|
|
1823
|
+
}
|
|
1824
|
+
return s;
|
|
1825
|
+
}
|
|
1826
|
+
function r(s) {
|
|
1827
|
+
if (!s) return {};
|
|
1828
|
+
if (s instanceof URLSearchParams || s instanceof FormData || s instanceof Map)
|
|
1829
|
+
return (0, e.toQueryRecord)(s);
|
|
1830
|
+
if (typeof s == "string") return (0, e.toQueryRecord)((0, e.fromString)(s));
|
|
1831
|
+
if (U(s)) return s;
|
|
1832
|
+
throw new TypeError(
|
|
1833
|
+
`unsupported type transformation, got: ${Object.prototype.toString.call(
|
|
1834
|
+
s
|
|
1835
|
+
)}`
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
function n(s, i) {
|
|
1839
|
+
for (const [o, u] of Object.entries(i)) {
|
|
1840
|
+
if (u === void 0) continue;
|
|
1841
|
+
if (u === null) {
|
|
1842
|
+
delete s[o];
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
const l = s[o];
|
|
1846
|
+
U(l) && U(u) ? n(l, u) : s[o] = t(u);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
})(oe || (oe = {}));
|
|
1850
|
+
const Ie = function(e) {
|
|
1851
|
+
const t = this.constructor.prototype, r = Reflect.get(t, e, t);
|
|
1852
|
+
function n(...s) {
|
|
1853
|
+
return Reflect.apply(r, n, s);
|
|
1854
|
+
}
|
|
1855
|
+
Reflect.setPrototypeOf(n, t);
|
|
1856
|
+
for (const s of Reflect.ownKeys(r)) {
|
|
1857
|
+
const i = Reflect.getOwnPropertyDescriptor(r, s);
|
|
1858
|
+
i && Reflect.defineProperty(n, s, i);
|
|
1859
|
+
}
|
|
1860
|
+
return n;
|
|
1861
|
+
};
|
|
1862
|
+
Ie.prototype = Object.create(Function.prototype);
|
|
1863
|
+
var V;
|
|
1864
|
+
((e) => {
|
|
1865
|
+
e.makeHeaders = (t) => {
|
|
1866
|
+
if (!t) return new Headers();
|
|
1867
|
+
if (t instanceof Headers) return new Headers(t);
|
|
1868
|
+
const r = new Headers();
|
|
1869
|
+
if (t instanceof Map) {
|
|
1870
|
+
for (const [n, s] of t.entries())
|
|
1871
|
+
if (s != null)
|
|
1872
|
+
if (Array.isArray(s))
|
|
1873
|
+
for (const i of s)
|
|
1874
|
+
i != null && r.append(n, String(i));
|
|
1875
|
+
else
|
|
1876
|
+
r.append(n, String(s));
|
|
1877
|
+
return r;
|
|
1878
|
+
}
|
|
1879
|
+
if (U(t)) {
|
|
1880
|
+
for (const [n, s] of Object.entries(t))
|
|
1881
|
+
if (s != null)
|
|
1882
|
+
if (Array.isArray(s))
|
|
1883
|
+
for (const i of s)
|
|
1884
|
+
i != null && r.append(n, String(i));
|
|
1885
|
+
else
|
|
1886
|
+
r.append(n, String(s));
|
|
1887
|
+
return r;
|
|
1888
|
+
}
|
|
1889
|
+
throw new TypeError(
|
|
1890
|
+
"only plain object, Map/ReadonlyMap, or Headers is supported"
|
|
1891
|
+
);
|
|
1892
|
+
}, e.toHeaderRecord = (t) => {
|
|
1893
|
+
if (t instanceof Headers) {
|
|
1894
|
+
const r = {};
|
|
1895
|
+
return t.forEach((n, s) => {
|
|
1896
|
+
r[s] = r[s] ? [...r[s], n] : [n];
|
|
1897
|
+
}), r;
|
|
1898
|
+
}
|
|
1899
|
+
if (t instanceof Map) {
|
|
1900
|
+
const r = {};
|
|
1901
|
+
for (const [n, s] of t.entries())
|
|
1902
|
+
if (s != null)
|
|
1903
|
+
if (Array.isArray(s)) {
|
|
1904
|
+
const i = s.filter((o) => o != null).map((o) => String(o));
|
|
1905
|
+
i.length && (r[n] = (r[n] ?? []).concat(i));
|
|
1906
|
+
} else {
|
|
1907
|
+
const i = String(s);
|
|
1908
|
+
r[n] = r[n] ? [...r[n], i] : [i];
|
|
1909
|
+
}
|
|
1910
|
+
return r;
|
|
1911
|
+
}
|
|
1912
|
+
throw new TypeError(
|
|
1913
|
+
`unsupported type transformation, got: ${Object.prototype.toString.call(
|
|
1914
|
+
t
|
|
1915
|
+
)}`
|
|
1916
|
+
);
|
|
1917
|
+
}, e.mergeHeaders = (t, ...r) => {
|
|
1918
|
+
const n = t instanceof Headers ? new Headers(t) : (0, e.makeHeaders)(t), s = (i) => {
|
|
1919
|
+
for (const [o, u] of Object.entries(i))
|
|
1920
|
+
if (u !== void 0) {
|
|
1921
|
+
if (u === null) {
|
|
1922
|
+
n.delete(o);
|
|
1923
|
+
continue;
|
|
1924
|
+
}
|
|
1925
|
+
if (Array.isArray(u)) {
|
|
1926
|
+
n.delete(o);
|
|
1927
|
+
for (const l of u)
|
|
1928
|
+
l != null && n.append(o, String(l));
|
|
1929
|
+
} else
|
|
1930
|
+
n.set(o, String(u));
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
for (const i of r) {
|
|
1934
|
+
if (i == null) continue;
|
|
1935
|
+
if (i instanceof Headers) {
|
|
1936
|
+
i.forEach((u, l) => {
|
|
1937
|
+
n.set(l, u);
|
|
1938
|
+
});
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1941
|
+
if (U(i)) {
|
|
1942
|
+
s(i);
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
const o = (0, e.toHeaderRecord)(i);
|
|
1946
|
+
for (const [u, l] of Object.entries(o)) {
|
|
1947
|
+
n.delete(u);
|
|
1948
|
+
for (const h of l) n.append(u, h);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return n;
|
|
1952
|
+
};
|
|
1953
|
+
})(V || (V = {}));
|
|
1954
|
+
class L extends Ie {
|
|
1955
|
+
static FINAL_SYMBOL = Symbol("FEXIOS_FINAL_CONTEXT");
|
|
1956
|
+
static NORMALIZED_SYMBOL = Symbol("FEXIOS_NORMALIZED_QUERY");
|
|
1957
|
+
baseConfigs;
|
|
1958
|
+
static DEFAULT_CONFIGS = {
|
|
1959
|
+
baseURL: "",
|
|
1960
|
+
timeout: 60 * 1e3,
|
|
1961
|
+
credentials: "same-origin",
|
|
1962
|
+
headers: {},
|
|
1963
|
+
query: {},
|
|
1964
|
+
responseType: void 0,
|
|
1965
|
+
fetch: globalThis.fetch
|
|
1966
|
+
};
|
|
1967
|
+
hooks = [];
|
|
1968
|
+
static ALL_METHODS = [
|
|
1969
|
+
"get",
|
|
1970
|
+
"post",
|
|
1971
|
+
"put",
|
|
1972
|
+
"patch",
|
|
1973
|
+
"delete",
|
|
1974
|
+
"head",
|
|
1975
|
+
"options",
|
|
1976
|
+
"trace"
|
|
1977
|
+
];
|
|
1978
|
+
static METHODS_WITHOUT_BODY = [
|
|
1979
|
+
"get",
|
|
1980
|
+
"head",
|
|
1981
|
+
"options",
|
|
1982
|
+
"trace"
|
|
1983
|
+
];
|
|
1984
|
+
constructor(t = {}) {
|
|
1985
|
+
super("request"), this.baseConfigs = re(L.DEFAULT_CONFIGS, t), L.ALL_METHODS.forEach(
|
|
1986
|
+
(r) => this.createMethodShortcut(r.toLowerCase())
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
async request(t, r) {
|
|
1990
|
+
let n = r = r || {};
|
|
1991
|
+
if (typeof t == "string" || t instanceof URL ? n.url = t.toString() : typeof t == "object" && (n = re(t, n)), n = await this.emit("beforeInit", n, {
|
|
1992
|
+
shouldAdjustRequestParams: !0,
|
|
1993
|
+
shouldHandleShortCircuitResponse: !0
|
|
1994
|
+
}), n[L.FINAL_SYMBOL]) return n;
|
|
1995
|
+
if (L.METHODS_WITHOUT_BODY.includes(
|
|
1996
|
+
n.method?.toLocaleLowerCase()
|
|
1997
|
+
) && n.body)
|
|
1998
|
+
throw new T(
|
|
1999
|
+
C.BODY_NOT_ALLOWED,
|
|
2000
|
+
`Request method "${n.method}" does not allow body`
|
|
2001
|
+
);
|
|
2002
|
+
if (n = await this.emit("beforeRequest", n, {
|
|
2003
|
+
shouldAdjustRequestParams: !0,
|
|
2004
|
+
shouldHandleShortCircuitResponse: !0,
|
|
2005
|
+
preAdjust: !0,
|
|
2006
|
+
requestOptionsOverridesURLSearchParams: !0,
|
|
2007
|
+
preRequestOptionsOverridesURLSearchParams: !0,
|
|
2008
|
+
postRequestOptionsOverridesURLSearchParams: !0
|
|
2009
|
+
}), n[L.FINAL_SYMBOL]) return n;
|
|
2010
|
+
let s;
|
|
2011
|
+
const i = {};
|
|
2012
|
+
if (typeof n.body < "u" && n.body !== null && (n.body instanceof Blob || n.body instanceof FormData || n.body instanceof URLSearchParams ? s = n.body : typeof n.body == "object" && n.body !== null ? (s = JSON.stringify(n.body), n.headers = this.mergeHeaders(n.headers, {
|
|
2013
|
+
"Content-Type": "application/json"
|
|
2014
|
+
})) : s = n.body), !V.makeHeaders(
|
|
2015
|
+
r.headers || {}
|
|
2016
|
+
).get("content-type") && s && (s instanceof FormData || s instanceof URLSearchParams ? i["content-type"] = null : typeof s == "string" && typeof n.body == "object" ? i["content-type"] = "application/json" : s instanceof Blob && (i["content-type"] = s.type || "application/octet-stream")), n.body = s, n = await this.emit("afterBodyTransformed", n, {
|
|
2017
|
+
shouldAdjustRequestParams: !0,
|
|
2018
|
+
shouldHandleShortCircuitResponse: !0,
|
|
2019
|
+
preAdjust: !0,
|
|
2020
|
+
postRequestOptionsOverridesURLSearchParams: !0
|
|
2021
|
+
}), n[L.FINAL_SYMBOL]) return n;
|
|
2022
|
+
const o = n.abortController || globalThis.AbortController ? new AbortController() : void 0, u = n.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", l = new URL(
|
|
2023
|
+
n.url.toString(),
|
|
2024
|
+
u
|
|
2025
|
+
), h = oe.makeURL(
|
|
2026
|
+
l,
|
|
2027
|
+
n.query,
|
|
2028
|
+
l.hash
|
|
2029
|
+
).toString(), d = new Request(h, {
|
|
2030
|
+
method: n.method || "GET",
|
|
2031
|
+
credentials: n.credentials,
|
|
2032
|
+
cache: n.cache,
|
|
2033
|
+
mode: n.mode,
|
|
2034
|
+
headers: V.mergeHeaders(
|
|
2035
|
+
this.baseConfigs.headers,
|
|
2036
|
+
n.headers || {},
|
|
2037
|
+
i
|
|
2038
|
+
),
|
|
2039
|
+
body: n.body,
|
|
2040
|
+
signal: o?.signal
|
|
2041
|
+
});
|
|
2042
|
+
if (n.rawRequest = d, n = await this.emit("beforeActualFetch", n, {
|
|
2043
|
+
shouldHandleShortCircuitResponse: !0
|
|
2044
|
+
}), n[L.FINAL_SYMBOL]) return n;
|
|
2045
|
+
const R = n.timeout || this.baseConfigs.timeout || 60 * 1e3;
|
|
2046
|
+
if (n.url.startsWith("ws"))
|
|
2047
|
+
try {
|
|
2048
|
+
const g = new WebSocket(n.url);
|
|
2049
|
+
return await new Promise((w, _) => {
|
|
2050
|
+
const $ = setTimeout(() => {
|
|
2051
|
+
_(
|
|
2052
|
+
new T(
|
|
2053
|
+
C.TIMEOUT,
|
|
2054
|
+
`WebSocket connection timed out after ${R}ms`,
|
|
2055
|
+
n
|
|
2056
|
+
)
|
|
2057
|
+
);
|
|
2058
|
+
}, R);
|
|
2059
|
+
g.onopen = () => {
|
|
2060
|
+
clearTimeout($), w();
|
|
2061
|
+
}, g.onerror = (v) => {
|
|
2062
|
+
clearTimeout($), _(
|
|
2063
|
+
new T(
|
|
2064
|
+
C.NETWORK_ERROR,
|
|
2065
|
+
"WebSocket connection failed",
|
|
2066
|
+
n
|
|
2067
|
+
)
|
|
2068
|
+
);
|
|
2069
|
+
}, g.onclose = (v) => {
|
|
2070
|
+
v.code !== 1e3 && (clearTimeout($), _(
|
|
2071
|
+
new T(
|
|
2072
|
+
C.NETWORK_ERROR,
|
|
2073
|
+
`WebSocket closed with code ${v.code}`,
|
|
2074
|
+
n
|
|
2075
|
+
)
|
|
2076
|
+
));
|
|
2077
|
+
};
|
|
2078
|
+
}), n.rawResponse = new Response(), n.response = new G(n.rawResponse, g, {
|
|
2079
|
+
ok: !0,
|
|
2080
|
+
status: 101,
|
|
2081
|
+
statusText: "Switching Protocols"
|
|
2082
|
+
}), n.data = g, n.headers = new Headers(), this.emit("afterResponse", n);
|
|
2083
|
+
} catch (g) {
|
|
2084
|
+
throw g instanceof T ? g : new T(
|
|
2085
|
+
C.NETWORK_ERROR,
|
|
2086
|
+
`WebSocket creation failed: ${g}`,
|
|
2087
|
+
n
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
let b;
|
|
2091
|
+
try {
|
|
2092
|
+
o && (b = setTimeout(() => {
|
|
2093
|
+
o.abort();
|
|
2094
|
+
}, R));
|
|
2095
|
+
const g = await (r.fetch || this.baseConfigs.fetch || globalThis.fetch)(n.rawRequest).catch((w) => {
|
|
2096
|
+
throw b && clearTimeout(b), o?.signal.aborted ? new T(
|
|
2097
|
+
C.TIMEOUT,
|
|
2098
|
+
`Request timed out after ${R}ms`,
|
|
2099
|
+
n
|
|
2100
|
+
) : new T(C.NETWORK_ERROR, w.message, n);
|
|
2101
|
+
});
|
|
2102
|
+
return b && clearTimeout(b), n.rawResponse = g, n.response = await ke(
|
|
2103
|
+
g,
|
|
2104
|
+
n.responseType,
|
|
2105
|
+
(w, _) => {
|
|
2106
|
+
r?.onProgress?.(w, _);
|
|
2107
|
+
}
|
|
2108
|
+
), n.data = n.response.data, n.headers = n.response.headers, this.emit("afterResponse", n);
|
|
2109
|
+
} catch (g) {
|
|
2110
|
+
throw b && clearTimeout(b), g;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
mergeQueries = oe.mergeQueries;
|
|
2114
|
+
mergeHeaders = V.mergeHeaders;
|
|
2115
|
+
normalizeContext(t, r = {}) {
|
|
2116
|
+
const n = t, s = n.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", i = new URL(
|
|
2117
|
+
s,
|
|
2118
|
+
globalThis.location?.href || "http://localhost"
|
|
2119
|
+
), o = new URL(n.url.toString(), i), u = !!n[L.NORMALIZED_SYMBOL];
|
|
2120
|
+
n.baseURL = i ? i.origin : o.origin;
|
|
2121
|
+
let l;
|
|
2122
|
+
u ? l = r.requestOptionsOverridesURLSearchParams ? this.mergeQueries({}, o.search, n.query) : this.mergeQueries({}, n.query, o.search) : (l = r.requestOptionsOverridesURLSearchParams ? this.mergeQueries(
|
|
2123
|
+
i?.search || "",
|
|
2124
|
+
this.baseConfigs.query,
|
|
2125
|
+
o.search,
|
|
2126
|
+
n.query
|
|
2127
|
+
) : this.mergeQueries(
|
|
2128
|
+
i?.search || "",
|
|
2129
|
+
this.baseConfigs.query,
|
|
2130
|
+
n.query,
|
|
2131
|
+
o.search
|
|
2132
|
+
), n[L.NORMALIZED_SYMBOL] = !0), n.query = l;
|
|
2133
|
+
const h = new URL(o);
|
|
2134
|
+
return h.search = "", n.url = h.toString(), n;
|
|
2135
|
+
}
|
|
2136
|
+
async emit(t, r, n = {}) {
|
|
2137
|
+
const s = this.hooks.filter((i) => i.event === t);
|
|
2138
|
+
if (n?.shouldAdjustRequestParams && n?.preAdjust)
|
|
2139
|
+
try {
|
|
2140
|
+
r = this.normalizeContext(r, {
|
|
2141
|
+
requestOptionsOverridesURLSearchParams: n.preRequestOptionsOverridesURLSearchParams
|
|
2142
|
+
});
|
|
2143
|
+
} catch {
|
|
2144
|
+
}
|
|
2145
|
+
try {
|
|
2146
|
+
let i = 0;
|
|
2147
|
+
for (const o of s) {
|
|
2148
|
+
const u = `${t}#${o.action.name || `anonymous#${i}`}`, l = Symbol("FEXIOS_HOOK_CONTEXT");
|
|
2149
|
+
r[l] = l;
|
|
2150
|
+
const h = r.url;
|
|
2151
|
+
let d = "";
|
|
2152
|
+
try {
|
|
2153
|
+
const b = this.mergeQueries(
|
|
2154
|
+
{},
|
|
2155
|
+
r.query || {}
|
|
2156
|
+
);
|
|
2157
|
+
d = JSON.stringify(b);
|
|
2158
|
+
} catch {
|
|
2159
|
+
}
|
|
2160
|
+
let R = await o.action.call(this, r);
|
|
2161
|
+
if (R === void 0 && (R = r), R === !1)
|
|
2162
|
+
throw new T(
|
|
2163
|
+
C.ABORTED_BY_HOOK,
|
|
2164
|
+
`Request aborted by hook "${u}"`,
|
|
2165
|
+
r
|
|
2166
|
+
);
|
|
2167
|
+
if (R instanceof Response) {
|
|
2168
|
+
const b = R, g = { ...r, rawResponse: b }, w = await ke(
|
|
2169
|
+
b,
|
|
2170
|
+
r.responseType,
|
|
2171
|
+
(_, $) => {
|
|
2172
|
+
r.onProgress?.(_, $);
|
|
2173
|
+
}
|
|
2174
|
+
);
|
|
2175
|
+
if (g.response = w, g.data = w.data, g.headers = w.headers, t !== "afterResponse") {
|
|
2176
|
+
const _ = await this.emit("afterResponse", g);
|
|
2177
|
+
return _[L.FINAL_SYMBOL] = !0, _;
|
|
2178
|
+
} else
|
|
2179
|
+
return g[L.FINAL_SYMBOL] = !0, g;
|
|
2180
|
+
} else if (typeof R == "object" && R[l] === l)
|
|
2181
|
+
r = R;
|
|
2182
|
+
else {
|
|
2183
|
+
const b = globalThis["".concat("console")];
|
|
2184
|
+
try {
|
|
2185
|
+
throw new T(
|
|
2186
|
+
C.HOOK_CONTEXT_CHANGED,
|
|
2187
|
+
`Hook "${u}" should return the original FexiosContext or return false to abort the request, but got "${R}".`
|
|
2188
|
+
);
|
|
2189
|
+
} catch (g) {
|
|
2190
|
+
b.warn(g.stack || g);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
if (n?.shouldAdjustRequestParams)
|
|
2194
|
+
try {
|
|
2195
|
+
const b = r.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", g = new URL(
|
|
2196
|
+
r.url.toString(),
|
|
2197
|
+
b
|
|
2198
|
+
);
|
|
2199
|
+
let w = {};
|
|
2200
|
+
if (d)
|
|
2201
|
+
try {
|
|
2202
|
+
w = JSON.parse(d);
|
|
2203
|
+
} catch {
|
|
2204
|
+
}
|
|
2205
|
+
const _ = r.query || {}, $ = this.mergeQueries(
|
|
2206
|
+
w,
|
|
2207
|
+
g.search,
|
|
2208
|
+
_
|
|
2209
|
+
);
|
|
2210
|
+
r.query = $;
|
|
2211
|
+
const v = new URL(g);
|
|
2212
|
+
v.search = "", r.url = v.toString();
|
|
2213
|
+
} catch {
|
|
2214
|
+
}
|
|
2215
|
+
delete r[l], i++;
|
|
2216
|
+
}
|
|
2217
|
+
} catch (i) {
|
|
2218
|
+
return Promise.reject(i);
|
|
2219
|
+
}
|
|
2220
|
+
return r;
|
|
2221
|
+
}
|
|
2222
|
+
on(t, r, n = !1) {
|
|
2223
|
+
if (typeof r != "function")
|
|
2224
|
+
throw new T(
|
|
2225
|
+
C.INVALID_HOOK_CALLBACK,
|
|
2226
|
+
`Hook should be a function, but got "${typeof r}"`
|
|
2227
|
+
);
|
|
2228
|
+
return this.hooks[n ? "unshift" : "push"]({
|
|
2229
|
+
event: t,
|
|
2230
|
+
action: r
|
|
2231
|
+
}), this;
|
|
2232
|
+
}
|
|
2233
|
+
off(t, r) {
|
|
2234
|
+
return t === "*" || !t ? this.hooks = this.hooks.filter((n) => n.action !== r) : this.hooks = this.hooks.filter(
|
|
2235
|
+
(n) => n.event !== t || n.action !== r
|
|
2236
|
+
), this;
|
|
2237
|
+
}
|
|
2238
|
+
createInterceptor(t) {
|
|
2239
|
+
return {
|
|
2240
|
+
handlers: () => this.hooks.filter((r) => r.event === t).map((r) => r.action),
|
|
2241
|
+
use: (r, n = !1) => this.on(t, r, n),
|
|
2242
|
+
clear: () => {
|
|
2243
|
+
this.hooks = this.hooks.filter((r) => r.event !== t);
|
|
2244
|
+
}
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
interceptors = {
|
|
2248
|
+
request: this.createInterceptor("beforeRequest"),
|
|
2249
|
+
response: this.createInterceptor("afterResponse")
|
|
2250
|
+
};
|
|
2251
|
+
createMethodShortcut(t) {
|
|
2252
|
+
return Reflect.defineProperty(this, t, {
|
|
2253
|
+
get: () => (r, n, s) => (L.METHODS_WITHOUT_BODY.includes(
|
|
2254
|
+
t.toLocaleLowerCase()
|
|
2255
|
+
) ? s = n : (s = s || {}, s.body = n), this.request(r, {
|
|
2256
|
+
...s,
|
|
2257
|
+
method: t
|
|
2258
|
+
}))
|
|
2259
|
+
}), this;
|
|
2260
|
+
}
|
|
2261
|
+
extends(t) {
|
|
2262
|
+
const r = new L(re(this.baseConfigs, t));
|
|
2263
|
+
return r.hooks = [...this.hooks], r._plugins = new Map(this._plugins), r._plugins.forEach(async (n) => {
|
|
2264
|
+
await r.plugin(n);
|
|
2265
|
+
}), r;
|
|
2266
|
+
}
|
|
2267
|
+
create = L.create;
|
|
2268
|
+
static create(t) {
|
|
2269
|
+
return new L(t);
|
|
2270
|
+
}
|
|
2271
|
+
_plugins = /* @__PURE__ */ new Map();
|
|
2272
|
+
async plugin(t) {
|
|
2273
|
+
if (typeof t?.name == "string" && typeof t?.install == "function") {
|
|
2274
|
+
if (this._plugins.has(t.name))
|
|
2275
|
+
return this;
|
|
2276
|
+
const r = await t.install(this);
|
|
2277
|
+
if (this._plugins.set(t.name, t), r instanceof L)
|
|
2278
|
+
return r;
|
|
2279
|
+
}
|
|
2280
|
+
return this;
|
|
2281
|
+
}
|
|
2282
|
+
// 版本弃子们.jpg
|
|
2283
|
+
/** @deprecated Use checkIsPlainObject from utils instead */
|
|
2284
|
+
checkIsPlainObject = U;
|
|
2285
|
+
/** @deprecated Use `mergeQueries` instead */
|
|
2286
|
+
mergeQuery = this.mergeQueries;
|
|
2287
|
+
}
|
|
2288
|
+
const At = L.create, xe = At();
|
|
2289
|
+
typeof globalThis < "u" ? globalThis.fexios = xe : typeof window < "u" && (window.fexios = xe);
|
|
2290
|
+
var ce;
|
|
2291
|
+
((e) => {
|
|
2292
|
+
function t(n) {
|
|
2293
|
+
return Array.isArray(n) ? n.join("|") : typeof n == "boolean" || n === null ? n ? "1" : void 0 : typeof n == "number" ? "" + n : n;
|
|
2294
|
+
}
|
|
2295
|
+
e.normalizeParamValue = t;
|
|
2296
|
+
function r(n) {
|
|
2297
|
+
const s = (o) => o && (o instanceof URLSearchParams || o instanceof FormData);
|
|
2298
|
+
if (n == null)
|
|
2299
|
+
return;
|
|
2300
|
+
const i = new FormData();
|
|
2301
|
+
if (s(n))
|
|
2302
|
+
return n.forEach((o, u) => {
|
|
2303
|
+
const l = t(o);
|
|
2304
|
+
l != null && i.append(u, l);
|
|
2305
|
+
}), i;
|
|
2306
|
+
if (U(n))
|
|
2307
|
+
return Object.entries(n).forEach(([o, u]) => {
|
|
2308
|
+
const l = t(u);
|
|
2309
|
+
l != null && i.append(o, l);
|
|
2310
|
+
}), i;
|
|
2311
|
+
}
|
|
2312
|
+
e.normalizeBody = r;
|
|
2313
|
+
})(ce || (ce = {}));
|
|
2314
|
+
var Q = /* @__PURE__ */ ((e) => (e.HTTP_ERROR = "HTTP_ERROR", e.LOGIN_FAILED = "LOGIN_FAILED", e.LOGIN_RETRY_LIMIT_EXCEEDED = "LOGIN_RETRY_LIMIT_EXCEEDED", e.TOKEN_RETRY_LIMIT_EXCEEDED = "TOKEN_RETRY_LIMIT_EXCEEDED", e))(Q || {});
|
|
2315
|
+
class D extends Error {
|
|
2316
|
+
constructor(t, r = "", n) {
|
|
2317
|
+
super(), this.code = t, this.message = r, this.cause = n, this.name = "WikiSaikouError";
|
|
2318
|
+
}
|
|
2319
|
+
static is(t, r) {
|
|
2320
|
+
return t instanceof this && (r === void 0 || t.code === r);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
class H extends Error {
|
|
2324
|
+
constructor(t, r) {
|
|
2325
|
+
super(), this.errors = t, this.cause = r, this.name = "MediaWikiApiError", this.errors = H.normalizeErrors(t), this.message = t.map((n) => n.text).filter(Boolean).join(`
|
|
2326
|
+
`), this.code = this.isBadTokenError() ? "badtoken" : this.errors[0]?.code || "Unknown Error";
|
|
2327
|
+
}
|
|
2328
|
+
get firstError() {
|
|
2329
|
+
return this.errors[0];
|
|
2330
|
+
}
|
|
2331
|
+
isBadTokenError() {
|
|
2332
|
+
return this.errors.some((t) => t.code === "badtoken") || ["NeedToken", "WrongToken"].includes(this.cause?.data?.login?.result);
|
|
2333
|
+
}
|
|
2334
|
+
toString() {
|
|
2335
|
+
return `[${this.name} ${this.code}]`;
|
|
2336
|
+
}
|
|
2337
|
+
static is(t) {
|
|
2338
|
+
return t instanceof this;
|
|
2339
|
+
}
|
|
2340
|
+
static normalizeErrors(t) {
|
|
2341
|
+
return Array.isArray(t) === !1 ? [] : t.filter((r) => typeof r == "object" && !!r?.code).map((r) => r.text ? r : r.info ? { ...r, text: r.info } : r["*"] ? { ...r, text: r["*"] } : { ...r, text: "" });
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
((e) => {
|
|
2345
|
+
function t(i) {
|
|
2346
|
+
if (i == null) return;
|
|
2347
|
+
if (i?.response?.data !== void 0) return i.response.data;
|
|
2348
|
+
if (i?.data !== void 0) return i.data;
|
|
2349
|
+
const o = i instanceof Error ? i.cause : void 0;
|
|
2350
|
+
return o?.response?.data !== void 0 ? o.response.data : o?.data !== void 0 ? o.data : i || void 0;
|
|
2351
|
+
}
|
|
2352
|
+
function r(i) {
|
|
2353
|
+
return n(i).length > 0;
|
|
2354
|
+
}
|
|
2355
|
+
e.includesMediaWikiApiError = r, e.normalizeMwApiErrors = H.normalizeErrors;
|
|
2356
|
+
function n(i) {
|
|
2357
|
+
let o = t(i);
|
|
2358
|
+
if (typeof o != "object" || o === null)
|
|
2359
|
+
return [];
|
|
2360
|
+
const u = o?.error, l = o?.errors, h = [];
|
|
2361
|
+
return u && h.push(u), Array.isArray(l) && h.push(...l), (0, e.normalizeMwApiErrors)(h);
|
|
2362
|
+
}
|
|
2363
|
+
e.extractMediaWikiApiErrors = n;
|
|
2364
|
+
function s(i) {
|
|
2365
|
+
if (H.is(i))
|
|
2366
|
+
return i.isBadTokenError();
|
|
2367
|
+
{
|
|
2368
|
+
const o = n(i);
|
|
2369
|
+
return new H(o).isBadTokenError();
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
e.isBadTokenError = s;
|
|
2373
|
+
})(D || (D = {}));
|
|
2374
|
+
const Ee = Symbol.for("__FEXIOS_SAIKOU__");
|
|
2375
|
+
function Ue(e) {
|
|
2376
|
+
const t = e instanceof L ? e : new L({
|
|
2377
|
+
baseURL: e instanceof URL ? e.toString() : String(e),
|
|
2378
|
+
responseType: "json"
|
|
2379
|
+
});
|
|
2380
|
+
return t[Ee] || (Reflect.defineProperty(t, Ee, {
|
|
2381
|
+
get: () => !0,
|
|
2382
|
+
enumerable: !1,
|
|
2383
|
+
configurable: !1
|
|
2384
|
+
}), t._tokens = /* @__PURE__ */ new Map(), t.on("afterResponse", (r) => {
|
|
2385
|
+
const { data: n, rawRequest: s } = r, i = s?.headers.get("x-mw-token-name");
|
|
2386
|
+
i && D.isBadTokenError(n) && t._tokens.delete(i);
|
|
2387
|
+
const o = n?.query?.tokens;
|
|
2388
|
+
o && typeof o == "object" && Object.entries(o).forEach(([l, h]) => {
|
|
2389
|
+
typeof h == "string" && t._tokens.set(l.replace(/token$/i, "").toLowerCase(), h);
|
|
2390
|
+
});
|
|
2391
|
+
const u = n?.login?.token;
|
|
2392
|
+
return typeof u == "string" && t._tokens.set("login", u), r;
|
|
2393
|
+
}), t.on("beforeInit", (r) => {
|
|
2394
|
+
if (r.method?.toLowerCase() !== "post")
|
|
2395
|
+
return r;
|
|
2396
|
+
if (r.body === void 0 || r.body === null)
|
|
2397
|
+
return r.body = void 0, r;
|
|
2398
|
+
const n = r.body = ce.normalizeBody(r.body), s = new URLSearchParams(r.query);
|
|
2399
|
+
return n.has("format") && s.delete("format"), n.has("formatversion") && s.delete("formatversion"), n.has("action") && s.delete("action"), n.has("origin") && (s.set("origin", "" + n.get("origin")), n.delete("origin")), r.query = Object.fromEntries(s.entries()), r;
|
|
2400
|
+
}), t.on("beforeInit", (r) => (r.query = ce.normalizeBody(r.query) || {}, r)), t.on("beforeRequest", (r) => {
|
|
2401
|
+
const n = new URL(r.url), s = n.searchParams;
|
|
2402
|
+
if (globalThis.location && (!s.has("origin") && location.origin !== n.origin ? (s.set("origin", location.origin), t.baseConfigs.credentials = "include", t.baseConfigs.mode = "cors") : location.origin === n.origin && (s.delete("origin"), t.baseConfigs.credentials = void 0, t.baseConfigs.mode = void 0)), n.searchParams.has("origin")) {
|
|
2403
|
+
const i = encodeURIComponent(
|
|
2404
|
+
n.searchParams.get("origin") || ""
|
|
2405
|
+
).replace(/\./g, "%2E");
|
|
2406
|
+
r.query = {}, n.searchParams.delete("origin"), r.url = `${n}${n.search ? "&" : "?"}origin=${i}`;
|
|
2407
|
+
}
|
|
2408
|
+
return r;
|
|
2409
|
+
})), t;
|
|
2410
|
+
}
|
|
2411
|
+
const W = (e, ...t) => {
|
|
2412
|
+
const r = (i) => Object.prototype.toString.call(i) === "[object Object]", n = (i) => {
|
|
2413
|
+
if (Array.isArray(i)) return i.slice();
|
|
2414
|
+
if (r(i)) {
|
|
2415
|
+
const o = {};
|
|
2416
|
+
for (const u of Reflect.ownKeys(i)) o[u] = n(i[u]);
|
|
2417
|
+
return o;
|
|
2418
|
+
}
|
|
2419
|
+
return i;
|
|
2420
|
+
}, s = n(e);
|
|
2421
|
+
for (const i of t)
|
|
2422
|
+
if (i != null)
|
|
2423
|
+
for (const o of Reflect.ownKeys(i)) {
|
|
2424
|
+
const u = i[o];
|
|
2425
|
+
if (typeof u > "u") continue;
|
|
2426
|
+
const l = s[o];
|
|
2427
|
+
r(l) && r(u) ? s[o] = W(l, u) : s[o] = n(u);
|
|
2428
|
+
}
|
|
2429
|
+
return s;
|
|
2430
|
+
}, vt = (e, t, r) => {
|
|
2431
|
+
let n = { ...Ne.DEFAULT_CONFIGS };
|
|
2432
|
+
if (typeof e == "string" ? n = W(n, {
|
|
2433
|
+
baseURL: e,
|
|
2434
|
+
fexiosConfigs: t || {},
|
|
2435
|
+
defaultParams: r || {}
|
|
2436
|
+
}) : typeof e == "object" && e !== null && (n = W(n, e)), !n.baseURL && typeof window == "object" && window.mediaWiki) {
|
|
2437
|
+
const { wgServer: s, wgScriptPath: i } = window.mediaWiki?.config?.get(["wgServer", "wgScriptPath"]) || {};
|
|
2438
|
+
typeof s == "string" && typeof i == "string" && (n.baseURL = `${s}${i}/api.php`);
|
|
2439
|
+
}
|
|
2440
|
+
if (typeof n.baseURL != "string")
|
|
2441
|
+
throw new Error("baseURL is required");
|
|
2442
|
+
return n;
|
|
2443
|
+
}, _t = () => {
|
|
2444
|
+
}, jt = async (e, t) => {
|
|
2445
|
+
let r = 0;
|
|
2446
|
+
const { retry: n = 3, onRetry: s = _t, shouldRetry: i = () => !0 } = t;
|
|
2447
|
+
let o;
|
|
2448
|
+
do
|
|
2449
|
+
try {
|
|
2450
|
+
return await e();
|
|
2451
|
+
} catch (u) {
|
|
2452
|
+
if (o = u, i(u, r))
|
|
2453
|
+
s(u, r), r++;
|
|
2454
|
+
else
|
|
2455
|
+
throw u;
|
|
2456
|
+
}
|
|
2457
|
+
while (r < n);
|
|
2458
|
+
throw o || new Error("Retry failed");
|
|
2459
|
+
};
|
|
2460
|
+
const J = class {
|
|
2461
|
+
constructor(t, r, n) {
|
|
2462
|
+
this.version = "7.1.2", this.token = this.getToken;
|
|
2463
|
+
const s = this.config = vt(
|
|
2464
|
+
t,
|
|
2465
|
+
r,
|
|
2466
|
+
n
|
|
2467
|
+
);
|
|
2468
|
+
this.request = Ue(s.baseURL);
|
|
2469
|
+
}
|
|
2470
|
+
setBaseURL(t) {
|
|
2471
|
+
return this.config.baseURL = t, this.request.baseConfigs.baseURL = t, this;
|
|
2472
|
+
}
|
|
2473
|
+
/** Base methods encapsulation */
|
|
2474
|
+
async get(t, r) {
|
|
2475
|
+
return this.runRequestWithApiErrorMapping(
|
|
2476
|
+
() => this.request.get(
|
|
2477
|
+
"",
|
|
2478
|
+
W(
|
|
2479
|
+
{},
|
|
2480
|
+
this.config.fexiosConfigs,
|
|
2481
|
+
{ query: W(this.config.defaultParams, t) },
|
|
2482
|
+
r
|
|
2483
|
+
)
|
|
2484
|
+
)
|
|
2485
|
+
);
|
|
2486
|
+
}
|
|
2487
|
+
async post(t, r) {
|
|
2488
|
+
return this.runRequestWithApiErrorMapping(
|
|
2489
|
+
() => this.request.post(
|
|
2490
|
+
"",
|
|
2491
|
+
t,
|
|
2492
|
+
W(
|
|
2493
|
+
{},
|
|
2494
|
+
this.config.fexiosConfigs,
|
|
2495
|
+
{
|
|
2496
|
+
query: this.config.defaultParams
|
|
2497
|
+
},
|
|
2498
|
+
r
|
|
2499
|
+
)
|
|
2500
|
+
)
|
|
2501
|
+
);
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
* Wrap a request to map non-2xx responses containing MediaWiki API error bodies
|
|
2505
|
+
* into MediaWikiApiError when throwOnApiError=true, and then pass 2xx responses
|
|
2506
|
+
* through handleApiResponse for unified processing.
|
|
2507
|
+
*/
|
|
2508
|
+
async runRequestWithApiErrorMapping(t) {
|
|
2509
|
+
try {
|
|
2510
|
+
const r = await t();
|
|
2511
|
+
return this.handleApiResponse(r);
|
|
2512
|
+
} catch (r) {
|
|
2513
|
+
throw this.config.throwOnApiError && D.includesMediaWikiApiError(r) ? new H(
|
|
2514
|
+
D.extractMediaWikiApiErrors(r),
|
|
2515
|
+
r
|
|
2516
|
+
) : r;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
throwIfApiError(t) {
|
|
2520
|
+
const r = D.extractMediaWikiApiErrors(t);
|
|
2521
|
+
if (r.length > 0)
|
|
2522
|
+
throw new H(r, t);
|
|
2523
|
+
}
|
|
2524
|
+
handleApiResponse(t) {
|
|
2525
|
+
return this.config.throwOnApiError && this.throwIfApiError(t.data), t;
|
|
2526
|
+
}
|
|
2527
|
+
/** Token Handler */
|
|
2528
|
+
get tokens() {
|
|
2529
|
+
return this.request._tokens;
|
|
2530
|
+
}
|
|
2531
|
+
async fetchTokens(t = ["csrf"]) {
|
|
2532
|
+
return this.config.fexiosConfigs.credentials = "include", await this.get({
|
|
2533
|
+
action: "query",
|
|
2534
|
+
meta: "tokens",
|
|
2535
|
+
type: t
|
|
2536
|
+
}), this.tokens;
|
|
2537
|
+
}
|
|
2538
|
+
async getToken(t = "csrf", r = !1) {
|
|
2539
|
+
return (!this.tokens.get(t) || r) && (this.tokens.delete(t), await this.fetchTokens([t])), this.tokens.get(t);
|
|
2540
|
+
}
|
|
2541
|
+
badToken(t) {
|
|
2542
|
+
return this.tokens.delete(t), this.tokens;
|
|
2543
|
+
}
|
|
2544
|
+
async postWithToken(t, r, n) {
|
|
2545
|
+
const {
|
|
2546
|
+
tokenName: s = "token",
|
|
2547
|
+
retry: i = 3,
|
|
2548
|
+
noCache: o = !1,
|
|
2549
|
+
fexiosOptions: u
|
|
2550
|
+
} = n || {};
|
|
2551
|
+
if (i < 1)
|
|
2552
|
+
throw new D(
|
|
2553
|
+
Q.TOKEN_RETRY_LIMIT_EXCEEDED,
|
|
2554
|
+
"The limit of the number of times to automatically re-acquire the token has been exceeded"
|
|
2555
|
+
);
|
|
2556
|
+
let l = 0;
|
|
2557
|
+
return jt(
|
|
2558
|
+
async () => {
|
|
2559
|
+
const h = await this.getToken(
|
|
2560
|
+
t,
|
|
2561
|
+
o || l > 0
|
|
2562
|
+
);
|
|
2563
|
+
try {
|
|
2564
|
+
const d = await this.post(
|
|
2565
|
+
{
|
|
2566
|
+
[s]: h,
|
|
2567
|
+
...r
|
|
2568
|
+
},
|
|
2569
|
+
W(u || {}, {
|
|
2570
|
+
headers: { "x-mw-token-name": t }
|
|
2571
|
+
})
|
|
2572
|
+
);
|
|
2573
|
+
if (D.isBadTokenError(d.data))
|
|
2574
|
+
throw d;
|
|
2575
|
+
return d;
|
|
2576
|
+
} catch (d) {
|
|
2577
|
+
throw D.isBadTokenError(d) || d?.ok === !1 || H.is(d) ? d : new D(
|
|
2578
|
+
Q.HTTP_ERROR,
|
|
2579
|
+
"Network/transport or SDK-internal error (not a MediaWiki API error)",
|
|
2580
|
+
d
|
|
2581
|
+
);
|
|
2582
|
+
}
|
|
2583
|
+
},
|
|
2584
|
+
{
|
|
2585
|
+
retry: i,
|
|
2586
|
+
onRetry: (h, d) => {
|
|
2587
|
+
l = d + 1;
|
|
2588
|
+
},
|
|
2589
|
+
shouldRetry: (h) => D.isBadTokenError(h) || h?.ok === !1
|
|
2590
|
+
}
|
|
2591
|
+
).catch((h) => {
|
|
2592
|
+
throw D.isBadTokenError(h) || h?.ok === !1 ? new D(
|
|
2593
|
+
Q.TOKEN_RETRY_LIMIT_EXCEEDED,
|
|
2594
|
+
"Retry attempts for acquiring/using token exhausted",
|
|
2595
|
+
h
|
|
2596
|
+
) : h;
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
postWithEditToken(t) {
|
|
2600
|
+
return this.postWithToken("csrf", t);
|
|
2601
|
+
}
|
|
2602
|
+
// for backward compatibility
|
|
2603
|
+
/** @deprecated Use `this.config.baseURL` instead */
|
|
2604
|
+
get baseURL() {
|
|
2605
|
+
return this.config.baseURL;
|
|
2606
|
+
}
|
|
2607
|
+
/** @deprecated Use `this.config.defaultParams` instead */
|
|
2608
|
+
get defaultParams() {
|
|
2609
|
+
return this.config.defaultParams;
|
|
2610
|
+
}
|
|
2611
|
+
/** @deprecated Use `this.config.fexiosConfigs` instead */
|
|
2612
|
+
get defaultOptions() {
|
|
2613
|
+
return this.config.fexiosConfigs;
|
|
2614
|
+
}
|
|
2615
|
+
};
|
|
2616
|
+
J.INIT_DEFAULT_PARAMS = {
|
|
2617
|
+
action: "query",
|
|
2618
|
+
errorformat: "plaintext",
|
|
2619
|
+
format: "json",
|
|
2620
|
+
formatversion: 2
|
|
2621
|
+
}, J.DEFAULT_CONFIGS = {
|
|
2622
|
+
baseURL: void 0,
|
|
2623
|
+
fexiosConfigs: {
|
|
2624
|
+
responseType: "json"
|
|
2625
|
+
},
|
|
2626
|
+
defaultParams: J.INIT_DEFAULT_PARAMS,
|
|
2627
|
+
throwOnApiError: !1
|
|
2628
|
+
}, J.createRequestHandler = Ue;
|
|
2629
|
+
let Ne = J;
|
|
2630
|
+
class Dt extends Ne {
|
|
2631
|
+
async clientLogin(t, r, n) {
|
|
2632
|
+
n ||= {}, !n.logincontinue && !n.loginreturnurl && (n.loginreturnurl = location?.origin);
|
|
2633
|
+
const s = await this.postWithToken(
|
|
2634
|
+
"login",
|
|
2635
|
+
{
|
|
2636
|
+
action: "clientlogin",
|
|
2637
|
+
username: t,
|
|
2638
|
+
password: r,
|
|
2639
|
+
...n
|
|
2640
|
+
},
|
|
2641
|
+
{
|
|
2642
|
+
tokenName: "logintoken"
|
|
2643
|
+
}
|
|
2644
|
+
);
|
|
2645
|
+
if (s?.data?.clientlogin?.status === "PASS")
|
|
2646
|
+
return s.data.clientlogin;
|
|
2647
|
+
throw new D(
|
|
2648
|
+
Q.LOGIN_FAILED,
|
|
2649
|
+
s.data.clientlogin.message,
|
|
2650
|
+
s
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
const Ct = (e, t = document) => t.querySelector(e), It = (e, t = document) => t.querySelectorAll(e), Be = (e) => typeof e == "function";
|
|
2655
|
+
async function Ut(e) {
|
|
2656
|
+
return Be(e) ? await e() : e;
|
|
2657
|
+
}
|
|
2658
|
+
function Nt(e) {
|
|
2659
|
+
return Be(e) ? e() : e;
|
|
2660
|
+
}
|
|
2661
|
+
var Lt = /* @__PURE__ */ ((e) => (e.ANALYTICS_API_BASE = "https://analytics.ipe.wiki/api/v6", e.ANALYTICS_DASH_URL = "https://analytics.ipe.wiki", e.GITHUB_URL = "https://github.com/inpageedit/inpageedit-next", e.GITHUB_OWNER = "inpageedit", e.GITHUB_REPO = "inpageedit-next", e.HOME_URL = "https://www.ipe.wiki/", e.UPDATE_LOGS_URL = "https://www.ipe.wiki/changelogs/", e.PLUGIN_REGISTRY_URL = "https://registry.ipe.wiki/registry.v1.json", e.I18N_INDEX_URL = "https://registry.ipe.wiki/i18n/index.json", e.QQ_GROUP_ID = "1026023666", e))(Lt || {});
|
|
2662
|
+
function qe(e) {
|
|
2663
|
+
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
2664
|
+
}
|
|
2665
|
+
function Bt(e) {
|
|
2666
|
+
return qe(e).replace(/_/g, "-").replace(/.[A-Z]+/g, (t) => t[0] + "-" + t.slice(1).toLowerCase());
|
|
2667
|
+
}
|
|
2668
|
+
function qt(e) {
|
|
2669
|
+
return qe(e).replace(/-/g, "_").replace(/.[A-Z]+/g, (t) => t[0] + "_" + t.slice(1).toLowerCase());
|
|
2670
|
+
}
|
|
2671
|
+
function Mt(e) {
|
|
2672
|
+
return function(t) {
|
|
2673
|
+
return t.PreferencesSchema = e, t;
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
export {
|
|
2677
|
+
pe as C,
|
|
2678
|
+
Lt as E,
|
|
2679
|
+
ht as F,
|
|
2680
|
+
Dt as G,
|
|
2681
|
+
se as I,
|
|
2682
|
+
Se as M,
|
|
2683
|
+
Mt as R,
|
|
2684
|
+
Pt as S,
|
|
2685
|
+
H as T,
|
|
2686
|
+
re as U,
|
|
2687
|
+
$e as a,
|
|
2688
|
+
lt as b,
|
|
2689
|
+
Tt as c,
|
|
2690
|
+
He as d,
|
|
2691
|
+
ut as e,
|
|
2692
|
+
qt as f,
|
|
2693
|
+
Nt as g,
|
|
2694
|
+
It as h,
|
|
2695
|
+
Ut as i,
|
|
2696
|
+
I as j,
|
|
2697
|
+
Bt as p,
|
|
2698
|
+
Ct as q,
|
|
2699
|
+
m as s
|
|
2700
|
+
};
|
|
2701
|
+
//# sourceMappingURL=Preferences-C10tZMl1.js.map
|