| 23 | * @returns Rounded rectangle overlay path data. |
| 24 | */ |
| 25 | export function makeOverlayPath(overlayPaths: OverlayPathParams[]) { |
| 26 | let openings = ''; |
| 27 | |
| 28 | const { innerWidth: w, innerHeight: h } = window; |
| 29 | |
| 30 | overlayPaths.forEach((overlayPath) => { |
| 31 | const { width, height, x = 0, y = 0, r = 0 } = overlayPath; |
| 32 | const { |
| 33 | topLeft = 0, |
| 34 | topRight = 0, |
| 35 | bottomRight = 0, |
| 36 | bottomLeft = 0 |
| 37 | } = typeof r === 'number' |
| 38 | ? { topLeft: r, topRight: r, bottomRight: r, bottomLeft: r } |
| 39 | : r; |
| 40 | |
| 41 | openings += |
| 42 | `M${x + topLeft},${y}` + |
| 43 | `a${topLeft},${topLeft},0,0,0-${topLeft},${topLeft}` + |
| 44 | `V${height + y - bottomLeft}` + |
| 45 | `a${bottomLeft},${bottomLeft},0,0,0,${bottomLeft},${bottomLeft}` + |
| 46 | `H${width + x - bottomRight}` + |
| 47 | `a${bottomRight},${bottomRight},0,0,0,${bottomRight}-${bottomRight}` + |
| 48 | `V${y + topRight}` + |
| 49 | `a${topRight},${topRight},0,0,0-${topRight}-${topRight}` + |
| 50 | `Z`; |
| 51 | }); |
| 52 | |
| 53 | return ( |
| 54 | `M${w},${h}` + |
| 55 | `H0` + |
| 56 | `V0` + |
| 57 | `H${w}` + |
| 58 | `V${h}` + |
| 59 | `Z` + |
| 60 | `${openings}` |
| 61 | ).replace(/\s/g, ''); |
| 62 | } |