Simplified tree node for optimization.
| 151 | |
| 152 | @dataclass(slots=True) |
| 153 | class SimplifiedNode: |
| 154 | """Simplified tree node for optimization.""" |
| 155 | |
| 156 | original_node: 'EnhancedDOMTreeNode' |
| 157 | children: list['SimplifiedNode'] |
| 158 | should_display: bool = True |
| 159 | interactive_index: int | None = None |
| 160 | |
| 161 | is_new: bool = False |
| 162 | |
| 163 | ignored_by_paint_order: bool = False # More info in dom/serializer/paint_order.py |
| 164 | excluded_by_parent: bool = False # New field for bbox filtering |
| 165 | is_shadow_host: bool = False # New field for shadow DOM hosts |
| 166 | is_compound_component: bool = False # True for virtual components of compound controls |
| 167 | |
| 168 | def _clean_original_node_json(self, node_json: dict) -> dict: |
| 169 | """Recursively remove children_nodes and shadow_roots from original_node JSON.""" |
| 170 | # Remove the fields we don't want in SimplifiedNode serialization |
| 171 | if 'children_nodes' in node_json: |
| 172 | del node_json['children_nodes'] |
| 173 | if 'shadow_roots' in node_json: |
| 174 | del node_json['shadow_roots'] |
| 175 | |
| 176 | # Clean nested content_document if it exists |
| 177 | if node_json.get('content_document'): |
| 178 | node_json['content_document'] = self._clean_original_node_json(node_json['content_document']) |
| 179 | |
| 180 | return node_json |
| 181 | |
| 182 | def __json__(self) -> dict: |
| 183 | original_node_json = self.original_node.__json__() |
| 184 | # Remove children_nodes and shadow_roots to avoid duplication with SimplifiedNode.children |
| 185 | cleaned_original_node_json = self._clean_original_node_json(original_node_json) |
| 186 | return { |
| 187 | 'should_display': self.should_display, |
| 188 | 'interactive_index': self.interactive_index, |
| 189 | 'ignored_by_paint_order': self.ignored_by_paint_order, |
| 190 | 'excluded_by_parent': self.excluded_by_parent, |
| 191 | 'original_node': cleaned_original_node_json, |
| 192 | 'children': [c.__json__() for c in self.children], |
| 193 | } |
| 194 | |
| 195 | |
| 196 | class NodeType(int, Enum): |
no outgoing calls
no test coverage detected