a
    $ñ»jËB  ã                   @  sˆ  d dl mZ d dlZd dlmZ ddlmZmZ ddlm	Z	 G dd„ de
ƒZG d	d
„ d
e
ƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZG dd„ deƒZdddœdd„Zddœdd„Zddœdd„Zdd d!œd"d#„Zdd dœd$d%„Zd=d
d&d'd(d)d*œd+d,„Zd
dd-œd.d/„Zd>d
d&d&d'd0d1œd2d3„Zd
d4d-œd5d6„Zed7ƒeG d8d9„ d9ƒƒƒZed:ƒeG d;d<„ d<ƒƒƒZdS )?é    )ÚannotationsN)Ú	dataclassé   )Úevent_classÚT_JSON_DICT)Údomc                      sB   e Zd ZdZddœdd„Zedd dœdd„ƒZ‡ fd	d
„Z‡  ZS )ÚLayerIdzUnique Layer identifier.Ústr©Úreturnc                 C  s   | S ©N© ©Úselfr   r   ú6E:\soccer\ml_env\Lib\site-packages\mycdp/layer_tree.pyÚto_json   s    zLayerId.to_json©Újsonr   c                 C  s   | |ƒS r   r   ©Úclsr   r   r   r   Ú	from_json   s    zLayerId.from_jsonc                   s   d  tƒ  ¡ ¡S )NzLayerId({})©ÚformatÚsuperÚ__repr__r   ©Ú	__class__r   r   r      s    zLayerId.__repr__©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r   Ú__classcell__r   r   r   r   r      s
   r   c                      sB   e Zd ZdZddœdd„Zedd dœdd„ƒZ‡ fd	d
„Z‡  ZS )Ú
SnapshotIdzUnique snapshot identifier.r	   r
   c                 C  s   | S r   r   r   r   r   r   r       s    zSnapshotId.to_jsonr   c                 C  s   | |ƒS r   r   r   r   r   r   r   #   s    zSnapshotId.from_jsonc                   s   d  tƒ  ¡ ¡S )NzSnapshotId({})r   r   r   r   r   r   '   s    zSnapshotId.__repr__r   r   r   r   r   r$      s
   r$   c                   @  sD   e Zd ZU dZded< ded< ddœdd	„Zedd d
œdd„ƒZdS )Ú
ScrollRectz5Rectangle where scrolling happens on the main thread.údom.RectÚrectr	   Útype_r   r
   c                 C  s"   t ƒ }| j ¡ |d< | j|d< |S )Nr'   Útype)Údictr'   r   r(   ©r   r   r   r   r   r   3   s    
zScrollRect.to_jsonr   c                 C  s$   | t j | d¡¡t| d¡ƒd�S )Nr'   r)   )r'   r(   )r   ÚRectr   Úgetr	   r   r   r   r   r   9   s    þzScrollRect.from_jsonN©r   r   r    r!   Ú__annotations__r   r"   r   r   r   r   r   r%   +   s   
r%   c                   @  s\   e Zd ZU dZded< ded< dZded< dZded< d	d
œdd„Zed	d dœdd„ƒZ	dS )ÚStickyPositionConstraintzSticky position constraints.r&   Ústicky_box_rectÚcontaining_block_rectNútyping.Optional[LayerId]Ú!nearest_layer_shifting_sticky_boxÚ'nearest_layer_shifting_containing_blockr   r
   c                 C  sV   t ƒ }| j ¡ |d< | j ¡ |d< | jd ur:| j ¡ |d< | jd urR| j ¡ |d< |S )NÚstickyBoxRectÚcontainingBlockRectÚnearestLayerShiftingStickyBoxÚ#nearestLayerShiftingContainingBlock)r*   r1   r   r2   r4   r5   r+   r   r   r   r   M   s    
ÿ
ÿz StickyPositionConstraint.to_jsonr   c              	   C  sj   | t j | d¡¡t j |d ¡| dd ¡d ur@t | d¡¡nd | dd ¡d urbt | d¡¡nd d�S )Nr6   r7   r8   r9   )r1   r2   r4   r5   )r   r,   r   r-   r   r   r   r   r   r   [   s     ÿÿ
ÿýÿðz"StickyPositionConstraint.from_json)
r   r   r    r!   r/   r4   r5   r   r"   r   r   r   r   r   r0   A   s   
r0   c                   @  sL   e Zd ZU dZded< ded< ded< ddœd	d
„Zedd dœdd„ƒZdS )ÚPictureTilezU
    Serialized fragment of layer picture along with its offset within the layer
    ÚfloatÚxÚyr	   Úpicturer   r
   c                 C  s(   t ƒ }| j|d< | j|d< | j|d< |S )Nr<   r=   r>   )r*   r<   r=   r>   r+   r   r   r   r      s
    


zPictureTile.to_jsonr   c                 C  s,   | t | d¡ƒt | d¡ƒt| d¡ƒd�S )Nr<   r=   r>   )r<   r=   r>   )r;   r-   r	   r   r   r   r   r   †   s
    ýzPictureTile.from_jsonNr.   r   r   r   r   r:   r   s   
r:   c                   @  sØ   e Zd ZU dZded< ded< ded< ded< ded< d	ed
< ded< dZded< dZded< dZded< dZded< dZ	ded< dZ
ded< dZded< dZded< dZded< ddœd d!„Zedd d"œd#d$„ƒZdS )%ÚLayerz&Information about a compositing layer.r   Úlayer_idr;   Úoffset_xÚoffset_yÚwidthÚheightÚintÚpaint_countÚboolÚdraws_contentNr3   Úparent_layer_idz"typing.Optional[dom.BackendNodeId]Úbackend_node_idz#typing.Optional[typing.List[float]]Ú	transformútyping.Optional[float]Úanchor_xÚanchor_yÚanchor_zztyping.Optional[bool]Ú	invisiblez(typing.Optional[typing.List[ScrollRect]]Úscroll_rectsz)typing.Optional[StickyPositionConstraint]Ústicky_position_constraintr   r
   c                 C  s,  t ƒ }| j ¡ |d< | j|d< | j|d< | j|d< | j|d< | j|d< | j|d< | j	d urh| j	 ¡ |d< | j
d ur€| j
 ¡ |d	< | jd uržd
d„ | jD ƒ|d< | jd ur²| j|d< | jd urÆ| j|d< | jd urÚ| j|d< | jd urî| j|d< | jd u�rdd„ | jD ƒ|d< | jd u�r(| j ¡ |d< |S )NÚlayerIdÚoffsetXÚoffsetYrC   rD   Ú
paintCountÚdrawsContentÚparentLayerIdÚbackendNodeIdc                 S  s   g | ]}|‘qS r   r   ©Ú.0Úir   r   r   Ú
<listcomp>Ä   ó    z!Layer.to_json.<locals>.<listcomp>rK   ÚanchorXÚanchorYÚanchorZrP   c                 S  s   g | ]}|  ¡ ‘qS r   ©r   rZ   r   r   r   r]   Î   r^   ÚscrollRectsÚstickyPositionConstraint)r*   r@   r   rA   rB   rC   rD   rF   rH   rI   rJ   rK   rM   rN   rO   rP   rQ   rR   r+   r   r   r   r   ¶   s8    
















ÿzLayer.to_jsonr   c                 C  s–  | t  | d¡¡t| d¡ƒt| d¡ƒt| d¡ƒt| d¡ƒt| d¡ƒt| d¡ƒ| dd ¡d urxt  | d¡¡nd | d	d ¡d urœtj | d	¡¡nd | d
d ¡d urÀdd„ |d
 D ƒnd | dd ¡d uràt| d¡ƒnd | dd ¡d u�rt| d¡ƒnd | dd ¡d u�r$t| d¡ƒnd | dd ¡d u�rFt| d¡ƒnd | dd ¡d u�rldd„ |d D ƒnd | dd ¡d u�rŽt |d ¡nd d�S )NrS   rT   rU   rC   rD   rV   rW   rX   rY   rK   c                 S  s   g | ]}t |ƒ‘qS r   )r;   rZ   r   r   r   r]   ê   r^   z#Layer.from_json.<locals>.<listcomp>r_   r`   ra   rP   rc   c                 S  s   g | ]}t  |¡‘qS r   )r%   r   rZ   r   r   r   r]     r^   rd   )r@   rA   rB   rC   rD   rF   rH   rI   rJ   rK   rM   rN   rO   rP   rQ   rR   )	r   r   r-   r;   rE   rG   r   ZBackendNodeIdr0   r   r   r   r   r   Õ   sL    ÿÿÿÿÿÿÿÿýÿËzLayer.from_json)r   r   r    r!   r/   rI   rJ   rK   rM   rN   rO   rP   rQ   rR   r   r"   r   r   r   r   r   r?   �   s*   
ÿ
r?   c                      sB   e Zd ZdZddœdd„Zedd dœdd„ƒZ‡ fd	d
„Z‡  ZS )ÚPaintProfilez%Array of timings, one per paint step.ztyping.List[float]r
   c                 C  s   | S r   r   r   r   r   r   r     s    zPaintProfile.to_jsonr   c                 C  s   | |ƒS r   r   r   r   r   r   r     s    zPaintProfile.from_jsonc                   s   d  tƒ  ¡ ¡S )NzPaintProfile({})r   r   r   r   r   r     s    zPaintProfile.__repr__r   r   r   r   r   re     s
   re   z\typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.Tuple[typing.List[str], typing.List[str]]])r@   r   c                 c  sF   t ƒ }|  ¡ |d< d|dœ}|V }dd„ |d D ƒdd„ |d D ƒfS )	aÖ  
    Provides the reasons why the given layer was composited.
    :param layer_id: The id of the layer
     for which we want to get the reasons it was composited.
    :returns: A tuple with the following items:

        0. **compositingReasons** - A list of strings specifying reasons
         for the given layer to become composited.
        1. **compositingReasonIds** - A list of strings specifying reason
         IDs for the given layer to become composited.
    rS   zLayerTree.compositingReasons©ÚmethodÚparamsc                 S  s   g | ]}t |ƒ‘qS r   ©r	   rZ   r   r   r   r]   7  r^   z'compositing_reasons.<locals>.<listcomp>ZcompositingReasonsc                 S  s   g | ]}t |ƒ‘qS r   ri   rZ   r   r   r   r]   8  r^   ZcompositingReasonIds©r*   r   ©r@   rh   Úcmd_dictr   r   r   r   Úcompositing_reasons  s    þþrm   z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None]r
   c                  c  s   ddi} | V }dS )z%Disables compositing tree inspection.rg   zLayerTree.disableNr   ©rl   r   r   r   r   Údisable<  s    ÿro   c                  c  s   ddi} | V }dS )z$Enables compositing tree inspection.rg   zLayerTree.enableNr   rn   r   r   r   ÚenableD  s    ÿrp   ztyping.List[PictureTile]z6typing.Generator[T_JSON_DICT, T_JSON_DICT, SnapshotId])Útilesr   c                 c  s8   t ƒ }dd„ | D ƒ|d< d|dœ}|V }t | d¡¡S )zŒ
    Returns the snapshot identifier.
    :param tiles: An array of tiles composing the snapshot.
    :returns: The id of the snapshot.
    c                 S  s   g | ]}|  ¡ ‘qS r   rb   rZ   r   r   r   r]   U  r^   z!load_snapshot.<locals>.<listcomp>rq   zLayerTree.loadSnapshotrf   Ú
snapshotId)r*   r$   r   r-   )rq   rh   rl   r   r   r   r   Úload_snapshotL  s    þrs   c                 c  s2   t ƒ }|  ¡ |d< d|dœ}|V }t | d¡¡S )z†
    Returns the layer snapshot identifier.
    :param layer_id: The id of the layer.
    :returns: The id of the layer snapshot.
    rS   zLayerTree.makeSnapshotrf   rr   )r*   r   r$   r   r-   rk   r   r   r   Úmake_snapshot^  s    þrt   ztyping.Optional[int]rL   ztyping.Optional[dom.Rect]zEtyping.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[PaintProfile]])Úsnapshot_idÚmin_repeat_countÚmin_durationÚ	clip_rectr   c                 c  sh   t ƒ }|  ¡ |d< |dur"||d< |dur2||d< |durF| ¡ |d< d|dœ}|V }dd	„ |d
 D ƒS )a²  
    :param snapshot_id: The id of the layer snapshot.
    :param min_repeat_count: *(Optional)*
     The maximum number of times to replay the snapshot (1, if not specified).
    :param min_duration: *(Optional)*
     The minimum duration (in seconds) to replay the snapshot.
    :param clip_rect: *(Optional)*
     The clip rectangle to apply when replaying the snapshot.
    :returns: The array of paint profiles, one per run.
    rr   NZminRepeatCountZminDurationZclipRectzLayerTree.profileSnapshotrf   c                 S  s   g | ]}t  |¡‘qS r   )re   r   rZ   r   r   r   r]   �  r^   z$profile_snapshot.<locals>.<listcomp>Ztimingsrj   )ru   rv   rw   rx   rh   rl   r   r   r   r   Úprofile_snapshotp  s    þry   )ru   r   c                 c  s&   t ƒ }|  ¡ |d< d|dœ}|V }dS )zq
    Releases layer snapshot captured by the back-end.
    :param snapshot_id: The id of the layer snapshot.
    rr   zLayerTree.releaseSnapshotrf   Nrj   ©ru   rh   rl   r   r   r   r   Úrelease_snapshot�  s    þr{   z/typing.Generator[T_JSON_DICT, T_JSON_DICT, str])ru   Ú	from_stepÚto_stepÚscaler   c                 c  s`   t ƒ }|  ¡ |d< |dur"||d< |dur2||d< |durB||d< d|dœ}|V }t| d¡ƒS )	aæ  
    Replays the layer snapshot and returns the resulting bitmap.
    :param snapshot_id: The id of the layer snapshot.
    :param from_step: *(Optional)*
     The first step to replay from
     (replay from the very start if not specified).
    :param to_step: *(Optional)*
     The last step to replay to (replay till the end if not specified).
    :param scale: *(Optional)*
     The scale to apply while replaying (defaults to 1).
    :returns: A data: URL for resulting image.
    rr   NZfromStepZtoStepr~   zLayerTree.replaySnapshotrf   ZdataURL)r*   r   r	   r-   )ru   r|   r}   r~   rh   rl   r   r   r   r   Úreplay_snapshot   s    þr   z=typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[dict]]c                 c  s4   t ƒ }|  ¡ |d< d|dœ}|V }dd„ |d D ƒS )z¤
    Replays the layer snapshot and returns canvas log.
    :param snapshot_id: The id of the layer snapshot.
    :returns: The array of canvas function calls.
    rr   zLayerTree.snapshotCommandLogrf   c                 S  s   g | ]}t |ƒ‘qS r   )r*   rZ   r   r   r   r]   Ñ  r^   z(snapshot_command_log.<locals>.<listcomp>Z
commandLogrj   rz   r   r   r   Úsnapshot_command_logÂ  s    þr€   zLayerTree.layerPaintedc                   @  s2   e Zd ZU ded< ded< edd dœdd„ƒZd	S )
ÚLayerPaintedr   r@   r&   Úclipr   r   c                 C  s&   | t  | d¡¡tj | d¡¡d�S )NrS   r‚   )r@   r‚   )r   r   r-   r   r,   r   r   r   r   r   Ü  s    þzLayerPainted.from_jsonN©r   r   r    r/   r"   r   r   r   r   r   r�   Ô  s   
r�   zLayerTree.layerTreeDidChangec                   @  s*   e Zd ZU ded< edd dœdd„ƒZdS )ÚLayerTreeDidChangez#typing.Optional[typing.List[Layer]]Úlayersr   r   c                 C  s,   | |  dd ¡d ur$dd„ |d D ƒnd d�S )Nr…   c                 S  s   g | ]}t  |¡‘qS r   )r?   r   rZ   r   r   r   r]   î  r^   z0LayerTreeDidChange.from_json.<locals>.<listcomp>)r…   )r-   r   r   r   r   r   ê  s
    ÿüzLayerTreeDidChange.from_jsonNrƒ   r   r   r   r   r„   ä  s   
r„   )NNN)NNN)Ú
__future__r   ÚtypingÚdataclassesr   Úutilr   r   Ú r   r	   r   r$   r%   r0   r:   r?   Úlistre   rm   ro   rp   rs   rt   ry   r{   r   r€   r�   r„   r   r   r   r   Ú<module>   sJ   0    ü    ü"