mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: keep docked recovery capsule off protected controls and address slot review
- Fall back to the default corner when the docked capsule's footprint (largest observed size) overlaps a visible protected control; runtime check only, no new chrome.json or skin.css restriction. - Demo skin docks at align:start, away from the audio dock buttons. - Compact mode: tap/click pins it open (touch), shortcut expansion clears when focus leaves; the 5 s full-display hold starts on first dock. - Built-in button border uses the skin accent only when visible on #fff7ed. - probeColor no longer misreads a token equal to its sentinel. - Periodic re-check survives an exception and fails safe to floating. - Browser fixture exercises bindHostSlot: dock, fallback, anti-flap, protected cover, offscreen, unreadable tokens, dispose.
This commit is contained in:
1 parent
aefa0bc163
commit
93d221c3ef
10 files changed
+404
-42
No files matched your search
+124
@@ -0,0 +1,124 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Host slot placement fixture</title>
|
||||
<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; }
|
||||
#dock { position: absolute; left: 40px; top: 200px; width: 640px; height: 56px; }
|
||||
#anchor { position: absolute; left: 0; top: 4px; width: 320px; height: 48px; }
|
||||
#mic { position: absolute; right: 8px; top: 11px; width: 120px; height: 34px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- A skin surface: an empty anchor node on the left, a protected control on the right. -->
|
||||
<div class="ws-skin-root" data-ws-skin="community.slot-fixture" data-ws-part="app">
|
||||
<div id="dock" data-ws-part="voice.audio-dock">
|
||||
<div id="anchor" data-ws-part="skin.voice.dock.part-anchor"
|
||||
style="--skin-recovery-accent:#ffcc00;--skin-recovery-background:#102030;--skin-recovery-foreground:#ffffff;--skin-recovery-size:large"></div>
|
||||
<button type="button" id="mic" data-ws-part="voice.audio-dock.microphone">Mic</button>
|
||||
</div>
|
||||
</div>
|
||||
<pre id="result">pending</pre>
|
||||
<script type="module">
|
||||
import { createHostOwnedLayer } from "/src/services/host-owned-layer.ts";
|
||||
import { bindHostSlot } from "/src/services/host-slot-placement.ts";
|
||||
|
||||
const output = document.getElementById("result");
|
||||
const CSS = `
|
||||
.cap {
|
||||
position: fixed; inset: auto auto 12px 12px; margin: 0;
|
||||
display: flex; gap: 4px; padding: 4px; border: 0; pointer-events: auto;
|
||||
background: var(--ws-recovery-background, #fff);
|
||||
color: var(--ws-recovery-foreground, #31524f);
|
||||
}
|
||||
.cap button { min-height: var(--ws-recovery-hit, 28px); padding: 0 8px; }
|
||||
`;
|
||||
try {
|
||||
const layer = createHostOwnedLayer("recovery", CSS);
|
||||
const control = document.createElement("div");
|
||||
control.className = "cap";
|
||||
control.setAttribute("popover", "manual");
|
||||
control.innerHTML = '<button type="button">Use built-in skin</button>';
|
||||
layer.container.append(control);
|
||||
control.showPopover();
|
||||
|
||||
const anchor = document.getElementById("anchor");
|
||||
const mic = document.getElementById("mic");
|
||||
const changes = [];
|
||||
const binding = bindHostSlot({
|
||||
layer,
|
||||
control,
|
||||
anchor: "skin.voice.dock.part-anchor",
|
||||
skinId: "community.slot-fixture",
|
||||
align: "start",
|
||||
onModeChange: (change) => changes.push(change),
|
||||
});
|
||||
|
||||
const snap = (name) => {
|
||||
const rect = control.getBoundingClientRect();
|
||||
const anchorRect = anchor.getBoundingClientRect();
|
||||
const hit = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
||||
const style = getComputedStyle(control);
|
||||
return {
|
||||
name,
|
||||
mode: changes.at(-1)?.mode ?? "floating",
|
||||
reason: changes.at(-1)?.reason,
|
||||
inlineLeft: control.style.left,
|
||||
insideAnchor: rect.left >= anchorRect.left - 0.5 && rect.right <= anchorRect.right + 0.5
|
||||
&& rect.top >= anchorRect.top - 0.5 && rect.bottom <= anchorRect.bottom + 0.5,
|
||||
atDefaultCorner: Math.abs(rect.left - 12) < 1 && Math.abs(innerHeight - 12 - rect.bottom) < 1,
|
||||
hitIsLayerHost: hit === layer.host,
|
||||
background: style.backgroundColor,
|
||||
color: style.color,
|
||||
buttonHeight: control.querySelector("button").getBoundingClientRect().height,
|
||||
};
|
||||
};
|
||||
|
||||
const results = [];
|
||||
results.push(snap("initial"));
|
||||
|
||||
anchor.style.display = "none";
|
||||
binding.revalidate();
|
||||
results.push(snap("anchor-hidden"));
|
||||
|
||||
anchor.style.display = "";
|
||||
binding.revalidate();
|
||||
results.push(snap("restored-once"));
|
||||
binding.revalidate();
|
||||
results.push(snap("restored-twice"));
|
||||
|
||||
mic.style.left = "8px";
|
||||
mic.style.right = "auto";
|
||||
binding.revalidate();
|
||||
results.push(snap("covers-mic"));
|
||||
mic.style.left = "";
|
||||
mic.style.right = "";
|
||||
binding.revalidate();
|
||||
binding.revalidate();
|
||||
|
||||
anchor.style.transform = "translateX(-5000px)";
|
||||
binding.revalidate();
|
||||
results.push(snap("anchor-offscreen"));
|
||||
anchor.style.transform = "";
|
||||
binding.revalidate();
|
||||
binding.revalidate();
|
||||
|
||||
anchor.style.setProperty("--skin-recovery-foreground", "#102030");
|
||||
binding.revalidate();
|
||||
results.push(snap("unreadable-tokens"));
|
||||
|
||||
binding.dispose();
|
||||
results.push({
|
||||
...snap("disposed"),
|
||||
leftoverAccent: control.style.getPropertyValue("--ws-recovery-accent"),
|
||||
});
|
||||
output.textContent = JSON.stringify({ results, changes });
|
||||
} catch (error) {
|
||||
output.textContent = JSON.stringify({ error: String(error && error.stack || error) });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -76,7 +76,8 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
|
||||
assert.match(hostChrome, /addEventListener\("keydown", onKeydown, true\)/);
|
||||
assert.match(hostChrome, /removeEventListener\("keydown", onKeydown, true\)/);
|
||||
// Escape closes the popover from inside its closed shadow root.
|
||||
assert.match(hostChrome, /@keydown\.escape="shortcutOpen = false"/);
|
||||
assert.match(hostChrome, /@keydown\.escape="onRecoveryEscape"/);
|
||||
assert.match(hostChrome, /function onRecoveryEscape\(\) \{\s*shortcutOpen\.value = false;/);
|
||||
assert.doesNotMatch(hostChrome, /event\.defaultPrevented \|\| event\.repeat/);
|
||||
assert.doesNotMatch(hostChrome, /data-ws-part="host\.recovery"/);
|
||||
assert.doesNotMatch(hostChrome, /ws-host-recovery-layer/);
|
||||
@@ -237,3 +238,59 @@ test("recovery stays visible and clickable under hostile compiled skins", { skip
|
||||
assert.equal(result.layerOutsideSkinRoot, true, `${result.name}: recovery was rendered inside .ws-skin-root`);
|
||||
}
|
||||
});
|
||||
|
||||
test("a declared slot docks the capsule and falls back at runtime", { 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-slot-placement.html`);
|
||||
const match = dom.match(/<pre id="result"[^>]*>([\s\S]*?)<\/pre>/);
|
||||
assert.ok(match, "the 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 byName = Object.fromEntries(payload.results.map((result) => [result.name, result]));
|
||||
|
||||
const initial = byName.initial;
|
||||
assert.equal(initial.mode, "slotted", JSON.stringify(payload));
|
||||
assert.equal(initial.insideAnchor, true, "the capsule is not placed over the anchor");
|
||||
assert.equal(initial.hitIsLayerHost, true, "the docked capsule is not the hit-test target");
|
||||
assert.equal(initial.background, "rgb(16, 32, 48)", "skin background token was not applied");
|
||||
assert.equal(initial.color, "rgb(255, 255, 255)", "skin foreground token was not applied");
|
||||
assert.ok(initial.buttonHeight >= 36, "the large size tier minimum was not enforced");
|
||||
|
||||
assert.equal(byName["anchor-hidden"].mode, "floating");
|
||||
assert.equal(byName["anchor-hidden"].reason, "anchor-missing");
|
||||
assert.equal(byName["anchor-hidden"].inlineLeft, "");
|
||||
assert.equal(byName["anchor-hidden"].atDefaultCorner, true);
|
||||
|
||||
// Anti-flap: one good check after a fallback is not enough to re-dock.
|
||||
assert.equal(byName["restored-once"].mode, "floating");
|
||||
assert.equal(byName["restored-twice"].mode, "slotted");
|
||||
assert.equal(byName["restored-twice"].insideAnchor, true);
|
||||
|
||||
assert.equal(byName["covers-mic"].mode, "floating");
|
||||
assert.equal(byName["covers-mic"].reason, "covers-protected");
|
||||
assert.equal(byName["covers-mic"].atDefaultCorner, true);
|
||||
|
||||
assert.equal(byName["anchor-offscreen"].mode, "floating");
|
||||
// An invisible/off-screen element is never resolved as the anchor at all.
|
||||
assert.equal(byName["anchor-offscreen"].reason, "anchor-missing");
|
||||
assert.equal(byName["anchor-offscreen"].atDefaultCorner, true);
|
||||
|
||||
// Foreground equal to background: the whole colour group reverts.
|
||||
assert.equal(byName["unreadable-tokens"].background, "rgb(255, 255, 255)");
|
||||
assert.equal(byName["unreadable-tokens"].color, "rgb(49, 82, 79)");
|
||||
|
||||
assert.equal(byName.disposed.inlineLeft, "");
|
||||
assert.equal(byName.disposed.atDefaultCorner, true);
|
||||
assert.equal(byName.disposed.leftoverAccent, "");
|
||||
});
|
||||
Reference in new issue
Block a user