
    Bhy                     2   S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  S	S
KJr  0 S\R                  _S\R                   _S\R                  _S\R"                  _S\R$                  _S\R&                  _S\R(                  _S\R*                  _S\R,                  _S\R.                  _S\R0                  _S\R2                  _S\R2                  _S\R2                  _S\R4                  _S\R6                  _S\R8                  _S\R:                  0Er\" SS5       V s0 s H  o \ " U S-   5      _M     sn r!\!RE                  S S!S".5        \RF                  " S#5      r$\RF                  " S$5      r%\RF                  " S%5      r&S& r'S' r(S( r) SES) jr*S* r+S+ r,   SFS, jr- SGS- jr.S. r/S/ r0S0 r1S1 r2\RF                  " S25      Rf                  4S3 jr4SES4 jr5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;S; r<SHS< jr=S= r>S> r?S? r@S@ rASESA jrBSB rCSC rDSD rEgs  sn f )IzTurn an element tree with style into a "before layout" box tree.

This includes creating anonymous boxes and processing whitespace as necessary.

    N   )html)
propertiestargets)collapse_table_borders)LOGGER)get_lang_quotes   )boxesblockflowinliner   )r   	flow-root)r   r   )r   table)r   r   )r   flex)r   r   )r   grid)r   r   )z	table-row)ztable-row-groupztable-header-groupztable-footer-group)ztable-column)ztable-column-group)z
table-cell)ztable-caption!      i  u   　u   −)    -   z
?z[	 ]*
[	 ]*z[	 ]+c                 t    [        U 5      n [        U 5      n [        U 5      n [        U 5      n [	        U 5      n U $ )zDCreate anonymous boxes in box descendants according to layout rules.)anonymous_table_boxes
flex_boxes
grid_boxesinline_in_blockblock_in_inlineboxs    W/var/www/html/env/lib/python3.13/site-packages/weasyprint/formatting_structure/build.pycreate_anonymous_boxesr$   5   s7    

$C
S/C
S/C
#
C
#
CJ    c           	         ^ ^ [        T TX#XEU5      nU(       a  Uu  nOSU U4S jjn	[        T XUXEU5      u  nUR                  5         SUl        [        U5      n[	        U5      nU$ )z=Build a formatting structure (box tree) from an element tree.c                 B   > T" X5      nUb  U T:X  a  SUS'   U$ SUS'   U$ )Nr   displaynone )elementpseudo_typestyleelement_tree	style_fors      r#   root_style_for2build_formatting_structure.<locals>.root_style_forJ   s=    g3E l*'8E)$ L (1E)$Lr%   TN)element_to_boxcheck_pending_targetsis_for_root_elementr$   set_viewport_overflow)
r/   r0   get_image_from_uribase_urltarget_collectorcounter_style	footnotesbox_listr"   r1   s
   ``        r#   build_formatting_structurer>   ?   s{     i!34H 	 	 .hY8 **,"C
 
%C

$CJr%   c                 .    [         US   S S    " XX25      $ )Nr(   r   )BOX_TYPE_FROM_DISPLAY)element_tagr.   contentr,   s       r#   make_boxrC   _   s%     y!1"1!56G. .r%   c                 R   [        U R                  [        5      (       d  / $ U" U 5      nUS   n	U	S:X  a  / $ US   S:X  a  US   S:X  a  SUS'   OSUS'   [        U R                  U/ U 5      n
Uc  S	/SS	/0S1/4nUu  pn[	        Xx5        / nUR                  [        5       5        U" U S
5      U
l        U" U S5      U
l        / nSUS   ;   a(  [        [        XXUXE5      5      nUR                  U5        UR                  [        U SXqUXE5      5        US   (       a  UR                  US   X5        U R                  nU(       a/  UR                  [        R                   R#                  U
U5      5        U  GH<  n[%        UXUXEXg5      nU(       a}  US	   R&                  S   S:X  ag  US	   nSUR&                  S'   UR                  U5        U" U S5      n[        U R                   S3U/ U 5      n[)        UUXX$U5      Ul        UUl        U/nUR                  U5        UR.                  nU(       d  M  [        R                   R#                  U
U5      nU(       aG  [        US   [        R                   5      (       a%  US   =R                  UR                  -  sl        GM+  UR                  U5        GM?     UR                  [        U SXqUXE5      5        UR1                  5        H3  nUU   R1                  5         UU   (       a  M"  UR1                  U5        M5     Xl        [3        U
5        [5        X
XXE5        [7        U
5        U(       a[  [9        U
R*                  5      S:X  aB  US   S:X  a9  U
R*                  R                  [        R                   R#                  U
S5      5        US   S:X  ac  US   S==   S-  ss'   U" U S5      n[        U R                   S3U/ U 5      n[)        UXXXE5      Ul        U
R*                  R;                  S	U5        [<        R>                  " X
X#5      $ )a  Convert an element and its children into a box with children.

Return a list of boxes. Most of the time the list will have one item but
may have zero or more than one.

Eg.::

    <p>Some <em>emphasised</em> text.</p>

gives (not actual syntax)::

    BlockBox[
        TextBox['Some '],
        InlineBox[
            TextBox['emphasised'],
        ],
        TextBox[' text.'],
    ]

``TextBox``es are anonymous inline boxes:
See https://www.w3.org/TR/CSS21/visuren.html#anonymous

r(   r)   floatfootnotefootnote_displayr   r   r   r   first-letterz
first-line	list-itembeforeanchorr*   zfootnote-callz::footnote-callafterr
   list_style_positionoutsideu   ​zfootnote-markerz::footnote-marker) 
isinstancetagstrrC   update_countersappendsetfirst_letter_stylefirst_line_stylelistmarker_to_boxextendbefore_after_to_boxstore_targettextr   TextBoxanonymous_fromr4   r.   content_to_boxeschildrenrF   tailpopprocess_whitespaceset_content_listsprocess_text_transformleninsertr   handle_element)r,   r0   r8   r9   r:   r;   r<   stater.   r(   r"   quote_depthcounter_valuescounter_scopesra   marker_boxesr]   child_elementchild_boxesrF   
call_stylefootnote_calltext_boxnamemarker_stylemarkers                             r#   r4   r4   d   s   2 gkk3''	gE IG)	W~##$/0E)  2E)
7;;r7
3C} C!\N
 38/KE!H #% &w?C$Wl;CLeI&&ME.@- . 	%OO'5-?) * X%%eHo~K<<D44S$?@ $9(Y? ;q>//8JF"1~H&,HNN7#X&"7O<J$;;-/RJM%5M;"m&EM" &.M"(/K$!!4}}33C>HJx|U]]CC!!X]]2!!)3 !6 OO'%,>) *
 ""$t  "d##t$ %
 Lse-=N3CLL)Q. &'94LL < <S% HIW~#z"2&!+& *;<{{m,-|RJ*#N- 	Av& w-?JJr%   c                    U" X5      nU(       a  Uc  / $ US   nUS:X  a  / $ US   n	U	S;   a  / $ [        U R                   SU 3U/ U 5      n
Uu  pn[        X'5        / nSU;   a(  [        [	        XXsUXV5      5      nUR                  U5        UR                  [        XzXUXV5      5        Xl        US   S:w  a  Uu  np[        X
US	   UXV5        U
/$ )
z8Return the boxes for ::before or ::after pseudo-element.r(   r)   rB   )normalinhibitr*   ::rI   bookmark_levelr*   bookmark_label)	rC   rQ   rS   rX   rY   rZ   r`   ra   compute_bookmark_label)r,   r-   rj   r0   r8   r:   r;   r.   r(   rB   r"   rk   rl   _counter_scopesra   rn   _quote_depths                    r#   r[   r[     s    g+Eu} 	
 IG)	IG//	
gkk]"[M2E2w
GC380KE!HgME.@- . 	%OO$K1C) * L &(8=5n% 01>	- 5Lr%   c              #     #    U" U S5      n/ nUu  pn[        U R                   S3XxU 5      nUS   S:X  a  gUS   u  pUS   S;  a  UR                  [        X|XUXV5      5        OUS	:X  a<  U" XS
   S9nUb0  [        R
                  R                  X5      nUR                  U5        U(       d}  US   S:w  at  U
R                  SS/5      S   nUS   nUR                  UU5      =n(       a@  [        R                  R                  UU5      nSUR                  S'   UR                  U5        U(       d  gUS   S:X  a  [        R                  R                  X5      nSUR                  S'   US   S:X  a  [        R                  " SS5      nO[        R                  " SS5      n[        R                  nSUU444UR                  S'   O[        R                   R                  X5      nUv   g7f)zqYield the box for ::marker pseudo-element if there is one.

https://drafts.csswg.org/css-lists-3/#marker-pseudo

rv   ::markerr(   r)   Nlist_style_imagerB   )rx   ry   urlimage_orientationr   orientationlist_style_typer*   rI   r   rL   zpre-wrapwhite_spacerN   rO   absoluteposition	directionltri%d   	translate	transform)rC   rQ   rZ   r`   r   InlineReplacedBoxr_   rT   getrender_markerr^   r.   BlockBoxr   	DimensionZERO_PIXELS	InlineBox)r,   rj   parent_styler0   r8   r:   r;   r.   ra   rk   rl   r~   r"   
image_typeimagecounter_valuecounter_typemarker_text
marker_boxtranslate_xtranslate_ys                        r#   rY   rY   3  s     gx(EH
 490K
gkk](+Ug
FCY9$01JY44(5G- 	.
 &-@'ACE --<<SH$E"34>*..{QC@DM !23L+99,VV{Vmm223D+5		-($)*i7^^223A
 (2
$$-$..tS9K$..sC8K ,,;45)8
% __33CB

s   G)G+c                   ^^^/^0^1 / m/[        5       m1U/U1U4S jn/ n0 nUSL=(       a    USLnUR                  =(       a    U(       + nTR                  c:  UR                  5        VVs0 s H  u  nnUUR	                  5       _M     snnTl        U  GH  u  nnUS:X  a
  U" U5        M  US:X  aZ  UbW  Uu  nnUS:w  a  M-  U" UTR
                  S   S9nUb1  T/R                  [        R                  R                  TU5      5        Mu  Mw  US:X  a$  [        UT5      nU" UR                  5       5        M  US	:X  aJ  U(       d(  [        R                  " S
SR                  U5      5        M  U" UR                  " U/UQ76 5        M  US;   a  US   US   snm0T0S:X  a  GM  U(       a#  U[!        U5      U-   ;  a  UR                  U5        US:X  a)  UR#                  US/5      S   nTR%                  UT05      nO2US   nUR                  UU04S jUR#                  US/5       5       5      nU" U5        GM  US;   GaG  USS US   su  nnm0T0S:X  a  GM  UR'                  UTX45      nUR(                  S:w  a    GOUR*                  R                  n U(       aE  UU ;  a?  [,        R.                  " U5      n!UR1                  U!/ 5      nUU;  a  UR                  U5        UR2                  R	                  5       n"U"R5                  U 5        US:X  a)  U"R#                  US/5      S   nTR%                  UT05      nOCUS   nUS   S:w  a    GOUS   n#U#R                  UU04S jU"R#                  US/5       5       5      nU" U5        GM  US:X  a\  Uu  nn$UR'                  UTX45      nUR(                  S:X  a1  UR*                  n%[        U$U%5      nU" UR                  5       5        GMN    GO9US:X  a  SX4;  a  SU;   n&UR7                  S5      (       + =(       a    U	S:g  n'U&(       d  [9        SUS   S-
  5      US'   U'(       aI  U	S:X  a  [;        U
5      u  n(n)OU	u  n(n)U&(       a  U(OU)n*U" U*[=        US   [?        U*5      S-
  5         5        U&(       a  US==   S-  ss'   GM  GM  US:X  a  U(       d)  [        R                  " SSR                  U5      5        GMA  UR@                  " U/UQ76 n+U+c  GMZ  U+RC                  5       n+SU+R
                  S '   [E        U+[        RF                  5      (       aI  U+RI                  5        H5  n,U,R
                  S!   S";   a  M  [K        U,R
                  U,XXuTXS#9	U,l&        M7     T/R                  U+5        GM  US$:X  d  GM  US   (       d  GM  [        RN                  R                  TUS   5      n-[        RP                  R                  TU-45      n.S%U.R
                  S&'   S%U-R
                  S&'   S'U.l)        T/R                  U.5        GM     T1(       d  T/(       a  URU                  TX4UU5        T/$ gs  snnf )(aM  Compute and return the boxes corresponding to the ``content_list``.

``parse_again`` is called to compute the ``content_list`` again when
``target_collector.lookup_target()`` detected a pending target.

``build_formatting_structure`` calls
``target_collector.check_pending_targets()`` after the first pass to do
required reparsing.

c                   > TR                  S5        U (       ar  T(       a;  [        TS   [        R                  5      (       a  TS   =R                  U -  sl        g TR                  [        R                  R                  TU 5      5        g g )NTrL   )addrP   r   r^   r]   rT   r_   )r]   content_boxeshas_text
parent_boxs    r#   add_text&compute_content_list.<locals>.add_text  sh    TM",=u}}!M!Mb!&&$.&$$MM00TBD	 r%   Nstringr   externalr   r   z	content()zstring()z,"string(%s)" is only allowed in page margins )	counter()z
counters()r   rL   r*   r   r
   c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr3   render_value.0r   r;   r   s     r#   	<genexpr>'compute_content_list.<locals>.<genexpr>  s)      &P)N "..}lKK)N   ")target-counter()ztarget-counters()r   z
up-to-dater   c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr3   r   r   s     r#   r   r     s)      -P)N "..}lKK)Nr   ztarget-text()quoteopenzno-autoz	element()z-"element(%s)" is only allowed in page marginsstaticr   rB   )rx   r*   )contextpagezleader()prer   T)+rU   
collectingcached_counter_valuesitemscopyr.   rT   r   r   r_   extract_textstripr   warningjoinget_string_set_forrX   r   r   lookup_targetrj   
target_boxr   anchor_name_from_token
setdefaultcached_page_counter_valuesupdate
startswithmaxr	   minrg   get_running_element_fordeepcopyrP   	ParentBoxdescendantsr`   ra   r^   r   	is_leadercollect_missing_counters)2content_listr   rl   	css_tokenparse_againr:   r;   r8   rk   quote_stylelangr   r   r,   r   missing_countersmissing_target_countersin_page_contextneed_collect_missingkeyvaluetype_originurir   
added_textcounter_namer   r]   	separatoranchor_tokenr   target_valuesanchor_namelocal_countersseparator_string
text_styler   is_openrh   open_quotesclose_quotesquotesnew_boxchildrs   
leader_boxr   r   r   s2    `    `                                        @@@r#   compute_content_listr   u  sD   ( MuHD  T)>d$.>O ,66N;N''/ 1?0D0D0F,H0F*#uC0F,H
($uHUOe^ 2 >KFC#&Z%5%56I%JLE $$++:::uMO ! k!%eZ8J Z%%'(j " BHHUO% W//=u=>11).q59&L,v%#tN';>N'NN$++L9# . 2 2<! Eb I$11-N!!H	 ~~ &P)7););L1#)N&P P TN??9>rE"I6(\<,v%,::j)BM""l2)44JJM#M(I%<<\J#:#E#E$% '77$++L9 +EEJJLN!!-0** . 2 2<! Eb I$11-N!!H	Q<8+#,Q< ',, -P)7););L1#)N-P P TNo%',$L*,::j)BM""l2*55
 $J
; &g${.H"HoG))%00J[F5JF!$QA(:!;A&(0?0E-K0;-K(/\KNCK!O DEFA!# k!"CHHUO% 55dCUCG&&(G(0GMM*%'5??33$002E{{9-1CC %5UK*m '&4EN 3   )j 8}}33JaIH77XK)J /4J]+,1HNN=)#'J   ,K %N =11	0@#	%  !S,Hs   'X?c	                    ^ ^^^^^ SUUUUU U4S jjn	T S   S:X  a  / $ USS mSn
[        T S   TX:U	TTTUT S   T S   Xx5      nU=(       d    / $ )z:Take the value of a ``content`` property and return boxes.Nc                 n  > U c  0 nOU R                  5       nUR                  TR                  5        / nUR                  [	        TTTUTTT5      5        [        TR                  5      S:X  aA  [        TR                  S   [        R                  5      (       a  UTR                  S   l        gUTl        g)z9Closure to parse the ``parent_boxes`` children all again.Nr
   r   )
r   r   r   rZ   r`   rg   ra   rP   r   LineBox)	mixin_pagebased_countersr   local_childrenr;   r8   orig_quote_depthr   r.   r:   s	      r#   r   %content_to_boxes.<locals>.parse_again5  s    
 $+N5::<Nj>>?.:/ 0-A 	B 
##$):..q15==AA.<J"+"0Jr%   rB   ry   r   r   r3   )r   )r.   r   rk   rl   r8   r:   r;   r   r   r   r   r=   r   s   ``  ```     @r#   r`   r`   1  sm    1 14 Y9$	"1~I#i*n-);[hv7H >rr%   c                 6  ^ ^^^^^ SUUUU UU4S jjnST 3n[        TTXHUTTT S9n	U	bo  SR                  S U	 5       5      n
TR                   H)  nUS   T:X  d  M  TR                  R                  U5          O   TR                  R	                  TU
45        gg)	zCParse the content-list value of ``string_name`` for ``string-set``.Nc           	         > U c  0 nOU R                  5       nUR                  TR                  5        [        TTTTUTT5        g)z7Closure to parse the string-set string value all again.N)r   r   r   compute_string_set)r   r   r"   r   r;   r,   string_namer:   s     r#   r   'compute_string_set.<locals>.parse_again^  sJ    
 $+N5::<Nc778S+|^m	-r%   zstring-set::r,    c              3   |   #    U  H2  n[        U[        R                  5      (       d  M$  UR                  v   M4     g 7fr3   rP   r   r^   r]   r   r"   s     r#   r   %compute_string_set.<locals>.<genexpr>r  s'      L (JsEMM,JHCHHs   #<<r   r3   )r   r   
string_setremoverT   )r,   r"   r   r   rl   r:   r;   r   r   r=   r   string_set_tuples   ```` ``     r#   r   r   [  s    - - {m,I#c>k-:H  L (L L !$"k1%%&67 !/ 	{F34 r%   c                    ^ ^^^^ 0 4UUUU U4S jjnSn[        TTX7UTTT S9nU(       a  SR                  S U 5       5      Tl        gg)z5Parses the content-list value for ``bookmark-label``.c                    > U c  0 nOU R                  5       nU R                  5       nUR                  TR                  5        [        TTTUTT5        g)z.Closure to parse the bookmark-label all again.N)r   r   r   r}   )r   r   r"   r   r;   r,   r:   s     r#   r   +compute_bookmark_label.<locals>.parse_again  sW     $+N5::<N1668c778S,8H	r%   zbookmark-labelr  r  c              3   8   #    U  H  n[        U5      v   M     g 7fr3   )box_textr  s     r#   r   )compute_bookmark_label.<locals>.<genexpr>  s     $GhsXc]]hs   N)r   r   r|   )	r,   r"   r   rl   r:   r;   r   r   r=   s	   ``` ``   r#   r}   r}   }  sT     .0   !I#c>k-:H WW$Gh$GG r%   c           
          / Ul         US   S:w  a(  [        US   5       H  u  nu  px[        XXxUXE5        M     US   S:w  a  [        XUS   UXE5        gg)z|Set the content-lists values.

These content-lists are used in GCPM properties like ``string-set`` and
``bookmark-label``.

r  r*   r{   r|   N)r  	enumerater   r}   )	r,   r"   r.   rl   r:   r;   ir   string_valuess	            r#   re   re     st     CN\f$/8|9L/M+A+k. 1 0N &(% 01>	- )r%   c                 X   U u  p#nUS   nUS    HO  u  pgXe;   a  X6   R                  5         OUR                  U5        UR                  U/ 5      R                  U5        MQ     US    HK  u  pgUR                  U/ 5      nU(       d)  Xe;  d   eUR                  U5        UR                  S5        XxS'   MM     US   n	U	S:X  a  SUS   ;   a  S	/n	O/ n	U	 HT  u  pgUR                  U/ 5      nU(       d)  Xe;  d   eUR                  U5        UR                  S5        US==   U-  ss'   MV     g
)z$Handle the ``counter-*`` properties.rL   counter_resetcounter_setr   counter_incrementr   rI   r(   )rI   r
   N)rc   r   r   rT   )
rj   r.   r   rl   rm   sibling_scopesrt   r   valuesr  s
             r#   rS   rS     sC   380L.#B'N_-! $$&t$!!$+2259 . ]+**44---t$MM!r
 , 12F"
 %	**!1 2 "(**44---t$MM!r
e
 )r%   z\Sc                 r    [        U [        R                  5      =(       a    U" U R                  5      (       + $ )z9Return True if ``box`` is a TextBox with only whitespace.r  )r"   _has_non_whitespaces     r#   is_whitespacer    s%    c5==)O2Echh2O.OOr%   c              #     ^#    Uc  U4S jn/ nU HM  nU" U5      (       a,  U(       a  TR                  U / S9n[        Xd5      v   / nUv   M<  UR                  U5        MO     U(       a  TR                  U / S9n[        Xd5      v   gg7f)zWrap consecutive children that do not pass ``test`` in a ``wrapper_type`` box.

``test`` defaults to children being of the same type as ``wrapper_type``.

Nc                    > [        U T5      $ r3   )rP   )r   wrapper_types    r#   testwrap_improper.<locals>.test  s    e\22r%   )ra   )r_   table_boxes_childrenrT   )r"   ra   r  r   improperr   wrappers     `    r#   wrap_improperr%    s      |	3H;;&55cB5G*7==KOOE"  --cB-?"755 s   BBc                     [        U [        R                  5      (       a  U R                  5       (       a  U $ U R                   Vs/ s H  n[        U5      PM     nn[        X5      $ s  snf )zRemove and add boxes according to the table model.

Take and return a ``Box`` object.

See https://www.w3.org/TR/CSS21/tables.html#anonymous-boxes

)rP   r   r   
is_runningra   r   r"  r"   r   ra   s      r#   r   r     sW     c5??++s~~/?/?
 ;>,,G,%e,,HG.. Hs   A'c                   ^	 [        U [        R                  5      (       a  / nO[        U [        R                  5      (       a  U Vs/ s H&  n[        U[        R                  5      (       d  M$  UPM(     nnU(       de  U R                  b  U R                  S:  a  SnOU R                  n[        U5       Vs/ s H#  n[        R                  R                  U / 5      PM%     nnU R                  (       a  [        U5      S:  a  USS u  pVUR                  (       a   [        U5      (       a  UR                  5         [        U5      S:  a9  USS u  peUR                  (       a!  [        U5      (       a  UR                  S5        [        S/USS -   UUSS S/-   5       VVVs/ s HJ  u  prnU(       a;  UR                  (       a*  U(       a#  UR                  (       a  [        U5      (       a  MH  UPML     nnnn[        U [        R                  5      (       a  [        X[        R                  S 5      nO9[        U [        R                   5      (       a  [        X[        R                  5      n[        U [        R                  5      (       a  [        X[        R"                  5      nO[        X[        R                  S 5      n[        U [        R$                  5      (       a  [        X[        R&                  S	 5      nO*[)        U 5      m	[        X[        R                  U	4S
 j5      n[        U [        R                  5      (       a  [+        X5      $ [-        U5      U l        U $ s  snf s  snf s  snnnf )z3Internal implementation of anonymous_table_boxes().Nr
   r   r   rL   c                     U R                   $ r3   proper_table_childr   s    r#   <lambda>&table_boxes_children.<locals>.<lambda>=  s
    %22r%   c                 @    [        U [        R                  5      (       + $ r3   )rP   r   TableCellBoxr.  s    r#   r/  r0  I  s    j0B0BCCr%   c                 $    U R                   (       + $ r3   r,  r.  s    r#   r/  r0  O  s    e666r%   c                 R   > U R                   (       + =(       d    TU R                  ;   $ r3   )r-  proper_parents)r   parent_types    r#   r/  r0  T  s&    u777 ?&%*>*>>?r%   )rP   r   TableColumnBoxTableColumnGroupBoxspanranger_   tabular_containerrg   internal_table_or_captionr  rc   zipTableBoxr%  TableRowBoxTableRowGroupBoxr2  r   InlineTableBoxtype
wrap_tablerX   ra   )
r"   ra   r   r9  _internalr]   
prev_child
next_childr6  s
            @r#   r"  r"     s   #u++,,	C22	3	3  (
'e%!5!56 x 	 
 xx388a<xx!&t.!,A ,,;;CD!,  . X!!3 ""#..=3F3FLLN x=A%bq\ND22}T7J7JQ .1FXcr]"QRLD6!.
.
)Jz :??:??%  	.
   #u~~&& 5,,24 
C//	0	0 0A0AB#u(()) 0B0BC !5,,CE
 #u'' 5//68 3i 5>>@A
 #u~~&&#((H~
i
.0s   #M#.M#6*M(!AM-,M-c           
      Z   / n/ n/ n[         R                  U[         R                  U[         R                  U[         R                  U[         R
                  U0nU H   nU[        U5         R                  U5        M"     / / S.nU H#  nXxR                  S      R                  U5        M%     [        [        X[         R                  5      5      n	Sn
U	 HH  nXl        UR                  (       a   UR                   H  nXl        U
S-  n
M     M:  XR                  -  n
MJ     U
n[        X[         R                  5      n/ nSnSnU HK  nUR                  S   nUS:X  a  Uc  SUl        UnM&  US	:X  a  Uc  SUl        UnM:  UR                  U5        MM     Ub  U/O/ U-   Ub  U/O/ -   nSnU GH:  nUR                   Vs/ s H  n[!        5       PM     nnUR                   H  nUR#                  S5      nSn
UR                   H  nU
U;   a  U
S-  n
U
U;   a  M  U
Ul        U
UR$                  -   nUR&                  S:w  a{  [)        U5      S-   nUR&                  S:X  a
  UnUUl        O-[+        UR&                  U5      Ul        USUR&                  S-
   n[-        U
U5      nU H  nUR/                  U5        M     Un
[1        X5      nM     M     U[)        UR                  5      -  nGM=     U R3                  U5      nUR                  R5                  5       Ul        [7        U	5      Ul        UR                  S
   S:X  a  [;        UUU5      Ul        [?        U [         R@                  5      (       a  [         RB                  nO[         RD                  nURG                  XS   U/-   US   -   5      nUR                  R5                  5       Ul        SUl$        [J        RL                   H?  n UR                  U    UR                  U '   [J        RN                  U    UR                  U '   MA     U$ s  snf )a}  Take a table box and return it in its table wrapper box.

Also re-order children and assign grid positions to each column and cell.

Because of colspan/rowspan works, grid_y is implicitly the index of a row,
but grid_x is an explicit attribute on cells, columns and column group.

https://www.w3.org/TR/CSS21/tables.html#model
https://www.w3.org/TR/CSS21/tables.html#table-layout

)topbottomcaption_sider   r
   Nr(   r   Tr   border_collapsecollapserI  rJ  )(r   r7  r8  r?  r@  TableCaptionBoxrB  rT   r.   rX   r%  grid_xra   r9  	is_header	is_footerrU   rc   colspanrowspanrg   r   r:  r   r   copy_with_childrenr   tuplecolumn_groupsr   collapsed_border_gridrP   rA  InlineBlockBoxr   r_   is_table_wrapperr   TABLE_WRAPPER_BOX_PROPERTIESINITIAL_VALUES)!r"   ra   columnsrowsall_captionsby_typer   captionscaptionrV  rO  groupcolumn
grid_width
row_groupsbody_row_groupsheaderfooterr(   grid_heightrowoccupied_cells_by_rowoccupied_cells_in_this_rowcell
new_grid_xmax_rowspanspanned_rowsspanned_columnsoccupied_cellsr   r  r$  rt   s!                                    r#   rC  rC  ^  s    GDLg!!74|G U##E*  R(H~./66w?   e//1 2MF>>.. !'!	 ) jj F  Js%*@*@AJOFF++i(--&."EOF//FN"EOF""5)  '&R	'&R	1  K 38.. A.3. A>>C)>)B)B1)E&F ::aKF  ::$#dll2
<<1$"%&;"<q"@K||q('<'2'*4<<'E'<=NdllQ>N'O&+FJ&?O*6&--o> +7# 4
) %	 "2 	s5>>**; > "":.E++""$EK.E{{$%3&<:{',# #u++,,++~~))e_w&();;=GMM&&(GM#G 77#kk$/d&55d;D 8 Ng !Bs   =P(c                     [        U [        R                  5      (       a  U R                  5       (       a  U $ U R                   Vs/ s H  n[        U5      PM     nn[        X5      U l        U $ s  snf )zRemove and add boxes according to the flex model.

Take and return a ``Box`` object.

See https://www.w3.org/TR/css-flexbox-1/#flex-items

)rP   r   r   r'  ra   r   flex_childrenr(  s      r#   r   r     [     c5??++s~~/?/?
 03||<|e
5!|H< /CLJ =   A.c                    [        U [        R                  5      (       Gac  / nU GHX  nS Ul        UR	                  5       (       a  SUl        [        U[        R                  5      (       a"  UR                  R                  S5      (       d  Mi  [        U[        R                  5      (       aT  [        R                  R                  X3R                  5      nUR                  Ul        SUl        UR                  U5        M  [        U[        R                  5      (       aL  [        R                  R                  X3/5      nUR                  Ul        SUl        UR                  U5        GMG  UR                  U5        GM[     U$ U$ )Nc                      g)NFr+   r+   r%   r#   r/  flex_children.<locals>.<lambda>  s    ur%   Tr   )rP   r   FlexContainerBox
is_floatedis_in_normal_flowis_flex_itemr^   r]   r   rX  r   r_   ra   r.   rT   InlineLevelBox)r"   ra   rt  r   	anonymouss        r#   rt  rt    s   #u--..E,E&&((%)"%//

8H8H8M8M %!5!566!NN99%P	"'++	)-	&$$Y/E5#7#788!NN99%I	"'++	)-	&$$Y/$$U+) * r%   c                     [        U [        R                  5      (       a  U R                  5       (       a  U $ U R                   Vs/ s H  n[        U5      PM     nn[        X5      U l        U $ s  snf )zRemove and add boxes according to the grid model.

Take and return a ``Box`` object.

See https://drafts.csswg.org/css-grid-2/#grid-item

)rP   r   r   r'  ra   r   grid_childrenr(  s      r#   r   r     ru  rv  c                 
   [        U [        R                  5      (       Gab  / nU GHW  nUR                  5       (       a  SUl        [        U[        R
                  5      (       a"  UR                  R                  S5      (       d  Ma  [        U[        R                  5      (       aT  [        R                  R                  X3R                  5      nUR                  Ul        SUl        UR                  U5        M  [        U[        R                  5      (       aS  [        R                  R                  X3/5      nUR                  Ul        SUl        SUl        UR                  U5        GMF  UR                  U5        GMZ     U$ U$ )NTr   F)rP   r   GridContainerBoxr|  is_grid_itemr^   r]   r   rX  r   r_   ra   r.   rT   r~  )r"   ra   r  r   r  s        r#   r  r     s   #u--..E&&((%)"%//

8H8H8M8M %!5!566!NN99%P	"'++	)-	&$$Y/E5#7#788!NN99%I	"'++	%*")-	&$$Y/$$U+) * r%   c                 z   [        U [        R                  5      (       a  U R                  nU(       d  U$ [        R                  SU5      nU R                  S   S;   nU R                  S   S;   nU(       a  [        R                  SU5      nU(       a  UR                  SS5      nU(       aR  [        R                  SU5      =pRU(       a"  UR                  S5      (       a  USS nSU l        UR                  S5      nOS	nX l        OU R                   H  n[        U[        R                  [        R                  45      (       a=  [        Xa5      nU R!                  5       (       a  UR!                  5       (       a  UnMk  Mm  Mo  UR!                  5       (       d  M  S	nM     U=(       a    U R#                  5       (       + $ )
zFirst part of "The 'white-space' processing model".

See https://www.w3.org/TR/CSS21/text.html#white-space-model
https://drafts.csswg.org/css-text-3/#white-space-rules


r   )rx   nowraprx   r  zpre-liner   r
   NTF)rP   r   r^   r]   LINE_FEED_REsubr.   TAB_REreplaceSPACE_REr   leading_collapsible_spaceendswithra   r   rd   r|  r'  )r"   following_collapsible_spacer]   new_line_collapsespace_collapseprevious_textr   child_collapsible_spaces           r#   rd   rd   =  sx    #u}}%%xx.. d+IIm48LL=1 6, , ::dD)D
 <<c*D#+<<T#::M*ts/C/CABx04-*7*@*@*E'*/' \\E%%--!ABB*<+8'((**u/F/F/H/H2I/ 0I*((**.3+ " '?s~~/?+??r%   c                    [        U [        R                  5      (       aq  U R                  S   nUS:w  a&  S S [        S S.U   " U R
                  5      U l        U R                  S   S:X  a"  U R
                  R                  SS	5      U l        g g U R                  5       (       dP  U R                   H?  n[        U[        R                  [        R                  45      (       d  M4  [        U5        MA     g g )
Ntext_transformr*   c                 "    U R                  5       $ r3   )upperr]   s    r#   r/  (process_text_transform.<locals>.<lambda>x  
    $**,r%   c                 "    U R                  5       $ r3   )lowerr  s    r#   r/  r  y  r  r%   c                 ,    U R                  [        5      $ r3   )r   ASCII_TO_WIDEr  s    r#   r/  r  {  s    4>>-+Hr%   )	uppercase	lowercase
capitalizez
full-widthhyphens   ­r  )rP   r   r^   r.   r  r]   r  r'  ra   r   rf   )r"   r  r   s      r#   rf   rf   s  s    #u}}%%#34V#66(H	
 
 "hh(CH 99Y6)xx''"5CH * ^^\\E%%--!ABB&u- " r%   c                     SnSnU  HH  n[         R                  " U5      S   nU(       d  US;   a  SnUR                  5       nOUS:X  a  SnX#-  nMJ     U$ )uC   Capitalize words according to CSS’s "text-transform: capitalize".Fr  r   )LNTZ)unicodedatacategoryr  )r]   letter_foundoutputletterr  s        r#   r  r    s`    LF''/2J 6L\\^F_ L  Mr%   c                    U R                   (       a  U R                  5       (       a  U $ [        U R                   5      nU(       a#  U R                  SL a  US   R                  U l        / nSnU Hk  nU(       a  SUl        [	        U[
        R                  5      (       a  UR                  (       d  UR                  nMO  SnUR                  [        U5      5        Mm     U R                  SL a  X0l
        [	        U [
        R                  5      (       d  X l         U $ / n/ nU GHW  n[	        U[
        R                  5      (       a   eU(       a(  UR                  5       (       a  UR                  U5        MT  [	        U[
        R                  5      (       d  U(       as  UR                  5       (       d^  U(       dB  [	        U[
        R                  5      (       a#  UR                  S:X  a  UR                   S   S;   d  UR                  U5        M  M  U(       aR  [
        R                  R#                  X5      n[
        R$                  R#                  X/5      n	UR                  U	5        / nUR                  U5        GMZ     U(       ai  [
        R                  R#                  X5      nU(       a2  [
        R$                  R#                  X/5      n	UR                  U	5        OUR                  U5        X`l         U $ )a  Build the structure of lines inside blocks and return a new box tree.

Consecutive inline-level boxes in a block container box are wrapped into a
line box, itself wrapped into an anonymous block box.

This line box will be broken into multiple lines later.

This is the first case in
https://www.w3.org/TR/CSS21/visuren.html#anonymous-block-level

Eg.::

    BlockBox[
        TextBox['Some '],
        InlineBox[TextBox['text']],
        BlockBox[
            TextBox['More text'],
        ]
    ]

is turned into::

    BlockBox[
        AnonymousBlockBox[
            LineBox[
                TextBox['Some '],
                InlineBox[TextBox['text']],
            ]
        ]
        BlockBox[
            LineBox[
                TextBox['More text'],
            ]
        ]
    ]

Fr   Tr   r   r  )ra   r'  rX   r  rP   r   r^   r]   rT   r   trailing_collapsible_spaceBlockContainerBoxr   is_absolutely_positionedr~  r|  r.   r_   r   )
r"   box_childrenra   r  r   new_line_childrennew_children	child_boxline_boxr  s
             r#   r   r     sJ   L <<3>>++
%L55>O55 	% H!&
 &.2E+eU]]++EJJ).)H)H&).&OOOE23  %%.)C&c52233
L	i7777!C!C!E!E$$Y/	5#7#788!)*E*E*G*G !y%--88 NNc)OOM2 78 8!((38 ! !==77O!NN99#zJ	##I.$&!	*1 2 ==//G55c:FI	* )LJr%   c                    U R                   (       a  U R                  5       (       a  U $ / nSnU R                    H  n[        U[        R                  5      (       a  [        U R                   5      S:X  d   SU R                   -  5       eSn [        X4S9u  pVnUc  OM[        R                  R                  X/5      nUR                  U5        UR                  [        U5      5        M]  U(       a!  [        R                  R                  X/5      nOUnO[        U5      nXLa  SnUR                  U5        M     U(       a  Xl         U $ )a  Build the structure of blocks inside lines.

Inline boxes containing block-level boxes will be broken in two
boxes on each side on consecutive block-level boxes, each side wrapped
in an anonymous block-level box.

This is the second case in
https://www.w3.org/TR/CSS21/visuren.html#anonymous-block-level

Eg. if this is given::

    BlockBox[
        LineBox[
            InlineBox[
                TextBox['Hello.'],
            ],
            InlineBox[
                TextBox['Some '],
                InlineBox[
                    TextBox['text']
                    BlockBox[LineBox[TextBox['More text']]],
                    BlockBox[LineBox[TextBox['More text again']]],
                ],
                BlockBox[LineBox[TextBox['And again.']]],
            ]
        ]
    ]

this is returned::

    BlockBox[
        AnonymousBlockBox[
            LineBox[
                InlineBox[
                    TextBox['Hello.'],
                ],
                InlineBox[
                    TextBox['Some '],
                    InlineBox[TextBox['text']],
                ]
            ]
        ],
        BlockBox[LineBox[TextBox['More text']]],
        BlockBox[LineBox[TextBox['More text again']]],
        AnonymousBlockBox[
            LineBox[
                InlineBox[
                ]
            ]
        ],
        BlockBox[LineBox[TextBox['And again.']]],
        AnonymousBlockBox[
            LineBox[
                InlineBox[
                ]
            ]
        ],
    ]

Fr
   z9Line boxes should have no siblings at this stage, got %r.NT)
skip_stack)ra   r'  rP   r   r   rg   _inner_block_in_inliner   r_   rT   r    )	r"   r  changedr   stacknew_liner   anon	new_childs	            r#   r    r      s0   z <<3>>++
LGeU]]++s||$) B247LLAB) E)?*-&=~~44S*E##D)##OE$:;   "NN99#zJ	 %	 (.I!GI&9 < #Jr%   c                 L   / nSnSnSnUSL nU(       a  SnOUR                  5       u  u  pq[        U R                  US 5       H  u  pX-   n
[        U	[        R
                  5      (       a"  U	R                  5       (       a  Ub   eU	nU
S-  n
OY[        U	[        R                  5      (       a  [        X5      nSnUu  pnOUb   e[        U	5      nXLa  SnUR                  U5        Uc  M  X0nU R                  U5      n   O!   U(       d  U(       a  U R                  U5      n XU4$ )a  Find a block-level box in an inline formatting context.

If one is found, return ``(new_box, block_level_box, resume_at)``.
``new_box`` contains all of ``box`` content before the block-level box.
``resume_at`` can be passed as ``skip_stack`` in a new call to
this function to resume the search just after the block-level box.

If no block-level box is found after the position marked by
``skip_stack``, return ``(new_box, None, None)``

NFr   r
   T)r   r  ra   rP   r   BlockLevelBoxr|  r   r  r    rT   rT  )r"   r  r  block_level_box	resume_atr  is_startskipr  r   index	recursionr  s                r#   r  r  k  s9    LOIGT!H(..0cll4512ue1122''))%%%#OQJE%1125E	!
8A5	I!)))+E2	%	*&*I((6C- 30 d((6C**r%   c                    U nU R                   R                  5       S:X  aH  U R                  S   S:X  a5  U R                   H%  nUR                   R                  5       S:X  d  M#  Un  O   UR                  S   U l        SUR                  S'   U $ )z
Set a ``viewport_overflow`` attribute on the box for the root element.

Like backgrounds, ``overflow`` on the root element must be propagated
to the viewport.

See https://www.w3.org/TR/CSS21/visufx.html#overflow
r   overflowvisiblebody)rA   r  r.   ra   viewport_overflow)root_box
chosen_boxr   s      r#   r7   r7     s     J""$.NN:&)3&&E  &&(F2"
 '
 ",!1!1*!=H#,JZ Or%   c                     [        U [        R                  5      (       a  U R                  $ [        U [        R                  5      (       a&  SR                  S U R                  5        5       5      $ g)Nr  c              3   H  #    U  H  nUR                   R                  S 5      (       a  M%  UR                   R                  S5      (       a  MG  UR                   R                  S5      (       a  Mi  [        U[        R                  5      (       d  M  UR
                  v   M     g7f)z::beforez::afterr   N)rA   r  rP   r   r^   r]   )r   r   s     r#   r   box_text.<locals>.<genexpr>  sz      .$55$$--j9 !!**95  !!**:6  uemm,	 EJJ$5s   $B"B"B".B"B")rP   r   r^   r]   r   r   r   r!   s    r#   r  r    sW    #u}}%%xx	C	)	)ww .$'OO$5. . 	. r%   c                 ^  ^  T S;   a  [        U5      $ T S;   aI  [        U[        R                  5      (       a)  SR	                  U 4S jUR                  5        5       5      $ gT S:X  aF  SnSn[        U5      nU H/  n[        R                  " U5      nUS;  a  U(       a    U$ SnX5-  nM1     U$ g )	N)r]   rB   )rJ   rM   r  c              3      >#    U  HV  nUR                   R                  S T 35      (       d  M(  [        U[        R                  5      (       a  MI  [        U5      v   MX     g7f)rz   N)rA   r  rP   r   r   r  )r   r   	text_parts     r#   r   extract_text.<locals>.<genexpr>  sN      8->E$$--9+.>?  ueoo6  ->s   'A!A!A!rH   F)PsPePiPfPoT)r  rP   r   r   r   r   r  r  )r  r"   character_foundfirst_letterr]   r  r  s   `      r#   r   r     s    ''}	)	)c5??++77 8-0__->8 8 8 	n	$}F"++F3H=="  #'"L   
%r%   r3   )NNNNNNN)NN)F)F__doc__rer  r  r   cssr   r   layout.tabler   loggerr   text.constantsr	   r   r   r   rX  r>  rA  FlexBoxInlineFlexBoxGridBoxInlineGridBoxr?  r@  r7  r8  r2  rN  r@   r:  chrr  r   compiler  r  r  r$   r>   rC   r4   r[   rY   r   r`   r   r}   re   rS   searchr  r%  r   r"  rC  r   rt  r   r  rd   rf   r  r   r    r  r7   r  r   )r  s   0r#   <module>r     s   
   % 1  , u~~ ENN	
 U11  -- u}} ++ u}} ++  E%%!" %00#$ U33%& U33'( u++)* U66+, U''-. --/ 6 .34->?->CF
O#->?   HH5 6zz'"	$	%::h@. FJ^KB+\?H ?CIM!%	y| )-'T5DH2-($N ,.::e+<+C+C P
64/ [|@F":":3@l.&m`cL2+j,
m, @s   )H