mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(kaak): match device picker geometry
This commit is contained in:
1 parent
c29109e898
commit
0453bc6d4a
12 files changed
+110
-41
No files matched your search
@@ -30,6 +30,7 @@
|
||||
<Transition name="settings-select-menu">
|
||||
<ul
|
||||
v-if="open"
|
||||
ref="menu"
|
||||
:id="listboxId"
|
||||
class="settings-select-menu"
|
||||
role="listbox"
|
||||
@@ -76,6 +77,7 @@ const emit = defineEmits<{ change: [value: string] }>();
|
||||
|
||||
const root = ref<HTMLElement | null>(null);
|
||||
const trigger = ref<HTMLButtonElement | null>(null);
|
||||
const menu = ref<HTMLUListElement | null>(null);
|
||||
const open = ref(false);
|
||||
const activeIndex = ref(-1);
|
||||
const menuStyle = ref<CSSProperties>({});
|
||||
@@ -91,9 +93,13 @@ function optionId(index: number): string {
|
||||
|
||||
function updateMenuPosition(): void {
|
||||
const rect = trigger.value?.getBoundingClientRect();
|
||||
if (!rect || typeof window === "undefined") return;
|
||||
const menuElement = menu.value;
|
||||
if (!rect || !menuElement || typeof window === "undefined") return;
|
||||
|
||||
const placement = placeAudioDeviceMenu(rect, { width: window.innerWidth, height: window.innerHeight }, props.options.length);
|
||||
const computedStyle = window.getComputedStyle(menuElement);
|
||||
const borderHeight = Number.parseFloat(computedStyle.borderTopWidth || "0") + Number.parseFloat(computedStyle.borderBottomWidth || "0");
|
||||
const naturalMenuHeight = menuElement.scrollHeight + (Number.isFinite(borderHeight) ? borderHeight : 0);
|
||||
const placement = placeAudioDeviceMenu(rect, { width: window.innerWidth, height: window.innerHeight }, naturalMenuHeight);
|
||||
|
||||
menuStyle.value = {
|
||||
top: `${placement.top}px`,
|
||||
|
||||
@@ -4,14 +4,14 @@ import { placeAudioDeviceMenu } from "./audio-device-menu-placement.js";
|
||||
|
||||
test("device menu opens below the trigger and keeps the 240px cap", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 80, bottom: 120, left: 40, width: 280 }, { width: 1280, height: 720 }, 20),
|
||||
placeAudioDeviceMenu({ top: 80, bottom: 120, left: 40, width: 280 }, { width: 1280, height: 720 }, 320),
|
||||
{ top: 124, left: 40, width: 280, maxHeight: 240 },
|
||||
);
|
||||
});
|
||||
|
||||
test("device menu opens above when the bottom edge cannot fit the list", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 600, bottom: 640, left: 80, width: 300 }, { width: 1280, height: 700 }, 20),
|
||||
placeAudioDeviceMenu({ top: 600, bottom: 640, left: 80, width: 300 }, { width: 1280, height: 700 }, 320),
|
||||
{ top: 356, left: 80, width: 300, maxHeight: 240 },
|
||||
);
|
||||
});
|
||||
@@ -20,7 +20,7 @@ test("device menu shrinks to the remaining space in a short viewport", () => {
|
||||
const placement = placeAudioDeviceMenu(
|
||||
{ top: 40, bottom: 60, left: 8, width: 180 },
|
||||
{ width: 320, height: 84 },
|
||||
8,
|
||||
320,
|
||||
);
|
||||
|
||||
assert.deepEqual(placement, { top: 8, left: 8, width: 180, maxHeight: 28 });
|
||||
@@ -29,7 +29,14 @@ test("device menu shrinks to the remaining space in a short viewport", () => {
|
||||
|
||||
test("device menu width stays inside narrow viewport bounds", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 20, bottom: 40, left: 120, width: 220 }, { width: 200, height: 400 }, 4),
|
||||
{ top: 44, left: 8, width: 184, maxHeight: 136 },
|
||||
placeAudioDeviceMenu({ top: 20, bottom: 40, left: 120, width: 220 }, { width: 200, height: 400 }, 150),
|
||||
{ top: 44, left: 8, width: 184, maxHeight: 150 },
|
||||
);
|
||||
});
|
||||
|
||||
test("device menu preserves the skin-defined natural height for short lists", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 80, bottom: 120, left: 40, width: 280 }, { width: 1280, height: 720 }, 84),
|
||||
{ top: 124, left: 40, width: 280, maxHeight: 84 },
|
||||
);
|
||||
});
|
||||
@@ -14,19 +14,17 @@ export interface AudioDeviceMenuPlacement {
|
||||
|
||||
const VIEWPORT_INSET = 8;
|
||||
const MENU_GAP = 4;
|
||||
const OPTION_HEIGHT = 32;
|
||||
const MENU_PADDING = 8;
|
||||
const MAX_MENU_HEIGHT = 240;
|
||||
|
||||
export function placeAudioDeviceMenu(
|
||||
anchor: AudioDeviceMenuAnchor,
|
||||
viewport: { width: number; height: number },
|
||||
optionCount: number,
|
||||
naturalMenuHeight: number,
|
||||
): AudioDeviceMenuPlacement {
|
||||
const insetX = Math.min(VIEWPORT_INSET, Math.max(0, viewport.width / 2));
|
||||
const width = Math.min(Math.max(0, anchor.width), Math.max(0, viewport.width - insetX * 2));
|
||||
const left = Math.max(insetX, Math.min(anchor.left, viewport.width - insetX - width));
|
||||
const fullHeight = Math.min(MAX_MENU_HEIGHT, Math.max(0, optionCount) * OPTION_HEIGHT + MENU_PADDING);
|
||||
const fullHeight = Math.min(MAX_MENU_HEIGHT, Number.isFinite(naturalMenuHeight) ? Math.max(0, naturalMenuHeight) : 0);
|
||||
const below = Math.max(0, viewport.height - VIEWPORT_INSET - anchor.bottom - MENU_GAP);
|
||||
const above = Math.max(0, anchor.top - VIEWPORT_INSET - MENU_GAP);
|
||||
const opensAbove = below < fullHeight && above > below;
|
||||
|
||||
@@ -46,7 +46,7 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
|
||||
{
|
||||
id: BUILTIN_KAAK_SKIN_ID,
|
||||
name: "KAAK",
|
||||
version: "3.1.39",
|
||||
version: "3.1.40",
|
||||
author: "WebSpeak Project",
|
||||
license: "AGPL-3.0-only",
|
||||
description: "A KOOK-inspired voice-room workspace with collapsible voice groups, current voice-channel chat, TeamSpeak profile cards, and accessible host-owned voice controls.",
|
||||
|
||||
@@ -464,7 +464,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
|
||||
const skin = await importSkinPack(file);
|
||||
assert.equal(skin.id, "community.kaak-voice");
|
||||
assert.equal(skin.version, "3.1.39");
|
||||
assert.equal(skin.version, "3.1.40");
|
||||
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
const home = skin.pluginData?.components.find((component) => component.page === "home");
|
||||
@@ -552,11 +552,18 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.match(skin.css, /@keyframes ws-community-kaak-voice-kaak-channel-join-hint/);
|
||||
assert.match(skin.css, /--skin-kaak-font:[\s\S]*?PingFang SC/);
|
||||
assert.match(skin.css, /\[data-ws-plugin-part="kaak-home"\] \{[^}]*font-family: var\(--skin-kaak-font\);/);
|
||||
assert.match(skin.css, /settings-select-menu[\s\S]*?background: #35373d/);
|
||||
assert.match(skin.css, /settings-select-menu[\s\S]*?background: #25262a/);
|
||||
assert.match(skin.css, /settings-select-option[\s\S]*?min-height: 32px/);
|
||||
assert.match(skin.css, /settings-header h2 \{\s*color: #f2f3f5;\s*font-size: 32px;\s*font-weight: 600;/);
|
||||
assert.match(skin.css, /settings-section h3 \{\s*color: #eceef0;\s*font-size: 16px;\s*font-weight: 600;/);
|
||||
assert.match(skin.css, /voice\.audio-settings"] \.settings-label \{\s*font-weight: 400;/);
|
||||
assert.match(skin.css, /voice\.audio-settings"] \.settings-select \{[\s\S]*?border-radius: 12px;/);
|
||||
assert.match(skin.css, /settings-select:hover:not\(:disabled\) \{\s*border-color: #6cbf00;/);
|
||||
assert.match(skin.css, /voice\.audio-settings"] \.settings-select-menu \{[\s\S]*?padding: 8px;[\s\S]*?border-radius: 12px;[\s\S]*?background: #25262a;[\s\S]*?box-shadow: 0 2px 8px rgba\(0, 0, 0, \.32\);/);
|
||||
assert.match(skin.css, /settings-select:focus-visible \{\s*border-color: #6cbf00;\s*box-shadow: 0 0 0 3px #6cbf001a;/);
|
||||
assert.match(skin.css, /voice\.audio-settings"] \.settings-select-option \{[\s\S]*?height: 32px;[\s\S]*?margin-bottom: 2px;[\s\S]*?padding-inline: 8px;[\s\S]*?border-radius: 8px;/);
|
||||
assert.match(skin.css, /settings-select\[aria-expanded="true"\] \.settings-select-chevron::before \{\s*transform: rotate\(225deg\);/);
|
||||
assert.match(skin.css, /settings-select-option:hover \{ background: #ffffff0f; \}/);
|
||||
assert.match(skin.css, /voice\.audio-settings\"] \.settings-range::-webkit-slider-thumb \{\s*width: 16px;\s*height: 16px;\s*margin-top: -6px;/);
|
||||
assert.match(skin.css, /voice\.audio-settings\"] \.settings-range::-moz-range-thumb \{\s*width: 16px;\s*height: 16px;/);
|
||||
assert.match(skin.css, /voice-performance-panel-enter-active[\s\S]*?transition: opacity \.16s/);
|
||||
|
||||
Reference in new issue
Block a user