
    hO                       % S r SSKJr  SSKJr  SSK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Jr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJr  SSKJr  SSKJ r J!r!J"r"J#r#J$r$  SSK%J&r&J'r'  Sr(S\)S'    " 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 S5      r0g )!z'Section-related custom element classes.    )annotations)deepcopy)CallableIteratorListSequencecast)etree)	TypeAlias)WD_HEADER_FOOTERWD_ORIENTATIONWD_SECTION_START)nsmap)CT_OnOff)ST_SignedTwipsMeasureST_TwipsMeasure	XsdString)CT_Tbl)CT_P)BaseOxmlElementOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOne)LengthlazypropertyzCT_P | CT_Tblr   BlockElementc                  r    \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   \" SSS9r\" SSS9r\	SS j5       r
Srg)	CT_HdrFtr   zN`w:hdr` and `w:ftr`, the root element for header and footer part respectively.zCallable[[], CT_P]add_pz
List[CT_P]p_lstzList[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl]_insert_tblzw:p 
successorszw:tblc                $    U R                  S5      $ )zGenerate all `w:p` and `w:tbl` elements in this header or footer.

Elements appear in document order. Elements shaded by nesting in a `w:ins` or
other "wrapper" element will not be included.
z./w:p | ./w:tbl)xpathselfs    C/var/www/html/env/lib/python3.13/site-packages/docx/oxml/section.pyinner_content_elements CT_HdrFtr.inner_content_elements)   s     zz+,,    N)returnzList[CT_P | CT_Tbl])__name__
__module____qualname____firstlineno____doc____annotations__r   ptblpropertyr-   __static_attributes__r%   r/   r,   r   r      sG    X++5R(A
W
,C- -r/   r   c                  R    \ rS rSr% Sr\" S\5      rS\S'   \" S\	5      r
S\S'   S	rg
)CT_HdrFtrRef3   z5`w:headerReference` and `w:footerReference` elements.w:typer   type_zr:idstrrIdr%   N)r1   r2   r3   r4   r5   r   r   r?   r6   r   rA   r:   r%   r/   r,   r<   r<   3   s0    ?/"E  !3C3r/   r<   c                      \ rS rSr% Sr\" S\5      rS\S'   \" S\	5      r
S\S'   \" S\5      rS\S	'   \" S
\	5      rS\S'   \" S\	5      rS\S'   \" S\	5      rS\S'   \" S\	5      rS\S'   Srg)
CT_PageMar<   z-``<w:pgMar>`` element, defining page margins.zw:topLength | Nonetopzw:rightrightzw:bottombottomzw:leftleftzw:headerheaderzw:footerfooterzw:guttergutterr%   N)r1   r2   r3   r4   r5   r   r   rF   r6   r   rG   rH   rI   rJ   rK   rL   r:   r%   r/   r,   rC   rC   <   s    7*&C  -?E=  .)FM  ,/D-  .OFM  .OFM  .OFM r/   rC   c                      \ rS rSr% Sr\" S\5      rS\S'   \" S\5      r	S\S'   \" S\
\
R                  S	9rS
\S'   Srg)	CT_PageSzV   z?``<w:pgSz>`` element, defining page dimensions and orientation.zw:wrE   wzw:hhzw:orient)defaultr   orientr%   N)r1   r2   r3   r4   r5   r   r   rP   r6   rQ   r   PORTRAITrS   r:   r%   r/   r,   rN   rN   V   sS    I(A}  )A}  /NN,C,CFN r/   rN   c                  8   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   Sr\" S\S9r\" S\S9r	\
" S\SS S9rS\S'   \
" S\SS S9rS\S'   \
" S\SS S9rS \S!'   \
" S"\S#S S9rS$\S%'   CSHS& jrSHS' jr\SIS( j5       r\R&                  SJS) j5       rSKS* jr\SIS+ j5       r\R&                  SJS, j5       rSLS- jrSLS. jr\SIS/ j5       r\R&                  SJS0 j5       r\SIS1 j5       r\R&                  SJS2 j5       rSMS3 jr\SIS4 j5       r\R&                  SJS5 j5       r\SNS6 j5       r\R&                  SOS7 j5       r\SIS8 j5       r\R&                  SPS9 j5       r\SIS: j5       r\R&                  SPS; j5       r\SQS< j5       rSRS= jr SSS> jr!\SIS? j5       r"\"R&                  SPS@ j5       r"\STSA j5       r#\#R&                  SUSB j5       r#\SVSC j5       r$\$R&                  SWSD j5       r$\SISE j5       r%\%R&                  SPSF j5       r%SGr&g)X	CT_SectPrd   zA`w:sectPr` element, the container element for section properties.zCallable[[], CT_PageMar]get_or_add_pgMarzCallable[[], CT_PageSz]get_or_add_pgSzzCallable[[], CT_OnOff]get_or_add_titlePgzCallable[[], CT_SectType]get_or_add_typezCallable[[], CT_HdrFtrRef]_add_footerReference_add_headerReferencezCallable[[], None]_remove_titlePg_remove_type)zw:footnotePrzw:endnotePrr>   w:pgSzw:pgMarz
w:paperSrczw:pgBorderszw:lnNumTypezw:pgNumTypezw:colsz
w:formProtzw:vAlignzw:noEndnote	w:titlePgzw:textDirectionzw:bidizw:rtlGutterz	w:docGridzw:printerSettingszw:sectPrChangezw:headerReferencer&   zw:footerReferencer>      NzCT_SectType | Nonetyper`      zCT_PageSz | NonepgSzra      zCT_PageMar | NonepgMarrb      zCT_OnOff | NonetitlePgc                >    U R                  5       nXl        X#l        U$ )zhReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

The element tag is `w:footerReference`.
)r\   r?   rA   )r+   r?   rA   footerReferences       r,   add_footerReferenceCT_SectPr.add_footerReference   $    
 335 %!r/   c                >    U R                  5       nXl        X#l        U$ )zhReturn newly added CT_HdrFtrRef element of `type_` with `rId`.

The element tag is `w:headerReference`.
)r]   r?   rA   )r+   r?   rA   headerReferences       r,   add_headerReferenceCT_SectPr.add_headerReference   ro   r/   c                :    U R                   nUc  gUR                  $ )zValue of the `w:bottom` attr of `<w:pgMar>` child element, as |Length|.

|None| when either the element or the attribute is not present.
N)rh   rH   r+   rh   s     r,   bottom_marginCT_SectPr.bottom_margin   s     

=||r/   c                    U R                  5       nUb  [        U[        5      (       a  Xl        g [        U5      Ul        g N)rX   
isinstancer   rH   r+   valuerh   s      r,   rv   rw      2    %%' %E61J1JuPVW\P]r/   c                P    [        U 5      nUR                  R                  5         U$ )zReturn an exact duplicate of this ``<w:sectPr>`` element tree suitable for
use in adding a section break.

All rsid* attributes are removed from the root ``<w:sectPr>`` element.
)r   attribclear)r+   cloned_sectPrs     r,   cloneCT_SectPr.clone   s%     !""$r/   c                :    U R                   nUc  gUR                  $ )zDistance from bottom edge of page to bottom edge of the footer.

This is the value of the `w:footer` attribute in the `w:pgMar` child element,
as a |Length| object, or |None| if either the element or the attribute is not
present.
N)rh   rK   ru   s     r,   rK   CT_SectPr.footer   s     

=||r/   c                    U R                  5       nUb  [        U[        5      (       a  Xl        g [        U5      Ul        g ry   )rX   rz   r   rK   r{   s      r,   rK   r      r}   r/   c                p    S[         R                  " U5      -  nU R                  U5      nU(       d  gUS   $ )zAReturn footerReference element of `type_` or None if not present.z!./w:footerReference[@w:type='%s']Nr   )r   to_xmlr)   )r+   r?   pathfooterReferencess       r,   get_footerReferenceCT_SectPr.get_footerReference   s8    25E5L5LU5SS::d+""r/   c                |    U R                  S[        R                  " U5      -  5      n[        U5      S:X  a  gUS   $ )zAReturn headerReference element of `type_` or None if not present.z!./w:headerReference[@w:type='%s']r   N)r)   r   r   len)r+   r?   matching_headerReferencess      r,   get_headerReferenceCT_SectPr.get_headerReference   sC    $(JJ/2B2I2I%2PP%
! ()Q.(++r/   c                :    U R                   nUc  gUR                  $ )zThe value of the ``w:gutter`` attribute in the ``<w:pgMar>`` child element,
as a |Length| object, or |None| if either the element or the attribute is not
present.N)rh   rL   ru   s     r,   rL   CT_SectPr.gutter   s    
 

=||r/   c                    U R                  5       nUb  [        U[        5      (       a  Xl        g [        U5      Ul        g ry   )rX   rz   r   rL   r{   s      r,   rL   r      r}   r/   c                :    U R                   nUc  gUR                  $ )zDistance from top edge of page to top edge of header.

This value comes from the `w:header` attribute on the `w:pgMar` child element.
|None| if either the element or the attribute is not present.
N)rh   rJ   ru   s     r,   rJ   CT_SectPr.header   s     

=||r/   c                    U R                  5       nUb  [        U[        5      (       a  Xl        g [        U5      Ul        g ry   )rX   rz   r   rJ   r{   s      r,   rJ   r     r}   r/   c                ,    [         R                  U 5      $ )zGenerate all `w:p` and `w:tbl` elements in this section.

Elements appear in document order. Elements shaded by nesting in a `w:ins` or
other "wrapper" element will not be included.
)_SectBlockElementIteratoriter_sect_block_elementsr*   s    r,   iter_inner_contentCT_SectPr.iter_inner_content  s     )AA$GGr/   c                :    U R                   nUc  gUR                  $ )zThe value of the ``w:left`` attribute in the ``<w:pgMar>`` child element, as
a |Length| object, or |None| if either the element or the attribute is not
present.N)rh   rI   ru   s     r,   left_marginCT_SectPr.left_margin  s    
 

=zzr/   c                    U R                  5       nUb  [        U[        5      (       a  Xl        g [        U5      Ul        g ry   )rX   rz   r   rI   r{   s      r,   r   r     s0    %%'#mz%/H/HU
fUZm
r/   c                X    U R                   nUc  [        R                  $ UR                  $ )z`WD_ORIENTATION` member indicating page-orientation for this section.

This is the value of the `orient` attribute on the `w:pgSz` child, or
`WD_ORIENTATION.PORTRAIT` if not present.
)rf   r   rT   rS   r+   rf   s     r,   orientationCT_SectPr.orientation  s(     yy<!***{{r/   c                j    U R                  5       nU(       a  Xl        g [        R                  Ul        g ry   )rY   r   rT   rS   r+   r|   rf   s      r,   r   r   *  s#    ##%$e.*A*Ar/   c                :    U R                   nUc  gUR                  $ )zYValue in EMU of the `h` attribute of the `w:pgSz` child element.

|None| if not present.
N)rf   rQ   r   s     r,   page_heightCT_SectPr.page_height/       yy<vvr/   c                0    U R                  5       nXl        g ry   )rY   rQ   r   s      r,   r   r   :      ##%r/   c                :    U R                   nUc  gUR                  $ )z_Value in EMU of the ``w`` attribute of the ``<w:pgSz>`` child element.

|None| if not present.
N)rf   rP   r   s     r,   
page_widthCT_SectPr.page_width?  r   r/   c                0    U R                  5       nXl        g ry   )rY   rP   r   s      r,   r   r   J  r   r/   c                P    U R                  S5      n[        U5      S:  a  US   $ S$ )zCSectPr immediately preceding this one or None if this is the first.z./preceding::w:sectPr[1]r   N)r)   r   )r+   preceding_sectPrss     r,   preceding_sectPrCT_SectPr.preceding_sectPrO  s2     !JJ'AB'*+<'='A #KtKr/   c                ~    U R                  U5      nUc  [        S5      eUR                  nU R                  U5        U$ )zCReturn rId of w:footerReference child of `type_` after removing it.z!CT_SectPr has no footer reference)r   
ValueErrorrA   remove)r+   r?   rl   rA   s       r,   remove_footerReference CT_SectPr.remove_footerReferenceV  @    2259"@AA!!O$
r/   c                ~    U R                  U5      nUc  [        S5      eUR                  nU R                  U5        U$ )zCReturn rId of w:headerReference child of `type_` after removing it.z!CT_SectPr has no header reference)r   r   rA   r   )r+   r?   rq   rA   s       r,   remove_headerReference CT_SectPr.remove_headerReference`  r   r/   c                :    U R                   nUc  gUR                  $ )zThe value of the ``w:right`` attribute in the ``<w:pgMar>`` child element, as
a |Length| object, or |None| if either the element or the attribute is not
present.N)rh   rG   ru   s     r,   right_marginCT_SectPr.right_marginj  s    
 

={{r/   c                0    U R                  5       nXl        g ry   )rX   rG   r{   s      r,   r   r   t  s    %%'r/   c                r    U R                   nUb  UR                  c  [        R                  $ UR                  $ )zThe member of the ``WD_SECTION_START`` enumeration corresponding to the value
of the ``val`` attribute of the ``<w:type>`` child element, or
``WD_SECTION_START.NEW_PAGE`` if not present.)rd   valr   NEW_PAGE)r+   rd   s     r,   
start_typeCT_SectPr.start_typey  s0    
 yy<488+#,,,xxr/   c                ~    Ub  U[         R                  L a  U R                  5         g U R                  5       nXl        g ry   )r   r   r_   r[   r   )r+   r|   rd   s      r,   r   r     s7    =E%5%>%>>##%r/   c                :    U R                   nUc  gUR                  $ )zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.F)rj   r   )r+   rj   s     r,   titlePg_valCT_SectPr.titlePg_val  s     ,,?{{r/   c                \    US;   a  U R                  5         g SU R                  5       l        g )N)NFT)r^   rZ   r   )r+   r|   s     r,   r   r     s'    M!  ",0D##%)r/   c                :    U R                   nUc  gUR                  $ )zThe value of the ``w:top`` attribute in the ``<w:pgMar>`` child element, as a
|Length| object, or |None| if either the element or the attribute is not
present.N)rh   rF   ru   s     r,   
top_marginCT_SectPr.top_margin  s    
 

=yyr/   c                0    U R                  5       nXl        g ry   )rX   rF   r{   s      r,   r   r     s    %%'	r/   r%   )r?   r   rA   r@   r0   r<   )r0   rE   )r|   zint | Length | None)r0   rV   )r?   r   r0   zCT_HdrFtrRef | None)r0   zIterator[CT_P | CT_Tbl])r0   r   )r|   zWD_ORIENTATION | None)r|   rE   )r0   zCT_SectPr | None)r?   r   r0   r@   )r?   r   )r0   r   )r|   WD_SECTION_START | None)r0   bool)r|   zbool | None)'r1   r2   r3   r4   r5   r6   _tag_seqr   rq   rl   r   rd   rf   rh   rj   rm   rr   r9   rv   setterr   rK   r   r   rL   rJ   r   r   r   r   r   r   r   r   r   r   r   r   r:   r%   r/   r,   rV   rV   d   sC   K..,,....4444''$$H, !!4JO !4JO(Xab\ D
  'Xab\D
   )hqrl E   ) G_  	   ^ ^ 
 
 ]]^ ^#,   ]]^ ^ 	 	 ]]^ ^H   \ \ 	 	 B B         L L           1 1    r/   rV   c                  6    \ rS rSr% Sr\" S\5      rS\S'   Sr	g)CT_SectTypei  z:``<w:sectType>`` element, defining the section start type.zw:valr   r   r%   N)
r1   r2   r3   r4   r5   r   r   r   r6   r:   r%   r/   r,   r   r     s    D#4!$C	  r/   r   c                      \ rS rSr% SrSrS\S'   SrS\S'   SS jr\	SS j5       r
SS	 jrSS
 jr\SS j5       rSS jr\SS j5       rSrg)r   i  zyGenerates the block-item XML elements in a section.

A block-item element is a `CT_P` (paragraph) or a `CT_Tbl` (table).
Nzetree.XPath | None_compiled_blocks_xpath_compiled_count_xpathc                    Xl         g ry   )_sectPr)r+   sectPrs     r,   __init__"_SectBlockElementIterator.__init__  s    r/   c                .    U " U5      R                  5       $ )zIGenerate each CT_P or CT_Tbl element within extents governed by `sectPr`.)_iter_sect_block_elements)clsr   s     r,   r   2_SectBlockElementIterator.iter_sect_block_elements  s     6{4466r/   c              #     #    U R                   U R                  p!UR                  U5      nUS:X  a  SOU R                  X#S-
     5      nU R	                  U5      US  H  nUv   M	     g7f)z0Generate each CT_P or CT_Tbl element in section.r      N)r   _sectPrsindex%_count_of_blocks_in_and_above_section_blocks_in_and_above_section)r+   r   sectPrs
sectPr_idxn_blks_to_skipelements         r,   r   3_SectBlockElementIterator._iter_sect_block_elements  sq      ,,]]6*

 Q ;;GQRN<ST 	 88@QGM Rs   A'A)c                    U R                   c)  [        R                  " U R                  [        SS9U l         U R                   n[        [        [           U" U5      5      $ )FAll ps and tbls in section defined by `sectPr` and all prior sections.F
namespacesregexp)r   r
   XPath"_blocks_in_and_above_section_xpathr   r	   r   r   r+   r   r)   s      r,   r   6_SectBlockElementIterator._blocks_in_and_above_section  sQ    &&.*/++77 +D'
 ++H\*E&M::r/   c           	     .    SnSnSnU SU SU SU SU 3	$ )zHXPath expr for ps and tbls in context of a sectPr and all prior sectPrs.z./parent::w:pPr/parent::w:pzself::w:sectPr[parent::w:body]z-preceding-sibling::*[self::w:p | self::w:tbl]z | /r%   )r+   p_sect_term_blockbody_sect_termpred_ps_and_tblss       r,   r   <_SectBlockElementIterator._blocks_in_and_above_section_xpath  sH     :9J !!#$A&6%7.!#3"4	6	
r/   c                    U R                   c-  [        R                  " SU R                   S3[        SS9U l         U R                   n[        [        [        U" U5      5      5      $ )r   zcount()Fr   )r   r
   r   r   r   intr	   floatr   s      r,   r   ?_SectBlockElementIterator._count_of_blocks_in_and_above_section  s[    %%-).@@AC *D&
 **4uV}-..r/   c                8    U R                   R                  S5      $ )z5All w:sectPr elements in document, in document-order.zC/w:document/w:body/w:p/w:pPr/w:sectPr | /w:document/w:body/w:sectPr)r   r)   r*   s    r,   r   "_SectBlockElementIterator._sectPrs  s     ||!!Q
 	
r/   )r   r   r   )r   rV   )r   rV   r0   Iterator[BlockElement])r0   r  )r   rV   r0   zSequence[BlockElement])r0   r@   )r   rV   r0   r   )r0   zSequence[CT_SectPr])r1   r2   r3   r4   r5   r   r6   r   r   classmethodr   r   r   r   r   r   r   r:   r%   r/   r,   r   r     sq    
 26.504-4 7 74
; 
 
6
/ 
 
r/   r   N)1r5   
__future__r   copyr   typingr   r   r   r   r	   lxmlr
   typing_extensionsr   docx.enum.sectionr   r   r   docx.oxml.nsr   docx.oxml.sharedr   docx.oxml.simpletypesr   r   r   docx.oxml.tabler   docx.oxml.text.paragraphr   docx.oxml.xmlchemyr   r   r   r   r   docx.sharedr   r   r   r6   r   r<   rC   rN   rV   r   r   r%   r/   r,   <module>r     s    - "  ; ;  ' P P  % S S " )  -)i )- -,4? 4 4 C CL
/ d
 d
r/   