@inpageedit/core 0.15.0 → 0.16.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/{ActionButton-CRjo_l3y.js → ActionButton-B6OUgtHx.js} +2 -2
- package/dist/{ActionButton-CRjo_l3y.js.map → ActionButton-B6OUgtHx.js.map} +1 -1
- package/dist/CheckBox-Dx3r3LQz.js +13 -0
- package/dist/CheckBox-Dx3r3LQz.js.map +1 -0
- package/dist/IconQuickDiff-BkbxyY-d.js +29 -0
- package/dist/IconQuickDiff-BkbxyY-d.js.map +1 -0
- package/dist/IconQuickEdit-BiRYADU_.js +68 -0
- package/dist/IconQuickEdit-BiRYADU_.js.map +1 -0
- package/dist/IconUpload-Bz4BW_nc.js +27 -0
- package/dist/IconUpload-Bz4BW_nc.js.map +1 -0
- package/dist/InPageEdit.js +20 -0
- package/dist/InPageEdit.js.map +1 -0
- package/dist/InputBox-D2ZRTMFP.js +42 -0
- package/dist/InputBox-D2ZRTMFP.js.map +1 -0
- package/dist/{PluginImagesUsed-Bq_C_rgg.js → PluginImagesUsed-BVyvFA1_.js} +7 -7
- package/dist/{PluginImagesUsed-Bq_C_rgg.js.map → PluginImagesUsed-BVyvFA1_.js.map} +1 -1
- package/dist/{PluginPrefSync-DP5NyPnI.js → PluginPrefSync-CUKkx4Qk.js} +10 -10
- package/dist/{PluginPrefSync-DP5NyPnI.js.map → PluginPrefSync-CUKkx4Qk.js.map} +1 -1
- package/dist/{PluginStoreApp-_YWpLgfs.js → PluginStoreApp-CoOAw1fr.js} +4 -4
- package/dist/{PluginStoreApp-_YWpLgfs.js.map → PluginStoreApp-CoOAw1fr.js.map} +1 -1
- package/dist/{PluginTemplatesUsed-DS_rHctR.js → PluginTemplatesUsed-CdjT1wR4.js} +12 -12
- package/dist/{PluginTemplatesUsed-DS_rHctR.js.map → PluginTemplatesUsed-CdjT1wR4.js.map} +1 -1
- package/dist/{index-CM_6yF2v.js → Promise.withResolvers-C4chhLB1.js} +17 -11
- package/dist/Promise.withResolvers-C4chhLB1.js.map +1 -0
- package/dist/{RadioBox-0UuxlcWZ.js → RadioBox-B0z9YHQg.js} +2 -2
- package/dist/{RadioBox-0UuxlcWZ.js.map → RadioBox-B0z9YHQg.js.map} +1 -1
- package/dist/components/index.js +75 -46
- package/dist/components/index.js.map +1 -1
- package/dist/{BasePlugin-BCVSn9QJ.js → core.js} +28 -10
- package/dist/core.js.map +1 -0
- package/dist/{index-n5KKWE9v.js → index-1tsXE6ax.js} +9 -8
- package/dist/{index-n5KKWE9v.js.map → index-1tsXE6ax.js.map} +1 -1
- package/dist/{index-CS1kidKF.js → index-B32tFyLB.js} +57 -57
- package/dist/{index-CS1kidKF.js.map → index-B32tFyLB.js.map} +1 -1
- package/dist/{index-Cq8xPcEY.js → index-BPTMltVf.js} +35 -35
- package/dist/index-BPTMltVf.js.map +1 -0
- package/dist/{index-rKL4D_7I.js → index-BYlcHc-O.js} +22 -24
- package/dist/index-BYlcHc-O.js.map +1 -0
- package/dist/{index-DjyjqpeO.js → index-C4qm_X_A.js} +11 -11
- package/dist/{index-DjyjqpeO.js.map → index-C4qm_X_A.js.map} +1 -1
- package/dist/index-CAtPo7xJ.js +793 -0
- package/dist/index-CAtPo7xJ.js.map +1 -0
- package/dist/{index-DPA1ptYq.js → index-CVCy0wPP.js} +8 -7
- package/dist/{index-DPA1ptYq.js.map → index-CVCy0wPP.js.map} +1 -1
- package/dist/index-CYfkwXRf.js +1631 -0
- package/dist/index-CYfkwXRf.js.map +1 -0
- package/dist/{index-mFwJhDwE.js → index-DZa9mxN4.js} +11 -11
- package/dist/{index-mFwJhDwE.js.map → index-DZa9mxN4.js.map} +1 -1
- package/dist/{index-B9VO3swL.js → index-Dm2vgYkZ.js} +58 -81
- package/dist/index-Dm2vgYkZ.js.map +1 -0
- package/dist/{index-C3t-Xj3e.js → index-NWWeW3tX.js} +10 -10
- package/dist/{index-C3t-Xj3e.js.map → index-NWWeW3tX.js.map} +1 -1
- package/dist/index-QnWieXQc.js +4932 -0
- package/dist/index-QnWieXQc.js.map +1 -0
- package/dist/{index-CbdkXGs7.js → index-bQ0CVu3l.js} +13 -17
- package/dist/{index-CbdkXGs7.js.map → index-bQ0CVu3l.js.map} +1 -1
- package/dist/{index-Cb2_vqBl.js → index-ygc4AMy4.js} +10 -10
- package/dist/{index-Cb2_vqBl.js.map → index-ygc4AMy4.js.map} +1 -1
- package/dist/{index-DD5CVCfD.js → index-z_qDGCMT.js} +2 -2
- package/dist/{index-DD5CVCfD.js.map → index-z_qDGCMT.js.map} +1 -1
- package/dist/index.d.ts +98 -36
- package/dist/index.js +24 -26
- package/dist/index.js.map +1 -1
- package/dist/{makeCallable-LDU0xZMJ.js → makeCallable-Cg4zUG4c.js} +2 -2
- package/dist/{makeCallable-LDU0xZMJ.js.map → makeCallable-Cg4zUG4c.js.map} +1 -1
- package/dist/models/index.js +7 -7
- package/dist/models/index.js.map +1 -1
- package/dist/plugins/index.js +12 -12
- package/dist/services/index.js +5 -4
- package/dist/style.css +1 -1
- package/dist/{vueHooks-l04s8cIl.js → vueHooks-Bs93iP61.js} +1519 -1492
- package/dist/vueHooks-Bs93iP61.js.map +1 -0
- package/lib/index.umd.js +19 -15
- package/lib/index.umd.js.map +1 -1
- package/lib/style.css +1 -1
- package/package.json +36 -27
- package/dist/BasePlugin-BCVSn9QJ.js.map +0 -1
- package/dist/IconQuickEdit-CMCQncyj.js +0 -27
- package/dist/IconQuickEdit-CMCQncyj.js.map +0 -1
- package/dist/InputBox-CZ1v4_l3.js +0 -50
- package/dist/InputBox-CZ1v4_l3.js.map +0 -1
- package/dist/Preferences-DqtjY7XU.js +0 -1541
- package/dist/Preferences-DqtjY7XU.js.map +0 -1
- package/dist/WatchlistAction-BbNAyryN.js +0 -5
- package/dist/WatchlistAction-BbNAyryN.js.map +0 -1
- package/dist/browser-DR-yCqVg.js +0 -1160
- package/dist/browser-DR-yCqVg.js.map +0 -1
- package/dist/index-B9VO3swL.js.map +0 -1
- package/dist/index-CG38LlAh.js +0 -46
- package/dist/index-CG38LlAh.js.map +0 -1
- package/dist/index-CM_6yF2v.js.map +0 -1
- package/dist/index-CcAmmXbb.js +0 -3290
- package/dist/index-CcAmmXbb.js.map +0 -1
- package/dist/index-Cq8xPcEY.js.map +0 -1
- package/dist/index-DVvsTsLI.js +0 -505
- package/dist/index-DVvsTsLI.js.map +0 -1
- package/dist/index-FvMu0Ka0.js +0 -342
- package/dist/index-FvMu0Ka0.js.map +0 -1
- package/dist/index-rKL4D_7I.js.map +0 -1
- package/dist/vueHooks-l04s8cIl.js.map +0 -1
package/dist/index-CcAmmXbb.js
DELETED
|
@@ -1,3290 +0,0 @@
|
|
|
1
|
-
import { u as mt, c as wt, a as yt } from "./index-DVvsTsLI.js";
|
|
2
|
-
import { c as L, q as _e, I as j, S as p, d as Pe, i as bt, p as O, R as vt, E as Re, j as _t } from "./Preferences-DqtjY7XU.js";
|
|
3
|
-
import { J as $e, e as $t, A as St } from "./browser-DR-yCqVg.js";
|
|
4
|
-
import { j as E, P as xt } from "./index-CM_6yF2v.js";
|
|
5
|
-
var De = /* @__PURE__ */ ((n) => (n[n.debug = -1] = "debug", n[n.log = 0] = "log", n[n.info = 1] = "info", n[n.warn = 2] = "warn", n[n.error = 3] = "error", n[n.silent = 4] = "silent", n))(De || {});
|
|
6
|
-
const te = globalThis || window, ie = Symbol.for("__IPE_LOGGER_COLOR_MAP__");
|
|
7
|
-
te[ie] || (te[ie] = /* @__PURE__ */ new Map());
|
|
8
|
-
const Q = te[ie];
|
|
9
|
-
function F(n) {
|
|
10
|
-
let e = 2166136261;
|
|
11
|
-
for (let t = 0; t < n.length; t++)
|
|
12
|
-
e ^= n.charCodeAt(t), e = (e >>> 0) * 16777619;
|
|
13
|
-
return e >>> 0;
|
|
14
|
-
}
|
|
15
|
-
const Se = [
|
|
16
|
-
[350, 360],
|
|
17
|
-
[0, 15],
|
|
18
|
-
[15, 30],
|
|
19
|
-
[200, 230],
|
|
20
|
-
[230, 250],
|
|
21
|
-
[250, 280],
|
|
22
|
-
[280, 310],
|
|
23
|
-
[310, 330],
|
|
24
|
-
[140, 160],
|
|
25
|
-
[160, 180]
|
|
26
|
-
];
|
|
27
|
-
function kt(n, e) {
|
|
28
|
-
const t = Se.length, i = F(n) % t, [s, r] = Se[i], o = r - s, a = F(n + ":" + e), c = s + a % (o || 1), l = F(n + ":s"), h = F(n + ":l");
|
|
29
|
-
let u, f;
|
|
30
|
-
if (e === "name")
|
|
31
|
-
u = 62 + l % 18, f = 30 + h % 12;
|
|
32
|
-
else {
|
|
33
|
-
const d = c >= 0 && c < 50 || c > 330 && c < 360, g = c >= 200 && c <= 300;
|
|
34
|
-
u = 55 + l % 20, g ? f = 55 + h % 8 : d ? f = 48 + h % 6 : f = 50 + h % 8, u < 60 && (u += 5);
|
|
35
|
-
}
|
|
36
|
-
return `hsl(${c}, ${u}%, ${f}%)`;
|
|
37
|
-
}
|
|
38
|
-
function z(n, e) {
|
|
39
|
-
if (e)
|
|
40
|
-
return Q.set(n, e), e;
|
|
41
|
-
const t = Q.get(n);
|
|
42
|
-
if (t) return t;
|
|
43
|
-
const i = n.startsWith("name:") ? "name" : "group", s = kt(n, i);
|
|
44
|
-
return Q.set(n, s), s;
|
|
45
|
-
}
|
|
46
|
-
class oe {
|
|
47
|
-
/**
|
|
48
|
-
* Note: constructor returns a callable Proxy so that you can do `logger('group')`.
|
|
49
|
-
*/
|
|
50
|
-
constructor(e = {}) {
|
|
51
|
-
this._custom = (t) => {
|
|
52
|
-
if (!this._enabled(t.level)) return xe;
|
|
53
|
-
const [i, s] = this._prefix(t.label);
|
|
54
|
-
return this._consoleMethod(t.method).bind(console, i, ...s);
|
|
55
|
-
}, this._name = e.name, this._nameColor = e.color, this._groupPath = e._groupPath ? [...e._groupPath] : [], this._dynamicLevels = { ...e._dynamicLevels }, this._levelRef = e._levelRef ?? {
|
|
56
|
-
value: e.level ?? 1
|
|
57
|
-
/* info */
|
|
58
|
-
}, this._name && z(`name:${this._name}`, this._nameColor), this._installBuiltinLevels();
|
|
59
|
-
for (const t of Object.keys(this._dynamicLevels))
|
|
60
|
-
this._installLevelGetter(t, this._dynamicLevels[t]);
|
|
61
|
-
return Ct(this);
|
|
62
|
-
}
|
|
63
|
-
// ---------- public API ----------
|
|
64
|
-
get level() {
|
|
65
|
-
return this._levelRef.value;
|
|
66
|
-
}
|
|
67
|
-
set level(e) {
|
|
68
|
-
this._levelRef.value = e;
|
|
69
|
-
}
|
|
70
|
-
/** Create a sub-logger with a group label */
|
|
71
|
-
group(e, t) {
|
|
72
|
-
return e && z(`group:${e}`, t?.color), new oe({
|
|
73
|
-
name: this._name,
|
|
74
|
-
color: this._nameColor,
|
|
75
|
-
_groupPath: [...this._groupPath, e],
|
|
76
|
-
_dynamicLevels: this._dynamicLevels,
|
|
77
|
-
_levelRef: this._levelRef
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/** Define a custom level, e.g. logger.defineLevel('success', { level: info, label: '✅', method: 'info' }) */
|
|
81
|
-
defineLevel(e, t) {
|
|
82
|
-
this._dynamicLevels[e] = { ...t }, this._installLevelGetter(e, t);
|
|
83
|
-
}
|
|
84
|
-
// Built-in level getters
|
|
85
|
-
get debug() {
|
|
86
|
-
return this._method("debug");
|
|
87
|
-
}
|
|
88
|
-
get log() {
|
|
89
|
-
return this._method("log");
|
|
90
|
-
}
|
|
91
|
-
get info() {
|
|
92
|
-
return this._method("info");
|
|
93
|
-
}
|
|
94
|
-
get warn() {
|
|
95
|
-
return this._method("warn");
|
|
96
|
-
}
|
|
97
|
-
get error() {
|
|
98
|
-
return this._method("error");
|
|
99
|
-
}
|
|
100
|
-
// ---------- internals ----------
|
|
101
|
-
_installBuiltinLevels() {
|
|
102
|
-
}
|
|
103
|
-
_installLevelGetter(e, t) {
|
|
104
|
-
Object.defineProperty(this, e, {
|
|
105
|
-
configurable: !0,
|
|
106
|
-
enumerable: !1,
|
|
107
|
-
get: () => this._custom(t)
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
_method(e) {
|
|
111
|
-
const t = Et[e];
|
|
112
|
-
if (!this._enabled(t.level)) return xe;
|
|
113
|
-
const [i, s] = this._prefix(t.label);
|
|
114
|
-
return this._consoleMethod(e).bind(console, i, ...s);
|
|
115
|
-
}
|
|
116
|
-
_consoleMethod(e) {
|
|
117
|
-
return (console[e] || console.log).bind(console);
|
|
118
|
-
}
|
|
119
|
-
_enabled(e) {
|
|
120
|
-
return e >= this._levelRef.value && this._levelRef.value !== 4;
|
|
121
|
-
}
|
|
122
|
-
_prefix(e) {
|
|
123
|
-
const t = [];
|
|
124
|
-
let i = "";
|
|
125
|
-
if (this._name) {
|
|
126
|
-
const s = z(`name:${this._name}`, this._nameColor);
|
|
127
|
-
i += `%c${this._name}%c`, t.push(
|
|
128
|
-
`background:${s}; color:#fff; padding:1px 4px; border-radius:2px; font-weight:700;`,
|
|
129
|
-
ke
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
if (e && (i += ` ${e}`), this._groupPath.length) {
|
|
133
|
-
const s = this._groupPath.join("/"), r = z(`group:${s}`);
|
|
134
|
-
i += ` %c${s}%c`, t.push(`color:${r}; text-decoration: underline;`, ke);
|
|
135
|
-
}
|
|
136
|
-
return [i, t];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const xe = () => {
|
|
140
|
-
}, ke = "color:inherit; background:transparent; text-decoration:none;", Et = {
|
|
141
|
-
debug: { level: -1, label: "", method: "debug" },
|
|
142
|
-
log: { level: 0, label: "", method: "log" },
|
|
143
|
-
info: { level: 1, label: "[I]", method: "info" },
|
|
144
|
-
warn: { level: 2, label: "[W]", method: "warn" },
|
|
145
|
-
error: { level: 3, label: "[E]", method: "error" }
|
|
146
|
-
};
|
|
147
|
-
function Ct(n) {
|
|
148
|
-
const e = function(t, i) {
|
|
149
|
-
return n.group(t, i);
|
|
150
|
-
};
|
|
151
|
-
return new Proxy(e, {
|
|
152
|
-
get(t, i, s) {
|
|
153
|
-
return n[i];
|
|
154
|
-
},
|
|
155
|
-
set(t, i, s) {
|
|
156
|
-
return n[i] = s, !0;
|
|
157
|
-
},
|
|
158
|
-
apply(t, i, s) {
|
|
159
|
-
return n.group(s[0], s[1]);
|
|
160
|
-
},
|
|
161
|
-
has(t, i) {
|
|
162
|
-
return i in n;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function It(n) {
|
|
167
|
-
return new oe(n);
|
|
168
|
-
}
|
|
169
|
-
class Lt {
|
|
170
|
-
constructor(e, t = {}) {
|
|
171
|
-
this.ctx = e, this.options = t, this._apiClients = /* @__PURE__ */ new Map(), location?.href && t?.baseURL?.toString()?.startsWith("/") && (t.baseURL = new URL(t.baseURL, location.origin));
|
|
172
|
-
const i = this.api = new $e({
|
|
173
|
-
baseURL: t.baseURL.toString(),
|
|
174
|
-
fexiosConfigs: {
|
|
175
|
-
headers: {
|
|
176
|
-
"x-api-user-agent": `InPageEdit-NEXT ${e.version}`,
|
|
177
|
-
...t.headers
|
|
178
|
-
},
|
|
179
|
-
...t
|
|
180
|
-
},
|
|
181
|
-
throwOnApiError: !0
|
|
182
|
-
});
|
|
183
|
-
e.set("api", i), e.set("apiService", this);
|
|
184
|
-
}
|
|
185
|
-
getClientByFileRepo(e) {
|
|
186
|
-
const t = new URL(`${e.scriptDirUrl}/api.php`, location.origin), i = t.toString();
|
|
187
|
-
if (i === this.ctx.root.config.apiConfigs.baseURL?.toString())
|
|
188
|
-
return this.ctx.api;
|
|
189
|
-
if (!this._apiClients.has(i)) {
|
|
190
|
-
const s = t.origin === location.origin, r = {
|
|
191
|
-
baseURL: t.toString(),
|
|
192
|
-
throwOnApiError: !0
|
|
193
|
-
}, o = s ? new $e(r) : new $t(r);
|
|
194
|
-
o.request.on("beforeRequest", (a) => {
|
|
195
|
-
a.headers = o.request.mergeHeaders(a.headers, {
|
|
196
|
-
"x-api-user-agent": null,
|
|
197
|
-
"x-mw-token-name": null
|
|
198
|
-
});
|
|
199
|
-
}), this._apiClients.set(i, o);
|
|
200
|
-
}
|
|
201
|
-
return this._apiClients.get(i);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
var At = Object.create, ae = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Te = (n, e) => (e = Symbol[n]) ? e : Symbol.for("Symbol." + n), Me = (n) => {
|
|
205
|
-
throw TypeError(n);
|
|
206
|
-
}, Rt = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Dt = (n, e) => ae(n, "name", { value: e, configurable: !0 }), Tt = (n) => [, , , At(n?.[Te("metadata")] ?? null)], Mt = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Ue = (n) => n !== void 0 && typeof n != "function" ? Me("Function expected") : n, Ut = (n, e, t, i, s) => ({ kind: Mt[n], name: e, metadata: i, addInitializer: (r) => t._ ? Me("Already initialized") : s.push(Ue(r || null)) }), Bt = (n, e) => Rt(e, Te("metadata"), n[3]), Ot = (n, e, t, i) => {
|
|
207
|
-
for (var s = 0, r = n[e >> 1], o = r && r.length; s < o; s++) r[s].call(t);
|
|
208
|
-
return i;
|
|
209
|
-
}, Nt = (n, e, t, i, s, r) => {
|
|
210
|
-
var o, a, c, l = e & 7, h = !1, u = 0, f = n[u] || (n[u] = []), d = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Pt(s, t));
|
|
211
|
-
Dt(s, t);
|
|
212
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
213
|
-
c = Ut(l, t, a = {}, n[3], f), o = (0, i[g])(s, c), a._ = 1, Ue(o) && (s = o);
|
|
214
|
-
return Bt(n, s), d && ae(s, t, d), h ? l ^ 4 ? r : d : s;
|
|
215
|
-
}, Be, le, Oe;
|
|
216
|
-
Be = [j(["wiki", "wikiTitle"])];
|
|
217
|
-
class H extends (Oe = L) {
|
|
218
|
-
constructor(e) {
|
|
219
|
-
super(e, "currentPage", !1), this.ctx = e, this.url = new URL(window.location.href), this.isMainPage = void 0, this.wikiTitle = void 0;
|
|
220
|
-
}
|
|
221
|
-
get logger() {
|
|
222
|
-
return this.ctx.logger("CURRENT_PAGE");
|
|
223
|
-
}
|
|
224
|
-
async start() {
|
|
225
|
-
await this.#e(), this.#i(), window.addEventListener("popstate", this.#t.bind(this)), this.logger.info("initialized", this.wikiTitle);
|
|
226
|
-
}
|
|
227
|
-
stop() {
|
|
228
|
-
window.removeEventListener("popstate", this.#t.bind(this));
|
|
229
|
-
}
|
|
230
|
-
async #e() {
|
|
231
|
-
await this.#s(), await this.#n();
|
|
232
|
-
}
|
|
233
|
-
#i() {
|
|
234
|
-
const e = Symbol.for("InPageEdit.CurrentPageService.UrlChangeListenerInstalled");
|
|
235
|
-
if (window[e])
|
|
236
|
-
return;
|
|
237
|
-
const t = history.pushState, i = history.replaceState;
|
|
238
|
-
history.pushState = function(s, r, o) {
|
|
239
|
-
t.apply(this, [s, r, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: s }));
|
|
240
|
-
}, history.replaceState = function(s, r, o) {
|
|
241
|
-
i.apply(this, [s, r, o]), window.dispatchEvent(new PopStateEvent("popstate", { state: s }));
|
|
242
|
-
}, window[e] = !0;
|
|
243
|
-
}
|
|
244
|
-
async #t(e) {
|
|
245
|
-
const t = this.url, i = new URL(window.location.href);
|
|
246
|
-
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));
|
|
247
|
-
}
|
|
248
|
-
get params() {
|
|
249
|
-
return this.url.searchParams;
|
|
250
|
-
}
|
|
251
|
-
get canonicalUrl() {
|
|
252
|
-
const e = (_e('link[rel="alternate"][hreflang="x-default"]') || _e('link[rel="canonical"]'))?.href;
|
|
253
|
-
let t = null;
|
|
254
|
-
return e && (t = new URL(e, location.origin)), Reflect.defineProperty(this, "canonicalUrl", {
|
|
255
|
-
get: () => t
|
|
256
|
-
}), t;
|
|
257
|
-
}
|
|
258
|
-
async #n() {
|
|
259
|
-
const t = this.wikiTitle?.getMainDBKey() === this.ctx.wiki.mainPageName;
|
|
260
|
-
return Reflect.defineProperty(this, "isMainPage", {
|
|
261
|
-
get: () => t
|
|
262
|
-
}), t;
|
|
263
|
-
}
|
|
264
|
-
async #s() {
|
|
265
|
-
let e = null;
|
|
266
|
-
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", {
|
|
267
|
-
get: () => e
|
|
268
|
-
}), e;
|
|
269
|
-
}
|
|
270
|
-
get wikiAction() {
|
|
271
|
-
return this.params.get("action") || "view";
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
le = Tt(Oe);
|
|
275
|
-
H = Nt(le, 0, "CurrentPageService", Be, H);
|
|
276
|
-
Ot(le, 1, H);
|
|
277
|
-
class jt extends L {
|
|
278
|
-
constructor(e) {
|
|
279
|
-
super(e, "resourceLoader", !0), this.ctx = e;
|
|
280
|
-
}
|
|
281
|
-
stop() {
|
|
282
|
-
this.removeAll();
|
|
283
|
-
}
|
|
284
|
-
loadScript(e, t) {
|
|
285
|
-
if (!e)
|
|
286
|
-
return Promise.resolve(null);
|
|
287
|
-
const i = `script:${e}`, s = document.querySelector(`[data-ipe="${i}"]`);
|
|
288
|
-
return s ? Promise.resolve(s) : new Promise((o, a) => {
|
|
289
|
-
const c = document.createElement("script");
|
|
290
|
-
c.src = e, c.dataset.ipe = i, t && Object.entries(t).forEach(([l, h]) => {
|
|
291
|
-
typeof h > "u" || h === !1 || h === null ? c.removeAttribute(l) : c.setAttribute(l, h);
|
|
292
|
-
}), document.body.appendChild(c), c.onload = () => o(c), c.onerror = (l) => a(l);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
loadStyle(e, t) {
|
|
296
|
-
if (!e)
|
|
297
|
-
return Promise.resolve(null);
|
|
298
|
-
const i = `style:${e}`, s = document.querySelector(`[data-ipe="${i}"]`);
|
|
299
|
-
return s ? Promise.resolve(s) : new Promise((o, a) => {
|
|
300
|
-
const c = document.createElement("link");
|
|
301
|
-
c.rel = "stylesheet", c.href = e, c.dataset.ipe = i, t && Object.entries(t).forEach(([h, u]) => {
|
|
302
|
-
typeof u > "u" || u === !1 || u === null ? c.removeAttribute(h) : c.setAttribute(h, u);
|
|
303
|
-
}), (document.querySelector('meta[name="ipe-styles"]') || (() => {
|
|
304
|
-
const h = document.createElement("meta");
|
|
305
|
-
return h.id = "ipe-styles", h.name = "ipe-styles", document.head.insertAdjacentElement("afterbegin", h), h;
|
|
306
|
-
})()).before(c), c.onload = () => o(c), c.onerror = (h) => a(h);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
removeStyle(e) {
|
|
310
|
-
const t = `style:${e}`, i = document.querySelector(`[data-ipe="${t}"]`);
|
|
311
|
-
i && i.remove();
|
|
312
|
-
}
|
|
313
|
-
removeScript(e) {
|
|
314
|
-
const t = `script:${e}`, i = document.querySelector(`[data-ipe="${t}"]`);
|
|
315
|
-
i && i.remove();
|
|
316
|
-
}
|
|
317
|
-
removeAll() {
|
|
318
|
-
document.querySelectorAll("[data-ipe]").forEach((e) => {
|
|
319
|
-
e.remove();
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
resolveImportPath(e) {
|
|
323
|
-
return e.startsWith("http") || e.startsWith("//") ? e : import.meta.resolve(e);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
const J = Object.keys;
|
|
327
|
-
function Ft(n) {
|
|
328
|
-
return typeof n == "boolean";
|
|
329
|
-
}
|
|
330
|
-
function zt(n) {
|
|
331
|
-
return n && typeof n.nodeType == "number";
|
|
332
|
-
}
|
|
333
|
-
function ce(n) {
|
|
334
|
-
return typeof n == "string";
|
|
335
|
-
}
|
|
336
|
-
function Ne(n) {
|
|
337
|
-
return typeof n == "number";
|
|
338
|
-
}
|
|
339
|
-
function D(n) {
|
|
340
|
-
return typeof n == "object" ? n !== null : N(n);
|
|
341
|
-
}
|
|
342
|
-
function N(n) {
|
|
343
|
-
return typeof n == "function";
|
|
344
|
-
}
|
|
345
|
-
function Kt(n) {
|
|
346
|
-
return !!(n && n.isComponent);
|
|
347
|
-
}
|
|
348
|
-
function Ht(n) {
|
|
349
|
-
return D(n) && typeof n.length == "number" && typeof n.nodeType != "number";
|
|
350
|
-
}
|
|
351
|
-
function ne(n, e) {
|
|
352
|
-
if (n)
|
|
353
|
-
for (const t of J(n))
|
|
354
|
-
e(n[t], t);
|
|
355
|
-
}
|
|
356
|
-
function Wt(n) {
|
|
357
|
-
return D(n) && "current" in n;
|
|
358
|
-
}
|
|
359
|
-
const se = {
|
|
360
|
-
animationIterationCount: 0,
|
|
361
|
-
borderImageOutset: 0,
|
|
362
|
-
borderImageSlice: 0,
|
|
363
|
-
borderImageWidth: 0,
|
|
364
|
-
boxFlex: 0,
|
|
365
|
-
boxFlexGroup: 0,
|
|
366
|
-
boxOrdinalGroup: 0,
|
|
367
|
-
columnCount: 0,
|
|
368
|
-
columns: 0,
|
|
369
|
-
flex: 0,
|
|
370
|
-
flexGrow: 0,
|
|
371
|
-
flexPositive: 0,
|
|
372
|
-
flexShrink: 0,
|
|
373
|
-
flexNegative: 0,
|
|
374
|
-
flexOrder: 0,
|
|
375
|
-
gridArea: 0,
|
|
376
|
-
gridRow: 0,
|
|
377
|
-
gridRowEnd: 0,
|
|
378
|
-
gridRowSpan: 0,
|
|
379
|
-
gridRowStart: 0,
|
|
380
|
-
gridColumn: 0,
|
|
381
|
-
gridColumnEnd: 0,
|
|
382
|
-
gridColumnSpan: 0,
|
|
383
|
-
gridColumnStart: 0,
|
|
384
|
-
fontWeight: 0,
|
|
385
|
-
lineClamp: 0,
|
|
386
|
-
lineHeight: 0,
|
|
387
|
-
opacity: 0,
|
|
388
|
-
order: 0,
|
|
389
|
-
orphans: 0,
|
|
390
|
-
tabSize: 0,
|
|
391
|
-
widows: 0,
|
|
392
|
-
zIndex: 0,
|
|
393
|
-
zoom: 0,
|
|
394
|
-
// SVG-related properties
|
|
395
|
-
fillOpacity: 0,
|
|
396
|
-
floodOpacity: 0,
|
|
397
|
-
stopOpacity: 0,
|
|
398
|
-
strokeDasharray: 0,
|
|
399
|
-
strokeDashoffset: 0,
|
|
400
|
-
strokeMiterlimit: 0,
|
|
401
|
-
strokeOpacity: 0,
|
|
402
|
-
strokeWidth: 0
|
|
403
|
-
};
|
|
404
|
-
function qt(n, e) {
|
|
405
|
-
return n + e.charAt(0).toUpperCase() + e.substring(1);
|
|
406
|
-
}
|
|
407
|
-
const Gt = ["Webkit", "ms", "Moz", "O"];
|
|
408
|
-
J(se).forEach((n) => {
|
|
409
|
-
Gt.forEach((e) => {
|
|
410
|
-
se[qt(e, n)] = 0;
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
const Xt = Symbol.for("jsx-dom:type");
|
|
414
|
-
var je = /* @__PURE__ */ (function(n) {
|
|
415
|
-
return n.ShadowRoot = "ShadowRoot", n;
|
|
416
|
-
})(je || {});
|
|
417
|
-
function Yt(n) {
|
|
418
|
-
return n != null && n[Xt] === je.ShadowRoot;
|
|
419
|
-
}
|
|
420
|
-
const Vt = "http://www.w3.org/2000/svg", Jt = "http://www.w3.org/1999/xlink", Zt = "http://www.w3.org/XML/1998/namespace";
|
|
421
|
-
function Fe(n) {
|
|
422
|
-
return !Ft(n) && n != null;
|
|
423
|
-
}
|
|
424
|
-
function re(n) {
|
|
425
|
-
return Array.isArray(n) ? n.map(re).filter(Boolean).join(" ") : D(n) ? Symbol.iterator in n ? re(Array.from(n)) : J(n).filter((e) => n[e]).join(" ") : Fe(n) ? "" + n : "";
|
|
426
|
-
}
|
|
427
|
-
const Qt = {
|
|
428
|
-
animate: 0,
|
|
429
|
-
circle: 0,
|
|
430
|
-
clipPath: 0,
|
|
431
|
-
defs: 0,
|
|
432
|
-
desc: 0,
|
|
433
|
-
ellipse: 0,
|
|
434
|
-
feBlend: 0,
|
|
435
|
-
feColorMatrix: 0,
|
|
436
|
-
feComponentTransfer: 0,
|
|
437
|
-
feComposite: 0,
|
|
438
|
-
feConvolveMatrix: 0,
|
|
439
|
-
feDiffuseLighting: 0,
|
|
440
|
-
feDisplacementMap: 0,
|
|
441
|
-
feDistantLight: 0,
|
|
442
|
-
feFlood: 0,
|
|
443
|
-
feFuncA: 0,
|
|
444
|
-
feFuncB: 0,
|
|
445
|
-
feFuncG: 0,
|
|
446
|
-
feFuncR: 0,
|
|
447
|
-
feGaussianBlur: 0,
|
|
448
|
-
feImage: 0,
|
|
449
|
-
feMerge: 0,
|
|
450
|
-
feMergeNode: 0,
|
|
451
|
-
feMorphology: 0,
|
|
452
|
-
feOffset: 0,
|
|
453
|
-
fePointLight: 0,
|
|
454
|
-
feSpecularLighting: 0,
|
|
455
|
-
feSpotLight: 0,
|
|
456
|
-
feTile: 0,
|
|
457
|
-
feTurbulence: 0,
|
|
458
|
-
filter: 0,
|
|
459
|
-
foreignObject: 0,
|
|
460
|
-
g: 0,
|
|
461
|
-
image: 0,
|
|
462
|
-
line: 0,
|
|
463
|
-
linearGradient: 0,
|
|
464
|
-
marker: 0,
|
|
465
|
-
mask: 0,
|
|
466
|
-
metadata: 0,
|
|
467
|
-
path: 0,
|
|
468
|
-
pattern: 0,
|
|
469
|
-
polygon: 0,
|
|
470
|
-
polyline: 0,
|
|
471
|
-
radialGradient: 0,
|
|
472
|
-
rect: 0,
|
|
473
|
-
stop: 0,
|
|
474
|
-
svg: 0,
|
|
475
|
-
switch: 0,
|
|
476
|
-
symbol: 0,
|
|
477
|
-
text: 0,
|
|
478
|
-
textPath: 0,
|
|
479
|
-
tspan: 0,
|
|
480
|
-
use: 0,
|
|
481
|
-
view: 0
|
|
482
|
-
}, ei = /^(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)/;
|
|
483
|
-
function ti(n) {
|
|
484
|
-
const e = document.createDocumentFragment();
|
|
485
|
-
return Z(n.children, e), e;
|
|
486
|
-
}
|
|
487
|
-
function ii(n, e, t) {
|
|
488
|
-
e = {
|
|
489
|
-
...e,
|
|
490
|
-
children: t
|
|
491
|
-
};
|
|
492
|
-
const i = new n(e), s = i.render();
|
|
493
|
-
return "ref" in e && he(e.ref, i), s;
|
|
494
|
-
}
|
|
495
|
-
function m(n, e) {
|
|
496
|
-
let { children: t, ...i } = e;
|
|
497
|
-
!i.namespaceURI && Qt[n] === 0 && (i = {
|
|
498
|
-
...i,
|
|
499
|
-
namespaceURI: Vt
|
|
500
|
-
});
|
|
501
|
-
let s;
|
|
502
|
-
if (ce(n)) {
|
|
503
|
-
if (s = i.namespaceURI ? document.createElementNS(i.namespaceURI, n) : document.createElement(n), ri(i, s), Z(t, s), s instanceof window.HTMLSelectElement && i.value != null)
|
|
504
|
-
if (i.multiple === !0 && Array.isArray(i.value)) {
|
|
505
|
-
const r = i.value.map((o) => String(o));
|
|
506
|
-
s.querySelectorAll("option").forEach(
|
|
507
|
-
(o) => o.selected = r.includes(o.value)
|
|
508
|
-
);
|
|
509
|
-
} else
|
|
510
|
-
s.value = i.value;
|
|
511
|
-
he(i.ref, s);
|
|
512
|
-
} else if (N(n))
|
|
513
|
-
D(n.defaultProps) && (i = {
|
|
514
|
-
...n.defaultProps,
|
|
515
|
-
...i
|
|
516
|
-
}), s = Kt(n) ? ii(n, i, t) : n({
|
|
517
|
-
...i,
|
|
518
|
-
children: t
|
|
519
|
-
});
|
|
520
|
-
else
|
|
521
|
-
throw new TypeError(`Invalid JSX element type: ${n}`);
|
|
522
|
-
return s;
|
|
523
|
-
}
|
|
524
|
-
function he(n, e) {
|
|
525
|
-
Wt(n) ? n.current = e : N(n) && n(e);
|
|
526
|
-
}
|
|
527
|
-
function Z(n, e) {
|
|
528
|
-
if (Ht(n))
|
|
529
|
-
ni(n, e);
|
|
530
|
-
else if (ce(n) || Ne(n))
|
|
531
|
-
ee(document.createTextNode(n), e);
|
|
532
|
-
else if (n === null)
|
|
533
|
-
ee(document.createComment(""), e);
|
|
534
|
-
else if (zt(n))
|
|
535
|
-
ee(n, e);
|
|
536
|
-
else if (Yt(n)) {
|
|
537
|
-
const t = e.attachShadow(n.attr);
|
|
538
|
-
Z(n.children, t), he(n.ref, t);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
function ni(n, e) {
|
|
542
|
-
for (const t of [...n])
|
|
543
|
-
Z(t, e);
|
|
544
|
-
return e;
|
|
545
|
-
}
|
|
546
|
-
function ee(n, e) {
|
|
547
|
-
e instanceof window.HTMLTemplateElement ? e.content.appendChild(n) : e.appendChild(n);
|
|
548
|
-
}
|
|
549
|
-
function K(n, e) {
|
|
550
|
-
return n.replace(/[A-Z]/g, (t) => e + t.toLowerCase());
|
|
551
|
-
}
|
|
552
|
-
function ze(n, e) {
|
|
553
|
-
e == null || e === !1 || (Array.isArray(e) ? e.forEach((t) => ze(n, t)) : ce(e) ? n.setAttribute("style", e) : D(e) && ne(e, (t, i) => {
|
|
554
|
-
i.indexOf("-") === 0 ? n.style.setProperty(i, t) : Ne(t) && se[i] !== 0 ? n.style[i] = t + "px" : n.style[i] = t;
|
|
555
|
-
}));
|
|
556
|
-
}
|
|
557
|
-
function si(n, e, t) {
|
|
558
|
-
switch (n) {
|
|
559
|
-
case "xlinkActuate":
|
|
560
|
-
case "xlinkArcrole":
|
|
561
|
-
case "xlinkHref":
|
|
562
|
-
case "xlinkRole":
|
|
563
|
-
case "xlinkShow":
|
|
564
|
-
case "xlinkTitle":
|
|
565
|
-
case "xlinkType":
|
|
566
|
-
Ee(t, Jt, K(n, ":"), e);
|
|
567
|
-
return;
|
|
568
|
-
case "xmlnsXlink":
|
|
569
|
-
T(t, K(n, ":"), e);
|
|
570
|
-
return;
|
|
571
|
-
case "xmlBase":
|
|
572
|
-
case "xmlLang":
|
|
573
|
-
case "xmlSpace":
|
|
574
|
-
Ee(t, Zt, K(n, ":"), e);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
switch (n) {
|
|
578
|
-
case "htmlFor":
|
|
579
|
-
T(t, "for", e);
|
|
580
|
-
return;
|
|
581
|
-
case "dataset":
|
|
582
|
-
ne(e, (i, s) => {
|
|
583
|
-
i != null && (t.dataset[s] = i);
|
|
584
|
-
});
|
|
585
|
-
return;
|
|
586
|
-
case "innerHTML":
|
|
587
|
-
case "innerText":
|
|
588
|
-
case "textContent":
|
|
589
|
-
Fe(e) && (t[n] = e);
|
|
590
|
-
return;
|
|
591
|
-
case "dangerouslySetInnerHTML":
|
|
592
|
-
D(e) && (t.innerHTML = e.__html);
|
|
593
|
-
return;
|
|
594
|
-
case "value":
|
|
595
|
-
if (e == null || t instanceof window.HTMLSelectElement)
|
|
596
|
-
return;
|
|
597
|
-
if (t instanceof window.HTMLTextAreaElement) {
|
|
598
|
-
t.value = e;
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
break;
|
|
602
|
-
case "spellCheck":
|
|
603
|
-
t.spellcheck = e;
|
|
604
|
-
return;
|
|
605
|
-
case "class":
|
|
606
|
-
case "className":
|
|
607
|
-
N(e) ? e(t) : T(t, "class", re(e));
|
|
608
|
-
return;
|
|
609
|
-
case "ref":
|
|
610
|
-
case "namespaceURI":
|
|
611
|
-
return;
|
|
612
|
-
case "style":
|
|
613
|
-
ze(t, e);
|
|
614
|
-
return;
|
|
615
|
-
case "on":
|
|
616
|
-
case "onCapture":
|
|
617
|
-
ne(e, (i, s) => {
|
|
618
|
-
t.addEventListener(s, i, n === "onCapture");
|
|
619
|
-
});
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
if (N(e)) {
|
|
623
|
-
if (n[0] === "o" && n[1] === "n") {
|
|
624
|
-
let i = n.toLowerCase();
|
|
625
|
-
const s = i.endsWith("capture");
|
|
626
|
-
if (i === "ondoubleclick" ? i = "ondblclick" : s && i === "ondoubleclickcapture" && (i = "ondblclickcapture"), !s && t[i] === null)
|
|
627
|
-
t[i] = e;
|
|
628
|
-
else if (s)
|
|
629
|
-
t.addEventListener(
|
|
630
|
-
i.substring(2, i.length - 7),
|
|
631
|
-
e,
|
|
632
|
-
!0
|
|
633
|
-
);
|
|
634
|
-
else {
|
|
635
|
-
let r;
|
|
636
|
-
i in window ? r = i.substring(2) : r = i[2] + n.slice(3), t.addEventListener(r, e);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
} else D(e) ? t[n] = e : e === !0 ? T(t, n, "") : e !== !1 && e != null && (t instanceof SVGElement && !ei.test(n) ? T(t, K(n, "-"), e) : T(t, n, e));
|
|
640
|
-
}
|
|
641
|
-
function T(n, e, t) {
|
|
642
|
-
n.setAttribute(e, t);
|
|
643
|
-
}
|
|
644
|
-
function Ee(n, e, t, i) {
|
|
645
|
-
n.setAttributeNS(e, t, i);
|
|
646
|
-
}
|
|
647
|
-
function ri(n, e) {
|
|
648
|
-
for (const t of J(n))
|
|
649
|
-
si(t, n[t], e);
|
|
650
|
-
return e;
|
|
651
|
-
}
|
|
652
|
-
var ue = /* @__PURE__ */ ((n) => (n.Init = "modal.init", n.BeforeShow = "modal.beforeShow", n.Show = "modal.show", n.BeforeClose = "modal.beforeClose", n.Close = "modal.close", n.Destroy = "modal.destroy", n.ToastShow = "toast.show", n.ToastClose = "toast.close", n))(ue || {});
|
|
653
|
-
let oi = 0;
|
|
654
|
-
const Ce = (n) => `${n}-${++oi}`;
|
|
655
|
-
function B(n) {
|
|
656
|
-
return n instanceof Node ? n : document.createTextNode(String(n));
|
|
657
|
-
}
|
|
658
|
-
function I(n, e) {
|
|
659
|
-
if (!n) throw new Error(`${e ?? "Element"} not found`);
|
|
660
|
-
return n;
|
|
661
|
-
}
|
|
662
|
-
function Ie(n) {
|
|
663
|
-
const e = [
|
|
664
|
-
"a[href]",
|
|
665
|
-
"button:not([disabled])",
|
|
666
|
-
"input:not([disabled])",
|
|
667
|
-
"select:not([disabled])",
|
|
668
|
-
"textarea:not([disabled])",
|
|
669
|
-
'[tabindex]:not([tabindex="-1"])'
|
|
670
|
-
].join(",");
|
|
671
|
-
return Array.from(n.querySelectorAll(e)).filter(
|
|
672
|
-
(t) => !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length)
|
|
673
|
-
);
|
|
674
|
-
}
|
|
675
|
-
function x(n, e = {}) {
|
|
676
|
-
const t = document.createElement(n);
|
|
677
|
-
if (e.className && (t.className = e.className), e.html != null && (t.innerHTML = e.html), e.text != null && (t.textContent = e.text), e.attrs)
|
|
678
|
-
for (const [i, s] of Object.entries(e.attrs)) t.setAttribute(i, s);
|
|
679
|
-
return t;
|
|
680
|
-
}
|
|
681
|
-
const ai = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform), Ke = ["ctrl", "alt", "shift", "meta"];
|
|
682
|
-
function li(n) {
|
|
683
|
-
if (!n) return null;
|
|
684
|
-
const e = String(n).trim().toLowerCase().split(/[+\-\s]+/g).filter(Boolean), t = [];
|
|
685
|
-
let i = null;
|
|
686
|
-
const s = (o) => {
|
|
687
|
-
t.includes(o) || t.push(o);
|
|
688
|
-
};
|
|
689
|
-
for (const o of e) {
|
|
690
|
-
let a = o;
|
|
691
|
-
if (a === "control" || a === "ctrl") {
|
|
692
|
-
s("ctrl");
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
if (a === "alt" || a === "option") {
|
|
696
|
-
s("alt");
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
if (a === "shift") {
|
|
700
|
-
s("shift");
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
if (a === "meta" || a === "cmd" || a === "command" || a === "super") {
|
|
704
|
-
s("meta");
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
if (a === "mod") {
|
|
708
|
-
s(ai ? "meta" : "ctrl");
|
|
709
|
-
continue;
|
|
710
|
-
}
|
|
711
|
-
a === "esc" && (a = "escape"), a === "return" && (a = "enter"), (a === "space" || a === "spacebar") && (a = "space"), i = a;
|
|
712
|
-
}
|
|
713
|
-
const r = Ke.filter((o) => t.includes(o));
|
|
714
|
-
return !i || i === "" ? r.length ? r.join("+") : null : r.length ? `${r.join("+")}+${i}` : i;
|
|
715
|
-
}
|
|
716
|
-
function ci(n) {
|
|
717
|
-
const e = [];
|
|
718
|
-
n.ctrlKey && e.push("ctrl"), n.altKey && e.push("alt"), n.shiftKey && e.push("shift"), n.metaKey && e.push("meta");
|
|
719
|
-
let t = n.key;
|
|
720
|
-
t === " " && (t = "space");
|
|
721
|
-
const i = (t.length, t.toLowerCase()), s = Ke.filter((r) => e.includes(r));
|
|
722
|
-
return s.length ? `${s.join("+")}+${i}` : i;
|
|
723
|
-
}
|
|
724
|
-
class hi {
|
|
725
|
-
constructor() {
|
|
726
|
-
this.zBase = 1e3, this.stack = [];
|
|
727
|
-
}
|
|
728
|
-
push(e) {
|
|
729
|
-
this.stack.push(e), this.syncZ();
|
|
730
|
-
}
|
|
731
|
-
remove(e) {
|
|
732
|
-
this.stack = this.stack.filter((t) => t !== e), this.syncZ();
|
|
733
|
-
}
|
|
734
|
-
top() {
|
|
735
|
-
return this.stack[this.stack.length - 1];
|
|
736
|
-
}
|
|
737
|
-
closeAll(e, t) {
|
|
738
|
-
const i = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), s = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
739
|
-
[...this.stack].reverse().forEach((r) => {
|
|
740
|
-
const o = r.modalId, a = s.size ? s.has(r.pluginName) : !0, c = i.has(o);
|
|
741
|
-
a && !c && r.close();
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
removeAll() {
|
|
745
|
-
[...this.stack].forEach((e) => e.destroy()), this.stack = [];
|
|
746
|
-
}
|
|
747
|
-
syncZ() {
|
|
748
|
-
this.stack.forEach((e, t) => e.setZIndex(this.zBase + t * 2));
|
|
749
|
-
}
|
|
750
|
-
lockBodyScroll() {
|
|
751
|
-
document.body.classList.add("ipe-modal-no-scroll");
|
|
752
|
-
}
|
|
753
|
-
unlockBodyScroll() {
|
|
754
|
-
document.body.classList.remove("ipe-modal-no-scroll");
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
const k = new hi();
|
|
758
|
-
class W {
|
|
759
|
-
constructor(e = {}) {
|
|
760
|
-
this.backdropId = Ce("ipe-modal-backdrop"), this.modalId = Ce("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 = ue, this._hooks = [], this.startCloseTimer = (t) => {
|
|
761
|
-
this.stopCloseTimer(), this.closeTimer = window.setTimeout(() => this.close(), t);
|
|
762
|
-
}, this.stopCloseTimer = () => {
|
|
763
|
-
this.closeTimer && window.clearTimeout(this.closeTimer), this.closeTimer = void 0;
|
|
764
|
-
}, this.onDragMove = (t) => {
|
|
765
|
-
if (!this.isDragging) return;
|
|
766
|
-
t.preventDefault();
|
|
767
|
-
const i = t.clientX - this.dragStartX, s = t.clientY - this.dragStartY, r = this.get$modal(), o = this.modalStartX + i, a = this.modalStartY + s;
|
|
768
|
-
r.style.left = `${o}px`, r.style.top = `${a}px`;
|
|
769
|
-
}, this.onDragEnd = () => {
|
|
770
|
-
if (!this.isDragging) return;
|
|
771
|
-
this.isDragging = !1, document.removeEventListener("pointermove", this.onDragMove), document.removeEventListener("pointerup", this.onDragEnd);
|
|
772
|
-
const t = this.get$modal(), i = this.get$window();
|
|
773
|
-
t.classList.remove("is-dragging"), i.style.animation = "none", requestAnimationFrame(() => {
|
|
774
|
-
this.applyAnimation(!0);
|
|
775
|
-
});
|
|
776
|
-
}, this.options = { ...W.DEFAULT_OPTIONS, ...e }, this.options.backdrop === !1 && e.bodyScroll === void 0 && (this.options.bodyScroll = !0);
|
|
777
|
-
}
|
|
778
|
-
get isDestroyed() {
|
|
779
|
-
return this._isDestroyed;
|
|
780
|
-
}
|
|
781
|
-
static {
|
|
782
|
-
this.DEFAULT_OPTIONS = {
|
|
783
|
-
className: "",
|
|
784
|
-
sizeClass: "auto",
|
|
785
|
-
center: !0,
|
|
786
|
-
fitScreen: !1,
|
|
787
|
-
closeIcon: !0,
|
|
788
|
-
bodyScroll: !1,
|
|
789
|
-
outSideClose: !0,
|
|
790
|
-
backdrop: !0,
|
|
791
|
-
animation: {
|
|
792
|
-
show: "ipe-modal-fade-in",
|
|
793
|
-
hide: "ipe-modal-fade-out"
|
|
794
|
-
},
|
|
795
|
-
animationSpeed: 200
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
static extends(e = {}) {
|
|
799
|
-
return class extends this {
|
|
800
|
-
constructor(t = {}) {
|
|
801
|
-
super({ ...e, ...t });
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
// ------------------------------ lifecycle ------------------------------ //
|
|
806
|
-
init() {
|
|
807
|
-
if (this.$modal) return this;
|
|
808
|
-
const e = this.options.backdrop !== !1;
|
|
809
|
-
let t;
|
|
810
|
-
e && (t = x("div", {
|
|
811
|
-
className: "ipe-modal-backdrop",
|
|
812
|
-
attrs: { id: this.backdropId, "data-modal-id": this.modalId }
|
|
813
|
-
}));
|
|
814
|
-
const i = x("div", {
|
|
815
|
-
className: "ipe-modal-modal",
|
|
816
|
-
attrs: { id: this.modalId, role: "dialog", "aria-modal": "true", tabindex: "-1" }
|
|
817
|
-
});
|
|
818
|
-
if (i.modal = this, !e) {
|
|
819
|
-
i.classList.add("no-backdrop");
|
|
820
|
-
const d = window.pageYOffset || document.documentElement.scrollTop, g = window.pageXOffset || document.documentElement.scrollLeft, w = window.innerWidth;
|
|
821
|
-
i.style.top = `${d + 60}px`, this.once("modal.show", () => {
|
|
822
|
-
i.style.left = `${g + w / 2 - i.offsetWidth / 2}px`;
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
const s = x("div", {
|
|
826
|
-
className: `ipe-modal-modal__window size--${this.options.sizeClass || "auto"} plugin--${this.pluginName}`
|
|
827
|
-
});
|
|
828
|
-
s.modal = this;
|
|
829
|
-
const r = x("div", { className: "ipe-modal-modal__header" }), o = `${this.modalId}-title`, a = x("h2", {
|
|
830
|
-
className: "ipe-modal-modal__title",
|
|
831
|
-
attrs: { id: o, role: "heading", "aria-level": "2" }
|
|
832
|
-
});
|
|
833
|
-
i.setAttribute("aria-labelledby", o);
|
|
834
|
-
const c = x("div", { className: "ipe-modal-modal__icons" });
|
|
835
|
-
if (this.options.closeIcon) {
|
|
836
|
-
const d = x("button", {
|
|
837
|
-
className: "ipe-modal-modal__close",
|
|
838
|
-
attrs: { type: "button", "aria-label": "Close" },
|
|
839
|
-
html: "×"
|
|
840
|
-
});
|
|
841
|
-
d.addEventListener("click", () => {
|
|
842
|
-
let g = !0;
|
|
843
|
-
typeof this.options.onClickClose == "function" ? this.options.onClickClose(this) === !1 && (g = !1) : this.options.onClickClose === !1 && (g = !1), g && this.close();
|
|
844
|
-
}), c.appendChild(d);
|
|
845
|
-
}
|
|
846
|
-
r.append(a, c), this.options.draggable && e && (this.options.draggable = !1), this.options.draggable && (r.style.cursor = "move", r.style.userSelect = "none", r.addEventListener("pointerdown", this.onDragStart.bind(this)), i.classList.add("is-draggable"));
|
|
847
|
-
const l = x("div", { className: "ipe-modal-modal__content" }), h = x("div", { className: "ipe-modal-modal__footer" }), u = x("div", {
|
|
848
|
-
className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--left"
|
|
849
|
-
}), f = x("div", {
|
|
850
|
-
className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--right"
|
|
851
|
-
});
|
|
852
|
-
return h.append(u, f), s.append(r, l, h), i.appendChild(s), this.$backdrop = t, this.$modal = i, this.$window = s, this.$header = r, this.$title = a, this.$icons = c, this.$content = l, this.$footer = h, this.$buttonsLeft = u, this.$buttonsRight = f, 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", (d) => {
|
|
853
|
-
this.options.outSideClose && d.target === t && this.close();
|
|
854
|
-
}), this.options.draggable && s.addEventListener("pointerdown", (d) => {
|
|
855
|
-
d.target && s.contains(d.target) && this.bringToFront();
|
|
856
|
-
}), this.onKeyDown = this.onKeyDown.bind(this), this.emit(
|
|
857
|
-
"modal.init"
|
|
858
|
-
/* Init */
|
|
859
|
-
), this;
|
|
860
|
-
}
|
|
861
|
-
show() {
|
|
862
|
-
if (this.$modal || this.init(), !this.$modal) throw new Error("Failed to initialize modal");
|
|
863
|
-
if (this.isOpen) return this;
|
|
864
|
-
{
|
|
865
|
-
const i = this.emit("modal.beforeShow", !0), s = this.options.beforeShow ? this.options.beforeShow(this) !== !1 : !0;
|
|
866
|
-
if (!i || !s) return this;
|
|
867
|
-
}
|
|
868
|
-
this.lastFocused = document.activeElement ?? null, this.$backdrop && document.body.appendChild(this.$backdrop), document.body.appendChild(this.$modal), this.shouldLockBodyOnOpen() && k.lockBodyScroll(), requestAnimationFrame(() => {
|
|
869
|
-
this.$backdrop?.classList.add("is-open"), this.$modal.classList.add("is-open"), this.applyAnimation(!0), this.focusFirst();
|
|
870
|
-
}), document.addEventListener("keydown", this.onKeyDown), k.push(this), this.isOpen = !0, this.options.onShow?.(this), this.emit(
|
|
871
|
-
"modal.show"
|
|
872
|
-
/* Show */
|
|
873
|
-
);
|
|
874
|
-
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;
|
|
875
|
-
return e && (this.startCloseTimer(e), t && (this.$window?.addEventListener("mouseenter", this.stopCloseTimer), this.$window?.addEventListener("mouseleave", () => this.startCloseTimer(e)))), this;
|
|
876
|
-
}
|
|
877
|
-
close() {
|
|
878
|
-
if (!this.isOpen) return this;
|
|
879
|
-
{
|
|
880
|
-
const r = this.emit("modal.beforeClose", !0), o = this.options.beforeClose ? this.options.beforeClose(this) !== !1 : !0;
|
|
881
|
-
if (!r || !o) return this;
|
|
882
|
-
}
|
|
883
|
-
if (this.isToast) {
|
|
884
|
-
this.applyAnimation(!1), this.emit(
|
|
885
|
-
"modal.close"
|
|
886
|
-
/* Close */
|
|
887
|
-
), this.emit(
|
|
888
|
-
"toast.close"
|
|
889
|
-
/* ToastClose */
|
|
890
|
-
);
|
|
891
|
-
const r = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
|
|
892
|
-
let o = !1;
|
|
893
|
-
const a = () => {
|
|
894
|
-
o || (o = !0, this.destroy(), this.options.onClose?.(this));
|
|
895
|
-
}, c = (l, h) => {
|
|
896
|
-
const u = () => {
|
|
897
|
-
l.removeEventListener(h, u), a();
|
|
898
|
-
};
|
|
899
|
-
l.addEventListener(h, u, { once: !0 });
|
|
900
|
-
};
|
|
901
|
-
return r > 0 && this.$window ? (c(this.$window, "transitionend"), c(this.$window, "animationend"), window.setTimeout(a, r + 20)) : window.setTimeout(a, r), this;
|
|
902
|
-
}
|
|
903
|
-
this.applyAnimation(!1), this.$backdrop?.classList.remove("is-open"), this.$modal?.classList.remove("is-open"), this.emit(
|
|
904
|
-
"modal.close"
|
|
905
|
-
/* Close */
|
|
906
|
-
);
|
|
907
|
-
const e = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
|
|
908
|
-
let t = !1;
|
|
909
|
-
const i = () => {
|
|
910
|
-
t || (t = !0, this.destroy(), this.options.onClose?.(this));
|
|
911
|
-
}, s = (r, o) => {
|
|
912
|
-
const a = () => {
|
|
913
|
-
r.removeEventListener(o, a), i();
|
|
914
|
-
};
|
|
915
|
-
r.addEventListener(o, a, { once: !0 });
|
|
916
|
-
};
|
|
917
|
-
return e > 0 && this.$window ? (s(this.$window, "transitionend"), s(this.$window, "animationend"), window.setTimeout(i, e + 20)) : window.setTimeout(i, e), this;
|
|
918
|
-
}
|
|
919
|
-
/** Immediately removes DOM and listeners */
|
|
920
|
-
destroy() {
|
|
921
|
-
if (this._isDestroyed) return this;
|
|
922
|
-
if (this.stopCloseTimer(), document.removeEventListener("keydown", this.onKeyDown), this.isDragging && this.onDragEnd(), this.$window?.removeEventListener("mouseenter", this.stopCloseTimer), this.isToast) {
|
|
923
|
-
this.$window?.parentElement && this.$window.parentElement.removeChild(this.$window);
|
|
924
|
-
const e = R.indexOf(this);
|
|
925
|
-
e !== -1 && R.splice(e, 1);
|
|
926
|
-
} else
|
|
927
|
-
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();
|
|
928
|
-
return this.isOpen = !1, this.lastFocused?.focus?.(), this.emit(
|
|
929
|
-
"modal.destroy"
|
|
930
|
-
/* Destroy */
|
|
931
|
-
), this._isDestroyed = !0, this;
|
|
932
|
-
}
|
|
933
|
-
// ------------------------------ getters ------------------------------- //
|
|
934
|
-
get$backdrop() {
|
|
935
|
-
return this.$backdrop;
|
|
936
|
-
}
|
|
937
|
-
get$modal() {
|
|
938
|
-
return I(this.$modal, "modal");
|
|
939
|
-
}
|
|
940
|
-
get$window() {
|
|
941
|
-
return I(this.$window, "window");
|
|
942
|
-
}
|
|
943
|
-
get$header() {
|
|
944
|
-
return I(this.$header, "header");
|
|
945
|
-
}
|
|
946
|
-
get$title() {
|
|
947
|
-
return I(this.$title, "title");
|
|
948
|
-
}
|
|
949
|
-
get$content() {
|
|
950
|
-
return I(this.$content, "content");
|
|
951
|
-
}
|
|
952
|
-
get$icons() {
|
|
953
|
-
return I(this.$icons, "icons");
|
|
954
|
-
}
|
|
955
|
-
get$buttons(e) {
|
|
956
|
-
return e === "leftButtons" ? I(this.$buttonsLeft, "leftButtons") : e === "rightButtons" ? I(this.$buttonsRight, "rightButtons") : I(this.$footer, "buttons");
|
|
957
|
-
}
|
|
958
|
-
// ------------------------------ content ------------------------------- //
|
|
959
|
-
setTitle(e) {
|
|
960
|
-
const t = this.get$title();
|
|
961
|
-
return t.innerHTML = "", t.append(B(e)), this;
|
|
962
|
-
}
|
|
963
|
-
setContent(e, t = "replace") {
|
|
964
|
-
const i = this.get$content();
|
|
965
|
-
return t === "replace" ? (i.innerHTML = "", i.append(B(e))) : t === "append" ? i.append(B(e)) : i.prepend(B(e)), this;
|
|
966
|
-
}
|
|
967
|
-
setIcons(e) {
|
|
968
|
-
const t = this.get$icons();
|
|
969
|
-
t.innerHTML = "";
|
|
970
|
-
for (const i of e) {
|
|
971
|
-
const s = x("button", {
|
|
972
|
-
className: `ipe-modal-modal__icon ${i.className}`,
|
|
973
|
-
attrs: { type: "button" }
|
|
974
|
-
});
|
|
975
|
-
s.addEventListener("click", i.method), t.appendChild(s);
|
|
976
|
-
}
|
|
977
|
-
return this;
|
|
978
|
-
}
|
|
979
|
-
setButtons(e, t) {
|
|
980
|
-
const i = this.$buttonsLeft, s = this.$buttonsRight;
|
|
981
|
-
[i, s].forEach((o) => o.innerHTML = ""), this.buttonElsLeft = [], this.buttonElsRight = [], this.keyMap.clear();
|
|
982
|
-
const r = t ?? this.$footer;
|
|
983
|
-
if (r === this.$footer)
|
|
984
|
-
e.forEach((o) => this.addButton(o)), e.length === 0 && (this.$footer.style.display = "none");
|
|
985
|
-
else {
|
|
986
|
-
r.innerHTML = "";
|
|
987
|
-
for (const o of e) {
|
|
988
|
-
const a = this.generateButton(o);
|
|
989
|
-
r.appendChild(a);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
return this;
|
|
993
|
-
}
|
|
994
|
-
generateButton(e) {
|
|
995
|
-
const t = e.type ?? "button", i = t === "link" ? x("a") : x("button", { attrs: { type: "button" } });
|
|
996
|
-
e.id && (i.id = e.id), i.className = `ipe-modal-btn ${e.className ?? ""}`.trim();
|
|
997
|
-
const s = B(e.label ?? "OK");
|
|
998
|
-
if (i.append(s), t === "link" && e.href && (i.href = e.href), e.method && i.addEventListener("click", (r) => {
|
|
999
|
-
if (i._ipe_tmpDisabled) {
|
|
1000
|
-
r.preventDefault(), r.stopPropagation();
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
1003
|
-
e.method.call(i, r, this);
|
|
1004
|
-
}), typeof e.closeAfter == "number" && e.closeAfter >= 0 && i.addEventListener("click", () => {
|
|
1005
|
-
window.setTimeout(() => this.close(), e.closeAfter);
|
|
1006
|
-
}), typeof e.enableAfter == "number" && e.enableAfter > 0) {
|
|
1007
|
-
t === "button" && i.setAttribute("disabled", "true"), i._ipe_tmpDisabled = !0, i.setAttribute("aria-disabled", "true");
|
|
1008
|
-
const r = () => {
|
|
1009
|
-
t === "button" && i.removeAttribute("disabled"), delete i._ipe_tmpDisabled, i.removeAttribute("aria-disabled");
|
|
1010
|
-
};
|
|
1011
|
-
window.setTimeout(r, e.enableAfter);
|
|
1012
|
-
}
|
|
1013
|
-
if (e.keyPress) {
|
|
1014
|
-
const r = String(e.keyPress).split(/[\,\|]+/g).map((o) => o.trim()).filter(Boolean);
|
|
1015
|
-
for (const o of r) {
|
|
1016
|
-
const a = li(o);
|
|
1017
|
-
a && this.keyMap.set(a, i);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
return i;
|
|
1021
|
-
}
|
|
1022
|
-
/** Dynamically add button(s) into footer. Supports insertion index per side. */
|
|
1023
|
-
addButton(e, t) {
|
|
1024
|
-
this.$footer && (this.$footer.style.display = "");
|
|
1025
|
-
const i = e.side ?? "right", s = i === "left" ? this.$buttonsLeft : this.$buttonsRight, r = i === "left" ? this.buttonElsLeft : this.buttonElsRight, o = this.generateButton(e), a = Math.max(0, Math.min(t ?? r.length, r.length));
|
|
1026
|
-
return a >= s.children.length ? s.appendChild(o) : s.insertBefore(o, s.children[a]), r.splice(a, 0, o), this;
|
|
1027
|
-
}
|
|
1028
|
-
/** Remove button by element / id / global index (left first, then right). */
|
|
1029
|
-
removeButton(e) {
|
|
1030
|
-
const t = this.buttonElsLeft, i = this.buttonElsRight, s = [...t, ...i];
|
|
1031
|
-
let r = null;
|
|
1032
|
-
if (e === "*")
|
|
1033
|
-
return s.forEach((a) => {
|
|
1034
|
-
this.keyMap.delete(a.id), a.parentElement?.removeChild(a);
|
|
1035
|
-
}), this.$footer && (this.$footer.style.display = "none"), this;
|
|
1036
|
-
if (typeof e == "number" ? r = s[e] ?? null : typeof e == "string" ? r = s.find((a) => a.id === e) ?? null : e instanceof HTMLElement && (r = s.find((a) => a === e) ?? null), !r) return this;
|
|
1037
|
-
for (const [a, c] of this.keyMap.entries()) c === r && this.keyMap.delete(a);
|
|
1038
|
-
let o = t.indexOf(r);
|
|
1039
|
-
return o !== -1 ? (t.splice(o, 1), r.parentElement?.removeChild(r)) : (o = i.indexOf(r), o !== -1 && (i.splice(o, 1), r.parentElement?.removeChild(r))), t.length === 0 && i.length === 0 && this.$footer && (this.$footer.style.display = "none"), this;
|
|
1040
|
-
}
|
|
1041
|
-
changePreviewState() {
|
|
1042
|
-
return this.get$modal().classList.toggle("is-fullscreen"), this;
|
|
1043
|
-
}
|
|
1044
|
-
setModalHeight(e, t = "height") {
|
|
1045
|
-
const i = this.get$window(), s = Math.max(0, window.innerHeight - e);
|
|
1046
|
-
return i.style[t] = `${s}px`, s;
|
|
1047
|
-
}
|
|
1048
|
-
setOptions(e, t) {
|
|
1049
|
-
return typeof e == "string" ? this.options[e] = t : Object.assign(this.options, e), this;
|
|
1050
|
-
}
|
|
1051
|
-
setPluginName(e) {
|
|
1052
|
-
return this.$window && (this.$window.className = this.$window.className.replace(
|
|
1053
|
-
`plugin--${this.pluginName}`,
|
|
1054
|
-
`plugin--${e}`
|
|
1055
|
-
)), this.pluginName = e, this;
|
|
1056
|
-
}
|
|
1057
|
-
// ------------------------------ helpers ------------------------------- //
|
|
1058
|
-
applyAnimation(e) {
|
|
1059
|
-
const t = this.get$modal(), i = this.get$window(), s = this.$backdrop, r = this.options.modalAnimation ?? this.options.animation, o = typeof r == "string" ? r : r && (e ? r.show : r.hide), a = this.options.backdropAnimation ?? this.options.animation, c = typeof a == "string" ? a : a && (e ? a.show : a.hide);
|
|
1060
|
-
!o || o === !1 ? (t.style.transition = "none", i.style.animation = "none", i.style.removeProperty("--ipe-modal-anim")) : (t.style.removeProperty("transition"), i.style.setProperty("--ipe-modal-anim", o)), s && (!c || c === !1 ? s.style.transition = "none" : s.style.removeProperty("transition"));
|
|
1061
|
-
}
|
|
1062
|
-
on(e, t) {
|
|
1063
|
-
return this._hooks.push({ type: e, listener: t }), () => this.off(e, t);
|
|
1064
|
-
}
|
|
1065
|
-
off(e, t) {
|
|
1066
|
-
return this._hooks = this._hooks.filter(
|
|
1067
|
-
(i) => i.type !== e && (t ? i.listener !== t : !0)
|
|
1068
|
-
), this;
|
|
1069
|
-
}
|
|
1070
|
-
once(e, t) {
|
|
1071
|
-
const i = this.on(e, (s) => (i(), t(s)));
|
|
1072
|
-
return i;
|
|
1073
|
-
}
|
|
1074
|
-
emit(e, t) {
|
|
1075
|
-
const i = this._hooks.filter((a) => a.type === e);
|
|
1076
|
-
let s = !0;
|
|
1077
|
-
for (const a of i) {
|
|
1078
|
-
const c = new CustomEvent(e, { detail: this, cancelable: t }), l = a.listener(c);
|
|
1079
|
-
if (c.defaultPrevented && (s = !1), l === !1 && (s = !1), !s) break;
|
|
1080
|
-
}
|
|
1081
|
-
const r = this.$modal ?? document.body, o = new CustomEvent(e, { detail: this, cancelable: t });
|
|
1082
|
-
return (!r.dispatchEvent(o) || o.defaultPrevented) && (s = !1), s;
|
|
1083
|
-
}
|
|
1084
|
-
focusFirst() {
|
|
1085
|
-
const e = this.get$modal(), t = Ie(e);
|
|
1086
|
-
t.length ? t[0].focus() : e.focus({ preventScroll: !0 });
|
|
1087
|
-
}
|
|
1088
|
-
onKeyDown(e) {
|
|
1089
|
-
if (k.top() !== this) return;
|
|
1090
|
-
if (e.key === "Escape") {
|
|
1091
|
-
e.preventDefault(), this.close();
|
|
1092
|
-
return;
|
|
1093
|
-
}
|
|
1094
|
-
const t = this.get$modal();
|
|
1095
|
-
if (!t.contains(document.activeElement)) return;
|
|
1096
|
-
if (e.key === "Tab") {
|
|
1097
|
-
const a = Ie(t);
|
|
1098
|
-
if (!a.length) return;
|
|
1099
|
-
const c = a[0], l = a[a.length - 1], h = document.activeElement;
|
|
1100
|
-
e.shiftKey && h === c ? (e.preventDefault(), l.focus()) : !e.shiftKey && h === l && (e.preventDefault(), c.focus());
|
|
1101
|
-
}
|
|
1102
|
-
const i = e.ctrlKey || e.altKey || e.metaKey, s = e.target;
|
|
1103
|
-
if (!i && (s && ["INPUT", "TEXTAREA"].includes(s.tagName) || s.contentEditable === "true"))
|
|
1104
|
-
return;
|
|
1105
|
-
const r = ci(e), o = this.keyMap.get(r);
|
|
1106
|
-
if (o) {
|
|
1107
|
-
e.preventDefault(), o.click();
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
setZIndex(e) {
|
|
1112
|
-
this.$backdrop && (this.$backdrop.style.zIndex = String(e)), this.$modal && (this.$modal.style.zIndex = String(e + 1));
|
|
1113
|
-
}
|
|
1114
|
-
/** Bring this modal to the top of the stack. */
|
|
1115
|
-
bringToFront() {
|
|
1116
|
-
return k.remove(this), k.push(this), this;
|
|
1117
|
-
}
|
|
1118
|
-
isAnimationDisabled() {
|
|
1119
|
-
const e = this.options.modalAnimation ?? this.options.animation;
|
|
1120
|
-
return e === !1 || e == null;
|
|
1121
|
-
}
|
|
1122
|
-
shouldLockBodyOnOpen() {
|
|
1123
|
-
return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !k.stack.some(
|
|
1124
|
-
(e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
|
|
1125
|
-
);
|
|
1126
|
-
}
|
|
1127
|
-
shouldUnlockBodyOnClose() {
|
|
1128
|
-
return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !k.stack.some(
|
|
1129
|
-
(e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
|
|
1130
|
-
);
|
|
1131
|
-
}
|
|
1132
|
-
// ------------------------------ drag handlers ------------------------------- //
|
|
1133
|
-
onDragStart(e) {
|
|
1134
|
-
if (this.options.backdrop !== !1 || !this.options.draggable) return;
|
|
1135
|
-
e.preventDefault(), this.isDragging = !0, this.bringToFront(), this.dragStartX = e.clientX, this.dragStartY = e.clientY;
|
|
1136
|
-
const t = this.get$modal(), i = t.getBoundingClientRect();
|
|
1137
|
-
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");
|
|
1138
|
-
}
|
|
1139
|
-
// ------------------------------ toast ------------------------------- //
|
|
1140
|
-
/** Show as toast (no backdrop, container stack). */
|
|
1141
|
-
showToast(e) {
|
|
1142
|
-
this.$window || this.init();
|
|
1143
|
-
const t = ui(e.position ?? "top right"), i = this.get$window();
|
|
1144
|
-
this.isToast = !0, i.style.pointerEvents = "auto", this.applyAnimation(!0), t.appendChild(i);
|
|
1145
|
-
const s = (typeof this.options.closeAfter == "number" ? this.options.closeAfter : this.options.closeAfter?.time) ?? 3e3, r = (typeof this.options.closeAfter == "number" ? !0 : this.options.closeAfter?.resetOnHover) ?? !0;
|
|
1146
|
-
return s > 0 && (this.startCloseTimer(s), r && (i.addEventListener("mouseenter", this.stopCloseTimer), i.addEventListener("mouseleave", () => this.startCloseTimer(s)))), this.isOpen = !0, this.options.onShow?.(this), R.push(this), this.emit(
|
|
1147
|
-
"toast.show"
|
|
1148
|
-
/* ToastShow */
|
|
1149
|
-
), this.emit(
|
|
1150
|
-
"modal.show"
|
|
1151
|
-
/* Show */
|
|
1152
|
-
), this;
|
|
1153
|
-
}
|
|
1154
|
-
// ------------------------------ static helpers --------------------------- //
|
|
1155
|
-
static show(e, t) {
|
|
1156
|
-
return new this(e).init().show();
|
|
1157
|
-
}
|
|
1158
|
-
static createObject(e, t) {
|
|
1159
|
-
return new this(e);
|
|
1160
|
-
}
|
|
1161
|
-
static close(e) {
|
|
1162
|
-
if (!e) {
|
|
1163
|
-
const r = k.top();
|
|
1164
|
-
return r?.close(), r;
|
|
1165
|
-
}
|
|
1166
|
-
const t = typeof e == "string" ? e : e.id, i = k.stack.find((r) => r.modalId === t);
|
|
1167
|
-
if (i)
|
|
1168
|
-
return i.close(), i;
|
|
1169
|
-
const s = R.find((r) => r.modalId === t);
|
|
1170
|
-
return s?.close(), s;
|
|
1171
|
-
}
|
|
1172
|
-
static closeAll(e, t) {
|
|
1173
|
-
const i = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), s = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
|
|
1174
|
-
return k.closeAll(e, t), [...R].forEach((r) => {
|
|
1175
|
-
const o = r.modalId, a = s.size ? s.has(r.pluginName) : !0, c = i.has(o);
|
|
1176
|
-
a && !c && r.close();
|
|
1177
|
-
}), k.top() ?? new W();
|
|
1178
|
-
}
|
|
1179
|
-
static removeAll() {
|
|
1180
|
-
k.removeAll(), [...R].forEach((e) => e.destroy());
|
|
1181
|
-
}
|
|
1182
|
-
static dialog(e, t) {
|
|
1183
|
-
const i = new this({
|
|
1184
|
-
sizeClass: "dialog",
|
|
1185
|
-
buttons: [
|
|
1186
|
-
{
|
|
1187
|
-
label: "OK",
|
|
1188
|
-
className: "is-primary is-ghost",
|
|
1189
|
-
method: (s, r) => {
|
|
1190
|
-
t?.(s, r), s.defaultPrevented || i.close();
|
|
1191
|
-
},
|
|
1192
|
-
keyPress: "Enter"
|
|
1193
|
-
}
|
|
1194
|
-
],
|
|
1195
|
-
...e
|
|
1196
|
-
});
|
|
1197
|
-
return i.init().show();
|
|
1198
|
-
}
|
|
1199
|
-
static confirm(e, t) {
|
|
1200
|
-
e.title ??= "Confirm", e.content ??= "Are you sure you want to perform this action?";
|
|
1201
|
-
const i = e.okBtn ?? { label: "OK", className: "is-primary is-ghost" }, s = e.cancelBtn ?? { label: "Cancel", className: "is-danger is-ghost" };
|
|
1202
|
-
return new this({
|
|
1203
|
-
sizeClass: "dialog",
|
|
1204
|
-
...e,
|
|
1205
|
-
buttons: [
|
|
1206
|
-
{
|
|
1207
|
-
label: s.label,
|
|
1208
|
-
className: s.className,
|
|
1209
|
-
keyPress: "n",
|
|
1210
|
-
method: (r, o) => {
|
|
1211
|
-
t?.(!1, o, r), o.close();
|
|
1212
|
-
}
|
|
1213
|
-
},
|
|
1214
|
-
{
|
|
1215
|
-
label: i.label,
|
|
1216
|
-
className: i.className,
|
|
1217
|
-
keyPress: "y",
|
|
1218
|
-
method: (r, o) => {
|
|
1219
|
-
t?.(!0, o, r), r.defaultPrevented || o.close();
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
]
|
|
1223
|
-
}).init().show();
|
|
1224
|
-
}
|
|
1225
|
-
static getDefaultNotifyIcon(e) {
|
|
1226
|
-
switch (e) {
|
|
1227
|
-
case "success":
|
|
1228
|
-
return /* @__PURE__ */ m(
|
|
1229
|
-
"svg",
|
|
1230
|
-
{
|
|
1231
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1232
|
-
width: "24",
|
|
1233
|
-
height: "24",
|
|
1234
|
-
viewBox: "0 0 24 24",
|
|
1235
|
-
fill: "currentColor",
|
|
1236
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-circle-check",
|
|
1237
|
-
children: [
|
|
1238
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1239
|
-
/* @__PURE__ */ m("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" })
|
|
1240
|
-
]
|
|
1241
|
-
}
|
|
1242
|
-
);
|
|
1243
|
-
case "error":
|
|
1244
|
-
return /* @__PURE__ */ m(
|
|
1245
|
-
"svg",
|
|
1246
|
-
{
|
|
1247
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1248
|
-
width: "24",
|
|
1249
|
-
height: "24",
|
|
1250
|
-
viewBox: "0 0 24 24",
|
|
1251
|
-
fill: "currentColor",
|
|
1252
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-triangle",
|
|
1253
|
-
children: [
|
|
1254
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1255
|
-
/* @__PURE__ */ m("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" })
|
|
1256
|
-
]
|
|
1257
|
-
}
|
|
1258
|
-
);
|
|
1259
|
-
case "warning":
|
|
1260
|
-
return /* @__PURE__ */ m(
|
|
1261
|
-
"svg",
|
|
1262
|
-
{
|
|
1263
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1264
|
-
width: "24",
|
|
1265
|
-
height: "24",
|
|
1266
|
-
viewBox: "0 0 24 24",
|
|
1267
|
-
fill: "currentColor",
|
|
1268
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-circle",
|
|
1269
|
-
children: [
|
|
1270
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1271
|
-
/* @__PURE__ */ m("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" })
|
|
1272
|
-
]
|
|
1273
|
-
}
|
|
1274
|
-
);
|
|
1275
|
-
case "info":
|
|
1276
|
-
return /* @__PURE__ */ m(
|
|
1277
|
-
"svg",
|
|
1278
|
-
{
|
|
1279
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1280
|
-
width: "24",
|
|
1281
|
-
height: "24",
|
|
1282
|
-
viewBox: "0 0 24 24",
|
|
1283
|
-
fill: "currentColor",
|
|
1284
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-info-circle",
|
|
1285
|
-
children: [
|
|
1286
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1287
|
-
/* @__PURE__ */ m("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" })
|
|
1288
|
-
]
|
|
1289
|
-
}
|
|
1290
|
-
);
|
|
1291
|
-
case "dialog":
|
|
1292
|
-
return /* @__PURE__ */ m(
|
|
1293
|
-
"svg",
|
|
1294
|
-
{
|
|
1295
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1296
|
-
width: "24",
|
|
1297
|
-
height: "24",
|
|
1298
|
-
viewBox: "0 0 24 24",
|
|
1299
|
-
fill: "none",
|
|
1300
|
-
stroke: "currentColor",
|
|
1301
|
-
"stroke-width": "2",
|
|
1302
|
-
"stroke-linecap": "round",
|
|
1303
|
-
"stroke-linejoin": "round",
|
|
1304
|
-
class: "icon icon-tabler icons-tabler-outline icon-tabler-message-dots",
|
|
1305
|
-
children: [
|
|
1306
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1307
|
-
/* @__PURE__ */ m("path", { d: "M12 11v.01" }),
|
|
1308
|
-
/* @__PURE__ */ m("path", { d: "M8 11v.01" }),
|
|
1309
|
-
/* @__PURE__ */ m("path", { d: "M16 11v.01" }),
|
|
1310
|
-
/* @__PURE__ */ m("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" })
|
|
1311
|
-
]
|
|
1312
|
-
}
|
|
1313
|
-
);
|
|
1314
|
-
case "confirm":
|
|
1315
|
-
return /* @__PURE__ */ m(
|
|
1316
|
-
"svg",
|
|
1317
|
-
{
|
|
1318
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1319
|
-
width: "24",
|
|
1320
|
-
height: "24",
|
|
1321
|
-
viewBox: "0 0 24 24",
|
|
1322
|
-
fill: "currentColor",
|
|
1323
|
-
class: "icon icon-tabler icons-tabler-filled icon-tabler-copy-check",
|
|
1324
|
-
children: [
|
|
1325
|
-
/* @__PURE__ */ m("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
|
|
1326
|
-
/* @__PURE__ */ m("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" })
|
|
1327
|
-
]
|
|
1328
|
-
}
|
|
1329
|
-
);
|
|
1330
|
-
default:
|
|
1331
|
-
return null;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
static notify(e, t, i) {
|
|
1335
|
-
if (t?.overrideOther && [...R].forEach((a) => a.close()), typeof t.title > "u") {
|
|
1336
|
-
const a = e || "Notification";
|
|
1337
|
-
t.title = a[0].toUpperCase() + a.slice(1).toLowerCase();
|
|
1338
|
-
}
|
|
1339
|
-
const s = t.icon ?? this.getDefaultNotifyIcon(e);
|
|
1340
|
-
s && (s instanceof Element && s.classList.add("ipe-modal-notify-icon"), t.title = /* @__PURE__ */ m(ti, { children: [
|
|
1341
|
-
s,
|
|
1342
|
-
t.title
|
|
1343
|
-
] })), 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) => {
|
|
1344
|
-
i?.(!0, c, a), c.close();
|
|
1345
|
-
}), 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) => {
|
|
1346
|
-
i?.(!1, c, a), c.close();
|
|
1347
|
-
}), t.buttons = [t.cancelBtn, t.okBtn, ...t.buttons ?? []].filter(
|
|
1348
|
-
Boolean
|
|
1349
|
-
);
|
|
1350
|
-
const r = `is-notify type-${e || "default"} ${t.className ?? ""}`, o = new this({
|
|
1351
|
-
...t,
|
|
1352
|
-
className: r,
|
|
1353
|
-
sizeClass: "auto",
|
|
1354
|
-
center: !1,
|
|
1355
|
-
fitScreen: !1,
|
|
1356
|
-
closeIcon: !0,
|
|
1357
|
-
outSideClose: !1,
|
|
1358
|
-
bodyScroll: !0,
|
|
1359
|
-
buttons: t.buttons ?? []
|
|
1360
|
-
});
|
|
1361
|
-
return o.setPluginName("toast"), o.showToast({
|
|
1362
|
-
position: t.position ?? "top right"
|
|
1363
|
-
});
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
const R = [];
|
|
1367
|
-
function ui(n = "top right") {
|
|
1368
|
-
const e = "ipe-modal-toast-container", t = `${e}-${n.replace(/[\s-\.|\/]+/g, "-")}`;
|
|
1369
|
-
let i = document.getElementById(t);
|
|
1370
|
-
return i || (i = x("div", {
|
|
1371
|
-
className: `${e} ${n}`,
|
|
1372
|
-
attrs: { id: t, "data-position": n }
|
|
1373
|
-
}), document.body.appendChild(i)), i;
|
|
1374
|
-
}
|
|
1375
|
-
class b extends W {
|
|
1376
|
-
constructor(e = {}) {
|
|
1377
|
-
e.className ||= "", e.className += " theme-ipe", e.modalAnimation ||= {
|
|
1378
|
-
show: "ipe-modal-fade-in",
|
|
1379
|
-
hide: "ipe-modal-fade-out"
|
|
1380
|
-
}, super(e);
|
|
1381
|
-
}
|
|
1382
|
-
setLoadingState(e) {
|
|
1383
|
-
if (this.get$window().classList.toggle("loading", e), e) {
|
|
1384
|
-
const t = this.get$window().querySelectorAll(
|
|
1385
|
-
"input:not([disabled]),button:not([disabled])"
|
|
1386
|
-
);
|
|
1387
|
-
this._tmpDisabledActiveInputs = t, t.forEach((i) => {
|
|
1388
|
-
i.disabled = !0;
|
|
1389
|
-
}), this.get$content().append(
|
|
1390
|
-
/* @__PURE__ */ E(
|
|
1391
|
-
"div",
|
|
1392
|
-
{
|
|
1393
|
-
id: "ipe-modalLoadingWrapper",
|
|
1394
|
-
style: {
|
|
1395
|
-
position: "absolute",
|
|
1396
|
-
top: 0,
|
|
1397
|
-
left: 0,
|
|
1398
|
-
right: 0,
|
|
1399
|
-
bottom: 0,
|
|
1400
|
-
display: "flex",
|
|
1401
|
-
justifyContent: "center",
|
|
1402
|
-
alignItems: "center",
|
|
1403
|
-
backgroundColor: "rgba(255, 255, 255, 0.5)",
|
|
1404
|
-
zIndex: 2e3
|
|
1405
|
-
},
|
|
1406
|
-
children: /* @__PURE__ */ E(xt, { style: { width: "80%", maxWidth: "800px" } })
|
|
1407
|
-
}
|
|
1408
|
-
)
|
|
1409
|
-
);
|
|
1410
|
-
} else {
|
|
1411
|
-
this.get$window().querySelector("#ipe-modalLoadingWrapper")?.remove();
|
|
1412
|
-
const t = this._tmpDisabledActiveInputs;
|
|
1413
|
-
t && t.forEach((i) => {
|
|
1414
|
-
i.disabled = !1;
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
class di {
|
|
1420
|
-
constructor(e) {
|
|
1421
|
-
this.ctx = e, this.IPEModal = b, this.IPEModalEvent = ue, 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", () => {
|
|
1422
|
-
b.closeAll();
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
const He = (n) => {
|
|
1427
|
-
if (!n)
|
|
1428
|
-
return new URLSearchParams();
|
|
1429
|
-
if (n instanceof URLSearchParams)
|
|
1430
|
-
return n;
|
|
1431
|
-
if (typeof n != "object" || n?.constructor !== Object)
|
|
1432
|
-
throw new TypeError("only plain object is supported");
|
|
1433
|
-
const e = new URLSearchParams();
|
|
1434
|
-
for (const [t, i] of Object.entries(n))
|
|
1435
|
-
if (i != null) {
|
|
1436
|
-
if (Array.isArray(i)) {
|
|
1437
|
-
for (const s of i)
|
|
1438
|
-
e.append(t, s?.toString());
|
|
1439
|
-
continue;
|
|
1440
|
-
}
|
|
1441
|
-
if (typeof i == "object" && i !== null && i.constructor === Object) {
|
|
1442
|
-
for (const [s, r] of Object.entries(i))
|
|
1443
|
-
r != null && e.set(`${t}[${s}]`, r?.toString());
|
|
1444
|
-
continue;
|
|
1445
|
-
}
|
|
1446
|
-
e.set(t, i?.toString());
|
|
1447
|
-
}
|
|
1448
|
-
return e;
|
|
1449
|
-
}, We = (n, e, t) => {
|
|
1450
|
-
const i = typeof n == "string" ? new URL(n, window?.location?.origin) : new URL(n), s = new URLSearchParams(i.search), r = He(e);
|
|
1451
|
-
for (const [o, a] of r.entries())
|
|
1452
|
-
s.set(o, a);
|
|
1453
|
-
return i.search = s.toString(), i.hash = "", i;
|
|
1454
|
-
};
|
|
1455
|
-
var fi = Object.create, de = Object.defineProperty, gi = Object.getOwnPropertyDescriptor, qe = (n, e) => (e = Symbol[n]) ? e : Symbol.for("Symbol." + n), Ge = (n) => {
|
|
1456
|
-
throw TypeError(n);
|
|
1457
|
-
}, pi = (n, e, t) => e in n ? de(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, mi = (n, e) => de(n, "name", { value: e, configurable: !0 }), wi = (n) => [, , , fi(n?.[qe("metadata")] ?? null)], yi = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Xe = (n) => n !== void 0 && typeof n != "function" ? Ge("Function expected") : n, bi = (n, e, t, i, s) => ({ kind: yi[n], name: e, metadata: i, addInitializer: (r) => t._ ? Ge("Already initialized") : s.push(Xe(r || null)) }), vi = (n, e) => pi(e, qe("metadata"), n[3]), _i = (n, e, t, i) => {
|
|
1458
|
-
for (var s = 0, r = n[e >> 1], o = r && r.length; s < o; s++) r[s].call(t);
|
|
1459
|
-
return i;
|
|
1460
|
-
}, $i = (n, e, t, i, s, r) => {
|
|
1461
|
-
var o, a, c, l = e & 7, h = !1, u = 0, f = n[u] || (n[u] = []), d = l && (s = s.prototype, l < 5 && (l > 3 || !h) && gi(s, t));
|
|
1462
|
-
mi(s, t);
|
|
1463
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
1464
|
-
c = bi(l, t, a = {}, n[3], f), o = (0, i[g])(s, c), a._ = 1, Xe(o) && (s = o);
|
|
1465
|
-
return vi(n, s), d && de(s, t, d), h ? l ^ 4 ? r : d : s;
|
|
1466
|
-
}, Ye, fe, Ve;
|
|
1467
|
-
Ye = [j(["api", "storage"])];
|
|
1468
|
-
class q extends (Ve = L) {
|
|
1469
|
-
constructor(e) {
|
|
1470
|
-
super(e, "wiki", !1), this.ctx = e, this._data = {}, this.CACHE_VERSION = 4, this.CACHE_TTL = {
|
|
1471
|
-
siteinfo: 1e3 * 60 * 60 * 24 * 3,
|
|
1472
|
-
// 3 days
|
|
1473
|
-
userinfo: 1e3 * 60 * 30
|
|
1474
|
-
// 30 minutes
|
|
1475
|
-
}, this.QUERY_DATA = {
|
|
1476
|
-
siteinfo: {
|
|
1477
|
-
meta: "siteinfo|filerepoinfo",
|
|
1478
|
-
siprop: "general|specialpagealiases|namespacealiases|namespaces|magicwords",
|
|
1479
|
-
friprop: "canUpload|displayname|initialCapital|local|name|rootUrl|scriptDirUrl|thumbUrl|url"
|
|
1480
|
-
},
|
|
1481
|
-
userinfo: { meta: "userinfo", uiprop: "groups|rights|blockinfo|options" }
|
|
1482
|
-
}, this.CACHE_DB = void 0, this.mwConfig = {
|
|
1483
|
-
get: ((t, i) => window?.mw?.config?.get?.(t, i) ?? i),
|
|
1484
|
-
has: ((t) => window?.mw?.config?.exists?.(t) ?? !1),
|
|
1485
|
-
get values() {
|
|
1486
|
-
return window?.mw?.config?.values || {};
|
|
1487
|
-
}
|
|
1488
|
-
}, this.CACHE_DB = e.storage.createDatabase(
|
|
1489
|
-
"wiki-metadata",
|
|
1490
|
-
1 / 0,
|
|
1491
|
-
this.CACHE_VERSION
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
get logger() {
|
|
1495
|
-
return this.ctx.logger("WIKI_METADATA");
|
|
1496
|
-
}
|
|
1497
|
-
get api() {
|
|
1498
|
-
return this.ctx.api;
|
|
1499
|
-
}
|
|
1500
|
-
async start() {
|
|
1501
|
-
await Promise.all(
|
|
1502
|
-
Object.keys(this.QUERY_DATA).map((e) => this.initData(e))
|
|
1503
|
-
), this.ctx.on("clear-cache", this.onClearCache.bind(this)), this.ctx.set("getUrl", this.getUrl.bind(this)), this.ctx.set("getSciprtUrl", this.getSciprtUrl.bind(this)), this.ctx.set("getMainpageUrl", this.getMainpageUrl.bind(this)), this.ctx.inject(["preferences", "$"], (e) => {
|
|
1504
|
-
const t = e.$;
|
|
1505
|
-
e.preferences.registerCustomConfig(
|
|
1506
|
-
"WikiMetadataService",
|
|
1507
|
-
p.object({
|
|
1508
|
-
WikiMetadataService: p.const(
|
|
1509
|
-
/* @__PURE__ */ E("div", { children: [
|
|
1510
|
-
/* @__PURE__ */ E("h3", { children: t`Wiki Informations` }),
|
|
1511
|
-
/* @__PURE__ */ E("ul", { children: [
|
|
1512
|
-
/* @__PURE__ */ E("li", { children: [
|
|
1513
|
-
/* @__PURE__ */ E("strong", { children: [
|
|
1514
|
-
t`Site`,
|
|
1515
|
-
":"
|
|
1516
|
-
] }),
|
|
1517
|
-
" ",
|
|
1518
|
-
this.general.sitename,
|
|
1519
|
-
" (",
|
|
1520
|
-
this.landingPageUrl,
|
|
1521
|
-
")"
|
|
1522
|
-
] }),
|
|
1523
|
-
/* @__PURE__ */ E("li", { children: [
|
|
1524
|
-
/* @__PURE__ */ E("strong", { children: t`User` }),
|
|
1525
|
-
": ",
|
|
1526
|
-
this.userInfo.name,
|
|
1527
|
-
" (ID: ",
|
|
1528
|
-
this.userInfo.id,
|
|
1529
|
-
")"
|
|
1530
|
-
] }),
|
|
1531
|
-
/* @__PURE__ */ E("li", { children: [
|
|
1532
|
-
/* @__PURE__ */ E("strong", { children: t`Groups` }),
|
|
1533
|
-
": ",
|
|
1534
|
-
this.userGroups.join(", ") || "None"
|
|
1535
|
-
] })
|
|
1536
|
-
] }),
|
|
1537
|
-
/* @__PURE__ */ E("div", { children: [
|
|
1538
|
-
/* @__PURE__ */ E("p", { style: { fontStyle: "italic" }, children: t`If the information shown above is incorrect (for example, the user is not you), click the button below.` }),
|
|
1539
|
-
/* @__PURE__ */ E(
|
|
1540
|
-
"button",
|
|
1541
|
-
{
|
|
1542
|
-
className: "btn danger",
|
|
1543
|
-
onClick: async (i) => {
|
|
1544
|
-
i.preventDefault(), await e.serial("clear-cache") || window.location.reload();
|
|
1545
|
-
},
|
|
1546
|
-
children: [
|
|
1547
|
-
"🧹 ",
|
|
1548
|
-
t`Clear caches & Reload`
|
|
1549
|
-
]
|
|
1550
|
-
}
|
|
1551
|
-
)
|
|
1552
|
-
] })
|
|
1553
|
-
] })
|
|
1554
|
-
).role("raw-html")
|
|
1555
|
-
}).description("WikiMetadataService"),
|
|
1556
|
-
"about"
|
|
1557
|
-
);
|
|
1558
|
-
}), this.logger.info("All initialized", this._data);
|
|
1559
|
-
}
|
|
1560
|
-
async initData(e, t = !1) {
|
|
1561
|
-
const i = t ? null : await this.fetchFromCache(e);
|
|
1562
|
-
if (i)
|
|
1563
|
-
return this._data[e] = i, this.logger.debug("Using cached", e, i), i;
|
|
1564
|
-
{
|
|
1565
|
-
const s = await this.fetchFromApi(e);
|
|
1566
|
-
return this.saveToCache(e, s), this._data[e] = s, this.logger.debug("Fetched from API", e, s), s;
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
getCacheKey(e) {
|
|
1570
|
-
return `${e}:${new URL(this.ctx.api.config.baseURL).pathname.replace(/^\//, "")}`;
|
|
1571
|
-
}
|
|
1572
|
-
async fetchFromApi(e) {
|
|
1573
|
-
return this.api.get({
|
|
1574
|
-
action: "query",
|
|
1575
|
-
...this.QUERY_DATA[e]
|
|
1576
|
-
}).then(({ data: t }) => {
|
|
1577
|
-
if (typeof t?.query != "object" || t.query === null)
|
|
1578
|
-
throw new Error("Invalid query data", { cause: t });
|
|
1579
|
-
return e === "siteinfo" ? t.query : t.query?.[e] || t.query;
|
|
1580
|
-
}).catch((t) => (this.logger.error("Failed to fetch", t), Promise.reject(t)));
|
|
1581
|
-
}
|
|
1582
|
-
async fetchFromCache(e) {
|
|
1583
|
-
const t = this.getCacheKey(e);
|
|
1584
|
-
return await this.CACHE_DB.get(t, this.CACHE_TTL[e]);
|
|
1585
|
-
}
|
|
1586
|
-
async saveToCache(e, t) {
|
|
1587
|
-
const i = this.getCacheKey(e);
|
|
1588
|
-
return this.CACHE_DB.set(i, t);
|
|
1589
|
-
}
|
|
1590
|
-
async invalidateCache(e) {
|
|
1591
|
-
const t = this.getCacheKey(e);
|
|
1592
|
-
return this.CACHE_DB.delete(t);
|
|
1593
|
-
}
|
|
1594
|
-
async onClearCache() {
|
|
1595
|
-
await this.CACHE_DB.clear();
|
|
1596
|
-
}
|
|
1597
|
-
// ====== shortcuts ======
|
|
1598
|
-
get _raw() {
|
|
1599
|
-
return this._data;
|
|
1600
|
-
}
|
|
1601
|
-
// siteInfo
|
|
1602
|
-
get siteInfo() {
|
|
1603
|
-
return this._data.siteinfo;
|
|
1604
|
-
}
|
|
1605
|
-
get general() {
|
|
1606
|
-
return this.siteInfo.general;
|
|
1607
|
-
}
|
|
1608
|
-
get specialPageAliases() {
|
|
1609
|
-
return this.siteInfo.specialpagealiases;
|
|
1610
|
-
}
|
|
1611
|
-
get namespaceAliases() {
|
|
1612
|
-
return this.siteInfo.namespacealiases;
|
|
1613
|
-
}
|
|
1614
|
-
get namespaces() {
|
|
1615
|
-
return this.siteInfo.namespaces;
|
|
1616
|
-
}
|
|
1617
|
-
get namespaceMap() {
|
|
1618
|
-
const e = Object.values(this.namespaces).map((t) => ({
|
|
1619
|
-
id: t.id,
|
|
1620
|
-
canonical: t.canonical,
|
|
1621
|
-
aliases: this.namespaceAliases.filter((i) => i.id === t.id).map((i) => i.alias)
|
|
1622
|
-
})).sort((t, i) => t.id - i.id);
|
|
1623
|
-
return Reflect.defineProperty(this, "namespaceMap", {
|
|
1624
|
-
get: () => e
|
|
1625
|
-
}), e;
|
|
1626
|
-
}
|
|
1627
|
-
get magicWords() {
|
|
1628
|
-
return this.siteInfo.magicwords;
|
|
1629
|
-
}
|
|
1630
|
-
// userInfo
|
|
1631
|
-
get userInfo() {
|
|
1632
|
-
return this._data.userinfo;
|
|
1633
|
-
}
|
|
1634
|
-
get userOptions() {
|
|
1635
|
-
return this.userInfo.options;
|
|
1636
|
-
}
|
|
1637
|
-
get isUserBlocked() {
|
|
1638
|
-
return this.userInfo.blockedbyid && this.userInfo.blockexpiry && new Date(this.userInfo.blockexpiry).getTime() > Date.now();
|
|
1639
|
-
}
|
|
1640
|
-
get userGroups() {
|
|
1641
|
-
return this.userInfo.groups;
|
|
1642
|
-
}
|
|
1643
|
-
get userRights() {
|
|
1644
|
-
return this.userInfo.rights;
|
|
1645
|
-
}
|
|
1646
|
-
// fileRepoInfo
|
|
1647
|
-
get fileRepos() {
|
|
1648
|
-
return this.siteInfo.repos || [];
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Base URL, without trailing slash
|
|
1652
|
-
* @example "https://mediawiki.org"
|
|
1653
|
-
*/
|
|
1654
|
-
get baseUrl() {
|
|
1655
|
-
const e = this.general.server;
|
|
1656
|
-
return e.startsWith("//") ? `${window?.location?.protocol || "https:"}//${e.slice(2)}` : e;
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Home page URL of this wiki
|
|
1660
|
-
* @description Generally same as the Mainpage URL,
|
|
1661
|
-
* but after MediaWiki 1.34,
|
|
1662
|
-
* it can be set to the website root directory.
|
|
1663
|
-
* @example "https://mediawiki.org/wiki/Main_Page" (In most cases)
|
|
1664
|
-
* @example "https://mediawiki.org/" ($wgMainPageIsDomainRoot = true)
|
|
1665
|
-
*/
|
|
1666
|
-
get landingPageUrl() {
|
|
1667
|
-
return this.general.base;
|
|
1668
|
-
}
|
|
1669
|
-
get mainPageName() {
|
|
1670
|
-
return this.general.mainpage;
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Exact Mainpage URL of this wiki
|
|
1674
|
-
* @example "https://mediawiki.org/wiki/Main_Page"
|
|
1675
|
-
*/
|
|
1676
|
-
get mainPageUrl() {
|
|
1677
|
-
return this.getUrl(this.mainPageName);
|
|
1678
|
-
}
|
|
1679
|
-
/**
|
|
1680
|
-
* Article path, with the $1 placeholder
|
|
1681
|
-
* @example "/wiki/$1"
|
|
1682
|
-
*/
|
|
1683
|
-
get articlePath() {
|
|
1684
|
-
return this.general.articlepath;
|
|
1685
|
-
}
|
|
1686
|
-
/**
|
|
1687
|
-
* Script path, without trailing slash
|
|
1688
|
-
* @example "/w"
|
|
1689
|
-
*/
|
|
1690
|
-
get scriptPath() {
|
|
1691
|
-
return this.general.scriptpath;
|
|
1692
|
-
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Article base URL, with the $1 placeholder
|
|
1695
|
-
* @example "https://mediawiki.org/wiki/$1"
|
|
1696
|
-
*/
|
|
1697
|
-
get articleBaseUrl() {
|
|
1698
|
-
return `${this.baseUrl}${this.articlePath}`;
|
|
1699
|
-
}
|
|
1700
|
-
/**
|
|
1701
|
-
* Script base URL, without trailing slash
|
|
1702
|
-
* @example "https://mediawiki.org/w"
|
|
1703
|
-
*/
|
|
1704
|
-
get scriptBaseUrl() {
|
|
1705
|
-
return `${this.baseUrl}${this.scriptPath}`;
|
|
1706
|
-
}
|
|
1707
|
-
// utils
|
|
1708
|
-
getSciprtUrl(e = "index") {
|
|
1709
|
-
return `${this.scriptBaseUrl}/${e.replace(/\.php$/, "")}.php`;
|
|
1710
|
-
}
|
|
1711
|
-
/** Get mainpage URL */
|
|
1712
|
-
getMainpageUrl(e) {
|
|
1713
|
-
return We(this.siteInfo.general.base, e).toString();
|
|
1714
|
-
}
|
|
1715
|
-
getUrl(e, t) {
|
|
1716
|
-
const i = He(t);
|
|
1717
|
-
let s;
|
|
1718
|
-
return typeof e == "string" && e !== "" ? s = new URL(`${this.articleBaseUrl.replace("$1", e)}`) : typeof e == "number" ? (i.set("curid", e.toString()), s = new URL(this.getSciprtUrl("index"))) : s = new URL(this.getSciprtUrl("index")), s.search = i.toString(), s.toString();
|
|
1719
|
-
}
|
|
1720
|
-
hasRight(e) {
|
|
1721
|
-
return this.userRights.includes(e);
|
|
1722
|
-
}
|
|
1723
|
-
hasAnyRight(...e) {
|
|
1724
|
-
return e.some((t) => this.hasRight(t));
|
|
1725
|
-
}
|
|
1726
|
-
hasEveryRights(...e) {
|
|
1727
|
-
return e.every((t) => this.hasRight(t));
|
|
1728
|
-
}
|
|
1729
|
-
inGroup(e) {
|
|
1730
|
-
return this.userGroups.includes(e);
|
|
1731
|
-
}
|
|
1732
|
-
inAnyGroup(...e) {
|
|
1733
|
-
return this.userGroups.some((t) => e.includes(t));
|
|
1734
|
-
}
|
|
1735
|
-
getBlockInfo() {
|
|
1736
|
-
return this.isUserBlocked ? {
|
|
1737
|
-
blockid: this.userInfo.blockid,
|
|
1738
|
-
blockedby: this.userInfo.blockedbyid,
|
|
1739
|
-
blockedbyid: this.userInfo.blockedbyid,
|
|
1740
|
-
blockreason: this.userInfo.blockreason,
|
|
1741
|
-
blockedtimestamp: this.userInfo.blockedtimestamp,
|
|
1742
|
-
blockexpiry: this.userInfo.blockexpiry
|
|
1743
|
-
} : null;
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
fe = wi(Ve);
|
|
1747
|
-
q = $i(fe, 0, "WikiMetadataService", Ye, q);
|
|
1748
|
-
_i(fe, 1, q);
|
|
1749
|
-
const Si = (() => {
|
|
1750
|
-
const n = Symbol.for("IPE.GlobalMemoryStorage");
|
|
1751
|
-
return n in globalThis || (globalThis[n] = mt()), globalThis[n];
|
|
1752
|
-
})();
|
|
1753
|
-
class xi {
|
|
1754
|
-
constructor(e, t, i = 1 / 0, s, r = "localStorage") {
|
|
1755
|
-
this.dbName = e, this.storeName = t, this.ttl = i, this.version = s, this.engine = r, 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 = Si;
|
|
1756
|
-
}
|
|
1757
|
-
// Key builder
|
|
1758
|
-
makeKey(e) {
|
|
1759
|
-
return `${this.dbName ? this.dbName + ":" : ""}${this.storeName ? this.storeName + "/" : ""}${e}`;
|
|
1760
|
-
}
|
|
1761
|
-
// Internal load & validation
|
|
1762
|
-
load(e) {
|
|
1763
|
-
const t = this.getRaw(e);
|
|
1764
|
-
if (t === null) return null;
|
|
1765
|
-
let i;
|
|
1766
|
-
try {
|
|
1767
|
-
i = JSON.parse(t);
|
|
1768
|
-
} catch {
|
|
1769
|
-
return this.deleteSync(e), null;
|
|
1770
|
-
}
|
|
1771
|
-
const s = i;
|
|
1772
|
-
return typeof s.time != "number" || !("value" in s) ? (this.deleteSync(e), null) : typeof this.version < "u" && typeof this.version < "u" && s.version !== this.version ? (this.deleteSync(e), null) : s;
|
|
1773
|
-
}
|
|
1774
|
-
getRaw(e) {
|
|
1775
|
-
const t = this.makeKey(e);
|
|
1776
|
-
return this.db.getItem(t);
|
|
1777
|
-
}
|
|
1778
|
-
setRaw(e, t) {
|
|
1779
|
-
const i = this.makeKey(e);
|
|
1780
|
-
try {
|
|
1781
|
-
this.db.setItem(i, t);
|
|
1782
|
-
} catch {
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
deleteSync(e) {
|
|
1786
|
-
const t = this.makeKey(e);
|
|
1787
|
-
this.db.removeItem(t);
|
|
1788
|
-
}
|
|
1789
|
-
isExpired(e, t = this.ttl) {
|
|
1790
|
-
return e ? Date.now() - e.time > t : !1;
|
|
1791
|
-
}
|
|
1792
|
-
async get(e, t = this.ttl, i) {
|
|
1793
|
-
const s = this.load(e), r = this.isExpired(s, t);
|
|
1794
|
-
if (!s || r) {
|
|
1795
|
-
if (typeof i == "function") {
|
|
1796
|
-
const o = await i();
|
|
1797
|
-
return await this.set(e, o), o;
|
|
1798
|
-
}
|
|
1799
|
-
return null;
|
|
1800
|
-
}
|
|
1801
|
-
return s.value;
|
|
1802
|
-
}
|
|
1803
|
-
async set(e, t) {
|
|
1804
|
-
const i = Date.now();
|
|
1805
|
-
if (typeof e == "string") {
|
|
1806
|
-
const o = e, a = t;
|
|
1807
|
-
if (a === null || typeof a > "u") {
|
|
1808
|
-
await this.delete(o);
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
const c = { time: i, value: a, version: this.version };
|
|
1812
|
-
return this.setRaw(o, JSON.stringify(c)), c;
|
|
1813
|
-
}
|
|
1814
|
-
const s = e, r = {};
|
|
1815
|
-
for (const [o, a] of Object.entries(s)) {
|
|
1816
|
-
if (a === null || typeof a > "u") {
|
|
1817
|
-
this.deleteSync(o);
|
|
1818
|
-
continue;
|
|
1819
|
-
}
|
|
1820
|
-
const c = { time: i, value: a, version: this.version };
|
|
1821
|
-
this.setRaw(o, JSON.stringify(c)), r[o] = c;
|
|
1822
|
-
}
|
|
1823
|
-
return r;
|
|
1824
|
-
}
|
|
1825
|
-
async has(e, t = this.ttl) {
|
|
1826
|
-
const i = this.load(e);
|
|
1827
|
-
return i !== null && !this.isExpired(i, t);
|
|
1828
|
-
}
|
|
1829
|
-
async delete(e) {
|
|
1830
|
-
this.deleteSync(e);
|
|
1831
|
-
}
|
|
1832
|
-
async updatedAt(e) {
|
|
1833
|
-
const t = this.load(e);
|
|
1834
|
-
return t ? t.time : 0;
|
|
1835
|
-
}
|
|
1836
|
-
async clear() {
|
|
1837
|
-
const e = this.makeKey(""), t = [];
|
|
1838
|
-
for (let i = 0; i < this.db.length; i++) {
|
|
1839
|
-
const s = this.db.key(i);
|
|
1840
|
-
s && s.startsWith(e) && t.push(s);
|
|
1841
|
-
}
|
|
1842
|
-
for (const i of t) this.db.removeItem(i);
|
|
1843
|
-
return this;
|
|
1844
|
-
}
|
|
1845
|
-
// Async generators
|
|
1846
|
-
async *keys() {
|
|
1847
|
-
const e = this.makeKey("");
|
|
1848
|
-
for (let t = 0; t < this.db.length; t++) {
|
|
1849
|
-
const i = this.db.key(t);
|
|
1850
|
-
i && i.startsWith(e) && (yield i.slice(e.length));
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
async *values() {
|
|
1854
|
-
for await (const e of this.keys()) {
|
|
1855
|
-
const t = this.load(e);
|
|
1856
|
-
if (t) {
|
|
1857
|
-
if (this.isExpired(t)) {
|
|
1858
|
-
this.deleteSync(e);
|
|
1859
|
-
continue;
|
|
1860
|
-
}
|
|
1861
|
-
yield t;
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
async *entries() {
|
|
1866
|
-
for await (const e of this.keys()) {
|
|
1867
|
-
const t = this.load(e);
|
|
1868
|
-
if (t) {
|
|
1869
|
-
if (this.isExpired(t)) {
|
|
1870
|
-
this.deleteSync(e);
|
|
1871
|
-
continue;
|
|
1872
|
-
}
|
|
1873
|
-
yield [e, t];
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
var y;
|
|
1879
|
-
((n) => {
|
|
1880
|
-
n.cache = /* @__PURE__ */ new Map(), n.defaults = Object.freeze({ iterBatch: 100, retry: { attempts: 3, baseDelayMs: 16 } }), n.sleep = (l) => new Promise((h) => setTimeout(h, l));
|
|
1881
|
-
function e(l) {
|
|
1882
|
-
const h = l?.name ?? "";
|
|
1883
|
-
return h === "AbortError" || h === "InvalidStateError" || h === "TransactionInactiveError" || h === "UnknownError";
|
|
1884
|
-
}
|
|
1885
|
-
n.shouldReconnect = e;
|
|
1886
|
-
async function t(l, h, u) {
|
|
1887
|
-
const f = Math.max(1, l.attempts);
|
|
1888
|
-
for (let d = 0; d < f; d++)
|
|
1889
|
-
try {
|
|
1890
|
-
return await h(d);
|
|
1891
|
-
} catch (g) {
|
|
1892
|
-
if (d === f - 1) throw g;
|
|
1893
|
-
await u?.(g, d);
|
|
1894
|
-
const w = l.baseDelayMs * Math.pow(2, d) + Math.floor(Math.random() * 10);
|
|
1895
|
-
await (0, n.sleep)(w);
|
|
1896
|
-
}
|
|
1897
|
-
throw new Error("withRetry exhausted unexpectedly");
|
|
1898
|
-
}
|
|
1899
|
-
n.withRetry = t;
|
|
1900
|
-
function i(l, h, u) {
|
|
1901
|
-
return new Promise((f, d) => {
|
|
1902
|
-
const g = indexedDB.open(l, h);
|
|
1903
|
-
g.onupgradeneeded = () => {
|
|
1904
|
-
try {
|
|
1905
|
-
const w = g.result, S = g.transaction;
|
|
1906
|
-
u?.(w, S);
|
|
1907
|
-
} catch (w) {
|
|
1908
|
-
d(w);
|
|
1909
|
-
}
|
|
1910
|
-
}, g.onerror = () => d(g.error), g.onblocked = () => {
|
|
1911
|
-
}, g.onsuccess = () => {
|
|
1912
|
-
const w = g.result;
|
|
1913
|
-
w.onversionchange = () => {
|
|
1914
|
-
try {
|
|
1915
|
-
w.close();
|
|
1916
|
-
} finally {
|
|
1917
|
-
n.cache.delete(l);
|
|
1918
|
-
}
|
|
1919
|
-
}, f(w);
|
|
1920
|
-
};
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
async function s(l, h, u) {
|
|
1924
|
-
let f = !l.objectStoreNames.contains(h), d = [];
|
|
1925
|
-
if (!f && u?.indexes?.length) {
|
|
1926
|
-
const S = l.transaction(h, "readonly"), P = S.objectStore(h), v = new Set(Array.from(P.indexNames));
|
|
1927
|
-
d = (u.indexes || []).filter((_) => !v.has(_.name)), await new Promise((_, C) => {
|
|
1928
|
-
S.oncomplete = () => _(), S.onabort = () => C(S.error), S.onerror = () => C(S.error);
|
|
1929
|
-
});
|
|
1930
|
-
}
|
|
1931
|
-
if (!f && d.length === 0) return l;
|
|
1932
|
-
const g = l.version + 1;
|
|
1933
|
-
l.close();
|
|
1934
|
-
const w = await i(l.name, g, (S, P) => {
|
|
1935
|
-
let v;
|
|
1936
|
-
S.objectStoreNames.contains(h) ? v = P.objectStore(h) : v = S.createObjectStore(h, {
|
|
1937
|
-
keyPath: u?.keyPath ?? void 0,
|
|
1938
|
-
autoIncrement: !!u?.autoIncrement
|
|
1939
|
-
});
|
|
1940
|
-
for (const _ of d)
|
|
1941
|
-
v.indexNames.contains(_.name) || v.createIndex(_.name, _.keyPath, _.options);
|
|
1942
|
-
});
|
|
1943
|
-
return w.onversionchange = () => {
|
|
1944
|
-
try {
|
|
1945
|
-
w.close();
|
|
1946
|
-
} finally {
|
|
1947
|
-
n.cache.delete(w.name);
|
|
1948
|
-
}
|
|
1949
|
-
}, w;
|
|
1950
|
-
}
|
|
1951
|
-
async function r(l, h, u) {
|
|
1952
|
-
let f = n.cache.get(l);
|
|
1953
|
-
return f ? (f = f.then((d) => s(d, h, u)), n.cache.set(l, f)) : (f = (async () => {
|
|
1954
|
-
const d = await i(l);
|
|
1955
|
-
return s(d, h, u);
|
|
1956
|
-
})(), n.cache.set(l, f)), f;
|
|
1957
|
-
}
|
|
1958
|
-
n.getDB = r;
|
|
1959
|
-
async function o(l) {
|
|
1960
|
-
const h = n.cache.get(l);
|
|
1961
|
-
if (n.cache.delete(l), h)
|
|
1962
|
-
try {
|
|
1963
|
-
(await h).close();
|
|
1964
|
-
} catch {
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
n.closeConnection = o;
|
|
1968
|
-
function a(l) {
|
|
1969
|
-
return new Promise((h, u) => {
|
|
1970
|
-
l.onsuccess = () => h(l.result), l.onerror = () => u(l.error);
|
|
1971
|
-
});
|
|
1972
|
-
}
|
|
1973
|
-
n.asyncRequest = a;
|
|
1974
|
-
function c(l) {
|
|
1975
|
-
return new Promise((h, u) => {
|
|
1976
|
-
l.oncomplete = () => h(), l.onabort = () => u(l.error ?? new DOMException("Aborted", "AbortError")), l.onerror = () => u(l.error ?? new DOMException("TransactionError", "UnknownError"));
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
n.waitTx = c;
|
|
1980
|
-
})(y || (y = {}));
|
|
1981
|
-
class ki {
|
|
1982
|
-
constructor(e, t, i = {}) {
|
|
1983
|
-
this.dbName = e, this.storeName = t, this.options = i;
|
|
1984
|
-
}
|
|
1985
|
-
get _iterBatch() {
|
|
1986
|
-
return this.options.iterBatch ?? y.defaults.iterBatch;
|
|
1987
|
-
}
|
|
1988
|
-
get _retryCfg() {
|
|
1989
|
-
const e = this.options.retry ?? y.defaults.retry;
|
|
1990
|
-
return { attempts: e.attempts ?? 3, baseDelayMs: e.baseDelayMs ?? 16 };
|
|
1991
|
-
}
|
|
1992
|
-
async _withStore(e, t) {
|
|
1993
|
-
const i = this._retryCfg;
|
|
1994
|
-
return y.withRetry(
|
|
1995
|
-
i,
|
|
1996
|
-
async () => {
|
|
1997
|
-
const s = await y.getDB(this.dbName, this.storeName, this.options.ensure);
|
|
1998
|
-
try {
|
|
1999
|
-
const r = s.transaction(this.storeName, e), o = r.objectStore(this.storeName), a = await t(o);
|
|
2000
|
-
return await y.waitTx(r), a;
|
|
2001
|
-
} catch (r) {
|
|
2002
|
-
throw r;
|
|
2003
|
-
}
|
|
2004
|
-
},
|
|
2005
|
-
async (s) => {
|
|
2006
|
-
y.shouldReconnect(s) && await y.closeConnection(this.dbName);
|
|
2007
|
-
}
|
|
2008
|
-
);
|
|
2009
|
-
}
|
|
2010
|
-
async get(e) {
|
|
2011
|
-
return this._withStore("readonly", async (t) => {
|
|
2012
|
-
const i = await y.asyncRequest(t.get(e));
|
|
2013
|
-
return i === void 0 ? void 0 : i;
|
|
2014
|
-
});
|
|
2015
|
-
}
|
|
2016
|
-
async set(e, t) {
|
|
2017
|
-
return await this._withStore("readwrite", async (i) => {
|
|
2018
|
-
const s = this.options.ensure?.keyPath != null ? i.put(t) : i.put(t, e);
|
|
2019
|
-
await y.asyncRequest(s);
|
|
2020
|
-
}), this;
|
|
2021
|
-
}
|
|
2022
|
-
async delete(e) {
|
|
2023
|
-
return this._withStore("readwrite", async (t) => {
|
|
2024
|
-
const i = await y.asyncRequest(t.get(e)) !== void 0;
|
|
2025
|
-
return await y.asyncRequest(t.delete(e)), i;
|
|
2026
|
-
});
|
|
2027
|
-
}
|
|
2028
|
-
async clear() {
|
|
2029
|
-
await this._withStore("readwrite", async (e) => {
|
|
2030
|
-
await y.asyncRequest(e.clear());
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
async has(e) {
|
|
2034
|
-
return await this.get(e) !== void 0;
|
|
2035
|
-
}
|
|
2036
|
-
async count() {
|
|
2037
|
-
return this._withStore("readonly", async (e) => await y.asyncRequest(e.count()) ?? 0);
|
|
2038
|
-
}
|
|
2039
|
-
async *_iterateEntries() {
|
|
2040
|
-
let e = null, t = !1;
|
|
2041
|
-
const i = Math.max(1, this._iterBatch);
|
|
2042
|
-
for (; !t; ) {
|
|
2043
|
-
const s = await this._withStore("readonly", async (r) => {
|
|
2044
|
-
const o = [], a = e === null ? void 0 : IDBKeyRange.lowerBound(e, !0);
|
|
2045
|
-
return await new Promise((c, l) => {
|
|
2046
|
-
const h = r.openCursor(a);
|
|
2047
|
-
h.onerror = () => l(h.error), h.onsuccess = () => {
|
|
2048
|
-
const u = h.result;
|
|
2049
|
-
if (!u) {
|
|
2050
|
-
t = !0, c();
|
|
2051
|
-
return;
|
|
2052
|
-
}
|
|
2053
|
-
o.push([u.key, u.value]), e = u.key, o.length >= i ? c() : u.continue();
|
|
2054
|
-
};
|
|
2055
|
-
}), o;
|
|
2056
|
-
});
|
|
2057
|
-
for (const r of s) yield r;
|
|
2058
|
-
if (s.length === 0) break;
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
entries() {
|
|
2062
|
-
return this._iterateEntries();
|
|
2063
|
-
}
|
|
2064
|
-
async *keys() {
|
|
2065
|
-
for await (const [e] of this.entries()) yield e;
|
|
2066
|
-
}
|
|
2067
|
-
async *values() {
|
|
2068
|
-
for await (const [, e] of this.entries()) yield e;
|
|
2069
|
-
}
|
|
2070
|
-
[Symbol.asyncIterator]() {
|
|
2071
|
-
return this.entries()[Symbol.asyncIterator]();
|
|
2072
|
-
}
|
|
2073
|
-
async forEach(e) {
|
|
2074
|
-
for await (const [t, i] of this.entries())
|
|
2075
|
-
await e(i, t, this);
|
|
2076
|
-
}
|
|
2077
|
-
async getMany(e) {
|
|
2078
|
-
const t = /* @__PURE__ */ new Map();
|
|
2079
|
-
for await (const i of e) t.set(i, void 0);
|
|
2080
|
-
return await this._withStore("readonly", async (i) => {
|
|
2081
|
-
await Promise.all(
|
|
2082
|
-
t.keys().map(async (s) => {
|
|
2083
|
-
const r = await y.asyncRequest(i.get(s));
|
|
2084
|
-
t.set(s, r === void 0 ? void 0 : r);
|
|
2085
|
-
})
|
|
2086
|
-
);
|
|
2087
|
-
}), t;
|
|
2088
|
-
}
|
|
2089
|
-
async setMany(e) {
|
|
2090
|
-
const t = this.options.ensure?.keyPath != null;
|
|
2091
|
-
return await this._withStore("readwrite", async (i) => {
|
|
2092
|
-
for await (const [s, r] of e) {
|
|
2093
|
-
const o = t ? i.put(r) : i.put(r, s);
|
|
2094
|
-
await y.asyncRequest(o);
|
|
2095
|
-
}
|
|
2096
|
-
}), this;
|
|
2097
|
-
}
|
|
2098
|
-
async deleteMany(e) {
|
|
2099
|
-
let t = 0;
|
|
2100
|
-
return await this._withStore("readwrite", async (i) => {
|
|
2101
|
-
for await (const s of e)
|
|
2102
|
-
await y.asyncRequest(i.get(s)) !== void 0 && t++, await y.asyncRequest(i.delete(s));
|
|
2103
|
-
}), t;
|
|
2104
|
-
}
|
|
2105
|
-
async disconnect() {
|
|
2106
|
-
await y.closeConnection(this.dbName);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
class Ei {
|
|
2110
|
-
constructor(e, t, i = 1 / 0, s) {
|
|
2111
|
-
this.dbName = e, this.storeName = t, this.ttl = i, this.version = s, this.db = new ki(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(() => {
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
async _clearExpiredEntries() {
|
|
2115
|
-
if (this.ttl === 1 / 0) return;
|
|
2116
|
-
const e = Date.now(), t = [];
|
|
2117
|
-
for await (const [i, s] of this.db.entries())
|
|
2118
|
-
typeof s.time == "number" && e - s.time > this.ttl && t.push(i);
|
|
2119
|
-
t.length > 0 && await this.db.deleteMany(t);
|
|
2120
|
-
}
|
|
2121
|
-
async get(e, t = this.ttl, i) {
|
|
2122
|
-
const s = await this.loadFromDB(e), r = this.checkIfExpired(s, t);
|
|
2123
|
-
if (!s || r) {
|
|
2124
|
-
if (typeof i == "function") {
|
|
2125
|
-
const o = await i();
|
|
2126
|
-
return await this.set(e, o), o;
|
|
2127
|
-
}
|
|
2128
|
-
return null;
|
|
2129
|
-
}
|
|
2130
|
-
return s.value;
|
|
2131
|
-
}
|
|
2132
|
-
async set(e, t) {
|
|
2133
|
-
const i = Date.now();
|
|
2134
|
-
if (typeof e == "string") {
|
|
2135
|
-
const c = e, l = t;
|
|
2136
|
-
if (l === null || typeof l > "u")
|
|
2137
|
-
return this.delete(c);
|
|
2138
|
-
const h = {
|
|
2139
|
-
time: i,
|
|
2140
|
-
value: l,
|
|
2141
|
-
version: this.version
|
|
2142
|
-
};
|
|
2143
|
-
return await this.db.set(c, h), h;
|
|
2144
|
-
}
|
|
2145
|
-
const s = e, r = [], o = [], a = {};
|
|
2146
|
-
for (const [c, l] of Object.entries(s))
|
|
2147
|
-
if (l === null || typeof l > "u")
|
|
2148
|
-
o.push(c);
|
|
2149
|
-
else {
|
|
2150
|
-
const h = { time: i, value: l, version: this.version };
|
|
2151
|
-
r.push([c, h]), a[c] = h;
|
|
2152
|
-
}
|
|
2153
|
-
return r.length > 0 && await this.db.setMany(r), o.length > 0 && await this.db.deleteMany(o), a;
|
|
2154
|
-
}
|
|
2155
|
-
async has(e, t = this.ttl) {
|
|
2156
|
-
const i = await this.loadFromDB(e), s = this.checkIfExpired(i, t);
|
|
2157
|
-
return i !== null && !s;
|
|
2158
|
-
}
|
|
2159
|
-
async delete(e) {
|
|
2160
|
-
await this.db.delete(e);
|
|
2161
|
-
}
|
|
2162
|
-
async updatedAt(e) {
|
|
2163
|
-
const t = await this.loadFromDB(e);
|
|
2164
|
-
return t ? t.time : 0;
|
|
2165
|
-
}
|
|
2166
|
-
async loadFromDB(e) {
|
|
2167
|
-
const t = await this.db.get(e);
|
|
2168
|
-
if (t === void 0)
|
|
2169
|
-
return null;
|
|
2170
|
-
if (typeof t.time != "number" || typeof t.value > "u") {
|
|
2171
|
-
try {
|
|
2172
|
-
await this.delete(e);
|
|
2173
|
-
} catch {
|
|
2174
|
-
}
|
|
2175
|
-
return null;
|
|
2176
|
-
}
|
|
2177
|
-
if (typeof this.version < "u" && typeof this.version < "u" && t.version !== this.version) {
|
|
2178
|
-
try {
|
|
2179
|
-
await this.delete(e);
|
|
2180
|
-
} catch {
|
|
2181
|
-
}
|
|
2182
|
-
return null;
|
|
2183
|
-
}
|
|
2184
|
-
return t;
|
|
2185
|
-
}
|
|
2186
|
-
checkIfExpired(e, t = this.ttl) {
|
|
2187
|
-
return e ? Date.now() - e.time > t : !1;
|
|
2188
|
-
}
|
|
2189
|
-
/**
|
|
2190
|
-
* [DANGER] Use with caution!
|
|
2191
|
-
* Delete all data from the database.
|
|
2192
|
-
*/
|
|
2193
|
-
async clear() {
|
|
2194
|
-
return await this.db.clear(), this;
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
class Ci extends L {
|
|
2198
|
-
constructor(e, t) {
|
|
2199
|
-
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");
|
|
2200
|
-
}
|
|
2201
|
-
createDatabase(e, t, i, s = "indexedDB") {
|
|
2202
|
-
const r = "indexedDB" in window && window.indexedDB !== null;
|
|
2203
|
-
switch (s === "indexedDB" && !r && (s = "localStorage"), s) {
|
|
2204
|
-
case "indexedDB":
|
|
2205
|
-
return new Ei(this.config.dbName, e, t, i);
|
|
2206
|
-
case "localStorage":
|
|
2207
|
-
case "sessionStorage":
|
|
2208
|
-
case "memory":
|
|
2209
|
-
return new xi(this.config.dbName, e, t, i, s);
|
|
2210
|
-
default:
|
|
2211
|
-
throw new Error(`Unsupported storage engine: ${s}`);
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
class Ii extends L {
|
|
2216
|
-
constructor(e) {
|
|
2217
|
-
super(e, "wikiPage", !0), this.ctx = e, this.WikiPage = wt(this.ctx.api);
|
|
2218
|
-
}
|
|
2219
|
-
static {
|
|
2220
|
-
this.inject = ["api"];
|
|
2221
|
-
}
|
|
2222
|
-
async createInstance(e, t = !1) {
|
|
2223
|
-
return await this.WikiPage.newFromApi(e);
|
|
2224
|
-
}
|
|
2225
|
-
async newFromTitle(e, t = !1, i, s = !1) {
|
|
2226
|
-
return this.createInstance({ titles: e.toString(), converttitles: t, rvsection: i }, s);
|
|
2227
|
-
}
|
|
2228
|
-
async newFromPageId(e, t, i = !1) {
|
|
2229
|
-
return this.createInstance({ pageids: e, rvsection: t }, i);
|
|
2230
|
-
}
|
|
2231
|
-
async newFromRevision(e, t, i = !1) {
|
|
2232
|
-
return await this.createInstance({ revids: e, rvsection: t }, i);
|
|
2233
|
-
}
|
|
2234
|
-
newBlankPage(e = {}) {
|
|
2235
|
-
return this.WikiPage.newBlankPage(e);
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
class ge extends L {
|
|
2239
|
-
constructor(e) {
|
|
2240
|
-
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 = yt(this.ctx.wiki.siteInfo);
|
|
2241
|
-
}
|
|
2242
|
-
static {
|
|
2243
|
-
this.inject = ["wiki", "wikiPage"];
|
|
2244
|
-
}
|
|
2245
|
-
newTitle(e, t) {
|
|
2246
|
-
return typeof e == "string" ? new this.Title(e, t) : e;
|
|
2247
|
-
}
|
|
2248
|
-
newMainPageTitle() {
|
|
2249
|
-
return this.newTitle(this.ctx.wiki.mainPageName);
|
|
2250
|
-
}
|
|
2251
|
-
async newTitleFromUrl(e) {
|
|
2252
|
-
const t = this.parseWikiLink(e);
|
|
2253
|
-
return t?.title ? t.title : t?.pageId ? this.newTitleFromPageId(t.pageId) : null;
|
|
2254
|
-
}
|
|
2255
|
-
async newTitleFromAnyId(e, t = !1) {
|
|
2256
|
-
const { title: i, pageId: s, revId: r } = e ?? {};
|
|
2257
|
-
if (typeof i == "string")
|
|
2258
|
-
return this.newTitle(i);
|
|
2259
|
-
let o, a;
|
|
2260
|
-
if (r ? (o = parseInt(r.toString(), 10), a = "revid") : s && (o = parseInt(s.toString(), 10), a = "pageid"), !o || !a || isNaN(o) || o <= 0)
|
|
2261
|
-
throw new Error("Invalid id or kind", { cause: e });
|
|
2262
|
-
if (!t && this._cachedTitles.has(`${a}:${o}`))
|
|
2263
|
-
return await this._cachedTitles.get(`${a}:${o}`);
|
|
2264
|
-
const { promise: c, resolve: l, reject: h } = Pe();
|
|
2265
|
-
this._cachedTitles.set(`${a}:${o}`, c);
|
|
2266
|
-
try {
|
|
2267
|
-
const { wikiPage: u } = this.ctx;
|
|
2268
|
-
let f = null;
|
|
2269
|
-
if (a === "pageid")
|
|
2270
|
-
f = await u.newFromPageId(o);
|
|
2271
|
-
else if (a === "revid")
|
|
2272
|
-
f = await u.newFromRevision(o);
|
|
2273
|
-
else
|
|
2274
|
-
throw new Error(`Invalid kind: ${a}`);
|
|
2275
|
-
l(this.newTitle(f.title));
|
|
2276
|
-
} catch (u) {
|
|
2277
|
-
this._cachedTitles.delete(`${a}:${o}`), h(u);
|
|
2278
|
-
}
|
|
2279
|
-
return c;
|
|
2280
|
-
}
|
|
2281
|
-
async newTitleFromPageId(e) {
|
|
2282
|
-
return this.newTitleFromAnyId({ pageId: e });
|
|
2283
|
-
}
|
|
2284
|
-
async newTitleFromRevision(e) {
|
|
2285
|
-
return this.newTitleFromAnyId({ revId: e });
|
|
2286
|
-
}
|
|
2287
|
-
/**
|
|
2288
|
-
* Resolve **special** special pages to it's real target
|
|
2289
|
-
*
|
|
2290
|
-
* If target is self or cannot be resolved, return null
|
|
2291
|
-
* @example
|
|
2292
|
-
* ```
|
|
2293
|
-
* Special:MyPage -> User:<username>
|
|
2294
|
-
* Special:Edit/Page_Title -> Page_Title
|
|
2295
|
-
* Special:NewSection/Page_Title -> Page_Title (section=new)
|
|
2296
|
-
* ```
|
|
2297
|
-
*/
|
|
2298
|
-
resolveSpecialPageTarget(e) {
|
|
2299
|
-
const t = typeof e == "string" ? this.newTitle(e) : e;
|
|
2300
|
-
if (!t || t.getNamespaceId() !== -1)
|
|
2301
|
-
return null;
|
|
2302
|
-
let i, s, r = "view";
|
|
2303
|
-
const o = t.getMainDBKey().split("/").slice(1).join("/") || "";
|
|
2304
|
-
if (t.isSpecial("edit") && o)
|
|
2305
|
-
i = o, r = "edit";
|
|
2306
|
-
else if (t.isSpecial("talkpage") && o) {
|
|
2307
|
-
const a = t.newTitle(o).getTalkPage();
|
|
2308
|
-
if (!a)
|
|
2309
|
-
return null;
|
|
2310
|
-
i = a.getPrefixedDBKey();
|
|
2311
|
-
} else if (t.isSpecial("mypage"))
|
|
2312
|
-
i = t.newTitle(this.ctx.wiki.userInfo.name, 2).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
2313
|
-
else if (t.isSpecial("mytalk"))
|
|
2314
|
-
i = t.newTitle(this.ctx.wiki.userInfo.name, 3).getPrefixedDBKey() + (o ? `/${o}` : "");
|
|
2315
|
-
else if (t.isSpecial("newsection") && o)
|
|
2316
|
-
i = o, s = "new", r = "edit";
|
|
2317
|
-
else
|
|
2318
|
-
return null;
|
|
2319
|
-
return {
|
|
2320
|
-
title: new this.Title(i),
|
|
2321
|
-
section: s,
|
|
2322
|
-
action: r
|
|
2323
|
-
};
|
|
2324
|
-
}
|
|
2325
|
-
isWikiLink(e) {
|
|
2326
|
-
return e.startsWith(this.wikiArticleBaseUrl) || e.startsWith(this.wikiIndexPhpUrl) || // Some servers allow index.php to be omitted
|
|
2327
|
-
e.startsWith(`${this.wikiBaseUrl}/?`) || // It's the landing page
|
|
2328
|
-
e === this.ctx.wiki.landingPageUrl;
|
|
2329
|
-
}
|
|
2330
|
-
static {
|
|
2331
|
-
this.REG_SKIPPED_HREF = /^(#|javascript:|vbscript:|file:)/i;
|
|
2332
|
-
}
|
|
2333
|
-
validateHrefAttr(e) {
|
|
2334
|
-
return typeof e != "string" ? !1 : !ge.REG_SKIPPED_HREF.test(e);
|
|
2335
|
-
}
|
|
2336
|
-
parseWikiLink(e) {
|
|
2337
|
-
if (!e || typeof e == "string" && !this.validateHrefAttr(e))
|
|
2338
|
-
return null;
|
|
2339
|
-
const t = We(e);
|
|
2340
|
-
if (!this.isWikiLink(t.toString()))
|
|
2341
|
-
return null;
|
|
2342
|
-
const i = t.searchParams, s = t.hash.replace("#", ""), r = i.get("action") || "view", o = i.get("title") || "", a = parseInt(i.get("curid") || "0", 10), c = parseInt(i.get("oldid") || "0", 10);
|
|
2343
|
-
let l = o || (() => {
|
|
2344
|
-
try {
|
|
2345
|
-
return decodeURIComponent(t.pathname.substring(this.wikiArticlePath.length));
|
|
2346
|
-
} catch (d) {
|
|
2347
|
-
return this.logger.error("parseLink", t, d), "";
|
|
2348
|
-
}
|
|
2349
|
-
})();
|
|
2350
|
-
l.endsWith("index.php") && (l = "");
|
|
2351
|
-
let h, u, f;
|
|
2352
|
-
if (c)
|
|
2353
|
-
f = c;
|
|
2354
|
-
else if (a)
|
|
2355
|
-
u = a;
|
|
2356
|
-
else if (l)
|
|
2357
|
-
h = this.newTitle(l);
|
|
2358
|
-
else if (t.origin + t.pathname === this.ctx.wiki.landingPageUrl)
|
|
2359
|
-
h = this.newMainPageTitle();
|
|
2360
|
-
else
|
|
2361
|
-
return null;
|
|
2362
|
-
return {
|
|
2363
|
-
title: h,
|
|
2364
|
-
pageId: u,
|
|
2365
|
-
revId: f,
|
|
2366
|
-
url: t,
|
|
2367
|
-
params: i,
|
|
2368
|
-
hash: s,
|
|
2369
|
-
action: r
|
|
2370
|
-
};
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
var Li = Object.create, pe = Object.defineProperty, Ai = Object.getOwnPropertyDescriptor, Je = (n, e) => (e = Symbol[n]) ? e : Symbol.for("Symbol." + n), Ze = (n) => {
|
|
2374
|
-
throw TypeError(n);
|
|
2375
|
-
}, Pi = (n, e, t) => e in n ? pe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Ri = (n, e) => pe(n, "name", { value: e, configurable: !0 }), Di = (n) => [, , , Li(n?.[Je("metadata")] ?? null)], Ti = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Qe = (n) => n !== void 0 && typeof n != "function" ? Ze("Function expected") : n, Mi = (n, e, t, i, s) => ({ kind: Ti[n], name: e, metadata: i, addInitializer: (r) => t._ ? Ze("Already initialized") : s.push(Qe(r || null)) }), Ui = (n, e) => Pi(e, Je("metadata"), n[3]), Bi = (n, e, t, i) => {
|
|
2376
|
-
for (var s = 0, r = n[e >> 1], o = r && r.length; s < o; s++) r[s].call(t);
|
|
2377
|
-
return i;
|
|
2378
|
-
}, Oi = (n, e, t, i, s, r) => {
|
|
2379
|
-
var o, a, c, l = e & 7, h = !1, u = 0, f = n[u] || (n[u] = []), d = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Ai(s, t));
|
|
2380
|
-
Ri(s, t);
|
|
2381
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
2382
|
-
c = Mi(l, t, a = {}, n[3], f), o = (0, i[g])(s, c), a._ = 1, Qe(o) && (s = o);
|
|
2383
|
-
return Ui(n, s), d && pe(s, t, d), h ? l ^ 4 ? r : d : s;
|
|
2384
|
-
}, et, me, tt;
|
|
2385
|
-
et = [j(["storage", "wiki"])];
|
|
2386
|
-
class G extends (tt = L) {
|
|
2387
|
-
constructor(e) {
|
|
2388
|
-
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);
|
|
2389
|
-
try {
|
|
2390
|
-
this._migrageFromLegacyMasterDB();
|
|
2391
|
-
} catch {
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
get logger() {
|
|
2395
|
-
return this.ctx.logger("PREFERENCES");
|
|
2396
|
-
}
|
|
2397
|
-
async start() {
|
|
2398
|
-
}
|
|
2399
|
-
async get(e, t) {
|
|
2400
|
-
if (!e)
|
|
2401
|
-
return this.getAll();
|
|
2402
|
-
t ??= () => {
|
|
2403
|
-
const s = this.defaultOf(e);
|
|
2404
|
-
return this.logger.debug(e, `(fallback value: ${s})`), s;
|
|
2405
|
-
};
|
|
2406
|
-
const i = await this.db.get(e, void 0);
|
|
2407
|
-
return i !== null ? i : await bt(t);
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* 获取全部注册的配置项以及最终生效的值
|
|
2411
|
-
* 未保存的配置项将使用默认值
|
|
2412
|
-
*/
|
|
2413
|
-
async getAll() {
|
|
2414
|
-
const e = this.loadDefaultConfigs();
|
|
2415
|
-
for await (const [t, i] of this.db.entries())
|
|
2416
|
-
t !== "_touched" && t in e && (e[t] = i.value);
|
|
2417
|
-
return e;
|
|
2418
|
-
}
|
|
2419
|
-
async set(e, t) {
|
|
2420
|
-
return (await this.setMany({ [e]: t }))[e];
|
|
2421
|
-
}
|
|
2422
|
-
async setMany(e) {
|
|
2423
|
-
const t = this.loadDefaultConfigs(), i = {};
|
|
2424
|
-
for (const [s, r] of Object.entries(e))
|
|
2425
|
-
r === t[s] || r === void 0 ? i[s] = void 0 : i[s] = r;
|
|
2426
|
-
return await this.db.set(i), this.ctx.emit("preferences/changed", { ctx: this.ctx, input: e, changes: i }), i;
|
|
2427
|
-
}
|
|
2428
|
-
defaultOf(e) {
|
|
2429
|
-
return this._defaultPreferences[e] ??= this.loadDefaultConfigs()[e];
|
|
2430
|
-
}
|
|
2431
|
-
/**
|
|
2432
|
-
* Get exportable configurations
|
|
2433
|
-
* - exclude values that are the same as the default value
|
|
2434
|
-
* - exclude invalid or undefined values
|
|
2435
|
-
* - sort by keys
|
|
2436
|
-
*/
|
|
2437
|
-
async getExportableRecord(e) {
|
|
2438
|
-
e ??= await this.getAll();
|
|
2439
|
-
const t = this.loadDefaultConfigs(), i = {};
|
|
2440
|
-
return Object.entries(t).sort(([s], [r]) => s.localeCompare(r)).forEach(([s, r]) => {
|
|
2441
|
-
const o = e[s];
|
|
2442
|
-
o !== void 0 && o !== r && (i[s] = o);
|
|
2443
|
-
}), i;
|
|
2444
|
-
}
|
|
2445
|
-
loadDefaultConfigs() {
|
|
2446
|
-
const e = {};
|
|
2447
|
-
return this.getConfigRegistries().forEach((t) => {
|
|
2448
|
-
try {
|
|
2449
|
-
const i = t.schema({});
|
|
2450
|
-
Object.entries(i).forEach(([s, r]) => {
|
|
2451
|
-
e[s] = r;
|
|
2452
|
-
});
|
|
2453
|
-
} catch {
|
|
2454
|
-
}
|
|
2455
|
-
}), Object.entries(e).forEach(([t, i]) => {
|
|
2456
|
-
this._defaultPreferences[t] = i;
|
|
2457
|
-
}), e;
|
|
2458
|
-
}
|
|
2459
|
-
registerCustomConfig(e, t, i) {
|
|
2460
|
-
const s = {
|
|
2461
|
-
name: e,
|
|
2462
|
-
schema: t,
|
|
2463
|
-
category: i || "general"
|
|
2464
|
-
}, r = this.customRegistries.findIndex((o) => o.name === e);
|
|
2465
|
-
return r >= 0 ? this.customRegistries[r] = s : this.customRegistries.push(s), this;
|
|
2466
|
-
}
|
|
2467
|
-
getConfigRegistries(e) {
|
|
2468
|
-
return Array.from(this.ctx.registry.entries()).map(([t]) => t === null ? {
|
|
2469
|
-
name: "@root",
|
|
2470
|
-
schema: V?.PreferencesSchema || null
|
|
2471
|
-
} : {
|
|
2472
|
-
name: t.name,
|
|
2473
|
-
schema: t?.PreferencesSchema || null
|
|
2474
|
-
}).filter((t) => t.schema !== null).map((t) => ({
|
|
2475
|
-
...t,
|
|
2476
|
-
category: t.schema.meta.category || "general"
|
|
2477
|
-
})).concat(this.customRegistries).filter((t) => !e || t.category === e);
|
|
2478
|
-
}
|
|
2479
|
-
getAllSchema() {
|
|
2480
|
-
return new p(
|
|
2481
|
-
p.intersect(this.getConfigRegistries().map((e) => e.schema))
|
|
2482
|
-
);
|
|
2483
|
-
}
|
|
2484
|
-
defineCategory(e) {
|
|
2485
|
-
const t = this.categoryDefinitions.findIndex((i) => i.name === e.name);
|
|
2486
|
-
return t < 0 ? this.categoryDefinitions.push(e) : this.categoryDefinitions[t] = e, this.categoryDefinitions.sort((i, s) => (i.index ?? 0) - (s.index ?? 0)), this;
|
|
2487
|
-
}
|
|
2488
|
-
getConfigCategories() {
|
|
2489
|
-
return this.categoryDefinitions;
|
|
2490
|
-
}
|
|
2491
|
-
async _migrageFromLegacyMasterDB() {
|
|
2492
|
-
const e = this.ctx.storage.createDatabase("preferences", 1 / 0);
|
|
2493
|
-
let t = 0;
|
|
2494
|
-
for await (const [i, s] of e.entries())
|
|
2495
|
-
i !== "_touched" && (await this.db.set(i, s.value), t++);
|
|
2496
|
-
return t && this.logger.info(`Migrated ${t} preferences from master DB`), await e.clear(), await e?.db?.disconnect?.(), t;
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
me = Di(tt);
|
|
2500
|
-
G = Oi(me, 0, "PreferencesService", et, G);
|
|
2501
|
-
Bi(me, 1, G);
|
|
2502
|
-
const it = "", nt = "", Ni = /\\\{/g, ji = /\\\}/g, Fi = new RegExp(it, "g"), zi = new RegExp(nt, "g");
|
|
2503
|
-
function Le(n) {
|
|
2504
|
-
const e = n ? { ...n } : void 0;
|
|
2505
|
-
return (i, ...s) => Ki(e, i, ...s);
|
|
2506
|
-
}
|
|
2507
|
-
function Ki(n, e, ...t) {
|
|
2508
|
-
if (!e) return "";
|
|
2509
|
-
let i = String(e).replace(Ni, it).replace(ji, nt), s = {}, r = [];
|
|
2510
|
-
t.length === 1 && Array.isArray(t[0]) ? r = t[0] : t.length === 1 && Hi(t[0]) ? s = t[0] : t.length > 0 && (r = t);
|
|
2511
|
-
const o = /* @__PURE__ */ Object.create(null);
|
|
2512
|
-
if (r && r.length)
|
|
2513
|
-
for (let a = 0; a < r.length; a++)
|
|
2514
|
-
o[`$${a + 1}`] = r[a];
|
|
2515
|
-
if (s && Object.keys(s).length)
|
|
2516
|
-
for (const a of Object.keys(s)) o[a] = s[a];
|
|
2517
|
-
if (n && Object.keys(n).length)
|
|
2518
|
-
for (const a of Object.keys(n))
|
|
2519
|
-
typeof o[a] > "u" && (o[a] = n[a]);
|
|
2520
|
-
return i = i.replace(/\{\{\s*([\s\S]*?)\s*\}\}/g, (a, c) => {
|
|
2521
|
-
const l = String(c).trim();
|
|
2522
|
-
if (!l) return "";
|
|
2523
|
-
try {
|
|
2524
|
-
const h = Wi(l, o);
|
|
2525
|
-
return h == null ? "" : String(h);
|
|
2526
|
-
} catch {
|
|
2527
|
-
return "";
|
|
2528
|
-
}
|
|
2529
|
-
}), i.replace(Fi, "{").replace(zi, "}");
|
|
2530
|
-
}
|
|
2531
|
-
function Hi(n) {
|
|
2532
|
-
return typeof n == "object" && n !== null && n.constructor === Object;
|
|
2533
|
-
}
|
|
2534
|
-
const Wi = qi();
|
|
2535
|
-
function qi() {
|
|
2536
|
-
const n = /* @__PURE__ */ new Set([
|
|
2537
|
-
"eval",
|
|
2538
|
-
"Object",
|
|
2539
|
-
"Array",
|
|
2540
|
-
"String",
|
|
2541
|
-
"Number",
|
|
2542
|
-
"Boolean",
|
|
2543
|
-
"Date",
|
|
2544
|
-
"Math",
|
|
2545
|
-
"JSON",
|
|
2546
|
-
"undefined",
|
|
2547
|
-
"null",
|
|
2548
|
-
"true",
|
|
2549
|
-
"false",
|
|
2550
|
-
"NaN",
|
|
2551
|
-
"Infinity",
|
|
2552
|
-
"isNaN",
|
|
2553
|
-
"isFinite",
|
|
2554
|
-
"parseInt",
|
|
2555
|
-
"parseFloat"
|
|
2556
|
-
]), e = new Function(
|
|
2557
|
-
"__expr__",
|
|
2558
|
-
"ctx",
|
|
2559
|
-
`
|
|
2560
|
-
try {
|
|
2561
|
-
with (ctx) {
|
|
2562
|
-
return (eval(__expr__));
|
|
2563
|
-
}
|
|
2564
|
-
} catch (e) {
|
|
2565
|
-
throw e;
|
|
2566
|
-
}
|
|
2567
|
-
`
|
|
2568
|
-
);
|
|
2569
|
-
return (t, i) => {
|
|
2570
|
-
const s = new Proxy(i, {
|
|
2571
|
-
has: (r, o) => typeof o == "symbol" ? o in r : !(typeof o == "string" && (n.has(o) || o === "__expr__")),
|
|
2572
|
-
get: (r, o) => {
|
|
2573
|
-
if (o in r)
|
|
2574
|
-
return r[o];
|
|
2575
|
-
}
|
|
2576
|
-
});
|
|
2577
|
-
return e(t, s);
|
|
2578
|
-
};
|
|
2579
|
-
}
|
|
2580
|
-
function A(n, e) {
|
|
2581
|
-
let t = n[0] ?? "";
|
|
2582
|
-
for (let i = 0; i < e.length; i++)
|
|
2583
|
-
t += String(e[i]) + (n[i + 1] ?? "");
|
|
2584
|
-
return t;
|
|
2585
|
-
}
|
|
2586
|
-
class Gi {
|
|
2587
|
-
constructor(e, t) {
|
|
2588
|
-
this.languages = /* @__PURE__ */ new Map(), this.currentLanguage = "en", this.missingKeys = /* @__PURE__ */ new Map(), this.usedKeys = /* @__PURE__ */ new Set();
|
|
2589
|
-
const i = t?.language || "en";
|
|
2590
|
-
this.currentLanguage = i, this.interpolate = Le(t?.globals), e && Object.keys(e).length && this.setLanguageData(i, e);
|
|
2591
|
-
}
|
|
2592
|
-
setGlobals(e) {
|
|
2593
|
-
return this.interpolate = Le(e), this;
|
|
2594
|
-
}
|
|
2595
|
-
set(e, t) {
|
|
2596
|
-
const i = this.currentLanguage, s = this.ensureLanguageMap(i);
|
|
2597
|
-
if (typeof e == "string" && typeof t == "string")
|
|
2598
|
-
s.set(e, t);
|
|
2599
|
-
else if (typeof e == "object") {
|
|
2600
|
-
const r = this.toStringRecord(e);
|
|
2601
|
-
for (const [o, a] of Object.entries(r))
|
|
2602
|
-
s.set(o, a);
|
|
2603
|
-
}
|
|
2604
|
-
return this;
|
|
2605
|
-
}
|
|
2606
|
-
setLanguageData(e, t) {
|
|
2607
|
-
e = O(e).toLowerCase();
|
|
2608
|
-
const i = this.ensureLanguageMap(e), s = this.toStringRecord(t);
|
|
2609
|
-
for (const [r, o] of Object.entries(s))
|
|
2610
|
-
i.set(r, o);
|
|
2611
|
-
return this;
|
|
2612
|
-
}
|
|
2613
|
-
setLanguage(e) {
|
|
2614
|
-
return e = O(e).toLowerCase(), this.currentLanguage = e, this;
|
|
2615
|
-
}
|
|
2616
|
-
getLanguage() {
|
|
2617
|
-
return this.currentLanguage;
|
|
2618
|
-
}
|
|
2619
|
-
hasLanguage(e) {
|
|
2620
|
-
e = O(e).toLowerCase();
|
|
2621
|
-
const t = this.languages.get(e);
|
|
2622
|
-
return t && Object.keys(t).length > 0;
|
|
2623
|
-
}
|
|
2624
|
-
toStringRecord(e, t) {
|
|
2625
|
-
const i = {};
|
|
2626
|
-
for (const [s, r] of Object.entries(e)) {
|
|
2627
|
-
const o = t ? `${t}.${s}` : s;
|
|
2628
|
-
if (r && typeof r == "object" && !Array.isArray(r)) {
|
|
2629
|
-
const a = this.toStringRecord(r, o);
|
|
2630
|
-
for (const [c, l] of Object.entries(a))
|
|
2631
|
-
i[c] = String(l);
|
|
2632
|
-
} else
|
|
2633
|
-
i[o] = String(r);
|
|
2634
|
-
}
|
|
2635
|
-
return i;
|
|
2636
|
-
}
|
|
2637
|
-
has(e) {
|
|
2638
|
-
const t = this.resolveLanguageOrder(this.currentLanguage);
|
|
2639
|
-
for (const i of t)
|
|
2640
|
-
if (this.languages.get(i)?.has(e)) return !0;
|
|
2641
|
-
return !1;
|
|
2642
|
-
}
|
|
2643
|
-
get(e) {
|
|
2644
|
-
this.recordUsedKey(e);
|
|
2645
|
-
const t = this.resolveLanguageOrder(this.currentLanguage), i = [];
|
|
2646
|
-
for (const s of t) {
|
|
2647
|
-
const o = this.languages.get(s)?.get(e);
|
|
2648
|
-
if (typeof o < "u")
|
|
2649
|
-
return i.length && this.recordMissing(e, i), o;
|
|
2650
|
-
i.push(s);
|
|
2651
|
-
}
|
|
2652
|
-
i.length && this.recordMissing(e, i);
|
|
2653
|
-
}
|
|
2654
|
-
translate(e, ...t) {
|
|
2655
|
-
if (!e)
|
|
2656
|
-
return "";
|
|
2657
|
-
if (this.currentLanguage === "qqx")
|
|
2658
|
-
return `⧼${e}⧽`;
|
|
2659
|
-
const i = this.get(e);
|
|
2660
|
-
return typeof i > "u" ? this.interpolate(e, ...t) : this.interpolate(i, ...t);
|
|
2661
|
-
}
|
|
2662
|
-
$(...e) {
|
|
2663
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
2664
|
-
const s = e[0], r = e.slice(1), o = A(s, r);
|
|
2665
|
-
return this.translate(o);
|
|
2666
|
-
}
|
|
2667
|
-
const i = e;
|
|
2668
|
-
return (s, ...r) => {
|
|
2669
|
-
const o = A(s, r);
|
|
2670
|
-
return this.translate(o, ...i);
|
|
2671
|
-
};
|
|
2672
|
-
}
|
|
2673
|
-
/**
|
|
2674
|
-
* [payload as template] Return the raw message without interpolation
|
|
2675
|
-
* @example
|
|
2676
|
-
* ```
|
|
2677
|
-
* i18n.rawMsg('Hello, {{ name }}')
|
|
2678
|
-
* // good: "你好,{{ name }}"
|
|
2679
|
-
* // missing: "Hello, {{ name }}"
|
|
2680
|
-
* ```
|
|
2681
|
-
*/
|
|
2682
|
-
translateRaw(e) {
|
|
2683
|
-
return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? e : "";
|
|
2684
|
-
}
|
|
2685
|
-
$raw(...e) {
|
|
2686
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
2687
|
-
const i = e[0], s = e.slice(1), r = A(i, s);
|
|
2688
|
-
return this.translateRaw(r);
|
|
2689
|
-
}
|
|
2690
|
-
return (i, ...s) => {
|
|
2691
|
-
const r = A(i, s);
|
|
2692
|
-
return this.translateRaw(r);
|
|
2693
|
-
};
|
|
2694
|
-
}
|
|
2695
|
-
message(e, ...t) {
|
|
2696
|
-
if (!e)
|
|
2697
|
-
return "";
|
|
2698
|
-
if (this.currentLanguage === "qqx")
|
|
2699
|
-
return `⧼${e}⧽`;
|
|
2700
|
-
const i = this.get(e);
|
|
2701
|
-
return typeof i > "u" ? `(${e})` : this.interpolate(i, ...t);
|
|
2702
|
-
}
|
|
2703
|
-
$$(...e) {
|
|
2704
|
-
if (Array.isArray(e[0]) && e[0]?.raw) {
|
|
2705
|
-
const s = e[0], r = e.slice(1), o = A(s, r);
|
|
2706
|
-
return this.message(o);
|
|
2707
|
-
}
|
|
2708
|
-
const i = e;
|
|
2709
|
-
return (s, ...r) => {
|
|
2710
|
-
const o = A(s, r);
|
|
2711
|
-
return this.message(o, ...i);
|
|
2712
|
-
};
|
|
2713
|
-
}
|
|
2714
|
-
/**
|
|
2715
|
-
* [payload as key] Return the raw message without interpolation
|
|
2716
|
-
* @example
|
|
2717
|
-
* ```
|
|
2718
|
-
* i18n.rawMsg('greeting')
|
|
2719
|
-
* // good: "你好,{{ name }}"
|
|
2720
|
-
* // missing: "(greeting)"
|
|
2721
|
-
* ```
|
|
2722
|
-
*/
|
|
2723
|
-
messageRaw(e) {
|
|
2724
|
-
return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? `(${e})` : "";
|
|
2725
|
-
}
|
|
2726
|
-
$$raw(...e) {
|
|
2727
|
-
if (Array.isArray(e[0]) && e[0].raw) {
|
|
2728
|
-
const i = e[0], s = e.slice(1), r = A(i, s);
|
|
2729
|
-
return this.messageRaw(r);
|
|
2730
|
-
}
|
|
2731
|
-
return (i, ...s) => {
|
|
2732
|
-
const r = A(i, s);
|
|
2733
|
-
return this.messageRaw(r);
|
|
2734
|
-
};
|
|
2735
|
-
}
|
|
2736
|
-
getAvailableLanguages() {
|
|
2737
|
-
return Array.from(this.languages.keys());
|
|
2738
|
-
}
|
|
2739
|
-
ensureLanguageMap(e) {
|
|
2740
|
-
let t = this.languages.get(e);
|
|
2741
|
-
return t || (t = /* @__PURE__ */ new Map(), this.languages.set(e, t)), t;
|
|
2742
|
-
}
|
|
2743
|
-
resolveLanguageOrder(e) {
|
|
2744
|
-
const t = e;
|
|
2745
|
-
return t === "en" ? ["en"] : [t, "en"];
|
|
2746
|
-
}
|
|
2747
|
-
/**
|
|
2748
|
-
* 获取缺失键报告:
|
|
2749
|
-
* { foo: ['zh', 'zh-hans', 'en'] }
|
|
2750
|
-
*/
|
|
2751
|
-
getMissingReport() {
|
|
2752
|
-
return Object.fromEntries(this.missingKeys.entries());
|
|
2753
|
-
}
|
|
2754
|
-
/**
|
|
2755
|
-
* 清空缺失键记录
|
|
2756
|
-
*/
|
|
2757
|
-
clearMissingReport() {
|
|
2758
|
-
this.missingKeys.clear();
|
|
2759
|
-
}
|
|
2760
|
-
recordMissing(e, t) {
|
|
2761
|
-
if (!t.length) return;
|
|
2762
|
-
const i = this.missingKeys.get(e) || [];
|
|
2763
|
-
for (const s of t)
|
|
2764
|
-
i.includes(s) || i.push(s);
|
|
2765
|
-
this.missingKeys.set(e, i);
|
|
2766
|
-
}
|
|
2767
|
-
recordUsedKey(e) {
|
|
2768
|
-
this.usedKeys.add(e);
|
|
2769
|
-
}
|
|
2770
|
-
getUsedKeys() {
|
|
2771
|
-
return Array.from(this.usedKeys);
|
|
2772
|
-
}
|
|
2773
|
-
generateBlankKeyRecord() {
|
|
2774
|
-
const e = {};
|
|
2775
|
-
for (const t of this.getUsedKeys())
|
|
2776
|
-
e[t] = "";
|
|
2777
|
-
return e;
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
var Xi = Object.create, we = Object.defineProperty, Yi = Object.getOwnPropertyDescriptor, st = (n, e) => (e = Symbol[n]) ? e : Symbol.for("Symbol." + n), rt = (n) => {
|
|
2781
|
-
throw TypeError(n);
|
|
2782
|
-
}, Vi = (n, e, t) => e in n ? we(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Ji = (n, e) => we(n, "name", { value: e, configurable: !0 }), Zi = (n) => [, , , Xi(n?.[st("metadata")] ?? null)], Qi = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ot = (n) => n !== void 0 && typeof n != "function" ? rt("Function expected") : n, en = (n, e, t, i, s) => ({ kind: Qi[n], name: e, metadata: i, addInitializer: (r) => t._ ? rt("Already initialized") : s.push(ot(r || null)) }), tn = (n, e) => Vi(e, st("metadata"), n[3]), nn = (n, e, t, i) => {
|
|
2783
|
-
for (var s = 0, r = n[e >> 1], o = r && r.length; s < o; s++) r[s].call(t);
|
|
2784
|
-
return i;
|
|
2785
|
-
}, sn = (n, e, t, i, s, r) => {
|
|
2786
|
-
var o, a, c, l = e & 7, h = !1, u = 0, f = n[u] || (n[u] = []), d = l && (s = s.prototype, l < 5 && (l > 3 || !h) && Yi(s, t));
|
|
2787
|
-
Ji(s, t);
|
|
2788
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
2789
|
-
c = en(l, t, a = {}, n[3], f), o = (0, i[g])(s, c), a._ = 1, ot(o) && (s = o);
|
|
2790
|
-
return tn(n, s), d && we(s, t, d), h ? l ^ 4 ? r : d : s;
|
|
2791
|
-
}, at, ye, lt;
|
|
2792
|
-
const Ae = new p(
|
|
2793
|
-
p.object({
|
|
2794
|
-
manifest_version: p.const(1).required(),
|
|
2795
|
-
base_language: p.string().required(),
|
|
2796
|
-
last_modified: p.string().required(),
|
|
2797
|
-
languages: p.dict(
|
|
2798
|
-
p.object({
|
|
2799
|
-
file: p.string().required(),
|
|
2800
|
-
fallback: p.string(),
|
|
2801
|
-
iso_name: p.string(),
|
|
2802
|
-
endonym: p.string(),
|
|
2803
|
-
data: p.transform(
|
|
2804
|
-
p.dict(p.any()).default({}),
|
|
2805
|
-
(n) => Object.keys(n).length > 0 ? n : void 0
|
|
2806
|
-
)
|
|
2807
|
-
})
|
|
2808
|
-
).required()
|
|
2809
|
-
})
|
|
2810
|
-
);
|
|
2811
|
-
at = [j(["wiki", "preferences"]), vt(
|
|
2812
|
-
p.object({
|
|
2813
|
-
"i18n.index_url": p.string().description("I18n index URL (DO NOT CHANGE THIS) ").default(
|
|
2814
|
-
Re.I18N_INDEX_URL
|
|
2815
|
-
)
|
|
2816
|
-
}).description("").extra("category", "general")
|
|
2817
|
-
)];
|
|
2818
|
-
class X extends (lt = L) {
|
|
2819
|
-
constructor(e) {
|
|
2820
|
-
super(e, "i18n", !1), this.ctx = e, this.logger = void 0, this._indexUrl = void 0, this._indexCache = null, this.manager = void 0, this.i18nIndexDB = void 0, this.i18nDataDB = void 0, this.$ = void 0, this.$raw = void 0, this.$$ = void 0, this.$$raw = void 0, this.logger = this.ctx.logger("I18nService"), this.manager = new Gi(
|
|
2821
|
-
{},
|
|
2822
|
-
{
|
|
2823
|
-
language: "",
|
|
2824
|
-
globals: {
|
|
2825
|
-
userName: this.ctx.wiki.userInfo.name || "",
|
|
2826
|
-
userId: this.ctx.wiki.userInfo.id || 0,
|
|
2827
|
-
siteName: this.ctx.wiki.siteInfo.general.sitename || ""
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
), this.i18nIndexDB = e.storage.createDatabase(
|
|
2831
|
-
"i18n-index",
|
|
2832
|
-
1e3 * 60 * 60 * 24 * 3,
|
|
2833
|
-
// 3 days
|
|
2834
|
-
this.ctx.version,
|
|
2835
|
-
"indexedDB"
|
|
2836
|
-
), this.i18nDataDB = e.storage.createDatabase(
|
|
2837
|
-
"i18n-data",
|
|
2838
|
-
1e3 * 60 * 60 * 24 * 3,
|
|
2839
|
-
// 3 days
|
|
2840
|
-
this.ctx.version,
|
|
2841
|
-
"indexedDB"
|
|
2842
|
-
), this.$ = this.manager.$.bind(this.manager), this.$raw = this.manager.$raw.bind(this.manager), this.$$ = this.manager.$$.bind(this.manager), this.$$raw = this.manager.$$raw.bind(this.manager);
|
|
2843
|
-
}
|
|
2844
|
-
async start() {
|
|
2845
|
-
this.ctx.preferences.registerCustomConfig(
|
|
2846
|
-
"language",
|
|
2847
|
-
p.object({
|
|
2848
|
-
language: p.union([
|
|
2849
|
-
"@user",
|
|
2850
|
-
"@site",
|
|
2851
|
-
p.string().description("Custom language code")
|
|
2852
|
-
]).description("UI language").default("@user")
|
|
2853
|
-
}).description("UI language")
|
|
2854
|
-
), this.ctx.on("clear-cache", this.onClearCache.bind(this));
|
|
2855
|
-
const e = this._indexUrl = await this.ctx.preferences.get("i18n.index_url") || "";
|
|
2856
|
-
if (!e) {
|
|
2857
|
-
this.logger.error("I18n index URL is not set"), this.setupShortcuts();
|
|
2858
|
-
return;
|
|
2859
|
-
}
|
|
2860
|
-
let t = null;
|
|
2861
|
-
try {
|
|
2862
|
-
t = await this.getI18nIndex(e);
|
|
2863
|
-
} catch (r) {
|
|
2864
|
-
this.logger.error("Failed to fetch i18n index", r), this.setupShortcuts();
|
|
2865
|
-
return;
|
|
2866
|
-
}
|
|
2867
|
-
this._indexCache = t, Object.entries(t.languages).forEach(([r, o]) => {
|
|
2868
|
-
o.data && Object.keys(o.data).length > 0 && this.manager.setLanguageData(r, o.data);
|
|
2869
|
-
});
|
|
2870
|
-
const i = await this.ctx.preferences.get("language"), s = this.normalizeLanguageCode(i);
|
|
2871
|
-
this.logger.debug("Settings", { prefer: i, normalized: s });
|
|
2872
|
-
try {
|
|
2873
|
-
await this.switchLanguage(s), this.logger.info(`Initialized for language: ${this.language}`);
|
|
2874
|
-
} catch (r) {
|
|
2875
|
-
this.logger.error("Failed to fetch i18n index", r), this.manager.setLanguage("en");
|
|
2876
|
-
}
|
|
2877
|
-
this.ctx.preferences.registerCustomConfig(
|
|
2878
|
-
"language",
|
|
2879
|
-
p.object({
|
|
2880
|
-
language: p.union([
|
|
2881
|
-
p.const("@user").description(this.$`Same as your personal language`),
|
|
2882
|
-
p.const("@site").description(this.$`Same as the site language`),
|
|
2883
|
-
...this.getAvailableLanguageCodes().map(
|
|
2884
|
-
({ code: r, endonym: o, iso_name: a }) => p.const(r).description(o || a || r)
|
|
2885
|
-
)
|
|
2886
|
-
]).default("@user")
|
|
2887
|
-
}).description(this.$`InPageEdit UI language`)
|
|
2888
|
-
), this.setupShortcuts(), this.ctx.on("preferences/changed", async ({ changes: r }) => {
|
|
2889
|
-
if (!("language" in r)) return;
|
|
2890
|
-
const o = this.normalizeLanguageCode(await this.ctx.preferences.get("language"));
|
|
2891
|
-
o && o !== this.language && await this.switchLanguage(o);
|
|
2892
|
-
});
|
|
2893
|
-
}
|
|
2894
|
-
setupShortcuts() {
|
|
2895
|
-
if (!this.manager) throw new Error("I18nManager is not initialized");
|
|
2896
|
-
this.ctx.set("$", this.manager.$.bind(this.manager)), this.ctx.set("$raw", this.manager.$raw.bind(this.manager)), this.ctx.set("$$", this.manager.$$.bind(this.manager)), this.ctx.set("$$raw", this.manager.$$raw.bind(this.manager));
|
|
2897
|
-
}
|
|
2898
|
-
normalizeLanguageCode(e) {
|
|
2899
|
-
return !e || typeof e != "string" ? "en" : (e === "@user" && (e = this.ctx.wiki.userInfo.options.language || "en"), e === "@site" && (e = this.ctx.wiki.siteInfo.general.lang || "en"), O(String(e)).toLowerCase());
|
|
2900
|
-
}
|
|
2901
|
-
get language() {
|
|
2902
|
-
return this.manager.getLanguage();
|
|
2903
|
-
}
|
|
2904
|
-
/**
|
|
2905
|
-
* 主动设置偏好值(会触发 preferences/changed,从而热切换)
|
|
2906
|
-
*/
|
|
2907
|
-
async setLanguagePreference(e) {
|
|
2908
|
-
await this.ctx.preferences.set("language", e);
|
|
2909
|
-
}
|
|
2910
|
-
/**
|
|
2911
|
-
* 直接切换到具体语言(不修改偏好值)
|
|
2912
|
-
*/
|
|
2913
|
-
async switchLanguage(e) {
|
|
2914
|
-
const t = this.normalizeLanguageCode(e);
|
|
2915
|
-
await this.ensureLanguageLoaded(t), this.manager.setLanguage(t), this.ctx.emit("i18n/changed", { ctx: this.ctx, language: t });
|
|
2916
|
-
}
|
|
2917
|
-
/**
|
|
2918
|
-
* 为指定语言注册(或合并)消息。
|
|
2919
|
-
* - 推荐加命名空间避免冲突:{ myPlugin: { key: 'value' } }
|
|
2920
|
-
* - 若 language 为当前语言,将立即可用;必要时你可以手动触发 UI 刷新或监听 i18n/changed。
|
|
2921
|
-
*/
|
|
2922
|
-
async registerMessages(e, t, i) {
|
|
2923
|
-
const s = i?.namespace ? { [i.namespace]: t } : t;
|
|
2924
|
-
this.manager.setLanguageData(e, s), e === this.language && this.ctx.emit("i18n/changed", { ctx: this.ctx, language: this.language });
|
|
2925
|
-
}
|
|
2926
|
-
/**
|
|
2927
|
-
* 列出可用语言与文件(来源于 index.json)
|
|
2928
|
-
*/
|
|
2929
|
-
getAvailableLanguageCodes() {
|
|
2930
|
-
if (!this._indexCache) throw new Error("I18n index is not loaded");
|
|
2931
|
-
return Object.entries(this._indexCache.languages).filter(([e, t]) => !t.fallback).reduce(
|
|
2932
|
-
(e, [t, i]) => (e.push({ code: t, ...i }), e),
|
|
2933
|
-
[]
|
|
2934
|
-
);
|
|
2935
|
-
}
|
|
2936
|
-
findLanguageMeta(e, t) {
|
|
2937
|
-
const i = O(String(t)).toLowerCase(), s = e.languages[i];
|
|
2938
|
-
if (s)
|
|
2939
|
-
return {
|
|
2940
|
-
code: i,
|
|
2941
|
-
...s
|
|
2942
|
-
};
|
|
2943
|
-
{
|
|
2944
|
-
const r = e.languages.en;
|
|
2945
|
-
if (r)
|
|
2946
|
-
return {
|
|
2947
|
-
code: "en",
|
|
2948
|
-
...r
|
|
2949
|
-
};
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
async getI18nIndex(e, t = !1) {
|
|
2953
|
-
if (!t) {
|
|
2954
|
-
const s = await this.i18nIndexDB.get(e);
|
|
2955
|
-
if (s)
|
|
2956
|
-
try {
|
|
2957
|
-
return Ae(s);
|
|
2958
|
-
} catch (r) {
|
|
2959
|
-
this.logger.error("Failed to parse cached i18n index", r), this.i18nIndexDB.delete(e);
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
const i = await this.fetchI18nIndex(e);
|
|
2963
|
-
return this.i18nIndexDB.set(e, i), i;
|
|
2964
|
-
}
|
|
2965
|
-
async fetchI18nIndex(e) {
|
|
2966
|
-
const t = await fetch(e).then((i) => i.json());
|
|
2967
|
-
return Ae(t);
|
|
2968
|
-
}
|
|
2969
|
-
async ensureLanguageLoaded(e) {
|
|
2970
|
-
if (!this.manager || !this._indexCache) throw new Error("I18nManager is not initialized");
|
|
2971
|
-
if (this.manager.hasLanguage(e))
|
|
2972
|
-
return this.logger.debug("Language already loaded", e);
|
|
2973
|
-
const t = await this.getLanguageData(e);
|
|
2974
|
-
this.manager.setLanguageData(e, t), this.logger.debug("Language data ensured", e, t);
|
|
2975
|
-
}
|
|
2976
|
-
async getLanguageData(e, t = !1) {
|
|
2977
|
-
if (!this._indexCache) throw new Error("I18n index is not loaded");
|
|
2978
|
-
const i = this.findLanguageMeta(this._indexCache, e);
|
|
2979
|
-
if (!i) return {};
|
|
2980
|
-
const s = `${this._indexUrl}#${i.file}`;
|
|
2981
|
-
if (!t) {
|
|
2982
|
-
const o = await this.i18nDataDB.get(s);
|
|
2983
|
-
if (o && Object.keys(o).length > 0)
|
|
2984
|
-
return this.logger.debug("Using cached language data", e, o), o;
|
|
2985
|
-
}
|
|
2986
|
-
const r = i.data || await fetch(new URL(i.file, this._indexUrl).toString()).then((o) => o.json());
|
|
2987
|
-
return this.i18nDataDB.set(s, r), this.logger.debug("Language data fetched", e, i.file, r), r;
|
|
2988
|
-
}
|
|
2989
|
-
/**
|
|
2990
|
-
* 获取缺失键报告,形如:
|
|
2991
|
-
* { foo: ['zh', 'zh-hans', 'en'] }
|
|
2992
|
-
*/
|
|
2993
|
-
getMissingReport() {
|
|
2994
|
-
return this.manager.getMissingReport();
|
|
2995
|
-
}
|
|
2996
|
-
/**
|
|
2997
|
-
* 清空缺失键记录
|
|
2998
|
-
*/
|
|
2999
|
-
clearMissingReport() {
|
|
3000
|
-
this.manager.clearMissingReport();
|
|
3001
|
-
}
|
|
3002
|
-
async onClearCache() {
|
|
3003
|
-
await this.i18nIndexDB.clear(), await this.i18nDataDB.clear();
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
ye = Zi(lt);
|
|
3007
|
-
X = sn(ye, 0, "I18nService", at, X);
|
|
3008
|
-
nn(ye, 1, X);
|
|
3009
|
-
const rn = new TextEncoder();
|
|
3010
|
-
function on(n) {
|
|
3011
|
-
if (typeof n == "string") return rn.encode(n);
|
|
3012
|
-
if (n instanceof ArrayBuffer) return new Uint8Array(n);
|
|
3013
|
-
if (ArrayBuffer.isView(n))
|
|
3014
|
-
return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
3015
|
-
throw new TypeError("Unsupported input type");
|
|
3016
|
-
}
|
|
3017
|
-
function an(n) {
|
|
3018
|
-
let e = "";
|
|
3019
|
-
for (let t = 0; t < n.length; t++) {
|
|
3020
|
-
const i = n[t].toString(16).padStart(2, "0");
|
|
3021
|
-
e += i;
|
|
3022
|
-
}
|
|
3023
|
-
return e;
|
|
3024
|
-
}
|
|
3025
|
-
function ln(n, e) {
|
|
3026
|
-
return n << e | n >>> 32 - e;
|
|
3027
|
-
}
|
|
3028
|
-
const cn = [
|
|
3029
|
-
7,
|
|
3030
|
-
12,
|
|
3031
|
-
17,
|
|
3032
|
-
22,
|
|
3033
|
-
7,
|
|
3034
|
-
12,
|
|
3035
|
-
17,
|
|
3036
|
-
22,
|
|
3037
|
-
7,
|
|
3038
|
-
12,
|
|
3039
|
-
17,
|
|
3040
|
-
22,
|
|
3041
|
-
7,
|
|
3042
|
-
12,
|
|
3043
|
-
17,
|
|
3044
|
-
22,
|
|
3045
|
-
5,
|
|
3046
|
-
9,
|
|
3047
|
-
14,
|
|
3048
|
-
20,
|
|
3049
|
-
5,
|
|
3050
|
-
9,
|
|
3051
|
-
14,
|
|
3052
|
-
20,
|
|
3053
|
-
5,
|
|
3054
|
-
9,
|
|
3055
|
-
14,
|
|
3056
|
-
20,
|
|
3057
|
-
5,
|
|
3058
|
-
9,
|
|
3059
|
-
14,
|
|
3060
|
-
20,
|
|
3061
|
-
4,
|
|
3062
|
-
11,
|
|
3063
|
-
16,
|
|
3064
|
-
23,
|
|
3065
|
-
4,
|
|
3066
|
-
11,
|
|
3067
|
-
16,
|
|
3068
|
-
23,
|
|
3069
|
-
4,
|
|
3070
|
-
11,
|
|
3071
|
-
16,
|
|
3072
|
-
23,
|
|
3073
|
-
4,
|
|
3074
|
-
11,
|
|
3075
|
-
16,
|
|
3076
|
-
23,
|
|
3077
|
-
6,
|
|
3078
|
-
10,
|
|
3079
|
-
15,
|
|
3080
|
-
21,
|
|
3081
|
-
6,
|
|
3082
|
-
10,
|
|
3083
|
-
15,
|
|
3084
|
-
21,
|
|
3085
|
-
6,
|
|
3086
|
-
10,
|
|
3087
|
-
15,
|
|
3088
|
-
21,
|
|
3089
|
-
6,
|
|
3090
|
-
10,
|
|
3091
|
-
15,
|
|
3092
|
-
21
|
|
3093
|
-
], hn = new Array(64).fill(0).map((n, e) => Math.floor(Math.abs(Math.sin(e + 1)) * 2 ** 32) >>> 0);
|
|
3094
|
-
function un(n) {
|
|
3095
|
-
const e = on(n), t = (56 - (e.length + 1) % 64 + 64) % 64, i = e.length + 1 + t + 8, s = new Uint8Array(i);
|
|
3096
|
-
s.set(e, 0), s[e.length] = 128;
|
|
3097
|
-
const r = e.length, o = r << 3 >>> 0, a = r >>> 29 >>> 0, c = new DataView(s.buffer);
|
|
3098
|
-
c.setUint32(i - 8, o, !0), c.setUint32(i - 4, a, !0);
|
|
3099
|
-
let l = 1732584193, h = 4023233417, u = 2562383102, f = 271733878;
|
|
3100
|
-
const d = new Uint32Array(16);
|
|
3101
|
-
for (let S = 0; S < s.length; S += 64) {
|
|
3102
|
-
for (let $ = 0; $ < 16; $++) d[$] = c.getUint32(S + $ * 4, !0);
|
|
3103
|
-
let P = l, v = h, _ = u, C = f;
|
|
3104
|
-
for (let $ = 0; $ < 64; $++) {
|
|
3105
|
-
let M, U;
|
|
3106
|
-
$ < 16 ? (M = v & _ | ~v & C, U = $) : $ < 32 ? (M = C & v | ~C & _, U = (5 * $ + 1) % 16) : $ < 48 ? (M = v ^ _ ^ C, U = (3 * $ + 5) % 16) : (M = _ ^ (v | ~C), U = 7 * $ % 16);
|
|
3107
|
-
const gt = C, pt = P + M + hn[$] + d[U] >>> 0;
|
|
3108
|
-
C = _, _ = v, v = v + ln(pt, cn[$]) >>> 0, P = gt;
|
|
3109
|
-
}
|
|
3110
|
-
l = l + P >>> 0, h = h + v >>> 0, u = u + _ >>> 0, f = f + C >>> 0;
|
|
3111
|
-
}
|
|
3112
|
-
const g = new Uint8Array(16), w = new DataView(g.buffer);
|
|
3113
|
-
return w.setUint32(0, l, !0), w.setUint32(4, h, !0), w.setUint32(8, u, !0), w.setUint32(12, f, !0), g;
|
|
3114
|
-
}
|
|
3115
|
-
var dn = Object.create, be = Object.defineProperty, fn = Object.getOwnPropertyDescriptor, ct = (n, e) => (e = Symbol[n]) ? e : Symbol.for("Symbol." + n), ht = (n) => {
|
|
3116
|
-
throw TypeError(n);
|
|
3117
|
-
}, gn = (n, e, t) => e in n ? be(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, pn = (n, e) => be(n, "name", { value: e, configurable: !0 }), mn = (n) => [, , , dn(n?.[ct("metadata")] ?? null)], wn = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ut = (n) => n !== void 0 && typeof n != "function" ? ht("Function expected") : n, yn = (n, e, t, i, s) => ({ kind: wn[n], name: e, metadata: i, addInitializer: (r) => t._ ? ht("Already initialized") : s.push(ut(r || null)) }), bn = (n, e) => gn(e, ct("metadata"), n[3]), vn = (n, e, t, i) => {
|
|
3118
|
-
for (var s = 0, r = n[e >> 1], o = r && r.length; s < o; s++) r[s].call(t);
|
|
3119
|
-
return i;
|
|
3120
|
-
}, _n = (n, e, t, i, s, r) => {
|
|
3121
|
-
var o, a, c, l = e & 7, h = !1, u = 0, f = n[u] || (n[u] = []), d = l && (s = s.prototype, l < 5 && (l > 3 || !h) && fn(s, t));
|
|
3122
|
-
pn(s, t);
|
|
3123
|
-
for (var g = i.length - 1; g >= 0; g--)
|
|
3124
|
-
c = yn(l, t, a = {}, n[3], f), o = (0, i[g])(s, c), a._ = 1, ut(o) && (s = o);
|
|
3125
|
-
return bn(n, s), d && be(s, t, d), h ? l ^ 4 ? r : d : s;
|
|
3126
|
-
}, dt, ve, ft;
|
|
3127
|
-
dt = [j(["wiki", "wikiTitle", "wikiPage", "apiService"])];
|
|
3128
|
-
class Y extends (ft = L) {
|
|
3129
|
-
constructor(e) {
|
|
3130
|
-
super(e, "wikiFile", !0), this.ctx = e;
|
|
3131
|
-
}
|
|
3132
|
-
get fileRepos() {
|
|
3133
|
-
return this.ctx.wiki.fileRepos || [];
|
|
3134
|
-
}
|
|
3135
|
-
get defaultFileRepo() {
|
|
3136
|
-
return this.fileRepos[0];
|
|
3137
|
-
}
|
|
3138
|
-
get localFileRepo() {
|
|
3139
|
-
return this.fileRepos.find((e) => e.local);
|
|
3140
|
-
}
|
|
3141
|
-
get writableFileRepo() {
|
|
3142
|
-
return this.fileRepos.find((e) => e.canUpload);
|
|
3143
|
-
}
|
|
3144
|
-
getFileName(e) {
|
|
3145
|
-
if (e = this.ctx.wikiTitle.newTitle(e, 6), ![6, -2].includes(e.getNamespaceId()))
|
|
3146
|
-
throw new Error("Not a file title");
|
|
3147
|
-
return e.getMainDBKey().split("/").pop() || "";
|
|
3148
|
-
}
|
|
3149
|
-
getHashPath(e, t = 2) {
|
|
3150
|
-
const i = this.getFileName(e), s = an(un(i));
|
|
3151
|
-
let r = [];
|
|
3152
|
-
for (let o = 1; o <= t; o++)
|
|
3153
|
-
r.push(s.slice(0, o));
|
|
3154
|
-
return r.push(i), r.join("/");
|
|
3155
|
-
}
|
|
3156
|
-
getFileUrl(e, t) {
|
|
3157
|
-
if (t = t || this.defaultFileRepo, !t)
|
|
3158
|
-
throw new Error("No file repository found");
|
|
3159
|
-
const i = this.getHashPath(e);
|
|
3160
|
-
return new URL(`${t.rootUrl}/${i}`, location.origin).toString();
|
|
3161
|
-
}
|
|
3162
|
-
async upload(e, t) {
|
|
3163
|
-
if (t = t || this.writableFileRepo, !t?.canUpload)
|
|
3164
|
-
throw new Error("No writable file repository found");
|
|
3165
|
-
if (!e.file && !e.url && !e.chunk && !e.filekey)
|
|
3166
|
-
throw new Error('At least one of "file", "url", "chunk", or "filekey" is required');
|
|
3167
|
-
return this.ctx.apiService.getClientByFileRepo(t).postWithToken(
|
|
3168
|
-
"csrf",
|
|
3169
|
-
{
|
|
3170
|
-
action: "upload",
|
|
3171
|
-
...e
|
|
3172
|
-
},
|
|
3173
|
-
{ fexiosOptions: { timeout: 0 } }
|
|
3174
|
-
);
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
ve = mn(ft);
|
|
3178
|
-
Y = _n(ve, 0, "WikiFileService", dt, Y);
|
|
3179
|
-
vn(ve, 1, Y);
|
|
3180
|
-
class V extends _t {
|
|
3181
|
-
constructor(e) {
|
|
3182
|
-
super({
|
|
3183
|
-
name: "InPageEdit"
|
|
3184
|
-
}), this.version = "0.15.0", this.Endpoints = Re, this.schema = p, this.config = St(V.DEFAULT_CONFIG, e), this.logger = It({
|
|
3185
|
-
name: "IPE",
|
|
3186
|
-
color: "#33aaff",
|
|
3187
|
-
level: this.config.logLevel
|
|
3188
|
-
}), this.#e();
|
|
3189
|
-
}
|
|
3190
|
-
static {
|
|
3191
|
-
this.DEFAULT_CONFIG = {
|
|
3192
|
-
apiConfigs: {},
|
|
3193
|
-
legacyPreferences: {},
|
|
3194
|
-
logLevel: De.info,
|
|
3195
|
-
storageNamespace: "InPageEdit",
|
|
3196
|
-
autoloadStyles: !0,
|
|
3197
|
-
autoInstallCorePlugins: !0
|
|
3198
|
-
};
|
|
3199
|
-
}
|
|
3200
|
-
async #e() {
|
|
3201
|
-
await this.#i(), this.config.autoInstallCorePlugins && this.#n(), this.#s();
|
|
3202
|
-
}
|
|
3203
|
-
async #i() {
|
|
3204
|
-
this.plugin(X), this.plugin(Lt, this.config.apiConfigs), this.plugin(H), this.plugin(jt), this.plugin(di), this.plugin(G), this.plugin(Ci, { dbName: this.config.storageNamespace }), this.plugin(Y), this.plugin(q), this.plugin(Ii), this.plugin(ge), this.#t([
|
|
3205
|
-
"i18n",
|
|
3206
|
-
"$",
|
|
3207
|
-
"$$",
|
|
3208
|
-
"api",
|
|
3209
|
-
"currentPage",
|
|
3210
|
-
"resourceLoader",
|
|
3211
|
-
"modal",
|
|
3212
|
-
"preferences",
|
|
3213
|
-
"storage",
|
|
3214
|
-
"wikiPage",
|
|
3215
|
-
"wikiTitle",
|
|
3216
|
-
// WikiMetadataService
|
|
3217
|
-
"wiki",
|
|
3218
|
-
"getUrl",
|
|
3219
|
-
"getSciprtUrl",
|
|
3220
|
-
"getMainpageUrl"
|
|
3221
|
-
]);
|
|
3222
|
-
}
|
|
3223
|
-
#t(e) {
|
|
3224
|
-
if (!Array.isArray(e) || e.length === 0) return this;
|
|
3225
|
-
for (const t of e) {
|
|
3226
|
-
const i = this[V.internal][t];
|
|
3227
|
-
i?.type === "service" && (i.builtin = !0);
|
|
3228
|
-
}
|
|
3229
|
-
return this;
|
|
3230
|
-
}
|
|
3231
|
-
// TODO: 这里不应该硬编码,暂时先这样
|
|
3232
|
-
async #n() {
|
|
3233
|
-
[
|
|
3234
|
-
import("./index-C3t-Xj3e.js").then(({ PluginAnalytics: t }) => t),
|
|
3235
|
-
import("./index-Cq8xPcEY.js").then(
|
|
3236
|
-
({ PluginInArticleLinks: t }) => t
|
|
3237
|
-
),
|
|
3238
|
-
import("./index-CbdkXGs7.js").then(({ PluginPluginStore: t }) => t),
|
|
3239
|
-
import("./index-rKL4D_7I.js").then(
|
|
3240
|
-
({ PluginPreferencesUI: t }) => t
|
|
3241
|
-
),
|
|
3242
|
-
import("./index-CS1kidKF.js").then(({ PluginQuickEdit: t }) => t),
|
|
3243
|
-
import("./index-DPA1ptYq.js").then(({ PluginQuickMove: t }) => t),
|
|
3244
|
-
import("./index-mFwJhDwE.js").then(
|
|
3245
|
-
({ PluginQuickPreview: t }) => t
|
|
3246
|
-
),
|
|
3247
|
-
import("./index-B9VO3swL.js").then(({ PluginQuickDiff: t }) => t),
|
|
3248
|
-
import("./index-n5KKWE9v.js").then(
|
|
3249
|
-
({ PluginQuickRedirect: t }) => t
|
|
3250
|
-
),
|
|
3251
|
-
import("./index-FvMu0Ka0.js").then(({ PluginQuickUpload: t }) => t),
|
|
3252
|
-
import("./index-Cb2_vqBl.js").then(({ PluginQuickUsage: t }) => t),
|
|
3253
|
-
import("./index-DjyjqpeO.js").then(({ PluginToolbox: t }) => t)
|
|
3254
|
-
].forEach(async (t) => {
|
|
3255
|
-
this.plugin(await t);
|
|
3256
|
-
});
|
|
3257
|
-
}
|
|
3258
|
-
// TODO: 应该抽象到 PluginTheme 中去,暂时先硬编码
|
|
3259
|
-
async #s() {
|
|
3260
|
-
this.inject(["resourceLoader"], (e) => {
|
|
3261
|
-
this.config.autoloadStyles && e.resourceLoader.loadStyle(import.meta.resolve("./style.css"));
|
|
3262
|
-
});
|
|
3263
|
-
}
|
|
3264
|
-
async withInject(e) {
|
|
3265
|
-
const { promise: t, resolve: i } = Pe();
|
|
3266
|
-
return this.inject(e, (s) => {
|
|
3267
|
-
i(s);
|
|
3268
|
-
}), t;
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
export {
|
|
3272
|
-
De as $,
|
|
3273
|
-
Lt as A,
|
|
3274
|
-
H as C,
|
|
3275
|
-
V as I,
|
|
3276
|
-
di as M,
|
|
3277
|
-
W as N,
|
|
3278
|
-
ue as P,
|
|
3279
|
-
jt as R,
|
|
3280
|
-
It as S,
|
|
3281
|
-
Y as W,
|
|
3282
|
-
Ci as a,
|
|
3283
|
-
b,
|
|
3284
|
-
G as c,
|
|
3285
|
-
q as d,
|
|
3286
|
-
Ii as e,
|
|
3287
|
-
ge as f,
|
|
3288
|
-
oe as m
|
|
3289
|
-
};
|
|
3290
|
-
//# sourceMappingURL=index-CcAmmXbb.js.map
|