mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skin): match Classic toolbar icon buttons for host recovery
Add slot appearance "icon" and "icon-and-label", allow an explicit 22px toolbar height, preserve transparent backgrounds, and introduce hover, surface, gap, and icon-size tokens so host-owned recovery and library buttons can match the Classic microphone control. Shortcut and failed- anchor fallbacks stay full label capsules. Update the example skin, docs, and tests, including a Classic toolbar fixture.
This commit is contained in:
1 parent
4131d9c319
commit
df826f575e
18 files changed
+805
-160
No files matched your search
@@ -86,6 +86,9 @@ export type SkinChromeSlotAlign = "start" | "center" | "end";
|
||||
*/
|
||||
export type SkinChromeSlotMode = "capsule" | "toolbar";
|
||||
|
||||
/** Toolbar buttons may show host-owned icons without losing their accessible names. */
|
||||
export type SkinChromeSlotAppearance = "label" | "icon" | "icon-and-label";
|
||||
|
||||
/** One anchor name, or ordered candidates (for example one per page). */
|
||||
export type SkinChromeSlotAnchor = string | string[];
|
||||
|
||||
@@ -102,6 +105,8 @@ export interface SkinChromeSlot {
|
||||
compact: boolean;
|
||||
/** Explicit presentation; see `SkinChromeSlotMode`. */
|
||||
mode: SkinChromeSlotMode;
|
||||
/** Toolbar-only label/icon shape; the host always supplies the icon and name. */
|
||||
appearance: SkinChromeSlotAppearance;
|
||||
}
|
||||
|
||||
export interface SkinChromeAssetInfo {
|
||||
@@ -196,6 +201,10 @@ function isSlotAlign(value: unknown): value is SkinChromeSlotAlign {
|
||||
return value === "start" || value === "center" || value === "end";
|
||||
}
|
||||
|
||||
function isSlotAppearance(value: unknown): value is SkinChromeSlotAppearance {
|
||||
return value === "label" || value === "icon" || value === "icon-and-label";
|
||||
}
|
||||
|
||||
export function parseSkinChromeDocument(source: string): SkinChromeDocument {
|
||||
const bytes = new TextEncoder().encode(source).byteLength;
|
||||
if (!bytes || bytes > SKIN_CHROME_MAX_BYTES) {
|
||||
@@ -271,7 +280,7 @@ export function parseSkinChromeDocument(source: string): SkinChromeDocument {
|
||||
return reject(`Slot ${part} must be an object.`, "SKIN_CHROME_SLOT_INVALID");
|
||||
}
|
||||
for (const key of Object.keys(value)) {
|
||||
if (key !== "anchor" && key !== "align" && key !== "compact" && key !== "mode") {
|
||||
if (key !== "anchor" && key !== "align" && key !== "compact" && key !== "mode" && key !== "appearance") {
|
||||
return reject(`Slot ${part} contains an unsupported field: ${key}.`, "SKIN_CHROME_SLOT_INVALID");
|
||||
}
|
||||
}
|
||||
@@ -299,7 +308,14 @@ export function parseSkinChromeDocument(source: string): SkinChromeDocument {
|
||||
if (mode === "toolbar" && compact) {
|
||||
return reject(`Slot ${part} compact is only valid in capsule mode.`, "SKIN_CHROME_SLOT_INVALID");
|
||||
}
|
||||
slots[part] = { anchor, align, compact, mode };
|
||||
const appearance = value.appearance === undefined ? "label" : value.appearance;
|
||||
if (!isSlotAppearance(appearance)) {
|
||||
return reject(`Slot ${part} has an invalid appearance value: ${String(appearance)}.`, "SKIN_CHROME_SLOT_INVALID");
|
||||
}
|
||||
if (mode !== "toolbar" && appearance !== "label") {
|
||||
return reject(`Slot ${part} appearance is only available in toolbar mode.`, "SKIN_CHROME_SLOT_INVALID");
|
||||
}
|
||||
slots[part] = { anchor, align, compact, mode, appearance };
|
||||
}
|
||||
const perAction = slots["host.recovery.built-in"] !== undefined || slots["host.recovery.library"] !== undefined;
|
||||
if (slots["host.recovery"] && perAction) {
|
||||
|
||||
@@ -209,7 +209,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", (
|
||||
const explicit = parseSkinChromeDocument(JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
slots: {
|
||||
"host.recovery": { anchor: "voice.audio-dock", align: "start", compact: true },
|
||||
"host.recovery": { anchor: "voice.audio-dock", align: "start", compact: true, appearance: "label" },
|
||||
},
|
||||
}));
|
||||
assert.deepEqual(explicit.slots?.["host.recovery"], {
|
||||
@@ -217,6 +217,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", (
|
||||
align: "start",
|
||||
compact: true,
|
||||
mode: "capsule",
|
||||
appearance: "label",
|
||||
});
|
||||
|
||||
// Old slots without `mode` keep the docked capsule: the presentation is
|
||||
@@ -232,6 +233,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", (
|
||||
align: "end",
|
||||
compact: false,
|
||||
mode: "capsule",
|
||||
appearance: "label",
|
||||
});
|
||||
assert.doesNotThrow(() => parseSkinChromeDocument(JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
@@ -256,6 +258,9 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", (
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "Voice Audio Dock" } } }, /not a valid part name/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "" } } }, /at most 240 characters/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "float" } } }, /invalid mode/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "toolbar", appearance: "text" } } }, /invalid appearance/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", appearance: "icon" } } }, /appearance is only available in toolbar mode/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "capsule", appearance: "icon-and-label" } } }, /appearance is only available in toolbar mode/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "toolbar", compact: true } } }, /compact is only valid in capsule mode/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery.built-in": { anchor: "voice.audio-dock", mode: "capsule" } } }, /only supports toolbar mode/],
|
||||
[{ schemaVersion: 1, slots: { "host.recovery.built-in": { anchor: "voice.audio-dock", compact: true } } }, /compact is only valid in capsule mode/],
|
||||
@@ -277,6 +282,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt
|
||||
"skin.home.topbar.part-host-actions",
|
||||
],
|
||||
align: "end",
|
||||
appearance: "icon",
|
||||
},
|
||||
},
|
||||
}));
|
||||
@@ -288,6 +294,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt
|
||||
align: "end",
|
||||
compact: false,
|
||||
mode: "toolbar",
|
||||
appearance: "icon",
|
||||
});
|
||||
|
||||
const perAction = parseSkinChromeDocument(JSON.stringify({
|
||||
@@ -297,6 +304,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt
|
||||
mode: "toolbar",
|
||||
anchor: "skin.voice.topbar.part-built-in",
|
||||
align: "start",
|
||||
appearance: "icon-and-label",
|
||||
},
|
||||
"host.recovery.library": {
|
||||
mode: "toolbar",
|
||||
@@ -309,10 +317,12 @@ test("chrome.json toolbar slots support page candidates and separate action butt
|
||||
align: "start",
|
||||
compact: false,
|
||||
mode: "toolbar",
|
||||
appearance: "icon-and-label",
|
||||
});
|
||||
// Single-action slots are toolbar-only and default to toolbar mode.
|
||||
assert.equal(perAction.slots?.["host.recovery.library"]?.mode, "toolbar");
|
||||
assert.equal(perAction.slots?.["host.recovery.library"]?.align, "end");
|
||||
assert.equal(perAction.slots?.["host.recovery.library"]?.appearance, "label");
|
||||
|
||||
const invalidDocuments: Array<[unknown, RegExp]> = [
|
||||
[{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: [] } } }, /between 1 and 8/],
|
||||
|
||||
Reference in new issue
Block a user