gooey.braebo.dev
Gooey is designed for creating interactive control panels that work seamlessly in both development and production environments. Use it for creative coding, data visualization, interactive art, educational demos, WebGL experiments, and any web experience where users need real-time parameter control.
- Features
- Getting Started
- 1. Install
- 2. Create a new
Gooey
- Basics
- Inputs
add vs bind
add
addMany
bind
- In an app
- About
- Roadmap
Features
Preset Manager · Theme Manager · Draggable / Resizable / Placeable · Local Storage Integration · Generators · Per-Input Reset · Undo/Redo History · Flexible API · Fully Typed · One Dependency (esm-env)
Getting Started
1. Install
npm install gooey
import { Gooey } from 'gooey'
JSR is a modern alternative to NPM
npx jsr add @braebo/gooey
import { Gooey } from '@braebo/gooey'
PNPM is the recommended way to install gooey.
pnpm i -D gooey
import { Gooey } from 'gooey'
<script type="module">
import { Gooey } from 'https://esm.sh/gooey'
const gui = new Gooey()
</script>
2. Create a new Gooey
const gui = new Gooey()
Basics
Use add to create a new input
gooey.add('hello', 'world')
gooey.add('count', 1, { min: -1 })
Use addMany to create multiple inputs at once:
gooey.addMany({
stuff: true,
more_stuff: {
like_colors: '#4aa7ff',
or_buttons: () => alert('thanks!'),
},
})
Do stuff on change:
const greetingInput = gooey.add('greeting', 'hello')
greetingInput.on('change', console.log) // logs the text value when changed
The onChange option can also be used to set a callback that will be called when the value changes:
gooey.add('title', 'change me', {
onChange: v => (gooey.title = v),
})
Or, you can chain stuff:
gooey.add('title', 'change me').on('change', v => (gooey.title = v))
Instead of using add with event callbacks, you can use bind to automatically sync an object's values with an input. For example:
const data = {
size: 12,
color: '#4aa7ff' as const,
}
gooey.bind(data, 'size')
gooey.bind(data, 'color')
Bind to an entire object with bindMany
const data = {
wght: 100,
wdth: 75,
}
gooey.bindMany(data)
Create folders with addFolder
const outer = gooey.addFolder('outer')
const inner = outer.addFolder('inner')
inner.add('say sike', () => outer.close(), {
text: 'sike',
})
Inputs
| Status |
Feature |
Primitive |
| ✅ |
Number |
number |
| ✅ |
Text |
string |
| ✅ |
Switch |
boolean |
| ✅ |
Select |
Array<any> |
| ✅ |
Button |
{ text, onClick, ... } |
| ✅ |
ButtonGrid |
{ text, onClick, ... }[][] |
| ✅ |
Color |
Color \| ColorRepresentation |
| 🏗️ |
Range |
{ min, max } |
| 🏗️ |
Vector2 |
{ x, y } |
| 🏗️ |
Vector3 |
{ x, y, z } |
add vs bind
There are two ways to create inputs; add or bind (along with addMany / bindMany for multiple inputs). The return value will be the generated Input instance.
-
add inputs when you have no data and just want to generate some values and hook into change events. The value will be created and managed by Gooey.
-
bind inputs when you have an existing object, and you want its value(s) to stay in sync with the generated input(s) automatically. This is useful for data that's integrated into a larger system, like reactive state in a web app or entities in a 3D scene graph.
add
The Folder.add method can be used to create any input.
type add = <T>(
title: string,
initialValue: T,
options?: InputOptions<T>
): Input<T>
It accepts a title, initialValue, and options object.
[!TIP]
Passing an empty string as the title will omit the title's <div> element, allowing the input to fill the entire width of the parent folder.
The type of input generated depends on the type of the initialValue argument. For example, passing a string results in an InputText instance, while passing a number results in an InputNumber instance.
gooey.add('my text', 'foo') // string -> InputText
gooey.add('my number', 1) // number -> InputNumber
Simple examples of each type of input that can be created with the add method (with empty strings in the title arguments for simplicity):
// InputText
gooey.add('', 'foo') // string
// InputNumber
gooey.add('', 1) // number
// InputColor
gooey.add('', '#4aa7ff') // ColorValue
// InputSelect
gooey.add('', ['foo', 'bar']) // any[]
// InputButton
gooey.add('', () => alert('hi')) // () => void
// InputSwitch
gooey.add('', true) // boolean
// InputButtonGrid
gooey.add('', [
[
{ text: 'foo', onClick: () => alert('foo') },
{ text: 'bar', onClick: () => alert('bar') },
],
[
{ text: 'baz', onClick: () => alert('baz') },
{ text: 'qux', onClick: () => alert('qux') },
],
]) // (() => void)[][]
The type of the options object in the third argument will change depending on the type of input, for example:
const countInput = gooey.add('count', 1, {
min: -1,
max: 10,
step: 0.1,
})
Because the initial value (1) is a number, gooey infers the options in the third argument as NumberInputOptions — which is why it accepts min, max, and step.
If we pass a string instead, it'll infer TextInputOptions:
const textInput = gooey.add('greeting', 'hello', {
maxLength: 10,
})
This should get you some nice, dynamic intellisense. However, you can always fall back to the more specific adders (like addNumber, addColor, etc.) if need be.
addMany
The Folder.addMany method can be used to create multiple inputs at once.
type addMany = <T>(
target: T,
options?: Record<keyof T, InputOptions<T>> & {
exclude?: Array<keyof T>
include?: Array<keyof T>
},
) => {
folders: Folder[];
inputs: Input<T>[];
}
It takes in any object, and generates a set of inputs based on the object's keys and values.
Nested objects will result in child folders being created.
Options can be passed to the second argument to customize the inputs being generated, and/or to include/exclude specific keys from generation.
While the simplified version of the type signature for addMany above might seem a bit complex, it's actually quite simple in practice! Let's break it down:
The addMany method takes two arguments:
target: The object to create inputs from.
options: Options to customize the inputs generated, as well as include and exclude arrays to omit certain keys.
It returns an object with two properties:
folders: The Folder made for each nested object, keyed like the target: folders.a.folder, with the folders nested in it under folders.a.subFolders.
inputs: The inputs, keyed like the target: inputs.a.b is the input for target.a.b.
Let's look at an example to see how this works in practice.
const {inputs, folders} = gooey.addMany({
myNumber: 5,
myFolder: {
myColor: '#4aa7ff',
}
})
This will result in an InputNumber, and a Folder titled myFolder containing an InputColor.
inputs.myNumber // -> InputNumber
inputs.myFolder.myColor // -> InputColor
folders.myFolder.folder // -> Folder
Suppose we want to configure the min and max options for myNumber. To do this, we can specify them in the second argument:
const { inputs, folders } = gooey.addMany({
myNumber: 5,
myFolder: {
myColor: '#4aa7ff',
}
}, {
myNumber: {
min: 0,
max: 10,
}
})
And that's it! If all goes well, you should get strong intellisense for all available options in the second argument. If you don't, please file an issue!
Sometimes, relying on inference won't be enough, and you'll need an escape-hatch to get the exact inputs you want. In that case, you can exclude a key from generation, and create it manually with a more specific adder:
const { inputs, folders } = gooey.addMany({
myNumber: 5,
myFolder: {
myColor: 'hsl(200, 100%, 50%)', // -> InputText (wrong! let's exclude it)
}
}, {
exclude: ['myColor'],
})
// ...and now we can add it manually:
gooey.addColor('myColor', 'hsl(200, 100%, 50%)', {
// and customize it a bit:
mode: 'hsl'
})
bind
type bind = <T>(
target: T,
key: keyof T,
options?: InputOptions<T>
): Input<T>
The Folder.bind method can be used to create an input that is bound to a key on a target object. When an input created with bind is changed, the target object's value for the given key will be updated automatically.
const data = {
size: 12,
color: '#4aa7ff' as const,
}
gooey.bind(data, 'size') // -> InputNumber
gooey.bind(data, 'color') // -> InputColor
A curve has no type of its own to infer — [0.4, 0, 0.2, 1] is just an array — so the bézier editor is added by name. Its value is [x1, y1, x2, y2], and it takes a 'cubic-bezier(...)' string or a CSS keyword too:
const ease = gooey.addBezier('ease', [0.16, 1, 0.3, 1])
el.style.transitionTimingFunction = bezierToString(ease.value) // 'cubic-bezier(0.16, 1, 0.3, 1)'
const eased = cubicBezier(...ease.value) // (progress) => eased progress
gooey.bindBezier({ ease: 'ease-out' }, 'ease') // a string field is written back as a string
A gradient is added by name too. Its value is { offset, color } stops sorted by offset (0..1), colours as hex — plain data that saves and serializes as-is. Drag a stop to move it, press the strip to add one, drag one off (or press Delete) to remove it; the selected stop's colour is edited with the colour picker:
const heat = gooey.addGradient('heat', [
{ offset: 0, color: '#3b82f6' },
{ offset: 0.6, color: '#eab308' },
{ offset: 1, color: '#ef4444' },
])
gooey.addGradient('sunset', ['#ff7e5f', '#feb47b', '#86a8e7']) // bare colours are spaced evenly
el.style.background = gradientToString(heat.value) // 'linear-gradient(to right, #3b82f6 0%, ...)'
const color = sampleGradient(heat.value, 0.29) // the colour 29% along, as hex
In an app
The constructor touches document.body — construct after mount, and dispose() on teardown:
onMount(() => { gui = new Gooey({ title: 'voice' }) })
onDestroy(() => gui?.dispose())
disabled and hidden take a function, re-evaluated on input.refresh() — call it on the dependents when the driver changes:
const voice = gui.addSelect('voice', 'charlotte', { options: voices })
const knob = gui.add('stability', 0.5, { disabled: () => !isEleven(voice.value) })
voice.on('change', () => knob.refresh())
input.set(v) fires change; input.refresh() re-reads the binding and emits only refresh — the path for an update you don't want echoed to your own change handler.
storage: true persists closed, theme, and presets; position and size are opt-in (storage: { position: true }); hidden is never persisted.
gui.window?.resize({ width, height }) sizes the panel from code — either dimension can be omitted, each clamps to the bounds and the root's own min-width / max-width, and the result persists like a drag on the grabber.
The select dropdown portals to <body> at z-index: 100 — a host panel at or above that hides its own open dropdowns.
If your page puts its own CSS in cascade layers, declare gooey's first — @layer gooey-reset, reset, globals; — so your button and input rules reach gooey's controls (gooey's class rules still win, being unlayered). Undeclared, gooey-reset lands after your layers and its all: revert voids them. A page without layers needs nothing.
registerWebMCP(gui) registers one WebMCP tool per input plus a <prefix>.state reader, and unregisters on dispose().
About
I built this to scratch an itch, and to pave the way for more advanced features related to WebGL / WebAudio / audio-reactive 3D in the future.
tweakpane was the main inspiration for this project. I recommend it over gooey -- it's a more lightweight solution with more features and an awesome, highly active developer!
Other, similar projects:
Roadmap
- [ ] Graph / Monitor Input
- [ ] LFO / Envelope Manager
- [x] Bezier Curve Editor Input
- [x] Gradient Stops Input
- [ ] Plugins
- [ ] Framework Wrappers (svelte 5 runes "just work", but other frameworks need wrappers)