mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): match Classic toolbar icon buttons for host recovery
Add slot appearance "icon" and "icon-and-label", allow an explicit 22px toolbar height, preserve transparent backgrounds, and introduce hover, surface, gap, and icon-size tokens so host-owned recovery and library buttons can match the Classic microphone control. Shortcut and failed- anchor fallbacks stay full label capsules. Update the example skin, docs, and tests, including a Classic toolbar fixture.
This commit is contained in:
1 parent
4131d9c319
commit
df826f575e
18 files changed
+805
-160
No files matched your search
@@ -61,6 +61,7 @@ try {
|
||||
const anchorRect = document.getElementById("anchor").getBoundingClientRect();
|
||||
const capsuleRect = capsule.getBoundingClientRect();
|
||||
const button = capsule.querySelector('[data-ws-recovery-action="built-in"]');
|
||||
const buttonStyle = getComputedStyle(button);
|
||||
const style = getComputedStyle(capsule);
|
||||
const isOpen = Boolean(capsule.matches(":popover-open")) || style.display !== "none";
|
||||
const before = hostBuiltInSkinRequests.value;
|
||||
@@ -75,6 +76,10 @@ try {
|
||||
.map((entry) => entry.getAttribute("data-ws-recovery-action")),
|
||||
background: style.backgroundColor,
|
||||
foreground: style.color,
|
||||
capsuleHeight: capsule.getBoundingClientRect().height,
|
||||
builtInHeight: button.getBoundingClientRect().height,
|
||||
builtInBackground: buttonStyle.backgroundColor,
|
||||
builtInForeground: buttonStyle.color,
|
||||
clicked: hostBuiltInSkinRequests.value === before + 1,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-ws-route="webclient" data-ws-page="voice" data-ws-host-skin="community.classic-toolbar-fixture">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Classic recovery toolbar fixture</title>
|
||||
<script>
|
||||
try { localStorage.setItem("webspeak:instance-authorization:v1", JSON.stringify({ schemaVersion: 1, allowed: true })); } catch {}
|
||||
</script>
|
||||
<style>
|
||||
html, body { margin: 0; width: 100%; height: 100%; font: 12px/1.5 system-ui, sans-serif; }
|
||||
.ws-skin-root { position: relative; width: 100vw; height: 100vh; background: #f4f7fb; }
|
||||
#topbar { position: absolute; left: 0; top: 0; right: 0; height: 32px; background: #f4f7fb; }
|
||||
#anchor { position: absolute; left: 40px; top: 5px; width: 320px; height: 22px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ws-skin-root" data-ws-skin="community.classic-toolbar-fixture" data-ws-page="voice" data-ws-part="app">
|
||||
<div id="topbar" data-ws-part="voice.header">
|
||||
<span id="anchor" data-ws-part="skin.voice.topbar.part-host-actions"
|
||||
style="--skin-recovery-toolbar-background:transparent;--skin-recovery-toolbar-foreground:#1a1a1a;--skin-recovery-toolbar-border:transparent;--skin-recovery-toolbar-hover-background:#eaf2fd;--skin-recovery-toolbar-hover-border:#b8cfe8;--skin-recovery-toolbar-radius:2px;--skin-recovery-toolbar-font-size:11px;--skin-recovery-toolbar-padding:0 4px;--skin-recovery-toolbar-height:22px;--skin-recovery-toolbar-gap:1px;--skin-recovery-toolbar-icon-size:16px"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="app"></div>
|
||||
<pre id="result" style="position:relative;z-index:5;background:#fff">pending</pre>
|
||||
<script type="module">
|
||||
import { createApp, h, nextTick } from "vue";
|
||||
import HostChrome from "/src/components/HostChrome.vue";
|
||||
import {
|
||||
hostBuiltInSkinRequests,
|
||||
pluginLibraryRequests,
|
||||
setHostChromeActiveSkin,
|
||||
setSkinHostChromeParts,
|
||||
} from "/src/services/host-chrome.ts";
|
||||
import { parseSkinChromeDocument } from "../../../src/shared/skin-chrome.ts";
|
||||
import { hostOwnedLayers } from "/src/services/host-owned-layer.ts";
|
||||
|
||||
const output = document.getElementById("result");
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const isOpen = (element) => Boolean(element?.matches?.(":popover-open"))
|
||||
|| (element ? getComputedStyle(element).display !== "none" : false);
|
||||
|
||||
try {
|
||||
setSkinHostChromeParts(parseSkinChromeDocument(JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
slots: {
|
||||
"host.recovery": {
|
||||
mode: "toolbar",
|
||||
appearance: "icon",
|
||||
anchor: "skin.voice.topbar.part-host-actions",
|
||||
align: "start",
|
||||
},
|
||||
},
|
||||
})));
|
||||
setHostChromeActiveSkin("community.classic-toolbar-fixture");
|
||||
createApp({
|
||||
render: () => h(HostChrome, { language: "en", connected: true, pluginLibraryAvailable: true }),
|
||||
}).mount("#app");
|
||||
|
||||
await nextTick();
|
||||
await sleep(300);
|
||||
|
||||
const layer = hostOwnedLayers().find((entry) => entry.name === "recovery");
|
||||
if (!layer) throw new Error("recovery layer was not created");
|
||||
const toolbar = layer.container.querySelector("[data-ws-host-recovery-toolbar]");
|
||||
const capsule = layer.container.querySelector("[data-ws-host-recovery]");
|
||||
const actions = [...toolbar.querySelectorAll("[data-ws-recovery-action]")];
|
||||
if (actions.length !== 2) throw new Error("expected two toolbar actions");
|
||||
const first = actions[0];
|
||||
const style = getComputedStyle(first);
|
||||
const icon = first.querySelector(".ws-host-toolbar-icon");
|
||||
const iconStyle = getComputedStyle(icon);
|
||||
const firstRect = first.getBoundingClientRect();
|
||||
const hit = document.elementFromPoint(firstRect.left + firstRect.width / 2, firstRect.top + firstRect.height / 2);
|
||||
const builtInBefore = hostBuiltInSkinRequests.value;
|
||||
const libraryBefore = pluginLibraryRequests.value;
|
||||
first.click();
|
||||
actions[1].click();
|
||||
|
||||
const initial = {
|
||||
toolbarOpen: isOpen(toolbar),
|
||||
capsuleOpen: isOpen(capsule),
|
||||
actionCount: actions.length,
|
||||
height: firstRect.height,
|
||||
width: firstRect.width,
|
||||
minHeight: style.minHeight,
|
||||
paddingTop: style.paddingTop,
|
||||
paddingRight: style.paddingRight,
|
||||
paddingBottom: style.paddingBottom,
|
||||
paddingLeft: style.paddingLeft,
|
||||
borderTopWidth: style.borderTopWidth,
|
||||
radius: style.borderTopLeftRadius,
|
||||
fontSize: style.fontSize,
|
||||
background: style.backgroundColor,
|
||||
foreground: style.color,
|
||||
gap: getComputedStyle(toolbar).columnGap,
|
||||
hoverBackground: toolbar.style.getPropertyValue("--ws-toolbar-hover-background"),
|
||||
hoverBorder: toolbar.style.getPropertyValue("--ws-toolbar-hover-border"),
|
||||
iconWidth: icon.getBoundingClientRect().width,
|
||||
iconHeight: icon.getBoundingClientRect().height,
|
||||
iconDisplay: iconStyle.display,
|
||||
iconAriaHidden: icon.getAttribute("aria-hidden"),
|
||||
svgFocusable: icon.querySelector("svg").getAttribute("focusable"),
|
||||
visibleText: actions.map((button) => button.textContent.trim()),
|
||||
accessibleNames: actions.map((button) => button.getAttribute("aria-label")),
|
||||
titles: actions.map((button) => button.getAttribute("title")),
|
||||
groupName: toolbar.getAttribute("aria-label"),
|
||||
hitIsLayerHost: hit === layer.host,
|
||||
builtInClicked: hostBuiltInSkinRequests.value === builtInBefore + 1,
|
||||
libraryClicked: pluginLibraryRequests.value === libraryBefore + 1,
|
||||
};
|
||||
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "r", code: "KeyR", ctrlKey: true, altKey: true, shiftKey: true, bubbles: true, cancelable: true,
|
||||
}));
|
||||
await nextTick();
|
||||
await sleep(100);
|
||||
const capsuleButtons = [...capsule.querySelectorAll("[data-ws-recovery-action]")];
|
||||
const builtInCapsuleStyle = getComputedStyle(capsuleButtons[0]);
|
||||
const shortcut = {
|
||||
capsuleOpen: isOpen(capsule),
|
||||
toolbarOpen: isOpen(toolbar),
|
||||
labels: capsuleButtons.map((button) => button.textContent.trim()),
|
||||
height: capsuleButtons[0].getBoundingClientRect().height,
|
||||
builtInBackground: builtInCapsuleStyle.backgroundColor,
|
||||
builtInForeground: builtInCapsuleStyle.color,
|
||||
focusedAction: layer.shadow.activeElement?.getAttribute?.("data-ws-recovery-action") ?? null,
|
||||
};
|
||||
capsule.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterEscape = { capsuleOpen: isOpen(capsule), toolbarOpen: isOpen(toolbar) };
|
||||
|
||||
const anchor = document.getElementById("anchor");
|
||||
anchor.style.setProperty("--skin-recovery-toolbar-foreground", "#ffffff");
|
||||
await sleep(700);
|
||||
const invalidStyle = getComputedStyle(first);
|
||||
const invalidTokens = {
|
||||
background: invalidStyle.backgroundColor,
|
||||
foreground: invalidStyle.color,
|
||||
visible: invalidStyle.display !== "none" && invalidStyle.visibility !== "hidden",
|
||||
};
|
||||
|
||||
output.textContent = JSON.stringify({ initial, shortcut, afterEscape, invalidTokens });
|
||||
} catch (error) {
|
||||
output.textContent = JSON.stringify({ error: String(error?.stack ?? error) });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -246,7 +246,7 @@ try {
|
||||
// Invalid / unreadable toolbar tokens must not make the button invisible.
|
||||
const voiceAnchor = document.getElementById("voice-anchor");
|
||||
voiceAnchor.style.setProperty("--skin-recovery-toolbar-background", "rgba(0,0,0,0)");
|
||||
voiceAnchor.style.setProperty("--skin-recovery-toolbar-foreground", "#111111");
|
||||
voiceAnchor.style.setProperty("--skin-recovery-toolbar-foreground", "#ffffff");
|
||||
voiceAnchor.style.setProperty("--skin-recovery-toolbar-shadow", "url(https://example.invalid/pixel)");
|
||||
await sleep(700);
|
||||
const fallbackStyle = getComputedStyle(buttons()[0]);
|
||||
|
||||
@@ -98,6 +98,14 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
|
||||
assert.match(hostChrome, /presentation: "toolbar"/);
|
||||
assert.match(hostChrome, /resolveHostRecoveryPresentation/);
|
||||
assert.match(hostChrome, /class="ws-host-toolbar-action"/);
|
||||
assert.match(hostChrome, /:aria-label="copy\.useBuiltIn"/);
|
||||
assert.match(hostChrome, /:aria-label="copy\.library"/);
|
||||
assert.match(hostChrome, /class="ws-host-toolbar-icon" aria-hidden="true"/);
|
||||
assert.match(hostChrome, /focusable="false"/);
|
||||
assert.match(hostChrome, /--ws-toolbar-hover-background/);
|
||||
assert.match(hostChrome, /--ws-toolbar-hover-border/);
|
||||
assert.match(hostChrome, /--ws-toolbar-gap/);
|
||||
assert.match(hostChrome, /--ws-toolbar-icon-size/);
|
||||
assert.match(hostChrome, /data-ws-recovery-action="built-in"[\s\S]*?@click="useBuiltInSkin"/);
|
||||
assert.match(hostChrome, /data-ws-recovery-action="library"[\s\S]*?@click="openLibrary"/);
|
||||
assert.match(hostChrome, /resolveHostRecoveryPresentation\(/);
|
||||
@@ -528,6 +536,75 @@ test("host control tokens follow late skin CSS, resolve modern colours and refus
|
||||
assert.equal(byName["after-dispose"].inlineBackground, late.inlineBackground, "a disposed binding kept observing the document");
|
||||
});
|
||||
|
||||
test("Classic toolbar icons keep 22px geometry, transparency, names and full-label shortcut recovery", { skip: !CHROME && "google-chrome is not installed" }, async (t) => {
|
||||
const server = await createServer({
|
||||
root: webRoot,
|
||||
configFile: path.join(webRoot, "vite.config.ts"),
|
||||
logLevel: "silent",
|
||||
server: { host: "127.0.0.1", port: 0, strictPort: false, hmr: false, ws: false },
|
||||
});
|
||||
t.after(() => server.close());
|
||||
await server.listen();
|
||||
const address = server.httpServer?.address();
|
||||
const port = address && typeof address === "object" ? address.port : 0;
|
||||
assert.ok(port, "Vite did not expose a listening port");
|
||||
|
||||
const dom = await dumpDom(
|
||||
`http://127.0.0.1:${port}/test/fixtures/host-recovery-toolbar-classic.html`,
|
||||
["--virtual-time-budget=10000", "--window-size=1280,800"],
|
||||
);
|
||||
const match = dom.match(/<pre id="result"[^>]*>([\s\S]*?)<\/pre>/);
|
||||
assert.ok(match, "the Classic toolbar fixture did not emit a result block");
|
||||
const payload = JSON.parse(match[1].replace(/"/g, '"').replace(/&/g, "&"));
|
||||
assert.equal(payload.error, undefined, payload.error);
|
||||
|
||||
const initial = payload.initial;
|
||||
assert.equal(initial.toolbarOpen, true);
|
||||
assert.equal(initial.capsuleOpen, false);
|
||||
assert.equal(initial.actionCount, 2);
|
||||
assert.equal(initial.height, 22);
|
||||
assert.equal(initial.width, 24);
|
||||
assert.equal(initial.minHeight, "22px");
|
||||
assert.equal(initial.paddingTop, "0px");
|
||||
assert.equal(initial.paddingRight, "0px");
|
||||
assert.equal(initial.paddingBottom, "0px");
|
||||
assert.equal(initial.paddingLeft, "0px");
|
||||
assert.equal(initial.borderTopWidth, "1px");
|
||||
assert.equal(initial.radius, "2px");
|
||||
assert.equal(initial.fontSize, "11px");
|
||||
assert.equal(initial.background, "rgba(0, 0, 0, 0)");
|
||||
assert.equal(initial.foreground, "rgb(26, 26, 26)");
|
||||
assert.equal(initial.gap, "1px");
|
||||
assert.equal(initial.hoverBackground, "rgb(234, 242, 253)");
|
||||
assert.equal(initial.hoverBorder, "rgb(184, 207, 232)");
|
||||
assert.equal(initial.iconWidth, 16);
|
||||
assert.equal(initial.iconHeight, 16);
|
||||
assert.equal(initial.iconDisplay, "block");
|
||||
assert.equal(initial.iconAriaHidden, "true");
|
||||
assert.equal(initial.svgFocusable, "false");
|
||||
assert.deepEqual(initial.visibleText, ["", ""]);
|
||||
assert.deepEqual(initial.accessibleNames, ["Use built-in skin", "Application library"]);
|
||||
assert.equal(initial.titles[0], "Restore the built-in skin (Ctrl+Alt+Shift+R, or ⌘+⌥+⇧+R on macOS)");
|
||||
assert.equal(initial.titles[1], "Application library");
|
||||
assert.equal(initial.groupName, "Restore built-in skin");
|
||||
assert.equal(initial.hitIsLayerHost, true);
|
||||
assert.equal(initial.builtInClicked, true);
|
||||
assert.equal(initial.libraryClicked, true);
|
||||
|
||||
assert.equal(payload.shortcut.capsuleOpen, true);
|
||||
assert.equal(payload.shortcut.toolbarOpen, false);
|
||||
assert.deepEqual(payload.shortcut.labels, ["Use built-in skin", "Application library"]);
|
||||
assert.ok(payload.shortcut.height >= 28);
|
||||
assert.equal(payload.shortcut.builtInBackground, "rgb(255, 247, 237)");
|
||||
assert.equal(payload.shortcut.builtInForeground, "rgb(124, 45, 18)");
|
||||
assert.equal(payload.shortcut.focusedAction, "built-in");
|
||||
assert.equal(payload.afterEscape.capsuleOpen, false);
|
||||
assert.equal(payload.afterEscape.toolbarOpen, true);
|
||||
assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)");
|
||||
assert.equal(payload.invalidTokens.foreground, "rgb(49, 82, 79)");
|
||||
assert.equal(payload.invalidTokens.visible, true);
|
||||
});
|
||||
|
||||
test("toolbar-mode recovery docks plain host buttons, de-duplicates the library and falls back", { skip: !CHROME && "google-chrome is not installed" }, async (t) => {
|
||||
const server = await createServer({
|
||||
root: webRoot,
|
||||
@@ -615,7 +692,7 @@ test("toolbar-mode recovery docks plain host buttons, de-duplicates the library
|
||||
|
||||
assert.equal(payload.invalidTokens.visible, true, "invalid toolbar tokens hid the button");
|
||||
assert.equal(payload.invalidTokens.inViewport, true);
|
||||
assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)", "transparent background must fall back to a visible surface");
|
||||
assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)", "unreadable transparent foreground must fall back to a visible surface");
|
||||
assert.equal(payload.invalidTokens.foreground, "rgb(49, 82, 79)");
|
||||
assert.equal(payload.invalidTokens.shadow, "none", "the invalid shadow token must not be applied");
|
||||
|
||||
@@ -832,5 +909,9 @@ test("legacy slots without a mode still dock the capsule", { skip: !CHROME && "g
|
||||
assert.deepEqual(payload.actions, ["built-in", "library"]);
|
||||
assert.equal(payload.background, "rgb(16, 32, 48)", "the capsule still reads --skin-recovery-* tokens");
|
||||
assert.equal(payload.foreground, "rgb(255, 255, 255)");
|
||||
assert.ok(payload.capsuleHeight >= 28, "the legacy capsule lost its original size floor");
|
||||
assert.ok(payload.builtInHeight >= 28, "the legacy capsule action lost its original size floor");
|
||||
assert.equal(payload.builtInBackground, "rgb(255, 247, 237)", "the capsule built-in action must keep its fixed light background");
|
||||
assert.equal(payload.builtInForeground, "rgb(124, 45, 18)");
|
||||
assert.equal(payload.clicked, true);
|
||||
});
|
||||
Reference in new issue
Block a user