Skip to content

feat: add useMousePosition utility#406

Open
hugentobler wants to merge 1 commit intosvecosystem:mainfrom
hugentobler:feat/use-mouse-position
Open

feat: add useMousePosition utility#406
hugentobler wants to merge 1 commit intosvecosystem:mainfrom
hugentobler:feat/use-mouse-position

Conversation

@hugentobler
Copy link

Add useMousePosition — a reactive utility that tracks cursor position in viewport coordinates and optionally relative to a target element. Follows the onClickOutside pattern with start()/stop()/enabled listener control.

PR Checklist

  • Code is formatted and linted (pnpm lint, pnpm format)

    • pnpm format — all files unchanged (clean)
    • pnpm lint — 0 errors, 0 warnings
  • Types pass (pnpm check)

    • svelte-check — 0 errors, 0 warnings across both packages
  • Tests pass locally (pnpm test)

    • 13 unit tests passing across 3 test groups:
      • Global position tracking (3 tests)
      • Element-relative position with negative/overflow values (6 tests)
      • Start/stop listener control with immediate option (4 tests)
  • Docs updated (content + demo)

    • Docs page with Basic Usage, Advanced Usage (out-of-bounds tracking, controlled listener), Options, and Type Definitions
    • Interactive demo with element label, coordinate display, inside status, enabled status, and start/stop buttons

Files Added

  • packages/runed/src/lib/utilities/use-mouse-position/use-mouse-position.svelte.ts — implementation
  • packages/runed/src/lib/utilities/use-mouse-position/index.ts — barrel export
  • packages/runed/src/lib/utilities/use-mouse-position/use-mouse-position.test.svelte.ts — unit tests
  • sites/docs/src/content/utilities/use-mouse-position.md — docs page
  • sites/docs/src/lib/components/demos/use-mouse-position.svelte — demo component

Files Modified

  • packages/runed/src/lib/utilities/index.ts — added use-mouse-position export

🤖 Generated with Claude Code

Reactive cursor position tracking in viewport coordinates and relative
to an optional target element. Follows the onClickOutside pattern with
start()/stop()/enabled listener control.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2026

⚠️ No Changeset found

Latest commit: 6b4194e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hugentobler
Copy link
Author

Thanks for reviewing. Added a new utility for my own usecase inspired by similar React hooks. Has an 'advanced' out-of-bounds usecase that composes nicely with other runed utilities.

Screenshot 2026-02-24 at 11 31 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant