@inpageedit/core 0.15.0 → 0.16.1

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.
Files changed (100) hide show
  1. package/dist/{ActionButton-CRjo_l3y.js → ActionButton-B6OUgtHx.js} +2 -2
  2. package/dist/{ActionButton-CRjo_l3y.js.map → ActionButton-B6OUgtHx.js.map} +1 -1
  3. package/dist/CheckBox-Dx3r3LQz.js +13 -0
  4. package/dist/CheckBox-Dx3r3LQz.js.map +1 -0
  5. package/dist/IconQuickDiff-BkbxyY-d.js +29 -0
  6. package/dist/IconQuickDiff-BkbxyY-d.js.map +1 -0
  7. package/dist/IconQuickEdit-BiRYADU_.js +68 -0
  8. package/dist/IconQuickEdit-BiRYADU_.js.map +1 -0
  9. package/dist/IconUpload-Bz4BW_nc.js +27 -0
  10. package/dist/IconUpload-Bz4BW_nc.js.map +1 -0
  11. package/dist/InPageEdit.js +20 -0
  12. package/dist/InPageEdit.js.map +1 -0
  13. package/dist/InputBox-D2ZRTMFP.js +42 -0
  14. package/dist/InputBox-D2ZRTMFP.js.map +1 -0
  15. package/dist/{PluginImagesUsed-Bq_C_rgg.js → PluginImagesUsed-DnPDXczO.js} +7 -7
  16. package/dist/{PluginImagesUsed-Bq_C_rgg.js.map → PluginImagesUsed-DnPDXczO.js.map} +1 -1
  17. package/dist/{PluginPrefSync-DP5NyPnI.js → PluginPrefSync-CDTFyM8g.js} +10 -10
  18. package/dist/{PluginPrefSync-DP5NyPnI.js.map → PluginPrefSync-CDTFyM8g.js.map} +1 -1
  19. package/dist/{PluginStoreApp-_YWpLgfs.js → PluginStoreApp-Bng4DFBZ.js} +4 -4
  20. package/dist/{PluginStoreApp-_YWpLgfs.js.map → PluginStoreApp-Bng4DFBZ.js.map} +1 -1
  21. package/dist/{PluginTemplatesUsed-DS_rHctR.js → PluginTemplatesUsed-oM_VzfbH.js} +12 -12
  22. package/dist/{PluginTemplatesUsed-DS_rHctR.js.map → PluginTemplatesUsed-oM_VzfbH.js.map} +1 -1
  23. package/dist/{index-CM_6yF2v.js → Promise.withResolvers-C4chhLB1.js} +17 -11
  24. package/dist/Promise.withResolvers-C4chhLB1.js.map +1 -0
  25. package/dist/{RadioBox-0UuxlcWZ.js → RadioBox-B0z9YHQg.js} +2 -2
  26. package/dist/{RadioBox-0UuxlcWZ.js.map → RadioBox-B0z9YHQg.js.map} +1 -1
  27. package/dist/components/index.js +75 -46
  28. package/dist/components/index.js.map +1 -1
  29. package/dist/{BasePlugin-BCVSn9QJ.js → core.js} +28 -10
  30. package/dist/core.js.map +1 -0
  31. package/dist/{index-Cq8xPcEY.js → index-1sZXko-X.js} +35 -35
  32. package/dist/index-1sZXko-X.js.map +1 -0
  33. package/dist/{index-B9VO3swL.js → index-42B3CrSO.js} +58 -81
  34. package/dist/index-42B3CrSO.js.map +1 -0
  35. package/dist/{index-n5KKWE9v.js → index-BBUv7Lv6.js} +9 -8
  36. package/dist/{index-n5KKWE9v.js.map → index-BBUv7Lv6.js.map} +1 -1
  37. package/dist/{index-rKL4D_7I.js → index-BcTomMXW.js} +22 -24
  38. package/dist/index-BcTomMXW.js.map +1 -0
  39. package/dist/{index-CbdkXGs7.js → index-BllIuJSJ.js} +13 -17
  40. package/dist/{index-CbdkXGs7.js.map → index-BllIuJSJ.js.map} +1 -1
  41. package/dist/index-Bn6y0Eln.js +793 -0
  42. package/dist/index-Bn6y0Eln.js.map +1 -0
  43. package/dist/index-C0spLL-i.js +1661 -0
  44. package/dist/index-C0spLL-i.js.map +1 -0
  45. package/dist/{index-mFwJhDwE.js → index-CMmEZcB1.js} +11 -11
  46. package/dist/{index-mFwJhDwE.js.map → index-CMmEZcB1.js.map} +1 -1
  47. package/dist/{index-CS1kidKF.js → index-CN7r2e0P.js} +57 -57
  48. package/dist/{index-CS1kidKF.js.map → index-CN7r2e0P.js.map} +1 -1
  49. package/dist/{index-DPA1ptYq.js → index-CkSHCMRN.js} +8 -7
  50. package/dist/{index-DPA1ptYq.js.map → index-CkSHCMRN.js.map} +1 -1
  51. package/dist/index-D7rUF8vA.js +4947 -0
  52. package/dist/index-D7rUF8vA.js.map +1 -0
  53. package/dist/{index-Cb2_vqBl.js → index-DlCbsA25.js} +10 -10
  54. package/dist/{index-Cb2_vqBl.js.map → index-DlCbsA25.js.map} +1 -1
  55. package/dist/{index-DjyjqpeO.js → index-TG_MTC9y.js} +11 -11
  56. package/dist/{index-DjyjqpeO.js.map → index-TG_MTC9y.js.map} +1 -1
  57. package/dist/{index-C3t-Xj3e.js → index-mf_pX14E.js} +10 -10
  58. package/dist/{index-C3t-Xj3e.js.map → index-mf_pX14E.js.map} +1 -1
  59. package/dist/{index-DD5CVCfD.js → index-z_qDGCMT.js} +2 -2
  60. package/dist/{index-DD5CVCfD.js.map → index-z_qDGCMT.js.map} +1 -1
  61. package/dist/index.d.ts +37405 -1321
  62. package/dist/index.js +24 -26
  63. package/dist/index.js.map +1 -1
  64. package/dist/{makeCallable-LDU0xZMJ.js → makeCallable-Cg4zUG4c.js} +2 -2
  65. package/dist/{makeCallable-LDU0xZMJ.js.map → makeCallable-Cg4zUG4c.js.map} +1 -1
  66. package/dist/models/index.js +7 -7
  67. package/dist/models/index.js.map +1 -1
  68. package/dist/plugins/index.js +12 -12
  69. package/dist/services/index.js +5 -4
  70. package/dist/style.css +1 -1
  71. package/dist/{vueHooks-l04s8cIl.js → vueHooks-Bs93iP61.js} +1519 -1492
  72. package/dist/vueHooks-Bs93iP61.js.map +1 -0
  73. package/lib/index.umd.js +22 -18
  74. package/lib/index.umd.js.map +1 -1
  75. package/lib/style.css +1 -1
  76. package/package.json +37 -28
  77. package/dist/BasePlugin-BCVSn9QJ.js.map +0 -1
  78. package/dist/IconQuickEdit-CMCQncyj.js +0 -27
  79. package/dist/IconQuickEdit-CMCQncyj.js.map +0 -1
  80. package/dist/InputBox-CZ1v4_l3.js +0 -50
  81. package/dist/InputBox-CZ1v4_l3.js.map +0 -1
  82. package/dist/Preferences-DqtjY7XU.js +0 -1541
  83. package/dist/Preferences-DqtjY7XU.js.map +0 -1
  84. package/dist/WatchlistAction-BbNAyryN.js +0 -5
  85. package/dist/WatchlistAction-BbNAyryN.js.map +0 -1
  86. package/dist/browser-DR-yCqVg.js +0 -1160
  87. package/dist/browser-DR-yCqVg.js.map +0 -1
  88. package/dist/index-B9VO3swL.js.map +0 -1
  89. package/dist/index-CG38LlAh.js +0 -46
  90. package/dist/index-CG38LlAh.js.map +0 -1
  91. package/dist/index-CM_6yF2v.js.map +0 -1
  92. package/dist/index-CcAmmXbb.js +0 -3290
  93. package/dist/index-CcAmmXbb.js.map +0 -1
  94. package/dist/index-Cq8xPcEY.js.map +0 -1
  95. package/dist/index-DVvsTsLI.js +0 -505
  96. package/dist/index-DVvsTsLI.js.map +0 -1
  97. package/dist/index-FvMu0Ka0.js +0 -342
  98. package/dist/index-FvMu0Ka0.js.map +0 -1
  99. package/dist/index-rKL4D_7I.js.map +0 -1
  100. package/dist/vueHooks-l04s8cIl.js.map +0 -1
@@ -0,0 +1,4947 @@
1
+ import { W as bi, d as vi, e as _i, r as xi, u as ki, c as Si, a as $i, f as Ei } from "./index-C0spLL-i.js";
2
+ import { j as N, P as Ci, p as bt } from "./Promise.withResolvers-C4chhLB1.js";
3
+ var Ai = Object.defineProperty, S = (i, e) => Ai(i, "name", { value: e, configurable: !0 });
4
+ function Oi() {
5
+ }
6
+ S(Oi, "noop");
7
+ function I(i) {
8
+ return i == null;
9
+ }
10
+ S(I, "isNullable");
11
+ function Pi(i) {
12
+ return !I(i);
13
+ }
14
+ S(Pi, "isNonNullable");
15
+ function he(i) {
16
+ return i && typeof i == "object" && !Array.isArray(i);
17
+ }
18
+ S(he, "isPlainObject");
19
+ function vt(i, e) {
20
+ return Object.fromEntries(Object.entries(i).filter(([t, r]) => e(t, r)));
21
+ }
22
+ S(vt, "filterKeys");
23
+ function K(i, e) {
24
+ return Object.fromEntries(Object.entries(i).map(([t, r]) => [t, e(r, t)]));
25
+ }
26
+ S(K, "mapValues");
27
+ function _t(i, e, t) {
28
+ if (!e) return { ...i };
29
+ const r = {};
30
+ for (const n of e)
31
+ (t || i[n] !== void 0) && (r[n] = i[n]);
32
+ return r;
33
+ }
34
+ S(_t, "pick");
35
+ function Ii(i, e) {
36
+ if (!e) return { ...i };
37
+ const t = { ...i };
38
+ for (const r of e)
39
+ Reflect.deleteProperty(t, r);
40
+ return t;
41
+ }
42
+ S(Ii, "omit");
43
+ function j(i, e, t) {
44
+ return Object.defineProperty(i, e, { writable: !0, value: t, enumerable: !1 });
45
+ }
46
+ S(j, "defineProperty");
47
+ function Li(i, e) {
48
+ return e.every((t) => i.includes(t));
49
+ }
50
+ S(Li, "contain");
51
+ function Ri(i, e) {
52
+ return i.filter((t) => e.includes(t));
53
+ }
54
+ S(Ri, "intersection");
55
+ function ji(i, e) {
56
+ return i.filter((t) => !e.includes(t));
57
+ }
58
+ S(ji, "difference");
59
+ function Di(i, e) {
60
+ return Array.from(/* @__PURE__ */ new Set([...i, ...e]));
61
+ }
62
+ S(Di, "union");
63
+ function Ti(i) {
64
+ return [...new Set(i)];
65
+ }
66
+ S(Ti, "deduplicate");
67
+ function W(i, e) {
68
+ const t = i?.indexOf(e);
69
+ return t >= 0 ? (i.splice(t, 1), !0) : !1;
70
+ }
71
+ S(W, "remove");
72
+ function Ni(i) {
73
+ return Array.isArray(i) ? i : I(i) ? [] : [i];
74
+ }
75
+ S(Ni, "makeArray");
76
+ function G(i, e) {
77
+ return arguments.length === 1 ? (t) => G(i, t) : i in globalThis && e instanceof globalThis[i] || Object.prototype.toString.call(e).slice(8, -1) === i;
78
+ }
79
+ S(G, "is");
80
+ function se(i) {
81
+ return G("ArrayBuffer", i) || G("SharedArrayBuffer", i);
82
+ }
83
+ S(se, "isArrayBufferLike");
84
+ function xt(i) {
85
+ return se(i) || ArrayBuffer.isView(i);
86
+ }
87
+ S(xt, "isArrayBufferSource");
88
+ var B;
89
+ ((i) => {
90
+ i.is = se, i.isSource = xt;
91
+ function e(o) {
92
+ return ArrayBuffer.isView(o) ? o.buffer.slice(o.byteOffset, o.byteOffset + o.byteLength) : o;
93
+ }
94
+ i.fromSource = e, S(e, "fromSource");
95
+ function t(o) {
96
+ if (typeof Buffer < "u")
97
+ return Buffer.from(o).toString("base64");
98
+ let a = "";
99
+ const f = new Uint8Array(o);
100
+ for (let u = 0; u < f.byteLength; u++)
101
+ a += String.fromCharCode(f[u]);
102
+ return btoa(a);
103
+ }
104
+ i.toBase64 = t, S(t, "toBase64");
105
+ function r(o) {
106
+ return typeof Buffer < "u" ? e(Buffer.from(o, "base64")) : Uint8Array.from(atob(o), (a) => a.charCodeAt(0));
107
+ }
108
+ i.fromBase64 = r, S(r, "fromBase64");
109
+ function n(o) {
110
+ return typeof Buffer < "u" ? Buffer.from(o).toString("hex") : Array.from(new Uint8Array(o), (a) => a.toString(16).padStart(2, "0")).join("");
111
+ }
112
+ i.toHex = n, S(n, "toHex");
113
+ function s(o) {
114
+ if (typeof Buffer < "u") return e(Buffer.from(o, "hex"));
115
+ const a = o.length % 2 === 0 ? o : o.slice(0, o.length - 1), f = [];
116
+ for (let u = 0; u < a.length; u += 2)
117
+ f.push(parseInt(`${a[u]}${a[u + 1]}`, 16));
118
+ return Uint8Array.from(f).buffer;
119
+ }
120
+ i.fromHex = s, S(s, "fromHex");
121
+ })(B || (B = {}));
122
+ B.fromBase64;
123
+ B.toBase64;
124
+ B.fromHex;
125
+ B.toHex;
126
+ function ue(i, e = /* @__PURE__ */ new Map()) {
127
+ if (!i || typeof i != "object") return i;
128
+ if (G("Date", i)) return new Date(i.valueOf());
129
+ if (G("RegExp", i)) return new RegExp(i.source, i.flags);
130
+ if (se(i)) return i.slice(0);
131
+ if (ArrayBuffer.isView(i)) return i.buffer.slice(i.byteOffset, i.byteOffset + i.byteLength);
132
+ const t = e.get(i);
133
+ if (t) return t;
134
+ if (Array.isArray(i)) {
135
+ const n = [];
136
+ return e.set(i, n), i.forEach((s, o) => {
137
+ n[o] = Reflect.apply(ue, null, [s, e]);
138
+ }), n;
139
+ }
140
+ const r = Object.create(Object.getPrototypeOf(i));
141
+ e.set(i, r);
142
+ for (const n of Reflect.ownKeys(i)) {
143
+ const s = { ...Reflect.getOwnPropertyDescriptor(i, n) };
144
+ "value" in s && (s.value = Reflect.apply(ue, null, [s.value, e])), Reflect.defineProperty(r, n, s);
145
+ }
146
+ return r;
147
+ }
148
+ S(ue, "clone");
149
+ function Y(i, e, t) {
150
+ if (i === e || !t && I(i) && I(e)) return !0;
151
+ if (typeof i != typeof e || typeof i != "object" || !i || !e) return !1;
152
+ function r(n, s) {
153
+ return n(i) ? n(e) ? s(i, e) : !1 : n(e) ? !1 : void 0;
154
+ }
155
+ return S(r, "check"), r(Array.isArray, (n, s) => n.length === s.length && n.every((o, a) => Y(o, s[a]))) ?? r(G("Date"), (n, s) => n.valueOf() === s.valueOf()) ?? r(G("RegExp"), (n, s) => n.source === s.source && n.flags === s.flags) ?? r(se, (n, s) => {
156
+ if (n.byteLength !== s.byteLength) return !1;
157
+ const o = new Uint8Array(n), a = new Uint8Array(s);
158
+ for (let f = 0; f < o.length; f++)
159
+ if (o[f] !== a[f]) return !1;
160
+ return !0;
161
+ }) ?? Object.keys({ ...i, ...e }).every((n) => Y(i[n], e[n], t));
162
+ }
163
+ S(Y, "deepEqual");
164
+ function Mi(i) {
165
+ return i.charAt(0).toUpperCase() + i.slice(1);
166
+ }
167
+ S(Mi, "capitalize");
168
+ function Bi(i) {
169
+ return i.charAt(0).toLowerCase() + i.slice(1);
170
+ }
171
+ S(Bi, "uncapitalize");
172
+ function Ui(i) {
173
+ return i.replace(/[_-][a-z]/g, (e) => e.slice(1).toUpperCase());
174
+ }
175
+ S(Ui, "camelCase");
176
+ function Me(i, e, t) {
177
+ const r = [];
178
+ let n = 0;
179
+ for (let s = 0; s < i.length; s++) {
180
+ const o = i.charCodeAt(s);
181
+ if (o >= 65 && o <= 90) {
182
+ if (n === 1) {
183
+ const a = i.charCodeAt(s + 1);
184
+ a >= 97 && a <= 122 && r.push(t), r.push(o + 32);
185
+ } else
186
+ n !== 0 && r.push(t), r.push(o + 32);
187
+ n = 1;
188
+ } else o >= 97 && o <= 122 ? (r.push(o), n = 2) : e.includes(o) ? (n !== 0 && r.push(t), n = 0) : r.push(o);
189
+ }
190
+ return String.fromCharCode(...r);
191
+ }
192
+ S(Me, "tokenize");
193
+ function Fi(i) {
194
+ return Me(i, [45, 95], 45);
195
+ }
196
+ S(Fi, "paramCase");
197
+ function zi(i) {
198
+ return Me(i, [45, 95], 95);
199
+ }
200
+ S(zi, "snakeCase");
201
+ function Hi(i) {
202
+ return typeof i != "string" ? `[${i.toString()}]` : /^[a-z_$][\w$]*$/i.test(i) ? `.${i}` : `[${JSON.stringify(i)}]`;
203
+ }
204
+ S(Hi, "formatProperty");
205
+ function kt(i) {
206
+ return i.replace(/\/$/, "");
207
+ }
208
+ S(kt, "trimSlash");
209
+ function Ki(i) {
210
+ return i.startsWith("/") || (i = "/" + i), kt(i);
211
+ }
212
+ S(Ki, "sanitize");
213
+ var at;
214
+ ((i) => {
215
+ i.millisecond = 1, i.second = 1e3, i.minute = i.second * 60, i.hour = i.minute * 60, i.day = i.hour * 24, i.week = i.day * 7;
216
+ let e = (/* @__PURE__ */ new Date()).getTimezoneOffset();
217
+ function t(g) {
218
+ e = g;
219
+ }
220
+ i.setTimezoneOffset = t, S(t, "setTimezoneOffset");
221
+ function r() {
222
+ return e;
223
+ }
224
+ i.getTimezoneOffset = r, S(r, "getTimezoneOffset");
225
+ function n(g = /* @__PURE__ */ new Date(), w) {
226
+ return typeof g == "number" && (g = new Date(g)), w === void 0 && (w = e), Math.floor((g.valueOf() / i.minute - w) / 1440);
227
+ }
228
+ i.getDateNumber = n, S(n, "getDateNumber");
229
+ function s(g, w) {
230
+ const O = new Date(g * i.day);
231
+ return w === void 0 && (w = e), new Date(+O + w * i.minute);
232
+ }
233
+ i.fromDateNumber = s, S(s, "fromDateNumber");
234
+ const o = /\d+(?:\.\d+)?/.source, a = new RegExp(`^${[
235
+ "w(?:eek(?:s)?)?",
236
+ "d(?:ay(?:s)?)?",
237
+ "h(?:our(?:s)?)?",
238
+ "m(?:in(?:ute)?(?:s)?)?",
239
+ "s(?:ec(?:ond)?(?:s)?)?"
240
+ ].map((g) => `(${o}${g})?`).join("")}$`);
241
+ function f(g) {
242
+ const w = a.exec(g);
243
+ return w ? (parseFloat(w[1]) * i.week || 0) + (parseFloat(w[2]) * i.day || 0) + (parseFloat(w[3]) * i.hour || 0) + (parseFloat(w[4]) * i.minute || 0) + (parseFloat(w[5]) * i.second || 0) : 0;
244
+ }
245
+ i.parseTime = f, S(f, "parseTime");
246
+ function u(g) {
247
+ const w = f(g);
248
+ return w ? g = Date.now() + w : /^\d{1,2}(:\d{1,2}){1,2}$/.test(g) ? g = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${g}` : /^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(g) && (g = `${(/* @__PURE__ */ new Date()).getFullYear()}-${g}`), g ? new Date(g) : /* @__PURE__ */ new Date();
249
+ }
250
+ i.parseDate = u, S(u, "parseDate");
251
+ function p(g) {
252
+ const w = Math.abs(g);
253
+ return w >= i.day - i.hour / 2 ? Math.round(g / i.day) + "d" : w >= i.hour - i.minute / 2 ? Math.round(g / i.hour) + "h" : w >= i.minute - i.second / 2 ? Math.round(g / i.minute) + "m" : w >= i.second ? Math.round(g / i.second) + "s" : g + "ms";
254
+ }
255
+ i.format = p, S(p, "format");
256
+ function y(g, w = 2) {
257
+ return g.toString().padStart(w, "0");
258
+ }
259
+ i.toDigits = y, S(y, "toDigits");
260
+ function _(g, w = /* @__PURE__ */ new Date()) {
261
+ return g.replace("yyyy", w.getFullYear().toString()).replace("yy", w.getFullYear().toString().slice(2)).replace("MM", y(w.getMonth() + 1)).replace("dd", y(w.getDate())).replace("hh", y(w.getHours())).replace("mm", y(w.getMinutes())).replace("ss", y(w.getSeconds())).replace("SSS", y(w.getMilliseconds(), 3));
262
+ }
263
+ i.template = _, S(_, "template");
264
+ })(at || (at = {}));
265
+ var qi = Object.defineProperty, k = (i, e) => qi(i, "name", { value: e, configurable: !0 }), b = {
266
+ // internal symbols
267
+ shadow: /* @__PURE__ */ Symbol.for("cordis.shadow"),
268
+ receiver: /* @__PURE__ */ Symbol.for("cordis.receiver"),
269
+ original: /* @__PURE__ */ Symbol.for("cordis.original"),
270
+ // context symbols
271
+ store: /* @__PURE__ */ Symbol.for("cordis.store"),
272
+ events: /* @__PURE__ */ Symbol.for("cordis.events"),
273
+ static: /* @__PURE__ */ Symbol.for("cordis.static"),
274
+ filter: /* @__PURE__ */ Symbol.for("cordis.filter"),
275
+ expose: /* @__PURE__ */ Symbol.for("cordis.expose"),
276
+ isolate: /* @__PURE__ */ Symbol.for("cordis.isolate"),
277
+ internal: /* @__PURE__ */ Symbol.for("cordis.internal"),
278
+ intercept: /* @__PURE__ */ Symbol.for("cordis.intercept"),
279
+ // service symbols
280
+ setup: /* @__PURE__ */ Symbol.for("cordis.setup"),
281
+ invoke: /* @__PURE__ */ Symbol.for("cordis.invoke"),
282
+ extend: /* @__PURE__ */ Symbol.for("cordis.extend"),
283
+ tracker: /* @__PURE__ */ Symbol.for("cordis.tracker"),
284
+ provide: /* @__PURE__ */ Symbol.for("cordis.provide"),
285
+ immediate: /* @__PURE__ */ Symbol.for("cordis.immediate")
286
+ }, Wi = function* () {
287
+ }.constructor, ct = async function* () {
288
+ }.constructor;
289
+ function Be(i) {
290
+ return !(!i.prototype || i instanceof Wi || ct !== Function && i instanceof ct);
291
+ }
292
+ k(Be, "isConstructor");
293
+ function oe(i, e) {
294
+ const t = i.Config || i.schema;
295
+ return t && i.schema !== !1 && (e = t(e)), e ?? {};
296
+ }
297
+ k(oe, "resolveConfig");
298
+ function St(i) {
299
+ return [Map, Set, Date, Promise].some((e) => i instanceof e);
300
+ }
301
+ k(St, "isUnproxyable");
302
+ function Ue(i, e) {
303
+ if (i === Object.prototype) return e;
304
+ const t = Object.create(Ue(Object.getPrototypeOf(i), e));
305
+ for (const r of Reflect.ownKeys(i))
306
+ Object.defineProperty(t, r, Object.getOwnPropertyDescriptor(i, r));
307
+ return t;
308
+ }
309
+ k(Ue, "joinPrototype");
310
+ function Fe(i) {
311
+ return i && (typeof i == "object" || typeof i == "function");
312
+ }
313
+ k(Fe, "isObject");
314
+ function U(i, e, t) {
315
+ if (!Fe(e)) return e;
316
+ if (Object.hasOwn(e, b.shadow))
317
+ return Object.getPrototypeOf(e);
318
+ const r = e[b.tracker];
319
+ return r ? _e(i, e, r, t) : e;
320
+ }
321
+ k(U, "getTraceable");
322
+ function re(i, e) {
323
+ return e ? new Proxy(i, {
324
+ get: /* @__PURE__ */ k((t, r, n) => r in e && r !== "constructor" ? Reflect.get(e, r, n) : Reflect.get(t, r, n), "get"),
325
+ set: /* @__PURE__ */ k((t, r, n, s) => r in e && r !== "constructor" ? Reflect.set(e, r, n, s) : Reflect.set(t, r, n, s), "set")
326
+ }) : i;
327
+ }
328
+ k(re, "withProps");
329
+ function fe(i, e, t) {
330
+ return re(i, Object.defineProperty(/* @__PURE__ */ Object.create(null), e, {
331
+ value: t,
332
+ writable: !1
333
+ }));
334
+ }
335
+ k(fe, "withProp");
336
+ function Ce(i, e, t, r) {
337
+ if (!t) return r;
338
+ const n = Reflect.getOwnPropertyDescriptor(e, t)?.value;
339
+ return n ? fe(r, t, i.extend({ [b.shadow]: n })) : r;
340
+ }
341
+ k(Ce, "createShadow");
342
+ function $t(i, e, t, r) {
343
+ return new Proxy(e, {
344
+ apply: /* @__PURE__ */ k((n, s, o) => (s === t && (s = r), o = o.map((a) => typeof a != "function" || a[b.original] ? a : new Proxy(a, {
345
+ get: /* @__PURE__ */ k((f, u, p) => {
346
+ if (u === b.original) return f;
347
+ const y = Reflect.get(f, u, p);
348
+ return u === "toString" && y === Function.prototype.toString ? function(..._) {
349
+ return Reflect.apply(y, this === p ? f : this, _);
350
+ } : y;
351
+ }, "get"),
352
+ apply: /* @__PURE__ */ k((f, u, p) => Reflect.apply(f, U(i, u), p.map((y) => U(i, y))), "apply"),
353
+ construct: /* @__PURE__ */ k((f, u, p) => Reflect.construct(f, u.map((y) => U(i, y)), p), "construct")
354
+ })), U(i, Reflect.apply(n, s, o))), "apply")
355
+ });
356
+ }
357
+ k($t, "createShadowMethod");
358
+ function _e(i, e, t, r) {
359
+ i[b.shadow] && (i = Object.getPrototypeOf(i));
360
+ const n = new Proxy(e, {
361
+ get: /* @__PURE__ */ k((s, o, a) => {
362
+ if (o === b.original) return s;
363
+ if (o === t.property) return i;
364
+ if (typeof o == "symbol")
365
+ return Reflect.get(s, o, a);
366
+ if (t.associate && i[b.internal][`${t.associate}.${o}`])
367
+ return Reflect.get(i, `${t.associate}.${o}`, fe(i, b.receiver, a));
368
+ const f = Ce(i, s, t.property, a), u = Reflect.get(s, o, f), p = u?.[b.tracker];
369
+ return p ? _e(i, u, p) : !r && typeof u == "function" ? $t(i, u, a, f) : u;
370
+ }, "get"),
371
+ set: /* @__PURE__ */ k((s, o, a, f) => {
372
+ if (o === b.original || o === t.property) return !1;
373
+ if (typeof o == "symbol")
374
+ return Reflect.set(s, o, a, f);
375
+ if (t.associate && i[b.internal][`${t.associate}.${o}`])
376
+ return Reflect.set(i, `${t.associate}.${o}`, a, fe(i, b.receiver, f));
377
+ const u = Ce(i, s, t.property, f);
378
+ return Reflect.set(s, o, a, u);
379
+ }, "set"),
380
+ apply: /* @__PURE__ */ k((s, o, a) => ze(n, s, o, a), "apply")
381
+ });
382
+ return n;
383
+ }
384
+ k(_e, "createTraceable");
385
+ function ze(i, e, t, r) {
386
+ return e[b.invoke] ? e[b.invoke].apply(i, r) : Reflect.apply(e, t, r);
387
+ }
388
+ k(ze, "applyTraceable");
389
+ function Ae(i, e, t) {
390
+ const r = /* @__PURE__ */ k(function(...n) {
391
+ const s = _e(r.ctx, r, t);
392
+ return ze(s, r, this, n);
393
+ }, "self");
394
+ return j(r, "name", i), Object.setPrototypeOf(r, e);
395
+ }
396
+ k(Ae, "createCallable");
397
+ var Gi = class Q {
398
+ constructor(e) {
399
+ this.ctx = e, j(this, b.tracker, {
400
+ associate: "reflect",
401
+ property: "ctx"
402
+ }), this._mixin("reflect", ["get", "set", "provide", "accessor", "mixin", "alias"]), this._mixin("scope", ["config", "runtime", "effect", "collect", "accept", "decline"]), this._mixin("registry", ["using", "inject", "plugin"]), this._mixin("lifecycle", ["on", "once", "parallel", "emit", "serial", "bail", "start", "stop"]);
403
+ }
404
+ static {
405
+ k(this, "ReflectService");
406
+ }
407
+ static resolveInject(e, t) {
408
+ let r = e[b.internal][t];
409
+ for (; r?.type === "alias"; )
410
+ t = r.name, r = e[b.internal][t];
411
+ return [t, r];
412
+ }
413
+ static checkInject(e, t, r) {
414
+ if (e = e[b.shadow] ?? e, ["prototype", "then", "registry", "lifecycle"].includes(t) || t[0] === "$" || t[0] === "_" || !e.runtime.plugin || e.bail(e, "internal/inject", t)) return;
415
+ const n = r.stack.split(`
416
+ `);
417
+ n.splice(1, 1), r.stack = n.join(`
418
+ `), e.emit(e, "internal/warning", r);
419
+ }
420
+ static handler = {
421
+ get: /* @__PURE__ */ k((e, t, r) => {
422
+ if (typeof t != "string") return Reflect.get(e, t, r);
423
+ if (Reflect.has(e, t))
424
+ return U(r, Reflect.get(e, t, r), !0);
425
+ const [n, s] = Q.resolveInject(e, t), o = new Error(`property ${n} is not registered, declare it as \`inject\` to suppress this warning`);
426
+ return s ? s.type === "accessor" ? s.get.call(r, r[b.receiver]) : (s.builtin || Q.checkInject(r, n, o), r.reflect.get(n)) : (Q.checkInject(r, n, o), Reflect.get(e, n, r));
427
+ }, "get"),
428
+ set: /* @__PURE__ */ k((e, t, r, n) => {
429
+ if (typeof t != "string") return Reflect.set(e, t, r, n);
430
+ const [s, o] = Q.resolveInject(e, t);
431
+ return o ? o.type === "accessor" ? o.set ? o.set.call(n, r, n[b.receiver]) : !1 : (n.reflect.set(s, r), !0) : Reflect.set(e, s, r, n);
432
+ }, "set"),
433
+ has: /* @__PURE__ */ k((e, t) => {
434
+ if (typeof t != "string") return Reflect.has(e, t);
435
+ if (Reflect.has(e, t)) return !0;
436
+ const [, r] = Q.resolveInject(e, t);
437
+ return !!r;
438
+ }, "has")
439
+ };
440
+ get(e) {
441
+ if (this.ctx[b.internal][e]?.type !== "service") return;
442
+ const r = this.ctx[b.isolate][e], n = this.ctx[b.store][r]?.value;
443
+ return U(this.ctx, n);
444
+ }
445
+ set(e, t) {
446
+ this.provide(e);
447
+ const r = this.ctx[b.isolate][e], n = this.ctx[b.store][r]?.value;
448
+ t ??= void 0;
449
+ let s = /* @__PURE__ */ k(() => {
450
+ }, "dispose");
451
+ if (n === t) return s;
452
+ if (!I(t) && !I(n))
453
+ throw new Error(`service ${e} has been registered`);
454
+ const o = this.ctx;
455
+ I(t) || (s = o.effect(() => () => {
456
+ o.set(e, void 0);
457
+ })), St(t) && o.emit(o, "internal/warning", new Error(`service ${e} is an unproxyable object, which may lead to unexpected behavior`));
458
+ const a = Object.create(o);
459
+ return a[b.filter] = (f) => o[b.isolate][e] === f[b.isolate][e], o.emit(a, "internal/before-service", e, t), o[b.store][r] = { value: t, source: o }, o.emit(a, "internal/service", e, n), s;
460
+ }
461
+ provide(e, t, r) {
462
+ const n = this.ctx.root[b.internal];
463
+ if (e in n) return;
464
+ const s = Symbol(e);
465
+ n[e] = { type: "service", builtin: r }, this.ctx.root[b.isolate][e] = s, Fe(t) && (this.ctx[b.store][s] = { value: t, source: null }, j(t, b.tracker, {
466
+ associate: e,
467
+ property: "ctx"
468
+ }));
469
+ }
470
+ _accessor(e, t) {
471
+ const r = this.ctx.root[b.internal];
472
+ return e in r ? () => {
473
+ } : (r[e] = { type: "accessor", ...t }, () => delete this.ctx.root[b.isolate][e]);
474
+ }
475
+ accessor(e, t) {
476
+ this.ctx.scope.effect(() => this._accessor(e, t));
477
+ }
478
+ alias(e, t) {
479
+ const r = this.ctx.root[b.internal];
480
+ if (!(e in r))
481
+ for (const n of t)
482
+ r[n] ||= { type: "alias", name: e };
483
+ }
484
+ _mixin(e, t) {
485
+ const r = Array.isArray(t) ? t.map((o) => [o, o]) : Object.entries(t), n = typeof e == "string" ? (o) => o[e] : () => e, s = r.map(([o, a]) => this._accessor(a, {
486
+ get(f) {
487
+ const u = n(this);
488
+ if (I(u)) return u;
489
+ const p = f ? re(f, u) : u, y = Reflect.get(u, o, p);
490
+ return typeof y != "function" ? y : y.bind(p ?? u);
491
+ },
492
+ set(f, u) {
493
+ const p = n(this), y = u ? re(u, p) : p;
494
+ return Reflect.set(p, o, f, y);
495
+ }
496
+ }));
497
+ return () => s.forEach((o) => o());
498
+ }
499
+ mixin(e, t) {
500
+ this.ctx.scope.effect(() => this._mixin(e, t));
501
+ }
502
+ trace(e) {
503
+ return U(this.ctx, e);
504
+ }
505
+ bind(e) {
506
+ return new Proxy(e, {
507
+ apply: /* @__PURE__ */ k((t, r, n) => t.apply(this.trace(r), n.map((s) => this.trace(s))), "apply")
508
+ });
509
+ }
510
+ }, Oe = Gi;
511
+ function Pe(i) {
512
+ return i !== null && i !== !1 && i !== void 0;
513
+ }
514
+ k(Pe, "isBailed");
515
+ var Vi = class {
516
+ constructor(i) {
517
+ this.ctx = i, j(this, b.tracker, {
518
+ associate: "lifecycle",
519
+ property: "ctx"
520
+ }), j(this.on("internal/listener", function(t, r, n) {
521
+ const s = n.prepend ? "unshift" : "push";
522
+ if (t === "ready")
523
+ return this.lifecycle.isActive ? (this.scope.ensure(async () => r()), () => !1) : void 0;
524
+ if (t === "dispose")
525
+ return this.scope.disposables[s](r), j(r, "name", "event <dispose>"), () => W(this.scope.disposables, r);
526
+ if (t === "fork")
527
+ return this.scope.runtime.forkables[s](r), this.scope.collect("event <fork>", () => W(this.scope.runtime.forkables, r));
528
+ }), M.static, i.scope);
529
+ for (const t of ["info", "error", "warning"])
530
+ j(this.on(`internal/${t}`, (r, ...n) => {
531
+ this._hooks[`internal/${t}`].length > 1;
532
+ }), M.static, i.scope);
533
+ j(this.on("internal/before-service", function(t) {
534
+ for (const r of this.registry.values()) {
535
+ if (!r.inject[t]?.required) continue;
536
+ const n = r.isReusable ? r.children : [r];
537
+ for (const s of n)
538
+ this[b.filter](s.ctx) && (s.updateStatus(), s.reset());
539
+ }
540
+ }, { global: !0 }), M.static, i.scope), j(this.on("internal/service", function(t) {
541
+ for (const r of this.registry.values()) {
542
+ if (!r.inject[t]?.required) continue;
543
+ const n = r.isReusable ? r.children : [r];
544
+ for (const s of n)
545
+ this[b.filter](s.ctx) && s.start();
546
+ }
547
+ }, { global: !0 }), M.static, i.scope);
548
+ const e = /* @__PURE__ */ k((t, r) => {
549
+ if (!t.runtime.plugin) return !1;
550
+ for (const n in t.runtime.inject)
551
+ if (r === Oe.resolveInject(t.ctx, n)[0]) return !0;
552
+ return e(t.parent.scope, r);
553
+ }, "checkInject");
554
+ j(this.on("internal/inject", function(t) {
555
+ return e(this.scope, t);
556
+ }, { global: !0 }), M.static, i.scope);
557
+ }
558
+ static {
559
+ k(this, "Lifecycle");
560
+ }
561
+ isActive = !1;
562
+ _tasks = /* @__PURE__ */ new Set();
563
+ _hooks = {};
564
+ async flush() {
565
+ for (; this._tasks.size; )
566
+ await Promise.all(Array.from(this._tasks));
567
+ }
568
+ filterHooks(i, e) {
569
+ return e = U(this.ctx, e), i.slice().filter((t) => {
570
+ const r = e?.[M.filter];
571
+ return t.global || !r || r.call(e, t.ctx);
572
+ });
573
+ }
574
+ *dispatch(i, e) {
575
+ const t = typeof e[0] == "object" || typeof e[0] == "function" ? e.shift() : null, r = e.shift();
576
+ r !== "internal/event" && this.emit("internal/event", i, r, e, t);
577
+ for (const n of this.filterHooks(this._hooks[r] || [], t))
578
+ yield n.callback.apply(t, e);
579
+ }
580
+ async parallel(...i) {
581
+ await Promise.all(this.dispatch("emit", i));
582
+ }
583
+ emit(...i) {
584
+ Array.from(this.dispatch("emit", i));
585
+ }
586
+ async serial(...i) {
587
+ for await (const e of this.dispatch("serial", i))
588
+ if (Pe(e)) return e;
589
+ }
590
+ bail(...i) {
591
+ for (const e of this.dispatch("bail", i))
592
+ if (Pe(e)) return e;
593
+ }
594
+ register(i, e, t, r) {
595
+ const n = r.prepend ? "unshift" : "push";
596
+ return e[n]({ ctx: this.ctx, callback: t, ...r }), this.ctx.state.collect(i, () => this.unregister(e, t));
597
+ }
598
+ unregister(i, e) {
599
+ const t = i.findIndex((r) => r.callback === e);
600
+ if (t >= 0)
601
+ return i.splice(t, 1), !0;
602
+ }
603
+ on(i, e, t) {
604
+ typeof t != "object" && (t = { prepend: t }), this.ctx.scope.assertActive(), e = this.ctx.reflect.bind(e);
605
+ const r = this.bail(this.ctx, "internal/listener", i, e, t);
606
+ if (r) return r;
607
+ const n = this._hooks[i] ||= [], s = typeof i == "string" ? `event <${i}>` : "event (Symbol)";
608
+ return this.register(s, n, e, t);
609
+ }
610
+ once(i, e, t) {
611
+ const r = this.on(i, function(...n) {
612
+ return r(), e.apply(this, n);
613
+ }, t);
614
+ return r;
615
+ }
616
+ async start() {
617
+ this.isActive = !0;
618
+ const i = this._hooks.ready || [];
619
+ for (; i.length; ) {
620
+ const { ctx: e, callback: t } = i.shift();
621
+ e.scope.ensure(async () => t());
622
+ }
623
+ await this.flush();
624
+ }
625
+ async stop() {
626
+ this.isActive = !1, this.ctx.scope.reset();
627
+ }
628
+ }, Yi = Vi, Ji = /* @__PURE__ */ ((i) => (i[i.PENDING = 0] = "PENDING", i[i.LOADING = 1] = "LOADING", i[i.ACTIVE = 2] = "ACTIVE", i[i.FAILED = 3] = "FAILED", i[i.DISPOSED = 4] = "DISPOSED", i))(Ji || {}), Ie = class Et extends Error {
629
+ constructor(e, t) {
630
+ super(t ?? Et.Code[e]), this.code = e;
631
+ }
632
+ static {
633
+ k(this, "CordisError");
634
+ }
635
+ };
636
+ ((i) => {
637
+ i.Code = {
638
+ INACTIVE_EFFECT: "cannot create effect on inactive context"
639
+ };
640
+ })(Ie || (Ie = {}));
641
+ var Ct = class {
642
+ constructor(i, e) {
643
+ this.parent = i, this.config = e, this.uid = i.registry ? i.registry.counter : 0, this.ctx = this.context = i.extend({ scope: this }), this.proxy = new Proxy({}, {
644
+ get: /* @__PURE__ */ k((t, r) => Reflect.get(this.config, r), "get")
645
+ });
646
+ }
647
+ static {
648
+ k(this, "EffectScope");
649
+ }
650
+ uid;
651
+ ctx;
652
+ disposables = [];
653
+ error;
654
+ status = 0;
655
+ isActive = !1;
656
+ // Same as `this.ctx`, but with a more specific type.
657
+ context;
658
+ proxy;
659
+ acceptors = [];
660
+ tasks = /* @__PURE__ */ new Set();
661
+ hasError = !1;
662
+ get _config() {
663
+ return this.runtime.isReactive ? this.proxy : this.config;
664
+ }
665
+ assertActive() {
666
+ if (!(this.uid !== null || this.isActive))
667
+ throw new Ie("INACTIVE_EFFECT");
668
+ }
669
+ effect(i, e) {
670
+ this.assertActive();
671
+ const t = Be(i) ? new i(this.ctx, e) : i(this.ctx, e);
672
+ let r = !1;
673
+ const n = typeof t == "function" ? t : t.dispose.bind(t), s = /* @__PURE__ */ k((...o) => {
674
+ if (!r)
675
+ return r = !0, W(this.disposables, s), n(...o);
676
+ }, "wrapped");
677
+ return this.disposables.push(s), typeof t == "function" ? s : (t.dispose = s, t);
678
+ }
679
+ collect(i, e) {
680
+ const t = j(() => (W(this.disposables, t), e()), "name", i);
681
+ return this.disposables.push(t), t;
682
+ }
683
+ restart() {
684
+ this.reset(), this.error = null, this.hasError = !1, this.status = 0, this.start();
685
+ }
686
+ _getStatus() {
687
+ return this.uid === null ? 4 : this.hasError ? 3 : this.tasks.size ? 1 : this.ready ? 2 : 0;
688
+ }
689
+ updateStatus(i) {
690
+ const e = this.status;
691
+ i?.(), this.status = this._getStatus(), e !== this.status && this.context.emit("internal/status", this, e);
692
+ }
693
+ ensure(i) {
694
+ const e = i().catch((t) => {
695
+ this.context.emit(this.ctx, "internal/error", t), this.cancel(t);
696
+ }).finally(() => {
697
+ this.updateStatus(() => this.tasks.delete(e)), this.context.events._tasks.delete(e);
698
+ });
699
+ this.updateStatus(() => this.tasks.add(e)), this.context.events._tasks.add(e);
700
+ }
701
+ cancel(i) {
702
+ this.error = i, this.updateStatus(() => this.hasError = !0), this.reset();
703
+ }
704
+ get ready() {
705
+ return Object.entries(this.runtime.inject).every(([i, e]) => !e.required || !I(this.ctx.get(i)));
706
+ }
707
+ reset() {
708
+ this.isActive = !1, this.disposables = this.disposables.splice(0).filter((i) => {
709
+ if (this.uid !== null && i[M.static] === this) return !0;
710
+ (async () => i())().catch((e) => {
711
+ this.context.emit(this.ctx, "internal/error", e);
712
+ });
713
+ });
714
+ }
715
+ init(i) {
716
+ this.config ? this.start() : this.cancel(i);
717
+ }
718
+ start() {
719
+ if (!this.ready || this.isActive || this.uid === null) return !0;
720
+ this.isActive = !0, this.updateStatus(() => this.hasError = !1);
721
+ }
722
+ accept(...i) {
723
+ const t = { keys: Array.isArray(i[0]) ? i.shift() : null, callback: i[0], ...i[1] };
724
+ return this.effect(() => (this.acceptors.push(t), t.immediate && t.callback?.(this.config), () => W(this.acceptors, t)));
725
+ }
726
+ decline(i) {
727
+ return this.accept(i, () => !0);
728
+ }
729
+ checkUpdate(i, e) {
730
+ if (e || !this.config) return [!0, !0];
731
+ if (e === !1) return [!1, !1];
732
+ const t = /* @__PURE__ */ Object.create(null), r = /* @__PURE__ */ k((f) => {
733
+ const u = t[f] ??= !Y(this.config[f], i[f]);
734
+ return s ||= u, u;
735
+ }, "checkPropertyUpdate"), n = /* @__PURE__ */ new Set();
736
+ let s = !1, o = !1, a = this.runtime.isReactive || null;
737
+ for (const { keys: f, callback: u, passive: p } of this.acceptors) {
738
+ if (!f)
739
+ a ||= !p;
740
+ else if (p)
741
+ f?.forEach((_) => n.add(_));
742
+ else {
743
+ let _ = !1;
744
+ for (const g of f)
745
+ _ ||= r(g);
746
+ if (!_) continue;
747
+ }
748
+ u?.(i) && (o = !0);
749
+ }
750
+ for (const f in { ...this.config, ...i })
751
+ if (a !== !1 && !(f in t) && !n.has(f)) {
752
+ const u = r(f);
753
+ a === null && (o ||= u);
754
+ }
755
+ return [s, o];
756
+ }
757
+ }, Xi = class extends Ct {
758
+ constructor(i, e, t, r) {
759
+ super(i, t), this.runtime = e, this.dispose = j(i.scope.collect(`fork <${i.runtime.name}>`, () => {
760
+ this.uid = null, this.reset(), this.context.emit("internal/fork", this);
761
+ const n = W(e.disposables, this.dispose);
762
+ return W(e.children, this) && !e.children.length && i.registry.delete(e.plugin), n;
763
+ }), M.static, e), e.children.push(this), e.disposables.push(this.dispose), this.context.emit("internal/fork", this), this.init(r);
764
+ }
765
+ static {
766
+ k(this, "ForkScope");
767
+ }
768
+ dispose;
769
+ start() {
770
+ if (super.start()) return !0;
771
+ for (const i of this.runtime.forkables)
772
+ this.ensure(async () => i(this.context, this._config));
773
+ }
774
+ update(i, e) {
775
+ const t = this.config, r = this.runtime.isForkable ? this : this.runtime;
776
+ if (r.config !== t) return;
777
+ let n;
778
+ try {
779
+ n = oe(this.runtime.plugin, i);
780
+ } catch (a) {
781
+ return this.context.emit("internal/error", a), this.cancel(a);
782
+ }
783
+ const [s, o] = r.checkUpdate(n, e);
784
+ this.context.emit("internal/before-update", this, i), this.config = n, r.config = n, s && this.context.emit("internal/update", this, t), o && r.restart();
785
+ }
786
+ }, lt = class extends Ct {
787
+ constructor(i, e, t, r) {
788
+ super(i, t), this.plugin = e, e ? (this.setup(), this.init(r)) : (this.name = "root", this.isActive = !0);
789
+ }
790
+ static {
791
+ k(this, "MainScope");
792
+ }
793
+ value;
794
+ runtime = this;
795
+ schema;
796
+ name;
797
+ inject = /* @__PURE__ */ Object.create(null);
798
+ forkables = [];
799
+ children = [];
800
+ isReusable = !1;
801
+ isReactive = !1;
802
+ get isForkable() {
803
+ return this.forkables.length > 0;
804
+ }
805
+ fork(i, e, t) {
806
+ return new Xi(i, this, e, t);
807
+ }
808
+ dispose() {
809
+ return this.uid = null, this.reset(), this.context.emit("internal/runtime", this), !0;
810
+ }
811
+ setup() {
812
+ const { name: i } = this.plugin;
813
+ i && i !== "apply" && (this.name = i), this.schema = this.plugin.Config || this.plugin.schema, this.inject = F.resolve(this.plugin.using || this.plugin.inject), this.isReusable = this.plugin.reusable, this.isReactive = this.plugin.reactive, this.context.emit("internal/runtime", this), this.isReusable && this.forkables.push(this.apply);
814
+ }
815
+ apply = /* @__PURE__ */ k((i, e) => {
816
+ if (typeof this.plugin != "function")
817
+ return this.plugin.apply(i, e);
818
+ if (Be(this.plugin)) {
819
+ const t = new this.plugin(i, e), r = t[M.expose];
820
+ return r && i.set(r, t), t.fork && this.forkables.push(t.fork.bind(t)), t;
821
+ } else
822
+ return this.plugin(i, e);
823
+ }, "apply");
824
+ reset() {
825
+ super.reset();
826
+ for (const i of this.children)
827
+ i.reset();
828
+ }
829
+ start() {
830
+ if (super.start()) return !0;
831
+ !this.isReusable && this.plugin && this.ensure(async () => this.value = this.apply(this.ctx, this._config));
832
+ for (const i of this.children)
833
+ i.start();
834
+ }
835
+ update(i, e) {
836
+ if (this.isForkable) {
837
+ const a = new Error(`attempting to update forkable plugin "${this.plugin.name}", which may lead to unexpected behavior`);
838
+ this.context.emit(this.ctx, "internal/warning", a);
839
+ }
840
+ const t = this.config;
841
+ let r;
842
+ try {
843
+ r = oe(this.runtime.plugin || this.context.constructor, i);
844
+ } catch (a) {
845
+ return this.context.emit("internal/error", a), this.cancel(a);
846
+ }
847
+ const [n, s] = this.checkUpdate(r, e), o = this.children.find((a) => a.config === t);
848
+ this.config = r, o && (this.context.emit("internal/before-update", o, i), o.config = r, n && this.context.emit("internal/update", o, t)), s && this.restart();
849
+ }
850
+ };
851
+ function At(i) {
852
+ return i && typeof i == "object" && typeof i.apply == "function";
853
+ }
854
+ k(At, "isApplicable");
855
+ function F(i) {
856
+ return function(e, t) {
857
+ if (t.kind === "class")
858
+ e.inject = i;
859
+ else if (t.kind === "method")
860
+ t.addInitializer(function() {
861
+ const r = this[b.tracker]?.property;
862
+ if (!r) throw new Error("missing context tracker");
863
+ this[r].inject(i, (n) => {
864
+ e.call(re(this, { [r]: n }));
865
+ });
866
+ });
867
+ else
868
+ throw new Error("@Inject can only be used on class or class methods");
869
+ };
870
+ }
871
+ k(F, "Inject");
872
+ ((i) => {
873
+ function e(t) {
874
+ if (!t) return {};
875
+ if (Array.isArray(t))
876
+ return Object.fromEntries(t.map((o) => [o, { required: !0 }]));
877
+ const { required: r, optional: n, ...s } = t;
878
+ return Array.isArray(r) && Object.assign(s, Object.fromEntries(r.map((o) => [o, { required: !0 }]))), Array.isArray(n) && Object.assign(s, Object.fromEntries(n.map((o) => [o, { required: !1 }]))), s;
879
+ }
880
+ i.resolve = e, k(e, "resolve");
881
+ })(F || (F = {}));
882
+ var Qi = class {
883
+ constructor(i, e) {
884
+ this.ctx = i, j(this, b.tracker, {
885
+ associate: "registry",
886
+ property: "ctx"
887
+ }), this.context = i;
888
+ const t = new lt(i, null, e);
889
+ i.scope = t, t.ctx = i, this.set(null, t);
890
+ }
891
+ static {
892
+ k(this, "Registry");
893
+ }
894
+ _counter = 0;
895
+ _internal = /* @__PURE__ */ new Map();
896
+ context;
897
+ get counter() {
898
+ return ++this._counter;
899
+ }
900
+ get size() {
901
+ return this._internal.size;
902
+ }
903
+ resolve(i, e = !1) {
904
+ if (i === null || typeof i == "function") return i;
905
+ if (At(i)) return i.apply;
906
+ if (e) throw new Error('invalid plugin, expect function or object with an "apply" method, received ' + typeof i);
907
+ }
908
+ get(i) {
909
+ const e = this.resolve(i);
910
+ return e && this._internal.get(e);
911
+ }
912
+ has(i) {
913
+ const e = this.resolve(i);
914
+ return !!e && this._internal.has(e);
915
+ }
916
+ set(i, e) {
917
+ const t = this.resolve(i);
918
+ this._internal.set(t, e);
919
+ }
920
+ delete(i) {
921
+ const e = this.resolve(i), t = e && this._internal.get(e);
922
+ if (t)
923
+ return this._internal.delete(e), t.dispose(), t;
924
+ }
925
+ keys() {
926
+ return this._internal.keys();
927
+ }
928
+ values() {
929
+ return this._internal.values();
930
+ }
931
+ entries() {
932
+ return this._internal.entries();
933
+ }
934
+ forEach(i) {
935
+ return this._internal.forEach(i);
936
+ }
937
+ using(i, e) {
938
+ return this.inject(i, e);
939
+ }
940
+ inject(i, e) {
941
+ return this.plugin({ inject: i, apply: e, name: e.name });
942
+ }
943
+ plugin(i, e, t) {
944
+ if (this.resolve(i, !0), this.ctx.scope.assertActive(), !t)
945
+ try {
946
+ e = oe(i, e);
947
+ } catch (n) {
948
+ this.context.emit(this.ctx, "internal/error", n), t = n, e = null;
949
+ }
950
+ let r = this.get(i);
951
+ return r ? (r.isForkable || this.context.emit(this.ctx, "internal/warning", new Error(`duplicate plugin detected: ${i.name}`)), r.fork(this.ctx, e, t)) : (r = new lt(this.ctx, i, e, t), this.set(i, r), r.fork(this.ctx, e, t));
952
+ }
953
+ }, Zi = Qi, M = class te {
954
+ static {
955
+ k(this, "Context");
956
+ }
957
+ static store = b.store;
958
+ static events = b.events;
959
+ static static = b.static;
960
+ static filter = b.filter;
961
+ static expose = b.expose;
962
+ static isolate = b.isolate;
963
+ static internal = b.internal;
964
+ static intercept = b.intercept;
965
+ static origin = "ctx";
966
+ static current = "ctx";
967
+ static is(e) {
968
+ return !!e?.[te.is];
969
+ }
970
+ static {
971
+ te.is[Symbol.toPrimitive] = () => /* @__PURE__ */ Symbol.for("cordis.is"), te.prototype[te.is] = !0;
972
+ }
973
+ /** @deprecated use `Service.traceable` instead */
974
+ static associate(e, t) {
975
+ return e;
976
+ }
977
+ constructor(e) {
978
+ e = oe(this.constructor, e), this[b.store] = /* @__PURE__ */ Object.create(null), this[b.isolate] = /* @__PURE__ */ Object.create(null), this[b.internal] = /* @__PURE__ */ Object.create(null), this[b.intercept] = /* @__PURE__ */ Object.create(null);
979
+ const t = new Proxy(this, Oe.handler);
980
+ t.root = t, t.reflect = new Oe(t), t.registry = new Zi(t, e), t.lifecycle = new Yi(t);
981
+ const r = /* @__PURE__ */ k((n) => {
982
+ if (n) {
983
+ r(Object.getPrototypeOf(n));
984
+ for (const s of Object.getOwnPropertyNames(n)) {
985
+ const o = n[s].prototype?.constructor;
986
+ o && (t[n[s].key] = new o(t, e), j(t[n[s].key], "ctx", t));
987
+ }
988
+ }
989
+ }, "attach");
990
+ return r(this[b.internal]), t;
991
+ }
992
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
993
+ return `Context <${this.name}>`;
994
+ }
995
+ get name() {
996
+ let e = this.runtime;
997
+ for (; e && !e.name; )
998
+ e = e.parent.runtime;
999
+ return e?.name;
1000
+ }
1001
+ get events() {
1002
+ return this.lifecycle;
1003
+ }
1004
+ /** @deprecated */
1005
+ get state() {
1006
+ return this.scope;
1007
+ }
1008
+ extend(e = {}) {
1009
+ const t = Reflect.getOwnPropertyDescriptor(this, b.shadow)?.value, r = Object.assign(Object.create(U(this, this)), e);
1010
+ return t ? Object.assign(Object.create(r), { [b.shadow]: t }) : r;
1011
+ }
1012
+ isolate(e, t) {
1013
+ const r = Object.create(this[b.isolate]);
1014
+ return r[e] = t ?? Symbol(e), this.extend({ [b.isolate]: r });
1015
+ }
1016
+ intercept(e, t) {
1017
+ const r = Object.create(this[b.intercept]);
1018
+ return r[e] = t, this.extend({ [b.intercept]: r });
1019
+ }
1020
+ };
1021
+ M.prototype[M.internal] = /* @__PURE__ */ Object.create(null);
1022
+ var z = class Ot {
1023
+ static {
1024
+ k(this, "Service");
1025
+ }
1026
+ static setup = b.setup;
1027
+ static invoke = b.invoke;
1028
+ static extend = b.extend;
1029
+ static tracker = b.tracker;
1030
+ static provide = b.provide;
1031
+ static immediate = b.immediate;
1032
+ start() {
1033
+ }
1034
+ stop() {
1035
+ }
1036
+ ctx;
1037
+ name;
1038
+ config;
1039
+ constructor(...e) {
1040
+ let t, r, n, s;
1041
+ M.is(e[0]) ? (t = e[0], typeof e[1] == "string" ? (r = e[1], n = e[2]) : s = e[1]) : s = e[0], r ??= this.constructor[b.provide], n ??= this.constructor[b.immediate];
1042
+ let o = this;
1043
+ const a = {
1044
+ associate: r,
1045
+ property: "ctx"
1046
+ };
1047
+ return o[b.invoke] && (o = Ae(r, Ue(Object.getPrototypeOf(this), Function.prototype), a)), t ? o.ctx = t : o[b.setup](), o.name = r, o.config = s, j(o, b.tracker, a), o.ctx.provide(r), o.ctx.runtime.name = r, n && (t ? o[b.expose] = r : o.ctx.set(r, o)), o.ctx.on("ready", async () => {
1048
+ await Promise.resolve(), await o.start(), n || o.ctx.set(r, o);
1049
+ }), o.ctx.on("dispose", () => o.stop()), o;
1050
+ }
1051
+ [b.filter](e) {
1052
+ return e[b.isolate][this.name] === this.ctx[b.isolate][this.name];
1053
+ }
1054
+ [b.setup]() {
1055
+ this.ctx = new M();
1056
+ }
1057
+ [b.extend](e) {
1058
+ let t;
1059
+ return this[Ot.invoke] ? t = Ae(this.name, this, this[b.tracker]) : t = Object.create(this), Object.assign(t, e);
1060
+ }
1061
+ static [Symbol.hasInstance](e) {
1062
+ let t = e.constructor;
1063
+ for (; t; ) {
1064
+ if (t = t.prototype?.constructor, t === this) return !0;
1065
+ t = Object.getPrototypeOf(t);
1066
+ }
1067
+ return !1;
1068
+ }
1069
+ }, er = Object.defineProperty, tr = Object.getOwnPropertyNames, E = (i, e) => er(i, "name", { value: e, configurable: !0 }), ir = (i, e) => function() {
1070
+ return e || (0, i[tr(i)[0]])((e = { exports: {} }).exports, e), e.exports;
1071
+ }, rr = ir({
1072
+ "src/index.ts"(i, e) {
1073
+ var t = /* @__PURE__ */ Symbol.for("schemastery"), r = /* @__PURE__ */ Symbol.for("ValidationError");
1074
+ globalThis.__schemastery_index__ ??= 0, globalThis.__schemastery_refs__ = void 0;
1075
+ var n = class extends TypeError {
1076
+ constructor(l, c) {
1077
+ let h = "$";
1078
+ for (const d of c.path || [])
1079
+ typeof d == "string" ? h += "." + d : typeof d == "number" ? h += "[" + d + "]" : typeof d == "symbol" && (h += `[Symbol(${d.toString()})]`);
1080
+ h.startsWith(".") && (h = h.slice(1)), super((h === "$" ? "" : `${h} `) + l), this.options = c;
1081
+ }
1082
+ static {
1083
+ E(this, "ValidationError");
1084
+ }
1085
+ name = "ValidationError";
1086
+ static is(l) {
1087
+ return !!l?.[r];
1088
+ }
1089
+ };
1090
+ Object.defineProperty(n.prototype, r, {
1091
+ value: !0
1092
+ });
1093
+ var s = /* @__PURE__ */ E(function(l) {
1094
+ const c = /* @__PURE__ */ E(function(h, d = {}) {
1095
+ return s.resolve(h, c, d)[0];
1096
+ }, "schema");
1097
+ if (l.refs) {
1098
+ const h = K(l.refs, (m) => new s(m)), d = /* @__PURE__ */ E((m) => h[m], "getRef");
1099
+ for (const m in h) {
1100
+ const v = h[m];
1101
+ v.sKey = d(v.sKey), v.inner = d(v.inner), v.list = v.list && v.list.map(d), v.dict = v.dict && K(v.dict, d);
1102
+ }
1103
+ return h[l.uid];
1104
+ }
1105
+ if (Object.assign(c, l), typeof c.callback == "string")
1106
+ try {
1107
+ c.callback = new Function("return " + c.callback)();
1108
+ } catch {
1109
+ }
1110
+ return Object.defineProperty(c, "uid", { value: globalThis.__schemastery_index__++ }), Object.setPrototypeOf(c, s.prototype), c.meta ||= {}, c.toString = c.toString.bind(c), c;
1111
+ }, "Schema");
1112
+ s.prototype = Object.create(Function.prototype), s.prototype[t] = !0, s.ValidationError = n, s.prototype.toJSON = /* @__PURE__ */ E(function() {
1113
+ if (globalThis.__schemastery_refs__)
1114
+ return globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this })), this.uid;
1115
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } }, globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
1116
+ const c = { uid: this.uid, refs: globalThis.__schemastery_refs__ };
1117
+ return globalThis.__schemastery_refs__ = void 0, c;
1118
+ }, "toJSON"), s.prototype.set = /* @__PURE__ */ E(function(c, h) {
1119
+ return this.dict[c] = h, this;
1120
+ }, "set"), s.prototype.push = /* @__PURE__ */ E(function(c) {
1121
+ return this.list.push(c), this;
1122
+ }, "push");
1123
+ function o(l, c) {
1124
+ const h = typeof l == "string" ? { "": l } : { ...l };
1125
+ for (const d in c) {
1126
+ const m = c[d];
1127
+ m?.$description || m?.$desc ? h[d] = m.$description || m.$desc : typeof m == "string" && (h[d] = m);
1128
+ }
1129
+ return h;
1130
+ }
1131
+ E(o, "mergeDesc");
1132
+ function a(l) {
1133
+ return l?.$value ?? l?.$inner;
1134
+ }
1135
+ E(a, "getInner");
1136
+ function f(l) {
1137
+ return vt(l ?? {}, (c) => !c.startsWith("$"));
1138
+ }
1139
+ E(f, "extractKeys"), s.prototype.i18n = /* @__PURE__ */ E(function(c) {
1140
+ const h = s(this), d = o(h.meta.description, c);
1141
+ return Object.keys(d).length && (h.meta.description = d), h.dict && (h.dict = K(h.dict, (m, v) => m.i18n(K(c, (x) => a(x)?.[v] ?? x?.[v])))), h.list && (h.list = h.list.map((m, v) => m.i18n(K(c, (x = {}) => Array.isArray(a(x)) ? a(x)[v] : Array.isArray(x) ? x[v] : f(x))))), h.inner && (h.inner = h.inner.i18n(K(c, (m) => a(m) ? a(m) : f(m)))), h.sKey && (h.sKey = h.sKey.i18n(K(c, (m) => m?.$key))), h;
1142
+ }, "i18n"), s.prototype.extra = /* @__PURE__ */ E(function(c, h) {
1143
+ const d = s(this);
1144
+ return d.meta = { ...d.meta, [c]: h }, d;
1145
+ }, "extra");
1146
+ for (const l of ["required", "disabled", "collapse", "hidden", "loose"])
1147
+ Object.assign(s.prototype, {
1148
+ [l](c = !0) {
1149
+ const h = s(this);
1150
+ return h.meta = { ...h.meta, [l]: c }, h;
1151
+ }
1152
+ });
1153
+ s.prototype.deprecated = /* @__PURE__ */ E(function() {
1154
+ const c = s(this);
1155
+ return c.meta.badges ||= [], c.meta.badges.push({ text: "deprecated", type: "danger" }), c;
1156
+ }, "deprecated"), s.prototype.experimental = /* @__PURE__ */ E(function() {
1157
+ const c = s(this);
1158
+ return c.meta.badges ||= [], c.meta.badges.push({ text: "experimental", type: "warning" }), c;
1159
+ }, "experimental"), s.prototype.pattern = /* @__PURE__ */ E(function(c) {
1160
+ const h = s(this), d = _t(c, ["source", "flags"]);
1161
+ return h.meta = { ...h.meta, pattern: d }, h;
1162
+ }, "pattern"), s.prototype.simplify = /* @__PURE__ */ E(function(c) {
1163
+ if (Y(c, this.meta.default, this.type === "dict")) return null;
1164
+ if (I(c)) return c;
1165
+ if (this.type === "object" || this.type === "dict") {
1166
+ const h = {};
1167
+ for (const d in c) {
1168
+ const v = (this.type === "object" ? this.dict[d] : this.inner)?.simplify(c[d]);
1169
+ (this.type === "dict" || !I(v)) && (h[d] = v);
1170
+ }
1171
+ return Y(h, this.meta.default, this.type === "dict") ? null : h;
1172
+ } else if (this.type === "array" || this.type === "tuple") {
1173
+ const h = [];
1174
+ return c.forEach((d, m) => {
1175
+ const v = this.type === "array" ? this.inner : this.list[m], x = v ? v.simplify(d) : d;
1176
+ h.push(x);
1177
+ }), h;
1178
+ } else if (this.type === "intersect") {
1179
+ const h = {};
1180
+ for (const d of this.list)
1181
+ Object.assign(h, d.simplify(c));
1182
+ return h;
1183
+ } else if (this.type === "union")
1184
+ for (const h of this.list)
1185
+ try {
1186
+ return s.resolve(c, h, {}), h.simplify(c);
1187
+ } catch {
1188
+ }
1189
+ return c;
1190
+ }, "simplify"), s.prototype.toString = /* @__PURE__ */ E(function(c) {
1191
+ return O[this.type]?.(this, c) ?? `Schema<${this.type}>`;
1192
+ }, "toString"), s.prototype.role = /* @__PURE__ */ E(function(l, c) {
1193
+ const h = s(this);
1194
+ return h.meta = { ...h.meta, role: l, extra: c }, h;
1195
+ }, "role");
1196
+ for (const l of ["default", "link", "comment", "description", "max", "min", "step"])
1197
+ Object.assign(s.prototype, {
1198
+ [l](c) {
1199
+ const h = s(this);
1200
+ return h.meta = { ...h.meta, [l]: c }, h;
1201
+ }
1202
+ });
1203
+ var u = {};
1204
+ s.extend = /* @__PURE__ */ E(function(c, h) {
1205
+ u[c] = h;
1206
+ }, "extend"), s.resolve = /* @__PURE__ */ E(function(c, h, d = {}, m = !1) {
1207
+ if (!h) return [c];
1208
+ if (d.ignore?.(c, h)) return [c];
1209
+ if (I(c) && h.type !== "lazy") {
1210
+ if (h.meta.required) throw new n("missing required value", d);
1211
+ let x = h, A = h.meta.default;
1212
+ for (; x?.type === "intersect" && I(A); )
1213
+ x = x.list[0], A = x?.meta.default;
1214
+ if (I(A)) return [c];
1215
+ c = ue(A);
1216
+ }
1217
+ const v = u[h.type];
1218
+ if (!v) throw new n(`unsupported type "${h.type}"`, d);
1219
+ try {
1220
+ return v(c, h, d, m);
1221
+ } catch (x) {
1222
+ if (!h.meta.loose) throw x;
1223
+ return [h.meta.default];
1224
+ }
1225
+ }, "resolve"), s.from = /* @__PURE__ */ E(function(c) {
1226
+ if (I(c))
1227
+ return s.any();
1228
+ if (["string", "number", "boolean"].includes(typeof c))
1229
+ return s.const(c).required();
1230
+ if (c[t])
1231
+ return c;
1232
+ if (typeof c == "function")
1233
+ switch (c) {
1234
+ case String:
1235
+ return s.string().required();
1236
+ case Number:
1237
+ return s.number().required();
1238
+ case Boolean:
1239
+ return s.boolean().required();
1240
+ case Function:
1241
+ return s.function().required();
1242
+ default:
1243
+ return s.is(c).required();
1244
+ }
1245
+ else
1246
+ throw new TypeError(`cannot infer schema from ${c}`);
1247
+ }, "from"), s.lazy = /* @__PURE__ */ E(function(c) {
1248
+ const h = /* @__PURE__ */ E(() => (d.inner[t] || (d.inner = d.builder(), d.inner.meta = { ...d.meta, ...d.inner.meta }), d.inner.toJSON()), "toJSON"), d = new s({ type: "lazy", builder: c, inner: { toJSON: h } });
1249
+ return d;
1250
+ }, "lazy"), s.natural = /* @__PURE__ */ E(function() {
1251
+ return s.number().step(1).min(0);
1252
+ }, "natural"), s.percent = /* @__PURE__ */ E(function() {
1253
+ return s.number().step(0.01).min(0).max(1).role("slider");
1254
+ }, "percent"), s.date = /* @__PURE__ */ E(function() {
1255
+ return s.union([
1256
+ s.is(Date),
1257
+ s.transform(s.string().role("datetime"), (c, h) => {
1258
+ const d = new Date(c);
1259
+ if (isNaN(+d)) throw new n(`invalid date "${c}"`, h);
1260
+ return d;
1261
+ }, !0)
1262
+ ]);
1263
+ }, "date"), s.regExp = /* @__PURE__ */ E(function(c = "") {
1264
+ return s.union([
1265
+ s.is(RegExp),
1266
+ s.transform(s.string().role("regexp", { flag: c }), (h, d) => {
1267
+ try {
1268
+ return new RegExp(h, c);
1269
+ } catch (m) {
1270
+ throw new n(m.message, d);
1271
+ }
1272
+ }, !0)
1273
+ ]);
1274
+ }, "regExp"), s.arrayBuffer = /* @__PURE__ */ E(function(c) {
1275
+ return s.union([
1276
+ s.is(ArrayBuffer),
1277
+ s.is(SharedArrayBuffer),
1278
+ s.transform(s.any(), (h, d) => {
1279
+ if (B.isSource(h)) return B.fromSource(h);
1280
+ throw new n(`expected ArrayBufferSource but got ${h}`, d);
1281
+ }, !0),
1282
+ ...c ? [s.transform(s.string(), (h, d) => {
1283
+ try {
1284
+ return c === "base64" ? B.fromBase64(h) : B.fromHex(h);
1285
+ } catch (m) {
1286
+ throw new n(m.message, d);
1287
+ }
1288
+ }, !0)] : []
1289
+ ]);
1290
+ }, "arrayBuffer"), s.extend("lazy", (l, c, h, d) => (c.inner[t] || (c.inner = c.builder(), c.inner.meta = { ...c.meta, ...c.inner.meta }), s.resolve(l, c.inner, h, d))), s.extend("any", (l) => [l]), s.extend("never", (l, c, h) => {
1291
+ throw new n(`expected nullable but got ${l}`, h);
1292
+ }), s.extend("const", (l, { value: c }, h) => {
1293
+ if (Y(l, c)) return [c];
1294
+ throw new n(`expected ${c} but got ${l}`, h);
1295
+ });
1296
+ function p(l, c, h, d, m = !1) {
1297
+ const { max: v = 1 / 0, min: x = -1 / 0 } = c;
1298
+ if (l > v) throw new n(`expected ${h} <= ${v} but got ${l}`, d);
1299
+ if (l < x && !m) throw new n(`expected ${h} >= ${x} but got ${l}`, d);
1300
+ }
1301
+ E(p, "checkWithinRange"), s.extend("string", (l, { meta: c }, h) => {
1302
+ if (typeof l != "string") throw new n(`expected string but got ${l}`, h);
1303
+ if (c.pattern) {
1304
+ const d = new RegExp(c.pattern.source, c.pattern.flags);
1305
+ if (!d.test(l)) throw new n(`expect string to match regexp ${d}`, h);
1306
+ }
1307
+ return p(l.length, c, "string length", h), [l];
1308
+ });
1309
+ function y(l, c) {
1310
+ const h = l.toString();
1311
+ if (h.includes("e")) return l * Math.pow(10, c);
1312
+ const d = h.indexOf(".");
1313
+ if (d === -1) return l * Math.pow(10, c);
1314
+ const m = h.slice(d + 1), v = h.slice(0, d);
1315
+ return m.length <= c ? +(v + m.padEnd(c, "0")) : +(v + m.slice(0, c) + "." + m.slice(c));
1316
+ }
1317
+ E(y, "decimalShift");
1318
+ function _(l, c, h) {
1319
+ if (h = Math.abs(h), !/^\d+\.\d+$/.test(h.toString()))
1320
+ return (l - c) % h === 0;
1321
+ const d = h.toString().indexOf("."), m = h.toString().slice(d + 1).length;
1322
+ return Math.abs(y(l, m) - y(c, m)) % y(h, m) === 0;
1323
+ }
1324
+ E(_, "isMultipleOf"), s.extend("number", (l, { meta: c }, h) => {
1325
+ if (typeof l != "number") throw new n(`expected number but got ${l}`, h);
1326
+ p(l, c, "number", h);
1327
+ const { step: d } = c;
1328
+ if (d && !_(l, c.min ?? 0, d))
1329
+ throw new n(`expected number multiple of ${d} but got ${l}`, h);
1330
+ return [l];
1331
+ }), s.extend("boolean", (l, c, h) => {
1332
+ if (typeof l == "boolean") return [l];
1333
+ throw new n(`expected boolean but got ${l}`, h);
1334
+ }), s.extend("bitset", (l, { bits: c, meta: h }, d) => {
1335
+ let m = 0, v = [];
1336
+ if (typeof l == "number") {
1337
+ m = l;
1338
+ for (const x in c)
1339
+ l & c[x] && v.push(x);
1340
+ } else if (Array.isArray(l)) {
1341
+ v = l;
1342
+ for (const x of v) {
1343
+ if (typeof x != "string") throw new n(`expected string but got ${x}`, d);
1344
+ x in c && (m |= c[x]);
1345
+ }
1346
+ } else
1347
+ throw new n(`expected number or array but got ${l}`, d);
1348
+ return m === h.default ? [m] : [m, v];
1349
+ }), s.extend("function", (l, c, h) => {
1350
+ if (typeof l == "function") return [l];
1351
+ throw new n(`expected function but got ${l}`, h);
1352
+ }), s.extend("is", (l, { constructor: c }, h) => {
1353
+ if (typeof c == "function") {
1354
+ if (l instanceof c) return [l];
1355
+ throw new n(`expected ${c.name} but got ${l}`, h);
1356
+ } else {
1357
+ if (I(l))
1358
+ throw new n(`expected ${c} but got ${l}`, h);
1359
+ let d = Object.getPrototypeOf(l);
1360
+ for (; d; ) {
1361
+ if (d.constructor?.name === c) return [l];
1362
+ d = Object.getPrototypeOf(d);
1363
+ }
1364
+ throw new n(`expected ${c} but got ${l}`, h);
1365
+ }
1366
+ });
1367
+ function g(l, c, h, d) {
1368
+ try {
1369
+ const [m, v] = s.resolve(l[c], h, {
1370
+ ...d,
1371
+ path: [...d.path || [], c]
1372
+ });
1373
+ return v !== void 0 && (l[c] = v), m;
1374
+ } catch (m) {
1375
+ if (!d?.autofix) throw m;
1376
+ return delete l[c], h.meta.default;
1377
+ }
1378
+ }
1379
+ E(g, "property"), s.extend("array", (l, { inner: c, meta: h }, d) => {
1380
+ if (!Array.isArray(l)) throw new n(`expected array but got ${l}`, d);
1381
+ return p(l.length, h, "array length", d, !I(c.meta.default)), [l.map((m, v) => g(l, v, c, d))];
1382
+ }), s.extend("dict", (l, { inner: c, sKey: h }, d, m) => {
1383
+ if (!he(l)) throw new n(`expected object but got ${l}`, d);
1384
+ const v = {};
1385
+ for (const x in l) {
1386
+ let A;
1387
+ try {
1388
+ A = s.resolve(x, h, d)[0];
1389
+ } catch (Se) {
1390
+ if (m) continue;
1391
+ throw Se;
1392
+ }
1393
+ v[A] = g(l, x, c, d), l[A] = l[x], x !== A && delete l[x];
1394
+ }
1395
+ return [v];
1396
+ }), s.extend("tuple", (l, { list: c }, h, d) => {
1397
+ if (!Array.isArray(l)) throw new n(`expected array but got ${l}`, h);
1398
+ const m = c.map((v, x) => g(l, x, v, h));
1399
+ return d ? [m] : (m.push(...l.slice(c.length)), [m]);
1400
+ });
1401
+ function w(l, c) {
1402
+ for (const h in c)
1403
+ h in l || (l[h] = c[h]);
1404
+ }
1405
+ E(w, "merge"), s.extend("object", (l, { dict: c }, h, d) => {
1406
+ if (!he(l)) throw new n(`expected object but got ${l}`, h);
1407
+ const m = {};
1408
+ for (const v in c) {
1409
+ const x = g(l, v, c[v], h);
1410
+ (!I(x) || v in l) && (m[v] = x);
1411
+ }
1412
+ return d || w(m, l), [m];
1413
+ }), s.extend("union", (l, { list: c, toString: h }, d, m) => {
1414
+ for (const v of c)
1415
+ try {
1416
+ return s.resolve(l, v, d, m);
1417
+ } catch {
1418
+ }
1419
+ throw new n(`expected ${h()} but got ${JSON.stringify(l)}`, d);
1420
+ }), s.extend("intersect", (l, { list: c, toString: h }, d, m) => {
1421
+ if (!c.length) return [l];
1422
+ let v;
1423
+ for (const x of c) {
1424
+ const A = s.resolve(l, x, d, !0)[0];
1425
+ if (!I(A))
1426
+ if (I(v))
1427
+ v = A;
1428
+ else {
1429
+ if (typeof v != typeof A)
1430
+ throw new n(`expected ${h()} but got ${JSON.stringify(l)}`, d);
1431
+ if (typeof A == "object")
1432
+ w(v ??= {}, A);
1433
+ else if (v !== A)
1434
+ throw new n(`expected ${h()} but got ${JSON.stringify(l)}`, d);
1435
+ }
1436
+ }
1437
+ return !m && he(l) && w(v, l), [v];
1438
+ }), s.extend("transform", (l, { inner: c, callback: h, preserve: d }, m) => {
1439
+ const [v, x = l] = s.resolve(l, c, m, !0);
1440
+ return d ? [h(v)] : [h(v), h(x)];
1441
+ });
1442
+ var O = {};
1443
+ function C(l, c, h) {
1444
+ O[l] = h, Object.assign(s, {
1445
+ [l](...d) {
1446
+ const m = new s({ type: l });
1447
+ return c.forEach((v, x) => {
1448
+ switch (v) {
1449
+ case "sKey":
1450
+ m.sKey = d[x] ?? s.string();
1451
+ break;
1452
+ case "inner":
1453
+ m.inner = s.from(d[x]);
1454
+ break;
1455
+ case "list":
1456
+ m.list = d[x].map(s.from);
1457
+ break;
1458
+ case "dict":
1459
+ m.dict = K(d[x], s.from);
1460
+ break;
1461
+ case "bits": {
1462
+ m.bits = {};
1463
+ for (const A in d[x])
1464
+ typeof d[x][A] == "number" && (m.bits[A] = d[x][A]);
1465
+ break;
1466
+ }
1467
+ case "callback": {
1468
+ const A = m.callback = d[x];
1469
+ A.toJSON ||= () => A.toString();
1470
+ break;
1471
+ }
1472
+ case "constructor": {
1473
+ const A = m.constructor = d[x];
1474
+ typeof A == "function" && (A.toJSON ||= () => A.name);
1475
+ break;
1476
+ }
1477
+ default:
1478
+ m[v] = d[x];
1479
+ }
1480
+ }), l === "object" || l === "dict" ? m.meta.default = {} : l === "array" || l === "tuple" ? m.meta.default = [] : l === "bitset" && (m.meta.default = 0), m;
1481
+ }
1482
+ });
1483
+ }
1484
+ E(C, "defineMethod"), C("is", ["constructor"], ({ constructor: l }) => typeof l == "function" ? l.name : l), C("any", [], () => "any"), C("never", [], () => "never"), C("const", ["value"], ({ value: l }) => typeof l == "string" ? JSON.stringify(l) : l), C("string", [], () => "string"), C("number", [], () => "number"), C("boolean", [], () => "boolean"), C("bitset", ["bits"], () => "bitset"), C("function", [], () => "function"), C("array", ["inner"], ({ inner: l }) => `${l.toString(!0)}[]`), C("dict", ["inner", "sKey"], ({ inner: l, sKey: c }) => `{ [key: ${c.toString()}]: ${l.toString()} }`), C("tuple", ["list"], ({ list: l }) => `[${l.map((c) => c.toString()).join(", ")}]`), C("object", ["dict"], ({ dict: l }) => Object.keys(l).length === 0 ? "{}" : `{ ${Object.entries(l).map(([c, h]) => `${c}${h.meta.required ? "" : "?"}: ${h.toString()}`).join(", ")} }`), C("union", ["list"], ({ list: l }, c) => {
1485
+ const h = l.map(({ toString: d }) => d()).join(" | ");
1486
+ return c ? `(${h})` : h;
1487
+ }), C("intersect", ["list"], ({ list: l }) => `${l.map((c) => c.toString(!0)).join(" & ")}`), C("transform", ["inner", "callback", "preserve"], ({ inner: l }, c) => l.toString(c)), e.exports = s;
1488
+ }
1489
+ });
1490
+ const $ = rr();
1491
+ var Pt = /* @__PURE__ */ ((i) => (i[i.debug = -1] = "debug", i[i.log = 0] = "log", i[i.info = 1] = "info", i[i.warn = 2] = "warn", i[i.error = 3] = "error", i[i.silent = 4] = "silent", i))(Pt || {});
1492
+ const Le = globalThis || window, Re = /* @__PURE__ */ Symbol.for("__IPE_LOGGER_COLOR_MAP__");
1493
+ Le[Re] || (Le[Re] = /* @__PURE__ */ new Map());
1494
+ const $e = Le[Re];
1495
+ function ae(i) {
1496
+ let e = 2166136261;
1497
+ for (let t = 0; t < i.length; t++)
1498
+ e ^= i.charCodeAt(t), e = (e >>> 0) * 16777619;
1499
+ return e >>> 0;
1500
+ }
1501
+ const ht = [
1502
+ [350, 360],
1503
+ [0, 15],
1504
+ [15, 30],
1505
+ [200, 230],
1506
+ [230, 250],
1507
+ [250, 280],
1508
+ [280, 310],
1509
+ [310, 330],
1510
+ [140, 160],
1511
+ [160, 180]
1512
+ ];
1513
+ function nr(i, e) {
1514
+ const t = ht.length, r = ae(i) % t, [n, s] = ht[r], o = s - n, a = ae(i + ":" + e), f = n + a % (o || 1), u = ae(i + ":s"), p = ae(i + ":l");
1515
+ let y, _;
1516
+ if (e === "name")
1517
+ y = 62 + u % 18, _ = 30 + p % 12;
1518
+ else {
1519
+ const g = f >= 0 && f < 50 || f > 330 && f < 360, w = f >= 200 && f <= 300;
1520
+ y = 55 + u % 20, w ? _ = 55 + p % 8 : g ? _ = 48 + p % 6 : _ = 50 + p % 8, y < 60 && (y += 5);
1521
+ }
1522
+ return `hsl(${f}, ${y}%, ${_}%)`;
1523
+ }
1524
+ function ce(i, e) {
1525
+ if (e)
1526
+ return $e.set(i, e), e;
1527
+ const t = $e.get(i);
1528
+ if (t) return t;
1529
+ const r = i.startsWith("name:") ? "name" : "group", n = nr(i, r);
1530
+ return $e.set(i, n), n;
1531
+ }
1532
+ class He {
1533
+ /**
1534
+ * Note: constructor returns a callable Proxy so that you can do `logger('group')`.
1535
+ */
1536
+ constructor(e = {}) {
1537
+ this._custom = (t) => {
1538
+ if (!this._enabled(t.level)) return ut;
1539
+ const [r, n] = this._prefix(t.label);
1540
+ return this._consoleMethod(t.method).bind(console, r, ...n);
1541
+ }, this._name = e.name, this._nameColor = e.color, this._groupPath = e._groupPath ? [...e._groupPath] : [], this._dynamicLevels = { ...e._dynamicLevels }, this._levelRef = e._levelRef ?? {
1542
+ value: e.level ?? 1
1543
+ /* info */
1544
+ }, this._name && ce(`name:${this._name}`, this._nameColor), this._installBuiltinLevels();
1545
+ for (const t of Object.keys(this._dynamicLevels))
1546
+ this._installLevelGetter(t, this._dynamicLevels[t]);
1547
+ return or(this);
1548
+ }
1549
+ // ---------- public API ----------
1550
+ get level() {
1551
+ return this._levelRef.value;
1552
+ }
1553
+ set level(e) {
1554
+ this._levelRef.value = e;
1555
+ }
1556
+ /** Create a sub-logger with a group label */
1557
+ group(e, t) {
1558
+ return e && ce(`group:${e}`, t?.color), new He({
1559
+ name: this._name,
1560
+ color: this._nameColor,
1561
+ _groupPath: [...this._groupPath, e],
1562
+ _dynamicLevels: this._dynamicLevels,
1563
+ _levelRef: this._levelRef
1564
+ });
1565
+ }
1566
+ /** Define a custom level, e.g. logger.defineLevel('success', { level: info, label: '✅', method: 'info' }) */
1567
+ defineLevel(e, t) {
1568
+ this._dynamicLevels[e] = { ...t }, this._installLevelGetter(e, t);
1569
+ }
1570
+ // Built-in level getters
1571
+ get debug() {
1572
+ return this._method("debug");
1573
+ }
1574
+ get log() {
1575
+ return this._method("log");
1576
+ }
1577
+ get info() {
1578
+ return this._method("info");
1579
+ }
1580
+ get warn() {
1581
+ return this._method("warn");
1582
+ }
1583
+ get error() {
1584
+ return this._method("error");
1585
+ }
1586
+ // ---------- internals ----------
1587
+ _installBuiltinLevels() {
1588
+ }
1589
+ _installLevelGetter(e, t) {
1590
+ Object.defineProperty(this, e, {
1591
+ configurable: !0,
1592
+ enumerable: !1,
1593
+ get: () => this._custom(t)
1594
+ });
1595
+ }
1596
+ _method(e) {
1597
+ const t = sr[e];
1598
+ if (!this._enabled(t.level)) return ut;
1599
+ const [r, n] = this._prefix(t.label);
1600
+ return this._consoleMethod(e).bind(console, r, ...n);
1601
+ }
1602
+ _consoleMethod(e) {
1603
+ return (console[e] || console.log).bind(console);
1604
+ }
1605
+ _enabled(e) {
1606
+ return e >= this._levelRef.value && this._levelRef.value !== 4;
1607
+ }
1608
+ _prefix(e) {
1609
+ const t = [];
1610
+ let r = "";
1611
+ if (this._name) {
1612
+ const n = ce(`name:${this._name}`, this._nameColor);
1613
+ r += `%c${this._name}%c`, t.push(
1614
+ `background:${n}; color:#fff; padding:1px 4px; border-radius:2px; font-weight:700;`,
1615
+ ft
1616
+ );
1617
+ }
1618
+ if (e && (r += ` ${e}`), this._groupPath.length) {
1619
+ const n = this._groupPath.join("/"), s = ce(`group:${n}`);
1620
+ r += ` %c${n}%c`, t.push(`color:${s}; text-decoration: underline;`, ft);
1621
+ }
1622
+ return [r, t];
1623
+ }
1624
+ }
1625
+ const ut = () => {
1626
+ }, ft = "color:inherit; background:transparent; text-decoration:none;", sr = {
1627
+ debug: { level: -1, label: "", method: "debug" },
1628
+ log: { level: 0, label: "", method: "log" },
1629
+ info: { level: 1, label: "[I]", method: "info" },
1630
+ warn: { level: 2, label: "[W]", method: "warn" },
1631
+ error: { level: 3, label: "[E]", method: "error" }
1632
+ };
1633
+ function or(i) {
1634
+ const e = function(t, r) {
1635
+ return i.group(t, r);
1636
+ };
1637
+ return new Proxy(e, {
1638
+ get(t, r, n) {
1639
+ return i[r];
1640
+ },
1641
+ set(t, r, n) {
1642
+ return i[r] = n, !0;
1643
+ },
1644
+ apply(t, r, n) {
1645
+ return i.group(n[0], n[1]);
1646
+ },
1647
+ has(t, r) {
1648
+ return r in i;
1649
+ }
1650
+ });
1651
+ }
1652
+ function ar(i) {
1653
+ return new He(i);
1654
+ }
1655
+ class je extends bi {
1656
+ async clientLogin(e, t, r) {
1657
+ r ||= {}, !r.logincontinue && !r.loginreturnurl && (r.loginreturnurl = location?.origin);
1658
+ const n = await this.postWithToken(
1659
+ "login",
1660
+ {
1661
+ action: "clientlogin",
1662
+ username: e,
1663
+ password: t,
1664
+ ...r
1665
+ },
1666
+ {
1667
+ tokenName: "logintoken"
1668
+ }
1669
+ );
1670
+ if (n?.data?.clientlogin?.status === "PASS")
1671
+ return n.data.clientlogin;
1672
+ throw new vi(
1673
+ _i.LOGIN_FAILED,
1674
+ n.data.clientlogin.message,
1675
+ n
1676
+ );
1677
+ }
1678
+ }
1679
+ class cr extends je {
1680
+ constructor(e, t, r) {
1681
+ const n = xi(
1682
+ e,
1683
+ {
1684
+ credentials: "include",
1685
+ mode: "cors",
1686
+ ...t
1687
+ },
1688
+ {
1689
+ origin: location.origin,
1690
+ ...r
1691
+ }
1692
+ );
1693
+ super(n);
1694
+ }
1695
+ }
1696
+ class lr {
1697
+ constructor(e, t = {}) {
1698
+ 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));
1699
+ const r = this.api = new je({
1700
+ baseURL: t.baseURL.toString(),
1701
+ fexiosConfigs: {
1702
+ headers: {
1703
+ "x-api-user-agent": `InPageEdit-NEXT ${e.version}`,
1704
+ ...t.headers
1705
+ },
1706
+ ...t
1707
+ },
1708
+ throwOnApiError: !0
1709
+ });
1710
+ e.set("api", r), e.set("apiService", this);
1711
+ }
1712
+ getClientByFileRepo(e) {
1713
+ const t = new URL(`${e.scriptDirUrl}/api.php`, location.origin), r = t.toString();
1714
+ if (r === this.ctx.root.config.apiConfigs.baseURL?.toString())
1715
+ return this.ctx.api;
1716
+ if (!this._apiClients.has(r)) {
1717
+ const n = t.origin === location.origin, s = {
1718
+ baseURL: t.toString(),
1719
+ throwOnApiError: !0
1720
+ }, o = n ? new je(s) : new cr(s);
1721
+ o.request.on("beforeRequest", (a) => {
1722
+ a.headers = o.request.mergeHeaders(a.headers, {
1723
+ "x-api-user-agent": null,
1724
+ "x-mw-token-name": null
1725
+ });
1726
+ }), this._apiClients.set(r, o);
1727
+ }
1728
+ return this._apiClients.get(r);
1729
+ }
1730
+ }
1731
+ const dt = (i, e = document) => e.querySelector(i), ms = (i, e = document) => e.querySelectorAll(i);
1732
+ var hr = Object.create, Ke = Object.defineProperty, ur = Object.getOwnPropertyDescriptor, It = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), Lt = (i) => {
1733
+ throw TypeError(i);
1734
+ }, fr = (i, e, t) => e in i ? Ke(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, dr = (i, e) => Ke(i, "name", { value: e, configurable: !0 }), pr = (i) => [, , , hr(i?.[It("metadata")] ?? null)], gr = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Rt = (i) => i !== void 0 && typeof i != "function" ? Lt("Function expected") : i, mr = (i, e, t, r, n) => ({ kind: gr[i], name: e, metadata: r, addInitializer: (s) => t._ ? Lt("Already initialized") : n.push(Rt(s || null)) }), yr = (i, e) => fr(e, It("metadata"), i[3]), wr = (i, e, t, r) => {
1735
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
1736
+ return r;
1737
+ }, br = (i, e, t, r, n, s) => {
1738
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && ur(n, t));
1739
+ dr(n, t);
1740
+ for (var w = r.length - 1; w >= 0; w--)
1741
+ f = mr(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, Rt(o) && (n = o);
1742
+ return yr(i, n), g && Ke(n, t, g), p ? u ^ 4 ? s : g : n;
1743
+ }, jt, qe, Dt;
1744
+ jt = [F(["wiki", "wikiTitle"])];
1745
+ let de = class Z extends (Dt = z) {
1746
+ constructor(e) {
1747
+ super(e, "currentPage", !1), this.ctx = e, this.#e = this.#r.bind(this), this.url = new URL(window.location.href), this.isMainPage = void 0, this.wikiTitle = void 0;
1748
+ }
1749
+ get logger() {
1750
+ return this.ctx.logger("CURRENT_PAGE");
1751
+ }
1752
+ static {
1753
+ this.HISTORY_CHANGE_EVENT = "inpageedit:historychange";
1754
+ }
1755
+ static {
1756
+ this.POPSTATE_INJECTION_KEY = /* @__PURE__ */ Symbol.for(
1757
+ "inpageedit:currentpage:popstateinjection"
1758
+ );
1759
+ }
1760
+ async start() {
1761
+ await this.#t(), this.#i(), window.addEventListener(Z.HISTORY_CHANGE_EVENT, this.#e), this.ctx.emit("current-page/popstate"), this.logger.info("initialized", this.wikiTitle);
1762
+ }
1763
+ stop() {
1764
+ window.removeEventListener(Z.HISTORY_CHANGE_EVENT, this.#e);
1765
+ }
1766
+ async #t() {
1767
+ await this.#s(), await this.#n();
1768
+ }
1769
+ /**
1770
+ * @NOTE
1771
+ * Do not use event name 'popstate' to listen to history change,
1772
+ * because it will cause conflict with some SPA frameworks (e.g. vue-router).
1773
+ */
1774
+ #i() {
1775
+ const e = Z.POPSTATE_INJECTION_KEY;
1776
+ if (window[e])
1777
+ return;
1778
+ const t = history.pushState, r = history.replaceState;
1779
+ history.pushState = function(n, s, o) {
1780
+ t.apply(this, [n, s, o]), window.dispatchEvent(new CustomEvent(Z.HISTORY_CHANGE_EVENT));
1781
+ }, history.replaceState = function(n, s, o) {
1782
+ r.apply(this, [n, s, o]), window.dispatchEvent(new CustomEvent(Z.HISTORY_CHANGE_EVENT));
1783
+ }, window[e] = !0;
1784
+ }
1785
+ async #r() {
1786
+ const e = this.url, t = new URL(window.location.href);
1787
+ this.url = t, (e.pathname !== t.pathname || e.searchParams.get("title") !== t.searchParams.get("title") || e.searchParams.get("curid") !== t.searchParams.get("curid")) && (await this.#t(), this.ctx.emit("current-page/popstate"), this.logger.info("location changed", t, this.wikiTitle));
1788
+ }
1789
+ #e;
1790
+ get params() {
1791
+ return this.url.searchParams;
1792
+ }
1793
+ get canonicalUrl() {
1794
+ const e = (dt('link[rel="alternate"][hreflang="x-default"]') || dt('link[rel="canonical"]'))?.href;
1795
+ let t = null;
1796
+ return e && (t = new URL(e, location.origin)), Reflect.defineProperty(this, "canonicalUrl", {
1797
+ get: () => t
1798
+ }), t;
1799
+ }
1800
+ async #n() {
1801
+ const t = this.wikiTitle?.getMainDBKey() === this.ctx.wiki.mainPageName;
1802
+ return Reflect.defineProperty(this, "isMainPage", {
1803
+ get: () => t
1804
+ }), t;
1805
+ }
1806
+ async #s() {
1807
+ let e = null;
1808
+ 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", {
1809
+ get: () => e
1810
+ }), e;
1811
+ }
1812
+ get wikiAction() {
1813
+ return this.params.get("action") || "view";
1814
+ }
1815
+ };
1816
+ qe = pr(Dt);
1817
+ de = br(qe, 0, "CurrentPageService", jt, de);
1818
+ wr(qe, 1, de);
1819
+ let vr = de;
1820
+ class _r extends z {
1821
+ constructor(e) {
1822
+ super(e, "resourceLoader", !0), this.ctx = e;
1823
+ }
1824
+ stop() {
1825
+ this.removeAll();
1826
+ }
1827
+ loadScript(e, t) {
1828
+ if (!e)
1829
+ return Promise.resolve(null);
1830
+ const r = `script:${e}`, n = document.querySelector(`[data-ipe="${r}"]`);
1831
+ return n ? Promise.resolve(n) : new Promise((o, a) => {
1832
+ const f = document.createElement("script");
1833
+ f.src = e, f.dataset.ipe = r, t && Object.entries(t).forEach(([u, p]) => {
1834
+ typeof p > "u" || p === !1 || p === null ? f.removeAttribute(u) : f.setAttribute(u, p);
1835
+ }), document.body.appendChild(f), f.onload = () => o(f), f.onerror = (u) => a(u);
1836
+ });
1837
+ }
1838
+ loadStyle(e, t) {
1839
+ if (!e)
1840
+ return Promise.resolve(null);
1841
+ const r = `style:${e}`, n = document.querySelector(`[data-ipe="${r}"]`);
1842
+ return n ? Promise.resolve(n) : new Promise((o, a) => {
1843
+ const f = document.createElement("link");
1844
+ f.rel = "stylesheet", f.href = e, f.dataset.ipe = r, t && Object.entries(t).forEach(([p, y]) => {
1845
+ typeof y > "u" || y === !1 || y === null ? f.removeAttribute(p) : f.setAttribute(p, y);
1846
+ }), (document.querySelector('meta[name="ipe-styles"]') || (() => {
1847
+ const p = document.createElement("meta");
1848
+ return p.id = "ipe-styles", p.name = "ipe-styles", document.head.insertAdjacentElement("afterbegin", p), p;
1849
+ })()).before(f), f.onload = () => o(f), f.onerror = (p) => a(p);
1850
+ });
1851
+ }
1852
+ removeStyle(e) {
1853
+ const t = `style:${e}`, r = document.querySelector(`[data-ipe="${t}"]`);
1854
+ r && r.remove();
1855
+ }
1856
+ removeScript(e) {
1857
+ const t = `script:${e}`, r = document.querySelector(`[data-ipe="${t}"]`);
1858
+ r && r.remove();
1859
+ }
1860
+ removeAll() {
1861
+ document.querySelectorAll("[data-ipe]").forEach((e) => {
1862
+ e.remove();
1863
+ });
1864
+ }
1865
+ resolveImportPath(e) {
1866
+ return e.startsWith("http") || e.startsWith("//") ? e : import.meta.resolve(e);
1867
+ }
1868
+ }
1869
+ const xe = Object.keys;
1870
+ function xr(i) {
1871
+ return typeof i == "boolean";
1872
+ }
1873
+ function kr(i) {
1874
+ return i && typeof i.nodeType == "number";
1875
+ }
1876
+ function We(i) {
1877
+ return typeof i == "string";
1878
+ }
1879
+ function Tt(i) {
1880
+ return typeof i == "number";
1881
+ }
1882
+ function J(i) {
1883
+ return typeof i == "object" ? i !== null : ne(i);
1884
+ }
1885
+ function ne(i) {
1886
+ return typeof i == "function";
1887
+ }
1888
+ function Sr(i) {
1889
+ return !!(i && i.isComponent);
1890
+ }
1891
+ function $r(i) {
1892
+ return J(i) && typeof i.length == "number" && typeof i.nodeType != "number";
1893
+ }
1894
+ function De(i, e) {
1895
+ if (i)
1896
+ for (const t of xe(i))
1897
+ e(i[t], t);
1898
+ }
1899
+ function Er(i) {
1900
+ return J(i) && "current" in i;
1901
+ }
1902
+ const Te = {
1903
+ animationIterationCount: 0,
1904
+ borderImageOutset: 0,
1905
+ borderImageSlice: 0,
1906
+ borderImageWidth: 0,
1907
+ boxFlex: 0,
1908
+ boxFlexGroup: 0,
1909
+ boxOrdinalGroup: 0,
1910
+ columnCount: 0,
1911
+ columns: 0,
1912
+ flex: 0,
1913
+ flexGrow: 0,
1914
+ flexPositive: 0,
1915
+ flexShrink: 0,
1916
+ flexNegative: 0,
1917
+ flexOrder: 0,
1918
+ gridArea: 0,
1919
+ gridRow: 0,
1920
+ gridRowEnd: 0,
1921
+ gridRowSpan: 0,
1922
+ gridRowStart: 0,
1923
+ gridColumn: 0,
1924
+ gridColumnEnd: 0,
1925
+ gridColumnSpan: 0,
1926
+ gridColumnStart: 0,
1927
+ fontWeight: 0,
1928
+ lineClamp: 0,
1929
+ lineHeight: 0,
1930
+ opacity: 0,
1931
+ order: 0,
1932
+ orphans: 0,
1933
+ tabSize: 0,
1934
+ widows: 0,
1935
+ zIndex: 0,
1936
+ zoom: 0,
1937
+ // SVG-related properties
1938
+ fillOpacity: 0,
1939
+ floodOpacity: 0,
1940
+ stopOpacity: 0,
1941
+ strokeDasharray: 0,
1942
+ strokeDashoffset: 0,
1943
+ strokeMiterlimit: 0,
1944
+ strokeOpacity: 0,
1945
+ strokeWidth: 0
1946
+ };
1947
+ function Cr(i, e) {
1948
+ return i + e.charAt(0).toUpperCase() + e.substring(1);
1949
+ }
1950
+ const Ar = ["Webkit", "ms", "Moz", "O"];
1951
+ xe(Te).forEach((i) => {
1952
+ Ar.forEach((e) => {
1953
+ Te[Cr(e, i)] = 0;
1954
+ });
1955
+ });
1956
+ const Or = /* @__PURE__ */ Symbol.for("jsx-dom:type");
1957
+ var Nt = /* @__PURE__ */ (function(i) {
1958
+ return i.ShadowRoot = "ShadowRoot", i;
1959
+ })(Nt || {});
1960
+ function Pr(i) {
1961
+ return i != null && i[Or] === Nt.ShadowRoot;
1962
+ }
1963
+ const Ir = "http://www.w3.org/2000/svg", Lr = "http://www.w3.org/1999/xlink", Rr = "http://www.w3.org/XML/1998/namespace";
1964
+ function Mt(i) {
1965
+ return !xr(i) && i != null;
1966
+ }
1967
+ function Ne(i) {
1968
+ return Array.isArray(i) ? i.map(Ne).filter(Boolean).join(" ") : J(i) ? Symbol.iterator in i ? Ne(Array.from(i)) : xe(i).filter((e) => i[e]).join(" ") : Mt(i) ? "" + i : "";
1969
+ }
1970
+ const jr = {
1971
+ animate: 0,
1972
+ circle: 0,
1973
+ clipPath: 0,
1974
+ defs: 0,
1975
+ desc: 0,
1976
+ ellipse: 0,
1977
+ feBlend: 0,
1978
+ feColorMatrix: 0,
1979
+ feComponentTransfer: 0,
1980
+ feComposite: 0,
1981
+ feConvolveMatrix: 0,
1982
+ feDiffuseLighting: 0,
1983
+ feDisplacementMap: 0,
1984
+ feDistantLight: 0,
1985
+ feFlood: 0,
1986
+ feFuncA: 0,
1987
+ feFuncB: 0,
1988
+ feFuncG: 0,
1989
+ feFuncR: 0,
1990
+ feGaussianBlur: 0,
1991
+ feImage: 0,
1992
+ feMerge: 0,
1993
+ feMergeNode: 0,
1994
+ feMorphology: 0,
1995
+ feOffset: 0,
1996
+ fePointLight: 0,
1997
+ feSpecularLighting: 0,
1998
+ feSpotLight: 0,
1999
+ feTile: 0,
2000
+ feTurbulence: 0,
2001
+ filter: 0,
2002
+ foreignObject: 0,
2003
+ g: 0,
2004
+ image: 0,
2005
+ line: 0,
2006
+ linearGradient: 0,
2007
+ marker: 0,
2008
+ mask: 0,
2009
+ metadata: 0,
2010
+ path: 0,
2011
+ pattern: 0,
2012
+ polygon: 0,
2013
+ polyline: 0,
2014
+ radialGradient: 0,
2015
+ rect: 0,
2016
+ stop: 0,
2017
+ svg: 0,
2018
+ switch: 0,
2019
+ symbol: 0,
2020
+ text: 0,
2021
+ textPath: 0,
2022
+ tspan: 0,
2023
+ use: 0,
2024
+ view: 0
2025
+ }, Dr = /^(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)/;
2026
+ function Tr(i) {
2027
+ const e = document.createDocumentFragment();
2028
+ return ke(i.children, e), e;
2029
+ }
2030
+ function Nr(i, e, t) {
2031
+ e = {
2032
+ ...e,
2033
+ children: t
2034
+ };
2035
+ const r = new i(e), n = r.render();
2036
+ return "ref" in e && Ge(e.ref, r), n;
2037
+ }
2038
+ function P(i, e) {
2039
+ let { children: t, ...r } = e;
2040
+ !r.namespaceURI && jr[i] === 0 && (r = {
2041
+ ...r,
2042
+ namespaceURI: Ir
2043
+ });
2044
+ let n;
2045
+ if (We(i)) {
2046
+ if (n = r.namespaceURI ? document.createElementNS(r.namespaceURI, i) : document.createElement(i), Ur(r, n), ke(t, n), n instanceof window.HTMLSelectElement && r.value != null)
2047
+ if (r.multiple === !0 && Array.isArray(r.value)) {
2048
+ const s = r.value.map((o) => String(o));
2049
+ n.querySelectorAll("option").forEach(
2050
+ (o) => o.selected = s.includes(o.value)
2051
+ );
2052
+ } else
2053
+ n.value = r.value;
2054
+ Ge(r.ref, n);
2055
+ } else if (ne(i))
2056
+ J(i.defaultProps) && (r = {
2057
+ ...i.defaultProps,
2058
+ ...r
2059
+ }), n = Sr(i) ? Nr(i, r, t) : i({
2060
+ ...r,
2061
+ children: t
2062
+ });
2063
+ else
2064
+ throw new TypeError(`Invalid JSX element type: ${i}`);
2065
+ return n;
2066
+ }
2067
+ function Ge(i, e) {
2068
+ Er(i) ? i.current = e : ne(i) && i(e);
2069
+ }
2070
+ function ke(i, e) {
2071
+ if ($r(i))
2072
+ Mr(i, e);
2073
+ else if (We(i) || Tt(i))
2074
+ Ee(document.createTextNode(i), e);
2075
+ else if (i === null)
2076
+ Ee(document.createComment(""), e);
2077
+ else if (kr(i))
2078
+ Ee(i, e);
2079
+ else if (Pr(i)) {
2080
+ const t = e.attachShadow(i.attr);
2081
+ ke(i.children, t), Ge(i.ref, t);
2082
+ }
2083
+ }
2084
+ function Mr(i, e) {
2085
+ for (const t of [...i])
2086
+ ke(t, e);
2087
+ return e;
2088
+ }
2089
+ function Ee(i, e) {
2090
+ e instanceof window.HTMLTemplateElement ? e.content.appendChild(i) : e.appendChild(i);
2091
+ }
2092
+ function le(i, e) {
2093
+ return i.replace(/[A-Z]/g, (t) => e + t.toLowerCase());
2094
+ }
2095
+ function Bt(i, e) {
2096
+ e == null || e === !1 || (Array.isArray(e) ? e.forEach((t) => Bt(i, t)) : We(e) ? i.setAttribute("style", e) : J(e) && De(e, (t, r) => {
2097
+ r.indexOf("-") === 0 ? i.style.setProperty(r, t) : Tt(t) && Te[r] !== 0 ? i.style[r] = t + "px" : i.style[r] = t;
2098
+ }));
2099
+ }
2100
+ function Br(i, e, t) {
2101
+ switch (i) {
2102
+ case "xlinkActuate":
2103
+ case "xlinkArcrole":
2104
+ case "xlinkHref":
2105
+ case "xlinkRole":
2106
+ case "xlinkShow":
2107
+ case "xlinkTitle":
2108
+ case "xlinkType":
2109
+ pt(t, Lr, le(i, ":"), e);
2110
+ return;
2111
+ case "xmlnsXlink":
2112
+ X(t, le(i, ":"), e);
2113
+ return;
2114
+ case "xmlBase":
2115
+ case "xmlLang":
2116
+ case "xmlSpace":
2117
+ pt(t, Rr, le(i, ":"), e);
2118
+ return;
2119
+ }
2120
+ switch (i) {
2121
+ case "htmlFor":
2122
+ X(t, "for", e);
2123
+ return;
2124
+ case "dataset":
2125
+ De(e, (r, n) => {
2126
+ r != null && (t.dataset[n] = r);
2127
+ });
2128
+ return;
2129
+ case "innerHTML":
2130
+ case "innerText":
2131
+ case "textContent":
2132
+ Mt(e) && (t[i] = e);
2133
+ return;
2134
+ case "dangerouslySetInnerHTML":
2135
+ J(e) && (t.innerHTML = e.__html);
2136
+ return;
2137
+ case "value":
2138
+ if (e == null || t instanceof window.HTMLSelectElement)
2139
+ return;
2140
+ if (t instanceof window.HTMLTextAreaElement) {
2141
+ t.value = e;
2142
+ return;
2143
+ }
2144
+ break;
2145
+ case "spellCheck":
2146
+ t.spellcheck = e;
2147
+ return;
2148
+ case "class":
2149
+ case "className":
2150
+ ne(e) ? e(t) : X(t, "class", Ne(e));
2151
+ return;
2152
+ case "ref":
2153
+ case "namespaceURI":
2154
+ return;
2155
+ case "style":
2156
+ Bt(t, e);
2157
+ return;
2158
+ case "on":
2159
+ case "onCapture":
2160
+ De(e, (r, n) => {
2161
+ t.addEventListener(n, r, i === "onCapture");
2162
+ });
2163
+ return;
2164
+ }
2165
+ if (ne(e)) {
2166
+ if (i[0] === "o" && i[1] === "n") {
2167
+ let r = i.toLowerCase();
2168
+ const n = r.endsWith("capture");
2169
+ if (r === "ondoubleclick" ? r = "ondblclick" : n && r === "ondoubleclickcapture" && (r = "ondblclickcapture"), !n && t[r] === null)
2170
+ t[r] = e;
2171
+ else if (n)
2172
+ t.addEventListener(
2173
+ r.substring(2, r.length - 7),
2174
+ e,
2175
+ !0
2176
+ );
2177
+ else {
2178
+ let s;
2179
+ r in window ? s = r.substring(2) : s = r[2] + i.slice(3), t.addEventListener(s, e);
2180
+ }
2181
+ }
2182
+ } else J(e) ? t[i] = e : e === !0 ? X(t, i, "") : e !== !1 && e != null && (t instanceof SVGElement && !Dr.test(i) ? X(t, le(i, "-"), e) : X(t, i, e));
2183
+ }
2184
+ function X(i, e, t) {
2185
+ i.setAttribute(e, t);
2186
+ }
2187
+ function pt(i, e, t, r) {
2188
+ i.setAttributeNS(e, t, r);
2189
+ }
2190
+ function Ur(i, e) {
2191
+ for (const t of xe(i))
2192
+ Br(t, i[t], e);
2193
+ return e;
2194
+ }
2195
+ var Ve = /* @__PURE__ */ ((i) => (i.Init = "modal.init", i.BeforeShow = "modal.beforeShow", i.Show = "modal.show", i.BeforeClose = "modal.beforeClose", i.Close = "modal.close", i.Destroy = "modal.destroy", i.ToastShow = "toast.show", i.ToastClose = "toast.close", i))(Ve || {});
2196
+ let Fr = 0;
2197
+ const gt = (i) => `${i}-${++Fr}`;
2198
+ function ee(i) {
2199
+ return i instanceof Node ? i : document.createTextNode(String(i));
2200
+ }
2201
+ function H(i, e) {
2202
+ if (!i) throw new Error(`${e ?? "Element"} not found`);
2203
+ return i;
2204
+ }
2205
+ function mt(i) {
2206
+ const e = [
2207
+ "a[href]",
2208
+ "button:not([disabled])",
2209
+ "input:not([disabled])",
2210
+ "select:not([disabled])",
2211
+ "textarea:not([disabled])",
2212
+ '[tabindex]:not([tabindex="-1"])'
2213
+ ].join(",");
2214
+ return Array.from(i.querySelectorAll(e)).filter(
2215
+ (t) => !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length)
2216
+ );
2217
+ }
2218
+ function D(i, e = {}) {
2219
+ const t = document.createElement(i);
2220
+ if (e.className && (t.className = e.className), e.html != null && (t.innerHTML = e.html), e.text != null && (t.textContent = e.text), e.attrs)
2221
+ for (const [r, n] of Object.entries(e.attrs)) t.setAttribute(r, n);
2222
+ return t;
2223
+ }
2224
+ const zr = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform), Ut = ["ctrl", "alt", "shift", "meta"];
2225
+ function Hr(i) {
2226
+ if (!i) return null;
2227
+ const e = String(i).trim().toLowerCase().split(/[+\-\s]+/g).filter(Boolean), t = [];
2228
+ let r = null;
2229
+ const n = (o) => {
2230
+ t.includes(o) || t.push(o);
2231
+ };
2232
+ for (const o of e) {
2233
+ let a = o;
2234
+ if (a === "control" || a === "ctrl") {
2235
+ n("ctrl");
2236
+ continue;
2237
+ }
2238
+ if (a === "alt" || a === "option") {
2239
+ n("alt");
2240
+ continue;
2241
+ }
2242
+ if (a === "shift") {
2243
+ n("shift");
2244
+ continue;
2245
+ }
2246
+ if (a === "meta" || a === "cmd" || a === "command" || a === "super") {
2247
+ n("meta");
2248
+ continue;
2249
+ }
2250
+ if (a === "mod") {
2251
+ n(zr ? "meta" : "ctrl");
2252
+ continue;
2253
+ }
2254
+ a === "esc" && (a = "escape"), a === "return" && (a = "enter"), (a === "space" || a === "spacebar") && (a = "space"), r = a;
2255
+ }
2256
+ const s = Ut.filter((o) => t.includes(o));
2257
+ return !r || r === "" ? s.length ? s.join("+") : null : s.length ? `${s.join("+")}+${r}` : r;
2258
+ }
2259
+ function Kr(i) {
2260
+ const e = [];
2261
+ i.ctrlKey && e.push("ctrl"), i.altKey && e.push("alt"), i.shiftKey && e.push("shift"), i.metaKey && e.push("meta");
2262
+ let t = i.key;
2263
+ t === " " && (t = "space");
2264
+ const r = (t.length, t.toLowerCase()), n = Ut.filter((s) => e.includes(s));
2265
+ return n.length ? `${n.join("+")}+${r}` : r;
2266
+ }
2267
+ class qr {
2268
+ constructor() {
2269
+ this.zBase = 1e3, this.stack = [];
2270
+ }
2271
+ push(e) {
2272
+ this.stack.push(e), this.syncZ();
2273
+ }
2274
+ remove(e) {
2275
+ this.stack = this.stack.filter((t) => t !== e), this.syncZ();
2276
+ }
2277
+ top() {
2278
+ return this.stack[this.stack.length - 1];
2279
+ }
2280
+ closeAll(e, t) {
2281
+ const r = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), n = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
2282
+ [...this.stack].reverse().forEach((s) => {
2283
+ const o = s.modalId, a = n.size ? n.has(s.pluginName) : !0, f = r.has(o);
2284
+ a && !f && s.close();
2285
+ });
2286
+ }
2287
+ removeAll() {
2288
+ [...this.stack].forEach((e) => e.destroy()), this.stack = [];
2289
+ }
2290
+ syncZ() {
2291
+ this.stack.forEach((e, t) => e.setZIndex(this.zBase + t * 2));
2292
+ }
2293
+ lockBodyScroll() {
2294
+ document.body.classList.add("ipe-modal-no-scroll");
2295
+ }
2296
+ unlockBodyScroll() {
2297
+ document.body.classList.remove("ipe-modal-no-scroll");
2298
+ }
2299
+ }
2300
+ const T = new qr();
2301
+ class pe {
2302
+ constructor(e = {}) {
2303
+ this.backdropId = gt("ipe-modal-backdrop"), this.modalId = gt("ipe-modal"), this.numberId = this.modalId.split("-")[1], this._isDestroyed = !1, this.pluginName = "normalModal", this.buttonElsLeft = [], this.buttonElsRight = [], this.keyMap = /* @__PURE__ */ new Map(), this.isOpen = !1, this.isToast = !1, this.isDragging = !1, this.dragStartX = 0, this.dragStartY = 0, this.modalStartX = 0, this.modalStartY = 0, this.Event = Ve, this._hooks = [], this.startCloseTimer = (t) => {
2304
+ this.stopCloseTimer(), this.closeTimer = window.setTimeout(() => this.close(), t);
2305
+ }, this.stopCloseTimer = () => {
2306
+ this.closeTimer && window.clearTimeout(this.closeTimer), this.closeTimer = void 0;
2307
+ }, this.onDragMove = (t) => {
2308
+ if (!this.isDragging) return;
2309
+ t.preventDefault();
2310
+ const r = t.clientX - this.dragStartX, n = t.clientY - this.dragStartY, s = this.get$modal(), o = this.modalStartX + r, a = this.modalStartY + n;
2311
+ s.style.left = `${o}px`, s.style.top = `${a}px`;
2312
+ }, this.onDragEnd = () => {
2313
+ if (!this.isDragging) return;
2314
+ this.isDragging = !1, document.removeEventListener("pointermove", this.onDragMove), document.removeEventListener("pointerup", this.onDragEnd);
2315
+ const t = this.get$modal(), r = this.get$window();
2316
+ t.classList.remove("is-dragging"), r.style.animation = "none", requestAnimationFrame(() => {
2317
+ this.applyAnimation(!0);
2318
+ });
2319
+ }, this.options = { ...pe.DEFAULT_OPTIONS, ...e }, this.options.backdrop === !1 && e.bodyScroll === void 0 && (this.options.bodyScroll = !0);
2320
+ }
2321
+ get isDestroyed() {
2322
+ return this._isDestroyed;
2323
+ }
2324
+ static {
2325
+ this.DEFAULT_OPTIONS = {
2326
+ className: "",
2327
+ sizeClass: "auto",
2328
+ center: !0,
2329
+ fitScreen: !1,
2330
+ closeIcon: !0,
2331
+ bodyScroll: !1,
2332
+ outSideClose: !0,
2333
+ backdrop: !0,
2334
+ animation: {
2335
+ show: "ipe-modal-fade-in",
2336
+ hide: "ipe-modal-fade-out"
2337
+ },
2338
+ animationSpeed: 200
2339
+ };
2340
+ }
2341
+ static extends(e = {}) {
2342
+ return class extends this {
2343
+ constructor(t = {}) {
2344
+ super({ ...e, ...t });
2345
+ }
2346
+ };
2347
+ }
2348
+ // ------------------------------ lifecycle ------------------------------ //
2349
+ init() {
2350
+ if (this.$modal) return this;
2351
+ const e = this.options.backdrop !== !1;
2352
+ let t;
2353
+ e && (t = D("div", {
2354
+ className: "ipe-modal-backdrop",
2355
+ attrs: { id: this.backdropId, "data-modal-id": this.modalId }
2356
+ }));
2357
+ const r = D("div", {
2358
+ className: "ipe-modal-modal",
2359
+ attrs: { id: this.modalId, role: "dialog", "aria-modal": "true", tabindex: "-1" }
2360
+ });
2361
+ if (r.modal = this, !e) {
2362
+ r.classList.add("no-backdrop");
2363
+ const g = window.pageYOffset || document.documentElement.scrollTop, w = window.pageXOffset || document.documentElement.scrollLeft, O = window.innerWidth;
2364
+ r.style.top = `${g + 60}px`, this.once("modal.show", () => {
2365
+ r.style.left = `${w + O / 2 - r.offsetWidth / 2}px`;
2366
+ });
2367
+ }
2368
+ const n = D("div", {
2369
+ className: `ipe-modal-modal__window size--${this.options.sizeClass || "auto"} plugin--${this.pluginName}`
2370
+ });
2371
+ n.modal = this;
2372
+ const s = D("div", { className: "ipe-modal-modal__header" }), o = `${this.modalId}-title`, a = D("h2", {
2373
+ className: "ipe-modal-modal__title",
2374
+ attrs: { id: o, role: "heading", "aria-level": "2" }
2375
+ });
2376
+ r.setAttribute("aria-labelledby", o);
2377
+ const f = D("div", { className: "ipe-modal-modal__icons" });
2378
+ if (this.options.closeIcon) {
2379
+ const g = D("button", {
2380
+ className: "ipe-modal-modal__close",
2381
+ attrs: { type: "button", "aria-label": "Close" },
2382
+ html: "&times;"
2383
+ });
2384
+ g.addEventListener("click", () => {
2385
+ let w = !0;
2386
+ typeof this.options.onClickClose == "function" ? this.options.onClickClose(this) === !1 && (w = !1) : this.options.onClickClose === !1 && (w = !1), w && this.close();
2387
+ }), f.appendChild(g);
2388
+ }
2389
+ s.append(a, f), this.options.draggable && e && (this.options.draggable = !1), this.options.draggable && (s.style.cursor = "move", s.style.userSelect = "none", s.addEventListener("pointerdown", this.onDragStart.bind(this)), r.classList.add("is-draggable"));
2390
+ const u = D("div", { className: "ipe-modal-modal__content" }), p = D("div", { className: "ipe-modal-modal__footer" }), y = D("div", {
2391
+ className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--left"
2392
+ }), _ = D("div", {
2393
+ className: "ipe-modal-modal__buttons ipe-modal-modal__buttons--right"
2394
+ });
2395
+ return p.append(y, _), n.append(s, u, p), r.appendChild(n), this.$backdrop = t, this.$modal = r, this.$window = n, this.$header = s, this.$title = a, this.$icons = f, this.$content = u, this.$footer = p, this.$buttonsLeft = y, this.$buttonsRight = _, 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) : p.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("pointerup", (g) => {
2396
+ this.options.outSideClose && g.target === t && this.close();
2397
+ }), this.options.draggable && n.addEventListener("pointerdown", (g) => {
2398
+ g.target && n.contains(g.target) && this.bringToFront();
2399
+ }), this.onKeyDown = this.onKeyDown.bind(this), this.emit(
2400
+ "modal.init"
2401
+ /* Init */
2402
+ ), this;
2403
+ }
2404
+ show() {
2405
+ if (this.$modal || this.init(), !this.$modal) throw new Error("Failed to initialize modal");
2406
+ if (this.isOpen) return this;
2407
+ {
2408
+ const r = this.emit("modal.beforeShow", !0), n = this.options.beforeShow ? this.options.beforeShow(this) !== !1 : !0;
2409
+ if (!r || !n) return this;
2410
+ }
2411
+ this.lastFocused = document.activeElement ?? null, this.$backdrop && document.body.appendChild(this.$backdrop), document.body.appendChild(this.$modal), this.shouldLockBodyOnOpen() && T.lockBodyScroll(), requestAnimationFrame(() => {
2412
+ this.$backdrop?.classList.add("is-open"), this.$modal.classList.add("is-open"), this.applyAnimation(!0), this.focusFirst();
2413
+ }), document.addEventListener("keydown", this.onKeyDown), T.push(this), this.isOpen = !0, this.options.onShow?.(this), this.emit(
2414
+ "modal.show"
2415
+ /* Show */
2416
+ );
2417
+ 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;
2418
+ return e && (this.startCloseTimer(e), t && (this.$window?.addEventListener("mouseenter", this.stopCloseTimer), this.$window?.addEventListener("mouseleave", () => this.startCloseTimer(e)))), this;
2419
+ }
2420
+ close() {
2421
+ if (!this.isOpen) return this;
2422
+ {
2423
+ const s = this.emit("modal.beforeClose", !0), o = this.options.beforeClose ? this.options.beforeClose(this) !== !1 : !0;
2424
+ if (!s || !o) return this;
2425
+ }
2426
+ if (this.isToast) {
2427
+ this.applyAnimation(!1), this.emit(
2428
+ "modal.close"
2429
+ /* Close */
2430
+ ), this.emit(
2431
+ "toast.close"
2432
+ /* ToastClose */
2433
+ );
2434
+ const s = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
2435
+ let o = !1;
2436
+ const a = () => {
2437
+ o || (o = !0, this.destroy(), this.options.onClose?.(this));
2438
+ }, f = (u, p) => {
2439
+ const y = () => {
2440
+ u.removeEventListener(p, y), a();
2441
+ };
2442
+ u.addEventListener(p, y, { once: !0 });
2443
+ };
2444
+ return s > 0 && this.$window ? (f(this.$window, "transitionend"), f(this.$window, "animationend"), window.setTimeout(a, s + 20)) : window.setTimeout(a, s), this;
2445
+ }
2446
+ this.applyAnimation(!1), this.$backdrop?.classList.remove("is-open"), this.$modal?.classList.remove("is-open"), this.emit(
2447
+ "modal.close"
2448
+ /* Close */
2449
+ );
2450
+ const e = this.isAnimationDisabled() ? 0 : this.options.animationSpeed ?? 200;
2451
+ let t = !1;
2452
+ const r = () => {
2453
+ t || (t = !0, this.destroy(), this.options.onClose?.(this));
2454
+ }, n = (s, o) => {
2455
+ const a = () => {
2456
+ s.removeEventListener(o, a), r();
2457
+ };
2458
+ s.addEventListener(o, a, { once: !0 });
2459
+ };
2460
+ return e > 0 && this.$window ? (n(this.$window, "transitionend"), n(this.$window, "animationend"), window.setTimeout(r, e + 20)) : window.setTimeout(r, e), this;
2461
+ }
2462
+ /** Immediately removes DOM and listeners */
2463
+ destroy() {
2464
+ if (this._isDestroyed) return this;
2465
+ if (this.stopCloseTimer(), document.removeEventListener("keydown", this.onKeyDown), this.isDragging && this.onDragEnd(), this.$window?.removeEventListener("mouseenter", this.stopCloseTimer), this.isToast) {
2466
+ this.$window?.parentElement && this.$window.parentElement.removeChild(this.$window);
2467
+ const e = V.indexOf(this);
2468
+ e !== -1 && V.splice(e, 1);
2469
+ } else
2470
+ this.$backdrop?.parentElement && this.$backdrop.parentElement.removeChild(this.$backdrop), this.$modal?.parentElement && this.$modal.parentElement.removeChild(this.$modal), T.remove(this), this.shouldUnlockBodyOnClose() && T.unlockBodyScroll();
2471
+ return this.isOpen = !1, this.lastFocused?.focus?.(), this.emit(
2472
+ "modal.destroy"
2473
+ /* Destroy */
2474
+ ), this._isDestroyed = !0, this;
2475
+ }
2476
+ // ------------------------------ getters ------------------------------- //
2477
+ get$backdrop() {
2478
+ return this.$backdrop;
2479
+ }
2480
+ get$modal() {
2481
+ return H(this.$modal, "modal");
2482
+ }
2483
+ get$window() {
2484
+ return H(this.$window, "window");
2485
+ }
2486
+ get$header() {
2487
+ return H(this.$header, "header");
2488
+ }
2489
+ get$title() {
2490
+ return H(this.$title, "title");
2491
+ }
2492
+ get$content() {
2493
+ return H(this.$content, "content");
2494
+ }
2495
+ get$icons() {
2496
+ return H(this.$icons, "icons");
2497
+ }
2498
+ get$buttons(e) {
2499
+ return e === "leftButtons" ? H(this.$buttonsLeft, "leftButtons") : e === "rightButtons" ? H(this.$buttonsRight, "rightButtons") : H(this.$footer, "buttons");
2500
+ }
2501
+ // ------------------------------ content ------------------------------- //
2502
+ setTitle(e) {
2503
+ const t = this.get$title();
2504
+ return t.innerHTML = "", t.append(ee(e)), this;
2505
+ }
2506
+ setContent(e, t = "replace") {
2507
+ const r = this.get$content();
2508
+ return t === "replace" ? (r.innerHTML = "", r.append(ee(e))) : t === "append" ? r.append(ee(e)) : r.prepend(ee(e)), this;
2509
+ }
2510
+ setIcons(e) {
2511
+ const t = this.get$icons();
2512
+ t.innerHTML = "";
2513
+ for (const r of e) {
2514
+ const n = D("button", {
2515
+ className: `ipe-modal-modal__icon ${r.className}`,
2516
+ attrs: { type: "button" }
2517
+ });
2518
+ n.addEventListener("click", r.method), t.appendChild(n);
2519
+ }
2520
+ return this;
2521
+ }
2522
+ setButtons(e, t) {
2523
+ const r = this.$buttonsLeft, n = this.$buttonsRight;
2524
+ [r, n].forEach((o) => o.innerHTML = ""), this.buttonElsLeft = [], this.buttonElsRight = [], this.keyMap.clear();
2525
+ const s = t ?? this.$footer;
2526
+ if (s === this.$footer)
2527
+ e.forEach((o) => this.addButton(o)), e.length === 0 && (this.$footer.style.display = "none");
2528
+ else {
2529
+ s.innerHTML = "";
2530
+ for (const o of e) {
2531
+ const a = this.generateButton(o);
2532
+ s.appendChild(a);
2533
+ }
2534
+ }
2535
+ return this;
2536
+ }
2537
+ generateButton(e) {
2538
+ const t = e.type ?? "button", r = t === "link" ? D("a") : D("button", { attrs: { type: "button" } });
2539
+ e.id && (r.id = e.id), r.className = `ipe-modal-btn ${e.className ?? ""}`.trim();
2540
+ const n = ee(e.label ?? "OK");
2541
+ if (r.append(n), t === "link" && e.href && (r.href = e.href), e.method && r.addEventListener("click", (s) => {
2542
+ if (r._ipe_tmpDisabled) {
2543
+ s.preventDefault(), s.stopPropagation();
2544
+ return;
2545
+ }
2546
+ e.method.call(r, s, this);
2547
+ }), typeof e.closeAfter == "number" && e.closeAfter >= 0 && r.addEventListener("click", () => {
2548
+ window.setTimeout(() => this.close(), e.closeAfter);
2549
+ }), typeof e.enableAfter == "number" && e.enableAfter > 0) {
2550
+ t === "button" && r.setAttribute("disabled", "true"), r._ipe_tmpDisabled = !0, r.setAttribute("aria-disabled", "true");
2551
+ const s = () => {
2552
+ t === "button" && r.removeAttribute("disabled"), delete r._ipe_tmpDisabled, r.removeAttribute("aria-disabled");
2553
+ };
2554
+ window.setTimeout(s, e.enableAfter);
2555
+ }
2556
+ if (e.keyPress) {
2557
+ const s = String(e.keyPress).split(/[\,\|]+/g).map((o) => o.trim()).filter(Boolean);
2558
+ for (const o of s) {
2559
+ const a = Hr(o);
2560
+ a && this.keyMap.set(a, r);
2561
+ }
2562
+ }
2563
+ return r;
2564
+ }
2565
+ /** Dynamically add button(s) into footer. Supports insertion index per side. */
2566
+ addButton(e, t) {
2567
+ this.$footer && (this.$footer.style.display = "");
2568
+ const r = e.side ?? "right", n = r === "left" ? this.$buttonsLeft : this.$buttonsRight, s = r === "left" ? this.buttonElsLeft : this.buttonElsRight, o = this.generateButton(e), a = Math.max(0, Math.min(t ?? s.length, s.length));
2569
+ return a >= n.children.length ? n.appendChild(o) : n.insertBefore(o, n.children[a]), s.splice(a, 0, o), this;
2570
+ }
2571
+ /** Remove button by element / id / global index (left first, then right). */
2572
+ removeButton(e) {
2573
+ const t = this.buttonElsLeft, r = this.buttonElsRight, n = [...t, ...r];
2574
+ let s = null;
2575
+ if (e === "*")
2576
+ return n.forEach((a) => {
2577
+ this.keyMap.delete(a.id), a.parentElement?.removeChild(a);
2578
+ }), this.$footer && (this.$footer.style.display = "none"), this;
2579
+ if (typeof e == "number" ? s = n[e] ?? null : typeof e == "string" ? s = n.find((a) => a.id === e) ?? null : e instanceof HTMLElement && (s = n.find((a) => a === e) ?? null), !s) return this;
2580
+ for (const [a, f] of this.keyMap.entries()) f === s && this.keyMap.delete(a);
2581
+ let o = t.indexOf(s);
2582
+ return o !== -1 ? (t.splice(o, 1), s.parentElement?.removeChild(s)) : (o = r.indexOf(s), o !== -1 && (r.splice(o, 1), s.parentElement?.removeChild(s))), t.length === 0 && r.length === 0 && this.$footer && (this.$footer.style.display = "none"), this;
2583
+ }
2584
+ changePreviewState() {
2585
+ return this.get$modal().classList.toggle("is-fullscreen"), this;
2586
+ }
2587
+ setModalHeight(e, t = "height") {
2588
+ const r = this.get$window(), n = Math.max(0, window.innerHeight - e);
2589
+ return r.style[t] = `${n}px`, n;
2590
+ }
2591
+ setOptions(e, t) {
2592
+ return typeof e == "string" ? this.options[e] = t : Object.assign(this.options, e), this;
2593
+ }
2594
+ setPluginName(e) {
2595
+ return this.$window && (this.$window.className = this.$window.className.replace(
2596
+ `plugin--${this.pluginName}`,
2597
+ `plugin--${e}`
2598
+ )), this.pluginName = e, this;
2599
+ }
2600
+ // ------------------------------ helpers ------------------------------- //
2601
+ applyAnimation(e) {
2602
+ const t = this.get$modal(), r = this.get$window(), n = this.$backdrop, s = this.options.modalAnimation ?? this.options.animation, o = typeof s == "string" ? s : s && (e ? s.show : s.hide), a = this.options.backdropAnimation ?? this.options.animation, f = typeof a == "string" ? a : a && (e ? a.show : a.hide);
2603
+ !o || o === !1 ? (t.style.transition = "none", r.style.animation = "none", r.style.removeProperty("--ipe-modal-anim")) : (t.style.removeProperty("transition"), r.style.setProperty("--ipe-modal-anim", o)), n && (!f || f === !1 ? n.style.transition = "none" : n.style.removeProperty("transition"));
2604
+ }
2605
+ on(e, t) {
2606
+ return this._hooks.push({ type: e, listener: t }), () => this.off(e, t);
2607
+ }
2608
+ off(e, t) {
2609
+ return this._hooks = this._hooks.filter(
2610
+ (r) => r.type !== e && (t ? r.listener !== t : !0)
2611
+ ), this;
2612
+ }
2613
+ once(e, t) {
2614
+ const r = this.on(e, (n) => (r(), t(n)));
2615
+ return r;
2616
+ }
2617
+ emit(e, t) {
2618
+ const r = this._hooks.filter((a) => a.type === e);
2619
+ let n = !0;
2620
+ for (const a of r) {
2621
+ const f = new CustomEvent(e, { detail: this, cancelable: t }), u = a.listener(f);
2622
+ if (f.defaultPrevented && (n = !1), u === !1 && (n = !1), !n) break;
2623
+ }
2624
+ const s = this.$modal ?? document.body, o = new CustomEvent(e, { detail: this, cancelable: t });
2625
+ return (!s.dispatchEvent(o) || o.defaultPrevented) && (n = !1), n;
2626
+ }
2627
+ focusFirst() {
2628
+ const e = this.get$modal(), t = mt(e);
2629
+ t.length ? t[0].focus() : e.focus({ preventScroll: !0 });
2630
+ }
2631
+ onKeyDown(e) {
2632
+ if (T.top() !== this) return;
2633
+ if (e.key === "Escape") {
2634
+ e.preventDefault(), this.close();
2635
+ return;
2636
+ }
2637
+ const t = this.get$modal();
2638
+ if (!t.contains(document.activeElement)) return;
2639
+ if (e.key === "Tab") {
2640
+ const a = mt(t);
2641
+ if (!a.length) return;
2642
+ const f = a[0], u = a[a.length - 1], p = document.activeElement;
2643
+ e.shiftKey && p === f ? (e.preventDefault(), u.focus()) : !e.shiftKey && p === u && (e.preventDefault(), f.focus());
2644
+ }
2645
+ const r = e.ctrlKey || e.altKey || e.metaKey, n = e.target;
2646
+ if (!r && (n && ["INPUT", "TEXTAREA"].includes(n.tagName) || n.contentEditable === "true"))
2647
+ return;
2648
+ const s = Kr(e), o = this.keyMap.get(s);
2649
+ if (o) {
2650
+ e.preventDefault(), o.click();
2651
+ return;
2652
+ }
2653
+ }
2654
+ setZIndex(e) {
2655
+ this.$backdrop && (this.$backdrop.style.zIndex = String(e)), this.$modal && (this.$modal.style.zIndex = String(e + 1));
2656
+ }
2657
+ /** Bring this modal to the top of the stack. */
2658
+ bringToFront() {
2659
+ return T.remove(this), T.push(this), this;
2660
+ }
2661
+ isAnimationDisabled() {
2662
+ const e = this.options.modalAnimation ?? this.options.animation;
2663
+ return e === !1 || e == null;
2664
+ }
2665
+ shouldLockBodyOnOpen() {
2666
+ return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !T.stack.some(
2667
+ (e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
2668
+ );
2669
+ }
2670
+ shouldUnlockBodyOnClose() {
2671
+ return this.options.backdrop === !1 || this.options.bodyScroll !== !1 ? !1 : !T.stack.some(
2672
+ (e) => e !== this && e.options.backdrop !== !1 && e.options.bodyScroll === !1
2673
+ );
2674
+ }
2675
+ // ------------------------------ drag handlers ------------------------------- //
2676
+ onDragStart(e) {
2677
+ if (this.options.backdrop !== !1 || !this.options.draggable) return;
2678
+ e.preventDefault(), this.isDragging = !0, this.bringToFront(), this.dragStartX = e.clientX, this.dragStartY = e.clientY;
2679
+ const t = this.get$modal(), r = t.getBoundingClientRect();
2680
+ this.modalStartX = r.left + window.pageXOffset, this.modalStartY = r.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");
2681
+ }
2682
+ // ------------------------------ toast ------------------------------- //
2683
+ /** Show as toast (no backdrop, container stack). */
2684
+ showToast(e) {
2685
+ this.$window || this.init();
2686
+ const t = Wr(e.position ?? "top right"), r = this.get$window();
2687
+ this.isToast = !0, r.style.pointerEvents = "auto", this.applyAnimation(!0), t.appendChild(r);
2688
+ const n = (typeof this.options.closeAfter == "number" ? this.options.closeAfter : this.options.closeAfter?.time) ?? 3e3, s = (typeof this.options.closeAfter == "number" ? !0 : this.options.closeAfter?.resetOnHover) ?? !0;
2689
+ return n > 0 && (this.startCloseTimer(n), s && (r.addEventListener("mouseenter", this.stopCloseTimer), r.addEventListener("mouseleave", () => this.startCloseTimer(n)))), this.isOpen = !0, this.options.onShow?.(this), V.push(this), this.emit(
2690
+ "toast.show"
2691
+ /* ToastShow */
2692
+ ), this.emit(
2693
+ "modal.show"
2694
+ /* Show */
2695
+ ), this;
2696
+ }
2697
+ // ------------------------------ static helpers --------------------------- //
2698
+ static show(e, t) {
2699
+ return new this(e).init().show();
2700
+ }
2701
+ static createObject(e, t) {
2702
+ return new this(e);
2703
+ }
2704
+ static close(e) {
2705
+ if (!e) {
2706
+ const s = T.top();
2707
+ return s?.close(), s;
2708
+ }
2709
+ const t = typeof e == "string" ? e : e.id, r = T.stack.find((s) => s.modalId === t);
2710
+ if (r)
2711
+ return r.close(), r;
2712
+ const n = V.find((s) => s.modalId === t);
2713
+ return n?.close(), n;
2714
+ }
2715
+ static closeAll(e, t) {
2716
+ const r = new Set((Array.isArray(t) ? t : t ? [t] : []).map(String)), n = new Set((Array.isArray(e) ? e : e ? [e] : []).map(String));
2717
+ return T.closeAll(e, t), [...V].forEach((s) => {
2718
+ const o = s.modalId, a = n.size ? n.has(s.pluginName) : !0, f = r.has(o);
2719
+ a && !f && s.close();
2720
+ }), T.top() ?? new pe();
2721
+ }
2722
+ static removeAll() {
2723
+ T.removeAll(), [...V].forEach((e) => e.destroy());
2724
+ }
2725
+ static dialog(e, t) {
2726
+ const r = new this({
2727
+ sizeClass: "dialog",
2728
+ buttons: [
2729
+ {
2730
+ label: "OK",
2731
+ className: "is-primary is-ghost",
2732
+ method: (n, s) => {
2733
+ t?.(n, s), n.defaultPrevented || r.close();
2734
+ },
2735
+ keyPress: "Enter"
2736
+ }
2737
+ ],
2738
+ ...e
2739
+ });
2740
+ return r.init().show();
2741
+ }
2742
+ static confirm(e, t) {
2743
+ e.title ??= "Confirm", e.content ??= "Are you sure you want to perform this action?";
2744
+ const r = e.okBtn ?? { label: "OK", className: "is-primary is-ghost" }, n = e.cancelBtn ?? { label: "Cancel", className: "is-danger is-ghost" };
2745
+ return new this({
2746
+ sizeClass: "dialog",
2747
+ ...e,
2748
+ buttons: [
2749
+ {
2750
+ label: n.label,
2751
+ className: n.className,
2752
+ keyPress: "n",
2753
+ method: (s, o) => {
2754
+ t?.(!1, o, s), o.close();
2755
+ }
2756
+ },
2757
+ {
2758
+ label: r.label,
2759
+ className: r.className,
2760
+ keyPress: "y",
2761
+ method: (s, o) => {
2762
+ t?.(!0, o, s), s.defaultPrevented || o.close();
2763
+ }
2764
+ }
2765
+ ]
2766
+ }).init().show();
2767
+ }
2768
+ static getDefaultNotifyIcon(e) {
2769
+ switch (e) {
2770
+ case "success":
2771
+ return /* @__PURE__ */ P(
2772
+ "svg",
2773
+ {
2774
+ xmlns: "http://www.w3.org/2000/svg",
2775
+ width: "24",
2776
+ height: "24",
2777
+ viewBox: "0 0 24 24",
2778
+ fill: "currentColor",
2779
+ class: "icon icon-tabler icons-tabler-filled icon-tabler-circle-check",
2780
+ children: [
2781
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2782
+ /* @__PURE__ */ P("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" })
2783
+ ]
2784
+ }
2785
+ );
2786
+ case "error":
2787
+ return /* @__PURE__ */ P(
2788
+ "svg",
2789
+ {
2790
+ xmlns: "http://www.w3.org/2000/svg",
2791
+ width: "24",
2792
+ height: "24",
2793
+ viewBox: "0 0 24 24",
2794
+ fill: "currentColor",
2795
+ class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-triangle",
2796
+ children: [
2797
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2798
+ /* @__PURE__ */ P("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" })
2799
+ ]
2800
+ }
2801
+ );
2802
+ case "warning":
2803
+ return /* @__PURE__ */ P(
2804
+ "svg",
2805
+ {
2806
+ xmlns: "http://www.w3.org/2000/svg",
2807
+ width: "24",
2808
+ height: "24",
2809
+ viewBox: "0 0 24 24",
2810
+ fill: "currentColor",
2811
+ class: "icon icon-tabler icons-tabler-filled icon-tabler-alert-circle",
2812
+ children: [
2813
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2814
+ /* @__PURE__ */ P("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" })
2815
+ ]
2816
+ }
2817
+ );
2818
+ case "info":
2819
+ return /* @__PURE__ */ P(
2820
+ "svg",
2821
+ {
2822
+ xmlns: "http://www.w3.org/2000/svg",
2823
+ width: "24",
2824
+ height: "24",
2825
+ viewBox: "0 0 24 24",
2826
+ fill: "currentColor",
2827
+ class: "icon icon-tabler icons-tabler-filled icon-tabler-info-circle",
2828
+ children: [
2829
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2830
+ /* @__PURE__ */ P("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" })
2831
+ ]
2832
+ }
2833
+ );
2834
+ case "dialog":
2835
+ return /* @__PURE__ */ P(
2836
+ "svg",
2837
+ {
2838
+ xmlns: "http://www.w3.org/2000/svg",
2839
+ width: "24",
2840
+ height: "24",
2841
+ viewBox: "0 0 24 24",
2842
+ fill: "none",
2843
+ stroke: "currentColor",
2844
+ "stroke-width": "2",
2845
+ "stroke-linecap": "round",
2846
+ "stroke-linejoin": "round",
2847
+ class: "icon icon-tabler icons-tabler-outline icon-tabler-message-dots",
2848
+ children: [
2849
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2850
+ /* @__PURE__ */ P("path", { d: "M12 11v.01" }),
2851
+ /* @__PURE__ */ P("path", { d: "M8 11v.01" }),
2852
+ /* @__PURE__ */ P("path", { d: "M16 11v.01" }),
2853
+ /* @__PURE__ */ P("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" })
2854
+ ]
2855
+ }
2856
+ );
2857
+ case "confirm":
2858
+ return /* @__PURE__ */ P(
2859
+ "svg",
2860
+ {
2861
+ xmlns: "http://www.w3.org/2000/svg",
2862
+ width: "24",
2863
+ height: "24",
2864
+ viewBox: "0 0 24 24",
2865
+ fill: "currentColor",
2866
+ class: "icon icon-tabler icons-tabler-filled icon-tabler-copy-check",
2867
+ children: [
2868
+ /* @__PURE__ */ P("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
2869
+ /* @__PURE__ */ P("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" })
2870
+ ]
2871
+ }
2872
+ );
2873
+ default:
2874
+ return null;
2875
+ }
2876
+ }
2877
+ static notify(e, t, r) {
2878
+ if (t?.overrideOther && [...V].forEach((a) => a.close()), typeof t.title > "u") {
2879
+ const a = e || "Notification";
2880
+ t.title = a[0].toUpperCase() + a.slice(1).toLowerCase();
2881
+ }
2882
+ const n = t.icon ?? this.getDefaultNotifyIcon(e);
2883
+ n && (n instanceof Element && n.classList.add("ipe-modal-notify-icon"), t.title = /* @__PURE__ */ P(Tr, { children: [
2884
+ n,
2885
+ t.title
2886
+ ] })), 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, f) => {
2887
+ r?.(!0, f, a), f.close();
2888
+ }), 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, f) => {
2889
+ r?.(!1, f, a), f.close();
2890
+ }), t.buttons = [t.cancelBtn, t.okBtn, ...t.buttons ?? []].filter(
2891
+ Boolean
2892
+ );
2893
+ const s = `is-notify type-${e || "default"} ${t.className ?? ""}`, o = new this({
2894
+ ...t,
2895
+ className: s,
2896
+ sizeClass: "auto",
2897
+ center: !1,
2898
+ fitScreen: !1,
2899
+ closeIcon: !0,
2900
+ outSideClose: !1,
2901
+ bodyScroll: !0,
2902
+ buttons: t.buttons ?? []
2903
+ });
2904
+ return o.setPluginName("toast"), o.showToast({
2905
+ position: t.position ?? "top right"
2906
+ });
2907
+ }
2908
+ }
2909
+ const V = [];
2910
+ function Wr(i = "top right") {
2911
+ const e = "ipe-modal-toast-container", t = `${e}-${i.replace(/[\s-\.|\/]+/g, "-")}`;
2912
+ let r = document.getElementById(t);
2913
+ return r || (r = D("div", {
2914
+ className: `${e} ${i}`,
2915
+ attrs: { id: t, "data-position": i }
2916
+ }), document.body.appendChild(r)), r;
2917
+ }
2918
+ class R extends pe {
2919
+ constructor(e = {}) {
2920
+ e.className ||= "", e.className += " theme-ipe", e.modalAnimation ||= {
2921
+ show: "ipe-modal-fade-in",
2922
+ hide: "ipe-modal-fade-out"
2923
+ }, super(e);
2924
+ }
2925
+ setLoadingState(e) {
2926
+ if (this.get$window().classList.toggle("loading", e), e) {
2927
+ const t = this.get$window().querySelectorAll(
2928
+ "input:not([disabled]),button:not([disabled])"
2929
+ );
2930
+ this._tmpDisabledActiveInputs = t, t.forEach((r) => {
2931
+ r.disabled = !0;
2932
+ }), this.get$content().append(
2933
+ /* @__PURE__ */ N(
2934
+ "div",
2935
+ {
2936
+ id: "ipe-modalLoadingWrapper",
2937
+ style: {
2938
+ position: "absolute",
2939
+ top: 0,
2940
+ left: 0,
2941
+ right: 0,
2942
+ bottom: 0,
2943
+ display: "flex",
2944
+ justifyContent: "center",
2945
+ alignItems: "center",
2946
+ backgroundColor: "rgba(255, 255, 255, 0.5)",
2947
+ zIndex: 2e3
2948
+ },
2949
+ children: /* @__PURE__ */ N(Ci, { style: { width: "80%", maxWidth: "800px" } })
2950
+ }
2951
+ )
2952
+ );
2953
+ } else {
2954
+ this.get$window().querySelector("#ipe-modalLoadingWrapper")?.remove();
2955
+ const t = this._tmpDisabledActiveInputs;
2956
+ t && t.forEach((r) => {
2957
+ r.disabled = !1;
2958
+ });
2959
+ }
2960
+ }
2961
+ }
2962
+ class Gr {
2963
+ constructor(e) {
2964
+ this.ctx = e, this.IPEModal = R, this.IPEModalEvent = Ve, this.show = R.show.bind(R), this.createObject = R.createObject.bind(R), this.close = R.close.bind(R), this.closeAll = R.closeAll.bind(R), this.removeAll = R.removeAll.bind(R), this.dialog = R.dialog.bind(R), this.confirm = R.confirm.bind(R), this.notify = R.notify.bind(R), e.set("modal", this), e.on("dispose", () => {
2965
+ R.closeAll();
2966
+ });
2967
+ }
2968
+ }
2969
+ const Ft = (i) => {
2970
+ if (!i)
2971
+ return new URLSearchParams();
2972
+ if (i instanceof URLSearchParams)
2973
+ return i;
2974
+ if (typeof i != "object" || i?.constructor !== Object)
2975
+ throw new TypeError("only plain object is supported");
2976
+ const e = new URLSearchParams();
2977
+ for (const [t, r] of Object.entries(i))
2978
+ if (r != null) {
2979
+ if (Array.isArray(r)) {
2980
+ for (const n of r)
2981
+ e.append(t, n?.toString());
2982
+ continue;
2983
+ }
2984
+ if (typeof r == "object" && r !== null && r.constructor === Object) {
2985
+ for (const [n, s] of Object.entries(r))
2986
+ s != null && e.set(`${t}[${n}]`, s?.toString());
2987
+ continue;
2988
+ }
2989
+ e.set(t, r?.toString());
2990
+ }
2991
+ return e;
2992
+ }, zt = (i, e, t) => {
2993
+ const r = typeof i == "string" ? new URL(i, window?.location?.origin) : new URL(i), n = new URLSearchParams(r.search), s = Ft(e);
2994
+ for (const [o, a] of s.entries())
2995
+ n.set(o, a);
2996
+ return r.search = n.toString(), r.hash = "", r;
2997
+ };
2998
+ var Vr = Object.create, Ye = Object.defineProperty, Yr = Object.getOwnPropertyDescriptor, Ht = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), Kt = (i) => {
2999
+ throw TypeError(i);
3000
+ }, Jr = (i, e, t) => e in i ? Ye(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, Xr = (i, e) => Ye(i, "name", { value: e, configurable: !0 }), Qr = (i) => [, , , Vr(i?.[Ht("metadata")] ?? null)], Zr = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], qt = (i) => i !== void 0 && typeof i != "function" ? Kt("Function expected") : i, en = (i, e, t, r, n) => ({ kind: Zr[i], name: e, metadata: r, addInitializer: (s) => t._ ? Kt("Already initialized") : n.push(qt(s || null)) }), tn = (i, e) => Jr(e, Ht("metadata"), i[3]), rn = (i, e, t, r) => {
3001
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
3002
+ return r;
3003
+ }, nn = (i, e, t, r, n, s) => {
3004
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && Yr(n, t));
3005
+ Xr(n, t);
3006
+ for (var w = r.length - 1; w >= 0; w--)
3007
+ f = en(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, qt(o) && (n = o);
3008
+ return tn(i, n), g && Ye(n, t, g), p ? u ^ 4 ? s : g : n;
3009
+ }, Wt, Je, Gt;
3010
+ Wt = [F(["api", "storage"])];
3011
+ class ge extends (Gt = z) {
3012
+ constructor(e) {
3013
+ super(e, "wiki", !1), this.ctx = e, this._data = {}, this.CACHE_VERSION = 4, this.CACHE_TTL = {
3014
+ siteinfo: 1e3 * 60 * 60 * 24 * 3,
3015
+ // 3 days
3016
+ userinfo: 1e3 * 60 * 30
3017
+ // 30 minutes
3018
+ }, this.QUERY_DATA = {
3019
+ siteinfo: {
3020
+ meta: "siteinfo|filerepoinfo",
3021
+ siprop: "general|specialpagealiases|namespacealiases|namespaces|magicwords",
3022
+ friprop: "canUpload|displayname|initialCapital|local|name|rootUrl|scriptDirUrl|thumbUrl|url"
3023
+ },
3024
+ userinfo: { meta: "userinfo", uiprop: "groups|rights|blockinfo|options" }
3025
+ }, this.CACHE_DB = void 0, this.mwConfig = {
3026
+ get: ((t, r) => window?.mw?.config?.get?.(t, r) ?? r),
3027
+ has: ((t) => window?.mw?.config?.exists?.(t) ?? !1),
3028
+ get values() {
3029
+ return window?.mw?.config?.values || {};
3030
+ }
3031
+ }, this.CACHE_DB = e.storage.createDatabase(
3032
+ "wiki-metadata",
3033
+ 1 / 0,
3034
+ this.CACHE_VERSION
3035
+ );
3036
+ }
3037
+ get logger() {
3038
+ return this.ctx.logger("WIKI_METADATA");
3039
+ }
3040
+ get api() {
3041
+ return this.ctx.api;
3042
+ }
3043
+ async start() {
3044
+ await Promise.all(
3045
+ Object.keys(this.QUERY_DATA).map((e) => this.initData(e))
3046
+ ), 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) => {
3047
+ const t = e.$;
3048
+ e.preferences.registerCustomConfig(
3049
+ "WikiMetadataService",
3050
+ $.object({
3051
+ WikiMetadataService: $.const(
3052
+ /* @__PURE__ */ N("div", { children: [
3053
+ /* @__PURE__ */ N("h3", { children: t`Wiki Informations` }),
3054
+ /* @__PURE__ */ N("ul", { children: [
3055
+ /* @__PURE__ */ N("li", { children: [
3056
+ /* @__PURE__ */ N("strong", { children: [
3057
+ t`Site`,
3058
+ ":"
3059
+ ] }),
3060
+ " ",
3061
+ this.general.sitename,
3062
+ " (",
3063
+ this.landingPageUrl,
3064
+ ")"
3065
+ ] }),
3066
+ /* @__PURE__ */ N("li", { children: [
3067
+ /* @__PURE__ */ N("strong", { children: t`User` }),
3068
+ ": ",
3069
+ this.userInfo.name,
3070
+ " (ID: ",
3071
+ this.userInfo.id,
3072
+ ")"
3073
+ ] }),
3074
+ /* @__PURE__ */ N("li", { children: [
3075
+ /* @__PURE__ */ N("strong", { children: t`Groups` }),
3076
+ ": ",
3077
+ this.userGroups.join(", ") || "None"
3078
+ ] })
3079
+ ] }),
3080
+ /* @__PURE__ */ N("div", { children: [
3081
+ /* @__PURE__ */ N("p", { style: { fontStyle: "italic" }, children: t`If the information shown above is incorrect (for example, the user is not you), click the button below.` }),
3082
+ /* @__PURE__ */ N(
3083
+ "button",
3084
+ {
3085
+ className: "btn danger",
3086
+ onClick: async (r) => {
3087
+ r.preventDefault(), await e.serial("clear-cache") || window.location.reload();
3088
+ },
3089
+ children: [
3090
+ "🧹 ",
3091
+ t`Clear caches & Reload`
3092
+ ]
3093
+ }
3094
+ )
3095
+ ] })
3096
+ ] })
3097
+ ).role("raw-html")
3098
+ }).description("WikiMetadataService"),
3099
+ "about"
3100
+ );
3101
+ }), this.logger.info("All initialized", this._data);
3102
+ }
3103
+ async initData(e, t = !1) {
3104
+ const r = t ? null : await this.fetchFromCache(e);
3105
+ if (r)
3106
+ return this._data[e] = r, this.logger.debug("Using cached", e, r), r;
3107
+ {
3108
+ const n = await this.fetchFromApi(e);
3109
+ return this.saveToCache(e, n), this._data[e] = n, this.logger.debug("Fetched from API", e, n), n;
3110
+ }
3111
+ }
3112
+ getCacheKey(e) {
3113
+ return `${e}:${new URL(this.ctx.api.config.baseURL).pathname.replace(/^\//, "")}`;
3114
+ }
3115
+ async fetchFromApi(e) {
3116
+ return this.api.get({
3117
+ action: "query",
3118
+ ...this.QUERY_DATA[e]
3119
+ }).then(({ data: t }) => {
3120
+ if (typeof t?.query != "object" || t.query === null)
3121
+ throw new Error("Invalid query data", { cause: t });
3122
+ return e === "siteinfo" ? t.query : t.query?.[e] || t.query;
3123
+ }).catch((t) => (this.logger.error("Failed to fetch", t), Promise.reject(t)));
3124
+ }
3125
+ async fetchFromCache(e) {
3126
+ const t = this.getCacheKey(e);
3127
+ return await this.CACHE_DB.get(t, this.CACHE_TTL[e]);
3128
+ }
3129
+ async saveToCache(e, t) {
3130
+ const r = this.getCacheKey(e);
3131
+ return this.CACHE_DB.set(r, t);
3132
+ }
3133
+ async invalidateCache(e) {
3134
+ const t = this.getCacheKey(e);
3135
+ return this.CACHE_DB.delete(t);
3136
+ }
3137
+ async onClearCache() {
3138
+ await this.CACHE_DB.clear();
3139
+ }
3140
+ // ====== shortcuts ======
3141
+ get _raw() {
3142
+ return this._data;
3143
+ }
3144
+ // siteInfo
3145
+ get siteInfo() {
3146
+ return this._data.siteinfo;
3147
+ }
3148
+ get general() {
3149
+ return this.siteInfo.general;
3150
+ }
3151
+ get specialPageAliases() {
3152
+ return this.siteInfo.specialpagealiases;
3153
+ }
3154
+ get namespaceAliases() {
3155
+ return this.siteInfo.namespacealiases;
3156
+ }
3157
+ get namespaces() {
3158
+ return this.siteInfo.namespaces;
3159
+ }
3160
+ get namespaceMap() {
3161
+ const e = Object.values(this.namespaces).map((t) => ({
3162
+ id: t.id,
3163
+ canonical: t.canonical,
3164
+ aliases: this.namespaceAliases.filter((r) => r.id === t.id).map((r) => r.alias)
3165
+ })).sort((t, r) => t.id - r.id);
3166
+ return Reflect.defineProperty(this, "namespaceMap", {
3167
+ get: () => e
3168
+ }), e;
3169
+ }
3170
+ get magicWords() {
3171
+ return this.siteInfo.magicwords;
3172
+ }
3173
+ // userInfo
3174
+ get userInfo() {
3175
+ return this._data.userinfo;
3176
+ }
3177
+ get userOptions() {
3178
+ return this.userInfo.options;
3179
+ }
3180
+ get isUserBlocked() {
3181
+ return this.userInfo.blockedbyid && this.userInfo.blockexpiry && new Date(this.userInfo.blockexpiry).getTime() > Date.now();
3182
+ }
3183
+ get userGroups() {
3184
+ return this.userInfo.groups;
3185
+ }
3186
+ get userRights() {
3187
+ return this.userInfo.rights;
3188
+ }
3189
+ // fileRepoInfo
3190
+ get fileRepos() {
3191
+ return this.siteInfo.repos || [];
3192
+ }
3193
+ /**
3194
+ * Base URL, without trailing slash
3195
+ * @example "https://mediawiki.org"
3196
+ */
3197
+ get baseUrl() {
3198
+ const e = this.general.server;
3199
+ return e.startsWith("//") ? `${window?.location?.protocol || "https:"}//${e.slice(2)}` : e;
3200
+ }
3201
+ /**
3202
+ * Home page URL of this wiki
3203
+ * @description Generally same as the Mainpage URL,
3204
+ * but after MediaWiki 1.34,
3205
+ * it can be set to the website root directory.
3206
+ * @example "https://mediawiki.org/wiki/Main_Page" (In most cases)
3207
+ * @example "https://mediawiki.org/" ($wgMainPageIsDomainRoot = true)
3208
+ */
3209
+ get landingPageUrl() {
3210
+ return this.general.base;
3211
+ }
3212
+ get mainPageName() {
3213
+ return this.general.mainpage;
3214
+ }
3215
+ /**
3216
+ * Exact Mainpage URL of this wiki
3217
+ * @example "https://mediawiki.org/wiki/Main_Page"
3218
+ */
3219
+ get mainPageUrl() {
3220
+ return this.getUrl(this.mainPageName);
3221
+ }
3222
+ /**
3223
+ * Article path, with the $1 placeholder
3224
+ * @example "/wiki/$1"
3225
+ */
3226
+ get articlePath() {
3227
+ return this.general.articlepath;
3228
+ }
3229
+ /**
3230
+ * Script path, without trailing slash
3231
+ * @example "/w"
3232
+ */
3233
+ get scriptPath() {
3234
+ return this.general.scriptpath;
3235
+ }
3236
+ /**
3237
+ * Article base URL, with the $1 placeholder
3238
+ * @example "https://mediawiki.org/wiki/$1"
3239
+ */
3240
+ get articleBaseUrl() {
3241
+ return `${this.baseUrl}${this.articlePath}`;
3242
+ }
3243
+ /**
3244
+ * Script base URL, without trailing slash
3245
+ * @example "https://mediawiki.org/w"
3246
+ */
3247
+ get scriptBaseUrl() {
3248
+ return `${this.baseUrl}${this.scriptPath}`;
3249
+ }
3250
+ // utils
3251
+ getSciprtUrl(e = "index") {
3252
+ return `${this.scriptBaseUrl}/${e.replace(/\.php$/, "")}.php`;
3253
+ }
3254
+ /** Get mainpage URL */
3255
+ getMainpageUrl(e) {
3256
+ return zt(this.siteInfo.general.base, e).toString();
3257
+ }
3258
+ getUrl(e, t) {
3259
+ const r = Ft(t);
3260
+ let n;
3261
+ return typeof e == "string" && e !== "" ? n = new URL(`${this.articleBaseUrl.replace("$1", e)}`) : typeof e == "number" ? (r.set("curid", e.toString()), n = new URL(this.getSciprtUrl("index"))) : n = new URL(this.getSciprtUrl("index")), n.search = r.toString(), n.toString();
3262
+ }
3263
+ hasRight(e) {
3264
+ return this.userRights.includes(e);
3265
+ }
3266
+ hasAnyRight(...e) {
3267
+ return e.some((t) => this.hasRight(t));
3268
+ }
3269
+ hasEveryRights(...e) {
3270
+ return e.every((t) => this.hasRight(t));
3271
+ }
3272
+ inGroup(e) {
3273
+ return this.userGroups.includes(e);
3274
+ }
3275
+ inAnyGroup(...e) {
3276
+ return this.userGroups.some((t) => e.includes(t));
3277
+ }
3278
+ getBlockInfo() {
3279
+ return this.isUserBlocked ? {
3280
+ blockid: this.userInfo.blockid,
3281
+ blockedby: this.userInfo.blockedbyid,
3282
+ blockedbyid: this.userInfo.blockedbyid,
3283
+ blockreason: this.userInfo.blockreason,
3284
+ blockedtimestamp: this.userInfo.blockedtimestamp,
3285
+ blockexpiry: this.userInfo.blockexpiry
3286
+ } : null;
3287
+ }
3288
+ }
3289
+ Je = Qr(Gt);
3290
+ ge = nn(Je, 0, "WikiMetadataService", Wt, ge);
3291
+ rn(Je, 1, ge);
3292
+ const sn = (() => {
3293
+ const i = /* @__PURE__ */ Symbol.for("IPE.GlobalMemoryStorage");
3294
+ return i in globalThis || (globalThis[i] = ki()), globalThis[i];
3295
+ })();
3296
+ class on {
3297
+ constructor(e, t, r = 1 / 0, n, s = "localStorage") {
3298
+ this.dbName = e, this.storeName = t, this.ttl = r, this.version = n, this.engine = s, typeof r != "number" && (this.ttl = Number(r)), (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 = sn;
3299
+ }
3300
+ // Key builder
3301
+ makeKey(e) {
3302
+ return `${this.dbName ? this.dbName + ":" : ""}${this.storeName ? this.storeName + "/" : ""}${e}`;
3303
+ }
3304
+ // Internal load & validation
3305
+ load(e) {
3306
+ const t = this.getRaw(e);
3307
+ if (t === null) return null;
3308
+ let r;
3309
+ try {
3310
+ r = JSON.parse(t);
3311
+ } catch {
3312
+ return this.deleteSync(e), null;
3313
+ }
3314
+ const n = r;
3315
+ return typeof n.time != "number" || !("value" in n) ? (this.deleteSync(e), null) : typeof this.version < "u" && typeof this.version < "u" && n.version !== this.version ? (this.deleteSync(e), null) : n;
3316
+ }
3317
+ getRaw(e) {
3318
+ const t = this.makeKey(e);
3319
+ return this.db.getItem(t);
3320
+ }
3321
+ setRaw(e, t) {
3322
+ const r = this.makeKey(e);
3323
+ try {
3324
+ this.db.setItem(r, t);
3325
+ } catch {
3326
+ }
3327
+ }
3328
+ deleteSync(e) {
3329
+ const t = this.makeKey(e);
3330
+ this.db.removeItem(t);
3331
+ }
3332
+ isExpired(e, t = this.ttl) {
3333
+ return e ? Date.now() - e.time > t : !1;
3334
+ }
3335
+ async get(e, t = this.ttl, r) {
3336
+ const n = this.load(e), s = this.isExpired(n, t);
3337
+ if (!n || s) {
3338
+ if (typeof r == "function") {
3339
+ const o = await r();
3340
+ return await this.set(e, o), o;
3341
+ }
3342
+ return null;
3343
+ }
3344
+ return n.value;
3345
+ }
3346
+ async set(e, t) {
3347
+ const r = Date.now();
3348
+ if (typeof e == "string") {
3349
+ const o = e, a = t;
3350
+ if (a === null || typeof a > "u") {
3351
+ await this.delete(o);
3352
+ return;
3353
+ }
3354
+ const f = { time: r, value: a, version: this.version };
3355
+ return this.setRaw(o, JSON.stringify(f)), f;
3356
+ }
3357
+ const n = e, s = {};
3358
+ for (const [o, a] of Object.entries(n)) {
3359
+ if (a === null || typeof a > "u") {
3360
+ this.deleteSync(o);
3361
+ continue;
3362
+ }
3363
+ const f = { time: r, value: a, version: this.version };
3364
+ this.setRaw(o, JSON.stringify(f)), s[o] = f;
3365
+ }
3366
+ return s;
3367
+ }
3368
+ async has(e, t = this.ttl) {
3369
+ const r = this.load(e);
3370
+ return r !== null && !this.isExpired(r, t);
3371
+ }
3372
+ async delete(e) {
3373
+ this.deleteSync(e);
3374
+ }
3375
+ async updatedAt(e) {
3376
+ const t = this.load(e);
3377
+ return t ? t.time : 0;
3378
+ }
3379
+ async clear() {
3380
+ const e = this.makeKey(""), t = [];
3381
+ for (let r = 0; r < this.db.length; r++) {
3382
+ const n = this.db.key(r);
3383
+ n && n.startsWith(e) && t.push(n);
3384
+ }
3385
+ for (const r of t) this.db.removeItem(r);
3386
+ return this;
3387
+ }
3388
+ // Async generators
3389
+ async *keys() {
3390
+ const e = this.makeKey("");
3391
+ for (let t = 0; t < this.db.length; t++) {
3392
+ const r = this.db.key(t);
3393
+ r && r.startsWith(e) && (yield r.slice(e.length));
3394
+ }
3395
+ }
3396
+ async *values() {
3397
+ for await (const e of this.keys()) {
3398
+ const t = this.load(e);
3399
+ if (t) {
3400
+ if (this.isExpired(t)) {
3401
+ this.deleteSync(e);
3402
+ continue;
3403
+ }
3404
+ yield t;
3405
+ }
3406
+ }
3407
+ }
3408
+ async *entries() {
3409
+ for await (const e of this.keys()) {
3410
+ const t = this.load(e);
3411
+ if (t) {
3412
+ if (this.isExpired(t)) {
3413
+ this.deleteSync(e);
3414
+ continue;
3415
+ }
3416
+ yield [e, t];
3417
+ }
3418
+ }
3419
+ }
3420
+ }
3421
+ var L;
3422
+ ((i) => {
3423
+ i.cache = /* @__PURE__ */ new Map(), i.defaults = Object.freeze({ iterBatch: 100, retry: { attempts: 3, baseDelayMs: 16 } }), i.sleep = (u) => new Promise((p) => setTimeout(p, u));
3424
+ function e(u) {
3425
+ const p = u?.name ?? "";
3426
+ return p === "AbortError" || p === "InvalidStateError" || p === "TransactionInactiveError" || p === "UnknownError";
3427
+ }
3428
+ i.shouldReconnect = e;
3429
+ async function t(u, p, y) {
3430
+ const _ = Math.max(1, u.attempts);
3431
+ for (let g = 0; g < _; g++)
3432
+ try {
3433
+ return await p(g);
3434
+ } catch (w) {
3435
+ if (g === _ - 1) throw w;
3436
+ await y?.(w, g);
3437
+ const O = u.baseDelayMs * Math.pow(2, g) + Math.floor(Math.random() * 10);
3438
+ await (0, i.sleep)(O);
3439
+ }
3440
+ throw new Error("withRetry exhausted unexpectedly");
3441
+ }
3442
+ i.withRetry = t;
3443
+ function r(u, p, y) {
3444
+ return new Promise((_, g) => {
3445
+ const w = indexedDB.open(u, p);
3446
+ w.onupgradeneeded = () => {
3447
+ try {
3448
+ const O = w.result, C = w.transaction;
3449
+ y?.(O, C);
3450
+ } catch (O) {
3451
+ g(O);
3452
+ }
3453
+ }, w.onerror = () => g(w.error), w.onblocked = () => {
3454
+ }, w.onsuccess = () => {
3455
+ const O = w.result;
3456
+ O.onversionchange = () => {
3457
+ try {
3458
+ O.close();
3459
+ } finally {
3460
+ i.cache.delete(u);
3461
+ }
3462
+ }, _(O);
3463
+ };
3464
+ });
3465
+ }
3466
+ async function n(u, p, y) {
3467
+ let _ = !u.objectStoreNames.contains(p), g = [];
3468
+ if (!_ && y?.indexes?.length) {
3469
+ const C = u.transaction(p, "readonly"), l = C.objectStore(p), c = new Set(Array.from(l.indexNames));
3470
+ g = (y.indexes || []).filter((h) => !c.has(h.name)), await new Promise((h, d) => {
3471
+ C.oncomplete = () => h(), C.onabort = () => d(C.error), C.onerror = () => d(C.error);
3472
+ });
3473
+ }
3474
+ if (!_ && g.length === 0) return u;
3475
+ const w = u.version + 1;
3476
+ u.close();
3477
+ const O = await r(u.name, w, (C, l) => {
3478
+ let c;
3479
+ C.objectStoreNames.contains(p) ? c = l.objectStore(p) : c = C.createObjectStore(p, {
3480
+ keyPath: y?.keyPath ?? void 0,
3481
+ autoIncrement: !!y?.autoIncrement
3482
+ });
3483
+ for (const h of g)
3484
+ c.indexNames.contains(h.name) || c.createIndex(h.name, h.keyPath, h.options);
3485
+ });
3486
+ return O.onversionchange = () => {
3487
+ try {
3488
+ O.close();
3489
+ } finally {
3490
+ i.cache.delete(O.name);
3491
+ }
3492
+ }, O;
3493
+ }
3494
+ async function s(u, p, y) {
3495
+ let _ = i.cache.get(u);
3496
+ return _ ? (_ = _.then((g) => n(g, p, y)), i.cache.set(u, _)) : (_ = (async () => {
3497
+ const g = await r(u);
3498
+ return n(g, p, y);
3499
+ })(), i.cache.set(u, _)), _;
3500
+ }
3501
+ i.getDB = s;
3502
+ async function o(u) {
3503
+ const p = i.cache.get(u);
3504
+ if (i.cache.delete(u), p)
3505
+ try {
3506
+ (await p).close();
3507
+ } catch {
3508
+ }
3509
+ }
3510
+ i.closeConnection = o;
3511
+ function a(u) {
3512
+ return new Promise((p, y) => {
3513
+ u.onsuccess = () => p(u.result), u.onerror = () => y(u.error);
3514
+ });
3515
+ }
3516
+ i.asyncRequest = a;
3517
+ function f(u) {
3518
+ return new Promise((p, y) => {
3519
+ u.oncomplete = () => p(), u.onabort = () => y(u.error ?? new DOMException("Aborted", "AbortError")), u.onerror = () => y(u.error ?? new DOMException("TransactionError", "UnknownError"));
3520
+ });
3521
+ }
3522
+ i.waitTx = f;
3523
+ })(L || (L = {}));
3524
+ class an {
3525
+ constructor(e, t, r = {}) {
3526
+ this.dbName = e, this.storeName = t, this.options = r;
3527
+ }
3528
+ get _iterBatch() {
3529
+ return this.options.iterBatch ?? L.defaults.iterBatch;
3530
+ }
3531
+ get _retryCfg() {
3532
+ const e = this.options.retry ?? L.defaults.retry;
3533
+ return { attempts: e.attempts ?? 3, baseDelayMs: e.baseDelayMs ?? 16 };
3534
+ }
3535
+ async _withStore(e, t) {
3536
+ const r = this._retryCfg;
3537
+ return L.withRetry(
3538
+ r,
3539
+ async () => {
3540
+ const n = await L.getDB(this.dbName, this.storeName, this.options.ensure);
3541
+ try {
3542
+ const s = n.transaction(this.storeName, e), o = s.objectStore(this.storeName), a = await t(o);
3543
+ return await L.waitTx(s), a;
3544
+ } catch (s) {
3545
+ throw s;
3546
+ }
3547
+ },
3548
+ async (n) => {
3549
+ L.shouldReconnect(n) && await L.closeConnection(this.dbName);
3550
+ }
3551
+ );
3552
+ }
3553
+ async get(e) {
3554
+ return this._withStore("readonly", async (t) => {
3555
+ const r = await L.asyncRequest(t.get(e));
3556
+ return r === void 0 ? void 0 : r;
3557
+ });
3558
+ }
3559
+ async set(e, t) {
3560
+ return await this._withStore("readwrite", async (r) => {
3561
+ const n = this.options.ensure?.keyPath != null ? r.put(t) : r.put(t, e);
3562
+ await L.asyncRequest(n);
3563
+ }), this;
3564
+ }
3565
+ async delete(e) {
3566
+ return this._withStore("readwrite", async (t) => {
3567
+ const r = await L.asyncRequest(t.get(e)) !== void 0;
3568
+ return await L.asyncRequest(t.delete(e)), r;
3569
+ });
3570
+ }
3571
+ async clear() {
3572
+ await this._withStore("readwrite", async (e) => {
3573
+ await L.asyncRequest(e.clear());
3574
+ });
3575
+ }
3576
+ async has(e) {
3577
+ return await this.get(e) !== void 0;
3578
+ }
3579
+ async count() {
3580
+ return this._withStore("readonly", async (e) => await L.asyncRequest(e.count()) ?? 0);
3581
+ }
3582
+ async *_iterateEntries() {
3583
+ let e = null, t = !1;
3584
+ const r = Math.max(1, this._iterBatch);
3585
+ for (; !t; ) {
3586
+ const n = await this._withStore("readonly", async (s) => {
3587
+ const o = [], a = e === null ? void 0 : IDBKeyRange.lowerBound(e, !0);
3588
+ return await new Promise((f, u) => {
3589
+ const p = s.openCursor(a);
3590
+ p.onerror = () => u(p.error), p.onsuccess = () => {
3591
+ const y = p.result;
3592
+ if (!y) {
3593
+ t = !0, f();
3594
+ return;
3595
+ }
3596
+ o.push([y.key, y.value]), e = y.key, o.length >= r ? f() : y.continue();
3597
+ };
3598
+ }), o;
3599
+ });
3600
+ for (const s of n) yield s;
3601
+ if (n.length === 0) break;
3602
+ }
3603
+ }
3604
+ entries() {
3605
+ return this._iterateEntries();
3606
+ }
3607
+ async *keys() {
3608
+ for await (const [e] of this.entries()) yield e;
3609
+ }
3610
+ async *values() {
3611
+ for await (const [, e] of this.entries()) yield e;
3612
+ }
3613
+ [Symbol.asyncIterator]() {
3614
+ return this.entries()[Symbol.asyncIterator]();
3615
+ }
3616
+ async forEach(e) {
3617
+ for await (const [t, r] of this.entries())
3618
+ await e(r, t, this);
3619
+ }
3620
+ async getMany(e) {
3621
+ const t = /* @__PURE__ */ new Map();
3622
+ for await (const r of e) t.set(r, void 0);
3623
+ return await this._withStore("readonly", async (r) => {
3624
+ await Promise.all(
3625
+ t.keys().map(async (n) => {
3626
+ const s = await L.asyncRequest(r.get(n));
3627
+ t.set(n, s === void 0 ? void 0 : s);
3628
+ })
3629
+ );
3630
+ }), t;
3631
+ }
3632
+ async setMany(e) {
3633
+ const t = this.options.ensure?.keyPath != null;
3634
+ return await this._withStore("readwrite", async (r) => {
3635
+ for await (const [n, s] of e) {
3636
+ const o = t ? r.put(s) : r.put(s, n);
3637
+ await L.asyncRequest(o);
3638
+ }
3639
+ }), this;
3640
+ }
3641
+ async deleteMany(e) {
3642
+ let t = 0;
3643
+ return await this._withStore("readwrite", async (r) => {
3644
+ for await (const n of e)
3645
+ await L.asyncRequest(r.get(n)) !== void 0 && t++, await L.asyncRequest(r.delete(n));
3646
+ }), t;
3647
+ }
3648
+ async disconnect() {
3649
+ await L.closeConnection(this.dbName);
3650
+ }
3651
+ }
3652
+ class cn {
3653
+ constructor(e, t, r = 1 / 0, n) {
3654
+ this.dbName = e, this.storeName = t, this.ttl = r, this.version = n, this.db = new an(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(() => {
3655
+ });
3656
+ }
3657
+ async _clearExpiredEntries() {
3658
+ if (this.ttl === 1 / 0) return;
3659
+ const e = Date.now(), t = [];
3660
+ for await (const [r, n] of this.db.entries())
3661
+ typeof n.time == "number" && e - n.time > this.ttl && t.push(r);
3662
+ t.length > 0 && await this.db.deleteMany(t);
3663
+ }
3664
+ async get(e, t = this.ttl, r) {
3665
+ const n = await this.loadFromDB(e), s = this.checkIfExpired(n, t);
3666
+ if (!n || s) {
3667
+ if (typeof r == "function") {
3668
+ const o = await r();
3669
+ return await this.set(e, o), o;
3670
+ }
3671
+ return null;
3672
+ }
3673
+ return n.value;
3674
+ }
3675
+ async set(e, t) {
3676
+ const r = Date.now();
3677
+ if (typeof e == "string") {
3678
+ const f = e, u = t;
3679
+ if (u === null || typeof u > "u")
3680
+ return this.delete(f);
3681
+ const p = {
3682
+ time: r,
3683
+ value: u,
3684
+ version: this.version
3685
+ };
3686
+ return await this.db.set(f, p), p;
3687
+ }
3688
+ const n = e, s = [], o = [], a = {};
3689
+ for (const [f, u] of Object.entries(n))
3690
+ if (u === null || typeof u > "u")
3691
+ o.push(f);
3692
+ else {
3693
+ const p = { time: r, value: u, version: this.version };
3694
+ s.push([f, p]), a[f] = p;
3695
+ }
3696
+ return s.length > 0 && await this.db.setMany(s), o.length > 0 && await this.db.deleteMany(o), a;
3697
+ }
3698
+ async has(e, t = this.ttl) {
3699
+ const r = await this.loadFromDB(e), n = this.checkIfExpired(r, t);
3700
+ return r !== null && !n;
3701
+ }
3702
+ async delete(e) {
3703
+ await this.db.delete(e);
3704
+ }
3705
+ async updatedAt(e) {
3706
+ const t = await this.loadFromDB(e);
3707
+ return t ? t.time : 0;
3708
+ }
3709
+ async loadFromDB(e) {
3710
+ const t = await this.db.get(e);
3711
+ if (t === void 0)
3712
+ return null;
3713
+ if (typeof t.time != "number" || typeof t.value > "u") {
3714
+ try {
3715
+ await this.delete(e);
3716
+ } catch {
3717
+ }
3718
+ return null;
3719
+ }
3720
+ if (typeof this.version < "u" && typeof this.version < "u" && t.version !== this.version) {
3721
+ try {
3722
+ await this.delete(e);
3723
+ } catch {
3724
+ }
3725
+ return null;
3726
+ }
3727
+ return t;
3728
+ }
3729
+ checkIfExpired(e, t = this.ttl) {
3730
+ return e ? Date.now() - e.time > t : !1;
3731
+ }
3732
+ /**
3733
+ * [DANGER] Use with caution!
3734
+ * Delete all data from the database.
3735
+ */
3736
+ async clear() {
3737
+ return await this.db.clear(), this;
3738
+ }
3739
+ }
3740
+ class ln extends z {
3741
+ constructor(e, t) {
3742
+ 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");
3743
+ }
3744
+ createDatabase(e, t, r, n = "indexedDB") {
3745
+ const s = "indexedDB" in window && window.indexedDB !== null;
3746
+ switch (n === "indexedDB" && !s && (n = "localStorage"), n) {
3747
+ case "indexedDB":
3748
+ return new cn(this.config.dbName, e, t, r);
3749
+ case "localStorage":
3750
+ case "sessionStorage":
3751
+ case "memory":
3752
+ return new on(this.config.dbName, e, t, r, n);
3753
+ default:
3754
+ throw new Error(`Unsupported storage engine: ${n}`);
3755
+ }
3756
+ }
3757
+ }
3758
+ function Vt(i) {
3759
+ return function(e) {
3760
+ return e.PreferencesSchema = i, e;
3761
+ };
3762
+ }
3763
+ var hn = Object.create, Xe = Object.defineProperty, un = Object.getOwnPropertyDescriptor, Yt = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), Jt = (i) => {
3764
+ throw TypeError(i);
3765
+ }, fn = (i, e, t) => e in i ? Xe(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, dn = (i, e) => Xe(i, "name", { value: e, configurable: !0 }), pn = (i) => [, , , hn(i?.[Yt("metadata")] ?? null)], gn = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], Xt = (i) => i !== void 0 && typeof i != "function" ? Jt("Function expected") : i, mn = (i, e, t, r, n) => ({ kind: gn[i], name: e, metadata: r, addInitializer: (s) => t._ ? Jt("Already initialized") : n.push(Xt(s || null)) }), yn = (i, e) => fn(e, Yt("metadata"), i[3]), wn = (i, e, t, r) => {
3766
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
3767
+ return r;
3768
+ }, bn = (i, e, t, r, n, s) => {
3769
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && un(n, t));
3770
+ dn(n, t);
3771
+ for (var w = r.length - 1; w >= 0; w--)
3772
+ f = mn(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, Xt(o) && (n = o);
3773
+ return yn(i, n), g && Xe(n, t, g), p ? u ^ 4 ? s : g : n;
3774
+ }, Qt, Qe, Zt;
3775
+ Qt = [F(["preferences"]), Vt(
3776
+ $.object({
3777
+ theme: $.union([
3778
+ $.const("auto").description("Follow system"),
3779
+ $.const("light").description("Light mode"),
3780
+ $.const("dark").description("Dark mode"),
3781
+ $.const("fandom").description("Follow Fandom")
3782
+ ]).default("auto").description("Theme preference")
3783
+ }).description("Theme settings").extra("category", "general")
3784
+ )];
3785
+ class me extends (Zt = z) {
3786
+ constructor(e) {
3787
+ super(e, "theme", !1), this.ctx = e, this._mediaQueryList = null, this._observer = null, this._handleSystemThemeChange = this._onSystemThemeChange.bind(this), this._handleBodyClassChange = this._onBodyClassChange.bind(this);
3788
+ }
3789
+ async start() {
3790
+ this._mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)"), this._mediaQueryList.addEventListener("change", this._handleSystemThemeChange), this._observer = new MutationObserver(this._handleBodyClassChange), await this.applyTheme(), this.ctx.on("preferences/changed", async ({ changes: e }) => {
3791
+ "theme" in e && await this.applyTheme();
3792
+ });
3793
+ }
3794
+ stop() {
3795
+ this._mediaQueryList && this._mediaQueryList.removeEventListener("change", this._handleSystemThemeChange), this._observer?.disconnect();
3796
+ }
3797
+ async _onSystemThemeChange() {
3798
+ await this.applyTheme();
3799
+ }
3800
+ async _onBodyClassChange() {
3801
+ await this.applyTheme();
3802
+ }
3803
+ async applyTheme() {
3804
+ const e = await this.ctx.preferences.get("theme") || "auto";
3805
+ this.updateFandomObserver(e);
3806
+ const t = this.getTheme(e);
3807
+ this.applyThemeClass(t), this.ctx.emit("theme/changed", { ctx: this.ctx, theme: t });
3808
+ }
3809
+ // don't run observer unless using fandom option
3810
+ updateFandomObserver(e) {
3811
+ e === "fandom" ? this._observer?.observe(document.body, {
3812
+ attributes: !0,
3813
+ attributeFilter: ["class"]
3814
+ }) : this._observer?.disconnect();
3815
+ }
3816
+ getTheme(e) {
3817
+ if (e === "auto")
3818
+ return this._mediaQueryList?.matches ? "dark" : "light";
3819
+ if (e === "fandom") {
3820
+ const t = document.body;
3821
+ return t.classList.contains("theme-fandomdesktop-dark") || t.classList.contains("theme-fandommobile-dark") ? "dark" : "light";
3822
+ }
3823
+ return e;
3824
+ }
3825
+ applyThemeClass(e) {
3826
+ const t = document.body;
3827
+ e === "dark" ? (t.classList.add("ipe-theme-dark"), t.setAttribute("data-ipe-theme", "dark")) : (t.classList.remove("ipe-theme-dark"), t.setAttribute("data-ipe-theme", "light"));
3828
+ }
3829
+ get currentTheme() {
3830
+ return document.body.classList.contains("ipe-theme-dark") ? "dark" : "light";
3831
+ }
3832
+ }
3833
+ Qe = pn(Zt);
3834
+ me = bn(Qe, 0, "ThemeService", Qt, me);
3835
+ wn(Qe, 1, me);
3836
+ class vn extends z {
3837
+ constructor(e) {
3838
+ super(e, "wikiPage", !0), this.ctx = e, this.WikiPage = Si(this.ctx.api);
3839
+ }
3840
+ static {
3841
+ this.inject = ["api"];
3842
+ }
3843
+ async createInstance(e, t = !1) {
3844
+ return await this.WikiPage.newFromApi(e);
3845
+ }
3846
+ async newFromTitle(e, t = !1, r, n = !1) {
3847
+ return this.createInstance({ titles: e.toString(), converttitles: t, rvsection: r }, n);
3848
+ }
3849
+ async newFromPageId(e, t, r = !1) {
3850
+ return this.createInstance({ pageids: e, rvsection: t }, r);
3851
+ }
3852
+ async newFromRevision(e, t, r = !1) {
3853
+ return await this.createInstance({ revids: e, rvsection: t }, r);
3854
+ }
3855
+ newBlankPage(e = {}) {
3856
+ return this.WikiPage.newBlankPage(e);
3857
+ }
3858
+ }
3859
+ class Ze extends z {
3860
+ constructor(e) {
3861
+ 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 = $i(this.ctx.wiki.siteInfo);
3862
+ }
3863
+ static {
3864
+ this.inject = ["wiki", "wikiPage"];
3865
+ }
3866
+ newTitle(e, t) {
3867
+ return typeof e == "string" ? new this.Title(e, t) : e;
3868
+ }
3869
+ newMainPageTitle() {
3870
+ return this.newTitle(this.ctx.wiki.mainPageName);
3871
+ }
3872
+ async newTitleFromUrl(e) {
3873
+ const t = this.parseWikiLink(e);
3874
+ return t?.title ? t.title : t?.pageId ? this.newTitleFromPageId(t.pageId) : null;
3875
+ }
3876
+ async newTitleFromAnyId(e, t = !1) {
3877
+ const { title: r, pageId: n, revId: s } = e ?? {};
3878
+ if (typeof r == "string")
3879
+ return this.newTitle(r);
3880
+ let o, a;
3881
+ if (s ? (o = parseInt(s.toString(), 10), a = "revid") : n && (o = parseInt(n.toString(), 10), a = "pageid"), !o || !a || isNaN(o) || o <= 0)
3882
+ throw new Error("Invalid id or kind", { cause: e });
3883
+ if (!t && this._cachedTitles.has(`${a}:${o}`))
3884
+ return await this._cachedTitles.get(`${a}:${o}`);
3885
+ const { promise: f, resolve: u, reject: p } = bt();
3886
+ this._cachedTitles.set(`${a}:${o}`, f);
3887
+ try {
3888
+ const { wikiPage: y } = this.ctx;
3889
+ let _ = null;
3890
+ if (a === "pageid")
3891
+ _ = await y.newFromPageId(o);
3892
+ else if (a === "revid")
3893
+ _ = await y.newFromRevision(o);
3894
+ else
3895
+ throw new Error(`Invalid kind: ${a}`);
3896
+ u(this.newTitle(_.title));
3897
+ } catch (y) {
3898
+ this._cachedTitles.delete(`${a}:${o}`), p(y);
3899
+ }
3900
+ return f;
3901
+ }
3902
+ async newTitleFromPageId(e) {
3903
+ return this.newTitleFromAnyId({ pageId: e });
3904
+ }
3905
+ async newTitleFromRevision(e) {
3906
+ return this.newTitleFromAnyId({ revId: e });
3907
+ }
3908
+ /**
3909
+ * Resolve **special** special pages to it's real target
3910
+ *
3911
+ * If target is self or cannot be resolved, return null
3912
+ * @example
3913
+ * ```
3914
+ * Special:MyPage -> User:<username>
3915
+ * Special:Edit/Page_Title -> Page_Title
3916
+ * Special:NewSection/Page_Title -> Page_Title (section=new)
3917
+ * ```
3918
+ */
3919
+ resolveSpecialPageTarget(e) {
3920
+ const t = typeof e == "string" ? this.newTitle(e) : e;
3921
+ if (!t || t.getNamespaceId() !== -1)
3922
+ return null;
3923
+ let r, n, s = "view";
3924
+ const o = t.getMainDBKey().split("/").slice(1).join("/") || "";
3925
+ if (t.isSpecial("edit") && o)
3926
+ r = o, s = "edit";
3927
+ else if (t.isSpecial("talkpage") && o) {
3928
+ const a = t.newTitle(o).getTalkPage();
3929
+ if (!a)
3930
+ return null;
3931
+ r = a.getPrefixedDBKey();
3932
+ } else if (t.isSpecial("mypage"))
3933
+ r = t.newTitle(this.ctx.wiki.userInfo.name, 2).getPrefixedDBKey() + (o ? `/${o}` : "");
3934
+ else if (t.isSpecial("mytalk"))
3935
+ r = t.newTitle(this.ctx.wiki.userInfo.name, 3).getPrefixedDBKey() + (o ? `/${o}` : "");
3936
+ else if (t.isSpecial("newsection") && o)
3937
+ r = o, n = "new", s = "edit";
3938
+ else
3939
+ return null;
3940
+ return {
3941
+ title: new this.Title(r),
3942
+ section: n,
3943
+ action: s
3944
+ };
3945
+ }
3946
+ isWikiLink(e) {
3947
+ return e.startsWith(this.wikiArticleBaseUrl) || e.startsWith(this.wikiIndexPhpUrl) || // Some servers allow index.php to be omitted
3948
+ e.startsWith(`${this.wikiBaseUrl}/?`) || // It's the landing page
3949
+ e === this.ctx.wiki.landingPageUrl;
3950
+ }
3951
+ static {
3952
+ this.REG_SKIPPED_HREF = /^(#|javascript:|vbscript:|file:)/i;
3953
+ }
3954
+ validateHrefAttr(e) {
3955
+ return typeof e != "string" ? !1 : !Ze.REG_SKIPPED_HREF.test(e);
3956
+ }
3957
+ parseWikiLink(e) {
3958
+ if (!e || typeof e == "string" && !this.validateHrefAttr(e))
3959
+ return null;
3960
+ const t = zt(e);
3961
+ if (!this.isWikiLink(t.toString()))
3962
+ return null;
3963
+ const r = t.searchParams, n = t.hash.replace("#", ""), s = r.get("action") || "view", o = r.get("title") || "", a = parseInt(r.get("curid") || "0", 10), f = parseInt(r.get("oldid") || "0", 10);
3964
+ let u = o || (() => {
3965
+ try {
3966
+ return decodeURIComponent(t.pathname.substring(this.wikiArticlePath.length));
3967
+ } catch (g) {
3968
+ return this.logger.error("parseLink", t, g), "";
3969
+ }
3970
+ })();
3971
+ u.endsWith("index.php") && (u = "");
3972
+ let p, y, _;
3973
+ if (f)
3974
+ _ = f;
3975
+ else if (a)
3976
+ y = a;
3977
+ else if (u)
3978
+ p = this.newTitle(u);
3979
+ else if (t.origin + t.pathname === this.ctx.wiki.landingPageUrl)
3980
+ p = this.newMainPageTitle();
3981
+ else
3982
+ return null;
3983
+ return {
3984
+ title: p,
3985
+ pageId: y,
3986
+ revId: _,
3987
+ url: t,
3988
+ params: r,
3989
+ hash: n,
3990
+ action: s
3991
+ };
3992
+ }
3993
+ }
3994
+ const ei = (i) => typeof i == "function";
3995
+ async function _n(i) {
3996
+ return ei(i) ? await i() : i;
3997
+ }
3998
+ function ys(i) {
3999
+ return ei(i) ? i() : i;
4000
+ }
4001
+ var xn = Object.create, et = Object.defineProperty, kn = Object.getOwnPropertyDescriptor, ti = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), ii = (i) => {
4002
+ throw TypeError(i);
4003
+ }, Sn = (i, e, t) => e in i ? et(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, $n = (i, e) => et(i, "name", { value: e, configurable: !0 }), En = (i) => [, , , xn(i?.[ti("metadata")] ?? null)], Cn = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ri = (i) => i !== void 0 && typeof i != "function" ? ii("Function expected") : i, An = (i, e, t, r, n) => ({ kind: Cn[i], name: e, metadata: r, addInitializer: (s) => t._ ? ii("Already initialized") : n.push(ri(s || null)) }), On = (i, e) => Sn(e, ti("metadata"), i[3]), Pn = (i, e, t, r) => {
4004
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
4005
+ return r;
4006
+ }, In = (i, e, t, r, n, s) => {
4007
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && kn(n, t));
4008
+ $n(n, t);
4009
+ for (var w = r.length - 1; w >= 0; w--)
4010
+ f = An(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, ri(o) && (n = o);
4011
+ return On(i, n), g && et(n, t, g), p ? u ^ 4 ? s : g : n;
4012
+ }, ni, tt, si;
4013
+ ni = [F(["storage", "wiki"])];
4014
+ class ye extends (si = z) {
4015
+ constructor(e) {
4016
+ 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);
4017
+ try {
4018
+ this._migrageFromLegacyMasterDB();
4019
+ } catch {
4020
+ }
4021
+ }
4022
+ get logger() {
4023
+ return this.ctx.logger("PREFERENCES");
4024
+ }
4025
+ async start() {
4026
+ }
4027
+ async get(e, t) {
4028
+ if (!e)
4029
+ return this.getAll();
4030
+ t ??= () => {
4031
+ const n = this.defaultOf(e);
4032
+ return this.logger.debug(e, `(fallback value: ${n})`), n;
4033
+ };
4034
+ const r = await this.db.get(e, void 0);
4035
+ return r !== null ? r : await _n(t);
4036
+ }
4037
+ /**
4038
+ * 获取全部注册的配置项以及最终生效的值
4039
+ * 未保存的配置项将使用默认值
4040
+ */
4041
+ async getAll() {
4042
+ const e = this.loadDefaultConfigs();
4043
+ for await (const [t, r] of this.db.entries())
4044
+ t !== "_touched" && t in e && (e[t] = r.value);
4045
+ return e;
4046
+ }
4047
+ async set(e, t) {
4048
+ return (await this.setMany({ [e]: t }))[e];
4049
+ }
4050
+ async setMany(e) {
4051
+ const t = this.loadDefaultConfigs(), r = {};
4052
+ for (const [n, s] of Object.entries(e))
4053
+ s === t[n] || s === void 0 ? r[n] = void 0 : r[n] = s;
4054
+ return await this.db.set(r), this.ctx.emit("preferences/changed", { ctx: this.ctx, input: e, changes: r }), r;
4055
+ }
4056
+ defaultOf(e) {
4057
+ return this._defaultPreferences[e] ??= this.loadDefaultConfigs()[e];
4058
+ }
4059
+ /**
4060
+ * Get exportable configurations
4061
+ * - exclude values that are the same as the default value
4062
+ * - exclude invalid or undefined values
4063
+ * - sort by keys
4064
+ */
4065
+ async getExportableRecord(e) {
4066
+ e ??= await this.getAll();
4067
+ const t = this.loadDefaultConfigs(), r = {};
4068
+ return Object.entries(t).sort(([n], [s]) => n.localeCompare(s)).forEach(([n, s]) => {
4069
+ const o = e[n];
4070
+ o !== void 0 && o !== s && (r[n] = o);
4071
+ }), r;
4072
+ }
4073
+ loadDefaultConfigs() {
4074
+ const e = {};
4075
+ return this.getConfigRegistries().forEach((t) => {
4076
+ try {
4077
+ const r = t.schema({});
4078
+ Object.entries(r).forEach(([n, s]) => {
4079
+ e[n] = s;
4080
+ });
4081
+ } catch {
4082
+ }
4083
+ }), Object.entries(e).forEach(([t, r]) => {
4084
+ this._defaultPreferences[t] = r;
4085
+ }), e;
4086
+ }
4087
+ registerCustomConfig(e, t, r) {
4088
+ const n = {
4089
+ name: e,
4090
+ schema: t,
4091
+ category: r || "general"
4092
+ }, s = this.customRegistries.findIndex((o) => o.name === e);
4093
+ return s >= 0 ? this.customRegistries[s] = n : this.customRegistries.push(n), this;
4094
+ }
4095
+ getConfigRegistries(e) {
4096
+ return Array.from(this.ctx.registry.entries()).map(([t]) => t === null ? {
4097
+ name: "@root",
4098
+ schema: ve?.PreferencesSchema || null
4099
+ } : {
4100
+ name: t.name,
4101
+ schema: t?.PreferencesSchema || null
4102
+ }).filter((t) => t.schema !== null).map((t) => ({
4103
+ ...t,
4104
+ category: t.schema.meta.category || "general"
4105
+ })).concat(this.customRegistries).filter((t) => !e || t.category === e);
4106
+ }
4107
+ getAllSchema() {
4108
+ return new $(
4109
+ $.intersect(this.getConfigRegistries().map((e) => e.schema))
4110
+ );
4111
+ }
4112
+ defineCategory(e) {
4113
+ const t = this.categoryDefinitions.findIndex((r) => r.name === e.name);
4114
+ return t < 0 ? this.categoryDefinitions.push(e) : this.categoryDefinitions[t] = e, this.categoryDefinitions.sort((r, n) => (r.index ?? 0) - (n.index ?? 0)), this;
4115
+ }
4116
+ getConfigCategories() {
4117
+ return this.categoryDefinitions;
4118
+ }
4119
+ async _migrageFromLegacyMasterDB() {
4120
+ const e = this.ctx.storage.createDatabase("preferences", 1 / 0);
4121
+ let t = 0;
4122
+ for await (const [r, n] of e.entries())
4123
+ r !== "_touched" && (await this.db.set(r, n.value), t++);
4124
+ return t && this.logger.info(`Migrated ${t} preferences from master DB`), await e.clear(), await e?.db?.disconnect?.(), t;
4125
+ }
4126
+ }
4127
+ tt = En(si);
4128
+ ye = In(tt, 0, "PreferencesService", ni, ye);
4129
+ Pn(tt, 1, ye);
4130
+ var it = /* @__PURE__ */ ((i) => (i.ANALYTICS_API_BASE = "https://analytics.ipe.wiki/api/v6", i.ANALYTICS_DASH_URL = "https://analytics.ipe.wiki", i.GITHUB_URL = "https://github.com/inpageedit/inpageedit-next", i.GITHUB_OWNER = "inpageedit", i.GITHUB_REPO = "inpageedit-next", i.HOME_URL = "https://www.ipe.wiki/", i.UPDATE_LOGS_URL = "https://www.ipe.wiki/changelogs/", i.PLUGIN_REGISTRY_URL = "https://registry.ipe.wiki/registry.v1.json", i.I18N_INDEX_URL = "https://registry.ipe.wiki/i18n/index.json", i.QQ_GROUP_ID = "1026023666", i))(it || {});
4131
+ const oi = "", ai = "", Ln = /\\\{/g, Rn = /\\\}/g, jn = new RegExp(oi, "g"), Dn = new RegExp(ai, "g");
4132
+ function yt(i) {
4133
+ const e = i ? { ...i } : void 0;
4134
+ return (r, ...n) => Tn(e, r, ...n);
4135
+ }
4136
+ function Tn(i, e, ...t) {
4137
+ if (!e) return "";
4138
+ let r = String(e).replace(Ln, oi).replace(Rn, ai), n = {}, s = [];
4139
+ t.length === 1 && Array.isArray(t[0]) ? s = t[0] : t.length === 1 && Nn(t[0]) ? n = t[0] : t.length > 0 && (s = t);
4140
+ const o = /* @__PURE__ */ Object.create(null);
4141
+ if (s && s.length)
4142
+ for (let a = 0; a < s.length; a++)
4143
+ o[`$${a + 1}`] = s[a];
4144
+ if (n && Object.keys(n).length)
4145
+ for (const a of Object.keys(n)) o[a] = n[a];
4146
+ if (i && Object.keys(i).length)
4147
+ for (const a of Object.keys(i))
4148
+ typeof o[a] > "u" && (o[a] = i[a]);
4149
+ return r = r.replace(/\{\{\s*([\s\S]*?)\s*\}\}/g, (a, f) => {
4150
+ const u = String(f).trim();
4151
+ if (!u) return "";
4152
+ try {
4153
+ const p = Mn(u, o);
4154
+ return p == null ? "" : String(p);
4155
+ } catch {
4156
+ return "";
4157
+ }
4158
+ }), r.replace(jn, "{").replace(Dn, "}");
4159
+ }
4160
+ function Nn(i) {
4161
+ return typeof i == "object" && i !== null && i.constructor === Object;
4162
+ }
4163
+ const Mn = Bn();
4164
+ function Bn() {
4165
+ const i = /* @__PURE__ */ new Set([
4166
+ "eval",
4167
+ "Object",
4168
+ "Array",
4169
+ "String",
4170
+ "Number",
4171
+ "Boolean",
4172
+ "Date",
4173
+ "Math",
4174
+ "JSON",
4175
+ "undefined",
4176
+ "null",
4177
+ "true",
4178
+ "false",
4179
+ "NaN",
4180
+ "Infinity",
4181
+ "isNaN",
4182
+ "isFinite",
4183
+ "parseInt",
4184
+ "parseFloat"
4185
+ ]), e = new Function(
4186
+ "__expr__",
4187
+ "ctx",
4188
+ `
4189
+ try {
4190
+ with (ctx) {
4191
+ return (eval(__expr__));
4192
+ }
4193
+ } catch (e) {
4194
+ throw e;
4195
+ }
4196
+ `
4197
+ );
4198
+ return (t, r) => {
4199
+ const n = new Proxy(r, {
4200
+ has: (s, o) => typeof o == "symbol" ? o in s : !(typeof o == "string" && (i.has(o) || o === "__expr__")),
4201
+ get: (s, o) => {
4202
+ if (o in s)
4203
+ return s[o];
4204
+ }
4205
+ });
4206
+ return e(t, n);
4207
+ };
4208
+ }
4209
+ function ci(i) {
4210
+ return i.charAt(0).toLowerCase() + i.slice(1);
4211
+ }
4212
+ function ie(i) {
4213
+ return ci(i).replace(/_/g, "-").replace(/.[A-Z]+/g, (e) => e[0] + "-" + e.slice(1).toLowerCase());
4214
+ }
4215
+ function ws(i) {
4216
+ return ci(i).replace(/-/g, "_").replace(/.[A-Z]+/g, (e) => e[0] + "_" + e.slice(1).toLowerCase());
4217
+ }
4218
+ function q(i, e) {
4219
+ let t = i[0] ?? "";
4220
+ for (let r = 0; r < e.length; r++)
4221
+ t += String(e[r]) + (i[r + 1] ?? "");
4222
+ return t;
4223
+ }
4224
+ class Un {
4225
+ constructor(e, t) {
4226
+ this.languages = /* @__PURE__ */ new Map(), this.currentLanguage = "en", this.missingKeys = /* @__PURE__ */ new Map(), this.usedKeys = /* @__PURE__ */ new Set();
4227
+ const r = t?.language || "en";
4228
+ this.currentLanguage = r, this.interpolate = yt(t?.globals), e && Object.keys(e).length && this.setLanguageData(r, e);
4229
+ }
4230
+ setGlobals(e) {
4231
+ return this.interpolate = yt(e), this;
4232
+ }
4233
+ set(e, t) {
4234
+ const r = this.currentLanguage, n = this.ensureLanguageMap(r);
4235
+ if (typeof e == "string" && typeof t == "string")
4236
+ n.set(e, t);
4237
+ else if (typeof e == "object") {
4238
+ const s = this.toStringRecord(e);
4239
+ for (const [o, a] of Object.entries(s))
4240
+ n.set(o, a);
4241
+ }
4242
+ return this;
4243
+ }
4244
+ setLanguageData(e, t) {
4245
+ e = ie(e).toLowerCase();
4246
+ const r = this.ensureLanguageMap(e), n = this.toStringRecord(t);
4247
+ for (const [s, o] of Object.entries(n))
4248
+ r.set(s, o);
4249
+ return this;
4250
+ }
4251
+ setLanguage(e) {
4252
+ return e = ie(e).toLowerCase(), this.currentLanguage = e, this;
4253
+ }
4254
+ getLanguage() {
4255
+ return this.currentLanguage;
4256
+ }
4257
+ hasLanguage(e) {
4258
+ e = ie(e).toLowerCase();
4259
+ const t = this.languages.get(e);
4260
+ return t && Object.keys(t).length > 0;
4261
+ }
4262
+ toStringRecord(e, t) {
4263
+ const r = {};
4264
+ for (const [n, s] of Object.entries(e)) {
4265
+ const o = t ? `${t}.${n}` : n;
4266
+ if (s && typeof s == "object" && !Array.isArray(s)) {
4267
+ const a = this.toStringRecord(s, o);
4268
+ for (const [f, u] of Object.entries(a))
4269
+ r[f] = String(u);
4270
+ } else
4271
+ r[o] = String(s);
4272
+ }
4273
+ return r;
4274
+ }
4275
+ has(e) {
4276
+ const t = this.resolveLanguageOrder(this.currentLanguage);
4277
+ for (const r of t)
4278
+ if (this.languages.get(r)?.has(e)) return !0;
4279
+ return !1;
4280
+ }
4281
+ get(e) {
4282
+ this.recordUsedKey(e);
4283
+ const t = this.resolveLanguageOrder(this.currentLanguage), r = [];
4284
+ for (const n of t) {
4285
+ const o = this.languages.get(n)?.get(e);
4286
+ if (typeof o < "u")
4287
+ return r.length && this.recordMissing(e, r), o;
4288
+ r.push(n);
4289
+ }
4290
+ r.length && this.recordMissing(e, r);
4291
+ }
4292
+ translate(e, ...t) {
4293
+ if (!e)
4294
+ return "";
4295
+ if (this.currentLanguage === "qqx")
4296
+ return `⧼${e}⧽`;
4297
+ const r = this.get(e);
4298
+ return typeof r > "u" ? this.interpolate(e, ...t) : this.interpolate(r, ...t);
4299
+ }
4300
+ $(...e) {
4301
+ if (Array.isArray(e[0]) && e[0]?.raw) {
4302
+ const n = e[0], s = e.slice(1), o = q(n, s);
4303
+ return this.translate(o);
4304
+ }
4305
+ const r = e;
4306
+ return (n, ...s) => {
4307
+ const o = q(n, s);
4308
+ return this.translate(o, ...r);
4309
+ };
4310
+ }
4311
+ /**
4312
+ * [payload as template] Return the raw message without interpolation
4313
+ * @example
4314
+ * ```
4315
+ * i18n.rawMsg('Hello, {{ name }}')
4316
+ * // good: "你好,{{ name }}"
4317
+ * // missing: "Hello, {{ name }}"
4318
+ * ```
4319
+ */
4320
+ translateRaw(e) {
4321
+ return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? e : "";
4322
+ }
4323
+ $raw(...e) {
4324
+ if (Array.isArray(e[0]) && e[0]?.raw) {
4325
+ const r = e[0], n = e.slice(1), s = q(r, n);
4326
+ return this.translateRaw(s);
4327
+ }
4328
+ return (r, ...n) => {
4329
+ const s = q(r, n);
4330
+ return this.translateRaw(s);
4331
+ };
4332
+ }
4333
+ message(e, ...t) {
4334
+ if (!e)
4335
+ return "";
4336
+ if (this.currentLanguage === "qqx")
4337
+ return `⧼${e}⧽`;
4338
+ const r = this.get(e);
4339
+ return typeof r > "u" ? `(${e})` : this.interpolate(r, ...t);
4340
+ }
4341
+ $$(...e) {
4342
+ if (Array.isArray(e[0]) && e[0]?.raw) {
4343
+ const n = e[0], s = e.slice(1), o = q(n, s);
4344
+ return this.message(o);
4345
+ }
4346
+ const r = e;
4347
+ return (n, ...s) => {
4348
+ const o = q(n, s);
4349
+ return this.message(o, ...r);
4350
+ };
4351
+ }
4352
+ /**
4353
+ * [payload as key] Return the raw message without interpolation
4354
+ * @example
4355
+ * ```
4356
+ * i18n.rawMsg('greeting')
4357
+ * // good: "你好,{{ name }}"
4358
+ * // missing: "(greeting)"
4359
+ * ```
4360
+ */
4361
+ messageRaw(e) {
4362
+ return e ? this.currentLanguage === "qqx" ? `⧼${e}⧽` : this.get(e) ?? `(${e})` : "";
4363
+ }
4364
+ $$raw(...e) {
4365
+ if (Array.isArray(e[0]) && e[0].raw) {
4366
+ const r = e[0], n = e.slice(1), s = q(r, n);
4367
+ return this.messageRaw(s);
4368
+ }
4369
+ return (r, ...n) => {
4370
+ const s = q(r, n);
4371
+ return this.messageRaw(s);
4372
+ };
4373
+ }
4374
+ getAvailableLanguages() {
4375
+ return Array.from(this.languages.keys());
4376
+ }
4377
+ ensureLanguageMap(e) {
4378
+ let t = this.languages.get(e);
4379
+ return t || (t = /* @__PURE__ */ new Map(), this.languages.set(e, t)), t;
4380
+ }
4381
+ resolveLanguageOrder(e) {
4382
+ const t = e;
4383
+ return t === "en" ? ["en"] : [t, "en"];
4384
+ }
4385
+ /**
4386
+ * 获取缺失键报告:
4387
+ * { foo: ['zh', 'zh-hans', 'en'] }
4388
+ */
4389
+ getMissingReport() {
4390
+ return Object.fromEntries(this.missingKeys.entries());
4391
+ }
4392
+ /**
4393
+ * 清空缺失键记录
4394
+ */
4395
+ clearMissingReport() {
4396
+ this.missingKeys.clear();
4397
+ }
4398
+ recordMissing(e, t) {
4399
+ if (!t.length) return;
4400
+ const r = this.missingKeys.get(e) || [];
4401
+ for (const n of t)
4402
+ r.includes(n) || r.push(n);
4403
+ this.missingKeys.set(e, r);
4404
+ }
4405
+ recordUsedKey(e) {
4406
+ this.usedKeys.add(e);
4407
+ }
4408
+ getUsedKeys() {
4409
+ return Array.from(this.usedKeys);
4410
+ }
4411
+ generateBlankKeyRecord() {
4412
+ const e = {};
4413
+ for (const t of this.getUsedKeys())
4414
+ e[t] = "";
4415
+ return e;
4416
+ }
4417
+ }
4418
+ var Fn = Object.create, rt = Object.defineProperty, zn = Object.getOwnPropertyDescriptor, li = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), hi = (i) => {
4419
+ throw TypeError(i);
4420
+ }, Hn = (i, e, t) => e in i ? rt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, Kn = (i, e) => rt(i, "name", { value: e, configurable: !0 }), qn = (i) => [, , , Fn(i?.[li("metadata")] ?? null)], Wn = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], ui = (i) => i !== void 0 && typeof i != "function" ? hi("Function expected") : i, Gn = (i, e, t, r, n) => ({ kind: Wn[i], name: e, metadata: r, addInitializer: (s) => t._ ? hi("Already initialized") : n.push(ui(s || null)) }), Vn = (i, e) => Hn(e, li("metadata"), i[3]), Yn = (i, e, t, r) => {
4421
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
4422
+ return r;
4423
+ }, Jn = (i, e, t, r, n, s) => {
4424
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && zn(n, t));
4425
+ Kn(n, t);
4426
+ for (var w = r.length - 1; w >= 0; w--)
4427
+ f = Gn(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, ui(o) && (n = o);
4428
+ return Vn(i, n), g && rt(n, t, g), p ? u ^ 4 ? s : g : n;
4429
+ }, fi, nt, di;
4430
+ const wt = new $(
4431
+ $.object({
4432
+ manifest_version: $.const(1).required(),
4433
+ base_language: $.string().required(),
4434
+ last_modified: $.string().required(),
4435
+ languages: $.dict(
4436
+ $.object({
4437
+ file: $.string().required(),
4438
+ fallback: $.string(),
4439
+ iso_name: $.string(),
4440
+ endonym: $.string(),
4441
+ data: $.transform(
4442
+ $.dict($.any()).default({}),
4443
+ (i) => Object.keys(i).length > 0 ? i : void 0
4444
+ )
4445
+ })
4446
+ ).required()
4447
+ })
4448
+ );
4449
+ fi = [F(["wiki", "preferences"]), Vt(
4450
+ $.object({
4451
+ "i18n.index_url": $.string().description("I18n index URL (DO NOT CHANGE THIS) ").default(
4452
+ it.I18N_INDEX_URL
4453
+ )
4454
+ }).description("").extra("category", "general")
4455
+ )];
4456
+ class we extends (di = z) {
4457
+ constructor(e) {
4458
+ 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 Un(
4459
+ {},
4460
+ {
4461
+ language: "",
4462
+ globals: {
4463
+ userName: this.ctx.wiki.userInfo.name || "",
4464
+ userId: this.ctx.wiki.userInfo.id || 0,
4465
+ siteName: this.ctx.wiki.siteInfo.general.sitename || ""
4466
+ }
4467
+ }
4468
+ ), this.i18nIndexDB = e.storage.createDatabase(
4469
+ "i18n-index",
4470
+ 1e3 * 60 * 60 * 24 * 3,
4471
+ // 3 days
4472
+ this.ctx.version,
4473
+ "indexedDB"
4474
+ ), this.i18nDataDB = e.storage.createDatabase(
4475
+ "i18n-data",
4476
+ 1e3 * 60 * 60 * 24 * 3,
4477
+ // 3 days
4478
+ this.ctx.version,
4479
+ "indexedDB"
4480
+ ), 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);
4481
+ }
4482
+ async start() {
4483
+ this.ctx.preferences.registerCustomConfig(
4484
+ "language",
4485
+ $.object({
4486
+ language: $.union([
4487
+ "@user",
4488
+ "@site",
4489
+ $.string().description("Custom language code")
4490
+ ]).description("UI language").default("@user")
4491
+ }).description("UI language")
4492
+ ), this.ctx.on("clear-cache", this.onClearCache.bind(this));
4493
+ const e = this._indexUrl = await this.ctx.preferences.get("i18n.index_url") || "";
4494
+ if (!e) {
4495
+ this.logger.error("I18n index URL is not set"), this.setupShortcuts();
4496
+ return;
4497
+ }
4498
+ let t = null;
4499
+ try {
4500
+ t = await this.getI18nIndex(e);
4501
+ } catch (s) {
4502
+ this.logger.error("Failed to fetch i18n index", s), this.setupShortcuts();
4503
+ return;
4504
+ }
4505
+ this._indexCache = t, Object.entries(t.languages).forEach(([s, o]) => {
4506
+ o.data && Object.keys(o.data).length > 0 && this.manager.setLanguageData(s, o.data);
4507
+ });
4508
+ const r = await this.ctx.preferences.get("language"), n = this.normalizeLanguageCode(r);
4509
+ this.logger.debug("Settings", { prefer: r, normalized: n });
4510
+ try {
4511
+ await this.switchLanguage(n), this.logger.info(`Initialized for language: ${this.language}`);
4512
+ } catch (s) {
4513
+ this.logger.error("Failed to fetch i18n index", s), this.manager.setLanguage("en");
4514
+ }
4515
+ this.ctx.preferences.registerCustomConfig(
4516
+ "language",
4517
+ $.object({
4518
+ language: $.union([
4519
+ $.const("@user").description(this.$`Same as your personal language`),
4520
+ $.const("@site").description(this.$`Same as the site language`),
4521
+ ...this.getAvailableLanguageCodes().map(
4522
+ ({ code: s, endonym: o, iso_name: a }) => $.const(s).description(o || a || s)
4523
+ )
4524
+ ]).default("@user")
4525
+ }).description(this.$`InPageEdit UI language`)
4526
+ ), this.setupShortcuts(), this.ctx.on("preferences/changed", async ({ changes: s }) => {
4527
+ if (!("language" in s)) return;
4528
+ const o = this.normalizeLanguageCode(await this.ctx.preferences.get("language"));
4529
+ o && o !== this.language && await this.switchLanguage(o);
4530
+ });
4531
+ }
4532
+ setupShortcuts() {
4533
+ if (!this.manager) throw new Error("I18nManager is not initialized");
4534
+ 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));
4535
+ }
4536
+ normalizeLanguageCode(e) {
4537
+ 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"), ie(String(e)).toLowerCase());
4538
+ }
4539
+ get language() {
4540
+ return this.manager.getLanguage();
4541
+ }
4542
+ /**
4543
+ * 主动设置偏好值(会触发 preferences/changed,从而热切换)
4544
+ */
4545
+ async setLanguagePreference(e) {
4546
+ await this.ctx.preferences.set("language", e);
4547
+ }
4548
+ /**
4549
+ * 直接切换到具体语言(不修改偏好值)
4550
+ */
4551
+ async switchLanguage(e) {
4552
+ const t = this.normalizeLanguageCode(e);
4553
+ await this.ensureLanguageLoaded(t), this.manager.setLanguage(t), this.ctx.emit("i18n/changed", { ctx: this.ctx, language: t });
4554
+ }
4555
+ /**
4556
+ * 为指定语言注册(或合并)消息。
4557
+ * - 推荐加命名空间避免冲突:{ myPlugin: { key: 'value' } }
4558
+ * - 若 language 为当前语言,将立即可用;必要时你可以手动触发 UI 刷新或监听 i18n/changed。
4559
+ */
4560
+ async registerMessages(e, t, r) {
4561
+ const n = r?.namespace ? { [r.namespace]: t } : t;
4562
+ this.manager.setLanguageData(e, n), e === this.language && this.ctx.emit("i18n/changed", { ctx: this.ctx, language: this.language });
4563
+ }
4564
+ /**
4565
+ * 列出可用语言与文件(来源于 index.json)
4566
+ */
4567
+ getAvailableLanguageCodes() {
4568
+ if (!this._indexCache) throw new Error("I18n index is not loaded");
4569
+ return Object.entries(this._indexCache.languages).filter(([e, t]) => !t.fallback).reduce(
4570
+ (e, [t, r]) => (e.push({ code: t, ...r }), e),
4571
+ []
4572
+ );
4573
+ }
4574
+ findLanguageMeta(e, t) {
4575
+ const r = ie(String(t)).toLowerCase(), n = e.languages[r];
4576
+ if (n)
4577
+ return {
4578
+ code: r,
4579
+ ...n
4580
+ };
4581
+ {
4582
+ const s = e.languages.en;
4583
+ if (s)
4584
+ return {
4585
+ code: "en",
4586
+ ...s
4587
+ };
4588
+ }
4589
+ }
4590
+ async getI18nIndex(e, t = !1) {
4591
+ if (!t) {
4592
+ const n = await this.i18nIndexDB.get(e);
4593
+ if (n)
4594
+ try {
4595
+ return wt(n);
4596
+ } catch (s) {
4597
+ this.logger.error("Failed to parse cached i18n index", s), this.i18nIndexDB.delete(e);
4598
+ }
4599
+ }
4600
+ const r = await this.fetchI18nIndex(e);
4601
+ return this.i18nIndexDB.set(e, r), r;
4602
+ }
4603
+ async fetchI18nIndex(e) {
4604
+ const t = await fetch(e).then((r) => r.json());
4605
+ return wt(t);
4606
+ }
4607
+ async ensureLanguageLoaded(e) {
4608
+ if (!this.manager || !this._indexCache) throw new Error("I18nManager is not initialized");
4609
+ if (this.manager.hasLanguage(e))
4610
+ return this.logger.debug("Language already loaded", e);
4611
+ const t = await this.getLanguageData(e);
4612
+ this.manager.setLanguageData(e, t), this.logger.debug("Language data ensured", e, t);
4613
+ }
4614
+ async getLanguageData(e, t = !1) {
4615
+ if (!this._indexCache) throw new Error("I18n index is not loaded");
4616
+ const r = this.findLanguageMeta(this._indexCache, e);
4617
+ if (!r) return {};
4618
+ const n = `${this._indexUrl}#${r.file}`;
4619
+ if (!t) {
4620
+ const o = await this.i18nDataDB.get(n);
4621
+ if (o && Object.keys(o).length > 0)
4622
+ return this.logger.debug("Using cached language data", e, o), o;
4623
+ }
4624
+ const s = r.data || await fetch(new URL(r.file, this._indexUrl).toString()).then((o) => o.json());
4625
+ return this.i18nDataDB.set(n, s), this.logger.debug("Language data fetched", e, r.file, s), s;
4626
+ }
4627
+ /**
4628
+ * 获取缺失键报告,形如:
4629
+ * { foo: ['zh', 'zh-hans', 'en'] }
4630
+ */
4631
+ getMissingReport() {
4632
+ return this.manager.getMissingReport();
4633
+ }
4634
+ /**
4635
+ * 清空缺失键记录
4636
+ */
4637
+ clearMissingReport() {
4638
+ this.manager.clearMissingReport();
4639
+ }
4640
+ async onClearCache() {
4641
+ await this.i18nIndexDB.clear(), await this.i18nDataDB.clear();
4642
+ }
4643
+ }
4644
+ nt = qn(di);
4645
+ we = Jn(nt, 0, "I18nService", fi, we);
4646
+ Yn(nt, 1, we);
4647
+ const Xn = new TextEncoder();
4648
+ function Qn(i) {
4649
+ if (typeof i == "string") return Xn.encode(i);
4650
+ if (i instanceof ArrayBuffer) return new Uint8Array(i);
4651
+ if (ArrayBuffer.isView(i))
4652
+ return new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
4653
+ throw new TypeError("Unsupported input type");
4654
+ }
4655
+ function Zn(i) {
4656
+ let e = "";
4657
+ for (let t = 0; t < i.length; t++) {
4658
+ const r = i[t].toString(16).padStart(2, "0");
4659
+ e += r;
4660
+ }
4661
+ return e;
4662
+ }
4663
+ function es(i, e) {
4664
+ return i << e | i >>> 32 - e;
4665
+ }
4666
+ const ts = [
4667
+ 7,
4668
+ 12,
4669
+ 17,
4670
+ 22,
4671
+ 7,
4672
+ 12,
4673
+ 17,
4674
+ 22,
4675
+ 7,
4676
+ 12,
4677
+ 17,
4678
+ 22,
4679
+ 7,
4680
+ 12,
4681
+ 17,
4682
+ 22,
4683
+ 5,
4684
+ 9,
4685
+ 14,
4686
+ 20,
4687
+ 5,
4688
+ 9,
4689
+ 14,
4690
+ 20,
4691
+ 5,
4692
+ 9,
4693
+ 14,
4694
+ 20,
4695
+ 5,
4696
+ 9,
4697
+ 14,
4698
+ 20,
4699
+ 4,
4700
+ 11,
4701
+ 16,
4702
+ 23,
4703
+ 4,
4704
+ 11,
4705
+ 16,
4706
+ 23,
4707
+ 4,
4708
+ 11,
4709
+ 16,
4710
+ 23,
4711
+ 4,
4712
+ 11,
4713
+ 16,
4714
+ 23,
4715
+ 6,
4716
+ 10,
4717
+ 15,
4718
+ 21,
4719
+ 6,
4720
+ 10,
4721
+ 15,
4722
+ 21,
4723
+ 6,
4724
+ 10,
4725
+ 15,
4726
+ 21,
4727
+ 6,
4728
+ 10,
4729
+ 15,
4730
+ 21
4731
+ ], is = new Array(64).fill(0).map((i, e) => Math.floor(Math.abs(Math.sin(e + 1)) * 2 ** 32) >>> 0);
4732
+ function rs(i) {
4733
+ const e = Qn(i), t = (56 - (e.length + 1) % 64 + 64) % 64, r = e.length + 1 + t + 8, n = new Uint8Array(r);
4734
+ n.set(e, 0), n[e.length] = 128;
4735
+ const s = e.length, o = s << 3 >>> 0, a = s >>> 29 >>> 0, f = new DataView(n.buffer);
4736
+ f.setUint32(r - 8, o, !0), f.setUint32(r - 4, a, !0);
4737
+ let u = 1732584193, p = 4023233417, y = 2562383102, _ = 271733878;
4738
+ const g = new Uint32Array(16);
4739
+ for (let C = 0; C < n.length; C += 64) {
4740
+ for (let m = 0; m < 16; m++) g[m] = f.getUint32(C + m * 4, !0);
4741
+ let l = u, c = p, h = y, d = _;
4742
+ for (let m = 0; m < 64; m++) {
4743
+ let v, x;
4744
+ m < 16 ? (v = c & h | ~c & d, x = m) : m < 32 ? (v = d & c | ~d & h, x = (5 * m + 1) % 16) : m < 48 ? (v = c ^ h ^ d, x = (3 * m + 5) % 16) : (v = h ^ (c | ~d), x = 7 * m % 16);
4745
+ const A = d, Se = l + v + is[m] + g[x] >>> 0;
4746
+ d = h, h = c, c = c + es(Se, ts[m]) >>> 0, l = A;
4747
+ }
4748
+ u = u + l >>> 0, p = p + c >>> 0, y = y + h >>> 0, _ = _ + d >>> 0;
4749
+ }
4750
+ const w = new Uint8Array(16), O = new DataView(w.buffer);
4751
+ return O.setUint32(0, u, !0), O.setUint32(4, p, !0), O.setUint32(8, y, !0), O.setUint32(12, _, !0), w;
4752
+ }
4753
+ var ns = Object.create, st = Object.defineProperty, ss = Object.getOwnPropertyDescriptor, pi = (i, e) => (e = Symbol[i]) ? e : /* @__PURE__ */ Symbol.for("Symbol." + i), gi = (i) => {
4754
+ throw TypeError(i);
4755
+ }, os = (i, e, t) => e in i ? st(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, as = (i, e) => st(i, "name", { value: e, configurable: !0 }), cs = (i) => [, , , ns(i?.[pi("metadata")] ?? null)], ls = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], mi = (i) => i !== void 0 && typeof i != "function" ? gi("Function expected") : i, hs = (i, e, t, r, n) => ({ kind: ls[i], name: e, metadata: r, addInitializer: (s) => t._ ? gi("Already initialized") : n.push(mi(s || null)) }), us = (i, e) => os(e, pi("metadata"), i[3]), fs = (i, e, t, r) => {
4756
+ for (var n = 0, s = i[e >> 1], o = s && s.length; n < o; n++) s[n].call(t);
4757
+ return r;
4758
+ }, ds = (i, e, t, r, n, s) => {
4759
+ var o, a, f, u = e & 7, p = !1, y = 0, _ = i[y] || (i[y] = []), g = u && (n = n.prototype, u < 5 && (u > 3 || !p) && ss(n, t));
4760
+ as(n, t);
4761
+ for (var w = r.length - 1; w >= 0; w--)
4762
+ f = hs(u, t, a = {}, i[3], _), o = (0, r[w])(n, f), a._ = 1, mi(o) && (n = o);
4763
+ return us(i, n), g && st(n, t, g), p ? u ^ 4 ? s : g : n;
4764
+ }, yi, ot, wi;
4765
+ yi = [F(["wiki", "wikiTitle", "wikiPage", "apiService"])];
4766
+ class be extends (wi = z) {
4767
+ constructor(e) {
4768
+ super(e, "wikiFile", !0), this.ctx = e;
4769
+ }
4770
+ get fileRepos() {
4771
+ return this.ctx.wiki.fileRepos || [];
4772
+ }
4773
+ get defaultFileRepo() {
4774
+ return this.fileRepos[0];
4775
+ }
4776
+ get localFileRepo() {
4777
+ return this.fileRepos.find((e) => e.local);
4778
+ }
4779
+ get writableFileRepo() {
4780
+ return this.fileRepos.find((e) => e.canUpload);
4781
+ }
4782
+ getFileName(e) {
4783
+ if (e = this.ctx.wikiTitle.newTitle(e, 6), ![6, -2].includes(e.getNamespaceId()))
4784
+ throw new Error("Not a file title");
4785
+ return e.getMainDBKey().split("/").pop() || "";
4786
+ }
4787
+ getHashPath(e, t = 2) {
4788
+ const r = this.getFileName(e), n = Zn(rs(r));
4789
+ let s = [];
4790
+ for (let o = 1; o <= t; o++)
4791
+ s.push(n.slice(0, o));
4792
+ return s.push(r), s.join("/");
4793
+ }
4794
+ getFileUrl(e, t) {
4795
+ if (t = t || this.defaultFileRepo, !t)
4796
+ throw new Error("No file repository found");
4797
+ const r = this.getHashPath(e);
4798
+ return new URL(`${t.rootUrl}/${r}`, location.origin).toString();
4799
+ }
4800
+ async upload(e, t) {
4801
+ if (t = t || this.writableFileRepo, !t?.canUpload)
4802
+ throw new Error("No writable file repository found");
4803
+ if (!e.file && !e.url && !e.chunk && !e.filekey)
4804
+ throw new Error('At least one of "file", "url", "chunk", or "filekey" is required');
4805
+ return this.ctx.apiService.getClientByFileRepo(t).postWithToken(
4806
+ "csrf",
4807
+ {
4808
+ action: "upload",
4809
+ ...e
4810
+ },
4811
+ { fexiosOptions: { timeout: 0 } }
4812
+ );
4813
+ }
4814
+ }
4815
+ ot = cs(wi);
4816
+ be = ds(ot, 0, "WikiFileService", yi, be);
4817
+ fs(ot, 1, be);
4818
+ class ve extends M {
4819
+ constructor(e) {
4820
+ super({
4821
+ name: "InPageEdit"
4822
+ }), this.version = "0.16.1", this.Endpoints = it, this.schema = $, this.config = Ei(ve.DEFAULT_CONFIG, e), this.logger = ar({
4823
+ name: "IPE",
4824
+ color: "#33aaff",
4825
+ level: this.config.logLevel
4826
+ }), this.#t();
4827
+ }
4828
+ static {
4829
+ this.DEFAULT_CONFIG = {
4830
+ apiConfigs: {},
4831
+ legacyPreferences: {},
4832
+ logLevel: Pt.info,
4833
+ storageNamespace: "InPageEdit",
4834
+ autoloadStyles: !0,
4835
+ autoInstallCorePlugins: !0
4836
+ };
4837
+ }
4838
+ async #t() {
4839
+ await this.#i(), this.config.autoInstallCorePlugins && this.#e(), this.#n();
4840
+ }
4841
+ async #i() {
4842
+ this.plugin(we), this.plugin(lr, this.config.apiConfigs), this.plugin(vr), this.plugin(_r), this.plugin(Gr), this.plugin(ye), this.plugin(ln, { dbName: this.config.storageNamespace }), this.plugin(me), this.plugin(be), this.plugin(ge), this.plugin(vn), this.plugin(Ze), this.#r([
4843
+ "i18n",
4844
+ "$",
4845
+ "$$",
4846
+ "api",
4847
+ "currentPage",
4848
+ "resourceLoader",
4849
+ "modal",
4850
+ "preferences",
4851
+ "storage",
4852
+ "theme",
4853
+ "wikiPage",
4854
+ "wikiTitle",
4855
+ // WikiMetadataService
4856
+ "wiki",
4857
+ "getUrl",
4858
+ "getSciprtUrl",
4859
+ "getMainpageUrl"
4860
+ ]);
4861
+ }
4862
+ #r(e) {
4863
+ if (!Array.isArray(e) || e.length === 0) return this;
4864
+ for (const t of e) {
4865
+ const r = this[ve.internal][t];
4866
+ r?.type === "service" && (r.builtin = !0);
4867
+ }
4868
+ return this;
4869
+ }
4870
+ // TODO: 这里不应该硬编码,暂时先这样
4871
+ async #e() {
4872
+ [
4873
+ import("./index-mf_pX14E.js").then(({ PluginAnalytics: t }) => t),
4874
+ import("./index-1sZXko-X.js").then(
4875
+ ({ PluginInArticleLinks: t }) => t
4876
+ ),
4877
+ import("./index-BllIuJSJ.js").then(({ PluginPluginStore: t }) => t),
4878
+ import("./index-BcTomMXW.js").then(
4879
+ ({ PluginPreferencesUI: t }) => t
4880
+ ),
4881
+ import("./index-CN7r2e0P.js").then(({ PluginQuickEdit: t }) => t),
4882
+ import("./index-CkSHCMRN.js").then(({ PluginQuickMove: t }) => t),
4883
+ import("./index-CMmEZcB1.js").then(
4884
+ ({ PluginQuickPreview: t }) => t
4885
+ ),
4886
+ import("./index-42B3CrSO.js").then(({ PluginQuickDiff: t }) => t),
4887
+ import("./index-BBUv7Lv6.js").then(
4888
+ ({ PluginQuickRedirect: t }) => t
4889
+ ),
4890
+ import("./index-Bn6y0Eln.js").then(({ PluginQuickUpload: t }) => t),
4891
+ import("./index-DlCbsA25.js").then(({ PluginQuickUsage: t }) => t),
4892
+ import("./index-TG_MTC9y.js").then(({ PluginToolbox: t }) => t)
4893
+ ].forEach(async (t) => {
4894
+ this.plugin(await t);
4895
+ });
4896
+ }
4897
+ // TODO: 应该抽象到 PluginTheme 中去,暂时先硬编码
4898
+ async #n() {
4899
+ this.inject(["resourceLoader"], (e) => {
4900
+ this.config.autoloadStyles && e.resourceLoader.loadStyle(import.meta.resolve("./style.css"));
4901
+ });
4902
+ }
4903
+ async withInject(e) {
4904
+ const { promise: t, resolve: r } = bt();
4905
+ return this.inject(e, (n) => {
4906
+ r(n);
4907
+ }), t;
4908
+ }
4909
+ }
4910
+ export {
4911
+ Pt as $,
4912
+ lr as A,
4913
+ Ie as C,
4914
+ it as E,
4915
+ Xi as F,
4916
+ ve as I,
4917
+ lt as M,
4918
+ pe as N,
4919
+ Ve as P,
4920
+ Vt as R,
4921
+ $ as S,
4922
+ me as T,
4923
+ be as W,
4924
+ F as a,
4925
+ Ct as b,
4926
+ Ji as c,
4927
+ z as d,
4928
+ Yi as e,
4929
+ ar as f,
4930
+ ys as g,
4931
+ ms as h,
4932
+ ws as i,
4933
+ ln as j,
4934
+ vr as k,
4935
+ R as l,
4936
+ He as m,
4937
+ Gr as n,
4938
+ ye as o,
4939
+ ie as p,
4940
+ dt as q,
4941
+ _r as r,
4942
+ b as s,
4943
+ ge as t,
4944
+ vn as u,
4945
+ Ze as v
4946
+ };
4947
+ //# sourceMappingURL=index-D7rUF8vA.js.map