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

@sarmal/react

v0.6.1

Published

React wrapper for @sarmal/core

Readme

@sarmal/react


@sarmal/react gives you a <Sarmal> component and a useSarmal hook so you can drop parametric curve animations into React apps without the canvas wiring. SVG output is also supported with <SarmalSVG> and useSarmalSVG.

Install

npm install @sarmal/react @sarmal/core

Quick Start

import { Sarmal } from "@sarmal/react";
import { rose3 } from "@sarmal/core";

export function Loader() {
  return <Sarmal curve={rose3} width={200} height={200} />;
}

That's it. The canvas is created, the animation starts, and everything is cleaned up when the component unmounts.

Canvas sizing

The canvas buffer dimensions must match the display size, otherwise the sarmal will distorted. Pass width and height props directly, or wrap the component in a container with explicit dimensions:

// Pass dimensions directly
<Sarmal curve={rose5} width={200} height={200} />

// Or provide a sized parent
<div style={{ width: 200, height: 200 }}>
  <Sarmal curve={rose5} />
</div>

Important: The parent container must have an explicit height. height: auto will result in clientHeight = 0 and a 300x300 fallback canvas with a console warning. width and height are set during initialization, so changing them after mount destroys and recreates the instance (trail resets).

Changing the curve

Pass a different curve prop and the component will morph to it smoothly. Control the duration with morphDuration (ms):

const [curve, setCurve] = useState(rose3);

<Sarmal curve={curve} morphDuration={600} width={200} height={200} />;

Styling

<Sarmal
  curve={rose5}
  trailColor="#00ffaa"
  skeletonColor="transparent"
  headColor="#ffffff"
  trailStyle="gradient-animated"
  trailWidth={1.5}
  width={200}
  height={200}
/>

trailColor accepts a single hex string or an array for gradients:

trailColor={["#ff0080", "#7928ca", "#0070f3"]}

Props

See sarmal.art/docs/api for the full props reference.

SVG output

The <SarmalSVG> component and useSarmalSVG hook render to SVG instead of canvas. The API mirrors <Sarmal> and useSarmal, with these differences:

  • SVG elements scale naturally with CSS, so no width/height sizing props needed. A viewBox="0 0 100 100" is set automatically.
  • className and style apply to the <svg> element.
  • trailLength and headRadius are still available as init-time props.

<SarmalSVG> component

import { SarmalSVG } from "@sarmal/react";
import { rose3 } from "@sarmal/core";

export function Loader() {
  return <SarmalSVG curve={rose3} style={{ width: 200, height: 200 }} />;
}

useSarmalSVG hook

import { useSarmalSVG } from "@sarmal/react";
import { rose5 } from "@sarmal/core";

function MyComponent() {
  const { svgRef, instance } = useSarmalSVG(rose5);

  return (
    <>
      <svg ref={svgRef} />
      <button onClick={() => instance.current?.pause()}>Pause</button>
      <button onClick={() => instance.current?.play()}>Play</button>
    </>
  );
}

The hook returns:

  • svgRef: attach this to your <svg> element
  • instance: a ref to the live SarmalInstance

useSarmal hook

If you need direct access to the SarmalInstance (to call play, pause, seek, etc.), use the hook:

import { useSarmal } from "@sarmal/react";
import { rose5 } from "@sarmal/core";

function MyComponent() {
  const { canvasRef, instance } = useSarmal(rose5, undefined, { width: 200, height: 200 });

  return (
    <>
      <canvas ref={canvasRef} />
      <button onClick={() => instance.current?.pause()}>Pause</button>
      <button onClick={() => instance.current?.play()}>Play</button>
    </>
  );
}

The hook returns:

  • canvasRef: attach this to your <canvas> element
  • instance: a ref to the live SarmalInstance

Documentation

Full API reference and examples are at sarmal.art/docs

License

MIT © Alper Halil

Links