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

@velvetkevorkian/sketch-ui

v0.0.5

Published

Generate a UI for your creative coding sketches with minimal configuration.

Readme

sketch-ui

Warning: extremely early version. Breaking changes will happen.

Generate a UI for tweaking the variables in your creative coding sketches with minimal configuration, using standard HTML inputs.

Designed for use with p5.js but not bound to any library or framework.

Installation

The examples currently assume you're using Webpack to build your JS and CSS.

Add it to your project:

npm install @velvetkevorkian/sketch-ui

Usage

import UI from '@velvetkevorkian/sketch-ui'
import '@velvetkevorkian/sketch-ui/src/ui.css'

// declare our variables object.
const vars = {
  myVariable: {
    value: 50
  }
}

// create a new UI instance and pass the variables object to it
const ui = new UI(vars).proxy

function loop() {
  // vars.myVariable.value is proxied to ui.myVariable
  console.log(ui.myVariable)
  // keep the loop going
  window.requestAnimationFrame(loop)
}

// start the requestAnimationFrame loop
window.requestAnimationFrame(loop)

Drag the slider and watch the values update in real time.

Setting a value works the same way.

  ui.myVariable = 200
  console.log(ui.myVariable) // 200

By default a number using a range input has a range of 0-255. Trying to set a variable outside that range will see it clamped to 0 or 255. Let's look at how we can configure the options.

Configuration

The script will try to infer the type of variable you're using, and generate a suitable input with sensible defaults:

  • 7 character hex codes, e.g. #ff0000, generates a color input.
  • numbers generates a range input with min=0, max=255, and step=1
  • a boolean value generates a checkbox input
  • an array generates a select field with each item in the array an option
  • anything else will default to a standard text input

You can pass additional options to override any of these defaults. For example:


const vars = {
  // use a `number` input instead of `range`
  num: {
    value: 50,
    type: 'number'
  },
  // override the step and max values
  bigNum: {
    value: 100,
    max: 1000,
    step: 10
  }
}

The script will validate min and max values for setters as well as via the UI, which is why myVariable maxes out at 255 in the click example above.

You can also set a custom label value if you don't want to use the plain variable name.

const vars = {
  backgroundColor: {
    value: '#0f0f0f',
    label: 'Background Color'
  }
}

Any other options you pass will be applied directly to the input, for example:

const vars = {
  myVariable: {
    value: 'some text',
    foo: 'bar'
  }
}

will result in

<input id='myVariable' type='text' value='some text' foo='bar'>

Buttons

Setting type: 'button' will create a <button> element with the text of the label as its text. Let's look at how we can make the button do something when you press it using a callback.

Callbacks

Each input can be passed a callback to run when the value is changed.

const vars = {
  blendMode: {
    value: ['ADD', 'BLEND'],
    label: 'Blend Mode',
    callback: (val) => {
      console.log(val)
    }
  }
}

When creating your UI you can pass an additional context parameter which will be available to the callback. This can be useful if you need to access properties of other objects. For example, this will call a method on our p5.js instance.

const vars = {
  loop: {
    value: true,
    callback: (val, p) => {
      val == true ? p.loop() : p.noLoop()
    }
  }
}

new p5(p => {
  p.setup = () => {
    const ui = new UI(variables, p).proxy
  }
})

You can also do something when a button is pressed. The button has no value but can still access the context if available.

const vars = {
  myButton: {
      type: 'button',
      label: 'Click me',
      callback() {
        console.log('button clicked!')
      }
    }
  }

To Do

  • [ ] drag handle should be clearer and shouldn't scroll away
  • [ ] make clearing saved state a function that can be called externally not hard-coded in
  • [ ] document with gifs
  • [ ] document multiple instances and new options
  • [ ] fieldsets
  • [ ] use with script tag only
  • [ ] worked examples
  • [ ] theming/styling
  • [ ] transpile/minify?
  • [ ] less flaky jsdom setup
  • [ ] show/hide options?
  • [ ] can callbacks reference the parent UI element?
  • [ ] url encoding?
  • [ ] load/save presets?