(nodes: Array<Pick<SnapshotNode, 'type' | 'rect'>>)
| 226 | } |
| 227 | |
| 228 | function inferViewportRect(nodes: Array<Pick<SnapshotNode, 'type' | 'rect'>>): Rect | undefined { |
| 229 | const candidate = nodes |
| 230 | .filter((node) => isViewportNode(node.type) && isValidRect(node.rect)) |
| 231 | .map((node) => node.rect) |
| 232 | .sort( |
| 233 | (left, right) => |
| 234 | (right?.width ?? 0) * (right?.height ?? 0) - (left?.width ?? 0) * (left?.height ?? 0), |
| 235 | )[0]; |
| 236 | if (candidate) return candidate; |
| 237 | |
| 238 | const rects = nodes.map((node) => node.rect).filter(isValidRect); |
| 239 | if (rects.length === 0) return undefined; |
| 240 | |
| 241 | const width = Math.max(...rects.map((rect) => rect.x + rect.width)); |
| 242 | const height = Math.max(...rects.map((rect) => rect.y + rect.height)); |
| 243 | if (width <= 0 || height <= 0) return undefined; |
| 244 | return { x: 0, y: 0, width, height }; |
| 245 | } |
| 246 | |
| 247 | function isViewportNode(type: string | undefined): boolean { |
| 248 | if (!type) return false; |
no test coverage detected
searching dependent graphs…