
    AHj                    T   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 erddlmZ  e	de      Zer$e
dd		 	 	 	 	 dd
       Ze
dd		 	 	 	 	 	 	 dd       Z	 ddd		 	 	 	 	 	 	 ddZer$e
dd		 	 	 	 	 dd       Ze
dd		 	 	 	 	 	 	 dd       Z	 ddd		 	 	 	 	 	 	 ddZdd		 	 	 	 	 	 	 ddZy)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)TYPE_CHECKINGIterableIteratorTypeVaroverloadDOMNodeWalkType)boundT)	with_rootc                    y N rootr   s     D/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/walk.pywalk_depth_firstr          
      c                    y r   r   r   filter_typer   s      r   r   r           !r   Nc             #    K   t        | j                        g}|j                  }|j                  }|I|r|  |r@t	        |d   d      x} |        n#| |j
                  x}r |t        |             |r?yy|rt        | |      r|  |rLt	        |d   d      x} |        n/t        ||      r| |j
                  x}r |t        |             |rKyyw)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(  D+6JU2Y--6dK0J#{{*8*h( s   A7C:A CCc                    y r   r   r   s     r   walk_breadth_firstr)   X   r   r   c                    y r   r   r   s      r   r)   r)   _   r   r   c             #    K   ddl m} t               }|j                  }|j                  }|xs |}|rt        | |      r|   || j                         |r- |       }t        ||      r|  ||j                         |r,yyw)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   queuer-   r.   
check_typer'   s	            r   r)   r)   h   su     * $!GEmmG\\F'JZj1

4==
ydJ'Jt{{	 s   B BBc                   |r| j                   |k(  r| S t               }|j                  |        |rM|j                         }|j                  j                  |      x}|S |j                  |j                         |rMy)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!   r-   r#   
_get_by_idr.   )r   node_idr   r/   r'   
found_nodes         r   walk_breadth_search_idr6      sr      TWW'!GE	LL
}}++0099JFT[[!	 
 r   )r   r   r   boolreturnzIterable[DOMNode])r   r   r   ztype[WalkType]r   r7   r8   zIterable[WalkType]r   )r   r   r   ztype[WalkType] | Noner   r7   r8   z&Iterable[DOMNode] | Iterable[WalkType])r   r   r4   strr   r7   r8   zDOMNode | None)__doc__
__future__r   collectionsr   typingr   r   r   r   r	   r,   r   r   r   r)   r6   r   r   r   <module>r>      s   #  G G#z1H       
	    
 	!!#! 	!
 
! ! *.-) 	-)
-)&-) 	-)
 ,-)`       
	    
 	!!#! 	!
 
! ! *.# 	#
#&# 	#
 ,#N 7;
/3r   