Skip to content

Geometry

🛈 DocStrings

Inputs shared by all render checks.

Source code in src/framesheet/analysis.py
@dataclass
class Geometry:
    """Inputs shared by all render checks."""

    elements: dict[int, Element]
    times: list[float]
    client: dict[int, list[Rect | None]]
    """Client rect (CSS px) per element per frame; ``None`` = not rendered/invisible."""
    user: dict[int, list[Rect | None]]
    """SVG user-space rect (outermost ``<svg>``) per element per frame."""
    canvas: Rect
    viewbox: Rect | None
    targets: dict[int, list[str]]
    animations: list[AnimationTiming]
    is_svg_doc: bool
    html_overflow: list[list[Any]] = field(default_factory=list)
    """``[index, dx, dy]`` per frame (list of lists)."""

    @classmethod
    def build(
        cls,
        description: list[dict[str, Any]],
        snapshots: list[Snapshot],
        *,
        canvas: Rect,
        viewbox: Rect | None,
        targets: dict[str, list[str]],
        animations: list[AnimationTiming],
        is_svg_doc: bool,
    ) -> Geometry:
        elements = {
            d["i"]: Element(d["i"], d["tag"], d["label"], d["svg"], d["parent"])
            for d in description
        }
        n = len(snapshots)
        client: dict[int, list[Rect | None]] = {}
        user: dict[int, list[Rect | None]] = {}
        for k, snap in enumerate(snapshots):
            for index, rect, user_rect, visible in snap.geometry:
                if not visible:
                    continue
                client.setdefault(index, [None] * n)[k] = as_rect(rect)
                if user_rect is not None:
                    user.setdefault(index, [None] * n)[k] = as_rect(user_rect)
        return cls(
            elements=elements,
            times=[s.t for s in snapshots],
            client=client,
            user=user,
            canvas=canvas,
            viewbox=viewbox,
            targets={int(k): v for k, v in targets.items()},
            animations=animations,
            is_svg_doc=is_svg_doc,
            html_overflow=[s.overflow for s in snapshots],
        )

    def ancestors(self, index: int) -> list[int]:
        out = []
        parent = self.elements[index].parent if index in self.elements else -1
        while parent != -1 and parent in self.elements:
            out.append(parent)
            parent = self.elements[parent].parent
        return out

    def label(self, index: int) -> str:
        return self.elements[index].label if index in self.elements else f"element {index}"

    def moved(self) -> set[int]:
        out = set()
        for index, rects in self.client.items():
            present = [r for r in rects if r is not None]
            if len(present) != len(rects) and present:
                out.add(index)  # appears / disappears
                continue
            if present and any(_differs(present[0], r) for r in present[1:]):
                out.add(index)
        return out

client instance-attribute

client: dict[int, list[Rect | None]]

Client rect (CSS px) per element per frame; None = not rendered/invisible.

html_overflow class-attribute instance-attribute

html_overflow: list[list[Any]] = field(default_factory=list)

[index, dx, dy] per frame (list of lists).

user instance-attribute

user: dict[int, list[Rect | None]]

SVG user-space rect (outermost <svg>) per element per frame.

:fa-brands-github: Show source on GitHub