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
8 changes: 5 additions & 3 deletions packages/cli/src/commands/layout-audit.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1664,13 +1664,15 @@
// part of a transient crossfade overlap.
// fallow-ignore-next-line complexity
function occluderAt(element, x, y, seenMattes) {
// The text, its ancestors, and its descendants end the stack walk before any foreign layer can count.
const topHit = document.elementFromPoint?.(x, y);
if (topHit && !isForeignElement(element, topHit)) return null;

// Walk the paint-ordered stack: a transparent layer on top must not mask an opaque one below it.
const stack =
typeof document.elementsFromPoint === "function"
? document.elementsFromPoint(x, y)
: typeof document.elementFromPoint === "function"
? [document.elementFromPoint(x, y)].filter(Boolean)
: [];
: [topHit];
for (const hit of stack) {
if (!isForeignElement(element, hit)) return null;
// Pair-specific exemptions excuse this hit only; keep walking for deeper occluders.
Expand Down
29 changes: 29 additions & 0 deletions packages/cli/src/commands/layout-audit.chromium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ describe.runIf(executablePath)("layout audit in Chromium", () => {
}
}

it("skips full hit-test stacks for visible text but sees through transparent overlays", async () => {
const page = await browser.newPage();
const labels = stage(heading(50, "Visible") + heading(300, "Covered"));
const overlay = "position:fixed;left:80px;top:290px;width:570px;height:145px;";
try {
await page.setContent(
`<body style="margin:0">${labels}<div id="cover" style="${overlay}background:#000;z-index:1"></div><div style="${overlay}z-index:2"></div></body>`,
);
await page.addScriptTag({ content: script });
const { visibleStacks, occlusions } = await page.evaluate(() => {
let visibleStacks = 0;
const elementsFromPoint = document.elementsFromPoint.bind(document);
document.elementsFromPoint = (x, y) => {
if (y < 200) visibleStacks += 1;
return elementsFromPoint(x, y);
};
const occlusions = window
.__hyperframesLayoutAudit({ time: 1, tolerance: 2 })
.filter((issue) => issue.code === "text_occluded");
return { visibleStacks, occlusions };
});
expect(visibleStacks).toBe(0);
expect(occlusions).toHaveLength(1);
expect(occlusions[0]).toMatchObject({ text: "Covered", containerSelector: "#cover" });
} finally {
await page.close();
}
});

function gradientHeading(content: string, backgroundStyle = ""): string {
return `<div data-composition-id="main" data-width="640" data-height="360" style="position:relative;width:640px;height:360px;background:#0a0a0a">
<h1 style="position:absolute;left:40px;top:100px;width:560px;margin:0;font:700 64px/1.2 Arial;-webkit-text-fill-color:transparent;background-image:linear-gradient(90deg,#f4f4f4,#f5e6c8);background-clip:text;${backgroundStyle}">${content}</h1>
Expand Down