40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
// SPDX-License-Identifier: CPAL-1.0
|
|
// Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
|
|
// License 1.0: see LICENSE (its Exhibit A is this file's notice).
|
|
|
|
// jsdom lacks a few browser features the UI uses.
|
|
|
|
if (typeof HTMLDialogElement !== "undefined") {
|
|
const p = HTMLDialogElement.prototype as HTMLDialogElement & Record<string, unknown>;
|
|
if (!p.showModal) {
|
|
p.showModal = function (this: HTMLDialogElement) {
|
|
this.setAttribute("open", "");
|
|
};
|
|
p.show = function (this: HTMLDialogElement) {
|
|
this.setAttribute("open", "");
|
|
};
|
|
p.close = function (this: HTMLDialogElement) {
|
|
this.removeAttribute("open");
|
|
};
|
|
}
|
|
}
|
|
|
|
const clipboard = { text: "", writeText: async (t: string) => void (clipboard.text = t) };
|
|
Object.defineProperty(globalThis.navigator, "clipboard", { value: clipboard, configurable: true });
|
|
(globalThis as unknown as { __clipboard: typeof clipboard }).__clipboard = clipboard;
|
|
|
|
if (!("BroadcastChannel" in globalThis)) {
|
|
(globalThis as unknown as { BroadcastChannel: unknown }).BroadcastChannel = class {
|
|
onmessage: unknown = null;
|
|
postMessage() {}
|
|
close() {}
|
|
};
|
|
}
|
|
|
|
if (!("randomUUID" in crypto)) {
|
|
Object.defineProperty(crypto, "randomUUID", { value: () => Math.random().toString(36).slice(2) });
|
|
}
|
|
|
|
window.open = () => null;
|
|
HTMLAnchorElement.prototype.click = function () {};
|