@sv443-network/userutils 9.4.3 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/LICENSE.txt +1 -1
- package/README.md +164 -86
- package/dist/UserUtils.cjs +1889 -0
- package/dist/UserUtils.mjs +1856 -0
- package/dist/UserUtils.umd.js +2078 -0
- package/dist/lib/Dialog.d.ts +2 -1
- package/dist/lib/Errors.d.ts +9 -0
- package/dist/lib/GMStorageEngine.d.ts +33 -0
- package/dist/lib/Mixins.d.ts +14 -11
- package/dist/lib/SelectorObserver.d.ts +1 -2
- package/dist/lib/dom.d.ts +8 -1
- package/dist/lib/index.d.ts +3 -11
- package/dist/lib/translation.d.ts +1 -1
- package/package.json +43 -50
- package/dist/index.cjs +0 -2076
- package/dist/index.global.js +0 -2118
- package/dist/index.js +0 -2019
- package/dist/lib/DataStore.d.ts +0 -164
- package/dist/lib/DataStoreSerializer.d.ts +0 -115
- package/dist/lib/Debouncer.d.ts +0 -86
- package/dist/lib/NanoEmitter.d.ts +0 -71
- package/dist/lib/array.d.ts +0 -17
- package/dist/lib/colors.d.ts +0 -25
- package/dist/lib/crypto.d.ts +0 -29
- package/dist/lib/errors.d.ts +0 -21
- package/dist/lib/math.d.ts +0 -81
- package/dist/lib/misc.d.ts +0 -69
- package/dist/lib/types.d.ts +0 -38
|
@@ -0,0 +1,2078 @@
|
|
|
1
|
+
/* umd */
|
|
2
|
+
(function (g, f) {
|
|
3
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
4
|
+
module.exports = f();
|
|
5
|
+
} else if ("function" == typeof define && define.amd) {
|
|
6
|
+
define("UserUtils", [], f);
|
|
7
|
+
} else if ("object" == typeof exports) {
|
|
8
|
+
exports["UserUtils"] = f();
|
|
9
|
+
} else {
|
|
10
|
+
g["UserUtils"] = f();
|
|
11
|
+
}
|
|
12
|
+
}(this, () => {
|
|
13
|
+
var exports = {};
|
|
14
|
+
var module = { exports };
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
var __create = Object.create;
|
|
21
|
+
var __defProp = Object.defineProperty;
|
|
22
|
+
var __defProps = Object.defineProperties;
|
|
23
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
24
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
25
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
26
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
27
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
28
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
29
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
30
|
+
var __pow = Math.pow;
|
|
31
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
32
|
+
var __spreadValues = (a, b) => {
|
|
33
|
+
for (var prop in b || (b = {}))
|
|
34
|
+
if (__hasOwnProp.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
if (__getOwnPropSymbols)
|
|
37
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
38
|
+
if (__propIsEnum.call(b, prop))
|
|
39
|
+
__defNormalProp(a, prop, b[prop]);
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
42
|
+
};
|
|
43
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
44
|
+
var __objRest = (source, exclude) => {
|
|
45
|
+
var target = {};
|
|
46
|
+
for (var prop in source)
|
|
47
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
48
|
+
target[prop] = source[prop];
|
|
49
|
+
if (source != null && __getOwnPropSymbols)
|
|
50
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
51
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
52
|
+
target[prop] = source[prop];
|
|
53
|
+
}
|
|
54
|
+
return target;
|
|
55
|
+
};
|
|
56
|
+
var __export = (target, all) => {
|
|
57
|
+
for (var name in all)
|
|
58
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
59
|
+
};
|
|
60
|
+
var __copyProps = (to, from, except, desc) => {
|
|
61
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
62
|
+
for (let key of __getOwnPropNames(from))
|
|
63
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
64
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
65
|
+
}
|
|
66
|
+
return to;
|
|
67
|
+
};
|
|
68
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
69
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
70
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
71
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
72
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
73
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
74
|
+
mod
|
|
75
|
+
));
|
|
76
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
77
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
78
|
+
var __async = (__this, __arguments, generator) => {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
var fulfilled = (value) => {
|
|
81
|
+
try {
|
|
82
|
+
step(generator.next(value));
|
|
83
|
+
} catch (e) {
|
|
84
|
+
reject(e);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var rejected = (value) => {
|
|
88
|
+
try {
|
|
89
|
+
step(generator.throw(value));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
reject(e);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
95
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// lib/index.ts
|
|
100
|
+
var lib_exports = {};
|
|
101
|
+
__export(lib_exports, {
|
|
102
|
+
Dialog: () => Dialog,
|
|
103
|
+
GMStorageEngine: () => GMStorageEngine,
|
|
104
|
+
Mixins: () => Mixins,
|
|
105
|
+
PlatformError: () => PlatformError,
|
|
106
|
+
SelectorObserver: () => SelectorObserver,
|
|
107
|
+
addGlobalStyle: () => addGlobalStyle,
|
|
108
|
+
addParent: () => addParent,
|
|
109
|
+
currentDialogId: () => currentDialogId,
|
|
110
|
+
defaultDialogCss: () => defaultDialogCss,
|
|
111
|
+
defaultStrings: () => defaultStrings,
|
|
112
|
+
getSiblingsFrame: () => getSiblingsFrame,
|
|
113
|
+
getUnsafeWindow: () => getUnsafeWindow,
|
|
114
|
+
interceptEvent: () => interceptEvent,
|
|
115
|
+
interceptWindowEvent: () => interceptWindowEvent,
|
|
116
|
+
isDomLoaded: () => isDomLoaded,
|
|
117
|
+
isScrollable: () => isScrollable,
|
|
118
|
+
observeElementProp: () => observeElementProp,
|
|
119
|
+
onDomLoad: () => onDomLoad,
|
|
120
|
+
openDialogs: () => openDialogs,
|
|
121
|
+
openInNewTab: () => openInNewTab,
|
|
122
|
+
preloadImages: () => preloadImages,
|
|
123
|
+
probeElementStyle: () => probeElementStyle,
|
|
124
|
+
setInnerHtmlUnsafe: () => setInnerHtmlUnsafe,
|
|
125
|
+
tr: () => tr
|
|
126
|
+
});
|
|
127
|
+
module.exports = __toCommonJS(lib_exports);
|
|
128
|
+
|
|
129
|
+
// node_modules/.pnpm/@sv443-network+coreutils@3.0.1/node_modules/@sv443-network/coreutils/dist/CoreUtils.min.umd.js
|
|
130
|
+
(function(g, f) {
|
|
131
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
132
|
+
module.exports = f();
|
|
133
|
+
} else if ("function" == typeof define && define.amd) {
|
|
134
|
+
define("CoreUtils", [], f);
|
|
135
|
+
} else if ("object" == typeof exports) {
|
|
136
|
+
exports["CoreUtils"] = f();
|
|
137
|
+
} else {
|
|
138
|
+
g["CoreUtils"] = f();
|
|
139
|
+
}
|
|
140
|
+
})(void 0, () => {
|
|
141
|
+
var exports2 = {};
|
|
142
|
+
var module2 = { exports: exports2 };
|
|
143
|
+
"use strict";
|
|
144
|
+
var X = Object.create;
|
|
145
|
+
var F = Object.defineProperty;
|
|
146
|
+
var Y = Object.getOwnPropertyDescriptor;
|
|
147
|
+
var ee = Object.getOwnPropertyNames;
|
|
148
|
+
var te = Object.getPrototypeOf, re = Object.prototype.hasOwnProperty;
|
|
149
|
+
var ie = (r, e) => {
|
|
150
|
+
for (var t in e) F(r, t, { get: e[t], enumerable: true });
|
|
151
|
+
}, B = (r, e, t, i) => {
|
|
152
|
+
if (e && typeof e == "object" || typeof e == "function") for (let n of ee(e)) !re.call(r, n) && n !== t && F(r, n, { get: () => e[n], enumerable: !(i = Y(e, n)) || i.enumerable });
|
|
153
|
+
return r;
|
|
154
|
+
};
|
|
155
|
+
var I = (r, e, t) => (t = r != null ? X(te(r)) : {}, B(e || !r || !r.__esModule ? F(t, "default", { value: r, enumerable: true }) : t, r)), ne = (r) => B(F({}, "__esModule", { value: true }), r);
|
|
156
|
+
var _e = {};
|
|
157
|
+
ie(_e, { BrowserStorageEngine: () => U, ChecksumMismatchError: () => S, CustomError: () => v, DataStore: () => z, DataStoreEngine: () => E, DataStoreSerializer: () => j, DatedError: () => d, Debouncer: () => A, FileStorageEngine: () => R, MigrationError: () => w, NanoEmitter: () => P, NetworkError: () => x, ScriptContextError: () => g, ValidationError: () => $, abtoa: () => H, atoab: () => W, autoPlural: () => Pe, bitSetHas: () => ae, capitalize: () => Oe, clamp: () => D, compress: () => N, computeHash: () => k, consumeGen: () => ge, consumeStringGen: () => be, createProgressBar: () => Fe, darkenColor: () => L, debounce: () => Ie, decompress: () => fe, defaultPbChars: () => Q, digitCount: () => oe, fetchAdvanced: () => ye, formatNumber: () => se, getCallStack: () => Ee, getListLength: () => De, hexToRgb: () => q, insertValues: () => Ve, joinArrayReadable: () => Ne, lightenColor: () => pe, mapRange: () => V, overflowVal: () => ue, pauseFor: () => Te, pureObj: () => Se, randRange: () => T, randomId: () => he, randomItem: () => le, randomItemIndex: () => C, randomizeArray: () => de, rgbToHex: () => J, roundFixed: () => _, scheduleExit: () => xe, secsToTimeStr: () => Ae, setImmediateInterval: () => ve, setImmediateTimeoutLoop: () => we, takeRandomItem: () => me, takeRandomItemIndex: () => K, truncStr: () => Me, valsWithin: () => ce });
|
|
158
|
+
module2.exports = ne(_e);
|
|
159
|
+
function ae(r, e) {
|
|
160
|
+
return (r & e) === e;
|
|
161
|
+
}
|
|
162
|
+
function D(r, e, t) {
|
|
163
|
+
return typeof t != "number" && (t = e, e = 0), Math.max(Math.min(r, t), e);
|
|
164
|
+
}
|
|
165
|
+
function oe(r, e = true) {
|
|
166
|
+
if (r = Number(["string", "number"].includes(typeof r) ? r : String(r)), typeof r == "number" && isNaN(r)) return NaN;
|
|
167
|
+
let [t, i] = r.toString().split("."), n = t === "0" ? 1 : Math.floor(Math.log10(Math.abs(Number(t))) + 1), o = e && i ? i.length : 0;
|
|
168
|
+
return n + o;
|
|
169
|
+
}
|
|
170
|
+
function se(r, e, t) {
|
|
171
|
+
return r.toLocaleString(e, t === "short" ? { notation: "compact", compactDisplay: "short", maximumFractionDigits: 1 } : { style: "decimal", maximumFractionDigits: 0 });
|
|
172
|
+
}
|
|
173
|
+
function V(r, e, t, i, n) {
|
|
174
|
+
return (typeof i > "u" || typeof n > "u") && (n = t, t = e, i = e = 0), Number(e) === 0 && Number(i) === 0 ? r * (n / t) : (r - e) * ((n - i) / (t - e)) + i;
|
|
175
|
+
}
|
|
176
|
+
function ue(r, e, t) {
|
|
177
|
+
let i = typeof t == "number" ? e : 0;
|
|
178
|
+
if (t = typeof t == "number" ? t : e, i > t) throw new RangeError(`Parameter "min" can't be bigger than "max"`);
|
|
179
|
+
if (isNaN(r) || isNaN(i) || isNaN(t) || !isFinite(r) || !isFinite(i) || !isFinite(t)) return NaN;
|
|
180
|
+
if (r >= i && r <= t) return r;
|
|
181
|
+
let n = t - i + 1;
|
|
182
|
+
return ((r - i) % n + n) % n + i;
|
|
183
|
+
}
|
|
184
|
+
function T(...r) {
|
|
185
|
+
let e, t, i = false;
|
|
186
|
+
if (typeof r[0] == "number" && typeof r[1] == "number") [e, t] = r;
|
|
187
|
+
else if (typeof r[0] == "number" && typeof r[1] != "number") e = 0, [t] = r;
|
|
188
|
+
else throw new TypeError(`Wrong parameter(s) provided - expected (number, boolean|undefined) or (number, number, boolean|undefined) but got (${r.map((n) => typeof n).join(", ")}) instead`);
|
|
189
|
+
if (typeof r[2] == "boolean" ? i = r[2] : typeof r[1] == "boolean" && (i = r[1]), e = Number(e), t = Number(t), isNaN(e) || isNaN(t)) return NaN;
|
|
190
|
+
if (e > t) throw new TypeError(`Parameter "min" can't be bigger than "max"`);
|
|
191
|
+
if (i) {
|
|
192
|
+
let n = new Uint8Array(1);
|
|
193
|
+
return crypto.getRandomValues(n), Number(Array.from(n, (o) => Math.round(V(o, 0, 255, e, t)).toString(10)).join(""));
|
|
194
|
+
} else return Math.floor(Math.random() * (t - e + 1)) + e;
|
|
195
|
+
}
|
|
196
|
+
function _(r, e) {
|
|
197
|
+
let t = __pow(10, e);
|
|
198
|
+
return Math.round(r * t) / t;
|
|
199
|
+
}
|
|
200
|
+
function ce(r, e, t = 1, i = 0.5) {
|
|
201
|
+
return Math.abs(_(r, t) - _(e, t)) <= i;
|
|
202
|
+
}
|
|
203
|
+
function le(r) {
|
|
204
|
+
return C(r)[0];
|
|
205
|
+
}
|
|
206
|
+
function C(r) {
|
|
207
|
+
if (r.length === 0) return [void 0, void 0];
|
|
208
|
+
let e = T(r.length - 1);
|
|
209
|
+
return [r[e], e];
|
|
210
|
+
}
|
|
211
|
+
function de(r) {
|
|
212
|
+
let e = [...r];
|
|
213
|
+
if (r.length === 0) return e;
|
|
214
|
+
for (let t = e.length - 1; t > 0; t--) {
|
|
215
|
+
let i = Math.floor(Math.random() * (t + 1));
|
|
216
|
+
[e[t], e[i]] = [e[i], e[t]];
|
|
217
|
+
}
|
|
218
|
+
return e;
|
|
219
|
+
}
|
|
220
|
+
function me(r) {
|
|
221
|
+
var e;
|
|
222
|
+
return (e = K(r)) == null ? void 0 : e[0];
|
|
223
|
+
}
|
|
224
|
+
function K(r) {
|
|
225
|
+
let [e, t] = C(r);
|
|
226
|
+
return t === void 0 ? [void 0, void 0] : (r.splice(t, 1), [e, t]);
|
|
227
|
+
}
|
|
228
|
+
function L(r, e, t = false) {
|
|
229
|
+
var l;
|
|
230
|
+
r = r.trim();
|
|
231
|
+
let i = (c, p, m, b) => (c = Math.max(0, Math.min(255, c - c * b / 100)), p = Math.max(0, Math.min(255, p - p * b / 100)), m = Math.max(0, Math.min(255, m - m * b / 100)), [c, p, m]), n, o, a, s, u = r.match(/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/);
|
|
232
|
+
if (u) [n, o, a, s] = q(r);
|
|
233
|
+
else if (r.startsWith("rgb")) {
|
|
234
|
+
let c = (l = r.match(/\d+(\.\d+)?/g)) == null ? void 0 : l.map(Number);
|
|
235
|
+
if (!c) throw new TypeError("Invalid RGB/RGBA color format");
|
|
236
|
+
[n, o, a, s] = c;
|
|
237
|
+
} else throw new TypeError("Unsupported color format");
|
|
238
|
+
return [n, o, a] = i(n, o, a, e), u ? J(n, o, a, s, r.startsWith("#"), t) : r.startsWith("rgba") ? `rgba(${n}, ${o}, ${a}, ${s != null ? s : NaN})` : `rgb(${n}, ${o}, ${a})`;
|
|
239
|
+
}
|
|
240
|
+
function q(r) {
|
|
241
|
+
r = (r.startsWith("#") ? r.slice(1) : r).trim();
|
|
242
|
+
let e = r.length === 8 || r.length === 4 ? parseInt(r.slice(-(r.length / 4)), 16) / (r.length === 8 ? 255 : 15) : void 0;
|
|
243
|
+
isNaN(Number(e)) || (r = r.slice(0, -(r.length / 4))), (r.length === 3 || r.length === 4) && (r = r.split("").map((a) => a + a).join(""));
|
|
244
|
+
let t = parseInt(r, 16), i = t >> 16 & 255, n = t >> 8 & 255, o = t & 255;
|
|
245
|
+
return [D(i, 0, 255), D(n, 0, 255), D(o, 0, 255), typeof e == "number" ? D(e, 0, 1) : void 0];
|
|
246
|
+
}
|
|
247
|
+
function pe(r, e, t = false) {
|
|
248
|
+
return L(r, e * -1, t);
|
|
249
|
+
}
|
|
250
|
+
function J(r, e, t, i, n = true, o = false) {
|
|
251
|
+
let a = (s) => D(Math.round(s), 0, 255).toString(16).padStart(2, "0")[o ? "toUpperCase" : "toLowerCase"]();
|
|
252
|
+
return `${n ? "#" : ""}${a(r)}${a(e)}${a(t)}${i ? a(i * 255) : ""}`;
|
|
253
|
+
}
|
|
254
|
+
function H(r) {
|
|
255
|
+
return btoa(new Uint8Array(r).reduce((e, t) => e + String.fromCharCode(t), ""));
|
|
256
|
+
}
|
|
257
|
+
function W(r) {
|
|
258
|
+
return Uint8Array.from(atob(r), (e) => e.charCodeAt(0));
|
|
259
|
+
}
|
|
260
|
+
function N(r, e, t = "string") {
|
|
261
|
+
return __async(this, null, function* () {
|
|
262
|
+
var _a;
|
|
263
|
+
let i = r instanceof Uint8Array ? r : new TextEncoder().encode((_a = r == null ? void 0 : r.toString()) != null ? _a : String(r)), n = new CompressionStream(e), o = n.writable.getWriter();
|
|
264
|
+
o.write(i), o.close();
|
|
265
|
+
let a = new Uint8Array(yield new Response(n.readable).arrayBuffer());
|
|
266
|
+
return t === "arrayBuffer" ? a : H(a);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function fe(r, e, t = "string") {
|
|
270
|
+
return __async(this, null, function* () {
|
|
271
|
+
var _a;
|
|
272
|
+
let i = r instanceof Uint8Array ? r : W((_a = r == null ? void 0 : r.toString()) != null ? _a : String(r)), n = new DecompressionStream(e), o = n.writable.getWriter();
|
|
273
|
+
o.write(i), o.close();
|
|
274
|
+
let a = new Uint8Array(yield new Response(n.readable).arrayBuffer());
|
|
275
|
+
return t === "arrayBuffer" ? a : new TextDecoder().decode(a);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function k(r, e = "SHA-256") {
|
|
279
|
+
return __async(this, null, function* () {
|
|
280
|
+
let t;
|
|
281
|
+
typeof r == "string" ? t = new TextEncoder().encode(r) : t = r;
|
|
282
|
+
let i = yield crypto.subtle.digest(e, t);
|
|
283
|
+
return Array.from(new Uint8Array(i)).map((a) => a.toString(16).padStart(2, "0")).join("");
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function he(r = 16, e = 16, t = false, i = true) {
|
|
287
|
+
if (r < 1) throw new RangeError("The length argument must be at least 1");
|
|
288
|
+
if (e < 2 || e > 36) throw new RangeError("The radix argument must be between 2 and 36");
|
|
289
|
+
let n = [], o = i ? [0, 1] : [0];
|
|
290
|
+
if (t) {
|
|
291
|
+
let a = new Uint8Array(r);
|
|
292
|
+
crypto.getRandomValues(a), n = Array.from(a, (s) => V(s, 0, 255, 0, e).toString(e).substring(0, 1));
|
|
293
|
+
} else n = Array.from({ length: r }, () => Math.floor(Math.random() * e).toString(e));
|
|
294
|
+
return n.some((a) => /[a-zA-Z]/.test(a)) ? n.map((a) => o[T(0, o.length - 1, t)] === 1 ? a.toUpperCase() : a).join("") : n.join("");
|
|
295
|
+
}
|
|
296
|
+
var d = class extends Error {
|
|
297
|
+
constructor(e, t) {
|
|
298
|
+
super(e, t);
|
|
299
|
+
__publicField(this, "date");
|
|
300
|
+
this.name = this.constructor.name, this.date = /* @__PURE__ */ new Date();
|
|
301
|
+
}
|
|
302
|
+
}, S = class extends d {
|
|
303
|
+
constructor(e, t) {
|
|
304
|
+
super(e, t), this.name = "ChecksumMismatchError";
|
|
305
|
+
}
|
|
306
|
+
}, v = class extends d {
|
|
307
|
+
constructor(e, t, i) {
|
|
308
|
+
super(t, i), this.name = e;
|
|
309
|
+
}
|
|
310
|
+
}, w = class extends d {
|
|
311
|
+
constructor(e, t) {
|
|
312
|
+
super(e, t), this.name = "MigrationError";
|
|
313
|
+
}
|
|
314
|
+
}, $ = class extends d {
|
|
315
|
+
constructor(e, t) {
|
|
316
|
+
super(e, t), this.name = "ValidationError";
|
|
317
|
+
}
|
|
318
|
+
}, g = class extends d {
|
|
319
|
+
constructor(e, t) {
|
|
320
|
+
super(e, t), this.name = "ScriptContextError";
|
|
321
|
+
}
|
|
322
|
+
}, x = class extends d {
|
|
323
|
+
constructor(e, t) {
|
|
324
|
+
super(e, t), this.name = "NetworkError";
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
function ge(r) {
|
|
328
|
+
return __async(this, null, function* () {
|
|
329
|
+
return yield typeof r == "function" ? r() : r;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function be(r) {
|
|
333
|
+
return __async(this, null, function* () {
|
|
334
|
+
return typeof r == "string" ? r : String(typeof r == "function" ? yield r() : r);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function ye(_0) {
|
|
338
|
+
return __async(this, arguments, function* (r, e = {}) {
|
|
339
|
+
let _a = e, { timeout: t = 1e4, signal: i } = _a, n = __objRest(_a, ["timeout", "signal"]), o = new AbortController();
|
|
340
|
+
i == null || i.addEventListener("abort", () => o.abort());
|
|
341
|
+
let a = {}, s;
|
|
342
|
+
t >= 0 && (s = setTimeout(() => o.abort(), t), a = { signal: o.signal });
|
|
343
|
+
try {
|
|
344
|
+
let u = yield fetch(r, __spreadValues(__spreadValues({}, n), a));
|
|
345
|
+
return typeof s < "u" && clearTimeout(s), u;
|
|
346
|
+
} catch (u) {
|
|
347
|
+
throw typeof s < "u" && clearTimeout(s), new x("Error while calling fetch", { cause: u });
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function De(r, e = true) {
|
|
352
|
+
return "length" in r ? r.length : "size" in r ? r.size : "count" in r ? r.count : e ? 0 : NaN;
|
|
353
|
+
}
|
|
354
|
+
function Te(r, e, t = false) {
|
|
355
|
+
return new Promise((i, n) => {
|
|
356
|
+
let o = setTimeout(() => i(), r);
|
|
357
|
+
e == null || e.addEventListener("abort", () => {
|
|
358
|
+
clearTimeout(o), t ? n(new v("AbortError", "The pause was aborted")) : i();
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
function Se(r) {
|
|
363
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), r != null ? r : {});
|
|
364
|
+
}
|
|
365
|
+
function ve(r, e, t) {
|
|
366
|
+
let i, n = () => clearInterval(i), o = () => {
|
|
367
|
+
if (t != null && t.aborted) return n();
|
|
368
|
+
r();
|
|
369
|
+
};
|
|
370
|
+
t == null || t.addEventListener("abort", n), o(), i = setInterval(o, e);
|
|
371
|
+
}
|
|
372
|
+
function we(r, e, t) {
|
|
373
|
+
let i, n = () => clearTimeout(i), o = () => __async(null, null, function* () {
|
|
374
|
+
if (t != null && t.aborted) return n();
|
|
375
|
+
yield r(), i = setTimeout(o, e);
|
|
376
|
+
});
|
|
377
|
+
t == null || t.addEventListener("abort", n), o();
|
|
378
|
+
}
|
|
379
|
+
function xe(r = 0, e = 0) {
|
|
380
|
+
if (e < 0) throw new TypeError("Timeout must be a non-negative number");
|
|
381
|
+
let t;
|
|
382
|
+
if (typeof process < "u" && "exit" in process && typeof process.exit == "function") t = () => process.exit(r);
|
|
383
|
+
else if (typeof Deno < "u" && "exit" in Deno && typeof Deno.exit == "function") t = () => Deno.exit(r);
|
|
384
|
+
else throw new g("Cannot exit the process, no exit method available");
|
|
385
|
+
setTimeout(t, e);
|
|
386
|
+
}
|
|
387
|
+
function Ee(r, e = 1 / 0) {
|
|
388
|
+
var _a;
|
|
389
|
+
if (typeof e != "number" || isNaN(e) || e < 0) throw new TypeError("lines parameter must be a non-negative number");
|
|
390
|
+
try {
|
|
391
|
+
throw new Error("This is to capture a stack trace with CoreUtils.getCallStack(). (If you see this somewhere, you can safely ignore it.)");
|
|
392
|
+
} catch (t) {
|
|
393
|
+
let i = ((_a = t.stack) != null ? _a : "").split(`
|
|
394
|
+
`).map((n) => n.trim()).slice(2, e + 2);
|
|
395
|
+
return r !== false ? i : i.join(`
|
|
396
|
+
`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function Pe(r, e, t = "auto") {
|
|
400
|
+
switch (typeof e != "number" && ("length" in e ? e = e.length : "size" in e ? e = e.size : "count" in e && (e = e.count)), ["-s", "-ies"].includes(t) || (t = "auto"), isNaN(e) && (e = 2), t === "auto" ? String(r).endsWith("y") ? "-ies" : "-s" : t) {
|
|
401
|
+
case "-s":
|
|
402
|
+
return `${r}${e === 1 ? "" : "s"}`;
|
|
403
|
+
case "-ies":
|
|
404
|
+
return `${String(r).slice(0, -1)}${e === 1 ? "y" : "ies"}`;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function Oe(r) {
|
|
408
|
+
return r.charAt(0).toUpperCase() + r.slice(1);
|
|
409
|
+
}
|
|
410
|
+
var Q = { 100: "\u2588", 75: "\u2593", 50: "\u2592", 25: "\u2591", 0: "\u2500" };
|
|
411
|
+
function Fe(r, e, t = Q) {
|
|
412
|
+
if (r === 100) return t[100].repeat(e);
|
|
413
|
+
let i = Math.floor(r / 100 * e), n = r / 10 * e - i, o = "";
|
|
414
|
+
n >= 0.75 ? o = t[75] : n >= 0.5 ? o = t[50] : n >= 0.25 && (o = t[25]);
|
|
415
|
+
let a = t[100].repeat(i), s = t[0].repeat(e - i - (o ? 1 : 0));
|
|
416
|
+
return `${a}${o}${s}`;
|
|
417
|
+
}
|
|
418
|
+
function Ve(r, ...e) {
|
|
419
|
+
return r.replace(/%\d/gm, (t) => {
|
|
420
|
+
var _a;
|
|
421
|
+
var n;
|
|
422
|
+
let i = Number(t.substring(1)) - 1;
|
|
423
|
+
return (n = (_a = e[i]) != null ? _a : t) == null ? void 0 : n.toString();
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function Ne(r, e = ", ", t = " and ") {
|
|
427
|
+
let i = [...r];
|
|
428
|
+
if (i.length === 0) return "";
|
|
429
|
+
if (i.length === 1) return String(i[0]);
|
|
430
|
+
if (i.length === 2) return i.join(t);
|
|
431
|
+
let n = t + i[i.length - 1];
|
|
432
|
+
return i.pop(), i.join(e) + n;
|
|
433
|
+
}
|
|
434
|
+
function Ae(r) {
|
|
435
|
+
let e = r < 0, t = Math.abs(r);
|
|
436
|
+
if (isNaN(t) || !isFinite(t)) throw new TypeError("The seconds argument must be a valid number");
|
|
437
|
+
let i = Math.floor(t / 3600), n = Math.floor(t % 3600 / 60), o = Math.floor(t % 60);
|
|
438
|
+
return (e ? "-" : "") + [i ? i + ":" : "", String(n).padStart(n > 0 || i > 0 ? 2 : 1, "0"), ":", String(o).padStart(o > 0 || n > 0 || i > 0 || r === 0 ? 2 : 1, "0")].join("");
|
|
439
|
+
}
|
|
440
|
+
function Me(r, e, t = "...") {
|
|
441
|
+
var _a;
|
|
442
|
+
let i = (_a = r == null ? void 0 : r.toString()) != null ? _a : String(r), n = i.length > e ? i.substring(0, e - t.length) + t : i;
|
|
443
|
+
return n.length > e ? n.substring(0, e) : n;
|
|
444
|
+
}
|
|
445
|
+
var G = 1, z = class {
|
|
446
|
+
constructor(e) {
|
|
447
|
+
__publicField(this, "id");
|
|
448
|
+
__publicField(this, "formatVersion");
|
|
449
|
+
__publicField(this, "defaultData");
|
|
450
|
+
__publicField(this, "encodeData");
|
|
451
|
+
__publicField(this, "decodeData");
|
|
452
|
+
__publicField(this, "compressionFormat", "deflate-raw");
|
|
453
|
+
__publicField(this, "memoryCache", true);
|
|
454
|
+
__publicField(this, "engine");
|
|
455
|
+
__publicField(this, "options");
|
|
456
|
+
__publicField(this, "firstInit", true);
|
|
457
|
+
__publicField(this, "cachedData");
|
|
458
|
+
__publicField(this, "migrations");
|
|
459
|
+
__publicField(this, "migrateIds", []);
|
|
460
|
+
var _a, _b, _c;
|
|
461
|
+
var t;
|
|
462
|
+
if (this.id = e.id, this.formatVersion = e.formatVersion, this.defaultData = e.defaultData, this.memoryCache = !!((_a = e.memoryCache) != null ? _a : true), this.cachedData = this.memoryCache ? e.defaultData : {}, this.migrations = e.migrations, e.migrateIds && (this.migrateIds = Array.isArray(e.migrateIds) ? e.migrateIds : [e.migrateIds]), this.encodeData = e.encodeData, this.decodeData = e.decodeData, this.engine = typeof e.engine == "function" ? e.engine() : e.engine, this.options = e, typeof e.compressionFormat > "u" && (this.compressionFormat = e.compressionFormat = (_b = (t = e.encodeData) == null ? void 0 : t[0]) != null ? _b : "deflate-raw"), typeof e.compressionFormat == "string") this.encodeData = [e.compressionFormat, (i) => __async(this, null, function* () {
|
|
463
|
+
return yield N(i, e.compressionFormat, "string");
|
|
464
|
+
})], this.decodeData = [e.compressionFormat, (i) => __async(this, null, function* () {
|
|
465
|
+
return yield N(i, e.compressionFormat, "string");
|
|
466
|
+
})];
|
|
467
|
+
else if ("encodeData" in e && "decodeData" in e && Array.isArray(e.encodeData) && Array.isArray(e.decodeData)) this.encodeData = [e.encodeData[0], e.encodeData[1]], this.decodeData = [e.decodeData[0], e.decodeData[1]], this.compressionFormat = (_c = e.encodeData[0]) != null ? _c : null;
|
|
468
|
+
else if (e.compressionFormat === null) this.encodeData = void 0, this.decodeData = void 0, this.compressionFormat = null;
|
|
469
|
+
else throw new TypeError("Either `compressionFormat` or `encodeData` and `decodeData` have to be set and valid, but not all three at a time. Please refer to the documentation for more info.");
|
|
470
|
+
this.engine.setDataStoreOptions(e);
|
|
471
|
+
}
|
|
472
|
+
loadData() {
|
|
473
|
+
return __async(this, null, function* () {
|
|
474
|
+
var _a;
|
|
475
|
+
try {
|
|
476
|
+
if (this.firstInit) {
|
|
477
|
+
this.firstInit = false;
|
|
478
|
+
let u = Number(yield this.engine.getValue("__ds_fmt_ver", 0)), l = yield this.engine.getValue(`_uucfg-${this.id}`, null);
|
|
479
|
+
if (l) {
|
|
480
|
+
let c = Number(yield this.engine.getValue(`_uucfgver-${this.id}`, NaN)), p = yield this.engine.getValue(`_uucfgenc-${this.id}`, null), m = [], b = (O, h, y) => {
|
|
481
|
+
m.push(this.engine.setValue(h, y)), m.push(this.engine.deleteValue(O));
|
|
482
|
+
};
|
|
483
|
+
b(`_uucfg-${this.id}`, `__ds-${this.id}-dat`, l), isNaN(c) || b(`_uucfgver-${this.id}`, `__ds-${this.id}-ver`, c), typeof p == "boolean" ? b(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, p === true ? (_a = this.compressionFormat) != null ? _a : null : null) : (m.push(this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)), m.push(this.engine.deleteValue(`_uucfgenc-${this.id}`))), yield Promise.allSettled(m);
|
|
484
|
+
}
|
|
485
|
+
(isNaN(u) || u < G) && (yield this.engine.setValue("__ds_fmt_ver", G));
|
|
486
|
+
}
|
|
487
|
+
this.migrateIds.length > 0 && (yield this.migrateId(this.migrateIds), this.migrateIds = []);
|
|
488
|
+
let e = yield this.engine.getValue(`__ds-${this.id}-dat`, null), t = Number(yield this.engine.getValue(`__ds-${this.id}-ver`, NaN));
|
|
489
|
+
if (typeof e != "string") return yield this.saveDefaultData(), this.engine.deepCopy(this.defaultData);
|
|
490
|
+
let i = e != null ? e : JSON.stringify(this.defaultData), n = String(yield this.engine.getValue(`__ds-${this.id}-enf`, null)), o = n !== "null" && n !== "false", a = false;
|
|
491
|
+
isNaN(t) && (yield this.engine.setValue(`__ds-${this.id}-ver`, t = this.formatVersion), a = true);
|
|
492
|
+
let s = yield this.engine.deserializeData(i, o);
|
|
493
|
+
return t < this.formatVersion && this.migrations && (s = yield this.runMigrations(s, t)), a && (yield this.setData(s)), this.memoryCache ? this.cachedData = this.engine.deepCopy(s) : this.engine.deepCopy(s);
|
|
494
|
+
} catch (e) {
|
|
495
|
+
return console.warn("Error while parsing JSON data, resetting it to the default value.", e), yield this.saveDefaultData(), this.defaultData;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
getData() {
|
|
500
|
+
if (!this.memoryCache) throw new d("In-memory cache is disabled for this DataStore instance, so getData() can't be used. Please use loadData() instead.");
|
|
501
|
+
return this.engine.deepCopy(this.cachedData);
|
|
502
|
+
}
|
|
503
|
+
setData(e) {
|
|
504
|
+
return this.memoryCache && (this.cachedData = e), new Promise((t) => __async(this, null, function* () {
|
|
505
|
+
yield Promise.allSettled([this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(e, this.encodingEnabled())), this.engine.setValue(`__ds-${this.id}-ver`, this.formatVersion), this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)]), t();
|
|
506
|
+
}));
|
|
507
|
+
}
|
|
508
|
+
saveDefaultData() {
|
|
509
|
+
return __async(this, null, function* () {
|
|
510
|
+
this.memoryCache && (this.cachedData = this.defaultData), yield Promise.allSettled([this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(this.defaultData, this.encodingEnabled())), this.engine.setValue(`__ds-${this.id}-ver`, this.formatVersion), this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)]);
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
deleteData() {
|
|
514
|
+
return __async(this, null, function* () {
|
|
515
|
+
var e, t;
|
|
516
|
+
yield Promise.allSettled([this.engine.deleteValue(`__ds-${this.id}-dat`), this.engine.deleteValue(`__ds-${this.id}-ver`), this.engine.deleteValue(`__ds-${this.id}-enf`)]), yield (t = (e = this.engine).deleteStorage) == null ? void 0 : t.call(e);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
encodingEnabled() {
|
|
520
|
+
return !!(this.encodeData && this.decodeData) && this.compressionFormat !== null || !!this.compressionFormat;
|
|
521
|
+
}
|
|
522
|
+
runMigrations(e, t, i = true) {
|
|
523
|
+
return __async(this, null, function* () {
|
|
524
|
+
if (!this.migrations) return e;
|
|
525
|
+
let n = e, o = Object.entries(this.migrations).sort(([s], [u]) => Number(s) - Number(u)), a = t;
|
|
526
|
+
for (let [s, u] of o) {
|
|
527
|
+
let l = Number(s);
|
|
528
|
+
if (t < this.formatVersion && t < l) try {
|
|
529
|
+
let c = u(n);
|
|
530
|
+
n = c instanceof Promise ? yield c : c, a = t = l;
|
|
531
|
+
} catch (c) {
|
|
532
|
+
if (!i) throw new w(`Error while running migration function for format version '${s}'`, { cause: c });
|
|
533
|
+
return yield this.saveDefaultData(), this.getData();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return yield Promise.allSettled([this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(n)), this.engine.setValue(`__ds-${this.id}-ver`, a), this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)]), this.memoryCache ? this.cachedData = this.engine.deepCopy(n) : this.engine.deepCopy(n);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
migrateId(e) {
|
|
540
|
+
return __async(this, null, function* () {
|
|
541
|
+
let t = Array.isArray(e) ? e : [e];
|
|
542
|
+
yield Promise.all(t.map((i) => __async(this, null, function* () {
|
|
543
|
+
let [n, o, a] = yield (() => __async(this, null, function* () {
|
|
544
|
+
let [u, l, c] = yield Promise.all([this.engine.getValue(`__ds-${i}-dat`, JSON.stringify(this.defaultData)), this.engine.getValue(`__ds-${i}-ver`, NaN), this.engine.getValue(`__ds-${i}-enf`, null)]);
|
|
545
|
+
return [u, Number(l), !!c && String(c) !== "null"];
|
|
546
|
+
}))();
|
|
547
|
+
if (n === void 0 || isNaN(o)) return;
|
|
548
|
+
let s = yield this.engine.deserializeData(n, a);
|
|
549
|
+
yield Promise.allSettled([this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(s)), this.engine.setValue(`__ds-${this.id}-ver`, o), this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat), this.engine.deleteValue(`__ds-${i}-dat`), this.engine.deleteValue(`__ds-${i}-ver`), this.engine.deleteValue(`__ds-${i}-enf`)]);
|
|
550
|
+
})));
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
var E = class {
|
|
555
|
+
constructor(e) {
|
|
556
|
+
__publicField(this, "dataStoreOptions");
|
|
557
|
+
e && (this.dataStoreOptions = e);
|
|
558
|
+
}
|
|
559
|
+
setDataStoreOptions(e) {
|
|
560
|
+
this.dataStoreOptions = e;
|
|
561
|
+
}
|
|
562
|
+
serializeData(e, t) {
|
|
563
|
+
return __async(this, null, function* () {
|
|
564
|
+
var o, a, s, u, l;
|
|
565
|
+
this.ensureDataStoreOptions();
|
|
566
|
+
let i = JSON.stringify(e);
|
|
567
|
+
if (!t || !((o = this.dataStoreOptions) != null && o.encodeData) || !((a = this.dataStoreOptions) != null && a.decodeData)) return i;
|
|
568
|
+
let n = (l = (u = (s = this.dataStoreOptions) == null ? void 0 : s.encodeData) == null ? void 0 : u[1]) == null ? void 0 : l.call(u, i);
|
|
569
|
+
return n instanceof Promise ? yield n : n;
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
deserializeData(e, t) {
|
|
573
|
+
return __async(this, null, function* () {
|
|
574
|
+
var n, o, a;
|
|
575
|
+
this.ensureDataStoreOptions();
|
|
576
|
+
let i = (n = this.dataStoreOptions) != null && n.decodeData && t ? (a = (o = this.dataStoreOptions.decodeData) == null ? void 0 : o[1]) == null ? void 0 : a.call(o, e) : void 0;
|
|
577
|
+
return i instanceof Promise && (i = yield i), JSON.parse(i != null ? i : e);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
ensureDataStoreOptions() {
|
|
581
|
+
if (!this.dataStoreOptions) throw new d("DataStoreEngine must be initialized with DataStore options before use. If you are using this instance standalone, set them in the constructor or call `setDataStoreOptions()` with the DataStore options.");
|
|
582
|
+
if (!this.dataStoreOptions.id) throw new d("DataStoreEngine must be initialized with a valid DataStore ID");
|
|
583
|
+
}
|
|
584
|
+
deepCopy(e) {
|
|
585
|
+
try {
|
|
586
|
+
if ("structuredClone" in globalThis) return structuredClone(e);
|
|
587
|
+
} catch (e2) {
|
|
588
|
+
}
|
|
589
|
+
return JSON.parse(JSON.stringify(e));
|
|
590
|
+
}
|
|
591
|
+
}, U = class extends E {
|
|
592
|
+
constructor(e) {
|
|
593
|
+
super(e == null ? void 0 : e.dataStoreOptions);
|
|
594
|
+
__publicField(this, "options");
|
|
595
|
+
this.options = __spreadValues({ type: "localStorage" }, e);
|
|
596
|
+
}
|
|
597
|
+
getValue(e, t) {
|
|
598
|
+
return __async(this, null, function* () {
|
|
599
|
+
let i = this.options.type === "localStorage" ? globalThis.localStorage.getItem(e) : globalThis.sessionStorage.getItem(e);
|
|
600
|
+
return typeof i > "u" ? t : i;
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
setValue(e, t) {
|
|
604
|
+
return __async(this, null, function* () {
|
|
605
|
+
this.options.type === "localStorage" ? globalThis.localStorage.setItem(e, String(t)) : globalThis.sessionStorage.setItem(e, String(t));
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
deleteValue(e) {
|
|
609
|
+
return __async(this, null, function* () {
|
|
610
|
+
this.options.type === "localStorage" ? globalThis.localStorage.removeItem(e) : globalThis.sessionStorage.removeItem(e);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}, f, R = class extends E {
|
|
614
|
+
constructor(e) {
|
|
615
|
+
super(e == null ? void 0 : e.dataStoreOptions);
|
|
616
|
+
__publicField(this, "options");
|
|
617
|
+
__publicField(this, "fileAccessQueue", Promise.resolve());
|
|
618
|
+
this.options = __spreadValues({ filePath: (t) => `.ds-${t}` }, e);
|
|
619
|
+
}
|
|
620
|
+
readFile() {
|
|
621
|
+
return __async(this, null, function* () {
|
|
622
|
+
var _a;
|
|
623
|
+
var e, t, i, n;
|
|
624
|
+
this.ensureDataStoreOptions();
|
|
625
|
+
try {
|
|
626
|
+
if (f || (f = (e = yield import("fs/promises")) == null ? void 0 : e.default), !f) throw new g("FileStorageEngine requires Node.js or Deno with Node compatibility (v1.31+)", { cause: new d("'node:fs/promises' module not available") });
|
|
627
|
+
let o = typeof this.options.filePath == "string" ? this.options.filePath : this.options.filePath(this.dataStoreOptions.id), a = yield f.readFile(o, "utf-8");
|
|
628
|
+
return a ? JSON.parse((_a = yield (n = (i = (t = this.dataStoreOptions) == null ? void 0 : t.decodeData) == null ? void 0 : i[1]) == null ? void 0 : n.call(i, a)) != null ? _a : a) : void 0;
|
|
629
|
+
} catch (e2) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
writeFile(e) {
|
|
635
|
+
return __async(this, null, function* () {
|
|
636
|
+
var _a;
|
|
637
|
+
var t, i, n, o;
|
|
638
|
+
this.ensureDataStoreOptions();
|
|
639
|
+
try {
|
|
640
|
+
if (f || (f = (t = yield import("fs/promises")) == null ? void 0 : t.default), !f) throw new g("FileStorageEngine requires Node.js or Deno with Node compatibility (v1.31+)", { cause: new d("'node:fs/promises' module not available") });
|
|
641
|
+
let a = typeof this.options.filePath == "string" ? this.options.filePath : this.options.filePath(this.dataStoreOptions.id);
|
|
642
|
+
yield f.mkdir(a.slice(0, a.lastIndexOf(a.includes("/") ? "/" : "\\")), { recursive: true }), yield f.writeFile(a, (_a = yield (o = (n = (i = this.dataStoreOptions) == null ? void 0 : i.encodeData) == null ? void 0 : n[1]) == null ? void 0 : o.call(n, JSON.stringify(e))) != null ? _a : JSON.stringify(e, void 0, 2), "utf-8");
|
|
643
|
+
} catch (a) {
|
|
644
|
+
console.error("Error writing file:", a);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
getValue(e, t) {
|
|
649
|
+
return __async(this, null, function* () {
|
|
650
|
+
let i = yield this.readFile();
|
|
651
|
+
if (!i) return t;
|
|
652
|
+
let n = i == null ? void 0 : i[e];
|
|
653
|
+
return typeof n > "u" ? t : n;
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
setValue(e, t) {
|
|
657
|
+
return __async(this, null, function* () {
|
|
658
|
+
this.fileAccessQueue = this.fileAccessQueue.then(() => __async(this, null, function* () {
|
|
659
|
+
let i = yield this.readFile();
|
|
660
|
+
i || (i = {}), i[e] = t, yield this.writeFile(i);
|
|
661
|
+
})).catch((i) => {
|
|
662
|
+
throw console.error("Error in setValue:", i), i;
|
|
663
|
+
}), yield this.fileAccessQueue.catch(() => {
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
deleteValue(e) {
|
|
668
|
+
return __async(this, null, function* () {
|
|
669
|
+
this.fileAccessQueue = this.fileAccessQueue.then(() => __async(this, null, function* () {
|
|
670
|
+
let t = yield this.readFile();
|
|
671
|
+
t && (delete t[e], yield this.writeFile(t));
|
|
672
|
+
})).catch((t) => {
|
|
673
|
+
throw console.error("Error in deleteValue:", t), t;
|
|
674
|
+
}), yield this.fileAccessQueue.catch(() => {
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
deleteStorage() {
|
|
679
|
+
return __async(this, null, function* () {
|
|
680
|
+
var e;
|
|
681
|
+
this.ensureDataStoreOptions();
|
|
682
|
+
try {
|
|
683
|
+
if (f || (f = (e = yield import("fs/promises")) == null ? void 0 : e.default), !f) throw new g("FileStorageEngine requires Node.js or Deno with Node compatibility (v1.31+)", { cause: new d("'node:fs/promises' module not available") });
|
|
684
|
+
let t = typeof this.options.filePath == "string" ? this.options.filePath : this.options.filePath(this.dataStoreOptions.id);
|
|
685
|
+
return yield f.unlink(t);
|
|
686
|
+
} catch (t) {
|
|
687
|
+
console.error("Error deleting file:", t);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var j = class r {
|
|
693
|
+
constructor(e, t = {}) {
|
|
694
|
+
__publicField(this, "stores");
|
|
695
|
+
__publicField(this, "options");
|
|
696
|
+
if (!crypto || !crypto.subtle) throw new g("DataStoreSerializer has to run in a secure context (HTTPS) or in another environment that implements the subtleCrypto API!");
|
|
697
|
+
this.stores = e, this.options = __spreadValues({ addChecksum: true, ensureIntegrity: true, remapIds: {} }, t);
|
|
698
|
+
}
|
|
699
|
+
calcChecksum(e) {
|
|
700
|
+
return __async(this, null, function* () {
|
|
701
|
+
return k(e, "SHA-256");
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
serializePartial(e, t = true, i = true) {
|
|
705
|
+
return __async(this, null, function* () {
|
|
706
|
+
var a;
|
|
707
|
+
let n = [], o = this.stores.filter((s) => typeof e == "function" ? e(s.id) : e.includes(s.id));
|
|
708
|
+
for (let s of o) {
|
|
709
|
+
let u = !!(t && s.encodingEnabled() && ((a = s.encodeData) != null && a[1])), l = s.memoryCache ? s.getData() : yield s.loadData(), c = u ? yield s.encodeData[1](JSON.stringify(l)) : JSON.stringify(l);
|
|
710
|
+
n.push({ id: s.id, data: c, formatVersion: s.formatVersion, encoded: u, checksum: this.options.addChecksum ? yield this.calcChecksum(c) : void 0 });
|
|
711
|
+
}
|
|
712
|
+
return i ? JSON.stringify(n) : n;
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
serialize(e = true, t = true) {
|
|
716
|
+
return __async(this, null, function* () {
|
|
717
|
+
return this.serializePartial(this.stores.map((i) => i.id), e, t);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
deserializePartial(e, t) {
|
|
721
|
+
return __async(this, null, function* () {
|
|
722
|
+
let i = typeof t == "string" ? JSON.parse(t) : t;
|
|
723
|
+
if (!Array.isArray(i) || !i.every(r.isSerializedDataStoreObj)) throw new TypeError("Invalid serialized data format! Expected an array of SerializedDataStore objects.");
|
|
724
|
+
let n = (a) => {
|
|
725
|
+
var _a;
|
|
726
|
+
var s;
|
|
727
|
+
return (_a = (s = Object.entries(this.options.remapIds).find(([, u]) => u.includes(a))) == null ? void 0 : s[0]) != null ? _a : a;
|
|
728
|
+
}, o = (a) => typeof e == "function" ? e(a) : e.includes(a);
|
|
729
|
+
for (let a of i) {
|
|
730
|
+
let s = n(a.id);
|
|
731
|
+
if (!o(s)) continue;
|
|
732
|
+
let u = this.stores.find((c) => c.id === s);
|
|
733
|
+
if (!u) throw new d(`Can't deserialize data because no DataStore instance with the ID "${s}" was found! Make sure to provide it in the DataStoreSerializer constructor.`);
|
|
734
|
+
if (this.options.ensureIntegrity && typeof a.checksum == "string") {
|
|
735
|
+
let c = yield this.calcChecksum(a.data);
|
|
736
|
+
if (c !== a.checksum) throw new S(`Checksum mismatch for DataStore with ID "${a.id}"!
|
|
737
|
+
Expected: ${a.checksum}
|
|
738
|
+
Has: ${c}`);
|
|
739
|
+
}
|
|
740
|
+
let l = a.encoded && u.encodingEnabled() ? yield u.decodeData[1](a.data) : a.data;
|
|
741
|
+
a.formatVersion && !isNaN(Number(a.formatVersion)) && Number(a.formatVersion) < u.formatVersion ? yield u.runMigrations(JSON.parse(l), Number(a.formatVersion), false) : yield u.setData(JSON.parse(l));
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
deserialize(e) {
|
|
746
|
+
return __async(this, null, function* () {
|
|
747
|
+
return this.deserializePartial(this.stores.map((t) => t.id), e);
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
loadStoresData(e) {
|
|
751
|
+
return __async(this, null, function* () {
|
|
752
|
+
return Promise.allSettled(this.getStoresFiltered(e).map((t) => __async(this, null, function* () {
|
|
753
|
+
return { id: t.id, data: yield t.loadData() };
|
|
754
|
+
})));
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
resetStoresData(e) {
|
|
758
|
+
return __async(this, null, function* () {
|
|
759
|
+
return Promise.allSettled(this.getStoresFiltered(e).map((t) => t.saveDefaultData()));
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
deleteStoresData(e) {
|
|
763
|
+
return __async(this, null, function* () {
|
|
764
|
+
return Promise.allSettled(this.getStoresFiltered(e).map((t) => t.deleteData()));
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
static isSerializedDataStoreObjArray(e) {
|
|
768
|
+
return Array.isArray(e) && e.every((t) => typeof t == "object" && t !== null && "id" in t && "data" in t && "formatVersion" in t && "encoded" in t);
|
|
769
|
+
}
|
|
770
|
+
static isSerializedDataStoreObj(e) {
|
|
771
|
+
return typeof e == "object" && e !== null && "id" in e && "data" in e && "formatVersion" in e && "encoded" in e;
|
|
772
|
+
}
|
|
773
|
+
getStoresFiltered(e) {
|
|
774
|
+
return this.stores.filter((t) => typeof e > "u" ? true : Array.isArray(e) ? e.includes(t.id) : e(t.id));
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
var Z = () => ({ emit(r, ...e) {
|
|
778
|
+
for (let t = this.events[r] || [], i = 0, n = t.length; i < n; i++) t[i](...e);
|
|
779
|
+
}, events: {}, on(r, e) {
|
|
780
|
+
var _a;
|
|
781
|
+
return ((_a = this.events)[r] || (_a[r] = [])).push(e), () => {
|
|
782
|
+
var t;
|
|
783
|
+
this.events[r] = (t = this.events[r]) == null ? void 0 : t.filter((i) => e !== i);
|
|
784
|
+
};
|
|
785
|
+
} });
|
|
786
|
+
var P = class {
|
|
787
|
+
constructor(e = {}) {
|
|
788
|
+
__publicField(this, "events", Z());
|
|
789
|
+
__publicField(this, "eventUnsubscribes", []);
|
|
790
|
+
__publicField(this, "emitterOptions");
|
|
791
|
+
this.emitterOptions = __spreadValues({ publicEmit: false }, e);
|
|
792
|
+
}
|
|
793
|
+
on(e, t) {
|
|
794
|
+
let i, n = () => {
|
|
795
|
+
i && (i(), this.eventUnsubscribes = this.eventUnsubscribes.filter((o) => o !== i));
|
|
796
|
+
};
|
|
797
|
+
return i = this.events.on(e, t), this.eventUnsubscribes.push(i), n;
|
|
798
|
+
}
|
|
799
|
+
once(e, t) {
|
|
800
|
+
return new Promise((i) => {
|
|
801
|
+
let n, o = ((...a) => {
|
|
802
|
+
t == null || t(...a), n == null || n(), i(a);
|
|
803
|
+
});
|
|
804
|
+
n = this.events.on(e, o), this.eventUnsubscribes.push(n);
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
onMulti(e) {
|
|
808
|
+
let t = [], i = () => {
|
|
809
|
+
for (let n of t) n();
|
|
810
|
+
t.splice(0, t.length), this.eventUnsubscribes = this.eventUnsubscribes.filter((n) => !t.includes(n));
|
|
811
|
+
};
|
|
812
|
+
for (let n of Array.isArray(e) ? e : [e]) {
|
|
813
|
+
let o = __spreadValues({ allOf: [], oneOf: [], once: false }, n), { oneOf: a, allOf: s, once: u, signal: l, callback: c } = o;
|
|
814
|
+
if (l != null && l.aborted) return i;
|
|
815
|
+
if (a.length === 0 && s.length === 0) throw new TypeError("NanoEmitter.onMulti(): Either `oneOf` or `allOf` or both must be provided in the options");
|
|
816
|
+
let p = [], m = (h = false) => {
|
|
817
|
+
if (!(!(l != null && l.aborted) && !h)) {
|
|
818
|
+
for (let y of p) y();
|
|
819
|
+
p.splice(0, p.length), this.eventUnsubscribes = this.eventUnsubscribes.filter((y) => !p.includes(y));
|
|
820
|
+
}
|
|
821
|
+
}, b = /* @__PURE__ */ new Set(), O = () => s.length === 0 || b.size === s.length;
|
|
822
|
+
for (let h of a) {
|
|
823
|
+
let y = this.events.on(h, ((...M) => {
|
|
824
|
+
m(), O() && (c(h, ...M), u && m(true));
|
|
825
|
+
}));
|
|
826
|
+
p.push(y);
|
|
827
|
+
}
|
|
828
|
+
for (let h of s) {
|
|
829
|
+
let y = this.events.on(h, ((...M) => {
|
|
830
|
+
m(), b.add(h), O() && (a.length === 0 || a.includes(h)) && (c(h, ...M), u && m(true));
|
|
831
|
+
}));
|
|
832
|
+
p.push(y);
|
|
833
|
+
}
|
|
834
|
+
t.push(() => m(true));
|
|
835
|
+
}
|
|
836
|
+
return i;
|
|
837
|
+
}
|
|
838
|
+
emit(e, ...t) {
|
|
839
|
+
return this.emitterOptions.publicEmit ? (this.events.emit(e, ...t), true) : false;
|
|
840
|
+
}
|
|
841
|
+
unsubscribeAll() {
|
|
842
|
+
for (let e of this.eventUnsubscribes) e();
|
|
843
|
+
this.eventUnsubscribes = [];
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
var A = class extends P {
|
|
847
|
+
constructor(t = 200, i = "immediate") {
|
|
848
|
+
super();
|
|
849
|
+
__publicField(this, "listeners", []);
|
|
850
|
+
__publicField(this, "activeTimeout");
|
|
851
|
+
__publicField(this, "queuedCall");
|
|
852
|
+
this.timeout = t;
|
|
853
|
+
this.type = i;
|
|
854
|
+
}
|
|
855
|
+
addListener(t) {
|
|
856
|
+
this.listeners.push(t);
|
|
857
|
+
}
|
|
858
|
+
removeListener(t) {
|
|
859
|
+
let i = this.listeners.findIndex((n) => n === t);
|
|
860
|
+
i !== -1 && this.listeners.splice(i, 1);
|
|
861
|
+
}
|
|
862
|
+
removeAllListeners() {
|
|
863
|
+
this.listeners = [];
|
|
864
|
+
}
|
|
865
|
+
getListeners() {
|
|
866
|
+
return this.listeners;
|
|
867
|
+
}
|
|
868
|
+
setTimeout(t) {
|
|
869
|
+
this.emit("change", this.timeout = t, this.type);
|
|
870
|
+
}
|
|
871
|
+
getTimeout() {
|
|
872
|
+
return this.timeout;
|
|
873
|
+
}
|
|
874
|
+
isTimeoutActive() {
|
|
875
|
+
return typeof this.activeTimeout < "u";
|
|
876
|
+
}
|
|
877
|
+
setType(t) {
|
|
878
|
+
this.emit("change", this.timeout, this.type = t);
|
|
879
|
+
}
|
|
880
|
+
getType() {
|
|
881
|
+
return this.type;
|
|
882
|
+
}
|
|
883
|
+
call(...t) {
|
|
884
|
+
let i = (...o) => {
|
|
885
|
+
this.queuedCall = void 0, this.emit("call", ...o), this.listeners.forEach((a) => a.call(this, ...o));
|
|
886
|
+
}, n = () => {
|
|
887
|
+
this.activeTimeout = setTimeout(() => {
|
|
888
|
+
this.queuedCall ? (this.queuedCall(), n()) : this.activeTimeout = void 0;
|
|
889
|
+
}, this.timeout);
|
|
890
|
+
};
|
|
891
|
+
switch (this.type) {
|
|
892
|
+
case "immediate":
|
|
893
|
+
typeof this.activeTimeout > "u" ? (i(...t), n()) : this.queuedCall = () => i(...t);
|
|
894
|
+
break;
|
|
895
|
+
case "idle":
|
|
896
|
+
this.activeTimeout && clearTimeout(this.activeTimeout), this.activeTimeout = setTimeout(() => {
|
|
897
|
+
i(...t), this.activeTimeout = void 0;
|
|
898
|
+
}, this.timeout);
|
|
899
|
+
break;
|
|
900
|
+
default:
|
|
901
|
+
throw new TypeError(`Invalid debouncer type: ${this.type}`);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
function Ie(r, e = 200, t = "immediate") {
|
|
906
|
+
let i = new A(e, t);
|
|
907
|
+
i.addListener(r);
|
|
908
|
+
let n = ((...o) => i.call(...o));
|
|
909
|
+
return n.debouncer = i, n;
|
|
910
|
+
}
|
|
911
|
+
if (typeof module2.exports == "object" && typeof exports2 == "object") {
|
|
912
|
+
var __cp = (to, from, except, desc) => {
|
|
913
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
914
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
915
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
916
|
+
Object.defineProperty(to, key, {
|
|
917
|
+
get: () => from[key],
|
|
918
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return to;
|
|
923
|
+
};
|
|
924
|
+
module2.exports = __cp(module2.exports, exports2);
|
|
925
|
+
}
|
|
926
|
+
return module2.exports;
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
// lib/Errors.ts
|
|
930
|
+
var PlatformError = class extends (void 0) {
|
|
931
|
+
constructor(message, options) {
|
|
932
|
+
super(message, options);
|
|
933
|
+
this.name = "PlatformError";
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
// lib/dom.ts
|
|
938
|
+
function getUnsafeWindow() {
|
|
939
|
+
try {
|
|
940
|
+
return unsafeWindow;
|
|
941
|
+
} catch (e) {
|
|
942
|
+
return window;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
function addParent(element, newParent) {
|
|
946
|
+
const oldParent = element.parentNode;
|
|
947
|
+
if (!oldParent)
|
|
948
|
+
throw new Error("Element doesn't have a parent node");
|
|
949
|
+
oldParent.replaceChild(newParent, element);
|
|
950
|
+
newParent.appendChild(element);
|
|
951
|
+
return newParent;
|
|
952
|
+
}
|
|
953
|
+
function addGlobalStyle(style) {
|
|
954
|
+
const styleElem = document.createElement("style");
|
|
955
|
+
setInnerHtmlUnsafe(styleElem, style);
|
|
956
|
+
document.head.appendChild(styleElem);
|
|
957
|
+
return styleElem;
|
|
958
|
+
}
|
|
959
|
+
function preloadImages(srcUrls, rejects = false) {
|
|
960
|
+
const promises = srcUrls.map((src) => new Promise((res, rej) => {
|
|
961
|
+
const image = new Image();
|
|
962
|
+
image.addEventListener("load", () => res(image), { once: true });
|
|
963
|
+
image.addEventListener("error", (evt) => rejects ? rej(evt) : res(image), { once: true });
|
|
964
|
+
image.src = src;
|
|
965
|
+
}));
|
|
966
|
+
return Promise.allSettled(promises);
|
|
967
|
+
}
|
|
968
|
+
function openInNewTab(href, background, additionalProps) {
|
|
969
|
+
try {
|
|
970
|
+
if (typeof window.GM === "object")
|
|
971
|
+
GM.openInTab(href, background);
|
|
972
|
+
} catch (e) {
|
|
973
|
+
const openElem = document.createElement("a");
|
|
974
|
+
Object.assign(openElem, __spreadValues({
|
|
975
|
+
className: "userutils-open-in-new-tab",
|
|
976
|
+
target: "_blank",
|
|
977
|
+
rel: "noopener noreferrer",
|
|
978
|
+
tabIndex: -1,
|
|
979
|
+
ariaHidden: "true",
|
|
980
|
+
href
|
|
981
|
+
}, additionalProps));
|
|
982
|
+
Object.assign(openElem.style, {
|
|
983
|
+
display: "none",
|
|
984
|
+
pointerEvents: "none"
|
|
985
|
+
});
|
|
986
|
+
document.body.appendChild(openElem);
|
|
987
|
+
openElem.click();
|
|
988
|
+
setTimeout(() => {
|
|
989
|
+
try {
|
|
990
|
+
openElem.remove();
|
|
991
|
+
} catch (e2) {
|
|
992
|
+
}
|
|
993
|
+
}, 0);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
function interceptEvent(eventObject, eventName, predicate = () => true) {
|
|
997
|
+
var _a;
|
|
998
|
+
if (typeof window.GM === "object" && ((_a = GM == null ? void 0 : GM.info) == null ? void 0 : _a.scriptHandler) && GM.info.scriptHandler === "FireMonkey" && (eventObject === window || eventObject === getUnsafeWindow()))
|
|
999
|
+
throw new PlatformError("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript is forced to run in.");
|
|
1000
|
+
if ("stackTraceLimit" in Error) {
|
|
1001
|
+
Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
1002
|
+
if (isNaN(Error.stackTraceLimit))
|
|
1003
|
+
Error.stackTraceLimit = 100;
|
|
1004
|
+
}
|
|
1005
|
+
(function(original) {
|
|
1006
|
+
eventObject.__proto__.addEventListener = function(...args) {
|
|
1007
|
+
var _a2, _b;
|
|
1008
|
+
const origListener = typeof args[1] === "function" ? args[1] : (_b = (_a2 = args[1]) == null ? void 0 : _a2.handleEvent) != null ? _b : (() => void 0);
|
|
1009
|
+
args[1] = function(...a) {
|
|
1010
|
+
if (args[0] === eventName && predicate(Array.isArray(a) ? a[0] : a))
|
|
1011
|
+
return;
|
|
1012
|
+
else
|
|
1013
|
+
return origListener.apply(this, a);
|
|
1014
|
+
};
|
|
1015
|
+
original.apply(this, args);
|
|
1016
|
+
};
|
|
1017
|
+
})(eventObject.__proto__.addEventListener);
|
|
1018
|
+
}
|
|
1019
|
+
function interceptWindowEvent(eventName, predicate = () => true) {
|
|
1020
|
+
return interceptEvent(getUnsafeWindow(), eventName, predicate);
|
|
1021
|
+
}
|
|
1022
|
+
function isScrollable(element) {
|
|
1023
|
+
const { overflowX, overflowY } = getComputedStyle(element);
|
|
1024
|
+
return {
|
|
1025
|
+
vertical: (overflowY === "scroll" || overflowY === "auto") && element.scrollHeight > element.clientHeight,
|
|
1026
|
+
horizontal: (overflowX === "scroll" || overflowX === "auto") && element.scrollWidth > element.clientWidth
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
function observeElementProp(element, property, callback) {
|
|
1030
|
+
const elementPrototype = Object.getPrototypeOf(element);
|
|
1031
|
+
if (elementPrototype.hasOwnProperty(property)) {
|
|
1032
|
+
const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property);
|
|
1033
|
+
Object.defineProperty(element, property, {
|
|
1034
|
+
get: function() {
|
|
1035
|
+
var _a;
|
|
1036
|
+
return (_a = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _a.apply(this, arguments);
|
|
1037
|
+
},
|
|
1038
|
+
set: function() {
|
|
1039
|
+
var _a;
|
|
1040
|
+
const oldValue = this[property];
|
|
1041
|
+
(_a = descriptor == null ? void 0 : descriptor.set) == null ? void 0 : _a.apply(this, arguments);
|
|
1042
|
+
const newValue = this[property];
|
|
1043
|
+
if (typeof callback === "function")
|
|
1044
|
+
callback.bind(this, oldValue, newValue);
|
|
1045
|
+
return newValue;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
function getSiblingsFrame(refElement, siblingAmount, refElementAlignment = "center-top", includeRef = true) {
|
|
1051
|
+
var _a, _b;
|
|
1052
|
+
const siblings = [...(_b = (_a = refElement.parentNode) == null ? void 0 : _a.childNodes) != null ? _b : []];
|
|
1053
|
+
const elemSiblIdx = siblings.indexOf(refElement);
|
|
1054
|
+
if (elemSiblIdx === -1)
|
|
1055
|
+
throw new Error("Element doesn't have a parent node");
|
|
1056
|
+
if (refElementAlignment === "top")
|
|
1057
|
+
return [...siblings.slice(elemSiblIdx + Number(!includeRef), elemSiblIdx + siblingAmount + Number(!includeRef))];
|
|
1058
|
+
else if (refElementAlignment.startsWith("center-")) {
|
|
1059
|
+
const halfAmount = (refElementAlignment === "center-bottom" ? Math.ceil : Math.floor)(siblingAmount / 2);
|
|
1060
|
+
const startIdx = Math.max(0, elemSiblIdx - halfAmount);
|
|
1061
|
+
const topOffset = Number(refElementAlignment === "center-top" && siblingAmount % 2 === 0 && includeRef);
|
|
1062
|
+
const btmOffset = Number(refElementAlignment === "center-bottom" && siblingAmount % 2 !== 0 && includeRef);
|
|
1063
|
+
const startIdxWithOffset = startIdx + topOffset + btmOffset;
|
|
1064
|
+
return [
|
|
1065
|
+
...siblings.filter((_, idx) => includeRef || idx !== elemSiblIdx).slice(startIdxWithOffset, startIdxWithOffset + siblingAmount)
|
|
1066
|
+
];
|
|
1067
|
+
} else if (refElementAlignment === "bottom")
|
|
1068
|
+
return [...siblings.slice(elemSiblIdx - siblingAmount + Number(includeRef), elemSiblIdx + Number(includeRef))];
|
|
1069
|
+
return [];
|
|
1070
|
+
}
|
|
1071
|
+
var ttPolicy;
|
|
1072
|
+
function setInnerHtmlUnsafe(element, html) {
|
|
1073
|
+
var _a, _b, _c;
|
|
1074
|
+
if (!ttPolicy && typeof ((_a = window == null ? void 0 : window.trustedTypes) == null ? void 0 : _a.createPolicy) === "function") {
|
|
1075
|
+
ttPolicy = window.trustedTypes.createPolicy("_uu_set_innerhtml_unsafe", {
|
|
1076
|
+
createHTML: (unsafeHtml) => unsafeHtml
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
element.innerHTML = (_c = (_b = ttPolicy == null ? void 0 : ttPolicy.createHTML) == null ? void 0 : _b.call(ttPolicy, html)) != null ? _c : html;
|
|
1080
|
+
return element;
|
|
1081
|
+
}
|
|
1082
|
+
function probeElementStyle(probeStyle, element, hideOffscreen = true, parentElement = document.body) {
|
|
1083
|
+
const el = element ? typeof element === "function" ? element() : element : document.createElement("span");
|
|
1084
|
+
if (hideOffscreen) {
|
|
1085
|
+
el.style.position = "absolute";
|
|
1086
|
+
el.style.left = "-9999px";
|
|
1087
|
+
el.style.top = "-9999px";
|
|
1088
|
+
el.style.zIndex = "-9999";
|
|
1089
|
+
}
|
|
1090
|
+
el.classList.add("_uu_probe_element");
|
|
1091
|
+
parentElement.appendChild(el);
|
|
1092
|
+
const style = window.getComputedStyle(el);
|
|
1093
|
+
const result = probeStyle(style, el);
|
|
1094
|
+
setTimeout(() => el.remove(), 1);
|
|
1095
|
+
return result;
|
|
1096
|
+
}
|
|
1097
|
+
var domReady = document.readyState !== "loading";
|
|
1098
|
+
!domReady && document.addEventListener("DOMContentLoaded", () => domReady = true, { once: true });
|
|
1099
|
+
function isDomLoaded() {
|
|
1100
|
+
return domReady;
|
|
1101
|
+
}
|
|
1102
|
+
function onDomLoad(cb) {
|
|
1103
|
+
return new Promise((res) => {
|
|
1104
|
+
if (domReady) {
|
|
1105
|
+
cb == null ? void 0 : cb();
|
|
1106
|
+
res();
|
|
1107
|
+
} else
|
|
1108
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
1109
|
+
cb == null ? void 0 : cb();
|
|
1110
|
+
res();
|
|
1111
|
+
}, { once: true });
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// lib/Dialog.ts
|
|
1116
|
+
var defaultDialogCss = `.uu-no-select {
|
|
1117
|
+
user-select: none;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
.uu-dialog-bg {
|
|
1121
|
+
--uu-dialog-bg: #333333;
|
|
1122
|
+
--uu-dialog-bg-highlight: #252525;
|
|
1123
|
+
--uu-scroll-indicator-bg: rgba(10, 10, 10, 0.7);
|
|
1124
|
+
--uu-dialog-separator-color: #797979;
|
|
1125
|
+
--uu-dialog-border-radius: 10px;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
.uu-dialog-bg {
|
|
1129
|
+
display: block;
|
|
1130
|
+
position: fixed;
|
|
1131
|
+
width: 100%;
|
|
1132
|
+
height: 100%;
|
|
1133
|
+
top: 0;
|
|
1134
|
+
left: 0;
|
|
1135
|
+
z-index: 5;
|
|
1136
|
+
background-color: rgba(0, 0, 0, 0.6);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
.uu-dialog {
|
|
1140
|
+
--uu-calc-dialog-height: calc(min(100vh - 40px, var(--uu-dialog-height-max)));
|
|
1141
|
+
position: absolute;
|
|
1142
|
+
display: flex;
|
|
1143
|
+
flex-direction: column;
|
|
1144
|
+
width: calc(min(100% - 60px, var(--uu-dialog-width-max)));
|
|
1145
|
+
border-radius: var(--uu-dialog-border-radius);
|
|
1146
|
+
height: auto;
|
|
1147
|
+
max-height: var(--uu-calc-dialog-height);
|
|
1148
|
+
left: 50%;
|
|
1149
|
+
top: 50%;
|
|
1150
|
+
transform: translate(-50%, -50%);
|
|
1151
|
+
z-index: 6;
|
|
1152
|
+
color: #fff;
|
|
1153
|
+
background-color: var(--uu-dialog-bg);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
.uu-dialog.align-top {
|
|
1157
|
+
top: 0;
|
|
1158
|
+
transform: translate(-50%, 40px);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
.uu-dialog.align-bottom {
|
|
1162
|
+
top: 100%;
|
|
1163
|
+
transform: translate(-50%, -100%);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
.uu-dialog-body {
|
|
1167
|
+
font-size: 1.5rem;
|
|
1168
|
+
padding: 20px;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
.uu-dialog-body.small {
|
|
1172
|
+
padding: 15px;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
#uu-dialog-opts {
|
|
1176
|
+
display: flex;
|
|
1177
|
+
flex-direction: column;
|
|
1178
|
+
position: relative;
|
|
1179
|
+
padding: 30px 0px;
|
|
1180
|
+
overflow-y: auto;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
.uu-dialog-header {
|
|
1184
|
+
display: flex;
|
|
1185
|
+
justify-content: space-between;
|
|
1186
|
+
align-items: center;
|
|
1187
|
+
margin-bottom: 6px;
|
|
1188
|
+
padding: 15px 20px 15px 20px;
|
|
1189
|
+
background-color: var(--uu-dialog-bg);
|
|
1190
|
+
border: 2px solid var(--uu-dialog-separator-color);
|
|
1191
|
+
border-style: none none solid none !important;
|
|
1192
|
+
border-radius: var(--uu-dialog-border-radius) var(--uu-dialog-border-radius) 0px 0px;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
.uu-dialog-header.small {
|
|
1196
|
+
padding: 10px 15px;
|
|
1197
|
+
border-style: none none solid none !important;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
.uu-dialog-header-pad {
|
|
1201
|
+
content: " ";
|
|
1202
|
+
min-height: 32px;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
.uu-dialog-header-pad.small {
|
|
1206
|
+
min-height: 24px;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
.uu-dialog-titlecont {
|
|
1210
|
+
display: flex;
|
|
1211
|
+
align-items: center;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
.uu-dialog-titlecont-no-title {
|
|
1215
|
+
display: flex;
|
|
1216
|
+
justify-content: flex-end;
|
|
1217
|
+
align-items: center;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
.uu-dialog-title {
|
|
1221
|
+
position: relative;
|
|
1222
|
+
display: inline-block;
|
|
1223
|
+
font-size: 22px;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
.uu-dialog-close {
|
|
1227
|
+
cursor: pointer;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
.uu-dialog-header-img,
|
|
1231
|
+
.uu-dialog-close
|
|
1232
|
+
{
|
|
1233
|
+
width: 32px;
|
|
1234
|
+
height: 32px;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
.uu-dialog-header-img.small,
|
|
1238
|
+
.uu-dialog-close.small
|
|
1239
|
+
{
|
|
1240
|
+
width: 24px;
|
|
1241
|
+
height: 24px;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
.uu-dialog-footer {
|
|
1245
|
+
font-size: 17px;
|
|
1246
|
+
text-decoration: underline;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
.uu-dialog-footer.hidden {
|
|
1250
|
+
display: none;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
.uu-dialog-footer-cont {
|
|
1254
|
+
margin-top: 6px;
|
|
1255
|
+
padding: 15px 20px;
|
|
1256
|
+
background: var(--uu-dialog-bg);
|
|
1257
|
+
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, var(--uu-dialog-bg) 30%, var(--uu-dialog-bg) 100%);
|
|
1258
|
+
border: 2px solid var(--uu-dialog-separator-color);
|
|
1259
|
+
border-style: solid none none none !important;
|
|
1260
|
+
border-radius: 0px 0px var(--uu-dialog-border-radius) var(--uu-dialog-border-radius);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
.uu-dialog-footer-buttons-cont button:not(:last-of-type) {
|
|
1264
|
+
margin-right: 15px;
|
|
1265
|
+
}`;
|
|
1266
|
+
var currentDialogId = null;
|
|
1267
|
+
var openDialogs = [];
|
|
1268
|
+
var defaultStrings = {
|
|
1269
|
+
closeDialogTooltip: "Click to close the dialog"
|
|
1270
|
+
};
|
|
1271
|
+
var Dialog = class _Dialog extends (void 0) {
|
|
1272
|
+
constructor(options) {
|
|
1273
|
+
super();
|
|
1274
|
+
/** Options passed to the dialog in the constructor */
|
|
1275
|
+
__publicField(this, "options");
|
|
1276
|
+
/** ID that gets added to child element IDs - has to be unique and conform to HTML ID naming rules! */
|
|
1277
|
+
__publicField(this, "id");
|
|
1278
|
+
/** Strings used in the dialog (used for translations) */
|
|
1279
|
+
__publicField(this, "strings");
|
|
1280
|
+
__publicField(this, "dialogOpen", false);
|
|
1281
|
+
__publicField(this, "dialogMounted", false);
|
|
1282
|
+
const _a = options, { strings } = _a, opts = __objRest(_a, ["strings"]);
|
|
1283
|
+
this.strings = __spreadValues(__spreadValues({}, defaultStrings), strings != null ? strings : {});
|
|
1284
|
+
this.options = __spreadValues({
|
|
1285
|
+
closeOnBgClick: true,
|
|
1286
|
+
closeOnEscPress: true,
|
|
1287
|
+
destroyOnClose: false,
|
|
1288
|
+
unmountOnClose: true,
|
|
1289
|
+
removeListenersOnDestroy: true,
|
|
1290
|
+
small: false,
|
|
1291
|
+
verticalAlign: "center"
|
|
1292
|
+
}, opts);
|
|
1293
|
+
this.id = opts.id;
|
|
1294
|
+
}
|
|
1295
|
+
//#region public
|
|
1296
|
+
/** Call after DOMContentLoaded to pre-render the dialog and invisibly mount it in the DOM */
|
|
1297
|
+
mount() {
|
|
1298
|
+
return __async(this, null, function* () {
|
|
1299
|
+
var _a;
|
|
1300
|
+
if (this.dialogMounted)
|
|
1301
|
+
return;
|
|
1302
|
+
this.dialogMounted = true;
|
|
1303
|
+
if (!document.querySelector("style.uu-dialog-css"))
|
|
1304
|
+
addGlobalStyle((_a = this.options.dialogCss) != null ? _a : defaultDialogCss).classList.add("uu-dialog-css");
|
|
1305
|
+
const bgElem = document.createElement("div");
|
|
1306
|
+
bgElem.id = `uu-${this.id}-dialog-bg`;
|
|
1307
|
+
bgElem.classList.add("uu-dialog-bg");
|
|
1308
|
+
if (this.options.closeOnBgClick)
|
|
1309
|
+
bgElem.ariaLabel = bgElem.title = this.getString("closeDialogTooltip");
|
|
1310
|
+
bgElem.style.setProperty("--uu-dialog-width-max", `${this.options.width}px`);
|
|
1311
|
+
bgElem.style.setProperty("--uu-dialog-height-max", `${this.options.height}px`);
|
|
1312
|
+
bgElem.style.visibility = "hidden";
|
|
1313
|
+
bgElem.style.display = "none";
|
|
1314
|
+
bgElem.inert = true;
|
|
1315
|
+
bgElem.appendChild(yield this.getDialogContent());
|
|
1316
|
+
document.body.appendChild(bgElem);
|
|
1317
|
+
this.attachListeners(bgElem);
|
|
1318
|
+
this.events.emit("render");
|
|
1319
|
+
return bgElem;
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
/** Closes the dialog and clears all its contents (unmounts elements from the DOM) in preparation for a new rendering call */
|
|
1323
|
+
unmount() {
|
|
1324
|
+
var _a;
|
|
1325
|
+
this.close();
|
|
1326
|
+
this.dialogMounted = false;
|
|
1327
|
+
const clearSelectors = [
|
|
1328
|
+
`#uu-${this.id}-dialog-bg`,
|
|
1329
|
+
`#uu-style-dialog-${this.id}`
|
|
1330
|
+
];
|
|
1331
|
+
for (const sel of clearSelectors)
|
|
1332
|
+
(_a = document.querySelector(sel)) == null ? void 0 : _a.remove();
|
|
1333
|
+
this.events.emit("clear");
|
|
1334
|
+
}
|
|
1335
|
+
/** Clears the DOM of the dialog and then renders it again */
|
|
1336
|
+
remount() {
|
|
1337
|
+
return __async(this, null, function* () {
|
|
1338
|
+
this.unmount();
|
|
1339
|
+
yield this.mount();
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Opens the dialog - also mounts it if it hasn't been mounted yet
|
|
1344
|
+
* Prevents default action and immediate propagation of the passed event
|
|
1345
|
+
*/
|
|
1346
|
+
open(e) {
|
|
1347
|
+
return __async(this, null, function* () {
|
|
1348
|
+
var _a;
|
|
1349
|
+
e == null ? void 0 : e.preventDefault();
|
|
1350
|
+
e == null ? void 0 : e.stopImmediatePropagation();
|
|
1351
|
+
if (this.isOpen())
|
|
1352
|
+
return;
|
|
1353
|
+
this.dialogOpen = true;
|
|
1354
|
+
if (openDialogs.includes(this.id))
|
|
1355
|
+
throw new Error(`A dialog with the same ID of '${this.id}' already exists and is open!`);
|
|
1356
|
+
if (!this.isMounted())
|
|
1357
|
+
yield this.mount();
|
|
1358
|
+
const dialogBg = document.querySelector(`#uu-${this.id}-dialog-bg`);
|
|
1359
|
+
if (!dialogBg)
|
|
1360
|
+
return console.warn(`Couldn't find background element for dialog with ID '${this.id}'`);
|
|
1361
|
+
dialogBg.style.visibility = "visible";
|
|
1362
|
+
dialogBg.style.display = "block";
|
|
1363
|
+
dialogBg.inert = false;
|
|
1364
|
+
currentDialogId = this.id;
|
|
1365
|
+
openDialogs.unshift(this.id);
|
|
1366
|
+
for (const dialogId of openDialogs)
|
|
1367
|
+
if (dialogId !== this.id)
|
|
1368
|
+
(_a = document.querySelector(`#uu-${dialogId}-dialog-bg`)) == null ? void 0 : _a.setAttribute("inert", "true");
|
|
1369
|
+
document.body.classList.remove("uu-no-select");
|
|
1370
|
+
document.body.setAttribute("inert", "true");
|
|
1371
|
+
this.events.emit("open");
|
|
1372
|
+
return dialogBg;
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
/** Closes the dialog - prevents default action and immediate propagation of the passed event */
|
|
1376
|
+
close(e) {
|
|
1377
|
+
var _a, _b;
|
|
1378
|
+
e == null ? void 0 : e.preventDefault();
|
|
1379
|
+
e == null ? void 0 : e.stopImmediatePropagation();
|
|
1380
|
+
if (!this.isOpen())
|
|
1381
|
+
return;
|
|
1382
|
+
this.dialogOpen = false;
|
|
1383
|
+
const dialogBg = document.querySelector(`#uu-${this.id}-dialog-bg`);
|
|
1384
|
+
if (!dialogBg)
|
|
1385
|
+
return console.warn(`Couldn't find background element for dialog with ID '${this.id}'`);
|
|
1386
|
+
dialogBg.style.visibility = "hidden";
|
|
1387
|
+
dialogBg.style.display = "none";
|
|
1388
|
+
dialogBg.inert = true;
|
|
1389
|
+
openDialogs.splice(openDialogs.indexOf(this.id), 1);
|
|
1390
|
+
currentDialogId = (_a = openDialogs[0]) != null ? _a : null;
|
|
1391
|
+
if (currentDialogId)
|
|
1392
|
+
(_b = document.querySelector(`#uu-${currentDialogId}-dialog-bg`)) == null ? void 0 : _b.removeAttribute("inert");
|
|
1393
|
+
if (openDialogs.length === 0) {
|
|
1394
|
+
document.body.classList.add("uu-no-select");
|
|
1395
|
+
document.body.removeAttribute("inert");
|
|
1396
|
+
}
|
|
1397
|
+
this.events.emit("close");
|
|
1398
|
+
if (this.options.destroyOnClose)
|
|
1399
|
+
this.destroy();
|
|
1400
|
+
else if (this.options.unmountOnClose)
|
|
1401
|
+
this.unmount();
|
|
1402
|
+
}
|
|
1403
|
+
/** Returns true if the dialog is currently open */
|
|
1404
|
+
isOpen() {
|
|
1405
|
+
return this.dialogOpen;
|
|
1406
|
+
}
|
|
1407
|
+
/** Returns true if the dialog is currently mounted */
|
|
1408
|
+
isMounted() {
|
|
1409
|
+
return this.dialogMounted;
|
|
1410
|
+
}
|
|
1411
|
+
/** Clears the DOM of the dialog and removes all event listeners */
|
|
1412
|
+
destroy() {
|
|
1413
|
+
this.unmount();
|
|
1414
|
+
this.events.emit("destroy");
|
|
1415
|
+
this.options.removeListenersOnDestroy && this.unsubscribeAll();
|
|
1416
|
+
}
|
|
1417
|
+
//#region static
|
|
1418
|
+
/** Returns the ID of the top-most dialog (the dialog that has been opened last) */
|
|
1419
|
+
static getCurrentDialogId() {
|
|
1420
|
+
return currentDialogId;
|
|
1421
|
+
}
|
|
1422
|
+
/** Returns the IDs of all currently open dialogs, top-most first */
|
|
1423
|
+
static getOpenDialogs() {
|
|
1424
|
+
return openDialogs;
|
|
1425
|
+
}
|
|
1426
|
+
//#region protected
|
|
1427
|
+
getString(key) {
|
|
1428
|
+
var _a;
|
|
1429
|
+
return (_a = this.strings[key]) != null ? _a : defaultStrings[key];
|
|
1430
|
+
}
|
|
1431
|
+
/** Called once to attach all generic event listeners */
|
|
1432
|
+
attachListeners(bgElem) {
|
|
1433
|
+
if (this.options.closeOnBgClick) {
|
|
1434
|
+
bgElem.addEventListener("click", (e) => {
|
|
1435
|
+
var _a;
|
|
1436
|
+
if (this.isOpen() && ((_a = e.target) == null ? void 0 : _a.id) === `uu-${this.id}-dialog-bg`)
|
|
1437
|
+
this.close(e);
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
if (this.options.closeOnEscPress) {
|
|
1441
|
+
document.body.addEventListener("keydown", (e) => {
|
|
1442
|
+
if (e.key === "Escape" && this.isOpen() && _Dialog.getCurrentDialogId() === this.id)
|
|
1443
|
+
this.close(e);
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
//#region protected
|
|
1448
|
+
/**
|
|
1449
|
+
* Adds generic, accessible interaction listeners to the passed element.
|
|
1450
|
+
* All listeners have the default behavior prevented and stop propagation (for keyboard events only as long as the captured key is valid).
|
|
1451
|
+
* @param listenerOptions Provide a {@linkcode listenerOptions} object to configure the listeners
|
|
1452
|
+
*/
|
|
1453
|
+
onInteraction(elem, listener, listenerOptions) {
|
|
1454
|
+
const _a = listenerOptions != null ? listenerOptions : {}, { preventDefault = true, stopPropagation = true } = _a, listenerOpts = __objRest(_a, ["preventDefault", "stopPropagation"]);
|
|
1455
|
+
const interactionKeys = ["Enter", " ", "Space"];
|
|
1456
|
+
const proxListener = (e) => {
|
|
1457
|
+
if (e instanceof KeyboardEvent) {
|
|
1458
|
+
if (interactionKeys.includes(e.key)) {
|
|
1459
|
+
preventDefault && e.preventDefault();
|
|
1460
|
+
stopPropagation && e.stopPropagation();
|
|
1461
|
+
} else return;
|
|
1462
|
+
} else if (e instanceof MouseEvent) {
|
|
1463
|
+
preventDefault && e.preventDefault();
|
|
1464
|
+
stopPropagation && e.stopPropagation();
|
|
1465
|
+
}
|
|
1466
|
+
(listenerOpts == null ? void 0 : listenerOpts.once) && e.type === "keydown" && elem.removeEventListener("click", proxListener, listenerOpts);
|
|
1467
|
+
(listenerOpts == null ? void 0 : listenerOpts.once) && e.type === "click" && elem.removeEventListener("keydown", proxListener, listenerOpts);
|
|
1468
|
+
listener(e);
|
|
1469
|
+
};
|
|
1470
|
+
elem.addEventListener("click", proxListener, listenerOpts);
|
|
1471
|
+
elem.addEventListener("keydown", proxListener, listenerOpts);
|
|
1472
|
+
}
|
|
1473
|
+
/** Returns the dialog content element and all its children */
|
|
1474
|
+
getDialogContent() {
|
|
1475
|
+
return __async(this, null, function* () {
|
|
1476
|
+
var _a, _b, _c, _d;
|
|
1477
|
+
const header = (_b = (_a = this.options).renderHeader) == null ? void 0 : _b.call(_a);
|
|
1478
|
+
const footer = (_d = (_c = this.options).renderFooter) == null ? void 0 : _d.call(_c);
|
|
1479
|
+
const dialogWrapperEl = document.createElement("div");
|
|
1480
|
+
dialogWrapperEl.id = `uu-${this.id}-dialog`;
|
|
1481
|
+
dialogWrapperEl.classList.add("uu-dialog");
|
|
1482
|
+
dialogWrapperEl.ariaLabel = dialogWrapperEl.title = "";
|
|
1483
|
+
dialogWrapperEl.role = "dialog";
|
|
1484
|
+
dialogWrapperEl.setAttribute("aria-labelledby", `uu-${this.id}-dialog-title`);
|
|
1485
|
+
dialogWrapperEl.setAttribute("aria-describedby", `uu-${this.id}-dialog-body`);
|
|
1486
|
+
if (this.options.verticalAlign !== "center")
|
|
1487
|
+
dialogWrapperEl.classList.add(`align-${this.options.verticalAlign}`);
|
|
1488
|
+
const headerWrapperEl = document.createElement("div");
|
|
1489
|
+
headerWrapperEl.classList.add("uu-dialog-header");
|
|
1490
|
+
this.options.small && headerWrapperEl.classList.add("small");
|
|
1491
|
+
if (header) {
|
|
1492
|
+
const headerTitleWrapperEl = document.createElement("div");
|
|
1493
|
+
headerTitleWrapperEl.id = `uu-${this.id}-dialog-title`;
|
|
1494
|
+
headerTitleWrapperEl.classList.add("uu-dialog-title-wrapper");
|
|
1495
|
+
headerTitleWrapperEl.role = "heading";
|
|
1496
|
+
headerTitleWrapperEl.ariaLevel = "1";
|
|
1497
|
+
headerTitleWrapperEl.appendChild(header instanceof Promise ? yield header : header);
|
|
1498
|
+
headerWrapperEl.appendChild(headerTitleWrapperEl);
|
|
1499
|
+
} else {
|
|
1500
|
+
const padEl = document.createElement("div");
|
|
1501
|
+
padEl.classList.add("uu-dialog-header-pad", this.options.small ? "small" : "");
|
|
1502
|
+
headerWrapperEl.appendChild(padEl);
|
|
1503
|
+
}
|
|
1504
|
+
if (this.options.renderCloseBtn) {
|
|
1505
|
+
const closeBtnEl = yield this.options.renderCloseBtn();
|
|
1506
|
+
closeBtnEl.classList.add("uu-dialog-close");
|
|
1507
|
+
this.options.small && closeBtnEl.classList.add("small");
|
|
1508
|
+
closeBtnEl.tabIndex = 0;
|
|
1509
|
+
if (closeBtnEl.hasAttribute("alt"))
|
|
1510
|
+
closeBtnEl.setAttribute("alt", this.getString("closeDialogTooltip"));
|
|
1511
|
+
closeBtnEl.title = closeBtnEl.ariaLabel = this.getString("closeDialogTooltip");
|
|
1512
|
+
this.onInteraction(closeBtnEl, () => this.close());
|
|
1513
|
+
headerWrapperEl.appendChild(closeBtnEl);
|
|
1514
|
+
}
|
|
1515
|
+
dialogWrapperEl.appendChild(headerWrapperEl);
|
|
1516
|
+
const dialogBodyElem = document.createElement("div");
|
|
1517
|
+
dialogBodyElem.id = `uu-${this.id}-dialog-body`;
|
|
1518
|
+
dialogBodyElem.classList.add("uu-dialog-body");
|
|
1519
|
+
this.options.small && dialogBodyElem.classList.add("small");
|
|
1520
|
+
const body = this.options.renderBody();
|
|
1521
|
+
dialogBodyElem.appendChild(body instanceof Promise ? yield body : body);
|
|
1522
|
+
dialogWrapperEl.appendChild(dialogBodyElem);
|
|
1523
|
+
if (footer) {
|
|
1524
|
+
const footerWrapper = document.createElement("div");
|
|
1525
|
+
footerWrapper.classList.add("uu-dialog-footer-cont");
|
|
1526
|
+
dialogWrapperEl.appendChild(footerWrapper);
|
|
1527
|
+
footerWrapper.appendChild(footer instanceof Promise ? yield footer : footer);
|
|
1528
|
+
}
|
|
1529
|
+
return dialogWrapperEl;
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1534
|
+
// lib/GMStorageEngine.ts
|
|
1535
|
+
var GMStorageEngine = class extends (void 0) {
|
|
1536
|
+
/**
|
|
1537
|
+
* Creates an instance of `GMStorageEngine`.
|
|
1538
|
+
*
|
|
1539
|
+
* - ⚠️ Requires the grants `GM.getValue`, `GM.setValue`, `GM.deleteValue`, and `GM.listValues` in your userscript metadata.
|
|
1540
|
+
* - ⚠️ Don't reuse engine instances, always create a new one for each {@linkcode DataStore} instance.
|
|
1541
|
+
*/
|
|
1542
|
+
constructor(options) {
|
|
1543
|
+
super(options == null ? void 0 : options.dataStoreOptions);
|
|
1544
|
+
__publicField(this, "options");
|
|
1545
|
+
this.options = __spreadValues({}, options);
|
|
1546
|
+
}
|
|
1547
|
+
/** Fetches a value from persistent storage */
|
|
1548
|
+
getValue(name, defaultValue) {
|
|
1549
|
+
return __async(this, null, function* () {
|
|
1550
|
+
try {
|
|
1551
|
+
if (!("GM" in globalThis))
|
|
1552
|
+
throw new PlatformError("GM is not defined. Make sure to run this in a userscript environment and that the necessary grants are set.");
|
|
1553
|
+
const value = yield globalThis.GM.getValue(name, defaultValue);
|
|
1554
|
+
return value === void 0 ? defaultValue : value;
|
|
1555
|
+
} catch (err) {
|
|
1556
|
+
console.error(`Error getting value for key "${name}":`, err);
|
|
1557
|
+
throw err;
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
/** Sets a value in persistent storage */
|
|
1562
|
+
setValue(name, value) {
|
|
1563
|
+
return __async(this, null, function* () {
|
|
1564
|
+
try {
|
|
1565
|
+
if (!("GM" in globalThis))
|
|
1566
|
+
throw new PlatformError("GM is not defined. Make sure to run this in a userscript environment and that the necessary grants are set.");
|
|
1567
|
+
yield globalThis.GM.setValue(name, value);
|
|
1568
|
+
} catch (err) {
|
|
1569
|
+
console.error(`Error setting value for key "${name}":`, err);
|
|
1570
|
+
throw err;
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
/** Deletes a value from persistent storage */
|
|
1575
|
+
deleteValue(name) {
|
|
1576
|
+
return __async(this, null, function* () {
|
|
1577
|
+
try {
|
|
1578
|
+
if (!("GM" in globalThis))
|
|
1579
|
+
throw new PlatformError("GM is not defined. Make sure to run this in a userscript environment and that the necessary grants are set.");
|
|
1580
|
+
yield globalThis.GM.deleteValue(name);
|
|
1581
|
+
} catch (err) {
|
|
1582
|
+
console.error(`Error deleting value for key "${name}":`, err);
|
|
1583
|
+
throw err;
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
/** Deletes all values from GM storage. Use with caution! */
|
|
1588
|
+
deleteStorage() {
|
|
1589
|
+
return __async(this, null, function* () {
|
|
1590
|
+
try {
|
|
1591
|
+
if (!("GM" in globalThis))
|
|
1592
|
+
throw new PlatformError("GM is not defined. Make sure to run this in a userscript environment and that the necessary grants are set.");
|
|
1593
|
+
const keys = yield globalThis.GM.listValues();
|
|
1594
|
+
for (const key of keys)
|
|
1595
|
+
yield globalThis.GM.deleteValue(key);
|
|
1596
|
+
} catch (err) {
|
|
1597
|
+
console.error("Error deleting storage:", err);
|
|
1598
|
+
throw err;
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1604
|
+
// lib/Mixins.ts
|
|
1605
|
+
var Mixins = class {
|
|
1606
|
+
/**
|
|
1607
|
+
* Creates a new Mixins instance.
|
|
1608
|
+
* @param config Configuration object to customize the behavior.
|
|
1609
|
+
*/
|
|
1610
|
+
constructor(config = {}) {
|
|
1611
|
+
/** List of all registered mixins */
|
|
1612
|
+
__publicField(this, "mixins", []);
|
|
1613
|
+
/** Default configuration object for mixins */
|
|
1614
|
+
__publicField(this, "defaultMixinCfg");
|
|
1615
|
+
/** Whether the priorities should auto-increment if not specified */
|
|
1616
|
+
__publicField(this, "autoIncPrioEnabled");
|
|
1617
|
+
/** The current auto-increment priority counter */
|
|
1618
|
+
__publicField(this, "autoIncPrioCounter", /* @__PURE__ */ new Map());
|
|
1619
|
+
var _a, _b, _c;
|
|
1620
|
+
this.defaultMixinCfg = (void 0)({
|
|
1621
|
+
priority: (_a = config.defaultPriority) != null ? _a : 0,
|
|
1622
|
+
stopPropagation: (_b = config.defaultStopPropagation) != null ? _b : false,
|
|
1623
|
+
signal: config.defaultSignal
|
|
1624
|
+
});
|
|
1625
|
+
this.autoIncPrioEnabled = (_c = config.autoIncrementPriority) != null ? _c : false;
|
|
1626
|
+
}
|
|
1627
|
+
//#region public
|
|
1628
|
+
/**
|
|
1629
|
+
* Adds a mixin function to the given {@linkcode mixinKey}.
|
|
1630
|
+
* If no priority is specified, it will be calculated via the protected method {@linkcode calcPriority()} based on the constructor configuration, or fall back to the default priority.
|
|
1631
|
+
* @param mixinKey The key to identify the mixin function.
|
|
1632
|
+
* @param mixinFn The function to be called to apply the mixin. The first argument is the input value, the second argument is the context object (if any).
|
|
1633
|
+
* @param config Configuration object to customize the mixin behavior, or just the priority if a number is passed.
|
|
1634
|
+
* @returns Returns a cleanup function, to be called when this mixin is no longer needed.
|
|
1635
|
+
*/
|
|
1636
|
+
add(mixinKey, mixinFn, config = (void 0)({})) {
|
|
1637
|
+
const calcPrio = typeof config === "number" ? config : this.calcPriority(mixinKey, config);
|
|
1638
|
+
const mixin = (void 0)(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, this.defaultMixinCfg), {
|
|
1639
|
+
key: mixinKey,
|
|
1640
|
+
fn: mixinFn
|
|
1641
|
+
}), typeof config === "object" ? config : {}), typeof calcPrio === "number" && !isNaN(calcPrio) ? { priority: calcPrio } : {}));
|
|
1642
|
+
this.mixins.push(mixin);
|
|
1643
|
+
const rem = () => {
|
|
1644
|
+
this.mixins = this.mixins.filter((m) => m !== mixin);
|
|
1645
|
+
};
|
|
1646
|
+
if (mixin.signal)
|
|
1647
|
+
mixin.signal.addEventListener("abort", rem, { once: true });
|
|
1648
|
+
return rem;
|
|
1649
|
+
}
|
|
1650
|
+
/** Returns a list of all added mixins with their keys and configuration objects, but not their functions */
|
|
1651
|
+
list() {
|
|
1652
|
+
return this.mixins.map((_a) => {
|
|
1653
|
+
var _b = _a, { fn: _f } = _b, rest = __objRest(_b, ["fn"]);
|
|
1654
|
+
return rest;
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Applies all mixins with the given key to the input value, respecting the priority and stopPropagation settings.
|
|
1659
|
+
* If additional context is set in the MixinMap, it will need to be passed as the third argument.
|
|
1660
|
+
* @returns The modified value after all mixins have been applied. The method will return a Promise if at least one of the mixins is async. If all mixins are indicated to be synchronous in TS, but at least one of them turns out to be asynchronous, the return type will be a Promise. With `await`, this will not make a difference, but `.then().catch()` could be affected.
|
|
1661
|
+
*/
|
|
1662
|
+
resolve(mixinKey, inputValue, ...inputCtx) {
|
|
1663
|
+
const mixins = this.mixins.filter((m) => m.key === mixinKey);
|
|
1664
|
+
const sortedMixins = [...mixins].sort((a, b) => b.priority - a.priority);
|
|
1665
|
+
let result = inputValue;
|
|
1666
|
+
for (let i = 0; i < sortedMixins.length; i++) {
|
|
1667
|
+
const mixin = sortedMixins[i];
|
|
1668
|
+
result = mixin.fn(result, ...inputCtx);
|
|
1669
|
+
if (result instanceof Promise) {
|
|
1670
|
+
return (() => __async(this, null, function* () {
|
|
1671
|
+
result = yield result;
|
|
1672
|
+
if (mixin.stopPropagation)
|
|
1673
|
+
return result;
|
|
1674
|
+
for (let j = i + 1; j < sortedMixins.length; j++) {
|
|
1675
|
+
const mixin2 = sortedMixins[j];
|
|
1676
|
+
result = yield mixin2.fn(result, ...inputCtx);
|
|
1677
|
+
if (mixin2.stopPropagation)
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
return result;
|
|
1681
|
+
}))();
|
|
1682
|
+
} else if (mixin.stopPropagation)
|
|
1683
|
+
break;
|
|
1684
|
+
}
|
|
1685
|
+
return result;
|
|
1686
|
+
}
|
|
1687
|
+
//#region protected
|
|
1688
|
+
/** Calculates the priority for a mixin based on the given configuration and the current auto-increment state of the instance */
|
|
1689
|
+
calcPriority(mixinKey, config) {
|
|
1690
|
+
var _a;
|
|
1691
|
+
if (config.priority !== void 0)
|
|
1692
|
+
return void 0;
|
|
1693
|
+
if (!this.autoIncPrioEnabled)
|
|
1694
|
+
return (_a = config.priority) != null ? _a : this.defaultMixinCfg.priority;
|
|
1695
|
+
if (!this.autoIncPrioCounter.has(mixinKey))
|
|
1696
|
+
this.autoIncPrioCounter.set(mixinKey, this.defaultMixinCfg.priority);
|
|
1697
|
+
let prio = this.autoIncPrioCounter.get(mixinKey);
|
|
1698
|
+
while (this.mixins.some((m) => m.key === mixinKey && m.priority === prio))
|
|
1699
|
+
prio++;
|
|
1700
|
+
this.autoIncPrioCounter.set(mixinKey, prio + 1);
|
|
1701
|
+
return prio;
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Removes all mixins with the given key.
|
|
1705
|
+
* Note: this method is protected to avoid third-party code from removing mixins. If needed, you can extend the Mixins class and expose this method publicly.
|
|
1706
|
+
*/
|
|
1707
|
+
removeAll(mixinKey) {
|
|
1708
|
+
this.mixins.filter((m) => m.key === mixinKey);
|
|
1709
|
+
this.mixins = this.mixins.filter((m) => m.key !== mixinKey);
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// lib/SelectorObserver.ts
|
|
1714
|
+
var SelectorObserver = class {
|
|
1715
|
+
constructor(baseElement, options = {}) {
|
|
1716
|
+
__publicField(this, "enabled", false);
|
|
1717
|
+
__publicField(this, "baseElement");
|
|
1718
|
+
__publicField(this, "observer");
|
|
1719
|
+
__publicField(this, "observerOptions");
|
|
1720
|
+
__publicField(this, "customOptions");
|
|
1721
|
+
__publicField(this, "listenerMap");
|
|
1722
|
+
this.baseElement = baseElement;
|
|
1723
|
+
this.listenerMap = /* @__PURE__ */ new Map();
|
|
1724
|
+
const _a = options, {
|
|
1725
|
+
defaultDebounce,
|
|
1726
|
+
defaultDebounceType,
|
|
1727
|
+
disableOnNoListeners,
|
|
1728
|
+
enableOnAddListener
|
|
1729
|
+
} = _a, observerOptions = __objRest(_a, [
|
|
1730
|
+
"defaultDebounce",
|
|
1731
|
+
"defaultDebounceType",
|
|
1732
|
+
"disableOnNoListeners",
|
|
1733
|
+
"enableOnAddListener"
|
|
1734
|
+
]);
|
|
1735
|
+
this.observerOptions = __spreadValues({
|
|
1736
|
+
childList: true,
|
|
1737
|
+
subtree: true
|
|
1738
|
+
}, observerOptions);
|
|
1739
|
+
this.customOptions = {
|
|
1740
|
+
defaultDebounce: defaultDebounce != null ? defaultDebounce : 0,
|
|
1741
|
+
defaultDebounceType: defaultDebounceType != null ? defaultDebounceType : "immediate",
|
|
1742
|
+
disableOnNoListeners: disableOnNoListeners != null ? disableOnNoListeners : false,
|
|
1743
|
+
enableOnAddListener: enableOnAddListener != null ? enableOnAddListener : true
|
|
1744
|
+
};
|
|
1745
|
+
if (typeof this.customOptions.checkInterval !== "number") {
|
|
1746
|
+
this.observer = new MutationObserver(() => this.checkAllSelectors());
|
|
1747
|
+
} else {
|
|
1748
|
+
this.checkAllSelectors();
|
|
1749
|
+
setInterval(() => this.checkAllSelectors(), this.customOptions.checkInterval);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
/** Call to check all selectors in the {@linkcode listenerMap} using {@linkcode checkSelector()} */
|
|
1753
|
+
checkAllSelectors() {
|
|
1754
|
+
if (!this.enabled || !isDomLoaded())
|
|
1755
|
+
return;
|
|
1756
|
+
for (const [selector, listeners] of this.listenerMap.entries())
|
|
1757
|
+
this.checkSelector(selector, listeners);
|
|
1758
|
+
}
|
|
1759
|
+
/** Checks if the element(s) with the given {@linkcode selector} exist in the DOM and calls the respective {@linkcode listeners} accordingly */
|
|
1760
|
+
checkSelector(selector, listeners) {
|
|
1761
|
+
var _a;
|
|
1762
|
+
if (!this.enabled)
|
|
1763
|
+
return;
|
|
1764
|
+
const baseElement = typeof this.baseElement === "string" ? document.querySelector(this.baseElement) : this.baseElement;
|
|
1765
|
+
if (!baseElement)
|
|
1766
|
+
return;
|
|
1767
|
+
const all = listeners.some((listener) => listener.all);
|
|
1768
|
+
const one = listeners.some((listener) => !listener.all);
|
|
1769
|
+
const allElements = all ? baseElement.querySelectorAll(selector) : null;
|
|
1770
|
+
const oneElement = one ? baseElement.querySelector(selector) : null;
|
|
1771
|
+
for (const options of listeners) {
|
|
1772
|
+
if (options.all) {
|
|
1773
|
+
if (allElements && allElements.length > 0) {
|
|
1774
|
+
options.listener(allElements);
|
|
1775
|
+
if (!options.continuous)
|
|
1776
|
+
this.removeListener(selector, options);
|
|
1777
|
+
}
|
|
1778
|
+
} else {
|
|
1779
|
+
if (oneElement) {
|
|
1780
|
+
options.listener(oneElement);
|
|
1781
|
+
if (!options.continuous)
|
|
1782
|
+
this.removeListener(selector, options);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
if (((_a = this.listenerMap.get(selector)) == null ? void 0 : _a.length) === 0)
|
|
1786
|
+
this.listenerMap.delete(selector);
|
|
1787
|
+
if (this.listenerMap.size === 0 && this.customOptions.disableOnNoListeners)
|
|
1788
|
+
this.disable();
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Starts observing the children of the base element for changes to the given {@linkcode selector} according to the set {@linkcode options}
|
|
1793
|
+
* @param selector The selector to observe
|
|
1794
|
+
* @param options Options for the selector observation
|
|
1795
|
+
* @param options.listener Gets called whenever the selector was found in the DOM
|
|
1796
|
+
* @param [options.all] Whether to use `querySelectorAll()` instead - default is false
|
|
1797
|
+
* @param [options.continuous] Whether to call the listener continuously instead of just once - default is false
|
|
1798
|
+
* @param [options.debounce] Whether to debounce the listener to reduce calls to `querySelector` or `querySelectorAll` - set undefined or <=0 to disable (default)
|
|
1799
|
+
* @returns Returns a function that can be called to remove this listener more easily
|
|
1800
|
+
*/
|
|
1801
|
+
addListener(selector, options) {
|
|
1802
|
+
options = __spreadValues({
|
|
1803
|
+
all: false,
|
|
1804
|
+
continuous: false,
|
|
1805
|
+
debounce: 0
|
|
1806
|
+
}, options);
|
|
1807
|
+
if (options.debounce && options.debounce > 0 || this.customOptions.defaultDebounce && this.customOptions.defaultDebounce > 0) {
|
|
1808
|
+
options.listener = (void 0)(
|
|
1809
|
+
options.listener,
|
|
1810
|
+
options.debounce || this.customOptions.defaultDebounce,
|
|
1811
|
+
options.debounceType || this.customOptions.defaultDebounceType
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
if (this.listenerMap.has(selector))
|
|
1815
|
+
this.listenerMap.get(selector).push(options);
|
|
1816
|
+
else
|
|
1817
|
+
this.listenerMap.set(selector, [options]);
|
|
1818
|
+
if (this.enabled === false && this.customOptions.enableOnAddListener)
|
|
1819
|
+
this.enable();
|
|
1820
|
+
this.checkSelector(selector, [options]);
|
|
1821
|
+
return () => this.removeListener(selector, options);
|
|
1822
|
+
}
|
|
1823
|
+
/** Disables the observation of the child elements */
|
|
1824
|
+
disable() {
|
|
1825
|
+
var _a;
|
|
1826
|
+
if (!this.enabled)
|
|
1827
|
+
return;
|
|
1828
|
+
this.enabled = false;
|
|
1829
|
+
(_a = this.observer) == null ? void 0 : _a.disconnect();
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Enables or reenables the observation of the child elements.
|
|
1833
|
+
* @param immediatelyCheckSelectors Whether to immediately check if all previously registered selectors exist (default is true)
|
|
1834
|
+
* @returns Returns true when the observation was enabled, false otherwise (e.g. when the base element wasn't found)
|
|
1835
|
+
*/
|
|
1836
|
+
enable(immediatelyCheckSelectors = true) {
|
|
1837
|
+
var _a;
|
|
1838
|
+
const baseElement = typeof this.baseElement === "string" ? document.querySelector(this.baseElement) : this.baseElement;
|
|
1839
|
+
if (this.enabled || !baseElement)
|
|
1840
|
+
return false;
|
|
1841
|
+
this.enabled = true;
|
|
1842
|
+
(_a = this.observer) == null ? void 0 : _a.observe(baseElement, this.observerOptions);
|
|
1843
|
+
if (immediatelyCheckSelectors)
|
|
1844
|
+
this.checkAllSelectors();
|
|
1845
|
+
return true;
|
|
1846
|
+
}
|
|
1847
|
+
/** Returns whether the observation of the child elements is currently enabled */
|
|
1848
|
+
isEnabled() {
|
|
1849
|
+
return this.enabled;
|
|
1850
|
+
}
|
|
1851
|
+
/** Removes all listeners that have been registered with {@linkcode addListener()} */
|
|
1852
|
+
clearListeners() {
|
|
1853
|
+
this.listenerMap.clear();
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Removes all listeners for the given {@linkcode selector} that have been registered with {@linkcode addListener()}
|
|
1857
|
+
* @returns Returns true when all listeners for the associated selector were found and removed, false otherwise
|
|
1858
|
+
*/
|
|
1859
|
+
removeAllListeners(selector) {
|
|
1860
|
+
return this.listenerMap.delete(selector);
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Removes a single listener for the given {@linkcode selector} and {@linkcode options} that has been registered with {@linkcode addListener()}
|
|
1864
|
+
* @returns Returns true when the listener was found and removed, false otherwise
|
|
1865
|
+
*/
|
|
1866
|
+
removeListener(selector, options) {
|
|
1867
|
+
const listeners = this.listenerMap.get(selector);
|
|
1868
|
+
if (!listeners)
|
|
1869
|
+
return false;
|
|
1870
|
+
const index = listeners.indexOf(options);
|
|
1871
|
+
if (index > -1) {
|
|
1872
|
+
listeners.splice(index, 1);
|
|
1873
|
+
return true;
|
|
1874
|
+
}
|
|
1875
|
+
return false;
|
|
1876
|
+
}
|
|
1877
|
+
/** Returns all listeners that have been registered with {@linkcode addListener()} */
|
|
1878
|
+
getAllListeners() {
|
|
1879
|
+
return this.listenerMap;
|
|
1880
|
+
}
|
|
1881
|
+
/** Returns all listeners for the given {@linkcode selector} that have been registered with {@linkcode addListener()} */
|
|
1882
|
+
getListeners(selector) {
|
|
1883
|
+
return this.listenerMap.get(selector);
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
|
|
1887
|
+
// lib/translation.ts
|
|
1888
|
+
var trans = {};
|
|
1889
|
+
var valTransforms = [];
|
|
1890
|
+
var fallbackLang;
|
|
1891
|
+
function translate(language, key, ...trArgs) {
|
|
1892
|
+
if (typeof language !== "string")
|
|
1893
|
+
language = fallbackLang != null ? fallbackLang : "";
|
|
1894
|
+
const trObj = trans[language];
|
|
1895
|
+
if (typeof language !== "string" || language.length === 0 || typeof trObj !== "object" || trObj === null)
|
|
1896
|
+
return fallbackLang && language !== fallbackLang ? translate(fallbackLang, key, ...trArgs) : key;
|
|
1897
|
+
const transformTrVal = (trKey, trValue) => {
|
|
1898
|
+
const tfs = valTransforms.filter(({ regex }) => new RegExp(regex).test(String(trValue)));
|
|
1899
|
+
if (tfs.length === 0)
|
|
1900
|
+
return String(trValue);
|
|
1901
|
+
let retStr = String(trValue);
|
|
1902
|
+
for (const tf of tfs) {
|
|
1903
|
+
const re = new RegExp(tf.regex);
|
|
1904
|
+
const matches = [];
|
|
1905
|
+
let execRes;
|
|
1906
|
+
while ((execRes = re.exec(trValue)) !== null) {
|
|
1907
|
+
if (matches.some((m) => m[0] === (execRes == null ? void 0 : execRes[0]) && m.index === (execRes == null ? void 0 : execRes.index)))
|
|
1908
|
+
break;
|
|
1909
|
+
matches.push(execRes);
|
|
1910
|
+
}
|
|
1911
|
+
retStr = String(tf.fn({
|
|
1912
|
+
language,
|
|
1913
|
+
trValue,
|
|
1914
|
+
currentValue: retStr,
|
|
1915
|
+
matches,
|
|
1916
|
+
trKey,
|
|
1917
|
+
trArgs
|
|
1918
|
+
}));
|
|
1919
|
+
}
|
|
1920
|
+
return retStr;
|
|
1921
|
+
};
|
|
1922
|
+
const keyParts = key.split(".");
|
|
1923
|
+
let value = trObj;
|
|
1924
|
+
for (const part of keyParts) {
|
|
1925
|
+
if (typeof value !== "object" || value === null) {
|
|
1926
|
+
value = void 0;
|
|
1927
|
+
break;
|
|
1928
|
+
}
|
|
1929
|
+
value = value == null ? void 0 : value[part];
|
|
1930
|
+
}
|
|
1931
|
+
if (typeof value === "string")
|
|
1932
|
+
return transformTrVal(key, value);
|
|
1933
|
+
value = trObj == null ? void 0 : trObj[key];
|
|
1934
|
+
if (typeof value === "string")
|
|
1935
|
+
return transformTrVal(key, value);
|
|
1936
|
+
return fallbackLang && language !== fallbackLang ? translate(fallbackLang, key, ...trArgs) : key;
|
|
1937
|
+
}
|
|
1938
|
+
function trFor(language, key, ...args) {
|
|
1939
|
+
const txt = translate(language, key, ...args);
|
|
1940
|
+
if (txt === key)
|
|
1941
|
+
return fallbackLang ? translate(fallbackLang, key, ...args) : key;
|
|
1942
|
+
return txt;
|
|
1943
|
+
}
|
|
1944
|
+
function useTr(language) {
|
|
1945
|
+
return (key, ...args) => translate(language, key, ...args);
|
|
1946
|
+
}
|
|
1947
|
+
function hasKey(language = fallbackLang != null ? fallbackLang : "", key) {
|
|
1948
|
+
return tr.for(language, key) !== key;
|
|
1949
|
+
}
|
|
1950
|
+
function addTranslations(language, translations) {
|
|
1951
|
+
trans[language] = JSON.parse(JSON.stringify(translations));
|
|
1952
|
+
}
|
|
1953
|
+
function getTranslations(language = fallbackLang != null ? fallbackLang : "") {
|
|
1954
|
+
return trans[language];
|
|
1955
|
+
}
|
|
1956
|
+
var deleteTranslations = (language) => {
|
|
1957
|
+
if (language in trans) {
|
|
1958
|
+
delete trans[language];
|
|
1959
|
+
return true;
|
|
1960
|
+
}
|
|
1961
|
+
return false;
|
|
1962
|
+
};
|
|
1963
|
+
function setFallbackLanguage(fallbackLanguage) {
|
|
1964
|
+
fallbackLang = fallbackLanguage;
|
|
1965
|
+
}
|
|
1966
|
+
function getFallbackLanguage() {
|
|
1967
|
+
return fallbackLang;
|
|
1968
|
+
}
|
|
1969
|
+
function addTransform(transform) {
|
|
1970
|
+
const [regex, fn] = transform;
|
|
1971
|
+
valTransforms.push({
|
|
1972
|
+
fn,
|
|
1973
|
+
regex
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
function deleteTransform(patternOrFn) {
|
|
1977
|
+
const idx = valTransforms.findIndex(
|
|
1978
|
+
(t) => typeof patternOrFn === "function" ? t.fn === patternOrFn : t.regex === patternOrFn
|
|
1979
|
+
);
|
|
1980
|
+
if (idx !== -1) {
|
|
1981
|
+
valTransforms.splice(idx, 1);
|
|
1982
|
+
return true;
|
|
1983
|
+
}
|
|
1984
|
+
return false;
|
|
1985
|
+
}
|
|
1986
|
+
var templateLiteralTransform = [
|
|
1987
|
+
/\$\{([a-zA-Z0-9$_-]+)\}/gm,
|
|
1988
|
+
({ matches, trArgs, trValue }) => {
|
|
1989
|
+
const patternStart = "${", patternEnd = "}", patternRegex = /\$\{.+\}/m;
|
|
1990
|
+
let str = String(trValue);
|
|
1991
|
+
const eachKeyInTrString = (keys) => keys.every((key) => trValue.includes(`${patternStart}${key}${patternEnd}`));
|
|
1992
|
+
const namedMapping = () => {
|
|
1993
|
+
var _a;
|
|
1994
|
+
if (!str.includes(patternStart) || typeof trArgs[0] === "undefined" || typeof trArgs[0] !== "object" || !eachKeyInTrString(Object.keys((_a = trArgs[0]) != null ? _a : {})))
|
|
1995
|
+
return;
|
|
1996
|
+
for (const match of matches) {
|
|
1997
|
+
const repl = match[1] !== void 0 ? trArgs[0][match[1]] : void 0;
|
|
1998
|
+
if (typeof repl !== "undefined")
|
|
1999
|
+
str = str.replace(match[0], String(repl));
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
const positionalMapping = () => {
|
|
2003
|
+
if (!patternRegex.test(str) || !trArgs[0])
|
|
2004
|
+
return;
|
|
2005
|
+
let matchNum = -1;
|
|
2006
|
+
for (const match of matches) {
|
|
2007
|
+
matchNum++;
|
|
2008
|
+
if (typeof trArgs[matchNum] !== "undefined")
|
|
2009
|
+
str = str.replace(match[0], String(trArgs[matchNum]));
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
let notStringifiable = false;
|
|
2013
|
+
try {
|
|
2014
|
+
String(trArgs[0]);
|
|
2015
|
+
} catch (e) {
|
|
2016
|
+
notStringifiable = true;
|
|
2017
|
+
}
|
|
2018
|
+
const isArgsObject = trArgs[0] && typeof trArgs[0] === "object" && trArgs[0] !== null && (notStringifiable || String(trArgs[0]).startsWith("[object"));
|
|
2019
|
+
if (isArgsObject && eachKeyInTrString(Object.keys(trArgs[0])))
|
|
2020
|
+
namedMapping();
|
|
2021
|
+
else
|
|
2022
|
+
positionalMapping();
|
|
2023
|
+
return str;
|
|
2024
|
+
}
|
|
2025
|
+
];
|
|
2026
|
+
var percentTransform = [
|
|
2027
|
+
/%(\d+)/gm,
|
|
2028
|
+
({ matches, trArgs, trValue }) => {
|
|
2029
|
+
let str = String(trValue);
|
|
2030
|
+
for (const match of matches) {
|
|
2031
|
+
const repl = match[1] !== void 0 ? trArgs == null ? void 0 : trArgs[Number(match[1]) - 1] : void 0;
|
|
2032
|
+
if (typeof repl !== "undefined")
|
|
2033
|
+
str = str.replace(match[0], String(repl));
|
|
2034
|
+
}
|
|
2035
|
+
return str;
|
|
2036
|
+
}
|
|
2037
|
+
];
|
|
2038
|
+
var tr = {
|
|
2039
|
+
for: (...params) => trFor(...params),
|
|
2040
|
+
use: (...params) => useTr(...params),
|
|
2041
|
+
hasKey: (language = fallbackLang != null ? fallbackLang : "", key) => hasKey(language, key),
|
|
2042
|
+
addTranslations,
|
|
2043
|
+
getTranslations,
|
|
2044
|
+
deleteTranslations,
|
|
2045
|
+
setFallbackLanguage,
|
|
2046
|
+
getFallbackLanguage,
|
|
2047
|
+
addTransform,
|
|
2048
|
+
deleteTransform,
|
|
2049
|
+
transforms: {
|
|
2050
|
+
templateLiteral: templateLiteralTransform,
|
|
2051
|
+
percent: percentTransform
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
2058
|
+
var __cp = (to, from, except, desc) => {
|
|
2059
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
2060
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
2061
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
2062
|
+
Object.defineProperty(to, key, {
|
|
2063
|
+
get: () => from[key],
|
|
2064
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
return to;
|
|
2069
|
+
};
|
|
2070
|
+
module.exports = __cp(module.exports, exports);
|
|
2071
|
+
}
|
|
2072
|
+
return module.exports;
|
|
2073
|
+
}))
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
//# sourceMappingURL=UserUtils.umd.js.map
|