* Gets the visible canvas bounds accounting for sidebar, terminal, and panel overlays. * When embedded, uses the container rect directly since CSS variable offsets don't apply.
(options?: CanvasViewportOptions)
| 19 | * When embedded, uses the container rect directly since CSS variable offsets don't apply. |
| 20 | */ |
| 21 | function getVisibleCanvasBounds(options?: CanvasViewportOptions): VisibleBounds { |
| 22 | const flowContainer = document.querySelector('.react-flow') |
| 23 | |
| 24 | if (options?.embedded && flowContainer) { |
| 25 | const rect = flowContainer.getBoundingClientRect() |
| 26 | return { |
| 27 | width: rect.width, |
| 28 | height: rect.height, |
| 29 | offsetLeft: 0, |
| 30 | offsetRight: 0, |
| 31 | offsetBottom: 0, |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | const style = getComputedStyle(document.documentElement) |
| 36 | |
| 37 | const sidebarWidth = Number.parseInt(style.getPropertyValue('--sidebar-width') || '0', 10) |
| 38 | const terminalHeight = Number.parseInt(style.getPropertyValue('--terminal-height') || '0', 10) |
| 39 | const panelWidth = Number.parseInt(style.getPropertyValue('--panel-width') || '0', 10) |
| 40 | |
| 41 | if (!flowContainer) { |
| 42 | return { |
| 43 | width: window.innerWidth - sidebarWidth - panelWidth, |
| 44 | height: window.innerHeight - terminalHeight, |
| 45 | offsetLeft: sidebarWidth, |
| 46 | offsetRight: panelWidth, |
| 47 | offsetBottom: terminalHeight, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const rect = flowContainer.getBoundingClientRect() |
| 52 | |
| 53 | // Calculate actual visible area in screen coordinates |
| 54 | // This works regardless of whether the container extends under overlays |
| 55 | const visibleLeft = Math.max(rect.left, sidebarWidth) |
| 56 | const visibleRight = Math.min(rect.right, window.innerWidth - panelWidth) |
| 57 | const visibleBottom = Math.min(rect.bottom, window.innerHeight - terminalHeight) |
| 58 | |
| 59 | // Calculate visible dimensions and offsets relative to the container |
| 60 | const visibleWidth = Math.max(0, visibleRight - visibleLeft) |
| 61 | const visibleHeight = Math.max(0, visibleBottom - rect.top) |
| 62 | |
| 63 | return { |
| 64 | width: visibleWidth, |
| 65 | height: visibleHeight, |
| 66 | offsetLeft: visibleLeft - rect.left, |
| 67 | offsetRight: rect.right - visibleRight, |
| 68 | offsetBottom: rect.bottom - visibleBottom, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets the center of the visible canvas in screen coordinates. |
no outgoing calls
no test coverage detected