| 150 | |
| 151 | // Group consecutive same-role siblings. [a,a,b,a,a,a] → [[a,a],[b],[a,a,a]] |
| 152 | function groupByConsecutiveRole(nodes) { |
| 153 | return nodes.reduce((groups, node) => { |
| 154 | const last = groups[groups.length - 1] |
| 155 | if (last && last[0].role === node.role) { |
| 156 | last.push(node) |
| 157 | return groups |
| 158 | } |
| 159 | groups.push([node]) |
| 160 | return groups |
| 161 | }, []) |
| 162 | } |
| 163 | |
| 164 | // Large group of same-role siblings → first N + placeholder line + last N. |
| 165 | // Returns mix of AriaNode (to render) and pre-rendered placeholder strings. |