feat: refine KAAK navigation and join experience

This commit is contained in:
illusia committed 2026-10-12 13:49:35 +08:00
1 parent 319a16f384
commit 458f95c2dc
21 files changed
+2017 -996

No files matched your search

+1
View File
@@ -200,6 +200,7 @@ const PUBLIC_PART_IDS = new Set<string>([
"voice.channel-tree.member-away",
"voice.channel-tree.member-muted",
"voice.channel-tree.member-name",
"voice.channel-tree.member-screen-share",
"voice.channel-tree.member-speaking",
"voice.channel-tree.name",
"voice.channel-tree.node",
+68 -12
View File
@@ -1,12 +1,13 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
parseSkinPluginDocument,
parseSkinPluginJson,
type SkinPluginDocument,
type SkinPluginNode,
} from "./skin-plugin.js";
import {
parseSkinPluginDocument,
parseSkinPluginJson,
skinPluginWidgetPermissions,
type SkinPluginDocument,
type SkinPluginNode,
} from "./skin-plugin.js";
function validDocument(): SkinPluginDocument {
return {
@@ -182,6 +183,52 @@ test("server banner host widget only exposes public session status fields", () =
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].root.children?.[0].widget, "voice.server-banner");
});
test("home connection status widget requires the public session status permission", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].page = "home";
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ widget: "home.connection-status" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["session.status.read"];
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].widget, "home.connection-status");
assert.deepEqual(skinPluginWidgetPermissions("home.connection-status"), ["session.status.read"]);
});
test("MyTS login is a host button with no connection permission or skin action", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].page = "home";
document.components[0].permissions = [];
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ widget: "home.myts-login" }] };
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].root.children?.[0].widget, "home.myts-login");
assert.deepEqual(skinPluginWidgetPermissions("home.myts-login"), []);
assert.deepEqual(Object.keys(parsed.components[0].actions), []);
});
test("skin SVG illustrations support bounded path and circle geometry attributes", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].root = {
tag: "svg",
attributes: { viewbox: "0 0 100 100", role: "img" },
children: [
{ tag: "circle", attributes: { cx: 25, cy: 30, r: 12, fill: "#b0f49b" } },
{ tag: "path", attributes: { d: "M10 20h30v40", stroke: "white", "stroke-width": 2, fill: "none" } },
],
};
const parsed = parseSkinPluginDocument(document).components[0].root;
assert.equal(parsed.children?.[0].attributes?.cx, 25);
assert.equal(parsed.children?.[1].attributes?.d, "M10 20h30v40");
document.components[0].root.children![1].attributes!.d = "x".repeat(513);
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
});
test("schema v3 host audio controls require read and control permissions while v2 remains compatible", () => {
const document = validDocument();
@@ -379,12 +426,21 @@ test("KAAK v3 example declares the connection home and complete voice workspace"
const parsed = parseSkinPluginJson(source);
const home = parsed.components.find((component) => component.id === "kaak-home");
const workspace = parsed.components.find((component) => component.id === "kaak-workspace");
assert.ok(home);
assert.ok(workspace);
assert.equal(home.page, "home");
assert.equal(home.mode, "surface");
assert.deepEqual(home.permissions, ["ui.surface.replace"]);
assert.equal(home.root.children?.[1].children?.[3].widget, "home.connection-form");
assert.ok(home);
assert.ok(workspace);
assert.equal(home.page, "home");
assert.equal(home.mode, "surface");
assert.deepEqual(home.permissions, ["ui.surface.replace", "session.status.read"]);
const connectionCard = home.root.children?.[1].children?.[0].children?.[1];
assert.equal(connectionCard?.part, "connection-card");
assert.equal(connectionCard?.children?.[0].part, "card-heading");
assert.equal(connectionCard?.children?.[0].children?.[0].part, "connection-title");
assert.equal(connectionCard?.children?.[0].children?.[1].widget, "home.myts-login");
assert.equal(connectionCard?.children?.[2].widget, "home.connection-form");
assert.equal(connectionCard?.children?.[4].widget, "home.connection-status");
const heroMedia = home.root.children?.[0].children?.[2];
assert.equal(heroMedia?.part, "hero-media");
assert.equal(heroMedia?.children?.[0].tag, "svg");
assert.equal(workspace.page, "voice");
assert.equal(workspace.mode, "surface");
+10 -7
View File
@@ -40,8 +40,10 @@ export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({
export type SkinPluginPermission = keyof typeof SKIN_PLUGIN_PERMISSIONS;
export type SkinPluginPage = "home" | "voice" | "demo";
export type SkinPluginComponentMode = "widget" | "surface";
export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([
"home.connection-form",
export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([
"home.connection-form",
"home.connection-status",
"home.myts-login",
"app.skin-switcher",
"app.language-switcher",
"voice.server-switcher",
@@ -72,6 +74,7 @@ export interface SkinPluginWidgetOptions {
}
const widgetPermissions = (...permissions: SkinPluginPermission[]): readonly SkinPluginPermission[] => Object.freeze(permissions);
export const SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS: Partial<Record<SkinPluginHostWidget, readonly SkinPluginPermission[]>> = Object.freeze({
"home.connection-status": widgetPermissions("session.status.read"),
"voice.channel-tree": widgetPermissions("session.channels.read", "session.members.read", "session.memberAvatars.read", "session.channel.join"),
"voice.server-switcher": widgetPermissions("servers.quickList.read", "servers.quickList.switch"),
"voice.server-header": widgetPermissions("session.status.read", "servers.quickList.read", "servers.quickList.switch"),
@@ -175,11 +178,11 @@ export const SKIN_PLUGIN_ALLOWED_ELEMENTS = Object.freeze([
] as const);
const ELEMENTS = new Set<string>(SKIN_PLUGIN_ALLOWED_ELEMENTS);
const VOID_ELEMENTS = new Set(["br", "circle", "hr", "img", "input", "line", "path", "polyline", "rect", "wbr"]);
const ATTRIBUTES = new Set([
"alt", "aria-current", "aria-expanded", "aria-hidden", "aria-label", "aria-pressed", "aria-selected", "autocomplete", "checked", "class", "colspan", "disabled", "draggable", "fill", "height", "inputmode", "max", "maxlength", "min",
"minlength", "multiple", "name", "open", "placeholder", "required", "role", "rows", "rowspan", "step", "stroke", "stroke-linecap", "stroke-linejoin",
"src", "stroke-width", "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2",
]);
const ATTRIBUTES = new Set([
"alt", "aria-current", "aria-expanded", "aria-hidden", "aria-label", "aria-pressed", "aria-selected", "autocomplete", "checked", "class", "colspan", "cx", "cy", "d", "disabled", "draggable", "fill", "height", "inputmode", "max", "maxlength", "min",
"minlength", "multiple", "name", "open", "placeholder", "required", "role", "rows", "rowspan", "step", "stroke", "stroke-linecap", "stroke-linejoin",
"r", "rx", "src", "stroke-width", "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2",
]);
const EVENTS = new Set<string>([
"click", "dblclick", "change", "input", "submit", "keydown", "keyup", "contextmenu", "focus", "blur", "pointerdown", "pointerup",
"pointerenter", "pointerleave", "dragstart", "dragover", "drop",