feat(channels): render TeamSpeak spacers across skins

This commit is contained in:
illusia committed 2026-10-24 18:16:01 +08:00
1 parent 4bff2133b6
commit b9fccb8757
21 files changed
+240 -17

No files matched your search

@@ -60,16 +60,19 @@
<button
class="member-channel-heading"
data-ws-part="voice.channel-group.heading"
:data-spacer="getChannelSpacer(channelItem) ? 'true' : undefined"
:data-ws-state="channelItem.id === currentChannelId ? 'current' : 'idle'"
:title="t('switchChannel')"
@click="emit('selectChannel', channelItem)"
>
<Icon
v-if="!getChannelSpacer(channelItem)"
:name="channelItem.passwordProtected ? 'lock' : 'speaker'"
:size="16"
/>
<span>{{ channelItem.name }}</span>
<small>{{ channelItem.members.length }}</small>
<ChannelSpacer v-if="getChannelSpacer(channelItem)" :spacer="getChannelSpacer(channelItem)!" />
<span v-else>{{ channelItem.name }}</span>
<small v-if="!getChannelSpacer(channelItem)">{{ channelItem.members.length }}</small>
</button>
<div
v-if="channelItem.members.length"
@@ -170,7 +173,7 @@
</div>
</div>
<div
v-else
v-else-if="!getChannelSpacer(channelItem)"
class="channel-no-members"
>{{ t("noMembersInChannel") }}</div
>
@@ -188,6 +191,8 @@
<script setup lang="ts">
import type { CSSProperties } from "vue";
import Icon from "../Icon.vue";
import ChannelSpacer from "./ChannelSpacer.vue";
import { getChannelSpacer } from "../../../../src/shared/channel-spacer.js";
import { memberPresenceKey } from "../../services/member-presence.js";
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
import type { useWebClientMembers } from "../../composables/useWebClientMembers.js";
@@ -0,0 +1,60 @@
<template>
<span
class="ws-channel-spacer"
data-ws-part="voice.channel-spacer"
:data-alignment="spacer.alignment"
:data-spacer-style="spacer.style"
:aria-label="spacer.text || undefined"
><span :aria-hidden="spacer.alignment === 'repeat' || spacer.style !== 'text' ? 'true' : undefined">{{ displayText }}</span></span>
</template>
<script setup lang="ts">
import { computed } from "vue";
import type { ChannelSpacer } from "../../../../src/shared/channel-spacer.js";
const props = defineProps<{ spacer: ChannelSpacer }>();
const displayText = computed(() => {
if (props.spacer.style !== "text") return "";
const text = props.spacer.text;
// Clip a bounded run in CSS rather than measuring DOM or growing with viewport width.
return props.spacer.alignment === "repeat" && text
? text.repeat(Math.max(1, Math.floor(1024 / text.length)))
: text;
});
</script>
<style scoped>
.ws-channel-spacer {
display: block;
flex: 1 1 0;
min-width: 0;
width: 100%;
min-height: 1.3em;
overflow: hidden;
color: inherit;
font: inherit;
line-height: 1.3;
text-align: left;
}
.ws-channel-spacer > span { white-space: pre; }
.ws-channel-spacer[data-alignment="center"] { text-align: center; }
.ws-channel-spacer[data-alignment="right"] { text-align: right; }
.ws-channel-spacer:where(:not([data-spacer-style="text"]))::before {
content: "";
display: block;
margin-block: .6em;
border-top: 1px solid currentColor;
opacity: .55;
}
.ws-channel-spacer[data-spacer-style="dashed"]::before { border-top-style: dashed; }
.ws-channel-spacer[data-spacer-style="dotted"]::before { border-top-style: dotted; }
.ws-channel-spacer[data-spacer-style="dash-dot"]::before,
.ws-channel-spacer[data-spacer-style="dash-dot-dot"]::before {
height: 1px;
border: 0;
background: repeating-linear-gradient(to right, currentColor 0 6px, transparent 6px 9px, currentColor 9px 11px, transparent 11px 14px);
}
.ws-channel-spacer[data-spacer-style="dash-dot-dot"]::before {
background: repeating-linear-gradient(to right, currentColor 0 6px, transparent 6px 9px, currentColor 9px 11px, transparent 11px 14px, currentColor 14px 16px, transparent 16px 19px);
}
</style>
@@ -16,7 +16,7 @@
type="button"
class="ws-voice-channel-expander"
data-ws-part="voice.channel-tree.expander"
:aria-label="`${expanded ? '收起' : '展开'} ${node.channel.name} / ${expanded ? 'Collapse' : 'Expand'} channel`"
:aria-label="`${expanded ? '收起' : '展开'} ${displayName} / ${expanded ? 'Collapse' : 'Expand'} channel`"
:aria-expanded="expanded"
@click.stop="emit('toggle', node.channel.id)"
><Icon :name="expanded ? 'chevron-down' : 'chevron-right'" :size="13" /></button>
@@ -24,8 +24,9 @@
type="button"
class="ws-voice-channel-row"
data-ws-part="voice.channel-tree.row"
:data-spacer="spacer ? 'true' : undefined"
:data-drag-over="memberDragDrop && dragOverChannelId === node.channel.id ? 'true' : undefined"
:title="`双击或按 Enter 加入 ${node.channel.name} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`"
:title="`双击或按 Enter 加入 ${displayName} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`"
:data-password-protected="node.channel.passwordProtected ? 'true' : undefined"
@click="emit('select', node.channel.id)"
@dblclick.stop.prevent="join"
@@ -35,15 +36,17 @@
@drop="handleChannelDrop($event)"
>
<Icon
v-if="!spacer"
class="ws-voice-channel-type"
data-ws-part="voice.channel-tree.icon"
:name="node.channel.passwordProtected ? 'lock' : 'speaker'"
:data-password-protected="node.channel.passwordProtected ? 'true' : 'false'"
:size="14"
/>
<span class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
<span v-if="selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
<span class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
<ChannelSpacer v-if="spacer" :spacer="spacer" />
<span v-else class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
<span v-if="!spacer && selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
<span v-if="!spacer" class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
{{ memberCount }}<template v-if="node.channel.maxClientsLimited && typeof node.channel.maxClients === 'number'">/{{ node.channel.maxClients }}</template>
</span>
</button>
@@ -230,6 +233,8 @@
<script setup lang="ts">
import { computed, type CSSProperties } from "vue";
import Icon from "../Icon.vue";
import ChannelSpacer from "./ChannelSpacer.vue";
import { channelDisplayName, getChannelSpacer } from "../../../../src/shared/channel-spacer.js";
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
import type { VoiceChannelTreeNode } from "../../services/voice-channel-tree.js";
@@ -267,6 +272,8 @@ const emit = defineEmits<{
}>();
const expanded = computed(() => props.expandedIds.has(props.node.channel.id));
const spacer = computed(() => getChannelSpacer(props.node.channel));
const displayName = computed(() => channelDisplayName(props.node.channel));
const hasChildren = computed(() => props.node.children.length > 0);
const hasContents = computed(() => hasChildren.value || props.node.channel.members.length > 0);
const isExpandable = computed(() => props.layout === "server-sidebar" ? hasChildren.value : hasContents.value);
+2 -1
View File
@@ -1,5 +1,6 @@
import { computed, watch, type Ref } from "vue";
import type { ChannelInfo, ChannelMember } from "./useVoiceWebSocket.js";
import { channelDisplayName } from "../../../src/shared/channel-spacer.js";
export interface TreeChannel extends ChannelInfo {
depth: number;
@@ -108,7 +109,7 @@ export function useWebClientChannels({
if (fromSelf) return fromSelf;
return channelTree.value.find((item) => item.name === channelName.value) ?? channelTree.value[0];
});
const currentChannelName = computed(() => (currentChannel.value?.name ?? channelName.value) || t("voiceLobby"));
const currentChannelName = computed(() => (currentChannel.value ? channelDisplayName(currentChannel.value) : channelName.value) || t("voiceLobby"));
const currentChannelDescription = computed(() => currentChannel.value?.description ?? "");
const currentMembers = computed<ChannelMember[]>(() => {
const source = currentChannel.value ? currentChannel.value.members : members;
@@ -27,6 +27,19 @@ function surfaceDocument(): SkinPluginDocument {
};
}
test("declarative skins can read channel spacer presentation without new permissions", () => {
const document = {
schemaVersion: 3,
components: [{ id: "channel-labels", name: "Channel labels", page: "voice", accessibleName: "Channel labels", permissions: ["session.channels.read"], actions: {},
root: { tag: "div", repeat: { path: "session.channels", as: "channel" }, children: [
{ tag: "span", children: [{ text: "{{channel.displayName}} {{channel.spacerAlignment}} {{channel.spacerStyle}}" }], when: { path: "channel.isSpacer", equals: true } },
] },
}],
};
assert.doesNotThrow(() => parseSkinPluginDocument(document));
assert.throws(() => parseSkinPluginDocument({ ...document, components: [{ ...document.components[0], permissions: [] }] }));
});
test("page replacement stays disabled until local approval and returns to the host after revocation", () => {
const storage = new Map<string, string>();
const previousStorage = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
@@ -5,6 +5,34 @@ import type { ChannelMember } from "../composables/useVoiceWebSocket.js";
import { useWebClientMembers } from "../composables/useWebClientMembers.js";
import { buildVoiceChannelTree, filterVoiceChannelTree } from "./voice-channel-tree.js";
import { memberPresenceKey } from "./member-presence.js";
import { channelDisplayName, getChannelSpacer } from "../../../src/shared/channel-spacer.js";
test("TeamSpeak spacers require a leading marker on a permanent root channel", () => {
const channel = { name: "[cspacer0]🏔 后山 🏔", parentID: "0", isPermanent: true };
assert.deepEqual(getChannelSpacer(channel), { text: "🏔 后山 🏔", alignment: "center", style: "text" });
assert.equal(channelDisplayName(channel), "🏔 后山 🏔");
for (const ordinary of [
{ ...channel, isPermanent: false }, { ...channel, isPermanent: undefined }, { ...channel, parentID: "1" },
{ ...channel, name: "prefix [cspacer0]Title" }, { ...channel, name: "[cspacer0Title" },
{ ...channel, name: "[xspacer0]Title" }, { ...channel, name: "General" },
]) {
assert.equal(getChannelSpacer(ordinary), null);
assert.equal(channelDisplayName(ordinary), ordinary.name);
}
});
test("spacer display supports blank labels, arbitrary IDs, case, alignment and standard line patterns", () => {
const base = { parentID: "0", isPermanent: true };
for (const [name, alignment, text] of [
["[spacer]", "left", ""], ["[CSPACER0]", "center", ""],
["[lspacerstaff]Staff", "left", "Staff"], ["[rspacer42]Right", "right", "Right"],
["[*spacer0]★·", "repeat", "★·"], ["[cspacer1]A]B", "center", "A]B"],
["[cspacer]__proto__", "center", "__proto__"],
]) assert.deepEqual(getChannelSpacer({ ...base, name }), { text, alignment, style: "text" });
for (const [text, style] of [["___", "solid"], ["---", "dashed"], ["...", "dotted"], ["-.-", "dash-dot"], ["-..", "dash-dot-dot"]]) {
assert.deepEqual(getChannelSpacer({ ...base, name: `[*spacer0]${text}` }), { text, alignment: "repeat", style });
}
});
test("channel search keeps matching nested channels and only their ancestors", () => {
const tree = buildVoiceChannelTree([
+1 -1
View File
@@ -144,7 +144,7 @@ const skinPluginContext = computed(() => ({
skin: { locale: language.value, messages: skinMessages.value },
session: {
status: { connected: true, connecting: false, channelId: selectedChannel.value.id, channelName: selectedChannel.value.name, userName: "illusia" },
channels: channels.map((channel, depth) => ({ id: channel.id, name: channel.name, parentId: "", depth, memberCount: channel.members.length, current: channel.id === selectedChannel.value.id })),
channels: channels.map((channel, depth) => ({ id: channel.id, name: channel.name, displayName: channel.name, isSpacer: false, spacerAlignment: "", spacerStyle: "", parentId: "", depth, memberCount: channel.members.length, current: channel.id === selectedChannel.value.id })),
members: selectedChannel.value.members.map((member) => ({
id: member.id,
name: member.name,
+6
View File
@@ -972,6 +972,7 @@ import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
import VoiceChannelTree from "../components/web-client/VoiceChannelTree.vue";
import { channelDisplayName, getChannelSpacer } from "../../../src/shared/channel-spacer.js";
import VoiceServerSwitcher from "../components/web-client/VoiceServerSwitcher.vue";
import VoiceServerHeader from "../components/web-client/VoiceServerHeader.vue";
import VoiceServerBanner from "../components/web-client/VoiceServerBanner.vue";
@@ -1649,9 +1650,14 @@ const skinPluginContext = computed(() => ({
},
channels: channelTree.value.map((item) => {
const members = skinPluginMembers.value.filter((member) => member.channelId === item.id);
const spacer = getChannelSpacer(item);
return {
id: item.id,
name: item.name,
displayName: channelDisplayName(item),
isSpacer: Boolean(spacer),
spacerAlignment: spacer?.alignment ?? "",
spacerStyle: spacer?.style ?? "",
parentId: item.parentID,
depth: item.depth,
memberCount: item.members.length,