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

soft-magnet

v0.1.0

Published

A subtle magnetic hover effect: elements lean toward the cursor and grow a little, with spring motion. No dependencies, React hook included.

Downloads

391

Readme

soft-magnet

A subtle magnetic hover effect. When the cursor comes near, an element leans toward it a few pixels and grows a little, with spring motion. It's meant to be felt more than seen.

Live demo · made for flowgraphs.app

  • No dependencies, about 2.5 kB gzipped. Plain DOM API plus an optional React hook.
  • Same feel at any refresh rate. The spring steps at a fixed 60 Hz and blends between steps, so it isn't faster on 120 or 144 Hz screens.
  • Doesn't chase itself. Distance is measured from where the element sits at rest, not where it has leaned to, so it never creeps after the cursor.
  • One listener for everything. Any number of elements share one pointermove listener and one animation frame loop, which stops when everything is still.
  • Polite. Off on touch screens and when the visitor prefers reduced motion.
  • Keeps your transforms. It moves the element with the translate and scale CSS properties, so the element's own transform keeps working.

Install

npm install soft-magnet

Use

import { magnet } from "soft-magnet";

const m = magnet(document.querySelector("button"));

m.update({ strength: 0.5 }); // change options while it runs
m.destroy(); // stop and put the element back

React

import { useRef } from "react";
import { useMagnet } from "soft-magnet/react";

function MagnetButton() {
  const ref = useRef<HTMLButtonElement>(null);
  useMagnet(ref, { strength: 0.5 });
  return <button ref={ref}>Hello</button>;
}

The hook file starts with "use client", so it works from Next.js App Router client components.

Options

| Option | Default | Meaning | | ---------- | ------- | -------------------------------------------------------------------- | | range | 120 | How far from the element's edge (px) the cursor starts pulling it. | | pull | 7 | The most it moves toward the cursor (px). | | grow | 0.1 | How much it grows at most (0.1 = 10%). | | strength | 1 | Multiplies pull and grow. 0.5 is half as strong, 0 is off. |

The pull fades out toward the edge of the range, so nothing jumps when the cursor crosses it.

Tip: add will-change: translate, scale; to the element's CSS for smoother motion.

Building your own

The two pieces inside magnet() are exported too, for when you run your own animation loop (for example many nodes on a canvas, or things that live in a zoomed coordinate space):

import { createSpring, magnetPose, STEP_MS } from "soft-magnet";

const spring = createSpring();

// When the cursor moves: dx, dy = cursor minus the element's resting center.
spring.setTarget(magnetPose(dx, dy, { range: 120 }));

// Every animation frame:
const moving = spring.advance(elapsedMs); // false once it has settled
el.style.translate = `${spring.x}px ${spring.y}px`;
el.style.scale = String(spring.scale);

magnetPose(dx, dy, options, radius) returns { x, y, scale }; radius adds the element's own size to the range. spring.snap() jumps straight to the target (useful under reduced motion). STEP_MS is the length of one spring step: pass it as the elapsed time of the first frame.

Notes

  • Works with the default transform-origin (center). If an ancestor is scaled, distances are measured on screen, so the effect is scaled with it.
  • The demo runs locally with npm run demo.

License

MIT