
    T-h"                     ^    d Z ddlZddlmZ  G d d      Z G d d      Zd	 Z G d
 d      Zy)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                       e Zd ZdZddZy)TargetLookupItemzItem controlling pending targets and page based target counters.

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

    c                 J    || _         d | _        i | _        d | _        i | _        y )N)state
target_boxparse_again_functionspage_maker_indexcached_page_counter_values)selfr   s     \/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/weasyprint/css/targets.py__init__zTargetLookupItem.__init__   s0    

  &(" !% +-'    N)pending__name__
__module____qualname____doc__r    r   r   r   r      s    
-r   r   c                       e Zd ZdZd Zy)CounterLookupItemzmItem controlling page based counters.

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

    c                 X    || _         || _        || _        d | _        d| _        i | _        y )NF)parse_againmissing_countersmissing_target_countersr   r   r   )r   r   r   r   s       r   r   zCounterLookupItem.__init__-   s9    & !1'>$ !%  +-'r   Nr   r   r   r   r   r   '   s    
-r   r   c                     | d   dk(  r| d   j                  d      r| d   dd S | d   dk(  r| d   d   dk(  r| d   d   S yy)z)Get anchor name from string or uri token.r   string   #Nurlinternal)
startswith)anchor_tokens    r   anchor_name_from_tokenr&   ?   sd    A("|A'A'A#'FAqr""	aE	!l1oa&8J&FAq!! 'G	!r   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
TargetCollectorz@Collector of HTML targets used by CSS content with ``target-*``.c                 <    i | _         i | _        d| _        d| _        y )NTF)target_lookup_itemscounter_lookup_items
collectinghad_pending_targets)r   s    r   r   zTargetCollector.__init__J   s%    #% $&! 
 $) r   c                     t        |t              rW| j                  j                  |      t	        j
                  d|       y| j                  j                  |t                      yy)z7Create a TargetLookupItem for the given `anchor_name``.NzAnchor defined twice: %r)
isinstancestrr*   getr   warning
setdefaultr   )r   anchor_names     r   collect_anchorzTargetCollector.collect_anchorZ   sT    k3'''++K8D9;G((33!1!35	 (r   c                    t        |      }| j                  j                  |t        d            }|j                  dk(  r%d| _        |j                  j                  ||f|       |j                  dk(  rt        j                  d|       |S )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&   r*   r1   r   r   r-   r
   r3   r   error)r   r%   
source_box	css_tokenr   r4   items          r   lookup_targetzTargetCollector.lookup_targetc   s     -\:''++)+68 ::"'+D$&&11Y'6 ::$LLI r   c                    | j                   j                  |      }|rc|j                  dk(  rSd|_        ||_        |j                  8|j                         D ci c]  \  }}||j                          c}}|_        yyyyc c}}w )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)r*   r1   r   r	   cached_counter_valuesitemscopy)r   r4   target_counter_valuesr	   r;   keyvalues          r   store_targetzTargetCollector.store_target{   s     ''++K8DJJ)+%DJ(DO //7 -22446*4#uC%46
0 8 ,446s   Bc                     | j                   sy|s|r?|j                  ||_        t        |||      }| j                  j	                  ||f|       yy)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)r,   missing_linkr   r+   r3   )r   
parent_boxr:   parse_again_functionr   r   counter_lookup_items          r   collect_missing_countersz(TargetCollector.collect_missing_counters   sd      6&&.*4
'"3$&6'#) %%00Y')<>  7r   c                     | j                   rL| j                  j                         D ](  }|j                  j                         D ]	  } |         * d| _         d| _        y)z Check pending targets if needed.FN)r-   r*   valuesr
   r,   )r   r;   functions      r   check_pending_targetsz%TargetCollector.check_pending_targets   s]    ##00779  $ : : A A C HJ (-D$r   c                 d   | j                   ry| j                  j                  |      }|r|j                  dk(  r||_        |j
                  |k7  rt        j                  |      |_        | j                  j                         D ]  \  \  }}}|dk7  r|j                  j                  |      }|-|j                  |j                  t        |      k\  rd|_        Y|D ]I  }	|j                  |	      }
|
||j                     d   }d|d<   |j                  |j
                            yyyy)zStore target's current ``page_maker_index`` and page counter values.

        Eventually update associated targeting boxes.

        Nr>   contentTcontent_changed)r,   r*   r1   r   r   r   rA   deepcopyr+   r@   r   lenr   r   )r   r4   page_counter_valuesr   
page_makerr;   _r:   r   counter_namecounter_valueremake_states               r   cache_target_page_countersz*TargetCollector.cache_target_page_counters   sN    ??''++K8DJJ,.$4D!..2EE26--'3)/
 -1,E,E,K,K,M "(NQ	D I-  (,'C'C'G'G#(%$'/  --5 11S_D'+ 
 )9 "(;(?(?(M(4 *4+@+@ A" E )>BL):; ,,T-L-LM!")" F /4r   N)r   r   r   r   r   r5   r<   rE   rK   rO   r\   r   r   r   r(   r(   G   s(    J) 506$>2 /"r   r(   )r   rA   loggerr   r   r   r&   r(   r   r   r   <module>r^      s7     - -2- -0"X" X"r   