ó
    �®žjk¸  ã                   ó”  • 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	J
r
Jr  SSKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJrJrJ r J!r!  SSK"J#r#  \RH                  " \%5      r&\" S	5      r' " S
 S\5      r(Sr) Sr* Sr+ Sr, Sr- Sr. SSSSS.r/ Sr0 Sr1 Sr2 Sr3 Sr4 Sr5 Sr6 Sr7 Sr8 Sr9 Sr: S r; S!r< S"r= S r> S#r? S$r@ SrA S%rB S&rC S'rD SrE S(rF SrGSrHSrI S)rJ SrK S*rL S rM S+rN S,rO S-rP S.rQ S/rR SrSS rT S0rU SrV SrWSrXSrY S1rZS2r[ S3r\ Sr]S4r^S%r_Sr` SraSrbS,rc SrdSre SrfSrgS%rh S5ri S6rjSrkSrlSrmSrnS4roSrp SrqS6rr SrsS%rt S+ru SrvS7rw SrxS+ryS8S9S:\xS4\yS44rz S6r{ S;r| S r} Sr~ S<r Sr€ S4r� Sr‚S+rƒ S=\GR                  S>\…\GR                     S?\‡S@\ˆSA\4
SB jr‰SC\ŠSA\ˆS-  4SD jr‹SE\Œ\‡\…\‡\Š-     4   SA\ˆ4SF jr�SE\Œ\‡\…\‡\Š-     4   SG\Œ\‡\4   SA\4SH jrŽSE\Œ\‡\…\‡\Š-     4   SI\‡SG\Œ\‡\4   SJ\‡SK\\Š/\'S-  4   SA\…\�\‡\'S-  4      4SL jr�SE\Œ\‡\…\‡\Š-     4   SA\…\�\‡\‡4      4SM jr‘SC\ŠSA\ˆS-  4SN jr’SC\ŠSA\4SO jr“SC\ŠSA\	S-  4SP jr”SQ\SG\Œ\‡\4   SA\S-  4SR jr•SS\Œ\‡\…\‡\Š-     4   SG\Œ\‡\4   SA\(4ST jr–SS\Œ\‡\…\‡\Š-     4   SI\‡SG\Œ\‡\4   SK\\Œ\‡\…\‡\Š-     4   \Œ\‡\4   /\ˆS-  4   SA\Œ\‡\ˆ4   4
SU jr—SV\Œ\‡\…\‡\Š-     4   SG\Œ\‡\4   SA\ˆS-  4SW jr˜SV\Œ\‡\…\‡\Š-     4   SG\Œ\‡\4   SA\ˆS-  4SX jr™SS\Œ\‡\…\‡\Š-     4   SG\Œ\‡\4   SA\…\   4SY jršSZ\S[\(S\\‡S]\‡SA\…\
   4
S^ jr›S_\ŠS`\‡S[\(SA\ˆS-  4Sa jrœSb\ŠSc\‡SA\‡4Sd jr�SC\ŠSA\Œ\‡\…\‡\Š-     4   4Se jrž " Sf Sg5      rŸSC\ŠSI\‡SA\‡S-  4Sh jr SC\ŠSI\‡SA\…\‡   4Si jr¡\B4SE\Œ\‡\…\‡\Š-     4   SI\‡SA\…\�\‡\‡4      4Sj jjr¢SG\Œ\‡\4   SA\Œ\‡\ˆ4   4Sk jr£SnSC\ŠSl\‡SA\¤\‡   4Sm jjr¥g)oa7  Reader for the object graph of a Pages 5+ (2013 onwards) document.

The container is a set of ``Index/*.iwa`` archives whose schemas Apple has never
published, so what is read here is the object graph itself: a document archive
referencing a body text storage, run tables keyed by character index for
everything applied to that text, and drawables reached either from the
attachments anchored in the text or from the document's own list of them.

Only the message and field numbers are format knowledge; the container layer
lives in :mod:`docling.backend.iwork.iwa`.
é    N)ÚCallable)Ú
NamedTupleÚTypeVar)Ú
FormattingÚ	TableCellÚ	TableData)ÚSCRIPTSÚBlockÚCommentÚContentÚ	ListStyleÚ	ParagraphÚPictureÚStorageRunsÚauthoredÚbuild_formattingÚlabel_for_styleÚlist_label_atÚruns_forÚsplit_paragraphsÚunique_paragraphsÚvalue_at)Ú	IWAObjectÚiter_objectsÚread_fieldsÚread_reference)ÚDocumentLoadErrorÚ_Tc                   óJ   • \ rS rSr% Sr0 r\\\4   \	S'   0 r
\\\4   \	S'   Srg)Ú
CellValuesé:   z³A table's shared value lists, keyed as its cells reference them.

Cells reference their contents by key rather than holding them, so two cells
with the same text share one entry.
ÚstringsÚ	rich_text© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   ÚdictÚintÚstrÚ__annotations__r#   Ú__static_attributes__r$   ó    Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/docling/backend/iwork/pages_iwa.pyr    r    :   s-   ‡ ñð !€GˆT�#�s�(‰^Ó Ø "€Iˆt�C˜�H‰~Ö"r/   r    é   é   iå  é   é   é
   ÚboldÚitalicÚ	underlineÚstrikethrough)é   é   r4   é   iÛ  é   i'  iÑ  iæ  é   r:   iq  ip  r;   i½  iÀ  )é   é   r4   r<   iÓ  é	   é   iÝ  ið  éÔ   iØ  é   é   i'  )rB   é   é   iŸ'  iþ*  zData/ir  iu  é   iJ  é   r<   )r:   rD   )r;   r3   )r1   r3   ið  iç  ÚarchiveÚinfosÚmax_file_bytesÚdocument_hashÚreturnc           
      óœ  • 0 nU H�  nUR                   R                  S5      (       d  M%  UR                  U:”  a)  [        SUR                    SUR                   SU S35      e[	        U R                  U5      5       H  nXdUR                  '   M     M�     [        S UR                  5        5       S5      nUc  [        SU S	35      e[        UR                  5      R                  [        S/5      S
   n[        U[        5      (       a  [        U5      OSn	U	b  UR                  U	5      OSn
U
b  U
R                   ["        :w  a  [        SU S35      e[%        X5      nUR'                  U
5      nUR)                  UR+                  U5      5        UR-                  U
5      u  pÞ[/        UUUUR1                  U
5      UR3                  U
5      S9$ )aÆ  Read the content of a Pages 5+ document out of its IWA object graph.

Args:
    archive: The open ``.pages`` container.
    infos: Its members.
    max_file_bytes: The largest member this is willing to decompress.
    document_hash: The document's hash, for error messages.

Returns:
    Everything the document holds.

Raises:
    DocumentLoadError: If a member is too large, or the object graph has no
        document archive or no body text storage.
z.iwazPages archive member z is z. bytes, exceeding the max_file_bytes limit of Ú.c              3   óP   #   • U  H  oR                   [        :X  d  M  Uv •  M     g 7f©N)Úmessage_typeÚTP_DOCUMENT_ARCHIVE©Ú.0Úos     r0   Ú	<genexpr>Úread_content.<locals>.<genexpr>Ï  s   é € ÐNÒ$ˆq¯©Ô:MÑ(M�‰Ò$ùó   ‚&�	&NzPages document with hash zO has no TP.DocumentArchive; the container may be corrupt or password-protected.r   z( does not reference a body text storage.)ÚblocksÚheadersÚfootersÚ	footnotesÚcomments)ÚfilenameÚendswithÚ	file_sizer   r   ÚreadÚ
identifierÚnextÚvaluesr   ÚpayloadÚgetÚDOCUMENT_BODY_FIELDÚ
isinstanceÚbytesr   rS   ÚTSWP_STORAGE_ARCHIVEÚ	IWAReaderÚstorage_blocksÚextendÚfloating_blocksÚpage_furniturer   r^   r_   )rJ   rK   rL   rM   ÚobjectsÚinfoÚobjÚdocumentÚbody_refÚtargetÚstorageÚreaderr[   r\   r]   s                  r0   Úread_contentrz   ¬  sÓ  € ð* %'€GÛˆØ�}‰}×%Ñ% f×-Ñ-ÙØ�>‰>˜NÓ*Ü#Ø'¨¯© °d¸4¿>¹>Ð:Jð K@à!Ð" !ð%óð ô
   §¡¨TÓ 2Ö3ˆCØ&)�C—N‘NÓ#ó 4ñ ô ÙN�G—N‘NÔ$ÓNØó€Hð ÑÜØ'¨ ð 7"ð "ó
ð 	
ô ˜8×+Ñ+Ó,×0Ñ0Ô1DÀtÀfÓMÈaÑP€HÜ)3°H¼e×)DÑ)DŒ^˜HÔ%È$€FØ%+Ñ%7ˆg�k‰k˜&Ô!¸T€GØ�˜'×.Ñ.Ô2FÓFÜØ'¨ ð 7#ð #ó
ð 	
ô
 �wÓ(€FØ×"Ñ" 7Ó+€FØ
‡M�M�&×(Ñ(¨Ó2Ô3Ø×,Ñ,¨WÓ5Ñ€GÜØØØØ×"Ñ" 7Ó+Ø—‘ Ó)ñð r/   rg   c                 ó*  • [        U 5      R                  [        S/5      S   n[        U[        5      (       d  g[        U5      R                  [
        S/5      S   n[        U[        5      (       d  g UR                  S5      $ ! [         a     gf = f)u«  Read a paragraph style's name out of its ``TSS`` super message.

``TSWP.ParagraphStyleArchive`` wraps a ``TSS.StyleArchive`` that carries the
human-facing name ("Body", "Heading 1"). Anonymous styles â€” the ones Pages
creates for ad-hoc formatting â€” have no name and are treated as body text.

Args:
    payload: The encoded ``TSWP.ParagraphStyleArchive``.

Returns:
    The style name, or None when the style is anonymous.
Nr   úutf-8)r   rh   ÚSTYLE_SUPER_FIELDrj   rk   ÚSTYLE_NAME_FIELDÚdecodeÚUnicodeDecodeError)rg   Úsuper_messageÚnames      r0   Úiwa_style_namerƒ   ï  sˆ   € ô   Ó(×,Ñ,Ô->ÀÀÓGÈÑJ€MÜ�m¤U×+Ñ+ØÜ�}Ó%×)Ñ)Ô*:¸T¸FÓCÀAÑF€DÜ�dœE×"Ñ"ØðØ�{‰{˜7Ó#Ð#øÜó Ùðús   Á4B Â
BÂBÚfieldsc                 óZ   • SR                  S U R                  [        / 5       5       5      $ )z2Join the text pieces of a ``TSWP.StorageArchive``.Ú c              3   óp   #   • U  H,  n[        U[        5      (       d  M  UR                  S SS9v •  M.     g7f©r|   Úreplace©ÚerrorsN©rj   rk   r   ©rV   Úvalues     r0   rX   Ú#iwa_storage_text.<locals>.<genexpr>
  s0   é € ð â7ˆEÜ�eœU×#ó 	0ˆ�‰�W YˆÕ/Ú7ùó   ‚6Ÿ6)Újoinrh   ÚSTORAGE_TEXT_FIELD)r„   s    r0   Úiwa_storage_textr“     s,   € à�7‰7ñ à—Z‘ZÔ 2°BÔ7óó ð r/   rr   c                 óö   • [        [        U [        U[        [        5      [        U [
        U[        [        5      [        U [        U[        [        5      [        U 5      [        U [        U[        [        5      S9$ )zçResolve every run table a ``TSWP.StorageArchive`` carries.

Args:
    fields: Decoded fields of the storage.
    objects: Every object in the document, keyed by identifier.

Returns:
    The tables, each sorted by character index.
)ÚstylesÚ
charactersÚlistsÚdepthsÚlinks)r   Úiwa_object_runsÚSTORAGE_PARAGRAPH_STYLE_FIELDÚTSWP_PARAGRAPH_STYLErƒ   ÚSTORAGE_CHARACTER_STYLE_FIELDÚTSWP_CHARACTER_STYLEÚiwa_formattingÚSTORAGE_LIST_STYLE_FIELDÚTSWP_LIST_STYLEÚiwa_list_styleÚiwa_depth_runsÚSTORAGE_SMART_FIELDÚTSWP_LINK_FIELDÚiwa_link)r„   rr   s     r0   Úiwa_storage_runsr§     sx   € ô ÜØÜ)ØÜ Üó
ô #ØÜ)ØÜ Üó
ô ØÜ$ØÜÜó
ô ˜fÓ%ÜØÔ'¨´/Ä8ó
ñ/ð r/   ÚfieldrS   r   c                 ó‚  • U R                  U/ 5      nU(       a  [        US   [        5      (       d  / $ / n[        US   5      R                  S/ 5       H×  n[        U[        5      (       d  M  [        U5      nUR                  SS/5      S   n	[        U	[        5      (       d  MR  UR                  SS/5      S   n
Sn[        U
[        5      (       aF  [        U
5      nUb  UR                  U5      OSnUb"  UR                  U:X  a  U" UR                  5      nUR                  X›45        MÙ     UR                  S S9  U$ )a¼  Resolve one ``TSWP.ObjectAttributeTable`` to (character index, value) pairs.

Every run table of a storage has this shape: entries pairing a character
index with a reference to the object that applies from there. An entry
without a reference clears the value from that character on, which is how
Pages ends a bold phrase or leaves a list.

Args:
    fields: Decoded fields of the storage.
    field: The storage field holding the table.
    objects: Every object in the document, keyed by identifier.
    message_type: The message type the referenced objects must have.
    decode: Reads one referenced object's payload into a value.

Returns:
    Character index and value pairs, in document order.
r   r:   Nr;   c                 ó   • U S   $ ©Nr   r$   ©Úruns    r0   Ú<lambda>Ú!iwa_object_runs.<locals>.<lambda>h  ó   € ˜c !šfr/   ©Úkey)
rh   rj   rk   Úsafe_fieldsr+   r   rS   rg   ÚappendÚsort)r„   r¨   rr   rS   r   ÚtableÚrunsÚentryÚparsedÚindexÚ	referencerŽ   rw   Ú
referenceds                 r0   rš   rš   :  s!  € ð0 �J‰J�u˜bÓ!€EÞœ
 5¨¡8¬U×3Ñ3Øˆ	à(*€DÜ˜U 1™XÓ&×*Ñ*¨1¨bÖ1ˆÜ˜%¤×'Ñ'ÙÜ˜UÓ#ˆØ—
‘
˜1˜t˜fÓ% aÑ(ˆÜ˜%¤×%Ñ%Ùà—J‘J˜q 4 &Ó)¨!Ñ,ˆ	ØˆÜ�i¤×'Ñ'Ü# IÓ.ˆFØ06Ñ0B˜Ÿ™ VÔ,ÈˆJØÑ%¨*×*AÑ*AÀ\Ó*QÙ˜z×1Ñ1Ó2�Ø�‰�U�NÖ#ñ 2ð" 	‡I�IÑ$€IÑ%Ø€Kr/   c                 óþ  • U R                  [        / 5      nU(       a  [        US   [        5      (       d  / $ / n[	        US   5      R                  S/ 5       H‘  n[        U[        5      (       d  M  [	        U5      nUR                  SS/5      S   nUR                  SS/5      S   n[        U[
        5      (       d  Mh  [        U[
        5      (       d  M  UR                  XV45        M“     UR                  S S9  U$ )zIResolve the list depth table, whose entries hold numbers, not references.r   r:   Nr;   c                 ó   • U S   $ r«   r$   r¬   s    r0   r®   Ú iwa_depth_runs.<locals>.<lambda>|  r°   r/   r±   )rh   ÚSTORAGE_LIST_DEPTH_FIELDrj   rk   r³   r+   r´   rµ   )r„   r¶   r·   r¸   r¹   rº   Údepths          r0   r£   r£   l  sÕ   € à�J‰JÔ/°Ó4€EÞœ
 5¨¡8¬U×3Ñ3Øˆ	à"$€DÜ˜U 1™XÓ&×*Ñ*¨1¨bÖ1ˆÜ˜%¤×'Ñ'ÙÜ˜UÓ#ˆØ—
‘
˜1˜t˜fÓ% aÑ(ˆØ—
‘
˜1˜t˜fÓ% aÑ(ˆÜ�eœS×!Ó!¤j°¼×&<Ó&<Ø�K‰K˜˜Ö'ñ 2ð 	‡I�IÑ$€IÑ%Ø€Kr/   c                 óÂ   • [        U 5      R                  [        S/5      S   n[        U[        5      (       d  gUR                  SSS9R                  5       =(       d    S$ )z7Read the address a ``TSWP.LinkFieldArchive`` points at.Nr   r|   r‰   rŠ   )r³   rh   ÚLINK_URL_FIELDrj   rk   r   Ústrip)rg   Úurls     r0   r¦   r¦   €  sQ   € ä
�gÓ
×
"Ñ
"¤>°D°6Ó
:¸1Ñ
=€CÜ�cœ5×!Ñ!ØØ�:‰:�g iˆ:Ð0×6Ñ6Ó8×@¸DÐ@r/   c                 óÆ   • [        U 5      n[        S UR                  [        / 5       5       5      n[        S UR                  [        / 5       5       5      n[        X#5      $ )z?Read a ``TSWP.ListStyleArchive`` as its per-depth label ladder.c              3   óT   #   • U  H  n[        U[        5      (       d  M  Uv •  M      g 7frR   ©rj   r+   r�   s     r0   rX   Ú!iwa_list_style.<locals>.<genexpr>‹  s#   é € ð â;ˆEÜ�eœS×!÷ 	‰Ú;ùó   ‚(Ÿ	(c              3   óp   #   • U  H,  n[        U[        5      (       d  M  UR                  S SS9v •  M.     g7frˆ   rŒ   r�   s     r0   rX   rÉ   �  s0   é € ð â7ˆEÜ�eœU×#ó 	0ˆ�‰�W YˆÕ/Ú7ùr�   )r³   Útuplerh   ÚLIST_LABEL_TYPES_FIELDÚLIST_STRINGS_FIELDr   )rg   r„   Úlabel_typesr"   s       r0   r¢   r¢   ˆ  sa   € ä˜Ó!€FÜñ à—Z‘ZÔ 6¸Ô;óó €Kô
 ñ à—Z‘ZÔ 2°BÔ7óó €Gô
 �[Ó*Ð*r/   c                 óâ  • [        U 5      R                  [        S/5      S   n[        U[        5      (       d  g[        U5      n[
        R                  5        VVs1 s H0  u  p4[        S UR                  U/ 5       5       5      (       d  M.  UiM2     nnnUR                  [        S/5      S   n[        U[        U[        5      (       a  [        R                  " U5      5      $ S5      $ s  snnf )z?Read a character style's property map as a :class:`Formatting`.Nr   c              3   óT   #   • U  H  n[        U[        5      =(       a    Uv •  M      g 7frR   rÈ   r�   s     r0   rX   Ú!iwa_formatting.<locals>.<genexpr>¢  s!   é € ÐTÒ=S°EŒz˜%¤Ó%×/¨%Ô/Ò=Sùs   ‚&()r³   rh   ÚSTYLE_PROPERTIES_FIELDrj   rk   ÚCHARACTER_PROPERTY_LABELSÚitemsÚanyÚSTYLE_SCRIPT_FIELDr   r+   r	   )rg   Ú
propertiesÚdecodedr¨   ÚlabelÚactiveÚscripts          r0   rŸ   rŸ   ˜  sÕ   € ä˜WÓ%×)Ñ)Ô*@À4À&ÓIÈ!ÑL€JÜ�j¤%×(Ñ(Øä˜*Ó%€Gô 6×;Ñ;Ô=ôâ=‰LˆEÜÑT¸W¿[¹[ÈÐPRÔ=SÓT×T÷ 	Ù=ð ñ ð
 �[‰[Ô+¨d¨VÓ4°QÑ7€FÜØ¤z°&¼#×'>Ñ'>”—’˜FÓ#óð ØDHóð ùós   Á-C+ÂC+Úmodelc                 óz  • [        U R                  5      nUR                  [        S/5      S   nUR                  [        S/5      S   nUR                  [
        S/5      S   n[        U[        5      (       a  [        U[        5      (       d  gU(       a  U(       a  [        U[        5      (       d  gUR                  [        S/5      S   n[        U5      n[        Xq5      n/ n	[        Xq5       H7  n
U	R                  [        U
UU[        U[        5      (       a  UOS5      5        M9     U	(       d  g[        X4U	S9$ )u)  Build table data from one ``TST.TableModelArchive``.

A table keeps its geometry on the model, its cell contents in a shared value
list, and the placement of those values in tiles. Cells reference their value
by key, so equal values share one entry â€” which is why the tiles have to be
read rather than assuming the value list is already in cell order.

Args:
    model: The table's ``TST.TableModelArchive``.
    objects: Every object in the document, keyed by identifier.

Returns:
    The table, or None when nothing readable could be placed in it.
Nr   )Únum_rowsÚnum_colsÚtable_cells)r³   rg   rh   ÚTABLE_ROWS_FIELDÚTABLE_COLS_FIELDÚTABLE_DATA_STORE_FIELDrj   r+   rk   ÚTABLE_HEADER_ROWS_FIELDÚiwa_cell_valuesÚ	iwa_tilesro   Úiwa_tile_cellsr   )rÝ   rr   r„   rß   rà   Ú	store_rawÚheader_rowsÚstorerf   ÚcellsÚtiles              r0   Ú	iwa_tablerî   ª  s  € ô ˜Ÿ™Ó'€FØ�z‰zÔ*¨T¨FÓ3°AÑ6€HØ�z‰zÔ*¨T¨FÓ3°AÑ6€HØ—
‘
Ô1°D°6Ó:¸1Ñ=€IÜ�h¤×$Ñ$¬J°xÄ×,EÑ,EØÞž8¬:°iÄ×+GÑ+GØà—*‘*Ô4°q°cÓ:¸1Ñ=€KÜ˜	Ó"€EÜ˜UÓ,€Fà€EÜ˜%Ö)ˆØ�‰ÜØØØÜ)¨+´s×;Ñ;‘Àó	ö	
ñ *ö ØÜ˜hÀuÑMÐMr/   rë   c           	      óf   • [        [        U [        U[        5      [        U [        U[
        5      S9$ )a  Read a table's shared value lists, keyed as its cells reference them.

Args:
    store: Decoded fields of the table's data store.
    objects: Every object in the document, keyed by identifier.

Returns:
    The plain strings and the rich text, each keyed by cell reference.
)r"   r#   )r    Úiwa_value_listÚSTORE_STRINGS_FIELDÚiwa_entry_stringÚSTORE_RICH_TEXT_FIELDÚiwa_entry_rich_text)rë   rr   s     r0   ræ   ræ   Ö  s5   € ô Ü˜uÔ&9¸7ÔDTÓUÜ ØÜ!ØÜó	
ñð r/   c                 ó¼  • U R                  US/5      S   n[        U[        5      (       a  [        U5      OSnUb  UR                  U5      OSnUb  UR                  [
        :w  a  0 $ UR                  /n[        UR                  [        5       H4  nUR                  U5      n	U	c  M  UR                  U	R                  5        M6     0 n
U H�  n[        U5      R                  [        / 5       Hg  n[        U[        5      (       d  M  [        U5      nUR                  [        S/5      S   nU" XÒ5      n[        U[        5      (       d  M^  Uc  Mc  XúU'   Mi     M�     U
$ )zFRead one ``TST.TableDataList``, following any segments it spills into.Nr   )rh   rj   rk   r   rS   ÚTST_DATA_LISTrg   Úiwa_reference_listÚLIST_SEGMENTS_FIELDr´   r³   ÚLIST_ENTRIES_FIELDÚENTRY_KEY_FIELDr+   )rë   r¨   rr   r   r»   rw   Ú	data_listÚpayloadsÚsegmentÚspilledrf   rg   r¸   r¹   r²   rŽ   s                   r0   rð   rð   í  s5  € ð —	‘	˜% $ Ó(¨Ñ+€IÜ*4°YÄ×*FÑ*FŒ^˜IÔ&ÈD€FØ'-Ñ'9�—‘˜FÔ#¸t€IØÑ˜I×2Ñ2´mÓCØˆ	à×!Ñ!Ð"€HÜ% i×&7Ñ&7Ô9LÖMˆØ—+‘+˜gÓ&ˆØÓØ�O‰O˜GŸO™OÖ,ñ Nð
  €FÛˆÜ  Ó)×-Ñ-Ô.@À"ÖEˆEÜ˜e¤U×+Ñ+ÙÜ  Ó'ˆFØ—*‘*œ_¨t¨fÓ5°aÑ8ˆCÙ˜6Ó+ˆEÜ˜#œs×#Ó#¨Ó(9Ø#�s“ó Fñ ð €Mr/   r¸   c                 óz   • [        S U R                  [        / 5       5       S5      nUc  S$ UR                  SSS9$ )z7Read a value list entry that holds its string directly.c              3   óT   #   • U  H  n[        U[        5      (       d  M  Uv •  M      g 7frR   )rj   rk   )rV   Úvs     r0   rX   Ú#iwa_entry_string.<locals>.<genexpr>  s   é € ÐNÒ5ˆq¼ÀAÄu×9M�‰Ò5ùrÊ   Nr|   r‰   rŠ   )re   rh   ÚENTRY_STRING_FIELDr   )r¸   rr   rŽ   s      r0   rò   rò     sC   € ô ÙN�E—I‘IÔ0°"Ô5ÓNÐPTó€Eð ‘=ˆ4ÐM e§l¡l°7À9 lÐ&MÐMr/   c                 óÈ  • U R                  [        S/5      S   n[        U[        5      (       a  [	        U5      OSnUb  UR                  U5      OSnUb  UR
                  [        :w  a  g[        UR                  S5      nUb  UR                  U5      OSnUb  UR
                  [        :w  a  g[        [        UR                  5      5      R                  5       =(       d    S$ )z<Read a value list entry that points at a whole text storage.Nr   r:   )rh   ÚENTRY_RICH_TEXT_FIELDrj   rk   r   rS   ÚTST_TEXT_REFÚiwa_reference_fieldrg   rl   r“   r³   rÄ   )r¸   rr   r»   rw   ÚindirectionÚ
storage_idrx   s          r0   rô   rô     s¾   € ð —	‘	Ô/°$°Ó8¸Ñ;€IÜ*4°YÄ×*FÑ*FŒ^˜IÔ&ÈD€FØ)/Ñ);�'—+‘+˜fÔ%À€KØÑ˜k×6Ñ6¼,ÓFØä$ [×%8Ñ%8¸!Ó<€JØ)3Ñ)?ˆg�k‰k˜*Ô%ÀT€GØ�˜'×.Ñ.Ô2FÓFØÜœK¨¯©Ó8Ó9×?Ñ?ÓA×IÀTÐIr/   c                 óä  • / nU R                  [        S/5      S   n[        U[        5      (       d  U$ [	        U5      R                  S/ 5       H�  n[        U[        5      (       d  M  [	        U5      R                  SS/5      S   n[        U[        5      (       a  [        U5      OSnUb  UR                  U5      OSnUc  Mv  UR                  [        :X  d  MŒ  UR                  U5        MŸ     U$ )z1Resolve the tiles a table's data store points at.Nr   r:   r;   )	rh   ÚSTORE_TILES_FIELDrj   rk   r³   r   rS   ÚTST_TILEr´   )rë   rr   ÚtilesÚ	containerr¸   r»   rw   rí   s           r0   rç   rç   (  sÑ   € ð  €EØ—	‘	Ô+¨d¨VÓ4°QÑ7€IÜ�i¤×'Ñ'Øˆä˜YÓ'×+Ñ+¨A¨rÖ2ˆÜ˜%¤×'Ñ'ÙÜ Ó&×*Ñ*¨1¨t¨fÓ5°aÑ8ˆ	Ü.8¸ÄE×.JÑ.J” 	Ô*ÐPTˆØ&,Ñ&8ˆw�{‰{˜6Ô"¸dˆØÓ × 1Ñ 1´XÕ =Ø�L‰L˜Öñ 3ð €Lr/   rí   rf   rà   rê   c                 óà  • / n[        U R                  5      R                  [        / 5       GH½  n[	        U[
        5      (       d  M  [        U5      nUR                  [        S/5      S   nUR                  [        S/5      S   nUR                  [        S/5      S   n	UR                  [        S/5      S   (       a  SOSn
[	        U[
        5      (       a  [	        U	[
        5      (       d6  UR                  [        S/5      S   nUR                  [        S/5      S   n	Sn
[	        U[        5      (       d  GM  [	        U[
        5      (       a  [	        U	[
        5      (       d  GM<  [        [        U[        U	5      S-  5      5       H\  n[        R!                  X›S-  US-  S-    SSS9n[#        XŒU
-  U5      nUc  M7  UR%                  ['        UUUS-   UUS-   Xs:  S	95        M^     GMÀ     U$ )
zERead one tile's cells, placing them by each row's per-column offsets.Nr   r1   r:   r;   ÚlittleT)Úsigned)ÚtextÚstart_row_offset_idxÚend_row_offset_idxÚstart_col_offset_idxÚend_col_offset_idxÚcolumn_header)r³   rg   rh   ÚTILE_ROWS_FIELDrj   rk   ÚROW_INDEX_FIELDÚROW_WIDE_STORAGE_FIELDÚROW_WIDE_OFFSETS_FIELDÚROW_WIDE_OFFSETS_FLAGÚROW_STORAGE_FIELDÚROW_OFFSETS_FIELDr+   ÚrangeÚminÚlenÚ
from_bytesÚiwa_cell_textr´   r   )rí   rf   rà   rê   rì   Úrow_messageÚrowÚ	row_indexrx   ÚoffsetsÚscaleÚcolumnÚstartr  s                 r0   rè   rè   <  s¾  € ð  €Eä" 4§<¡<Ó0×4Ñ4´_Àb×IˆÜ˜+¤u×-Ñ-ÙÜ˜+Ó&ˆØ—G‘GœO¨d¨VÓ4°QÑ7ˆ	Ø—'‘'Ô0°4°&Ó9¸!Ñ<ˆØ—'‘'Ô0°4°&Ó9¸!Ñ<ˆØ—W‘WÔ2°Q°CÓ8¸×;‘ÀˆÜ˜'¤5×)Ñ)´¸GÄU×1KÑ1KØ—g‘gÔ/°$°Ó8¸Ñ;ˆGØ—g‘gÔ/°$°Ó8¸Ñ;ˆGØˆEÜ˜)¤S×)Ñ)ÚÜ˜'¤5×)Ñ)´¸GÄU×1KÑ1KÚäœC ¬#¨g«,¸!Ñ*;Ó<Ö=ˆFÜ—N‘NØ ™
 V¨a¡Z°!¡^Ð4°hÀtð #ð ˆEô ! °%©-¸Ó@ˆDØ‰|ÙØ�L‰LÜØØ)2Ø'0°1¡}Ø)/Ø'-°¡zØ"+Ñ"9ñö	ô >ñ# JðF €Lr/   rx   r*  c                 ó”  • US:  d  U[         -   [        U 5      :”  a  gX   nU[        :X  aP  XS-      [        :w  a  gU[        -   nUS-   [        U 5      :”  a  gUR
                  R                  [        X5      5      $ U[        :w  a  gXS-      [        [        4;  a  g[        X[        -   5      nU[         -   n[         H‡  u  pxXW-  (       d  M  Xh-   [        U 5      :”  a    gU[        :X  a&  UR
                  R                  [        X5      5      s  $ U[        :X  a&  UR                  R                  [        X5      5      s  $ Xh-  nM‰     g)uê  Read one packed cell, or None when there is nothing readable there.

Only the layouts that carry text are decoded. Any other value type â€” a
number, a date, a formula result â€” is skipped rather than guessed at from
bytes whose meaning has not been established against a real document.

Args:
    storage: The row's packed cell buffer.
    start: Where in the buffer this cell begins.
    values: The table's shared value lists.

Returns:
    The cell's text, or None when it holds none.
r   Nr:   r1   )ÚCELL_VALUES_OFFSETr!  ÚCELL_VERSION_LEGACYÚCELL_TYPE_TEXTÚCELL_KEY_OFFSETr"   rh   Úread_uint32ÚCELL_VERSION_CURRENTÚCELL_TYPE_RICH_TEXTÚCELL_FLAGS_OFFSETÚCELL_VALUE_WIDTHSÚCELL_FLAG_STRINGÚCELL_FLAG_RICH_TEXTr#   )	rx   r*  rf   ÚversionÚkey_atÚflagsÚoffsetÚflagÚwidths	            r0   r#  r#  h  s0  € ð ˆqƒy�EÔ.Ñ.´°W³Ó=Øà‰n€GØÔ%Ó%Ø˜1‘9Ñ¤Ó/ØØœÑ(ˆØ�A‰:œ˜G›Ó$ØØ�~‰~×!Ñ!¤+¨gÓ">Ó?Ð?àÔ&Ó&ØØ�q‰yÑ¤.Ô2EÐ!FÓFØä˜Ô):Ñ!:Ó;€EØÔ'Ñ'€Fß(‰ˆØ�|ÙØ‰>œC ›LÓ(ÙØÔ#Ó#Ø—>‘>×%Ñ%¤k°'Ó&BÓCÒCØÔ&Ó&Ø×#Ñ#×'Ñ'¬°GÓ(DÓEÒEØ‰Šñ )ð r/   ÚbufferÚatc                 ó8   • [         R                  XUS-    S5      $ )z>Read a little-endian 32-bit value out of a packed cell buffer.r1   r  )r+   r"  )r=  r>  s     r0   r0  r0  —  s   € ä�>‰>˜& b¨1¡fÐ-¨xÓ8Ð8r/   c                 ó>   •  [        U 5      $ ! [         a    0 s $ f = f)a  Decode a message, treating an unreadable one as empty.

The table archives carry sub-messages this reader has no need to understand,
some of which use wire types the fields it does want never use. Failing the
whole document over one of them would be wrong.
)r   r   )rg   s    r0   r³   r³   œ  s&   € ðÜ˜7Ó#Ð#øÜó ØŠ	ðús   ‚
 �›c                   óR  • \ rS rSrSrS\R                  S\\\	4   SS4S jr
S\	S\\   4S	 jrS
\	S\\   4S jrS\	S\\   4S jrS\	S\\\   \\   4   4S jrS\	S\\   4S jrS\S-  S\\   4S jrS\S\S-  4S jrS\S-  S\\   4S jrS\S\\   4S jrS\	S\4S jrSrg)rm   i©  uY  Reads content out of the object graph of a Pages 5+ document.

Drawables are reached twice over â€” once from the attachment table of the
text they are anchored in, and once from the document's own list of floating
ones â€” so every drawable this has already emitted is remembered. That also
bounds the walk: an object graph may contain cycles.
rJ   rr   rN   Nc                 óZ   • Xl         X l        [        U5      U l        [	        5       U l        g rR   )Ú_archiveÚ_objectsÚiwa_data_filesÚ_data_filesÚsetÚ_emitted)ÚselfrJ   rr   s      r0   Ú__init__ÚIWAReader.__init__²  s"   € ØŒØŒÜ)¨'Ó2ˆÔÜ"%£%ˆ�r/   rx   c                 óh  ^^• [        UR                  5      n[        U5      n[        X R                  5      n[        U5      n[        U[        5      n/ nSmUR                  S5       HÆ  nT[        U5      -   S-   m[        UTU5      n	U	(       a^  [        [        UR                  T5      5      u  p«[        UU4S jU 5       5      nUR                  [        XšU[!        UT5      U5      5        U H8  u  pÞTUs=::  a  T:  d  M  O  M  UR#                  U R%                  U5      5        M:     TmMÈ     U$ )a¦  Read one ``TSWP.StorageArchive`` as paragraphs and anchored drawables.

Apple marks the anchor of a drawable with U+FFFC inside the text, and the
storage's attachment table says which drawable each one is. The drawable
is emitted straight after the paragraph it is anchored in, which is where
it belongs in the reading order.

Args:
    storage: The storage to read.

Returns:
    The storage's blocks, in document order.
r   Ú
r:   c              3   ód   >#   • U  H%  u  pTUs=::  a  T:  d  M  O  M  [        U5      v •  M'     g 7frR   )r,   )rV   rº   r¨   Úendr:  s      €€r0   rX   Ú+IWAReader.storage_blocks.<locals>.<genexpr>Ó  s0   øé € ð  Ú3;¡< 5¸vÈÕ?TÐQTÑ?T“JÑ?T‘J”C˜—J�J²8ùs   ƒ0š0ž0)r   rg   r“   r§   rD  Úiwa_attachment_runsÚSTORAGE_COMMENT_FIELDÚsplitr!  r   r   r   r•   rÌ   r´   r   r   ro   Ú_drawable_blocks)rI  rx   r„   r  r·   Úattachmentsr_   r[   ÚlineÚpiecesrÚ   ÚlevelÚanchorsrº   rd   rO  r:  s                  @@r0   rn   ÚIWAReader.storage_blocks¸  s  ù€ ô ˜WŸ_™_Ó-ˆÜ Ó'ˆÜ ¯©Ó6ˆÜ)¨&Ó1ˆÜ& vÔ/DÓEˆà ˆØˆØ—J‘J˜tÖ$ˆDØœ3˜t›9Ñ$ qÑ(ˆCÜ˜d F¨DÓ1ˆFÞÜ.¬x¸¿¹ÀVÓ/LÓM‘�Üõ  Ù3;ó ó �ð —‘ÜØ u¬m¸DÀ&Ó.IÈ7óôó
 &1Ñ!�Ø˜UÕ( S×(Ñ(Ø—M‘M $×"7Ñ"7¸
Ó"CÖDñ &1ð ŠFñ! %ð$ ˆr/   ru   c                 ó|  • [        UR                  5      R                  [        S/5      S   n[	        U[
        5      (       d  / $ [        U5      nUb  U R                  R                  U5      OSnUc  / $ / n[        [        UR                  5      5       H#  nUR                  U R                  U5      5        M%     U$ )a›  Read the drawables the document owns rather than anchors in its text.

Reaching them by ownership matters: scanning every ``TSWP.StorageArchive``
in the document would also pick up headers, footers and footnotes, which
belong to the page rather than to the body flow.

Args:
    document: The ``TP.DocumentArchive`` of the document.

Returns:
    The blocks of every drawable not already emitted from the text.
Nr   )r   rg   rh   ÚDOCUMENT_DRAWABLES_FIELDrj   rk   r   rD  ÚsortedÚiwa_referenced_idsro   rT  )rI  ru   Ú	drawablesr  Úrootr[   rd   s          r0   rp   ÚIWAReader.floating_blocksâ  s¬   € ô   × 0Ñ 0Ó1×5Ñ5Ô6NÐQUÐPVÓWØñ
ˆ	ô ˜)¤U×+Ñ+ØˆIä" 9Ó-ˆ	Ø/8Ñ/Dˆt�}‰}× Ñ  Ô+È$ˆØ‰<ØˆIà ˆÜ Ô!3°D·L±LÓ!AÖBˆJØ�M‰M˜$×/Ñ/°
Ó;Ö<ñ Càˆr/   c                 óB  • [        UR                  5      n/ n[        U[        5       Hs  u  pEU R                  R                  U5      nUb  UR                  [        :w  a  M9  [        UR                  [        5      nUR                  U R                  U5      5        Mu     U$ )uY  Read the notes anchored in one storage.

The footnote run table anchors a note at the character its mark occupies
â€” one of the U+FFFC placeholders the text carries â€” and the note holds
its own storage of text.

Args:
    storage: The storage whose footnote table to read.

Returns:
    The notes' paragraphs, in the order they are anchored.
)r   rg   rQ  ÚSTORAGE_FOOTNOTE_FIELDrD  rh   rS   Ú	TSWP_NOTEr  ÚNOTE_STORAGE_FIELDro   Ú_storage_paragraphs)rI  rx   r„   Ú
paragraphsÚ_rd   ÚnoteÚtext_ids           r0   r^   ÚIWAReader.footnotesÿ  s‡   € ô ˜WŸ_™_Ó-ˆØ&(ˆ
Ü0°Ô9OÖP‰MˆAØ—=‘=×$Ñ$ ZÓ0ˆDØ‰|˜t×0Ñ0´IÓ=ÙÜ)¨$¯,©,Ô8JÓKˆGØ×Ñ˜d×6Ñ6°wÓ?Ö@ñ Qð Ðr/   c           	      ó^  • [        UR                  5      n/ n/ n[        U[        5       Hë  u  pVU R                  R                  U5      nUb  UR                  [        :w  a  M9  [         H¨  n[        UR                  U5      n	U	b  U R                  R                  U	5      OSn
U
b  U
R                  [        :w  a  MR  [        U4[        U44 HB  u  p¼[        U
R                  U5       H#  nUR                  U R                  U5      5        M%     MD     Mª     Mí     [!        U5      [!        U5      4$ )u£  Read the headers and footers of the page masters a storage runs under.

Pages writes three sets per master â€” first page, even pages, odd pages â€”
whether or not the author filled them in, and a document with several
sections repeats them per master, so identical text is emitted once.

Args:
    storage: The body storage, which names its page masters.

Returns:
    The header paragraphs and the footer paragraphs.
N)r   rg   rQ  ÚSTORAGE_PAGE_MASTER_FIELDrD  rh   rS   ÚTP_PAGE_MASTERÚ PAGE_MASTER_HEADER_FOOTER_FIELDSr  ÚTP_HEADERS_AND_FOOTERSÚHEADERS_FIELDÚFOOTERS_FIELDr÷   ro   rf  r   )rI  rx   r„   r\   r]   rh  rd   Úmasterr¨   ÚpairÚbundleÚsourcerw   rj  s                 r0   rq   ÚIWAReader.page_furniture  s
  € ô ˜WŸ_™_Ó-ˆØ#%ˆØ#%ˆä0°Ô9RÖS‰MˆAØ—]‘]×&Ñ& zÓ2ˆFØ‰~ ×!4Ñ!4¼Ó!FÙß9�Ü*¨6¯>©>¸5ÓA�Ø48Ñ4D˜Ÿ™×*Ñ*¨4Ô0È$�Ø‘> V×%8Ñ%8Ô<RÓ%RÙä" GÐ,Ü" GÐ,ó'‘N�Fô $6°f·n±nÀfÖ#M˜ØŸ™ d×&>Ñ&>¸wÓ&GÖHó $Nó	'ó :ñ	 Tô  ! Ó)Ô+<¸WÓ+EÐEÐEr/   c                 óZ  ^• [        UR                  5      n/ n[        U[        5       H~  u  nmU R                  R                  T5      nUb  UR                  [        :w  a  M:  [        UR                  [        5      nUR                  U4S jU R                  U5       5       5        M€     U$ )aæ  Read the comments attached to the text of one storage.

Pages 5 records a comment as a highlight over the words being commented
on rather than as a character in the text, so the run table gives the
stretch it covers. Each entry names a comment field, which holds the
comment; replies are comments in their own right and are followed as a
chain.

Args:
    storage: The storage whose comment table to read.

Returns:
    One comment per thread entry, anchored by the field's identifier.
c              3   óN   >#   • U  H  n[        U[        T5      5      v •  M     g 7frR   )r   r,   )rV   r  rd   s     €r0   rX   Ú%IWAReader.comments.<locals>.<genexpr>R  s#   øé € ð Ú;M°4”˜œc *›o×.Ð.Ò;Mùs   ƒ"%)r   rg   rQ  rR  rD  rh   rS   ÚTSWP_COMMENT_FIELDr  ÚCOMMENT_FIELD_STORAGE_FIELDro   Ú_thread)rI  rx   r„   r_   rh  r¨   Úheadrd   s          @r0   r_   ÚIWAReader.comments;  s“   ø€ ô ˜WŸ_™_Ó-ˆØ"$ˆä0°Ô9NÖO‰MˆAˆzØ—M‘M×%Ñ% jÓ1ˆEØ‰} × 2Ñ 2Ô6HÓ HÙÜ& u§}¡}Ô6QÓRˆDØ�O‰Oô Ø;?¿<¹<ÈÔ;Móö ñ Pð ˆr/   rd   c                 ó”  • / nU/n[        5       nU(       Ga0  UR                  S5      nUb  XT;   a  M#  UR                  U5        U R                  R	                  U5      nUb  UR
                  [        :w  a  Mh  [        UR                  5      nUR	                  [        S/5      S   n[        U[        5      (       aY  UR                  SSS9R                  5       n	U	(       a4  UR                  [        U R!                  UR                  5      U	5      5        UR#                  [%        UR                  [&        5      5        U(       a  GM0  U$ )zDRead one comment and its replies, as text prefixed by their authors.r   Nr|   r‰   rŠ   )rG  ÚpopÚaddrD  rh   rS   ÚTSD_COMMENT_STORAGEr³   rg   ÚCOMMENT_TEXT_FIELDrj   rk   r   rÄ   r´   r   Ú_authorro   r÷   ÚCOMMENT_REPLIES_FIELD)
rI  rd   ÚtextsÚpendingÚseenÚcurrentÚcommentr„   Úrawr  s
             r0   r}  ÚIWAReader._threadX  sÿ   € àˆØ�,ˆÜ›ˆçØ—k‘k !“nˆGØ‰ '£/ÙØ�H‰H�WÔØ—m‘m×'Ñ'¨Ó0ˆGØ‰ '×"6Ñ"6Ô:MÓ"MÙä  §¡Ó1ˆFØ—*‘*Ô/°$°Ó8¸Ñ;ˆCÜ˜#œu×%Ñ%Ø—z‘z '°)�zÐ<×BÑBÓD�ÞØ—L‘L¤¨$¯,©,°w·±Ó*GÈÓ!NÔOØ�N‰NÔ-¨g¯o©oÔ?TÓUÔV÷ ‰gð" ˆr/   rg   c                 óf  • [        U[        5      nUb  U R                  R                  U5      OSnUb  UR                  [
        :w  a  g[        UR                  5      R                  [        S/5      S   n[        U[        5      (       d  gUR                  SSS9R                  5       =(       d    S$ )z)Read the name of whoever wrote a comment.Nr   r|   r‰   rŠ   )r  ÚCOMMENT_AUTHOR_FIELDrD  rh   rS   ÚTSK_ANNOTATION_AUTHORr³   rg   ÚAUTHOR_NAME_FIELDrj   rk   r   rÄ   )rI  rg   rd   Úauthorr‚   s        r0   r…  ÚIWAReader._authorq  s”   € ä(¨Ô2FÓGˆ
Ø2<Ñ2H�—‘×"Ñ" :Ô.ÈdˆØ‰>˜V×0Ñ0Ô4IÓIØÜ˜6Ÿ>™>Ó*×.Ñ.Ô/@À4À&ÓIÈ!ÑLˆÜ˜$¤×&Ñ&ØØ�{‰{˜7¨9ˆ{Ð5×;Ñ;Ó=×EÀÐEr/   c                 óî   • Ub  U R                   R                  U5      OSnUb  UR                  [        :w  a  / $ [	        UR
                  5      n[        [        U5      [        X0R                   5      5      $ )z@Read one storage's paragraphs, ignoring anything anchored in it.N)	rD  rh   rS   rl   r   rg   r   r“   r§   )rI  rd   rx   r„   s       r0   rf  ÚIWAReader._storage_paragraphs|  sd   € à3=Ñ3I�$—-‘-×#Ñ# JÔ/ÈtˆØ‰?˜g×2Ñ2Ô6JÓJØˆIÜ˜WŸ_™_Ó-ˆÜÜ˜VÓ$Ô&6°v¿}¹}Ó&Mó
ð 	
r/   c                 óR  • XR                   ;   a  / $ U R                   R                  U5        U R                  R                  U5      nUc  / $ UR                  [
        :X  a0  [        UR                  [        5      nUb  U R                  U5      $ / $ UR                  [        :X  a  U R                  U5      /$ UR                  [        :X  ap  [        UR                  [        5      nUb  U R                  R                  U5      OSnUb  UR                  [        :w  a  / $ [        XPR                  5      nUb  U/$ / $ UR                  [         :X  aE  / n[#        UR                  [$        5       H#  nUR'                  U R                  U5      5        M%     U$ UR                  [(        :X  a  / n[+        [-        UR                  5      5       HY  n	U R                  R                  U	5      n
U
c  M#  U
R                  [.        :X  d  M9  UR'                  U R1                  U
5      5        M[     U$ / $ )z5Read whichever kind of drawable ``identifier`` names.N)rH  r‚  rD  rh   rS   ÚTSWP_DRAWABLE_ATTACHMENTr  rg   ÚATTACHMENT_DRAWABLE_FIELDrT  Ú	TSD_IMAGEÚ_pictureÚTST_TABULAR_INFOÚTABULAR_INFO_MODEL_FIELDÚTST_TABLE_MODELrî   Ú	TSD_GROUPr÷   ÚGROUP_CHILDREN_FIELDro   ÚTSWP_SHAPE_INFOr]  r^  rl   rn   )rI  rd   ÚdrawableÚanchoredrÝ   r¶   Údatar[   Úchildr	  rx   s              r0   rT  ÚIWAReader._drawable_blocks†  sÖ  € àŸ™Ó&ØˆIØ�‰×Ñ˜*Ô%à—=‘=×$Ñ$ ZÓ0ˆØÑØˆIà× Ñ Ô$<Ó<Ü*¨8×+;Ñ+;Ô=VÓWˆHØ6>Ñ6J�4×(Ñ(¨Ó2ÐRÐPRÐRà× Ñ ¤IÓ-Ø—M‘M (Ó+Ð,Ð,à× Ñ Ô$4Ó4Ü'¨×(8Ñ(8Ô:RÓSˆEØ05Ñ0A�D—M‘M×%Ñ% eÔ,ÀtˆEØ‰} × 2Ñ 2´oÓ EØ�	Ü˜U§M¡MÓ2ˆDØ!Ñ-�D�6Ð5°2Ð5à× Ñ ¤IÓ-Ø"$ˆFÜ+¨H×,<Ñ,<Ô>RÖS�Ø—‘˜d×3Ñ3°EÓ:Ö;ñ TàˆMà× Ñ ¤OÓ3ØˆFÜ$Ô%7¸×8HÑ8HÓ%IÖJ�
ØŸ-™-×+Ñ+¨JÓ7�ØÓ&¨7×+?Ñ+?ÔCWÕ+WØ—M‘M $×"5Ñ"5°gÓ">Ö?ñ Kð ˆMàˆ	r/   Úimagec                 óÌ  • [        UR                  5      nSn[         H‘  nUR                  US/5      S   n[	        U[
        5      (       d  M0  [        U5      nUb  U R                  R                  U5      OSnUc  M`  U=(       d    Un [        U R                  R                  U5      U5      s  $    [        SU5      $ ! [         a    [        R                  SU5         MÄ  f = f)zGRead a ``TSD.ImageArchive`` and the container member holding its bytes.r†   Nr   z%Pages image data member %s is missing)r³   rg   ÚIMAGE_DATA_FIELDSrh   rj   rk   r   rF  r   rC  rc   ÚKeyErrorÚ_logÚdebug)rI  r¦  r„   Únamedr¨   r»   Údata_idÚmembers           r0   rš  ÚIWAReader._picture¯  sÓ   € ä˜UŸ]™]Ó+ˆØˆß&ˆEØŸ
™
 5¨4¨&Ó1°!Ñ4ˆIÜ˜i¬×/Ñ/ÙÜ$ YÓ/ˆGØ6=Ñ6I�T×%Ñ%×)Ñ)¨'Ô2ÈtˆFØ‰~ÙØ—O˜VˆEðLÜ˜tŸ}™}×1Ñ1°&Ó9¸6ÓBÒBñ 'ô �t˜UÓ#Ð#øô	 ó Lô —
‘
ÐBÀF×KðLús   Â
$B?Â? C#Ã"C#)rC  rF  rH  rD  )r%   r&   r'   r(   r)   ÚzipfileÚZipFiler*   r+   r   rJ  Úlistr
   rn   rp   r   r^   rÌ   rq   r   r_   r,   r}  rk   r…  rf  rT  r   rš  r.   r$   r/   r0   rm   rm   ©  s2  † ñð( §¡ð (¸$¸sÀI¸~Ñ:Nð (ÐSWô (ð( ið (°D¸±Kô (ðT¨	ð °d¸5±kô ð: ð ¨t°I©ô ð.#FØ ð#Fà	ˆt�I‰  Y¡Ð/Ñ	0ô#FðJ 	ð ¨d°7©mô ð: #¨¡*ð °°c±ô ð2	F˜uð 	F¨¨t©ô 	Fð
¨c°D©jð 
¸TÀ)¹_ô 
ð'¨3ð '°4¸±;ô 'ðR$˜ið $¨G÷ $r/   rm   c                 ó‚   • [        U 5      R                  US/5      S   n[        U[        5      (       d  g[	        U5      $ )zARead the object identifier a message's reference field points at.Nr   )r³   rh   rj   rk   r   )rg   r¨   r»   s      r0   r  r  Å  s;   € ä˜GÓ$×(Ñ(¨°°Ó7¸Ñ:€IÜ�i¤×'Ñ'ØÜ˜)Ó$Ð$r/   c                 ó¾   • / n[        U 5      R                  U/ 5       H;  n[        U[        5      (       d  M  [	        U5      nUc  M*  UR                  U5        M=     U$ )zGRead the object identifiers a message's repeated reference field holds.)r³   rh   rj   rk   r   r´   )rg   r¨   Úidentifiersr»   rw   s        r0   r÷   r÷   Í  sY   € à€KÜ  Ó)×-Ñ-¨e°RÖ8ˆ	Ü˜)¤U×+Ñ+ÙÜ 	Ó*ˆØÓØ×Ñ˜vÖ&ñ 9ð Ðr/   c                 ó  • U R                  U/ 5      nU(       a  [        US   [        5      (       d  / $ / n[        US   5      R                  S/ 5       HŸ  n[        U[        5      (       d  M  [        U5      nUR                  SS/5      S   nUR                  SS/5      S   n[        U[        5      (       a  [        U[        5      (       d  M}  [        U5      nUc  M�  UR                  Xh45        M¡     UR                  S S9  U$ )aé  Resolve an anchoring run table to (character index, object id) pairs.

Unlike the style tables, an entry here anchors an object at one character
rather than putting a value in force from it, so entries without a reference
carry nothing and are dropped. Attachments, footnotes and page masters all
use this shape.

Args:
    fields: Decoded fields of the storage.
    field: The storage field holding the table.

Returns:
    Character index and object identifier pairs, in document order.
r   r:   Nr;   c                 ó   • U S   $ r«   r$   r¬   s    r0   r®   Ú%iwa_attachment_runs.<locals>.<lambda>ü  r°   r/   r±   )rh   rj   rk   r³   r+   r   r´   rµ   )	r„   r¨   r¶   r·   r¸   r¹   rº   r»   rw   s	            r0   rQ  rQ  Ù  sé   € ð$ �J‰J�u˜bÓ!€EÞœ
 5¨¡8¬U×3Ñ3Øˆ	à"$€DÜ˜U 1™XÓ&×*Ñ*¨1¨bÖ1ˆÜ˜%¤×'Ñ'ÙÜ˜UÓ#ˆØ—
‘
˜1˜t˜fÓ% aÑ(ˆØ—J‘J˜q 4 &Ó)¨!Ñ,ˆ	Ü˜%¤×%Ñ%¬Z¸	Ä5×-IÑ-IÙÜ 	Ó*ˆØÓØ�K‰K˜˜Ö(ñ 2ð 	‡I�IÑ$€IÑ%Ø€Kr/   c                 óN  • [        S U R                  5        5       S5      nUc  0 $ 0 n[        UR                  5      R	                  [
        / 5       HÏ  n[        U[        5      (       d  M  [        U5      nUR	                  [        S/5      S   nUR	                  [        S/5      S   n[        U[        5      (       d  UR	                  [        S/5      S   n[        U[        5      (       d  MŸ  [        U[        5      (       d  M¶  [        UR                  SSS9-   X%'   MÑ     U$ )z×Map each data identifier to the container member that holds its bytes.

Args:
    objects: Every object in the document, keyed by identifier.

Returns:
    Data identifiers and the ``Data/`` member names they name.
c              3   óP   #   • U  H  oR                   [        :X  d  M  Uv •  M     g 7frR   )rS   ÚTSP_PACKAGE_METADATArU   s     r0   rX   Ú!iwa_data_files.<locals>.<genexpr>
  s   é € ÐOÒ$ˆq¯©Ô:NÑ(N�‰Ò$ùrZ   Nr   r|   r‰   rŠ   )re   rf   r³   rg   rh   ÚPACKAGE_DATAS_FIELDrj   rk   ÚDATA_INFO_IDENTIFIER_FIELDÚDATA_INFO_NAME_FIELDÚDATA_INFO_PREFERRED_NAME_FIELDr+   ÚDATA_MEMBER_PREFIXr   )rr   ÚmetadataÚfilesr¸   rs   rd   r‚   s          r0   rE  rE     s  € ô ÙO�G—N‘NÔ$ÓOÐQUó€Hð ÑØˆ	à€EÜ˜X×-Ñ-Ó.×2Ñ2Ô3FÈÖKˆÜ˜%¤×'Ñ'ÙÜ˜5Ó!ˆØ—X‘XÔ8¸4¸&ÓAÀ!ÑDˆ
Ø�x‰xÔ,¨t¨fÓ5°aÑ8ˆÜ˜$¤×&Ñ&Ø—8‘8Ô:¸T¸FÓCÀAÑFˆDÜ�j¤#×&Ó&¬:°d¼E×+BÓ+BÜ 2°T·[±[Ø 	ð 6Að 6ñ !ˆEÓñ Lð €Lr/   rÁ   c                 ó˜  • U[         :”  a
  [        5       $ [        5       n[        U 5      R                  5        H}  nU Ht  n[	        U[
        5      (       d  M  [        U5      [        ::  a6   [        U5      n[	        U[        5      (       a  UR                  U5        Ma  Mc  U[        XAS-   5      -  nMv     M     U$ ! [         a     M‹  f = f)a$  Collect the object identifiers a message references, at any nesting.

Args:
    payload: The encoded message to scan.
    depth: Current recursion depth, bounded to keep a hostile document from
        driving this arbitrarily deep.

Returns:
    Every identifier reachable from the message.
r:   )ÚMAX_REFERENCE_DEPTHrG  r³   rf   rj   rk   r!  ÚREFERENCE_MAX_BYTESr   r   r+   r‚  r^  )rg   rÁ   Úfoundrf   rŽ   rw   s         r0   r^  r^    sº   € ð Ô"Ó"Ü‹uˆä“e€EÜ˜gÓ&×-Ñ-Ö/ˆÛˆEÜ˜e¤U×+Ñ+ÙÜ�5‹zÔ0Ó0ðÜ+¨EÓ2�Fô ˜f¤c×*Ñ*Ø—I‘I˜fÖ%ñ +ð Ô+¨E¸1±9Ó=Ñ=’ó ñ 0ð €Løô )ó Úðús   Á+B;Â;
C	ÃC	)r   )¦r)   Úloggingr°  Úcollections.abcr   Útypingr   r   Údocling_core.types.docr   r   r   Údocling.backend.iwork.contentr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Údocling.backend.iwork.iwar   r   r   r   Údocling.exceptionsr   Ú	getLoggerr%   rª  r   r    rÅ  rÆ  rž   r�   rÓ   r×   rÔ   r   r\  rT   rl   rœ   ri   r’   r}   r~   r�  r›  rœ  r™  rž  rŸ  r¨  r—  r˜  ÚSTORAGE_ATTACHMENT_FIELDrR  r{  r|  rƒ  r„  r�  r†  r�  r‘  rd  re  rc  rm  rn  ro  rp  rq  rr  r»  r½  r¾  rÀ  r¿  rÁ  r  rö   râ   rã   rå   rä   r  rñ   ró   rù   rø   rú   r  r  r  r  r  r  r  r  r  r  r-  r1  r.  r2  r/  r3  r,  r5  r6  r4  r›   r¥   rÃ   r¤   r¡   rÀ   r    rÍ   rÎ   r±  r²  ÚZipInfor+   r,   rz   rk   rƒ   r*   r“   r§   rÌ   rš   r£   r¦   r¢   rŸ   rî   ræ   rð   rò   rô   rç   rè   r#  r0  r³   rm   r  r÷   rQ  rE  rG  r^  r$   r/   r0   Ú<module>rÒ     s�  ðñ
ó Û Ý $ß &÷ñ ÷÷ ÷ ÷ ó ÷$ó õ 1à×Ò˜Ó"€áˆTƒ]€ô#�ô #ð Ð Ø CàÐ Ø NàÐ Ø 5à !Ð Ø MàÐ Ø :àÐ Ø Nð ØØØñ	Ð ðð €Ø IàÐ ðð Ð Ø RàÐ ðð Ð Ø QàÐ Ø SàÐ Ø ?àÐ Ø UàÐ Ø Jà€Ø GàÐ Ø MàÐ Ø Rà€	Ø =à€	Ø OàÐ Ø Gà$Ð ðð  Ð ðð Ð Ø TàÐ Ø HàÐ ðð Ð Ø NàÐ Ø KàÐ Ø NàÐ àÐ àÐ ðð
 Ð Ø KàÐ Ø Ià€	Ø DàÐ Ø TàÐ ðð Ð ðð €Ø Oà#/Ð  ðð Ð Ø 6à€à€Ø NàÐ Ø VàÐ Ø RàÐ à!"Ð àÐ ðð Ð à€Ø Mà€ðð Ð àÐ àÐ àÐ Ø QàÐ àÐ àÐ ðð Ð àÐ ðð €àÐ àÐ Ø Sà€ðð
 €à€àÐ àÐ àÐ àÐ àÐ ðð Ð àÐ Ø 3à€àÐ Ø ?à€Ø 9àÐ àÐ ðð Ð àÐ ð ØØØ�qÐØ˜!ÐðÐ ðð !"Ð ðð €Ø ?à€Ø JàÐ ðð €Ø NàÐ ðð Ð ðð Ð àÐ Ø Gð@Ø�_Š_ð@à�—’Ñ ð@ð ð@ð ð	@ð
 ô@ðF˜Eð  c¨D¡jô ð2˜T # t¨C°%©KÑ'8Ð"8Ñ9ð ¸cô ð&Ø��d˜3 ™;Ñ'Ð'Ñ(ð&Ø37¸¸Y¸Ñ3Gð&àô&ðR/Ø��d˜3 ™;Ñ'Ð'Ñ(ð/àð/ð �#�y�.Ñ!ð/ð ð	/ð
 �e�W˜b 4™iÐ'Ñ(ð/ð 
ˆ%��R˜$‘Y�Ñ
Ñ ô/ðd˜4  T¨#°©+Ñ%6Ð 6Ñ7ð ¸DÀÀsÈCÀxÁÑ<Qô ð(A�eð A  d¡
ô Að+˜Eð + iô +ð ˜Eð  j°4Ñ&7ô ð$)N�Yð )N¨¨c°9¨nÑ)=ð )NÀ)ÈdÑBRô )NðXØ��T˜# ™+Ñ&Ð&Ñ'ðØ26°s¸I°~Ñ2Fðàôð.Ø��T˜# ™+Ñ&Ð&Ñ'ðàðð �#�y�.Ñ!ðð �d˜3  S¨5¡[Ñ 1Ð1Ñ2°D¸¸i¸Ñ4HÐIÈ3ÐQUÉ:ÐUÑVð	ð
 
ˆ#ˆsˆ(�^ôð@NØ��T˜# ™+Ñ&Ð&Ñ'ðNØ26°s¸I°~Ñ2FðNàˆ4�ZôNðJØ��T˜# ™+Ñ&Ð&Ñ'ðJØ26°s¸I°~Ñ2FðJàˆ4�ZôJð"Ø��T˜# ™+Ñ&Ð&Ñ'ðØ26°s¸I°~Ñ2Fðà	ˆ)�_ôð()Ø
ð)Ø'ð)Ø36ð)ØEHð)à	ˆ)�_ô)ðX,˜5ð ,¨ð ,°jð ,ÀSÈ4ÁZô ,ð^9˜ð 9 3ð 9¨3ô 9ð

˜ð 
 4¨¨T°#¸±+Ñ->Ð(>Ñ#?ô 
÷Y$ñ Y$ðx% ð %¨sð %°s¸T±zô %ð	 ð 	¨cð 	°d¸3±iô 	ð *ñ$Ø��d˜3 ™;Ñ'Ð'Ñ(ð$àð$ð 
ˆ%��S�‰/Ñõ$ðN˜D  i Ñ0ð °T¸#¸s¸(±^ô ñ> ð ¨cð ¸#¸c¹(ö r/   