findById function
Finds a node by ID in the entire tree.
If nodeIndex is provided (e.g. document.nodeIndex), it is used
directly for an O(1) lookup instead of a full DFS traversal.
Implementation
FNode? findById(FNode root, String id, {Map<String, FNode>? nodeIndex}) {
if (nodeIndex != null) return nodeIndex[id];
return findNode(root, (n) => n.id == id);
}