From b74fa37385c147de772f689b003bd3d46eab912e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 27 Apr 2026 13:06:56 -0300 Subject: client: hoverable-tooltip: avoid elementFromPoint for hit detection --- src/static/js/rectangles.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/static/js/rectangles.js') diff --git a/src/static/js/rectangles.js b/src/static/js/rectangles.js index 24382ef8..428eebba 100644 --- a/src/static/js/rectangles.js +++ b/src/static/js/rectangles.js @@ -16,7 +16,10 @@ export class WikiRect extends DOMRect { static fromMouse() { const {clientX, clientY} = liveMousePositionInfo.state; + return WikiRect.fromPoint(clientX, clientY); + } + static fromPoint(clientX, clientY) { return WikiRect.fromRect({ x: clientX, y: clientY, @@ -26,20 +29,15 @@ export class WikiRect extends DOMRect { } static fromElementUnderMouse(element) { - const mouseRect = WikiRect.fromMouse(); + return WikiRect.fromElementContaining(element, WikiRect.fromMouse()); + } + static fromElementContaining(element, innerRect) { 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]; - } + return rects.find(rect => rect.contains(innerRect)); } static leftOf(origin, offset = 0) { -- cgit 1.3.0-6-gf8a5