mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: let skins theme every protected control through skin.css and shared host tokens
App-DOM protected parts keep only hide/off-screen/disable guards; host-owned recovery capsule, skin-load banner and authorization dialog read one sanitized --skin-host-* token set with per-part overrides (--skin-recovery-*, --skin-load-recovery-*, --skin-permission-*) via the new host-control-tokens module.
This commit is contained in:
1 parent
93d221c3ef
commit
c1187d12d2
19 files changed
+1094
-422
No files matched your search
@@ -85,6 +85,11 @@ import {
|
||||
import { bindHostSlot, type HostSlotBinding } from "../services/host-slot-placement.js";
|
||||
import { shouldShowRecovery } from "../services/host-chrome-visibility.js";
|
||||
import { thirdPartyAllowed } from "../services/instance-authorization.js";
|
||||
import {
|
||||
RECOVERY_CONTROL_DEFAULTS,
|
||||
bindHostControlTheme,
|
||||
findSkinRoot,
|
||||
} from "../services/host-control-tokens.js";
|
||||
|
||||
const props = withDefaults(defineProps<{ language: SiteLanguage; connected?: boolean; pluginLibraryAvailable?: boolean }>(), { connected: false });
|
||||
const copy = computed(() => hostChromeCopy[props.language] ?? hostChromeCopy.en);
|
||||
@@ -102,12 +107,12 @@ const RECOVERY_LAYER_CSS = `
|
||||
gap: 4px;
|
||||
max-width: calc(100vw - 24px);
|
||||
padding: 4px 5px 4px 9px;
|
||||
border: 1px solid #9db6b2;
|
||||
border-radius: var(--ws-recovery-radius, 999px);
|
||||
background: var(--ws-recovery-background, color-mix(in srgb, #ffffff 92%, transparent));
|
||||
color: var(--ws-recovery-foreground, #31524f);
|
||||
font-family: var(--ws-recovery-font, ui-sans-serif, system-ui, sans-serif);
|
||||
font-size: var(--ws-recovery-font-size, 11px);
|
||||
border: 1px solid var(--ws-control-border, #9db6b2);
|
||||
border-radius: var(--ws-control-radius, 999px);
|
||||
background: var(--ws-control-background, color-mix(in srgb, #ffffff 92%, transparent));
|
||||
color: var(--ws-control-foreground, #31524f);
|
||||
font-family: var(--ws-control-font, ui-sans-serif, system-ui, sans-serif);
|
||||
font-size: var(--ws-control-font-size, 11px);
|
||||
box-shadow: 0 6px 18px #0f2a2626;
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -122,18 +127,18 @@ const RECOVERY_LAYER_CSS = `
|
||||
.ws-host-recovery button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: var(--ws-recovery-hit, 28px);
|
||||
min-height: var(--ws-control-hit, 28px);
|
||||
padding: 4px 9px;
|
||||
border: 1px solid #9db6b2;
|
||||
border-radius: var(--ws-recovery-radius, 999px);
|
||||
background: var(--ws-recovery-background, #fff);
|
||||
color: var(--ws-recovery-foreground, #31524f);
|
||||
border: 1px solid var(--ws-control-border, #9db6b2);
|
||||
border-radius: var(--ws-control-radius, 999px);
|
||||
background: var(--ws-control-background, #fff);
|
||||
color: var(--ws-control-foreground, #31524f);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ws-host-recovery button[data-ws-recovery-action="built-in"] {
|
||||
border-color: var(--ws-recovery-builtin-border, #b45309);
|
||||
border-color: var(--ws-control-builtin-border, #b45309);
|
||||
background: #fff7ed;
|
||||
color: #7c2d12;
|
||||
}
|
||||
@@ -142,10 +147,10 @@ const RECOVERY_LAYER_CSS = `
|
||||
.ws-host-recovery.ws-host-recovery-compact:not(:hover):not(:focus-within) { gap: 0; padding: 4px; }
|
||||
.ws-host-recovery.ws-host-recovery-compact:not(:hover):not(:focus-within) .ws-host-recovery-action { display: none; }
|
||||
.ws-host-recovery.ws-host-recovery-compact:not(:hover):not(:focus-within) .ws-host-recovery-mark {
|
||||
min-width: var(--ws-recovery-hit, 28px);
|
||||
min-height: var(--ws-recovery-hit, 28px);
|
||||
min-width: var(--ws-control-hit, 28px);
|
||||
min-height: var(--ws-control-hit, 28px);
|
||||
}
|
||||
.ws-host-recovery.ws-host-recovery-compact:focus-visible { outline: 2px solid var(--ws-recovery-accent, #4c8f88); outline-offset: 2px; }
|
||||
.ws-host-recovery.ws-host-recovery-compact:focus-visible { outline: 2px solid var(--ws-control-accent, #4c8f88); outline-offset: 2px; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ws-host-recovery, .ws-host-recovery button { transition: none !important; }
|
||||
}
|
||||
@@ -172,6 +177,21 @@ const showRecovery = computed(() => shouldShowRecovery({
|
||||
// already reset). It never renders decoration on its own.
|
||||
const shortcutOpen = ref(false);
|
||||
const recoveryPopover = ref<HTMLElement | null>(null);
|
||||
|
||||
/**
|
||||
* Theme the capsule even when the skin does not declare a slot. `bindHostSlot`
|
||||
* still reads the anchor first when a slot exists; this root-level pass covers
|
||||
* the floating capsule and is overwritten by the anchor values on the next
|
||||
* revalidation.
|
||||
*/
|
||||
const recoveryTheme = layer ? bindHostControlTheme({
|
||||
layer,
|
||||
control: () => recoveryPopover.value,
|
||||
part: "host.recovery",
|
||||
defaults: RECOVERY_CONTROL_DEFAULTS,
|
||||
source: () => findSkinRoot(hostChromeActiveSkinId.value),
|
||||
}) : null;
|
||||
|
||||
const recoveryVisible = computed(() => showRecovery.value || (shortcutOpen.value && thirdPartyAllowed.value));
|
||||
|
||||
/**
|
||||
@@ -238,6 +258,9 @@ let slotBinding: HostSlotBinding | undefined;
|
||||
function syncSlotBinding() {
|
||||
slotBinding?.dispose();
|
||||
slotBinding = undefined;
|
||||
// Disposing a slot clears its inline tokens; restore the root-level theme
|
||||
// before deciding whether a new anchor should override it.
|
||||
recoveryTheme?.apply();
|
||||
// A fresh binding starts floating and reports its first successful dock.
|
||||
slotMode.value = "floating";
|
||||
const control = recoveryPopover.value;
|
||||
@@ -294,6 +317,9 @@ watch([recoveryVisible, recoveryPopover], () => {
|
||||
slotBinding?.revalidate();
|
||||
});
|
||||
}, { flush: "post" });
|
||||
watch([recoveryPopover, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => recoveryTheme?.apply());
|
||||
}, { flush: "post", immediate: true });
|
||||
watch([slotConfig, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => {
|
||||
syncPopover();
|
||||
@@ -317,6 +343,7 @@ onBeforeUnmount(() => {
|
||||
if (reachabilityTimer) clearInterval(reachabilityTimer);
|
||||
if (compactHoldTimer) clearTimeout(compactHoldTimer);
|
||||
slotBinding?.dispose();
|
||||
recoveryTheme?.dispose();
|
||||
window.removeEventListener("resize", refreshLauncherReachability);
|
||||
window.removeEventListener("keydown", onKeydown, true);
|
||||
window.removeEventListener("pointerdown", onDocumentPointerDown, true);
|
||||
|
||||
@@ -25,13 +25,19 @@ import type { SiteLanguage } from '../../../src/site-copy.js';
|
||||
import { authorizationDecision, authorizationLanguage, authorizationRequested, setInstanceAuthorization } from '../services/instance-authorization.js';
|
||||
import { instanceAuthorizationCopy } from '../i18n/instance-authorization.js';
|
||||
import { createHostOwnedLayer, type HostOwnedLayer } from '../services/host-owned-layer.js';
|
||||
import { hostChromeActiveSkinId } from '../services/host-chrome.js';
|
||||
import {
|
||||
PERMISSION_CONTROL_DEFAULTS,
|
||||
bindHostControlTheme,
|
||||
findSkinRoot,
|
||||
} from '../services/host-control-tokens.js';
|
||||
|
||||
const AUTHORIZATION_LAYER_CSS = `
|
||||
:host { font: 14px/1.75 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
||||
.ws-instance-authorization{box-sizing:border-box;width:min(570px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;padding:30px;border:1px solid #dbe3f1;border-radius:20px;background:#fff;color:#25324b;font:inherit;box-shadow:0 24px 90px #101c4140;color-scheme:light;overflow:auto;pointer-events:auto}
|
||||
.ws-instance-authorization{box-sizing:border-box;width:min(570px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;padding:30px;border:1px solid var(--ws-control-border,#dbe3f1);border-radius:var(--ws-control-radius,20px);background:var(--ws-control-background,#fff);color:var(--ws-control-foreground,#25324b);font-family:var(--ws-control-font,system-ui,-apple-system,"Segoe UI",sans-serif);font-size:var(--ws-control-font-size,14px);line-height:1.75;box-shadow:0 24px 90px #101c4140;color-scheme:light;overflow:auto;pointer-events:auto}
|
||||
.ws-instance-authorization::backdrop{background:#10182d8c;backdrop-filter:blur(5px)}
|
||||
.ws-instance-authorization form{margin:0}.ws-instance-authorization h2{margin:12px 0 16px;font-size:23px;line-height:1.4;color:#202e49}.ws-instance-authorization p{margin:12px 0;color:#526079}.ws-authorization-mark{display:grid;place-items:center;width:43px;height:43px;border-radius:13px;background:#edf0ff;color:#5265df;font-size:28px}
|
||||
.ws-instance-authorization label{display:flex;align-items:flex-start;gap:12px;margin:22px 0;padding:15px;background:#f4f6fc;border:1px solid #dce3f3;border-radius:12px;cursor:pointer}.ws-instance-authorization input{appearance:auto;flex:none;width:18px;height:18px;margin:4px 0 0;accent-color:#5265df}.ws-instance-authorization footer{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap;margin-top:24px}.ws-instance-authorization button{appearance:none;min-height:42px;padding:9px 16px;border:1px solid #d9e1ef;border-radius:10px;background:#f4f6fc;color:#43516d;font:600 14px/1.5 system-ui;cursor:pointer}.ws-instance-authorization .ws-authorization-primary{background:#5265df;color:#fff;border-color:#5265df}.ws-instance-authorization button:disabled{opacity:.45;cursor:not-allowed}.ws-instance-authorization button:focus-visible,.ws-instance-authorization input:focus-visible{outline:2px solid #5265df;outline-offset:3px}
|
||||
.ws-instance-authorization form{margin:0}.ws-instance-authorization h2{margin:12px 0 16px;font-size:23px;line-height:1.4;color:var(--ws-control-foreground,#202e49)}.ws-instance-authorization p{margin:12px 0;color:color-mix(in srgb,var(--ws-control-foreground,#25324b) 76%,transparent)}.ws-authorization-mark{display:grid;place-items:center;width:43px;height:43px;border-radius:13px;background:color-mix(in srgb,var(--ws-control-accent,#5265df) 14%,var(--ws-control-background,#fff));color:var(--ws-control-accent,#5265df);font-size:28px}
|
||||
.ws-instance-authorization label{display:flex;align-items:flex-start;gap:12px;margin:22px 0;padding:15px;background:color-mix(in srgb,var(--ws-control-foreground,#25324b) 6%,var(--ws-control-background,#fff));border:1px solid var(--ws-control-border,#dce3f3);border-radius:12px;cursor:pointer}.ws-instance-authorization input{appearance:auto;flex:none;width:18px;height:18px;margin:4px 0 0;accent-color:var(--ws-control-accent,#5265df)}.ws-instance-authorization footer{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap;margin-top:24px}.ws-instance-authorization button{appearance:none;min-height:var(--ws-control-hit,42px);padding:9px 16px;border:1px solid var(--ws-control-border,#d9e1ef);border-radius:var(--ws-control-radius,10px);background:color-mix(in srgb,var(--ws-control-foreground,#25324b) 6%,var(--ws-control-background,#fff));color:var(--ws-control-foreground,#43516d);font:600 var(--ws-control-font-size,14px)/1.5 var(--ws-control-font,system-ui);cursor:pointer}.ws-instance-authorization .ws-authorization-primary{background:var(--ws-control-accent,#5265df);color:var(--ws-control-on-accent,#fff);border-color:var(--ws-control-accent,#5265df)}.ws-instance-authorization button:disabled{opacity:.45;cursor:not-allowed}.ws-instance-authorization button:focus-visible,.ws-instance-authorization input:focus-visible{outline:2px solid var(--ws-control-accent,#5265df);outline-offset:3px}
|
||||
@media(max-width:600px){.ws-instance-authorization{padding:22px}.ws-instance-authorization footer button{flex:1}}
|
||||
`;
|
||||
|
||||
@@ -39,6 +45,17 @@ const layer: HostOwnedLayer | null = createHostOwnedLayer('authorization', AUTHO
|
||||
const props = defineProps<{ language: SiteLanguage }>();
|
||||
const dialog = ref<HTMLDialogElement | null>(null), checked = ref(false), firstVisit = ref(false);
|
||||
const copy = computed(() => instanceAuthorizationCopy[props.language]);
|
||||
|
||||
/** The authorization dialog is host-owned; only sanitized tokens can theme it. */
|
||||
const theme = layer ? bindHostControlTheme({
|
||||
layer,
|
||||
control: () => dialog.value,
|
||||
part: 'host.permission',
|
||||
defaults: PERMISSION_CONTROL_DEFAULTS,
|
||||
source: () => findSkinRoot(hostChromeActiveSkinId.value),
|
||||
}) : null;
|
||||
|
||||
watch([dialog, hostChromeActiveSkinId], () => { theme?.apply(); }, { flush: 'post', immediate: true });
|
||||
watch(() => props.language, value => { authorizationLanguage.value = value; }, { immediate: true });
|
||||
watch([dialog, authorizationRequested, authorizationDecision], () => {
|
||||
if (!dialog.value || dialog.value.open || (authorizationDecision.value !== null && !authorizationRequested.value)) return;
|
||||
@@ -50,5 +67,5 @@ function finish() { authorizationRequested.value = false; dialog.value?.close();
|
||||
function save() { if (firstVisit.value && !checked.value) return; setInstanceAuthorization(checked.value); finish(); }
|
||||
function decline() { setInstanceAuthorization(false); finish(); }
|
||||
function cancel() { if (firstVisit.value) decline(); else finish(); }
|
||||
onBeforeUnmount(() => { dialog.value?.close(); layer?.dispose(); });
|
||||
onBeforeUnmount(() => { dialog.value?.close(); theme?.dispose(); layer?.dispose(); });
|
||||
</script>
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<Teleport v-if="layer" :to="layer.container">
|
||||
<section v-if="error" class="skin-load-recovery" data-ws-part="app.skin-load-recovery" role="alert">
|
||||
<section v-if="error" ref="banner" class="skin-load-recovery" data-ws-part="app.skin-load-recovery" role="alert">
|
||||
<p>{{ labels.skinLoadError(error.skinId) }}</p>
|
||||
<button type="button" @click="$emit('use-built-in')">{{ labels.skinUseBuiltIn }}</button>
|
||||
</section>
|
||||
@@ -8,10 +8,16 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount } from "vue";
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import type { Language } from "../i18n/web-client.js";
|
||||
import { resolveSkinLayoutLanguage, skinLayoutLabels } from "../i18n/skin-layout.js";
|
||||
import { createHostOwnedLayer, type HostOwnedLayer } from "../services/host-owned-layer.js";
|
||||
import { hostChromeActiveSkinId } from "../services/host-chrome.js";
|
||||
import {
|
||||
SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
|
||||
bindHostControlTheme,
|
||||
findSkinRoot,
|
||||
} from "../services/host-control-tokens.js";
|
||||
|
||||
defineEmits<{ "use-built-in": [] }>();
|
||||
|
||||
@@ -38,17 +44,19 @@ const SKIN_LOAD_LAYER_CSS = `
|
||||
box-sizing: border-box;
|
||||
padding: 10px 12px;
|
||||
transform: translateX(-50%);
|
||||
border: 1px solid #f59e0b;
|
||||
border-radius: 12px;
|
||||
color: #78350f;
|
||||
background: #fffbeb;
|
||||
border: 1px solid var(--ws-control-border, #f59e0b);
|
||||
border-radius: var(--ws-control-radius, 12px);
|
||||
color: var(--ws-control-foreground, #78350f);
|
||||
background: var(--ws-control-background, #fffbeb);
|
||||
box-shadow: 0 8px 28px #0f172a33;
|
||||
font: 14px/1.45 ui-sans-serif, system-ui, sans-serif;
|
||||
font-family: var(--ws-control-font, ui-sans-serif, system-ui, sans-serif);
|
||||
font-size: var(--ws-control-font-size, 14px);
|
||||
line-height: 1.45;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.skin-load-recovery p { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
|
||||
.skin-load-recovery button { flex: 0 0 auto; min-height: 44px; max-width: 100%; padding: 7px 10px; border: 1px solid #b45309; border-radius: 8px; color: #78350f; background: #fff; cursor: pointer; white-space: normal; }
|
||||
.skin-load-recovery button:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 2px; }
|
||||
.skin-load-recovery button { flex: 0 0 auto; min-height: var(--ws-control-hit, 44px); max-width: 100%; padding: 7px 10px; border: 1px solid var(--ws-control-accent, #b45309); border-radius: var(--ws-control-radius, 8px); color: var(--ws-control-foreground, #78350f); background: var(--ws-control-background, #fff); font: inherit; cursor: pointer; white-space: normal; }
|
||||
.skin-load-recovery button:focus-visible { outline: 3px solid var(--ws-control-accent, #1d4ed8); outline-offset: 2px; }
|
||||
@media (max-width: 520px) {
|
||||
.skin-load-recovery { align-items: stretch; flex-direction: column; gap: 7px; }
|
||||
.skin-load-recovery button { width: 100%; }
|
||||
@@ -56,6 +64,27 @@ const SKIN_LOAD_LAYER_CSS = `
|
||||
`;
|
||||
|
||||
const layer: HostOwnedLayer | null = createHostOwnedLayer("skin-load", SKIN_LOAD_LAYER_CSS);
|
||||
const banner = ref<HTMLElement | null>(null);
|
||||
|
||||
onBeforeUnmount(() => layer?.dispose());
|
||||
/**
|
||||
* Tokens come from the active skin root, never from the document. The banner
|
||||
* appears when a skin failed to load, so a missing root simply keeps the
|
||||
* built-in amber surface; an unreadable palette reverts the same way.
|
||||
*/
|
||||
const theme = layer ? bindHostControlTheme({
|
||||
layer,
|
||||
control: () => banner.value,
|
||||
part: "app.skin-load-recovery",
|
||||
defaults: SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
|
||||
source: () => findSkinRoot(hostChromeActiveSkinId.value),
|
||||
}) : null;
|
||||
|
||||
watch([() => props.error, banner, hostChromeActiveSkinId], () => {
|
||||
void nextTick(() => theme?.apply());
|
||||
}, { flush: "post", immediate: true });
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
theme?.dispose();
|
||||
layer?.dispose();
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user