* Gets the center of the visible canvas in screen coordinates.
(options?: CanvasViewportOptions)
| 73 | * Gets the center of the visible canvas in screen coordinates. |
| 74 | */ |
| 75 | function getVisibleCanvasCenter(options?: CanvasViewportOptions): { x: number; y: number } { |
| 76 | const bounds = getVisibleCanvasBounds(options) |
| 77 | |
| 78 | const flowContainer = document.querySelector('.react-flow') |
| 79 | const rect = flowContainer?.getBoundingClientRect() |
| 80 | const containerLeft = rect?.left ?? 0 |
| 81 | const containerTop = rect?.top ?? 0 |
| 82 | |
| 83 | return { |
| 84 | x: containerLeft + bounds.offsetLeft + bounds.width / 2, |
| 85 | y: containerTop + bounds.height / 2, |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | interface FitViewToBoundsOptions { |
| 90 | padding?: number |
no test coverage detected