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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fluid.js

v0.1.0

Published

A lightweight, zero-dependency fluid simulation for web backgrounds that reacts to device motion.

Readme

🌊 fluid.js

A tiny (<4KB), zero-dependency fluid simulation for the web that reacts to device motion.

npm version License: MIT

Most fluid simulations are heavy particle engines (100KB+). fluid.js is different. It uses a 2D spring-mass system coupled with inertial angular physics to simulate the feeling of liquid in a container.

It is designed for UI Backgrounds, Loading States, and Interactive Cards.

✨ Features

  • Micro-Library: < 4KB (minified + gzipped).
  • Device Ready: Reacts to Gyroscope/Accelerometer (Mobile) and Mouse/Slider (PC).
  • Inertial Physics: Simulates "Slosh", momentum, and wall climbing (U-Shape).
  • Zero Dependencies: Pure Vanilla JS. Works with React, Vue, Svelte, or plain HTML.

🚀 Installation

npm install fluid.js
# (Or whatever name you successfully publish)

💻 Usage

Vanilla JS / HTML

<canvas id="my-fluid-canvas"></canvas>

<script type="module">
  import { Fluid } from 'fluid.js';

  const fluid = new Fluid('#my-fluid-canvas', {
    color: '#00aaff', // Hex color
    tension: 0.01,    // Surface tension
    dampening: 0.02   // Ripple decay
  });

  // Set initial fill level (0 to 100)
  fluid.setFill(50);
</script>

React / Vue

import { useEffect, useRef } from 'react';
import { Fluid } from 'fluid.js';

export default function LiquidCard() {
  const canvasRef = useRef(null);

  useEffect(() => {
    const myFluid = new Fluid(canvasRef.current, {
      color: '#ff4444'
    });
    myFluid.setFill(60);
  }, []);

  return <canvas ref={canvasRef} style={{ width: '100%', height: '100%' }} />;
}

⚙️ Configuration

You can tune the liquid to feel like Water, Oil, or Jelly.

| Option | Default | Description | | :--- | :--- | :--- | | color | #3b82f6 | The hex color of the liquid. | | tension | 0.01 | Surface stiffness. Lower = more waves. | | dampening | 0.02 | Friction. Lower = waves last longer. | | spread | 0.25 | How fast ripples travel across the surface. | | inertia | 0.96 | Momentum conservation. Higher = more slosh. | | wallClimb | 2.5 | How high fluid climbs walls during rotation. |

Presets

If you don't want to tune physics manually, copy these values:

Water (Default)

{ tension: 0.01, dampening: 0.02, inertia: 0.96 }

Oil / Honey

{ tension: 0.03, dampening: 0.1, inertia: 0.90 }

Slime / Jelly

{ tension: 0.08, dampening: 0.05, inertia: 0.80 }

⚠️ Mobile Permissions (iOS)

On iOS 13+, you must request permission to access the Gyroscope. The browser will not let you access sensors automatically. You must trigger this from a button click (e.g., "Enable Gravity").

// Run this inside a button click handler
if (typeof DeviceMotionEvent.requestPermission === 'function') {
    DeviceMotionEvent.requestPermission()
        .then(response => {
            if (response === 'granted') {
                // Sensors are now active, fluid.js will auto-detect them
            }
        })
        .catch(console.error);
}

📄 License

MIT

{ github.com/mgks }