
    9i-                        S SK JrJrJr  \" S5      (       a,  SSKJr  SSKJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJrJr  S	r\" S5      S
 5       rS rS r0 r\" S5      SS j5       r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S S\5      r"S r#S r$\" S5       " S S\5      5       r%g)    )class_requires_depsfunction_requires_depsis_dep_availableopenpyxl    )cell)	AlignmentBorderColorFont
NamedStylePatternFillSide)BLACK)
FILL_SOLID)FORMAT_CURRENCY_USD_SIMPLEFORMAT_PERCENTAGEz
mm/dd/yyyyc                 4    S[         0nUR                  X 5      $ )z)
Convenience for looking up known colors
black)r   get)colorcmaps     `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/utils/io/style.pycolormapr   $   s    
 UD88E!!    c                     S nU R                  S5       Vs/ s H  nSU;   d  M  U" US5      PM     nn[        U5      $ s  snf )z1
Convert css style string to a python dictionary
c                 2    S U R                  U5       5       $ )zB
Clean up a string by removing all spaces and splitting on delim.
c              3   @   #    U  H  oR                  5       v   M     g 7fN)strip).0ss     r   	<genexpr><style_string_to_dict.<locals>.clean_split.<locals>.<genexpr>6   s     7#6a		#6s   )split)stringdelims     r   clean_split)style_string_to_dict.<locals>.clean_split2   s     86<<#677r   ;:)r%   dict)styler(   r"   styless       r   style_string_to_dictr/   -   sH    
8 ,1;;s+;H+;asax!k!S!+;FH< Is   
??c                     U R                  SR                  U5      5      [        U R                  SR                  U5      5      5      S.$ )z

get side
zborder-{}-stylezborder-{}-color)border_styler   )r   formatr   )r-   names     r   get_sider4   <   sC    
 		"3":":4"@A%))$5$<$<T$BCD r   Nc                    [        U U R                  US.5      nU[        ;  Ga  [        U R	                  S5      S:H  U R                  SS5      U R	                  S5      S9n[        U R	                  SS	5      U R	                  S
5      U R	                  SS5      S:H  S9nU R                  S5      nU R                  S[        5       5      nU R	                  S5      nU(       a  US:w  a  [        U=(       d    [        UUS9nO
[        5       n[        [        S0 [        U S5      D6[        S0 [        U S5      D6[        S0 [        U S5      D6[        S0 [        U S5      D6[        S0 [        U S5      D6S[        S0 [        U S5      D6SSS9	n	SR                  [        [        5      S-   5      n
[        U
UUUU	US9nU[        U'   [        U   $ )zI
Change css style (stored in a python dictionary) to openpyxl NamedStyle
)
style_dictparentnumber_formatzfont-weightboldr   Nz	font-size)r9   r   sizez
text-aligngeneralzvertical-alignzwhite-spacenowrapnormal)
horizontalvertical	wrap_textzbackground-colorzforeground-colorz	fill-typetransparent)	fill_typestart_color	end_colorleftrighttopbottomdiagonaloutline)	rE   rF   rG   rH   rI   diagonal_directionrJ   r?   r>   zStyle {}   )r3   fontfill	alignmentborderr8    )strr7   known_stylesr   r   	get_colorr	   r   r   r   r
   r   r4   r2   lenr   )r6   r8   style_and_format_stringrM   rO   bg_colorfg_colorrB   rN   rP   r3   
pyxl_styles               r   style_dict_to_named_stylerZ   I   s    "$ ''*	
 l2.&8&&w5,
 !~~lI>^^$45 nn]H=I
	 ''(:;''(:EGDNN;/	M1#1z$"D =D 5V457*g673x
E239(:x89=HZ<=#;8J	:;

   \!2Q!67'

 1;,-/00r   c                   X   ^  \ rS rSrSrU 4S jrU 4S jrS rS rS
S jr	S
S jr
S	rU =r$ )	StyleDict   zI
It's like a dictionary, but it looks for items in the parent dictionary
c                 \   > UR                  SS 5      U l        [        [        U ]  " U0 UD6  g )Nr7   )popr7   superr\   __init__)selfargskwargs	__class__s      r   ra   StyleDict.__init__   s)    jj40i'88r   c                    > X;   a  [         [        U ]  U5      $ U R                  (       a  U R                  U   $ [	        SR                  U5      5      e)Nz{} not found)r`   r\   __getitem__r7   KeyErrorr2   )rb   itemre   s     r   rh   StyleDict.__getitem__   sF    <D5d;;[[;;t$$>00677r   c                     [        [        U R                  5        Vs/ s H  oU R                  U5      4PM     sn5      5      $ s  snf r   )hashtuple_keysr   )rb   ks     r   __hash__StyleDict.__hash__   s5    ETZZ\B\txx{+\BCDDBs   Ac              #     #    [        5       nU R                  5        H  nUR                  U5        Uv   M     U R                  (       a>  U R                  R	                  5        H  nX!;  d  M
  UR                  U5        Uv   M!     g g 7fr   )setkeysaddr7   ro   )rb   yieldedrp   s      r   ro   StyleDict._keys   sg     %AKKNG  ;;[[&&(#KKNG ) s   A(B	.B	c                 0     X   $ ! [          a    Us $ f = fr   )ri   )rb   rp   ds      r   r   StyleDict.get   s"    	7N 	H	s    c                     U R                  X5      n[        US5      (       aB  UR                  S5      (       a,  USS n[        U5      S:X  a  SR	                  S U 5       5      nU$ )z)
Strip leading # off colors if necessary

startswith#rL   N    c              3   ,   #    U  H
  nS U-  v   M     g7f)   NrQ   )r!   cs     r   r#   &StyleDict.get_color.<locals>.<genexpr>   s     5u!Aus   )r   hasattrr}   rU   join)rb   rp   rz   r   s       r   rT   StyleDict.get_color   s]     5,''E,<,<S,A,A!"IEE
a5u55r   r7   r   )__name__
__module____qualname____firstlineno____doc__ra   rh   rq   ro   r   rT   __static_attributes____classcell__re   s   @r   r\   r\      s,    98E	 r   r\   c                   .    \ rS rSrSrSS jrS rS rSrg)	Element   z
Our base class for representing an html element along with a cascading style.
The element is created along with a parent so that the StyleDict that we store
can point to the parent's StyleDict.
Nc                     Xl         S U l        U(       a  UR                  OS n[        [	        UR                  SS5      5      US9U l        S U l        g )Nr-   r   r   )elementr8   r6   r\   r/   r   _style_cache)rb   r   r7   parent_styles       r   ra   Element.__init__   sI    !,2v((# Wb!9:<
 !r   c                     U R                   (       d#  [        U R                  U R                  S9U l         U R                   $ )zC
Turn the css styles for this element into an openpyxl NamedStyle.
)r8   )r   rZ   r6   r8   rb   s    r   r-   Element.style   s7        9t/A/A!D    r   c                 |    U R                   R                  U5      nU(       a  USS S;   a  USS n[        U5      nU$ )zV
Extracts the dimension from the style dict of the Element and returns it as a float.
N)pxemptincm)r6   r   float)rb   dimension_key	dimensions      r   get_dimensionElement.get_dimension   sE     OO''6	~!??%crN	i(Ir   )r   r   r8   r6   r   )	r   r   r   r   r   ra   r-   r   r   rQ   r   r   r   r      s    !!	r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Table   aH  
The concrete implementations of Elements are semantically named for the types of elements we are interested in.
This defines a very concrete tree structure for html tables that we expect to deal with. I prefer this compared to
allowing Element to have an arbitrary number of children and dealing with an abstract element tree.
c                    > [         [        U ]  U5        UR                  S5      nUb	  [	        X S9OSU l        UR                  S5      n[        Ub  UOUU S9U l        g)z(
takes an html table object (from lxml)
theadNr   tbody)r`   r   ra   find	TableHeadhead	TableBodybody)rb   table
table_head
table_bodyre   s       r   ra   Table.__init__   s`     	eT#E*ZZ(
2<2HIj.d 		 ZZ(
$0JeD
	r   )r   r   r   r   r   r   r   ra   r   r   r   s   @r   r   r      s    
 
r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   i  z:
This class maps to the `<th>` element of the html table.
c                    > [         [        U ]  XS9  UR                  S5       Vs/ s H  n[	        X0S9PM     snU l        g s  snf Nr   tr)r`   r   ra   findallTableRowrows)rb   r   r7   r   re   s       r   ra   TableHead.__init__  >    i''<9=d9KL9K2Xb.9KL	L   Ar   r   r   r   s   @r   r   r         M Mr   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   i  z=
This class maps to the `<tbody>` element of the html table.
c                    > [         [        U ]  XS9  UR                  S5       Vs/ s H  n[	        X0S9PM     snU l        g s  snf r   )r`   r   ra   r   r   r   )rb   r   r7   r   re   s       r   ra   TableBody.__init__  r   r   r   r   r   r   s   @r   r   r     r   r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   i  z:
This class maps to the `<tr>` element of the html table.
c                    > [         [        U ]  XS9  UR                  S5      UR                  S5      -    Vs/ s H  n[	        X0S9PM     snU l        g s  snf )Nr   thtd)r`   r   ra   r   	TableCellcells)rb   r   r7   r   re   s       r   ra   TableRow.__init__  sS    h&r&957ZZ5E

SWHX5X
5XTId(5X

 
s   A)r   r   r   r   s   @r   r   r     s    
 
r   r   c                 4    [        U 5      R                  5       $ )
element to string
)_element_to_stringr    )els    r   element_to_stringr   "  s     b!''))r   c                    SnU R                  5        H  nUS[        U5      -   -  nM     U R                  (       a  U R                  R                  5       OSnU R                  (       a  U R                  R                  5       OSnX1-   S-   U-   $ )r   r   
)iterchildrenr   textr    tail)r   r&   xr   r   s        r   r   r   )  sq     F__$+A...  !gg277==?2D gg277==?2D=4$&&r   c                   J   ^  \ rS rSrSr1 SkrS	U 4S jjrS rS rS r	Sr
U =r$ )
r   i8  z:
This class maps to the `<td>` element of the html table.
>   	TYPE_BOOL	TYPE_NULL
TYPE_ERRORTYPE_INLINETYPE_STRINGTYPE_FORMULATYPE_INTEGERTYPE_NUMERICTYPE_CURRENCYTYPE_PERCENTAGETYPE_FORMULA_CACHE_STRINGc                 r   > [         [        U ]  XS9  [        U5      U l        U R                  5       U l        g )Nr   )r`   r   ra   r   valueget_number_formatr8   )rb   r   r7   re   s      r   ra   TableCell.__init__L  s2    i''<&t,
!335r   c                    U R                   [        U R                  R                  SS5      R	                  5       5      -  nU(       a)  SU;   a  SnO"U1 Sk-  (       a  SnOUR                  5       nOSn[        [        U5      $ )z
get data type
classr   r   >   r   r   r   r   r   )
CELL_TYPESrt   r   r   r%   r_   getattrr   )rb   
cell_types	cell_types      r   	data_typeTableCell.data_typeQ  sm     __s4<<+;+;GR+H+N+N+P'QQ
+*	RR*	&NN,	%ItY''r   c                 ,   SU R                   R                  SS5      R                  5       ;   a  [        $ SU R                   R                  SS5      R                  5       ;   a  gSU R                   R                  SS5      R                  5       ;   a  [        $ SU R                   R                  SS5      R                  5       ;   a  [
        $ U R                  5       [        R                  :X  a   [        U R                  5        gg	! [         a     gf = f)
z
get number format
r   r   r   r   z#,##0r   	TYPE_DATEz#,##0.##N)r   r   r%   r   r   FORMAT_DATE_MMDDYYYYr   r   r   intr   
ValueErrorr   s    r   r   TableCell.get_number_formatb  s     dll..w;AACC--T\\--gr:@@BB 0 0" = C C EE$$$,,**7B7==??''>>t000DJJ  1  "!"s   /D 
DDc                 j    U R                  5       Ul         U R                  5       nU(       a  X!l        gg)z
format
N)r-   r   )rb   r   r   s      r   r2   TableCell.formatv  s*     ZZ\
NN$	&N r   )r8   r   r   )r   r   r   r   r   r   ra   r   r   r2   r   r   r   s   @r   r   r   8  s(    J6
("(' 'r   r   r   )&
utils.depsr   r   r   openpyxl.cellr   openpyxl.stylesr	   r
   r   r   r   r   r   openpyxl.styles.colorsr   openpyxl.styles.fillsr   openpyxl.styles.numbersr   r   r   r   r/   r4   rS   rZ   r,   r\   objectr   r   r   r   r   r   r   r   rQ   r   r   <module>r      s     Y XJ"   -0U#  
#" $"  
#C1 $C1L3 3l#f #L
G 
,M MM M	
w 	
*' Z D' D' !D'r   