
    <6h`                        d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 e j                  dk\  rd dlmZ nd dlmZ  G d de      Zd	ed
e	e   dee   fdZd	edee   dee   dee   dee   f
dZ	 dd	edee   deee      dee   fdZedk(  rHd dlmZ e G d d             Z ed eddd       eddd       eddd      g      Z e ee             yy)    N)Fraction)ceil)castListOptionalSequence)      )Protocolc                   B    e Zd ZU dZdZee   ed<   dZeed<   dZ	eed<   y)Edgez1Any object that defines an edge (such as Layout).Nsize   ratiominimum_size)
__name__
__module____qualname____doc__r   r   int__annotations__r   r        \/var/www/panel.atabookie.online/venv/lib/python3.12/site-packages/pip/_vendor/rich/_ratio.pyr   r      s&    ;D(3-E3NL#r   r   totaledgesreturnc                    |D cg c]  }|j                   xs d }}t        }d|v rt        t        ||            D cg c]  \  }\  }}|||f }}}}| t	        d |D              z
  }|dk  r1t        ||      D cg c]  \  }}||j
                  xs dn| c}}S  ||t	        d |D                    }	|D ]2  \  }}|	|j                  z  |j
                  k  s#|j
                  ||<    n8  |d      }
|D ])  \  }}t        |	|j                  z  |
z   d      \  }}
|||<   + nd|v rt        t        t           |      S c c}w c c}}}w c c}}w )a  Divide total space to satisfy size, ratio, and minimum_size, constraints.

    The returned list of integers should add up to total in most cases, unless it is
    impossible to satisfy all the constraints. For instance, if there are two edges
    with a minimum size of 20 each and `total` is 30 then the returned list will be
    greater than total. In practice, this would mean that a Layout object would
    clip the rows that would overflow the screen height.

    Args:
        total (int): Total number of characters.
        edges (List[Edge]): Edges within total space.

    Returns:
        List[int]: Number of characters for each edge.
    Nc              3   (   K   | ]
  }|xs d   yw)r   Nr   ).0r   s     r   	<genexpr>z ratio_resolve.<locals>.<genexpr>2   s     <d		<s   r   r   c              3   B   K   | ]  \  }}|j                   xs d   yw)r   N)r   )r    _edges      r   r!   z ratio_resolve.<locals>.<genexpr>;   s     KDDJJO!OKs   )r   r   	enumeratezipsumr   r   divmodr   r   r   )r   r   r$   sizes	_Fractionindexr   flexible_edges	remainingportion	remainders              r   ratio_resolver0      s   " .33Tdii43E3I %- (1UE1B'C
 
#|d| DM
 
 C<e<<<	> #&eU"3D$ .2\$##(qtC 
 sKNKK

 * 	KE4#t'8'88#00e		 "!I- $t"(4::)=	)I1"Mi#e$ E %-H S	5!!S 4
s   EEEratiosmaximumsvaluesc                 F   t        ||      D cg c]  \  }}|r|nd }}}t        |      }|s|dd S | }g }|j                  }	t        |||      D ]F  \  }}
}|r6|dkD  r1t        |
t	        ||z  |z              } |	||z
         ||z  }||z  }? |	|       H |S c c}}w )ad  Divide an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        maximums (List[int]): List of maximums values for each slot.
        values (List[int]): List of values

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    r   N)r&   r'   appendminround)r   r1   r2   r3   r   _maxtotal_ratiototal_remainingresultr5   maximumvaluedistributeds                r   ratio_reducer?   Q   s     7:&(6KL{udte"LFLf+KayOF]]F!$VXv!> w[1_guU_-D{-R'STK5;&'{*O5 K5M M Ms   Bminimumsc                 b   |r"t        ||      D cg c]  \  }}|r|nd }}}t        |      }|dkD  sJ d       | }g }|j                  }|dgt        |      z  }	n|}	t        ||	      D ]:  \  }}
|dkD  rt	        |
t        ||z  |z              }n|} ||       ||z  }||z  }< |S c c}}w )a<  Distribute an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        minimums (List[int]): List of minimum values for each slot.

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    r   zSum of ratios must be > 0)r&   r'   r5   lenmaxr   )r   r1   r@   r   _minr9   r:   distributed_totalr5   	_minimumsminimumr>   s               r   ratio_distributerH   q   s     :=fh:OP;5$4%Q&PPf+K?777?O#%%%FC#f+%		fi0 'w?gtEO,Ck,Q'RSK)K{u;&' ' Qs   B+__main__)	dataclassc                   >    e Zd ZU dZee   ed<   dZeed<   dZeed<   y)ENr   r   r   r   )	r   r   r   r   r   r   r   r   r   r   r   r   rL   rL      s%     #hsm"scr   rL   n   r   )N)sys	fractionsr   mathr   typingr   r   r   r   version_infor   pip._vendor.typing_extensionsr   r   r0   r?   rH   r   dataclassesrJ   rL   resolvedprintr'   r   r   r   <module>rW      s5   
   1 1v68 :" :"Xd^ :"S	 :"zS	-1#Y@DS		#YB DH!!S	!-5d3i-@!	#Y!H z%   S1T1a=!D!Q-4A"OPH	#h- r   