@inpageedit/core 0.12.1 → 0.13.0-alpha.0
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/dist/BasePlugin-Bf2UuIHF.js +64 -0
- package/dist/BasePlugin-Bf2UuIHF.js.map +1 -0
- package/dist/{PluginPrefSync-Ziogy_o-.js → PluginPrefSync-Dn1Xsiqz.js} +6 -4
- package/dist/PluginPrefSync-Dn1Xsiqz.js.map +1 -0
- package/dist/{PluginStoreApp-Bnvyl-Oc.js → PluginStoreApp-CpOLArL7.js} +2 -2
- package/dist/{PluginStoreApp-Bnvyl-Oc.js.map → PluginStoreApp-CpOLArL7.js.map} +1 -1
- package/dist/WatchlistAction-BbNAyryN.js +5 -0
- package/dist/WatchlistAction-BbNAyryN.js.map +1 -0
- package/dist/endpoints-DgyuoRZd.js +1507 -0
- package/dist/endpoints-DgyuoRZd.js.map +1 -0
- package/dist/{index-BvuaLEFc.js → index-2RfILgXm.js} +11 -10
- package/dist/{index-BvuaLEFc.js.map → index-2RfILgXm.js.map} +1 -1
- package/dist/{index-eARjMi7f.js → index-BCdABp0e.js} +23 -22
- package/dist/{index-eARjMi7f.js.map → index-BCdABp0e.js.map} +1 -1
- package/dist/{index-zHTGCjfF.js → index-BJ7_Q1mB.js} +8 -7
- package/dist/{index-zHTGCjfF.js.map → index-BJ7_Q1mB.js.map} +1 -1
- package/dist/{index-Dnmv-xDn.js → index-BNh95-x2.js} +37 -49
- package/dist/index-BNh95-x2.js.map +1 -0
- package/dist/{index-B3FUDhxl.js → index-BQ-cHWkJ.js} +15 -16
- package/dist/{index-B3FUDhxl.js.map → index-BQ-cHWkJ.js.map} +1 -1
- package/dist/{index-B3YJdjxo.js → index-BwdWyHLe.js} +77 -76
- package/dist/{index-B3YJdjxo.js.map → index-BwdWyHLe.js.map} +1 -1
- package/dist/{index-Ccr3YhkP.js → index-CCRMmnwk.js} +10 -9
- package/dist/{index-Ccr3YhkP.js.map → index-CCRMmnwk.js.map} +1 -1
- package/dist/{index-Bd70aDMT.js → index-CnIpUF9x.js} +7 -6
- package/dist/{index-Bd70aDMT.js.map → index-CnIpUF9x.js.map} +1 -1
- package/dist/{index-D5zX93bn.js → index-CyG7_IYz.js} +47 -45
- package/dist/{index-D5zX93bn.js.map → index-CyG7_IYz.js.map} +1 -1
- package/dist/index-DdTiZqwt.js +3744 -0
- package/dist/index-DdTiZqwt.js.map +1 -0
- package/dist/{index-BRjEc8b8.js → index-eSlbrNqF.js} +6 -6
- package/dist/{index-BRjEc8b8.js.map → index-eSlbrNqF.js.map} +1 -1
- package/dist/index.d.ts +1723 -31
- package/dist/index.js +73 -9
- package/dist/index.js.map +1 -1
- package/dist/models/index.js +486 -0
- package/dist/models/index.js.map +1 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/services/index.js +16 -0
- package/dist/services/index.js.map +1 -0
- package/dist/style.css +1 -1
- package/lib/index.umd.js +10 -10
- package/lib/index.umd.js.map +1 -1
- package/package.json +22 -25
- package/dist/InPageEdit.d.ts +0 -42
- package/dist/PluginPrefSync-Ziogy_o-.js.map +0 -1
- package/dist/__test__/utils/constants.d.ts +0 -3
- package/dist/components/ActionButton.d.ts +0 -6
- package/dist/components/CheckBox.d.ts +0 -10
- package/dist/components/Icon/IconEdit.d.ts +0 -2
- package/dist/components/Icon/IconQuickEdit.d.ts +0 -2
- package/dist/components/InputBox.d.ts +0 -11
- package/dist/components/MBox/index.d.ts +0 -14
- package/dist/components/MwUserLinks.d.ts +0 -6
- package/dist/components/ProgressBar/index.d.ts +0 -7
- package/dist/components/RadioBox.d.ts +0 -10
- package/dist/components/TabView/index.d.ts +0 -19
- package/dist/components/TwinSwapInput/index.d.ts +0 -19
- package/dist/components/index.d.ts +0 -8
- package/dist/components/utils.d.ts +0 -4
- package/dist/constants/endpoints.d.ts +0 -8
- package/dist/decorators/Preferences.d.ts +0 -35
- package/dist/index-DgQNTfPR.js +0 -5829
- package/dist/index-DgQNTfPR.js.map +0 -1
- package/dist/index-Dnmv-xDn.js.map +0 -1
- package/dist/models/MemoryStorage.d.ts +0 -10
- package/dist/models/WikiPage/index.d.ts +0 -76
- package/dist/models/WikiPage/types/PageInfo.d.ts +0 -58
- package/dist/models/WikiPage/types/PageParseData.d.ts +0 -17
- package/dist/models/WikiPage/types/WatchlistAction.d.ts +0 -6
- package/dist/models/WikiTitle/index.d.ts +0 -89
- package/dist/models/WikiTitle/index.spec.d.ts +0 -1
- package/dist/plugins/BasePlugin.d.ts +0 -25
- package/dist/plugins/_debug/index.d.ts +0 -8
- package/dist/plugins/analytics/index.d.ts +0 -41
- package/dist/plugins/in-article-links/index.d.ts +0 -44
- package/dist/plugins/plugin-store/index.d.ts +0 -56
- package/dist/plugins/plugin-store/schema.d.ts +0 -41
- package/dist/plugins/preferences-ui/PluginPrefSync.d.ts +0 -28
- package/dist/plugins/preferences-ui/index.d.ts +0 -48
- package/dist/plugins/quick-diff/components/DiffTable.d.ts +0 -23
- package/dist/plugins/quick-diff/index.d.ts +0 -85
- package/dist/plugins/quick-edit/index.d.ts +0 -79
- package/dist/plugins/quick-move/index.d.ts +0 -47
- package/dist/plugins/quick-preview/index.d.ts +0 -37
- package/dist/plugins/quick-redirect/index.d.ts +0 -48
- package/dist/plugins/toolbox/index.d.ts +0 -65
- package/dist/polyfills/Promise.withResolvers.d.ts +0 -5
- package/dist/polyfills/index.d.ts +0 -0
- package/dist/services/ApiService.d.ts +0 -14
- package/dist/services/CurrentPageService.d.ts +0 -28
- package/dist/services/ModalService.d.ts +0 -27
- package/dist/services/PreferencesService.d.ts +0 -94
- package/dist/services/ResourceLoaderService.d.ts +0 -17
- package/dist/services/WikiMetadataService.d.ts +0 -108
- package/dist/services/WikiPageService.d.ts +0 -20
- package/dist/services/WikiTitleService.d.ts +0 -70
- package/dist/services/storage/index.d.ts +0 -40
- package/dist/services/storage/managers/IDBStorageManager.d.ts +0 -28
- package/dist/services/storage/managers/LocalStorageManager.d.ts +0 -27
- package/dist/types/WikiMetadata.d.ts +0 -131
- package/dist/utils/computeable.d.ts +0 -2
- package/dist/utils/defineAsyncPlugin.d.ts +0 -2
- package/dist/utils/interpolate.d.ts +0 -20
- package/dist/utils/interpolate.spec.d.ts +0 -1
- package/dist/utils/makeCallable.d.ts +0 -3
- package/dist/utils/noop.d.ts +0 -1
- package/dist/utils/sleep.d.ts +0 -1
- package/dist/utils/string.d.ts +0 -7
- package/dist/utils/url.d.ts +0 -24
- package/dist/utils/vueHooks.d.ts +0 -6
- package/dist/utils/vueReactivity.d.ts +0 -2
|
@@ -0,0 +1,3744 @@
|
|
|
1
|
+
import { useMemoryStorage as ht, createWikiPageModel as ut, createWikiTitleModel as dt } from "./models/index.js";
|
|
2
|
+
import { a as I, I as de, S as W, p as Pe, C as ft, E as pt } from "./endpoints-DgyuoRZd.js";
|
|
3
|
+
import { j as E, P as mt } from "./index-CM_6yF2v.js";
|
|
4
|
+
var Ie = /* @__PURE__ */ ((s) => (s[s.debug = -1] = "debug", s[s.log = 0] = "log", s[s.info = 1] = "info", s[s.warn = 2] = "warn", s[s.error = 3] = "error", s[s.silent = 4] = "silent", s))(Ie || {});
|
|
5
|
+
const oe = globalThis || window, ae = Symbol.for("__IPE_LOGGER_COLOR_MAP__");
|
|
6
|
+
oe[ae] || (oe[ae] = /* @__PURE__ */ new Map());
|
|
7
|
+
const re = oe[ae];
|
|
8
|
+
function z(s) {
|
|
9
|
+
let e = 2166136261;
|
|
10
|
+
for (let t = 0; t < s.length; t++)
|
|
11
|
+
e ^= s.charCodeAt(t), e = (e >>> 0) * 16777619;
|
|
12
|
+
return e >>> 0;
|
|
13
|
+
}
|
|
14
|
+
const _e = [
|
|
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 gt(s, e) {
|
|
27
|
+
const t = _e.length, i = z(s) % t, [r, n] = _e[i], o = n - r, a = z(s + ":" + e), c = r + a % (o || 1), l = z(s + ":s"), h = z(s + ":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, p = c >= 200 && c <= 300;
|
|
33
|
+
d = 55 + l % 20, p ? 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 Y(s, e) {
|
|
38
|
+
if (e)
|
|
39
|
+
return re.set(s, e), e;
|
|
40
|
+
const t = re.get(s);
|
|
41
|
+
if (t) return t;
|
|
42
|
+
const i = s.startsWith("name:") ? "name" : "group", r = gt(s, i);
|
|
43
|
+
return re.set(s, r), r;
|
|
44
|
+
}
|
|
45
|
+
let yt = class De {
|
|
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 Re;
|
|
52
|
+
const [i, r] = this._prefix(t.label);
|
|
53
|
+
return this._consoleMethod(t.method).bind(console, i, ...r);
|
|
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 && Y(`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 bt(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 && Y(`group:${e}`, t?.color), new De({
|
|
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 = wt[e];
|
|
111
|
+
if (!this._enabled(t.level)) return Re;
|
|
112
|
+
const [i, r] = this._prefix(t.label);
|
|
113
|
+
return this._consoleMethod(e).bind(console, i, ...r);
|
|
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 r = Y(`name:${this._name}`, this._nameColor);
|
|
126
|
+
i += `%c${this._name}%c`, t.push(
|
|
127
|
+
`background:${r}; color:#fff; padding:1px 4px; border-radius:2px; font-weight:700;`,
|
|
128
|
+
Te
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
if (e && (i += ` ${e}`), this._groupPath.length) {
|
|
132
|
+
const r = this._groupPath.join("/"), n = Y(`group:${r}`);
|
|
133
|
+
i += ` %c${r}%c`, t.push(`color:${n}; text-decoration: underline;`, Te);
|
|
134
|
+
}
|
|
135
|
+
return [i, t];
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const Re = () => {
|
|
139
|
+
}, Te = "color:inherit; background:transparent; text-decoration:none;", wt = {
|
|
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 bt(s) {
|
|
147
|
+
const e = function(t, i) {
|
|
148
|
+
return s.group(t, i);
|
|
149
|
+
};
|
|
150
|
+
return new Proxy(e, {
|
|
151
|
+
get(t, i, r) {
|
|
152
|
+
return s[i];
|
|
153
|
+
},
|
|
154
|
+
set(t, i, r) {
|
|
155
|
+
return s[i] = r, !0;
|
|
156
|
+
},
|
|
157
|
+
apply(t, i, r) {
|
|
158
|
+
return s.group(r[0], r[1]);
|
|
159
|
+
},
|
|
160
|
+
has(t, i) {
|
|
161
|
+
return i in s;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function vt(s) {
|
|
166
|
+
return new yt(s);
|
|
167
|
+
}
|
|
168
|
+
var T = /* @__PURE__ */ ((s) => (s.BODY_USED = "BODY_USED", s.NO_BODY_READER = "NO_BODY_READER", s.TIMEOUT = "TIMEOUT", s.NETWORK_ERROR = "NETWORK_ERROR", s.BODY_NOT_ALLOWED = "BODY_NOT_ALLOWED", s.HOOK_CONTEXT_CHANGED = "HOOK_CONTEXT_CHANGED", s.ABORTED_BY_HOOK = "ABORTED_BY_HOOK", s.INVALID_HOOK_CALLBACK = "INVALID_HOOK_CALLBACK", s.UNEXPECTED_HOOK_RETURN = "UNEXPECTED_HOOK_RETURN", s))(T || {});
|
|
169
|
+
let _ = class Me extends Error {
|
|
170
|
+
constructor(e, t, i, r) {
|
|
171
|
+
super(t, r), this.code = e, this.context = i;
|
|
172
|
+
}
|
|
173
|
+
name = "FexiosError";
|
|
174
|
+
static is(e) {
|
|
175
|
+
return e?.constructor === Me;
|
|
176
|
+
}
|
|
177
|
+
}, St = class Ue 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 === Ue;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
function kt(s, e = 2048) {
|
|
187
|
+
if (!(s instanceof Uint8Array))
|
|
188
|
+
throw new TypeError("Input must be a Uint8Array");
|
|
189
|
+
if (s.length === 0)
|
|
190
|
+
return !0;
|
|
191
|
+
const t = Math.min(
|
|
192
|
+
Math.max(s.length, 256),
|
|
193
|
+
e
|
|
194
|
+
), i = s.slice(0, t);
|
|
195
|
+
if (Et(i))
|
|
196
|
+
return !1;
|
|
197
|
+
const r = _t(i);
|
|
198
|
+
if (r.nullByteRatio > 0.05 || r.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 = Rt(l);
|
|
205
|
+
h > o && (o = h, a = h > 0.7);
|
|
206
|
+
} catch {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
return a;
|
|
210
|
+
}
|
|
211
|
+
function Et(s) {
|
|
212
|
+
if (s.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 (s.length >= t.length) {
|
|
241
|
+
let i = !0;
|
|
242
|
+
for (let r = 0; r < t.length; r++)
|
|
243
|
+
if (s[r] !== t[r]) {
|
|
244
|
+
i = !1;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
if (i) return !0;
|
|
248
|
+
}
|
|
249
|
+
return !1;
|
|
250
|
+
}
|
|
251
|
+
function _t(s) {
|
|
252
|
+
let e = 0, t = 0, i = 0;
|
|
253
|
+
for (const r of s)
|
|
254
|
+
r === 0 && e++, r > 127 && t++, (r < 32 && r !== 9 && r !== 10 && r !== 13 || r === 127) && i++;
|
|
255
|
+
return {
|
|
256
|
+
nullByteRatio: e / s.length,
|
|
257
|
+
highByteRatio: t / s.length,
|
|
258
|
+
controlCharRatio: i / s.length
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function Rt(s) {
|
|
262
|
+
if (s.length === 0) return 1;
|
|
263
|
+
let e = 1, t = 0;
|
|
264
|
+
for (let r = 0; r < s.length; r++) {
|
|
265
|
+
const n = s[r].charCodeAt(0);
|
|
266
|
+
n >= 32 && n <= 126 || n === 9 || n === 10 || n === 13 || n === 32 ? t++ : n > 127 && n < 65534 ? !Tt(n) && !$t(n) && t++ : e -= 0.1;
|
|
267
|
+
}
|
|
268
|
+
const i = t / s.length;
|
|
269
|
+
return e *= i, At(s) && (e *= 1.1), Math.max(0, Math.min(1, e));
|
|
270
|
+
}
|
|
271
|
+
function Tt(s) {
|
|
272
|
+
return s >= 0 && s <= 31 || s >= 127 && s <= 159;
|
|
273
|
+
}
|
|
274
|
+
function $t(s) {
|
|
275
|
+
return s >= 57344 && s <= 63743 || s >= 983040 && s <= 1048573 || s >= 1048576 && s <= 1114109;
|
|
276
|
+
}
|
|
277
|
+
function At(s) {
|
|
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(s));
|
|
292
|
+
}
|
|
293
|
+
function A(s) {
|
|
294
|
+
if (typeof s != "object" || s === null || Object.prototype.toString.call(s) !== "[object Object]")
|
|
295
|
+
return !1;
|
|
296
|
+
const e = Object.getPrototypeOf(s);
|
|
297
|
+
return e === Object.prototype || e === null;
|
|
298
|
+
}
|
|
299
|
+
const F = (s, ...e) => {
|
|
300
|
+
const t = (r) => {
|
|
301
|
+
if (Array.isArray(r)) return r.slice();
|
|
302
|
+
if (A(r)) {
|
|
303
|
+
const n = {};
|
|
304
|
+
for (const o of Reflect.ownKeys(r)) n[o] = t(r[o]);
|
|
305
|
+
return n;
|
|
306
|
+
}
|
|
307
|
+
return r;
|
|
308
|
+
}, i = t(s);
|
|
309
|
+
for (const r of e)
|
|
310
|
+
if (r != null)
|
|
311
|
+
for (const n of Reflect.ownKeys(r)) {
|
|
312
|
+
const o = r[n];
|
|
313
|
+
if (typeof o > "u") continue;
|
|
314
|
+
const a = i[n];
|
|
315
|
+
A(a) && A(o) ? i[n] = F(a, o) : i[n] = t(o);
|
|
316
|
+
}
|
|
317
|
+
return i;
|
|
318
|
+
};
|
|
319
|
+
let B = 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(([r, n]) => {
|
|
322
|
+
this[r] = n;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
ok;
|
|
326
|
+
status;
|
|
327
|
+
statusText;
|
|
328
|
+
headers;
|
|
329
|
+
};
|
|
330
|
+
async function $e(s, e, t) {
|
|
331
|
+
if (s.bodyUsed)
|
|
332
|
+
throw new _(
|
|
333
|
+
T.BODY_USED,
|
|
334
|
+
"Response body has already been used or locked"
|
|
335
|
+
);
|
|
336
|
+
const i = s.headers.get("content-type") || "", r = Number(s.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/") || !kt(c);
|
|
337
|
+
if ((s.status === 101 || s.status === 426 || s.headers.get("upgrade")) && typeof globalThis.WebSocket < "u") {
|
|
338
|
+
const a = new WebSocket(s.url);
|
|
339
|
+
return await new Promise((c, l) => {
|
|
340
|
+
a.onopen = c, a.onerror = l;
|
|
341
|
+
}), new B(s, 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(s.url);
|
|
348
|
+
return await new Promise((c, l) => {
|
|
349
|
+
a.onopen = c, a.onerror = l;
|
|
350
|
+
}), new B(s, a);
|
|
351
|
+
} else {
|
|
352
|
+
if (e === "stream")
|
|
353
|
+
return new B(
|
|
354
|
+
s,
|
|
355
|
+
s.body
|
|
356
|
+
);
|
|
357
|
+
{
|
|
358
|
+
const a = s.clone().body?.getReader();
|
|
359
|
+
if (!a)
|
|
360
|
+
throw new _(
|
|
361
|
+
T.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 && r > 0)) {
|
|
369
|
+
const u = Math.min(c.length / r, 1);
|
|
370
|
+
t(u, c);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const l = new B(s, 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: s.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 St(
|
|
395
|
+
`Request failed with status code ${s.status}`,
|
|
396
|
+
l
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
var X;
|
|
402
|
+
((s) => {
|
|
403
|
+
s.makeSearchParams = (r) => {
|
|
404
|
+
if (!r)
|
|
405
|
+
return new URLSearchParams();
|
|
406
|
+
if (r instanceof URLSearchParams)
|
|
407
|
+
return r;
|
|
408
|
+
if (typeof r != "object" || r?.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("[]"), p = f ? d.slice(0, -2) : d, m = `${l}[${p}]`;
|
|
424
|
+
if (f) {
|
|
425
|
+
const g = `${m}[]`;
|
|
426
|
+
if (Array.isArray(u))
|
|
427
|
+
for (const $ of u) o(g, $?.toString());
|
|
428
|
+
else typeof u == "object" && u !== null && u.constructor === Object ? c(`${m}[]`, u) : o(g, u?.toString());
|
|
429
|
+
} else if (Array.isArray(u))
|
|
430
|
+
for (const g of u) o(m, g?.toString());
|
|
431
|
+
else typeof u == "object" && u !== null && u.constructor === Object ? c(m, u) : a(m, u?.toString());
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
a(l, h?.toString());
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
for (const [l, h] of Object.entries(r))
|
|
439
|
+
c(l, h);
|
|
440
|
+
return n;
|
|
441
|
+
}, s.makeQueryString = (r) => (0, s.makeSearchParams)(r).toString(), s.makeURL = (r, n, o, a) => {
|
|
442
|
+
const c = typeof window < "u" && window.location?.origin || "http://localhost", l = typeof r == "string" ? new URL(r, a ?? c) : new URL(r), h = (0, s.toQueryRecord)(l.searchParams), d = (0, s.mergeQueries)(h, n || {}), u = (0, s.makeSearchParams)(d);
|
|
443
|
+
return l.search = u.toString(), l.hash = o || "", l;
|
|
444
|
+
}, s.toQueryRecord = (r) => {
|
|
445
|
+
typeof r == "string" && (r = (0, s.fromString)(r));
|
|
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 p = l[f];
|
|
457
|
+
f === l.length - 1 ? d ? u[p] === void 0 ? u[p] = [h] : Array.isArray(u[p]) ? u[p].push(h) : u[p] = [u[p], h] : u[p] === void 0 ? u[p] = h : Array.isArray(u[p]) ? u[p].push(h) : u[p] = [u[p], h] : ((u[p] === void 0 || typeof u[p] != "object" || Array.isArray(u[p])) && (u[p] = {}), u = u[p]);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
for (const [c, l] of r.entries()) {
|
|
461
|
+
const { path: h, forceArray: d } = o(String(c));
|
|
462
|
+
a(n, h, l?.toString(), d);
|
|
463
|
+
}
|
|
464
|
+
return n;
|
|
465
|
+
}, s.fromString = (r) => {
|
|
466
|
+
const n = r.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
|
+
}, s.mergeQueries = (r, ...n) => {
|
|
476
|
+
const o = e(t(r));
|
|
477
|
+
for (const a of n)
|
|
478
|
+
a != null && i(o, t(a));
|
|
479
|
+
return o;
|
|
480
|
+
};
|
|
481
|
+
function e(r) {
|
|
482
|
+
if (Array.isArray(r)) return r.map(e);
|
|
483
|
+
if (A(r)) {
|
|
484
|
+
const n = {};
|
|
485
|
+
for (const [o, a] of Object.entries(r)) n[o] = e(a);
|
|
486
|
+
return n;
|
|
487
|
+
}
|
|
488
|
+
if (r instanceof Map) {
|
|
489
|
+
const n = {};
|
|
490
|
+
for (const [o, a] of r.entries()) n[o] = e(a);
|
|
491
|
+
return n;
|
|
492
|
+
}
|
|
493
|
+
return r;
|
|
494
|
+
}
|
|
495
|
+
function t(r) {
|
|
496
|
+
if (!r) return {};
|
|
497
|
+
if (r instanceof URLSearchParams || r instanceof FormData || r instanceof Map)
|
|
498
|
+
return (0, s.toQueryRecord)(r);
|
|
499
|
+
if (typeof r == "string") return (0, s.toQueryRecord)((0, s.fromString)(r));
|
|
500
|
+
if (A(r)) return r;
|
|
501
|
+
throw new TypeError(
|
|
502
|
+
`unsupported type transformation, got: ${Object.prototype.toString.call(
|
|
503
|
+
r
|
|
504
|
+
)}`
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
function i(r, n) {
|
|
508
|
+
for (const [o, a] of Object.entries(n)) {
|
|
509
|
+
if (a === void 0) continue;
|
|
510
|
+
if (a === null) {
|
|
511
|
+
delete r[o];
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const c = r[o];
|
|
515
|
+
A(c) && A(a) ? i(c, a) : r[o] = e(a);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
})(X || (X = {}));
|
|
519
|
+
const Ne = function(s) {
|
|
520
|
+
const e = this.constructor.prototype, t = Reflect.get(e, s, e);
|
|
521
|
+
function i(...r) {
|
|
522
|
+
return Reflect.apply(t, i, r);
|
|
523
|
+
}
|
|
524
|
+
Reflect.setPrototypeOf(i, e);
|
|
525
|
+
for (const r of Reflect.ownKeys(t)) {
|
|
526
|
+
const n = Reflect.getOwnPropertyDescriptor(t, r);
|
|
527
|
+
n && Reflect.defineProperty(i, r, n);
|
|
528
|
+
}
|
|
529
|
+
return i;
|
|
530
|
+
};
|
|
531
|
+
Ne.prototype = Object.create(Function.prototype);
|
|
532
|
+
var H;
|
|
533
|
+
((s) => {
|
|
534
|
+
s.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, r] of e.entries())
|
|
540
|
+
if (r != null)
|
|
541
|
+
if (Array.isArray(r))
|
|
542
|
+
for (const n of r)
|
|
543
|
+
n != null && t.append(i, String(n));
|
|
544
|
+
else
|
|
545
|
+
t.append(i, String(r));
|
|
546
|
+
return t;
|
|
547
|
+
}
|
|
548
|
+
if (A(e)) {
|
|
549
|
+
for (const [i, r] of Object.entries(e))
|
|
550
|
+
if (r != null)
|
|
551
|
+
if (Array.isArray(r))
|
|
552
|
+
for (const n of r)
|
|
553
|
+
n != null && t.append(i, String(n));
|
|
554
|
+
else
|
|
555
|
+
t.append(i, String(r));
|
|
556
|
+
return t;
|
|
557
|
+
}
|
|
558
|
+
throw new TypeError(
|
|
559
|
+
"only plain object, Map/ReadonlyMap, or Headers is supported"
|
|
560
|
+
);
|
|
561
|
+
}, s.toHeaderRecord = (e) => {
|
|
562
|
+
if (e instanceof Headers) {
|
|
563
|
+
const t = {};
|
|
564
|
+
return e.forEach((i, r) => {
|
|
565
|
+
t[r] = t[r] ? [...t[r], i] : [i];
|
|
566
|
+
}), t;
|
|
567
|
+
}
|
|
568
|
+
if (e instanceof Map) {
|
|
569
|
+
const t = {};
|
|
570
|
+
for (const [i, r] of e.entries())
|
|
571
|
+
if (r != null)
|
|
572
|
+
if (Array.isArray(r)) {
|
|
573
|
+
const n = r.filter((o) => o != null).map((o) => String(o));
|
|
574
|
+
n.length && (t[i] = (t[i] ?? []).concat(n));
|
|
575
|
+
} else {
|
|
576
|
+
const n = String(r);
|
|
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
|
+
}, s.mergeHeaders = (e, ...t) => {
|
|
587
|
+
const i = e instanceof Headers ? new Headers(e) : (0, s.makeHeaders)(e), r = (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
|
+
r(n);
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
const o = (0, s.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
|
+
})(H || (H = {}));
|
|
623
|
+
let le = class v extends Ne {
|
|
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 = F(v.DEFAULT_CONFIGS, e), v.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 = F(e, i)), i = await this.emit("beforeInit", i, {
|
|
661
|
+
shouldAdjustRequestParams: !0,
|
|
662
|
+
shouldHandleShortCircuitResponse: !0
|
|
663
|
+
}), i[v.FINAL_SYMBOL]) return i;
|
|
664
|
+
if (v.METHODS_WITHOUT_BODY.includes(
|
|
665
|
+
i.method?.toLocaleLowerCase()
|
|
666
|
+
) && i.body)
|
|
667
|
+
throw new _(
|
|
668
|
+
T.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[v.FINAL_SYMBOL]) return i;
|
|
679
|
+
let r;
|
|
680
|
+
const n = {};
|
|
681
|
+
if (typeof i.body < "u" && i.body !== null && (i.body instanceof Blob || i.body instanceof FormData || i.body instanceof URLSearchParams ? r = i.body : typeof i.body == "object" && i.body !== null ? (r = JSON.stringify(i.body), i.headers = this.mergeHeaders(i.headers, {
|
|
682
|
+
"Content-Type": "application/json"
|
|
683
|
+
})) : r = i.body), !H.makeHeaders(
|
|
684
|
+
t.headers || {}
|
|
685
|
+
).get("content-type") && r && (r instanceof FormData || r instanceof URLSearchParams ? n["content-type"] = null : typeof r == "string" && typeof i.body == "object" ? n["content-type"] = "application/json" : r instanceof Blob && (n["content-type"] = r.type || "application/octet-stream")), i.body = r, i = await this.emit("afterBodyTransformed", i, {
|
|
686
|
+
shouldAdjustRequestParams: !0,
|
|
687
|
+
shouldHandleShortCircuitResponse: !0,
|
|
688
|
+
preAdjust: !0,
|
|
689
|
+
postRequestOptionsOverridesURLSearchParams: !0
|
|
690
|
+
}), i[v.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 = X.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: H.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[v.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((p, m) => {
|
|
719
|
+
const g = setTimeout(() => {
|
|
720
|
+
m(
|
|
721
|
+
new _(
|
|
722
|
+
T.TIMEOUT,
|
|
723
|
+
`WebSocket connection timed out after ${d}ms`,
|
|
724
|
+
i
|
|
725
|
+
)
|
|
726
|
+
);
|
|
727
|
+
}, d);
|
|
728
|
+
f.onopen = () => {
|
|
729
|
+
clearTimeout(g), p();
|
|
730
|
+
}, f.onerror = ($) => {
|
|
731
|
+
clearTimeout(g), m(
|
|
732
|
+
new _(
|
|
733
|
+
T.NETWORK_ERROR,
|
|
734
|
+
"WebSocket connection failed",
|
|
735
|
+
i
|
|
736
|
+
)
|
|
737
|
+
);
|
|
738
|
+
}, f.onclose = ($) => {
|
|
739
|
+
$.code !== 1e3 && (clearTimeout(g), m(
|
|
740
|
+
new _(
|
|
741
|
+
T.NETWORK_ERROR,
|
|
742
|
+
`WebSocket closed with code ${$.code}`,
|
|
743
|
+
i
|
|
744
|
+
)
|
|
745
|
+
));
|
|
746
|
+
};
|
|
747
|
+
}), i.rawResponse = new Response(), i.response = new B(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
|
+
T.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((p) => {
|
|
765
|
+
throw u && clearTimeout(u), o?.signal.aborted ? new _(
|
|
766
|
+
T.TIMEOUT,
|
|
767
|
+
`Request timed out after ${d}ms`,
|
|
768
|
+
i
|
|
769
|
+
) : new _(T.NETWORK_ERROR, p.message, i);
|
|
770
|
+
});
|
|
771
|
+
return u && clearTimeout(u), i.rawResponse = f, i.response = await $e(
|
|
772
|
+
f,
|
|
773
|
+
i.responseType,
|
|
774
|
+
(p, m) => {
|
|
775
|
+
t?.onProgress?.(p, m);
|
|
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 = X.mergeQueries;
|
|
783
|
+
mergeHeaders = H.mergeHeaders;
|
|
784
|
+
normalizeContext(e, t = {}) {
|
|
785
|
+
const i = e, r = i.baseURL || this.baseConfigs.baseURL || globalThis.location?.href || "http://localhost", n = new URL(
|
|
786
|
+
r,
|
|
787
|
+
globalThis.location?.href || "http://localhost"
|
|
788
|
+
), o = new URL(i.url.toString(), n), a = !!i[v.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[v.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 r = 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 r) {
|
|
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
|
+
T.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 }, p = await $e(
|
|
838
|
+
u,
|
|
839
|
+
t.responseType,
|
|
840
|
+
(m, g) => {
|
|
841
|
+
t.onProgress?.(m, g);
|
|
842
|
+
}
|
|
843
|
+
);
|
|
844
|
+
if (f.response = p, f.data = p.data, f.headers = p.headers, e !== "afterResponse") {
|
|
845
|
+
const m = await this.emit("afterResponse", f);
|
|
846
|
+
return m[v.FINAL_SYMBOL] = !0, m;
|
|
847
|
+
} else
|
|
848
|
+
return f[v.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
|
+
T.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 p = {};
|
|
869
|
+
if (h)
|
|
870
|
+
try {
|
|
871
|
+
p = JSON.parse(h);
|
|
872
|
+
} catch {
|
|
873
|
+
}
|
|
874
|
+
const m = t.query || {}, g = this.mergeQueries(
|
|
875
|
+
p,
|
|
876
|
+
f.search,
|
|
877
|
+
m
|
|
878
|
+
);
|
|
879
|
+
t.query = g;
|
|
880
|
+
const $ = new URL(f);
|
|
881
|
+
$.search = "", t.url = $.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
|
+
T.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, r) => (v.METHODS_WITHOUT_BODY.includes(
|
|
923
|
+
e.toLocaleLowerCase()
|
|
924
|
+
) ? r = i : (r = r || {}, r.body = i), this.request(t, {
|
|
925
|
+
...r,
|
|
926
|
+
method: e
|
|
927
|
+
}))
|
|
928
|
+
}), this;
|
|
929
|
+
}
|
|
930
|
+
extends(e) {
|
|
931
|
+
const t = new v(F(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 = v.create;
|
|
937
|
+
static create(e) {
|
|
938
|
+
return new v(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 v)
|
|
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 Lt = le.create, Ae = Lt();
|
|
958
|
+
typeof globalThis < "u" ? globalThis.fexios = Ae : typeof window < "u" && (window.fexios = Ae);
|
|
959
|
+
var Q;
|
|
960
|
+
((s) => {
|
|
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
|
+
s.normalizeParamValue = e;
|
|
965
|
+
function t(i) {
|
|
966
|
+
const r = (o) => o && (o instanceof URLSearchParams || o instanceof FormData);
|
|
967
|
+
if (i == null)
|
|
968
|
+
return;
|
|
969
|
+
const n = new FormData();
|
|
970
|
+
if (r(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
|
+
s.normalizeBody = t;
|
|
982
|
+
})(Q || (Q = {}));
|
|
983
|
+
var q = /* @__PURE__ */ ((s) => (s.HTTP_ERROR = "HTTP_ERROR", s.LOGIN_FAILED = "LOGIN_FAILED", s.LOGIN_RETRY_LIMIT_EXCEEDED = "LOGIN_RETRY_LIMIT_EXCEEDED", s.TOKEN_RETRY_LIMIT_EXCEEDED = "TOKEN_RETRY_LIMIT_EXCEEDED", s))(q || {});
|
|
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 U = class Be extends Error {
|
|
993
|
+
constructor(e, t) {
|
|
994
|
+
super(), this.errors = e, this.cause = t, this.name = "MediaWikiApiError", this.errors = Be.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
|
+
((s) => {
|
|
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
|
+
s.includesMediaWikiApiError = t, s.normalizeMwApiErrors = U.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, s.normalizeMwApiErrors)(l);
|
|
1031
|
+
}
|
|
1032
|
+
s.extractMediaWikiApiErrors = i;
|
|
1033
|
+
function r(n) {
|
|
1034
|
+
if (U.is(n))
|
|
1035
|
+
return n.isBadTokenError();
|
|
1036
|
+
{
|
|
1037
|
+
const o = i(n);
|
|
1038
|
+
return new U(o).isBadTokenError();
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
s.isBadTokenError = r;
|
|
1042
|
+
})(R || (R = {}));
|
|
1043
|
+
const Le = Symbol.for("__FEXIOS_SAIKOU__");
|
|
1044
|
+
function je(s) {
|
|
1045
|
+
const e = s instanceof le ? s : new le({
|
|
1046
|
+
baseURL: s instanceof URL ? s.toString() : String(s),
|
|
1047
|
+
responseType: "json"
|
|
1048
|
+
});
|
|
1049
|
+
return e[Le] || (Reflect.defineProperty(e, Le, {
|
|
1050
|
+
get: () => !0,
|
|
1051
|
+
enumerable: !1,
|
|
1052
|
+
configurable: !1
|
|
1053
|
+
}), e._tokens = /* @__PURE__ */ new Map(), e.on("afterResponse", (t) => {
|
|
1054
|
+
const { data: i, rawRequest: r } = t, n = r?.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 = Q.normalizeBody(t.body), r = new URLSearchParams(t.query);
|
|
1068
|
+
return i.has("format") && r.delete("format"), i.has("formatversion") && r.delete("formatversion"), i.has("action") && r.delete("action"), i.has("origin") && (r.set("origin", "" + i.get("origin")), i.delete("origin")), t.query = Object.fromEntries(r.entries()), t;
|
|
1069
|
+
}), e.on("beforeInit", (t) => (t.query = Q.normalizeBody(t.query) || {}, t)), e.on("beforeRequest", (t) => {
|
|
1070
|
+
const i = new URL(t.url), r = i.searchParams;
|
|
1071
|
+
if (globalThis.location && (!r.has("origin") && location.origin !== i.origin ? (r.set("origin", location.origin), e.baseConfigs.credentials = "include", e.baseConfigs.mode = "cors") : location.origin === i.origin && (r.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 C = (s, ...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
|
+
}, r = i(s);
|
|
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 = r[o];
|
|
1096
|
+
t(c) && t(a) ? r[o] = C(c, a) : r[o] = i(a);
|
|
1097
|
+
}
|
|
1098
|
+
return r;
|
|
1099
|
+
}, Ot = (s, e, t) => {
|
|
1100
|
+
let i = { ...Fe.DEFAULT_CONFIGS };
|
|
1101
|
+
if (typeof s == "string" ? i = C(i, {
|
|
1102
|
+
baseURL: s,
|
|
1103
|
+
fexiosConfigs: e || {},
|
|
1104
|
+
defaultParams: t || {}
|
|
1105
|
+
}) : typeof s == "object" && s !== null && (i = C(i, s)), !i.baseURL && typeof window == "object" && window.mediaWiki) {
|
|
1106
|
+
const { wgServer: r, wgScriptPath: n } = window.mediaWiki?.config?.get(["wgServer", "wgScriptPath"]) || {};
|
|
1107
|
+
typeof r == "string" && typeof n == "string" && (i.baseURL = `${r}${n}/api.php`);
|
|
1108
|
+
}
|
|
1109
|
+
if (typeof i.baseURL != "string")
|
|
1110
|
+
throw new Error("baseURL is required");
|
|
1111
|
+
return i;
|
|
1112
|
+
}, xt = () => {
|
|
1113
|
+
}, Ct = async (s, e) => {
|
|
1114
|
+
let t = 0;
|
|
1115
|
+
const { retry: i = 3, onRetry: r = xt, shouldRetry: n = () => !0 } = e;
|
|
1116
|
+
let o;
|
|
1117
|
+
do
|
|
1118
|
+
try {
|
|
1119
|
+
return await s();
|
|
1120
|
+
} catch (a) {
|
|
1121
|
+
if (o = a, n(a, t))
|
|
1122
|
+
r(a, t), t++;
|
|
1123
|
+
else
|
|
1124
|
+
throw a;
|
|
1125
|
+
}
|
|
1126
|
+
while (t < i);
|
|
1127
|
+
throw o || new Error("Retry failed");
|
|
1128
|
+
};
|
|
1129
|
+
const j = class {
|
|
1130
|
+
constructor(e, t, i) {
|
|
1131
|
+
this.version = "7.1.2", this.token = this.getToken;
|
|
1132
|
+
const r = this.config = Ot(
|
|
1133
|
+
e,
|
|
1134
|
+
t,
|
|
1135
|
+
i
|
|
1136
|
+
);
|
|
1137
|
+
this.request = je(r.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
|
+
C(
|
|
1148
|
+
{},
|
|
1149
|
+
this.config.fexiosConfigs,
|
|
1150
|
+
{ query: C(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
|
+
C(
|
|
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 U(
|
|
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 U(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: r = "token",
|
|
1216
|
+
retry: n = 3,
|
|
1217
|
+
noCache: o = !1,
|
|
1218
|
+
fexiosOptions: a
|
|
1219
|
+
} = i || {};
|
|
1220
|
+
if (n < 1)
|
|
1221
|
+
throw new R(
|
|
1222
|
+
q.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 Ct(
|
|
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
|
+
[r]: l,
|
|
1236
|
+
...t
|
|
1237
|
+
},
|
|
1238
|
+
C(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 || U.is(h) ? h : new R(
|
|
1247
|
+
q.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
|
+
q.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
|
+
j.INIT_DEFAULT_PARAMS = {
|
|
1286
|
+
action: "query",
|
|
1287
|
+
errorformat: "plaintext",
|
|
1288
|
+
format: "json",
|
|
1289
|
+
formatversion: 2
|
|
1290
|
+
}, j.DEFAULT_CONFIGS = {
|
|
1291
|
+
baseURL: void 0,
|
|
1292
|
+
fexiosConfigs: {
|
|
1293
|
+
responseType: "json"
|
|
1294
|
+
},
|
|
1295
|
+
defaultParams: j.INIT_DEFAULT_PARAMS,
|
|
1296
|
+
throwOnApiError: !1
|
|
1297
|
+
}, j.createRequestHandler = je;
|
|
1298
|
+
let Fe = j;
|
|
1299
|
+
let Pt = class extends Fe {
|
|
1300
|
+
async clientLogin(e, t, i) {
|
|
1301
|
+
i ||= {}, !i.logincontinue && !i.loginreturnurl && (i.loginreturnurl = location?.origin);
|
|
1302
|
+
const r = 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 (r?.data?.clientlogin?.status === "PASS")
|
|
1315
|
+
return r.data.clientlogin;
|
|
1316
|
+
throw new R(
|
|
1317
|
+
q.LOGIN_FAILED,
|
|
1318
|
+
r.data.clientlogin.message,
|
|
1319
|
+
r
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
class It {
|
|
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 Pt({
|
|
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 Dt = Object.create, fe = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, He = (s, e) => (e = Symbol[s]) ? e : Symbol.for("Symbol." + s), qe = (s) => {
|
|
1341
|
+
throw TypeError(s);
|
|
1342
|
+
}, Ut = (s, e, t) => e in s ? fe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Nt = (s, e) => fe(s, "name", { value: e, configurable: !0 }), Bt = (s) => [, , , Dt(s?.[He("metadata")] ?? null)], jt = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], We = (s) => s !== void 0 && typeof s != "function" ? qe("Function expected") : s, Ft = (s, e, t, i, r) => ({ kind: jt[s], name: e, metadata: i, addInitializer: (n) => t._ ? qe("Already initialized") : r.push(We(n || null)) }), Ht = (s, e) => Ut(e, He("metadata"), s[3]), qt = (s, e, t, i) => {
|
|
1343
|
+
for (var r = 0, n = s[e >> 1], o = n && n.length; r < o; r++) n[r].call(t);
|
|
1344
|
+
return i;
|
|
1345
|
+
}, Wt = (s, e, t, i, r, n) => {
|
|
1346
|
+
var o, a, c, l = e & 7, h = !1, d = 0, u = s[d] || (s[d] = []), f = l && (r = r.prototype, l < 5 && (l > 3 || !h) && Mt(r, t));
|
|
1347
|
+
Nt(r, t);
|
|
1348
|
+
for (var p = i.length - 1; p >= 0; p--)
|
|
1349
|
+
c = Ft(l, t, a = {}, s[3], u), o = (0, i[p])(r, c), a._ = 1, We(o) && (r = o);
|
|
1350
|
+
return Ht(s, r), f && fe(r, t, f), h ? l ^ 4 ? n : f : r;
|
|
1351
|
+
}, Ke, pe, ze;
|
|
1352
|
+
Ke = [de(["wiki", "wikiTitle"])];
|
|
1353
|
+
class V extends (ze = 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(r, n, o) {
|
|
1375
|
+
t.apply(this, [r, n, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: r }));
|
|
1376
|
+
}, history.replaceState = function(r, n, o) {
|
|
1377
|
+
i.apply(this, [r, n, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: r }));
|
|
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
|
+
pe = Bt(ze);
|
|
1411
|
+
V = Wt(pe, 0, "CurrentPageService", Ke, V);
|
|
1412
|
+
qt(pe, 1, V);
|
|
1413
|
+
class Kt 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}`, r = document.querySelector(`[data-ipe="${i}"]`);
|
|
1424
|
+
return r ? Promise.resolve(r) : 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}`, r = document.querySelector(`[data-ipe="${i}"]`);
|
|
1435
|
+
return r ? Promise.resolve(r) : 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 ie = Object.keys;
|
|
1463
|
+
function zt(s) {
|
|
1464
|
+
return typeof s == "boolean";
|
|
1465
|
+
}
|
|
1466
|
+
function Yt(s) {
|
|
1467
|
+
return s && typeof s.nodeType == "number";
|
|
1468
|
+
}
|
|
1469
|
+
function me(s) {
|
|
1470
|
+
return typeof s == "string";
|
|
1471
|
+
}
|
|
1472
|
+
function Ye(s) {
|
|
1473
|
+
return typeof s == "number";
|
|
1474
|
+
}
|
|
1475
|
+
function P(s) {
|
|
1476
|
+
return typeof s == "object" ? s !== null : K(s);
|
|
1477
|
+
}
|
|
1478
|
+
function K(s) {
|
|
1479
|
+
return typeof s == "function";
|
|
1480
|
+
}
|
|
1481
|
+
function Gt(s) {
|
|
1482
|
+
return !!(s && s.isComponent);
|
|
1483
|
+
}
|
|
1484
|
+
function Xt(s) {
|
|
1485
|
+
return P(s) && typeof s.length == "number" && typeof s.nodeType != "number";
|
|
1486
|
+
}
|
|
1487
|
+
function ce(s, e) {
|
|
1488
|
+
if (s)
|
|
1489
|
+
for (const t of ie(s))
|
|
1490
|
+
e(s[t], t);
|
|
1491
|
+
}
|
|
1492
|
+
function Qt(s) {
|
|
1493
|
+
return P(s) && "current" in s;
|
|
1494
|
+
}
|
|
1495
|
+
const he = {
|
|
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 Vt(s, e) {
|
|
1541
|
+
return s + e.charAt(0).toUpperCase() + e.substring(1);
|
|
1542
|
+
}
|
|
1543
|
+
const Zt = ["Webkit", "ms", "Moz", "O"];
|
|
1544
|
+
ie(he).forEach((s) => {
|
|
1545
|
+
Zt.forEach((e) => {
|
|
1546
|
+
he[Vt(e, s)] = 0;
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
const Jt = Symbol.for("jsx-dom:type");
|
|
1550
|
+
var Ge = /* @__PURE__ */ (function(s) {
|
|
1551
|
+
return s.ShadowRoot = "ShadowRoot", s;
|
|
1552
|
+
})(Ge || {});
|
|
1553
|
+
function ei(s) {
|
|
1554
|
+
return s != null && s[Jt] === Ge.ShadowRoot;
|
|
1555
|
+
}
|
|
1556
|
+
const ti = "http://www.w3.org/2000/svg", ii = "http://www.w3.org/1999/xlink", si = "http://www.w3.org/XML/1998/namespace";
|
|
1557
|
+
function Xe(s) {
|
|
1558
|
+
return !zt(s) && s != null;
|
|
1559
|
+
}
|
|
1560
|
+
function ue(s) {
|
|
1561
|
+
return Array.isArray(s) ? s.map(ue).filter(Boolean).join(" ") : P(s) ? Symbol.iterator in s ? ue(Array.from(s)) : ie(s).filter((e) => s[e]).join(" ") : Xe(s) ? "" + s : "";
|
|
1562
|
+
}
|
|
1563
|
+
const ri = {
|
|
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
|
+
}, ni = /^(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 oi(s) {
|
|
1620
|
+
const e = document.createDocumentFragment();
|
|
1621
|
+
return se(s.children, e), e;
|
|
1622
|
+
}
|
|
1623
|
+
function ai(s, e, t) {
|
|
1624
|
+
e = {
|
|
1625
|
+
...e,
|
|
1626
|
+
children: t
|
|
1627
|
+
};
|
|
1628
|
+
const i = new s(e), r = i.render();
|
|
1629
|
+
return "ref" in e && ge(e.ref, i), r;
|
|
1630
|
+
}
|
|
1631
|
+
function y(s, e) {
|
|
1632
|
+
let { children: t, ...i } = e;
|
|
1633
|
+
!i.namespaceURI && ri[s] === 0 && (i = {
|
|
1634
|
+
...i,
|
|
1635
|
+
namespaceURI: ti
|
|
1636
|
+
});
|
|
1637
|
+
let r;
|
|
1638
|
+
if (me(s)) {
|
|
1639
|
+
if (r = i.namespaceURI ? document.createElementNS(i.namespaceURI, s) : document.createElement(s), hi(i, r), se(t, r), r 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
|
+
r.querySelectorAll("option").forEach(
|
|
1643
|
+
(o) => o.selected = n.includes(o.value)
|
|
1644
|
+
);
|
|
1645
|
+
} else
|
|
1646
|
+
r.value = i.value;
|
|
1647
|
+
ge(i.ref, r);
|
|
1648
|
+
} else if (K(s))
|
|
1649
|
+
P(s.defaultProps) && (i = {
|
|
1650
|
+
...s.defaultProps,
|
|
1651
|
+
...i
|
|
1652
|
+
}), r = Gt(s) ? ai(s, i, t) : s({
|
|
1653
|
+
...i,
|
|
1654
|
+
children: t
|
|
1655
|
+
});
|
|
1656
|
+
else
|
|
1657
|
+
throw new TypeError(`Invalid JSX element type: ${s}`);
|
|
1658
|
+
return r;
|
|
1659
|
+
}
|
|
1660
|
+
function ge(s, e) {
|
|
1661
|
+
Qt(s) ? s.current = e : K(s) && s(e);
|
|
1662
|
+
}
|
|
1663
|
+
function se(s, e) {
|
|
1664
|
+
if (Xt(s))
|
|
1665
|
+
li(s, e);
|
|
1666
|
+
else if (me(s) || Ye(s))
|
|
1667
|
+
ne(document.createTextNode(s), e);
|
|
1668
|
+
else if (s === null)
|
|
1669
|
+
ne(document.createComment(""), e);
|
|
1670
|
+
else if (Yt(s))
|
|
1671
|
+
ne(s, e);
|
|
1672
|
+
else if (ei(s)) {
|
|
1673
|
+
const t = e.attachShadow(s.attr);
|
|
1674
|
+
se(s.children, t), ge(s.ref, t);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
function li(s, e) {
|
|
1678
|
+
for (const t of [...s])
|
|
1679
|
+
se(t, e);
|
|
1680
|
+
return e;
|
|
1681
|
+
}
|
|
1682
|
+
function ne(s, e) {
|
|
1683
|
+
e instanceof window.HTMLTemplateElement ? e.content.appendChild(s) : e.appendChild(s);
|
|
1684
|
+
}
|
|
1685
|
+
function G(s, e) {
|
|
1686
|
+
return s.replace(/[A-Z]/g, (t) => e + t.toLowerCase());
|
|
1687
|
+
}
|
|
1688
|
+
function Qe(s, e) {
|
|
1689
|
+
e == null || e === !1 || (Array.isArray(e) ? e.forEach((t) => Qe(s, t)) : me(e) ? s.setAttribute("style", e) : P(e) && ce(e, (t, i) => {
|
|
1690
|
+
i.indexOf("-") === 0 ? s.style.setProperty(i, t) : Ye(t) && he[i] !== 0 ? s.style[i] = t + "px" : s.style[i] = t;
|
|
1691
|
+
}));
|
|
1692
|
+
}
|
|
1693
|
+
function ci(s, e, t) {
|
|
1694
|
+
switch (s) {
|
|
1695
|
+
case "xlinkActuate":
|
|
1696
|
+
case "xlinkArcrole":
|
|
1697
|
+
case "xlinkHref":
|
|
1698
|
+
case "xlinkRole":
|
|
1699
|
+
case "xlinkShow":
|
|
1700
|
+
case "xlinkTitle":
|
|
1701
|
+
case "xlinkType":
|
|
1702
|
+
Oe(t, ii, G(s, ":"), e);
|
|
1703
|
+
return;
|
|
1704
|
+
case "xmlnsXlink":
|
|
1705
|
+
M(t, G(s, ":"), e);
|
|
1706
|
+
return;
|
|
1707
|
+
case "xmlBase":
|
|
1708
|
+
case "xmlLang":
|
|
1709
|
+
case "xmlSpace":
|
|
1710
|
+
Oe(t, si, G(s, ":"), e);
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
switch (s) {
|
|
1714
|
+
case "htmlFor":
|
|
1715
|
+
M(t, "for", e);
|
|
1716
|
+
return;
|
|
1717
|
+
case "dataset":
|
|
1718
|
+
ce(e, (i, r) => {
|
|
1719
|
+
i != null && (t.dataset[r] = i);
|
|
1720
|
+
});
|
|
1721
|
+
return;
|
|
1722
|
+
case "innerHTML":
|
|
1723
|
+
case "innerText":
|
|
1724
|
+
case "textContent":
|
|
1725
|
+
Xe(e) && (t[s] = e);
|
|
1726
|
+
return;
|
|
1727
|
+
case "dangerouslySetInnerHTML":
|
|
1728
|
+
P(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
|
+
K(e) ? e(t) : M(t, "class", ue(e));
|
|
1744
|
+
return;
|
|
1745
|
+
case "ref":
|
|
1746
|
+
case "namespaceURI":
|
|
1747
|
+
return;
|
|
1748
|
+
case "style":
|
|
1749
|
+
Qe(t, e);
|
|
1750
|
+
return;
|
|
1751
|
+
case "on":
|
|
1752
|
+
case "onCapture":
|
|
1753
|
+
ce(e, (i, r) => {
|
|
1754
|
+
t.addEventListener(r, i, s === "onCapture");
|
|
1755
|
+
});
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
if (K(e)) {
|
|
1759
|
+
if (s[0] === "o" && s[1] === "n") {
|
|
1760
|
+
let i = s.toLowerCase();
|
|
1761
|
+
const r = i.endsWith("capture");
|
|
1762
|
+
if (i === "ondoubleclick" ? i = "ondblclick" : r && i === "ondoubleclickcapture" && (i = "ondblclickcapture"), !r && t[i] === null)
|
|
1763
|
+
t[i] = e;
|
|
1764
|
+
else if (r)
|
|
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] + s.slice(3), t.addEventListener(n, e);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
} else P(e) ? t[s] = e : e === !0 ? M(t, s, "") : e !== !1 && e != null && (t instanceof SVGElement && !ni.test(s) ? M(t, G(s, "-"), e) : M(t, s, e));
|
|
1776
|
+
}
|
|
1777
|
+
function M(s, e, t) {
|
|
1778
|
+
s.setAttribute(e, t);
|
|
1779
|
+
}
|
|
1780
|
+
function Oe(s, e, t, i) {
|
|
1781
|
+
s.setAttributeNS(e, t, i);
|
|
1782
|
+
}
|
|
1783
|
+
function hi(s, e) {
|
|
1784
|
+
for (const t of ie(s))
|
|
1785
|
+
ci(t, s[t], e);
|
|
1786
|
+
return e;
|
|
1787
|
+
}
|
|
1788
|
+
var ye = /* @__PURE__ */ ((s) => (s.Init = "modal.init", s.BeforeShow = "modal.beforeShow", s.Show = "modal.show", s.BeforeClose = "modal.beforeClose", s.Close = "modal.close", s.Destroy = "modal.destroy", s.ToastShow = "toast.show", s.ToastClose = "toast.close", s))(ye || {});
|
|
1789
|
+
let ui = 0;
|
|
1790
|
+
const xe = (s) => `${s}-${++ui}`;
|
|
1791
|
+
function N(s) {
|
|
1792
|
+
return s instanceof Node ? s : document.createTextNode(String(s));
|
|
1793
|
+
}
|
|
1794
|
+
function L(s, e) {
|
|
1795
|
+
if (!s) throw new Error(`${e ?? "Element"} not found`);
|
|
1796
|
+
return s;
|
|
1797
|
+
}
|
|
1798
|
+
function Ce(s) {
|
|
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(s.querySelectorAll(e)).filter(
|
|
1808
|
+
(t) => !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length)
|
|
1809
|
+
);
|
|
1810
|
+
}
|
|
1811
|
+
function S(s, e = {}) {
|
|
1812
|
+
const t = document.createElement(s);
|
|
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, r] of Object.entries(e.attrs)) t.setAttribute(i, r);
|
|
1815
|
+
return t;
|
|
1816
|
+
}
|
|
1817
|
+
const di = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform), Ve = ["ctrl", "alt", "shift", "meta"];
|
|
1818
|
+
function fi(s) {
|
|
1819
|
+
if (!s) return null;
|
|
1820
|
+
const e = String(s).trim().toLowerCase().split(/[+\-\s]+/g).filter(Boolean), t = [];
|
|
1821
|
+
let i = null;
|
|
1822
|
+
const r = (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
|
+
r("ctrl");
|
|
1829
|
+
continue;
|
|
1830
|
+
}
|
|
1831
|
+
if (a === "alt" || a === "option") {
|
|
1832
|
+
r("alt");
|
|
1833
|
+
continue;
|
|
1834
|
+
}
|
|
1835
|
+
if (a === "shift") {
|
|
1836
|
+
r("shift");
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
if (a === "meta" || a === "cmd" || a === "command" || a === "super") {
|
|
1840
|
+
r("meta");
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
if (a === "mod") {
|
|
1844
|
+
r(di ? "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 = Ve.filter((o) => t.includes(o));
|
|
1850
|
+
return !i || i === "" ? n.length ? n.join("+") : null : n.length ? `${n.join("+")}+${i}` : i;
|
|
1851
|
+
}
|
|
1852
|
+
function pi(s) {
|
|
1853
|
+
const e = [];
|
|
1854
|
+
s.ctrlKey && e.push("ctrl"), s.altKey && e.push("alt"), s.shiftKey && e.push("shift"), s.metaKey && e.push("meta");
|
|
1855
|
+
let t = s.key;
|
|
1856
|
+
t === " " && (t = "space");
|
|
1857
|
+
const i = (t.length, t.toLowerCase()), r = Ve.filter((n) => e.includes(n));
|
|
1858
|
+
return r.length ? `${r.join("+")}+${i}` : i;
|
|
1859
|
+
}
|
|
1860
|
+
class mi {
|
|
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)), r = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
1875
|
+
[...this.stack].reverse().forEach((n) => {
|
|
1876
|
+
const o = n.modalId, a = r.size ? r.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 k = new mi();
|
|
1894
|
+
class Z {
|
|
1895
|
+
constructor(e = {}) {
|
|
1896
|
+
this.backdropId = xe("ipe-modal-backdrop"), this.modalId = xe("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 = ye, 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, r = t.clientY - this.dragStartY, n = this.get$modal(), o = this.modalStartX + i, a = this.modalStartY + r;
|
|
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 = { ...Z.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, p = window.pageXOffset || document.documentElement.scrollLeft, m = window.innerWidth;
|
|
1957
|
+
i.style.top = `${f + 60}px`, this.once("modal.show", () => {
|
|
1958
|
+
i.style.left = `${p + m / 2 - i.offsetWidth / 2}px`;
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
const r = S("div", {
|
|
1962
|
+
className: `ipe-modal-modal__window size--${this.options.sizeClass || "auto"} plugin--${this.pluginName}`
|
|
1963
|
+
});
|
|
1964
|
+
r.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 p = !0;
|
|
1979
|
+
typeof this.options.onClickClose == "function" ? this.options.onClickClose(this) === !1 && (p = !1) : this.options.onClickClose === !1 && (p = !1), p && 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), r.append(n, l, h), i.appendChild(r), this.$backdrop = t, this.$modal = i, this.$window = r, 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 && r.addEventListener("pointerdown", (f) => {
|
|
1991
|
+
f.target && r.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), r = this.options.beforeShow ? this.options.beforeShow(this) !== !1 : !0;
|
|
2002
|
+
if (!i || !r) return this;
|
|
2003
|
+
}
|
|
2004
|
+
this.lastFocused = document.activeElement ?? null, this.$backdrop && document.body.appendChild(this.$backdrop), document.body.appendChild(this.$modal), this.shouldLockBodyOnOpen() && k.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), k.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
|
+
}, r = (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 ? (r(this.$window, "transitionend"), r(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 = x.indexOf(this);
|
|
2061
|
+
e !== -1 && x.splice(e, 1);
|
|
2062
|
+
} else
|
|
2063
|
+
this.$backdrop?.parentElement && this.$backdrop.parentElement.removeChild(this.$backdrop), this.$modal?.parentElement && this.$modal.parentElement.removeChild(this.$modal), k.remove(this), this.shouldUnlockBodyOnClose() && k.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 L(this.$modal, "modal");
|
|
2075
|
+
}
|
|
2076
|
+
get$window() {
|
|
2077
|
+
return L(this.$window, "window");
|
|
2078
|
+
}
|
|
2079
|
+
get$header() {
|
|
2080
|
+
return L(this.$header, "header");
|
|
2081
|
+
}
|
|
2082
|
+
get$title() {
|
|
2083
|
+
return L(this.$title, "title");
|
|
2084
|
+
}
|
|
2085
|
+
get$content() {
|
|
2086
|
+
return L(this.$content, "content");
|
|
2087
|
+
}
|
|
2088
|
+
get$icons() {
|
|
2089
|
+
return L(this.$icons, "icons");
|
|
2090
|
+
}
|
|
2091
|
+
get$buttons(e) {
|
|
2092
|
+
return e === "leftButtons" ? L(this.$buttonsLeft, "leftButtons") : e === "rightButtons" ? L(this.$buttonsRight, "rightButtons") : L(this.$footer, "buttons");
|
|
2093
|
+
}
|
|
2094
|
+
// ------------------------------ content ------------------------------- //
|
|
2095
|
+
setTitle(e) {
|
|
2096
|
+
const t = this.get$title();
|
|
2097
|
+
return t.innerHTML = "", t.append(N(e)), this;
|
|
2098
|
+
}
|
|
2099
|
+
setContent(e, t = "replace") {
|
|
2100
|
+
const i = this.get$content();
|
|
2101
|
+
return t === "replace" ? (i.innerHTML = "", i.append(N(e))) : t === "append" ? i.append(N(e)) : i.prepend(N(e)), this;
|
|
2102
|
+
}
|
|
2103
|
+
setIcons(e) {
|
|
2104
|
+
const t = this.get$icons();
|
|
2105
|
+
t.innerHTML = "";
|
|
2106
|
+
for (const i of e) {
|
|
2107
|
+
const r = S("button", {
|
|
2108
|
+
className: `ipe-modal-modal__icon ${i.className}`,
|
|
2109
|
+
attrs: { type: "button" }
|
|
2110
|
+
});
|
|
2111
|
+
r.addEventListener("click", i.method), t.appendChild(r);
|
|
2112
|
+
}
|
|
2113
|
+
return this;
|
|
2114
|
+
}
|
|
2115
|
+
setButtons(e, t) {
|
|
2116
|
+
const i = this.$buttonsLeft, r = this.$buttonsRight;
|
|
2117
|
+
[i, r].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 r = N(e.label ?? "OK");
|
|
2134
|
+
if (i.append(r), 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 = fi(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", r = 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 >= r.children.length ? r.appendChild(o) : r.insertBefore(o, r.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, r = [...t, ...i];
|
|
2167
|
+
let n = null;
|
|
2168
|
+
if (e === "*")
|
|
2169
|
+
return r.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 = r[e] ?? null : typeof e == "string" ? n = r.find((a) => a.id === e) ?? null : e instanceof HTMLElement && (n = r.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(), r = Math.max(0, window.innerHeight - e);
|
|
2182
|
+
return i.style[t] = `${r}px`, r;
|
|
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(), r = 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)), r && (!c || c === !1 ? r.style.transition = "none" : r.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, (r) => (i(), t(r)));
|
|
2208
|
+
return i;
|
|
2209
|
+
}
|
|
2210
|
+
emit(e, t) {
|
|
2211
|
+
const i = this._hooks.filter((a) => a.type === e);
|
|
2212
|
+
let r = !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 && (r = !1), l === !1 && (r = !1), !r) break;
|
|
2216
|
+
}
|
|
2217
|
+
const n = this.$modal ?? document.body, o = new CustomEvent(e, { detail: this, cancelable: t });
|
|
2218
|
+
return (!n.dispatchEvent(o) || o.defaultPrevented) && (r = !1), r;
|
|
2219
|
+
}
|
|
2220
|
+
focusFirst() {
|
|
2221
|
+
const e = this.get$modal(), t = Ce(e);
|
|
2222
|
+
t.length ? t[0].focus() : e.focus({ preventScroll: !0 });
|
|
2223
|
+
}
|
|
2224
|
+
onKeyDown(e) {
|
|
2225
|
+
if (k.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 = Ce(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, r = e.target;
|
|
2239
|
+
if (!i && (r && ["INPUT", "TEXTAREA"].includes(r.tagName) || r.contentEditable === "true"))
|
|
2240
|
+
return;
|
|
2241
|
+
const n = pi(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 k.remove(this), k.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 : !k.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 : !k.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 = gi(e.position ?? "top right"), i = this.get$window();
|
|
2280
|
+
this.isToast = !0, i.style.pointerEvents = "auto", this.applyAnimation(!0), t.appendChild(i);
|
|
2281
|
+
const r = (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 r > 0 && (this.startCloseTimer(r), n && (i.addEventListener("mouseenter", this.stopCloseTimer), i.addEventListener("mouseleave", () => this.startCloseTimer(r)))), this.isOpen = !0, this.options.onShow?.(this), x.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 = k.top();
|
|
2300
|
+
return n?.close(), n;
|
|
2301
|
+
}
|
|
2302
|
+
const t = typeof e == "string" ? e : e.id, i = k.stack.find((n) => n.modalId === t);
|
|
2303
|
+
if (i)
|
|
2304
|
+
return i.close(), i;
|
|
2305
|
+
const r = x.find((n) => n.modalId === t);
|
|
2306
|
+
return r?.close(), r;
|
|
2307
|
+
}
|
|
2308
|
+
static closeAll(e, t) {
|
|
2309
|
+
const i = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), r = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
2310
|
+
return k.closeAll(e, t), [...x].forEach((n) => {
|
|
2311
|
+
const o = n.modalId, a = r.size ? r.has(n.pluginName) : !0, c = i.has(o);
|
|
2312
|
+
a && !c && n.close();
|
|
2313
|
+
}), k.top() ?? new Z();
|
|
2314
|
+
}
|
|
2315
|
+
static removeAll() {
|
|
2316
|
+
k.removeAll(), [...x].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: (r, n) => {
|
|
2326
|
+
t?.(r, n), r.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" }, r = e.cancelBtn ?? { label: "Cancel", className: "is-danger is-ghost" };
|
|
2338
|
+
return new this({
|
|
2339
|
+
sizeClass: "dialog",
|
|
2340
|
+
...e,
|
|
2341
|
+
buttons: [
|
|
2342
|
+
{
|
|
2343
|
+
label: r.label,
|
|
2344
|
+
className: r.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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2375
|
+
/* @__PURE__ */ y("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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2391
|
+
/* @__PURE__ */ y("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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2407
|
+
/* @__PURE__ */ y("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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2423
|
+
/* @__PURE__ */ y("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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2443
|
+
/* @__PURE__ */ y("path", { d: "M12 11v.01" }),
|
|
2444
|
+
/* @__PURE__ */ y("path", { d: "M8 11v.01" }),
|
|
2445
|
+
/* @__PURE__ */ y("path", { d: "M16 11v.01" }),
|
|
2446
|
+
/* @__PURE__ */ y("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__ */ y(
|
|
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__ */ y("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
2462
|
+
/* @__PURE__ */ y("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 && [...x].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 r = t.icon ?? this.getDefaultNotifyIcon(e);
|
|
2476
|
+
r && (r instanceof Element && r.classList.add("ipe-modal-notify-icon"), t.title = /* @__PURE__ */ y(oi, { children: [
|
|
2477
|
+
r,
|
|
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 x = [];
|
|
2503
|
+
function gi(s = "top right") {
|
|
2504
|
+
const e = "ipe-modal-toast-container", t = `${e}-${s.replace(/[\s-\.|\/]+/g, "-")}`;
|
|
2505
|
+
let i = document.getElementById(t);
|
|
2506
|
+
return i || (i = S("div", {
|
|
2507
|
+
className: `${e} ${s}`,
|
|
2508
|
+
attrs: { id: t, "data-position": s }
|
|
2509
|
+
}), document.body.appendChild(i)), i;
|
|
2510
|
+
}
|
|
2511
|
+
class b extends Z {
|
|
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__ */ E(
|
|
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__ */ E(mt, { 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 yi {
|
|
2556
|
+
constructor(e) {
|
|
2557
|
+
this.ctx = e, this.IPEModal = b, this.IPEModalEvent = ye, this.show = b.show.bind(b), this.createObject = b.createObject.bind(b), this.close = b.close.bind(b), this.closeAll = b.closeAll.bind(b), this.removeAll = b.removeAll.bind(b), this.dialog = b.dialog.bind(b), this.confirm = b.confirm.bind(b), this.notify = b.notify.bind(b), e.set("modal", this), e.on("dispose", () => {
|
|
2558
|
+
b.closeAll();
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
const Ze = (s) => {
|
|
2563
|
+
if (!s)
|
|
2564
|
+
return new URLSearchParams();
|
|
2565
|
+
if (s instanceof URLSearchParams)
|
|
2566
|
+
return s;
|
|
2567
|
+
if (typeof s != "object" || s?.constructor !== Object)
|
|
2568
|
+
throw new TypeError("only plain object is supported");
|
|
2569
|
+
const e = new URLSearchParams();
|
|
2570
|
+
for (const [t, i] of Object.entries(s))
|
|
2571
|
+
if (i != null) {
|
|
2572
|
+
if (Array.isArray(i)) {
|
|
2573
|
+
for (const r of i)
|
|
2574
|
+
e.append(t, r?.toString());
|
|
2575
|
+
continue;
|
|
2576
|
+
}
|
|
2577
|
+
if (typeof i == "object" && i !== null && i.constructor === Object) {
|
|
2578
|
+
for (const [r, n] of Object.entries(i))
|
|
2579
|
+
n != null && e.set(`${t}[${r}]`, n?.toString());
|
|
2580
|
+
continue;
|
|
2581
|
+
}
|
|
2582
|
+
e.set(t, i?.toString());
|
|
2583
|
+
}
|
|
2584
|
+
return e;
|
|
2585
|
+
}, Je = (s, e, t) => {
|
|
2586
|
+
const i = typeof s == "string" ? new URL(s, window?.location?.origin) : new URL(s), r = new URLSearchParams(i.search), n = Ze(e);
|
|
2587
|
+
for (const [o, a] of n.entries())
|
|
2588
|
+
r.set(o, a);
|
|
2589
|
+
return i.search = r.toString(), i.hash = "", i;
|
|
2590
|
+
};
|
|
2591
|
+
var wi = Object.create, we = Object.defineProperty, bi = Object.getOwnPropertyDescriptor, et = (s, e) => (e = Symbol[s]) ? e : Symbol.for("Symbol." + s), tt = (s) => {
|
|
2592
|
+
throw TypeError(s);
|
|
2593
|
+
}, vi = (s, e, t) => e in s ? we(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Si = (s, e) => we(s, "name", { value: e, configurable: !0 }), ki = (s) => [, , , wi(s?.[et("metadata")] ?? null)], Ei = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], it = (s) => s !== void 0 && typeof s != "function" ? tt("Function expected") : s, _i = (s, e, t, i, r) => ({ kind: Ei[s], name: e, metadata: i, addInitializer: (n) => t._ ? tt("Already initialized") : r.push(it(n || null)) }), Ri = (s, e) => vi(e, et("metadata"), s[3]), Ti = (s, e, t, i) => {
|
|
2594
|
+
for (var r = 0, n = s[e >> 1], o = n && n.length; r < o; r++) n[r].call(t);
|
|
2595
|
+
return i;
|
|
2596
|
+
}, $i = (s, e, t, i, r, n) => {
|
|
2597
|
+
var o, a, c, l = e & 7, h = !1, d = 0, u = s[d] || (s[d] = []), f = l && (r = r.prototype, l < 5 && (l > 3 || !h) && bi(r, t));
|
|
2598
|
+
Si(r, t);
|
|
2599
|
+
for (var p = i.length - 1; p >= 0; p--)
|
|
2600
|
+
c = _i(l, t, a = {}, s[3], u), o = (0, i[p])(r, c), a._ = 1, it(o) && (r = o);
|
|
2601
|
+
return Ri(s, r), f && we(r, t, f), h ? l ^ 4 ? n : f : r;
|
|
2602
|
+
}, st, be, rt;
|
|
2603
|
+
st = [de(["api", "storage"])];
|
|
2604
|
+
class J extends (rt = 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.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
|
+
e.preferences.registerCustomConfig(
|
|
2640
|
+
"WikiMetadataService",
|
|
2641
|
+
W.object({
|
|
2642
|
+
WikiMetadataService: W.const(
|
|
2643
|
+
/* @__PURE__ */ E("div", { children: [
|
|
2644
|
+
/* @__PURE__ */ E("h3", { children: "Wiki Informations" }),
|
|
2645
|
+
/* @__PURE__ */ E("ul", { children: [
|
|
2646
|
+
/* @__PURE__ */ E("li", { children: [
|
|
2647
|
+
/* @__PURE__ */ E("strong", { children: "Site:" }),
|
|
2648
|
+
" ",
|
|
2649
|
+
this.general.sitename,
|
|
2650
|
+
" (",
|
|
2651
|
+
this.landingPageUrl,
|
|
2652
|
+
")"
|
|
2653
|
+
] }),
|
|
2654
|
+
/* @__PURE__ */ E("li", { children: [
|
|
2655
|
+
/* @__PURE__ */ E("strong", { children: "User" }),
|
|
2656
|
+
": ",
|
|
2657
|
+
this.userInfo.name,
|
|
2658
|
+
" (ID: ",
|
|
2659
|
+
this.userInfo.id,
|
|
2660
|
+
")"
|
|
2661
|
+
] }),
|
|
2662
|
+
/* @__PURE__ */ E("li", { children: [
|
|
2663
|
+
/* @__PURE__ */ E("strong", { children: "Groups" }),
|
|
2664
|
+
": ",
|
|
2665
|
+
this.userGroups.join(", ") || "None"
|
|
2666
|
+
] })
|
|
2667
|
+
] }),
|
|
2668
|
+
/* @__PURE__ */ E("div", { children: [
|
|
2669
|
+
/* @__PURE__ */ E("p", { style: { fontStyle: "italic" }, children: "If the information shown above is incorrect (for example, the user is not you), click the button below." }),
|
|
2670
|
+
/* @__PURE__ */ E(
|
|
2671
|
+
"button",
|
|
2672
|
+
{
|
|
2673
|
+
className: "btn danger",
|
|
2674
|
+
onClick: (t) => {
|
|
2675
|
+
t.preventDefault(), Promise.all(
|
|
2676
|
+
Object.keys(this.QUERY_DATA).map(
|
|
2677
|
+
(i) => this.invalidateCache(i)
|
|
2678
|
+
)
|
|
2679
|
+
).then(() => {
|
|
2680
|
+
window.location.reload();
|
|
2681
|
+
});
|
|
2682
|
+
},
|
|
2683
|
+
children: "🧹 Clear caches & Reload"
|
|
2684
|
+
}
|
|
2685
|
+
)
|
|
2686
|
+
] })
|
|
2687
|
+
] })
|
|
2688
|
+
).role("raw-html")
|
|
2689
|
+
}).description("WikiMetadataService"),
|
|
2690
|
+
"about"
|
|
2691
|
+
);
|
|
2692
|
+
}), this.logger.info("All initialized", this._data);
|
|
2693
|
+
}
|
|
2694
|
+
async initData(e, t = !1) {
|
|
2695
|
+
const i = t ? null : await this.fetchFromCache(e);
|
|
2696
|
+
if (i)
|
|
2697
|
+
return this._data[e] = i, this.logger.debug("Using cached", e, i), i;
|
|
2698
|
+
{
|
|
2699
|
+
const r = await this.fetchFromApi(e);
|
|
2700
|
+
return this.saveToCache(e, r), this._data[e] = r, this.logger.debug("Fetched from API", e, r), r;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
getCacheKey(e) {
|
|
2704
|
+
return `${e}:${new URL(this.ctx.api.config.baseURL).pathname.replace(/^\//, "")}`;
|
|
2705
|
+
}
|
|
2706
|
+
async fetchFromApi(e) {
|
|
2707
|
+
return this.api.get({
|
|
2708
|
+
action: "query",
|
|
2709
|
+
...this.QUERY_DATA[e]
|
|
2710
|
+
}).then(({ data: t }) => {
|
|
2711
|
+
if (typeof t?.query != "object" || t.query === null)
|
|
2712
|
+
throw new Error("Invalid query data", { cause: t });
|
|
2713
|
+
return e === "siteinfo" ? t.query : t.query?.[e] || t.query;
|
|
2714
|
+
}).catch((t) => (this.logger.error("Failed to fetch", t), Promise.reject(t)));
|
|
2715
|
+
}
|
|
2716
|
+
async fetchFromCache(e) {
|
|
2717
|
+
const t = this.getCacheKey(e);
|
|
2718
|
+
return await this.CACHE_DB.get(t, this.CACHE_TTL[e]);
|
|
2719
|
+
}
|
|
2720
|
+
async saveToCache(e, t) {
|
|
2721
|
+
const i = this.getCacheKey(e);
|
|
2722
|
+
return this.CACHE_DB.set(i, t);
|
|
2723
|
+
}
|
|
2724
|
+
async invalidateCache(e) {
|
|
2725
|
+
const t = this.getCacheKey(e);
|
|
2726
|
+
return this.CACHE_DB.delete(t);
|
|
2727
|
+
}
|
|
2728
|
+
// ====== shortcuts ======
|
|
2729
|
+
get _raw() {
|
|
2730
|
+
return this._data;
|
|
2731
|
+
}
|
|
2732
|
+
// siteInfo
|
|
2733
|
+
get siteInfo() {
|
|
2734
|
+
return this._data.siteinfo;
|
|
2735
|
+
}
|
|
2736
|
+
get general() {
|
|
2737
|
+
return this.siteInfo.general;
|
|
2738
|
+
}
|
|
2739
|
+
get specialPageAliases() {
|
|
2740
|
+
return this.siteInfo.specialpagealiases;
|
|
2741
|
+
}
|
|
2742
|
+
get namespaceAliases() {
|
|
2743
|
+
return this.siteInfo.namespacealiases;
|
|
2744
|
+
}
|
|
2745
|
+
get namespaces() {
|
|
2746
|
+
return this.siteInfo.namespaces;
|
|
2747
|
+
}
|
|
2748
|
+
get namespaceMap() {
|
|
2749
|
+
const e = Object.values(this.namespaces).map((t) => ({
|
|
2750
|
+
id: t.id,
|
|
2751
|
+
canonical: t.canonical,
|
|
2752
|
+
aliases: this.namespaceAliases.filter((i) => i.id === t.id).map((i) => i.alias)
|
|
2753
|
+
})).sort((t, i) => t.id - i.id);
|
|
2754
|
+
return Reflect.defineProperty(this, "namespaceMap", {
|
|
2755
|
+
get: () => e
|
|
2756
|
+
}), e;
|
|
2757
|
+
}
|
|
2758
|
+
get magicWords() {
|
|
2759
|
+
return this.siteInfo.magicwords;
|
|
2760
|
+
}
|
|
2761
|
+
// userInfo
|
|
2762
|
+
get userInfo() {
|
|
2763
|
+
return this._data.userinfo;
|
|
2764
|
+
}
|
|
2765
|
+
get userOptions() {
|
|
2766
|
+
return this.userInfo.options;
|
|
2767
|
+
}
|
|
2768
|
+
get isUserBlocked() {
|
|
2769
|
+
return this.userInfo.blockedbyid && this.userInfo.blockexpiry && new Date(this.userInfo.blockexpiry).getTime() > Date.now();
|
|
2770
|
+
}
|
|
2771
|
+
get userGroups() {
|
|
2772
|
+
return this.userInfo.groups;
|
|
2773
|
+
}
|
|
2774
|
+
get userRights() {
|
|
2775
|
+
return this.userInfo.rights;
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Base URL, without trailing slash
|
|
2779
|
+
* @example "https://mediawiki.org"
|
|
2780
|
+
*/
|
|
2781
|
+
get baseUrl() {
|
|
2782
|
+
const e = this.general.server;
|
|
2783
|
+
return e.startsWith("//") ? `${window?.location?.protocol || "https:"}//${e.slice(2)}` : e;
|
|
2784
|
+
}
|
|
2785
|
+
/**
|
|
2786
|
+
* Home page URL of this wiki
|
|
2787
|
+
* @description Generally same as the Mainpage URL,
|
|
2788
|
+
* but after MediaWiki 1.34,
|
|
2789
|
+
* it can be set to the website root directory.
|
|
2790
|
+
* @example "https://mediawiki.org/wiki/Main_Page" (In most cases)
|
|
2791
|
+
* @example "https://mediawiki.org/" ($wgMainPageIsDomainRoot = true)
|
|
2792
|
+
*/
|
|
2793
|
+
get landingPageUrl() {
|
|
2794
|
+
return this.general.base;
|
|
2795
|
+
}
|
|
2796
|
+
get mainPageName() {
|
|
2797
|
+
return this.general.mainpage;
|
|
2798
|
+
}
|
|
2799
|
+
/**
|
|
2800
|
+
* Exact Mainpage URL of this wiki
|
|
2801
|
+
* @example "https://mediawiki.org/wiki/Main_Page"
|
|
2802
|
+
*/
|
|
2803
|
+
get mainPageUrl() {
|
|
2804
|
+
return this.getUrl(this.mainPageName);
|
|
2805
|
+
}
|
|
2806
|
+
/**
|
|
2807
|
+
* Article path, with the $1 placeholder
|
|
2808
|
+
* @example "/wiki/$1"
|
|
2809
|
+
*/
|
|
2810
|
+
get articlePath() {
|
|
2811
|
+
return this.general.articlepath;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Script path, without trailing slash
|
|
2815
|
+
* @example "/w"
|
|
2816
|
+
*/
|
|
2817
|
+
get scriptPath() {
|
|
2818
|
+
return this.general.scriptpath;
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2821
|
+
* Article base URL, with the $1 placeholder
|
|
2822
|
+
* @example "https://mediawiki.org/wiki/$1"
|
|
2823
|
+
*/
|
|
2824
|
+
get articleBaseUrl() {
|
|
2825
|
+
return `${this.baseUrl}${this.articlePath}`;
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Script base URL, without trailing slash
|
|
2829
|
+
* @example "https://mediawiki.org/w"
|
|
2830
|
+
*/
|
|
2831
|
+
get scriptBaseUrl() {
|
|
2832
|
+
return `${this.baseUrl}${this.scriptPath}`;
|
|
2833
|
+
}
|
|
2834
|
+
// utils
|
|
2835
|
+
getSciprtUrl(e = "index") {
|
|
2836
|
+
return `${this.scriptBaseUrl}/${e.replace(/\.php$/, "")}.php`;
|
|
2837
|
+
}
|
|
2838
|
+
/** Get mainpage URL */
|
|
2839
|
+
getMainpageUrl(e) {
|
|
2840
|
+
return Je(this.siteInfo.general.base, e).toString();
|
|
2841
|
+
}
|
|
2842
|
+
getUrl(e, t) {
|
|
2843
|
+
const i = Ze(t);
|
|
2844
|
+
let r;
|
|
2845
|
+
return typeof e == "string" && e !== "" ? r = new URL(`${this.articleBaseUrl.replace("$1", e)}`) : typeof e == "number" ? (i.set("curid", e.toString()), r = new URL(this.getSciprtUrl("index"))) : r = new URL(this.getSciprtUrl("index")), r.search = i.toString(), r.toString();
|
|
2846
|
+
}
|
|
2847
|
+
hasRight(e) {
|
|
2848
|
+
return this.userRights.includes(e);
|
|
2849
|
+
}
|
|
2850
|
+
hasAnyRight(...e) {
|
|
2851
|
+
return e.some((t) => this.hasRight(t));
|
|
2852
|
+
}
|
|
2853
|
+
hasEveryRights(...e) {
|
|
2854
|
+
return e.every((t) => this.hasRight(t));
|
|
2855
|
+
}
|
|
2856
|
+
inGroup(e) {
|
|
2857
|
+
return this.userGroups.includes(e);
|
|
2858
|
+
}
|
|
2859
|
+
inAnyGroup(...e) {
|
|
2860
|
+
return this.userGroups.some((t) => e.includes(t));
|
|
2861
|
+
}
|
|
2862
|
+
getBlockInfo() {
|
|
2863
|
+
return this.isUserBlocked ? {
|
|
2864
|
+
blockid: this.userInfo.blockid,
|
|
2865
|
+
blockedby: this.userInfo.blockedbyid,
|
|
2866
|
+
blockedbyid: this.userInfo.blockedbyid,
|
|
2867
|
+
blockreason: this.userInfo.blockreason,
|
|
2868
|
+
blockedtimestamp: this.userInfo.blockedtimestamp,
|
|
2869
|
+
blockexpiry: this.userInfo.blockexpiry
|
|
2870
|
+
} : null;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
be = ki(rt);
|
|
2874
|
+
J = $i(be, 0, "WikiMetadataService", st, J);
|
|
2875
|
+
Ti(be, 1, J);
|
|
2876
|
+
const Ai = (() => {
|
|
2877
|
+
const s = Symbol.for("IPE.GlobalMemoryStorage");
|
|
2878
|
+
return s in globalThis || (globalThis[s] = ht()), globalThis[s];
|
|
2879
|
+
})();
|
|
2880
|
+
class Li {
|
|
2881
|
+
constructor(e, t, i = 1 / 0, r, n = "localStorage") {
|
|
2882
|
+
this.dbName = e, this.storeName = t, this.ttl = i, this.version = r, 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 = Ai;
|
|
2883
|
+
}
|
|
2884
|
+
// Key builder
|
|
2885
|
+
makeKey(e) {
|
|
2886
|
+
return `${this.dbName ? this.dbName + ":" : ""}${this.storeName ? this.storeName + "/" : ""}${e}`;
|
|
2887
|
+
}
|
|
2888
|
+
// Internal load & validation
|
|
2889
|
+
load(e) {
|
|
2890
|
+
const t = this.getRaw(e);
|
|
2891
|
+
if (t === null) return null;
|
|
2892
|
+
let i;
|
|
2893
|
+
try {
|
|
2894
|
+
i = JSON.parse(t);
|
|
2895
|
+
} catch {
|
|
2896
|
+
return this.deleteSync(e), null;
|
|
2897
|
+
}
|
|
2898
|
+
const r = i;
|
|
2899
|
+
return typeof r.time != "number" || !("value" in r) ? (this.deleteSync(e), null) : typeof this.version == "number" && r.version !== this.version ? (this.deleteSync(e), null) : r;
|
|
2900
|
+
}
|
|
2901
|
+
getRaw(e) {
|
|
2902
|
+
const t = this.makeKey(e);
|
|
2903
|
+
return this.db.getItem(t);
|
|
2904
|
+
}
|
|
2905
|
+
setRaw(e, t) {
|
|
2906
|
+
const i = this.makeKey(e);
|
|
2907
|
+
try {
|
|
2908
|
+
this.db.setItem(i, t);
|
|
2909
|
+
} catch {
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
deleteSync(e) {
|
|
2913
|
+
const t = this.makeKey(e);
|
|
2914
|
+
this.db.removeItem(t);
|
|
2915
|
+
}
|
|
2916
|
+
isExpired(e, t = this.ttl) {
|
|
2917
|
+
return e ? Date.now() - e.time > t : !1;
|
|
2918
|
+
}
|
|
2919
|
+
async get(e, t = this.ttl, i) {
|
|
2920
|
+
const r = this.load(e), n = this.isExpired(r, t);
|
|
2921
|
+
if (!r || n) {
|
|
2922
|
+
if (typeof i == "function") {
|
|
2923
|
+
const o = await i();
|
|
2924
|
+
return await this.set(e, o), o;
|
|
2925
|
+
}
|
|
2926
|
+
return null;
|
|
2927
|
+
}
|
|
2928
|
+
return r.value;
|
|
2929
|
+
}
|
|
2930
|
+
async set(e, t) {
|
|
2931
|
+
const i = Date.now();
|
|
2932
|
+
if (typeof e == "string") {
|
|
2933
|
+
const o = e, a = t;
|
|
2934
|
+
if (a === null || typeof a > "u") {
|
|
2935
|
+
await this.delete(o);
|
|
2936
|
+
return;
|
|
2937
|
+
}
|
|
2938
|
+
const c = { time: i, value: a, version: this.version };
|
|
2939
|
+
return this.setRaw(o, JSON.stringify(c)), c;
|
|
2940
|
+
}
|
|
2941
|
+
const r = e, n = {};
|
|
2942
|
+
for (const [o, a] of Object.entries(r)) {
|
|
2943
|
+
if (a === null || typeof a > "u") {
|
|
2944
|
+
this.deleteSync(o);
|
|
2945
|
+
continue;
|
|
2946
|
+
}
|
|
2947
|
+
const c = { time: i, value: a, version: this.version };
|
|
2948
|
+
this.setRaw(o, JSON.stringify(c)), n[o] = c;
|
|
2949
|
+
}
|
|
2950
|
+
return n;
|
|
2951
|
+
}
|
|
2952
|
+
async has(e, t = this.ttl) {
|
|
2953
|
+
const i = this.load(e);
|
|
2954
|
+
return i !== null && !this.isExpired(i, t);
|
|
2955
|
+
}
|
|
2956
|
+
async delete(e) {
|
|
2957
|
+
this.deleteSync(e);
|
|
2958
|
+
}
|
|
2959
|
+
async updatedAt(e) {
|
|
2960
|
+
const t = this.load(e);
|
|
2961
|
+
return t ? t.time : 0;
|
|
2962
|
+
}
|
|
2963
|
+
async clear() {
|
|
2964
|
+
const e = this.makeKey(""), t = [];
|
|
2965
|
+
for (let i = 0; i < this.db.length; i++) {
|
|
2966
|
+
const r = this.db.key(i);
|
|
2967
|
+
r && r.startsWith(e) && t.push(r);
|
|
2968
|
+
}
|
|
2969
|
+
for (const i of t) this.db.removeItem(i);
|
|
2970
|
+
return this;
|
|
2971
|
+
}
|
|
2972
|
+
// Async generators
|
|
2973
|
+
async *keys() {
|
|
2974
|
+
const e = this.makeKey("");
|
|
2975
|
+
for (let t = 0; t < this.db.length; t++) {
|
|
2976
|
+
const i = this.db.key(t);
|
|
2977
|
+
i && i.startsWith(e) && (yield i.slice(e.length));
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
async *values() {
|
|
2981
|
+
for await (const e of this.keys()) {
|
|
2982
|
+
const t = this.load(e);
|
|
2983
|
+
if (t) {
|
|
2984
|
+
if (this.isExpired(t)) {
|
|
2985
|
+
this.deleteSync(e);
|
|
2986
|
+
continue;
|
|
2987
|
+
}
|
|
2988
|
+
yield t;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
async *entries() {
|
|
2993
|
+
for await (const e of this.keys()) {
|
|
2994
|
+
const t = this.load(e);
|
|
2995
|
+
if (t) {
|
|
2996
|
+
if (this.isExpired(t)) {
|
|
2997
|
+
this.deleteSync(e);
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
yield [e, t];
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
var w;
|
|
3006
|
+
((s) => {
|
|
3007
|
+
s.cache = /* @__PURE__ */ new Map(), s.defaults = Object.freeze({ iterBatch: 100, retry: { attempts: 3, baseDelayMs: 16 } }), s.sleep = (l) => new Promise((h) => setTimeout(h, l));
|
|
3008
|
+
function e(l) {
|
|
3009
|
+
const h = l?.name ?? "";
|
|
3010
|
+
return h === "AbortError" || h === "InvalidStateError" || h === "TransactionInactiveError" || h === "UnknownError";
|
|
3011
|
+
}
|
|
3012
|
+
s.shouldReconnect = e;
|
|
3013
|
+
async function t(l, h, d) {
|
|
3014
|
+
const u = Math.max(1, l.attempts);
|
|
3015
|
+
for (let f = 0; f < u; f++)
|
|
3016
|
+
try {
|
|
3017
|
+
return await h(f);
|
|
3018
|
+
} catch (p) {
|
|
3019
|
+
if (f === u - 1) throw p;
|
|
3020
|
+
await d?.(p, f);
|
|
3021
|
+
const m = l.baseDelayMs * Math.pow(2, f) + Math.floor(Math.random() * 10);
|
|
3022
|
+
await (0, s.sleep)(m);
|
|
3023
|
+
}
|
|
3024
|
+
throw new Error("withRetry exhausted unexpectedly");
|
|
3025
|
+
}
|
|
3026
|
+
s.withRetry = t;
|
|
3027
|
+
function i(l, h, d) {
|
|
3028
|
+
return new Promise((u, f) => {
|
|
3029
|
+
const p = indexedDB.open(l, h);
|
|
3030
|
+
p.onupgradeneeded = () => {
|
|
3031
|
+
try {
|
|
3032
|
+
const m = p.result, g = p.transaction;
|
|
3033
|
+
d?.(m, g);
|
|
3034
|
+
} catch (m) {
|
|
3035
|
+
f(m);
|
|
3036
|
+
}
|
|
3037
|
+
}, p.onerror = () => f(p.error), p.onblocked = () => {
|
|
3038
|
+
}, p.onsuccess = () => {
|
|
3039
|
+
const m = p.result;
|
|
3040
|
+
m.onversionchange = () => {
|
|
3041
|
+
try {
|
|
3042
|
+
m.close();
|
|
3043
|
+
} finally {
|
|
3044
|
+
s.cache.delete(l);
|
|
3045
|
+
}
|
|
3046
|
+
}, u(m);
|
|
3047
|
+
};
|
|
3048
|
+
});
|
|
3049
|
+
}
|
|
3050
|
+
async function r(l, h, d) {
|
|
3051
|
+
let u = !l.objectStoreNames.contains(h), f = [];
|
|
3052
|
+
if (!u && d?.indexes?.length) {
|
|
3053
|
+
const g = l.transaction(h, "readonly"), $ = g.objectStore(h), D = new Set(Array.from($.indexNames));
|
|
3054
|
+
f = (d.indexes || []).filter((O) => !D.has(O.name)), await new Promise((O, Ee) => {
|
|
3055
|
+
g.oncomplete = () => O(), g.onabort = () => Ee(g.error), g.onerror = () => Ee(g.error);
|
|
3056
|
+
});
|
|
3057
|
+
}
|
|
3058
|
+
if (!u && f.length === 0) return l;
|
|
3059
|
+
const p = l.version + 1;
|
|
3060
|
+
l.close();
|
|
3061
|
+
const m = await i(l.name, p, (g, $) => {
|
|
3062
|
+
let D;
|
|
3063
|
+
g.objectStoreNames.contains(h) ? D = $.objectStore(h) : D = g.createObjectStore(h, {
|
|
3064
|
+
keyPath: d?.keyPath ?? void 0,
|
|
3065
|
+
autoIncrement: !!d?.autoIncrement
|
|
3066
|
+
});
|
|
3067
|
+
for (const O of f)
|
|
3068
|
+
D.indexNames.contains(O.name) || D.createIndex(O.name, O.keyPath, O.options);
|
|
3069
|
+
});
|
|
3070
|
+
return m.onversionchange = () => {
|
|
3071
|
+
try {
|
|
3072
|
+
m.close();
|
|
3073
|
+
} finally {
|
|
3074
|
+
s.cache.delete(m.name);
|
|
3075
|
+
}
|
|
3076
|
+
}, m;
|
|
3077
|
+
}
|
|
3078
|
+
async function n(l, h, d) {
|
|
3079
|
+
let u = s.cache.get(l);
|
|
3080
|
+
return u ? (u = u.then((f) => r(f, h, d)), s.cache.set(l, u)) : (u = (async () => {
|
|
3081
|
+
const f = await i(l);
|
|
3082
|
+
return r(f, h, d);
|
|
3083
|
+
})(), s.cache.set(l, u)), u;
|
|
3084
|
+
}
|
|
3085
|
+
s.getDB = n;
|
|
3086
|
+
async function o(l) {
|
|
3087
|
+
const h = s.cache.get(l);
|
|
3088
|
+
if (s.cache.delete(l), h)
|
|
3089
|
+
try {
|
|
3090
|
+
(await h).close();
|
|
3091
|
+
} catch {
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
s.closeConnection = o;
|
|
3095
|
+
function a(l) {
|
|
3096
|
+
return new Promise((h, d) => {
|
|
3097
|
+
l.onsuccess = () => h(l.result), l.onerror = () => d(l.error);
|
|
3098
|
+
});
|
|
3099
|
+
}
|
|
3100
|
+
s.asyncRequest = a;
|
|
3101
|
+
function c(l) {
|
|
3102
|
+
return new Promise((h, d) => {
|
|
3103
|
+
l.oncomplete = () => h(), l.onabort = () => d(l.error ?? new DOMException("Aborted", "AbortError")), l.onerror = () => d(l.error ?? new DOMException("TransactionError", "UnknownError"));
|
|
3104
|
+
});
|
|
3105
|
+
}
|
|
3106
|
+
s.waitTx = c;
|
|
3107
|
+
})(w || (w = {}));
|
|
3108
|
+
class Oi {
|
|
3109
|
+
constructor(e, t, i = {}) {
|
|
3110
|
+
this.dbName = e, this.storeName = t, this.options = i;
|
|
3111
|
+
}
|
|
3112
|
+
get _iterBatch() {
|
|
3113
|
+
return this.options.iterBatch ?? w.defaults.iterBatch;
|
|
3114
|
+
}
|
|
3115
|
+
get _retryCfg() {
|
|
3116
|
+
const e = this.options.retry ?? w.defaults.retry;
|
|
3117
|
+
return { attempts: e.attempts ?? 3, baseDelayMs: e.baseDelayMs ?? 16 };
|
|
3118
|
+
}
|
|
3119
|
+
async _withStore(e, t) {
|
|
3120
|
+
const i = this._retryCfg;
|
|
3121
|
+
return w.withRetry(
|
|
3122
|
+
i,
|
|
3123
|
+
async () => {
|
|
3124
|
+
const r = await w.getDB(this.dbName, this.storeName, this.options.ensure);
|
|
3125
|
+
try {
|
|
3126
|
+
const n = r.transaction(this.storeName, e), o = n.objectStore(this.storeName), a = await t(o);
|
|
3127
|
+
return await w.waitTx(n), a;
|
|
3128
|
+
} catch (n) {
|
|
3129
|
+
throw n;
|
|
3130
|
+
}
|
|
3131
|
+
},
|
|
3132
|
+
async (r) => {
|
|
3133
|
+
w.shouldReconnect(r) && await w.closeConnection(this.dbName);
|
|
3134
|
+
}
|
|
3135
|
+
);
|
|
3136
|
+
}
|
|
3137
|
+
async get(e) {
|
|
3138
|
+
return this._withStore("readonly", async (t) => {
|
|
3139
|
+
const i = await w.asyncRequest(t.get(e));
|
|
3140
|
+
return i === void 0 ? void 0 : i;
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
async set(e, t) {
|
|
3144
|
+
return await this._withStore("readwrite", async (i) => {
|
|
3145
|
+
const r = this.options.ensure?.keyPath != null ? i.put(t) : i.put(t, e);
|
|
3146
|
+
await w.asyncRequest(r);
|
|
3147
|
+
}), this;
|
|
3148
|
+
}
|
|
3149
|
+
async delete(e) {
|
|
3150
|
+
return this._withStore("readwrite", async (t) => {
|
|
3151
|
+
const i = await w.asyncRequest(t.get(e)) !== void 0;
|
|
3152
|
+
return await w.asyncRequest(t.delete(e)), i;
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
async clear() {
|
|
3156
|
+
await this._withStore("readwrite", async (e) => {
|
|
3157
|
+
await w.asyncRequest(e.clear());
|
|
3158
|
+
});
|
|
3159
|
+
}
|
|
3160
|
+
async has(e) {
|
|
3161
|
+
return await this.get(e) !== void 0;
|
|
3162
|
+
}
|
|
3163
|
+
async count() {
|
|
3164
|
+
return this._withStore("readonly", async (e) => await w.asyncRequest(e.count()) ?? 0);
|
|
3165
|
+
}
|
|
3166
|
+
async *_iterateEntries() {
|
|
3167
|
+
let e = null, t = !1;
|
|
3168
|
+
const i = Math.max(1, this._iterBatch);
|
|
3169
|
+
for (; !t; ) {
|
|
3170
|
+
const r = await this._withStore("readonly", async (n) => {
|
|
3171
|
+
const o = [], a = e === null ? void 0 : IDBKeyRange.lowerBound(e, !0);
|
|
3172
|
+
return await new Promise((c, l) => {
|
|
3173
|
+
const h = n.openCursor(a);
|
|
3174
|
+
h.onerror = () => l(h.error), h.onsuccess = () => {
|
|
3175
|
+
const d = h.result;
|
|
3176
|
+
if (!d) {
|
|
3177
|
+
t = !0, c();
|
|
3178
|
+
return;
|
|
3179
|
+
}
|
|
3180
|
+
o.push([d.key, d.value]), e = d.key, o.length >= i ? c() : d.continue();
|
|
3181
|
+
};
|
|
3182
|
+
}), o;
|
|
3183
|
+
});
|
|
3184
|
+
for (const n of r) yield n;
|
|
3185
|
+
if (r.length === 0) break;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
entries() {
|
|
3189
|
+
return this._iterateEntries();
|
|
3190
|
+
}
|
|
3191
|
+
async *keys() {
|
|
3192
|
+
for await (const [e] of this.entries()) yield e;
|
|
3193
|
+
}
|
|
3194
|
+
async *values() {
|
|
3195
|
+
for await (const [, e] of this.entries()) yield e;
|
|
3196
|
+
}
|
|
3197
|
+
[Symbol.asyncIterator]() {
|
|
3198
|
+
return this.entries()[Symbol.asyncIterator]();
|
|
3199
|
+
}
|
|
3200
|
+
async forEach(e) {
|
|
3201
|
+
for await (const [t, i] of this.entries())
|
|
3202
|
+
await e(i, t, this);
|
|
3203
|
+
}
|
|
3204
|
+
async getMany(e) {
|
|
3205
|
+
const t = /* @__PURE__ */ new Map();
|
|
3206
|
+
for await (const i of e) t.set(i, void 0);
|
|
3207
|
+
return await this._withStore("readonly", async (i) => {
|
|
3208
|
+
await Promise.all(
|
|
3209
|
+
t.keys().map(async (r) => {
|
|
3210
|
+
const n = await w.asyncRequest(i.get(r));
|
|
3211
|
+
t.set(r, n === void 0 ? void 0 : n);
|
|
3212
|
+
})
|
|
3213
|
+
);
|
|
3214
|
+
}), t;
|
|
3215
|
+
}
|
|
3216
|
+
async setMany(e) {
|
|
3217
|
+
const t = this.options.ensure?.keyPath != null;
|
|
3218
|
+
return await this._withStore("readwrite", async (i) => {
|
|
3219
|
+
for await (const [r, n] of e) {
|
|
3220
|
+
const o = t ? i.put(n) : i.put(n, r);
|
|
3221
|
+
await w.asyncRequest(o);
|
|
3222
|
+
}
|
|
3223
|
+
}), this;
|
|
3224
|
+
}
|
|
3225
|
+
async deleteMany(e) {
|
|
3226
|
+
let t = 0;
|
|
3227
|
+
return await this._withStore("readwrite", async (i) => {
|
|
3228
|
+
for await (const r of e)
|
|
3229
|
+
await w.asyncRequest(i.get(r)) !== void 0 && t++, await w.asyncRequest(i.delete(r));
|
|
3230
|
+
}), t;
|
|
3231
|
+
}
|
|
3232
|
+
async disconnect() {
|
|
3233
|
+
await w.closeConnection(this.dbName);
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
class xi {
|
|
3237
|
+
constructor(e, t, i = 1 / 0, r) {
|
|
3238
|
+
this.dbName = e, this.storeName = t, this.ttl = i, this.version = r, this.db = new Oi(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(() => {
|
|
3239
|
+
});
|
|
3240
|
+
}
|
|
3241
|
+
async _clearExpiredEntries() {
|
|
3242
|
+
if (this.ttl === 1 / 0) return;
|
|
3243
|
+
const e = Date.now(), t = [];
|
|
3244
|
+
for await (const [i, r] of this.db.entries())
|
|
3245
|
+
typeof r.time == "number" && e - r.time > this.ttl && t.push(i);
|
|
3246
|
+
t.length > 0 && await this.db.deleteMany(t);
|
|
3247
|
+
}
|
|
3248
|
+
async get(e, t = this.ttl, i) {
|
|
3249
|
+
const r = await this.loadFromDB(e), n = this.checkIfExpired(r, t);
|
|
3250
|
+
if (!r || n) {
|
|
3251
|
+
if (typeof i == "function") {
|
|
3252
|
+
const o = await i();
|
|
3253
|
+
return await this.set(e, o), o;
|
|
3254
|
+
}
|
|
3255
|
+
return null;
|
|
3256
|
+
}
|
|
3257
|
+
return r.value;
|
|
3258
|
+
}
|
|
3259
|
+
async set(e, t) {
|
|
3260
|
+
const i = Date.now();
|
|
3261
|
+
if (typeof e == "string") {
|
|
3262
|
+
const c = e, l = t;
|
|
3263
|
+
if (l === null || typeof l > "u")
|
|
3264
|
+
return this.delete(c);
|
|
3265
|
+
const h = {
|
|
3266
|
+
time: i,
|
|
3267
|
+
value: l,
|
|
3268
|
+
version: this.version
|
|
3269
|
+
};
|
|
3270
|
+
return await this.db.set(c, h), h;
|
|
3271
|
+
}
|
|
3272
|
+
const r = e, n = [], o = [], a = {};
|
|
3273
|
+
for (const [c, l] of Object.entries(r))
|
|
3274
|
+
if (l === null || typeof l > "u")
|
|
3275
|
+
o.push(c);
|
|
3276
|
+
else {
|
|
3277
|
+
const h = { time: i, value: l, version: this.version };
|
|
3278
|
+
n.push([c, h]), a[c] = h;
|
|
3279
|
+
}
|
|
3280
|
+
return n.length > 0 && await this.db.setMany(n), o.length > 0 && await this.db.deleteMany(o), a;
|
|
3281
|
+
}
|
|
3282
|
+
async has(e, t = this.ttl) {
|
|
3283
|
+
const i = await this.loadFromDB(e), r = this.checkIfExpired(i, t);
|
|
3284
|
+
return i !== null && !r;
|
|
3285
|
+
}
|
|
3286
|
+
async delete(e) {
|
|
3287
|
+
await this.db.delete(e);
|
|
3288
|
+
}
|
|
3289
|
+
async updatedAt(e) {
|
|
3290
|
+
const t = await this.loadFromDB(e);
|
|
3291
|
+
return t ? t.time : 0;
|
|
3292
|
+
}
|
|
3293
|
+
async loadFromDB(e) {
|
|
3294
|
+
const t = await this.db.get(e);
|
|
3295
|
+
if (t === void 0)
|
|
3296
|
+
return null;
|
|
3297
|
+
if (typeof t.time != "number" || typeof t.value > "u") {
|
|
3298
|
+
try {
|
|
3299
|
+
await this.delete(e);
|
|
3300
|
+
} catch {
|
|
3301
|
+
}
|
|
3302
|
+
return null;
|
|
3303
|
+
}
|
|
3304
|
+
if (typeof this.version == "number" && t.version !== this.version) {
|
|
3305
|
+
try {
|
|
3306
|
+
await this.delete(e);
|
|
3307
|
+
} catch {
|
|
3308
|
+
}
|
|
3309
|
+
return null;
|
|
3310
|
+
}
|
|
3311
|
+
return t;
|
|
3312
|
+
}
|
|
3313
|
+
checkIfExpired(e, t = this.ttl) {
|
|
3314
|
+
return e ? Date.now() - e.time > t : !1;
|
|
3315
|
+
}
|
|
3316
|
+
/**
|
|
3317
|
+
* [DANGER] Use with caution!
|
|
3318
|
+
* Delete all data from the database.
|
|
3319
|
+
*/
|
|
3320
|
+
async clear() {
|
|
3321
|
+
return await this.db.clear(), this;
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
class Ci extends I {
|
|
3325
|
+
constructor(e, t) {
|
|
3326
|
+
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");
|
|
3327
|
+
}
|
|
3328
|
+
createDatabase(e, t, i, r = "indexedDB") {
|
|
3329
|
+
const n = "indexedDB" in window && window.indexedDB !== null;
|
|
3330
|
+
switch (r === "indexedDB" && !n && (r = "localStorage"), r) {
|
|
3331
|
+
case "indexedDB":
|
|
3332
|
+
return new xi(this.config.dbName, e, t, i);
|
|
3333
|
+
case "localStorage":
|
|
3334
|
+
case "sessionStorage":
|
|
3335
|
+
case "memory":
|
|
3336
|
+
return new Li(this.config.dbName, e, t, i, r);
|
|
3337
|
+
default:
|
|
3338
|
+
throw new Error(`Unsupported storage engine: ${r}`);
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
class Pi extends I {
|
|
3343
|
+
constructor(e) {
|
|
3344
|
+
super(e, "wikiPage", !0), this.ctx = e, this.WikiPage = ut(this.ctx.api);
|
|
3345
|
+
}
|
|
3346
|
+
static {
|
|
3347
|
+
this.inject = ["api"];
|
|
3348
|
+
}
|
|
3349
|
+
async createInstance(e, t = !1) {
|
|
3350
|
+
return await this.WikiPage.newFromApi(e);
|
|
3351
|
+
}
|
|
3352
|
+
async newFromTitle(e, t = !1, i, r = !1) {
|
|
3353
|
+
return this.createInstance({ titles: e.toString(), converttitles: t, rvsection: i }, r);
|
|
3354
|
+
}
|
|
3355
|
+
async newFromPageId(e, t, i = !1) {
|
|
3356
|
+
return this.createInstance({ pageids: e, rvsection: t }, i);
|
|
3357
|
+
}
|
|
3358
|
+
async newFromRevision(e, t, i = !1) {
|
|
3359
|
+
return await this.createInstance({ revids: e, rvsection: t }, i);
|
|
3360
|
+
}
|
|
3361
|
+
newBlankPage(e = {}) {
|
|
3362
|
+
return this.WikiPage.newBlankPage(e);
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
class ve extends I {
|
|
3366
|
+
constructor(e) {
|
|
3367
|
+
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 = dt(this.ctx.wiki.siteInfo);
|
|
3368
|
+
}
|
|
3369
|
+
static {
|
|
3370
|
+
this.inject = ["wiki", "wikiPage"];
|
|
3371
|
+
}
|
|
3372
|
+
newTitle(e, t) {
|
|
3373
|
+
return new this.Title(e, t);
|
|
3374
|
+
}
|
|
3375
|
+
newMainPageTitle() {
|
|
3376
|
+
return this.newTitle(this.ctx.wiki.mainPageName);
|
|
3377
|
+
}
|
|
3378
|
+
async newTitleFromUrl(e) {
|
|
3379
|
+
const t = this.parseWikiLink(e);
|
|
3380
|
+
return t?.title ? t.title : t?.pageId ? this.newTitleFromPageId(t.pageId) : null;
|
|
3381
|
+
}
|
|
3382
|
+
async newTitleFromAnyId(e, t = !1) {
|
|
3383
|
+
const { title: i, pageId: r, revId: n } = e ?? {};
|
|
3384
|
+
if (typeof i == "string")
|
|
3385
|
+
return this.newTitle(i);
|
|
3386
|
+
let o, a;
|
|
3387
|
+
if (n ? (o = parseInt(n.toString(), 10), a = "revid") : r && (o = parseInt(r.toString(), 10), a = "pageid"), !o || !a || isNaN(o) || o <= 0)
|
|
3388
|
+
throw new Error("Invalid id or kind", { cause: e });
|
|
3389
|
+
if (!t && this._cachedTitles.has(`${a}:${o}`))
|
|
3390
|
+
return await this._cachedTitles.get(`${a}:${o}`);
|
|
3391
|
+
const { promise: c, resolve: l, reject: h } = Pe();
|
|
3392
|
+
this._cachedTitles.set(`${a}:${o}`, c);
|
|
3393
|
+
try {
|
|
3394
|
+
const { wikiPage: d } = this.ctx;
|
|
3395
|
+
let u = null;
|
|
3396
|
+
if (a === "pageid")
|
|
3397
|
+
u = await d.newFromPageId(o);
|
|
3398
|
+
else if (a === "revid")
|
|
3399
|
+
u = await d.newFromRevision(o);
|
|
3400
|
+
else
|
|
3401
|
+
throw new Error(`Invalid kind: ${a}`);
|
|
3402
|
+
l(this.newTitle(u.title));
|
|
3403
|
+
} catch (d) {
|
|
3404
|
+
this._cachedTitles.delete(`${a}:${o}`), h(d);
|
|
3405
|
+
}
|
|
3406
|
+
return c;
|
|
3407
|
+
}
|
|
3408
|
+
async newTitleFromPageId(e) {
|
|
3409
|
+
return this.newTitleFromAnyId({ pageId: e });
|
|
3410
|
+
}
|
|
3411
|
+
async newTitleFromRevision(e) {
|
|
3412
|
+
return this.newTitleFromAnyId({ revId: e });
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* Resolve **special** special pages to it's real target
|
|
3416
|
+
*
|
|
3417
|
+
* If target is self or cannot be resolved, return null
|
|
3418
|
+
* @example
|
|
3419
|
+
* ```
|
|
3420
|
+
* Special:MyPage -> User:<username>
|
|
3421
|
+
* Special:Edit/Page_Title -> Page_Title
|
|
3422
|
+
* Special:NewSection/Page_Title -> Page_Title (section=new)
|
|
3423
|
+
* ```
|
|
3424
|
+
*/
|
|
3425
|
+
resolveSpecialPageTarget(e) {
|
|
3426
|
+
const t = typeof e == "string" ? this.newTitle(e) : e;
|
|
3427
|
+
if (!t || t.getNamespaceId() !== -1)
|
|
3428
|
+
return null;
|
|
3429
|
+
let i, r, n = "view";
|
|
3430
|
+
const o = t.getMainDBKey().split("/").slice(1).join("/") || "";
|
|
3431
|
+
if (t.isSpecial("edit") && o)
|
|
3432
|
+
i = o, n = "edit";
|
|
3433
|
+
else if (t.isSpecial("talkpage") && o) {
|
|
3434
|
+
const a = t.newTitle(o).getTalkPage();
|
|
3435
|
+
if (!a)
|
|
3436
|
+
return null;
|
|
3437
|
+
i = a.getPrefixedDBKey();
|
|
3438
|
+
} else if (t.isSpecial("mypage"))
|
|
3439
|
+
i = t.newTitle(this.ctx.wiki.userInfo.name, 2).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
3440
|
+
else if (t.isSpecial("mytalk"))
|
|
3441
|
+
i = t.newTitle(this.ctx.wiki.userInfo.name, 3).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
3442
|
+
else if (t.isSpecial("newsection") && o)
|
|
3443
|
+
i = o, r = "new", n = "edit";
|
|
3444
|
+
else
|
|
3445
|
+
return null;
|
|
3446
|
+
return {
|
|
3447
|
+
title: new this.Title(i),
|
|
3448
|
+
section: r,
|
|
3449
|
+
action: n
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3452
|
+
isWikiLink(e) {
|
|
3453
|
+
return e.startsWith(this.wikiArticleBaseUrl) || e.startsWith(this.wikiIndexPhpUrl) || // Some servers allow index.php to be omitted
|
|
3454
|
+
e.startsWith(`${this.wikiBaseUrl}/?`) || // It's the landing page
|
|
3455
|
+
e === this.ctx.wiki.landingPageUrl;
|
|
3456
|
+
}
|
|
3457
|
+
static {
|
|
3458
|
+
this.REG_SKIPPED_HREF = /^(#|javascript:|vbscript:|file:)/i;
|
|
3459
|
+
}
|
|
3460
|
+
validateHrefAttr(e) {
|
|
3461
|
+
return typeof e != "string" ? !1 : !ve.REG_SKIPPED_HREF.test(e);
|
|
3462
|
+
}
|
|
3463
|
+
parseWikiLink(e) {
|
|
3464
|
+
if (!e || typeof e == "string" && !this.validateHrefAttr(e))
|
|
3465
|
+
return null;
|
|
3466
|
+
const t = Je(e);
|
|
3467
|
+
if (!this.isWikiLink(t.toString()))
|
|
3468
|
+
return null;
|
|
3469
|
+
const i = t.searchParams, r = 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);
|
|
3470
|
+
let l = o || (() => {
|
|
3471
|
+
try {
|
|
3472
|
+
return decodeURIComponent(t.pathname.substring(this.wikiArticlePath.length));
|
|
3473
|
+
} catch (f) {
|
|
3474
|
+
return this.logger.error("parseLink", t, f), "";
|
|
3475
|
+
}
|
|
3476
|
+
})();
|
|
3477
|
+
l.endsWith("index.php") && (l = "");
|
|
3478
|
+
let h, d, u;
|
|
3479
|
+
if (c)
|
|
3480
|
+
u = c;
|
|
3481
|
+
else if (a)
|
|
3482
|
+
d = a;
|
|
3483
|
+
else if (l)
|
|
3484
|
+
h = this.newTitle(l);
|
|
3485
|
+
else if (t.origin + t.pathname === this.ctx.wiki.landingPageUrl)
|
|
3486
|
+
h = this.newMainPageTitle();
|
|
3487
|
+
else
|
|
3488
|
+
return null;
|
|
3489
|
+
return {
|
|
3490
|
+
title: h,
|
|
3491
|
+
pageId: d,
|
|
3492
|
+
revId: u,
|
|
3493
|
+
url: t,
|
|
3494
|
+
params: i,
|
|
3495
|
+
hash: r,
|
|
3496
|
+
action: n
|
|
3497
|
+
};
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
const Ii = (s) => typeof s == "function";
|
|
3501
|
+
async function Di(s) {
|
|
3502
|
+
return Ii(s) ? await s() : s;
|
|
3503
|
+
}
|
|
3504
|
+
var Mi = Object.create, Se = Object.defineProperty, Ui = Object.getOwnPropertyDescriptor, nt = (s, e) => (e = Symbol[s]) ? e : Symbol.for("Symbol." + s), ot = (s) => {
|
|
3505
|
+
throw TypeError(s);
|
|
3506
|
+
}, Ni = (s, e, t) => e in s ? Se(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Bi = (s, e) => Se(s, "name", { value: e, configurable: !0 }), ji = (s) => [, , , Mi(s?.[nt("metadata")] ?? null)], Fi = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], at = (s) => s !== void 0 && typeof s != "function" ? ot("Function expected") : s, Hi = (s, e, t, i, r) => ({ kind: Fi[s], name: e, metadata: i, addInitializer: (n) => t._ ? ot("Already initialized") : r.push(at(n || null)) }), qi = (s, e) => Ni(e, nt("metadata"), s[3]), Wi = (s, e, t, i) => {
|
|
3507
|
+
for (var r = 0, n = s[e >> 1], o = n && n.length; r < o; r++) n[r].call(t);
|
|
3508
|
+
return i;
|
|
3509
|
+
}, Ki = (s, e, t, i, r, n) => {
|
|
3510
|
+
var o, a, c, l = e & 7, h = !1, d = 0, u = s[d] || (s[d] = []), f = l && (r = r.prototype, l < 5 && (l > 3 || !h) && Ui(r, t));
|
|
3511
|
+
Bi(r, t);
|
|
3512
|
+
for (var p = i.length - 1; p >= 0; p--)
|
|
3513
|
+
c = Hi(l, t, a = {}, s[3], u), o = (0, i[p])(r, c), a._ = 1, at(o) && (r = o);
|
|
3514
|
+
return qi(s, r), f && Se(r, t, f), h ? l ^ 4 ? n : f : r;
|
|
3515
|
+
}, lt, ke, ct;
|
|
3516
|
+
lt = [de(["storage", "wiki"])];
|
|
3517
|
+
class ee extends (ct = 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
|
+
this.defineCategory({
|
|
3530
|
+
name: "general",
|
|
3531
|
+
label: "General",
|
|
3532
|
+
description: "General settings",
|
|
3533
|
+
autoGenerateForm: !0
|
|
3534
|
+
}), this.defineCategory({
|
|
3535
|
+
name: "editor",
|
|
3536
|
+
label: "Editor",
|
|
3537
|
+
description: "Settings related to editing content",
|
|
3538
|
+
autoGenerateForm: !0
|
|
3539
|
+
});
|
|
3540
|
+
}
|
|
3541
|
+
async get(e, t) {
|
|
3542
|
+
if (!e)
|
|
3543
|
+
return this.getAll();
|
|
3544
|
+
t ??= () => {
|
|
3545
|
+
const r = this.defaultOf(e);
|
|
3546
|
+
return this.logger.debug(e, `(fallback value: ${r})`), r;
|
|
3547
|
+
};
|
|
3548
|
+
const i = await this.db.get(e, void 0);
|
|
3549
|
+
return i !== null ? i : await Di(t);
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* 获取全部注册的配置项以及最终生效的值
|
|
3553
|
+
* 未保存的配置项将使用默认值
|
|
3554
|
+
*/
|
|
3555
|
+
async getAll() {
|
|
3556
|
+
const e = this.loadDefaultConfigs();
|
|
3557
|
+
for await (const [t, i] of this.db.entries())
|
|
3558
|
+
t !== "_touched" && t in e && (e[t] = i.value);
|
|
3559
|
+
return e;
|
|
3560
|
+
}
|
|
3561
|
+
async set(e, t) {
|
|
3562
|
+
return (await this.setMany({ [e]: t }))[e];
|
|
3563
|
+
}
|
|
3564
|
+
async setMany(e) {
|
|
3565
|
+
const t = this.loadDefaultConfigs(), i = {};
|
|
3566
|
+
for (const [r, n] of Object.entries(e))
|
|
3567
|
+
n === t[r] || n === void 0 ? i[r] = void 0 : i[r] = n;
|
|
3568
|
+
return await this.db.set(i), this.ctx.emit("preferences/changed", { ctx: this.ctx, input: e, changes: i }), i;
|
|
3569
|
+
}
|
|
3570
|
+
defaultOf(e) {
|
|
3571
|
+
return this._defaultPreferences[e] ??= this.loadDefaultConfigs()[e];
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* Get exportable configurations
|
|
3575
|
+
* - exclude values that are the same as the default value
|
|
3576
|
+
* - exclude invalid or undefined values
|
|
3577
|
+
* - sort by keys
|
|
3578
|
+
*/
|
|
3579
|
+
async getExportableRecord(e) {
|
|
3580
|
+
e ??= await this.getAll();
|
|
3581
|
+
const t = this.loadDefaultConfigs(), i = {};
|
|
3582
|
+
return Object.entries(t).sort(([r], [n]) => r.localeCompare(n)).forEach(([r, n]) => {
|
|
3583
|
+
const o = e[r];
|
|
3584
|
+
o !== void 0 && o !== n && (i[r] = o);
|
|
3585
|
+
}), i;
|
|
3586
|
+
}
|
|
3587
|
+
loadDefaultConfigs() {
|
|
3588
|
+
const e = {};
|
|
3589
|
+
return this.getConfigRegistries().forEach((t) => {
|
|
3590
|
+
try {
|
|
3591
|
+
const i = t.schema({});
|
|
3592
|
+
Object.entries(i).forEach(([r, n]) => {
|
|
3593
|
+
e[r] = n;
|
|
3594
|
+
});
|
|
3595
|
+
} catch {
|
|
3596
|
+
}
|
|
3597
|
+
}), Object.entries(e).forEach(([t, i]) => {
|
|
3598
|
+
this._defaultPreferences[t] = i;
|
|
3599
|
+
}), e;
|
|
3600
|
+
}
|
|
3601
|
+
registerCustomConfig(e, t, i) {
|
|
3602
|
+
return this.customRegistries.push({
|
|
3603
|
+
name: e,
|
|
3604
|
+
schema: t,
|
|
3605
|
+
category: i || "general"
|
|
3606
|
+
}), this;
|
|
3607
|
+
}
|
|
3608
|
+
getConfigRegistries(e) {
|
|
3609
|
+
return Array.from(this.ctx.registry.entries()).map(([t]) => t === null ? {
|
|
3610
|
+
name: "@root",
|
|
3611
|
+
schema: te?.PreferencesSchema || null
|
|
3612
|
+
} : {
|
|
3613
|
+
name: t.name,
|
|
3614
|
+
schema: t?.PreferencesSchema || null
|
|
3615
|
+
}).filter((t) => t.schema !== null).map((t) => ({
|
|
3616
|
+
...t,
|
|
3617
|
+
category: t.schema.meta.category || "general"
|
|
3618
|
+
})).concat(this.customRegistries).filter((t) => !e || t.category === e);
|
|
3619
|
+
}
|
|
3620
|
+
getAllSchema() {
|
|
3621
|
+
return new W(
|
|
3622
|
+
W.intersect(this.getConfigRegistries().map((e) => e.schema))
|
|
3623
|
+
);
|
|
3624
|
+
}
|
|
3625
|
+
defineCategory(e) {
|
|
3626
|
+
const t = this.categoryDefinitions.findIndex((i) => i.name === e.name);
|
|
3627
|
+
return t < 0 ? this.categoryDefinitions.push(e) : this.categoryDefinitions[t] = e, this.categoryDefinitions.sort((i, r) => (i.index ?? 0) - (r.index ?? 0)), this;
|
|
3628
|
+
}
|
|
3629
|
+
getConfigCategories() {
|
|
3630
|
+
return this.categoryDefinitions;
|
|
3631
|
+
}
|
|
3632
|
+
async _migrageFromLegacyMasterDB() {
|
|
3633
|
+
const e = this.ctx.storage.createDatabase("preferences", 1 / 0);
|
|
3634
|
+
let t = 0;
|
|
3635
|
+
for await (const [i, r] of e.entries())
|
|
3636
|
+
i !== "_touched" && (await this.db.set(i, r.value), t++);
|
|
3637
|
+
return t && this.logger.info(`Migrated ${t} preferences from master DB`), await e.clear(), await e?.db?.disconnect?.(), t;
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
ke = ji(ct);
|
|
3641
|
+
ee = Ki(ke, 0, "PreferencesService", lt, ee);
|
|
3642
|
+
Wi(ke, 1, ee);
|
|
3643
|
+
class te extends ft {
|
|
3644
|
+
constructor(e) {
|
|
3645
|
+
super({
|
|
3646
|
+
name: "InPageEdit"
|
|
3647
|
+
}), this.version = "0.13.0-alpha.0", this.Endpoints = pt, this.schema = W, this.config = F(te.DEFAULT_CONFIG, e), this.logger = vt({
|
|
3648
|
+
name: "IPE",
|
|
3649
|
+
color: "#33aaff",
|
|
3650
|
+
level: this.config.logLevel
|
|
3651
|
+
}), this.#e(), this.config.autoInstallCorePlugins && this.#t(), this.#s();
|
|
3652
|
+
}
|
|
3653
|
+
static {
|
|
3654
|
+
this.DEFAULT_CONFIG = {
|
|
3655
|
+
apiConfigs: {},
|
|
3656
|
+
legacyPreferences: {},
|
|
3657
|
+
logLevel: Ie.info,
|
|
3658
|
+
storageNamespace: "InPageEdit",
|
|
3659
|
+
autoloadStyles: !0,
|
|
3660
|
+
autoInstallCorePlugins: !0
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
async #e() {
|
|
3664
|
+
this.plugin(It, this.config.apiConfigs), this.plugin(V), this.plugin(Kt), this.plugin(yi), this.plugin(ee), this.plugin(Ci, { dbName: this.config.storageNamespace }), this.plugin(J), this.plugin(Pi), this.plugin(ve), this.#i([
|
|
3665
|
+
"api",
|
|
3666
|
+
"currentPage",
|
|
3667
|
+
"resourceLoader",
|
|
3668
|
+
"modal",
|
|
3669
|
+
"preferences",
|
|
3670
|
+
"storage",
|
|
3671
|
+
"wikiPage",
|
|
3672
|
+
"wikiTitle",
|
|
3673
|
+
// WikiMetadataService
|
|
3674
|
+
"wiki",
|
|
3675
|
+
"getUrl",
|
|
3676
|
+
"getSciprtUrl",
|
|
3677
|
+
"getMainpageUrl"
|
|
3678
|
+
]);
|
|
3679
|
+
}
|
|
3680
|
+
#i(e) {
|
|
3681
|
+
if (typeof e == "string" && (e = [e]), !Array.isArray(e) || e.length === 0) return this;
|
|
3682
|
+
for (const t of e) {
|
|
3683
|
+
const i = this[te.internal][t];
|
|
3684
|
+
i?.type === "service" && (i.builtin = !0);
|
|
3685
|
+
}
|
|
3686
|
+
return this;
|
|
3687
|
+
}
|
|
3688
|
+
// TODO: 这里不应该硬编码,暂时先这样
|
|
3689
|
+
async #t() {
|
|
3690
|
+
[
|
|
3691
|
+
import("./index-BQ-cHWkJ.js").then(({ PluginAnalytics: t }) => t),
|
|
3692
|
+
import("./index-BJ7_Q1mB.js").then(
|
|
3693
|
+
({ PluginInArticleLinks: t }) => t
|
|
3694
|
+
),
|
|
3695
|
+
import("./index-BwdWyHLe.js").then(({ PluginPluginStore: t }) => t),
|
|
3696
|
+
import("./index-BCdABp0e.js").then(
|
|
3697
|
+
({ PluginPreferencesUI: t }) => t
|
|
3698
|
+
),
|
|
3699
|
+
import("./index-CyG7_IYz.js").then(({ PluginQuickEdit: t }) => t),
|
|
3700
|
+
import("./index-2RfILgXm.js").then(({ PluginQuickMove: t }) => t),
|
|
3701
|
+
import("./index-BNh95-x2.js").then(
|
|
3702
|
+
({ PluginQuickPreview: t }) => t
|
|
3703
|
+
),
|
|
3704
|
+
import("./index-CCRMmnwk.js").then(({ PluginQuickDiff: t }) => t),
|
|
3705
|
+
import("./index-CnIpUF9x.js").then(
|
|
3706
|
+
({ PluginQuickRedirect: t }) => t
|
|
3707
|
+
),
|
|
3708
|
+
import("./index-eSlbrNqF.js").then(({ PluginToolbox: t }) => t)
|
|
3709
|
+
].forEach(async (t) => {
|
|
3710
|
+
this.plugin(await t);
|
|
3711
|
+
});
|
|
3712
|
+
}
|
|
3713
|
+
// TODO: 应该抽象到 PluginTheme 中去,暂时先硬编码
|
|
3714
|
+
async #s() {
|
|
3715
|
+
this.inject(["resourceLoader"], (e) => {
|
|
3716
|
+
this.config.autoloadStyles && e.resourceLoader.loadStyle(import.meta.resolve("./style.css"));
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
async withInject(e) {
|
|
3720
|
+
const { promise: t, resolve: i } = Pe();
|
|
3721
|
+
return this.inject(e, (r) => {
|
|
3722
|
+
i(r);
|
|
3723
|
+
}), t;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
export {
|
|
3727
|
+
Ie as $,
|
|
3728
|
+
It as A,
|
|
3729
|
+
V as C,
|
|
3730
|
+
te as I,
|
|
3731
|
+
yi as M,
|
|
3732
|
+
Z as N,
|
|
3733
|
+
ye as P,
|
|
3734
|
+
Kt as R,
|
|
3735
|
+
vt as S,
|
|
3736
|
+
J as W,
|
|
3737
|
+
Ci as a,
|
|
3738
|
+
b,
|
|
3739
|
+
ee as c,
|
|
3740
|
+
Pi as d,
|
|
3741
|
+
ve as e,
|
|
3742
|
+
yt as m
|
|
3743
|
+
};
|
|
3744
|
+
//# sourceMappingURL=index-DdTiZqwt.js.map
|