
    Cj&                    &   S SK Jr  S SKrS SKJrJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKrS SKJrJrJr   " S S	\5      r " S
 S\5      r " S S\5      r\ " S S\5      5       r\R0                  S\R2                  S\R4                  S\R6                  S\R8                  S\R:                  S\R<                  S0r\RA                  5        V Vs0 s H  u  pX_M	     snn r!\RD                  " S5      RF                  r$\" S5      r%          S'S jr&          S'S jr'          S'S jr(          S'S jr)          S'S jr*          S'S jr+\R0                  \&\R2                  \'\R6                  \(\R8                  \)\R:                  \*\R<                  \+0r,S(S jr- " S  S!\5      r.\R^                  Ra                  S"S#9 " S$ S%\5      5       r1\1" \.Re                  S 5      \.Re                  S 5      5      r3S)S& jr4gs  snn f )*    )annotationsN)EnumuniqueFraction)	lru_cache)Iterable
NamedTuple)OffsetSizeclampc                      \ rS rSrSrSrg)ScalarError   z5Base class for exceptions raised by the Scalar class. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       d/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/css/scalar.pyr   r      s    ?r   r   c                      \ rS rSrSrSrg)ScalarResolveError   zDRaised for errors resolving scalars (unlikely to occur in practice).r   Nr   r   r   r   r   r      s    Nr   r   c                      \ rS rSrSrSrg)ScalarParseError   z6Raised when a scalar couldn't be parsed from a string.r   Nr   r   r   r   r   r      s    @r   r   c                  8    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrg)Unit   z4Enumeration of the various units inherited from CSS.                        r   N)r   r   r   r   r   CELLSFRACTIONPERCENTWIDTHHEIGHT
VIEW_WIDTHVIEW_HEIGHTAUTOr   r   r   r   r"   r"      s-    >EHGEFJKDr   r"    fr%whvwvhz ^(-?\d+\.?\d*)(fr|%|w|h|vw|vh)?$r$   c                    [        U 5      $ )zResolves explicit cell size, i.e. width: 10

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
r   valuesizeviewportfraction_units       r   _resolve_cellsrA   8   s     E?r   c                    U[        U 5      -  $ )zResolves a fraction unit i.e. width: 2fr

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
r   r<   s       r   _resolve_fractionrC   I   s     8E?**r   c                F    [        U 5      [        UR                  S5      -  $ )zResolves width unit i.e. width: 50w.

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
d   r   widthr<   s       r   _resolve_widthrH   Z   s     E?Xdjj#666r   c                F    [        U 5      [        UR                  S5      -  $ )zResolves height unit, i.e. height: 12h.

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
rE   r   heightr<   s       r   _resolve_heightrL   k   s     E?Xdkk3777r   c                F    [        U 5      [        UR                  S5      -  $ )zResolves view width unit, i.e. width: 25vw.

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
rE   rF   r<   s       r   _resolve_view_widthrN   |   s     E?Xhnnc:::r   c                F    [        U 5      [        UR                  S5      -  $ )zResolves view height unit, i.e. height: 25vh.

Args:
    value: Scalar value.
    size: Size of widget.
    viewport: Size of viewport.
    fraction_unit: Size of fraction, i.e. size of 1fr as a Fraction.

Returns:
    Resolved unit.
rE   rJ   r<   s       r   _resolve_view_heightrP      s     E?Xhoos;;;r   c                @    U  Vs/ s H  n[         U   PM     sn$ s  snf )zjGet symbols for an iterable of units.

Args:
    units: A number of units.

Returns:
    List of symbols.
)UNIT_SYMBOL)unitsunits     r   get_symbolsrU      s!     +00%$K%000s   c                  t   \ rS rSr% SrS\S'   S\S'   S\S'   SS jr\SS	 j5       r\SS
 j5       r	\SS j5       r
\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\\" SS9\R&                  4SS jj5       5       r\" SS9 S       SS jj5       r   S        S!S jjrSrg)"Scalar   zA numeric value and a unit.floatr=   r"   rT   percent_unitc                    U u  pnU[         R                  :X  a  gUR                  5       (       a  [        U5      OU U R                   3$ )Nauto)r"   r3   
is_integerintsymbolselfr=   rT   _s       r   __str__Scalar.__str__   sB    Q499 % 0 0 2 2#e*>t{{mLLr   c                <    U R                   [        R                  :H  $ )z&Check if the Scalar is explicit cells.)rT   r"   r,   ra   s    r   is_cellsScalar.is_cells   s     yyDJJ&&r   c                <    U R                   [        R                  :H  $ )z)Check if the Scalar is a percentage unit.)rT   r"   r.   rf   s    r   
is_percentScalar.is_percent   s     yyDLL((r   c                <    U R                   [        R                  :H  $ )z Check if the unit is a fraction.)rT   r"   r-   rf   s    r   is_fractionScalar.is_fraction   s     yyDMM))r   c                N    U u  pnU[         R                  :X  a  [        U5      $ S$ )z$Check if the unit is explicit cells.N)r"   r,   r^   r`   s       r   cellsScalar.cells   s'     Q!TZZ/s5z9T9r   c                N    U u  pnU[         R                  :X  a  [        U5      $ S$ )z/Get the fraction value, or None if not a value.N)r"   r-   r^   r`   s       r   fractionScalar.fraction   s'     Q!T]]2s5z<<r   c                (    [         U R                     $ )zGet the symbol of this unit.)rR   rT   rf   s    r   r_   Scalar.symbol   s     499%%r   c                <    U R                   [        R                  :H  $ )zCheck if this is an auto unit.)rT   r"   r3   rf   s    r   is_autoScalar.is_auto   s     yyDII%%r   c                `    U " [        U5      [        R                  [        R                  5      $ )z`Create a scalar with cells unit.

Args:
    value: A number of cells.

Returns:
    New Scalar.
)rY   r"   r,   r/   )clsr=   s     r   from_numberScalar.from_number   s     5<TZZ88r   i   )maxsizec                "   UR                  5       S:X  a(  U " S[        R                  [        R                  5      nU$ [        U5      nUc  [	        U< S35      eUR                  5       u  pVU " [        U5      [        U=(       d    S   U5      nU$ )zParse a string into a Scalar

Args:
    token: A string containing a scalar, e.g. "3.14fr"

Raises:
    ScalarParseError: If the value is not a valid scalar

Returns:
    New scalar
r\         ?z is not a valid scalarr4   )lowerr"   r3   _MATCH_SCALARr   groupsrY   SYMBOL_UNIT)r{   tokenrZ   scalarmatchr=   	unit_names          r   parseScalar.parse   s     ;;=F"dii3F  "%(E}&%2H'IJJ$||~Eu{9?'C\RFr   i   Nc                    U u  pEnU[         R                  :X  a  Un [        U   " XAX#=(       d    [        5      nU$ ! [         a    [        S[        U 5      < 35      ef = f)zResolve scalar with units into a dimensions.

Args:
    size: Size of the container.
    viewport: Size of the viewport (typically terminal size)

Raises:
    ScalarResolveError: If the unit is unknown.

Returns:
    A size (in cells)
zexpected dimensions; found )r"   r.   RESOLVE_MAP_FRACTION_ONEKeyErrorr   str)ra   r>   r?   r@   r=   rT   rZ   	dimensions           r   resolveScalar.resolve
  sp      %)!\4<<D	R#D)X'EI
   	R$'B3t9-%PQQ	Rs	   < #Ac                ~    [        Ub  UOU R                  Ub  UOU R                  Ub  U5      $ U R                  5      $ )zGet a copy of this Scalar, with values optionally modified

Args:
    value: The new value, or None to keep the same value
    unit: The new unit, or None to keep the same unit
    percent_unit: The new percent_unit, or None to keep the same percent_unit
)rW   r=   rT   rZ   )ra   r=   rT   rZ   s       r   	copy_withScalar.copy_with&  sJ     &EDJJ$D$))(4L
 	
 ;?:K:K
 	
r   r   )returnr   r   bool)r   z
int | None)r=   rY   r   rW   )r   r   rZ   r"   r   rW   N)r>   r   r?   r   r@   zFraction | Noner   r   )NNN)r=   zfloat | NonerT   Unit | NonerZ   r   r   rW   )r   r   r   r   r   __annotations__rc   propertyrg   rj   rm   rp   rs   r_   rx   classmethodr|   r   r"   r/   r   r   r   r   r   r   r   rW   rW      sZ   %L
JM ' ' ) ) * * : :
 = =
 & & & & 	9 	9 t48JJ   , tKO$(9H	 : # $(	

 
 "	

 

 
r   rW   T)angularc                  t    \ rS rSr% SrS\S'   S\S'   \SS j5       r\SS j5       rSS jr	SS	 jr
SS
 jrSrg)ScalarOffseti:  z?An Offset with two scalars, used to animate between to Scalars.rW   xyc                    [         $ )z Get a null scalar offset (0, 0).)NULL_SCALAR)r{   s    r   nullScalarOffset.nullA  s
     r   c                    Uu  p#U " [        U[        R                  [        R                  5      [        U[        R                  [        R                  5      5      $ )zoCreate a Scalar offset from a tuple of integers.

Args:
    offset: Offset in cells.

Returns:
    New offset.
)rW   r"   r,   r/   r0   )r{   offsetr   r   s       r   from_offsetScalarOffset.from_offsetF  s@     1djj$**-1djj$++.
 	
r   c                Z    U u  p[        UR                  =(       d    UR                  5      $ r   )r   r=   )ra   r   r   s      r   __bool__ScalarOffset.__bool__V  s!    AGG&qww''r   c              #  p   #    S [        U R                  5      4v   S [        U R                  5      4v   g 7fr   )r   r   r   rf   s    r   __rich_repr__ScalarOffset.__rich_repr__Z  s+     CKCKs   46c           	         U u  p4[        [        UR                  X5      5      [        UR                  X5      5      5      $ )zResolve the offset into cells.

Args:
    size: Size of container.
    viewport: Size of viewport.

Returns:
    Offset in cells.
)r   roundr   )ra   r>   r?   r   r   s        r   r   ScalarOffset.resolve^  s:     !))D+,!))D+,
 	
r   r   N)r   r   )r   ztuple[int, int]r   r   r   )r   zrich.repr.Result)r>   r   r?   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   :  sD    III  
 
( 
r   r   c                    U R                  5       n U R                  S5      (       a  [        [        U SS 5      S-  SS5      nU$ [        U 5      nU$ )zrConvert a string percentage e.g. '20%' to a float e.g. 20.0.

Args:
    string: The percentage string to convert.
r6   Ng      Y@g        r   )stripendswithr   rY   )stringfloat_percentages     r   percentage_string_to_floatr   r  sW     \\^Fs vcr{!3e!;S#F  !=r   )
r=   rY   r>   r   r?   r   r@   r   r   r   )rS   zIterable[Unit]r   z	list[str])r   r   r   rY   )5
__future__r   reenumr   r   	fractionsr   	functoolsr   typingr	   r
   	rich.reprrichtextual.geometryr   r   r   	Exceptionr   r   r   r"   r,   r-   r.   r/   r0   r1   r2   rR   itemsr   compiler   r   r   rA   rC   rH   rL   rN   rP   r   rU   rW   reprr\   r   r|   r   r   )kvs   00r   <module>r      s   " 	    '  0 0@) @O OA{ A 
4 
 
 	JJMM4LL#JJKKOOTd !, 1 1 34 3qt 34

>?EE(,=E"+++(,+=E++"777(,7=E77"888(,8=E88";;;(,;=E;;"<<<(,<=E<<$ 	JJMM$JJKKOO(*	1C
Z C
L 1
: 1
 1
h 6--a0&2D2DQ2GHA
 5s   H