@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
package/dist/index-BgkZW91u.js
DELETED
|
@@ -1,4245 +0,0 @@
|
|
|
1
|
-
import { useMemoryStorage as $t, createWikiPageModel as Rt, createWikiTitleModel as xt } from "./models/index.js";
|
|
2
|
-
import { c as I, I as ne, S as m, d as je, h as Lt, p as H, R as At, E as qe, i as Tt } from "./Preferences-BF2fcXrn.js";
|
|
3
|
-
import { j as k, P as Ct } from "./index-CM_6yF2v.js";
|
|
4
|
-
var Fe = /* @__PURE__ */ ((r) => (r[r.debug = -1] = "debug", r[r.log = 0] = "log", r[r.info = 1] = "info", r[r.warn = 2] = "warn", r[r.error = 3] = "error", r[r.silent = 4] = "silent", r))(Fe || {});
|
|
5
|
-
const he = globalThis || window, ue = Symbol.for("__IPE_LOGGER_COLOR_MAP__");
|
|
6
|
-
he[ue] || (he[ue] = /* @__PURE__ */ new Map());
|
|
7
|
-
const le = he[ue];
|
|
8
|
-
function Y(r) {
|
|
9
|
-
let e = 2166136261;
|
|
10
|
-
for (let t = 0; t < r.length; t++)
|
|
11
|
-
e ^= r.charCodeAt(t), e = (e >>> 0) * 16777619;
|
|
12
|
-
return e >>> 0;
|
|
13
|
-
}
|
|
14
|
-
const Ae = [
|
|
15
|
-
[350, 360],
|
|
16
|
-
[0, 15],
|
|
17
|
-
[15, 30],
|
|
18
|
-
[200, 230],
|
|
19
|
-
[230, 250],
|
|
20
|
-
[250, 280],
|
|
21
|
-
[280, 310],
|
|
22
|
-
[310, 330],
|
|
23
|
-
[140, 160],
|
|
24
|
-
[160, 180]
|
|
25
|
-
];
|
|
26
|
-
function Ot(r, e) {
|
|
27
|
-
const t = Ae.length, i = Y(r) % t, [s, n] = Ae[i], o = n - s, a = Y(r + ":" + e), c = s + a % (o || 1), l = Y(r + ":s"), h = Y(r + ":l");
|
|
28
|
-
let d, u;
|
|
29
|
-
if (e === "name")
|
|
30
|
-
d = 62 + l % 18, u = 30 + h % 12;
|
|
31
|
-
else {
|
|
32
|
-
const f = c >= 0 && c < 50 || c > 330 && c < 360, g = c >= 200 && c <= 300;
|
|
33
|
-
d = 55 + l % 20, g ? u = 55 + h % 8 : f ? u = 48 + h % 6 : u = 50 + h % 8, d < 60 && (d += 5);
|
|
34
|
-
}
|
|
35
|
-
return `hsl(${c}, ${d}%, ${u}%)`;
|
|
36
|
-
}
|
|
37
|
-
function X(r, e) {
|
|
38
|
-
if (e)
|
|
39
|
-
return le.set(r, e), e;
|
|
40
|
-
const t = le.get(r);
|
|
41
|
-
if (t) return t;
|
|
42
|
-
const i = r.startsWith("name:") ? "name" : "group", s = Ot(r, i);
|
|
43
|
-
return le.set(r, s), s;
|
|
44
|
-
}
|
|
45
|
-
let It = class He {
|
|
46
|
-
/**
|
|
47
|
-
* Note: constructor returns a callable Proxy so that you can do `logger('group')`.
|
|
48
|
-
*/
|
|
49
|
-
constructor(e = {}) {
|
|
50
|
-
this._custom = (t) => {
|
|
51
|
-
if (!this._enabled(t.level)) return Te;
|
|
52
|
-
const [i, s] = this._prefix(t.label);
|
|
53
|
-
return this._consoleMethod(t.method).bind(console, i, ...s);
|
|
54
|
-
}, this._name = e.name, this._nameColor = e.color, this._groupPath = e._groupPath ? [...e._groupPath] : [], this._dynamicLevels = { ...e._dynamicLevels }, this._levelRef = e._levelRef ?? {
|
|
55
|
-
value: e.level ?? 1
|
|
56
|
-
/* info */
|
|
57
|
-
}, this._name && X(`name:${this._name}`, this._nameColor), this._installBuiltinLevels();
|
|
58
|
-
for (const t of Object.keys(this._dynamicLevels))
|
|
59
|
-
this._installLevelGetter(t, this._dynamicLevels[t]);
|
|
60
|
-
return Dt(this);
|
|
61
|
-
}
|
|
62
|
-
// ---------- public API ----------
|
|
63
|
-
get level() {
|
|
64
|
-
return this._levelRef.value;
|
|
65
|
-
}
|
|
66
|
-
set level(e) {
|
|
67
|
-
this._levelRef.value = e;
|
|
68
|
-
}
|
|
69
|
-
/** Create a sub-logger with a group label */
|
|
70
|
-
group(e, t) {
|
|
71
|
-
return e && X(`group:${e}`, t?.color), new He({
|
|
72
|
-
name: this._name,
|
|
73
|
-
color: this._nameColor,
|
|
74
|
-
_groupPath: [...this._groupPath, e],
|
|
75
|
-
_dynamicLevels: this._dynamicLevels,
|
|
76
|
-
_levelRef: this._levelRef
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/** Define a custom level, e.g. logger.defineLevel('success', { level: info, label: '✅', method: 'info' }) */
|
|
80
|
-
defineLevel(e, t) {
|
|
81
|
-
this._dynamicLevels[e] = { ...t }, this._installLevelGetter(e, t);
|
|
82
|
-
}
|
|
83
|
-
// Built-in level getters
|
|
84
|
-
get debug() {
|
|
85
|
-
return this._method("debug");
|
|
86
|
-
}
|
|
87
|
-
get log() {
|
|
88
|
-
return this._method("log");
|
|
89
|
-
}
|
|
90
|
-
get info() {
|
|
91
|
-
return this._method("info");
|
|
92
|
-
}
|
|
93
|
-
get warn() {
|
|
94
|
-
return this._method("warn");
|
|
95
|
-
}
|
|
96
|
-
get error() {
|
|
97
|
-
return this._method("error");
|
|
98
|
-
}
|
|
99
|
-
// ---------- internals ----------
|
|
100
|
-
_installBuiltinLevels() {
|
|
101
|
-
}
|
|
102
|
-
_installLevelGetter(e, t) {
|
|
103
|
-
Object.defineProperty(this, e, {
|
|
104
|
-
configurable: !0,
|
|
105
|
-
enumerable: !1,
|
|
106
|
-
get: () => this._custom(t)
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
_method(e) {
|
|
110
|
-
const t = Pt[e];
|
|
111
|
-
if (!this._enabled(t.level)) return Te;
|
|
112
|
-
const [i, s] = this._prefix(t.label);
|
|
113
|
-
return this._consoleMethod(e).bind(console, i, ...s);
|
|
114
|
-
}
|
|
115
|
-
_consoleMethod(e) {
|
|
116
|
-
return (console[e] || console.log).bind(console);
|
|
117
|
-
}
|
|
118
|
-
_enabled(e) {
|
|
119
|
-
return e >= this._levelRef.value && this._levelRef.value !== 4;
|
|
120
|
-
}
|
|
121
|
-
_prefix(e) {
|
|
122
|
-
const t = [];
|
|
123
|
-
let i = "";
|
|
124
|
-
if (this._name) {
|
|
125
|
-
const s = X(`name:${this._name}`, this._nameColor);
|
|
126
|
-
i += `%c${this._name}%c`, t.push(
|
|
127
|
-
`background:${s}; color:#fff; padding:1px 4px; border-radius:2px; font-weight:700;`,
|
|
128
|
-
Ce
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
if (e && (i += ` ${e}`), this._groupPath.length) {
|
|
132
|
-
const s = this._groupPath.join("/"), n = X(`group:${s}`);
|
|
133
|
-
i += ` %c${s}%c`, t.push(`color:${n}; text-decoration: underline;`, Ce);
|
|
134
|
-
}
|
|
135
|
-
return [i, t];
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const Te = () => {
|
|
139
|
-
}, Ce = "color:inherit; background:transparent; text-decoration:none;", Pt = {
|
|
140
|
-
debug: { level: -1, label: "", method: "debug" },
|
|
141
|
-
log: { level: 0, label: "", method: "log" },
|
|
142
|
-
info: { level: 1, label: "[I]", method: "info" },
|
|
143
|
-
warn: { level: 2, label: "[W]", method: "warn" },
|
|
144
|
-
error: { level: 3, label: "[E]", method: "error" }
|
|
145
|
-
};
|
|
146
|
-
function Dt(r) {
|
|
147
|
-
const e = function(t, i) {
|
|
148
|
-
return r.group(t, i);
|
|
149
|
-
};
|
|
150
|
-
return new Proxy(e, {
|
|
151
|
-
get(t, i, s) {
|
|
152
|
-
return r[i];
|
|
153
|
-
},
|
|
154
|
-
set(t, i, s) {
|
|
155
|
-
return r[i] = s, !0;
|
|
156
|
-
},
|
|
157
|
-
apply(t, i, s) {
|
|
158
|
-
return r.group(s[0], s[1]);
|
|
159
|
-
},
|
|
160
|
-
has(t, i) {
|
|
161
|
-
return i in r;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
function Mt(r) {
|
|
166
|
-
return new It(r);
|
|
167
|
-
}
|
|
168
|
-
var x = /* @__PURE__ */ ((r) => (r.BODY_USED = "BODY_USED", r.NO_BODY_READER = "NO_BODY_READER", r.TIMEOUT = "TIMEOUT", r.NETWORK_ERROR = "NETWORK_ERROR", r.BODY_NOT_ALLOWED = "BODY_NOT_ALLOWED", r.HOOK_CONTEXT_CHANGED = "HOOK_CONTEXT_CHANGED", r.ABORTED_BY_HOOK = "ABORTED_BY_HOOK", r.INVALID_HOOK_CALLBACK = "INVALID_HOOK_CALLBACK", r.UNEXPECTED_HOOK_RETURN = "UNEXPECTED_HOOK_RETURN", r))(x || {});
|
|
169
|
-
let $ = class Ke extends Error {
|
|
170
|
-
constructor(e, t, i, s) {
|
|
171
|
-
super(t, s), this.code = e, this.context = i;
|
|
172
|
-
}
|
|
173
|
-
name = "FexiosError";
|
|
174
|
-
static is(e) {
|
|
175
|
-
return e?.constructor === Ke;
|
|
176
|
-
}
|
|
177
|
-
}, Ut = class We extends $ {
|
|
178
|
-
constructor(e, t, i) {
|
|
179
|
-
super(t.statusText, e, void 0, i), this.response = t;
|
|
180
|
-
}
|
|
181
|
-
name = "FexiosResponseError";
|
|
182
|
-
static is(e) {
|
|
183
|
-
return e?.constructor === We;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
function Bt(r, e = 2048) {
|
|
187
|
-
if (!(r instanceof Uint8Array))
|
|
188
|
-
throw new TypeError("Input must be a Uint8Array");
|
|
189
|
-
if (r.length === 0)
|
|
190
|
-
return !0;
|
|
191
|
-
const t = Math.min(
|
|
192
|
-
Math.max(r.length, 256),
|
|
193
|
-
e
|
|
194
|
-
), i = r.slice(0, t);
|
|
195
|
-
if (Nt(i))
|
|
196
|
-
return !1;
|
|
197
|
-
const s = jt(i);
|
|
198
|
-
if (s.nullByteRatio > 0.05 || s.highByteRatio > 0.95)
|
|
199
|
-
return !1;
|
|
200
|
-
const n = ["utf-8", "utf-16le", "utf-16be", "iso-8859-1"];
|
|
201
|
-
let o = -1, a = !1;
|
|
202
|
-
for (const c of n)
|
|
203
|
-
try {
|
|
204
|
-
const l = new TextDecoder(c, { fatal: !0 }).decode(i), h = qt(l);
|
|
205
|
-
h > o && (o = h, a = h > 0.7);
|
|
206
|
-
} catch {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
return a;
|
|
210
|
-
}
|
|
211
|
-
function Nt(r) {
|
|
212
|
-
if (r.length < 4) return !1;
|
|
213
|
-
const e = [
|
|
214
|
-
[137, 80, 78, 71],
|
|
215
|
-
// PNG
|
|
216
|
-
[255, 216, 255],
|
|
217
|
-
// JPEG
|
|
218
|
-
[71, 73, 70],
|
|
219
|
-
// GIF
|
|
220
|
-
[37, 80, 68, 70],
|
|
221
|
-
// PDF
|
|
222
|
-
[80, 75, 3, 4],
|
|
223
|
-
// ZIP/Office documents
|
|
224
|
-
[80, 75, 5, 6],
|
|
225
|
-
// ZIP empty archive
|
|
226
|
-
[80, 75, 7, 8],
|
|
227
|
-
// ZIP spanned archive
|
|
228
|
-
[127, 69, 76, 70],
|
|
229
|
-
// ELF executable
|
|
230
|
-
[77, 90],
|
|
231
|
-
// Windows executable
|
|
232
|
-
[202, 254, 186, 190],
|
|
233
|
-
// Java class file
|
|
234
|
-
[0, 0, 1, 0],
|
|
235
|
-
// ICO
|
|
236
|
-
[82, 73, 70, 70]
|
|
237
|
-
// RIFF (AVI, WAV, etc.)
|
|
238
|
-
];
|
|
239
|
-
for (const t of e)
|
|
240
|
-
if (r.length >= t.length) {
|
|
241
|
-
let i = !0;
|
|
242
|
-
for (let s = 0; s < t.length; s++)
|
|
243
|
-
if (r[s] !== t[s]) {
|
|
244
|
-
i = !1;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
if (i) return !0;
|
|
248
|
-
}
|
|
249
|
-
return !1;
|
|
250
|
-
}
|
|
251
|
-
function jt(r) {
|
|
252
|
-
let e = 0, t = 0, i = 0;
|
|
253
|
-
for (const s of r)
|
|
254
|
-
s === 0 && e++, s > 127 && t++, (s < 32 && s !== 9 && s !== 10 && s !== 13 || s === 127) && i++;
|
|
255
|
-
return {
|
|
256
|
-
nullByteRatio: e / r.length,
|
|
257
|
-
highByteRatio: t / r.length,
|
|
258
|
-
controlCharRatio: i / r.length
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function qt(r) {
|
|
262
|
-
if (r.length === 0) return 1;
|
|
263
|
-
let e = 1, t = 0;
|
|
264
|
-
for (let s = 0; s < r.length; s++) {
|
|
265
|
-
const n = r[s].charCodeAt(0);
|
|
266
|
-
n >= 32 && n <= 126 || n === 9 || n === 10 || n === 13 || n === 32 ? t++ : n > 127 && n < 65534 ? !Ft(n) && !Ht(n) && t++ : e -= 0.1;
|
|
267
|
-
}
|
|
268
|
-
const i = t / r.length;
|
|
269
|
-
return e *= i, Kt(r) && (e *= 1.1), Math.max(0, Math.min(1, e));
|
|
270
|
-
}
|
|
271
|
-
function Ft(r) {
|
|
272
|
-
return r >= 0 && r <= 31 || r >= 127 && r <= 159;
|
|
273
|
-
}
|
|
274
|
-
function Ht(r) {
|
|
275
|
-
return r >= 57344 && r <= 63743 || r >= 983040 && r <= 1048573 || r >= 1048576 && r <= 1114109;
|
|
276
|
-
}
|
|
277
|
-
function Kt(r) {
|
|
278
|
-
return [
|
|
279
|
-
/\b\w+\b/,
|
|
280
|
-
// Words
|
|
281
|
-
/[.!?]+\s/,
|
|
282
|
-
// Sentence endings
|
|
283
|
-
/\s+/,
|
|
284
|
-
// Whitespace
|
|
285
|
-
/[a-zA-Z]{3,}/,
|
|
286
|
-
// English words
|
|
287
|
-
/[\u4e00-\u9fa5]+/,
|
|
288
|
-
// Chinese characters
|
|
289
|
-
/\d+/
|
|
290
|
-
// Numbers
|
|
291
|
-
].some((e) => e.test(r));
|
|
292
|
-
}
|
|
293
|
-
function A(r) {
|
|
294
|
-
if (typeof r != "object" || r === null || Object.prototype.toString.call(r) !== "[object Object]")
|
|
295
|
-
return !1;
|
|
296
|
-
const e = Object.getPrototypeOf(r);
|
|
297
|
-
return e === Object.prototype || e === null;
|
|
298
|
-
}
|
|
299
|
-
const K = (r, ...e) => {
|
|
300
|
-
const t = (s) => {
|
|
301
|
-
if (Array.isArray(s)) return s.slice();
|
|
302
|
-
if (A(s)) {
|
|
303
|
-
const n = {};
|
|
304
|
-
for (const o of Reflect.ownKeys(s)) n[o] = t(s[o]);
|
|
305
|
-
return n;
|
|
306
|
-
}
|
|
307
|
-
return s;
|
|
308
|
-
}, i = t(r);
|
|
309
|
-
for (const s of e)
|
|
310
|
-
if (s != null)
|
|
311
|
-
for (const n of Reflect.ownKeys(s)) {
|
|
312
|
-
const o = s[n];
|
|
313
|
-
if (typeof o > "u") continue;
|
|
314
|
-
const a = i[n];
|
|
315
|
-
A(a) && A(o) ? i[n] = K(a, o) : i[n] = t(o);
|
|
316
|
-
}
|
|
317
|
-
return i;
|
|
318
|
-
};
|
|
319
|
-
let q = class {
|
|
320
|
-
constructor(e, t, i) {
|
|
321
|
-
this.rawResponse = e, this.data = t, this.ok = e.ok, this.status = e.status, this.statusText = e.statusText, this.headers = e.headers, Object.entries(i || {}).forEach(([s, n]) => {
|
|
322
|
-
this[s] = n;
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
ok;
|
|
326
|
-
status;
|
|
327
|
-
statusText;
|
|
328
|
-
headers;
|
|
329
|
-
};
|
|
330
|
-
async function Oe(r, e, t) {
|
|
331
|
-
if (r.bodyUsed)
|
|
332
|
-
throw new $(
|
|
333
|
-
x.BODY_USED,
|
|
334
|
-
"Response body has already been used or locked"
|
|
335
|
-
);
|
|
336
|
-
const i = r.headers.get("content-type") || "", s = Number(r.headers.get("content-length")) || 0, n = (a, c) => c === "json" || a.startsWith("application/json"), o = (a, c, l) => l === "blob" || a.startsWith("image/") && !a.startsWith("image/svg") || a.startsWith("video/") || a.startsWith("audio/") || !Bt(c);
|
|
337
|
-
if ((r.status === 101 || r.status === 426 || r.headers.get("upgrade")) && typeof globalThis.WebSocket < "u") {
|
|
338
|
-
const a = new WebSocket(r.url);
|
|
339
|
-
return await new Promise((c, l) => {
|
|
340
|
-
a.onopen = c, a.onerror = l;
|
|
341
|
-
}), new q(r, a, {
|
|
342
|
-
ok: !0,
|
|
343
|
-
status: 101,
|
|
344
|
-
statusText: "Switching Protocols"
|
|
345
|
-
});
|
|
346
|
-
} else if (i.startsWith("text/event-stream") && !["text", "json"].includes(e || "") && typeof globalThis.EventSource < "u") {
|
|
347
|
-
const a = new EventSource(r.url);
|
|
348
|
-
return await new Promise((c, l) => {
|
|
349
|
-
a.onopen = c, a.onerror = l;
|
|
350
|
-
}), new q(r, a);
|
|
351
|
-
} else {
|
|
352
|
-
if (e === "stream")
|
|
353
|
-
return new q(
|
|
354
|
-
r,
|
|
355
|
-
r.body
|
|
356
|
-
);
|
|
357
|
-
{
|
|
358
|
-
const a = r.clone().body?.getReader();
|
|
359
|
-
if (!a)
|
|
360
|
-
throw new $(
|
|
361
|
-
x.NO_BODY_READER,
|
|
362
|
-
"Failed to get ReadableStream from response body"
|
|
363
|
-
);
|
|
364
|
-
let c = new Uint8Array();
|
|
365
|
-
for (; ; ) {
|
|
366
|
-
const { done: h, value: d } = await a.read();
|
|
367
|
-
if (h) break;
|
|
368
|
-
if (d && (c = new Uint8Array([...c, ...d]), t && s > 0)) {
|
|
369
|
-
const u = Math.min(c.length / s, 1);
|
|
370
|
-
t(u, c);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const l = new q(r, void 0);
|
|
374
|
-
if (e === "arrayBuffer")
|
|
375
|
-
return l.data = c.buffer, l;
|
|
376
|
-
if (n(i, e))
|
|
377
|
-
try {
|
|
378
|
-
const h = new TextDecoder().decode(c);
|
|
379
|
-
l.data = JSON.parse(h);
|
|
380
|
-
} catch {
|
|
381
|
-
}
|
|
382
|
-
if (typeof l.data != "string" && o(i, c, e) ? l.data = new Blob([c], {
|
|
383
|
-
type: r.headers.get("content-type") || void 0
|
|
384
|
-
}) : l.data = new TextDecoder().decode(c), typeof l.data == "string" && e !== "text") {
|
|
385
|
-
const h = l.data.trim(), d = h[0], u = h[h.length - 1];
|
|
386
|
-
if (d === "{" && u === "}" || d === "[" && u === "]")
|
|
387
|
-
try {
|
|
388
|
-
l.data = JSON.parse(l.data);
|
|
389
|
-
} catch {
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
if (typeof l.data > "u" && (l.data = c.length > 0 ? c : void 0), l.ok)
|
|
393
|
-
return l;
|
|
394
|
-
throw new Ut(
|
|
395
|
-
`Request failed with status code ${r.status}`,
|
|
396
|
-
l
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
var V;
|
|
402
|
-
((r) => {
|
|
403
|
-
r.makeSearchParams = (s) => {
|
|
404
|
-
if (!s)
|
|
405
|
-
return new URLSearchParams();
|
|
406
|
-
if (s instanceof URLSearchParams)
|
|
407
|
-
return s;
|
|
408
|
-
if (typeof s != "object" || s?.constructor !== Object)
|
|
409
|
-
throw new TypeError("only plain object is supported");
|
|
410
|
-
const n = new URLSearchParams(), o = (l, h) => {
|
|
411
|
-
h != null && n.append(l, h);
|
|
412
|
-
}, a = (l, h) => {
|
|
413
|
-
h != null && n.set(l, h);
|
|
414
|
-
}, c = (l, h) => {
|
|
415
|
-
if (h != null) {
|
|
416
|
-
if (Array.isArray(h)) {
|
|
417
|
-
for (const d of h) o(l, d?.toString());
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
if (typeof h == "object" && h.constructor === Object) {
|
|
421
|
-
for (const [d, u] of Object.entries(h)) {
|
|
422
|
-
if (u == null) continue;
|
|
423
|
-
const f = d.endsWith("[]"), g = f ? d.slice(0, -2) : d, p = `${l}[${g}]`;
|
|
424
|
-
if (f) {
|
|
425
|
-
const y = `${p}[]`;
|
|
426
|
-
if (Array.isArray(u))
|
|
427
|
-
for (const L of u) o(y, L?.toString());
|
|
428
|
-
else typeof u == "object" && u !== null && u.constructor === Object ? c(`${p}[]`, u) : o(y, u?.toString());
|
|
429
|
-
} else if (Array.isArray(u))
|
|
430
|
-
for (const y of u) o(p, y?.toString());
|
|
431
|
-
else typeof u == "object" && u !== null && u.constructor === Object ? c(p, u) : a(p, u?.toString());
|
|
432
|
-
}
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
a(l, h?.toString());
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
for (const [l, h] of Object.entries(s))
|
|
439
|
-
c(l, h);
|
|
440
|
-
return n;
|
|
441
|
-
}, r.makeQueryString = (s) => (0, r.makeSearchParams)(s).toString(), r.makeURL = (s, n, o, a) => {
|
|
442
|
-
const c = typeof window < "u" && window.location?.origin || "http://localhost", l = typeof s == "string" ? new URL(s, a ?? c) : new URL(s), h = (0, r.toQueryRecord)(l.searchParams), d = (0, r.mergeQueries)(h, n || {}), u = (0, r.makeSearchParams)(d);
|
|
443
|
-
return l.search = u.toString(), l.hash = o || "", l;
|
|
444
|
-
}, r.toQueryRecord = (s) => {
|
|
445
|
-
typeof s == "string" && (s = (0, r.fromString)(s));
|
|
446
|
-
const n = {}, o = (c) => {
|
|
447
|
-
if (!c.includes("[")) return { path: [c], forceArray: !1 };
|
|
448
|
-
const l = [c.slice(0, c.indexOf("["))], h = /\[([^\]]*)\]/g;
|
|
449
|
-
let d, u = !1, f = !1;
|
|
450
|
-
for (; d = h.exec(c); )
|
|
451
|
-
d[1] === "" ? (u = !0, f = !0) : (l.push(d[1]), f = !1);
|
|
452
|
-
return u && f && (l[l.length - 1] = l[l.length - 1] + "[]"), { path: l, forceArray: u };
|
|
453
|
-
}, a = (c, l, h, d) => {
|
|
454
|
-
let u = c;
|
|
455
|
-
for (let f = 0; f < l.length; f++) {
|
|
456
|
-
const g = l[f];
|
|
457
|
-
f === l.length - 1 ? d ? u[g] === void 0 ? u[g] = [h] : Array.isArray(u[g]) ? u[g].push(h) : u[g] = [u[g], h] : u[g] === void 0 ? u[g] = h : Array.isArray(u[g]) ? u[g].push(h) : u[g] = [u[g], h] : ((u[g] === void 0 || typeof u[g] != "object" || Array.isArray(u[g])) && (u[g] = {}), u = u[g]);
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
for (const [c, l] of s.entries()) {
|
|
461
|
-
const { path: h, forceArray: d } = o(String(c));
|
|
462
|
-
a(n, h, l?.toString(), d);
|
|
463
|
-
}
|
|
464
|
-
return n;
|
|
465
|
-
}, r.fromString = (s) => {
|
|
466
|
-
const n = s.trim();
|
|
467
|
-
if (!n) return new URLSearchParams();
|
|
468
|
-
if (n.startsWith("?")) return new URLSearchParams(n.slice(1));
|
|
469
|
-
const o = n.indexOf("?");
|
|
470
|
-
if (o >= 0) {
|
|
471
|
-
const a = n.indexOf("#", o + 1), c = n.slice(o + 1, a >= 0 ? a : void 0);
|
|
472
|
-
return new URLSearchParams(c);
|
|
473
|
-
}
|
|
474
|
-
return new URLSearchParams(n);
|
|
475
|
-
}, r.mergeQueries = (s, ...n) => {
|
|
476
|
-
const o = e(t(s));
|
|
477
|
-
for (const a of n)
|
|
478
|
-
a != null && i(o, t(a));
|
|
479
|
-
return o;
|
|
480
|
-
};
|
|
481
|
-
function e(s) {
|
|
482
|
-
if (Array.isArray(s)) return s.map(e);
|
|
483
|
-
if (A(s)) {
|
|
484
|
-
const n = {};
|
|
485
|
-
for (const [o, a] of Object.entries(s)) n[o] = e(a);
|
|
486
|
-
return n;
|
|
487
|
-
}
|
|
488
|
-
if (s instanceof Map) {
|
|
489
|
-
const n = {};
|
|
490
|
-
for (const [o, a] of s.entries()) n[o] = e(a);
|
|
491
|
-
return n;
|
|
492
|
-
}
|
|
493
|
-
return s;
|
|
494
|
-
}
|
|
495
|
-
function t(s) {
|
|
496
|
-
if (!s) return {};
|
|
497
|
-
if (s instanceof URLSearchParams || s instanceof FormData || s instanceof Map)
|
|
498
|
-
return (0, r.toQueryRecord)(s);
|
|
499
|
-
if (typeof s == "string") return (0, r.toQueryRecord)((0, r.fromString)(s));
|
|
500
|
-
if (A(s)) return s;
|
|
501
|
-
throw new TypeError(
|
|
502
|
-
`unsupported type transformation, got: ${Object.prototype.toString.call(
|
|
503
|
-
s
|
|
504
|
-
)}`
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
function i(s, n) {
|
|
508
|
-
for (const [o, a] of Object.entries(n)) {
|
|
509
|
-
if (a === void 0) continue;
|
|
510
|
-
if (a === null) {
|
|
511
|
-
delete s[o];
|
|
512
|
-
continue;
|
|
513
|
-
}
|
|
514
|
-
const c = s[o];
|
|
515
|
-
A(c) && A(a) ? i(c, a) : s[o] = e(a);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
})(V || (V = {}));
|
|
519
|
-
const ze = function(r) {
|
|
520
|
-
const e = this.constructor.prototype, t = Reflect.get(e, r, e);
|
|
521
|
-
function i(...s) {
|
|
522
|
-
return Reflect.apply(t, i, s);
|
|
523
|
-
}
|
|
524
|
-
Reflect.setPrototypeOf(i, e);
|
|
525
|
-
for (const s of Reflect.ownKeys(t)) {
|
|
526
|
-
const n = Reflect.getOwnPropertyDescriptor(t, s);
|
|
527
|
-
n && Reflect.defineProperty(i, s, n);
|
|
528
|
-
}
|
|
529
|
-
return i;
|
|
530
|
-
};
|
|
531
|
-
ze.prototype = Object.create(Function.prototype);
|
|
532
|
-
var W;
|
|
533
|
-
((r) => {
|
|
534
|
-
r.makeHeaders = (e) => {
|
|
535
|
-
if (!e) return new Headers();
|
|
536
|
-
if (e instanceof Headers) return new Headers(e);
|
|
537
|
-
const t = new Headers();
|
|
538
|
-
if (e instanceof Map) {
|
|
539
|
-
for (const [i, s] of e.entries())
|
|
540
|
-
if (s != null)
|
|
541
|
-
if (Array.isArray(s))
|
|
542
|
-
for (const n of s)
|
|
543
|
-
n != null && t.append(i, String(n));
|
|
544
|
-
else
|
|
545
|
-
t.append(i, String(s));
|
|
546
|
-
return t;
|
|
547
|
-
}
|
|
548
|
-
if (A(e)) {
|
|
549
|
-
for (const [i, s] of Object.entries(e))
|
|
550
|
-
if (s != null)
|
|
551
|
-
if (Array.isArray(s))
|
|
552
|
-
for (const n of s)
|
|
553
|
-
n != null && t.append(i, String(n));
|
|
554
|
-
else
|
|
555
|
-
t.append(i, String(s));
|
|
556
|
-
return t;
|
|
557
|
-
}
|
|
558
|
-
throw new TypeError(
|
|
559
|
-
"only plain object, Map/ReadonlyMap, or Headers is supported"
|
|
560
|
-
);
|
|
561
|
-
}, r.toHeaderRecord = (e) => {
|
|
562
|
-
if (e instanceof Headers) {
|
|
563
|
-
const t = {};
|
|
564
|
-
return e.forEach((i, s) => {
|
|
565
|
-
t[s] = t[s] ? [...t[s], i] : [i];
|
|
566
|
-
}), t;
|
|
567
|
-
}
|
|
568
|
-
if (e instanceof Map) {
|
|
569
|
-
const t = {};
|
|
570
|
-
for (const [i, s] of e.entries())
|
|
571
|
-
if (s != null)
|
|
572
|
-
if (Array.isArray(s)) {
|
|
573
|
-
const n = s.filter((o) => o != null).map((o) => String(o));
|
|
574
|
-
n.length && (t[i] = (t[i] ?? []).concat(n));
|
|
575
|
-
} else {
|
|
576
|
-
const n = String(s);
|
|
577
|
-
t[i] = t[i] ? [...t[i], n] : [n];
|
|
578
|
-
}
|
|
579
|
-
return t;
|
|
580
|
-
}
|
|
581
|
-
throw new TypeError(
|
|
582
|
-
`unsupported type transformation, got: ${Object.prototype.toString.call(
|
|
583
|
-
e
|
|
584
|
-
)}`
|
|
585
|
-
);
|
|
586
|
-
}, r.mergeHeaders = (e, ...t) => {
|
|
587
|
-
const i = e instanceof Headers ? new Headers(e) : (0, r.makeHeaders)(e), s = (n) => {
|
|
588
|
-
for (const [o, a] of Object.entries(n))
|
|
589
|
-
if (a !== void 0) {
|
|
590
|
-
if (a === null) {
|
|
591
|
-
i.delete(o);
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
if (Array.isArray(a)) {
|
|
595
|
-
i.delete(o);
|
|
596
|
-
for (const c of a)
|
|
597
|
-
c != null && i.append(o, String(c));
|
|
598
|
-
} else
|
|
599
|
-
i.set(o, String(a));
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
for (const n of t) {
|
|
603
|
-
if (n == null) continue;
|
|
604
|
-
if (n instanceof Headers) {
|
|
605
|
-
n.forEach((a, c) => {
|
|
606
|
-
i.set(c, a);
|
|
607
|
-
});
|
|
608
|
-
continue;
|
|
609
|
-
}
|
|
610
|
-
if (A(n)) {
|
|
611
|
-
s(n);
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
const o = (0, r.toHeaderRecord)(n);
|
|
615
|
-
for (const [a, c] of Object.entries(o)) {
|
|
616
|
-
i.delete(a);
|
|
617
|
-
for (const l of c) i.append(a, l);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
return i;
|
|
621
|
-
};
|
|
622
|
-
})(W || (W = {}));
|
|
623
|
-
let de = class _ extends ze {
|
|
624
|
-
static FINAL_SYMBOL = Symbol("FEXIOS_FINAL_CONTEXT");
|
|
625
|
-
static NORMALIZED_SYMBOL = Symbol("FEXIOS_NORMALIZED_QUERY");
|
|
626
|
-
baseConfigs;
|
|
627
|
-
static DEFAULT_CONFIGS = {
|
|
628
|
-
baseURL: "",
|
|
629
|
-
timeout: 60 * 1e3,
|
|
630
|
-
credentials: "same-origin",
|
|
631
|
-
headers: {},
|
|
632
|
-
query: {},
|
|
633
|
-
responseType: void 0,
|
|
634
|
-
fetch: globalThis.fetch
|
|
635
|
-
};
|
|
636
|
-
hooks = [];
|
|
637
|
-
static ALL_METHODS = [
|
|
638
|
-
"get",
|
|
639
|
-
"post",
|
|
640
|
-
"put",
|
|
641
|
-
"patch",
|
|
642
|
-
"delete",
|
|
643
|
-
"head",
|
|
644
|
-
"options",
|
|
645
|
-
"trace"
|
|
646
|
-
];
|
|
647
|
-
static METHODS_WITHOUT_BODY = [
|
|
648
|
-
"get",
|
|
649
|
-
"head",
|
|
650
|
-
"options",
|
|
651
|
-
"trace"
|
|
652
|
-
];
|
|
653
|
-
constructor(e = {}) {
|
|
654
|
-
super("request"), this.baseConfigs = K(_.DEFAULT_CONFIGS, e), _.ALL_METHODS.forEach(
|
|
655
|
-
(t) => this.createMethodShortcut(t.toLowerCase())
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
async request(e, t) {
|
|
659
|
-
let i = t = t || {};
|
|
660
|
-
if (typeof e == "string" || e instanceof URL ? i.url = e.toString() : typeof e == "object" && (i = K(e, i)), i = await this.emit("beforeInit", i, {
|
|
661
|
-
shouldAdjustRequestParams: !0,
|
|
662
|
-
shouldHandleShortCircuitResponse: !0
|
|
663
|
-
}), i[_.FINAL_SYMBOL]) return i;
|
|
664
|
-
if (_.METHODS_WITHOUT_BODY.includes(
|
|
665
|
-
i.method?.toLocaleLowerCase()
|
|
666
|
-
) && i.body)
|
|
667
|
-
throw new $(
|
|
668
|
-
x.BODY_NOT_ALLOWED,
|
|
669
|
-
`Request method "${i.method}" does not allow body`
|
|
670
|
-
);
|
|
671
|
-
if (i = await this.emit("beforeRequest", i, {
|
|
672
|
-
shouldAdjustRequestParams: !0,
|
|
673
|
-
shouldHandleShortCircuitResponse: !0,
|
|
674
|
-
preAdjust: !0,
|
|
675
|
-
requestOptionsOverridesURLSearchParams: !0,
|
|
676
|
-
preRequestOptionsOverridesURLSearchParams: !0,
|
|
677
|
-
postRequestOptionsOverridesURLSearchParams: !0
|
|
678
|
-
}), i[_.FINAL_SYMBOL]) return i;
|
|
679
|
-
let s;
|
|
680
|
-
const n = {};
|
|
681
|
-
if (typeof i.body < "u" && i.body !== null && (i.body instanceof Blob || i.body instanceof FormData || i.body instanceof URLSearchParams ? s = i.body : typeof i.body == "object" && i.body !== null ? (s = JSON.stringify(i.body), i.headers = this.mergeHeaders(i.headers, {
|
|
682
|
-
"Content-Type": "application/json"
|
|
683
|
-
})) : s = i.body), !W.makeHeaders(
|
|
684
|
-
t.headers || {}
|
|
685
|
-
).get("content-type") && s && (s instanceof FormData || s instanceof URLSearchParams ? n["content-type"] = null : typeof s == "string" && typeof i.body == "object" ? n["content-type"] = "application/json" : s instanceof Blob && (n["content-type"] = s.type || "application/octet-stream")), i.body = s, i = await this.emit("afterBodyTransformed", i, {
|
|
686
|
-
shouldAdjustRequestParams: !0,
|
|
687
|
-
shouldHandleShortCircuitResponse: !0,
|
|
688
|
-
preAdjust: !0,
|
|
689
|
-
postRequestOptionsOverridesURLSearchParams: !0
|
|
690
|
-
}), i[_.FINAL_SYMBOL]) return i;
|
|
691
|
-
const o = i.abortController || globalThis.AbortController ? new AbortController() : void 0, a = i.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", c = new URL(
|
|
692
|
-
i.url.toString(),
|
|
693
|
-
a
|
|
694
|
-
), l = V.makeURL(
|
|
695
|
-
c,
|
|
696
|
-
i.query,
|
|
697
|
-
c.hash
|
|
698
|
-
).toString(), h = new Request(l, {
|
|
699
|
-
method: i.method || "GET",
|
|
700
|
-
credentials: i.credentials,
|
|
701
|
-
cache: i.cache,
|
|
702
|
-
mode: i.mode,
|
|
703
|
-
headers: W.mergeHeaders(
|
|
704
|
-
this.baseConfigs.headers,
|
|
705
|
-
i.headers || {},
|
|
706
|
-
n
|
|
707
|
-
),
|
|
708
|
-
body: i.body,
|
|
709
|
-
signal: o?.signal
|
|
710
|
-
});
|
|
711
|
-
if (i.rawRequest = h, i = await this.emit("beforeActualFetch", i, {
|
|
712
|
-
shouldHandleShortCircuitResponse: !0
|
|
713
|
-
}), i[_.FINAL_SYMBOL]) return i;
|
|
714
|
-
const d = i.timeout || this.baseConfigs.timeout || 60 * 1e3;
|
|
715
|
-
if (i.url.startsWith("ws"))
|
|
716
|
-
try {
|
|
717
|
-
const f = new WebSocket(i.url);
|
|
718
|
-
return await new Promise((g, p) => {
|
|
719
|
-
const y = setTimeout(() => {
|
|
720
|
-
p(
|
|
721
|
-
new $(
|
|
722
|
-
x.TIMEOUT,
|
|
723
|
-
`WebSocket connection timed out after ${d}ms`,
|
|
724
|
-
i
|
|
725
|
-
)
|
|
726
|
-
);
|
|
727
|
-
}, d);
|
|
728
|
-
f.onopen = () => {
|
|
729
|
-
clearTimeout(y), g();
|
|
730
|
-
}, f.onerror = (L) => {
|
|
731
|
-
clearTimeout(y), p(
|
|
732
|
-
new $(
|
|
733
|
-
x.NETWORK_ERROR,
|
|
734
|
-
"WebSocket connection failed",
|
|
735
|
-
i
|
|
736
|
-
)
|
|
737
|
-
);
|
|
738
|
-
}, f.onclose = (L) => {
|
|
739
|
-
L.code !== 1e3 && (clearTimeout(y), p(
|
|
740
|
-
new $(
|
|
741
|
-
x.NETWORK_ERROR,
|
|
742
|
-
`WebSocket closed with code ${L.code}`,
|
|
743
|
-
i
|
|
744
|
-
)
|
|
745
|
-
));
|
|
746
|
-
};
|
|
747
|
-
}), i.rawResponse = new Response(), i.response = new q(i.rawResponse, f, {
|
|
748
|
-
ok: !0,
|
|
749
|
-
status: 101,
|
|
750
|
-
statusText: "Switching Protocols"
|
|
751
|
-
}), i.data = f, i.headers = new Headers(), this.emit("afterResponse", i);
|
|
752
|
-
} catch (f) {
|
|
753
|
-
throw f instanceof $ ? f : new $(
|
|
754
|
-
x.NETWORK_ERROR,
|
|
755
|
-
`WebSocket creation failed: ${f}`,
|
|
756
|
-
i
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
let u;
|
|
760
|
-
try {
|
|
761
|
-
o && (u = setTimeout(() => {
|
|
762
|
-
o.abort();
|
|
763
|
-
}, d));
|
|
764
|
-
const f = await (t.fetch || this.baseConfigs.fetch || globalThis.fetch)(i.rawRequest).catch((g) => {
|
|
765
|
-
throw u && clearTimeout(u), o?.signal.aborted ? new $(
|
|
766
|
-
x.TIMEOUT,
|
|
767
|
-
`Request timed out after ${d}ms`,
|
|
768
|
-
i
|
|
769
|
-
) : new $(x.NETWORK_ERROR, g.message, i);
|
|
770
|
-
});
|
|
771
|
-
return u && clearTimeout(u), i.rawResponse = f, i.response = await Oe(
|
|
772
|
-
f,
|
|
773
|
-
i.responseType,
|
|
774
|
-
(g, p) => {
|
|
775
|
-
t?.onProgress?.(g, p);
|
|
776
|
-
}
|
|
777
|
-
), i.data = i.response.data, i.headers = i.response.headers, this.emit("afterResponse", i);
|
|
778
|
-
} catch (f) {
|
|
779
|
-
throw u && clearTimeout(u), f;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
mergeQueries = V.mergeQueries;
|
|
783
|
-
mergeHeaders = W.mergeHeaders;
|
|
784
|
-
normalizeContext(e, t = {}) {
|
|
785
|
-
const i = e, s = i.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", n = new URL(
|
|
786
|
-
s,
|
|
787
|
-
globalThis.location?.href || "http://localhost"
|
|
788
|
-
), o = new URL(i.url.toString(), n), a = !!i[_.NORMALIZED_SYMBOL];
|
|
789
|
-
i.baseURL = n ? n.origin : o.origin;
|
|
790
|
-
let c;
|
|
791
|
-
a ? c = t.requestOptionsOverridesURLSearchParams ? this.mergeQueries({}, o.search, i.query) : this.mergeQueries({}, i.query, o.search) : (c = t.requestOptionsOverridesURLSearchParams ? this.mergeQueries(
|
|
792
|
-
n?.search || "",
|
|
793
|
-
this.baseConfigs.query,
|
|
794
|
-
o.search,
|
|
795
|
-
i.query
|
|
796
|
-
) : this.mergeQueries(
|
|
797
|
-
n?.search || "",
|
|
798
|
-
this.baseConfigs.query,
|
|
799
|
-
i.query,
|
|
800
|
-
o.search
|
|
801
|
-
), i[_.NORMALIZED_SYMBOL] = !0), i.query = c;
|
|
802
|
-
const l = new URL(o);
|
|
803
|
-
return l.search = "", i.url = l.toString(), i;
|
|
804
|
-
}
|
|
805
|
-
async emit(e, t, i = {}) {
|
|
806
|
-
const s = this.hooks.filter((n) => n.event === e);
|
|
807
|
-
if (i?.shouldAdjustRequestParams && i?.preAdjust)
|
|
808
|
-
try {
|
|
809
|
-
t = this.normalizeContext(t, {
|
|
810
|
-
requestOptionsOverridesURLSearchParams: i.preRequestOptionsOverridesURLSearchParams
|
|
811
|
-
});
|
|
812
|
-
} catch {
|
|
813
|
-
}
|
|
814
|
-
try {
|
|
815
|
-
let n = 0;
|
|
816
|
-
for (const o of s) {
|
|
817
|
-
const a = `${e}#${o.action.name || `anonymous#${n}`}`, c = Symbol("FEXIOS_HOOK_CONTEXT");
|
|
818
|
-
t[c] = c;
|
|
819
|
-
const l = t.url;
|
|
820
|
-
let h = "";
|
|
821
|
-
try {
|
|
822
|
-
const u = this.mergeQueries(
|
|
823
|
-
{},
|
|
824
|
-
t.query || {}
|
|
825
|
-
);
|
|
826
|
-
h = JSON.stringify(u);
|
|
827
|
-
} catch {
|
|
828
|
-
}
|
|
829
|
-
let d = await o.action.call(this, t);
|
|
830
|
-
if (d === void 0 && (d = t), d === !1)
|
|
831
|
-
throw new $(
|
|
832
|
-
x.ABORTED_BY_HOOK,
|
|
833
|
-
`Request aborted by hook "${a}"`,
|
|
834
|
-
t
|
|
835
|
-
);
|
|
836
|
-
if (d instanceof Response) {
|
|
837
|
-
const u = d, f = { ...t, rawResponse: u }, g = await Oe(
|
|
838
|
-
u,
|
|
839
|
-
t.responseType,
|
|
840
|
-
(p, y) => {
|
|
841
|
-
t.onProgress?.(p, y);
|
|
842
|
-
}
|
|
843
|
-
);
|
|
844
|
-
if (f.response = g, f.data = g.data, f.headers = g.headers, e !== "afterResponse") {
|
|
845
|
-
const p = await this.emit("afterResponse", f);
|
|
846
|
-
return p[_.FINAL_SYMBOL] = !0, p;
|
|
847
|
-
} else
|
|
848
|
-
return f[_.FINAL_SYMBOL] = !0, f;
|
|
849
|
-
} else if (typeof d == "object" && d[c] === c)
|
|
850
|
-
t = d;
|
|
851
|
-
else {
|
|
852
|
-
const u = globalThis["".concat("console")];
|
|
853
|
-
try {
|
|
854
|
-
throw new $(
|
|
855
|
-
x.HOOK_CONTEXT_CHANGED,
|
|
856
|
-
`Hook "${a}" should return the original FexiosContext or return false to abort the request, but got "${d}".`
|
|
857
|
-
);
|
|
858
|
-
} catch (f) {
|
|
859
|
-
u.warn(f.stack || f);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
if (i?.shouldAdjustRequestParams)
|
|
863
|
-
try {
|
|
864
|
-
const u = t.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", f = new URL(
|
|
865
|
-
t.url.toString(),
|
|
866
|
-
u
|
|
867
|
-
);
|
|
868
|
-
let g = {};
|
|
869
|
-
if (h)
|
|
870
|
-
try {
|
|
871
|
-
g = JSON.parse(h);
|
|
872
|
-
} catch {
|
|
873
|
-
}
|
|
874
|
-
const p = t.query || {}, y = this.mergeQueries(
|
|
875
|
-
g,
|
|
876
|
-
f.search,
|
|
877
|
-
p
|
|
878
|
-
);
|
|
879
|
-
t.query = y;
|
|
880
|
-
const L = new URL(f);
|
|
881
|
-
L.search = "", t.url = L.toString();
|
|
882
|
-
} catch {
|
|
883
|
-
}
|
|
884
|
-
delete t[c], n++;
|
|
885
|
-
}
|
|
886
|
-
} catch (n) {
|
|
887
|
-
return Promise.reject(n);
|
|
888
|
-
}
|
|
889
|
-
return t;
|
|
890
|
-
}
|
|
891
|
-
on(e, t, i = !1) {
|
|
892
|
-
if (typeof t != "function")
|
|
893
|
-
throw new $(
|
|
894
|
-
x.INVALID_HOOK_CALLBACK,
|
|
895
|
-
`Hook should be a function, but got "${typeof t}"`
|
|
896
|
-
);
|
|
897
|
-
return this.hooks[i ? "unshift" : "push"]({
|
|
898
|
-
event: e,
|
|
899
|
-
action: t
|
|
900
|
-
}), this;
|
|
901
|
-
}
|
|
902
|
-
off(e, t) {
|
|
903
|
-
return e === "*" || !e ? this.hooks = this.hooks.filter((i) => i.action !== t) : this.hooks = this.hooks.filter(
|
|
904
|
-
(i) => i.event !== e || i.action !== t
|
|
905
|
-
), this;
|
|
906
|
-
}
|
|
907
|
-
createInterceptor(e) {
|
|
908
|
-
return {
|
|
909
|
-
handlers: () => this.hooks.filter((t) => t.event === e).map((t) => t.action),
|
|
910
|
-
use: (t, i = !1) => this.on(e, t, i),
|
|
911
|
-
clear: () => {
|
|
912
|
-
this.hooks = this.hooks.filter((t) => t.event !== e);
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
interceptors = {
|
|
917
|
-
request: this.createInterceptor("beforeRequest"),
|
|
918
|
-
response: this.createInterceptor("afterResponse")
|
|
919
|
-
};
|
|
920
|
-
createMethodShortcut(e) {
|
|
921
|
-
return Reflect.defineProperty(this, e, {
|
|
922
|
-
get: () => (t, i, s) => (_.METHODS_WITHOUT_BODY.includes(
|
|
923
|
-
e.toLocaleLowerCase()
|
|
924
|
-
) ? s = i : (s = s || {}, s.body = i), this.request(t, {
|
|
925
|
-
...s,
|
|
926
|
-
method: e
|
|
927
|
-
}))
|
|
928
|
-
}), this;
|
|
929
|
-
}
|
|
930
|
-
extends(e) {
|
|
931
|
-
const t = new _(K(this.baseConfigs, e));
|
|
932
|
-
return t.hooks = [...this.hooks], t._plugins = new Map(this._plugins), t._plugins.forEach(async (i) => {
|
|
933
|
-
await t.plugin(i);
|
|
934
|
-
}), t;
|
|
935
|
-
}
|
|
936
|
-
create = _.create;
|
|
937
|
-
static create(e) {
|
|
938
|
-
return new _(e);
|
|
939
|
-
}
|
|
940
|
-
_plugins = /* @__PURE__ */ new Map();
|
|
941
|
-
async plugin(e) {
|
|
942
|
-
if (typeof e?.name == "string" && typeof e?.install == "function") {
|
|
943
|
-
if (this._plugins.has(e.name))
|
|
944
|
-
return this;
|
|
945
|
-
const t = await e.install(this);
|
|
946
|
-
if (this._plugins.set(e.name, e), t instanceof _)
|
|
947
|
-
return t;
|
|
948
|
-
}
|
|
949
|
-
return this;
|
|
950
|
-
}
|
|
951
|
-
// 版本弃子们.jpg
|
|
952
|
-
/** @deprecated Use checkIsPlainObject from utils instead */
|
|
953
|
-
checkIsPlainObject = A;
|
|
954
|
-
/** @deprecated Use `mergeQueries` instead */
|
|
955
|
-
mergeQuery = this.mergeQueries;
|
|
956
|
-
};
|
|
957
|
-
const Wt = de.create, Ie = Wt();
|
|
958
|
-
typeof globalThis < "u" ? globalThis.fexios = Ie : typeof window < "u" && (window.fexios = Ie);
|
|
959
|
-
var Z;
|
|
960
|
-
((r) => {
|
|
961
|
-
function e(i) {
|
|
962
|
-
return Array.isArray(i) ? i.join("|") : typeof i == "boolean" || i === null ? i ? "1" : void 0 : typeof i == "number" ? "" + i : i;
|
|
963
|
-
}
|
|
964
|
-
r.normalizeParamValue = e;
|
|
965
|
-
function t(i) {
|
|
966
|
-
const s = (o) => o && (o instanceof URLSearchParams || o instanceof FormData);
|
|
967
|
-
if (i == null)
|
|
968
|
-
return;
|
|
969
|
-
const n = new FormData();
|
|
970
|
-
if (s(i))
|
|
971
|
-
return i.forEach((o, a) => {
|
|
972
|
-
const c = e(o);
|
|
973
|
-
c != null && n.append(a, c);
|
|
974
|
-
}), n;
|
|
975
|
-
if (A(i))
|
|
976
|
-
return Object.entries(i).forEach(([o, a]) => {
|
|
977
|
-
const c = e(a);
|
|
978
|
-
c != null && n.append(o, c);
|
|
979
|
-
}), n;
|
|
980
|
-
}
|
|
981
|
-
r.normalizeBody = t;
|
|
982
|
-
})(Z || (Z = {}));
|
|
983
|
-
var z = /* @__PURE__ */ ((r) => (r.HTTP_ERROR = "HTTP_ERROR", r.LOGIN_FAILED = "LOGIN_FAILED", r.LOGIN_RETRY_LIMIT_EXCEEDED = "LOGIN_RETRY_LIMIT_EXCEEDED", r.TOKEN_RETRY_LIMIT_EXCEEDED = "TOKEN_RETRY_LIMIT_EXCEEDED", r))(z || {});
|
|
984
|
-
class R extends Error {
|
|
985
|
-
constructor(e, t = "", i) {
|
|
986
|
-
super(), this.code = e, this.message = t, this.cause = i, this.name = "WikiSaikouError";
|
|
987
|
-
}
|
|
988
|
-
static is(e, t) {
|
|
989
|
-
return e instanceof this && (t === void 0 || e.code === t);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
let N = class Ge extends Error {
|
|
993
|
-
constructor(e, t) {
|
|
994
|
-
super(), this.errors = e, this.cause = t, this.name = "MediaWikiApiError", this.errors = Ge.normalizeErrors(e), this.message = e.map((i) => i.text).filter(Boolean).join(`
|
|
995
|
-
`), this.code = this.isBadTokenError() ? "badtoken" : this.errors[0]?.code || "Unknown Error";
|
|
996
|
-
}
|
|
997
|
-
get firstError() {
|
|
998
|
-
return this.errors[0];
|
|
999
|
-
}
|
|
1000
|
-
isBadTokenError() {
|
|
1001
|
-
return this.errors.some((e) => e.code === "badtoken") || ["NeedToken", "WrongToken"].includes(this.cause?.data?.login?.result);
|
|
1002
|
-
}
|
|
1003
|
-
toString() {
|
|
1004
|
-
return `[${this.name} ${this.code}]`;
|
|
1005
|
-
}
|
|
1006
|
-
static is(e) {
|
|
1007
|
-
return e instanceof this;
|
|
1008
|
-
}
|
|
1009
|
-
static normalizeErrors(e) {
|
|
1010
|
-
return Array.isArray(e) === !1 ? [] : e.filter((t) => typeof t == "object" && !!t?.code).map((t) => t.text ? t : t.info ? { ...t, text: t.info } : t["*"] ? { ...t, text: t["*"] } : { ...t, text: "" });
|
|
1011
|
-
}
|
|
1012
|
-
};
|
|
1013
|
-
((r) => {
|
|
1014
|
-
function e(n) {
|
|
1015
|
-
if (n == null) return;
|
|
1016
|
-
if (n?.response?.data !== void 0) return n.response.data;
|
|
1017
|
-
if (n?.data !== void 0) return n.data;
|
|
1018
|
-
const o = n instanceof Error ? n.cause : void 0;
|
|
1019
|
-
return o?.response?.data !== void 0 ? o.response.data : o?.data !== void 0 ? o.data : n || void 0;
|
|
1020
|
-
}
|
|
1021
|
-
function t(n) {
|
|
1022
|
-
return i(n).length > 0;
|
|
1023
|
-
}
|
|
1024
|
-
r.includesMediaWikiApiError = t, r.normalizeMwApiErrors = N.normalizeErrors;
|
|
1025
|
-
function i(n) {
|
|
1026
|
-
let o = e(n);
|
|
1027
|
-
if (typeof o != "object" || o === null)
|
|
1028
|
-
return [];
|
|
1029
|
-
const a = o?.error, c = o?.errors, l = [];
|
|
1030
|
-
return a && l.push(a), Array.isArray(c) && l.push(...c), (0, r.normalizeMwApiErrors)(l);
|
|
1031
|
-
}
|
|
1032
|
-
r.extractMediaWikiApiErrors = i;
|
|
1033
|
-
function s(n) {
|
|
1034
|
-
if (N.is(n))
|
|
1035
|
-
return n.isBadTokenError();
|
|
1036
|
-
{
|
|
1037
|
-
const o = i(n);
|
|
1038
|
-
return new N(o).isBadTokenError();
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
r.isBadTokenError = s;
|
|
1042
|
-
})(R || (R = {}));
|
|
1043
|
-
const Pe = Symbol.for("__FEXIOS_SAIKOU__");
|
|
1044
|
-
function Ye(r) {
|
|
1045
|
-
const e = r instanceof de ? r : new de({
|
|
1046
|
-
baseURL: r instanceof URL ? r.toString() : String(r),
|
|
1047
|
-
responseType: "json"
|
|
1048
|
-
});
|
|
1049
|
-
return e[Pe] || (Reflect.defineProperty(e, Pe, {
|
|
1050
|
-
get: () => !0,
|
|
1051
|
-
enumerable: !1,
|
|
1052
|
-
configurable: !1
|
|
1053
|
-
}), e._tokens = /* @__PURE__ */ new Map(), e.on("afterResponse", (t) => {
|
|
1054
|
-
const { data: i, rawRequest: s } = t, n = s?.headers.get("x-mw-token-name");
|
|
1055
|
-
n && R.isBadTokenError(i) && e._tokens.delete(n);
|
|
1056
|
-
const o = i?.query?.tokens;
|
|
1057
|
-
o && typeof o == "object" && Object.entries(o).forEach(([c, l]) => {
|
|
1058
|
-
typeof l == "string" && e._tokens.set(c.replace(/token$/i, "").toLowerCase(), l);
|
|
1059
|
-
});
|
|
1060
|
-
const a = i?.login?.token;
|
|
1061
|
-
return typeof a == "string" && e._tokens.set("login", a), t;
|
|
1062
|
-
}), e.on("beforeInit", (t) => {
|
|
1063
|
-
if (t.method?.toLowerCase() !== "post")
|
|
1064
|
-
return t;
|
|
1065
|
-
if (t.body === void 0 || t.body === null)
|
|
1066
|
-
return t.body = void 0, t;
|
|
1067
|
-
const i = t.body = Z.normalizeBody(t.body), s = new URLSearchParams(t.query);
|
|
1068
|
-
return i.has("format") && s.delete("format"), i.has("formatversion") && s.delete("formatversion"), i.has("action") && s.delete("action"), i.has("origin") && (s.set("origin", "" + i.get("origin")), i.delete("origin")), t.query = Object.fromEntries(s.entries()), t;
|
|
1069
|
-
}), e.on("beforeInit", (t) => (t.query = Z.normalizeBody(t.query) || {}, t)), e.on("beforeRequest", (t) => {
|
|
1070
|
-
const i = new URL(t.url), s = i.searchParams;
|
|
1071
|
-
if (globalThis.location && (!s.has("origin") && location.origin !== i.origin ? (s.set("origin", location.origin), e.baseConfigs.credentials = "include", e.baseConfigs.mode = "cors") : location.origin === i.origin && (s.delete("origin"), e.baseConfigs.credentials = void 0, e.baseConfigs.mode = void 0)), i.searchParams.has("origin")) {
|
|
1072
|
-
const n = encodeURIComponent(
|
|
1073
|
-
i.searchParams.get("origin") || ""
|
|
1074
|
-
).replace(/\./g, "%2E");
|
|
1075
|
-
t.query = {}, i.searchParams.delete("origin"), t.url = `${i}${i.search ? "&" : "?"}origin=${n}`;
|
|
1076
|
-
}
|
|
1077
|
-
return t;
|
|
1078
|
-
})), e;
|
|
1079
|
-
}
|
|
1080
|
-
const D = (r, ...e) => {
|
|
1081
|
-
const t = (n) => Object.prototype.toString.call(n) === "[object Object]", i = (n) => {
|
|
1082
|
-
if (Array.isArray(n)) return n.slice();
|
|
1083
|
-
if (t(n)) {
|
|
1084
|
-
const o = {};
|
|
1085
|
-
for (const a of Reflect.ownKeys(n)) o[a] = i(n[a]);
|
|
1086
|
-
return o;
|
|
1087
|
-
}
|
|
1088
|
-
return n;
|
|
1089
|
-
}, s = i(r);
|
|
1090
|
-
for (const n of e)
|
|
1091
|
-
if (n != null)
|
|
1092
|
-
for (const o of Reflect.ownKeys(n)) {
|
|
1093
|
-
const a = n[o];
|
|
1094
|
-
if (typeof a > "u") continue;
|
|
1095
|
-
const c = s[o];
|
|
1096
|
-
t(c) && t(a) ? s[o] = D(c, a) : s[o] = i(a);
|
|
1097
|
-
}
|
|
1098
|
-
return s;
|
|
1099
|
-
}, zt = (r, e, t) => {
|
|
1100
|
-
let i = { ...Xe.DEFAULT_CONFIGS };
|
|
1101
|
-
if (typeof r == "string" ? i = D(i, {
|
|
1102
|
-
baseURL: r,
|
|
1103
|
-
fexiosConfigs: e || {},
|
|
1104
|
-
defaultParams: t || {}
|
|
1105
|
-
}) : typeof r == "object" && r !== null && (i = D(i, r)), !i.baseURL && typeof window == "object" && window.mediaWiki) {
|
|
1106
|
-
const { wgServer: s, wgScriptPath: n } = window.mediaWiki?.config?.get(["wgServer", "wgScriptPath"]) || {};
|
|
1107
|
-
typeof s == "string" && typeof n == "string" && (i.baseURL = `${s}${n}/api.php`);
|
|
1108
|
-
}
|
|
1109
|
-
if (typeof i.baseURL != "string")
|
|
1110
|
-
throw new Error("baseURL is required");
|
|
1111
|
-
return i;
|
|
1112
|
-
}, Gt = () => {
|
|
1113
|
-
}, Yt = async (r, e) => {
|
|
1114
|
-
let t = 0;
|
|
1115
|
-
const { retry: i = 3, onRetry: s = Gt, shouldRetry: n = () => !0 } = e;
|
|
1116
|
-
let o;
|
|
1117
|
-
do
|
|
1118
|
-
try {
|
|
1119
|
-
return await r();
|
|
1120
|
-
} catch (a) {
|
|
1121
|
-
if (o = a, n(a, t))
|
|
1122
|
-
s(a, t), t++;
|
|
1123
|
-
else
|
|
1124
|
-
throw a;
|
|
1125
|
-
}
|
|
1126
|
-
while (t < i);
|
|
1127
|
-
throw o || new Error("Retry failed");
|
|
1128
|
-
};
|
|
1129
|
-
const F = class {
|
|
1130
|
-
constructor(e, t, i) {
|
|
1131
|
-
this.version = "7.1.2", this.token = this.getToken;
|
|
1132
|
-
const s = this.config = zt(
|
|
1133
|
-
e,
|
|
1134
|
-
t,
|
|
1135
|
-
i
|
|
1136
|
-
);
|
|
1137
|
-
this.request = Ye(s.baseURL);
|
|
1138
|
-
}
|
|
1139
|
-
setBaseURL(e) {
|
|
1140
|
-
return this.config.baseURL = e, this.request.baseConfigs.baseURL = e, this;
|
|
1141
|
-
}
|
|
1142
|
-
/** Base methods encapsulation */
|
|
1143
|
-
async get(e, t) {
|
|
1144
|
-
return this.runRequestWithApiErrorMapping(
|
|
1145
|
-
() => this.request.get(
|
|
1146
|
-
"",
|
|
1147
|
-
D(
|
|
1148
|
-
{},
|
|
1149
|
-
this.config.fexiosConfigs,
|
|
1150
|
-
{ query: D(this.config.defaultParams, e) },
|
|
1151
|
-
t
|
|
1152
|
-
)
|
|
1153
|
-
)
|
|
1154
|
-
);
|
|
1155
|
-
}
|
|
1156
|
-
async post(e, t) {
|
|
1157
|
-
return this.runRequestWithApiErrorMapping(
|
|
1158
|
-
() => this.request.post(
|
|
1159
|
-
"",
|
|
1160
|
-
e,
|
|
1161
|
-
D(
|
|
1162
|
-
{},
|
|
1163
|
-
this.config.fexiosConfigs,
|
|
1164
|
-
{
|
|
1165
|
-
query: this.config.defaultParams
|
|
1166
|
-
},
|
|
1167
|
-
t
|
|
1168
|
-
)
|
|
1169
|
-
)
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Wrap a request to map non-2xx responses containing MediaWiki API error bodies
|
|
1174
|
-
* into MediaWikiApiError when throwOnApiError=true, and then pass 2xx responses
|
|
1175
|
-
* through handleApiResponse for unified processing.
|
|
1176
|
-
*/
|
|
1177
|
-
async runRequestWithApiErrorMapping(e) {
|
|
1178
|
-
try {
|
|
1179
|
-
const t = await e();
|
|
1180
|
-
return this.handleApiResponse(t);
|
|
1181
|
-
} catch (t) {
|
|
1182
|
-
throw this.config.throwOnApiError && R.includesMediaWikiApiError(t) ? new N(
|
|
1183
|
-
R.extractMediaWikiApiErrors(t),
|
|
1184
|
-
t
|
|
1185
|
-
) : t;
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
throwIfApiError(e) {
|
|
1189
|
-
const t = R.extractMediaWikiApiErrors(e);
|
|
1190
|
-
if (t.length > 0)
|
|
1191
|
-
throw new N(t, e);
|
|
1192
|
-
}
|
|
1193
|
-
handleApiResponse(e) {
|
|
1194
|
-
return this.config.throwOnApiError && this.throwIfApiError(e.data), e;
|
|
1195
|
-
}
|
|
1196
|
-
/** Token Handler */
|
|
1197
|
-
get tokens() {
|
|
1198
|
-
return this.request._tokens;
|
|
1199
|
-
}
|
|
1200
|
-
async fetchTokens(e = ["csrf"]) {
|
|
1201
|
-
return this.config.fexiosConfigs.credentials = "include", await this.get({
|
|
1202
|
-
action: "query",
|
|
1203
|
-
meta: "tokens",
|
|
1204
|
-
type: e
|
|
1205
|
-
}), this.tokens;
|
|
1206
|
-
}
|
|
1207
|
-
async getToken(e = "csrf", t = !1) {
|
|
1208
|
-
return (!this.tokens.get(e) || t) && (this.tokens.delete(e), await this.fetchTokens([e])), this.tokens.get(e);
|
|
1209
|
-
}
|
|
1210
|
-
badToken(e) {
|
|
1211
|
-
return this.tokens.delete(e), this.tokens;
|
|
1212
|
-
}
|
|
1213
|
-
async postWithToken(e, t, i) {
|
|
1214
|
-
const {
|
|
1215
|
-
tokenName: s = "token",
|
|
1216
|
-
retry: n = 3,
|
|
1217
|
-
noCache: o = !1,
|
|
1218
|
-
fexiosOptions: a
|
|
1219
|
-
} = i || {};
|
|
1220
|
-
if (n < 1)
|
|
1221
|
-
throw new R(
|
|
1222
|
-
z.TOKEN_RETRY_LIMIT_EXCEEDED,
|
|
1223
|
-
"The limit of the number of times to automatically re-acquire the token has been exceeded"
|
|
1224
|
-
);
|
|
1225
|
-
let c = 0;
|
|
1226
|
-
return Yt(
|
|
1227
|
-
async () => {
|
|
1228
|
-
const l = await this.getToken(
|
|
1229
|
-
e,
|
|
1230
|
-
o || c > 0
|
|
1231
|
-
);
|
|
1232
|
-
try {
|
|
1233
|
-
const h = await this.post(
|
|
1234
|
-
{
|
|
1235
|
-
[s]: l,
|
|
1236
|
-
...t
|
|
1237
|
-
},
|
|
1238
|
-
D(a || {}, {
|
|
1239
|
-
headers: { "x-mw-token-name": e }
|
|
1240
|
-
})
|
|
1241
|
-
);
|
|
1242
|
-
if (R.isBadTokenError(h.data))
|
|
1243
|
-
throw h;
|
|
1244
|
-
return h;
|
|
1245
|
-
} catch (h) {
|
|
1246
|
-
throw R.isBadTokenError(h) || h?.ok === !1 || N.is(h) ? h : new R(
|
|
1247
|
-
z.HTTP_ERROR,
|
|
1248
|
-
"Network/transport or SDK-internal error (not a MediaWiki API error)",
|
|
1249
|
-
h
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
},
|
|
1253
|
-
{
|
|
1254
|
-
retry: n,
|
|
1255
|
-
onRetry: (l, h) => {
|
|
1256
|
-
c = h + 1;
|
|
1257
|
-
},
|
|
1258
|
-
shouldRetry: (l) => R.isBadTokenError(l) || l?.ok === !1
|
|
1259
|
-
}
|
|
1260
|
-
).catch((l) => {
|
|
1261
|
-
throw R.isBadTokenError(l) || l?.ok === !1 ? new R(
|
|
1262
|
-
z.TOKEN_RETRY_LIMIT_EXCEEDED,
|
|
1263
|
-
"Retry attempts for acquiring/using token exhausted",
|
|
1264
|
-
l
|
|
1265
|
-
) : l;
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
postWithEditToken(e) {
|
|
1269
|
-
return this.postWithToken("csrf", e);
|
|
1270
|
-
}
|
|
1271
|
-
// for backward compatibility
|
|
1272
|
-
/** @deprecated Use `this.config.baseURL` instead */
|
|
1273
|
-
get baseURL() {
|
|
1274
|
-
return this.config.baseURL;
|
|
1275
|
-
}
|
|
1276
|
-
/** @deprecated Use `this.config.defaultParams` instead */
|
|
1277
|
-
get defaultParams() {
|
|
1278
|
-
return this.config.defaultParams;
|
|
1279
|
-
}
|
|
1280
|
-
/** @deprecated Use `this.config.fexiosConfigs` instead */
|
|
1281
|
-
get defaultOptions() {
|
|
1282
|
-
return this.config.fexiosConfigs;
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
F.INIT_DEFAULT_PARAMS = {
|
|
1286
|
-
action: "query",
|
|
1287
|
-
errorformat: "plaintext",
|
|
1288
|
-
format: "json",
|
|
1289
|
-
formatversion: 2
|
|
1290
|
-
}, F.DEFAULT_CONFIGS = {
|
|
1291
|
-
baseURL: void 0,
|
|
1292
|
-
fexiosConfigs: {
|
|
1293
|
-
responseType: "json"
|
|
1294
|
-
},
|
|
1295
|
-
defaultParams: F.INIT_DEFAULT_PARAMS,
|
|
1296
|
-
throwOnApiError: !1
|
|
1297
|
-
}, F.createRequestHandler = Ye;
|
|
1298
|
-
let Xe = F;
|
|
1299
|
-
let Xt = class extends Xe {
|
|
1300
|
-
async clientLogin(e, t, i) {
|
|
1301
|
-
i ||= {}, !i.logincontinue && !i.loginreturnurl && (i.loginreturnurl = location?.origin);
|
|
1302
|
-
const s = await this.postWithToken(
|
|
1303
|
-
"login",
|
|
1304
|
-
{
|
|
1305
|
-
action: "clientlogin",
|
|
1306
|
-
username: e,
|
|
1307
|
-
password: t,
|
|
1308
|
-
...i
|
|
1309
|
-
},
|
|
1310
|
-
{
|
|
1311
|
-
tokenName: "logintoken"
|
|
1312
|
-
}
|
|
1313
|
-
);
|
|
1314
|
-
if (s?.data?.clientlogin?.status === "PASS")
|
|
1315
|
-
return s.data.clientlogin;
|
|
1316
|
-
throw new R(
|
|
1317
|
-
z.LOGIN_FAILED,
|
|
1318
|
-
s.data.clientlogin.message,
|
|
1319
|
-
s
|
|
1320
|
-
);
|
|
1321
|
-
}
|
|
1322
|
-
};
|
|
1323
|
-
class Qt {
|
|
1324
|
-
constructor(e, t = {}) {
|
|
1325
|
-
this.ctx = e, location?.href && t?.baseURL?.toString()?.startsWith("/") && (t.baseURL = new URL(t.baseURL, location.origin));
|
|
1326
|
-
const i = new Xt({
|
|
1327
|
-
baseURL: t.baseURL.toString(),
|
|
1328
|
-
fexiosConfigs: {
|
|
1329
|
-
headers: {
|
|
1330
|
-
"x-api-user-agent": `InPageEdit-NEXT ${e.version}`,
|
|
1331
|
-
...t.headers
|
|
1332
|
-
},
|
|
1333
|
-
...t
|
|
1334
|
-
},
|
|
1335
|
-
throwOnApiError: !0
|
|
1336
|
-
});
|
|
1337
|
-
e.set("api", i);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
var Vt = Object.create, me = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Qe = (r, e) => (e = Symbol[r]) ? e : Symbol.for("Symbol." + r), Ve = (r) => {
|
|
1341
|
-
throw TypeError(r);
|
|
1342
|
-
}, Jt = (r, e, t) => e in r ? me(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ei = (r, e) => me(r, "name", { value: e, configurable: !0 }), ti = (r) => [, , , Vt(r?.[Qe("metadata")] ?? null)], ii = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Ze = (r) => r !== void 0 && typeof r != "function" ? Ve("Function expected") : r, si = (r, e, t, i, s) => ({ kind: ii[r], name: e, metadata: i, addInitializer: (n) => t._ ? Ve("Already initialized") : s.push(Ze(n || null)) }), ri = (r, e) => Jt(e, Qe("metadata"), r[3]), ni = (r, e, t, i) => {
|
|
1343
|
-
for (var s = 0, n = r[e >> 1], o = n && n.length; s < o; s++) n[s].call(t);
|
|
1344
|
-
return i;
|
|
1345
|
-
}, oi = (r, e, t, i, s, n) => {
|
|
1346
|
-
var o, a, c, l = e & 7, h = !1, d = 0, u = r[d] || (r[d] = []), f = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Zt(s, t));
|
|
1347
|
-
ei(s, t);
|
|
1348
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
1349
|
-
c = si(l, t, a = {}, r[3], u), o = (0, i[g])(s, c), a._ = 1, Ze(o) && (s = o);
|
|
1350
|
-
return ri(r, s), f && me(s, t, f), h ? l ^ 4 ? n : f : s;
|
|
1351
|
-
}, Je, ye, et;
|
|
1352
|
-
Je = [ne(["wiki", "wikiTitle"])];
|
|
1353
|
-
class J extends (et = I) {
|
|
1354
|
-
constructor(e) {
|
|
1355
|
-
super(e, "currentPage", !1), this.ctx = e, this.url = new URL(window.location.href), this.isMainPage = void 0, this.wikiTitle = void 0;
|
|
1356
|
-
}
|
|
1357
|
-
get logger() {
|
|
1358
|
-
return this.ctx.logger("CURRENT_PAGE");
|
|
1359
|
-
}
|
|
1360
|
-
async start() {
|
|
1361
|
-
await this.#e(), this.#i(), window.addEventListener("popstate", this.#t.bind(this)), this.logger.info("initialized", this.wikiTitle);
|
|
1362
|
-
}
|
|
1363
|
-
stop() {
|
|
1364
|
-
window.removeEventListener("popstate", this.#t.bind(this));
|
|
1365
|
-
}
|
|
1366
|
-
async #e() {
|
|
1367
|
-
await this.#r(), await this.#s();
|
|
1368
|
-
}
|
|
1369
|
-
#i() {
|
|
1370
|
-
const e = Symbol.for("InPageEdit.CurrentPageService.UrlChangeListenerInstalled");
|
|
1371
|
-
if (window[e])
|
|
1372
|
-
return;
|
|
1373
|
-
const t = history.pushState, i = history.replaceState;
|
|
1374
|
-
history.pushState = function(s, n, o) {
|
|
1375
|
-
t.apply(this, [s, n, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: s }));
|
|
1376
|
-
}, history.replaceState = function(s, n, o) {
|
|
1377
|
-
i.apply(this, [s, n, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: s }));
|
|
1378
|
-
}, window[e] = !0;
|
|
1379
|
-
}
|
|
1380
|
-
async #t(e) {
|
|
1381
|
-
const t = this.url, i = new URL(window.location.href);
|
|
1382
|
-
this.url = i, (t.pathname !== i.pathname || t.searchParams.get("title") !== i.searchParams.get("title") || t.searchParams.get("curid") !== i.searchParams.get("curid")) && (await this.#e(), this.logger.info("location changed", i, this.wikiTitle));
|
|
1383
|
-
}
|
|
1384
|
-
get params() {
|
|
1385
|
-
return this.url.searchParams;
|
|
1386
|
-
}
|
|
1387
|
-
get canonicalUrl() {
|
|
1388
|
-
const e = document.querySelector('link[rel="canonical"]')?.href;
|
|
1389
|
-
let t = null;
|
|
1390
|
-
return e && (t = new URL(e, location.origin)), Reflect.defineProperty(this, "canonicalUrl", {
|
|
1391
|
-
get: () => t
|
|
1392
|
-
}), t;
|
|
1393
|
-
}
|
|
1394
|
-
async #s() {
|
|
1395
|
-
const t = this.wikiTitle?.getMainDBKey() === this.ctx.wiki.mainPageName;
|
|
1396
|
-
return Reflect.defineProperty(this, "isMainPage", {
|
|
1397
|
-
get: () => t
|
|
1398
|
-
}), t;
|
|
1399
|
-
}
|
|
1400
|
-
async #r() {
|
|
1401
|
-
let e = null;
|
|
1402
|
-
return this.canonicalUrl ? e = await this.ctx.wikiTitle.newTitleFromUrl(this.canonicalUrl) : e = await this.ctx.wikiTitle.newTitleFromUrl(this.url), Object.freeze(e), Reflect.defineProperty(this, "wikiTitle", {
|
|
1403
|
-
get: () => e
|
|
1404
|
-
}), e;
|
|
1405
|
-
}
|
|
1406
|
-
get wikiAction() {
|
|
1407
|
-
return this.params.get("action") || "view";
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
ye = ti(et);
|
|
1411
|
-
J = oi(ye, 0, "CurrentPageService", Je, J);
|
|
1412
|
-
ni(ye, 1, J);
|
|
1413
|
-
class ai extends I {
|
|
1414
|
-
constructor(e) {
|
|
1415
|
-
super(e, "resourceLoader", !0), this.ctx = e;
|
|
1416
|
-
}
|
|
1417
|
-
stop() {
|
|
1418
|
-
this.removeAll();
|
|
1419
|
-
}
|
|
1420
|
-
loadScript(e, t) {
|
|
1421
|
-
if (!e)
|
|
1422
|
-
return Promise.resolve(null);
|
|
1423
|
-
const i = `script:${e}`, s = document.querySelector(`[data-ipe="${i}"]`);
|
|
1424
|
-
return s ? Promise.resolve(s) : new Promise((o, a) => {
|
|
1425
|
-
const c = document.createElement("script");
|
|
1426
|
-
c.src = e, c.dataset.ipe = i, t && Object.entries(t).forEach(([l, h]) => {
|
|
1427
|
-
typeof h > "u" || h === !1 || h === null ? c.removeAttribute(l) : c.setAttribute(l, h);
|
|
1428
|
-
}), document.body.appendChild(c), c.onload = () => o(c), c.onerror = (l) => a(l);
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
loadStyle(e, t) {
|
|
1432
|
-
if (!e)
|
|
1433
|
-
return Promise.resolve(null);
|
|
1434
|
-
const i = `style:${e}`, s = document.querySelector(`[data-ipe="${i}"]`);
|
|
1435
|
-
return s ? Promise.resolve(s) : new Promise((o, a) => {
|
|
1436
|
-
const c = document.createElement("link");
|
|
1437
|
-
c.rel = "stylesheet", c.href = e, c.dataset.ipe = i, t && Object.entries(t).forEach(([h, d]) => {
|
|
1438
|
-
typeof d > "u" || d === !1 || d === null ? c.removeAttribute(h) : c.setAttribute(h, d);
|
|
1439
|
-
}), (document.querySelector('meta[name="ipe-styles"]') || (() => {
|
|
1440
|
-
const h = document.createElement("meta");
|
|
1441
|
-
return h.id = "ipe-styles", h.name = "ipe-styles", document.head.insertAdjacentElement("afterbegin", h), h;
|
|
1442
|
-
})()).before(c), c.onload = () => o(c), c.onerror = (h) => a(h);
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
removeStyle(e) {
|
|
1446
|
-
const t = `style:${e}`, i = document.querySelector(`[data-ipe="${t}"]`);
|
|
1447
|
-
i && i.remove();
|
|
1448
|
-
}
|
|
1449
|
-
removeScript(e) {
|
|
1450
|
-
const t = `script:${e}`, i = document.querySelector(`[data-ipe="${t}"]`);
|
|
1451
|
-
i && i.remove();
|
|
1452
|
-
}
|
|
1453
|
-
removeAll() {
|
|
1454
|
-
document.querySelectorAll("[data-ipe]").forEach((e) => {
|
|
1455
|
-
e.remove();
|
|
1456
|
-
});
|
|
1457
|
-
}
|
|
1458
|
-
resolveImportPath(e) {
|
|
1459
|
-
return e.startsWith("http") || e.startsWith("//") ? e : import.meta.resolve(e);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
const oe = Object.keys;
|
|
1463
|
-
function li(r) {
|
|
1464
|
-
return typeof r == "boolean";
|
|
1465
|
-
}
|
|
1466
|
-
function ci(r) {
|
|
1467
|
-
return r && typeof r.nodeType == "number";
|
|
1468
|
-
}
|
|
1469
|
-
function we(r) {
|
|
1470
|
-
return typeof r == "string";
|
|
1471
|
-
}
|
|
1472
|
-
function tt(r) {
|
|
1473
|
-
return typeof r == "number";
|
|
1474
|
-
}
|
|
1475
|
-
function M(r) {
|
|
1476
|
-
return typeof r == "object" ? r !== null : G(r);
|
|
1477
|
-
}
|
|
1478
|
-
function G(r) {
|
|
1479
|
-
return typeof r == "function";
|
|
1480
|
-
}
|
|
1481
|
-
function hi(r) {
|
|
1482
|
-
return !!(r && r.isComponent);
|
|
1483
|
-
}
|
|
1484
|
-
function ui(r) {
|
|
1485
|
-
return M(r) && typeof r.length == "number" && typeof r.nodeType != "number";
|
|
1486
|
-
}
|
|
1487
|
-
function fe(r, e) {
|
|
1488
|
-
if (r)
|
|
1489
|
-
for (const t of oe(r))
|
|
1490
|
-
e(r[t], t);
|
|
1491
|
-
}
|
|
1492
|
-
function di(r) {
|
|
1493
|
-
return M(r) && "current" in r;
|
|
1494
|
-
}
|
|
1495
|
-
const ge = {
|
|
1496
|
-
animationIterationCount: 0,
|
|
1497
|
-
borderImageOutset: 0,
|
|
1498
|
-
borderImageSlice: 0,
|
|
1499
|
-
borderImageWidth: 0,
|
|
1500
|
-
boxFlex: 0,
|
|
1501
|
-
boxFlexGroup: 0,
|
|
1502
|
-
boxOrdinalGroup: 0,
|
|
1503
|
-
columnCount: 0,
|
|
1504
|
-
columns: 0,
|
|
1505
|
-
flex: 0,
|
|
1506
|
-
flexGrow: 0,
|
|
1507
|
-
flexPositive: 0,
|
|
1508
|
-
flexShrink: 0,
|
|
1509
|
-
flexNegative: 0,
|
|
1510
|
-
flexOrder: 0,
|
|
1511
|
-
gridArea: 0,
|
|
1512
|
-
gridRow: 0,
|
|
1513
|
-
gridRowEnd: 0,
|
|
1514
|
-
gridRowSpan: 0,
|
|
1515
|
-
gridRowStart: 0,
|
|
1516
|
-
gridColumn: 0,
|
|
1517
|
-
gridColumnEnd: 0,
|
|
1518
|
-
gridColumnSpan: 0,
|
|
1519
|
-
gridColumnStart: 0,
|
|
1520
|
-
fontWeight: 0,
|
|
1521
|
-
lineClamp: 0,
|
|
1522
|
-
lineHeight: 0,
|
|
1523
|
-
opacity: 0,
|
|
1524
|
-
order: 0,
|
|
1525
|
-
orphans: 0,
|
|
1526
|
-
tabSize: 0,
|
|
1527
|
-
widows: 0,
|
|
1528
|
-
zIndex: 0,
|
|
1529
|
-
zoom: 0,
|
|
1530
|
-
// SVG-related properties
|
|
1531
|
-
fillOpacity: 0,
|
|
1532
|
-
floodOpacity: 0,
|
|
1533
|
-
stopOpacity: 0,
|
|
1534
|
-
strokeDasharray: 0,
|
|
1535
|
-
strokeDashoffset: 0,
|
|
1536
|
-
strokeMiterlimit: 0,
|
|
1537
|
-
strokeOpacity: 0,
|
|
1538
|
-
strokeWidth: 0
|
|
1539
|
-
};
|
|
1540
|
-
function fi(r, e) {
|
|
1541
|
-
return r + e.charAt(0).toUpperCase() + e.substring(1);
|
|
1542
|
-
}
|
|
1543
|
-
const gi = ["Webkit", "ms", "Moz", "O"];
|
|
1544
|
-
oe(ge).forEach((r) => {
|
|
1545
|
-
gi.forEach((e) => {
|
|
1546
|
-
ge[fi(e, r)] = 0;
|
|
1547
|
-
});
|
|
1548
|
-
});
|
|
1549
|
-
const pi = Symbol.for("jsx-dom:type");
|
|
1550
|
-
var it = /* @__PURE__ */ (function(r) {
|
|
1551
|
-
return r.ShadowRoot = "ShadowRoot", r;
|
|
1552
|
-
})(it || {});
|
|
1553
|
-
function mi(r) {
|
|
1554
|
-
return r != null && r[pi] === it.ShadowRoot;
|
|
1555
|
-
}
|
|
1556
|
-
const yi = "http://www.w3.org/2000/svg", wi = "http://www.w3.org/1999/xlink", bi = "http://www.w3.org/XML/1998/namespace";
|
|
1557
|
-
function st(r) {
|
|
1558
|
-
return !li(r) && r != null;
|
|
1559
|
-
}
|
|
1560
|
-
function pe(r) {
|
|
1561
|
-
return Array.isArray(r) ? r.map(pe).filter(Boolean).join(" ") : M(r) ? Symbol.iterator in r ? pe(Array.from(r)) : oe(r).filter((e) => r[e]).join(" ") : st(r) ? "" + r : "";
|
|
1562
|
-
}
|
|
1563
|
-
const vi = {
|
|
1564
|
-
animate: 0,
|
|
1565
|
-
circle: 0,
|
|
1566
|
-
clipPath: 0,
|
|
1567
|
-
defs: 0,
|
|
1568
|
-
desc: 0,
|
|
1569
|
-
ellipse: 0,
|
|
1570
|
-
feBlend: 0,
|
|
1571
|
-
feColorMatrix: 0,
|
|
1572
|
-
feComponentTransfer: 0,
|
|
1573
|
-
feComposite: 0,
|
|
1574
|
-
feConvolveMatrix: 0,
|
|
1575
|
-
feDiffuseLighting: 0,
|
|
1576
|
-
feDisplacementMap: 0,
|
|
1577
|
-
feDistantLight: 0,
|
|
1578
|
-
feFlood: 0,
|
|
1579
|
-
feFuncA: 0,
|
|
1580
|
-
feFuncB: 0,
|
|
1581
|
-
feFuncG: 0,
|
|
1582
|
-
feFuncR: 0,
|
|
1583
|
-
feGaussianBlur: 0,
|
|
1584
|
-
feImage: 0,
|
|
1585
|
-
feMerge: 0,
|
|
1586
|
-
feMergeNode: 0,
|
|
1587
|
-
feMorphology: 0,
|
|
1588
|
-
feOffset: 0,
|
|
1589
|
-
fePointLight: 0,
|
|
1590
|
-
feSpecularLighting: 0,
|
|
1591
|
-
feSpotLight: 0,
|
|
1592
|
-
feTile: 0,
|
|
1593
|
-
feTurbulence: 0,
|
|
1594
|
-
filter: 0,
|
|
1595
|
-
foreignObject: 0,
|
|
1596
|
-
g: 0,
|
|
1597
|
-
image: 0,
|
|
1598
|
-
line: 0,
|
|
1599
|
-
linearGradient: 0,
|
|
1600
|
-
marker: 0,
|
|
1601
|
-
mask: 0,
|
|
1602
|
-
metadata: 0,
|
|
1603
|
-
path: 0,
|
|
1604
|
-
pattern: 0,
|
|
1605
|
-
polygon: 0,
|
|
1606
|
-
polyline: 0,
|
|
1607
|
-
radialGradient: 0,
|
|
1608
|
-
rect: 0,
|
|
1609
|
-
stop: 0,
|
|
1610
|
-
svg: 0,
|
|
1611
|
-
switch: 0,
|
|
1612
|
-
symbol: 0,
|
|
1613
|
-
text: 0,
|
|
1614
|
-
textPath: 0,
|
|
1615
|
-
tspan: 0,
|
|
1616
|
-
use: 0,
|
|
1617
|
-
view: 0
|
|
1618
|
-
}, _i = /^(a(ll|t|u)|base[FP]|c(al|lipPathU|on)|di|ed|ex|filter[RU]|g(lyphR|r)|ke|l(en|im)|ma(rker[HUW]|s)|n|pat|pr|point[^e]|re[^n]|s[puy]|st[^or]|ta|textL|vi|xC|y|z)/;
|
|
1619
|
-
function Si(r) {
|
|
1620
|
-
const e = document.createDocumentFragment();
|
|
1621
|
-
return ae(r.children, e), e;
|
|
1622
|
-
}
|
|
1623
|
-
function Ei(r, e, t) {
|
|
1624
|
-
e = {
|
|
1625
|
-
...e,
|
|
1626
|
-
children: t
|
|
1627
|
-
};
|
|
1628
|
-
const i = new r(e), s = i.render();
|
|
1629
|
-
return "ref" in e && be(e.ref, i), s;
|
|
1630
|
-
}
|
|
1631
|
-
function w(r, e) {
|
|
1632
|
-
let { children: t, ...i } = e;
|
|
1633
|
-
!i.namespaceURI && vi[r] === 0 && (i = {
|
|
1634
|
-
...i,
|
|
1635
|
-
namespaceURI: yi
|
|
1636
|
-
});
|
|
1637
|
-
let s;
|
|
1638
|
-
if (we(r)) {
|
|
1639
|
-
if (s = i.namespaceURI ? document.createElementNS(i.namespaceURI, r) : document.createElement(r), Ri(i, s), ae(t, s), s instanceof window.HTMLSelectElement && i.value != null)
|
|
1640
|
-
if (i.multiple === !0 && Array.isArray(i.value)) {
|
|
1641
|
-
const n = i.value.map((o) => String(o));
|
|
1642
|
-
s.querySelectorAll("option").forEach(
|
|
1643
|
-
(o) => o.selected = n.includes(o.value)
|
|
1644
|
-
);
|
|
1645
|
-
} else
|
|
1646
|
-
s.value = i.value;
|
|
1647
|
-
be(i.ref, s);
|
|
1648
|
-
} else if (G(r))
|
|
1649
|
-
M(r.defaultProps) && (i = {
|
|
1650
|
-
...r.defaultProps,
|
|
1651
|
-
...i
|
|
1652
|
-
}), s = hi(r) ? Ei(r, i, t) : r({
|
|
1653
|
-
...i,
|
|
1654
|
-
children: t
|
|
1655
|
-
});
|
|
1656
|
-
else
|
|
1657
|
-
throw new TypeError(`Invalid JSX element type: ${r}`);
|
|
1658
|
-
return s;
|
|
1659
|
-
}
|
|
1660
|
-
function be(r, e) {
|
|
1661
|
-
di(r) ? r.current = e : G(r) && r(e);
|
|
1662
|
-
}
|
|
1663
|
-
function ae(r, e) {
|
|
1664
|
-
if (ui(r))
|
|
1665
|
-
ki(r, e);
|
|
1666
|
-
else if (we(r) || tt(r))
|
|
1667
|
-
ce(document.createTextNode(r), e);
|
|
1668
|
-
else if (r === null)
|
|
1669
|
-
ce(document.createComment(""), e);
|
|
1670
|
-
else if (ci(r))
|
|
1671
|
-
ce(r, e);
|
|
1672
|
-
else if (mi(r)) {
|
|
1673
|
-
const t = e.attachShadow(r.attr);
|
|
1674
|
-
ae(r.children, t), be(r.ref, t);
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
function ki(r, e) {
|
|
1678
|
-
for (const t of [...r])
|
|
1679
|
-
ae(t, e);
|
|
1680
|
-
return e;
|
|
1681
|
-
}
|
|
1682
|
-
function ce(r, e) {
|
|
1683
|
-
e instanceof window.HTMLTemplateElement ? e.content.appendChild(r) : e.appendChild(r);
|
|
1684
|
-
}
|
|
1685
|
-
function Q(r, e) {
|
|
1686
|
-
return r.replace(/[A-Z]/g, (t) => e + t.toLowerCase());
|
|
1687
|
-
}
|
|
1688
|
-
function rt(r, e) {
|
|
1689
|
-
e == null || e === !1 || (Array.isArray(e) ? e.forEach((t) => rt(r, t)) : we(e) ? r.setAttribute("style", e) : M(e) && fe(e, (t, i) => {
|
|
1690
|
-
i.indexOf("-") === 0 ? r.style.setProperty(i, t) : tt(t) && ge[i] !== 0 ? r.style[i] = t + "px" : r.style[i] = t;
|
|
1691
|
-
}));
|
|
1692
|
-
}
|
|
1693
|
-
function $i(r, e, t) {
|
|
1694
|
-
switch (r) {
|
|
1695
|
-
case "xlinkActuate":
|
|
1696
|
-
case "xlinkArcrole":
|
|
1697
|
-
case "xlinkHref":
|
|
1698
|
-
case "xlinkRole":
|
|
1699
|
-
case "xlinkShow":
|
|
1700
|
-
case "xlinkTitle":
|
|
1701
|
-
case "xlinkType":
|
|
1702
|
-
De(t, wi, Q(r, ":"), e);
|
|
1703
|
-
return;
|
|
1704
|
-
case "xmlnsXlink":
|
|
1705
|
-
B(t, Q(r, ":"), e);
|
|
1706
|
-
return;
|
|
1707
|
-
case "xmlBase":
|
|
1708
|
-
case "xmlLang":
|
|
1709
|
-
case "xmlSpace":
|
|
1710
|
-
De(t, bi, Q(r, ":"), e);
|
|
1711
|
-
return;
|
|
1712
|
-
}
|
|
1713
|
-
switch (r) {
|
|
1714
|
-
case "htmlFor":
|
|
1715
|
-
B(t, "for", e);
|
|
1716
|
-
return;
|
|
1717
|
-
case "dataset":
|
|
1718
|
-
fe(e, (i, s) => {
|
|
1719
|
-
i != null && (t.dataset[s] = i);
|
|
1720
|
-
});
|
|
1721
|
-
return;
|
|
1722
|
-
case "innerHTML":
|
|
1723
|
-
case "innerText":
|
|
1724
|
-
case "textContent":
|
|
1725
|
-
st(e) && (t[r] = e);
|
|
1726
|
-
return;
|
|
1727
|
-
case "dangerouslySetInnerHTML":
|
|
1728
|
-
M(e) && (t.innerHTML = e.__html);
|
|
1729
|
-
return;
|
|
1730
|
-
case "value":
|
|
1731
|
-
if (e == null || t instanceof window.HTMLSelectElement)
|
|
1732
|
-
return;
|
|
1733
|
-
if (t instanceof window.HTMLTextAreaElement) {
|
|
1734
|
-
t.value = e;
|
|
1735
|
-
return;
|
|
1736
|
-
}
|
|
1737
|
-
break;
|
|
1738
|
-
case "spellCheck":
|
|
1739
|
-
t.spellcheck = e;
|
|
1740
|
-
return;
|
|
1741
|
-
case "class":
|
|
1742
|
-
case "className":
|
|
1743
|
-
G(e) ? e(t) : B(t, "class", pe(e));
|
|
1744
|
-
return;
|
|
1745
|
-
case "ref":
|
|
1746
|
-
case "namespaceURI":
|
|
1747
|
-
return;
|
|
1748
|
-
case "style":
|
|
1749
|
-
rt(t, e);
|
|
1750
|
-
return;
|
|
1751
|
-
case "on":
|
|
1752
|
-
case "onCapture":
|
|
1753
|
-
fe(e, (i, s) => {
|
|
1754
|
-
t.addEventListener(s, i, r === "onCapture");
|
|
1755
|
-
});
|
|
1756
|
-
return;
|
|
1757
|
-
}
|
|
1758
|
-
if (G(e)) {
|
|
1759
|
-
if (r[0] === "o" && r[1] === "n") {
|
|
1760
|
-
let i = r.toLowerCase();
|
|
1761
|
-
const s = i.endsWith("capture");
|
|
1762
|
-
if (i === "ondoubleclick" ? i = "ondblclick" : s && i === "ondoubleclickcapture" && (i = "ondblclickcapture"), !s && t[i] === null)
|
|
1763
|
-
t[i] = e;
|
|
1764
|
-
else if (s)
|
|
1765
|
-
t.addEventListener(
|
|
1766
|
-
i.substring(2, i.length - 7),
|
|
1767
|
-
e,
|
|
1768
|
-
!0
|
|
1769
|
-
);
|
|
1770
|
-
else {
|
|
1771
|
-
let n;
|
|
1772
|
-
i in window ? n = i.substring(2) : n = i[2] + r.slice(3), t.addEventListener(n, e);
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
} else M(e) ? t[r] = e : e === !0 ? B(t, r, "") : e !== !1 && e != null && (t instanceof SVGElement && !_i.test(r) ? B(t, Q(r, "-"), e) : B(t, r, e));
|
|
1776
|
-
}
|
|
1777
|
-
function B(r, e, t) {
|
|
1778
|
-
r.setAttribute(e, t);
|
|
1779
|
-
}
|
|
1780
|
-
function De(r, e, t, i) {
|
|
1781
|
-
r.setAttributeNS(e, t, i);
|
|
1782
|
-
}
|
|
1783
|
-
function Ri(r, e) {
|
|
1784
|
-
for (const t of oe(r))
|
|
1785
|
-
$i(t, r[t], e);
|
|
1786
|
-
return e;
|
|
1787
|
-
}
|
|
1788
|
-
var ve = /* @__PURE__ */ ((r) => (r.Init = "modal.init", r.BeforeShow = "modal.beforeShow", r.Show = "modal.show", r.BeforeClose = "modal.beforeClose", r.Close = "modal.close", r.Destroy = "modal.destroy", r.ToastShow = "toast.show", r.ToastClose = "toast.close", r))(ve || {});
|
|
1789
|
-
let xi = 0;
|
|
1790
|
-
const Me = (r) => `${r}-${++xi}`;
|
|
1791
|
-
function j(r) {
|
|
1792
|
-
return r instanceof Node ? r : document.createTextNode(String(r));
|
|
1793
|
-
}
|
|
1794
|
-
function T(r, e) {
|
|
1795
|
-
if (!r) throw new Error(`${e ?? "Element"} not found`);
|
|
1796
|
-
return r;
|
|
1797
|
-
}
|
|
1798
|
-
function Ue(r) {
|
|
1799
|
-
const e = [
|
|
1800
|
-
"a[href]",
|
|
1801
|
-
"button:not([disabled])",
|
|
1802
|
-
"input:not([disabled])",
|
|
1803
|
-
"select:not([disabled])",
|
|
1804
|
-
"textarea:not([disabled])",
|
|
1805
|
-
'[tabindex]:not([tabindex="-1"])'
|
|
1806
|
-
].join(",");
|
|
1807
|
-
return Array.from(r.querySelectorAll(e)).filter(
|
|
1808
|
-
(t) => !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length)
|
|
1809
|
-
);
|
|
1810
|
-
}
|
|
1811
|
-
function S(r, e = {}) {
|
|
1812
|
-
const t = document.createElement(r);
|
|
1813
|
-
if (e.className && (t.className = e.className), e.html != null && (t.innerHTML = e.html), e.text != null && (t.textContent = e.text), e.attrs)
|
|
1814
|
-
for (const [i, s] of Object.entries(e.attrs)) t.setAttribute(i, s);
|
|
1815
|
-
return t;
|
|
1816
|
-
}
|
|
1817
|
-
const Li = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform), nt = ["ctrl", "alt", "shift", "meta"];
|
|
1818
|
-
function Ai(r) {
|
|
1819
|
-
if (!r) return null;
|
|
1820
|
-
const e = String(r).trim().toLowerCase().split(/[+\-\s]+/g).filter(Boolean), t = [];
|
|
1821
|
-
let i = null;
|
|
1822
|
-
const s = (o) => {
|
|
1823
|
-
t.includes(o) || t.push(o);
|
|
1824
|
-
};
|
|
1825
|
-
for (const o of e) {
|
|
1826
|
-
let a = o;
|
|
1827
|
-
if (a === "control" || a === "ctrl") {
|
|
1828
|
-
s("ctrl");
|
|
1829
|
-
continue;
|
|
1830
|
-
}
|
|
1831
|
-
if (a === "alt" || a === "option") {
|
|
1832
|
-
s("alt");
|
|
1833
|
-
continue;
|
|
1834
|
-
}
|
|
1835
|
-
if (a === "shift") {
|
|
1836
|
-
s("shift");
|
|
1837
|
-
continue;
|
|
1838
|
-
}
|
|
1839
|
-
if (a === "meta" || a === "cmd" || a === "command" || a === "super") {
|
|
1840
|
-
s("meta");
|
|
1841
|
-
continue;
|
|
1842
|
-
}
|
|
1843
|
-
if (a === "mod") {
|
|
1844
|
-
s(Li ? "meta" : "ctrl");
|
|
1845
|
-
continue;
|
|
1846
|
-
}
|
|
1847
|
-
a === "esc" && (a = "escape"), a === "return" && (a = "enter"), (a === "space" || a === "spacebar") && (a = "space"), i = a;
|
|
1848
|
-
}
|
|
1849
|
-
const n = nt.filter((o) => t.includes(o));
|
|
1850
|
-
return !i || i === "" ? n.length ? n.join("+") : null : n.length ? `${n.join("+")}+${i}` : i;
|
|
1851
|
-
}
|
|
1852
|
-
function Ti(r) {
|
|
1853
|
-
const e = [];
|
|
1854
|
-
r.ctrlKey && e.push("ctrl"), r.altKey && e.push("alt"), r.shiftKey && e.push("shift"), r.metaKey && e.push("meta");
|
|
1855
|
-
let t = r.key;
|
|
1856
|
-
t === " " && (t = "space");
|
|
1857
|
-
const i = (t.length, t.toLowerCase()), s = nt.filter((n) => e.includes(n));
|
|
1858
|
-
return s.length ? `${s.join("+")}+${i}` : i;
|
|
1859
|
-
}
|
|
1860
|
-
class Ci {
|
|
1861
|
-
constructor() {
|
|
1862
|
-
this.zBase = 1e3, this.stack = [];
|
|
1863
|
-
}
|
|
1864
|
-
push(e) {
|
|
1865
|
-
this.stack.push(e), this.syncZ();
|
|
1866
|
-
}
|
|
1867
|
-
remove(e) {
|
|
1868
|
-
this.stack = this.stack.filter((t) => t !== e), this.syncZ();
|
|
1869
|
-
}
|
|
1870
|
-
top() {
|
|
1871
|
-
return this.stack[this.stack.length - 1];
|
|
1872
|
-
}
|
|
1873
|
-
closeAll(e, t) {
|
|
1874
|
-
const i = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), s = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
1875
|
-
[...this.stack].reverse().forEach((n) => {
|
|
1876
|
-
const o = n.modalId, a = s.size ? s.has(n.pluginName) : !0, c = i.has(o);
|
|
1877
|
-
a && !c && n.close();
|
|
1878
|
-
});
|
|
1879
|
-
}
|
|
1880
|
-
removeAll() {
|
|
1881
|
-
[...this.stack].forEach((e) => e.destroy()), this.stack = [];
|
|
1882
|
-
}
|
|
1883
|
-
syncZ() {
|
|
1884
|
-
this.stack.forEach((e, t) => e.setZIndex(this.zBase + t * 2));
|
|
1885
|
-
}
|
|
1886
|
-
lockBodyScroll() {
|
|
1887
|
-
document.body.classList.add("ipe-modal-no-scroll");
|
|
1888
|
-
}
|
|
1889
|
-
unlockBodyScroll() {
|
|
1890
|
-
document.body.classList.remove("ipe-modal-no-scroll");
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
const E = new Ci();
|
|
1894
|
-
class ee {
|
|
1895
|
-
constructor(e = {}) {
|
|
1896
|
-
this.backdropId = Me("ipe-modal-backdrop"), this.modalId = Me("ipe-modal"), this.numberId = this.modalId.split("-")[1], this._isDestroyed = !1, this.pluginName = "normalModal", this.buttonElsLeft = [], this.buttonElsRight = [], this.keyMap = /* @__PURE__ */ new Map(), this.isOpen = !1, this.isToast = !1, this.isDragging = !1, this.dragStartX = 0, this.dragStartY = 0, this.modalStartX = 0, this.modalStartY = 0, this.Event = ve, this._hooks = [], this.startCloseTimer = (t) => {
|
|
1897
|
-
this.stopCloseTimer(), this.closeTimer = window.setTimeout(() => this.close(), t);
|
|
1898
|
-
}, this.stopCloseTimer = () => {
|
|
1899
|
-
this.closeTimer && window.clearTimeout(this.closeTimer), this.closeTimer = void 0;
|
|
1900
|
-
}, this.onDragMove = (t) => {
|
|
1901
|
-
if (!this.isDragging) return;
|
|
1902
|
-
t.preventDefault();
|
|
1903
|
-
const i = t.clientX - this.dragStartX, s = t.clientY - this.dragStartY, n = this.get$modal(), o = this.modalStartX + i, a = this.modalStartY + s;
|
|
1904
|
-
n.style.left = `${o}px`, n.style.top = `${a}px`;
|
|
1905
|
-
}, this.onDragEnd = () => {
|
|
1906
|
-
if (!this.isDragging) return;
|
|
1907
|
-
this.isDragging = !1, document.removeEventListener("pointermove", this.onDragMove), document.removeEventListener("pointerup", this.onDragEnd);
|
|
1908
|
-
const t = this.get$modal(), i = this.get$window();
|
|
1909
|
-
t.classList.remove("is-dragging"), i.style.animation = "none", requestAnimationFrame(() => {
|
|
1910
|
-
this.applyAnimation(!0);
|
|
1911
|
-
});
|
|
1912
|
-
}, this.options = { ...ee.DEFAULT_OPTIONS, ...e }, this.options.backdrop === !1 && e.bodyScroll === void 0 && (this.options.bodyScroll = !0);
|
|
1913
|
-
}
|
|
1914
|
-
get isDestroyed() {
|
|
1915
|
-
return this._isDestroyed;
|
|
1916
|
-
}
|
|
1917
|
-
static {
|
|
1918
|
-
this.DEFAULT_OPTIONS = {
|
|
1919
|
-
className: "",
|
|
1920
|
-
sizeClass: "auto",
|
|
1921
|
-
center: !0,
|
|
1922
|
-
fitScreen: !1,
|
|
1923
|
-
closeIcon: !0,
|
|
1924
|
-
bodyScroll: !1,
|
|
1925
|
-
outSideClose: !0,
|
|
1926
|
-
backdrop: !0,
|
|
1927
|
-
animation: {
|
|
1928
|
-
show: "ipe-modal-fade-in",
|
|
1929
|
-
hide: "ipe-modal-fade-out"
|
|
1930
|
-
},
|
|
1931
|
-
animationSpeed: 200
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
static extends(e = {}) {
|
|
1935
|
-
return class extends this {
|
|
1936
|
-
constructor(t = {}) {
|
|
1937
|
-
super({ ...e, ...t });
|
|
1938
|
-
}
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
// ------------------------------ lifecycle ------------------------------ //
|
|
1942
|
-
init() {
|
|
1943
|
-
if (this.$modal) return this;
|
|
1944
|
-
const e = this.options.backdrop !== !1;
|
|
1945
|
-
let t;
|
|
1946
|
-
e && (t = S("div", {
|
|
1947
|
-
className: "ipe-modal-backdrop",
|
|
1948
|
-
attrs: { id: this.backdropId, "data-modal-id": this.modalId }
|
|
1949
|
-
}));
|
|
1950
|
-
const i = S("div", {
|
|
1951
|
-
className: "ipe-modal-modal",
|
|
1952
|
-
attrs: { id: this.modalId, role: "dialog", "aria-modal": "true", tabindex: "-1" }
|
|
1953
|
-
});
|
|
1954
|
-
if (i.modal = this, !e) {
|
|
1955
|
-
i.classList.add("no-backdrop");
|
|
1956
|
-
const f = window.pageYOffset || document.documentElement.scrollTop, g = window.pageXOffset || document.documentElement.scrollLeft, p = window.innerWidth;
|
|
1957
|
-
i.style.top = `${f + 60}px`, this.once("modal.show", () => {
|
|
1958
|
-
i.style.left = `${g + p / 2 - i.offsetWidth / 2}px`;
|
|
1959
|
-
});
|
|
1960
|
-
}
|
|
1961
|
-
const s = S("div", {
|
|
1962
|
-
className: `ipe-modal-modal__window size--${this.options.sizeClass || "auto"} plugin--${this.pluginName}`
|
|
1963
|
-
});
|
|
1964
|
-
s.modal = this;
|
|
1965
|
-
const n = S("div", { className: "ipe-modal-modal__header" }), o = `${this.modalId}-title`, a = S("h2", {
|
|
1966
|
-
className: "ipe-modal-modal__title",
|
|
1967
|
-
attrs: { id: o, role: "heading", "aria-level": "2" }
|
|
1968
|
-
});
|
|
1969
|
-
i.setAttribute("aria-labelledby", o);
|
|
1970
|
-
const c = S("div", { className: "ipe-modal-modal__icons" });
|
|
1971
|
-
if (this.options.closeIcon) {
|
|
1972
|
-
const f = S("button", {
|
|
1973
|
-
className: "ipe-modal-modal__close",
|
|
1974
|
-
attrs: { type: "button", "aria-label": "Close" },
|
|
1975
|
-
html: "×"
|
|
1976
|
-
});
|
|
1977
|
-
f.addEventListener("click", () => {
|
|
1978
|
-
let g = !0;
|
|
1979
|
-
typeof this.options.onClickClose == "function" ? this.options.onClickClose(this) === !1 && (g = !1) : this.options.onClickClose === !1 && (g = !1), g && this.close();
|
|
1980
|
-
}), c.appendChild(f);
|
|
1981
|
-
}
|
|
1982
|
-
n.append(a, c), this.options.draggable && e && (this.options.draggable = !1), this.options.draggable && (n.style.cursor = "move", n.style.userSelect = "none", n.addEventListener("pointerdown", this.onDragStart.bind(this)), i.classList.add("is-draggable"));
|
|
1983
|
-
const l = S("div", { className: "ipe-modal-modal__content" }), h = S("div", { className: "ipe-modal-modal__footer" }), d = S("div", {
|
|
1984
|
-
className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--left"
|
|
1985
|
-
}), u = S("div", {
|
|
1986
|
-
className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--right"
|
|
1987
|
-
});
|
|
1988
|
-
return h.append(d, u), s.append(n, l, h), i.appendChild(s), this.$backdrop = t, this.$modal = i, this.$window = s, this.$header = n, this.$title = a, this.$icons = c, this.$content = l, this.$footer = h, this.$buttonsLeft = d, this.$buttonsRight = u, this.options.title && this.setTitle(this.options.title), this.options.content && this.setContent(this.options.content), this.options.buttons?.length ? this.setButtons(this.options.buttons) : h.style.display = "none", this.options.center && this.$modal.classList.add("is-centered"), this.options.fitScreen && this.$modal.classList.add("is-fullscreen"), this.options.iconButtons && this.$header.classList.add("has-icon-buttons"), this.options.className && this.$window.classList.add(...this.options.className.split(/[\s\.#+]+/g).filter(Boolean)), typeof this.options.fixedHeight == "number" ? this.$window.style.height = `${Math.max(0, this.options.fixedHeight)}px` : this.options.fixedHeight === !0 && this.$window.classList.add("is-fixed-height"), t && t.addEventListener("pointerdown", (f) => {
|
|
1989
|
-
this.options.outSideClose && f.target === t && this.close();
|
|
1990
|
-
}), this.options.draggable && s.addEventListener("pointerdown", (f) => {
|
|
1991
|
-
f.target && s.contains(f.target) && this.bringToFront();
|
|
1992
|
-
}), this.onKeyDown = this.onKeyDown.bind(this), this.emit(
|
|
1993
|
-
"modal.init"
|
|
1994
|
-
/* Init */
|
|
1995
|
-
), this;
|
|
1996
|
-
}
|
|
1997
|
-
show() {
|
|
1998
|
-
if (this.$modal || this.init(), !this.$modal) throw new Error("Failed to initialize modal");
|
|
1999
|
-
if (this.isOpen) return this;
|
|
2000
|
-
{
|
|
2001
|
-
const i = this.emit("modal.beforeShow", !0), s = this.options.beforeShow ? this.options.beforeShow(this) !== !1 : !0;
|
|
2002
|
-
if (!i || !s) return this;
|
|
2003
|
-
}
|
|
2004
|
-
this.lastFocused = document.activeElement ?? null, this.$backdrop && document.body.appendChild(this.$backdrop), document.body.appendChild(this.$modal), this.shouldLockBodyOnOpen() && E.lockBodyScroll(), requestAnimationFrame(() => {
|
|
2005
|
-
this.$backdrop?.classList.add("is-open"), this.$modal.classList.add("is-open"), this.applyAnimation(!0), this.focusFirst();
|
|
2006
|
-
}), document.addEventListener("keydown", this.onKeyDown), E.push(this), this.isOpen = !0, this.options.onShow?.(this), this.emit(
|
|
2007
|
-
"modal.show"
|
|
2008
|
-
/* Show */
|
|
2009
|
-
);
|
|
2010
|
-
const e = typeof this.options.closeAfter == "number" ? this.options.closeAfter : this.options.closeAfter?.time, t = typeof this.options.closeAfter == "number" ? !0 : this.options.closeAfter?.resetOnHover;
|
|
2011
|
-
return e && (this.startCloseTimer(e), t && (this.$window?.addEventListener("mouseenter", this.stopCloseTimer), this.$window?.addEventListener("mouseleave", () => this.startCloseTimer(e)))), this;
|
|
2012
|
-
}
|
|
2013
|
-
close() {
|
|
2014
|
-
if (!this.isOpen) return this;
|
|
2015
|
-
{
|
|
2016
|
-
const n = this.emit("modal.beforeClose", !0), o = this.options.beforeClose ? this.options.beforeClose(this) !== !1 : !0;
|
|
2017
|
-
if (!n || !o) return this;
|
|
2018
|
-
}
|
|
2019
|
-
if (this.isToast) {
|
|
2020
|
-
this.applyAnimation(!1), this.emit(
|
|
2021
|
-
"modal.close"
|
|
2022
|
-
/* Close */
|
|
2023
|
-
), this.emit(
|
|
2024
|
-
"toast.close"
|
|
2025
|
-
/* ToastClose */
|
|
2026
|
-
);
|
|
2027
|
-
const n = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
|
|
2028
|
-
let o = !1;
|
|
2029
|
-
const a = () => {
|
|
2030
|
-
o || (o = !0, this.destroy(), this.options.onClose?.(this));
|
|
2031
|
-
}, c = (l, h) => {
|
|
2032
|
-
const d = () => {
|
|
2033
|
-
l.removeEventListener(h, d), a();
|
|
2034
|
-
};
|
|
2035
|
-
l.addEventListener(h, d, { once: !0 });
|
|
2036
|
-
};
|
|
2037
|
-
return n > 0 && this.$window ? (c(this.$window, "transitionend"), c(this.$window, "animationend"), window.setTimeout(a, n + 20)) : window.setTimeout(a, n), this;
|
|
2038
|
-
}
|
|
2039
|
-
this.applyAnimation(!1), this.$backdrop?.classList.remove("is-open"), this.$modal?.classList.remove("is-open"), this.emit(
|
|
2040
|
-
"modal.close"
|
|
2041
|
-
/* Close */
|
|
2042
|
-
);
|
|
2043
|
-
const e = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
|
|
2044
|
-
let t = !1;
|
|
2045
|
-
const i = () => {
|
|
2046
|
-
t || (t = !0, this.destroy(), this.options.onClose?.(this));
|
|
2047
|
-
}, s = (n, o) => {
|
|
2048
|
-
const a = () => {
|
|
2049
|
-
n.removeEventListener(o, a), i();
|
|
2050
|
-
};
|
|
2051
|
-
n.addEventListener(o, a, { once: !0 });
|
|
2052
|
-
};
|
|
2053
|
-
return e > 0 && this.$window ? (s(this.$window, "transitionend"), s(this.$window, "animationend"), window.setTimeout(i, e + 20)) : window.setTimeout(i, e), this;
|
|
2054
|
-
}
|
|
2055
|
-
/** Immediately removes DOM and listeners */
|
|
2056
|
-
destroy() {
|
|
2057
|
-
if (this._isDestroyed) return this;
|
|
2058
|
-
if (this.stopCloseTimer(), document.removeEventListener("keydown", this.onKeyDown), this.isDragging && this.onDragEnd(), this.$window?.removeEventListener("mouseenter", this.stopCloseTimer), this.isToast) {
|
|
2059
|
-
this.$window?.parentElement && this.$window.parentElement.removeChild(this.$window);
|
|
2060
|
-
const e = P.indexOf(this);
|
|
2061
|
-
e !== -1 && P.splice(e, 1);
|
|
2062
|
-
} else
|
|
2063
|
-
this.$backdrop?.parentElement && this.$backdrop.parentElement.removeChild(this.$backdrop), this.$modal?.parentElement && this.$modal.parentElement.removeChild(this.$modal), E.remove(this), this.shouldUnlockBodyOnClose() && E.unlockBodyScroll();
|
|
2064
|
-
return this.isOpen = !1, this.lastFocused?.focus?.(), this.emit(
|
|
2065
|
-
"modal.destroy"
|
|
2066
|
-
/* Destroy */
|
|
2067
|
-
), this._isDestroyed = !0, this;
|
|
2068
|
-
}
|
|
2069
|
-
// ------------------------------ getters ------------------------------- //
|
|
2070
|
-
get$backdrop() {
|
|
2071
|
-
return this.$backdrop;
|
|
2072
|
-
}
|
|
2073
|
-
get$modal() {
|
|
2074
|
-
return T(this.$modal, "modal");
|
|
2075
|
-
}
|
|
2076
|
-
get$window() {
|
|
2077
|
-
return T(this.$window, "window");
|
|
2078
|
-
}
|
|
2079
|
-
get$header() {
|
|
2080
|
-
return T(this.$header, "header");
|
|
2081
|
-
}
|
|
2082
|
-
get$title() {
|
|
2083
|
-
return T(this.$title, "title");
|
|
2084
|
-
}
|
|
2085
|
-
get$content() {
|
|
2086
|
-
return T(this.$content, "content");
|
|
2087
|
-
}
|
|
2088
|
-
get$icons() {
|
|
2089
|
-
return T(this.$icons, "icons");
|
|
2090
|
-
}
|
|
2091
|
-
get$buttons(e) {
|
|
2092
|
-
return e === "leftButtons" ? T(this.$buttonsLeft, "leftButtons") : e === "rightButtons" ? T(this.$buttonsRight, "rightButtons") : T(this.$footer, "buttons");
|
|
2093
|
-
}
|
|
2094
|
-
// ------------------------------ content ------------------------------- //
|
|
2095
|
-
setTitle(e) {
|
|
2096
|
-
const t = this.get$title();
|
|
2097
|
-
return t.innerHTML = "", t.append(j(e)), this;
|
|
2098
|
-
}
|
|
2099
|
-
setContent(e, t = "replace") {
|
|
2100
|
-
const i = this.get$content();
|
|
2101
|
-
return t === "replace" ? (i.innerHTML = "", i.append(j(e))) : t === "append" ? i.append(j(e)) : i.prepend(j(e)), this;
|
|
2102
|
-
}
|
|
2103
|
-
setIcons(e) {
|
|
2104
|
-
const t = this.get$icons();
|
|
2105
|
-
t.innerHTML = "";
|
|
2106
|
-
for (const i of e) {
|
|
2107
|
-
const s = S("button", {
|
|
2108
|
-
className: `ipe-modal-modal__icon ${i.className}`,
|
|
2109
|
-
attrs: { type: "button" }
|
|
2110
|
-
});
|
|
2111
|
-
s.addEventListener("click", i.method), t.appendChild(s);
|
|
2112
|
-
}
|
|
2113
|
-
return this;
|
|
2114
|
-
}
|
|
2115
|
-
setButtons(e, t) {
|
|
2116
|
-
const i = this.$buttonsLeft, s = this.$buttonsRight;
|
|
2117
|
-
[i, s].forEach((o) => o.innerHTML = ""), this.buttonElsLeft = [], this.buttonElsRight = [], this.keyMap.clear();
|
|
2118
|
-
const n = t ?? this.$footer;
|
|
2119
|
-
if (n === this.$footer)
|
|
2120
|
-
e.forEach((o) => this.addButton(o)), e.length === 0 && (this.$footer.style.display = "none");
|
|
2121
|
-
else {
|
|
2122
|
-
n.innerHTML = "";
|
|
2123
|
-
for (const o of e) {
|
|
2124
|
-
const a = this.generateButton(o);
|
|
2125
|
-
n.appendChild(a);
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
return this;
|
|
2129
|
-
}
|
|
2130
|
-
generateButton(e) {
|
|
2131
|
-
const t = e.type ?? "button", i = t === "link" ? S("a") : S("button", { attrs: { type: "button" } });
|
|
2132
|
-
e.id && (i.id = e.id), i.className = `ipe-modal-btn ${e.className ?? ""}`.trim();
|
|
2133
|
-
const s = j(e.label ?? "OK");
|
|
2134
|
-
if (i.append(s), t === "link" && e.href && (i.href = e.href), e.method && i.addEventListener("click", (n) => {
|
|
2135
|
-
if (i._ipe_tmpDisabled) {
|
|
2136
|
-
n.preventDefault(), n.stopPropagation();
|
|
2137
|
-
return;
|
|
2138
|
-
}
|
|
2139
|
-
e.method.call(i, n, this);
|
|
2140
|
-
}), typeof e.closeAfter == "number" && e.closeAfter >= 0 && i.addEventListener("click", () => {
|
|
2141
|
-
window.setTimeout(() => this.close(), e.closeAfter);
|
|
2142
|
-
}), typeof e.enableAfter == "number" && e.enableAfter > 0) {
|
|
2143
|
-
t === "button" && i.setAttribute("disabled", "true"), i._ipe_tmpDisabled = !0, i.setAttribute("aria-disabled", "true");
|
|
2144
|
-
const n = () => {
|
|
2145
|
-
t === "button" && i.removeAttribute("disabled"), delete i._ipe_tmpDisabled, i.removeAttribute("aria-disabled");
|
|
2146
|
-
};
|
|
2147
|
-
window.setTimeout(n, e.enableAfter);
|
|
2148
|
-
}
|
|
2149
|
-
if (e.keyPress) {
|
|
2150
|
-
const n = String(e.keyPress).split(/[\,\|]+/g).map((o) => o.trim()).filter(Boolean);
|
|
2151
|
-
for (const o of n) {
|
|
2152
|
-
const a = Ai(o);
|
|
2153
|
-
a && this.keyMap.set(a, i);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
return i;
|
|
2157
|
-
}
|
|
2158
|
-
/** Dynamically add button(s) into footer. Supports insertion index per side. */
|
|
2159
|
-
addButton(e, t) {
|
|
2160
|
-
this.$footer && (this.$footer.style.display = "");
|
|
2161
|
-
const i = e.side ?? "right", s = i === "left" ? this.$buttonsLeft : this.$buttonsRight, n = i === "left" ? this.buttonElsLeft : this.buttonElsRight, o = this.generateButton(e), a = Math.max(0, Math.min(t ?? n.length, n.length));
|
|
2162
|
-
return a >= s.children.length ? s.appendChild(o) : s.insertBefore(o, s.children[a]), n.splice(a, 0, o), this;
|
|
2163
|
-
}
|
|
2164
|
-
/** Remove button by element / id / global index (left first, then right). */
|
|
2165
|
-
removeButton(e) {
|
|
2166
|
-
const t = this.buttonElsLeft, i = this.buttonElsRight, s = [...t, ...i];
|
|
2167
|
-
let n = null;
|
|
2168
|
-
if (e === "*")
|
|
2169
|
-
return s.forEach((a) => {
|
|
2170
|
-
this.keyMap.delete(a.id), a.parentElement?.removeChild(a);
|
|
2171
|
-
}), this.$footer && (this.$footer.style.display = "none"), this;
|
|
2172
|
-
if (typeof e == "number" ? n = s[e] ?? null : typeof e == "string" ? n = s.find((a) => a.id === e) ?? null : e instanceof HTMLElement && (n = s.find((a) => a === e) ?? null), !n) return this;
|
|
2173
|
-
for (const [a, c] of this.keyMap.entries()) c === n && this.keyMap.delete(a);
|
|
2174
|
-
let o = t.indexOf(n);
|
|
2175
|
-
return o !== -1 ? (t.splice(o, 1), n.parentElement?.removeChild(n)) : (o = i.indexOf(n), o !== -1 && (i.splice(o, 1), n.parentElement?.removeChild(n))), t.length === 0 && i.length === 0 && this.$footer && (this.$footer.style.display = "none"), this;
|
|
2176
|
-
}
|
|
2177
|
-
changePreviewState() {
|
|
2178
|
-
return this.get$modal().classList.toggle("is-fullscreen"), this;
|
|
2179
|
-
}
|
|
2180
|
-
setModalHeight(e, t = "height") {
|
|
2181
|
-
const i = this.get$window(), s = Math.max(0, window.innerHeight - e);
|
|
2182
|
-
return i.style[t] = `${s}px`, s;
|
|
2183
|
-
}
|
|
2184
|
-
setOptions(e, t) {
|
|
2185
|
-
return typeof e == "string" ? this.options[e] = t : Object.assign(this.options, e), this;
|
|
2186
|
-
}
|
|
2187
|
-
setPluginName(e) {
|
|
2188
|
-
return this.$window && (this.$window.className = this.$window.className.replace(
|
|
2189
|
-
`plugin--${this.pluginName}`,
|
|
2190
|
-
`plugin--${e}`
|
|
2191
|
-
)), this.pluginName = e, this;
|
|
2192
|
-
}
|
|
2193
|
-
// ------------------------------ helpers ------------------------------- //
|
|
2194
|
-
applyAnimation(e) {
|
|
2195
|
-
const t = this.get$modal(), i = this.get$window(), s = this.$backdrop, n = this.options.modalAnimation ?? this.options.animation, o = typeof n == "string" ? n : n && (e ? n.show : n.hide), a = this.options.backdropAnimation ?? this.options.animation, c = typeof a == "string" ? a : a && (e ? a.show : a.hide);
|
|
2196
|
-
!o || o === !1 ? (t.style.transition = "none", i.style.animation = "none", i.style.removeProperty("--ipe-modal-anim")) : (t.style.removeProperty("transition"), i.style.setProperty("--ipe-modal-anim", o)), s && (!c || c === !1 ? s.style.transition = "none" : s.style.removeProperty("transition"));
|
|
2197
|
-
}
|
|
2198
|
-
on(e, t) {
|
|
2199
|
-
return this._hooks.push({ type: e, listener: t }), () => this.off(e, t);
|
|
2200
|
-
}
|
|
2201
|
-
off(e, t) {
|
|
2202
|
-
return this._hooks = this._hooks.filter(
|
|
2203
|
-
(i) => i.type !== e && (t ? i.listener !== t : !0)
|
|
2204
|
-
), this;
|
|
2205
|
-
}
|
|
2206
|
-
once(e, t) {
|
|
2207
|
-
const i = this.on(e, (s) => (i(), t(s)));
|
|
2208
|
-
return i;
|
|
2209
|
-
}
|
|
2210
|
-
emit(e, t) {
|
|
2211
|
-
const i = this._hooks.filter((a) => a.type === e);
|
|
2212
|
-
let s = !0;
|
|
2213
|
-
for (const a of i) {
|
|
2214
|
-
const c = new CustomEvent(e, { detail: this, cancelable: t }), l = a.listener(c);
|
|
2215
|
-
if (c.defaultPrevented && (s = !1), l === !1 && (s = !1), !s) break;
|
|
2216
|
-
}
|
|
2217
|
-
const n = this.$modal ?? document.body, o = new CustomEvent(e, { detail: this, cancelable: t });
|
|
2218
|
-
return (!n.dispatchEvent(o) || o.defaultPrevented) && (s = !1), s;
|
|
2219
|
-
}
|
|
2220
|
-
focusFirst() {
|
|
2221
|
-
const e = this.get$modal(), t = Ue(e);
|
|
2222
|
-
t.length ? t[0].focus() : e.focus({ preventScroll: !0 });
|
|
2223
|
-
}
|
|
2224
|
-
onKeyDown(e) {
|
|
2225
|
-
if (E.top() !== this) return;
|
|
2226
|
-
if (e.key === "Escape") {
|
|
2227
|
-
e.preventDefault(), this.close();
|
|
2228
|
-
return;
|
|
2229
|
-
}
|
|
2230
|
-
const t = this.get$modal();
|
|
2231
|
-
if (!t.contains(document.activeElement)) return;
|
|
2232
|
-
if (e.key === "Tab") {
|
|
2233
|
-
const a = Ue(t);
|
|
2234
|
-
if (!a.length) return;
|
|
2235
|
-
const c = a[0], l = a[a.length - 1], h = document.activeElement;
|
|
2236
|
-
e.shiftKey && h === c ? (e.preventDefault(), l.focus()) : !e.shiftKey && h === l && (e.preventDefault(), c.focus());
|
|
2237
|
-
}
|
|
2238
|
-
const i = e.ctrlKey || e.altKey || e.metaKey, s = e.target;
|
|
2239
|
-
if (!i && (s && ["INPUT", "TEXTAREA"].includes(s.tagName) || s.contentEditable === "true"))
|
|
2240
|
-
return;
|
|
2241
|
-
const n = Ti(e), o = this.keyMap.get(n);
|
|
2242
|
-
if (o) {
|
|
2243
|
-
e.preventDefault(), o.click();
|
|
2244
|
-
return;
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
setZIndex(e) {
|
|
2248
|
-
this.$backdrop && (this.$backdrop.style.zIndex = String(e)), this.$modal && (this.$modal.style.zIndex = String(e + 1));
|
|
2249
|
-
}
|
|
2250
|
-
/** Bring this modal to the top of the stack. */
|
|
2251
|
-
bringToFront() {
|
|
2252
|
-
return E.remove(this), E.push(this), this;
|
|
2253
|
-
}
|
|
2254
|
-
isAnimationDisabled() {
|
|
2255
|
-
const e = this.options.modalAnimation ?? this.options.animation;
|
|
2256
|
-
return e === !1 || e == null;
|
|
2257
|
-
}
|
|
2258
|
-
shouldLockBodyOnOpen() {
|
|
2259
|
-
return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !E.stack.some(
|
|
2260
|
-
(e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
|
|
2261
|
-
);
|
|
2262
|
-
}
|
|
2263
|
-
shouldUnlockBodyOnClose() {
|
|
2264
|
-
return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !E.stack.some(
|
|
2265
|
-
(e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
|
|
2266
|
-
);
|
|
2267
|
-
}
|
|
2268
|
-
// ------------------------------ drag handlers ------------------------------- //
|
|
2269
|
-
onDragStart(e) {
|
|
2270
|
-
if (this.options.backdrop !== !1 || !this.options.draggable) return;
|
|
2271
|
-
e.preventDefault(), this.isDragging = !0, this.bringToFront(), this.dragStartX = e.clientX, this.dragStartY = e.clientY;
|
|
2272
|
-
const t = this.get$modal(), i = t.getBoundingClientRect();
|
|
2273
|
-
this.modalStartX = i.left + window.pageXOffset, this.modalStartY = i.top + window.pageYOffset, t.style.transform = "none", t.style.left = `${this.modalStartX}px`, t.style.top = `${this.modalStartY}px`, document.addEventListener("pointermove", this.onDragMove), document.addEventListener("pointerup", this.onDragEnd), t.classList.add("is-dragging");
|
|
2274
|
-
}
|
|
2275
|
-
// ------------------------------ toast ------------------------------- //
|
|
2276
|
-
/** Show as toast (no backdrop, container stack). */
|
|
2277
|
-
showToast(e) {
|
|
2278
|
-
this.$window || this.init();
|
|
2279
|
-
const t = Oi(e.position ?? "top right"), i = this.get$window();
|
|
2280
|
-
this.isToast = !0, i.style.pointerEvents = "auto", this.applyAnimation(!0), t.appendChild(i);
|
|
2281
|
-
const s = (typeof this.options.closeAfter == "number" ? this.options.closeAfter : this.options.closeAfter?.time) ?? 3e3, n = (typeof this.options.closeAfter == "number" ? !0 : this.options.closeAfter?.resetOnHover) ?? !0;
|
|
2282
|
-
return s > 0 && (this.startCloseTimer(s), n && (i.addEventListener("mouseenter", this.stopCloseTimer), i.addEventListener("mouseleave", () => this.startCloseTimer(s)))), this.isOpen = !0, this.options.onShow?.(this), P.push(this), this.emit(
|
|
2283
|
-
"toast.show"
|
|
2284
|
-
/* ToastShow */
|
|
2285
|
-
), this.emit(
|
|
2286
|
-
"modal.show"
|
|
2287
|
-
/* Show */
|
|
2288
|
-
), this;
|
|
2289
|
-
}
|
|
2290
|
-
// ------------------------------ static helpers --------------------------- //
|
|
2291
|
-
static show(e, t) {
|
|
2292
|
-
return new this(e).init().show();
|
|
2293
|
-
}
|
|
2294
|
-
static createObject(e, t) {
|
|
2295
|
-
return new this(e);
|
|
2296
|
-
}
|
|
2297
|
-
static close(e) {
|
|
2298
|
-
if (!e) {
|
|
2299
|
-
const n = E.top();
|
|
2300
|
-
return n?.close(), n;
|
|
2301
|
-
}
|
|
2302
|
-
const t = typeof e == "string" ? e : e.id, i = E.stack.find((n) => n.modalId === t);
|
|
2303
|
-
if (i)
|
|
2304
|
-
return i.close(), i;
|
|
2305
|
-
const s = P.find((n) => n.modalId === t);
|
|
2306
|
-
return s?.close(), s;
|
|
2307
|
-
}
|
|
2308
|
-
static closeAll(e, t) {
|
|
2309
|
-
const i = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), s = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
2310
|
-
return E.closeAll(e, t), [...P].forEach((n) => {
|
|
2311
|
-
const o = n.modalId, a = s.size ? s.has(n.pluginName) : !0, c = i.has(o);
|
|
2312
|
-
a && !c && n.close();
|
|
2313
|
-
}), E.top() ?? new ee();
|
|
2314
|
-
}
|
|
2315
|
-
static removeAll() {
|
|
2316
|
-
E.removeAll(), [...P].forEach((e) => e.destroy());
|
|
2317
|
-
}
|
|
2318
|
-
static dialog(e, t) {
|
|
2319
|
-
const i = new this({
|
|
2320
|
-
sizeClass: "dialog",
|
|
2321
|
-
buttons: [
|
|
2322
|
-
{
|
|
2323
|
-
label: "OK",
|
|
2324
|
-
className: "is-primary is-ghost",
|
|
2325
|
-
method: (s, n) => {
|
|
2326
|
-
t?.(s, n), s.defaultPrevented || i.close();
|
|
2327
|
-
},
|
|
2328
|
-
keyPress: "Enter"
|
|
2329
|
-
}
|
|
2330
|
-
],
|
|
2331
|
-
...e
|
|
2332
|
-
});
|
|
2333
|
-
return i.init().show();
|
|
2334
|
-
}
|
|
2335
|
-
static confirm(e, t) {
|
|
2336
|
-
e.title ??= "Confirm", e.content ??= "Are you sure you want to perform this action?";
|
|
2337
|
-
const i = e.okBtn ?? { label: "OK", className: "is-primary is-ghost" }, s = e.cancelBtn ?? { label: "Cancel", className: "is-danger is-ghost" };
|
|
2338
|
-
return new this({
|
|
2339
|
-
sizeClass: "dialog",
|
|
2340
|
-
...e,
|
|
2341
|
-
buttons: [
|
|
2342
|
-
{
|
|
2343
|
-
label: s.label,
|
|
2344
|
-
className: s.className,
|
|
2345
|
-
keyPress: "n",
|
|
2346
|
-
method: (n, o) => {
|
|
2347
|
-
t?.(!1, o, n), o.close();
|
|
2348
|
-
}
|
|
2349
|
-
},
|
|
2350
|
-
{
|
|
2351
|
-
label: i.label,
|
|
2352
|
-
className: i.className,
|
|
2353
|
-
keyPress: "y",
|
|
2354
|
-
method: (n, o) => {
|
|
2355
|
-
t?.(!0, o, n), n.defaultPrevented || o.close();
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
]
|
|
2359
|
-
}).init().show();
|
|
2360
|
-
}
|
|
2361
|
-
static getDefaultNotifyIcon(e) {
|
|
2362
|
-
switch (e) {
|
|
2363
|
-
case "success":
|
|
2364
|
-
return /* @__PURE__ */ w(
|
|
2365
|
-
"svg",
|
|
2366
|
-
{
|
|
2367
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2368
|
-
width: "24",
|
|
2369
|
-
height: "24",
|
|
2370
|
-
viewBox: "0 0 24 24",
|
|
2371
|
-
fill: "currentColor",
|
|
2372
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-circle-check",
|
|
2373
|
-
children: [
|
|
2374
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2375
|
-
/* @__PURE__ */ w("path", { d: "M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z" })
|
|
2376
|
-
]
|
|
2377
|
-
}
|
|
2378
|
-
);
|
|
2379
|
-
case "error":
|
|
2380
|
-
return /* @__PURE__ */ w(
|
|
2381
|
-
"svg",
|
|
2382
|
-
{
|
|
2383
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2384
|
-
width: "24",
|
|
2385
|
-
height: "24",
|
|
2386
|
-
viewBox: "0 0 24 24",
|
|
2387
|
-
fill: "currentColor",
|
|
2388
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-triangle",
|
|
2389
|
-
children: [
|
|
2390
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2391
|
-
/* @__PURE__ */ w("path", { d: "M12 1.67c.955 0 1.845 .467 2.39 1.247l.105 .16l8.114 13.548a2.914 2.914 0 0 1 -2.307 4.363l-.195 .008h-16.225a2.914 2.914 0 0 1 -2.582 -4.2l.099 -.185l8.11 -13.538a2.914 2.914 0 0 1 2.491 -1.403zm.01 13.33l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -7a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" })
|
|
2392
|
-
]
|
|
2393
|
-
}
|
|
2394
|
-
);
|
|
2395
|
-
case "warning":
|
|
2396
|
-
return /* @__PURE__ */ w(
|
|
2397
|
-
"svg",
|
|
2398
|
-
{
|
|
2399
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2400
|
-
width: "24",
|
|
2401
|
-
height: "24",
|
|
2402
|
-
viewBox: "0 0 24 24",
|
|
2403
|
-
fill: "currentColor",
|
|
2404
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-circle",
|
|
2405
|
-
children: [
|
|
2406
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2407
|
-
/* @__PURE__ */ w("path", { d: "M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" })
|
|
2408
|
-
]
|
|
2409
|
-
}
|
|
2410
|
-
);
|
|
2411
|
-
case "info":
|
|
2412
|
-
return /* @__PURE__ */ w(
|
|
2413
|
-
"svg",
|
|
2414
|
-
{
|
|
2415
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2416
|
-
width: "24",
|
|
2417
|
-
height: "24",
|
|
2418
|
-
viewBox: "0 0 24 24",
|
|
2419
|
-
fill: "currentColor",
|
|
2420
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-info-circle",
|
|
2421
|
-
children: [
|
|
2422
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2423
|
-
/* @__PURE__ */ w("path", { d: "M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 9h-1l-.117 .007a1 1 0 0 0 0 1.986l.117 .007v3l.007 .117a1 1 0 0 0 .876 .876l.117 .007h1l.117 -.007a1 1 0 0 0 .876 -.876l.007 -.117l-.007 -.117a1 1 0 0 0 -.764 -.857l-.112 -.02l-.117 -.006v-3l-.007 -.117a1 1 0 0 0 -.876 -.876l-.117 -.007zm.01 -3l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007z" })
|
|
2424
|
-
]
|
|
2425
|
-
}
|
|
2426
|
-
);
|
|
2427
|
-
case "dialog":
|
|
2428
|
-
return /* @__PURE__ */ w(
|
|
2429
|
-
"svg",
|
|
2430
|
-
{
|
|
2431
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2432
|
-
width: "24",
|
|
2433
|
-
height: "24",
|
|
2434
|
-
viewBox: "0 0 24 24",
|
|
2435
|
-
fill: "none",
|
|
2436
|
-
stroke: "currentColor",
|
|
2437
|
-
"stroke-width": "2",
|
|
2438
|
-
"stroke-linecap": "round",
|
|
2439
|
-
"stroke-linejoin": "round",
|
|
2440
|
-
class: "icon icon-tabler icons-tabler-outline icon-tabler-message-dots",
|
|
2441
|
-
children: [
|
|
2442
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2443
|
-
/* @__PURE__ */ w("path", { d: "M12 11v.01" }),
|
|
2444
|
-
/* @__PURE__ */ w("path", { d: "M8 11v.01" }),
|
|
2445
|
-
/* @__PURE__ */ w("path", { d: "M16 11v.01" }),
|
|
2446
|
-
/* @__PURE__ */ w("path", { d: "M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3z" })
|
|
2447
|
-
]
|
|
2448
|
-
}
|
|
2449
|
-
);
|
|
2450
|
-
case "confirm":
|
|
2451
|
-
return /* @__PURE__ */ w(
|
|
2452
|
-
"svg",
|
|
2453
|
-
{
|
|
2454
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2455
|
-
width: "24",
|
|
2456
|
-
height: "24",
|
|
2457
|
-
viewBox: "0 0 24 24",
|
|
2458
|
-
fill: "currentColor",
|
|
2459
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-copy-check",
|
|
2460
|
-
children: [
|
|
2461
|
-
/* @__PURE__ */ w("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2462
|
-
/* @__PURE__ */ w("path", { d: "M18.333 6a3.667 3.667 0 0 1 3.667 3.667v8.666a3.667 3.667 0 0 1 -3.667 3.667h-8.666a3.667 3.667 0 0 1 -3.667 -3.667v-8.666a3.667 3.667 0 0 1 3.667 -3.667zm-3.333 -4c1.094 0 1.828 .533 2.374 1.514a1 1 0 1 1 -1.748 .972c-.221 -.398 -.342 -.486 -.626 -.486h-10c-.548 0 -1 .452 -1 1v9.998c0 .32 .154 .618 .407 .805l.1 .065a1 1 0 1 1 -.99 1.738a3 3 0 0 1 -1.517 -2.606v-10c0 -1.652 1.348 -3 3 -3zm1.293 9.293l-3.293 3.292l-1.293 -1.292a1 1 0 0 0 -1.414 1.414l2 2a1 1 0 0 0 1.414 0l4 -4a1 1 0 0 0 -1.414 -1.414" })
|
|
2463
|
-
]
|
|
2464
|
-
}
|
|
2465
|
-
);
|
|
2466
|
-
default:
|
|
2467
|
-
return null;
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
static notify(e, t, i) {
|
|
2471
|
-
if (t?.overrideOther && [...P].forEach((a) => a.close()), typeof t.title > "u") {
|
|
2472
|
-
const a = e || "Notification";
|
|
2473
|
-
t.title = a[0].toUpperCase() + a.slice(1).toLowerCase();
|
|
2474
|
-
}
|
|
2475
|
-
const s = t.icon ?? this.getDefaultNotifyIcon(e);
|
|
2476
|
-
s && (s instanceof Element && s.classList.add("ipe-modal-notify-icon"), t.title = /* @__PURE__ */ w(Si, { children: [
|
|
2477
|
-
s,
|
|
2478
|
-
t.title
|
|
2479
|
-
] })), e === "confirm" && (typeof t.closeAfter > "u" && (t.closeAfter = 0), t.okBtn || (t.okBtn = { label: "OK" })), t.okBtn && (typeof t.okBtn != "object" && (t.okBtn = { label: "OK" }), t.okBtn.label ??= "OK", t.okBtn.className ??= "is-primary is-text ok-btn", t.okBtn.method = (a, c) => {
|
|
2480
|
-
i?.(!0, c, a), c.close();
|
|
2481
|
-
}), t.cancelBtn && (typeof t.cancelBtn != "object" && (t.cancelBtn = { label: "Cancel" }), t.cancelBtn.label ??= "Cancel", t.cancelBtn.className ??= "is-danger is-text cancel-btn", t.cancelBtn.method = (a, c) => {
|
|
2482
|
-
i?.(!1, c, a), c.close();
|
|
2483
|
-
}), t.buttons = [t.cancelBtn, t.okBtn, ...t.buttons ?? []].filter(
|
|
2484
|
-
Boolean
|
|
2485
|
-
);
|
|
2486
|
-
const n = `is-notify type-${e || "default"} ${t.className ?? ""}`, o = new this({
|
|
2487
|
-
...t,
|
|
2488
|
-
className: n,
|
|
2489
|
-
sizeClass: "auto",
|
|
2490
|
-
center: !1,
|
|
2491
|
-
fitScreen: !1,
|
|
2492
|
-
closeIcon: !0,
|
|
2493
|
-
outSideClose: !1,
|
|
2494
|
-
bodyScroll: !0,
|
|
2495
|
-
buttons: t.buttons ?? []
|
|
2496
|
-
});
|
|
2497
|
-
return o.setPluginName("toast"), o.showToast({
|
|
2498
|
-
position: t.position ?? "top right"
|
|
2499
|
-
});
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
const P = [];
|
|
2503
|
-
function Oi(r = "top right") {
|
|
2504
|
-
const e = "ipe-modal-toast-container", t = `${e}-${r.replace(/[\s-\.|\/]+/g, "-")}`;
|
|
2505
|
-
let i = document.getElementById(t);
|
|
2506
|
-
return i || (i = S("div", {
|
|
2507
|
-
className: `${e} ${r}`,
|
|
2508
|
-
attrs: { id: t, "data-position": r }
|
|
2509
|
-
}), document.body.appendChild(i)), i;
|
|
2510
|
-
}
|
|
2511
|
-
class v extends ee {
|
|
2512
|
-
constructor(e = {}) {
|
|
2513
|
-
e.className ||= "", e.className += " theme-ipe", e.modalAnimation ||= {
|
|
2514
|
-
show: "ipe-modal-fade-in",
|
|
2515
|
-
hide: "ipe-modal-fade-out"
|
|
2516
|
-
}, super(e);
|
|
2517
|
-
}
|
|
2518
|
-
setLoadingState(e) {
|
|
2519
|
-
if (this.get$window().classList.toggle("loading", e), e) {
|
|
2520
|
-
const t = this.get$window().querySelectorAll(
|
|
2521
|
-
"input:not([disabled]),button:not([disabled])"
|
|
2522
|
-
);
|
|
2523
|
-
this._tmpDisabledActiveInputs = t, t.forEach((i) => {
|
|
2524
|
-
i.disabled = !0;
|
|
2525
|
-
}), this.get$content().append(
|
|
2526
|
-
/* @__PURE__ */ k(
|
|
2527
|
-
"div",
|
|
2528
|
-
{
|
|
2529
|
-
id: "ipe-modalLoadingWrapper",
|
|
2530
|
-
style: {
|
|
2531
|
-
position: "absolute",
|
|
2532
|
-
top: 0,
|
|
2533
|
-
left: 0,
|
|
2534
|
-
right: 0,
|
|
2535
|
-
bottom: 0,
|
|
2536
|
-
display: "flex",
|
|
2537
|
-
justifyContent: "center",
|
|
2538
|
-
alignItems: "center",
|
|
2539
|
-
backgroundColor: "rgba(255, 255, 255, 0.5)",
|
|
2540
|
-
zIndex: 2e3
|
|
2541
|
-
},
|
|
2542
|
-
children: /* @__PURE__ */ k(Ct, { style: { width: "80%", maxWidth: "800px" } })
|
|
2543
|
-
}
|
|
2544
|
-
)
|
|
2545
|
-
);
|
|
2546
|
-
} else {
|
|
2547
|
-
this.get$window().querySelector("#ipe-modalLoadingWrapper")?.remove();
|
|
2548
|
-
const t = this._tmpDisabledActiveInputs;
|
|
2549
|
-
t && t.forEach((i) => {
|
|
2550
|
-
i.disabled = !1;
|
|
2551
|
-
});
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
class Ii {
|
|
2556
|
-
constructor(e) {
|
|
2557
|
-
this.ctx = e, this.IPEModal = v, this.IPEModalEvent = ve, this.show = v.show.bind(v), this.createObject = v.createObject.bind(v), this.close = v.close.bind(v), this.closeAll = v.closeAll.bind(v), this.removeAll = v.removeAll.bind(v), this.dialog = v.dialog.bind(v), this.confirm = v.confirm.bind(v), this.notify = v.notify.bind(v), e.set("modal", this), e.on("dispose", () => {
|
|
2558
|
-
v.closeAll();
|
|
2559
|
-
});
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
const ot = (r) => {
|
|
2563
|
-
if (!r)
|
|
2564
|
-
return new URLSearchParams();
|
|
2565
|
-
if (r instanceof URLSearchParams)
|
|
2566
|
-
return r;
|
|
2567
|
-
if (typeof r != "object" || r?.constructor !== Object)
|
|
2568
|
-
throw new TypeError("only plain object is supported");
|
|
2569
|
-
const e = new URLSearchParams();
|
|
2570
|
-
for (const [t, i] of Object.entries(r))
|
|
2571
|
-
if (i != null) {
|
|
2572
|
-
if (Array.isArray(i)) {
|
|
2573
|
-
for (const s of i)
|
|
2574
|
-
e.append(t, s?.toString());
|
|
2575
|
-
continue;
|
|
2576
|
-
}
|
|
2577
|
-
if (typeof i == "object" && i !== null && i.constructor === Object) {
|
|
2578
|
-
for (const [s, n] of Object.entries(i))
|
|
2579
|
-
n != null && e.set(`${t}[${s}]`, n?.toString());
|
|
2580
|
-
continue;
|
|
2581
|
-
}
|
|
2582
|
-
e.set(t, i?.toString());
|
|
2583
|
-
}
|
|
2584
|
-
return e;
|
|
2585
|
-
}, at = (r, e, t) => {
|
|
2586
|
-
const i = typeof r == "string" ? new URL(r, window?.location?.origin) : new URL(r), s = new URLSearchParams(i.search), n = ot(e);
|
|
2587
|
-
for (const [o, a] of n.entries())
|
|
2588
|
-
s.set(o, a);
|
|
2589
|
-
return i.search = s.toString(), i.hash = "", i;
|
|
2590
|
-
};
|
|
2591
|
-
var Pi = Object.create, _e = Object.defineProperty, Di = Object.getOwnPropertyDescriptor, lt = (r, e) => (e = Symbol[r]) ? e : Symbol.for("Symbol." + r), ct = (r) => {
|
|
2592
|
-
throw TypeError(r);
|
|
2593
|
-
}, Mi = (r, e, t) => e in r ? _e(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Ui = (r, e) => _e(r, "name", { value: e, configurable: !0 }), Bi = (r) => [, , , Pi(r?.[lt("metadata")] ?? null)], Ni = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ht = (r) => r !== void 0 && typeof r != "function" ? ct("Function expected") : r, ji = (r, e, t, i, s) => ({ kind: Ni[r], name: e, metadata: i, addInitializer: (n) => t._ ? ct("Already initialized") : s.push(ht(n || null)) }), qi = (r, e) => Mi(e, lt("metadata"), r[3]), Fi = (r, e, t, i) => {
|
|
2594
|
-
for (var s = 0, n = r[e >> 1], o = n && n.length; s < o; s++) n[s].call(t);
|
|
2595
|
-
return i;
|
|
2596
|
-
}, Hi = (r, e, t, i, s, n) => {
|
|
2597
|
-
var o, a, c, l = e & 7, h = !1, d = 0, u = r[d] || (r[d] = []), f = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Di(s, t));
|
|
2598
|
-
Ui(s, t);
|
|
2599
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
2600
|
-
c = ji(l, t, a = {}, r[3], u), o = (0, i[g])(s, c), a._ = 1, ht(o) && (s = o);
|
|
2601
|
-
return qi(r, s), f && _e(s, t, f), h ? l ^ 4 ? n : f : s;
|
|
2602
|
-
}, ut, Se, dt;
|
|
2603
|
-
ut = [ne(["api", "storage"])];
|
|
2604
|
-
class te extends (dt = I) {
|
|
2605
|
-
constructor(e) {
|
|
2606
|
-
super(e, "wiki", !1), this.ctx = e, this._data = {}, this.CACHE_VERSION = 3, this.CACHE_TTL = {
|
|
2607
|
-
siteinfo: 1e3 * 60 * 60 * 24 * 3,
|
|
2608
|
-
// 3 days
|
|
2609
|
-
userinfo: 1e3 * 60 * 30
|
|
2610
|
-
// 30 minutes
|
|
2611
|
-
}, this.QUERY_DATA = {
|
|
2612
|
-
siteinfo: {
|
|
2613
|
-
meta: "siteinfo",
|
|
2614
|
-
siprop: "general|specialpagealiases|namespacealiases|namespaces|magicwords"
|
|
2615
|
-
},
|
|
2616
|
-
userinfo: { meta: "userinfo", uiprop: "groups|rights|blockinfo|options" }
|
|
2617
|
-
}, this.CACHE_DB = void 0, this.mwConfig = {
|
|
2618
|
-
get: ((t, i) => window?.mw?.config?.get?.(t, i) ?? i),
|
|
2619
|
-
has: ((t) => window?.mw?.config?.exists?.(t) ?? !1),
|
|
2620
|
-
get values() {
|
|
2621
|
-
return window?.mw?.config?.values || {};
|
|
2622
|
-
}
|
|
2623
|
-
}, this.CACHE_DB = e.storage.createDatabase(
|
|
2624
|
-
"wiki-metadata",
|
|
2625
|
-
1 / 0,
|
|
2626
|
-
this.CACHE_VERSION
|
|
2627
|
-
);
|
|
2628
|
-
}
|
|
2629
|
-
get logger() {
|
|
2630
|
-
return this.ctx.logger("WIKI_METADATA");
|
|
2631
|
-
}
|
|
2632
|
-
get api() {
|
|
2633
|
-
return this.ctx.api;
|
|
2634
|
-
}
|
|
2635
|
-
async start() {
|
|
2636
|
-
await Promise.all(
|
|
2637
|
-
Object.keys(this.QUERY_DATA).map((e) => this.initData(e))
|
|
2638
|
-
), this.ctx.on("clear-cache", this.onClearCache.bind(this)), this.ctx.set("getUrl", this.getUrl.bind(this)), this.ctx.set("getSciprtUrl", this.getSciprtUrl.bind(this)), this.ctx.set("getMainpageUrl", this.getMainpageUrl.bind(this)), this.ctx.inject(["preferences", "$"], (e) => {
|
|
2639
|
-
const t = e.$;
|
|
2640
|
-
e.preferences.registerCustomConfig(
|
|
2641
|
-
"WikiMetadataService",
|
|
2642
|
-
m.object({
|
|
2643
|
-
WikiMetadataService: m.const(
|
|
2644
|
-
/* @__PURE__ */ k("div", { children: [
|
|
2645
|
-
/* @__PURE__ */ k("h3", { children: t`Wiki Informations` }),
|
|
2646
|
-
/* @__PURE__ */ k("ul", { children: [
|
|
2647
|
-
/* @__PURE__ */ k("li", { children: [
|
|
2648
|
-
/* @__PURE__ */ k("strong", { children: [
|
|
2649
|
-
t`Site`,
|
|
2650
|
-
":"
|
|
2651
|
-
] }),
|
|
2652
|
-
" ",
|
|
2653
|
-
this.general.sitename,
|
|
2654
|
-
" (",
|
|
2655
|
-
this.landingPageUrl,
|
|
2656
|
-
")"
|
|
2657
|
-
] }),
|
|
2658
|
-
/* @__PURE__ */ k("li", { children: [
|
|
2659
|
-
/* @__PURE__ */ k("strong", { children: t`User` }),
|
|
2660
|
-
": ",
|
|
2661
|
-
this.userInfo.name,
|
|
2662
|
-
" (ID: ",
|
|
2663
|
-
this.userInfo.id,
|
|
2664
|
-
")"
|
|
2665
|
-
] }),
|
|
2666
|
-
/* @__PURE__ */ k("li", { children: [
|
|
2667
|
-
/* @__PURE__ */ k("strong", { children: t`Groups` }),
|
|
2668
|
-
": ",
|
|
2669
|
-
this.userGroups.join(", ") || "None"
|
|
2670
|
-
] })
|
|
2671
|
-
] }),
|
|
2672
|
-
/* @__PURE__ */ k("div", { children: [
|
|
2673
|
-
/* @__PURE__ */ k("p", { style: { fontStyle: "italic" }, children: t`If the information shown above is incorrect (for example, the user is not you), click the button below.` }),
|
|
2674
|
-
/* @__PURE__ */ k(
|
|
2675
|
-
"button",
|
|
2676
|
-
{
|
|
2677
|
-
className: "btn danger",
|
|
2678
|
-
onClick: async (i) => {
|
|
2679
|
-
i.preventDefault(), await e.serial("clear-cache") || window.location.reload();
|
|
2680
|
-
},
|
|
2681
|
-
children: [
|
|
2682
|
-
"🧹 ",
|
|
2683
|
-
t`Clear caches & Reload`
|
|
2684
|
-
]
|
|
2685
|
-
}
|
|
2686
|
-
)
|
|
2687
|
-
] })
|
|
2688
|
-
] })
|
|
2689
|
-
).role("raw-html")
|
|
2690
|
-
}).description("WikiMetadataService"),
|
|
2691
|
-
"about"
|
|
2692
|
-
);
|
|
2693
|
-
}), this.logger.info("All initialized", this._data);
|
|
2694
|
-
}
|
|
2695
|
-
async initData(e, t = !1) {
|
|
2696
|
-
const i = t ? null : await this.fetchFromCache(e);
|
|
2697
|
-
if (i)
|
|
2698
|
-
return this._data[e] = i, this.logger.debug("Using cached", e, i), i;
|
|
2699
|
-
{
|
|
2700
|
-
const s = await this.fetchFromApi(e);
|
|
2701
|
-
return this.saveToCache(e, s), this._data[e] = s, this.logger.debug("Fetched from API", e, s), s;
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
getCacheKey(e) {
|
|
2705
|
-
return `${e}:${new URL(this.ctx.api.config.baseURL).pathname.replace(/^\//, "")}`;
|
|
2706
|
-
}
|
|
2707
|
-
async fetchFromApi(e) {
|
|
2708
|
-
return this.api.get({
|
|
2709
|
-
action: "query",
|
|
2710
|
-
...this.QUERY_DATA[e]
|
|
2711
|
-
}).then(({ data: t }) => {
|
|
2712
|
-
if (typeof t?.query != "object" || t.query === null)
|
|
2713
|
-
throw new Error("Invalid query data", { cause: t });
|
|
2714
|
-
return e === "siteinfo" ? t.query : t.query?.[e] || t.query;
|
|
2715
|
-
}).catch((t) => (this.logger.error("Failed to fetch", t), Promise.reject(t)));
|
|
2716
|
-
}
|
|
2717
|
-
async fetchFromCache(e) {
|
|
2718
|
-
const t = this.getCacheKey(e);
|
|
2719
|
-
return await this.CACHE_DB.get(t, this.CACHE_TTL[e]);
|
|
2720
|
-
}
|
|
2721
|
-
async saveToCache(e, t) {
|
|
2722
|
-
const i = this.getCacheKey(e);
|
|
2723
|
-
return this.CACHE_DB.set(i, t);
|
|
2724
|
-
}
|
|
2725
|
-
async invalidateCache(e) {
|
|
2726
|
-
const t = this.getCacheKey(e);
|
|
2727
|
-
return this.CACHE_DB.delete(t);
|
|
2728
|
-
}
|
|
2729
|
-
async onClearCache() {
|
|
2730
|
-
await this.CACHE_DB.clear();
|
|
2731
|
-
}
|
|
2732
|
-
// ====== shortcuts ======
|
|
2733
|
-
get _raw() {
|
|
2734
|
-
return this._data;
|
|
2735
|
-
}
|
|
2736
|
-
// siteInfo
|
|
2737
|
-
get siteInfo() {
|
|
2738
|
-
return this._data.siteinfo;
|
|
2739
|
-
}
|
|
2740
|
-
get general() {
|
|
2741
|
-
return this.siteInfo.general;
|
|
2742
|
-
}
|
|
2743
|
-
get specialPageAliases() {
|
|
2744
|
-
return this.siteInfo.specialpagealiases;
|
|
2745
|
-
}
|
|
2746
|
-
get namespaceAliases() {
|
|
2747
|
-
return this.siteInfo.namespacealiases;
|
|
2748
|
-
}
|
|
2749
|
-
get namespaces() {
|
|
2750
|
-
return this.siteInfo.namespaces;
|
|
2751
|
-
}
|
|
2752
|
-
get namespaceMap() {
|
|
2753
|
-
const e = Object.values(this.namespaces).map((t) => ({
|
|
2754
|
-
id: t.id,
|
|
2755
|
-
canonical: t.canonical,
|
|
2756
|
-
aliases: this.namespaceAliases.filter((i) => i.id === t.id).map((i) => i.alias)
|
|
2757
|
-
})).sort((t, i) => t.id - i.id);
|
|
2758
|
-
return Reflect.defineProperty(this, "namespaceMap", {
|
|
2759
|
-
get: () => e
|
|
2760
|
-
}), e;
|
|
2761
|
-
}
|
|
2762
|
-
get magicWords() {
|
|
2763
|
-
return this.siteInfo.magicwords;
|
|
2764
|
-
}
|
|
2765
|
-
// userInfo
|
|
2766
|
-
get userInfo() {
|
|
2767
|
-
return this._data.userinfo;
|
|
2768
|
-
}
|
|
2769
|
-
get userOptions() {
|
|
2770
|
-
return this.userInfo.options;
|
|
2771
|
-
}
|
|
2772
|
-
get isUserBlocked() {
|
|
2773
|
-
return this.userInfo.blockedbyid && this.userInfo.blockexpiry && new Date(this.userInfo.blockexpiry).getTime() > Date.now();
|
|
2774
|
-
}
|
|
2775
|
-
get userGroups() {
|
|
2776
|
-
return this.userInfo.groups;
|
|
2777
|
-
}
|
|
2778
|
-
get userRights() {
|
|
2779
|
-
return this.userInfo.rights;
|
|
2780
|
-
}
|
|
2781
|
-
/**
|
|
2782
|
-
* Base URL, without trailing slash
|
|
2783
|
-
* @example "https://mediawiki.org"
|
|
2784
|
-
*/
|
|
2785
|
-
get baseUrl() {
|
|
2786
|
-
const e = this.general.server;
|
|
2787
|
-
return e.startsWith("//") ? `${window?.location?.protocol || "https:"}//${e.slice(2)}` : e;
|
|
2788
|
-
}
|
|
2789
|
-
/**
|
|
2790
|
-
* Home page URL of this wiki
|
|
2791
|
-
* @description Generally same as the Mainpage URL,
|
|
2792
|
-
* but after MediaWiki 1.34,
|
|
2793
|
-
* it can be set to the website root directory.
|
|
2794
|
-
* @example "https://mediawiki.org/wiki/Main_Page" (In most cases)
|
|
2795
|
-
* @example "https://mediawiki.org/" ($wgMainPageIsDomainRoot = true)
|
|
2796
|
-
*/
|
|
2797
|
-
get landingPageUrl() {
|
|
2798
|
-
return this.general.base;
|
|
2799
|
-
}
|
|
2800
|
-
get mainPageName() {
|
|
2801
|
-
return this.general.mainpage;
|
|
2802
|
-
}
|
|
2803
|
-
/**
|
|
2804
|
-
* Exact Mainpage URL of this wiki
|
|
2805
|
-
* @example "https://mediawiki.org/wiki/Main_Page"
|
|
2806
|
-
*/
|
|
2807
|
-
get mainPageUrl() {
|
|
2808
|
-
return this.getUrl(this.mainPageName);
|
|
2809
|
-
}
|
|
2810
|
-
/**
|
|
2811
|
-
* Article path, with the $1 placeholder
|
|
2812
|
-
* @example "/wiki/$1"
|
|
2813
|
-
*/
|
|
2814
|
-
get articlePath() {
|
|
2815
|
-
return this.general.articlepath;
|
|
2816
|
-
}
|
|
2817
|
-
/**
|
|
2818
|
-
* Script path, without trailing slash
|
|
2819
|
-
* @example "/w"
|
|
2820
|
-
*/
|
|
2821
|
-
get scriptPath() {
|
|
2822
|
-
return this.general.scriptpath;
|
|
2823
|
-
}
|
|
2824
|
-
/**
|
|
2825
|
-
* Article base URL, with the $1 placeholder
|
|
2826
|
-
* @example "https://mediawiki.org/wiki/$1"
|
|
2827
|
-
*/
|
|
2828
|
-
get articleBaseUrl() {
|
|
2829
|
-
return `${this.baseUrl}${this.articlePath}`;
|
|
2830
|
-
}
|
|
2831
|
-
/**
|
|
2832
|
-
* Script base URL, without trailing slash
|
|
2833
|
-
* @example "https://mediawiki.org/w"
|
|
2834
|
-
*/
|
|
2835
|
-
get scriptBaseUrl() {
|
|
2836
|
-
return `${this.baseUrl}${this.scriptPath}`;
|
|
2837
|
-
}
|
|
2838
|
-
// utils
|
|
2839
|
-
getSciprtUrl(e = "index") {
|
|
2840
|
-
return `${this.scriptBaseUrl}/${e.replace(/\.php$/, "")}.php`;
|
|
2841
|
-
}
|
|
2842
|
-
/** Get mainpage URL */
|
|
2843
|
-
getMainpageUrl(e) {
|
|
2844
|
-
return at(this.siteInfo.general.base, e).toString();
|
|
2845
|
-
}
|
|
2846
|
-
getUrl(e, t) {
|
|
2847
|
-
const i = ot(t);
|
|
2848
|
-
let s;
|
|
2849
|
-
return typeof e == "string" && e !== "" ? s = new URL(`${this.articleBaseUrl.replace("$1", e)}`) : typeof e == "number" ? (i.set("curid", e.toString()), s = new URL(this.getSciprtUrl("index"))) : s = new URL(this.getSciprtUrl("index")), s.search = i.toString(), s.toString();
|
|
2850
|
-
}
|
|
2851
|
-
hasRight(e) {
|
|
2852
|
-
return this.userRights.includes(e);
|
|
2853
|
-
}
|
|
2854
|
-
hasAnyRight(...e) {
|
|
2855
|
-
return e.some((t) => this.hasRight(t));
|
|
2856
|
-
}
|
|
2857
|
-
hasEveryRights(...e) {
|
|
2858
|
-
return e.every((t) => this.hasRight(t));
|
|
2859
|
-
}
|
|
2860
|
-
inGroup(e) {
|
|
2861
|
-
return this.userGroups.includes(e);
|
|
2862
|
-
}
|
|
2863
|
-
inAnyGroup(...e) {
|
|
2864
|
-
return this.userGroups.some((t) => e.includes(t));
|
|
2865
|
-
}
|
|
2866
|
-
getBlockInfo() {
|
|
2867
|
-
return this.isUserBlocked ? {
|
|
2868
|
-
blockid: this.userInfo.blockid,
|
|
2869
|
-
blockedby: this.userInfo.blockedbyid,
|
|
2870
|
-
blockedbyid: this.userInfo.blockedbyid,
|
|
2871
|
-
blockreason: this.userInfo.blockreason,
|
|
2872
|
-
blockedtimestamp: this.userInfo.blockedtimestamp,
|
|
2873
|
-
blockexpiry: this.userInfo.blockexpiry
|
|
2874
|
-
} : null;
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
Se = Bi(dt);
|
|
2878
|
-
te = Hi(Se, 0, "WikiMetadataService", ut, te);
|
|
2879
|
-
Fi(Se, 1, te);
|
|
2880
|
-
const Ki = (() => {
|
|
2881
|
-
const r = Symbol.for("IPE.GlobalMemoryStorage");
|
|
2882
|
-
return r in globalThis || (globalThis[r] = $t()), globalThis[r];
|
|
2883
|
-
})();
|
|
2884
|
-
class Wi {
|
|
2885
|
-
constructor(e, t, i = 1 / 0, s, n = "localStorage") {
|
|
2886
|
-
this.dbName = e, this.storeName = t, this.ttl = i, this.version = s, this.engine = n, typeof i != "number" && (this.ttl = Number(i)), (isNaN(this.ttl) || this.ttl <= 0) && (this.ttl = 1 / 0), this.engine === "localStorage" && "localStorage" in window ? this.db = window.localStorage : this.engine === "sessionStorage" && "sessionStorage" in window ? this.db = window.sessionStorage : this.db = Ki;
|
|
2887
|
-
}
|
|
2888
|
-
// Key builder
|
|
2889
|
-
makeKey(e) {
|
|
2890
|
-
return `${this.dbName ? this.dbName + ":" : ""}${this.storeName ? this.storeName + "/" : ""}${e}`;
|
|
2891
|
-
}
|
|
2892
|
-
// Internal load & validation
|
|
2893
|
-
load(e) {
|
|
2894
|
-
const t = this.getRaw(e);
|
|
2895
|
-
if (t === null) return null;
|
|
2896
|
-
let i;
|
|
2897
|
-
try {
|
|
2898
|
-
i = JSON.parse(t);
|
|
2899
|
-
} catch {
|
|
2900
|
-
return this.deleteSync(e), null;
|
|
2901
|
-
}
|
|
2902
|
-
const s = i;
|
|
2903
|
-
return typeof s.time != "number" || !("value" in s) ? (this.deleteSync(e), null) : typeof this.version < "u" && typeof this.version < "u" && s.version !== this.version ? (this.deleteSync(e), null) : s;
|
|
2904
|
-
}
|
|
2905
|
-
getRaw(e) {
|
|
2906
|
-
const t = this.makeKey(e);
|
|
2907
|
-
return this.db.getItem(t);
|
|
2908
|
-
}
|
|
2909
|
-
setRaw(e, t) {
|
|
2910
|
-
const i = this.makeKey(e);
|
|
2911
|
-
try {
|
|
2912
|
-
this.db.setItem(i, t);
|
|
2913
|
-
} catch {
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
deleteSync(e) {
|
|
2917
|
-
const t = this.makeKey(e);
|
|
2918
|
-
this.db.removeItem(t);
|
|
2919
|
-
}
|
|
2920
|
-
isExpired(e, t = this.ttl) {
|
|
2921
|
-
return e ? Date.now() - e.time > t : !1;
|
|
2922
|
-
}
|
|
2923
|
-
async get(e, t = this.ttl, i) {
|
|
2924
|
-
const s = this.load(e), n = this.isExpired(s, t);
|
|
2925
|
-
if (!s || n) {
|
|
2926
|
-
if (typeof i == "function") {
|
|
2927
|
-
const o = await i();
|
|
2928
|
-
return await this.set(e, o), o;
|
|
2929
|
-
}
|
|
2930
|
-
return null;
|
|
2931
|
-
}
|
|
2932
|
-
return s.value;
|
|
2933
|
-
}
|
|
2934
|
-
async set(e, t) {
|
|
2935
|
-
const i = Date.now();
|
|
2936
|
-
if (typeof e == "string") {
|
|
2937
|
-
const o = e, a = t;
|
|
2938
|
-
if (a === null || typeof a > "u") {
|
|
2939
|
-
await this.delete(o);
|
|
2940
|
-
return;
|
|
2941
|
-
}
|
|
2942
|
-
const c = { time: i, value: a, version: this.version };
|
|
2943
|
-
return this.setRaw(o, JSON.stringify(c)), c;
|
|
2944
|
-
}
|
|
2945
|
-
const s = e, n = {};
|
|
2946
|
-
for (const [o, a] of Object.entries(s)) {
|
|
2947
|
-
if (a === null || typeof a > "u") {
|
|
2948
|
-
this.deleteSync(o);
|
|
2949
|
-
continue;
|
|
2950
|
-
}
|
|
2951
|
-
const c = { time: i, value: a, version: this.version };
|
|
2952
|
-
this.setRaw(o, JSON.stringify(c)), n[o] = c;
|
|
2953
|
-
}
|
|
2954
|
-
return n;
|
|
2955
|
-
}
|
|
2956
|
-
async has(e, t = this.ttl) {
|
|
2957
|
-
const i = this.load(e);
|
|
2958
|
-
return i !== null && !this.isExpired(i, t);
|
|
2959
|
-
}
|
|
2960
|
-
async delete(e) {
|
|
2961
|
-
this.deleteSync(e);
|
|
2962
|
-
}
|
|
2963
|
-
async updatedAt(e) {
|
|
2964
|
-
const t = this.load(e);
|
|
2965
|
-
return t ? t.time : 0;
|
|
2966
|
-
}
|
|
2967
|
-
async clear() {
|
|
2968
|
-
const e = this.makeKey(""), t = [];
|
|
2969
|
-
for (let i = 0; i < this.db.length; i++) {
|
|
2970
|
-
const s = this.db.key(i);
|
|
2971
|
-
s && s.startsWith(e) && t.push(s);
|
|
2972
|
-
}
|
|
2973
|
-
for (const i of t) this.db.removeItem(i);
|
|
2974
|
-
return this;
|
|
2975
|
-
}
|
|
2976
|
-
// Async generators
|
|
2977
|
-
async *keys() {
|
|
2978
|
-
const e = this.makeKey("");
|
|
2979
|
-
for (let t = 0; t < this.db.length; t++) {
|
|
2980
|
-
const i = this.db.key(t);
|
|
2981
|
-
i && i.startsWith(e) && (yield i.slice(e.length));
|
|
2982
|
-
}
|
|
2983
|
-
}
|
|
2984
|
-
async *values() {
|
|
2985
|
-
for await (const e of this.keys()) {
|
|
2986
|
-
const t = this.load(e);
|
|
2987
|
-
if (t) {
|
|
2988
|
-
if (this.isExpired(t)) {
|
|
2989
|
-
this.deleteSync(e);
|
|
2990
|
-
continue;
|
|
2991
|
-
}
|
|
2992
|
-
yield t;
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
}
|
|
2996
|
-
async *entries() {
|
|
2997
|
-
for await (const e of this.keys()) {
|
|
2998
|
-
const t = this.load(e);
|
|
2999
|
-
if (t) {
|
|
3000
|
-
if (this.isExpired(t)) {
|
|
3001
|
-
this.deleteSync(e);
|
|
3002
|
-
continue;
|
|
3003
|
-
}
|
|
3004
|
-
yield [e, t];
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
var b;
|
|
3010
|
-
((r) => {
|
|
3011
|
-
r.cache = /* @__PURE__ */ new Map(), r.defaults = Object.freeze({ iterBatch: 100, retry: { attempts: 3, baseDelayMs: 16 } }), r.sleep = (l) => new Promise((h) => setTimeout(h, l));
|
|
3012
|
-
function e(l) {
|
|
3013
|
-
const h = l?.name ?? "";
|
|
3014
|
-
return h === "AbortError" || h === "InvalidStateError" || h === "TransactionInactiveError" || h === "UnknownError";
|
|
3015
|
-
}
|
|
3016
|
-
r.shouldReconnect = e;
|
|
3017
|
-
async function t(l, h, d) {
|
|
3018
|
-
const u = Math.max(1, l.attempts);
|
|
3019
|
-
for (let f = 0; f < u; f++)
|
|
3020
|
-
try {
|
|
3021
|
-
return await h(f);
|
|
3022
|
-
} catch (g) {
|
|
3023
|
-
if (f === u - 1) throw g;
|
|
3024
|
-
await d?.(g, f);
|
|
3025
|
-
const p = l.baseDelayMs * Math.pow(2, f) + Math.floor(Math.random() * 10);
|
|
3026
|
-
await (0, r.sleep)(p);
|
|
3027
|
-
}
|
|
3028
|
-
throw new Error("withRetry exhausted unexpectedly");
|
|
3029
|
-
}
|
|
3030
|
-
r.withRetry = t;
|
|
3031
|
-
function i(l, h, d) {
|
|
3032
|
-
return new Promise((u, f) => {
|
|
3033
|
-
const g = indexedDB.open(l, h);
|
|
3034
|
-
g.onupgradeneeded = () => {
|
|
3035
|
-
try {
|
|
3036
|
-
const p = g.result, y = g.transaction;
|
|
3037
|
-
d?.(p, y);
|
|
3038
|
-
} catch (p) {
|
|
3039
|
-
f(p);
|
|
3040
|
-
}
|
|
3041
|
-
}, g.onerror = () => f(g.error), g.onblocked = () => {
|
|
3042
|
-
}, g.onsuccess = () => {
|
|
3043
|
-
const p = g.result;
|
|
3044
|
-
p.onversionchange = () => {
|
|
3045
|
-
try {
|
|
3046
|
-
p.close();
|
|
3047
|
-
} finally {
|
|
3048
|
-
r.cache.delete(l);
|
|
3049
|
-
}
|
|
3050
|
-
}, u(p);
|
|
3051
|
-
};
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
async function s(l, h, d) {
|
|
3055
|
-
let u = !l.objectStoreNames.contains(h), f = [];
|
|
3056
|
-
if (!u && d?.indexes?.length) {
|
|
3057
|
-
const y = l.transaction(h, "readonly"), L = y.objectStore(h), U = new Set(Array.from(L.indexNames));
|
|
3058
|
-
f = (d.indexes || []).filter((C) => !U.has(C.name)), await new Promise((C, Le) => {
|
|
3059
|
-
y.oncomplete = () => C(), y.onabort = () => Le(y.error), y.onerror = () => Le(y.error);
|
|
3060
|
-
});
|
|
3061
|
-
}
|
|
3062
|
-
if (!u && f.length === 0) return l;
|
|
3063
|
-
const g = l.version + 1;
|
|
3064
|
-
l.close();
|
|
3065
|
-
const p = await i(l.name, g, (y, L) => {
|
|
3066
|
-
let U;
|
|
3067
|
-
y.objectStoreNames.contains(h) ? U = L.objectStore(h) : U = y.createObjectStore(h, {
|
|
3068
|
-
keyPath: d?.keyPath ?? void 0,
|
|
3069
|
-
autoIncrement: !!d?.autoIncrement
|
|
3070
|
-
});
|
|
3071
|
-
for (const C of f)
|
|
3072
|
-
U.indexNames.contains(C.name) || U.createIndex(C.name, C.keyPath, C.options);
|
|
3073
|
-
});
|
|
3074
|
-
return p.onversionchange = () => {
|
|
3075
|
-
try {
|
|
3076
|
-
p.close();
|
|
3077
|
-
} finally {
|
|
3078
|
-
r.cache.delete(p.name);
|
|
3079
|
-
}
|
|
3080
|
-
}, p;
|
|
3081
|
-
}
|
|
3082
|
-
async function n(l, h, d) {
|
|
3083
|
-
let u = r.cache.get(l);
|
|
3084
|
-
return u ? (u = u.then((f) => s(f, h, d)), r.cache.set(l, u)) : (u = (async () => {
|
|
3085
|
-
const f = await i(l);
|
|
3086
|
-
return s(f, h, d);
|
|
3087
|
-
})(), r.cache.set(l, u)), u;
|
|
3088
|
-
}
|
|
3089
|
-
r.getDB = n;
|
|
3090
|
-
async function o(l) {
|
|
3091
|
-
const h = r.cache.get(l);
|
|
3092
|
-
if (r.cache.delete(l), h)
|
|
3093
|
-
try {
|
|
3094
|
-
(await h).close();
|
|
3095
|
-
} catch {
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
r.closeConnection = o;
|
|
3099
|
-
function a(l) {
|
|
3100
|
-
return new Promise((h, d) => {
|
|
3101
|
-
l.onsuccess = () => h(l.result), l.onerror = () => d(l.error);
|
|
3102
|
-
});
|
|
3103
|
-
}
|
|
3104
|
-
r.asyncRequest = a;
|
|
3105
|
-
function c(l) {
|
|
3106
|
-
return new Promise((h, d) => {
|
|
3107
|
-
l.oncomplete = () => h(), l.onabort = () => d(l.error ?? new DOMException("Aborted", "AbortError")), l.onerror = () => d(l.error ?? new DOMException("TransactionError", "UnknownError"));
|
|
3108
|
-
});
|
|
3109
|
-
}
|
|
3110
|
-
r.waitTx = c;
|
|
3111
|
-
})(b || (b = {}));
|
|
3112
|
-
class zi {
|
|
3113
|
-
constructor(e, t, i = {}) {
|
|
3114
|
-
this.dbName = e, this.storeName = t, this.options = i;
|
|
3115
|
-
}
|
|
3116
|
-
get _iterBatch() {
|
|
3117
|
-
return this.options.iterBatch ?? b.defaults.iterBatch;
|
|
3118
|
-
}
|
|
3119
|
-
get _retryCfg() {
|
|
3120
|
-
const e = this.options.retry ?? b.defaults.retry;
|
|
3121
|
-
return { attempts: e.attempts ?? 3, baseDelayMs: e.baseDelayMs ?? 16 };
|
|
3122
|
-
}
|
|
3123
|
-
async _withStore(e, t) {
|
|
3124
|
-
const i = this._retryCfg;
|
|
3125
|
-
return b.withRetry(
|
|
3126
|
-
i,
|
|
3127
|
-
async () => {
|
|
3128
|
-
const s = await b.getDB(this.dbName, this.storeName, this.options.ensure);
|
|
3129
|
-
try {
|
|
3130
|
-
const n = s.transaction(this.storeName, e), o = n.objectStore(this.storeName), a = await t(o);
|
|
3131
|
-
return await b.waitTx(n), a;
|
|
3132
|
-
} catch (n) {
|
|
3133
|
-
throw n;
|
|
3134
|
-
}
|
|
3135
|
-
},
|
|
3136
|
-
async (s) => {
|
|
3137
|
-
b.shouldReconnect(s) && await b.closeConnection(this.dbName);
|
|
3138
|
-
}
|
|
3139
|
-
);
|
|
3140
|
-
}
|
|
3141
|
-
async get(e) {
|
|
3142
|
-
return this._withStore("readonly", async (t) => {
|
|
3143
|
-
const i = await b.asyncRequest(t.get(e));
|
|
3144
|
-
return i === void 0 ? void 0 : i;
|
|
3145
|
-
});
|
|
3146
|
-
}
|
|
3147
|
-
async set(e, t) {
|
|
3148
|
-
return await this._withStore("readwrite", async (i) => {
|
|
3149
|
-
const s = this.options.ensure?.keyPath != null ? i.put(t) : i.put(t, e);
|
|
3150
|
-
await b.asyncRequest(s);
|
|
3151
|
-
}), this;
|
|
3152
|
-
}
|
|
3153
|
-
async delete(e) {
|
|
3154
|
-
return this._withStore("readwrite", async (t) => {
|
|
3155
|
-
const i = await b.asyncRequest(t.get(e)) !== void 0;
|
|
3156
|
-
return await b.asyncRequest(t.delete(e)), i;
|
|
3157
|
-
});
|
|
3158
|
-
}
|
|
3159
|
-
async clear() {
|
|
3160
|
-
await this._withStore("readwrite", async (e) => {
|
|
3161
|
-
await b.asyncRequest(e.clear());
|
|
3162
|
-
});
|
|
3163
|
-
}
|
|
3164
|
-
async has(e) {
|
|
3165
|
-
return await this.get(e) !== void 0;
|
|
3166
|
-
}
|
|
3167
|
-
async count() {
|
|
3168
|
-
return this._withStore("readonly", async (e) => await b.asyncRequest(e.count()) ?? 0);
|
|
3169
|
-
}
|
|
3170
|
-
async *_iterateEntries() {
|
|
3171
|
-
let e = null, t = !1;
|
|
3172
|
-
const i = Math.max(1, this._iterBatch);
|
|
3173
|
-
for (; !t; ) {
|
|
3174
|
-
const s = await this._withStore("readonly", async (n) => {
|
|
3175
|
-
const o = [], a = e === null ? void 0 : IDBKeyRange.lowerBound(e, !0);
|
|
3176
|
-
return await new Promise((c, l) => {
|
|
3177
|
-
const h = n.openCursor(a);
|
|
3178
|
-
h.onerror = () => l(h.error), h.onsuccess = () => {
|
|
3179
|
-
const d = h.result;
|
|
3180
|
-
if (!d) {
|
|
3181
|
-
t = !0, c();
|
|
3182
|
-
return;
|
|
3183
|
-
}
|
|
3184
|
-
o.push([d.key, d.value]), e = d.key, o.length >= i ? c() : d.continue();
|
|
3185
|
-
};
|
|
3186
|
-
}), o;
|
|
3187
|
-
});
|
|
3188
|
-
for (const n of s) yield n;
|
|
3189
|
-
if (s.length === 0) break;
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
entries() {
|
|
3193
|
-
return this._iterateEntries();
|
|
3194
|
-
}
|
|
3195
|
-
async *keys() {
|
|
3196
|
-
for await (const [e] of this.entries()) yield e;
|
|
3197
|
-
}
|
|
3198
|
-
async *values() {
|
|
3199
|
-
for await (const [, e] of this.entries()) yield e;
|
|
3200
|
-
}
|
|
3201
|
-
[Symbol.asyncIterator]() {
|
|
3202
|
-
return this.entries()[Symbol.asyncIterator]();
|
|
3203
|
-
}
|
|
3204
|
-
async forEach(e) {
|
|
3205
|
-
for await (const [t, i] of this.entries())
|
|
3206
|
-
await e(i, t, this);
|
|
3207
|
-
}
|
|
3208
|
-
async getMany(e) {
|
|
3209
|
-
const t = /* @__PURE__ */ new Map();
|
|
3210
|
-
for await (const i of e) t.set(i, void 0);
|
|
3211
|
-
return await this._withStore("readonly", async (i) => {
|
|
3212
|
-
await Promise.all(
|
|
3213
|
-
t.keys().map(async (s) => {
|
|
3214
|
-
const n = await b.asyncRequest(i.get(s));
|
|
3215
|
-
t.set(s, n === void 0 ? void 0 : n);
|
|
3216
|
-
})
|
|
3217
|
-
);
|
|
3218
|
-
}), t;
|
|
3219
|
-
}
|
|
3220
|
-
async setMany(e) {
|
|
3221
|
-
const t = this.options.ensure?.keyPath != null;
|
|
3222
|
-
return await this._withStore("readwrite", async (i) => {
|
|
3223
|
-
for await (const [s, n] of e) {
|
|
3224
|
-
const o = t ? i.put(n) : i.put(n, s);
|
|
3225
|
-
await b.asyncRequest(o);
|
|
3226
|
-
}
|
|
3227
|
-
}), this;
|
|
3228
|
-
}
|
|
3229
|
-
async deleteMany(e) {
|
|
3230
|
-
let t = 0;
|
|
3231
|
-
return await this._withStore("readwrite", async (i) => {
|
|
3232
|
-
for await (const s of e)
|
|
3233
|
-
await b.asyncRequest(i.get(s)) !== void 0 && t++, await b.asyncRequest(i.delete(s));
|
|
3234
|
-
}), t;
|
|
3235
|
-
}
|
|
3236
|
-
async disconnect() {
|
|
3237
|
-
await b.closeConnection(this.dbName);
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
class Gi {
|
|
3241
|
-
constructor(e, t, i = 1 / 0, s) {
|
|
3242
|
-
this.dbName = e, this.storeName = t, this.ttl = i, this.version = s, this.db = new zi(e, t), this.keys = this.db.keys.bind(this.db), this.values = this.db.values.bind(this.db), this.entries = this.db.entries.bind(this.db), typeof this.ttl != "number" && (this.ttl = Number(this.ttl)), (isNaN(this.ttl) || this.ttl <= 0) && (this.ttl = 1 / 0), this._clearExpiredEntries().catch(() => {
|
|
3243
|
-
});
|
|
3244
|
-
}
|
|
3245
|
-
async _clearExpiredEntries() {
|
|
3246
|
-
if (this.ttl === 1 / 0) return;
|
|
3247
|
-
const e = Date.now(), t = [];
|
|
3248
|
-
for await (const [i, s] of this.db.entries())
|
|
3249
|
-
typeof s.time == "number" && e - s.time > this.ttl && t.push(i);
|
|
3250
|
-
t.length > 0 && await this.db.deleteMany(t);
|
|
3251
|
-
}
|
|
3252
|
-
async get(e, t = this.ttl, i) {
|
|
3253
|
-
const s = await this.loadFromDB(e), n = this.checkIfExpired(s, t);
|
|
3254
|
-
if (!s || n) {
|
|
3255
|
-
if (typeof i == "function") {
|
|
3256
|
-
const o = await i();
|
|
3257
|
-
return await this.set(e, o), o;
|
|
3258
|
-
}
|
|
3259
|
-
return null;
|
|
3260
|
-
}
|
|
3261
|
-
return s.value;
|
|
3262
|
-
}
|
|
3263
|
-
async set(e, t) {
|
|
3264
|
-
const i = Date.now();
|
|
3265
|
-
if (typeof e == "string") {
|
|
3266
|
-
const c = e, l = t;
|
|
3267
|
-
if (l === null || typeof l > "u")
|
|
3268
|
-
return this.delete(c);
|
|
3269
|
-
const h = {
|
|
3270
|
-
time: i,
|
|
3271
|
-
value: l,
|
|
3272
|
-
version: this.version
|
|
3273
|
-
};
|
|
3274
|
-
return await this.db.set(c, h), h;
|
|
3275
|
-
}
|
|
3276
|
-
const s = e, n = [], o = [], a = {};
|
|
3277
|
-
for (const [c, l] of Object.entries(s))
|
|
3278
|
-
if (l === null || typeof l > "u")
|
|
3279
|
-
o.push(c);
|
|
3280
|
-
else {
|
|
3281
|
-
const h = { time: i, value: l, version: this.version };
|
|
3282
|
-
n.push([c, h]), a[c] = h;
|
|
3283
|
-
}
|
|
3284
|
-
return n.length > 0 && await this.db.setMany(n), o.length > 0 && await this.db.deleteMany(o), a;
|
|
3285
|
-
}
|
|
3286
|
-
async has(e, t = this.ttl) {
|
|
3287
|
-
const i = await this.loadFromDB(e), s = this.checkIfExpired(i, t);
|
|
3288
|
-
return i !== null && !s;
|
|
3289
|
-
}
|
|
3290
|
-
async delete(e) {
|
|
3291
|
-
await this.db.delete(e);
|
|
3292
|
-
}
|
|
3293
|
-
async updatedAt(e) {
|
|
3294
|
-
const t = await this.loadFromDB(e);
|
|
3295
|
-
return t ? t.time : 0;
|
|
3296
|
-
}
|
|
3297
|
-
async loadFromDB(e) {
|
|
3298
|
-
const t = await this.db.get(e);
|
|
3299
|
-
if (t === void 0)
|
|
3300
|
-
return null;
|
|
3301
|
-
if (typeof t.time != "number" || typeof t.value > "u") {
|
|
3302
|
-
try {
|
|
3303
|
-
await this.delete(e);
|
|
3304
|
-
} catch {
|
|
3305
|
-
}
|
|
3306
|
-
return null;
|
|
3307
|
-
}
|
|
3308
|
-
if (typeof this.version < "u" && typeof this.version < "u" && t.version !== this.version) {
|
|
3309
|
-
try {
|
|
3310
|
-
await this.delete(e);
|
|
3311
|
-
} catch {
|
|
3312
|
-
}
|
|
3313
|
-
return null;
|
|
3314
|
-
}
|
|
3315
|
-
return t;
|
|
3316
|
-
}
|
|
3317
|
-
checkIfExpired(e, t = this.ttl) {
|
|
3318
|
-
return e ? Date.now() - e.time > t : !1;
|
|
3319
|
-
}
|
|
3320
|
-
/**
|
|
3321
|
-
* [DANGER] Use with caution!
|
|
3322
|
-
* Delete all data from the database.
|
|
3323
|
-
*/
|
|
3324
|
-
async clear() {
|
|
3325
|
-
return await this.db.clear(), this;
|
|
3326
|
-
}
|
|
3327
|
-
}
|
|
3328
|
-
class Yi extends I {
|
|
3329
|
-
constructor(e, t) {
|
|
3330
|
-
super(e, "storage", !1), this.config = t, this.kv = this.createDatabase("key-val", 0, 1, "indexedDB"), this.simpleKV = this.createDatabase("~", 0, 1, "localStorage"), this.memoryKV = this.createDatabase("~", 0, 1, "memory");
|
|
3331
|
-
}
|
|
3332
|
-
createDatabase(e, t, i, s = "indexedDB") {
|
|
3333
|
-
const n = "indexedDB" in window && window.indexedDB !== null;
|
|
3334
|
-
switch (s === "indexedDB" && !n && (s = "localStorage"), s) {
|
|
3335
|
-
case "indexedDB":
|
|
3336
|
-
return new Gi(this.config.dbName, e, t, i);
|
|
3337
|
-
case "localStorage":
|
|
3338
|
-
case "sessionStorage":
|
|
3339
|
-
case "memory":
|
|
3340
|
-
return new Wi(this.config.dbName, e, t, i, s);
|
|
3341
|
-
default:
|
|
3342
|
-
throw new Error(`Unsupported storage engine: ${s}`);
|
|
3343
|
-
}
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
class Xi extends I {
|
|
3347
|
-
constructor(e) {
|
|
3348
|
-
super(e, "wikiPage", !0), this.ctx = e, this.WikiPage = Rt(this.ctx.api);
|
|
3349
|
-
}
|
|
3350
|
-
static {
|
|
3351
|
-
this.inject = ["api"];
|
|
3352
|
-
}
|
|
3353
|
-
async createInstance(e, t = !1) {
|
|
3354
|
-
return await this.WikiPage.newFromApi(e);
|
|
3355
|
-
}
|
|
3356
|
-
async newFromTitle(e, t = !1, i, s = !1) {
|
|
3357
|
-
return this.createInstance({ titles: e.toString(), converttitles: t, rvsection: i }, s);
|
|
3358
|
-
}
|
|
3359
|
-
async newFromPageId(e, t, i = !1) {
|
|
3360
|
-
return this.createInstance({ pageids: e, rvsection: t }, i);
|
|
3361
|
-
}
|
|
3362
|
-
async newFromRevision(e, t, i = !1) {
|
|
3363
|
-
return await this.createInstance({ revids: e, rvsection: t }, i);
|
|
3364
|
-
}
|
|
3365
|
-
newBlankPage(e = {}) {
|
|
3366
|
-
return this.WikiPage.newBlankPage(e);
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
class Ee extends I {
|
|
3370
|
-
constructor(e) {
|
|
3371
|
-
super(e, "wikiTitle", !0), this.ctx = e, this.logger = this.ctx.logger("WikiTitleService"), this._cachedTitles = /* @__PURE__ */ new Map(), this.wiki = this.ctx.wiki, this.wikiBaseUrl = this.wiki.baseUrl, this.wikiArticlePath = this.wiki.articlePath.replace("$1", ""), this.wikiArticleBaseUrl = this.wiki.articleBaseUrl.replace("$1", ""), this.wikiIndexPhpUrl = this.wiki.getSciprtUrl("index.php"), this.Title = xt(this.ctx.wiki.siteInfo);
|
|
3372
|
-
}
|
|
3373
|
-
static {
|
|
3374
|
-
this.inject = ["wiki", "wikiPage"];
|
|
3375
|
-
}
|
|
3376
|
-
newTitle(e, t) {
|
|
3377
|
-
return new this.Title(e, t);
|
|
3378
|
-
}
|
|
3379
|
-
newMainPageTitle() {
|
|
3380
|
-
return this.newTitle(this.ctx.wiki.mainPageName);
|
|
3381
|
-
}
|
|
3382
|
-
async newTitleFromUrl(e) {
|
|
3383
|
-
const t = this.parseWikiLink(e);
|
|
3384
|
-
return t?.title ? t.title : t?.pageId ? this.newTitleFromPageId(t.pageId) : null;
|
|
3385
|
-
}
|
|
3386
|
-
async newTitleFromAnyId(e, t = !1) {
|
|
3387
|
-
const { title: i, pageId: s, revId: n } = e ?? {};
|
|
3388
|
-
if (typeof i == "string")
|
|
3389
|
-
return this.newTitle(i);
|
|
3390
|
-
let o, a;
|
|
3391
|
-
if (n ? (o = parseInt(n.toString(), 10), a = "revid") : s && (o = parseInt(s.toString(), 10), a = "pageid"), !o || !a || isNaN(o) || o <= 0)
|
|
3392
|
-
throw new Error("Invalid id or kind", { cause: e });
|
|
3393
|
-
if (!t && this._cachedTitles.has(`${a}:${o}`))
|
|
3394
|
-
return await this._cachedTitles.get(`${a}:${o}`);
|
|
3395
|
-
const { promise: c, resolve: l, reject: h } = je();
|
|
3396
|
-
this._cachedTitles.set(`${a}:${o}`, c);
|
|
3397
|
-
try {
|
|
3398
|
-
const { wikiPage: d } = this.ctx;
|
|
3399
|
-
let u = null;
|
|
3400
|
-
if (a === "pageid")
|
|
3401
|
-
u = await d.newFromPageId(o);
|
|
3402
|
-
else if (a === "revid")
|
|
3403
|
-
u = await d.newFromRevision(o);
|
|
3404
|
-
else
|
|
3405
|
-
throw new Error(`Invalid kind: ${a}`);
|
|
3406
|
-
l(this.newTitle(u.title));
|
|
3407
|
-
} catch (d) {
|
|
3408
|
-
this._cachedTitles.delete(`${a}:${o}`), h(d);
|
|
3409
|
-
}
|
|
3410
|
-
return c;
|
|
3411
|
-
}
|
|
3412
|
-
async newTitleFromPageId(e) {
|
|
3413
|
-
return this.newTitleFromAnyId({ pageId: e });
|
|
3414
|
-
}
|
|
3415
|
-
async newTitleFromRevision(e) {
|
|
3416
|
-
return this.newTitleFromAnyId({ revId: e });
|
|
3417
|
-
}
|
|
3418
|
-
/**
|
|
3419
|
-
* Resolve **special** special pages to it's real target
|
|
3420
|
-
*
|
|
3421
|
-
* If target is self or cannot be resolved, return null
|
|
3422
|
-
* @example
|
|
3423
|
-
* ```
|
|
3424
|
-
* Special:MyPage -> User:<username>
|
|
3425
|
-
* Special:Edit/Page_Title -> Page_Title
|
|
3426
|
-
* Special:NewSection/Page_Title -> Page_Title (section=new)
|
|
3427
|
-
* ```
|
|
3428
|
-
*/
|
|
3429
|
-
resolveSpecialPageTarget(e) {
|
|
3430
|
-
const t = typeof e == "string" ? this.newTitle(e) : e;
|
|
3431
|
-
if (!t || t.getNamespaceId() !== -1)
|
|
3432
|
-
return null;
|
|
3433
|
-
let i, s, n = "view";
|
|
3434
|
-
const o = t.getMainDBKey().split("/").slice(1).join("/") || "";
|
|
3435
|
-
if (t.isSpecial("edit") && o)
|
|
3436
|
-
i = o, n = "edit";
|
|
3437
|
-
else if (t.isSpecial("talkpage") && o) {
|
|
3438
|
-
const a = t.newTitle(o).getTalkPage();
|
|
3439
|
-
if (!a)
|
|
3440
|
-
return null;
|
|
3441
|
-
i = a.getPrefixedDBKey();
|
|
3442
|
-
} else if (t.isSpecial("mypage"))
|
|
3443
|
-
i = t.newTitle(this.ctx.wiki.userInfo.name, 2).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
3444
|
-
else if (t.isSpecial("mytalk"))
|
|
3445
|
-
i = t.newTitle(this.ctx.wiki.userInfo.name, 3).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
3446
|
-
else if (t.isSpecial("newsection") && o)
|
|
3447
|
-
i = o, s = "new", n = "edit";
|
|
3448
|
-
else
|
|
3449
|
-
return null;
|
|
3450
|
-
return {
|
|
3451
|
-
title: new this.Title(i),
|
|
3452
|
-
section: s,
|
|
3453
|
-
action: n
|
|
3454
|
-
};
|
|
3455
|
-
}
|
|
3456
|
-
isWikiLink(e) {
|
|
3457
|
-
return e.startsWith(this.wikiArticleBaseUrl) || e.startsWith(this.wikiIndexPhpUrl) || // Some servers allow index.php to be omitted
|
|
3458
|
-
e.startsWith(`${this.wikiBaseUrl}/?`) || // It's the landing page
|
|
3459
|
-
e === this.ctx.wiki.landingPageUrl;
|
|
3460
|
-
}
|
|
3461
|
-
static {
|
|
3462
|
-
this.REG_SKIPPED_HREF = /^(#|javascript:|vbscript:|file:)/i;
|
|
3463
|
-
}
|
|
3464
|
-
validateHrefAttr(e) {
|
|
3465
|
-
return typeof e != "string" ? !1 : !Ee.REG_SKIPPED_HREF.test(e);
|
|
3466
|
-
}
|
|
3467
|
-
parseWikiLink(e) {
|
|
3468
|
-
if (!e || typeof e == "string" && !this.validateHrefAttr(e))
|
|
3469
|
-
return null;
|
|
3470
|
-
const t = at(e);
|
|
3471
|
-
if (!this.isWikiLink(t.toString()))
|
|
3472
|
-
return null;
|
|
3473
|
-
const i = t.searchParams, s = t.hash.replace("#", ""), n = i.get("action") || "view", o = i.get("title") || "", a = parseInt(i.get("curid") || "0", 10), c = parseInt(i.get("oldid") || "0", 10);
|
|
3474
|
-
let l = o || (() => {
|
|
3475
|
-
try {
|
|
3476
|
-
return decodeURIComponent(t.pathname.substring(this.wikiArticlePath.length));
|
|
3477
|
-
} catch (f) {
|
|
3478
|
-
return this.logger.error("parseLink", t, f), "";
|
|
3479
|
-
}
|
|
3480
|
-
})();
|
|
3481
|
-
l.endsWith("index.php") && (l = "");
|
|
3482
|
-
let h, d, u;
|
|
3483
|
-
if (c)
|
|
3484
|
-
u = c;
|
|
3485
|
-
else if (a)
|
|
3486
|
-
d = a;
|
|
3487
|
-
else if (l)
|
|
3488
|
-
h = this.newTitle(l);
|
|
3489
|
-
else if (t.origin + t.pathname === this.ctx.wiki.landingPageUrl)
|
|
3490
|
-
h = this.newMainPageTitle();
|
|
3491
|
-
else
|
|
3492
|
-
return null;
|
|
3493
|
-
return {
|
|
3494
|
-
title: h,
|
|
3495
|
-
pageId: d,
|
|
3496
|
-
revId: u,
|
|
3497
|
-
url: t,
|
|
3498
|
-
params: i,
|
|
3499
|
-
hash: s,
|
|
3500
|
-
action: n
|
|
3501
|
-
};
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
var Qi = Object.create, ke = Object.defineProperty, Vi = Object.getOwnPropertyDescriptor, ft = (r, e) => (e = Symbol[r]) ? e : Symbol.for("Symbol." + r), gt = (r) => {
|
|
3505
|
-
throw TypeError(r);
|
|
3506
|
-
}, Zi = (r, e, t) => e in r ? ke(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Ji = (r, e) => ke(r, "name", { value: e, configurable: !0 }), es = (r) => [, , , Qi(r?.[ft("metadata")] ?? null)], ts = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], pt = (r) => r !== void 0 && typeof r != "function" ? gt("Function expected") : r, is = (r, e, t, i, s) => ({ kind: ts[r], name: e, metadata: i, addInitializer: (n) => t._ ? gt("Already initialized") : s.push(pt(n || null)) }), ss = (r, e) => Zi(e, ft("metadata"), r[3]), rs = (r, e, t, i) => {
|
|
3507
|
-
for (var s = 0, n = r[e >> 1], o = n && n.length; s < o; s++) n[s].call(t);
|
|
3508
|
-
return i;
|
|
3509
|
-
}, ns = (r, e, t, i, s, n) => {
|
|
3510
|
-
var o, a, c, l = e & 7, h = !1, d = 0, u = r[d] || (r[d] = []), f = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Vi(s, t));
|
|
3511
|
-
Ji(s, t);
|
|
3512
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
3513
|
-
c = is(l, t, a = {}, r[3], u), o = (0, i[g])(s, c), a._ = 1, pt(o) && (s = o);
|
|
3514
|
-
return ss(r, s), f && ke(s, t, f), h ? l ^ 4 ? n : f : s;
|
|
3515
|
-
}, mt, $e, yt;
|
|
3516
|
-
mt = [ne(["storage", "wiki"])];
|
|
3517
|
-
class ie extends (yt = I) {
|
|
3518
|
-
constructor(e) {
|
|
3519
|
-
super(e, "preferences", !0), this.ctx = e, this.db = void 0, this.customRegistries = [], this.categoryDefinitions = [], this._defaultPreferences = {}, e.set("prefs", this), this.db = e.storage.createDatabase(`preferences:${e.wiki.userInfo.id}`, 1 / 0);
|
|
3520
|
-
try {
|
|
3521
|
-
this._migrageFromLegacyMasterDB();
|
|
3522
|
-
} catch {
|
|
3523
|
-
}
|
|
3524
|
-
}
|
|
3525
|
-
get logger() {
|
|
3526
|
-
return this.ctx.logger("PREFERENCES");
|
|
3527
|
-
}
|
|
3528
|
-
async start() {
|
|
3529
|
-
}
|
|
3530
|
-
async get(e, t) {
|
|
3531
|
-
if (!e)
|
|
3532
|
-
return this.getAll();
|
|
3533
|
-
t ??= () => {
|
|
3534
|
-
const s = this.defaultOf(e);
|
|
3535
|
-
return this.logger.debug(e, `(fallback value: ${s})`), s;
|
|
3536
|
-
};
|
|
3537
|
-
const i = await this.db.get(e, void 0);
|
|
3538
|
-
return i !== null ? i : await Lt(t);
|
|
3539
|
-
}
|
|
3540
|
-
/**
|
|
3541
|
-
* 获取全部注册的配置项以及最终生效的值
|
|
3542
|
-
* 未保存的配置项将使用默认值
|
|
3543
|
-
*/
|
|
3544
|
-
async getAll() {
|
|
3545
|
-
const e = this.loadDefaultConfigs();
|
|
3546
|
-
for await (const [t, i] of this.db.entries())
|
|
3547
|
-
t !== "_touched" && t in e && (e[t] = i.value);
|
|
3548
|
-
return e;
|
|
3549
|
-
}
|
|
3550
|
-
async set(e, t) {
|
|
3551
|
-
return (await this.setMany({ [e]: t }))[e];
|
|
3552
|
-
}
|
|
3553
|
-
async setMany(e) {
|
|
3554
|
-
const t = this.loadDefaultConfigs(), i = {};
|
|
3555
|
-
for (const [s, n] of Object.entries(e))
|
|
3556
|
-
n === t[s] || n === void 0 ? i[s] = void 0 : i[s] = n;
|
|
3557
|
-
return await this.db.set(i), this.ctx.emit("preferences/changed", { ctx: this.ctx, input: e, changes: i }), i;
|
|
3558
|
-
}
|
|
3559
|
-
defaultOf(e) {
|
|
3560
|
-
return this._defaultPreferences[e] ??= this.loadDefaultConfigs()[e];
|
|
3561
|
-
}
|
|
3562
|
-
/**
|
|
3563
|
-
* Get exportable configurations
|
|
3564
|
-
* - exclude values that are the same as the default value
|
|
3565
|
-
* - exclude invalid or undefined values
|
|
3566
|
-
* - sort by keys
|
|
3567
|
-
*/
|
|
3568
|
-
async getExportableRecord(e) {
|
|
3569
|
-
e ??= await this.getAll();
|
|
3570
|
-
const t = this.loadDefaultConfigs(), i = {};
|
|
3571
|
-
return Object.entries(t).sort(([s], [n]) => s.localeCompare(n)).forEach(([s, n]) => {
|
|
3572
|
-
const o = e[s];
|
|
3573
|
-
o !== void 0 && o !== n && (i[s] = o);
|
|
3574
|
-
}), i;
|
|
3575
|
-
}
|
|
3576
|
-
loadDefaultConfigs() {
|
|
3577
|
-
const e = {};
|
|
3578
|
-
return this.getConfigRegistries().forEach((t) => {
|
|
3579
|
-
try {
|
|
3580
|
-
const i = t.schema({});
|
|
3581
|
-
Object.entries(i).forEach(([s, n]) => {
|
|
3582
|
-
e[s] = n;
|
|
3583
|
-
});
|
|
3584
|
-
} catch {
|
|
3585
|
-
}
|
|
3586
|
-
}), Object.entries(e).forEach(([t, i]) => {
|
|
3587
|
-
this._defaultPreferences[t] = i;
|
|
3588
|
-
}), e;
|
|
3589
|
-
}
|
|
3590
|
-
registerCustomConfig(e, t, i) {
|
|
3591
|
-
const s = {
|
|
3592
|
-
name: e,
|
|
3593
|
-
schema: t,
|
|
3594
|
-
category: i || "general"
|
|
3595
|
-
}, n = this.customRegistries.findIndex((o) => o.name === e);
|
|
3596
|
-
return n >= 0 ? this.customRegistries[n] = s : this.customRegistries.push(s), this;
|
|
3597
|
-
}
|
|
3598
|
-
getConfigRegistries(e) {
|
|
3599
|
-
return Array.from(this.ctx.registry.entries()).map(([t]) => t === null ? {
|
|
3600
|
-
name: "@root",
|
|
3601
|
-
schema: re?.PreferencesSchema || null
|
|
3602
|
-
} : {
|
|
3603
|
-
name: t.name,
|
|
3604
|
-
schema: t?.PreferencesSchema || null
|
|
3605
|
-
}).filter((t) => t.schema !== null).map((t) => ({
|
|
3606
|
-
...t,
|
|
3607
|
-
category: t.schema.meta.category || "general"
|
|
3608
|
-
})).concat(this.customRegistries).filter((t) => !e || t.category === e);
|
|
3609
|
-
}
|
|
3610
|
-
getAllSchema() {
|
|
3611
|
-
return new m(
|
|
3612
|
-
m.intersect(this.getConfigRegistries().map((e) => e.schema))
|
|
3613
|
-
);
|
|
3614
|
-
}
|
|
3615
|
-
defineCategory(e) {
|
|
3616
|
-
const t = this.categoryDefinitions.findIndex((i) => i.name === e.name);
|
|
3617
|
-
return t < 0 ? this.categoryDefinitions.push(e) : this.categoryDefinitions[t] = e, this.categoryDefinitions.sort((i, s) => (i.index ?? 0) - (s.index ?? 0)), this;
|
|
3618
|
-
}
|
|
3619
|
-
getConfigCategories() {
|
|
3620
|
-
return this.categoryDefinitions;
|
|
3621
|
-
}
|
|
3622
|
-
async _migrageFromLegacyMasterDB() {
|
|
3623
|
-
const e = this.ctx.storage.createDatabase("preferences", 1 / 0);
|
|
3624
|
-
let t = 0;
|
|
3625
|
-
for await (const [i, s] of e.entries())
|
|
3626
|
-
i !== "_touched" && (await this.db.set(i, s.value), t++);
|
|
3627
|
-
return t && this.logger.info(`Migrated ${t} preferences from master DB`), await e.clear(), await e?.db?.disconnect?.(), t;
|
|
3628
|
-
}
|
|
3629
|
-
}
|
|
3630
|
-
$e = es(yt);
|
|
3631
|
-
ie = ns($e, 0, "PreferencesService", mt, ie);
|
|
3632
|
-
rs($e, 1, ie);
|
|
3633
|
-
const wt = "", bt = "", os = /\\\{/g, as = /\\\}/g, ls = new RegExp(wt, "g"), cs = new RegExp(bt, "g");
|
|
3634
|
-
function Be(r) {
|
|
3635
|
-
const e = r ? { ...r } : void 0;
|
|
3636
|
-
return (i, ...s) => hs(e, i, ...s);
|
|
3637
|
-
}
|
|
3638
|
-
function hs(r, e, ...t) {
|
|
3639
|
-
if (!e) return "";
|
|
3640
|
-
let i = String(e).replace(os, wt).replace(as, bt), s = {}, n = [];
|
|
3641
|
-
t.length === 1 && Array.isArray(t[0]) ? n = t[0] : t.length === 1 && us(t[0]) ? s = t[0] : t.length > 0 && (n = t);
|
|
3642
|
-
const o = /* @__PURE__ */ Object.create(null);
|
|
3643
|
-
if (n && n.length)
|
|
3644
|
-
for (let a = 0; a < n.length; a++)
|
|
3645
|
-
o[`$${a + 1}`] = n[a];
|
|
3646
|
-
if (s && Object.keys(s).length)
|
|
3647
|
-
for (const a of Object.keys(s)) o[a] = s[a];
|
|
3648
|
-
if (r && Object.keys(r).length)
|
|
3649
|
-
for (const a of Object.keys(r))
|
|
3650
|
-
typeof o[a] > "u" && (o[a] = r[a]);
|
|
3651
|
-
return i = i.replace(/\{\{\s*([\s\S]*?)\s*\}\}/g, (a, c) => {
|
|
3652
|
-
const l = String(c).trim();
|
|
3653
|
-
if (!l) return "";
|
|
3654
|
-
try {
|
|
3655
|
-
const h = ds(l, o);
|
|
3656
|
-
return h == null ? "" : String(h);
|
|
3657
|
-
} catch {
|
|
3658
|
-
return "";
|
|
3659
|
-
}
|
|
3660
|
-
}), i.replace(ls, "{").replace(cs, "}");
|
|
3661
|
-
}
|
|
3662
|
-
function us(r) {
|
|
3663
|
-
return typeof r == "object" && r !== null && r.constructor === Object;
|
|
3664
|
-
}
|
|
3665
|
-
const ds = fs();
|
|
3666
|
-
function fs() {
|
|
3667
|
-
const r = /* @__PURE__ */ new Set([
|
|
3668
|
-
"eval",
|
|
3669
|
-
"Object",
|
|
3670
|
-
"Array",
|
|
3671
|
-
"String",
|
|
3672
|
-
"Number",
|
|
3673
|
-
"Boolean",
|
|
3674
|
-
"Date",
|
|
3675
|
-
"Math",
|
|
3676
|
-
"JSON",
|
|
3677
|
-
"undefined",
|
|
3678
|
-
"null",
|
|
3679
|
-
"true",
|
|
3680
|
-
"false",
|
|
3681
|
-
"NaN",
|
|
3682
|
-
"Infinity",
|
|
3683
|
-
"isNaN",
|
|
3684
|
-
"isFinite",
|
|
3685
|
-
"parseInt",
|
|
3686
|
-
"parseFloat"
|
|
3687
|
-
]), e = new Function(
|
|
3688
|
-
"__expr__",
|
|
3689
|
-
"ctx",
|
|
3690
|
-
`
|
|
3691
|
-
try {
|
|
3692
|
-
with (ctx) {
|
|
3693
|
-
return (eval(__expr__));
|
|
3694
|
-
}
|
|
3695
|
-
} catch (e) {
|
|
3696
|
-
throw e;
|
|
3697
|
-
}
|
|
3698
|
-
`
|
|
3699
|
-
);
|
|
3700
|
-
return (t, i) => {
|
|
3701
|
-
const s = new Proxy(i, {
|
|
3702
|
-
has: (n, o) => typeof o == "symbol" ? o in n : !(typeof o == "string" && (r.has(o) || o === "__expr__")),
|
|
3703
|
-
get: (n, o) => {
|
|
3704
|
-
if (o in n)
|
|
3705
|
-
return n[o];
|
|
3706
|
-
}
|
|
3707
|
-
});
|
|
3708
|
-
return e(t, s);
|
|
3709
|
-
};
|
|
3710
|
-
}
|
|
3711
|
-
function O(r, e) {
|
|
3712
|
-
let t = r[0] ?? "";
|
|
3713
|
-
for (let i = 0; i < e.length; i++)
|
|
3714
|
-
t += String(e[i]) + (r[i + 1] ?? "");
|
|
3715
|
-
return t;
|
|
3716
|
-
}
|
|
3717
|
-
class gs {
|
|
3718
|
-
constructor(e, t) {
|
|
3719
|
-
this.languages = /* @__PURE__ */ new Map(), this.currentLanguage = "en", this.missingKeys = /* @__PURE__ */ new Map(), this.usedKeys = /* @__PURE__ */ new Set();
|
|
3720
|
-
const i = t?.language || "en";
|
|
3721
|
-
this.currentLanguage = i, this.interpolate = Be(t?.globals), e && Object.keys(e).length && this.setLanguageData(i, e);
|
|
3722
|
-
}
|
|
3723
|
-
setGlobals(e) {
|
|
3724
|
-
return this.interpolate = Be(e), this;
|
|
3725
|
-
}
|
|
3726
|
-
set(e, t) {
|
|
3727
|
-
const i = this.currentLanguage, s = this.ensureLanguageMap(i);
|
|
3728
|
-
if (typeof e == "string" && typeof t == "string")
|
|
3729
|
-
s.set(e, t);
|
|
3730
|
-
else if (typeof e == "object") {
|
|
3731
|
-
const n = this.toStringRecord(e);
|
|
3732
|
-
for (const [o, a] of Object.entries(n))
|
|
3733
|
-
s.set(o, a);
|
|
3734
|
-
}
|
|
3735
|
-
return this;
|
|
3736
|
-
}
|
|
3737
|
-
setLanguageData(e, t) {
|
|
3738
|
-
e = H(e).toLowerCase();
|
|
3739
|
-
const i = this.ensureLanguageMap(e), s = this.toStringRecord(t);
|
|
3740
|
-
for (const [n, o] of Object.entries(s))
|
|
3741
|
-
i.set(n, o);
|
|
3742
|
-
return this;
|
|
3743
|
-
}
|
|
3744
|
-
setLanguage(e) {
|
|
3745
|
-
return e = H(e).toLowerCase(), this.currentLanguage = e, this;
|
|
3746
|
-
}
|
|
3747
|
-
getLanguage() {
|
|
3748
|
-
return this.currentLanguage;
|
|
3749
|
-
}
|
|
3750
|
-
hasLanguage(e) {
|
|
3751
|
-
e = H(e).toLowerCase();
|
|
3752
|
-
const t = this.languages.get(e);
|
|
3753
|
-
return t && Object.keys(t).length > 0;
|
|
3754
|
-
}
|
|
3755
|
-
toStringRecord(e, t) {
|
|
3756
|
-
const i = {};
|
|
3757
|
-
for (const [s, n] of Object.entries(e)) {
|
|
3758
|
-
const o = t ? `${t}.${s}` : s;
|
|
3759
|
-
if (n && typeof n == "object" && !Array.isArray(n)) {
|
|
3760
|
-
const a = this.toStringRecord(n, o);
|
|
3761
|
-
for (const [c, l] of Object.entries(a))
|
|
3762
|
-
i[c] = String(l);
|
|
3763
|
-
} else
|
|
3764
|
-
i[o] = String(n);
|
|
3765
|
-
}
|
|
3766
|
-
return i;
|
|
3767
|
-
}
|
|
3768
|
-
has(e) {
|
|
3769
|
-
const t = this.resolveLanguageOrder(this.currentLanguage);
|
|
3770
|
-
for (const i of t)
|
|
3771
|
-
if (this.languages.get(i)?.has(e)) return !0;
|
|
3772
|
-
return !1;
|
|
3773
|
-
}
|
|
3774
|
-
get(e) {
|
|
3775
|
-
this.recordUsedKey(e);
|
|
3776
|
-
const t = this.resolveLanguageOrder(this.currentLanguage), i = [];
|
|
3777
|
-
for (const s of t) {
|
|
3778
|
-
const o = this.languages.get(s)?.get(e);
|
|
3779
|
-
if (typeof o < "u")
|
|
3780
|
-
return i.length && this.recordMissing(e, i), o;
|
|
3781
|
-
i.push(s);
|
|
3782
|
-
}
|
|
3783
|
-
i.length && this.recordMissing(e, i);
|
|
3784
|
-
}
|
|
3785
|
-
translate(e, ...t) {
|
|
3786
|
-
if (!e)
|
|
3787
|
-
return "";
|
|
3788
|
-
if (this.currentLanguage === "qqx")
|
|
3789
|
-
return `⧼${e}⧽`;
|
|
3790
|
-
const i = this.get(e);
|
|
3791
|
-
return typeof i > "u" ? this.interpolate(e, ...t) : this.interpolate(i, ...t);
|
|
3792
|
-
}
|
|
3793
|
-
$(...e) {
|
|
3794
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
3795
|
-
const s = e[0], n = e.slice(1), o = O(s, n);
|
|
3796
|
-
return this.translate(o);
|
|
3797
|
-
}
|
|
3798
|
-
const i = e;
|
|
3799
|
-
return (s, ...n) => {
|
|
3800
|
-
const o = O(s, n);
|
|
3801
|
-
return this.translate(o, ...i);
|
|
3802
|
-
};
|
|
3803
|
-
}
|
|
3804
|
-
/**
|
|
3805
|
-
* [payload as template] Return the raw message without interpolation
|
|
3806
|
-
* @example
|
|
3807
|
-
* ```
|
|
3808
|
-
* i18n.rawMsg('Hello, {{ name }}')
|
|
3809
|
-
* // good: "你好,{{ name }}"
|
|
3810
|
-
* // missing: "Hello, {{ name }}"
|
|
3811
|
-
* ```
|
|
3812
|
-
*/
|
|
3813
|
-
translateRaw(e) {
|
|
3814
|
-
return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? e : "";
|
|
3815
|
-
}
|
|
3816
|
-
$raw(...e) {
|
|
3817
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
3818
|
-
const i = e[0], s = e.slice(1), n = O(i, s);
|
|
3819
|
-
return this.translateRaw(n);
|
|
3820
|
-
}
|
|
3821
|
-
return (i, ...s) => {
|
|
3822
|
-
const n = O(i, s);
|
|
3823
|
-
return this.translateRaw(n);
|
|
3824
|
-
};
|
|
3825
|
-
}
|
|
3826
|
-
message(e, ...t) {
|
|
3827
|
-
if (!e)
|
|
3828
|
-
return "";
|
|
3829
|
-
if (this.currentLanguage === "qqx")
|
|
3830
|
-
return `⧼${e}⧽`;
|
|
3831
|
-
const i = this.get(e);
|
|
3832
|
-
return typeof i > "u" ? `(${e})` : this.interpolate(i, ...t);
|
|
3833
|
-
}
|
|
3834
|
-
$$(...e) {
|
|
3835
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
3836
|
-
const s = e[0], n = e.slice(1), o = O(s, n);
|
|
3837
|
-
return this.message(o);
|
|
3838
|
-
}
|
|
3839
|
-
const i = e;
|
|
3840
|
-
return (s, ...n) => {
|
|
3841
|
-
const o = O(s, n);
|
|
3842
|
-
return this.message(o, ...i);
|
|
3843
|
-
};
|
|
3844
|
-
}
|
|
3845
|
-
/**
|
|
3846
|
-
* [payload as key] Return the raw message without interpolation
|
|
3847
|
-
* @example
|
|
3848
|
-
* ```
|
|
3849
|
-
* i18n.rawMsg('greeting')
|
|
3850
|
-
* // good: "你好,{{ name }}"
|
|
3851
|
-
* // missing: "(greeting)"
|
|
3852
|
-
* ```
|
|
3853
|
-
*/
|
|
3854
|
-
messageRaw(e) {
|
|
3855
|
-
return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? `(${e})` : "";
|
|
3856
|
-
}
|
|
3857
|
-
$$raw(...e) {
|
|
3858
|
-
if (Array.isArray(e[0]) && e[0].raw) {
|
|
3859
|
-
const i = e[0], s = e.slice(1), n = O(i, s);
|
|
3860
|
-
return this.messageRaw(n);
|
|
3861
|
-
}
|
|
3862
|
-
return (i, ...s) => {
|
|
3863
|
-
const n = O(i, s);
|
|
3864
|
-
return this.messageRaw(n);
|
|
3865
|
-
};
|
|
3866
|
-
}
|
|
3867
|
-
getAvailableLanguages() {
|
|
3868
|
-
return Array.from(this.languages.keys());
|
|
3869
|
-
}
|
|
3870
|
-
ensureLanguageMap(e) {
|
|
3871
|
-
let t = this.languages.get(e);
|
|
3872
|
-
return t || (t = /* @__PURE__ */ new Map(), this.languages.set(e, t)), t;
|
|
3873
|
-
}
|
|
3874
|
-
resolveLanguageOrder(e) {
|
|
3875
|
-
const t = e;
|
|
3876
|
-
return t === "en" ? ["en"] : [t, "en"];
|
|
3877
|
-
}
|
|
3878
|
-
/**
|
|
3879
|
-
* 获取缺失键报告:
|
|
3880
|
-
* { foo: ['zh', 'zh-hans', 'en'] }
|
|
3881
|
-
*/
|
|
3882
|
-
getMissingReport() {
|
|
3883
|
-
return Object.fromEntries(this.missingKeys.entries());
|
|
3884
|
-
}
|
|
3885
|
-
/**
|
|
3886
|
-
* 清空缺失键记录
|
|
3887
|
-
*/
|
|
3888
|
-
clearMissingReport() {
|
|
3889
|
-
this.missingKeys.clear();
|
|
3890
|
-
}
|
|
3891
|
-
recordMissing(e, t) {
|
|
3892
|
-
if (!t.length) return;
|
|
3893
|
-
const i = this.missingKeys.get(e) || [];
|
|
3894
|
-
for (const s of t)
|
|
3895
|
-
i.includes(s) || i.push(s);
|
|
3896
|
-
this.missingKeys.set(e, i);
|
|
3897
|
-
}
|
|
3898
|
-
recordUsedKey(e) {
|
|
3899
|
-
this.usedKeys.add(e);
|
|
3900
|
-
}
|
|
3901
|
-
getUsedKeys() {
|
|
3902
|
-
return Array.from(this.usedKeys);
|
|
3903
|
-
}
|
|
3904
|
-
generateBlankKeyRecord() {
|
|
3905
|
-
const e = {};
|
|
3906
|
-
for (const t of this.getUsedKeys())
|
|
3907
|
-
e[t] = "";
|
|
3908
|
-
return e;
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
var ps = Object.create, Re = Object.defineProperty, ms = Object.getOwnPropertyDescriptor, vt = (r, e) => (e = Symbol[r]) ? e : Symbol.for("Symbol." + r), _t = (r) => {
|
|
3912
|
-
throw TypeError(r);
|
|
3913
|
-
}, ys = (r, e, t) => e in r ? Re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ws = (r, e) => Re(r, "name", { value: e, configurable: !0 }), bs = (r) => [, , , ps(r?.[vt("metadata")] ?? null)], vs = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], St = (r) => r !== void 0 && typeof r != "function" ? _t("Function expected") : r, _s = (r, e, t, i, s) => ({ kind: vs[r], name: e, metadata: i, addInitializer: (n) => t._ ? _t("Already initialized") : s.push(St(n || null)) }), Ss = (r, e) => ys(e, vt("metadata"), r[3]), Es = (r, e, t, i) => {
|
|
3914
|
-
for (var s = 0, n = r[e >> 1], o = n && n.length; s < o; s++) n[s].call(t);
|
|
3915
|
-
return i;
|
|
3916
|
-
}, ks = (r, e, t, i, s, n) => {
|
|
3917
|
-
var o, a, c, l = e & 7, h = !1, d = 0, u = r[d] || (r[d] = []), f = l && (s = s.prototype, l < 5 && (l > 3 || !h) && ms(s, t));
|
|
3918
|
-
ws(s, t);
|
|
3919
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
3920
|
-
c = _s(l, t, a = {}, r[3], u), o = (0, i[g])(s, c), a._ = 1, St(o) && (s = o);
|
|
3921
|
-
return Ss(r, s), f && Re(s, t, f), h ? l ^ 4 ? n : f : s;
|
|
3922
|
-
}, Et, xe, kt;
|
|
3923
|
-
const Ne = new m(
|
|
3924
|
-
m.object({
|
|
3925
|
-
manifest_version: m.const(1).required(),
|
|
3926
|
-
base_language: m.string().required(),
|
|
3927
|
-
last_modified: m.string().required(),
|
|
3928
|
-
languages: m.dict(
|
|
3929
|
-
m.object({
|
|
3930
|
-
file: m.string().required(),
|
|
3931
|
-
fallback: m.string(),
|
|
3932
|
-
iso_name: m.string(),
|
|
3933
|
-
endonym: m.string(),
|
|
3934
|
-
data: m.transform(
|
|
3935
|
-
m.dict(m.any()).default({}),
|
|
3936
|
-
(r) => Object.keys(r).length > 0 ? r : void 0
|
|
3937
|
-
)
|
|
3938
|
-
})
|
|
3939
|
-
).required()
|
|
3940
|
-
})
|
|
3941
|
-
);
|
|
3942
|
-
Et = [ne(["wiki", "preferences"]), At(
|
|
3943
|
-
m.object({
|
|
3944
|
-
"i18n.index_url": m.string().description("I18n index URL (DO NOT CHANGE THIS) ").default(
|
|
3945
|
-
qe.I18N_INDEX_URL
|
|
3946
|
-
)
|
|
3947
|
-
}).description("").extra("category", "general")
|
|
3948
|
-
)];
|
|
3949
|
-
class se extends (kt = I) {
|
|
3950
|
-
constructor(e) {
|
|
3951
|
-
super(e, "i18n", !1), this.ctx = e, this.logger = void 0, this._indexUrl = void 0, this._indexCache = null, this.manager = void 0, this.i18nIndexDB = void 0, this.i18nDataDB = void 0, this.$ = void 0, this.$raw = void 0, this.$$ = void 0, this.$$raw = void 0, this.logger = this.ctx.logger("I18nService"), this.manager = new gs(
|
|
3952
|
-
{},
|
|
3953
|
-
{
|
|
3954
|
-
language: "",
|
|
3955
|
-
globals: {
|
|
3956
|
-
getUrl: (...t) => e.wiki.getUrl(...t)
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
), this.i18nIndexDB = e.storage.createDatabase(
|
|
3960
|
-
"i18n-index",
|
|
3961
|
-
1e3 * 60 * 60 * 24 * 3,
|
|
3962
|
-
// 3 days
|
|
3963
|
-
this.ctx.version,
|
|
3964
|
-
"indexedDB"
|
|
3965
|
-
), this.i18nDataDB = e.storage.createDatabase(
|
|
3966
|
-
"i18n-data",
|
|
3967
|
-
1e3 * 60 * 60 * 24 * 3,
|
|
3968
|
-
// 3 days
|
|
3969
|
-
this.ctx.version,
|
|
3970
|
-
"indexedDB"
|
|
3971
|
-
), this.$ = this.manager.$.bind(this.manager), this.$raw = this.manager.$raw.bind(this.manager), this.$$ = this.manager.$$.bind(this.manager), this.$$raw = this.manager.$$raw.bind(this.manager);
|
|
3972
|
-
}
|
|
3973
|
-
async start() {
|
|
3974
|
-
this.ctx.preferences.registerCustomConfig(
|
|
3975
|
-
"language",
|
|
3976
|
-
m.object({
|
|
3977
|
-
language: m.union([
|
|
3978
|
-
"@user",
|
|
3979
|
-
"@site",
|
|
3980
|
-
m.string().description("Custom language code")
|
|
3981
|
-
]).description("UI language").default("@user")
|
|
3982
|
-
}).description("UI language")
|
|
3983
|
-
), this.ctx.on("clear-cache", this.onClearCache.bind(this));
|
|
3984
|
-
const e = this._indexUrl = await this.ctx.preferences.get("i18n.index_url") || "";
|
|
3985
|
-
if (!e) {
|
|
3986
|
-
this.logger.error("I18n index URL is not set"), this.setupShortcuts();
|
|
3987
|
-
return;
|
|
3988
|
-
}
|
|
3989
|
-
let t = null;
|
|
3990
|
-
try {
|
|
3991
|
-
t = await this.getI18nIndex(e);
|
|
3992
|
-
} catch (n) {
|
|
3993
|
-
this.logger.error("Failed to fetch i18n index", n), this.setupShortcuts();
|
|
3994
|
-
return;
|
|
3995
|
-
}
|
|
3996
|
-
this._indexCache = t, Object.entries(t.languages).forEach(([n, o]) => {
|
|
3997
|
-
o.data && Object.keys(o.data).length > 0 && this.manager.setLanguageData(n, o.data);
|
|
3998
|
-
});
|
|
3999
|
-
const i = await this.ctx.preferences.get("language"), s = this.normalizeLanguageCode(i);
|
|
4000
|
-
this.logger.debug("Settings", { prefer: i, normalized: s });
|
|
4001
|
-
try {
|
|
4002
|
-
await this.switchLanguage(s), this.logger.info(`Initialized for language: ${this.language}`);
|
|
4003
|
-
} catch (n) {
|
|
4004
|
-
this.logger.error("Failed to fetch i18n index", n), this.manager.setLanguage("en");
|
|
4005
|
-
}
|
|
4006
|
-
this.ctx.preferences.registerCustomConfig(
|
|
4007
|
-
"language",
|
|
4008
|
-
m.object({
|
|
4009
|
-
language: m.union([
|
|
4010
|
-
m.const("@user").description(this.$`Same as your personal language`),
|
|
4011
|
-
m.const("@site").description(this.$`Same as the site language`),
|
|
4012
|
-
...this.getAvailableLanguageCodes().map(
|
|
4013
|
-
({ code: n, endonym: o, iso_name: a }) => m.const(n).description(o || a || n)
|
|
4014
|
-
)
|
|
4015
|
-
]).default("@user")
|
|
4016
|
-
}).description(this.$`InPageEdit UI language`)
|
|
4017
|
-
), this.setupShortcuts(), this.ctx.on("preferences/changed", async ({ changes: n }) => {
|
|
4018
|
-
if (!("language" in n)) return;
|
|
4019
|
-
const o = this.normalizeLanguageCode(await this.ctx.preferences.get("language"));
|
|
4020
|
-
o && o !== this.language && await this.switchLanguage(o);
|
|
4021
|
-
});
|
|
4022
|
-
}
|
|
4023
|
-
setupShortcuts() {
|
|
4024
|
-
if (!this.manager) throw new Error("I18nManager is not initialized");
|
|
4025
|
-
this.ctx.set("$", this.manager.$.bind(this.manager)), this.ctx.set("$raw", this.manager.$raw.bind(this.manager)), this.ctx.set("$$", this.manager.$$.bind(this.manager)), this.ctx.set("$$raw", this.manager.$$raw.bind(this.manager));
|
|
4026
|
-
}
|
|
4027
|
-
normalizeLanguageCode(e) {
|
|
4028
|
-
return !e || typeof e != "string" ? "en" : (e === "@user" && (e = this.ctx.wiki.userInfo.options.language || "en"), e === "@site" && (e = this.ctx.wiki.siteInfo.general.lang || "en"), H(String(e)).toLowerCase());
|
|
4029
|
-
}
|
|
4030
|
-
get language() {
|
|
4031
|
-
return this.manager.getLanguage();
|
|
4032
|
-
}
|
|
4033
|
-
/**
|
|
4034
|
-
* 主动设置偏好值(会触发 preferences/changed,从而热切换)
|
|
4035
|
-
*/
|
|
4036
|
-
async setLanguagePreference(e) {
|
|
4037
|
-
await this.ctx.preferences.set("language", e);
|
|
4038
|
-
}
|
|
4039
|
-
/**
|
|
4040
|
-
* 直接切换到具体语言(不修改偏好值)
|
|
4041
|
-
*/
|
|
4042
|
-
async switchLanguage(e) {
|
|
4043
|
-
const t = this.normalizeLanguageCode(e);
|
|
4044
|
-
await this.ensureLanguageLoaded(t), this.manager.setLanguage(t), this.ctx.emit("i18n/changed", { ctx: this.ctx, language: t });
|
|
4045
|
-
}
|
|
4046
|
-
/**
|
|
4047
|
-
* 为指定语言注册(或合并)消息。
|
|
4048
|
-
* - 推荐加命名空间避免冲突:{ myPlugin: { key: 'value' } }
|
|
4049
|
-
* - 若 language 为当前语言,将立即可用;必要时你可以手动触发 UI 刷新或监听 i18n/changed。
|
|
4050
|
-
*/
|
|
4051
|
-
async registerMessages(e, t, i) {
|
|
4052
|
-
const s = i?.namespace ? { [i.namespace]: t } : t;
|
|
4053
|
-
this.manager.setLanguageData(e, s), e === this.language && this.ctx.emit("i18n/changed", { ctx: this.ctx, language: this.language });
|
|
4054
|
-
}
|
|
4055
|
-
/**
|
|
4056
|
-
* 列出可用语言与文件(来源于 index.json)
|
|
4057
|
-
*/
|
|
4058
|
-
getAvailableLanguageCodes() {
|
|
4059
|
-
if (!this._indexCache) throw new Error("I18n index is not loaded");
|
|
4060
|
-
return Object.entries(this._indexCache.languages).filter(([e, t]) => !t.fallback).reduce(
|
|
4061
|
-
(e, [t, i]) => (e.push({ code: t, ...i }), e),
|
|
4062
|
-
[]
|
|
4063
|
-
);
|
|
4064
|
-
}
|
|
4065
|
-
findLanguageMeta(e, t) {
|
|
4066
|
-
const i = H(String(t)).toLowerCase(), s = e.languages[i];
|
|
4067
|
-
if (s)
|
|
4068
|
-
return {
|
|
4069
|
-
code: i,
|
|
4070
|
-
...s
|
|
4071
|
-
};
|
|
4072
|
-
{
|
|
4073
|
-
const n = e.languages.en;
|
|
4074
|
-
if (n)
|
|
4075
|
-
return {
|
|
4076
|
-
code: "en",
|
|
4077
|
-
...n
|
|
4078
|
-
};
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4081
|
-
async getI18nIndex(e, t = !1) {
|
|
4082
|
-
if (!t) {
|
|
4083
|
-
const s = await this.i18nIndexDB.get(e);
|
|
4084
|
-
if (s)
|
|
4085
|
-
try {
|
|
4086
|
-
return Ne(s);
|
|
4087
|
-
} catch (n) {
|
|
4088
|
-
this.logger.error("Failed to parse cached i18n index", n), this.i18nIndexDB.delete(e);
|
|
4089
|
-
}
|
|
4090
|
-
}
|
|
4091
|
-
const i = await this.fetchI18nIndex(e);
|
|
4092
|
-
return this.i18nIndexDB.set(e, i), i;
|
|
4093
|
-
}
|
|
4094
|
-
async fetchI18nIndex(e) {
|
|
4095
|
-
const t = await fetch(e).then((i) => i.json());
|
|
4096
|
-
return Ne(t);
|
|
4097
|
-
}
|
|
4098
|
-
async ensureLanguageLoaded(e) {
|
|
4099
|
-
if (!this.manager || !this._indexCache) throw new Error("I18nManager is not initialized");
|
|
4100
|
-
if (this.manager.hasLanguage(e))
|
|
4101
|
-
return this.logger.debug("Language already loaded", e);
|
|
4102
|
-
const t = await this.getLanguageData(e);
|
|
4103
|
-
this.manager.setLanguageData(e, t), this.logger.debug("Language data ensured", e, t);
|
|
4104
|
-
}
|
|
4105
|
-
async getLanguageData(e, t = !1) {
|
|
4106
|
-
if (!this._indexCache) throw new Error("I18n index is not loaded");
|
|
4107
|
-
const i = this.findLanguageMeta(this._indexCache, e);
|
|
4108
|
-
if (!i) return {};
|
|
4109
|
-
const s = `${this._indexUrl}#${i.file}`;
|
|
4110
|
-
if (!t) {
|
|
4111
|
-
const o = await this.i18nDataDB.get(s);
|
|
4112
|
-
if (o && Object.keys(o).length > 0)
|
|
4113
|
-
return this.logger.debug("Using cached language data", e, o), o;
|
|
4114
|
-
}
|
|
4115
|
-
const n = i.data || await fetch(new URL(i.file, this._indexUrl).toString()).then((o) => o.json());
|
|
4116
|
-
return this.i18nDataDB.set(s, n), this.logger.debug("Language data fetched", e, i.file, n), n;
|
|
4117
|
-
}
|
|
4118
|
-
/**
|
|
4119
|
-
* 获取缺失键报告,形如:
|
|
4120
|
-
* { foo: ['zh', 'zh-hans', 'en'] }
|
|
4121
|
-
*/
|
|
4122
|
-
getMissingReport() {
|
|
4123
|
-
return this.manager.getMissingReport();
|
|
4124
|
-
}
|
|
4125
|
-
/**
|
|
4126
|
-
* 清空缺失键记录
|
|
4127
|
-
*/
|
|
4128
|
-
clearMissingReport() {
|
|
4129
|
-
this.manager.clearMissingReport();
|
|
4130
|
-
}
|
|
4131
|
-
async onClearCache() {
|
|
4132
|
-
await this.i18nIndexDB.clear(), await this.i18nDataDB.clear();
|
|
4133
|
-
}
|
|
4134
|
-
}
|
|
4135
|
-
xe = bs(kt);
|
|
4136
|
-
se = ks(xe, 0, "I18nService", Et, se);
|
|
4137
|
-
Es(xe, 1, se);
|
|
4138
|
-
class re extends Tt {
|
|
4139
|
-
constructor(e) {
|
|
4140
|
-
super({
|
|
4141
|
-
name: "InPageEdit"
|
|
4142
|
-
}), this.version = "0.14.1", this.Endpoints = qe, this.schema = m, this.config = K(re.DEFAULT_CONFIG, e), this.logger = Mt({
|
|
4143
|
-
name: "IPE",
|
|
4144
|
-
color: "#33aaff",
|
|
4145
|
-
level: this.config.logLevel
|
|
4146
|
-
}), this.#e();
|
|
4147
|
-
}
|
|
4148
|
-
static {
|
|
4149
|
-
this.DEFAULT_CONFIG = {
|
|
4150
|
-
apiConfigs: {},
|
|
4151
|
-
legacyPreferences: {},
|
|
4152
|
-
logLevel: Fe.info,
|
|
4153
|
-
storageNamespace: "InPageEdit",
|
|
4154
|
-
autoloadStyles: !0,
|
|
4155
|
-
autoInstallCorePlugins: !0
|
|
4156
|
-
};
|
|
4157
|
-
}
|
|
4158
|
-
async #e() {
|
|
4159
|
-
await this.#i(), this.config.autoInstallCorePlugins && this.#s(), this.#r();
|
|
4160
|
-
}
|
|
4161
|
-
async #i() {
|
|
4162
|
-
this.plugin(se), this.plugin(Qt, this.config.apiConfigs), this.plugin(J), this.plugin(ai), this.plugin(Ii), this.plugin(ie), this.plugin(Yi, { dbName: this.config.storageNamespace }), this.plugin(te), this.plugin(Xi), this.plugin(Ee), this.#t([
|
|
4163
|
-
"i18n",
|
|
4164
|
-
"$",
|
|
4165
|
-
"$$",
|
|
4166
|
-
"api",
|
|
4167
|
-
"currentPage",
|
|
4168
|
-
"resourceLoader",
|
|
4169
|
-
"modal",
|
|
4170
|
-
"preferences",
|
|
4171
|
-
"storage",
|
|
4172
|
-
"wikiPage",
|
|
4173
|
-
"wikiTitle",
|
|
4174
|
-
// WikiMetadataService
|
|
4175
|
-
"wiki",
|
|
4176
|
-
"getUrl",
|
|
4177
|
-
"getSciprtUrl",
|
|
4178
|
-
"getMainpageUrl"
|
|
4179
|
-
]);
|
|
4180
|
-
}
|
|
4181
|
-
#t(e) {
|
|
4182
|
-
if (!Array.isArray(e) || e.length === 0) return this;
|
|
4183
|
-
for (const t of e) {
|
|
4184
|
-
const i = this[re.internal][t];
|
|
4185
|
-
i?.type === "service" && (i.builtin = !0);
|
|
4186
|
-
}
|
|
4187
|
-
return this;
|
|
4188
|
-
}
|
|
4189
|
-
// TODO: 这里不应该硬编码,暂时先这样
|
|
4190
|
-
async #s() {
|
|
4191
|
-
[
|
|
4192
|
-
import("./index-Bb0FiU2c.js").then(({ PluginAnalytics: t }) => t),
|
|
4193
|
-
import("./index-BBNseJXG.js").then(
|
|
4194
|
-
({ PluginInArticleLinks: t }) => t
|
|
4195
|
-
),
|
|
4196
|
-
import("./index-DTHY5rAO.js").then(({ PluginPluginStore: t }) => t),
|
|
4197
|
-
import("./index-DELHsLHS.js").then(
|
|
4198
|
-
({ PluginPreferencesUI: t }) => t
|
|
4199
|
-
),
|
|
4200
|
-
import("./index-DmLoihN1.js").then(({ PluginQuickEdit: t }) => t),
|
|
4201
|
-
import("./index-BrYKe18j.js").then(({ PluginQuickMove: t }) => t),
|
|
4202
|
-
import("./index-3NZkG2a3.js").then(
|
|
4203
|
-
({ PluginQuickPreview: t }) => t
|
|
4204
|
-
),
|
|
4205
|
-
import("./index-D97lUU3h.js").then(({ PluginQuickDiff: t }) => t),
|
|
4206
|
-
import("./index-D6zFqL2u.js").then(
|
|
4207
|
-
({ PluginQuickRedirect: t }) => t
|
|
4208
|
-
),
|
|
4209
|
-
import("./index-D-fW3ESK.js").then(({ PluginToolbox: t }) => t)
|
|
4210
|
-
].forEach(async (t) => {
|
|
4211
|
-
this.plugin(await t);
|
|
4212
|
-
});
|
|
4213
|
-
}
|
|
4214
|
-
// TODO: 应该抽象到 PluginTheme 中去,暂时先硬编码
|
|
4215
|
-
async #r() {
|
|
4216
|
-
this.inject(["resourceLoader"], (e) => {
|
|
4217
|
-
this.config.autoloadStyles && e.resourceLoader.loadStyle(import.meta.resolve("./style.css"));
|
|
4218
|
-
});
|
|
4219
|
-
}
|
|
4220
|
-
async withInject(e) {
|
|
4221
|
-
const { promise: t, resolve: i } = je();
|
|
4222
|
-
return this.inject(e, (s) => {
|
|
4223
|
-
i(s);
|
|
4224
|
-
}), t;
|
|
4225
|
-
}
|
|
4226
|
-
}
|
|
4227
|
-
export {
|
|
4228
|
-
Fe as $,
|
|
4229
|
-
Qt as A,
|
|
4230
|
-
J as C,
|
|
4231
|
-
re as I,
|
|
4232
|
-
Ii as M,
|
|
4233
|
-
ee as N,
|
|
4234
|
-
ve as P,
|
|
4235
|
-
ai as R,
|
|
4236
|
-
Mt as S,
|
|
4237
|
-
te as W,
|
|
4238
|
-
Yi as a,
|
|
4239
|
-
v as b,
|
|
4240
|
-
ie as c,
|
|
4241
|
-
Xi as d,
|
|
4242
|
-
Ee as e,
|
|
4243
|
-
It as m
|
|
4244
|
-
};
|
|
4245
|
-
//# sourceMappingURL=index-BgkZW91u.js.map
|