
    Cj>                       S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	J
r
JrJr  SSKJr  \(       a  SSKJr  SSKJr  \" S	\S
9r\(       a(  \SS.     SS jj5       r\SS.       SS jj5       r SSS.       SS jjjr\(       a(  \SS.     SS jj5       r\SS.       SS jj5       r SSS.       SS jjjrSS.       SS jjr        SS jrg)z
Functions for *walking* the DOM.

!!! note

    For most purposes you would be better off using [query][textual.dom.DOMNode.query], which uses these functions internally.
    )annotations)deque)
attrgetter)TYPE_CHECKINGIterableIteratorTypeVaroverload)ShapeDOMNode)WidgetWalkType)boundT)	with_rootc                   g N rootr   s     ^/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/walk.pywalk_depth_firstr          
      c                   g r   r   r   filter_typer   s      r   r   r   !        !r   Nc             #  (  #    [        U R                  5      /nUR                  nUR                  nUc_  U(       a  U v   U(       aL  [	        US   S5      =nc  U" 5         O(Uv   UR
                  =n(       a  U" [        U5      5        U(       a  MK  ggU(       a  [        X5      (       a  U v   U(       a\  [	        US   S5      =nc  U" 5         O8[        Xa5      (       a  Uv   UR
                  =n(       a  U" [        U5      5        U(       a  M[  gg7f)a  Walk the tree depth first (parents first).

!!! note

    Avoid changing the DOM (mounting, removing etc.) while iterating with this function.
    Consider [walk_children][textual.dom.DOMNode.walk_children] which doesn't have this limitation.

Args:
    root: The root note (starting point).
    filter_type: Optional DOMNode subclass to filter by, or `None` for no filter.
    with_root: Include the root in the walk.

Returns:
    An iterable of DOMNodes, or the type specified in `filter_type`.
N)iterchildrenpopappendnext_nodes
isinstance)r   r   r   stackr#   pushnoder"   s           r   r   r   *   s     * '+4==&9%:E
))C<<DJU2Y--6
#{{*8*h( e D66JU2Y--6d00J#{{*8*h( es   BDA=DDc                   g r   r   r   s     r   walk_breadth_firstr,   \   r   r   c                   g r   r   r   s      r   r,   r,   c   r   r   c             #  H  #    SSK Jn  [        5       nUR                  nUR                  nU=(       d    UnU(       a  [        X5      (       a  U v   U" U R                  5        U(       a7  U" 5       n[        X5      (       a  Uv   U" UR                  5        U(       a  M6  gg7f)a  Walk the tree breadth first (children first).

!!! note

    Avoid changing the DOM (mounting, removing etc.) while iterating with this function.
    Consider [walk_children][textual.dom.DOMNode.walk_children] which doesn't have this limitation.

Args:
    root: The root note (starting point).
    filter_type: Optional DOMNode subclass to filter by, or `None` for no filter.
    with_root: Include the root in the walk.

Returns:
    An iterable of DOMNodes, or the type specified in `filter_type`.
r   r   N)textual.domr   r   popleftextendr'   r"   r&   )	r   r   r   r   queuer0   r1   
check_typer*   s	            r   r,   r,   l   sx     * $!GEmmG\\F'JZ11

4==
yd''Jt{{	 %s   BB" B"c               "   U(       a  U R                   U:X  a  U $ [        5       nUR                  U 5        U(       aT  UR                  5       nUR                  R                  U5      =nb  U$ UR                  UR                  5        U(       a  MT  g)a  Special case to walk breadth first searching for a node with a given id.

This is more efficient than [walk_breadth_first][textual.walk.walk_breadth_first] for this special case, as it can use an index.

Args:
    root: The root node (starting point).
    node_id: Node id to search for.
    with_root: Consider the root node? If the root has the node id, then return it.

Returns:
    A DOMNode if a node was found, otherwise `None`.
N)idr   r$   r0   r&   
_get_by_idr1   )r   node_idr   r2   r*   
found_nodes         r   walk_breadth_search_idr9      st      TWW'!GE	LL
}}++0099JFT[[!	 %
 r   c              #  x  ^^^	#    [        U /5      /nUR                  nUR                  n[        S5      m	SUUU	4S jjnU" U 5      nU(       aj  [	        US   S5      =nc  U" 5         OFUR
                  (       d  UR                  (       a  Uv   U" U5      =n(       a  U" [        U5      5        U(       a  Mi  gg7f)a!  Walk the tree depth first in select order (top to bottom, then left to right).

Args:
    root: The root note (starting point).
    bounds: A Shape object that defines the selection bounds.
    bounded: Container widgets that require a bounds check.

Returns:
    An iterable of DOMNodes.
_selection_orderc                   > [        U R                  TS9nU T;   a4  U Vs/ s H'  nTR                  UR                  5      (       d  M%  UPM)     nnU$ s  snf )zGet children, sorted in selection order, and potentially filtered by selection bounds.

Args:
    node: A root node.

Returns:
    A list of child widgets.
)key)sorteddisplayed_and_visible_childrenoverlapscontent_region)r*   r"   childbounds
containersget_selection_orders      r   get_children-walk_selectable_widgets.<locals>.get_children   s^     //#
 :#+#+%vu?S?S/T8   s   $AAr    N)r*   r   returnzlist[Widget])r!   r#   r$   r   r%   is_containerallow_select)
r   rC   rD   r(   r#   r)   rF   r"   r*   rE   s
    ``      @r   walk_selectable_widgetsrK      s      &*4&\NE
))C<<D$%78 & D!H
rD))D2E$$):):
'--x-T(^$ %s   B1B:8B:)r   r   r   boolrH   zIterable[DOMNode])r   r   r   ztype[WalkType]r   rL   rH   zIterable[WalkType]r   )r   r   r   ztype[WalkType] | Noner   rL   rH   z&Iterable[DOMNode] | Iterable[WalkType])r   r   r7   strr   rL   rH   zDOMNode | None)r   r   rC   r   rD   zset[DOMNode]rH   zIterable[Widget])__doc__
__future__r   collectionsr   operatorr   typingr   r   r   r	   r
   textual.geometryr   r/   r   textual.widgetr   r   r   r,   r9   rK   r   r   r   <module>rU      s   #   G G "#%z1H       
	    
 	!!#! 	!
 
! ! *.-) 	-)
-)&-) 	-)
 ,-)`       
	    
 	!!#! 	!
 
! ! *.# 	#
#&# 	#
 ,#N 7;
/3</%
/%/%-9/%/%r   