|
1604 | 1604 | }; |
1605 | 1605 | } |
1606 | 1606 |
|
| 1607 | + // canvas_covered: an opaque element over most of the canvas with every other painted clip beneath it. |
| 1608 | + const COVER_CANVAS_SHARE = 0.9; |
| 1609 | + const COVERED_CONTENT_SHARE = 0.9; |
| 1610 | + |
| 1611 | + function paintsOwnContent(element) { |
| 1612 | + return ( |
| 1613 | + hasOwnTextCandidate(element, true) || |
| 1614 | + FRAME_MEDIA_TAGS.has(element.tagName.toUpperCase()) || |
| 1615 | + hasPaint(getComputedStyle(element)) |
| 1616 | + ); |
| 1617 | + } |
| 1618 | + |
| 1619 | + function onCanvasRect(element, rootRect) { |
| 1620 | + const rect = toRect(element.getBoundingClientRect()); |
| 1621 | + const left = Math.max(rect.left, rootRect.left); |
| 1622 | + const top = Math.max(rect.top, rootRect.top); |
| 1623 | + const right = Math.min(rect.right, rootRect.right); |
| 1624 | + const bottom = Math.min(rect.bottom, rootRect.bottom); |
| 1625 | + return right > left && bottom > top |
| 1626 | + ? rectFromOrigin(left, top, right - left, bottom - top) |
| 1627 | + : null; |
| 1628 | + } |
| 1629 | + |
| 1630 | + // Topmost first, and a centre probe before the grid: a backdrop under its content clears on the first clip. |
| 1631 | + function isBuried(element, rootRect) { |
| 1632 | + const rect = onCanvasRect(element, rootRect); |
| 1633 | + if (!rect) return true; |
| 1634 | + if (!occluderAt(element, rect.left + rect.width / 2, rect.top + rect.height / 2)) return false; |
| 1635 | + return occlusionCoverage(element, [rect]).coveredFraction >= COVERED_CONTENT_SHARE; |
| 1636 | + } |
| 1637 | + |
| 1638 | + function spansCanvas(element, rootRect) { |
| 1639 | + const rect = toRect(element.getBoundingClientRect()); |
| 1640 | + return intersectionArea(rect, rootRect) >= rectArea(rootRect) * COVER_CANVAS_SHARE; |
| 1641 | + } |
| 1642 | + |
| 1643 | + function visibleElementsIn(root) { |
| 1644 | + return Array.from(root.querySelectorAll("*")).filter((element) => |
| 1645 | + isVisibleElement(element, 0.05), |
| 1646 | + ); |
| 1647 | + } |
| 1648 | + |
| 1649 | + // Only frame 0 asks: the craft sweep samples at 8 fps and the scan restores hit testing on every node. |
| 1650 | + function canvasCoverAt(root, rootRect) { |
| 1651 | + const restoreHits = restoreHitTesting(root); |
| 1652 | + try { |
| 1653 | + return canvasCoveredIssue(root, rootRect, visibleElementsIn(root), 0); |
| 1654 | + } finally { |
| 1655 | + restoreHits(); |
| 1656 | + } |
| 1657 | + } |
| 1658 | + |
| 1659 | + function canvasCoveredIssue(root, rootRect, elements, time) { |
| 1660 | + for (const cover of elements) { |
| 1661 | + if (cover === root || hasAllowOcclusionFlag(cover) || !spansCanvas(cover, rootRect)) continue; |
| 1662 | + // A buried backdrop is not a lost clip: full-frame b-roll over a background is the film. |
| 1663 | + const beneath = elements.filter( |
| 1664 | + (element) => |
| 1665 | + element !== cover && |
| 1666 | + !element.contains(cover) && |
| 1667 | + paintsOwnContent(element) && |
| 1668 | + !spansCanvas(element, rootRect), |
| 1669 | + ); |
| 1670 | + if ( |
| 1671 | + beneath.length === 0 || |
| 1672 | + !beneath.reverse().every((element) => isBuried(element, rootRect)) |
| 1673 | + ) |
| 1674 | + continue; |
| 1675 | + // Last: an opaque check reads a video's frame, which a backdrop under its content never needs. |
| 1676 | + const rect = toRect(cover.getBoundingClientRect()); |
| 1677 | + if (!isOpaqueOccluder(cover, rect.left + rect.width / 2, rect.top + rect.height / 2)) |
| 1678 | + continue; |
| 1679 | + return { |
| 1680 | + code: "canvas_covered", |
| 1681 | + severity: "error", |
| 1682 | + time, |
| 1683 | + selector: uniqueSelectorFor(cover), |
| 1684 | + message: |
| 1685 | + "An opaque element covers the canvas above every other visible clip, so the frame shows only it.", |
| 1686 | + rect: toRect(cover.getBoundingClientRect()), |
| 1687 | + fixHint: |
| 1688 | + "Move the full-frame element below the content (earlier in the DOM or a lower z-index / track), or mark a deliberate full-frame card with data-layout-allow-occlusion.", |
| 1689 | + }; |
| 1690 | + } |
| 1691 | + return null; |
| 1692 | + } |
| 1693 | + |
1607 | 1694 | function layoutOffset(element) { |
1608 | 1695 | let left = 0; |
1609 | 1696 | let top = 0; |
|
2410 | 2497 | document.querySelector("[data-composition-id]") || |
2411 | 2498 | document.body; |
2412 | 2499 | const rootRect = rootRectFor(root); |
2413 | | - const elements = Array.from(root.querySelectorAll("*")).filter((element) => |
2414 | | - isVisibleElement(element, 0.05), |
2415 | | - ); |
| 2500 | + const elements = visibleElementsIn(root); |
2416 | 2501 | const issues = []; |
2417 | 2502 | const matteResults = new Map(); |
2418 | 2503 | videoAlphaFrames = new Map(); |
|
2429 | 2514 | const invisible = invisibleTextIssue(element, time); |
2430 | 2515 | if (invisible) issues.push(invisible); |
2431 | 2516 | } |
| 2517 | + const covered = canvasCoveredIssue(root, rootRect, elements, time); |
| 2518 | + if (covered) issues.push(covered); |
2432 | 2519 | } finally { |
2433 | 2520 | restoreHits(); |
2434 | 2521 | } |
|
2617 | 2704 | return false; |
2618 | 2705 | } |
2619 | 2706 |
|
2620 | | - window.__hyperframesCraftSample = function collectCraftSample() { |
| 2707 | + window.__hyperframesCraftSample = function collectCraftSample(options) { |
2621 | 2708 | const root = |
2622 | 2709 | document.querySelector("[data-composition-id][data-width][data-height]") || |
2623 | 2710 | document.querySelector("[data-composition-id]") || |
2624 | 2711 | document.body; |
2625 | 2712 | const rootRect = rootRectFor(root); |
2626 | 2713 | const parts = craftTextParts(root, rootRect); |
| 2714 | + const cover = options && options.withCover ? canvasCoverAt(root, rootRect) : null; |
2627 | 2715 | const holds = [root, ...Array.from(root.querySelectorAll("[data-hold]"))].filter((element) => |
2628 | 2716 | element.hasAttribute("data-hold"), |
2629 | 2717 | ); |
|
2632 | 2720 | parts, |
2633 | 2721 | held: holds.some((element) => isPaintedBox(element, rootRect)), |
2634 | 2722 | painted: paintsContent(root, rootRect, parts), |
| 2723 | + coveredBy: cover ? cover.selector : null, |
2635 | 2724 | signature: shared |
2636 | 2725 | ? shared.compositionSignature(shared.compositionRoot(), { quantize: true }) |
2637 | 2726 | : "", |
|
0 commit comments