
    Bh                     f   S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	J
r
  SSKJr  S	S
KJrJr  S	SKJrJr  S	SKJr  S	SKJrJr  S	SKJr  S	SKJrJr  \" S/ SQ5      r " S S5      r " S S\5      r " S S\5      r S r!S r"S r#S r$S r%S r&\S 5       r'\S 5       r(S  r)S! r*S" r+S# r,S$ r-S% r.g)&z'Layout for pages and CSS3 margin boxes.    N)
namedtuple)inf   )computed_from_cascaded)boxesbuild)PROGRESS_LOGGER   )absolute_box_layoutabsolute_layout)block_container_layoutblock_level_layout)float_layout)handle_min_max_heighthandle_min_max_width)resolve_percentages)max_content_widthmin_content_widthPageType)sideblanknameindexgroupsc                   x    \ rS rSr\S 5       r\S 5       r\R                  S 5       r\S 5       r\S 5       r	Sr
g)	OrientedBox   c                 N    U R                   U R                  -   U R                  -   $ N)padding_plus_bordermargin_amargin_bselfs    H/var/www/html/env/lib/python3.13/site-packages/weasyprint/layout/page.pysugarOrientedBox.sugar   s     ''$--7$--GG    c                 4    U R                   U R                  -   $ r   )r&   innerr#   s    r%   outerOrientedBox.outer   s    zzDJJ&&r(   c                 z    [        [        U R                  XR                  -
  5      U R                  5      U l        g r   )minmaxmin_content_sizer&   max_content_sizer*   )r$   new_outer_widths     r%   r+   r,      s.    %%'CD!!#
r(   c                 p    U R                   U R                  S:X  a  U R                  -   $ U R                  -   $ Nauto)r&   r*   r0   r#   s    r%   outer_min_content_size"OrientedBox.outer_min_content_size#   <    zz%)ZZ6%9D!!K 	K?CzzK 	Kr(   c                 p    U R                   U R                  S:X  a  U R                  -   $ U R                  -   $ r4   )r&   r*   r1   r#   s    r%   outer_max_content_size"OrientedBox.outer_max_content_size(   r8   r(   )r*   N)__name__
__module____qualname____firstlineno__propertyr&   r+   setterr6   r:   __static_attributes__ r(   r%   r   r      sn    H H ' ' \\# #
 K K K Kr(   r   c                   @    \ rS rSrS rS r\S 5       r\S 5       rSr	g)VerticalBox.   c                     Xl         X l        UR                  U l        UR                  U l        UR                  U l        UR                  UR                  -   UR                  -   UR                  -   U l        g r   )contextboxheightr*   
margin_topr!   margin_bottomr"   padding_toppadding_bottomborder_top_widthborder_bottom_widthr    r$   rH   rI   s      r%   __init__VerticalBox.__init__/   sg     ZZ
))OOc000  !#&#:#:; 	 r(   c                     U R                   nU R                  Ul        U R                  Ul        U R
                  Ul        g r   )rI   r*   rJ   r!   rK   r"   rL   r$   rI   s     r%   restore_box_attributes"VerticalBox.restore_box_attributes;   s-    hhZZ
 MMr(   c                     g)Nr   rC   r#   s    r%   r0   VerticalBox.min_content_sizeB   s    r(   c                     g)Ng    .ArC   r#   s    r%   r1   VerticalBox.max_content_sizeF   s    r(   )rI   rH   r*   r!   r"   r    N
r<   r=   r>   r?   rR   rV   r@   r0   r1   rB   rC   r(   r%   rE   rE   .   s4    
<*    r(   rE   c                   @    \ rS rSrS rS r\S 5       r\S 5       rSr	g)HorizontalBoxK   c                    Xl         X l        UR                  U l        UR                  U l        UR                  U l        UR                  UR                  -   UR                  -   UR                  -   U l        S U l        S U l        g r   )rH   rI   widthr*   margin_leftr!   margin_rightr"   padding_leftpadding_rightborder_left_widthborder_right_widthr    _min_content_size_max_content_sizerQ   s      r%   rR   HorizontalBox.__init__L   sy    YY
((s000!!"$'$:$:; 	  "&!%r(   c                     U R                   nU R                  Ul        U R                  Ul        U R
                  Ul        g r   )rI   r*   ra   r!   rb   r"   rc   rU   s     r%   rV   $HorizontalBox.restore_box_attributesX   s-    hhJJ	--==r(   c                 |    U R                   c$  [        U R                  U R                  SS9U l         U R                   $ NF)r+   )rh   r   rH   rI   r#   s    r%   r0   HorizontalBox.min_content_size^   6    !!)%6dhhe&5D"%%%r(   c                 |    U R                   c$  [        U R                  U R                  SS9U l         U R                   $ rn   )ri   r   rH   rI   r#   s    r%   r1   HorizontalBox.max_content_sizee   rp   r(   )ri   rh   rI   rH   r*   r!   r"   r    Nr\   rC   r(   r%   r^   r^   K   s4    
&) & & & &r(   r^   c                    U(       a  [         O[        " X5      nUR                  [        S UR                  UR
                  UR                  4 5       5      -   nXR:  aE  UR                  S:X  a  SUl        UR
                  S:X  a  SUl        UR                  S:X  a  SUl        SUR                  UR
                  UR                  4;  a  U(       a  SUl        OSUl        UR                  UR
                  UR                  /R                  S5      S:X  a  UR                  S:X  a.  X!R                  -
  UR                  -
  UR
                  -
  Ul        O{UR                  S:X  a.  X!R                  -
  UR
                  -
  UR                  -
  Ul        O=UR
                  S:X  a-  X!R                  -
  UR                  -
  UR                  -
  Ul        UR                  S:X  a[  UR                  S:X  a  SUl        UR
                  S:X  a  SUl        X!R                  -
  UR                  -
  UR
                  -
  Ul        UR                  UR
                  s=:X  a  S:X  a-  O  O*X!R                  -
  UR                  -
  S-  =Ul        Ul        SUR                  UR
                  UR                  4;  d   eUR                  5         g)aj  Compute and set a margin box fixed dimension on ``box``.

Described in: https://drafts.csswg.org/css-page-3/#margin-constraints

:param box:
    The margin box to work on
:param outer:
    The target outer dimension (value of a page margin)
:param vertical:
    True to set height, margin-top and margin-bottom; False for width,
    margin-left and margin-right
:param top_or_left:
    True if the margin box in if the top half (for vertical==True) or
    left half (for vertical==False) of the page.
    This determines which margin should be 'auto' if the values are
    over-constrained. (Rule 3 of the algorithm.)
c              3   6   #    U  H  nUS :w  d  M  Uv   M     g7f)r5   NrC   ).0values     r%   	<genexpr>*compute_fixed_dimension.<locals>.<genexpr>   s       *B%F? 	Bs   
	r5   r   r
   r   N)	rE   r^   r    sumr!   r"   r*   countrV   )rH   rI   r+   verticaltop_or_lefttotals         r%   compute_fixed_dimensionr~   m   sI   $ #;5w
DC ##c *LL#,,		B* ' E }<<6!CL<<6!CL99
 CIcllCLL#))<<!CL!CLcllCII.44V<A99!8!88&(+5CI\\V#!$;$;;LL)+.995CL\\V#!$;$;;LL)+.995CL yyF<<6!CL<<6!CL444\\"$'LL1	 ||s||-v-+++cii71'= 	=s| #,,cii@@@@ r(   c                 N	   U(       a  [         O[        nU Vs/ s H
  oT" X5      PM     nnUu  pgnU H3  nUR                  S:X  a  SUl        UR                  S:X  d  M,  SUl        M5     UR                  R
                  (       Gd2  UR                  S:X  d   eUR                  UR                  s=:X  a  S:X  Ga  O  GOUUR                  UR                  -   :  at  UUR                  -
  UR                  -
  n	UR                  n
UR                  nX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        UR                  X-  U-  -   Ul	        GOUUR                  UR                  -   :  a  UUR                  -
  UR                  -
  n	UR                  UR                  -
  n
UR                  UR                  -
  nX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        UR                  X-  U-  -   Ul	        GOhUUR                  -
  UR                  -
  n	UR                  n
UR                  nX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        UR                  X-  U-  -   Ul	        GOUR                  S:X  a  X8R                  -
  Ul	        GOUR                  S:X  a  X6R                  -
  Ul	        GOUR                  S:X  GaM  S[        UR                  UR                  5      -  nUUR                  U-   :  aF  UUR                  -
  U-
  n	UR                  nUnX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        OS[        UR                  UR                  5      -  nUUR                  U-   :  aV  UUR                  -
  U-
  n	UR                  UR                  -
  nUU-
  nX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        OEUUR                  -
  U-
  n	UR                  nUnX-   nUS:X  a  SnUR                  X-  U-  -   Ul	        UR                  S:X  a  X7R                  -
  S-  Ul	        UR                  S:X  a  X7R                  -
  S-  Ul	        SU Vs/ s H  oUR                  PM     sn;  d   eU H  nUR                  5         M     gs  snf s  snf )u-  Compute and set a margin box fixed dimension on ``box``

Described in: https://drafts.csswg.org/css-page-3/#margin-dimension

:param side_boxes:
    Three boxes on a same side (as opposed to a corner).
    A list of:
    - A @*-left or @*-top margin box
    - A @*-center or @*-middle margin box
    - A @*-right or @*-bottom margin box
:param vertical:
    ``True`` to set height, margin-top and margin-bottom;
    ``False`` for width, margin-left and margin-right.
:param available_size:
    The distance between the page box’s left right border edges

r5   r   r
   r   N)rE   r^   r!   r"   rI   is_generatedr*   r:   r1   r+   r6   r0   r/   rV   )rH   
side_boxesr{   available_size	box_classrI   box_abox_bbox_c
flex_spaceflex_factor_aflex_factor_cflex_factor_sumac_max_content_sizeflex_factor_bflex_factor_acac_min_content_sizes                    r%   compute_variable_dimensionr      s)   $  (]I5?@Zc)G)ZJ@$E%<<6!CL<<6!CL	  99!!!{{a;;%++///000012 #001001  !& < < % < <"/"?"a'&'O#44.@B#44.@B000012 #001001 
 **U-C-CC  **U-C-CC "/"?"a'&'O#44.@B#44.@B
 #001001  !& 6 6 % 6 6"/"?"a'&'O#44.@B#44.@B {{f$,{{:&,{{:;;& "#c,,e.J.J'L #L003FFH #001'(  !& < <!4"/"@"a'&'O#44.@B '(#00%2N2N+P 'P#!447JJL '445+, 
 ..1G1GG "%8;N%NN&3&DO&!+*+"'"8"8"2_D#FEK '445+,  %*$:$:M%8N&3&DO&!+*+"'"8"8"2_D#FEK;;& )KK71<EK;;& )KK71<EK z:z))z::::""$ A A| ;s   R&R"c                     SnS HO  nX   S:X  a  SX'   M  / nX    H'  u  pVUS:X  a  SnUS:w  d  M  UR                  XV45        M)     [        U5      X'   MQ     Uc  U(       d  S	U S
   -   U S
'   ggg)zDrop 'pages' counter from style in @page and @margin context.

Ensure `counter-increment: page` for @page context if not otherwise
manipulated by the style.

F)counter_setcounter_resetcounter_incrementr5   rC   pageTpagesN))r   r
   r   )appendtuple)stylepseudo_typepage_counter_touchedpropnamejustified_valuesr   rv   s          r%    _standardize_page_based_countersr   K  s     !I?f$ EO ?KDv~'+$w ''6	 +
   01 J #7&!"56&7!" $8r(   c           
   #     ^ ^^#    U UU4S jnTR                   nTR                  nTR                  nTR                  nTR	                  5       nTR                  5       n	Xh-   n
XI-   n/ nSSX4US4SSX4Xk4SSXi4SU4SSXy4X44 GH$  u  pnnnU(       a
  / S	QnUu  nnO	/ S
QnUu  nnU Vs/ s H  nU" SU SU 3U5      PM     nn[        S U 5       5      (       d  M[  [        T UUU5        [        U/ SQ5       H  u  nnUR                  (       d  M  UUl
        UUl        U(       a*  U=R                  UUUR                  5       -
  -  -  sl        O)U=R                  UUUR                  5       -
  -  -  sl
        [        T UUU(       + US;   5        UR                  U5        M     GM'     SXdSS4SXtU
S4SXeSU4SXuX44 Hj  u  nnnnnU" UUU45      nUR                  (       d  M'  UUl
        UUl        [        T UUSSU;   5        [        T UUSSU;   5        UR                  U5        Ml     U H  n[!        T TU5      v   M     gs  snf 7f)zYield laid-out margin boxes for this page.

``state`` is the actual, up-to-date page-state from
``context.page_maker[context.current_page]``.

c                 6  > T	R                  T
R                  U 5      nUc  [        S0 T
R                  S9n[	        X 5        [
        R                  " X5      nUS   S;  Ul        UR                  (       a  [        R                  " T5      nUu  pVnUR                  [        5       5        [        R                  " XCR                  5        [        R                  " UR                  X5UT	R                  T	R                   T	R"                  T	T
5	      Ul        [        R&                  " U5        [        R(                  " U5        [        R*                  " U5      n[-        X15        UR                  (       d(  S=Ul        Ul        S H  nUR3                  U5        M     U$ )a)  Return a margin box with resolved percentages.

The margin box may still have 'auto' values.

Return ``None`` if this margin box should not be generated.

:param at_keyword:
    Which margin box to return, e.g. '@top-left'
:param containing_block:
    As expected by :func:`resolve_percentages`.

N)elementcascadedparent_stylecontent)normalinhibitnoner   )toprightbottomleft)	style_for	page_typer   r   r   r   	MarginBoxr   copydeepcopyr   setr   update_counterscontent_to_boxesget_image_from_uritarget_collectorcounter_stylechildrenprocess_whitespaceprocess_text_transformcreate_anonymous_boxesr   ra   rJ   _reset_spacing)
at_keywordcontaining_blockr   rI   margin_statequote_depthcounter_valuescounter_scopesr   rH   r   states            r%   make_box#make_margin_boxes.<locals>.make_boxl  sO    !!$..*==*r

DE(;ooj0 !+ 4) ) ==/L:F7K!!#%(!!,		: 11		3^**G,D,D%%w6CL $$S)((-..s3CC2%&&CI
:""4( ;
r(   r   Fr   r   r   Tr   )r   middler   )r   centerr   @-c              3   8   #    U  H  oR                   v   M     g 7fr   )r   )ru   rI   s     r%   rw   $make_margin_boxes.<locals>.<genexpr>  s     :z##zs   )r   g      ?r
   )r   r   z@top-left-cornerz@top-right-cornerz@bottom-left-cornerz@bottom-right-cornerN)rK   rL   rb   rc   border_widthborder_heightanyr   zipr   
position_x
position_ymargin_heightmargin_widthr~   r   margin_box_content_layout)rH   r   r   r   rK   rL   rb   rc   max_box_widthmax_box_height
page_end_x
page_end_ygenerated_boxesprefixr{   r   r   r   suffixesfixed_outervariable_outersuffixr   rI   offsetr   cb_width	cb_heights   ```                         r%   make_margin_boxesr   d  s    -^ J&&M""K$$L%%'M'')N ,J,J O 
2		5=8	%	4z		$6	$	GB*J
 2H*:'K2H*:'NK #$" q&*,<=" 	 $ :z:::"Z>	;z;7KC##'CN'CN&"S%6%6%88#: : &"S%5%5%77#9 9#kx</)+ ""3' 81	GV 
[a;	l
AF	AzJ		$	D?
HiZ zHi#89##S)T5J+>	@S(E6Z+?	As#!D$ 's;; Y$s   B&I+I	F
Ic                    / n[        X[        * SSX3SSSS9
u  p$n    nUb   eU H  n[        XX#SSS9  M     UR                  S   nUS;   a  UR                  (       a  UR                  S   n	UR                  S	   n
U	R
                  nU
R
                  U
R                  5       -   nX-
  nUR                  U-
  nUS
:X  a  US-  nUR                   H  nUR                  SU5        M     U$ )u<   Layout a margin box’s content once the box has dimensions.NTF)bottom_space
skip_stackpage_is_emptyabsolute_boxesfixed_boxesadjoining_marginsdiscard	max_linesr   r   r   vertical_align)r   r   r   r   )	r   r   r   r   r   r   r   rJ   	translate)rH   r   rI   positioned_boxes	resume_at	next_page_absolute_boxr   first_child
last_childr   r   content_heightr   childs                   r%   r   r     s   )?C4D'*?&CIq!Q (3q	 )
 YY/0N--#,,ll1o\\"%
$$ &&)A)A)CCn,X%aKF\\EOOAv& "Jr(   c                 D   XR                   -
  nU R                  S:X  aO  U R                  S:X  a  SU l        U R                  S:X  a  SU l        X R                  -
  U R                  -
  U l        OU R                  U R                  s=:X  a  S:X  a!  O  OX R                  -
  S-  =U l        U l        OaU R                  S:X  a!  X R                  -
  U R                  -
  U l        O0U R                  S:X  a   X R                  -
  U R                  -
  U l        U R	                  5         g)a  Take a :class:`OrientedBox` object and set either width, margin-left
and margin-right; or height, margin-top and margin-bottom.

"The width and horizontal margins of the page box are then calculated
 exactly as for a non-replaced block element in normal flow. The height
 and vertical margins of the page box are calculated analogously (instead
 of using the block height formulas). In both cases if the values are
 over-constrained, instead of ignoring any margins, the containing block
 is resized to coincide with the margin edges of the page box."

https://drafts.csswg.org/css-page-3/#page-box-page-rule
https://www.w3.org/TR/CSS21/visudet.html#blockwidth

r5   r   r   N)r    r*   r!   r"   rV   )rI   containing_block_size	remainings      r%   page_width_or_heightr   	  s     &(?(??I
yyF<<6!CL<<6!CL,s||;			/	/'099'<&AAs|		 99,s||;		 99,s||; r(   c                 .    [        [        X5      U5        g r   )r   r^   )rI   rH   containing_block_widths      r%   
page_widthr   (  s    w46LMr(   c                 .    [        [        X5      U5        g r   )r   rE   )rI   rH   containing_block_heights      r%   page_heightr   -  s    W24KLr(   c                    U R                  U5      nUR                  US'   [        R                  " X&5      nUR                  S   n[        Xx5        SUl        SUl        Uu  p[        XpU	5        [        XpU
5        UR                  5       Ul        UR                  5       Ul        UR                  UR                  -   U l        UnU R                  US5      n[        R                  " X|5      n[        X5        UR                  5       Ul        U R                  Ul        UR                  (       a  UnUR!                  / 5      n[#        U[        R$                  5      (       d   eU R'                  5         X@l        / U l        Xl        U R.                  n/ U l        [1        U5       H^  u  nnU R2                  R5                  U5        U R7                  U5      nU(       d  M;  US:w  d  MC  U R9                  U5        UUS U l          O   Sn/ n/ n/ n0 nU R:                  R=                  5       nUU l        U H  u  nnnUR                  5       Ul        UR?                  5       (       a  [A        U UUUUSU5      u  nnO*URC                  5       (       d   e[E        U UUUSU5      u  nnUR5                  U5        U(       d  M  UUU4UU'   M     [G        XSX;UUUU5	      u  pn    nU(       d   eUURH                  -   Ul$        [J        RL                  " URO                  5       5      n[G        X[P        * SURR                  SUU5      S   nURU                  URW                  5       * S9  U V s/ s H.  n U RX                  R                  S   S	:X  d  M"  U RX                  PM0     sn Ul-        U H  n![]        U U!UUSSS
9  M     U R_                  U5        X/Ul$        [a        US5        [J        Rb                  " XV5        US   n"U Rd                  n#U Rf                  n$U$US-
     S   n%/ n&/ n'U$SUS-
    HK  u        nn(U&Ri                  U(Rk                  S/ 5      5        U'Ri                  U(Rk                  S/ 5      5        MM     URm                  SS9 GH,  n)U)R                  S   n*U*(       aB  U*U&;  a<  U%S   R5                  U*5        U&R5                  U*5        U#Ro                  U*U"US-
  U$5        U)Rp                  (       a(  U#Rr                  Rk                  U)Rp                  S45      n+OSn+U+c  M  Sn,[u        U+5      n-U-U';  n.U.(       a/  U%S   R5                  U-5        U'R5                  U-5        US-
  U+l;        U+Rx                  (       a4  U"U+Rz                  :w  a  [|        RN                  " U"5      U+l=        SU+l<        Sn,U+R~                  n/U/(       a_  SU/;   a  SU%S'   U.(       aM  U"U+Rz                  :w  a=  [|        RN                  " U"5      U+l=        U/ H  n0U"Rk                  U0S5      n1U1c  M  Sn,  O   U+R                  n2U2R                  5        HQ  u  n3n4SU4;  a  M  U#R                  Rk                  U3S5      n5U5Rv                  n6U6S:  d  M>  U3U&;   d  MF  SU$U6   S   S'   MS     U,(       d  GM  SU%S'   U+R                  U"5        GM/     UR                  (       a  WnU$US-
     S   nXsU4$ s  sn f )a  Take just enough content from the beginning to fill one page.

Return ``(page, finished)``. ``page`` is a laid out PageBox object
and ``resume_at`` indicates where in the document to start the next page,
or is ``None`` if this was the last page.

:param int page_number:
    Page number, starts at 1 for the first page.
:param resume_at:
    As returned by ``make_page()`` for the previous page, or ``None`` for
    the first page.

overflowsizer   z	@footnoteNT)dypositionfixedr   r
   r   anchorscontent_lookups)placeholdersanchorr   Fr   pages_wantedcontent_changed)Dr   viewport_overflowr   PageBoxr   r   r   r   r   r   content_box_xcontent_box_yrJ   page_bottomFootnoteAreaBoxr   copy_with_children
isinstanceBlockLevelBoxcreate_block_formatting_contextcurrent_pagecurrent_page_footnotescurrent_footnote_areareported_footnotes	enumerate	footnotesr   layout_footnotereport_footnotebroken_out_of_flowvalues
is_floatedr   is_absolutely_positionedr   r   r   r   r   r   r   r   r   r   _boxr   r   finish_block_formatting_contextr   r   r   
page_makerextendgetdescendantscache_target_page_countersmissing_linkcounter_lookup_itemsidpage_maker_indexpendingcached_page_counter_valuesr   missing_countersmissing_target_countersitemstarget_lookup_itemsparse_again)7rH   root_boxr   r   page_number
page_stater   r   device_sizer   r   initial_containing_blockfootnote_area_stylefootnote_areaprevious_resume_atr  ireported_footnoter  r   r   r   out_of_flow_boxesr  context_out_of_flowrI   r   r   out_of_flow_boxout_of_flow_resume_atr   r   placeholderr   page_counter_valuesr   r%  remake_statecached_anchorscached_lookupsx_remake_stater   r
  counter_lookupcall_parse_againcounter_lookup_idrefresh_missing_countersr0  counter_namecounter_valuetarget_missinganchor_namemissed_countersitemr-  s7                                                          r%   	make_pagerS  2  s3    i(E !22E*==*D**V$K*DODO%Hth'y),,.H,,.H"--;G#!++I{C))$DM,#113M&22M&..r2 h 3 34444++-&%'G"$1! 33!#G )*< =  !23**+<=8Q##$56);AB)?G& !> M!44;;=!3G-@)z!//1>>5A.0@ !Z612O2 //11115H.0@!62O2 	  1  %'<3>/ .A /A1i')9;L/N+HAq! O8)H,=,==H001G1G1IJM&dM,>,>*,,-/M  ; ; ==> -=:,<[!!*-8 	,<:D )\4)9	 )
 ++H5-DM %UD1	*,$Q- //##J kAo.r2L
 NN(23CK!O(D$Aq!^n00B?@n001BBGH )E !!t!4X&fN2#**62!!&)77+[1_jJ -BBFF##Y/1N "N %$ !#> 2'8'N$'./667HI%%&782=// %%'&AAB@D+A-N=).&#' 
  .>>..37L0+0C&AA1B &9: #=(8(;(?(?($)0(4/3,! )9 ,CCN0>0D0D0F,_/1';;??'#'#8#8 #q([N-JGKJ/04^D 1G  26./**+>?[ 5^ &	{Q/2	I%%k:s   &![[c           	      $   UR                  U 5        UR                  U UR                  UR                  UR                  S9  UR	                  5        H;  u  p4U(       d  M  X0:X  d  M  UR                  X4UR                  UUR                  S9  M=     g)zASet style for page types and pseudo-types matching ``page_type``.)rootparentbase_url)r   rU  rV  rW  N)add_page_declarationsset_computed_stylesetree_elementrW  get_cascaded_styles)r   htmlr   r   r   s        r%   set_page_type_computed_stylesr]    s    ##I. !! (:(: "   !* = = ?;7/))''	 * ( !@r(   c                 p    U(       d  gUR                  5       u  u  p#U b  X ;  a  gUc  g[        X   U5      $ )NTF)r2  _includes_resume_at)r   page_group_resume_atpage_child_indexpage_child_resume_ats       r%   r_  r_  !  sF    0D0J0J0L-,,=#y:<PQQr(   c                 X   [        U 5      n[        U S S  5       H:  u  pg[        XS   5      (       a  US==   S-  ss'   M'  U R                  Xe-
  5        M<     U(       d:  U(       a	  US   S:X  d
  US   (       d  US   $ U (       a  U S   S   US   :X  a  US   $ [        R
                  " U5      =(       d    SS 0=pUn
 [        UR                  5       5      S   u  pU
nU
R                  U   n
Uc  OUnM7  U(       a  UR                  S   $  U
R                  S   US   :X  a  U R                  US   SU	/5        US   $ [        U
[        R                  5      (       d  US   $ [        U
R                  5       H*  u  pnUR                  5       (       d  M  US 0X'   X   nUnUn
  O   US   $ M  )Nr   r
   breakr   r   r   r   )lenr  r_  popr   r   r   r2  r   r   r   r  r   	ParentBoxis_in_normal_flow)page_groupsr   r   r5  r   page_groups_lengthr=  
page_groupcurrent_resume_atr`  current_elementchild_indexchild_resume_atparent_elementr   s                  r%   _update_page_groupsrq  ,  s    [)";q>2yQ-88qMQMOOA23	 3 )G,5i>OV$$;r?1-61BBV$$ 04}}Y/G/TAt9TO
',->-D-D-F'G'K$()22;?"+  ##F++   (If,==	& 116JKLV$$/5??;;V$$!/":":;HA**,,./Y* 1 >K#O < V$$# r(   c                    UR                   nXP   u  pgpn
[        R                  " U	5      n	US   S;   a  US   nO3US   S;   a(  UR                  S   S:H  nUS   S:H  nX-  (       a  SOSnOS	n[	        US:H  =(       a    U=(       d1    US:H  =(       a    U(       + =(       d    UR
                  =(       a    US	L 5      nU(       a  SOSn[        XXsU5      n[        S
 U 5       5      n[        XUU U5      n[        UXBR                  5        US   S:g  =(       d    US   Ul        SUl        U S-   n[        X#UUUU	5      u  npgU(       d   eU(       + nU S-   [        U5      :  a  SnO6XPS-      u  nnnnn
UU:g  =(       d    UU:g  =(       d    UU:g  =(       d    UU	:g  nU(       aA  SS/ / S.nUS	LUS'   XgXU4nU S-   [        U5      :  a  UR                  U5        UU4$ UXPS-   '   UU4$ )a  Return one laid out page without margin boxes.

Start with the initial values from ``context.page_maker[index]``.
The resulting values / initial values for the next page are stored in
the ``page_maker``.

As the function's name suggests: the plan is not to make all pages
repeatedly when a missing counter was resolved, but rather re-make the
single page where the ``content_changed`` happened.

rd  )r   r   )rectoverso	directionltrrt  r   r   Nc              3   .   #    U  H  u  po1U4v   M     g 7fr   rC   )ru   r   r   r   s       r%   rw   remake_page.<locals>.<genexpr>  s     C{^T!%={s   r   r   Fr
   T)r  r  r  r  r  )r%  r   r   r   boolr  rq  r   r   r]  r   forced_breakmargin_clearancerS  re  r   )r   ri  rH   r5  r\  r%  r   r   
right_pager7  r   next_page_sidedirection_ltrbreak_versor   r   r   r   r   r6  r   page_maker_next_changednext_resume_atnext_next_pagenext_right_pagenext_page_staterE  rR  s                               r%   remake_pager  g  sR    ##J6@6G3I*! z*J.."7+	7	1	1 {3u<(G3$1$?V	6	!	0j 	;	7	"	5:~	;		#	#	9	T(9<E !7fD{yERDC{CCFdE6:I!)T3D3DE%g.%7L9V;LG$G !)K!*9ij"JD)9J qyC
O#"& qy! 	L! i' *i'*z)* z)	 	    %!!	
 +44*?&'Z\I19J'd# ? %)Jqy!?r(   c              #   H  #    SnSn/ n U R                   U   S   n[        U5      S:X  d  US   (       d
  US   (       aN  [        R                  " SUS-   5        SUS'   SUS'   / US	'   / US
'   [	        XFXU5      u  pU R
                  nUv   O7[        R                  " SUS-   5        U R                   US-      S   n	SnX4   v   US-  nU	cS  U(       dL  U R                   SUS-    U l         U R                  R                  5         U R
                  R                  5         gGM  7f)zYReturn a list of laid out pages without margin boxes.

Re-make pages only if necessary.

r   Nr   r  r  z"Step 5 - Creating layout - Page %dr
   Fr  r  z/Step 5 - Creating layout - Page %d (up-to-date))r%  re  r	   infor  r  r  clear)
rH   r5  r\  r   r=  r  ri  rE  r   r   s
             r%   make_all_pagesr    s@     	
AK
))!,R0J!O./^,  !Eq1uM.3L*++0L(&(L#.0L*+)!'TROD!(!;!;J  A1q5J**1q51!4I!%(N	Q%7!(!3!3FQU!;G&&,,.&&,,.7 s   D D")/__doc__r   collectionsr   mathr   cssr   formatting_structurer   r   loggerr	   absoluter   r   blockr   r   floatr   min_maxr   r   percentr   	preferredr   r   r   r   rE   r^   r~   r   r   r   r   r   r   r   rS  r]  r_  rq  r  r  rC   r(   r%   <module>r     s    -  "  ( / $ : =  @ ( ;j"NOK K4+ :&K &DD!NT%n72C<L>!> N N M MV&r(,R8%vNb$r(   