o
    d1                     @  sx   d Z ddlmZ ddlZddlmZmZmZmZ ddl	Z	ddl
mZ ddlmZ dddZddddZG dd dZdS )zN
Utilities for interpreting CSS from Stylers for formatting non-HTML outputs.
    )annotationsN)Callable	GeneratorIterableIterator)
CSSWarning)find_stack_levelprop_fmtstrreturnr   c                   s   d fdd}|S )	a)  
    Wrapper to expand shorthand property into top, right, bottom, left properties

    Parameters
    ----------
    side : str
        The border side to expand into properties

    Returns
    -------
        function: Return to call when a 'border(-{side}): {value}' string is encountered
    valuer
   r   &Generator[tuple[str, str], None, None]c              	   3  s    |  }z	| jt| }W n ty(   tjd| d| dtt d Y dS w t| j	|D ]\}} 
||| fV  q/dS )a<  
        Expand shorthand property into side-specific property (top, right, bottom, left)

        Parameters
        ----------
            prop (str): CSS property name
            value (str): String token for property

        Yields
        ------
            Tuple (str, str): Expanded property, value
        zCould not expand "z: "
stacklevelN)splitSIDE_SHORTHANDSlenKeyErrorwarningswarnr   r   zipSIDESformat)selfpropr   tokensmappingkeyidxr	    Z/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/io/formats/css.pyexpand!   s   z_side_expander.<locals>.expandNr   r
   r   r   r!   )r	   r#   r!   r    r"   _side_expander   s   r%    sidec                   s$    dkr	d   d
 fdd}|S )a.  
    Wrapper to expand 'border' property into border color, style, and width properties

    Parameters
    ----------
    side : str
        The border side to expand into properties

    Returns
    -------
        function: Return to call when a 'border(-{side}): {value}' string is encountered
    r&   -r   r
   r   r   c                 3  s    |  }t|dkst|dkrtjd| dtt d d ddd d	d
d ddi}|D ]/   | jv rF |d d	< q4t fdd| j	D r[ |d d< q4 |d d< q4| 
| E dH  dS )aV  
        Expand border into color, style, and width tuples

        Parameters
        ----------
            prop : str
                CSS property name passed to styler
            value : str
                Value passed to styler for property

        Yields
        ------
            Tuple (str, str): Expanded property, value
        r      zToo many tokens provided to "z" (expected 1-3)r   borderz-colorblackz-stylenone-widthmediumc                 3  s    | ]	}|   v V  qd S N)lower).0ratiotokenr!   r"   	<genexpr>n   s    z3_border_expander.<locals>.expand.<locals>.<genexpr>N)r   r   r   r   r   r   r0   BORDER_STYLESanyBORDER_WIDTH_RATIOSatomizeitems)r   r   r   r   border_declarationsr'   r3   r"   r#   N   s&   
z _border_expander.<locals>.expandNr$   r!   )r'   r#   r!   r<   r"   _border_expander>   s   
)r=   c                   @  sF  e Zd ZdZddddddddd	d
ddZe Zedddddddddddd e Zeddi e Z	e	ddddd g dZ
g dg d g d!g d"d#Zd$Zi d%d& d'D d(d& d)D ed*ed+d,Z	-dOdPd4d5ZdQd7d8ZdQd9d:ZdRd<d=ZdSdAdBZdTdCdDZd-efdEdFZdUdIdJZdVdMdNZd-S )WCSSResolverzH
    A callable for parsing and resolving CSS to atomic properties.
    )pt   )emr@   )r?      )rA         ?)r?   g      ?)r?   H   )ingL&d2?)rE   g
BP(?)mmg      ?)rA   r   )r?   rA   remexpxpcrE   cmrF   q	!!default)rA   g{Gz?)rG   rC   )rG   g      ?)rG   g?)rG   r@   )rG   g      ?)rG   g      ?)rG      )rA   g?)rA   g333333?)%zxx-smallzx-smallsmallr.   largezx-largezxx-largesmallerlargerrM   r,   )r?   r   )rI      )rI   rN   )rI   r@   )r,   thickr.   thin)r,   hiddendotteddashedsoliddoublegrooveridgeinsetoutsetmediumdashdot
dashdotdothairmediumdashdotdotdashdotslantdashdotmediumdashed)r   r   r   r   )r   r@   r   r@   )r   r@   rN   r@   )r   r@   rN   r)   )r@   rN   r)   rT   )toprightbottomleftc                 C  s$   i | ]}|rd | ndt |qS )border-r*   )r=   r1   r   r!   r!   r"   
<dictcomp>   s    zCSSResolver.<dictcomp>)r&   rg   rh   ri   rj   c                 C  s"   i | ]}d | t d| qS )rk   zborder-{:s}-)r%   rl   r!   r!   r"   rm      s    )colorstylewidthzmargin-{:s}zpadding-{:s})marginpaddingNdeclarationsstr | Iterable[tuple[str, str]]	inheriteddict[str, str] | Noner   dict[str, str]c                 C  sP   t |tr
| |}t| |}|du ri }| ||}| ||}| |S )a  
        The given declarations to atomic properties.

        Parameters
        ----------
        declarations_str : str | Iterable[tuple[str, str]]
            A CSS string or set of CSS declaration tuples
            e.g. "font-weight: bold; background: blue" or
            {("font-weight", "bold"), ("background", "blue")}
        inherited : dict, optional
            Atomic properties indicating the inherited style context in which
            declarations_str is to be resolved. ``inherited`` should already
            be resolved, i.e. valid output of this method.

        Returns
        -------
        dict
            Atomic CSS 2.2 properties.

        Examples
        --------
        >>> resolve = CSSResolver()
        >>> inherited = {'font-family': 'serif', 'font-weight': 'bold'}
        >>> out = resolve('''
        ...               border-color: BLUE RED;
        ...               font-size: 1em;
        ...               font-size: 2em;
        ...               font-weight: normal;
        ...               font-weight: inherit;
        ...               ''', inherited)
        >>> sorted(out.items())  # doctest: +NORMALIZE_WHITESPACE
        [('border-bottom-color', 'blue'),
         ('border-left-color', 'red'),
         ('border-right-color', 'red'),
         ('border-top-color', 'blue'),
         ('font-family', 'serif'),
         ('font-size', '24pt'),
         ('font-weight', 'bold')]
        N)
isinstancer
   parsedictr9   _update_initial_update_font_size_update_other_units)r   rs   ru   propsr!   r!   r"   __call__   s   
,

zCSSResolver.__call__r~   c                 C  sl   |  D ]\}}||vr|||< q| }|  D ]\}}|dkr'||d}|dv r/||= q|||< q|S )Ninheritinitial)r   N)r:   copyget)r   r~   ru   r   val	new_propsr!   r!   r"   r{     s   
zCSSResolver._update_initialc                 C  s.   | dr| j|d | || jd|d< |S )N	font-sizeconversions)r   
size_to_pt_get_font_sizeFONT_SIZE_RATIOS)r   r~   ru   r!   r!   r"   r|   %  s   

zCSSResolver._update_font_sizefloat | Nonec                 C  s    | dr|d }| |S d S )Nr   )r   _get_float_font_size_from_pt)r   r~   font_size_stringr!   r!   r"   r   3  s   

zCSSResolver._get_font_sizer   r
   floatc                 C  s   | dsJ t|dS )Nr?   )endswithr   rstrip)r   r   r!   r!   r"   r   9  s   z(CSSResolver._get_float_font_size_from_ptc                 C  s   |  |}| jD ]7}d| d}||v r!| j|| || jd||< d| d| fD ]}||v r>| j|| || jd||< q+q|S )Nrk   r-   )em_ptr   zmargin-zpadding-)r   r   r   r8   MARGIN_RATIOS)r   r~   	font_sizer'   r   r!   r!   r"   r}   =  s&   



zCSSResolver._update_other_unitsc           
        s
   fdd}t d}|d u r| S | \}}|dkr"d}nzt|}W n ty4   |  Y S w |dkrh|dkrK|d u rDd}n||9 }d}q5z | \}}W n ty_   |  Y S w ||9 }|dks9t|d	}t||kr}t|d
d}	|	S |dd}	|	S )Nc                     s*   t jdt tt d jd dS )NzUnhandled size: r   z
1!!defaultr   )r   r   reprr   r   r   r!   r   in_valr   r!   r"   _errorT  s   z&CSSResolver.size_to_pt.<locals>._errorz^(\S*?)([a-zA-Z%!].*)r&   r@   r?   rA   rG      df)rematchgroupsr   
ValueErrorr   roundint)
r   r   r   r   r   r   r   unitmulsize_fmtr!   r   r"   r   S  s@   


zCSSResolver.size_to_ptr   r   c                 c  sV    |D ]%\}}|  }|  }|| jv r#| j| }|| ||E d H  q||fV  qd S r/   )r0   CSS_EXPANSIONS)r   rs   r   r   r#   r!   r!   r"   r9     s   

zCSSResolver.atomizedeclarations_strIterator[tuple[str, str]]c                 c  st    | dD ]1}| sq|d\}}}|  }|  }|r)||fV  qtjdt| tt d qdS )z
        Generates (prop, value) pairs from declarations.

        In a future version may generate parsed tokens from tinycss/tinycss2

        Parameters
        ----------
        declarations_str : str
        ;:z-Ill-formatted attribute: expected a colon in r   N)	r   strip	partitionr0   r   r   r   r   r   )r   r   declr   sepr   r!   r!   r"   ry     s   
zCSSResolver.parser/   )rs   rt   ru   rv   r   rw   )r~   rw   ru   rw   r   rw   )r~   rw   r   r   )r   r
   r   r   )r~   rw   r   rw   )rs   r   r   r   )r   r
   r   r   )__name__
__module____qualname____doc__UNIT_RATIOSr   r   updater   r8   r6   r   r   r%   r   r   r{   r|   r   r   r}   r   r9   ry   r!   r!   r!   r"   r>   z   s    


6




-
r>   )r	   r
   r   r   )r&   )r'   r
   r   r   )r   
__future__r   r   typingr   r   r   r   r   pandas.errorsr   pandas.util._exceptionsr   r%   r=   r>   r!   r!   r!   r"   <module>   s    
+<