(x, y, elem)
| 11 | */ |
| 12 | |
| 13 | export function clientToElement(x, y, elem) { |
| 14 | const bounds = elem.getBoundingClientRect(); |
| 15 | let pos = { x: 0, y: 0 }; |
| 16 | // Clip to target bounds |
| 17 | if (x < bounds.left) { |
| 18 | pos.x = 0; |
| 19 | } else if (x >= bounds.right) { |
| 20 | pos.x = bounds.width - 1; |
| 21 | } else { |
| 22 | pos.x = x - bounds.left; |
| 23 | } |
| 24 | if (y < bounds.top) { |
| 25 | pos.y = 0; |
| 26 | } else if (y >= bounds.bottom) { |
| 27 | pos.y = bounds.height - 1; |
| 28 | } else { |
| 29 | pos.y = y - bounds.top; |
| 30 | } |
| 31 | return pos; |
| 32 | } |
no outgoing calls
no test coverage detected