// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.23

package html

import 

// Ancestors returns an iterator over the ancestors of n, starting with n.Parent.
//
// Mutating a Node or its parents while iterating may have unexpected results.
func ( *Node) () iter.Seq[*Node] {
	_ = .Parent // eager nil check

	return func( func(*Node) bool) {
		for  := .Parent;  != nil && ();  = .Parent {
		}
	}
}

// ChildNodes returns an iterator over the immediate children of n,
// starting with n.FirstChild.
//
// Mutating a Node or its children while iterating may have unexpected results.
func ( *Node) () iter.Seq[*Node] {
	_ = .FirstChild // eager nil check

	return func( func(*Node) bool) {
		for  := .FirstChild;  != nil && ();  = .NextSibling {
		}
	}

}

// Descendants returns an iterator over all nodes recursively beneath
// n, excluding n itself. Nodes are visited in depth-first preorder.
//
// Mutating a Node or its descendants while iterating may have unexpected results.
func ( *Node) () iter.Seq[*Node] {
	_ = .FirstChild // eager nil check

	return func( func(*Node) bool) {
		.descendants()
	}
}

func ( *Node) ( func(*Node) bool) bool {
	for  := range .ChildNodes() {
		if !() || !.() {
			return false
		}
	}
	return true
}