npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

normalized-mouse-position

v1.0.0

Published

Convert mouse coordinates to normalized values relative to any origin point for smooth UI interactions and animations.

Readme

normalized-mouse-position

Convert mouse coordinates to normalized values relative to any origin point for smooth UI interactions and animations.

npm version npm downloads npm dependents github stars github license

Installation

npm i normalized-mouse-position
pnpm add normalized-mouse-position

Quick Start

import { getNormalizedMousePosition } from 'normalized-mouse-position';

// Basic usage - mouse position relative to center
const pos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    origin: "50% 50%" // center origin
});
// Result: {x: 0.3, y: -0.8, origin: {x: 0.5, y: 0.5}, size: {width: 800, height: 600}}

Key Features

  • 🎯 Configurable Origin - Use any point as reference: center, corners, or custom positions
  • 📏 Normalized Output - Always get predictable [-1, 1] range (or beyond if unclamped)
  • 🔄 Axis Inversion - Perfect for 3D controls and mirror effects
  • 🎨 Multiple Targets - Works with window or any DOM element
  • 📦 TypeScript Ready - Full type safety with comprehensive JSDoc

Examples

Different Origin Points

// Center origin (default)
const centerPos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    origin: "50% 50%"
});

// Top-left origin  
const topLeftPos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    origin: "0 0"
});

// Custom origin
const customPos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    origin: "25% 75%"
});

Target Specific Elements

const elementPos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    target: document.querySelector('.my-element'),
    origin: "50% 50%"
});

3D-Style Controls

const controlPos = getNormalizedMousePosition({
    x: mouseEvent.clientX,
    y: mouseEvent.clientY,
    origin: "50% 50%",
    invertY: true, // Mouse up = positive Y (like 3D coordinates)
    clamp: false   // Allow values beyond [-1, 1]
});

GSAP Observer Integration

import { gsap } from "gsap";
import { Observer } from "gsap/Observer";
import { getNormalizedMousePosition } from 'normalized-mouse-position';

function gsapMouseParallaxImage() {
    gsap.registerPlugin(Observer);

    document.querySelectorAll('[data-mouse-parallax-parent]').forEach(parentTarget => {
        const childTarget = parentTarget.querySelector('[data-mouse-parallax-target]');
        if (!childTarget) return;

        Observer.create({
            target: parentTarget,
            type: "pointer",
            onMove: ({x, y, target}) => {
                const pos = getNormalizedMousePosition({x, y, target});
                const parallaxIntensity = -20; // Negative for opposite direction

                gsap.to(childTarget, {
                    force3D: true,
                    x: pos.x * parallaxIntensity,
                    y: pos.y * parallaxIntensity,
                    duration: 1,
                    ease: "power1.out"
                });
            }
        });
    });
}

Parallax Effects

// Mouse parallax with GSAP
document.addEventListener('mousemove', (e) => {
    const pos = getNormalizedMousePosition({
        x: e.clientX,
        y: e.clientY,
        origin: "50% 50%"
    });
    
    gsap.to('.parallax-element', {
        x: pos.x * 50,
        y: pos.y * 50,
        duration: 0.3
    });
});

API

getNormalizedMousePosition(options)

Parameters:

  • x: number - Mouse X coordinate
  • y: number - Mouse Y coordinate
  • origin?: string - Origin point as "x% y%" (default: "50% 50%")
  • target?: Window | Element - Reference element (default: window)
  • clamp?: boolean - Limit to [-1, 1] range (default: true)
  • invertX?: boolean - Invert X axis (default: false)
  • invertY?: boolean - Invert Y axis (default: false)

Returns:

{
    x: number;        // Normalized X coordinate
    y: number;        // Normalized Y coordinate  
    origin: {         // Origin as decimal values
        x: number;
        y: number;
    };
    size: {           // Target dimensions
        width: number;
        height: number;
    };
}

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Build the package
pnpm run build

# Run tests in watch mode
pnpm run test:watch

License

MIT © phucbm