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

smooth-value

v1.1.0

Published

Create smooth, spring-based animated values

Readme

smooth-value

npm GitHub License: MIT

A lightweight, framework-agnostic utility for creating smooth, spring-based animated values. Perfect for parallax effects, cursor followers, sliders, color pickers, scroll-driven animations, and any scenario where you need a value to smoothly chase a moving target.

Features

  • Multi-framework support — First-class support for React, Vue, Preact, Solid, Svelte, and Lit, with more on the way.
  • Tiny & tree-shakeable — Only bundles the adapter for the framework you import.
  • FPS-aware — Automatically adjusts spring speed based on the current frame rate for consistent animation feel across devices.
  • Reduced motion respect — Honors prefers-reduced-motion: reduce out of the box, with a manual override option.
  • Single value or multi-values — Smoothly animate individual numbers, tuples, or arrays of numbers simultaneously.
  • TypeScript-first — Fully typed with generics for both number and number[] usage.

Installation

# npm
npm install smooth-value

# yarn
yarn add smooth-value

# pnpm
pnpm add smooth-value

Important: Framework-Specific Imports

This library supports multiple frontend frameworks. Always import from the framework-specific entrypoint — never from the root package:

// ✅ Correct — explicitly specifies the framework
import { useSmoothValue } from "smooth-value/react";
import { useSmoothValue } from "smooth-value/vue";
import { useSmoothValue } from "smooth-value/svelte";

// ❌ Wrong — root import is not supported
import { useSmoothValue } from "smooth-value";

Roadmap

| Framework | Status | | ---------- | ------ | | React | ✅ Supported | | Vue | ✅ Supported | | Preact | ✅ Supported | | Solid | ✅ Supported | | Svelte | ✅ Supported | | Lit | ✅ Supported | | Angular | 🚧 In progress | | Qwik | 🚧 In progress | | Ember | 🚧 In progress | | Marko | 🚧 In progress |

Usage

Parameters

The useSmoothValue hook function accepts the following arguments (the exact type signature varies slightly per framework — see the examples below):

| Parameter | Type | Required | Default | Description | | ----------- | --------------------------------- | -------- | ------- | ----------- | | current | Varies by framework (see below) | Yes | — | The target value to smoothly animate toward. Accepts number or number[]. | | spring | number | No | 0.5 | Smooth speed factor in the range (0, 1]. Higher values are snappier; lower values are smoother. | | options | SmoothValueOptions<T> | No | {} | Configuration object (see below). |

The spring parameter value must be within (0, 1]. A RangeError is thrown otherwise.

SmoothValueOptions<T>

| Option | Type | Default | Description | | --------------- | ---------------------------------------- | ------------ | ----------- | | disabled | boolean | false | Force-disable smooth animation. When true, the value snaps immediately to the target. | | onChange | (current: T, previous: T) => void | undefined | Called every time the smooth value updates. | | onStopChange | (current: T, previous: T) => void | undefined | Called when the smooth value settles at the target. |

React

import { useState } from "react";
import { useSmoothValue } from "smooth-value/react";

function MouseFollower() {
  const [target, setTarget] = useState([0, 0]);

  const smooth = useSmoothValue(target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });

  return (
    <div onMouseMove={e => setTarget([e.clientX, e.clientY])}>
      <div style={{ translate: `${smooth[0]}px ${smooth[1]}px` }} />
    </div>
  );
}

In React, current is a plain state value (T), and the return value is the smooth state directly (T).

Vue

<script setup lang="ts">
  import { ref } from "vue";
  import { useSmoothValue } from "smooth-value/vue";

  const target = ref([0, 0]);

  const smooth = useSmoothValue(target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });
</script>

<template>
  <div @mousemove="e => target = [e.clientX, e.clientY]">
    <div :style="{ translate: `${smooth[0]}px ${smooth[1]}px` }" />
  </div>
</template>

In Vue, current accepts a MaybeRef<T> (a ref, computed, getter, or plain value), and the return value is a ComputedRef<T> (a readonly ref). Access .value inside <script>; template unwrapping is automatic.

Preact

import { useState } from "preact/hooks";
import { useSmoothValue } from "smooth-value/preact";

function MouseFollower() {
  const [target, setTarget] = useState([0, 0]);

  const smooth = useSmoothValue(target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });

  return (
    <div onMouseMove={e => setTarget([e.clientX, e.clientY])}>
      <div style={{ translate: `${smooth[0]}px ${smooth[1]}px` }} />
    </div>
  );
}

In Preact, current is a plain state value (T), and the return value is the smooth state directly (T). The API is identical to React.

Solid

import { createSignal } from "solid-js";
import { useSmoothValue } from "smooth-value/solid";

function MouseFollower() {
  const [target, setTarget] = createSignal([0, 0]);

  const smooth = useSmoothValue(target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });

  return (
    <div onMouseMove={e => setTarget([e.clientX, e.clientY])}>
      <div style={{ translate: `${smooth()[0]}px ${smooth()[1]}px` }} />
    </div>
  );
}

In Solid, current is an Accessor<T> (a getter function), and the return value is also an Accessor<T>. Call it (smooth()) to read the value.

Svelte

<script lang="ts">
  import { useSmoothValue } from "smooth-value/svelte";

  let target = $state(0);

  const getSmooth = useSmoothValue(() => target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });
</script>

<div onmousemove={e => target = [e.clientX, e.clientY]}>
  <div style="translate: {getSmooth()[0]}px {getSmooth()[1]}px" />
</div>

In Svelte, current is a getter function (() => T), and the return value is also a getter function (() => T). Call it as getSmooth() to read the value.

Note: The Svelte adapter uses Svelte 5's $state rune internally and requires Svelte 5+.

Lit

import { LitElement, html } from "lit";
import { useSmoothValue } from "smooth-value/lit";

class MouseFollower extends LitElement {
  private _target = 0;

  private _smooth = useSmoothValue(this, () => this._target, 0.3, {
    onChange: (cur, prev) => console.log(`Moving: ${prev} → ${cur}`),
    onStopChange: (cur, prev) => console.log(`Settled at ${cur}`),
  });

  render() {
    return html`
      <div @mousemove=${(e: MouseEvent) => this._target = [e.clientX, e.clientY]}>
        <div style="translate: ${this._smooth.value[0]}px ${this._smooth.value[1]}px"></div>
      </div>
    `;
  }
}

In Lit, useSmoothValue takes an extra first argument: the ReactiveControllerHost (your element instance, typically this). The second argument, current, is a getter function (() => T). The return value is a SmoothValueController whose .value property holds the current smooth value.

Advanced: Framework-Agnostic Core

The package smooth-value/framework-agnostic exports the underlying createSmoothValue function and the SmoothValueAdapter interface. This is intended for building adapters for frameworks not yet officially supported. Most users should use a framework-specific entrypoint instead.

Each framework package also exports a getSpringByFps utility for manual spring calculations at varying frame rates — this is an advanced API and not needed for typical usage.

How It Works

smooth-value uses requestAnimationFrame to continuously interpolate between the current smooth value and the target value using a spring formula. On each frame, it moves a fraction (spring speed) of the remaining distance toward the target, creating a natural deceleration curve. The spring speed is automatically adjusted based on the monitor's actual frame rate so the animation feels consistent whether you're at 60 Hz, 120 Hz, or higher.

When prefers-reduced-motion: reduce is detected (or the disabled option is set), the value snaps immediately to the target without any interpolation.

References

License

MIT