Skip to content

Commit b693e0c

Browse files
vanceingallsclaude
andcommitted
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 <[email protected]>
1 parent 9fa02ba commit b693e0c

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎packages/core/src/runtime/captureMotionBlur/index.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,18 @@ const HIDE = "data-hf-motion-blur-hide";
659659
const ONLY = "data-hf-motion-blur-only";
660660
const MOVER = "data-hf-motion-blur-mover";
661661

662+
describe("a canvas inside the composition", () => {
663+
// Chrome drops a nested canvas's layout offset from drawElementImage unless it has a transform.
664+
it("gets a transform while captured, one the composition's own translate overrides", () => {
665+
installHtmlInCanvas();
666+
const { h } = movingHost({ "data-motion-blur": "on" });
667+
initCaptureMotionBlur(h);
668+
void paintCaptureMotionBlur(0.1, PLAY);
669+
const rules = [...document.head.querySelectorAll("style")].map((s) => s.textContent).join("\n");
670+
expect(rules).toContain(`[data-hf-motion-blur="capture"] canvas { translate: 0 0 0; }`);
671+
});
672+
});
673+
662674
describe("two-phase frames", () => {
663675
it("hides the movers for a background capture, then reveals them and settles", async () => {
664676
installHtmlInCanvas();

‎packages/core/src/runtime/captureMotionBlur/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const HIDE_ATTR = "data-hf-motion-blur-hide";
6565
/** On the root while the movers alone are captured; the movers carry MOVER_ATTR. */
6666
const ONLY_ATTR = "data-hf-motion-blur-only";
6767
const MOVER_ATTR = "data-hf-motion-blur-mover";
68+
const NESTED_CANVAS_KEEPS_ITS_PLACE = `[data-hf-motion-blur="capture"] canvas { translate: 0 0 0; }`;
6869

6970
interface Job {
7071
seq: number;
@@ -170,6 +171,7 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
170171
`[${ONLY_ATTR}] { background: none !important; border-color: transparent !important; box-shadow: none !important; outline-color: transparent !important; }`,
171172
`[${ONLY_ATTR}]::before, [${ONLY_ATTR}]::after, [${ONLY_ATTR}] *:not([${MOVER_ATTR}], [${MOVER_ATTR}] *) { visibility: hidden !important; }`,
172173
`[${ONLY_ATTR}] [${MOVER_ATTR}] { visibility: visible !important; }`,
174+
NESTED_CANVAS_KEEPS_ITS_PLACE,
173175
].join("\n");
174176

175177
let movers: HTMLElement[] = [];

0 commit comments

Comments
 (0)