mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: add host chrome theming and a skin-proof recovery layer
Allow skins to theme host chrome through a second scope and explicit visibleParts. Official and built-in skins stay decoration-free by default. Harden the CSS compiler so skins cannot hide the document root, push protected controls off-screen, or target the host layer with sibling selectors. Move recovery and authorization UI into a closed Shadow DOM on the top layer, so a third-party skin cannot block the built-in skin reset.
This commit is contained in:
1 parent
33ba062686
commit
f8d61d22ef
45 files changed
+3535
-558
No files matched your search
@@ -8,7 +8,11 @@ import {
|
||||
SKIN_LAYOUT_COMPONENTS,
|
||||
validateSkinLayout,
|
||||
canEditSkinLayoutComponent,
|
||||
DECORATIVE_PART_IDS,
|
||||
HOST_PART_IDS,
|
||||
} from "./skin-layout.js";
|
||||
import { HOST_TRUSTED_PART_IDS } from "./skin-visual-parts.js";
|
||||
import { OPTIONAL_VISUAL_PARTS } from "./skin-css.js";
|
||||
|
||||
async function vueSources(directory: URL): Promise<string[]> {
|
||||
const files = (await readdir(directory, { recursive: true })).filter((file) => file.endsWith(".vue"));
|
||||
@@ -16,16 +20,20 @@ async function vueSources(directory: URL): Promise<string[]> {
|
||||
}
|
||||
|
||||
test("the stable layout registry covers public skin hooks and excludes the admin console", async () => {
|
||||
const [webClient, demo, sharedComponents, skinSwitcher, languageSwitcher, admin, adminComponents] = await Promise.all([
|
||||
const [webClient, demo, sharedComponents, skinSwitcher, languageSwitcher, hostChrome, pluginPanel, authorization, recoveryNotice, admin, adminComponents] = await Promise.all([
|
||||
readFile(new URL("../../web/src/views/WebClient.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/views/DemoView.vue", import.meta.url), "utf8"),
|
||||
vueSources(new URL("../../web/src/components/web-client/", import.meta.url)),
|
||||
readFile(new URL("../../web/src/components/SkinSwitcher.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/components/LanguageSwitcher.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/components/HostChrome.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/components/PluginPanel.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/components/InstanceAuthorization.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/components/SkinLoadRecoveryNotice.vue", import.meta.url), "utf8"),
|
||||
readFile(new URL("../../web/src/views/AdminView.vue", import.meta.url), "utf8"),
|
||||
vueSources(new URL("../../web/src/components/admin/", import.meta.url)),
|
||||
]);
|
||||
const publicSource = [webClient, demo, ...sharedComponents, skinSwitcher, languageSwitcher].join("\n");
|
||||
const publicSource = [webClient, demo, ...sharedComponents, skinSwitcher, languageSwitcher, hostChrome, pluginPanel, authorization, recoveryNotice].join("\n");
|
||||
const publicParts = new Set([...publicSource.matchAll(/data-ws-part="([^"]+)"/g)].map((match) => match[1]));
|
||||
const interactiveParts = new Set<string>();
|
||||
for (const match of publicSource.matchAll(/<[A-Za-z][\w.-]*\b[^>]*>/gs)) {
|
||||
@@ -35,17 +43,25 @@ test("the stable layout registry covers public skin hooks and excludes the admin
|
||||
const isNativeControl = /^<(?:button|a|input|select|textarea)\b/i.test(attributes);
|
||||
const hasButtonRole = /\brole="button"/.test(attributes);
|
||||
const keyboardAction = /@keydown\.(?:enter|space)\b/.test(attributes);
|
||||
// Native HTML drag gestures are desktop-only and do not make a row a 44px touch control.
|
||||
if (isNativeControl || hasButtonRole || keyboardAction) interactiveParts.add(part);
|
||||
// Native HTML drag gestures are desktop-only and do not make a row a 44px touch control.
|
||||
if (isNativeControl || hasButtonRole || keyboardAction) interactiveParts.add(part);
|
||||
}
|
||||
const registered = new Set(SKIN_LAYOUT_COMPONENTS.map((component) => component.selectorPart));
|
||||
for (const part of publicParts) assert.ok(registered.has(part), "Unregistered public layout hook: " + part);
|
||||
const micStatus = getSkinLayoutComponent("voice.member.mic-status", "voice");
|
||||
assert.equal(micStatus?.category, "core");
|
||||
assert.equal(micStatus?.editable, true);
|
||||
assert.ok(micStatus?.layoutModes.includes("visibility"));
|
||||
assert.equal(getSkinLayoutComponent("voice.server-banner", "voice")?.editable, true);
|
||||
for (const part of interactiveParts) {
|
||||
const registered = new Set(SKIN_LAYOUT_COMPONENTS.map((component) => component.selectorPart));
|
||||
for (const part of publicParts) assert.ok(registered.has(part), "Unregistered public layout hook: " + part);
|
||||
for (const part of HOST_PART_IDS) assert.ok(registered.has(part), "Unregistered host chrome hook: " + part);
|
||||
// The layout registry and the CSS hiding whitelist must never drift apart.
|
||||
assert.deepEqual([...DECORATIVE_PART_IDS].sort(), [...OPTIONAL_VISUAL_PARTS].sort());
|
||||
for (const part of HOST_TRUSTED_PART_IDS) {
|
||||
const component = getSkinLayoutComponent(part, "voice");
|
||||
assert.equal(component?.category, "trusted-chrome", "Trusted host entry must not be layout-editable: " + part);
|
||||
assert.equal(component?.editable, false);
|
||||
}
|
||||
const micStatus = getSkinLayoutComponent("voice.member.mic-status", "voice");
|
||||
assert.equal(micStatus?.category, "core");
|
||||
assert.equal(micStatus?.editable, true);
|
||||
assert.ok(micStatus?.layoutModes.includes("visibility"));
|
||||
assert.equal(getSkinLayoutComponent("voice.server-banner", "voice")?.editable, true);
|
||||
for (const part of interactiveParts) {
|
||||
const component = SKIN_LAYOUT_COMPONENTS.find((entry) => entry.id === part);
|
||||
assert.ok(component, "Interactive public hook must have its own component metadata: " + part);
|
||||
assert.ok(component.minTouchTarget >= 44, "Interactive public hook needs a 44px touch target: " + part);
|
||||
@@ -174,9 +190,9 @@ test("registered components carry accessibility, responsive, purpose, and data-s
|
||||
assert.ok(component.narrowScreenBehavior.length > 0);
|
||||
assert.ok(component.dataSensitivity.length > 0);
|
||||
}
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.connect")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.range")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.checkbox")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.connect")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.range")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.checkbox")?.minTouchTarget, 44);
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.feature")?.category, "optional");
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.security-note")?.category, "trusted-chrome");
|
||||
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.identity-import.security")?.dataSensitivity, "identity");
|
||||
|
||||
Reference in new issue
Block a user