2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2020 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
10 * HTML element utility functions
13export 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) {
19 } else if (x >= bounds.right) {
20 pos.x = bounds.width - 1;
22 pos.x = x - bounds.left;
26 } else if (y >= bounds.bottom) {
27 pos.y = bounds.height - 1;
29 pos.y = y - bounds.top;