bndr-js
v0.18.0
Published
A monadic library for composing and filtering various types of user inputs to generate event handling
Downloads
26
Readme
Doc ⌇ Sandbox ⌇ API ⌇ Become a Sponsor
Bndr /ˈbaɪndɚ/ is a library designed to compose events from various user inputs and chain filters in a monadic manner, integrating them into a single event object. It accommodates input devices such as mice🖱️, styluses🖊️, touch inputs👆, keyboards⌨️, MIDI controllers🎹, and gamepads🎮. Developed and maintained by Baku Hashimoto.
Potential use cases for this library include:
- ⚡️ Associating user inputs with arbitrary triggers for VJing
- 🎨 Introducing manual operations in generative art.
To get a feel for how it works, please try out this demo.
Supported Parameters
- 👆 Pointer (mouse, stylus, touch)
- All parameters supported in PointerEvent. (pressure, tilt, multi-touch)
- ⌨️ Keyboard
- 🎹 MIDI
- CC and velocity
- 🎮 Gamepad
- Vendor-specific button name support: JoyCon, PS5 Controller
How to use
Installation
npm install bndr-js
Example
import {Bndr} from 'bndr-js'
Bndr.pointer().on(pressed =>
console.log('Pointer %s', pressed ? 'pressed' : 'released')
)
Bndr.pointer()
.position()
.lerp(vec2.lerp, 0.1)
.on(([x, y]) => console.log('Pointer moved: [%f, %f]', x, y))
Bndr.keyboard()
.hotkey('shift+c')
.on(() => console.log('Hotkey shift+c pressed'))
Bndr.keyboard()
.key('a')
.on(pressed => console.log(`Key 'a' ${pressed ? 'pressed' : 'released'}`))
Bndr.midi()
.note(0, 50)
.on(velocity => console.log('MIDI slider #50 moved: %d', velocity))
Bndr.gamepad()
.axis(0)
.on(([x, y]) => console.log('Gamepad axis #0 tilted: [%f, %f]', x, y))
License
This repository is published under an MIT License. See the included LICENSE file.