feat(know-your-world): make magnifier lazy - only move when cursor obscured

The magnifier now stays in place unless the cursor enters its bounds.
This reduces visual distraction since the magnifier won't constantly
jump to opposite corners as the user moves the mouse.

- Track current magnifier bounds (position + dimensions)
- Check if cursor is within magnifier area (with 10px padding)
- Only calculate new position when cursor would be obscured
- Otherwise keep magnifier at its current position

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock 2025-11-26 10:02:10 -06:00
parent d7be8947bd
commit ac82564eac
1 changed files with 27 additions and 7 deletions

View File

@ -1588,20 +1588,40 @@ export function MapRenderer({
const magnifierWidth = containerRect.width * MAGNIFIER_SIZE_RATIO
const magnifierHeight = containerRect.height * MAGNIFIER_SIZE_RATIO
// Calculate magnifier position (opposite corner from cursor)
// magnifierWidth and magnifierHeight already declared above
const isLeftHalf = cursorX < containerRect.width / 2
const isTopHalf = cursorY < containerRect.height / 2
// Lazy magnifier positioning: only move if cursor would be obscured
// Check if cursor is within current magnifier bounds (with padding)
const padding = 10 // pixels of buffer around magnifier
const currentMagLeft = targetLeft
const currentMagTop = targetTop
const currentMagRight = currentMagLeft + magnifierWidth
const currentMagBottom = currentMagTop + magnifierHeight
const newTop = isTopHalf ? containerRect.height - magnifierHeight - 20 : 20
const newLeft = isLeftHalf ? containerRect.width - magnifierWidth - 20 : 20
const cursorInMagnifier =
cursorX >= currentMagLeft - padding &&
cursorX <= currentMagRight + padding &&
cursorY >= currentMagTop - padding &&
cursorY <= currentMagBottom + padding
// Only calculate new position if cursor would be obscured
let newTop = targetTop
let newLeft = targetLeft
if (cursorInMagnifier) {
// Move to opposite corner from cursor
const isLeftHalf = cursorX < containerRect.width / 2
const isTopHalf = cursorY < containerRect.height / 2
newTop = isTopHalf ? containerRect.height - magnifierHeight - 20 : 20
newLeft = isLeftHalf ? containerRect.width - magnifierWidth - 20 : 20
}
if (pointerLocked) {
console.log(
'[Magnifier] SHOWING with zoom:',
adaptiveZoom,
'| Setting opacity to 1, position:',
{ top: newTop, left: newLeft }
{ top: newTop, left: newLeft },
cursorInMagnifier ? '(moved - cursor was in magnifier)' : '(staying put)'
)
}