mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02: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
+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