Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/engine/src/services/drawElementService.dom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @vitest-environment happy-dom

import { afterEach, describe, expect, it } from "vitest";
import type { Page } from "puppeteer-core";
import { injectDrawElementCanvas } from "./drawElementService.js";

describe("injectDrawElementCanvas", () => {
afterEach(() => {
document.body.replaceChildren();
Reflect.deleteProperty(window, "__HF_ROOT_BASE_OPACITY__");
});

it("preserves a zero composition root opacity", async () => {
const root = document.createElement("main");
root.dataset.compositionId = "test";
root.style.opacity = "0";
document.body.appendChild(root);

const page = {
evaluate: async <T, A>(callback: (arg: A) => T, arg: A) => callback(arg),
} as unknown as Page;

await injectDrawElementCanvas(page, 1920, 1080);

expect(
(window as unknown as { __HF_ROOT_BASE_OPACITY__?: number }).__HF_ROOT_BASE_OPACITY__,
).toBe(0);
});
});
3 changes: 2 additions & 1 deletion packages/engine/src/services/drawElementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ export async function injectDrawElementCanvas(
// current opacity into the snapshot — BeginFrame (sync=false) captures
// and builds without canvas.requestPaint(); see __hfDeInvalidate below.
try {
const parsedBaseOpacity = parseFloat(getComputedStyle(root).opacity);
(window as unknown as { __HF_ROOT_BASE_OPACITY__?: number }).__HF_ROOT_BASE_OPACITY__ =
parseFloat(getComputedStyle(root).opacity) || 1;
Number.isFinite(parsedBaseOpacity) ? parsedBaseOpacity : 1;
} catch {
/* leave undefined → ratio defaults to 1 */
}
Expand Down