snapshotBudgetRank function
Planner-usefulness rank; LOWER survives the budget.
Implementation
int snapshotBudgetRank(UiNode n) {
// Occluded controls cannot be used now. Keep the active surface ahead of
// background inputs/buttons when a modal pushes the snapshot over budget.
final visibilityRank = n.visible ? 0 : 10;
if (n.editable) return visibilityRank;
// Navigation primitives (the backend's `_is_nav_primitive` roles) ahead of
// other tappables: the bottom nav comes LAST in document order, so on a
// dense screen an order tie-break evicted the whole bar first and left
// the planner unable to switch sections.
if (n.role == 'tab' || n.role == 'link') return visibilityRank + 1;
if (n.actions.contains('tap') || n.role == 'button') {
return visibilityRank + 2;
}
if (n.checked != null || n.role == 'slider' || n.role == 'input_field') {
return visibilityRank + 3;
}
if (n.scrollable) return visibilityRank + 4;
if (n.identifier.isNotEmpty) return visibilityRank + 5;
if (n.text.isNotEmpty || n.value.isNotEmpty) return visibilityRank + 6;
return visibilityRank + 7;
}