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:
OddTurtleHead committed 2026-11-15 17:03:07 +08:00
1 parent 93d221c3ef
commit c1187d12d2
19 files changed
+1094 -422

No files matched your search

+42 -15
View File
@@ -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);
+21 -4
View File
@@ -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>
+39 -10
View File
@@ -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>
@@ -0,0 +1,250 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
HOST_CONTROL_APPLIED_VARIABLES,
HOST_CONTROL_GLOBAL_TOKEN_PROPERTIES,
HOST_CONTROL_MIN_ACCENT_CONTRAST,
HOST_CONTROL_MIN_BORDER_CONTRAST,
HOST_CONTROL_MIN_FONT_SIZE,
HOST_CONTROL_MIN_FOREGROUND_CONTRAST,
HOST_CONTROL_MIN_HIT_TARGET,
HOST_CONTROL_SIZE_METRICS,
PERMISSION_CONTROL_DEFAULTS,
RECOVERY_CONTROL_DEFAULTS,
SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
applyHostControlTokens,
contrastRatio,
hasHostControlTokens,
hostControlTokenKey,
hostControlTokenProperty,
parseCssColor,
relativeLuminance,
resolveHostControlTokens,
type HostControlRawTokens,
} from "./host-control-tokens.js";
type TokenMap = Record<string, string>;
const style = (tokens: TokenMap): Pick<CSSStyleDeclaration, "getPropertyValue"> => ({
getPropertyValue: (name) => tokens[name] ?? "",
});
const prefixed = (prefix: string, tokens: HostControlRawTokens): TokenMap => Object.fromEntries(
Object.entries(tokens)
.filter((entry): entry is [string, string] => typeof entry[1] === "string")
.map(([name, value]) => [`--skin-${prefix}-${name}`, value]),
);
const resolveRecovery = (part: HostControlRawTokens = {}, global: HostControlRawTokens = {}) =>
resolveHostControlTokens(
style({ ...prefixed("host", global), ...prefixed("recovery", part) }),
"host.recovery",
raw => raw,
RECOVERY_CONTROL_DEFAULTS,
);
test("host control token names are stable and keep --skin-recovery-* working", () => {
assert.equal(hostControlTokenKey("host.recovery"), "recovery");
assert.equal(hostControlTokenKey("app.skin-load-recovery"), "load-recovery");
assert.equal(hostControlTokenKey("host.permission"), "permission");
assert.equal(hostControlTokenKey("host.future"), "future");
assert.equal(hostControlTokenProperty("host.recovery", "background"), "--skin-recovery-background");
assert.equal(hostControlTokenProperty("app.skin-load-recovery", "size"), "--skin-load-recovery-size");
assert.equal(hostControlTokenProperty("host.permission", "accent"), "--skin-permission-accent");
assert.equal(HOST_CONTROL_GLOBAL_TOKEN_PROPERTIES.foreground, "--skin-host-foreground");
});
test("recovery tokens default to the host palette", () => {
const tokens = resolveHostControlTokens(null, "host.recovery", () => undefined, RECOVERY_CONTROL_DEFAULTS);
assert.equal(tokens.accent, "rgb(180, 83, 9)");
assert.equal(tokens.builtInBorder, "rgb(180, 83, 9)");
assert.equal(tokens.background, "rgb(255, 255, 255)");
assert.equal(tokens.foreground, "rgb(49, 82, 79)");
assert.equal(tokens.border, "rgb(157, 182, 178)");
assert.equal(tokens.radius, 999);
assert.equal(tokens.font, "ui-sans-serif, system-ui, sans-serif");
assert.equal(tokens.size, "small");
assert.equal(tokens.hitTarget, HOST_CONTROL_MIN_HIT_TARGET);
assert.equal(tokens.fontSize, HOST_CONTROL_MIN_FONT_SIZE);
assert.ok(contrastRatio(parseCssColor(tokens.onAccent)!, parseCssColor(tokens.accent)!) >= 4.5);
});
test("a readable skin palette is kept and translucent backgrounds become opaque", () => {
const tokens = resolveRecovery({
accent: "#47dcc4",
background: "rgba(9, 19, 23, 0.4)",
foreground: "#edf8f5",
border: "#47dcc4",
});
assert.equal(tokens.accent, "rgb(71, 220, 196)");
assert.equal(tokens.background, "rgb(9, 19, 23)");
assert.equal(tokens.foreground, "rgb(237, 248, 245)");
assert.equal(tokens.border, "rgb(71, 220, 196)");
});
test("per-part tokens win over the global set and both fall back as a colour group", () => {
const readable = resolveRecovery(
{ background: "#102030", foreground: "#ffffff", accent: "#47dcc4" },
{ background: "#ffffff", foreground: "#111111", accent: "#1d4ed8" },
);
assert.equal(readable.background, "rgb(16, 32, 48)", "the per-part background must win");
assert.equal(readable.foreground, "rgb(255, 255, 255)");
assert.equal(readable.accent, "rgb(71, 220, 196)");
// An unreadable per-part group falls back to a readable global palette.
const globalFallback = resolveRecovery(
{ background: "#777777", foreground: "#888888", accent: "#47dcc4" },
{ background: "#102030", foreground: "#ffffff", accent: "#47dcc4" },
);
assert.equal(globalFallback.background, "rgb(16, 32, 48)");
assert.equal(globalFallback.foreground, "rgb(255, 255, 255)");
assert.equal(globalFallback.accent, "rgb(71, 220, 196)");
// No readable layer: the built-in palette wins as a whole.
const reset = resolveRecovery(
{ background: "#777777", foreground: "#888888", accent: "#47dcc4" },
{ background: "#888888", foreground: "#999999", accent: "#eeeeee" },
);
assert.equal(reset.background, "rgb(255, 255, 255)");
assert.equal(reset.foreground, "rgb(49, 82, 79)");
assert.equal(reset.accent, "rgb(180, 83, 9)");
});
test("the border only uses a colour visible against the resolved background", () => {
assert.equal(resolveRecovery({ border: "#ffffff" }).border, "rgb(157, 182, 178)");
assert.equal(resolveRecovery({ border: "#000000" }).border, "rgb(0, 0, 0)");
const globalFallback = resolveRecovery({ border: "#ffffff" }, { border: "#000000" });
assert.equal(globalFallback.border, "rgb(0, 0, 0)");
assert.ok(contrastRatio(parseCssColor(globalFallback.border)!, parseCssColor(globalFallback.background)!) >= HOST_CONTROL_MIN_BORDER_CONTRAST);
});
test("radius, font and size tokens are sanitized and host minimums win", () => {
assert.equal(resolveRecovery({ radius: "12px" }).radius, 12);
assert.equal(resolveRecovery({ radius: "2000px" }).radius, 999);
assert.equal(resolveRecovery({ radius: "-5px" }).radius, 0);
assert.equal(resolveRecovery({ radius: "1em" }).radius, 999);
assert.equal(resolveRecovery({ radius: "12" }).radius, 999);
assert.equal(resolveRecovery({ font: 'Tahoma, "Segoe UI", sans-serif' }).font, 'Tahoma, "Segoe UI", sans-serif');
for (const font of ["url(https://example.invalid/a.woff2)", "Tahoma; color: red", "x".repeat(121)]) {
assert.equal(resolveRecovery({ font }).font, "ui-sans-serif, system-ui, sans-serif", font);
}
assert.equal(resolveRecovery({ size: "medium" }).hitTarget, 32);
assert.equal(resolveRecovery({ size: "medium" }).fontSize, 12);
assert.equal(resolveRecovery({ size: "large" }).hitTarget, 36);
assert.equal(resolveRecovery({ size: "large" }).fontSize, 13);
assert.equal(resolveRecovery({ size: "huge" }).size, "small");
for (const metrics of Object.values(HOST_CONTROL_SIZE_METRICS)) {
assert.ok(metrics.hitTarget >= HOST_CONTROL_MIN_HIT_TARGET);
assert.ok(metrics.fontSize >= HOST_CONTROL_MIN_FONT_SIZE);
}
// Controls with a larger built-in action never shrink below it.
const banner = resolveHostControlTokens(
style(prefixed("host", { size: "small" })),
"app.skin-load-recovery",
raw => raw,
SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
);
assert.equal(banner.hitTarget, 44);
assert.equal(banner.fontSize, 14);
const bannerLarge = resolveHostControlTokens(
style(prefixed("load-recovery", { size: "large" })),
"app.skin-load-recovery",
raw => raw,
SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
);
assert.equal(bannerLarge.hitTarget, 48);
assert.equal(bannerLarge.fontSize, 16);
});
test("the built-in button border only uses an accent visible on its fixed light background", () => {
const pale = resolveRecovery({ background: "#141414", foreground: "#ffffff", accent: "#fff7ec" });
assert.equal(pale.accent, "rgb(255, 247, 236)");
assert.equal(pale.builtInBorder, "rgb(180, 83, 9)");
const strong = resolveRecovery({ background: "#ffffff", foreground: "#111111", accent: "#1d4ed8" });
assert.equal(strong.builtInBorder, "rgb(29, 78, 216)");
});
test("global tokens theme the banner and the authorization dialog", () => {
const root = style(prefixed("host", {
background: "#102030",
foreground: "#ffffff",
accent: "#47dcc4",
border: "#47dcc4",
radius: "18px",
font: "Tahoma, sans-serif",
size: "large",
}));
const banner = resolveHostControlTokens(root, "app.skin-load-recovery", raw => raw, SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS);
assert.equal(banner.background, "rgb(16, 32, 48)");
assert.equal(banner.foreground, "rgb(255, 255, 255)");
assert.equal(banner.radius, 18);
assert.equal(banner.font, "Tahoma, sans-serif");
assert.equal(banner.hitTarget, 48);
const dialog = resolveHostControlTokens(root, "host.permission", raw => raw, PERMISSION_CONTROL_DEFAULTS);
assert.equal(dialog.background, "rgb(16, 32, 48)");
assert.equal(dialog.foreground, "rgb(255, 255, 255)");
assert.ok(contrastRatio(parseCssColor(dialog.onAccent)!, parseCssColor(dialog.accent)!) >= 4.5);
assert.equal(dialog.hitTarget, 46);
const override = resolveHostControlTokens(
style({ ...prefixed("host", { background: "#102030", foreground: "#ffffff", accent: "#47dcc4" }), ...prefixed("load-recovery", { background: "#ffffff", foreground: "#111111", accent: "#1d4ed8" }) }),
"app.skin-load-recovery",
raw => raw,
SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS,
);
assert.equal(override.background, "rgb(255, 255, 255)");
});
test("only a declared global or per-part token triggers host theming", () => {
assert.equal(hasHostControlTokens(style({}), "host.recovery"), false);
assert.equal(hasHostControlTokens(style({ "--skin-unrelated": "red" }), "host.recovery"), false);
assert.equal(hasHostControlTokens(style({ "--skin-host-background": "#102030" }), "host.recovery"), true);
assert.equal(hasHostControlTokens(style({ "--skin-recovery-radius": "8px" }), "host.recovery"), true);
assert.equal(hasHostControlTokens(style({ "--skin-load-recovery-accent": "#123456" }), "app.skin-load-recovery"), true);
assert.equal(hasHostControlTokens(style({ "--skin-permission-font": "Tahoma" }), "host.permission"), true);
});
test("applying and clearing tokens writes only host-owned variables", () => {
const values = new Map<string, string>();
const control = {
style: {
setProperty: (name: string, value: string) => { values.set(name, value); },
removeProperty: (name: string) => { values.delete(name); },
},
} as unknown as HTMLElement;
const tokens = resolveRecovery({ background: "#102030", foreground: "#ffffff", accent: "#47dcc4", radius: "8px" });
applyHostControlTokens(control, tokens);
assert.equal(values.get(HOST_CONTROL_APPLIED_VARIABLES.background), "rgb(16, 32, 48)");
assert.equal(values.get(HOST_CONTROL_APPLIED_VARIABLES.radius), "8px");
assert.ok(values.has(HOST_CONTROL_APPLIED_VARIABLES.onAccent));
applyHostControlTokens(control, null);
assert.equal(values.size, 0);
});
test("CSS colours parse to RGB and ignore alpha for contrast", () => {
assert.deepEqual(parseCssColor("#1d4f9c"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("#fff"), { r: 255, g: 255, b: 255 });
assert.deepEqual(parseCssColor("#ffff"), { r: 255, g: 255, b: 255 });
assert.deepEqual(parseCssColor("rgb(29, 79, 156)"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("rgb(29 79 156 / 50%)"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("rgba(255, 0, 0, .4)"), { r: 255, g: 0, b: 0 });
assert.deepEqual(parseCssColor("rgb(300, -5, 0)"), { r: 255, g: 0, b: 0 });
for (const invalid of ["", "red", "hsl(10, 20%, 30%)", "color(srgb 1 0 0)", "#12345", "rgb(1, 2)"]) {
assert.equal(parseCssColor(invalid), null, invalid);
}
});
test("WCAG contrast follows the relative-luminance formula", () => {
assert.equal(relativeLuminance({ r: 0, g: 0, b: 0 }), 0);
assert.equal(relativeLuminance({ r: 255, g: 255, b: 255 }), 1);
assert.equal(contrastRatio({ r: 0, g: 0, b: 0 }, { r: 255, g: 255, b: 255 }), 21);
assert.equal(contrastRatio({ r: 12, g: 34, b: 56 }, { r: 12, g: 34, b: 56 }), 1);
assert.ok(HOST_CONTROL_MIN_FOREGROUND_CONTRAST > HOST_CONTROL_MIN_ACCENT_CONTRAST);
});
+522
View File
@@ -0,0 +1,522 @@
/**
* Style tokens for host-owned protected controls.
*
* Recovery, the skin-load banner and the authorization dialog live inside
* closed shadow roots, so compiled skin CSS can never reach them. A skin may
* declare a small, sanitised token set on the active skin root instead; the
* host reads it, checks readability and applies the result inside the shadow
* root. The control still owns its structure, hit target and fallback.
*
* Token names:
* --skin-host-accent | background | foreground | border | radius | font | size
* --skin-<part-key>-<token> (per-part override)
*
* `host.recovery` keeps its historical `recovery` key so `--skin-recovery-*`
* continues to work; its per-part values win over the global set.
*/
import type { HostOwnedLayer } from "./host-owned-layer.js";
export type HostControlSizeTier = "small" | "medium" | "large";
export interface HostControlMetrics {
/** Host-enforced minimum button hit target in CSS pixels. */
readonly hitTarget: number;
/** Host-enforced minimum font size in CSS pixels. */
readonly fontSize: number;
}
export const HOST_CONTROL_MIN_HIT_TARGET = 28;
export const HOST_CONTROL_MIN_FONT_SIZE = 11;
export const HOST_CONTROL_MIN_FOREGROUND_CONTRAST = 4.5;
export const HOST_CONTROL_MIN_ACCENT_CONTRAST = 3;
export const HOST_CONTROL_MIN_BORDER_CONTRAST = 3;
/** Host-controlled size tiers; a skin can choose a tier, never a smaller size. */
export const HOST_CONTROL_SIZE_METRICS: Readonly<Record<HostControlSizeTier, HostControlMetrics>> = {
small: { hitTarget: 28, fontSize: 11 },
medium: { hitTarget: 32, fontSize: 12 },
large: { hitTarget: 36, fontSize: 13 },
};
export const HOST_CONTROL_TOKEN_NAMES = [
"accent", "background", "foreground", "border", "radius", "font", "size",
] as const;
export type HostControlTokenName = (typeof HOST_CONTROL_TOKEN_NAMES)[number];
/** Global token set read from the active skin root (or a slot anchor). */
export const HOST_CONTROL_GLOBAL_TOKEN_PROPERTIES: Readonly<Record<HostControlTokenName, string>> = {
accent: "--skin-host-accent",
background: "--skin-host-background",
foreground: "--skin-host-foreground",
border: "--skin-host-border",
radius: "--skin-host-radius",
font: "--skin-host-font",
size: "--skin-host-size",
};
/**
* Stable per-part token keys. The last dotted segment would turn
* `app.skin-load-recovery` into `--skin-skin-load-recovery-*`; the explicit
* keys keep the public names readable.
*/
export const HOST_CONTROL_TOKEN_KEYS: Readonly<Record<string, string>> = {
"host.recovery": "recovery",
"app.skin-load-recovery": "load-recovery",
"host.permission": "permission",
};
export function hostControlTokenKey(part: string): string {
return HOST_CONTROL_TOKEN_KEYS[part] ?? part.split(".").pop() ?? part;
}
export function hostControlTokenProperty(part: string, token: HostControlTokenName): string {
return `--skin-${hostControlTokenKey(part)}-${token}`;
}
/** Host-owned variables written inside the closed shadow root. */
export const HOST_CONTROL_APPLIED_VARIABLES = {
accent: "--ws-control-accent",
onAccent: "--ws-control-on-accent",
background: "--ws-control-background",
foreground: "--ws-control-foreground",
border: "--ws-control-border",
radius: "--ws-control-radius",
font: "--ws-control-font",
hitTarget: "--ws-control-hit",
fontSize: "--ws-control-font-size",
builtInBorder: "--ws-control-builtin-border",
} as const;
export interface HostControlRawTokens {
/** Computed-style colour values; unresolved values are rejected. */
accent?: string;
background?: string;
foreground?: string;
border?: string;
radius?: string;
font?: string;
size?: string;
}
export interface HostControlDefaults {
accent: RgbColor;
background: RgbColor;
foreground: RgbColor;
border: RgbColor;
radius: number;
maxRadius: number;
font: string;
hitTarget: number;
fontSize: number;
/** Optional per-tier metrics; defaults to HOST_CONTROL_SIZE_METRICS. */
sizeMetrics?: Readonly<Record<HostControlSizeTier, HostControlMetrics>>;
/** A fixed light-background action that keeps its own border contrast check. */
builtInButton?: { background: RgbColor; border: RgbColor };
}
export interface HostControlTokens {
accent: string;
/** Text colour that stays readable on top of `accent`. */
onAccent: string;
background: string;
foreground: string;
border: string;
radius: number;
font: string;
size: HostControlSizeTier;
hitTarget: number;
fontSize: number;
builtInBorder?: string;
}
export interface RgbColor {
r: number;
g: number;
b: number;
}
const DEFAULT_ACCENT: RgbColor = { r: 180, g: 83, b: 9 };
const DEFAULT_BACKGROUND: RgbColor = { r: 255, g: 255, b: 255 };
const DEFAULT_FOREGROUND: RgbColor = { r: 49, g: 82, b: 79 };
const DEFAULT_BORDER: RgbColor = { r: 157, g: 182, b: 178 };
const RECOVERY_BUILT_IN_BACKGROUND: RgbColor = { r: 255, g: 247, b: 237 };
const RECOVERY_BUILT_IN_BORDER: RgbColor = { r: 180, g: 83, b: 9 };
const ON_ACCENT_LIGHT: RgbColor = { r: 255, g: 255, b: 255 };
const ON_ACCENT_DARK: RgbColor = { r: 17, g: 24, b: 39 };
const MAX_RADIUS = 999;
const MAX_FONT_LENGTH = 120;
const FONT_FAMILY_PATTERN = /^[A-Za-z0-9 ,'"-]{1,120}$/;
/** Defaults for the recovery capsule: white surface, teal text, amber accent. */
export const RECOVERY_CONTROL_DEFAULTS: HostControlDefaults = {
accent: DEFAULT_ACCENT,
background: DEFAULT_BACKGROUND,
foreground: DEFAULT_FOREGROUND,
border: DEFAULT_BORDER,
radius: 999,
maxRadius: MAX_RADIUS,
font: "ui-sans-serif, system-ui, sans-serif",
hitTarget: HOST_CONTROL_MIN_HIT_TARGET,
fontSize: HOST_CONTROL_MIN_FONT_SIZE,
builtInButton: { background: RECOVERY_BUILT_IN_BACKGROUND, border: RECOVERY_BUILT_IN_BORDER },
};
/** Defaults for the skin-load failure banner: amber alert, 44px action. */
export const SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS: HostControlDefaults = {
accent: { r: 180, g: 83, b: 9 },
background: { r: 255, g: 251, b: 235 },
foreground: { r: 120, g: 53, b: 15 },
border: { r: 245, g: 158, b: 11 },
radius: 12,
maxRadius: 64,
font: "ui-sans-serif, system-ui, sans-serif",
hitTarget: 44,
fontSize: 14,
sizeMetrics: {
small: { hitTarget: 44, fontSize: 14 },
medium: { hitTarget: 46, fontSize: 15 },
large: { hitTarget: 48, fontSize: 16 },
},
};
/** Defaults for the host-owned authorization ("permission") dialog. */
export const PERMISSION_CONTROL_DEFAULTS: HostControlDefaults = {
accent: { r: 82, g: 101, b: 223 },
background: { r: 255, g: 255, b: 255 },
foreground: { r: 37, g: 50, b: 75 },
border: { r: 219, g: 227, b: 241 },
radius: 20,
maxRadius: 64,
font: 'system-ui, -apple-system, "Segoe UI", sans-serif',
hitTarget: 42,
fontSize: 14,
sizeMetrics: {
small: { hitTarget: 42, fontSize: 14 },
medium: { hitTarget: 44, fontSize: 15 },
large: { hitTarget: 46, fontSize: 16 },
},
};
/** Parse `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()`. */
export function parseCssColor(value: string | undefined | null): RgbColor | null {
if (!value) return null;
const text = value.trim().toLowerCase();
const hex = /^#([0-9a-f]{3,8})$/.exec(text);
if (hex) {
const digits = hex[1];
if (digits.length === 3 || digits.length === 4) {
return {
r: Number.parseInt(digits[0] + digits[0], 16),
g: Number.parseInt(digits[1] + digits[1], 16),
b: Number.parseInt(digits[2] + digits[2], 16),
};
}
if (digits.length === 6 || digits.length === 8) {
return {
r: Number.parseInt(digits.slice(0, 2), 16),
g: Number.parseInt(digits.slice(2, 4), 16),
b: Number.parseInt(digits.slice(4, 6), 16),
};
}
return null;
}
const fn = /^rgba?\(([^()]*)\)$/.exec(text);
if (!fn) return null;
const parts = fn[1].replace(/\//g, " ").split(/[\s,]+/).filter(Boolean);
if (parts.length < 3 || parts.length > 4) return null;
const channels: number[] = [];
for (const part of parts.slice(0, 3)) {
const percent = part.endsWith("%");
const parsed = Number.parseFloat(part);
if (!Number.isFinite(parsed)) return null;
const channel = percent ? parsed * 2.55 : parsed;
channels.push(Math.round(Math.min(255, Math.max(0, channel))));
}
return { r: channels[0], g: channels[1], b: channels[2] };
}
export function formatRgb(color: RgbColor): string {
return `rgb(${color.r}, ${color.g}, ${color.b})`;
}
/** WCAG 2.x relative luminance, 0 (black) to 1 (white). */
export function relativeLuminance(color: RgbColor): number {
const channel = (value: number): number => {
const normalized = Math.min(255, Math.max(0, value)) / 255;
return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * channel(color.r) + 0.7152 * channel(color.g) + 0.0722 * channel(color.b);
}
export function contrastRatio(first: RgbColor, second: RgbColor): number {
const lighter = Math.max(relativeLuminance(first), relativeLuminance(second));
const darker = Math.min(relativeLuminance(first), relativeLuminance(second));
return (lighter + 0.05) / (darker + 0.05);
}
export function isHostControlSizeTier(value: unknown): value is HostControlSizeTier {
return value === "small" || value === "medium" || value === "large";
}
function sanitizeRadius(value: string | undefined, fallback: number, maxRadius: number): number {
if (!value) return fallback;
const match = /^(-?\d+(?:\.\d+)?)px$/i.exec(value.trim());
if (!match) return fallback;
const radius = Number.parseFloat(match[1]);
return Number.isFinite(radius) ? Math.min(maxRadius, Math.max(0, radius)) : fallback;
}
function sanitizeFont(value: string | undefined, fallback: string): string {
if (!value) return fallback;
const font = value.trim().replace(/\s+/g, " ");
if (!font || font.length > MAX_FONT_LENGTH || !FONT_FAMILY_PATTERN.test(font) || !/[A-Za-z0-9]/.test(font)) {
return fallback;
}
return font;
}
function readTokenSet(
style: Pick<CSSStyleDeclaration, "getPropertyValue"> | null,
resolveProperty: (token: HostControlTokenName) => string,
): HostControlRawTokens {
if (!style) return {};
const read = (token: HostControlTokenName): string | undefined => {
const value = style.getPropertyValue(resolveProperty(token)).trim();
return value || undefined;
};
return {
accent: read("accent"),
background: read("background"),
foreground: read("foreground"),
border: read("border"),
radius: read("radius"),
font: read("font"),
size: read("size"),
};
}
function mergeRawTokens(...layers: readonly HostControlRawTokens[]): HostControlRawTokens {
const merged: HostControlRawTokens = {};
for (const layer of layers) {
for (const token of HOST_CONTROL_TOKEN_NAMES) {
if (layer[token] !== undefined) merged[token] = layer[token];
}
}
return merged;
}
type ColorProbe = (raw: string | undefined) => string | undefined;
function resolvePalette(
raw: HostControlRawTokens,
defaults: HostControlDefaults,
probeColor: ColorProbe,
): { accent: RgbColor; background: RgbColor; foreground: RgbColor } {
return {
accent: parseCssColor(probeColor(raw.accent)) ?? defaults.accent,
background: parseCssColor(probeColor(raw.background)) ?? defaults.background,
foreground: parseCssColor(probeColor(raw.foreground)) ?? defaults.foreground,
};
}
function paletteReadable(palette: { accent: RgbColor; background: RgbColor; foreground: RgbColor }): boolean {
return contrastRatio(palette.foreground, palette.background) >= HOST_CONTROL_MIN_FOREGROUND_CONTRAST
&& contrastRatio(palette.accent, palette.background) >= HOST_CONTROL_MIN_ACCENT_CONTRAST;
}
function resolveBorder(
raw: string | undefined,
background: RgbColor,
probeColor: ColorProbe,
): RgbColor | undefined {
const color = parseCssColor(probeColor(raw));
return color && contrastRatio(color, background) >= HOST_CONTROL_MIN_BORDER_CONTRAST ? color : undefined;
}
function readableOnAccent(accent: RgbColor): RgbColor {
return contrastRatio(ON_ACCENT_LIGHT, accent) >= contrastRatio(ON_ACCENT_DARK, accent)
? ON_ACCENT_LIGHT
: ON_ACCENT_DARK;
}
/** True when the skin root declares at least one global or per-part token. */
export function hasHostControlTokens(
style: Pick<CSSStyleDeclaration, "getPropertyValue"> | null,
part: string,
): boolean {
if (!style) return false;
return HOST_CONTROL_TOKEN_NAMES.some((token) =>
Boolean(style.getPropertyValue(hostControlTokenProperty(part, token)).trim())
|| Boolean(style.getPropertyValue(HOST_CONTROL_GLOBAL_TOKEN_PROPERTIES[token]).trim())
);
}
/**
* Read and sanitize the skin token layers from one computed style.
*
* `--skin-<part-key>-*` wins per token; unset values fall back to
* `--skin-host-*`, then to the control's built-in defaults. Colours are
* all-or-nothing: if the combined foreground/background/accent palette is
* unreadable, the resolver retries the global layer and finally the built-in
* palette, so a skin can never make a protected control unreadable. The
* border is optional and must stay visible against the resolved background.
*/
export function resolveHostControlTokens(
style: Pick<CSSStyleDeclaration, "getPropertyValue"> | null,
part: string,
probeColor: ColorProbe,
defaults: HostControlDefaults,
): HostControlTokens {
const partTokens = readTokenSet(style, (token) => hostControlTokenProperty(part, token));
const globalTokens = readTokenSet(style, (token) => HOST_CONTROL_GLOBAL_TOKEN_PROPERTIES[token]);
const merged = mergeRawTokens(globalTokens, partTokens);
let palette = resolvePalette(merged, defaults, probeColor);
if (!paletteReadable(palette)) palette = resolvePalette(globalTokens, defaults, probeColor);
if (!paletteReadable(palette)) palette = resolvePalette({}, defaults, probeColor);
const border = resolveBorder(merged.border, palette.background, probeColor)
?? resolveBorder(globalTokens.border, palette.background, probeColor)
?? defaults.border;
const sizeValue = merged.size?.trim();
const size = isHostControlSizeTier(sizeValue) ? sizeValue : "small";
const tierMetrics = (defaults.sizeMetrics ?? HOST_CONTROL_SIZE_METRICS)[size];
const hitTarget = Math.max(defaults.hitTarget, tierMetrics.hitTarget);
const fontSize = Math.max(defaults.fontSize, tierMetrics.fontSize);
const builtInBorder = defaults.builtInButton
? contrastRatio(palette.accent, defaults.builtInButton.background) >= HOST_CONTROL_MIN_ACCENT_CONTRAST
? palette.accent
: defaults.builtInButton.border
: undefined;
return {
accent: formatRgb(palette.accent),
onAccent: formatRgb(readableOnAccent(palette.accent)),
background: formatRgb(palette.background),
foreground: formatRgb(palette.foreground),
border: formatRgb(border),
radius: sanitizeRadius(merged.radius, defaults.radius, defaults.maxRadius),
font: sanitizeFont(merged.font, defaults.font),
size,
hitTarget,
fontSize,
...(builtInBorder ? { builtInBorder: formatRgb(builtInBorder) } : {}),
};
}
/** Apply (or clear) host-owned variables on the control inside the shadow root. */
export function applyHostControlTokens(control: HTMLElement, tokens: HostControlTokens | null): void {
const style = control.style;
for (const property of Object.values(HOST_CONTROL_APPLIED_VARIABLES)) style.removeProperty(property);
if (!tokens) return;
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.accent, tokens.accent);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.onAccent, tokens.onAccent);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.background, tokens.background);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.foreground, tokens.foreground);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.border, tokens.border);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.radius, `${tokens.radius}px`);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.font, tokens.font);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.hitTarget, `${tokens.hitTarget}px`);
style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.fontSize, `${tokens.fontSize}px`);
if (tokens.builtInBorder) style.setProperty(HOST_CONTROL_APPLIED_VARIABLES.builtInBorder, tokens.builtInBorder);
}
export interface HostControlThemeBindingOptions {
layer: HostOwnedLayer;
/** The host-owned element whose inline `--ws-control-*` variables are set. */
control: () => HTMLElement | null;
part: string;
defaults: HostControlDefaults;
/** The active skin root (or a slot anchor) to read token values from. */
source: () => Element | null;
}
export interface HostControlThemeBinding {
apply(): void;
dispose(): void;
}
/**
* Bind one host-owned control to the active skin's token set. The returned
* binding owns the hidden colour probe and never stores a token value on the
* skin side; callers re-apply it when the active skin or the control changes.
*/
export function bindHostControlTheme(options: HostControlThemeBindingOptions): HostControlThemeBinding {
let probe: HostControlColorProbe | null = null;
return {
apply() {
const control = options.control();
if (!control) return;
const source = options.source();
const view = source?.ownerDocument.defaultView;
if (!source || !view) {
applyHostControlTokens(control, null);
return;
}
const style = view.getComputedStyle(source);
// No token declaration keeps the control's built-in CSS fallback.
if (!hasHostControlTokens(style, options.part)) {
applyHostControlTokens(control, null);
return;
}
probe ??= createHostControlColorProbe(options.layer.shadow);
applyHostControlTokens(control, resolveHostControlTokens(style, options.part, probe.probeColor, options.defaults));
},
dispose() {
probe?.dispose();
probe = null;
},
};
}
/** The active skin root; the token source for controls without a slot anchor. */
export function findSkinRoot(skinId: string | undefined, doc: Document = document): Element | null {
for (const root of doc.querySelectorAll(".ws-skin-root")) {
if (!skinId || root.getAttribute("data-ws-skin") === skinId) return root;
}
return null;
}
export interface HostControlColorProbe {
/** Resolve a CSS colour through the browser, inside the closed shadow root. */
probeColor(raw: string | undefined): string | undefined;
dispose(): void;
}
/**
* A hidden probe element for resolving arbitrary CSS colour syntax (for
* example `color-mix()` or `oklch()`) to a concrete `rgb()` value.
*/
export function createHostControlColorProbe(shadow: ShadowRoot): HostControlColorProbe {
const doc = shadow.ownerDocument;
const win = doc.defaultView;
const element = doc.createElement("span");
element.setAttribute("aria-hidden", "true");
element.style.cssText = "position:absolute;left:-9999px;top:0;width:0;height:0;visibility:hidden;pointer-events:none;";
shadow.append(element);
const resolveWith = (raw: string, sentinel: string): string | undefined => {
if (!win) return undefined;
// An invalid value leaves the previous colour in place. Probe against two
// different sentinels so a real token equal to one of them still resolves.
element.style.color = sentinel;
element.style.color = raw;
return win.getComputedStyle(element).color;
};
return {
probeColor(raw) {
if (!raw) return undefined;
const first = resolveWith(raw, "rgb(1, 2, 3)");
if (first !== "rgb(1, 2, 3)") return first;
const second = resolveWith(raw, "rgb(4, 5, 6)");
return second === "rgb(4, 5, 6)" ? undefined : second;
},
dispose() {
element.remove();
},
};
}
+2 -106
View File
@@ -2,22 +2,13 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
INITIAL_SLOT_MODE_STATE,
RECOVERY_BUILT_IN_BUTTON_BACKGROUND,
RECOVERY_MIN_ACCENT_CONTRAST,
RECOVERY_MIN_FONT_SIZE,
RECOVERY_MIN_FOREGROUND_CONTRAST,
RECOVERY_MIN_HIT_TARGET,
RECOVERY_SIZE_METRICS,
computeSlotPlacement,
contrastRatio,
evaluateSlottedControl,
nextSlotModeState,
parseCssColor,
rectsOverlap,
relativeLuminance,
resolveRecoveryTokens,
type SlotAnchorSnapshot,
} from "./host-slot-placement.js";
import { HOST_CONTROL_MIN_HIT_TARGET } from "./host-control-tokens.js";
import type { HostPartRect } from "./host-chrome-visibility.js";
const rect = (left: number, top: number, width: number, height: number): HostPartRect => ({
@@ -41,7 +32,7 @@ const baseEvaluation = {
anchor: anchor(),
controlRect: rect(180, 105, 120, 30),
viewport: { width: 800, height: 600 },
minHitTarget: RECOVERY_MIN_HIT_TARGET,
minHitTarget: HOST_CONTROL_MIN_HIT_TARGET,
hitTestOk: true,
};
@@ -135,90 +126,6 @@ test("control size, position and hit test are enforced", () => {
);
});
test("CSS colours parse to RGB and ignore alpha for contrast", () => {
assert.deepEqual(parseCssColor("#1d4f9c"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("#fff"), { r: 255, g: 255, b: 255 });
assert.deepEqual(parseCssColor("#ffff"), { r: 255, g: 255, b: 255 });
assert.deepEqual(parseCssColor("rgb(29, 79, 156)"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("rgb(29 79 156 / 50%)"), { r: 29, g: 79, b: 156 });
assert.deepEqual(parseCssColor("rgba(255, 0, 0, .4)"), { r: 255, g: 0, b: 0 });
assert.deepEqual(parseCssColor("rgb(300, -5, 0)"), { r: 255, g: 0, b: 0 });
for (const invalid of ["", "red", "hsl(10, 20%, 30%)", "color(srgb 1 0 0)", "#12345", "rgb(1, 2)"]) {
assert.equal(parseCssColor(invalid), null, invalid);
}
});
test("WCAG contrast follows the relative-luminance formula", () => {
assert.equal(relativeLuminance({ r: 0, g: 0, b: 0 }), 0);
assert.equal(relativeLuminance({ r: 255, g: 255, b: 255 }), 1);
assert.equal(contrastRatio({ r: 0, g: 0, b: 0 }, { r: 255, g: 255, b: 255 }), 21);
assert.equal(contrastRatio({ r: 12, g: 34, b: 56 }, { r: 12, g: 34, b: 56 }), 1);
});
test("skin tokens default to the host palette", () => {
const tokens = resolveRecoveryTokens();
assert.deepEqual(tokens, {
accent: "rgb(180, 83, 9)",
builtInBorder: "rgb(180, 83, 9)",
background: "rgb(255, 255, 255)",
foreground: "rgb(49, 82, 79)",
radius: 999,
font: "ui-sans-serif, system-ui, sans-serif",
size: "small",
hitTarget: 28,
fontSize: 11,
});
});
test("a readable skin palette is kept and translucent backgrounds become opaque", () => {
const tokens = resolveRecoveryTokens({
accent: "#47dcc4",
background: "rgba(9, 19, 23, 0.4)",
foreground: "#edf8f5",
});
assert.equal(tokens.accent, "rgb(71, 220, 196)");
assert.equal(tokens.background, "rgb(9, 19, 23)");
assert.equal(tokens.foreground, "rgb(237, 248, 245)");
});
test("an unreadable colour group falls back as a whole", () => {
const lowForeground = resolveRecoveryTokens({ background: "#777777", foreground: "#888888", accent: "#47dcc4" });
assert.equal(lowForeground.background, "rgb(255, 255, 255)");
assert.equal(lowForeground.foreground, "rgb(49, 82, 79)");
assert.equal(lowForeground.accent, "rgb(180, 83, 9)");
const lowAccent = resolveRecoveryTokens({ background: "#ffffff", foreground: "#31524f", accent: "#eeeeee" });
assert.equal(lowAccent.accent, "rgb(180, 83, 9)");
assert.ok(contrastRatio(parseCssColor(lowAccent.accent)!, parseCssColor(lowAccent.background)!) >= RECOVERY_MIN_ACCENT_CONTRAST);
assert.ok(contrastRatio(parseCssColor(lowAccent.foreground)!, parseCssColor(lowAccent.background)!) >= RECOVERY_MIN_FOREGROUND_CONTRAST);
});
test("radius, font and size tokens are sanitized and host minimums win", () => {
assert.equal(resolveRecoveryTokens({ radius: "12px" }).radius, 12);
assert.equal(resolveRecoveryTokens({ radius: "2000px" }).radius, 999);
assert.equal(resolveRecoveryTokens({ radius: "-5px" }).radius, 0);
assert.equal(resolveRecoveryTokens({ radius: "1em" }).radius, 999);
assert.equal(resolveRecoveryTokens({ radius: "12" }).radius, 999);
assert.equal(
resolveRecoveryTokens({ font: 'Tahoma, "Segoe UI", sans-serif' }).font,
'Tahoma, "Segoe UI", sans-serif',
);
for (const font of ["url(https://example.invalid/a.woff2)", "Tahoma; color: red", "x".repeat(121)]) {
assert.equal(resolveRecoveryTokens({ font }).font, "ui-sans-serif, system-ui, sans-serif", font);
}
assert.equal(resolveRecoveryTokens({ size: "medium" }).hitTarget, 32);
assert.equal(resolveRecoveryTokens({ size: "medium" }).fontSize, 12);
assert.equal(resolveRecoveryTokens({ size: "large" }).hitTarget, 36);
assert.equal(resolveRecoveryTokens({ size: "large" }).fontSize, 13);
assert.equal(resolveRecoveryTokens({ size: "huge" }).size, "small");
for (const metrics of Object.values(RECOVERY_SIZE_METRICS)) {
assert.ok(metrics.hitTarget >= RECOVERY_MIN_HIT_TARGET);
assert.ok(metrics.fontSize >= RECOVERY_MIN_FONT_SIZE);
}
});
test("the mode gate does not flap between the anchor and the fallback", () => {
let state = INITIAL_SLOT_MODE_STATE;
// The first valid check slots immediately, even under the anti-flap rule.
@@ -259,14 +166,3 @@ test("rect overlap ignores edge contact and sub-pixel slivers", () => {
assert.equal(rectsOverlap(rect(0, 0, 100, 40), rect(99.5, 0, 50, 40)), false);
assert.equal(rectsOverlap(rect(0, 0, 100, 40), rect(0, 60, 100, 40)), false);
});
test("the built-in button border only uses an accent visible on its fixed light background", () => {
// Passes against the dark skin background, but vanishes on #fff7ed.
const pale = resolveRecoveryTokens({ background: "#141414", foreground: "#ffffff", accent: "#fff7ec" });
assert.equal(pale.accent, "rgb(255, 247, 236)");
assert.equal(pale.builtInBorder, "rgb(180, 83, 9)");
assert.ok(contrastRatio(parseCssColor(pale.builtInBorder)!, RECOVERY_BUILT_IN_BUTTON_BACKGROUND) >= RECOVERY_MIN_ACCENT_CONTRAST);
const strong = resolveRecoveryTokens({ background: "#ffffff", foreground: "#111111", accent: "#1d4ed8" });
assert.equal(strong.builtInBorder, "rgb(29, 78, 216)");
});
+21 -275
View File
@@ -17,6 +17,15 @@ import type { SkinChromeSlotAlign } from "../../../src/shared/skin-chrome.js";
import type { HostOwnedLayer } from "./host-owned-layer.js";
import { isHostPartReachable, type HostPartRect } from "./host-chrome-visibility.js";
import { PROTECTED_PART_IDS } from "../../../src/shared/skin-visual-parts.js";
import {
RECOVERY_CONTROL_DEFAULTS,
applyHostControlTokens,
createHostControlColorProbe,
findSkinRoot,
resolveHostControlTokens,
type HostControlTokens,
type HostControlColorProbe,
} from "./host-control-tokens.js";
export interface SlotViewport {
width: number;
@@ -190,229 +199,6 @@ export function nextSlotModeState(
};
}
/* ------------------------------------------------------------------ *
* Style tokens
* ------------------------------------------------------------------ */
export type RecoverySizeTier = "small" | "medium" | "large";
export interface RecoverySizeMetrics {
/** Host-enforced minimum button hit target in CSS pixels. */
readonly hitTarget: number;
/** Host-enforced minimum font size in CSS pixels. */
readonly fontSize: number;
}
export const RECOVERY_MIN_HIT_TARGET = 28;
export const RECOVERY_MIN_FONT_SIZE = 11;
export const RECOVERY_MIN_FOREGROUND_CONTRAST = 4.5;
export const RECOVERY_MIN_ACCENT_CONTRAST = 3;
/** Host-controlled metrics; a skin can choose a tier, never a smaller size. */
export const RECOVERY_SIZE_METRICS: Readonly<Record<RecoverySizeTier, RecoverySizeMetrics>> = {
small: { hitTarget: RECOVERY_MIN_HIT_TARGET, fontSize: RECOVERY_MIN_FONT_SIZE },
medium: { hitTarget: 32, fontSize: 12 },
large: { hitTarget: 36, fontSize: 13 },
};
export interface RecoveryRawTokens {
/** Computed-style colour values; unresolved CSS values are rejected. */
accent?: string;
background?: string;
foreground?: string;
radius?: string;
font?: string;
size?: string;
}
export interface RecoveryTokens {
accent: string;
/**
* Border of the built-in-skin button, which keeps its own fixed light
* background (`#fff7ed`). The skin accent is used only when it stays visible
* against that background; otherwise the host default accent is used there.
*/
builtInBorder: string;
background: string;
foreground: string;
radius: number;
font: string;
size: RecoverySizeTier;
hitTarget: number;
fontSize: number;
}
export interface RgbColor {
r: number;
g: number;
b: number;
}
/** CSS custom properties a skin declares on the anchor or an ancestor. */
export const RECOVERY_SKIN_TOKEN_PROPERTIES = {
accent: "--skin-recovery-accent",
background: "--skin-recovery-background",
foreground: "--skin-recovery-foreground",
radius: "--skin-recovery-radius",
font: "--skin-recovery-font",
size: "--skin-recovery-size",
} as const;
/** Host-owned variables set inside the closed shadow root. */
export const RECOVERY_APPLIED_VARIABLES = {
accent: "--ws-recovery-accent",
builtInBorder: "--ws-recovery-builtin-border",
background: "--ws-recovery-background",
foreground: "--ws-recovery-foreground",
radius: "--ws-recovery-radius",
font: "--ws-recovery-font",
hitTarget: "--ws-recovery-hit",
fontSize: "--ws-recovery-font-size",
} as const;
const DEFAULT_ACCENT: RgbColor = { r: 180, g: 83, b: 9 };
/** Fixed background of the built-in-skin button (`#fff7ed`). */
export const RECOVERY_BUILT_IN_BUTTON_BACKGROUND: RgbColor = { r: 255, g: 247, b: 237 };
const DEFAULT_BACKGROUND: RgbColor = { r: 255, g: 255, b: 255 };
const DEFAULT_FOREGROUND: RgbColor = { r: 49, g: 82, b: 79 };
const DEFAULT_RADIUS = 999;
const DEFAULT_FONT = "ui-sans-serif, system-ui, sans-serif";
const MAX_RADIUS = 999;
const MAX_FONT_LENGTH = 120;
const FONT_FAMILY_PATTERN = /^[A-Za-z0-9 ,'"-]{1,120}$/;
/** Parse `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()`. */
export function parseCssColor(value: string | undefined | null): RgbColor | null {
if (!value) return null;
const text = value.trim().toLowerCase();
const hex = /^#([0-9a-f]{3,8})$/.exec(text);
if (hex) {
const digits = hex[1];
if (digits.length === 3 || digits.length === 4) {
return {
r: Number.parseInt(digits[0] + digits[0], 16),
g: Number.parseInt(digits[1] + digits[1], 16),
b: Number.parseInt(digits[2] + digits[2], 16),
};
}
if (digits.length === 6 || digits.length === 8) {
return {
r: Number.parseInt(digits.slice(0, 2), 16),
g: Number.parseInt(digits.slice(2, 4), 16),
b: Number.parseInt(digits.slice(4, 6), 16),
};
}
return null;
}
const fn = /^rgba?\(([^()]*)\)$/.exec(text);
if (!fn) return null;
const parts = fn[1].replace(/\//g, " ").split(/[\s,]+/).filter(Boolean);
if (parts.length < 3 || parts.length > 4) return null;
const channels: number[] = [];
for (const part of parts.slice(0, 3)) {
const percent = part.endsWith("%");
const parsed = Number.parseFloat(part);
if (!Number.isFinite(parsed)) return null;
const channel = percent ? parsed * 2.55 : parsed;
channels.push(Math.round(Math.min(255, Math.max(0, channel))));
}
return { r: channels[0], g: channels[1], b: channels[2] };
}
export function formatRgb(color: RgbColor): string {
return `rgb(${color.r}, ${color.g}, ${color.b})`;
}
/** WCAG 2.x relative luminance, 0 (black) to 1 (white). */
export function relativeLuminance(color: RgbColor): number {
const channel = (value: number): number => {
const normalized = Math.min(255, Math.max(0, value)) / 255;
return normalized <= 0.03928 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * channel(color.r) + 0.7152 * channel(color.g) + 0.0722 * channel(color.b);
}
export function contrastRatio(first: RgbColor, second: RgbColor): number {
const lighter = Math.max(relativeLuminance(first), relativeLuminance(second));
const darker = Math.min(relativeLuminance(first), relativeLuminance(second));
return (lighter + 0.05) / (darker + 0.05);
}
export function isRecoverySizeTier(value: unknown): value is RecoverySizeTier {
return value === "small" || value === "medium" || value === "large";
}
function sanitizeRadius(value: string | undefined): number {
if (!value) return DEFAULT_RADIUS;
const match = /^(-?\d+(?:\.\d+)?)px$/i.exec(value.trim());
if (!match) return DEFAULT_RADIUS;
const radius = Number.parseFloat(match[1]);
return Number.isFinite(radius) ? Math.min(MAX_RADIUS, Math.max(0, radius)) : DEFAULT_RADIUS;
}
function sanitizeFont(value: string | undefined): string {
if (!value) return DEFAULT_FONT;
const font = value.trim().replace(/\s+/g, " ");
if (!font || font.length > MAX_FONT_LENGTH || !FONT_FAMILY_PATTERN.test(font) || !/[A-Za-z0-9]/.test(font)) {
return DEFAULT_FONT;
}
return font;
}
/**
* Sanitize skin-provided tokens. Colours are all-or-nothing: a readable
* foreground/background pair and a visible accent keep the skin palette;
* otherwise the whole colour group reverts to the host palette so a skin can
* never make the recovery action unreadable.
*/
export function resolveRecoveryTokens(raw: RecoveryRawTokens = {}): RecoveryTokens {
const accent = parseCssColor(raw.accent) ?? DEFAULT_ACCENT;
const background = parseCssColor(raw.background) ?? DEFAULT_BACKGROUND;
const foreground = parseCssColor(raw.foreground) ?? DEFAULT_FOREGROUND;
const readable = contrastRatio(foreground, background) >= RECOVERY_MIN_FOREGROUND_CONTRAST
&& contrastRatio(accent, background) >= RECOVERY_MIN_ACCENT_CONTRAST;
const palette = readable ? { accent, background, foreground } : {
accent: DEFAULT_ACCENT,
background: DEFAULT_BACKGROUND,
foreground: DEFAULT_FOREGROUND,
};
const sizeValue = raw.size?.trim();
const size = isRecoverySizeTier(sizeValue) ? sizeValue : "small";
const metrics = RECOVERY_SIZE_METRICS[size];
const builtInBorder = contrastRatio(palette.accent, RECOVERY_BUILT_IN_BUTTON_BACKGROUND) >= RECOVERY_MIN_ACCENT_CONTRAST
? palette.accent
: DEFAULT_ACCENT;
return {
accent: formatRgb(palette.accent),
builtInBorder: formatRgb(builtInBorder),
background: formatRgb(palette.background),
foreground: formatRgb(palette.foreground),
radius: sanitizeRadius(raw.radius),
font: sanitizeFont(raw.font),
size,
hitTarget: metrics.hitTarget,
fontSize: metrics.fontSize,
};
}
/** Apply (or clear) host-owned variables on the control inside the shadow root. */
export function applyRecoveryTokens(control: HTMLElement, tokens: RecoveryTokens | null): void {
const style = control.style;
if (!tokens) {
for (const property of Object.values(RECOVERY_APPLIED_VARIABLES)) style.removeProperty(property);
return;
}
style.setProperty(RECOVERY_APPLIED_VARIABLES.accent, tokens.accent);
style.setProperty(RECOVERY_APPLIED_VARIABLES.builtInBorder, tokens.builtInBorder);
style.setProperty(RECOVERY_APPLIED_VARIABLES.background, tokens.background);
style.setProperty(RECOVERY_APPLIED_VARIABLES.foreground, tokens.foreground);
style.setProperty(RECOVERY_APPLIED_VARIABLES.radius, `${tokens.radius}px`);
style.setProperty(RECOVERY_APPLIED_VARIABLES.font, tokens.font);
style.setProperty(RECOVERY_APPLIED_VARIABLES.hitTarget, `${tokens.hitTarget}px`);
style.setProperty(RECOVERY_APPLIED_VARIABLES.fontSize, `${tokens.fontSize}px`);
}
/* ------------------------------------------------------------------ *
* DOM binding
* ------------------------------------------------------------------ */
@@ -506,14 +292,6 @@ export function resolveSkinAnchor(
return null;
}
/** The active skin's root element; the token source while no anchor is usable. */
export function findSkinRoot(skinId: string | undefined, doc: Document = document): Element | null {
for (const root of doc.querySelectorAll(".ws-skin-root")) {
if (!skinId || root.getAttribute("data-ws-skin") === skinId) return root;
}
return null;
}
export interface HostSlotModeChange {
mode: "slotted" | "floating";
reason?: SlotFailureReason;
@@ -560,7 +338,7 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding {
let lastReason: SlotFailureReason | undefined;
let currentAnchor: HTMLElement | null = null;
let observer: ResizeObserver | null = null;
let probe: HTMLElement | null = null;
const colorProbe: HostControlColorProbe = createHostControlColorProbe(layer.shadow);
let frame: number | undefined;
let timer: ReturnType<typeof setTimeout> | undefined;
let disposed = false;
@@ -570,45 +348,14 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding {
const requestFrame = (callback: FrameRequestCallback): number => win.requestAnimationFrame(callback);
const cancelFrame = (handle: number): void => win.cancelAnimationFrame(handle);
function ensureProbe(): HTMLElement | null {
if (probe) return probe;
probe = doc.createElement("span");
probe.setAttribute("aria-hidden", "true");
probe.style.cssText = "position:absolute;left:-9999px;top:0;width:0;height:0;visibility:hidden;pointer-events:none;";
layer.shadow.append(probe);
return probe;
}
/** Resolve a CSS colour through the browser, inside the closed shadow root. */
function probeColor(raw: string | undefined): string | undefined {
if (!raw) return undefined;
const element = ensureProbe();
if (!element) return undefined;
// An invalid value leaves the previous colour in place. Probe against two
// different sentinels so a real token equal to one of them still resolves.
const resolveWith = (sentinel: string): string => {
element.style.color = sentinel;
element.style.color = raw;
return win.getComputedStyle(element).color;
};
const first = resolveWith("rgb(1, 2, 3)");
if (first !== "rgb(1, 2, 3)") return first;
const second = resolveWith("rgb(4, 5, 6)");
return second === "rgb(4, 5, 6)" ? undefined : second;
}
function readTokens(source: Element | null): RecoveryTokens {
if (!source) return resolveRecoveryTokens();
const style = win.getComputedStyle(source);
const read = (property: string): string | undefined => style.getPropertyValue(property).trim() || undefined;
return resolveRecoveryTokens({
accent: probeColor(read(RECOVERY_SKIN_TOKEN_PROPERTIES.accent)),
background: probeColor(read(RECOVERY_SKIN_TOKEN_PROPERTIES.background)),
foreground: probeColor(read(RECOVERY_SKIN_TOKEN_PROPERTIES.foreground)),
radius: read(RECOVERY_SKIN_TOKEN_PROPERTIES.radius),
font: read(RECOVERY_SKIN_TOKEN_PROPERTIES.font),
size: read(RECOVERY_SKIN_TOKEN_PROPERTIES.size),
});
function readTokens(source: Element | null): HostControlTokens {
if (!source) return resolveHostControlTokens(null, "host.recovery", colorProbe.probeColor, RECOVERY_CONTROL_DEFAULTS);
return resolveHostControlTokens(
win.getComputedStyle(source),
"host.recovery",
colorProbe.probeColor,
RECOVERY_CONTROL_DEFAULTS,
);
}
function clearPlacement(): void {
@@ -656,7 +403,7 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding {
const tokenSource = anchorElement
?? (options.skinId ? findSkinRoot(options.skinId, doc) : null);
const tokens = readTokens(tokenSource);
applyRecoveryTokens(control, tokenSource ? tokens : null);
applyHostControlTokens(control, tokenSource ? tokens : null);
const controlBox = control.getBoundingClientRect();
maxSize = {
@@ -783,9 +530,8 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding {
win.removeEventListener("resize", schedule);
win.removeEventListener("scroll", schedule, { capture: true });
clearPlacement();
applyRecoveryTokens(control, null);
probe?.remove();
probe = null;
applyHostControlTokens(control, null);
colorProbe.dispose();
},
};
}