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

tweakpane-plugin-gradient

v0.1.5

Published

A Tweakpane plugin for editing gradients

Downloads

417

Readme

Tweakpane-plugin-gradient

cover

Tweakpane-plugin-gradient is a plugin for Tweakpane that introduces a gradient picker as a new blade type, allowing users to create, visualize, and manage color gradients with ease.

DEMO

Installation

npm install tweakpane-plugin-gradient

Usage

To use the gradient blade in your Tweakpane instance, register the plugin and set up the gradient parameters:

import { Pane } from 'tweakpane';
import { 
  Gradient,
  GradientBladeApi,
  GradientPluginBundle,
  GradientBladeParams,
} from 'tweakpane-plugin-gradient';

const pane = new Pane();
pane.registerPlugin(GradientPluginBundle);

const gradientParams = {
  view: 'gradient',
  initialPoints: [ // minimum 2 points
    { time: 0, value: { r: 255, g: 0, b: 255, a: 1 } },
    { time: 1, value: { r: 0, g: 255, b: 255, a: 1 } },
  ],
  label: 'Gradient',
  colorPicker: true,
  colorPickerProps: {
    alpha: true,
    layout: 'popup',
    expanded: false,
  },
  alphaPicker: false,
  timePicker: false,
  timeStep: 0.001,
  timeDecimalPrecision: 4,
} satisfies GradientBladeParams;

const api = pane.addBlade(gradientParams) as GradientBladeApi;

api.on('change', (ev) => {
  console.log(ev.value.points);
  console.log(ev.value.points[0].time);
  console.log(ev.value.points[0].value.r);
  console.log(ev.value.points[0].value.g);
  console.log(ev.value.points[0].value.b);
  console.log(ev.value.points[0].value.a);
  console.log(ev.value.toCssGradient());
});

Parameters

The following parameters allow you to customize the gradient picker to suit various needs.

Base parameters

  • view (string): Set to 'gradient' to initialize a gradient blade.
  • initialPoints: Array of points defining the gradient colors and positions (minimum 2 points).
    • time (number): Position of the color stop in the gradient (0 to 1).
    • value (number): Object defining the RGBA color value (color 0-255, alpha 0-1).
  • label (string): Sets the label displayed in Tweakpane for the gradient field.
  • timeStep (number): Sets the increment for adjusting time values.
  • timeDecimalPrecision (number): Defines the decimal precision for time adjustments

Color picker parameters

  • colorPicker (boolean): Enables or disables the color picker for each gradient point.
  • colorPickerProps (object): Additional configuration for the color picker.
    • alpha (boolean): Enables alpha transparency in the color picker.
    • layout ('inline' | 'popup'): Configures color picker layout, either as an inline or popup.
    • expanded (boolean): Sets whether the color picker is expanded by default in popup mode.

Time picker parameters

  • timePicker (boolean): Adds a control to adjust the time value for each color point, allowing precise placement.

Alpha picker parameters

  • alphaPicker (boolean): Enables an additional control to adjust alpha values independently.

Gradient object

Events

Listen for changes to the gradient to dynamically update the background or other UI elements:

gradientApi.on('change', (event) => {
  document.body.style.background = event.value.toCssGradient();
});