
    -Ph              	          U d dl Z d dlmZmZmZmZ  ede          Zeeeef         Zee	d<   de
defdZde
defd	Zd
edefdZdedefdZdededefdZ	 ddededeeef         fdZdede
fdZdede
fdZde
de
fdZdS )    N)NewTypeTuple	TypeAliasUnionfloat01RGBColorxxreturnc                 B    t          t          | d          dz            S )a  Convert a two-digit, 8-bit hex value to a float between 0 and 1.

    >>> hexdd_to_float01("00")
    0.0
    >>> hexdd_to_float01("33")
    0.2
    >>> hexdd_to_float01("55")
    0.3333333333333333
    >>> hexdd_to_float01("cc")
    0.8
    >>> hexdd_to_float01("ff")
    1.0
          )r   int)r	   s    a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/a11y_pygments/utils/wcag_contrast.pyhexdd_to_float01r      s     3r2;;$%%%    hexc                    t          j        d|           rDt          | dd                   t          | dd                   t          | dd                   fS t          j        d|           rGt          | d         dz            t          | d         dz            t          | d         dz            fS t          d          )	a  Convert a hex defined colour to RGB.

    Args:
        hex (string): color in hex format (#rrggbb/#rgb)

    Returns:
        rgb: tuple of rgb values ``(r, g, b)``, where each channel (red, green,
        blue) can assume values between 0 and 1 (inclusive).
    z\A#[a-fA-F0-9]{6}\Z            z\A#[a-fA-F0-9]{3}\Z   zInvalid hex color format)rematchr   
ValueError)r   s    r   hex_to_rgb01r      s     
x&,, 
 S1X&&S1X&&S1X&&
 	
 
x&,, 
 SVaZ((SVaZ((SVaZ((
 	
 /
0
00r   vc                 .    | dk    r| dz  S | dz   dz  dz  S )zColors need to be normalised (from a sRGB space) before computing the relative
    luminance.

    Args:
        v (float): r,g,b channels values between 0 and 1

    Returns:
        float: sRGB channel value for a given rgb color channel
    g?ܵ?gףp=
)@g)\(?gzG?g333333@ )r   s    r   sRGB_channelr    =   s+     	G||5yUe#++r   colorc                     | \  }}}t          |          }t          |          }t          |          }d|z  d|z  z   d|z  z   S )zCompute the relative luminance of a color.

    Args:
        color (tuple): rgb color tuple ``(r, g, b)``

    Returns:
        float: relative luminance of a color
    gz6?g,C?g]m{?)r    )r!   rgbr_g_b_s          r   relative_luminancer)   M   sL     GAq!	aB	aB	aBB;"$v{22r   color1color2c                 v    t          |           }t          |          }||k    r|dz   |dz   z  S |dz   |dz   z  S )zCompute the contrast ratio between two colors.

    Args:
        color1 (tuple): rgb color tuple ``(r, g, b)``
        color2 (tuple): rgb color tuple ``(r, g, b)``

    Returns:
        float: contrast ratio between two colors
    g?)r)   )r*   r+   l1l2s       r   contrast_ratior/   ^   sM     
F	#	#B	F	#	#B	BwwT	b4i((T	b4i((r   AAc                     t          | |          }|dk    r|dk    rt          |d          S dS |dk    r|dk    rt          |d          S dS t          d          )zMethod to verify the contrast ratio between two colours.

    Args:
        color1 (tuple): rgb color tuple ``(r, g, b)``
        color2 (tuple): rgb color tuple ``(r, g, b)``
        level (str, optional): WCAG contrast level. Defaults to "AA".
    r0         @r   FAAAg      @z"level must be either 'AA' or 'AAA')r/   roundr   )r*   r+   levelratios       r   passes_contrastr7   r   sl     66**E}}C<<??"5	%C<<??"5
9
:
::r   contrastc                 &    | dk    rdS | dk    rdS dS )zGDoes the given contrast meet level AA or level AAA for normal size textr   r3   r2   r0    r   r8   s    r   get_wcag_level_normal_textr<      s#    1}}u	Strr   c                 &    | dk    rdS | dk    rdS dS )zADoes the given contrast meet level AA or level AAA for large textr2   r3   r   r0   r:   r   r;   s    r   get_wcag_level_large_textr>      s#    3u	Qtrr   	hex_colorc                 .    |                      dd          S )zjRemove '#' from hex color strings.

    Usage example:

    >>> hexstr_without_hash("#fff")
    'fff'
    #r:   )replace)r?   s    r   hexstr_without_hashrC      s     S"%%%r   )r0   )r   typingr   r   r   r   floatr   r   __annotations__strr   r   r    r)   r/   boolr7   r<   r>   rC   r   r   r   <module>rI      s   
				 3 3 3 3 3 3 3 3 3 3 3 3 ')U
#
#GWg56) 6 6 6& & & & & &"1c 1h 1 1 1 1<,G , , , , , 3h 35 3 3 3 3")8 )X )% ) ) ) )* /3; ;;&;
4;; ; ; ;6 3     #    &3 &3 & & & & & &r   