mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix: harden floating host-control avoidance after review
Independent review of 16e25ea (DeepSeek v4.1 Flash, Qwen4 Max) found the runtime avoidance could flap, park on protected controls and drift from the CSS on notched phones. Runtime only; still no skin.css restriction. - Anti-flap: a move needs the collision to persist ~250 ms, moves are at least 1 s apart, and more than 6 moves in 10 s park the control at its default corner for 10 s (an animated/hostile skin can no longer keep it moving). - Protected parts now outweigh dialogs and the other host control; ordinary buttons inside the protected `app` root (or `home.footer`) are no longer weighted as protected. - Never move onto the last pointer position or the focused control. - Fold to the compact mark only when that frees at least one control (a full-screen click-away layer no longer hides the recovery buttons). - Score with the live expanded size (language switch) and reset on resize; model margins include env(safe-area-inset-*) like the CSS. - Skip invisible (opacity 0) controls; also count [tabindex], option/switch/ checkbox/radio roles, iframes and media controls; count the other host control once; prefilter by candidate rects (cheap on 3 000-control skins); re-check after scrolls; ignore sticky :hover on touch; bind idempotently. - Tests: weights, fold threshold, pointer, safe area, protected-vs-dialog, stability over repeated ticks, two host controls, anti-flap.
This commit is contained in:
1 parent
e46d7a0eb7
commit
2b019d82ff
7 files changed
+391
-42
No files matched your search
@@ -251,6 +251,9 @@ const compactPinned = ref(false);
|
||||
const floatPosition = ref<FloatingPosition>("bottom-left");
|
||||
const floatCompact = ref(false);
|
||||
let floatingAvoidance: FloatingAvoidance | undefined;
|
||||
let floatingElement: HTMLElement | null = null;
|
||||
/** Sticky `:hover` after a tap on touch screens must not pause avoidance. */
|
||||
const canHover = () => typeof matchMedia === "function" && matchMedia("(hover: hover)").matches;
|
||||
|
||||
const compact = computed(() => !shortcutExpanded.value
|
||||
&& !compactPinned.value
|
||||
@@ -301,15 +304,26 @@ function syncSlotBinding() {
|
||||
}
|
||||
|
||||
function bindFloating() {
|
||||
const control = recoveryPopover.value;
|
||||
// Idempotent: called on mount and whenever the popover element appears.
|
||||
if (floatingAvoidance && floatingElement === control) return;
|
||||
floatingAvoidance?.dispose();
|
||||
floatingAvoidance = undefined;
|
||||
const control = recoveryPopover.value;
|
||||
floatingElement = null;
|
||||
if (!control || !layer) return;
|
||||
const host = layer.host;
|
||||
floatingElement = control;
|
||||
floatingAvoidance = bindFloatingAvoidance({
|
||||
element: control,
|
||||
isSelf: node => node === host || host.contains(node),
|
||||
margins: { top: 12, right: 12, bottom: 38, left: 12 },
|
||||
// Same numbers as RECOVERY_LAYER_CSS, including env(safe-area-inset-*).
|
||||
margins: insets => ({
|
||||
top: Math.max(12, insets.top),
|
||||
right: Math.max(12, insets.right),
|
||||
bottom: 38 + insets.bottom,
|
||||
left: Math.max(12, insets.left),
|
||||
}),
|
||||
insetsParent: layer.shadow,
|
||||
defaultPosition: "bottom-left",
|
||||
apply: next => { floatPosition.value = next; },
|
||||
compactSize: () => {
|
||||
@@ -322,7 +336,7 @@ function bindFloating() {
|
||||
paused: () => slotMode.value === "slotted"
|
||||
|| shortcutExpanded.value
|
||||
|| compactPinned.value
|
||||
|| control.matches(":hover")
|
||||
|| (canHover() && control.matches(":hover"))
|
||||
|| Boolean(layer.shadow.activeElement),
|
||||
});
|
||||
}
|
||||
@@ -366,6 +380,7 @@ watch([recoveryVisible, recoveryPopover], () => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
slotBinding?.revalidate();
|
||||
bindFloating();
|
||||
floatingAvoidance?.revalidate();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
@@ -397,6 +412,8 @@ onBeforeUnmount(() => {
|
||||
if (compactHoldTimer) clearTimeout(compactHoldTimer);
|
||||
slotBinding?.dispose();
|
||||
floatingAvoidance?.dispose();
|
||||
floatingAvoidance = undefined;
|
||||
floatingElement = null;
|
||||
recoveryTheme?.dispose();
|
||||
window.removeEventListener("resize", refreshLauncherReachability);
|
||||
window.removeEventListener("keydown", onKeydown, true);
|
||||
|
||||
Reference in new issue
Block a user