nodeById method
Returns the node with the given id in O(1) using a cached index.
The index is rebuilt lazily (single tree walk) only when the document
has changed since the last lookup.
Implementation
FNode? nodeById(String id) {
if (_nodeIndexDirty) _rebuildNodeIndex();
final cached = _nodeById[id];
if (cached != null) return cached;
// Fallback: the index may be stale if a mutation forgot to notify.
// Rebuild once and retry before giving up.
_rebuildNodeIndex();
return _nodeById[id];
}