
    ^j!5                       d Z ddlmZ ddlmZmZmZmZmZ  G d d          Z	 G d d          Z
 G d d	          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )zRun list encoding utilities.    )annotations)AnyCallable	GeneratorIterableIteratorc                  "    e Zd ZdZddZdd
ZdS )_Run)countvaluer   r   r   intreturnNonec                "    || _         || _        d S Nr   r   )selfr   r   s      N/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/text/runlist.py__init__z_Run.__init__	   s    



    strc                (    d| j          d| j         dS )NzRun(z, )r   r   s    r   __repr__z_Run.__repr__   s    1dj11DJ1111r   N)r   r   r   r   r   r   r   r   )__name__
__module____qualname__	__slots__r   r    r   r   r
   r
      sA        "I   2 2 2 2 2 2r   r
   c                  d    e Zd ZU dZded<   dgZdd
ZddZddZddZ	d dZ
d!dZd"dZd#dZdS )$RunLista  List of contiguous runs of values.

    A `RunList` is an efficient encoding of a sequence of values.  For
    example, the sequence ``aaaabbccccc`` is encoded as ``(4, a), (2, b),
    (5, c)``.  The class provides methods for modifying and querying the
    run list without needing to deal with the tricky cases of splitting and
    merging the run list entries.

    Run lists are used to represent formatted character data in pyglet.  A
    separate run list is maintained for each style attribute, for example,
    weight, italic, font size, and so on.  Unless you are overriding the
    document interfaces, the only interaction with run lists is via
    `RunIterator`.

    The length and ranges of a run list always refer to the character
    positions in the decoded list.  For example, in the above sequence,
    ``set_run(2, 5, 'x')`` would change the sequence to ``aaxxxbccccc``.
    z
list[_Run]runssizer   initialr   r   r   c                2    t          ||          g| _        dS )zCreate a run list of the given size and a default value.

        Args:
            size:
                Number of characters to represent initially.
            initial:
                The value of all characters in the run list.

        N)r
   r$   )r   r%   r&   s      r   r   zRunList.__init__'   s     '4(()			r   poslengthc                    d}| j         D ]4}||cxk    r||j        z   k    rn n|xj        |z  c_        ||j        z  }5dS )aZ  Insert characters into the run list.

        The inserted characters will take on the value immediately preceding
        the insertion point (or the value of the first character, if `pos` is
        0).

        Args:
            pos:
                Insertion index
            length:
                Number of characters to insert.

        r   N)r$   r   )r   r(   r)   iruns        r   insertzRunList.insert3   si     9 	 	CC((((1sy=(((((		V#		NAA	 	r   startendc                R   d}| j         D ]b}||z
  dk    r nV||cxk    r||j        z   k    r6n n3t          ||z
  ||j        z   |z
            }|xj        |z  c_        ||z  }||j        z  }cd | j         D             | _         | j         st          |j        d          g| _         dS dS )zRemove characters from the run list.

        Args:
            start:
                Starting index to remove from.
            end:
                End index, exclusive.

        r   c                (    g | ]}|j         d k    |S r   r   .0rs     r   
<listcomp>z"RunList.delete.<locals>.<listcomp>[       9991QWq[[Q[[[r   N)r$   r   minr
   r   )r   r.   r/   r+   r,   trims         r   deletezRunList.deleteG   s     9 	 	CU{aE****Q]*****3;CI(=>>		T!		tNAA99	999	 y 	-ci++,DIII	- 	-r   r   c                d   ||z
  dk    rdS d}d}d}d}d}t          | j                  D ]E\  }	}
|
j        }||cxk     r	||z   k     r
n n|	}||z
  }||cxk     r	||z   k     r
n n|	}||z
  }||z  }F|]| j        |         }
| j                            |t	          |
j        |                     |
xj        |z  c_        |||k    r||z  }|dz  }|K| j        |         }
| j                            |t	          |
j        |                     |
xj        |z  c_        d}| j        D ]'}
||k    r||
j        z   |k    r||
_        ||
j        z  }(| j        d         }| j        dd         D ]0}
|
j        |j        k    r|
xj        |j        z  c_        d|_        |
}1d | j        D             | _        dS )zSet the value of a range of characters.

        Args:
            start:
                Start index of range.
            end:
                End of range, exclusive.
            value:
                Value to set over the range.

        r   N   c                (    g | ]}|j         d k    |S r2   r3   r4   s     r   r7   z#RunList.set_run.<locals>.<listcomp>   r8   r   )	enumerater$   r   r-   r
   r   )r   r.   r/   r   r+   start_i
start_trimend_iend_trimrun_ir,   r   last_runs                r   set_runzRunList.set_runa   s3    ;!F 
#DI.. 	 	JE3IE5$$$$1u9$$$$$"QY
3""""U"""""7JAA )G$CIWd39j&A&ABBBII#II G##
*H
)E"CIUDH$=$=>>>II!II 9 	 	Czza#)ms22!	NAA 9Q<9QRR= 	 	CyHN**		X^+		!"HH :9	999			r   *Generator[tuple[int, int, Any], Any, None]c              #  ^   K   d}| j         D ] }|||j        z   |j        fV  ||j        z  }!d S Nr   )r$   r   r   )r   r+   r,   s      r   __iter__zRunList.__iter__   sN      9 	 	CQ]CI----NAA	 	r   RunIteratorc                     t          |           S )z+Get an extended iterator over the run list.)rK   r   s    r   get_run_iteratorzRunList.get_run_iterator   s    4   r   indexc                    d}| j         D ]-}||cxk    r||j        z   k     rn n	|j        c S ||j        z  }.||k    r| j         d         j        S t          )zGet the value at a character position.

        Args:
            index:
                Index of character.  Must be within range and non-negative.

        r   )r$   r   r   
IndexError)r   rN   r+   r,   s       r   __getitem__zRunList.__getitem__   s}     9 	 	CE))))A	M)))))y   NAA A::9R=&&r   r   c                :    t          t          |                     S r   )r   listr   s    r   r   zRunList.__repr__   s    4::r   N)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   rG   )r   rK   rN   r   r   r   r   )r   r   r   __doc____annotations__r    r   r-   r;   rF   rJ   rM   rR   r   r!   r   r   r#   r#      s          $ I
* 
* 
* 
*   (- - - -4=: =: =: =:~   ! ! ! !   (     r   r#   c                  "    e Zd ZdZddZdd
ZdS )AbstractRunIteratora  Range iteration over `RunList`.

    `AbstractRunIterator` objects allow any monotonically non-decreasing
    access of the iteration, including repeated iteration over the same index.
    Use the ``[index]`` operator to get the value at a particular index within
    the document.  For example::

        run_iter = iter(run_list)
        value = run_iter[0]
        value = run_iter[0]       # non-decreasing access is OK
        value = run_iter[15]
        value = run_iter[17]
        value = run_iter[16]      # this is illegal, the index decreased.

    Using `AbstractRunIterator` to access increasing indices of the value runs
    is more efficient than calling `RunList.__getitem__` repeatedly.

    You can also iterate over monotonically non-decreasing ranges over the
    iteration.  For example::

        run_iter = iter(run_list)
        for start, end, value in run_iter.ranges(0, 20):
            pass
        for start, end, value in run_iter.ranges(25, 30):
            pass
        for start, end, value in run_iter.ranges(30, 40):
            pass

    Both start and end indices of the slice are required and must be positive.
    rN   r   r   r   c                     t          d          )zGet the value at a given index.

        See the class documentation for examples of valid usage.

        Args:
            index:
                Document position to query.
        abstractNotImplementedErrorr   rN   s     r   rR   zAbstractRunIterator.__getitem__   s     "*---r   r.   r/   +Generator[tuple[int, int, Any], None, None]c                     t          d          )aA  Iterate over a subrange of the run list.

        See the class documentation for examples of valid usage.

        Args:
            start:
                Start index to iterate from.
            end:
                End index, exclusive.

        Returns:
            Iterator over (start, end, value) tuples.
        r\   r]   r   r.   r/   s      r   rangeszAbstractRunIterator.ranges   s     "*---r   NrV   r.   r   r/   r   r   r`   )r   r   r   rW   rR   rc   r!   r   r   rZ   rZ      sF         >	. 	. 	. 	.. . . . . .r   rZ   c                  :    e Zd ZU ded<   ddZdd	ZddZddZdS )rK   zIterator[AbstractRunIterator]_run_list_iterrun_list'Iterable[AbstractRunIterator] | RunListr   r   c                r    t          |          | _        t          |           \  | _        | _        | _        d S r   )iterrf   nextr.   r/   r   )r   rg   s     r   r   zRunIterator.__init__  s,    "8nn+/::(
DHdjjjr   rZ   c                *    t          | j                  S r   )rk   rf   r   s    r   __next__zRunIterator.__next__  s    D'(((r   rN   r   r   c                    	 || j         k    rC|| j        k    r8t          |           \  | _        | _         | _        || j         k    r|| j        k    8| j        S # t          $ r t
          w xY wr   )r/   r.   rk   r   StopIterationrQ   r_   s     r   rR   zRunIterator.__getitem__  s~    	48##
(:(:37::0
DHdj 48##
(:(: : 	 	 		s   AA A)r.   r/   r`   c              #    K   	 || j         k    r-t          |           \  | _        | _         | _        || j         k    -|t	          | j         |          | j        fV  || j         k    rSt          |           \  | _        | _         | _        | j        t	          | j         |          | j        fV  || j         k    Qd S d S # t
          $ r Y d S w xY wr   )r/   rk   r.   r   r9   ro   rb   s      r   rc   zRunIterator.ranges  s      	48##37::0
DHdj 48##TXs++TZ7777..37::0
DHdjj#dh"4"4dj@@@@ ......  	 	 	FF	s   B3B; ;
C	C	N)rg   rh   r   r   )r   rZ   rV   rd   )r   r   r   rX   r   rm   rR   rc   r!   r   r   rK   rK      sr         11116 6 6 6) ) ) )   	 	 	 	 	 	r   rK   c                  *    e Zd ZdZddZddZddZdS )OverriddenRunIteratorzPIterator over a `RunIterator`, with a value temporarily replacing a given range.base_iteratorrZ   r.   r   r/   r   r   r   r   c                >    || _         || _        || _        || _        dS )a4  Create a derived iterator.

        Args:
            base_iterator:
                Source of runs.
            start:
                Start of range to override
            end:
                End of range to override, exclusive
            value:
                Value to replace over the range

        N)rj   override_startoverride_endoverride_value)r   rs   r.   r/   r   s        r   r   zOverriddenRunIterator.__init__   s)     "	##r   r`   c              #    K   || j         k    s|| j        k    r$| j                            ||          D ]}|V  d S || j         cxk     r|k     r*n n'| j                            || j                   D ]}|V  t	          | j         |          t          | j        |          | j        fV  || j        cxk     r|k     r+n d S | j                            | j        |          D ]}|V  d S d S r   )ru   rv   rj   rc   maxr9   rw   )r   r.   r/   r6   s       r   rc   zOverriddenRunIterator.ranges3  sR     $%%%$2C)C)CY%%eS11    t*0000S00000))%1DEE  AGGGGt*E22t(#..&( ( ( ( t(....3......))$*;SAA  AGGGG /. r   rN   c                ^    | j         |cxk    r| j        k     r
n n| j        S | j        |         S r   )ru   rv   rw   rj   r_   s     r   rR   z!OverriddenRunIterator.__getitem__D  s@    %;;;;$*;;;;;;&&yr   N)
rs   rZ   r.   r   r/   r   r   r   r   r   rd   rV   r   r   r   rW   r   rc   rR   r!   r   r   rr   rr     sV        ZZ$ $ $ $&   "           r   rr   c                  *    e Zd ZdZdd
ZddZddZdS )FilteredRunIteratorzWIterate over an `AbstractRunIterator` with filtered values replaced by a default value.rs   rZ   filter_funcCallable[[Any], bool]defaultr   r   r   c                0    || _         || _        || _        dS )a  Create a filtered run iterator.

        Args:
            base_iterator:
                Source of runs.
            filter_func:
                Function taking a value as parameter, and returning ``True``
                if the value is acceptable, and ``False`` if the default value
                should be substituted.
            default:
                Default value to replace filtered values.

        Nrj   filterr   )r   rs   r~   r   s       r   r   zFilteredRunIterator.__init__N  s     "	!r   r.   r   r/   r`   c              #     K   | j                             ||          D ]/\  }}}|                     |          r|||fV  #||| j        fV  0d S r   )rj   rc   r   r   )r   r.   r/   start_end_r   s         r   rc   zFilteredRunIterator.ranges`  sz      #'9#3#3E3#?#? 	1 	1FD%{{5!! 1dE)))))dDL00000		1 	1r   rN   c                X    | j         |         }|                     |          r|S | j        S r   r   )r   rN   r   s      r   rR   zFilteredRunIterator.__getitem__g  s/    	% ;;u 	L|r   N)rs   rZ   r~   r   r   r   r   r   rd   rV   r{   r!   r   r   r}   r}   K  sV        aa   $1 1 1 1     r   r}   c                  6    e Zd ZU dZded<   ddZddZddZdS )ZipRunIteratorz1Iterate over multiple run iterators concurrently.tuple[RunIterator, ...]range_iteratorsr   r   c                    || _         dS )zCreate a zipped run iterator.

        Args:
            range_iterators:
                A tuple of ranged iterators.

        Nr   )r   r   s     r   r   zZipRunIterator.__init__r  s      /r   r.   r   r/   r`   c              #    K   	 fd| j         D             }t          d |D              \  }}}t          |          }t          |          }t          |          }k     r]t          |          }||fV  |t	          |          D ]-\  }}	||         |k    rt          |	          \  ||<   ||<   ||<   .k     [d S d S # t          $ r Y d S w xY w)Nc                <    g | ]}|                               S r!   )rc   )r5   r+   r/   r.   s     r   r7   z)ZipRunIterator.ranges.<locals>.<listcomp>~  s'    LLL!%--LLLr   c                ,    g | ]}t          |          S r!   )rk   )r5   r+   s     r   r7   z)ZipRunIterator.ranges.<locals>.<listcomp>  s    (D(D(DQa(D(D(Dr   )r   ziprT   r9   r?   rk   ro   )
r   r.   r/   	iteratorsstartsendsvaluesmin_endr+   iterators
    ``       r   rc   zZipRunIterator.ranges|  s     	LLLLLt7KLLLI#&(D(D)(D(D(D#E FD&&\\F::D&\\F#++d))Wf,,,,#,Y#7#7 G GKAxAw'))8<X5q	47F1I #++++++  	 	 	FF	s   B9C 
CCrN   r   c                *    fd| j         D             S )Nc                     g | ]
}|         S r!   r!   )r5   r+   rN   s     r   r7   z.ZipRunIterator.__getitem__.<locals>.<listcomp>  s    777Q%777r   r   r_   s    `r   rR   zZipRunIterator.__getitem__  s     7777$"67777r   N)r   r   r   r   rd   rV   )r   r   r   rW   rX   r   rc   rR   r!   r   r   r   r   n  sd         ;;,,,,/ / / /   "8 8 8 8 8 8r   r   c                  R    e Zd ZU dZded<   ded<   ded<   dd	ZddZddZddZdS )ConstRunIteratorz9Iterate over a constant value without creating a RunList.r   r)   r/   r   r   r   r   c                0    || _         || _        || _        d S r   )r)   r/   r   )r   r)   r   s      r   r   zConstRunIterator.__init__  s    


r   rG   c              #  ,   K   d| j         | j        fV  d S rI   )r)   r   r   s    r   rm   zConstRunIterator.__next__  s#      dj((((((r   r.   r`   c              #  "   K   ||| j         fV  d S r   r   rb   s      r   rc   zConstRunIterator.ranges  s!      S$*$$$$$$r   rN   c                    | j         S r   r   r_   s     r   rR   zConstRunIterator.__getitem__  s
    zr   N)r)   r   r   r   r   r   rU   rd   rV   )	r   r   r   rW   rX   r   rm   rc   rR   r!   r   r   r   r     s         CCKKKHHHJJJ   
) ) ) )% % % %     r   r   N)rW   
__future__r   typingr   r   r   r   r   r
   r#   rZ   rK   rr   r}   r   r   r!   r   r   <module>r      s   " " " " " " " " ? ? ? ? ? ? ? ? ? ? ? ? ? ?2 2 2 2 2 2 2 2n n n n n n n nb9. 9. 9. 9. 9. 9. 9. 9.x    %   >+  +  +  +  + / +  +  + \         -      F 8  8  8  8  8(  8  8  8F    *     r   