From f523ee2fcacdbe792561209dd8309cb01a116fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 30 Oct 2026 01:47:19 +0000 Subject: [PATCH] fix(cli): check flags caption words hidden behind a cut-out and ignores a mostly transparent cover (#6770) * fix(cli): check flags caption words hidden behind a cut-out and ignores a mostly transparent cover * fix(cli): a caption word's lifetime is shifted only by its composition hosts --- .../cli/src/commands/layout-audit.browser.js | 26 ++++++++++- .../layout-audit.video-alpha.browser.test.ts | 45 ++++++++++++++++++- packages/cli/src/commands/layout.ts | 2 +- packages/cli/src/utils/checkBrowser.ts | 4 ++ packages/cli/src/utils/checkPipeline.ts | 6 +-- packages/cli/src/utils/layoutAudit.test.ts | 32 +++++++++++++ packages/cli/src/utils/layoutAudit.ts | 29 ++++++++++-- 7 files changed, 134 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/commands/layout-audit.browser.js b/packages/cli/src/commands/layout-audit.browser.js index b1bf1fdc93..b15244bc84 100644 --- a/packages/cli/src/commands/layout-audit.browser.js +++ b/packages/cli/src/commands/layout-audit.browser.js @@ -1605,6 +1605,24 @@ return false; } + // The global window [start, end) the element's own timed clip is on screen, or null when any timing + // up the chain is not a plain number. Only composition hosts shift their children's clock. + function clipLifetime(element) { + const own = element.closest("[data-start]"); + if (!own) return null; + const start = Number(own.getAttribute("data-start")); + const duration = Number(own.getAttribute("data-duration")); + if (!Number.isFinite(start) || !(duration > 0)) return null; + let offset = 0; + for (let host = own.parentElement; host; host = host.parentElement) { + if (!host.hasAttribute("data-composition-id") || !host.hasAttribute("data-start")) continue; + const hostStart = Number(host.getAttribute("data-start")); + if (!Number.isFinite(hostStart)) return null; + offset += hostStart; + } + return { start: start + offset, end: start + duration + offset }; + } + // text_occluded: atomic labels flag at any hit; prose needs coveredFraction >= proseCoverageFloor (default 0.15). function occludedTextIssue(element, time, proseCoverageFloor, matteResults) { if (hasAllowOcclusionFlag(element)) return null; @@ -1708,6 +1726,8 @@ ) continue; // Last: an opaque check reads a video's frame, which a backdrop under its content never needs. + const matte = matteFrameFor(cover); + if (matte && matteCoverage([rootRect], [matte]) < COVER_CANVAS_SHARE) continue; const rect = toRect(cover.getBoundingClientRect()); if (!isOpaqueOccluder(cover, rect.left + rect.width / 2, rect.top + rect.height / 2)) continue; @@ -2550,7 +2570,11 @@ if (clipped) issues.push(clipped); issues.push(...textOverflowIssues(element, root, rootRect, time, tolerance, clipped)); const occluded = occludedTextIssue(element, time, proseCoverageFloor, matteResults); - if (occluded) issues.push(occluded); + if (occluded) { + const lifetime = clipLifetime(element); + if (lifetime) occluded.lifetime = lifetime; + issues.push(occluded); + } const invisible = invisibleTextIssue(element, time); if (invisible) issues.push(invisible); } diff --git a/packages/cli/src/commands/layout-audit.video-alpha.browser.test.ts b/packages/cli/src/commands/layout-audit.video-alpha.browser.test.ts index 16a601b76f..c661083972 100644 --- a/packages/cli/src/commands/layout-audit.video-alpha.browser.test.ts +++ b/packages/cli/src/commands/layout-audit.video-alpha.browser.test.ts @@ -43,6 +43,10 @@ interface VideoScene { /** Report each element's text as one line box, as Chromium does, rather than one per word. */ wholeLine?: boolean; textAttrs?: string; + /** Size each text element to its first word's box instead of the whole frame. */ + sizedText?: boolean; + /** Attributes on the timed wrapper around the text. */ + lineAttrs?: string; } function domRect({ left, top, width, height }: Box): DOMRect { @@ -88,7 +92,7 @@ function installVideoScene(scene: VideoScene): { getImageData: ReturnType -
${spans}
+
${spans}
`; @@ -111,6 +115,18 @@ function installVideoScene(scene: VideoScene): { getImageData: ReturnType { const owner = node?.parentElement?.id ?? ""; const word = (node?.textContent ?? "").slice(start, end); @@ -202,6 +218,8 @@ function runAudit(): AuditIssue[] { const occlusionOf = (issues: AuditIssue[], id: string) => issues.find((issue) => issue.code === "text_occluded" && issue.selector === `#${id}`); +const coverOf = (issues: AuditIssue[]) => issues.find((issue) => issue.code === "canvas_covered"); + const SHIP = { ship: [{ word: "SHIP", left: 800, width: 200 }] }; const subjectLeftOf = (edge: number) => (x: number) => (x < edge ? 255 : 0); @@ -213,6 +231,31 @@ describe("layout-audit.browser text behind a