o
    lôjØ  ã                   @   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   ú]/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/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)ÚtitleZcaptionÚ	highlightZcaption_justifyz                )Úbgcolor)Ústyle)Ú
rich.colorr   Ú
rich.styler   Ú	rich.textr   Ú
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   Zred2Zgreen2Zblue2Zred_meanÚredÚgreenÚblue©Ú_sqrtÚblue1Z	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-   r;   Z	min_indexr   r6   r   Úmatch,   s   

zPalette.matchN)r   r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r=   r   r   r   r.   r   rA   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      ð?r0   éÿ   u   â–„)r-   r    )ÚsizeÚheightr@   Ú	max_widthÚcolorsysÚ
hls_to_rgbr   r+   rJ   r   Úline)r   rL   rM   rQ   ÚyÚxÚhÚlÚr1Úg1Úb1Úr2Úg2Úb2r    r-   r   r   r   Ú__rich_console__T   s   €
 ÷zColorBox.__rich_console__N)rB   rC   rD   rH   rI   rG   rJ   r`   r   r   r   r   rK   S   s    ÿÿþrK   )Úmathr   Ú	functoolsr   Útypingr   r   r   Úcolor_tripletr   r%   r
   r   rB   rS   rG   r"   r   Úrich.consolerH   rI   Zrich.segmentrJ   r#   r   rK   rL   Úprintr   r   r   r   Ú<module>   s$    @ç