o
    Ëý°jD  ã                   @   sÎ   d dl mZ d dlmZ d dlmZmZmZ ddlm	Z	 er$d dl
mZ G dd„ dƒZed	kred d
lZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ G dd„ dƒZeƒ Ze eƒ ¡ d
S d
S )é    )Úsqrt)Ú	lru_cache)ÚSequenceÚTupleÚTYPE_CHECKINGé   )ÚColorTriplet©ÚTablec                   @   sn   e Zd ZdZdeeeeef  fdd„Zdedefdd„Z	dd
d„Z
edd�deeeef defdd„ƒZdS )ÚPalettezA palette of available colors.Úcolorsc                 C   s
   || _ d S ©N)Ú_colors)Úselfr   © r   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/rich/palette.pyÚ__init__   s   
zPalette.__init__ÚnumberÚreturnc                 C   s   t | j| Ž S r   )r   r   )r   r   r   r   r   Ú__getitem__   s   zPalette.__getitem__r
   c              
   C   s”   ddl m} ddlm} ddlm} ddlm} |dddd	t| j	ƒ› d
�ddd�}t
| j	ƒD ]\}}| t|ƒt|ƒ|d||j|Ž d�d�¡ q.|S )Nr   ©ÚColor©ÚStyle)ÚTextr	   ÚindexÚRGBr   r   z colorsTÚright)ÚtitleÚcaptionÚ	highlightÚcaption_justifyz                )Úbgcolor)Ústyle)Úpip._vendor.rich.colorr   Úpip._vendor.rich.styler   Úpip._vendor.rich.textr   Úpip._vendor.rich.tabler
   Úlenr   Ú	enumerateÚadd_rowÚstrÚreprÚfrom_rgb)r   r   r   r   r
   Útabler   Úcolorr   r   r   Ú__rich__   s(   ù	ýzPalette.__rich__i   )Úmaxsizer/   c                    sN   |\‰‰‰t ‰ | jj‰dtdtf‡ ‡‡‡‡fdd„}ttt| jƒƒ|d�}|S )zêFind a color from a palette that most closely matches a given color.

        Args:
            color (Tuple[int, int, int]): RGB components in range 0 > 255.

        Returns:
            int: Index of closes matching color.
        r   r   c                    sj   ˆ| ƒ\}}}ˆ| d }ˆ| }ˆ| }ˆ| }ˆ d| | | d? d| |  d| | | d?  ƒS )zGet the distance to a color.é   i   é   é   iÿ  r   )r   Úred2Úgreen2Úblue2Úred_meanÚredÚgreenÚblue©Ú_sqrtÚblue1Ú	get_colorÚgreen1Úred1r   r   Úget_color_distance:   s   
ÿþÿz)Palette.match.<locals>.get_color_distance)Úkey)r   r   r   ÚintÚfloatÚminÚranger(   )r   r/   rB   Ú	min_indexr   r<   r   Úmatch,   s   

zPalette.matchN)r   r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   rD   r   r   r   r0   r   rI   r   r   r   r   r      s    
"r   Ú__main__N)ÚIterabler   )ÚConsoleÚConsoleOptions)ÚSegmentr   c                   @   s&   e Zd Zdededee fdd„ZdS )ÚColorBoxÚconsoleÚoptionsr   c                 c   sÎ   � |j jd }td|ƒD ]X}t|jƒD ]K}||j }||d  }t ||d¡\}}	}
t ||d| d  d¡\}}}t |d |	d |
d ¡}t |d |d |d ¡}tdt	||d�ƒV  qt 
¡ V  qd S )	Né   r   r   g      ð?r2   éÿ   u   â–„)r/   r"   )ÚsizeÚheightrG   Ú	max_widthÚcolorsysÚ
hls_to_rgbr   r-   rR   r   Úline)r   rT   rU   rY   ÚyÚxÚhÚlÚr1Úg1Úb1Úr2Úg2Úb2r"   r/   r   r   r   Ú__rich_console__T   s   €
 ÷zColorBox.__rich_console__N)rJ   rK   rL   rP   rQ   rO   rR   rh   r   r   r   r   rS   S   s    ÿÿþrS   )Úmathr   Ú	functoolsr   Útypingr   r   r   Úcolor_tripletr   r'   r
   r   rJ   r[   rO   r$   r   Úpip._vendor.rich.consolerP   rQ   Úpip._vendor.rich.segmentrR   r%   r   rS   rT   Úprintr   r   r   r   Ú<module>   s$    @ç