Repository: pyscript/pyscript
File: pyscript.core/src/stdlib/pyweb/pydom.py (Python)

Code before:
        to: BaseElement | str = None,
        width: int | None = None,
        height: int | None = None,
    ):
        """
        Captures a snapshot of a video element. (Only available for video elements)

        Inputs:

            * to: element where to save the snapshot of the video frame to
            * width: width of the image
            * height: height of the image

        Output:
            (Element) canvas element where the video frame snapshot was drawn into
        """
        if self._js.tagName != "VIDEO":
            raise AttributeError("Snap method is only available for video Elements")

        if to is None:
            canvas = self.create("canvas")
            if width is None:
                width = self._js.width
            if height is None:
                height = self._js.height
            canvas._js.setAttribute("width", width)
            canvas._js.setAttribute("height", height)

        elif isistance(to, Element):
            if to._js.tagName != "CANVAS":
                raise TypeError("Element to snap to must a canvas.")
            canvas = to
        elif getattr(to, "tagName", "") == "CANVAS":
            canvas = Element(to)
        elif isinstance(to, str):
            canvas = pydom[to][0]
            if canvas._js.tagName != "CANVAS":
                raise TypeError("Element to snap to must a canvas.")

        canvas.draw(self, width, height)

        return canvas

    def download(self, filename: str = "snapped.png") -> None:
        """Download the current element (only available for canvas elements) with the filename
        provided in input.

        Inputs:
            * filename (str): name of the file being downloaded

        Output:

Review comment (suggestion):
watch out attribute in canvas is a bit weird ... the accessor is usually what you want to use instead ... so `canvas._js.width = width` is probably better, or even both, with the former assigned after.

Code after:
        to: BaseElement | str = None,
        width: int | None = None,
        height: int | None = None,
    ):
        """
        Captures a snapshot of a video element. (Only available for video elements)

        Inputs:

            * to: element where to save the snapshot of the video frame to
            * width: width of the image
            * height: height of the image

        Output:
            (Element) canvas element where the video frame snapshot was drawn into
        """
        if self._js.tagName != "VIDEO":
            raise AttributeError("Snap method is only available for video Elements")

        if to is None:
            canvas = self.create("canvas")
            if width is None:
                width = self._js.width
            if height is None:
                height = self._js.height
            canvas._js.width = width
            canvas._js.height = height

        elif isistance(to, Element):
            if to._js.tagName != "CANVAS":
                raise TypeError("Element to snap to must a canvas.")
            canvas = to
        elif getattr(to, "tagName", "") == "CANVAS":
            canvas = Element(to)
        elif isinstance(to, str):
            canvas = pydom[to][0]
            if canvas._js.tagName != "CANVAS":
                raise TypeError("Element to snap to must a be canvas.")

        canvas.draw(self, width, height)

        return canvas

    def download(self, filename: str = "snapped.png") -> None:
        """Download the current element (only available for canvas elements) with the filename
        provided in input.

        Inputs:
            * filename (str): name of the file being downloaded

        Output: