From ae6788a796ed6ba8f01a54663f82cb0cdffdd3cd Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:16:36 +0800 Subject: [PATCH] fix: correct recovery placement and quoted skin animations --- src/shared/skin-css.test.ts | 13 +++++++ src/shared/skin-css.ts | 4 ++ web/src/services/host-floating-placement.ts | 8 ++++ web/src/services/host-slot-placement.ts | 4 ++ .../fixtures/host-floating-transient.html | 20 +++++++++- web/test/fixtures/host-slot-placement.html | 16 ++++++++ web/test/host-chrome-recovery.test.mjs | 38 +++++++++++++++++++ 7 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/shared/skin-css.test.ts b/src/shared/skin-css.test.ts index 6943b80..693438b 100644 --- a/src/shared/skin-css.test.ts +++ b/src/shared/skin-css.test.ts @@ -682,6 +682,19 @@ test("escaped, namespaced and :is()/:where() animation names cannot bypass the p assert.match(webkit.css, /-webkit-animation: ws-demo-skin-fade 2s ease/); }); +test("quoted animation names stay names even when they match shorthand keywords", () => { + for (const name of ["linear", "ease", "reverse", "paused", "infinite", "none", "initial"]) { + const frames = `@keyframes ${name} { from { opacity: .5; } to { opacity: 1; } }`; + const shorthand = compile(`${frames} [data-ws-part="home.feature"] { animation: "${name}" 2s ease-in-out infinite; }`); + assert.ok(shorthand.css.includes(`animation: "ws-demo-skin-${name}" 2s ease-in-out infinite`), shorthand.css); + const longhand = compile(`${frames} [data-ws-part="home.feature"] { animation-name: "${name}"; }`); + assert.ok(longhand.css.includes(`animation-name: "ws-demo-skin-${name}"`), longhand.css); + assert.throws(() => compile(`@keyframes ${name} { to { opacity: 0; } } [data-ws-part="voice.audio-dock"] { animation: "${name}" 1s ease; }`), /must remain available/); + } + const layers = compile('@keyframes linear { to { opacity: 1; } } @keyframes paused { to { opacity: 1; } } [data-ws-part="home.feature"] { animation: "linear" 2s ease, "paused" 3s linear; }'); + assert.ok(layers.css.includes('animation: "ws-demo-skin-linear" 2s ease, "ws-demo-skin-paused" 3s linear'), layers.css); +}); + test("keyframes cannot turn the plugin overlay into a fullscreen layer", () => { for (const css of [ '@keyframes k { to { position: fixed; inset: 0; z-index: 2147483647; } } [data-ws-part="host.plugins.overlay"] { animation: k 1s forwards; }', diff --git a/src/shared/skin-css.ts b/src/shared/skin-css.ts index 384a49d..57a69b6 100644 --- a/src/shared/skin-css.ts +++ b/src/shared/skin-css.ts @@ -871,11 +871,15 @@ function parseAnimationLayers(value: string, property: string): { parsed: Return const names = groups.map((nodes) => { const words = nodes.filter((node) => node.type === "word" || node.type === "string"); if (property === "animation-name") { + if (words[0]?.type === "string") return words[0]; const name = words[0] ? decodeCssEscapes(words[0].value).toLowerCase() : ""; return words[0] && name !== "none" && !CSS_WIDE_KEYWORDS.has(name) ? words[0] : null; } const used = new Set(); for (const node of words) { + // Quoted strings always name keyframes, even "linear" or "none"; + // only unquoted words may fill the shorthand's keyword slots. + if (node.type === "string") return node; const token = decodeCssEscapes(node.value).toLowerCase(); const dimension = parseDimension(token); if (dimension && ["", "s", "ms"].includes(dimension.unit)) continue; diff --git a/web/src/services/host-floating-placement.ts b/web/src/services/host-floating-placement.ts index b8e649a..3499677 100644 --- a/web/src/services/host-floating-placement.ts +++ b/web/src/services/host-floating-placement.ts @@ -563,6 +563,14 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati function screenChanged() { if (disposed) return; for (const pending of screenTimers) clearTimeout(pending); + if (confirmTimer) clearTimeout(confirmTimer); + confirmTimer = undefined; + // Freeze and move history belong to the old screen. Carrying them over + // can strand the capsule on a newly mounted microphone or other control. + frozenUntil = 0; + frozenEscaped = false; + moveTimes = []; + lastMoveAt = Number.NEGATIVE_INFINITY; pendingSince = 0; urgentUntil = Date.now() + HOST_FLOATING_SCREEN_CHANGE_MS; screenTimers = HOST_FLOATING_SCREEN_CHANGE_SAMPLES_MS.map(delay => setTimeout(safeEvaluate, delay)); diff --git a/web/src/services/host-slot-placement.ts b/web/src/services/host-slot-placement.ts index 4050f44..ec1d156 100644 --- a/web/src/services/host-slot-placement.ts +++ b/web/src/services/host-slot-placement.ts @@ -364,6 +364,7 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding { control.style.removeProperty("top"); control.style.removeProperty("right"); control.style.removeProperty("bottom"); + control.style.removeProperty("translate"); } function applyPlacement(left: number, top: number): void { @@ -372,6 +373,9 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding { control.style.top = `${top}px`; control.style.right = "auto"; control.style.bottom = "auto"; + // Floating positions may centre the capsule with a percentage translate. + // Slot coordinates already include alignment, including during hit tests. + control.style.translate = "none"; } function hitTestAt(left: number, top: number, size: { width: number; height: number }): boolean { diff --git a/web/test/fixtures/host-floating-transient.html b/web/test/fixtures/host-floating-transient.html index 6f5301a..6a47ec1 100644 --- a/web/test/fixtures/host-floating-transient.html +++ b/web/test/fixtures/host-floating-transient.html @@ -134,10 +134,28 @@ try { movesWhileHeld: moves.length - heldFrom, sinceFreezeMs: Math.round(performance.now() - pinnedAt), }); + + // A different screen must not inherit the old screen's exhausted freeze + // escape or move history. Its microphone now occupies the parked spot. + const frozenPosition = binding.position; + document.getElementById("walls").remove(); + hopper.setAttribute("data-ws-part", "voice.audio-dock.microphone"); + chase(lib); + const coveredBeforeScreenChange = coveredByLib(hopper); + binding.screenChanged(); + await sleep(200); + binding.revalidate(); + results.push({ + name: "screen-change-during-freeze", + frozenPosition, + position: binding.position, + coveredBeforeScreenChange, + microphoneCovered: coveredByLib(hopper), + sinceFreezeMs: Math.round(performance.now() - pinnedAt), + }); binding.dispose(); lib.remove(); hopper.remove(); - document.getElementById("walls").remove(); accompaniment.style.display = ""; } diff --git a/web/test/fixtures/host-slot-placement.html b/web/test/fixtures/host-slot-placement.html index 7a57413..e72d64d 100644 --- a/web/test/fixtures/host-slot-placement.html +++ b/web/test/fixtures/host-slot-placement.html @@ -34,6 +34,8 @@ const CSS = ` background: var(--ws-control-background, #fff); color: var(--ws-control-foreground, #31524f); } +.cap[data-ws-float^="middle"] { bottom: auto; top: 50%; translate: 0 -50%; } +.cap[data-ws-float$="center"] { left: 50%; translate: -50% 0; } .cap button { min-height: var(--ws-control-hit, 28px); padding: 0 8px; } `; try { @@ -80,6 +82,20 @@ try { const results = []; results.push(snap("initial")); + // A floating fallback may have moved to a centred position. Its CSS + // translation must not offset the slot's fixed coordinates or hit test. + for (const position of ["middle-left", "middle-right", "top-center", "bottom-center"]) { + anchor.style.display = "none"; + binding.revalidate(); + control.dataset.wsFloat = position; + results.push({ ...snap(`fallback-${position}`), translated: getComputedStyle(control).translate !== "none" }); + anchor.style.display = ""; + binding.revalidate(); + binding.revalidate(); + results.push({ ...snap(`redocked-${position}`), translate: getComputedStyle(control).translate }); + } + delete control.dataset.wsFloat; + anchor.style.display = "none"; binding.revalidate(); results.push(snap("anchor-hidden")); diff --git a/web/test/host-chrome-recovery.test.mjs b/web/test/host-chrome-recovery.test.mjs index 4ba197d..09318b8 100644 --- a/web/test/host-chrome-recovery.test.mjs +++ b/web/test/host-chrome-recovery.test.mjs @@ -275,6 +275,17 @@ test("a declared slot docks the capsule and falls back at runtime", { skip: !CHR assert.equal(initial.color, "rgb(255, 255, 255)", "skin foreground token was not applied"); assert.ok(initial.buttonHeight >= 36, "the large size tier minimum was not enforced"); + for (const position of ["middle-left", "middle-right", "top-center", "bottom-center"]) { + const fallback = byName[`fallback-${position}`]; + assert.equal(fallback.mode, "floating", JSON.stringify(fallback)); + assert.equal(fallback.translated, true, "floating CSS translation was not restored"); + const docked = byName[`redocked-${position}`]; + assert.equal(docked.mode, "slotted", JSON.stringify(docked)); + assert.equal(docked.insideAnchor, true, JSON.stringify(docked)); + assert.equal(docked.hitIsLayerHost, true, JSON.stringify(docked)); + assert.equal(docked.translate, "none", JSON.stringify(docked)); + } + assert.equal(byName["anchor-hidden"].mode, "floating"); assert.equal(byName["anchor-hidden"].reason, "anchor-missing"); assert.equal(byName["anchor-hidden"].inlineLeft, ""); @@ -417,6 +428,33 @@ test("floating host controls see through toasts and still step off a control whi assert.notEqual(freeze.escapes[0].position, "bottom-right", JSON.stringify(freeze)); assert.ok(freeze.escapes[0].afterPinMs < 3000, JSON.stringify(freeze)); assert.equal(freeze.movesWhileHeld, 0, JSON.stringify(freeze)); + + const screen = byName["screen-change-during-freeze"]; + assert.ok(screen.sinceFreezeMs < 10000, "the test must switch screens before the old freeze expires"); + assert.equal(screen.coveredBeforeScreenChange, true, JSON.stringify(screen)); + assert.notEqual(screen.position, screen.frozenPosition, JSON.stringify(screen)); + assert.equal(screen.microphoneCovered, false, JSON.stringify(screen)); +}); + +test("compiled quoted keyword animations still run in the browser", { skip: !CHROME && "google-chrome is not installed" }, async () => { + const raw = '@keyframes linear { from { opacity: .5; } to { opacity: 1; } } [data-ws-part="home.feature"] { animation: "linear" 10s ease-in-out infinite; }'; + const compiled = compileSkinCss(raw, "community.animation-fixture", {}, 3).css; + const html = ` +
Feature
+
`;
+  const dom = await dumpDom(`data:text/html;base64,${Buffer.from(html).toString("base64")}`);
+  const match = dom.match(/
]*>([\s\S]*?)<\/pre>/);
+  assert.ok(match, "the animation fixture did not emit a result block");
+  const payload = JSON.parse(match[1]);
+  assert.equal(payload.before, 1, JSON.stringify(payload));
+  assert.equal(payload.after, 1, JSON.stringify(payload));
 });
 
 test("host control tokens follow late skin CSS, resolve modern colours and refuse skin fonts", { skip: !CHROME && "google-chrome is not installed" }, async (t) => {