// HasMatcher reduces the set of matched elements to those that have a descendant
// that matches the matcher.
// It returns a new Selection object with the matching elements.
7828
func (s *Selection) HasMatcher(m Matcher) *Selection {
	return s.HasSelection(s.document.FindMatcher(m))
}
926437
func (l *loopCrosser) hasCrossing(ai, bi *rangeIterator) bool {
	// If ai.CellID() intersects many edges of B, then it is faster to use
	// CrossingEdgeQuery to narrow down the candidates. But if it intersects
	// only a few edges, it is faster to check all the crossings directly.
	// We handle this by advancing bi and keeping track of how many edges we
	// would need to test.
	const edgeQueryMinEdges = 20 // Tuned from benchmarks.
	var totalEdges int
	l.bCells = nil

	for {
		if n := bi.it.IndexCell().shapes[0].numEdges(); n > 0 {
			totalEdges += n
			if totalEdges >= edgeQueryMinEdges {
				// There are too many edges to test them directly, so use CrossingEdgeQuery.
				if l.cellCrossesAnySubcell(ai.it.IndexCell().shapes[0], ai.cellID()) {
					return true
				}
				bi.seekBeyond(ai)
				return false
			}
			l.bCells = append(l.bCells, bi.indexCell())
		}
		bi.next()
		if bi.cellID() > ai.rangeMax {
			break
		}
	}

	// Test all the edge crossings directly.
	for _, c := range l.bCells {
		if l.cellCrossesCell(ai.it.IndexCell().shapes[0], c.shapes[0]) {
			return true
		}
	}

	return false
}
305561
func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection {
	return filterAndPush(s, getParentsNodes(s.Nodes, until, nil), filter)
}
549905
func (s *Selection) BeforeMatcher(m Matcher) *Selection {
	return s.BeforeNodes(m.MatchAll(s.document.rootNode)...)
}
533988
func (s *Selection) RemoveMatcher(m Matcher) *Selection {
	return s.FilterMatcher(m).Remove()
}
354717
func (s *Selection) WrapAllMatcher(m Matcher) *Selection {
	return s.wrapAllNodes(m.MatchAll(s.document.rootNode)...)
}
1141200
func (s *Selection) ClosestMatcher(m Matcher) *Selection {
	return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
		// For each node in the selection, test the node itself, then each parent
		// until a match is found.
		for ; n != nil; n = n.Parent {
			if m.Match(n) {
				return []*html.Node{n}
			}
		}
		return nil
	}))
}
261905
func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
		until, nil), filter)
}
358187
func hasDescendantMatch(n *html.Node, a Selector) bool {
	for c := n.FirstChild; c != nil; c = c.NextSibling {
		if a(c) || (c.Type == html.ElementNode && hasDescendantMatch(c, a)) {
			return true
		}
	}
	return false
}
928814
func hasChildSelector(a Selector) Selector {
	return func(n *html.Node) bool {
		if n.Type != html.ElementNode {
			return false
		}
		return hasChildMatch(n, a)
	}
}
1222347
func NewMatcher(match string, matchType MatchType, log Log) Matcher {
	return Matcher{match: match, matchType: matchType, log: log}
}
736651
func (s *Selection) AppendMatcher(m Matcher) *Selection {
	return s.AppendNodes(m.MatchAll(s.document.rootNode)...)
}
675168
func Matcher(p rpc.ReadPeeker) bool {
	b, err := p.Peek(1)
	return err == nil && b[0] == '{'
}
595508
func (s *Selection) FilterMatcher(m Matcher) *Selection {
	return pushStack(s, winnow(s, m, true))
}
495852
func (m *Mux) AddMatcher(matchers ...Matcher) *Mux {
	m.Matchers = append(m.Matchers, matchers...)
	return m
}
629557
func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection {
	if sel == nil {
		return s.NextMatcher(filter)
	}
	return s.NextMatcherUntilNodes(filter, sel.Nodes...)
}
744274
func (r *Route) addMatcher(m matcher) *Route {
	if r.err == nil {
		r.matchers = append(r.matchers, m)
	}
	return r
}