22 |
23 | **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](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API) controllers🎹, and [gamepads](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API)🎮. Developed and maintained by [Baku Hashimoto](https://baku89.com).
24 |
25 | Potential use cases for this library include:
26 |
27 | - ⚡️ Associating user inputs with arbitrary triggers for VJing
28 | - 🎨 Introducing manual operations in generative art.
29 |
30 | To get a feel for how it works, please try out [this demo](https://baku89.github.io/bndr-js/).
31 |
32 | ## Supported Parameters
33 |
34 | - 👆 Pointer (mouse, stylus, touch)
35 | - All parameters supported in [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events). (pressure, tilt, multi-touch)
36 | - ⌨️ Keyboard
37 | - 🎹 MIDI
38 | - CC and velocity
39 | - 🎮 Gamepad
40 | - Vendor-specific button name support: JoyCon, PS5 Controller
41 |
42 | ## How to use
43 |
44 | - [Full API documentation](https://baku89.github.io/bndr-js/docs/)
45 |
46 | ### Installation
47 |
48 | ```
49 | npm install bndr-js
50 | ```
51 |
52 | ### Example
53 |
54 | ```js
55 | import {Bndr} from 'bndr-js'
56 |
57 | Bndr.pointer().on(pressed =>
58 | console.log('Pointer %s', pressed ? 'pressed' : 'released')
59 | )
60 |
61 | Bndr.pointer()
62 | .position()
63 | .lerp(vec2.lerp, 0.1)
64 | .on(([x, y]) => console.log('Pointer moved: [%f, %f]', x, y))
65 |
66 | Bndr.keyboard()
67 | .hotkey('shift+c')
68 | .on(() => console.log('Hotkey shift+c pressed'))
69 |
70 | Bndr.keyboard()
71 | .key('a')
72 | .on(pressed => console.log(`Key 'a' ${pressed ? 'pressed' : 'released'}`))
73 |
74 | Bndr.midi()
75 | .note(0, 50)
76 | .on(velocity => console.log('MIDI slider #50 moved: %d', velocity))
77 |
78 | Bndr.gamepad()
79 | .axis(0)
80 | .on(([x, y]) => console.log('Gamepad axis #0 tilted: [%f, %f]', x, y))
81 | ```
82 |
83 | ## License
84 |
85 | This repository is published under an MIT License. See the included [LICENSE file](./LICENSE).
86 |
--------------------------------------------------------------------------------
/docs/.vuepress/config.ts:
--------------------------------------------------------------------------------
1 | import {defineUserConfig} from 'vuepress'
2 | import {path} from '@vuepress/utils'
3 | import {defaultTheme} from '@vuepress/theme-default'
4 | import {viteBundler} from '@vuepress/bundler-vite'
5 | import monacoEditorPlugin, {
6 | type IMonacoEditorOpts,
7 | } from 'vite-plugin-monaco-editor'
8 |
9 | import {fileURLToPath} from 'url'
10 |
11 | import eslint from 'vite-plugin-eslint'
12 |
13 | const monacoEditorPluginDefault = (monacoEditorPlugin as any).default as (
14 | options: IMonacoEditorOpts
15 | ) => any
16 |
17 | export default defineUserConfig({
18 | title: 'Bndr',
19 | base: '/bndr-js/',
20 | alias: {
21 | 'bndr-js': path.resolve(__dirname, '../../src'),
22 | },
23 | head: [
24 | ['link', {rel: 'icon', href: './logo.svg'}],
25 | ['link', {rel: 'preconnect', href: 'https://fonts.googleapis.com'}],
26 | [
27 | 'link',
28 | {rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true},
29 | ],
30 | [
31 | 'link',
32 | {
33 | rel: 'stylesheet',
34 | href: 'https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500&family=Work+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300;1,400;1,500;1,600&display=swap',
35 | },
36 | ],
37 | ['link', {rel: 'icon', href: './logo.svg'}],
38 | [
39 | 'link',
40 | {
41 | rel: 'stylesheet',
42 | href: 'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200',
43 | },
44 | ],
45 | ],
46 | theme: defaultTheme({
47 | navbar: [
48 | {
49 | text: 'Home',
50 | link: '/',
51 | },
52 | {
53 | text: 'Guide',
54 | link: '/guide',
55 | },
56 | {
57 | text: 'API',
58 | link: '/api',
59 | },
60 | {
61 | text: 'Sandbox',
62 | link: '/sandbox',
63 | },
64 | ],
65 | logo: '/logo.svg',
66 | repo: 'baku89/bndr-js',
67 | }),
68 | locales: {
69 | '/': {
70 | lang: 'English',
71 | title: 'Bndr',
72 | description:
73 | 'A monadic library designed to compose and filter events from various inputs devices',
74 | },
75 | '/ja/': {
76 | lang: '日本語',
77 | title: 'Bndr',
78 | description:
79 | '様々な入力デバイスからのイベントをモナドとして合成・フィルターするライブラリ',
80 | },
81 | },
82 | bundler: viteBundler({
83 | viteOptions: {
84 | plugins: [
85 | monacoEditorPluginDefault({
86 | languageWorkers: ['editorWorkerService', 'typescript'],
87 | }),
88 | eslint(),
89 | ],
90 | resolve: {
91 | alias: [
92 | {
93 | find: 'bndr-js',
94 | replacement: fileURLToPath(new URL('../../src', import.meta.url)),
95 | },
96 | ],
97 | },
98 | },
99 | }),
100 | markdown: {
101 | //@ts-ignore
102 | linkify: true,
103 | typographer: true,
104 | code: {
105 | lineNumbers: false,
106 | },
107 | },
108 | extendsMarkdown: md => {
109 | const defaultRender = md.renderer.rules.fence!
110 |
111 | md.renderer.rules.fence = (tokens, idx, options, env, self) => {
112 | const token = tokens[idx]
113 | if (token.tag === 'code' && token.info === 'mermaid') {
114 | const diagram = md.utils.escapeHtml(token.content)
115 | return `