Skip to content

Commit 3a7269d

Browse files
committed
Fix eyedropper loupe region when UI zoom is not 1
On webkit2gtk, CSS zoom on <html> scales getBoundingClientRect() but leaves event.clientX/Y in logical coords, so the loupe sampled a patch offset from the cursor whenever Ctrl+=/Ctrl+- had been used. Normalize the rect into the same space as the mouse coords before computing the object-fit letterbox mapping.
1 parent 621f235 commit 3a7269d

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

frontend/src/lib/components/editor/WallpaperHero.svelte

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,23 @@
103103
: source.naturalHeight;
104104
if (!naturalW || !naturalH) return null;
105105
106+
// CSS `zoom` on <html> scales getBoundingClientRect() but not e.clientX/Y
107+
// on webkit2gtk — normalize rect into the same space as the mouse coords.
108+
const zoom =
109+
parseFloat(document.documentElement.style.zoom as string) || 1;
110+
const rectLeft = rect.left / zoom;
111+
const rectTop = rect.top / zoom;
112+
const rectWidth = rect.width / zoom;
113+
const rectHeight = rect.height / zoom;
114+
106115
// object-cover uses max (crop-fill), object-contain uses min (letterbox).
107116
const scale = expanded
108-
? Math.min(rect.width / naturalW, rect.height / naturalH)
109-
: Math.max(rect.width / naturalW, rect.height / naturalH);
110-
const offsetX = (rect.width - naturalW * scale) / 2;
111-
const offsetY = (rect.height - naturalH * scale) / 2;
112-
const localX = e.clientX - rect.left - offsetX;
113-
const localY = e.clientY - rect.top - offsetY;
117+
? Math.min(rectWidth / naturalW, rectHeight / naturalH)
118+
: Math.max(rectWidth / naturalW, rectHeight / naturalH);
119+
const offsetX = (rectWidth - naturalW * scale) / 2;
120+
const offsetY = (rectHeight - naturalH * scale) / 2;
121+
const localX = e.clientX - rectLeft - offsetX;
122+
const localY = e.clientY - rectTop - offsetY;
114123
115124
// In contain mode, clicks on the letterbox lie outside the image — bail.
116125
if (

0 commit comments

Comments
 (0)