diff options
-rw-r--r-- | src/static/client3.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/static/client3.js b/src/static/client3.js index 764bdaa8..6aea86ad 100644 --- a/src/static/client3.js +++ b/src/static/client3.js @@ -193,6 +193,34 @@ class WikiRect extends DOMRect { return this.fromRect(element.getBoundingClientRect()); } + static fromMouse() { + const {clientX, clientY} = liveMousePositionInfo.state; + + return WikiRect.fromRect({ + x: clientX, + y: clientY, + width: 0, + height: 0, + }); + } + + static fromElementUnderMouse(element) { + const mouseRect = WikiRect.fromMouse(); + + const rects = + Array.from(element.getClientRects()) + .map(rect => WikiRect.fromRect(rect)); + + const rectUnderMouse = + rects.find(rect => rect.contains(mouseRect)); + + if (rectUnderMouse) { + return rectUnderMouse; + } else { + return rects[0]; + } + } + static leftOf(origin, offset = 0) { // Returns a rectangle representing everywhere to the left of the provided // point or rectangle (with no top or bottom bounds), towards negative x. |