a
    Of1                     @  s   d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z	 ddl
mZ er`ddlmZmZmZ dd	d
ddZdd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)TYPE_CHECKINGCallable)
CSSWarning)find_stack_level)	GeneratorIterableIteratorstrr   )prop_fmtreturnc                   s   dd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
    r
   &Generator[tuple[str, str], None, None]valuer   c              	   3  s~   |  }z| jt| }W n4 tyN   tjd| d| dtt d Y dS 0 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    N/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/io/formats/css.pyexpand&   s    z_side_expander.<locals>.expandr#   )r   r%   r#   r"   r$   _side_expander   s    r&    )sider   c                   s*    dkrd   d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   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 r |d d	< qft fdd| j	D r |d d< qf |d d< qf| 
| 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>s       z3_border_expander.<locals>.expand.<locals>.<genexpr>N)r   r   r   r   r   r   r1   BORDER_STYLESanyBORDER_WIDTH_RATIOSatomizeitems)r   r   r   r   Zborder_declarationsr(   r4   r$   r%   S   s$    
z _border_expander.<locals>.expandr#   )r(   r%   r#   r=   r$   _border_expanderC   s    
)r>   c                   @  s  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dPd.d/d0d1d2d3Zd0d0d0d4d5d6Zd0d0d0d4d7d8Zd0d9d:d;d<Zd=d>d?d@dAZd0d0d:dBdCZd-efd=dDdEdFZdGdHdIdJdKZd=dLdMdNdOZd-S )QCSSResolverzH
    A callable for parsing and resolving CSS to atomic properties.
    )pt   )emrA   )r@      )rB         ?)r@   g      ?)r@   H   )ingL&d2?)rF   g
BP(?)mmg      ?)rB   r   )r@   rB   remexpxZpcrF   cmrG   q	!!default)rB   g{Gz?)rH   rD   )rH   g      ?)rH   g?)rH   rA   )rH   g      ?)rH   g      ?)rH      )rB   g?)rB   g333333?)%zxx-smallzx-smallZsmallr/   Zlargezx-largezxx-largeZsmallerZlargerrM   r-   )r@   r   )rJ      )rJ   rN   )rJ   rA   )r-   Zthickr/   Zthin)r-   ZhiddenZdottedZdashedZsoliddoubleZgrooveZridgeZinsetZoutsetZmediumdashdotZ
dashdotdotZhairZmediumdashdotdotZdashdotZslantdashdotZmediumdashed)r   r   r   r   )r   rA   r   rA   )r   rA   rN   rA   )r   rA   rN   r*   )rA   rN   r*   rP   )toprightbottomleftc                 C  s$   i | ]}|rd | ndt |qS )border-r+   )r>   r2   r   r#   r#   r$   
<dictcomp>   s   zCSSResolver.<dictcomp>)r'   rR   rS   rT   rU   c                 C  s"   i | ]}d | t d| qS )rV   zborder-{:s}-)r&   rW   r#   r#   r$   rX      s   )colorstylewidthzmargin-{:s}zpadding-{:s})marginpaddingNzstr | Iterable[tuple[str, str]]zdict[str, str] | Nonezdict[str, str])declarations	inheritedr   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dictr;   _update_initial_update_font_size_update_other_units)r   r^   r_   propsr#   r#   r$   __call__   s    ,

zCSSResolver.__call__)rf   r_   r   c                 C  sl   |  D ]\}}||vr|||< q| }|  D ]4\}}|dkrN||d}|dv r^||= q2|||< q2|S )Ninheritinitial)ri   N)r<   copyget)r   rf   r_   r   valZ	new_propsr#   r#   r$   rc     s    

zCSSResolver._update_initialc                 C  s.   | dr*| j|d | || jd|d< |S )N	font-sizeconversions)rk   
size_to_pt_get_font_sizeFONT_SIZE_RATIOS)r   rf   r_   r#   r#   r$   rd   (  s    

zCSSResolver._update_font_sizezfloat | None)rf   r   c                 C  s    | dr|d }| |S d S )Nrm   )rk   _get_float_font_size_from_pt)r   rf   font_size_stringr#   r#   r$   rq   6  s    

zCSSResolver._get_font_sizer
   float)rt   r   c                 C  s   | dsJ t|dS )Nr@   )endswithru   rstrip)r   rt   r#   r#   r$   rs   <  s    z(CSSResolver._get_float_font_size_from_ptc                 C  s   |  |}| jD ]n}d| d}||v rB| j|| || jd||< d| d| fD ]&}||v rV| j|| || jd||< qVq|S )NrV   r.   )em_ptro   zmargin-zpadding-)rq   r   rp   r:   MARGIN_RATIOS)r   rf   Z	font_sizer(   r   r#   r#   r$   re   @  s"    


zCSSResolver._update_other_units)r   c           
        s   fdd}t d}|d u r*| S | \}}|dkrDd}n&zt|}W n tyh   |  Y S 0 |dkr|dkr|d u rd}qj||9 }d}qjz | \}}W n ty   |  Y S 0 ||9 }qjt|d	}t||krt|d
d}	n|dd}	|	S )Nc                     s*   t jdt tt d jd dS )NzUnhandled size: r   z
1!!defaultrn   )r   r   reprr   r   rp   r#   ro   in_valr   r#   r$   _errorW  s    z&CSSResolver.size_to_pt.<locals>._errorz^(\S*?)([a-zA-Z%!].*)r'   rA   r@   rB   rH      df)rematchgroupsru   
ValueErrorr   roundint)
r   r|   rx   ro   r}   r   rl   unitmulZsize_fmtr#   r{   r$   rp   V  s8    

zCSSResolver.size_to_ptr   r   )r^   r   c                 c  sT   |D ]J\}}|  }|  }|| jv rD| j| }|| ||E d H  q||fV  qd S r0   )r1   CSS_EXPANSIONS)r   r^   r   r   r%   r#   r#   r$   r;     s    

zCSSResolver.atomizezIterator[tuple[str, str]])declarations_strr   c                 c  sr   | dD ]b}| sq
|d\}}}|  }|  }|rP||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	partitionr1   r   r   rz   r   r   )r   r   declr   seprl   r#   r#   r$   ra     s    
zCSSResolver.parse)N)__name__
__module____qualname____doc__ZUNIT_RATIOSrj   rr   updatery   r:   r8   r   r   r&   r   rg   rc   rd   rq   rs   re   rp   r;   ra   r#   r#   r#   r$   r?      s   
	 6-
r?   )r'   )r   
__future__r   r   typingr   r   r   Zpandas.errorsr   Zpandas.util._exceptionsr   collections.abcr   r   r	   r&   r>   r?   r#   r#   r#   r$   <module>   s   +<