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

easy-mesh-gradient

v0.0.5

Published

![Frame 2 (2)](https://user-images.githubusercontent.com/3497863/210480494-fe5c3edf-5684-4881-8295-ea702e66e33e.png)

Downloads

192

Readme

Easy Mesh Gradient

Frame 2 (2)

Installation

To install, use npm:

npm install easy-mesh-gradient

or yarn:

yarn add easy-mesh-gradient

Usage

import easyMeshGradient from "easy-mesh-gradient";

const gradientString = easyMeshGradient();

document.body.style.backgroundImage = `${gradientString}`;

Options

The easyMeshGradient function accepts an optional options object with the following properties:

points

An array of points that define the mesh gradient. Each point should have the following properties:

  • x: The x coordinate of the point as a decimal between 0 and 1.
  • y: The y coordinate of the point as a decimal between 0 and 1.
  • h: The hue of the point as a number between 0 and 360.
  • s: The saturation of the point as a decimal between 0 and 1.
  • l: The lightness of the point as a decimal between 0 and 1.
  • scale: A number representing the size of the gradient fade around the point.

If the points option is not specified, the library will generate points using the pointsGenerator function (see below).

easing

A function that defines the easing of the gradient transitions between points. This function should accept a number between 0 and 1 and return a number between 0 and 1. The default easing function is easeInOutCubic.

easingStops

The number of intermediate colors to use in the gradient transitions between points. The default value is 10.

seed

A string that is used to seed the random number generator when generating points. This allows the generated points to be reproducible.

pointCount

The number of points to generate when using the pointsGenerator function. The default value is 5.

scaleRange

A 2-element array that defines the minimum and maximum allowed values for the scale property of generated points. The default value is [0.5, 2].

hueRange

A 2-element array that defines the minimum and maximum allowed values for the h property of generated points. The default value is [0, 360].

saturationRange

A 2-element array that defines the minimum and maximum allowed values for the s property of generated points. The default value is [0.5, 1].

lightnessRange

A 2-element array that defines the minimum and maximum allowed values for the l property of generated points. The default value is [0.5, 1].

pointsGenerator

A function that generates an array of points when the points option is not specified. This function should accept an options object with the same properties as the main easyMeshGradient function, and return an array of points with the same structure as described above for the points option. The default pointsGenerator function is provided by the library.

Example

import easyMeshGradient from "easy-mesh-gradient";

const gradientString = easyMeshGradient({
  points: [
    { x: 0.1, y: 0.1, h: 120, s: 0.8, l: 0.6, scale: 1 },
    { x: 0.5, y: 0.5, h: 60, s: 0.7, l: 0.5, scale: 1.5 },
    { x: 0.9, y: 0.9, h: 300, s: 0.6, l: 0.4, scale: 1 },
  ],
  easingStops: 20,
});

document.body.style.backgroundImage = `${gradientString}`;

This will generate a mesh gradient with 3 points, using 20 intermediate colors in the gradient transitions and the default easing function. The resulting gradient will be applied as the background-image of the document.body element.

License

MIT

(documentation co-authored by chatGPT 😄)