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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mouser.js

v0.2.6

Published

A Javascript helper for mouseover animations

Downloads

18

Readme

Mouser.js · GitHub license npm version CI PRs Welcome

Mouser.js is a Javascript helper for mouse move animations. Import the function, pass a list of listeners, and they will recieve a vector with the current mouse position ranging from 0 to 1 relative to the reference, and the global position (gx and gy). {x: 0.23, y: 0.7, gx: 235, gy: 367}

  • Zero-Dependencies: With a size of ~18kb (unpacked).
  • Minimal: Mouser.js just registers the listeners and pass the vector to them. What you do with those values is totally up to you.
  • Use Anywhere: Mouser.js doesn't make assumptions about your technology stack, so you can use mouser.js wherever you want.

Installation

Mouser.js has been designed for minimal and efficient usage. To avoid memory leaking and ensure efficiency, Mouser.js works as a singleton. It will only return a new object, only if the params field is used, otherwise it will return the same instance. Users are in charge of clearing the events with the removeEventListeners method. (See example below).

You can use Mouser.js as a <script> tag from a CDN (TO-DO), or as a mouser.js package on npm:

npm install --save mouser.js
import mouser from 'mouser.js'

// your code

Examples

Here is the first example to get you started:

import mouser from 'mouser.js'

const domElement = document.querySelector('#id')

mouser({
  reference: domElement, // optional, defaults to window
  listeners: [console.log]
})

This example will print the vector {x: number, y: number, gx: number, gy: number} to the console whenever the effect is triggered. You'll notice that we used a simple console.log method, but you can pass to the listener any synchronous function...

Using it with React

import React, { useState } from 'react';
import mouser from 'mouser.js';

function Example() {
  const [v, setV] = useState({x: 0, y: 0}); // you can pass any rest state

  useEffect(() => {
    mouser({
      listeners: [setV]
    });
    return () => mouser.removeEventListeners(); // clear all registered events
  }, [setV]);

  return (
    <div>
      <p>x: {v.x} - y: {v.y}</p>
      <p>global x: {v.gx} - global y: {v.gy}</p>
    </div>
  );
}

API

Params

Optional object the you can pass when calling the mouser.js function

import mouser from 'mouser.js';

const helper = mouser({
    // element from which the range values will be applied
    reference: Document | Window | HTMLElement // defaults to window

    // array of functions that accepts the x,y vector
    listeners: ((v: {x: number, y: number}) => void)[] // defaults to []

    // rate to apply the update of the returned vector
    refreshRate: number // defaults to 0

    // value that will be returned ONCE when mouse is out the reference
    restState: { x: number, y: number } // defaults to {x: 0, y: 0}
})

Methods

import mouser from 'mouser.js';

const helper = mouser();

// replaces the current reference
helper.addReference(el: Document | Window | HTMLElement);

// sets the reference to the default (window)
helper.removeReference();

// adds a listener to the current array of listeners
helper.addListener(listener: (v: {x: number, y: number}) => void);

// IMPORTANT clears all event listeners to avoid memory leaks
helper.removeEventListeners();

Rest State Behaviour

While you can provide a rest state to the values relative to the reference, the global values, when effect is not active it will maintain the last recorded position.

NOTE: as we are still in alpha, the restState parameter behaviour might change in the feature

Showcase

Articles

PRs welcome!

Contributing

The main purpose of this repository is to continue evolving Mouser.js, making it faster and easier to use. Development of Mouser.js happens in the open on GitHub, and I am are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving Mouser.js.

Contributing Guide

Just send a PR or report an issue and I will be happy to review.

"Buy Me A Coffee"

Good First Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started.

License

Mouser.js is MIT licensed.

Stadistics

Note

This project has been heavily inspired by the Webflow approach to mouse move animations.