mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +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>
|
||||
+37
-2
@@ -16,6 +16,7 @@
|
||||
#home-anchor { left: 20px; }
|
||||
#voice-anchor { left: 20px; display: none; }
|
||||
#dock { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; }
|
||||
#blank { position: absolute; left: 20px; top: 100px; padding: 12px; background: #fff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -34,6 +35,7 @@
|
||||
<button type="button" data-ws-part="voice.audio-dock.microphone">Mic</button>
|
||||
</div>
|
||||
<button type="button" id="launcher" data-ws-part="host.plugins.launcher">Plugins</button>
|
||||
<div id="blank" tabindex="-1">Blank area</div>
|
||||
</div>
|
||||
<div id="app"></div>
|
||||
<pre id="result" style="position:relative;z-index:5;background:#fff">pending</pre>
|
||||
@@ -209,7 +211,7 @@ try {
|
||||
capsuleActions: [...(capsule()?.querySelectorAll("[data-ws-recovery-action]") ?? [])]
|
||||
.map((button) => button.getAttribute("data-ws-recovery-action")),
|
||||
};
|
||||
capsule().dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
layer.shadow.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, composed: true }));
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterEscape = {
|
||||
@@ -235,7 +237,7 @@ try {
|
||||
capsuleActions: [...(capsule()?.querySelectorAll("[data-ws-recovery-action]") ?? [])]
|
||||
.map((button) => button.getAttribute("data-ws-recovery-action")),
|
||||
};
|
||||
capsule().dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
layer.shadow.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, composed: true }));
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterMacEscape = {
|
||||
@@ -243,6 +245,37 @@ try {
|
||||
toolbarOpen: isOpen(toolbar()),
|
||||
};
|
||||
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "r", ctrlKey: true, altKey: true, shiftKey: true, bubbles: true, cancelable: true,
|
||||
}));
|
||||
await nextTick();
|
||||
await sleep(80);
|
||||
document.getElementById("blank").focus();
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterFocusOut = {
|
||||
focusedAction: layer.shadow.activeElement?.getAttribute?.("data-ws-recovery-action") ?? null,
|
||||
activeId: document.activeElement?.id ?? null,
|
||||
capsuleOpen: isOpen(capsule()),
|
||||
toolbarOpen: isOpen(toolbar()),
|
||||
};
|
||||
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "r", ctrlKey: true, altKey: true, shiftKey: true, bubbles: true, cancelable: true,
|
||||
}));
|
||||
await nextTick();
|
||||
await sleep(80);
|
||||
const blank = document.getElementById("blank");
|
||||
blank.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, composed: true, pointerType: "mouse" }));
|
||||
blank.dispatchEvent(new MouseEvent("click", { bubbles: true, composed: true }));
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterBlankClick = {
|
||||
activeId: document.activeElement?.id ?? null,
|
||||
capsuleOpen: isOpen(capsule()),
|
||||
toolbarOpen: isOpen(toolbar()),
|
||||
};
|
||||
|
||||
// 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)");
|
||||
@@ -270,6 +303,8 @@ try {
|
||||
afterEscape,
|
||||
macShortcut,
|
||||
afterMacEscape,
|
||||
afterFocusOut,
|
||||
afterBlankClick,
|
||||
invalidTokens,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Host slot observer scheduling fixture</title>
|
||||
<style>
|
||||
html, body { margin: 0; width: 100%; height: 100%; }
|
||||
.ws-skin-root { position: relative; width: 100vw; height: 100vh; }
|
||||
#anchor { position: absolute; left: 20px; top: 20px; width: 240px; height: 48px; background: #f4f7fb; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ws-skin-root" data-ws-skin="community.observer-fixture" data-ws-part="app">
|
||||
<div id="anchor" data-ws-part="skin.home.header.part-host-actions"></div>
|
||||
</div>
|
||||
<pre id="result">pending</pre>
|
||||
<script type="module">
|
||||
import { bindHostSlot } from "/src/services/host-slot-placement.ts";
|
||||
import { createHostOwnedLayer, syncRecoveryPopover } from "/src/services/host-owned-layer.ts";
|
||||
|
||||
const NativeResizeObserver = window.ResizeObserver;
|
||||
const observedTargets = new Set();
|
||||
let resizeCallbacks = 0;
|
||||
window.ResizeObserver = class extends NativeResizeObserver {
|
||||
constructor(callback) {
|
||||
super((entries, observer) => {
|
||||
resizeCallbacks += 1;
|
||||
callback(entries, observer);
|
||||
});
|
||||
}
|
||||
observe(target) {
|
||||
observedTargets.add(target);
|
||||
super.observe(target);
|
||||
}
|
||||
unobserve(target) {
|
||||
observedTargets.delete(target);
|
||||
super.unobserve(target);
|
||||
}
|
||||
disconnect() {
|
||||
observedTargets.clear();
|
||||
super.disconnect();
|
||||
}
|
||||
};
|
||||
const observedIds = () => [...observedTargets]
|
||||
.map((target) => target.id || target.getAttribute("data-ws-part") || target.tagName.toLowerCase());
|
||||
const nativeRequestAnimationFrame = window.requestAnimationFrame.bind(window);
|
||||
let frameCallbacks = 0;
|
||||
window.requestAnimationFrame = (callback) => nativeRequestAnimationFrame((time) => {
|
||||
frameCallbacks += 1;
|
||||
callback(time);
|
||||
});
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const output = document.getElementById("result");
|
||||
|
||||
try {
|
||||
const layer = createHostOwnedLayer("recovery", `
|
||||
.toolbar { position: fixed; pointer-events: auto; min-width: 160px; min-height: 28px; }
|
||||
.toolbar:popover-open { display: flex; }
|
||||
.toolbar button { min-width: 120px; min-height: 28px; }
|
||||
`);
|
||||
if (!layer) throw new Error("recovery layer was not created");
|
||||
const control = document.createElement("div");
|
||||
control.id = "measurement-toolbar";
|
||||
control.className = "toolbar";
|
||||
control.popover = "manual";
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.textContent = "Use built-in skin";
|
||||
control.append(button);
|
||||
layer.container.append(control);
|
||||
const modeChanges = [];
|
||||
let toolbarVisible = true;
|
||||
let lastMode = "floating";
|
||||
const binding = bindHostSlot({
|
||||
layer,
|
||||
control,
|
||||
anchor: "skin.home.header.part-host-actions",
|
||||
skinId: "community.observer-fixture",
|
||||
presentation: "toolbar",
|
||||
prepare: () => syncRecoveryPopover(control, true),
|
||||
settle: (slotted) => { if (!slotted || !toolbarVisible) syncRecoveryPopover(control, false); },
|
||||
onModeChange: (change) => { modeChanges.push(change); lastMode = change.mode; },
|
||||
});
|
||||
await sleep(120);
|
||||
const initial = {
|
||||
mode: modeChanges.at(-1)?.mode ?? null,
|
||||
reason: modeChanges.at(-1)?.reason ?? null,
|
||||
open: control.matches(":popover-open"),
|
||||
width: control.getBoundingClientRect().width,
|
||||
height: control.getBoundingClientRect().height,
|
||||
observed: observedIds(),
|
||||
};
|
||||
|
||||
resizeCallbacks = 0;
|
||||
frameCallbacks = 0;
|
||||
modeChanges.length = 0;
|
||||
toolbarVisible = false;
|
||||
binding.revalidate();
|
||||
await sleep(600);
|
||||
const whileDockedButHidden = {
|
||||
mode: lastMode,
|
||||
open: control.matches(":popover-open"),
|
||||
resizeCallbacks,
|
||||
frameCallbacks,
|
||||
observed: observedIds(),
|
||||
};
|
||||
|
||||
resizeCallbacks = 0;
|
||||
frameCallbacks = 0;
|
||||
modeChanges.length = 0;
|
||||
document.getElementById("anchor").remove();
|
||||
binding.revalidate();
|
||||
await sleep(600);
|
||||
const afterAnchorRemoved = {
|
||||
mode: modeChanges.at(-1)?.mode ?? null,
|
||||
reason: modeChanges.at(-1)?.reason ?? null,
|
||||
open: control.matches(":popover-open"),
|
||||
display: getComputedStyle(control).display,
|
||||
resizeCallbacks,
|
||||
frameCallbacks,
|
||||
modeChanges: modeChanges.length,
|
||||
observed: observedIds(),
|
||||
};
|
||||
binding.dispose();
|
||||
output.textContent = JSON.stringify({ initial, whileDockedButHidden, afterAnchorRemoved });
|
||||
} catch (error) {
|
||||
output.textContent = JSON.stringify({ error: String(error?.stack ?? error) });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user