
    Mh1                        S r SSKJr  SSKrSSKJrJr  SSKrSSKJ	r	  SSK
Jr  \(       a
  SSKJrJrJr  SS jrSSS	 jjr " S
 S5      rg)zN
Utilities for interpreting CSS from Stylers for formatting non-HTML outputs.
    )annotationsN)TYPE_CHECKINGCallable)
CSSWarning)find_stack_level)	GeneratorIterableIteratorc                   ^  SU 4S jjnU$ )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
c              3  >  >#    UR                  5       n U R                  [        U5         n[        U R                  U5       H  u  pVTR                  U5      X6   4v   M     g! [         a,    [        R
                  " SU SU S3[        [        5       S9   gf = f7f)z
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propvaluetokensmappingkeyidxprop_fmts          G/var/www/html/env/lib/python3.13/site-packages/pandas/io/formats/css.pyexpand_side_expander.<locals>.expand&   s      	**3v;7G DJJ0HC//#&33 1  	MM$TF"UG15+-
 	s'   BA$ 7B$3BBBBr   strreturn&Generator[tuple[str, str], None, None] )r    r"   s   ` r!   _side_expanderr)      s    44 M    c                .   ^  T S:w  a  ST  3m SU 4S jjnU$ )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
 -c              3    >^#    UR                  5       n[        U5      S:X  d  [        U5      S:  a&  [        R                  " SU S3[        [        5       S9  ST S3SST S	3S
ST S3S0nU Hd  mTR                  5       U R                  ;   a  TUST S	3'   M,  [        U4S jU R                   5       5      (       a  TUST S3'   M[  TUST S3'   Mf     U R                  UR                  5       5       Sh  vN   g N7f)z
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  H   >#    U  H  oTR                  5       ;   v   M     g 7fN)lower).0ratiotokens     r!   	<genexpr>3_border_expander.<locals>.expand.<locals>.<genexpr>s   s     R9Qekkm+9Qs   "N)r   r   r   r   r   r   r7   BORDER_STYLESanyBORDER_WIDTH_RATIOSatomizeitems)r   r   r   r   border_declarationsr:   sides        @r!   r"    _border_expander.<locals>.expandS   s     v;!s6{QMM/v5EF+- TF&!7TF&!6TF&!8

 E{{} 2 22=B#fTF&$9:R9Q9QRRR=B#fTF&$9:=B#fTF&$9:  << 3 9 9 ;<<<s   C5D9C?:Dr$   r(   )rC   r"   s   ` r!   _border_expanderrE   C   s$     rz4&z'=R Mr*   c                     \ rS rSrSrSSSSSSSS	S
SSS.r\R                  5       r\R                  SSSSSSSSSSSS.5        \R                  5       r	\	R                  SS05        \R                  5       r
\
R                  SSSSS.5        / SQr/ S Q/ S!Q/ S"Q/ S#QS$.rS%r0 S& V VVs0 s H  nU(       a  S'U 3OS([        U5      _M     snnn ES) V VVs0 s H  nS'U 3[        S*U 35      _M     snnn E\" S+5      \" S,5      S-.Er S9     S:S/ jjr      S;S0 jr      S;S1 jrS<S2 jrS=S3 jrS>S4 jrS.\4S?S5 jjrS@S6 jrSAS7 jrS8rg.s  snnn f s  snnn f )BCSSResolver   z@
A callable for parsing and resolving CSS to atomic properties.
)pt   )emrJ   )rI      )rK         ?)rI   g      ?)rI   H   )ingL&d2?)rO   g
BP(?)mmg      ?)rK   r   )rI   rK   remexpxpcrO   cmrP   q	!!default)rK   g{Gz?)rQ   rM   )rQ   g      ?)rQ   g?)rQ   rJ   )rQ   g      ?)rQ   g      ?)rQ      )rK   g?)rK   g333333?)%zxx-smallzx-smallsmallr4   largezx-largezxx-largesmallerlargerrW   r2   )rI   r   )rS      )rS   rX   )rS   rJ   )r2   thickr4   thin)r2   hiddendotteddashedsoliddoublegrooveridgeinsetoutsetmediumdashdot
dashdotdothairmediumdashdotdotdashdotslantdashdotmediumdashed)r   r   r   r   )r   rJ   r   rJ   )r   rJ   rX   rJ   )r   rJ   rX   r/   )rJ   rX   r/   r^   )toprightbottomleft)r,   rq   rr   rs   rt   border-r0   )colorstylewidthzborder-{:s}-zmargin-{:s}zpadding-{:s})marginpaddingNc                    [        U[        5      (       a  U R                  U5      n[        U R	                  U5      5      nUc  0 nU R                  X25      nU R                  X25      nU R                  U5      $ )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')]
)
isinstancer%   parsedictr@   _update_initial_update_font_size_update_other_units)r   declarations	inheritedpropss       r!   __call__CSSResolver.__call__   so    X lC((::l3LT\\,/0I$$U6&&u8''..r*   c                    UR                  5        H  u  p4X1;  d  M  XAU'   M     UR                  5       nUR                  5        H+  u  p4US:X  a  UR                  US5      nUS;   a  XS	 M'  XEU'   M-     U$ )Ninheritinitial)r   N)rA   copyget)r   r   r   r   val	new_propss         r!   r   CSSResolver._update_initial  sx     #*ID !d + JJL	IDimmD)4''O"%$ ' r*   c                    UR                  S5      (       a0  U R                  US   U R                  U5      U R                  S9US'   U$ )N	font-sizeconversions)r   
size_to_pt_get_font_sizeFONT_SIZE_RATIOS)r   r   r   s      r!   r   CSSResolver._update_font_size(  sQ     99[!!!%k"##I. 11 "1 "E+
 r*   c                \    UR                  S5      (       a  US   nU R                  U5      $ g )Nr   )r   _get_float_font_size_from_pt)r   r   font_size_strings      r!   r   CSSResolver._get_font_size6  s1    99[!!$[1445EFFr*   c                f    UR                  S5      (       d   e[        UR                  S5      5      $ )NrI   )endswithfloatrstrip)r   r   s     r!   r   (CSSResolver._get_float_font_size_from_pt<  s0    ((....%,,T233r*   c                   U R                  U5      nU R                   Hd  nSU S3nXA;   a  U R                  X   UU R                  S9X'   SU 3SU 34 H)  nXA;   d  M
  U R                  X   UU R                  S9X'   M+     Mf     U$ )Nru   r3   )em_ptr   zmargin-zpadding-)r   r   r   r?   MARGIN_RATIOS)r   r   	font_sizerC   r   s        r!   r   CSSResolver._update_other_units@  s    ''.	JJDTF&)D}"ooK# $ 8 8 .  #4&)XdV+<=="&//'$($6$6 #2 #EK > " r*   c                  ^ ^^ UUU 4S jn[         R                  " ST5      nUc  U" 5       $ UR                  5       u  pgUS:X  a  SnO [        U5      nUS:w  a(  US:X  a  Uc  SnOXb-  nSnM   TU   u  pxXh-  nUS:w  a  M(  [        US5      n[        U5      U:X  a  [        U5      S	 S3n	U	$ US
 S3n	U	$ ! [         a
    U" 5       s $ f = f! [
         a
    U" 5       s $ f = f)Nc                    > [         R                  " S[        T5       3[        [	        5       S9  TR                  ST S9$ )NzUnhandled size: r   z
1!!defaultr   )r   r   reprr   r   r   )r   in_valr   s   r!   _error&CSSResolver.size_to_pt.<locals>._errorW  s;    MM"4<.1+-
 ??<[?IIr*   z^(\S*?)([a-zA-Z%!].*)r,   rJ   rI   rK   rQ      df)rematchgroupsr   
ValueErrorr   roundint)
r   r   r   r   r   r   r   unitmulsize_fmts
   `` `      r!   r   CSSResolver.size_to_ptV  s   	J 16:=8OLLN	"9C Cj dlt|= DLCD '-	 JC dl Cms8s?c(1R(H  a|H/   x    x s$   	B6 /C 6C
	C
C! C!c              #     #    U H[  u  p#UR                  5       nUR                  5       nX R                  ;   a"  U R                  U   nU" XU5       S h  vN   MV  X#4v   M]     g  N7fr6   )r7   CSS_EXPANSIONS)r   r   r   r   r"   s        r!   r@   CSSResolver.atomize  s`     'KD::<DKKME***,,T2!$e444k! (
 5s   AA'A%A'c              #    #    UR                  S5       H  nUR                  5       (       d  M  UR                  S5      u  p4nUR                  5       R                  5       nUR                  5       R                  5       nU(       a  X54v   Mx  [        R
                  " S[        U5       3[        [        5       S9  M     g7f)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	partitionr7   r   r   r   r   r   )r   declarations_strdeclr   sepr   s         r!   r}   CSSResolver.parse  s      %**3/D::<<!^^C0NDs::<%%'D))+##%CiCDJ<P/1 0s   B=B?r(   r6   )r   zstr | Iterable[tuple[str, str]]r   zdict[str, str] | Noner&   dict[str, str])r   r   r   r   r&   r   )r   r   r&   zfloat | None)r   r%   r&   r   )r   r   r&   r   )r&   r%   )r   r	   r&   r'   )r   r%   r&   zIterator[tuple[str, str]])__name__
__module____qualname____firstlineno____doc__UNIT_RATIOSr   r   updater   r?   r=   r   r   rE   r)   r   r   r   r   r   r   r   r   r@   r}   __static_attributes__)r8   r   rE   r)   s   0000r!   rG   rG      s   
 K #'')$%! ##"&!"	
   $$&M&),-%**,		
M* 	O /E ?
> "&wtf86Ft6LL>
 4
3 dVn~dV-DEE3
 !/!.1N  ,04/54/ )4/ 
	4/l " 
	, " 
	4, (, +Z"{

s   )"E
E
rG   )r    r%   r&   r   )r,   )rC   r%   r&   r   )r   
__future__r   r   typingr   r   r   pandas.errorsr   pandas.util._exceptionsr   collections.abcr   r	   r
   r)   rE   rG   r(   r*   r!   <module>r      sG    # 	  $ 4 (V9xf fr*   