
    Bh"                     ^    S r SSKrSSKJr   " S S5      r " S S5      rS	 r " S
 S5      rg)zHandle target-counter, target-counters and target-text.

The TargetCollector is a structure providing required targets' counter_values
and stuff needed to build pending targets later, when the layout of all
targeted anchors has been done.

    N   )LOGGERc                   "    \ rS rSrSrSS jrSrg)TargetLookupItem   zItem controlling pending targets and page based target counters.

Collected in the TargetCollector's ``target_lookup_items``.

c                 H    Xl         S U l        0 U l        S U l        0 U l        g )N)state
target_boxparse_again_functionspage_maker_indexcached_page_counter_values)selfr	   s     H/var/www/html/env/lib/python3.13/site-packages/weasyprint/css/targets.py__init__TargetLookupItem.__init__   s.    

  &(" !% +-'    )r   r   r   r	   r
   N)pending__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r      s    
-r   r   c                       \ rS rSrSrS rSrg)CounterLookupItem'   zeItem controlling page based counters.

Collected in the TargetCollector's ``counter_lookup_items``.

c                 R    Xl         X l        X0l        S U l        SU l        0 U l        g )NF)parse_againmissing_countersmissing_target_countersr   r   r   )r   r    r!   r"   s       r   r   CounterLookupItem.__init__-   s3    & !1'>$ !%  +-'r   )r   r!   r"   r   r    r   Nr   r   r   r   r   r   '   s    
-r   r   c                     U S   S:X  a!  U S   R                  S5      (       a  U S   SS $ U S   S:X  a  U S   S   S:X  a  U S   S   $ gg)z)Get anchor name from string or uri token.r   string   #Nurlinternal)
startswith)anchor_tokens    r   anchor_name_from_tokenr,   ?   sg    A("|A'A'A#'F'FAqr""	aE	!l1oa&8J&FAq!! 'G	!r   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)TargetCollectorG   z@Collector of HTML targets used by CSS content with ``target-*``.c                 <    0 U l         0 U l        SU l        SU l        g )NTF)target_lookup_itemscounter_lookup_items
collectinghad_pending_targets)r   s    r   r   TargetCollector.__init__J   s%    #% $&! 
 $) r   c                     [        U[        5      (       aY  U R                  R                  U5      b  [        R
                  " SU5        gU R                  R                  U[        5       5        gg)z7Create a TargetLookupItem for the given `anchor_name``.NzAnchor defined twice: %r)
isinstancestrr1   getr   warning
setdefaultr   )r   anchor_names     r   collect_anchorTargetCollector.collect_anchorZ   sW    k3''''++K8D9;G((33!1!35	 (r   c                    [        U5      nU R                  R                  U[        S5      5      nUR                  S:X  a$  SU l        UR                  R                  X#4U5        UR                  S:X  a  [        R                  " SU5        U$ )zGet a TargetLookupItem corresponding to ``anchor_token``.

If it is already filled by a previous anchor-element, the status is
'up-to-date'. Otherwise, it is 'pending', we must parse the whole
tree again.

	undefinedr   Tz7Content discarded: target points to undefined anchor %r)
r,   r1   r9   r   r	   r4   r   r;   r   error)r   r+   
source_box	css_tokenr    r<   items          r   lookup_targetTargetCollector.lookup_targetc   s     -\:''++)+68 ::"'+D$&&11'6 ::$LLI r   c                    U R                   R                  U5      nU(       ae  UR                  S:X  aT  SUl        X4l        UR                  c9  UR                  5        VVs0 s H  u  pVXVR                  5       _M     snnUl        ggggs  snnf )zStore a target called ``anchor_name``.

If there is a pending TargetLookupItem, it is updated. Only previously
collected anchors are stored.

r   
up-to-dateN)r1   r9   r	   r
   cached_counter_valuesitemscopy)r   r<   target_counter_valuesr
   rD   keyvalues          r   store_targetTargetCollector.store_target{   s     ''++K8DJJ)+%DJ(O //7 -224464 +5#C%446
0 8 ,446s    B	c                     U R                   (       d  gU(       d  U(       a=  UR                  c  Xl        [        X4U5      nU R                  R	                  X4U5        gg)a  Collect missing (probably page-based) counters during formatting.

The ``missing_counters`` are re-used during pagination.

The ``missing_link`` attribute added to the parent_box is required to
connect the paginated boxes to their originating ``parent_box``.

N)r3   missing_linkr   r2   r;   )r   
parent_boxrC   parse_again_functionr!   r"   counter_lookup_items          r   collect_missing_counters(TargetCollector.collect_missing_counters   s]      6&&.*4'"3$'#) %%00')<>  7r   c                     U R                   (       aP  U R                  R                  5        H+  nUR                  R                  5        H
  nU" 5         M     M-     SU l         SU l        g)z Check pending targets if needed.FN)r4   r1   valuesr   r3   )r   rD   functions      r   check_pending_targets%TargetCollector.check_pending_targets   sT    ##00779 $ : : A A CHJ !D : (-D$r   c                    U R                   (       a  gU R                  R                  U5      nU(       Ga  UR                  S:X  Ga  X5l        UR
                  U:w  a  [        R                  " U5      Ul        U R                  R                  5        H  u  u  pgnUS:w  a  M  UR                  R                  U5      nUc  M0  UR                  b  UR                  [        U5      :  a	  SUl        M_  U HK  n	UR                  U	5      n
U
c  M  XER                     S   nSUS'   UR                  UR
                  5          M     M     gggg)zuStore target's current ``page_maker_index`` and page counter values.

Eventually update associated targeting boxes.

NrH   contentTcontent_changed)r3   r1   r9   r	   r   r   rK   deepcopyr2   rJ   r"   lenr   r    )r   r<   page_counter_valuesr   
page_makerrD   _rC   r!   counter_namecounter_valueremake_states               r   cache_target_page_counters*TargetCollector.cache_target_page_counters   s?    ??''++K8DJJ,.$4!..2EE26--'3)/
 -1,E,E,K,K,M(NQD I-  (,'C'C'G'G#(%$'/  --5 11S_D'+ 
 )9(;(?(?(M(4 *+@+@ A" E )>BL):; ,,T-L-LM! )9) -N F /4r   )r3   r2   r4   r1   N)r   r   r   r   r   r   r=   rE   rO   rV   r[   ri   r   r   r   r   r.   r.   G   s(    J) 506$>2 /"r   r.   )r   rK   loggerr   r   r   r,   r.   r   r   r   <module>rl      s7     - -2- -0"X" X"r   