From 2bdc866c85198acb143accaf1dedfeff22b6f9d0 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Mon, 2 Nov 2026 11:41:01 -0800 Subject: [PATCH] fix(core): a canvas in a blurred composition stays where it was laid out (#6975) * fix(core): a canvas in a blurred composition stays where it was laid out drawElementImage drops a nested canvas's layout offset unless the canvas has a transform, so with capture blur on, `top: 200px` painted at 0. A zero `translate` while captured is enough, and leaves `top`, the composition's own `transform` and its `translate` alone. Co-Authored-By: Claude Opus 5.5 * fix(core): give the nested canvas rule no specificity A class on a composition's canvas lost to the rule, so its own `translate` was dropped while captured. Under `:where()` any composition rule wins. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../core/src/runtime/captureMotionBlur/index.test.ts | 12 ++++++++++++ packages/core/src/runtime/captureMotionBlur/index.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/core/src/runtime/captureMotionBlur/index.test.ts b/packages/core/src/runtime/captureMotionBlur/index.test.ts index ae56a62eb3..cedd037a0c 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.test.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.test.ts @@ -681,6 +681,18 @@ const HIDE = "data-hf-motion-blur-hide"; const ONLY = "data-hf-motion-blur-only"; const MOVER = "data-hf-motion-blur-mover"; +describe("a canvas inside the composition", () => { + // Chrome drops a nested canvas's layout offset from drawElementImage unless it has a transform. + it("gets a transform while captured, one the composition's own translate overrides", () => { + installHtmlInCanvas(); + const { h } = movingHost({ "data-motion-blur": "on" }); + initCaptureMotionBlur(h); + void paintCaptureMotionBlur(0.1, PLAY); + const rules = [...document.head.querySelectorAll("style")].map((s) => s.textContent).join("\n"); + expect(rules).toContain(`:where([data-hf-motion-blur="capture"] canvas) { translate: 0 0 0; }`); + }); +}); + describe("two-phase frames", () => { it("hides the movers for a background capture, then reveals them and settles", async () => { installHtmlInCanvas(); diff --git a/packages/core/src/runtime/captureMotionBlur/index.ts b/packages/core/src/runtime/captureMotionBlur/index.ts index 7750c6fc7e..f21954bd45 100644 --- a/packages/core/src/runtime/captureMotionBlur/index.ts +++ b/packages/core/src/runtime/captureMotionBlur/index.ts @@ -65,6 +65,7 @@ const HIDE_ATTR = "data-hf-motion-blur-hide"; /** On the root while the movers alone are captured; the movers carry MOVER_ATTR. */ const ONLY_ATTR = "data-hf-motion-blur-only"; const MOVER_ATTR = "data-hf-motion-blur-mover"; +const NESTED_CANVAS_KEEPS_ITS_PLACE = `:where([data-hf-motion-blur="capture"] canvas) { translate: 0 0 0; }`; interface Job { seq: number; @@ -170,6 +171,7 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI `[${ONLY_ATTR}] { background: none !important; border-color: transparent !important; box-shadow: none !important; outline-color: transparent !important; }`, `[${ONLY_ATTR}]::before, [${ONLY_ATTR}]::after, [${ONLY_ATTR}] *:not([${MOVER_ATTR}], [${MOVER_ATTR}] *) { visibility: hidden !important; }`, `[${ONLY_ATTR}] [${MOVER_ATTR}] { visibility: visible !important; }`, + NESTED_CANVAS_KEEPS_ITS_PLACE, ].join("\n"); let movers: HTMLElement[] = [];