o
    MfD                     @   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   Z/var/www/html/analyze/labelStudio/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 )zFind 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$    @