( value: unknown, displays: WindowBoundsDisplay[], )
| 40 | } |
| 41 | |
| 42 | export function normalizeWindowBounds( |
| 43 | value: unknown, |
| 44 | displays: WindowBoundsDisplay[], |
| 45 | ): Partial<Rectangle> { |
| 46 | if (!isRecord(value)) { |
| 47 | return {} |
| 48 | } |
| 49 | |
| 50 | const width = readDimension(value.width) |
| 51 | const height = readDimension(value.height) |
| 52 | const x = readNumber(value.x) |
| 53 | const y = readNumber(value.y) |
| 54 | const bounds: Partial<Rectangle> = {} |
| 55 | |
| 56 | if (width) { |
| 57 | bounds.width = width |
| 58 | } |
| 59 | |
| 60 | if (height) { |
| 61 | bounds.height = height |
| 62 | } |
| 63 | |
| 64 | if (x === undefined || y === undefined) { |
| 65 | return bounds |
| 66 | } |
| 67 | |
| 68 | const positionedBounds: Rectangle = { |
| 69 | x, |
| 70 | y, |
| 71 | width: width ?? DEFAULT_WINDOW_BOUNDS.width, |
| 72 | height: height ?? DEFAULT_WINDOW_BOUNDS.height, |
| 73 | } |
| 74 | |
| 75 | if ( |
| 76 | displays.some(display => |
| 77 | hasVisibleIntersection(positionedBounds, display.workArea), |
| 78 | ) |
| 79 | ) { |
| 80 | bounds.x = x |
| 81 | bounds.y = y |
| 82 | } |
| 83 | |
| 84 | return bounds |
| 85 | } |
no test coverage detected