@makefully/engagefully 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +90 -2
- package/lib/engagefully.js +1 -0
- package/package.json +66 -4
- package/src/ActionMap.js +261 -0
- package/src/Controller.js +74 -0
- package/src/actions/Amount.js +21 -0
- package/src/actions/Button.js +33 -0
- package/src/actions/Data.js +13 -0
- package/src/actions/Dial.js +15 -0
- package/src/actions/Drop.js +19 -0
- package/src/actions/Joystick.js +17 -0
- package/src/actions/PageAction.js +30 -0
- package/src/actions/Pointer.js +19 -0
- package/src/actions/Throttle.js +6 -0
- package/src/actions/Wheel.js +6 -0
- package/src/actions/index.js +24 -0
- package/src/devices/BLEDevice.js +440 -0
- package/src/devices/FabricDevice.js +97 -0
- package/src/devices/GamepadDevice.js +193 -0
- package/src/devices/KeyboardDevice.js +28 -0
- package/src/devices/PageDevice.js +14 -0
- package/src/devices/PixiDevice.js +50 -0
- package/src/devices/PointerDevice.js +50 -0
- package/src/devices/index.js +22 -0
- package/src/devices/specs/ble-characteristics.json +160 -0
- package/src/devices/specs/ble-descriptors.js +12 -0
- package/src/devices/specs/ble-formats.js +96 -0
- package/src/index.js +28 -0
- package/src/utils/focusGate.js +22 -0
- package/src/utils/quantizeStick.js +26 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build an `enabled` predicate for ActionMap that returns false while the
|
|
3
|
+
* user is typing in an editable field (or when `extra()` is true).
|
|
4
|
+
*
|
|
5
|
+
* @param {{ extra?: () => boolean }} [options]
|
|
6
|
+
* @returns {() => boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function focusGate (options = {}) {
|
|
9
|
+
const extra = typeof options.extra === 'function' ? options.extra : () => false;
|
|
10
|
+
|
|
11
|
+
return () => {
|
|
12
|
+
if (extra()) return false;
|
|
13
|
+
const el = typeof document !== 'undefined' ? document.activeElement : null;
|
|
14
|
+
if (!el || el === document.body) return true;
|
|
15
|
+
const tag = el.tagName;
|
|
16
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return false;
|
|
17
|
+
if (el.isContentEditable) return false;
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default focusGate;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quantize a 2D stick vector into equal angular sectors.
|
|
3
|
+
*
|
|
4
|
+
* Screen convention: +x right, +y down. Sector 0 is screen-forward (-y)
|
|
5
|
+
* when `forward` is `'-y'` (default).
|
|
6
|
+
*
|
|
7
|
+
* @param {number} x
|
|
8
|
+
* @param {number} y
|
|
9
|
+
* @param {{ sectors?: number, deadzone?: number, forward?: '-y' | '+y' }} [options]
|
|
10
|
+
* @returns {{ sector: number } | null}
|
|
11
|
+
*/
|
|
12
|
+
export function quantizeStick (x, y, options = {}) {
|
|
13
|
+
const sectors = options.sectors ?? 8;
|
|
14
|
+
const deadzone = options.deadzone ?? 0.35;
|
|
15
|
+
const forward = options.forward ?? '-y';
|
|
16
|
+
|
|
17
|
+
const mag = Math.hypot(x, y);
|
|
18
|
+
if (mag < deadzone || sectors < 1) return null;
|
|
19
|
+
|
|
20
|
+
const fy = forward === '+y' ? y : -y;
|
|
21
|
+
const angle = Math.atan2(x, fy);
|
|
22
|
+
const sector = Math.round(angle / (Math.PI * 2 / sectors));
|
|
23
|
+
return { sector: ((sector % sectors) + sectors) % sectors };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default quantizeStick;
|