mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-01 02:52:49 +08:00
fix(skin): repair host recovery compatibility and placement
Align the toolbar example with its first compatible runtime, restore recovery after shortcut focus leaves, and harden observer scheduling, contrast, floating avoidance, and private selector validation.
This commit is contained in:
1 parent
df826f575e
commit
4e8ea3081c
17 files changed
+453
-23
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Host floating placement: docked toolbar and pointer avoidance</title>
|
||||
<style>
|
||||
html, body { margin: 0; width: 100%; height: 100%; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="result">pending</pre>
|
||||
<script type="module">
|
||||
import { createHostOwnedLayer } from "/src/services/host-owned-layer.ts";
|
||||
import { bindFloatingAvoidance, floatingRect } from "/src/services/host-floating-placement.ts";
|
||||
|
||||
const output = document.getElementById("result");
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const viewport = { width: innerWidth, height: innerHeight };
|
||||
const margins = { top: 12, right: 12, bottom: 38, left: 12 };
|
||||
const size = { width: 200, height: 30 };
|
||||
|
||||
try {
|
||||
const layer = createHostOwnedLayer("recovery", `
|
||||
.cap { position: fixed; display: flex; width: 200px; height: 30px; pointer-events: auto; }
|
||||
.cap button { width: 200px; height: 30px; }
|
||||
`);
|
||||
if (!layer) throw new Error("recovery layer was not created");
|
||||
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();
|
||||
let bound = false;
|
||||
const moves = [];
|
||||
const binding = bindFloatingAvoidance({
|
||||
element: control,
|
||||
isSelf: (node) => node === layer.host || layer.host.contains(node),
|
||||
margins,
|
||||
defaultPosition: "bottom-left",
|
||||
avoidRects: () => [
|
||||
floatingRect("bottom-left", size, viewport, margins),
|
||||
floatingRect("bottom-right", size, viewport, margins),
|
||||
],
|
||||
apply: (position) => {
|
||||
control.style.left = position.endsWith("left") ? "12px" : position.endsWith("center") ? "50%" : "auto";
|
||||
control.style.right = position.endsWith("right") ? "12px" : "auto";
|
||||
control.style.top = position.startsWith("top") ? "12px" : position.startsWith("middle") ? "50%" : "auto";
|
||||
control.style.bottom = position.startsWith("bottom") ? "38px" : "auto";
|
||||
control.style.translate = position.endsWith("center") ? "-50% 0" : position.startsWith("middle") ? "0 -50%" : "none";
|
||||
if (bound) moves.push(position);
|
||||
},
|
||||
});
|
||||
bound = true;
|
||||
const pointerTarget = floatingRect("top-left", size, viewport, margins);
|
||||
document.dispatchEvent(new PointerEvent("pointermove", {
|
||||
bubbles: true,
|
||||
pointerType: "mouse",
|
||||
clientX: pointerTarget.left + pointerTarget.width / 2,
|
||||
clientY: pointerTarget.top + pointerTarget.height / 2,
|
||||
}));
|
||||
binding.screenChanged();
|
||||
await sleep(80);
|
||||
binding.revalidate();
|
||||
const box = control.getBoundingClientRect();
|
||||
output.textContent = JSON.stringify({
|
||||
position: binding.position,
|
||||
moves,
|
||||
pointerTarget: "top-left",
|
||||
pointerHit: document.elementFromPoint(
|
||||
pointerTarget.left + pointerTarget.width / 2,
|
||||
pointerTarget.top + pointerTarget.height / 2,
|
||||
) === layer.host,
|
||||
rect: { left: box.left, top: box.top, width: box.width, height: box.height },
|
||||
});
|
||||
binding.dispose();
|
||||
} catch (error) {
|
||||
output.textContent = JSON.stringify({ error: String(error?.stack ?? error) });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user