mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat: add host chrome theming and a skin-proof recovery layer
Allow skins to theme host chrome through a second scope and explicit visibleParts. Official and built-in skins stay decoration-free by default. Harden the CSS compiler so skins cannot hide the document root, push protected controls off-screen, or target the host layer with sibling selectors. Move recovery and authorization UI into a closed Shadow DOM on the top layer, so a third-party skin cannot block the built-in skin reset.
This commit is contained in:
1 parent
33ba062686
commit
f8d61d22ef
45 files changed
+3535
-558
No files matched your search
@@ -0,0 +1,128 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { isRecoveryShortcut } from "./host-chrome.js";
|
||||
import { HOST_OWNED_LAYER_Z_INDEX, syncRecoveryPopover } from "./host-owned-layer.js";
|
||||
|
||||
type ShortcutEvent = {
|
||||
ctrlKey: boolean;
|
||||
metaKey: boolean;
|
||||
altKey: boolean;
|
||||
shiftKey: boolean;
|
||||
key: string;
|
||||
};
|
||||
|
||||
const shortcut = (overrides: Partial<ShortcutEvent> = {}): ShortcutEvent => ({
|
||||
ctrlKey: false,
|
||||
metaKey: false,
|
||||
altKey: false,
|
||||
shiftKey: false,
|
||||
key: "",
|
||||
...overrides,
|
||||
});
|
||||
|
||||
test("the recovery shortcut requires the full Ctrl/Cmd+Alt+Shift+R chord", () => {
|
||||
assert.equal(isRecoveryShortcut(shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "r" })), true);
|
||||
// macOS uses the Meta/Command key in place of Ctrl.
|
||||
assert.equal(isRecoveryShortcut(shortcut({ metaKey: true, altKey: true, shiftKey: true, key: "R" })), true);
|
||||
|
||||
for (const rejected of [
|
||||
shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "x" }),
|
||||
shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "Enter" }),
|
||||
// Ordinary app/browser shortcuts must stay available.
|
||||
shortcut({ ctrlKey: true, key: "r" }),
|
||||
shortcut({ altKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: true, shiftKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: true, altKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: false, altKey: true, shiftKey: true, key: "r" }),
|
||||
]) {
|
||||
assert.equal(isRecoveryShortcut(rejected), false, JSON.stringify(rejected));
|
||||
}
|
||||
});
|
||||
|
||||
interface FakePopover {
|
||||
style: { display: string };
|
||||
showPopover?: () => void;
|
||||
hidePopover?: () => void;
|
||||
matches?: (selector: string) => boolean;
|
||||
removedAttributes: string[];
|
||||
removeAttribute(name: string): void;
|
||||
}
|
||||
|
||||
const fakePopover = (overrides: Partial<FakePopover> = {}): FakePopover => {
|
||||
const element: FakePopover = {
|
||||
style: { display: "" },
|
||||
removedAttributes: [],
|
||||
removeAttribute(name: string) {
|
||||
element.removedAttributes.push(name);
|
||||
},
|
||||
matches: () => false,
|
||||
...overrides,
|
||||
};
|
||||
return element;
|
||||
};
|
||||
|
||||
const asElement = (element: FakePopover) => element as unknown as HTMLElement;
|
||||
|
||||
test("a missing showPopover uses the display fallback, visible and hidden", () => {
|
||||
const element = fakePopover();
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.equal(element.style.display, "flex", "the capsule must be laid out without the Popover API");
|
||||
syncRecoveryPopover(asElement(element), false);
|
||||
assert.equal(element.style.display, "none");
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.equal(element.style.display, "flex");
|
||||
});
|
||||
|
||||
test("a throwing showPopover drops the popover attribute and shows the capsule", () => {
|
||||
let calls = 0;
|
||||
const element = fakePopover({
|
||||
showPopover() {
|
||||
calls += 1;
|
||||
throw new Error("top-layer promotion rejected");
|
||||
},
|
||||
});
|
||||
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.deepEqual(element.removedAttributes, ["popover"], "the UA display:none rule must be removed");
|
||||
assert.equal(element.style.display, "flex");
|
||||
assert.notEqual(element.style.display, "none");
|
||||
assert.equal(calls, 1);
|
||||
|
||||
// Once fallback is in use the element must not flap back to showPopover().
|
||||
syncRecoveryPopover(asElement(element), false);
|
||||
assert.equal(element.style.display, "none");
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.equal(element.style.display, "flex");
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test("a working showPopover/hidePopover keeps the top-layer path", () => {
|
||||
let open = false;
|
||||
let shown = 0;
|
||||
let hidden = 0;
|
||||
const element = fakePopover({
|
||||
showPopover() {
|
||||
shown += 1;
|
||||
open = true;
|
||||
},
|
||||
hidePopover() {
|
||||
hidden += 1;
|
||||
open = false;
|
||||
},
|
||||
matches: (selector) => selector === ":popover-open" && open,
|
||||
});
|
||||
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.equal(shown, 1);
|
||||
assert.equal(element.style.display, "", "the top-layer path must not force display");
|
||||
syncRecoveryPopover(asElement(element), true);
|
||||
assert.equal(shown, 1, "an already-open popover is not reopened");
|
||||
|
||||
syncRecoveryPopover(asElement(element), false);
|
||||
assert.equal(hidden, 1);
|
||||
assert.deepEqual(element.removedAttributes, [], "a working popover keeps its attribute");
|
||||
});
|
||||
|
||||
test("the pre-Popover host layer uses the CSS 32-bit maximum z-index", () => {
|
||||
assert.equal(HOST_OWNED_LAYER_Z_INDEX, 2147483647);
|
||||
});
|
||||
Reference in new issue
Block a user