
    AHjV	                    T    d dl mZ d dlmZmZ d dlmZmZmZ erd dl	m
Z
 ddZd	dZy)
    )annotations)TYPE_CHECKINGIterable)CombinatorTypeSelectorSelectorSet)DOMNodec                ,    t        fd| D              S )zCheck if a given node matches any of the given selector sets.

    Args:
        selector_sets: Iterable of selector sets.
        node: DOM node.

    Returns:
        True if the node matches the selector, otherwise False.
    c              3  ^   K   | ]$  }t        |j                  j                         & y w)N)_check_selectors	selectorscss_path_nodes).0selector_setnodes     I/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/css/match.py	<genexpr>zmatch.<locals>.<genexpr>   s,       	//1D1DEs   *-)any)selector_setsr   s    `r   matchr      s      )      c                   t         j                  }|d   }t        |      }t        |       }dg}|j                  }|j                  }d}	|r|d   \  }	}
|	|k(  s|
|k(  r |        n||
   }| |	   }|j
                  |k(  rN|j                  |      r2||u r	|	|dz
  k(  ry|	dz   |
|j                  z   f|d<    ||	|
dz   f       nH|	|
dz   f|d<   n=|j                  |      r%||u r	|	|dz
  k(  ry|	dz   |
|j                  z   f|d<   n |        |ry)zMatch a list of selectors against DOM nodes.

    Args:
        selectors: A list of selectors.
        css_path_nodes: The DOM nodes to check the selectors against.

    Returns:
        True if any node in css_path_nodes matches a selector.
    )r   r   r      TF)r   
DESCENDENTlenappendpop
combinatorcheckadvance)r   r   r   r   
path_countselector_countstackpushr   selector_index
node_index	path_nodeselectors                r   r   r      sI     **J"D^$J^N$*8E<<D
))CN
%*2Y"
^+zZ/GE&z2I 0H""j0>>), D(^~PQ?Q-Q#!/!!3Z(BRBR5R SE"I.*q.9:!/a @E"I >>), D(^~PQ?Q-Q#!/!!3Z(BRBR5R SE"IE/ 0 r   N)r   zIterable[SelectorSet]r   r	   returnbool)r   zlist[Selector]r   zlist[DOMNode]r*   r+   )
__future__r   typingr   r   textual.css.modelr   r   r   textual.domr	   r   r    r   r   <module>r1      s!    " * C C# /r   