@sv443-network/userutils 7.1.0 → 7.2.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 +11 -0
- package/README.md +185 -74
- package/dist/index.global.js +204 -190
- package/dist/index.js +203 -190
- package/dist/lib/Dialog.d.ts +6 -33
- package/dist/lib/NanoEmitter.d.ts +2 -2
- package/dist/lib/colors.d.ts +18 -0
- package/dist/lib/crypto.d.ts +24 -0
- package/dist/lib/dom.d.ts +8 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/misc.d.ts +7 -31
- package/dist/lib/types.d.ts +10 -0
- package/package.json +5 -2
package/dist/index.global.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// ==UserLibrary==
|
|
9
9
|
// @name UserUtils
|
|
10
10
|
// @description Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more
|
|
11
|
-
// @version 7.
|
|
11
|
+
// @version 7.2.0
|
|
12
12
|
// @license MIT
|
|
13
13
|
// @copyright Sv443 (https://github.com/Sv443)
|
|
14
14
|
|
|
@@ -128,6 +128,197 @@ var UserUtils = (function (exports) {
|
|
|
128
128
|
return retArray;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// lib/dom.ts
|
|
132
|
+
function getUnsafeWindow() {
|
|
133
|
+
try {
|
|
134
|
+
return unsafeWindow;
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return window;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function addParent(element, newParent) {
|
|
140
|
+
const oldParent = element.parentNode;
|
|
141
|
+
if (!oldParent)
|
|
142
|
+
throw new Error("Element doesn't have a parent node");
|
|
143
|
+
oldParent.replaceChild(newParent, element);
|
|
144
|
+
newParent.appendChild(element);
|
|
145
|
+
return newParent;
|
|
146
|
+
}
|
|
147
|
+
function addGlobalStyle(style) {
|
|
148
|
+
const styleElem = document.createElement("style");
|
|
149
|
+
setInnerHtmlUnsafe(styleElem, style);
|
|
150
|
+
document.head.appendChild(styleElem);
|
|
151
|
+
return styleElem;
|
|
152
|
+
}
|
|
153
|
+
function preloadImages(srcUrls, rejects = false) {
|
|
154
|
+
const promises = srcUrls.map((src) => new Promise((res, rej) => {
|
|
155
|
+
const image = new Image();
|
|
156
|
+
image.src = src;
|
|
157
|
+
image.addEventListener("load", () => res(image));
|
|
158
|
+
image.addEventListener("error", (evt) => rejects && rej(evt));
|
|
159
|
+
}));
|
|
160
|
+
return Promise.allSettled(promises);
|
|
161
|
+
}
|
|
162
|
+
function openInNewTab(href, background) {
|
|
163
|
+
try {
|
|
164
|
+
GM.openInTab(href, background);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
const openElem = document.createElement("a");
|
|
167
|
+
Object.assign(openElem, {
|
|
168
|
+
className: "userutils-open-in-new-tab",
|
|
169
|
+
target: "_blank",
|
|
170
|
+
rel: "noopener noreferrer",
|
|
171
|
+
href
|
|
172
|
+
});
|
|
173
|
+
openElem.style.display = "none";
|
|
174
|
+
document.body.appendChild(openElem);
|
|
175
|
+
openElem.click();
|
|
176
|
+
setTimeout(openElem.remove, 50);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function interceptEvent(eventObject, eventName, predicate = () => true) {
|
|
180
|
+
Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
181
|
+
if (isNaN(Error.stackTraceLimit))
|
|
182
|
+
Error.stackTraceLimit = 100;
|
|
183
|
+
(function(original) {
|
|
184
|
+
eventObject.__proto__.addEventListener = function(...args) {
|
|
185
|
+
var _a, _b;
|
|
186
|
+
const origListener = typeof args[1] === "function" ? args[1] : (_b = (_a = args[1]) == null ? void 0 : _a.handleEvent) != null ? _b : () => void 0;
|
|
187
|
+
args[1] = function(...a) {
|
|
188
|
+
if (args[0] === eventName && predicate(Array.isArray(a) ? a[0] : a))
|
|
189
|
+
return;
|
|
190
|
+
else
|
|
191
|
+
return origListener.apply(this, a);
|
|
192
|
+
};
|
|
193
|
+
original.apply(this, args);
|
|
194
|
+
};
|
|
195
|
+
})(eventObject.__proto__.addEventListener);
|
|
196
|
+
}
|
|
197
|
+
function interceptWindowEvent(eventName, predicate = () => true) {
|
|
198
|
+
return interceptEvent(getUnsafeWindow(), eventName, predicate);
|
|
199
|
+
}
|
|
200
|
+
function isScrollable(element) {
|
|
201
|
+
const { overflowX, overflowY } = getComputedStyle(element);
|
|
202
|
+
return {
|
|
203
|
+
vertical: (overflowY === "scroll" || overflowY === "auto") && element.scrollHeight > element.clientHeight,
|
|
204
|
+
horizontal: (overflowX === "scroll" || overflowX === "auto") && element.scrollWidth > element.clientWidth
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function observeElementProp(element, property, callback) {
|
|
208
|
+
const elementPrototype = Object.getPrototypeOf(element);
|
|
209
|
+
if (elementPrototype.hasOwnProperty(property)) {
|
|
210
|
+
const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property);
|
|
211
|
+
Object.defineProperty(element, property, {
|
|
212
|
+
get: function() {
|
|
213
|
+
var _a;
|
|
214
|
+
return (_a = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _a.apply(this, arguments);
|
|
215
|
+
},
|
|
216
|
+
set: function() {
|
|
217
|
+
var _a;
|
|
218
|
+
const oldValue = this[property];
|
|
219
|
+
(_a = descriptor == null ? void 0 : descriptor.set) == null ? void 0 : _a.apply(this, arguments);
|
|
220
|
+
const newValue = this[property];
|
|
221
|
+
if (typeof callback === "function") {
|
|
222
|
+
callback.bind(this, oldValue, newValue);
|
|
223
|
+
}
|
|
224
|
+
return newValue;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function getSiblingsFrame(refElement, siblingAmount, refElementAlignment = "center-top", includeRef = true) {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
const siblings = [...(_b = (_a = refElement.parentNode) == null ? void 0 : _a.childNodes) != null ? _b : []];
|
|
232
|
+
const elemSiblIdx = siblings.indexOf(refElement);
|
|
233
|
+
if (elemSiblIdx === -1)
|
|
234
|
+
throw new Error("Element doesn't have a parent node");
|
|
235
|
+
if (refElementAlignment === "top")
|
|
236
|
+
return [...siblings.slice(elemSiblIdx + Number(!includeRef), elemSiblIdx + siblingAmount + Number(!includeRef))];
|
|
237
|
+
else if (refElementAlignment.startsWith("center-")) {
|
|
238
|
+
const halfAmount = (refElementAlignment === "center-bottom" ? Math.ceil : Math.floor)(siblingAmount / 2);
|
|
239
|
+
const startIdx = Math.max(0, elemSiblIdx - halfAmount);
|
|
240
|
+
const topOffset = Number(refElementAlignment === "center-top" && siblingAmount % 2 === 0 && includeRef);
|
|
241
|
+
const btmOffset = Number(refElementAlignment === "center-bottom" && siblingAmount % 2 !== 0 && includeRef);
|
|
242
|
+
const startIdxWithOffset = startIdx + topOffset + btmOffset;
|
|
243
|
+
return [
|
|
244
|
+
...siblings.filter((_, idx) => includeRef || idx !== elemSiblIdx).slice(startIdxWithOffset, startIdxWithOffset + siblingAmount)
|
|
245
|
+
];
|
|
246
|
+
} else if (refElementAlignment === "bottom")
|
|
247
|
+
return [...siblings.slice(elemSiblIdx - siblingAmount + Number(includeRef), elemSiblIdx + Number(includeRef))];
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
var ttPolicy;
|
|
251
|
+
function setInnerHtmlUnsafe(element, html) {
|
|
252
|
+
var _a, _b, _c;
|
|
253
|
+
if (!ttPolicy && typeof ((_a = window == null ? void 0 : window.trustedTypes) == null ? void 0 : _a.createPolicy) === "function") {
|
|
254
|
+
ttPolicy = window.trustedTypes.createPolicy("_uu_set_innerhtml_unsafe", {
|
|
255
|
+
createHTML: (unsafeHtml) => unsafeHtml
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
element.innerHTML = (_c = (_b = ttPolicy == null ? void 0 : ttPolicy.createHTML) == null ? void 0 : _b.call(ttPolicy, html)) != null ? _c : html;
|
|
259
|
+
return element;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// lib/crypto.ts
|
|
263
|
+
function compress(input, compressionFormat, outputType = "string") {
|
|
264
|
+
return __async(this, null, function* () {
|
|
265
|
+
const byteArray = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
266
|
+
const comp = new CompressionStream(compressionFormat);
|
|
267
|
+
const writer = comp.writable.getWriter();
|
|
268
|
+
writer.write(byteArray);
|
|
269
|
+
writer.close();
|
|
270
|
+
const buf = yield new Response(comp.readable).arrayBuffer();
|
|
271
|
+
return outputType === "arrayBuffer" ? buf : ab2str(buf);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function decompress(input, compressionFormat, outputType = "string") {
|
|
275
|
+
return __async(this, null, function* () {
|
|
276
|
+
const byteArray = typeof input === "string" ? str2ab(input) : input;
|
|
277
|
+
const decomp = new DecompressionStream(compressionFormat);
|
|
278
|
+
const writer = decomp.writable.getWriter();
|
|
279
|
+
writer.write(byteArray);
|
|
280
|
+
writer.close();
|
|
281
|
+
const buf = yield new Response(decomp.readable).arrayBuffer();
|
|
282
|
+
return outputType === "arrayBuffer" ? buf : new TextDecoder().decode(buf);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function ab2str(buf) {
|
|
286
|
+
return getUnsafeWindow().btoa(
|
|
287
|
+
new Uint8Array(buf).reduce((data, byte) => data + String.fromCharCode(byte), "")
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
function str2ab(str) {
|
|
291
|
+
return Uint8Array.from(getUnsafeWindow().atob(str), (c) => c.charCodeAt(0));
|
|
292
|
+
}
|
|
293
|
+
function computeHash(input, algorithm = "SHA-256") {
|
|
294
|
+
return __async(this, null, function* () {
|
|
295
|
+
let data;
|
|
296
|
+
if (typeof input === "string") {
|
|
297
|
+
const encoder = new TextEncoder();
|
|
298
|
+
data = encoder.encode(input);
|
|
299
|
+
} else
|
|
300
|
+
data = input;
|
|
301
|
+
const hashBuffer = yield crypto.subtle.digest(algorithm, data);
|
|
302
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
303
|
+
const hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
304
|
+
return hashHex;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function randomId(length = 16, radix = 16, enhancedEntropy = false) {
|
|
308
|
+
if (enhancedEntropy) {
|
|
309
|
+
const arr = new Uint8Array(length);
|
|
310
|
+
crypto.getRandomValues(arr);
|
|
311
|
+
return Array.from(
|
|
312
|
+
arr,
|
|
313
|
+
(v) => mapRange(v, 0, 255, 0, radix).toString(radix).substring(0, 1)
|
|
314
|
+
).join("");
|
|
315
|
+
}
|
|
316
|
+
return Array.from(
|
|
317
|
+
{ length },
|
|
318
|
+
() => Math.floor(Math.random() * radix).toString(radix)
|
|
319
|
+
).join("");
|
|
320
|
+
}
|
|
321
|
+
|
|
131
322
|
// lib/DataStore.ts
|
|
132
323
|
var DataStore = class {
|
|
133
324
|
/**
|
|
@@ -432,126 +623,6 @@ Has: ${checksum}`);
|
|
|
432
623
|
}
|
|
433
624
|
};
|
|
434
625
|
|
|
435
|
-
// lib/dom.ts
|
|
436
|
-
function getUnsafeWindow() {
|
|
437
|
-
try {
|
|
438
|
-
return unsafeWindow;
|
|
439
|
-
} catch (e) {
|
|
440
|
-
return window;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function addParent(element, newParent) {
|
|
444
|
-
const oldParent = element.parentNode;
|
|
445
|
-
if (!oldParent)
|
|
446
|
-
throw new Error("Element doesn't have a parent node");
|
|
447
|
-
oldParent.replaceChild(newParent, element);
|
|
448
|
-
newParent.appendChild(element);
|
|
449
|
-
return newParent;
|
|
450
|
-
}
|
|
451
|
-
function addGlobalStyle(style) {
|
|
452
|
-
const styleElem = document.createElement("style");
|
|
453
|
-
styleElem.innerHTML = style;
|
|
454
|
-
document.head.appendChild(styleElem);
|
|
455
|
-
return styleElem;
|
|
456
|
-
}
|
|
457
|
-
function preloadImages(srcUrls, rejects = false) {
|
|
458
|
-
const promises = srcUrls.map((src) => new Promise((res, rej) => {
|
|
459
|
-
const image = new Image();
|
|
460
|
-
image.src = src;
|
|
461
|
-
image.addEventListener("load", () => res(image));
|
|
462
|
-
image.addEventListener("error", (evt) => rejects && rej(evt));
|
|
463
|
-
}));
|
|
464
|
-
return Promise.allSettled(promises);
|
|
465
|
-
}
|
|
466
|
-
function openInNewTab(href, background) {
|
|
467
|
-
try {
|
|
468
|
-
GM.openInTab(href, background);
|
|
469
|
-
} catch (e) {
|
|
470
|
-
const openElem = document.createElement("a");
|
|
471
|
-
Object.assign(openElem, {
|
|
472
|
-
className: "userutils-open-in-new-tab",
|
|
473
|
-
target: "_blank",
|
|
474
|
-
rel: "noopener noreferrer",
|
|
475
|
-
href
|
|
476
|
-
});
|
|
477
|
-
openElem.style.display = "none";
|
|
478
|
-
document.body.appendChild(openElem);
|
|
479
|
-
openElem.click();
|
|
480
|
-
setTimeout(openElem.remove, 50);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function interceptEvent(eventObject, eventName, predicate = () => true) {
|
|
484
|
-
Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
485
|
-
if (isNaN(Error.stackTraceLimit))
|
|
486
|
-
Error.stackTraceLimit = 100;
|
|
487
|
-
(function(original) {
|
|
488
|
-
eventObject.__proto__.addEventListener = function(...args) {
|
|
489
|
-
var _a, _b;
|
|
490
|
-
const origListener = typeof args[1] === "function" ? args[1] : (_b = (_a = args[1]) == null ? void 0 : _a.handleEvent) != null ? _b : () => void 0;
|
|
491
|
-
args[1] = function(...a) {
|
|
492
|
-
if (args[0] === eventName && predicate(Array.isArray(a) ? a[0] : a))
|
|
493
|
-
return;
|
|
494
|
-
else
|
|
495
|
-
return origListener.apply(this, a);
|
|
496
|
-
};
|
|
497
|
-
original.apply(this, args);
|
|
498
|
-
};
|
|
499
|
-
})(eventObject.__proto__.addEventListener);
|
|
500
|
-
}
|
|
501
|
-
function interceptWindowEvent(eventName, predicate = () => true) {
|
|
502
|
-
return interceptEvent(getUnsafeWindow(), eventName, predicate);
|
|
503
|
-
}
|
|
504
|
-
function isScrollable(element) {
|
|
505
|
-
const { overflowX, overflowY } = getComputedStyle(element);
|
|
506
|
-
return {
|
|
507
|
-
vertical: (overflowY === "scroll" || overflowY === "auto") && element.scrollHeight > element.clientHeight,
|
|
508
|
-
horizontal: (overflowX === "scroll" || overflowX === "auto") && element.scrollWidth > element.clientWidth
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
function observeElementProp(element, property, callback) {
|
|
512
|
-
const elementPrototype = Object.getPrototypeOf(element);
|
|
513
|
-
if (elementPrototype.hasOwnProperty(property)) {
|
|
514
|
-
const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property);
|
|
515
|
-
Object.defineProperty(element, property, {
|
|
516
|
-
get: function() {
|
|
517
|
-
var _a;
|
|
518
|
-
return (_a = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _a.apply(this, arguments);
|
|
519
|
-
},
|
|
520
|
-
set: function() {
|
|
521
|
-
var _a;
|
|
522
|
-
const oldValue = this[property];
|
|
523
|
-
(_a = descriptor == null ? void 0 : descriptor.set) == null ? void 0 : _a.apply(this, arguments);
|
|
524
|
-
const newValue = this[property];
|
|
525
|
-
if (typeof callback === "function") {
|
|
526
|
-
callback.bind(this, oldValue, newValue);
|
|
527
|
-
}
|
|
528
|
-
return newValue;
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
function getSiblingsFrame(refElement, siblingAmount, refElementAlignment = "center-top", includeRef = true) {
|
|
534
|
-
var _a, _b;
|
|
535
|
-
const siblings = [...(_b = (_a = refElement.parentNode) == null ? void 0 : _a.childNodes) != null ? _b : []];
|
|
536
|
-
const elemSiblIdx = siblings.indexOf(refElement);
|
|
537
|
-
if (elemSiblIdx === -1)
|
|
538
|
-
throw new Error("Element doesn't have a parent node");
|
|
539
|
-
if (refElementAlignment === "top")
|
|
540
|
-
return [...siblings.slice(elemSiblIdx + Number(!includeRef), elemSiblIdx + siblingAmount + Number(!includeRef))];
|
|
541
|
-
else if (refElementAlignment.startsWith("center-")) {
|
|
542
|
-
const halfAmount = (refElementAlignment === "center-bottom" ? Math.ceil : Math.floor)(siblingAmount / 2);
|
|
543
|
-
const startIdx = Math.max(0, elemSiblIdx - halfAmount);
|
|
544
|
-
const topOffset = Number(refElementAlignment === "center-top" && siblingAmount % 2 === 0 && includeRef);
|
|
545
|
-
const btmOffset = Number(refElementAlignment === "center-bottom" && siblingAmount % 2 !== 0 && includeRef);
|
|
546
|
-
const startIdxWithOffset = startIdx + topOffset + btmOffset;
|
|
547
|
-
return [
|
|
548
|
-
...siblings.filter((_, idx) => includeRef || idx !== elemSiblIdx).slice(startIdxWithOffset, startIdxWithOffset + siblingAmount)
|
|
549
|
-
];
|
|
550
|
-
} else if (refElementAlignment === "bottom")
|
|
551
|
-
return [...siblings.slice(elemSiblIdx - siblingAmount + Number(includeRef), elemSiblIdx + Number(includeRef))];
|
|
552
|
-
return [];
|
|
553
|
-
}
|
|
554
|
-
|
|
555
626
|
// node_modules/nanoevents/index.js
|
|
556
627
|
var createNanoEvents = () => ({
|
|
557
628
|
emit(event, ...args) {
|
|
@@ -796,9 +867,8 @@ Has: ${checksum}`);
|
|
|
796
867
|
destroyOnClose: false,
|
|
797
868
|
unmountOnClose: true,
|
|
798
869
|
removeListenersOnDestroy: true,
|
|
799
|
-
|
|
800
|
-
verticalAlign: "center"
|
|
801
|
-
dialogCss: defaultDialogCss
|
|
870
|
+
small: false,
|
|
871
|
+
verticalAlign: "center"
|
|
802
872
|
}, opts);
|
|
803
873
|
this.id = opts.id;
|
|
804
874
|
}
|
|
@@ -806,11 +876,12 @@ Has: ${checksum}`);
|
|
|
806
876
|
/** Call after DOMContentLoaded to pre-render the dialog and invisibly mount it in the DOM */
|
|
807
877
|
mount() {
|
|
808
878
|
return __async(this, null, function* () {
|
|
879
|
+
var _a;
|
|
809
880
|
if (this.dialogMounted)
|
|
810
881
|
return;
|
|
811
882
|
this.dialogMounted = true;
|
|
812
883
|
if (!document.querySelector("style.uu-dialog-css"))
|
|
813
|
-
addGlobalStyle(this.options.dialogCss).classList.add("uu-dialog-css");
|
|
884
|
+
addGlobalStyle((_a = this.options.dialogCss) != null ? _a : defaultDialogCss).classList.add("uu-dialog-css");
|
|
814
885
|
const bgElem = document.createElement("div");
|
|
815
886
|
bgElem.id = `uu-${this.id}-dialog-bg`;
|
|
816
887
|
bgElem.classList.add("uu-dialog-bg");
|
|
@@ -1047,6 +1118,13 @@ Has: ${checksum}`);
|
|
|
1047
1118
|
num = num.length;
|
|
1048
1119
|
return `${word}${num === 1 ? "" : "s"}`;
|
|
1049
1120
|
}
|
|
1121
|
+
function insertValues(input, ...values) {
|
|
1122
|
+
return input.replace(/%\d/gm, (match) => {
|
|
1123
|
+
var _a, _b;
|
|
1124
|
+
const argIndex = Number(match.substring(1)) - 1;
|
|
1125
|
+
return (_b = (_a = values[argIndex]) != null ? _a : match) == null ? void 0 : _b.toString();
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1050
1128
|
function pauseFor(time) {
|
|
1051
1129
|
return new Promise((res) => {
|
|
1052
1130
|
setTimeout(() => res(), time);
|
|
@@ -1085,71 +1163,6 @@ Has: ${checksum}`);
|
|
|
1085
1163
|
}
|
|
1086
1164
|
});
|
|
1087
1165
|
}
|
|
1088
|
-
function insertValues(input, ...values) {
|
|
1089
|
-
return input.replace(/%\d/gm, (match) => {
|
|
1090
|
-
var _a, _b;
|
|
1091
|
-
const argIndex = Number(match.substring(1)) - 1;
|
|
1092
|
-
return (_b = (_a = values[argIndex]) != null ? _a : match) == null ? void 0 : _b.toString();
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
function compress(input, compressionFormat, outputType = "string") {
|
|
1096
|
-
return __async(this, null, function* () {
|
|
1097
|
-
const byteArray = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
1098
|
-
const comp = new CompressionStream(compressionFormat);
|
|
1099
|
-
const writer = comp.writable.getWriter();
|
|
1100
|
-
writer.write(byteArray);
|
|
1101
|
-
writer.close();
|
|
1102
|
-
const buf = yield new Response(comp.readable).arrayBuffer();
|
|
1103
|
-
return outputType === "arrayBuffer" ? buf : ab2str(buf);
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
function decompress(input, compressionFormat, outputType = "string") {
|
|
1107
|
-
return __async(this, null, function* () {
|
|
1108
|
-
const byteArray = typeof input === "string" ? str2ab(input) : input;
|
|
1109
|
-
const decomp = new DecompressionStream(compressionFormat);
|
|
1110
|
-
const writer = decomp.writable.getWriter();
|
|
1111
|
-
writer.write(byteArray);
|
|
1112
|
-
writer.close();
|
|
1113
|
-
const buf = yield new Response(decomp.readable).arrayBuffer();
|
|
1114
|
-
return outputType === "arrayBuffer" ? buf : new TextDecoder().decode(buf);
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
function ab2str(buf) {
|
|
1118
|
-
return getUnsafeWindow().btoa(
|
|
1119
|
-
new Uint8Array(buf).reduce((data, byte) => data + String.fromCharCode(byte), "")
|
|
1120
|
-
);
|
|
1121
|
-
}
|
|
1122
|
-
function str2ab(str) {
|
|
1123
|
-
return Uint8Array.from(getUnsafeWindow().atob(str), (c) => c.charCodeAt(0));
|
|
1124
|
-
}
|
|
1125
|
-
function computeHash(input, algorithm = "SHA-256") {
|
|
1126
|
-
return __async(this, null, function* () {
|
|
1127
|
-
let data;
|
|
1128
|
-
if (typeof input === "string") {
|
|
1129
|
-
const encoder = new TextEncoder();
|
|
1130
|
-
data = encoder.encode(input);
|
|
1131
|
-
} else
|
|
1132
|
-
data = input;
|
|
1133
|
-
const hashBuffer = yield crypto.subtle.digest(algorithm, data);
|
|
1134
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
1135
|
-
const hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1136
|
-
return hashHex;
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
function randomId(length = 16, radix = 16, enhancedEntropy = false) {
|
|
1140
|
-
if (enhancedEntropy) {
|
|
1141
|
-
const arr = new Uint8Array(length);
|
|
1142
|
-
crypto.getRandomValues(arr);
|
|
1143
|
-
return Array.from(
|
|
1144
|
-
arr,
|
|
1145
|
-
(v) => mapRange(v, 0, 255, 0, radix).toString(radix).substring(0, 1)
|
|
1146
|
-
).join("");
|
|
1147
|
-
}
|
|
1148
|
-
return Array.from(
|
|
1149
|
-
{ length },
|
|
1150
|
-
() => Math.floor(Math.random() * radix).toString(radix)
|
|
1151
|
-
).join("");
|
|
1152
|
-
}
|
|
1153
1166
|
|
|
1154
1167
|
// lib/SelectorObserver.ts
|
|
1155
1168
|
var domLoaded = false;
|
|
@@ -1385,6 +1398,7 @@ Has: ${checksum}`);
|
|
|
1385
1398
|
exports.randomItem = randomItem;
|
|
1386
1399
|
exports.randomItemIndex = randomItemIndex;
|
|
1387
1400
|
exports.randomizeArray = randomizeArray;
|
|
1401
|
+
exports.setInnerHtmlUnsafe = setInnerHtmlUnsafe;
|
|
1388
1402
|
exports.takeRandomItem = takeRandomItem;
|
|
1389
1403
|
exports.tr = tr;
|
|
1390
1404
|
|