« get me outta code hell

client: hoverable-tooltip: avoid elementFromPoint for hit detection - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js/rectangles.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-04-27 13:06:56 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-04-27 13:06:56 -0300
commitb74fa37385c147de772f689b003bd3d46eab912e (patch)
tree33450fb78250436d387996407132df528dd666c4 /src/static/js/rectangles.js
parentb4dce2cbdfc295402d29badfcc6b7f0db0e91493 (diff)
client: hoverable-tooltip: avoid elementFromPoint for hit detection
Diffstat (limited to 'src/static/js/rectangles.js')
-rw-r--r--src/static/js/rectangles.js16
1 files changed, 7 insertions, 9 deletions
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) {